Esempio n. 1
0
        /* The SignIn MessageHandler
         * It handles messages of SIGN_IN_REQUEST type.
         */
        private static void SignIn(RMessage message, TcpClient connection)
        {
            RMessage replyMessage;

            UserData user1 = (UserData)message.Data;
            UserData user2 = UserConnector.GetUser(user1.Username);

            // Check if the password match
            if (user2 != null && user2.Password != user1.Password)
            {
                user2 = null;
            }

            // If the credentials do not match, refuse the authentification
            if (user2 == null)
            {
                ServerCore.GetWorkerByConnection(connection).SendMessage(
                    new RMessage(MessageType.SIGN_IN_REPLY, null));
                return;
            }

            // If the user can authenticate, disconnect another user connected
            // with the same username
            if (user2 != null)
            {
                TcpClient previousConnection = ServerCore.GetConnectionById(user2.Id);
                if (previousConnection != null)
                {
                    ServerCore.RemoveIdConnectionMapping(user2.Id, previousConnection);
                    replyMessage =
                        new RMessage(
                            MessageType.SIGN_OUT_REPLY,
                            user2);
                    ServerCore.GetWorkerByConnection(previousConnection)
                    .SendMessage(replyMessage);
                }
            }

            List <Object> payload = new List <Object>();

            payload.Add(user2);                                        // user data
            payload.Add(DomainConnector.GetAllDomains());              // all domains
            payload.Add(DomainConnector.GetUserValidations(user2.Id)); // domains for which the user has certificates
            replyMessage =
                new RMessage(
                    MessageType.SIGN_IN_REPLY,
                    payload);
            ServerCore.GetWorkerByConnection(connection).SendMessage(replyMessage);

            // If the user connected successfully, store the connection mapping
            if (user2 != null)
            {
                ServerCore.AddIdConnectionMapping(user2.Id, connection);
            }
        }
Esempio n. 2
0
        /* The CheckUserDomainValidation MessageHandler
         * It handles messages of GET_USER_CERTIFIED_DOMAINS_REQUEST type.
         */
        private static void CheckUserDomainValidation(RMessage message, TcpClient connection)
        {
            Console.WriteLine("GetUserDomainValidation");
            List <Object> resultContent = new List <Object>();

            resultContent.Add((Object)((UserData)message.Data));
            resultContent.Add((Object)DomainConnector.GetUserValidations(((UserData)message.Data).Id));
            RMessage replyMessage = new RMessage(MessageType.GET_USER_CERTIFIED_DOMAINS_REPLY, resultContent);

            ServerCore.GetWorkerByConnection(connection).SendMessage(replyMessage);
        }
Esempio n. 3
0
        /* 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);
        }
Esempio n. 4
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);
        }