mirror of
https://github.com/etlegacy/wolfadmin.git
synced 2024-11-10 06:41:53 +00:00
Misc rewriting to make use of players module instead of stats
This commit is contained in:
parent
7befbbf9aa
commit
c272eb67fe
12 changed files with 51 additions and 31 deletions
|
@ -81,14 +81,14 @@ function players.oninfochange(clientId)
|
||||||
local new = et.Info_ValueForKey(clientInfo, "name")
|
local new = et.Info_ValueForKey(clientInfo, "name")
|
||||||
|
|
||||||
if new ~= old then
|
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
|
if (os.time() - stats.get(clientId, "namechangeStart")) < settings.get("g_renameInterval") and stats.get(clientId, "namechangePts") >= settings.get("g_renameLimit") and not players.isNameForced(clientId) then
|
||||||
stats.set(clientId, "namechangeForce", true)
|
players.setNameForced(clientId, true)
|
||||||
|
|
||||||
clientInfo = et.Info_SetValueForKey(clientInfo, "name", old)
|
clientInfo = et.Info_SetValueForKey(clientInfo, "name", old)
|
||||||
et.trap_SetUserinfo(clientId, clientInfo)
|
et.trap_SetUserinfo(clientId, clientInfo)
|
||||||
et.ClientUserinfoChanged(clientId)
|
et.ClientUserinfoChanged(clientId)
|
||||||
|
|
||||||
stats.set(clientId, "namechangeForce", false)
|
players.setNameForced(clientId, false)
|
||||||
|
|
||||||
et.trap_SendServerCommand(clientId, "cp \"Too many name changes in 1 minute.\";")
|
et.trap_SendServerCommand(clientId, "cp \"Too many name changes in 1 minute.\";")
|
||||||
else
|
else
|
||||||
|
|
|
@ -73,7 +73,7 @@ function commandListPlayers(clientId, cmdArguments)
|
||||||
level, -- level
|
level, -- level
|
||||||
levelName, -- levelname
|
levelName, -- levelname
|
||||||
guidStub, -- guid stub
|
guidStub, -- guid stub
|
||||||
(stats.get(player, "playerMuted") and "M" or ""), -- muted
|
(players.isMuted(player) and "M" or ""), -- muted
|
||||||
fireteamName, -- fireteam
|
fireteamName, -- fireteam
|
||||||
players.getName(player), -- name
|
players.getName(player), -- name
|
||||||
"", -- alias open
|
"", -- alias open
|
||||||
|
|
|
@ -59,7 +59,7 @@ function commandMute(clientId, cmdArguments)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
if players.isPlayerMuted(cmdClient) then
|
if players.isMuted(cmdClient) then
|
||||||
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dmute: ^7"..et.gentity_get(cmdClient, "pers.netname").." ^9is already muted.\";")
|
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dmute: ^7"..et.gentity_get(cmdClient, "pers.netname").." ^9is already muted.\";")
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
@ -75,7 +75,7 @@ function commandMute(clientId, cmdArguments)
|
||||||
|
|
||||||
et.trap_SendConsoleCommand(et.EXEC_APPEND, "chat \"^dmute: ^7"..et.gentity_get(cmdClient, "pers.netname").." ^9has been muted for "..muteTime.." seconds\";")
|
et.trap_SendConsoleCommand(et.EXEC_APPEND, "chat \"^dmute: ^7"..et.gentity_get(cmdClient, "pers.netname").." ^9has been muted for "..muteTime.." seconds\";")
|
||||||
|
|
||||||
players.setPlayerMuted(cmdClient, true, players.MUTE_CHAT + players.MUTE_VOICE, os.time(), muteTime)
|
players.setMuted(cmdClient, true, players.MUTE_CHAT + players.MUTE_VOICE, os.time(), muteTime)
|
||||||
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
|
@ -45,7 +45,7 @@ function commandPlayerLock(clientId, cmdArguments)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
if players.isPlayerTeamLocked(cmdClient) then
|
if players.isTeamLocked(cmdClient) then
|
||||||
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dplock: ^7"..et.gentity_get(cmdClient, "pers.netname").." ^9is already locked to a team.\";")
|
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dplock: ^7"..et.gentity_get(cmdClient, "pers.netname").." ^9is already locked to a team.\";")
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
@ -61,7 +61,7 @@ function commandPlayerLock(clientId, cmdArguments)
|
||||||
|
|
||||||
et.trap_SendConsoleCommand(et.EXEC_APPEND, "chat \"^dplock: ^7"..et.gentity_get(cmdClient, "pers.netname").." ^9has been locked to his team\";")
|
et.trap_SendConsoleCommand(et.EXEC_APPEND, "chat \"^dplock: ^7"..et.gentity_get(cmdClient, "pers.netname").." ^9has been locked to his team\";")
|
||||||
|
|
||||||
players.setPlayerTeamLocked(cmdClient, true)
|
players.setTeamLocked(cmdClient, true)
|
||||||
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
|
@ -45,7 +45,7 @@ function commandPlayerUnlock(clientId, cmdArguments)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
if not players.isPlayerTeamLocked(cmdClient) then
|
if not players.isTeamLocked(cmdClient) then
|
||||||
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dpunlock: ^9no player by that name or slot # is locked to a team\";")
|
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dpunlock: ^9no player by that name or slot # is locked to a team\";")
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
@ -53,7 +53,7 @@ function commandPlayerUnlock(clientId, cmdArguments)
|
||||||
|
|
||||||
et.trap_SendConsoleCommand(et.EXEC_APPEND, "chat \"^dpunlock: ^7"..et.gentity_get(cmdClient, "pers.netname").." ^9has been unlocked from his team\";")
|
et.trap_SendConsoleCommand(et.EXEC_APPEND, "chat \"^dpunlock: ^7"..et.gentity_get(cmdClient, "pers.netname").." ^9has been unlocked from his team\";")
|
||||||
|
|
||||||
players.setPlayerTeamLocked(cmdClient, false)
|
players.setTeamLocked(cmdClient, false)
|
||||||
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
|
@ -42,7 +42,7 @@ function commandUnmute(clientId, cmdArguments)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
if not players.isPlayerMuted(cmdClient) then
|
if not players.isMuted(cmdClient) then
|
||||||
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dunmute: ^9no player by that name or slot # is muted\";")
|
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dunmute: ^9no player by that name or slot # is muted\";")
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
@ -50,7 +50,7 @@ function commandUnmute(clientId, cmdArguments)
|
||||||
|
|
||||||
et.trap_SendConsoleCommand(et.EXEC_APPEND, "chat \"^dunmute: ^7"..et.gentity_get(cmdClient, "pers.netname").." ^9has been unmuted\";")
|
et.trap_SendConsoleCommand(et.EXEC_APPEND, "chat \"^dunmute: ^7"..et.gentity_get(cmdClient, "pers.netname").." ^9has been unmuted\";")
|
||||||
|
|
||||||
players.setPlayerMuted(cmdClient, false)
|
players.setMuted(cmdClient, false)
|
||||||
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
|
@ -59,7 +59,7 @@ function commandVoiceMute(clientId, cmdArguments)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
if players.isPlayerMuted(cmdClient) then
|
if players.isMuted(cmdClient) then
|
||||||
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dvmute: ^7"..et.gentity_get(cmdClient, "pers.netname").." ^9is already muted.\";")
|
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dvmute: ^7"..et.gentity_get(cmdClient, "pers.netname").." ^9is already muted.\";")
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
@ -75,7 +75,7 @@ function commandVoiceMute(clientId, cmdArguments)
|
||||||
|
|
||||||
et.trap_SendConsoleCommand(et.EXEC_APPEND, "chat \"^dvmute: ^7"..et.gentity_get(cmdClient, "pers.netname").." ^9has been voicemuted for "..vmuteTime.." seconds\";")
|
et.trap_SendConsoleCommand(et.EXEC_APPEND, "chat \"^dvmute: ^7"..et.gentity_get(cmdClient, "pers.netname").." ^9has been voicemuted for "..vmuteTime.." seconds\";")
|
||||||
|
|
||||||
players.setPlayerMuted(cmdClient, true, players.MUTE_VOICE, os.time(), vmuteTime)
|
players.setMuted(cmdClient, true, players.MUTE_VOICE, os.time(), vmuteTime)
|
||||||
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
|
@ -42,7 +42,7 @@ function commandVoiceUnmute(clientId, cmdArguments)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
if not players.isPlayerMuted(cmdClient) then
|
if not players.isMuted(cmdClient) then
|
||||||
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dvunmute: ^9no player by that name or slot # is voicemuted\";")
|
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dvunmute: ^9no player by that name or slot # is voicemuted\";")
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
@ -50,7 +50,7 @@ function commandVoiceUnmute(clientId, cmdArguments)
|
||||||
|
|
||||||
et.trap_SendConsoleCommand(et.EXEC_APPEND, "chat \"^dvunmute: ^7"..et.gentity_get(cmdClient, "pers.netname").." ^9has been unvoicemuted\";")
|
et.trap_SendConsoleCommand(et.EXEC_APPEND, "chat \"^dvunmute: ^7"..et.gentity_get(cmdClient, "pers.netname").." ^9has been unvoicemuted\";")
|
||||||
|
|
||||||
players.setPlayerMuted(cmdClient, false)
|
players.setMuted(cmdClient, false)
|
||||||
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
|
@ -16,8 +16,10 @@
|
||||||
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
|
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
local auth = require "luascripts.wolfadmin.auth.auth"
|
local auth = require "luascripts.wolfadmin.auth.auth"
|
||||||
|
|
||||||
local commands = require "luascripts.wolfadmin.commands.commands"
|
local commands = require "luascripts.wolfadmin.commands.commands"
|
||||||
local stats = require "luascripts.wolfadmin.players.stats"
|
|
||||||
|
local players = require "luascripts.wolfadmin.players.players"
|
||||||
|
|
||||||
function commandPersonalMessage(clientId, cmdArguments)
|
function commandPersonalMessage(clientId, cmdArguments)
|
||||||
if #cmdArguments > 1 then
|
if #cmdArguments > 1 then
|
||||||
|
@ -30,7 +32,7 @@ function commandPersonalMessage(clientId, cmdArguments)
|
||||||
end
|
end
|
||||||
|
|
||||||
if cmdClient ~= -1 and et.gentity_get(cmdClient, "pers.netname") then
|
if cmdClient ~= -1 and et.gentity_get(cmdClient, "pers.netname") then
|
||||||
stats.set(cmdClient, "lastMessageFrom", clientId)
|
players.setLastPMSender(cmdClient, clientId)
|
||||||
|
|
||||||
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..cmdClient.." \"^9reply: ^7r [^2message^7]\";")
|
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..cmdClient.." \"^9reply: ^7r [^2message^7]\";")
|
||||||
end
|
end
|
||||||
|
|
|
@ -16,14 +16,16 @@
|
||||||
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
|
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
local auth = require "luascripts.wolfadmin.auth.auth"
|
local auth = require "luascripts.wolfadmin.auth.auth"
|
||||||
|
|
||||||
local commands = require "luascripts.wolfadmin.commands.commands"
|
local commands = require "luascripts.wolfadmin.commands.commands"
|
||||||
local stats = require "luascripts.wolfadmin.players.stats"
|
|
||||||
|
local players = require "luascripts.wolfadmin.players.players"
|
||||||
|
|
||||||
function commandR(clientId, cmdArguments)
|
function commandR(clientId, cmdArguments)
|
||||||
if #cmdArguments == 0 then
|
if #cmdArguments == 0 then
|
||||||
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^9usage: "..commands.getclient("r")["syntax"].."\";")
|
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^9usage: "..commands.getclient("r")["syntax"].."\";")
|
||||||
else
|
else
|
||||||
local recipient = stats.get(clientId, "lastMessageFrom")
|
local recipient = players.getLastPMSender(clientId)
|
||||||
|
|
||||||
if not (recipient and et.gentity_get(recipient, "pers.netname")) then
|
if not (recipient and et.gentity_get(recipient, "pers.netname")) then
|
||||||
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"player not found\";")
|
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"player not found\";")
|
||||||
|
@ -36,7 +38,7 @@ function commandR(clientId, cmdArguments)
|
||||||
|
|
||||||
messageConcatenated = table.concat(message, " ")
|
messageConcatenated = table.concat(message, " ")
|
||||||
|
|
||||||
stats.set(recipient, "lastMessageFrom", clientId)
|
players.setLastPMSender(recipient, clientId)
|
||||||
|
|
||||||
et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat "..clientId.." \"^7"..et.gentity_get(clientId, "pers.netname").."^7 -> "..recipient..": (1 recipients): ^3"..messageConcatenated.."\";")
|
et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat "..clientId.." \"^7"..et.gentity_get(clientId, "pers.netname").."^7 -> "..recipient..": (1 recipients): ^3"..messageConcatenated.."\";")
|
||||||
et.trap_SendConsoleCommand(et.EXEC_APPEND, "playsound "..clientId.." \"sound/misc/pm.wav\";")
|
et.trap_SendConsoleCommand(et.EXEC_APPEND, "playsound "..clientId.." \"sound/misc/pm.wav\";")
|
||||||
|
|
|
@ -210,7 +210,7 @@ function commands.onclientcommand(clientId, cmdText)
|
||||||
|
|
||||||
-- all Wolfenstein-related commands defined separately for now
|
-- all Wolfenstein-related commands defined separately for now
|
||||||
if wolfCmd == "team" then
|
if wolfCmd == "team" then
|
||||||
if players.isPlayerTeamLocked(clientId) then
|
if players.isTeamLocked(clientId) then
|
||||||
local clientTeam = tonumber(et.gentity_get(clientId, "sess.sessionTeam"))
|
local clientTeam = tonumber(et.gentity_get(clientId, "sess.sessionTeam"))
|
||||||
local teamName = util.getTeamName(clientTeam)
|
local teamName = util.getTeamName(clientTeam)
|
||||||
local teamColor = util.getTeamColor(clientTeam)
|
local teamColor = util.getTeamColor(clientTeam)
|
||||||
|
@ -231,13 +231,13 @@ function commands.onclientcommand(clientId, cmdText)
|
||||||
|
|
||||||
return events.trigger("onCallvote", clientId, et.trap_Argv(1), voteArguments)
|
return events.trigger("onCallvote", clientId, et.trap_Argv(1), voteArguments)
|
||||||
elseif wolfCmd == "say" or wolfCmd == "say_team" or wolfCmd == "say_teamnl" or wolfCmd == "say_buddy" then
|
elseif wolfCmd == "say" or wolfCmd == "say_team" or wolfCmd == "say_teamnl" or wolfCmd == "say_buddy" then
|
||||||
if players.isPlayerMuted(clientId, players.MUTE_CHAT) then
|
if players.isMuted(clientId, players.MUTE_CHAT) then
|
||||||
et.trap_SendServerCommand(clientId, "cp \"^1You are muted\"")
|
et.trap_SendServerCommand(clientId, "cp \"^1You are muted\"")
|
||||||
|
|
||||||
return 1
|
return 1
|
||||||
end
|
end
|
||||||
elseif wolfCmd == "vsay" or wolfCmd == "vsay_team" then
|
elseif wolfCmd == "vsay" or wolfCmd == "vsay_team" then
|
||||||
if players.isPlayerMuted(clientId, players.MUTE_VOICE) then
|
if players.isMuted(clientId, players.MUTE_VOICE) then
|
||||||
et.trap_SendServerCommand(clientId, "cp \"^1You are voicemuted\"")
|
et.trap_SendServerCommand(clientId, "cp \"^1You are voicemuted\"")
|
||||||
|
|
||||||
return 1
|
return 1
|
||||||
|
|
|
@ -51,7 +51,23 @@ function players.isBot(clientId)
|
||||||
return data[clientId]["bot"]
|
return data[clientId]["bot"]
|
||||||
end
|
end
|
||||||
|
|
||||||
function players.setPlayerMuted(clientId, state, type, issued, expires)
|
function players.setLastPMSender(clientId, senderId)
|
||||||
|
data[clientId]["lastpmsender"] = senderId
|
||||||
|
end
|
||||||
|
|
||||||
|
function players.getLastPMSender(clientId)
|
||||||
|
return data[clientId]["lastpmsender"]
|
||||||
|
end
|
||||||
|
|
||||||
|
function players.setNameForced(clientId, state)
|
||||||
|
data[clientId]["nameforced"] = state
|
||||||
|
end
|
||||||
|
|
||||||
|
function players.isNameForced(clientId)
|
||||||
|
return data[clientId]["nameforced"]
|
||||||
|
end
|
||||||
|
|
||||||
|
function players.setMuted(clientId, state, type, issued, expires)
|
||||||
data[clientId]["mute"] = nil
|
data[clientId]["mute"] = nil
|
||||||
|
|
||||||
if state == true then
|
if state == true then
|
||||||
|
@ -63,7 +79,7 @@ function players.setPlayerMuted(clientId, state, type, issued, expires)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function players.isPlayerMuted(clientId, type)
|
function players.isMuted(clientId, type)
|
||||||
if type == nil then
|
if type == nil then
|
||||||
return data[clientId]["mute"] ~= nil
|
return data[clientId]["mute"] ~= nil
|
||||||
elseif type == players.MUTE_CHAT then
|
elseif type == players.MUTE_CHAT then
|
||||||
|
@ -75,23 +91,23 @@ function players.isPlayerMuted(clientId, type)
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
function players.getPlayerMuteType(clientId)
|
function players.getMuteType(clientId)
|
||||||
return data[clientId]["mute"]["type"]
|
return data[clientId]["mute"]["type"]
|
||||||
end
|
end
|
||||||
|
|
||||||
function players.getPlayerMuteIssuedAt(clientId)
|
function players.getMuteIssuedAt(clientId)
|
||||||
return data[clientId]["mute"]["issued"]
|
return data[clientId]["mute"]["issued"]
|
||||||
end
|
end
|
||||||
|
|
||||||
function players.getPlayerMuteExpiresAt(clientId)
|
function players.getMuteExpiresAt(clientId)
|
||||||
return data[clientId]["mute"]["expires"]
|
return data[clientId]["mute"]["expires"]
|
||||||
end
|
end
|
||||||
|
|
||||||
function players.setPlayerTeamLocked(clientId, state)
|
function players.setTeamLocked(clientId, state)
|
||||||
data[clientId]["teamlock"] = state
|
data[clientId]["teamlock"] = state
|
||||||
end
|
end
|
||||||
|
|
||||||
function players.isPlayerTeamLocked(clientId)
|
function players.isTeamLocked(clientId)
|
||||||
return data[clientId]["teamlock"]
|
return data[clientId]["teamlock"]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue