Codechange: use NetworkAddress instead of two host/port variables where possible

This also means we no longer need last_host/last_port, but can
just use a single last_joined setting.
This commit is contained in:
Patric Stout
2021-04-29 12:09:03 +02:00
committed by Patric Stout
parent 99f998805b
commit be37a2cab8
11 changed files with 112 additions and 141 deletions

View File

@@ -473,29 +473,21 @@ struct AfterNewGRFScan : NewGRFScanCallback {
if (_switch_mode != SM_NONE) MakeNewgameSettingsLive();
if (_network_available && network_conn != nullptr) {
const char *port = nullptr;
const char *company = nullptr;
uint16 rport = NETWORK_DEFAULT_PORT;
CompanyID join_as = COMPANY_NEW_COMPANY;
NetworkAddress address = ParseGameConnectionString(&join_as, network_conn, NETWORK_DEFAULT_PORT);
ParseGameConnectionString(&company, &port, network_conn);
if (company != nullptr) {
join_as = (CompanyID)atoi(company);
if (join_as != COMPANY_SPECTATOR) {
join_as--;
if (join_as >= MAX_COMPANIES) {
delete this;
return;
}
if (join_as != COMPANY_NEW_COMPANY && join_as != COMPANY_SPECTATOR) {
join_as--;
if (join_as >= MAX_COMPANIES) {
delete this;
return;
}
}
if (port != nullptr) rport = atoi(port);
LoadIntroGame();
_switch_mode = SM_NONE;
NetworkClientConnectGame(network_conn, rport, join_as, join_server_password, join_company_password);
NetworkClientConnectGame(address, join_as, join_server_password, join_company_password);
}
/* After the scan we're not used anymore. */
@@ -585,7 +577,7 @@ int openttd_main(int argc, char *argv[])
SetDebugString("net=6");
if (mgo.opt != nullptr) {
const char *port = nullptr;
ParseConnectionString(&port, mgo.opt);
ParseFullConnectionString(nullptr, &port, mgo.opt);
if (!StrEmpty(mgo.opt)) scanner->dedicated_host = mgo.opt;
if (port != nullptr) scanner->dedicated_port = atoi(port);
}
@@ -771,15 +763,8 @@ int openttd_main(int argc, char *argv[])
NetworkStartUp(); // initialize network-core
if (debuglog_conn != nullptr && _network_available) {
const char *port = nullptr;
uint16 rport;
rport = NETWORK_DEFAULT_DEBUGLOG_PORT;
ParseConnectionString(&port, debuglog_conn);
if (port != nullptr) rport = atoi(port);
NetworkStartDebugLog(debuglog_conn, rport);
NetworkAddress address = ParseConnectionString(debuglog_conn, NETWORK_DEFAULT_DEBUGLOG_PORT);
NetworkStartDebugLog(address);
}
if (!HandleBootstrap()) {
@@ -1491,7 +1476,8 @@ void GameLoop()
if (_network_reconnect > 0 && --_network_reconnect == 0) {
/* This means that we want to reconnect to the last host
* We do this here, because it means that the network is really closed */
NetworkClientConnectGame(_settings_client.network.last_host, _settings_client.network.last_port, COMPANY_SPECTATOR);
NetworkAddress address = ParseConnectionString(_settings_client.network.last_joined, NETWORK_DEFAULT_PORT);
NetworkClientConnectGame(address, COMPANY_SPECTATOR);
}
/* Singleplayer */
StateGameLoop();