2014-05-26 06:17:51 -06:00
|
|
|
--[[
|
|
|
|
Copyright (C) 2014 HarpyWar (harpywar@gmail.com)
|
|
|
|
|
|
|
|
This file is a part of the PvPGN Project http://pvpgn.pro
|
|
|
|
Licensed under the same terms as Lua itself.
|
|
|
|
]]--
|
|
|
|
|
|
|
|
|
|
|
|
-- List of available lua commands
|
|
|
|
-- (To create a new command - create a new file in directory "commands")
|
|
|
|
local lua_command_table = {
|
|
|
|
[1] = {
|
|
|
|
["/w3motd"] = command_w3motd,
|
2014-07-30 07:15:30 -06:00
|
|
|
|
2014-05-26 06:17:51 -06:00
|
|
|
-- Quiz
|
|
|
|
["/quiz"] = command_quiz,
|
2014-07-30 07:15:30 -06:00
|
|
|
|
|
|
|
-- GHost
|
2014-08-02 04:13:52 -06:00
|
|
|
["/ghost"] = command_ghost,
|
2014-07-30 07:15:30 -06:00
|
|
|
|
|
|
|
["/host"] = command_host,
|
2014-08-02 09:28:33 -06:00
|
|
|
["/chost"] = command_chost,
|
2014-07-30 07:15:30 -06:00
|
|
|
["/unhost"] = command_unhost,
|
|
|
|
["/ping"] = command_ping, ["/p"] = command_ping,
|
|
|
|
["/swap"] = command_swap,
|
|
|
|
["/open"] = command_open_close,
|
|
|
|
["/close"] = command_open_close,
|
|
|
|
["/start"] = command_start_abort_pub_priv,
|
|
|
|
["/abort"] = command_start_abort_pub_priv,
|
|
|
|
["/pub"] = command_start_abort_pub_priv,
|
|
|
|
["/priv"] = command_start_abort_pub_priv,
|
|
|
|
["/stats"] = command_stats,
|
2014-06-23 05:12:59 -06:00
|
|
|
},
|
2014-05-26 06:17:51 -06:00
|
|
|
[8] = {
|
|
|
|
["/redirect"] = command_redirect,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
-- Global function to handle commands
|
2014-07-26 06:39:14 -06:00
|
|
|
-- ("return 1" from a command will allow next C++ code execution)
|
2014-05-26 06:17:51 -06:00
|
|
|
function handle_command(account, text)
|
|
|
|
-- find command in table
|
|
|
|
for cg,cmdlist in pairs(lua_command_table) do
|
|
|
|
for cmd,func in pairs(cmdlist) do
|
|
|
|
if string.starts(text, cmd) then
|
|
|
|
|
2014-08-30 06:32:38 -06:00
|
|
|
-- check if command group is in account commandgroups
|
|
|
|
if math_and(account_get_auth_command_groups(account.name), cg) == 0 then
|
2014-06-28 11:33:09 -06:00
|
|
|
api.message_send_text(account.name, message_type_error, account.name, localize(account.name, "This command is reserved for admins."))
|
2014-07-26 06:39:14 -06:00
|
|
|
return -1
|
2014-05-26 06:17:51 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
-- FIXME: we can use _G[func] if func is a text but not a function,
|
|
|
|
-- like ["/dotastats"] = "command_dotastats"
|
|
|
|
-- and function command_dotastats can be defined below, not only before
|
|
|
|
return func(account, text)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2014-07-26 06:39:14 -06:00
|
|
|
return 1
|
2014-05-26 06:17:51 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2014-07-31 01:08:36 -06:00
|
|
|
-- Executes before executing any command
|
2014-08-02 09:28:33 -06:00
|
|
|
-- "return 0" stay with flood protection
|
2014-07-31 01:08:36 -06:00
|
|
|
-- "return 1" allow ignore flood protection
|
2014-08-02 09:28:33 -06:00
|
|
|
-- "return -1" will prevent next command execution silently
|
2014-07-31 01:08:36 -06:00
|
|
|
function handle_command_before(account, text)
|
|
|
|
-- special users
|
|
|
|
for k,username in pairs(config.flood_immunity_users) do
|
|
|
|
if (username == account.name) then return 1 end
|
|
|
|
end
|
|
|
|
|
|
|
|
if (config.ghost) then
|
|
|
|
-- ghost bots
|
|
|
|
for k,username in pairs(config.ghost_bots) do
|
|
|
|
if (username == account.name) then return 1 end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return 0
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2014-05-26 06:17:51 -06:00
|
|
|
-- Split command to arguments,
|
|
|
|
-- index 0 is always a command name without a slash
|
|
|
|
-- return table with arguments
|
|
|
|
function split_command(text, args_count)
|
|
|
|
local count = args_count
|
|
|
|
local result = {}
|
|
|
|
local tmp = ""
|
|
|
|
|
|
|
|
-- remove slash from the command
|
|
|
|
if not string:empty(text) then
|
|
|
|
text = string.sub(text, 2)
|
|
|
|
end
|
|
|
|
|
|
|
|
i = 0
|
|
|
|
-- split by space
|
|
|
|
for token in string.split(text) do
|
|
|
|
if not string:empty(token) then
|
|
|
|
if (i < count) then
|
|
|
|
result[i] = token
|
|
|
|
i = i + 1
|
|
|
|
else
|
|
|
|
if not string:empty(tmp) then
|
|
|
|
tmp = tmp .. " "
|
|
|
|
end
|
|
|
|
tmp = tmp .. token
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
-- push remaining text at the end
|
|
|
|
if not string:empty(tmp) then
|
|
|
|
result[count] = tmp
|
|
|
|
end
|
|
|
|
return result
|
|
|
|
end
|
|
|
|
|