Ticket #3806: 3556_dedServer_v1.5.2.patch

File 3556_dedServer_v1.5.2.patch, 22.7 KB (added by elexis, 3 years ago)

Tell me if that works on windows and I'll commit it.

  • binaries/data/mods/public/gui/common/network.js

    function reportDisconnect(reason, wasCon 
    8787    );
    8888}
    8989
    9090function kickPlayer(username, ban)
    9191{
    92     if (!Engine.KickPlayer(username, ban))
     92    if (g_IsController)
     93        Engine.KickPlayer(username, ban);
     94    else
    9395        addChatMessage({
    9496            "type": "system",
    9597            "text": sprintf(ban ? translate("Could not ban %(name)s.") : translate("Could not kick %(name)s."), {
    9698                "name": username
    9799            })
  • binaries/data/mods/public/gui/gamesetup/gamesetup.js

    function handleReadyMessage(message) 
    654654
    655655    if (!g_IsController)
    656656        return;
    657657
    658658    g_PlayerAssignments[message.guid].status = +message.status == 1;
    659     Engine.SetNetworkPlayerStatus(message.guid, +message.status);
    660659    updateReadyUI();
    661660}
    662661
    663662/**
    664663 * Called after every player is ready and the host decided to finally start the game.
  • source/gui/scripting/ScriptFunctions.cpp

    JS::Value GetEngineInfo(ScriptInterface: 
    244244    return SavedGames::GetEngineInfo(*(pCxPrivate->pScriptInterface));
    245245}
    246246
    247247void StartNetworkGame(ScriptInterface::CxPrivate* UNUSED(pCxPrivate))
    248248{
    249     ENSURE(g_NetServer);
    250     g_NetServer->StartGame();
     249    ENSURE(g_NetClient);
     250    g_NetClient->SendStartGameMessage();
    251251}
    252252
    253253void StartGame(ScriptInterface::CxPrivate* pCxPrivate, JS::HandleValue attribs, int playerID)
    254254{
    255255    ENSURE(!g_NetServer);
    void SaveGamePrefix(ScriptInterface::CxP 
    328328        LOGERROR("Failed to save game");
    329329}
    330330
    331331void SetNetworkGameAttributes(ScriptInterface::CxPrivate* pCxPrivate, JS::HandleValue attribs1)
    332332{
    333     ENSURE(g_NetServer);
     333    ENSURE(g_NetClient);
     334
    334335    //TODO: This is a workaround because we need to pass a MutableHandle to a JSAPI functions somewhere
    335336    // (with no obvious reason).
    336337    JSContext* cx = pCxPrivate->pScriptInterface->GetContext();
    337338    JSAutoRequest rq(cx);
    338339    JS::RootedValue attribs(cx, attribs1);
    339340
    340     g_NetServer->UpdateGameAttributes(&attribs, *(pCxPrivate->pScriptInterface));
     341    g_NetClient->SendGameSetupMessage(&attribs, *(pCxPrivate->pScriptInterface));
    341342}
    342343
    343344void StartNetworkHost(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& playerName)
    344345{
    345346    ENSURE(!g_NetClient);
    std::string GetPlayerGUID(ScriptInterfac 
    398399        return std::string();
    399400
    400401    return g_NetClient->GetGUID();
    401402}
    402403
    403 bool KickPlayer(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const CStrW& playerName, bool ban)
     404void KickPlayer(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const CStrW& playerName, bool ban)
    404405{
    405     if (!g_NetServer)
    406         return false;
     406    ENSURE(g_NetClient);
    407407
    408     return g_NetServer->KickPlayer(playerName, ban);
     408    g_NetClient->SendKickPlayerMessage(playerName, ban);
    409409}
    410410
    411411JS::Value PollNetworkClient(ScriptInterface::CxPrivate* pCxPrivate)
    412412{
    413413    if (!g_NetClient)
    JS::Value PollNetworkClient(ScriptInterf 
    421421    return pCxPrivate->pScriptInterface->CloneValueFromOtherContext(g_NetClient->GetScriptInterface(), pollNet);
    422422}
    423423
    424424void AssignNetworkPlayer(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), int playerID, const std::string& guid)
    425425{
    426     ENSURE(g_NetServer);
    427 
    428     g_NetServer->AssignPlayer(playerID, guid);
    429 }
    430 
    431 void SetNetworkPlayerStatus(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::string& guid, int ready)
    432 {
    433     ENSURE(g_NetServer);
     426    ENSURE(g_NetClient);
    434427
    435     g_NetServer->SetPlayerReady(guid, ready);
     428    g_NetClient->SendAssignPlayerMessage(playerID, guid);
    436429}
    437430
    438431void ClearAllPlayerReady (ScriptInterface::CxPrivate* UNUSED(pCxPrivate))
    439432{
    440     ENSURE(g_NetServer);
     433    ENSURE(g_NetClient);
    441434
    442     g_NetServer->ClearAllPlayerReady();
     435    g_NetClient->SendClearAllReadyMessage();
    443436}
    444437
    445438void SendNetworkChat(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::wstring& message)
    446439{
    447440    ENSURE(g_NetClient);
    void GuiScriptingInit(ScriptInterface& s 
    10361029    scriptInterface.RegisterFunction<void, &Script_EndGame>("EndGame");
    10371030    scriptInterface.RegisterFunction<void, std::wstring, &StartNetworkHost>("StartNetworkHost");
    10381031    scriptInterface.RegisterFunction<void, std::wstring, std::string, &StartNetworkJoin>("StartNetworkJoin");
    10391032    scriptInterface.RegisterFunction<void, &DisconnectNetworkGame>("DisconnectNetworkGame");
    10401033    scriptInterface.RegisterFunction<std::string, &GetPlayerGUID>("GetPlayerGUID");
    1041     scriptInterface.RegisterFunction<bool, CStrW, bool, &KickPlayer>("KickPlayer");
     1034    scriptInterface.RegisterFunction<void, CStrW, bool, &KickPlayer>("KickPlayer");
    10421035    scriptInterface.RegisterFunction<JS::Value, &PollNetworkClient>("PollNetworkClient");
    10431036    scriptInterface.RegisterFunction<void, JS::HandleValue, &SetNetworkGameAttributes>("SetNetworkGameAttributes");
    10441037    scriptInterface.RegisterFunction<void, int, std::string, &AssignNetworkPlayer>("AssignNetworkPlayer");
    1045     scriptInterface.RegisterFunction<void, std::string, int, &SetNetworkPlayerStatus>("SetNetworkPlayerStatus");
    10461038    scriptInterface.RegisterFunction<void, &ClearAllPlayerReady>("ClearAllPlayerReady");
    10471039    scriptInterface.RegisterFunction<void, std::wstring, &SendNetworkChat>("SendNetworkChat");
    10481040    scriptInterface.RegisterFunction<void, int, &SendNetworkReady>("SendNetworkReady");
    10491041    scriptInterface.RegisterFunction<JS::Value, &GetAIs>("GetAIs");
    10501042    scriptInterface.RegisterFunction<JS::Value, &GetEngineInfo>("GetEngineInfo");
  • source/network/NetClient.cpp

    void CNetClient::HandleDisconnect(u32 re 
    321321    // Update the state immediately to UNCONNECTED (don't bother with FSM transitions since
    322322    // we'd need one for every single state, and we don't need to use per-state actions)
    323323    SetCurrState(NCS_UNCONNECTED);
    324324}
    325325
     326void CNetClient::SendGameSetupMessage(JS::MutableHandleValue attrs, ScriptInterface& scriptInterface)
     327{
     328    CGameSetupMessage gameSetup(scriptInterface);
     329    gameSetup.m_Data = attrs;
     330    SendMessage(&gameSetup);
     331}
     332
     333void CNetClient::SendAssignPlayerMessage(const int playerID, const CStr& guid)
     334{
     335    CAssignPlayerMessage assignPlayer;
     336    assignPlayer.m_PlayerID = playerID;
     337    assignPlayer.m_GUID = guid;
     338    SendMessage(&assignPlayer);
     339}
     340
    326341void CNetClient::SendChatMessage(const std::wstring& text)
    327342{
    328343    CChatMessage chat;
    329344    chat.m_Message = text;
    330345    SendMessage(&chat);
    void CNetClient::SendReadyMessage(const 
    335350    CReadyMessage readyStatus;
    336351    readyStatus.m_Status = status;
    337352    SendMessage(&readyStatus);
    338353}
    339354
     355void CNetClient::SendClearAllReadyMessage()
     356{
     357    CClearAllReadyMessage clearAllReady;
     358    SendMessage(&clearAllReady);
     359}
     360
     361void CNetClient::SendStartGameMessage()
     362{
     363    CGameStartMessage gameStart;
     364    SendMessage(&gameStart);
     365}
     366
    340367void CNetClient::SendRejoinedMessage()
    341368{
    342369    CRejoinedMessage rejoinedMessage;
    343370    SendMessage(&rejoinedMessage);
    344371}
    345372
     373void CNetClient::SendKickPlayerMessage(const CStrW& playerName, bool ban)
     374{
     375    CKickedMessage kickPlayer;
     376    kickPlayer.m_Name = playerName;
     377    kickPlayer.m_Ban = ban;
     378    SendMessage(&kickPlayer);
     379}
     380
    346381void CNetClient::SendPausedMessage(bool pause)
    347382{
    348383    CClientPausedMessage pausedMessage;
    349384    pausedMessage.m_Pause = pause;
    350385    SendMessage(&pausedMessage);
  • source/network/NetClient.h

    public: 
    185185     * Call when the game has started and all data files have been loaded,
    186186     * to signal to the server that we are ready to begin the game.
    187187     */
    188188    void LoadFinished();
    189189
     190    void SendGameSetupMessage(JS::MutableHandleValue attrs, ScriptInterface& scriptInterface);
     191
     192    void SendAssignPlayerMessage(const int playerID, const CStr& guid);
     193
    190194    void SendChatMessage(const std::wstring& text);
    191195
    192196    void SendReadyMessage(const int status);
    193197
     198    void SendClearAllReadyMessage();
     199
     200    void SendStartGameMessage();
     201
    194202    /**
    195203     * Call when the client has rejoined a running match and finished
    196204     * the loading screen.
    197205     */
    198206    void SendRejoinedMessage();
    199207
    200208    /**
     209     * Call to kick/ban a client
     210     */
     211    void SendKickPlayerMessage(const CStrW& playerName, bool ban);
     212
     213    /**
    201214     * Call when the client has paused or unpaused the game.
    202215     */
    203216    void SendPausedMessage(bool pause);
    204217
    205218private:
  • source/network/NetMessage.cpp

    CNetMessage* CNetMessageFactory::CreateM 
    201201
    202202    case NMT_SIMULATION_COMMAND:
    203203        pNewMessage = new CSimulationMessage(scriptInterface);
    204204        break;
    205205
     206    case NMT_CLEAR_ALL_READY:
     207        pNewMessage = new CClearAllReadyMessage;
     208        break;
     209
     210    case NMT_ASSIGN_PLAYER:
     211        pNewMessage = new CAssignPlayerMessage;
     212        break;
     213
    206214    default:
    207215        LOGERROR("CNetMessageFactory::CreateMessage(): Unknown message type '%d' received", header.GetType());
    208216        break;
    209217    }
    210218
  • source/network/NetMessages.h

     
    2626#include "ps/CStr.h"
    2727#include "scriptinterface/ScriptVal.h"
    2828
    2929#define PS_PROTOCOL_MAGIC               0x5073013f      // 'P', 's', 0x01, '?'
    3030#define PS_PROTOCOL_MAGIC_RESPONSE      0x50630121      // 'P', 'c', 0x01, '!'
    31 #define PS_PROTOCOL_VERSION             0x01010013      // Arbitrary protocol
     31#define PS_PROTOCOL_VERSION             0x01010014      // Arbitrary protocol
    3232#define PS_DEFAULT_PORT                 0x5073          // 'P', 's'
    3333
    3434// Defines the list of message types. The order of the list must not change.
    3535// The message types having a negative value are used internally and not sent
    3636// over the network. The message types used for network communication have
    enum NetMessageType 
    4848    NMT_AUTHENTICATE,
    4949    NMT_AUTHENTICATE_RESULT,
    5050
    5151    NMT_CHAT,
    5252    NMT_READY,
     53    NMT_CLEAR_ALL_READY,
    5354    NMT_GAME_SETUP,
     55    NMT_ASSIGN_PLAYER,
    5456    NMT_PLAYER_ASSIGNMENT,
    5557
    5658    NMT_FILE_TRANSFER_REQUEST,
    5759    NMT_FILE_TRANSFER_RESPONSE,
    5860    NMT_FILE_TRANSFER_DATA,
    END_NMT_CLASS() 
    134136START_NMT_CLASS_(Ready, NMT_READY)
    135137    NMT_FIELD(CStr, m_GUID)
    136138    NMT_FIELD_INT(m_Status, u8, 1)
    137139END_NMT_CLASS()
    138140
     141START_NMT_CLASS_(ClearAllReady, NMT_CLEAR_ALL_READY)
     142END_NMT_CLASS()
     143
    139144START_NMT_CLASS_(PlayerAssignment, NMT_PLAYER_ASSIGNMENT)
    140145    NMT_START_ARRAY(m_Hosts)
    141146        NMT_FIELD(CStr, m_GUID)
    142147        NMT_FIELD(CStrW, m_Name)
    143148        NMT_FIELD_INT(m_PlayerID, i8, 1)
    START_NMT_CLASS_(SyncError, NMT_SYNC_ERR 
    216221    NMT_START_ARRAY(m_PlayerNames)
    217222        NMT_FIELD(CStrW, m_Name)
    218223    NMT_END_ARRAY()
    219224END_NMT_CLASS()
    220225
     226START_NMT_CLASS_(AssignPlayer, NMT_ASSIGN_PLAYER)
     227    NMT_FIELD_INT(m_PlayerID, i8, 1)
     228    NMT_FIELD(CStr, m_GUID)
     229END_NMT_CLASS()
     230
    221231END_NMTS()
    222232
    223233#else
    224234#ifndef ALLNETMSGS_DONT_CREATE_NMTS
    225235
  • source/network/NetServer.cpp

    bool CNetServerWorker::RunStep() 
    402402    m_ScriptInterface->GetRuntime()->MaybeIncrementalGC(0.5f);
    403403
    404404    JSContext* cx = m_ScriptInterface->GetContext();
    405405    JSAutoRequest rq(cx);
    406406
    407     std::vector<std::pair<int, CStr>> newAssignPlayer;
    408407    std::vector<bool> newStartGame;
    409     std::vector<std::pair<CStr, int>> newPlayerReady;
    410     std::vector<bool> newPlayerResetReady;
    411408    std::vector<std::string> newGameAttributes;
    412409    std::vector<u32> newTurnLength;
    413410
    414411    {
    415412        CScopeLock lock(m_WorkerMutex);
    416413
    417414        if (m_Shutdown)
    418415            return false;
    419416
    420417        newStartGame.swap(m_StartGameQueue);
    421         newPlayerReady.swap(m_PlayerReadyQueue);
    422         newPlayerResetReady.swap(m_PlayerResetReadyQueue);
    423         newAssignPlayer.swap(m_AssignPlayerQueue);
    424418        newGameAttributes.swap(m_GameAttributesQueue);
    425419        newTurnLength.swap(m_TurnLengthQueue);
    426420    }
    427421
    428     for (const std::pair<int, CStr8>& p : newAssignPlayer)
    429         AssignPlayer(p.first, p.second);
    430 
    431     for (const std::pair<CStr8, int>& p : newPlayerReady)
    432         SetPlayerReady(p.first, p.second);
    433 
    434     if (!newPlayerResetReady.empty())
    435         ClearAllPlayerReady();
    436 
    437422    if (!newGameAttributes.empty())
    438423    {
    439424        JS::RootedValue gameAttributesVal(cx);
    440425        GetScriptInterface().ParseJSON(newGameAttributes.back(), &gameAttributesVal);
    441426        UpdateGameAttributes(&gameAttributesVal);
    void CNetServerWorker::SetupSession(CNet 
    647632    session->AddTransition(NSS_AUTHENTICATE, (uint)NMT_AUTHENTICATE, NSS_PREGAME, (void*)&OnAuthenticate, context);
    648633
    649634    session->AddTransition(NSS_PREGAME, (uint)NMT_CONNECTION_LOST, NSS_UNCONNECTED, (void*)&OnDisconnect, context);
    650635    session->AddTransition(NSS_PREGAME, (uint)NMT_CHAT, NSS_PREGAME, (void*)&OnChat, context);
    651636    session->AddTransition(NSS_PREGAME, (uint)NMT_READY, NSS_PREGAME, (void*)&OnReady, context);
     637    session->AddTransition(NSS_PREGAME, (uint)NMT_CLEAR_ALL_READY, NSS_PREGAME, (void*)&OnClearAllReady, context);
     638    session->AddTransition(NSS_PREGAME, (uint)NMT_GAME_SETUP, NSS_PREGAME, (void*)&OnGameSetup, context);
     639    session->AddTransition(NSS_PREGAME, (uint)NMT_ASSIGN_PLAYER, NSS_PREGAME, (void*)&OnAssignPlayer, context);
     640    session->AddTransition(NSS_PREGAME, (uint)NMT_KICKED, NSS_PREGAME, (void*)&OnKickPlayer, context);
     641    session->AddTransition(NSS_PREGAME, (uint)NMT_GAME_START, NSS_PREGAME, (void*)&OnStartGame, context);
    652642    session->AddTransition(NSS_PREGAME, (uint)NMT_LOADED_GAME, NSS_INGAME, (void*)&OnLoadedGame, context);
    653643
     644    session->AddTransition(NSS_JOIN_SYNCING, (uint)NMT_KICKED, NSS_JOIN_SYNCING, (void*)&OnKickPlayer, context);
    654645    session->AddTransition(NSS_JOIN_SYNCING, (uint)NMT_CONNECTION_LOST, NSS_UNCONNECTED, (void*)&OnDisconnect, context);
    655646    session->AddTransition(NSS_JOIN_SYNCING, (uint)NMT_LOADED_GAME, NSS_INGAME, (void*)&OnJoinSyncingLoadedGame, context);
    656647
    657648    session->AddTransition(NSS_INGAME, (uint)NMT_REJOINED, NSS_INGAME, (void*)&OnRejoined, context);
     649    session->AddTransition(NSS_INGAME, (uint)NMT_KICKED, NSS_INGAME, (void*)&OnKickPlayer, context);
    658650    session->AddTransition(NSS_INGAME, (uint)NMT_CLIENT_PAUSED, NSS_INGAME, (void*)&OnClientPaused, context);
    659651    session->AddTransition(NSS_INGAME, (uint)NMT_CONNECTION_LOST, NSS_UNCONNECTED, (void*)&OnDisconnect, context);
    660652    session->AddTransition(NSS_INGAME, (uint)NMT_CHAT, NSS_INGAME, (void*)&OnChat, context);
    661653    session->AddTransition(NSS_INGAME, (uint)NMT_SIMULATION_COMMAND, NSS_INGAME, (void*)&OnInGame, context);
    662654    session->AddTransition(NSS_INGAME, (uint)NMT_SYNC_CHECK, NSS_INGAME, (void*)&OnInGame, context);
    void CNetServerWorker::ClearAllPlayerRea 
    782774        it->second.m_Status = 0;
    783775
    784776    SendPlayerAssignments();
    785777}
    786778
    787 bool CNetServerWorker::KickPlayer(const CStrW& playerName, const bool ban)
     779void CNetServerWorker::KickPlayer(const CStrW& playerName, const bool ban)
    788780{
    789781    // Find the user with that name
    790782    std::vector<CNetServerSession*>::iterator it = std::find_if(m_Sessions.begin(), m_Sessions.end(),
    791783        [&](CNetServerSession* session) { return session->GetUserName() == playerName; });
    792784
    793785    // and return if no one or the host has that name
    794786    if (it == m_Sessions.end() || (*it)->GetGUID() == m_HostGUID)
    795         return false;
     787        return;
    796788
    797789    if (ban)
    798790    {
    799791        // Remember name
    800792        if (std::find(m_BannedPlayers.begin(), m_BannedPlayers.end(), playerName) == m_BannedPlayers.end())
    bool CNetServerWorker::KickPlayer(const 
    812804    // Send message notifying other clients
    813805    CKickedMessage kickedMessage;
    814806    kickedMessage.m_Name = playerName;
    815807    kickedMessage.m_Ban = ban;
    816808    Broadcast(&kickedMessage);
    817 
    818     return true;
    819809}
    820810
    821811void CNetServerWorker::AssignPlayer(int playerID, const CStr& guid)
    822812{
    823813    // Remove anyone who's already assigned to this player
    bool CNetServerWorker::OnReady(void* con 
    11061096    CReadyMessage* message = (CReadyMessage*)event->GetParamRef();
    11071097
    11081098    message->m_GUID = session->GetGUID();
    11091099
    11101100    server.Broadcast(message);
     1101    server.SetPlayerReady(message->m_GUID, message->m_Status);
     1102
     1103    return true;
     1104}
     1105
     1106bool CNetServerWorker::OnClearAllReady(void* context, CFsmEvent* event)
     1107{
     1108    ENSURE(event->GetType() == (uint)NMT_CLEAR_ALL_READY);
     1109
     1110    CNetServerSession* session = (CNetServerSession*)context;
     1111    CNetServerWorker& server = session->GetServer();
     1112
     1113    if (session->GetGUID() == server.m_HostGUID)
     1114        server.ClearAllPlayerReady();
     1115
     1116    return true;
     1117}
     1118
     1119bool CNetServerWorker::OnGameSetup(void* context, CFsmEvent* event)
     1120{
     1121    ENSURE(event->GetType() == (uint)NMT_GAME_SETUP);
     1122
     1123    CNetServerSession* session = (CNetServerSession*)context;
     1124    CNetServerWorker& server = session->GetServer();
     1125
     1126    if (session->GetGUID() == server.m_HostGUID)
     1127    {
     1128        CGameSetupMessage* message = (CGameSetupMessage*)event->GetParamRef();
     1129        server.UpdateGameAttributes(&(message->m_Data));
     1130    }
     1131    return true;
     1132}
     1133
     1134bool CNetServerWorker::OnAssignPlayer(void* context, CFsmEvent* event)
     1135{
     1136    ENSURE(event->GetType() == (uint)NMT_ASSIGN_PLAYER);
     1137    CNetServerSession* session = (CNetServerSession*)context;
     1138    CNetServerWorker& server = session->GetServer();
     1139
     1140    if (session->GetGUID() == server.m_HostGUID)
     1141    {
     1142        CAssignPlayerMessage* message = (CAssignPlayerMessage*)event->GetParamRef();
     1143        server.AssignPlayer(message->m_PlayerID, message->m_GUID);
     1144    }
     1145    return true;
     1146}
     1147
     1148bool CNetServerWorker::OnStartGame(void* context, CFsmEvent* event)
     1149{
     1150    ENSURE(event->GetType() == (uint)NMT_GAME_START);
     1151    CNetServerSession* session = (CNetServerSession*)context;
     1152    CNetServerWorker& server = session->GetServer();
     1153
     1154    if (session->GetGUID() == server.m_HostGUID)
     1155        server.StartGame();
    11111156
    11121157    return true;
    11131158}
    11141159
    11151160bool CNetServerWorker::OnLoadedGame(void* context, CFsmEvent* event)
    bool CNetServerWorker::OnRejoined(void* 
    12021247    }
    12031248
    12041249    return true;
    12051250}
    12061251
     1252bool CNetServerWorker::OnKickPlayer(void* context, CFsmEvent* event)
     1253{
     1254    ENSURE(event->GetType() == (uint)NMT_KICKED);
     1255
     1256    CNetServerSession* session = (CNetServerSession*)context;
     1257    CNetServerWorker& server = session->GetServer();
     1258
     1259    if (session->GetGUID() == server.m_HostGUID)
     1260    {
     1261        CKickedMessage* message = (CKickedMessage*)event->GetParamRef();
     1262        server.KickPlayer(message->m_Name, message->m_Ban);
     1263    }
     1264    return true;
     1265}
     1266
    12071267bool CNetServerWorker::OnDisconnect(void* context, CFsmEvent* event)
    12081268{
    12091269    ENSURE(event->GetType() == (uint)NMT_CONNECTION_LOST);
    12101270
    12111271    CNetServerSession* session = (CNetServerSession*)context;
    CNetServer::~CNetServer() 
    13701430bool CNetServer::SetupConnection()
    13711431{
    13721432    return m_Worker->SetupConnection();
    13731433}
    13741434
    1375 bool CNetServer::KickPlayer(const CStrW& playerName, const bool ban)
    1376 {
    1377     CScopeLock lock(m_Worker->m_WorkerMutex);
    1378     return m_Worker->KickPlayer(playerName, ban);
    1379 }
    1380 
    1381 void CNetServer::AssignPlayer(int playerID, const CStr& guid)
    1382 {
    1383     CScopeLock lock(m_Worker->m_WorkerMutex);
    1384     m_Worker->m_AssignPlayerQueue.emplace_back(playerID, guid);
    1385 }
    1386 
    1387 void CNetServer::SetPlayerReady(const CStr& guid, int ready)
    1388 {
    1389     CScopeLock lock(m_Worker->m_WorkerMutex);
    1390     m_Worker->m_PlayerReadyQueue.emplace_back(guid, ready);
    1391 }
    1392 
    1393 void CNetServer::ClearAllPlayerReady()
    1394 {
    1395     CScopeLock lock(m_Worker->m_WorkerMutex);
    1396     m_Worker->m_PlayerResetReadyQueue.push_back(false);
    1397 }
    1398 
    13991435void CNetServer::StartGame()
    14001436{
    14011437    CScopeLock lock(m_Worker->m_WorkerMutex);
    14021438    m_Worker->m_StartGameQueue.push_back(true);
    14031439}
  • source/network/NetServer.h

    public: 
    114114     * @return true on success, false on error (e.g. port already in use)
    115115     */
    116116    bool SetupConnection();
    117117
    118118    /**
    119      * Call from the GUI to update the player assignments.
    120      * The given GUID will be (re)assigned to the given player ID.
    121      * Any player currently using that ID will be unassigned.
    122      * The changes will be asynchronously propagated to all clients.
    123      */
    124     void AssignPlayer(int playerID, const CStr& guid);
    125 
    126     /**
    127      * Call from the GUI to update the player readiness.
    128      * The changes will be asynchronously propagated to all clients.
    129      */
    130     void SetPlayerReady(const CStr& guid, int ready);
    131 
    132     /**
    133      * Call from the GUI to set the all player readiness to 0.
    134      * The changes will be asynchronously propagated to all clients.
    135      */
    136     void ClearAllPlayerReady();
    137 
    138     /**
    139      * Disconnects a player from gamesetup or session.
    140      */
    141     bool KickPlayer(const CStrW& playerName, const bool ban);
    142 
    143     /**
    144119     * Call from the GUI to asynchronously notify all clients that they should start loading the game.
    145120     */
    146121    void StartGame();
    147122
    148123    /**
    public: 
    188163    bool SendMessage(ENetPeer* peer, const CNetMessage* message);
    189164
    190165    /**
    191166     * Disconnects a player from gamesetup or session.
    192167     */
    193     bool KickPlayer(const CStrW& playerName, const bool ban);
     168    void KickPlayer(const CStrW& playerName, const bool ban);
    194169
    195170    /**
    196171     * Send a message to all clients who have completed the full connection process
    197172     * (i.e. are in the pre-game or in-game states).
    198173     */
    private: 
    268243    static bool OnClientHandshake(void* context, CFsmEvent* event);
    269244    static bool OnAuthenticate(void* context, CFsmEvent* event);
    270245    static bool OnInGame(void* context, CFsmEvent* event);
    271246    static bool OnChat(void* context, CFsmEvent* event);
    272247    static bool OnReady(void* context, CFsmEvent* event);
     248    static bool OnClearAllReady(void* context, CFsmEvent* event);
     249    static bool OnGameSetup(void* context, CFsmEvent* event);
     250    static bool OnAssignPlayer(void* context, CFsmEvent* event);
     251    static bool OnStartGame(void* context, CFsmEvent* event);
    273252    static bool OnLoadedGame(void* context, CFsmEvent* event);
    274253    static bool OnJoinSyncingLoadedGame(void* context, CFsmEvent* event);
    275254    static bool OnRejoined(void* context, CFsmEvent* event);
     255    static bool OnKickPlayer(void* context, CFsmEvent* event);
    276256    static bool OnDisconnect(void* context, CFsmEvent* event);
    277257    static bool OnClientPaused(void* context, CFsmEvent* event);
    278258
    279259    void CheckGameLoadStatus(CNetServerSession* changedSession);
    280260
    private: 
    365345    CMutex m_WorkerMutex;
    366346
    367347    bool m_Shutdown; // protected by m_WorkerMutex
    368348
    369349    // Queues for messages sent by the game thread:
    370     std::vector<std::pair<int, CStr>> m_AssignPlayerQueue; // protected by m_WorkerMutex
    371350    std::vector<bool> m_StartGameQueue; // protected by m_WorkerMutex
    372     std::vector<std::pair<CStr, int>> m_PlayerReadyQueue; // protected by m_WorkerMutex
    373     std::vector<bool> m_PlayerResetReadyQueue; // protected by m_WorkerMutex
    374351    std::vector<std::string> m_GameAttributesQueue; // protected by m_WorkerMutex
    375352    std::vector<u32> m_TurnLengthQueue; // protected by m_WorkerMutex
    376353};
    377354
    378355/// Global network server for the standard game