MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame^] | 1 | // da dieses Objekt in /secure liegt und ROOTID inne hat, muessen besondere |
| 2 | // Sicherheitsvorkehrungen getroffen werden. Insbesondere duerfen keine Files |
| 3 | // aus /std/ inheritet werden, da es fuer diese Files keiner ROOTID bedarf. |
| 4 | |
| 5 | #include <properties.h> |
| 6 | #include <defines.h> |
| 7 | #include "/secure/wizlevels.h" |
| 8 | |
| 9 | static string in_use; |
| 10 | |
| 11 | string thema; |
| 12 | string *moeglichkeiten; |
| 13 | string *ergebnis; |
| 14 | |
| 15 | #undef SAY |
| 16 | |
| 17 | private void SAY( string str ) |
| 18 | { |
| 19 | write ( str ); |
| 20 | write_file("/log/WAHL", str); |
| 21 | } |
| 22 | |
| 23 | void create() |
| 24 | { |
| 25 | if (clonep(ME)) destruct(ME); |
| 26 | if (ergebnis) return; |
| 27 | seteuid(getuid()); |
| 28 | in_use=0; |
| 29 | ergebnis=({({}),({})}); |
| 30 | moeglichkeiten=({}); |
| 31 | restore_object("wahl/wahl"); |
| 32 | move_object(ME, "/gilden/abenteurer"); |
| 33 | } |
| 34 | |
| 35 | varargs string name(int casus, int demon) |
| 36 | { |
| 37 | if (demon==RAW) return "Wahlmaschine"; |
| 38 | switch(casus) { |
| 39 | case WEM: |
| 40 | case WESSEN: |
| 41 | if (demon==1) |
| 42 | return "der Wahlmaschine"; |
| 43 | return "einer Wahlmaschine"; |
| 44 | default: |
| 45 | if (demon==1) |
| 46 | return "die Wahlmaschine"; |
| 47 | return "eine Wahlmaschine"; |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | varargs string Name(int casus, int demon) |
| 52 | { return capitalize(name(casus, demon)); } |
| 53 | |
| 54 | |
| 55 | public string QueryPronoun(int casus) |
| 56 | { |
| 57 | switch(casus) |
| 58 | { |
| 59 | case WER: |
| 60 | return "sie"; |
| 61 | break; |
| 62 | case WEM: |
| 63 | return "ihr"; |
| 64 | } |
| 65 | return "sie"; |
| 66 | } |
| 67 | |
| 68 | string short() |
| 69 | { return "Eine Wahlmaschine.\n"; } |
| 70 | |
| 71 | string long() |
| 72 | { |
| 73 | return "Eine Wahlmaschine. Mit ihr koennen geheime Wahlen durchgefuehrt werden.\n"+ |
| 74 | "Aktuelles Thema: "+(stringp(thema) ? thema : "keines")+"\n"; |
| 75 | } |
| 76 | |
| 77 | mixed Query(mixed param) |
| 78 | { |
| 79 | if (!stringp(param)) return 0; |
| 80 | switch (param) { |
| 81 | case P_NOGET: return 1; |
| 82 | case P_GENDER: return FEMALE; |
| 83 | case P_NAME: return "Wahlmaschine"; |
| 84 | } |
| 85 | return 0; |
| 86 | } |
| 87 | |
| 88 | mixed QueryProp(mixed param) |
| 89 | { return Query(param); } |
| 90 | |
| 91 | int Set(mixed param) |
| 92 | { return -1; } |
| 93 | |
| 94 | int SetProp(mixed param) |
| 95 | { return -1; } |
| 96 | |
| 97 | varargs int id(string str, int lvl) |
| 98 | { return (member(({"maschine", "waehler", "wahlmaschine"}), str)!=-1); } |
| 99 | |
| 100 | // ab hier kommt der eigentliche Code der Wahlmaschine |
| 101 | |
| 102 | void init() |
| 103 | { |
| 104 | add_action("waehle", "waehl",1); |
| 105 | add_action("auswertung","auswertung"); |
| 106 | add_action("wahlthema", "wahlthema"); |
| 107 | add_action("moeglichkeit","moeglichkeit"); |
| 108 | } |
| 109 | |
| 110 | void save_me() |
| 111 | { save_object("wahl/wahl"); } |
| 112 | |
| 113 | static int waehle() |
| 114 | { |
| 115 | int i; |
| 116 | mixed second; |
| 117 | |
| 118 | if (!RPL) return 0; |
| 119 | if (RPL->QueryProp(P_LEVEL)<10) { |
| 120 | notify_fail("Man kann erst ab Stufe 10 mitwaehlen :(\n"); |
| 121 | return 0; |
| 122 | } |
| 123 | if (RPL->QueryProp(P_TESTPLAYER)) { |
| 124 | notify_fail("Testspieler sind von der Wahl ausgeschlossen.\n"); |
| 125 | return 0; |
| 126 | } |
| 127 | if ((second=RPL->QueryProp(P_SECOND)) && |
| 128 | (!stringp(second) || (file_size("/save/"+lower_case(second[0..0])+"/"+lower_case(second)+".o")<=0))) { |
| 129 | notify_fail("Nicht richtig markierte Zweities sind von der Wahl ausgeschlossen.\n"); |
| 130 | return 0; |
| 131 | } |
| 132 | if (in_use) |
| 133 | { |
| 134 | write(in_use+" waehlt gerade, warte also bitte einen Augenblick.\n"); |
| 135 | return 1; |
| 136 | } |
| 137 | in_use=capitalize(getuid(RPL)); |
| 138 | say(in_use+" tritt an die Wahlmaschine.\n"); |
| 139 | write(long()); |
| 140 | write("Das steht zur Auswahl:\n"); |
| 141 | for (i=0;i<sizeof(moeglichkeiten);i++) |
| 142 | write(sprintf(" -- %d.) %s\n",i+1,moeglichkeiten[i])); |
| 143 | write("Triff nun Deine Wahl (sie ist UNSICHTBAR): "); |
| 144 | input_to("waehle_2",1); |
| 145 | return 1; |
| 146 | } |
| 147 | |
| 148 | private int falsch() |
| 149 | { |
| 150 | write("Diese Auswahl ist ungueltig. Versuchs bitte gleich nochmal.\n"); |
| 151 | say(in_use+" hat ausgewaehlt.\n"); |
| 152 | in_use=0; |
| 153 | return 1; |
| 154 | } |
| 155 | |
| 156 | static int waehle_2(string str) |
| 157 | { |
| 158 | int i; |
| 159 | mixed name; |
| 160 | |
| 161 | if (!str) return falsch(); |
| 162 | |
| 163 | name=RPL->QueryProp(P_SECOND); |
| 164 | if (!stringp(name)) |
| 165 | name=getuid(RPL); |
| 166 | else name=lower_case(name); |
| 167 | |
| 168 | if (member_array(str, moeglichkeiten)==-1) { |
| 169 | if ( !sscanf( str, "%d", i ) ) return falsch(); |
| 170 | if ( i<1 || i>sizeof(moeglichkeiten) ) return falsch(); |
| 171 | ergebnis=insert_alist(name,moeglichkeiten[i-1],ergebnis); |
| 172 | } |
| 173 | else ergebnis=insert_alist(name,str,ergebnis); |
| 174 | write("Ok.\n"); |
| 175 | save_me(); |
| 176 | say(in_use+" hat ausgewaehlt.\n"); |
| 177 | in_use=0; |
| 178 | return 1; |
| 179 | } |
| 180 | |
| 181 | static int auswertung() |
| 182 | { |
| 183 | int i,j,max,all; |
| 184 | mapping stimmen, data; |
| 185 | mixed names; |
| 186 | |
| 187 | if (!ARCH_SECURITY || process_call()) return 0; |
| 188 | |
| 189 | rm("/log/WAHL"); |
| 190 | |
| 191 | data = mkmapping(ergebnis[0], ergebnis[1]); |
| 192 | names = m_indices(data); |
| 193 | stimmen = ([]); |
| 194 | |
| 195 | SAY("\n\n\nWahlergebnisse zum Thema: "+thema+"\n"); |
| 196 | SAY("\nGewaehlt haben folgende Personen: \n"); |
| 197 | SAY(break_string(CountUp(map(sort_array(names, #'>/*'*/), #'capitalize/*'*/)), 78)); |
| 198 | SAY("\n"); |
| 199 | |
| 200 | while(sizeof(names)) { |
| 201 | stimmen[data[names[0]]]++; |
| 202 | names[0..0] = ({}); |
| 203 | all++; |
| 204 | } |
| 205 | |
| 206 | SAY("*****************************************\n"); |
| 207 | SAY("Ergebnis:\n"); |
| 208 | for (i=0;i<sizeof(moeglichkeiten);i++) |
| 209 | SAY(sprintf(" -- %2d.) %20s: %3d (%' '3.2f%%)\n", i+1, moeglichkeiten[i], |
| 210 | stimmen[moeglichkeiten[i]], 1.0 * stimmen[moeglichkeiten[i]] * 100.0 / (1.0 * all))); |
| 211 | SAY(sprintf("Gesamtstimmen: %d\n", sizeof(m_indices(data)))); |
| 212 | return 1; |
| 213 | } |
| 214 | |
| 215 | static int wahlthema(string str) |
| 216 | { |
| 217 | if (!ARCH_SECURITY || process_call()) { |
| 218 | write("NOT allowed"); |
| 219 | return 0; |
| 220 | } |
| 221 | if (!(str=this_interactive()->_unparsed_args())) return 0; |
| 222 | thema=str; |
| 223 | say(RPL->name(WER)+" setzt ein neues Abstimmungsthema fest.\n"); |
| 224 | ergebnis=({({}),({})}); |
| 225 | moeglichkeiten=({}); |
| 226 | write("Ok.\n"); |
| 227 | save_me(); |
| 228 | return 1; |
| 229 | } |
| 230 | |
| 231 | static int moeglichkeit(string str) |
| 232 | { |
| 233 | if (!ARCH_SECURITY || process_call()) { |
| 234 | write("NOT allowed"); |
| 235 | return 0; |
| 236 | } |
| 237 | if (!(str=RPL->_unparsed_args())) return 0; |
| 238 | if (member_array(str, moeglichkeiten) != -1) { |
| 239 | write("Schon drin.\n"); |
| 240 | return 1; |
| 241 | } |
| 242 | moeglichkeiten+=({str}); |
| 243 | write("Ok.\n"); |
| 244 | save_me(); |
| 245 | return 1; |
| 246 | } |
| 247 | |
| 248 | mixed _internal() |
| 249 | { |
| 250 | if (!ARCH_SECURITY || process_call()) return 0; |
| 251 | return ergebnis; |
| 252 | } |