nmps-server

server-side nmps
git clone git://git.kocotian.pl/nmps-server.git
Log | Files | Refs | README

commit 4f0136df6266d1d4aa8103260ea0f8d87ea815d6
parent 7573d3b51beb1b55b141aac04781f5e8295badc9
Author: kocotian <kocotian@kocotian.pl>
Date:   Mon,  7 Dec 2020 20:35:54 +0100

statistics, inventories

Diffstat:
Ainv.php | 38++++++++++++++++++++++++++++++++++++++
Mmotd.php | 2+-
Mrequire/nmps.php | 20++++++++++++++++++++
Muserinfo.php | 13++++++++-----
4 files changed, 67 insertions(+), 6 deletions(-)

diff --git a/inv.php b/inv.php @@ -0,0 +1,38 @@ +<?php + +require_once "require/nmps.php"; + +$inventories = db::query("SELECT * FROM inventories WHERE userId=:userId", [':userId' => $userinfo['id']]); + +if (!count($inventories)) { + echo "\033[1;33m* \033[0;97mCreating new inventory\n"; + db::query("INSERT INTO storages VALUES ()"); + echo "\033[1;32m* \033[0;97mCreated storage\n"; + $storage = db::query("SELECT * FROM storages ORDER BY id DESC LIMIT 1")[0]; + db::query("INSERT INTO inventories (userId, storageId) VALUES (:userId, :storageId)", + [':userId' => $userinfo['id'], ':storageId' => $storage['id']]); + echo "\033[1;32m* \033[0;97mCreated main inventory\n"; + for ($i = 0; $i < 9; ++$i) + db::query("INSERT INTO slots (storageId) VALUES (:storageId)", + [':storageId' => $storage['id']]); + echo "\033[1;32m* \033[0;97mCreated 9 slots\n"; + $inventories = db::query("SELECT * FROM inventories WHERE userId=:userId", [':userId' => $userinfo['id']]); + echo "\033[1;32mCreated new inventory with id #0\033[0;32m" . $inventories[0]['id'] . "\n"; +} + +$index = -1; +echo "\033[1;97mYour inventories:\n"; +foreach ($inventories as $inv) { + $slotindex = -1; + echo "\033[1;33m" . ++$index . ". \033[0;37m" . ($inv['name'] ? $inv['name'] : "no name") . " \033[1;97m[\033[0;97m#0" . $inv['id'] . "\033[1;97m]:\n"; + $slots = db::query("SELECT * FROM slots WHERE storageId=:storageId", + [':storageId' => $inv['storageId']]); + if (!count($slots)) + echo "\033[1;97m| \033[0;33mno slots.\n"; + foreach ($slots as $slot) { + $item = db::query("SELECT * FROM items WHERE slotId=:slotId", + [':slotId' => $slot['id']])[0]; + echo "\033[1;97m| \033[0;33m" . ++$slotindex . ". \033[1;37m[\033[0;97m" . + ($item ? $item['name'] : "\033[1;97mempty") . "\033[1;37m]\n"; + } +} diff --git a/motd.php b/motd.php @@ -5,7 +5,7 @@ require_once "require/nmps.php"; $eq = "\033[1;33m======================="; for ($i = 0; $i < strlen($_SERVER['SERVER_NAME']); ++$i) $eq .= "="; -echo $eq . " +echo nmps::getStat('health', $userinfo) . nmps::getStat('energy', $userinfo) . nmps::getStat('saturation', $userinfo) . nmps::getStat('sanity', $userinfo) . $eq . " \033[1;97mWelcome to the \033[1;33m{$_SERVER['SERVER_NAME']} \033[1;97mserver!" . ($userinfo['addressBefore'] != "0.0.0.0" ? diff --git a/require/nmps.php b/require/nmps.php @@ -99,4 +99,24 @@ class nmps { echo "\033[1;33m[\033[1;97m" . date("H:i:s") . "\033[1;33m] \033[0;97m" . $eventData; } + + public static function + getStatCode($which) + { + if ($which == 'health') + return "\001"; + else if ($which == 'energy') + return "\002"; + else if ($which == 'saturation') + return "\003"; + else if ($which == 'sanity') + return "\004"; + else return "\177"; + } + + public static function + getStat($which, $userinfo) + { + return "\016" . self::getStatCode($which) . ($userinfo[$which] < 16 ? "0" : "") . dechex($userinfo[$which]) . "\001"; + } } diff --git a/userinfo.php b/userinfo.php @@ -5,10 +5,13 @@ if (!strlen($argv[0])) $argv[0] = $userinfo['username']; $user = db::query("SELECT * FROM users WHERE username=:username", ['username' => $argv[0]])[0]; if ($user) { - echo "\033[1;33musername: \033[0;33m" . $user['username'] . "\n"; - echo "\033[1;33mlast online: \033[0;33m" . $user['lastOnline'] . "\n"; - echo "\033[1;33mmoney: \033[0;33m" . $user['money'] . "\n"; - echo "\033[1;33mlevel: \033[0;33m" . $user['level'] . "\n"; - echo "\033[1;33mxp: \033[0;33m" . $user['xp'] . "\n"; + echo "\033[1;97musername: \033[0;97m" . $user['username'] . "\n"; + echo "\033[1;37mlast online: \033[0;33m" . $user['lastOnline'] . "\n"; + echo "\033[1;37mmoney: \033[0;33m" . $user['money'] . "\n"; + echo "\033[1;37mhealth: \033[0;33m" . $user['health'] . "\n"; + echo "\033[1;37menergy: \033[0;33m" . $user['energy'] . "\n"; + echo "\033[1;37msaturation: \033[0;33m" . $user['saturation'] . "\n"; + echo "\033[1;37msanity: \033[0;33m" . $user['sanity'] . "\n"; + echo "\033[1;37mxp: \033[0;33m" . $user['xp'] . "\n"; } else echo "\033[1;31mUser doesn't exists";