summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Changelog.txt21
-rw-r--r--src/char_sql/char.c2
-rw-r--r--src/char_sql/int_guild.c54
-rw-r--r--src/common/socket.c6
-rw-r--r--src/common/socket.h1
-rw-r--r--src/map/chrif.c15
-rw-r--r--src/map/chrif.h2
-rw-r--r--src/map/map.c6
-rw-r--r--src/map/pc.c31
9 files changed, 101 insertions, 37 deletions
diff --git a/Changelog.txt b/Changelog.txt
index 9c70a25f2..bffbac0f2 100644
--- a/Changelog.txt
+++ b/Changelog.txt
@@ -1,5 +1,26 @@
Date Added
12/26
+ * @mapexit (and do_final) now persist all data to the
+ char server before exiting to eliminate storage/inventory
+ inconsistancies.. [MouseJstr] (SVN 793)
+ * Some cleanup of spiritball memory management [MouseJstr]
+ * Dramatic performance work for exp updates to sql. Previously, [MouseJstr]
+ when u killed a mob (in party share), it would cause the char_server to
+
+ 1) Delete all guilds for all members of your party
+ 2) Re-create all guilds for all members of your party with the new exp
+ values.
+
+ Now it just generates 2 sql statements per party member,
+
+ 1) update the guild exp,
+ 2) update the guild_member exp.
+
+
+ src/common/socket.c src/common/socket.h src/char_sql/char.c
+ src/char_sql/int_guild.c src/map/chrif.h src/map/pc.c
+ src/map/map.c src/map/chrif.c
+
* Disabled import charcommand_conf.txt by default [celest]
* Added Bitmap File system from jA 1086 - automatically generates a cache
from maps in the GRF to speed up loading. You can enable/disable it with
diff --git a/src/char_sql/char.c b/src/char_sql/char.c
index 7eb9a1929..82c8e2a34 100644
--- a/src/char_sql/char.c
+++ b/src/char_sql/char.c
@@ -3338,7 +3338,7 @@ int do_init(int argc, char **argv){
#undef mysql_query
int debug_mysql_query(char *file, int line, void *mysql, const char *q) {
- // printf("sql: %s:%d# %s\n", file, line, q);
+ printf("sql: %s:%d# %s\n", file, line, q);
return mysql_query((MYSQL *) mysql, q);
}
diff --git a/src/char_sql/int_guild.c b/src/char_sql/int_guild.c
index df3ec4d81..dedabfab7 100644
--- a/src/char_sql/int_guild.c
+++ b/src/char_sql/int_guild.c
@@ -1235,12 +1235,14 @@ int mapif_parse_GuildChangeMemberInfoShort(int fd,int guild_id,
{
// Could speed up by manipulating only guild_member
struct guild * g= inter_guild_fromsql(guild_id);
- int i,alv,c;
+ int i,alv,c, idx;
if(g==NULL||g->guild_id<=0)
return 0;
g->connect_member=0;
+
+ idx = -1;
for(i=0,alv=0,c=0;i<g->max_member;i++){
if( g->member[i].account_id==account_id &&
@@ -1250,6 +1252,7 @@ int mapif_parse_GuildChangeMemberInfoShort(int fd,int guild_id,
g->member[i].lv=lv;
g->member[i].class=class;
mapif_guild_memberinfoshort(g,i);
+ idx = i;
}
if( g->member[i].account_id>0 ){
alv+=g->member[i].lv;
@@ -1260,8 +1263,14 @@ int mapif_parse_GuildChangeMemberInfoShort(int fd,int guild_id,
}
// •½‹ÏƒŒƒxƒ‹
g->average_lv=alv/c;
-
- inter_guild_tosql(g,3); // Change guild & guild_member
+
+ sprintf(tmp_sql, "UPDATE `%s` SET `connect_member`=%d,`average_lv`=%d WHERE `guild_id`='%d'", guild_db, g->connect_member, g->average_lv, g->guild_id);
+ if(mysql_query(&mysql_handle, tmp_sql) )
+ printf("DB server Error: %s - %s\n", tmp_sql, mysql_error(&mysql_handle) );
+
+ sprintf(tmp_sql, "UPDATE `%s` SET `online`=%d,`lv`=%d,`class`=%d WHERE `char_id`=%d", guild_member_db, g->member[idx].online, g->member[idx].lv, g->member[idx].class, g->member[idx].char_id);
+ if(mysql_query(&mysql_handle, tmp_sql) )
+ printf("DB server Error: %s - %s\n", tmp_sql, mysql_error(&mysql_handle) );
return 0;
}
@@ -1385,21 +1394,34 @@ int mapif_parse_GuildMemberInfoChange(int fd,int guild_id,int account_id,int cha
}
switch(type){
case GMI_POSITION: // –ðE
- g->member[i].position=*((int *)data);
- break;
- case GMI_EXP: { // EXP
- int exp,oldexp=g->member[i].exp;
- exp=g->member[i].exp=*((unsigned int *)data);
- g->exp+=(exp-oldexp);
- guild_calcinfo(g); // LvƒAƒbƒv”»’f
- mapif_guild_basicinfochanged(guild_id,GBI_EXP,&g->exp,4);
- }break;
+ {
+ g->member[i].position=*((int *)data);
+ mapif_guild_memberinfochanged(guild_id,account_id,char_id,type,data,len);
+ inter_guild_tosql(g,3); // Change guild & guild_member
+ break;
+ }
+ case GMI_EXP:
+ { // EXP
+ int exp,oldexp=g->member[i].exp;
+ exp=g->member[i].exp=*((unsigned int *)data);
+ g->exp+=(exp-oldexp);
+ guild_calcinfo(g); // LvƒAƒbƒv”»’f
+ mapif_guild_basicinfochanged(guild_id,GBI_EXP,&g->exp,4);
+ mapif_guild_memberinfochanged(guild_id,account_id,char_id,type,data,len);
+
+ sprintf(tmp_sql, "UPDATE `%s` SET `guild_lv`=%d,`connect_member`=%d,`max_member`=%d,`average_lv`=%d,`exp`=%d,`next_exp`=%d,`skill_point`=%d WHERE `guild_id`='%d'", guild_db, g->guild_lv, g->connect_member, g->max_member, g->average_lv, g->exp, g->next_exp, g->skill_point, g->guild_id);
+ if(mysql_query(&mysql_handle, tmp_sql) )
+ printf("DB server Error: %s - %s\n", tmp_sql, mysql_error(&mysql_handle) );
+
+ sprintf(tmp_sql, "UPDATE `%s` SET `exp`=%d WHERE `char_id`=%d", guild_member_db, g->member[i].exp, g->member[i].char_id);
+ if(mysql_query(&mysql_handle, tmp_sql) )
+ printf("DB server Error: %s - %s\n", tmp_sql, mysql_error(&mysql_handle) );
+ break;
+ }
default:
- printf("int_guild: GuildMemberInfoChange: Unknown type %d\n",type);
- break;
+ printf("int_guild: GuildMemberInfoChange: Unknown type %d\n",type);
+ break;
}
- mapif_guild_memberinfochanged(guild_id,account_id,char_id,type,data,len);
- inter_guild_tosql(g,3); // Change guild & guild_member
return 0;
}
diff --git a/src/common/socket.c b/src/common/socket.c
index 0f5b53550..729f2fdfe 100644
--- a/src/common/socket.c
+++ b/src/common/socket.c
@@ -62,6 +62,10 @@ void set_defaultparse(int (*defaultparse)(int))
default_func_parse = defaultparse;
}
+void set_nonblocking(int fd, int yes) {
+ setsockopt(fd,IPPROTO_TCP,TCP_NODELAY,(char *)&yes,sizeof yes);
+}
+
static void setsocketopts(int fd)
{
int yes = 1; // reuse fix
@@ -70,7 +74,7 @@ static void setsocketopts(int fd)
#ifdef SO_REUSEPORT
setsockopt(fd,SOL_SOCKET,SO_REUSEPORT,(char *)&yes,sizeof yes);
#endif
- setsockopt(fd,IPPROTO_TCP,TCP_NODELAY,(char *)&yes,sizeof yes);
+ set_nonblocking(fd, yes);
setsockopt(fd, SOL_SOCKET, SO_SNDBUF, (char *) &wfifo_size , sizeof(rfifo_size ));
setsockopt(fd, SOL_SOCKET, SO_RCVBUF, (char *) &rfifo_size , sizeof(rfifo_size ));
diff --git a/src/common/socket.h b/src/common/socket.h
index 43acd6941..9b0c05013 100644
--- a/src/common/socket.h
+++ b/src/common/socket.h
@@ -91,6 +91,7 @@ int do_parsepacket(void);
void do_socket(void);
extern void flush_fifos();
+extern void set_nonblocking(int fd, int yes);
int start_console(void);
diff --git a/src/map/chrif.c b/src/map/chrif.c
index 236590ff3..353533561 100644
--- a/src/map/chrif.c
+++ b/src/map/chrif.c
@@ -943,6 +943,21 @@ int chrif_char_offline(struct map_session_data *sd)
* Tell char-server to reset all chars offline [Wizputer]
*-----------------------------------------
*/
+int chrif_flush_fifo(void) {
+ if (char_fd < 1)
+ return -1;
+
+ set_nonblocking(char_fd, 0);
+ flush_fifos();
+ set_nonblocking(char_fd, 1);
+
+ return 0;
+}
+
+/*=========================================
+ * Tell char-server to reset all chars offline [Wizputer]
+ *-----------------------------------------
+ */
int chrif_char_reset_offline(void) {
if (char_fd < 1)
return -1;
diff --git a/src/map/chrif.h b/src/map/chrif.h
index d53631e25..7f55d23d6 100644
--- a/src/map/chrif.h
+++ b/src/map/chrif.h
@@ -33,4 +33,6 @@ int check_connect_char_server(int tid, unsigned int tick, int id, int data);
int do_init_chrif(void);
+int chrif_flush_fifo(void);
+
#endif
diff --git a/src/map/map.c b/src/map/map.c
index 46705dc8d..4e7223d11 100644
--- a/src/map/map.c
+++ b/src/map/map.c
@@ -2489,7 +2489,7 @@ static int cleanup_sub(struct block_list *bl, va_list ap) {
switch(bl->type) {
case BL_PC:
- map_delblock(bl); // There is something better...
+ map_quit((struct map_session_data *) bl);
break;
case BL_NPC:
npc_delete((struct npc_data *)bl);
@@ -2522,9 +2522,13 @@ void do_final(void) {
if(map[map_id].m)
map_foreachinarea(cleanup_sub, map_id, 0, 0, map[map_id].xs, map[map_id].ys, 0, 0);
}
+
#ifndef TXT_ONLY
chrif_char_reset_offline();
#endif
+
+ chrif_flush_fifo();
+
for (i = 0; i < fd_max; i++)
delete_session(i);
diff --git a/src/map/pc.c b/src/map/pc.c
index d314d2e30..881d302c5 100644
--- a/src/map/pc.c
+++ b/src/map/pc.c
@@ -183,7 +183,6 @@ int pc_delinvincibletimer(struct map_session_data *sd) {
static int pc_spiritball_timer(int tid,unsigned int tick,int id,int data) {
struct map_session_data *sd;
- int i;
if( (sd=(struct map_session_data *)map_id2sd(id)) == NULL || sd->bl.type!=BL_PC )
return 1;
@@ -193,22 +192,24 @@ static int pc_spiritball_timer(int tid,unsigned int tick,int id,int data) {
printf("spirit_timer %d != %d\n",sd->spirit_timer[0],tid);
return 0;
}
- sd->spirit_timer[0]=-1;
- for(i=1;i<sd->spiritball;i++) {
- sd->spirit_timer[i-1] = sd->spirit_timer[i];
- sd->spirit_timer[i] = -1;
+
+ if(sd->spiritball <= 0) {
+ if(battle_config.error_log)
+ printf("Spiritballs are already 0 when pc_spiritball_timer gets called");
+ sd->spiritball = 0;
+ return 0;
}
+
sd->spiritball--;
- if(sd->spiritball < 0)
- sd->spiritball = 0;
+ memcpy( &sd->spirit_timer[0], &sd->spirit_timer[1], sizeof(sd->spirit_timer[0]) * sd->spiritball );
+ sd->spirit_timer[sd->spiritball]=-1;
+
clif_spiritball(sd);
return 0;
}
int pc_addspiritball(struct map_session_data *sd,int interval,int max) {
- int i;
-
nullpo_retr(0, sd);
if(max > MAX_SKILL_LEVEL)
@@ -217,16 +218,10 @@ int pc_addspiritball(struct map_session_data *sd,int interval,int max) {
sd->spiritball = 0;
if(sd->spiritball >= max) {
- if(sd->spirit_timer[0] != -1) {
+ if(sd->spirit_timer[0] != -1)
delete_timer(sd->spirit_timer[0],pc_spiritball_timer);
- sd->spirit_timer[0] = -1;
- }
- for(i=1;i<max;i++) {
- sd->spirit_timer[i-1] = sd->spirit_timer[i];
- sd->spirit_timer[i] = -1;
- }
- }
- else
+ memcpy( &sd->spirit_timer[0], &sd->spirit_timer[1], sizeof(sd->spirit_timer[0]) * (sd->spiritball - 1));
+ } else
sd->spiritball++;
sd->spirit_timer[sd->spiritball-1] = add_timer(gettick()+interval,pc_spiritball_timer,sd->bl.id,0);