diff --git a/database/upgrade/1.0.2/wolfadmin_mysql.sql b/database/upgrade/1.0.2/wolfadmin_mysql.sql deleted file mode 100644 index 80dbbd3..0000000 --- a/database/upgrade/1.0.2/wolfadmin_mysql.sql +++ /dev/null @@ -1,95 +0,0 @@ --- new naming convention -ALTER TABLE `aliases` - RENAME TO `alias`; - -ALTER TABLE `levels` - RENAME TO `level`; - -ALTER TABLE `maps` - RENAME TO `map`; - -ALTER TABLE `players` - RENAME TO `player`; - -ALTER TABLE `records` - RENAME TO `record`; - -ALTER TABLE `warns` - RENAME TO `warn`; - -ALTER TABLE `alias` - DROP FOREIGN KEY `aliasplayer`, - DROP INDEX `playerid_idx`; -ALTER TABLE `alias` - CHANGE COLUMN `player` `player_id` INT(10) UNSIGNED NOT NULL; -ALTER TABLE `alias` - ADD CONSTRAINT `alias_player` - FOREIGN KEY (`player_id`) - REFERENCES `player` (`id`) - ON DELETE NO ACTION - ON UPDATE NO ACTION, - ADD INDEX `player_idx` (`player_id` ASC); - -ALTER TABLE `level` - DROP FOREIGN KEY `levelplayer`, - DROP INDEX `leveladmin_idx`, - DROP FOREIGN KEY `leveladmin`, - DROP INDEX `levelplayer`; -ALTER TABLE `level` - CHANGE COLUMN `player` `player_id` INT(10) UNSIGNED NOT NULL, - CHANGE COLUMN `admin` `admin_id` INT(10) UNSIGNED NOT NULL; -ALTER TABLE `level` - ADD CONSTRAINT `level_player` - FOREIGN KEY (`player_id`) - REFERENCES `player` (`id`) - ON DELETE NO ACTION - ON UPDATE NO ACTION, - ADD INDEX `player_idx` (`player_id` ASC), - ADD CONSTRAINT `level_admin` - FOREIGN KEY (`admin_id`) - REFERENCES `player` (`id`) - ON DELETE NO ACTION - ON UPDATE NO ACTION, - ADD INDEX `admin_idx` (`admin_id` ASC); - -ALTER TABLE `record` - DROP FOREIGN KEY `spreemap`, - DROP FOREIGN KEY `kspreeplayer`, - DROP INDEX `ksplayer_idx`; -ALTER TABLE `record` - CHANGE COLUMN `mapid` `map_id` INT(10) UNSIGNED NOT NULL, - CHANGE COLUMN `player` `player_id` INT(10) UNSIGNED NOT NULL; -ALTER TABLE `record` - ADD CONSTRAINT `record_map` - FOREIGN KEY (`map_id`) - REFERENCES `map` (`id`) - ON DELETE NO ACTION - ON UPDATE NO ACTION, - ADD CONSTRAINT `record_player` - FOREIGN KEY (`player_id`) - REFERENCES `player` (`id`) - ON DELETE NO ACTION - ON UPDATE NO ACTION, - ADD INDEX `player_idx` (`player_id` ASC); - -ALTER TABLE `warn` - DROP FOREIGN KEY `warnadmin`, - DROP INDEX `invoker_idx`, - DROP FOREIGN KEY `warnplayer`, - DROP INDEX `playerid_idx`; -ALTER TABLE `warn` - CHANGE COLUMN `player` `player_id` INT(10) UNSIGNED NOT NULL, - CHANGE COLUMN `admin` `admin_id` INT(10) UNSIGNED NOT NULL; -ALTER TABLE `warn` - ADD CONSTRAINT `warn_player` - FOREIGN KEY (`player_id`) - REFERENCES `player` (`id`) - ON DELETE NO ACTION - ON UPDATE NO ACTION, - ADD INDEX `player_idx` (`player_id` ASC), - ADD CONSTRAINT `warn_admin` - FOREIGN KEY (`admin_id`) - REFERENCES `player` (`id`) - ON DELETE NO ACTION - ON UPDATE NO ACTION, - ADD INDEX `admin_idx` (`admin_id` ASC); diff --git a/database/upgrade/1.1.0/wolfadmin_mysql.sql b/database/upgrade/1.1.0/wolfadmin_mysql.sql new file mode 100644 index 0000000..55e2d34 --- /dev/null +++ b/database/upgrade/1.1.0/wolfadmin_mysql.sql @@ -0,0 +1,6 @@ +-- remove old rows (MySQL only) + +DELETE FROM + `aliases` +WHERE + `cleanalias`=''; diff --git a/luascripts/admin/admin.lua b/luascripts/admin/admin.lua index 20cbedf..462eeb3 100644 --- a/luascripts/admin/admin.lua +++ b/luascripts/admin/admin.lua @@ -20,6 +20,8 @@ local events = require "luascripts.wolfadmin.util.events" local settings = require "luascripts.wolfadmin.util.settings" local files = require "luascripts.wolfadmin.util.files" local db = require "luascripts.wolfadmin.db.db" + +local players = require "luascripts.wolfadmin.players.players" local stats = require "luascripts.wolfadmin.players.stats" local admin = {} @@ -74,100 +76,63 @@ function admin.unlockPlayer(clientId) stats.set(clientId, "teamLock", false) end -function admin.updatePlayer(clientId) - local player = db.getplayer(stats.get(clientId, "playerGUID")) - - if player then - local guid = stats.get(clientId, "playerGUID") - local ip = stats.get(clientId, "playerIP") - - db.updateplayer(guid, ip) - else - local guid = stats.get(clientId, "playerGUID") - local ip = stats.get(clientId, "playerIP") - - db.addplayer(guid, ip) - admin.setPlayerLevel(clientId, et.G_shrubbot_level(clientId), 1) - end -end - -function admin.updateAlias(clientId) - local playerid = db.getplayer(stats.get(clientId, "playerGUID"))["id"] - local name = stats.get(clientId, "playerName") - local alias = db.getaliasbyname(playerid, name) - - if alias then - db.updatealias(alias["id"], os.time()) - if alias["cleanalias"] == "" then - db.updatecleanalias(alias["id"], name) - end - else - db.addalias(playerid, name, os.time()) - end -end - function admin.setPlayerLevel(clientId, level, adminId) local playerid = db.getplayer(stats.get(clientId, "playerGUID"))["id"] local adminid = db.getplayer(stats.get(adminId, "playerGUID"))["id"] - + + db.updateplayerlevel(playerid, level) db.addsetlevel(playerid, level, adminid, os.time()) end +function admin.onconnectattempt(clientId, firstTime, isBot) + if firstTime then + if stats.get(clientId, "playerGUID") == "NO_GUID" or stats.get(clientId, "playerGUID") == "unknown" then + return "\n\nIt appears you do not have a ^7GUID^9/^7etkey^9. In order to play on this server, enable ^7PunkBuster ^9(use ^7\\pb_cl_enable^9) ^9and/or create an ^7etkey^9.\n\nMore info: ^7www.etkey.org" + end + end + + events.trigger("onClientConnect", clientId, firstTime, isBot) +end +events.handle("onClientConnectAttempt", admin.onconnectattempt) + function admin.onconnect(clientId, firstTime, isBot) -- only increase the counter on first connection (fixes counter increase on -- clientbegin which is also triggered on warmup/maprestart/etc) stats.set(clientId, "namechangeStart", os.time()) stats.set(clientId, "namechangePts", 0) - - if firstTime then - if stats.get(clientId, "playerGUID") == "NO_GUID" or stats.get(clientId, "playerGUID") == "unknown" then - return "\n\nIt appears you do not have a ^7GUID^9/^7etkey^9. In order to play on this server, enable ^7PunkBuster ^9(use ^7\\pb_cl_enable^9) ^9and/or create an ^7etkey^9.\n\nMore info: ^7www.etkey.org" - end - - if db.isconnected() then - admin.updatePlayer(clientId) - admin.updateAlias(clientId) - end - end end events.handle("onClientConnect", admin.onconnect) -function stats.oninfochange(clientId) +function players.oninfochange(clientId) local clientInfo = et.trap_GetUserinfo(clientId) local old = stats.get(clientId, "playerName") local new = et.Info_ValueForKey(clientInfo, "name") - + if new ~= old then if (os.time() - stats.get(clientId, "namechangeStart")) < settings.get("g_renameInterval") and stats.get(clientId, "namechangePts") >= settings.get("g_renameLimit") and not stats.get(clientId, "namechangeForce") then stats.set(clientId, "namechangeForce", true) - + clientInfo = et.Info_SetValueForKey(clientInfo, "name", old) et.trap_SetUserinfo(clientId, clientInfo) et.ClientUserinfoChanged(clientId) - + stats.set(clientId, "namechangeForce", false) - + et.trap_SendServerCommand(clientId, "cp \"Too many name changes in 1 minute.\";") else stats.set(clientId, "playerName", new) - + if (os.time() - stats.get(clientId, "namechangeStart")) > settings.get("g_renameInterval") then stats.set(clientId, "namechangeStart", os.time()) stats.get(clientId, "namechangePts", 0) end - + stats.add(clientId, "namechangePts", 1) - - et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay -1 \""..old.." ^7is now known as "..new.."\";") - - if db.isconnected() then - admin.updateAlias(clientId) - end - + events.trigger("onClientNameChange", clientId, old, new) end end end -events.handle("onClientInfoChange", stats.oninfochange) +events.handle("onClientInfoChange", players.oninfochange) -return admin \ No newline at end of file +return admin diff --git a/luascripts/auth/acl.lua b/luascripts/auth/acl.lua new file mode 100644 index 0000000..6cc5193 --- /dev/null +++ b/luascripts/auth/acl.lua @@ -0,0 +1,57 @@ + +-- WolfAdmin module for Wolfenstein: Enemy Territory servers. +-- Copyright (C) 2015-2016 Timo 'Timothy' Smit + +-- This program is free software: you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation, either version 3 of the License, or +-- at your option any later version. + +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. + +-- You should have received a copy of the GNU General Public License +-- along with this program. If not, see . + +local auth = require "luascripts.wolfadmin.auth.auth" + +local db = require "luascripts.wolfadmin.db.db" + +local stats = require "luascripts.wolfadmin.players.stats" + +local events = require "luascripts.wolfadmin.util.events" +local files = require "luascripts.wolfadmin.util.files" + +local acl = {} + +function acl.readpermissions() + -- read level permissions into a cache file (can be loaded at mod start) + -- should probably cache current players' permissions as well, then + -- read in new players' permissions as they join the server +end + +function acl.clearcache() + -- clear cache whenever database is updated, or do this manually +end + +function acl.isallowed(clientId, permission) + -- stub function, reads from cache + + return 1 +end + +function acl.getlevel(clientId) + local player = db.getplayer(stats.get(clientId, "playerGUID")) + + return player["level_id"] +end + +function acl.getlevelname(levelId) + local level = db.getlevel(levelId) + + return level["name"] +end + +return acl diff --git a/luascripts/auth/auth.lua b/luascripts/auth/auth.lua new file mode 100644 index 0000000..49614fe --- /dev/null +++ b/luascripts/auth/auth.lua @@ -0,0 +1,129 @@ + +-- WolfAdmin module for Wolfenstein: Enemy Territory servers. +-- Copyright (C) 2015-2016 Timo 'Timothy' Smit + +-- This program is free software: you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation, either version 3 of the License, or +-- at your option any later version. + +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. + +-- You should have received a copy of the GNU General Public License +-- along with this program. If not, see . + +local events = require "luascripts.wolfadmin.util.events" +local files = require "luascripts.wolfadmin.util.files" +local settings = require "luascripts.wolfadmin.util.settings" + +local auth = {} + +local srv + +auth.PERM_ADMINTEST = "admintest" +auth.PERM_HELP = "help" +auth.PERM_TIME = "time" +auth.PERM_GREETING = "greeting" + +auth.PERM_LISTPLAYERS = "listplayers" +auth.PERM_LISTTEAMS = "listteams" +auth.PERM_LISTMAPS = "listmaps" +auth.PERM_LISTSPREES = "listsprees" +auth.PERM_LISTRULES = "listrules" +auth.PERM_LISTWARNS = "listwarns" +auth.PERM_LISTBANS = "listbans" +auth.PERM_LISTALIASES = "listaliases" +auth.PERM_LISTLEVELS = "listlevels" +auth.PERM_LISTSTATS = "liststats" +auth.PERM_FINGER = "finger" + +auth.PERM_RESETXP = "resetxp" +auth.PERM_RESETXP_SELF = "resetxp_self" + +auth.PERM_ADMINCHAT = "adminchat" + +auth.PERM_PUT = "put" +auth.PERM_DROPWEAPONS = "dropweapons" +auth.PERM_RENAME = "rename" +auth.PERM_FREEZE = "freeze" +auth.PERM_DISORIENT = "disorient" +auth.PERM_BURN = "burn" +auth.PERM_SLAP = "slap" +auth.PERM_GIB = "gib" +auth.PERM_THROW = "throw" +auth.PERM_GLOW = "glow" +auth.PERM_PANTS = "pants" +auth.PERM_POP = "pop" + +auth.PERM_WARN = "warn" +auth.PERM_MUTE = "mute" +auth.PERM_VOICEMUTE = "voicemute" +auth.PERM_KICK = "kick" +auth.PERM_BAN = "ban" + +auth.PERM_SPEC999 = "spec999" +auth.PERM_BALANCE = "balance" +auth.PERM_LOCKPLAYER = "lockplayers" +auth.PERM_LOCKTEAM = "lockteam" +auth.PERM_SHUFFLE = "shuffle" +auth.PERM_SWAP = "swap" + +auth.PERM_PAUSE = "pause" +auth.PERM_NEXTMAP = "nextmap" +auth.PERM_RESTART = "restart" + +auth.PERM_BOTADMIN = "botadmin" + +auth.PERM_ENABLEVOTE = "enablevote" +auth.PERM_CANCELVOTE = "cancelvote" +auth.PERM_PASSVOTE = "passvote" + +auth.PERM_NEWS = "news" + +auth.PERM_UPTIME = "uptime" +auth.PERM_SETLEVEL = "setlevel" +auth.PERM_READCONFIG = "readconfig" + +auth.PERM_CHEATS = "cheats" +auth.PERM_DISGUISE = "disguise" -- legacy +auth.PERM_AMMOPACK = "ammopack" -- legacy +auth.PERM_MEDPACK = "medpack" -- legacy +auth.PERM_REVIVE = "revive" -- legacy + +auth.PERM_NOINACTIVITY = "noinactivity" +auth.PERM_NOVOTE = "novote" +auth.PERM_NOCENSOR = "nocensor" +auth.PERM_NOBALANCE = "nobalance" +auth.PERM_NOVOTELIMIT = "novotelimit" +auth.PERM_NOREASON = "noreason" +auth.PERM_PERMA = "perma" + +auth.PERM_TEAMCMDS = "teamcmds" +auth.PERM_SILENTCMDS = "silentcmds" + +auth.PERM_SPY = "spy" +auth.PERM_INCOGNITO = "incognito" +auth.PERM_IMMUNE = "immune" + +-- as this module serves as a wrapper/super class, we load the selected database +-- system in this function. might have to think of a better way to implement +-- this, but it will suffice. +function auth.oninit() + if settings.get("g_standalone") == 1 then + srv = require "luascripts.wolfadmin.auth.acl" + else + srv = require "luascripts.wolfadmin.auth.shrubbot" + end + + if settings.get("g_standalone") == 1 and et.trap_Cvar_Get("g_shrubbot") ~= "" then + outputDebug("Running in standalone mode while g_shrubbot is set", 3) + end + + setmetatable(auth, {__index = srv}) +end +events.handle("onGameInit", auth.oninit) + +return auth diff --git a/luascripts/auth/shrubbot.lua b/luascripts/auth/shrubbot.lua new file mode 100644 index 0000000..c8f8559 --- /dev/null +++ b/luascripts/auth/shrubbot.lua @@ -0,0 +1,120 @@ + +-- WolfAdmin module for Wolfenstein: Enemy Territory servers. +-- Copyright (C) 2015-2016 Timo 'Timothy' Smit + +-- This program is free software: you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation, either version 3 of the License, or +-- at your option any later version. + +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. + +-- You should have received a copy of the GNU General Public License +-- along with this program. If not, see . + +local events = require "luascripts.wolfadmin.util.events" +local files = require "luascripts.wolfadmin.util.files" + +local auth = require "luascripts.wolfadmin.auth.auth" + +local shrubbot = {} + +local flags = { + [auth.PERM_ADMINTEST] = "a", + [auth.PERM_HELP] = "h", + [auth.PERM_TIME] = "C", + [auth.PERM_GREETING] = "Q", + + [auth.PERM_LISTPLAYERS] = "i", + [auth.PERM_LISTTEAMS] = "l", + [auth.PERM_LISTMAPS] = "C", + [auth.PERM_LISTSPREES] = "I", + [auth.PERM_LISTRULES] = "C", + [auth.PERM_LISTWARNS] = "R", + [auth.PERM_LISTBANS] = "B", + [auth.PERM_LISTALIASES] = "f", + [auth.PERM_LISTLEVELS] = "s", + [auth.PERM_LISTSTATS] = "I", + [auth.PERM_FINGER] = "f", + + [auth.PERM_RESETXP] = "X", + [auth.PERM_RESETXP_SELF] = "M", + + [auth.PERM_ADMINCHAT] = "~", + + [auth.PERM_PUT] = "p", + [auth.PERM_DROPWEAPONS] = "D", + [auth.PERM_RENAME] = "N", + [auth.PERM_FREEZE] = "E", + [auth.PERM_DISORIENT] = "d", + [auth.PERM_BURN] = "U", + [auth.PERM_SLAP] = "A", + [auth.PERM_GIB] = "g", + [auth.PERM_THROW] = "L", + [auth.PERM_GLOW] = "o", + [auth.PERM_PANTS] = "t", + [auth.PERM_POP] = "z", + + [auth.PERM_WARN] = "R", + [auth.PERM_MUTE] = "m", + [auth.PERM_VOICEMUTE] = "m", + [auth.PERM_KICK] = "k", + [auth.PERM_BAN] = "b", + + [auth.PERM_SPEC999] = "P", + [auth.PERM_BALANCE] = "p", + [auth.PERM_LOCKPLAYER] = "L", + [auth.PERM_LOCKTEAM] = "L", + [auth.PERM_SHUFFLE] = "S", + [auth.PERM_SWAP] = "w", + + [auth.PERM_PAUSE] = "Z", + [auth.PERM_NEXTMAP] = "n", + [auth.PERM_RESTART] = "r", + + [auth.PERM_BOTADMIN] = "O", + + [auth.PERM_ENABLEVOTE] = "c", + [auth.PERM_CANCELVOTE] = "c", + [auth.PERM_PASSVOTE] = "V", + + [auth.PERM_NEWS] = "W", + + [auth.PERM_UPTIME] = "u", + [auth.PERM_SETLEVEL] = "s", + [auth.PERM_READCONFIG] = "G", + + [auth.PERM_CHEATS] = "e", + [auth.PERM_DISGUISE] = "T", + [auth.PERM_AMMOPACK] = "J", + [auth.PERM_MEDPACK] = "J", + [auth.PERM_REVIVE] = "v", + + [auth.PERM_NOINACTIVITY] = "0", + [auth.PERM_NOVOTE] = "1", + [auth.PERM_NOCENSOR] = "2", + [auth.PERM_NOBALANCE] = "5", + [auth.PERM_NOVOTELIMIT] = "7", + [auth.PERM_NOREASON] = "6", + [auth.PERM_PERMA] = "8", + + [auth.PERM_TEAMCMDS] = "9", + [auth.PERM_SILENTCMDS] = "3", + + [auth.PERM_SPY] = "4", + [auth.PERM_INCOGNITO] = "@", + [auth.PERM_IMMUNE] = "!", +} + +function shrubbot.isallowed(clientId, permission) + return et.G_shrubbot_permission(clientId, flags[permission]) +end + +function shrubbot.getlevel(clientId) + return et.G_shrubbot_level(clientId) +end + +return shrubbot diff --git a/luascripts/commands/admin/balance.lua b/luascripts/commands/admin/balance.lua index ccd2b7c..4b7c305 100644 --- a/luascripts/commands/admin/balance.lua +++ b/luascripts/commands/admin/balance.lua @@ -16,6 +16,7 @@ -- along with this program. If not, see . local commands = require "luascripts.wolfadmin.commands.commands" +local auth = require "luascripts.wolfadmin.auth.auth" local balancer = require "luascripts.wolfadmin.admin.balancer" function commandBalance(clientId, cmdArguments) @@ -43,4 +44,4 @@ function commandBalance(clientId, cmdArguments) return true end -commands.addadmin("balance", commandBalance, "p", "either asks the players to even up or evens them by moving or shuffling players", "^2!balance ^9(^hforce^9)") \ No newline at end of file +commands.addadmin("balance", commandBalance, auth.PERM_BALANCE, "either asks the players to even up or evens them by moving or shuffling players", "^2!balance ^9(^hforce^9)") diff --git a/luascripts/commands/admin/dewarn.lua b/luascripts/commands/admin/dewarn.lua index 5a2fb37..031d428 100644 --- a/luascripts/commands/admin/dewarn.lua +++ b/luascripts/commands/admin/dewarn.lua @@ -18,6 +18,7 @@ local db = require "luascripts.wolfadmin.db.db" local settings = require "luascripts.wolfadmin.util.settings" local commands = require "luascripts.wolfadmin.commands.commands" +local auth = require "luascripts.wolfadmin.auth.auth" local warns = require "luascripts.wolfadmin.admin.warns" function commandRemoveWarn(clientId, cmdArguments) @@ -57,4 +58,4 @@ function commandRemoveWarn(clientId, cmdArguments) return true end -commands.addadmin("dewarn", commandRemoveWarn, "R", "remove a warning for a certain player", "^9[^3name|slot#^9] ^9[^3warn#^9]", function() return (settings.get("g_warnHistory") == 0 or not db.isconnected()) end) \ No newline at end of file +commands.addadmin("dewarn", commandRemoveWarn, auth.PERM_WARN, "remove a warning for a certain player", "^9[^3name|slot#^9] ^9[^3warn#^9]", function() return (settings.get("g_warnHistory") == 0 or not db.isconnected()) end) diff --git a/luascripts/commands/admin/enablevote.lua b/luascripts/commands/admin/enablevote.lua index b3ae804..0ddbb87 100644 --- a/luascripts/commands/admin/enablevote.lua +++ b/luascripts/commands/admin/enablevote.lua @@ -16,6 +16,7 @@ -- along with this program. If not, see . local commands = require "luascripts.wolfadmin.commands.commands" +local auth = require "luascripts.wolfadmin.auth.auth" local voting = require "luascripts.wolfadmin.game.voting" function commandEnableVote(clientId, cmdArguments) @@ -25,4 +26,4 @@ function commandEnableVote(clientId, cmdArguments) return true end -commands.addadmin("enablevote", commandEnableVote, "c", "enables next map voting") \ No newline at end of file +commands.addadmin("enablevote", commandEnableVote, auth.PERM_ENABLEVOTE, "enables next map voting") diff --git a/luascripts/commands/admin/greeting.lua b/luascripts/commands/admin/greeting.lua index 8f995b7..6a6d45d 100644 --- a/luascripts/commands/admin/greeting.lua +++ b/luascripts/commands/admin/greeting.lua @@ -16,6 +16,7 @@ -- along with this program. If not, see . local util = require "luascripts.wolfadmin.util.util" +local auth = require "luascripts.wolfadmin.auth.auth" local commands = require "luascripts.wolfadmin.commands.commands" local settings = require "luascripts.wolfadmin.util.settings" local greetings = require "luascripts.wolfadmin.players.greetings" @@ -29,4 +30,4 @@ function commandGreeting(clientId, cmdArguments) et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dgreeting: ^9you do not have a personal greeting.\";") end end -commands.addadmin("greeting", commandGreeting, "Q", "display your personal greeting, if you have one") \ No newline at end of file +commands.addadmin("greeting", commandGreeting, auth.PERM_GREETING, "display your personal greeting, if you have one") diff --git a/luascripts/commands/admin/help.lua b/luascripts/commands/admin/help.lua index 5003076..9aaf4c9 100644 --- a/luascripts/commands/admin/help.lua +++ b/luascripts/commands/admin/help.lua @@ -17,6 +17,7 @@ local commands = require "luascripts.wolfadmin.commands.commands" local settings = require "luascripts.wolfadmin.util.settings" +local auth = require "luascripts.wolfadmin.auth.auth" function commandHelp(clientId, cmdArguments) local cmds = commands.getadmin() @@ -25,7 +26,7 @@ function commandHelp(clientId, cmdArguments) local availableCommands = {} for command, data in pairs(cmds) do - if data["function"] and data["flag"] and et.G_shrubbot_permission(clientId, data["flag"]) == 1 and (not data["hidden"] or (type(data["hidden"]) == "function" and not data["hidden"]())) then + if data["function"] and data["flag"] and auth.isallowed(clientId, data["flag"]) == 1 and (not data["hidden"] or (type(data["hidden"]) == "function" and not data["hidden"]())) then table.insert(availableCommands, command) end end @@ -67,4 +68,4 @@ function commandHelp(clientId, cmdArguments) return false end -commands.addadmin("help", commandHelp, "h", "display commands available to you or help on a specific command", "^9(^hcommand^9)", true) +commands.addadmin("help", commandHelp, auth.PERM_HELP, "display commands available to you or help on a specific command", "^9(^hcommand^9)", true) diff --git a/luascripts/commands/admin/incognito.lua b/luascripts/commands/admin/incognito.lua index 8012e25..d74cf22 100644 --- a/luascripts/commands/admin/incognito.lua +++ b/luascripts/commands/admin/incognito.lua @@ -16,6 +16,7 @@ -- along with this program. If not, see . local commands = require "luascripts.wolfadmin.commands.commands" +local auth = require "luascripts.wolfadmin.auth.auth" local stats = require "luascripts.wolfadmin.players.stats" function commandIncognito(clientId, cmdArguments) @@ -37,7 +38,7 @@ function commandIncognito(clientId, cmdArguments) -- et.G_Print(string.format("%s %s %d %s\n", adminName, adminGUID, adminLevel, adminFlags)) if stats.get(clientId, "playerGUID") == adminGUID then - if et.G_shrubbot_permission(clientId, "@") ~= 1 then + if auth.isallowed(clientId, "@") ~= 1 then adminFlags = adminFlags.."+@" et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat "..clientId.." \"^dincognito: ^9you are now playing incognito.\";") @@ -74,4 +75,4 @@ function commandIncognito(clientId, cmdArguments) return true end -commands.addadmin("incognito", commandIncognito, "s", "fakes your level to guest (no aka)") \ No newline at end of file +commands.addadmin("incognito", commandIncognito, auth.PERM_INCOGNITO, "fakes your level to guest (no aka)") diff --git a/luascripts/commands/admin/kickbots.lua b/luascripts/commands/admin/kickbots.lua index 47b2084..fa6ef96 100644 --- a/luascripts/commands/admin/kickbots.lua +++ b/luascripts/commands/admin/kickbots.lua @@ -15,6 +15,7 @@ -- You should have received a copy of the GNU General Public License -- along with this program. If not, see . +local auth = require "luascripts.wolfadmin.auth.auth" local commands = require "luascripts.wolfadmin.commands.commands" local bots = require "luascripts.wolfadmin.game.bots" @@ -25,4 +26,4 @@ function commandBotsOff(clientId, cmdArguments) return true end -commands.addadmin("kickbots", commandBotsOff, "O", "kicks all bots from the game") \ No newline at end of file +commands.addadmin("kickbots", commandBotsOff, auth.PERM_BOTADMIN, "kicks all bots from the game") diff --git a/luascripts/commands/admin/listaliases.lua b/luascripts/commands/admin/listaliases.lua index 35bc116..ef61c53 100644 --- a/luascripts/commands/admin/listaliases.lua +++ b/luascripts/commands/admin/listaliases.lua @@ -18,6 +18,7 @@ local util = require "luascripts.wolfadmin.util.util" local settings = require "luascripts.wolfadmin.util.settings" local pagination = require "luascripts.wolfadmin.util.pagination" +local auth = require "luascripts.wolfadmin.auth.auth" local db = require "luascripts.wolfadmin.db.db" local commands = require "luascripts.wolfadmin.commands.commands" local stats = require "luascripts.wolfadmin.players.stats" @@ -47,11 +48,11 @@ function commandListAliases(clientId, cmdArguments) return true end - if et.G_shrubbot_permission(cmdClient, "!") == 1 then + if auth.isallowed(cmdClient, "!") == 1 then et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dlistaliases: ^7"..et.gentity_get(cmdClient, "pers.netname").." ^9is immune to this command.\";") return true - elseif et.G_shrubbot_level(cmdClient) > et.G_shrubbot_level(clientId) then + elseif auth.getlevel(cmdClient) > auth.getlevel(clientId) then et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dlistaliases: ^9sorry, but your intended victim has a higher admin level than you do.\";") return true @@ -76,4 +77,4 @@ function commandListAliases(clientId, cmdArguments) return true end -commands.addadmin("listaliases", commandListAliases, "f", "display all known aliases for a player", "^9[^3name|slot#^9] ^9(^hoffset^9)", function() return (not db.isconnected()) end) \ No newline at end of file +commands.addadmin("listaliases", commandListAliases, auth.PERM_FINGER, "display all known aliases for a player", "^9[^3name|slot#^9] ^9(^hoffset^9)", function() return (not db.isconnected()) end) diff --git a/luascripts/commands/admin/listlevels.lua b/luascripts/commands/admin/listlevels.lua index 56852c4..9018ce4 100644 --- a/luascripts/commands/admin/listlevels.lua +++ b/luascripts/commands/admin/listlevels.lua @@ -15,6 +15,7 @@ -- You should have received a copy of the GNU General Public License -- along with this program. If not, see . +local auth = require "luascripts.wolfadmin.auth.auth" local util = require "luascripts.wolfadmin.util.util" local settings = require "luascripts.wolfadmin.util.settings" local pagination = require "luascripts.wolfadmin.util.pagination" @@ -93,4 +94,4 @@ function commandListLevels(clientId, cmdArguments) return true end -commands.addadmin("listlevels", commandListLevels, "s", "display all levels on the server", (not db.isconnected() and nil or "^9(^3name|slot#^9) ^9(^hoffset^9)")) \ No newline at end of file +commands.addadmin("listlevels", commandListLevels, auth.PERM_LISTLEVELS, "display all levels on the server", (not db.isconnected() and nil or "^9(^3name|slot#^9) ^9(^hoffset^9)")) diff --git a/luascripts/commands/admin/listmaps.lua b/luascripts/commands/admin/listmaps.lua index e352cdc..f3f5a4a 100644 --- a/luascripts/commands/admin/listmaps.lua +++ b/luascripts/commands/admin/listmaps.lua @@ -15,6 +15,7 @@ -- You should have received a copy of the GNU General Public License -- along with this program. If not, see . +local auth = require "luascripts.wolfadmin.auth.auth" local util = require "luascripts.wolfadmin.util.util" local commands = require "luascripts.wolfadmin.commands.commands" local game = require "luascripts.wolfadmin.game.game" @@ -35,4 +36,4 @@ function commandListMaps(clientId, cmdArguments) return true end -commands.addadmin("listmaps", commandListMaps, "C", "display the maps in the rotation") \ No newline at end of file +commands.addadmin("listmaps", commandListMaps, auth.PERM_LISTMAPS, "display the maps in the rotation") diff --git a/luascripts/commands/admin/lock.lua b/luascripts/commands/admin/lock.lua index e30c500..06e0c6e 100644 --- a/luascripts/commands/admin/lock.lua +++ b/luascripts/commands/admin/lock.lua @@ -15,6 +15,7 @@ -- You should have received a copy of the GNU General Public License -- along with this program. If not, see . +local auth = require "luascripts.wolfadmin.auth.auth" local util = require "luascripts.wolfadmin.util.util" local constants = require "luascripts.wolfadmin.util.constants" local commands = require "luascripts.wolfadmin.commands.commands" @@ -37,4 +38,4 @@ function commandLock(clientId, cmdArguments) return false end -commands.addadmin("lock", commandLock, "K", "lock one or all of the teams from players joining", "^9[^3r|b|s|all#^9]", true) \ No newline at end of file +commands.addadmin("lock", commandLock, auth.PERM_LOCKTEAM, "lock one or all of the teams from players joining", "^9[^3r|b|s|all#^9]", true) diff --git a/luascripts/commands/admin/needbots.lua b/luascripts/commands/admin/needbots.lua index 9f8f077..02c85e2 100644 --- a/luascripts/commands/admin/needbots.lua +++ b/luascripts/commands/admin/needbots.lua @@ -15,6 +15,7 @@ -- You should have received a copy of the GNU General Public License -- along with this program. If not, see . +local auth = require "luascripts.wolfadmin.auth.auth" local commands = require "luascripts.wolfadmin.commands.commands" local bots = require "luascripts.wolfadmin.game.bots" @@ -25,4 +26,4 @@ function commandBotsOn(clientId, cmdArguments) return true end -commands.addadmin("needbots", commandBotsOn, "O", "adds bots to the game") \ No newline at end of file +commands.addadmin("needbots", commandBotsOn, auth.PERM_BOTADMIN, "adds bots to the game") diff --git a/luascripts/commands/admin/plock.lua b/luascripts/commands/admin/plock.lua index 3b3dbf8..fa20e09 100644 --- a/luascripts/commands/admin/plock.lua +++ b/luascripts/commands/admin/plock.lua @@ -15,6 +15,7 @@ -- You should have received a copy of the GNU General Public License -- along with this program. If not, see . +local auth = require "luascripts.wolfadmin.auth.auth" local util = require "luascripts.wolfadmin.util.util" local commands = require "luascripts.wolfadmin.commands.commands" local admin = require "luascripts.wolfadmin.admin.admin" @@ -45,11 +46,11 @@ function commandPlayerLock(clientId, cmdArguments) et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dplock: ^7"..et.gentity_get(cmdClient, "pers.netname").." ^9is already locked to a team.\";") return true - elseif et.G_shrubbot_permission(cmdClient, "!") == 1 then + elseif auth.isallowed(cmdClient, "!") == 1 then et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dplock: ^7"..et.gentity_get(cmdClient, "pers.netname").." ^9is immune to this command.\";") return true - elseif et.G_shrubbot_level(cmdClient) > et.G_shrubbot_level(clientId) then + elseif auth.getlevel(cmdClient) > auth.getlevel(clientId) then et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dplock: ^9sorry, but your intended victim has a higher admin level than you do.\";") return true @@ -61,4 +62,4 @@ function commandPlayerLock(clientId, cmdArguments) return true end -commands.addadmin("plock", commandPlayerLock, "K", "locks a player to a specific team", "^9[^3name|slot#^9]") \ No newline at end of file +commands.addadmin("plock", commandPlayerLock, auth.PERM_LOCKPLAYER, "locks a player to a specific team", "^9[^3name|slot#^9]") diff --git a/luascripts/commands/admin/punlock.lua b/luascripts/commands/admin/punlock.lua index 6f0b393..5c34522 100644 --- a/luascripts/commands/admin/punlock.lua +++ b/luascripts/commands/admin/punlock.lua @@ -15,6 +15,7 @@ -- You should have received a copy of the GNU General Public License -- along with this program. If not, see . +local auth = require "luascripts.wolfadmin.auth.auth" local util = require "luascripts.wolfadmin.util.util" local commands = require "luascripts.wolfadmin.commands.commands" local admin = require "luascripts.wolfadmin.admin.admin" @@ -53,4 +54,4 @@ function commandPlayerUnlock(clientId, cmdArguments) return true end -commands.addadmin("punlock", commandPlayerUnlock, "K", "unlocks a player", "^9[^3name|slot#^9]") \ No newline at end of file +commands.addadmin("punlock", commandPlayerUnlock, auth.PERM_LOCKPLAYER, "unlocks a player", "^9[^3name|slot#^9]") diff --git a/luascripts/commands/admin/putbots.lua b/luascripts/commands/admin/putbots.lua index 3732be6..5fd5943 100644 --- a/luascripts/commands/admin/putbots.lua +++ b/luascripts/commands/admin/putbots.lua @@ -15,6 +15,7 @@ -- You should have received a copy of the GNU General Public License -- along with this program. If not, see . +local auth = require "luascripts.wolfadmin.auth.auth" local constants = require "luascripts.wolfadmin.util.constants" local util = require "luascripts.wolfadmin.util.util" local balancer = require "luascripts.wolfadmin.admin.balancer" @@ -51,4 +52,4 @@ function commandPutBots(clientId, cmdArguments) return true end -commands.addadmin("putbots", commandPutBots, "p", "puts all bots into a specific team", "^9[r|b|s]") \ No newline at end of file +commands.addadmin("putbots", commandPutBots, auth.PERM_PUT, "puts all bots into a specific team", "^9[r|b|s]") diff --git a/luascripts/commands/admin/readconfig.lua b/luascripts/commands/admin/readconfig.lua index 6baaff0..c84dc8a 100644 --- a/luascripts/commands/admin/readconfig.lua +++ b/luascripts/commands/admin/readconfig.lua @@ -15,6 +15,7 @@ -- You should have received a copy of the GNU General Public License -- along with this program. If not, see . +local auth = require "luascripts.wolfadmin.auth.auth" local settings = require "luascripts.wolfadmin.util.settings" local commands = require "luascripts.wolfadmin.commands.commands" local rules = require "luascripts.wolfadmin.admin.rules" @@ -29,4 +30,4 @@ function commandReadconfig(clientId, cmdArguments) return false end -commands.addadmin("readconfig", commandReadconfig, "G", "reloads the shrubbot config file and refreshes user flags", nil, true) \ No newline at end of file +commands.addadmin("readconfig", commandReadconfig, auth.PERM_READCONFIG, "reloads the shrubbot config file and refreshes user flags", nil, true) diff --git a/luascripts/commands/admin/resetsprees.lua b/luascripts/commands/admin/resetsprees.lua index efdeb24..a998065 100644 --- a/luascripts/commands/admin/resetsprees.lua +++ b/luascripts/commands/admin/resetsprees.lua @@ -15,6 +15,7 @@ -- You should have received a copy of the GNU General Public License -- along with this program. If not, see . +local auth = require "luascripts.wolfadmin.auth.auth" local db = require "luascripts.wolfadmin.db.db" local commands = require "luascripts.wolfadmin.commands.commands" local game = require "luascripts.wolfadmin.game.game" @@ -39,4 +40,4 @@ function commandResetSprees(clientId, cmdArguments) return true end -commands.addadmin("resetsprees", commandResetSprees, "G", "resets the spree records") \ No newline at end of file +commands.addadmin("resetsprees", commandResetSprees, auth.PERM_READCONFIG, "resets the spree records") diff --git a/luascripts/commands/admin/rules.lua b/luascripts/commands/admin/rules.lua index 47d1ab6..325d9b3 100644 --- a/luascripts/commands/admin/rules.lua +++ b/luascripts/commands/admin/rules.lua @@ -15,6 +15,7 @@ -- You should have received a copy of the GNU General Public License -- along with this program. If not, see . +local auth = require "luascripts.wolfadmin.auth.auth" local commands = require "luascripts.wolfadmin.commands.commands" local rules = require "luascripts.wolfadmin.admin.rules" @@ -42,4 +43,4 @@ function commandRules(clientId, cmdArguments) return true end -commands.addadmin("rules", commandRules, "C", "display the rules on the server", "^9(^hrule^9)") \ No newline at end of file +commands.addadmin("rules", commandRules, auth.PERM_LISTRULES, "display the rules on the server", "^9(^hrule^9)") diff --git a/luascripts/commands/admin/setlevel.lua b/luascripts/commands/admin/setlevel.lua index 3ed8eba..5111eb1 100644 --- a/luascripts/commands/admin/setlevel.lua +++ b/luascripts/commands/admin/setlevel.lua @@ -15,6 +15,7 @@ -- You should have received a copy of the GNU General Public License -- along with this program. If not, see . +local auth = require "luascripts.wolfadmin.auth.auth" local settings = require "luascripts.wolfadmin.util.settings" local db = require "luascripts.wolfadmin.db.db" local commands = require "luascripts.wolfadmin.commands.commands" @@ -28,22 +29,54 @@ function commandSetLevel(clientId, cmdArguments) else cmdClient = tonumber(cmdArguments[1]) end - + if cmdClient == -1 then return false elseif not et.gentity_get(cmdClient, "pers.netname") then return false end - - -- plays a promotion sound - et.trap_SendConsoleCommand(et.EXEC_APPEND, "playsound \"/sound/vo/general/axis/hq_promogen.wav\";") - - if db.isconnected() then - cmdArguments[2] = tonumber(cmdArguments[2]) or 0 - - admin.setPlayerLevel(cmdClient, tonumber(cmdArguments[2]), clientId) - end - + + cmdArguments[2] = tonumber(cmdArguments[2]) or 0 + + admin.setPlayerLevel(cmdClient, tonumber(cmdArguments[2]), clientId) + return false end -commands.addadmin("setlevel", commandSetLevel, "s", "sets the admin level of a player", "^9[^3name|slot#^9] ^9[^3level^9]", true) \ No newline at end of file +commands.addadmin("setlevel", commandSetLevel, auth.PERM_SETLEVEL, "sets the admin level of a player", "^9[^3name|slot#^9] ^9[^3level^9]", (settings.get("g_standalone") == 0 and db.isconnected())) + +function commandSetLevel(clientId, cmdArguments) + if cmdArguments[1] == nil then + et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dsetlevel usage: "..commands.getadmin("setlevel")["syntax"].."\";") + + return true + elseif tonumber(cmdArguments[1]) == nil then + cmdClient = et.ClientNumberFromString(cmdArguments[1]) + else + cmdClient = tonumber(cmdArguments[1]) + end + + if cmdClient == -1 then + et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dsetlevel: ^9no or multiple matches for '^7"..cmdArguments[1].."^9'.\";") + + return true + elseif not et.gentity_get(cmdClient, "pers.netname") then + et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dsetlevel: ^9no connected player by that name or slot #\";") + + return true + end + + if auth.getlevel(cmdClient) > auth.getlevel(clientId) then + et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dsetlevel: ^9sorry, but your intended victim has a higher admin level than you do.\";") + + return true + end + + cmdArguments[2] = tonumber(cmdArguments[2]) or 0 + + admin.setPlayerLevel(cmdClient, tonumber(cmdArguments[2]), clientId) + + et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay -1 \"^dsetlevel: ^7"..et.gentity_get(cmdClient, "pers.netname").." ^9is now a level ^7"..cmdArguments[2].." ^9player.\";") + + return false +end +commands.addadmin("setlevel", commandSetLevel, auth.PERM_SETLEVEL, "sets the admin level of a player", "^9[^3name|slot#^9] ^9[^3level^9]", (settings.get("g_standalone") == 0 and db.isconnected())) diff --git a/luascripts/commands/admin/showwarns.lua b/luascripts/commands/admin/showwarns.lua index 520e0ce..fd30701 100644 --- a/luascripts/commands/admin/showwarns.lua +++ b/luascripts/commands/admin/showwarns.lua @@ -15,6 +15,7 @@ -- You should have received a copy of the GNU General Public License -- along with this program. If not, see . +local auth = require "luascripts.wolfadmin.auth.auth" local util = require "luascripts.wolfadmin.util.util" local settings = require "luascripts.wolfadmin.util.settings" local pagination = require "luascripts.wolfadmin.util.pagination" @@ -66,4 +67,4 @@ function commandShowWarns(clientId, cmdArguments) return true end -commands.addadmin("showwarns", commandShowWarns, "R", "display warnings for a specific player", "^9[^3name|slot#^9] ^9(^hoffset^9)", function() return (settings.get("g_warnHistory") == 0 or not db.isconnected()) end) \ No newline at end of file +commands.addadmin("showwarns", commandShowWarns, auth.PERM_LISTWARNS, "display warnings for a specific player", "^9[^3name|slot#^9] ^9(^hoffset^9)", function() return (settings.get("g_warnHistory") == 0 or not db.isconnected()) end) diff --git a/luascripts/commands/admin/sprees.lua b/luascripts/commands/admin/sprees.lua index 1784496..3bdfd3b 100644 --- a/luascripts/commands/admin/sprees.lua +++ b/luascripts/commands/admin/sprees.lua @@ -15,6 +15,7 @@ -- You should have received a copy of the GNU General Public License -- along with this program. If not, see . +local auth = require "luascripts.wolfadmin.auth.auth" local commands = require "luascripts.wolfadmin.commands.commands" local db = require "luascripts.wolfadmin.db.db" local sprees = require "luascripts.wolfadmin.game.sprees" @@ -44,4 +45,4 @@ function commandShowSprees(clientId, cmdArguments) return true end -commands.addadmin("sprees", commandShowSprees, "I", "display the current spree records") \ No newline at end of file +commands.addadmin("sprees", commandShowSprees, auth.PERM_LISTSPREES, "display the current spree records") diff --git a/luascripts/commands/admin/stats.lua b/luascripts/commands/admin/stats.lua index 9b0b457..5f426b0 100644 --- a/luascripts/commands/admin/stats.lua +++ b/luascripts/commands/admin/stats.lua @@ -15,6 +15,7 @@ -- You should have received a copy of the GNU General Public License -- along with this program. If not, see . +local auth = require "luascripts.wolfadmin.auth.auth" local util = require "luascripts.wolfadmin.util.util" local commands = require "luascripts.wolfadmin.commands.commands" @@ -94,4 +95,4 @@ function commandShowStats(clientId, cmdArguments) return true end -commands.addadmin("stats", commandShowStats, "I", "display the statistics for a specific player", "^9[^3name|slot#^9]") \ No newline at end of file +commands.addadmin("stats", commandShowStats, auth.PERM_LISTSTATS, "display the statistics for a specific player", "^9[^3name|slot#^9]") diff --git a/luascripts/commands/admin/unlock.lua b/luascripts/commands/admin/unlock.lua index 7a93a3b..244a2c7 100644 --- a/luascripts/commands/admin/unlock.lua +++ b/luascripts/commands/admin/unlock.lua @@ -15,6 +15,7 @@ -- You should have received a copy of the GNU General Public License -- along with this program. If not, see . +local auth = require "luascripts.wolfadmin.auth.auth" local util = require "luascripts.wolfadmin.util.util" local constants = require "luascripts.wolfadmin.util.constants" local commands = require "luascripts.wolfadmin.commands.commands" @@ -37,4 +38,4 @@ function commandUnlock(clientId, cmdArguments) return false end -commands.addadmin("unlock", commandUnlock, "K", "unlock one or all locked teams", "^9[^3r|b|s|all#^9]", true) \ No newline at end of file +commands.addadmin("unlock", commandUnlock, auth.PERM_LOCKTEAM, "unlock one or all locked teams", "^9[^3r|b|s|all#^9]", true) diff --git a/luascripts/commands/admin/vmute.lua b/luascripts/commands/admin/vmute.lua index dd5f8ba..d685ac7 100644 --- a/luascripts/commands/admin/vmute.lua +++ b/luascripts/commands/admin/vmute.lua @@ -15,6 +15,7 @@ -- You should have received a copy of the GNU General Public License -- along with this program. If not, see . +local auth = require "luascripts.wolfadmin.auth.auth" local util = require "luascripts.wolfadmin.util.util" local commands = require "luascripts.wolfadmin.commands.commands" local admin = require "luascripts.wolfadmin.admin.admin" @@ -49,7 +50,7 @@ function commandVoiceMute(clientId, cmdArguments) vmuteTime = util.getTimeFromString(cmdArguments[2]) elseif cmdArguments[2] then vmuteReason = table.concat(cmdArguments, " ", 2) - elseif et.G_shrubbot_permission(clientId, "8") ~= 1 then + elseif auth.isallowed(clientId, "8") ~= 1 then et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dvmute usage: "..commands.getadmin("vmute")["syntax"].."\";") return true @@ -59,11 +60,11 @@ function commandVoiceMute(clientId, cmdArguments) et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dvmute: ^7"..et.gentity_get(cmdClient, "pers.netname").." ^9is already muted.\";") return true - elseif et.G_shrubbot_permission(cmdClient, "!") == 1 then + elseif auth.isallowed(cmdClient, "!") == 1 then et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dvmute: ^7"..et.gentity_get(cmdClient, "pers.netname").." ^9is immune to this command.\";") return true - elseif et.G_shrubbot_level(cmdClient) > et.G_shrubbot_level(clientId) then + elseif auth.getlevel(cmdClient) > auth.getlevel(clientId) then et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dvmute: ^9sorry, but your intended victim has a higher admin level than you do.\";") return true @@ -75,4 +76,4 @@ function commandVoiceMute(clientId, cmdArguments) return true end -commands.addadmin("vmute", commandVoiceMute, "m", "voicemutes a player", "^9[^3name|slot#^9]") \ No newline at end of file +commands.addadmin("vmute", commandVoiceMute, auth.PERM_VOICEMUTE, "voicemutes a player", "^9[^3name|slot#^9]") diff --git a/luascripts/commands/admin/vunmute.lua b/luascripts/commands/admin/vunmute.lua index 5877309..4f83d95 100644 --- a/luascripts/commands/admin/vunmute.lua +++ b/luascripts/commands/admin/vunmute.lua @@ -15,6 +15,7 @@ -- You should have received a copy of the GNU General Public License -- along with this program. If not, see . +local auth = require "luascripts.wolfadmin.auth.auth" local commands = require "luascripts.wolfadmin.commands.commands" local admin = require "luascripts.wolfadmin.admin.admin" @@ -51,4 +52,4 @@ function commandVoiceUnmute(clientId, cmdArguments) return true end -commands.addadmin("vunmute", commandVoiceUnmute, "m", "unvoicemutes a player", "^9[^3name|slot#^9]") \ No newline at end of file +commands.addadmin("vunmute", commandVoiceUnmute, auth.PERM_VOICEMUTE, "unvoicemutes a player", "^9[^3name|slot#^9]") diff --git a/luascripts/commands/admin/warn.lua b/luascripts/commands/admin/warn.lua index 1b2d158..798dcba 100644 --- a/luascripts/commands/admin/warn.lua +++ b/luascripts/commands/admin/warn.lua @@ -15,6 +15,7 @@ -- You should have received a copy of the GNU General Public License -- along with this program. If not, see . +local auth = require "luascripts.wolfadmin.auth.auth" local settings = require "luascripts.wolfadmin.util.settings" local db = require "luascripts.wolfadmin.db.db" local commands = require "luascripts.wolfadmin.commands.commands" @@ -41,4 +42,4 @@ function commandAddWarn(clientId, cmdArguments) return false end -commands.addadmin("warn", commandAddWarn, "R", "warns a player by displaying the reason", "^9[^3name|slot#^9] ^9[^3reason^9]", true) \ No newline at end of file +commands.addadmin("warn", commandAddWarn, auth.PERM_WARN, "warns a player by displaying the reason", "^9[^3name|slot#^9] ^9[^3reason^9]", true) diff --git a/luascripts/commands/client/ac.lua b/luascripts/commands/client/ac.lua index 87ae5f5..15b1fed 100644 --- a/luascripts/commands/client/ac.lua +++ b/luascripts/commands/client/ac.lua @@ -15,6 +15,7 @@ -- You should have received a copy of the GNU General Public License -- along with this program. If not, see . +local auth = require "luascripts.wolfadmin.auth.auth" local commands = require "luascripts.wolfadmin.commands.commands" function commandAdminChat(clientId, cmdArguments) @@ -29,7 +30,7 @@ function commandAdminChat(clientId, cmdArguments) end for playerId = 0, et.trap_Cvar_Get("sv_maxclients") - 1 do - if wolfa_isPlayer(playerId) and et.G_shrubbot_permission(playerId, "~") == 1 then + if wolfa_isPlayer(playerId) and auth.isallowed(playerId, "~") == 1 then table.insert(recipients, playerId) end end @@ -45,5 +46,5 @@ function commandAdminChat(clientId, cmdArguments) return true end -commands.addclient("adminchat", commandAdminChat, "~", "[^2message^7]", true) -commands.addclient("ac", commandAdminChat, "~", "[^2message^7]", true) \ No newline at end of file +commands.addclient("adminchat", commandAdminChat, auth.PERM_ADMINCHAT, "[^2message^7]", true) +commands.addclient("ac", commandAdminChat, auth.PERM_ADMINCHAT, "[^2message^7]", true) diff --git a/luascripts/commands/client/pm.lua b/luascripts/commands/client/pm.lua index bdc7571..d6ab4ee 100644 --- a/luascripts/commands/client/pm.lua +++ b/luascripts/commands/client/pm.lua @@ -15,6 +15,7 @@ -- You should have received a copy of the GNU General Public License -- along with this program. If not, see . +local auth = require "luascripts.wolfadmin.auth.auth" local commands = require "luascripts.wolfadmin.commands.commands" local stats = require "luascripts.wolfadmin.players.stats" @@ -36,4 +37,4 @@ function commandPersonalMessage(clientId, cmdArguments) end end commands.addclient("pm", commandPersonalMessage, "", "", true) -commands.addclient("m", commandPersonalMessage, "", "", true) \ No newline at end of file +commands.addclient("m", commandPersonalMessage, "", "", true) diff --git a/luascripts/commands/client/r.lua b/luascripts/commands/client/r.lua index 366230d..3c48383 100644 --- a/luascripts/commands/client/r.lua +++ b/luascripts/commands/client/r.lua @@ -15,6 +15,7 @@ -- You should have received a copy of the GNU General Public License -- along with this program. If not, see . +local auth = require "luascripts.wolfadmin.auth.auth" local commands = require "luascripts.wolfadmin.commands.commands" local stats = require "luascripts.wolfadmin.players.stats" @@ -52,4 +53,4 @@ function commandR(clientId, cmdArguments) return true end -commands.addclient("r", commandR, "", "[^2message^7]", true) \ No newline at end of file +commands.addclient("r", commandR, "", "[^2message^7]", true) diff --git a/luascripts/commands/client/wolfadmin.lua b/luascripts/commands/client/wolfadmin.lua index 4c35801..161c1ea 100644 --- a/luascripts/commands/client/wolfadmin.lua +++ b/luascripts/commands/client/wolfadmin.lua @@ -15,6 +15,7 @@ -- You should have received a copy of the GNU General Public License -- along with this program. If not, see . +local auth = require "luascripts.wolfadmin.auth.auth" local commands = require "luascripts.wolfadmin.commands.commands" function commandWolfAdmin(clientId, cmdArguments) @@ -27,4 +28,4 @@ function commandWolfAdmin(clientId, cmdArguments) return true end -commands.addclient("wolfadmin", commandWolfAdmin, "", "") \ No newline at end of file +commands.addclient("wolfadmin", commandWolfAdmin, "", "") diff --git a/luascripts/commands/commands.lua b/luascripts/commands/commands.lua index 17a596a..5d5dc80 100644 --- a/luascripts/commands/commands.lua +++ b/luascripts/commands/commands.lua @@ -21,6 +21,7 @@ local util = require "luascripts.wolfadmin.util.util" local events = require "luascripts.wolfadmin.util.events" local files = require "luascripts.wolfadmin.util.files" local admin = require "luascripts.wolfadmin.admin.admin" +local auth = require "luascripts.wolfadmin.auth.auth" local stats = require "luascripts.wolfadmin.players.stats" local commands = {} @@ -194,7 +195,7 @@ function commands.onclientcommand(clientId, cmdText) -- mod-specific or custom commands loading if clientcmds[wolfCmd] and clientcmds[wolfCmd]["function"] and clientcmds[wolfCmd]["flag"] then - if clientcmds[wolfCmd]["flag"] == "" or et.G_shrubbot_permission(clientId, clientcmds[wolfCmd]["flag"]) == 1 then + if clientcmds[wolfCmd]["flag"] == "" or auth.isallowed(clientId, clientcmds[wolfCmd]["flag"]) == 1 then for i = 1, et.trap_Argc() - 1 do cmdArguments[i] = et.trap_Argv(i) end @@ -272,7 +273,7 @@ function commands.onclientcommand(clientId, cmdText) clientCmd = string.lower(clientCmd) if clientcmds[clientCmd] and clientcmds[clientCmd]["function"] and clientcmds[clientCmd]["chat"] then - if clientcmds[clientCmd]["flag"] == "" or et.G_shrubbot_permission(clientId, clientcmds[clientCmd]["flag"]) == 1 then + if clientcmds[clientCmd]["flag"] == "" or auth.isallowed(clientId, clientcmds[clientCmd]["flag"]) == 1 then return clientcmds[clientCmd]["function"](clientId, cmdArguments) and 1 or 0 end end @@ -311,8 +312,8 @@ function commands.onclientcommand(clientId, cmdText) shrubCmd = string.lower(shrubCmd) if admincmds[shrubCmd] and admincmds[shrubCmd]["function"] and admincmds[shrubCmd]["flag"] then - if wolfCmd == "say" or (((wolfCmd == "say_team" and et.gentity_get(cmdClient, "sess.sessionTeam") ~= et.TEAM_SPECTATORS) or wolfCmd == "say_buddy") and et.G_shrubbot_permission(clientId, "9") == 1) or (wolfCmd == "!"..shrubCmd and et.G_shrubbot_permission(clientId, "3") == 1) then - if admincmds[shrubCmd]["flag"] ~= "" and et.G_shrubbot_permission(clientId, admincmds[shrubCmd]["flag"]) == 1 then + if wolfCmd == "say" or (((wolfCmd == "say_team" and et.gentity_get(cmdClient, "sess.sessionTeam") ~= et.TEAM_SPECTATORS) or wolfCmd == "say_buddy") and auth.isallowed(clientId, auth.PERM_TEAMCMDS) == 1) or (wolfCmd == "!"..shrubCmd and auth.isallowed(clientId, auth.PERM_SILENTCMDS) == 1) then + if admincmds[shrubCmd]["flag"] ~= "" and auth.isallowed(clientId, admincmds[shrubCmd]["flag"]) == 1 then local isFinished = admincmds[shrubCmd]["function"](clientId, cmdArguments) if not admincmds[shrubCmd]["hidden"] then @@ -333,4 +334,4 @@ function commands.onclientcommand(clientId, cmdText) end events.handle("onClientCommand", commands.onclientcommand) -return commands \ No newline at end of file +return commands diff --git a/luascripts/db/mysql.lua b/luascripts/db/mysql.lua index 6fa1a4b..6bd45a7 100644 --- a/luascripts/db/mysql.lua +++ b/luascripts/db/mysql.lua @@ -18,6 +18,7 @@ local constants = require "luascripts.wolfadmin.util.constants" local util = require "luascripts.wolfadmin.util.util" local settings = require "luascripts.wolfadmin.util.settings" +local tables = require "luascripts.wolfadmin.util.tables" local stats = require "luascripts.wolfadmin.players.stats" @@ -34,10 +35,14 @@ function mysql.addplayer(guid, ip) cur = assert(con:execute("INSERT INTO `player` (`guid`, `ip`) VALUES ('"..util.escape(guid).."', '"..util.escape(ip).."')")) end -function mysql.updateplayer(guid, ip) +function mysql.updateplayerip(guid, ip) cur = assert(con:execute("UPDATE `player` SET `ip`='"..util.escape(ip).."' WHERE `guid`='"..util.escape(guid).."'")) end +function mysql.updateplayerlevel(id, level) + cur = assert(con:execute("UPDATE `player` SET `level_id`='"..tonumber(level).."' WHERE `id`='"..tonumber(id).."'")) +end + function mysql.getplayerid(clientid) return mysql.getplayer(stats.get(clientid, "playerGUID"))["id"] end @@ -51,15 +56,29 @@ function mysql.getplayer(guid) return player end +-- levels +function mysql.addlevel(id, name) + cur = assert(con:execute("INSERT INTO `level` (`id`, `name`) VALUES ('"..tonumber(id).."', '"..util.escape(name).."')")) +end + +function mysql.updatelevel(id, name) + cur = assert(con:execute("UPDATE `level` SET `name`='"..util.escape(name).."' WHERE `id`='"..tonumber(id).."'")) +end + +function mysql.getlevel(id) + cur = assert(con:execute("SELECT * FROM `level` WHERE `id`='"..tonumber(id).."'")) + + local level = cur:fetch({}, "a") + cur:close() + + return level +end + -- aliases function mysql.addalias(playerid, alias, lastused) cur = assert(con:execute("INSERT INTO `alias` (`player_id`, `alias`, `cleanalias`, `lastused`, `used`) VALUES ("..tonumber(playerid)..", '"..util.escape(alias).."', '"..util.escape(util.removeColors(alias)).."', "..tonumber(lastused)..", 1)")) end -function mysql.updatecleanalias(aliasid, alias) - cur = assert(con:execute("UPDATE `alias` SET `cleanalias`='"..util.escape(util.removeColors(alias)).."' WHERE `id`='"..util.escape(aliasid).."'")) -end - function mysql.updatealias(aliasid, lastused) cur = assert(con:execute("UPDATE `alias` SET `lastused`="..tonumber(lastused)..", `used`=`used`+1 WHERE `id`='"..util.escape(aliasid).."'")) end @@ -83,7 +102,7 @@ function mysql.getaliases(playerid, limit, offset) local row = cur:fetch({}, "a") while row do - table.insert(aliases, row) + table.insert(aliases, tables.copy(row)) row = cur:fetch(row, "a") end @@ -119,13 +138,13 @@ function mysql.getlastalias(playerid) return alias end --- setlevels +-- level history function mysql.addsetlevel(playerid, level, adminid, datetime) - cur = assert(con:execute("INSERT INTO `level` (`player_id`, `level`, `admin_id`, `datetime`) VALUES ("..tonumber(playerid)..", "..tonumber(level)..", "..tonumber(adminid)..", "..tonumber(datetime)..")")) + cur = assert(con:execute("INSERT INTO `player_level` (`player_id`, `level`, `admin_id`, `datetime`) VALUES ("..tonumber(playerid)..", "..tonumber(level)..", "..tonumber(adminid)..", "..tonumber(datetime)..")")) end function mysql.getlevelscount(playerid) - cur = assert(con:execute("SELECT COUNT(`id`) AS `count` FROM `level` WHERE `player_id`="..tonumber(playerid).."")) + cur = assert(con:execute("SELECT COUNT(`id`) AS `count` FROM `player_level` WHERE `player_id`="..tonumber(playerid).."")) local count = tonumber(cur:fetch({}, "a")["count"]) cur:close() @@ -137,13 +156,13 @@ function mysql.getlevels(playerid, limit, offset) limit = limit or 30 offset = offset or 0 - cur = assert(con:execute("SELECT * FROM `level` WHERE `player_id`="..tonumber(playerid).." LIMIT "..tonumber(limit).." OFFSET "..tonumber(offset))) + cur = assert(con:execute("SELECT * FROM `player_level` WHERE `player_id`="..tonumber(playerid).." LIMIT "..tonumber(limit).." OFFSET "..tonumber(offset))) local levels = {} local row = cur:fetch({}, "a") while row do - table.insert(levels, row) + table.insert(levels, tables.copy(row)) row = cur:fetch(row, "a") end @@ -180,7 +199,7 @@ function mysql.getwarns(playerid, limit, offset) local row = cur:fetch({}, "a") while row do - table.insert(warns, row) + table.insert(warns, tables.copy(row)) row = cur:fetch(row, "a") end @@ -309,4 +328,4 @@ end function mysql.close(doSave) end -return mysql \ No newline at end of file +return mysql diff --git a/luascripts/db/sqlite3.lua b/luascripts/db/sqlite3.lua index 58f7e29..2be688c 100644 --- a/luascripts/db/sqlite3.lua +++ b/luascripts/db/sqlite3.lua @@ -18,6 +18,7 @@ local constants = require "luascripts.wolfadmin.util.constants" local util = require "luascripts.wolfadmin.util.util" local settings = require "luascripts.wolfadmin.util.settings" +local tables = require "luascripts.wolfadmin.util.tables" local stats = require "luascripts.wolfadmin.players.stats" @@ -34,10 +35,14 @@ function sqlite3.addplayer(guid, ip) cur = assert(con:execute("INSERT INTO `player` (`guid`, `ip`) VALUES ('"..util.escape(guid).."', '"..util.escape(ip).."')")) end -function sqlite3.updateplayer(guid, ip) +function sqlite3.updateplayerip(guid, ip) cur = assert(con:execute("UPDATE `player` SET `ip`='"..util.escape(ip).."' WHERE `guid`='"..util.escape(guid).."'")) end +function sqlite3.updateplayerlevel(id, level) + cur = assert(con:execute("UPDATE `player` SET `level_id`='"..tonumber(level).."' WHERE `id`='"..tonumber(id).."'")) +end + function sqlite3.getplayerid(clientid) return sqlite3.getplayer(stats.get(clientid, "playerGUID"))["id"] end @@ -51,15 +56,29 @@ function sqlite3.getplayer(guid) return player end +-- levels +function sqlite3.addlevel(id, name) + cur = assert(con:execute("INSERT INTO `level` (`id`, `name`) VALUES ('"..tonumber(id).."', '"..util.escape(name).."')")) +end + +function sqlite3.updatelevel(id, name) + cur = assert(con:execute("UPDATE `level` SET `name`='"..util.escape(name).."' WHERE `id`='"..tonumber(id).."'")) +end + +function sqlite3.getlevel(id) + cur = assert(con:execute("SELECT * FROM `level` WHERE `id`='"..tonumber(id).."'")) + + local level = cur:fetch({}, "a") + cur:close() + + return level +end + -- aliases function sqlite3.addalias(playerid, alias, lastused) cur = assert(con:execute("INSERT INTO `alias` (`player_id`, `alias`, `cleanalias`, `lastused`, `used`) VALUES ("..tonumber(playerid)..", '"..util.escape(alias).."', '"..util.escape(util.removeColors(alias)).."', "..tonumber(lastused)..", 1)")) end -function sqlite3.updatecleanalias(aliasid, alias) - cur = assert(con:execute("UPDATE `alias` SET `cleanalias`='"..util.escape(util.removeColors(alias)).."' WHERE `id`='"..util.escape(aliasid).."'")) -end - function sqlite3.updatealias(aliasid, lastused) cur = assert(con:execute("UPDATE `alias` SET `lastused`="..tonumber(lastused)..", `used`=`used`+1 WHERE `id`='"..util.escape(aliasid).."'")) end @@ -83,7 +102,7 @@ function sqlite3.getaliases(playerid, limit, offset) local row = cur:fetch({}, "a") while row do - table.insert(aliases, row) + table.insert(aliases, tables.copy(row)) row = cur:fetch(row, "a") end @@ -119,13 +138,13 @@ function sqlite3.getlastalias(playerid) return alias end --- setlevels +-- level history function sqlite3.addsetlevel(playerid, level, adminid, datetime) - cur = assert(con:execute("INSERT INTO `level` (`player_id`, `level`, `admin_id`, `datetime`) VALUES ("..tonumber(playerid)..", "..tonumber(level)..", "..tonumber(adminid)..", "..tonumber(datetime)..")")) + cur = assert(con:execute("INSERT INTO `player_level` (`player_id`, `level`, `admin_id`, `datetime`) VALUES ("..tonumber(playerid)..", "..tonumber(level)..", "..tonumber(adminid)..", "..tonumber(datetime)..")")) end function sqlite3.getlevelscount(playerid) - cur = assert(con:execute("SELECT COUNT(`id`) AS `count` FROM `level` WHERE `player_id`="..tonumber(playerid).."")) + cur = assert(con:execute("SELECT COUNT(`id`) AS `count` FROM `player_level` WHERE `player_id`="..tonumber(playerid).."")) local count = tonumber(cur:fetch({}, "a")["count"]) cur:close() @@ -137,13 +156,13 @@ function sqlite3.getlevels(playerid, limit, offset) limit = limit or 30 offset = offset or 0 - cur = assert(con:execute("SELECT * FROM `level` WHERE `player_id`="..tonumber(playerid).." LIMIT "..tonumber(limit).." OFFSET "..tonumber(offset))) + cur = assert(con:execute("SELECT * FROM `player_level` WHERE `player_id`="..tonumber(playerid).." LIMIT "..tonumber(limit).." OFFSET "..tonumber(offset))) local levels = {} local row = cur:fetch({}, "a") while row do - table.insert(levels, row) + table.insert(levels, tables.copy(row)) row = cur:fetch(row, "a") end @@ -180,7 +199,7 @@ function sqlite3.getwarns(playerid, limit, offset) local row = cur:fetch({}, "a") while row do - table.insert(warns, row) + table.insert(warns, tables.copy(row)) row = cur:fetch(row, "a") end @@ -312,4 +331,4 @@ end function sqlite3.close(doSave) end -return sqlite3 \ No newline at end of file +return sqlite3 diff --git a/luascripts/game/game.lua b/luascripts/game/game.lua index efaab62..8018183 100644 --- a/luascripts/game/game.lua +++ b/luascripts/game/game.lua @@ -104,11 +104,11 @@ function game.onrevive(clientMedic, clientVictim) end events.handle("onPlayerRevive", game.onrevive) -function game.onbegin(clientId, firstTime) +function game.onready(clientId, firstTime) if firstTime and settings.get("g_welcomeMessage") ~= "" then et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat "..clientId.." \""..settings.get("g_welcomeMessage").."\";") end end -events.handle("onClientBegin", game.onbegin) +events.handle("onPlayerReady", game.onready) -return game \ No newline at end of file +return game diff --git a/luascripts/game/voting.lua b/luascripts/game/voting.lua index 6d22782..f05a15e 100644 --- a/luascripts/game/voting.lua +++ b/luascripts/game/voting.lua @@ -15,6 +15,7 @@ -- You should have received a copy of the GNU General Public License -- along with this program. If not, see . +local auth = require "luascripts.wolfadmin.auth.auth" local constants = require "luascripts.wolfadmin.util.constants" local util = require "luascripts.wolfadmin.util.util" local events = require "luascripts.wolfadmin.util.events" @@ -88,7 +89,7 @@ events.handle("onGameStateChange", voting.ongamestatechange) function voting.oncallvote(clientId, type, args) if et.gentity_get(clientId, "sess.sessionTeam") == constants.TEAM_SPECTATORS or args[1] == "?" then return 0 - elseif voting.isrestricted(type) and et.G_shrubbot_permission(clientId, "%") ~= 1 then + elseif voting.isrestricted(type) and auth.isallowed(clientId, PERM_NOVOTELIMIT) ~= 1 then et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"callvote: you are not allowed to call this type of vote.\";") et.trap_SendServerCommand(clientId, "cp \"You are not allowed to call this type of vote.") diff --git a/luascripts/main.lua b/luascripts/main.lua index 0e8df8a..3262907 100644 --- a/luascripts/main.lua +++ b/luascripts/main.lua @@ -38,8 +38,9 @@ local sprees = require "luascripts.wolfadmin.game.sprees" local teams = require "luascripts.wolfadmin.game.teams" local voting = require "luascripts.wolfadmin.game.voting" -local stats = require "luascripts.wolfadmin.players.stats" local greetings = require "luascripts.wolfadmin.players.greetings" +local players = require "luascripts.wolfadmin.players.players" +local stats = require "luascripts.wolfadmin.players.stats" local version = "1.1.0-beta" local release = "26 August 2016" @@ -89,17 +90,11 @@ function et_ConsoleCommand(cmdText) end function et_ClientConnect(clientId, firstTime, isBot) - if firstTime == 1 then - stats.set(clientId, "newConnection", true) - end - - return events.trigger("onClientConnect", clientId, (firstTime == 1), (isBot == 1)) + return events.trigger("onClientConnectAttempt", clientId, (firstTime == 1), (isBot == 1)) end function et_ClientBegin(clientId) - events.trigger("onClientBegin", clientId, stats.get(clientId, "newConnection")) - - stats.set(clientId, "newConnection", false) + events.trigger("onClientBegin", clientId) end function et_ClientDisconnect(clientId) diff --git a/luascripts/players/greetings.lua b/luascripts/players/greetings.lua index 6ae270d..333a00e 100644 --- a/luascripts/players/greetings.lua +++ b/luascripts/players/greetings.lua @@ -15,6 +15,8 @@ -- You should have received a copy of the GNU General Public License -- along with this program. If not, see . +local auth = require "luascripts.wolfadmin.auth.auth" + local constants = require "luascripts.wolfadmin.util.constants" local util = require "luascripts.wolfadmin.util.util" local events = require "luascripts.wolfadmin.util.events" @@ -29,9 +31,9 @@ local userGreetings = {} local levelGreetings = {} function greetings.get(clientId) - local lvl = et.G_shrubbot_level(clientId) + local lvl = auth.getlevel(clientId) - if et.G_shrubbot_permission(clientId, "@") ~= 1 then + if auth.isallowed(clientId, auth.PERM_INCOGNITO) ~= 1 then if userGreetings[stats.get(clientId, "playerGUID")] ~= nil then return userGreetings[stats.get(clientId, "playerGUID")] elseif levelGreetings[lvl] ~= nil then @@ -105,15 +107,15 @@ function greetings.oninit(levelTime, randomSeed, restartMap) if settings.get("g_fileGreetings") ~= "" then greetings.load() - events.handle("onClientBegin", greetings.onbegin) + events.handle("onPlayerReady", greetings.onready) end end events.handle("onGameInit", greetings.oninit) -function greetings.onbegin(clientId, firstTime) +function greetings.onready(clientId, firstTime) if firstTime and (not stats.get(clientId, "isBot") or settings.get("g_botGreetings") == 1) then greetings.show(clientId) end end -return greetings \ No newline at end of file +return greetings diff --git a/luascripts/players/players.lua b/luascripts/players/players.lua new file mode 100644 index 0000000..b5365df --- /dev/null +++ b/luascripts/players/players.lua @@ -0,0 +1,117 @@ + +-- WolfAdmin module for Wolfenstein: Enemy Territory servers. +-- Copyright (C) 2015-2016 Timo 'Timothy' Smit + +-- This program is free software: you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation, either version 3 of the License, or +-- at your option any later version. + +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. + +-- You should have received a copy of the GNU General Public License +-- along with this program. If not, see . + +local db = require "luascripts.wolfadmin.db.db" + +local stats = require "luascripts.wolfadmin.players.stats" + +local events = require "luascripts.wolfadmin.util.events" + +local players = {} + +function players.onconnect(clientId, firstTime, isBot) + local clientInfo = et.trap_GetUserinfo(clientId) + + -- name is NOT yet set in pers.netname, so get all info out of infostring + stats.set(clientId, "playerName", et.Info_ValueForKey(clientInfo, "name")) + stats.set(clientId, "playerGUID", et.Info_ValueForKey(clientInfo, "cl_guid")) + stats.set(clientId, "playerIP", string.gsub(et.Info_ValueForKey(clientInfo, "ip"), ":%d*", "")) + stats.set(clientId, "playerTeam", tonumber(et.gentity_get(clientId, "sess.sessionTeam"))) + stats.set(clientId, "isBot", isBot) + + if firstTime == 1 then + stats.set(clientId, "newConnection", true) + + if db.isconnected() then + local player = db.getplayer(stats.get(clientId, "playerGUID")) + + if player then + local guid = stats.get(clientId, "playerGUID") + local ip = stats.get(clientId, "playerIP") + + db.updateplayerip(guid, ip) + else + local guid = stats.get(clientId, "playerGUID") + local ip = stats.get(clientId, "playerIP") + + db.addplayer(guid, ip) + end + + local name = stats.get(clientId, "playerName") + local alias = db.getaliasbyname(player["id"], name) + + if alias then + db.updatealias(alias["id"], os.time()) + else + db.addalias(playerid, name, os.time()) + end + end + end +end +events.handle("onClientConnect", players.onconnect) + +function players.onbegin(clientId) + -- TODO: + -- new approach: load necessary data in onClientConnect event handlers, + -- load rest in onClientBegin handlers (avoids useless loading of stats, + -- less coupling between main.lua and stats.lua) + -- ensures that all data is loaded from this moment on + + events.trigger("onPlayerReady", clientId, stats.get(clientId, "newConnection")) + + stats.set(clientId, "newConnection", false) +end +events.handle("onClientBegin", players.onbegin) + +function players.ondisconnect(clientId) + stats.remove(clientId) +end +events.handle("onClientDisconnect", players.ondisconnect) + +function players.onnamechange(clientId, old, new) + -- TODO: on some mods, this message is already printed + -- known: old NQ versions, Legacy + et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay -1 \""..old.." ^7is now known as "..new.."\";") + + if db.isconnected() then + local playerid = db.getplayer(stats.get(clientId, "playerGUID"))["id"] + local name = stats.get(clientId, "playerName") + local alias = db.getaliasbyname(playerid, name) + + if alias then + db.updatealias(alias["id"], os.time()) + else + db.addalias(playerid, name, os.time()) + end + end +end +events.handle("onClientNameChange", players.onnamechange) + +function players.oninfochange(clientId) + local clientInfo = et.trap_GetUserinfo(clientId) + local old = stats.get(clientId, "playerTeam") + local new = tonumber(et.gentity_get(clientId, "sess.sessionTeam")) + + if new ~= old then + stats.set(clientId, "playerTeam", new) + + events.trigger("onClientTeamChange", clientId, old, new) + end +end +events.handle("onClientInfoChange", players.oninfochange) + +return players diff --git a/luascripts/players/stats.lua b/luascripts/players/stats.lua index bb498b4..110f046 100644 --- a/luascripts/players/stats.lua +++ b/luascripts/players/stats.lua @@ -15,8 +15,6 @@ -- You should have received a copy of the GNU General Public License -- along with this program. If not, see . -local events = require "luascripts.wolfadmin.util.events" - local stats = {} local data = {[-1337] = {["playerGUID"] = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"}} @@ -74,38 +72,4 @@ function stats.remove(clientId) return true end -function stats.onconnect(clientId, firstTime, isBot) - local clientInfo = et.trap_GetUserinfo(clientId) - - -- name is NOT yet set in pers.netname, so get all info out of infostring - stats.set(clientId, "playerName", et.Info_ValueForKey(clientInfo, "name")) - stats.set(clientId, "playerGUID", et.Info_ValueForKey(clientInfo, "cl_guid")) - stats.set(clientId, "playerIP", string.gsub(et.Info_ValueForKey(clientInfo, "ip"), ":%d*", "")) - stats.set(clientId, "playerTeam", tonumber(et.gentity_get(clientId, "sess.sessionTeam"))) - stats.set(clientId, "isBot", isBot) - - if firstTime then - stats.set(clientId, "voiceMute", false) - end -end -events.handle("onClientConnect", stats.onconnect) - -function stats.ondisconnect(clientId) - stats.remove(clientId) -end -events.handle("onClientDisconnect", stats.ondisconnect) - -function stats.onteamchange(clientId) - local clientInfo = et.trap_GetUserinfo(clientId) - local old = stats.get(clientId, "playerTeam") - local new = tonumber(et.gentity_get(clientId, "sess.sessionTeam")) - - if new ~= old then - stats.set(clientId, "playerTeam", new) - - events.trigger("onClientTeamChange", clientId, old, new) - end -end -events.handle("onClientInfoChange", stats.onteamchange) - -return stats \ No newline at end of file +return stats diff --git a/luascripts/util/debug.lua b/luascripts/util/debug.lua index 8885f65..0c03e03 100644 --- a/luascripts/util/debug.lua +++ b/luascripts/util/debug.lua @@ -36,9 +36,9 @@ function outputDebug(msg, severity) et.G_Print("[WolfAdmin] "..msg.."\n") for playerId = 0, et.trap_Cvar_Get("sv_maxclients") - 1 do - if settings.get("g_debugWolfAdmin") ~= 0 and et.G_shrubbot_permission(playerId, "*") then + if settings.get("g_debugWolfAdmin") ~= 0 then et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..playerId.." \"^:[WolfAdmin DEBUG] "..SEVERITY_LEVELS[severity]..msg.."\";") end end end -end \ No newline at end of file +end diff --git a/luascripts/util/events.lua b/luascripts/util/events.lua index 2eb9d49..fec8762 100644 --- a/luascripts/util/events.lua +++ b/luascripts/util/events.lua @@ -104,6 +104,7 @@ events.add("onCallvote") events.add("onPollStart") events.add("onPollFinish") +events.add("onClientConnectAttempt") events.add("onClientConnect") events.add("onClientDisconnect") events.add("onClientBegin") @@ -117,6 +118,7 @@ events.add("onGameStateChange") events.add("onGameFrame") events.add("onGameShutdown") +events.add("onPlayerReady") events.add("onPlayerSpawn") events.add("onPlayerDeath") events.add("onPlayerRevive") @@ -125,4 +127,4 @@ events.add("onPlayerSkillUpdate") events.add("onServerCommand") -return events \ No newline at end of file +return events diff --git a/luascripts/util/tables.lua b/luascripts/util/tables.lua index cd46a58..7c2fc12 100644 --- a/luascripts/util/tables.lua +++ b/luascripts/util/tables.lua @@ -17,6 +17,16 @@ local tables = {} +function tables.copy(table) + local copy = {} + + for key, value in pairs(table) do + copy[key] = value + end + + return copy +end + function tables.unpack(table) if table.unpack ~= nil then return table.unpack(table)