summaryrefslogtreecommitdiff
path: root/src/char_sql
diff options
context:
space:
mode:
Diffstat (limited to 'src/char_sql')
-rw-r--r--src/char_sql/char.c140
-rw-r--r--src/char_sql/char.h26
-rw-r--r--src/char_sql/int_guild.c75
-rw-r--r--src/char_sql/int_guild.h21
-rw-r--r--src/char_sql/int_party.c73
-rw-r--r--src/char_sql/int_party.h20
-rw-r--r--src/char_sql/int_pet.c4
-rw-r--r--src/char_sql/int_pet.h6
-rw-r--r--src/char_sql/int_storage.c9
-rw-r--r--src/char_sql/int_storage.h10
-rw-r--r--src/char_sql/inter.c43
-rw-r--r--src/char_sql/inter.h9
12 files changed, 225 insertions, 211 deletions
diff --git a/src/char_sql/char.c b/src/char_sql/char.c
index df1ed6b2e..affdd3a62 100644
--- a/src/char_sql/char.c
+++ b/src/char_sql/char.c
@@ -33,8 +33,9 @@
#include "malloc.h"
#include "int_guild.h"
+#ifndef TXT_SQL_CONVERT
static struct dbt *char_db_;
-
+#endif
char char_db[256] = "char";
char scdata_db[256] = "sc_data";
char cart_db[256] = "cart_inventory";
@@ -57,6 +58,10 @@ char party_db[256] = "party";
char pet_db[256] = "pet";
char gm_db[256] = "gm_accounts";
char friend_db[256] = "friends";
+#ifdef TXT_SQL_CONVERT
+int save_log = 0; //Have the logs be off by default when converting
+#else
+int save_log = 1;
int db_use_sqldbs;
int connection_ping_interval = 0;
@@ -67,7 +72,13 @@ int lowest_gm_level = 1;
char *SQL_CONF_NAME = "conf/inter_athena.conf";
-struct mmo_map_server server[MAX_MAP_SERVERS];
+struct mmo_map_server{
+ long ip;
+ short port;
+ int users;
+ unsigned short map[MAX_MAP_PER_SERVER];
+} server[MAX_MAP_SERVERS];
+
int server_fd[MAX_MAP_SERVERS];
int login_fd, char_fd;
@@ -135,7 +146,6 @@ int char_num,char_max;
int max_connect_user = 0;
int gm_allow_level = 99;
int autosave_interval = DEFAULT_AUTOSAVE_INTERVAL;
-int save_log = 1;
int start_zeny = 0;
int start_weapon = 1201;
int start_armor = 2301;
@@ -385,7 +395,7 @@ void read_gm_account(void) {
mysql_free_result(lsql_res);
mapif_send_gmaccounts();
}
-
+#endif //TXT_SQL_CONVERT
int compare_item(struct item *a, struct item *b) {
if(a->id == b->id &&
@@ -403,13 +413,14 @@ int compare_item(struct item *a, struct item *b) {
return 0;
}
+#ifndef TXT_SQL_CONVERT
static void* create_charstatus(DBKey key, va_list args) {
struct mmo_charstatus *cp;
cp = (struct mmo_charstatus *) aCalloc(1,sizeof(struct mmo_charstatus));
cp->char_id = key.i;
return cp;
}
-
+#endif //TXT_SQL_CONVERT
int mmo_char_tosql(int char_id, struct mmo_charstatus *p){
int i=0,j;
int count = 0;
@@ -422,7 +433,11 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus *p){
if (char_id!=p->char_id) return 0;
+#ifndef TXT_SQL_CONVERT
cp = idb_ensure(char_db_, char_id, create_charstatus);
+#else
+ cp = aCalloc(1, sizeof(struct mmo_charstatus));
+#endif
memset(save_status, 0, sizeof(save_status));
diff = 0;
@@ -474,6 +489,17 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus *p){
if (diff)
if (!memitemdata_to_sql(mapitem, count, p->char_id,TABLE_CART))
strcat(save_status, " cart");
+#ifdef TXT_SQL_CONVERT
+ //Insert the barebones to then update the rest.
+ sprintf(tmp_sql, "REPLACE INTO `%s` (`account_id`, `char_num`, `name`) VALUES ('%d', '%d', '%s')",
+ char_db, p->account_id, p->char_num, p->name);
+ if(mysql_query(&mysql_handle, tmp_sql))
+ {
+ ShowSQL("DB error - %s\n",mysql_error(&mysql_handle));
+ ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
+ } else
+ strcat(save_status, " creation");
+#endif
if (
(p->base_exp != cp->base_exp) || (p->base_level != cp->base_level) ||
@@ -640,71 +666,6 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus *p){
} else //Skills removed (reset?)
strcat(save_status, " skills");
}
-/* Saving of global registry values is now handled by the inter-server. [Skotlex]
- diff = 0;
- for(i=0;i<p->global_reg_num;i++) {
- if ((p->global_reg[i].str == NULL) && (cp->global_reg[i].str == NULL))
- continue;
- if (((p->global_reg[i].str == NULL) != (cp->global_reg[i].str == NULL)) ||
- strcmp(p->global_reg[i].value, cp->global_reg[i].value) != 0 ||
- strcmp(p->global_reg[i].str, cp->global_reg[i].str) != 0
- ) {
- diff = 1;
- break;
- }
- }
-
- if (diff)
- { //Save global registry.
- //`global_reg_value` (`char_id`, `str`, `value`)
-
- sprintf(tmp_sql,"DELETE FROM `%s` WHERE `type`=3 AND `char_id`='%d'",reg_db, p->char_id);
- if (mysql_query(&mysql_handle, tmp_sql))
- {
- ShowSQL("DB error - %s\n",mysql_error(&mysql_handle));
- ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
- }
-
- //insert here.
- tmp_ptr = tmp_sql;
- tmp_ptr += sprintf(tmp_ptr,"INSERT INTO `%s` (`type`, `char_id`, `str`, `value`) VALUES", reg_db);
- count = 0;
- for(i=0;i<p->global_reg_num;i++)
- {
- if (p->global_reg[i].str && p->global_reg[i].value)
- {
- tmp_ptr += sprintf(tmp_ptr,"('3','%d','%s','%s'),",
- char_id, jstrescapecpy(temp_str,p->global_reg[i].str), jstrescapecpy(temp_str2,p->global_reg[i].value));
- if (++count%100 == 0)
- { //Save every X registers to avoid overflowing tmp_sql [Skotlex]
- tmp_ptr[-1] = '\0';
- if(mysql_query(&mysql_handle, tmp_sql))
- {
- ShowSQL("DB error - %s\n",mysql_error(&mysql_handle));
- ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
- } else
- strcat(save_status, " global_reg");
-
- tmp_ptr = tmp_sql;
- tmp_ptr += sprintf(tmp_ptr,"INSERT INTO `%s` (`type`, `char_id`, `str`, `value`) VALUES", reg_db);
- count = 0;
- }
- }
- }
-
- if (count)
- {
- tmp_ptr[-1] = '\0';
- if(mysql_query(&mysql_handle, tmp_sql))
- {
- ShowSQL("DB error - %s\n",mysql_error(&mysql_handle));
- ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
- } else
- strcat(save_status, " global_reg");
- } else //Values cleared.
- strcat(save_status, " global_reg");
- }
-*/
diff = 0;
for(i = 0; i < MAX_FRIENDS; i++){
if(p->friends[i].char_id != cp->friends[i].char_id ||
@@ -748,8 +709,11 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus *p){
if (save_status[0]!='\0' && save_log)
ShowInfo("Saved char %d - %s:%s.\n", char_id, p->name, save_status);
+#ifndef TXT_SQL_CONVERT
memcpy(cp, p, sizeof(struct mmo_charstatus));
-
+#else
+ aFree(cp);
+#endif
return 0;
}
@@ -820,6 +784,7 @@ int memitemdata_to_sql(struct itemtmp mapitem[], int count, int char_id, int tab
{ //Do nothing.
} else
//==============================================Memory data > SQL ===============================
+#ifndef TXT_SQL_CONVERT
if(!itemdb_isequip(mapitem[i].nameid))
{ //Quick update of stackable items. Update Qty and Equip should be enough, but in case we are also updating identify
sprintf(tmp_sql,"UPDATE `%s` SET `equip`='%d', `identify`='%d', `amount`='%d' WHERE `id`='%d' LIMIT 1",
@@ -830,6 +795,7 @@ int memitemdata_to_sql(struct itemtmp mapitem[], int count, int char_id, int tab
ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
}
} else
+#endif //TXT_SQL_CONVERT
{ //Equipment or Misc item, just update all fields.
str_p = tmp_sql;
str_p += sprintf(str_p,"UPDATE `%s` SET `equip`='%d', `identify`='%d', `refine`='%d',`attribute`='%d'",
@@ -888,7 +854,7 @@ int memitemdata_to_sql(struct itemtmp mapitem[], int count, int char_id, int tab
}
return 0;
}
-
+#ifndef TXT_SQL_CONVERT
//=====================================================================================================
int mmo_char_fromsql(int char_id, struct mmo_charstatus *p){
int i,j, n;
@@ -1690,19 +1656,6 @@ int delete_char_sql(int char_id, int partner_id)
//==========================================================================================================
-void mmo_char_sync(void)
-{
- ShowWarning("mmo_char_sync() - nothing to do\n");
-}
-
-// to do
-///////////////////////////
-
-int mmo_char_sync_timer(int tid, unsigned int tick, int id, int data) {
- ShowWarning("mmo_char_sync_timer() tic - no works to do\n");
- return 0;
-}
-
int count_users(void) {
int i, users;
@@ -3918,7 +3871,6 @@ int char_lan_config_read(const char *lancfgName) {
void do_final(void) {
ShowInfo("Doing final stage...\n");
- //mmo_char_sync();
//inter_save();
do_final_itemdb();
//check SQL save progress.
@@ -3956,7 +3908,7 @@ void do_final(void) {
ShowInfo("ok! all done...\n");
}
-
+#endif //TXT_SQL_CONVERT
void sql_config_read(const char *cfgName){ /* Kalaspuff, to get login_db */
char line[1024], w1[1024], w2[1024];
FILE *fp;
@@ -3975,15 +3927,17 @@ void sql_config_read(const char *cfgName){ /* Kalaspuff, to get login_db */
if (sscanf(line, "%[^:]: %[^\r\n]", w1, w2) != 2)
continue;
- if(strcmpi(w1, "gm_read_method") == 0) {
+ if(strcmpi(w1,"char_db")==0){
+ strcpy(char_db,w2);
+#ifndef TXT_SQL_CONVERT
+ } else if(strcmpi(w1, "gm_read_method") == 0) {
if(atoi(w2) != 0)
char_gm_read = true;
else
char_gm_read = false;
} else if(strcmpi(w1, "gm_db") == 0) {
strcpy(gm_db, w2);
- } else if(strcmpi(w1,"char_db")==0){
- strcpy(char_db,w2);
+#endif
}else if(strcmpi(w1,"scdata_db")==0){
strcpy(scdata_db,w2);
}else if(strcmpi(w1,"cart_db")==0){
@@ -4024,6 +3978,7 @@ void sql_config_read(const char *cfgName){ /* Kalaspuff, to get login_db */
strcpy(pet_db,w2);
}else if(strcmpi(w1,"friend_db")==0){
strcpy(friend_db,w2);
+#ifndef TXT_SQL_CONVERT
}else if(strcmpi(w1,"db_path")==0){
strcpy(db_path,w2);
//Map server option to use SQL db or not
@@ -4045,6 +4000,7 @@ void sql_config_read(const char *cfgName){ /* Kalaspuff, to get login_db */
lowest_gm_level = atoi(w2);
ShowStatus("set lowest_gm_level : %s\n",w2);
//support the import command, just like any other config
+#endif
}else if(strcmpi(w1,"import")==0){
sql_config_read(w2);
}
@@ -4053,6 +4009,7 @@ void sql_config_read(const char *cfgName){ /* Kalaspuff, to get login_db */
fclose(fp);
ShowInfo("done reading %s.\n", cfgName);
}
+#ifndef TXT_SQL_CONVERT
int char_config_read(const char *cfgName) {
char line[1024], w1[1024], w2[1024];
@@ -4263,7 +4220,7 @@ int do_init(int argc, char **argv){
ShowInfo("Finished reading the char-server configuration.\n");
- inter_init((argc > 2) ? argv[2] : inter_cfgName); // inter server ʱȭ
+ inter_init_sql((argc > 2) ? argv[2] : inter_cfgName); // inter server ʱȭ
ShowInfo("Finished reading the inter-server configuration.\n");
//Read ItemDB
@@ -4453,3 +4410,4 @@ int char_family(int pl1,int pl2,int pl3) {
mysql_free_result (sql_res);
return 0;
}
+#endif //TXT_SQL_CONVERT
diff --git a/src/char_sql/char.h b/src/char_sql/char.h
index 343d04b4e..70d8e3b13 100644
--- a/src/char_sql/char.h
+++ b/src/char_sql/char.h
@@ -1,5 +1,7 @@
// Copyright (c) Athena Dev Teams - Licensed under GNU GPL
// For more information, see LICENCE in the main folder
+#ifndef _CHARSQL_H_
+#define _CHARSQL_H_
#include "../common/core.h"
#include "../common/socket.h"
@@ -9,8 +11,12 @@
#include "../common/db.h"
#include "../common/mapindex.h"
-#ifndef _CHAR_H_
-#define _CHAR_H_
+#include "inter.h"
+#include "int_pet.h"
+#include "int_guild.h"
+#include "int_party.h"
+#include "int_storage.h"
+#include "itemdb.h"
#define START_CHAR_NUM 150000
#define MAX_MAP_SERVERS 30
@@ -19,12 +25,6 @@
#define DEFAULT_AUTOSAVE_INTERVAL 300*1000
-struct mmo_map_server{
- long ip;
- short port;
- int users;
- unsigned short map[MAX_MAP_PER_SERVER];
-};
struct itemtmp {
int flag;//checked = 1 else 0
int id;
@@ -100,13 +100,11 @@ extern int GM_num;
extern struct gm_account *gm_account;
extern int guild_exp_rate;
+extern int log_inter;
extern int debug_mysql_query(char *file, int line, void *mysql, const char *q);
+//Exported for use in the TXT-SQL converter.
+int mmo_char_tosql(int char_id, struct mmo_charstatus *p);
+void sql_config_read(const char *cfgName);
#endif
-
-#include "inter.h"
-#include "int_pet.h"
-#include "int_guild.h"
-#include "int_party.h"
-#include "int_storage.h"
diff --git a/src/char_sql/int_guild.c b/src/char_sql/int_guild.c
index af302346b..8f9e50acf 100644
--- a/src/char_sql/int_guild.c
+++ b/src/char_sql/int_guild.c
@@ -20,27 +20,6 @@
#include "db.h"
#include "malloc.h"
-//Guild cache
-static struct dbt *guild_db_;
-
-struct guild_castle castles[MAX_GUILDCASTLE];
-
-static unsigned int guild_exp[100];
-
-#define GS_BASIC 0x0001
-#define GS_MEMBER 0x0002
-#define GS_POSITION 0x0004
-#define GS_ALLIANCE 0x0008
-#define GS_EXPULSION 0x0010
-#define GS_SKILL 0x0020
-#define GS_EMBLEM 0x0040
-#define GS_CONNECT 0x0080
-#define GS_LEVEL 0x0100
-#define GS_MES 0x0200
-#define GS_MASK 0x03FF
-#define GS_BASIC_MASK (GS_BASIC | GS_EMBLEM | GS_CONNECT | GS_LEVEL | GS_MES)
-#define GS_REMOVE 0x8000
-
#define GS_MEMBER_UNMODIFIED 0x00
#define GS_MEMBER_MODIFIED 0x01
#define GS_MEMBER_NEW 0x02
@@ -52,6 +31,16 @@ static unsigned int guild_exp[100];
#define GUILD_ALLIANCE_TYPE_MASK 0x01
#define GUILD_ALLIANCE_REMOVE 0x08
+static char dataToHex[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
+
+#ifndef TXT_SQL_CONVERT
+//Guild cache
+static struct dbt *guild_db_;
+
+struct guild_castle castles[MAX_GUILDCASTLE];
+
+static unsigned int guild_exp[100];
+
int mapif_parse_GuildLeave(int fd,int guild_id,int account_id,int char_id,int flag,const char *mes);
int mapif_guild_broken(int guild_id,int flag);
int guild_check_empty(struct guild *g);
@@ -60,7 +49,6 @@ int mapif_guild_basicinfochanged(int guild_id,int type,const void *data,int len)
int mapif_guild_info(int fd,struct guild *g);
int guild_break_sub(int key,void *data,va_list ap);
int inter_guild_tosql(struct guild *g,int flag);
-static char dataToHex[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
#define mysql_query(_x, _y) debug_mysql_query(__FILE__, __LINE__, _x, _y)
@@ -119,7 +107,7 @@ int inter_guild_removemember_tosql(int account_id, int char_id)
}
return 0;
}
-
+#endif //TXT_SQL_CONVERT
// Save guild into sql
int inter_guild_tosql(struct guild *g,int flag)
{
@@ -162,6 +150,7 @@ int inter_guild_tosql(struct guild *g,int flag)
t_info[0]='\0';
+#ifndef TXT_SQL_CONVERT
// Insert a new guild the guild
if (flag&GS_BASIC && g->guild_id == -1)
{
@@ -191,7 +180,31 @@ int inter_guild_tosql(struct guild *g,int flag)
return 0; //Failed to get ID??
}
}
-
+#else
+ // Insert a new guild the guild
+ if (flag&GS_BASIC)
+ {
+ strcat(t_info, " guild_create");
+ // Since the PK is guild id + master id, a replace will not be enough if we are overwriting data, we need to wipe the previous guild.
+ sprintf(tmp_sql,"DELETE FROM `%s` where `guild_id` = '%d'", guild_db,g->guild_id);
+ if(mysql_query(&mysql_handle, tmp_sql) )
+ {
+ ShowSQL("DB error - %s\n",mysql_error(&mysql_handle));
+ ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
+ }
+ // Create a new guild
+ sprintf(tmp_sql,"REPLACE INTO `%s` "
+ "(`guild_id`,`name`,`master`,`guild_lv`,`max_member`,`average_lv`,`char_id`) "
+ "VALUES ('%d', '%s', '%s', '%d', '%d', '%d', '%d')",
+ guild_db,g->guild_id,t_name,jstrescapecpy(t_master,g->master),g->guild_lv,g->max_member,g->average_lv,g->member[0].char_id);
+ if(mysql_query(&mysql_handle, tmp_sql) )
+ {
+ ShowSQL("DB error - %s\n",mysql_error(&mysql_handle));
+ ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
+ return 0; //Failed to create guild.
+ }
+ }
+#endif //TXT_SQL_CONVERT
// If we need an update on an existing guild or more update on the new guild
if (((flag & GS_BASIC_MASK) && !new_guild) || ((flag & (GS_BASIC_MASK & ~GS_BASIC)) && new_guild))
{
@@ -244,8 +257,10 @@ int inter_guild_tosql(struct guild *g,int flag)
// Update only needed players
for(i=0;i<g->max_member;i++){
m = &g->member[i];
+#ifndef TXT_SQL_CONVERT
if (!m->modified)
continue;
+#endif
if(m->account_id) {
//Since nothing references guild member table as foreign keys, it's safe to use REPLACE INTO
sprintf(tmp_sql,"REPLACE INTO `%s` (`guild_id`,`account_id`,`char_id`,`hair`,`hair_color`,`gender`,`class`,`lv`,`exp`,`exp_payper`,`online`,`position`,`name`) "
@@ -279,8 +294,10 @@ int inter_guild_tosql(struct guild *g,int flag)
//printf("- Insert guild %d to guild_position\n",g->guild_id);
for(i=0;i<MAX_GUILDPOSITION;i++){
struct guild_position *p = &g->position[i];
+#ifndef TXT_SQL_CONVERT
if (!p->modified)
continue;
+#endif
sprintf(tmp_sql,"REPLACE INTO `%s` (`guild_id`,`position`,`name`,`mode`,`exp_mode`) VALUES ('%d','%d', '%s','%d','%d')",
guild_position_db, g->guild_id, i, jstrescapecpy(t_position,p->name),p->mode,p->exp_mode);
//printf(" %s\n",tmp_sql);
@@ -366,7 +383,7 @@ int inter_guild_tosql(struct guild *g,int flag)
ShowInfo("Saved guild (%d - %s):%s\n",g->guild_id,g->name,t_info);
return 1;
}
-
+#ifndef TXT_SQL_CONVERT
// Read guild from sql
struct guild * inter_guild_fromsql(int guild_id)
{
@@ -582,6 +599,7 @@ struct guild * inter_guild_fromsql(int guild_id)
return g;
}
+#endif //TXT_SQL_CONVERT
int inter_guildcastle_tosql(struct guild_castle *gc){
// `guild_castle` (`castle_id`, `guild_id`, `economy`, `defense`, `triggerE`, `triggerD`, `nextTime`, `payTime`, `createTime`, `visibleC`, `visibleG0`, `visibleG1`, `visibleG2`, `visibleG3`, `visibleG4`, `visibleG5`, `visibleG6`, `visibleG7`)
@@ -607,12 +625,12 @@ ShowDebug("Save guild_castle (%d)\n", gc->castle_id);
ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
}
-
+#ifndef TXT_SQL_CONVERT
memcpy(&castles[gc->castle_id],gc,sizeof(struct guild_castle));
-
+#endif //TXT_SQL_CONVERT
return 0;
}
-
+#ifndef TXT_SQL_CONVERT
// Read guild_castle from sql
int inter_guildcastle_fromsql(int castle_id,struct guild_castle *gc)
@@ -2083,3 +2101,4 @@ int inter_guild_broken(int guild_id)
{
return mapif_guild_broken(guild_id, 0);
}
+#endif //TXT_SQL_CONVERT
diff --git a/src/char_sql/int_guild.h b/src/char_sql/int_guild.h
index 6faf4e2b1..88836a2a1 100644
--- a/src/char_sql/int_guild.h
+++ b/src/char_sql/int_guild.h
@@ -1,8 +1,8 @@
// Copyright (c) Athena Dev Teams - Licensed under GNU GPL
// For more information, see LICENCE in the main folder
-#ifndef _INT_GUILD_H_
-#define _INT_GUILD_H_
+#ifndef _INT_GUILD_SQL_H_
+#define _INT_GUILD_SQL_H_
int inter_guild_parse_frommap(int fd);
int inter_guild_sql_init(void);
@@ -15,4 +15,21 @@ int inter_guild_sex_changed(int guild_id,int account_id,int char_id, int gender)
int inter_guild_CharOnline(int char_id, int guild_id);
int inter_guild_CharOffline(int char_id, int guild_id);
+#define GS_BASIC 0x0001
+#define GS_MEMBER 0x0002
+#define GS_POSITION 0x0004
+#define GS_ALLIANCE 0x0008
+#define GS_EXPULSION 0x0010
+#define GS_SKILL 0x0020
+#define GS_EMBLEM 0x0040
+#define GS_CONNECT 0x0080
+#define GS_LEVEL 0x0100
+#define GS_MES 0x0200
+#define GS_MASK 0x03FF
+#define GS_BASIC_MASK (GS_BASIC | GS_EMBLEM | GS_CONNECT | GS_LEVEL | GS_MES)
+#define GS_REMOVE 0x8000
+
+//For the TXT->SQL converter.
+int inter_guild_tosql(struct guild *g,int flag);
+int inter_guildcastle_tosql(struct guild_castle *gc);
#endif
diff --git a/src/char_sql/int_party.c b/src/char_sql/int_party.c
index 897a110d6..fe46ac9c6 100644
--- a/src/char_sql/int_party.c
+++ b/src/char_sql/int_party.c
@@ -14,6 +14,7 @@
#include "../common/socket.h"
#include "../common/showmsg.h"
+#ifndef TXT_SQL_CONVERT
struct party_data {
struct party party;
unsigned int min_lv, max_lv;
@@ -40,20 +41,6 @@ int mapif_party_optionchanged(int fd,struct party *p, int account_id, int flag);
#endif
-//Party Flags on what to save/delete.
-//Create a new party entry (index holds leader's info)
-#define PS_CREATE 0x01
-//Update basic party info.
-#define PS_BASIC 0x02
-//Update party's leader
-#define PS_LEADER 0x04
-//Specify new party member (index specifies which party member)
-#define PS_ADDMEMBER 0x08
-//Specify member that left (index specifies which party member)
-#define PS_DELMEMBER 0x10
-//Specify that this party must be deleted.
-#define PS_BREAK 0x20
-
//Updates party's level range and unsets even share if broken.
static int int_party_check_lv(struct party_data *p) {
int i;
@@ -114,17 +101,15 @@ static void int_party_calc_state(struct party_data *p)
}
return;
}
-
+#endif //TXT_SQL_CONVERT
// Save party to mysql
-int inter_party_tosql(struct party_data *party, int flag, int index)
+int inter_party_tosql(struct party *p, int flag, int index)
{
// 'party' ('party_id','name','exp','item','leader_id','leader_char')
char t_name[NAME_LENGTH*2]; //Required for jstrescapecpy [Skotlex]
- struct party *p;
int party_id;
- if (party == NULL || party->party.party_id == 0)
+ if (p == NULL || p->party_id == 0)
return 0;
- p = &party->party;
party_id = p->party_id;
#ifdef NOISY
@@ -132,6 +117,7 @@ int inter_party_tosql(struct party_data *party, int flag, int index)
#endif
jstrescapecpy(t_name, p->name);
+#ifndef TXT_SQL_CONVERT
if (flag&PS_BREAK) { //Break the party
// we'll skip name-checking and just reset everyone with the same party id [celest]
sprintf (tmp_sql, "UPDATE `%s` SET `party_id`='0' WHERE `party_id`='%d'", char_db, party_id);
@@ -148,8 +134,9 @@ int inter_party_tosql(struct party_data *party, int flag, int index)
idb_remove(party_db_, party_id);
return 1;
}
-
+#endif //TXT_SQL_CONVERT
if(flag&PS_CREATE) { //Create party
+#ifndef TXT_SQL_CONVERT
sprintf(tmp_sql, "INSERT INTO `%s` "
"(`name`, `exp`, `item`, `leader_id`, `leader_char`) "
"VALUES ('%s', '%d', '%d', '%d', '%d')",
@@ -157,21 +144,29 @@ int inter_party_tosql(struct party_data *party, int flag, int index)
if (mysql_query(&mysql_handle, tmp_sql)) {
ShowSQL("DB error - %s\n",mysql_error(&mysql_handle));
ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
- aFree(party); //Free party, couldn't create it.
return 0;
}
if(mysql_field_count(&mysql_handle) == 0 &&
mysql_insert_id(&mysql_handle) != 0)
party_id = p->party_id = (int)mysql_insert_id(&mysql_handle);
- else { //Failed to retrieve ID??
- aFree(party); //Free party, couldn't create it.
+ else //Failed to retrieve ID??
+ return 0;
+#else
+ //During conversion, you want to specify the id, and allow overwriting
+ //(in case someone is re-running the process.
+ sprintf(tmp_sql, "REPLACE INTO `%s` "
+ "(`party_id`, `name`, `exp`, `item`, `leader_id`, `leader_char`) "
+ "VALUES ('%d', '%s', '%d', '%d', '%d', '%d')",
+ party_db, p->party_id, t_name, p->exp, p->item, p->member[index].account_id, p->member[index].char_id);
+ if (mysql_query(&mysql_handle, tmp_sql)) {
+ ShowSQL("DB error - %s\n",mysql_error(&mysql_handle));
+ ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
return 0;
}
- //Add party to db
- int_party_calc_state(party);
- idb_put(party_db_, party_id, party);
+#endif
}
+#ifndef TXT_SQL_CONVERT
if (flag&PS_BASIC) {
//Update party info.
sprintf(tmp_sql, "UPDATE `%s` SET `name`='%s', `exp`='%d', `item`='%d' WHERE `party_id`='%d'",
@@ -211,12 +206,12 @@ int inter_party_tosql(struct party_data *party, int flag, int index)
ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
}
}
-
+#endif //TXT_SQL_CONVERT
if (save_log)
ShowInfo("Party Saved (%d - %s)\n", party_id, p->name);
return 1;
}
-
+#ifndef TXT_SQL_CONVERT
// Read party from mysql
struct party_data *inter_party_fromsql(int party_id)
{
@@ -365,7 +360,7 @@ int party_check_empty(struct party_data *p)
if (i < MAX_PARTY) return 0;
// If there is no member, then break the party
mapif_party_broken(p->party.party_id,0);
- inter_party_tosql(p, PS_BREAK, 0);
+ inter_party_tosql(&p->party, PS_BREAK, 0);
return 1;
}
@@ -577,11 +572,16 @@ int mapif_parse_CreateParty(int fd, char *name, int item, int item2, struct part
p->party.member[0].online=1;
p->party.party_id=-1;//New party.
- if (inter_party_tosql(p,PS_CREATE|PS_ADDMEMBER,0)) {
+ if (inter_party_tosql(&p->party,PS_CREATE|PS_ADDMEMBER,0)) {
+ //Add party to db
+ int_party_calc_state(p);
+ idb_put(party_db_, p->party.party_id, p);
mapif_party_created(fd,leader->account_id,leader->char_id,&p->party);
mapif_party_info(fd,&p->party);
- } else //Failed to create party.
+ } else { //Failed to create party.
+ aFree(p);
mapif_party_created(fd,leader->account_id,leader->char_id,NULL);
+ }
return 0;
}
@@ -627,7 +627,7 @@ int mapif_parse_PartyAddMember(int fd, int party_id, struct party_member *member
mapif_party_memberadded(fd,party_id,member->account_id,member->char_id,0);
mapif_party_info(-1,&p->party);
- inter_party_tosql(p, PS_ADDMEMBER, i);
+ inter_party_tosql(&p->party, PS_ADDMEMBER, i);
return 0;
}
//Party full
@@ -651,7 +651,7 @@ int mapif_parse_PartyChangeOption(int fd,int party_id,int account_id,int exp,int
}
p->party.item = item&0x3; //Filter out invalid values.
mapif_party_optionchanged(fd,&p->party,account_id,flag);
- inter_party_tosql(p, PS_BASIC, 0);
+ inter_party_tosql(&p->party, PS_BASIC, 0);
return 0;
}
// p[eBEޗv
@@ -691,7 +691,7 @@ int mapif_parse_PartyLeave(int fd, int party_id, int account_id, int char_id)
}
//Party gets deleted on the check_empty call below.
} else {
- inter_party_tosql(p,PS_DELMEMBER,i);
+ inter_party_tosql(&p->party,PS_DELMEMBER,i);
j = p->party.member[i].lv;
if(p->party.member[i].online) p->party.count--;
memset(&p->party.member[i], 0, sizeof(struct party_member));
@@ -765,7 +765,7 @@ int mapif_parse_BreakParty(int fd,int party_id)
if(!p)
return 0;
- inter_party_tosql(p,PS_BREAK,0);
+ inter_party_tosql(&p->party,PS_BREAK,0);
mapif_party_broken(fd,party_id);
return 0;
}
@@ -798,7 +798,7 @@ int mapif_parse_PartyLeaderChange(int fd,int party_id,int account_id,int char_id
p->party.member[i].char_id == char_id)
{
p->party.member[i].leader = 1;
- inter_party_tosql(p,PS_LEADER, i);
+ inter_party_tosql(&p->party,PS_LEADER, i);
}
}
return 1;
@@ -927,3 +927,4 @@ int inter_party_CharOffline(int char_id, int party_id) {
idb_remove(party_db_, party_id);
return 1;
}
+#endif //TXT_SQL_CONVERT
diff --git a/src/char_sql/int_party.h b/src/char_sql/int_party.h
index 902739232..7e6219f9c 100644
--- a/src/char_sql/int_party.h
+++ b/src/char_sql/int_party.h
@@ -1,8 +1,22 @@
// Copyright (c) Athena Dev Teams - Licensed under GNU GPL
// For more information, see LICENCE in the main folder
-#ifndef _INT_PARTY_H_
-#define _INT_PARTY_H_
+#ifndef _INT_PARTY_SQL_H_
+#define _INT_PARTY_SQL_H_
+
+//Party Flags on what to save/delete.
+//Create a new party entry (index holds leader's info)
+#define PS_CREATE 0x01
+//Update basic party info.
+#define PS_BASIC 0x02
+//Update party's leader
+#define PS_LEADER 0x04
+//Specify new party member (index specifies which party member)
+#define PS_ADDMEMBER 0x08
+//Specify member that left (index specifies which party member)
+#define PS_DELMEMBER 0x10
+//Specify that this party must be deleted.
+#define PS_BREAK 0x20
int inter_party_parse_frommap(int fd);
int inter_party_sql_init(void);
@@ -11,4 +25,6 @@ int inter_party_leave(int party_id,int account_id, int char_id);
int inter_party_logged(int party_id, int account_id, int char_id);
int inter_party_CharOnline(int char_id, int party_id);
int inter_party_CharOffline(int char_id, int party_id);
+//Required for the TXT->SQL converter
+int inter_party_tosql(struct party *p, int flag, int index);
#endif
diff --git a/src/char_sql/int_pet.c b/src/char_sql/int_pet.c
index c036a6019..5d5dc0615 100644
--- a/src/char_sql/int_pet.c
+++ b/src/char_sql/int_pet.c
@@ -68,7 +68,7 @@ int inter_pet_tosql(int pet_id, struct s_pet *p) {
ShowInfo("Pet saved %d - %s.\n", pet_id, p->name);
return 1;
}
-
+#ifndef TXT_SQL_CONVERT
int inter_pet_fromsql(int pet_id, struct s_pet *p){
#ifdef NOISY
@@ -355,4 +355,4 @@ int inter_pet_parse_frommap(int fd){
}
return 1;
}
-
+#endif //TXT_SQL_CONVERT
diff --git a/src/char_sql/int_pet.h b/src/char_sql/int_pet.h
index 543dfe296..fa5cbac0d 100644
--- a/src/char_sql/int_pet.h
+++ b/src/char_sql/int_pet.h
@@ -1,8 +1,8 @@
// Copyright (c) Athena Dev Teams - Licensed under GNU GPL
// For more information, see LICENCE in the main folder
-#ifndef _INT_PET_H_
-#define _INT_PET_H_
+#ifndef _INT_PET_SQL_H_
+#define _INT_PET_SQL_H_
int inter_pet_init(void);
void inter_pet_sql_final(void);
@@ -13,4 +13,6 @@ int inter_pet_parse_frommap(int fd);
int inter_pet_sql_init(void);
//extern char pet_txt[256];
+//Exported for use in the TXT-SQL converter.
+int inter_pet_tosql(int pet_id, struct s_pet *p);
#endif
diff --git a/src/char_sql/int_storage.c b/src/char_sql/int_storage.c
index f91276e75..3ed0c2aa9 100644
--- a/src/char_sql/int_storage.c
+++ b/src/char_sql/int_storage.c
@@ -13,6 +13,7 @@
#define STORAGE_MEMINC 16
+#ifndef TXT_SQL_CONVERT
// reset by inter_config_read()
struct storage *storage_pt=NULL;
struct guild_storage *guild_storage_pt=NULL;
@@ -27,6 +28,7 @@ struct guild_storage *guild_storage_pt=NULL;
#endif
+#endif //TXT_SQL_CONVERT
// storage data -> DB conversion
int storage_tosql(int account_id,struct storage *p){
int i,j;
@@ -55,6 +57,7 @@ int storage_tosql(int account_id,struct storage *p){
//printf ("storage dump to DB - id: %d (total: %d)\n", account_id, j);
return 0;
}
+#ifndef TXT_SQL_CONVERT
// DB -> storage data conversion
int storage_fromsql(int account_id, struct storage *p){
@@ -99,7 +102,7 @@ int storage_fromsql(int account_id, struct storage *p){
ShowInfo ("storage load complete from DB - id: %d (total: %d)\n", account_id, p->storage_amount);
return 1;
}
-
+#endif //TXT_SQL_CONVERT
// Save guild_storage data to sql
int guild_storage_tosql(int guild_id, struct guild_storage *p){
int i,j;
@@ -128,7 +131,7 @@ int guild_storage_tosql(int guild_id, struct guild_storage *p){
ShowInfo ("guild storage save to DB - id: %d (total: %d)\n", guild_id,i);
return 0;
}
-
+#ifndef TXT_SQL_CONVERT
// Load guild_storage data to mem
int guild_storage_fromsql(int guild_id, struct guild_storage *p){
int i=0,j;
@@ -361,4 +364,4 @@ int inter_storage_parse_frommap(int fd){
}
return 1;
}
-
+#endif //TXT_SQL_CONVERT
diff --git a/src/char_sql/int_storage.h b/src/char_sql/int_storage.h
index 8cbf78fea..c886a45e2 100644
--- a/src/char_sql/int_storage.h
+++ b/src/char_sql/int_storage.h
@@ -1,8 +1,8 @@
// Copyright (c) Athena Dev Teams - Licensed under GNU GPL
// For more information, see LICENCE in the main folder
-#ifndef _INT_STORAGE_H_
-#define _INT_STORAGE_H_
+#ifndef _INT_STORAGE_SQL_H_
+#define _INT_STORAGE_SQL_H_
int inter_storage_sql_init(void);
void inter_storage_sql_final(void);
@@ -11,7 +11,7 @@ int inter_guild_storage_delete(int guild_id);
int inter_storage_parse_frommap(int fd);
-
-//extern char storage_txt[256];
-
+//Exported for use in the TXT-SQL converter.
+int storage_tosql(int account_id,struct storage *p);
+int guild_storage_tosql(int guild_id, struct guild_storage *p);
#endif
diff --git a/src/char_sql/inter.c b/src/char_sql/inter.c
index ba0507313..f02296f58 100644
--- a/src/char_sql/inter.c
+++ b/src/char_sql/inter.c
@@ -21,16 +21,6 @@
#define WISDELLIST_MAX 256 // Wisf[^폜Xg̗vf
-struct accreg {
- int account_id, char_id;
- int reg_num;
- struct global_reg reg[MAX_REG_NUM];
-};
-
-static struct accreg *accreg_pt;
-
-
-unsigned int party_share_level = 10;
MYSQL mysql_handle;
MYSQL_RES* sql_res ;
MYSQL_ROW sql_row ;
@@ -54,6 +44,10 @@ char login_server_id[32] = "ragnarok";
char login_server_pw[32] = "ragnarok";
char login_server_db[32] = "ragnarok";
+#ifndef TXT_SQL_CONVERT
+
+static struct accreg *accreg_pt;
+unsigned int party_share_level = 10;
char main_chat_nick[16] = "Main";
// sending packet list
@@ -93,6 +87,7 @@ static int wis_dellist[WISDELLIST_MAX], wis_delnum;
int inter_sql_test (void);
+#endif //TXT_SQL_CONVERT
//--------------------------------------------------------
// Save registry to sql
int inter_accreg_tosql(int account_id, int char_id, struct accreg *reg, int type){
@@ -141,6 +136,7 @@ int inter_accreg_tosql(int account_id, int char_id, struct accreg *reg, int type
}
return 1;
}
+#ifndef TXT_SQL_CONVERT
// Load account_reg from sql (type=2)
int inter_accreg_fromsql(int account_id,int char_id, struct accreg *reg, int type)
@@ -187,12 +183,13 @@ int inter_accreg_sql_init(void)
return 0;
}
+#endif //TXT_SQL_CONVERT
/*==========================================
* read config file
*------------------------------------------
*/
-int inter_config_read(const char *cfgName) {
+static int inter_config_read(const char *cfgName) {
int i;
char line[1024], w1[1024], w2[1024];
FILE *fp;
@@ -236,7 +233,6 @@ int inter_config_read(const char *cfgName) {
}
//Logins information to be read from the inter_athena.conf
//for character deletion (checks email in the loginDB)
-
else if(strcmpi(w1,"login_server_ip")==0){
strcpy(login_server_ip, w2);
ShowStatus ("set login_server_ip : %s\n",w2);
@@ -257,19 +253,17 @@ int inter_config_read(const char *cfgName) {
strcpy(login_server_db, w2);
ShowStatus ("set login_server_db : %s\n",w2);
}
+#ifndef TXT_SQL_CONVERT
else if(strcmpi(w1,"party_share_level")==0){
party_share_level=(unsigned int)atof(w2);
}
else if(strcmpi(w1,"log_inter")==0){
log_inter = atoi(w2);
}
- else if(strcmpi(w1,"login_server_db")==0){
- strcpy(login_server_db, w2);
- ShowStatus ("set login_server_db : %s\n",w2);
- }
else if(strcmpi(w1, "main_chat_nick")==0){ // Main chat nick [LuzZza]
strcpy(main_chat_nick, w2); //
}
+#endif //TXT_SQL_CONVERT
else if(strcmpi(w1,"import")==0){
inter_config_read(w2);
}
@@ -280,6 +274,7 @@ int inter_config_read(const char *cfgName) {
return 0;
}
+#ifndef TXT_SQL_CONVERT
// Save interlog into sql
int inter_log(char *fmt,...)
@@ -312,9 +307,10 @@ int inter_sql_ping(int tid, unsigned int tick, int id, int data)
mysql_ping(&lmysql_handle);
return 0;
}
+#endif //TXT_SQL_CONVERT
// initialize
-int inter_init(const char *file)
+int inter_init_sql(const char *file)
{
//int i;
@@ -330,6 +326,7 @@ int inter_init(const char *file)
ShowFatalError("%s\n",mysql_error(&mysql_handle));
exit(1);
}
+#ifndef TXT_SQL_CONVERT
else if (inter_sql_test()) {
ShowStatus("Connect Success! (Character Server)\n");
}
@@ -346,37 +343,40 @@ int inter_init(const char *file)
ShowStatus ("Connect Success! (Login Server)\n");
}
}
+#endif //TXT_SQL_CONVERT
if(strlen(default_codepage) > 0 ) {
sprintf( tmp_sql, "SET NAMES %s", default_codepage );
if (mysql_query(&mysql_handle, tmp_sql)) {
ShowSQL("DB error - %s\n",mysql_error(&mysql_handle));
ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
}
+#ifndef TXT_SQL_CONVERT
if(char_gm_read)
if (mysql_query(&lmysql_handle, tmp_sql)) {
ShowSQL("DB error - %s\n",mysql_error(&lmysql_handle));
ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
}
+#endif //TXT_SQL_CONVERT
}
+
+#ifndef TXT_SQL_CONVERT
wis_db = db_alloc(__FILE__,__LINE__,DB_INT,DB_OPT_RELEASE_DATA,sizeof(int));
inter_guild_sql_init();
inter_storage_sql_init();
inter_party_sql_init();
-
inter_pet_sql_init();
inter_homunculus_sql_init(); // albator
inter_accreg_sql_init();
- //printf ("interserver timer initializing : %d sec...\n",autosave_interval);
- //i=add_timer_interval(gettick()+autosave_interval,inter_save_timer,0,0,autosave_interval);
-
if (connection_ping_interval) {
add_timer_func_list(inter_sql_ping, "inter_sql_ping");
add_timer_interval(gettick()+connection_ping_interval*60*60*1000,
inter_sql_ping, 0, 0, connection_ping_interval*60*60*1000);
}
+#endif //TXT_SQL_CONVERT
return 0;
}
+#ifndef TXT_SQL_CONVERT
int inter_sql_test (void)
{
@@ -808,3 +808,4 @@ int inter_check_length(int fd, int length)
return length;
}
+#endif //TXT_SQL_CONVERT
diff --git a/src/char_sql/inter.h b/src/char_sql/inter.h
index d84085651..8dc6f3668 100644
--- a/src/char_sql/inter.h
+++ b/src/char_sql/inter.h
@@ -1,10 +1,10 @@
// Copyright (c) Athena Dev Teams - Licensed under GNU GPL
// For more information, see LICENCE in the main folder
-#ifndef _INTER_H_
-#define _INTER_H_
+#ifndef _INTER_SQL_H_
+#define _INTER_SQL_H_
-int inter_init(const char *file);
+int inter_init_sql(const char *file);
void inter_final(void);
int inter_parse_frommap(int fd);
int inter_mapif_init(int fd);
@@ -50,8 +50,7 @@ extern char login_db_server_id[32];
extern char login_db_server_pw[32];
extern char login_db_server_db[32];
-extern int log_inter;
-
extern char main_chat_nick[16];
+int inter_accreg_tosql(int account_id, int char_id, struct accreg *reg, int type);
#endif