public void VerifyProceduresActionWithNoUpdatesNoDriver() { DatabaseDriver driver = new DatabaseDriver(DatabaseConfig.GetProviderTypeString(), DatabaseConfig.GetConnectionString()); var result = driver.Execute("setStateAbbrevToSelf", new { StateAbbreviation = "ZZ" }, commandType: CommandType.StoredProcedure); Assert.AreEqual(0, result, "Expected 0 state abbreviation to be updated."); }
/// <summary> /// Creates a new Gamespy Account /// </summary> /// <remarks>Used by the login server when a create account request is made</remarks> /// <param name="databaseDriver">The database connection to use</param> /// <param name="Nick">The Account Name</param> /// <param name="Pass">The UN-HASHED Account Password</param> /// <param name="Email">The Account Email Address</param> /// <param name="Country">The Country Code for this Account</param> /// <param name="UniqueNick">The unique nickname for this Account</param> /// <returns>Returns the Player ID if sucessful, 0 otherwise</returns> public static uint CreateUser(DatabaseDriver databaseDriver, string Nick, string Pass, string Email, string Country, string UniqueNick) { databaseDriver.Execute("INSERT INTO users(email, password) VALUES(@P0, @P1)", Email, StringExtensions.GetMD5Hash(Pass)); var Rows = databaseDriver.Query("SELECT userid FROM users WHERE email=@P0 and password=@P1", Email, Pass); if (Rows.Count < 1) { return(0); } databaseDriver.Execute("INSERT INTO profiles(userid, nick, uniquenick, countrycode) VALUES(@P0, @P1, @P2, @P3)", Rows[0]["userid"], Nick, UniqueNick, Country); Rows = databaseDriver.Query("SELECT profileid FROM profiles WHERE uniquenick=@P0", UniqueNick); if (Rows.Count < 1) { return(0); } return(uint.Parse(Rows[0]["profileid"].ToString())); }
public static void UpdateUser(DatabaseDriver databaseDriver, uint playerId, string Country) { databaseDriver.Execute("UPDATE profiles SET countrycode=@P0 WHERE `profileid`=@P1", Country, playerId); }
/// <summary> /// Creates a new instance of <see cref="GPCMServer"/> /// </summary> public GPCMServer(DatabaseDriver databaseDriver) : base(databaseDriver) { GPCMClient.OnDisconnect += GpcmClient_OnDisconnect; GPCMClient.OnSuccessfulLogin += GpcmClient_OnSuccessfulLogin; // Setup timer. Every 15 seconds should be sufficient if (PollTimer == null || !PollTimer.Enabled) { PollTimer = new System.Timers.Timer(15000); PollTimer.Elapsed += (s, e) => { // Send keep alive to all connected clients if (Clients.Count > 0) { Parallel.ForEach(Clients.Values, client => client.SendKeepAlive()); } // Disconnect hanging connections if (Processing.Count > 0) { Parallel.ForEach(Processing.Values, client => CheckTimeout(client)); } }; PollTimer.Start(); } // Setup timer. Every 5 seconds should be sufficient if (StatusTimer == null || !StatusTimer.Enabled) { StatusTimer = new System.Timers.Timer(5000); StatusTimer.Elapsed += (s, e) => { // Return if we are empty if (PlayerStatusQueue.IsEmpty) { return; } // Open database connection using (var transaction = databaseDriver.BeginTransaction()) { try { long timestamp = ((DateTimeOffset)DateTime.UtcNow).ToUnixTimeSeconds(); GPCMClient result; while (PlayerStatusQueue.TryDequeue(out result)) { // Skip if this player never finished logging in if (result == null) { continue; } if (!result.CompletedLoginProcess) { continue; } // Only update record under these two status' { // Update player record databaseDriver.Execute( "UPDATE profiles SET status=@P3, lastip=@P0, lastonline=@P1 WHERE profileid=@P2", result.RemoteEndPoint.Address, timestamp, result.PlayerId, (uint)result.PlayerStatus ); } } transaction.Commit(); } catch (Exception ex) { LogWriter.Log.WriteException(ex); transaction.Rollback(); } } }; StatusTimer.Start(); } // Set connection handling ConnectionEnforceMode = EnforceMode.DuringPrepare; // TODO: Change this //FullErrorMessage = Config.GetValue("Settings", "LoginServerFullMessage").Replace("\"", ""); FullErrorMessage = ""; }