diff --git a/src/char/int_guild.cpp b/src/char/int_guild.cpp index 1f8cbed0fd..8f4bcaa3b6 100644 --- a/src/char/int_guild.cpp +++ b/src/char/int_guild.cpp @@ -37,18 +37,18 @@ using namespace rathena; static const char dataToHex[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; -// int guild_id -> struct guild* -static std::unordered_map> guild_db; +// int guild_id -> CharGuild* +static std::unordered_map> guild_db; static std::unordered_map> castle_db; int mapif_parse_GuildLeave(int fd,int guild_id,uint32 account_id,uint32 char_id,int flag,const char *mes); int mapif_guild_broken(int guild_id,int flag); -bool guild_check_empty( std::shared_ptr g ); -int guild_calcinfo( std::shared_ptr g ); +bool guild_check_empty( std::shared_ptr g ); +int guild_calcinfo( std::shared_ptr g ); int mapif_guild_basicinfochanged(int guild_id,int type,const void *data,int len); -int mapif_guild_info( int fd, std::shared_ptr g ); -int inter_guild_tosql( std::shared_ptr g, int flag ); -int guild_checkskill( std::shared_ptr g, int id ); +int mapif_guild_info( int fd, const struct mmo_guild &g ); +int inter_guild_tosql( mmo_guild &g, int flag ); +int guild_checkskill( std::shared_ptr g, int id ); TIMER_FUNC(guild_save_timer){ static int last_id = 0; //To know in which guild we were. @@ -58,24 +58,24 @@ TIMER_FUNC(guild_save_timer){ state = 1; for( auto it = guild_db.begin(); it != guild_db.end(); ){ - std::shared_ptr g = it->second; + std::shared_ptr g = it->second; - if( state == 0 && g->guild_id == last_id ) + if( state == 0 && g->guild.guild_id == last_id ) state++; //Save next guild in the list. else if( state == 1 && g->save_flag&GS_MASK ) { - inter_guild_tosql(g, g->save_flag&GS_MASK); + inter_guild_tosql(g->guild, g->save_flag&GS_MASK); g->save_flag &= ~GS_MASK; //Some guild saved. - last_id = g->guild_id; + last_id = g->guild.guild_id; state++; } // Nothing to save, guild is ready for removal. if( g->save_flag == GS_REMOVE ){ if (charserv_config.save_log) - ShowInfo("Guild Unloaded (%d - %s)\n", g->guild_id, g->name); + ShowInfo("Guild Unloaded (%d - %s)\n", g->guild.guild_id, g->guild.name); it = guild_db.erase( it ); }else{ it++; @@ -100,8 +100,8 @@ int inter_guild_removemember_tosql(uint32 char_id) return 0; } -// Save guild into sql -int inter_guild_tosql( std::shared_ptr g, int flag ){ +// Save mmo_guild into sql +int inter_guild_tosql( mmo_guild &g, int flag ){ // Table guild (GS_BASIC_MASK) // GS_EMBLEM `emblem_len`,`emblem_id`,`emblem_data` // GS_CONNECT `connect_member`,`average_lv` @@ -123,18 +123,18 @@ int inter_guild_tosql( std::shared_ptr g, int flag ){ char new_guild = 0; int i=0; - if (g->guild_id<=0 && g->guild_id != -1) return 0; + if (g.guild_id<=0 && g.guild_id != -1) return 0; #ifdef NOISY - ShowInfo("Save guild request (" CL_BOLD "%d" CL_RESET " - flag 0x%x).",g->guild_id, flag); + ShowInfo("Save guild request (" CL_BOLD "%d" CL_RESET " - flag 0x%x).",g.guild_id, flag); #endif - Sql_EscapeStringLen(sql_handle, esc_name, g->name, strnlen(g->name, NAME_LENGTH)); - Sql_EscapeStringLen(sql_handle, esc_master, g->master, strnlen(g->master, NAME_LENGTH)); + Sql_EscapeStringLen(sql_handle, esc_name, g.name, strnlen(g.name, NAME_LENGTH)); + Sql_EscapeStringLen(sql_handle, esc_master, g.master, strnlen(g.master, NAME_LENGTH)); *t_info = '\0'; // Insert a new guild the guild - if (flag&GS_BASIC && g->guild_id == -1) + if (flag&GS_BASIC && g.guild_id == -1) { strcat(t_info, " guild_create"); @@ -142,14 +142,14 @@ int inter_guild_tosql( std::shared_ptr g, int flag ){ if( SQL_ERROR == Sql_Query(sql_handle, "INSERT INTO `%s` " "(`name`,`master`,`guild_lv`,`max_member`,`average_lv`,`char_id`) " "VALUES ('%s', '%s', '%d', '%d', '%d', '%d')", - schema_config.guild_db, esc_name, esc_master, g->guild_lv, g->max_member, g->average_lv, g->member[0].char_id) ) + schema_config.guild_db, esc_name, esc_master, g.guild_lv, g.max_member, g.average_lv, g.member[0].char_id) ) { Sql_ShowDebug(sql_handle); return 0; //Failed to create guild! } else { - g->guild_id = (int)Sql_LastInsertId(sql_handle); + g.guild_id = (int)Sql_LastInsertId(sql_handle); new_guild = 1; } } @@ -165,18 +165,18 @@ int inter_guild_tosql( std::shared_ptr g, int flag ){ if (flag & GS_EMBLEM) { - char emblem_data[sizeof(g->emblem_data)*2+1]; + char emblem_data[sizeof(g.emblem_data)*2+1]; char* pData = emblem_data; strcat(t_info, " emblem"); // Convert emblem_data to hex //TODO: why not use binary directly? [ultramage] - for(i=0; iemblem_len; i++){ - *pData++ = dataToHex[(g->emblem_data[i] >> 4) & 0x0F]; - *pData++ = dataToHex[g->emblem_data[i] & 0x0F]; + for(i=0; i> 4) & 0x0F]; + *pData++ = dataToHex[g.emblem_data[i] & 0x0F]; } *pData = 0; - StringBuf_Printf(&buf, "`emblem_len`=%d, `emblem_id`=%d, `emblem_data`='%s'", g->emblem_len, g->emblem_id, emblem_data); + StringBuf_Printf(&buf, "`emblem_len`=%d, `emblem_id`=%d, `emblem_data`='%s'", g.emblem_len, g.emblem_id, emblem_data); add_comma = true; } if (flag & GS_BASIC) @@ -186,10 +186,10 @@ int inter_guild_tosql( std::shared_ptr g, int flag ){ StringBuf_AppendStr(&buf, ", "); else add_comma = true; - StringBuf_Printf(&buf, "`name`='%s', `master`='%s', `char_id`=%d", esc_name, esc_master, g->member[0].char_id); + StringBuf_Printf(&buf, "`name`='%s', `master`='%s', `char_id`=%d", esc_name, esc_master, g.member[0].char_id); - if (g->last_leader_change) - StringBuf_Printf(&buf, ", `last_master_change`=FROM_UNIXTIME(%d)", g->last_leader_change); + if (g.last_leader_change) + StringBuf_Printf(&buf, ", `last_master_change`=FROM_UNIXTIME(%d)", g.last_leader_change); } if (flag & GS_CONNECT) { @@ -198,20 +198,20 @@ int inter_guild_tosql( std::shared_ptr g, int flag ){ StringBuf_AppendStr(&buf, ", "); else add_comma = true; - StringBuf_Printf(&buf, "`connect_member`=%d, `average_lv`=%d", g->connect_member, g->average_lv); + StringBuf_Printf(&buf, "`connect_member`=%d, `average_lv`=%d", g.connect_member, g.average_lv); } if (flag & GS_MES) { - char esc_mes1[sizeof(g->mes1)*2+1]; - char esc_mes2[sizeof(g->mes2)*2+1]; + char esc_mes1[sizeof(g.mes1)*2+1]; + char esc_mes2[sizeof(g.mes2)*2+1]; strcat(t_info, " mes"); if( add_comma ) StringBuf_AppendStr(&buf, ", "); else add_comma = true; - Sql_EscapeStringLen(sql_handle, esc_mes1, g->mes1, strnlen(g->mes1, sizeof(g->mes1))); - Sql_EscapeStringLen(sql_handle, esc_mes2, g->mes2, strnlen(g->mes2, sizeof(g->mes2))); + Sql_EscapeStringLen(sql_handle, esc_mes1, g.mes1, strnlen(g.mes1, sizeof(g.mes1))); + Sql_EscapeStringLen(sql_handle, esc_mes2, g.mes2, strnlen(g.mes2, sizeof(g.mes2))); StringBuf_Printf(&buf, "`mes1`='%s', `mes2`='%s'", esc_mes1, esc_mes2); } if (flag & GS_LEVEL) @@ -221,9 +221,9 @@ int inter_guild_tosql( std::shared_ptr g, int flag ){ StringBuf_AppendStr(&buf, ", "); //else //last condition using add_coma setting // add_comma = true; - StringBuf_Printf(&buf, "`guild_lv`=%d, `skill_point`=%d, `exp`=%" PRIu64 ", `next_exp`=%" PRIu64 ", `max_member`=%d", g->guild_lv, g->skill_point, g->exp, g->next_exp, g->max_member); + StringBuf_Printf(&buf, "`guild_lv`=%d, `skill_point`=%d, `exp`=%" PRIu64 ", `next_exp`=%" PRIu64 ", `max_member`=%d", g.guild_lv, g.skill_point, g.exp, g.next_exp, g.max_member); } - StringBuf_Printf(&buf, " WHERE `guild_id`=%d", g->guild_id); + StringBuf_Printf(&buf, " WHERE `guild_id`=%d", g.guild_id); if( SQL_ERROR == Sql_Query(sql_handle, "%s", StringBuf_Value(&buf)) ) Sql_ShowDebug(sql_handle); StringBuf_Destroy(&buf); @@ -233,20 +233,20 @@ int inter_guild_tosql( std::shared_ptr g, int flag ){ { strcat(t_info, " members"); // Update only needed players - for(i=0;imax_member;i++){ - struct guild_member *m = &g->member[i]; + for(i=0;imodified) continue; if(m->account_id) { //Since nothing references guild member table as foreign keys, it's safe to use REPLACE INTO if( SQL_ERROR == Sql_Query(sql_handle, "REPLACE INTO `%s` (`guild_id`,`char_id`,`exp`,`position`) " "VALUES ('%d','%d','%" PRIu64 "','%d')", - schema_config.guild_member_db, g->guild_id, m->char_id, m->exp, m->position ) ) + schema_config.guild_member_db, g.guild_id, m->char_id, m->exp, m->position ) ) Sql_ShowDebug(sql_handle); if (m->modified&GS_MEMBER_NEW || new_guild == 1) { if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `guild_id` = '%d' WHERE `char_id` = '%d'", - schema_config.char_db, g->guild_id, m->char_id) ) + schema_config.char_db, g.guild_id, m->char_id) ) Sql_ShowDebug(sql_handle); } m->modified = GS_MEMBER_UNMODIFIED; @@ -256,14 +256,14 @@ int inter_guild_tosql( std::shared_ptr g, int flag ){ if (flag&GS_POSITION){ strcat(t_info, " positions"); - //printf("- Insert guild %d to guild_position\n",g->guild_id); + //printf("- Insert guild %d to guild_position\n",g.guild_id); for(i=0;iposition[i]; + struct guild_position *p = &g.position[i]; if (!p->modified) continue; Sql_EscapeStringLen(sql_handle, esc_name, p->name, strnlen(p->name, NAME_LENGTH)); if( SQL_ERROR == Sql_Query(sql_handle, "REPLACE INTO `%s` (`guild_id`,`position`,`name`,`mode`,`exp_mode`) VALUES ('%d','%d','%s','%d','%d')", - schema_config.guild_position_db, g->guild_id, i, esc_name, p->mode, p->exp_mode) ) + schema_config.guild_position_db, g.guild_id, i, esc_name, p->mode, p->exp_mode) ) Sql_ShowDebug(sql_handle); p->modified = GS_POSITION_UNMODIFIED; } @@ -275,23 +275,23 @@ int inter_guild_tosql( std::shared_ptr g, int flag ){ // NOTE: no need to do it on both sides since both guilds in memory had // their info changed, not to mention this would also mess up oppositions! // [Skotlex] - //if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `guild_id`='%d' OR `alliance_id`='%d'", guild_alliance_db, g->guild_id, g->guild_id) ) - if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `guild_id`='%d'", schema_config.guild_alliance_db, g->guild_id) ) + //if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `guild_id`='%d' OR `alliance_id`='%d'", guild_alliance_db, g.guild_id, g.guild_id) ) + if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `guild_id`='%d'", schema_config.guild_alliance_db, g.guild_id) ) { Sql_ShowDebug(sql_handle); } else { - //printf("- Insert guild %d to guild_alliance\n",g->guild_id); + //printf("- Insert guild %d to guild_alliance\n",g.guild_id); for(i=0;ialliance[i]; + struct guild_alliance *a=&g.alliance[i]; if(a->guild_id>0) { Sql_EscapeStringLen(sql_handle, esc_name, a->name, strnlen(a->name, NAME_LENGTH)); if( SQL_ERROR == Sql_Query(sql_handle, "REPLACE INTO `%s` (`guild_id`,`opposition`,`alliance_id`,`name`) " "VALUES ('%d','%d','%d','%s')", - schema_config.guild_alliance_db, g->guild_id, a->opposition, a->guild_id, esc_name) ) + schema_config.guild_alliance_db, g.guild_id, a->opposition, a->guild_id, esc_name) ) Sql_ShowDebug(sql_handle); } } @@ -300,16 +300,16 @@ int inter_guild_tosql( std::shared_ptr g, int flag ){ if (flag&GS_EXPULSION){ strcat(t_info, " expulsions"); - //printf("- Insert guild %d to guild_expulsion\n",g->guild_id); + //printf("- Insert guild %d to guild_expulsion\n",g.guild_id); for(i=0;iexpulsion[i]; + struct guild_expulsion *e=&g.expulsion[i]; if(e->account_id>0){ char esc_mes[sizeof(e->mes)*2+1]; Sql_EscapeStringLen(sql_handle, esc_name, e->name, strnlen(e->name, NAME_LENGTH)); Sql_EscapeStringLen(sql_handle, esc_mes, e->mes, strnlen(e->mes, sizeof(e->mes))); if( SQL_ERROR == Sql_Query(sql_handle, "REPLACE INTO `%s` (`guild_id`,`account_id`,`name`,`mes`) " - "VALUES ('%d','%d','%s','%s')", schema_config.guild_expulsion_db, g->guild_id, e->account_id, esc_name, esc_mes) ) + "VALUES ('%d','%d','%s','%s')", schema_config.guild_expulsion_db, g.guild_id, e->account_id, esc_name, esc_mes) ) Sql_ShowDebug(sql_handle); } } @@ -317,23 +317,23 @@ int inter_guild_tosql( std::shared_ptr g, int flag ){ if (flag&GS_SKILL){ strcat(t_info, " skills"); - //printf("- Insert guild %d to guild_skill\n",g->guild_id); + //printf("- Insert guild %d to guild_skill\n",g.guild_id); for(i=0;iskill[i].id>0 && g->skill[i].lv>0){ + if (g.skill[i].id>0 && g.skill[i].lv>0){ if( SQL_ERROR == Sql_Query(sql_handle, "REPLACE INTO `%s` (`guild_id`,`id`,`lv`) VALUES ('%d','%d','%d')", - schema_config.guild_skill_db, g->guild_id, g->skill[i].id, g->skill[i].lv) ) + schema_config.guild_skill_db, g.guild_id, g.skill[i].id, g.skill[i].lv) ) Sql_ShowDebug(sql_handle); } } } if (charserv_config.save_log) - ShowInfo("Saved guild (%d - %s):%s\n",g->guild_id,g->name,t_info); + ShowInfo("Saved guild (%d - %s):%s\n",g.guild_id,g.name,t_info); return 1; } // Read guild from sql -std::shared_ptr inter_guild_fromsql( int32 guild_id ){ +std::shared_ptr inter_guild_fromsql( int32 guild_id ){ char* data; size_t len; char* p; @@ -343,7 +343,7 @@ std::shared_ptr inter_guild_fromsql( int32 guild_id ){ return nullptr; } - std::shared_ptr g = util::umap_find( guild_db, guild_id ); + auto g = util::umap_find( guild_db, guild_id ); if( g != nullptr ){ return g; @@ -365,32 +365,32 @@ std::shared_ptr inter_guild_fromsql( int32 guild_id ){ return nullptr; } - g = std::make_shared(); + g = std::make_shared(); - g->guild_id = guild_id; - Sql_GetData(sql_handle, 0, &data, &len); memcpy(g->name, data, zmin(len, NAME_LENGTH)); - Sql_GetData(sql_handle, 1, &data, &len); memcpy(g->master, data, zmin(len, NAME_LENGTH)); - Sql_GetData(sql_handle, 2, &data, NULL); g->guild_lv = atoi(data); - Sql_GetData(sql_handle, 3, &data, NULL); g->connect_member = atoi(data); - Sql_GetData(sql_handle, 4, &data, NULL); g->max_member = atoi(data); - if( g->max_member > MAX_GUILD ) + g->guild.guild_id = guild_id; + Sql_GetData(sql_handle, 0, &data, &len); memcpy(g->guild.name, data, zmin(len, NAME_LENGTH)); + Sql_GetData(sql_handle, 1, &data, &len); memcpy(g->guild.master, data, zmin(len, NAME_LENGTH)); + Sql_GetData(sql_handle, 2, &data, NULL); g->guild.guild_lv = atoi(data); + Sql_GetData(sql_handle, 3, &data, NULL); g->guild.connect_member = atoi(data); + Sql_GetData(sql_handle, 4, &data, NULL); g->guild.max_member = atoi(data); + if( g->guild.max_member > MAX_GUILD ) { // Fix reduction of MAX_GUILD [PoW] - ShowWarning("Guild %d:%s specifies higher capacity (%d) than MAX_GUILD (%d)\n", guild_id, g->name, g->max_member, MAX_GUILD); - g->max_member = MAX_GUILD; + ShowWarning("Guild %d:%s specifies higher capacity (%d) than MAX_GUILD (%d)\n", guild_id, g->guild.name, g->guild.max_member, MAX_GUILD); + g->guild.max_member = MAX_GUILD; } - Sql_GetData(sql_handle, 5, &data, NULL); g->average_lv = atoi(data); - Sql_GetData(sql_handle, 6, &data, NULL); g->exp = strtoull(data, NULL, 10); - Sql_GetData(sql_handle, 7, &data, NULL); g->next_exp = strtoull(data, nullptr, 10); - Sql_GetData(sql_handle, 8, &data, NULL); g->skill_point = atoi(data); - Sql_GetData(sql_handle, 9, &data, &len); memcpy(g->mes1, data, zmin(len, sizeof(g->mes1))); - Sql_GetData(sql_handle, 10, &data, &len); memcpy(g->mes2, data, zmin(len, sizeof(g->mes2))); - Sql_GetData(sql_handle, 11, &data, &len); g->emblem_len = atoi(data); - Sql_GetData(sql_handle, 12, &data, &len); g->emblem_id = atoi(data); - Sql_GetData(sql_handle, 13, &data, NULL); g->last_leader_change = atoi(data); + Sql_GetData(sql_handle, 5, &data, NULL); g->guild.average_lv = atoi(data); + Sql_GetData(sql_handle, 6, &data, NULL); g->guild.exp = strtoull(data, NULL, 10); + Sql_GetData(sql_handle, 7, &data, NULL); g->guild.next_exp = strtoull(data, nullptr, 10); + Sql_GetData(sql_handle, 8, &data, NULL); g->guild.skill_point = atoi(data); + Sql_GetData(sql_handle, 9, &data, &len); memcpy(g->guild.mes1, data, zmin(len, sizeof(g->guild.mes1))); + Sql_GetData(sql_handle, 10, &data, &len); memcpy(g->guild.mes2, data, zmin(len, sizeof(g->guild.mes2))); + Sql_GetData(sql_handle, 11, &data, &len); g->guild.emblem_len = atoi(data); + Sql_GetData(sql_handle, 12, &data, &len); g->guild.emblem_id = atoi(data); + Sql_GetData(sql_handle, 13, &data, NULL); g->guild.last_leader_change = atoi(data); Sql_GetData(sql_handle, 14, &data, &len); // convert emblem data from hexadecimal to binary //TODO: why not store it in the db as binary directly? [ultramage] - for( i = 0, p = g->emblem_data; i < g->emblem_len; ++i, ++p ) + for( i = 0, p = g->guild.emblem_data; i < g->guild.emblem_len; ++i, ++p ) { if( *data >= '0' && *data <= '9' ) *p = *data - '0'; @@ -417,9 +417,9 @@ std::shared_ptr inter_guild_fromsql( int32 guild_id ){ Sql_ShowDebug(sql_handle); return nullptr; } - for( i = 0; i < g->max_member && SQL_SUCCESS == Sql_NextRow(sql_handle); ++i ) + for( i = 0; i < g->guild.max_member && SQL_SUCCESS == Sql_NextRow(sql_handle); ++i ) { - struct guild_member* m = &g->member[i]; + struct guild_member* m = &g->guild.member[i]; Sql_GetData(sql_handle, 0, &data, NULL); m->account_id = atoi(data); Sql_GetData(sql_handle, 1, &data, NULL); m->char_id = atoi(data); @@ -464,7 +464,7 @@ std::shared_ptr inter_guild_fromsql( int32 guild_id ){ Sql_GetData(sql_handle, 0, &data, NULL); position = atoi(data); if( position < 0 || position >= MAX_GUILDPOSITION ) continue;// invalid position - gpos = &g->position[position]; + gpos = &g->guild.position[position]; Sql_GetData(sql_handle, 1, &data, &len); memcpy(gpos->name, data, zmin(len, NAME_LENGTH)); Sql_GetData(sql_handle, 2, &data, NULL); gpos->mode = atoi(data); Sql_GetData(sql_handle, 3, &data, NULL); gpos->exp_mode = atoi(data); @@ -479,7 +479,7 @@ std::shared_ptr inter_guild_fromsql( int32 guild_id ){ } for( i = 0; i < MAX_GUILDALLIANCE && SQL_SUCCESS == Sql_NextRow(sql_handle); ++i ) { - struct guild_alliance* a = &g->alliance[i]; + struct guild_alliance* a = &g->guild.alliance[i]; Sql_GetData(sql_handle, 0, &data, NULL); a->opposition = atoi(data); Sql_GetData(sql_handle, 1, &data, NULL); a->guild_id = atoi(data); @@ -494,7 +494,7 @@ std::shared_ptr inter_guild_fromsql( int32 guild_id ){ } for( i = 0; i < MAX_GUILDEXPULSION && SQL_SUCCESS == Sql_NextRow(sql_handle); ++i ) { - struct guild_expulsion *e = &g->expulsion[i]; + struct guild_expulsion *e = &g->guild.expulsion[i]; Sql_GetData(sql_handle, 0, &data, NULL); e->account_id = atoi(data); Sql_GetData(sql_handle, 1, &data, &len); memcpy(e->name, data, zmin(len, NAME_LENGTH)); @@ -510,7 +510,7 @@ std::shared_ptr inter_guild_fromsql( int32 guild_id ){ for(i = 0; i < MAX_GUILDSKILL; i++) { //Skill IDs must always be initialized. [Skotlex] - g->skill[i].id = i + GD_SKILLBASE; + g->guild.skill[i].id = i + GD_SKILLBASE; } while( SQL_SUCCESS == Sql_NextRow(sql_handle) ) @@ -519,18 +519,18 @@ std::shared_ptr inter_guild_fromsql( int32 guild_id ){ Sql_GetData(sql_handle, 0, &data, NULL); id = atoi(data) - GD_SKILLBASE; if( id < 0 || id >= MAX_GUILDSKILL ) continue;// invalid guild skill - Sql_GetData(sql_handle, 1, &data, NULL); g->skill[id].lv = atoi(data); + Sql_GetData(sql_handle, 1, &data, NULL); g->guild.skill[id].lv = atoi(data); } Sql_FreeResult(sql_handle); // Add to cache - guild_db[g->guild_id] = g; + guild_db[g->guild.guild_id] = g; // But set it to be removed, in case it is not needed for long. g->save_flag |= GS_REMOVE; if (charserv_config.save_log) - ShowInfo("Guild loaded (%d - %s)\n", guild_id, g->name); + ShowInfo("Guild loaded (%d - %s)\n", guild_id, g->guild.name); return g; } @@ -543,7 +543,7 @@ std::shared_ptr inter_guild_fromsql( int32 guild_id ){ uint16 inter_guild_storagemax(int guild_id) { #ifdef OFFICIAL_GUILD_STORAGE - std::shared_ptr g = inter_guild_fromsql( guild_id ); + auto g = inter_guild_fromsql( guild_id ); uint16 max = 0; if( g == nullptr ){ @@ -665,7 +665,7 @@ int inter_guild_CharOnline(uint32 char_id, int guild_id) if (guild_id == 0) return 0; //No guild... - std::shared_ptr g = inter_guild_fromsql( guild_id ); + auto g = inter_guild_fromsql( guild_id ); if( g == nullptr ){ ShowError("Character %d's guild %d not found!\n", char_id, guild_id); @@ -677,11 +677,11 @@ int inter_guild_CharOnline(uint32 char_id, int guild_id) g->save_flag &= ~GS_REMOVE; //Set member online - ARR_FIND( 0, g->max_member, i, g->member[i].char_id == char_id ); - if( i < g->max_member ) + ARR_FIND( 0, g->guild.max_member, i, g->guild.member[i].char_id == char_id ); + if( i < g->guild.max_member ) { - g->member[i].online = 1; - g->member[i].modified = GS_MEMBER_MODIFIED; + g->guild.member[i].online = 1; + g->guild.member[i].modified = GS_MEMBER_MODIFIED; } return 1; @@ -717,7 +717,7 @@ int inter_guild_CharOffline(uint32 char_id, int guild_id) return 0; //No guild... //Character has a guild, set character offline and check if they were the only member online - std::shared_ptr g = inter_guild_fromsql( guild_id ); + auto g = inter_guild_fromsql( guild_id ); // Guild not found? if( g == nullptr ){ @@ -725,16 +725,16 @@ int inter_guild_CharOffline(uint32 char_id, int guild_id) } //Set member offline - ARR_FIND( 0, g->max_member, i, g->member[i].char_id == char_id ); - if( i < g->max_member ) + ARR_FIND( 0, g->guild.max_member, i, g->guild.member[i].char_id == char_id ); + if( i < g->guild.max_member ) { - g->member[i].online = 0; - g->member[i].modified = GS_MEMBER_MODIFIED; + g->guild.member[i].online = 0; + g->guild.member[i].modified = GS_MEMBER_MODIFIED; } online_count = 0; - for( i = 0; i < g->max_member; i++ ) - if( g->member[i].online ) + for( i = 0; i < g->guild.max_member; i++ ) + if( g->guild.member[i].online ) online_count++; // Remove guild from memory if no players online @@ -812,10 +812,10 @@ void inter_guild_sql_init(void) { void inter_guild_sql_final(void) { for( const auto& pair : guild_db ){ - std::shared_ptr guild = pair.second; + auto guild = pair.second; if( guild->save_flag&GS_MASK ){ - inter_guild_tosql( guild, guild->save_flag&GS_MASK ); + inter_guild_tosql( guild->guild, guild->save_flag&GS_MASK ); } } guild_db.clear(); @@ -852,12 +852,12 @@ int search_guildname(char *str) } // Check if guild is empty -bool guild_check_empty( std::shared_ptr g ){ +bool guild_check_empty( std::shared_ptr g ){ int i; - ARR_FIND( 0, g->max_member, i, g->member[i].account_id > 0 ); + ARR_FIND( 0, g->guild.max_member, i, g->guild.member[i].account_id > 0 ); //Let the calling function handle the guild removal in case they need //to do something else with it before freeing the data. [Skotlex] - return i < g->max_member ? false : true; // not empty + return i < g->guild.max_member ? false : true; // not empty } t_exp GuildExpDatabase::get_nextexp(uint16 level) { @@ -866,64 +866,64 @@ t_exp GuildExpDatabase::get_nextexp(uint16 level) { return ((guild_exp == nullptr) ? 0 : guild_exp->exp); } -int guild_checkskill( std::shared_ptr g, int id ){ +int guild_checkskill( std::shared_ptr g, int id ){ int idx = id - GD_SKILLBASE; - return idx < 0 || idx >= MAX_GUILDSKILL ? 0 : g->skill[idx].lv; + return idx < 0 || idx >= MAX_GUILDSKILL ? 0 : g->guild.skill[idx].lv; } -int guild_calcinfo( std::shared_ptr g ){ +int guild_calcinfo( std::shared_ptr g ){ int i,c; - struct guild before = *g; // Save guild current values + struct mmo_guild before = g->guild; // Save guild current values - if(g->guild_lv<=0) - g->guild_lv = 1; - g->next_exp = guild_exp_db.get_nextexp(g->guild_lv); + if(g->guild.guild_lv<=0) + g->guild.guild_lv = 1; + g->guild.next_exp = guild_exp_db.get_nextexp(g->guild.guild_lv); // Consume guild exp and increase guild level - while(g->exp >= g->next_exp && g->next_exp > 0 && g->guild_lv < MAX_GUILDLEVEL){ - g->exp-=g->next_exp; - g->guild_lv++; - g->skill_point++; - g->next_exp = guild_exp_db.get_nextexp(g->guild_lv); + while(g->guild.exp >= g->guild.next_exp && g->guild.next_exp > 0 && g->guild.guild_lv < MAX_GUILDLEVEL){ + g->guild.exp-=g->guild.next_exp; + g->guild.guild_lv++; + g->guild.skill_point++; + g->guild.next_exp = guild_exp_db.get_nextexp(g->guild.guild_lv); } // Set the max number of members, Guild Extention skill - currently adds 6 to max per skill lv. - g->max_member = 16 + guild_checkskill(g, GD_EXTENSION) * 6; - if(g->max_member > MAX_GUILD) + g->guild.max_member = 16 + guild_checkskill(g, GD_EXTENSION) * 6; + if(g->guild.max_member > MAX_GUILD) { - ShowError("Guild %d:%s has capacity for too many guild members (%d), max supported is %d\n", g->guild_id, g->name, g->max_member, MAX_GUILD); - g->max_member = MAX_GUILD; + ShowError("Guild %d:%s has capacity for too many guild members (%d), max supported is %d\n", g->guild.guild_id, g->guild.name, g->guild.max_member, MAX_GUILD); + g->guild.max_member = MAX_GUILD; } // Compute the guild average level - g->average_lv=0; - g->connect_member=0; - for(i=c=0;imax_member;i++) + g->guild.average_lv=0; + g->guild.connect_member=0; + for(i=c=0;iguild.max_member;i++) { - if(g->member[i].account_id>0) + if(g->guild.member[i].account_id>0) { - if (g->member[i].lv >= 0) + if (g->guild.member[i].lv >= 0) { - g->average_lv+=g->member[i].lv; + g->guild.average_lv+=g->guild.member[i].lv; c++; } else { - ShowWarning("Guild %d:%s, member %d:%s has an invalid level %d\n", g->guild_id, g->name, g->member[i].char_id, g->member[i].name, g->member[i].lv); + ShowWarning("Guild %d:%s, member %d:%s has an invalid level %d\n", g->guild.guild_id, g->guild.name, g->guild.member[i].char_id, g->guild.member[i].name, g->guild.member[i].lv); } - if(g->member[i].online) - g->connect_member++; + if(g->guild.member[i].online) + g->guild.connect_member++; } } if(c) - g->average_lv /= c; + g->guild.average_lv /= c; // Check if guild stats has change - if(g->max_member != before.max_member || g->guild_lv != before.guild_lv || g->skill_point != before.skill_point ) + if(g->guild.max_member != before.max_member || g->guild.guild_lv != before.guild_lv || g->guild.skill_point != before.skill_point ) { g->save_flag |= GS_LEVEL; - mapif_guild_info(-1,g); + mapif_guild_info(-1,g->guild); return 1; } @@ -933,7 +933,7 @@ int guild_calcinfo( std::shared_ptr g ){ //------------------------------------------------------------------- // Packet sent to map server -int mapif_guild_created( int fd, uint32 account_id, std::shared_ptr g ){ +int mapif_guild_created( int fd, uint32 account_id, struct mmo_guild *g ){ WFIFOHEAD(fd, 10); WFIFOW(fd,0)=0x3830; WFIFOL(fd,2)=account_id; @@ -964,11 +964,11 @@ int mapif_guild_noinfo(int fd,int guild_id) } // Send guild info -int mapif_guild_info( int fd, std::shared_ptr g ){ - unsigned char buf[8+sizeof(struct guild)]; +int mapif_guild_info( int fd, const struct mmo_guild &g ){ + unsigned char buf[8+sizeof(struct mmo_guild)]; WBUFW(buf,0)=0x3831; - WBUFW(buf,2)=4+sizeof(struct guild); - memcpy( buf + 4, g.get(), sizeof( struct guild ) ); + WBUFW(buf,2)=4+sizeof(struct mmo_guild); + memcpy( buf + 4, &g, sizeof( struct mmo_guild ) ); if(fd<0) chmapif_sendall(buf,WBUFW(buf,2)); else @@ -1006,15 +1006,15 @@ int mapif_guild_withdraw(int guild_id,uint32 account_id,uint32 char_id,int flag, } // Send short member's info -int mapif_guild_memberinfoshort( std::shared_ptr g, int idx ){ +int mapif_guild_memberinfoshort( const struct mmo_guild &g, int idx ){ unsigned char buf[19]; WBUFW(buf, 0)=0x3835; - WBUFL(buf, 2)=g->guild_id; - WBUFL(buf, 6)=g->member[idx].account_id; - WBUFL(buf,10)=g->member[idx].char_id; - WBUFB(buf,14)=(unsigned char)g->member[idx].online; - WBUFW(buf,15)=g->member[idx].lv; - WBUFW(buf,17)=g->member[idx].class_; + WBUFL(buf, 2)=g.guild_id; + WBUFL(buf, 6)=g.member[idx].account_id; + WBUFL(buf,10)=g.member[idx].char_id; + WBUFB(buf,14)=(unsigned char)g.member[idx].online; + WBUFW(buf,15)=g.member[idx].lv; + WBUFW(buf,17)=g.member[idx].class_; chmapif_sendall(buf,19); return 0; } @@ -1107,55 +1107,55 @@ int mapif_guild_alliance(int guild_id1,int guild_id2,uint32 account_id1,uint32 a } // Send a guild position desc -int mapif_guild_position( std::shared_ptr g, int idx ){ +int mapif_guild_position( const struct mmo_guild &g, int idx ){ unsigned char buf[12 + sizeof(struct guild_position)]; WBUFW(buf,0)=0x383b; WBUFW(buf,2)=sizeof(struct guild_position)+12; - WBUFL(buf,4)=g->guild_id; + WBUFL(buf,4)=g.guild_id; WBUFL(buf,8)=idx; - memcpy(WBUFP(buf,12),&g->position[idx],sizeof(struct guild_position)); + memcpy(WBUFP(buf,12),&g.position[idx],sizeof(struct guild_position)); chmapif_sendall(buf,WBUFW(buf,2)); return 0; } // Send the guild notice -int mapif_guild_notice( std::shared_ptr g ){ +int mapif_guild_notice( const struct mmo_guild &g ){ unsigned char buf[256]; WBUFW(buf,0)=0x383e; - WBUFL(buf,2)=g->guild_id; - memcpy(WBUFP(buf,6),g->mes1,MAX_GUILDMES1); - memcpy(WBUFP(buf,66),g->mes2,MAX_GUILDMES2); + WBUFL(buf,2)=g.guild_id; + memcpy(WBUFP(buf,6),g.mes1,MAX_GUILDMES1); + memcpy(WBUFP(buf,66),g.mes2,MAX_GUILDMES2); chmapif_sendall(buf,186); return 0; } // Send emblem data -int mapif_guild_emblem( std::shared_ptr g ){ - unsigned char buf[12 + sizeof(g->emblem_data)]; +int mapif_guild_emblem( const struct mmo_guild &g ){ + unsigned char buf[12 + sizeof(g.emblem_data)]; WBUFW(buf,0)=0x383f; - WBUFW(buf,2)=g->emblem_len+12; - WBUFL(buf,4)=g->guild_id; - WBUFL(buf,8)=g->emblem_id; - memcpy(WBUFP(buf,12),g->emblem_data,g->emblem_len); + WBUFW(buf,2)=g.emblem_len+12; + WBUFL(buf,4)=g.guild_id; + WBUFL(buf,8)=g.emblem_id; + memcpy(WBUFP(buf,12),g.emblem_data,g.emblem_len); chmapif_sendall(buf,WBUFW(buf,2)); return 0; } // Send the guild emblem_id (version) -int mapif_guild_emblem_version( std::shared_ptr g ){ +int mapif_guild_emblem_version( const struct mmo_guild &g ){ unsigned char buf[10]; WBUFW(buf, 0) = 0x3841; - WBUFL(buf, 2) = g->guild_id; - WBUFL(buf, 6) = g->emblem_id; + WBUFL(buf, 2) = g.guild_id; + WBUFL(buf, 6) = g.emblem_id; chmapif_sendall(buf, 10); return 0; } -int mapif_guild_master_changed( std::shared_ptr g, int aid, int cid, time_t time ){ +int mapif_guild_master_changed( const struct mmo_guild &g, int aid, int cid, time_t time ){ unsigned char buf[18]; WBUFW(buf,0)=0x3843; - WBUFL(buf,2)=g->guild_id; + WBUFL(buf,2)=g.guild_id; WBUFL(buf,6)=aid; WBUFL(buf,10)=cid; WBUFL(buf,14)=(uint32)time; @@ -1211,53 +1211,51 @@ int mapif_parse_CreateGuild(int fd,uint32 account_id,char *name,struct guild_mem } } - std::shared_ptr g = std::make_shared(); + auto g = std::make_shared(); - memset( g.get(), 0, sizeof( struct guild ) ); - - memcpy(g->name,name,NAME_LENGTH); - memcpy(g->master,master->name,NAME_LENGTH); - memcpy(&g->member[0],master,sizeof(struct guild_member)); - g->member[0].modified = GS_MEMBER_MODIFIED; + memcpy(g->guild.name,name,NAME_LENGTH); + memcpy(g->guild.master,master->name,NAME_LENGTH); + memcpy(&g->guild.member[0],master,sizeof(struct guild_member)); + g->guild.member[0].modified = GS_MEMBER_MODIFIED; // Set default positions - g->position[0].mode = GUILD_PERM_DEFAULT; - strcpy(g->position[0].name,"GuildMaster"); - strcpy(g->position[MAX_GUILDPOSITION-1].name,"Newbie"); - g->position[0].modified = g->position[MAX_GUILDPOSITION-1].modified = GS_POSITION_MODIFIED; + g->guild.position[0].mode = GUILD_PERM_DEFAULT; + strcpy(g->guild.position[0].name,"GuildMaster"); + strcpy(g->guild.position[MAX_GUILDPOSITION-1].name,"Newbie"); + g->guild.position[0].modified = g->guild.position[MAX_GUILDPOSITION-1].modified = GS_POSITION_MODIFIED; for(i=1;iposition[i].name,"Position %d",i+1); - g->position[i].modified = GS_POSITION_MODIFIED; + sprintf(g->guild.position[i].name,"Position %d",i+1); + g->guild.position[i].modified = GS_POSITION_MODIFIED; } // Initialize guild property - g->max_member=16; - g->average_lv=master->lv; - g->connect_member=1; + g->guild.max_member=16; + g->guild.average_lv=master->lv; + g->guild.connect_member=1; for(i=0;iskill[i].id=i + GD_SKILLBASE; - g->guild_id= -1; //Request to create guild. + g->guild.skill[i].id=i + GD_SKILLBASE; + g->guild.guild_id= -1; //Request to create guild. // Create the guild - if (!inter_guild_tosql(g,GS_BASIC|GS_POSITION|GS_SKILL|GS_MEMBER)) { + if (!inter_guild_tosql(g->guild,GS_BASIC|GS_POSITION|GS_SKILL|GS_MEMBER)) { //Failed to Create guild.... - ShowError("Failed to create Guild %s (Guild Master: %s)\n", g->name, g->master); + ShowError("Failed to create Guild %s (Guild Master: %s)\n", g->guild.name, g->guild.master); mapif_guild_created(fd,account_id,NULL); return 0; } - ShowInfo("Created Guild %d - %s (Guild Master: %s)\n", g->guild_id, g->name, g->master); + ShowInfo("Created Guild %d - %s (Guild Master: %s)\n", g->guild.guild_id, g->guild.name, g->guild.master); // Add to cache - guild_db[g->guild_id] = g; + guild_db[g->guild.guild_id] = g; // Report to client - mapif_guild_created(fd,account_id,g); - mapif_guild_info(fd,g); + mapif_guild_created(fd, account_id, &g->guild); + mapif_guild_info(fd,g->guild); if(charserv_config.log_inter) inter_log("guild %s (id=%d) created by master %s (id=%d)\n", - name, g->guild_id, master->name, master->account_id ); + name, g->guild.guild_id, master->name, master->account_id ); return 0; } @@ -1265,11 +1263,11 @@ int mapif_parse_CreateGuild(int fd,uint32 account_id,char *name,struct guild_mem // Return guild info to client int mapif_parse_GuildInfo(int fd,int guild_id) { - std::shared_ptr g = inter_guild_fromsql( guild_id ); + auto g = inter_guild_fromsql( guild_id ); if( g != nullptr ){ if (!guild_calcinfo(g)) - mapif_guild_info(fd,g); + mapif_guild_info(fd,g->guild); }else mapif_guild_noinfo(fd,guild_id); // Failed to load info return 0; @@ -1278,7 +1276,7 @@ int mapif_parse_GuildInfo(int fd,int guild_id) // Add member to guild int mapif_parse_GuildAddMember(int fd,int guild_id,struct guild_member *m) { - std::shared_ptr g = inter_guild_fromsql( guild_id ); + auto g = inter_guild_fromsql( guild_id ); if( g == nullptr ){ // Failed to add @@ -1287,14 +1285,14 @@ int mapif_parse_GuildAddMember(int fd,int guild_id,struct guild_member *m) } // Find an empty slot - for( int i = 0; i < g->max_member; i++ ){ - if(g->member[i].account_id==0) + for( int i = 0; i < g->guild.max_member; i++ ){ + if(g->guild.member[i].account_id==0) { - memcpy(&g->member[i],m,sizeof(struct guild_member)); - g->member[i].modified = (GS_MEMBER_NEW | GS_MEMBER_MODIFIED); + memcpy(&g->guild.member[i],m,sizeof(struct guild_member)); + g->guild.member[i].modified = (GS_MEMBER_NEW | GS_MEMBER_MODIFIED); mapif_guild_memberadded(fd,guild_id,m->account_id,m->char_id,0); if (!guild_calcinfo(g)) //Send members if it was not invoked. - mapif_guild_info(-1,g); + mapif_guild_info(-1,g->guild); g->save_flag |= GS_MEMBER; if (g->save_flag&GS_REMOVE) @@ -1313,19 +1311,19 @@ int mapif_parse_GuildLeave(int fd, int guild_id, uint32 account_id, uint32 char_ { int i; - std::shared_ptr g = inter_guild_fromsql( guild_id ); + auto g = inter_guild_fromsql( guild_id ); if( g == nullptr ){ // Unknown guild, just update the player if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `guild_id`='0' WHERE `account_id`='%d' AND `char_id`='%d'", schema_config.char_db, account_id, char_id) ) Sql_ShowDebug(sql_handle); - // mapif_guild_withdraw(guild_id,account_id,char_id,flag,g->member[i].name,mes); + // mapif_guild_withdraw(guild_id,account_id,char_id,flag,g->guild.member[i].name,mes); return 0; } // Find the member - ARR_FIND( 0, g->max_member, i, g->member[i].account_id == account_id && g->member[i].char_id == char_id ); - if( i == g->max_member ) + ARR_FIND( 0, g->guild.max_member, i, g->guild.member[i].account_id == account_id && g->guild.member[i].char_id == char_id ); + if( i == g->guild.max_member ) { //TODO member not found return 0; @@ -1335,31 +1333,31 @@ int mapif_parse_GuildLeave(int fd, int guild_id, uint32 account_id, uint32 char_ { // Write expulsion reason // Find an empty slot int j; - ARR_FIND( 0, MAX_GUILDEXPULSION, j, g->expulsion[j].account_id == 0 ); + ARR_FIND( 0, MAX_GUILDEXPULSION, j, g->guild.expulsion[j].account_id == 0 ); if( j == MAX_GUILDEXPULSION ) { // Expulsion list is full, flush the oldest one for( j = 0; j < MAX_GUILDEXPULSION - 1; j++ ) - g->expulsion[j] = g->expulsion[j+1]; + g->guild.expulsion[j] = g->guild.expulsion[j+1]; j = MAX_GUILDEXPULSION-1; } // Save the expulsion entry - g->expulsion[j].account_id = account_id; - safestrncpy(g->expulsion[j].name, g->member[i].name, NAME_LENGTH); - safestrncpy(g->expulsion[j].mes, mes, 40); + g->guild.expulsion[j].account_id = account_id; + safestrncpy(g->guild.expulsion[j].name, g->guild.member[i].name, NAME_LENGTH); + safestrncpy(g->guild.expulsion[j].mes, mes, 40); } - mapif_guild_withdraw(guild_id,account_id,char_id,flag,g->member[i].name,mes); - inter_guild_removemember_tosql(g->member[i].char_id); + mapif_guild_withdraw(guild_id,account_id,char_id,flag,g->guild.member[i].name,mes); + inter_guild_removemember_tosql(g->guild.member[i].char_id); - memset(&g->member[i],0,sizeof(struct guild_member)); + memset(&g->guild.member[i],0,sizeof(struct guild_member)); if( guild_check_empty(g) ) mapif_parse_BreakGuild(-1,guild_id); //Break the guild. else { //Update member info. if (!guild_calcinfo(g)) - mapif_guild_info(fd,g); + mapif_guild_info(fd,g->guild); g->save_flag |= GS_EXPULSION; } @@ -1373,45 +1371,45 @@ int mapif_parse_GuildChangeMemberInfoShort(int fd,int guild_id,uint32 account_id int i,sum,c; int prev_count, prev_alv; - std::shared_ptr g = inter_guild_fromsql( guild_id ); + auto g = inter_guild_fromsql( guild_id ); if( g == nullptr ){ return 0; } - ARR_FIND( 0, g->max_member, i, g->member[i].account_id == account_id && g->member[i].char_id == char_id ); - if( i < g->max_member ) + ARR_FIND( 0, g->guild.max_member, i, g->guild.member[i].account_id == account_id && g->guild.member[i].char_id == char_id ); + if( i < g->guild.max_member ) { - g->member[i].online = online; - g->member[i].lv = lv; - g->member[i].class_ = class_; - g->member[i].modified = GS_MEMBER_MODIFIED; - mapif_guild_memberinfoshort(g,i); + g->guild.member[i].online = online; + g->guild.member[i].lv = lv; + g->guild.member[i].class_ = class_; + g->guild.member[i].modified = GS_MEMBER_MODIFIED; + mapif_guild_memberinfoshort(g->guild,i); } - prev_count = g->connect_member; - prev_alv = g->average_lv; + prev_count = g->guild.connect_member; + prev_alv = g->guild.average_lv; - g->average_lv = 0; - g->connect_member = 0; + g->guild.average_lv = 0; + g->guild.connect_member = 0; c = 0; sum = 0; - for( i = 0; i < g->max_member; i++ ) + for( i = 0; i < g->guild.max_member; i++ ) { - if( g->member[i].account_id > 0 ) + if( g->guild.member[i].account_id > 0 ) { - sum += g->member[i].lv; + sum += g->guild.member[i].lv; c++; } - if( g->member[i].online ) - g->connect_member++; + if( g->guild.member[i].online ) + g->guild.connect_member++; } if( c ) // this check should always succeed... { - g->average_lv = sum / c; - if( g->connect_member != prev_count || g->average_lv != prev_alv ) + g->guild.average_lv = sum / c; + if( g->guild.connect_member != prev_count || g->guild.average_lv != prev_alv ) g->save_flag |= GS_CONNECT; if( g->save_flag & GS_REMOVE ) g->save_flag &= ~GS_REMOVE; @@ -1423,7 +1421,7 @@ int mapif_parse_GuildChangeMemberInfoShort(int fd,int guild_id,uint32 account_id // BreakGuild int mapif_parse_BreakGuild(int fd,int guild_id) { - std::shared_ptr g = inter_guild_fromsql( guild_id ); + auto g = inter_guild_fromsql( guild_id ); if( g == nullptr ){ return 0; @@ -1462,7 +1460,7 @@ int mapif_parse_BreakGuild(int fd,int guild_id) mapif_guild_broken(guild_id,0); if(charserv_config.log_inter) - inter_log("guild %s (id=%d) broken\n",g->name,guild_id); + inter_log("guild %s (id=%d) broken\n",g->guild.name,guild_id); // Remove the guild from memory. [Skotlex] guild_db.erase( guild_id ); @@ -1479,7 +1477,7 @@ int mapif_parse_GuildMessage(int fd,int guild_id,uint32 account_id,char *mes,int // Modification of the guild int mapif_parse_GuildBasicInfoChange(int fd,int guild_id,int type,const char *data,int len) { - std::shared_ptr g = inter_guild_fromsql( guild_id ); + auto g = inter_guild_fromsql( guild_id ); if( g == nullptr ){ return 0; @@ -1489,13 +1487,13 @@ int mapif_parse_GuildBasicInfoChange(int fd,int guild_id,int type,const char *da switch(type) { case GBI_GUILDLV: - if (data_value > 0 && g->guild_lv + data_value <= MAX_GUILDLEVEL) { - g->guild_lv += data_value; - g->skill_point += data_value; - } else if (data_value < 0 && g->guild_lv + data_value >= 1) - g->guild_lv += data_value; + if (data_value > 0 && g->guild.guild_lv + data_value <= MAX_GUILDLEVEL) { + g->guild.guild_lv += data_value; + g->guild.skill_point += data_value; + } else if (data_value < 0 && g->guild.guild_lv + data_value >= 1) + g->guild.guild_lv += data_value; - mapif_guild_info(-1, g); + mapif_guild_info(-1, g->guild); g->save_flag |= GS_LEVEL; return 0; default: @@ -1522,22 +1520,22 @@ int mapif_parse_GuildMemberInfoChange(int fd,int guild_id,uint32 account_id,uint // Could make some improvement in speed, because only change guild_member int i; - std::shared_ptr g = inter_guild_fromsql( guild_id ); + auto g = inter_guild_fromsql( guild_id ); if( g == nullptr ){ return 0; } // Search the member - for(i=0;imax_member;i++) - if( g->member[i].account_id==account_id && - g->member[i].char_id==char_id ) + for(i=0;iguild.max_member;i++) + if( g->guild.member[i].account_id==account_id && + g->guild.member[i].char_id==char_id ) break; // Not Found - if(i==g->max_member){ + if(i==g->guild.max_member){ ShowWarning("int_guild: GuildMemberChange: Not found %d,%d in guild (%d - %s)\n", - account_id,char_id,guild_id,g->name); + account_id,char_id,guild_id,g->guild.name); return 0; } @@ -1545,30 +1543,30 @@ int mapif_parse_GuildMemberInfoChange(int fd,int guild_id,uint32 account_id,uint { case GMI_POSITION: { - g->member[i].position=*((short *)data); - g->member[i].modified = GS_MEMBER_MODIFIED; + g->guild.member[i].position=*((short *)data); + g->guild.member[i].modified = GS_MEMBER_MODIFIED; mapif_guild_memberinfochanged(guild_id,account_id,char_id,type,data,len); g->save_flag |= GS_MEMBER; break; } case GMI_EXP: { // EXP - t_exp old_exp=g->member[i].exp; - g->member[i].exp=*((t_exp *)data); - g->member[i].modified = GS_MEMBER_MODIFIED; - if (g->member[i].exp > old_exp) + t_exp old_exp=g->guild.member[i].exp; + g->guild.member[i].exp=*((t_exp *)data); + g->guild.member[i].modified = GS_MEMBER_MODIFIED; + if (g->guild.member[i].exp > old_exp) { - t_exp exp = g->member[i].exp - old_exp; + t_exp exp = g->guild.member[i].exp - old_exp; // Compute gained exp if (charserv_config.guild_exp_rate != 100) exp = exp*(charserv_config.guild_exp_rate)/100; // Update guild exp - g->exp = util::safe_addition_cap(g->exp, exp, MAX_GUILD_EXP); + g->guild.exp = util::safe_addition_cap(g->guild.exp, exp, MAX_GUILD_EXP); guild_calcinfo(g); - mapif_guild_basicinfochanged(guild_id,GBI_EXP,&g->exp,sizeof(g->exp)); + mapif_guild_basicinfochanged(guild_id,GBI_EXP,&g->guild.exp,sizeof(g->guild.exp)); g->save_flag |= GS_LEVEL; } mapif_guild_memberinfochanged(guild_id,account_id,char_id,type,data,len); @@ -1577,40 +1575,40 @@ int mapif_parse_GuildMemberInfoChange(int fd,int guild_id,uint32 account_id,uint } case GMI_HAIR: { - g->member[i].hair=*((short *)data); - g->member[i].modified = GS_MEMBER_MODIFIED; + g->guild.member[i].hair=*((short *)data); + g->guild.member[i].modified = GS_MEMBER_MODIFIED; mapif_guild_memberinfochanged(guild_id,account_id,char_id,type,data,len); g->save_flag |= GS_MEMBER; //Save new data. break; } case GMI_HAIR_COLOR: { - g->member[i].hair_color=*((short *)data); - g->member[i].modified = GS_MEMBER_MODIFIED; + g->guild.member[i].hair_color=*((short *)data); + g->guild.member[i].modified = GS_MEMBER_MODIFIED; mapif_guild_memberinfochanged(guild_id,account_id,char_id,type,data,len); g->save_flag |= GS_MEMBER; //Save new data. break; } case GMI_GENDER: { - g->member[i].gender=*((short *)data); - g->member[i].modified = GS_MEMBER_MODIFIED; + g->guild.member[i].gender=*((short *)data); + g->guild.member[i].modified = GS_MEMBER_MODIFIED; mapif_guild_memberinfochanged(guild_id,account_id,char_id,type,data,len); g->save_flag |= GS_MEMBER; //Save new data. break; } case GMI_CLASS: { - g->member[i].class_=*((short *)data); - g->member[i].modified = GS_MEMBER_MODIFIED; + g->guild.member[i].class_=*((short *)data); + g->guild.member[i].modified = GS_MEMBER_MODIFIED; mapif_guild_memberinfochanged(guild_id,account_id,char_id,type,data,len); g->save_flag |= GS_MEMBER; //Save new data. break; } case GMI_LEVEL: { - g->member[i].lv=*((short *)data); - g->member[i].modified = GS_MEMBER_MODIFIED; + g->guild.member[i].lv=*((short *)data); + g->guild.member[i].modified = GS_MEMBER_MODIFIED; mapif_guild_memberinfochanged(guild_id,account_id,char_id,type,data,len); g->save_flag |= GS_MEMBER; //Save new data. break; @@ -1631,33 +1629,33 @@ int inter_guild_charname_changed(int guild_id,uint32 account_id, uint32 char_id, { int i, flag = 0; - std::shared_ptr g = inter_guild_fromsql( guild_id ); + auto g = inter_guild_fromsql( guild_id ); if( g == nullptr ){ ShowError("inter_guild_charrenamed: Can't find guild %d.\n", guild_id); return 0; } - ARR_FIND(0, g->max_member, i, g->member[i].char_id == char_id); - if( i == g->max_member ) + ARR_FIND(0, g->guild.max_member, i, g->guild.member[i].char_id == char_id); + if( i == g->guild.max_member ) { ShowError("inter_guild_charrenamed: Can't find character %d in the guild\n", char_id); return 0; } - if( !strcmp(g->member[i].name, g->master) ) + if( !strcmp(g->guild.member[i].name, g->guild.master) ) { - safestrncpy(g->master, name, NAME_LENGTH); + safestrncpy(g->guild.master, name, NAME_LENGTH); flag |= GS_BASIC; } - safestrncpy(g->member[i].name, name, NAME_LENGTH); - g->member[i].modified = GS_MEMBER_MODIFIED; + safestrncpy(g->guild.member[i].name, name, NAME_LENGTH); + g->guild.member[i].modified = GS_MEMBER_MODIFIED; flag |= GS_MEMBER; - if( !inter_guild_tosql(g, flag) ) + if( !inter_guild_tosql(g->guild, flag) ) return 0; - mapif_guild_info(-1,g); + mapif_guild_info(-1,g->guild); return 0; } @@ -1666,15 +1664,15 @@ int inter_guild_charname_changed(int guild_id,uint32 account_id, uint32 char_id, int mapif_parse_GuildPosition(int fd,int guild_id,int idx,struct guild_position *p) { // Could make some improvement in speed, because only change guild_position - std::shared_ptr g = inter_guild_fromsql( guild_id ); + auto g = inter_guild_fromsql( guild_id ); if( g == nullptr || idx < 0 || idx >= MAX_GUILDPOSITION ){ return 0; } - memcpy(&g->position[idx],p,sizeof(struct guild_position)); - mapif_guild_position(g,idx); - g->position[idx].modified = GS_POSITION_MODIFIED; + memcpy(&g->guild.position[idx],p,sizeof(struct guild_position)); + mapif_guild_position(g->guild,idx); + g->guild.position[idx].modified = GS_POSITION_MODIFIED; g->save_flag |= GS_POSITION; // Change guild_position return 0; } @@ -1684,39 +1682,39 @@ int mapif_parse_GuildSkillUp(int fd,int guild_id,uint16 skill_id,uint32 account_ { int idx = skill_id - GD_SKILLBASE; - std::shared_ptr g = inter_guild_fromsql( guild_id ); + auto g = inter_guild_fromsql( guild_id ); if( g == nullptr || idx < 0 || idx >= MAX_GUILDSKILL ){ return 0; } - if(g->skill_point>0 && g->skill[idx].id>0 && g->skill[idx].lvguild.skill_point>0 && g->guild.skill[idx].id>0 && g->guild.skill[idx].lvskill[idx].lv++; - g->skill_point--; + g->guild.skill[idx].lv++; + g->guild.skill_point--; if (!guild_calcinfo(g)) - mapif_guild_info(-1,g); + mapif_guild_info(-1,g->guild); mapif_guild_skillupack(guild_id,skill_id,account_id); g->save_flag |= (GS_LEVEL|GS_SKILL); // Change guild & guild_skill if (skill_id == GD_GUILD_STORAGE) - inter_guild_tosql(g, g->save_flag); // Force save for GD_GUILD_STORAGE + inter_guild_tosql(g->guild, g->save_flag); // Force save for GD_GUILD_STORAGE } return 0; } //Manual deletion of an alliance when partnering guild does not exists. [Skotlex] -int mapif_parse_GuildDeleteAlliance( std::shared_ptr g, int guild_id, uint32 account_id1, uint32 account_id2, int flag ){ +int mapif_parse_GuildDeleteAlliance( std::shared_ptr &g, int guild_id, uint32 account_id1, uint32 account_id2, int flag ){ int i; char name[NAME_LENGTH]; - ARR_FIND( 0, MAX_GUILDALLIANCE, i, g->alliance[i].guild_id == guild_id ); + ARR_FIND( 0, MAX_GUILDALLIANCE, i, g->guild.alliance[i].guild_id == guild_id ); if( i == MAX_GUILDALLIANCE ) return -1; - strcpy(name, g->alliance[i].name); - g->alliance[i].guild_id=0; + strcpy(name, g->guild.alliance[i].name); + g->guild.alliance[i].guild_id=0; - mapif_guild_alliance(g->guild_id,guild_id,account_id1,account_id2,flag,g->name,name); + mapif_guild_alliance(g->guild.guild_id,guild_id,account_id1,account_id2,flag,g->guild.name,name); g->save_flag |= GS_ALLIANCE; return 0; } @@ -1734,7 +1732,7 @@ int mapif_parse_GuildDeleteAlliance( std::shared_ptr g, int guild_ int mapif_parse_GuildAlliance(int fd,int guild_id1,int guild_id2,uint32 account_id1,uint32 account_id2,int flag) { // Could speed up - std::shared_ptr g[2]; + std::shared_ptr g[2]; int j,i; g[0] = inter_guild_fromsql(guild_id1); g[1] = inter_guild_fromsql(guild_id2); @@ -1753,9 +1751,9 @@ int mapif_parse_GuildAlliance(int fd,int guild_id1,int guild_id2,uint32 account_ // Remove alliance/opposition, in case of alliance, remove on both side for(i=0;i<2-(flag&GUILD_ALLIANCE_TYPE_MASK);i++) { - ARR_FIND( 0, MAX_GUILDALLIANCE, j, g[i]->alliance[j].guild_id == g[1-i]->guild_id && g[i]->alliance[j].opposition == (flag&GUILD_ALLIANCE_TYPE_MASK) ); + ARR_FIND( 0, MAX_GUILDALLIANCE, j, g[i]->guild.alliance[j].guild_id == g[1-i]->guild.guild_id && g[i]->guild.alliance[j].opposition == (flag&GUILD_ALLIANCE_TYPE_MASK) ); if( j < MAX_GUILDALLIANCE ) - g[i]->alliance[j].guild_id = 0; + g[i]->guild.alliance[j].guild_id = 0; } } else @@ -1764,19 +1762,19 @@ int mapif_parse_GuildAlliance(int fd,int guild_id1,int guild_id2,uint32 account_ for(i=0;i<2-(flag&GUILD_ALLIANCE_TYPE_MASK);i++) { // Search an empty slot - ARR_FIND( 0, MAX_GUILDALLIANCE, j, g[i]->alliance[j].guild_id == 0 ); + ARR_FIND( 0, MAX_GUILDALLIANCE, j, g[i]->guild.alliance[j].guild_id == 0 ); if( j < MAX_GUILDALLIANCE ) { - g[i]->alliance[j].guild_id=g[1-i]->guild_id; - memcpy(g[i]->alliance[j].name,g[1-i]->name,NAME_LENGTH); + g[i]->guild.alliance[j].guild_id = g[1-i]->guild.guild_id; + memcpy(g[i]->guild.alliance[j].name,g[1-i]->guild.name,NAME_LENGTH); // Set alliance type - g[i]->alliance[j].opposition = flag&GUILD_ALLIANCE_TYPE_MASK; + g[i]->guild.alliance[j].opposition = flag&GUILD_ALLIANCE_TYPE_MASK; } } } // Send on all map the new alliance/opposition - mapif_guild_alliance(guild_id1,guild_id2,account_id1,account_id2,flag,g[0]->name,g[1]->name); + mapif_guild_alliance(guild_id1,guild_id2,account_id1,account_id2,flag,g[0]->guild.name,g[1]->guild.name); // Mark the two guild to be saved g[0]->save_flag |= GS_ALLIANCE; @@ -1787,35 +1785,35 @@ int mapif_parse_GuildAlliance(int fd,int guild_id1,int guild_id2,uint32 account_ // Change guild message int mapif_parse_GuildNotice(int fd,int guild_id,const char *mes1,const char *mes2) { - std::shared_ptr g = inter_guild_fromsql( guild_id ); + auto g = inter_guild_fromsql( guild_id ); if( g == nullptr ){ return 0; } - memcpy(g->mes1,mes1,MAX_GUILDMES1); - memcpy(g->mes2,mes2,MAX_GUILDMES2); + memcpy(g->guild.mes1,mes1,MAX_GUILDMES1); + memcpy(g->guild.mes2,mes2,MAX_GUILDMES2); g->save_flag |= GS_MES; //Change mes of guild - inter_guild_tosql(g, g->save_flag); - return mapif_guild_notice(g); + inter_guild_tosql(g->guild, g->save_flag); + return mapif_guild_notice(g->guild); } int mapif_parse_GuildEmblem(int fd,int len,int guild_id,int dummy,const char *data) { - std::shared_ptr g = inter_guild_fromsql( guild_id ); + auto g = inter_guild_fromsql( guild_id ); if( g == nullptr ){ return 0; } - if (len > sizeof(g->emblem_data)) - len = sizeof(g->emblem_data); + if (len > sizeof(g->guild.emblem_data)) + len = sizeof(g->guild.emblem_data); - memcpy(g->emblem_data,data,len); - g->emblem_len=len; - g->emblem_id++; + memcpy(g->guild.emblem_data,data,len); + g->guild.emblem_len=len; + g->guild.emblem_id++; g->save_flag |= GS_EMBLEM; //Change guild - return mapif_guild_emblem(g); + return mapif_guild_emblem(g->guild); } int mapif_parse_GuildCastleDataLoad(int fd, int len, int *castle_ids) @@ -1836,9 +1834,9 @@ int mapif_parse_GuildCastleDataSave(int fd, int castle_id, int index, int value) case CD_GUILD_ID: if (charserv_config.log_inter && gc->guild_id != value) { int gid = (value) ? value : gc->guild_id; - std::shared_ptr g = util::umap_find( guild_db, gid ); + auto g = util::umap_find( guild_db, gid ); inter_log("guild %s (id=%d) %s castle id=%d\n", - (g) ? g->name : "??", gid, (value) ? "occupy" : "abandon", castle_id); + (g) ? g->guild.name : "??", gid, (value) ? "occupy" : "abandon", castle_id); } gc->guild_id = value; break; @@ -1867,53 +1865,53 @@ int mapif_parse_GuildMasterChange(int fd, int guild_id, const char* name, int le struct guild_member gm; int pos; - std::shared_ptr g = inter_guild_fromsql( guild_id ); + auto g = inter_guild_fromsql( guild_id ); if( g == nullptr || len > NAME_LENGTH ){ return 0; } // Find member (name) - for (pos = 0; pos < g->max_member && strncmp(g->member[pos].name, name, len); pos++); + for (pos = 0; pos < g->guild.max_member && strncmp(g->guild.member[pos].name, name, len); pos++); - if (pos == g->max_member) + if (pos == g->guild.max_member) return 0; //Character not found?? // Switch current and old GM - memcpy(&gm, &g->member[pos], sizeof (struct guild_member)); - memcpy(&g->member[pos], &g->member[0], sizeof(struct guild_member)); - memcpy(&g->member[0], &gm, sizeof(struct guild_member)); + memcpy(&gm, &g->guild.member[pos], sizeof (struct guild_member)); + memcpy(&g->guild.member[pos], &g->guild.member[0], sizeof(struct guild_member)); + memcpy(&g->guild.member[0], &gm, sizeof(struct guild_member)); // Switch positions - g->member[pos].position = g->member[0].position; - g->member[pos].modified = GS_MEMBER_MODIFIED; - g->member[0].position = 0; //Position 0: guild Master. - g->member[0].modified = GS_MEMBER_MODIFIED; + g->guild.member[pos].position = g->guild.member[0].position; + g->guild.member[pos].modified = GS_MEMBER_MODIFIED; + g->guild.member[0].position = 0; //Position 0: guild Master. + g->guild.member[0].modified = GS_MEMBER_MODIFIED; // Store changing time - g->last_leader_change = time(NULL); + g->guild.last_leader_change = time(NULL); - safestrncpy(g->master, name, len); + safestrncpy(g->guild.master, name, len); if (len < NAME_LENGTH) - g->master[len] = '\0'; + g->guild.master[len] = '\0'; - ShowInfo("int_guild: Guildmaster Changed to %s (Guild %d - %s)\n",g->master, guild_id, g->name); + ShowInfo("int_guild: Guildmaster Changed to %s (Guild %d - %s)\n",g->guild.master, guild_id, g->guild.name); g->save_flag |= (GS_BASIC|GS_MEMBER); //Save main data and member data. - return mapif_guild_master_changed(g, g->member[0].account_id, g->member[0].char_id, g->last_leader_change); + return mapif_guild_master_changed(g->guild, g->guild.member[0].account_id, g->guild.member[0].char_id, g->guild.last_leader_change); } int mapif_parse_GuildEmblemVersion(int fd, int guild_id, int version) { - std::shared_ptr g = inter_guild_fromsql( guild_id ); + auto g = inter_guild_fromsql( guild_id ); if (g == nullptr) return 0; - g->emblem_len = 0; - g->emblem_id = version; + g->guild.emblem_len = 0; + g->guild.emblem_id = version; g->save_flag |= GS_EMBLEM; - mapif_guild_emblem_version(g); + mapif_guild_emblem_version(g->guild); return 1; } diff --git a/src/char/int_guild.hpp b/src/char/int_guild.hpp index 564ef824cf..5a48594ef5 100644 --- a/src/char/int_guild.hpp +++ b/src/char/int_guild.hpp @@ -8,6 +8,7 @@ #include #include +#include enum e_guild_action : uint32 { GS_BASIC = 0x0001, @@ -25,7 +26,7 @@ enum e_guild_action : uint32 { GS_REMOVE = 0x8000, }; -struct guild; +struct mmo_guild; struct guild_castle; struct s_guild_exp_db { @@ -47,6 +48,12 @@ public: t_exp get_nextexp(uint16 level); }; +class CharGuild { +public: + struct mmo_guild guild; + unsigned short save_flag; +}; + int inter_guild_parse_frommap(int fd); void inter_guild_sql_init(void); void inter_guild_sql_final(void); diff --git a/src/common/mmo.hpp b/src/common/mmo.hpp index f88555b328..cabf20d946 100644 --- a/src/common/mmo.hpp +++ b/src/common/mmo.hpp @@ -743,7 +743,7 @@ struct guild_skill { }; struct Channel; -struct guild { +struct mmo_guild { int guild_id; short guild_lv, connect_member, max_member, average_lv; t_exp exp; @@ -758,14 +758,7 @@ struct guild { struct guild_alliance alliance[MAX_GUILDALLIANCE]; struct guild_expulsion expulsion[MAX_GUILDEXPULSION]; struct guild_skill skill[MAX_GUILDSKILL]; - struct Channel *channel; - int instance_id; time_t last_leader_change; - - /* Used by char-server to save events for guilds */ - unsigned short save_flag; - - int32 chargeshout_flag_id; }; enum e_woe_type{ diff --git a/src/map/atcommand.cpp b/src/map/atcommand.cpp index 7bd0e3a2d0..ff5f07be77 100644 --- a/src/map/atcommand.cpp +++ b/src/map/atcommand.cpp @@ -809,7 +809,7 @@ ACMD_FUNC(who) { } default: { struct party_data *p = party_search(pl_sd->status.party_id); - struct guild *g = pl_sd->guild; + auto &g = pl_sd->guild; StringBuf_Printf(&buf, msg_txt(sd,343), pl_sd->status.name); // "Name: %s " if (pc_get_group_id(pl_sd) > 0) // Player title, if exists @@ -817,7 +817,7 @@ ACMD_FUNC(who) { if (p != NULL) StringBuf_Printf(&buf, msg_txt(sd,345), p->party.name); // " | Party: '%s'" if (g != NULL) - StringBuf_Printf(&buf, msg_txt(sd,346), g->name); // " | Guild: '%s'" + StringBuf_Printf(&buf, msg_txt(sd,346), g->guild.name); // " | Guild: '%s'" break; } } @@ -861,7 +861,6 @@ ACMD_FUNC(whogm) int level; char match_text[CHAT_SIZE_MAX]; char player_name[NAME_LENGTH]; - struct guild *g; struct party_data *p; nullpo_retr(-1, sd); @@ -914,10 +913,10 @@ ACMD_FUNC(whogm) clif_displaymessage(fd, atcmd_output); p = party_search(pl_sd->status.party_id); - g = pl_sd->guild; + auto &g = pl_sd->guild; sprintf(atcmd_output,msg_txt(sd,916), // Party: '%s' | Guild: '%s' - p?p->party.name:msg_txt(sd,917), g?g->name:msg_txt(sd,917)); // None. + p?p->party.name:msg_txt(sd,917), g?g->guild.name:msg_txt(sd,917)); // None. clif_displaymessage(fd, atcmd_output); count++; @@ -3050,7 +3049,6 @@ ACMD_FUNC(trait_all) { ACMD_FUNC(guildlevelup) { int level = 0; short added_level; - struct guild *guild_info; nullpo_retr(-1, sd); if (!message || !*message || sscanf(message, "%11d", &level) < 1 || level == 0) { @@ -3058,7 +3056,9 @@ ACMD_FUNC(guildlevelup) { return -1; } - if (sd->status.guild_id <= 0 || (guild_info = sd->guild) == NULL) { + auto &guild_info = sd->guild; + + if (sd->status.guild_id <= 0 || guild_info == nullptr) { clif_displaymessage(fd, msg_txt(sd,43)); // You're not in a guild. return -1; } @@ -3068,13 +3068,13 @@ ACMD_FUNC(guildlevelup) { //} added_level = (short)level; - if (level > 0 && (level > MAX_GUILDLEVEL || added_level > ((short)MAX_GUILDLEVEL - guild_info->guild_lv))) // fix positive overflow - added_level = (short)MAX_GUILDLEVEL - guild_info->guild_lv; - else if (level < 0 && (level < -MAX_GUILDLEVEL || added_level < (1 - guild_info->guild_lv))) // fix negative overflow - added_level = 1 - guild_info->guild_lv; + if (level > 0 && (level > MAX_GUILDLEVEL || added_level > ((short)MAX_GUILDLEVEL - guild_info->guild.guild_lv))) // fix positive overflow + added_level = (short)MAX_GUILDLEVEL - guild_info->guild.guild_lv; + else if (level < 0 && (level < -MAX_GUILDLEVEL || added_level < (1 - guild_info->guild.guild_lv))) // fix negative overflow + added_level = 1 - guild_info->guild.guild_lv; if (added_level != 0) { - intif_guild_change_basicinfo(guild_info->guild_id, GBI_GUILDLV, &added_level, sizeof(added_level)); + intif_guild_change_basicinfo(guild_info->guild.guild_id, GBI_GUILDLV, &added_level, sizeof(added_level)); clif_displaymessage(fd, msg_txt(sd,179)); // Guild level changed. } else { clif_displaymessage(fd, msg_txt(sd,45)); // Guild level change failed. @@ -3856,12 +3856,10 @@ ACMD_FUNC(breakguild) nullpo_retr(-1, sd); if (sd->status.guild_id) { // Check if the player has a guild - struct guild *g; - g = sd->guild; // Search the guild - if (g) { // Check if guild was found + if (sd->guild) { // Check if guild was found if (sd->state.gmaster_flag) { // Check if player is guild master int ret = 0; - ret = guild_break(sd, g->name); // Break guild + ret = guild_break(sd, sd->guild->guild.name); // Break guild if (ret) { // Check if anything went wrong return 0; // Guild was broken } else { @@ -4083,7 +4081,6 @@ ACMD_FUNC(guildrecall) struct s_mapiterator* iter; int count; char guild_name[NAME_LENGTH]; - struct guild *g; nullpo_retr(-1, sd); memset(guild_name, '\0', sizeof(guild_name)); @@ -4099,9 +4096,8 @@ ACMD_FUNC(guildrecall) return -1; } - if ((g = guild_searchname(guild_name)) == NULL && // name first to avoid error when name begin with a number - (g = guild_search(atoi(message))) == NULL) - { + auto g = guild_searchnameid(guild_name); + if (!g) { clif_displaymessage(fd, msg_txt(sd,94)); // Incorrect name/ID, or no one from the guild is online. return -1; } @@ -4111,7 +4107,7 @@ ACMD_FUNC(guildrecall) iter = mapit_getallusers(); for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) ) { - if (sd->status.account_id != pl_sd->status.account_id && pl_sd->status.guild_id == g->guild_id) + if (sd->status.account_id != pl_sd->status.account_id && pl_sd->status.guild_id == g->guild.guild_id) { if (pc_get_group_level(pl_sd) > pc_get_group_level(sd) || (pl_sd->bl.m == sd->bl.m && pl_sd->bl.x == sd->bl.x && pl_sd->bl.y == sd->bl.y)) continue; // Skip GMs greater than you... or chars already on the cell @@ -4126,7 +4122,7 @@ ACMD_FUNC(guildrecall) } mapit_free(iter); - sprintf(atcmd_output, msg_txt(sd,93), g->name); // All online characters of the %s guild have been recalled to your position. + sprintf(atcmd_output, msg_txt(sd,93), g->guild.name); // All online characters of the %s guild have been recalled to your position. clif_displaymessage(fd, atcmd_output); if (count) { sprintf(atcmd_output, msg_txt(sd,1033), count); // Because you are not authorized to warp from some maps, %d player(s) have not been recalled. @@ -4791,7 +4787,6 @@ ACMD_FUNC(mount_peco) ACMD_FUNC(guildspy) { char guild_name[NAME_LENGTH]; - struct guild *g; nullpo_retr(-1, sd); memset(guild_name, '\0', sizeof(guild_name)); @@ -4807,22 +4802,22 @@ ACMD_FUNC(guildspy) return -1; } - if ((g = guild_searchname(guild_name)) != NULL || // name first to avoid error when name begin with a number - (g = guild_search(atoi(message))) != NULL) { - if (sd->guildspy == g->guild_id) { - sd->guildspy = 0; - sprintf(atcmd_output, msg_txt(sd,103), g->name); // No longer spying on the %s guild. - clif_displaymessage(fd, atcmd_output); - } else { - sd->guildspy = g->guild_id; - sprintf(atcmd_output, msg_txt(sd,104), g->name); // Spying on the %s guild. - clif_displaymessage(fd, atcmd_output); - } - } else { + auto g = guild_searchnameid(guild_name); + if (!g) { clif_displaymessage(fd, msg_txt(sd,94)); // Incorrect name/ID, or no one from the specified guild is online. return -1; } + if (sd->guildspy == g->guild.guild_id) { + sd->guildspy = 0; + sprintf(atcmd_output, msg_txt(sd,103), g->guild.name); // No longer spying on the %s guild. + clif_displaymessage(fd, atcmd_output); + } else { + sd->guildspy = g->guild.guild_id; + sprintf(atcmd_output, msg_txt(sd,104), g->guild.name); // Spying on the %s guild. + clif_displaymessage(fd, atcmd_output); + } + return 0; } @@ -5506,8 +5501,6 @@ ACMD_FUNC(disguiseguild) { int id = 0, i; char monster[NAME_LENGTH], guild[NAME_LENGTH]; - - struct guild *g; memset(monster, '\0', sizeof(monster)); memset(guild, '\0', sizeof(guild)); @@ -5533,14 +5526,15 @@ ACMD_FUNC(disguiseguild) return -1; } - if( (g = guild_searchname(guild)) == NULL && (g = guild_search(atoi(guild))) == NULL ) { + auto g = guild_searchnameid(guild); + if (!g) { clif_displaymessage(fd, msg_txt(sd,94)); // Incorrect name/ID, or no one from the guild is online. return -1; } - for( i = 0; i < g->max_member; i++ ){ + for( i = 0; i < g->guild.max_member; i++ ){ map_session_data *pl_sd; - if( (pl_sd = g->member[i].sd) && !pc_isriding(pl_sd) ) + if( (pl_sd = g->guild.member[i].sd) && !pc_isriding(pl_sd) ) pc_disguise(pl_sd, id); } @@ -5592,7 +5586,6 @@ ACMD_FUNC(undisguiseall) ACMD_FUNC(undisguiseguild) { char guild_name[NAME_LENGTH]; - struct guild *g; int i; nullpo_retr(-1, sd); @@ -5603,14 +5596,15 @@ ACMD_FUNC(undisguiseguild) return -1; } - if( (g = guild_searchname(guild_name)) == NULL && (g = guild_search(atoi(message))) == NULL ) { + auto g = guild_searchnameid(guild_name); + if (!g) { clif_displaymessage(fd, msg_txt(sd,94)); // Incorrect name/ID, or no one from the guild is online. return -1; } - for(i = 0; i < g->max_member; i++){ + for(i = 0; i < g->guild.max_member; i++){ map_session_data *pl_sd; - if( (pl_sd = g->member[i].sd) && pl_sd->disguise ) + if( (pl_sd = g->guild.member[i].sd) && pl_sd->disguise ) pc_disguise(pl_sd, 0); } @@ -6028,13 +6022,10 @@ ACMD_FUNC(clearstorage) ACMD_FUNC(cleargstorage) { int i, j; - struct guild *g; struct s_storage *gstorage; nullpo_retr(-1, sd); - g = sd->guild; - - if (g == NULL) { + if (!sd->guild) { clif_displaymessage(fd, msg_txt(sd,43)); // You're not in a guild. return -1; } @@ -6487,13 +6478,12 @@ ACMD_FUNC(autotrade) { *------------------------------------------*/ ACMD_FUNC(changegm) { - struct guild *g; map_session_data *pl_sd; nullpo_retr(-1, sd); memset(atcmd_player_name, '\0', sizeof(atcmd_player_name)); - if (sd->status.guild_id == 0 || (g = sd->guild) == NULL || strcmp(g->master,sd->status.name)) { + if (sd->status.guild_id == 0 || sd->guild == NULL || strcmp(sd->guild->guild.master,sd->status.name)) { clif_displaymessage(fd, msg_txt(sd,1181)); // You need to be a Guild Master to use this command. return -1; } @@ -6522,7 +6512,7 @@ ACMD_FUNC(changegm) return -1; } - if( battle_config.guild_leaderchange_delay && DIFF_TICK(time(NULL),sd->guild->last_leader_change) < battle_config.guild_leaderchange_delay ){ + if( battle_config.guild_leaderchange_delay && DIFF_TICK(time(NULL),sd->guild->guild.last_leader_change) < battle_config.guild_leaderchange_delay ){ #if PACKETVER >= 20151001 clif_msg(sd, GUILD_MASTER_DELAY); #else @@ -8588,7 +8578,6 @@ ACMD_FUNC(sizeguild) int size = SZ_SMALL, i; char guild[NAME_LENGTH]; map_session_data *pl_sd; - struct guild *g; nullpo_retr(-1, sd); memset(guild, '\0', sizeof(guild)); @@ -8598,15 +8587,16 @@ ACMD_FUNC(sizeguild) return -1; } - if( (g = guild_searchname(guild)) == NULL && (g = guild_search(atoi(guild))) == NULL ) { + auto g = guild_searchnameid(guild); + if (!g) { clif_displaymessage(fd, msg_txt(sd,94)); // Incorrect name/ID, or no one from the guild is online. return -1; } size = cap_value(size,SZ_SMALL,SZ_BIG); - for( i = 0; i < g->max_member; i++ ) { - if( (pl_sd = g->member[i].sd) && pl_sd->state.size != size ) { + for( i = 0; i < g->guild.max_member; i++ ) { + if( (pl_sd = g->guild.member[i].sd) && pl_sd->state.size != size ) { if( pl_sd->state.size ) { pl_sd->state.size = SZ_SMALL; pc_setpos(pl_sd, pl_sd->mapindex, pl_sd->bl.x, pl_sd->bl.y, CLR_TELEPORT); diff --git a/src/map/battle.cpp b/src/map/battle.cpp index 1101c837aa..1610a9c577 100644 --- a/src/map/battle.cpp +++ b/src/map/battle.cpp @@ -2044,16 +2044,16 @@ bool battle_can_hit_gvg_target(struct block_list *src,struct block_list *bl,uint if ((status_bl_has_mode(bl,MD_SKILLIMMUNE) || (class_ == MOBID_EMPERIUM && !skill_get_inf2(skill_id, INF2_TARGETEMPERIUM))) && flag&BF_SKILL) //Skill immunity. return false; if( src->type != BL_MOB || mob_is_clone( ((struct mob_data*)src)->mob_id ) ){ - struct guild *g = src->type == BL_PC ? ((TBL_PC *)src)->guild : guild_search(status_get_guild_id(src)); + auto g = src->type == BL_PC ? ((TBL_PC *)src)->guild : guild_search(status_get_guild_id(src)); - if (class_ == MOBID_EMPERIUM && (!g || guild_checkskill(g,GD_APPROVAL) <= 0 )) + if (class_ == MOBID_EMPERIUM && (!g || guild_checkskill(g->guild, GD_APPROVAL) <= 0 )) return false; if (g != nullptr) { - if (battle_config.guild_max_castles && guild_checkcastles(g)>=battle_config.guild_max_castles) + if (battle_config.guild_max_castles && guild_checkcastles(g->guild)>=battle_config.guild_max_castles) return false; // [MouseJstr] - if (md->special_state.ai == AI_GUILD && g->guild_id == md->master_id) + if (md->special_state.ai == AI_GUILD && g->guild.guild_id == md->master_id) return false; } } diff --git a/src/map/battleground.cpp b/src/map/battleground.cpp index e17336718b..6dda37f8ba 100644 --- a/src/map/battleground.cpp +++ b/src/map/battleground.cpp @@ -1097,7 +1097,7 @@ void bg_queue_join_guild(const char *name, map_session_data *sd) return; // Someone has bypassed the client check for being in a guild } - if (strcmp(sd->status.name, sd->guild->master) != 0) { + if (strcmp(sd->status.name, sd->guild->guild.master) != 0) { clif_bg_queue_apply_result(BG_APPLY_PARTYGUILD_LEADER, name, sd); return; // Not the guild leader } @@ -1110,16 +1110,16 @@ void bg_queue_join_guild(const char *name, map_session_data *sd) return; } - struct guild* g = sd->guild; + auto &g = sd->guild; - if (g->connect_member > bg->max_players) { + if (g->guild.connect_member > bg->max_players) { clif_bg_queue_apply_result(BG_APPLY_PLAYER_COUNT, name, sd); return; // Too many guild members online } std::vector list; - for (const auto &it : g->member) { + for (const auto &it : g->guild.member) { if (list.size() == bg->max_players) break; diff --git a/src/map/channel.cpp b/src/map/channel.cpp index dae1d4f552..9210f96307 100644 --- a/src/map/channel.cpp +++ b/src/map/channel.cpp @@ -171,7 +171,7 @@ int channel_delete(struct Channel *channel, bool force) { aFree(channel); break; case CHAN_TYPE_ALLY: { - struct guild *g = guild_search(channel->gid); + auto g = guild_search(channel->gid); if(g) g->channel = NULL; aFree(channel); break; @@ -277,19 +277,20 @@ int channel_mjoin(map_session_data *sd) { * 0: Success * -1: Invalid guild or no channel for guild */ -int channel_ajoin(struct guild *g){ +int channel_ajoin(MapGuild &g) { int i, j; map_session_data *pl_sd; - if(!g || !g->channel) return -1; + if (!g.channel) + return -1; for (i = 0; i < MAX_GUILDALLIANCE; i++){ - struct guild *ag; //allied guld - struct guild_alliance *ga = &g->alliance[i]; //guild alliance + std::shared_ptr ag; //allied guild + struct guild_alliance *ga = &g.guild.alliance[i]; //guild alliance if(ga->guild_id && (ga->opposition==0) && (ag=guild_search(ga->guild_id))){ - for (j = 0; j < ag->max_member; j++){ //load all guildmember - pl_sd = ag->member[j].sd; + for (j = 0; j < ag->guild.max_member; j++){ //load all guildmember + pl_sd = ag->guild.member[j].sd; if(channel_haspc(ag->channel,pl_sd)==1) //only if they are in their own guildchan - channel_join(g->channel,pl_sd); + channel_join(g.channel,pl_sd); } } } @@ -308,17 +309,16 @@ int channel_ajoin(struct guild *g){ */ int channel_gjoin(map_session_data *sd, int flag){ struct Channel *channel; - struct guild *g; if(!sd || sd->state.autotrade) return -1; - g = sd->guild; + auto &g = sd->guild; if(!g) return -2; channel = g->channel; if(!channel){ - channel = channel_create_simple(NULL,NULL,CHAN_TYPE_ALLY,g->guild_id); + channel = channel_create_simple(NULL,NULL,CHAN_TYPE_ALLY,g->guild.guild_id); g->channel = channel; - channel_ajoin(g); + channel_ajoin(*g); } if(flag&1) { channel_join(channel,sd); //join our guild chat @@ -326,8 +326,8 @@ int channel_gjoin(map_session_data *sd, int flag){ if(flag&2){ int i; for (i = 0; i < MAX_GUILDALLIANCE; i++){ - struct guild *ag; //allied guld - struct guild_alliance *ga = &g->alliance[i]; //guild alliance + std::shared_ptr ag; //allied guild + struct guild_alliance *ga = &g->guild.alliance[i]; //guild alliance if(ga->guild_id && (ga->opposition==0) && (ag=guild_search(ga->guild_id)) ) //only join allies channel_join(ag->channel,sd); } @@ -401,14 +401,14 @@ int channel_pcquit(map_session_data *sd, int type){ // Leave all chat channels. if(type&(1|2) && channel_config.ally_tmpl.name[0] && sd->guild){ //quit guild and ally chan - struct guild *g = sd->guild; + auto &g = sd->guild; if(type&1 && channel_haspc(g->channel,sd)==1){ channel_clean(g->channel,sd,0); //leave guild chan } if(type&2){ for (i = 0; i < MAX_GUILDALLIANCE; i++) { //leave all alliance chan - struct guild *ag; //allied guild - if( g->alliance[i].guild_id && (ag = guild_search(g->alliance[i].guild_id) ) ) { + std::shared_ptr ag; //allied guild + if( g->guild.alliance[i].guild_id && (ag = guild_search(g->guild.alliance[i].guild_id) ) ) { if(channel_haspc(ag->channel,sd) == 1) channel_clean(ag->channel,sd,0); break; @@ -519,7 +519,7 @@ struct Channel* channel_name2channel(char *chname, map_session_data *sd, int fla } else if(sd && (strcmpi(chname + 1,channel_config.ally_tmpl.name) == 0) && sd->guild){ if(flag&1 && !sd->guild->channel) - sd->guild->channel = channel_create_simple(NULL,NULL,CHAN_TYPE_ALLY,sd->guild->guild_id); + sd->guild->channel = channel_create_simple(NULL,NULL,CHAN_TYPE_ALLY,sd->guild->guild.guild_id); if(flag&2 && channel_pc_haschan(sd,mapdata->channel) < 1) channel_gjoin(sd,3); return sd->guild->channel; @@ -630,7 +630,7 @@ int channel_display_list(map_session_data *sd, const char *options){ clif_displaymessage(sd->fd, output); } if( channel_config.ally_tmpl.name[0] && sd->status.guild_id ) { - struct guild *g = sd->guild; + auto &g = sd->guild; if (g && g->channel) { sprintf(output, msg_txt(sd,1409), g->channel->name, db_size(((struct Channel *)g->channel)->users));// - #%s (%d users) clif_displaymessage(sd->fd, output); diff --git a/src/map/channel.hpp b/src/map/channel.hpp index 78ff16a57f..6e6fc72948 100644 --- a/src/map/channel.hpp +++ b/src/map/channel.hpp @@ -10,7 +10,7 @@ //namespace rA { class map_session_data; -struct guild; +struct mmo_guild; struct DBMap; #define CHAN_NAME_LENGTH 20 @@ -95,7 +95,7 @@ int channel_delete(struct Channel *channel, bool force); int channel_join(struct Channel *channel, map_session_data *sd); int channel_mjoin(map_session_data *sd); int channel_gjoin(map_session_data *sd, int flag); -int channel_ajoin(struct guild *g); +int channel_ajoin(struct mmo_guild &g); int channel_clean(struct Channel *channel, map_session_data *sd, int flag); int channel_pcquit(map_session_data *sd, int type); diff --git a/src/map/clif.cpp b/src/map/clif.cpp index 0c28c6af37..7aaf851393 100644 --- a/src/map/clif.cpp +++ b/src/map/clif.cpp @@ -488,7 +488,6 @@ int clif_send(const void* buf, int len, struct block_list* bl, enum send_target int i; map_session_data *sd, *tsd; struct party_data *p = NULL; - struct guild *g = NULL; std::shared_ptr bg; int x0 = 0, x1 = 0, y0 = 0, y1 = 0, fd; struct s_mapiterator* iter; @@ -647,48 +646,47 @@ int clif_send(const void* buf, int len, struct block_list* bl, enum send_target case GUILD_SAMEMAP_WOS: case GUILD: case GUILD_WOS: - case GUILD_NOBG: - if (sd && sd->status.guild_id) - g = sd->guild; + case GUILD_NOBG: { + if (!sd || !sd->status.guild_id || !sd->guild) + break; - if (g) { - for(i = 0; i < g->max_member; i++) { - if( (sd = g->member[i].sd) != nullptr ){ - if( !session_isActive( fd = sd->fd ) ) - continue; + const auto &g = sd->guild->guild; + for(i = 0; i < g.max_member; i++) { + if( (sd = g.member[i].sd) != nullptr ){ + if( !session_isActive( fd = sd->fd ) ) + continue; - if( type == GUILD_NOBG && sd->bg_id ) - continue; + if( type == GUILD_NOBG && sd->bg_id ) + continue; - if( sd->bl.id == bl->id && (type == GUILD_WOS || type == GUILD_SAMEMAP_WOS || type == GUILD_AREA_WOS) ) - continue; + if( sd->bl.id == bl->id && (type == GUILD_WOS || type == GUILD_SAMEMAP_WOS || type == GUILD_AREA_WOS) ) + continue; - if( type != GUILD && type != GUILD_NOBG && type != GUILD_WOS && sd->bl.m != bl->m ) - continue; + if( type != GUILD && type != GUILD_NOBG && type != GUILD_WOS && sd->bl.m != bl->m ) + continue; - if( (type == GUILD_AREA || type == GUILD_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) ) - continue; + if( (type == GUILD_AREA || type == GUILD_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) ) + continue; - WFIFOHEAD(fd,len); - memcpy(WFIFOP(fd,0), buf, len); - WFIFOSET(fd,len); - } + WFIFOHEAD(fd,len); + memcpy(WFIFOP(fd,0), buf, len); + WFIFOSET(fd,len); } - if (!enable_spy) //Skip unnecessary parsing. [Skotlex] - break; - - iter = mapit_getallusers(); - while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){ - if( tsd->guildspy == g->guild_id && session_isActive( fd = tsd->fd ) ){ - WFIFOHEAD( fd, len ); - memcpy( WFIFOP( fd, 0 ), buf, len ); - WFIFOSET( fd, len ); - } - } - mapit_free(iter); } - break; + if (!enable_spy) //Skip unnecessary parsing. [Skotlex] + break; + iter = mapit_getallusers(); + while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){ + if( tsd->guildspy == g.guild_id && session_isActive( fd = tsd->fd ) ){ + WFIFOHEAD( fd, len ); + memcpy( WFIFOP( fd, 0 ), buf, len ); + WFIFOSET( fd, len ); + } + } + mapit_free(iter); + break; + } case BG_AREA: case BG_AREA_WOS: x0 = bl->x - AREA_SIZE; @@ -3311,12 +3309,12 @@ void clif_guild_xy_remove(map_session_data *sd) *------------------------------------------*/ void clif_guild_castle_list(map_session_data& sd){ #if PACKETVER_MAIN_NUM >= 20190731 || PACKETVER_RE_NUM >= 20190717 || PACKETVER_ZERO_NUM >= 20190814 - struct guild* g = sd.guild; + auto &g = sd.guild; if (g == nullptr) return; - int castle_count = guild_checkcastles(g); + int castle_count = guild_checkcastles(g->guild); if (castle_count > 0) { struct PACKET_ZC_GUILD_AGIT_INFO* p = (struct PACKET_ZC_GUILD_AGIT_INFO*)packet_buffer; @@ -3326,7 +3324,7 @@ void clif_guild_castle_list(map_session_data& sd){ int i = 0; for (const auto& gc : castle_db) { - if (gc.second->guild_id == g->guild_id && gc.second->client_id) { + if (gc.second->guild_id == g->guild.guild_id && gc.second->client_id) { p->castle_list[i] = static_cast( gc.second->client_id ); p->packetLength += static_cast( sizeof( p->castle_list[0] ) ); ++i; @@ -3378,7 +3376,7 @@ void clif_guild_castle_teleport_res(map_session_data& sd, enum e_siege_teleport_ void clif_parse_guild_castle_info_request(int fd, map_session_data* sd){ #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190522 || PACKETVER_ZERO_NUM >= 20190515 const struct PACKET_CZ_REQ_AGIT_INVESTMENT* p = (struct PACKET_CZ_REQ_AGIT_INVESTMENT*)RFIFOP(fd, 0); - struct guild* g = sd->guild; + auto &g = sd->guild; if (g == nullptr) return; @@ -3387,7 +3385,7 @@ void clif_parse_guild_castle_info_request(int fd, map_session_data* sd){ if (gc == nullptr) return; - if (gc->guild_id != g->guild_id) + if (gc->guild_id != g->guild.guild_id) return; clif_guild_castleinfo(*sd, gc); @@ -3400,7 +3398,7 @@ void clif_parse_guild_castle_info_request(int fd, map_session_data* sd){ void clif_parse_guild_castle_teleport_request(int fd, map_session_data* sd){ #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190522 || PACKETVER_ZERO_NUM >= 20190515 const struct PACKET_CZ_REQ_MOVE_GUILD_AGIT* p = (struct PACKET_CZ_REQ_MOVE_GUILD_AGIT*)RFIFOP(fd, 0); - struct guild* g = sd->guild; + auto &g = sd->guild; if (g == nullptr) return; @@ -3411,7 +3409,7 @@ void clif_parse_guild_castle_teleport_request(int fd, map_session_data* sd){ return; if (!gc->warp_enabled) return; - if (gc->guild_id != g->guild_id) + if (gc->guild_id != g->guild.guild_id) return; if (map_getmapflag(sd->bl.m, MF_GVG_CASTLE) @@ -8780,8 +8778,8 @@ void clif_guild_belonginfo( map_session_data& sd ){ return; } - struct guild& guild = *sd.guild; - int position = guild_getposition( &sd ); + const auto &guild = sd.guild->guild; + int position = guild_getposition(sd); if( position < 0 ){ return; @@ -8810,19 +8808,17 @@ void clif_guild_belonginfo( map_session_data& sd ){ /// status: /// 0 = offline /// 1 = online -void clif_guild_memberlogin_notice(struct guild *g,int idx,int flag) +void clif_guild_memberlogin_notice(const struct mmo_guild &g,int idx,int flag) { unsigned char buf[64]; map_session_data* sd; - nullpo_retv(g); - WBUFW(buf, 0)=0x1f2; - WBUFL(buf, 2)=g->member[idx].account_id; - WBUFL(buf, 6)=g->member[idx].char_id; + WBUFL(buf, 2)=g.member[idx].account_id; + WBUFL(buf, 6)=g.member[idx].char_id; WBUFL(buf,10)=flag; - if( ( sd = g->member[idx].sd ) != NULL ) + if( ( sd = g.member[idx].sd ) != NULL ) { WBUFW(buf,14) = sd->status.sex; WBUFW(buf,16) = sd->status.hair; @@ -8849,7 +8845,6 @@ void clif_guild_memberlogin_notice(struct guild *g,int idx,int flag) // to economize traffic. [LuzZza] void clif_guild_send_onlineinfo(map_session_data *sd) { - struct guild *g; unsigned char buf[14*128]; int i, count=0, p_len; @@ -8857,18 +8852,19 @@ void clif_guild_send_onlineinfo(map_session_data *sd) p_len = packet_len(0x16d); - if(!(g = sd->guild)) + auto &g = sd->guild; + if (!g) return; - for(i=0; imax_member; i++) { + for(i=0; iguild.max_member; i++) { - if(g->member[i].account_id > 0 && - g->member[i].account_id != sd->status.account_id) { + if(g->guild.member[i].account_id > 0 && + g->guild.member[i].account_id != sd->status.account_id) { WBUFW(buf,count*p_len) = 0x16d; - WBUFL(buf,count*p_len+2) = g->member[i].account_id; - WBUFL(buf,count*p_len+6) = g->member[i].char_id; - WBUFL(buf,count*p_len+10) = g->member[i].online; + WBUFL(buf,count*p_len+2) = g->guild.member[i].account_id; + WBUFL(buf,count*p_len+6) = g->guild.member[i].char_id; + WBUFL(buf,count*p_len+10) = g->guild.member[i].online; count++; } } @@ -8910,7 +8906,7 @@ void clif_guild_basicinfo( map_session_data& sd ){ return; } - struct guild& guild = *sd.guild; + const auto &guild = sd.guild->guild; struct PACKET_ZC_GUILD_INFO p = {}; p.PacketType = HEADER_ZC_GUILD_INFO; @@ -8926,7 +8922,7 @@ void clif_guild_basicinfo( map_session_data& sd ){ p.virtue = 0; // Virtue: (down) Wicked [-100,100] Righteous (up) p.emblemVersion = guild.emblem_id; safestrncpy( p.guildname, guild.name, sizeof( p.guildname ) ); - safestrncpy( p.manageLand, msg_txt( &sd, 300 + guild_checkcastles( &guild ) ), sizeof( p.manageLand ) ); + safestrncpy( p.manageLand, msg_txt( &sd, 300 + guild_checkcastles( guild ) ), sizeof( p.manageLand ) ); p.zeny = 0; #if PACKETVER >= 20200902 p.masterGID = guild.member[0].char_id; // leader @@ -8946,17 +8942,17 @@ void clif_guild_basicinfo( map_session_data& sd ){ void clif_guild_allianceinfo(map_session_data *sd) { int fd,i,c; - struct guild *g; nullpo_retv(sd); - if( (g = sd->guild) == NULL ) + auto &g = sd->guild; + if (!g) return; fd = sd->fd; WFIFOHEAD(fd, MAX_GUILDALLIANCE * 32 + 4); WFIFOW(fd, 0)=0x14c; for(i=c=0;ialliance[i]; + struct guild_alliance *a=&g->guild.alliance[i]; if(a->guild_id>0){ WFIFOL(fd,c*32+4)=a->opposition; WFIFOL(fd,c*32+8)=a->guild_id; @@ -8982,14 +8978,14 @@ void clif_guild_memberlist( map_session_data& sd ){ return; } - struct guild& guild = *sd.guild; + const auto &guild = sd.guild->guild; struct PACKET_ZC_MEMBERMGR_INFO* p = (struct PACKET_ZC_MEMBERMGR_INFO*)packet_buffer; p->PacketType = HEADER_ZC_MEMBERMGR_INFO; p->packetLength = sizeof( *p ); for( int i = 0, c = 0; i < guild.max_member; i++ ){ - struct guild_member& member = guild.member[i]; + const auto &member = guild.member[i]; if( member.account_id == 0 ){ continue; @@ -9030,10 +9026,10 @@ void clif_guild_memberlist( map_session_data& sd ){ void clif_guild_positionnamelist(map_session_data *sd) { int i,fd; - struct guild *g; nullpo_retv(sd); - if( (g = sd->guild) == NULL ) + auto &g = sd->guild; + if (!g) return; fd = sd->fd; @@ -9041,7 +9037,7 @@ void clif_guild_positionnamelist(map_session_data *sd) WFIFOW(fd, 0)=0x166; for(i=0;iposition[i].name,NAME_LENGTH); + safestrncpy(WFIFOCP(fd,i*28+8),g->guild.position[i].name,NAME_LENGTH); } WFIFOW(fd,2)=i*28+4; WFIFOSET(fd,WFIFOW(fd,2)); @@ -9058,17 +9054,17 @@ void clif_guild_positionnamelist(map_session_data *sd) void clif_guild_positioninfolist(map_session_data *sd) { int i,fd; - struct guild *g; nullpo_retv(sd); - if( (g = sd->guild) == NULL ) + auto &g = sd->guild; + if (!g) return; fd = sd->fd; WFIFOHEAD(fd, MAX_GUILDPOSITION * 16 + 4); WFIFOW(fd, 0)=0x160; for(i=0;iposition[i]; + struct guild_position *p=&g->guild.position[i]; WFIFOL(fd,i*16+ 4)=i; WFIFOL(fd,i*16+ 8)=p->mode; WFIFOL(fd,i*16+12)=i; @@ -9086,7 +9082,7 @@ void clif_guild_positioninfolist(map_session_data *sd) /// &0x10 = allow expel /// ranking: /// TODO -void clif_guild_positionchanged(struct guild *g,int idx) +void clif_guild_positionchanged(const struct mmo_guild &g,int idx) { // FIXME: This packet is intended to update the clients after a // commit of position info changes, not sending one packet per @@ -9094,16 +9090,14 @@ void clif_guild_positionchanged(struct guild *g,int idx) map_session_data *sd; unsigned char buf[128]; - nullpo_retv(g); - WBUFW(buf, 0)=0x174; WBUFW(buf, 2)=44; // packet len // GUILD_REG_POSITION_INFO{ WBUFL(buf, 4)=idx; - WBUFL(buf, 8)=g->position[idx].mode; + WBUFL(buf, 8)=g.position[idx].mode; WBUFL(buf,12)=idx; - WBUFL(buf,16)=g->position[idx].exp_mode; - safestrncpy(WBUFCP(buf,20),g->position[idx].name,NAME_LENGTH); + WBUFL(buf,16)=g.position[idx].exp_mode; + safestrncpy(WBUFCP(buf,20),g.position[idx].name,NAME_LENGTH); // }* if( (sd=guild_getavailablesd(g))!=NULL ) clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD); @@ -9112,7 +9106,7 @@ void clif_guild_positionchanged(struct guild *g,int idx) /// Notifies clients in a guild about updated member position assignments (ZC_ACK_REQ_CHANGE_MEMBERS). /// 0156 .W { .L .L .L }* -void clif_guild_memberpositionchanged(struct guild *g,int idx) +void clif_guild_memberpositionchanged(const struct mmo_guild &g, int idx) { // FIXME: This packet is intended to update the clients after a // commit of member position assignment changes, not sending one @@ -9120,14 +9114,12 @@ void clif_guild_memberpositionchanged(struct guild *g,int idx) map_session_data *sd; unsigned char buf[64]; - nullpo_retv(g); - WBUFW(buf, 0)=0x156; WBUFW(buf, 2)=16; // packet len // MEMBER_POSITION_INFO{ - WBUFL(buf, 4)=g->member[idx].account_id; - WBUFL(buf, 8)=g->member[idx].char_id; - WBUFL(buf,12)=g->member[idx].position; + WBUFL(buf, 4)=g.member[idx].account_id; + WBUFL(buf, 8)=g.member[idx].char_id; + WBUFL(buf,12)=g.member[idx].position; // }* if( (sd=guild_getavailablesd(g))!=NULL ) clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD); @@ -9136,22 +9128,18 @@ void clif_guild_memberpositionchanged(struct guild *g,int idx) /// Sends emblems bitmap data to the client that requested it (ZC_GUILD_EMBLEM_IMG). /// 0152 .W .L .L .?B -void clif_guild_emblem(map_session_data *sd,struct guild *g) +void clif_guild_emblem(const map_session_data &sd, const struct mmo_guild &g) { - int fd; - nullpo_retv(sd); - nullpo_retv(g); - - fd = sd->fd; - if( g->emblem_len <= 0 ) + int fd = sd.fd; + if( g.emblem_len <= 0 ) return; - WFIFOHEAD(fd,g->emblem_len+12); + WFIFOHEAD(fd,g.emblem_len+12); WFIFOW(fd,0)=0x152; - WFIFOW(fd,2)=g->emblem_len+12; - WFIFOL(fd,4)=g->guild_id; - WFIFOL(fd,8)=g->emblem_id; - memcpy(WFIFOP(fd,12),g->emblem_data,g->emblem_len); + WFIFOW(fd,2)=g.emblem_len+12; + WFIFOL(fd,4)=g.guild_id; + WFIFOL(fd,8)=g.emblem_id; + memcpy(WFIFOP(fd,12),g.emblem_data,g.emblem_len); WFIFOSET(fd,WFIFOW(fd,2)); } @@ -9184,30 +9172,30 @@ void clif_guild_emblem_area(struct block_list* bl) void clif_guild_skillinfo(map_session_data* sd) { int fd; - struct guild* g; int i,c; nullpo_retv(sd); - if( (g = sd->guild) == NULL ) + auto &g = sd->guild; + if (!g) return; fd = sd->fd; WFIFOHEAD(fd, 6 + MAX_GUILDSKILL*37); WFIFOW(fd,0) = 0x0162; - WFIFOW(fd,4) = g->skill_point; + WFIFOW(fd,4) = g->guild.skill_point; for(i = 0, c = 0; i < MAX_GUILDSKILL; i++) { - if(g->skill[i].id > 0 && guild_check_skill_require(g, g->skill[i].id)) + if(g->guild.skill[i].id > 0 && guild_check_skill_require(g->guild, g->guild.skill[i].id)) { - int id = g->skill[i].id; + int id = g->guild.skill[i].id; int p = 6 + c*37; WFIFOW(fd,p+0) = id; WFIFOL(fd,p+2) = skill_get_inf(id); - WFIFOW(fd,p+6) = g->skill[i].lv; - WFIFOW(fd,p+8) = skill_get_sp(id, g->skill[i].lv); - WFIFOW(fd,p+10) = skill_get_range(id, g->skill[i].lv); + WFIFOW(fd,p+6) = g->guild.skill[i].lv; + WFIFOW(fd,p+8) = skill_get_sp(id, g->guild.skill[i].lv); + WFIFOW(fd,p+10) = skill_get_range(id, g->guild.skill[i].lv); safestrncpy(WFIFOCP(fd,p+12), skill_get_name(id), NAME_LENGTH); - WFIFOB(fd,p+36)= (g->skill[i].lv < guild_skill_get_max(id) && sd == g->member[0].sd) ? 1 : 0; + WFIFOB(fd,p+36)= (g->guild.skill[i].lv < guild_skill_get_max(id) && sd == g->guild.member[0].sd) ? 1 : 0; c++; } } @@ -9220,41 +9208,35 @@ void clif_guild_skillinfo(map_session_data* sd) /// 016f .60B .120B void clif_guild_notice(map_session_data* sd) { - struct guild* g; - nullpo_retv(sd); - nullpo_retv(g = sd->guild); + + auto &g = sd->guild; int fd = sd->fd; if ( !session_isActive(fd) ) return; - if(g->mes1[0] == '\0' && g->mes2[0] == '\0') + if(g->guild.mes1[0] == '\0' && g->guild.mes2[0] == '\0') return; WFIFOHEAD(fd,packet_len(0x16f)); WFIFOW(fd,0) = 0x16f; - memcpy(WFIFOP(fd,2), g->mes1, MAX_GUILDMES1); - memcpy(WFIFOP(fd,62), g->mes2, MAX_GUILDMES2); + memcpy(WFIFOP(fd,2), g->guild.mes1, MAX_GUILDMES1); + memcpy(WFIFOP(fd,62), g->guild.mes2, MAX_GUILDMES2); WFIFOSET(fd,packet_len(0x16f)); } /// Guild invite (ZC_REQ_JOIN_GUILD). /// 016a .L .24B -void clif_guild_invite(map_session_data *sd,struct guild *g) +void clif_guild_invite(const map_session_data &sd, const struct mmo_guild &g) { - int fd; - - nullpo_retv(sd); - nullpo_retv(g); - - fd=sd->fd; + int fd = sd.fd; WFIFOHEAD(fd,packet_len(0x16a)); WFIFOW(fd,0)=0x16a; - WFIFOL(fd,2)=g->guild_id; - safestrncpy(WFIFOCP(fd,6),g->name,NAME_LENGTH); + WFIFOL(fd,2)=g.guild_id; + safestrncpy(WFIFOCP(fd,6),g.name,NAME_LENGTH); WFIFOSET(fd,packet_len(0x16a)); } @@ -9330,11 +9312,11 @@ void clif_guild_expulsionlist(map_session_data* sd) const int offset = NAME_LENGTH+40; #endif int fd, i, c = 0; - struct guild* g; nullpo_retv(sd); - if( (g = sd->guild) == NULL ) + auto &g = sd->guild; + if (!g) return; fd = sd->fd; @@ -9344,7 +9326,7 @@ void clif_guild_expulsionlist(map_session_data* sd) for( i = 0; i < MAX_GUILDEXPULSION; i++ ) { - struct guild_expulsion* e = &g->expulsion[i]; + struct guild_expulsion* e = &g->guild.expulsion[i]; if( e->account_id > 0 ) { @@ -9365,7 +9347,7 @@ void clif_guild_expulsionlist(map_session_data* sd) /// Guild chat message (ZC_GUILD_CHAT). /// 017f .W .?B -void clif_guild_message(struct guild *g,uint32 account_id,const char *mes,int len) +void clif_guild_message(const struct mmo_guild &g,uint32 account_id,const char *mes,int len) {// TODO: account_id is not used, candidate for deletion? [Ai4rei] map_session_data *sd; uint8 buf[256]; @@ -9376,7 +9358,7 @@ void clif_guild_message(struct guild *g,uint32 account_id,const char *mes,int le } else if( len > sizeof(buf)-5 ) { - ShowWarning("clif_guild_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", guild_id=%d).\n", mes, len, sizeof(buf)-5, g->guild_id); + ShowWarning("clif_guild_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", guild_id=%d).\n", mes, len, sizeof(buf)-5, g.guild_id); len = sizeof(buf)-5; } @@ -10091,10 +10073,10 @@ void clif_name( struct block_list* src, struct block_list *bl, send_target targe int position; // Will get the position of the guild the player is in - position = guild_getposition( sd ); + position = guild_getposition(*sd); - safestrncpy( packet.guild_name, sd->guild->name, NAME_LENGTH ); - safestrncpy( packet.position_name, sd->guild->position[position].name, NAME_LENGTH ); + safestrncpy( packet.guild_name, sd->guild->guild.name, NAME_LENGTH ); + safestrncpy( packet.position_name, sd->guild->guild.position[position].name, NAME_LENGTH ); }else if( sd->clan ){ safestrncpy( packet.position_name, sd->clan->name, NAME_LENGTH ); } @@ -11210,10 +11192,10 @@ void clif_parse_LoadEndAck(int fd,map_session_data *sd) /* Guild Aura Init */ if( sd->guild && sd->state.gmaster_flag ) { - guild_guildaura_refresh(sd,GD_LEADERSHIP,guild_checkskill(sd->guild,GD_LEADERSHIP)); - guild_guildaura_refresh(sd,GD_GLORYWOUNDS,guild_checkskill(sd->guild,GD_GLORYWOUNDS)); - guild_guildaura_refresh(sd,GD_SOULCOLD,guild_checkskill(sd->guild,GD_SOULCOLD)); - guild_guildaura_refresh(sd,GD_HAWKEYES,guild_checkskill(sd->guild,GD_HAWKEYES)); + guild_guildaura_refresh(sd,GD_LEADERSHIP,guild_checkskill(sd->guild->guild,GD_LEADERSHIP)); + guild_guildaura_refresh(sd,GD_GLORYWOUNDS,guild_checkskill(sd->guild->guild,GD_GLORYWOUNDS)); + guild_guildaura_refresh(sd,GD_SOULCOLD,guild_checkskill(sd->guild->guild,GD_SOULCOLD)); + guild_guildaura_refresh(sd,GD_HAWKEYES,guild_checkskill(sd->guild->guild,GD_HAWKEYES)); } if( sd->state.vending ) { /* show we have a vending */ @@ -13021,8 +13003,8 @@ void clif_parse_skill_toid( map_session_data* sd, uint16 skill_id, uint16 skill_ sd->skillitem = sd->skillitemlv = 0; if( SKILL_CHK_GUILD(skill_id) ) { - if( sd->state.gmaster_flag || skill_id == GD_CHARGESHOUT_BEATING ) - skill_lv = guild_checkskill(sd->guild, skill_id); + if (sd->guild && sd->state.gmaster_flag || skill_id == GD_CHARGESHOUT_BEATING) + skill_lv = guild_checkskill(sd->guild->guild, skill_id); else skill_lv = 0; } else { @@ -14304,7 +14286,7 @@ void clif_parse_GuildChangeMemberPosition( int fd, map_session_data *sd ){ return; } - if( battle_config.guild_leaderchange_delay && DIFF_TICK( time( nullptr ),sd->guild->last_leader_change ) < battle_config.guild_leaderchange_delay ){ + if( battle_config.guild_leaderchange_delay && DIFF_TICK( time( nullptr ),sd->guild->guild.last_leader_change ) < battle_config.guild_leaderchange_delay ){ clif_msg( sd, GUILD_MASTER_DELAY ); return; } @@ -14324,11 +14306,12 @@ void clif_parse_GuildChangeMemberPosition( int fd, map_session_data *sd ){ /// 0151 .L void clif_parse_GuildRequestEmblem(int fd,map_session_data *sd) { - struct guild* g; int guild_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]); - if( (g = guild_search(guild_id)) != NULL ) - clif_guild_emblem(sd,g); + auto g = guild_search(guild_id); + + if (g) + clif_guild_emblem(*sd, g->guild); } @@ -14405,9 +14388,9 @@ void clif_parse_GuildChangeEmblem2(int fd, map_session_data* sd) { #if PACKETVER >= 20190724 const PACKET_CZ_GUILD_EMBLEM_CHANGE2* p = (PACKET_CZ_GUILD_EMBLEM_CHANGE2*)RFIFOP(fd, 0); - guild* g = sd->guild; + auto &g = sd->guild; - if (g == nullptr || g->guild_id != p->guild_id) + if (!g || g->guild.guild_id != p->guild_id) return; if (!sd->state.gmaster_flag) diff --git a/src/map/clif.hpp b/src/map/clif.hpp index 30a4c99c88..1bf10b262a 100644 --- a/src/map/clif.hpp +++ b/src/map/clif.hpp @@ -34,7 +34,7 @@ struct skill_unit; struct s_vending; struct party; struct party_data; -struct guild; +struct mmo_guild; struct s_battleground_data; struct quest; struct party_booking_ad_info; @@ -848,17 +848,17 @@ void clif_guild_allianceinfo(map_session_data *sd); void clif_guild_memberlist( map_session_data& sd ); void clif_guild_skillinfo(map_session_data* sd); void clif_guild_send_onlineinfo(map_session_data *sd); //[LuzZza] -void clif_guild_memberlogin_notice(struct guild *g,int idx,int flag); -void clif_guild_invite(map_session_data *sd,struct guild *g); +void clif_guild_memberlogin_notice(const struct mmo_guild &g,int idx,int flag); +void clif_guild_invite(const map_session_data &sd, const struct mmo_guild &g); void clif_guild_inviteack(map_session_data *sd,int flag); void clif_guild_leave(map_session_data *sd,const char *name,const char *mes); void clif_guild_expulsion(map_session_data* sd, const char* name, const char* mes, uint32 account_id); -void clif_guild_positionchanged(struct guild *g,int idx); -void clif_guild_memberpositionchanged(struct guild *g,int idx); -void clif_guild_emblem(map_session_data *sd,struct guild *g); +void clif_guild_positionchanged(const struct mmo_guild &g,int idx); +void clif_guild_memberpositionchanged(const struct mmo_guild &g,int idx); +void clif_guild_emblem(const map_session_data &sd, const struct mmo_guild &g); void clif_guild_emblem_area(struct block_list* bl); void clif_guild_notice(map_session_data* sd); -void clif_guild_message(struct guild *g,uint32 account_id,const char *mes,int len); +void clif_guild_message(const struct mmo_guild &g,uint32 account_id,const char *mes,int len); void clif_guild_reqalliance(map_session_data *sd,uint32 account_id,const char *name); void clif_guild_allianceack(map_session_data *sd,int flag); void clif_guild_delalliance(map_session_data *sd,int guild_id,int flag); diff --git a/src/map/guild.cpp b/src/map/guild.cpp index cbc45cd64d..373e5c03d5 100644 --- a/src/map/guild.cpp +++ b/src/map/guild.cpp @@ -4,6 +4,7 @@ #include "guild.hpp" #include +#include #include #include @@ -32,7 +33,7 @@ using namespace rathena; -static DBMap* guild_db; // int guild_id -> struct guild* +std::unordered_map> guild_db; CastleDatabase castle_db; static DBMap* guild_expcache_db; // uint32 char_id -> struct guild_expcache* @@ -241,20 +242,16 @@ uint16 guild_skill_get_max( uint16 id ){ } // Retrieve skill_lv learned by guild -int guild_checkskill(struct guild *g, int id) { - if ( g == nullptr || (id = guild_skill_get_index(id)) < 0) +int guild_checkskill(const struct mmo_guild &g, int id) { + if ((id = guild_skill_get_index(id)) < 0) return 0; - return g->skill[id].lv; + return g.skill[id].lv; } /*========================================== * Guild skill check - from jA [Komurka] *------------------------------------------*/ -bool guild_check_skill_require( struct guild *g, uint16 id ){ - if( g == nullptr ){ - return false; - } - +bool guild_check_skill_require(const struct mmo_guild &g, uint16 id ){ std::shared_ptr skill = guild_skill_tree_db.find( id ); if( skill == nullptr ){ @@ -262,7 +259,7 @@ bool guild_check_skill_require( struct guild *g, uint16 id ){ } for( const auto& pair : skill->need ){ - if( pair.second->lv > guild_checkskill( g, pair.second->id ) ){ + if( pair.second->lv > guild_checkskill(g, pair.second->id ) ){ return false; } } @@ -519,23 +516,36 @@ void CastleDatabase::loadingFinished(){ } } -/// lookup: guild id -> guild* -struct guild* guild_search(int guild_id) { - return (struct guild*)idb_get(guild_db,guild_id); +/// lookup: guild id -> guild +std::shared_ptr guild_search(int guild_id) { + return util::umap_find(guild_db, guild_id); } -/// lookup: guild name -> guild* -struct guild* guild_searchname(char* str) { - struct guild* g; - DBIterator *iter = db_iterator(guild_db); - - for( g = (struct guild*)dbi_first(iter); dbi_exists(iter); g = (struct guild*)dbi_next(iter) ) { - if( strcmpi(g->name, str) == 0 ) - break; +/// lookup: guild name -> guild +std::shared_ptr guild_searchname(const char* str) { + if (!str) + return nullptr; + for (const auto &it : guild_db) { + if (it.second && (strcmp(it.second->guild.name, str) == 0)) + return it.second; } - dbi_destroy(iter); - return g; + return nullptr; +} + +/** + * Helper function to find a guild via a string + * The string might be a guild_id, so test names first then id +*/ +std::shared_ptr guild_searchnameid(const char *str) { + if (!str) + return nullptr; + + auto g = guild_searchname(str); + if (g) + return g; + + return guild_search(atoi(str)); } /// lookup: map index -> castle* @@ -562,35 +572,32 @@ std::shared_ptr CastleDatabase::find_by_clientid( uint16 client_id return nullptr; } -map_session_data* guild_getavailablesd(struct guild* g) { +map_session_data* guild_getavailablesd(const struct mmo_guild &g) { int i; - nullpo_retr(NULL, g); - - ARR_FIND( 0, g->max_member, i, g->member[i].sd != NULL ); - return( i < g->max_member ) ? g->member[i].sd : NULL; + ARR_FIND( 0, g.max_member, i, g.member[i].sd != NULL ); + return( i < g.max_member ) ? g.member[i].sd : NULL; } /// lookup: player AID/CID -> member index -int guild_getindex(struct guild *g,uint32 account_id,uint32 char_id) { +int guild_getindex(const struct mmo_guild &g, uint32 account_id, uint32 char_id) { int i; - if( g == NULL ) - return -1; - - ARR_FIND( 0, g->max_member, i, g->member[i].account_id == account_id && g->member[i].char_id == char_id ); - return( i < g->max_member ) ? i : -1; + ARR_FIND( 0, g.max_member, i, g.member[i].account_id == account_id && g.member[i].char_id == char_id ); + return( i < g.max_member ) ? i : -1; } /// lookup: player sd -> member position -int guild_getposition(map_session_data* sd) { +int guild_getposition(const map_session_data& sd) { int i; - struct guild *g; - nullpo_retr( -1, g = sd->guild ); + if (!sd.guild) + return -1; + + const auto &g = sd.guild->guild; - ARR_FIND( 0, g->max_member, i, g->member[i].account_id == sd->status.account_id && g->member[i].char_id == sd->status.char_id ); - return( i < g->max_member ) ? g->member[i].position : -1; + ARR_FIND( 0, g.max_member, i, g.member[i].account_id == sd.status.account_id && g.member[i].char_id == sd.status.char_id ); + return( i < g.max_member ) ? g.member[i].position : -1; } //Creation of member information @@ -619,22 +626,20 @@ void guild_makemember(struct guild_member *m,map_session_data *sd) { int guild_payexp_timer_sub(DBKey key, DBData *data, va_list ap) { int i; struct guild_expcache *c; - struct guild *g; c = (struct guild_expcache *)db_data2ptr(data); - if ( - (g = guild_search(c->guild_id)) == NULL || - (i = guild_getindex(g, c->account_id, c->char_id)) < 0 - ) { + auto g = guild_search(c->guild_id); + + if (!g || (i = guild_getindex(g->guild, c->account_id, c->char_id)) < 0) { ers_free(expcache_ers, c); return 0; } - g->member[i].exp = util::safe_addition_cap(g->member[i].exp, c->exp, MAX_GUILD_EXP); + g->guild.member[i].exp = util::safe_addition_cap(g->guild.member[i].exp, c->exp, MAX_GUILD_EXP); - intif_guild_change_memberinfo(g->guild_id,c->account_id,c->char_id, - GMI_EXP,&g->member[i].exp,sizeof(g->member[i].exp)); + intif_guild_change_memberinfo(g->guild.guild_id,c->account_id,c->char_id, + GMI_EXP,&g->guild.member[i].exp,sizeof(g->guild.member[i].exp)); c->exp=0; ers_free(expcache_ers, c); @@ -647,22 +652,17 @@ TIMER_FUNC(guild_payexp_timer){ } /** - * Taken from party_send_xy_timer_sub. [Skotlex] - * @see DBApply + * Send xy coords to a guild + * @param g Reference to a guild */ -int guild_send_xy_timer_sub(DBKey key, DBData *data, va_list ap) { - struct guild *g = (struct guild *)db_data2ptr(data); - int i; - - nullpo_ret(g); - - if( !g->connect_member ) { +int guild_send_xy_timer_sub(const struct mmo_guild& g) { + if (g.connect_member <= 0) { // no members connected to this guild so do not iterate return 0; } - for(i=0;imax_member;i++){ - map_session_data* sd = g->member[i].sd; + for (int i = 0; i < g.max_member; i++) { + map_session_data* sd = g.member[i].sd; if( sd != NULL && sd->fd && (sd->guild_x != sd->bl.x || sd->guild_y != sd->bl.y) && !sd->bg_id ) { clif_guild_xy(sd); sd->guild_x = sd->bl.x; @@ -674,7 +674,10 @@ int guild_send_xy_timer_sub(DBKey key, DBData *data, va_list ap) { //Code from party_send_xy_timer [Skotlex] static TIMER_FUNC(guild_send_xy_timer){ - guild_db->foreach(guild_db,guild_send_xy_timer_sub,tick); + for (const auto &it : guild_db) { + if (it.second) + guild_send_xy_timer_sub(it.second->guild); + } return 0; } @@ -777,16 +780,14 @@ static void guild_trade_bound_cancel(map_session_data *sd) { } //Confirmation of the character belongs to guild -int guild_check_member(struct guild *g) { +int guild_check_member(const struct mmo_guild &g) { int i; map_session_data *sd; struct s_mapiterator* iter; - nullpo_ret(g); - iter = mapit_getallusers(); for( sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); sd = (TBL_PC*)mapit_next(iter) ) { - if( sd->status.guild_id != g->guild_id ) + if( sd->status.guild_id != g.guild_id ) continue; i = guild_getindex(g,sd->status.account_id,sd->status.char_id); @@ -818,23 +819,23 @@ int guild_recv_noinfo(int guild_id) { } //Get and display information for all member -int guild_recv_info(struct guild *sg) { - struct guild *g,before; +int guild_recv_info(const struct mmo_guild &sg) { + struct mmo_guild before; int i,bm,m; DBData data; map_session_data *sd; bool guild_new = false; - nullpo_ret(sg); + auto g = guild_search(sg.guild_id); - if((g = guild_search(sg->guild_id))==NULL) { + if (!g) { + g = std::make_shared(); guild_new = true; - g=(struct guild *)aCalloc(1,sizeof(struct guild)); - idb_put(guild_db,sg->guild_id,g); - before=*sg; + guild_db.insert({sg.guild_id, g}); + before = sg; //Perform the check on the user because the first load guild_check_member(sg); - if ((sd = map_nick2sd(sg->master,false)) != NULL) { + if ((sd = map_nick2sd(sg.master,false)) != NULL) { #ifndef RENEWAL //If the guild master is online the first time the guild_info is received, //that means he was the first to join, so apply guild skill blocking here. @@ -849,33 +850,28 @@ int guild_recv_info(struct guild *sg) { clif_guild_masterormember(sd); } } else { - before=*g; + before = g->guild; } - memcpy(g,sg,sizeof(struct guild)); + memcpy(&g->guild, &sg, sizeof(struct mmo_guild)); - if(g->max_member > MAX_GUILD) { - ShowError("guild_recv_info: Received guild with %d members, but MAX_GUILD is only %d. Extra guild-members have been lost!\n", g->max_member, MAX_GUILD); - g->max_member = MAX_GUILD; + if(g->guild.max_member > MAX_GUILD) { + ShowError("guild_recv_info: Received guild with %d members, but MAX_GUILD is only %d. Extra guild-members have been lost!\n", g->guild.max_member, MAX_GUILD); + g->guild.max_member = MAX_GUILD; } - for(i=bm=m=0;imax_member;i++){ - if(g->member[i].account_id>0){ - sd = g->member[i].sd = guild_sd_check(g->guild_id, g->member[i].account_id, g->member[i].char_id); + for(i=bm=m=0;iguild.max_member;i++){ + if(g->guild.member[i].account_id>0){ + sd = g->guild.member[i].sd = guild_sd_check(g->guild.guild_id, g->guild.member[i].account_id, g->guild.member[i].char_id); if (sd) clif_name_area(&sd->bl); // [LuzZza] m++; }else - g->member[i].sd=NULL; + g->guild.member[i].sd=NULL; if(before.member[i].account_id>0) bm++; } - // Restore the instance id - if( !guild_new && before.instance_id ){ - g->instance_id = before.instance_id; - } - - for (i = 0; i < g->max_member; i++) { //Transmission of information at all members - sd = g->member[i].sd; + for (i = 0; i < g->guild.max_member; i++) { //Transmission of information at all members + sd = g->guild.member[i].sd; if( sd==NULL ) continue; sd->guild = g; @@ -883,30 +879,30 @@ int guild_recv_info(struct guild *sg) { channel_gjoin(sd,3); //make all member join guildchan+allieschan } - if (before.guild_lv != g->guild_lv || bm != m || - before.max_member != g->max_member) { + if (before.guild_lv != g->guild.guild_lv || bm != m || + before.max_member != g->guild.max_member) { clif_guild_basicinfo( *sd ); //Submit basic information - clif_guild_emblem(sd, g); //Submit emblem + clif_guild_emblem(*sd, g->guild); //Submit emblem } if (bm != m) { //Send members information clif_guild_memberlist( *sd ); } - if (before.skill_point != g->skill_point) + if (before.skill_point != g->guild.skill_point) clif_guild_skillinfo(sd); //Submit information skills if (guild_new) { // Send information and affiliation if unsent clif_guild_belonginfo( *sd ); clif_guild_notice(sd); - sd->guild_emblem_id = g->emblem_id; + sd->guild_emblem_id = g->guild.emblem_id; } if (g->instance_id > 0) instance_reqinfo(sd, g->instance_id); } //Occurrence of an event - if (guild_infoevent_db->remove(guild_infoevent_db, db_i2key(sg->guild_id), &data)) { + if (guild_infoevent_db->remove(guild_infoevent_db, db_i2key(sg.guild_id), &data)) { struct eventlist *ev = (struct eventlist *)db_data2ptr(&data), *ev2; while(ev) { npc_event_do(ev->name); @@ -923,17 +919,16 @@ int guild_recv_info(struct guild *sg) { * Player sd send a guild invatation to player tsd to join his guild *--------------------------------------------*/ int guild_invite(map_session_data *sd, map_session_data *tsd) { - struct guild *g; int i; nullpo_ret(sd); - g=sd->guild; + auto &g = sd->guild; if(tsd==NULL || g==NULL) return 0; - if( (i=guild_getposition(sd))<0 || !(g->position[i].mode&GUILD_PERM_INVITE) ) + if( (i=guild_getposition(*sd))<0 || !(g->guild.position[i].mode&GUILD_PERM_INVITE) ) return 0; //Invite permission. if(!battle_config.invite_request_check) { @@ -957,8 +952,8 @@ int guild_invite(map_session_data *sd, map_session_data *tsd) { } //search an empty spot in guild - ARR_FIND( 0, g->max_member, i, g->member[i].account_id == 0 ); - if(i==g->max_member){ + ARR_FIND( 0, g->guild.max_member, i, g->guild.member[i].account_id == 0 ); + if(i==g->guild.max_member){ clif_guild_inviteack(sd,3); return 0; } @@ -966,7 +961,7 @@ int guild_invite(map_session_data *sd, map_session_data *tsd) { tsd->guild_invite=sd->status.guild_id; tsd->guild_invite_account=sd->status.account_id; - clif_guild_invite(tsd,g); + clif_guild_invite(*tsd, g->guild); return 0; } @@ -996,17 +991,17 @@ int guild_reply_invite(map_session_data* sd, int guild_id, int flag) { if( tsd ) clif_guild_inviteack(tsd,1); } else {// accepted struct guild_member m; - struct guild* g; + auto g = guild_search(guild_id); int i; - if( (g=guild_search(guild_id)) == NULL ) { + if (!g) { sd->guild_invite = 0; sd->guild_invite_account = 0; return 0; } - ARR_FIND( 0, g->max_member, i, g->member[i].account_id == 0 ); - if( i == g->max_member ) { + ARR_FIND( 0, g->guild.max_member, i, g->guild.member[i].account_id == 0 ); + if( i == g->guild.max_member ) { sd->guild_invite = 0; sd->guild_invite_account = 0; if( tsd ) clif_guild_inviteack(tsd,3); @@ -1026,14 +1021,13 @@ int guild_reply_invite(map_session_data* sd, int guild_id, int flag) { //- Otherwise sd pointer is set up. //- Player must be authed and must belong to a guild before invoking this method void guild_member_joined(map_session_data *sd) { - struct guild* g; int i; - g=guild_search(sd->status.guild_id); + auto g = guild_search(sd->status.guild_id); if (!g) { guild_request_info(sd->status.guild_id); return; } - if (strcmp(sd->status.name,g->master) == 0) { // set the Guild Master flag + if (strcmp(sd->status.name,g->guild.master) == 0) { // set the Guild Master flag sd->state.gmaster_flag = 1; #ifndef RENEWAL // prevent Guild Skills from being used directly after relog @@ -1041,11 +1035,11 @@ void guild_member_joined(map_session_data *sd) { guild_block_skill(sd, battle_config.guild_skill_relog_delay); #endif } - i = guild_getindex(g, sd->status.account_id, sd->status.char_id); + i = guild_getindex(g->guild, sd->status.account_id, sd->status.char_id); if (i == -1) sd->status.guild_id = 0; else { - g->member[i].sd = sd; + g->guild.member[i].sd = sd; sd->guild = g; if( channel_config.ally_tmpl.name[0] && (channel_config.ally_tmpl.opt&CHAN_OPT_AUTOJOIN) ) { @@ -1059,9 +1053,9 @@ void guild_member_joined(map_session_data *sd) { *----------------------------------------*/ int guild_member_added(int guild_id,uint32 account_id,uint32 char_id,int flag) { map_session_data *sd= map_id2sd(account_id),*sd2; - struct guild *g; + auto g = guild_search(guild_id); - if( (g=guild_search(guild_id))==NULL ) + if (!g) return 0; if(sd==NULL || sd->guild_invite==0){ @@ -1083,8 +1077,8 @@ int guild_member_added(int guild_id,uint32 account_id,uint32 char_id,int flag) { } //if all ok add player to guild - sd->status.guild_id = g->guild_id; - sd->guild_emblem_id = g->emblem_id; + sd->status.guild_id = g->guild.guild_id; + sd->guild_emblem_id = g->guild.emblem_id; sd->guild = g; //Packets which were sent in the previous 'guild_sent' implementation. clif_guild_belonginfo( *sd ); @@ -1108,13 +1102,9 @@ int guild_member_added(int guild_id,uint32 account_id,uint32 char_id,int flag) { * Player request leaving a given guild_id *----------------------------------------*/ int guild_leave(map_session_data* sd, int guild_id, uint32 account_id, uint32 char_id, const char* mes) { - struct guild *g; - nullpo_ret(sd); - g = sd->guild; - - if(g==NULL) + if (!sd->guild) return 0; if(sd->status.account_id!=account_id || @@ -1132,20 +1122,19 @@ int guild_leave(map_session_data* sd, int guild_id, uint32 account_id, uint32 ch *----------------------------------------*/ int guild_expulsion(map_session_data* sd, int guild_id, uint32 account_id, uint32 char_id, const char* mes) { map_session_data *tsd; - struct guild *g; int i,ps; nullpo_ret(sd); - g = sd->guild; + auto &g = sd->guild; - if(g==NULL) + if (!g) return 0; if(sd->status.guild_id!=guild_id) return 0; - if( (ps=guild_getposition(sd))<0 || !(g->position[ps].mode&GUILD_PERM_EXPEL) ) + if( (ps=guild_getposition(*sd))<0 || !(g->guild.position[ps].mode&GUILD_PERM_EXPEL) ) return 0; //Expulsion permission //Can't leave inside guild castles. @@ -1155,11 +1144,11 @@ int guild_expulsion(map_session_data* sd, int guild_id, uint32 account_id, uint3 return 0; // find the member and perform expulsion - i = guild_getindex(g, account_id, char_id); - if( i != -1 && strcmp(g->member[i].name,g->master) != 0 ) { //Can't expel the GL! + i = guild_getindex(g->guild, account_id, char_id); + if( i != -1 && strcmp(g->guild.member[i].name,g->guild.master) != 0 ) { //Can't expel the GL! if (tsd) guild_trade_bound_cancel(tsd); - intif_guild_leave(g->guild_id,account_id,char_id,1,mes); + intif_guild_leave(g->guild.guild_id,account_id,char_id,1,mes); } return 0; @@ -1176,14 +1165,14 @@ int guild_expulsion(map_session_data* sd, int guild_id, uint32 account_id, uint3 */ int guild_member_withdraw(int guild_id, uint32 account_id, uint32 char_id, int flag, const char* name, const char* mes) { int i; - struct guild* g = guild_search(guild_id); + auto g = guild_search(guild_id); map_session_data* sd = map_charid2sd(char_id); map_session_data* online_member_sd; - if(g == NULL) + if (!g) return 0; // no such guild (error!) - i = guild_getindex(g, account_id, char_id); + i = guild_getindex(g->guild, account_id, char_id); if( i == -1 ) return 0; // not a member (inconsistency!) @@ -1192,7 +1181,7 @@ int guild_member_withdraw(int guild_id, uint32 account_id, uint32 char_id, int f guild_retrieveitembound(char_id,account_id,guild_id); #endif - online_member_sd = guild_getavailablesd(g); + online_member_sd = guild_getavailablesd(g->guild); if(online_member_sd == NULL) return 0; // noone online to inform @@ -1203,7 +1192,7 @@ int guild_member_withdraw(int guild_id, uint32 account_id, uint32 char_id, int f clif_guild_expulsion(online_member_sd, name, mes, account_id); // remove member from guild - memset(&g->member[i],0,sizeof(struct guild_member)); + memset(&g->guild.member[i],0,sizeof(struct guild_member)); clif_guild_memberlist( *online_member_sd ); // update char, if online @@ -1252,11 +1241,11 @@ void guild_retrieveitembound(uint32 char_id, uint32 account_id, int guild_id) { j = pc_bound_chk(sd,BOUND_GUILD,idxlist); if (j) { struct s_storage* stor = guild2storage(sd->status.guild_id); - struct guild *g = guild_search(guild_id); + auto g = guild_search(guild_id); int i; if (stor && stor->status) { //Someone is in guild storage, close them - for (i = 0; i < g->max_member; i++) { - TBL_PC *pl_sd = g->member[i].sd; + for (i = 0; i < g->guild.max_member; i++) { + TBL_PC *pl_sd = g->guild.member[i].sd; if (pl_sd && pl_sd->state.storage_flag == 2) storage_guild_storageclose(pl_sd); } @@ -1270,12 +1259,13 @@ void guild_retrieveitembound(uint32 char_id, uint32 account_id, int guild_id) { } } else { //Character is offline, ask char server to do the job struct s_storage* stor = guild2storage2(guild_id); - struct guild *g = guild_search(guild_id); - nullpo_retv(g); + auto g = guild_search(guild_id); + if (!g) + return; if (stor && stor->status) { //Someone is in guild storage, close them int i; - for (i = 0; i < g->max_member; i++) { - TBL_PC *pl_sd = g->member[i].sd; + for (i = 0; i < g->guild.max_member; i++) { + TBL_PC *pl_sd = g->guild.member[i].sd; if (pl_sd && pl_sd->state.storage_flag == 2) storage_guild_storageclose(pl_sd); } @@ -1286,31 +1276,31 @@ void guild_retrieveitembound(uint32 char_id, uint32 account_id, int guild_id) { #endif int guild_send_memberinfoshort(map_session_data *sd,int online) { // cleaned up [LuzZza] - struct guild *g; - nullpo_ret(sd); if(sd->status.guild_id <= 0) return 0; - if(!(g = sd->guild)) + auto &g = sd->guild; + + if (!g) return 0; - intif_guild_memberinfoshort(g->guild_id, + intif_guild_memberinfoshort(g->guild.guild_id, sd->status.account_id,sd->status.char_id,online,sd->status.base_level,sd->status.class_); if(!online){ - int i=guild_getindex(g,sd->status.account_id,sd->status.char_id); + int i=guild_getindex(g->guild, sd->status.account_id,sd->status.char_id); if(i>=0) - g->member[i].sd=NULL; + g->guild.member[i].sd=NULL; else - ShowError("guild_send_memberinfoshort: Failed to locate member %d:%d in guild %d!\n", sd->status.account_id, sd->status.char_id, g->guild_id); + ShowError("guild_send_memberinfoshort: Failed to locate member %d:%d in guild %d!\n", sd->status.account_id, sd->status.char_id, g->guild.guild_id); return 0; } if(sd->state.connect_new) { //Note that this works because it is invoked in parse_LoadEndAck before connect_new is cleared. clif_guild_belonginfo( *sd ); - sd->guild_emblem_id = g->emblem_id; + sd->guild_emblem_id = g->guild.emblem_id; } return 0; } @@ -1318,13 +1308,13 @@ int guild_send_memberinfoshort(map_session_data *sd,int online) { // cleaned up int guild_recv_memberinfoshort(int guild_id,uint32 account_id,uint32 char_id,int online,int lv,int class_) { // cleaned up [LuzZza] int i,alv,c,idx=-1,om=0,oldonline=-1; - struct guild *g = guild_search(guild_id); + auto g = guild_search(guild_id); if(g == NULL) return 0; - for(i=0,alv=0,c=0,om=0;imax_member;i++){ - struct guild_member *m=&g->member[i]; + for(i=0,alv=0,c=0,om=0;iguild.max_member;i++){ + struct guild_member *m=&g->guild.member[i]; if(!m->account_id) continue; if(m->account_id==account_id && m->char_id==char_id ){ oldonline=m->online; @@ -1346,32 +1336,32 @@ int guild_recv_memberinfoshort(int guild_id,uint32 account_id,uint32 char_id,int sd->status.guild_id=0; sd->guild_emblem_id=0; } - ShowWarning("guild: not found member %d,%d on %d[%s]\n", account_id,char_id,guild_id,g->name); + ShowWarning("guild: not found member %d,%d on %d[%s]\n", account_id,char_id,guild_id,g->guild.name); return 0; } - g->average_lv=alv/c; - g->connect_member=om; + g->guild.average_lv=alv/c; + g->guild.connect_member=om; //Ensure validity of pointer (ie: player logs in/out, changes map-server) - g->member[idx].sd = guild_sd_check(guild_id, account_id, char_id); + g->guild.member[idx].sd = guild_sd_check(guild_id, account_id, char_id); if(oldonline!=online) - clif_guild_memberlogin_notice(g, idx, online); + clif_guild_memberlogin_notice(g->guild, idx, online); - if(!g->member[idx].sd) + if(!g->guild.member[idx].sd) return 0; //Send XY dot updates. [Skotlex] //Moved from guild_send_memberinfoshort [LuzZza] - for(i=0; i < g->max_member; i++) { + for(i=0; i < g->guild.max_member; i++) { - if(!g->member[i].sd || i == idx || - g->member[i].sd->bl.m != g->member[idx].sd->bl.m) + if(!g->guild.member[i].sd || i == idx || + g->guild.member[i].sd->bl.m != g->guild.member[idx].sd->bl.m) continue; - clif_guild_xy_single(g->member[idx].sd->fd, g->member[i].sd); - clif_guild_xy_single(g->member[i].sd->fd, g->member[idx].sd); + clif_guild_xy_single(g->guild.member[idx].sd->fd, g->guild.member[i].sd); + clif_guild_xy_single(g->guild.member[i].sd->fd, g->guild.member[idx].sd); } return 0; @@ -1398,10 +1388,10 @@ int guild_send_message(map_session_data *sd,const char *mes,int len) { * Guild receive a message, will be displayed to whole member *---------------------------------------------------*/ int guild_recv_message(int guild_id,uint32 account_id,const char *mes,int len) { - struct guild *g; - if( (g=guild_search(guild_id))==NULL) + auto g = guild_search(guild_id); + if (!g) return 0; - clif_guild_message(g,account_id,mes,len); + clif_guild_message(g->guild,account_id,mes,len); return 0; } @@ -1415,15 +1405,14 @@ int guild_change_memberposition(int guild_id,uint32 account_id,uint32 char_id,sh /*==================================================== * Notification of new position for member *---------------------------------------------------*/ -int guild_memberposition_changed(struct guild *g,int idx,int pos) { - nullpo_ret(g); +int guild_memberposition_changed(struct mmo_guild &g,int idx,int pos) { - g->member[idx].position=pos; + g.member[idx].position=pos; clif_guild_memberpositionchanged(g,idx); // Update char position in client [LuzZza] - if(g->member[idx].sd != NULL) - clif_name_area(&g->member[idx].sd->bl); + if(g.member[idx].sd != NULL) + clif_name_area(&g.member[idx].sd->bl); return 0; } @@ -1444,17 +1433,17 @@ int guild_change_position(int guild_id,int idx, int mode, int exp_mode, const ch * Notification of member has changed his guild title *---------------------------------------------------*/ int guild_position_changed(int guild_id,int idx,struct guild_position *p) { - struct guild *g=guild_search(guild_id); + auto g = guild_search(guild_id); int i; if(g==NULL) return 0; - memcpy(&g->position[idx],p,sizeof(struct guild_position)); - clif_guild_positionchanged(g,idx); + memcpy(&g->guild.position[idx],p,sizeof(struct guild_position)); + clif_guild_positionchanged(g->guild,idx); // Update char name in client [LuzZza] - for(i=0;imax_member;i++) - if(g->member[i].position == idx && g->member[i].sd != NULL) - clif_name_area(&g->member[i].sd->bl); + for(i=0;iguild.max_member;i++) + if(g->guild.member[i].position == idx && g->guild.member[i].sd != NULL) + clif_name_area(&g->guild.member[i].sd->bl); return 0; } @@ -1474,15 +1463,15 @@ int guild_change_notice(map_session_data *sd,int guild_id,const char *mes1,const *---------------------------------------------------*/ int guild_notice_changed(int guild_id,const char *mes1,const char *mes2) { int i; - struct guild *g=guild_search(guild_id); - if(g==NULL) + auto g = guild_search(guild_id); + if (!g) return 0; - memcpy(g->mes1,mes1,MAX_GUILDMES1); - memcpy(g->mes2,mes2,MAX_GUILDMES2); + memcpy(g->guild.mes1,mes1,MAX_GUILDMES1); + memcpy(g->guild.mes2,mes2,MAX_GUILDMES2); - for(i=0;imax_member;i++){ - map_session_data *sd = g->member[i].sd; + for(i=0;iguild.max_member;i++){ + map_session_data *sd = g->guild.member[i].sd; if(sd != NULL) clif_guild_notice(sd); } @@ -1495,9 +1484,9 @@ int guild_notice_changed(int guild_id,const char *mes1,const char *mes2) { bool guild_check_emblem_change_condition(map_session_data *sd) { nullpo_ret(sd); - guild* g = sd->guild; + auto &g = sd->guild; - if (battle_config.require_glory_guild && g != nullptr && guild_checkskill(g, GD_GLORYGUILD) > 0) { + if (battle_config.require_glory_guild && g != nullptr && guild_checkskill(g->guild, GD_GLORYGUILD) > 0) { clif_skill_fail(sd, GD_GLORYGUILD, USESKILL_FAIL_LEVEL, 0); return false; } @@ -1538,20 +1527,20 @@ int guild_change_emblem_version(map_session_data* sd, int version) int guild_emblem_changed(int len,int guild_id,int emblem_id,const char *data) { int i; map_session_data *sd; - struct guild *g=guild_search(guild_id); - if(g==NULL) + auto g = guild_search(guild_id); + if (!g) return 0; if (data != nullptr) - memcpy(g->emblem_data,data,len); - g->emblem_len=len; - g->emblem_id=emblem_id; + memcpy(g->guild.emblem_data,data,len); + g->guild.emblem_len=len; + g->guild.emblem_id=emblem_id; - for(i=0;imax_member;i++){ - if((sd=g->member[i].sd)!=NULL){ + for(i=0;iguild.max_member;i++){ + if((sd=g->guild.member[i].sd)!=NULL){ sd->guild_emblem_id=emblem_id; clif_guild_belonginfo( *sd ); - clif_guild_emblem(sd,g); + clif_guild_emblem(*sd, g->guild); clif_guild_emblem_area(&sd->bl); } } @@ -1608,7 +1597,6 @@ static DBData create_expcache(DBKey key, va_list args) { * Return taxed experience from player sd to guild *---------------------------------------------------*/ t_exp guild_payexp(map_session_data *sd,t_exp exp) { - struct guild *g; struct guild_expcache *c; int per; @@ -1616,10 +1604,11 @@ t_exp guild_payexp(map_session_data *sd,t_exp exp) { if (!exp) return 0; - if (sd->status.guild_id == 0 || - (g = sd->guild) == NULL || - (per = guild_getposition(sd)) < 0 || - (per = g->position[per].exp_mode) < 1) + auto &g = sd->guild; + + if (sd->status.guild_id == 0 || !g || + (per = guild_getposition(*sd)) < 0 || + (per = g->guild.position[per].exp_mode) < 1) return 0; @@ -1655,7 +1644,6 @@ t_exp guild_getexp(map_session_data *sd,t_exp exp) { * Ask to increase guildskill skill_id *---------------------------------------------------*/ void guild_skillup(map_session_data* sd, uint16 skill_id) { - struct guild* g; short idx = guild_skill_get_index(skill_id); short max = 0; @@ -1664,16 +1652,18 @@ void guild_skillup(map_session_data* sd, uint16 skill_id) { if (idx == -1) return; - if( sd->status.guild_id == 0 || (g=sd->guild) == NULL || // no guild - strcmp(sd->status.name, g->master) ) // not the guild master + auto &g = sd->guild; + + if( sd->status.guild_id == 0 || !g || // no guild + strcmp(sd->status.name, g->guild.master) ) // not the guild master return; max = guild_skill_get_max(skill_id); - if( g->skill_point > 0 && - g->skill[idx].id != 0 && - g->skill[idx].lv < max ) - intif_guild_skillup(g->guild_id, skill_id, sd->status.account_id, max); + if( g->guild.skill_point > 0 && + g->guild.skill[idx].id != 0 && + g->guild.skill[idx].lv < max ) + intif_guild_skillup(g->guild.guild_id, skill_id, sd->status.account_id, max); } /*==================================================== @@ -1681,14 +1671,14 @@ void guild_skillup(map_session_data* sd, uint16 skill_id) { *---------------------------------------------------*/ int guild_skillupack(int guild_id,uint16 skill_id,uint32 account_id) { map_session_data *sd = map_id2sd(account_id); - struct guild *g = guild_search(guild_id); + auto g = guild_search(guild_id); int i; short idx = guild_skill_get_index(skill_id); if (g == NULL || idx == -1) return 0; if (sd != NULL) { - int lv = g->skill[idx].lv; + int lv = g->guild.skill[idx].lv; int range = skill_get_range(skill_id, lv); clif_skillup(sd,skill_id,lv,range,1); @@ -1698,14 +1688,14 @@ int guild_skillupack(int guild_id,uint16 skill_id,uint32 account_id) { case GD_GLORYWOUNDS: case GD_SOULCOLD: case GD_HAWKEYES: - guild_guildaura_refresh(sd,skill_id,g->skill[idx].lv); + guild_guildaura_refresh(sd,skill_id,g->guild.skill[idx].lv); break; } } // Inform all members - for (i = 0; i < g->max_member; i++) - if ((sd = g->member[i].sd) != NULL) + for (i = 0; i < g->guild.max_member; i++) + if ((sd = g->guild.member[i].sd) != NULL) clif_guild_skillinfo(sd); return 0; @@ -1738,14 +1728,12 @@ void guild_guildaura_refresh(map_session_data *sd, uint16 skill_id, uint16 skill * 0 = allied * 1 = enemy *---------------------------------------------------*/ -int guild_get_alliance_count(struct guild *g,int flag) { +int guild_get_alliance_count(const struct mmo_guild &g,int flag) { int i,c; - nullpo_ret(g); - for(i=c=0;ialliance[i].guild_id>0 && - g->alliance[i].opposition==flag ) + if( g.alliance[i].guild_id>0 && + g.alliance[i].opposition==flag ) c++; } return c; @@ -1767,14 +1755,13 @@ void guild_block_skill(map_session_data *sd, int time) { * Returns true if yes. *---------------------------------------------------*/ int guild_check_alliance(int guild_id1, int guild_id2, int flag) { - struct guild *g; int i; - g = guild_search(guild_id1); + auto g = guild_search(guild_id1); if (g == NULL) return 0; - ARR_FIND( 0, MAX_GUILDALLIANCE, i, g->alliance[i].guild_id == guild_id2 && g->alliance[i].opposition == flag ); + ARR_FIND( 0, MAX_GUILDALLIANCE, i, g->guild.alliance[i].guild_id == guild_id2 && g->guild.alliance[i].opposition == flag ); return( i < MAX_GUILDALLIANCE ) ? 1 : 0; } @@ -1782,7 +1769,6 @@ int guild_check_alliance(int guild_id1, int guild_id2, int flag) { * Player sd, asking player tsd an alliance between their 2 guilds *---------------------------------------------------*/ int guild_reqalliance(map_session_data *sd,map_session_data *tsd) { - struct guild *g[2]; int i; if(is_agit_start()) { // Disable alliance creation during woe [Valaris] @@ -1802,21 +1788,21 @@ int guild_reqalliance(map_session_data *sd,map_session_data *tsd) { return 0; } - g[0]=sd->guild; - g[1]=tsd->guild; + auto &g = sd->guild; + auto &tg = tsd->guild; - if(g[0]==NULL || g[1]==NULL) + if(g==NULL || tg==NULL) return 0; // Prevent creation alliance with same guilds [LuzZza] if(sd->status.guild_id == tsd->status.guild_id) return 0; - if( guild_get_alliance_count(g[0],0) >= battle_config.max_guild_alliance ) { + if( guild_get_alliance_count(g->guild,0) >= battle_config.max_guild_alliance ) { clif_guild_allianceack(sd,4); return 0; } - if( guild_get_alliance_count(g[1],0) >= battle_config.max_guild_alliance ) { + if( guild_get_alliance_count(tg->guild,0) >= battle_config.max_guild_alliance ) { clif_guild_allianceack(sd,3); return 0; } @@ -1826,9 +1812,9 @@ int guild_reqalliance(map_session_data *sd,map_session_data *tsd) { return 0; } - for (i = 0; i < MAX_GUILDALLIANCE; i++) { // check if already allied - if( g[0]->alliance[i].guild_id==tsd->status.guild_id && - g[0]->alliance[i].opposition==0){ + for (i = 0; i < MAX_GUILDALLIANCE; i++) { // check if already allied + if( g->guild.alliance[i].guild_id==tsd->status.guild_id && + g->guild.alliance[i].opposition==0){ clif_guild_allianceack(sd,0); return 0; } @@ -1837,7 +1823,7 @@ int guild_reqalliance(map_session_data *sd,map_session_data *tsd) { tsd->guild_alliance=sd->status.guild_id; tsd->guild_alliance_account=sd->status.account_id; - clif_guild_reqalliance(tsd,sd->status.account_id,g[0]->name); + clif_guild_reqalliance(tsd,sd->status.account_id,g->guild.name); return 0; } @@ -1860,30 +1846,29 @@ int guild_reply_reqalliance(map_session_data *sd,uint32 account_id,int flag) { if (flag == 1) { // consent int i; - struct guild *g, *tg; // Reconfirm the number of alliance - g=sd->guild; - tg=tsd->guild; + auto &g = sd->guild; + auto &tg = tsd->guild; - if(g==NULL || guild_get_alliance_count(g,0) >= battle_config.max_guild_alliance){ + if (!g || guild_get_alliance_count(g->guild,0) >= battle_config.max_guild_alliance) { clif_guild_allianceack(sd,4); clif_guild_allianceack(tsd,3); return 0; } - if(tg==NULL || guild_get_alliance_count(tg,0) >= battle_config.max_guild_alliance){ + if (!g || guild_get_alliance_count(tg->guild,0) >= battle_config.max_guild_alliance) { clif_guild_allianceack(sd,3); clif_guild_allianceack(tsd,4); return 0; } for(i=0;ialliance[i].guild_id==tsd->status.guild_id && - g->alliance[i].opposition==1) + if(g->guild.alliance[i].guild_id==tsd->status.guild_id && + g->guild.alliance[i].opposition==1) intif_guild_alliance( sd->status.guild_id,tsd->status.guild_id, sd->status.account_id,tsd->status.account_id,9 ); } for(i=0;ialliance[i].guild_id==sd->status.guild_id && - tg->alliance[i].opposition==1) + if(tg->guild.alliance[i].guild_id==sd->status.guild_id && + tg->guild.alliance[i].opposition==1) intif_guild_alliance( tsd->status.guild_id,sd->status.guild_id, tsd->status.account_id,sd->status.account_id,9 ); } @@ -1920,12 +1905,11 @@ int guild_delalliance(map_session_data *sd,int guild_id,int flag) { * Player sd, asking player tsd a formal enemy relation between their 2 guilds *---------------------------------------------------*/ int guild_opposition(map_session_data *sd,map_session_data *tsd) { - struct guild *g; int i; nullpo_ret(sd); - g=sd->guild; + auto &g = sd->guild; if(g==NULL || tsd==NULL) return 0; @@ -1933,14 +1917,14 @@ int guild_opposition(map_session_data *sd,map_session_data *tsd) { if(sd->status.guild_id == tsd->status.guild_id) return 0; - if( guild_get_alliance_count(g,1) >= battle_config.max_guild_alliance ) { + if( guild_get_alliance_count(g->guild,1) >= battle_config.max_guild_alliance ) { clif_guild_oppositionack(sd,1); return 0; } for (i = 0; i < MAX_GUILDALLIANCE; i++) { // checking relations - if(g->alliance[i].guild_id==tsd->status.guild_id){ - if (g->alliance[i].opposition == 1) { // check if not already hostile + if(g->guild.alliance[i].guild_id==tsd->status.guild_id){ + if (g->guild.alliance[i].opposition == 1) { // check if not already hostile clif_guild_oppositionack(sd,2); return 0; } @@ -1963,7 +1947,7 @@ int guild_opposition(map_session_data *sd,map_session_data *tsd) { *---------------------------------------------------*/ int guild_allianceack(int guild_id1,int guild_id2,uint32 account_id1,uint32 account_id2,int flag,const char *name1,const char *name2) { - struct guild *g[2]; + struct mmo_guild *g[2]; int guild_id[2]; const char *guild_name[2]; map_session_data *sd[2]; @@ -1976,8 +1960,8 @@ int guild_allianceack(int guild_id1,int guild_id2,uint32 account_id1,uint32 acco sd[0] = map_id2sd(account_id1); sd[1] = map_id2sd(account_id2); - g[0]=guild_search(guild_id1); - g[1]=guild_search(guild_id2); + g[0] = &guild_search(guild_id1)->guild; + g[1] = &guild_search(guild_id2)->guild; if(sd[0]!=NULL && (flag&0x0f)==0){ sd[0]->guild_alliance=0; @@ -2045,21 +2029,15 @@ int guild_allianceack(int guild_id1,int guild_id2,uint32 account_id1,uint32 acco * Notification for the guild disbanded * @see DBApply */ -int guild_broken_sub(DBKey key, DBData *data, va_list ap) { - struct guild *g = (struct guild *)db_data2ptr(data); - int guild_id=va_arg(ap,int); - int i,j; - map_session_data *sd=NULL; - - nullpo_ret(g); - - for(i=0;ialliance[i].guild_id==guild_id){ - for(j=0;jmax_member;j++) - if( (sd=g->member[j].sd)!=NULL ) - clif_guild_delalliance(sd,guild_id,g->alliance[i].opposition); - intif_guild_alliance(g->guild_id, guild_id,0,0,g->alliance[i].opposition|8); - g->alliance[i].guild_id=0; +int guild_broken_sub(struct mmo_guild &g, int guild_id) { + for (int i = 0; i < MAX_GUILDALLIANCE; i++) { // Destroy all relationships + if (g.alliance[i].guild_id == guild_id) { + for (int j = 0; j < g.max_member; j++) { + if (g.member[j].sd) + clif_guild_delalliance(g.member[j].sd, guild_id, g.alliance[i].opposition); + } + intif_guild_alliance(g.guild_id, guild_id, 0, 0, g.alliance[i].opposition | 8); + g.alliance[i].guild_id = 0; } } return 0; @@ -2087,21 +2065,21 @@ void castle_guild_broken_sub(int guild_id) { //Invoked on /breakguild "Guild name" int guild_broken(int guild_id,int flag) { - struct guild *g = guild_search(guild_id); + auto g = guild_search(guild_id); int i; if (flag != 0 || g == NULL) return 0; - for (i = 0; i < g->max_member; i++){ // Destroy all relationships - map_session_data *sd = g->member[i].sd; + for (i = 0; i < g->guild.max_member; i++){ // Destroy all relationships + map_session_data *sd = g->guild.member[i].sd; if(sd != NULL){ if(sd->state.storage_flag == 2) storage_guild_storage_quit(sd,1); sd->status.guild_id=0; sd->guild = NULL; sd->state.gmaster_flag = 0; - clif_guild_broken(g->member[i].sd,0); + clif_guild_broken(g->guild.member[i].sd,0); clif_name_area(&sd->bl); // [LuzZza] status_change_end(&sd->bl,SC_LEADERSHIP); status_change_end(&sd->bl,SC_GLORYWOUNDS); @@ -2111,13 +2089,18 @@ int guild_broken(int guild_id,int flag) { } } - guild_db->foreach(guild_db,guild_broken_sub,guild_id); + for (auto &it : guild_db) { + if (!it.second) + continue; + guild_broken_sub(it.second->guild, guild_id); + } + castle_guild_broken_sub(guild_id); storage_guild_delete(guild_id); if( channel_config.ally_tmpl.name[0] ) { channel_delete(g->channel,false); } - idb_remove(guild_db,guild_id); + guild_db.erase(guild_id); return 0; } @@ -2126,24 +2109,23 @@ int guild_broken(int guild_id,int flag) { * @param sd New guild master */ int guild_gm_change(int guild_id, uint32 char_id) { - struct guild *g; char *name; int i; - g = guild_search(guild_id); + auto g = guild_search(guild_id); + if (!g) + return 0; - nullpo_ret(g); - - ARR_FIND(0, MAX_GUILD, i, g->member[i].char_id == char_id); + ARR_FIND(0, MAX_GUILD, i, g->guild.member[i].char_id == char_id); if( i == MAX_GUILD ){ // Not part of the guild return 0; } - name = g->member[i].name; + name = g->guild.member[i].name; - if (strcmp(g->master, name) == 0) //Nothing to change. + if (strcmp(g->guild.master, name) == 0) //Nothing to change. return 0; //Notify servers that master has changed. @@ -2157,58 +2139,57 @@ int guild_gm_change(int guild_id, uint32 char_id) { * @param char_id */ int guild_gm_changed(int guild_id, uint32 account_id, uint32 char_id, time_t time) { - struct guild *g; struct guild_member gm; int pos, i; - g=guild_search(guild_id); + auto g = guild_search(guild_id); if (!g) return 0; - for(pos=0; posmax_member && !( - g->member[pos].account_id==account_id && - g->member[pos].char_id==char_id); + for(pos=0; posguild.max_member && !( + g->guild.member[pos].account_id==account_id && + g->guild.member[pos].char_id==char_id); pos++); - if (pos == 0 || pos == g->max_member) return 0; + if (pos == 0 || pos == g->guild.max_member) return 0; - memcpy(&gm, &g->member[pos], sizeof (struct guild_member)); - memcpy(&g->member[pos], &g->member[0], sizeof(struct guild_member)); - memcpy(&g->member[0], &gm, sizeof(struct guild_member)); + memcpy(&gm, &g->guild.member[pos], sizeof (struct guild_member)); + memcpy(&g->guild.member[pos], &g->guild.member[0], sizeof(struct guild_member)); + memcpy(&g->guild.member[0], &gm, sizeof(struct guild_member)); - g->member[pos].position = g->member[0].position; - g->member[0].position = 0; //Position 0: guild Master. - strcpy(g->master, g->member[0].name); + g->guild.member[pos].position = g->guild.member[0].position; + g->guild.member[0].position = 0; //Position 0: guild Master. + strcpy(g->guild.master, g->guild.member[0].name); - if (g->member[pos].sd && g->member[pos].sd->fd) { - clif_displaymessage(g->member[pos].sd->fd, msg_txt(g->member[pos].sd,678)); //"You no longer are the Guild Master." - g->member[pos].sd->state.gmaster_flag = 0; - clif_name_area(&g->member[pos].sd->bl); + if (g->guild.member[pos].sd && g->guild.member[pos].sd->fd) { + clif_displaymessage(g->guild.member[pos].sd->fd, msg_txt(g->guild.member[pos].sd,678)); //"You no longer are the Guild Master." + g->guild.member[pos].sd->state.gmaster_flag = 0; + clif_name_area(&g->guild.member[pos].sd->bl); } - if (g->member[0].sd && g->member[0].sd->fd) { - clif_displaymessage(g->member[0].sd->fd, msg_txt(g->member[pos].sd,679)); //"You have become the Guild Master!" - g->member[0].sd->state.gmaster_flag = 1; - clif_name_area(&g->member[0].sd->bl); + if (g->guild.member[0].sd && g->guild.member[0].sd->fd) { + clif_displaymessage(g->guild.member[0].sd->fd, msg_txt(g->guild.member[pos].sd,679)); //"You have become the Guild Master!" + g->guild.member[0].sd->state.gmaster_flag = 1; + clif_name_area(&g->guild.member[0].sd->bl); //Block his skills to prevent abuse. #ifndef RENEWAL if (battle_config.guild_skill_relog_delay) - guild_block_skill(g->member[0].sd, battle_config.guild_skill_relog_delay); + guild_block_skill(g->guild.member[0].sd, battle_config.guild_skill_relog_delay); #endif } // announce the change to all guild members - for( i = 0; i < g->max_member; i++ ) { - if( g->member[i].sd ){ - clif_guild_basicinfo( *g->member[i].sd ); - clif_guild_memberlist( *g->member[i].sd ); - clif_guild_belonginfo( *g->member[i].sd ); // Update clientside guildmaster flag + for( i = 0; i < g->guild.max_member; i++ ) { + if( g->guild.member[i].sd ){ + clif_guild_basicinfo( *g->guild.member[i].sd ); + clif_guild_memberlist( *g->guild.member[i].sd ); + clif_guild_belonginfo( *g->guild.member[i].sd ); // Update clientside guildmaster flag } } // Store changing time - g->last_leader_change = time; + g->guild.last_leader_change = time; return 1; } @@ -2218,7 +2199,6 @@ int guild_gm_changed(int guild_id, uint32 account_id, uint32 char_id, time_t tim * @param name Guild name */ int guild_break(map_session_data *sd,char *name) { - struct guild *g; struct unit_data *ud; int i; #ifdef BOUND_ITEMS @@ -2228,19 +2208,21 @@ int guild_break(map_session_data *sd,char *name) { nullpo_ret(sd); - if ((g=sd->guild)==NULL) + auto &g = sd->guild; + + if (!g) return 0; - if (strcmp(g->name,name) != 0) + if (strcmp(g->guild.name,name) != 0) return 0; if (!sd->state.gmaster_flag) return 0; - for (i = 0; i < g->max_member; i++) { - if( g->member[i].account_id>0 && ( - g->member[i].account_id!=sd->status.account_id || - g->member[i].char_id!=sd->status.char_id )) + for (i = 0; i < g->guild.max_member; i++) { + if( g->guild.member[i].account_id>0 && ( + g->guild.member[i].account_id!=sd->status.account_id || + g->guild.member[i].char_id!=sd->status.char_id )) break; } - if (i < g->max_member) { + if (i < g->guild.max_member) { clif_guild_broken(sd,2); return 0; } @@ -2275,7 +2257,7 @@ int guild_break(map_session_data *sd,char *name) { pc_delitem(sd,idxlist[i],sd->inventory.u.items_inventory[idxlist[i]].amount,0,1,LOG_TYPE_BOUND_REMOVAL); #endif - intif_guild_break(g->guild_id); + intif_guild_break(g->guild.guild_id); return 1; } @@ -2533,12 +2515,10 @@ bool guild_agit3_end(void){ } // How many castles does this guild have? -int guild_checkcastles(struct guild *g) { - nullpo_retr(0, g); - +int guild_checkcastles(const struct mmo_guild &g) { int nb_cas = 0; for (const auto &it : castle_db) { - if (it.second->guild_id == g->guild_id) + if (it.second->guild_id == g.guild_id) nb_cas++; } return nb_cas; @@ -2547,11 +2527,12 @@ int guild_checkcastles(struct guild *g) { // Are these two guilds allied? bool guild_isallied(int guild_id, int guild_id2) { int i; - struct guild* g = guild_search(guild_id); - nullpo_ret(g); + auto g = guild_search(guild_id); + if (!g) + return false; - ARR_FIND( 0, MAX_GUILDALLIANCE, i, g->alliance[i].guild_id == guild_id2 ); - return( i < MAX_GUILDALLIANCE && g->alliance[i].opposition == 0 ); + ARR_FIND( 0, MAX_GUILDALLIANCE, i, g->guild.alliance[i].guild_id == guild_id2 ); + return( i < MAX_GUILDALLIANCE && g->guild.alliance[i].opposition == 0 ); } void guild_flag_add(struct npc_data *nd) { @@ -2630,7 +2611,6 @@ void guild_flags_clear(void) { } void do_init_guild(void) { - guild_db = idb_alloc(DB_OPT_RELEASE_DATA); guild_expcache_db = idb_alloc(DB_OPT_BASE); guild_infoevent_db = idb_alloc(DB_OPT_BASE); expcache_ers = ers_new(sizeof(struct guild_expcache),"guild.cpp::expcache_ers",ERS_OPT_NONE); @@ -2647,15 +2627,13 @@ void do_init_guild(void) { } void do_final_guild(void) { - DBIterator *iter = db_iterator(guild_db); - struct guild *g; - - for( g = (struct guild *)dbi_first(iter); dbi_exists(iter); g = (struct guild *)dbi_next(iter) ) { - channel_delete(g->channel,false); + for (auto &it : guild_db) { + if (!it.second) + continue; + channel_delete(it.second->channel, false); } - dbi_destroy(iter); - db_destroy(guild_db); + guild_db.clear(); castle_db.clear(); guild_expcache_db->destroy(guild_expcache_db,guild_expcache_db_final); guild_infoevent_db->destroy(guild_infoevent_db,eventlist_db_final); diff --git a/src/map/guild.hpp b/src/map/guild.hpp index a674d28950..20aa6c0a2c 100644 --- a/src/map/guild.hpp +++ b/src/map/guild.hpp @@ -10,7 +10,7 @@ #include "map.hpp" // NAME_LENGTH -struct guild; +struct mmo_guild; struct guild_member; struct guild_position; struct guild_castle; @@ -27,20 +27,29 @@ struct guardian_data { std::shared_ptr castle; }; +class MapGuild { +public: + struct mmo_guild guild; + struct Channel *channel; + int instance_id; + int32 chargeshout_flag_id; +}; + uint16 guild_skill_get_max(uint16 id); -int guild_checkskill(struct guild *g,int id); -bool guild_check_skill_require(struct guild *g,uint16 id); // [Komurka] -int guild_checkcastles(struct guild *g); // [MouseJstr] +int guild_checkskill(const struct mmo_guild &g,int id); +bool guild_check_skill_require(const struct mmo_guild &g,uint16 id); // [Komurka] +int guild_checkcastles(const struct mmo_guild &g); // [MouseJstr] bool guild_isallied(int guild_id, int guild_id2); //Checks alliance based on guild Ids. [Skotlex] void do_init_guild(void); -struct guild *guild_search(int guild_id); -struct guild *guild_searchname(char *str); +std::shared_ptr guild_search(int guild_id); +std::shared_ptr guild_searchname(const char *str); +std::shared_ptr guild_searchnameid(const char *str); -map_session_data *guild_getavailablesd(struct guild *g); -int guild_getindex(struct guild *g,uint32 account_id,uint32 char_id); -int guild_getposition(map_session_data *sd); +map_session_data* guild_getavailablesd(const struct mmo_guild &g); +int guild_getindex(const struct mmo_guild &g, uint32 account_id, uint32 char_id); +int guild_getposition(const map_session_data &sd); t_exp guild_payexp(map_session_data *sd,t_exp exp); t_exp guild_getexp(map_session_data *sd,t_exp exp); // [Celest] @@ -48,7 +57,7 @@ int guild_create(map_session_data *sd, const char *name); int guild_created(uint32 account_id,int guild_id); int guild_request_info(int guild_id); int guild_recv_noinfo(int guild_id); -int guild_recv_info(struct guild *sg); +int guild_recv_info(const struct mmo_guild &sg); int guild_npc_request_info(int guild_id,const char *ev); int guild_invite(map_session_data *sd,map_session_data *tsd); int guild_reply_invite(map_session_data *sd,int guild_id,int flag); @@ -73,7 +82,7 @@ int guild_check_alliance(int guild_id1, int guild_id2, int flag); int guild_send_memberinfoshort(map_session_data *sd,int online); int guild_recv_memberinfoshort(int guild_id,uint32 account_id,uint32 char_id,int online,int lv,int class_); int guild_change_memberposition(int guild_id,uint32 account_id,uint32 char_id,short idx); -int guild_memberposition_changed(struct guild *g,int idx,int pos); +int guild_memberposition_changed(struct mmo_guild &g,int idx,int pos); int guild_change_position(int guild_id,int idx,int mode,int exp_mode,const char *name); int guild_position_changed(int guild_id,int idx,struct guild_position *p); int guild_change_notice(map_session_data *sd,int guild_id,const char *mes1,const char *mes2); diff --git a/src/map/instance.cpp b/src/map/instance.cpp index 1ba879b0ae..24b35e43dd 100644 --- a/src/map/instance.cpp +++ b/src/map/instance.cpp @@ -305,7 +305,7 @@ void instance_getsd(int instance_id, map_session_data *&sd, enum send_target *ta (*target) = SELF; break; case IM_GUILD: - sd = guild_getavailablesd(guild_search(idata->owner_id)); + sd = guild_getavailablesd(guild_search(idata->owner_id)->guild); (*target) = GUILD; break; case IM_PARTY: @@ -348,7 +348,7 @@ static TIMER_FUNC(instance_subscription_timer){ map_session_data *sd; struct party_data *pd; - struct guild *gd; + std::shared_ptr gd; struct clan *cd; e_instance_mode mode = idata->mode; int ret = instance_addmap(instance_id); // Check that maps have been added @@ -613,7 +613,7 @@ int instance_create(int owner_id, const char *name, e_instance_mode mode) { map_session_data *sd = nullptr; struct party_data *pd; - struct guild *gd; + std::shared_ptr gd; struct clan* cd; switch(mode) { @@ -683,7 +683,7 @@ int instance_create(int owner_id, const char *name, e_instance_mode mode) { break; case IM_GUILD: gd->instance_id = instance_id; - sd = map_charid2sd(gd->member[0].char_id); + sd = map_charid2sd(gd->guild.member[0].char_id); break; case IM_CLAN: cd->instance_id = instance_id; @@ -878,7 +878,7 @@ void instance_destroy_command(map_session_data *sd) { instance_id = pd->instance_id; } else if (sd->instance_mode == IM_GUILD && sd->guild != nullptr && sd->guild->instance_id > 0) { - guild *gd = guild_search(sd->status.guild_id); + auto gd = guild_search(sd->status.guild_id); if (gd == nullptr) return; @@ -888,7 +888,7 @@ void instance_destroy_command(map_session_data *sd) { if (idata == nullptr) return; - if (strcmp(sd->status.name, gd->master) != 0) // Player is not guild master + if (strcmp(sd->status.name, gd->guild.master) != 0) // Player is not guild master return; instance_id = gd->instance_id; @@ -915,7 +915,7 @@ void instance_destroy_command(map_session_data *sd) { instance_reqinfo(sd, pd->instance_id); } if (sd->guild != nullptr && sd->guild->instance_id > 0) { - guild *gd = guild_search(sd->status.guild_id); + auto gd = guild_search(sd->status.guild_id); if (gd == nullptr) return; @@ -938,7 +938,7 @@ bool instance_destroy(int instance_id) map_session_data *sd; struct party_data *pd; - struct guild *gd; + std::shared_ptr gd; struct clan *cd; e_instance_mode mode = idata->mode; e_instance_notify type = IN_NOTIFY; @@ -1065,7 +1065,7 @@ e_instance_enter instance_enter(map_session_data *sd, int instance_id, const cha std::shared_ptr idata = nullptr; struct party_data *pd; - struct guild *gd; + std::shared_ptr gd; struct clan *cd; e_instance_mode mode; @@ -1103,7 +1103,7 @@ e_instance_enter instance_enter(map_session_data *sd, int instance_id, const cha return IE_NOMEMBER; if (gd->instance_id == 0) // Guild must have an instance return IE_NOINSTANCE; - if (idata->owner_id != gd->guild_id) + if (idata->owner_id != gd->guild.guild_id) return IE_OTHER; break; case IM_CLAN: @@ -1249,7 +1249,7 @@ void do_reload_instance(void) if (sd && mapdata->instance_id > 0) { struct party_data *pd; - struct guild *gd; + std::shared_ptr gd; struct clan *cd; int instance_id; std::shared_ptr idata = util::umap_find(instances, map[sd->bl.m].instance_id); diff --git a/src/map/intif.cpp b/src/map/intif.cpp index 9d1a369550..e5883f5fac 100644 --- a/src/map/intif.cpp +++ b/src/map/intif.cpp @@ -1666,9 +1666,9 @@ int intif_parse_GuildInfo(int fd) guild_recv_noinfo(RFIFOL(fd,4)); return 0; } - if( RFIFOW(fd,2)!=sizeof(struct guild)+4 ) - ShowError("intif: guild info : data size error Gid: %d recv size: %d Expected size: %" PRIuPTR "\n",RFIFOL(fd,4),RFIFOW(fd,2),sizeof(struct guild)+4); - guild_recv_info((struct guild *)RFIFOP(fd,4)); + if( RFIFOW(fd,2)!=sizeof(struct mmo_guild)+4 ) + ShowError("intif: guild info : data size error Gid: %d recv size: %d Expected size: %" PRIuPTR "\n",RFIFOL(fd,4),RFIFOW(fd,2),sizeof(struct mmo_guild)+4); + guild_recv_info(*(struct mmo_guild *)RFIFOP(fd,4)); return 1; } @@ -1731,14 +1731,14 @@ int intif_parse_GuildBasicInfoChanged(int fd) int type = RFIFOW(fd,8); //void* data = RFIFOP(fd,10); - struct guild* g = guild_search(guild_id); + auto g = guild_search(guild_id); if( g == NULL ) return 0; switch(type) { - case GBI_EXP: g->exp = RFIFOQ(fd,10); break; - case GBI_GUILDLV: g->guild_lv = RFIFOW(fd,10); break; - case GBI_SKILLPOINT: g->skill_point = RFIFOL(fd,10); break; + case GBI_EXP: g->guild.exp = RFIFOQ(fd,10); break; + case GBI_GUILDLV: g->guild.guild_lv = RFIFOW(fd,10); break; + case GBI_SKILLPOINT: g->guild.skill_point = RFIFOL(fd,10); break; } return 1; @@ -1759,25 +1759,24 @@ int intif_parse_GuildMemberInfoChanged(int fd) int type = RFIFOW(fd,16); //void* data = RFIFOP(fd,18); - struct guild* g; int idx; - g = guild_search(guild_id); - if( g == NULL ) + auto g = guild_search(guild_id); + if( g == nullptr ) return 0; - idx = guild_getindex(g,account_id,char_id); + idx = guild_getindex(g->guild,account_id,char_id); if( idx == -1 ) return 0; switch( type ) { - case GMI_POSITION: g->member[idx].position = RFIFOW(fd,18); guild_memberposition_changed(g,idx,RFIFOW(fd,18)); break; - case GMI_EXP: g->member[idx].exp = RFIFOQ(fd,18); break; - case GMI_HAIR: g->member[idx].hair = RFIFOW(fd,18); break; - case GMI_HAIR_COLOR: g->member[idx].hair_color = RFIFOW(fd,18); break; - case GMI_GENDER: g->member[idx].gender = RFIFOW(fd,18); break; - case GMI_CLASS: g->member[idx].class_ = RFIFOW(fd,18); break; - case GMI_LEVEL: g->member[idx].lv = RFIFOW(fd,18); break; + case GMI_POSITION: g->guild.member[idx].position = RFIFOW(fd,18); guild_memberposition_changed(g->guild,idx,RFIFOW(fd,18)); break; + case GMI_EXP: g->guild.member[idx].exp = RFIFOQ(fd,18); break; + case GMI_HAIR: g->guild.member[idx].hair = RFIFOW(fd,18); break; + case GMI_HAIR_COLOR: g->guild.member[idx].hair_color = RFIFOW(fd,18); break; + case GMI_GENDER: g->guild.member[idx].gender = RFIFOW(fd,18); break; + case GMI_CLASS: g->guild.member[idx].class_ = RFIFOW(fd,18); break; + case GMI_LEVEL: g->guild.member[idx].lv = RFIFOW(fd,18); break; } return 1; } diff --git a/src/map/mob.cpp b/src/map/mob.cpp index 6ce6be00a8..71f8207609 100644 --- a/src/map/mob.cpp +++ b/src/map/mob.cpp @@ -684,7 +684,7 @@ int mob_once_spawn(map_session_data* sd, int16 m, int16 x, int16 y, const char* if (mob_id == MOBID_EMPERIUM) { std::shared_ptr gc = castle_db.mapindex2gc(map_getmapdata(m)->index); - struct guild* g = (gc) ? guild_search(gc->guild_id) : nullptr; + auto g = (gc) ? guild_search(gc->guild_id) : nullptr; if (gc) { md->guardian_data = (struct guardian_data*)aCalloc(1, sizeof(struct guardian_data)); @@ -694,8 +694,8 @@ int mob_once_spawn(map_session_data* sd, int16 m, int16 x, int16 y, const char* md->guardian_data->guild_id = gc->guild_id; if (g) { - md->guardian_data->emblem_id = g->emblem_id; - memcpy(md->guardian_data->guild_name, g->name, NAME_LENGTH); + md->guardian_data->emblem_id = g->guild.emblem_id; + memcpy(md->guardian_data->guild_name, g->guild.name, NAME_LENGTH); } else if (gc->guild_id) // Guild is not yet available, retry after the configured timespan. add_timer(gettick() + battle_config.mob_respawn_time,mob_spawn_guardian_sub,md->bl.id,md->guardian_data->guild_id); @@ -774,7 +774,6 @@ static TIMER_FUNC(mob_spawn_guardian_sub){ //Needed because the guild_data may not be available at guardian spawn time. struct block_list* bl = map_id2bl(id); struct mob_data* md; - struct guild* g; int guardup_lv; if (bl == nullptr) //It is possible mob was already removed from map when the castle has no owner. [Skotlex] @@ -788,7 +787,7 @@ static TIMER_FUNC(mob_spawn_guardian_sub){ md = (struct mob_data*)bl; nullpo_ret(md->guardian_data); - g = guild_search((int)data); + auto g = guild_search((int)data); if (g == nullptr) { //Liberate castle, if the guild is not found this is an error! [Skotlex] @@ -808,9 +807,9 @@ static TIMER_FUNC(mob_spawn_guardian_sub){ } return 0; } - guardup_lv = guild_checkskill(g,GD_GUARDUP); - md->guardian_data->emblem_id = g->emblem_id; - memcpy(md->guardian_data->guild_name, g->name, NAME_LENGTH); + guardup_lv = guild_checkskill(g->guild, GD_GUARDUP); + md->guardian_data->emblem_id = g->guild.emblem_id; + memcpy(md->guardian_data->guild_name, g->guild.name, NAME_LENGTH); md->guardian_data->guardup_lv = guardup_lv; if( guardup_lv ) status_calc_mob(md, SCO_NONE); //Give bonuses. @@ -824,7 +823,7 @@ int mob_spawn_guardian(const char* mapname, int16 x, int16 y, const char* mobnam { struct mob_data *md=nullptr; struct spawn_data data; - struct guild *g=nullptr; + std::shared_ptr g = nullptr; int16 m; memset(&data, 0, sizeof(struct spawn_data)); //fixme data.num = 1; @@ -913,9 +912,9 @@ int mob_spawn_guardian(const char* mapname, int16 x, int16 y, const char* mobnam } if (g) { - md->guardian_data->emblem_id = g->emblem_id; - memcpy (md->guardian_data->guild_name, g->name, NAME_LENGTH); - md->guardian_data->guardup_lv = guild_checkskill(g,GD_GUARDUP); + md->guardian_data->emblem_id = g->guild.emblem_id; + memcpy (md->guardian_data->guild_name, g->guild.name, NAME_LENGTH); + md->guardian_data->guardup_lv = guild_checkskill(g->guild,GD_GUARDUP); } else if (md->guardian_data->guild_id) add_timer(gettick() + battle_config.mob_respawn_time,mob_spawn_guardian_sub,md->bl.id,md->guardian_data->guild_id); mob_spawn(md); @@ -3212,7 +3211,6 @@ void mob_revive(struct mob_data *md, unsigned int hp) int mob_guardian_guildchange(struct mob_data *md) { - struct guild *g; nullpo_ret(md); if (!md->guardian_data) @@ -3233,7 +3231,7 @@ int mob_guardian_guildchange(struct mob_data *md) return 0; } - g = guild_search(md->guardian_data->castle->guild_id); + auto g = guild_search(md->guardian_data->castle->guild_id); if (g == NULL) { //Properly remove guardian info from Castle data. ShowError("mob_guardian_guildchange: New Guild (id %d) does not exists!\n", md->guardian_data->guild_id); @@ -3243,10 +3241,10 @@ int mob_guardian_guildchange(struct mob_data *md) return 0; } - md->guardian_data->guild_id = g->guild_id; - md->guardian_data->emblem_id = g->emblem_id; - md->guardian_data->guardup_lv = guild_checkskill(g,GD_GUARDUP); - memcpy(md->guardian_data->guild_name, g->name, NAME_LENGTH); + md->guardian_data->guild_id = g->guild.guild_id; + md->guardian_data->emblem_id = g->guild.emblem_id; + md->guardian_data->guardup_lv = guild_checkskill(g->guild, GD_GUARDUP); + memcpy(md->guardian_data->guild_name, g->guild.name, NAME_LENGTH); return 1; } diff --git a/src/map/pc.cpp b/src/map/pc.cpp index 79f0aee001..1cb25fad69 100755 --- a/src/map/pc.cpp +++ b/src/map/pc.cpp @@ -1225,7 +1225,7 @@ bool pc_can_sell_item(map_session_data *sd, struct item *item, enum npc_subtype case NPCTYPE_SHOP: if (item->bound && battle_config.allow_bound_sell&ISR_BOUND_SELLABLE && ( item->bound != BOUND_GUILD || - (sd->guild && sd->status.char_id == sd->guild->member[0].char_id) || + (sd->guild && sd->status.char_id == sd->guild->guild.member[0].char_id) || (item->bound == BOUND_GUILD && !(battle_config.allow_bound_sell&ISR_BOUND_GUILDLEADER_ONLY)) )) return true; @@ -1233,7 +1233,7 @@ bool pc_can_sell_item(map_session_data *sd, struct item *item, enum npc_subtype case NPCTYPE_ITEMSHOP: if (item->bound && battle_config.allow_bound_sell&ISR_BOUND && ( item->bound != BOUND_GUILD || - (sd->guild && sd->status.char_id == sd->guild->member[0].char_id) || + (sd->guild && sd->status.char_id == sd->guild->guild.member[0].char_id) || (item->bound == BOUND_GUILD && !(battle_config.allow_bound_sell&ISR_BOUND_GUILDLEADER_ONLY)) )) return true; @@ -7161,10 +7161,8 @@ uint8 pc_checkskill(map_session_data *sd, uint16 skill_id) return 0; } if (SKILL_CHK_GUILD(skill_id) ) { - struct guild *g; - - if( sd->status.guild_id>0 && (g=sd->guild)!=NULL) - return guild_checkskill(g,skill_id); + if (sd->status.guild_id>0 && sd->guild) + return guild_checkskill(sd->guild->guild,skill_id); return 0; } return (sd->status.skill[idx].id == skill_id) ? sd->status.skill[idx].lv : 0; @@ -9954,11 +9952,11 @@ void pc_revive(map_session_data *sd,unsigned int hp, unsigned int sp, unsigned i if(battle_config.pc_invincible_time > 0) pc_setinvincibletimer(sd, battle_config.pc_invincible_time); - if( sd->state.gmaster_flag ) { - guild_guildaura_refresh(sd,GD_LEADERSHIP,guild_checkskill(sd->guild,GD_LEADERSHIP)); - guild_guildaura_refresh(sd,GD_GLORYWOUNDS,guild_checkskill(sd->guild,GD_GLORYWOUNDS)); - guild_guildaura_refresh(sd,GD_SOULCOLD,guild_checkskill(sd->guild,GD_SOULCOLD)); - guild_guildaura_refresh(sd,GD_HAWKEYES,guild_checkskill(sd->guild,GD_HAWKEYES)); + if (sd->state.gmaster_flag && sd->guild) { + guild_guildaura_refresh(sd,GD_LEADERSHIP,guild_checkskill(sd->guild->guild,GD_LEADERSHIP)); + guild_guildaura_refresh(sd,GD_GLORYWOUNDS,guild_checkskill(sd->guild->guild,GD_GLORYWOUNDS)); + guild_guildaura_refresh(sd,GD_SOULCOLD,guild_checkskill(sd->guild->guild,GD_SOULCOLD)); + guild_guildaura_refresh(sd,GD_HAWKEYES,guild_checkskill(sd->guild->guild,GD_HAWKEYES)); } } diff --git a/src/map/pc.hpp b/src/map/pc.hpp index 34421b7374..c37cd4fb59 100644 --- a/src/map/pc.hpp +++ b/src/map/pc.hpp @@ -33,6 +33,8 @@ enum e_instance_mode : uint8; enum e_log_pick_type : uint32; enum sc_type : int16; +class MapGuild; + #define MAX_PC_BONUS 50 /// Max bonus, usually used by item bonus #define MAX_PC_FEELHATE 3 /// Max feel hate info #define DAMAGELOG_SIZE_PC 100 /// Damage log @@ -716,7 +718,7 @@ public: int party_invite, party_invite_account; // for handling party invitation (holds party id and account id) int adopt_invite; // Adoption - struct guild *guild; // [Ind] speed everything up + std::shared_ptr guild; // [Ind] speed everything up int guild_invite,guild_invite_account; int guild_emblem_id,guild_alliance,guild_alliance_account; short guild_x,guild_y; // For guildmate position display. [Skotlex] should be short [zzo] diff --git a/src/map/script.cpp b/src/map/script.cpp index b54ce45c77..027587945e 100644 --- a/src/map/script.cpp +++ b/src/map/script.cpp @@ -5916,7 +5916,6 @@ BUILDIN_FUNC(warpguild) { TBL_PC *sd = NULL; TBL_PC *pl_sd; - struct guild* g; struct s_mapiterator* iter; int type, mapindex = 0, m = -1; @@ -5925,7 +5924,7 @@ BUILDIN_FUNC(warpguild) int y = script_getnum(st,4); int gid = script_getnum(st,5); - g = guild_search(gid); + auto g = guild_search(gid); if( g == NULL ) return SCRIPT_CMD_SUCCESS; @@ -9005,11 +9004,11 @@ BUILDIN_FUNC(getpartyleader) BUILDIN_FUNC(getguildname) { int guild_id; - struct guild* g; guild_id = script_getnum(st,2); - if( ( g = guild_search(guild_id) ) != NULL ) - script_pushstrcopy(st,g->name); + auto g = guild_search(guild_id); + if (g) + script_pushstrcopy(st,g->guild.name); else script_pushconststr(st,"null"); return SCRIPT_CMD_SUCCESS; @@ -9022,11 +9021,11 @@ BUILDIN_FUNC(getguildname) BUILDIN_FUNC(getguildmaster) { int guild_id; - struct guild* g; guild_id = script_getnum(st,2); - if( ( g = guild_search(guild_id) ) != NULL ) - script_pushstrcopy(st,g->member[0].name); + auto g = guild_search(guild_id); + if (g) + script_pushstrcopy(st,g->guild.member[0].name); else script_pushconststr(st,"null"); return SCRIPT_CMD_SUCCESS; @@ -9035,11 +9034,11 @@ BUILDIN_FUNC(getguildmaster) BUILDIN_FUNC(getguildmasterid) { int guild_id; - struct guild* g; guild_id = script_getnum(st,2); - if( ( g = guild_search(guild_id) ) != NULL ) - script_pushint(st,g->member[0].char_id); + auto g = guild_search(guild_id); + if (g) + script_pushint(st,g->guild.member[0].char_id); else script_pushint(st,0); return SCRIPT_CMD_SUCCESS; @@ -9059,7 +9058,6 @@ BUILDIN_FUNC(strcharinfo) { TBL_PC *sd; int num; - struct guild* g; struct party_data* p; if (!script_charid2sd(3,sd)) { @@ -9080,8 +9078,8 @@ BUILDIN_FUNC(strcharinfo) } break; case 2: - if( ( g = sd->guild ) != NULL ) { - script_pushstrcopy(st,g->name); + if (sd->guild) { + script_pushstrcopy(st,sd->guild->guild.name); } else { script_pushconststr(st,""); } @@ -10296,15 +10294,14 @@ BUILDIN_FUNC(getgdskilllv) { int guild_id; uint16 skill_id; - struct guild* g; guild_id = script_getnum(st,2); skill_id = ( script_isstring(st, 3) ? skill_name2id(script_getstr(st,3)) : script_getnum(st,3) ); - g = guild_search(guild_id); - if( g == NULL ) + auto g = guild_search(guild_id); + if (!g) script_pushint(st, -1); else - script_pushint(st, guild_checkskill(g,skill_id)); + script_pushint(st, guild_checkskill(g->guild,skill_id)); return SCRIPT_CMD_SUCCESS; } @@ -10878,9 +10875,9 @@ BUILDIN_FUNC(guild_has_permission){ return SCRIPT_CMD_SUCCESS; } - int position = guild_getposition(sd); + int position = guild_getposition(*sd); - if( position < 0 || ( sd->guild->position[position].mode&permission ) != permission ){ + if( position < 0 || ( sd->guild->guild.position[position].mode&permission ) != permission ){ script_pushint( st, false ); return SCRIPT_CMD_SUCCESS; @@ -11981,20 +11978,19 @@ BUILDIN_FUNC(getmapguildusers) int16 m; int gid; int c=0; - struct guild *g = NULL; str=script_getstr(st,2); gid=script_getnum(st,3); if ((m = map_mapname2mapid(str)) < 0) { // map id on this server (m == -1 if not in actual map-server) script_pushint(st,-1); return SCRIPT_CMD_SUCCESS; } - g = guild_search(gid); + auto g = guild_search(gid); if (g){ unsigned short i; - for(i = 0; i < g->max_member; i++) + for(i = 0; i < g->guild.max_member; i++) { - if (g->member[i].sd && g->member[i].sd->bl.m == m) + if (g->guild.member[i].sd && g->guild.member[i].sd->bl.m == m) c++; } } @@ -14099,7 +14095,7 @@ BUILDIN_FUNC(failedremovecards) { BUILDIN_FUNC(mapwarp) // Added by RoVeRT { int x,y,m,check_val=0,check_ID=0,i=0; - struct guild *g = NULL; + std::shared_ptr g; struct party_data *p = NULL; const char *str; const char *mapname; @@ -14123,10 +14119,10 @@ BUILDIN_FUNC(mapwarp) // Added by RoVeRT case 1: g = guild_search(check_ID); if (g){ - for( i=0; i < g->max_member; i++) + for( i=0; i < g->guild.max_member; i++) { - if(g->member[i].sd && g->member[i].sd->bl.m==m){ - pc_setpos(g->member[i].sd,index,x,y,CLR_TELEPORT); + if(g->guild.member[i].sd && g->guild.member[i].sd->bl.m==m){ + pc_setpos(g->guild.member[i].sd,index,x,y,CLR_TELEPORT); } } } @@ -15654,7 +15650,6 @@ BUILDIN_FUNC(recovery) } case 2: { - struct guild* g; //When no guild given, we use invoker guild int g_id = 0, i; if(script_hasdata(st,5)) {//Bad maps shouldn't cause issues @@ -15668,12 +15663,12 @@ BUILDIN_FUNC(recovery) g_id = script_getnum(st,3); else if(script_rid2sd(sd)) g_id = sd->status.guild_id; - g = guild_search(g_id); + auto g = guild_search(g_id); if(g == NULL) return SCRIPT_CMD_SUCCESS; for (i = 0; i < MAX_GUILD; i++) { map_session_data* pl_sd; - if((!(pl_sd = g->member[i].sd) || pl_sd->status.guild_id != g_id) + if((!(pl_sd = g->guild.member[i].sd) || pl_sd->status.guild_id != g_id) || (map_idx && pl_sd->bl.m != map_idx)) continue; recovery_sub(pl_sd, revive); @@ -21331,7 +21326,7 @@ int script_instancegetid(struct script_state* st, e_instance_mode mode) } break; case IM_GUILD: { - struct guild *gd = guild_search(sd->status.guild_id); + auto gd = guild_search(sd->status.guild_id); if (gd && gd->instance_id > 0) instance_id = gd->instance_id; @@ -21735,7 +21730,6 @@ BUILDIN_FUNC(instance_check_party) BUILDIN_FUNC(instance_check_guild) { int amount, min, max, i, guild_id = 0, c = 0; - struct guild *g = NULL; amount = script_hasdata(st,3) ? script_getnum(st,3) : 1; // Amount of needed Guild members for the Instance. min = script_hasdata(st,4) ? script_getnum(st,4) : 1; // Minimum Level needed to join the Instance. @@ -21754,7 +21748,8 @@ BUILDIN_FUNC(instance_check_guild) else return SCRIPT_CMD_FAILURE; - if (!(g = guild_search(guild_id))) { + auto g = guild_search(guild_id); + if (!g) { script_pushint(st, 0); // Returns false if guild does not exist. return SCRIPT_CMD_FAILURE; } @@ -21762,7 +21757,7 @@ BUILDIN_FUNC(instance_check_guild) for(i = 0; i < MAX_GUILD; i++) { map_session_data *pl_sd; - if ((pl_sd = g->member[i].sd)) { + if ((pl_sd = g->guild.member[i].sd)) { if (map_id2bl(pl_sd->bl.id) && !pl_sd->state.autotrade) { if (pl_sd->status.base_level < min) { script_pushint(st, 0); @@ -23493,10 +23488,9 @@ BUILDIN_FUNC(disable_command) { */ BUILDIN_FUNC(getguildmember) { - struct guild *g = NULL; uint8 j = 0; - g = guild_search(script_getnum(st,2)); + auto g = guild_search(script_getnum(st,2)); if (g) { uint8 i, type = 0; @@ -23528,25 +23522,25 @@ BUILDIN_FUNC(getguildmember) } for (i = 0; i < MAX_GUILD; i++) { - if (g->member[i].account_id) { + if (g->guild.member[i].account_id) { switch (type) { case 2: if (data) - setd_sub_num( st, NULL, varname, j, g->member[i].account_id, data->ref ); + setd_sub_num( st, NULL, varname, j, g->guild.member[i].account_id, data->ref ); else - mapreg_setreg(reference_uid(add_str("$@guildmemberaid"), j),g->member[i].account_id); + mapreg_setreg(reference_uid(add_str("$@guildmemberaid"), j),g->guild.member[i].account_id); break; case 1: if (data) - setd_sub_num( st, NULL, varname, j, g->member[i].char_id, data->ref ); + setd_sub_num( st, NULL, varname, j, g->guild.member[i].char_id, data->ref ); else - mapreg_setreg(reference_uid(add_str("$@guildmembercid"), j), g->member[i].char_id); + mapreg_setreg(reference_uid(add_str("$@guildmembercid"), j), g->guild.member[i].char_id); break; default: if (data) - setd_sub_str( st, NULL, varname, j, g->member[i].name, data->ref ); + setd_sub_str( st, NULL, varname, j, g->guild.member[i].name, data->ref ); else - mapreg_setregstr(reference_uid(add_str("$@guildmembername$"), j), g->member[i].name); + mapreg_setregstr(reference_uid(add_str("$@guildmembername$"), j), g->guild.member[i].name); break; } j++; @@ -24533,7 +24527,6 @@ BUILDIN_FUNC(jobcanentermap) { */ BUILDIN_FUNC(getguildalliance) { - struct guild *guild_data1, *guild_data2; int guild_id1, guild_id2, i = 0; guild_id1 = script_getnum(st,2); @@ -24549,8 +24542,8 @@ BUILDIN_FUNC(getguildalliance) return SCRIPT_CMD_SUCCESS; } - guild_data1 = guild_search(guild_id1); - guild_data2 = guild_search(guild_id2); + auto guild_data1 = guild_search(guild_id1); + auto guild_data2 = guild_search(guild_id2); if (guild_data1 == NULL) { ShowWarning("buildin_getguildalliance: Requesting non-existent GuildID1 '%d'.\n", guild_id1); @@ -24563,13 +24556,13 @@ BUILDIN_FUNC(getguildalliance) return SCRIPT_CMD_FAILURE; } - ARR_FIND(0, MAX_GUILDALLIANCE, i, guild_data1->alliance[i].guild_id == guild_id2); + ARR_FIND(0, MAX_GUILDALLIANCE, i, guild_data1->guild.alliance[i].guild_id == guild_id2); if (i == MAX_GUILDALLIANCE) { script_pushint(st, 0); return SCRIPT_CMD_SUCCESS; } - if (guild_data1->alliance[i].opposition) + if (guild_data1->guild.alliance[i].opposition) script_pushint(st, 2); else script_pushint(st, 1); @@ -25929,7 +25922,6 @@ BUILDIN_FUNC(identifyall) { BUILDIN_FUNC(is_guild_leader) { map_session_data* sd; - struct guild* guild_data; int guild_id; if (!script_rid2sd(sd)) { @@ -25942,9 +25934,9 @@ BUILDIN_FUNC(is_guild_leader) else guild_id = sd->status.guild_id; - guild_data = guild_search(guild_id); + auto guild_data = guild_search(guild_id); if (guild_data) - script_pushint(st, (guild_data->member[0].char_id == sd->status.char_id)); + script_pushint(st, (guild_data->guild.member[0].char_id == sd->status.char_id)); else script_pushint(st, false); return SCRIPT_CMD_SUCCESS; diff --git a/src/map/skill.cpp b/src/map/skill.cpp index 3255e1b34a..611aff4523 100755 --- a/src/map/skill.cpp +++ b/src/map/skill.cpp @@ -10365,9 +10365,8 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, ui int8 dx[9] = {-1, 1, 0, 0,-1, 1,-1, 1, 0}; int8 dy[9] = { 0, 0, 1,-1, 1,-1,-1, 1, 0}; uint8 j = 0, calls = 0, called = 0; - struct guild *g; // i don't know if it actually summons in a circle, but oh well. ;P - g = sd?sd->guild:guild_search(status_get_guild_id(src)); + auto g = sd?sd->guild:guild_search(status_get_guild_id(src)); if (!g) break; @@ -10380,10 +10379,10 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, ui } clif_skill_nodamage(src,bl,skill_id,skill_lv,1); - for (i = 0; i < g->max_member && (!calls || (calls && called < calls)); i++, j++) { + for (i = 0; i < g->guild.max_member && (!calls || (calls && called < calls)); i++, j++) { if (j > 8) j = 0; - if ((dstsd = g->member[i].sd) != NULL && sd != dstsd && !dstsd->state.autotrade && !pc_isdead(dstsd)) { + if ((dstsd = g->guild.member[i].sd) != NULL && sd != dstsd && !dstsd->state.autotrade && !pc_isdead(dstsd)) { if (map_getmapflag(dstsd->bl.m, MF_NOWARP) && !map_flag_gvg2(dstsd->bl.m)) continue; if (!pc_job_can_entermap((enum e_job)dstsd->status.class_, src->m, pc_get_group_level(dstsd))) @@ -10404,7 +10403,7 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, ui break; case GD_CHARGESHOUT_FLAG: if (sd && sd->guild && sd->state.gmaster_flag == 1) { - mob_data *md = mob_once_spawn_sub(src, src->m, src->x, src->y, sd->guild->name, MOBID_GUILD_SKILL_FLAG, nullptr, SZ_SMALL, AI_GUILD); + mob_data *md = mob_once_spawn_sub(src, src->m, src->x, src->y, sd->guild->guild.name, MOBID_GUILD_SKILL_FLAG, nullptr, SZ_SMALL, AI_GUILD); if (md) { sd->guild->chargeshout_flag_id = md->bl.id; diff --git a/src/map/status.cpp b/src/map/status.cpp index 40becff12d..13aa873ec1 100644 --- a/src/map/status.cpp +++ b/src/map/status.cpp @@ -9089,9 +9089,9 @@ int status_get_emblem_id(struct block_list *bl) break; case BL_NPC: if (((TBL_NPC*)bl)->subtype == NPCTYPE_SCRIPT && ((TBL_NPC*)bl)->u.scr.guild_id > 0) { - struct guild *g = guild_search(((TBL_NPC*)bl)->u.scr.guild_id); + auto g = guild_search(((TBL_NPC*)bl)->u.scr.guild_id); if (g) - return g->emblem_id; + return g->guild.emblem_id; } break; case BL_ELEM: diff --git a/src/map/storage.cpp b/src/map/storage.cpp index 448b9ad0ae..5f59a26012 100644 --- a/src/map/storage.cpp +++ b/src/map/storage.cpp @@ -561,7 +561,7 @@ char storage_guild_storageopen(map_session_data* sd) return GSTORAGE_NO_GUILD; #ifdef OFFICIAL_GUILD_STORAGE - if (!guild_checkskill(sd->guild, GD_GUILD_STORAGE)) + if (!guild_checkskill(sd->guild->guild, GD_GUILD_STORAGE)) return GSTORAGE_NO_STORAGE; // Can't open storage if the guild has not learned the skill #endif @@ -573,7 +573,7 @@ char storage_guild_storageopen(map_session_data* sd) #if PACKETVER >= 20140205 int pos; - if ((pos = guild_getposition(sd)) < 0 || !(sd->guild->position[pos].mode&GUILD_PERM_STORAGE)) + if ((pos = guild_getposition(*sd)) < 0 || !(sd->guild->guild.position[pos].mode&GUILD_PERM_STORAGE)) return GSTORAGE_NO_PERMISSION; // Guild member doesn't have permission #endif @@ -584,7 +584,7 @@ char storage_guild_storageopen(map_session_data* sd) if((gstor = guild2storage2(sd->status.guild_id)) == nullptr #ifdef OFFICIAL_GUILD_STORAGE - || (gstor->max_amount != guild_checkskill(sd->guild, GD_GUILD_STORAGE) * 100) + || (gstor->max_amount != guild_checkskill(sd->guild->guild, GD_GUILD_STORAGE) * 100) #endif ) { intif_request_guild_storage(sd->status.account_id,sd->status.guild_id);