Пример #1
0
        public void Process(Context context)
        {
            var user = context.Server.Database.QueryUser(Username);
            if (user != null)
            {
                if (user.Password != Password)
                {
                    context.SendAndProcessMessage(new LoginFailure());
                    return;
                }
            }
            else
            {
                user = context.Server.Database.InsertUser(Username, Password, context.Salt);
            }

            // Remove any older sessions from this user (duplicate logins)
            var otherSession = context.Server.GetSession(user);
            if (otherSession != null)
            {
                context.Server.RemoveSession(otherSession);
                otherSession.TcpClient.Close();
            }

            context.User = user;

            var success = new LoginSuccess();
            context.SendAndProcessMessage(success);
        }
Пример #2
0
        public void Process(Context context)
        {
            var friend = context.Server.Database.QueryUser(FriendUsername);

            context.Server.Database.InsertMutualFriend(context.User, friend);

            context.SendAndProcessMessage(new FriendsList(context.User));
            context.SendAndProcessMessage(new FriendsSessionAssign(context.User));

            // It's possible to accept a friend request where the inviter is not online
            var friendSession = context.Server.GetSession(friend);
            if (friendSession != null)
            {
                friendSession.SendAndProcessMessage(new FriendsList(friend));
                friendSession.SendAndProcessMessage(new FriendsSessionAssign(friend));
            }

            var pendingRequests = context.Server.Database.QueryPendingFriendRequests(context.User);
            var pq = pendingRequests.FirstOrDefault(a => a.FriendUserId == context.User.UserId);
            if (pq != null)
            {
                context.Server.Database.DeletePendingFriendRequest(pq.PendingFriendRequestId);
            }
        }
Пример #3
0
        public void Process(Context context)
        {
            var clientPrefs = new Unknown10();
            context.SendAndProcessMessage(clientPrefs);

            var groups = new Groups();
            context.SendAndProcessMessage(groups);

            var groupsFriends = new GroupsFriends();
            context.SendAndProcessMessage(groupsFriends);

            var serverList = new ServerList();
            context.SendAndProcessMessage(serverList);

            var chatRooms = new ChatRooms();
            context.SendAndProcessMessage(chatRooms);

            var friendsList = new FriendsList(context.User);
            context.SendAndProcessMessage(friendsList);

            var friendsStatus = new FriendsSessionAssign(context.User);
            context.SendAndProcessMessage(friendsStatus);

            // Tell friends this user came online
            //if (context.User.Username == "test") Debugger.Break();
            var friends = context.Server.Database.QueryFriends(context.User);
            friends.ForEach(friend =>
            {
                var otherSession = context.Server.GetSession(friend);
                if (otherSession != null)
                {
                    otherSession.SendAndProcessMessage(new FriendsSessionAssign(friend));
                }
            });

            var pendingFriendRequests = context.Server.Database.QueryPendingFriendRequests(context.User);
            pendingFriendRequests.ForEach(request =>
            {
                var requester = context.Server.Database.QueryUser(request.UserId);
                context.SendAndProcessMessage(new FriendInvite(requester.Username, requester.Nickname, request.Message));
            });
        }
Пример #4
0
        void OnDisconnection(Context sessionContext)
        {
            RemoveSession(sessionContext);

            var friends = Database.QueryFriends(sessionContext.User);
            friends.ForEach(friend =>
            {
                var friendSession = GetSession(friend);
                if (friendSession != null)
                {
                    // Not working
                    sessionContext.SendAndProcessMessage(new FriendsSessionAssign(friend));
                }
            });
        }
Пример #5
0
 public void Process(Context context)
 {
     var result = new UserLookupResult(Username);
     context.SendAndProcessMessage(result);
 }
Пример #6
0
 public void Process(Context context)
 {
     context.SendAndProcessMessage(new Did());
 }