Ticket #4528: late_observer_buddies_v0.8.patch

File late_observer_buddies_v0.8.patch, 5.0 KB (added by elexis, 7 years ago)
  • binaries/data/config/default.cfg

    buddies = "," ; Co  
    377377[mod]
    378378enabledmods = "mod public"
    379379
    380380[network]
    381381duplicateplayernames = false      ; Rename joining player to "User (2)" if "User" is already connected, otherwise prohibit join.
    382 lateobserverjoins = true          ; Allow observers to join the game after it started
     382lateobserverjoins = 2             ; Allow observers to join the game after it started
    383383observerlimit = 8                 ; Prevent further observer joins in running games if this limit is reached
    384384
    385385[overlay]
    386386fps = "false"                     ; Show frames per second in top right corner
    387387realtime = "false"                ; Show current system time in top right corner
  • binaries/data/mods/public/gui/options/options.json

     
    7878            "label": "Persist Match Settings",
    7979            "tooltip": "Save and restore match settings for quick reuse when hosting another game",
    8080            "parameters": { "config": "persistmatchsettings" }
    8181        },
    8282        {
    83             "type": "boolean",
     83            "type": "dropdown",
    8484            "label": "Late Observer Joins",
    85             "tooltip": "Allow observers to join the game after it started",
    86             "parameters": { "config": "network.lateobserverjoins" }
     85            "tooltip": "Allow everybody or buddies only to join the game as observer after it started",
     86            "parameters": { "list": [ "Enabled", "Only Buddies", "Disabled" ], "config": "network.lateobserverjoins" }
    8787        },
    8888        {
    8989            "type": "number",
    9090            "label": "Observer Limit",
    9191            "tooltip": "Prevent further observers from joining if the limit is reached",
  • source/network/NetServer.cpp

     
    2323#include "NetMessage.h"
    2424#include "NetSession.h"
    2525#include "NetServerTurnManager.h"
    2626#include "NetStats.h"
    2727
     28// TODO: find right place
     29#include <regex>
     30
    2831#include "lib/external_libraries/enet.h"
    2932#include "ps/CLogger.h"
    3033#include "ps/ConfigDB.h"
    3134#include "ps/Profile.h"
    3235#include "scriptinterface/ScriptInterface.h"
    bool CNetServerWorker::OnAuthenticate(vo  
    928931    {
    929932        session->Disconnect(NDR_BANNED);
    930933        return true;
    931934    }
    932935
    933     // Optionally allow observers to join after the game has started
    934     bool observerLateJoin = false;
    935     CFG_GET_VAL("network.lateobserverjoins", observerLateJoin);
    936 
    937     int maxObservers = 0;
    938     CFG_GET_VAL("network.observerlimit", maxObservers);
    939 
    940936    bool isRejoining = false;
    941937    bool serverFull = false;
    942938    if (server.m_State == SERVER_STATE_PREGAME)
    943939    {
    944940        // Don't check for maxObservers in the gamesetup, as we don't know yet who will be assigned
    945941        serverFull = server.m_Sessions.size() >= MAX_CLIENTS;
    946942    }
    947943    else
    948944    {
    949         isRejoining = observerLateJoin;
    950945        bool isObserver = true;
    951946        int disconnectedPlayers = 0;
    952947        int connectedPlayers = 0;
    953948        // (TODO: if GUIDs were stable, we should use them instead)
    954949        for (const std::pair<CStr, PlayerAssignment>& p : server.m_PlayerAssignments)
    bool CNetServerWorker::OnAuthenticate(vo  
    968963                ++connectedPlayers;
    969964            else
    970965                ++disconnectedPlayers;
    971966        }
    972967
    973         // Players who weren't already in the game are not allowed to join now that it's started
     968        // Optionally allow everyone or only buddies to join after the game has started
     969        if (!isRejoining)
     970        {
     971            int observerLateJoin = 0;
     972            CFG_GET_VAL("network.lateobserverjoins", observerLateJoin);
     973
     974            if (observerLateJoin == 2)
     975            {
     976                isRejoining = true;
     977            }
     978            else if (observerLateJoin == 1)
     979            {
     980                CStr usernameWithoutRating;
     981                std::regex usernameRegEx("S+ ([0-9]+)");
     982                std::cmatch usernameMatch;
     983                if (std::regex_search(utf8_from_wstring(username).c_str(), usernameMatch, usernameRegEx))
     984                    usernameWithoutRating = usernameMatch[0].str();
     985                debug_printf("witout rating %s\n", usernameWithoutRating.c_str());
     986/*
     987                std::string buddies;
     988                CFG_GET_VAL("lobby.buddies", buddies);
     989                std::regex buddyRegEx("");
     990                std::cmatch buddyMatch;
     991                if (std::regex_search(usernameWithoutRating, buddyMatch, buddyRegEx))
     992                    isRejoining = true;
     993*/          }
     994        }
     995
    974996        if (!isRejoining)
    975997        {
    976998            LOGMESSAGE("Refused connection after game start from not-previously-known user \"%s\"", utf8_from_wstring(username));
    977999            session->Disconnect(NDR_SERVER_ALREADY_IN_GAME);
    9781000            return true;
    9791001        }
    9801002
     1003        int maxObservers = 0;
     1004        CFG_GET_VAL("network.observerlimit", maxObservers);
     1005
    9811006        // Ensure all players will be able to rejoin
    9821007        serverFull = isObserver && (
    9831008            (int) server.m_Sessions.size() - connectedPlayers > maxObservers ||
    9841009            (int) server.m_Sessions.size() + disconnectedPlayers >= MAX_CLIENTS);
    9851010    }