PsyOps

CheckDB

Jan 25th, 2013
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.82 KB | None | 0 0
  1.         // If the code reaches here - there is no player on the bot list to add
  2.         // and we are checking here to see if the player is stored on the bz database
  3.         public void CheckDB(PublicPlayer StoredPlayer, Queue<EventArgs> q)
  4.         {
  5.                         //Open connection
  6.             if (this.OpenConnection(q) == true)
  7.             {
  8.                 int Bux = 0;
  9.  
  10.                 string query = "SELECT bz_bux FROM bz_bank WHERE player_name = \"" + StoredPlayer.PlayerName + "\"";
  11.                 //Create Command
  12.                 MySqlCommand cmd = new MySqlCommand(query, connection);
  13.                 //Create a data reader and Execute the command
  14.                 MySqlDataReader dataReader = cmd.ExecuteReader();
  15.  
  16.                 bool exists = dataReader.HasRows;
  17.  
  18.                 if (exists)
  19.                 {
  20.                     //Read the data and store them in the list
  21.                     while (dataReader.Read())
  22.                     {
  23.                         Bux = int.Parse(dataReader["bz_bux"] + "");
  24.                     }
  25.  
  26.                     StoredPlayer.BZBux = Bux * .01;
  27.                 }
  28.                 else
  29.                 {
  30.                     string query2 = "INSERT INTO bz_bank (player_name, bz_bux) VALUES (\"" + StoredPlayer.PlayerName + "\", 0);";
  31.                     //create command and assign the query and connection from the constructor
  32.                     MySqlCommand cmd2 = new MySqlCommand(query2, connection);
  33.  
  34.                     //Execute command
  35.                     cmd2.ExecuteNonQuery();
  36.  
  37.                     q.Enqueue(msg.arena("New Player Detected - Player inserted into database."));
  38.                 }
  39.                
  40.                 if (this.CloseConnection(q) == true)
  41.                     q.Enqueue(msg.arena("Connection closed."));
  42.             }
  43.         }
Advertisement
Add Comment
Please, Sign In to add comment