Ejemplo n.º 1
0
        private ErrorCode TryGetRandomGame(string queryData, JoinRandomGameRequest joinRequest, ILobbyPeer peer, out GameState gameState, out string message)
        {
            message = null;

            int skipCount = 0;

            while (true)
            {
                string id;
                try
                {
                    id = this.gameDatabase.FindMatch(queryData, skipCount++);
                }
                catch (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);
                }

                if (IsGameJoinable(joinRequest, peer, gameState))
                {
                    if (log.IsDebugEnabled)
                    {
                        log.Debug($"Random Game '{gameState}', CheckUserOnJoin:{gameState.CheckUserIdOnJoin}, " +
                                  $"UserLists: {gameState.GetUserListsAsString()} Properties:{ValueToString.ToString(gameState.ToHashTable())}" +
                                  $"is joinable for request: {ValueToString.OperationToString(joinRequest.OperationRequest)}, Joining User:{peer.UserId}");
                    }
                    return(ErrorCode.Ok);
                }
            }
        }
Ejemplo n.º 2
0
        private ErrorCode GetFirstJoinableGame(JoinRandomGameRequest joinRequest, ILobbyPeer peer, out GameState gameState)
        {
            var node = this.gameDict.First;

            while (node != null)
            {
                gameState = node.Value;
                if (IsGameJoinable(joinRequest, peer, gameState))
                {
                    log.Debug($"First Joinable Game '{gameState}', CheckUserOnJoin:{gameState.CheckUserIdOnJoin}, " +
                              $"UserLists: {gameState.GetUserListsAsString()} Properties:{ValueToString.ToString(gameState.ToHashTable())}" +
                              $"is joinable for request: {ValueToString.OperationToString(joinRequest.OperationRequest)}, Joining User:{peer.UserId}");
                    return(ErrorCode.Ok);
                }

                node = node.Next;
            }

            gameState = null;
            return(ErrorCode.NoMatchFound);
        }
        OperationResponse IOperationHandler.OnOperationRequest(PeerBase peer, OperationRequest operationRequest, SendParameters sendParameters)
        {
            try
            {
                return(this.OnOperationRequest(peer, operationRequest, sendParameters));
            }
            catch (Exception e)
            {
                /// we do not use LogExtensions log methods here to reduce cpu loading if message will be skipped anyway
                if (exceptionLogGuard.IncrementAndCheck())
                {
                    var message = LogExtensions.AddSkipedMessagesInfo(exceptionLogGuard,
                                                                      $"OnOperationRequest Exception: p:{peer}, Exception Msg:{e.Message}, request:{ValueToString.OperationToString(operationRequest)}");
                    log.Error(message, e);
                }

                return(new OperationResponse(operationRequest.OperationCode)
                {
                    ReturnCode = (short)ErrorCode.InternalServerError,
                    DebugMessage = e.ToString()
                });
            }
        }