From 040e0b29a2468d990d0ae10346baa161221839de Mon Sep 17 00:00:00 2001 From: phosit Date: Tue, 3 Mar 2026 20:00:57 +0100 Subject: [PATCH] Initialize members in the class of CNet* Sometimes the order was wrong. --- source/network/NetClient.cpp | 7 +------ source/network/NetClient.h | 16 ++++++++-------- source/network/NetServer.cpp | 15 ++------------- source/network/NetServer.h | 22 +++++++++++----------- 4 files changed, 22 insertions(+), 38 deletions(-) diff --git a/source/network/NetClient.cpp b/source/network/NetClient.cpp index 6a47929da0..7fe2875e84 100644 --- a/source/network/NetClient.cpp +++ b/source/network/NetClient.cpp @@ -67,14 +67,9 @@ constexpr u32 NETWORK_BAD_PING = DEFAULT_TURN_LENGTH * COMMAND_DELAY_MP / 2; CNetClient *g_NetClient = NULL; CNetClient::CNetClient(CGame* game, const CStrW& username, const CStr& hostJID) : - m_Session(NULL), m_UserName{username}, m_HostJID{hostJID}, - m_HostID((u32)-1), m_ClientTurnManager(NULL), m_Game(game), - m_LastConnectionCheck(0), - m_ServerAddress(), - m_ServerPort(0), - m_Rejoin(false) + m_Game{game} { m_Game->SetTurnManager(NULL); // delete the old local turn manager so we don't accidentally use it diff --git a/source/network/NetClient.h b/source/network/NetClient.h index 374b78413d..70ab481bfc 100644 --- a/source/network/NetClient.h +++ b/source/network/NetClient.h @@ -318,7 +318,7 @@ private: CStr m_HostJID; CStr m_ServerAddress; - u16 m_ServerPort; + u16 m_ServerPort{0}; /** * Password to join the game. @@ -331,19 +331,19 @@ private: /// Note that this is just a "gui hint" with no actual impact on being controller. bool m_IsController = false; - /// Current network session (or NULL if not connected) - CNetClientSession* m_Session; + /// Current network session (or nullptr if not connected) + CNetClientSession* m_Session{nullptr}; std::thread m_PollingThread; - /// Turn manager associated with the current game (or NULL if we haven't started the game yet) - CNetClientTurnManager* m_ClientTurnManager; + /// Turn manager associated with the current game (or nullptr if we haven't started the game yet) + CNetClientTurnManager* m_ClientTurnManager{nullptr}; /// Unique-per-game identifier of this client, used to identify the sender of simulation commands - u32 m_HostID; + u32 m_HostID{static_cast(-1)}; /// True if the player is currently rejoining or has already rejoined the game. - bool m_Rejoin; + bool m_Rejoin{false}; /// Latest copy of player assignments heard from the server PlayerAssignmentMap m_PlayerAssignments; @@ -372,7 +372,7 @@ private: std::string m_SavedState; /// Time when the server was last checked for timeouts and bad latency - std::time_t m_LastConnectionCheck; + std::time_t m_LastConnectionCheck{0}; /// Record of the server engine version and loaded mods CSrvHandshakeMessage m_ServerHandshake; diff --git a/source/network/NetServer.cpp b/source/network/NetServer.cpp index bc6cfe4dcb..63ceba6647 100644 --- a/source/network/NetServer.cpp +++ b/source/network/NetServer.cpp @@ -77,8 +77,6 @@ */ #define MAX_CLIENTS 41 -#define DEFAULT_SERVER_NAME L"Unnamed Server" - constexpr int CHANNEL_COUNT = 1; constexpr int FAILED_PASSWORD_TRIES_BEFORE_BAN = 3; @@ -115,17 +113,8 @@ static CStr DebugName(CNetServerSession* session) CNetServerWorker::CNetServerWorker(const bool continueSavedGame, const bool useLobbyAuth) : m_ContinuesSavedGame{continueSavedGame}, - m_LobbyAuth(useLobbyAuth), - m_Shutdown(false), - m_ScriptInterface(NULL), - m_NextHostID(1), m_Host(NULL), m_ControllerGUID(), m_Stats(NULL), - m_LastConnectionCheck(0) + m_LobbyAuth{useLobbyAuth} { - m_State = SERVER_STATE_UNCONNECTED; - - m_ServerTurnManager = NULL; - - m_ServerName = DEFAULT_SERVER_NAME; } CNetServerWorker::~CNetServerWorker() @@ -1705,7 +1694,7 @@ void CNetServerWorker::SendHolePunchingMessage(const CStr& ipStr, u16 port) CNetServer::CNetServer(const bool continueSavedGame, const bool useLobbyAuth) : m_Worker{new CNetServerWorker{continueSavedGame, useLobbyAuth}}, - m_LobbyAuth(useLobbyAuth), m_PublicIp(""), m_PublicPort(20595), m_Password() + m_LobbyAuth{useLobbyAuth} { } diff --git a/source/network/NetServer.h b/source/network/NetServer.h index 014f38be94..95eb51203d 100644 --- a/source/network/NetServer.h +++ b/source/network/NetServer.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -186,7 +186,7 @@ public: private: CNetServerWorker* m_Worker; const bool m_LobbyAuth; - u16 m_PublicPort; + u16 m_PublicPort{20595}; CStr m_PublicIp; CStr m_Password; std::unordered_map m_FailedAttempts; @@ -346,7 +346,7 @@ private: * (TODO: we shouldn't bother deserializing (except for debug printing of messages), * we should just forward messages blindly and efficiently.) */ - ScriptInterface* m_ScriptInterface; + ScriptInterface* m_ScriptInterface{nullptr}; PlayerAssignmentMap m_PlayerAssignments; @@ -367,14 +367,14 @@ private: */ const bool m_LobbyAuth; - ENetHost* m_Host; + ENetHost* m_Host{nullptr}; std::vector m_Sessions; - CNetStatsTable* m_Stats; + CNetStatsTable* m_Stats{nullptr}; - NetServerState m_State; + NetServerState m_State{SERVER_STATE_UNCONNECTED}; - CStrW m_ServerName; + CStrW m_ServerName{L"Unnamed Server"}; std::vector m_BannedIPs; std::vector m_BannedPlayers; @@ -386,9 +386,9 @@ private: */ std::vector m_PausingPlayers; - u32 m_NextHostID; + u32 m_NextHostID{1}; - CNetServerTurnManager* m_ServerTurnManager; + CNetServerTurnManager* m_ServerTurnManager{nullptr}; /** * The GUID of the client in control of the game (the 'host' from the players' perspective). @@ -421,7 +421,7 @@ private: /** * Time when the clients connections were last checked for timeouts and latency. */ - std::time_t m_LastConnectionCheck; + std::time_t m_LastConnectionCheck{0}; private: // Thread-related stuff: @@ -442,7 +442,7 @@ private: std::mutex m_WorkerMutex; // protected by m_WorkerMutex - bool m_Shutdown; + bool m_Shutdown{false}; // Queues for messages sent by the game thread (protected by m_WorkerMutex): std::vector m_StartGameQueue;