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