blob: 0dcac9f61fd51cd4d2a0e0514dd4d323d91d7d6a [file] [log] [blame]
MG Mud User88f12472016-06-24 23:31:02 +02001// MorgenGrauen MUDlib
2//
3// admin.c
4//
5// $Id: admin.c 8755 2014-04-26 13:13:40Z Zesstra $
6#pragma strict_types
7#pragma save_types
8#pragma range_check
9#pragma no_clone
MG Mud User88f12472016-06-24 23:31:02 +020010
11#include <udp.h>
12#include <wizlevels.h>
13#include <input_to.h>
14
15#define NEED_PROTOTYPES
16#include <magier.h>
17#include <player.h>
18
19inherit "/std/util/cidr";
20
21mixed _query_localcmds()
22{
23 return ({({"udpq","_udpq",0,LEARNER_LVL}),
24 ({"shutdown","shut_down_game",0,ARCH_LVL}),
25 ({"addmaster","_addmaster",0,GOD_LVL}),
26 ({"removemaster","_removemaster",0,GOD_LVL}),
27 ({"addguildmaster", "_addguildmaster", 0, GOD_LVL}),
28 ({"removeguildmaster", "_removeguildmaster", 0, GOD_LVL}),
29 ({"suender","sinners",0,WIZARD_LVL}),
30 ({"banish","banish", 0, WIZARD_LVL}),
31 ({"mbanish","mbanish", 0, WIZARD_LVL}),
32 ({"tbanish","tbanish", 0, WIZARD_LVL}),
33 ({"sbanish","sbanish", 0, WIZARD_LVL})});
34}
35
36static int _udpq(string str)
37{
38 string ret, mud, type;
39
40 if (!(str=_unparsed_args()) || str=="" || sscanf(str,"%s %s",mud,type)<2)
41 {
42 write("Syntax: udpq mud type\n");
43 return 1;
44 }
45 if (member(({"commands","email","hosts","inetd","list","mud_port","time",
46 "version"}),type)==-1)
47 write("TYPEs: commands, email, hosts, inetd, list, mud_port, time, version\n");
Vanion50652322020-03-10 21:13:25 +010048 if (ret=({string})INETD->_send_udp(mud,([SENDER:getuid(), REQUEST:QUERY, DATA:type]),1))
MG Mud User88f12472016-06-24 23:31:02 +020049 write(ret);
50 else
51 write("Anfrage abgeschickt.\n");
52 return 1;
53}
54
55static int shut_down_game(string str)
56{
57 if (!IS_ARCH(this_object()) || this_object()!=this_interactive())
58 return 0;
59 _notify_fail("Du musst einen Grund dafuer angeben.\n");
60 if (!str) return 0;
61 write( "Direkter shutdown mit Grund \""+str+"\"?\n" );
62 input_to("shut_down_game_2",INPUT_PROMPT, "(ja/nein) :", str);
63 return 1;
64}
65
66static int shut_down_game_2(string arg,string str)
67{
68 if (!IS_ARCH(this_object()) || this_object()!=this_interactive())
69 return 0;
70 if( arg!="ja" ) {
71 write( "Shutdown abgebrochen.\n" );
72 } else {
73 shutdown(str);
74 }
75 return 1;
76}
77
78
79static int _addmaster(string str)
80{
81 string master, domain;
82
83 if (!GOD_SECURITY)
84 {
85 write("Das darfst Du nicht!\n");
86 return 1;
87 }
88 _notify_fail("Syntax: addmaster <user> <domain>\n");
89 if (!str) return 0;
90 if (sscanf(str,"%s %s",master,domain)!=2) return 0;
91 if (!master || !domain) return 0;
bugfixd94d0932020-04-08 11:27:13 +020092 if (!({int})"/secure/master"->add_domain_master(master,domain))
MG Mud User88f12472016-06-24 23:31:02 +020093 write("Hat nicht funktioniert.\n");
94 else
95 write("Ok.\n");
96 return 1;
97}
98
99static int _removemaster(string str)
100{
101 string master, domain;
102
103 if (!GOD_SECURITY)
104 {
105 write("Das darfst Du nicht!\n");
106 return 1;
107 }
108 _notify_fail("Syntax: removemaster <user> <domain>\n");
109 if (!str) return 0;
110 if (sscanf(str,"%s %s",master,domain)!=2) return 0;
111 if (!master || !domain) return 0;
bugfixd94d0932020-04-08 11:27:13 +0200112 if (!({int})"/secure/master"->remove_domain_master(master,domain))
MG Mud User88f12472016-06-24 23:31:02 +0200113 write("Hat nicht funktioniert.\n");
114 else
115 write("Ok.\n");
116 return 1;
117}
118
119static int _addguildmaster(string str)
120{
121 string master, guild;
122
123 if (!GOD_SECURITY)
124 {
125 write ("Das darfst Du nicht!\n");
126 return 1;
127 }
128
129 _notify_fail("Synatx: addguildmaster <user> <guild>\n");
130 if (!str) return 0;
131 if (sscanf(str, "%s %s", master, guild)!=2) return 0;
132 if (!master || !guild) return 0;
bugfixd94d0932020-04-08 11:27:13 +0200133 if (!({int})"/secure/master"->add_guild_master(master,guild))
MG Mud User88f12472016-06-24 23:31:02 +0200134 write("Hat nicht funktioniert.\n");
135 else
136 write ("Ok.\n");
137 return 1;
138}
139
140static int _removeguildmaster(string str)
141{
142 string master, guild;
143
144 if (!GOD_SECURITY)
145 {
146 write ("Das darfst Du nicht!\n");
147 return 1;
148 }
149 _notify_fail("Syntax: removeguildmaster <user> <guild>\n");
150 if (!str) return 0;
151 if (sscanf(str, "%s %s", master, guild)!=2) return 0;
152 if (!master || !guild) return 0;
bugfixd94d0932020-04-08 11:27:13 +0200153 if (!({int})"/secure/master"->remove_guild_master(master,guild))
MG Mud User88f12472016-06-24 23:31:02 +0200154 write("Hat nicht funktioniert.\n");
155 else
156 write("Ok.\n");
157 return 1;
158}
159
160static int sinners(string arg)
161{ string *parts;
162 int i;
163
164 if ( !IS_DEPUTY(this_object()) )
165 return 0;
166
167 arg=_unparsed_args()||arg;
168
169 notify_fail(
170 "Syntax: suender ? => Liste aller Eingetragenen\n"+
171 " suender <name> => Eintraege lesen\n"+
172 " suender +<name> <text> => Eintrag hinzufuegen\n"+
173 " suender -<name> <nr> => Eintrag loeschen\n"+
174 " suender ! => Alle Eintraege dumpen\n"+
175 " suender * => Alle Eintraege anzeigen\n");
176
177 if ( !stringp(arg) || (sizeof(arg)<1) )
178 return 0;
179
180 if ( arg=="?" )
181 {
bugfixd94d0932020-04-08 11:27:13 +0200182 write(({string})call_other("/secure/sinmaster","ListSinners"));
MG Mud User88f12472016-06-24 23:31:02 +0200183 return 1;
184 }
185 if ( arg=="!" )
186 {
bugfixd94d0932020-04-08 11:27:13 +0200187 write(({string})call_other("/secure/sinmaster","Dump"));
MG Mud User88f12472016-06-24 23:31:02 +0200188 return 1;
189 }
190 if ( arg=="*" )
191 {
Vanion50652322020-03-10 21:13:25 +0100192 More(({string})call_other("/secure/sinmaster","Dump",1));
MG Mud User88f12472016-06-24 23:31:02 +0200193 return 1;
194 }
195
196 if ( (i=sizeof(parts=explode(arg," ")))<1 )
197 return 0;
198
199 if ( parts[0][0..0]=="-" )
200 {
201 if ( i<2 )
202 return 0;
bugfixd94d0932020-04-08 11:27:13 +0200203 write(({string})call_other("/secure/sinmaster","RemoveSin",
MG Mud User88f12472016-06-24 23:31:02 +0200204 lowerstring(parts[0][1..]),
205 to_int(parts[1])));
206 }
207 else if ( parts[0][0..0]=="+" )
208 {
209 if ( i<2 )
210 return 0;
bugfixd94d0932020-04-08 11:27:13 +0200211 write(({string})call_other("/secure/sinmaster","AddSin",
MG Mud User88f12472016-06-24 23:31:02 +0200212 lowerstring(parts[0][1..]),
213 implode(parts[1..]," ")));
214 }
215 else
216 {
217 if ( i>1 )
218 return 0;
bugfixd94d0932020-04-08 11:27:13 +0200219 write(({string})call_other("/secure/sinmaster","ListSins",
MG Mud User88f12472016-06-24 23:31:02 +0200220 lowerstring(parts[0])));
221 }
222 return 1;
223}
224
225static int banish(string str)
226{
227 string grund, name;
228 int force;
229
230 if ( !LORD_SECURITY && !IS_DEPUTY(secure_euid()) )
231 return 0;
232
233 if ( !str || !stringp(str) || !sizeof(str) ) {
234 write("Syntax: banish [-f] <name> [<grund>]\n");
235 return 1;
236 }
237
238 str = _unparsed_args();
239
240 if ( explode(str, " ")[0] == "-f" ){
241 str = implode( explode(str, " ")[1..], " " );
242 force = 1;
243 }
244
245 if ( sscanf( str, "%s %s", name, grund ) != 2 )
246 name=str;
247
248 if ( !name || !sizeof(name) ){
249 write("Syntax: banish [-f] <name> [<grund>]\n");
250 return 1;
251 }
252
253 name=lower_case(name);
bugfixd94d0932020-04-08 11:27:13 +0200254 ({int})"/secure/master"->BanishName( name, grund, force );
MG Mud User88f12472016-06-24 23:31:02 +0200255 return 1;
256}
257
258static int mbanish(string str)
259{
260 string grund, name, *namen, txt, *dummy;
261 mapping list;
262 int i;
263
264 if ( !IS_DEPUTY(secure_euid()) )
265 return 0;
266
267 _notify_fail( "Syntax: mbanish <name> [<grund>]\n" );
268
269 if ( !str || !stringp(str) || !sizeof(str) ){
Vanion50652322020-03-10 21:13:25 +0100270 if ( !mappingp(list = ({mapping})"/secure/merlin"->MBanishList()) ||
MG Mud User88f12472016-06-24 23:31:02 +0200271 !(i = sizeof(list)) ){
272 write( "Momentan ist kein Spieler auf der mbanish-Liste.\n" );
273 return 1;
274 }
275
276 txt = " Name | gebanisht von | Grund\n" +
277 "=============================================================" +
278 "==================\n";
279
280 namen = sort_array( m_indices(list), #'</*'*/ );
281
282 for ( ; i--; ){
283 dummy = explode( break_string( list[namen[i],0] ||
284 "-- keine Begruendung --", 45 ),
285 "\n" ) - ({""});
286
287 txt += sprintf( " %-11s | %-11s | %s\n",
288 capitalize( namen[i] ),
289 capitalize( list[namen[i],1] || "" ),
290 capitalize( implode( dummy, "\n |"
291 " | " ) ) );
292 }
293
294 More(txt);
295
296 return 1;
297 }
298
299 if ( sscanf( str, "%s %s", name, grund ) !=2 )
300 name = str;
301
302 if ( !name || !sizeof(name) )
303 return 0;
304
305 name = lower_case(name);
306
307 if ( !grund || !stringp(grund) || lower_case(grund) != "loeschen" ){
bugfixd94d0932020-04-08 11:27:13 +0200308 ({void})"/secure/merlin"->MBanishInsert( name, grund, this_interactive() );
MG Mud User88f12472016-06-24 23:31:02 +0200309 write( "Du setzt "+capitalize(name)+" auf die MBanish-Liste.\n" );
310 }
311 else{
312 if ( !ARCH_SECURITY ){
313 write( "Das duerfen nur Erzmagier.\n" );
314 return 1;
315 }
bugfixd94d0932020-04-08 11:27:13 +0200316 ({void})"/secure/merlin"->MBanishDelete( name );
MG Mud User88f12472016-06-24 23:31:02 +0200317 write( "Du loescht "+capitalize(name)+" von der MBanish-Liste.\n" );
318 }
319
320 return 1;
321}
322
323
324static int tbanish( string str )
325{
326 string name;
327 int days;
328
329 if ( !IS_DEPUTY(secure_euid()) )
330 return 0;
331
332 _notify_fail("Syntax: tbanish <name> <tage>\n");
333
334 if ( !str || !stringp(str) || !sizeof(str) )
335 return 0;
336
337 if ( sscanf(str,"%s %d",name,days) != 2 )
338 return 0;
339
340 if ( !name || !sizeof(name) )
341 return 0;
342
343 name = lower_case(name);
344
bugfixd94d0932020-04-08 11:27:13 +0200345 if ( !({int})"/secure/master"->TBanishName( name, days ) )
MG Mud User88f12472016-06-24 23:31:02 +0200346 return 1;
347
348 if ( !days )
349 write( "Okay, keine Spielpause fuer "+capitalize(name)+" mehr.\n" );
350 else
351 write( "Du verpasst "+capitalize(name)+" eine Spielpause fuer "+
352 (days>0 ? days+" Tage" : "laaaange Zeit")+".\n" );
353 return 1;
354}
355
356static int sbanish( string str )
357{
358 string ip;
359 int days;
MG Mud User88f12472016-06-24 23:31:02 +0200360
361 // Mindestens L26 fuer diesen Befehl
362 if ( secure_level() <= DOMAINMEMBER_LVL )
363 return 0;
364
Vanion50652322020-03-10 21:13:25 +0100365 if ( !str || !stringp(str) || !sizeof(str) )
366 {
367 mapping|int sites = ({mapping|int})MASTER->SiteBanish( 0, 0 );
368 if ( !mappingp(sites) )
369 {
370 write("Du darfst (noch) keine gesperrten Adressen abfragen!\n");
371 return 1;
372 }
373 if ( !sizeof(sites) )
374 {
MG Mud User88f12472016-06-24 23:31:02 +0200375 write( "Es sind zur Zeit keine Adressen gesperrt!\n" );
376 return 1;
377 }
378
379 ip = " Adresse | gesperrt bis | gesperrt "
380 + "durch\n========================================================"
381 + "==============\n";
382
383 int *keys = sort_array( m_indices(sites), #'</*'*/ );
384
385 foreach(int key : keys) {
386 ip += sprintf( " %:15-s | %:27-s | %-s\n",
387 IPv4_int2addr(key),
388 sites[key] > 0 ? dtime(sites[key]) :
389 "St. Nimmerleinstag",
390 capitalize(sites[key, 1]) );
391 }
392 write( ip + "\n" );
393 return 1;
394 }
395
396 _notify_fail("Syntax: sbanish <numerische ip> <tage>\n");
397
bugfixd94d0932020-04-08 11:27:13 +0200398 if ( sscanf( ({string})this_player()->_unparsed_args(), "%s %d", ip, days ) != 2 )
MG Mud User88f12472016-06-24 23:31:02 +0200399 return 0;
400
401 if ( !ip || !sizeof(ip) )
402 return 0;
403
404// _notify_fail( "Ungueltiges Adress-Format!\n" );
405
Vanion50652322020-03-10 21:13:25 +0100406 if ( !days )
407 {
408 // Eigentlich ist SiteBanish() int|mapping. Bei diesem Aufruf kommt
409 // jedoch nur int zurueck. Fall sichs das mal aendert, soll es buggen.
410 int res=({int})MASTER->SiteBanish(ip, 0);
MG Mud User88f12472016-06-24 23:31:02 +0200411 if ( res == 1 )
412 printf( "Die Adresse '%s' ist jetzt nicht mehr gesperrt.\n",
413 ip );
414 else if ( res == 0 )
415 printf( "Die Adresse '%s' war gar nicht gesperrt!\n",
416 ip );
417 else
418 printf( "Du darfst nur eigene Sperrungen wieder aufheben!\n" );
419 }
Vanion50652322020-03-10 21:13:25 +0100420 else
421 {
MG Mud User88f12472016-06-24 23:31:02 +0200422 if ( days != 1 && !IS_DEPUTY(secure_euid()) )
Vanion50652322020-03-10 21:13:25 +0100423 {
MG Mud User88f12472016-06-24 23:31:02 +0200424 write( "Du darfst Adressen nur fuer einen Tag sperren!\n" );
Vanion50652322020-03-10 21:13:25 +0100425 return 1;
426 }
427 // Eigentlich ist SiteBanish() int|mapping. Bei diesem Aufruf kommt
428 // jedoch nur int zurueck. Fall sichs das mal aendert, soll es buggen.
429 int res = ({int})MASTER->SiteBanish(ip, days);
430 if ( res == 1 )
MG Mud User88f12472016-06-24 23:31:02 +0200431 printf( "Die Adresse '%s' ist jetzt fuer %s gesperrt.\n",
432 ip, (days > 1 ? sprintf( "%d Tage", days ) :
433 (days > 0 ? "einen Tag" : "immer")) );
434 else if ( res == -1 )
435 write( "Du darfst " + (LORD_SECURITY ? "255 IP-Adressen"
Vanion50652322020-03-10 21:13:25 +0100436 : "nur einzelne IP-Adressen") + " sperren!\n" );
MG Mud User88f12472016-06-24 23:31:02 +0200437 else if ( res == -2 )
438 write( "Du hast schon genug Adressen gesperrt!\n" );
439 }
440
441 return 1;
442}
443