Пример #1
0
        /// <summary>
        /// Handle inbound VersionResponseMessage.
        /// </summary>
        /// <param name="responseMessage"></param>
        public void ReceiveResponse(VersionResponseMessage responseMessage)
        {
            Trace.WriteLine("VersionResponseMessage received from " + m_RemoteParticipant.Guid.ToString());
            m_RemoteVersion = responseMessage.ResponderVersion;

            if (m_RemoteVersion > VersionExchangeModel.LocalVersion)
            {
                m_RemoteCompatibility = responseMessage.Compatibility;
                m_RecommendedAction   = responseMessage.Action;
                m_WarningMessage      = responseMessage.WarningMessage;
                if (!this.m_LocalNodeIsInstructor)
                {
                    if ((m_RecommendedAction == VersionIncompatibilityRecommendedAction.IssueWarning) &&
                        (m_WarningMessage != null) && (m_WarningMessage != ""))
                    {
                        //Cause a local pop-up warning to be displayed.
                        PresenterModel.TheInstance.VersionExchange.SetPopUpWarning(m_WarningMessage);
                    }
                }
                else
                {
                    //Here we might want to show warning, but aggregate across all participants and show one messagebox.
                }
            }
            else if (m_RemoteVersion < VersionExchangeModel.LocalVersion)
            {
                //This node is newer than the remote node, so use the local compatibility matrix
                // to generate compatibility information.
                VersionResponseMessage vrm = CompatiblityMatrix.GetVersionResponseMessage(m_RemoteVersion);
                m_RemoteCompatibility = vrm.Compatibility;
                m_RecommendedAction   = vrm.Action;
                m_WarningMessage      = vrm.LocalWarningMessage;

                //If the local node is an instructor and if the local node has a later version, we send one more
                // response back to the client since our verison of the compatibility matrix may have information
                // that the client's matrix doesn't have.
                if (this.m_LocalNodeIsInstructor)
                {
                    using (Synchronizer.Lock(this.SyncRoot)) {
                        this.SetPublishedProperty("SendVersionResponse", ref this.m_SendVersionResponse, vrm);
                    }
                }

                //Are there any cases where we want to raise events?  If so, the code can be added later as needed.
            }
            else
            {
                //Versions are equal.  We fully expect compatiblity in this case.
                m_RemoteCompatibility = responseMessage.Compatibility;
                m_RecommendedAction   = responseMessage.Action;
                m_WarningMessage      = responseMessage.WarningMessage;
            }
        }
Пример #2
0
        /// <summary>
        /// Handle inbound VersionRequestMessage from this participant.  Always respond.
        /// </summary>
        /// <param name="version"></param>
        internal void ReceiveRequest(Version version)
        {
            m_RemoteVersion = version;
            VersionResponseMessage vrm = CompatiblityMatrix.GetVersionResponseMessage(m_RemoteVersion);

            //If local is newer or equal, populate compatibility information from the local matrix
            if (m_RemoteVersion <= VersionExchangeModel.LocalVersion)
            {
                m_RemoteCompatibility = vrm.Compatibility;
                m_RecommendedAction   = vrm.Action;
                m_WarningMessage      = vrm.LocalWarningMessage;
            }

            //Set the property to cause the Network Service to send the response.
            using (Synchronizer.Lock(this.SyncRoot)) {
                this.SetPublishedProperty("SendVersionResponse", ref this.m_SendVersionResponse, vrm);
            }
        }
Пример #3
0
        /// <summary>
        /// Generate the outbound VersionResponseMessage
        /// </summary>
        /// <param name="localVersion"></param>
        /// <param name="remoteVersion"></param>
        /// <returns></returns>
        public static VersionResponseMessage GetVersionResponseMessage(Version remoteVersion)
        {
            VersionResponseMessage vrm = new VersionResponseMessage();

            ///If the remote version is newer, we always send the default message which claims full compatibility.
            ///If this is not the case, the remote node's compatibility matrix will be used to override the properties.
            ///If the remote node's version is older, the information we provide here will be meaningful.

            if (remoteVersion < VersionExchangeModel.LocalVersion)
            {
                /// Note: When new CP3 versions are created, add code here to populate the
                /// VersionResponseMessage properties with compatibility warnings and actions as appropriate.
                /// Note that the pop-up and dialog always show the compatibility info URL, so do not include it
                /// in the warning message.

                ///This is only displayed in the Version Compatibility Info dialog:
                //vrm.Compatibility = VersionCompatibility.Partial;

                ///IssueWarning means that a pop-up appears on student or public nodes with earlier version when connection is made.
                //vrm.Action = VersionIncompatibilityRecommendedAction.IssueWarning;

                ///The WarningMessage is displayed on the remote node with earlier version.  It appears in the pop-up if
                /// the remote node is public or student, and it appears in the Compatiblity Info dialog available from the
                /// menu for all roles.
                //vrm.WarningMessage = "The local Classroom Presenter version has known compatibility problems affecting feature X when connected to this remote node. Upgrade of the local Classroom Presenter is recommended.";

                ///The LocalWarningMessage is not part of the serialized message. It is only displayed locally in the
                /// Compatibility Info dialog on the node with the later version.
                //vrm.LocalWarningMessage = "The remote node has known problems with feature X. Upgrade of the remote node is recommended.";

                #region QuickPoll
                Version qpVersion = new Version(3, 0, 1654);
                if (remoteVersion < qpVersion)
                {
                    vrm.Compatibility       = VersionCompatibility.Partial;
                    vrm.Action              = VersionIncompatibilityRecommendedAction.NoAction;
                    vrm.WarningMessage      = Strings.QuickPollVersionWarning;
                    vrm.LocalWarningMessage = Strings.QuickPollLocalVersionWarning;
                }
                #endregion QuickPoll
            }

            return(vrm);
        }
Пример #4
0
        /// <summary>
        /// Called when a VersionResponseMessage is received
        /// </summary>
        /// <param name="participantModel"></param>
        /// <param name="versionResponseMessage"></param>
        internal void ReceiveVersionResponse(ParticipantModel remoteParticipant, VersionResponseMessage versionResponseMessage)
        {
            Trace.WriteLine("VersionExchangeModel.ReceiveVersionResponse started. remoteParticipant=" +
                            remoteParticipant.Guid.ToString() + ";responderID=" + versionResponseMessage.ResponderId.ToString());

            VersionExchange ve = null;

            //Look up the VersionExchange for this remote participant
            using (Synchronizer.Lock(this.SyncRoot)) {
                if (m_VersionExchangeDictionary.ContainsKey(versionResponseMessage.ResponderId))
                {
                    ve = m_VersionExchangeDictionary[versionResponseMessage.ResponderId];
                }
            }
            //Let the VersionExchange handle the inbound message.
            if (ve != null)
            {
                ve.ReceiveResponse(versionResponseMessage);
            }
            else
            {
                Trace.WriteLine("Warning: Failed to find a pending version exchange to match inbound response message from participant: " + remoteParticipant.Guid.ToString());
            }
        }
        public bool Check()
        {
            #region vérification de la longeur de la chaine
            if (CommandStrings.Length != 5)
            {
                return(false);
            }
            #endregion
            #region vérifier si le joueur est déjà connecté, pour cela on vérifie si il nous as déjà fournie son nom d'utilisateur et si une map lui a été attribué
            if (_actor.Username != "" || _actor.map != "")
            {
                //Security.User_banne("identification", im);
                // il faut informer le joueur que ceci ne peux pas arriver et qu'il dois soumettre un bugReporte
                return(false);
            }
            #endregion
            #region verification de la version
            // ReSharper disable once PossibleNullReferenceException
            var verServer = (DataBase.DataTables.version as List <mysql.version>).Find(f => f.app == "app")._version.Split('.');

            // la requette retourne 1 seul enregistrement qui correspond a l'application
            // si un loader.exe est prévus, cette requette va retourner 2 enregistrement,app puis loader
            // il faut ajouter un while si c'est le ca
            var verClient = _clientVersion.Split('.');

            // une version dois imperativement se composer de 2 indentifiants, numéro version majeur, puis révision
            if (verClient.Length < 2)
            {
                return(false);       // il faut informer le client que sa version est érronnée
            }
            try
            {
                int.Parse(verClient[0]);
                int.Parse(verClient[1]);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex + " \n\t" + _username + " client tente de passer une version non numerique");
                return(false);
            }
            /////////// comparaison du 1er index
            if (Convert.ToInt32(verServer[0]) != Convert.ToInt32(verClient[0]))
            {
                ///// version majeur inferieur, a proposer la MAJ
                VersionResponseMessage versionResponseMessage = new VersionResponseMessage();
                versionResponseMessage.Initialize(new[] { Enums.Version.version.MAJOR_LESS.ToString() }, Nc);
                versionResponseMessage.Send();
                return(false);
            }
            ////// client a la derniere version majeur
            //  verification de la version secondaire
            if (Convert.ToInt32(verServer[1]) != Convert.ToInt32(verClient[1]))
            {
                /////// version secondaire inferieur,a proposer la MAJ
                VersionResponseMessage versionResponseMessage = new VersionResponseMessage();
                versionResponseMessage.Initialize(new[] { Enums.Version.version.REVISION_LESS.ToString() }, Nc);
                versionResponseMessage.Send();
                return(false);
            }

            #endregion
            #region Verification du nom d'utilisateur contre les injections}
            ///////////////////////////////////////////////
            if (!Security.check_valid_user(_username) || !Security.check_valid_pwd(_password))
            {
                // si arrivé ici c'est que le client a modifié son application pour contourner la methode de securité
                AuthentificationUserNotAllowedResponseMessage authentificationUserNotAllowedResponseMessage = new AuthentificationUserNotAllowedResponseMessage();
                authentificationUserNotAllowedResponseMessage.Initialize(CommandStrings, Nc);
                authentificationUserNotAllowedResponseMessage.Serialize();
                authentificationUserNotAllowedResponseMessage.Send();
                return(false);
            }
            #endregion
            #region comparaison des identifiants avec la bdd
            int resultQuery = ((List <mysql.users>)DataBase.DataTables.users).FindAll(f => f.username == _username && f.password == _password.ToLower()).Count;

            switch (resultQuery)
            {
            case 0:
                // check flooding access try
                int curTimestamp    = CommonCode.ReturnTimeStamp();
                int resultUserLogin = ((List <mysql.logcounter>)DataBase.DataTables.logcounter).FindAll(f => f.timestamp >= (curTimestamp - (60 * 30))).Count;

                if (resultUserLogin >= 10)
                {
                    // supression des anciens enregistrement qui dates de plus de 30min
                    ((List <mysql.logcounter>)DataBase.DataTables.logcounter).RemoveAll(f => f.user == _username);

                    // ban de l'ip
                    mysql.bannedip bannedIp = new mysql.bannedip
                    {
                        ip      = Nc.RemoteEndPoint.Address.ToString(),
                        reson   = "too many wrong login tries",
                        censure = curTimestamp + (60 * 30)
                    };

                    ((List <mysql.bannedip>)DataBase.DataTables.bannedip).Add(bannedIp);
                    Nc.Disconnect(Enums.DisconnectReason.disconnectReason.IP_BANNED.ToString());
                    return(false);
                }
                mysql.logcounter logCounter = new mysql.logcounter
                {
                    user      = _username,
                    timestamp = curTimestamp
                };

                ((List <mysql.logcounter>)DataBase.DataTables.logcounter).Add(logCounter);

                // on supprime tous les instances dons le timestamp est supérieur à 30 min
                ((List <mysql.logcounter>)DataBase.DataTables.logcounter).RemoveAll(f => f.timestamp < curTimestamp - (60 * 30));

                // utilisateur ou mot de passe incorrecte
                // il faut que le message passé en référence sois une Enum.disconnect
                Nc.Disconnect(Enums.DisconnectReason.disconnectReason.WRONG_CREDENTIALS.ToString());
                return(false);

            case 1:
                // identification confirmé
                /////////  verification si l'utilisateur est bannée
                int banned = ((List <mysql.banneduser>)DataBase.DataTables.banneduser).FindAll(f => f.user == _username).Count;

                if (banned == 0)
                {
                    /////// l'utilisateur n'est pas banni
                    // verification si l'utilisateur a confirmé sa boite email

                    if (((List <mysql.users>)DataBase.DataTables.users).Exists(f => f.username == _username && f.confirmation_email == 0))
                    {
                        // il faut envoyer au client la bonne commande, il faut aussi deconnecter le client, parce la on lui envoie juste l'information mais il reste connecté, peux etre que le client se deconnecte depuis le client mais c'est unsafe
                        AuthentificationEmailNotValidatedResponseMessage authentificationEmailValidationResponseMessage = new AuthentificationEmailNotValidatedResponseMessage();
                        authentificationEmailValidationResponseMessage.Initialize(CommandStrings, Nc);
                        authentificationEmailValidationResponseMessage.Serialize();
                        authentificationEmailValidationResponseMessage.Send();
                        return(false);
                    }
                    return(true);
                }
                /////// l'utilisateur est banni, il faut que le message passé en référence sois une Enum.Disconnect
                Nc.Disconnect(Enums.DisconnectReason.disconnectReason.USER_BANNED.ToString());
                return(false);
            }
            return(true);

            #endregion
        }