Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Class Name: GC Helper
- 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
- Author: Matheus Diniz
- Email: [email protected]
- Skype: mateus.diniz13
- Date: 01/10/2014
- */
- class GCHelper
- {
- //User information variables, don't change!
- var $NickName, $Login, $Ip, $Gp, $Cash, $Email, $LoginUID, $Password, $LastConnect, $Sex, $FirstLogin, $LastLogin, $Connecting, $Point;
- //Item Information variables, don't change!
- var $itemID, $itemName, $itemDescription, $itemDuration, $itemChar, $itemType, $itemWeb, $itemPrice, $itemCash, $itemAttack, $itemDefence, $itemHP, $itemGem, $itemCrystal;
- //Char information variables, don't change!
- var $charLogin, $charType, $charPromotion, $charExp, $charLevel, $charWin, $charLose;
- //Server information variables, don't change!
- var $ServerUsersOn, $ServerName, $ServerMaxUsers, $ServerIP, $ServerPort;
- //function to connect to the sql server
- public function connectToServer($Host,$User,$Password,$Database)
- {
- $con = @mssql_connect($Host,$User,$Password,$Database);
- $db = @mssql_select_db($Database,$con);
- if(!$con)
- die ("Unable to connect to the Server: ".$Host);
- if (!$db)
- die ("Cannot connect to the Database: ".$Database);
- }
- //function to get a specific user info
- public function getUserInfo($Login)
- {
- //Query to get all user information
- $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'");
- $u = mssql_fetch_assoc($queryUserInfo);
- $this->NickName = $u['nick'];
- $this->Login = $u['Login'];
- $this->Ip = $u['IPAddress'];
- $this->Gp = $u['gamePoint'];
- $this->Cash = $u['Cash'];
- $this->Email = $u['email'];
- $this->LoginUID = $u['LoginUID'];
- $this->Password = $u['passwd'];
- $this->LastConnect = $u['lastConnect'];
- $this->Sex = $u['Sex'];
- $this->FirstLogin = $u['firstLogin'];
- $this->LastLogin = $u['lastLogin'];
- $this->Connecting = $u['Connecting'];
- $this->Point = $u['Point']; //Pontos de diário
- if(empty($this->NickName))
- $this->NickName = $this->Login;
- if(empty($this->Cash))
- $this->Cash = 0;
- switch($u['Connecting'])
- {
- case 0: $this->Connecting = "Offline";
- break;
- case 1: $this->Connecting = "Online";
- break;
- }
- }
- //get item info
- public function itemsInfo($Item)
- {
- $searchOp = is_numeric($Item) ? true : false;
- if($searchOp)
- {
- $queryItemInfo = mssql_query("SELECT GoodsID, GoodsName, Description, Duration, CharType, ItemType, ShowWeb, Price, Cash, Attack, Defence, HPInc, Gem, Crystal FROM GoodsInfoList WHERE GoodsID = $Item");
- $a = mssql_fetch_assoc($queryItemInfo);
- $this->itemID = $a['GoodsID'];
- $this->itemName = $a['GoodsName'];
- $this->itemDescription = $a['Description'];
- $this->itemDuration = $a['Duration'];
- $this->itemChar = $a['CharType'];
- $this->itemType = $a['itemType'];
- $this->itemWeb = $a['ShowWeb'];
- $this->itemPrice = $a['Price'];
- $this->itemCash = $a['Cash'];
- $this->itemAttack = $a['Attack'];
- $this->itemDefence = $a['Defence'];
- $this->itemHP = $a['HPInc'];
- $this->itemGem = $a['Gem'];
- $this->itemCrystal = $a['Crystal'];
- }else
- {
- $queryItemInfo = mssql_query("SELECT GoodsID, GoodsName, Description, Duration, CharType, ItemType, ShowWeb, Price, Cash, Attack, Defence, HPInc, Gem, Crystal FROM GoodsInfoList WHERE GoodsName ='$Item'");
- $a = mssql_fetch_assoc($queryItemInfo);
- $this->itemID = $a['GoodsID'];
- $this->itemName = $a['GoodsName']."<br>";
- $this->itemDescription = $a['Description'];
- $this->itemDuration = $a['Duration'];
- $this->itemChar = $a['CharType'];
- $this->itemType = $a['itemType'];
- $this->itemWeb = $a['ShowWeb'];
- $this->itemPrice = $a['Price'];
- $this->itemCash = $a['Cash'];
- $this->itemAttack = $a['Attack'];
- $this->itemDefence = $a['Defence'];
- $this->itemHP = $a['HPInc'];
- $this->itemGem = $a['Gem'];
- $this->itemCrystal = $a['Crystal'];
- }
- }
- //function to get a chracter info
- public function getCharacterInfo($Login,$CharType)
- {
- if(is_numeric($CharType))
- {
- $queryCharacterInfo = mssql_query("SELECT Login, CharType, Promotion, Exp, [Level], Win, Lose FROM Characters WHERE Login ='$Login' AND CharType=$CharType");
- $c = mssql_fetch_assoc($queryCharacterInfo);
- $this->charLogin = $c['Login'];
- $this->charPromotion = $c['Promotion'];
- $this->charExp = $c['Exp'];
- $this->charLevel = $c['Level'];
- $this->charWin = $c['Win'];
- $this->charLose = $c['Lose'];
- switch($CharType)
- {
- case 0: $this->charType = "Elesis"; break;
- case 1: $this->charType = "Lire"; break;
- case 2: $this->charType = "Arme"; break;
- case 3: $this->charType = "Lass"; break;
- case 4: $this->charType = "Ryan"; break;
- case 5: $this->charType = "Ronan"; break;
- case 6: $this->charType = "Amy"; break;
- case 7: $this->charType = "Jin"; break;
- case 8: $this->charType = "Sieghart"; break;
- default: $this->charType = "CharType not found"; break;
- }
- }else
- echo "Chartype must be a number";
- }
- //function to get a server info
- public function getServerInfo($ServerName)
- {
- $queryServerInfo = mssql_query("SELECT UserNum, ServerIP, ServerPort, ServerName, MaxNum FROM ConnectStatusDB WHERE ServerName='$ServerName'");
- $p = mssql_fetch_assoc($queryServerInfo);
- $this->ServerUsersOn = $p['UserNum'];
- $this->ServerName = $p['ServerName'];
- $this->ServerMaxUsers = $p['MaxNum'];
- $this->ServerIP = $p['ServerIP'];
- $this->ServerPort = $p['ServerPort'];
- }
- //function to add new User
- public function addUser($Login,$Password, $Sex, $Email)
- {
- if($Sex==1 || $Sex ==0)
- {
- $EncryptPass = md5($Password);
- $queryAddUser = mssql_query("INSERT INTO users(Login,passwd,sex,email)VALUES('$Login','$EncryptPass','$Sex','$Email')");
- }else
- {
- echo "Please, insert a valid value";
- }
- }
- //function to addGM
- public function addGM($LoginGM)
- {
- $querySelectUser = mssql_query("SELECT * FROM users WHERE Login='$LoginGM'");
- if(mssql_num_rows($querySelectUser) >=1)
- {
- $s = mssql_fetch_assoc($querySelectUser);
- $LoginUID = $s['LoginUID'];
- $CheckLoginUID = mssql_query("SELECT * FROM UAGUserAuth WHERE LoginUID='$LoginUID'");
- if(mssql_num_rows($CheckLoginUID) >=1)
- {
- $updateUserStatus = mssql_query("UPDATE UAGUserAuth SET AuthLevel='3' WHERE LoginUID='$LoginUID'");
- }else
- {
- $addToDB = mssql_query("INSERT INTO UAGUserAuth(LoginUID,AuthLevel)VALUES('$LoginUID','3')");
- }
- }else
- {
- echo "Unable to add this user because it was not found on database";
- }
- }
- //function to ban user
- public function banUser($LoginUserBan)
- {
- $querySelectUser = mssql_query("SELECT * FROM users WHERE Login='$LoginUserBan'");
- if(mssql_num_rows($querySelectUser) >=1)
- {
- $s = mssql_fetch_assoc($querySelectUser);
- $LoginUID = $s['LoginUID'];
- $CheckLoginUID = mssql_query("SELECT * FROM UAGUserAuth WHERE LoginUID='$LoginUID'");
- if(mssql_num_rows($CheckLoginUID) >=1)
- {
- $updateUserStatus = mssql_query("UPDATE UAGUserAuth SET AuthLevel='-3' WHERE LoginUID='$LoginUID'");
- }else
- {
- $addToDB = mssql_query("INSERT INTO UAGUserAuth(LoginUID,AuthLevel)VALUES('$LoginUID','-3')");
- }
- }else
- {
- echo "Unable ban this user because it was not found on database";
- }
- }
- //function to delete user
- public function deleteUser($LoginDelUser)
- {
- $queryVerifyUserDelete = mssql_query("SELECT * FROM users WHERE Login='$LoginDelUser'");
- if(mssql_num_rows($queryVerifyUserDelete) >= 1)
- {
- $queryDeleteUser = mssql_query("DELETE FROM users WHERE Login='$LoginDelUser'");
- }else
- {
- echo "Unable delete user, because it was not found on database";
- }
- }
- //function to change user nick
- public function alterNick($LoginNickChange,$newNick)
- {
- $queryVerifyUserNick = mssql_query("SELECT * FROM NickNames WHERE Login='$LoginNickChange'");
- if(mssql_num_rows($queryVerifyUserNick) >=1)
- {
- $updateUserNick = mssql_query("UPDATE NickNames SET Nick='$newNick' WHERE Login='$LoginNickChange'");
- }else
- {
- echo "Unable to change User Nick because Login was not found on database";
- }
- }
- }
- //Exemplos de como usar as class:
- //
- $gc = new GCHelper();
- //Connect to sql server
- $gc->connectToServer("MATEUS-PC\SQLEXPRESS,1433","sa","dark","gc_s2"); //Host, User, password, db name
- //Get all infos of user(available infos are: NickName, Login, Ip, Gp, Cash, Email, LoginUID, Password, LastConnect, Sex, FirstLogin, LastLogin, Connecting, Point)
- $gc->getUserInfo("DarkHero");
- $login = $gc->Login; //Show the login of user "DarkHero"
- //public function itemsInfo($Item)
- $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
- $itemName = $gc->itemName; //Avaible infos are: itemID, itemName, itemDescription, itemDuration, itemChar, itemType, itemWeb, itemPrice, itemCash, itemAttack, itemDefence, itemHP, itemGem, itemCrystal
- //get all char infos with login "DarkHero"
- $gc->getCharacterInfo("DarkHero","0"); //Login, Chartype
- $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)
- getServerInfo($ServerName)
- $gc->getServerInfo("DarkTuga"); //Get all infos of server with name "DarkTuga"(table ConnectStatusDB)
- $usersON = $gc->ServerName; //ServerName (available infos are: ServerUsersOn, ServerName, ServerMaxUsers, ServerIP, ServerPort)
- //Add new user
- $gc->addUser("DarkHero","123",0,"[email protected]"); //Login, password, sex, email
- //Add new GM
- $gc->addGM("DarkHero"); //Login
- //change nick of an user
- $gc->alterNick("!Shade","darkhero"); //old nick, new nick
- //Ban an User
- $gc->banUser("MatheusDiniz")//Login
- //delete an use
- $gc->deleteUser("Diniz"); //Login
Advertisement
Add Comment
Please, Sign In to add comment