Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using BattleCore;
- using BattleCore.Events;
- using PsyModules;
- using System.IO;
- using MySql.Data.MySqlClient;
- using System.Diagnostics;
- namespace Battle
- {
- public class BZMYSQL
- {
- private MySqlConnection connection;
- private string server;
- private string database;
- private string uid;
- private string password;
- ShortChat msg = new ShortChat();
- public void Initialize( Queue<EventArgs> q)
- {
- server = "123.456.1.123";
- database = "db name";
- uid = "username";
- password = "pa55w0rd";
- string connectionString;
- connectionString = "SERVER=" + server + ";" + "DATABASE=" +
- database + ";" + "UID=" + uid + ";" + "PASSWORD=" + password + ";";
- connection = new MySqlConnection(connectionString);
- if (this.OpenConnection(q) == true)
- {
- if (this.CloseConnection(q) == true)
- q.Enqueue(msg.arena("Battle Database configured and loaded.."));
- }
- else
- q.Enqueue(msg.arena("SQL Connection Phail."));
- }
- //open connection to database
- private bool OpenConnection(Queue<EventArgs> q)
- {
- try
- {
- connection.Open();
- return true;
- }
- catch (MySqlException ex)
- {
- //When handling errors, you can your application's response based
- //on the error number.
- //The two most common error numbers when connecting are as follows:
- //0: Cannot connect to server.
- //1045: Invalid user name and/or password.
- switch (ex.Number)
- {
- case 0:
- q.Enqueue(msg.arena("Cannot connect to server. Contact administrator"));
- break;
- case 1045:
- q.Enqueue(msg.arena("Invalid username/password, please try again"));
- break;
- default:
- q.Enqueue(msg.arena("Error: Num[" + ex.Number + "]"));
- break;
- }
- return false;
- }
- }
- //Close connection
- private bool CloseConnection(Queue<EventArgs> q)
- {
- try
- {
- connection.Close();
- return true;
- }
- catch (MySqlException ex)
- {
- q.Enqueue(msg.arena(ex.Message));
- return false;
- }
- }
- /*
- * I need to have a table with a label of "BZ Bank" or something similar
- * Inside it will have variables: PlayerName, Money(bz bux), Timestamp(when it was last updated)
- * money uses a double
- */
- // If the code reaches here - there is no player on the bot list to add
- // and we are checking here to see if the player is stored on the bz database
- public void CheckDB(PublicPlayer StoredPlayer, Queue<EventArgs> q)
- {
- bool playerfound = FindPlayer(StoredPlayer);
- // if player isnt found we just make new one here
- if (!playerfound)
- {
- // Load player defaults
- q.Enqueue(msg.pm(StoredPlayer.PlayerName,"You do not have a profile stored. Any points attained will not be saved for this session."));
- }
- }
- private bool FindPlayer(PublicPlayer StoredPlayer)
- {
- // PlayerName is stored inside StoredPlayer.PlayerName
- // Money is in StoredPlayer.BZBux
- // open connection
- // search for player and get info - return true/false
- // If found update StoredPlayer with money
- // close connection
- return false;//just a placeholder
- }
- public void UpdatePlayerList(List<PublicPlayer> Pub_List)
- {
- Pub_List.ForEach(delegate(PublicPlayer p)
- {
- //find player and store updated info and update timestamp
- /* info to update
- p.PlayerName;
- p.BZBux;
- */
- });
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment