コード例 #1
0
        public void Handle(Connection conn)
        {
            while (conn.IsConnected())
            {
                try
                {
                    string[] message = conn.ReadMessage();
                    var      request = new Request(message);

                    switch (request.Command)
                    {
                    case Command.Login:
                        serverController.ConnectClient(conn, request);
                        break;

                    case Command.DoAction:
                        serverController.DoAction(conn, request);
                        break;

                    case Command.ListPlayersInGame:
                        serverController.ListPlayersInGame(conn, request);
                        break;

                    case Command.ListAllClients:
                        serverController.ListAllClients(conn, request);
                        break;

                    case Command.ListConnectedClients:
                        serverController.ListConnectedClients(conn, request);
                        break;

                    case Command.DisconnectClient:
                        serverController.DisconnectClient(conn, request);
                        break;

                    case Command.JoinGame:
                        serverController.JoinGame(conn, request);
                        break;

                    case Command.SelectRole:
                        serverController.SelectRole(conn, request);
                        break;

                    case Command.TimesOut:
                        serverController.TimesOut(conn, request);
                        break;

                    case Command.RemovePlayerFromGame:
                        serverController.RemovePlayerFromGame(conn, request);
                        break;

                    case Command.CheckIfGameHasFinished:
                        serverController.CheckIfGameHasFinished(conn, request);
                        break;

                    case Command.GetResultByTimesOut:
                        serverController.GetResultByTimesOut(conn, request);
                        break;

                    case Command.ReadyToSendPicture:
                        serverController.ReadyToSendPicture(conn, request);
                        break;

                    case Command.SendPicturePart:
                        serverController.SendPicturePart(conn, request);
                        break;

                    case Command.SendLastPicturePart:
                        serverController.SendLastPicturePart(conn, request);
                        break;

                    default:
                        serverController.InvalidCommand(conn);
                        break;
                    }
                }
                catch (Exception e)
                {
                    conn.SendMessage(new string[] { ResponseCode.InternalServerError.ToString(), "There was a problem with the server" });
                    break;
                }
            }
        }