MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame^] | 1 | #pragma no_clone |
| 2 | #pragma no_inherit |
| 3 | #pragma no_shadow |
| 4 | #pragma strong_types |
| 5 | |
| 6 | #include <properties.h> |
| 7 | #include <events.h> |
| 8 | #include <time.h> |
| 9 | |
| 10 | private string ulog = ""; |
| 11 | |
| 12 | void WaitForQuarterHour() { |
| 13 | while(remove_call_out("QuarterReached")!=-1); |
| 14 | call_out("QuarterReached",900-(time() % 900)); |
| 15 | } |
| 16 | |
| 17 | void create() { |
| 18 | WaitForQuarterHour(); |
| 19 | } |
| 20 | |
| 21 | /* Ueberprueft die als Parameter "str" uebergebene Uhrmeldung. |
| 22 | Rueckgabewerte: 0 fuer fehlerhafte Parameter, |
| 23 | 1 fuer korrekten Aufbau. */ |
| 24 | int CheckClockMsg(string str) |
| 25 | { |
| 26 | int i = strstr(str, "%", 0); |
| 27 | /* Mehr als 1x %d enthalten, mehr als 1x % enthalten, oder auf das einzige |
| 28 | enthaltene % folgt kein "d". */ |
| 29 | if ( sizeof(explode(str,"%d")) > 2 || |
| 30 | sizeof(explode(str,"%")) > 2 || |
| 31 | (i>-1 && ( i==sizeof(str)-1 || str[i+1] != 'd'))) |
| 32 | return 0; |
| 33 | else |
| 34 | return 1; |
| 35 | } |
| 36 | |
| 37 | void QuarterReached() { |
| 38 | int std, minuten; |
| 39 | string str, format; |
| 40 | int off; |
| 41 | |
| 42 | int *lt=localtime(time()); |
| 43 | minuten=lt[TM_MIN]; |
| 44 | std=lt[TM_HOUR]; |
| 45 | mapping edata = mkmapping( |
| 46 | ({TM_SEC, TM_MIN, TM_HOUR, TM_MDAY, TM_MON, TM_YEAR, TM_WDAY, TM_YDAY, |
| 47 | TM_ISDST}), |
| 48 | lt); |
| 49 | |
| 50 | // Clock-Event triggern |
| 51 | EVENTD->TriggerEvent(EVT_LIB_CLOCK, edata); |
| 52 | |
| 53 | // bei Datumswechsel DATECHANGE-Event ausloesen. |
| 54 | if (std==0 && minuten < 15) { |
| 55 | EVENTD->TriggerEvent(EVT_LIB_DATECHANGE, edata); |
| 56 | } |
| 57 | |
| 58 | if (minuten <= 2) { |
| 59 | foreach(object u : users()) { |
| 60 | if((off=to_int(u->QueryProp(P_TIMEZONE)))<0)off+=24; |
| 61 | off=(std+off)%24; |
| 62 | format=u->QueryProp(P_CLOCKMSG)||"Du hoerst die Uhr schlagen: " |
| 63 | "Es ist jetzt %d Uhr.\n"; |
| 64 | if ( !CheckClockMsg(format) ) |
| 65 | { |
| 66 | tell_object(u, break_string( |
| 67 | "So kann ich nicht arbeiten! Deine Uhrmeldung funktioniert so " |
| 68 | "nicht. Bitte korrigiere das.", 78, "Die Uhr teilt Dir mit: ")); |
| 69 | continue; |
| 70 | } |
| 71 | if (strstr(format,"%d",0)==-1) |
| 72 | str=format; |
| 73 | else |
| 74 | str=sprintf(format,off); |
| 75 | if (str!="") tell_object(u,str); |
| 76 | } |
| 77 | } |
| 78 | str = ""; |
| 79 | if (minuten < 10) { |
| 80 | log_file("USER_STATISTIK", ulog); |
| 81 | ulog = sprintf("\n%s%02d: ",(!std?("# "+lt[TM_WDAY]+":\n"):""),std); |
| 82 | } |
| 83 | ulog += sprintf("%4d",sizeof(users())); |
| 84 | WaitForQuarterHour(); |
| 85 | } |
| 86 | |