/
voting.lua
148 lines (119 loc) · 4.8 KB
/
voting.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
-- WolfAdmin module for Wolfenstein: Enemy Territory servers.
-- Copyright (C) 2015-2017 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 = require (wolfa_getLuaPath()..".auth.auth")
local constants = require (wolfa_getLuaPath()..".util.constants")
local events = require (wolfa_getLuaPath()..".util.events")
local settings = require (wolfa_getLuaPath()..".util.settings")
local timers = require (wolfa_getLuaPath()..".util.timers")
local util = require (wolfa_getLuaPath()..".util.util")
local voting = {}
local allowed = {}
local forced = {}
local restricted = {}
function voting.allow(type, value)
allowed[type] = value
et.trap_Cvar_Set("vote_allow_"..type, value)
end
function voting.isAllowed(type)
return (allowed[type] == 1)
end
function voting.force(type)
forced[type] = 1
voting.allow(type, 1)
end
function voting.isForced(type)
return (forced[type] == 1)
end
function voting.isRestricted(type)
return (restricted[type] == 1)
end
function voting.disableNextMap()
et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat -1 \"^dvote: ^9next map voting has automatically been disabled.\";")
voting.allow("nextmap", 0)
end
function voting.load()
for _, type in pairs(constants.VOTE_TYPES) do
allowed[type] = tonumber(et.trap_Cvar_Get("vote_allow_"..type))
forced[type] = 0
end
local restrictedVotes = util.split(settings.get("g_restrictedVotes"), ",")
for _, type in pairs(restrictedVotes) do
restricted[type] = 1
end
end
function voting.onGameInit(levelTime, randomSeed, restartMap)
voting.load()
if settings.get("g_voteNextMapTimeout") > 0 then
voting.allow("nextmap", 1)
end
end
events.handle("onGameInit", voting.onGameInit)
function voting.onGameStateChange(gameState)
if gameState == 0 and settings.get("g_voteNextMapTimeout") > 0 then
timers.add(voting.disableNextMap, settings.get("g_voteNextMapTimeout") * 1000, 1)
end
end
events.handle("onGameStateChange", voting.onGameStateChange)
function voting.onCallvote(clientId, type, args)
if et.gentity_get(clientId, "sess.sessionTeam") == constants.TEAM_SPECTATORS or args[1] == "?" then
return 0
elseif voting.isRestricted(type) and not auth.isPlayerAllowed(clientId, auth.PERM_NOVOTELIMIT) then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"callvote: you are not allowed to call this type of vote.\";")
et.trap_SendServerCommand(clientId, "cp \"You are not allowed to call this type of vote.")
return 1
end
end
events.handle("onCallvote", voting.onCallvote)
function voting.onPollFinish(passed, poll)
if passed then
if poll == "enable bots" then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "needbots")
elseif poll == "disable bots" then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "kickbots")
elseif string.find(poll, "put bots") == 1 then
local team = string.sub(poll, 10)
if team == "axis" then
team = constants.TEAM_AXIS_SC
elseif team == "allies" then
team = constants.TEAM_ALLIES_SC
else
return
end
et.trap_SendConsoleCommand(et.EXEC_APPEND, "putbots "..team)
elseif string.find(poll, "set bot difficulty") == 1 then
local difficulty = string.sub(poll, 20)
if tonumber(difficulty) then
difficulty = tonumber(difficulty)
elseif difficulty == "uber" then
difficulty = 6
elseif difficulty == "professional" then
difficulty = 5
elseif difficulty == "standard" then
difficulty = 4
elseif difficulty == "easy frag" then
difficulty = 3
elseif difficulty == "poor" then
difficulty = 2
elseif difficulty == "very poor" then
difficulty = 1
elseif difficulty == "poorest" then
difficulty = 0
else
return
end
et.trap_SendConsoleCommand(et.EXEC_APPEND, "bot difficulty "..difficulty)
end
end
end
events.handle("onPollFinish", voting.onPollFinish)
return voting