· 10 years ago · Feb 19, 2016, 03:24 PM
1function SetDBName(){
2
3 $dbname = $DBName;
4 echo ("--------------DBName = ", $dbname, "-------------");
5
6 if (%DBName $= "SinglePlayer")
7 {
8 echo("Single Player Start=========Server Type = ", $dbname);
9 $dbname = "SinglePlayer.db";
10 $SqLite = new SqLiteObject(sqlite);
11 }
12 else if (%DBName $= "MultiPlayer")
13 {
14 echo("MultiPlayer Player Start=========Server Type = ", $dbname);
15 $dbname = "HostingDB.db";
16 $SqLite = new SqLiteObject(sqlite);
17 }
18 else if (%DBName $= " ")
19 {
20 echo("Dedicated Player Start=========Server Type = ", $dbname);
21 $dbname = "DedicatedDB.db";
22 $SqLite = new SqLiteObject(sqlite);
23 }
24
25}
26
27
28if ($SqLite == 0){
29 echo("ERROR: Failed to create SqLiteObject. $SqLiteObject aborted.");
30 return;
31}
32
33// open database
34if ($SqLite.openDatabase($dbname) == 0){
35 echo("ERROR: Failed to open database: " @ $dbname);
36 echo(" Ensure that the disk is not full or write protected. $SqLiteObject aborted.");
37 return;
38}
39
40//Reports errors on Query Fail
41function SqLite::onQueryFailed(%this, %error)
42{
43 echo ("$SqLite Query Error: " @ %error);
44}
45
46
47//Account TABLE functions
48function serverCmdValidateAccount(%client,%AccountName,%AccountPassword){
49 echo("--------serverCMDValidateAccount Start--------------");
50 echo("Username = ", %AccountName);
51 echo("Password = ", %AccountPassword);
52 %query = "CREATE TABLE Accounts (Name VARCHAR(20),password VARCHAR(20),CharName VARCHAR(20),Level INT(11))";
53 %result = $SqLite.query(%query, 0);
54 if (%result == 0)
55 {
56 // query failed
57 echo("Table already exists table creation aborted.");
58 //
59 //
60 //return;
61 }
62 if(%AccountName !$="" && %AccountPassword !$=""){
63 %query ="SELECT * FROM Accounts WHERE Name = \'" @ %AccountName @ "\' AND Password = \'" @ %AccountPassword @ "\'";
64 echo(%query);
65 %result = $SqLite.query(%query,0);
66 if ($SqLite.numRows(%result) > 0){
67 echo("If we are seeing this then the server has found a match for the Account name and Password");
68 $SqLite.clearResult(%result);
69 commandToClient(%client,'ValidateAccountResult','LOGEDIN');
70 serverCmdLoadZone(%client,%AccountName);
71 }else{
72 %query ="SELECT * FROM Accounts WHERE Name = \'" @ %AccountName @ "\'";
73 %result = $SqLite.query(%query,0);
74 echo(%query);
75 if($SqLite.numRows(%result) > 0){
76 echo("If we are seeing this then the server has found a match for the Account Name but not the Password");
77 $SqLite.clearResult(%result);
78 commandToClient(%client,'ValidateAccountResult','WRONGPASSWORD');
79 return("WRONGPASSWORD");
80 }else{
81 echo("If we are seeing this then the server was unable to find a match for the Account name and Password");
82 $SqLite.clearResult(%result);
83 commandToClient(%client,'ValidateAccountResult','NEW');
84 return("NEW");
85
86 }
87 }
88 }else{
89 commandToClient(%client,'ValidateAccountResult','NULL');
90 }
91}
92
93function serverCmdCreateAccount(%client,%AccountName,%AccountPassword,%CharName){
94 if(%CharName $=""){
95 %CharName ="DefaultPlayer";
96 }
97 %query ="INSERT INTO Accounts VALUES (\'" @ %AccountName @ "\',\'" @ %AccountPassword @ "\',\'"@%CharName@"\',\'1\')";
98 echo(%query);
99 %result = $SqLite.query(%query,0);
100 if(%result != 0){
101 echo("If we are seeing this then the server was able to insert the Account name, Password and CharName");
102 $SqLite.clearResult(%result);
103 commandToClient(%client,'ValidateAccountResult','ACCOUNTCREATED');
104 }else{
105 echo("If we are seeing this then the server was not able to insert the Account name, Password and CharName");
106 $SqLite.clearResult(%result);
107 commandToClient(%client,'ValidateAccountResult','FALSE');
108 }
109
110}
111
112function getPlayerName(%CharName){
113 %query = "SELECT * from Accounts WHERE Name = \'"@%name@"\'";
114 echo(%query);
115 %result = $SqLite.query(%query,0);
116 echo(%result);
117 if(%result){
118 %CharName = $SqLite.getColumn(%result, "CharName");
119 $SqLite.clearResult(%result);
120 return(%CharName);
121 }else{
122 echo("Uhoh! This player has no Character Name,Setting Default Name to Player");
123 return("Player"); //Well we gotta make 'em somethin now don't we
124 }
125}
126
127SetDBName();