MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame^] | 1 | #include "../haus.h" |
| 2 | #include <properties.h> |
| 3 | #include <moving.h> |
| 4 | #include <wizlevels.h> |
| 5 | |
| 6 | inherit "std/secure_thing"; |
| 7 | |
| 8 | private int secure() |
| 9 | { |
| 10 | return (this_interactive() && (IS_ARCH(this_interactive()) || |
| 11 | getuid(this_interactive()) == "wurzel")); |
| 12 | } |
| 13 | |
| 14 | create() |
| 15 | { |
| 16 | if (!clonep(this_object())) return; |
| 17 | ::create(); |
| 18 | |
| 19 | SetProp(P_SHORT, "Ein Adressverzeichnis" ); |
| 20 | SetProp(P_LONG, |
| 21 | "Mit diesem Adressverzeichnis koennen die richtigen Leute Ordnung in den\n" |
| 22 | +"Wust der Seherhausangelegenheiten bringen.\n" |
| 23 | +"Die richtigen Leute?\n" |
| 24 | +"Ja: Man muss schon Erzmagier sein oder Wurzel heissen! ;)\n" |
| 25 | +"Du kannst es uebrigens lesen!\n" ); |
| 26 | SetProp(P_NAME, "Adressverzeichnis"); |
| 27 | SetProp(P_READ_MSG, |
| 28 | "Es stehen folgende Befehle zur Verfuegung:\n" |
| 29 | +"checked <name> [+/-] <nr>\n" |
| 30 | +"rep\n" |
| 31 | +"mkmail <name>\n" |
| 32 | ); |
| 33 | SetProp(P_GENDER, NEUTER); |
| 34 | SetProp(P_WEIGHT, 100); |
| 35 | SetProp(P_AUTOLOADOBJ, 1); |
| 36 | SetProp(P_NEVERDROP, 1); |
| 37 | SetProp(P_NODROP, 1); |
| 38 | |
| 39 | AddId( ({ "verzeichnis", "adressverzeichnis", "haustool" }) ); |
| 40 | |
| 41 | AddCmd("checked", "checked"); |
| 42 | AddCmd("rep", "report"); |
| 43 | AddCmd("mkmail", "mkmail"); |
| 44 | } |
| 45 | |
| 46 | #define CHECKED PATH+"log/CHECKED" |
| 47 | static int |
| 48 | checked(string str) |
| 49 | { |
| 50 | mapping drin; |
| 51 | string name, *lines, *ind, pm; |
| 52 | int nr, i; |
| 53 | closure hp; |
| 54 | |
| 55 | if (!secure()) |
| 56 | return 0; |
| 57 | |
| 58 | notify_fail("Syntax: checked <name> [+/-] <nr>\n" ); |
| 59 | if (!str || str == "") |
| 60 | return 0; |
| 61 | |
| 62 | if (file_size(CHECKED) > 0) |
| 63 | lines = explode(read_file(CHECKED), "\n") - ({""}); |
| 64 | else |
| 65 | lines = ({}); |
| 66 | |
| 67 | for (drin = ([]), i=sizeof(lines)-1; i>=0; i--) { |
| 68 | if (sscanf(lines[i], "%s%t%d", name, nr) == 2) |
| 69 | drin += ([ name : nr-1 ]); |
| 70 | } |
| 71 | lines = ({ }); |
| 72 | pm = ""; |
| 73 | hp = symbol_function("HausProp", VERWALTER); |
| 74 | |
| 75 | if (sscanf(str, "%s %d", name, nr)==2 || sscanf(str, "%s %s %d", name, pm, nr) == 3) { |
| 76 | if (!funcall(hp, name, HP_ENV)) { |
| 77 | write(capitalize(name)+" hat gar kein Haus!\n"); |
| 78 | return 1; |
| 79 | } |
| 80 | if (nr < 0) { |
| 81 | write("Zum Abziehen nimm bitte 'checked <name> - <nr>'!\n"); |
| 82 | return 1; |
| 83 | } |
| 84 | if (member(drin, name)) |
| 85 | i = drin[name]; |
| 86 | switch(pm) { |
| 87 | case "+": |
| 88 | if (i+nr > funcall(hp, name, HP_ROOMS)) { |
| 89 | printf("%d Raeume? Wie soll das gehen?\n", i+nr); |
| 90 | return 1; |
| 91 | } |
| 92 | drin[name] += nr; |
| 93 | break; |
| 94 | case "-": |
| 95 | if (i-nr < 0) { |
| 96 | write("Soviele Raeume kannst Du "+capitalize(name)+" gar nicht abziehen...\n"); |
| 97 | return 1; |
| 98 | } |
| 99 | drin[name] -= nr; |
| 100 | break; |
| 101 | default: |
| 102 | if (nr > funcall(hp, name, HP_ROOMS)) { |
| 103 | printf("%s nat keine %d Raeume!\n",capitalize(name),nr); |
| 104 | return 1; |
| 105 | } |
| 106 | drin[name] = nr; |
| 107 | } |
| 108 | rm(CHECKED); |
| 109 | for (i=sizeof(ind=sort_array(m_indices(drin),#'<))-1; i>=0; i--) |
| 110 | write_file(CHECKED, sprintf("%s %d\n",ind[i], 1+drin[ind[i]])); |
| 111 | return 1; |
| 112 | } |
| 113 | else |
| 114 | return 0; |
| 115 | } |
| 116 | |
| 117 | static int |
| 118 | report() |
| 119 | { |
| 120 | string *rep, *head, name; |
| 121 | int i, lp, nr; |
| 122 | |
| 123 | if (file_size("/log/report/wurzel.rep")<=0) { |
| 124 | write("Kein wurzel.rep (Jippieh! ;)\n"); |
| 125 | return 1; |
| 126 | } |
| 127 | |
| 128 | rep = old_explode(read_file("/log/report/wurzel.rep"),"\n"); |
| 129 | lp = sizeof(PATH)-1; |
| 130 | |
| 131 | for (i=sizeof(rep)-2; i>=0; i-=2) { |
| 132 | head = old_explode(rep[i], " "); |
| 133 | if (head[4][0..lp] == PATH) { |
| 134 | name = old_explode(head[4],"/")[<1]; |
| 135 | nr = to_int(name[<1..<1]); |
| 136 | name = name[0..<6]; |
| 137 | head[2] = capitalize(head[2]); |
| 138 | write_file(PATH+"rep/"+name, |
| 139 | sprintf("%s in Raum %d:\n%s\n", |
| 140 | implode(head[0..2]," "),nr,rep[i+1])); |
| 141 | } |
| 142 | else |
| 143 | write_file(PATH+"rep/wurzel.rep",sprintf("%s\n%s\n", rep[i], rep[i+1])); |
| 144 | } |
| 145 | return 1; |
| 146 | } |
| 147 | |
| 148 | static int |
| 149 | mkmail(string str) |
| 150 | { |
| 151 | string f,fm; |
| 152 | |
| 153 | if (!str || str == "") { |
| 154 | notify_fail( "Syntax: mkmail <name>\n"); |
| 155 | return 0; |
| 156 | } |
| 157 | |
| 158 | if (!(f=(VERWALTER)->HausProp(str, HP_ENV))) { |
| 159 | printf("%s hat kein Haus!\n", str); |
| 160 | return 1; |
| 161 | } |
| 162 | fm = PATH+str+".mail"; |
| 163 | |
| 164 | write_file(fm, "\ |
| 165 | Huhu!\n\ |
| 166 | \n\ |
| 167 | Da Du Magier bist, brauchst Du auch kein Seherhaus mehr. Damit Deine\n\ |
| 168 | Beschreibungen aber nicht verloren sind, findest Du die Files Deines\n\ |
| 169 | Hauses in /players/"+str+"/seherhaus/.\n\ |
| 170 | \n\ |
| 171 | Soll Dein Haus weiterhin an der jetzigen Stelle stehen bleiben\n\ |
| 172 | ("+f+"),\n\ |
| 173 | so klaere das bitte mit dem dort zustaendigen Magier sowie den zustaen-\n\ |
| 174 | digen Regionsmagiern (weil es sich jetzt um den Anschluss von Files an\n\ |
| 175 | ein Gebiet handelt).\n\ |
| 176 | \n\ |
| 177 | !! Das Haus wird auf jeden Fall nach Ende der Haussperre abgerissen !!\n\ |
| 178 | \n\ |
| 179 | Wargon.\n"); |
| 180 | |
| 181 | return 1; |
| 182 | } |