blob: ba6b2d591aa07bb329bba7d10518a91d623046c0 [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
Zesstra2ea5d3e2017-06-20 22:03:32 +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.
Zesstra2ea5d3e2017-06-20 22:03:32 +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{
33 string *ignore;
34
35 if ( !environment(ob) )
36 return 0;
37
38 return sizeof( regexp( ({ object_name( environment(ob) ) }), pat ) );
39}
40
41varargs void shout( string s, mixed where ){
42 object *u;
43 string *pfade;
44
45 if ( !sizeof( u = users() - ({ this_player() }) ) )
46 return;
47
48 if ( !where )
49 pfade = ({ "/" });
50 else if ( intp(where) )
51 pfade =
52 ({ implode( efun::explode( object_name( environment(this_player()) ),
53 "/" )[0..2], "/" ) + "/" });
54 else if ( stringp(where) )
55 pfade = ({ where });
56 else
57 pfade = where;
58
59 u = filter( u, "_shout_filter", ME, implode( pfade, "|" ) );
60 u->ReceiveMsg(s, MT_COMM|MT_FAR|MSG_DONT_WRAP|MSG_DONT_STORE,
61 MA_SHOUT_SEFUN, 0, previous_object());
62}
63
64
65#if __VERSION__ > "3.3.718"
66// This sefun replaces the deprecated efun cat().
67#define CAT_MAX_LINES 50
68varargs int cat(string file, int start, int num)
69{
70 if (extern_call())
71 set_this_object(previous_object());
72
73 int more;
74
75 if (num < 0 || !this_player())
76 return 0;
77
78 if (!start)
79 start = 1;
80
81 if (!num || num > CAT_MAX_LINES) {
82 num = CAT_MAX_LINES;
83 more = sizeof(read_file(file, start+num, 1));
84 }
85
86 string txt = read_file(file, start, num);
87 if (!txt)
88 return 0;
89
90 efun::tell_object(this_player(), txt);
91
92 if (more)
93 efun::tell_object(this_player(), "*****TRUNCATED****\n");
94
95 return sizeof(txt & "\n");
96}
97#undef CAT_MAX_LINES
98#endif // __VERSION__ > "3.3.718"
99
100#if __VERSION__ > "3.3.719"
101// This sefun replaces the deprecated efun tail().
102#define TAIL_MAX_BYTES 1000
103varargs int tail(string file)
104{
105 if (extern_call())
106 set_this_object(previous_object());
107
108 if (!stringp(file) || !this_player())
109 return 0;
110
Zesstraa284f5c2019-09-27 16:14:00 +0200111 bytes bs = read_bytes(file, -(TAIL_MAX_BYTES + 80),
112 (TAIL_MAX_BYTES + 80));
MG Mud User88f12472016-06-24 23:31:02 +0200113 // read_bytes() returns 0 if the start of the section given by
Zesstraa284f5c2019-09-27 16:14:00 +0200114 // parameter #2 lies before the beginning of the file.
MG Mud User88f12472016-06-24 23:31:02 +0200115 // In this case we simply try and read the entire file.
Zesstraa284f5c2019-09-27 16:14:00 +0200116 if (!bytesp(bs) && file_size(file) < TAIL_MAX_BYTES+80)
117 bs = read_bytes(file, 0, (TAIL_MAX_BYTES + 80));
MG Mud User88f12472016-06-24 23:31:02 +0200118 // Exit if still nothing could be read.
Zesstraa284f5c2019-09-27 16:14:00 +0200119 if (!bytesp(bs))
MG Mud User88f12472016-06-24 23:31:02 +0200120 return 0;
121
Zesstraa284f5c2019-09-27 16:14:00 +0200122 // convert to string
123 string txt = to_text(bs, "UTF-8");
124
MG Mud User88f12472016-06-24 23:31:02 +0200125 // cut off first (incomplete) line
126 int index = strstr(txt, "\n");
127 if (index > -1) {
128 if (index + 1 < sizeof(txt))
129 txt = txt[index+1..];
130 else
131 txt = "";
132 }
133
134 efun::tell_object(this_player(), txt);
135
136 return 1;
137}
138#undef TAIL_MAX_BYTES
139#endif // __VERSION__ > "3.3.719"
140