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 | |
| parent | 622dbc6f3e5a5f398af8c6ef98d057a200c813a0 (diff) | |
| download | zcatch-0747c2dff9289db6204b82501d03447f3ec6cc99.tar.gz zcatch-0747c2dff9289db6204b82501d03447f3ec6cc99.zip | |
fixed remote console. some gui tweaks aswell.
Diffstat (limited to 'src')
| -rw-r--r-- | src/engine/client/ec_client.c | 47 | ||||
| -rw-r--r-- | src/engine/e_config.c | 37 | ||||
| -rw-r--r-- | src/engine/e_config.h | 4 | ||||
| -rw-r--r-- | src/engine/e_config_variables.h | 4 | ||||
| -rw-r--r-- | src/engine/e_console.c | 25 | ||||
| -rw-r--r-- | src/engine/e_console.h | 3 | ||||
| -rw-r--r-- | src/engine/e_engine.c | 45 | ||||
| -rw-r--r-- | src/engine/e_engine.h | 6 | ||||
| -rw-r--r-- | src/engine/e_if_client.h | 44 | ||||
| -rw-r--r-- | src/engine/e_if_modc.h | 12 | ||||
| -rw-r--r-- | src/engine/e_protocol.h | 23 | ||||
| -rw-r--r-- | src/engine/e_ringbuffer.c | 2 | ||||
| -rw-r--r-- | src/engine/server/es_register.c | 2 | ||||
| -rw-r--r-- | src/engine/server/es_server.c | 85 | ||||
| -rw-r--r-- | src/game/client/gc_client.cpp | 33 | ||||
| -rw-r--r-- | src/game/client/gc_client.h | 4 | ||||
| -rw-r--r-- | src/game/client/gc_console.cpp | 340 | ||||
| -rw-r--r-- | src/game/client/gc_console.h | 3 | ||||
| -rw-r--r-- | src/game/client/gc_hooks.cpp | 39 | ||||
| -rw-r--r-- | src/game/client/gc_menu.cpp | 35 | ||||
| -rw-r--r-- | src/game/g_variables.h | 6 | ||||
| -rw-r--r-- | src/game/g_vmath.h | 1 | ||||
| -rw-r--r-- | src/game/server/gs_server.cpp | 3 |
23 files changed, 546 insertions, 257 deletions
diff --git a/src/engine/client/ec_client.c b/src/engine/client/ec_client.c index 0ddcf7d9..56c817a6 100644 --- a/src/engine/client/ec_client.c +++ b/src/engine/client/ec_client.c @@ -58,6 +58,7 @@ static int snapcrcerrors = 0; static int ack_game_tick = -1; static int current_recv_tick = 0; +static int rcon_authed = 0; /* pinging */ static int64 ping_start_time = 0; @@ -323,10 +324,23 @@ static void client_send_ready() client_send_msg(); } +int client_rcon_authed() +{ + return rcon_authed; +} + +void client_rcon_auth(const char *name, const char *password) +{ + msg_pack_start_system(NETMSG_RCON_AUTH, MSGFLAG_VITAL); + msg_pack_string(name, 32); + msg_pack_string(password, 32); + msg_pack_end(); + client_send_msg(); +} + void client_rcon(const char *cmd) { - msg_pack_start_system(NETMSG_CMD, MSGFLAG_VITAL); - msg_pack_string(config.rcon_password, 32); + msg_pack_start_system(NETMSG_RCON_CMD, MSGFLAG_VITAL); msg_pack_string(cmd, 256); msg_pack_end(); client_send_msg(); @@ -470,17 +484,18 @@ void client_connect(const char *server_address_str) if(net_host_lookup(buf, port, &server_address) != 0) dbg_msg("client", "could not find the address of %s, connecting to localhost", buf); + rcon_authed = 0; netclient_connect(net, &server_address); client_set_state(CLIENTSTATE_CONNECTING); graph_init(&intra_graph, 0.0f, 1.0f); graph_init(&input_late_graph, 0.0f, 1.0f); graph_init(&predict_graph, 0.0f, 200.0f); - } void client_disconnect_with_reason(const char *reason) { + rcon_authed = 0; netclient_disconnect(net, reason); client_set_state(CLIENTSTATE_OFFLINE); map_unload(); @@ -722,7 +737,7 @@ static void client_process_packet(NETPACKET *packet) if(sys) { /* system message */ - if(msg == NETMSG_MAP) + if(msg == NETMSG_MAP_CHANGE) { const char *map = msg_unpack_string(); int map_crc = msg_unpack_int(); @@ -830,6 +845,21 @@ static void client_process_packet(NETPACKET *packet) msg_pack_end(); client_send_msg(); } + else if(msg == NETMSG_RCON_AUTH_STATUS) + { + int result = msg_unpack_int(); + if(msg_unpack_error() == 0) + rcon_authed = result; + } + else if(msg == NETMSG_RCON_LINE) + { + const char *line = msg_unpack_string(); + if(msg_unpack_error() == 0) + { + /*dbg_msg("remote", "%s", line);*/ + modc_rcon_line(line); + } + } else if(msg == NETMSG_PING_REPLY) dbg_msg("client/network", "latency %.2f", (time_get() - ping_start_time)*1000 / (float)time_freq()); else if(msg == NETMSG_SNAP || msg == NETMSG_SNAPSINGLE || msg == NETMSG_SNAPEMPTY) @@ -1451,7 +1481,12 @@ int main(int argc, char **argv) /* run the client*/ client_run(); - /* write down the config and quit */ - engine_writeconfig(); + /* write down the config and quit */ + if(engine_config_write_start() == 0) + { + config_save(); + engine_config_write_stop(); + } + return 0; } diff --git a/src/engine/e_config.c b/src/engine/e_config.c index e71d2ad3..9cef342f 100644 --- a/src/engine/e_config.c +++ b/src/engine/e_config.c @@ -7,6 +7,7 @@ #include "e_system.h" #include "e_config.h" #include "e_linereader.h" +#include "e_engine.h" CONFIGURATION config; @@ -63,6 +64,7 @@ void config_set(const char *line) void config_load(const char *filename) { + /* IOHANDLE file; dbg_msg("config/load", "loading %s", filename); file = io_open(filename, IOFLAG_READ); @@ -77,37 +79,20 @@ void config_load(const char *filename) config_set(line); io_close(file); - } + }*/ } -void config_save(const char *filename) +void config_save() { - IOHANDLE file; - dbg_msg("config/save", "saving config to %s", filename); + char linebuf[512]; + + #define MACRO_CONFIG_INT(name,def,min,max) { str_format(linebuf, sizeof(linebuf), "%s %i", #name, config.name); engine_config_write_line(linebuf); } + #define MACRO_CONFIG_STR(name,len,def) { str_format(linebuf, sizeof(linebuf), "%s \"%s\"", #name, config.name); engine_config_write_line(linebuf); } - file = io_open(filename, IOFLAG_WRITE); + #include "e_config_variables.h" - if(file) - { -#if defined(CONF_FAMILY_WINDOWS) - const char newline[] = "\r\n"; -#else - const char newline[] = "\n"; -#endif - const int newline_len = sizeof(newline)-1; - - #define MACRO_CONFIG_INT(name,def,min,max) { char str[256]; str_format(str, sizeof(str), "%s=%i%s", #name, config.name, newline); io_write(file, str, strlen(str)); } - #define MACRO_CONFIG_STR(name,len,def) { io_write(file, #name, strlen(#name)); io_write(file, "=", 1); io_write(file, config.name, strlen(config.name)); io_write(file, newline, newline_len); } - - #include "e_config_variables.h" - - #undef MACRO_CONFIG_INT - #undef MACRO_CONFIG_STR - - io_close(file); - } - else - dbg_msg("config/save", "couldn't open %s for writing. :(", filename); + #undef MACRO_CONFIG_INT + #undef MACRO_CONFIG_STR } #define MACRO_CONFIG_INT(name,def,min,max) int config_get_ ## name (CONFIGURATION *c) { return c->name; } diff --git a/src/engine/e_config.h b/src/engine/e_config.h index 78ffdd02..514a6ceb 100644 --- a/src/engine/e_config.h +++ b/src/engine/e_config.h @@ -20,8 +20,8 @@ extern CONFIGURATION config; void config_init(); void config_set(const char *line); void config_reset(); -void config_load(const char *filename); -void config_save(const char *filename); +/*void config_load(const char *filename);*/ +void config_save(); typedef int (*CONFIG_INT_GETTER)(CONFIGURATION *c); typedef const char *(*CONFIG_STR_GETTER)(CONFIGURATION *c); diff --git a/src/engine/e_config_variables.h b/src/engine/e_config_variables.h index 01b35dc0..9b3f5cf3 100644 --- a/src/engine/e_config_variables.h +++ b/src/engine/e_config_variables.h @@ -5,7 +5,6 @@ MACRO_CONFIG_STR(player_name, 32, "nameless tee") MACRO_CONFIG_STR(clan_name, 32, "") MACRO_CONFIG_STR(password, 32, "") -MACRO_CONFIG_STR(rcon_password, 32, "") MACRO_CONFIG_INT(cl_cpu_throttle, 0, 0, 1) /*MACRO_CONFIG_STR(cl_connect, 32, "")*/ @@ -52,12 +51,13 @@ MACRO_CONFIG_STR(sv_name, 128, "unnamed server") MACRO_CONFIG_STR(sv_bindaddr, 128, "") MACRO_CONFIG_INT(sv_port, 8303, 0, 0) MACRO_CONFIG_INT(sv_external_port, 0, 0, 0) -MACRO_CONFIG_INT(sv_sendheartbeats, 1, 0, 1) MACRO_CONFIG_STR(sv_map, 128, "dm1") MACRO_CONFIG_INT(sv_map_reload, 0, 0, 1) MACRO_CONFIG_INT(sv_max_clients, 8, 1, 12) MACRO_CONFIG_INT(sv_high_bandwidth, 0, 0, 1) MACRO_CONFIG_INT(sv_status, 0, 0, 1) +MACRO_CONFIG_INT(sv_register, 1, 0, 1) +MACRO_CONFIG_STR(sv_rcon_password, 32, "") MACRO_CONFIG_INT(debug, 0, 0, 1) MACRO_CONFIG_INT(dbg_stress, 0, 0, 0) diff --git a/src/engine/e_console.c b/src/engine/e_console.c index db0398b4..27add750 100644 --- a/src/engine/e_console.c +++ b/src/engine/e_console.c @@ -1,6 +1,7 @@ #include "e_system.h" #include "e_console.h" #include "e_config.h" +#include "e_linereader.h" #include <stdio.h> #include <string.h> #include <stdlib.h> @@ -339,7 +340,7 @@ void console_print(const char *str) print_callback(str); } -void console_execute(const char *str) +void console_execute_line(const char *str) { LEXER_RESULT result; int error; @@ -374,6 +375,28 @@ void console_execute(const char *str) } } +void console_execute_file(const char *filename) +{ + IOHANDLE file; + file = io_open(filename, IOFLAG_READ); + + if(file) + { + char *line; + LINEREADER lr; + + dbg_msg("console", "executing '%s'", filename); + linereader_init(&lr, file); + + while((line = linereader_get(&lr))) + console_execute_line(line); + + io_close(file); + } + else + dbg_msg("console", "failed to open '%s'", filename); +} + static void echo_command(void *result, void *user_data) { const char *str; diff --git a/src/engine/e_console.h b/src/engine/e_console.h index 10d77a3a..730779f8 100644 --- a/src/engine/e_console.h +++ b/src/engine/e_console.h @@ -18,7 +18,8 @@ typedef struct COMMAND_t void console_init(); void console_register(COMMAND *cmd); -void console_execute(const char *str); +void console_execute_line(const char *str); +void console_execute_file(const char *filename); void console_print(const char *str); void console_register_print_callback(void (*callback)(const char *)); diff --git a/src/engine/e_engine.c b/src/engine/e_engine.c index 6fe61efe..04094573 100644 --- a/src/engine/e_engine.c +++ b/src/engine/e_engine.c @@ -78,7 +78,7 @@ void engine_parse_arguments(int argc, char **argv) /* load the configuration */ int i; int abs = 0; - const char *config_filename = "default.cfg"; + const char *config_filename = "settings.cfg"; char buf[1024]; for(i = 1; i < argc; i++) { @@ -91,15 +91,15 @@ void engine_parse_arguments(int argc, char **argv) } if(abs) - config_load(config_filename); + console_execute_file(config_filename); else - config_load(engine_savepath(config_filename, buf, sizeof(buf))); + console_execute_file(engine_savepath(config_filename, buf, sizeof(buf))); /* search arguments for overrides */ { int i; for(i = 1; i < argc; i++) - config_set(argv[i]); + console_execute_line(argv[i]); } /* set default servers and load from disk*/ @@ -107,12 +107,43 @@ void engine_parse_arguments(int argc, char **argv) mastersrv_load(); } -void engine_writeconfig() + +static IOHANDLE config_file = 0; + +int engine_config_write_start() { - char buf[1024]; - config_save(engine_savepath("default.cfg", buf, sizeof(buf))); + char filename[1024]; + config_save(engine_savepath("settings.cfg", filename, sizeof(filename))); + + config_file = io_open(filename, IOFLAG_WRITE); + if(config_file == 0) + return -1; + return 0; } +void engine_config_write_line(const char *line) +{ + if(config_file) + { +#if defined(CONF_FAMILY_WINDOWS) + static const char newline[] = "\r\n"; +#else + static const char newline[] = "\n"; +#endif + io_write(config_file, line, strlen(line)); + io_write(config_file, newline, sizeof(newline)-1); + } +} + +void engine_config_write_stop() +{ + io_close(config_file); + config_file = 0; +} +/* +void engine_writeconfig() +{ +}*/ static int perf_tick = 1; static PERFORMACE_INFO *current = 0; diff --git a/src/engine/e_engine.h b/src/engine/e_engine.h index 6818d96d..7b5baec9 100644 --- a/src/engine/e_engine.h +++ b/src/engine/e_engine.h @@ -3,7 +3,11 @@ const char *engine_savepath(const char *filename, char *buffer, int max); void engine_init(const char *appname); void engine_parse_arguments(int argc, char **argv); -void engine_writeconfig(); + +int engine_config_write_start(); +void engine_config_write_line(const char *line); +void engine_config_write_stop(); + int engine_stress(float probability); diff --git a/src/engine/e_if_client.h b/src/engine/e_if_client.h index 9173cfe1..e921f9e9 100644 --- a/src/engine/e_if_client.h +++ b/src/engine/e_if_client.h @@ -319,9 +319,40 @@ void client_entergame(); Remarks: The client must have the correct rcon password to connect. + + See Also: + <client_rcon_auth, client_rcon_authed> */ void client_rcon(const char *cmd); +/* + Function: client_rcon_auth + TODO + + Arguments: + arg1 - desc + + Returns: + + See Also: + <client_rcon, client_rcon_authed> +*/ +void client_rcon_auth(const char *name, const char *password); + +/* + Function: client_rcon_authed + TODO + + Arguments: + arg1 - desc + + Returns: + + See Also: + <client_rcon, client_rcon_auth> +*/ +int client_rcon_authed(); + /********************************************************************************** Group: Other **********************************************************************************/ @@ -414,5 +445,18 @@ int client_mapdownload_amount(); */ int client_mapdownload_totalsize(); +/* + Function: client_save_line + TODO + + Arguments: + arg1 - desc + + Returns: + + See Also: + <other_func> +*/ +void client_save_line(const char *line); #endif diff --git a/src/engine/e_if_modc.h b/src/engine/e_if_modc.h index 33069a6f..8839d5f1 100644 --- a/src/engine/e_if_modc.h +++ b/src/engine/e_if_modc.h @@ -12,6 +12,18 @@ void modc_console_init(); /* + Function: modc_rcon_line + TODO +*/ +void modc_rcon_line(const char *line); + +/* + Function: modc_save_config + TODO +*/ +void modc_save_config(); + +/* Function: modc_init Called when the client starts. diff --git a/src/engine/e_protocol.h b/src/engine/e_protocol.h index a0213483..0bca00a4 100644 --- a/src/engine/e_protocol.h +++ b/src/engine/e_protocol.h @@ -33,19 +33,22 @@ enum NETMSG_INFO=1, /* sent by server */ - NETMSG_MAP, - NETMSG_MAP_DATA, - NETMSG_SNAP, - NETMSG_SNAPEMPTY, - NETMSG_SNAPSINGLE, - NETMSG_SNAPSMALL, + NETMSG_MAP_CHANGE, /* sent when client should switch map */ + NETMSG_MAP_DATA, /* map transfer, contains a chunk of the map file */ + NETMSG_SNAP, /* normal snapshot, multiple parts */ + NETMSG_SNAPEMPTY, /* empty snapshot */ + NETMSG_SNAPSINGLE, /* ? */ + NETMSG_SNAPSMALL, /* */ + NETMSG_RCON_AUTH_STATUS,/* result of the authentication */ + NETMSG_RCON_LINE, /* line that should be printed to the remote console */ /* sent by client */ - NETMSG_READY, + NETMSG_READY, /* */ NETMSG_ENTERGAME, - NETMSG_INPUT, - NETMSG_CMD, - NETMSG_REQUEST_MAP_DATA, + NETMSG_INPUT, /* contains the inputdata from the client */ + NETMSG_RCON_CMD, /* */ + NETMSG_RCON_AUTH, /* */ + NETMSG_REQUEST_MAP_DATA,/* */ /* sent by both */ NETMSG_PING, diff --git a/src/engine/e_ringbuffer.c b/src/engine/e_ringbuffer.c index 02350140..6a9c12f6 100644 --- a/src/engine/e_ringbuffer.c +++ b/src/engine/e_ringbuffer.c @@ -215,5 +215,7 @@ void *ringbuf_first(RINGBUFFER *rb) void *ringbuf_last(RINGBUFFER *rb) { + if(rb->last_alloc == 0) + return 0; return rb->last_alloc+1; } 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 */ diff --git a/src/game/client/gc_client.cpp b/src/game/client/gc_client.cpp index fae66cf0..eae9f52f 100644 --- a/src/game/client/gc_client.cpp +++ b/src/game/client/gc_client.cpp @@ -793,22 +793,15 @@ void render_game() // send message if(chat_input_len) { - if(chat_mode == CHATMODE_CONSOLE) - config_set(chat_input); - else if(chat_mode == CHATMODE_REMOTECONSOLE) - client_rcon(chat_input); + // send chat message + msg_pack_start(MSG_SAY, MSGFLAG_VITAL); + if(chat_mode == CHATMODE_ALL) + msg_pack_int(0); else - { - // send chat message - msg_pack_start(MSG_SAY, MSGFLAG_VITAL); - if(chat_mode == CHATMODE_ALL) - msg_pack_int(0); - else - msg_pack_int(1); - msg_pack_string(chat_input, 512); - msg_pack_end(); - client_send_msg(); - } + msg_pack_int(1); + msg_pack_string(chat_input, 512); + msg_pack_end(); + client_send_msg(); } chat_mode = CHATMODE_NONE; @@ -847,13 +840,7 @@ void render_game() if(inp_key_down(config.key_teamchat)) chat_mode = CHATMODE_TEAM; - - if(inp_key_down(config.key_console)) - chat_mode = CHATMODE_CONSOLE; - if(inp_key_down(config.key_remoteconsole)) - chat_mode = CHATMODE_REMOTECONSOLE; - if(chat_mode != CHATMODE_NONE) { mem_zero(chat_input, sizeof(chat_input)); @@ -1252,10 +1239,6 @@ void render_game() str_format(buf, sizeof(buf), "All: %s_", chat_input); else if(chat_mode == CHATMODE_TEAM) str_format(buf, sizeof(buf), "Team: %s_", chat_input); - else if(chat_mode == CHATMODE_CONSOLE) - str_format(buf, sizeof(buf), "Console: %s_", chat_input); - else if(chat_mode == CHATMODE_REMOTECONSOLE) - str_format(buf, sizeof(buf), "Rcon: %s_", chat_input); else str_format(buf, sizeof(buf), "Chat: %s_", chat_input); gfx_text(0, x, y, 8.0f, buf, 380); diff --git a/src/game/client/gc_client.h b/src/game/client/gc_client.h index 93a90a86..0b76e38c 100644 --- a/src/game/client/gc_client.h +++ b/src/game/client/gc_client.h @@ -74,8 +74,8 @@ enum CHATMODE_NONE=0, CHATMODE_ALL, CHATMODE_TEAM, - CHATMODE_CONSOLE, - CHATMODE_REMOTECONSOLE, + //CHATMODE_CONSOLE, + //CHATMODE_REMOTECONSOLE, }; extern int chat_mode; diff --git a/src/game/client/gc_console.cpp b/src/game/client/gc_console.cpp index 75c20e15..21e3bc34 100644 --- a/src/game/client/gc_console.cpp +++ b/src/game/client/gc_console.cpp @@ -26,14 +26,150 @@ enum CONSOLE_CLOSING, }; -static char console_history_data[65536]; -static RINGBUFFER *console_history; +class CONSOLE +{ +public: + char history_data[65536]; + RINGBUFFER *history; + char *history_entry; + + char backlog_data[65536]; + RINGBUFFER *backlog; + + unsigned int input_len; + char input[256]; + + int type; + +public: + CONSOLE(int t) + { + // clear input + input_len = 0; + mem_zero(input, sizeof(input)); + + // init ringbuffers + history = ringbuf_init(history_data, sizeof(history_data)); + backlog = ringbuf_init(backlog_data, sizeof(backlog_data)); + + history_entry = 0x0; + + type = t; + } + + void execute_line(const char *line) + { + if(type == 0) + console_execute_line(line); + else + { + if(client_rcon_authed()) + client_rcon(line); + else + client_rcon_auth("", line); + } + } + + void handle_event(INPUT_EVENT e) + { + if (!(e.ch >= 0 && e.ch < 32)) + { + if (input_len < sizeof(input) - 1) + { + input[input_len] = e.ch; + input[input_len+1] = 0; + input_len++; + + history_entry = 0x0; + } + } -static char console_backlog_data[65536]; -static RINGBUFFER *console_backlog; + if(e.key == KEY_BACKSPACE) + { + if(input_len > 0) + { + input[input_len-1] = 0; + input_len--; -static unsigned int console_input_len = 0; -static char console_input[256] = {0}; + history_entry = 0x0; + } + } + else if(e.key == KEY_ENTER || e.key == KEY_KP_ENTER) + { + if (input_len) + { + char *entry = (char *)ringbuf_allocate(history, input_len+1); + mem_copy(entry, input, input_len+1); + + execute_line(input); + input[0] = 0; + input_len = 0; + + history_entry = 0x0; + } + } + else if (e.key == KEY_UP) + { + if (history_entry) + { + char *test = (char *)ringbuf_prev(history, history_entry); + + if (test) + history_entry = test; + } + else + history_entry = (char *)ringbuf_last(history); + + if (history_entry) + { + unsigned int len = strlen(history_entry); + if (len < sizeof(input) - 1) + { + mem_copy(input, history_entry, len+1); + input_len = len; + } + } + + } + else if (e.key == KEY_DOWN) + { + if (history_entry) + history_entry = (char *)ringbuf_next(history, history_entry); + + if (history_entry) + { + unsigned int len = strlen(history_entry); + if (len < sizeof(input) - 1) + { + mem_copy(input, history_entry, len+1); + + input_len = len; + } + } + else + { + input[0] = 0; + input_len = 0; + } + } + } + + void print_line(const char *line) + { + int len = strlen(line); + + if (len > 255) + len = 255; + + char *entry = (char *)ringbuf_allocate(backlog, len+1); + mem_copy(entry, line, len+1); + } +}; + +static CONSOLE local_console(0); +static CONSOLE remote_console(1); + +static int console_type = 0; static int console_state = CONSOLE_CLOSED; static float state_change_end = 0.0f; static const float state_change_duration = 0.1f; @@ -44,17 +180,22 @@ static float time_now() return float(time_get()-time_start)/float(time_freq()); } -static void client_console_print(const char *str) +static CONSOLE *current_console() { - int len = strlen(str); - - if (len > 255) - len = 255; + if(console_type != 0) + return &remote_console; + return &local_console; +} - char *entry = (char *)ringbuf_allocate(console_backlog, len+1); - mem_copy(entry, str, len+1); +static void client_console_print(const char *str) +{ + local_console.print_line(str); } +void console_rcon_print(const char *line) +{ + remote_console.print_line(line); +} static void con_team(void *result, void *user_data) { @@ -63,7 +204,8 @@ static void con_team(void *result, void *user_data) send_switch_team(new_team); } -static void command_history(void *result, void *user_data) +/* +static void con_history(void *result, void *user_data) { char *entry = (char *)ringbuf_first(console_history); @@ -73,28 +215,23 @@ static void command_history(void *result, void *user_data) entry = (char *)ringbuf_next(console_history, entry); } -} +}*/ void send_kill(int client_id); -static void command_kill(void *result, void *user_data) +static void con_kill(void *result, void *user_data) { send_kill(-1); } void client_console_init() { - console_history = ringbuf_init(console_history_data, sizeof(console_history_data)); - console_backlog = ringbuf_init(console_backlog_data, sizeof(console_backlog_data)); - console_register_print_callback(client_console_print); MACRO_REGISTER_COMMAND("team", "i", con_team, 0x0); - MACRO_REGISTER_COMMAND("history", "", command_history, 0x0); - MACRO_REGISTER_COMMAND("kill", "", command_kill, 0x0); + //MACRO_REGISTER_COMMAND("history", "", con_history, 0x0); + MACRO_REGISTER_COMMAND("kill", "", con_kill, 0x0); } -static char *console_history_entry = 0x0; - void console_handle_input() { int was_active = console_active(); @@ -103,95 +240,12 @@ void console_handle_input() { INPUT_EVENT e = inp_get_event(i); - if (e.key == KEY_F3) - { - console_toggle(); - } - - if (console_active()) - { - if (!(e.ch >= 0 && e.ch < 32)) - { - if (console_input_len < sizeof(console_input) - 1) - { - console_input[console_input_len] = e.ch; - console_input[console_input_len+1] = 0; - console_input_len++; - - console_history_entry = 0x0; - } - } - - if(e.key == KEY_BACKSPACE) - { - if(console_input_len > 0) - { - console_input[console_input_len-1] = 0; - console_input_len--; - - console_history_entry = 0x0; - } - } - else if(e.key == KEY_ENTER || e.key == KEY_KP_ENTER) - { - if (console_input_len) - { - char *entry = (char *)ringbuf_allocate(console_history, console_input_len+1); - mem_copy(entry, console_input, console_input_len+1); - - console_execute(console_input); - console_input[0] = 0; - console_input_len = 0; - - console_history_entry = 0x0; - } - } - else if (e.key == KEY_UP) - { - if (console_history_entry) - { - char *test = (char *)ringbuf_prev(console_history, console_history_entry); - - if (test) - console_history_entry = test; - } - else - console_history_entry = (char *)ringbuf_last(console_history); - - if (console_history_entry) - { - unsigned int len = strlen(console_history_entry); - if (len < sizeof(console_input) - 1) - { - mem_copy(console_input, console_history_entry, len+1); - - console_input_len = len; - } - } - - } - else if (e.key == KEY_DOWN) - { - if (console_history_entry) - console_history_entry = (char *)ringbuf_next(console_history, console_history_entry); - - if (console_history_entry) - { - unsigned int len = strlen(console_history_entry); - if (len < sizeof(console_input) - 1) - { - mem_copy(console_input, console_history_entry, len+1); - - console_input_len = len; - } - } - else - { - console_input[0] = 0; - console_input_len = 0; - } - } - } + if (e.key == config.key_toggleconsole) + console_toggle(0); + else if (e.key == config.key_toggleconsole+1) + console_toggle(1); + else if(console_active()) + current_console()->handle_event(e); } if (was_active || console_active()) @@ -201,24 +255,33 @@ void console_handle_input() } } -void console_toggle() +void console_toggle(int type) { - if (console_state == CONSOLE_CLOSED || console_state == CONSOLE_OPEN) + if(console_type != type && (console_state == CONSOLE_OPEN || console_state == CONSOLE_OPENING)) { - state_change_end = time_now()+state_change_duration; + // don't toggle console, just switch what console to use } else - { - float progress = state_change_end-time_now(); - float reversed_progress = state_change_duration-progress; + { + if (console_state == CONSOLE_CLOSED || console_state == CONSOLE_OPEN) + { + state_change_end = time_now()+state_change_duration; + } + else + { + float progress = state_change_end-time_now(); + float reversed_progress = state_change_duration-progress; + + state_change_end = time_now()+reversed_progress; + } - state_change_end = time_now()+reversed_progress; + if (console_state == CONSOLE_CLOSED || console_state == CONSOLE_CLOSING) + console_state = CONSOLE_OPENING; + else + console_state = CONSOLE_CLOSING; } - if (console_state == CONSOLE_CLOSED || console_state == CONSOLE_CLOSING) - console_state = CONSOLE_OPENING; - else - console_state = CONSOLE_CLOSING; + console_type = type; } // only defined for 0<=t<=1 @@ -276,6 +339,8 @@ void console_render() gfx_texture_set(data->images[IMAGE_CONSOLE_BG].id); gfx_quads_begin(); gfx_setcolor(0.2f, 0.2f, 0.2f,0.9f); + if(console_type != 0) + gfx_setcolor(0.4f, 0.2f, 0.2f,0.9f); gfx_quads_setsubset(0,-console_height*0.075f,screen.w*0.075f*0.5f,0); gfx_quads_drawTL(0,0,screen.w,console_height); gfx_quads_end(); @@ -287,36 +352,45 @@ void console_render() gfx_quads_setsubset(0,0.1f,screen.w*0.015f,1-0.1f); gfx_quads_drawTL(0,console_height-10.0f,screen.w,10.0f); gfx_quads_end(); - - console_height -= 10.0f; + + CONSOLE *console = current_console(); { float font_size = 10.0f; float row_height = font_size*1.25f; - float width = gfx_text_width(0, font_size, console_input, -1); + float width = gfx_text_width(0, font_size, console->input, -1); float x = 3, y = console_height - row_height - 2; - float prompt_width = gfx_text_width(0, font_size, ">", -1)+2; + const char *prompt = ">"; + if(console_type) + { + if(client_rcon_authed()) + prompt = "rcon>"; + else + prompt = "rcon password>"; + } + + float prompt_width = gfx_text_width(0, font_size,prompt, -1)+2; - gfx_text(0, x, y, font_size, ">", -1); - gfx_text(0, x+prompt_width, y, font_size, console_input, -1); + gfx_text(0, x, y, font_size, prompt, -1); + gfx_text(0, x+prompt_width, y, font_size, console->input, -1); gfx_text(0, x+prompt_width+width+1, y, font_size, "_", -1); - char buf[64]; - str_format(buf, sizeof(buf), "Teewars v%s", TEEWARS_VERSION); + char buf[128]; + str_format(buf, sizeof(buf), "Teewars v%s %s", TEEWARS_VERSION); float version_width = gfx_text_width(0, font_size, buf, -1); gfx_text(0, screen.w-version_width-5, y, font_size, buf, -1); y -= row_height; - char *entry = (char *)ringbuf_last(console_backlog); + char *entry = (char *)ringbuf_last(console->backlog); while (y > 0.0f && entry) { gfx_text(0, x, y, font_size, entry, -1); y -= row_height; - entry = (char *)ringbuf_prev(console_backlog, entry); + entry = (char *)ringbuf_prev(console->backlog, entry); } } } diff --git a/src/game/client/gc_console.h b/src/game/client/gc_console.h index 87628a2a..0d516820 100644 --- a/src/game/client/gc_console.h +++ b/src/game/client/gc_console.h @@ -2,9 +2,10 @@ #define _GC_CONSOLE_H void console_handle_input(); -void console_toggle(); +void console_toggle(int tpye); void console_render(); int console_active(); void client_console_init(); +void console_rcon_print(const char *line); #endif diff --git a/src/game/client/gc_hooks.cpp b/src/game/client/gc_hooks.cpp index 9292d08c..d8863be7 100644 --- a/src/game/client/gc_hooks.cpp +++ b/src/game/client/gc_hooks.cpp @@ -31,9 +31,25 @@ extern "C" void modc_console_init() client_console_init(); } +static void load_sounds_thread(void *) +{ + // load sounds + for(int s = 0; s < data->num_sounds; s++) + { + //render_loading(current/total); + for(int i = 0; i < data->sounds[s].num_sounds; i++) + { + int id = snd_load_wv(data->sounds[s].sounds[i].filename); + data->sounds[s].sounds[i].id = id; + } + } +} + extern "C" void modc_init() { static FONT_SET default_font; + + int64 start = time_get(); int before = gfx_memory_usage(); font_set_load(&default_font, "data/fonts/default_font%d.tfnt", "data/fonts/default_font%d.png", "data/fonts/default_font%d_b.png", 14, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 36); @@ -56,9 +72,9 @@ extern "C" void modc_init() // TODO: should be removed snd_set_listener_pos(0.0f, 0.0f); - float total = data->num_sounds+data->num_images; + float total = data->num_images; float current = 0; - + // load textures for(int i = 0; i < data->num_images; i++) { @@ -66,8 +82,14 @@ extern "C" void modc_init() data->images[i].id = gfx_load_texture(data->images[i].filename, IMG_AUTO); current++; } + + skin_init(); + //load_sounds_thread(0); + thread_create(load_sounds_thread, 0); + // load sounds + /* for(int s = 0; s < data->num_sounds; s++) { render_loading(current/total); @@ -83,9 +105,11 @@ extern "C" void modc_init() } current++; - } - - skin_init(); + }*/ + + + int64 end = time_get(); + dbg_msg("", "%f.2ms", ((end-start)*1000)/(float)time_freq()); } extern "C" void modc_entergame() @@ -324,6 +348,11 @@ extern "C" void modc_render() console_render(); } +extern "C" void modc_rcon_line(const char *line) +{ + console_rcon_print(line); +} + extern "C" int modc_snap_input(int *data) { picked_up_weapon = -1; diff --git a/src/game/client/gc_menu.cpp b/src/game/client/gc_menu.cpp index ec2cc2fe..96b4a9f1 100644 --- a/src/game/client/gc_menu.cpp +++ b/src/game/client/gc_menu.cpp @@ -90,16 +90,24 @@ static void ui_draw_browse_icon(int what, const RECT *r) gfx_quads_end(); } +static vec4 button_color_mul(const void *id) +{ + if(ui_active_item() == id) + return vec4(1,1,1,0.5f); + else if(ui_hot_item() == id) + return vec4(1,1,1,1.5f); + return vec4(1,1,1,1); +} + static void ui_draw_menu_button(const void *id, const char *text, int checked, const RECT *r, const void *extra) { - ui_draw_rect(r, vec4(1,1,1,0.5f), CORNER_ALL, 5.0f); + ui_draw_rect(r, vec4(1,1,1,0.5f)*button_color_mul(id), CORNER_ALL, 5.0f); ui_do_label(r, text, 18.0f, 0); } - static void ui_draw_keyselect_button(const void *id, const char *text, int checked, const RECT *r, const void *extra) { - ui_draw_rect(r, vec4(1,1,1,0.5f), CORNER_ALL, 5.0f); + ui_draw_rect(r, vec4(1,1,1,0.5f)*button_color_mul(id), CORNER_ALL, 5.0f); ui_do_label(r, text, 14.0f, 0); } @@ -152,7 +160,7 @@ static void ui_draw_checkbox_common(const void *id, const char *text, const char ui_vsplit_l(&t, 5.0f, 0, &t); ui_margin(&c, 2.0f, &c); - ui_draw_rect(&c, vec4(1,1,1,0.25f), CORNER_ALL, 3.0f); + ui_draw_rect(&c, vec4(1,1,1,0.25f)*button_color_mul(id), CORNER_ALL, 3.0f); c.y += 2; ui_do_label(&c, boxtext, 12.0f, 0); ui_do_label(&t, text, 14.0f, -1); @@ -337,7 +345,7 @@ float ui_do_scrollbar_v(const void *id, const RECT *rect, float current) slider = handle; ui_margin(&slider, 5.0f, &slider); - ui_draw_rect(&slider, vec4(1,1,1,0.25f), CORNER_ALL, 2.5f); + ui_draw_rect(&slider, vec4(1,1,1,0.25f)*button_color_mul(id), CORNER_ALL, 2.5f); return ret; } @@ -393,7 +401,7 @@ float ui_do_scrollbar_h(const void *id, const RECT *rect, float current) slider = handle; ui_margin(&slider, 5.0f, &slider); - ui_draw_rect(&slider, vec4(1,1,1,0.25f), CORNER_ALL, 2.5f); + ui_draw_rect(&slider, vec4(1,1,1,0.25f)*button_color_mul(id), CORNER_ALL, 2.5f); return ret; } @@ -761,6 +769,13 @@ static void menu2_render_serverbrowser(RECT main_view) int new_selected = -1; int selected_index = -1; + int num_players = 0; + + for (int i = 0; i < num_servers; i++) + { + SERVER_INFO *item = client_serverbrowse_sorted_get(i); + num_players += item->num_players; + } for (int i = 0; i < num_servers; i++) { @@ -1069,7 +1084,7 @@ static void menu2_render_serverbrowser(RECT main_view) ui_draw_rect(&status, vec4(1,1,1,0.25f), CORNER_B, 5.0f); ui_vmargin(&status, 50.0f, &status); char buf[128]; - str_format(buf, sizeof(buf), "%d of %d servers", client_serverbrowse_sorted_num(), client_serverbrowse_num()); + str_format(buf, sizeof(buf), "%d of %d servers, %d players", client_serverbrowse_sorted_num(), client_serverbrowse_num(), num_players); ui_do_label(&status, buf, 14.0f, -1); // render toolbox @@ -1302,8 +1317,7 @@ static void menu2_render_settings_controls(RECT main_view) { "Emoticon:", &config.key_emoticon }, { "Chat:", &config.key_chat }, { "Team Chat:", &config.key_teamchat }, - { "Console:", &config.key_console }, - { "Remote Console:", &config.key_remoteconsole }, + { "Toggle Console:", &config.key_toggleconsole }, { "Screenshot:", &config.key_screenshot }, }; @@ -1530,6 +1544,7 @@ static void menu2_render_settings_sound(RECT main_view) static void menu2_render_settings_network(RECT main_view) { + /* RECT button; ui_vsplit_l(&main_view, 300.0f, &main_view, 0); @@ -1539,7 +1554,7 @@ static void menu2_render_settings_network(RECT main_view) ui_vsplit_l(&button, 110.0f, 0, &button); ui_vsplit_l(&button, 180.0f, &button, 0); ui_do_edit_box(&config.rcon_password, &button, config.rcon_password, sizeof(config.rcon_password), true); - } + }*/ } static void menu2_render_settings(RECT main_view) diff --git a/src/game/g_variables.h b/src/game/g_variables.h index d7848629..b597decf 100644 --- a/src/game/g_variables.h +++ b/src/game/g_variables.h @@ -20,10 +20,10 @@ MACRO_CONFIG_INT(key_emoticon, 'E', 32, 512) MACRO_CONFIG_INT(key_chat, 'T', 32, 512) MACRO_CONFIG_INT(key_teamchat, 'Y', 32, 512) -MACRO_CONFIG_INT(key_console, 256+2, 32, 512) -MACRO_CONFIG_INT(key_remoteconsole, 256+3, 32, 512) +/*MACRO_CONFIG_INT(key_console, 256+2, 32, 512) +MACRO_CONFIG_INT(key_remoteconsole, 256+3, 32, 512)*/ -MACRO_CONFIG_INT(key_toggleconsole, 256+4, 32, 512) +MACRO_CONFIG_INT(key_toggleconsole, 256+2, 32, 512) MACRO_CONFIG_INT(cl_predict, 1, 0, 1) diff --git a/src/game/g_vmath.h b/src/game/g_vmath.h index 65f94776..db7f4a50 100644 --- a/src/game/g_vmath.h +++ b/src/game/g_vmath.h @@ -162,6 +162,7 @@ public: vector4_base operator +(const vector4_base &v) const { return vector4_base(x+v.x, y+v.y, z+v.z, w+v.w); } vector4_base operator -(const vector4_base &v) const { return vector4_base(x-v.x, y-v.y, z-v.z, w-v.w); } vector4_base operator -() const { return vector4_base(-x, -y, -z, -w); } + vector4_base operator *(const vector4_base &v) const { return vector4_base(x*v.x, y*v.y, z*v.z, w*v.w); } vector4_base operator *(const T v) const { return vector4_base(x*v, y*v, z*v, w*v); } const vector4_base &operator =(const vector4_base &v) { x = v.x; y = v.y; z = v.z; w = v.w; return *this; } diff --git a/src/game/server/gs_server.cpp b/src/game/server/gs_server.cpp index b95eae97..c37dac01 100644 --- a/src/game/server/gs_server.cpp +++ b/src/game/server/gs_server.cpp @@ -578,7 +578,6 @@ player::player() void player::init() { proximity_radius = phys_size; - dbg_msg("", "%p %d -> %d (init)", this, client_id, -1); client_id = -1; team = -1; // -1 == spectator @@ -2124,7 +2123,6 @@ void mods_client_enter(int client_id) void mods_connected(int client_id) { players[client_id].init(); - dbg_msg("", "%p %d -> %d (mods_connected)", &players[client_id], players[client_id].client_id, client_id); players[client_id].client_id = client_id; //dbg_msg("game", "connected player='%d:%s'", client_id, server_clientname(client_id)); @@ -2153,7 +2151,6 @@ void mods_client_drop(int client_id) gameobj->on_player_death(&players[client_id], 0, -1); world->remove_entity(&players[client_id]); world->core.players[client_id] = 0x0; - dbg_msg("", "%p %d -> %d (mods_client_drop)", &players[client_id], players[client_id].client_id, -1); players[client_id].client_id = -1; } |