Beispiel #1
0
        public override Packet OnPacketReceive(Packet receivedPacket)
        {
            ClientPacketUpdatePet clientPacketUpdatePet = receivedPacket as ClientPacketUpdatePet;

            ConsoleHelper.Write("Receive - ClientPacketUpdatePet");

            PLFPet pet = clientPacketUpdatePet.PetProfile;

            //insert new profile into DB
            MySqlCommand updatePetCommand = new MySqlCommand();

            updatePetCommand.Connection  = Program.mySQLManager.MySQLConnection.MysqlConnection;
            updatePetCommand.CommandText =
                $"UPDATE `T_Pet` SET `petType`='{(int)pet.PetType}',`petName`='{pet.PetName.ToSQL()}' WHERE `petID`='{pet.PetID}'";

            ServerPacketConfirmation serverPacketConfirmation;

            try
            {
                updatePetCommand.ExecuteNonQuery();

                serverPacketConfirmation = new ServerPacketConfirmation(true, NetworkError.NONE);
            }
            catch (Exception e)
            {
                serverPacketConfirmation = new ServerPacketConfirmation(false, NetworkError.GLOBAL_UNKNOWN);
                Console.WriteLine(e.Message);
            }

            ConsoleHelper.Write("Send - ServerPacketConfirmation");

            return(serverPacketConfirmation);
        }
        partial void BtnAskForNewCode_TouchUpInside(UIButton sender)
        {
            //send packet to server
            ServerPacketConfirmation serverPacketConfirmation = ServerHelper.AskConfirmUserAccount(Application.ActualUser, Application.UserPassword);

            //if success
            if (serverPacketConfirmation.ActionSuccess)
            {
                BarHelper.DisplayInfoBar(uivMainView, "Compte", $"Un nouveau code d'activation a été envoyé par mail à  {Application.ActualUser.UserEMail}.", 10,
                                         delegate { tfConfirmationCodeField.BecomeFirstResponder(); btnAskForNewCode.Enabled = false; },
                                         delegate { tfConfirmationCodeField.BecomeFirstResponder(); btnAskForNewCode.Enabled = false; });
                return;
            }

            //chose right error message
            String messageError = string.Empty;

            switch (serverPacketConfirmation.NetworkError)
            {
            case NetworkError.GLOBAL_UNKNOWN:
                goto default;

            case NetworkError.SERVER_UNAVAILABLE:
                messageError = MSGBank.ERROR_NO_SERVER;
                break;

            default:
                messageError = MSGBank.ERROR_UNKNOWN;
                break;
            }

            MessageBox.ShowOK(MSGBank.ERROR_TITLE, messageError, this);
        }
Beispiel #3
0
        public override Packet OnPacketReceive(Packet receivedPacket)
        {
            //get received packet
            ClientPacketDeletePet clientPacketDeletePet = receivedPacket as ClientPacketDeletePet;

            ConsoleHelper.Write("Receive - ClientPacketDeletePet");

            //read packet infos
            int userID = clientPacketDeletePet.UserID;
            int petID  = clientPacketDeletePet.PetID;

            //insert new profile into DB
            MySqlCommand deletePetCommand = new MySqlCommand();

            deletePetCommand.Connection  = Program.mySQLManager.MySQLConnection.MysqlConnection;
            deletePetCommand.CommandText =
                $"DELETE FROM T_Own WHERE T_Own.`fkPetID`='{petID}' AND T_Own.`fkUserID`='{userID}'; DELETE FROM `T_Share` WHERE `fkPetID`='{petID}'; DELETE FROM T_Pet WHERE `petID`= '{petID}'";

            ServerPacketConfirmation serverPacketConfirmation;

            try
            {
                //Execute command
                deletePetCommand.ExecuteNonQuery();
                serverPacketConfirmation = new ServerPacketConfirmation(true, NetworkError.NONE);
            }
            catch
            {
                serverPacketConfirmation = new ServerPacketConfirmation(false, NetworkError.GLOBAL_UNKNOWN);
            }

            ConsoleHelper.Write("Send - ServerPacketConfirmation");

            return(serverPacketConfirmation);
        }
        public override Packet OnPacketReceive(Packet receivedPacket)
        {
            ClientPacketKillSharePet clientPacketKillSharePet = receivedPacket as ClientPacketKillSharePet;

            ConsoleHelper.Write("Receive - ClientPacketKillSharePet");

            int userID = clientPacketKillSharePet.ReceiverUserID;
            int petID  = clientPacketKillSharePet.PetID;

            //insert new profile into DB
            MySqlCommand killPetShareCommand = new MySqlCommand();

            killPetShareCommand.Connection  = Program.mySQLManager.MySQLConnection.MysqlConnection;
            killPetShareCommand.CommandText =
                $"DELETE FROM `T_Share` WHERE `fkPetID`='{petID}' AND `fkReceiverID`='{userID}'";

            ServerPacketConfirmation serverPacketConfirmation;

            try
            {
                killPetShareCommand.ExecuteNonQuery();
                serverPacketConfirmation = new ServerPacketConfirmation(true, NetworkError.NONE);
            }
            catch
            {
                serverPacketConfirmation = new ServerPacketConfirmation(false, NetworkError.GLOBAL_UNKNOWN);
            }

            ConsoleHelper.Write("Send - ServerPacketConfirmation");

            return(serverPacketConfirmation);
        }
Beispiel #5
0
        partial void BtnDeleteAttribut_TouchUpInside(UIButton sender)
        {
            //if is a new attribute
            if (petAttributeID == -1)
            {
                this.NavigationController.PopViewController(true);
                return;
            }

            //remove attribute
            ServerPacketConfirmation serverPacketConfirmation = ServerHelper.DeleteAttribut(Application.PetManager.SelectedPet.PetID, petAttributeID);

            if (serverPacketConfirmation.ActionSuccess)
            {
                this.NavigationController.PopViewController(true);
                return;
            }

            //chose right error message
            String errorMessage = string.Empty;

            switch (serverPacketConfirmation.NetworkError)
            {
            case NetworkError.SERVER_UNAVAILABLE:
                errorMessage = MSGBank.ERROR_NO_SERVER;
                break;

            default:
                errorMessage = $"Impossible de modifier les attributs";
                break;
            }
            //show error message
            BarHelper.DisplayErrorBar(uivMainView, MSGBank.ERROR_TITLE, errorMessage);
        }
Beispiel #6
0
        public override Packet OnPacketReceive(Packet receivedPacket)
        {
            ClientPacketUserUpdateProfile clientPacketUserUpdateProfile = receivedPacket as ClientPacketUserUpdateProfile;

            ConsoleHelper.Write("Receive - ClientPacketUserUpdateProfile");

            PLFUser user         = clientPacketUserUpdateProfile.User;
            String  userPassword = clientPacketUserUpdateProfile.UserPassword.ToSQL();

            //insert new profile into DB
            MySqlCommand updateUserProfileCommand = new MySqlCommand();

            updateUserProfileCommand.Connection  = Program.mySQLManager.MySQLConnection.MysqlConnection;
            updateUserProfileCommand.CommandText =
                $"UPDATE `T_User` SET `userPassword`='{userPassword}',`userName`='{user.UserName.ToSQL()}'," +
                $"`userSurname`='{user.UserSurname.ToSQL()}',`userEmail`='{user.UserEMail.ToSQL()}' WHERE `userID`='{user.ID}'";


            ServerPacketConfirmation serverPacketConfirmation;

            try
            {
                updateUserProfileCommand.ExecuteNonQuery();

                serverPacketConfirmation = new ServerPacketConfirmation(true, NetworkError.NONE);
            }
            catch (MySqlException e)
            {
                Console.WriteLine(e.Number + " - " + e.Message);
                NetworkError networkError;
                switch (e.Number)
                {
                case 1062:
                    networkError = NetworkError.SQL_USER_EXIST;
                    break;

                case 1064:
                    networkError = NetworkError.GLOBAL_UNKNOWN;
                    break;

                default:
                    networkError = NetworkError.GLOBAL_UNKNOWN;
                    break;
                }
                serverPacketConfirmation = new ServerPacketConfirmation(false, networkError);
            }
            catch (Exception e)
            {
                serverPacketConfirmation = new ServerPacketConfirmation(false, NetworkError.GLOBAL_UNKNOWN);
                Console.WriteLine(e.Message);
            }

            ConsoleHelper.Write("Send - ServerPacketConfirmation");

            return(serverPacketConfirmation);
        }
        public void ConfirmAccount()
        {
            //get confirmation code
            String confirmationCode = tfConfirmationCodeField.Text;

            //send packet to server
            ServerPacketConfirmation serverPacketConfirmation = ServerHelper.ConfirmUserAccount(Application.ActualUser, confirmationCode);

            //if success
            if (serverPacketConfirmation.ActionSuccess)
            {
                BarHelper.DisplayInfoBar(uivMainView, "Compte", "Votre compte a été confirmé", 5, delegate
                {
                    //load user pets
                    Application.PetManager.LoadUserPetList(Application.ActualUser);

                    //instantiate main view controller
                    UIStoryboard mainBoard = UIStoryboard.FromName("Main", null);
                    MainTabBarController mainTabBarController = mainBoard.InstantiateViewController("MainTabBarController") as MainTabBarController;
                    PresentViewController(mainTabBarController, true, null);
                }, delegate
                {
                    //load user pets
                    Application.PetManager.LoadUserPetList(Application.ActualUser);

                    //instantiate main view controller
                    UIStoryboard mainBoard = UIStoryboard.FromName("Main", null);
                    MainTabBarController mainTabBarController = mainBoard.InstantiateViewController("MainTabBarController") as MainTabBarController;
                    PresentViewController(mainTabBarController, true, null);
                });

                return;
            }

            //chose right error message
            String messageError = string.Empty;

            switch (serverPacketConfirmation.NetworkError)
            {
            case NetworkError.GLOBAL_UNKNOWN:
                goto default;

            case NetworkError.SQL_USER_WRONG_ACCODE:
                messageError = "Ce code d'activation n'existe pas.";
                break;

            case NetworkError.SERVER_UNAVAILABLE:
                messageError = MSGBank.ERROR_NO_SERVER;
                break;

            default:
                messageError = MSGBank.ERROR_UNKNOWN;
                break;
            }
            BarHelper.DisplayErrorBar(uivMainView, MSGBank.ERROR_TITLE, messageError);
        }
        partial void BtnSaveEdit_TouchUpInside(UIButton sender)
        {
            //if some fields are empty
            if (String.IsNullOrEmpty(tfUserEmailField.Text) || String.IsNullOrEmpty(tfUserPasswordField.Text))
            {
                BarHelper.DisplayErrorBar(uivMainView, MSGBank.ERROR_TITLE, MSGBank.ERROR_FILL_ALL_FIELDS);
                return;
            }

            //if email is valid
            if (!tfUserEmailField.Text.IsValidEmail())
            {
                BarHelper.DisplayErrorBar(uivMainView, MSGBank.ERROR_TITLE, MSGBank.ERROR_WRONG_EMAIL);
                return;
            }

            //if the two passwords are the same
            if (tfUserPasswordField.Text != tfUserPasswordConfirmField.Text)
            {
                BarHelper.DisplayErrorBar(uivMainView, MSGBank.ERROR_TITLE, MSGBank.ERROR_NOT_SAME_PASSWORD);
                return;
            }

            //change actual user infos
            PLFUser actualUser = Application.ActualUser;

            actualUser.UserName    = tfUserNameField.Text;
            actualUser.UserSurname = tfUserSurnameField.Text;
            actualUser.UserEMail   = tfUserEmailField.Text;

            //send profile update to server
            ServerPacketConfirmation serverPacketConfirmation = ServerHelper.UpdateUserProfile(actualUser, tfUserPasswordField.Text);

            //if success
            if (serverPacketConfirmation.ActionSuccess)
            {
                BarHelper.DisplayInfoBar(uivMainView, "Profil", "Votre profil a correctement été mis à jour.");
            }
            else
            {
                //get the good error message
                String errorMessage = string.Empty;
                switch (serverPacketConfirmation.NetworkError)
                {
                case NetworkError.SERVER_UNAVAILABLE:
                    errorMessage = MSGBank.ERROR_NO_SERVER;
                    break;

                default:
                    errorMessage = $"Impossible de mettre à jour votre profil.";
                    break;
                }
                BarHelper.DisplayErrorBar(uivMainView, MSGBank.ERROR_TITLE, errorMessage);
            }
        }
        partial void BtnChangePassword_TouchUpInside(UIButton sender)
        {
            //if fields are empty
            if (String.IsNullOrEmpty(tfNickNameField.Text) || String.IsNullOrEmpty(tfCodeField.Text) ||
                String.IsNullOrEmpty(tfPasswordField.Text))
            {
                BarHelper.DisplayErrorBar(uivMainView, MSGBank.ERROR_TITLE, MSGBank.ERROR_FILL_ALL_FIELDS);
                return;
            }

            //if not same password
            if (tfPasswordField.Text != tfPasswordConfirmField.Text)
            {
                BarHelper.DisplayErrorBar(uivMainView, MSGBank.ERROR_TITLE, MSGBank.ERROR_NOT_SAME_PASSWORD);
                return;
            }

            //send packet to server
            ServerPacketConfirmation serverPacketConfirmation = ServerHelper.ResetUserPassword(tfNickNameField.Text, tfPasswordField.Text, tfCodeField.Text);

            if (serverPacketConfirmation.ActionSuccess)
            {
                MessageBox.ShowOK("Restauration de mot de passe", "Votre mot de passe a été mis à jour ! Vous pouvez désormais vous connecter avec celui-ci !", this, delegate { this.NavigationController.PopToRootViewController(true); });
                return;
            }

            //chose right error message
            String messageError = string.Empty;

            switch (serverPacketConfirmation.NetworkError)
            {
            case NetworkError.GLOBAL_UNKNOWN:
                goto default;

            case NetworkError.SERVER_UNAVAILABLE:
                messageError = MSGBank.ERROR_NO_SERVER;
                break;

            case NetworkError.SQL_USER_UNKNOWN:
                messageError = MSGBank.ERROR_UNKNOWN_USER;
                break;

            case NetworkError.SQL_USER_WRONG_ACCODE:
                messageError = "Ce code de restauration n'existe pas ou n'est plus valide !";
                break;

            default:
                messageError = MSGBank.ERROR_UNKNOWN;
                break;
            }
            BarHelper.DisplayErrorBar(uivMainView, MSGBank.ERROR_TITLE, messageError);
        }
Beispiel #10
0
        /// <summary>
        /// Asks the reset user password.
        /// </summary>
        /// <returns>The reset user password.</returns>
        /// <param name="userName">User name.</param>
        public static ServerPacketConfirmation AskResetUserPassword(String userName)
        {
            ClientPacketUserAskResetPassword clientPacketUserAskResetPassword = new ClientPacketUserAskResetPassword(userName);

            ServerPacketConfirmation serverPacketConfirmation = TCPClient.SendPacket(clientPacketUserAskResetPassword) as ServerPacketConfirmation;

            if (serverPacketConfirmation == null)
            {
                return(new ServerPacketConfirmation(false, NetworkError.SERVER_UNAVAILABLE));
            }

            return(serverPacketConfirmation);
        }
Beispiel #11
0
        /// <summary>
        /// Disables the user DA uth.
        /// </summary>
        /// <returns>The user DA uth.</returns>
        /// <param name="plfUser">Plf user.</param>
        public static ServerPacketConfirmation DisableUserDAuth(PLFUser plfUser)
        {
            ClientPacketDisableDAuth clientPacketDisableDAuth = new ClientPacketDisableDAuth(plfUser);

            ServerPacketConfirmation serverPacketConfirmation = TCPClient.SendPacket(clientPacketDisableDAuth) as ServerPacketConfirmation;

            if (serverPacketConfirmation == null)
            {
                return(new ServerPacketConfirmation(false, NetworkError.SERVER_UNAVAILABLE));
            }

            return(serverPacketConfirmation);
        }
Beispiel #12
0
        /// <summary>
        /// Confirms the user account.
        /// </summary>
        /// <returns>The user account.</returns>
        /// <param name="user">User.</param>
        /// <param name="code">Code.</param>
        public static ServerPacketConfirmation ConfirmUserAccount(PLFUser user, String code)
        {
            ClientPacketUserActivateAccount clientPacketUserActivateAccount = new ClientPacketUserActivateAccount(user, code);

            ServerPacketConfirmation serverPacketConfirmation = TCPClient.SendPacket(clientPacketUserActivateAccount) as ServerPacketConfirmation;

            if (serverPacketConfirmation == null)
            {
                return(new ServerPacketConfirmation(false, NetworkError.SERVER_UNAVAILABLE));
            }

            return(serverPacketConfirmation);
        }
Beispiel #13
0
        /// <summary>
        /// Asks the confirm user account.
        /// </summary>
        /// <returns>The confirm user account.</returns>
        /// <param name="user">User.</param>
        /// <param name="userPassword">User password.</param>
        public static ServerPacketConfirmation AskConfirmUserAccount(PLFUser user, String userPassword)
        {
            ClientPacketAskUserActivateAccout clientPacketAskUserActivateAccout = new ClientPacketAskUserActivateAccout(user, userPassword.HashSHA256());

            ServerPacketConfirmation serverPacketConfirmation = TCPClient.SendPacket(clientPacketAskUserActivateAccout) as ServerPacketConfirmation;

            if (serverPacketConfirmation == null)
            {
                return(new ServerPacketConfirmation(false, NetworkError.SERVER_UNAVAILABLE));
            }

            return(serverPacketConfirmation);
        }
Beispiel #14
0
        /// <summary>
        /// Kills the share pet.
        /// </summary>
        /// <returns>The share pet.</returns>
        /// <param name="petID">Pet identifier.</param>
        /// <param name="userID">User identifier.</param>
        public static ServerPacketConfirmation KillSharePet(int petID, int userID)
        {
            //create new packet kill share pet
            ClientPacketKillSharePet clientPacketKillSharePet = new ClientPacketKillSharePet(petID, userID);

            //send packet to server
            ServerPacketConfirmation serverPacketConfirmation = TCPClient.SendPacket(clientPacketKillSharePet) as ServerPacketConfirmation;

            //if no answer
            if (serverPacketConfirmation == null)
            {
                return(new ServerPacketConfirmation(false, NetworkError.SERVER_UNAVAILABLE));
            }

            return(serverPacketConfirmation);
        }
Beispiel #15
0
        /// <summary>
        /// Updates the pet.
        /// </summary>
        /// <returns>The pet.</returns>
        /// <param name="pet">Pet.</param>
        public static ServerPacketConfirmation UpdatePet(PLFPet pet)
        {
            //create new client packet update pet
            ClientPacketUpdatePet clientPacketUpdatePet = new ClientPacketUpdatePet(0, pet);

            //send packet to the server
            ServerPacketConfirmation serverPacketConfirmation = TCPClient.SendPacket(clientPacketUpdatePet) as ServerPacketConfirmation;

            //if no answer
            if (serverPacketConfirmation == null)
            {
                return(new ServerPacketConfirmation(false, NetworkError.SERVER_UNAVAILABLE));
            }

            return(serverPacketConfirmation);
        }
Beispiel #16
0
        public override Packet OnPacketReceive(Packet receivedPacket)
        {
            //get received packet
            ClientPacketEnableDAuth clientPacketEnableDAuth = receivedPacket as ClientPacketEnableDAuth;

            ConsoleHelper.Write("Receive - ClientPacketEnableDAuth");

            //read packet infos
            PLFUser user = clientPacketEnableDAuth.PlfUser;

            byte[] userPrivateKey = clientPacketEnableDAuth.UserPrivateKey;
            String userKey        = JsonConvert.SerializeObject(userPrivateKey);

            //insert key in db command
            MySqlCommand enableDAuthCommand = new MySqlCommand();

            enableDAuthCommand.Connection  = Program.mySQLManager.MySQLConnection.MysqlConnection;
            enableDAuthCommand.CommandText =
                $"INSERT INTO `T_DoubleAuth`(`daUserID`, `daUserKey`) VALUES ('{user.ID}','{userKey}')";

            ServerPacketConfirmation serverPacketConfirmation;

            try
            {
                //execute command
                enableDAuthCommand.ExecuteNonQuery();

                serverPacketConfirmation = new ServerPacketConfirmation(true, NetworkError.NONE);

                //run on extern thread
                new Thread(() =>
                {
                    Program.mailManager.SendMail(user.UserEMail, "PET LA FORME - Double Authentification",
                                                 $"Bonjour {user.UserName}! La double authentification a bien été activée sur votre compte. ");
                }
                           ).Start();
            }
            catch (Exception e)
            {
                serverPacketConfirmation = new ServerPacketConfirmation(false, NetworkError.GLOBAL_UNKNOWN);
                Console.WriteLine(e.Message);
            }

            ConsoleHelper.Write("Send - ServerPacketConfirmation");

            return(serverPacketConfirmation);
        }
Beispiel #17
0
        /// <summary>
        /// Deletes the attribut.
        /// </summary>
        /// <returns>The attribut.</returns>
        /// <param name="petID">Pet identifier.</param>
        /// <param name="attributID">Attribut identifier.</param>
        public static ServerPacketConfirmation DeleteAttribut(int petID, int attributID)
        {
            //create new client packet delete attribut
            ClientPacketDeleteAttribut clientPacketDeleteAttribut = new ClientPacketDeleteAttribut(petID, attributID);

            //send packet to server
            ServerPacketConfirmation serverPacketConfirmation = TCPClient.SendPacket(clientPacketDeleteAttribut) as ServerPacketConfirmation;

            //if no answer
            if (serverPacketConfirmation == null)
            {
                return(new ServerPacketConfirmation(false, NetworkError.SERVER_UNAVAILABLE));
            }

            //return packet
            return(serverPacketConfirmation);
        }
        public override Packet OnPacketReceive(Packet receivedPacket)
        {
            ClientPacketSharePet clientPacketSharePet = receivedPacket as ClientPacketSharePet;

            ConsoleHelper.Write("Receive - ClientPacketSharePet");

            int    ownerID          = clientPacketSharePet.OwnerUserID;
            int    petID            = clientPacketSharePet.PetID;
            String receiverUserName = clientPacketSharePet.ReceiverUserNick.ToSQL();
            int    sharePower       = clientPacketSharePet.SharePower;

            int receiverID = SQLHelper.GetUserID(receiverUserName);

            //if incorect user
            if (receiverID == -1)
            {
                return(new ServerPacketConfirmation(false, NetworkError.SQL_USER_UNKNOWN));
            }


            //insert new profile into DB
            MySqlCommand sharePetCommand = new MySqlCommand();

            sharePetCommand.Connection  = Program.mySQLManager.MySQLConnection.MysqlConnection;
            sharePetCommand.CommandText =
                $"INSERT INTO `T_Share`(`fkOwnerID`, `fkPetID`, `fkReceiverID`, `sharePower`) VALUES ('{ownerID}','{petID}','{receiverID}','{sharePower}')";

            ServerPacketConfirmation serverPacketConfirmation;

            try
            {
                sharePetCommand.ExecuteNonQuery();

                serverPacketConfirmation = new ServerPacketConfirmation(true, NetworkError.NONE);
            }
            catch (Exception e)
            {
                serverPacketConfirmation = new ServerPacketConfirmation(false, NetworkError.GLOBAL_UNKNOWN);
                Console.WriteLine(e.Message);
            }

            ConsoleHelper.Write("Send - ServerPacketConfirmation");

            return(serverPacketConfirmation);
        }
Beispiel #19
0
        public override Packet OnPacketReceive(Packet receivedPacket)
        {
            //get received packet
            ClientPacketDisableDAuth clientPacketDisableDAuth = receivedPacket as ClientPacketDisableDAuth;

            ConsoleHelper.Write("Receive - ClientPacketDisableDAuth");

            //read packet infos
            PLFUser user = clientPacketDisableDAuth.PlfUser;

            //insert key in db command
            MySqlCommand disableDAuthCommand = new MySqlCommand();

            disableDAuthCommand.Connection  = Program.mySQLManager.MySQLConnection.MysqlConnection;
            disableDAuthCommand.CommandText =
                $"DELETE FROM `T_DoubleAuth` WHERE `daUserID`='{user.ID}'";

            ServerPacketConfirmation serverPacketConfirmation;

            try
            {
                //execute command
                disableDAuthCommand.ExecuteNonQuery();

                serverPacketConfirmation = new ServerPacketConfirmation(true, NetworkError.NONE);

                //run on extern thread
                new Thread(() =>
                {
                    Program.mailManager.SendMail(user.UserEMail, "PET LA FORME - Double Authentification",
                                                 $"Bonjour {user.UserName}! La double authentification a bien été désactivée sur votre compte. ");
                }
                           ).Start();
            }
            catch (Exception e)
            {
                serverPacketConfirmation = new ServerPacketConfirmation(false, NetworkError.GLOBAL_UNKNOWN);
                Console.WriteLine(e.Message);
            }

            ConsoleHelper.Write("Send - ServerPacketConfirmation");

            return(serverPacketConfirmation);
        }
Beispiel #20
0
        /// <summary>
        /// Updates the user profile.
        /// </summary>
        /// <returns>The user profile.</returns>
        /// <param name="user">User.</param>
        /// <param name="userPassword">User password.</param>
        public static ServerPacketConfirmation UpdateUserProfile(PLFUser user, String userPassword)
        {
            //hash user profile
            String hashPassword = userPassword.HashSHA256();

            //create new user update profile packet
            ClientPacketUserUpdateProfile clientPacketUserUpdateProfile = new ClientPacketUserUpdateProfile(user, hashPassword);

            //send update packet to server
            ServerPacketConfirmation serverPacketConfirmation = TCPClient.SendPacket(clientPacketUserUpdateProfile) as ServerPacketConfirmation;

            //if no answer
            if (serverPacketConfirmation == null)
            {
                return(new ServerPacketConfirmation(false, NetworkError.SERVER_UNAVAILABLE));
            }

            return(serverPacketConfirmation);
        }
Beispiel #21
0
        /// <summary>
        /// Shares the pet.
        /// </summary>
        /// <returns>The pet.</returns>
        /// <param name="user">User.</param>
        /// <param name="pet">Pet.</param>
        /// <param name="receiverUserName">Receiver user name.</param>
        /// <param name="sharePower">Share power.</param>
        public static ServerPacketConfirmation SharePet(PLFUser user, PLFPet pet, String receiverUserName, int sharePower)
        {
            //get user id
            int userID = user.ID;

            //create new packet share pet
            ClientPacketSharePet clientPacketSharePet = new ClientPacketSharePet(userID, pet.PetID, receiverUserName, sharePower);

            //send packet to the server
            ServerPacketConfirmation serverPacketConfirmation = TCPClient.SendPacket(clientPacketSharePet) as ServerPacketConfirmation;

            //if no answer
            if (serverPacketConfirmation == null)
            {
                return(new ServerPacketConfirmation(false, NetworkError.SERVER_UNAVAILABLE));
            }

            return(serverPacketConfirmation);
        }
        partial void BtnAskForNewCode_TouchUpInside(UIButton sender)
        {
            //if fields are empty
            if (String.IsNullOrEmpty(tfNickNameField.Text))
            {
                BarHelper.DisplayErrorBar(uivMainView, MSGBank.ERROR_TITLE, "Vous devez remplir le champ 'Nom d'utilisateur'");
                return;
            }

            //send packet to server
            ServerPacketConfirmation serverPacketConfirmation = ServerHelper.AskResetUserPassword(tfNickNameField.Text);

            //if success
            if (serverPacketConfirmation.ActionSuccess)
            {
                BarHelper.DisplayInfoBar(uivMainView, "Restauration de mot de passe", "Un nouveau code de restauration de mot de passe vous a été envoyé par mail !");
                btnAskForNewCode.Enabled = false;
                return;
            }

            //chose right error message
            String messageError = string.Empty;

            switch (serverPacketConfirmation.NetworkError)
            {
            case NetworkError.GLOBAL_UNKNOWN:
                goto default;

            case NetworkError.SERVER_UNAVAILABLE:
                messageError = MSGBank.ERROR_NO_SERVER;
                break;

            case NetworkError.SQL_USER_UNKNOWN:
                messageError = MSGBank.ERROR_UNKNOWN_USER;
                break;

            default:
                messageError = MSGBank.ERROR_UNKNOWN;
                break;
            }
            BarHelper.DisplayErrorBar(uivMainView, MSGBank.ERROR_TITLE, messageError);
        }
Beispiel #23
0
        /// <summary>
        /// Deletes the pet.
        /// </summary>
        /// <returns>The pet.</returns>
        /// <param name="user">User.</param>
        /// <param name="pet">Pet.</param>
        public static ServerPacketConfirmation DeletePet(PLFUser user, PLFPet pet)
        {
            //get user and pet id
            int userID = user.ID;
            int petID  = pet.PetID;

            //new client delete pet
            ClientPacketDeletePet clientPacketDeletePet = new ClientPacketDeletePet(userID, petID);

            //send delete packet to the server
            ServerPacketConfirmation serverPacketConfirmation = TCPClient.SendPacket(clientPacketDeletePet) as ServerPacketConfirmation;

            //if no answer
            if (serverPacketConfirmation == null)
            {
                return(new ServerPacketConfirmation(false, NetworkError.SERVER_UNAVAILABLE));
            }

            return(serverPacketConfirmation);
        }
        partial void BtnSharePet_TouchUpInside(UIButton sender)
        {
            //if try to share to himself
            if (tfShareUserName.Text.ToLower() == Application.ActualUser.UserNickName.ToLower())
            {
                BarHelper.DisplayErrorBar(uivMainView, MSGBank.ERROR_TITLE, MSGBank.ERROR_SHARE_YOURSELF);
                return;
            }

            //send share pet packet to server
            ServerPacketConfirmation serverPacketConfirmation = ServerHelper.SharePet(
                Application.ActualUser, selectedPet, tfShareUserName.Text, swAllowModifications.On ? 1 : 0);

            //if success share
            if (serverPacketConfirmation.ActionSuccess)
            {
                this.NavigationController.PopViewController(true);
                MessageBox.ShowOK("Partage", $"Votre familier a bien été partagé avec {tfShareUserName.Text}", this.NavigationController.ParentViewController);
                return;
            }

            //chose right error message
            String errorMessage = string.Empty;

            switch (serverPacketConfirmation.NetworkError)
            {
            case NetworkError.SERVER_UNAVAILABLE:
                errorMessage = MSGBank.ERROR_NO_SERVER;
                break;

            case NetworkError.SQL_USER_UNKNOWN:
                errorMessage = MSGBank.ERROR_UNKNOWN_USER;
                break;

            default:
                errorMessage = $"Impossible de partager ce familier";
                break;
            }
            //show error message
            BarHelper.DisplayErrorBar(uivMainView, MSGBank.ERROR_TITLE, errorMessage);
        }
Beispiel #25
0
        /// <summary>
        /// Buttons the delete pet touch up inside.
        /// </summary>
        /// <param name="sender">Sender.</param>
        partial void BtnDeletePet_TouchUpInside(UIButton sender)
        {
            //ask yes no  delete
            MessageBox.ShowYesNo("Suppression de familier", "Etes vous sûr de vouloir supprimer ce familier ?", delegate
            {
                //yes
                //send delete pet to server
                ServerPacketConfirmation serverPacketConfirmation = ServerHelper.DeletePet(Application.ActualUser, actualPet);

                //if pet successfuly delete
                if (serverPacketConfirmation.ActionSuccess)
                {
                    //delete from list
                    Application.PetManager.DeletePet(actualPet);

                    //pop view controller
                    this.NavigationController.PopViewController(true);
                    return;
                }

                //switch for the good error msg
                String errorMessage = string.Empty;
                switch (serverPacketConfirmation.NetworkError)
                {
                case NetworkError.SERVER_UNAVAILABLE:
                    errorMessage = MSGBank.ERROR_NO_SERVER;
                    break;

                default:
                    errorMessage = $"Impossible de supprimer ce familier";
                    break;
                }
                BarHelper.DisplayErrorBar(uivMainView, MSGBank.ERROR_TITLE, errorMessage);
                //Show error message
            }, delegate
            {
                //no
                //nothing
            }, this);
        }
        partial void BtnActivateDAuth_TouchUpInside(UIButton sender)
        {
            if (String.IsNullOrEmpty(tfCodeField.Text))
            {
                BarHelper.DisplayErrorBar(uivMainView, MSGBank.ERROR_TITLE, MSGBank.ERROR_FILL_ALL_FIELDS);
                return;
            }

            if (googleTOTP.GeneratePin().ToLower() != tfCodeField.Text.ToLower())
            {
                BarHelper.DisplayErrorBar(uivMainView, MSGBank.ERROR_TITLE, "Code erroné !");
                return;
            }

            ServerPacketConfirmation serverPacketConfirmation = ServerHelper.EnableUserDAuth(Application.ActualUser, googleTOTP.getPrivateKey());

            //if success
            if (serverPacketConfirmation.ActionSuccess)
            {
                Application.ActualUserPrivateKey = googleTOTP.getPrivateKey();
                MessageBox.ShowOK("Double authentification", "La double authentification a bien été activée.", this,
                                  delegate { this.NavigationController.PopToRootViewController(true); });
            }
            else
            {
                //get the good error message
                String errorMessage = string.Empty;
                switch (serverPacketConfirmation.NetworkError)
                {
                case NetworkError.SERVER_UNAVAILABLE:
                    errorMessage = MSGBank.ERROR_NO_SERVER;
                    break;

                default:
                    errorMessage = $"Impossible d'activer la double authentification.";
                    break;
                }
                BarHelper.DisplayErrorBar(uivMainView, MSGBank.ERROR_TITLE, errorMessage);
            }
        }
        partial void BtnDesactivateDAuth_TouchUpInside(UIButton sender)
        {
            MessageBox.ShowYesNo("Double Authentification", "Êtes vous sûr de vouloir supprimer la double authentification?",
                                 delegate
            {
                ServerPacketConfirmation serverPacketConfirmation = ServerHelper.DisableUserDAuth(Application.ActualUser);

                //if success
                if (serverPacketConfirmation.ActionSuccess)
                {
                    MessageBox.ShowOK("Double authentification", "La double authentification a bien été désactivée.", this, delegate {
                        Application.ActualUserPrivateKey = null;
                        this.NavigationController.PopToRootViewController(true);
                    });
                }
                else
                {
                    //get the good error message
                    String errorMessage = string.Empty;
                    switch (serverPacketConfirmation.NetworkError)
                    {
                    case NetworkError.SERVER_UNAVAILABLE:
                        errorMessage = MSGBank.ERROR_NO_SERVER;
                        break;

                    default:
                        errorMessage = $"Impossible de désactiver la double authentification.";
                        break;
                    }
                    BarHelper.DisplayErrorBar(uivMainView, MSGBank.ERROR_TITLE, errorMessage);
                }
            },
                                 delegate
            {
                //no action
            },
                                 this);
        }
Beispiel #28
0
        partial void BtnSaveChanges_TouchUpInside(UIButton sender)
        {
            //set pet attribute fields
            petAttribute.AttributeTitle       = tfAttributName.Text;
            petAttribute.AttributeDescription = tvAttributDescription.Text;
            petAttribute.PetAttributeType     = selectedType;

            //remove old attribute and add new one
            if (petAttributeID != -1)
            {
                ServerHelper.DeleteAttribut(Application.PetManager.SelectedPet.PetID, petAttributeID);
            }

            //send packet to server
            ServerPacketConfirmation serverPacketConfirmation = ServerHelper.AddAttribut(Application.PetManager.SelectedPet.PetID, petAttribute);

            if (serverPacketConfirmation.ActionSuccess)
            {
                this.NavigationController.PopViewController(true);
                return;
            }

            //chose right error message
            String errorMessage = string.Empty;

            switch (serverPacketConfirmation.NetworkError)
            {
            case NetworkError.SERVER_UNAVAILABLE:
                errorMessage = MSGBank.ERROR_NO_SERVER;
                break;

            default:
                errorMessage = $"Impossible de modifier les attributs";
                break;
            }
            //show error message
            BarHelper.DisplayErrorBar(uivMainView, MSGBank.ERROR_TITLE, errorMessage);
        }
Beispiel #29
0
        partial void BtnCancelShare_TouchUpInside(UIButton sender)
        {
            //if no user selected
            if (selectedUser == null)
            {
                BarHelper.DisplayErrorBar(uivMainView, MSGBank.ERROR_TITLE, "Il faut sélectionner un utilisateur !");
                return;
            }

            //send kill share pet to server
            ServerPacketConfirmation serverPacketConfirmation = ServerHelper.KillSharePet(selectedPet.PetID, selectedUser.ID);

            //if success
            if (serverPacketConfirmation.ActionSuccess)
            {
                BarHelper.DisplayInfoBar(uivMainView, "Partage", $"Le partage a bien été cessé avec {selectedUser.UserNickName} !");
                //reload page
                LoadPage();
                return;
            }

            //chose right error message
            String errorMessage = string.Empty;

            switch (serverPacketConfirmation.NetworkError)
            {
            case NetworkError.SERVER_UNAVAILABLE:
                errorMessage = MSGBank.ERROR_NO_SERVER;
                break;

            default:
                errorMessage = $"Impossible de césser le partage de ce familier !";
                break;
            }
            //show error message
            BarHelper.DisplayErrorBar(uivMainView, MSGBank.ERROR_TITLE, errorMessage);
        }
Beispiel #30
0
        public override Packet OnPacketReceive(Packet receivedPacket)
        {
            ClientPacketUserActivateAccount clientPacketUserActivateAccount = receivedPacket as ClientPacketUserActivateAccount;

            ConsoleHelper.Write("Receive - ClientPacketUserActivateAccount");

            PLFUser user    = clientPacketUserActivateAccount.User;
            String  userKey = clientPacketUserActivateAccount.UserCode.ToSQL();

            //insert new profile into DB
            MySqlCommand checkActivationCodeCommabd = new MySqlCommand();

            checkActivationCodeCommabd.Connection  = Program.mySQLManager.MySQLConnection.MysqlConnection;
            checkActivationCodeCommabd.CommandText =
                $"SELECT * FROM `T_RegisterKey` WHERE `regUserMail`='{user.UserEMail}' AND `regKey`='{userKey}'";

            MySqlDataReader mysqlDataReader = null;

            ServerPacketConfirmation serverPacketConfirmation;

            Boolean confirmationAllow = false;

            try
            {
                mysqlDataReader = checkActivationCodeCommabd.ExecuteReader();

                //open reader
                while (mysqlDataReader.Read())
                {
                    confirmationAllow = true;
                }

                if (confirmationAllow)
                {
                    serverPacketConfirmation = new ServerPacketConfirmation(true, NetworkError.NONE);
                    new Thread(() =>
                    {
                        Program.mailManager.SendMail(user.UserEMail, "PET LA FORME - Inscription",
                                                     $"Bonjour {user.UserName}! Votre compte a été confirmé avec succés ! Bonne journée !");
                    }
                               ).Start();
                }
                else
                {
                    serverPacketConfirmation = new ServerPacketConfirmation(false, NetworkError.SQL_USER_WRONG_ACCODE);
                }
            }
            catch (MySqlException e)
            {
                Console.WriteLine(e.Number + " - " + e.Message);
                NetworkError networkError;
                switch (e.Number)
                {
                case 1062:
                    networkError = NetworkError.SQL_USER_WRONG_ACCODE;
                    break;

                case 1064:
                    networkError = NetworkError.GLOBAL_UNKNOWN;
                    break;

                default:
                    networkError = NetworkError.GLOBAL_UNKNOWN;
                    break;
                }
                serverPacketConfirmation = new ServerPacketConfirmation(false, networkError);
            }
            catch (Exception e)
            {
                serverPacketConfirmation = new ServerPacketConfirmation(false, NetworkError.GLOBAL_UNKNOWN);
                Console.WriteLine(e.Message);
            }

            if (mysqlDataReader != null && !mysqlDataReader.IsClosed)
            {
                mysqlDataReader.Close();
            }

            if (confirmationAllow)
            {
                MySqlCommand activeAccountCommand = new MySqlCommand();
                activeAccountCommand.Connection  = Program.mySQLManager.MySQLConnection.MysqlConnection;
                activeAccountCommand.CommandText =
                    $"UPDATE `T_User` SET `userAccountActive`='1' WHERE `userID`='{user.ID}'";
                activeAccountCommand.ExecuteNonQuery();
            }

            ConsoleHelper.Write("Send - ServerPacketConfirmation");

            return(serverPacketConfirmation);
        }