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