From dfce8d97dd0ea8820c3248f6f395d0d8b2f3fb07 Mon Sep 17 00:00:00 2001 From: Stefan Brannfjell Date: Mon, 10 Mar 2014 08:10:03 +0100 Subject: [PATCH] TFS 0.2 and 1.0 report bug system Players can say !report SomeMessageHere to send a report to database, it will automatically fetch position of player etc. You can check reports in admin panel and change status of them, and optionally reward player with points if you feel they deserve it for reporting the bug. Default working TFS 1.0 scripts for shop and firstitems --- .../Installation Instructions.txt | 4 + .../creaturescript firstitems/firstitems.lua | 77 ++++++++++ .../talkaction report system/adminreport.lua | 20 +++ .../talkaction shopsystem/talkaction XML.txt | 1 + .../talkaction shopsystem/znoteshop.lua | 49 +++++++ admin_reports.php | 136 ++++++++++++++++++ createcharacter.php | 2 +- engine/database/connect.php | 11 ++ layout/widgets/Wadmin.php | 3 + 9 files changed, 302 insertions(+), 1 deletion(-) create mode 100644 LUA/TFS_10/creaturescript firstitems/Installation Instructions.txt create mode 100644 LUA/TFS_10/creaturescript firstitems/firstitems.lua create mode 100644 LUA/TFS_10/talkaction report system/adminreport.lua create mode 100644 LUA/TFS_10/talkaction shopsystem/talkaction XML.txt create mode 100644 LUA/TFS_10/talkaction shopsystem/znoteshop.lua create mode 100644 admin_reports.php diff --git a/LUA/TFS_10/creaturescript firstitems/Installation Instructions.txt b/LUA/TFS_10/creaturescript firstitems/Installation Instructions.txt new file mode 100644 index 0000000..4b60316 --- /dev/null +++ b/LUA/TFS_10/creaturescript firstitems/Installation Instructions.txt @@ -0,0 +1,4 @@ +Step 1: Copy firstitems.lua to /data/creaturescripts/scripts/ folder +-- Edit firstitems.lua with item IDs you want characters to start with on your server. + +Step 2: Restart OT server, and it should work. :) \ No newline at end of file diff --git a/LUA/TFS_10/creaturescript firstitems/firstitems.lua b/LUA/TFS_10/creaturescript firstitems/firstitems.lua new file mode 100644 index 0000000..c0043be --- /dev/null +++ b/LUA/TFS_10/creaturescript firstitems/firstitems.lua @@ -0,0 +1,77 @@ +function onLogin(cid) + local storage = 30055 -- storage value + + local sorcItems = { + 2460, -- Brass helmet + 2465, -- Brass armor + 2190, -- Wand of vortex + 2511, -- Brass shield + 2478, -- Brass legs + 2643, -- Leather boots + 1988, -- Brown backpack + 2050 -- torch + } + local druidItems = { + 2460, -- Brass helmet + 2465, -- Brass armor + 2511, -- Brass shield + 2182, -- Snakebite rod + 2478, -- Brass legs + 2643, -- Leather boots + 1988, -- Brown backpack + 2050 -- torch + } + local pallyItems = { + 2460, -- Brass helmet + 2465, -- Brass armor + 2456, -- Bow + 2478, -- Brass legs + 2643, -- Leather boots + 1988, -- Brown backpack + } + local kinaItems = { + 2460, -- Brass helmet + 2465, -- Brass armor + 2511, -- Brass shield + 2412, -- Katana + 2478, -- Brass legs + 2643, -- Leather boots + 1988, -- Brown backpack + 2050 -- torch + } + + if getPlayerStorageValue(cid, storage) == -1 then + setPlayerStorageValue(cid, storage, 1) + if getPlayerVocation(cid) == 1 then + -- Sorcerer + for i = 1, table.getn(sorcItems), 1 do + doPlayerAddItem(cid, sorcItems[i], 1, FALSE) + end + + elseif getPlayerVocation(cid) == 2 then + -- Druid + for i = 1, table.getn(druidItems), 1 do + doPlayerAddItem(cid, druidItems[i], 1, FALSE) + end + + elseif getPlayerVocation(cid) == 3 then + -- Paladin + for i = 1, table.getn(pallyItems), 1 do + doPlayerAddItem(cid, pallyItems[i], 1, FALSE) + end + -- 8 arrows + doPlayerAddItem(cid, 2544, 8, FALSE) + + elseif getPlayerVocation(cid) == 4 then + -- Knight + for i = 1, table.getn(kinaItems), 1 do + doPlayerAddItem(cid, kinaItems[i], 1, FALSE) + end + end + + -- Common for all + doPlayerAddItem(cid, 2674, 5, FALSE) -- 5 apples + doPlayerAddItem(cid, 2120, 1, FALSE) -- 1 rope + end + return true +end diff --git a/LUA/TFS_10/talkaction report system/adminreport.lua b/LUA/TFS_10/talkaction report system/adminreport.lua new file mode 100644 index 0000000..c4262c5 --- /dev/null +++ b/LUA/TFS_10/talkaction report system/adminreport.lua @@ -0,0 +1,20 @@ +-- +function onSay(cid, words, param, channel) + local storage = 6708 -- (You can change the storage if its already in use) + local delaytime = 30 -- (Exhaust In Seconds.) + local x = getPlayerPosition(cid).x -- (Do not edit this.) + local y = getPlayerPosition(cid).y -- (Do not edit this.) + local z = getPlayerPosition(cid).z -- (Do not edit this.) + if(param == '') then + doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Command param required.") + return true + end + if (getPlayerStorageValue(cid, storage) <= os.time()) then + doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Your report has been received successfully!") + db.query("INSERT INTO `player_reports` (`id` ,`name` ,`posx` ,`posy` ,`posz` ,`report_description` ,`date`)VALUES (NULL , '" .. getPlayerName(cid) .. "', '" .. x .. "', '" .. y .. "', '" .. z .. "', '" .. string.gsub(param, "'", "\\'") .. "', '" .. os.time() .. "')") + setPlayerStorageValue(cid,storage,os.time()+delaytime) + else + doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "You have to wait 30 seconds to report again.") + end + return TRUE +end \ No newline at end of file diff --git a/LUA/TFS_10/talkaction shopsystem/talkaction XML.txt b/LUA/TFS_10/talkaction shopsystem/talkaction XML.txt new file mode 100644 index 0000000..2fdffee --- /dev/null +++ b/LUA/TFS_10/talkaction shopsystem/talkaction XML.txt @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/LUA/TFS_10/talkaction shopsystem/znoteshop.lua b/LUA/TFS_10/talkaction shopsystem/znoteshop.lua new file mode 100644 index 0000000..3841348 --- /dev/null +++ b/LUA/TFS_10/talkaction shopsystem/znoteshop.lua @@ -0,0 +1,49 @@ +-- Znote Shop v1.0 for Znote AAC on TFS 0.2.13+ Mystic Spirit. +function onSay(cid, words, param) + local storage = 54073 -- Make sure to select non-used storage. This is used to prevent SQL load attacks. + local cooldown = 15 -- in seconds. + + if getPlayerStorageValue(cid, storage) <= os.time() then + setPlayerStorageValue(cid, storage, os.time() + cooldown) + local accid = getAccountNumberByPlayerName(getCreatureName(cid)) + + -- Create the query + local orderQuery = db.storeQuery("SELECT `id`, `type`, `itemid`, `count` FROM `znote_shop_orders` WHERE `account_id` = " .. accid .. " LIMIT 1;") + + -- Detect if we got any results + if orderQuery ~= false then + -- Fetch order values + local q_id = result.getDataInt(orderQuery, "id") + local q_type = result.getDataInt(orderQuery, "type") + local q_itemid = result.getDataInt(orderQuery, "itemid") + local q_count = result.getDataInt(orderQuery, "count") + result.free(orderQuery) + + -- ORDER TYPE 1 (Regular item shop products) + if q_type == 1 then + -- Get wheight + local playerCap = getPlayerFreeCap(cid) + local itemweight = getItemWeight(q_itemid, q_count) + if playerCap >= itemweight then + db.query("DELETE FROM `znote_shop_orders` WHERE `id` = " .. q_id .. ";") + doPlayerAddItem(cid, q_itemid, q_count) + doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Congratulations! You have recieved ".. q_count .." "..getItemName(q_itemid).."(s)!") + else + doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "Need more CAP!") + end + end + -- Add custom order types here + -- Type 2 is reserved for premium days and is handled on website, not needed here. + -- Type 3 is reserved for character gender(sex) change and is handled on website as well. + -- So use type 4+ for custom stuff, like etc packages. + -- if q_type == 4 then + -- end + else + doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "You have no orders.") + end + + else + doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Can only be executed once every "..cooldown.." seconds. Remaining cooldown: ".. getPlayerStorageValue(cid, storage) - os.time()) + end + return false +end \ No newline at end of file diff --git a/admin_reports.php b/admin_reports.php new file mode 100644 index 0000000..3080f07 --- /dev/null +++ b/admin_reports.php @@ -0,0 +1,136 @@ + 'Reported', + 1 => 'To-Do List', + 2 => 'Confirmed bug', + 3 => 'Invalid', + 4 => 'Rejected', + 5 => 'Fixed' +); + +// Fetch data from SQL +$reportsData = mysql_select_multi("SELECT id, name, posx, posy, posz, report_description, date, status FROM znote_player_reports ORDER BY id DESC;"); +// If sql data is not empty +if ($reportsData !== false) { + // Order reports array by ID for easy reference later on. + $reports = array(); + for ($i = 0; $i < count($reportsData); $i++) $reports[$reportsData[$i]['id']] = $reportsData[$i]; +} + +// POST logic (Update report and give player points) +if (!empty($_POST)) { + // Fetch POST data + $playerName = getValue($_POST['playerName']); + $status = getValue($_POST['status']); + $price = getValue($_POST['price']); + $customPoints = getValue($_POST['customPoints']); + $reportId = getValue($_POST['id']); + + if ($customPoints !== false) $price = (int)($price + $customPoints); + + // Update SQL + mysql_update("UPDATE `znote_player_reports` SET `status`='$status' WHERE `id`='$reportId' LIMIT 1;"); + // Update local array representation + $reports[$reportId]['status'] = $status; + + // If we should give user price + if ($price > 0) { + $account = mysql_select_single("SELECT `a`.`id`, `a`.`email` FROM `accounts` AS `a` + INNER JOIN `players` AS `p` ON `p`.`account_id` = `a`.`id` + WHERE `p`.`name` = '$playerName' LIMIT 1;"); + + if ($account !== false) { + // transaction log + mysql_insert("INSERT INTO `znote_paypal` VALUES ('', '$reportId', 'report@admin.".$user_data['name']." to ".$account['email']."', '".$account['id']."', '0', '".$price."')"); + // Process payment + $data = mysql_select_single("SELECT `points` AS `old_points` FROM `znote_accounts` WHERE `account_id`='".$account['id']."';"); + // Give points to user + $new_points = $data['old_points'] + $price; + mysql_update("UPDATE `znote_accounts` SET `points`='$new_points' WHERE `account_id`='".$account['id']."'"); + + // Remind GM that he sent points to character + echo "".$playerName." has been granted ".$price." points for his reports."; + } + } + +// GET logic (Edit report data and specify how many [if any] points to give to user) +} elseif (!empty($_GET)) { + // Fetch GET data + $action = getValue($_GET['action']); + $playerName = getValue($_GET['playerName']); + $reportId = getValue($_GET['id']); + + // Fetch the report we intend to modify + $report = $reports[$reportId]; + + // Create html form + ?> +
+
+ Player: + + +
Set status: +
+ Give user points: + +

+ +
+
+ +
+

Reports List

+ + + + + + + + + + + +
Info
Description
Report ID: # +
Name: +
Position: +
Reported: +
Status: . Edit +
+
+
+
+ No reports submitted."; +include 'layout/overall/footer.php'; +?> \ No newline at end of file diff --git a/createcharacter.php b/createcharacter.php index 98924da..32d34f8 100644 --- a/createcharacter.php +++ b/createcharacter.php @@ -21,7 +21,7 @@ if (empty($_POST) === false) { if ($_POST['name'] === false) { $errors[] = 'Your name can not contain more than 2 words.'; } else { - if (user_character_exist($_POST['name']) === true) { + if (user_character_exist($_POST['name']) !== false) { $errors[] = 'Sorry, that character name already exist.'; } if (!preg_match("/^[a-zA-Z_ ]+$/", $_POST['name'])) { diff --git a/engine/database/connect.php b/engine/database/connect.php index a243881..38bd8b9 100644 --- a/engine/database/connect.php +++ b/engine/database/connect.php @@ -95,6 +95,17 @@ CREATE TABLE IF NOT EXISTS `znote_players` ( INSERT INTO `znote_players` (`player_id`, `created`, `hide_char`, `comment`) VALUES ('1', '$time', '0', '. . .'); +CREATE TABLE IF NOT EXISTS `znote_player_reports` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(50) NOT NULL, + `posx` int(6) NOT NULL, + `posy` int(6) NOT NULL, + `posz` int(6) NOT NULL, + `report_description` VARCHAR(255) NOT NULL, + `date` INT(11) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; + CREATE TABLE IF NOT EXISTS `znote_shop` ( `id` int(11) NOT NULL AUTO_INCREMENT, `type` int(11) NOT NULL, diff --git a/layout/widgets/Wadmin.php b/layout/widgets/Wadmin.php index dcd15d8..14e5670 100644 --- a/layout/widgets/Wadmin.php +++ b/layout/widgets/Wadmin.php @@ -14,6 +14,9 @@
  • Admin Skills
  • +
  • + Admin Reports +