diff options
Diffstat (limited to 'src/char_sql/int_guild.c')
-rw-r--r-- | src/char_sql/int_guild.c | 56 |
1 files changed, 19 insertions, 37 deletions
diff --git a/src/char_sql/int_guild.c b/src/char_sql/int_guild.c index 8e71935ab..2f294bade 100644 --- a/src/char_sql/int_guild.c +++ b/src/char_sql/int_guild.c @@ -528,28 +528,23 @@ static int _set_guild_castle(void *key, void *data, va_list ap) { int inter_guildcastle_tosql(struct guild_castle *gc) { struct guild_castle *gcopy; - // `guild_castle` (`castle_id`, `guild_id`, `economy`, `defense`, `triggerE`, `triggerD`, `nextTime`, `payTime`, `createTime`, `visibleC`, `visibleG0`, `visibleG1`, `visibleG2`, `visibleG3`, `visibleG4`, `visibleG5`, `visibleG6`, `visibleG7`) - if(gc == NULL || gc->castle_id < 0 ){ //gc->castle_id can be == 0 (for the 1st castle it's == 0) [Lupus] return 0; } + //printf("[Guild Castle %02i]: Save...\n",gc->castle_id); + gcopy = numdb_search(castle_db_,gc->castle_id); + if (gcopy == NULL) { + gcopy = (struct guild_castle *) aMalloc(sizeof(struct guild_castle)); + numdb_insert(castle_db_, gc->castle_id, gcopy); + } else { + //if the castle data hasn't been changed, then we don't write it into SQL + if ((gc->guild_id == gcopy->guild_id ) && ( gc->economy == gcopy->economy ) && ( gc->defense == gcopy->defense ) && ( gc->triggerE == gcopy->triggerE ) && ( gc->triggerD == gcopy->triggerD ) && ( gc->nextTime == gcopy->nextTime ) && ( gc->payTime == gcopy->payTime ) && ( gc->createTime == gcopy->createTime ) && ( gc->visibleC == gcopy->visibleC ) && ( gc->visibleG0 == gcopy->visibleG0 ) && ( gc->visibleG1 == gcopy->visibleG1 ) && ( gc->visibleG2 == gcopy->visibleG2 ) && ( gc->visibleG3 == gcopy->visibleG3 ) && ( gc->visibleG4 == gcopy->visibleG4 ) && ( gc->visibleG5 == gcopy->visibleG5 ) && ( gc->visibleG6 == gcopy->visibleG6 ) && ( gc->visibleG7 == gcopy->visibleG7 ) && ( gc->Ghp0 == gcopy->Ghp0 ) && ( gc->Ghp1 == gcopy->Ghp1 ) && ( gc->Ghp2 == gcopy->Ghp2 ) && ( gc->Ghp3 == gcopy->Ghp3 ) && ( gc->Ghp4 == gcopy->Ghp4 ) && ( gc->Ghp5 == gcopy->Ghp5 ) && ( gc->Ghp6 == gcopy->Ghp6 ) && ( gc->Ghp7 == gcopy->Ghp7 )) + return 0; + } + //printf("[Guild Castle %02i]: Save... ->SQL\n",gc->castle_id); + memcpy(gcopy, gc, sizeof(struct guild_castle)); - if( gc->guild_id > 0) { //we just update the castle - printf("[Guild Castle %02i]: Save...\n",gc->castle_id); - - gcopy = numdb_search(castle_db_,gc->castle_id); - if (gcopy == NULL) { - gcopy = (struct guild_castle *) aMalloc(sizeof(struct guild_castle)); - numdb_insert(castle_db_, gc->castle_id, gcopy); - } else { - //if the castle data hasn't been changed, then we don't write it into SQL - if ((gc->guild_id == gcopy->guild_id ) && ( gc->economy == gcopy->economy ) && ( gc->defense == gcopy->defense ) && ( gc->triggerE == gcopy->triggerE ) && ( gc->triggerD == gcopy->triggerD ) && ( gc->nextTime == gcopy->nextTime ) && ( gc->payTime == gcopy->payTime ) && ( gc->createTime == gcopy->createTime ) && ( gc->visibleC == gcopy->visibleC ) && ( gc->visibleG0 == gcopy->visibleG0 ) && ( gc->visibleG1 == gcopy->visibleG1 ) && ( gc->visibleG2 == gcopy->visibleG2 ) && ( gc->visibleG3 == gcopy->visibleG3 ) && ( gc->visibleG4 == gcopy->visibleG4 ) && ( gc->visibleG5 == gcopy->visibleG5 ) && ( gc->visibleG6 == gcopy->visibleG6 ) && ( gc->visibleG7 == gcopy->visibleG7 ) && ( gc->Ghp0 == gcopy->Ghp0 ) && ( gc->Ghp1 == gcopy->Ghp1 ) && ( gc->Ghp2 == gcopy->Ghp2 ) && ( gc->Ghp3 == gcopy->Ghp3 ) && ( gc->Ghp4 == gcopy->Ghp4 ) && ( gc->Ghp5 == gcopy->Ghp5 ) && ( gc->Ghp6 == gcopy->Ghp6 ) && ( gc->Ghp7 == gcopy->Ghp7 )) - return 0; - } - printf("[Guild Castle %02i]: Save... ->SQL\n",gc->castle_id); - memcpy(gcopy, gc, sizeof(struct guild_castle)); - - sprintf(tmp_sql,"REPLACE INTO `%s` " + sprintf(tmp_sql,"REPLACE INTO `%s` " "(`castle_id`, `guild_id`, `economy`, `defense`, `triggerE`, `triggerD`, `nextTime`, `payTime`, `createTime`," "`visibleC`, `visibleG0`, `visibleG1`, `visibleG2`, `visibleG3`, `visibleG4`, `visibleG5`, `visibleG6`, `visibleG7`," "`Ghp0`, `Ghp1`, `Ghp2`, `Ghp3`, `Ghp4`, `Ghp5`, `Ghp6`, `Ghp7`)" @@ -558,26 +553,13 @@ int inter_guildcastle_tosql(struct guild_castle *gc) gc->createTime, gc->visibleC, gc->visibleG0, gc->visibleG1, gc->visibleG2, gc->visibleG3, gc->visibleG4, gc->visibleG5, gc->visibleG6, gc->visibleG7, gc->Ghp0, gc->Ghp1, gc->Ghp2, gc->Ghp3, gc->Ghp4, gc->Ghp5, gc->Ghp6, gc->Ghp7); - //printf(" %s\n",tmp_sql); - if(mysql_query(&mysql_handle, tmp_sql) ) { - printf("DB server Error - %s\n", mysql_error(&mysql_handle) ); - return 0; - } - } else { - sprintf(tmp_sql,"UPDATE `%s` SET `castle_id`='-1' WHERE `castle_id`='%d'",guild_db, gc->castle_id); - //printf(" %s\n",tmp_sql); - if(mysql_query(&mysql_handle, tmp_sql) ) { - printf("DB server Error - %s\n", mysql_error(&mysql_handle) ); - return 0; - } - - sprintf(tmp_sql,"UPDATE `%s` SET `castle_id`='%d' WHERE `guild_id`='%d'",guild_db, gc->castle_id,gc->guild_id); - //printf(" %s\n",tmp_sql); - if(mysql_query(&mysql_handle, tmp_sql) ) { - printf("DB server Error - %s\n", mysql_error(&mysql_handle) ); - return 0; - } + //printf(" %s\n",tmp_sql); + + if(mysql_query(&mysql_handle, tmp_sql) ) { + printf("DB server Error - %s\n", mysql_error(&mysql_handle) ); + return 0; } + db_foreach(guild_db_, _set_guild_castle, gc->castle_id,gc->guild_id); return 0; |