/// <summary> /// Implements the execution of the sendDotPoint 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(GameService current, GameSessions sessions, string message) { if (null == current.Context.BuddyInstance) { sessions.SendMessage(current, "SendDotPointResponse:Failure;BuddyNotFound."); return; } else { if (string.IsNullOrEmpty(message)) { sessions.SendMessage(current, "SendDotPointResponse:Failure;WrongFormat."); return; } string[] location = message.Split(new char[] { ';' }); if (location.Length != 2) { sessions.SendMessage(current, "SendDotPointResponse:Failure;WrongFormat."); return; } sessions.SendMessage(current.Context.BuddyInstance, "FixDotPoint:" + location[0] + ";" + location[1]); sessions.SendMessage(current, "SendDotPointResponse:Successful"); } }
/// <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"); } }
/// <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"); } }
/// <summary> /// Implements the execution of the sendMousePoint 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(GameService current, GameSessions sessions, string message) { if (null == current.Context.BuddyInstance) { sessions.SendMessage(current, "SendMousePointResponse:Failure;Buddy not found."); return; } else { if (string.IsNullOrEmpty(message)) { sessions.SendMessage(current, "SendMousePointResponse:Failure;Co-ordinates are not found in the request."); return; } string[] location = message.Split(new char[] { ';' }); if (location.Length != 2) { sessions.SendMessage(current, "SendMousePointResponse:Failure;Co-ordinates are in incorrect format."); return; } sessions.SendMessage(current.Context.BuddyInstance, "FixMousePoint:" + location[0] + ";" + location[1]); sessions.SendMessage(current, "SendMousePointResponse:Successful"); } }
/// <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(GameService current, GameSessions sessions, string message) { 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"); } }
/// <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"); } }
/// <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"); } }
/// <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(GameService current, GameSessions sessions, string message) { if (null == current.Context.PlayerInstance) { sessions.SendMessage(current, "WinGameResponse:Failure;PlayerNotFound."); return; } else { sessions.SendMessage(current.Context.PlayerInstance, "WinGame"); sessions.SendMessage(current, "WinGameResponse:Successful"); } }
/// <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(GameService current, GameSessions sessions, string message) { if (null == current.Context.BuddyInstance) { sessions.SendMessage(current, "UILoadCompleteResponse:Failure;Buddy not found."); return; } else { sessions.SendMessage(current.Context.BuddyInstance, "CompleteUILoad:" + current.Context.LogOnName); sessions.SendMessage(current, "UILoadCompleteResponse:Successful"); } }
/// <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"); } }
/// <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; } } }
/// <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(GameService current, GameSessions sessions, string message) { if (null == current.Context.BuddyInstance) { sessions.SendMessage(current, "GameCompleteResponse:Failure;Buddy does not exist."); return; } else { GameService buddyInstance = current.Context.BuddyInstance; lock (gameCompleteLock) { if (null != buddyInstance) { buddyInstance.Context.BuddyInstance = null; } if (null != current) { current.Context.BuddyInstance = null; } // Need to send gameComplete response to the current service, gameComplete to buddyInstance // and also we need to braodcast gameCompleteResponse to all other sessions. sessions.BroadcastMessage(BroadcastMessageType.GameCompleteResponse, current, buddyInstance, "GameCompleteResponse:Successful", "GameComplete"); return; } } }
/// <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); } } }
/// <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(GameService current, GameSessions sessions, string message) { if (null == current.Context.BuddyInstance) { sessions.SendMessage(current, "UpdateScoreResponse:Failure;Buddy not found."); return; } else { if (string.IsNullOrEmpty(message)) { sessions.SendMessage(current, "UpdateScoreResponse:Failure;Score is not found."); return; } sessions.SendMessage(current.Context.BuddyInstance, "FixBuddyScore:" + message); sessions.SendMessage(current, "UpdateScoreResponse:Successful"); } }
/// <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"); } }
/// <summary> /// Implements the execution of getbuddyPlayer 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(GameService 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, "GetBuddyPlayersResponse:" + players); }
/// <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); }