Пример #1
0
        //ToDo: Move this class elsewhere.
        public static Friend GetFriendFromUser(user user)
        {
            var friend = new Friend { Alias = user.alias, EmailAddress = user.email };

            if (user.creation_time != null)
            {
                friend.CreationTime = (DateTime)user.creation_time;
            }

            if (user.skill_level != null)
            {
                friend.Level = (int)user.skill_level;
            }

            if (user.ranking != null)
            {
                friend.Ranking = (int)user.ranking;
            }

            if (user.experience != null)
            {
                friend.Experience = (long)user.experience;
            }

            return friend;
        }
Пример #2
0
        public async void RejectFriendRequest(Friend friend)
        {
            PendingFriendRequests.Remove(friend);

            //ToDo: This null check is no bueno.  This needs to get sent at some point, 
            // this call will make the packet never get sent to the server.
            var serverProxy = ServerProxy.GetInstance();
            if (null != serverProxy.messageSender)
            {
                await serverProxy.messageSender.SendMessage(
                        PacketType.c_RejectFriendRequest,
                        friend);
            }
        }
Пример #3
0
        /// <summary>
        /// This method is called when a server notification is received saying that someone has
        /// joined your current room.
        /// </summary>
        public async void AddMemberToRoom(Friend newMember)
        {
            //
            // First check to make sure that the buddy doesn't already exist in the room.  If
            // not, then add the buddy.
            //
                await App.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    var budref = RoomMembers.FirstOrDefault(
                        b => b.EmailAddress == newMember.EmailAddress);

                    if (budref == null)
                    {
                        RoomMembers.Add(newMember);
                    }
                });
        }
Пример #4
0
        /// <summary>
        /// This method is called when a server notification is received saying that someone has
        /// left your current room.
        /// </summary>
        /// <param name="buddyAccountAddress">buddy that is leaving the room</param>
        public async void RemoveMemberFromRoom(Friend leavingMember)
        {
            var roomManager = RoomManager.GetInstance();

            Friend budref = roomManager.RoomMembers.FirstOrDefault(
                b => b.EmailAddress == leavingMember.EmailAddress);

            await App.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                //
                // Don't remove yourself from the room.
                //

                if ((budref != null) &&
                    (leavingMember.EmailAddress != Settings.EmailAddress))
                {
                    roomManager.RoomMembers.Remove(budref);
                }
            });
        }
Пример #5
0
 public async void JoinRoom(Friend buddyToJoin)
 {
     var serverProxy = ServerProxy.GetInstance();
     await serverProxy.messageSender.SendMessage(
             PacketType.c_JoinRoom,
             buddyToJoin);
 }
Пример #6
0
        public async void ChangeRoomHost(Friend newHost)
        {
            Host = newHost;

            var mainPageViewModel = MainPageViewModel.GetInstance();

            await App.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                mainPageViewModel.RoomHost = newHost.Alias;
            });
            
            if (newHost.EmailAddress != Settings.EmailAddress)
            {
                //ToDO: Disable Start Game with Room Button.
            }
        }
Пример #7
0
        private void ProcessLogInPacket(Client client, Friend friend)
        {
            //
            // Sign out anyone who is using the same user name.
            //

            var clientManager = ClientManager.GetInstance();
            var duplicateClient = clientManager.GetClientList()
                .FirstOrDefault(c => c.UserInfo.EmailAddress == friend.EmailAddress);

            if (duplicateClient != null)
            {
                duplicateClient.Disconnect();
            }

            client.UserInfo = friend;

            clientManager.AddClient(client);

            //
            // Look for the user in the database.  If the user does not exist, add
            // 'em to the DB
            //

            var db = Database.GetInstance();
            var user = db.GetUserByEmail(client.UserInfo.EmailAddress);

            if (user == null)
            {
                db.AddNewUser(client.UserInfo.EmailAddress, client.UserInfo.Alias);
            }

            user = db.GetUserByEmail(client.UserInfo.EmailAddress);

            var userAsFriend = MessageReceiver.GetFriendFromUser(user);

            //
            // Send the user a copy of his/her stats.
            //

            MessageSender.SendMessage(
                client,
                PacketType.s_UserStats,
                userAsFriend);

            //
            // Send both the online list and the complete list of friends to the user.
            //

            MessageReceiver.SendOnlineAndCompleteFriendList(client);

            //
            // Send pending friend requests to user.
            //

            var pendingRequests = db.GetPendingFriendRequests(client.UserInfo.EmailAddress);

            if (null != pendingRequests)
            {
                var pendingFriendRequests = MessageReceiver.CreateFriendListFromUserList(pendingRequests);

                MessageSender.SendMessage(
                        client,
                        PacketType.s_FriendRequests,
                        pendingFriendRequests);
            }
        }
Пример #8
0
        private Client ProcessJoinRoomPacket(Client client, Friend joiner)
        {
            var clientManager = ClientManager.GetInstance();
            var clientToJoin = clientManager.GetClientList().FirstOrDefault(
                myClient => myClient.UserInfo.EmailAddress == joiner.EmailAddress);

            if (clientToJoin != null)
            {
                var roomManager = RoomManager.GetInstance();
                roomManager.AddMemberToRoom(clientToJoin.Room.Host, ref client);
            }

            return client;
        }
Пример #9
0
 /// <summary>
 /// Used when a friend request is accepted while the user is still online.
 /// </summary>
 /// <param name="buddy"></param>
 public void AddNewBuddy(Friend buddy)
 {
     CompleteFriendList.Add(buddy);
     OnBuddySignIn(buddy);
 }
Пример #10
0
        /// <summary>
        /// Friend signed out, move him from the online list to the offline list.
        /// </summary>
        /// <param name="buddy"></param>
        public void OnBuddySignOut(Friend buddy)
        {
            if (buddy == null)
            {
                return;
            }

            var buddyToRemove = OnlineFriendList.FirstOrDefault((Friend b) => b.EmailAddress == buddy.EmailAddress);

            if (null != buddyToRemove)
            {
                OnlineFriendList.Remove(buddyToRemove);
            }

            if (OfflineFriendList.FirstOrDefault((Friend b) => b.EmailAddress == buddy.EmailAddress) == null)
            {
                OfflineFriendList.Add(buddy);
            }
        }
Пример #11
0
 public void NewFriendRequest(Friend friend)
 {
     PendingFriendRequests.Add(friend);
 }