blob: f5583dbd2f1ee8f113e0fde640030b1454e42e95 [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"
Zesstra19d657d2017-01-29 21:40:38 +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;
Zesstraf84b6272013-01-26 00:14:12 +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
Zesstraf84b6272013-01-26 00:14:12 +0100828 if (stringp(name)) {
829 // abs. Pfad erzeugen. *seufz*
830 if (name[0]!='/')
831 name = "/" + name;
832 oldpath = name;
833 // automatisch in LIBDATADIR speichern
834 if (strstr(name,"/"LIBDATADIR"/") != 0) {
835 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
Zesstraf84b6272013-01-26 00:14:12 +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__);
Zesstraf84b6272013-01-26 00:14:12 +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__);
Zesstraf84b6272013-01-26 00:14:12 +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
Zesstra87166e12017-01-29 20:12:37 +0100914 // Wenn name vermutlich ein Pfad (also nicht mit #x:y anfaengt)
915 if (name[0] != '#')
916 {
917 // abs. Pfad erzeugen *seufz*
Zesstra0fbf95d2017-01-29 21:48:02 +0100918 if (name[0]!='/')
Zesstra87166e12017-01-29 20:12:37 +0100919 name = "/" + name;
Zesstraf84b6272013-01-26 00:14:12 +0100920
Zesstra87166e12017-01-29 20:12:37 +0100921 // wenn kein /data/ vorn steht, erstmal gucken, ob das Savefile unter
922 // /data/ existiert. Wenn ja, wird das geladen.
Zesstra0fbf95d2017-01-29 21:48:02 +0100923 if (strstr(name,"/"LIBDATADIR"/") != 0)
Zesstra87166e12017-01-29 20:12:37 +0100924 {
925 string path = "/"LIBDATADIR + name;
926 if (file_size(path + ".o") >= 0)
927 name = path;
928 }
Zesstraf84b6272013-01-26 00:14:12 +0100929 }
930
MG Mud User88f12472016-06-24 23:31:02 +0200931 // get actual property settings (by create())
932 properties = (mapping)previous_object()->QueryProperties();
933
934// DEBUG(sprintf("RESTORE %O\n",name));
935 // restore object
936 result=funcall(bind_lambda(#'efun::restore_object, previous_object()), name);
937 //'))
938 //_get_save_data liefert tatsaechlich mixed zurueck, wenn das auch immer ein
939 //mapping sein sollte.
940 save = (mixed)previous_object()->_get_save_data();
941 if(mappingp(save))
942 {
943 index = m_indices(save);
944 for(i = sizeof(index)-1; i>=0; i--)
945 {
946 properties[index[i]] = save[index[i]];
947 properties[index[i], F_MODE] = save[index[i], F_MODE]
948 &~(SETCACHED|QUERYCACHED);
949 }
950 }
951 else properties = ([]);
952
953 // restore properties
954 funcall(
955 bind_lambda(
956 unbound_lambda(({'arg}), //'})
957 ({#'call_other,({#'this_object}),
958 "SetProperties",'arg})),//')
959 previous_object()),properties);
960 previous_object()->_set_save_data(0);
961
962#ifdef IOSTATS
963 // Stats...
964 //debug_message("restoreo: "+restoreo_stat[0]+"\n");
965 struct iostat_s stat = (<iostat_s>);
966 stat->oname = object_name(previous_object());
967 stat->time = time();
968 //stat->size = (int)object_info(previous_object(),OINFO_MEMORY,
969 // OIM_TOTAL_DATA_SIZE);
970 stat->size = file_size(name + ".o");
971 restoreo_stat[1][restoreo_stat[0]] = stat;
972
973 restoreo_stat[0] = (restoreo_stat[0] + 1) % sizeof(restoreo_stat[1]);
974#endif
975
976 return result;
977}
978
979// * HB eines Objektes ein/ausschalten
980int set_object_heart_beat(object ob, int flag)
981{
982 if (objectp(ob))
983 return funcall(bind_lambda(#'efun::configure_object,ob), ob, OC_HEART_BEAT, flag);
984}
985
986// * Magierlevelgruppen ermitteln
987int query_wiz_grp(mixed wiz)
988{
989 int lev;
990
991 lev=query_wiz_level(wiz);
992 if (lev<SEER_LVL) return 0;
993 if (lev>=GOD_LVL) return lev;
994 if (lev>=ARCH_LVL) return ARCH_GRP;
995 if (lev>=ELDER_LVL) return ELDER_GRP;
996 if (lev>=LORD_LVL) return LORD_GRP;
997 if (lev>=SPECIAL_LVL) return SPECIAL_GRP;
998 if (lev>=DOMAINMEMBER_LVL) return DOMAINMEMBER_GRP;
999 if (lev>=WIZARD_LVL) return WIZARD_GRP;
1000 if (lev>=LEARNER_LVL) return LEARNER_GRP;
1001 return SEER_GRP;
1002}
1003
1004mixed *wizlist_info()
1005{
1006 if (ARCH_SECURITY || !extern_call())
1007 return efun::wizlist_info();
1008 return 0;
1009}
1010
1011// * wizlist ausgeben
1012varargs void wizlist(string name, int sortkey ) {
1013
1014 if (!name)
1015 {
1016 if (this_player())
1017 name = getuid(this_player());
1018 if (!name)
1019 return;
1020 }
1021
1022 // Schluessel darf nur in einem gueltigen Bereich sein
1023 if (sortkey<WL_NAME || sortkey>=WL_SIZE) sortkey=WL_COST;
1024
1025 mixed** wl = efun::wizlist_info();
1026 // nach <sortkey> sortieren
1027 wl = sort_array(wl, function int (mixed a, mixed b)
1028 {return a[sortkey] < b[sortkey]; } );
1029
1030 // Summe ueber alle Kommandos ermitteln.
1031 int total_cmd, i;
1032 int pos=-1;
1033 foreach(mixed entry : wl)
1034 {
1035 total_cmd += entry[WL_COMMANDS];
1036 if (entry[WL_NAME] == name)
1037 pos = i;
1038 ++i;
1039 }
1040
1041 if (pos < 0 && name != "ALL" && name != "TOP100")
1042 return;
1043
1044 if (name == "TOP100")
1045 {
1046 if (sizeof(wl) > 100)
1047 wl = wl[0..100];
1048 else
1049 wl = wl;
1050 }
1051 // um name herum schneiden
1052 else if (name != "ALL")
1053 {
1054 if (sizeof(wl) <= 21)
1055 wl = wl;
1056 else if (pos + 10 < sizeof(wl) && pos - 10 > 0)
1057 wl = wl[pos-10..pos+10];
1058 else if (pos <=21)
1059 wl = wl[0..20];
1060 else if (pos >= sizeof(wl) - 21)
1061 wl = wl[<21..];
1062 else
1063 wl = wl;
1064 }
1065
1066 write("\nWizard top score list\n\n");
1067 if (total_cmd == 0)
1068 total_cmd = 1;
1069 printf("%-20s %-6s %-3s %-17s %-6s %-6s %-6s\n",
1070 "EUID", "cmds", "%", "Costs", "HB", "Arrays","Mapp.");
1071 foreach(mixed e: wl)
1072 {
1073 printf("%-:20s %:6d %:2d%% [%:6dk,%:6dG] %:6d %:6d %:6d\n",
1074 e[WL_NAME], e[WL_COMMANDS], e[WL_COMMANDS] * 100 / total_cmd,
1075 e[WL_COST] / 1000, e[WL_TOTAL_GIGACOST],
1076 e[WL_HEART_BEATS], e[WL_ARRAY_TOTAL], e[WL_MAPPING_TOTAL]
1077 );
1078 }
1079 printf("\nTotal %7d (%d)\n\n", total_cmd, sizeof(wl));
1080}
1081
1082
1083// Ab hier folgen Hilfsfunktionen fuer call_out() bzw. fuer deren Begrenzung
1084
1085// ermittelt das Objekt des Callouts.
1086private object _call_out_obj( mixed call_out ) {
1087 return pointerp(call_out) ? call_out[0] : 0;
1088}
1089
1090private void _same_object( object ob, mapping m ) {
1091 // ist nicht so bloed, wie es aussieht, s. nachfolgede Verwendung von m
1092 if ( m[ob] )
1093 m[ob] += ({ ob });
1094 else
1095 m[ob] = ({ ob });
1096}
1097
1098// alle Objekte im Mapping m zusammenfassen, die den gleichen Loadname (Name der
1099// Blueprint) haben, also alle Clones der BP, die Callouts laufen haben.
1100// Objekte werden auch mehrfach erfasst, je nach Anzahl ihrer Callouts.
1101private void _same_path( object key, object *obs, mapping m ) {
1102 string path;
1103 if (!objectp(key) || !pointerp(obs)) return;
1104
1105 path = load_name(key);
1106
1107 if ( m[path] )
1108 m[path] += obs;
1109 else
1110 m[path] = obs;
1111}
1112
1113// key kann object oder string sein.
1114private int _too_many( mixed key, mapping m, int i ) {
1115 return sizeof(m[key]) >= i;
1116}
1117
1118// alle Objekte in obs zerstoeren und Fehlermeldung ausgeben. ACHTUNG: Die
1119// Objekte werden idR zu einer BP gehoeren, muessen aber nicht! In dem Fall
1120// wird auf der Ebene aber nur ein Objekt in der Fehlermeldung erwaehnt.
1121private void _destroy( mixed key, object *obs, string text, int uid ) {
1122 if (!pointerp(obs)) return;
1123 // Array mit unique Eintraege erzeugen.
1124 obs = m_indices( mkmapping(obs) );
1125 // Fehlermeldung auf der Ebene ausgeben, im catch() mit publish, damit es
1126 // auf der Ebene direkt scrollt, der backtrace verfuegbar ist (im
1127 // gegensatz zur Loesung mittels Callout), die Ausfuehrung aber weiter
1128 // laeuft.
1129 catch( efun::raise_error(
1130 sprintf( text,
1131 uid ? (string)master()->creator_file(key) : key,
1132 sizeof(obs), object_name(obs[<1]) ) );publish);
1133 // Und weg mit dem Kram...
1134 filter( obs, #'efun::destruct/*'*/ );
1135}
1136
1137// Alle Objekt einer UID im Mapping m mit UID als KEys zusammenfassen. Objekt
1138// sind dabei nicht unique.
1139private void _same_uid( string key, object *obs, mapping m, closure cf ) {
1140 string uid;
1141
1142 if ( !pointerp(obs) || !sizeof(obs) )
1143 return;
1144
1145 uid = funcall( cf, key );
1146
1147 if ( m[uid] )
1148 m[uid] += obs; // obs ist nen Array
1149 else
1150 m[uid] = obs;
1151}
1152
1153private int _log_call_out(mixed co)
1154{
1155 log_file("TOO_MANY_CALLOUTS",
1156 sprintf("%s::%O (%d)\n",object_name(co[0]),co[1],co[2]),
1157 200000);
1158 return 0;
1159}
1160
1161private int last_callout_log=0;
1162
1163nomask varargs void call_out( varargs mixed *args )
1164{
1165 mixed tmp, *call_outs;
1166
1167 // Bei >600 Callouts alle Objekte killen, die mehr als 30 Callouts laufen
1168 // haben.
1169 if ( efun::driver_info(DI_NUM_CALLOUTS) > 600
1170 && geteuid(previous_object()) != ROOTID )
1171 {
1172 // Log erzeugen...
1173 if (last_callout_log <
1174 efun::driver_info(DI_NUM_HEARTBEAT_TOTAL_CYCLES) - 10
1175 && get_eval_cost() > 200000)
1176 {
1177 last_callout_log = efun::driver_info(DI_NUM_HEARTBEAT_TOTAL_CYCLES);
1178 log_file("TOO_MANY_CALLOUTS",
1179 sprintf("\n%s: ############ Too many callouts: %d ##############\n",
1180 strftime("%y%m%d-%H%M%S"),
1181 efun::driver_info(DI_NUM_CALLOUTS)));
1182 filter(efun::call_out_info(), #'_log_call_out);
1183 }
1184 // Objekte aller Callouts ermitteln
1185 call_outs = map( efun::call_out_info(), #'_call_out_obj );
1186 mapping objectmap = ([]);
1187 filter( call_outs, #'_same_object, &objectmap );
1188 // Master nicht grillen...
1189 efun::m_delete( objectmap, master(1) );
1190 // alle Objekte raussuchen, die zuviele haben...
1191 mapping res = filter_indices( objectmap, #'_too_many, objectmap, 29 );
1192 // und ueber alle Keys gehen, an _destroy() werden Key und Array mit
1193 // Objekten uebergeben (in diesem Fall sind Keys und Array mit
1194 // Objekten jeweils das gleiche Objekt).
1195 if ( sizeof(res) )
1196 walk_mapping(res, #'_destroy, "CALL_OUT overflow by single "
1197 "object [%O]. Destructed %d objects. [%s]\n", 0 );
1198
1199 // Bei (auch nach dem ersten Aufraeumen noch) >800 Callouts alle
1200 // Objekte killen, die mehr als 50 Callouts laufen haben - und
1201 // diesmal zaehlen Clones nicht eigenstaendig! D.h. es werden alle
1202 // Clones einer BP gekillt, die Callouts laufen haben, falls alle
1203 // diese Objekte _zusammen_ mehr als 50 Callouts haben!
1204 if ( efun::driver_info(DI_NUM_CALLOUTS) > 800 ) {
1205 // zerstoerte Objekte von der letzten Aktion sind in objectmap nicht
1206 // mehr drin, da sie dort als Keys verwendet wurden.
1207 mapping pathmap=([]);
1208 // alle Objekt einer BP in res sortieren, BP-Name als Key, Arrays
1209 // von Objekten als Werte.
1210 walk_mapping( objectmap, #'_same_path, &pathmap);
1211 // alle BPs (und ihre Objekte) raussuchen, die zuviele haben...
1212 res = filter_indices( pathmap, #'_too_many/*'*/, pathmap, 50 );
1213 // und ueber alle Keys gehen, an _destroy() werden die Clones
1214 // uebergeben, die Callouts haben.
1215 if ( sizeof(res) )
1216 walk_mapping( res, #'_destroy/*'*/, "CALL_OUT overflow by file "
1217 "'%s'. Destructed %d objects. [%s]\n", 0 );
1218
1219 // Wenn beide Aufraeumarbeiten nichts gebracht haben und immer
1220 // noch >1000 Callouts laufen, werden diesmal alle Callouts
1221 // einer UID zusammengezaehlt.
1222 // Alle Objekte einer UID, die es in Summe aller ihrer Objekt mit
1223 // Callouts auf mehr als 100 Callouts bringt, werden geroestet.
1224 if (efun::driver_info(DI_NUM_CALLOUTS) > 1000)
1225 {
1226 // das nach BP-Namen vorgefilterte Mapping jetzt nach UIDs
1227 // zusammensortieren. Zerstoerte Clones filter _same_uid()
1228 // raus.
1229 mapping uidmap=([]);
1230 walk_mapping( pathmap, #'_same_uid, &uidmap,
1231 symbol_function( "creator_file",
1232 "/secure/master" ) );
1233 // In res nun UIDs als Keys und Arrays von Objekten als Werte.
1234 // Die rausfiltern, die mehr als 100 Objekte (non-unique, d.h.
1235 // 100 Callouts!) haben.
1236 res = filter_indices( uidmap, #'_too_many, uidmap, 100 );
1237 // und erneut ueber die Keys laufen und jeweils die Arrays mit
1238 // den Objekten zur Zerstoerung an _destroy()...
1239 if ( sizeof(res) )
1240 walk_mapping( res, #'_destroy, "CALL_OUT overflow by "
1241 "UID '%s'. Destructed %d objects. [%s]\n",
1242 1 );
1243 }
1244 }
1245 }
1246
1247 // Falls das aufrufende Objekt zerstoert wurde beim Aufraeumen
1248 if ( !previous_object() )
1249 return;
1250
1251 set_this_object( previous_object() );
1252 apply( #'efun::call_out, args );
1253 return;
1254}
1255
1256mixed call_out_info() {
1257
1258 object po = previous_object();
1259 mixed coi = efun::call_out_info();
1260
1261 // ungefilterten Output nur fuer bestimmte Objekte, Objekte in /std oder
1262 // /obj haben die BackboneID.
1263 if (query_wiz_level(getuid(po)) >= ARCH_LVL
1264 || (string)master()->creator_file(load_name(po)) == BACKBONEID ) {
1265 return coi;
1266 }
1267 else {
1268 return filter(coi, function mixed (mixed arr) {
1269 if (pointerp(arr) && arr[0]==po)
1270 return 1;
1271 else return 0; });
1272 }
1273}
1274
1275// * Zu einer closure das Objekt, an das sie gebunden ist, suchen
1276// NICHT das Objekt, was ggf. die lfun definiert!
1277mixed query_closure_object(closure c) {
1278 return
1279 CLOSURE_IS_UNBOUND_LAMBDA(get_type_info(c, 1)) ?
1280 0 :
1281 (to_object(c) || -1);
1282}
1283
1284// * Wir wollen nur EIN Argument ... ausserdem checks fuer den Netztotenraum
1285varargs void move_object(mixed what, mixed where)
1286{
1287 object po,tmp;
1288
1289 po=previous_object();
1290 if (!where)
1291 {
1292 where=what;
1293 what=po;
1294 }
1295 if (((stringp(where) && where==NETDEAD_ROOM ) ||
1296 (objectp(where) && where==find_object(NETDEAD_ROOM))) &&
1297 objectp(what) && object_name(what)!="/obj/sperrer")
1298 {
1299 if (!query_once_interactive(what))
1300 {
1301 what->remove();
1302 if (what) destruct(what);
1303 return;
1304 }
1305 if (living(what) || interactive(what))
1306 {
1307 log_file("NDEAD2",sprintf("TRYED TO MOVE TO NETDEAD: %O\n",what));
1308 return;
1309 }
1310 set_object_heart_beat(what,0);
1311 }
1312 tmp=what;
1313 while (tmp=environment(tmp))
1314 // Ja. Man ruft die _set_xxx()-Funktionen eigentlich nicht direkt auf.
1315 // Aber das Lichtsystem ist schon *so* rechenintensiv und gerade der
1316 // P_LAST_CONTENT_CHANGE-Cache wird *so* oft benoetigt, dass es mir
1317 // da um jedes bisschen Rechenzeit geht.
1318 // Der Zweck heiligt ja bekanntlich die Mittel. ;-)
1319 //
1320 // Tiamak
1321 tmp->_set_last_content_change();
1322 funcall(bind_lambda(#'efun::move_object,po),what,where);
1323 if (tmp=what)
1324 while (tmp=environment(tmp))
1325 tmp->_set_last_content_change();
1326}
1327
1328
1329void start_simul_efun() {
1330 mixed *info;
1331
1332 // Falls noch nicht getan, extra_wizinfo initialisieren
1333 if ( !pointerp(info = get_extra_wizinfo(0)) )
1334 set_extra_wizinfo(0, info = allocate(BACKBONE_WIZINFO_SIZE));
1335
1336 InitLivingData(info);
1337
1338 set_next_reset(10); // direkt mal aufraeumen
1339}
1340
1341protected void reset() {
1342 set_next_reset(7200);
1343 CleanLivingData();
1344}
1345
1346#if !__EFUN_DEFINED__(absolute_hb_count)
1347int absolute_hb_count() {
1348 return efun::driver_info(DI_NUM_HEARTBEAT_TOTAL_CYCLES);
1349}
1350#endif
1351
1352void __set_environment(object ob, mixed target)
1353{
1354 string path;
1355 object obj;
1356
1357 if (!objectp(ob))
1358 return;
1359 if (!IS_ARCH(geteuid(previous_object())) || !ARCH_SECURITY )
1360 return;
1361 if (objectp(target))
1362 {
1363 efun::set_environment(ob,target);
1364 return;
1365 }
1366 path=(string)MASTER->_get_path(target,this_interactive());
1367 if (stringp(path) && file_size(path+".c")>=0 &&
1368 !catch(load_object(path);publish) )
1369 {
1370 obj=find_object(path);
1371 efun::set_environment(ob,obj);
1372 return;
1373 }
1374}
1375
1376void _dump_wizlist(string file, int sortby) {
1377 int i;
1378 mixed *a;
1379
1380 if (!LORD_SECURITY)
1381 return;
1382 if (!master()->valid_write(file,geteuid(previous_object()),"write_file"))
1383 {
1384 write("NO WRITE PERMISSION\n");
1385 return;
1386 }
1387 a = wizlist_info();
1388 a = sort_array(a, lambda( ({'a,'b}),
1389 ({#'<,
1390 ({#'[,'a,sortby}),
1391 ({#'[,'b,sortby})
1392 })));
1393 rm(file);
1394 for (i=sizeof(a)-1;i>=0;i--)
1395 write_file(file,sprintf("%-11s: eval=%-8d cmds=%-6d HBs=%-5d array=%-5d mapping=%-7d\n",
1396 a[i][WL_NAME],a[i][WL_TOTAL_COST],a[i][WL_COMMANDS],a[i][WL_HEART_BEATS],
1397 a[i][WL_ARRAY_TOTAL],a[i][WL_CALL_OUT]));
1398}
1399
1400public varargs object deep_present(mixed what, object ob) {
1401
1402 if(!objectp(ob))
1403 ob=previous_object();
1404 // Wenn ein Objekt gesucht wird: Alle Envs dieses Objekts ermitteln und
1405 // schauen, ob in diesen ob vorkommt. Dann ist what in ob enthalten.
1406 if(objectp(what)) {
1407 object *envs=all_environment(what);
1408 // wenn ob kein Environment hat, ist es offensichtlich nicht in what
1409 // enthalten.
1410 if (!pointerp(envs)) return 0;
1411 if (member(envs, ob) != -1) return what;
1412 }
1413 // sonst wirds teurer, ueber alle Objekte im (deep) Inv laufen und per id()
1414 // testen. Dabei muss aber die gewuenschte Nr. ("flasche 3") abgeschnitten
1415 // werden und selber gezaehlt werden, welche das entsprechende Objekt ist.
1416 else if (stringp(what)) {
1417 int cnt;
1418 string newwhat;
1419 if(sscanf(what,"%s %d",newwhat,cnt)!=2)
1420 cnt=1;
1421 else
1422 what=newwhat;
1423 foreach(object invob: deep_inventory(ob)) {
1424 if (invob->id(what) && !--cnt)
1425 return invob;
1426 }
1427 }
1428 else {
1429 set_this_object(previous_object());
1430 raise_error(sprintf("Wrong argument 1 to deep_present(). "
1431 "Expected \"object\" or \"string\", got %.50O.\n",
1432 what));
1433 }
1434 return 0;
1435}
1436
1437mapping dump_ip_mapping()
1438{
1439 return 0;
1440}
1441
1442nomask void swap(object obj)
1443{
1444 write("Your are not allowed to swap objects by hand!\n");
1445 return;
1446}
1447
1448nomask varargs void garbage_collection(string str)
1449{
1450 if(previous_object()==0 || !IS_ARCH(geteuid(previous_object()))
1451 || !ARCH_SECURITY)
1452 {
1453 write("Call GC now and the mud will crash in 5-6 hours. DONT DO IT!\n");
1454 return;
1455 }
1456 else if (stringp(str))
1457 {
1458 return efun::garbage_collection(str);
1459 }
1460 else
1461 return efun::garbage_collection();
1462}
1463
1464varargs void notify_fail(mixed nf, int prio) {
1465 object po,oldo;
1466 int oldprio;
1467
1468 if (!PL || !objectp(po=previous_object())) return;
1469 if (!stringp(nf) && !closurep(nf)) {
1470 set_this_object(po);
1471 raise_error(sprintf(
1472 "Only strings and closures allowed for notify_fail! "
1473 "Argument was: %.50O...\n",nf));
1474 }
1475
1476 // falls ein Objekt bereits nen notify_fail() setzte, Prioritaeten abschaetzen
1477 // und vergleichen.
1478 if (objectp(oldo=query_notify_fail(1)) && po!=oldo) {
1479 if (!prio) {
1480 //Prioritaet dieses notify_fail() 'abschaetzen'
1481 if (po==PL) // Spieler-interne (soul-cmds)
1482 prio=NF_NL_OWN;
1483 else if (living(po))
1484 prio=NF_NL_LIVING;
1485 else if ((int)po->IsRoom())
1486 prio=NF_NL_ROOM;
1487 else
1488 prio=NF_NL_THING;
1489 }
1490 //Prioritaet des alten Setzers abschaetzen
1491 if (oldo==PL)
1492 oldprio=NF_NL_OWN;
1493 else if (living(oldo))
1494 oldprio=NF_NL_LIVING;
1495 else if ((int)oldo->IsRoom())
1496 oldprio=NF_NL_ROOM;
1497 else
1498 oldprio=NF_NL_THING;
1499 }
1500 else // wenn es noch kein Notify_fail gibt:
1501 oldprio=NF_NL_NONE;
1502
1503 //vergleichen und ggf. setzen
1504 if (prio >= oldprio) {
1505 set_this_object(po);
1506 efun::notify_fail(nf);
1507 }
1508
1509 return;
1510}
1511
1512void _notify_fail(string str)
1513{
1514 //query_notify_fail() benutzen, um das Objekt
1515 //des letzten notify_fail() zu ermitteln
1516 object o;
1517 if ((o=query_notify_fail(1)) && o!=previous_object())
1518 return;
1519 //noch kein notify_fail() fuer dieses Kommando gesetzt, auf gehts.
1520 set_this_object(previous_object());
1521 efun::notify_fail(str);
1522 return;
1523}
1524
1525string time2string( string format, int zeit )
1526{
1527 int i,ch,maxunit,dummy;
1528 string *parts, fmt;
1529
1530 int secs = zeit;
1531 int mins = (zeit/60);
1532 int hours = (zeit/3600);
1533 int days = (zeit/86400);
1534 int weeks = (zeit/604800);
1535 int months = (zeit/2419200);
1536 int abbr = 0;
1537
1538 parts = regexplode( format, "\(%\(-|\)[0-9]*[nwdhmsxNWDHMSX]\)|\(%%\)" );
1539
1540 for( i=1; i<sizeof(parts); i+=2 )
1541 {
1542 ch = parts[i][<1];
1543 switch( parts[i][<1] )
1544 {
1545 case 'x': case 'X':
1546 abbr = sscanf( parts[i], "%%%d", dummy ) && dummy==0;
1547 // NO break !
1548 case 'n': case 'N':
1549 maxunit |= 31;
1550 break;
1551 case 'w': case 'W':
1552 maxunit |= 15;
1553 break;
1554 case 'd': case 'D':
1555 maxunit |= 7;
1556 break;
1557 case 'h': case 'H':
1558 maxunit |= 3;
1559 break;
1560 case 'm': case 'M':
1561 maxunit |= 1;
1562 break;
1563 }
1564 }
1565 if( maxunit & 16 ) weeks %= 4;
1566 if( maxunit & 8 ) days %= 7;
1567 if( maxunit & 4 ) hours %= 24;
1568 if( maxunit & 2 ) mins %= 60;
1569 if( maxunit ) secs %= 60;
1570
1571 for( i=1; i<sizeof(parts); i+=2 )
1572 {
1573 fmt = parts[i][0..<2];
1574 ch = parts[i][<1];
1575 if( ch=='x' )
1576 {
1577 if (months > 0) ch='n';
1578 else if( weeks>0 ) ch='w';
1579 else if( days>0 ) ch='d';
1580 else if( hours>0 ) ch='h';
1581 else if(mins > 0) ch = 'm';
1582 else ch = 's';
1583 }
1584 else if( ch=='X' )
1585 {
1586 if (months > 0) ch='N';
1587 else if( weeks>0 ) ch='W';
1588 else if( days>0 ) ch='D';
1589 else if( hours>0 ) ch='H';
1590 else if(mins > 0) ch = 'M';
1591 else ch = 'S';
1592 }
1593
1594 switch( ch )
1595 {
1596 case 'n': parts[i] = sprintf( fmt+"d", months ); break;
1597 case 'w': parts[i] = sprintf( fmt+"d", weeks ); break;
1598 case 'd': parts[i] = sprintf( fmt+"d", days ); break;
1599 case 'h': parts[i] = sprintf( fmt+"d", hours ); break;
1600 case 'm': parts[i] = sprintf( fmt+"d", mins ); break;
1601 case 's': parts[i] = sprintf( fmt+"d", secs ); break;
1602 case 'N':
1603 if(abbr) parts[i] = "M";
1604 else parts[i] = sprintf( fmt+"s", (months==1) ? "Monat" : "Monate" );
1605 break;
1606 case 'W':
1607 if(abbr) parts[i] = "w"; else
1608 parts[i] = sprintf( fmt+"s", (weeks==1) ? "Woche" : "Wochen" );
1609 break;
1610 case 'D':
1611 if(abbr) parts[i] = "d"; else
1612 parts[i] = sprintf( fmt+"s", (days==1) ? "Tag" : "Tage" );
1613 break;
1614 case 'H':
1615 if(abbr) parts[i] = "h"; else
1616 parts[i] = sprintf( fmt+"s", (hours==1) ? "Stunde" : "Stunden" );
1617 break;
1618 case 'M':
1619 if(abbr) parts[i] = "m"; else
1620 parts[i] = sprintf( fmt+"s", (mins==1) ? "Minute" : "Minuten" );
1621 break;
1622 case 'S':
1623 if(abbr) parts[i] = "s"; else
1624 parts[i] = sprintf( fmt+"s", (secs==1) ? "Sekunde" : "Sekunden" );
1625 break;
1626 case '%':
1627 parts[i] = "%";
1628 break;
1629 }
1630 }
1631 return implode( parts, "" );
1632}
1633
1634nomask mixed __create_player_dummy(string name)
1635{
1636 string err;
1637 object ob;
1638 mixed m;
1639 //hat nen Scherzkeks die Blueprint bewegt?
1640 if ((ob=find_object("/secure/login")) && environment(ob))
1641 catch(destruct(ob);publish);
1642 err = catch(ob = clone_object("secure/login");publish);
1643 if (err)
1644 {
1645 write("Fehler beim Laden von /secure/login.c\n"+err+"\n");
1646 return 0;
1647 }
1648 if (objectp(m=(mixed)ob->new_logon(name))) netdead[name]=m;
1649 return m;
1650}
1651
1652nomask int secure_level()
1653{
1654 int *level;
1655 //kette der Caller durchlaufen, den niedrigsten Level in der Kette
1656 //zurueckgeben. Zerstoerte Objekte (Selbstzerstoerer) fuehren zur Rueckgabe
1657 //von 0.
1658 //caller_stack(1) fuegt dem Rueckgabearray this_interactive() hinzu bzw. 0,
1659 //wenn es keinen Interactive gibt. Die 0 fuehrt dann wie bei zerstoerten
1660 //Objekten zur Rueckgabe von 0, was gewuenscht ist, da es hier einen
1661 //INteractive geben muss.
1662 level=map(caller_stack(1),function int (object caller)
1663 {if (objectp(caller))
1664 return(query_wiz_level(geteuid(caller)));
1665 return(0); // kein Objekt da, 0.
1666 } );
1667 return(min(level)); //den kleinsten Wert im Array zurueckgeben (ggf. 0)
1668}
1669
1670nomask string secure_euid()
1671{
1672 string euid;
1673
1674 if (!this_interactive()) // Es muss einen interactive geben
1675 return 0;
1676 euid=geteuid(this_interactive());
1677 // ueber alle Caller iterieren. Wenn eines davon eine andere euid hat als
1678 // der Interactive und diese nicht die ROOTID ist, wird 0 zurueckgeben.
1679 // Ebenso, falls ein Selbstzerstoerer irgendwo in der Kette ist.
1680 foreach(object caller: caller_stack()) {
1681 if (!objectp(caller) ||
1682 (geteuid(caller)!=euid && geteuid(caller)!=ROOTID))
1683 return 0;
1684 }
1685 return euid; // 'sichere' euid zurueckgeben
1686}
1687
1688// INPUT_PROMPT und nen Leerprompt hinzufuegen, wenn keins uebergeben wird.
1689// Das soll dazu dienen, dass alle ggf. ein EOR am Promptende kriegen...
1690//#if __BOOT_TIME__ < 1360017213
1691varargs void input_to( mixed fun, int flags, varargs mixed *args )
1692{
1693 mixed *arr;
1694 int i;
1695
1696 if ( !this_player() || !previous_object() )
1697 return;
1698
1699 // TODO: input_to(...,INPUT_PROMPT, "", ...), wenn kein INPUT_PROMPT
1700 // vorkommt...
1701 if ( flags&INPUT_PROMPT ) {
1702 arr = ({ fun, flags }) + args;
1703 }
1704 else {
1705 // ggf. ein INPUT_PROMPT hinzufuegen und nen Leerstring als Prompt.
1706 flags |= INPUT_PROMPT;
1707 arr = ({ fun, flags, "" }) + args;
1708 }
1709
1710 // Arrays gegen flatten quoten.
1711 for ( i = sizeof(arr) - 1; i > 1; i-- )
1712 if ( pointerp(arr[i]) )
1713 arr[i] = quote(arr[i]);
1714
1715 apply( bind_lambda( unbound_lambda( ({}),
1716 ({ #'efun::input_to/*'*/ }) + arr ),
1717 previous_object() ) );
1718}
1719//#endif
1720
1721nomask int set_light(int i)
1722// erhoeht das Lichtlevel eines Objekts um i
1723// result: das Lichtlevel innerhalb des Objekts
1724{
1725 object ob, *inv;
1726 int lall, light, dark, tmp;
1727
1728 if (!(ob=previous_object())) return 0; // ohne das gehts nicht.
1729
1730 // aus kompatibilitaetsgruenden kann man auch den Lichtlevel noch setzen
1731 if (i!=0) ob->SetProp(P_LIGHT, ob->QueryProp(P_LIGHT)+i);
1732
1733 // Lichtberechnung findet eigentlich in der Mudlib statt.
1734 return (int)ob->QueryProp(P_INT_LIGHT);
1735}
1736
1737
1738public string iso2ascii( string str )
1739{
1740 if ( !stringp(str) || !sizeof(str) )
1741 return "";
1742
1743 str = regreplace( str, "ä", "ae", 1 );
1744 str = regreplace( str, "ö", "oe", 1 );
1745 str = regreplace( str, "ü", "ue", 1 );
1746 str = regreplace( str, "Ä", "Ae", 1 );
1747 str = regreplace( str, "Ö", "Oe", 1 );
1748 str = regreplace( str, "Ü", "Ue", 1 );
1749 str = regreplace( str, "ß", "ss", 1 );
1750 str = regreplace( str, "[^ -~]", "?", 1 );
1751
1752 return str;
1753}
1754
1755
1756public varargs string CountUp( string *s, string sep, string lastsep )
1757{
1758 string ret;
1759
1760 if ( !pointerp(s) )
1761 return "";
1762
1763 if (!sep) sep = ", ";
1764 if (!lastsep) lastsep = " und ";
1765
1766 switch (sizeof(s)) {
1767 case 0: ret=""; break;
1768 case 1: ret=s[0]; break;
1769 default:
1770 ret = implode(s[0..<2], sep);
1771 ret += lastsep + s[<1];
1772 }
1773 return ret;
1774}
1775
1776nomask varargs int query_next_reset(object ob) {
1777
1778 // Typpruefung: etwas anderes als Objekte oder 0 sollen Fehler sein.
1779 if (ob && !objectp(ob))
1780 raise_error(sprintf("Bad arg 1 to query_next_reset(): got %.20O, "
1781 "expected object.\n",ob));
1782
1783 // Defaultobjekt PO, wenn 0 uebergeben.
1784 if ( !objectp(ob) )
1785 ob = previous_object();
1786
1787 return efun::object_info(ob, OI_NEXT_RESET_TIME);
1788}
1789
1790
MG Mud User88f12472016-06-24 23:31:02 +02001791
1792// ### Ersatzaufloesung in Strings ###
1793varargs string replace_personal(string str, mixed *obs, int caps) {
1794 int i;
1795 string *parts;
1796
1797 parts = regexplode(str, "@WE[A-SU]*[0-9]");
1798 i = sizeof(parts);
1799
Zesstra19102132016-09-01 22:50:36 +02001800 if (i>1)
1801 {
MG Mud User88f12472016-06-24 23:31:02 +02001802 int j, t;
1803 closure *name_cls;
1804
1805 t = j = sizeof(obs);
1806
1807 name_cls = allocate(j);
1808 while (j--)
1809 if (objectp(obs[j]))
1810 name_cls[j] = symbol_function("name", obs[j]);
1811 else if (stringp(obs[j]))
1812 name_cls[j] = obs[j];
1813
Zesstra19102132016-09-01 22:50:36 +02001814 while ((i-= 2)>0)
1815 {
MG Mud User88f12472016-06-24 23:31:02 +02001816 int ob_nr;
1817 // zu ersetzendes Token in Fall und Objektindex aufspalten
1818 ob_nr = parts[i][<1]-'1';
1819 if (ob_nr<0 || ob_nr>=t) {
1820 set_this_object(previous_object());
1821 raise_error(sprintf("replace_personal: using wrong object index %d\n",
1822 ob_nr));
1823 return implode(parts, "");
1824 }
1825
1826 // casus kann man schon hier entscheiden
1827 int casus;
1828 string part = parts[i];
1829 switch (part[3]) {
1830 case 'R': casus = WER; break;
1831 case 'S': casus = WESSEN; break;
1832 case 'M': casus = WEM; break;
1833 case 'N': casus = WEN; break;
1834 default: continue; // passt schon jetzt nicht in das Hauptmuster
1835 }
1836
1837 // und jetzt die einzelnen Keywords ohne fuehrendes "@WE", beendende Id
1838 mixed tmp;
1839 switch (part[3..<2]) {
1840 case "R": case "SSEN": case "M": case "N": // Name
1841 parts[i] = funcall(name_cls[ob_nr], casus, 1); break;
1842 case "RU": case "SSENU": case "MU": case "NU": // unbestimmt
1843 parts[i] = funcall(name_cls[ob_nr], casus); break;
1844 case "RQP": case "SSENQP": case "MQP": case "NQP": // Pronoun
1845 if (objectp(tmp = obs[ob_nr]))
1846 parts[i] = (string)tmp->QueryPronoun(casus);
1847 break;
1848 case "RQA": case "SSENQA": case "MQA": case "NQA": // Article
1849 if (objectp(tmp = obs[ob_nr]))
1850 tmp = (string)tmp->QueryArticle(casus, 1, 1);
1851 if (stringp(tmp) && !(tmp[<1]^' '))
1852 tmp = tmp[0..<2]; // Extra-Space wieder loeschen
1853 break;
1854 case "RQPPMS": case "SSENQPPMS": case "MQPPMS": case "NQPPMS":
1855 if (objectp(tmp = obs[ob_nr]))
1856 parts[i] = (string)tmp->QueryPossPronoun(MALE, casus, SINGULAR);
1857 break;
1858 case "RQPPFS": case "SSENQPPFS": case "MQPPFS": case "NQPPFS":
1859 if (objectp(tmp = obs[ob_nr]))
1860 parts[i] = (string)tmp->QueryPossPronoun(FEMALE, casus, SINGULAR);
1861 break;
1862 case "RQPPNS": case "SSENQPPNS": case "MQPPNS": case "NQPPNS":
1863 if (objectp(tmp = obs[ob_nr]))
1864 parts[i] = (string)tmp->QueryPossPronoun(NEUTER, casus, SINGULAR);
1865 break;
1866 case "RQPPMP": case "SSENQPPMP": case "MQPPMP": case "NQPPMP":
1867 if (objectp(tmp = obs[ob_nr]))
1868 parts[i] = (string)tmp->QueryPossPronoun(MALE, casus, PLURAL);
1869 break;
1870 case "RQPPFP": case "SSENQPPFP": case "MQPPFP": case "NQPPFP":
1871 if (objectp(tmp = obs[ob_nr]))
1872 parts[i] = (string)tmp->QueryPossPronoun(FEMALE, casus, PLURAL);
1873 break;
1874 case "RQPPNP": case "SSENQPPNP": case "MQPPNP": case "NQPPNP":
1875 if (objectp(tmp = obs[ob_nr]))
1876 parts[i] = (string)tmp->QueryPossPronoun(NEUTER, casus, PLURAL);
1877 break;
1878 default:
1879 continue;
1880 }
Zesstra19102132016-09-01 22:50:36 +02001881
MG Mud User88f12472016-06-24 23:31:02 +02001882 // wenn tmp ein String war, weisen wir es hier pauschal zu
1883 if (stringp(tmp))
1884 parts[i] = tmp;
1885
1886 // auf Wunsch wird nach Satzenden gross geschrieben
1887 if (caps)
Zesstra19102132016-09-01 22:50:36 +02001888 {
1889 // Wenn das vorhergehende parts[i] == "" ist, sind wir am Anfang vom
1890 // String und dies wird wie ein Satzende vorher behandelt.
1891 if (parts[i-1] == "")
MG Mud User88f12472016-06-24 23:31:02 +02001892 parts[i] = capitalize(parts[i]);
Zesstra19102132016-09-01 22:50:36 +02001893 else
1894 {
1895 switch (parts[i-1][<2..])
1896 {
1897 case ". ": case "! ": case "? ":
1898 case ".": case "!": case "?":
1899 case ".\n": case "!\n": case "?\n":
1900 case "\" ": case "\"\n":
1901 parts[i] = capitalize(parts[i]);
1902 break;
1903 }
MG Mud User88f12472016-06-24 23:31:02 +02001904 }
Zesstra19102132016-09-01 22:50:36 +02001905 }
MG Mud User88f12472016-06-24 23:31:02 +02001906 }
1907 return implode(parts, "");
1908 }
1909 return str;
1910}
1911
MG Mud User88f12472016-06-24 23:31:02 +02001912//replacements for dropped efuns in LD
1913#if !__EFUN_DEFINED__(extract)
1914deprecated varargs string extract(string str, int from, int to) {
1915
1916 if(!stringp(str)) {
1917 set_this_object(previous_object());
1918 raise_error(sprintf("Bad argument 1 to extract(): %O",str));
1919 }
1920 if (intp(from) && intp(to)) {
1921 if (from>=0 && to>=0)
1922 return(str[from .. to]);
1923 else if (from>=0 && to<0)
1924 return(str[from .. <abs(to)]);
1925 else if (from<0 && to>=0)
1926 return(str[<abs(from) .. to]);
1927 else
1928 return(str[<abs(from) .. <abs(to)]);
1929 }
1930 else if (intp(from)) {
1931 if (from>=0)
1932 return(str[from .. ]);
1933 else
1934 return(str[<abs(from) .. ]);
1935 }
1936 else {
1937 return(str);
1938 }
1939}
1940#endif // !__EFUN_DEFINED__(extract)
1941
1942#if !__EFUN_DEFINED__(slice_array)
1943deprecated varargs mixed slice_array(mixed array, int from, int to) {
1944
1945 if(!pointerp(array)) {
1946 set_this_object(previous_object());
1947 raise_error(sprintf("Bad argument 1 to slice_array(): %O",array));
1948 }
1949 if (intp(from) && intp(to)) {
1950 if (from>=0 && to>=0)
1951 return(array[from .. to]);
1952 else if (from>=0 && to<0)
1953 return(array[from .. <abs(to)]);
1954 else if (from<0 && to>=0)
1955 return(array[<abs(from) .. to]);
1956 else
1957 return(array[<abs(from) .. <abs(to)]);
1958 }
1959 else if (intp(from)) {
1960 if (from>=0)
1961 return(array[from .. ]);
1962 else
1963 return(array[<abs(from) .. ]);
1964 }
1965 else {
1966 return(array);
1967 }
1968}
1969#endif // !__EFUN_DEFINED__(slice_array)
1970
1971#if !__EFUN_DEFINED__(member_array)
1972deprecated int member_array(mixed item, mixed arraystring) {
1973
1974 if (pointerp(arraystring)) {
1975 return(efun::member(arraystring,item));
1976 }
1977 else if (stringp(arraystring)) {
1978 return(efun::member(arraystring,to_int(item)));
1979 }
1980 else {
1981 set_this_object(previous_object());
1982 raise_error(sprintf("Bad argument 1 to member_array(): %O",arraystring));
1983 }
1984}
1985#endif // !__EFUN_DEFINED__(member_array)
1986
1987// The digit at the i'th position is the number of bits set in 'i'.
1988string count_table =
1989 "0112122312232334122323342334344512232334233434452334344534454556";
1990int broken_count_bits( string s ) {
1991 int i, res;
1992 if( !stringp(s) || !(i=sizeof(s)) ) return 0;
1993 for( ; i-->0; ) {
1994 // We are counting 6 bits at a time using a precompiled table.
1995 res += count_table[(s[i]-' ')&63]-'0';
1996 }
1997 return res;
1998}
1999
2000#if !__EFUN_DEFINED__(count_bits)
2001int count_bits( string s ) {
2002 return(broken_count_bits(s));
2003}
2004#endif
2005
2006
2007// * Teile aus einem Array entfernen *** OBSOLETE
2008deprecated mixed *exclude_array(mixed *arr,int from,int to)
2009{
2010 if (to<from)
2011 to = from;
2012 return arr[0..from-1]+arr[to+1..];
2013}
2014