blob: 4ef060f3d67b513a4ed8a6176deb07725c9c8b79 [file] [log] [blame]
MG Mud User88f12472016-06-24 23:31:02 +02001#include <living/comm.h>
2
3// Sendet an alle Objekte in room und room selber durch Aufruf von
4// ReceiveMsg().
5varargs void send_room(object|string room, string msg, int msg_type,
6 string msg_action, string msg_prefix, object *exclude,
7 object origin)
8{
9 if (stringp(room))
10 room=load_object(room);
11
12 origin ||= previous_object();
13 object *dest = exclude ? all_inventory(room) - exclude :
14 all_inventory(room);
15
16 dest->ReceiveMsg(msg, msg_type, msg_action, msg_prefix, origin);
17}
18
Zesstra370a7142017-06-20 22:00:30 +020019varargs void send_debug(object|string wiz, string msg, string msg_prefix)
20{
21 if (stringp(wiz))
22 wiz=find_player(wiz);
Zesstraa6ac2802020-10-14 00:17:06 +020023 // Mit Absicht hier keine Pruefung auf Magierstatus. Das macht ReceiveMsg.
24 // Und: so ist die Moeglichkeit gegeben, Testspieler so einzustellen, dass
25 // sie die Debugmeldungen erhalten.
Zesstra370a7142017-06-20 22:00:30 +020026 if (objectp(wiz))
27 wiz->ReceiveMsg(msg, MT_DEBUG|MSG_BS_LEAVE_LFS|MSG_DONT_STORE,
28 0, msg_prefix, previous_object());
29}
30
MG Mud User88f12472016-06-24 23:31:02 +020031static int _shout_filter( object ob, string pat )
32{
MG Mud User88f12472016-06-24 23:31:02 +020033 if ( !environment(ob) )
34 return 0;
35
36 return sizeof( regexp( ({ object_name( environment(ob) ) }), pat ) );
37}
38
39varargs void shout( string s, mixed where ){
40 object *u;
41 string *pfade;
42
43 if ( !sizeof( u = users() - ({ this_player() }) ) )
44 return;
45
46 if ( !where )
47 pfade = ({ "/" });
48 else if ( intp(where) )
49 pfade =
50 ({ implode( efun::explode( object_name( environment(this_player()) ),
51 "/" )[0..2], "/" ) + "/" });
52 else if ( stringp(where) )
53 pfade = ({ where });
54 else
55 pfade = where;
56
57 u = filter( u, "_shout_filter", ME, implode( pfade, "|" ) );
58 u->ReceiveMsg(s, MT_COMM|MT_FAR|MSG_DONT_WRAP|MSG_DONT_STORE,
59 MA_SHOUT_SEFUN, 0, previous_object());
60}
61
62
63#if __VERSION__ > "3.3.718"
64// This sefun replaces the deprecated efun cat().
65#define CAT_MAX_LINES 50
66varargs int cat(string file, int start, int num)
67{
68 if (extern_call())
69 set_this_object(previous_object());
70
71 int more;
72
73 if (num < 0 || !this_player())
74 return 0;
75
76 if (!start)
77 start = 1;
78
79 if (!num || num > CAT_MAX_LINES) {
80 num = CAT_MAX_LINES;
81 more = sizeof(read_file(file, start+num, 1));
82 }
83
84 string txt = read_file(file, start, num);
85 if (!txt)
86 return 0;
87
88 efun::tell_object(this_player(), txt);
89
90 if (more)
91 efun::tell_object(this_player(), "*****TRUNCATED****\n");
92
93 return sizeof(txt & "\n");
94}
95#undef CAT_MAX_LINES
96#endif // __VERSION__ > "3.3.718"
97
98#if __VERSION__ > "3.3.719"
99// This sefun replaces the deprecated efun tail().
100#define TAIL_MAX_BYTES 1000
101varargs int tail(string file)
102{
103 if (extern_call())
104 set_this_object(previous_object());
105
106 if (!stringp(file) || !this_player())
107 return 0;
108
Zesstraa284f5c2019-09-27 16:14:00 +0200109 bytes bs = read_bytes(file, -(TAIL_MAX_BYTES + 80),
110 (TAIL_MAX_BYTES + 80));
MG Mud User88f12472016-06-24 23:31:02 +0200111 // read_bytes() returns 0 if the start of the section given by
Zesstraa284f5c2019-09-27 16:14:00 +0200112 // parameter #2 lies before the beginning of the file.
MG Mud User88f12472016-06-24 23:31:02 +0200113 // In this case we simply try and read the entire file.
Zesstraa284f5c2019-09-27 16:14:00 +0200114 if (!bytesp(bs) && file_size(file) < TAIL_MAX_BYTES+80)
115 bs = read_bytes(file, 0, (TAIL_MAX_BYTES + 80));
MG Mud User88f12472016-06-24 23:31:02 +0200116 // Exit if still nothing could be read.
Zesstraa284f5c2019-09-27 16:14:00 +0200117 if (!bytesp(bs))
MG Mud User88f12472016-06-24 23:31:02 +0200118 return 0;
119
Zesstraa284f5c2019-09-27 16:14:00 +0200120 // convert to string
121 string txt = to_text(bs, "UTF-8");
122
MG Mud User88f12472016-06-24 23:31:02 +0200123 // cut off first (incomplete) line
124 int index = strstr(txt, "\n");
125 if (index > -1) {
126 if (index + 1 < sizeof(txt))
127 txt = txt[index+1..];
128 else
129 txt = "";
130 }
131
132 efun::tell_object(this_player(), txt);
133
134 return 1;
135}
136#undef TAIL_MAX_BYTES
137#endif // __VERSION__ > "3.3.719"
138