viewing paste Unknown #5881 | Diff

Posted on the
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
Index: src/map/intif.c
===================================================================
--- src/map/intif.c (revision 17327)
+++ src/map/intif.c (working copy)
@@ -43,7 +43,7 @@
    -1, 7, 0, 0,  0, 0, 0, 0,  0, 0, 0, 0,  0, 0,  0, 0, //0x3860  Quests [Kevin] [Inkfish]
    -1, 3, 3, 0,  0, 0, 0, 0,  0, 0, 0, 0, -1, 3,  3, 0, //0x3870  Mercenaries [Zephyrus] / Elemental [pakpil]
    11,-1, 7, 3,  0, 0, 0, 0,  0, 0, 0, 0,  0, 0,  0, 0, //0x3880
-   -1,-1, 7, 3,  0, 0, 0, 0,  0, 0, 0, 0,  0, 0,  0, 0, //0x3890  Homunculus [albator]
+   -1,-1, 7, 3,  15, 10, 0, 0,  0, 0, 0, 0,  0, 0,  0, 0, //0x3890  Homunculus [albator] / VIP
 };
 
 extern int char_fd; // inter server Fd used for char_fd
@@ -2152,6 +2152,28 @@
    return;
 }
 
+void intif_parse_ack_vipActive(int fd){
+   int aid = RFIFOL(inter_fd,2);
+   uint32 vip_time = RFIFOL(inter_fd,6);
+   TBL_PC *sd = map_id2sd(aid);
+   if(sd && vip_time)
+       ; //do stuff with sd
+}
+
+void intif_req_vipActive(TBL_PC *sd, int8 req_duration, int8 type){
+   int len;
+   if (CheckForCharServer() || sd == NULL)
+       return 0;
+   len = packet_len_table[0x3894-0x3800];
+   WFIFOHEAD(inter_fd,len);
+   WFIFOW(inter_fd,0) = 0x3894;
+   WFIFOL(inter_fd,2) = sd->fd; //user fd
+   WFIFOL(inter_fd,6) = sd.bl.id; //aid
+   WFIFOB(inter_fd,10) = type; //type&1 select, type&2 update for new_duration
+   WFIFOL(inter_fd,11) = req_duration;
+   WFIFOSET(inter_fd,len);
+}
+
 //-----------------------------------------------------------------
 // Communication from the inter server
 // Return a 0 (false) if there were any errors.
@@ -2160,7 +2182,7 @@
 {
    int packet_len, cmd;
    cmd = RFIFOW(fd,0);
-    // Verify ID of the packet
+   // Verify ID of the packet
    if(cmd<0x3800 || cmd>=0x3800+(sizeof(packet_len_table)/sizeof(packet_len_table[0])) ||
       packet_len_table[cmd-0x3800]==0){
        return 0;
@@ -2252,6 +2274,7 @@
    case 0x3891:    intif_parse_RecvHomunculusData(fd); break;
    case 0x3892:    intif_parse_SaveHomunculusOk(fd); break;
    case 0x3893:    intif_parse_DeleteHomunculusOk(fd); break;
+   case 0x3895:    intif_parse_ack_vipActive(fd); break;
    default:
        ShowError("intif_parse : unknown packet %d %x\n",fd,RFIFOW(fd,0));
        return 0;
Index: src/char/inter.c
===================================================================
--- src/char/inter.c    (revision 17327)
+++ src/char/inter.c    (working copy)
@@ -55,7 +55,7 @@
     6,-1, 0, 0,  0, 0, 0, 0,  0, 0, 0, 0,  0, 0,  0, 0,    // 3060-  Quest system [Kevin] [Inkfish]
    -1,10, 6,-1,  0, 0, 0, 0,  0, 0, 0, 0, -1,10,  6,-1,    // 3070-  Mercenary packets [Zephyrus], Elemental packets [pakpil]
    48,14,-1, 6,  0, 0, 0, 0,  0, 0, 0, 0,  0, 0,  0, 0,    // 3080-
-   -1,10,-1, 6,  0, 0, 0, 0,  0, 0, 0, 0,  0, 0,  0, 0,    // 3090-  Homunculus packets [albator]
+   -1,10,-1, 6,  15, 10, 0, 0,  0, 0, 0, 0,  0, 0,  0, 0,  // 3090-  Homunculus packets [albator]
 };
 
 struct WisData {
@@ -1153,6 +1153,7 @@
    case 0x3005: mapif_parse_RegistryRequest(fd); break;
    case 0x3006: mapif_parse_NameChangeRequest(fd); break;
    case 0x3007: mapif_parse_accinfo(fd); break;
+   case 0x3894: inter_parse_vipactive(fd); break;
    /* 0x3008 is used by the report stuff */
    default:
        if(  inter_party_parse_frommap(fd)
@@ -1194,4 +1195,50 @@
    return 0;
 }
 
+void inter_vipactive(int fd, int aid, uint32 vip_time){
+   int len = inter_recv_packet_length[0x3895-3000]; //actually we sending this but well
+   WFIFOHEAD(fd,len);
+   WFIFOW(fd,0) = 0x3895;
+   WFIFOL(fd,2) = aid;
+   WFIFOL(fd,6) = vip_time;
+   WFIFOSET(fd,len);
+}
+void inter_parse_vipactive(int fd){
+   int u_fd = RFIFOL(fd,2);
+   int aid = RFIFOL(fd,6);
+   int8 type = RFIFOB(fd,10);
+   uint32 req_duration = RFIFOL(fd,11);
+   uint32 vip_time=0;
+   char data;
 
+   if ( SQL_ERROR == Sql_Query(sql_handle, "SELECT `vip_time` FROM `login` WHERE `account_id` = %d LIMIT 1", aid)
+       || Sql_NumRows(sql_handle) == 0 ) {
+           if( Sql_NumRows(sql_handle) == 0 ) {
+               inter_to_fd(fd, u_fd, aid, "No matches were found for your criteria, '%s'", aid);
+           } else {
+               Sql_ShowDebug(sql_handle);
+               inter_to_fd(fd, u_fd, aid, "An error occured, bother your admin about it.");
+           }
+           Sql_FreeResult(sql_handle);
+           return;
+   } else {
+       if(type&1) {
+           Sql_NextRow(sql_handle);
+           Sql_GetData(sql_handle, 0, &data, NULL); vip_time = data;
+           Sql_FreeResult(sql_handle);
+       }
+       if(type&2) {
+           time_t duration = time(NULL)+req_duration;
+           if(SQL_ERROR == Sql_Query(sql_handle, "UPDATE `login` set `vip_time`= %d WHERE `account_id` = %d LIMIT 1",aid,duration))
+               Sql_ShowDebug(sql_handle);
+           if(SQL_SUCCESS == Sql_Query(sql_handle, "SELECT `vip_time` FROM `login` WHERE `account_id` = %d LIMIT 1", aid)) {
+               Sql_NextRow(sql_handle);
+               Sql_GetData(sql_handle, 0, &data, NULL); vip_time = data;
+               Sql_FreeResult(sql_handle);
+           }
+       }
+   }
+
+   inter_vipactive(fd,aid,vip_time); //send anwser to map
+}
+
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);
Viewed 1375 times, submitted by lighta.