public override ErrorCode TryGetRandomGame(JoinRandomGameRequest joinRequest, ILobbyPeer peer, out GameState gameState, out string message) { message = null; if (this.gameDict.Count == 0) { gameState = null; return(ErrorCode.NoMatchFound); } if (string.IsNullOrEmpty(joinRequest.QueryData)) { var node = this.gameDict.First; while (node != null) { gameState = node.Value; if (gameState.IsJoinable) { if (!gameState.CheckUserIdOnJoin || (!gameState.ContainsUser(peer.UserId) && !gameState.IsUserInExcludeList(peer.UserId) && gameState.CheckSlots(peer.UserId, joinRequest.AddUsers))) { return(ErrorCode.Ok); } } node = node.Next; } gameState = null; return(ErrorCode.NoMatchFound); } string id; try { id = this.gameDatabase.FindMatch(joinRequest.QueryData); } catch (System.Data.Common.DbException sqlException) { gameState = null; message = sqlException.Message; return(ErrorCode.OperationInvalid); } if (string.IsNullOrEmpty(id)) { gameState = null; return(ErrorCode.NoMatchFound); } if (!this.gameDict.TryGet(id, out gameState)) { return(ErrorCode.NoMatchFound); } return(ErrorCode.Ok); }
protected static bool IsGameJoinable(JoinRandomGameRequest joinRequest, ILobbyPeer peer, GameState gameState) { if (!gameState.IsJoinable) { return(false); } if (!gameState.SupportsProtocol(peer.NetworkProtocol)) { return(false); } return(!gameState.CheckUserIdOnJoin || (!gameState.ContainsUser(peer.UserId) && !gameState.IsUserInExcludeList(peer.UserId) && gameState.CheckSlots(peer.UserId, joinRequest.AddUsers))); }
public override ErrorCode TryGetRandomGame(JoinRandomGameRequest joinRequest, ILobbyPeer peer, out GameState gameState, out string message) { message = null; if (this.gameDict.Count == 0) { gameState = null; return ErrorCode.NoMatchFound; } if (string.IsNullOrEmpty(joinRequest.QueryData)) { var node = this.gameDict.First; while (node != null) { gameState = node.Value; if (gameState.IsJoinable) { if (!gameState.CheckUserIdOnJoin || (!gameState.ContainsUser(peer.UserId) && !gameState.IsUserInExcludeList(peer.UserId) && gameState.CheckSlots(peer.UserId, joinRequest.AddUsers))) { return ErrorCode.Ok; } } node = node.Next; } gameState = null; return ErrorCode.NoMatchFound; } string id; try { id = this.gameDatabase.FindMatch(joinRequest.QueryData); } catch (System.Data.Common.DbException sqlException) { gameState = null; message = sqlException.Message; return ErrorCode.OperationInvalid; } if (string.IsNullOrEmpty(id)) { gameState = null; return ErrorCode.NoMatchFound; } if (!this.gameDict.TryGet(id, out gameState)) { return ErrorCode.NoMatchFound; } return ErrorCode.Ok; }