@@ -62,85 +62,104 @@ static void EndConsoleOutputCapture(CClient* pClient, const SString& strIfNoOutp
62
62
63
63
bool CConsoleCommands::StartResource (CConsole* pConsole, const char * szArguments, CClient* pClient, CClient* pEchoClient)
64
64
{
65
- SString strResponse;
65
+ if (!szArguments || !szArguments[0 ])
66
+ {
67
+ pEchoClient->SendConsole (" * Syntax: start <resource1> <resource2> ..." );
68
+ return false ;
69
+ }
66
70
67
- if (szArguments && szArguments[0 ])
71
+ if (pClient->GetNick ())
72
+ CLogger::LogPrintf (" start: Requested by %s\n " , GetAdminNameForLog (pClient).c_str ());
73
+
74
+ CSplitString resourceNames (szArguments, " " );
75
+ CResourceManager* resourceManager = g_pGame->GetResourceManager ();
76
+
77
+ for (const std::string& resourceName : resourceNames)
68
78
{
69
- CResource* resource = g_pGame->GetResourceManager ()->GetResource (szArguments);
70
- if (resource)
79
+ CResource* resource = resourceManager->GetResource (resourceName.c_str ());
80
+
81
+ if (!resource)
71
82
{
72
- if (pClient->GetNick ())
73
- CLogger::LogPrintf (" start: Requested by %s\n " , GetAdminNameForLog (pClient).c_str ());
83
+ pEchoClient->SendConsole (SString (" start: Resource '%s' could not be found" , resourceName.c_str ()));
84
+ continue ;
85
+ }
74
86
75
- if (resource->IsLoaded ())
76
- {
77
- if (!resource->IsActive ())
78
- {
79
- if (g_pGame->GetResourceManager ()->StartResource (resource, NULL , true ))
80
- {
81
- strResponse = SString (" start: Resource '%s' started" , szArguments);
82
- }
83
- else
84
- {
85
- strResponse = SString (" start: Resource '%s' start was requested (%s)" , szArguments, resource->GetFailureReason ().c_str ());
86
- }
87
- }
88
- else
89
- strResponse = " start: Resource is already running" ;
90
- }
91
- else
92
- strResponse = SString (" start: Resource is loaded, but has errors (%s)" , resource->GetFailureReason ().c_str ());
87
+ if (!resource->IsLoaded ())
88
+ {
89
+ pEchoClient->SendConsole (SString (" start: Resource '%s' is loaded, but has errors (%s)" , resourceName.c_str (), resource->GetFailureReason ().c_str ()));
90
+ continue ;
91
+ }
92
+
93
+ if (resource->IsActive ())
94
+ {
95
+ pEchoClient->SendConsole (SString (" start: Resource '%s' is already running" , resourceName.c_str ()));
96
+ continue ;
97
+ }
98
+
99
+ if (resourceManager->StartResource (resource, nullptr , true ))
100
+ {
101
+ pEchoClient->SendConsole (SString (" start: Resource '%s' started" , resourceName.c_str ()));
93
102
}
94
103
else
95
- strResponse = " start: Resource could not be found" ;
104
+ {
105
+ pEchoClient->SendConsole (SString (" start: Resource '%s' start was requested (%s)" , resourceName.c_str (), resource->GetFailureReason ().c_str ()));
106
+ }
96
107
}
97
- else
98
- strResponse = " * Syntax: start <resource-name>" ;
99
108
100
- pEchoClient->SendConsole (strResponse);
101
109
return true ;
102
110
}
103
111
104
112
bool CConsoleCommands::RestartResource (CConsole* pConsole, const char * szArguments, CClient* pClient, CClient* pEchoClient)
105
113
{
106
- if (szArguments && szArguments[0 ])
114
+ if (! szArguments || ! szArguments[0 ])
107
115
{
108
- CResource* resource = g_pGame->GetResourceManager ()->GetResource (szArguments);
109
- if (resource)
116
+ pEchoClient->SendConsole (" * Syntax: restart <resource1> <resource2> ..." );
117
+ return false ;
118
+ }
119
+
120
+ if (pClient->GetNick ())
121
+ CLogger::LogPrintf (" restart: Requested by %s\n " , GetAdminNameForLog (pClient).c_str ());
122
+
123
+ CSplitString resourceNames (szArguments, " " );
124
+ CResourceManager* resourceManager = g_pGame->GetResourceManager ();
125
+
126
+ for (const std::string& resourceName : resourceNames)
127
+ {
128
+ CResource* resource = resourceManager->GetResource (resourceName.c_str ());
129
+
130
+ if (!resource)
110
131
{
111
- if (pClient->GetNick ())
112
- CLogger::LogPrintf (" restart: Requested by %s\n " , GetAdminNameForLog (pClient).c_str ());
132
+ pEchoClient->SendConsole (SString (" restart: Resource '%s' could not be found" , resourceName.c_str ()));
133
+ continue ;
134
+ }
113
135
114
- if (resource->IsLoaded ())
115
- {
116
- if (resource->IsActive ())
117
- {
118
- if (resource->IsProtected ())
119
- {
120
- if (!g_pGame->GetACLManager ()->CanObjectUseRight (pClient->GetNick (), CAccessControlListGroupObject::OBJECT_TYPE_USER,
121
- " restart.protected" , CAccessControlListRight::RIGHT_TYPE_COMMAND, false ))
122
- {
123
- pEchoClient->SendConsole (" restart: Resource could not be restarted as it is protected" );
124
- return false ;
125
- }
126
- }
136
+ if (!resource->IsLoaded ())
137
+ {
138
+ pEchoClient->SendConsole (SString (" restart: Resource '%s' is loaded, but has errors (%s)" , resourceName.c_str (), resource->GetFailureReason ().c_str ()));
139
+ continue ;
140
+ }
127
141
128
- g_pGame->GetResourceManager ()->QueueResource (resource, CResourceManager::QUEUE_RESTART, NULL );
129
- pEchoClient->SendConsole (" restart: Resource restarting..." );
130
- }
131
- else
132
- pEchoClient->SendConsole (" restart: Resource is not running" );
142
+ if (!resource->IsActive ())
143
+ {
144
+ pEchoClient->SendConsole (SString (" restart: Resource '%s' is not running" , resourceName.c_str ()));
145
+ continue ;
146
+ }
147
+
148
+ if (resource->IsProtected ())
149
+ {
150
+ if (!g_pGame->GetACLManager ()->CanObjectUseRight (pClient->GetNick (), CAccessControlListGroupObject::OBJECT_TYPE_USER, " restart.protected" ,
151
+ CAccessControlListRight::RIGHT_TYPE_COMMAND, false ))
152
+ {
153
+ pEchoClient->SendConsole (SString (" restart: Resource '%s' could not be restarted as it is protected" , resourceName.c_str ()));
154
+ continue ;
133
155
}
134
- else
135
- pEchoClient->SendConsole (SString (" restart: Resource is loaded, but has errors (%s)" , resource->GetFailureReason ().c_str ()));
136
156
}
137
- else
138
- pEchoClient-> SendConsole ( " restart: Resource could not be found " );
139
- return true ;
157
+
158
+ resourceManager-> QueueResource (resource, CResourceManager::QUEUE_RESTART, nullptr );
159
+ pEchoClient-> SendConsole ( SString ( " restart: Resource '%s' restarting... " , resourceName. c_str ())) ;
140
160
}
141
- else
142
- pEchoClient->SendConsole (" * Syntax: restart <resource-name>" );
143
- return false ;
161
+
162
+ return true ;
144
163
}
145
164
146
165
bool CConsoleCommands::RefreshResources (CConsole* pConsole, const char * szArguments, CClient* pClient, CClient* pEchoClient)
@@ -195,45 +214,55 @@ bool CConsoleCommands::ResourceInfo(CConsole* pConsole, const char* szArguments,
195
214
196
215
bool CConsoleCommands::StopResource (CConsole* pConsole, const char * szArguments, CClient* pClient, CClient* pEchoClient)
197
216
{
198
- if (szArguments && szArguments[0 ])
217
+ if (! szArguments || ! szArguments[0 ])
199
218
{
200
- CResource* resource = g_pGame->GetResourceManager ()->GetResource (szArguments);
201
- if (resource)
219
+ pEchoClient->SendConsole (" * Syntax: stop <resource1> <resource2> ..." );
220
+ return false ;
221
+ }
222
+
223
+ if (pClient->GetNick ())
224
+ CLogger::LogPrintf (" stop: Requested by %s\n " , GetAdminNameForLog (pClient).c_str ());
225
+
226
+ CSplitString resourceNames (szArguments, " " );
227
+ CResourceManager* resourceManager = g_pGame->GetResourceManager ();
228
+
229
+ for (const std::string& resourceName : resourceNames)
230
+ {
231
+ CResource* resource = resourceManager->GetResource (resourceName.c_str ());
232
+
233
+ if (!resource)
202
234
{
203
- if (pClient->GetNick ())
204
- CLogger::LogPrintf (" stop: Requested by %s\n " , GetAdminNameForLog (pClient).c_str ());
235
+ pEchoClient->SendConsole (SString (" stop: Resource '%s' could not be found" , resourceName.c_str ()));
236
+ continue ;
237
+ }
205
238
206
- if (resource->IsLoaded ())
207
- {
208
- if (resource->IsActive ())
209
- {
210
- if (resource->IsProtected ())
211
- {
212
- if (!g_pGame->GetACLManager ()->CanObjectUseRight (pClient->GetNick (), CAccessControlListGroupObject::OBJECT_TYPE_USER, " stop.protected" ,
213
- CAccessControlListRight::RIGHT_TYPE_COMMAND, false ))
214
- {
215
- pEchoClient->SendConsole (" stop: Resource could not be stopped as it is protected" );
216
- return false ;
217
- }
218
- }
239
+ if (!resource->IsLoaded ())
240
+ {
241
+ pEchoClient->SendConsole (SString (" stop: Resource '%s' is loaded, but has errors (%s)" , resourceName.c_str (), resource->GetFailureReason ().c_str ()));
242
+ continue ;
243
+ }
219
244
220
- g_pGame->GetResourceManager ()->QueueResource (resource, CResourceManager::QUEUE_STOP, NULL );
221
- pEchoClient->SendConsole (" stop: Resource stopping" );
222
- }
223
- else
224
- pEchoClient->SendConsole (" stop: Resource is not running" );
245
+ if (!resource->IsActive ())
246
+ {
247
+ pEchoClient->SendConsole (SString (" stop: Resource '%s' is not running" , resourceName.c_str ()));
248
+ continue ;
249
+ }
250
+
251
+ if (resource->IsProtected ())
252
+ {
253
+ if (!g_pGame->GetACLManager ()->CanObjectUseRight (pClient->GetNick (), CAccessControlListGroupObject::OBJECT_TYPE_USER, " stop.protected" ,
254
+ CAccessControlListRight::RIGHT_TYPE_COMMAND, false ))
255
+ {
256
+ pEchoClient->SendConsole (SString (" stop: Resource '%s' could not be stopped as it is protected" , resourceName.c_str ()));
257
+ continue ;
225
258
}
226
- else
227
- pEchoClient->SendConsole (SString (" stop: Resource is loaded, but has errors (%s)" , resource->GetFailureReason ().c_str ()));
228
259
}
229
- else
230
- pEchoClient-> SendConsole ( " stop: Resource could not be found " );
231
- return true ;
260
+
261
+ resourceManager-> QueueResource (resource, CResourceManager::QUEUE_STOP, nullptr );
262
+ pEchoClient-> SendConsole ( SString ( " stop: Resource '%s' stopping... " , resourceName. c_str ())) ;
232
263
}
233
- else
234
- pEchoClient->SendConsole (" * Syntax: stop <resource-name>" );
235
264
236
- return false ;
265
+ return true ;
237
266
}
238
267
239
268
bool CConsoleCommands::StopAllResources (CConsole* pConsole, const char * szArguments, CClient* pClient, CClient* pEchoClient)
0 commit comments