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