viewing paste Unknown #6081 | 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
Index: src/map/guild.c
===================================================================
--- src/map/guild.c (revision 17347)
+++ src/map/guild.c (working copy)
@@ -786,6 +786,25 @@
 /*==========================================
  * Player request leaving a given guild_id
  *----------------------------------------*/
+
+int itemdb_guildbound_chk(TBL_PC *sd,int type,int *idxlist){
+   int i=0, j=0;
+   switch(type){
+   case 1: //cehck in inventory
+       for(i=0;i<MAX_INVENTORY;i++){
+           if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].amount > 0 && sd->status.inventory[i].bound == 2) {
+               idxlist[j] = i;
+               j++;
+           }
+       }
+       break;
+   case 2: //check in cart
+   case 3: //check in storage
+       break;
+   }
+   return j;
+}
+
 int guild_leave(struct map_session_data* sd, int guild_id, int account_id, int char_id, const char* mes)
 {
    struct guild *g;
@@ -828,7 +847,7 @@
    if( (ps=guild_getposition(g,sd))<0 || !(g->position[ps].mode&0x0010) )
        return 0;   //Expulsion permission
 
-   //Can't leave inside guild castles.
+   //Can't leave inside guild castles.
    if ((tsd = map_id2sd(account_id)) &&
        tsd->status.char_id == char_id &&
        ((agit_flag || agit2_flag) && map[tsd->bl.m].flag.gvg_castle))
@@ -842,6 +861,26 @@
    return 0;
 }
 
+int guild_retrieveitembound(int char_id,int aid,int guild_id) {
+   TBL_PC *sd = map_id2sd(aid);
+   if(sd){ //char is online
+       int idxlist[MAX_INVENTORY]; //or malloc to reduce consumtion
+       int j,i;
+       j = itemdb_guildbound_chk(sd,1,idxlist);
+       if(j) {
+           struct guild_storage* stor = guild2storage(sd->status.guild_id);
+           for(i=0;i<j;i++) {
+               guild_storage_additem(sd,stor,&sd->status.inventory[idxlist[i]],sd->status.inventory[idxlist[i]].amount);
+               pc_delitem(sd,idxlist[i],sd->status.inventory[idxlist[i]].amount,0,4,LOG_TYPE_GSTORAGE);
+           }
+           storage_guild_storageclose(sd);
+       }
+   }
+   else { //char is offline ask char to do the job
+       intif_itembound_req(char_id,aid,guild_id);
+   }
+}
+
 int guild_member_withdraw(int guild_id, int account_id, int char_id, int flag, const char* name, const char* mes)
 {
    int i;
@@ -849,6 +888,7 @@
    struct map_session_data* sd = map_charid2sd(char_id);
    struct map_session_data* online_member_sd;
 
+
    if(g == NULL)
        return 0; // no such guild (error!)
 
@@ -884,6 +924,9 @@
        clif_charnameupdate(sd); //Update display name [Skotlex]
        //TODO: send emblem update to self and people around
    }
+   //Guild bound item check (or move this even into a func)
+   guild_retrieveitembound(char_id,account_id,guild_id);
+
    return 0;
 }
 
Index: src/map/intif.c
===================================================================
--- src/map/intif.c (revision 17347)
+++ src/map/intif.c (working copy)
@@ -39,7 +39,7 @@
    39,-1,15,15, 14,19, 7,-1,  0, 0, 0, 0,  0, 0,  0, 0, //0x3820
    10,-1,15, 0, 79,19, 7,-1,  0,-1,-1,-1, 14,67,186,-1, //0x3830
    -1, 0, 0,14,  0, 0, 0, 0, -1,74,-1,11, 11,-1,  0, 0, //0x3840
-   -1,-1, 7, 7,  7,11, 0, 0,  0, 0, 0, 0,  0, 0,  0, 0, //0x3850  Auctions [Zephyrus]
+   -1,-1, 7, 7,  7,11, 10, 8,  0, 0, 0, 0,  0, 0,  0, 0, //0x3850  Auctions [Zephyrus] itembound[Akinari]
    -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
@@ -2152,6 +2152,32 @@
    return;
 }
 
+
+void intif_itembound_req(int char_id,int aid,int guild_id){
+   struct guild_storage *gstor = guild2storage2(guild_id);
+   if(gstor) {
+       WFIFOHEAD(char_fd,10);
+       WFIFOW(char_fd,0) = 0x3856;
+       WFIFOW(char_fd,2) = char_id;
+       WFIFOL(char_fd,4) = aid;
+       WFIFOW(char_fd,8) = guild_id;
+       WFIFOSET(char_fd,10);
+       gstor->lock = 1; //lock for retrive process
+   } //no guildstorage ?
+}
+
+//3857
+void intif_parse_itembound_ack(int fd){
+   struct guild_storage *gstor;
+   int aid = RFIFOL(char_fd,2);
+   int guild_id = RFIFOW(char_fd,6);
+   TBL_PC *sd = map_id2sd(aid);
+
+   gstor = guild2storage2(guild_id);
+   if(gstor) gstor->lock = 0; //now could be used again
+   if(sd) storage_guild_storageclose(sd); //at this point guild_storage should have been open
+}
+
 //-----------------------------------------------------------------
 // Communication from the inter server
 // Return a 0 (false) if there were any errors.
Index: src/map/unit.c
===================================================================
--- src/map/unit.c  (revision 17347)
+++ src/map/unit.c  (working copy)
@@ -151,7 +151,7 @@
        case BL_ELEM:
        case BL_PET :
        case BL_MER :
-           if(msd && *mast_tid != INVALID_TIMER && !check_distance_bl(&msd->bl, bl, MAX_MER_DISTANCE)){
+           if(msd && !check_distance_bl(&msd->bl, bl, MAX_MER_DISTANCE)){
                *mast_tid = INVALID_TIMER;
                unit_warp(bl, msd->bl.id, msd->bl.x, msd->bl.y, CLR_TELEPORT );
            }
Index: src/char/int_storage.c
===================================================================
--- src/char/int_storage.c  (revision 17347)
+++ src/char/int_storage.c  (working copy)
@@ -235,12 +235,89 @@
 }
 
 
+//------------------------------------------------
+//Guild bound items pull for offline characters [Akinari]
+//Fills in item structure to be used elsewhere
+//------------------------------------------------
+int mapif_parse_itembound_retrieve(int fd)
+{
+   StringBuf buf;
+   SqlStmt* stmt;
+   struct item item;
+   int j, i=0;
+   struct item items[MAX_INVENTORY];
+   int char_id = RFIFOW(fd,2);
+   int aid = RFIFOL(fd,4);
+   int guild_id = RFIFOW(fd,8);
+
+   StringBuf_Init(&buf);
+   StringBuf_AppendStr(&buf, "SELECT `id`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `expire_time`, `bound`");
+   for( j = 0; j < MAX_SLOTS; ++j )
+       StringBuf_Printf(&buf, ", `card%d`", j);
+   StringBuf_Printf(&buf, " FROM `%s` WHERE `char_id`='%d'",inventory_db,char_id);
+
+   stmt = SqlStmt_Malloc(mmysql_handle);
+   if( SQL_ERROR == SqlStmt_PrepareStr(stmt, StringBuf_Value(&buf))
+   ||  SQL_ERROR == SqlStmt_Execute(stmt) )
+   {
+       SqlStmt_ShowDebug(stmt);
+       SqlStmt_Free(stmt);
+       StringBuf_Destroy(&buf);
+       return 1;
+   }
+
+   SqlStmt_BindColumn(stmt, 0, SQLDT_INT,       &item.id,          0, NULL, NULL);
+   SqlStmt_BindColumn(stmt, 1, SQLDT_SHORT,     &item.nameid,      0, NULL, NULL);
+   SqlStmt_BindColumn(stmt, 2, SQLDT_SHORT,     &item.amount,      0, NULL, NULL);
+   SqlStmt_BindColumn(stmt, 3, SQLDT_USHORT,    &item.equip,       0, NULL, NULL);
+   SqlStmt_BindColumn(stmt, 4, SQLDT_CHAR,      &item.identify,    0, NULL, NULL);
+   SqlStmt_BindColumn(stmt, 5, SQLDT_CHAR,      &item.refine,      0, NULL, NULL);
+   SqlStmt_BindColumn(stmt, 6, SQLDT_CHAR,      &item.attribute,   0, NULL, NULL);
+   SqlStmt_BindColumn(stmt, 7, SQLDT_UINT,      &item.expire_time, 0, NULL, NULL);
+   SqlStmt_BindColumn(stmt, 8, SQLDT_UINT,      &item.bound,       0, NULL, NULL);
+   for( j = 0; j < MAX_SLOTS; ++j )
+       SqlStmt_BindColumn(stmt, 9+j, SQLDT_SHORT, &item.card[j], 0, NULL, NULL);
+
+   while( SQL_SUCCESS == SqlStmt_NextRow(stmt) ) {
+       if(item.bound == 2) {
+           memcpy(items[i],&item,sizeof(item));
+           i++;
+       }
+   }
+
+   for(j=0; j<i; j++){
+       StringBuf_Printf(&buf, "DELETE FROM `%s` WHERE `id`=%d;",inventory_db,items[j].id);
+       StringBuf_Printf(&buf, "INSERT INTO %s(nameid,amount,identify,refine,attribute,expire_time) VALUES(%d,%d,%d,%d,%d,%d);",
+           guild_storage_db,items[i].nameid,items[i].amount,items[i].identify,items[i].refine,items[i].attribute,items[i].expire_time);
+       if( SQL_ERROR == SqlStmt_PrepareStr(stmt, StringBuf_Value(&buf))
+       ||  SQL_ERROR == SqlStmt_Execute(stmt) )
+       {
+           SqlStmt_ShowDebug(stmt);
+           SqlStmt_Free(stmt);
+           StringBuf_Destroy(&buf);
+           return 1;
+       }
+   }
+   mapif_load_guild_storage(aid,guild_id);
+   mapif_itembound_ack(fd,aid,guild_id);
+   return 0;
+}
+
+int  mapif_itembound_ack(int fd, int aid, int guild_id) {
+   WFIFOHEAD(fd,8);
+   WFIFOW(fd,0) = 0x3857;
+   WFIFOL(fd,2) = aid;
+   WFIFOW(fd,6) = guild_id;
+   WFIFOSET(fd,8);
+}
+
 int inter_storage_parse_frommap(int fd)
 {
    RFIFOHEAD(fd);
    switch(RFIFOW(fd,0)){
    case 0x3018: mapif_parse_LoadGuildStorage(fd); break;
    case 0x3019: mapif_parse_SaveGuildStorage(fd); break;
+   case 0x3856: mapif_parse_itembound_retrieve(fd); break;
    default:
        return 0;
    }
 
Viewed 1500 times, submitted by lighta.