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; }
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); }
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); } }