コード例 #1
0
        public bool Register(string userName, string password, string email)
        {
            MySqlConnection myConnection = new MySqlConnection(connectionString);
            // Select všechny učty a porovnani s učtem hračovym

            List<MySqlParameter> parameters = new List<MySqlParameter>();
            parameters.Add(new MySqlParameter("@ACC_NAME", userName));

            // Kontrola zda zadane jmeno uctu j*z existuje v DB
            List<string>[] queryResult = Select("SELECT COUNT(*) FROM accounts WHERE ACCOUNT_NAME = @ACC_NAME", 1, parameters);
            if (!sqlStatementCompleted)
            {
                // Nebylo navazano spojeni s DB
                actualState = ConnectionStatus.Disconnected;
                return false;
            }
            // Jestli již existuje hrač se stejnym jmenem, je vracen vysledek > 0
            if (Convert.ToInt32(queryResult[0][0]) > 1)
            {
                if (actualLanguage == Language.English)
                    statusText = "Player with nick "+userName+" already exists!";
                else statusText = "Hráč se jménem " + userName + " již existuje!";
                return false;
            }

            parameters = new List<MySqlParameter>();
            parameters.Add(new MySqlParameter("@ACC_MAIL", email));

            // Kontrola zda zadany email již existuje v DB
            queryResult = Select("SELECT COUNT(*) FROM accounts WHERE EMAIL = @ACC_MAIL", 1, parameters);
            if (Convert.ToInt32(queryResult[0][0]) > 1)
            {
                if (actualLanguage == Language.English)
                    statusText = "Someone with email \""+email+"\" was already registered!";
                else statusText = "Někdo s emailem \"" + email + "\" již byl zaregistrován!";
                return false;
            }

            // Vše je OK! Je možno zaregistrovat nového hráče!
            parameters = new List<MySqlParameter>();
            parameters.Add(new MySqlParameter("@ACC_NAME", userName));

            /*
            string encryptedstring = StringCipher.Encrypt("6DFdsx65v23eRe3yx2De6qer", password);
            string encryptedAccName = StringCipher.Encrypt("okv2pPOWdc665YYxX333", userName);*/

            string encryptedstring = Hash(password);
            string encryptedAccName = Hash(userName);
            Console.WriteLine("Vygeneroval jsem " + encryptedstring);
            parameters.Add(new MySqlParameter("@ACC_PWD", encryptedstring));
            parameters.Add(new MySqlParameter("@ACC_MAIL", email));
            parameters.Add(new MySqlParameter("@ENC_NAME", encryptedAccName));
            if (Insert("INSERT INTO ACCOUNTS VALUES(@ACC_NAME,@ACC_PWD,@ACC_MAIL,'registered',@ENC_NAME)", parameters))
            {
                if (actualLanguage == Language.English)
                    statusText = "Your game account was successfully registered!";
                else statusText = "Váš herni učet byl úspěšně zaregistrován!";
                actualState = ConnectionStatus.Connected;
                loggedPlayerName = userName;
                thisPlayer = new Player(userName);
                thisPlayer.achievements = loadPlayersAchievements(thisPlayer);
                loggedPlayerStatus = AccountStatus.Registered;
                return true;
            }

            return false;
        }
コード例 #2
0
        List<Achievement> loadPlayersAchievements(Player player)
        {
            MySqlConnection myConnection = new MySqlConnection(connectionString);

            List<MySqlParameter> parameters = new List<MySqlParameter>();
            parameters.Add(new MySqlParameter("@ACC_NAME", player.name));

            List<Achievement> outputAchievements = new List<Achievement>();
            if (actualState == ConnectionStatus.Disconnected) return outputAchievements;
            // Kontrola zda zadane jmeno uctu j*z existuje v DB
            List<string>[] queryResult = Select("SELECT * FROM players_achievements WHERE ACCOUNT_NAME = @ACC_NAME", 2, parameters);
            if (!sqlStatementCompleted) return outputAchievements;

            // Naplnění listu vysledku
            Console.WriteLine("loading players  " + player.name + " achievements :");
            for (int i = 0; i < numberOfSelectedRows; i++)
            {
                //Vyhledani informaci o achievementu na zaklade id achievementu
                string foundAchievementID = queryResult[i][0];

                // Vytvořeni parametru
                List<MySqlParameter> parameters2 = new List<MySqlParameter>();
                parameters2.Add(new MySqlParameter("@ID_ACHIEVEMENT", foundAchievementID));

                List<string>[] queryResult2 = Select("SELECT * FROM ACHIEVEMENTS WHERE ID_ACHIEVEMENT = @ID_ACHIEVEMENT",5,parameters2);
                if (!sqlStatementCompleted) return outputAchievements;
                if (queryResult2[0][4] == "1") // achievement byl smazan
                    continue;

                Achievement newAchievement = new Achievement(Convert.ToInt32(queryResult2[0][0]),queryResult2[0][1],queryResult2[0][2],Convert.ToInt32(queryResult2[0][3]));
                Console.WriteLine(" achievement ["+newAchievement.AchievementID+"] " + newAchievement.AchievementName + " from game " + newAchievement.GameName + " with score - " + newAchievement.Score);
                outputAchievements.Add(newAchievement);

            }
            return outputAchievements;
        }
コード例 #3
0
        public bool Login(string userName, string password)
        {
            loggedPlayerName = "";
            // Hlavní metoda pro přihlášení uživatele
            MySqlConnection myConnection = new MySqlConnection(connectionString);
            actualState = ConnectionStatus.Connecting;
            if (actualLanguage == Language.English)
                statusText = "Connecting to server...";
            else statusText = "Připojuji se k serveru...";

            // Select všechny učty a porovnani s učtem hračovym
            List<MySqlParameter> parameters = new List<MySqlParameter>();
            //parameters.Add(new MySqlParameter(
            parameters.Add(new MySqlParameter("@ACC_NAME", userName));

            // encryptovani vstupniho hesla
            string encryptedstring = Hash(password);

            parameters.Add(new MySqlParameter("@ACC_PWD", encryptedstring));
            //List<string>[] queryResult = Select("SELECT * FROM accounts WHERE ACCOUNT_NAME = @ACC_NAME AND PASSWORD = @ACC_PWD", 3, parameters);
            List<string>[] queryResult = Select("SELECT COUNT(*) FROM accounts WHERE ACCOUNT_NAME = @ACC_NAME AND PASSWORD = @ACC_PWD", 1, parameters);

            if (!sqlStatementCompleted)
            {
                // Nebylo navazano spojeni s DB
                actualState = ConnectionStatus.Disconnected;
                return false;
            }

            // Jestli se hrač přihlásí tak musí být vysledek select count(*) roven 1
            if (queryResult[0][0] == "1")
            {
                // Hrač je nalezen, zkontroluj jeho status

                parameters = new List<MySqlParameter>();
                parameters.Add(new MySqlParameter("@ACC_NAME", userName));

                queryResult = Select("SELECT STATUS FROM accounts WHERE ACCOUNT_NAME = @ACC_NAME", 1, parameters);
                loggedPlayerStatus = convertStatusFromString(queryResult[0][0]);

                switch (loggedPlayerStatus)
                {
                    case AccountStatus.Banned:
                        if (actualLanguage == Language.English)
                            statusText = "Your account was banned!";
                        else statusText = "Váš účet byl zabanován!";
                        return false;
                        break;
                   /* case AccountStatus.Registered:
                        if (actualLanguage == Language.English)
                            statusText = "You need to activate your account via link sended to your email address.";
                        else statusText = "Je nutno aktivovat účet pomocí odkazu zaslaném na Vaši emailovou adresu!";
                        return false;
                        break;*/
                    default:
                        break;
                }

                if (actualLanguage == Language.English)
                    statusText = "You was successfully logged in!";
                else statusText = "Úspěšně jste se přihlásil";
                actualState = ConnectionStatus.Connected;
                loggedPlayerName = userName;
                thisPlayer = new Player(userName);
                thisPlayer.achievements = loadPlayersAchievements(thisPlayer);

                return true;
            }
            actualState = ConnectionStatus.InvalidUserNamePassword;
            if (actualLanguage == Language.English)
                statusText = "Incorrect username or password.";
            else statusText = "Nesprávné přihlašovací jméno či heslo.";
            return false;
        }