public static void DoHandle(Client client, byte[] data, Server server)
        {
            BaseResponseData responseData = null;

            try {
                EnterInRoomData enterInRoomData = Utils.ToObjectFromBytes <EnterInRoomData>(data);

                Room room = server.GetRoomByName(enterInRoomData.Name);

                if (room == null)
                {
                    responseData = new BaseResponseData(RequestTypes.EnterInRoom, RequestResult.UnknowRoom);
                    server.SendResponseData(new List <Client>()
                    {
                        client
                    }, (byte)responseData.Request, responseData);
                    return;
                }

                server.RemoveClientFromRoom(client, client.CurrentRoomID);

                AddClientInRoom(client, room.ID, server);

                Console.WriteLine("Client entered in room");
            } catch (Exception e) {
                responseData = new BaseResponseData(RequestTypes.EnterInRoom, RequestResult.Ok);
                server.SendResponseData(new List <Client>()
                {
                    client
                }, (byte)responseData.Request, responseData);

                Console.WriteLine("Error {0} - {1}", e.Message, e.StackTrace);
            }
        }
示例#2
0
    public void EnterInRoom(string name)
    {
        if (client != null)
        {
            EnterInRoomData enterInRoomData = new EnterInRoomData(name);
            SendRequest(client, (byte)RequestTypes.EnterInRoom, enterInRoomData);

            Debug.Log("Sended request \"EnterRoom\"");
        }
    }