andrelcalad

Class GC Helper v1.0

Oct 14th, 2014
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.34 KB | None | 0 0
  1. <?php
  2. /*
  3. Class Name: GC Helper
  4. Functions: Adquire informações, Adquire informações dos itens, get char Information, Adquire informações do servidor, connecta com MSSQL Server, Troca o User Nick, Adiciona Novo Usuario, Bane Usuario, Deleta Usuario, Adiciona GM
  5. Author: Matheus Diniz
  6. Skype: mateus.diniz13
  7. Date: 01/10/2014
  8. */
  9. class GCHelper
  10. {
  11. //User information variables, don't change!
  12. var $NickName, $Login, $Ip, $Gp, $Cash, $Email, $LoginUID, $Password, $LastConnect, $Sex, $FirstLogin, $LastLogin, $Connecting, $Point;
  13.  
  14. //Item Information variables, don't change!
  15. var $itemID, $itemName, $itemDescription, $itemDuration, $itemChar, $itemType, $itemWeb, $itemPrice, $itemCash, $itemAttack, $itemDefence, $itemHP, $itemGem, $itemCrystal;
  16.  
  17. //Char information variables, don't change!
  18. var $charLogin, $charType, $charPromotion, $charExp, $charLevel, $charWin, $charLose;
  19.  
  20. //Server information variables, don't change!
  21. var $ServerUsersOn, $ServerName, $ServerMaxUsers, $ServerIP, $ServerPort;
  22.  
  23. //function to connect to the sql server
  24. public function connectToServer($Host,$User,$Password,$Database)
  25. {
  26. $con = @mssql_connect($Host,$User,$Password,$Database);
  27. $db = @mssql_select_db($Database,$con);
  28. if(!$con)
  29. die ("Unable to connect to the Server: ".$Host);
  30. if (!$db)
  31. die ("Cannot connect to the Database: ".$Database);
  32. }
  33. //function to get a specific user info
  34. public function getUserInfo($Login)
  35. {
  36. //Query to get all user information
  37. $queryUserInfo = mssql_query("SELECT users.Login, NickNames.nick, CashUsers.Cash, users.passwd, users.sex, users.firstLogin, users.LoginUID, users.lastLogin, users.lastConnect, users.gamePoint, users.IPAddress, users.Connecting, users.email FROM users LEFT JOIN NickNames on users.Login = NickNames.Login LEFT JOIN CashUsers ON CashUsers.Login = users.Login WHERE users.Login = '$Login'");
  38. $u = mssql_fetch_assoc($queryUserInfo);
  39. $this->NickName = $u['nick'];
  40. $this->Login = $u['Login'];
  41. $this->Ip = $u['IPAddress'];
  42. $this->Gp = $u['gamePoint'];
  43. $this->Cash = $u['Cash'];
  44. $this->Email = $u['email'];
  45. $this->LoginUID = $u['LoginUID'];
  46. $this->Password = $u['passwd'];
  47. $this->LastConnect = $u['lastConnect'];
  48. $this->Sex = $u['Sex'];
  49. $this->FirstLogin = $u['firstLogin'];
  50. $this->LastLogin = $u['lastLogin'];
  51. $this->Connecting = $u['Connecting'];
  52. $this->Point = $u['Point']; //Pontos de diário
  53. if(empty($this->NickName))
  54. $this->NickName = $this->Login;
  55. if(empty($this->Cash))
  56. $this->Cash = 0;
  57. switch($u['Connecting'])
  58. {
  59. case 0: $this->Connecting = "Offline";
  60. break;
  61. case 1: $this->Connecting = "Online";
  62. break;
  63. }
  64. }
  65. //get item info
  66. public function itemsInfo($Item)
  67. {
  68. $searchOp = is_numeric($Item) ? true : false;
  69. if($searchOp)
  70. {
  71. $queryItemInfo = mssql_query("SELECT GoodsID, GoodsName, Description, Duration, CharType, ItemType, ShowWeb, Price, Cash, Attack, Defence, HPInc, Gem, Crystal FROM GoodsInfoList WHERE GoodsID = $Item");
  72. $a = mssql_fetch_assoc($queryItemInfo);
  73. $this->itemID = $a['GoodsID'];
  74. $this->itemName = $a['GoodsName'];
  75. $this->itemDescription = $a['Description'];
  76. $this->itemDuration = $a['Duration'];
  77. $this->itemChar = $a['CharType'];
  78. $this->itemType = $a['itemType'];
  79. $this->itemWeb = $a['ShowWeb'];
  80. $this->itemPrice = $a['Price'];
  81. $this->itemCash = $a['Cash'];
  82. $this->itemAttack = $a['Attack'];
  83. $this->itemDefence = $a['Defence'];
  84. $this->itemHP = $a['HPInc'];
  85. $this->itemGem = $a['Gem'];
  86. $this->itemCrystal = $a['Crystal'];
  87. }else
  88. {
  89. $queryItemInfo = mssql_query("SELECT GoodsID, GoodsName, Description, Duration, CharType, ItemType, ShowWeb, Price, Cash, Attack, Defence, HPInc, Gem, Crystal FROM GoodsInfoList WHERE GoodsName ='$Item'");
  90. $a = mssql_fetch_assoc($queryItemInfo);
  91. $this->itemID = $a['GoodsID'];
  92. $this->itemName = $a['GoodsName']."<br>";
  93. $this->itemDescription = $a['Description'];
  94. $this->itemDuration = $a['Duration'];
  95. $this->itemChar = $a['CharType'];
  96. $this->itemType = $a['itemType'];
  97. $this->itemWeb = $a['ShowWeb'];
  98. $this->itemPrice = $a['Price'];
  99. $this->itemCash = $a['Cash'];
  100. $this->itemAttack = $a['Attack'];
  101. $this->itemDefence = $a['Defence'];
  102. $this->itemHP = $a['HPInc'];
  103. $this->itemGem = $a['Gem'];
  104. $this->itemCrystal = $a['Crystal'];
  105. }
  106. }
  107. //function to get a chracter info
  108. public function getCharacterInfo($Login,$CharType)
  109. {
  110. if(is_numeric($CharType))
  111. {
  112. $queryCharacterInfo = mssql_query("SELECT Login, CharType, Promotion, Exp, [Level], Win, Lose FROM Characters WHERE Login ='$Login' AND CharType=$CharType");
  113. $c = mssql_fetch_assoc($queryCharacterInfo);
  114. $this->charLogin = $c['Login'];
  115. $this->charPromotion = $c['Promotion'];
  116. $this->charExp = $c['Exp'];
  117. $this->charLevel = $c['Level'];
  118. $this->charWin = $c['Win'];
  119. $this->charLose = $c['Lose'];
  120. switch($CharType)
  121. {
  122. case 0: $this->charType = "Elesis"; break;
  123. case 1: $this->charType = "Lire"; break;
  124. case 2: $this->charType = "Arme"; break;
  125. case 3: $this->charType = "Lass"; break;
  126. case 4: $this->charType = "Ryan"; break;
  127. case 5: $this->charType = "Ronan"; break;
  128. case 6: $this->charType = "Amy"; break;
  129. case 7: $this->charType = "Jin"; break;
  130. case 8: $this->charType = "Sieghart"; break;
  131. default: $this->charType = "CharType not found"; break;
  132. }
  133. }else
  134. echo "Chartype must be a number";
  135. }
  136.  
  137. //function to get a server info
  138. public function getServerInfo($ServerName)
  139. {
  140. $queryServerInfo = mssql_query("SELECT UserNum, ServerIP, ServerPort, ServerName, MaxNum FROM ConnectStatusDB WHERE ServerName='$ServerName'");
  141. $p = mssql_fetch_assoc($queryServerInfo);
  142. $this->ServerUsersOn = $p['UserNum'];
  143. $this->ServerName = $p['ServerName'];
  144. $this->ServerMaxUsers = $p['MaxNum'];
  145. $this->ServerIP = $p['ServerIP'];
  146. $this->ServerPort = $p['ServerPort'];
  147. }
  148. //function to add new User
  149. public function addUser($Login,$Password, $Sex, $Email)
  150. {
  151. if($Sex==1 || $Sex ==0)
  152. {
  153. $EncryptPass = md5($Password);
  154. $queryAddUser = mssql_query("INSERT INTO users(Login,passwd,sex,email)VALUES('$Login','$EncryptPass','$Sex','$Email')");
  155. }else
  156. {
  157. echo "Please, insert a valid value";
  158. }
  159. }
  160. //function to addGM
  161. public function addGM($LoginGM)
  162. {
  163. $querySelectUser = mssql_query("SELECT * FROM users WHERE Login='$LoginGM'");
  164. if(mssql_num_rows($querySelectUser) >=1)
  165. {
  166. $s = mssql_fetch_assoc($querySelectUser);
  167. $LoginUID = $s['LoginUID'];
  168. $CheckLoginUID = mssql_query("SELECT * FROM UAGUserAuth WHERE LoginUID='$LoginUID'");
  169. if(mssql_num_rows($CheckLoginUID) >=1)
  170. {
  171. $updateUserStatus = mssql_query("UPDATE UAGUserAuth SET AuthLevel='3' WHERE LoginUID='$LoginUID'");
  172. }else
  173. {
  174. $addToDB = mssql_query("INSERT INTO UAGUserAuth(LoginUID,AuthLevel)VALUES('$LoginUID','3')");
  175. }
  176. }else
  177. {
  178. echo "Unable to add this user because it was not found on database";
  179. }
  180. }
  181. //function to ban user
  182. public function banUser($LoginUserBan)
  183. {
  184. $querySelectUser = mssql_query("SELECT * FROM users WHERE Login='$LoginUserBan'");
  185. if(mssql_num_rows($querySelectUser) >=1)
  186. {
  187. $s = mssql_fetch_assoc($querySelectUser);
  188. $LoginUID = $s['LoginUID'];
  189. $CheckLoginUID = mssql_query("SELECT * FROM UAGUserAuth WHERE LoginUID='$LoginUID'");
  190. if(mssql_num_rows($CheckLoginUID) >=1)
  191. {
  192. $updateUserStatus = mssql_query("UPDATE UAGUserAuth SET AuthLevel='-3' WHERE LoginUID='$LoginUID'");
  193. }else
  194. {
  195. $addToDB = mssql_query("INSERT INTO UAGUserAuth(LoginUID,AuthLevel)VALUES('$LoginUID','-3')");
  196. }
  197. }else
  198. {
  199. echo "Unable ban this user because it was not found on database";
  200. }
  201. }
  202. //function to delete user
  203. public function deleteUser($LoginDelUser)
  204. {
  205. $queryVerifyUserDelete = mssql_query("SELECT * FROM users WHERE Login='$LoginDelUser'");
  206. if(mssql_num_rows($queryVerifyUserDelete) >= 1)
  207. {
  208. $queryDeleteUser = mssql_query("DELETE FROM users WHERE Login='$LoginDelUser'");
  209. }else
  210. {
  211. echo "Unable delete user, because it was not found on database";
  212. }
  213. }
  214.  
  215. //function to change user nick
  216. public function alterNick($LoginNickChange,$newNick)
  217. {
  218. $queryVerifyUserNick = mssql_query("SELECT * FROM NickNames WHERE Login='$LoginNickChange'");
  219. if(mssql_num_rows($queryVerifyUserNick) >=1)
  220. {
  221. $updateUserNick = mssql_query("UPDATE NickNames SET Nick='$newNick' WHERE Login='$LoginNickChange'");
  222. }else
  223. {
  224. echo "Unable to change User Nick because Login was not found on database";
  225. }
  226. }
  227.  
  228. }
  229.  
  230. //Exemplos de como usar as class:
  231. //
  232. $gc = new GCHelper();
  233. //Connect to sql server
  234. $gc->connectToServer("MATEUS-PC\SQLEXPRESS,1433","sa","dark","gc_s2"); //Host, User, password, db name
  235.  
  236. //Get all infos of user(available infos are: NickName, Login, Ip, Gp, Cash, Email, LoginUID, Password, LastConnect, Sex, FirstLogin, LastLogin, Connecting, Point)
  237. $gc->getUserInfo("DarkHero");
  238.  
  239. $login = $gc->Login; //Show the login of user "DarkHero"
  240. //public function itemsInfo($Item)
  241.  
  242. $gc->itemsInfo(201030);// If you search for a number, then it will search for the item ID, otherwise, if you search for numbers and letters(or only letters) then it will search for the name of the item
  243.  
  244. $itemName = $gc->itemName; //Avaible infos are: itemID, itemName, itemDescription, itemDuration, itemChar, itemType, itemWeb, itemPrice, itemCash, itemAttack, itemDefence, itemHP, itemGem, itemCrystal
  245.  
  246. //get all char infos with login "DarkHero"
  247. $gc->getCharacterInfo("DarkHero","0"); //Login, Chartype
  248. $charLevel = $gc->charLevel; //Show the level of char with login is darkhero, and chartype is 0(available infos are: charLogin, charType, charPromotion, charExp, charLevel, charWin, charLose)
  249.  
  250. getServerInfo($ServerName)
  251. $gc->getServerInfo("DarkTuga"); //Get all infos of server with name "DarkTuga"(table ConnectStatusDB)
  252. $usersON = $gc->ServerName; //ServerName (available infos are: ServerUsersOn, ServerName, ServerMaxUsers, ServerIP, ServerPort)
  253.  
  254. //Add new user
  255. $gc->addUser("DarkHero","123",0,"[email protected]"); //Login, password, sex, email
  256.  
  257. //Add new GM
  258. $gc->addGM("DarkHero"); //Login
  259.  
  260. //change nick of an user
  261. $gc->alterNick("!Shade","darkhero"); //old nick, new nick
  262.  
  263.  
  264. //Ban an User
  265. $gc->banUser("MatheusDiniz")//Login
  266.  
  267. //delete an use
  268. $gc->deleteUser("Diniz"); //Login
Advertisement
Add Comment
Please, Sign In to add comment