Example #1
0
        /// <summary>
        /// Helper method that sends two messages to the user: A complete friend list,
        /// and then a list of friends that are online.
        /// </summary>
        /// <param name="client"></param>
        public static void SendOnlineAndCompleteFriendList(Client client)
        {
            //
            // Send the user a list of all of their friends.
            //

            var db         = Database.GetInstance();
            var friendList = db.GetFriends(client.UserInfo.EmailAddress);

            if (null != friendList)
            {
                var friendListString = CreateFriendListFromUserList(friendList);

                MessageSender.SendMessage(
                    client,
                    PacketType.s_FriendList,
                    friendListString);


                //
                // Send the user a list of all of their friends who are online.
                //

                var onlineUsers = new List <user>();

                foreach (var frd in friendList)
                {
                    var clientManager = ClientManager.GetInstance();
                    var onlineClient  = clientManager.GetClientFromEmailAddress(frd.email);

                    if (null != onlineClient)
                    {
                        onlineUsers.Add(frd);
                    }
                }

                var onlineFriends = CreateFriendListFromUserList(onlineUsers);

                MessageSender.SendMessage(
                    client,
                    PacketType.s_OnlineFriendList,
                    onlineFriends);
            }
        }
Example #2
0
        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);
        }