Misc rewriting to make use of players module instead of stats

This commit is contained in:
Timo Smit 2016-09-07 20:06:07 +02:00
parent 7befbbf9aa
commit c272eb67fe
12 changed files with 51 additions and 31 deletions

View File

@ -81,14 +81,14 @@ function players.oninfochange(clientId)
local new = et.Info_ValueForKey(clientInfo, "name")
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
stats.set(clientId, "namechangeForce", true)
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
players.setNameForced(clientId, true)
clientInfo = et.Info_SetValueForKey(clientInfo, "name", old)
et.trap_SetUserinfo(clientId, clientInfo)
et.ClientUserinfoChanged(clientId)
stats.set(clientId, "namechangeForce", false)
players.setNameForced(clientId, false)
et.trap_SendServerCommand(clientId, "cp \"Too many name changes in 1 minute.\";")
else

View File

@ -73,7 +73,7 @@ function commandListPlayers(clientId, cmdArguments)
level, -- level
levelName, -- levelname
guidStub, -- guid stub
(stats.get(player, "playerMuted") and "M" or ""), -- muted
(players.isMuted(player) and "M" or ""), -- muted
fireteamName, -- fireteam
players.getName(player), -- name
"", -- alias open

View File

@ -59,7 +59,7 @@ function commandMute(clientId, cmdArguments)
return true
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.\";")
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\";")
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
end

View File

@ -45,7 +45,7 @@ function commandPlayerLock(clientId, cmdArguments)
return true
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.\";")
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\";")
players.setPlayerTeamLocked(cmdClient, true)
players.setTeamLocked(cmdClient, true)
return true
end

View File

@ -45,7 +45,7 @@ function commandPlayerUnlock(clientId, cmdArguments)
return true
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\";")
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\";")
players.setPlayerTeamLocked(cmdClient, false)
players.setTeamLocked(cmdClient, false)
return true
end

View File

@ -42,7 +42,7 @@ function commandUnmute(clientId, cmdArguments)
return true
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\";")
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\";")
players.setPlayerMuted(cmdClient, false)
players.setMuted(cmdClient, false)
return true
end

View File

@ -59,7 +59,7 @@ function commandVoiceMute(clientId, cmdArguments)
return true
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.\";")
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\";")
players.setPlayerMuted(cmdClient, true, players.MUTE_VOICE, os.time(), vmuteTime)
players.setMuted(cmdClient, true, players.MUTE_VOICE, os.time(), vmuteTime)
return true
end

View File

@ -42,7 +42,7 @@ function commandVoiceUnmute(clientId, cmdArguments)
return true
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\";")
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\";")
players.setPlayerMuted(cmdClient, false)
players.setMuted(cmdClient, false)
return true
end

View File

@ -16,8 +16,10 @@
-- 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"
function commandPersonalMessage(clientId, cmdArguments)
if #cmdArguments > 1 then
@ -30,7 +32,7 @@ function commandPersonalMessage(clientId, cmdArguments)
end
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]\";")
end

View File

@ -16,14 +16,16 @@
-- 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"
function commandR(clientId, cmdArguments)
if #cmdArguments == 0 then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^9usage: "..commands.getclient("r")["syntax"].."\";")
else
local recipient = stats.get(clientId, "lastMessageFrom")
local recipient = players.getLastPMSender(clientId)
if not (recipient and et.gentity_get(recipient, "pers.netname")) then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"player not found\";")
@ -36,7 +38,7 @@ function commandR(clientId, cmdArguments)
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, "playsound "..clientId.." \"sound/misc/pm.wav\";")

View File

@ -210,7 +210,7 @@ function commands.onclientcommand(clientId, cmdText)
-- all Wolfenstein-related commands defined separately for now
if wolfCmd == "team" then
if players.isPlayerTeamLocked(clientId) then
if players.isTeamLocked(clientId) then
local clientTeam = tonumber(et.gentity_get(clientId, "sess.sessionTeam"))
local teamName = util.getTeamName(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)
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\"")
return 1
end
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\"")
return 1

View File

@ -51,7 +51,23 @@ function players.isBot(clientId)
return data[clientId]["bot"]
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
if state == true then
@ -63,7 +79,7 @@ function players.setPlayerMuted(clientId, state, type, issued, expires)
end
end
function players.isPlayerMuted(clientId, type)
function players.isMuted(clientId, type)
if type == nil then
return data[clientId]["mute"] ~= nil
elseif type == players.MUTE_CHAT then
@ -75,23 +91,23 @@ function players.isPlayerMuted(clientId, type)
return false
end
function players.getPlayerMuteType(clientId)
function players.getMuteType(clientId)
return data[clientId]["mute"]["type"]
end
function players.getPlayerMuteIssuedAt(clientId)
function players.getMuteIssuedAt(clientId)
return data[clientId]["mute"]["issued"]
end
function players.getPlayerMuteExpiresAt(clientId)
function players.getMuteExpiresAt(clientId)
return data[clientId]["mute"]["expires"]
end
function players.setPlayerTeamLocked(clientId, state)
function players.setTeamLocked(clientId, state)
data[clientId]["teamlock"] = state
end
function players.isPlayerTeamLocked(clientId)
function players.isTeamLocked(clientId)
return data[clientId]["teamlock"]
end