Skip to content

Commit cad7927

Browse files
committed
Fixes SV side Timers module
Status, Pause/UnPause, Remove, Delete Reference
1 parent d6b7784 commit cad7927

File tree

4 files changed

+108
-37
lines changed

4 files changed

+108
-37
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ For now, the all modules are currently locked away behind only a usergroup == su
4343
- :wavy_dash: Module-system (Code refactor)
4444

4545
### Known issues
46-
- Other addons detouring timer.Create can cause issues with obtaining source
47-
- Timer status isn't correctly reported for SV timers
46+
- Other addons detouring timer.Create can cause issues with obtaining correct source
4847

4948
### Credits
5049
- [Ace Editor](https://ace.c9.io/ "Ace Editor")

lua/blobsprofiler/client/cl_blobsprofiler.lua

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ local function addDTreeNode(parentNode, nodeData, specialType, isRoot, varType,
425425
continue
426426
end
427427

428-
if v.onLoad then v.onLoad(nodeData, childNode) end
428+
if v.onLoad then v.onLoad(nodeData, childNode, luaState) end
429429
end
430430
end
431431

@@ -490,15 +490,15 @@ local function addDTreeNode(parentNode, nodeData, specialType, isRoot, varType,
490490

491491
local useName = rcM.name
492492
if type(rcM.name) == "function" then
493-
useName = rcM.name(nodeData, childNode)
493+
useName = rcM.name(nodeData, childNode, luaState)
494494
end
495495
if useName then
496496
if rcM.submenu then
497497
local rcChild, rcParent = RCMenu:AddSubMenu(useName)
498498

499499
local useIcon = rcM.icon
500500
if type(rcM.icon) == "function" then
501-
useIcon = rcM.icon(nodeData, childNode)
501+
useIcon = rcM.icon(nodeData, childNode, luaState)
502502
end
503503
if useIcon then rcParent:SetIcon(useIcon) end
504504

@@ -509,19 +509,19 @@ local function addDTreeNode(parentNode, nodeData, specialType, isRoot, varType,
509509

510510
local useNameSM = rcMS.name
511511
if type(rcMS.name) == "function" then
512-
useNameSM = rcMS.name(nodeData, childNode)
512+
useNameSM = rcMS.name(nodeData, childNode, luaState)
513513
end
514514
if useNameSM then
515515
local rcChildP = rcChild:AddOption(useNameSM, function()
516516
rcMS.func(nodeData, childNode, luaState)
517517
if rcMS.onLoad then
518-
rcMS.onLoad(nodeData, childNode)
518+
rcMS.onLoad(nodeData, childNode, luaState)
519519
end
520520
end)
521521

522522
local useIconSM = rcMS.icon
523523
if type(rcMS.icon) == "function" then
524-
useIconSM = rcMS.icon(nodeData, childNode)
524+
useIconSM = rcMS.icon(nodeData, childNode, luaState)
525525
end
526526
if useIconSM then rcChildP:SetIcon(useIconSM) end
527527
end
@@ -530,13 +530,13 @@ local function addDTreeNode(parentNode, nodeData, specialType, isRoot, varType,
530530
local rcOption = RCMenu:AddOption(useName, function()
531531
rcM.func(nodeData, childNode, luaState)
532532
if rcM.onLoad then
533-
rcM.onLoad(nodeData, childNode)
533+
rcM.onLoad(nodeData, childNode, luaState)
534534
end
535535
end)
536536

537537
local useIcon = rcM.icon
538538
if type(rcM.icon) == "function" then
539-
useIcon = rcM.icon(nodeData, childNode)
539+
useIcon = rcM.icon(nodeData, childNode, luaState)
540540
end
541541
if useIcon then rcOption:SetIcon(useIcon) end
542542
end
@@ -554,7 +554,7 @@ local function addDTreeNode(parentNode, nodeData, specialType, isRoot, varType,
554554
continue
555555
end
556556

557-
if v.onLoad then v.onLoad(nodeData, childNode) end
557+
if v.onLoad then v.onLoad(nodeData, childNode, luaState) end
558558
end
559559
end
560560

lua/blobsprofiler/server/sv_blobsprofiler.lua

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,8 @@ local function transformModuleNameForPermissionsCheck(moduleName)
118118
end
119119
end
120120

121-
net.Receive("blobsProfiler:requestData", function(l, ply)
121+
blobsProfiler.SendModuleData = function(rawModuleName, ply)
122122
if not blobsProfiler.CanAccess(ply, "serverData") then return end
123-
local rawModuleName = net.ReadString()
124123
blobsProfiler.Log(blobsProfiler.L_DEBUG, "requestData SV: ".. rawModuleName)
125124

126125
local permStrs = transformModuleNameForPermissionsCheck(rawModuleName)
@@ -144,4 +143,10 @@ net.Receive("blobsProfiler:requestData", function(l, ply)
144143

145144
sendDataToClient(ply, rawModuleName, dataTbl)
146145
blobsProfiler.Log(blobsProfiler.L_DEBUG, "Module: ".. rawModuleName .." data sent to client!")
146+
end
147+
148+
net.Receive("blobsProfiler:requestData", function(l, ply)
149+
local rawModuleName = net.ReadString()
150+
151+
blobsProfiler.SendModuleData(rawModuleName, ply)
147152
end)

lua/blobsprofiler/shared/modules/bp_timers.lua

Lines changed: 91 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,29 @@ function timer.Create(identifier, delay, reps, func)
2020
return blobsProfiler.original_timerCreate(identifier, delay, reps, func)
2121
end
2222

23+
if SERVER then
24+
util.AddNetworkString("blobsProfiler:Timers_Control")
25+
net.Receive("blobsProfiler:Timers_Control", function(len,ply)
26+
if not blobsProfiler.CanAccess(ply, "Timers") then return end
27+
if not blobsProfiler.CanAccess(ply, "Timers_Control") then return end
28+
29+
local timerName = net.ReadString()
30+
local Control = net.ReadUInt(2)
31+
32+
if Control == 1 then
33+
timer.Pause(timerName)
34+
elseif Control == 2 then
35+
timer.UnPause(timerName)
36+
elseif Control == 3 then
37+
timer.Remove(timerName)
38+
elseif Control == 0 then
39+
createdTimers[timerName] = nil
40+
end
41+
42+
blobsProfiler.SendModuleData("Timers", ply)
43+
end)
44+
end
45+
2346
blobsProfiler.RegisterModule("Timers", {
2447
Icon = "icon16/clock.png",
2548
OrderPriority = 7,
@@ -34,6 +57,11 @@ blobsProfiler.RegisterModule("Timers", {
3457
end
3558
end,
3659
PrepServerData = function()
60+
for k,v in pairs(createdTimers) do
61+
local timerAlive = timer.Exists(k)
62+
v.timeLeft = timerAlive and timer.TimeLeft(k)
63+
v.isAlive = timerAlive
64+
end
3765
return createdTimers
3866
end,
3967
PreloadClient = true,
@@ -53,38 +81,57 @@ blobsProfiler.RegisterModule("Timers", {
5381
icon = "icon16/application_osx_terminal.png"
5482
},
5583
{ -- Pause/Resume timer
56-
name = function(ref, node)
57-
if not timer.Exists(node.GlobalPath) then return end
58-
local timeLeft = timer.TimeLeft(node.GlobalPath)
84+
name = function(ref, node, luaState)
85+
if luaState == "Client" and not timer.Exists(node.GlobalPath) then return end
86+
if luaState == "Server" and not ref.value.isAlive then return end
87+
local timeLeft = luaState == "Client" and timer.TimeLeft(node.GlobalPath) or ref.value.timeLeft
5988
if timeLeft < 0 then
6089
return "Resume"
6190
else
6291
return "Pause"
6392
end
6493
end,
65-
func = function(ref, node)
66-
if not timer.Exists(node.GlobalPath) then return end
67-
local timeLeft = timer.TimeLeft(node.GlobalPath)
94+
func = function(ref, node, luaState)
95+
if luaState == "Client" and not timer.Exists(node.GlobalPath) then return end
96+
if luaState == "Server" and not ref.value.isAlive then return end
97+
local timeLeft = luaState == "Client" and timer.TimeLeft(node.GlobalPath) or ref.value.timeLeft
6898
if timeLeft < 0 then
69-
timer.UnPause(node.GlobalPath)
99+
if luaState == "Client" then
100+
timer.UnPause(node.GlobalPath)
101+
else
102+
net.Start("blobsProfiler:Timers_Control")
103+
net.WriteString(node.GlobalPath)
104+
net.WriteUInt(2, 2)
105+
net.SendToServer()
106+
end
107+
70108
node.Icon:SetImage("icon16/clock_stop.png")
71109
else
72-
timer.Pause(node.GlobalPath)
110+
if luaState == "Client" then
111+
timer.Pause(node.GlobalPath)
112+
else
113+
net.Start("blobsProfiler:Timers_Control")
114+
net.WriteString(node.GlobalPath)
115+
net.WriteUInt(1, 2)
116+
net.SendToServer()
117+
end
73118
node.Icon:SetImage("icon16/clock_play.png")
74119
end
75120
end,
76-
onLoad = function(ref, node)
77-
if not timer.Exists(node.GlobalPath) then return end
78-
local timeLeft = timer.TimeLeft(node.GlobalPath)
121+
onLoad = function(ref, node, luaState)
122+
if luaState == "Client" and not timer.Exists(node.GlobalPath) then return end
123+
if luaState == "Server" and not ref.value.isAlive then return end
124+
local timeLeft = luaState == "Client" and timer.TimeLeft(node.GlobalPath) or ref.value.timeLeft
79125
if timeLeft < 0 then
80126
node.Icon:SetImage("icon16/clock_stop.png")
81127
else
82128
node.Icon:SetImage("icon16/clock_play.png")
83129
end
84130
end,
85-
icon = function(ref, node)
86-
if not timer.Exists(node.GlobalPath) then return end
87-
local timeLeft = timer.TimeLeft(node.GlobalPath)
131+
icon = function(ref, node, luaState)
132+
if luaState == "Client" and not timer.Exists(node.GlobalPath) then return end
133+
if luaState == "Server" and not ref.value.isAlive then return end
134+
local timeLeft = luaState == "Client" and timer.TimeLeft(node.GlobalPath) or ref.value.timeLeft
88135
if timeLeft < 0 then
89136
return "icon16/clock_stop.png"
90137
else
@@ -93,29 +140,49 @@ blobsProfiler.RegisterModule("Timers", {
93140
end
94141
},
95142
{ -- Delete timer
96-
name = function(ref, node)
97-
if not timer.Exists(node.GlobalPath) then node.Label:SetTextColor(Color(255,0,0)) return end
143+
name = function(ref, node, luaState)
144+
if (luaState == "Client" and not timer.Exists(node.GlobalPath)) or (luaState == "Server" and not ref.value.isAlive) then
145+
node.Label:SetTextColor(Color(255,0,0))
146+
return
147+
end
98148
return "Delete"
99149
end,
100-
func = function(ref, node)
101-
timer.Remove(node.GlobalPath)
150+
func = function(ref, node, luaState)
151+
if luaState == "Client" then
152+
timer.Remove(node.GlobalPath)
153+
else
154+
net.Start("blobsProfiler:Timers_Control")
155+
net.WriteString(node.GlobalPath)
156+
net.WriteUInt(3, 2)
157+
net.SendToServer()
158+
end
102159
node.Label:SetTextColor(Color(255,0,0))
103160
node.Icon:SetImage("icon16/clock_delete.png")
104161
end,
105-
onLoad = function(ref, node)
106-
if not timer.Exists(node.GlobalPath) then
162+
onLoad = function(ref, node, luaState)
163+
if (luaState == "Client" and not timer.Exists(node.GlobalPath)) or (luaState == "Server" and not ref.value.isAlive) then
107164
node.Label:SetTextColor(Color(255,0,0))
108165
node.Icon:SetImage("icon16/clock_delete.png")
109166
end
110167
end,
111168
icon = "icon16/clock_delete.png"
112169
},
113170
{ -- Remove timer reference
114-
name = function(ref, node)
115-
if not timer.Exists(node.GlobalPath) then return "Remove reference" end
171+
name = function(ref, node, luaState)
172+
if (luaState == "Client" and not timer.Exists(node.GlobalPath)) or (luaState == "Server" and not ref.value.isAlive) then
173+
return "Remove reference"
174+
end
116175
end,
117-
func = function(ref, node)
118-
blobsProfiler.createdTimers[node.GlobalPath] = nil
176+
func = function(ref, node, luaState)
177+
createdTimers[node.GlobalPath] = nil
178+
179+
if luaState == "Server" then
180+
net.Start("blobsProfiler:Timers_Control")
181+
net.WriteString(node.GlobalPath)
182+
net.WriteUInt(0, 2)
183+
net.SendToServer()
184+
end
185+
119186
node:Remove()
120187
end,
121188
icon = "icon16/clock_red.png"

0 commit comments

Comments
 (0)