MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame^] | 1 | // MorgenGrauen MUDlib |
| 2 | // |
| 3 | // newsclient.c -- Nachrichtenbretter |
| 4 | // |
| 5 | // $Id: newsclient.c 8349 2013-02-04 21:15:28Z Zesstra $ |
| 6 | |
| 7 | /* 1992 JOF */ |
| 8 | #pragma strong_types |
| 9 | #pragma save_types |
| 10 | #pragma no_clone |
| 11 | #pragma range_check |
| 12 | #pragma pedantic |
| 13 | |
| 14 | inherit "/std/thing"; |
| 15 | inherit "/std/more"; |
| 16 | |
| 17 | #include <config.h> |
| 18 | #include <properties.h> |
| 19 | #include <news.h> |
| 20 | #include <wizlevels.h> |
| 21 | #include <language.h> |
| 22 | #include <defines.h> |
| 23 | #include <input_to.h> |
| 24 | |
| 25 | string GROUP; |
| 26 | string writer; |
| 27 | string usemsg; |
| 28 | |
| 29 | void SetInUseMessage(string str) |
| 30 | { |
| 31 | usemsg=str; |
| 32 | } |
| 33 | |
| 34 | string SetGroup(string str) |
| 35 | { |
| 36 | return GROUP=str; |
| 37 | } |
| 38 | |
| 39 | protected void create() |
| 40 | { |
| 41 | thing::create(); |
| 42 | writer==""; |
| 43 | |
| 44 | } |
| 45 | |
| 46 | void thinginit() /* If someone doesnt want our add_action he may call this */ |
| 47 | { |
| 48 | thing::init(); |
| 49 | } |
| 50 | |
| 51 | varargs int remove(int silent) |
| 52 | { |
| 53 | return thing::remove(); |
| 54 | } |
| 55 | |
| 56 | void init() |
| 57 | { |
| 58 | thing::init(); |
| 59 | add_action("schreib","schreib",1); |
| 60 | add_action("lies","lies"); |
| 61 | add_action("loesche","loesch",1); |
| 62 | } |
| 63 | |
| 64 | string ladj(string str, int weite) |
| 65 | { |
| 66 | return((str+" ")[0..weite-1]); |
| 67 | } |
| 68 | |
| 69 | string QueryLong() |
| 70 | { |
| 71 | mixed *messages; |
| 72 | string desc; |
| 73 | int i; |
| 74 | |
| 75 | desc=QueryProp(P_LONG); |
| 76 | desc+="\n"; |
| 77 | messages=NEWSSERVER->GetNotes(GROUP); |
| 78 | if (!pointerp(messages) || !sizeof(messages)) |
| 79 | return desc+"Zur Zeit befinden sich keine Nachrichten am Brett.\n"; |
| 80 | if (sizeof(messages)==1) |
| 81 | desc+="Zur Zeit befindet sich eine Nachricht am Brett:\n\n"; |
| 82 | else |
| 83 | desc+="Zur Zeit befinden sich "+sizeof(messages)+" Nachrichten am Brett:\n\n"; |
| 84 | for (i=0;i<sizeof(messages);i++) |
| 85 | { |
| 86 | if (i<9) desc+=" "; |
| 87 | desc+=""+(i+1)+". "; |
| 88 | desc+=(ladj(messages[i][M_TITLE],45)+" ("+ |
| 89 | ladj(messages[i][M_WRITER]+",",13)+ |
| 90 | dtime(messages[i][M_TIME])[4..24] + ")\n"); |
| 91 | } |
| 92 | return desc; |
| 93 | } |
| 94 | |
| 95 | varargs string long(int mode) |
| 96 | { |
| 97 | return QueryLong(); |
| 98 | } |
| 99 | |
| 100 | mixed *message; |
| 101 | |
| 102 | int schreib(string str) |
| 103 | { |
| 104 | int err; |
| 105 | |
| 106 | if (!this_interactive() || !this_interactive()->query_real_name()) return 0; |
| 107 | if (writer) |
| 108 | { |
| 109 | write("Das geht im Moment nicht, da "+capitalize(writer)+" gerade an diesem Brett schreibt.\n"); |
| 110 | if (usemsg) write(usemsg+"\n"); |
| 111 | return 1; |
| 112 | } |
| 113 | _notify_fail("Du musst einen Titel fuer die Notiz angeben !\n"); |
| 114 | if (!str) return 0; |
| 115 | switch (err=NEWSSERVER->AskAllowedWrite(GROUP)) |
| 116 | { |
| 117 | case 1: break; |
| 118 | case -1: write("Du darfst keine Notes an dieses Brett heften !\n"); return 1; |
| 119 | case -3: write("Das Brett ist leider voll !\n"); return 1; |
| 120 | default: write("Interner Fehler "+err+", Erzmagier verstaendigen !\n"); return 1; |
| 121 | } |
| 122 | writer=this_interactive()->query_real_name(); |
| 123 | message=allocate(6); |
| 124 | message[M_BOARD]=GROUP; |
| 125 | message[M_TITLE]=str; |
| 126 | message[M_MESSAGE]=""; |
| 127 | write("Ok, beende Deine Notiz mit '**' oder brich sie mit '~q' ab !\n"); |
| 128 | if (IS_WIZARD(this_player())) |
| 129 | write("Als Magier"+(this_player()->QueryProp(P_GENDER)==FEMALE ? "in" : "")+ |
| 130 | " kannst Du per '~r<filename>' ein File in die Notiz einlesen.\n"); |
| 131 | input_to("get_note_line", INPUT_PROMPT, ":"); |
| 132 | return 1; |
| 133 | } |
| 134 | |
| 135 | int get_note_line(string str) |
| 136 | { |
| 137 | int err; |
| 138 | if (str=="**" || str=="~.") |
| 139 | { |
| 140 | writer=0; |
| 141 | switch (err=(NEWSSERVER->WriteNote(message))) |
| 142 | { |
| 143 | case 1: write("Ok, Nachricht aufgehaengt.\n"); |
| 144 | say(message[M_WRITER]+" hat eine Nachricht ans Brett gehaengt.\n"); |
| 145 | return 1; |
| 146 | case -1: write("Du darfst leider keine Nachrichten hier aufhaengen.\n"); |
| 147 | return 1; |
| 148 | case -3: write("Das Brett ist leider voll !\n"); |
| 149 | return 1; |
| 150 | default: write("Interner Fehler "+err+" aufgetreten ! Bitte Erzmagier verstaendigen.\n"); |
| 151 | return 1; |
| 152 | } |
| 153 | } |
| 154 | if (str=="~q") |
| 155 | { |
| 156 | writer=0; |
| 157 | write("Notiz nicht angeheftet.\n"); |
| 158 | return 1; |
| 159 | } |
| 160 | if (str[0..1]=="~r" && IS_WIZARD(this_player())) { |
| 161 | str=str[2..<1]; |
| 162 | if (str[0]==' ') str=str[1..<1]; |
| 163 | if (!str || catch(err=file_size(str);publish) || err<0) { |
| 164 | write("File nicht gefunden.\n"); |
| 165 | input_to("get_note_line", INPUT_PROMPT, ":"); |
| 166 | return 1; |
| 167 | } |
| 168 | str=read_file(str); |
| 169 | if (!str){ |
| 170 | write("Zu gross!\n"); |
| 171 | input_to("get_note_line", INPUT_PROMPT, ":"); |
| 172 | return 1; |
| 173 | } |
| 174 | write("Ok.\n"); |
| 175 | } |
| 176 | if (message[M_MESSAGE] && message[M_MESSAGE]!="") message[M_MESSAGE]+="\n"; |
| 177 | message[M_MESSAGE]+=str; |
| 178 | input_to("get_note_line", INPUT_PROMPT, ":"); |
| 179 | return 1; |
| 180 | } |
| 181 | |
| 182 | int lies(string str) |
| 183 | { |
| 184 | int num; |
| 185 | mixed *messages; |
| 186 | |
| 187 | if (!str || str=="" || sscanf(str,"%d",num)!=1 || num<=0) |
| 188 | { |
| 189 | _notify_fail("WELCHE Nachricht willst Du lesen ?\n"); |
| 190 | return 0; |
| 191 | } |
| 192 | num--; |
| 193 | messages=(NEWSSERVER->GetNotes(GROUP)); |
| 194 | if (sizeof(messages)<=num) |
| 195 | { |
| 196 | _notify_fail("So viele Nachrichten sind da nicht !\n"); |
| 197 | return 0; |
| 198 | } |
| 199 | this_player()->More(messages[num][M_TITLE]+" ("+messages[num][M_WRITER]+", "+ |
| 200 | dtime(messages[num][M_TIME])[5..26] + "):\n" + |
| 201 | messages[num][M_MESSAGE]); |
| 202 | return 1; |
| 203 | } |
| 204 | |
| 205 | int loesche(string str) |
| 206 | { |
| 207 | int num; |
| 208 | |
| 209 | if (!str || str=="" || sscanf(str,"%d",num)!=1 || num<=0) |
| 210 | { |
| 211 | _notify_fail("WELCHE Nachricht willst Du loeschen ?\n"); |
| 212 | return 0; |
| 213 | } |
| 214 | num--; |
| 215 | switch (NEWSSERVER->RemoveNote(GROUP, num)){ |
| 216 | case 1: write("Ok.\n"); |
| 217 | say(this_player()->name()+" entfernt eine Nachricht vom Brett.\n"); |
| 218 | return 1; |
| 219 | case -1: write("Das darfst Du nicht.\n"); |
| 220 | say(this_player()->name()+" versucht, eine Nachricht vom Brett zu reissen.\n"); |
| 221 | return 1; |
| 222 | case -3: write("So viele Nachrichten sind da nicht !\n"); |
| 223 | return 1; |
| 224 | default: write("Interner Fehler. Bitte Erzmagier verstaendigen !\n"); |
| 225 | return 1; |
| 226 | } |
| 227 | return 0; |
| 228 | } |
| 229 | |
| 230 | void Crumble() |
| 231 | { |
| 232 | if (environment() && living(environment())) |
| 233 | return; |
| 234 | say(capitalize(name(WER))+" zerfaellt zu Staub, der sich sofort verteilt.\n"); |
| 235 | write(capitalize(name(WER))+" zerfaellt zu Staub, der sich sofort verteilt.\n"); |
| 236 | remove(); |
| 237 | } |
| 238 | |
| 239 | varargs int move(object target,mixed method) |
| 240 | { |
| 241 | if (objectp(target)&&!living(target)&&environment()&&living(environment())) |
| 242 | call_out("Crumble",30+random(30)); |
| 243 | return ::move(target, method); |
| 244 | } |