/
fB_DB.php
327 lines (313 loc) · 13.2 KB
/
fB_DB.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
<?php
$_SESSION['vDataDB'] = Parser_SQlite_Connect(PARSER_SQLITE);
$_SESSION['vDataStoreDB'] = Parser_SQlite_Connect(DATASTORE_SQLITE);
$_SESSION['vRewardStoreDB'] = Parser_SQlite_Connect(REWARDSTORE_SQLITE);
// ------------------------------------------------------------------------------
// Units_GetUnitByName get unit by Name
// ------------------------------------------------------------------------------
function Units_GetUnitByName($vName, $vAllInfo = false)
{
if ($vAllInfo)
{
$vSQL = 'select * from units where name="' . $vName . '"';
}
else
{
$vSQL = "select * from units where field in ('name','type','code','buyable','className','iconurl','market','cash','cost','subtype','growTime','coinYield','action','limitedEnd','requiredLevel','crop','sizeX','sizeY','plantXp','masterymax','license','realname','desc') and name='$vName'";
}
$vResult = @$_SESSION['vDataDB']->query($vSQL);
while ($vRow = $vResult->fetchArray(SQLITE3_ASSOC))
{
$vReturn[$vRow['field']] = $vRow['content'];
}
return(@$vReturn);
}
// ------------------------------------------------------------------------------
// Units_GetUnitByCode get unit by Name
// ------------------------------------------------------------------------------
function Units_GetUnitByCode($vCode, $vAllInfo = false)
{
return(Units_GetUnitByName(Units_GetNameByCode($vCode), $vAllInfo));
}
// ------------------------------------------------------------------------------
// Units_GetRealnameByName
// ------------------------------------------------------------------------------
function Units_GetRealnameByName($vName)
{
$vSQL = 'select content from units where name="' . $vName . '" and field="realname"';
$vResult = $_SESSION['vDataDB']->querySingle($vSQL);
return($vResult === false?$vName:$vResult);
}
// ------------------------------------------------------------------------------
// Units_GetNameByRealname
// ------------------------------------------------------------------------------
function Units_GetNameByRealname($vRealName)
{
$vSQL = 'select name from units where content="' . $vName . '" and field="realname"';
$vResult = $_SESSION['vDataDB']->querySingle($vSQL);
return($vResult === false?$vName:$vResult);
}
// ------------------------------------------------------------------------------
// Units_GetCodeByName
// ------------------------------------------------------------------------------
function Units_GetCodeByName($vName)
{
$vSQL = 'select content from units where name="' . $vName . '" and field="code"';
$vResult = $_SESSION['vDataDB']->querySingle($vSQL);
return($vResult === false?$vName:$vResult);
}
// ------------------------------------------------------------------------------
// Units_GetNameByCode
// ------------------------------------------------------------------------------
function Units_GetNameByCode($vCode)
{
$vSQL = 'select name from units where content="' . $vCode . '" and field="code"';
$vResult = $_SESSION['vDataDB']->querySingle($vSQL);
return($vResult === false?$vCode:$vResult);
}
// ------------------------------------------------------------------------------
// Units_GetRealnameByCode
// ------------------------------------------------------------------------------
function Units_GetRealnameByCode($vCode)
{
$vSQL = 'select content from units where field="realname" and name in (select name from units where content="' . $vCode . '" and field="code")';
$vResult = $_SESSION['vDataDB']->querySingle($vSQL);
return($vResult === false?$vCode:$vResult);
}
// ------------------------------------------------------------------------------
// Units_GetAll get all units
// ------------------------------------------------------------------------------
function Units_GetAll($vAllInfo = false)
{
if ($vAllInfo)
{
$vSQL = 'select * from units';
}
else
{
$vSQL = "select * from units where field in ('name','type','code','buyable','className','iconurl','market','cash','cost','subtype','growTime','coinYield','action','limitedEnd','requiredLevel','crop','sizeX','sizeY','plantXp','masterymax','license','realname','desc')";
}
$vResult = @$_SESSION['vDataDB']->query($vSQL);
while ($vRow = @$vResult->fetchArray(SQLITE3_ASSOC))
{
$vReturn[$vRow['name']][$vRow['field']] = $vRow['content'];
}
return($vReturn);
}
// ------------------------------------------------------------------------------
// Units_GetByType get all units of type $vType
// ------------------------------------------------------------------------------
function Units_GetByType($vType, $vAllInfo = false)
{
if ($vAllInfo)
{
$vSQL = 'select * from units where name in (select name from units where field="type" and content="' . $vType . '")';
}
else
{
$vSQL = "select * from units where field in ('name','type','code','buyable','class','iconurl','market','cash','cost','subtype','growTime','coinYield','action','limitedEnd','requiredLevel','crop','sizeX','sizeY','plantXp','masterymax','license','realname','desc') and name in (select name from units where field='type' and content='" . $vType . "')";
}
$vResult = @$_SESSION['vDataDB']->query($vSQL);
while ($vRow = @$vResult->fetchArray(SQLITE3_ASSOC))
{
$vReturn[$vRow['name']][$vRow['field']] = $vRow['content'];
}
return($vReturn);
}
// ------------------------------------------------------------------------------
// Units_GetByType get all units of type $vType
// ------------------------------------------------------------------------------
function Units_GetByField($vField, $vType, $vAllInfo = false)
{
if ($vAllInfo)
{
$vSQL = 'select * from units where name in (select name from units where field="' . $vField . '" and content="' . $vType . '")';
}
else
{
$vSQL = "select * from units where field in ('name','type','code','buyable','class','iconurl','market','cash','cost','subtype','growTime','coinYield','action','limitedEnd','requiredLevel','crop','sizeX','sizeY','plantXp','masterymax','license','realname','desc') and name in (select name from units where field='" . $vField . "' and content='" . $vType . "')";
}
$vResult = @$_SESSION['vDataDB']->query($vSQL);
while ($vRow = @$vResult->fetchArray(SQLITE3_ASSOC))
{
$vReturn[$vRow['name']][$vRow['field']] = $vRow['content'];
}
return($vReturn);
}
// ------------------------------------------------------------------------------
// Units_GetRealnameByField
// ------------------------------------------------------------------------------
function Units_GetRealnameByField($vData, $vField)
{
$vSQL = 'select content from units where field="realname" and name in (select name from units where content="' . $vData . '" and field="' . $vField . '")';
$vResult = $_SESSION['vDataDB']->querySingle($vSQL);
return($vResult === false?$vCode:$vResult);
}
// ------------------------------------------------------------------------------
// Units_GetByClass get all units of type $vType
// ------------------------------------------------------------------------------
function Units_GetByClass($vClass, $vAllInfo = false)
{
if ($vAllInfo)
{
$vSQL = 'select * from units where name in (select name from units where field="className" and content="' . $vClass . '")';
}
else
{
$vSQL = "select * from units where field in ('name','type','code','buyable','class','iconurl','market','cash','cost','subtype','growTime','coinYield','action','limitedEnd','requiredLevel','crop','sizeX','sizeY','plantXp','masterymax','license','realname','desc') and name in (select name from units where field='className' and content='" . $vClass . "')";
}
$vResult = @$_SESSION['vDataDB']->query($vSQL);
while ($vRow = @$vResult->fetchArray(SQLITE3_ASSOC))
{
$vReturn[$vRow['name']][$vRow['field']] = $vRow['content'];
}
return($vReturn);
}
// ------------------------------------------------------------------------------
// Crafts_GetByCode get all crafts of code $vCode
// ------------------------------------------------------------------------------
function Crafts_GetByCode($vCode)
{
$vSQL = "select * from crafting where name in (select name from crafting where field='id' and content='" . $vCode . "')";
$vResult = @$_SESSION['vDataDB']->query($vSQL);
while ($vRow = @$vResult->fetchArray(SQLITE3_ASSOC))
{
if (isset($vReturn[$vRow['field']])) {
$vReturn[$vRow['field']] = $vReturn[$vRow['field']] . ':' . $vRow['content'];
} else {
$vReturn[$vRow['field']] = $vRow['content'];
}
}
return($vReturn);
}
// ------------------------------------------------------------------------------
// Storage_GetByName get all storage of code $vName
// ------------------------------------------------------------------------------
function Storage_GetByName($vName)
{
$vSQL = "select * from storage where name in (select name from storage where field='name' and content='" . $vName . "')";
$vResult = @$_SESSION['vDataDB']->query($vSQL);
while ($vRow = @$vResult->fetchArray(SQLITE3_ASSOC))
{
if (isset($vReturn[$vRow['field']])) {
$vReturn[$vRow['field']] = $vReturn[$vRow['field']] . ':' . $vRow['content'];
} else {
$vReturn[$vRow['field']] = $vRow['content'];
}
}
return($vReturn);
}
// ------------------------------------------------------------------------------
// Crafts_GetByCode get all crafts of code $vCode
// ------------------------------------------------------------------------------
function Quests_GetByCode($vCode)
{
$vSQL = "select * from quests where name in (select name from quests where field='id' and content='" . $vCode . "')";
$vResult = @$_SESSION['vDataDB']->query($vSQL);
while ($vRow = @$vResult->fetchArray(SQLITE3_ASSOC))
{
if (isset($vReturn[$vRow['field']])) {
$vReturn[$vRow['field']] = $vReturn[$vRow['field']] . ':' . $vRow['content'];
} else {
$vReturn[$vRow['field']] = $vRow['content'];
}
}
return($vReturn);
}
// ------------------------------------------------------------------------------
// Quests_GetAll get all quests
// ------------------------------------------------------------------------------
function Quests_GetAll()
{
$vSQL = 'select * from quests';
$vResult = @$_SESSION['vDataDB']->query($vSQL);
while ($vRow = @$vResult->fetchArray(SQLITE3_ASSOC))
{
$vReturn[$vRow['name']][$vRow['field']] = $vRow['content'];
}
return($vReturn);
}
// ------------------------------------------------------------------------------
// Quests_GetRealnameByTitle
// ------------------------------------------------------------------------------
function Quests_GetRealnameByTitle($vField)
{
$vSQL = 'select content from quests where field="realname" and name ="' . $vField . '"';
$vResult = $_SESSION['vDataDB']->querySingle($vSQL);
return($vResult === false?$vCode:$vResult);
}
// ------------------------------------------------------------------------------n
// Units_GetCodeByName
// ------------------------------------------------------------------------------
function Units_GetFarming($vField)
{
$vSQL = 'select content from units where name="_farming" and field="' . $vField . '"';
$vResult = $_SESSION['vDataDB']->querySingle($vSQL);
return($vResult === false?$vField:$vResult);
}
// ------------------------------------------------------------------------------
// Units_GetUnitByName get unit by Name
// ------------------------------------------------------------------------------
function Units_IsConsumableByName($vName)
{
$vSQL = 'select count(*) from units where name="' . $vName . '" and content="consumable" and field in ("type","subtype")';
$vResult = @$_SESSION['vDataDB']->querySingle($vSQL);
return(@$vResult === false?false:true);
}
// ------------------------------------------------------------------------------
// Parser_SQlite_Connect
// ------------------------------------------------------------------------------
function Parser_SQlite_Connect($vDBFile)
{
$vDB = new SQLite3($vDBFile);
if (!$vDB)
{
AddLog2('Parser SQlite Error: cant open ' . $vDBFile);
return(false);
}
$vDB->exec('PRAGMA cache_size=20000');
$vDB->exec('PRAGMA synchronous=OFF');
$vDB->exec('PRAGMA count_changes=OFF');
$vDB->exec('PRAGMA journal_mode=MEMORY');
$vDB->exec('PRAGMA temp_store=MEMORY');
$vDB->busyTimeout(10000);
return $vDB;
}
// ------------------------------------------------------------------------------
// Units_GetByClass get all units of type $vType
// ------------------------------------------------------------------------------
function fBGetUserInfo()
{
$vSQL = 'SELECT * FROM userids';
$results = @$_SESSION['vDataStoreDB']->query($vSQL);
while ($vRow = @$results->fetchArray(SQLITE3_ASSOC))
{
$vReturn[$vRow['userid']] = $vRow['username'];
}
return($vReturn);
}
function fBGetDefUser()
{
$vSQL = 'SELECT * FROM userids LIMIT 1';
$fresult = @$_SESSION['vDataStoreDB']->querySingle($vSQL);
return($fresult);
}
function fBGetNeighborRealName($uid)
{
$vSQL = "SELECT fullname FROM neighbors WHERE neighborid='" . $uid . "' LIMIT 1";
$fresult = @$_SESSION['vDataStoreDB']->querySingle($vSQL);
return($fresult=== false?false:$fresult);
}
function fBGetDataStore($storetype)
{
$vSQL = "SELECT content FROM datastore WHERE userid='" . $_SESSION['userId'] . "' AND storetype='$storetype'";
$fresult = @$_SESSION['vDataStoreDB']->querySingle($vSQL);
return($fresult);
}
function fBGetRewardStore($storetype)
{
$vSQL = "SELECT content FROM rewardstore WHERE userid='" . $_SESSION['userId'] . "' AND storetype='$storetype'";
$fresult = $_SESSION['vRewardStoreDB']->querySingle($vSQL);
return($fresult);
}
?>