void AuthStringRequestHandler(Task t) { GlobalTask task = (GlobalTask)t; task.Type = (int)GlobalTask.GlobalType.AuthStringProcess; object[] args = (object[])task.Args; DBQuery q = AddDBQuery(string.Format("SELECT * FROM accounts WHERE auth_string=\"{0}\";", (string)args[0]), task); }
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); }
static void gclient_OnAccountInfoRequest(object sender, AccountInfoRequestArgs e) { GlobalTask gst = new GlobalTask(); gst.Type = (int)GlobalTask.GlobalType.AccountInfoRequest; gst.Client = (GlobalClient)sender; gst.Args = e; _server.TaskProcessor.AddTask(gst); }
private static void Gclient_OnAuthStringRequest(GlobalClient arg1, string arg2, uint clientKey) { GlobalTask gt = new GlobalTask(); gt.Type = (int)GlobalTask.GlobalType.AuthStringRequest; gt.Client = arg1; gt.Args = new object[] { arg2, clientKey }; _server.TaskProcessor.AddTask(gt); }
void AccountInfoRequestHandler(Task t) { GlobalTask task = (GlobalTask)t; AccountInfoRequestArgs args = (AccountInfoRequestArgs)task.Args; // Fetch account from the database DBQuery q = AddDBQuery(string.Format("SELECT * FROM accounts WHERE email=\"{0}\";", args.Email), task); task.Type = (int)GlobalTask.GlobalType.AccountInfoProcess; }
public void FinalizeProductPurchase(string uid, string pid, string transactionJson) { int user = -1; if (int.TryParse(uid, out user)) { GlobalProduct p = GetProduct(pid); GlobalTask gt = new GlobalTask(GlobalTask.GlobalType.Purchase_Product); gt.Args = new object[] { user, p.ProductId, p.Coins, p.VIP, p.USD, 0 /*braintree*/, transactionJson.Replace('\"', '\'') }; _server.TaskProcessor.AddTask(gt); } }
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); } } }
void AuthStringProcessHandler(Task t) { GlobalTask task = (GlobalTask)t; int accountId = -1; string displayName = ""; int hardCurrency = 0; object[] args = (object[])task.Args; string authString = (string)args[0]; int vip = 0; if (task.Query.Rows.Count > 0) { if (task.Query.Rows.Count > 1) { // This matched more than one record? log this error but just associate with the first one string errorMessage = string.Format("AuthString {0} matches multiple account records!", authString); NetworkCore.LogInterface.Log(errorMessage, NetworkCore.LogInterface.LogMessageType.Security, true); } object[] row = task.Query.Rows[0]; accountId = (int)row[0]; displayName = row[3].ToString(); hardCurrency = (int)row[4]; vip = (int)row[6]; } else { // No accounts matching the given auth string! // Log the error string errorMessage = string.Format("Unknown auth string '{0}' recieved from: {1}", authString, task.Client.IPAddress); NetworkCore.LogInterface.Log(errorMessage, NetworkCore.LogInterface.LogMessageType.Security, true); // Deny access accountId = -1; } task.Client.SendAccountInfo((uint)args[1], accountId, displayName, hardCurrency, vip, authString); }
void AccountInfoProcessHandler(Task t) { GlobalTask task = (GlobalTask)t; int accountId = -1; string displayName = ""; int hardCurrency = 0; string authString = ""; int vip = 0; AccountInfoRequestArgs args = (AccountInfoRequestArgs)task.Args; bool sendAccountInfo = true; if (task.Query.Rows.Count > 0) { // 0: account_id // 1: email // 2: password // 3: display name // 4: hard_currency // 5: auth_string // 6: vip // 7: google_id // 8: facebook_id // Found the account, check the password object[] row = task.Query.Rows[0]; accountId = (int)row[0]; string pw = row[2].ToString(); string google_id = (row[7] is DBNull) ? null : row[7].ToString(); string facebook_id = (row[8] is DBNull) ? null : row[8].ToString(); if (ValidPassword(args.Password, args.OAuthMode, pw, google_id, facebook_id, args.Email)) { // password match displayName = row[3].ToString(); hardCurrency = (int)row[4]; vip = (int)row[6]; if (row[5] is DBNull) { // Auth string doesnt exist, generate it now authString = GenerateAuthString((string)row[1], pw, displayName, accountId); // Store it in the database DBQuery q = AddDBQuery(string.Format("UPDATE accounts SET auth_string=\"{0}\" WHERE account_id={1};", authString, accountId), null); } else { authString = (string)row[5]; } } else { if (args.OAuthMode == 1 && google_id == null) { // Trying to sign in with google but this account isn't associated with google. // Add the google id to the database for this user and try again task.Type = (int)GlobalTask.GlobalType.AccountInfoRequest; AddDBQuery(string.Format("UPDATE accounts SET google_id=\"{0}\" WHERE account_id={1};", args.Password, accountId), task); sendAccountInfo = false; } else if (args.OAuthMode == 2 && facebook_id == null) { // Trying to sign in with facebook but this account isn't associated with facebook. // Add the facebook id to the database for this user and try again task.Type = (int)GlobalTask.GlobalType.AccountInfoRequest; AddDBQuery(string.Format("UPDATE accounts SET facebook_id=\"{0}\" WHERE account_id={1};", args.Password, accountId), task); sendAccountInfo = false; } // password mismatch - displayName stays empty but accountId is filled in } } else { // Account does not exist if (args.DisplayName != null) { // This is actually a request to create the account. sendAccountInfo = false; task.Type = (int)GlobalTask.GlobalType.AccountInfoRequest; switch (args.OAuthMode) { default: AddDBQuery(string.Format("INSERT INTO accounts SET email=\"{0}\",password=\"{1}\",display_name=\"{2}\",hard_currency={3},vip={4};", args.Email, args.Password, args.DisplayName, 0, 0), task); break; case 1: // Google AddDBQuery(string.Format("INSERT INTO accounts SET email=\"{0}\",display_name=\"{1}\",hard_currency={2},vip={3},google_id={4};", args.Email, args.DisplayName, 0, 0, args.Password), task); break; case 2: // Facebook AddDBQuery(string.Format("INSERT INTO accounts SET email=\"{0}\",display_name=\"{1}\",hard_currency={2},vip={3},facebook_id={4};", args.Email, args.DisplayName, 0, 0, args.Password), task); break; } } } if (sendAccountInfo) { task.Client.SendAccountInfo(args.ClientKey, accountId, displayName, hardCurrency, vip, authString); } }