コード例 #1
0
ファイル: RoomManager.cs プロジェクト: jonathanyeung/ozwego
        public void RemoveMemberfromRoom(Client roomHost, Client memberToRemove)
        {
            Room room;

            lock (_roomListLock)
            {
                room = _roomList.FirstOrDefault(myRoom => myRoom.Host == roomHost);
            }

            if (room == null)
            {
                return;
            }

            room.Members.Remove(memberToRemove);

            if (roomHost == memberToRemove)
            {
                room.ChangeToRandomNewHost();
            }

            if (0 == room.Members.Count)
            {
                lock (_roomListLock)
                {
                    _roomList.Remove(room);
                }
            }
            else
            {
                MessageSender.BroadcastMessage(
                    room.Members,
                    PacketType.s_UserLeftRoom,
                    memberToRemove.UserInfo,
                    memberToRemove);
            }
        }
コード例 #2
0
ファイル: RoomManager.cs プロジェクト: jonathanyeung/ozwego
        public void AddMemberToRoom(Client roomHost, ref Client memberToAdd)
        {
            Room room;

            lock (_roomListLock)
            {
                room = _roomList.FirstOrDefault(myRoom => myRoom.Host == roomHost);
            }

            if (room == null)
            {
                return;
            }


            //
            // First, remove the member from his previous room.
            //

            RemoveMemberfromRoom(memberToAdd.Room.Host, memberToAdd);


            //
            // Now add the member to the new room.
            //

            room.Members.Add(memberToAdd);
            memberToAdd.Room = room;


            //
            // Send a message to all the existing members in the room indicating who has joined.
            //

            MessageSender.BroadcastMessage(
                room.Members,
                PacketType.s_UserJoinedRoom,
                memberToAdd.UserInfo,
                memberToAdd);


            //
            // Now send a message to the person who has joined containing the list of room
            // members.
            //

            var friendList = new FriendList();

            foreach (var c in room.Members)
            {
                friendList.Friends.Add(c.UserInfo);
            }

            MessageSender.SendMessage(
                memberToAdd,
                PacketType.s_RoomList,
                friendList);


            //
            // Now tell the joining person who the room host is.
            //

            MessageSender.SendMessage(
                memberToAdd,
                PacketType.s_HostTransfer,
                room.Host.UserInfo);
        }