From 57b2c49d571ac160d03b9bc30b6eb72976bfe82a Mon Sep 17 00:00:00 2001 From: Magnus Auvinen Date: Mon, 15 Jun 2009 13:16:33 +0000 Subject: [PATCH] fixed so that the demo player doesn't crash when the map isn't found --- src/engine/client/ec_client.c | 15 ++++++++++++--- src/engine/e_if_client.h | 2 +- src/game/client/components/menus.cpp | 17 ++++++++++++++++- src/game/client/components/menus.hpp | 8 ++++++++ src/game/client/components/menus_demo.cpp | 6 +++++- 5 files changed, 42 insertions(+), 6 deletions(-) diff --git a/src/engine/client/ec_client.c b/src/engine/client/ec_client.c index 07117b37c..e741958fa 100644 --- a/src/engine/client/ec_client.c +++ b/src/engine/client/ec_client.c @@ -1902,9 +1902,10 @@ static void con_addfavorite(void *result, void *user_data) client_serverbrowse_addfavorite(addr); } -void client_demoplayer_play(const char *filename) +const char *client_demoplayer_play(const char *filename) { int crc; + const char *error; client_disconnect(); netclient_error_string_reset(net); @@ -1912,14 +1913,20 @@ void client_demoplayer_play(const char *filename) demorec_playback_registercallbacks(client_democallback_snapshot, client_democallback_message); if(demorec_playback_load(filename)) - return; + return "error loading demo"; /* load map */ crc = (demorec_playback_info()->header.crc[0]<<24)| (demorec_playback_info()->header.crc[1]<<16)| (demorec_playback_info()->header.crc[2]<<8)| (demorec_playback_info()->header.crc[3]); - client_load_map_search(demorec_playback_info()->header.map, crc); + error = client_load_map_search(demorec_playback_info()->header.map, crc); + if(error) + { + client_disconnect_with_reason(error); + return error; + } + modc_connected(); /* setup buffers */ @@ -1943,6 +1950,8 @@ void client_demoplayer_play(const char *filename) demorec_playback_play(); modc_entergame(); + + return 0; } static void con_play(void *result, void *user_data) diff --git a/src/engine/e_if_client.h b/src/engine/e_if_client.h index 319c3dead..86c6f5fcf 100644 --- a/src/engine/e_if_client.h +++ b/src/engine/e_if_client.h @@ -567,7 +567,7 @@ typedef struct DEMOPLAYBACK_INFO float speed; } DEMOPLAYBACK_INFO; -void client_demoplayer_play(const char *filename); +const char *client_demoplayer_play(const char *filename); const DEMOPLAYBACK_INFO *client_demoplayer_getinfo(); void client_demoplayer_setpos(float percent); void client_demoplayer_setpause(int paused); diff --git a/src/game/client/components/menus.cpp b/src/game/client/components/menus.cpp index 1748fe181..168c514d6 100644 --- a/src/game/client/components/menus.cpp +++ b/src/game/client/components/menus.cpp @@ -666,6 +666,15 @@ void MENUS::on_init() config.cl_show_welcome = 0; } +void MENUS::popup_message(const char *topic, const char *body, const char *button) +{ + str_copy(message_topic, topic, sizeof(message_topic)); + str_copy(message_body, body, sizeof(message_body)); + str_copy(message_button, button, sizeof(message_button)); + popup = POPUP_MESSAGE; +} + + int MENUS::render() { RECT screen = *ui_screen(); @@ -749,7 +758,13 @@ int MENUS::render() const char *button_text = ""; int extra_align = 0; - if(popup == POPUP_CONNECTING) + if(popup == POPUP_MESSAGE) + { + title = message_topic; + extra_text = message_body; + button_text = message_button; + } + else if(popup == POPUP_CONNECTING) { title = localize("Connecting to"); extra_text = config.ui_server_address; // TODO: query the client about the address diff --git a/src/game/client/components/menus.hpp b/src/game/client/components/menus.hpp index 3ca3ee433..15369dbc9 100644 --- a/src/game/client/components/menus.hpp +++ b/src/game/client/components/menus.hpp @@ -68,6 +68,7 @@ class MENUS : public COMPONENT POPUP_NONE=0, POPUP_FIRST_LAUNCH, POPUP_CONNECTING, + POPUP_MESSAGE, POPUP_DISCONNECTED, POPUP_PURE, POPUP_PASSWORD, @@ -95,6 +96,13 @@ class MENUS : public COMPONENT vec2 mouse_pos; int64 last_input; + + // + char message_topic[512]; + char message_body[512]; + char message_button[512]; + + void popup_message(const char *topic, const char *body, const char *button); // TODO: this is a bit ugly but.. well.. yeah enum { MAX_INPUTEVENTS = 32 }; diff --git a/src/game/client/components/menus_demo.cpp b/src/game/client/components/menus_demo.cpp index 3a22fde2d..efcf05b81 100644 --- a/src/game/client/components/menus_demo.cpp +++ b/src/game/client/components/menus_demo.cpp @@ -406,7 +406,11 @@ void MENUS::render_demolist(RECT main_view) if(ui_do_button(&play_button, localize("Play"), 0, &play_rect, ui_draw_menu_button, 0)) { if(selected_item >= 0 && selected_item < demos.size()) - client_demoplayer_play(demos[selected_item].filename); + { + const char *error = client_demoplayer_play(demos[selected_item].filename); + if(error) + popup_message(localize("Error"), error, localize("Ok")); + } } }