Removed sprees code

Stop filling 30% of server logs when disabled,
you idiot!

That feature is also controversial as it is quite
quake-like and goes against the idea of better
teamwork we try to emphase in Legacy mod.

* Removed spees game plugin and command
* Removed resetsprees command and related code.
* Removed related g_botRecords
* Not touched the database to ease update.

For something supposedely modular, the spree
code is surprsingly deeply integrated in the
codebase.
This commit is contained in:
Remy Marquis 2020-04-27 17:21:58 +02:00
parent 3193d2f708
commit 8eb29aca14
8 changed files with 2 additions and 517 deletions

View file

@ -57,6 +57,3 @@ file = "rules.toml"
file = "greetings.toml" file = "greetings.toml"
area = 3 area = 3
bots = 1 bots = 1
[records]
bots = 0

View file

@ -22,8 +22,6 @@ local auth = wolfa_requireModule("auth.auth")
local commands = wolfa_requireModule("commands.commands") local commands = wolfa_requireModule("commands.commands")
local sprees = wolfa_requireModule("game.sprees")
local greetings = wolfa_requireModule("players.greetings") local greetings = wolfa_requireModule("players.greetings")
local settings = wolfa_requireModule("util.settings") local settings = wolfa_requireModule("util.settings")
@ -33,9 +31,8 @@ function commandReadconfig(clientId, command)
local bannersCount = banners.load() local bannersCount = banners.load()
local rulesCount = rules.load() local rulesCount = rules.load()
local greetingsCount = greetings.load() local greetingsCount = greetings.load()
local spreesCount = sprees.load()
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"readconfig: loaded "..bannersCount.." banners, "..rulesCount.." rules, "..greetingsCount.." greetings, "..spreesCount.." sprees\";") et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"readconfig: loaded "..bannersCount.." banners, "..rulesCount.." rules, "..greetingsCount.." greetings\";")
return false return false
end end
@ -46,9 +43,8 @@ function commandReadconfig(clientId, command)
local bannersCount = banners.load() local bannersCount = banners.load()
local rulesCount = rules.load() local rulesCount = rules.load()
local greetingsCount = greetings.load() local greetingsCount = greetings.load()
local spreesCount = sprees.load()
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"readconfig: loaded "..bannersCount.." banners, "..rulesCount.." rules, "..greetingsCount.." greetings, "..spreesCount.." sprees\";") et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"readconfig: loaded "..bannersCount.." banners, "..rulesCount.." rules, "..greetingsCount.." greetings\";")
return false return false
end end

View file

@ -1,48 +0,0 @@
-- WolfAdmin module for Wolfenstein: Enemy Territory servers.
-- Copyright (C) 2015-2020 Timo 'Timothy' Smit
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- at your option any later version.
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
-- 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 auth = wolfa_requireModule("auth.auth")
local db = wolfa_requireModule("db.db")
local commands = wolfa_requireModule("commands.commands")
local game = wolfa_requireModule("game.game")
local sprees = wolfa_requireModule("game.sprees")
local settings = wolfa_requireModule("util.settings")
function commandResetSprees(clientId, command, map)
if not db.isConnected() then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dsprees: ^9spree records are disabled.\";")
return true
end
if map and map == "all" then
sprees.reset(true)
et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat -1 \"^dresetsprees: ^9all spree records have been reset.\";")
else
sprees.reset()
et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat -1 \"^dresetsprees: ^9spree records have been reset for map '^7"..game.getMap().."^9'.\";")
end
return true
end
commands.addadmin("resetsprees", commandResetSprees, auth.PERM_READCONFIG, "resets the spree records", nil, (settings.get("g_spreeRecords") == 0))

View file

@ -1,47 +0,0 @@
-- WolfAdmin module for Wolfenstein: Enemy Territory servers.
-- Copyright (C) 2015-2020 Timo 'Timothy' Smit
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- at your option any later version.
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
-- 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 auth = wolfa_requireModule("auth.auth")
local commands = wolfa_requireModule("commands.commands")
local db = wolfa_requireModule("db.db")
local sprees = wolfa_requireModule("game.sprees")
function commandShowSprees(clientId, command)
if not db.isConnected() then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dsprees: ^9spree records are disabled.\";")
return true
end
local records = sprees.get()
if #records == 0 then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dsprees: ^9there are no records for this map yet.\"")
else
for i = 0, sprees.TYPE_NUM - 1 do
if records[i] and records[i]["record"] > 0 then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat -1 \"^dsprees: ^9longest "..sprees.getRecordNameByType(i).." spree (^7"..records[i]["record"].."^9) by ^7"..db.getLastAlias(records[i]["player"])["alias"].."^9.\";")
end
end
end
return true
end
commands.addadmin("sprees", commandShowSprees, auth.PERM_LISTSPREES, "display the current spree records")

View file

@ -1,394 +0,0 @@
-- WolfAdmin module for Wolfenstein: Enemy Territory servers.
-- Copyright (C) 2015-2020 Timo 'Timothy' Smit
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- at your option any later version.
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
-- 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 db = wolfa_requireModule("db.db")
local game = wolfa_requireModule("game.game")
local players = wolfa_requireModule("players.players")
local bits = wolfa_requireModule("util.bits")
local constants = wolfa_requireModule("util.constants")
local events = wolfa_requireModule("util.events")
local files = wolfa_requireModule("util.files")
local settings = wolfa_requireModule("util.settings")
local toml = wolfa_requireLib("toml")
local sprees = {}
sprees.RECORD_BOTS_PLAYING = 1
sprees.RECORD_BOTS = 2
sprees.SOUND_PLAY_SELF = 0
sprees.SOUND_PLAY_PUBLIC = 1
sprees.TYPE_KILL = 0
sprees.TYPE_DEATH = 1
sprees.TYPE_REVIVE = 2
sprees.TYPE_NUM = 3
sprees.TYPE_KILL_NAME = "kill"
sprees.TYPE_DEATH_NAME = "death"
sprees.TYPE_REVIVE_NAME = "revive"
local spreeNames = {
[sprees.TYPE_KILL] = sprees.TYPE_KILL_NAME,
[sprees.TYPE_DEATH] = sprees.TYPE_DEATH_NAME,
[sprees.TYPE_REVIVE] = sprees.TYPE_REVIVE_NAME
}
local spreeTypes = {
[sprees.TYPE_KILL_NAME] = sprees.TYPE_KILL,
[sprees.TYPE_DEATH_NAME] = sprees.TYPE_DEATH,
[sprees.TYPE_REVIVE_NAME] = sprees.TYPE_REVIVE
}
local spreeMessages = {}
local spreeMessagesByType = {}
local playerSprees = {}
local currentRecords = {} -- cached version
local currentMapId
function sprees.getRecordNameByType(type)
return spreeNames[type]
end
function sprees.getRecordTypeByName(name)
return spreeTypes[name]
end
function sprees.get()
return currentRecords
end
function sprees.reset(truncate)
if truncate then
db.removeAllRecords()
else
db.removeRecords(currentMapId)
end
currentRecords = {}
end
function sprees.load()
if db.isConnected() and settings.get("g_spreeRecords") ~= 0 then
local map = db.getMap(game.getMap())
if map then
currentMapId = map["id"]
db.updateMap(currentMapId, os.time())
else
db.addMap(game.getMap(), os.time())
currentMapId = db.getMap(game.getMap())["id"]
end
local records = db.getRecords(currentMapId)
for _, record in ipairs(records) do
currentRecords[record["type"]] = {
["player"] = tonumber(record["player_id"]),
["record"] = tonumber(record["record"])
}
end
end
for i = 0, sprees.TYPE_NUM - 1 do
spreeMessages[i] = {}
spreeMessagesByType[i] = {}
end
local fileName = settings.get("g_fileSprees")
if fileName == "" then
return 0
end
if string.find(fileName, ".toml") == string.len(fileName) - 4 then
local fileDescriptor, fileLength = et.trap_FS_FOpenFile(fileName, et.FS_READ)
if fileLength == -1 then
return 0
end
local fileString = et.trap_FS_Read(fileDescriptor, fileLength)
et.trap_FS_FCloseFile(fileDescriptor)
local fileTable = toml.parse(fileString)
local amount = 0
for name, block in pairs(fileTable) do
for _, spree in ipairs(block) do
if spree["msg"] then
table.insert(spreeMessagesByType[sprees.getRecordTypeByName(name)], spree)
spreeMessages[sprees.getRecordTypeByName(name)][spree["amount"]] = spree
amount = amount + 1
end
end
end
return amount
else
-- compatibility for 1.1.* and lower
outputDebug("Using .cfg files is deprecated as of 1.2.0. Please consider updating to .toml files.", 3)
local amount, array = files.loadFromCFG(fileName, "[a-z]+")
for name, block in pairs(array) do
for _, spree in ipairs(block) do
if spree["msg"] then
for k, v in pairs(spree) do
if k == "amount" then
spree[k] = tonumber(v)
end
end
table.insert(spreeMessagesByType[sprees.getRecordTypeByName(name)], spree)
spreeMessages[sprees.getRecordTypeByName(name)][spree["amount"]] = spree
end
end
end
return amount
end
return 0
end
function sprees.save()
if db.isConnected() and settings.get("g_spreeRecords") ~= 0 then
for i = 0, sprees.TYPE_NUM - 1 do
if currentRecords[i] and currentRecords[i]["record"] > 0 then
if db.getRecord(currentMapId, i) then
db.updateRecord(currentMapId, os.time(), i, currentRecords[i]["record"], currentRecords[i]["player"])
else
db.addRecord(currentMapId, os.time(), i, currentRecords[i]["record"], currentRecords[i]["player"])
end
end
end
end
end
function sprees.printRecords()
if db.isConnected() and settings.get("g_spreeRecords") ~= 0 then
for i = 0, sprees.TYPE_NUM - 1 do
if currentRecords[i] and currentRecords[i]["record"] > 0 then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat -1 \"^dsprees: ^9longest "..sprees.getRecordNameByType(i).." spree (^7"..currentRecords[i]["record"].."^9) by ^7"..db.getLastAlias(currentRecords[i]["player"])["alias"].."^9.\";")
end
end
end
end
function sprees.onGameInit(levelTime, randomSeed, restartMap)
sprees.load()
events.handle("onGameStateChange", sprees.onGameStateChange)
end
events.handle("onGameInit", sprees.onGameInit)
function sprees.onClientConnect(clientId, firstTime, isBot)
playerSprees[clientId] = {}
for i = 0, sprees.TYPE_NUM - 1 do
playerSprees[clientId][i] = 0
end
end
events.handle("onClientConnect", sprees.onClientConnect)
function sprees.onClientDisconnect(clientId)
playerSprees[clientId] = nil
end
events.handle("onClientDisconnect", sprees.onClientDisconnect)
function sprees.onClientTeamChange(clientId, old, new)
events.trigger("onPlayerSpreeEnd", clientId, clientId)
end
function sprees.onGameStateChange(gameState)
if gameState == constants.GAME_STATE_RUNNING then
events.handle("onClientTeamChange", sprees.onClientTeamChange)
events.handle("onPlayerDeath", sprees.onPlayerDeath)
events.handle("onPlayerRevive", sprees.onPlayerRevive)
events.handle("onPlayerSpree", sprees.onPlayerSpree)
events.handle("onPlayerSpreeEnd", sprees.onPlayerSpreeEnd)
elseif gameState == constants.GAME_STATE_INTERMISSION then
sprees.save()
sprees.printRecords()
end
end
function sprees.onPlayerSpree(clientId, causeId, type)
playerSprees[clientId][type] = playerSprees[clientId][type] + 1
local currentSpree = playerSprees[clientId][type]
if db.isConnected() and settings.get("g_spreeRecords") ~= 0 and
(bits.hasbit(settings.get("g_botRecords"), sprees.RECORD_BOTS_PLAYING) or tonumber(et.trap_Cvar_Get("omnibot_playing")) == 0) and
(bits.hasbit(settings.get("g_botRecords"), sprees.RECORD_BOTS) or not players.isBot(clientId)) and
(bits.hasbit(settings.get("g_botRecords"), sprees.RECORD_BOTS) or not players.isBot(causeId)) and
(not currentRecords[type] or currentSpree > currentRecords[type]["record"])
then
currentRecords[type] = {
["player"] = db.getPlayerId(clientId),
["record"] = currentSpree
}
end
if sprees.isSpreeEnabled(type) and #spreeMessagesByType[type] > 0 then
local spreeMessage = spreeMessages[type][currentSpree]
local maxSpreeMessage = spreeMessagesByType[type][#spreeMessagesByType[type]]
if spreeMessage then
local msg = string.format("^1%s SPREE! ^*%s ^*%s ^d(^3%d ^d%ss in a row!)",
string.upper(spreeNames[type]),
players.getName(clientId),
spreeMessage["msg"],
currentSpree,
spreeNames[type])
if settings.get("g_spreeSounds") > 0 and spreeMessage["sound"] and spreeMessage["sound"] ~= "" and files.exists("sound/spree/"..spreeMessage["sound"]) then
if bits.hasbit(settings.get("g_spreeSounds"), sprees.SOUND_PLAY_PUBLIC) then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "playsound \"sound/spree/"..spreeMessage["sound"].."\";")
else
et.trap_SendConsoleCommand(et.EXEC_APPEND, "playsound "..clientId.." \"sound/spree/"..spreeMessage["sound"].."\";")
end
end
et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat -1 \""..msg.."\";")
elseif currentSpree % 5 == 0 and currentSpree > maxSpreeMessage["amount"] then
local msg = string.format("^1%s SPREE! ^*%s ^*%s ^d(^3%d ^d%ss in a row!)",
string.upper(spreeNames[type]),
players.getName(clientId),
maxSpreeMessage["msg"],
currentSpree,
spreeNames[type])
if settings.get("g_spreeSounds") > 0 and maxSpreeMessage["sound"] and maxSpreeMessage["sound"] ~= "" and files.exists("sound/spree/"..maxSpreeMessage["sound"]) then
if bits.hasbit(settings.get("g_spreeSounds"), sprees.SOUND_PLAY_PUBLIC) then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "playsound \"sound/spree/"..maxSpreeMessage["sound"].."\";")
else
et.trap_SendConsoleCommand(et.EXEC_APPEND, "playsound "..clientId.." \"sound/spree/"..maxSpreeMessage["sound"].."\";")
end
end
et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat -1 \""..msg.."\";")
end
end
end
function sprees.onPlayerSpreeEnd(clientId, causeId, type)
if type == sprees.TYPE_DEATH then
if sprees.isSpreeEnabled(type) and sprees.isPlayerOnSpree(clientId, sprees.TYPE_DEATH) then
local msg = string.format("^7%s^d was the first victim of ^7%s ^dafter ^3%d ^d%ss!",
players.getName(causeId),
players.getName(clientId),
playerSprees[clientId][sprees.TYPE_DEATH],
spreeNames[sprees.TYPE_DEATH])
et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat -1 \""..msg.."\";")
end
playerSprees[clientId][sprees.TYPE_DEATH] = 0
elseif type == nil then
for i = 0, sprees.TYPE_NUM - 1 do
if i ~= sprees.TYPE_DEATH then
if sprees.isSpreeEnabled(i) and sprees.isPlayerOnSpree(clientId, i) then
local msg = ""
if clientId == causeId then
msg = string.format("^7%s^d's spree (^3%d ^d%ss) was brought to an end by ^1himself^d!",
players.getName(clientId),
playerSprees[clientId][i],
spreeNames[i])
elseif causeId then
local prefix = ""
if et.gentity_get(clientId, "sess.sessionTeam") == et.gentity_get(causeId, "sess.sessionTeam") then
prefix = "^1TEAMMATE "
end
msg = string.format("^7%s^d's spree (^3%d ^d%ss) was brought to an end by %s^7%s^d!",
players.getName(clientId),
playerSprees[clientId][i],
spreeNames[i],
prefix,
players.getName(causeId))
else
msg = string.format("^7%s^d's spree (^3%d ^d%ss) was brought to an end.",
players.getName(clientId),
playerSprees[clientId][i],
spreeNames[i])
end
et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat -1 \""..msg.."\";")
end
playerSprees[clientId][i] = 0
end
end
end
end
function sprees.onPlayerDeath(victimId, killerId, mod)
if killerId == 1022 then -- killed by map
events.trigger("onPlayerSpreeEnd", victimId)
events.trigger("onPlayerSpree", victimId, nil, sprees.TYPE_DEATH)
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 players.isConnected(victimId) then return end
events.trigger("onPlayerSpreeEnd", victimId, killerId)
events.trigger("onPlayerSpree", victimId, killerId, sprees.TYPE_DEATH)
else -- regular kills
if et.gentity_get(victimId, "sess.sessionTeam") == et.gentity_get(killerId, "sess.sessionTeam") then
-- teamkill handling
events.trigger("onPlayerSpreeEnd", victimId, killerId)
events.trigger("onPlayerSpree", victimId, killerId, sprees.TYPE_DEATH)
else
events.trigger("onPlayerSpreeEnd", killerId, victimId, sprees.TYPE_DEATH)
events.trigger("onPlayerSpree", killerId, victimId, sprees.TYPE_KILL)
-- 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 players.isConnected(victimId) then return end
events.trigger("onPlayerSpreeEnd", victimId, killerId)
events.trigger("onPlayerSpree", victimId, killerId, sprees.TYPE_DEATH)
end
end
end
function sprees.onPlayerRevive(clientMedic, clientVictim)
events.trigger("onPlayerSpree", clientMedic, clientVictim, sprees.TYPE_REVIVE)
end
function sprees.isSpreeEnabled(type)
return bits.hasbit(settings.get("g_spreeMessages"), 2^type)
end
function sprees.isPlayerOnSpree(clientId, type)
return spreeMessagesByType[type][1] and playerSprees[clientId][type] >= spreeMessagesByType[type][1]["amount"]
end
return sprees

View file

@ -32,7 +32,6 @@ local commands
local bots local bots
local fireteams local fireteams
local game local game
local sprees
local teams local teams
local voting local voting
@ -123,7 +122,6 @@ function et_InitGame(levelTime, randomSeed, restartMap)
bots = wolfa_requireModule("game.bots") bots = wolfa_requireModule("game.bots")
game = wolfa_requireModule("game.game") game = wolfa_requireModule("game.game")
fireteams = wolfa_requireModule("game.fireteams") fireteams = wolfa_requireModule("game.fireteams")
sprees = wolfa_requireModule("game.sprees")
teams = wolfa_requireModule("game.teams") teams = wolfa_requireModule("game.teams")
voting = wolfa_requireModule("game.voting") voting = wolfa_requireModule("game.voting")

View file

@ -130,9 +130,6 @@ events.add("onPlayerRevive")
events.add("onPlayerSkillUpdate") events.add("onPlayerSkillUpdate")
events.add("onPlayerSpree")
events.add("onPlayerSpreeEnd")
events.add("onServerCommand") events.add("onServerCommand")
return events return events

View file

@ -26,12 +26,7 @@ local data = {
["g_fileBanners"] = "banners.toml", ["g_fileBanners"] = "banners.toml",
["g_fileGreetings"] = "greetings.toml", ["g_fileGreetings"] = "greetings.toml",
["g_fileRules"] = "rules.toml", ["g_fileRules"] = "rules.toml",
["g_fileSprees"] = "sprees.toml",
["g_playerHistory"] = 1, ["g_playerHistory"] = 1,
["g_spreeMessages"] = 7,
["g_spreeSounds"] = 3,
["g_spreeRecords"] = 1,
["g_botRecords"] = 1,
["g_announceRevives"] = 1, ["g_announceRevives"] = 1,
["g_greetingArea"] = 3, ["g_greetingArea"] = 3,
["g_botGreetings"] = 1, ["g_botGreetings"] = 1,
@ -109,15 +104,6 @@ local cfgStructure = {
["file"] = "g_fileGreetings", ["file"] = "g_fileGreetings",
["area"] = "g_greetingsArea", ["area"] = "g_greetingsArea",
["bots"] = "g_botGreetings" ["bots"] = "g_botGreetings"
},
["records"] = {
["bots"] = "g_botRecords"
},
["sprees"] = {
["file"] = "g_fileSprees",
["messages"] = "g_spreeMessages",
["sounds"] = "g_spreeSounds",
["records"] = "g_spreeRecords"
} }
} }