Ticket #1949: rejoined_message_wip_v2.patch

File rejoined_message_wip_v2.patch, 10.0 KB (added by elexis, 9 years ago)
  • binaries/data/mods/public/gui/gamesetup/gamesetup_mp.js

     
    111111                Engine.SwitchGuiPage("page_loading.xml", {
    112112                    "attribs": g_GameAttributes,
    113113                    "isNetworked" : true,
     114                    "isRejoining" : g_IsRejoining,
    114115                    "playerAssignments": g_PlayerAssignments
    115116                });
    116117                break;
  • binaries/data/mods/public/gui/loading/loading.js

     
    113113
    114114    // Restore default cursor.
    115115    Engine.SetCursor("arrow-default");
     116   
     117    // Notify the other clients that we have finished the loading screen
     118    if (g_Data.isNetworked && g_Data.isRejoining) {
     119        Engine.SendNetworkRejoined();
     120    }
    116121}
  • binaries/data/mods/public/gui/session/messages.js

     
    291291    case "aichat":
    292292        addChatMessage({ "type": "message", "guid": message.guid, "text": message.text, "translate": true });
    293293        break;
    294 
     294       
     295    case "rejoined":
     296        addChatMessage({ "type": "rejoined", "guid": message.guid});
     297        break;
     298       
    295299    // To prevent errors, ignore these message types that occur during autostart
    296300    case "gamesetup":
    297301    case "start":
     
    431435    switch (msg.type)
    432436    {
    433437    case "connect":
    434         formatted = sprintf(translate("%(player)s has joined the game."), { player: "[color=\"" + playerColor + "\"]" + username + "[/color]" });
     438        formatted = sprintf(translate("%(player)s is connecting..."), { player: "[color=\"" + playerColor + "\"]" + username + "[/color]" });
    435439        break;
    436440    case "disconnect":
    437441        formatted = sprintf(translate("%(player)s has left the game."), { player: "[color=\"" + playerColor + "\"]" + username + "[/color]" });
    438442        break;
     443    case "rejoined":
     444        formatted = sprintf(translate("%(player)s has rejoined the game."), { player: "[color=\"" + playerColor + "\"]" + username + "[/color]" });
     445        break;
    439446    case "defeat":
    440447        // In singleplayer, the local player is "You". "You has" is incorrect.
    441448        if (!g_IsNetworked && msg.player == Engine.GetPlayerID())
  • source/gui/scripting/ScriptFunctions.cpp

     
    388388    g_NetClient->SendChatMessage(message);
    389389}
    390390
     391void SendNetworkRejoined(ScriptInterface::CxPrivate* UNUSED(pCxPrivate))
     392{
     393    ENSURE(g_NetClient);
     394
     395    g_NetClient->SendRejoinedMessage();
     396}
     397
    391398void SendNetworkReady(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), int message)
    392399{
    393400    ENSURE(g_NetClient);
     
    951958    scriptInterface.RegisterFunction<void, &ClearAllPlayerReady>("ClearAllPlayerReady");
    952959    scriptInterface.RegisterFunction<void, std::wstring, &SendNetworkChat>("SendNetworkChat");
    953960    scriptInterface.RegisterFunction<void, int, &SendNetworkReady>("SendNetworkReady");
     961    scriptInterface.RegisterFunction<void, &SendNetworkRejoined>("SendNetworkRejoined");
    954962    scriptInterface.RegisterFunction<JS::Value, &GetAIs>("GetAIs");
    955963    scriptInterface.RegisterFunction<JS::Value, &GetEngineInfo>("GetEngineInfo");
    956964
  • source/network/NetClient.cpp

     
    115115    AddTransition(NCS_INGAME, (uint)NMT_SIMULATION_COMMAND, NCS_INGAME, (void*)&OnInGame, context);
    116116    AddTransition(NCS_INGAME, (uint)NMT_SYNC_ERROR, NCS_INGAME, (void*)&OnInGame, context);
    117117    AddTransition(NCS_INGAME, (uint)NMT_END_COMMAND_BATCH, NCS_INGAME, (void*)&OnInGame, context);
     118    AddTransition(NCS_INGAME, (uint)NMT_REJOINED, NCS_INGAME, (void*)&OnRejoined, context);
    118119
    119120    // Set first state
    120121    SetFirstState(NCS_UNCONNECTED);
     
    286287    SendMessage(&readyStatus);
    287288}
    288289
     290void CNetClient::SendRejoinedMessage()
     291{
     292    CRejoinedMessage rejoinedMessage;
     293    SendMessage(&rejoinedMessage);
     294}
     295
    289296bool CNetClient::HandleMessage(CNetMessage* message)
    290297{
    291298    // Handle non-FSM messages first
     
    631638
    632639    return true;
    633640}
     641
     642bool CNetClient::OnRejoined(void *context, CFsmEvent* event)
     643{
     644    ENSURE(event->GetType() == (uint)NMT_REJOINED);
     645
     646    CNetClient* client = (CNetClient*)context;
     647    JSContext* cx = client->GetScriptInterface().GetContext();
     648
     649    CRejoinedMessage* message = (CRejoinedMessage*)event->GetParamRef();
     650    JS::RootedValue msg(cx);
     651    client->GetScriptInterface().Eval("({'type':'rejoined'})", &msg);
     652    client->GetScriptInterface().SetProperty(msg, "guid", std::string(message->m_GUID), false);
     653    client->PushGuiMessage(msg);
     654
     655    return true;
     656}
  • source/network/NetClient.h

     
    180180   
    181181    void SendReadyMessage(const int status);
    182182
     183    /**
     184     * Call when the client has rejoined a running match and finished
     185     * the loading screen.
     186     */
     187    void SendRejoinedMessage();
     188
     189
    183190private:
    184191    // Net message / FSM transition handlers
    185192    static bool OnConnect(void* context, CFsmEvent* event);
     
    195202    static bool OnJoinSyncStart(void* context, CFsmEvent* event);
    196203    static bool OnJoinSyncEndCommandBatch(void* context, CFsmEvent* event);
    197204    static bool OnLoadedGame(void* context, CFsmEvent* event);
     205    static bool OnRejoined(void* context, CFsmEvent* event);
    198206
    199207    /**
    200208     * Take ownership of a session object, and use it for all network communication.
  • source/network/NetMessage.cpp

     
    174174    case NMT_CHAT:
    175175        pNewMessage = new CChatMessage;
    176176        break;
    177    
     177
    178178    case NMT_READY:
    179179        pNewMessage = new CReadyMessage;
    180180        break;
    181181
     182    case NMT_REJOINED:
     183        pNewMessage = new CRejoinedMessage;
     184        break;
     185
    182186    case NMT_SIMULATION_COMMAND:
    183187        pNewMessage = new CSimulationMessage(scriptInterface);
    184188        break;
  • source/network/NetMessages.h

     
    4747    NMT_AUTHENTICATE_RESULT,
    4848    NMT_CHAT,       // Common chat message
    4949    NMT_READY,
     50    NMT_REJOINED,
    5051    NMT_GAME_SETUP,
    5152    NMT_PLAYER_ASSIGNMENT,
    5253
     
    124125    NMT_FIELD_INT(m_Status, u8, 1)
    125126END_NMT_CLASS()
    126127
     128START_NMT_CLASS_(Rejoined, NMT_REJOINED)
     129    NMT_FIELD(CStr8, m_GUID)
     130END_NMT_CLASS()
     131
    127132START_NMT_CLASS_(PlayerAssignment, NMT_PLAYER_ASSIGNMENT)
    128133    NMT_START_ARRAY(m_Hosts)
    129134        NMT_FIELD(CStr8, m_GUID)
  • source/network/NetServer.cpp

     
    598598    session->AddTransition(NSS_INGAME, (uint)NMT_SIMULATION_COMMAND, NSS_INGAME, (void*)&OnInGame, context);
    599599    session->AddTransition(NSS_INGAME, (uint)NMT_SYNC_CHECK, NSS_INGAME, (void*)&OnInGame, context);
    600600    session->AddTransition(NSS_INGAME, (uint)NMT_END_COMMAND_BATCH, NSS_INGAME, (void*)&OnInGame, context);
     601    session->AddTransition(NSS_INGAME, (uint)NMT_REJOINED, NSS_INGAME, (void*)&OnRejoined, context);
    601602
    602603    // Set first state
    603604    session->SetFirstState(NSS_HANDSHAKE);
     
    922923    return true;
    923924}
    924925
     926bool CNetServerWorker::OnRejoined(void* context, CFsmEvent* event)
     927{
     928    ENSURE(event->GetType() == (uint)NMT_REJOINED);
     929
     930    CNetServerSession* session = (CNetServerSession*)context;
     931    CNetServerWorker& server = session->GetServer();
     932
     933    CRejoinedMessage* message = (CRejoinedMessage*)event->GetParamRef();
     934
     935    message->m_GUID = session->GetGUID();
     936
     937    server.Broadcast(message);
     938
     939    return true;
     940}
     941
    925942bool CNetServerWorker::OnLoadedGame(void* context, CFsmEvent* event)
    926943{
    927944    ENSURE(event->GetType() == (uint)NMT_LOADED_GAME);
  • source/network/NetServer.h

     
    260260    static bool OnInGame(void* context, CFsmEvent* event);
    261261    static bool OnChat(void* context, CFsmEvent* event);
    262262    static bool OnReady(void* context, CFsmEvent* event);
     263    static bool OnRejoined(void* context, CFsmEvent* event);
    263264    static bool OnLoadedGame(void* context, CFsmEvent* event);
    264265    static bool OnJoinSyncingLoadedGame(void* context, CFsmEvent* event);
    265266    static bool OnDisconnect(void* context, CFsmEvent* event);
  • source/ps/Game.cpp

     
    235235    if (CRenderer::IsInitialised())
    236236        Render();
    237237
     238    if (g_NetClient)
     239        g_NetClient->LoadFinished();
     240
    238241    // Call the reallyStartGame GUI function, but only if it exists
    239242    if (g_GUI && g_GUI->HasPages())
    240243    {
     
    243246            g_GUI->GetActiveGUI()->GetScriptInterface()->CallFunctionVoid(global, "reallyStartGame");
    244247    }
    245248
    246     if (g_NetClient)
    247         g_NetClient->LoadFinished();
    248 
    249249    debug_printf("GAME STARTED, ALL INIT COMPLETE\n");
    250250
    251251    // The call tree we've built for pregame probably isn't useful in-game.