blob: 04a312b77266a86529e2a9e58fb4899cf36ffc8c [file] [log] [blame]
MG Mud User88f12472016-06-24 23:31:02 +02001// MorgenGrauen MUDlib
2//
3// simul_efun.c -- simul efun's
4//
5// $Id: simul_efun.c 7408 2010-02-06 00:27:25Z Zesstra $
6#pragma strict_types,save_types,rtt_checks
7#pragma no_clone,no_shadow,no_inherit
8#pragma pedantic,range_check,warn_deprecated
9#pragma warn_empty_casts,warn_missing_return,warn_function_inconsistent
10
11// Absolute Pfade erforderlich - zum Zeitpunkt, wo der Master geladen
12// wird, sind noch keine Include-Pfade da ...
13
14#define SNOOPLOGFILE "SNOOP"
15#define ASNOOPLOGFILE "ARCH/SNOOP"
16
17#include "/secure/config.h"
18#include "/secure/wizlevels.h"
19#include "/sys/snooping.h"
20#include "/sys/language.h"
21#include "/sys/thing/properties.h"
22#include "/sys/wizlist.h"
23#include "/sys/erq.h"
24#include "/sys/lpctypes.h"
25#include "/sys/daemon.h"
26#include "/sys/player/base.h"
27#include "/sys/thing/description.h"
28#include "/sys/container.h"
29#include "/sys/defines.h"
30#include "/sys/telnet.h"
31#include "/sys/objectinfo.h"
32#include "/sys/files.h"
33#include "/sys/strings.h"
34#include "/sys/time.h"
35#include "/sys/lpctypes.h"
36#include "/sys/notify_fail.h"
37#include "/sys/tls.h"
38#include "/sys/input_to.h"
39#include "/sys/object_info.h"
40
41/* function prototypes
42 */
43string dtime(int wann);
44varargs int log_file(string file, string txt, int size_to_break);
45int query_wiz_level(mixed player);
46nomask varargs int snoop(object me, object you);
47varargs string country(mixed ip, string num);
48int query_wiz_grp(mixed wiz);
49public varargs object deep_present(mixed what, object ob);
50nomask int secure_level();
51nomask string secure_euid();
52public nomask int process_call();
53nomask mixed __create_player_dummy(string name);
54varargs string replace_personal(string str, mixed *obs, int caps);
55
56
57//replacements for dropped efuns in LD
58#if !__EFUN_DEFINED__(extract)
59varargs string extract(string str, int from, int to);
60#endif
61#if !__EFUN_DEFINED__(slice_array)
62varargs mixed slice_array(mixed array, int from, int to);
63#endif
64#if !__EFUN_DEFINED__(member_array)
65int member_array(mixed item, mixed arraystring);
66#endif
67
68// Include the different sub 'modules' of the simul_efun
69#include __DIR__"debug_info.c"
70#include __DIR__"enable_commands.c"
71#include __DIR__"hash.c"
72#include __DIR__"object_info.c"
73#include __DIR__"query_editing.c"
74#include __DIR__"query_idle.c"
75#include __DIR__"query_input_pending.c"
76#include __DIR__"query_ip_name.c"
77#include __DIR__"query_limits.c"
78#include __DIR__"query_load_average.c"
79#include __DIR__"query_mud_port.c"
80#include __DIR__"query_once_interactive.c"
81#include __DIR__"query_snoop.c"
82#include __DIR__"set_heart_beat.c"
83#if __BOOT_TIME__ < 1456261859
84#include __DIR__"set_prompt.c"
85#endif
86#include __DIR__"shadow.c"
87#include __DIR__"livings.c"
88#include __DIR__"comm.c"
Zesstra984bde92017-01-29 22:19:52 +010089#include __DIR__"files.c"
MG Mud User88f12472016-06-24 23:31:02 +020090
91#define TO efun::this_object()
92#define TI efun::this_interactive()
93#define TP efun::this_player()
94#define PO efun::previous_object(0)
95#define LEVEL(x) query_wiz_level(x)
96#define NAME(x) capitalize(getuid(x))
97
98#define DEBUG(x) if (find_player("zesstra")) \
99 tell_object(find_player("zesstra"),x)
100
101mixed dtime_cache = ({-1,""});
102
103#ifdef IOSTATS
104struct iostat_s {
105 string oname;
106 int time;
107 int size;
108};
109mixed saveo_stat = ({ 0,allocate(200, 0) });
110mixed restoreo_stat = ({ 0,allocate(200,0) });
111//mixed writefile_stat = ({ 0,allocate(100,(<iostat_s>)) });
112//mixed readfile_stat = ({ 0,allocate(100,(<iostat_s>)) });
113//mixed log_stat = ({ 0,allocate(100,(<iostat_s>)) });
114
115mixed ___iostats(int type) {
116 switch(type) {
117 case 1:
118 return saveo_stat;
119 case 2:
120 return restoreo_stat;
121/* case 3:
122 return writefile_stat;
123 case 4:
124 return readfile_stat;
125 case 5:
126 return log_stat;
127 */
128 }
129 return 0;
130}
131#endif
132
133// Nicht jeder Magier muss die simul_efun entsorgen koennen.
134string NotifyDestruct(object caller) {
135 if( (caller!=this_object() && !ARCH_SECURITY) || process_call() ) {
136 return "Du darfst das simul_efun Objekt nicht zerstoeren!\n";
137 }
138 return 0;
139}
140
141public nomask void remove_interactive( object ob )
142{
143 if ( objectp(ob) && previous_object()
144 && object_name(previous_object())[0..7] != "/secure/"
145 && ((previous_object() != ob
146 && (ob != this_player() || ob != this_interactive()))
147 || (previous_object() == ob
148 && (this_player() && this_player() != ob
149 || this_interactive() && this_interactive() != ob)) ) )
150
151 log_file( "PLAYERDEST",
152 sprintf( "%s: %O ausgeloggt von PO %O, TI %O, TP %O\n",
153 dtime(time()), ob, previous_object(),
154 this_interactive(), this_player() ) );
155
156 efun::remove_interactive(ob);
157}
158
159
160void ___updmaster()
161{
162 object ob;
163
164 //sollte nicht jeder duerfen.
165 if (process_call() || !ARCH_SECURITY)
166 raise_error("Illegal use of ___updmaster()!");
167
168 write("Removing old master ... ");
169 foreach(string file:
170 get_dir("/secure/master/*.c",GETDIR_NAMES|GETDIR_UNSORTED|GETDIR_PATH)) {
171 if (ob = find_object(file))
172 efun::destruct(ob);
173 }
174 efun::destruct(efun::find_object("/secure/master"));
175 write("done.\nLoading again ... ");
176 load_object("/secure/master");
177
178 write("done.\n");
179}
180
181varargs string country(mixed ip, string num) {
182 mixed ret;
183
184 if(ret = (string)"/p/daemon/iplookup"->country(num || ip)) {
185 return ret;
186 } else return "???";
187}
188
189
190// * Snoopen und was dazugehoert
191static object find_snooped(object who)
192{
193 object *u;
194 int i;
195
196 for (i=sizeof(u=users())-1;i>=0;i--)
197 if (who==efun::interactive_info(u[i], II_SNOOP_NEXT))
198 return u[i];
199 return 0;
200}
201
202private string Lcut(string str) {
203 return str[5..11]+str[18..];
204}
205
206nomask varargs int snoop( object me, object you )
207{
208 int ret;
209 object snooper0, snooper, snooper2, snooper3;
210
211 if( !objectp(me) || me == you || !PO )
212 return 0;
213
214 snooper0 = find_snooped(me);
215
216 if(you){
217 if ( PO != me && query_wiz_grp(me) >= query_wiz_grp(geteuid(PO)) )
218 return 0;
219
220 if ( query_wiz_grp(me) <= query_wiz_grp(you) &&
221 !(you->QueryAllowSnoop(me)) )
222 if ( !IS_DEPUTY(me) || IS_ARCH(you) )
223 return 0;
224
225 if ( (snooper = efun::interactive_info(you, II_SNOOP_NEXT)) &&
226 query_wiz_grp(snooper) >= query_wiz_grp(me) ){
227 if ( (int)snooper->QueryProp(P_SNOOPFLAGS) & SF_LOCKED )
228 return 0;
229
230 tell_object( snooper, sprintf( "%s snooped jetzt %s.\n",
231 me->name(WER), you->name(WER) ) );
232
233 snooper2 = me;
234
235 while ( snooper3 = interactive_info(snooper2, II_SNOOP_NEXT) ){
236 tell_object( snooper,
237 sprintf( "%s wird seinerseits von %s gesnooped.\n"
238 ,snooper2->name(WER),
239 snooper3->name(WEM) ) );
240 snooper2 = snooper3;
241 }
242
243 efun::snoop( snooper, snooper2 );
244
245 if ( efun::interactive_info(snooper2, II_SNOOP_NEXT) != snooper )
246 tell_object( snooper, sprintf( "Du kannst %s nicht snoopen.\n",
247 snooper2->name(WEN) ) );
248 else{
249 tell_object( snooper, sprintf( "Du snoopst jetzt %s.\n",
250 snooper2->name(WEN) ) );
251 if ( !IS_DEPUTY(snooper) ){
252 log_file( SNOOPLOGFILE, sprintf("%s: %O %O %O\n",
253 dtime(time()),
254 snooper,
255 snooper2,
256 environment(snooper2) ),
257 100000 );
258 if (snooper0)
259 CHMASTER->send( "Snoop", snooper,
260 sprintf( "%s *OFF* %s (%O)",
261 capitalize(getuid(snooper)),
262 capitalize(getuid(snooper0)),
263 environment(snooper0) ) );
264
265 CHMASTER->send( "Snoop", snooper,
266 sprintf("%s -> %s (%O)",
267 capitalize(getuid(snooper)),
268 capitalize(getuid(snooper2)),
269 environment(snooper2)));
270 }
271 else{
272 log_file( ASNOOPLOGFILE, sprintf( "%s: %O %O %O\n",
273 dtime(time()),
274 snooper,
275 snooper2,
276 environment(snooper2) )
277 ,100000 );
278 }
279 }
280 }
281 else
282 if (snooper)
283 if ( !me->QueryProp(P_SNOOPFLAGS) & SF_LOCKED ){
284 printf( "%s wird bereits von %s gesnooped. Benutze das "
285 "\"f\"-Flag, wenn du dennoch snoopen willst.\n",
286 you->name(WER), snooper->name(WEM) );
287 return 0;
288 }
289
290 ret = efun::snoop( me, you );
291
292 if ( !IS_DEPUTY(me) && efun::interactive_info(you, II_SNOOP_NEXT) == me){
293 log_file( SNOOPLOGFILE, sprintf( "%s: %O %O %O\n",
294 Lcut(dtime(time())),
295 me, you, environment(you) ),
296 100000 );
297
298 if (snooper0)
299 CHMASTER->send( "Snoop", me,
300 sprintf( "%s *OFF* %s (%O).",
301 capitalize(getuid(me)),
302 capitalize(getuid(snooper0)),
303 environment(snooper0) ) );
304
305 CHMASTER->send( "Snoop", me, sprintf( "%s -> %s (%O).",
306 capitalize(getuid(me)),
307 capitalize(getuid(you)),
308 environment(you) ) );
309 }
310 else{
311 if ( efun::interactive_info(you, II_SNOOP_NEXT) == me ){
312 log_file( ASNOOPLOGFILE, sprintf( "%s: %O %O %O\n",
313 Lcut(dtime(time())),
314 me, you, environment(you) ),
315 100000 );
316 }
317 }
318
319 if ( ret && query_wiz_grp(me) <= query_wiz_grp(you) &&
320 !IS_DEPUTY(me) )
321 tell_object( you, "*** " + NAME(me) + " snoopt Dich!\n" );
322
323 return ret;
324 }
325 else {
326 if ( (me == PO ||
327 query_wiz_grp(geteuid(PO)) > query_wiz_grp(me) ||
328 (query_wiz_grp(geteuid(PO)) == query_wiz_grp(me) &&
329 efun::interactive_info(PO, II_SNOOP_NEXT) == me)) && snooper0 ){
330 if ( !IS_DEPUTY(me) ){
331 log_file( SNOOPLOGFILE, sprintf( "%s: %O %O %O *OFF*\n",
332 Lcut(dtime(time())), me,
333 snooper0,
334 environment(snooper0) ),
335 100000 );
336
337 CHMASTER->send( "Snoop", me,
338 sprintf( "%s *OFF* %s (%O).",
339 capitalize(getuid(me)),
340 capitalize(getuid(snooper0)),
341 environment(snooper0) ) );
342 }
343 else{
344 log_file( ASNOOPLOGFILE, sprintf( "%s: %O %O %O *OFF*\n",
345 Lcut(dtime(time())), me,
346 snooper0,
347 environment(snooper0) ),
348 100000 );
349 }
350
351 return efun::snoop(me);
352 }
353 }
354 return 0;
355}
356
357
358
359// * Emulation des 'alten' explode durch das neue
360string *old_explode(string str, string del) {
361 int s, t;
362 string *strs;
363
364 if (!stringp(str)) {
365 set_this_object(previous_object());
366 raise_error(sprintf(
367 "Invalid argument 1 to old_explode()! Expected <string>, got: "
368 "%.30O\n",str));
369 }
370 if (!stringp(del)) {
371 set_this_object(previous_object());
372 raise_error(sprintf(
373 "Invalid argument 2 to old_explode()! Expected <string>, got: "
374 "%.30O\n",del));
375 }
376 if(del == "")
377 return ({str});
378 strs=efun::explode(str, del);
379 t=sizeof(strs)-1;
380 while(s<=t && strs[s++] == "");s--;
381 while(t>=0 && strs[t--] == "");t++;
382 if(s<=t)
383 return strs[s..t];
384 return ({});
385}
386
387int file_time(string path) {
388 mixed *v;
389
390 set_this_object(previous_object());
391 if (sizeof(v=get_dir(path,GETDIR_DATES))) return v[0];
392 return(0); //sonst
393}
394
MG Mud User88f12472016-06-24 23:31:02 +0200395// * Magier-Level abfragen
396int query_wiz_level(mixed player) {
397 return (int)"/secure/master"->query_wiz_level(player);
398}
399
400#ifdef __ALISTS__
401// * Element aus Alist loeschen (by key)
402mixed *remove_alist(mixed key,mixed *alist)
403{
404 int i,j;
405
406 if (!pointerp(alist) || !sizeof(alist))
407 return alist;
408 if (!pointerp(alist[0]))
409 {
410 if ((i=assoc(key,alist))<0)
411 return alist;
412 return alist[0..i-1]+alist[i+1..];
413 }
414 i = assoc(key,alist[0]);
415 if ((i=assoc(key,alist[0]))<0)
416 return alist;
417 alist=alist[0..];
418 for (j=sizeof(alist)-1;j>=0;j--)
419 alist[j]=alist[j][0..i-1]+alist[j][i+1..];
420 return alist;
421}
422
423// * Element aus Alist loeschen (by pos)
424mixed *exclude_alist(int i,mixed *alist)
425{
426 int j;
427 if (!pointerp(alist) || !sizeof(alist) || i<0)
428 return alist;
429 if (!pointerp(alist[0]))
430 return alist[0..i-1]+alist[i+1..];
431 alist=alist[0..]; /* Create PHYSICAL copy of alist */
432 for (j=sizeof(alist)-1;j>=0;j--)
433 alist[j]=alist[j][0..i-1]+alist[j][i+1..];
434 return alist; /* order_alist is NOT necessary - see /doc/LPC/alist */
435}
436#endif // __ALISTS__
437
438// * German version of ctime()
439#define TAGE ({"Son","Mon","Die","Mit","Don","Fre","Sam"})
440#define MONATE ({"Jan","Feb","Mar","Apr","Mai","Jun","Jul","Aug",\
441 "Sep","Okt","Nov","Dez"})
442string dtime(int wann) {
443
444 if (wann == dtime_cache[0])
445 return(dtime_cache[1]);
446
447 int *lt = localtime(wann);
448 return sprintf("%s, %2d. %s %d, %02d:%02d:%02d",
449 TAGE[lt[TM_WDAY]], lt[TM_MDAY], MONATE[lt[TM_MON]],
450 lt[TM_YEAR],lt[TM_HOUR], lt[TM_MIN], lt[TM_SEC]);
451}
452
453// wenn strftime im Driver nicht existiert, ist dies hier ein Alias auf dtime(),
454// zwar stimmt das Format dann nicht, aber die Mudlib buggt nicht und schreibt
455// ein ordentliches Datum/Uhrzeit.
456#if !__EFUN_DEFINED__(strftime)
457varargs string strftime(mixed fmt, int clock, int localized) {
458 if (intp(clock) && clock >= 0)
459 return dtime(clock);
460 else if (intp(fmt) && fmt >= 0)
461 return dtime(fmt);
462
463 return dtime(time());
464}
465#endif //!__EFUN_DEFINED__(strftime)
466
467// * Shutdown mit zusaetzlichem logging
468nomask int shutdown(string reason)
469{
470 string name;
471 string obname;
472 string output;
473
474 if (!reason)
475 return 0;
476 if ( !ARCH_SECURITY && getuid(previous_object())!=ROOTID &&
477 object_name(previous_object())!="/obj/shut" )
478 {
479 write("You have no permission to shut down the gamedriver!\n");
480 return 0;
481 }
482 if ((this_interactive())&&(name=getuid(this_interactive())))
483 {
484 name=capitalize(name);
485 filter(users(),#'tell_object,//'
486 capitalize(name)+" faehrt das Spiel herunter!\n");
487 }
488 else
489 name="ANONYMOUS";
490 if (previous_object()) obname=capitalize(getuid(previous_object()));
491 output=name;
492 if (obname && name!=obname) output=output+" ("+obname+")";
493 if (previous_object()&&object_name(previous_object())=="/obj/shut"){
494 output+=" faehrt das Spiel via Armageddon herunter.\n";
495 output=dtime(time())+": "+output;
496 log_file("GAME_LOG",output+"\n",-1);
497 efun::shutdown();
498 return 1;
499 }
500 output=ctime(time())+": "+output+" faehrt das Spiel herunter.\n";
501 output+=" Grund: "+reason;
502 log_file("GAME_LOG",output+"\n",-1);
503 efun::shutdown();
504 return 1;
505}
506
507// * lowerchar
508
509int lowerchar(int char) {
510 if (char<'A' || char>'Z') return char;
511 return char+32;
512}
513
514// * upperstring
515
516string upperstring(string s)
517{
518#if __EFUN_DEFINED__(upper_case)
519 return(upper_case(s));
520#else
521 int i;
522 if (!stringp(s)) return 0;
523 for (i=sizeof(s)-1;i>=0;i--) s[i]=((s[i]<'a'||s[i]>'z')?s[i]:s[i]-32);
524 return s;
525#endif
526}
527
528// * lowerstring
529
530string lowerstring(string s)
531{
532 if (!stringp(s)) return 0;
533 return lower_case(s);
534}
535
536
537// * GD version
538string version()
539{
540 return __VERSION__;
541}
542
543// * break_string
544// stretch() -- stretch a line to fill a given width
545private string stretch(string s, int width) {
546 int len=sizeof(s);
547 if (len==width) return s;
548
549 // reine Leerzeilen, direkt zurueckgeben
550 string trimmed=trim(s,TRIM_LEFT," ");
551 if (trimmed=="") return s;
552 int start_spaces = len - sizeof(trimmed);
553
554 string* words = explode(trimmed, " ");
555 // der letzte kriegt keine Spaces
556 int word_count=sizeof(words) - 1;
557 // wenn Zeile nur aus einem Wort, wird das Wort zurueckgegeben
558 if (!word_count)
559 return " "*start_spaces + words[0];
560
561 int space_count = width - len;
562
563 int space_per_word=(word_count+space_count) / word_count;
564 // Anz.Woerter mit Zusatz-Space
565 int rest=(word_count+space_count) % word_count;
566 // Rest-Spaces Verteilen
567 foreach (int pos : rest) words[pos]+=" ";
568 return (" "*start_spaces) + implode( words, " "*space_per_word );
569}
570
571// aus Geschwindigkeitsgruenden hat der Blocksatz fuer break_string eine
572// eigene Funktion bekommen:
573private varargs string block_string(string s, int width, int flags) {
574 // wenn BS_LEAVE_MY_LFS, aber kein BS_NO_PARINDENT, dann werden Zeilen mit
575 // einem Leerzeichen begonnen.
576 // BTW: Wenn !BS_LEAVE_MY_LFS, hat der Aufrufer bereits alle \n durch " "
577 // ersetzt.
578 if ( (flags & BS_LEAVE_MY_LFS)
579 && !(flags & BS_NO_PARINDENT))
580 {
581 s = " "+regreplace(s,"\n","\n ",1);
582 }
583
584 // sprintf fuellt die letzte Zeile auf die Feldbreite (hier also
585 // Zeilenbreite) mit Fuellzeichen auf, wenn sie NICHT mit \n umgebrochen
586 // ist. Es wird an die letzte Zeile aber kein Zeilenumbruch angehaengt.
587 // Eigentlich ist das Auffuellen doof, aber vermutlich ist es unnoetig, es
588 // wieder rueckgaengig zu machen.
589 s = sprintf( "%-*=s", width, s);
590
591 string *tmp=explode(s, "\n");
592 // Nur wenn s mehrzeilig ist, Blocksatz draus machen. Die letzte Zeile wird
593 // natuerlich nicht gedehnt. Sie ist dafuer schon von sprintf() aufgefuellt
594 // worden. BTW: Die letzte Zeile endet u.U. noch nicht mit einem \n (bzw.
595 // nur dann, wenn BS_LEAVE_MY_LFS und der uebergebene Text schon nen \n am
596 // Ende der letzten Zeile hat), das macht der Aufrufer...
597 if (sizeof(tmp) > 1)
598 return implode( map( tmp[0..<2], #'stretch/*'*/, width ), "\n" )
599 + "\n" + tmp[<1];
600
601 return s;
602}
603
604public varargs string break_string(string s, int w, mixed indent, int flags)
605{
606 if ( !s || s == "" ) return "";
607
608 if ( !w ) w=78;
609
610 if( intp(indent) )
611 indent = indent ? " "*indent : "";
612
613 int indentlen=stringp(indent) ? sizeof(indent) : 0;
614
615 if (indentlen>w) {
616 set_this_object(previous_object());
617 raise_error(sprintf("break_string: indent longer %d than width %d\n",
618 indentlen,w));
619 // w=((indentlen/w)+1)*w;
620 }
621
622 if (!(flags & BS_LEAVE_MY_LFS))
623 s=regreplace( s, "\n", " ", 1 );
624
625 if ( flags & BS_SINGLE_SPACE )
626 s = regreplace( s, "(^|\n| ) *", "\\1", 1 );
627
628 string prefix="";
629 if (indentlen && flags & BS_PREPEND_INDENT) {
630 if (indentlen+sizeof(s) > w ||
631 (flags & BS_LEAVE_MY_LFS) && strstr(s,"\n")>-1) {
632 prefix=indent+"\n";
633 indent=(flags & BS_NO_PARINDENT) ? "" : " ";
634 indentlen=sizeof(indent);
635 }
636 }
637
638 if ( flags & BS_BLOCK ) {
639 /*
640 s = implode( map( explode( s, "\n" ),
641 #'block_string, w, indentlen, flags),
642 "" );
643 */
644 s = block_string( s , w - indentlen, flags );
645 }
646 else {
647 s = sprintf("%-1.*=s",w-indentlen,s);
648 }
649 if ( s[<1] != '\n' ) s += "\n";
650
651 if ( !indentlen ) return prefix + s;
652
653 string indent2 = ( flags & BS_INDENT_ONCE ) ? (" "*indentlen) :indent;
654
655 return prefix + indent +
656 regreplace( s[0..<2], "\n", "\n"+indent2, 1 ) + "\n";
657 /*
658 string *buf;
659
660 buf = explode( s, "\n" );
661 return prefix + indent + implode( buf[0..<2], "\n"+indent2 ) + buf[<1] + "\n";
662 */
663}
664
665// * Elemente aus mapping loeschen - mapping vorher kopieren
666
667mapping m_copy_delete(mapping m, mixed key) {
668 return m_delete(copy(m), key);
669}
670
671// * times
672int last_reboot_time()
673{
674 return __BOOT_TIME__;
675}
676
677int first_boot_time()
678{
679 return 701517600;
680}
681
682int exist_days()
683{
684 return (((time()-first_boot_time())/8640)+5)/10;
685}
686
687// * uptime :)
688string uptime()
689{
690 int t;
691 int tmp;
692 string s;
693
694 t=time()-__BOOT_TIME__;
695 s="";
696 if (t>=86400)
697 s+=sprintf("%d Tag%s, ",tmp=t/86400,(tmp==1?"":"e"));
698 if (t>=3600)
699 s+=sprintf("%d Stunde%s, ",tmp=(t=t%86400)/3600,(tmp==1?"":"n"));
700 if (t>60)
701 s+=sprintf("%d Minute%s und ",tmp=(t=t%3600)/60,(tmp==1?"":"n"));
702 return s+sprintf("%d Sekunde%s",t=t%60,(t==1?"":"n"));
703}
704
705// * Was tun bei 'dangling' lfun-closures ?
706void dangling_lfun_closure() {
707 raise_error("dangling lfun closure\n");
708}
709
710// * Sperren ausser fuer master/simul_efun
711
712#if __EFUN_DEFINED__(set_environment)
713nomask void set_environment(object o1, object o2) {
714 raise_error("Available only for root\n");
715}
716#endif
717
718nomask void set_this_player(object pl) {
719 raise_error("Available only for root\n");
720}
721
722#if __EFUN_DEFINED__(export_uid)
723nomask void export_uid(object ob) {
724 raise_error("Available only for root\n");
725}
726#endif
727
728// * Jetzt auch closures
729int process_flag;
730
731public nomask int process_call()
732{
733 if (process_flag>0)
734 return process_flag;
735 else return(0);
736}
737
738private nomask string _process_string(string str,object po) {
739 set_this_object(po);
740 return(efun::process_string(str));
741}
742
743nomask string process_string( mixed str )
744{
745 string tmp, err;
746 int flag;
747
748 if ( closurep(str) ) {
749 set_this_object( previous_object() );
750 return funcall(str);
751 }
752 else if (str==0)
753 return((string)str);
754 else if ( !stringp(str) ) {
755 return to_string(str);
756 }
757
758 if ( !(flag = process_flag > time() - 60))
759 process_flag=time();
760
761 err = catch(tmp = funcall(#'_process_string,str,previous_object()); publish);
762
763 if ( !flag )
764 process_flag=0;
765
766 if (err) {
767 // Verarbeitung abbrechen
768 set_this_object(previous_object());
769 raise_error(err);
770 }
771 return tmp;
772}
773
774// 'mkdir -p' - erzeugt eine komplette Hierarchie von Verzeichnissen.
775// wenn das Verzeichnis angelegt wurde oder schon existiert, wird 1
776// zurueckgeliefert, sonst 0.
777// Wirft einen Fehler, wenn das angebene Verzeichnis nicht absolut ist!
778public int mkdirp(string dir) {
779 // wenn es nur keinen fuehrenden / gibt, ist das ein Fehler.
780 if (strstr(dir, "/") != 0)
781 raise_error("mkdirp(): Pfad ist nicht absolute.\n");
782 // cut off trailing /...
783 if (dir[<1]=='/')
784 dir = dir[0..<2];
785
786 int fstat = file_size(dir);
787 // wenn es schon existiert, tun wir einfach so, als haetten wir es angelegt.
788 if (fstat == FSIZE_DIR)
789 return 1;
790 // wenn schon ne Datei existiert, geht es nicht.
791 if (fstat != FSIZE_NOFILE)
792 return 0;
793 // wenn es nur einen / gibt (den fuehrenden), dann ist es ein
794 // toplevel-verzeichnis, was direkt angelegt wird.
795 if (strrstr(dir,"/")==0) {
796 return funcall(bind_lambda(#'efun::mkdir, previous_object()), dir);
797 }
798
799 // mkdir() nicht direkt rufen, sondern vorher als closure ans aufrufende
800 // Objekt binden. Sonst laeuft die Rechtepruefung in valid_write() im Master
801 // unter der Annahme, dass die simul_efun.c mit ihrer root id was will.
802
803 // jetzt rekursiv die Verzeichnishierarchie anlegen. Wenn das erfolgreich
804 // ist, dann koennen wir jetzt mit mkdir das tiefste Verzeichnis anlegen
805 if (mkdirp(dir[0..strrstr(dir,"/")-1]) == 1)
806 return funcall(bind_lambda(#'efun::mkdir, previous_object()), dir);
807}
808
809
810// * Properties ggfs. mitspeichern
811mixed save_object(mixed name)
812{
813 mapping properties;
814 mapping save;
815 mixed index, res;
816 int i;
Zesstraa012d622017-01-29 20:38:48 +0100817 string oldpath;
MG Mud User88f12472016-06-24 23:31:02 +0200818
819 // nur Strings und 0 zulassen
820 if ((!stringp(name) || !sizeof(name)) &&
821 (!intp(name) || name!=0)) {
822 set_this_object(previous_object());
823 raise_error(sprintf(
824 "Only non-empty strings and 0 may be used as filename in "
825 "sefun::save_object()! Argument was %O\n",name));
826 }
827
Zesstraa012d622017-01-29 20:38:48 +0100828 if (stringp(name)) {
829 // abs. Pfad erzeugen. *seufz*
830 if (name[0]!='/')
831 name = "/" + name;
Zesstraa012d622017-01-29 20:38:48 +0100832 // automatisch in LIBDATADIR speichern
833 if (strstr(name,"/"LIBDATADIR"/") != 0) {
Zesstra60aed3e2017-01-31 16:03:51 +0100834 oldpath = name;
Zesstraa012d622017-01-29 20:38:48 +0100835 name = "/"LIBDATADIR + name;
836 // wenn das Verzeichnis nicht existiert, ggf. anlegen
837 string dir = name[0..strrstr(name,"/")-1];
838 if (file_size(dir) != FSIZE_DIR) {
839 if (mkdirp(dir) != 1)
840 raise_error("save_object(): kann Verzeichnis " + dir
841 + " nicht anlegen!");
842 }
843 }
844 }
845
MG Mud User88f12472016-06-24 23:31:02 +0200846 save = m_allocate(0, 2);
847 properties = (mapping)previous_object()->QueryProperties();
848
849 if(mappingp(properties))
850 {
851 // delete all entries in mapping properties without SAVE flag!
852 index = m_indices(properties);
853 for(i = sizeof(index)-1; i>=0;i--)
854 {
855 if(properties[index[i], F_MODE] & SAVE)
856 {
857 save[index[i]] = properties[index[i]];
858 save[index[i], F_MODE] =
859 properties[index[i], F_MODE] &
860 (~(SETMNOTFOUND|QUERYMNOTFOUND|QUERYCACHED|SETCACHED));
861 }
862 }
863 }
864 else save = ([]);
865
866 // save object!
867 previous_object()->_set_save_data(save);
868 // format: wie definiert in config.h
Zesstraa012d622017-01-29 20:38:48 +0100869 if (stringp(name)) {
MG Mud User88f12472016-06-24 23:31:02 +0200870 res = funcall(bind_lambda(#'efun::save_object, previous_object()), name,
871 __LIB__SAVE_FORMAT_VERSION__);
Zesstraa012d622017-01-29 20:38:48 +0100872 // wenn erfolgreich und noch nen Savefile existiert, was nicht unter
873 // /data/ liegt, wird das geloescht.
874 if (!res && oldpath
875 && file_size(oldpath+".o") >= 0)
876 rm(oldpath+".o");
877 }
MG Mud User88f12472016-06-24 23:31:02 +0200878 else
879 res = funcall(bind_lambda(#'efun::save_object, previous_object()),
880 __LIB__SAVE_FORMAT_VERSION__);
Zesstraa012d622017-01-29 20:38:48 +0100881
MG Mud User88f12472016-06-24 23:31:02 +0200882 previous_object()->_set_save_data(0);
883
884#ifdef IOSTATS
885 // Stats...
886 struct iostat_s stat = (<iostat_s>);
887 stat->oname = object_name(previous_object());
888 stat->time = time();
889 //stat->size = (int)object_info(previous_object(),OINFO_MEMORY,
890 // OIM_TOTAL_DATA_SIZE);
891 if (stringp(name))
892 stat->size = file_size(name + ".o");
893 else
894 stat->sizeof(res);
895 //debug_message("saveo: "+saveo_stat[0]+"\n");
896 saveo_stat[1][saveo_stat[0]] = stat;
897 saveo_stat[0] = (saveo_stat[0] + 1) % sizeof(saveo_stat[1]);
898 //debug_message("saveo 2: "+saveo_stat[0]+"\n");
899#endif
900
901 return res;
902}
903
904// * Auch Properties laden
905int restore_object(string name)
906{
907 int result;
908 mixed index;
909 mixed save;
910 mapping properties;
911 int i;
912 closure cl;
913
Zesstra94381a42017-01-29 22:37:52 +0100914 if (sizeof(name) < 1)
915 {
916 set_this_object(previous_object());
917 raise_error("Bad arg 1 to restore_object(): expected non-empty "
918 "'string'.\n");
919 }
920
Zesstraa012d622017-01-29 20:38:48 +0100921 // Wenn name vermutlich ein Pfad (also nicht mit #x:y anfaengt)
922 if (name[0] != '#')
923 {
924 // abs. Pfad erzeugen *seufz*
Zesstra984bde92017-01-29 22:19:52 +0100925 if (name[0]!='/')
Zesstraa012d622017-01-29 20:38:48 +0100926 name = "/" + name;
927
Zesstraf2a0d492017-04-29 11:05:46 +0200928 // .c am Ende loeschen, sonst wird das File ggf. nicht gefunden.
929 if(name[<2..]==".c")
930 name=name[..<3];
931
Zesstraa012d622017-01-29 20:38:48 +0100932 // wenn kein /data/ vorn steht, erstmal gucken, ob das Savefile unter
933 // /data/ existiert. Wenn ja, wird das geladen.
Zesstra984bde92017-01-29 22:19:52 +0100934 if (strstr(name,"/"LIBDATADIR"/") != 0)
Zesstraa012d622017-01-29 20:38:48 +0100935 {
936 string path = "/"LIBDATADIR + name;
937 if (file_size(path + ".o") >= 0)
938 name = path;
939 }
940 }
941
MG Mud User88f12472016-06-24 23:31:02 +0200942 // get actual property settings (by create())
943 properties = (mapping)previous_object()->QueryProperties();
944
945// DEBUG(sprintf("RESTORE %O\n",name));
946 // restore object
947 result=funcall(bind_lambda(#'efun::restore_object, previous_object()), name);
948 //'))
949 //_get_save_data liefert tatsaechlich mixed zurueck, wenn das auch immer ein
950 //mapping sein sollte.
951 save = (mixed)previous_object()->_get_save_data();
952 if(mappingp(save))
953 {
954 index = m_indices(save);
955 for(i = sizeof(index)-1; i>=0; i--)
956 {
957 properties[index[i]] = save[index[i]];
958 properties[index[i], F_MODE] = save[index[i], F_MODE]
959 &~(SETCACHED|QUERYCACHED);
960 }
961 }
962 else properties = ([]);
963
964 // restore properties
965 funcall(
966 bind_lambda(
967 unbound_lambda(({'arg}), //'})
968 ({#'call_other,({#'this_object}),
969 "SetProperties",'arg})),//')
970 previous_object()),properties);
971 previous_object()->_set_save_data(0);
972
973#ifdef IOSTATS
974 // Stats...
975 //debug_message("restoreo: "+restoreo_stat[0]+"\n");
976 struct iostat_s stat = (<iostat_s>);
977 stat->oname = object_name(previous_object());
978 stat->time = time();
979 //stat->size = (int)object_info(previous_object(),OINFO_MEMORY,
980 // OIM_TOTAL_DATA_SIZE);
981 stat->size = file_size(name + ".o");
982 restoreo_stat[1][restoreo_stat[0]] = stat;
983
984 restoreo_stat[0] = (restoreo_stat[0] + 1) % sizeof(restoreo_stat[1]);
985#endif
986
987 return result;
988}
989
990// * HB eines Objektes ein/ausschalten
991int set_object_heart_beat(object ob, int flag)
992{
993 if (objectp(ob))
994 return funcall(bind_lambda(#'efun::configure_object,ob), ob, OC_HEART_BEAT, flag);
995}
996
997// * Magierlevelgruppen ermitteln
998int query_wiz_grp(mixed wiz)
999{
1000 int lev;
1001
1002 lev=query_wiz_level(wiz);
1003 if (lev<SEER_LVL) return 0;
1004 if (lev>=GOD_LVL) return lev;
1005 if (lev>=ARCH_LVL) return ARCH_GRP;
1006 if (lev>=ELDER_LVL) return ELDER_GRP;
1007 if (lev>=LORD_LVL) return LORD_GRP;
1008 if (lev>=SPECIAL_LVL) return SPECIAL_GRP;
1009 if (lev>=DOMAINMEMBER_LVL) return DOMAINMEMBER_GRP;
1010 if (lev>=WIZARD_LVL) return WIZARD_GRP;
1011 if (lev>=LEARNER_LVL) return LEARNER_GRP;
1012 return SEER_GRP;
1013}
1014
1015mixed *wizlist_info()
1016{
1017 if (ARCH_SECURITY || !extern_call())
1018 return efun::wizlist_info();
1019 return 0;
1020}
1021
1022// * wizlist ausgeben
1023varargs void wizlist(string name, int sortkey ) {
1024
1025 if (!name)
1026 {
1027 if (this_player())
1028 name = getuid(this_player());
1029 if (!name)
1030 return;
1031 }
1032
1033 // Schluessel darf nur in einem gueltigen Bereich sein
1034 if (sortkey<WL_NAME || sortkey>=WL_SIZE) sortkey=WL_COST;
1035
1036 mixed** wl = efun::wizlist_info();
1037 // nach <sortkey> sortieren
1038 wl = sort_array(wl, function int (mixed a, mixed b)
1039 {return a[sortkey] < b[sortkey]; } );
1040
1041 // Summe ueber alle Kommandos ermitteln.
1042 int total_cmd, i;
1043 int pos=-1;
1044 foreach(mixed entry : wl)
1045 {
1046 total_cmd += entry[WL_COMMANDS];
1047 if (entry[WL_NAME] == name)
1048 pos = i;
1049 ++i;
1050 }
1051
1052 if (pos < 0 && name != "ALL" && name != "TOP100")
1053 return;
1054
1055 if (name == "TOP100")
1056 {
1057 if (sizeof(wl) > 100)
1058 wl = wl[0..100];
1059 else
1060 wl = wl;
1061 }
1062 // um name herum schneiden
1063 else if (name != "ALL")
1064 {
1065 if (sizeof(wl) <= 21)
1066 wl = wl;
1067 else if (pos + 10 < sizeof(wl) && pos - 10 > 0)
1068 wl = wl[pos-10..pos+10];
1069 else if (pos <=21)
1070 wl = wl[0..20];
1071 else if (pos >= sizeof(wl) - 21)
1072 wl = wl[<21..];
1073 else
1074 wl = wl;
1075 }
1076
1077 write("\nWizard top score list\n\n");
1078 if (total_cmd == 0)
1079 total_cmd = 1;
1080 printf("%-20s %-6s %-3s %-17s %-6s %-6s %-6s\n",
1081 "EUID", "cmds", "%", "Costs", "HB", "Arrays","Mapp.");
1082 foreach(mixed e: wl)
1083 {
1084 printf("%-:20s %:6d %:2d%% [%:6dk,%:6dG] %:6d %:6d %:6d\n",
1085 e[WL_NAME], e[WL_COMMANDS], e[WL_COMMANDS] * 100 / total_cmd,
1086 e[WL_COST] / 1000, e[WL_TOTAL_GIGACOST],
1087 e[WL_HEART_BEATS], e[WL_ARRAY_TOTAL], e[WL_MAPPING_TOTAL]
1088 );
1089 }
1090 printf("\nTotal %7d (%d)\n\n", total_cmd, sizeof(wl));
1091}
1092
1093
1094// Ab hier folgen Hilfsfunktionen fuer call_out() bzw. fuer deren Begrenzung
1095
1096// ermittelt das Objekt des Callouts.
1097private object _call_out_obj( mixed call_out ) {
1098 return pointerp(call_out) ? call_out[0] : 0;
1099}
1100
1101private void _same_object( object ob, mapping m ) {
1102 // ist nicht so bloed, wie es aussieht, s. nachfolgede Verwendung von m
1103 if ( m[ob] )
1104 m[ob] += ({ ob });
1105 else
1106 m[ob] = ({ ob });
1107}
1108
1109// alle Objekte im Mapping m zusammenfassen, die den gleichen Loadname (Name der
1110// Blueprint) haben, also alle Clones der BP, die Callouts laufen haben.
1111// Objekte werden auch mehrfach erfasst, je nach Anzahl ihrer Callouts.
1112private void _same_path( object key, object *obs, mapping m ) {
1113 string path;
1114 if (!objectp(key) || !pointerp(obs)) return;
1115
1116 path = load_name(key);
1117
1118 if ( m[path] )
1119 m[path] += obs;
1120 else
1121 m[path] = obs;
1122}
1123
1124// key kann object oder string sein.
1125private int _too_many( mixed key, mapping m, int i ) {
1126 return sizeof(m[key]) >= i;
1127}
1128
1129// alle Objekte in obs zerstoeren und Fehlermeldung ausgeben. ACHTUNG: Die
1130// Objekte werden idR zu einer BP gehoeren, muessen aber nicht! In dem Fall
1131// wird auf der Ebene aber nur ein Objekt in der Fehlermeldung erwaehnt.
1132private void _destroy( mixed key, object *obs, string text, int uid ) {
1133 if (!pointerp(obs)) return;
1134 // Array mit unique Eintraege erzeugen.
1135 obs = m_indices( mkmapping(obs) );
1136 // Fehlermeldung auf der Ebene ausgeben, im catch() mit publish, damit es
1137 // auf der Ebene direkt scrollt, der backtrace verfuegbar ist (im
1138 // gegensatz zur Loesung mittels Callout), die Ausfuehrung aber weiter
1139 // laeuft.
1140 catch( efun::raise_error(
1141 sprintf( text,
1142 uid ? (string)master()->creator_file(key) : key,
1143 sizeof(obs), object_name(obs[<1]) ) );publish);
1144 // Und weg mit dem Kram...
1145 filter( obs, #'efun::destruct/*'*/ );
1146}
1147
1148// Alle Objekt einer UID im Mapping m mit UID als KEys zusammenfassen. Objekt
1149// sind dabei nicht unique.
1150private void _same_uid( string key, object *obs, mapping m, closure cf ) {
1151 string uid;
1152
1153 if ( !pointerp(obs) || !sizeof(obs) )
1154 return;
1155
1156 uid = funcall( cf, key );
1157
1158 if ( m[uid] )
1159 m[uid] += obs; // obs ist nen Array
1160 else
1161 m[uid] = obs;
1162}
1163
1164private int _log_call_out(mixed co)
1165{
1166 log_file("TOO_MANY_CALLOUTS",
1167 sprintf("%s::%O (%d)\n",object_name(co[0]),co[1],co[2]),
1168 200000);
1169 return 0;
1170}
1171
1172private int last_callout_log=0;
1173
1174nomask varargs void call_out( varargs mixed *args )
1175{
1176 mixed tmp, *call_outs;
1177
1178 // Bei >600 Callouts alle Objekte killen, die mehr als 30 Callouts laufen
1179 // haben.
1180 if ( efun::driver_info(DI_NUM_CALLOUTS) > 600
1181 && geteuid(previous_object()) != ROOTID )
1182 {
1183 // Log erzeugen...
1184 if (last_callout_log <
1185 efun::driver_info(DI_NUM_HEARTBEAT_TOTAL_CYCLES) - 10
1186 && get_eval_cost() > 200000)
1187 {
1188 last_callout_log = efun::driver_info(DI_NUM_HEARTBEAT_TOTAL_CYCLES);
1189 log_file("TOO_MANY_CALLOUTS",
1190 sprintf("\n%s: ############ Too many callouts: %d ##############\n",
1191 strftime("%y%m%d-%H%M%S"),
1192 efun::driver_info(DI_NUM_CALLOUTS)));
1193 filter(efun::call_out_info(), #'_log_call_out);
1194 }
1195 // Objekte aller Callouts ermitteln
1196 call_outs = map( efun::call_out_info(), #'_call_out_obj );
1197 mapping objectmap = ([]);
1198 filter( call_outs, #'_same_object, &objectmap );
1199 // Master nicht grillen...
1200 efun::m_delete( objectmap, master(1) );
1201 // alle Objekte raussuchen, die zuviele haben...
1202 mapping res = filter_indices( objectmap, #'_too_many, objectmap, 29 );
1203 // und ueber alle Keys gehen, an _destroy() werden Key und Array mit
1204 // Objekten uebergeben (in diesem Fall sind Keys und Array mit
1205 // Objekten jeweils das gleiche Objekt).
1206 if ( sizeof(res) )
1207 walk_mapping(res, #'_destroy, "CALL_OUT overflow by single "
1208 "object [%O]. Destructed %d objects. [%s]\n", 0 );
1209
1210 // Bei (auch nach dem ersten Aufraeumen noch) >800 Callouts alle
1211 // Objekte killen, die mehr als 50 Callouts laufen haben - und
1212 // diesmal zaehlen Clones nicht eigenstaendig! D.h. es werden alle
1213 // Clones einer BP gekillt, die Callouts laufen haben, falls alle
1214 // diese Objekte _zusammen_ mehr als 50 Callouts haben!
1215 if ( efun::driver_info(DI_NUM_CALLOUTS) > 800 ) {
1216 // zerstoerte Objekte von der letzten Aktion sind in objectmap nicht
1217 // mehr drin, da sie dort als Keys verwendet wurden.
1218 mapping pathmap=([]);
1219 // alle Objekt einer BP in res sortieren, BP-Name als Key, Arrays
1220 // von Objekten als Werte.
1221 walk_mapping( objectmap, #'_same_path, &pathmap);
1222 // alle BPs (und ihre Objekte) raussuchen, die zuviele haben...
1223 res = filter_indices( pathmap, #'_too_many/*'*/, pathmap, 50 );
1224 // und ueber alle Keys gehen, an _destroy() werden die Clones
1225 // uebergeben, die Callouts haben.
1226 if ( sizeof(res) )
1227 walk_mapping( res, #'_destroy/*'*/, "CALL_OUT overflow by file "
1228 "'%s'. Destructed %d objects. [%s]\n", 0 );
1229
1230 // Wenn beide Aufraeumarbeiten nichts gebracht haben und immer
1231 // noch >1000 Callouts laufen, werden diesmal alle Callouts
1232 // einer UID zusammengezaehlt.
1233 // Alle Objekte einer UID, die es in Summe aller ihrer Objekt mit
1234 // Callouts auf mehr als 100 Callouts bringt, werden geroestet.
1235 if (efun::driver_info(DI_NUM_CALLOUTS) > 1000)
1236 {
1237 // das nach BP-Namen vorgefilterte Mapping jetzt nach UIDs
1238 // zusammensortieren. Zerstoerte Clones filter _same_uid()
1239 // raus.
1240 mapping uidmap=([]);
1241 walk_mapping( pathmap, #'_same_uid, &uidmap,
1242 symbol_function( "creator_file",
1243 "/secure/master" ) );
1244 // In res nun UIDs als Keys und Arrays von Objekten als Werte.
1245 // Die rausfiltern, die mehr als 100 Objekte (non-unique, d.h.
1246 // 100 Callouts!) haben.
1247 res = filter_indices( uidmap, #'_too_many, uidmap, 100 );
1248 // und erneut ueber die Keys laufen und jeweils die Arrays mit
1249 // den Objekten zur Zerstoerung an _destroy()...
1250 if ( sizeof(res) )
1251 walk_mapping( res, #'_destroy, "CALL_OUT overflow by "
1252 "UID '%s'. Destructed %d objects. [%s]\n",
1253 1 );
1254 }
1255 }
1256 }
1257
1258 // Falls das aufrufende Objekt zerstoert wurde beim Aufraeumen
1259 if ( !previous_object() )
1260 return;
1261
1262 set_this_object( previous_object() );
1263 apply( #'efun::call_out, args );
1264 return;
1265}
1266
1267mixed call_out_info() {
1268
1269 object po = previous_object();
1270 mixed coi = efun::call_out_info();
1271
1272 // ungefilterten Output nur fuer bestimmte Objekte, Objekte in /std oder
1273 // /obj haben die BackboneID.
1274 if (query_wiz_level(getuid(po)) >= ARCH_LVL
1275 || (string)master()->creator_file(load_name(po)) == BACKBONEID ) {
1276 return coi;
1277 }
1278 else {
1279 return filter(coi, function mixed (mixed arr) {
1280 if (pointerp(arr) && arr[0]==po)
1281 return 1;
1282 else return 0; });
1283 }
1284}
1285
1286// * Zu einer closure das Objekt, an das sie gebunden ist, suchen
1287// NICHT das Objekt, was ggf. die lfun definiert!
1288mixed query_closure_object(closure c) {
1289 return
1290 CLOSURE_IS_UNBOUND_LAMBDA(get_type_info(c, 1)) ?
1291 0 :
1292 (to_object(c) || -1);
1293}
1294
1295// * Wir wollen nur EIN Argument ... ausserdem checks fuer den Netztotenraum
1296varargs void move_object(mixed what, mixed where)
1297{
1298 object po,tmp;
1299
1300 po=previous_object();
1301 if (!where)
1302 {
1303 where=what;
1304 what=po;
1305 }
1306 if (((stringp(where) && where==NETDEAD_ROOM ) ||
1307 (objectp(where) && where==find_object(NETDEAD_ROOM))) &&
1308 objectp(what) && object_name(what)!="/obj/sperrer")
1309 {
1310 if (!query_once_interactive(what))
1311 {
1312 what->remove();
1313 if (what) destruct(what);
1314 return;
1315 }
1316 if (living(what) || interactive(what))
1317 {
1318 log_file("NDEAD2",sprintf("TRYED TO MOVE TO NETDEAD: %O\n",what));
1319 return;
1320 }
1321 set_object_heart_beat(what,0);
1322 }
1323 tmp=what;
1324 while (tmp=environment(tmp))
1325 // Ja. Man ruft die _set_xxx()-Funktionen eigentlich nicht direkt auf.
1326 // Aber das Lichtsystem ist schon *so* rechenintensiv und gerade der
1327 // P_LAST_CONTENT_CHANGE-Cache wird *so* oft benoetigt, dass es mir
1328 // da um jedes bisschen Rechenzeit geht.
1329 // Der Zweck heiligt ja bekanntlich die Mittel. ;-)
1330 //
1331 // Tiamak
1332 tmp->_set_last_content_change();
1333 funcall(bind_lambda(#'efun::move_object,po),what,where);
1334 if (tmp=what)
1335 while (tmp=environment(tmp))
1336 tmp->_set_last_content_change();
1337}
1338
1339
1340void start_simul_efun() {
1341 mixed *info;
1342
1343 // Falls noch nicht getan, extra_wizinfo initialisieren
1344 if ( !pointerp(info = get_extra_wizinfo(0)) )
1345 set_extra_wizinfo(0, info = allocate(BACKBONE_WIZINFO_SIZE));
1346
1347 InitLivingData(info);
1348
1349 set_next_reset(10); // direkt mal aufraeumen
1350}
1351
1352protected void reset() {
1353 set_next_reset(7200);
1354 CleanLivingData();
1355}
1356
1357#if !__EFUN_DEFINED__(absolute_hb_count)
1358int absolute_hb_count() {
1359 return efun::driver_info(DI_NUM_HEARTBEAT_TOTAL_CYCLES);
1360}
1361#endif
1362
1363void __set_environment(object ob, mixed target)
1364{
1365 string path;
1366 object obj;
1367
1368 if (!objectp(ob))
1369 return;
1370 if (!IS_ARCH(geteuid(previous_object())) || !ARCH_SECURITY )
1371 return;
1372 if (objectp(target))
1373 {
1374 efun::set_environment(ob,target);
1375 return;
1376 }
1377 path=(string)MASTER->_get_path(target,this_interactive());
1378 if (stringp(path) && file_size(path+".c")>=0 &&
1379 !catch(load_object(path);publish) )
1380 {
1381 obj=find_object(path);
1382 efun::set_environment(ob,obj);
1383 return;
1384 }
1385}
1386
1387void _dump_wizlist(string file, int sortby) {
1388 int i;
1389 mixed *a;
1390
1391 if (!LORD_SECURITY)
1392 return;
1393 if (!master()->valid_write(file,geteuid(previous_object()),"write_file"))
1394 {
1395 write("NO WRITE PERMISSION\n");
1396 return;
1397 }
1398 a = wizlist_info();
1399 a = sort_array(a, lambda( ({'a,'b}),
1400 ({#'<,
1401 ({#'[,'a,sortby}),
1402 ({#'[,'b,sortby})
1403 })));
1404 rm(file);
1405 for (i=sizeof(a)-1;i>=0;i--)
1406 write_file(file,sprintf("%-11s: eval=%-8d cmds=%-6d HBs=%-5d array=%-5d mapping=%-7d\n",
1407 a[i][WL_NAME],a[i][WL_TOTAL_COST],a[i][WL_COMMANDS],a[i][WL_HEART_BEATS],
1408 a[i][WL_ARRAY_TOTAL],a[i][WL_CALL_OUT]));
1409}
1410
1411public varargs object deep_present(mixed what, object ob) {
1412
1413 if(!objectp(ob))
1414 ob=previous_object();
1415 // Wenn ein Objekt gesucht wird: Alle Envs dieses Objekts ermitteln und
1416 // schauen, ob in diesen ob vorkommt. Dann ist what in ob enthalten.
1417 if(objectp(what)) {
1418 object *envs=all_environment(what);
1419 // wenn ob kein Environment hat, ist es offensichtlich nicht in what
1420 // enthalten.
1421 if (!pointerp(envs)) return 0;
1422 if (member(envs, ob) != -1) return what;
1423 }
1424 // sonst wirds teurer, ueber alle Objekte im (deep) Inv laufen und per id()
1425 // testen. Dabei muss aber die gewuenschte Nr. ("flasche 3") abgeschnitten
1426 // werden und selber gezaehlt werden, welche das entsprechende Objekt ist.
1427 else if (stringp(what)) {
1428 int cnt;
1429 string newwhat;
1430 if(sscanf(what,"%s %d",newwhat,cnt)!=2)
1431 cnt=1;
1432 else
1433 what=newwhat;
1434 foreach(object invob: deep_inventory(ob)) {
1435 if (invob->id(what) && !--cnt)
1436 return invob;
1437 }
1438 }
1439 else {
1440 set_this_object(previous_object());
1441 raise_error(sprintf("Wrong argument 1 to deep_present(). "
1442 "Expected \"object\" or \"string\", got %.50O.\n",
1443 what));
1444 }
1445 return 0;
1446}
1447
1448mapping dump_ip_mapping()
1449{
1450 return 0;
1451}
1452
1453nomask void swap(object obj)
1454{
1455 write("Your are not allowed to swap objects by hand!\n");
1456 return;
1457}
1458
1459nomask varargs void garbage_collection(string str)
1460{
1461 if(previous_object()==0 || !IS_ARCH(geteuid(previous_object()))
1462 || !ARCH_SECURITY)
1463 {
1464 write("Call GC now and the mud will crash in 5-6 hours. DONT DO IT!\n");
1465 return;
1466 }
1467 else if (stringp(str))
1468 {
1469 return efun::garbage_collection(str);
1470 }
1471 else
1472 return efun::garbage_collection();
1473}
1474
1475varargs void notify_fail(mixed nf, int prio) {
1476 object po,oldo;
1477 int oldprio;
1478
1479 if (!PL || !objectp(po=previous_object())) return;
1480 if (!stringp(nf) && !closurep(nf)) {
1481 set_this_object(po);
1482 raise_error(sprintf(
1483 "Only strings and closures allowed for notify_fail! "
1484 "Argument was: %.50O...\n",nf));
1485 }
1486
1487 // falls ein Objekt bereits nen notify_fail() setzte, Prioritaeten abschaetzen
1488 // und vergleichen.
1489 if (objectp(oldo=query_notify_fail(1)) && po!=oldo) {
1490 if (!prio) {
1491 //Prioritaet dieses notify_fail() 'abschaetzen'
1492 if (po==PL) // Spieler-interne (soul-cmds)
1493 prio=NF_NL_OWN;
1494 else if (living(po))
1495 prio=NF_NL_LIVING;
1496 else if ((int)po->IsRoom())
1497 prio=NF_NL_ROOM;
1498 else
1499 prio=NF_NL_THING;
1500 }
1501 //Prioritaet des alten Setzers abschaetzen
1502 if (oldo==PL)
1503 oldprio=NF_NL_OWN;
1504 else if (living(oldo))
1505 oldprio=NF_NL_LIVING;
1506 else if ((int)oldo->IsRoom())
1507 oldprio=NF_NL_ROOM;
1508 else
1509 oldprio=NF_NL_THING;
1510 }
1511 else // wenn es noch kein Notify_fail gibt:
1512 oldprio=NF_NL_NONE;
1513
1514 //vergleichen und ggf. setzen
1515 if (prio >= oldprio) {
1516 set_this_object(po);
1517 efun::notify_fail(nf);
1518 }
1519
1520 return;
1521}
1522
1523void _notify_fail(string str)
1524{
1525 //query_notify_fail() benutzen, um das Objekt
1526 //des letzten notify_fail() zu ermitteln
1527 object o;
1528 if ((o=query_notify_fail(1)) && o!=previous_object())
1529 return;
1530 //noch kein notify_fail() fuer dieses Kommando gesetzt, auf gehts.
1531 set_this_object(previous_object());
1532 efun::notify_fail(str);
1533 return;
1534}
1535
1536string time2string( string format, int zeit )
1537{
1538 int i,ch,maxunit,dummy;
1539 string *parts, fmt;
1540
1541 int secs = zeit;
1542 int mins = (zeit/60);
1543 int hours = (zeit/3600);
1544 int days = (zeit/86400);
1545 int weeks = (zeit/604800);
1546 int months = (zeit/2419200);
1547 int abbr = 0;
1548
1549 parts = regexplode( format, "\(%\(-|\)[0-9]*[nwdhmsxNWDHMSX]\)|\(%%\)" );
1550
1551 for( i=1; i<sizeof(parts); i+=2 )
1552 {
1553 ch = parts[i][<1];
1554 switch( parts[i][<1] )
1555 {
1556 case 'x': case 'X':
1557 abbr = sscanf( parts[i], "%%%d", dummy ) && dummy==0;
1558 // NO break !
1559 case 'n': case 'N':
1560 maxunit |= 31;
1561 break;
1562 case 'w': case 'W':
1563 maxunit |= 15;
1564 break;
1565 case 'd': case 'D':
1566 maxunit |= 7;
1567 break;
1568 case 'h': case 'H':
1569 maxunit |= 3;
1570 break;
1571 case 'm': case 'M':
1572 maxunit |= 1;
1573 break;
1574 }
1575 }
1576 if( maxunit & 16 ) weeks %= 4;
1577 if( maxunit & 8 ) days %= 7;
1578 if( maxunit & 4 ) hours %= 24;
1579 if( maxunit & 2 ) mins %= 60;
1580 if( maxunit ) secs %= 60;
1581
1582 for( i=1; i<sizeof(parts); i+=2 )
1583 {
1584 fmt = parts[i][0..<2];
1585 ch = parts[i][<1];
1586 if( ch=='x' )
1587 {
1588 if (months > 0) ch='n';
1589 else if( weeks>0 ) ch='w';
1590 else if( days>0 ) ch='d';
1591 else if( hours>0 ) ch='h';
1592 else if(mins > 0) ch = 'm';
1593 else ch = 's';
1594 }
1595 else if( ch=='X' )
1596 {
1597 if (months > 0) ch='N';
1598 else if( weeks>0 ) ch='W';
1599 else if( days>0 ) ch='D';
1600 else if( hours>0 ) ch='H';
1601 else if(mins > 0) ch = 'M';
1602 else ch = 'S';
1603 }
1604
1605 switch( ch )
1606 {
1607 case 'n': parts[i] = sprintf( fmt+"d", months ); break;
1608 case 'w': parts[i] = sprintf( fmt+"d", weeks ); break;
1609 case 'd': parts[i] = sprintf( fmt+"d", days ); break;
1610 case 'h': parts[i] = sprintf( fmt+"d", hours ); break;
1611 case 'm': parts[i] = sprintf( fmt+"d", mins ); break;
1612 case 's': parts[i] = sprintf( fmt+"d", secs ); break;
1613 case 'N':
1614 if(abbr) parts[i] = "M";
1615 else parts[i] = sprintf( fmt+"s", (months==1) ? "Monat" : "Monate" );
1616 break;
1617 case 'W':
1618 if(abbr) parts[i] = "w"; else
1619 parts[i] = sprintf( fmt+"s", (weeks==1) ? "Woche" : "Wochen" );
1620 break;
1621 case 'D':
1622 if(abbr) parts[i] = "d"; else
1623 parts[i] = sprintf( fmt+"s", (days==1) ? "Tag" : "Tage" );
1624 break;
1625 case 'H':
1626 if(abbr) parts[i] = "h"; else
1627 parts[i] = sprintf( fmt+"s", (hours==1) ? "Stunde" : "Stunden" );
1628 break;
1629 case 'M':
1630 if(abbr) parts[i] = "m"; else
1631 parts[i] = sprintf( fmt+"s", (mins==1) ? "Minute" : "Minuten" );
1632 break;
1633 case 'S':
1634 if(abbr) parts[i] = "s"; else
1635 parts[i] = sprintf( fmt+"s", (secs==1) ? "Sekunde" : "Sekunden" );
1636 break;
1637 case '%':
1638 parts[i] = "%";
1639 break;
1640 }
1641 }
1642 return implode( parts, "" );
1643}
1644
1645nomask mixed __create_player_dummy(string name)
1646{
1647 string err;
1648 object ob;
1649 mixed m;
1650 //hat nen Scherzkeks die Blueprint bewegt?
1651 if ((ob=find_object("/secure/login")) && environment(ob))
1652 catch(destruct(ob);publish);
1653 err = catch(ob = clone_object("secure/login");publish);
1654 if (err)
1655 {
1656 write("Fehler beim Laden von /secure/login.c\n"+err+"\n");
1657 return 0;
1658 }
1659 if (objectp(m=(mixed)ob->new_logon(name))) netdead[name]=m;
1660 return m;
1661}
1662
1663nomask int secure_level()
1664{
1665 int *level;
1666 //kette der Caller durchlaufen, den niedrigsten Level in der Kette
1667 //zurueckgeben. Zerstoerte Objekte (Selbstzerstoerer) fuehren zur Rueckgabe
1668 //von 0.
1669 //caller_stack(1) fuegt dem Rueckgabearray this_interactive() hinzu bzw. 0,
1670 //wenn es keinen Interactive gibt. Die 0 fuehrt dann wie bei zerstoerten
1671 //Objekten zur Rueckgabe von 0, was gewuenscht ist, da es hier einen
1672 //INteractive geben muss.
1673 level=map(caller_stack(1),function int (object caller)
1674 {if (objectp(caller))
1675 return(query_wiz_level(geteuid(caller)));
1676 return(0); // kein Objekt da, 0.
1677 } );
1678 return(min(level)); //den kleinsten Wert im Array zurueckgeben (ggf. 0)
1679}
1680
1681nomask string secure_euid()
1682{
1683 string euid;
1684
1685 if (!this_interactive()) // Es muss einen interactive geben
1686 return 0;
1687 euid=geteuid(this_interactive());
1688 // ueber alle Caller iterieren. Wenn eines davon eine andere euid hat als
1689 // der Interactive und diese nicht die ROOTID ist, wird 0 zurueckgeben.
1690 // Ebenso, falls ein Selbstzerstoerer irgendwo in der Kette ist.
1691 foreach(object caller: caller_stack()) {
1692 if (!objectp(caller) ||
1693 (geteuid(caller)!=euid && geteuid(caller)!=ROOTID))
1694 return 0;
1695 }
1696 return euid; // 'sichere' euid zurueckgeben
1697}
1698
1699// INPUT_PROMPT und nen Leerprompt hinzufuegen, wenn keins uebergeben wird.
1700// Das soll dazu dienen, dass alle ggf. ein EOR am Promptende kriegen...
1701//#if __BOOT_TIME__ < 1360017213
1702varargs void input_to( mixed fun, int flags, varargs mixed *args )
1703{
1704 mixed *arr;
1705 int i;
1706
1707 if ( !this_player() || !previous_object() )
1708 return;
1709
1710 // TODO: input_to(...,INPUT_PROMPT, "", ...), wenn kein INPUT_PROMPT
1711 // vorkommt...
1712 if ( flags&INPUT_PROMPT ) {
1713 arr = ({ fun, flags }) + args;
1714 }
1715 else {
1716 // ggf. ein INPUT_PROMPT hinzufuegen und nen Leerstring als Prompt.
1717 flags |= INPUT_PROMPT;
1718 arr = ({ fun, flags, "" }) + args;
1719 }
1720
1721 // Arrays gegen flatten quoten.
1722 for ( i = sizeof(arr) - 1; i > 1; i-- )
1723 if ( pointerp(arr[i]) )
1724 arr[i] = quote(arr[i]);
1725
1726 apply( bind_lambda( unbound_lambda( ({}),
1727 ({ #'efun::input_to/*'*/ }) + arr ),
1728 previous_object() ) );
1729}
1730//#endif
1731
1732nomask int set_light(int i)
1733// erhoeht das Lichtlevel eines Objekts um i
1734// result: das Lichtlevel innerhalb des Objekts
1735{
1736 object ob, *inv;
1737 int lall, light, dark, tmp;
1738
1739 if (!(ob=previous_object())) return 0; // ohne das gehts nicht.
1740
1741 // aus kompatibilitaetsgruenden kann man auch den Lichtlevel noch setzen
1742 if (i!=0) ob->SetProp(P_LIGHT, ob->QueryProp(P_LIGHT)+i);
1743
1744 // Lichtberechnung findet eigentlich in der Mudlib statt.
1745 return (int)ob->QueryProp(P_INT_LIGHT);
1746}
1747
1748
1749public string iso2ascii( string str )
1750{
Zesstra0bfccdf2017-01-31 12:43:22 +01001751 if ( !sizeof(str) )
MG Mud User88f12472016-06-24 23:31:02 +02001752 return "";
Zesstra0bfccdf2017-01-31 12:43:22 +01001753 return convert_charset(str, "ISO-8859-15", "ASCII//TRANSLIT");
MG Mud User88f12472016-06-24 23:31:02 +02001754}
1755
1756
1757public varargs string CountUp( string *s, string sep, string lastsep )
1758{
1759 string ret;
1760
1761 if ( !pointerp(s) )
1762 return "";
1763
1764 if (!sep) sep = ", ";
1765 if (!lastsep) lastsep = " und ";
1766
1767 switch (sizeof(s)) {
1768 case 0: ret=""; break;
1769 case 1: ret=s[0]; break;
1770 default:
1771 ret = implode(s[0..<2], sep);
1772 ret += lastsep + s[<1];
1773 }
1774 return ret;
1775}
1776
1777nomask varargs int query_next_reset(object ob) {
1778
1779 // Typpruefung: etwas anderes als Objekte oder 0 sollen Fehler sein.
1780 if (ob && !objectp(ob))
1781 raise_error(sprintf("Bad arg 1 to query_next_reset(): got %.20O, "
1782 "expected object.\n",ob));
1783
1784 // Defaultobjekt PO, wenn 0 uebergeben.
1785 if ( !objectp(ob) )
1786 ob = previous_object();
1787
1788 return efun::object_info(ob, OI_NEXT_RESET_TIME);
1789}
1790
1791
MG Mud User88f12472016-06-24 23:31:02 +02001792
1793// ### Ersatzaufloesung in Strings ###
1794varargs string replace_personal(string str, mixed *obs, int caps) {
1795 int i;
1796 string *parts;
1797
1798 parts = regexplode(str, "@WE[A-SU]*[0-9]");
1799 i = sizeof(parts);
1800
Zesstra19102132016-09-01 22:50:36 +02001801 if (i>1)
1802 {
MG Mud User88f12472016-06-24 23:31:02 +02001803 int j, t;
1804 closure *name_cls;
1805
1806 t = j = sizeof(obs);
1807
1808 name_cls = allocate(j);
1809 while (j--)
1810 if (objectp(obs[j]))
1811 name_cls[j] = symbol_function("name", obs[j]);
1812 else if (stringp(obs[j]))
1813 name_cls[j] = obs[j];
1814
Zesstra19102132016-09-01 22:50:36 +02001815 while ((i-= 2)>0)
1816 {
MG Mud User88f12472016-06-24 23:31:02 +02001817 int ob_nr;
1818 // zu ersetzendes Token in Fall und Objektindex aufspalten
1819 ob_nr = parts[i][<1]-'1';
1820 if (ob_nr<0 || ob_nr>=t) {
1821 set_this_object(previous_object());
1822 raise_error(sprintf("replace_personal: using wrong object index %d\n",
1823 ob_nr));
1824 return implode(parts, "");
1825 }
1826
1827 // casus kann man schon hier entscheiden
1828 int casus;
1829 string part = parts[i];
1830 switch (part[3]) {
1831 case 'R': casus = WER; break;
1832 case 'S': casus = WESSEN; break;
1833 case 'M': casus = WEM; break;
1834 case 'N': casus = WEN; break;
1835 default: continue; // passt schon jetzt nicht in das Hauptmuster
1836 }
1837
1838 // und jetzt die einzelnen Keywords ohne fuehrendes "@WE", beendende Id
1839 mixed tmp;
1840 switch (part[3..<2]) {
1841 case "R": case "SSEN": case "M": case "N": // Name
1842 parts[i] = funcall(name_cls[ob_nr], casus, 1); break;
1843 case "RU": case "SSENU": case "MU": case "NU": // unbestimmt
1844 parts[i] = funcall(name_cls[ob_nr], casus); break;
1845 case "RQP": case "SSENQP": case "MQP": case "NQP": // Pronoun
1846 if (objectp(tmp = obs[ob_nr]))
1847 parts[i] = (string)tmp->QueryPronoun(casus);
1848 break;
1849 case "RQA": case "SSENQA": case "MQA": case "NQA": // Article
1850 if (objectp(tmp = obs[ob_nr]))
1851 tmp = (string)tmp->QueryArticle(casus, 1, 1);
1852 if (stringp(tmp) && !(tmp[<1]^' '))
1853 tmp = tmp[0..<2]; // Extra-Space wieder loeschen
1854 break;
1855 case "RQPPMS": case "SSENQPPMS": case "MQPPMS": case "NQPPMS":
1856 if (objectp(tmp = obs[ob_nr]))
1857 parts[i] = (string)tmp->QueryPossPronoun(MALE, casus, SINGULAR);
1858 break;
1859 case "RQPPFS": case "SSENQPPFS": case "MQPPFS": case "NQPPFS":
1860 if (objectp(tmp = obs[ob_nr]))
1861 parts[i] = (string)tmp->QueryPossPronoun(FEMALE, casus, SINGULAR);
1862 break;
1863 case "RQPPNS": case "SSENQPPNS": case "MQPPNS": case "NQPPNS":
1864 if (objectp(tmp = obs[ob_nr]))
1865 parts[i] = (string)tmp->QueryPossPronoun(NEUTER, casus, SINGULAR);
1866 break;
1867 case "RQPPMP": case "SSENQPPMP": case "MQPPMP": case "NQPPMP":
1868 if (objectp(tmp = obs[ob_nr]))
1869 parts[i] = (string)tmp->QueryPossPronoun(MALE, casus, PLURAL);
1870 break;
1871 case "RQPPFP": case "SSENQPPFP": case "MQPPFP": case "NQPPFP":
1872 if (objectp(tmp = obs[ob_nr]))
1873 parts[i] = (string)tmp->QueryPossPronoun(FEMALE, casus, PLURAL);
1874 break;
1875 case "RQPPNP": case "SSENQPPNP": case "MQPPNP": case "NQPPNP":
1876 if (objectp(tmp = obs[ob_nr]))
1877 parts[i] = (string)tmp->QueryPossPronoun(NEUTER, casus, PLURAL);
1878 break;
1879 default:
1880 continue;
1881 }
Zesstra19102132016-09-01 22:50:36 +02001882
MG Mud User88f12472016-06-24 23:31:02 +02001883 // wenn tmp ein String war, weisen wir es hier pauschal zu
1884 if (stringp(tmp))
1885 parts[i] = tmp;
1886
1887 // auf Wunsch wird nach Satzenden gross geschrieben
1888 if (caps)
Zesstra19102132016-09-01 22:50:36 +02001889 {
1890 // Wenn das vorhergehende parts[i] == "" ist, sind wir am Anfang vom
1891 // String und dies wird wie ein Satzende vorher behandelt.
1892 if (parts[i-1] == "")
MG Mud User88f12472016-06-24 23:31:02 +02001893 parts[i] = capitalize(parts[i]);
Zesstra19102132016-09-01 22:50:36 +02001894 else
1895 {
1896 switch (parts[i-1][<2..])
1897 {
1898 case ". ": case "! ": case "? ":
1899 case ".": case "!": case "?":
1900 case ".\n": case "!\n": case "?\n":
1901 case "\" ": case "\"\n":
1902 parts[i] = capitalize(parts[i]);
1903 break;
1904 }
MG Mud User88f12472016-06-24 23:31:02 +02001905 }
Zesstra19102132016-09-01 22:50:36 +02001906 }
MG Mud User88f12472016-06-24 23:31:02 +02001907 }
1908 return implode(parts, "");
1909 }
1910 return str;
1911}
1912
MG Mud User88f12472016-06-24 23:31:02 +02001913//replacements for dropped efuns in LD
1914#if !__EFUN_DEFINED__(extract)
1915deprecated varargs string extract(string str, int from, int to) {
1916
1917 if(!stringp(str)) {
1918 set_this_object(previous_object());
1919 raise_error(sprintf("Bad argument 1 to extract(): %O",str));
1920 }
1921 if (intp(from) && intp(to)) {
1922 if (from>=0 && to>=0)
1923 return(str[from .. to]);
1924 else if (from>=0 && to<0)
1925 return(str[from .. <abs(to)]);
1926 else if (from<0 && to>=0)
1927 return(str[<abs(from) .. to]);
1928 else
1929 return(str[<abs(from) .. <abs(to)]);
1930 }
1931 else if (intp(from)) {
1932 if (from>=0)
1933 return(str[from .. ]);
1934 else
1935 return(str[<abs(from) .. ]);
1936 }
1937 else {
1938 return(str);
1939 }
1940}
1941#endif // !__EFUN_DEFINED__(extract)
1942
1943#if !__EFUN_DEFINED__(slice_array)
1944deprecated varargs mixed slice_array(mixed array, int from, int to) {
1945
1946 if(!pointerp(array)) {
1947 set_this_object(previous_object());
1948 raise_error(sprintf("Bad argument 1 to slice_array(): %O",array));
1949 }
1950 if (intp(from) && intp(to)) {
1951 if (from>=0 && to>=0)
1952 return(array[from .. to]);
1953 else if (from>=0 && to<0)
1954 return(array[from .. <abs(to)]);
1955 else if (from<0 && to>=0)
1956 return(array[<abs(from) .. to]);
1957 else
1958 return(array[<abs(from) .. <abs(to)]);
1959 }
1960 else if (intp(from)) {
1961 if (from>=0)
1962 return(array[from .. ]);
1963 else
1964 return(array[<abs(from) .. ]);
1965 }
1966 else {
1967 return(array);
1968 }
1969}
1970#endif // !__EFUN_DEFINED__(slice_array)
1971
1972#if !__EFUN_DEFINED__(member_array)
1973deprecated int member_array(mixed item, mixed arraystring) {
1974
1975 if (pointerp(arraystring)) {
1976 return(efun::member(arraystring,item));
1977 }
1978 else if (stringp(arraystring)) {
1979 return(efun::member(arraystring,to_int(item)));
1980 }
1981 else {
1982 set_this_object(previous_object());
1983 raise_error(sprintf("Bad argument 1 to member_array(): %O",arraystring));
1984 }
1985}
1986#endif // !__EFUN_DEFINED__(member_array)
1987
1988// The digit at the i'th position is the number of bits set in 'i'.
1989string count_table =
1990 "0112122312232334122323342334344512232334233434452334344534454556";
1991int broken_count_bits( string s ) {
1992 int i, res;
1993 if( !stringp(s) || !(i=sizeof(s)) ) return 0;
1994 for( ; i-->0; ) {
1995 // We are counting 6 bits at a time using a precompiled table.
1996 res += count_table[(s[i]-' ')&63]-'0';
1997 }
1998 return res;
1999}
2000
2001#if !__EFUN_DEFINED__(count_bits)
2002int count_bits( string s ) {
2003 return(broken_count_bits(s));
2004}
2005#endif
2006
2007
2008// * Teile aus einem Array entfernen *** OBSOLETE
2009deprecated mixed *exclude_array(mixed *arr,int from,int to)
2010{
2011 if (to<from)
2012 to = from;
2013 return arr[0..from-1]+arr[to+1..];
2014}
2015