MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame^] | 1 | // MorgenGrauen MUDlib |
| 2 | // |
| 3 | // secure/sinmaster.c -- Das Strafregister |
| 4 | // |
| 5 | // $Id: sinmaster.c 9142 2015-02-04 22:17:29Z Zesstra $ |
| 6 | |
| 7 | #define SIN_SAVE "/secure/ARCH/sins" |
| 8 | #define SIN_LOG "ARCH/sins" |
| 9 | #define SIN_DUMP "/secure/ARCH/sins.dump" |
| 10 | |
| 11 | #include <defines.h> |
| 12 | #include <properties.h> |
| 13 | #include <wizlevels.h> |
| 14 | |
| 15 | #pragma strict_types |
| 16 | |
| 17 | mapping sins; |
| 18 | |
| 19 | public void create() |
| 20 | { |
| 21 | seteuid(getuid(ME)); |
| 22 | if ( !restore_object(SIN_SAVE) ) |
| 23 | sins = ([]); |
| 24 | } |
| 25 | |
| 26 | static void save_me() |
| 27 | { |
| 28 | save_object(SIN_SAVE); |
| 29 | } |
| 30 | |
| 31 | private varargs int is_allowed(int archonly) |
| 32 | { |
| 33 | if (previous_object() && geteuid(previous_object())==ROOTID) |
| 34 | return 1; |
| 35 | if (!process_call() && previous_object() && this_interactive() && (ARCH_SECURITY || (!archonly && IS_DEPUTY(secure_euid())) ) ) |
| 36 | return 1; |
| 37 | return 0; |
| 38 | } |
| 39 | |
| 40 | public nomask int query_prevent_shadow() |
| 41 | { |
| 42 | return 1; |
| 43 | } |
| 44 | |
| 45 | public string ListSinners() |
| 46 | { string *names; |
| 47 | |
| 48 | if ( !is_allowed() ) |
| 49 | return "ACCESS DENIED\n"; |
| 50 | |
| 51 | if ( sizeof(names=m_indices(sins))<1 ) |
| 52 | return "Es sind keine Eintraege vorhanden.\n"; |
| 53 | |
| 54 | names = sort_array( map( names, #'capitalize ), #'> ); |
| 55 | |
| 56 | return sprintf("Liste der eingetragenen Suender:\n%#78.6s\n", |
| 57 | implode(names,"\n")); |
| 58 | } |
| 59 | |
| 60 | public string ListSins(string who) |
| 61 | { string re; |
| 62 | int i,j; |
| 63 | |
| 64 | if ( !is_allowed() ) |
| 65 | return "ACCESS DENIED\n"; |
| 66 | |
| 67 | if ( !stringp(who) || (sizeof(who)<1) ) |
| 68 | return "SYNTAX ERROR.\n"; |
| 69 | |
| 70 | if ( !member(sins,who) || !pointerp(sins[who]) || ((j=sizeof(sins[who]))<1) ) |
| 71 | return sprintf("Es liegen keine Eintraege fuer '%s' vor.\n",CAP(who)); |
| 72 | |
| 73 | for ( i=1, re = ((string)sins[who][0]+"\n") ; i<j ; i++ ) |
| 74 | re += sprintf("%3d: %s\n",i,(string)sins[who][i]); |
| 75 | |
| 76 | return re; |
| 77 | } |
| 78 | |
| 79 | static void _add_entry(string who, string entry, object pl) |
| 80 | { string *add; |
| 81 | |
| 82 | if ( member(sins,who) && pointerp(sins[who]) && (sizeof(sins[who])>0) ) |
| 83 | add = (string*)sins[who]; |
| 84 | else |
| 85 | add = ({ sprintf("Eintraege fuer '%s':",CAP(who)) }); |
| 86 | |
| 87 | add += ({ entry }); |
| 88 | |
| 89 | sins[who] = add; |
| 90 | |
| 91 | save_me(); |
| 92 | |
| 93 | log_file(SIN_LOG, |
| 94 | sprintf("%s Eintrag fuer %s von %s\n", |
| 95 | dtime(time()),CAP(who),CAP(getuid(pl)) ) ); |
| 96 | } |
| 97 | |
| 98 | public string AddSin(string who, string text) |
| 99 | { object pl; |
| 100 | string ersti; |
| 101 | |
| 102 | if ( !is_allowed() ) |
| 103 | return "ACCESS DENIED\n"; |
| 104 | |
| 105 | if ( !stringp(who) || (sizeof(who)<1) |
| 106 | || !stringp(text) || (sizeof(text)<1) ) |
| 107 | return "SYNTAX ERROR.\n"; |
| 108 | |
| 109 | if ( text[0..2]=="-f " ) |
| 110 | text=text[3..]; |
| 111 | else if ( file_size(sprintf("/save/%s/%s.o",who[0..0],who))<1) |
| 112 | return sprintf("Es gibt keinen Spieler namens '%s'\n",who); |
| 113 | |
| 114 | text = dtime(time()) + " ("+CAP(getuid(RPL))+")\n" |
| 115 | + break_string(text,78," " ); |
| 116 | |
| 117 | _add_entry( who, text, RPL ); |
| 118 | |
| 119 | if ( objectp(pl=(find_player(who)||find_netdead(who))) |
| 120 | && !IS_WIZARD(pl) // Magier haben manchmal komische Ersties ... |
| 121 | && stringp(ersti=(string)pl->QueryProp(P_SECOND)) ) |
| 122 | { |
| 123 | return ( sprintf("Ok.\nFuege Eintrag bei Ersti '%s' hinzu.\n",ersti) |
| 124 | + AddSin( lower_case(ersti), ("-f siehe "+who) ) ); |
| 125 | } |
| 126 | |
| 127 | return "OK.\n"; |
| 128 | } |
| 129 | |
| 130 | public string RemoveSin(string who, int nr) |
| 131 | { string *rem; |
| 132 | |
| 133 | if ( !is_allowed(1) ) |
| 134 | return "ACCESS DENIED\n"; |
| 135 | |
| 136 | if ( !intp(nr) || (nr<1) || !stringp(who) || (sizeof(who)<1) ) |
| 137 | return "SYNTAX ERROR.\n"; |
| 138 | |
| 139 | if ( !member(sins,who) || !pointerp(sins[who]) || (sizeof(sins[who])<1) ) |
| 140 | return sprintf("FEHLER: Keine Eintraege fuer '%s' vorhanden.\n", |
| 141 | CAP(who)); |
| 142 | |
| 143 | rem = (string*)sins[who]; |
| 144 | |
| 145 | if ( sizeof(rem)<=nr ) |
| 146 | return "FEHLER: Diesen Eintrag gibt es nicht.\n"; |
| 147 | |
| 148 | rem[nr] = 0; |
| 149 | |
| 150 | rem -= ({ 0 }); |
| 151 | |
| 152 | log_file(SIN_LOG, |
| 153 | sprintf("%s Loeschung bei %s von %s\n", |
| 154 | dtime(time()),CAP(who),CAP(getuid(RPL)) ) ); |
| 155 | |
| 156 | |
| 157 | if ( sizeof(rem)<2 ) |
| 158 | { |
| 159 | m_delete(sins,who); |
| 160 | save_me(); |
| 161 | return sprintf("Letzten Eintrag von '%s' geloescht.\n",CAP(who)); |
| 162 | } |
| 163 | |
| 164 | sins[who] = rem; |
| 165 | save_me(); |
| 166 | |
| 167 | return sprintf("Eintrag %d von '%s' geloescht.\n",nr,CAP(who)); |
| 168 | } |
| 169 | |
| 170 | public varargs string Dump(int flag) |
| 171 | { string *snr,*sns,dump; |
| 172 | int i,j,k,s,t; |
| 173 | |
| 174 | if ( !is_allowed(0) ) |
| 175 | return "ACCESS DENIED\n"; |
| 176 | |
| 177 | if ( !flag && file_size(SIN_DUMP)>1 ) |
| 178 | rm( SIN_DUMP ); |
| 179 | |
| 180 | s=i=sizeof(snr=sort_array(m_indices(sins),#'<)); |
| 181 | |
| 182 | if ( i<1 ) |
| 183 | return "Keine Suender da.\n"; |
| 184 | |
| 185 | dump = sprintf("\n%|78s\n%'='78.78s\n\n", |
| 186 | sprintf("Dump der Suenden-Eintraege (%s):",dtime(time())), |
| 187 | ""); |
| 188 | |
| 189 | for ( --i,t=0 ; i>=0 ; i-- ) |
| 190 | { |
| 191 | j = sizeof(sns=sins[snr[i]]); |
| 192 | t += (j-1); |
| 193 | dump += (sns[0]+"\n\n"); |
| 194 | |
| 195 | for ( k=1 ; k<j ; k++ ) |
| 196 | dump += sprintf("%3d: %s\n",k,sns[k]); |
| 197 | |
| 198 | dump += sprintf("%'='78.78s\n\n",""); |
| 199 | } |
| 200 | |
| 201 | dump += sprintf("Statistik:\n\n"+ |
| 202 | " Es sind %d Suender mit insges. %d Eintraegen vorhanden.\n"+ |
| 203 | " Das macht einen Schnitt von %.6f Eintraegen.\n\n", |
| 204 | s,t,( to_float(t)/to_float(s) )); |
| 205 | |
| 206 | if ( !flag ) |
| 207 | { |
| 208 | write_file(SIN_DUMP,dump); |
| 209 | return sprintf("Es wurden %d Suender gedumped.\n",s); |
| 210 | |
| 211 | } |
| 212 | return dump; |
| 213 | } |