Beispiel #1
0
        public static bool JoinRoom(Socket s, int roomNum)
        {
            byte[] joinRoomRequest
                = PacketMaker.CreatePacket(PacketMaker.CommandCode.JOIN_ROOM, Convert.ToUInt16(roomNum), Connection.StringToByte("0"));

            Connection.ClientToServer(s, joinRoomRequest);
            ChatProtocol joinResult = Connection.ServerToClient(s);

            if (joinResult.command == PacketMaker.CommandCode.JOIN_ROOM_RESULT)
            {
                if (BitConverter.ToInt32(joinResult.variableLengthField, 0) == 1)
                {
                    Console.WriteLine("Join to Room # : " + roomNum);
                    Chat.StartChat(roomNum);
                    return(true);
                }
                else if (BitConverter.ToInt32(joinResult.variableLengthField, 0) == -1)
                {
                    Console.WriteLine("Join Room Failed");
                    return(false);
                }
            }
            else
            {
                Console.WriteLine("Invalid Message from Server");
                return(false);
            }
            return(false);
        }