blob: 07ffeb6b1541485a3dbc47d2babb9348194c7a08 [file] [log] [blame]
MG Mud User88f12472016-06-24 23:31:02 +02001#include <living/comm.h>
2
Zesstraf0425f82022-09-14 00:01:15 +02003// Eine grundlegende Struct fuer Nachrichten an Livings, welche alle
4// Programme benutzen koennen.
5public struct wave_s
6{
7 string msg;
8 int type;
9 string prefix;
10};
11
MG Mud User88f12472016-06-24 23:31:02 +020012// Sendet an alle Objekte in room und room selber durch Aufruf von
13// ReceiveMsg().
14varargs void send_room(object|string room, string msg, int msg_type,
15 string msg_action, string msg_prefix, object *exclude,
Zesstraddddbf72021-05-14 16:52:16 +020016 object origin=previous_object())
MG Mud User88f12472016-06-24 23:31:02 +020017{
18 if (stringp(room))
19 room=load_object(room);
20
Bugfix1e909a02024-01-04 23:07:56 +010021 // Keine Ausgabe im Netztotenraum. Die Anwesenden fangen damit sowieso
22 // nichts an und aufgrund der aufwaendigen Checks besteht die Gefahr, dass
23 // die Ticks ausgehen.
24 if(object_name(room) == "/room/netztot") return;
25
MG Mud User88f12472016-06-24 23:31:02 +020026 object *dest = exclude ? all_inventory(room) - exclude :
27 all_inventory(room);
28
29 dest->ReceiveMsg(msg, msg_type, msg_action, msg_prefix, origin);
30}
31
Zesstra2ea5d3e2017-06-20 22:03:32 +020032varargs void send_debug(object|string wiz, string msg, string msg_prefix)
33{
34 if (stringp(wiz))
35 wiz=find_player(wiz);
Zesstraa6ac2802020-10-14 00:17:06 +020036 // Mit Absicht hier keine Pruefung auf Magierstatus. Das macht ReceiveMsg.
37 // Und: so ist die Moeglichkeit gegeben, Testspieler so einzustellen, dass
38 // sie die Debugmeldungen erhalten.
Zesstra2ea5d3e2017-06-20 22:03:32 +020039 if (objectp(wiz))
40 wiz->ReceiveMsg(msg, MT_DEBUG|MSG_BS_LEAVE_LFS|MSG_DONT_STORE,
41 0, msg_prefix, previous_object());
42}
43
MG Mud User88f12472016-06-24 23:31:02 +020044static int _shout_filter( object ob, string pat )
45{
MG Mud User88f12472016-06-24 23:31:02 +020046 if ( !environment(ob) )
47 return 0;
48
49 return sizeof( regexp( ({ object_name( environment(ob) ) }), pat ) );
50}
51
52varargs void shout( string s, mixed where ){
53 object *u;
54 string *pfade;
55
56 if ( !sizeof( u = users() - ({ this_player() }) ) )
57 return;
58
59 if ( !where )
60 pfade = ({ "/" });
61 else if ( intp(where) )
62 pfade =
63 ({ implode( efun::explode( object_name( environment(this_player()) ),
64 "/" )[0..2], "/" ) + "/" });
65 else if ( stringp(where) )
66 pfade = ({ where });
67 else
68 pfade = where;
69
70 u = filter( u, "_shout_filter", ME, implode( pfade, "|" ) );
71 u->ReceiveMsg(s, MT_COMM|MT_FAR|MSG_DONT_WRAP|MSG_DONT_STORE,
72 MA_SHOUT_SEFUN, 0, previous_object());
73}
74
75
76#if __VERSION__ > "3.3.718"
77// This sefun replaces the deprecated efun cat().
78#define CAT_MAX_LINES 50
79varargs int cat(string file, int start, int num)
80{
81 if (extern_call())
82 set_this_object(previous_object());
83
84 int more;
85
86 if (num < 0 || !this_player())
87 return 0;
88
89 if (!start)
90 start = 1;
91
92 if (!num || num > CAT_MAX_LINES) {
93 num = CAT_MAX_LINES;
94 more = sizeof(read_file(file, start+num, 1));
95 }
96
97 string txt = read_file(file, start, num);
98 if (!txt)
99 return 0;
100
101 efun::tell_object(this_player(), txt);
102
103 if (more)
104 efun::tell_object(this_player(), "*****TRUNCATED****\n");
105
106 return sizeof(txt & "\n");
107}
108#undef CAT_MAX_LINES
109#endif // __VERSION__ > "3.3.718"
110
111#if __VERSION__ > "3.3.719"
112// This sefun replaces the deprecated efun tail().
113#define TAIL_MAX_BYTES 1000
114varargs int tail(string file)
115{
116 if (extern_call())
117 set_this_object(previous_object());
118
119 if (!stringp(file) || !this_player())
120 return 0;
121
Zesstraa284f5c2019-09-27 16:14:00 +0200122 bytes bs = read_bytes(file, -(TAIL_MAX_BYTES + 80),
123 (TAIL_MAX_BYTES + 80));
MG Mud User88f12472016-06-24 23:31:02 +0200124 // read_bytes() returns 0 if the start of the section given by
Zesstraa284f5c2019-09-27 16:14:00 +0200125 // parameter #2 lies before the beginning of the file.
MG Mud User88f12472016-06-24 23:31:02 +0200126 // In this case we simply try and read the entire file.
Zesstraa284f5c2019-09-27 16:14:00 +0200127 if (!bytesp(bs) && file_size(file) < TAIL_MAX_BYTES+80)
128 bs = read_bytes(file, 0, (TAIL_MAX_BYTES + 80));
MG Mud User88f12472016-06-24 23:31:02 +0200129 // Exit if still nothing could be read.
Zesstraa284f5c2019-09-27 16:14:00 +0200130 if (!bytesp(bs))
MG Mud User88f12472016-06-24 23:31:02 +0200131 return 0;
132
Zesstraa284f5c2019-09-27 16:14:00 +0200133 // convert to string
134 string txt = to_text(bs, "UTF-8");
135
MG Mud User88f12472016-06-24 23:31:02 +0200136 // cut off first (incomplete) line
137 int index = strstr(txt, "\n");
138 if (index > -1) {
139 if (index + 1 < sizeof(txt))
140 txt = txt[index+1..];
141 else
142 txt = "";
143 }
144
145 efun::tell_object(this_player(), txt);
146
147 return 1;
148}
149#undef TAIL_MAX_BYTES
150#endif // __VERSION__ > "3.3.719"
151