Implemented setting player level (issue #61, #62)

This commit is contained in:
Timo Smit 2016-09-04 22:28:57 +02:00
parent e993fcc89e
commit e745fe4c2c
4 changed files with 50 additions and 17 deletions

View file

@ -80,6 +80,7 @@ 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

View file

@ -36,15 +36,47 @@ function commandSetLevel(clientId, cmdArguments)
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
return false
end
commands.addadmin("setlevel", commandSetLevel, auth.PERM_SETLEVEL, "sets the admin level of a player", "^9[^3name|slot#^9] ^9[^3level^9]", true)
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()))

View file

@ -39,8 +39,8 @@ 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(guid, level)
cur = assert(con:execute("UPDATE `player` SET `level`='"..tonumber(level).."' WHERE `guid`='"..util.escape(guid).."'"))
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)

View file

@ -39,8 +39,8 @@ 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(guid, level)
cur = assert(con:execute("UPDATE `player` SET `level`='"..tonumber(level).."' WHERE `guid`='"..util.escape(guid).."'"))
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)