MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame^] | 1 | // (c) by Padreic (Padreic@mg.mud.de) |
| 2 | |
| 3 | inherit "std/secure_thing"; |
| 4 | |
| 5 | #include <properties.h> |
| 6 | #include <wizlevels.h> |
| 7 | #include <defines.h> |
| 8 | #include <moving.h> |
| 9 | |
| 10 | #define SAVEFILE "/players/"+geteuid()+"/.logtool" |
| 11 | |
| 12 | // definieren von "inline" Funktionen: |
| 13 | #define allowed() (!process_call() && PL==RPL && geteuid()==getuid(RPL)) |
| 14 | |
| 15 | mapping logs; |
| 16 | |
| 17 | static void check_logs() |
| 18 | { |
| 19 | filter(sort_array(m_indices(logs), #'>), lambda( ({ 'x }), ({#'?, |
| 20 | ({#'!=, ({#'[, logs, 'x, 2}), ({#'file_time, ({#'[, logs, 'x, 0}) }) }), |
| 21 | ({#'tell_object, ({#'environment }), ({#'sprintf, |
| 22 | "Neue Eintraege in <%s>.\n", 'x }) }), 0}))); |
| 23 | } |
| 24 | |
| 25 | void create() |
| 26 | { |
| 27 | if (!clonep(ME)) return; |
| 28 | ::create(); |
| 29 | if (!restore_object(SAVEFILE)) { |
| 30 | logs=([ "repfile": sprintf("/log/report/%s.rep", geteuid()); 0; 0 ]); |
| 31 | if (IS_ARCH(geteuid())) |
| 32 | logs+=(["snooplog": "/log/SNOOP"; 0; 0, "killer": "/log/KILLER"; 0; 0]); |
| 33 | } |
| 34 | SetProp(P_SHORT, this_player()->Name(WESSEN)+" Logtool"); |
| 35 | SetProp(P_NAME, QueryProp(P_SHORT)); |
| 36 | SetProp(P_NODROP, 0); |
| 37 | SetProp(P_NEVERDROP, 0); |
| 38 | SetProp(P_AUTOLOADOBJ, 1); |
| 39 | AddId("logtool"); |
| 40 | AddCmd("mark", "aktualisieren"); |
| 41 | AddCmd(m_indices(logs), "read_log"); |
| 42 | AddCmd("AddLog", "add_log"); |
| 43 | AddCmd("DelLog", "del_log"); |
| 44 | } |
| 45 | |
| 46 | void reset() |
| 47 | { |
| 48 | ::reset(); |
| 49 | if (!clonep(ME) || !environment()) return; |
| 50 | call_out("check_logs", 0); |
| 51 | set_next_reset(2*__RESET_TIME__); // kein Zufall, max. Laenge |
| 52 | } |
| 53 | |
| 54 | varargs int move(mixed dest, int method) |
| 55 | { |
| 56 | int i; |
| 57 | if (!objectp(dest)) dest=find_object(dest); |
| 58 | if (!dest || !interactive(dest) || getuid(dest)!=geteuid()) |
| 59 | return ME_CANT_BE_TAKEN; |
| 60 | i=::move(dest, method); |
| 61 | if (i!=1) return i; |
| 62 | if (environment()) call_out("check_logs", 0); |
| 63 | return 1; |
| 64 | } |
| 65 | |
| 66 | varargs string long() |
| 67 | { |
| 68 | return "Folgende Logfiles werden derzeit von Deinem Logtool verwaltet:\n\n" |
| 69 | +implode(map(sort_array(m_indices(logs), #'>), |
| 70 | lambda( ({ 'x }), ({#'sprintf, " %1s %-14s - %s", ({#'?, ({#'!=, |
| 71 | ({#'[,logs,'x, 2}), ({#'file_time,({#'[,logs,'x, 0})})}),"*",""}), |
| 72 | ({#'sprintf, "<%s>", 'x}), ({#'[, logs, 'x, 0})}) ) ), "\n") |
| 73 | +"\n\nMit <mark> koennen alle Eintraege als gelesen markiert und " |
| 74 | +"mit Add- und\nDelLog Logfiles in die Liste aufgenommen bzw. aus " |
| 75 | +"der Liste entfernt werden.\n"; |
| 76 | } |
| 77 | |
| 78 | static int aktualisieren(string str) |
| 79 | { |
| 80 | if (!allowed()) return 0; |
| 81 | if (str && str!="") { |
| 82 | if (!logs[str]) { |
| 83 | notify_fail("Ein solches Logfile ist nicht in der Liste enthalten.\n"); |
| 84 | return 0; |
| 85 | } |
| 86 | logs[str, 1]=file_size(logs[str, 0]); |
| 87 | logs[str, 2]=file_time(logs[str, 0]); |
| 88 | } |
| 89 | else filter(m_indices(logs), lambda( ({ 'x }),({#', , |
| 90 | ({#'=, ({#'[, logs, 'x, 1}), ({#'file_size, ({#'[, logs, 'x, 0}) }) }), |
| 91 | ({#'=, ({#'[, logs, 'x, 2}), ({#'file_time, ({#'[, logs, 'x, 0}) })})}))); |
| 92 | write("Done!\n"); |
| 93 | save_object(SAVEFILE); |
| 94 | return 1; |
| 95 | } |
| 96 | |
| 97 | static int read_log(string str) |
| 98 | { |
| 99 | int si; |
| 100 | if (!allowed()) return 0; |
| 101 | si=file_size(logs[query_verb(),0]); |
| 102 | if (str) |
| 103 | PL->more(logs[query_verb(),0]); |
| 104 | else { |
| 105 | if (si<0 || file_time(logs[query_verb(), 0])==logs[query_verb(), 2]) |
| 106 | write("Keine neuen Eintraege in <"+query_verb()+">.\n"); |
| 107 | else { |
| 108 | write("Folgendes ist neu in <"+query_verb()+">.\n"); |
| 109 | if (si<logs[query_verb(),1]) |
| 110 | PL->more(logs[query_verb(),0]); |
| 111 | else PL->More(read_bytes(logs[query_verb(),0], |
| 112 | logs[query_verb(),1],si-logs[query_verb(),1])); |
| 113 | } |
| 114 | } |
| 115 | logs[query_verb(), 1]=si; |
| 116 | logs[query_verb(), 2]=file_time(logs[query_verb(), 0]); |
| 117 | save_object(SAVEFILE); |
| 118 | return 1; |
| 119 | } |
| 120 | |
| 121 | static int add_log() |
| 122 | { |
| 123 | string key, path, str; |
| 124 | str=PL->_unparsed_args(); |
| 125 | if (!allowed() || !str || sscanf(str, "%s %s", key, path)!=2) { |
| 126 | notify_fail("Syntax: AddLog <key> <path>\n"); |
| 127 | return 0; |
| 128 | } |
| 129 | key=lower_case(key); |
| 130 | if (logs[key]) { |
| 131 | notify_fail("Es gibt schon ein Logfile mit diesem Key in der Liste.\n"); |
| 132 | return 0; |
| 133 | } |
| 134 | logs+=([ key: path; 0; 0 ]); |
| 135 | AddCmd(key, "read_log"); |
| 136 | save_object(SAVEFILE); |
| 137 | write("Logfile <"+key+"> in die Liste aufgenommen.\n"); |
| 138 | return 1; |
| 139 | } |
| 140 | |
| 141 | static int del_log(string str) |
| 142 | { |
| 143 | if (!allowed() || !str) { |
| 144 | notify_fail("WELCHES Logfile soll aus der Liste entfernt werden?\n"); |
| 145 | return 0; |
| 146 | } |
| 147 | if (!logs[str]) { |
| 148 | notify_fail("Logfile nicht in Liste enthalten.\n"); |
| 149 | return 0; |
| 150 | } |
| 151 | logs=m_copy_delete(logs,str); |
| 152 | RemoveCmd(str); |
| 153 | save_object(SAVEFILE); |
| 154 | write("Logfile <"+str+"> aus Liste entfernt.\n"); |
| 155 | return 1; |
| 156 | } |