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