diff --git a/command.h b/command.h index ddb9a2dcf9..19d36fb9c0 100644 --- a/command.h +++ b/command.h @@ -202,6 +202,8 @@ enum event_command CMD_EVENT_NETPLAY_DEINIT, /* Switch between netplay gaming and watching. */ CMD_EVENT_NETPLAY_GAME_WATCH, + /* Open a netplay chat input menu. */ + CMD_EVENT_NETPLAY_PLAYER_CHAT, /* Start hosting netplay. */ CMD_EVENT_NETPLAY_ENABLE_HOST, /* Disconnect from the netplay host. */ diff --git a/network/netplay/netplay.h b/network/netplay/netplay.h index b505021e4f..8f811ca057 100644 --- a/network/netplay/netplay.h +++ b/network/netplay/netplay.h @@ -43,6 +43,7 @@ enum rarch_netplay_ctl_state { RARCH_NETPLAY_CTL_NONE = 0, RARCH_NETPLAY_CTL_GAME_WATCH, + RARCH_NETPLAY_CTL_PLAYER_CHAT, RARCH_NETPLAY_CTL_POST_FRAME, RARCH_NETPLAY_CTL_PRE_FRAME, RARCH_NETPLAY_CTL_ENABLE_SERVER, @@ -188,7 +189,6 @@ typedef struct { netplay_t *data; /* Used while Netplay is running */ struct netplay_room host_room; /* ptr alignment */ - netplay_t *ref; struct netplay_room *room_list; struct netplay_rooms *rooms_data; /* List of discovered hosts */ diff --git a/network/netplay/netplay_frontend.c b/network/netplay/netplay_frontend.c index a227b9484d..6be97dbaba 100644 --- a/network/netplay/netplay_frontend.c +++ b/network/netplay/netplay_frontend.c @@ -893,9 +893,14 @@ static void handshake_password(void *ignore, const char *line) struct password_buf_s password_buf; char password[8+NETPLAY_PASS_LEN]; /* 8 for salt, 128 for password */ char hash[NETPLAY_PASS_HASH_LEN+1]; /* + NULL terminator */ + struct netplay_connection *connection; net_driver_state_t *net_st = &networking_driver_st; - netplay_t *netplay = net_st->ref; - struct netplay_connection *connection = &netplay->connections[0]; + netplay_t *netplay = net_st->data; + + if (!netplay) + return; + + connection = &netplay->connections[0]; snprintf(password, sizeof(password), "%08lX", (unsigned long)connection->salt); if (!string_is_empty(line)) @@ -1071,11 +1076,6 @@ bool netplay_handshake_init(netplay_t *netplay, #ifdef HAVE_MENU menu_input_ctx_line_t line; retroarch_menu_running(); -#endif - - net_st->ref = netplay; - -#ifdef HAVE_MENU memset(&line, 0, sizeof(line)); line.label = msg_hash_to_str(MSG_NETPLAY_ENTER_PASSWORD); line.label_setting = "no_setting"; @@ -4470,7 +4470,7 @@ static void send_chat(void *userdata, const char *line) char chat_msg[MAX_CHAT_SIZE]; size_t chat_len; net_driver_state_t *net_st = &networking_driver_st; - netplay_t *netplay = net_st->ref; + netplay_t *netplay = net_st->data; /* We perform the same checks, just in case something has changed. */ @@ -4512,8 +4512,6 @@ void netplay_input_chat(netplay_t *netplay) retroarch_menu_running(); - net_st->ref = netplay; - chat_input.label = msg_hash_to_str(MSG_NETPLAY_ENTER_CHAT); chat_input.label_setting = "no_setting"; chat_input.cb = send_chat; @@ -7731,6 +7729,9 @@ bool netplay_driver_ctl(enum rarch_netplay_ctl_state state, void *data) case RARCH_NETPLAY_CTL_GAME_WATCH: netplay_toggle_play_spectate(netplay); break; + case RARCH_NETPLAY_CTL_PLAYER_CHAT: + netplay_input_chat(netplay); + break; case RARCH_NETPLAY_CTL_PAUSE: if (netplay->local_paused != true) netplay_frontend_paused(netplay, true); diff --git a/retroarch.c b/retroarch.c index d26365455c..bcd71036fa 100644 --- a/retroarch.c +++ b/retroarch.c @@ -5295,6 +5295,9 @@ bool command_event(enum event_command cmd, void *data) case CMD_EVENT_NETPLAY_GAME_WATCH: netplay_driver_ctl(RARCH_NETPLAY_CTL_GAME_WATCH, NULL); break; + case CMD_EVENT_NETPLAY_PLAYER_CHAT: + netplay_driver_ctl(RARCH_NETPLAY_CTL_PLAYER_CHAT, NULL); + break; case CMD_EVENT_NETPLAY_DEINIT: deinit_netplay(); break; @@ -5531,6 +5534,7 @@ bool command_event(enum event_command cmd, void *data) case CMD_EVENT_NETPLAY_DISCONNECT: case CMD_EVENT_NETPLAY_ENABLE_HOST: case CMD_EVENT_NETPLAY_GAME_WATCH: + case CMD_EVENT_NETPLAY_PLAYER_CHAT: return false; #endif case CMD_EVENT_FULLSCREEN_TOGGLE: @@ -15568,6 +15572,9 @@ static enum runloop_state_enum runloop_check_state( #ifdef HAVE_NETWORKING /* Check Netplay */ HOTKEY_CHECK(RARCH_NETPLAY_GAME_WATCH, CMD_EVENT_NETPLAY_GAME_WATCH, true, NULL); +#if NETPLAY_PROTOCOL_VERSION >= 6 + HOTKEY_CHECK(RARCH_NETPLAY_PLAYER_CHAT, CMD_EVENT_NETPLAY_PLAYER_CHAT, true, NULL); +#endif #endif /* Check if we have pressed the pause button */