Update to 1.10.0-beta1
This commit is contained in:
@@ -11,8 +11,6 @@
|
||||
|
||||
#include "../stdafx.h"
|
||||
|
||||
#ifdef ENABLE_NETWORK
|
||||
|
||||
#include "../strings_func.h"
|
||||
#include "../command_func.h"
|
||||
#include "../date_func.h"
|
||||
@@ -59,7 +57,7 @@ bool _network_available; ///< is network mode available?
|
||||
bool _network_dedicated; ///< are we a dedicated server?
|
||||
bool _is_network_server; ///< Does this client wants to be a network-server?
|
||||
NetworkServerGameInfo _network_game_info; ///< Information about our game.
|
||||
NetworkCompanyState *_network_company_states = NULL; ///< Statistics about some companies.
|
||||
NetworkCompanyState *_network_company_states = nullptr; ///< Statistics about some companies.
|
||||
ClientID _network_own_client_id; ///< Our client identifier.
|
||||
ClientID _redirect_console_to_client; ///< If not invalid, redirect the console output to a client.
|
||||
bool _network_need_advertise; ///< Whether we need to advertise.
|
||||
@@ -121,7 +119,7 @@ NetworkClientInfo::~NetworkClientInfo()
|
||||
/**
|
||||
* Return the CI given it's client-identifier
|
||||
* @param client_id the ClientID to search for
|
||||
* @return return a pointer to the corresponding NetworkClientInfo struct or NULL when not found
|
||||
* @return return a pointer to the corresponding NetworkClientInfo struct or nullptr when not found
|
||||
*/
|
||||
/* static */ NetworkClientInfo *NetworkClientInfo::GetByClientID(ClientID client_id)
|
||||
{
|
||||
@@ -131,13 +129,13 @@ NetworkClientInfo::~NetworkClientInfo()
|
||||
if (ci->client_id == client_id) return ci;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the client state given it's client-identifier
|
||||
* @param client_id the ClientID to search for
|
||||
* @return return a pointer to the corresponding NetworkClientSocket struct or NULL when not found
|
||||
* @return return a pointer to the corresponding NetworkClientSocket struct or nullptr when not found
|
||||
*/
|
||||
/* static */ ServerNetworkGameSocketHandler *ServerNetworkGameSocketHandler::GetByClientID(ClientID client_id)
|
||||
{
|
||||
@@ -147,7 +145,7 @@ NetworkClientInfo::~NetworkClientInfo()
|
||||
if (cs->client_id == client_id) return cs;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
byte NetworkSpectatorCount()
|
||||
@@ -380,7 +378,7 @@ void NetworkHandlePauseChange(PauseMode prev_mode, PauseMode changed_mode)
|
||||
|
||||
char buffer[DRAW_STRING_BUFFER];
|
||||
GetString(buffer, str, lastof(buffer));
|
||||
NetworkTextMessage(NETWORK_ACTION_SERVER_MESSAGE, CC_DEFAULT, false, NULL, buffer);
|
||||
NetworkTextMessage(NETWORK_ACTION_SERVER_MESSAGE, CC_DEFAULT, false, nullptr, buffer);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -543,7 +541,7 @@ void NetworkClose(bool close_admins)
|
||||
}
|
||||
ServerNetworkGameSocketHandler::CloseListeners();
|
||||
ServerNetworkAdminSocketHandler::CloseListeners();
|
||||
} else if (MyClient::my_client != NULL) {
|
||||
} else if (MyClient::my_client != nullptr) {
|
||||
MyClient::SendQuit();
|
||||
MyClient::my_client->CloseConnection(NETWORK_RECV_STATUS_CONN_LOST);
|
||||
}
|
||||
@@ -556,7 +554,7 @@ void NetworkClose(bool close_admins)
|
||||
NetworkFreeLocalCommandQueue();
|
||||
|
||||
free(_network_company_states);
|
||||
_network_company_states = NULL;
|
||||
_network_company_states = nullptr;
|
||||
|
||||
InitializeNetworkPools(close_admins);
|
||||
}
|
||||
@@ -578,12 +576,12 @@ class TCPQueryConnecter : TCPConnecter {
|
||||
public:
|
||||
TCPQueryConnecter(const NetworkAddress &address) : TCPConnecter(address) {}
|
||||
|
||||
virtual void OnFailure()
|
||||
void OnFailure() override
|
||||
{
|
||||
NetworkDisconnect();
|
||||
}
|
||||
|
||||
virtual void OnConnect(SOCKET s)
|
||||
void OnConnect(SOCKET s) override
|
||||
{
|
||||
_networking = true;
|
||||
new ClientNetworkGameSocketHandler(s);
|
||||
@@ -610,8 +608,8 @@ void NetworkTCPQueryServer(NetworkAddress address)
|
||||
void NetworkAddServer(const char *b)
|
||||
{
|
||||
if (*b != '\0') {
|
||||
const char *port = NULL;
|
||||
const char *company = NULL;
|
||||
const char *port = nullptr;
|
||||
const char *company = nullptr;
|
||||
char host[NETWORK_HOSTNAME_LENGTH];
|
||||
uint16 rport;
|
||||
|
||||
@@ -621,7 +619,7 @@ void NetworkAddServer(const char *b)
|
||||
rport = NETWORK_DEFAULT_PORT;
|
||||
|
||||
ParseConnectionString(&company, &port, host);
|
||||
if (port != NULL) rport = atoi(port);
|
||||
if (port != nullptr) rport = atoi(port);
|
||||
|
||||
NetworkUDPQueryServer(NetworkAddress(host, rport), true);
|
||||
}
|
||||
@@ -634,13 +632,13 @@ void NetworkAddServer(const char *b)
|
||||
*/
|
||||
void GetBindAddresses(NetworkAddressList *addresses, uint16 port)
|
||||
{
|
||||
for (char **iter = _network_bind_list.Begin(); iter != _network_bind_list.End(); iter++) {
|
||||
*addresses->Append() = NetworkAddress(*iter, port);
|
||||
for (const auto &iter : _network_bind_list) {
|
||||
addresses->emplace_back(iter.c_str(), port);
|
||||
}
|
||||
|
||||
/* No address, so bind to everything. */
|
||||
if (addresses->Length() == 0) {
|
||||
*addresses->Append() = NetworkAddress("", port);
|
||||
if (addresses->size() == 0) {
|
||||
addresses->emplace_back("", port);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -649,10 +647,10 @@ void GetBindAddresses(NetworkAddressList *addresses, uint16 port)
|
||||
* by the function that generates the config file. */
|
||||
void NetworkRebuildHostList()
|
||||
{
|
||||
_network_host_list.Clear();
|
||||
_network_host_list.clear();
|
||||
|
||||
for (NetworkGameList *item = _network_game_list; item != NULL; item = item->next) {
|
||||
if (item->manually) *_network_host_list.Append() = stredup(item->address.GetAddressAsString(false));
|
||||
for (NetworkGameList *item = _network_game_list; item != nullptr; item = item->next) {
|
||||
if (item->manually) _network_host_list.emplace_back(item->address.GetAddressAsString(false));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -661,12 +659,12 @@ class TCPClientConnecter : TCPConnecter {
|
||||
public:
|
||||
TCPClientConnecter(const NetworkAddress &address) : TCPConnecter(address) {}
|
||||
|
||||
virtual void OnFailure()
|
||||
void OnFailure() override
|
||||
{
|
||||
NetworkError(STR_NETWORK_ERROR_NOCONNECTION);
|
||||
}
|
||||
|
||||
virtual void OnConnect(SOCKET s)
|
||||
void OnConnect(SOCKET s) override
|
||||
{
|
||||
_networking = true;
|
||||
new ClientNetworkGameSocketHandler(s);
|
||||
@@ -886,21 +884,21 @@ void NetworkGameLoop()
|
||||
static FILE *f = FioFOpenFile("commands.log", "rb", SAVE_DIR);
|
||||
static Date next_date = 0;
|
||||
static uint32 next_date_fract;
|
||||
static CommandPacket *cp = NULL;
|
||||
static CommandPacket *cp = nullptr;
|
||||
static bool check_sync_state = false;
|
||||
static uint32 sync_state[2];
|
||||
if (f == NULL && next_date == 0) {
|
||||
if (f == nullptr && next_date == 0) {
|
||||
DEBUG(net, 0, "Cannot open commands.log");
|
||||
next_date = 1;
|
||||
}
|
||||
|
||||
while (f != NULL && !feof(f)) {
|
||||
while (f != nullptr && !feof(f)) {
|
||||
if (_date == next_date && _date_fract == next_date_fract) {
|
||||
if (cp != NULL) {
|
||||
NetworkSendCommand(cp->tile, cp->p1, cp->p2, cp->cmd & ~CMD_FLAGS_MASK, NULL, cp->text, cp->company);
|
||||
if (cp != nullptr) {
|
||||
NetworkSendCommand(cp->tile, cp->p1, cp->p2, cp->cmd & ~CMD_FLAGS_MASK, nullptr, cp->text, cp->company);
|
||||
DEBUG(net, 0, "injecting: %08x; %02x; %02x; %06x; %08x; %08x; %08x; \"%s\" (%s)", _date, _date_fract, (int)_current_company, cp->tile, cp->p1, cp->p2, cp->cmd, cp->text, GetCommandName(cp->cmd));
|
||||
free(cp);
|
||||
cp = NULL;
|
||||
cp = nullptr;
|
||||
}
|
||||
if (check_sync_state) {
|
||||
if (sync_state[0] == _random.state[0] && sync_state[1] == _random.state[1]) {
|
||||
@@ -914,16 +912,16 @@ void NetworkGameLoop()
|
||||
}
|
||||
}
|
||||
|
||||
if (cp != NULL || check_sync_state) break;
|
||||
if (cp != nullptr || check_sync_state) break;
|
||||
|
||||
char buff[4096];
|
||||
if (fgets(buff, lengthof(buff), f) == NULL) break;
|
||||
if (fgets(buff, lengthof(buff), f) == nullptr) break;
|
||||
|
||||
char *p = buff;
|
||||
/* Ignore the "[date time] " part of the message */
|
||||
if (*p == '[') {
|
||||
p = strchr(p, ']');
|
||||
if (p == NULL) break;
|
||||
if (p == nullptr) break;
|
||||
p += 2;
|
||||
}
|
||||
|
||||
@@ -970,10 +968,10 @@ void NetworkGameLoop()
|
||||
NOT_REACHED();
|
||||
}
|
||||
}
|
||||
if (f != NULL && feof(f)) {
|
||||
if (f != nullptr && feof(f)) {
|
||||
DEBUG(net, 0, "End of commands.log");
|
||||
fclose(f);
|
||||
f = NULL;
|
||||
f = nullptr;
|
||||
}
|
||||
#endif /* DEBUG_DUMP_COMMANDS */
|
||||
if (_frame_counter >= _frame_counter_max) {
|
||||
@@ -1172,5 +1170,3 @@ bool IsNetworkCompatibleVersion(const char *other)
|
||||
const char *hash2 = ExtractNetworkRevisionHash(other);
|
||||
return hash1 && hash2 && (strncmp(hash1, hash2, GITHASH_SUFFIX_LEN) == 0);
|
||||
}
|
||||
|
||||
#endif /* ENABLE_NETWORK */
|
||||
|
||||
Reference in New Issue
Block a user