Seperated players and stats module

This commit is contained in:
Timo Smit 2016-09-06 12:41:02 +02:00
parent f2667e558f
commit 5ea4fc90e4
21 changed files with 219 additions and 129 deletions

View file

@ -33,6 +33,18 @@ local teamLocks = {
[constants.TEAM_SPECTATORS] = false,
}
function admin.isPlayerMuted(clientId)
-- return players.isPlayerMuted(clientId)
end
function admin.mutePlayer(clientId, length)
--
end
function admin.unmutePlayer(clientId)
--
end
function admin.isVoiceMuted(clientId)
if stats.get(clientId, "voiceMute") then
if stats.get(clientId, "voiceMute") - os.time() > 0 then
@ -45,14 +57,6 @@ function admin.isVoiceMuted(clientId)
return false
end
function admin.isPlayerLocked(clientId)
if stats.get(clientId, "teamLock") then
return true
end
return false
end
function admin.muteVoice(clientId, length)
stats.set(clientId, "voiceMute", length)
end
@ -73,6 +77,14 @@ function admin.unlockTeam(teamId)
teamLocks[teamId] = false
end
function admin.isPlayerLocked(clientId)
if stats.get(clientId, "teamLock") then
return true
end
return false
end
function admin.lockPlayer(clientId)
stats.set(clientId, "teamLock", true)
end
@ -82,8 +94,8 @@ function admin.unlockPlayer(clientId)
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"]
local playerid = db.getplayer(players.getGUID(clientId))["id"]
local adminid = db.getplayer(players.getGUID(clientId))["id"]
db.updateplayerlevel(playerid, level)
db.addsetlevel(playerid, level, adminid, os.time())
@ -112,7 +124,8 @@ events.handle("onClientConnect", admin.onconnect)
function players.oninfochange(clientId)
local clientInfo = et.trap_GetUserinfo(clientId)
local old = stats.get(clientId, "playerName")
local old = players.getCachedName(clientId)
local new = et.Info_ValueForKey(clientInfo, "name")
if new ~= old then
@ -127,8 +140,6 @@ function players.oninfochange(clientId)
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)

View file

@ -16,9 +16,11 @@
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
local db = require "luascripts.wolfadmin.db.db"
local players = require "luascripts.wolfadmin.players.players"
local events = require "luascripts.wolfadmin.util.events"
local settings = require "luascripts.wolfadmin.util.settings"
local stats = require "luascripts.wolfadmin.players.stats"
local warns = {}
@ -28,27 +30,27 @@ function warns.get(clientId, warnId)
if warnId then
return db.getwarn(warnId)
else
local playerid = db.getplayer(stats.get(clientId, "playerGUID"))["id"]
local playerid = db.getplayer(players.getGUID(clientId))["id"]
return db.getwarns(playerid)
end
end
function warns.getcount(clientId)
local playerid = db.getplayer(stats.get(clientId, "playerGUID"))["id"]
local playerid = db.getplayer(players.getGUID(clientId))["id"]
return db.getwarnscount(playerid)
end
function warns.getlimit(clientId, start, limit)
local playerid = db.getplayer(stats.get(clientId, "playerGUID"))["id"]
local playerid = db.getplayer(players.getGUID(clientId))["id"]
return db.getwarns(playerid, start, limit)
end
function warns.add(clientId, reason, adminId, datetime)
local playerid = db.getplayer(stats.get(clientId, "playerGUID"))["id"]
local adminid = db.getplayer(stats.get(adminId, "playerGUID"))["id"]
local playerid = db.getplayer(players.getGUID(clientId))["id"]
local adminid = db.getplayer(players.getGUID(clientId))["id"]
db.addwarn(playerid, reason, adminid, datetime)
end
@ -61,4 +63,4 @@ function warns.remove(clientId, warnId)
db.removewarn(warnId)
end
return warns
return warns

View file

@ -19,7 +19,7 @@ local auth = require "luascripts.wolfadmin.auth.auth"
local db = require "luascripts.wolfadmin.db.db"
local stats = require "luascripts.wolfadmin.players.stats"
local players = require "luascripts.wolfadmin.players.players"
local events = require "luascripts.wolfadmin.util.events"
local files = require "luascripts.wolfadmin.util.files"
@ -43,7 +43,7 @@ function acl.isallowed(clientId, permission)
end
function acl.getlevel(clientId)
local player = db.getplayer(stats.get(clientId, "playerGUID"))
local player = db.getplayer(players.getGUID(clientId))
return player["level_id"]
end

View file

@ -16,15 +16,18 @@
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
local auth = require "luascripts.wolfadmin.auth.auth"
local commands = require "luascripts.wolfadmin.commands.commands"
local stats = require "luascripts.wolfadmin.players.stats"
local players = require "luascripts.wolfadmin.players.players"
local settings = require "luascripts.wolfadmin.util.settings"
function commandAdminTest(clientId, cmdArguments)
local level = auth.getlevel(clientId)
local levelName = auth.getlevelname(level)
et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat -1 \"^dadmintest: ^7"..stats.get(clientId, "playerName").." ^9is a level "..level.." user (^7"..levelName.."^9).\";")
et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat -1 \"^dadmintest: ^7"..players.getName(clientId).." ^9is a level "..level.." user (^7"..levelName.."^9).\";")
return true
end

View file

@ -16,8 +16,11 @@
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
local auth = require "luascripts.wolfadmin.auth.auth"
local commands = require "luascripts.wolfadmin.commands.commands"
local stats = require "luascripts.wolfadmin.players.stats"
local players = require "luascripts.wolfadmin.players.players"
local settings = require "luascripts.wolfadmin.util.settings"
local util = require "luascripts.wolfadmin.util.util"
@ -43,12 +46,11 @@ function commandFinger(clientId, cmdArguments)
end
local stats = {
["name"] = et.gentity_get(cmdClient, "pers.netname"),
["cleanname"] = et.gentity_get(cmdClient, "pers.netname"):gsub("%^[^^]", ""),
["codedsname"] = et.gentity_get(cmdClient, "pers.netname"):gsub("%^([^^])", "^^2%1"),
["guid"] = et.gentity_get(cmdClient, "pers.netname"):gsub("%^([^^])", "^^2%1"),
["name"] = players.getName(clientId),
["cleanname"] = players.getName(clientId):gsub("%^[^^]", ""),
["codedsname"] = players.getName(clientId):gsub("%^([^^])", "^^2%1"),
["slot"] = cmdClient,
["guid"] = stats.get(cmdClient, "playerGUID"),
["guid"] = players.getGUID(clientId),
}
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dInformation about ^7"..stats["name"].."^d:\";")

View file

@ -16,8 +16,11 @@
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
local auth = require "luascripts.wolfadmin.auth.auth"
local commands = require "luascripts.wolfadmin.commands.commands"
local stats = require "luascripts.wolfadmin.players.stats"
local players = require "luascripts.wolfadmin.players.players"
local settings = require "luascripts.wolfadmin.util.settings"
function commandGib(clientId, cmdArguments)
@ -56,7 +59,7 @@ function commandGib(clientId, cmdArguments)
-- ENTITYNUM_WORLD MAX_GENTITIES - 2 18
et.G_Damage(cmdClient, 18, 18, 500, 0, 0) -- MOD_UNKNOWN = 0
et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat -1 \"^dgib: ^7"..stats.get(cmdClient, "playerName").." ^9was gibbed.\";")
et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat -1 \"^dgib: ^7"..players.getName(cmdClient).." ^9was gibbed.\";")
return true
end

View file

@ -15,9 +15,11 @@
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
local commands = require "luascripts.wolfadmin.commands.commands"
local auth = require "luascripts.wolfadmin.auth.auth"
local stats = require "luascripts.wolfadmin.players.stats"
local commands = require "luascripts.wolfadmin.commands.commands"
local players = require "luascripts.wolfadmin.players.players"
function commandIncognito(clientId, cmdArguments)
local fileName = et.trap_Cvar_Get("g_shrubbot")
@ -37,7 +39,7 @@ function commandIncognito(clientId, cmdArguments)
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
if players.getGUID(clientId) == adminGUID then
if auth.isallowed(clientId, "@") ~= 1 then
adminFlags = adminFlags.."+@"

View file

@ -15,13 +15,17 @@
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
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"
local players = require "luascripts.wolfadmin.players.players"
local pagination = require "luascripts.wolfadmin.util.pagination"
local settings = require "luascripts.wolfadmin.util.settings"
local util = require "luascripts.wolfadmin.util.util"
function commandListAliases(clientId, cmdArguments)
if not db.isconnected() then
@ -58,7 +62,7 @@ function commandListAliases(clientId, cmdArguments)
return true
end
local player = db.getplayer(stats.get(cmdClient, "playerGUID"))["id"]
local player = db.getplayer(players.getGUID(cmdClient))["id"]
local count = db.getaliasescount(player)
local limit, offset = pagination.calculate(count, 30, tonumber(cmdArguments[2]))

View file

@ -16,12 +16,16 @@
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
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"
local db = require "luascripts.wolfadmin.db.db"
local commands = require "luascripts.wolfadmin.commands.commands"
local stats = require "luascripts.wolfadmin.players.stats"
local db = require "luascripts.wolfadmin.db.db"
local players = require "luascripts.wolfadmin.players.players"
local pagination = require "luascripts.wolfadmin.util.pagination"
local settings = require "luascripts.wolfadmin.util.settings"
local util = require "luascripts.wolfadmin.util.util"
function commandListLevels(clientId, cmdArguments)
if cmdArguments[1] == nil then
@ -74,7 +78,7 @@ function commandListLevels(clientId, cmdArguments)
return true
end
local player = db.getplayer(stats.get(cmdClient, "playerGUID"))["id"]
local player = db.getplayer(players.getGUID(cmdClient))["id"]
local count = db.getlevelscount(player)
local limit, offset = pagination.calculate(count, 30, tonumber(cmdArguments[2]))

View file

@ -22,6 +22,7 @@ local commands = require "luascripts.wolfadmin.commands.commands"
local game = require "luascripts.wolfadmin.game.game"
local fireteams = require "luascripts.wolfadmin.game.fireteams"
local players = require "luascripts.wolfadmin.players.players"
local stats = require "luascripts.wolfadmin.players.stats"
local constants = require "luascripts.wolfadmin.util.constants"
@ -32,7 +33,7 @@ function commandListPlayers(clientId, cmdArguments)
local players = {}
for playerId = 0, et.trap_Cvar_Get("sv_maxclients") - 1 do
if wolfa_isPlayer(playerId) then
if players.isConnected(playerId) then
table.insert(players, playerId)
end
end
@ -41,10 +42,10 @@ function commandListPlayers(clientId, cmdArguments)
for _, player in pairs(players) do
local guidStub
if stats.get(player, "isBot") then
if players.isBot(player) then
guidStub = "OMNIBOT-"
else
guidStub = stats.get(player, "playerGUID"):sub(-8)
guidStub = players.getGUID(player):sub(-8)
end
local level = auth.getlevel(player)
@ -74,7 +75,7 @@ function commandListPlayers(clientId, cmdArguments)
guidStub, -- guid stub
(stats.get(player, "playerMuted") and "M" or ""), -- muted
fireteamName, -- fireteam
stats.get(player, "playerName"), -- name
players.getName(player), -- name
"", -- alias open
"", -- alias
"" -- alias close

View file

@ -16,8 +16,11 @@
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
local auth = require "luascripts.wolfadmin.auth.auth"
local commands = require "luascripts.wolfadmin.commands.commands"
local stats = require "luascripts.wolfadmin.players.stats"
local players = require "luascripts.wolfadmin.players.players"
local settings = require "luascripts.wolfadmin.util.settings"
function commandSlap(clientId, cmdArguments)
@ -59,7 +62,7 @@ function commandSlap(clientId, cmdArguments)
et.gentity_set(cmdClient, "health", newHealth)
et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat -1 \"^dslap: ^7"..stats.get(cmdClient, "playerName").." ^9was slapped.\";")
et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat -1 \"^dslap: ^7"..players.getName(cmdClient).." ^9was slapped.\";")
return true
end

View file

@ -16,8 +16,11 @@
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
local auth = require "luascripts.wolfadmin.auth.auth"
local commands = require "luascripts.wolfadmin.commands.commands"
local players = require "luascripts.wolfadmin.players.players"
function commandAdminChat(clientId, cmdArguments)
if #cmdArguments == 0 then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^9usage: "..commands.getclient("adminchat")["syntax"].."\";")
@ -30,7 +33,7 @@ function commandAdminChat(clientId, cmdArguments)
end
for playerId = 0, et.trap_Cvar_Get("sv_maxclients") - 1 do
if wolfa_isPlayer(playerId) and auth.isallowed(playerId, "~") == 1 then
if players.isConnected(playerId) and auth.isallowed(playerId, "~") == 1 then
table.insert(recipients, playerId)
end
end

View file

@ -17,12 +17,16 @@
require "luascripts.wolfadmin.util.debug"
local admin = require "luascripts.wolfadmin.admin.admin"
local auth = require "luascripts.wolfadmin.auth.auth"
local players = require "luascripts.wolfadmin.players.players"
local stats = require "luascripts.wolfadmin.players.stats"
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 = {}
@ -116,8 +120,8 @@ function commands.log(clientId, command, cmdArguments)
local logLine
local levelTime = wolfa_getLevelTime() / 1000
local clientGUID = clientId and stats.get(clientId, "playerGUID") or "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
local clientName = clientId and stats.get(clientId, "playerName") or "console"
local clientGUID = clientId and players.getGUID(clientId) or "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
local clientName = clientId and players.getName(clientId) or "console"
local clientFlags = ""
local victimId
@ -140,7 +144,7 @@ function commands.log(clientId, command, cmdArguments)
end
if victimId then
local victimName = stats.get(victimId, "playerName")
local victimName = players.getName(victimId)
logLine = string.format("%3i:%02i: %i: %s: %s: %s: %s: %s: %s: \"%s\"\n", math.floor(levelTime / 60), (levelTime % 60), clientId, clientGUID, clientName, clientFlags, command, victimId, victimName, table.concat(cmdArguments, " ", 2))
else
logLine = string.format("%3i:%02i: %i: %s: %s: %s: %s: \"%s\"\n", math.floor(levelTime / 60), (levelTime % 60), clientId, clientGUID, clientName, clientFlags, command, table.concat(cmdArguments, " "))

View file

@ -15,13 +15,13 @@
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
local players = require "luascripts.wolfadmin.players.players"
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"
local luasql = require "luasql.mysql"
local mysql = {}
@ -43,8 +43,8 @@ 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"]
function mysql.getplayerid(clientId)
return mysql.getplayer(players.getGUID(clientId))["id"]
end
function mysql.getplayer(guid)

View file

@ -15,13 +15,13 @@
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
local players = require "luascripts.wolfadmin.players.players"
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"
local luasql = require "luasql.sqlite3"
local sqlite3 = {}
@ -43,8 +43,8 @@ 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"]
function sqlite3.getplayerid(clientId)
return sqlite3.getplayer(players.getGUID(clientId))["id"]
end
function sqlite3.getplayer(guid)

View file

@ -15,22 +15,19 @@
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
local util = require "luascripts.wolfadmin.util.util"
local players = require "luascripts.wolfadmin.players.players"
local events = require "luascripts.wolfadmin.util.events"
local settings = require "luascripts.wolfadmin.util.settings"
local stats = require "luascripts.wolfadmin.players.stats"
local util = require "luascripts.wolfadmin.util.util"
local bots = {}
function bots.is(clientId)
return stats.get(clientId, "isBot")
end
function bots.put(team)
local team = util.getTeamCode(team)
for playerId = 0, et.trap_Cvar_Get("sv_maxclients") - 1 do
if wolfa_isPlayer(playerId) and bots.is(playerId) then
if players.isConnected(playerId) and players.isBot(playerId) then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "!put "..playerId.." "..team..";")
end
end
@ -51,4 +48,4 @@ function bots.oninit(levelTime, randomSeed, restartMap)
end
events.handle("onGameInit", bots.oninit)
return bots
return bots

View file

@ -96,7 +96,7 @@ events.handle("onPlayerDeath", game.ondeath)
function game.onrevive(clientMedic, clientVictim)
if settings.get("g_announceRevives") ~= 0 then
for playerId = 0, et.trap_Cvar_Get("sv_maxclients") - 1 do
if wolfa_isPlayer(playerId) and tonumber(et.gentity_get(playerId, "sess.sessionTeam")) == tonumber(et.gentity_get(clientMedic, "sess.sessionTeam")) then
if players.isConnected(playerId) and tonumber(et.gentity_get(playerId, "sess.sessionTeam")) == tonumber(et.gentity_get(clientMedic, "sess.sessionTeam")) then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat "..playerId.." \"^drevive: ^7"..et.gentity_get(clientMedic, "pers.netname").." ^9revived ^7"..et.gentity_get(clientVictim, "pers.netname").."^9.\";")
end
end

View file

@ -155,7 +155,7 @@ function sprees.ondeath(victimId, killerId, mod)
elseif victimId == killerId then -- suicides
-- happens when a bot disconnects, it selfkills before leaving, thus emptying the
-- player data table, resulting in errors. I'm sorry for your spree records, bots.
if not wolfa_isPlayer(victimId) then return end
if not players.isConnected(victimId) then return end
stats.set(victimId, "currentKillSpree", 0)
stats.add(victimId, "currentDeathSpree", 1)
@ -163,7 +163,7 @@ function sprees.ondeath(victimId, killerId, mod)
stats.set(victimId, "longestDeathSpree", stats.get(victimId, "currentDeathSpree") > stats.get(victimId, "longestDeathSpree") and stats.get(victimId, "currentDeathSpree") or stats.get(victimId, "longestDeathSpree"))
if (settings.get("g_botRecords") == 1 or not stats.get(victimId, "isBot")) and (not currentRecords["dsrecord"] or stats.get(victimId, "longestDeathSpree") > currentRecords["dsrecord"]) then
if (settings.get("g_botRecords") == 1 or not players.isBot(victimId)) and (not currentRecords["dsrecord"] or stats.get(victimId, "longestDeathSpree") > currentRecords["dsrecord"]) then
currentRecords["dsplayer"] = db.getplayerid(victimId)
currentRecords["dsrecord"] = stats.get(victimId, "longestDeathSpree")
end
@ -176,14 +176,14 @@ function sprees.ondeath(victimId, killerId, mod)
stats.set(killerId, "longestKillSpree", stats.get(killerId, "currentKillSpree") > stats.get(killerId, "longestKillSpree") and stats.get(killerId, "currentKillSpree") or stats.get(killerId, "longestKillSpree"))
if (settings.get("g_botRecords") == 1 or not stats.get(killerId, "isBot")) and (not currentRecords["ksrecord"] or stats.get(killerId, "longestKillSpree") > currentRecords["ksrecord"]) then
if (settings.get("g_botRecords") == 1 or not players.isBot(killerId)) and (not currentRecords["ksrecord"] or stats.get(killerId, "longestKillSpree") > currentRecords["ksrecord"]) then
currentRecords["ksplayer"] = db.getplayerid(killerId)
currentRecords["ksrecord"] = stats.get(killerId, "longestKillSpree")
end
-- happens when a bot disconnects, it selfkills before leaving, thus emptying the
-- player data table, resulting in errors. I'm sorry for your spree records, bots.
if not wolfa_isPlayer(victimId) then return end
if not players.isConnected(victimId) then return end
stats.set(victimId, "currentKillSpree", 0)
stats.add(victimId, "currentDeathSpree", 1)
@ -191,7 +191,7 @@ function sprees.ondeath(victimId, killerId, mod)
stats.set(victimId, "longestDeathSpree", stats.get(victimId, "currentDeathSpree") > stats.get(victimId, "longestDeathSpree") and stats.get(victimId, "currentDeathSpree") or stats.get(victimId, "longestDeathSpree"))
if (settings.get("g_botRecords") == 1 or not stats.get(victimId, "isBot")) and (not currentRecords["dsrecord"] or stats.get(victimId, "longestDeathSpree") > currentRecords["dsrecord"]) then
if (settings.get("g_botRecords") == 1 or not players.isBot(victimId)) and (not currentRecords["dsrecord"] or stats.get(victimId, "longestDeathSpree") > currentRecords["dsrecord"]) then
currentRecords["dsplayer"] = db.getplayerid(victimId)
currentRecords["dsrecord"] = stats.get(victimId, "longestDeathSpree")
end
@ -204,13 +204,13 @@ function sprees.onrevive(clientMedic, clientVictim)
stats.set(clientMedic, "longestReviveSpree", stats.get(clientMedic, "currentReviveSpree") > stats.get(clientMedic, "longestReviveSpree") and stats.get(clientMedic, "currentReviveSpree") or stats.get(clientMedic, "longestReviveSpree"))
if revivespreeMessages[stats.get(clientMedic, "currentReviveSpree")] then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "chat \"^1REVIVE SPREE! ^*"..stats.get(clientMedic, "playerName").." ^*"..revivespreeMessages[stats.get(clientMedic, "currentReviveSpree")]["msg"].." ^d(^3"..stats.get(clientMedic, "currentReviveSpree").." ^drevives in a row!)\";")
et.trap_SendConsoleCommand(et.EXEC_APPEND, "chat \"^1REVIVE SPREE! ^*"..players.getName(clientMedic).." ^*"..revivespreeMessages[stats.get(clientMedic, "currentReviveSpree")]["msg"].." ^d(^3"..stats.get(clientMedic, "currentReviveSpree").." ^drevives in a row!)\";")
end
if (settings.get("g_botRecords") == 1 or not stats.get(clientMedic, "isBot")) and (not currentRecords["rsrecord"] or stats.get(clientMedic, "longestReviveSpree") > currentRecords["rsrecord"]) then
if (settings.get("g_botRecords") == 1 or not players.isBot(clientMedic)) and (not currentRecords["rsrecord"] or stats.get(clientMedic, "longestReviveSpree") > currentRecords["rsrecord"]) then
currentRecords["rsplayer"] = db.getplayerid(clientMedic)
currentRecords["rsrecord"] = stats.get(clientMedic, "longestReviveSpree")
end
end
return sprees
return sprees

View file

@ -17,14 +17,14 @@
local auth = require "luascripts.wolfadmin.auth.auth"
local players = require "luascripts.wolfadmin.players.players"
local constants = require "luascripts.wolfadmin.util.constants"
local util = require "luascripts.wolfadmin.util.util"
local events = require "luascripts.wolfadmin.util.events"
local settings = require "luascripts.wolfadmin.util.settings"
local files = require "luascripts.wolfadmin.util.files"
local stats = require "luascripts.wolfadmin.players.stats"
local greetings = {}
local userGreetings = {}
@ -34,8 +34,8 @@ function greetings.get(clientId)
local lvl = auth.getlevel(clientId)
if auth.isallowed(clientId, auth.PERM_INCOGNITO) ~= 1 then
if userGreetings[stats.get(clientId, "playerGUID")] ~= nil then
return userGreetings[stats.get(clientId, "playerGUID")]
if userGreetings[players.getGUID(clientId)] ~= nil then
return userGreetings[players.getGUID(clientId)]
elseif levelGreetings[lvl] ~= nil then
return levelGreetings[lvl]
end
@ -113,7 +113,7 @@ end
events.handle("onGameInit", greetings.oninit)
function greetings.onready(clientId, firstTime)
if firstTime and (not stats.get(clientId, "isBot") or settings.get("g_botGreetings") == 1) then
if firstTime and (not players.isBot(clientId) or settings.get("g_botGreetings") == 1) then
greetings.show(clientId)
end
end

View file

@ -17,34 +17,87 @@
local db = require "luascripts.wolfadmin.db.db"
local stats = require "luascripts.wolfadmin.players.stats"
local events = require "luascripts.wolfadmin.util.events"
local players = {}
local data = {}
function players.isConnected(clientId)
return (data[clientId] ~= nil)
end
function players.getCachedName(clientId)
return data[clientId]["name"]
end
function players.getName(clientId)
return et.gentity_get(clientId, "pers.netname")
end
function players.getGUID(clientId)
return data[clientId]["guid"]
end
function players.getIP(clientId)
return data[clientId]["ip"]
end
function players.isBot(clientId)
return data[clientId]["bot"]
end
function players.setPlayerMuted(clientId, state, type, duration)
data[clientId]["mute"] = state
if state == true then
data[clientId]["mutetype"] = type
data[clientId]["muteduration"] = duration
end
end
function players.isPlayerMuted(clientId)
return data[clientId]["mute"]
end
function players.getPlayerMuteType(clientId, state, type, duration)
return data[clientId]["mutetype"]
end
function players.getPlayerMuteDuration(clientId, state, type, duration)
return data[clientId]["muteduration"]
end
function players.setPlayerTeamLocked(clientId, state)
data[clientId]["teamlock"] = state
end
function players.isPlayerTeamLocked(clientId)
return data[clientId]["teamlock"]
end
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)
data[clientId] = {}
-- data[clientId]["name"] is cached version for detecting namechanges, do not
-- use it to retrieve a player's name
data[clientId]["name"] = et.Info_ValueForKey(clientInfo, "name")
data[clientId]["guid"] = et.Info_ValueForKey(clientInfo, "cl_guid")
data[clientId]["ip"] = string.gsub(et.Info_ValueForKey(clientInfo, "ip"), ":%d*", "")
data[clientId]["bot"] = isBot
data[clientId]["team"] = tonumber(et.gentity_get(clientId, "sess.sessionTeam"))
if firstTime then
stats.set(clientId, "newConnection", true)
data[clientId]["new"] = true
if db.isconnected() then
local player = db.getplayer(stats.get(clientId, "playerGUID"))
local name = stats.get(clientId, "playerName")
local player = db.getplayer(data[clientId]["guid"])
if player then
local guid = stats.get(clientId, "playerGUID")
local ip = stats.get(clientId, "playerIP")
db.updateplayerip(guid, ip)
db.updateplayerip(data[clientId]["guid"], data[clientId]["ip"])
local alias = db.getaliasbyname(player["id"], name)
@ -54,12 +107,9 @@ function players.onconnect(clientId, firstTime, isBot)
db.addalias(playerid, name, os.time())
end
else
local guid = stats.get(clientId, "playerGUID")
local ip = stats.get(clientId, "playerIP")
db.addplayer(data[clientId]["guid"], data[clientId]["ip"])
db.addplayer(guid, ip)
local player = db.getplayer(stats.get(clientId, "playerGUID"))
local player = db.getplayer(data[clientId]["guid"])
db.addalias(player["id"], name, os.time())
end
end
@ -74,9 +124,9 @@ function players.onbegin(clientId)
-- 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"))
events.trigger("onPlayerReady", clientId, data[clientId]["new"])
stats.set(clientId, "newConnection", false)
data[clientId]["new"] = false
end
events.handle("onClientBegin", players.onbegin)
@ -90,9 +140,11 @@ function players.onnamechange(clientId, old, new)
-- known: old NQ versions, Legacy
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay -1 \""..old.." ^7is now known as "..new.."\";")
data[clientId]["name"] = new
if db.isconnected() then
local playerid = db.getplayer(stats.get(clientId, "playerGUID"))["id"]
local name = stats.get(clientId, "playerName")
local playerid = db.getplayer(players.getGUID(clientId))["id"]
local name = players.getName(clientId)
local alias = db.getaliasbyname(playerid, name)
if alias then
@ -106,11 +158,11 @@ events.handle("onClientNameChange", players.onnamechange)
function players.oninfochange(clientId)
local clientInfo = et.trap_GetUserinfo(clientId)
local old = stats.get(clientId, "playerTeam")
local old = data[clientId]["team"]
local new = tonumber(et.gentity_get(clientId, "sess.sessionTeam"))
if new ~= old then
stats.set(clientId, "playerTeam", new)
data[clientId]["team"] = new
events.trigger("onClientTeamChange", clientId, old, new)
end

View file

@ -15,21 +15,16 @@
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
local players = require "luascripts.wolfadmin.players.players"
local stats = {}
local data = {[-1337] = {["playerGUID"] = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"}}
-- TODO: need to check this in stat functions, apparently goes wrong
function wolfa_isPlayer(clientId)
if data[clientId] then
return true
end
return false
end
local data = {}
function stats.get(clientId, statKey)
-- if not wolfa_isPlayer(clientId) then return false end
if not players.isConnected(clientId) then
error("client "..clientId.." is not connected")
end
if statKey and type(statKey) == "string" and data[clientId] then
return data[clientId][statKey]
@ -39,7 +34,9 @@ function stats.get(clientId, statKey)
end
function stats.set(clientId, statKey, statValue)
-- if not wolfa_isPlayer(clientId) then return false end
if not players.isConnected(clientId) then
error("client "..clientId.." is not connected")
end
if not data[clientId] then data[clientId] = {} end
@ -52,20 +49,22 @@ function stats.set(clientId, statKey, statValue)
return false
end
function stats.add(clientId, statKey, statAdd) -- alias
function stats.add(clientId, statKey, statAdd)
statAdd = statAdd and statAdd or 1
return stats.set(clientId, statKey, stats.get(clientId, statKey) + statAdd)
end
function stats.take(clientId, statKey, statTake) -- alias
function stats.take(clientId, statKey, statTake)
statTake = statTake and statTake or 1
return stats.set(clientId, statKey, stats.get(clientId, statKey) - statTake)
end
function stats.remove(clientId)
-- if not wolfa_isPlayer(clientId) then return false end
if not players.isConnected(clientId) then
error("client "..clientId.." is not connected")
end
data[clientId] = nil