Esempio n. 1
0
        private void action_change_room()
        {
            var oldroom = Room;

            _chatserver.RemoveRoomUser(_chatserver.RoomUsers[oldroom - 1], Nickname);
            Room = 0;
            while (Room == 0)
            {
                _chatserver.Write(_client.GetStream(),
                                  ChatProtocolValues.CHOOSE_ROOM(Nickname, _chatserver.NumRoom));
                var temp = _chatserver.Read(_client.GetStream());
                try
                {
                    var rN = int.Parse(temp);
                    if (rN >= 1 && rN <= _chatserver.NumRoom)
                    {
                        Room = rN;
                    }
                }
                catch
                {
                    // ignored
                }
            }
            _chatserver.AddRoomUser(_chatserver.RoomUsers[Room - 1], Nickname);
            _chatserver.Broadcast(ChatProtocolValues.MOVE_TO(Nickname, Room), oldroom);
            _chatserver.Broadcast(ChatProtocolValues.Welcome(Nickname, Room), Room);
        }
Esempio n. 2
0
        //CHANGE ROOM
        private void action_change_room()
        {
            //store old room number
            int oldroom = room;

            //Remove the user from the chat room
            chatserver.RemoveRoomUser(chatserver.RoomUsers[oldroom - 1], nickname);

            //Assigned to No room first
            room = 0;

            //while no room is assigned
            while (room == 0)
            {
                //Get room number from client
                chatserver.Write(client.GetStream(),
                                 ChatProtocolValues.CHOOSE_ROOM(nickname, chatserver.NumRoom));
                string temp = chatserver.Read(client.GetStream());

                //check for valid room number
                try
                {
                    //convert the text message to integer
                    int r_n = int.Parse(temp);
                    //check to make sure that the room number is within range
                    if ((r_n >= 1) && (r_n <= chatserver.NumRoom))
                    {
                        room = r_n;
                    }
                }
                catch {}
            }
            //Add user to the assigned room
            chatserver.AddRoomUser(chatserver.RoomUsers[room - 1], nickname);
            //Broadcast to old room participants
            chatserver.Broadcast(ChatProtocolValues.MOVE_TO(nickname, room), oldroom);
            //Broadcast to new room participants
            chatserver.Broadcast(ChatProtocolValues.WELCOME(nickname, room), room);
        }