MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame^] | 1 | inherit "std/thing"; |
| 2 | inherit "std/more"; |
| 3 | inherit "/mail/nedit"; |
| 4 | |
| 5 | #include <properties.h> |
| 6 | #include <wizlevels.h> |
| 7 | #include "../haus.h" |
| 8 | |
| 9 | #define FAQ(f) (SPECIALPATH+"faq/"+(f)) |
| 10 | #define FAQUSER ({ "ryne", "toss", "sting" }) |
| 11 | #define IS_USER(pl) (member(FAQUSER, getuid(pl)) >= 0) |
| 12 | |
| 13 | static string *seite; |
| 14 | static string f,*s; |
| 15 | |
| 16 | mapping synonym = ([]); |
| 17 | |
| 18 | create() |
| 19 | { |
| 20 | ::create(); |
| 21 | SetProp(P_NAME,"SeherFAQ"); |
| 22 | SetProp(P_GENDER,FEMALE); |
| 23 | SetProp(P_NOGET,1); |
| 24 | AddId( ({"faq","seherfaq","FAQ","SeherFAQ" }) ); |
| 25 | AddCmd("lies","lesen"); |
| 26 | AddCmd(({"beschreib","beschreibe"}),"beschreiben"); |
| 27 | AddCmd("seiten","seiten"); |
| 28 | AddCmd(({"loesch","loesche"}),"loeschen"); |
| 29 | AddCmd(({"kopier","kopiere"}),"kopieren"); |
| 30 | restore_object(FAQ("faq")); |
| 31 | seite = get_dir(FAQ("*"))-({".","..","faq.o"}); |
| 32 | } |
| 33 | |
| 34 | init() |
| 35 | { |
| 36 | thing::init(); |
| 37 | if (this_player() && IS_USER(this_player())) |
| 38 | nedit::init_rescue(); |
| 39 | } |
| 40 | |
| 41 | string |
| 42 | _query_short() |
| 43 | { |
| 44 | if (this_player() && IS_SEER(this_player())) |
| 45 | return "Die SeherFAQ"; |
| 46 | else |
| 47 | return 0; |
| 48 | } |
| 49 | |
| 50 | string |
| 51 | _query_long() |
| 52 | { |
| 53 | if (this_player() && IS_SEER(this_player())) |
| 54 | return "Dies ist Rynes SeherFAQ.\n\ |
| 55 | Wenn Du weitere Fragen oder Anregungen zu dieser FAQ hast,\n\ |
| 56 | sei so nett und schicke Ryne einen kurzen Brief\n\n\ |
| 57 | Zum Inhalt der FAQ kommst Du mit >lies inhalt<\n"; |
| 58 | else |
| 59 | return 0; |
| 60 | } |
| 61 | |
| 62 | int |
| 63 | id(string str) |
| 64 | { |
| 65 | if (!IS_SEER(this_player())) |
| 66 | return 0; |
| 67 | else |
| 68 | return ::id(str); |
| 69 | } |
| 70 | |
| 71 | int |
| 72 | seiten(string str) |
| 73 | { |
| 74 | int i,j; |
| 75 | string *syn; |
| 76 | closure filter_ldfied; |
| 77 | |
| 78 | if (!IS_USER(this_player())) |
| 79 | return 0; |
| 80 | |
| 81 | if(!(i = sizeof(seite))) |
| 82 | write("Keine Seiten beschrieben!\n"); |
| 83 | else { |
| 84 | filter_ldfied = lambda(({'ind,'page,'map_ldfied/*'*/}), |
| 85 | ({#'==,'page,({#'[/*]'*/,'map_ldfied,'ind})})); |
| 86 | for (str = "",i-=1;i>=0;i--) { |
| 87 | syn = m_indices(filter_indices(synonym,filter_ldfied,seite[i],synonym)); |
| 88 | printf("Seite '%s' - ",seite[i]); |
| 89 | if (j=sizeof(syn)) { |
| 90 | for(j-=1;j>=0;j--) |
| 91 | printf("'%s' ",syn[j]); |
| 92 | write("\n"); |
| 93 | } |
| 94 | else |
| 95 | write( "(keine Synonyme definiert)\n"); |
| 96 | } |
| 97 | } |
| 98 | return 1; |
| 99 | } |
| 100 | |
| 101 | int |
| 102 | lesen(string str) |
| 103 | { |
| 104 | if (!IS_SEER(this_player())) |
| 105 | return 0; |
| 106 | |
| 107 | if (!str || str == "") { |
| 108 | notify_fail("Was willst Du denn lesen?\n"); |
| 109 | return 0; |
| 110 | } |
| 111 | str = lower_case(this_player()->_unparsed_args()); |
| 112 | if (member(seite,str)<0) { |
| 113 | if (!member(synonym,str)) { |
| 114 | notify_fail("Diese Seite gibt es nicht...\n"); |
| 115 | return 0; |
| 116 | } |
| 117 | else |
| 118 | str = synonym[str]; |
| 119 | } |
| 120 | this_player()->More(FAQ(str),1); |
| 121 | return 1; |
| 122 | } |
| 123 | |
| 124 | int |
| 125 | beschreiben(string str) |
| 126 | { |
| 127 | string faq,*desc; |
| 128 | int i; |
| 129 | |
| 130 | if (!IS_USER(this_player())) |
| 131 | return 0; |
| 132 | |
| 133 | str = lower_case(this_player()->_unparsed_args()); |
| 134 | |
| 135 | if (!str || str == "") { |
| 136 | notify_fail("Was willst Du denn beschreiben?\n"); |
| 137 | return 0; |
| 138 | } |
| 139 | if (sscanf(str,"%s %s",faq,str)!=2 || !id(faq)) { |
| 140 | notify_fail("Syntax: beschreibe faq <seite>\n"); |
| 141 | return 0; |
| 142 | } |
| 143 | str = implode(old_explode(str," ")-({""}), " "); |
| 144 | desc = old_explode(implode(old_explode(str,", "),","),","); |
| 145 | f = 0; |
| 146 | s = 0; |
| 147 | |
| 148 | for (i=sizeof(desc)-1;i>=0;i--) { |
| 149 | if (member(seite,desc[i])>=0) { |
| 150 | f = desc[i]; |
| 151 | s = desc-({desc[i]}); |
| 152 | break; |
| 153 | } |
| 154 | } |
| 155 | if (!f) { |
| 156 | f = desc[0]; |
| 157 | s = desc[1..]; |
| 158 | } |
| 159 | write("Bitte Beschreibung fuer die FAQ-Seite '"+f+"' angeben\n"); |
| 160 | nedit("faq"); |
| 161 | return 1; |
| 162 | } |
| 163 | |
| 164 | static void |
| 165 | faq(string str) |
| 166 | { |
| 167 | int i; |
| 168 | string file; |
| 169 | |
| 170 | if (!str || str == 0) { |
| 171 | write("** Abbruch! **\nNichts geaendert!\n"); |
| 172 | return; |
| 173 | } |
| 174 | |
| 175 | if (file_size(file=FAQ(f))>=0) |
| 176 | rm(file); |
| 177 | write_file(file, str); |
| 178 | if (member(seite,f)==-1) |
| 179 | seite += ({f}); |
| 180 | |
| 181 | for (i=sizeof(s)-1;i>=0;i--) |
| 182 | synonym += ([ s[i] : f ]); |
| 183 | |
| 184 | save_object(FAQ("faq")); |
| 185 | } |
| 186 | |
| 187 | int |
| 188 | loeschen(string str) |
| 189 | { |
| 190 | string *syn; |
| 191 | int i; |
| 192 | |
| 193 | if(!IS_USER(this_player())) |
| 194 | return 0; |
| 195 | |
| 196 | str = lower_case(this_player()->_unparsed_args()); |
| 197 | if (!str || str == "") { |
| 198 | notify_fail("Was willst Du denn loeschen?\n"); |
| 199 | return 0; |
| 200 | } |
| 201 | if (member(seite,str)>=0) { |
| 202 | syn = m_indices(filter_indices(synonym, |
| 203 | lambda(({'ind,'page,'map_ldfied/*'*/}), |
| 204 | ({#'==,'page,({#'[/*]'*/,'map_ldfied,'ind})})) |
| 205 | ,seite[i],synonym)); |
| 206 | rm(FAQ(str)); |
| 207 | seite -= ({str}); |
| 208 | } |
| 209 | else { |
| 210 | str = implode(old_explode(str," ")-({""}), " "); |
| 211 | syn = old_explode(implode(old_explode(str,", "),","),","); |
| 212 | } |
| 213 | for (i=sizeof(syn)-1; i>=0; i--) |
| 214 | synonym = filter_indices(synonym, |
| 215 | lambda(({'key,'cmp}), |
| 216 | ({#'!=,'key,'cmp/*'*/})), |
| 217 | syn[i]); |
| 218 | |
| 219 | save_object(FAQ("faq")); |
| 220 | write("OK\n"); |
| 221 | return 1; |
| 222 | } |
| 223 | |
| 224 | int |
| 225 | kopieren(string str) |
| 226 | { |
| 227 | string *part; |
| 228 | int i; |
| 229 | |
| 230 | if (!IS_USER(this_player())) |
| 231 | return 0; |
| 232 | |
| 233 | str = lower_case(this_player()->_unparsed_args()); |
| 234 | part = old_explode(str," ")-({""}); |
| 235 | if(sizeof(part)<4 || !id(part[0]) || part[2] != "nach" || |
| 236 | member(seite,part[1]) == -1) { |
| 237 | notify_fail("kopiere faq <seite> nach <alias>\n"); |
| 238 | return 0; |
| 239 | } |
| 240 | str = part[1]; |
| 241 | part=old_explode(implode(old_explode(implode(part[3..]," "),", "),","),","); |
| 242 | for(i=sizeof(part)-1;i>=0;i--) |
| 243 | synonym += ([ part[i] : str ]); |
| 244 | save_object(FAQ("faq")); |
| 245 | write("OK.\n"); |
| 246 | return 1; |
| 247 | } |