viewing paste Unknown #5758 | 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 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 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521
Index: src/common/mmo.h
===================================================================
--- src/common/mmo.h    (revision 17301)
+++ src/common/mmo.h    (working copy)
@@ -47,7 +47,7 @@
 // 20120307 - 2012-03-07aRagexeRE+ - 0x970
 
 #ifndef PACKETVER
-       #define PACKETVER 20120410
+       #define PACKETVER 20130320
        //#define PACKETVER 20111116
 #endif
 
Index: src/map/mob.c
===================================================================
--- src/map/mob.c       (revision 17301)
+++ src/map/mob.c       (working copy)
@@ -159,9 +159,9 @@
        map_addnpc(nd->bl.m, nd);
        map_addblock(&nd->bl);
        status_set_viewdata(&nd->bl, nd->class_);
-    status_change_init(&nd->bl);
-    unit_dataset(&nd->bl);
-    clif_spawn(&nd->bl);
+       status_change_init(&nd->bl);
+       unit_dataset(&nd->bl);
+       clif_spawn(&nd->bl);
 
 }
 
@@ -2491,7 +2491,7 @@
 
                        for(i = 0; i < MAX_MVP_DROP; i++) {
                                while( 1 ) {
-                                       int va = rand()%MAX_MVP_DROP;
+                                       int va = rnd()%MAX_MVP_DROP;
                                        if( !mdrop_id[va] || !md->db->mvpitem[i].nameid ) {
                                                mdrop_id[va] = md->db->mvpitem[i].nameid;
                                                mdrop_p[va]  = md->db->mvpitem[i].p;
Index: src/map/clif.c
===================================================================
--- src/map/clif.c      (revision 17301)
+++ src/map/clif.c      (working copy)
@@ -1271,11 +1271,6 @@
                        clif_specialeffect_single(&sd->bl, 163, fd);
                if (map[m].flag.leaves)
                        clif_specialeffect_single(&sd->bl, 333, fd);
-               /**
-                * No longer available, keeping here just in case it's back someday. [Ind]
-                **/
-               //if (map[m].flag.rain)
-               //      clif_specialeffect_single(&sd->bl, 161, fd);
        }
 }
 /**
@@ -1714,8 +1709,7 @@
        WBUFW(buf,8) = bl->y;
        clif_send(buf, packet_len(0x88), bl, AREA);
 
-       if( disguised(bl) )
-       {
+       if( disguised(bl) ) {
                WBUFL(buf,2) = -bl->id;
                clif_send(buf, packet_len(0x88), bl, SELF);
        }
@@ -1882,8 +1876,7 @@
 /*==========================================
  *
  *------------------------------------------*/
-void clif_sendfakenpc(struct map_session_data *sd, int npcid)
-{
+void clif_sendfakenpc(struct map_session_data *sd, int npcid) {
        unsigned char *buf;
        int fd = sd->fd;
        sd->state.using_fake_npc = 1;
@@ -2240,8 +2233,7 @@
 // Simplifies inventory/cart/storage packets by handling the packet section relevant to items. [Skotlex]
 // Equip is >= 0 for equippable items (holds the equip-point, is 0 for pet
 // armor/egg) -1 for stackable items, -2 for stackable items where arrows must send in the equip-point.
-void clif_item_sub(unsigned char *buf, int n, struct item *i, struct item_data *id, int equip)
-{
+void clif_item_sub(unsigned char *buf, int n, struct item *i, struct item_data *id, int equip) {
        if (id->view_id > 0)
                WBUFW(buf,n)=id->view_id;
        else
@@ -2264,8 +2256,7 @@
 }
 void clif_favorite_item(struct map_session_data* sd, unsigned short index);
 //Unified inventory function which sends all of the inventory (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
-void clif_inventorylist(struct map_session_data *sd)
-{
+void clif_inventorylist(struct map_session_data *sd) {
        int i,n,ne,arrow=-1;
        unsigned char *buf;
        unsigned char *bufe;
@@ -2340,8 +2331,7 @@
        if( arrow >= 0 )
                clif_arrowequip(sd,arrow);
 
-       if( ne )
-       {
+       if( ne ) {
 #if PACKETVER < 20071002
                WBUFW(bufe,0)=0xa4;
 #else
@@ -3111,8 +3101,7 @@
 ///     <int>.B <need int>.B <dex>.B <need dex>.B <luk>.B <need luk>.B <atk>.W <atk2>.W
 ///     <matk min>.W <matk max>.W <def>.W <def2>.W <mdef>.W <mdef2>.W <hit>.W
 ///     <flee>.W <flee2>.W <crit>.W <aspd>.W <aspd2>.W
-void clif_initialstatus(struct map_session_data *sd)
-{
+void clif_initialstatus(struct map_session_data *sd) {
        int fd, mdef2;
        unsigned char *buf;
 
Index: src/map/npc.c
===================================================================
--- src/map/npc.c       (revision 17301)
+++ src/map/npc.c       (working copy)
@@ -262,19 +262,7 @@
        }
 
        if( DIFF_TICK(tick,sd->npc_idle_tick) > (timeout*1000) ) {
-               /**
-                * If we still have the NPC script attached, tell it to stop.
-                **/
-               if( sd->st )
-                       sd->st->state = END;
-               sd->state.menu_or_input = 0;
-               sd->npc_menu = 0;
-
-               /**
-                * This guy's been idle for longer than allowed, close him.
-                **/
-               clif_scriptclose(sd,sd->npc_id);
-               sd->npc_idle_timer = INVALID_TIMER;
+               pc_close_npc(sd,1);
        } else //Create a new instance of ourselves to continue
                sd->npc_idle_timer = add_timer(gettick() + (SECURE_NPCTIMEOUT_INTERVAL*1000),npc_rr_secure_timeout_timer,sd->bl.id,0);
        return 0;
@@ -1248,14 +1236,8 @@
                        return 1;
                }
        }
-       /**
-        * For the Secure NPC Timeout option (check config/Secure.h) [RR]
-        **/
 #ifdef SECURE_NPCTIMEOUT
-       /**
-        * Update the last NPC iteration
-        **/
-       sd->npc_idle_tick = gettick();
+       sd->npc_idle_tick = gettick(); //Update the last NPC iteration
 #endif
 
        /**
@@ -1290,7 +1272,7 @@
                        sd->npc_id=0;
                return 1;
        }
-    if (nd->sc.option & OPTION_INVISIBLE) // can't buy if npc is not visible (hack?)
+       if (nd->sc.option & OPTION_INVISIBLE) // can't buy if npc is not visible (hack?)
                return 1;
        if( nd->class_ < 0 && !sd->state.callshop )
        {// not called through a script and is not a visible NPC so an invalid call
Index: src/map/npc.h
===================================================================
--- src/map/npc.h       (revision 17301)
+++ src/map/npc.h       (working copy)
@@ -175,9 +175,6 @@
 
 int npc_cashshop_buylist(struct map_session_data *sd, int points, int count, unsigned short* item_list);
 
-/**
- * For the Secure NPC Timeout option (check config/Secure.h) [RR]
- **/
 #ifdef SECURE_NPCTIMEOUT
        int npc_rr_secure_timeout_timer(int tid, unsigned int tick, int id, intptr_t data);
 #endif
Index: src/map/pc.c
===================================================================
--- src/map/pc.c        (revision 17301)
+++ src/map/pc.c        (working copy)
@@ -965,13 +965,9 @@
        sd->invincible_timer = INVALID_TIMER;
        sd->npc_timer_id = INVALID_TIMER;
        sd->pvp_timer = INVALID_TIMER;
-       /**
-        * For the Secure NPC Timeout option (check config/Secure.h) [RR]
-        **/
+
 #ifdef SECURE_NPCTIMEOUT
-       /**
-        * Initialize to defaults/expected
-        **/
+       // Initialize to defaults/expected
        sd->npc_idle_timer = INVALID_TIMER;
        sd->npc_idle_tick = tick;
        sd->npc_idle_type = NPCT_INPUT;
@@ -6569,6 +6565,29 @@
        sd->canlog_tick = gettick();
 }
 
+/*
+ *  Method to properly close npc for player and clear anything related
+ * @flag == 1 : produce close button
+ * @flag == 2 : directly close it
+ */
+void pc_close_npc(struct map_session_data *sd,int flag) {
+       if (sd->npc_id) {
+               if (sd->state.using_fake_npc) {
+                       clif_clearunit_single(sd->npc_id, CLR_OUTSIGHT, sd->fd);
+                       sd->state.using_fake_npc = 0;
+               }
+               if (sd->st) {
+                       sd->st->state = ((flag==1)?CLOSE:END);
+                       sd->st->mes_active = 0;
+               }
+               sd->state.menu_or_input = 0;
+               sd->npc_menu = 0;
+               sd->npc_idle_timer = INVALID_TIMER;
+               clif_scriptclose(sd,sd->npc_id);
+               sd->npc_id = 0;
+       }
+}
+
 /*==========================================
  * Invoked when a player has negative current hp
  *------------------------------------------*/
@@ -6620,22 +6639,8 @@
                        duel_reject(sd->duel_invite, sd);
        }
 
-       // Clear anything NPC-related when you die and was interacting with one.
-       if (sd->npc_id) {
-               if (sd->state.using_fake_npc) {
-                       clif_clearunit_single(sd->npc_id, CLR_OUTSIGHT, sd->fd);
-                       sd->state.using_fake_npc = 0;
-               }
-               if (sd->state.menu_or_input)
-                       sd->state.menu_or_input = 0;
-               if (sd->npc_menu)
-                       sd->npc_menu = 0;
+       pc_close_npc(sd,2); //close npc if we were using one
 
-               sd->npc_id = 0;
-               if (sd->st && sd->st->state != END)
-                       sd->st->state = END;
-       }
-
        /* e.g. not killed thru pc_damage */
        if( pc_issit(sd) ) {
                clif_status_load(&sd->bl,SI_SIT,0);
Index: src/map/pc.h
===================================================================
--- src/map/pc.h        (revision 17301)
+++ src/map/pc.h        (working copy)
@@ -472,9 +472,6 @@
        unsigned int bg_id;
        unsigned short user_font;
 
-       /**
-        * For the Secure NPC Timeout option (check config/Secure.h) [RR]
-        **/
 #ifdef SECURE_NPCTIMEOUT
        /**
         * ID of the timer
@@ -720,6 +717,7 @@
 bool pc_authok(struct map_session_data *sd, int login_id2, time_t expiration_time, int group_id, struct mmo_charstatus *st, bool changing_mapservers);
 void pc_authfail(struct map_session_data *);
 int pc_reg_received(struct map_session_data *sd);
+void pc_close_npc(struct map_session_data *sd,int flag);
 
 int pc_isequip(struct map_session_data *sd,int n);
 int pc_equippoint(struct map_session_data *sd,int n);
Index: src/map/cashshop.c
===================================================================
--- src/map/cashshop.c  (revision 17301)
+++ src/map/cashshop.c  (working copy)
@@ -15,13 +15,59 @@
 #include <string.h> // memset
 #include <stdlib.h> // atoi
 
-static int cashshop_parse_dbrow( char** str, const char* source, int line );
-
 struct cash_item_db cash_shop_items[CASHSHOP_TAB_SEARCH];
 
 extern char item_cash_db_db[32];
 extern char item_cash_db2_db[32];
 
+/*
+ * Read one line of db and assign it to ram
+ * return
+ *  0 = failure
+ *  1 = succes
+ */
+static int cashshop_parse_dbrow( char** str, const char* source, int line ){
+       uint32 nameid = atoi( str[1] );
+
+       if( itemdb_exists( nameid ) ){
+               uint16 tab = atoi( str[0] );
+               uint32 price = atoi( str[2] );
+               struct cash_item_data* cid;
+               int j;
+
+               if( tab > CASHSHOP_TAB_SEARCH ){
+                       ShowWarning( "cashshop_parse_dbrow: Invalid tab %d in line %d of \"%s\", skipping.\n", tab, line, source );
+                       return 0;
+               }else if( price < 1 ){
+                       ShowWarning( "cashshop_parse_dbrow: Invalid price %d in line %d of \"%s\", skipping.\n", price, line, source );
+                       return 0;
+               }
+
+               ARR_FIND( 0, cash_shop_items[tab].count, j, nameid == cash_shop_items[tab].item[j]->nameid );
+
+               if( j == cash_shop_items[tab].count ){
+                       RECREATE( cash_shop_items[tab].item, struct cash_item_data *, ++cash_shop_items[tab].count );
+                       CREATE( cash_shop_items[tab].item[ cash_shop_items[tab].count - 1], struct cash_item_data, 1 );
+                       cid = cash_shop_items[tab].item[ cash_shop_items[tab].count - 1];
+               }else{
+                       cid = cash_shop_items[tab].item[j];
+               }
+
+               cid->nameid = nameid;
+               cid->price = price;
+
+               return 1;
+       }else{
+               ShowWarning( "cashshop_parse_dbrow: Invalid id %d in line %d of \"%s\", skipping.\n", nameid, line, source );
+       }
+
+       return 0;
+}
+
+/*
+ * Read database from txt format,
+ * parse line and send them to parse_dbrow
+ */
 static void cashshop_read_db_txt( void ){
        const char* filename[] = { DBPATH"item_cash_db.txt", "item_cash_db2.txt" };
        int fi;
@@ -88,6 +134,10 @@
        }
 }
 
+/*
+ * Read database from sql format,
+ * parse line and send them to parse_dbrow
+ */
 static int cashshop_read_db_sql( void ){
        const char* cash_db_name[] = { item_cash_db_db, item_cash_db2_db };
        int fi;
@@ -128,6 +178,11 @@
        return 0;
 }
 
+/*
+ * Read cashshop database main
+ * choose wich reader to use depending of config :
+ * conf/map_athena.conf  db_use_sqldbs
+ */
 static void cashshop_read_db( void ){
        if( db_use_sqldbs ){
                cashshop_read_db_sql();
@@ -136,44 +191,12 @@
        }
 }
 
-static int cashshop_parse_dbrow( char** str, const char* source, int line ){
-       uint32 nameid = atoi( str[1] );
-
-       if( itemdb_exists( nameid ) ){
-               uint16 tab = atoi( str[0] );
-               uint32 price = atoi( str[2] );
-               struct cash_item_data* cid;
-               int j;
-
-               if( tab > CASHSHOP_TAB_SEARCH ){
-                       ShowWarning( "cashshop_parse_dbrow: Invalid tab %d in line %d of \"%s\", skipping.\n", tab, line, source );
-                       return 0;
-               }else if( price < 1 ){
-                       ShowWarning( "cashshop_parse_dbrow: Invalid price %d in line %d of \"%s\", skipping.\n", price, line, source );
-                       return 0;
-               }
-
-               ARR_FIND( 0, cash_shop_items[tab].count, j, nameid == cash_shop_items[tab].item[j]->nameid );
-
-               if( j == cash_shop_items[tab].count ){
-                       RECREATE( cash_shop_items[tab].item, struct cash_item_data *, ++cash_shop_items[tab].count );
-                       CREATE( cash_shop_items[tab].item[ cash_shop_items[tab].count - 1], struct cash_item_data, 1 );
-                       cid = cash_shop_items[tab].item[ cash_shop_items[tab].count - 1];
-               }else{
-                       cid = cash_shop_items[tab].item[j];
-               }
-
-               cid->nameid = nameid;
-               cid->price = price;
-
-               return 1;
-       }else{
-               ShowWarning( "cashshop_parse_dbrow: Invalid id %d in line %d of \"%s\", skipping.\n", nameid, line, source );
-       }
-
-       return 0;
-}
-
+/*
+ * Attempt to buy a cashshop item from list
+ * check if valid transaction and if user have enough place to receive item
+ * if yes take cashpoint and give else
+ * else return clif_error
+ */
 void cashshop_buylist( struct map_session_data* sd, uint32 kafrapoints, int n, uint16* item_list ){
        uint32 totalcash = 0;
        uint32 totalweight = 0;
@@ -227,10 +250,7 @@
                totalweight += itemdb_weight( nameid ) * quantity;
        }
 
-       if( ( totalcash - kafrapoints ) > sd->cashPoints || kafrapoints > sd->kafraPoints ){
-               clif_cashshop_result( sd, 0, CASHSHOP_RESULT_ERROR_SHORTTAGE_CASH );
-               return;
-       }else if( ( totalweight + sd->weight ) > sd->max_weight ){
+       if( ( totalweight + sd->weight ) > sd->max_weight ){
                clif_cashshop_result( sd, 0, CASHSHOP_RESULT_ERROR_INVENTORY_WEIGHT );
                return;
        }else if( pc_inventoryblank( sd ) < new_ ){
@@ -238,7 +258,10 @@
                return;
        }
 
-       pc_paycash( sd, totalcash, kafrapoints, LOG_TYPE_CASH );
+       if(pc_paycash( sd, totalcash, kafrapoints, LOG_TYPE_CASH ) < 0){
+               clif_cashshop_result( sd, 0, CASHSHOP_RESULT_ERROR_SHORTTAGE_CASH );
+               return;
+       }
 
        for( i = 0; i < n; ++i ){
                uint32 nameid = *( item_list + i * 5 );
@@ -273,11 +296,19 @@
        clif_cashshop_result( sd, 0, CASHSHOP_RESULT_SUCCESS );
 }
 
+/*
+ * Reload database of cashshop
+ * by destroying and read it again
+ */
 void cashshop_reloaddb( void ){
        do_final_cashshop();
        do_init_cashshop();
 }
 
+/*
+ * Destroy cashshop class
+ * Close all and cleanup
+ */
 int do_final_cashshop( void ){
        int tab, i;
 
@@ -285,15 +316,18 @@
                for( i = 0; i < cash_shop_items[tab].count; i++ ){
                        aFree( cash_shop_items[tab].item[i] );
                }
-
                aFree( cash_shop_items[tab].item );
        }
-
        memset( cash_shop_items, 0, sizeof( cash_shop_items ) );
 
        return 0;
 }
 
+/*
+ * Initialise cashshop class
+ * return
+ *  0 : success
+ */
 int do_init_cashshop( void ){
        cashshop_read_db();
 
Index: src/map/script.c
===================================================================
--- src/map/script.c    (revision 17301)
+++ src/map/script.c    (working copy)
@@ -3606,9 +3606,7 @@
                        st->bk_st = NULL;
                        st->bk_npcid = 0;
                } else if(dequeue_event) {
-                       /**
-                        * For the Secure NPC Timeout option (check config/Secure.h) [RR]
-                        **/
+
 #ifdef SECURE_NPCTIMEOUT
                        /**
                         * We're done with this NPC session, so we cancel the timer (if existent) and move on
@@ -3652,9 +3650,6 @@
                sd->st = st;
                sd->npc_id = st->oid;
                sd->npc_item_flag = st->npc_item_flag; // load default.
-/**
- * For the Secure NPC Timeout option (check config/Secure.h) [RR]
- **/
 #ifdef SECURE_NPCTIMEOUT
                if( sd->npc_idle_timer == INVALID_TIMER )
                        sd->npc_idle_timer = add_timer(gettick() + (SECURE_NPCTIMEOUT_INTERVAL*1000),npc_rr_secure_timeout_timer,sd->bl.id,0);
@@ -6916,6 +6911,7 @@
 
        ShowError("script:delitem: failed to delete %d items (AID=%d item_id=%d).\n", it.amount, sd->status.account_id, it.nameid);
        st->state = END;
+       st->mes_active = 0;
        clif_scriptclose(sd, st->oid);
        return 1;
 }
@@ -6992,6 +6988,7 @@
 
        ShowError("script:delitem2: failed to delete %d items (AID=%d item_id=%d).\n", it.amount, sd->status.account_id, it.nameid);
        st->state = END;
+       sd->st->mes_active = 0;
        clif_scriptclose(sd, st->oid);
        return 1;
 }
Viewed 526 times, submitted by lighta.