예제 #1
0
        /// <summary>
        /// Implements the execution of SendJigSawCoordinates command.
        /// </summary>
        /// <param name="current">Current service instance.</param>
        /// <param name="sessions">Collection of all sessions.</param>
        /// <param name="message">Command arguments.</param>
        public void Execute(JigsawGameService current, GameSessions sessions, string message)
        {
            if (null == current.Context.PlayerInstance)
            {
                sessions.SendMessage(current, "SendJigSawCoordinatesResponse:Failure;PlayerNotFound.");
                return;
            }
            else
            {
                if (string.IsNullOrEmpty(message))
                {
                    sessions.SendMessage(current, "SendJigSawCoordinatesResponse:Failure;WrongFormat.");
                    return;
                }

                string[] location = message.Split(new char[] { ';' });

                if (location.Length != 3)
                {
                    sessions.SendMessage(current, "SendJigSawCoordinatesResponse:Failure;WrongFormat.");
                    return;
                }

                sessions.SendMessage(current.Context.PlayerInstance, "FixJigSawCoordinates:" + location[0] + ";" + location[1] + ";" + location[2]);
                sessions.SendMessage(current, "SendJigSawCoordinatesResponse:Successful");
            }
        }
예제 #2
0
        /// <summary>
        /// Implements the execution of the ResetTile command.
        /// </summary>
        /// <param name="current">Current service instance.</param>
        /// <param name="sessions">Collection of all sessions.</param>
        /// <param name="message">Command arguments.</param>
        public void Execute(JigsawGameService current, GameSessions sessions, string message)
        {
            if (null == current.Context.PlayerInstance)
            {
                sessions.SendMessage(current, "ResetTileResponse:Failure;PlayerNotFound.");
                return;
            }
            else
            {
                if (string.IsNullOrEmpty(message))
                {
                    sessions.SendMessage(current, "ResetTileResponse:Failure;WrongFormat.");
                    return;
                }

                string[] selectedTile = message.Split(new char[] { ';' });

                if (selectedTile.Length != 1)
                {
                    sessions.SendMessage(current, "ResetTileResponse:Failure;WrongFormat.");
                    return;
                }

                sessions.SendMessage(current.Context.PlayerInstance, "ResetTileBack:" + selectedTile[0]);
                sessions.SendMessage(current, "ResetTileResponse:Successful");
            }
        }
예제 #3
0
        /// <summary>
        /// Implements the execution of the AssignTile command.
        /// </summary>
        /// <param name="current">Current service instance.</param>
        /// <param name="sessions">Collection of all sessions.</param>
        /// <param name="message">Command arguments.</param>
        public void Execute(JigsawGameService current, GameSessions sessions, string message)
        {
            if (null == current.Context.PlayerInstance)
            {
                sessions.SendMessage(current, "AssignTileResponse:Failure;PlayerNotFound.");
                return;
            }
            else
            {
                if (string.IsNullOrEmpty(message))
                {
                    sessions.SendMessage(current, "AssignTileResponse:Failure;WrongFormat.");
                    return;
                }

                string[] selectedTile = message.Split(new char[] { ';' });

                if (selectedTile.Length != 2)
                {
                    sessions.SendMessage(current, "AssignTileResponse:Failure;WrongFormat.");
                    return;
                }

                sessions.SendMessage(current.Context.PlayerInstance, "AssignTileToCell:" + selectedTile[0] + ";" + selectedTile[1]);
                sessions.SendMessage(current, "AssignTileResponse:Successful");
            }
        }
예제 #4
0
        /// <summary>
        /// Implements execution of this command.
        /// </summary>
        /// <param name="current">Current gameservice instance.</param>
        /// <param name="sessions">Collection of all sessons.</param>
        /// <param name="message">Command parameters.</param>
        public void Execute(JigsawGameService current, GameSessions sessions, string message)
        {
            if (null == current.Context.PlayerInstance)
            {
                sessions.SendMessage(current, "GameCompleteResponse:Failure;Player does not exist.");
                return;
            }
            else
            {
                JigsawGameService playerInstance = current.Context.PlayerInstance;
                lock (gameCompleteLock)
                {
                    if (null != playerInstance)
                    {
                        playerInstance.Context.PlayerInstance = null;
                    }

                    if (null != current)
                    {
                        current.Context.PlayerInstance = null;
                    }

                    // Need to send gameComplete response to the current service, gameComplete to playerInstance
                    // and also we need to braodcast gameCompleteResponse to all other sessions.
                    sessions.BroadcastMessage(BroadcastMessageType.GameCompleteResponse, current, playerInstance, "GameCompleteResponse:Successful", "GameComplete");
                    return;
                }
            }
        }
예제 #5
0
        /// <summary>
        /// Implements execution of this command.
        /// </summary>
        /// <param name="current">Current gameservice instance.</param>
        /// <param name="sessions">Collection of all sessons.</param>
        /// <param name="message">Command parameters.</param>
        public void Execute(JigsawGameService current, GameSessions sessions, string message)
        {
            if (null == current.Context.PlayerInstance)
            {
                sessions.SendMessage(current, "GameCompleteResponse:Failure;Player does not exist.");
                return;
            }
            else
            {
                JigsawGameService playerInstance = current.Context.PlayerInstance;
                lock (gameCompleteLock)
                {
                    if (null != playerInstance)
                    {
                        playerInstance.Context.PlayerInstance = null;
                    }

                    if (null != current)
                    {
                        current.Context.PlayerInstance = null;
                    }

                    // Need to send gameComplete response to the current service, gameComplete to playerInstance
                    // and also we need to braodcast gameCompleteResponse to all other sessions.
                    sessions.BroadcastMessage(BroadcastMessageType.GameCompleteResponse, current, playerInstance, "GameCompleteResponse:Successful", "GameComplete");
                    return;
                }
            }
        }
예제 #6
0
파일: Login.cs 프로젝트: radtek/cellbank
        /// <summary>
        /// Implements the execution of login command.
        /// </summary>
        /// <param name="current">Current service instance.</param>
        /// <param name="sessions">Collection of all sessions.</param>
        /// <param name="message">Command arguments.</param>
        public void Execute(JigsawGameService current, GameSessions sessions, string message)
        {
            // Check if the context already have Logged in context.
            if (!string.IsNullOrEmpty(current.Context.LogOnName))
            {
                sessions.SendMessage(current, "LoginResponse:Failure;Loggedin");
                return;
            }

            if (string.IsNullOrEmpty(message))
            {
                sessions.SendMessage(current, "LoginResponse:Failure;LoginNameEmpty");
                return;
            }

            var service = sessions.FindSession(message);

            if (null == service && loggedInUsers < MaxUsers)
            {
                Interlocked.Increment(ref loggedInUsers);
                current.Context.LogOnName = message;

                // Need to send successful response to the current service and LogOn response to all other sessions.
                // so that other sessions can also see that this user is logged in.
                sessions.BroadcastMessage(BroadcastMessageType.LogOnResponse, current, null, "LoginResponse:Successful", null);
            }
            else if (MaxUsers == loggedInUsers)
            {
                sessions.SendMessage(current, "LoginResponse:Failure;LoginLimitReached");
            }
            else
            {
                sessions.SendMessage(current, "LoginResponse:Failure;LoginNameTaken");
            }
        }
예제 #7
0
        /// <summary>
        /// Implements the execution of login command.
        /// </summary>
        /// <param name="current">Current service instance.</param>
        /// <param name="sessions">Collection of all sessions.</param>
        /// <param name="message">Command arguments.</param>
        public void Execute(JigsawGameService current, GameSessions sessions, string message)
        {
            // Check if the context already have Logged in context.
            if (!string.IsNullOrEmpty(current.Context.LogOnName))
            {
                sessions.SendMessage(current, "LoginResponse:Failure;Loggedin");
                return;
            }

            if (string.IsNullOrEmpty(message))
            {
                sessions.SendMessage(current, "LoginResponse:Failure;LoginNameEmpty");
                return;
            }

            var service = sessions.FindSession(message);

            if (null == service && loggedInUsers < MaxUsers)
            {
                Interlocked.Increment(ref loggedInUsers);
                current.Context.LogOnName = message;

                // Need to send successful response to the current service and LogOn response to all other sessions.
                // so that other sessions can also see that this user is logged in.
                sessions.BroadcastMessage(BroadcastMessageType.LogOnResponse, current, null, "LoginResponse:Successful", null);
            }
            else if (MaxUsers == loggedInUsers)
            {
                sessions.SendMessage(current, "LoginResponse:Failure;LoginLimitReached");
            }
            else
            {
                sessions.SendMessage(current, "LoginResponse:Failure;LoginNameTaken");
            }
        }
예제 #8
0
        /// <summary>
        /// Implements the execution of SendJigSawCoordinates command.
        /// </summary>
        /// <param name="current">Current service instance.</param>
        /// <param name="sessions">Collection of all sessions.</param>
        /// <param name="message">Command arguments.</param>
        public void Execute(JigsawGameService current, GameSessions sessions, string message)
        {
            if (null == current.Context.PlayerInstance)
            {
                sessions.SendMessage(current, "SendJigSawCoordinatesResponse:Failure;PlayerNotFound.");
                return;
            }
            else
            {
                if (string.IsNullOrEmpty(message))
                {
                    sessions.SendMessage(current, "SendJigSawCoordinatesResponse:Failure;WrongFormat.");
                    return;
                }

                string[] location = message.Split(new char[] { ';' });

                if (location.Length != 3)
                {
                    sessions.SendMessage(current, "SendJigSawCoordinatesResponse:Failure;WrongFormat.");
                    return;
                }

                sessions.SendMessage(current.Context.PlayerInstance, "FixJigSawCoordinates:" + location[0] + ";" + location[1] + ";" + location[2]);
                sessions.SendMessage(current, "SendJigSawCoordinatesResponse:Successful");
            }
        }
예제 #9
0
        /// <summary>
        /// Implements the execution of GetPlayersList command.
        /// </summary>
        /// <param name="current">Current service instance.</param>
        /// <param name="sessions">Collection of all sessions.</param>
        /// <param name="message">Command arguments.</param>
        public void Execute(JigsawGameService current, GameSessions sessions, string message)
        {
            var players = string.Empty;
            players = sessions.GetOtherLoggedInSessionsList(current);

            // Removes last semicolon from players string.
            if (!string.IsNullOrEmpty(players))
            {
                players = players.Substring(0, players.Length - 1);
            }

            sessions.SendMessage(current, "GetPlayersListResponse:" + players);
        }
예제 #10
0
 /// <summary>
 /// Implements the execution of the UILoadComplete command.
 /// </summary>
 /// <param name="current">Current service instance.</param>
 /// <param name="sessions">Collection of all sessions.</param>
 /// <param name="message">Command arguments.</param>
 public void Execute(JigsawGameService current, GameSessions sessions, string message)
 {
     if (null == current.Context.PlayerInstance)
     {
         sessions.SendMessage(current, "UILoadCompleteResponse:Failure;PlayerNotFound.");
         return;
     }
     else
     {
         sessions.SendMessage(current.Context.PlayerInstance, "CompleteUILoad:" + current.Context.LogOnName);
         sessions.SendMessage(current, "UILoadCompleteResponse:Successful");
     }
 }
예제 #11
0
 /// <summary>
 /// Implements the execution of the UILoadComplete command.
 /// </summary>
 /// <param name="current">Current service instance.</param>
 /// <param name="sessions">Collection of all sessions.</param>
 /// <param name="message">Command arguments.</param>
 public void Execute(JigsawGameService current, GameSessions sessions, string message)
 {
     if (null == current.Context.PlayerInstance)
     {
         sessions.SendMessage(current, "UILoadCompleteResponse:Failure;PlayerNotFound.");
         return;
     }
     else
     {
         sessions.SendMessage(current.Context.PlayerInstance, "CompleteUILoad:" + current.Context.LogOnName);
         sessions.SendMessage(current, "UILoadCompleteResponse:Successful");
     }
 }
예제 #12
0
        /// <summary>
        /// Implements the execution of GetPlayersList command.
        /// </summary>
        /// <param name="current">Current service instance.</param>
        /// <param name="sessions">Collection of all sessions.</param>
        /// <param name="message">Command arguments.</param>
        public void Execute(JigsawGameService current, GameSessions sessions, string message)
        {
            var players = string.Empty;

            players = sessions.GetOtherLoggedInSessionsList(current);

            // Removes last semicolon from players string.
            if (!string.IsNullOrEmpty(players))
            {
                players = players.Substring(0, players.Length - 1);
            }

            sessions.SendMessage(current, "GetPlayersListResponse:" + players);
        }
예제 #13
0
        /// <summary>
        /// Implements the execution of selectPlayer command.
        /// </summary>
        /// <param name="current">Current service instance.</param>
        /// <param name="sessions">Collection of all sessions.</param>
        /// <param name="message">Command arguments.</param>
        public void Execute(JigsawGameService current, GameSessions sessions, string message)
        {
            if (null != current.Context.PlayerInstance)
            {
                sessions.SendMessage(current, "SelectPlayerResponse:Failure;PlayerExist.");
                return;
            }
            else
            {
                if (string.IsNullOrEmpty(message))
                {
                    sessions.SendMessage(current, "SelectPlayerResponse:Failure;WrongRequest.");
                    return;
                }

                var playerInstance = sessions.FindSession(message);

                if (null == playerInstance)
                {
                    sessions.SendMessage(current, "SelectPlayerResponse:Failure;PlayerDoesNotExist" + message);
                    return;
                }
                else
                {
                    // Associate both players and then send all responses in the same atomic operation.
                    lock (selectPlayerLock)
                    {
                        if (null == playerInstance.Context.PlayerInstance && null == current.Context.PlayerInstance)
                        {
                            current.Context.PlayerInstance        = playerInstance;
                            playerInstance.Context.PlayerInstance = current;

                            // Need to send selectPlayer response to the current service, fixedPlayerresponse to PlayerInstance
                            // and also we need to braodcast selectPlayerResposne to other sessions.
                            sessions.BroadcastMessage(BroadcastMessageType.SelectPlayerResponse, current, playerInstance, "SelectPlayerResponse:Successful", "FixedPlayerResponse:" + current.Context.LogOnName);
                            return;
                        }
                    }

                    // Selected player is already a Player.
                    sessions.SendMessage(current, "SelectPlayerResponse:Failure;BusyPlayer;" + message);
                }
            }
        }
예제 #14
0
        /// <summary>
        /// Implements the execution of selectPlayer command.
        /// </summary>
        /// <param name="current">Current service instance.</param>
        /// <param name="sessions">Collection of all sessions.</param>
        /// <param name="message">Command arguments.</param>
        public void Execute(JigsawGameService current, GameSessions sessions, string message)
        {
            if (null != current.Context.PlayerInstance)
            {
                sessions.SendMessage(current, "SelectPlayerResponse:Failure;PlayerExist.");
                return;
            }
            else
            {
                if (string.IsNullOrEmpty(message))
                {
                    sessions.SendMessage(current, "SelectPlayerResponse:Failure;WrongRequest.");
                    return;
                }

                var playerInstance = sessions.FindSession(message);

                if (null == playerInstance)
                {
                    sessions.SendMessage(current, "SelectPlayerResponse:Failure;PlayerDoesNotExist" + message);
                    return;
                }
                else
                {
                    // Associate both players and then send all responses in the same atomic operation.
                    lock (selectPlayerLock)
                    {
                        if (null == playerInstance.Context.PlayerInstance && null == current.Context.PlayerInstance)
                        {
                            current.Context.PlayerInstance = playerInstance;
                            playerInstance.Context.PlayerInstance = current;

                            // Need to send selectPlayer response to the current service, fixedPlayerresponse to PlayerInstance
                            // and also we need to braodcast selectPlayerResposne to other sessions.
                            sessions.BroadcastMessage(BroadcastMessageType.SelectPlayerResponse, current, playerInstance, "SelectPlayerResponse:Successful", "FixedPlayerResponse:" + current.Context.LogOnName);
                            return;
                        }
                    }

                    // Selected player is already a Player.
                    sessions.SendMessage(current, "SelectPlayerResponse:Failure;BusyPlayer;" + message);
                }
            }
        }
예제 #15
0
        /// <summary>
        /// Implements the execution of the updateScore command.
        /// </summary>
        /// <param name="current">Current service instance.</param>
        /// <param name="sessions">Collection of all sessions.</param>
        /// <param name="message">Command arguments.</param>
        public void Execute(JigsawGameService current, GameSessions sessions, string message)
        {
            if (null == current.Context.PlayerInstance)
            {
                sessions.SendMessage(current, "UpdateScoreResponse:Failure;PlayerNotFound.");
                return;
            }
            else
            {
                if (string.IsNullOrEmpty(message))
                {
                    sessions.SendMessage(current, "UpdateScoreResponse:Failure;Score is not found.");
                    return;
                }

                 sessions.SendMessage(current.Context.PlayerInstance, "FixPlayerScore:" + message);
                 sessions.SendMessage(current, "UpdateScoreResponse:Successful");
            }
        }
예제 #16
0
        /// <summary>
        /// Implements the execution of the updateScore command.
        /// </summary>
        /// <param name="current">Current service instance.</param>
        /// <param name="sessions">Collection of all sessions.</param>
        /// <param name="message">Command arguments.</param>
        public void Execute(JigsawGameService current, GameSessions sessions, string message)
        {
            if (null == current.Context.PlayerInstance)
            {
                sessions.SendMessage(current, "UpdateScoreResponse:Failure;PlayerNotFound.");
                return;
            }
            else
            {
                if (string.IsNullOrEmpty(message))
                {
                    sessions.SendMessage(current, "UpdateScoreResponse:Failure;Score is not found.");
                    return;
                }

                sessions.SendMessage(current.Context.PlayerInstance, "FixPlayerScore:" + message);
                sessions.SendMessage(current, "UpdateScoreResponse:Successful");
            }
        }