MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 1 | // 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 User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 10 | |
| 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 | |
| 19 | inherit "/std/util/cidr"; |
| 20 | |
| 21 | mixed _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 | |
| 36 | static 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"); |
| 48 | if (ret=(string)INETD->_send_udp(mud,([SENDER:getuid(), REQUEST:QUERY, DATA:type]),1)) |
| 49 | write(ret); |
| 50 | else |
| 51 | write("Anfrage abgeschickt.\n"); |
| 52 | return 1; |
| 53 | } |
| 54 | |
| 55 | static 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 | |
| 66 | static 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 | |
| 79 | static 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; |
| 92 | if (!"/secure/master"->add_domain_master(master,domain)) |
| 93 | write("Hat nicht funktioniert.\n"); |
| 94 | else |
| 95 | write("Ok.\n"); |
| 96 | return 1; |
| 97 | } |
| 98 | |
| 99 | static 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; |
| 112 | if (!"/secure/master"->remove_domain_master(master,domain)) |
| 113 | write("Hat nicht funktioniert.\n"); |
| 114 | else |
| 115 | write("Ok.\n"); |
| 116 | return 1; |
| 117 | } |
| 118 | |
| 119 | static 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; |
| 133 | if (!"/secure/master"->add_guild_master(master,guild)) |
| 134 | write("Hat nicht funktioniert.\n"); |
| 135 | else |
| 136 | write ("Ok.\n"); |
| 137 | return 1; |
| 138 | } |
| 139 | |
| 140 | static 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; |
| 153 | if (!"/secure/master"->remove_guild_master(master,guild)) |
| 154 | write("Hat nicht funktioniert.\n"); |
| 155 | else |
| 156 | write("Ok.\n"); |
| 157 | return 1; |
| 158 | } |
| 159 | |
| 160 | static 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 | { |
| 182 | write(call_other("/secure/sinmaster","ListSinners")); |
| 183 | return 1; |
| 184 | } |
| 185 | if ( arg=="!" ) |
| 186 | { |
| 187 | write(call_other("/secure/sinmaster","Dump")); |
| 188 | return 1; |
| 189 | } |
| 190 | if ( arg=="*" ) |
| 191 | { |
| 192 | More((string)call_other("/secure/sinmaster","Dump",1)); |
| 193 | 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; |
| 203 | write(call_other("/secure/sinmaster","RemoveSin", |
| 204 | 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; |
| 211 | write(call_other("/secure/sinmaster","AddSin", |
| 212 | lowerstring(parts[0][1..]), |
| 213 | implode(parts[1..]," "))); |
| 214 | } |
| 215 | else |
| 216 | { |
| 217 | if ( i>1 ) |
| 218 | return 0; |
| 219 | write(call_other("/secure/sinmaster","ListSins", |
| 220 | lowerstring(parts[0]))); |
| 221 | } |
| 222 | return 1; |
| 223 | } |
| 224 | |
| 225 | static 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); |
| 254 | "/secure/master"->BanishName( name, grund, force ); |
| 255 | return 1; |
| 256 | } |
| 257 | |
| 258 | static 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) ){ |
| 270 | if ( !mappingp(list = (mapping)"/secure/merlin"->MBanishList()) || |
| 271 | !(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" ){ |
| 308 | "/secure/merlin"->MBanishInsert( name, grund, this_interactive() ); |
| 309 | 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 | } |
| 316 | "/secure/merlin"->MBanishDelete( name ); |
| 317 | write( "Du loescht "+capitalize(name)+" von der MBanish-Liste.\n" ); |
| 318 | } |
| 319 | |
| 320 | return 1; |
| 321 | } |
| 322 | |
| 323 | |
| 324 | static 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 | |
| 345 | if ( !"/secure/master"->TBanishName( name, days ) ) |
| 346 | 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 | |
| 356 | static int sbanish( string str ) |
| 357 | { |
| 358 | string ip; |
| 359 | int days; |
| 360 | mapping sites; |
| 361 | |
| 362 | // Mindestens L26 fuer diesen Befehl |
| 363 | if ( secure_level() <= DOMAINMEMBER_LVL ) |
| 364 | return 0; |
| 365 | |
| 366 | if ( !str || !stringp(str) || !sizeof(str) ){ |
| 367 | if ( !sizeof(sites = (mapping)MASTER->SiteBanish( 0, 0 )) ){ |
| 368 | write( "Es sind zur Zeit keine Adressen gesperrt!\n" ); |
| 369 | return 1; |
| 370 | } |
| 371 | |
| 372 | ip = " Adresse | gesperrt bis | gesperrt " |
| 373 | + "durch\n========================================================" |
| 374 | + "==============\n"; |
| 375 | |
| 376 | int *keys = sort_array( m_indices(sites), #'</*'*/ ); |
| 377 | |
| 378 | foreach(int key : keys) { |
| 379 | ip += sprintf( " %:15-s | %:27-s | %-s\n", |
| 380 | IPv4_int2addr(key), |
| 381 | sites[key] > 0 ? dtime(sites[key]) : |
| 382 | "St. Nimmerleinstag", |
| 383 | capitalize(sites[key, 1]) ); |
| 384 | } |
| 385 | write( ip + "\n" ); |
| 386 | return 1; |
| 387 | } |
| 388 | |
| 389 | _notify_fail("Syntax: sbanish <numerische ip> <tage>\n"); |
| 390 | |
| 391 | if ( sscanf( this_player()->_unparsed_args(), "%s %d", ip, days ) != 2 ) |
| 392 | return 0; |
| 393 | |
| 394 | if ( !ip || !sizeof(ip) ) |
| 395 | return 0; |
| 396 | |
| 397 | // _notify_fail( "Ungueltiges Adress-Format!\n" ); |
| 398 | |
| 399 | if ( !days ){ |
| 400 | int res=(int)MASTER->SiteBanish(ip, 0); |
| 401 | if ( res == 1 ) |
| 402 | printf( "Die Adresse '%s' ist jetzt nicht mehr gesperrt.\n", |
| 403 | ip ); |
| 404 | else if ( res == 0 ) |
| 405 | printf( "Die Adresse '%s' war gar nicht gesperrt!\n", |
| 406 | ip ); |
| 407 | else |
| 408 | printf( "Du darfst nur eigene Sperrungen wieder aufheben!\n" ); |
| 409 | } |
| 410 | else { |
| 411 | int res; |
| 412 | if ( days != 1 && !IS_DEPUTY(secure_euid()) ) |
| 413 | write( "Du darfst Adressen nur fuer einen Tag sperren!\n" ); |
| 414 | else if ( (res = (int)MASTER->SiteBanish(ip, days)) == 1 ) |
| 415 | printf( "Die Adresse '%s' ist jetzt fuer %s gesperrt.\n", |
| 416 | ip, (days > 1 ? sprintf( "%d Tage", days ) : |
| 417 | (days > 0 ? "einen Tag" : "immer")) ); |
| 418 | else if ( res == -1 ) |
| 419 | write( "Du darfst " + (LORD_SECURITY ? "255 IP-Adressen" |
| 420 | : "nur einzelne IP-Adressen") + " sperren!\n" ); |
| 421 | else if ( res == -2 ) |
| 422 | write( "Du hast schon genug Adressen gesperrt!\n" ); |
| 423 | } |
| 424 | |
| 425 | return 1; |
| 426 | } |
| 427 | |