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 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 +/- 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; }