blob: b11bff76ab0a4c7c7fc14533debf3f868bd174de [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 }
Bugfix5babf782022-01-10 15:58:50 +010048 this_interactive()->More(
49 BS(BARCHIV->GetLightAnnounce(n)));
MG Mud User88f12472016-06-24 23:31:02 +020050 return 1;
51 });
52 AddCmd("bsuch",
53 function int()
54 {
55 string str=this_interactive()->_unparsed_args();
56 if(!str || !sizeof(str))
57 {
58 notify_fail(
Arathorn3d137ba2019-09-15 14:59:25 +020059 BS("Syntax: bsuch [-s] <str>"));
MG Mud User88f12472016-06-24 23:31:02 +020060 return 0;
61 }
Arathorne75740c2019-09-15 14:43:55 +020062 int cutoff;
MG Mud User88f12472016-06-24 23:31:02 +020063 string* arr=old_explode(str," ");
Arathorn3d137ba2019-09-15 14:59:25 +020064
MG Mud User88f12472016-06-24 23:31:02 +020065 if(arr[0]=="-s")
66 {
Arathorne75740c2019-09-15 14:43:55 +020067 cutoff=1;
Arathorn3d137ba2019-09-15 14:59:25 +020068 if (sizeof(arr)>=2)
69 {
70 str=implode(arr[1..]," ");
71 }
72 else
73 {
74 this_interactive()->ReceiveMsg(
75 "Kein Suchmuster angegeben.",
76 MT_NOTIFICATION);
77 return 1;
78 }
MG Mud User88f12472016-06-24 23:31:02 +020079 }
80 mapping tmp=BARCHIV->SearchIndex(str);
81 if(!sizeof(tmp))
82 {
83 this_interactive()->ReceiveMsg(
84 "Keine Eintraege gefunden.",
85 MT_NOTIFICATION);
86 }
87 else
88 {
Arathorne75740c2019-09-15 14:43:55 +020089 print_map(tmp,cutoff);
MG Mud User88f12472016-06-24 23:31:02 +020090 }
91 return 1;
92 });
93 AddCmd("binhalt",
94 function int(string str)
95 {
Arathorne75740c2019-09-15 14:43:55 +020096 int cutoff;
Bugfixed431842016-07-29 12:46:05 +020097 string check;
98
99 mapping tmp=BARCHIV->GetIndexForWizards();
MG Mud User88f12472016-06-24 23:31:02 +0200100 if(sizeof(str))
101 {
102 string* arr=old_explode(str," ");
103
104 if(arr[0]=="-s")
105 {
Arathorne75740c2019-09-15 14:43:55 +0200106 cutoff=1;
Bugfixed431842016-07-29 12:46:05 +0200107 if(sizeof(arr)>=2)
108 {
109 check=arr[1];
110 }
111 }
112 else
113 {
114 check=arr[0];
115 }
116
117 if(sizeof(check))
118 {
119 tmp=filter(tmp,
Bugfixe75df3c2016-07-29 13:11:21 +0200120 function int(int key, <int|string>* values)
Bugfixed431842016-07-29 12:46:05 +0200121 {
Bugfixe75df3c2016-07-29 13:11:21 +0200122 return values[2]==check;
Bugfixed431842016-07-29 12:46:05 +0200123 });
MG Mud User88f12472016-06-24 23:31:02 +0200124 }
125 }
Arathorne75740c2019-09-15 14:43:55 +0200126
127 print_map(tmp,cutoff);
MG Mud User88f12472016-06-24 23:31:02 +0200128 return 1;
129 });
130}
131
Arathorne7ef31e2019-09-15 15:02:15 +0200132#define B_SUBJECT 0
133#define B_TIME 1
134#define B_UID 2
135
Arathorn8f3cccb2019-09-24 19:33:37 +0200136private varargs void print_map(mapping tmp, int cutoff)
MG Mud User88f12472016-06-24 23:31:02 +0200137{
Arathorn965dcc02019-09-15 14:58:34 +0200138 if (!mappingp(tmp) || !sizeof(tmp))
MG Mud User88f12472016-06-24 23:31:02 +0200139 {
140 this_interactive()->ReceiveMsg("Keine Daten vorhanden.\n");
141 return;
142 }
Arathorn523359a2019-09-15 15:00:17 +0200143
Arathorn8f3cccb2019-09-24 19:33:37 +0200144 string ret = "";
145 string topic;
146
147 // Kein automatisch ausgehandelter Wert vorhanden? Dann Default setzen.
148 int cols = (PL->QueryProp(P_TTY_COLS) || 78);
149 // War ein Wert gesetzt, aber < 35 (was der Mindestwert bei Auto-
150 // Negotiation ist), dann auf 35 begrenzen.
151 cols = max(cols, 35);
152
153 // Auf die fuers Subject verfuegbare Breite kuerzen: 7 Zeichen fuer die
154 // BTOP-Nummer abziehen und ein bisschen was als Puffer am rechten Rand
155 // des Terminals. Erfahrungsgemaess melden Clients oft mehr Zeichen als
156 // Terminbreite als sie darstellen, so dass wir das hier kompensieren
157 // muessen.
158 cols -= 10;
159
Arathorne7ef31e2019-09-15 15:02:15 +0200160 foreach(int i : sort_array(m_indices(tmp),#'>))
MG Mud User88f12472016-06-24 23:31:02 +0200161 {
Arathorn8f3cccb2019-09-24 19:33:37 +0200162 topic = sprintf("%s {%s} (%s)",
163 regreplace(tmp[i,B_SUBJECT], " \\[angenommen\\]", "", 1),
164 tmp[i,B_UID],
165 strftime("%d.%m.%Y", tmp[i,B_TIME]));
166 if (cutoff)
167 ret += sprintf(" %4d: %-.*s\n", i, cols, topic);
MG Mud User88f12472016-06-24 23:31:02 +0200168 else
Arathorn8f3cccb2019-09-24 19:33:37 +0200169 ret += sprintf(" %4d: %=-*s\n", i, cols, topic);
MG Mud User88f12472016-06-24 23:31:02 +0200170 }
171 this_interactive()->More(ret);
172}