blob: d25d756406f4d80504e93ae9a279e4b447e8452f [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,
Zesstraddddbf72021-05-14 16:52:16 +02007 object origin=previous_object())
MG Mud User88f12472016-06-24 23:31:02 +02008{
9 if (stringp(room))
10 room=load_object(room);
11
Bugfix1e909a02024-01-04 23:07:56 +010012 // Keine Ausgabe im Netztotenraum. Die Anwesenden fangen damit sowieso
13 // nichts an und aufgrund der aufwaendigen Checks besteht die Gefahr, dass
14 // die Ticks ausgehen.
15 if(object_name(room) == "/room/netztot") return;
16
MG Mud User88f12472016-06-24 23:31:02 +020017 object *dest = exclude ? all_inventory(room) - exclude :
18 all_inventory(room);
19
20 dest->ReceiveMsg(msg, msg_type, msg_action, msg_prefix, origin);
21}
22
Zesstra2ea5d3e2017-06-20 22:03:32 +020023varargs void send_debug(object|string wiz, string msg, string msg_prefix)
24{
25 if (stringp(wiz))
26 wiz=find_player(wiz);
Zesstraa6ac2802020-10-14 00:17:06 +020027 // Mit Absicht hier keine Pruefung auf Magierstatus. Das macht ReceiveMsg.
28 // Und: so ist die Moeglichkeit gegeben, Testspieler so einzustellen, dass
29 // sie die Debugmeldungen erhalten.
Zesstra2ea5d3e2017-06-20 22:03:32 +020030 if (objectp(wiz))
31 wiz->ReceiveMsg(msg, MT_DEBUG|MSG_BS_LEAVE_LFS|MSG_DONT_STORE,
32 0, msg_prefix, previous_object());
33}
34
MG Mud User88f12472016-06-24 23:31:02 +020035static int _shout_filter( object ob, string pat )
36{
MG Mud User88f12472016-06-24 23:31:02 +020037 if ( !environment(ob) )
38 return 0;
39
40 return sizeof( regexp( ({ object_name( environment(ob) ) }), pat ) );
41}
42
43varargs void shout( string s, mixed where ){
44 object *u;
45 string *pfade;
46
47 if ( !sizeof( u = users() - ({ this_player() }) ) )
48 return;
49
50 if ( !where )
51 pfade = ({ "/" });
52 else if ( intp(where) )
53 pfade =
54 ({ implode( efun::explode( object_name( environment(this_player()) ),
55 "/" )[0..2], "/" ) + "/" });
56 else if ( stringp(where) )
57 pfade = ({ where });
58 else
59 pfade = where;
60
61 u = filter( u, "_shout_filter", ME, implode( pfade, "|" ) );
62 u->ReceiveMsg(s, MT_COMM|MT_FAR|MSG_DONT_WRAP|MSG_DONT_STORE,
63 MA_SHOUT_SEFUN, 0, previous_object());
64}
65
66
67#if __VERSION__ > "3.3.718"
68// This sefun replaces the deprecated efun cat().
69#define CAT_MAX_LINES 50
70varargs int cat(string file, int start, int num)
71{
72 if (extern_call())
73 set_this_object(previous_object());
74
75 int more;
76
77 if (num < 0 || !this_player())
78 return 0;
79
80 if (!start)
81 start = 1;
82
83 if (!num || num > CAT_MAX_LINES) {
84 num = CAT_MAX_LINES;
85 more = sizeof(read_file(file, start+num, 1));
86 }
87
88 string txt = read_file(file, start, num);
89 if (!txt)
90 return 0;
91
92 efun::tell_object(this_player(), txt);
93
94 if (more)
95 efun::tell_object(this_player(), "*****TRUNCATED****\n");
96
97 return sizeof(txt & "\n");
98}
99#undef CAT_MAX_LINES
100#endif // __VERSION__ > "3.3.718"
101
102#if __VERSION__ > "3.3.719"
103// This sefun replaces the deprecated efun tail().
104#define TAIL_MAX_BYTES 1000
105varargs int tail(string file)
106{
107 if (extern_call())
108 set_this_object(previous_object());
109
110 if (!stringp(file) || !this_player())
111 return 0;
112
Zesstraa284f5c2019-09-27 16:14:00 +0200113 bytes bs = read_bytes(file, -(TAIL_MAX_BYTES + 80),
114 (TAIL_MAX_BYTES + 80));
MG Mud User88f12472016-06-24 23:31:02 +0200115 // read_bytes() returns 0 if the start of the section given by
Zesstraa284f5c2019-09-27 16:14:00 +0200116 // parameter #2 lies before the beginning of the file.
MG Mud User88f12472016-06-24 23:31:02 +0200117 // In this case we simply try and read the entire file.
Zesstraa284f5c2019-09-27 16:14:00 +0200118 if (!bytesp(bs) && file_size(file) < TAIL_MAX_BYTES+80)
119 bs = read_bytes(file, 0, (TAIL_MAX_BYTES + 80));
MG Mud User88f12472016-06-24 23:31:02 +0200120 // Exit if still nothing could be read.
Zesstraa284f5c2019-09-27 16:14:00 +0200121 if (!bytesp(bs))
MG Mud User88f12472016-06-24 23:31:02 +0200122 return 0;
123
Zesstraa284f5c2019-09-27 16:14:00 +0200124 // convert to string
125 string txt = to_text(bs, "UTF-8");
126
MG Mud User88f12472016-06-24 23:31:02 +0200127 // cut off first (incomplete) line
128 int index = strstr(txt, "\n");
129 if (index > -1) {
130 if (index + 1 < sizeof(txt))
131 txt = txt[index+1..];
132 else
133 txt = "";
134 }
135
136 efun::tell_object(this_player(), txt);
137
138 return 1;
139}
140#undef TAIL_MAX_BYTES
141#endif // __VERSION__ > "3.3.719"
142