MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 1 | #include <living/comm.h> |
| 2 | |
| 3 | // Sendet an alle Objekte in room und room selber durch Aufruf von |
| 4 | // ReceiveMsg(). |
| 5 | varargs void send_room(object|string room, string msg, int msg_type, |
| 6 | string msg_action, string msg_prefix, object *exclude, |
Zesstra | ddddbf7 | 2021-05-14 16:52:16 +0200 | [diff] [blame] | 7 | object origin=previous_object()) |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 8 | { |
| 9 | if (stringp(room)) |
| 10 | room=load_object(room); |
| 11 | |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 12 | object *dest = exclude ? all_inventory(room) - exclude : |
| 13 | all_inventory(room); |
| 14 | |
| 15 | dest->ReceiveMsg(msg, msg_type, msg_action, msg_prefix, origin); |
| 16 | } |
| 17 | |
Zesstra | 2ea5d3e | 2017-06-20 22:03:32 +0200 | [diff] [blame] | 18 | varargs void send_debug(object|string wiz, string msg, string msg_prefix) |
| 19 | { |
| 20 | if (stringp(wiz)) |
| 21 | wiz=find_player(wiz); |
Zesstra | a6ac280 | 2020-10-14 00:17:06 +0200 | [diff] [blame] | 22 | // Mit Absicht hier keine Pruefung auf Magierstatus. Das macht ReceiveMsg. |
| 23 | // Und: so ist die Moeglichkeit gegeben, Testspieler so einzustellen, dass |
| 24 | // sie die Debugmeldungen erhalten. |
Zesstra | 2ea5d3e | 2017-06-20 22:03:32 +0200 | [diff] [blame] | 25 | if (objectp(wiz)) |
| 26 | wiz->ReceiveMsg(msg, MT_DEBUG|MSG_BS_LEAVE_LFS|MSG_DONT_STORE, |
| 27 | 0, msg_prefix, previous_object()); |
| 28 | } |
| 29 | |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 30 | static int _shout_filter( object ob, string pat ) |
| 31 | { |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 32 | if ( !environment(ob) ) |
| 33 | return 0; |
| 34 | |
| 35 | return sizeof( regexp( ({ object_name( environment(ob) ) }), pat ) ); |
| 36 | } |
| 37 | |
| 38 | varargs 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 |
| 65 | varargs 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 |
| 100 | varargs 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 | |
Zesstra | a284f5c | 2019-09-27 16:14:00 +0200 | [diff] [blame] | 108 | bytes bs = read_bytes(file, -(TAIL_MAX_BYTES + 80), |
| 109 | (TAIL_MAX_BYTES + 80)); |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 110 | // read_bytes() returns 0 if the start of the section given by |
Zesstra | a284f5c | 2019-09-27 16:14:00 +0200 | [diff] [blame] | 111 | // parameter #2 lies before the beginning of the file. |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 112 | // In this case we simply try and read the entire file. |
Zesstra | a284f5c | 2019-09-27 16:14:00 +0200 | [diff] [blame] | 113 | if (!bytesp(bs) && file_size(file) < TAIL_MAX_BYTES+80) |
| 114 | bs = read_bytes(file, 0, (TAIL_MAX_BYTES + 80)); |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 115 | // Exit if still nothing could be read. |
Zesstra | a284f5c | 2019-09-27 16:14:00 +0200 | [diff] [blame] | 116 | if (!bytesp(bs)) |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 117 | return 0; |
| 118 | |
Zesstra | a284f5c | 2019-09-27 16:14:00 +0200 | [diff] [blame] | 119 | // convert to string |
| 120 | string txt = to_text(bs, "UTF-8"); |
| 121 | |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 122 | // 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 | |