viewing paste ra_timeupd | Diff

Posted on the | Last edited on
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355
Index: src/common/timer.c
===================================================================
--- src/common/timer.c  (revision 17327)
+++ src/common/timer.c  (working copy)
@@ -109,28 +109,28 @@
    } t;
 
    asm volatile("rdtsc":"=a"(t.dw[0]), "=d"(t.dw[1]) );
-   
+
    return t.qw;
 }
 
 static void rdtsc_calibrate(){
    uint64 t1, t2;
    int32 i;
-   
+
    ShowStatus("Calibrating Timer Source, please wait... ");
-   
+
    RDTSC_CLOCK = 0;
-   
+
    for(i = 0; i < 5; i++){
        t1 = _rdtsc();
        usleep(1000000); //1000 MS
        t2 = _rdtsc();
-       RDTSC_CLOCK += (t2 - t1) / 1000; 
+       RDTSC_CLOCK += (t2 - t1) / 1000;
    }
    RDTSC_CLOCK /= 5;
-   
+
    RDTSC_BEGINTICK = _rdtsc();
-   
+
    ShowMessage(" done. (Frequency: %u Mhz)\n", (uint32)(RDTSC_CLOCK/1000) );
 }
 
@@ -243,7 +243,7 @@
 int add_timer(unsigned int tick, TimerFunc func, int id, intptr_t data)
 {
    int tid;
-   
+
    tid = acquire_timer();
    timer_data[tid].tick     = tick;
    timer_data[tid].func     = func;
@@ -267,7 +267,7 @@
        ShowError("add_timer_interval: invalid interval (tick=%u %p[%s] id=%d data=%d diff_tick=%d)\n", tick, func, search_timer_func_list(func), id, data, DIFF_TICK(tick, gettick()));
        return INVALID_TIMER;
    }
-   
+
    tid = acquire_timer();
    timer_data[tid].tick     = tick;
    timer_data[tid].func     = func;
@@ -320,7 +320,7 @@
 int settick_timer(int tid, unsigned int tick)
 {
    size_t i;
-   
+
    // search timer position
    ARR_FIND(0, BHEAP_LENGTH(timer_heap), i, BHEAP_DATA(timer_heap)[i] == tid);
    if( i == BHEAP_LENGTH(timer_heap) )
@@ -406,6 +406,91 @@
    return (unsigned long)difftime(time(NULL), start_time);
 }
 
+void time2str(char *timestr, char *format, int timein){
+   time_t timeout = time(NULL)  + timein;
+   strftime(timestr, 24, format, localtime(&timeout));
+}
+
+/*
+ * Split given timein into your years,month,day,hours,minutes,second
+ */
+void split_time(int timein, int* year, int* month, int* day, int* hour, int* minute, int *second){
+   const int factor_min = 60;
+   const int factor_hour = factor_min*60;
+   const int factor_day = factor_hour*24;
+   const int factor_month = factor_day*30; //approx
+   const int factor_year = factor_month*12; //even worse approx
+
+   *year = timein/factor_year;
+   timein -= *year*factor_year;
+   *month = timein/factor_month;
+   timein -= *month*factor_month;
+   *day = timein/factor_day;
+   timein -= *day*factor_day;
+   *hour = timein/factor_hour;
+   timein -= *hour*factor_hour;
+   *minute = timein/factor_min;
+   timein -= *minute*factor_min;
+   *second = timein;
+
+   *year = max(0,*year);
+   *month = max(0,*month);
+   *day = max(0,*day);
+   *hour = max(0,*hour);
+   *minute = max(0,*minute);
+   *second = max(0,*second);
+}
+
+/*
+ * Create a "timestamp" with the given argument
+ */
+int solve_time(char * modif_p){
+   int totaltime=0, value=0;
+   struct tm then_tm;
+   time_t now = time( NULL);
+   time_t then = now;
+   then_tm = *localtime( &then);
+
+   while (modif_p[0] != '\0') {
+       value = atoi(modif_p);
+       if (value == 0)
+           modif_p++;
+       else {
+           if (modif_p[0] == '-' || modif_p[0] == '+')
+               modif_p++;
+           while (modif_p[0] >= '0' && modif_p[0] <= '9')
+               modif_p++;
+           if (modif_p[0] == 's') {
+               then_tm.tm_sec += value;
+               modif_p++;
+           } else if (modif_p[0] == 'n') {
+               then_tm.tm_min += value;
+               modif_p++;
+           } else if (modif_p[0] == 'm' && modif_p[1] == 'n') {
+               then_tm.tm_min += value;
+               modif_p = modif_p + 2;
+           } else if (modif_p[0] == 'h') {
+               then_tm.tm_hour += value;
+               modif_p++;
+           } else if (modif_p[0] == 'd' || modif_p[0] == 'j') {
+               then_tm.tm_mday += value;
+               modif_p++;
+           } else if (modif_p[0] == 'm') {
+               then_tm.tm_mon += value;
+               modif_p++;
+           } else if (modif_p[0] == 'y' || modif_p[0] == 'a') {
+               then_tm.tm_year += value;
+               modif_p++;
+           } else if (modif_p[0] != '\0') {
+               modif_p++;
+           }
+       }
+   }
+   then = mktime(&then_tm);
+   totaltime = difftime(then,now);
+   return totaltime;
+}
+
 void timer_init(void)
 {
 #if defined(ENABLE_RDTSC)
Index: src/common/timer.h
===================================================================
--- src/common/timer.h  (revision 17327)
+++ src/common/timer.h  (working copy)
@@ -51,6 +51,10 @@
 
 unsigned long get_uptime(void);
 
+void split_time(int time, int* year, int* month, int* day, int* hour, int* minute, int *second);
+int solve_time(char * modif_p);
+void time2str(char *timestr, char *format, int timein);
+
 int do_timer(unsigned int tick);
 void timer_init(void);
 void timer_final(void);
Index: src/map/atcommand.c
===================================================================
--- src/map/atcommand.c (revision 17327)
+++ src/map/atcommand.c (working copy)
@@ -3707,8 +3707,8 @@
        packetdb_readdb();
        clif_displaymessage(fd, msg_txt(sd,1477)); // Packet database has been reloaded.
    }
-       
 
+
    return 0;
 }
 
@@ -4416,34 +4416,6 @@
    return 0;
 }
 
-//Added by Coltaro
-//We're using this function here instead of using time_t so that it only counts player's jail time when he/she's online (and since the idea is to reduce the amount of minutes one by one in status_change_timer...).
-//Well, using time_t could still work but for some reason that looks like more coding x_x
-static void get_jail_time(int jailtime, int* year, int* month, int* day, int* hour, int* minute)
-{
-   const int factor_year = 518400; //12*30*24*60 = 518400
-   const int factor_month = 43200; //30*24*60 = 43200
-   const int factor_day = 1440; //24*60 = 1440
-   const int factor_hour = 60;
-
-   *year = jailtime/factor_year;
-   jailtime -= *year*factor_year;
-   *month = jailtime/factor_month;
-   jailtime -= *month*factor_month;
-   *day = jailtime/factor_day;
-   jailtime -= *day*factor_day;
-   *hour = jailtime/factor_hour;
-   jailtime -= *hour*factor_hour;
-   *minute = jailtime;
-
-   *year = *year > 0? *year : 0;
-   *month = *month > 0? *month : 0;
-   *day = *day > 0? *day : 0;
-   *hour = *hour > 0? *hour : 0;
-   *minute = *minute > 0? *minute : 0;
-   return;
-}
-
 /*==========================================
  * @jail <char_name> by [Yor]
  * Special warp! No check with nowarp and nowarpto flag
@@ -4468,7 +4440,7 @@
    }
 
    if (pc_get_group_level(sd) < pc_get_group_level(pl_sd))
-   { // you can jail only lower or same GM
+   { // you can jail only lower or same GM
        clif_displaymessage(fd, msg_txt(sd,81)); // Your GM level don't authorise you to do this action on this player.
        return -1;
    }
@@ -4541,7 +4513,6 @@
 ACMD_FUNC(jailfor)
 {
    struct map_session_data *pl_sd = NULL;
-   int year, month, day, hour, minute, value;
    char * modif_p;
    int jailtime = 0,x,y;
    short m_index = 0;
@@ -4555,42 +4526,10 @@
    atcmd_output[sizeof(atcmd_output)-1] = '\0';
 
    modif_p = atcmd_output;
-   year = month = day = hour = minute = 0;
-   while (modif_p[0] != '\0') {
-       value = atoi(modif_p);
-       if (value == 0)
-           modif_p++;
-       else {
-           if (modif_p[0] == '-' || modif_p[0] == '+')
-               modif_p++;
-           while (modif_p[0] >= '0' && modif_p[0] <= '9')
-               modif_p++;
-           if (modif_p[0] == 'n') {
-               minute = value;
-               modif_p++;
-           } else if (modif_p[0] == 'm' && modif_p[1] == 'n') {
-               minute = value;
-               modif_p = modif_p + 2;
-           } else if (modif_p[0] == 'h') {
-               hour = value;
-               modif_p++;
-           } else if (modif_p[0] == 'd' || modif_p[0] == 'j') {
-               day = value;
-               modif_p++;
-           } else if (modif_p[0] == 'm') {
-               month = value;
-               modif_p++;
-           } else if (modif_p[0] == 'y' || modif_p[0] == 'a') {
-               year = value;
-               modif_p++;
-           } else if (modif_p[0] != '\0') {
-               modif_p++;
-           }
-       }
-   }
-
-   if (year == 0 && month == 0 && day == 0 && hour == 0 && minute == 0) {
+   jailtime = solve_time(modif_p)/60; //change in minute
+   if(jailtime==0) {
        clif_displaymessage(fd, msg_txt(sd,1136)); // Invalid time for jail command.
+       clif_displaymessage(fd, "Time parameter format is +/-<value> to alter. y/a = Year, m = Month, d/j = Day, h = Hour, n/mn = Minute, s = Second.");
        return -1;
    }
 
@@ -4604,28 +4543,27 @@
        return -1;
    }
 
-   jailtime = year*12*30*24*60 + month*30*24*60 + day*24*60 + hour*60 + minute;    //In minutes
-
-   if(jailtime==0) {
-       clif_displaymessage(fd, msg_txt(sd,1136)); // Invalid time for jail command.
-       return -1;
-   }
-
    //Added by Coltaro
    if(pl_sd->sc.data[SC_JAILED] &&
        pl_sd->sc.data[SC_JAILED]->val1 != INT_MAX)
-   {   //Update the player's jail time
+   {   //Update the player's jail time
        jailtime += pl_sd->sc.data[SC_JAILED]->val1;
        if (jailtime <= 0) {
            jailtime = 0;
            clif_displaymessage(pl_sd->fd, msg_txt(sd,120)); // GM has discharge you.
            clif_displaymessage(fd, msg_txt(sd,121)); // Player unjailed
        } else {
-           get_jail_time(jailtime,&year,&month,&day,&hour,&minute);
+           int year,month,day,hour,minute,second;
+           char timestr[128];
+           split_time(jailtime*60,&year,&month,&day,&hour,&minute,&second);
            sprintf(atcmd_output,msg_txt(sd,402),msg_txt(sd,1137),year,month,day,hour,minute); //%s in jail for %d years, %d months, %d days, %d hours and %d minutes
-           clif_displaymessage(pl_sd->fd, atcmd_output);
+           clif_displaymessage(pl_sd->fd, atcmd_output);
            sprintf(atcmd_output,msg_txt(sd,402),msg_txt(sd,1138),year,month,day,hour,minute); //This player is now in jail for %d years, %d months, %d days, %d hours and %d minutes
-           clif_displaymessage(fd, atcmd_output);
+           clif_displaymessage(fd, atcmd_output);
+           time2str(timestr,"%Y-%m-%d %H:%M",jailtime*60);
+           sprintf(atcmd_output,"Release date is : %s",timestr);
+           clif_displaymessage(pl_sd->fd, atcmd_output);
+           clif_displaymessage(fd, atcmd_output);
        }
    } else if (jailtime < 0) {
        clif_displaymessage(fd, msg_txt(sd,1136));
@@ -4649,11 +4587,10 @@
    return 0;
 }
 
-
 //By Coltaro
-ACMD_FUNC(jailtime)
-{
-   int year, month, day, hour, minute;
+ACMD_FUNC(jailtime) {
+   int year, month, day, hour, minute,second;
+   char timestr[128];
 
    nullpo_retr(-1, sd);
 
@@ -4673,10 +4610,12 @@
    }
 
    //Get remaining jail time
-   get_jail_time(sd->sc.data[SC_JAILED]->val1,&year,&month,&day,&hour,&minute);
+   split_time(sd->sc.data[SC_JAILED]->val1*60,&year,&month,&day,&hour,&minute,&second);
    sprintf(atcmd_output,msg_txt(sd,402),msg_txt(sd,1142),year,month,day,hour,minute); // You will remain in jail for %d years, %d months, %d days, %d hours and %d minutes
-
    clif_displaymessage(fd, atcmd_output);
+   time2str(timestr,"%Y-%m-%d %H:%M",sd->sc.data[SC_JAILED]->val1*60);
+   sprintf(atcmd_output,"Release date is : %s",timestr);
+   clif_displaymessage(fd, atcmd_output);
 
    return 0;
 }
Viewed 1208 times, submitted by lighta.