public string this[GameExecutionResult result] { get { switch (result) { case GameExecutionResult.ERROR: return("General error."); case GameExecutionResult.ERR_ALREADY_CONNECTED: return("You are already connected."); case GameExecutionResult.ERR_ALREADY_OCCUPIED: return("The region is already occupied by a follower."); case GameExecutionResult.ERR_INCORRECT_COLOR: return("The color is incorrect."); case GameExecutionResult.ERR_INCORRECT_COORDS: return("Invalid coordinates."); case GameExecutionResult.ERR_NOT_ON_MOVE: return("You are not on move."); case GameExecutionResult.ERR_NO_FOLLOWER_AVAILABLE: return("You have no follower available"); case GameExecutionResult.ERR_NO_SURROUNDINGS: return("Tile must be placed next to other tile."); case GameExecutionResult.ERR_TOO_MANY_PLAYERS: return("There are already too much players."); case GameExecutionResult.ERR_UNKNOWN_PLAYER: return("You have to log as player first."); case GameExecutionResult.ERR_WRONG_SURROUNDINGS: return("The surrouning tiles has different region types."); case GameExecutionResult.ERR_WRONG_TILE: return("You are placing a wrong tile."); case GameExecutionResult.ERR_WRONG_TIME: return("You are not supposed to do that now."); case GameExecutionResult.NONE: return("There is no response."); case GameExecutionResult.OK: return("OK."); default: return("Unexpected result."); } } }
public GameException(GameExecutionResult result) { _Result = result; }
/// <summary> /// Loop for handling messages. /// </summary> public void MessageHandlingLoop() { try { // Inifinite loop while (true) { // Waiting for any message HasMessageResetEvent.Wait(); lock (MessageHandlerThread) { HasMessageResetEvent.Reset(); // Handle all messages while (true) { // Get next message AnnotedPlayerRequest msg = Socket.GetNextMessage(); // Finish when no message to handle if (msg == null) { break; } PlayerRequest rqst = msg.Request; GameExecutionResult result = GameExecutionResult.NONE; // Check if player should be known when making the request if (rqst.Type != PlayerRequestType.CONNECT && rqst.Type != PlayerRequestType.DISCONNECT && !(PlayersInGame.TryGetValue(rqst.Color, out ClientHandlerSocket realSocket) && realSocket == msg.HandlerSocket)) { result = GameExecutionResult.ERR_UNKNOWN_PLAYER; } else { result = GameExecutionResult.OK; try { switch (rqst.Type) { case PlayerRequestType.CONNECT: ConnectPlayer(msg); break; case PlayerRequestType.FOLLOWER_PLACEMENT: Executor.PlaceFollower(rqst.Color, rqst.Coords, rqst.RegionId); break; case PlayerRequestType.FOLLOWER_REMOVEMENT: Executor.RemoveFollower(rqst.Color, rqst.Coords); break; case PlayerRequestType.NO_FOLLOWER_PLACEMENT: Executor.NoFollowerPlacement(rqst.Color); break; case PlayerRequestType.TILE_PLACEMENT: Executor.PlaceTile(rqst.Color, rqst.Scheme, rqst.Coords, rqst.Orientation); break; case PlayerRequestType.DISCONNECT: msg.HandlerSocket.Stop(); Socket_ClientDisconnected(msg.HandlerSocket); result = GameExecutionResult.NONE; break; default: result = GameExecutionResult.ERROR; break; } } catch (GameException ex) { result = ex.ToExecutionResult(); } if (result != GameExecutionResult.NONE) { msg.HandlerSocket.SendMessage(new ServerResponse() { Type = ServerResponseType.EXECUTION_REQUEST_RESULT, Request = rqst, ExecutionResult = result }); } } } } } } catch (ThreadAbortException) { } }