mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-20 06:58:20 +00:00
fixed so that the demo player doesn't crash when the map isn't found
This commit is contained in:
parent
feade98dae
commit
57b2c49d57
|
@ -1902,9 +1902,10 @@ static void con_addfavorite(void *result, void *user_data)
|
||||||
client_serverbrowse_addfavorite(addr);
|
client_serverbrowse_addfavorite(addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void client_demoplayer_play(const char *filename)
|
const char *client_demoplayer_play(const char *filename)
|
||||||
{
|
{
|
||||||
int crc;
|
int crc;
|
||||||
|
const char *error;
|
||||||
client_disconnect();
|
client_disconnect();
|
||||||
netclient_error_string_reset(net);
|
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);
|
demorec_playback_registercallbacks(client_democallback_snapshot, client_democallback_message);
|
||||||
|
|
||||||
if(demorec_playback_load(filename))
|
if(demorec_playback_load(filename))
|
||||||
return;
|
return "error loading demo";
|
||||||
|
|
||||||
/* load map */
|
/* load map */
|
||||||
crc = (demorec_playback_info()->header.crc[0]<<24)|
|
crc = (demorec_playback_info()->header.crc[0]<<24)|
|
||||||
(demorec_playback_info()->header.crc[1]<<16)|
|
(demorec_playback_info()->header.crc[1]<<16)|
|
||||||
(demorec_playback_info()->header.crc[2]<<8)|
|
(demorec_playback_info()->header.crc[2]<<8)|
|
||||||
(demorec_playback_info()->header.crc[3]);
|
(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();
|
modc_connected();
|
||||||
|
|
||||||
/* setup buffers */
|
/* setup buffers */
|
||||||
|
@ -1943,6 +1950,8 @@ void client_demoplayer_play(const char *filename)
|
||||||
|
|
||||||
demorec_playback_play();
|
demorec_playback_play();
|
||||||
modc_entergame();
|
modc_entergame();
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void con_play(void *result, void *user_data)
|
static void con_play(void *result, void *user_data)
|
||||||
|
|
|
@ -567,7 +567,7 @@ typedef struct DEMOPLAYBACK_INFO
|
||||||
float speed;
|
float speed;
|
||||||
} DEMOPLAYBACK_INFO;
|
} DEMOPLAYBACK_INFO;
|
||||||
|
|
||||||
void client_demoplayer_play(const char *filename);
|
const char *client_demoplayer_play(const char *filename);
|
||||||
const DEMOPLAYBACK_INFO *client_demoplayer_getinfo();
|
const DEMOPLAYBACK_INFO *client_demoplayer_getinfo();
|
||||||
void client_demoplayer_setpos(float percent);
|
void client_demoplayer_setpos(float percent);
|
||||||
void client_demoplayer_setpause(int paused);
|
void client_demoplayer_setpause(int paused);
|
||||||
|
|
|
@ -666,6 +666,15 @@ void MENUS::on_init()
|
||||||
config.cl_show_welcome = 0;
|
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()
|
int MENUS::render()
|
||||||
{
|
{
|
||||||
RECT screen = *ui_screen();
|
RECT screen = *ui_screen();
|
||||||
|
@ -749,7 +758,13 @@ int MENUS::render()
|
||||||
const char *button_text = "";
|
const char *button_text = "";
|
||||||
int extra_align = 0;
|
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");
|
title = localize("Connecting to");
|
||||||
extra_text = config.ui_server_address; // TODO: query the client about the address
|
extra_text = config.ui_server_address; // TODO: query the client about the address
|
||||||
|
|
|
@ -68,6 +68,7 @@ class MENUS : public COMPONENT
|
||||||
POPUP_NONE=0,
|
POPUP_NONE=0,
|
||||||
POPUP_FIRST_LAUNCH,
|
POPUP_FIRST_LAUNCH,
|
||||||
POPUP_CONNECTING,
|
POPUP_CONNECTING,
|
||||||
|
POPUP_MESSAGE,
|
||||||
POPUP_DISCONNECTED,
|
POPUP_DISCONNECTED,
|
||||||
POPUP_PURE,
|
POPUP_PURE,
|
||||||
POPUP_PASSWORD,
|
POPUP_PASSWORD,
|
||||||
|
@ -95,6 +96,13 @@ class MENUS : public COMPONENT
|
||||||
vec2 mouse_pos;
|
vec2 mouse_pos;
|
||||||
|
|
||||||
int64 last_input;
|
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
|
// TODO: this is a bit ugly but.. well.. yeah
|
||||||
enum { MAX_INPUTEVENTS = 32 };
|
enum { MAX_INPUTEVENTS = 32 };
|
||||||
|
|
|
@ -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(ui_do_button(&play_button, localize("Play"), 0, &play_rect, ui_draw_menu_button, 0))
|
||||||
{
|
{
|
||||||
if(selected_item >= 0 && selected_item < demos.size())
|
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"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue