Ticket #3409: t3409_getPlayerGUID_v1.patch
File t3409_getPlayerGUID_v1.patch, 4.5 KB (added by , 9 years ago) |
---|
-
source/gui/scripting/ScriptFunctions.cpp
191 191 if (g_Game) 192 192 return g_Game->GetPlayerID(); 193 193 return -1; 194 194 } 195 195 196 CStr GetPlayerGUID(ScriptInterface::CxPrivate* UNUSED(pCxPrivate)) 197 { 198 if (g_NetServer) 199 return g_NetServer->GetHostGUID(); 200 else if (g_NetClient) 201 return g_NetClient->GetGUID(); 202 203 return ""; 204 } 205 196 206 void SetPlayerID(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), int id) 197 207 { 198 208 if (g_Game) 199 209 g_Game->SetPlayerID(id); 200 210 } … … 963 973 scriptInterface.RegisterFunction<void, &DisconnectNetworkGame>("DisconnectNetworkGame"); 964 974 scriptInterface.RegisterFunction<JS::Value, &PollNetworkClient>("PollNetworkClient"); 965 975 scriptInterface.RegisterFunction<void, JS::HandleValue, &SetNetworkGameAttributes>("SetNetworkGameAttributes"); 966 976 scriptInterface.RegisterFunction<void, int, std::string, &AssignNetworkPlayer>("AssignNetworkPlayer"); 967 977 scriptInterface.RegisterFunction<void, std::string, int, &SetNetworkPlayerStatus>("SetNetworkPlayerStatus"); 978 scriptInterface.RegisterFunction<CStr, &GetPlayerGUID>("GetPlayerGUID"); 968 979 scriptInterface.RegisterFunction<void, &ClearAllPlayerReady>("ClearAllPlayerReady"); 969 980 scriptInterface.RegisterFunction<void, std::wstring, &SendNetworkChat>("SendNetworkChat"); 970 981 scriptInterface.RegisterFunction<void, int, &SendNetworkReady>("SendNetworkReady"); 971 982 scriptInterface.RegisterFunction<void, &SendNetworkRejoined>("SendNetworkRejoined"); 972 983 scriptInterface.RegisterFunction<JS::Value, &GetAIs>("GetAIs"); -
source/network/NetClient.h
87 87 * This must not be called after the connection setup. 88 88 */ 89 89 void SetUserName(const CStrW& username); 90 90 91 91 /** 92 * Returns the GUID of the client. 93 */ 94 CStr GetGUID() const { return m_GUID; } 95 96 /** 92 97 * Set up a connection to the remote networked server. 93 98 * @param server IP address or host name to connect to 94 99 * @return true on success, false on connection failure 95 100 */ 96 101 bool SetupConnection(const CStr& server); -
source/network/NetServer.cpp
615 615 616 616 void CNetServerWorker::OnUserJoin(CNetServerSession* session) 617 617 { 618 618 AddPlayer(session->GetGUID(), session->GetUserName()); 619 619 620 if (m_HostGUID.empty()) 621 m_HostGUID = session->GetGUID(); 622 620 623 CGameSetupMessage gameSetupMessage(GetScriptInterface()); 621 624 gameSetupMessage.m_Data = m_GameAttributes.get(); 622 625 session->SendMessage(&gameSetupMessage); 623 626 624 627 CPlayerAssignmentMessage assignMessage; … … 1159 1162 { 1160 1163 CScopeLock lock(m_Worker->m_WorkerMutex); 1161 1164 m_Worker->m_PlayerReadyQueue.emplace_back(guid, ready); 1162 1165 } 1163 1166 1167 CStr CNetServer::GetHostGUID() 1168 { 1169 CScopeLock lock(m_Worker->m_WorkerMutex); 1170 return m_Worker->GetHostGUID(); 1171 } 1172 1164 1173 void CNetServer::ClearAllPlayerReady() 1165 1174 { 1166 1175 CScopeLock lock(m_Worker->m_WorkerMutex); 1167 1176 m_Worker->m_PlayerResetReadyQueue.push_back(false); 1168 1177 } -
source/network/NetServer.h
132 132 /** 133 133 * Call from the GUI to set the all player readiness to 0. 134 134 * The changes will be asynchronously propagated to all clients. 135 135 */ 136 136 void ClearAllPlayerReady(); 137 137 138 /** 139 * Returns the GUID of the host. 140 */ 141 CStr GetHostGUID(); 142 138 143 /** 139 144 * Call from the GUI to asynchronously notify all clients that they should start loading the game. 140 145 */ 141 146 void StartGame(); 142 147 … … 186 191 * Send a message to all clients who have completed the full connection process 187 192 * (i.e. are in the pre-game or in-game states). 188 193 */ 189 194 bool Broadcast(const CNetMessage* message); 190 195 196 CStr GetHostGUID() const { return m_HostGUID; } 197 191 198 private: 192 199 friend class CNetServer; 193 200 friend class CNetFileReceiveTask_ServerRejoin; 194 201 195 202 CNetServerWorker(int autostartPlayers); … … 301 308 302 309 u32 m_NextHostID; 303 310 304 311 CNetServerTurnManager* m_ServerTurnManager; 305 312 313 CStr m_HostGUID; 314 306 315 /** 307 316 * A copy of all simulation commands received so far, indexed by 308 317 * turn number, to simplify support for rejoining etc. 309 318 * TODO: verify this doesn't use too much RAM. 310 319 */