blob: 93d2d85ff25c929ed3da497807eff2b80e431126 [file] [log] [blame]
MG Mud User88f12472016-06-24 23:31:02 +02001#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
Zesstrad39f73d2018-11-09 00:01:15 +01006inherit "/std/secure_thing";
MG Mud User88f12472016-06-24 23:31:02 +02007
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)
Arathorna5f91522019-09-23 21:37:03 +020014#define BSI(x, y) break_string(x, 78, y, BS_LEAVE_MY_LFS|BS_INDENT_ONCE)
MG Mud User88f12472016-06-24 23:31:02 +020015
Arathorne75740c2019-09-15 14:43:55 +020016private varargs void print_map(mapping tmp,int cutoff);
MG Mud User88f12472016-06-24 23:31:02 +020017
18protected void create()
19{
20 ::create();
21 SetProp(P_NAME,"Balance-Tool");
Bugfixefe25e92016-07-29 13:14:01 +020022 SetProp(P_AUTOLOADOBJ,1);
Arathorn82058962018-01-05 23:42:05 +010023 SetProp(P_NODROP,1);
24 SetProp(P_NEVERDROP,1);
MG Mud User88f12472016-06-24 23:31:02 +020025 AddId(({"btool","balancetool","balance-tool"}));
26 SetProp(P_SHORT,"Ein Balance-Tool light");
27 SetProp(P_LONG,
Arathorn32fe1792019-09-15 14:40:47 +020028 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 User88f12472016-06-24 23:31:02 +020036 "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(
Arathorn3d137ba2019-09-15 14:59:25 +020060 BS("Syntax: bsuch [-s] <str>"));
MG Mud User88f12472016-06-24 23:31:02 +020061 return 0;
62 }
Arathorne75740c2019-09-15 14:43:55 +020063 int cutoff;
MG Mud User88f12472016-06-24 23:31:02 +020064 string* arr=old_explode(str," ");
Arathorn3d137ba2019-09-15 14:59:25 +020065
MG Mud User88f12472016-06-24 23:31:02 +020066 if(arr[0]=="-s")
67 {
Arathorne75740c2019-09-15 14:43:55 +020068 cutoff=1;
Arathorn3d137ba2019-09-15 14:59:25 +020069 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 User88f12472016-06-24 23:31:02 +020080 }
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 {
Arathorne75740c2019-09-15 14:43:55 +020090 print_map(tmp,cutoff);
MG Mud User88f12472016-06-24 23:31:02 +020091 }
92 return 1;
93 });
94 AddCmd("binhalt",
95 function int(string str)
96 {
Arathorne75740c2019-09-15 14:43:55 +020097 int cutoff;
Bugfixed431842016-07-29 12:46:05 +020098 string check;
99
100 mapping tmp=BARCHIV->GetIndexForWizards();
MG Mud User88f12472016-06-24 23:31:02 +0200101 if(sizeof(str))
102 {
103 string* arr=old_explode(str," ");
104
105 if(arr[0]=="-s")
106 {
Arathorne75740c2019-09-15 14:43:55 +0200107 cutoff=1;
Bugfixed431842016-07-29 12:46:05 +0200108 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,
Bugfixe75df3c2016-07-29 13:11:21 +0200121 function int(int key, <int|string>* values)
Bugfixed431842016-07-29 12:46:05 +0200122 {
Bugfixe75df3c2016-07-29 13:11:21 +0200123 return values[2]==check;
Bugfixed431842016-07-29 12:46:05 +0200124 });
MG Mud User88f12472016-06-24 23:31:02 +0200125 }
126 }
Arathorne75740c2019-09-15 14:43:55 +0200127
128 print_map(tmp,cutoff);
MG Mud User88f12472016-06-24 23:31:02 +0200129 return 1;
130 });
131}
132
Arathorne7ef31e2019-09-15 15:02:15 +0200133#define B_SUBJECT 0
134#define B_TIME 1
135#define B_UID 2
136
Arathorn8f3cccb2019-09-24 19:33:37 +0200137private varargs void print_map(mapping tmp, int cutoff)
MG Mud User88f12472016-06-24 23:31:02 +0200138{
Arathorn965dcc02019-09-15 14:58:34 +0200139 if (!mappingp(tmp) || !sizeof(tmp))
MG Mud User88f12472016-06-24 23:31:02 +0200140 {
141 this_interactive()->ReceiveMsg("Keine Daten vorhanden.\n");
142 return;
143 }
Arathorn523359a2019-09-15 15:00:17 +0200144
Arathorn8f3cccb2019-09-24 19:33:37 +0200145 string ret = "";
146 string topic;
147
148 // Kein automatisch ausgehandelter Wert vorhanden? Dann Default setzen.
149 int cols = (PL->QueryProp(P_TTY_COLS) || 78);
150 // War ein Wert gesetzt, aber < 35 (was der Mindestwert bei Auto-
151 // Negotiation ist), dann auf 35 begrenzen.
152 cols = max(cols, 35);
153
154 // Auf die fuers Subject verfuegbare Breite kuerzen: 7 Zeichen fuer die
155 // BTOP-Nummer abziehen und ein bisschen was als Puffer am rechten Rand
156 // des Terminals. Erfahrungsgemaess melden Clients oft mehr Zeichen als
157 // Terminbreite als sie darstellen, so dass wir das hier kompensieren
158 // muessen.
159 cols -= 10;
160
Arathorne7ef31e2019-09-15 15:02:15 +0200161 foreach(int i : sort_array(m_indices(tmp),#'>))
MG Mud User88f12472016-06-24 23:31:02 +0200162 {
Arathorn8f3cccb2019-09-24 19:33:37 +0200163 topic = sprintf("%s {%s} (%s)",
164 regreplace(tmp[i,B_SUBJECT], " \\[angenommen\\]", "", 1),
165 tmp[i,B_UID],
166 strftime("%d.%m.%Y", tmp[i,B_TIME]));
167 if (cutoff)
168 ret += sprintf(" %4d: %-.*s\n", i, cols, topic);
MG Mud User88f12472016-06-24 23:31:02 +0200169 else
Arathorn8f3cccb2019-09-24 19:33:37 +0200170 ret += sprintf(" %4d: %=-*s\n", i, cols, topic);
MG Mud User88f12472016-06-24 23:31:02 +0200171 }
172 this_interactive()->More(ret);
173}