Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function SetDBName(){
- $dbname = $DBName;
- echo ("--------------DBName = ", $dbname, "-------------");
- if (%DBName $= "SinglePlayer")
- {
- echo("Single Player Start=========Server Type = ", $dbname);
- $dbname = "SinglePlayer.db";
- $SqLite = new SqLiteObject(sqlite);
- }
- else if (%DBName $= "MultiPlayer")
- {
- echo("MultiPlayer Player Start=========Server Type = ", $dbname);
- $dbname = "HostingDB.db";
- $SqLite = new SqLiteObject(sqlite);
- }
- else if (%DBName $= " ")
- {
- echo("Dedicated Player Start=========Server Type = ", $dbname);
- $dbname = "DedicatedDB.db";
- $SqLite = new SqLiteObject(sqlite);
- }
- }
- if ($SqLite == 0){
- echo("ERROR: Failed to create SqLiteObject. $SqLiteObject aborted.");
- return;
- }
- // open database
- if ($SqLite.openDatabase($dbname) == 0){
- echo("ERROR: Failed to open database: " @ $dbname);
- echo(" Ensure that the disk is not full or write protected. $SqLiteObject aborted.");
- return;
- }
- //Reports errors on Query Fail
- function SqLite::onQueryFailed(%this, %error)
- {
- echo ("$SqLite Query Error: " @ %error);
- }
- //Account TABLE functions
- function serverCmdValidateAccount(%client,%AccountName,%AccountPassword){
- echo("--------serverCMDValidateAccount Start--------------");
- echo("Username = ", %AccountName);
- echo("Password = ", %AccountPassword);
- %query = "CREATE TABLE Accounts (Name VARCHAR(20),password VARCHAR(20),CharName VARCHAR(20),Level INT(11))";
- %result = $SqLite.query(%query, 0);
- if (%result == 0)
- {
- // query failed
- echo("Table already exists table creation aborted.");
- //
- //
- //return;
- }
- if(%AccountName !$="" && %AccountPassword !$=""){
- %query ="SELECT * FROM Accounts WHERE Name = \'" @ %AccountName @ "\' AND Password = \'" @ %AccountPassword @ "\'";
- echo(%query);
- %result = $SqLite.query(%query,0);
- if ($SqLite.numRows(%result) > 0){
- echo("If we are seeing this then the server has found a match for the Account name and Password");
- $SqLite.clearResult(%result);
- commandToClient(%client,'ValidateAccountResult','LOGEDIN');
- serverCmdLoadZone(%client,%AccountName);
- }else{
- %query ="SELECT * FROM Accounts WHERE Name = \'" @ %AccountName @ "\'";
- %result = $SqLite.query(%query,0);
- echo(%query);
- if($SqLite.numRows(%result) > 0){
- echo("If we are seeing this then the server has found a match for the Account Name but not the Password");
- $SqLite.clearResult(%result);
- commandToClient(%client,'ValidateAccountResult','WRONGPASSWORD');
- return("WRONGPASSWORD");
- }else{
- echo("If we are seeing this then the server was unable to find a match for the Account name and Password");
- $SqLite.clearResult(%result);
- commandToClient(%client,'ValidateAccountResult','NEW');
- return("NEW");
- }
- }
- }else{
- commandToClient(%client,'ValidateAccountResult','NULL');
- }
- }
- function serverCmdCreateAccount(%client,%AccountName,%AccountPassword,%CharName){
- if(%CharName $=""){
- %CharName ="DefaultPlayer";
- }
- %query ="INSERT INTO Accounts VALUES (\'" @ %AccountName @ "\',\'" @ %AccountPassword @ "\',\'"@%CharName@"\',\'1\')";
- echo(%query);
- %result = $SqLite.query(%query,0);
- if(%result != 0){
- echo("If we are seeing this then the server was able to insert the Account name, Password and CharName");
- $SqLite.clearResult(%result);
- commandToClient(%client,'ValidateAccountResult','ACCOUNTCREATED');
- }else{
- echo("If we are seeing this then the server was not able to insert the Account name, Password and CharName");
- $SqLite.clearResult(%result);
- commandToClient(%client,'ValidateAccountResult','FALSE');
- }
- }
- function getPlayerName(%CharName){
- %query = "SELECT * from Accounts WHERE Name = \'"@%name@"\'";
- echo(%query);
- %result = $SqLite.query(%query,0);
- echo(%result);
- if(%result){
- %CharName = $SqLite.getColumn(%result, "CharName");
- $SqLite.clearResult(%result);
- return(%CharName);
- }else{
- echo("Uhoh! This player has no Character Name,Setting Default Name to Player");
- return("Player"); //Well we gotta make 'em somethin now don't we
- }
- }
- SetDBName();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement