-
Notifications
You must be signed in to change notification settings - Fork 0
/
slotBlockGameGUI.lua
290 lines (200 loc) · 9.39 KB
/
slotBlockGameGUI.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
local agcST = {}
--
-- AGC_MP 服务器可选飞机管理工具
-- AGC_MP Slot Blocking Tools
--
-- Version 1.5
--
-- Change logs:
-- 1. 修改了管理员命令,增加-id命令以查看玩家playerID。
--
-- By Dennic - https://github.com/Dennic/DCS-Script-AGC_MP
--
agcST.disabledPlayerTimeleft = {}
agcST.playerIDList = {}
agcST.Admins = {"Server Admin", "小恐龙Dennic", }
function agcST.agcCheck(_playerID, _slotID, _mode)
local _unitId = agcST.getUnitId(_slotID);
local _playerName = net.get_player_info(_playerID, 'name')
if _playerName == nil then
return true
end
local _flag = 0
if _mode == 1 then
_flag = agcST.getFlagValue("AGC_DontTakeoff".._playerName:gsub('%W',''))
if _flag == 1 then
return false
end
elseif _mode == 2 then
_flag = agcST.getFlagValue("AGC_DontEject".._playerName:gsub('%W',''))
if _flag == 1 then
return false
end
elseif _mode == 3 then
_flag = agcST.getFlagValue("AGC_DontLand".._playerName:gsub('%W',''))
if _flag == 1 then
return false
end
else
return true
end
return true
end
function agcST.getFlagValue(_flag)
local _status,_error = net.dostring_in('server', " return trigger.misc.getUserFlag(\"".._flag.."\"); ")
if not _status and _error then
net.log("error getting flag: ".._error)
return 0
else
return tonumber(_status)
end
end
function agcST.getUnitId(_slotID)
local _unitId = tostring(_slotID)
if string.find(tostring(_unitId),"_",1,true) then
--extract substring
_unitId = string.sub(_unitId,1,string.find(_unitId,"_",1,true))
net.log("Unit ID Substr ".._unitId)
end
return tonumber(_unitId)
end
agcST.onGameEvent = function(eventName,playerID,arg2,arg3,arg4) -- This stops the user flying again after crashing or other events
if DCS.isServer() and DCS.isMultiplayer() then
if DCS.getModelTime() > 1 then -- must check this to prevent a possible CTD by using a_do_script before the game is ready to use a_do_script. -- Source GRIMES :)
local _playerDetails = nil
local _allow = true
if eventName == "eject" then
-- is player in a slot and valid?
_playerDetails = net.get_player_info(playerID)
if _playerDetails ~=nil and _playerDetails.side ~= 0 and _playerDetails.slot ~= "" and _playerDetails.slot ~= nil then
_allow = agcST.agcCheck(playerID, _playerDetails.slot, 2)
if not _allow then -- put to spectators
net.force_player_slot(playerID, 0, '')
end
end
elseif eventName == "takeoff" or eventName == "landing" then
-- is player in a slot and valid?
_playerDetails = net.get_player_info(playerID)
if _playerDetails ~=nil and _playerDetails.side ~= 0 and _playerDetails.slot ~= "" and _playerDetails.slot ~= nil then
if eventName == "takeoff" then
_allow = agcST.agcCheck(playerID, _playerDetails.slot, 1)
elseif eventName == "landing" then
_allow = agcST.agcCheck(playerID, _playerDetails.slot, 3)
end
if not _allow then
local _playerName = _playerDetails.name
local _time = math.floor(os.time())
local _timeout = agcST.getFlagValue("AGC_DisableTimeout")
agcST.disabledPlayerTimeleft[_playerName] = _time + _timeout
agcST.disabledPlayer(playerID, _timeout, true)
end
end
end
end
end
end
agcST.onPlayerTryChangeSlot = function(playerID, side, slotID)
if (side ~=0 and slotID ~='' and slotID ~= nil) then
local _playerDetails = net.get_player_info(playerID)
if _playerDetails == nil then
return true
end
local _playerName = _playerDetails.name
if agcST.disabledPlayerTimeleft[_playerName] then
local _time = math.floor(os.time())
if agcST.disabledPlayerTimeleft[_playerName] > _time then
agcST.disabledPlayer(playerID, agcST.disabledPlayerTimeleft[_playerName] - _time, false)
return false
end
end
agcST.playerIDList[_playerName] = playerID
net.log("Add to playerIDList: ".._playerName.." -- "..playerID)
end
net.log("allowing - playerid: "..playerID.." side:"..side.." slot: "..slotID)
return true
end
agcST.onPlayerTrySendChat = function(playerID, msg, all)
-- if DCS.isServer() and DCS.isMultiplayer() then
local _name = net.get_player_info(playerID, 'name')
if _name ~= nil then
if agcST.checkInTable(agcST.Admins, _name) then
local _cmd = agcST.trimStr(msg)
local _chatMessage = ""
if _cmd:sub(1,4) == "-ban" and string.len(_cmd) >= 6 then
if tonumber(_cmd:sub(6,-1)) == nil then
net.send_chat_to("命令输入错误 请输入:-ban [playerID]", playerID)
return msg
end
for _playerName, _playerID in pairs(agcST.playerIDList) do
if _playerID == tonumber(_cmd:sub(6,-1)) then
local _time = math.floor(os.time())
local _timeout = agcST.getFlagValue("AGC_DisableTimeout")
agcST.disabledPlayerTimeleft[_playerName] = _time + _timeout
agcST.disabledPlayer(_playerID, _timeout, true)
_chatMessage = string.format("玩家【%s】被管理员停飞 %i 秒。", _playerName, _timeout)
net.send_chat(_chatMessage, 0, 0)
break
end
end
elseif _cmd:sub(1,5) == "-kick" and string.len(_cmd) >= 7 then
if tonumber(_cmd:sub(7,-1)) == nil then
net.send_chat_to("命令输入错误 请输入:-kick [playerID]", playerID)
return msg
end
for _playerName, _playerID in pairs(agcST.playerIDList) do
if _playerID == tonumber(_cmd:sub(7,-1)) then
net.force_player_slot(_playerID, 0, '')
_chatMessage = string.format("玩家【%s】被管理员踢回到观众席。",_playerName)
net.send_chat(_chatMessage, 0, 0)
break
end
end
elseif _cmd:sub(1,3) == "-id" and string.len(_cmd) >= 5 then
local _check = _cmd:sub(5,-1)
local _result = 0
local _msg = ""
for _playerName, _playerID in pairs(agcST.playerIDList) do
if string.find(_playerName, _check) ~= nil then
_result = _result + 1
_msg = _msg .. string.format("【%d -- %s】 ", _playerID, _playerName)
end
end
_chatMessage = string.format("找到 %d 个玩家:%s", _result, _msg)
net.send_chat_to(_chatMessage, playerID)
end
end
else
net.log("playername null")
end
return msg
end
agcST.trimStr = function(_str)
return string.format( "%s", _str:match( "^%s*(.-)%s*$" ) )
end
function agcST.checkInTable(_tb, _vl)
for _i,_v in pairs(_tb) do
if _v == _vl then
return true
end
end
return false
end
function agcST.chatmsg_net(text)
local clientindex = 0
while clientindex <= 128 do
net.send_chat(text, clientindex, clientindex)
clientindex = clientindex + 1
end
end
agcST.disabledPlayer = function(playerID, timeLeft, _toSpectators)
if _toSpectators then
-- put to spectators
net.force_player_slot(playerID, 0, '')
end
local _playerName = net.get_player_info(playerID, 'name')
if _playerName ~= nil then
local _chatMessage = string.format("【 %s - 你因违反服务器规定,现已被停飞。请 %i 秒后再试!】",_playerName,timeLeft)
net.send_chat_to(_chatMessage, playerID)
end
end
DCS.setUserCallbacks(agcST)