MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 1 | #pragma no_shadow, no_inherit |
| 2 | #pragma strong_types,save_types,rtt_checks |
| 3 | #pragma pedantic,range_check,warn_deprecated |
| 4 | #pragma warn_empty_casts,warn_missing_return,warn_function_inconsistent |
| 5 | |
Zesstra | d39f73d | 2018-11-09 00:01:15 +0100 | [diff] [blame] | 6 | inherit "/std/secure_thing"; |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 7 | |
| 8 | #include <properties.h> |
| 9 | #include <defines.h> |
| 10 | |
| 11 | #define BARCHIV "/d/erzmagier/boing/balance/barchives" |
| 12 | |
| 13 | #define BS(x) break_string(x,78,0,BS_LEAVE_MY_LFS) |
Arathorn | 32fe179 | 2019-09-15 14:40:47 +0200 | [diff] [blame] | 14 | #define BSI(x) break_string(x, 78, y, BS_LEAVE_MY_LFS|BS_INDENT_ONCE) |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 15 | |
Arathorn | e75740c | 2019-09-15 14:43:55 +0200 | [diff] [blame] | 16 | private varargs void print_map(mapping tmp,int cutoff); |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 17 | |
| 18 | protected void create() |
| 19 | { |
| 20 | ::create(); |
| 21 | SetProp(P_NAME,"Balance-Tool"); |
Bugfix | efe25e9 | 2016-07-29 13:14:01 +0200 | [diff] [blame] | 22 | SetProp(P_AUTOLOADOBJ,1); |
Arathorn | 8205896 | 2018-01-05 23:42:05 +0100 | [diff] [blame] | 23 | SetProp(P_NODROP,1); |
| 24 | SetProp(P_NEVERDROP,1); |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 25 | AddId(({"btool","balancetool","balance-tool"})); |
| 26 | SetProp(P_SHORT,"Ein Balance-Tool light"); |
| 27 | SetProp(P_LONG, |
Arathorn | 32fe179 | 2019-09-15 14:40:47 +0200 | [diff] [blame] | 28 | BS("Dies ist das Balance-Tool light. Es versteht folgende Befehle:")+ |
| 29 | BSI("btop <n>:\nZeigt den letzten genehmigten Antrag zu Top n.","- ")+ |
| 30 | BSI("bsuch [-s] <str>:\nSucht case-sensitiv nach str, -s bricht jeden " |
| 31 | "Eintrag nach 78 Zeichen ab. str darf eine RegExp sein.", "- ")+ |
| 32 | BSI("binhalt [-s] [uid]:\nZeigt den gesamten Inhalt des Balancearchives, " |
| 33 | "-s bricht jeden Eintrag nach 78 Zeichen ab, uid filtert auf " |
| 34 | "_vollstaendige_ uids.", "- ")+"\n"+ |
| 35 | BS("Es kann vorkommen, dass Eintraege der falschen UID zugeordnet sind, " |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 36 | "oder dass die Genehmigung nicht sehr aussagekraeftig ist, in diesem " |
| 37 | "Fall bitte eine Mail an das Balanceteam schreiben.")); |
| 38 | AddCmd("btop", |
| 39 | function int(string str) |
| 40 | { |
| 41 | int n; |
| 42 | if(!str || sscanf(str,"%d",n)!=1) |
| 43 | { |
| 44 | notify_fail( |
| 45 | BS("Syntax: btop <n>")); |
| 46 | return 0; |
| 47 | } |
| 48 | this_interactive()->ReceiveMsg( |
| 49 | BARCHIV->GetLightAnnounce(n), |
| 50 | MT_NOTIFICATION|MSG_BS_LEAVE_LFS); |
| 51 | return 1; |
| 52 | }); |
| 53 | AddCmd("bsuch", |
| 54 | function int() |
| 55 | { |
| 56 | string str=this_interactive()->_unparsed_args(); |
| 57 | if(!str || !sizeof(str)) |
| 58 | { |
| 59 | notify_fail( |
Arathorn | 3d137ba | 2019-09-15 14:59:25 +0200 | [diff] [blame^] | 60 | BS("Syntax: bsuch [-s] <str>")); |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 61 | return 0; |
| 62 | } |
Arathorn | e75740c | 2019-09-15 14:43:55 +0200 | [diff] [blame] | 63 | int cutoff; |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 64 | string* arr=old_explode(str," "); |
Arathorn | 3d137ba | 2019-09-15 14:59:25 +0200 | [diff] [blame^] | 65 | |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 66 | if(arr[0]=="-s") |
| 67 | { |
Arathorn | e75740c | 2019-09-15 14:43:55 +0200 | [diff] [blame] | 68 | cutoff=1; |
Arathorn | 3d137ba | 2019-09-15 14:59:25 +0200 | [diff] [blame^] | 69 | if (sizeof(arr)>=2) |
| 70 | { |
| 71 | str=implode(arr[1..]," "); |
| 72 | } |
| 73 | else |
| 74 | { |
| 75 | this_interactive()->ReceiveMsg( |
| 76 | "Kein Suchmuster angegeben.", |
| 77 | MT_NOTIFICATION); |
| 78 | return 1; |
| 79 | } |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 80 | } |
| 81 | mapping tmp=BARCHIV->SearchIndex(str); |
| 82 | if(!sizeof(tmp)) |
| 83 | { |
| 84 | this_interactive()->ReceiveMsg( |
| 85 | "Keine Eintraege gefunden.", |
| 86 | MT_NOTIFICATION); |
| 87 | } |
| 88 | else |
| 89 | { |
Arathorn | e75740c | 2019-09-15 14:43:55 +0200 | [diff] [blame] | 90 | print_map(tmp,cutoff); |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 91 | } |
| 92 | return 1; |
| 93 | }); |
| 94 | AddCmd("binhalt", |
| 95 | function int(string str) |
| 96 | { |
Arathorn | e75740c | 2019-09-15 14:43:55 +0200 | [diff] [blame] | 97 | int cutoff; |
Bugfix | ed43184 | 2016-07-29 12:46:05 +0200 | [diff] [blame] | 98 | string check; |
| 99 | |
| 100 | mapping tmp=BARCHIV->GetIndexForWizards(); |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 101 | if(sizeof(str)) |
| 102 | { |
| 103 | string* arr=old_explode(str," "); |
| 104 | |
| 105 | if(arr[0]=="-s") |
| 106 | { |
Arathorn | e75740c | 2019-09-15 14:43:55 +0200 | [diff] [blame] | 107 | cutoff=1; |
Bugfix | ed43184 | 2016-07-29 12:46:05 +0200 | [diff] [blame] | 108 | if(sizeof(arr)>=2) |
| 109 | { |
| 110 | check=arr[1]; |
| 111 | } |
| 112 | } |
| 113 | else |
| 114 | { |
| 115 | check=arr[0]; |
| 116 | } |
| 117 | |
| 118 | if(sizeof(check)) |
| 119 | { |
| 120 | tmp=filter(tmp, |
Bugfix | e75df3c | 2016-07-29 13:11:21 +0200 | [diff] [blame] | 121 | function int(int key, <int|string>* values) |
Bugfix | ed43184 | 2016-07-29 12:46:05 +0200 | [diff] [blame] | 122 | { |
Bugfix | e75df3c | 2016-07-29 13:11:21 +0200 | [diff] [blame] | 123 | return values[2]==check; |
Bugfix | ed43184 | 2016-07-29 12:46:05 +0200 | [diff] [blame] | 124 | }); |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 125 | } |
| 126 | } |
Arathorn | e75740c | 2019-09-15 14:43:55 +0200 | [diff] [blame] | 127 | |
| 128 | print_map(tmp,cutoff); |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 129 | return 1; |
| 130 | }); |
| 131 | } |
| 132 | |
Arathorn | e75740c | 2019-09-15 14:43:55 +0200 | [diff] [blame] | 133 | private varargs void print_map(mapping tmp,int cutoff) |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 134 | { |
Arathorn | 965dcc0 | 2019-09-15 14:58:34 +0200 | [diff] [blame] | 135 | if (!mappingp(tmp) || !sizeof(tmp)) |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 136 | { |
| 137 | this_interactive()->ReceiveMsg("Keine Daten vorhanden.\n"); |
| 138 | return; |
| 139 | } |
| 140 | int* sort=sort_array(m_indices(tmp),#'>); |
| 141 | string ret=""; |
| 142 | foreach(int i : sort) |
| 143 | { |
| 144 | string str=sprintf(" %4d: %s {%s} (%s)",i,tmp[i,0],tmp[i,2], |
| 145 | strftime("%d.%m.%y",tmp[i,1])); |
Arathorn | e75740c | 2019-09-15 14:43:55 +0200 | [diff] [blame] | 146 | if(cutoff) |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 147 | { |
| 148 | ret+=BS(str[0..77]); |
| 149 | } |
| 150 | else |
| 151 | { |
| 152 | ret+=BS(str); |
| 153 | } |
| 154 | } |
| 155 | this_interactive()->More(ret); |
| 156 | } |