Esempio n. 1
0
        void SpendCoinsHandler(Task t)
        {
            GlobalSpendCoinArgs args = (GlobalSpendCoinArgs)t.Args;
            string sql = string.Format("SELECT hard_currency,vip FROM accounts WHERE account_id={0};", args.AccountId);

            t.Type = (int)GlobalTask.GlobalType.SpendCoins_Process;
            AddDBQuery(sql, t);
        }
Esempio n. 2
0
        private static void Gclient_OnSpendCoins(object sender, GlobalSpendCoinArgs e)
        {
            GlobalTask gst = new GlobalTask();

            gst.Type   = (int)GlobalTask.GlobalType.SpendCoins;
            gst.Client = (GlobalClient)sender;
            gst.Args   = e;

            _server.TaskProcessor.AddTask(gst);
        }
Esempio n. 3
0
        void SpendCoins_ProcessHandler(Task t)
        {
            GlobalTask          task = (GlobalTask)t;
            GlobalSpendCoinArgs args = (GlobalSpendCoinArgs)t.Args;
            int currency             = (int)t.Query.Rows[0][0];
            int vip    = (int)t.Query.Rows[0][1];
            int before = currency;

            currency -= args.Amount;
            if (currency < 0)
            {
                // Spent more than they had!?
                currency = 0;
            }

            vip += args.VIP;

            // Store transaction in the database
            string sql = string.Format("INSERT INTO transactions SET account_id={0}, amount={1}, before_t={2}, after_t={3}, server_record={4}, timestamp=\"{5}\";", args.AccountId, -args.Amount, before, currency, args.ServerRecord, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));

            AddDBQuery(sql, null, false);

            // Store currency in the database
            sql = string.Format("UPDATE accounts SET hard_currency={0},vip={1} WHERE account_id={2};", currency, vip, args.AccountId);
            AddDBQuery(sql, null, false);

            if (task.Client != null)
            {
                // Tell the client about it
                task.Client.HardCurrencyUpdate(args.AccountId, currency, vip);
            }
            else
            {
                // Tell all connected game servers about it
                Connection[] gameServers = GlobalServer.Server.InputThread.Clients;
                foreach (Connection c in gameServers)
                {
                    GlobalClient gc = (GlobalClient)c;
                    gc.HardCurrencyUpdate(args.AccountId, currency, vip);
                }
            }
        }