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 | |
Bugfix | 1e909a0 | 2024-01-04 23:07:56 +0100 | [diff] [blame] | 12 | // Keine Ausgabe im Netztotenraum. Die Anwesenden fangen damit sowieso |
| 13 | // nichts an und aufgrund der aufwaendigen Checks besteht die Gefahr, dass |
| 14 | // die Ticks ausgehen. |
| 15 | if(object_name(room) == "/room/netztot") return; |
| 16 | |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 17 | object *dest = exclude ? all_inventory(room) - exclude : |
| 18 | all_inventory(room); |
| 19 | |
| 20 | dest->ReceiveMsg(msg, msg_type, msg_action, msg_prefix, origin); |
| 21 | } |
| 22 | |
Zesstra | 2ea5d3e | 2017-06-20 22:03:32 +0200 | [diff] [blame] | 23 | varargs void send_debug(object|string wiz, string msg, string msg_prefix) |
| 24 | { |
| 25 | if (stringp(wiz)) |
| 26 | wiz=find_player(wiz); |
Zesstra | a6ac280 | 2020-10-14 00:17:06 +0200 | [diff] [blame] | 27 | // Mit Absicht hier keine Pruefung auf Magierstatus. Das macht ReceiveMsg. |
| 28 | // Und: so ist die Moeglichkeit gegeben, Testspieler so einzustellen, dass |
| 29 | // sie die Debugmeldungen erhalten. |
Zesstra | 2ea5d3e | 2017-06-20 22:03:32 +0200 | [diff] [blame] | 30 | if (objectp(wiz)) |
| 31 | wiz->ReceiveMsg(msg, MT_DEBUG|MSG_BS_LEAVE_LFS|MSG_DONT_STORE, |
| 32 | 0, msg_prefix, previous_object()); |
| 33 | } |
| 34 | |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 35 | static int _shout_filter( object ob, string pat ) |
| 36 | { |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 37 | if ( !environment(ob) ) |
| 38 | return 0; |
| 39 | |
| 40 | return sizeof( regexp( ({ object_name( environment(ob) ) }), pat ) ); |
| 41 | } |
| 42 | |
| 43 | varargs void shout( string s, mixed where ){ |
| 44 | object *u; |
| 45 | string *pfade; |
| 46 | |
| 47 | if ( !sizeof( u = users() - ({ this_player() }) ) ) |
| 48 | return; |
| 49 | |
| 50 | if ( !where ) |
| 51 | pfade = ({ "/" }); |
| 52 | else if ( intp(where) ) |
| 53 | pfade = |
| 54 | ({ implode( efun::explode( object_name( environment(this_player()) ), |
| 55 | "/" )[0..2], "/" ) + "/" }); |
| 56 | else if ( stringp(where) ) |
| 57 | pfade = ({ where }); |
| 58 | else |
| 59 | pfade = where; |
| 60 | |
| 61 | u = filter( u, "_shout_filter", ME, implode( pfade, "|" ) ); |
| 62 | u->ReceiveMsg(s, MT_COMM|MT_FAR|MSG_DONT_WRAP|MSG_DONT_STORE, |
| 63 | MA_SHOUT_SEFUN, 0, previous_object()); |
| 64 | } |
| 65 | |
| 66 | |
| 67 | #if __VERSION__ > "3.3.718" |
| 68 | // This sefun replaces the deprecated efun cat(). |
| 69 | #define CAT_MAX_LINES 50 |
| 70 | varargs int cat(string file, int start, int num) |
| 71 | { |
| 72 | if (extern_call()) |
| 73 | set_this_object(previous_object()); |
| 74 | |
| 75 | int more; |
| 76 | |
| 77 | if (num < 0 || !this_player()) |
| 78 | return 0; |
| 79 | |
| 80 | if (!start) |
| 81 | start = 1; |
| 82 | |
| 83 | if (!num || num > CAT_MAX_LINES) { |
| 84 | num = CAT_MAX_LINES; |
| 85 | more = sizeof(read_file(file, start+num, 1)); |
| 86 | } |
| 87 | |
| 88 | string txt = read_file(file, start, num); |
| 89 | if (!txt) |
| 90 | return 0; |
| 91 | |
| 92 | efun::tell_object(this_player(), txt); |
| 93 | |
| 94 | if (more) |
| 95 | efun::tell_object(this_player(), "*****TRUNCATED****\n"); |
| 96 | |
| 97 | return sizeof(txt & "\n"); |
| 98 | } |
| 99 | #undef CAT_MAX_LINES |
| 100 | #endif // __VERSION__ > "3.3.718" |
| 101 | |
| 102 | #if __VERSION__ > "3.3.719" |
| 103 | // This sefun replaces the deprecated efun tail(). |
| 104 | #define TAIL_MAX_BYTES 1000 |
| 105 | varargs int tail(string file) |
| 106 | { |
| 107 | if (extern_call()) |
| 108 | set_this_object(previous_object()); |
| 109 | |
| 110 | if (!stringp(file) || !this_player()) |
| 111 | return 0; |
| 112 | |
Zesstra | a284f5c | 2019-09-27 16:14:00 +0200 | [diff] [blame] | 113 | bytes bs = read_bytes(file, -(TAIL_MAX_BYTES + 80), |
| 114 | (TAIL_MAX_BYTES + 80)); |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 115 | // read_bytes() returns 0 if the start of the section given by |
Zesstra | a284f5c | 2019-09-27 16:14:00 +0200 | [diff] [blame] | 116 | // parameter #2 lies before the beginning of the file. |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 117 | // In this case we simply try and read the entire file. |
Zesstra | a284f5c | 2019-09-27 16:14:00 +0200 | [diff] [blame] | 118 | if (!bytesp(bs) && file_size(file) < TAIL_MAX_BYTES+80) |
| 119 | bs = read_bytes(file, 0, (TAIL_MAX_BYTES + 80)); |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 120 | // Exit if still nothing could be read. |
Zesstra | a284f5c | 2019-09-27 16:14:00 +0200 | [diff] [blame] | 121 | if (!bytesp(bs)) |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 122 | return 0; |
| 123 | |
Zesstra | a284f5c | 2019-09-27 16:14:00 +0200 | [diff] [blame] | 124 | // convert to string |
| 125 | string txt = to_text(bs, "UTF-8"); |
| 126 | |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 127 | // cut off first (incomplete) line |
| 128 | int index = strstr(txt, "\n"); |
| 129 | if (index > -1) { |
| 130 | if (index + 1 < sizeof(txt)) |
| 131 | txt = txt[index+1..]; |
| 132 | else |
| 133 | txt = ""; |
| 134 | } |
| 135 | |
| 136 | efun::tell_object(this_player(), txt); |
| 137 | |
| 138 | return 1; |
| 139 | } |
| 140 | #undef TAIL_MAX_BYTES |
| 141 | #endif // __VERSION__ > "3.3.719" |
| 142 | |