Пример #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);
        }
Пример #2
0
        public static void LogIn(Socket s)
        {
            string id        = String.Empty;
            string pw        = String.Empty;
            int    idMaxSize = 12;

            //Get correct login info
            do
            {
                Console.Write("Enter your ID : ");
                id = Console.ReadLine();
            }while (!IsValidID(id, idMaxSize));

            do
            {
                Console.Write("Enter your PW : ");
                pw = Console.ReadLine();
            }while (!IsValidPW(pw, idMaxSize));

            //Send login info to server
            string loginInfo = id + "#" + pw;

            byte[] loginData = PacketMaker.CreatePacket(PacketMaker.CommandCode.LOGIN, Convert.ToUInt16(loginInfo.Length), Connection.StringToByte(loginInfo));

            Connection.ClientToServer(s, loginData);
        }
Пример #3
0
        public static int CreateRoom(Socket s)
        {
            int    roomNumber        = -1;
            int    maxRoomNameLength = 20;
            string roomName;

            do
            {
                Console.WriteLine("Enter Room Name");
                roomName = Console.ReadLine();

                if (roomName.Length > maxRoomNameLength)
                {
                    Console.WriteLine("방 이름이 너무 길어양");
                }
            } while (roomName.Length > maxRoomNameLength);

            ushort roomNameLength = Convert.ToUInt16(roomName.Length);

            byte[] newRoomRequest = PacketMaker.CreatePacket(PacketMaker.CommandCode.CREATE_ROOM, roomNameLength, Connection.StringToByte(roomName));
            Connection.ClientToServer(s, newRoomRequest);

            Console.WriteLine(Chat.KeyInputController.wasStopChatted);
            ChatProtocol newRoom = Connection.ServerToClient(s);

            if (newRoom.command == PacketMaker.CommandCode.CREATE_ROOM_RESULT)
            {
                roomNumber = BitConverter.ToInt32(newRoom.variableLengthField, 0);
            }
            else
            {
                Console.WriteLine("command error");
            }

            return(roomNumber);
        }
Пример #4
0
 public static void LogOut(Socket s)
 {
     byte[] logoutData = PacketMaker.CreatePacket(PacketMaker.CommandCode.LOGOUT, 0, Connection.StringToByte("0"));
     Connection.ClientToServer(s, logoutData);
 }