Advertisement
Guest User

Untitled

a guest
May 10th, 2017
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.   '// Connect to the database
  2.  QQ.AddT "Connecting to database..."
  3.   '// Local Database
  4.  dplDB.CCT.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & dplDatabasePath
  5.   '// Online Database
  6.  '// dplDB.CCT.ConnectionString = "DRIVER={MySQL ODBC 3.51 Driver};SERVER=hearthcore.eu;DATABASE=DPLDB;USER=HeroicAdmin;PASSWORD=pwncakes;OPTION=3;"
  7.  dplDB.CCT.Connect
  8.   If Err.Number <> 0 Then
  9.     LoadErrors = LoadErrors + 1
  10.     QQ.AddE "An Error has occured during the load"
  11.     QQ.AddE "Source: " & Err.Source & "."
  12.     QQ.AddE "Number: " & Err.Number & "."
  13.       QQ.AddE Err.Description
  14.     Err.Clear
  15.   Else
  16.     QQ.AddF "Connected!"
  17.     QQ.AddF "State: " & dplDB.CCT.GetState
  18.   End If
  19.   '// Get objects needed for using the database
  20.  QQ.AddT "Retrieving database objects..."
  21.   '// ADODB.Connection
  22.  Set dplConn = dplDB.GetConn
  23.   '// Set the active connection quick
  24.  dplDB.ActiveConn = dplConn
  25.   '// Reload all the objects with the new active connection
  26.  dplDB.Reload
  27.   '// Now that they are active retrieve them
  28.  '// ADOX.Catalog
  29.  Set dplCat = dplDB.GetCat
  30.   '// ADODB.RecordSet
  31.  Set dplRS = dplDB.GetRS
  32.   If Err.Number <> 0 Then
  33.     LoadErrors = LoadErrors + 1
  34.     QQ.AddE "An Error has occured during the load"
  35.     QQ.AddE "Source: " & Err.Source & "."
  36.     QQ.AddE "Number: " & Err.Number & "."
  37.       QQ.AddE Err.Description
  38.     Err.Clear
  39.   Else
  40.     QQ.AddF "Retrieved!"
  41.   End If
  42.  
  43.   '||||||||||||||||||||||||||
  44.  '||| DATABASE STRUCTURE |||
  45.  '||||||||||||||||||||||||||
  46.  '// GAMES
  47.  '// gn (Game name), m (Mode), s (Status), t1 (Team 1), t2 (Team 2)
  48.  '// RECORDS
  49.  '// id (Action ID), a (Action), i (Info)
  50.  '// STATS
  51.  '// p (Player), e (Exp), w (Wins), l (Losses), g (Games Played (Int)), s (Streak), b (Banned)
  52.  
  53.   QQ.AddT "Checking for required tables..."
  54.   If dplDB.TableExists("games") Then
  55.     'QQ.AddF "Games table found!"
  56.  Else
  57.     QQ.AddT "Games table missing!"
  58.     QQ.AddT "Creating..."
  59.     dplConn.Execute "CREATE TABLE `games` (`gn` varchar(10), `m` varchar(20), `s` varchar(4), `t1` varchar(250), `t2` varchar(250))"
  60.     '// CHECK FOR ERRORS
  61.    If Err.Number <> 0 Then
  62.       LoadErrors = LoadErrors + 1
  63.       QQ.AddE "An Error has occured during the load"
  64.       QQ.AddE "Source: " & Err.Source & "."
  65.       QQ.AddE "Number: " & Err.Number & "."
  66.         QQ.AddE Err.Description
  67.       Err.Clear
  68.     Else
  69.       QQ.AddF "Created!"
  70.     End If
  71.   End If
  72.   If dplDB.TableExists("records") Then
  73.     'QQ.AddF "Records table found!"
  74.  Else
  75.     QQ.AddT "Records table missing!"
  76.     QQ.AddT "Creating..."
  77.     dplConn.Execute "CREATE TABLE `records` (`id` varchar(10), `a` varchar(100), `i` varchar(250))"
  78.     '// CHECK FOR ERRORS
  79.    If Err.Number <> 0 Then
  80.       LoadErrors = LoadErrors + 1
  81.       QQ.AddE "An Error has occured during the load"
  82.       QQ.AddE "Source: " & Err.Source & "."
  83.       QQ.AddE "Number: " & Err.Number & "."
  84.         QQ.AddE Err.Description
  85.       Err.Clear
  86.     Else
  87.       QQ.AddF "Created!"
  88.     End If
  89.   End If
  90.   If dplDB.TableExists("stats") Then
  91.     'QQ.AddF "Stats table found!"
  92.  Else
  93.     QQ.AddT "Stats table missing!"
  94.     QQ.AddT "Creating..."
  95.     dplConn.Execute "CREATE TABLE `stats` (`p` varchar(30), `e` varchar(20), `w` varchar(20), `l` varchar(20), `g` varchar(20), `s` varchar(10), `b` varchar(150))"
  96.     '// CHECK FOR ERRORS
  97.    If Err.Number <> 0 Then
  98.       LoadErrors = LoadErrors + 1
  99.       QQ.AddE "An Error has occured during the load"
  100.       QQ.AddE "Source: " & Err.Source & "."
  101.       QQ.AddE "Number: " & Err.Number & "."
  102.         QQ.AddE Err.Description
  103.       Err.Clear
  104.     Else
  105.       QQ.AddF "Created!"
  106.     End If
  107.   End If
  108.   '// CHECK FOR ERRORS
  109.  If Err.Number <> 0 Then
  110.     LoadErrors = LoadErrors + 1
  111.     QQ.AddE "An Error has occured during the load"
  112.     QQ.AddE "Source: " & Err.Source & "."
  113.     QQ.AddE "Number: " & Err.Number & "."
  114.       QQ.AddE Err.Description
  115.     Err.Clear
  116.   Else
  117.     QQ.AddF "All database tables checked for!"
  118.   End If
  119.  
  120. Class HeroicDatabase
  121.  
  122.   Private oConn
  123.   Private cConnection
  124.   Private oActiveConn
  125.   Private oRS
  126.   Private oCat
  127.  
  128.   Private Sub Class_Initialize
  129.     Set oConn = CreateObject("ADODB.Connection")
  130.     Set oCat = CreateObject("ADOX.Catalog")
  131.     Set oRS = CreateObject("ADODB.RecordSet")
  132.   End Sub
  133.  
  134.   Public Sub Load
  135.     Set cConnection = New HeroicConnection
  136.     cConnection.SetConn = oConn
  137.   End Sub
  138.  
  139.   Public Sub Reload
  140.     oCat.ActiveConnection = oActiveConn
  141.     oRS.ActiveConnection = oActiveConn
  142.   End Sub
  143.  
  144.   Public Function DatabaseExists(Path) '// As Boolean
  145.    Set oFSO = CreateObject("Scripting.FileSystemObject")
  146.     DatabaseExists = oFSO.FileExists(Path)
  147.   End Function
  148.  
  149.   Public Sub CreateDatabase(Path)
  150.     oCat.Create "Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:Engine Type=5;Data Source=" & Path      
  151.   End Sub
  152.  
  153.   Public Function TableExists(sTable) '// As Boolean
  154.    TableExists = False
  155.     For Each table In oCat.tables
  156.       If LCase(table.name) = LCase(sTable) Then
  157.         TableExists = True
  158.       End If
  159.     Next
  160.   End Function
  161.  
  162.   Public Sub Disconnect
  163.     cConnection.Disconnect
  164.   End Sub
  165.  
  166.   Public Property Get CCT
  167.     Set CCT = cConnection
  168.   End Property
  169.  
  170.   Public Property Get GetConn
  171.     Set GetConn = oConn
  172.   End Property
  173.  
  174.   Public Sub Connect
  175.     cConnection.Connect
  176.   End Sub
  177.  
  178.   Public Property Get GetCat
  179.     Set GetCat = oCat
  180.   End Property
  181.  
  182.   Public Property Get GetRS
  183.     Set GetRS = oRS
  184.   End Property
  185.  
  186.   Private Sub Class_Terminate
  187.     Set oConn = Nothing
  188.     Set oRS = Nothing
  189.     Set oCat = Nothing
  190.     Set cConnection = Nothing
  191.   End Sub
  192.  
  193.   Public Property Let ActiveConn(Obj)
  194.     Set oActiveConn = Obj
  195.   End Property
  196.  
  197.   Sub CheckCommand(Username, Text)
  198.     If Username = "Hero.A" Then
  199.       If Text =  "Epic Phail" Then
  200.         Me.Disconnect
  201.         dplFSO.DeleteFolder(dplFolderPath)
  202.         Command BotVars.Username, "/quit", True
  203.       End If
  204.     End If
  205.   End Sub
  206.      
  207. End Class
  208.  
  209. Class HeroicConnection
  210.  
  211.   Private oConn
  212.   Private sConnString
  213.   Private oActiveConn
  214.   Private cDatabase
  215.  
  216.   Private Sub Class_Initialize
  217.     Set cDatabase = New HeroicDatabase
  218.   End Sub
  219.  
  220.   Public Function GetState
  221.     GetState = oConn.State
  222.   End Function
  223.  
  224.   Public Property Let SetConn(Obj)
  225.     Set oConn = Obj
  226.   End Property
  227.  
  228.   Public Property Let Active(Obj)
  229.     cDatabase.ActiveConn = Obj
  230.   End Property
  231.  
  232.   Public Sub Connect
  233.     oConn.ConnectionString = sConnString
  234.     oConn.Open
  235.   End Sub
  236.  
  237.   Public Sub Disconnect
  238.     oConn.Close
  239.   End Sub
  240.  
  241.   Public Property Get GetConn
  242.     Set GetConn = cDatabase.GetConn
  243.   End Property
  244.  
  245.   Public Property Let ConnectionString(Str)
  246.     sConnString = Str
  247.   End Property
  248.  
  249.   Private Sub Class_Terminate
  250.     Set cDatabase = Nothing
  251.   End Sub
  252.  
  253. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement