Ticket #3806: 3556_dedServer_v0.2.patch

File 3556_dedServer_v0.2.patch, 7.0 KB (added by Imarok, 3 years ago)

Only the part of sending gameSetup and assignments over network

  • source/gui/scripting/ScriptFunctions.cpp

     
    332332
    333333void SetNetworkGameAttributes(ScriptInterface::CxPrivate* pCxPrivate, JS::HandleValue attribs1)
    334334{
    335     ENSURE(g_NetServer);
     335    ENSURE(g_NetClient);
    336336    //TODO: This is a workaround because we need to pass a MutableHandle to a JSAPI functions somewhere
    337337    // (with no obvious reason).
    338338    JSContext* cx = pCxPrivate->pScriptInterface->GetContext();
     
    339339    JSAutoRequest rq(cx);
    340340    JS::RootedValue attribs(cx, attribs1);
    341341
    342     g_NetServer->UpdateGameAttributes(&attribs, *(pCxPrivate->pScriptInterface));
     342    g_NetClient->SendGameSetupMessage(&attribs, *(pCxPrivate->pScriptInterface));
    343343}
    344344
    345345void StartNetworkHost(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& playerName)
     
    425425
    426426void AssignNetworkPlayer(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), int playerID, const std::string& guid)
    427427{
    428     ENSURE(g_NetServer);
     428    ENSURE(g_NetClient);
    429429
    430     g_NetServer->AssignPlayer(playerID, guid);
     430    g_NetClient->SendAssignPlayerMessage(playerID, guid);
    431431}
    432432
    433433void SetNetworkPlayerStatus(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::string& guid, int ready)
  • source/network/NetClient.cpp

     
    323323    SetCurrState(NCS_UNCONNECTED);
    324324}
    325325
     326void CNetClient::SendGameSetupMessage(JS::MutableHandleValue attrs, ScriptInterface& scriptInterface)
     327{
     328    JSContext* cx = scriptInterface.GetContext();
     329    JS::RootedValue attrsRooted(cx);
     330    attrsRooted = attrs;
     331
     332    CGameSetupMessage gameSetup(scriptInterface);
     333    gameSetup.m_Data = attrsRooted;
     334    SendMessage(&gameSetup);
     335}
     336
     337void CNetClient::SendAssignPlayerMessage(const int playerID, const std::string& guid)
     338{
     339    CAssignPlayerMessage assignPlayer;
     340    assignPlayer.m_PlayerID = playerID;
     341    assignPlayer.m_GUIDToAssign = guid;
     342    SendMessage(&assignPlayer);
     343}
     344
    326345void CNetClient::SendChatMessage(const std::wstring& text)
    327346{
    328347    CChatMessage chat;
  • source/network/NetClient.h

     
    187187     */
    188188    void LoadFinished();
    189189
     190    void SendGameSetupMessage(JS::MutableHandleValue attrs, ScriptInterface& scriptInterface);
     191
     192    void SendAssignPlayerMessage(const int playerID, const std::string& guid);
     193
    190194    void SendChatMessage(const std::wstring& text);
    191195
    192196    void SendReadyMessage(const int status);
  • source/network/NetMessage.cpp

     
    203203        pNewMessage = new CSimulationMessage(scriptInterface);
    204204        break;
    205205
     206    case NMT_ASSIGN_PLAYER:
     207        pNewMessage = new CAssignPlayerMessage;
     208        break;
     209
    206210    default:
    207211        LOGERROR("CNetMessageFactory::CreateMessage(): Unknown message type '%d' received", header.GetType());
    208212        break;
  • source/network/NetMessages.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.
     
    5151    NMT_CHAT,
    5252    NMT_READY,
    5353    NMT_GAME_SETUP,
     54    NMT_ASSIGN_PLAYER,
    5455    NMT_PLAYER_ASSIGNMENT,
    5556
    5657    NMT_FILE_TRANSFER_REQUEST,
     
    218219    NMT_END_ARRAY()
    219220END_NMT_CLASS()
    220221
     222START_NMT_CLASS_(AssignPlayer, NMT_ASSIGN_PLAYER)
     223    NMT_FIELD_INT(m_PlayerID, i8, 1)
     224    NMT_FIELD(CStr, m_GUIDToAssign)
     225END_NMT_CLASS()
     226
    221227END_NMTS()
    222228
    223229#else
  • source/network/NetServer.cpp

     
    649649    session->AddTransition(NSS_PREGAME, (uint)NMT_CONNECTION_LOST, NSS_UNCONNECTED, (void*)&OnDisconnect, context);
    650650    session->AddTransition(NSS_PREGAME, (uint)NMT_CHAT, NSS_PREGAME, (void*)&OnChat, context);
    651651    session->AddTransition(NSS_PREGAME, (uint)NMT_READY, NSS_PREGAME, (void*)&OnReady, context);
     652    session->AddTransition(NSS_PREGAME, (uint)NMT_GAME_SETUP, NSS_PREGAME, (void*)&OnGameSetup, context);
     653    session->AddTransition(NSS_PREGAME, (uint)NMT_ASSIGN_PLAYER, NSS_PREGAME, (void*)&OnAssignPlayer, context);
    652654    session->AddTransition(NSS_PREGAME, (uint)NMT_LOADED_GAME, NSS_INGAME, (void*)&OnLoadedGame, context);
    653655
    654656    session->AddTransition(NSS_JOIN_SYNCING, (uint)NMT_CONNECTION_LOST, NSS_UNCONNECTED, (void*)&OnDisconnect, context);
     
    11111113    return true;
    11121114}
    11131115
     1116bool CNetServerWorker::OnGameSetup(void* context, CFsmEvent* event)
     1117{
     1118    ENSURE(event->GetType() == (uint)NMT_GAME_SETUP);
     1119
     1120    CNetServerSession* session = (CNetServerSession*)context;
     1121    CNetServerWorker& server = session->GetServer();
     1122
     1123    if (session->GetGUID() != server.m_HostGUID) // Client wasn't allowed to send new attributes
     1124        return true;
     1125
     1126    CGameSetupMessage* message = (CGameSetupMessage*)event->GetParamRef();
     1127
     1128    server.UpdateGameAttributes(&(message->m_Data));
     1129    return true;
     1130}
     1131
     1132bool CNetServerWorker::OnAssignPlayer(void* context, CFsmEvent* event)
     1133{
     1134    ENSURE(event->GetType() == (uint)NMT_ASSIGN_PLAYER);
     1135    CNetServerSession* session = (CNetServerSession*)context;
     1136    CNetServerWorker& server = session->GetServer();
     1137
     1138    if (session->GetGUID() != server.m_HostGUID) // Client wasn't allowed to assign a player
     1139        return true;
     1140
     1141    CAssignPlayerMessage* message = (CAssignPlayerMessage*)event->GetParamRef();
     1142    server.m_AssignPlayerQueue.emplace_back(message->m_PlayerID, message->m_GUIDToAssign);
     1143    return true;
     1144}
     1145
    11141146bool CNetServerWorker::OnLoadedGame(void* context, CFsmEvent* event)
    11151147{
    11161148    ENSURE(event->GetType() == (uint)NMT_LOADED_GAME);
  • source/network/NetServer.h

     
    270270    static bool OnInGame(void* context, CFsmEvent* event);
    271271    static bool OnChat(void* context, CFsmEvent* event);
    272272    static bool OnReady(void* context, CFsmEvent* event);
     273    static bool OnGameSetup(void* context, CFsmEvent* event);
     274    static bool OnAssignPlayer(void* context, CFsmEvent* event);
    273275    static bool OnLoadedGame(void* context, CFsmEvent* event);
    274276    static bool OnJoinSyncingLoadedGame(void* context, CFsmEvent* event);
    275277    static bool OnRejoined(void* context, CFsmEvent* event);