Ticket #3254: t3254_arbitrary_observer_limit_v1.patch
File t3254_arbitrary_observer_limit_v1.patch, 6.1 KB (added by , 8 years ago) |
---|
-
binaries/data/config/default.cfg
xpartamupp = "wfgbot20" ; Na 352 352 enabledmods = "mod public" 353 353 354 354 [network] 355 355 duplicateplayernames = false ; Rename joining player to "User (2)" if "User" is already connected, otherwise prohibit join. 356 356 lateobserverjoins = false ; Allow observers to join the game after it started 357 observerlimit = 5 ; Allow observers to join the game after it started 357 358 358 359 [overlay] 359 360 fps = "false" ; Show frames per second in top right corner 360 361 realtime = "false" ; Show current system time in top right corner 361 362 netwarnings = "true" ; Show warnings if the network connection is bad -
binaries/data/mods/public/gui/common/network.js
function getDisconnectReason(id) 56 56 case 3: return translate("Game is loading, please try later"); 57 57 case 4: return translate("Game has already started, no observers allowed"); 58 58 case 5: return translate("You have been kicked"); 59 59 case 6: return translate("You have been banned"); 60 60 case 7: return translate("Playername in use. If you were disconnected, retry in few seconds"); 61 case 8: return translate("Server full"); 61 62 default: 62 63 warn("Unknown disconnect-reason ID received: " + id); 63 64 return sprintf(translate("\\[Invalid value %(id)s]"), { "id": id }); 64 65 } 65 66 } -
binaries/data/mods/public/gui/options/options.json
64 64 { 65 65 "type": "boolean", 66 66 "label": "Late Observer Joins", 67 67 "tooltip": "Allow observers to join the game after it started", 68 68 "parameters": { "config": "network.lateobserverjoins" } 69 }, 70 { 71 "type": "number", 72 "label": "Observer Limit", 73 "tooltip": "Prevent further observer from joining if the limit is reached", 74 "parameters": { "config": "network.observerlimit", "min": 0, "max": 16 } 69 75 } 70 76 ], 71 77 "graphicsSetting": 72 78 [ 73 79 { -
source/network/NetHost.h
enum NetDisconnectReason 64 64 NDR_INCORRECT_PROTOCOL_VERSION, 65 65 NDR_SERVER_LOADING, 66 66 NDR_SERVER_ALREADY_IN_GAME, 67 67 NDR_KICKED, 68 68 NDR_BANNED, 69 NDR_PLAYERNAME_IN_USE 69 NDR_PLAYERNAME_IN_USE, 70 NDR_SERVER_FULL 70 71 }; 71 72 72 73 class CNetHost 73 74 { 74 75 public: -
source/network/NetServer.cpp
37 37 #include <miniupnpc/miniupnpc.h> 38 38 #include <miniupnpc/upnpcommands.h> 39 39 #include <miniupnpc/upnperrors.h> 40 40 #endif 41 41 42 /** 43 * Number of peers to allocate for the enet host. 44 * Limited by ENET_PROTOCOL_MAXIMUM_PEER_ID (4096). 45 * 46 * At most 8 players, 16 observers and 1 temporary connection to send the "server full" disconnect-reason. 47 */ 48 #define MAX_CLIENTS 25 49 42 50 #define DEFAULT_SERVER_NAME L"Unnamed Server" 43 51 #define DEFAULT_WELCOME_MESSAGE L"Welcome" 44 #define MAX_CLIENTS 1045 52 46 53 static const int CHANNEL_COUNT = 1; 47 54 48 55 /** 49 56 * enet_host_service timeout (msecs). … … bool CNetServerWorker::OnAuthenticate(vo 927 934 928 935 // Optionally allow observers to join after the game has started 929 936 bool observerLateJoin = false; 930 937 CFG_GET_VAL("network.lateobserverjoins", observerLateJoin); 931 938 932 // If the game has already started, only allow rejoins 939 int maxObservers = 0; 940 CFG_GET_VAL("network.observerlimit", maxObservers); 941 933 942 bool isRejoining = false; 934 if (server.m_State != SERVER_STATE_PREGAME) 943 bool serverFull = false; 944 if (server.m_State == SERVER_STATE_PREGAME) 935 945 { 936 // Search for an old disconnected player of the same name 937 // (TODO: if GUIDs were stable, we should use them instead) 938 isRejoining = 939 observerLateJoin || 940 std::find_if( 941 server.m_PlayerAssignments.begin(), server.m_PlayerAssignments.end(), 942 [&username] (const std::pair<CStr, PlayerAssignment>& pair) 943 { return !pair.second.m_Enabled && pair.second.m_Name == username; }) 944 != server.m_PlayerAssignments.end(); 946 // Don't check for maxObservers in the gamesetup, as we don't know who will be assigned 947 serverFull = server.m_Sessions.size() >= MAX_CLIENTS; 948 } 949 else 950 { 951 isRejoining = observerLateJoin; 952 bool isObserver = true; 953 int disconnectedPlayers = 0; 954 int connectedPlayers = 0; 955 for (PlayerAssignmentMap::iterator it = server.m_PlayerAssignments.begin(); it != server.m_PlayerAssignments.end(); ++it) 956 { 957 // (TODO: if GUIDs were stable, we should use them instead) 958 if (!it->second.m_Enabled && it->second.m_Name == username) 959 { 960 isObserver = it->second.m_PlayerID == -1; 961 isRejoining = true; 962 } 963 964 if (it->second.m_PlayerID == -1) 965 continue; 945 966 967 if (it->second.m_Enabled) 968 ++connectedPlayers; 969 else 970 ++disconnectedPlayers; 971 } 972 973 // If the game has already started, only allow rejoins 946 974 // Players who weren't already in the game are not allowed to join now that it's started 947 975 if (!isRejoining) 948 976 { 949 977 LOGMESSAGE("Refused connection after game start from not-previously-known user \"%s\"", utf8_from_wstring(username)); 950 978 session->Disconnect(NDR_SERVER_ALREADY_IN_GAME); 951 979 return true; 952 980 } 981 982 // Ensure all players will be able to rejoin 983 serverFull = isObserver && ( 984 (int) server.m_Sessions.size() - connectedPlayers > maxObservers || 985 (int) server.m_Sessions.size() + disconnectedPlayers >= MAX_CLIENTS); 986 } 987 988 if (serverFull) 989 { 990 session->Disconnect(NDR_SERVER_FULL); 991 return true; 953 992 } 954 993 955 994 // TODO: check server password etc? 956 995 957 996 u32 newHostID = server.m_NextHostID++;