1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2025-12-10 09:32:29 +01:00

Add "Reconnect" option under the multiplayer button

This commit is contained in:
Xkeeper
2019-02-04 21:57:09 -08:00
committed by Aaron van Geffen
parent d614fb4035
commit bc8ecd8e67
5 changed files with 42 additions and 3 deletions

View File

@@ -3756,6 +3756,7 @@ STR_6305 :Multithreading
STR_6306 :{SMALLFONT}{BLACK}Experimental option to use multiple threads to render, may cause instability.
STR_6307 :Colour scheme: {BLACK}{STRINGID}
STR_6308 :“{STRINGID}{OUTLINE}{TOPAZ}”{NEWLINE}{STRINGID}
STR_6309 :Reconnect
#############
# Scenarios #

View File

@@ -152,6 +152,9 @@ enum TOP_TOOLBAR_DEBUG_DDIDX {
enum TOP_TOOLBAR_NETWORK_DDIDX {
DDIDX_MULTIPLAYER = 0,
DDIDX_NETWORK = 1,
DDIDX_MULTIPLAYER_RECONNECT = 2,
TOP_TOOLBAR_NETWORK_COUNT
};
enum {
@@ -3415,13 +3418,13 @@ static void top_toolbar_init_debug_menu(rct_window* w, rct_widget* widget)
static void top_toolbar_init_network_menu(rct_window* w, rct_widget* widget)
{
gDropdownItemsFormat[0] = STR_MULTIPLAYER;
gDropdownItemsFormat[DDIDX_MULTIPLAYER] = STR_MULTIPLAYER;
gDropdownItemsFormat[DDIDX_NETWORK] = STR_NETWORK;
gDropdownItemsFormat[DDIDX_MULTIPLAYER_RECONNECT] = STR_MULTIPLAYER_RECONNECT;
window_dropdown_show_text(
w->x + widget->left, w->y + widget->top, widget->bottom - widget->top + 1, w->colours[0] | 0x80, 0, 2);
w->x + widget->left, w->y + widget->top, widget->bottom - widget->top + 1, w->colours[0] | 0x80, 0,
TOP_TOOLBAR_NETWORK_COUNT);
gDropdownDefaultIndex = DDIDX_MULTIPLAYER;
}
@@ -3466,6 +3469,9 @@ static void top_toolbar_network_menu_dropdown(int16_t dropdownIndex)
case DDIDX_NETWORK:
context_open_window(WC_NETWORK);
break;
case DDIDX_MULTIPLAYER_RECONNECT:
network_reconnect();
break;
}
}
}

View File

@@ -3941,6 +3941,8 @@ enum
STR_MAP_TOOLTIP_BANNER_STRINGID_STRINGID = 6308,
STR_MULTIPLAYER_RECONNECT = 6309,
// Have to include resource strings (from scenarios and objects) for the time being now that language is partially working
STR_COUNT = 32768
};

View File

@@ -113,6 +113,7 @@ public:
void SetEnvironment(const std::shared_ptr<OpenRCT2::IPlatformEnvironment>& env);
bool Init();
void Reconnect();
void Close();
bool BeginClient(const std::string& host, uint16_t port);
bool BeginServer(uint16_t port, const std::string& address);
@@ -299,6 +300,7 @@ private:
int32_t status = NETWORK_STATUS_NONE;
bool _closeLock = false;
bool _requireClose = false;
bool _requireReconnect = false;
bool wsa_initialized = false;
bool _clientMapLoaded = false;
std::unique_ptr<ITcpSocket> _listenSocket;
@@ -312,6 +314,8 @@ private:
std::list<std::unique_ptr<NetworkConnection>> client_connection_list;
std::multiset<GameCommand> game_command_queue;
std::vector<uint8_t> chunk_buffer;
std::string _host;
uint16_t _port = 0;
std::string _password;
bool _desynchronised = false;
uint32_t server_connect_time = 0;
@@ -430,6 +434,20 @@ bool Network::Init()
return true;
}
void Network::Reconnect()
{
if (status != NETWORK_STATUS_NONE)
{
Close();
}
if (_requireClose)
{
_requireReconnect = true;
return;
}
BeginClient(_host, _port);
}
void Network::Close()
{
if (status != NETWORK_STATUS_NONE)
@@ -508,6 +526,8 @@ bool Network::BeginClient(const std::string& host, uint16_t port)
mode = NETWORK_MODE_CLIENT;
log_info("Connecting to %s:%u\n", host.c_str(), port);
_host = host;
_port = port;
_serverConnection = std::make_unique<NetworkConnection>();
_serverConnection->Socket = CreateTcpSocket();
@@ -715,6 +735,10 @@ void Network::Update()
if (_requireClose)
{
Close();
if (_requireReconnect)
{
Reconnect();
}
}
}
@@ -3159,6 +3183,11 @@ void network_close()
gNetwork.Close();
}
void network_reconnect()
{
gNetwork.Reconnect();
}
void network_shutdown_client()
{
gNetwork.ShutdownClient();

View File

@@ -31,6 +31,7 @@ namespace OpenRCT2
void network_set_env(const std::shared_ptr<OpenRCT2::IPlatformEnvironment>& env);
void network_close();
void network_reconnect();
void network_shutdown_client();
int32_t network_begin_client(const std::string& host, int32_t port);
int32_t network_begin_server(int32_t port, const std::string& address);