diff options
| author | Jakob Fries <jakob.fries@gmail.com> | 2008-02-04 00:13:34 +0000 |
|---|---|---|
| committer | Jakob Fries <jakob.fries@gmail.com> | 2008-02-04 00:13:34 +0000 |
| commit | d76661b3be30a78203438d53bd91657006d930a9 (patch) | |
| tree | f70fcb4dd6128c980dfd8f035d8a8073aa220bcb | |
| parent | be33e56abccb9459419ffa5376774332c06b517d (diff) | |
| download | zcatch-d76661b3be30a78203438d53bd91657006d930a9.tar.gz zcatch-d76661b3be30a78203438d53bd91657006d930a9.zip | |
console now has proper backlog and command history. kill command added. predicted hooks no longer make a sound when hitting a player.
| -rw-r--r-- | src/engine/e_ringbuffer.c | 8 | ||||
| -rw-r--r-- | src/engine/e_ringbuffer.h | 4 | ||||
| -rw-r--r-- | src/game/client/gc_client.cpp | 8 | ||||
| -rw-r--r-- | src/game/client/gc_console.cpp | 122 | ||||
| -rw-r--r-- | src/game/client/gc_hooks.cpp | 2 | ||||
| -rw-r--r-- | src/game/g_protocol.h | 1 | ||||
| -rw-r--r-- | src/game/server/gs_server.cpp | 10 |
7 files changed, 122 insertions, 33 deletions
diff --git a/src/engine/e_ringbuffer.c b/src/engine/e_ringbuffer.c index f6f529f8..9ece9b98 100644 --- a/src/engine/e_ringbuffer.c +++ b/src/engine/e_ringbuffer.c @@ -206,9 +206,11 @@ void *ringbuf_item_ptr(void *p) return ((RBITEM *)p) - 1; } -void *ringbuf_first(RINGBUFFER *rb) -{ - return ringbuf_next(rb, rb->last_alloc+1); +void *ringbuf_first(RINGBUFFER *rb) +{ + if(rb->last_alloc && rb->last_alloc->next) + return ringbuf_next(rb, rb->last_alloc->next+1); + return 0x0; } void *ringbuf_last(RINGBUFFER *rb) diff --git a/src/engine/e_ringbuffer.h b/src/engine/e_ringbuffer.h index 9c2ce9c3..7de5b01e 100644 --- a/src/engine/e_ringbuffer.h +++ b/src/engine/e_ringbuffer.h @@ -1,3 +1,5 @@ +#ifndef _RINGBUFFER_H +#define _RINGBUFFER_H typedef struct { @@ -20,3 +22,5 @@ void *ringbuf_prev(RINGBUFFER *rb, void *current); void *ringbuf_next(RINGBUFFER *rb, void *current); void *ringbuf_first(RINGBUFFER *rb); void *ringbuf_last(RINGBUFFER *rb); + +#endif diff --git a/src/game/client/gc_client.cpp b/src/game/client/gc_client.cpp index 79b50317..7032637f 100644 --- a/src/game/client/gc_client.cpp +++ b/src/game/client/gc_client.cpp @@ -334,6 +334,14 @@ void send_emoticon(int emoticon) client_send_msg(); } +void send_kill(int client_id) +{ + msg_pack_start(MSG_KILL, MSGFLAG_VITAL); + msg_pack_int(client_id); + msg_pack_end(); + client_send_msg(); +} + void anim_seq_eval(sequence *seq, float time, keyframe *frame) { if(seq->num_frames == 0) diff --git a/src/game/client/gc_console.cpp b/src/game/client/gc_console.cpp index d462156b..4b70739f 100644 --- a/src/game/client/gc_console.cpp +++ b/src/game/client/gc_console.cpp @@ -5,6 +5,7 @@ extern "C" { #include <engine/e_client_interface.h> #include <engine/e_config.h> #include <engine/e_console.h> + #include <engine/e_ringbuffer.h> #include <engine/client/ec_font.h> } @@ -24,23 +25,24 @@ enum CONSOLE_CLOSING, }; +static char console_history_data[65536]; +static RINGBUFFER *console_history; + +static char console_backlog_data[65536]; +static RINGBUFFER *console_backlog; + static unsigned int console_input_len = 0; static char console_input[256] = {0}; static int console_state = CONSOLE_CLOSED; static float state_change_end = 0.0f; static const float state_change_duration = 0.1f; -static char backlog[256][256] = {{0}}; -static int backlog_len; - static float time_now() { static long long time_start = time_get(); return float(time_get()-time_start)/float(time_freq()); } - - static void client_console_print(const char *str) { int len = strlen(str); @@ -48,24 +50,8 @@ static void client_console_print(const char *str) if (len > 255) len = 255; - if (backlog_len >= 256) - { - static int warning = 0; - if (!warning) - { - puts("console backlog full"); - warning = 1; - } - - return; - } - - memcpy(backlog[backlog_len], str, len); - backlog[backlog_len][len] = 0; - - backlog_len++; - - //dbg_msg("console", "FROM CLIENT!! %s", str); + char *entry = (char *)ringbuf_allocate(console_backlog, len+1); + memcpy(entry, str, len+1); } @@ -76,12 +62,37 @@ static void con_team(void *result, void *user_data) send_switch_team(new_team); } +static void command_history(void *result, void *user_data) +{ + char *entry = (char *)ringbuf_first(console_history); + + while (entry) + { + dbg_msg("console/history", entry); + + entry = (char *)ringbuf_next(console_history, entry); + } +} + +void send_kill(int client_id); + +static void command_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); } +static char *console_history_entry = 0x0; void console_handle_input() { @@ -105,6 +116,8 @@ void console_handle_input() console_input[console_input_len] = e.ch; console_input[console_input_len+1] = 0; console_input_len++; + + console_history_entry = 0x0; } } @@ -114,15 +127,67 @@ void console_handle_input() { 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); + memcpy(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) + { + memcpy(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) + { + memcpy(console_input, console_history_entry, len+1); + + console_input_len = len; + } + } + else + { + console_input[0] = 0; + console_input_len = 0; } } } @@ -208,7 +273,6 @@ void console_render() float row_height = font_size*1.4f; float width = gfx_text_width(0, font_size, console_input, -1); float x = 3, y = console_height - row_height - 2; - int backlog_index = backlog_len-1; float prompt_width = gfx_text_width(0, font_size, ">", -1)+2; gfx_text(0, x, y, font_size, ">", -1); @@ -222,13 +286,13 @@ void console_render() y -= row_height; - while (y > 0.0f && backlog_index >= 0) + char *entry = (char *)ringbuf_last(console_backlog); + while (y > 0.0f && entry) { - const char *line = backlog[backlog_index]; - gfx_text(0, x, y, font_size, line, -1); - - backlog_index--; + gfx_text(0, x, y, font_size, entry, -1); y -= row_height; + + entry = (char *)ringbuf_prev(console_backlog, entry); } } } diff --git a/src/game/client/gc_hooks.cpp b/src/game/client/gc_hooks.cpp index 0acd1c41..f04af5cb 100644 --- a/src/game/client/gc_hooks.cpp +++ b/src/game/client/gc_hooks.cpp @@ -186,7 +186,7 @@ extern "C" void modc_predict() snd_play_random(CHN_WORLD, SOUND_PLAYER_AIRJUMP, 1.0f, pos); } //if(events&COREEVENT_HOOK_LAUNCH) snd_play_random(CHN_WORLD, SOUND_HOOK_LOOP, 1.0f, pos); - if(events&COREEVENT_HOOK_ATTACH_PLAYER) snd_play_random(CHN_WORLD, SOUND_HOOK_ATTACH_PLAYER, 1.0f, pos); + //if(events&COREEVENT_HOOK_ATTACH_PLAYER) snd_play_random(CHN_WORLD, SOUND_HOOK_ATTACH_PLAYER, 1.0f, pos); if(events&COREEVENT_HOOK_ATTACH_GROUND) snd_play_random(CHN_WORLD, SOUND_HOOK_ATTACH_GROUND, 1.0f, pos); //if(events&COREEVENT_HOOK_RETRACT) snd_play_random(CHN_WORLD, SOUND_PLAYER_JUMP, 1.0f, pos); } diff --git a/src/game/g_protocol.h b/src/game/g_protocol.h index f7d26900..ada685bb 100644 --- a/src/game/g_protocol.h +++ b/src/game/g_protocol.h @@ -43,6 +43,7 @@ enum MSG_WEAPON_PICKUP, MSG_SOUND_GLOBAL, MSG_TUNE_PARAMS, + MSG_KILL, }; enum diff --git a/src/game/server/gs_server.cpp b/src/game/server/gs_server.cpp index c21af02c..4a95406e 100644 --- a/src/game/server/gs_server.cpp +++ b/src/game/server/gs_server.cpp @@ -1320,6 +1320,9 @@ void player::tick_defered() void player::die(int killer, int weapon) { + if (dead || team == -1) + return; + int mode_special = gameobj->on_player_death(this, get_player(killer), weapon); dbg_msg("game", "kill killer='%d:%s' victim='%d:%s' weapon=%d special=%d", @@ -2067,6 +2070,13 @@ void mods_message(int msg, int client_id) int emoteicon = msg_unpack_int(); send_emoticon(client_id, emoteicon % 16); } + else if (msg == MSG_KILL) + { + //int kill_client_id = msg_unpack_int(); // to be used to kill players from rcon? hihi + + player *pplayer = get_player(client_id); + pplayer->die(client_id, -1); + } } extern unsigned char internal_data[]; |