Example #1
0
        /* The EditResource MessageHandler
         * It handles messages of EDIT_RESOURCE_REQUEST type.
         */
        private static void EditResource(RMessage message, TcpClient connection)
        {
            Console.WriteLine("EditResource");
            ResourceData res = (ResourceData)message.Data;

            ResourceConnector.EditResource(res);
            ResourceData        editedResource = ResourceConnector.GetResource(res.Id);
            RMessage            replyMessage   = new RMessage(MessageType.EDIT_RESOURCE_REPLY, editedResource);
            List <ClientWorker> clientList     = ServerCore.GetAllWorkers();

            foreach (ClientWorker client in clientList)
            {
                client.SendMessage(replyMessage);
            }
        }
Example #2
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);
            }
        }
Example #3
0
        /* The ResourceAccess MessageHandler
         * It handles messages of RANK_RESOURCE_ACCESSED_REQUEST type.
         */
        private static void ResourceAccess(RMessage message, TcpClient connection)
        {
            Console.WriteLine("AccessResource");
            ResourceData res = (ResourceData)message.Data;

            ResourceConnector.UpdateResourceRank(res, Ranking.RESOURCE_ACCESSED_VALUE);

            ResourceData editedResource = ResourceConnector.GetResource(res.Id);

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

            foreach (ClientWorker client in clientList)
            {
                client.SendMessage(replyMessage);
            }
        }
Example #4
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);
            }
        }