mirror of
https://github.com/etlegacy/wolfadmin.git
synced 2024-11-21 20:01:18 +00:00
Added banners module (refs #98)
This commit is contained in:
parent
217456cbb6
commit
311f4877c7
7 changed files with 148 additions and 12 deletions
16
config/banners.toml
Normal file
16
config/banners.toml
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
[[banner]]
|
||||||
|
welcome = true
|
||||||
|
text = "This server is running WolfAdmin."
|
||||||
|
|
||||||
|
[[banner]]
|
||||||
|
welcome = true
|
||||||
|
text = "Type ^7/wolfadmin ^9for more information."
|
||||||
|
|
||||||
|
[[banner]]
|
||||||
|
welcome = true
|
||||||
|
info = true
|
||||||
|
text = "Type ^7!help ^9to view your available commands."
|
||||||
|
|
||||||
|
[[banner]]
|
||||||
|
info = true
|
||||||
|
text = "Remember to have fun!"
|
|
@ -45,7 +45,9 @@ timeout = 0
|
||||||
restricted = []
|
restricted = []
|
||||||
|
|
||||||
[banners]
|
[banners]
|
||||||
welcome = "^dwolfadmin: ^9This server is running WolfAdmin, type ^7/wolfadmin ^9for more information."
|
file = "banners.toml"
|
||||||
|
interval = 120
|
||||||
|
random = 1
|
||||||
area = 3
|
area = 3
|
||||||
|
|
||||||
[rules]
|
[rules]
|
||||||
|
|
116
luascripts/wolfadmin/admin/banners.lua
Normal file
116
luascripts/wolfadmin/admin/banners.lua
Normal file
|
@ -0,0 +1,116 @@
|
||||||
|
|
||||||
|
-- WolfAdmin module for Wolfenstein: Enemy Territory servers.
|
||||||
|
-- Copyright (C) 2015-2019 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 bits = wolfa_requireModule("util.bits")
|
||||||
|
local events = wolfa_requireModule("util.events")
|
||||||
|
local settings = wolfa_requireModule("util.settings")
|
||||||
|
local timers = wolfa_requireModule("util.timers")
|
||||||
|
|
||||||
|
local toml = wolfa_requireLib("toml")
|
||||||
|
|
||||||
|
local banners = {}
|
||||||
|
|
||||||
|
banners.RANDOM_START = 1
|
||||||
|
banners.RANDOM_ALL = 2
|
||||||
|
|
||||||
|
local nextBannerId = 0
|
||||||
|
local bannerTimer
|
||||||
|
|
||||||
|
local welcomeBanners = {}
|
||||||
|
local infoBanners = {}
|
||||||
|
|
||||||
|
function banners.print(clientId, banner)
|
||||||
|
local target = clientId and clientId or -1
|
||||||
|
|
||||||
|
et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat "..target.." \"^dbanner: ^9"..banner["text"].."\";")
|
||||||
|
end
|
||||||
|
|
||||||
|
function banners.autoprint()
|
||||||
|
if bits.hasbit(settings.get("g_bannerRandomize"), banners.RANDOM_ALL) then
|
||||||
|
nextBannerId = math.random(#infoBanners)
|
||||||
|
elseif nextBannerId ~= #infoBanners then
|
||||||
|
nextBannerId = nextBannerId + 1
|
||||||
|
else
|
||||||
|
nextBannerId = 0
|
||||||
|
end
|
||||||
|
|
||||||
|
banners.print(nil, infoBanners[nextBannerId])
|
||||||
|
end
|
||||||
|
|
||||||
|
function banners.load()
|
||||||
|
local fileName = settings.get("g_fileBanners")
|
||||||
|
|
||||||
|
if fileName == "" then
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
|
||||||
|
local fileDescriptor, fileLength = et.trap_FS_FOpenFile(fileName, et.FS_READ)
|
||||||
|
|
||||||
|
if fileLength == -1 then
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
|
||||||
|
-- in case someone issued a !readconfig, make sure the old data is removed
|
||||||
|
banners.clear()
|
||||||
|
|
||||||
|
local fileString = et.trap_FS_Read(fileDescriptor, fileLength)
|
||||||
|
|
||||||
|
et.trap_FS_FCloseFile(fileDescriptor)
|
||||||
|
|
||||||
|
local fileTable = toml.parse(fileString)
|
||||||
|
|
||||||
|
if fileTable["banner"] then
|
||||||
|
for _, banner in ipairs(fileTable["banner"]) do
|
||||||
|
if banner["welcome"] and banner["welcome"] == true then
|
||||||
|
table.insert(welcomeBanners, banner)
|
||||||
|
end
|
||||||
|
|
||||||
|
if banner["info"] and banner["info"] == true then
|
||||||
|
table.insert(infoBanners, banner)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return #welcomeBanners + #infoBanners
|
||||||
|
end
|
||||||
|
|
||||||
|
function banners.clear()
|
||||||
|
welcomeBanners = {}
|
||||||
|
infoBanners = {}
|
||||||
|
end
|
||||||
|
|
||||||
|
function banners.onPlayerReady(clientId, firstTime)
|
||||||
|
if firstTime then
|
||||||
|
for _, banner in ipairs(welcomeBanners) do
|
||||||
|
banners.print(clientId, banner)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
events.handle("onPlayerReady", banners.onPlayerReady)
|
||||||
|
|
||||||
|
function banners.onGameInit(levelTime, randomSeed, restartMap)
|
||||||
|
banners.load()
|
||||||
|
|
||||||
|
if bits.hasbit(settings.get("g_bannerRandomize"), banners.RANDOM_START) then
|
||||||
|
nextBannerId = math.random(#infoBanners)
|
||||||
|
end
|
||||||
|
|
||||||
|
bannerTimer = timers.add(banners.autoprint, settings.get("g_bannerInterval") * 1000, 0)
|
||||||
|
end
|
||||||
|
events.handle("onGameInit", banners.onGameInit)
|
||||||
|
|
||||||
|
return banners
|
|
@ -15,6 +15,7 @@
|
||||||
-- You should have received a copy of the GNU General Public License
|
-- You should have received a copy of the GNU General Public License
|
||||||
-- 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 banners = wolfa_requireModule("admin.banners")
|
||||||
local rules = wolfa_requireModule("admin.rules")
|
local rules = wolfa_requireModule("admin.rules")
|
||||||
|
|
||||||
local auth = wolfa_requireModule("auth.auth")
|
local auth = wolfa_requireModule("auth.auth")
|
||||||
|
@ -29,11 +30,12 @@ local settings = wolfa_requireModule("util.settings")
|
||||||
|
|
||||||
function commandReadconfig(clientId, command)
|
function commandReadconfig(clientId, command)
|
||||||
settings.load()
|
settings.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()
|
local spreesCount = sprees.load()
|
||||||
|
|
||||||
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"readconfig: loaded "..greetingsCount.." greetings, "..rulesCount.." rules, "..spreesCount.." sprees\";")
|
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"readconfig: loaded "..bannersCount.." banners, "..rulesCount.." rules, "..greetingsCount.." greetings, "..spreesCount.." sprees\";")
|
||||||
|
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
@ -41,11 +43,12 @@ commands.addadmin("readconfig", commandReadconfig, auth.PERM_READCONFIG, "reload
|
||||||
|
|
||||||
function commandReadconfig(clientId, command)
|
function commandReadconfig(clientId, command)
|
||||||
settings.load()
|
settings.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()
|
local spreesCount = sprees.load()
|
||||||
|
|
||||||
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"readconfig: loaded "..greetingsCount.." greetings, "..rulesCount.." rules, "..spreesCount.." sprees\";")
|
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"readconfig: loaded "..bannersCount.." banners, "..rulesCount.." rules, "..greetingsCount.." greetings, "..spreesCount.." sprees\";")
|
||||||
|
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
|
@ -108,11 +108,4 @@ function game.onrevive(clientMedic, clientVictim)
|
||||||
end
|
end
|
||||||
events.handle("onPlayerRevive", game.onrevive)
|
events.handle("onPlayerRevive", game.onrevive)
|
||||||
|
|
||||||
function game.onready(clientId, firstTime)
|
|
||||||
if firstTime and settings.get("g_welcomeMessage") ~= "" then
|
|
||||||
et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat "..clientId.." \""..settings.get("g_welcomeMessage").."\";")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
events.handle("onPlayerReady", game.onready)
|
|
||||||
|
|
||||||
return game
|
return game
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
|
|
||||||
local admin
|
local admin
|
||||||
local balancer
|
local balancer
|
||||||
|
local banners
|
||||||
local bans
|
local bans
|
||||||
local history
|
local history
|
||||||
local mutes
|
local mutes
|
||||||
|
@ -107,6 +108,7 @@ function et_InitGame(levelTime, randomSeed, restartMap)
|
||||||
|
|
||||||
admin = wolfa_requireModule("admin.admin")
|
admin = wolfa_requireModule("admin.admin")
|
||||||
balancer = wolfa_requireModule("admin.balancer")
|
balancer = wolfa_requireModule("admin.balancer")
|
||||||
|
banners = wolfa_requireModule("admin.banners")
|
||||||
bans = wolfa_requireModule("admin.bans")
|
bans = wolfa_requireModule("admin.bans")
|
||||||
history = wolfa_requireModule("admin.history")
|
history = wolfa_requireModule("admin.history")
|
||||||
mutes = wolfa_requireModule("admin.mutes")
|
mutes = wolfa_requireModule("admin.mutes")
|
||||||
|
|
|
@ -23,6 +23,7 @@ local settings = {}
|
||||||
local data = {
|
local data = {
|
||||||
["g_logChat"] = "chat.log",
|
["g_logChat"] = "chat.log",
|
||||||
["g_logAdmin"] = "admin.log",
|
["g_logAdmin"] = "admin.log",
|
||||||
|
["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_fileSprees"] = "sprees.toml",
|
||||||
|
@ -34,7 +35,8 @@ local data = {
|
||||||
["g_announceRevives"] = 1,
|
["g_announceRevives"] = 1,
|
||||||
["g_greetingArea"] = 3,
|
["g_greetingArea"] = 3,
|
||||||
["g_botGreetings"] = 1,
|
["g_botGreetings"] = 1,
|
||||||
["g_welcomeMessage"] = "^dwolfadmin: ^9This server is running WolfAdmin, type ^7/wolfadmin ^9for more information.",
|
["g_bannerInterval"] = 120,
|
||||||
|
["g_bannerRandomize"] = 1,
|
||||||
["g_welcomeArea"] = 3,
|
["g_welcomeArea"] = 3,
|
||||||
["g_evenerMinDifference"] = 2,
|
["g_evenerMinDifference"] = 2,
|
||||||
["g_evenerMaxDifference"] = 5,
|
["g_evenerMaxDifference"] = 5,
|
||||||
|
@ -95,7 +97,9 @@ local cfgStructure = {
|
||||||
["restricted"] = "g_restrictedVotes"
|
["restricted"] = "g_restrictedVotes"
|
||||||
},
|
},
|
||||||
["banners"] = {
|
["banners"] = {
|
||||||
["welcome"] = "g_welcomeMessage",
|
["file"] = "g_fileBanners",
|
||||||
|
["interval"] = "g_bannerInterval",
|
||||||
|
["random"] = "g_bannerRandomize",
|
||||||
["area"] = "g_welcomeArea"
|
["area"] = "g_welcomeArea"
|
||||||
},
|
},
|
||||||
["rules"] = {
|
["rules"] = {
|
||||||
|
|
Loading…
Reference in a new issue