summaryrefslogtreecommitdiff
path: root/src/char_sql/int_guild.c
diff options
context:
space:
mode:
authoramber <amber@54d463be-8e91-2dee-dedb-b68131a5f0ec>2004-12-08 00:59:42 +0000
committeramber <amber@54d463be-8e91-2dee-dedb-b68131a5f0ec>2004-12-08 00:59:42 +0000
commit0bc9aab6f0de4d833d9b338c9455905724c2b027 (patch)
tree69b16157f7d6c96121c3d5326e9906c92bc66822 /src/char_sql/int_guild.c
parent78fd470e61d794a859580e932452c8657e317280 (diff)
downloadhercules-0bc9aab6f0de4d833d9b338c9455905724c2b027.tar.gz
hercules-0bc9aab6f0de4d833d9b338c9455905724c2b027.tar.bz2
hercules-0bc9aab6f0de4d833d9b338c9455905724c2b027.tar.xz
hercules-0bc9aab6f0de4d833d9b338c9455905724c2b027.zip
guild cache update
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/branches/stable@500 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/char_sql/int_guild.c')
-rw-r--r--src/char_sql/int_guild.c145
1 files changed, 145 insertions, 0 deletions
diff --git a/src/char_sql/int_guild.c b/src/char_sql/int_guild.c
index 007a2eb0d..69fe587aa 100644
--- a/src/char_sql/int_guild.c
+++ b/src/char_sql/int_guild.c
@@ -11,11 +11,22 @@
#include "int_storage.h"
#include "mmo.h"
#include "socket.h"
+#ifdef GUILDCACHE
+#include "db.h"
+#endif /* GUILDCACHE */
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
+#ifdef GUILDCACHE
+static struct dbt *guild_db_;
+static struct dbt *castle_db_;
+static struct dbt *guild_expcache_db_;
+static struct dbt *guild_infoevent_db_;
+static struct dbt *guild_castleinfoevent_db_;
+#endif /* GUILDCACHE */
+
static struct guild *guild_pt;
static struct guild *guild_pt2;
static struct guild_castle * guildcastle_pt;
@@ -285,15 +296,34 @@ int inter_guild_tosql(struct guild *g,int flag)
}
// Read guild from sql
+#ifndef GUILDCACHE
int inter_guild_fromsql(int guild_id,struct guild *g)
+#else /* GUILDCACHE */
+struct guild * inter_guild_fromsql(int guild_id)
+#endif /* GUILDCACHE */
{
int i;
char emblem_data[4096];
char *pstr;
+#ifdef GUILDCACHE
+ struct guild *g;
+
+ if (guild_id==0) return 0;
+
+ g = numdb_search(guild_db_,guild_id);
+ if (g != NULL)
+ return g;
+#endif /* GUILDCACHE */
+#ifndef GUILDCACHE
if (g==NULL) return 0;
+#else /* GUILDCACHE */
+ g = (struct guild *) malloc(sizeof(struct guild));
+#endif /* GUILDCACHE */
memset(g,0,sizeof(struct guild));
+#ifndef GUILDCACHE
if (guild_id==0) return 0;
+#endif /* not GUILDCACHE */
// printf("Retrieve guild information from sql ......\n");
// printf("- Read guild %d from sql \n",guild_id);
@@ -303,6 +333,9 @@ int inter_guild_fromsql(int guild_id,struct guild *g)
//printf(" %s\n",tmp_sql);
if(mysql_query(&mysql_handle, tmp_sql) ) {
printf("DB server Error (select `guild`)- %s\n", mysql_error(&mysql_handle) );
+#ifdef GUILDCACHE
+ free(g);
+#endif /* GUILDCACHE */
return 0;
}
@@ -311,6 +344,9 @@ int inter_guild_fromsql(int guild_id,struct guild *g)
sql_row = mysql_fetch_row(sql_res);
if (sql_row==NULL) {
mysql_free_result(sql_res);
+#ifdef GUILDCACHE
+ free(g);
+#endif /* GUILDCACHE */
return 0;
}
@@ -349,6 +385,9 @@ int inter_guild_fromsql(int guild_id,struct guild *g)
//printf(" %s\n",tmp_sql);
if(mysql_query(&mysql_handle, tmp_sql) ) {
printf("DB server Error (select `guild_member`)- %s\n", mysql_error(&mysql_handle) );
+#ifdef GUILDCACHE
+ free(g);
+#endif /* GUILDCACHE */
return 0;
}
sql_res = mysql_store_result(&mysql_handle) ;
@@ -377,6 +416,9 @@ int inter_guild_fromsql(int guild_id,struct guild *g)
//printf(" %s\n",tmp_sql);
if(mysql_query(&mysql_handle, tmp_sql) ) {
printf("DB server Error (select `guild_position`)- %s\n", mysql_error(&mysql_handle) );
+#ifdef GUILDCACHE
+ free(g);
+#endif /* GUILDCACHE */
return 0;
}
sql_res = mysql_store_result(&mysql_handle) ;
@@ -396,6 +438,9 @@ int inter_guild_fromsql(int guild_id,struct guild *g)
sprintf(tmp_sql,"SELECT `guild_id`,`opposition`,`alliance_id`,`name` FROM `%s` WHERE `guild_id`='%d'",guild_alliance_db, guild_id);
if(mysql_query(&mysql_handle, tmp_sql) ) {
printf("DB server Error (select `guild_alliance`)- %s\n", mysql_error(&mysql_handle) );
+#ifdef GUILDCACHE
+ free(g);
+#endif /* GUILDCACHE */
return 0;
}
sql_res = mysql_store_result(&mysql_handle) ;
@@ -414,6 +459,9 @@ int inter_guild_fromsql(int guild_id,struct guild *g)
sprintf(tmp_sql,"SELECT `guild_id`,`name`,`mes`,`acc`,`account_id`,`rsv1`,`rsv2`,`rsv3` FROM `%s` WHERE `guild_id`='%d'",guild_expulsion_db, guild_id);
if(mysql_query(&mysql_handle, tmp_sql) ) {
printf("DB server Error (select `guild_expulsion`)- %s\n", mysql_error(&mysql_handle) );
+#ifdef GUILDCACHE
+ free(g);
+#endif /* GUILDCACHE */
return 0;
}
sql_res = mysql_store_result(&mysql_handle) ;
@@ -438,6 +486,9 @@ int inter_guild_fromsql(int guild_id,struct guild *g)
sprintf(tmp_sql,"SELECT `guild_id`,`id`,`lv` FROM `%s` WHERE `guild_id`='%d' ORDER BY `id`",guild_skill_db, guild_id);
if(mysql_query(&mysql_handle, tmp_sql) ) {
printf("DB server Error (select `guild_skill`)- %s\n", mysql_error(&mysql_handle) );
+#ifdef GUILDCACHE
+ free(g);
+#endif /* GUILDCACHE */
return 0;
}
sql_res = mysql_store_result(&mysql_handle) ;
@@ -452,8 +503,14 @@ int inter_guild_fromsql(int guild_id,struct guild *g)
// printf("Successfully retrieve guild information from sql!\n");
+#ifndef GUILDCACHE
return 0;
+#else /* GUILDCACHE */
+ numdb_insert(guild_db_, guild_id,g);
+
+ return g;
+#endif /* GUILDCACHE */
}
// Save guild_castle to sql
@@ -588,6 +645,14 @@ int inter_guild_readdb()
int inter_guild_sql_init()
{
int i;
+
+#ifdef GUILDCACHE
+ guild_db_=numdb_init();
+ castle_db_=numdb_init();
+ guild_expcache_db_=numdb_init();
+ guild_infoevent_db_=numdb_init();
+ guild_castleinfoevent_db_=numdb_init();
+#endif /* GUILDCACHE */
printf("interserver guild memory initialize.... (%d byte)\n",sizeof(struct guild));
guild_pt = calloc(sizeof(struct guild), 1);
@@ -630,7 +695,9 @@ int inter_guild_sql_init()
// Get guild by its name
struct guild* search_guildname(char *str)
{
+#ifndef GUILDCACHE
struct guild *g=guild_pt;
+#endif /* not GUILDCACHE */
char t_name[24];
int guild_id=0;
printf("search_guildname\n");
@@ -644,8 +711,12 @@ struct guild* search_guildname(char *str)
guild_id = atoi (sql_row[0]);
}
mysql_free_result(sql_res);
+#ifndef GUILDCACHE
inter_guild_fromsql(guild_id,g);
return g;
+#else /* GUILDCACHE */
+ return inter_guild_fromsql(guild_id);
+#endif /* GUILDCACHE */
}
// Check if guild is empty
@@ -1077,9 +1148,13 @@ int mapif_parse_CreateGuild(int fd,int account_id,char *name,struct guild_member
// Return guild info to client
int mapif_parse_GuildInfo(int fd,int guild_id)
{
+#ifndef GUILDCACHE
struct guild *g;
g=guild_pt;
inter_guild_fromsql(guild_id,g);
+#else /* GUILDCACHE */
+ struct guild * g = inter_guild_fromsql(guild_id);
+#endif /* GUILDCACHE */
if(g!=NULL&&g->guild_id>0){
guild_calcinfo(g);
mapif_guild_info(fd,g);
@@ -1091,10 +1166,16 @@ 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)
{
+#ifndef GUILDCACHE
struct guild *g=guild_pt;
+#else /* GUILDCACHE */
+ struct guild *g = inter_guild_fromsql(guild_id);
+#endif /* GUILDCACHE */
int i;
+#ifndef GUILDCACHE
inter_guild_fromsql(guild_id,g);
+#endif /* not GUILDCACHE */
if(g==NULL||g->guild_id<=0){
mapif_guild_memberadded(fd,guild_id,m->account_id,m->char_id,1);
@@ -1119,9 +1200,13 @@ int mapif_parse_GuildAddMember(int fd,int guild_id,struct guild_member *m)
// Delete member from guild
int mapif_parse_GuildLeave(int fd,int guild_id,int account_id,int char_id,int flag,const char *mes)
{
+#ifndef GUILDCACHE
struct guild *g=guild_pt;
inter_guild_fromsql(guild_id,g);
+#else /* GUILDCACHE */
+ struct guild *g= inter_guild_fromsql(guild_id);
+#endif /* GUILDCACHE */
if(g!=NULL&&g->guild_id>0){
int i;
@@ -1171,25 +1256,38 @@ int mapif_parse_GuildLeave(int fd,int guild_id,int account_id,int char_id,int fl
/* mapif_guild_leaved(guild_id,account_id,char_id,flag,g->member[i].name,mes); */
}
+#ifndef GUILDCACHE
+#endif /* not GUILDCACHE */
return 0;
}
+#ifdef GUILDCACHE
+
+#endif /* GUILDCACHE */
// Change member info
int mapif_parse_GuildChangeMemberInfoShort(int fd,int guild_id,
int account_id,int char_id,int online,int lv,int class)
{
// Could speed up by manipulating only guild_member
+#ifndef GUILDCACHE
struct guild * g=guild_pt;
+#else /* GUILDCACHE */
+ struct guild * g= inter_guild_fromsql(guild_id);
+#endif /* GUILDCACHE */
int i,alv,c;
+#ifndef GUILDCACHE
+#endif /* not GUILDCACHE */
if(g==NULL||g->guild_id<=0)
return 0;
+#ifndef GUILDCACHE
inter_guild_fromsql(guild_id,g);
+#endif /* not GUILDCACHE */
g->connect_member=0;
@@ -1220,13 +1318,19 @@ int mapif_parse_GuildChangeMemberInfoShort(int fd,int guild_id,
// BreakGuild
int mapif_parse_BreakGuild(int fd,int guild_id)
{
+#ifndef GUILDCACHE
struct guild *g=guild_pt;
+#else /* GUILDCACHE */
+ struct guild *g= inter_guild_fromsql(guild_id);
+#endif /* GUILDCACHE */
if(g==NULL)
return 0;
+#ifndef GUILDCACHE
inter_guild_fromsql(guild_id,g);
+#endif /* not GUILDCACHE */
// Delete guild from sql
//printf("- Delete guild %d from guild\n",guild_id);
@@ -1290,17 +1394,25 @@ int mapif_parse_GuildMessage(int fd,int guild_id,int account_id,char *mes,int le
int mapif_parse_GuildBasicInfoChange(int fd,int guild_id,
int type,const char *data,int len)
{
+#ifndef GUILDCACHE
struct guild * g=guild_pt;
+#else /* GUILDCACHE */
+ struct guild * g = inter_guild_fromsql(guild_id);
+#endif /* GUILDCACHE */
// int dd=*((int *)data);
short dw=*((short *)data);
+#ifndef GUILDCACHE
+#endif /* not GUILDCACHE */
if(g==NULL||g->guild_id<=0)
return 0;
+#ifndef GUILDCACHE
inter_guild_fromsql(guild_id,g);
+#endif /* not GUILDCACHE */
switch(type){
case GBI_GUILDLV: {
printf("GBI_GUILDLV\n");
@@ -1327,9 +1439,15 @@ int mapif_parse_GuildMemberInfoChange(int fd,int guild_id,int account_id,int cha
{
// Could make some improvement in speed, because only change guild_member
int i;
+#ifndef GUILDCACHE
struct guild * g=guild_pt;
+#else /* GUILDCACHE */
+ struct guild * g = inter_guild_fromsql(guild_id);
+#endif /* GUILDCACHE */
+#ifndef GUILDCACHE
inter_guild_fromsql(guild_id,g);
+#endif /* not GUILDCACHE */
//printf("GuildMemberInfoChange %s \n",(type==GMI_EXP)?"GMI_EXP":"OTHER");
if(g==NULL){
@@ -1368,9 +1486,13 @@ int mapif_parse_GuildMemberInfoChange(int fd,int guild_id,int account_id,int cha
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
+#ifndef GUILDCACHE
struct guild * g=guild_pt;
inter_guild_fromsql(guild_id,g);
+#else /* GUILDCACHE */
+ struct guild * g = inter_guild_fromsql(guild_id);
+#endif /* GUILDCACHE */
if(g==NULL || idx<0 || idx>=MAX_GUILDPOSITION){
return 0;
@@ -1385,10 +1507,16 @@ int mapif_parse_GuildPosition(int fd,int guild_id,int idx,struct guild_position
int mapif_parse_GuildSkillUp(int fd,int guild_id,int skill_num,int account_id)
{
// Could make some improvement in speed, because only change guild_position
+#ifndef GUILDCACHE
struct guild *g=guild_pt;
+#else /* GUILDCACHE */
+ struct guild *g = inter_guild_fromsql(guild_id);
+#endif /* GUILDCACHE */
int idx = skill_num - GD_SKILLBASE;
+#ifndef GUILDCACHE
inter_guild_fromsql(guild_id,g);
+#endif /* not GUILDCACHE */
if(g == NULL || idx < 0 || idx >= MAX_GUILDSKILL)
return 0;
@@ -1414,10 +1542,15 @@ int mapif_parse_GuildAlliance(int fd,int guild_id1,int guild_id2,
// Could speed up
struct guild *g[2];
int j,i;
+#ifndef GUILDCACHE
g[0]=guild_pt;
g[1]=guild_pt2;
inter_guild_fromsql(guild_id1,g[0]);
inter_guild_fromsql(guild_id2,g[1]);
+#else /* GUILDCACHE */
+ g[0]= inter_guild_fromsql(guild_id1);
+ g[1]= inter_guild_fromsql(guild_id2);
+#endif /* GUILDCACHE */
if(g[0]==NULL || g[1]==NULL || g[0]->guild_id ==0 || g[1]->guild_id==0)
return 0;
@@ -1451,9 +1584,13 @@ int mapif_parse_GuildAlliance(int fd,int guild_id1,int guild_id2,
// ギルド告知変更要求
int mapif_parse_GuildNotice(int fd,int guild_id,const char *mes1,const char *mes2)
{
+#ifndef GUILDCACHE
struct guild *g=guild_pt;
inter_guild_fromsql(guild_id,g);
+#else /* GUILDCACHE */
+ struct guild *g= inter_guild_fromsql(guild_id);
+#endif /* GUILDCACHE */
if(g==NULL||g->guild_id<=0)
return 0;
@@ -1465,9 +1602,13 @@ int mapif_parse_GuildNotice(int fd,int guild_id,const char *mes1,const char *mes
// ギルドエンブレム変更要求
int mapif_parse_GuildEmblem(int fd,int len,int guild_id,int dummy,const char *data)
{
+#ifndef GUILDCACHE
struct guild * g=guild_pt;
inter_guild_fromsql(guild_id,g);
+#else /* GUILDCACHE */
+ struct guild * g= inter_guild_fromsql(guild_id);
+#endif /* GUILDCACHE */
if(g==NULL||g->guild_id<=0)
return 0;
@@ -1528,8 +1669,12 @@ int mapif_parse_GuildCastleDataSave(int fd,int castle_id,int index,int value)
case 1:
if( gc->guild_id!=value ){
int gid=(value)?value:gc->guild_id;
+#ifndef GUILDCACHE
struct guild *g=guild_pt;
inter_guild_fromsql(gid, g);
+#else /* GUILDCACHE */
+ struct guild *g=inter_guild_fromsql(gid);
+#endif /* GUILDCACHE */
if(log_inter)
inter_log("guild %s (id=%d) %s castle id=%d" RETCODE,
(g)?g->name:"??" ,gid, (value)?"occupy":"abandon", index);