diff --git a/luascripts/wolfadmin/commands/admin/listplayers.lua b/luascripts/wolfadmin/commands/admin/listplayers.lua index 70a3943..b413eff 100644 --- a/luascripts/wolfadmin/commands/admin/listplayers.lua +++ b/luascripts/wolfadmin/commands/admin/listplayers.lua @@ -19,10 +19,13 @@ local auth = wolfa_requireModule("auth.auth") local commands = wolfa_requireModule("commands.commands") +local db = wolfa_requireModule("db.db") + local fireteams = wolfa_requireModule("game.fireteams") local players = wolfa_requireModule("players.players") +local constants = wolfa_requireModule("util.constants") local settings = wolfa_requireModule("util.settings") local util = wolfa_requireModule("util.util") @@ -37,6 +40,19 @@ function commandListPlayers(clientId, command) et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dCurrently ^7"..(#playersOnline).." ^dplayers online^d:\";") for _, player in pairs(playersOnline) do + local teamColor, teamCode + + if et.gentity_get(player, "pers.connected") == constants.CON_CONNECTED then + teamColor = util.getTeamColor(tonumber(et.gentity_get(player, "sess.sessionTeam"))) + teamCode = util.getTeamCode(tonumber(et.gentity_get(player, "sess.sessionTeam"))):upper():sub(1,1) + else + teamColor = "^8" + teamCode = "C" + end + + local level = auth.isPlayerAllowed(player, auth.PERM_INCOGNITO) and 0 or auth.getPlayerLevel(player) + local levelName = auth.getLevelName(level) + local guidStub if players.isBot(player) then @@ -45,26 +61,20 @@ function commandListPlayers(clientId, command) guidStub = players.getGUID(player):sub(-8) end - local level = auth.isPlayerAllowed(player, auth.PERM_INCOGNITO) and 0 or auth.getPlayerLevel(player) - local levelName = auth.getLevelName(level) - - local teamColor, teamCode - - if et.gentity_get(player, "pers.connected") then - teamColor = util.getTeamColor(tonumber(et.gentity_get(player, "sess.sessionTeam"))) - teamCode = util.getTeamCode(tonumber(et.gentity_get(player, "sess.sessionTeam"))):upper():sub(1,1) - else - teamColor = "^8" - teamCode = "C" - end - local fireteamId, fireteamName = fireteams.getPlayerFireteamId(player), "" if fireteamId then fireteamName = fireteams.getName(fireteamId):sub(1, 1) end - et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^f"..string.format("%2i %s%s ^7%-2i %20s ^7(*%s) ^1%1s ^3%1s ^7%s ^7%s%s^7%s", + local aka = "" + + local mostUsedAlias = db.getMostUsedAlias(db.getPlayerId(player))["alias"] + if not players.isBot(player) and not auth.isPlayerAllowed(player, auth.PERM_INCOGNITO) and players.getName(player) ~= mostUsedAlias then + aka = "(a.k.a. "..mostUsedAlias.."^7)" + end + + et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^f"..string.format("%2i %s%s ^7%-2i %20s ^7(*%s) ^1%1s ^3%1s ^7%s ^7%s", player, -- slot teamColor, -- team teamCode, -- team @@ -74,9 +84,7 @@ function commandListPlayers(clientId, command) (players.isMuted(player) and "M" or ""), -- muted fireteamName, -- fireteam players.getName(player), -- name - "", -- alias open - "", -- alias - "" -- alias close + aka -- alias ).."\";") end diff --git a/luascripts/wolfadmin/db/mysql.lua b/luascripts/wolfadmin/db/mysql.lua index 0d70d96..3af61df 100644 --- a/luascripts/wolfadmin/db/mysql.lua +++ b/luascripts/wolfadmin/db/mysql.lua @@ -272,6 +272,15 @@ function mysql.getAliasByName(playerid, aliasname) return alias end +function mysql.getMostUsedAlias(playerid) + cur = assert(con:execute("SELECT * FROM `alias` WHERE `player_id`="..tonumber(playerid).." ORDER BY `used` DESC LIMIT 1")) + + local alias = cur:fetch({}, "a") + cur:close() + + return alias +end + function mysql.getLastAlias(playerid) cur = assert(con:execute("SELECT * FROM `alias` WHERE `player_id`="..tonumber(playerid).." ORDER BY `lastused` DESC LIMIT 1")) diff --git a/luascripts/wolfadmin/db/sqlite3.lua b/luascripts/wolfadmin/db/sqlite3.lua index 5a2dca6..7406d3f 100644 --- a/luascripts/wolfadmin/db/sqlite3.lua +++ b/luascripts/wolfadmin/db/sqlite3.lua @@ -272,6 +272,15 @@ function sqlite3.getAliasByName(playerid, aliasname) return alias end +function sqlite3.getMostUsedAlias(playerid) + cur = assert(con:execute("SELECT * FROM `alias` WHERE `player_id`="..tonumber(playerid).." ORDER BY `used` DESC LIMIT 1")) + + local alias = cur:fetch({}, "a") + cur:close() + + return alias +end + function sqlite3.getLastAlias(playerid) cur = assert(con:execute("SELECT * FROM `alias` WHERE `player_id`="..tonumber(playerid).." ORDER BY `lastused` DESC LIMIT 1")) diff --git a/luascripts/wolfadmin/util/constants.lua b/luascripts/wolfadmin/util/constants.lua index d8fdf9d..d2a2f67 100644 --- a/luascripts/wolfadmin/util/constants.lua +++ b/luascripts/wolfadmin/util/constants.lua @@ -46,6 +46,10 @@ constants.TEAM_SPECTATORS_COLOR = "^2" constants.TEAM_AXIS_COLOR_NAME = "red" constants.TEAM_ALLIES_COLOR_NAME = "blue" +constants.CON_DISCONNECTED = 0 +constants.CON_CONNECTING = 1 +constants.CON_CONNECTED = 2 + constants.CLASS_SOLDIER = 0 constants.CLASS_MEDIC = 1 constants.CLASS_ENGINEER = 2