-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.lua
280 lines (254 loc) · 7.98 KB
/
main.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
--=================================================================
-- BeamBase
-- By Titch
--=================================================================
-- Configuration
--=================================================================
-- Settings = Value (true/false)
--=================================================================
local admins = {
"beammp:62932", -- Unsure
"beammp:342659", -- Titch
"beammp:124353" -- Leo
}
local allowGuests = true
local allowGuestChat = false
--=================================================================
-- DO NOT TOUCH BEYOND THIS POINT
--=================================================================
pluginPath = debug.getinfo(1).source:gsub("\\","/")
pluginPath = pluginPath:sub(2,(pluginPath:find("main.lua"))-2)
package.path = package.path .. ";;" .. pluginPath .. "/?.lua;;".. pluginPath .. "/lua/?.lua"
package.cpath = package.cpath .. ";;" .. pluginPath .. "/?.dll;;" .. pluginPath .. "/lib/?.dll"
package.cpath = package.cpath .. ";;" .. pluginPath .. "/?.so;;" .. pluginPath .. "/lib/?.so"
function trim(s)
-- from PiL2 20.4
return (s:gsub("^%s*(.-)%s*$", "%1"))
end
function checkAdmin(identifiers)
for TYPE, ID in pairs(identifiers) do
for _, admin in pairs(admins) do
--print(admin .. ' -> '..TYPE .. ":" ..ID)
if TYPE..":"..ID == admin then
--print('Harry, your a ~wizard~ admin!!')
return true
end
end
end
return false
end
function split(str, patt)
vals = {}; valindex = 0; word = ""
-- need to add a trailing separator to catch the last value.
str = str .. patt
for i = 1, string.len(str) do
cha = string.sub(str, i, i)
if cha ~= patt then
word = word .. cha
else
if word ~= nil then
vals[valindex] = word
valindex = valindex + 1
word = ""
else
-- in case we get a line with no data.
break
end
end
end
return vals
end
-- Load the bans list
local bans = {}
function onInit()
print('BeamBase Starting!')
local bans_file_path = "Resources/Server/" .. pluginPath .. "/bans.txt"
local bans_file = io.open(bans_file_path)
print('Loading Banned Players List..')
if not bans_file then
print("Failed to load bans.txt from '" .. bans_file_path .. "'!")
return
end
local count = 0
for line in bans_file:lines() do
count = count + 1
print(' '..line)
table.insert(bans, line);
end
print(count..' Bans Loaded.')
end
function toboolean(str)
local bool = false
if str == "true" or str == "1" then
bool = true
end
return bool
end
print('LOADED!!!!')
function onChatMessage(id, name, message)
local isGuest = MP.IsPlayerGuest(id)
local identifiers = MP.GetPlayerIdentifiers(id)
if not allowGuestChat then
if isGuest and not allowGuestChat then
MP.SendChatMessage(id, '^4Sorry Chat for Guest Accounts is Disabled on this server.')
return 1
end
end
local message = trim(message)
message = split(message, ' ')
if message[0] == '/help' then
if checkAdmin(identifiers) then
MP.SendChatMessage(id, 'The following Commands are available:')
MP.SendChatMessage(id, '/help - This help message')
MP.SendChatMessage(id, '/players - Display a list of players and their ID')
MP.SendChatMessage(id, '/say - Say a message as the server.')
MP.SendChatMessage(id, '/id /identifiers <optional id> - Show yours/another players identifiers')
MP.SendChatMessage(id, '/allowGuestChat <true|false|1|0> - Allow Guests to use the chat')
MP.SendChatMessage(id, '/allowGuests <true|false|1|0>- Allow Guests to join the server.... or not')
MP.SendChatMessage(id, '/kick <id> <reason> - Kick a player')
MP.SendChatMessage(id, '/ban <id> <reason> - Ban a player')
else
MP.SendChatMessage(id, '^4Insufficient Permissions')
end
return 1
end
if message[0] == '/say' then
if checkAdmin(identifiers) then
if message[1] then
message[0] = ''
msg = table.concat(message, ' ')
MP.SendChatMessage(-1, tostring(msg))
else
MP.SendChatMessage(id, 'Please provide a message to send to the server.')
end
else
MP.SendChatMessage(id, '^4Insufficient Permissions')
end
return 1
end
if message[0] == '/allowGuests' then
if checkAdmin(identifiers) then
if message[1] then
allowGuests = toboolean(message[1])
MP.SendChatMessage(id, 'Allow Guests has now been set to: '..message[1])
else
MP.SendChatMessage(id, 'Allow Guests is currently set to: '..tostring(allowGuests))
end
else
MP.SendChatMessage(id, '^4Insufficient Permissions')
end
return 1
end
if message[0] == '/allowGuestChat' then
if checkAdmin(identifiers) then
if message[1] then
allowGuestChat = toboolean(message[1])
MP.SendChatMessage(id, 'Allow Guest Chat has now been set to: '..message[1])
else
MP.SendChatMessage(id, 'Allow Guest Chat is currently set to: '..tostring(allowGuestChat))
end
else
MP.SendChatMessage(id, '^4Insufficient Permissions')
end
return 1
end
if message[0] == '/players' then
if checkAdmin(identifiers) then
MP.SendChatMessage(id, 'There are currently '..MP.GetPlayerCount()..' on the server')
local players = MP.GetPlayers()
for playerID, playerName in pairs(players) do
MP.SendChatMessage(id, 'ID: '..playerID..' Name: '..playerName)
end
else
MP.SendChatMessage(id, '^4Insufficient Permissions')
end
return 1
end
if message[0] == '/id' or message[0] == '/identifiers' then
if message[1] then
MP.SendChatMessage(id, 'Player '..message[1].."'s identifiers:")
for TYPE, ID in pairs(MP.GetPlayerIdentifiers(tonumber(message[1]))) do
MP.SendChatMessage(id, 'ID: '..TYPE..' Name: '..ID)
end
else
MP.SendChatMessage(id, 'Your identifiers:')
for TYPE, ID in pairs(identifiers) do
MP.SendChatMessage(id, 'Type: '..TYPE..' Value: '..ID..' (Raw: '..TYPE..':'..ID..')')
end
end
return 1
end
if message[0] == '/kick' then
if checkAdmin(identifiers) then
local players = MP.GetPlayers()
for playerID, playerName in pairs(players) do
print(playerID, message[1])
if message[1] == tostring(playerID) then
if message[2] then
message[0] = ''
message[1] = ''
msg = table.concat(message, ' ')
MP.DropPlayer(tonumber(playerID), msg)
MP.SendChatMessage(-1, playerName..' was kicked from the server.')
MP.SendChatMessage(-1, 'Reason: '..msg)
else
MP.DropPlayer(tonumber(playerID))
MP.SendChatMessage(-1, playerName..' was kicked from the server.')
end
end
end
else
MP.SendChatMessage(id, '^4Insufficient Permissions')
end
return 1
end
if message[0] == '/ban' then
if checkAdmin(identifiers) then
local players = MP.GetPlayers()
for playerID, playerName in pairs(players) do
if message[1] == ''..playerID then
local ids = MP.GetPlayerIdentifiers(playerID)
if checkAdmin(ids) then
-- Do not allow admins to ban admins
MP.SendChatMessage(id, '^4You cannot ban another server admin.')
else
MP.DropPlayer(tonumber(message[1]))
local file = io.open("bans.txt", "a");
for TYPE, ID in pairs(ids) do
file:write(ID, "\n")
table.insert (bans, ID);
end
MP.SendChatMessage(-1, playerName..' was banned.')
if message[2] then
message[0] = ''
message[1] = ''
msg = table.concat(message, ' ')
MP.SendChatMessage(-1, 'Reason: '..msg)
end
end
end
end
else
MP.SendChatMessage(id, '^4Insufficient Permissions')
end
return 1
end
end
function onPlayerAuth(name, _, isGuest, identifiers)
if isGuest and not allowGuests then
return "You must be signed in to join this server!"
end
local id = identifiers.beammp
for _, player in pairs(bans) do
if id == player then
print('Connecting Player "'..name..'" is banned from the server.')
return "You are banned from this server."
end
end
end
function onPlayerConnecting(id)
print('Player '..MP.GetPlayerName(id)..' ('..id..') connecting.')
end
MP.RegisterEvent("onPlayerAuth","onPlayerAuth")
MP.RegisterEvent("onPlayerConnecting","onPlayerConnecting")
MP.RegisterEvent("onChatMessage","onChatMessage")