示例#1
0
        /* The GetFriendList MessageHandler
         * It handles messages of UPDATE_FRIENDSHIP_REQ type.
         */
        private static void UpdateFriendship(RMessage message, TcpClient connection)
        {
            Console.WriteLine("UpdateFriendship");
            FriendshipData friendship = (FriendshipData)message.Data;
            RMessage       replyMessageFormer, replyMessageLatter;

            if (friendship.Status)
            {
                FriendshipConnector.ConfirmFriendship(friendship);
                replyMessageFormer = new RMessage(MessageType.CONFIRM_FRIENDSHIP_REPLY, friendship.Latter);
                replyMessageLatter = new RMessage(MessageType.CONFIRM_FRIENDSHIP_REPLY, friendship.Former);
                UserConnector.UpdateUserRank(friendship.Latter, Ranking.ADD_FRIEND);
                UserConnector.UpdateUserRank(friendship.Former, Ranking.ADD_FRIEND);
            }
            else
            {
                FriendshipConnector.DeleteFriendship(friendship);
                replyMessageFormer = new RMessage(MessageType.DENY_FRIENDSHIP_REPLY, friendship.Latter);
                replyMessageLatter = new RMessage(MessageType.DENY_FRIENDSHIP_REPLY, friendship.Former);
            }
            ClientWorker formerWorker = ServerCore.GetWorkerById(friendship.Former);

            if (formerWorker != null)
            {
                formerWorker.SendMessage(replyMessageFormer);
            }
            ClientWorker latterWorker = ServerCore.GetWorkerById(friendship.Latter);

            if (latterWorker != null)
            {
                latterWorker.SendMessage(replyMessageLatter);
            }
        }
示例#2
0
        /* The GetFriendList MessageHandler
         * It handles messages of GET_ALL_FRIENDSHIPS_REQUEST type.
         */
        private static void GetAllFriendships(RMessage message, TcpClient connection)
        {
            Console.WriteLine("GetAllFriendships");
            List <FriendshipData> friendlist = FriendshipConnector.GetFriendshipList(ServerCore.GetIdByConnection(connection));
            RMessage replyMessage            = new RMessage(MessageType.GET_ALL_FRIENDSHIPS_REPLY, friendlist);

            ServerCore.GetWorkerByConnection(connection).SendMessage(replyMessage);
        }
示例#3
0
        /* The GetFriendList MessageHandler
         * It handles messages of ADD_FRIEND_REQ type.
         */
        private static void AddFriend(RMessage message, TcpClient connection)
        {
            Console.WriteLine("AddFriend");
            uint     thisUserId = ServerCore.GetIdByConnection(connection);
            UserData friend     = UserConnector.GetUser((String)message.Data);
            UserData thisUser   = UserConnector.GetUser(thisUserId);

            if (friend == null)
            {
                return;
            }
            if (friend.Id == thisUserId)
            {
                return;
            }
            List <FriendshipData> friendships = FriendshipConnector.GetFriendshipList(thisUserId);

            foreach (FriendshipData friendshipIt in friendships)
            {
                if (friendshipIt.Former == friend.Id || friendshipIt.Latter == friend.Id)
                {
                    return;
                }
            }
            FriendshipData friendship = new FriendshipData(thisUserId, friend.Id, false);

            FriendshipConnector.AddFriendship(friendship);

            ClientWorker formerWorker = ServerCore.GetWorkerById(friendship.Former);
            ClientWorker latterWorker = ServerCore.GetWorkerById(friendship.Latter);

            RMessage replyMessageFormer = new RMessage(MessageType.ADD_FRIEND_REPLY, friend);
            RMessage replyMessageLatter = new RMessage(MessageType.ADD_FRIEND_REPLY, thisUser);
            RMessage replyMessage       = new RMessage(MessageType.ADD_FRIENDSHIP_REPLY, friendship);

            if (formerWorker != null)
            {
                formerWorker.SendMessage(replyMessageFormer);
                formerWorker.SendMessage(replyMessage);
            }
            if (latterWorker != null)
            {
                latterWorker.SendMessage(replyMessageLatter);
                latterWorker.SendMessage(replyMessage);
            }
        }