1
0
forked from 0ad/0ad

Optionally allow late observers for buddies only.

Differential Revision: https://code.wildfiregames.com/D549
Fixes #4528
Reviewed By: fpre
This was SVN commit r19685.
This commit is contained in:
elexis 2017-05-28 18:05:08 +00:00
parent d44a407fc4
commit 31d1536e52
3 changed files with 41 additions and 10 deletions

View File

@ -388,7 +388,7 @@ enabledmods = "mod public"
[network]
duplicateplayernames = false ; Rename joining player to "User (2)" if "User" is already connected, otherwise prohibit join.
lateobserverjoins = true ; Allow observers to join the game after it started
lateobservers = buddies ; Allow observers to join the game after it started. Possible values: disabled, buddies, everyone.
observerlimit = 8 ; Prevent further observer joins in running games if this limit is reached
[overlay]

View File

@ -93,10 +93,17 @@
}
},
{
"type": "boolean",
"type": "dropdown",
"label": "Late Observer Joins",
"tooltip": "Allow observers to join the game after it started",
"parameters": { "config": "network.lateobserverjoins" }
"tooltip": "Allow everybody or buddies only to join the game as observer after it started",
"parameters": {
"config": "network.lateobservers",
"list": [
{ "value": "everyone", "label": "Everyone" },
{ "value": "buddies", "label": "Buddies" },
{ "value": "disabled", "label": "Disabled" }
]
}
},
{
"type": "number",

View File

@ -930,10 +930,6 @@ bool CNetServerWorker::OnAuthenticate(void* context, CFsmEvent* event)
return true;
}
// Optionally allow observers to join after the game has started
bool observerLateJoin = false;
CFG_GET_VAL("network.lateobserverjoins", observerLateJoin);
int maxObservers = 0;
CFG_GET_VAL("network.observerlimit", maxObservers);
@ -946,7 +942,6 @@ bool CNetServerWorker::OnAuthenticate(void* context, CFsmEvent* event)
}
else
{
isRejoining = observerLateJoin;
bool isObserver = true;
int disconnectedPlayers = 0;
int connectedPlayers = 0;
@ -970,7 +965,36 @@ bool CNetServerWorker::OnAuthenticate(void* context, CFsmEvent* event)
++disconnectedPlayers;
}
// Players who weren't already in the game are not allowed to join now that it's started
// Optionally allow everyone or only buddies to join after the game has started
if (!isRejoining)
{
CStr observerLateJoin;
CFG_GET_VAL("network.lateobservers", observerLateJoin);
if (observerLateJoin == "everyone")
{
isRejoining = true;
}
else if (observerLateJoin == "buddies")
{
std::size_t pos = username.find(L" (");
CStrW usernameWithoutRating(pos == CStrW::npos ? username : username.substr(0, pos));
CStr buddies;
CFG_GET_VAL("lobby.buddies", buddies);
std::wstringstream buddiesStream(wstring_from_utf8(buddies));
CStrW buddy;
while (std::getline(buddiesStream, buddy, L','))
{
if (buddy == usernameWithoutRating)
{
isRejoining = true;
break;
}
}
}
}
if (!isRejoining)
{
LOGMESSAGE("Refused connection after game start from not-previously-known user \"%s\"", utf8_from_wstring(username));