コード例 #1
0
        /* The AddUserVote MessageHandler
         * It handles messages of ADD_USER_VOTE_REQUEST type.
         */
        private static void AddUserVote(RMessage message, TcpClient connection)
        {
            Console.WriteLine("AddUserVote");
            // Get the vote data from the message
            UserVoteData vote = (UserVoteData)message.Data;

            // Update the voter's rank
            UserVoteData rating = UserVoteConnector.CheckUserVote(vote);

            if (rating == null)
            {
                UserConnector.UpdateUserRank(vote.Id_voter_user, Ranking.VOTE_USER);
            }

            // Update the votee's rank
            UserConnector.VoteUser(vote);

            // Send the vote back to the client
            RMessage replyMessage = new RMessage(MessageType.ADD_USER_VOTE_REPLY, vote);

            ServerCore.GetWorkerByConnection(connection).SendMessage(replyMessage);

            // Send the updated user rank to all clients
            UserData user = UserConnector.GetUserById(vote.Id_votee_user);

            replyMessage = new RMessage(MessageType.RANK_USER_UPDATED, user);
            List <ClientWorker> allWorkers = ServerCore.GetAllWorkers();

            foreach (ClientWorker workersIterator in allWorkers)
            {
                workersIterator.SendMessage(replyMessage);
            }
        }
コード例 #2
0
        /* The CheckUserVote MessageHandler
         * It handles messages of CHECK_USER_VOTE_REQUEST type.
         */
        private static void CheckUserVote(RMessage message, TcpClient connection)
        {
            Console.WriteLine("CheckUserVote");
            UserVoteData userVote = (UserVoteData)message.Data;
            UserVoteData rating   = UserVoteConnector.CheckUserVote(userVote);
            RMessage     replyMessage;

            replyMessage = new RMessage(MessageType.CHECK_USER_VOTE_REPLY, rating);
            ServerCore.GetWorkerByConnection(connection).SendMessage(replyMessage);
        }