MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame^] | 1 | |
| 2 | #pragma strict_types,save_types |
| 3 | #pragma no_clone,no_shadow |
| 4 | |
| 5 | #include <daemon.h> |
| 6 | #include <logging.h> |
| 7 | |
| 8 | static int d_start, d_end, e_start, e_end; |
| 9 | |
| 10 | protected void create() |
| 11 | { |
| 12 | d_end = d_start = e_end = e_start = file_size(__DEBUG_LOG__); |
| 13 | } |
| 14 | |
| 15 | int check( string ch, object pl, string cmd, string txt ) |
| 16 | { |
| 17 | mixed tmp; |
| 18 | |
| 19 | if ( ch != "Debug" && ch != "Entwicklung" && ch != "Warnungen" ) |
| 20 | return 0; |
| 21 | |
| 22 | if( objectp(pl) && query_once_interactive(pl) && query_wiz_level(pl) > 15 ) |
| 23 | switch(cmd){ |
| 24 | case C_FIND: |
| 25 | case C_LIST: |
| 26 | case C_JOIN: |
| 27 | case C_LEAVE: |
| 28 | return 1; |
| 29 | case C_SEND: |
| 30 | // Wer (noch) nicht auf dem Kanal ist, bekommt auch keine |
| 31 | // Ausgabe - sonst gibt es selbige doppelt, da der CHMASTER |
| 32 | // einen automatisch den Kanal betreten laesst ... |
| 33 | if ( !objectp(pl) || !pointerp(tmp=(mixed)pl->QueryProp(P_CHANNELS)) || |
| 34 | member( tmp, lower_case(ch) ) == -1 ) |
| 35 | return 1; |
| 36 | |
| 37 | switch( lower_case(txt) ){ |
| 38 | case "backtrace": |
| 39 | { |
| 40 | string bt, log; |
| 41 | int start, end; |
| 42 | |
| 43 | if ( ch == "Debug" ) { |
| 44 | start = d_start; |
| 45 | end = d_end; |
| 46 | } |
| 47 | else if (ch == "Entwicklung") { |
| 48 | start = e_start; |
| 49 | end = e_end; |
| 50 | } |
| 51 | else if (ch == "Warnungen") { |
| 52 | pl->Message( "[" + ch + ":] Backtrace fuer Warnungen " |
| 53 | "nicht verfuegbar!\n"); |
| 54 | return 0; |
| 55 | } |
| 56 | else return(1); |
| 57 | |
| 58 | if( start >= end ) |
| 59 | bt = "[" + ch + ":] Kein Backtrace verfuegbar!\n"; |
| 60 | else { |
| 61 | log = regreplace( read_bytes( __DEBUG_LOG__, start, |
| 62 | (end-start>10000)?10000: |
| 63 | end - start ) || "\nFehler beim Einlesen des Debuglogs: Kein Backtrace verfuegbar!\n", |
| 64 | "(Misplaced|current_object|" |
| 65 | "Connection|Host)[^\n]*\n", |
| 66 | "", 1 ); |
| 67 | bt = "[" + ch + ":] -- BACKTRACE BEGIN --\n" |
| 68 | + log |
| 69 | + "[" + ch + ":] -- BACKTRACE END --\n"; |
| 70 | } |
| 71 | |
| 72 | call_out( symbol_function( "Message", pl ), 0, bt ); |
| 73 | } |
| 74 | break; |
| 75 | |
| 76 | default: |
| 77 | if ( ch != "Warnungen" ) { |
| 78 | pl->Message( "[" + ch + ":] Hilfe...\n" |
| 79 | "[" + ch + ":] Folgende Kommandos stehen zur " |
| 80 | "Verfuegung:\n" |
| 81 | "[" + ch + ":] 'backtrace' -- sendet den " |
| 82 | "Backtrace zum Fehler\n" |
| 83 | "[" + ch + ":] 'hilfe' -- sendet diese " |
| 84 | "Hilfeseite\n"); |
| 85 | } |
| 86 | else { |
| 87 | pl->Message( "[" + ch + ":] Keine Kommandos verfuegbar!\n"); |
| 88 | } |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | return 0; |
| 93 | } |
| 94 | |
| 95 | string name() { return "<Debugger>"; } |
| 96 | string Name() { return "<Debugger>"; } |
| 97 | |
| 98 | void ChannelMessage( mixed a ) |
| 99 | { |
| 100 | int fs; |
| 101 | |
| 102 | fs = file_size(__DEBUG_LOG__); |
| 103 | |
| 104 | switch( a[0] ){ |
| 105 | case "Debug": |
| 106 | if ( fs > d_end && fs > e_end ){ |
| 107 | d_start = max((d_end > e_end ? d_end : e_end),0); |
| 108 | d_end = fs; |
| 109 | } |
| 110 | else if (fs < d_start || fs <= d_end) { |
| 111 | // Debuglog wurde wohl neu geoeffnet. |
| 112 | d_start = d_end = e_start = e_end = fs; |
| 113 | } |
| 114 | break; |
| 115 | |
| 116 | case "Entwicklung": |
| 117 | if ( fs > d_end && fs > e_end ){ |
| 118 | e_start = max((e_end > d_end ? e_end : d_end),0); |
| 119 | e_end = fs; |
| 120 | } |
| 121 | else if (fs < e_start || fs <= e_end) { |
| 122 | // Debuglog wurde wohl neu geoeffnet. |
| 123 | d_start = d_end = e_start = e_end = fs; |
| 124 | } |
| 125 | break; |
| 126 | } |
| 127 | } |
| 128 | |