MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 1 | // channeld.c |
| 2 | // |
| 3 | // $Id: channeld.c 9138 2015-02-03 21:46:56Z Zesstra $ |
| 4 | // |
| 5 | |
| 6 | #pragma strong_types |
| 7 | #pragma no_shadow // keine Shadowing... |
| 8 | #pragma no_clone |
| 9 | #pragma no_inherit |
| 10 | #pragma save_types |
| 11 | |
| 12 | #include <sys_debug.h> |
| 13 | #include <lpctypes.h> |
| 14 | #include <wizlevels.h> |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 15 | #include <regexp.h> |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 16 | |
| 17 | #include <properties.h> |
| 18 | #include <config.h> |
| 19 | #include <language.h> |
| 20 | |
| 21 | #define NEED_PROTOTYPES |
| 22 | #include "channel.h" |
| 23 | |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 24 | #define CHANNEL_SAVE "/p/daemon/save/channeld" |
| 25 | #define MEMORY "/secure/memory" |
| 26 | #define MAX_HIST_SIZE 200 |
| 27 | #define MAX_CHANNELS 90 |
| 28 | #define CMDS ({C_FIND, C_LIST, C_JOIN, C_LEAVE, C_SEND, C_NEW}) |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 29 | |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 30 | |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 31 | // Datenstrukturen fuer die Ebenen. |
| 32 | // Basisdaten, welche auch inaktive Ebenen in channelC haben |
| 33 | struct channel_base_s { |
| 34 | string name; // readable channelname, case-sensitive |
| 35 | string|closure desc; // stat. oder dyn. Beschreibung |
| 36 | string creator; // Ersteller der Ebene (Objektname) |
| 37 | // int flags; // Flags, die weiteres Verhalten steuern. |
| 38 | }; |
| 39 | |
| 40 | // Basisdaten + die von aktiven Ebenen |
| 41 | struct channel_s (channel_base_s) { |
| 42 | object|string supervisor; // aktueller Supervisor der Ebene |
| 43 | closure access_cl; // Closure fuer Zugriffsrechtepruefung |
| 44 | object *members; // Zuhoerer der Ebene |
| 45 | }; |
| 46 | |
| 47 | /* Ebenenliste und die zugehoerigen Daten in struct (<channel>). |
| 48 | channels = ([string channelname : (<channel_s>) ]) |
Zesstra | 7831001 | 2020-08-09 12:21:48 +0200 | [diff] [blame] | 49 | */ |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 50 | private nosave mapping channels = ([]); |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 51 | |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 52 | /* Ebenenhistory |
| 53 | mapping channelH = ([ string channelname : ({ ({string channelname, |
| 54 | string sender, |
| 55 | string msg, |
| 56 | int msg_type}) }) ]) */ |
| 57 | // channelH wird in create() geeignet initialisiert |
| 58 | // HINWEIS: Bitte beachten, dass channelH immer nur so manipuliert werden |
| 59 | // darf, dass keine Kopie erstellt wird, weder direkt noch implizit. Die |
| 60 | // History wird via Referenz in /secure/memory hinterlegt, damit sie einen |
| 61 | // Reload des Channeld ueberlebt. Das funktioniert aber nur, wenn die Mapping- |
| 62 | // Referenz in Memory und Channeld dieselbe ist. |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 63 | private nosave mapping channelH; |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 64 | |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 65 | /* Globale channeld-Stats (Startzeit, geladen von, Anzahl erstellte und |
| 66 | zerstoerte Ebenen. |
| 67 | mapping stats = ([ "time" : int object_time(), |
| 68 | "boot" : string getuid(previous_object()), |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 69 | "new" : int total_channels_created, |
| 70 | "disposed" : int total_channels_removed ]) */ |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 71 | // stats wird in create() geeignet initialisiert |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 72 | private nosave mapping stats; |
| 73 | |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 74 | /* Ebenen-Cache, enthaelt Daten zu inaktiven Ebenen. |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 75 | mapping channelC = ([ string channelname : (<channel_base_s>); |
| 76 | int time() ]) |
| 77 | Der Zeitstempel ist die letzte Aenderung, d.h. in der Regel des Ablegens in |
| 78 | channelC. |
| 79 | */ |
| 80 | private mapping channelC = ([:2]); |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 81 | |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 82 | /* Liste von Spielern, fuer die ein Bann besteht, mit den verbotenen Kommandos |
| 83 | mapping channelB = ([ string playername : string* banned_command ]) */ |
| 84 | private mapping channelB = ([]); |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 85 | |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 86 | /* Timeout-Liste der Datenabfrage-Kommandos; die Timestamps werden verwendet, |
| 87 | um sicherzustellen, dass jedes Kommando max. 1x pro Minute benutzt werden |
| 88 | kann. |
| 89 | |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 90 | mapping Tcmd = ([ "lag": int timestamp, |
| 91 | "uptime": int timestamp, |
| 92 | "statistik": int timestamp]) */ |
| 93 | private mapping Tcmd = ([]); |
| 94 | |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 95 | /* Flag, das anzeigt, dass Daten veraendert wurden und beim naechsten |
| 96 | Speicherevent das Savefile geschrieben werden soll. |
| 97 | Wird auf 0 oder 1 gesetzt. */ |
Zesstra | a2db552 | 2020-08-11 22:14:55 +0200 | [diff] [blame] | 98 | private nosave int save_me_soon; |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 99 | |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 100 | |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 101 | // BEGIN OF THE CHANNEL MASTER ADMINISTRATIVE PART |
| 102 | |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 103 | // Indizes fuer Zugriffe auf das Mapping <admin>. |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 104 | #define RECV 0 |
| 105 | #define SEND 1 |
| 106 | #define FLAG 2 |
| 107 | |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 108 | // Ebenenflags, gespeichert in admin[ch, FLAG] |
| 109 | // F_WIZARD kennzeichnet reine Magierebenen |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 110 | #define F_WIZARD 1 |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 111 | // Ebenen, auf denen keine Gaeste erlaubt sind, sind mit F_NOGUEST markiert. |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 112 | #define F_NOGUEST 2 |
| 113 | |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 114 | /* Speichert Sende- und Empfangslevel sowie Flags zu den einzelnen Channeln. |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 115 | * Diese werden aber nur ausgewertet, wenn der Channeld die Rechtepruefung |
| 116 | * fuer die jeweilige Ebene macht, d.h. in der Praxis bei Ebenen, bei denen |
| 117 | * der CHANNELD der Supervisor ist. |
| 118 | * Deswegen sind diese Daten auch nicht in der struct (<channel_s>) drin. |
| 119 | * Wird beim Laden des Masters via create() -> initalize() -> setup() mit den |
| 120 | * Daten aus dem Init-File ./channeld.init befuellt. |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 121 | mapping admin = ([ string channel_name : int RECV_LVL, |
| 122 | int SEND_LVL, |
| 123 | int FLAG ]) */ |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 124 | private nosave mapping admin = m_allocate(0, 3); |
| 125 | |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 126 | // check_ch_access() prueft die Zugriffsberechtigungen auf Ebenen. |
| 127 | // |
| 128 | // Gibt 1 zurueck, wenn Aktion erlaubt, 0 sonst. |
| 129 | // Wird von access() gerufen; access() gibt das Ergebnis von |
| 130 | // check_ch_access() zurueck. |
| 131 | // |
| 132 | // Verlassen (C_LEAVE) ist immer erlaubt. Die anderen Aktionen sind in zwei |
| 133 | // Gruppen eingeteilt: |
| 134 | // 1) RECV. Die Aktionen dieser Gruppe sind Suchen (C_FIND), Auflisten |
| 135 | // (C_LIST) und Betreten (C_JOIN). |
| 136 | // 2) SEND. Die Aktion dieser Gruppe ist zur Zeit nur Senden (C_SEND). |
| 137 | // |
| 138 | // Aktionen werden zugelassen, wenn Spieler/MagierLevel groesser ist als die |
| 139 | // fuer die jeweilige Aktionsgruppe RECV oder SEND festgelegte Stufe. |
| 140 | // Handelt es sich um eine Magierebene (F_WIZARD), muss die Magierstufe |
| 141 | // des Spielers groesser sein als die Mindeststufe der Ebene. Ansonsten |
| 142 | // wird gegen den Spielerlevel geprueft. |
| 143 | // |
| 144 | // Wenn RECV_LVL oder SEND_LVL auf -1 gesetzt ist, sind die Aktionen der |
| 145 | // jeweiligen Gruppen komplett geblockt. |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 146 | |
Arathorn | 739a4fa | 2020-08-06 21:52:58 +0200 | [diff] [blame] | 147 | public int check_ch_access(string ch, object pl, string cmd) |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 148 | { |
| 149 | // <pl> ist Gast, es sind aber keine Gaeste zugelassen? Koennen wir |
| 150 | // direkt ablehnen. |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 151 | if ((admin[ch, FLAG] & F_NOGUEST) && pl->QueryGuest()) |
| 152 | return 0; |
| 153 | |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 154 | // Ebenso auf Magier- oder Seherebenen, wenn ein Spieler anfragt, der |
| 155 | // noch kein Seher ist. |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 156 | if ((admin[ch, FLAG] & F_WIZARD) && query_wiz_level(pl) < SEER_LVL) |
| 157 | return 0; |
| 158 | |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 159 | // Ebene ist Magierebene? Dann werden alle Stufenlimits gegen Magierlevel |
| 160 | // geprueft, ansonsten gegen Spielerlevel. |
| 161 | int level = (admin[ch, FLAG] & F_WIZARD |
| 162 | ? query_wiz_level(pl) |
| 163 | : pl->QueryProp(P_LEVEL)); |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 164 | |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 165 | switch (cmd) |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 166 | { |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 167 | case C_FIND: |
| 168 | case C_LIST: |
| 169 | case C_JOIN: |
| 170 | if (admin[ch, RECV] == -1) |
| 171 | return 0; |
| 172 | if (admin[ch, RECV] <= level) |
| 173 | return 1; |
| 174 | break; |
| 175 | |
| 176 | case C_SEND: |
| 177 | if (admin[ch, SEND] == -1) |
| 178 | return 0; |
| 179 | if (admin[ch, SEND] <= level) |
| 180 | return 1; |
| 181 | break; |
| 182 | |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 183 | // Verlassen ist immer erlaubt |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 184 | case C_LEAVE: |
| 185 | return 1; |
| 186 | |
| 187 | default: |
| 188 | break; |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 189 | } |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 190 | return (0); |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 191 | } |
| 192 | |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 193 | /* CountUsers() zaehlt die Anzahl Abonnenten aller Ebenen. */ |
| 194 | // TODO: Mapping- und Arrayvarianten bzgl. der Effizienz vergleichen |
| 195 | private int CountUsers() |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 196 | { |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 197 | object* userlist = ({}); |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 198 | foreach(string ch_name, struct channel_s ch : channels) |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 199 | { |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 200 | userlist += ch.members; |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 201 | } |
| 202 | // Das Mapping dient dazu, dass jeder Eintrag nur einmal vorkommt. |
| 203 | return sizeof(mkmapping(userlist)); |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 204 | } |
| 205 | |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 206 | // Ist das Objekt <sender> Abonnent der Ebene <ch>? |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 207 | private int IsChannelMember(struct channel_s ch, object sender) |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 208 | { |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 209 | return (member(ch.members, sender) != -1); |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 210 | } |
| 211 | |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 212 | // Besteht fuer das Objekt <ob> ein Bann fuer die Ebenenfunktion <command>? |
| 213 | private int IsBanned(string|object ob, string command) |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 214 | { |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 215 | if (objectp(ob)) |
| 216 | ob = getuid(ob); |
| 217 | return(pointerp(channelB[ob]) && |
| 218 | member(channelB[ob], command) != -1); |
| 219 | } |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 220 | |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 221 | private void banned(string plname, string* cmds, string res) |
| 222 | { |
| 223 | res += sprintf("%s [%s], ", capitalize(plname), implode(cmds, ",")); |
| 224 | } |
| 225 | |
| 226 | #define TIMEOUT (time() - 60) |
| 227 | |
| 228 | // IsNotBlocked(): prueft fuer die Liste der uebergebenen Kommandos, ob |
| 229 | // die Zeitsperre fuer alle abgelaufen ist und sie ausgefuehrt werden duerfen. |
| 230 | // Dabei gilt jedes Kommando, dessen letzte Nutzung laenger als 60 s |
| 231 | // zurueckliegt, als "nicht gesperrt". |
| 232 | private int IsNotBlocked(string* cmd) |
| 233 | { |
| 234 | string* res = filter(cmd, function int (string str) { |
| 235 | return (Tcmd[str] < TIMEOUT); |
| 236 | }); |
| 237 | // Wenn das Ergebnis-Array genauso gross ist wie das Eingabe-Array, dann |
| 238 | // sind alle Kommandos frei. Sie werden direkt gesperrt; return 1 |
| 239 | // signalisiert dem Aufrufer, dass das Kommando ausgefuehrt werden darf. |
| 240 | if (sizeof(res) == sizeof(cmd)) { |
| 241 | foreach(string str : cmd) { |
| 242 | Tcmd[str] = time(); |
| 243 | } |
| 244 | return 1; |
| 245 | } |
| 246 | return 0; |
| 247 | } |
| 248 | |
| 249 | // Prueft, ob der gesendete Befehl <cmd> als gueltiges Kommando <check> |
| 250 | // zugelassen wird. Anforderungen: |
| 251 | // 1) <cmd> muss Teilstring von <check> sein |
| 252 | // 2) <cmd> muss am Anfang von <check> stehen |
| 253 | // 3) <cmd> darf nicht laenger sein als <check> |
| 254 | // 4) die Nutzung von <cmd> darf nur einmal pro Minute erfolgen |
| 255 | // Beispiel: check = "statistik", cmd = "stat" ist gueltig, nicht aber |
| 256 | // cmd = "statistiker" oder cmd = "tist" |
| 257 | // Wenn die Syntax zugelassen wird, wird anschliessend geprueft |
| 258 | private int IsValidChannelCommand(string cmd, string check) { |
| 259 | // Syntaxcheck (prueft Bedingungen 1 bis 3). |
| 260 | if ( strstr(check, cmd)==0 && sizeof(cmd) <= sizeof(check) ) { |
| 261 | string* cmd_to_check; |
| 262 | // Beim Kombi-Kommando "lust" muessen alle 3 Befehle gecheckt werden. |
| 263 | // Der Einfachheit halber werden auch Einzelkommandos als Array ueber- |
| 264 | // geben. |
| 265 | if ( cmd == "lust" ) |
| 266 | cmd_to_check = ({"lag", "statistik", "uptime"}); |
| 267 | else |
| 268 | cmd_to_check = ({cmd}); |
| 269 | // Prueft die Zeitsperre (Bedingung 4). |
| 270 | return (IsNotBlocked(cmd_to_check)); |
| 271 | } |
| 272 | return 0; |
| 273 | } |
| 274 | |
| 275 | #define CH_NAME 0 |
| 276 | #define CH_SENDER 1 |
| 277 | #define CH_MSG 2 |
| 278 | #define CH_MSG_TYPE 3 |
| 279 | // Gibt die Channelmeldungen fuer die Kommandos up, stat, lag und bann des |
| 280 | // <MasteR>-Channels aus. Auszugebende Informationen werden in <ret> gesammelt |
| 281 | // und dieses per Callout an send() uebergeben. |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 282 | // Argument: ({channel.name, object pl, string msg, int type}) |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 283 | // Funktion muss public sein, auch wenn der erste Check im Code das Gegenteil |
| 284 | // nahezulegen scheint, weil sie von send() per call_other() gerufen wird, |
| 285 | // was aber bei einer private oder protected Funktion nicht moeglich waere. |
| 286 | public void ChannelMessage(<string|object|int>* msg) |
| 287 | { |
| 288 | // Wir reagieren nur auf Meldungen, die wir uns selbst geschickt haben, |
| 289 | // aber nur dann, wenn sie auf der Ebene <MasteR> eingegangen sind. |
| 290 | if (msg[CH_SENDER] == this_object() || !stringp(msg[CH_MSG]) || |
| 291 | msg[CH_NAME] != CMNAME || previous_object() != this_object()) |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 292 | return; |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 293 | |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 294 | float* lag; |
| 295 | int max, rekord; |
| 296 | string ret; |
Arathorn | 739a4fa | 2020-08-06 21:52:58 +0200 | [diff] [blame] | 297 | string mesg = msg[CH_MSG]; |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 298 | |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 299 | if (IsValidChannelCommand(mesg, "hilfe")) |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 300 | { |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 301 | ret = "Folgende Kommandos gibt es: hilfe, lag, uptime, statistik, lust, " |
| 302 | "bann. Die Kommandos koennen abgekuerzt werden."; |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 303 | } |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 304 | else if (IsValidChannelCommand(mesg, "lag")) |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 305 | { |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 306 | lag = "/p/daemon/lag-o-daemon"->read_ext_lag_data(); |
| 307 | ret = sprintf("Lag: %.1f%%/60, %.1f%%/15, %.1f%%/5, %.1f%%/1, " |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 308 | "%.1f%%/20s, %.1f%%/2s", |
| 309 | lag[5], lag[4], lag[3], lag[2], lag[1], lag[0]); |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 310 | // Erster Callout wird hier schon abgesetzt, um sicherzustellen, dass |
| 311 | // die Meldung in zwei Zeilen auf der Ebene erscheint. |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 312 | call_out(#'send, 2, CMNAME, this_object(), ret); |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 313 | ret = query_load_average(); |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 314 | } |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 315 | else if (IsValidChannelCommand(mesg, "uptime")) |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 316 | { |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 317 | if (file_size("/etc/maxusers") > 0 && file_size("/etc/maxusers.ever")) |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 318 | { |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 319 | string unused; |
| 320 | sscanf(read_file("/etc/maxusers"), "%d %s", max, unused); |
| 321 | sscanf(read_file("/etc/maxusers.ever"), "%d %s", rekord, unused); |
| 322 | ret = sprintf("Das MUD laeuft jetzt %s. Es sind momentan %d Spieler " |
| 323 | "eingeloggt; das Maximum lag heute bei %d und der Rekord " |
| 324 | "bisher ist %d.", uptime(), sizeof(users()), max, rekord); |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 325 | } |
| 326 | else |
| 327 | { |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 328 | ret = "Diese Information liegt nicht vor."; |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 329 | } |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 330 | } |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 331 | else if (IsValidChannelCommand(mesg, "statistik")) |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 332 | { |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 333 | ret = sprintf( |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 334 | "Im Moment sind insgesamt %d Ebenen mit %d Teilnehmern aktiv. " |
| 335 | "Der %s wurde das letzte mal am %s von %s neu gestartet. " |
| 336 | "Seitdem wurden %d Ebenen neu erzeugt und %d zerstoert.", |
| 337 | sizeof(channels), CountUsers(), CMNAME, |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 338 | dtime(stats["time"]), stats["boot"], stats["new"], stats["dispose"]); |
| 339 | } |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 340 | // Ebenenaktion beginnt mit "bann"? |
| 341 | else if (strstr(mesg, "bann")==0) |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 342 | { |
| 343 | string pl, cmd; |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 344 | |
| 345 | if (mesg == "bann") |
| 346 | { |
| 347 | if (sizeof(channelB)) |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 348 | { |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 349 | ret = "Fuer folgende Spieler besteht ein Bann: "; |
| 350 | // Zwischenspeicher fuer die Einzeleintraege, um diese spaeter mit |
| 351 | // CountUp() in eine saubere Aufzaehlung umwandeln zu koennen. |
| 352 | string* banlist = ({}); |
| 353 | foreach(string plname, string* banned_cmds : channelB) { |
| 354 | banlist += ({ sprintf("%s [%s]", |
| 355 | capitalize(plname), implode(banned_cmds, ", "))}); |
| 356 | } |
| 357 | ret = CountUp(banlist); |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 358 | } |
| 359 | else |
| 360 | { |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 361 | ret = "Zur Zeit ist kein Bann aktiv."; |
| 362 | } |
| 363 | } |
| 364 | else |
| 365 | { |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 366 | if (sscanf(mesg, "bann %s %s", pl, cmd) == 2 && |
| 367 | IS_DEPUTY(msg[CH_SENDER])) |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 368 | { |
| 369 | pl = lower_case(pl); |
| 370 | cmd = lower_case(cmd); |
| 371 | |
| 372 | if (member(CMDS, cmd) != -1) |
| 373 | { |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 374 | // Kein Eintrag fuer <pl> in der Bannliste vorhanden, dann anlegen; |
| 375 | // ist der Eintrag kein Array, ist ohnehin was faul, dann wird |
| 376 | // ueberschrieben. |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 377 | if (!pointerp(channelB[pl])) |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 378 | m_add(channelB, pl, ({})); |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 379 | |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 380 | if (IsBanned(pl, cmd)) |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 381 | channelB[pl] -= ({ cmd }); |
| 382 | else |
| 383 | channelB[pl] += ({ cmd }); |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 384 | |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 385 | ret = "Fuer '" + capitalize(pl) + "' besteht " + |
| 386 | (sizeof(channelB[pl]) |
| 387 | // TODO: implode() -> CountUp()? |
| 388 | ? "folgender Bann: " + implode(channelB[pl], ", ") + "." |
| 389 | : "kein Bann mehr."); |
| 390 | |
| 391 | // Liste der gebannten Kommandos leer? Dann <pl> komplett austragen. |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 392 | if (!sizeof(channelB[pl])) |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 393 | m_delete(channelB, pl); |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 394 | |
Zesstra | a2db552 | 2020-08-11 22:14:55 +0200 | [diff] [blame] | 395 | //TODO: save_me_soon=1 sollte auch reichen... |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 396 | save_object(CHANNEL_SAVE); |
| 397 | } |
| 398 | else |
| 399 | { |
| 400 | ret = "Das Kommando '" + cmd + "' ist unbekannt. " |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 401 | "Erlaubte Kommandos: "+ CountUp(CMDS); |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 402 | } |
| 403 | } |
| 404 | else |
| 405 | { |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 406 | if (IS_ARCH(msg[CH_SENDER])) |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 407 | ret = "Syntax: bann <name> <kommando>"; |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 408 | } |
| 409 | } |
| 410 | } |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 411 | else if (IsValidChannelCommand(mesg, "lust")) |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 412 | { |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 413 | lag = "/p/daemon/lag-o-daemon"->read_lag_data(); |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 414 | if (file_size("/etc/maxusers") > 0 && file_size("/etc/maxusers.ever")) |
| 415 | { |
| 416 | string unused; |
| 417 | sscanf(read_file("/etc/maxusers"), "%d %s", max, unused); |
| 418 | sscanf(read_file("/etc/maxusers.ever"), "%d %s", rekord, unused); |
| 419 | } |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 420 | |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 421 | int t = time() - last_reboot_time(); |
| 422 | |
| 423 | // TODO: fuer solche Anwendungen ein separates Inheritfile bauen, da |
| 424 | // die Funktionalitaet oefter benoetigt wird als nur hier. |
| 425 | string up = ""; |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 426 | if (t >= 86400) |
| 427 | up += sprintf("%dT", t / 86400); |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 428 | |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 429 | t %= 86400; |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 430 | if (t >= 3600) |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 431 | up += sprintf("%dh", t / 3600); |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 432 | |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 433 | t %= 3600; |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 434 | if (t > 60) |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 435 | up += sprintf("%dm", t / 60); |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 436 | |
| 437 | up += sprintf("%ds", t % 60); |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 438 | |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 439 | ret = sprintf("%.1f%%/15 %.1f%%/1 %s %d:%d:%d E:%d T:%d", |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 440 | lag[1], lag[2], up, sizeof(users()), max, rekord, |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 441 | sizeof(channels), CountUsers()); |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 442 | } |
| 443 | else |
| 444 | { |
| 445 | return; |
| 446 | } |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 447 | |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 448 | // Nur die Ausgabe starten, wenn ein Ausgabestring vorliegt. Es kann |
| 449 | // vorkommen, dass weiter oben keiner zugewiesen wird, weil die Bedingungen |
| 450 | // nicht erfuellt sind. |
| 451 | if (stringp(ret) && sizeof(ret)) |
| 452 | call_out(#'send, 2, CMNAME, this_object(), ret); |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 453 | } |
| 454 | |
| 455 | // setup() -- set up a channel and register it |
| 456 | // arguments are stored in the following order: |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 457 | // string* chinfo = ({ channel_name, receive_level, send_level, |
Zesstra | e19391f | 2020-08-09 13:40:12 +0200 | [diff] [blame] | 458 | // flags, description, supervisor }) |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 459 | private void setup(string* chinfo) |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 460 | { |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 461 | string desc = "- Keine Beschreibung -"; |
Zesstra | e19391f | 2020-08-09 13:40:12 +0200 | [diff] [blame] | 462 | object supervisor = this_object(); |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 463 | |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 464 | if (sizeof(chinfo) && sizeof(chinfo[0]) > 1 && chinfo[0][0] == '\\') |
| 465 | chinfo[0] = chinfo[0][1..]; |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 466 | |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 467 | switch (sizeof(chinfo)) |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 468 | { |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 469 | // Alle Fallthroughs in dem switch() sind Absicht. |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 470 | case 6: |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 471 | if (stringp(chinfo[5]) && sizeof(chinfo[5])) |
Zesstra | e19391f | 2020-08-09 13:40:12 +0200 | [diff] [blame] | 472 | catch(supervisor = load_object(chinfo[5]); publish); |
| 473 | if (!objectp(supervisor)) |
| 474 | supervisor = this_object(); |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 475 | |
| 476 | case 5: |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 477 | if (stringp(chinfo[4]) || closurep(chinfo[4])) |
| 478 | desc = chinfo[4]; |
Zesstra | 26aaf1a | 2020-08-07 19:10:39 +0200 | [diff] [blame] | 479 | // Die admin-Daten sind nicht fuer die Ebene wichtig, nur fuer die |
| 480 | // check_ch_access(). |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 481 | case 4: |
Arathorn | 739a4fa | 2020-08-06 21:52:58 +0200 | [diff] [blame] | 482 | admin[lower_case(chinfo[0]), FLAG] = to_int(chinfo[3]); |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 483 | |
| 484 | case 3: |
Arathorn | 739a4fa | 2020-08-06 21:52:58 +0200 | [diff] [blame] | 485 | admin[lower_case(chinfo[0]), SEND] = to_int(chinfo[2]); |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 486 | |
| 487 | case 2: |
Arathorn | 739a4fa | 2020-08-06 21:52:58 +0200 | [diff] [blame] | 488 | admin[lower_case(chinfo[0]), RECV] = to_int(chinfo[1]); |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 489 | break; |
| 490 | |
| 491 | case 0: |
| 492 | default: |
| 493 | return; |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 494 | } |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 495 | |
Zesstra | e19391f | 2020-08-09 13:40:12 +0200 | [diff] [blame] | 496 | if (new(chinfo[0], supervisor, desc) == E_ACCESS_DENIED) |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 497 | { |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 498 | log_file("CHANNEL", sprintf("[%s] %s: %O: error, access denied\n", |
Zesstra | e19391f | 2020-08-09 13:40:12 +0200 | [diff] [blame] | 499 | dtime(time()), chinfo[0], supervisor)); |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 500 | } |
| 501 | return; |
| 502 | } |
| 503 | |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 504 | private void initialize() |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 505 | { |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 506 | string ch_list; |
Zesstra@Morgengrauen | 3b569c8 | 2016-07-18 20:22:08 +0200 | [diff] [blame] | 507 | #if !defined(__TESTMUD__) && MUDNAME=="MorgenGrauen" |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 508 | ch_list = read_file(object_name(this_object()) + ".init"); |
Zesstra@Morgengrauen | 3b569c8 | 2016-07-18 20:22:08 +0200 | [diff] [blame] | 509 | #else |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 510 | ch_list = read_file(object_name(this_object()) + ".init.testmud"); |
Zesstra@Morgengrauen | 3b569c8 | 2016-07-18 20:22:08 +0200 | [diff] [blame] | 511 | #endif |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 512 | |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 513 | if (!stringp(ch_list)) |
Zesstra@Morgengrauen | 2b22937 | 2016-07-20 23:59:54 +0200 | [diff] [blame] | 514 | return; |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 515 | |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 516 | // Channeldatensaetze erzeugen, dazu zuerst Datenfile in Zeilen zerlegen |
| 517 | // "Allgemein: 0: 0: 0:Allgemeine Unterhaltungsebene" |
| 518 | // Danach drueberlaufen und in Einzelfelder splitten, dabei gleich die |
| 519 | // Trennzeichen (Doppelpunkt, Tab und Space) rausfiltern. |
| 520 | foreach(string ch : old_explode(ch_list, "\n")) |
| 521 | { |
| 522 | if (ch[0]=='#') |
| 523 | continue; |
| 524 | setup( regexplode(ch, ":[ \t]*", RE_OMIT_DELIM) ); |
| 525 | } |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 526 | } |
| 527 | |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 528 | // BEGIN OF THE CHANNEL MASTER IMPLEMENTATION |
Zesstra@Morgengrauen | 2b22937 | 2016-07-20 23:59:54 +0200 | [diff] [blame] | 529 | protected void create() |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 530 | { |
| 531 | seteuid(getuid()); |
| 532 | restore_object(CHANNEL_SAVE); |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 533 | |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 534 | // Altes channelC aus Savefiles konvertieren... |
| 535 | if (widthof(channelC) == 1) |
| 536 | { |
| 537 | mapping new = m_allocate(sizeof(channelC), 2); |
| 538 | foreach(string chname, mixed arr: channelC) |
| 539 | { |
| 540 | struct channel_base_s ch = (<channel_base_s> name: arr[0], |
| 541 | desc: arr[1]); |
| 542 | // die anderen beiden Werte bleiben 0 |
| 543 | m_add(new, chname, ch, arr[2]); |
| 544 | } |
| 545 | channelC = new; |
| 546 | } |
Zesstra | 26aaf1a | 2020-08-07 19:10:39 +0200 | [diff] [blame] | 547 | //TODO: weitere Mappings im MEMORY speichern, Savefile ersetzen. |
| 548 | |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 549 | /* Die Channel-History wird nicht nur lokal sondern auch noch im Memory |
| 550 | gespeichert, dadurch bleibt sie auch ueber ein Reload erhalten. |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 551 | Der folgende Code versucht, den Zeiger aus dem Memory zu holen. Falls |
| 552 | das nicht moeglich ist, wird ein neuer erzeugt und gegebenenfalls im |
| 553 | Memory abgelegt. */ |
| 554 | |
| 555 | // Hab ich die noetigen Rechte im Memory? |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 556 | if (call_other(MEMORY, "HaveRights")) |
| 557 | { |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 558 | // Objektpointer laden |
Dominik Schaefer | fa564d5 | 2020-08-05 20:50:27 +0200 | [diff] [blame] | 559 | channelH = ({mapping}) call_other(MEMORY, "Load", "History"); |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 560 | |
| 561 | // Wenns nich geklappt hat, hat der Memory noch keinen Zeiger, dann |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 562 | if (!mappingp(channelH)) |
| 563 | { |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 564 | // Zeiger erzeugen |
| 565 | channelH = ([]); |
| 566 | // und in den Memory schreiben |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 567 | call_other(MEMORY, "Save", "History", channelH); |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 568 | } |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 569 | } |
| 570 | else |
| 571 | { |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 572 | // Keine Rechte im Memory, dann wird mit einem lokalen Zeiger gearbeitet. |
| 573 | channelH = ([]); |
| 574 | } |
| 575 | |
| 576 | stats = (["time": time(), |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 577 | "boot": capitalize(getuid(previous_object()) || "<Unbekannt>")]); |
| 578 | |
| 579 | // <MasteR>-Ebene erstellen. Channeld wird Ebenenbesitzer und somit auch |
| 580 | // Zuhoerer, damit er auf Kommandos auf dieser Ebene reagieren kann. |
| 581 | new(CMNAME, this_object(), "Zentrale Informationen zu den Ebenen"); |
| 582 | |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 583 | initialize(); |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 584 | users()->RegisterChannels(); |
| 585 | |
| 586 | // Die Zugriffskontrolle auf die Ebenen wird von der Funktion access() |
| 587 | // erledigt. Weil sowohl externe Aufrufe aus dem Spielerobjekt, als auch |
| 588 | // interne Aufrufe aus diesem Objekt vorkommen koennen, wird hier ein |
| 589 | // explizites call_other() auf this_object() gemacht, damit der |
| 590 | // Caller-Stack bei dem internen Aufruf denselben Aufbau hat wie bei |
| 591 | // einem externen. |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 592 | this_object()->send(CMNAME, this_object(), |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 593 | sprintf("%d Ebenen mit %d Teilnehmern initialisiert.", |
| 594 | sizeof(channels), |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 595 | CountUsers())); |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 596 | } |
| 597 | |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 598 | varargs void reset() |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 599 | { |
Zesstra | 26aaf1a | 2020-08-07 19:10:39 +0200 | [diff] [blame] | 600 | //TODO reset nur 1-2mal am Tag mit etwas random. |
| 601 | |
| 602 | // Cache bereinigen entsprechend dessen Timeout-Zeit (12 h) |
| 603 | // TODO: Zeit auf 2-3 Tage erhoehen. |
| 604 | // TODO 2: Zeit dynamisch machen und nur expiren, wenn mehr als n Eintraege. |
| 605 | // Zeit reduzieren, bis nur noch n/2 Eintraege verbleiben. |
Zesstra | 8f5102c | 2020-08-08 12:51:52 +0200 | [diff] [blame] | 606 | channelC = filter(channelC, |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 607 | function int (string ch_name, struct channel_base_s data, int ts) |
Zesstra | 8f5102c | 2020-08-08 12:51:52 +0200 | [diff] [blame] | 608 | { |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 609 | if (ts + 43200 > time()) |
Zesstra | 8f5102c | 2020-08-08 12:51:52 +0200 | [diff] [blame] | 610 | return 1; |
| 611 | // Ebenendaten koennen weg, inkl. History, die also auch loeschen |
| 612 | m_delete(channelH, ch_name); |
| 613 | return 0; |
| 614 | }); |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 615 | |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 616 | if (save_me_soon) |
| 617 | { |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 618 | save_me_soon = 0; |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 619 | save_object(CHANNEL_SAVE); |
| 620 | } |
| 621 | } |
| 622 | |
| 623 | // name() - define the name of this object. |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 624 | string name() |
| 625 | { |
| 626 | return CMNAME; |
| 627 | } |
| 628 | |
| 629 | string Name() |
| 630 | { |
| 631 | return CMNAME; |
| 632 | } |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 633 | |
Zesstra | 28986e1 | 2020-08-09 12:44:26 +0200 | [diff] [blame] | 634 | // Low-level function for adding members without access checks |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 635 | private int add_member(struct channel_s ch, object m) |
Zesstra | 28986e1 | 2020-08-09 12:44:26 +0200 | [diff] [blame] | 636 | { |
| 637 | if (IsChannelMember(ch, m)) |
| 638 | return E_ALREADY_JOINED; |
| 639 | |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 640 | ch.members += ({ m }); |
Zesstra | 28986e1 | 2020-08-09 12:44:26 +0200 | [diff] [blame] | 641 | return 0; |
| 642 | } |
| 643 | |
Zesstra | f87cb77 | 2020-08-10 11:14:45 +0200 | [diff] [blame] | 644 | // Deaktiviert eine Ebene, behaelt aber einige Stammdaten in channelC und die |
| 645 | // History, so dass sie spaeter reaktiviert werden kann. |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 646 | private void deactivate_channel(string chname) |
Zesstra | f87cb77 | 2020-08-10 11:14:45 +0200 | [diff] [blame] | 647 | { |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 648 | chname = lower_case(chname); |
| 649 | struct channel_s ch = channels[chname]; |
| 650 | if (!structp(ch)) |
Zesstra | f87cb77 | 2020-08-10 11:14:45 +0200 | [diff] [blame] | 651 | return; |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 652 | |
| 653 | // nur Ebenen ohne Zuhoerer deaktivieren. |
| 654 | if (sizeof(ch.members)) |
| 655 | { |
| 656 | raise_error( |
| 657 | sprintf("[%s] Attempt to deactivate channel %s with listeners.\n", |
| 658 | dtime(), ch.name)); |
| 659 | } |
Zesstra | f87cb77 | 2020-08-10 11:14:45 +0200 | [diff] [blame] | 660 | // Einige Daten merken, damit sie reaktiviert werden kann, wenn jemand |
| 661 | // einloggt, der die Ebene abonniert hat. |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 662 | m_add(channelC, chname, to_struct(channels[chname], (<channel_base_s>)), |
| 663 | time()); |
Zesstra | f87cb77 | 2020-08-10 11:14:45 +0200 | [diff] [blame] | 664 | |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 665 | // aktive Ebene loeschen bzw. deaktivieren. |
| 666 | m_delete(channels, chname); |
Zesstra | f87cb77 | 2020-08-10 11:14:45 +0200 | [diff] [blame] | 667 | // History wird nicht geloescht, damit sie noch verfuegbar ist, wenn die |
| 668 | // Ebene spaeter nochmal neu erstellt wird. Sie wird dann bereinigt, wenn |
| 669 | // channelC bereinigt wird. |
| 670 | |
| 671 | stats["dispose"]++; |
| 672 | save_me_soon = 1; |
| 673 | } |
| 674 | |
| 675 | // Loescht eine Ebene vollstaendig inkl. Stammdaten und History. |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 676 | private void delete_channel(string chname) |
Zesstra | f87cb77 | 2020-08-10 11:14:45 +0200 | [diff] [blame] | 677 | { |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 678 | chname = lower_case(chname); |
| 679 | struct channel_s ch = channels[chname]; |
| 680 | if (ch) |
Zesstra | f87cb77 | 2020-08-10 11:14:45 +0200 | [diff] [blame] | 681 | { |
| 682 | // nur Ebenen ohne Zuhoerer loeschen. (Wenn der Aufrufer auch andere |
| 683 | // loeschen will, muss er vorher selber die Ebene leer raeumen, s. |
| 684 | // Kommandofunktion remove_channel(). |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 685 | if (sizeof(ch.members)) |
Zesstra | f87cb77 | 2020-08-10 11:14:45 +0200 | [diff] [blame] | 686 | raise_error( |
| 687 | sprintf("[%s] Attempt to delete channel %s with listeners.\n", |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 688 | dtime(), ch.name)); |
Zesstra | f87cb77 | 2020-08-10 11:14:45 +0200 | [diff] [blame] | 689 | stats["dispose"]++; |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 690 | m_delete(channels, chname); |
Zesstra | f87cb77 | 2020-08-10 11:14:45 +0200 | [diff] [blame] | 691 | } |
| 692 | // Ab hier das gleiche fuer aktive und inaktive Ebenen. |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 693 | m_delete(channelsC, chname); |
| 694 | m_delete(channelsH, chname); |
Zesstra | f87cb77 | 2020-08-10 11:14:45 +0200 | [diff] [blame] | 695 | save_me_soon = 1; |
| 696 | } |
| 697 | |
Zesstra | 5b7f2fc | 2020-08-10 02:09:13 +0200 | [diff] [blame] | 698 | // Aendert das Supervisor-Objekt einer Ebene, ggf. mit Meldung. |
| 699 | // Wenn kein neuer SV angegeben, wird der aelteste Zuhoerer gewaehlt. |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 700 | private int change_sv_object(struct channel_s ch, object old_sv, object new_sv) |
Zesstra | 5b7f2fc | 2020-08-10 02:09:13 +0200 | [diff] [blame] | 701 | { |
| 702 | if (!new_sv) |
| 703 | { |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 704 | ch.members -= ({0}); |
| 705 | if (sizeof(ch.members)) |
| 706 | new_sv = ch.members[0]; |
Zesstra | 5b7f2fc | 2020-08-10 02:09:13 +0200 | [diff] [blame] | 707 | else |
| 708 | return 0; // kein neuer SV moeglich. |
| 709 | } |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 710 | ch.supervisor = new_sv; |
| 711 | //TODO angleichen an new() ! |
| 712 | ch.access_cl = symbol_function("check_ch_access", new_sv); |
Zesstra | 0c69c2d | 2020-08-10 02:27:20 +0200 | [diff] [blame] | 713 | |
Zesstra | 5b7f2fc | 2020-08-10 02:09:13 +0200 | [diff] [blame] | 714 | if (old_sv && new_sv |
| 715 | && !old_sv->QueryProp(P_INVIS) |
| 716 | && !new_sv->QueryProp(P_INVIS)) |
| 717 | { |
| 718 | // Die Zugriffskontrolle auf die Ebenen wird von der Funktion access() |
| 719 | // erledigt. Weil sowohl externe Aufrufe aus dem Spielerobjekt, als auch |
| 720 | // interne Aufrufe aus diesem Objekt vorkommen koennen, wird hier ein |
| 721 | // explizites call_other() auf this_object() gemacht, damit der |
| 722 | // Caller-Stack bei dem internen Aufruf denselben Aufbau hat wie bei |
| 723 | // einem externen. |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 724 | this_object()->send(ch.name, old_sv, |
Zesstra | 5b7f2fc | 2020-08-10 02:09:13 +0200 | [diff] [blame] | 725 | sprintf("uebergibt die Ebene an %s.",new_sv->name(WEN)), |
| 726 | MSG_EMOTE); |
| 727 | } |
| 728 | else if (old_svn && !old_sv->QueryProp(P_INVIS)) |
| 729 | { |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 730 | this_object()->send(ch.name, old_sv, |
Zesstra | 5b7f2fc | 2020-08-10 02:09:13 +0200 | [diff] [blame] | 731 | "uebergibt die Ebene an jemand anderen.", MSG_EMOTE); |
| 732 | } |
| 733 | else if (new_sv && !new_sv->QueryProp(P_INVIS)) |
| 734 | { |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 735 | this_object()->send(ch.name, new_sv, |
Zesstra | 5b7f2fc | 2020-08-10 02:09:13 +0200 | [diff] [blame] | 736 | "uebernimmt die Ebene von jemand anderem.", MSG_EMOTE); |
| 737 | } |
| 738 | return 1; |
| 739 | } |
| 740 | |
Zesstra | 56692c7 | 2020-08-09 13:03:10 +0200 | [diff] [blame] | 741 | // Stellt sicher, dass einen Ebenen-Supervisor gibt. Wenn dies nicht moeglich |
| 742 | // ist (z.b. leere Ebene), dann wird die Ebene geloescht und 0 |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 743 | // zurueckgegeben. Allerdings kann nach dieser Funktion sehr wohl die |
| 744 | // access_cl 0 sein, wenn der SV keine oeffentliche definiert! In diesem Fall |
Zesstra | 56692c7 | 2020-08-09 13:03:10 +0200 | [diff] [blame] | 745 | // wird access() den Zugriff immer erlauben. |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 746 | private int assert_supervisor(struct channel_s ch) |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 747 | { |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 748 | //Es ist keine Closure vorhanden, d.h. der Ebenenbesitzer wurde zerstoert. |
Zesstra | 5770ba6 | 2020-08-10 10:19:23 +0200 | [diff] [blame] | 749 | //TODO: es ist nicht so selten, dass die Closure 0 ist, d.h. der Code laeuft |
| 750 | //haeufig unnoetig! |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 751 | if (!closurep(ch.access_cl)) |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 752 | { |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 753 | // Wenn der Ebenenbesitzer als String eingetragen ist, versuchen wir, |
| 754 | // die Closure wiederherzustellen. Dabei wird das Objekt gleichzeitig |
Zesstra | e19391f | 2020-08-09 13:40:12 +0200 | [diff] [blame] | 755 | // neugeladen und eingetragen. |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 756 | if (stringp(ch.supervisor)) |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 757 | { |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 758 | closure new_acc_cl; |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 759 | // TODO: angleichen an new()! |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 760 | string err = catch(new_acc_cl= |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 761 | symbol_function("check_ch_access", ch->supervisor); |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 762 | publish); |
Zesstra | 56692c7 | 2020-08-09 13:03:10 +0200 | [diff] [blame] | 763 | /* Wenn das SV-Objekt neu geladen werden konnte, wird es als Mitglied |
| 764 | * eingetragen. Auch die Closure wird neu eingetragen, allerdings kann |
| 765 | * sie 0 sein, wenn das SV-Objekt keine oeffentliche check_ch_access() |
| 766 | * mehr definiert. In diesem Fall gibt es zwar ein SV-Objekt, aber keine |
| 767 | * Zugriffrechte(pruefung) mehr. */ |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 768 | if (!err) |
| 769 | { |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 770 | ch.access_cl = new_acc_cl; |
Zesstra | 28986e1 | 2020-08-09 12:44:26 +0200 | [diff] [blame] | 771 | // Der neue Ebenenbesitzer tritt auch gleich der Ebene bei. Hierbei |
| 772 | // erfolgt keine Pruefung des Zugriffsrechtes (ist ja unsinnig, weil |
| 773 | // er sich ja selber genehmigen koennte), und auch um eine Rekursion |
| 774 | // zu vermeiden. |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 775 | add_member(ch, find_object(ch.supervisor)); |
Zesstra | 56692c7 | 2020-08-09 13:03:10 +0200 | [diff] [blame] | 776 | // Rueckgabewert ist 1, ein neues SV-Objekt ist eingetragen. |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 777 | } |
| 778 | else |
| 779 | { |
Zesstra | 5770ba6 | 2020-08-10 10:19:23 +0200 | [diff] [blame] | 780 | log_file("CHANNEL", |
| 781 | sprintf("[%s] Channel %s deleted. SV-Fehler: %O -> %O\n", |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 782 | dtime(time()), ch.name, ch.supervisor, err)); |
Zesstra | f87cb77 | 2020-08-10 11:14:45 +0200 | [diff] [blame] | 783 | // Dies ist ein richtiges Loeschen, weil nicht-ladbare SV koennen bei |
| 784 | // Deaktivierung zu einer lesbaren History fuehren. |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 785 | delete_channel(ch.name); |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 786 | return 0; |
| 787 | } |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 788 | } |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 789 | else if (!objectp(ch.supervisor)) |
Zesstra | 56692c7 | 2020-08-09 13:03:10 +0200 | [diff] [blame] | 790 | { |
| 791 | // In diesem Fall muss ein neues SV-Objekt gesucht und ggf. eingetragen |
Zesstra | 5770ba6 | 2020-08-10 10:19:23 +0200 | [diff] [blame] | 792 | // werden. change_sv_object nimmt das aelteste Mitglied der Ebene. |
| 793 | if (!change_sv_object(ch, pl, 0)) |
| 794 | { |
| 795 | // wenn das nicht klappt, Ebene aufloesen |
| 796 | log_file("CHANNEL", |
Zesstra | f87cb77 | 2020-08-10 11:14:45 +0200 | [diff] [blame] | 797 | sprintf("[%s] Deactivating channel %s without SV.\n", |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 798 | dtime(time()), ch.name)); |
| 799 | deactivate_channel(ch.name); |
Zesstra | 5770ba6 | 2020-08-10 10:19:23 +0200 | [diff] [blame] | 800 | return 0; |
| 801 | } |
Zesstra | 56692c7 | 2020-08-09 13:03:10 +0200 | [diff] [blame] | 802 | } |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 803 | } |
Zesstra | 7831001 | 2020-08-09 12:21:48 +0200 | [diff] [blame] | 804 | return 1; |
| 805 | } |
| 806 | |
| 807 | // access() - check access by looking for the right argument types and |
| 808 | // calling access closures respectively |
| 809 | // SEE: new, join, leave, send, list, users |
| 810 | // Note: <pl> is usually an object, only the master supplies a string during |
| 811 | // runtime error handling. |
| 812 | // Wertebereich: 0 fuer Zugriff verweigert, 1 fuer Zugriff erlaubt, 2 fuer |
| 813 | // Zugriff erlaubt fuer privilegierte Objekte, die senden duerfen ohne |
| 814 | // Zuhoerer zu sein. (Die Aufrufer akzeptieren aber auch alle negativen Werte |
| 815 | // als Erfolg und alles ueber >2 als privilegiert.) |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 816 | varargs private int access(struct channel_s ch, object|string pl, string cmd, |
Zesstra | 7831001 | 2020-08-09 12:21:48 +0200 | [diff] [blame] | 817 | string txt) |
| 818 | { |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 819 | if (!ch) |
Zesstra | 7831001 | 2020-08-09 12:21:48 +0200 | [diff] [blame] | 820 | return 0; |
| 821 | |
Zesstra | fbfe636 | 2020-08-09 13:30:21 +0200 | [diff] [blame] | 822 | // Dieses Objekt und Root-Objekte duerfen auf der Ebene senden, ohne |
| 823 | // Mitglied zu sein. Das ist die Folge der zurueckgegebenen 2. |
Zesstra | 7831001 | 2020-08-09 12:21:48 +0200 | [diff] [blame] | 824 | if ( !previous_object(1) || !extern_call() || |
| 825 | previous_object(1) == this_object() || |
Zesstra | fbfe636 | 2020-08-09 13:30:21 +0200 | [diff] [blame] | 826 | getuid(previous_object(1)) == ROOTID) |
Zesstra | 7831001 | 2020-08-09 12:21:48 +0200 | [diff] [blame] | 827 | return 2; |
Arathorn | 739a4fa | 2020-08-06 21:52:58 +0200 | [diff] [blame] | 828 | |
Zesstra | 56692c7 | 2020-08-09 13:03:10 +0200 | [diff] [blame] | 829 | // Nur dieses Objekt darf Meldungen im Namen anderer Objekte faken, |
| 830 | // ansonsten muss <pl> der Aufrufer sein. |
Arathorn | 739a4fa | 2020-08-06 21:52:58 +0200 | [diff] [blame] | 831 | if (!objectp(pl) || |
| 832 | ((previous_object(1) != pl) && (previous_object(1) != this_object()))) |
| 833 | return 0; |
| 834 | |
| 835 | if (IsBanned(pl, cmd)) |
| 836 | return 0; |
| 837 | |
Zesstra | 56692c7 | 2020-08-09 13:03:10 +0200 | [diff] [blame] | 838 | // Wenn kein SV-Objekt mehr existiert und kein neues bestimmt werden konnte, |
| 839 | // wurde die Ebene ausfgeloest. In diesem Fall auch den Zugriff verweigern. |
Zesstra | 7831001 | 2020-08-09 12:21:48 +0200 | [diff] [blame] | 840 | if (!assert_supervisor(ch)) |
Zesstra | 56692c7 | 2020-08-09 13:03:10 +0200 | [diff] [blame] | 841 | return 0; |
| 842 | // Wenn closure jetzt dennoch 0, wird der Zugriff erlaubt. |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 843 | if (!ch.access_cl) |
Arathorn | 739a4fa | 2020-08-06 21:52:58 +0200 | [diff] [blame] | 844 | return 1; |
| 845 | |
Zesstra | 6fe46cd | 2020-08-09 13:12:15 +0200 | [diff] [blame] | 846 | // Das SV-Objekt wird gefragt, ob der Zugriff erlaubt ist. Dieses erfolgt |
| 847 | // fuer EM+ aber nur, wenn der CHANNELD selber das SV-Objekt ist, damit |
| 848 | // nicht beliebige SV-Objekt EMs den Zugriff verweigern koennen. Ebenen mit |
| 849 | // CHANNELD als SV koennen aber natuerlich auch EM+ Zugriff verweigern. |
| 850 | if (IS_ARCH(previous_object(1)) |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 851 | && find_object(ch.supervisor) != this_object()) |
Zesstra | 6fe46cd | 2020-08-09 13:12:15 +0200 | [diff] [blame] | 852 | return 1; |
| 853 | |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 854 | return funcall(ch.access_cl, lower_case(ch.name), pl, cmd, &txt); |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 855 | } |
| 856 | |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 857 | // Neue Ebene <ch> erstellen mit <owner> als Ebenenbesitzer. |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 858 | // <desc> kann die statische Beschreibung der Ebene sein oder eine Closure, |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 859 | // die dynamisch aktualisierte Infos ausgibt. |
| 860 | // Das Objekt <owner> kann eine Funktion check_ch_access() definieren, die |
| 861 | // gerufen wird, wenn eine Ebenenaktion vom Typ join/leave/send/list/users |
| 862 | // eingeht. |
| 863 | // check_ch_access() dient der Zugriffskontrolle und entscheidet, ob die |
| 864 | // Nachricht gesendet werden darf oder nicht. |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 865 | #define IGNORE "^/xx" |
| 866 | |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 867 | // TODO: KOMMENTAR |
| 868 | //check may contain a closure |
| 869 | // called when a join/leave/send/list/users message is received |
Zesstra | 7da4d69 | 2020-08-10 11:17:54 +0200 | [diff] [blame] | 870 | public varargs int new(string ch_name, object owner, string|closure desc) |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 871 | { |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 872 | // Kein Channelmaster angegeben, oder wir sind es selbst, aber der Aufruf |
| 873 | // kam von ausserhalb. (Nur der channeld selbst darf sich als Channelmaster |
| 874 | // fuer eine neue Ebene eintragen.) |
| 875 | if (!objectp(owner) || (owner == this_object() && extern_call()) ) |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 876 | return E_ACCESS_DENIED; |
| 877 | |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 878 | // Kein gescheiter Channelname angegeben. |
| 879 | if (!stringp(ch_name) || !sizeof(ch_name)) |
| 880 | return E_ACCESS_DENIED; |
| 881 | |
| 882 | // Channel schon vorhanden oder schon alle Channel-Slots belegt. |
| 883 | if (channels[lower_case(ch_name)] || sizeof(channels) >= MAX_CHANNELS) |
| 884 | return E_ACCESS_DENIED; |
| 885 | |
| 886 | // Der angegebene Ebenenbesitzer darf keine Ebenen erstellen, wenn fuer ihn |
| 887 | // ein Bann auf die Aktion C_NEW besteht, oder das Ignore-Pattern auf |
| 888 | // seinen Objektnamen matcht. |
| 889 | if (IsBanned(owner,C_NEW) || regmatch(object_name(owner), IGNORE)) |
| 890 | return E_ACCESS_DENIED; |
| 891 | |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 892 | struct channel_s ch; |
Zesstra | 7da4d69 | 2020-08-10 11:17:54 +0200 | [diff] [blame] | 893 | // Keine Beschreibung mitgeliefert? Dann holen wir sie aus dem Cache. |
| 894 | if (!desc) |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 895 | { |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 896 | struct channel_base_s cbase = channelC[lower_case(ch_name)]; |
| 897 | if (cbase) |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 898 | { |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 899 | ch = to_struct(cbase, (<channel_s>)); |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 900 | } |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 901 | else |
| 902 | { |
| 903 | return E_ACCESS_DENIED; |
| 904 | } |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 905 | } |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 906 | else |
| 907 | { |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 908 | ch = (<channel_s> name: ch_name, desc: desc, creator: object_name(owner) |
| 909 | ); |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 910 | } |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 911 | |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 912 | ch_name = lower_case(ch_name); |
| 913 | |
| 914 | ch.members = ({ owner }); |
| 915 | ch.supervisor = (!living(owner) && !clonep(owner) && owner != this_object()) |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 916 | ? object_name(owner) |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 917 | : owner; |
| 918 | //TODO: Ist das wirklich eine gute Idee, eine Access-Closure zu |
| 919 | //bauen, die *nicht* im Supervisor liegt? IMHO nein! Es ist ein |
| 920 | //merkwuerdiges Konzept, dass der channeld Rechte fuer ne Ebene |
| 921 | //pruefen soll, die nen anderes Objekt als Supervisor haben. |
| 922 | ch.access_cl = symbol_function("check_ch_access", owner) || #'check_ch_access; |
| 923 | |
| 924 | m_add(channels, ch_name, ch); |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 925 | |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 926 | // History fuer eine Ebene nur dann initialisieren, wenn es sie noch |
| 927 | // nicht gibt. |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 928 | if (!pointerp(channelH[ch_name])) |
| 929 | channelH[ch_name] = ({}); |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 930 | |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 931 | // Erstellen neuer Ebenen loggen, wenn wir nicht selbst der Ersteller sind. |
| 932 | if (owner != this_object()) |
Zesstra | 5770ba6 | 2020-08-10 10:19:23 +0200 | [diff] [blame] | 933 | log_file("CHANNEL.new", sprintf("[%s] Neue Ebene %s: %O %O\n", |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 934 | dtime(time()), ch.name, owner, desc)); |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 935 | |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 936 | // Erfolgsmeldung ausgeben, ausser bei unsichtbarem Ebenenbesitzer. |
| 937 | if (!owner->QueryProp(P_INVIS)) |
| 938 | { |
| 939 | // Die Zugriffskontrolle auf die Ebenen wird von der Funktion access() |
| 940 | // erledigt. Weil sowohl externe Aufrufe aus dem Spielerobjekt, als auch |
| 941 | // interne Aufrufe aus diesem Objekt vorkommen koennen, wird hier ein |
| 942 | // explizites call_other() auf this_object() gemacht, damit der |
| 943 | // Caller-Stack bei dem internen Aufruf denselben Aufbau hat wie bei |
| 944 | // einem externen. |
| 945 | this_object()->send(CMNAME, owner, |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 946 | "laesst die Ebene '" + ch.name + "' entstehen.", MSG_EMOTE); |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 947 | } |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 948 | |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 949 | stats["new"]++; |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 950 | save_me_soon = 1; |
| 951 | return (0); |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 952 | } |
| 953 | |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 954 | // Objekt <pl> betritt Ebene <ch>. Dies wird zugelassen, wenn <pl> die |
| 955 | // Berechtigung hat und noch nicht Mitglied ist. (Man kann einer Ebene nicht |
| 956 | // zweimal beitreten.) |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 957 | public int join(string chname, object pl) |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 958 | { |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 959 | struct channel_s ch = channels[lower_case(chname)]; |
Arathorn | 739a4fa | 2020-08-06 21:52:58 +0200 | [diff] [blame] | 960 | /* funcall() auf Closure-Operator, um einen neuen Eintrag im Caller Stack |
| 961 | zu erzeugen, weil access() mit extern_call() und previous_object() |
| 962 | arbeitet und sichergestellt sein muss, dass das in jedem Fall das |
| 963 | richtige ist. */ |
| 964 | if (!funcall(#'access, ch, pl, C_JOIN)) |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 965 | return E_ACCESS_DENIED; |
| 966 | |
Zesstra | 28986e1 | 2020-08-09 12:44:26 +0200 | [diff] [blame] | 967 | return add_member(ch, pl); |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 968 | } |
| 969 | |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 970 | // Objekt <pl> verlaesst Ebene <ch>. |
| 971 | // Zugriffsrechte werden nur der Vollstaendigkeit halber geprueft; es duerfte |
| 972 | // normalerweise keinen Grund geben, das Verlassen einer Ebene zu verbieten. |
| 973 | // Dies ist in check_ch_access() so geregelt, allerdings koennte dem Objekt |
| 974 | // <pl> das Verlassen auf Grund eines Banns verboten sein. |
| 975 | // Wenn kein Spieler mehr auf der Ebene ist, loest sie sich auf, sofern nicht |
| 976 | // noch ein Ebenenbesitzer eingetragen ist. |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 977 | public int leave(string chname, object pl) |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 978 | { |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 979 | struct channel_s ch = channels[lower_case(chname)]; |
Zesstra | 877cb0a | 2020-08-10 02:10:21 +0200 | [diff] [blame] | 980 | |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 981 | ch.members -= ({0}); // kaputte Objekte erstmal raus |
Zesstra | 877cb0a | 2020-08-10 02:10:21 +0200 | [diff] [blame] | 982 | |
| 983 | if (!IsChannelMember(ch, pl)) |
| 984 | return E_NOT_MEMBER; |
| 985 | |
Arathorn | 739a4fa | 2020-08-06 21:52:58 +0200 | [diff] [blame] | 986 | /* funcall() auf Closure-Operator, um einen neuen Eintrag im Caller Stack |
| 987 | zu erzeugen, weil access() mit extern_call() und previous_object() |
| 988 | arbeitet und sichergestellt sein muss, dass das in jedem Fall das |
| 989 | richtige ist. */ |
| 990 | if (!funcall(#'access, ch, pl, C_LEAVE)) |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 991 | return E_ACCESS_DENIED; |
| 992 | |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 993 | // Dann mal den Zuhoerer raus. |
| 994 | ch.members -= ({pl}); |
Zesstra | e6d3385 | 2020-08-09 14:37:53 +0200 | [diff] [blame] | 995 | |
Zesstra | 5b7f2fc | 2020-08-10 02:09:13 +0200 | [diff] [blame] | 996 | // Wenn auf der Ebene jetzt noch Objekte zuhoeren, muss ggf. der SV |
| 997 | // wechseln. |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 998 | if (sizeof(ch.members)) |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 999 | { |
Zesstra | 5b7f2fc | 2020-08-10 02:09:13 +0200 | [diff] [blame] | 1000 | // Kontrolle an jemand anderen uebergeben, wenn der Ebenensupervisor |
| 1001 | // diese verlassen hat. change_sv_object() waehlt per Default den |
| 1002 | // aeltesten Zuhoerer. |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 1003 | if (pl == ch.supervisor |
| 1004 | || object_name(pl) == ch.supervisor) |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 1005 | { |
Zesstra | 5b7f2fc | 2020-08-10 02:09:13 +0200 | [diff] [blame] | 1006 | change_sv_object(ch, pl, 0); |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 1007 | } |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 1008 | } |
Zesstra | 137ea1c | 2020-08-10 02:15:20 +0200 | [diff] [blame] | 1009 | // ansonsten Ebene loeschen, wenn keiner zuhoert. |
| 1010 | // Kommentar: Supervisoren sind auch Zuhoerer auf der Ebene. Wenn keine |
| 1011 | // Zuhoerer mehr, folglich auch kein Supervisor mehr da. |
| 1012 | else |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 1013 | { |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 1014 | // Der Letzte macht das Licht aus, aber nur, wenn er nicht unsichtbar ist. |
Zesstra | 137ea1c | 2020-08-10 02:15:20 +0200 | [diff] [blame] | 1015 | // Wenn Spieler, NPC, Clone oder Channeld als letztes die Ebene verlassen, |
| 1016 | // wird diese zerstoert, mit Meldung. |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 1017 | if (!pl->QueryProp(P_INVIS)) |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 1018 | { |
| 1019 | // Die Zugriffskontrolle auf die Ebenen wird von der Funktion access() |
| 1020 | // erledigt. Weil sowohl externe Aufrufe aus dem Spielerobjekt, als auch |
| 1021 | // interne Aufrufe aus diesem Objekt vorkommen koennen, wird hier ein |
| 1022 | // explizites call_other() auf this_object() gemacht, damit der |
| 1023 | // Caller-Stack bei dem internen Aufruf denselben Aufbau hat wie bei |
| 1024 | // einem externen. |
| 1025 | this_object()->send(CMNAME, pl, |
| 1026 | "verlaesst als "+ |
| 1027 | (pl->QueryProp(P_GENDER) == 1 ? "Letzter" : "Letzte")+ |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 1028 | " die Ebene '" + ch.name + "', worauf diese sich in " |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 1029 | "einem Blitz oktarinen Lichts aufloest.", MSG_EMOTE); |
| 1030 | } |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 1031 | deactivate_channel(lower_case(ch.name)); |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 1032 | } |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 1033 | return (0); |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 1034 | } |
| 1035 | |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 1036 | // Nachricht <msg> vom Typ <type> mit Absender <pl> auf der Ebene <ch> posten, |
| 1037 | // sofern <pl> dort senden darf. |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 1038 | public varargs int send(string chname, object pl, string msg, int type) |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 1039 | { |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 1040 | chname = lower_case(chname); |
| 1041 | struct channel_s ch = channels[chname]; |
Arathorn | 739a4fa | 2020-08-06 21:52:58 +0200 | [diff] [blame] | 1042 | /* funcall() auf Closure-Operator, um einen neuen Eintrag im Caller Stack |
| 1043 | zu erzeugen, weil access() mit extern_call() und previous_object() |
| 1044 | arbeitet und sichergestellt sein muss, dass das in jedem Fall das |
| 1045 | richtige ist. */ |
| 1046 | int a = funcall(#'access, ch, pl, C_SEND, msg); |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 1047 | if (!a) |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 1048 | return E_ACCESS_DENIED; |
| 1049 | |
Zesstra | 26aaf1a | 2020-08-07 19:10:39 +0200 | [diff] [blame] | 1050 | // a<2 bedeutet effektiv a==1 (weil a==0 oben rausfaellt), was dem |
| 1051 | // Rueckgabewert von check_ch_access() entspricht, wenn die Aktion zugelassen |
| 1052 | // wird. access() allerdings 2 fuer "privilegierte" Objekte (z.B. |
| 1053 | // ROOT-Objekte oder den channeld selber). Der Effekt ist, dass diese |
| 1054 | // Objekte auf Ebenen senden duerfen, auf denen sie nicht zuhoeren. |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 1055 | if (a < 2 && !IsChannelMember(ch, pl)) |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 1056 | return E_NOT_MEMBER; |
| 1057 | |
| 1058 | if (!msg || !stringp(msg) || !sizeof(msg)) |
| 1059 | return E_EMPTY_MESSAGE; |
| 1060 | |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 1061 | // Jedem Mitglied der Ebene wird die Nachricht ueber die Funktion |
| 1062 | // ChannelMessage() zugestellt. Der Channeld selbst hat ebenfalls eine |
| 1063 | // Funktion dieses Namens, so dass er, falls er Mitglied der Ebene ist, die |
| 1064 | // Nachricht ebenfalls erhaelt. |
| 1065 | // Um die Kommandos der Ebene <MasteR> verarbeiten zu koennen, muss er |
| 1066 | // demzufolge Mitglied dieser Ebene sein. Da Ebenenbesitzer automatisch |
| 1067 | // auch Mitglied sind, wird die Ebene <MasteR> im create() mittels new() |
| 1068 | // erzeugt und der Channeld als Besitzer angegeben. |
| 1069 | // Die Aufrufkette ist dann wie folgt: |
| 1070 | // Eingabe "-< xyz" => pl::ChannelParser() => send() => ChannelMessage() |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 1071 | (ch.members)->ChannelMessage( |
| 1072 | ({ ch.name, pl, msg, type})); |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 1073 | |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 1074 | if (sizeof(channelH[chname]) > MAX_HIST_SIZE) |
| 1075 | channelH[chname] = channelH[chname][1..]; |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 1076 | |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 1077 | channelH[chname] += |
| 1078 | ({ ({ ch.name, |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 1079 | (stringp(pl) |
| 1080 | ? pl |
| 1081 | : (pl->QueryProp(P_INVIS) |
| 1082 | ? "/(" + capitalize(getuid(pl)) + ")$" |
| 1083 | : "") |
| 1084 | + (pl->Name(WER, 2) || "<Unbekannt>")), |
| 1085 | msg + " <" + strftime("%a, %H:%M:%S") + ">\n", |
| 1086 | type }) }); |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 1087 | return (0); |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 1088 | } |
| 1089 | |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 1090 | // Gibt ein Mapping mit allen Ebenen aus, die das Objekt <pl> lesen kann, |
| 1091 | // oder einen Integer-Fehlercode |
| 1092 | public int|mapping list(object pl) |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 1093 | { |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 1094 | mapping chs = ([]); |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 1095 | foreach(string chname, struct channel_s ch : channels) |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 1096 | { |
Arathorn | 739a4fa | 2020-08-06 21:52:58 +0200 | [diff] [blame] | 1097 | /* funcall() auf Closure-Operator, um einen neuen Eintrag im Caller Stack |
| 1098 | zu erzeugen, weil access() mit extern_call() und previous_object() |
| 1099 | arbeitet und sichergestellt sein muss, dass das in jedem Fall das |
| 1100 | richtige ist. */ |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 1101 | if(funcall(#'access, ch, pl, C_LIST)) |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 1102 | { |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 1103 | ch.members = filter(ch.members, #'objectp); |
| 1104 | m_add(chs, chname, ({ch.members, ch.access_cl, ch.desc, |
| 1105 | ch.supervisor, ch.name }) ); |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 1106 | } |
| 1107 | } |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 1108 | |
| 1109 | if (!sizeof(chs)) |
| 1110 | return E_ACCESS_DENIED; |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 1111 | return (chs); |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 1112 | } |
| 1113 | |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 1114 | // Ebene suchen, deren Name <ch> enthaelt, und auf der Objekt <pl> senden darf |
| 1115 | // Rueckgabewerte: |
| 1116 | // - den gefundenen Namen als String |
| 1117 | // - String-Array, wenn es mehrere Treffer gibt |
| 1118 | // - 0, wenn es keinen Treffer gibt |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 1119 | public string|string* find(string chname, object pl) |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 1120 | { |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 1121 | chname = lower_case(chname); |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 1122 | |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 1123 | // Suchstring <ch> muss Formatanforderung erfuellen; |
| 1124 | // TODO: soll das ein Check auf gueltigen Ebenennamen als Input sein? |
| 1125 | // Wenn ja, muesste laut Manpage mehr geprueft werden: |
| 1126 | // "Gueltige Namen setzen sich zusammen aus den Buchstaben a-z, A-Z sowie |
| 1127 | // #$%&@<>-." Es wuerden also $%&@ fehlen. |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 1128 | if (!regmatch(chname, "^[<>a-z0-9#-]+$")) |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 1129 | return 0; |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 1130 | |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 1131 | // Der Anfang des Ebenennamens muss dem Suchstring entsprechen und das |
| 1132 | // Objekt <pl> muss auf dieser Ebene senden duerfen, damit der Ebenenname |
| 1133 | // in das Suchergebnis aufgenommen wird. |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 1134 | string* chs = filter(m_indices(channels), function int (string ch_n) { |
Arathorn | 739a4fa | 2020-08-06 21:52:58 +0200 | [diff] [blame] | 1135 | /* funcall() auf Closure-Operator, um einen neuen Eintrag |
| 1136 | im Caller Stack zu erzeugen, weil access() mit |
| 1137 | extern_call() und previous_object() arbeitet und |
| 1138 | sichergestellt sein muss, dass das in jedem Fall das |
| 1139 | richtige ist. */ |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 1140 | return ( stringp(regmatch(ch_n, "^"+chname)) && |
| 1141 | funcall(#'access, channels[ch_n], pl, C_SEND) ); |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 1142 | }); |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 1143 | |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 1144 | int num_channels = sizeof(chs); |
| 1145 | if (num_channels > 1) |
| 1146 | return chs; |
| 1147 | else if (num_channels == 1) |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 1148 | return chs[0]; |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 1149 | else |
| 1150 | return 0; |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 1151 | } |
| 1152 | |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 1153 | // Ebenen-History abfragen. |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 1154 | public int|<int|string>** history(string chname, object pl) |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 1155 | { |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 1156 | struct channel_s ch = channels[lower_case(chname)]; |
Arathorn | 739a4fa | 2020-08-06 21:52:58 +0200 | [diff] [blame] | 1157 | /* funcall() auf Closure-Operator, um einen neuen Eintrag im Caller Stack |
| 1158 | zu erzeugen, weil access() mit extern_call() und previous_object() |
| 1159 | arbeitet und sichergestellt sein muss, dass das in jedem Fall das |
| 1160 | richtige ist. */ |
| 1161 | if (!funcall(#'access, ch, pl, C_JOIN)) |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 1162 | return E_ACCESS_DENIED; |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 1163 | else |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 1164 | return channelH[chname]; |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 1165 | } |
| 1166 | |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 1167 | // Wird aus der Shell gerufen, fuer das Erzmagier-Kommando "kill". |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 1168 | public int remove_channel(string chname, object pl) |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 1169 | { |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 1170 | chname = lower_case(chname); |
| 1171 | struct channel_s ch = channels[chname]; |
| 1172 | |
Zesstra | 26aaf1a | 2020-08-07 19:10:39 +0200 | [diff] [blame] | 1173 | //TODO: integrieren in access()? |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 1174 | if (previous_object() != this_object()) |
| 1175 | { |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 1176 | if (!stringp(chname) || |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 1177 | pl != this_player() || this_player() != this_interactive() || |
| 1178 | this_interactive() != previous_object() || |
| 1179 | !IS_ARCH(this_interactive())) |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 1180 | return E_ACCESS_DENIED; |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 1181 | } |
Zesstra | f87cb77 | 2020-08-10 11:14:45 +0200 | [diff] [blame] | 1182 | // Wenn die Ebene aktiv ist (d.h. Zuhoerer hat), muessen die erst |
| 1183 | // runtergeworfen werden. |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 1184 | if (ch) |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 1185 | { |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 1186 | // Einer geloeschten Ebene kann man nicht zuhoeren: Ebenenname aus der |
| 1187 | // Ebenenliste aller Mitglieder austragen. Dabei werden sowohl ein-, als |
| 1188 | // auch temporaer ausgeschaltete Ebenen beruecksichtigt. |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 1189 | foreach(object listener : ch.members) |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 1190 | { |
| 1191 | string* pl_chans = listener->QueryProp(P_CHANNELS); |
| 1192 | if (pointerp(pl_chans)) |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 1193 | { |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 1194 | listener->SetProp(P_CHANNELS, pl_chans-({chname})); |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 1195 | } |
| 1196 | pl_chans = listener->QueryProp(P_SWAP_CHANNELS); |
| 1197 | if (pointerp(pl_chans)) |
| 1198 | { |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 1199 | listener->SetProp(P_SWAP_CHANNELS, pl_chans-({chname})); |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 1200 | } |
| 1201 | } |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 1202 | } |
Zesstra | f87cb77 | 2020-08-10 11:14:45 +0200 | [diff] [blame] | 1203 | // Dies auserhalb des Blocks oben ermoeglicht es, inaktive Ebenen bzw. |
Zesstra | 8f5102c | 2020-08-08 12:51:52 +0200 | [diff] [blame] | 1204 | // deren Daten zu entfernen. |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 1205 | delete_channel(chname); |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 1206 | |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 1207 | return (0); |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 1208 | } |
| 1209 | |
Arathorn | 78c0837 | 2019-12-11 20:14:23 +0100 | [diff] [blame] | 1210 | // Wird aus der Shell aufgerufen, fuer das Erzmagier-Kommando "clear". |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 1211 | public int clear_history(string chname) |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 1212 | { |
Zesstra | 26aaf1a | 2020-08-07 19:10:39 +0200 | [diff] [blame] | 1213 | //TODO: mit access() vereinigen? |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 1214 | // Sicherheitsabfragen |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 1215 | if (previous_object() != this_object()) |
| 1216 | { |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 1217 | if (!stringp(chname) || |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 1218 | this_player() != this_interactive() || |
| 1219 | this_interactive() != previous_object() || |
| 1220 | !IS_ARCH(this_interactive())) |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 1221 | return E_ACCESS_DENIED; |
Arathorn | 19459eb | 2019-11-30 00:45:51 +0100 | [diff] [blame] | 1222 | } |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 1223 | chname=lower_case(chname); |
Zesstra | 26aaf1a | 2020-08-07 19:10:39 +0200 | [diff] [blame] | 1224 | // History des Channels loeschen (ohne die ebene als ganzes, daher Key nicht |
| 1225 | // aus dem mapping loeschen.) |
Zesstra | b7720dc | 2020-08-11 22:14:18 +0200 | [diff] [blame^] | 1226 | if (pointerp(channelH[chname])) |
| 1227 | channelH[chname] = ({}); |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 1228 | |
| 1229 | return 0; |
| 1230 | } |