blob: ffb598c4d555af85d33199c849d582e697935bf4 [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 room->ReceiveMsg(msg, msg_type, msg_action, msg_prefix, origin);
18}
19
20static int _shout_filter( object ob, string pat )
21{
22 string *ignore;
23
24 if ( !environment(ob) )
25 return 0;
26
27 return sizeof( regexp( ({ object_name( environment(ob) ) }), pat ) );
28}
29
30varargs void shout( string s, mixed where ){
31 object *u;
32 string *pfade;
33
34 if ( !sizeof( u = users() - ({ this_player() }) ) )
35 return;
36
37 if ( !where )
38 pfade = ({ "/" });
39 else if ( intp(where) )
40 pfade =
41 ({ implode( efun::explode( object_name( environment(this_player()) ),
42 "/" )[0..2], "/" ) + "/" });
43 else if ( stringp(where) )
44 pfade = ({ where });
45 else
46 pfade = where;
47
48 u = filter( u, "_shout_filter", ME, implode( pfade, "|" ) );
49 u->ReceiveMsg(s, MT_COMM|MT_FAR|MSG_DONT_WRAP|MSG_DONT_STORE,
50 MA_SHOUT_SEFUN, 0, previous_object());
51}
52
53
54#if __VERSION__ > "3.3.718"
55// This sefun replaces the deprecated efun cat().
56#define CAT_MAX_LINES 50
57varargs int cat(string file, int start, int num)
58{
59 if (extern_call())
60 set_this_object(previous_object());
61
62 int more;
63
64 if (num < 0 || !this_player())
65 return 0;
66
67 if (!start)
68 start = 1;
69
70 if (!num || num > CAT_MAX_LINES) {
71 num = CAT_MAX_LINES;
72 more = sizeof(read_file(file, start+num, 1));
73 }
74
75 string txt = read_file(file, start, num);
76 if (!txt)
77 return 0;
78
79 efun::tell_object(this_player(), txt);
80
81 if (more)
82 efun::tell_object(this_player(), "*****TRUNCATED****\n");
83
84 return sizeof(txt & "\n");
85}
86#undef CAT_MAX_LINES
87#endif // __VERSION__ > "3.3.718"
88
89#if __VERSION__ > "3.3.719"
90// This sefun replaces the deprecated efun tail().
91#define TAIL_MAX_BYTES 1000
92varargs int tail(string file)
93{
94 if (extern_call())
95 set_this_object(previous_object());
96
97 if (!stringp(file) || !this_player())
98 return 0;
99
100 string txt = read_bytes(file, -(TAIL_MAX_BYTES + 80), (TAIL_MAX_BYTES + 80));
101 // read_bytes() returns 0 if the start of the section given by
102 // parameter #2 lies beyond the beginning of the file.
103 // In this case we simply try and read the entire file.
104 if (!stringp(txt) && file_size(file) < TAIL_MAX_BYTES+80)
105 txt = read_file(file);
106 // Exit if still nothing could be read.
107 if (!stringp(txt))
108 return 0;
109
110 // cut off first (incomplete) line
111 int index = strstr(txt, "\n");
112 if (index > -1) {
113 if (index + 1 < sizeof(txt))
114 txt = txt[index+1..];
115 else
116 txt = "";
117 }
118
119 efun::tell_object(this_player(), txt);
120
121 return 1;
122}
123#undef TAIL_MAX_BYTES
124#endif // __VERSION__ > "3.3.719"
125