@@ -20,6 +20,29 @@ function timer.Create(identifier, delay, reps, func)
20
20
return blobsProfiler .original_timerCreate (identifier , delay , reps , func )
21
21
end
22
22
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
+
23
46
blobsProfiler .RegisterModule (" Timers" , {
24
47
Icon = " icon16/clock.png" ,
25
48
OrderPriority = 7 ,
@@ -34,6 +57,11 @@ blobsProfiler.RegisterModule("Timers", {
34
57
end
35
58
end ,
36
59
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
37
65
return createdTimers
38
66
end ,
39
67
PreloadClient = true ,
@@ -53,38 +81,57 @@ blobsProfiler.RegisterModule("Timers", {
53
81
icon = " icon16/application_osx_terminal.png"
54
82
},
55
83
{ -- 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
59
88
if timeLeft < 0 then
60
89
return " Resume"
61
90
else
62
91
return " Pause"
63
92
end
64
93
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
68
98
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
+
70
108
node .Icon :SetImage (" icon16/clock_stop.png" )
71
109
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
73
118
node .Icon :SetImage (" icon16/clock_play.png" )
74
119
end
75
120
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
79
125
if timeLeft < 0 then
80
126
node .Icon :SetImage (" icon16/clock_stop.png" )
81
127
else
82
128
node .Icon :SetImage (" icon16/clock_play.png" )
83
129
end
84
130
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
88
135
if timeLeft < 0 then
89
136
return " icon16/clock_stop.png"
90
137
else
@@ -93,29 +140,49 @@ blobsProfiler.RegisterModule("Timers", {
93
140
end
94
141
},
95
142
{ -- 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
98
148
return " Delete"
99
149
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
102
159
node .Label :SetTextColor (Color (255 ,0 ,0 ))
103
160
node .Icon :SetImage (" icon16/clock_delete.png" )
104
161
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
107
164
node .Label :SetTextColor (Color (255 ,0 ,0 ))
108
165
node .Icon :SetImage (" icon16/clock_delete.png" )
109
166
end
110
167
end ,
111
168
icon = " icon16/clock_delete.png"
112
169
},
113
170
{ -- 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
116
175
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
+
119
186
node :Remove ()
120
187
end ,
121
188
icon = " icon16/clock_red.png"
0 commit comments