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