blob: 6c995a9b75000dc0558c66fd6027ad0a27846f6f [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
108 string txt = read_bytes(file, -(TAIL_MAX_BYTES + 80), (TAIL_MAX_BYTES + 80));
109 // read_bytes() returns 0 if the start of the section given by
110 // parameter #2 lies beyond the beginning of the file.
111 // In this case we simply try and read the entire file.
112 if (!stringp(txt) && file_size(file) < TAIL_MAX_BYTES+80)
113 txt = read_file(file);
114 // Exit if still nothing could be read.
115 if (!stringp(txt))
116 return 0;
117
118 // cut off first (incomplete) line
119 int index = strstr(txt, "\n");
120 if (index > -1) {
121 if (index + 1 < sizeof(txt))
122 txt = txt[index+1..];
123 else
124 txt = "";
125 }
126
127 efun::tell_object(this_player(), txt);
128
129 return 1;
130}
131#undef TAIL_MAX_BYTES
132#endif // __VERSION__ > "3.3.719"
133