Skip to content

Commit 90eb253

Browse files
committed
Simplify database query from admin panel.
1 parent 8576cc1 commit 90eb253

5 files changed

Lines changed: 34 additions & 21 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Second step, add the library if the database uses MD5.
2525
* Copy "WZ_MD5_MOD.dll" from project to Microsoft SQL "Server\MSSQL\Binn\"
2626
*********************************************************************
2727
The third step is to change socks.
28-
* Change `config.php` and replace 'IP Address', 'Login', 'Password', 'DataBase'
28+
* Customize the file `config.php` and variable $mmw['sql'] replace '127.0.0.1', 'USER', 'PASSWORD'
2929
* If you will be installing from a non-local ip, you set CUSTOM_IP_ADDRESS in install.php
3030
* Open install http://localhost/install.php
3131
*********************************************************************

admin/acc.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -368,13 +368,13 @@
368368
$search = clean_var(stripslashes($_POST['search_account']));
369369

370370
$queryBuildWhere = !empty($_POST['search_type'])
371-
? "LIKE '%{$search}%'"
372-
: "= '{$search}'";
371+
? "mi.memb___id LIKE '%{$search}%'"
372+
: "mi.memb___id = '{$search}'";
373373
$result = mssql_query("SELECT
374374
mi.memb___id,mi.memb__pwd,mi.bloc_code,mi.country,mi.gender,ms.ConnectStat
375375
FROM dbo.MEMB_INFO AS mi
376376
LEFT JOIN dbo.MEMB_STAT AS ms ON ms.memb___id = mi.memb___id
377-
WHERE mi.memb___id {$queryBuildWhere}");
377+
WHERE {$queryBuildWhere}");
378378

379379
$rank = 1;
380380
while ($row = mssql_fetch_row($result)) {

admin/acclist.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,13 @@
4545
mi.bloc_code,
4646
mi.appl_days,
4747
ms.ConnectStat,
48-
ms.ConnectTM
49-
FROM dbo.MEMB_INFO AS mi
50-
LEFT JOIN dbo.MEMB_STAT AS ms ON ms.memb___id = mi.memb___id
51-
ORDER BY appl_days");
48+
ms.ConnectTM,
49+
c.count
50+
FROM dbo.MEMB_INFO AS mi
51+
LEFT JOIN dbo.MEMB_STAT AS ms ON ms.memb___id = mi.memb___id
52+
LEFT JOIN (SELECT COUNT(*) AS count, AccountID FROM dbo.Character GROUP BY AccountID) AS c ON c.AccountID = mi.memb___id
53+
ORDER BY appl_days
54+
");
5255
while ($row = mssql_fetch_row($result)) {
5356
$mode = $row[1];
5457
if ($row[1] == 0) {
@@ -75,16 +78,14 @@
7578
if ($row[3] === null) {
7679
$status = '<img src="../images/death.gif" alt="death">';
7780
}
78-
79-
$char_numb = mssql_num_rows(mssql_query("SELECT Name FROM dbo.Character WHERE AccountID='{$row[0]}'"));
8081
?>
8182
<tr>
8283
<td align="center"><?php echo $rank++; ?>.</td>
8384
<td><a href=?op=acc&acc=<?php echo $row[0]; ?>><?php echo $row[0]; ?></a></td>
8485
<td><?php echo $mode; ?></td>
8586
<td><?php echo time_format($row[2]); ?></td>
8687
<td><?php echo $row[4] ? time_format($row[4]) : '---'; ?></td>
87-
<td><?php echo $char_numb; ?></td>
88+
<td><?php echo intval($row[5]); ?></td>
8889
<td align="center"><?php echo $status; ?></td>
8990
<td align="center">
9091
<form action="" method="post">

admin/char.php

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -270,22 +270,34 @@
270270
$search_type = $_POST['search_type'];
271271

272272
$queryBuildWhere = !empty($_POST['search_type'])
273-
? "LIKE '%{$search}%'"
274-
: "= '{$search}'";
275-
$result = mssql_query("SELECT Name,Class,cLevel,{$mmw['reset_column']},strength,dexterity,vitality,energy,accountid,CtlCode FROM dbo.Character WHERE Name {$queryBuildWhere}");
273+
? "c.Name LIKE '%{$search}%'"
274+
: "c.Name = '{$search}'";
275+
$result = mssql_query("SELECT
276+
c.Name,
277+
c.Class,
278+
c.cLevel,
279+
c.{$mmw['reset_column']},
280+
c.Strength,
281+
c.Dexterity,
282+
c.Vitality,
283+
c.Energy,
284+
c.AccountID,
285+
c.CtlCode,
286+
ms.ConnectStat
287+
FROM dbo.Character as c
288+
LEFT JOIN dbo.MEMB_STAT as ms ON ms.memb___id = c.AccountID
289+
WHERE {$queryBuildWhere}
290+
");
276291

277292
$rank = 1;
278293
while ($row = mssql_fetch_row($result)) {
279-
$status_result = mssql_query("SELECT ConnectStat FROM dbo.MEMB_STAT WHERE memb___id='{$row[8]}'");
280-
$status = mssql_fetch_row($status_result);
281-
282-
if ($status[0] == 0) {
294+
if ($row[10] == 0) {
283295
$status = '<img src="../images/offline.gif" alt="offline">';
284296
}
285-
if ($status[0] == 1) {
297+
if ($row[10] == 1) {
286298
$status = '<img src="../images/online.gif" alt="online">';
287299
}
288-
if ($status[0] === null) {
300+
if ($row[10] === null) {
289301
$status = '<img src="../images/death.gif" alt="death">';
290302
}
291303

admin/sqlquery.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
$exampleQuery = "UPDATE table SET [column]=? WHERE [column]=?\n\nSELECT * FROM table WHERE [column]=?\n\nSELECT CAST(Items AS varbinary(1920)) FROM warehouse WHERE AccountID='?'";
77

88
if (isset($_POST['sql_query_true'])) {
9-
$sqlQuery = str_replace(array('\"', '\''), array('"', ''), $_POST['sql_query']);
9+
$sqlQuery = str_replace(array('\"', '\'', '&#39;'), array('"', '', '\''), $_POST['sql_query']);
1010
if ($sqlQueryResult = mssql_query($sqlQuery)) {
1111
$queryResult = $mmw['warning']['green'] . 'Query done!';
1212
writelog('a_sql_query', 'Query: <b>' . $sqlQuery . '</b> Has Been <span style="color:red">Injection</span>');

0 commit comments

Comments
 (0)