-
Notifications
You must be signed in to change notification settings - Fork 1
/
examples.lua
89 lines (70 loc) · 2.37 KB
/
examples.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
require"network"
if not istable(gmnetwork) then return end
do -- Client error report handle
gmnetwork.EnableClientErrHandle(true)
hook.Add("GmNetwork.OnClientErr", "Example", function(num_idx, str_err)
print(Entity(num_idx)) -- Player
print("Error: ", str_err)
return true -- prevent default error actions (console print, clientside_errors.txt log, lua_error_url send)
end)
end
do -- Client request to server concommand handle
gmnetwork.EnableClientProcessCmd(true)
hook.Add("GmNetwork.ProcessCmd", "Example", function(num_userid, str_cmd)
local ply = Player(num_userid)
if not IsValid(ply) then return true end
Msg(Format("[ProcessCmds] Player '%s' (id: %s | ip: %s) command: '%s'\n", ply:Nick(), ply:SteamID(), ply:IPAddress(), str_cmd))
-- Request block example
if str_cmd:find"status" then
return true
end
end)
end
do -- Lua auto-refresh handle
gmnetwork.EnableLuaAutoRefreshHandle(true)
hook.Add("GmNetwork.OnLuaRefresh", "Example", function(file_path)
print("Auto-refreshed: ", file_path)
-- Refresh block example
-- (blocking there didn't tested and not guaranted!)
if file_path:find"myfile.lua" then
return true
end
end)
end
do -- Custom disconnect reason on server shutdown (built-in 'ply:Kick' and 'game.KickID' can't do this)
hook.Add("ShutDown", "Example", function()
for _, ply in ipairs(player.GetAll()) do
gmnetwork.DisconnectClient(ply:UserID(), "Server is restarting. This may take 2-5 min.")
end
end)
end
do -- Close connection with clients (aka without disconnect message) on server shutdown
hook.Add("ShutDown", "Example2", function()
for _, ply in ipairs(player.GetAll()) do
gmnetwork.DisconnectClientSilent(ply:UserID())
end
end)
end
do -- Bypass command blacklist without alias
-- Example 1
local cmd = "rcon_password "
local passEnv = gmnetwork.GetEnv"RCON_PASS"
if passEnv then
cmd = cmd .. passEnv
else
for i = 12, 25 do
cmd = cmd .. string.char(math.random(97, 122))
end
end
gmnetwork.GMOD_RawServerCommand(cmd)
-- Example 2
util.AddNetworkString"ingame_rcon"
net.Receive("ingame_rcon", function(l, ply)
if not IsValid(ply) then return end
if not ply:IsFullyAuthenticated() then return end
if not ply:IsSuperAdmin() then return end
local rawcmd = net.ReadString()
if not isstring(rawcmd) or rawcmd:len() == 0 then return end
gmnetwork.GMOD_RawServerCommand(rawcmd)
end)
end