Ticket #4528: late_observer_buddies_v0.8.patch
File late_observer_buddies_v0.8.patch, 5.0 KB (added by , 7 years ago) |
---|
-
binaries/data/config/default.cfg
buddies = "," ; Co 377 377 [mod] 378 378 enabledmods = "mod public" 379 379 380 380 [network] 381 381 duplicateplayernames = 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 started382 lateobserverjoins = 2 ; Allow observers to join the game after it started 383 383 observerlimit = 8 ; Prevent further observer joins in running games if this limit is reached 384 384 385 385 [overlay] 386 386 fps = "false" ; Show frames per second in top right corner 387 387 realtime = "false" ; Show current system time in top right corner -
binaries/data/mods/public/gui/options/options.json
78 78 "label": "Persist Match Settings", 79 79 "tooltip": "Save and restore match settings for quick reuse when hosting another game", 80 80 "parameters": { "config": "persistmatchsettings" } 81 81 }, 82 82 { 83 "type": " boolean",83 "type": "dropdown", 84 84 "label": "Late Observer Joins", 85 "tooltip": "Allow observers to join the gameafter 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" } 87 87 }, 88 88 { 89 89 "type": "number", 90 90 "label": "Observer Limit", 91 91 "tooltip": "Prevent further observers from joining if the limit is reached", -
source/network/NetServer.cpp
23 23 #include "NetMessage.h" 24 24 #include "NetSession.h" 25 25 #include "NetServerTurnManager.h" 26 26 #include "NetStats.h" 27 27 28 // TODO: find right place 29 #include <regex> 30 28 31 #include "lib/external_libraries/enet.h" 29 32 #include "ps/CLogger.h" 30 33 #include "ps/ConfigDB.h" 31 34 #include "ps/Profile.h" 32 35 #include "scriptinterface/ScriptInterface.h" … … bool CNetServerWorker::OnAuthenticate(vo 928 931 { 929 932 session->Disconnect(NDR_BANNED); 930 933 return true; 931 934 } 932 935 933 // Optionally allow observers to join after the game has started934 bool observerLateJoin = false;935 CFG_GET_VAL("network.lateobserverjoins", observerLateJoin);936 937 int maxObservers = 0;938 CFG_GET_VAL("network.observerlimit", maxObservers);939 940 936 bool isRejoining = false; 941 937 bool serverFull = false; 942 938 if (server.m_State == SERVER_STATE_PREGAME) 943 939 { 944 940 // Don't check for maxObservers in the gamesetup, as we don't know yet who will be assigned 945 941 serverFull = server.m_Sessions.size() >= MAX_CLIENTS; 946 942 } 947 943 else 948 944 { 949 isRejoining = observerLateJoin;950 945 bool isObserver = true; 951 946 int disconnectedPlayers = 0; 952 947 int connectedPlayers = 0; 953 948 // (TODO: if GUIDs were stable, we should use them instead) 954 949 for (const std::pair<CStr, PlayerAssignment>& p : server.m_PlayerAssignments) … … bool CNetServerWorker::OnAuthenticate(vo 968 963 ++connectedPlayers; 969 964 else 970 965 ++disconnectedPlayers; 971 966 } 972 967 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 974 996 if (!isRejoining) 975 997 { 976 998 LOGMESSAGE("Refused connection after game start from not-previously-known user \"%s\"", utf8_from_wstring(username)); 977 999 session->Disconnect(NDR_SERVER_ALREADY_IN_GAME); 978 1000 return true; 979 1001 } 980 1002 1003 int maxObservers = 0; 1004 CFG_GET_VAL("network.observerlimit", maxObservers); 1005 981 1006 // Ensure all players will be able to rejoin 982 1007 serverFull = isObserver && ( 983 1008 (int) server.m_Sessions.size() - connectedPlayers > maxObservers || 984 1009 (int) server.m_Sessions.size() + disconnectedPlayers >= MAX_CLIENTS); 985 1010 }