Beispiel #1
0
        void ValidateGameInfo_Handler(Task t)
        {
            HTask task = (HTask)t;

            object[] args       = (object[])t.Args;
            string   authString = (string)args[0];
            string   hash       = (string)args[1];


            // Validate auth string
            AuthStringManager.AuthAccountInfo aai = _server.AuthManager.FindAccount(authString);
            if (aai == null)
            {
                // This account isnt in the cache, need to go fetch from global server
                task.Client.PendingAuthTask = task;
                _server.GlobalServer.FetchAuthString(authString, task.Client.SessionKey);
                return;
            }

            ValidateGameInfoArgs gia = new ValidateGameInfoArgs(authString, hash);

            task.Client.AccountId    = aai.AccountID;
            task.Client.HardCurrency = aai.HardCurrency;

            // Fetch game data
            string sql = string.Format("SELECT * FROM game_data WHERE account_id={0};", task.Client.AccountId);

            AddDBQuery(sql, new HTask(HTask.HTaskType.ValidateGameInfo_GameDataProcess, task.Client, gia));

            // Fetch floor data
            sql = string.Format("SELECT * FROM floor_records WHERE account_id={0};", task.Client.AccountId);
            AddDBQuery(sql, new HTask(HTask.HTaskType.ValidateGameInfo_FloorInfoProcess, task.Client, gia));
        }
Beispiel #2
0
        void SpendCoins_Handler(Task t)
        {
            HTask task = (HTask)t;

            object[]       argsA = (object[])t.Args;
            SpendCoinsArgs args  = (SpendCoinsArgs)argsA[0];

            // Validate auth string
            AuthStringManager.AuthAccountInfo aai = _server.AuthManager.FindAccount(args.AuthToken);
            if (aai == null)
            {
                // This account isnt in the cache, need to go fetch from global server
                task.Client.PendingAuthTask = task;
                _server.GlobalServer.FetchAuthString(args.AuthToken, task.Client.SessionKey);
                return;
            }

            // Record this spend in the database
            string sql = string.Format("INSERT INTO spends SET account_id={0}, amount={1}, reason={2}, timestamp={3}; SELECT LAST_INSERT_ID();", aai.AccountID, args.Coins, args.SpendOn, DateTime.Now.Ticks);

            task.Client.AccountId = aai.AccountID;
            t.Type = (int)GSTask.GSTType.SpendCoins_Global;
            t.Args = args.Coins;
            AddDBQuery(sql, t);
        }
Beispiel #3
0
        void ProcessValidateGameInfo(ValidateGameInfoArgs gia, HClient client)
        {
            byte[] hash       = gia.GameInfo.GenerateHash();
            string serverHash = Encoding.UTF8.GetString(hash);
            string clientHash = gia.Hash;

            AuthStringManager.AuthAccountInfo aai = _server.AuthManager.FindAccount(gia.AuthString);
            gia.GameInfo.AuthString   = gia.AuthString;
            gia.GameInfo.DisplayName  = aai.DisplayName;
            gia.GameInfo.HardCurrency = aai.HardCurrency;
            gia.GameInfo.VipData      = VipData.Create(aai.Vip);
            client.SendValidateGameInfoResponse(aai.AccountID, aai.HardCurrency, aai.Vip, serverHash == clientHash, gia.GameInfo);
        }
Beispiel #4
0
        void CoinBalance_Process_Handler(Task t)
        {
            HTask task = (HTask)t;

            object[] args      = (object[])t.Args;
            string   authToken = (string)args[0];

            AuthStringManager.AuthAccountInfo aai = _server.AuthManager.FindAccount(authToken);
            if (aai == null)
            {
                // This account isnt in the cache, need to go fetch from global server
                task.Client.PendingAuthTask = task;
                _server.GlobalServer.FetchAuthString(authToken, task.Client.SessionKey);
                return;
            }

            task.Client.CurrencyUpdate(aai.HardCurrency, aai.Vip);
        }
Beispiel #5
0
        void TutorialData_Store_Handler(Task t)
        {
            HTask task = (HTask)t;

            object[] args         = (object[])t.Args;
            ulong    tutorialData = (ulong)args[0];
            string   authToken    = (string)args[1];

            AuthStringManager.AuthAccountInfo aai = _server.AuthManager.FindAccount(authToken);
            if (aai == null)
            {
                // This account isnt in the cache, need to go fetch from global server
                task.Client.PendingAuthTask = task;
                _server.GlobalServer.FetchAuthString(authToken, task.Client.SessionKey);
                return;
            }

            string sql = string.Format("UPDATE game_data SET tutorial={0} WHERE account_id={1};", tutorialData, aai.AccountID);

            AddDBQuery(sql, null, false);
        }
Beispiel #6
0
        void ValidateGameInfo_GameDataProcess_Handler(Task t)
        {
            HTask task = (HTask)t;

            object[]             args = (object[])t.Args;
            ValidateGameInfoArgs gia  = (ValidateGameInfoArgs)args[0];

            if (t.Query.Rows.Count > 0)
            {
                gia.GameInfo.GameData = ReadGameData(t.Query);
            }
            else
            {
                // Put this record in the database
                string sql = string.Format("INSERT INTO game_data SET account_id={0},tower0=1;", task.Client.AccountId);
                t.Type = -1;
                AddDBQuery(sql, t);

                // Also give this user 100 coins
                SpendCoinsArgs scargs = new SpendCoinsArgs();
                scargs.AuthToken = gia.AuthString;
                scargs.Coins     = -100;
                scargs.SpendOn   = 0;
                AddTask(new HTask(HTask.HTaskType.SpendCoins, task.Client, scargs));
                AuthStringManager.AuthAccountInfo aai = _server.AuthManager.FindAccount(gia.AuthString);
                aai.HardCurrency += 100;

                // Setup the default info
                gia.GameInfo.GameData                = new GameDataArgs();
                gia.GameInfo.GameData.TowerFloors    = new int[6];
                gia.GameInfo.GameData.TowerFloors[0] = 1;
            }

            if (gia.RequestFinished)
            {
                ProcessValidateGameInfo(gia, task.Client);
            }
        }
Beispiel #7
0
        void PuzzleComplete_FetchData_Handler(Task t)
        {
            HTask task = (HTask)t;

            object[]           args = (object[])t.Args;
            PuzzleCompleteArgs pca  = (PuzzleCompleteArgs)args[0];

            // Validate auth string
            AuthStringManager.AuthAccountInfo aai = _server.AuthManager.FindAccount(pca.AuthToken);
            if (aai == null)
            {
                // This account isnt in the cache, need to go fetch from global server
                task.Client.PendingAuthTask = task;
                _server.GlobalServer.FetchAuthString(pca.AuthToken, task.Client.SessionKey);
                return;
            }

            string sql = string.Format("SELECT * FROM game_data WHERE account_id={0};", aai.AccountID);

            task.Client.AccountId = aai.AccountID;
            task.Type             = (int)HTask.HTaskType.PuzzleComplete_Validate;
            task.Args             = new object[] { pca, aai };
            AddDBQuery(sql, t);
        }
Beispiel #8
0
        void PuzzleComplete_Validate_Handler(Task t)
        {
            HTask        task     = (HTask)t;
            GameDataArgs gameData = ReadGameData(t.Query);

            object[]           args = (object[])t.Args;
            PuzzleCompleteArgs pca  = (PuzzleCompleteArgs)args[0];

            AuthStringManager.AuthAccountInfo aai = (AuthStringManager.AuthAccountInfo)args[1];
            if (pca.TowerIndex < 0 || pca.TowerIndex >= gameData.TowerFloors.Length)
            {
                // Invalid tower number
                RecordError(task.Client.AccountId, "Invalid floor number submitted: " + pca.TowerIndex);
            }
            else
            {
                if (pca.FloorNumber > gameData.TowerFloors[pca.TowerIndex])
                {
                    // Trying to complete a puzzle further ahead than the current progress?!
                    RecordError(task.Client.AccountId, string.Format("Out of order completion - got:{0}, expected{1}", pca.FloorNumber, gameData.TowerFloors[pca.TowerIndex]));
                }
                else
                {
                    // This is the expected puzzle or a repeat of a previous puzzle

                    // Move to the next puzzle on this floor
                    if (pca.FloorNumber == gameData.TowerFloors[pca.TowerIndex])
                    {
                        gameData.TowerFloors[pca.TowerIndex]++;
                    }

                    VipDataArgs vda      = VipData.Create(aai.Vip);
                    float       expBonus = pca.NoExpBonus ? 1 : vda.ExpBonus;

                    // Level up?
                    double baseExp  = Balance.BaseExp(pca.TowerIndex);
                    double bonusExp = Balance.BonusExp(pca.TowerIndex, pca.CompletionTime);
                    double total    = (baseExp + bonusExp) * expBonus;
                    int    exp      = (int)total;
                    gameData.Exp += exp;
                    int expForNextLevel = Balance.ExpForNextLevel(gameData.Level);
                    while (gameData.Exp >= expForNextLevel)
                    {
                        gameData.Level++;
                        gameData.Exp   -= expForNextLevel;
                        expForNextLevel = Balance.ExpForNextLevel(gameData.Level);
                    }

                    // Unlock next tower?
                    if (pca.TowerIndex < (gameData.TowerFloors.Length - 1) &&
                        gameData.TowerFloors[pca.TowerIndex + 1] == 0 &&
                        gameData.Level >= Balance.UnlockThreshold(pca.TowerIndex))
                    {
                        gameData.TowerFloors[pca.TowerIndex + 1] = 1;
                    }

                    // Save changes
                    string sql = string.Format("UPDATE game_data SET tower0={0}, tower1={1}, tower2={2}, tower3={3}, tower4={4}, tower5={5}, level={6}, exp={7} WHERE account_id={8};",
                                               gameData.TowerFloors[0], gameData.TowerFloors[1], gameData.TowerFloors[2], gameData.TowerFloors[3], gameData.TowerFloors[4], gameData.TowerFloors[5], gameData.Level, gameData.Exp, task.Client.AccountId);
                    AddDBQuery(sql, null, false);
                    task.Client.SendGameData(gameData);

                    // Store this completion record
                    sql       = string.Format("SELECT * FROM floor_records WHERE account_id={0} AND tower={1} AND floor={2};", task.Client.AccountId, pca.TowerIndex, pca.FloorNumber);
                    task.Type = (int)HTask.HTaskType.FloorRecord_Process;
                    AddDBQuery(sql, task);
                }
            }
        }