2016-02-13 11:19:37 +00:00
|
|
|
|
|
|
|
-- WolfAdmin module for Wolfenstein: Enemy Territory servers.
|
2016-02-16 13:10:00 +00:00
|
|
|
-- Copyright (C) 2015-2016 Timo 'Timothy' Smit
|
2016-02-13 11:19:37 +00:00
|
|
|
|
|
|
|
-- 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 <http://www.gnu.org/licenses/>.
|
|
|
|
|
2016-02-18 18:42:17 +00:00
|
|
|
local commands = require "luascripts.wolfadmin.commands.commands"
|
2016-08-29 20:00:11 +00:00
|
|
|
local auth = require "luascripts.wolfadmin.auth.auth"
|
2016-02-13 11:19:37 +00:00
|
|
|
local stats = require "luascripts.wolfadmin.players.stats"
|
|
|
|
|
|
|
|
function commandIncognito(clientId, cmdArguments)
|
|
|
|
local fileName = et.trap_Cvar_Get("g_shrubbot")
|
|
|
|
local functionStart = et.trap_Milliseconds()
|
|
|
|
local fileDescriptor, fileLength = et.trap_FS_FOpenFile(fileName, et.FS_READ)
|
|
|
|
|
|
|
|
if fileLength == -1 then
|
|
|
|
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dincognito: ^9an error happened (shrubbot file could not be opened)\";")
|
|
|
|
|
|
|
|
error("failed to open "..fileName.."\n")
|
|
|
|
end
|
|
|
|
|
|
|
|
local fileString = et.trap_FS_Read(fileDescriptor, fileLength)
|
|
|
|
|
|
|
|
et.trap_FS_FCloseFile(fileDescriptor)
|
|
|
|
|
|
|
|
for entry, adminName, adminGUID, adminLevel, adminFlags in string.gmatch(fileString, "(%[admin%]\nname%s+=%s+([%a%d%p]+)\nguid%s+=%s+([%u%d]+)\nlevel%s+=%s+([%d]+)\nflags%s+=%s+([%a%d%p]*)\n\n)") do
|
|
|
|
-- et.G_Print(string.format("%s %s %d %s\n", adminName, adminGUID, adminLevel, adminFlags))
|
|
|
|
|
|
|
|
if stats.get(clientId, "playerGUID") == adminGUID then
|
2016-08-29 20:00:11 +00:00
|
|
|
if auth.isallowed(clientId, "@") ~= 1 then
|
2016-02-13 11:19:37 +00:00
|
|
|
adminFlags = adminFlags.."+@"
|
|
|
|
|
|
|
|
et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat "..clientId.." \"^dincognito: ^9you are now playing incognito.\";")
|
|
|
|
else
|
|
|
|
if string.find(adminFlags, "+@") then
|
|
|
|
adminFlags = string.gsub(adminFlags, "+@", "")
|
|
|
|
elseif string.find(adminFlags, "@") then
|
|
|
|
adminFlags = string.gsub(adminFlags, "@", "")
|
|
|
|
else
|
|
|
|
adminFlags = adminFlags.."-@"
|
|
|
|
end
|
|
|
|
|
|
|
|
et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat "..clientId.." \"^dincognito: ^9you stopped playing incognito.\";")
|
|
|
|
end
|
|
|
|
|
|
|
|
local adminNameEscaped = string.gsub(adminName, "([%*%+%-%?%^%$%%%[%]%(%)%.])", "%%%1") -- fix for special captures
|
|
|
|
fileString = string.gsub(fileString, "%[admin%]\nname%s+=%s+"..adminNameEscaped.."\nguid%s+=%s+"..adminGUID.."\nlevel%s+=%s+"..adminLevel.."\nflags%s+=%s+([%a%d%p]*)\n\n", "[admin]\nname = "..adminName.."\nguid = "..adminGUID.."\nlevel = "..adminLevel.."\nflags = "..adminFlags.."\n\n")
|
|
|
|
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local fileDescriptor, fileLength = et.trap_FS_FOpenFile(fileName, et.FS_WRITE)
|
|
|
|
|
|
|
|
local writeCount = et.trap_FS_Write(fileString, string.len(fileString), fileDescriptor)
|
|
|
|
|
|
|
|
if not writeCount or writeCount < 1 then
|
|
|
|
error("failed to write "..fileName.."\n")
|
|
|
|
end
|
|
|
|
|
|
|
|
et.trap_FS_FCloseFile(fileDescriptor)
|
|
|
|
|
|
|
|
et.trap_SendConsoleCommand(et.EXEC_APPEND, "readconfig;")
|
|
|
|
|
|
|
|
return true
|
|
|
|
end
|
2016-08-29 20:00:11 +00:00
|
|
|
commands.addadmin("incognito", commandIncognito, auth.PERM_INCOGNITO, "fakes your level to guest (no aka)")
|