diff options
| author | Magnus Auvinen <magnus.auvinen@gmail.com> | 2008-03-01 14:36:36 +0000 |
|---|---|---|
| committer | Magnus Auvinen <magnus.auvinen@gmail.com> | 2008-03-01 14:36:36 +0000 |
| commit | 0747c2dff9289db6204b82501d03447f3ec6cc99 (patch) | |
| tree | ecca83ee860dfa5293f4dba9233820579a4bf4ac /src/engine/server | |
| parent | 622dbc6f3e5a5f398af8c6ef98d057a200c813a0 (diff) | |
| download | zcatch-0747c2dff9289db6204b82501d03447f3ec6cc99.tar.gz zcatch-0747c2dff9289db6204b82501d03447f3ec6cc99.zip | |
fixed remote console. some gui tweaks aswell.
Diffstat (limited to 'src/engine/server')
| -rw-r--r-- | src/engine/server/es_register.c | 2 | ||||
| -rw-r--r-- | src/engine/server/es_server.c | 85 |
2 files changed, 68 insertions, 19 deletions
diff --git a/src/engine/server/es_register.c b/src/engine/server/es_register.c index 65c56821..47712350 100644 --- a/src/engine/server/es_register.c +++ b/src/engine/server/es_register.c @@ -88,7 +88,7 @@ void register_update() int64 now = time_get(); int64 freq = time_freq(); - if(!config.sv_sendheartbeats) + if(!config.sv_register) return; mastersrv_update(); diff --git a/src/engine/server/es_server.c b/src/engine/server/es_server.c index 9fe75e39..a177ced8 100644 --- a/src/engine/server/es_server.c +++ b/src/engine/server/es_server.c @@ -98,6 +98,7 @@ typedef struct char name[MAX_NAME_LENGTH]; char clan[MAX_CLANNAME_LENGTH]; int score; + int authed; } CLIENT; static CLIENT clients[MAX_CLIENTS]; @@ -511,6 +512,7 @@ static int new_client_callback(int cid, void *user) clients[cid].last_acked_snapshot = -1; clients[cid].snap_rate = SRVCLIENT_SNAPRATE_INIT; clients[cid].score = 0; + clients[cid].authed = 0; return 0; } @@ -526,19 +528,45 @@ static int del_client_callback(int cid, void *user) clients[cid].state = SRVCLIENT_STATE_EMPTY; clients[cid].name[0] = 0; clients[cid].clan[0] = 0; + clients[cid].authed = 0; snapstorage_purge_all(&clients[cid].snapshots); return 0; } static void server_send_map(int cid) { - msg_pack_start_system(NETMSG_MAP, MSGFLAG_VITAL); + msg_pack_start_system(NETMSG_MAP_CHANGE, MSGFLAG_VITAL); msg_pack_string(config.sv_map, 0); msg_pack_int(current_map_crc); msg_pack_end(); server_send_msg(cid); } +static void server_send_rcon_line(int cid, const char *line) +{ + msg_pack_start_system(NETMSG_RCON_LINE, MSGFLAG_VITAL); + msg_pack_string(line, 512); + msg_pack_end(); + server_send_msg(cid); +} + +static void server_send_rcon_line_authed(const char *line) +{ + static volatile int reentry_guard = 0; + int i; + + if(reentry_guard) return; + reentry_guard++; + + for(i = 0; i < MAX_CLIENTS; i++) + { + if(clients[i].state != SRVCLIENT_STATE_EMPTY && clients[i].authed) + server_send_rcon_line(i, line); + } + + reentry_guard--; +} + static void server_process_client_packet(NETPACKET *packet) { int cid = packet->client_id; @@ -658,14 +686,43 @@ static void server_process_client_packet(NETPACKET *packet) /* call the mod with the fresh input data */ mods_client_direct_input(cid, clients[cid].latestinput.data); } - else if(msg == NETMSG_CMD) + else if(msg == NETMSG_RCON_CMD) { - const char *pw = msg_unpack_string(); const char *cmd = msg_unpack_string(); - if(config.rcon_password[0] != 0 && strcmp(pw, config.rcon_password) == 0) + + if(msg_unpack_error() == 0 && clients[cid].authed) { dbg_msg("server", "cid=%d rcon='%s'", cid, cmd); - console_execute(cmd); + console_execute_line(cmd); + } + } + else if(msg == NETMSG_RCON_AUTH) + { + const char *pw; + msg_unpack_string(); /* login name, not used */ + pw = msg_unpack_string(); + + if(msg_unpack_error() == 0) + { + if(config.sv_rcon_password[0] == 0) + { + server_send_rcon_line(cid, "No rcon password set on server. Set sv_rcon_password to enable the remote console."); + } + else if(strcmp(pw, config.sv_rcon_password) == 0) + { + msg_pack_start_system(NETMSG_RCON_AUTH_STATUS, MSGFLAG_VITAL); + msg_pack_int(1); + msg_pack_end(); + server_send_msg(cid); + + clients[cid].authed = 1; + dbg_msg("server", "cid=%d authed", cid); + server_send_rcon_line(cid, "Authentication successful. Remote console access granted."); + } + else + { + server_send_rcon_line(cid, "Wrong password."); + } } } else if(msg == NETMSG_PING) @@ -838,8 +895,10 @@ static int server_run() NETADDR4 bindaddr; net_init(); - snap_init_id(); + + /* */ + console_register_print_callback(server_send_rcon_line_authed); /* load map */ if(!server_load_map(config.sv_map)) @@ -1022,16 +1081,6 @@ static int server_run() /* wait for incomming data */ net_socket_read_wait(netserver_socket(net), 5); - - /* - if(config.dbg_hitch) - { - thread_sleep(config.dbg_hitch); - config.dbg_hitch = 0; - } - else - thread_sleep(1); - */ } } @@ -1043,10 +1092,10 @@ static int server_run() static void server_register_commands() { - + /* kick */ + /* status */ } - int main(int argc, char **argv) { /* init the engine */ |