Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions GenOnlineService/Controllers/Lobby/LobbyController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,8 @@ public async Task<APIResult> Post(Int64 lobbyID)
internal static bool TryParseSlotState(UInt16 rawValue, out EPlayerType slotState)
{
slotState = (EPlayerType)rawValue;
return Enum.IsDefined(typeof(EPlayerType), slotState);
// hosts can open, close or fill a slot with AI, but never mark it as a human
return Enum.IsDefined(typeof(EPlayerType), slotState) && slotState != EPlayerType.SLOT_PLAYER;
}

// Rejects any wire value that isn't a real ELobbyUpdateField member, so an unknown/malformed
Expand Down Expand Up @@ -542,6 +543,13 @@ internal static bool TryParseLobbyUpdateField(int rawValue, out ELobbyUpdateFiel
bool bOfficialMap = data["map_official"].GetBoolean();
int maxPlayers = data["max_players"].GetInt32();

// same limits as lobby creation
if ((strMap != null && strMap.Length > 255) || (strMapPath != null && strMapPath.Length > 512))
{
Response.StatusCode = (int)HttpStatusCode.BadRequest;
return null;
}

if (strMap != null && strMapPath != null)
{
await using var db = await _dbFactory.CreateDbContextAsync();
Expand Down Expand Up @@ -648,8 +656,9 @@ internal static bool TryParseLobbyUpdateField(int rawValue, out ELobbyUpdateFiel
return null;
}

// human slots are left alone; kicking is how a host removes a player
LobbyMember? TargetMember = lobby.GetMemberFromSlot(slot_index);
if (TargetMember != null)
if (TargetMember != null && TargetMember.SlotState != EPlayerType.SLOT_PLAYER)
{
TargetMember.SetPlayerSlotState(slot_state);
}
Expand Down Expand Up @@ -849,6 +858,13 @@ public async Task<APIResult> Put(Int64 lobbyID)
EUserSessionType sessionType = TokenHelper.GetSessionType(this);
if (user_id != -1 && SessionHelpers.SessionTypeHasAccessTo(sessionType, ESessionAccessType.Gameplay))
{
if (lobby.LobbyType == ELobbyType.QuickMatch && !lobby.MatchedUserIDs.Contains(user_id))
{
Response.StatusCode = (int)HttpStatusCode.Forbidden;
result.success = false;
return result;
}

UInt16 userPreferredPort = data["preferred_port"].GetUInt16();
bool bHasMap = data["has_map"].GetBoolean();
EKnownAnticheatID anticheatID = (EKnownAnticheatID)data["anticheat_id"].GetInt32();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,16 @@ public async Task<APIResult> Put()
// TODO: Update client so this is an associative array and not just in order...
if (jsonReqData != null)
{
// anything past the known stats is ignored, which also bounds the work per request
int numStats = Enum.GetValues<EStatIndex>().Length;
int stat_id = 0;
foreach (JsonElement elem in jsonReqData)
{
if (stat_id >= numStats)
{
break;
}

// TODO: do we care about the string stats? they dont seem relevant, its things like system spec
try
{
Expand Down
12 changes: 8 additions & 4 deletions GenOnlineService/Controllers/WebSocket/WebSocketController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ public WebSocketController(LobbyManager lobbyManager, IDbContextFactory<AppDbCon
_dbFactory = dbFactory;
}

// longer chat is dropped rather than relayed
private const int MaxChatMessageLength = 512;

private static readonly JsonSerializerOptions JsonOpts = new()
{
PropertyNameCaseInsensitive = true,
Expand Down Expand Up @@ -522,7 +525,7 @@ private async Task ProcessWSMessage(UserWebSocketInstance sourceWS, UserSession
WebSocketMessage_Social_FriendChatMessage_Inbound? chatMessage =
JsonSerializer.Deserialize<WebSocketMessage_Social_FriendChatMessage_Inbound>(payload, JsonOpts);

if (chatMessage != null)
if (chatMessage != null && (chatMessage.message?.Length ?? 0) <= MaxChatMessageLength)
{
if (!sourceUserData.TryConsumeChatMessage())
{
Expand Down Expand Up @@ -589,7 +592,7 @@ private async Task ProcessWSMessage(UserWebSocketInstance sourceWS, UserSession
WebSocketMessage_NetworkRoomChatMessageInbound? chatMessage =
JsonSerializer.Deserialize<WebSocketMessage_NetworkRoomChatMessageInbound>(payload, JsonOpts);

if (chatMessage != null)
if (chatMessage != null && (chatMessage.message?.Length ?? 0) <= MaxChatMessageLength)
{
if (!sourceUserData.TryConsumeChatMessage())
{
Expand Down Expand Up @@ -875,7 +878,7 @@ await lobby.RunExclusiveAsync(() =>
WebSocketMessage_LobbyChatMessageInbound? chatMessage =
JsonSerializer.Deserialize<WebSocketMessage_LobbyChatMessageInbound>(payload, JsonOpts);

if (chatMessage != null)
if (chatMessage != null && (chatMessage.message?.Length ?? 0) <= MaxChatMessageLength)
{
// get lobby
Lobby? playerLobby = _lobbyManager.GetLobby(sourceUserSession.currentLobbyID);
Expand Down Expand Up @@ -978,7 +981,8 @@ await lobby.RunExclusiveAsync(() =>
}
}

if (lobbyInfo == null)
// only a lobby still in setup can start
if (lobbyInfo == null || lobbyInfo.State != ELobbyState.GAME_SETUP)
{
return;
}
Expand Down
8 changes: 4 additions & 4 deletions GenOnlineService/Discord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public async Task SendNetworkRoomChat(int roomID, Int64 userID, string strDispla
if (channel != null)
{
string strDiscordMsg = String.Format("[NETWORK ROOM CHAT ID #{0}] {1}", roomID, strFormattedChatMsg);
await channel.SendMessageAsync(strDiscordMsg).ConfigureAwait(true);
await channel.SendMessageAsync(strDiscordMsg, allowedMentions: AllowedMentions.None).ConfigureAwait(true);
}
}
}
Expand Down Expand Up @@ -751,7 +751,7 @@ public void PushDM(SocketUser user, string strMessage)
{
if (user != null)
{
user.SendMessageAsync(strMessage).ContinueWith(t => { }, TaskContinuationOptions.OnlyOnFaulted);
user.SendMessageAsync(strMessage, allowedMentions: AllowedMentions.None).ContinueWith(t => { }, TaskContinuationOptions.OnlyOnFaulted);
}
}
catch
Expand Down Expand Up @@ -799,7 +799,7 @@ public void PushChannelMessage(EDiscordChannelIDs channelID, string strMessage)
ISocketMessageChannel? channel = GetChannel(channelID);
if (channel != null)
{
channel.SendMessageAsync(strMessage).ContinueWith(t => { }, TaskContinuationOptions.OnlyOnFaulted);
channel.SendMessageAsync(strMessage, allowedMentions: AllowedMentions.None).ContinueWith(t => { }, TaskContinuationOptions.OnlyOnFaulted);
}
}
catch
Expand All @@ -823,7 +823,7 @@ public async Task PushMessage(SocketUser user, ulong channelToUse, string strMes
ISocketMessageChannel channel = (ISocketMessageChannel)discord.GetChannel(channelToUse);
if (channel != null)
{
RestUserMessage msg = await channel.SendMessageAsync(strMessage).ConfigureAwait(true);
RestUserMessage msg = await channel.SendMessageAsync(strMessage, allowedMentions: AllowedMentions.None).ConfigureAwait(true);
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions GenOnlineService/LobbyManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,9 @@ public int MaxPlayers

public ELobbyType LobbyType { get; private set; } = ELobbyType.CustomGame;

// quick match lobbies only admit the players the matchmaker paired
public HashSet<Int64> MatchedUserIDs { get; } = new();

public string Region { get; private set; } = "";
public int EstimatedLatency { get; private set; } = 999999;

Expand Down
13 changes: 13 additions & 0 deletions GenOnlineService/MatchmakingManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1266,6 +1266,19 @@ await SendMatchmakingMessage(memberSession,
true, playlist.DesiredPlayers, "", 12345, false, true, 10000, false, String.Empty, -5, false, Constants.g_DefaultCameraMaxHeight, dummyHostUser.ExeCRC, dummyHostUser.IniCRC, ELobbyType.QuickMatch,
dummyHostUser.AnticheatID);

Lobby? quickMatchLobby = lobbyManager.GetLobby(m_LobbyID);
if (quickMatchLobby != null)
{
foreach (MatchmakingBucketMember member in m_lstMembers)
{
UserSession? memberSession = member.GetAssociatedSession();
if (memberSession != null)
{
quickMatchLobby.MatchedUserIDs.Add(memberSession.m_UserID);
}
}
}

// tell both to join our lobby
WebSocketMessage_MatchmakerJoinLobby joinAction = new WebSocketMessage_MatchmakerJoinLobby();
joinAction.msg_id = (int)EWebSocketMessageID.MATCHMAKING_ACTION_JOIN_PREARRANGED_LOBBY;
Expand Down
Loading