/* 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); } }
/* The PartnerInfoRequested MessageHandler * It handles messages of PARTNER_INFO_REQUEST type. */ private static void PartnerInfoRequested(RMessage message, TcpClient connection) { Console.WriteLine("PartnerInfoRequested"); UserData partner = UserConnector.GetUserById((uint)message.Data); RMessage replyMessage = new RMessage(MessageType.PARTNER_INFO_REPLY, partner); ServerCore.GetWorkerByConnection(connection).SendMessage(replyMessage); }
/* The GetUserInfo MessageHandler * It handles messages of GET_USER_INFO_REQUEST type. */ private static void GetUserInfo(RMessage message, TcpClient connection) { UserData user = (UserData)message.Data; user = UserConnector.GetUserById(user.Id); List <Object> list = new List <Object>(); list.Add(user); list.Add(DomainConnector.GetAllDomains()); // all domains list.Add(DomainConnector.GetUserValidations(user.Id)); // domains for which the user has certificates RMessage replyMessage = new RMessage(MessageType.GET_USER_INFO_REPLY, list); ServerCore.GetWorkerByConnection(connection).SendMessage(replyMessage); }