Advertisement
Guest User

Untitled

a guest
Feb 17th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.05 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Runtime.Serialization.Formatters.Binary;
  4. using ADODB;
  5.  
  6. namespace Server
  7. {
  8. class Database
  9. {
  10. public bool AccountExist(int index,string username)
  11. {
  12. var db = Globals.mysql.DB_RS;
  13. {
  14. db.Open("SELECT * FROM accounts WHERE Username='"+username+"'", Globals.mysql.DB_CONN, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic);
  15.  
  16. if(db.EOF)
  17. {
  18. SocketSend.SendAlertMsg(index,"Username does not exists! Please try again.");
  19. db.Close();
  20. return false;
  21. }
  22. else
  23. {
  24. db.Close();
  25. return true;
  26. }
  27.  
  28. }
  29. }
  30.  
  31.  
  32. public bool PasswordOK(int index,string username,string password)
  33. {
  34. var db = Globals.mysql.DB_RS;
  35. {
  36. db.Open("SELECT Id FROM accounts WHERE Username='" + username + "' and Password='" + password + "'", Globals.mysql.DB_CONN, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic);
  37.  
  38. if (db.EOF)
  39. {
  40. SocketSend.SendAlertMsg(index, "Password does not match! Please try again.");
  41. db.Close();
  42. return false;
  43. }
  44. else
  45. {
  46. db.Close();
  47. SocketSend.SendAlertMsg(index, "You have successfully logged in.");
  48.  
  49. return true;
  50. }
  51.  
  52. }
  53. }
  54.  
  55. // ADD: Create Character
  56. // ADD: Delete Character
  57.  
  58. public void LoadPlayer(int index, string username)
  59. {
  60. var db = Globals.mysql.DB_RS;
  61. {
  62. db.Open("SELECT * FROM accounts WHERE Username='" + username + "'", Globals.mysql.DB_CONN, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic);
  63.  
  64. // Account
  65. Globals.player[index].ID = db.Fields["ID"].Value;
  66. Globals.player[index].Username = db.Fields["Username"].Value;
  67.  
  68. Console.WriteLine("Username: " + Globals.player[index].Username);
  69. Console.WriteLine("ID: " + Globals.player[index].ID);
  70. //// Position
  71. //Globals.player[index].posX = db.Fields["X"].Value;
  72. //Globals.player[index].posY = db.Fields["Y"].Value;
  73. //Globals.player[index].posZ = db.Fields["Z"].Value;
  74.  
  75.  
  76. db.Close(); // Close Connection
  77. }
  78. }
  79.  
  80. public void LoadAcc(int index)
  81. {
  82. var db = Globals.mysql.DB_RS;
  83. {
  84. db.Open("SELECT * FROM characters WHERE OwnerID='OwnerID'", Globals.mysql.DB_CONN, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic);
  85.  
  86. // Account
  87. Globals.player[index].OwnerID = db.Fields["OwnerID"].Value;
  88.  
  89.  
  90. Console.WriteLine("OwnerID:" + Globals.player[index].OwnerID);
  91.  
  92. db.Close(); // Close Connection
  93. }
  94. }
  95.  
  96. public void SavePlayer(int index)
  97. {
  98.  
  99. var db = Globals.mysql.DB_RS;
  100. {
  101. db.Open("SELECT * FROM accounts WHERE Username='" + Globals.player[index].Username + "'", Globals.mysql.DB_CONN, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic);
  102.  
  103. // Position
  104. db.Fields["X"].Value = Globals.player[index].posX;
  105. db.Fields["Y"].Value = Globals.player[index].posY;
  106. db.Fields["Z"].Value = Globals.player[index].posZ;
  107. db.Update(); // Update Data
  108. db.Close(); // Close Connection
  109. }
  110. //Console.WriteLine("SAVING: " + Globals.player[index].Username);
  111.  
  112. }
  113. }
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement