Esempio n. 1
0
        public ErrorCode TryGetRandomGame(JoinRandomType joinType, ILobbyPeer peer, Hashtable gameProperties, string query, out GameState gameState, out string message)
        {
            message = null;

            if (this.gameDict.Count == 0)
            {
                gameState = null;
                return(ErrorCode.NoMatchFound);
            }

            LinkedListNode <GameState> startNode;

            switch (joinType)
            {
            default:
                startNode = this.gameDict.First;
                break;

            case JoinRandomType.FromLastMatch:
                startNode = this.nextJoinRandomStartNode ?? this.gameDict.First;
                break;

            case JoinRandomType.Random:
                var startNodeIndex = this.rnd.Next(this.gameDict.Count);
                startNode = this.gameDict.GetAtIntext(startNodeIndex);
                break;
            }

            if (!TryGetRandomGame(startNode, gameProperties, out gameState))
            {
                return(ErrorCode.NoMatchFound);
            }

            return(ErrorCode.Ok);
        }
Esempio n. 2
0
        public bool TryGetRandomGame(JoinRandomType joinType, ILobbyPeer peer, Hashtable gameProperties, out GameState gameState)
        {
            if (this.gameDict.Count == 0)
            {
                gameState = null;
                return(false);
            }

            LinkedListNode <GameState> startNode;

            switch (joinType)
            {
            default:
                startNode = this.gameDict.First;
                break;

            case JoinRandomType.FromLastMatch:
                startNode = this.nextJoinRandomStartNode ?? this.gameDict.First;
                break;

            case JoinRandomType.Random:
                var startNodeIndex = this.rnd.Next(this.gameDict.Count);
                startNode = this.gameDict.GetAtIntext(startNodeIndex);
                break;
            }

            return(this.TryGetRandomGame(startNode, peer, gameProperties, out gameState));
        }
Esempio n. 3
0
        public ErrorCode TryGetRandomGame(JoinRandomType joinType, ILobbyPeer peer, Hashtable gameProperties, string query, out GameState gameState, out string message)
        {
            message = null;

            if (this.gameDict.Count == 0)
            {
                gameState = null;
                return(ErrorCode.NoMatchFound);
            }

            if (string.IsNullOrEmpty(query))
            {
                var node = this.gameDict.First;
                while (node != null)
                {
                    gameState = node.Value;
                    if (this.IsGameJoinable(gameState))
                    {
                        return(ErrorCode.Ok);
                    }

                    node = node.Next;
                }

                gameState = null;
                return(ErrorCode.NoMatchFound);
            }

            string id;

            try
            {
                id = this.gameDatabase.FindMatch(query);
            }
            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);
        }
Esempio n. 4
0
        public ErrorCode TryGetRandomGame(JoinRandomType joinType, ILobbyPeer peer, Hashtable gameProperties, string query, out GameState gameState, out string message)
        {
            message = null;

            foreach (GameState game in this.GameDict.Values)
            {
                if (game.IsOpen && game.IsVisible && game.IsCreatedOnGameServer && (game.MaxPlayer <= 0 || game.PlayerCount < game.MaxPlayer))
                {
                    if (gameProperties != null && game.MatchGameProperties(gameProperties) == false)
                    {
                        continue;
                    }

                    gameState = game;
                    return(ErrorCode.Ok);
                }
            }

            gameState = null;
            return(ErrorCode.NoMatchFound);
        }
Esempio n. 5
0
        public bool TryGetRandomGame(JoinRandomType joinType, ILobbyPeer peer, Hashtable gameProperties, out GameState gameState)
        {
            foreach (GameState game in this.GameDict.Values)
            {
                if (game.IsOpen && game.IsVisible && game.IsCreatedOnGameServer && (game.MaxPlayer <= 0 || game.PlayerCount < game.MaxPlayer))
                {
                    if (game.IsBlocked(peer))
                    {
                        continue;
                    }

                    if (gameProperties != null && game.MatchGameProperties(gameProperties) == false)
                    {
                        continue;
                    }

                    gameState = game;
                    return(true);
                }
            }

            gameState = null;
            return(false);
        }
Esempio n. 6
0
        public ErrorCode TryGetRandomGame(JoinRandomType joinType, ILobbyPeer peer, Hashtable gameProperties, string query, out GameState gameState, out string message)
        {
            message = null;

            if (this.gameDict.Count == 0)
            {
                gameState = null;
                return ErrorCode.NoMatchFound;
            }

            if (string.IsNullOrEmpty(query))
            {
                var node = this.gameDict.First;
                while (node != null)
                {
                    gameState = node.Value;
                    if (this.IsGameJoinable(gameState))
                    {
                        return ErrorCode.Ok;
                    }

                    node = node.Next;
                }

                gameState = null;
                return ErrorCode.NoMatchFound;
            }

            string id;
            try
            {
                id = this.gameDatabase.FindMatch(query);
            }
            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;
        }
        public ErrorCode TryGetRandomGame(JoinRandomType joinType, ILobbyPeer peer, Hashtable gameProperties, string query, out GameState gameState, out string message)
        {
            message = null;

            foreach (GameState game in this.GameDict.Values)
            {
                if (game.IsOpen && game.IsVisible && game.IsCreatedOnGameServer && (game.MaxPlayer <= 0 || game.PlayerCount < game.MaxPlayer))
                {
                    if (gameProperties != null && game.MatchGameProperties(gameProperties) == false)
                    {
                        continue;
                    }

                    gameState = game;
                    return ErrorCode.Ok;
                }
            }

            gameState = null;
            return ErrorCode.NoMatchFound;
        }
Esempio n. 8
0
        public ErrorCode TryGetRandomGame(JoinRandomType joinType, ILobbyPeer peer, Hashtable gameProperties, string query, out GameState gameState, out string message)
        {
            message = null;

            if (this.gameDict.Count == 0)
            {
                gameState = null;
                return ErrorCode.NoMatchFound;
            }

            LinkedListNode<GameState> startNode;
            switch (joinType)
            {
                default:
                    startNode = this.gameDict.First;
                    break;

                case JoinRandomType.FromLastMatch:
                    startNode = this.nextJoinRandomStartNode ?? this.gameDict.First;
                    break;

                case JoinRandomType.Random:
                    var startNodeIndex = this.rnd.Next(this.gameDict.Count);
                    startNode = this.gameDict.GetAtIntext(startNodeIndex);
                    break;
            }

            if (!TryGetRandomGame(startNode, gameProperties, out gameState))
            {
                return ErrorCode.NoMatchFound;
            }

            return ErrorCode.Ok;
        }