Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
        /* The GetAllDomainsOrdered MessageHandler
         * It handles messages of GET_ALL_DOMAINS_ORDERED_REQUEST type.
         */
        private static void GetAllDomainsOrdered(RMessage message, TcpClient connection)
        {
            uint uid = ServerCore.GetIdByConnection(connection);
            List <DomainData> validations    = DomainConnector.GetUserValidations(uid);
            List <DomainData> nonValidations = DomainConnector.GetUserNonValidations(uid);

            validations.AddRange(nonValidations);
            RMessage replyMessage =
                new RMessage(
                    MessageType.GET_ALL_DOMAINS_ORDERED_REPLY,
                    validations);

            ServerCore.GetWorkerByConnection(connection).SendMessage(replyMessage);
        }
Exemplo n.º 3
0
        /* The GetFriendList MessageHandler
         * It handles messages of ADD_SAY_REQUEST type.
         */
        private static void AddSay(RMessage message, TcpClient connection)
        {
            Console.WriteLine("AddSay");
            SayData say = (SayData)(message.Data);
            uint    id  = say.Id;

            say.Id = ServerCore.GetIdByConnection(connection);
            if (ServerCore.GetWorkerById(id) != null)
            {
                RMessage replyMessage = new RMessage(MessageType.ADD_SAY_REPLY, say);
                ServerCore.GetWorkerById(id).SendMessage(replyMessage);
            }
            UserConnector.UpdateUserRank(say.Id, Ranking.ADD_SAY);
        }
Exemplo n.º 4
0
        /* The PostResource MessageHandler
         * It handles messages of ADD_RESOURCE_REQUEST type.
         */
        private static void PostResource(RMessage message, TcpClient connection)
        {
            Console.WriteLine("PostResource");
            ResourceConnector.AddResource((ResourceData)message.Data);
            // a lil' something for the user
            UserConnector.UpdateUserRank(ServerCore.GetIdByConnection(connection), Ranking.USER_POSTED_RESOURCE_VALUE);

            ResourceData        adddedResource = ResourceConnector.GetResource((ResourceData)message.Data);
            RMessage            replyMessage   = new RMessage(MessageType.ADD_RESOURCE_REPLY, adddedResource);
            List <ClientWorker> clientList     = ServerCore.GetAllWorkers();

            foreach (ClientWorker client in clientList)
            {
                client.SendMessage(replyMessage);
            }
        }
Exemplo n.º 5
0
        /*
         * On connection crash, makes the user offline
         */
        private static void MakeUserOffline(TcpClient connection)
        {
            uint            id           = ServerCore.GetIdByConnection(connection);
            UserData        user         = UserConnector.UpdateUserState(id, false);
            List <UserData> friendList   = UserConnector.GetFriendList(id);
            RMessage        replyMessage = new RMessage(MessageType.CHANGE_USER_STATE_REPLY, user);

            foreach (UserData friend in friendList)
            {
                ClientWorker worker = ServerCore.GetWorkerById(friend.Id);
                if (worker != null)
                {
                    ServerCore.GetWorkerById(friend.Id).SendMessage(replyMessage);
                }
            }
        }
Exemplo n.º 6
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);
            }
        }
Exemplo n.º 7
0
        /* The GetFriendList MessageHandler
         * It handles messages of CHANGE_USER_STATE_REQUEST type.
         */
        private static void ChangeUserState(RMessage message, TcpClient connection)
        {
            Console.WriteLine("ChangeUserState");
            uint            id           = ServerCore.GetIdByConnection(connection);
            UserData        user         = UserConnector.UpdateUserState(id, (bool)message.Data);
            List <UserData> friendList   = UserConnector.GetFriendList(id);
            RMessage        replyMessage = new RMessage(MessageType.CHANGE_USER_STATE_REPLY, user);

            foreach (UserData friend in friendList)
            {
                ClientWorker worker = ServerCore.GetWorkerById(friend.Id);
                if (worker != null)
                {
                    ServerCore.GetWorkerById(friend.Id).SendMessage(replyMessage);
                }
            }
            ServerCore.GetWorkerByConnection(connection).SendMessage(replyMessage);
        }
Exemplo n.º 8
0
        /* The ResourceVote MessageHandler
         * It handles messages of VOTE_RESOURCE_REQUEST type.
         */
        private static void ResourceVote(RMessage message, TcpClient connection)
        {
            Console.WriteLine("VoteResource");
            ResourceVoteData resVote = (ResourceVoteData)message.Data;

            ResourceVoteData oldResVote = ResourceVoteConnector.UpdateVote(resVote);

            ResourceConnector.VoteResource(oldResVote, resVote);
            UserConnector.UpdateUserRank(ServerCore.GetIdByConnection(connection), Ranking.USER_VOTED_RESOURCE_VALUE);

            ResourceData editedResource = ResourceConnector.GetResource(resVote.Id_Resource);

            RMessage            replyMessage = new RMessage(MessageType.EDIT_RESOURCE_REPLY, editedResource);
            List <ClientWorker> clientList   = ServerCore.GetAllWorkers();

            foreach (ClientWorker client in clientList)
            {
                client.SendMessage(replyMessage);
            }
        }
Exemplo n.º 9
0
        /* The LogConnector MessageHandler
         * It handles messages of RANK_USER_LOGGED_TIME_REQUEST type.
         */
        private static void LogConnector(RMessage message, TcpClient connection)
        {
            double value = Ranking.USER_UP_TIME_POINT_VALUE * (Double)message.Data;

            UserConnector.UpdateUserRank(ServerCore.GetIdByConnection(connection), value);
        }