summaryrefslogtreecommitdiff
path: root/src/char_sql
diff options
context:
space:
mode:
authorultramage <ultramage@54d463be-8e91-2dee-dedb-b68131a5f0ec>2007-07-01 15:26:53 +0000
committerultramage <ultramage@54d463be-8e91-2dee-dedb-b68131a5f0ec>2007-07-01 15:26:53 +0000
commitbdfce85b67dd0e63f34ddf9bed05d94b79dd9d05 (patch)
tree8a5660f98c2af5a8456e801e5d11f17a31bb6e1d /src/char_sql
parente8268e93edc3fe17abb22b870a66eecaf5ba1e13 (diff)
downloadhercules-bdfce85b67dd0e63f34ddf9bed05d94b79dd9d05.tar.gz
hercules-bdfce85b67dd0e63f34ddf9bed05d94b79dd9d05.tar.bz2
hercules-bdfce85b67dd0e63f34ddf9bed05d94b79dd9d05.tar.xz
hercules-bdfce85b67dd0e63f34ddf9bed05d94b79dd9d05.zip
Cleaned up some parts of the code.
Removed obsolete script function 'hasitems'. git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@10838 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/char_sql')
-rw-r--r--src/char_sql/char.c338
-rw-r--r--src/char_sql/inter.c273
2 files changed, 290 insertions, 321 deletions
diff --git a/src/char_sql/char.c b/src/char_sql/char.c
index f9a431f73..b9abe1038 100644
--- a/src/char_sql/char.c
+++ b/src/char_sql/char.c
@@ -743,27 +743,15 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus *p){
int memitemdata_to_sql(struct itemtmp mapitem[], int count, int char_id, int tableswitch)
{
int i,j, flag, id;
- char *tablename;
+ char* tablename;
char selectoption[16];
- char * str_p = tmp_sql;
+ char* str_p = tmp_sql;
switch (tableswitch) {
- case TABLE_INVENTORY:
- tablename = inventory_db; // no need for sprintf here as *_db are char*.
- sprintf(selectoption,"char_id");
- break;
- case TABLE_CART:
- tablename = cart_db;
- sprintf(selectoption,"char_id");
- break;
- case TABLE_STORAGE:
- tablename = storage_db;
- sprintf(selectoption,"account_id");
- break;
- case TABLE_GUILD_STORAGE:
- tablename = guild_storage_db;
- sprintf(selectoption,"guild_id");
- break;
+ case TABLE_INVENTORY: tablename = inventory_db; sprintf(selectoption,"char_id"); break;
+ case TABLE_CART: tablename = cart_db; sprintf(selectoption,"char_id"); break;
+ case TABLE_STORAGE: tablename = storage_db; sprintf(selectoption,"account_id"); break;
+ case TABLE_GUILD_STORAGE: tablename = guild_storage_db; sprintf(selectoption,"guild_id"); break;
default:
ShowError("Invalid table name!\n");
return 1;
@@ -1578,50 +1566,45 @@ int count_users(void)
/// Writes char data to the buffer in the format used by the client.
/// Used in packets 0x6b (chars info) and 0x6d (new char info)
/// Returns the size (106 or 108)
-int mmo_char_tobuf(uint8* buf, struct mmo_charstatus *p)
+int mmo_char_tobuf(uint8* buf, struct mmo_charstatus* p)
{
if( buf == NULL || p == NULL )
return 0;
WBUFL(buf,0) = p->char_id;
- WBUFL(buf,4) = p->base_exp>LONG_MAX?LONG_MAX:p->base_exp;
+ WBUFL(buf,4) = min(p->base_exp, LONG_MAX);
WBUFL(buf,8) = p->zeny;
- WBUFL(buf,12) = p->job_exp>LONG_MAX?LONG_MAX:p->job_exp;
+ WBUFL(buf,12) = min(p->job_exp, LONG_MAX);
WBUFL(buf,16) = p->job_level;
-
- WBUFL(buf,20) = 0;// probably opt1
- WBUFL(buf,24) = 0;// probably opt2
+ WBUFL(buf,20) = 0; // probably opt1
+ WBUFL(buf,24) = 0; // probably opt2
WBUFL(buf,28) = p->option;
-
WBUFL(buf,32) = p->karma;
WBUFL(buf,36) = p->manner;
-
- WBUFW(buf,40) = (p->status_point > SHRT_MAX) ? SHRT_MAX : p->status_point;
- WBUFW(buf,42) = (p->hp > SHRT_MAX) ? SHRT_MAX : p->hp;
- WBUFW(buf,44) = (p->max_hp > SHRT_MAX) ? SHRT_MAX : p->max_hp;
- WBUFW(buf,46) = (p->sp > SHRT_MAX) ? SHRT_MAX : p->sp;
- WBUFW(buf,48) = (p->max_sp > SHRT_MAX) ? SHRT_MAX : p->max_sp;
+ WBUFW(buf,40) = min(p->status_point, SHRT_MAX);
+ WBUFW(buf,42) = min(p->hp, SHRT_MAX);
+ WBUFW(buf,44) = min(p->max_hp, SHRT_MAX);
+ WBUFW(buf,46) = min(p->sp, SHRT_MAX);
+ WBUFW(buf,48) = min(p->max_sp, SHRT_MAX);
WBUFW(buf,50) = DEFAULT_WALK_SPEED; // p->speed;
WBUFW(buf,52) = p->class_;
WBUFW(buf,54) = p->hair;
WBUFW(buf,56) = p->option&0x20 ? 0 : p->weapon; //When the weapon is sent and your option is riding, the client crashes on login!?
WBUFW(buf,58) = p->base_level;
- WBUFW(buf,60) = (p->skill_point > SHRT_MAX) ? SHRT_MAX : p->skill_point;
+ WBUFW(buf,60) = min(p->skill_point, SHRT_MAX);
WBUFW(buf,62) = p->head_bottom;
WBUFW(buf,64) = p->shield;
WBUFW(buf,66) = p->head_top;
WBUFW(buf,68) = p->head_mid;
WBUFW(buf,70) = p->hair_color;
WBUFW(buf,72) = p->clothes_color;
-
memcpy(WBUFP(buf,74), p->name, NAME_LENGTH);
-
- WBUFB(buf,98) = (p->str > UCHAR_MAX) ? UCHAR_MAX : p->str;
- WBUFB(buf,99) = (p->agi > UCHAR_MAX) ? UCHAR_MAX : p->agi;
- WBUFB(buf,100) = (p->vit > UCHAR_MAX) ? UCHAR_MAX : p->vit;
- WBUFB(buf,101) = (p->int_ > UCHAR_MAX) ? UCHAR_MAX : p->int_;
- WBUFB(buf,102) = (p->dex > UCHAR_MAX) ? UCHAR_MAX : p->dex;
- WBUFB(buf,103) = (p->luk > UCHAR_MAX) ? UCHAR_MAX : p->luk;
+ WBUFB(buf,98) = min(p->str, UCHAR_MAX);
+ WBUFB(buf,99) = min(p->agi, UCHAR_MAX);
+ WBUFB(buf,100) = min(p->vit, UCHAR_MAX);
+ WBUFB(buf,101) = min(p->int_, UCHAR_MAX);
+ WBUFB(buf,102) = min(p->dex, UCHAR_MAX);
+ WBUFB(buf,103) = min(p->luk, UCHAR_MAX);
//Updated packet structure with rename-button included. Credits to Sara-chan
#if PACKETVER > 7
WBUFW(buf,104) = p->char_num;
@@ -1633,11 +1616,11 @@ int mmo_char_tobuf(uint8* buf, struct mmo_charstatus *p)
#endif
}
-int mmo_char_send006b(int fd, struct char_session_data *sd)
+int mmo_char_send006b(int fd, struct char_session_data* sd)
{
int i, j, found_num = 0;
- set_char_online(-1, 99,sd->account_id);
+ set_char_online(-1, 99, sd->account_id);
//search char.
sprintf(tmp_sql, "SELECT `char_id` FROM `%s` WHERE `account_id` = '%d' AND `char_num` < '%d'",char_db, sd->account_id, MAX_CHARS);
@@ -1664,19 +1647,17 @@ int mmo_char_send006b(int fd, struct char_session_data *sd)
ShowInfo("Loading Char Data ("CL_BOLD"%d"CL_RESET")\n",sd->account_id);
- j = 24;// offset
+ j = 24; // offset
+ WFIFOHEAD(fd, j + found_num*108);
+ WFIFOW(fd,0) = 0x6b;
+ memset(WFIFOP(fd,4), 0, 20); // unknown bytes
+ for(i = 0; i < found_num; i++)
{
- WFIFOHEAD(fd, j + found_num*108);
- WFIFOW(fd,0) = 0x6b;
- memset(WFIFOP(fd,4), 0, 20);// unknown bytes
- for(i = 0; i < found_num; i++)
- {
- mmo_char_fromsql(sd->found_char[i], &char_dat, false);
- j += mmo_char_tobuf(WFIFOP(fd,j), &char_dat);
- }
- WFIFOW(fd,2) = j;// packet len
- WFIFOSET(fd,j);
+ mmo_char_fromsql(sd->found_char[i], &char_dat, false);
+ j += mmo_char_tobuf(WFIFOP(fd,j), &char_dat);
}
+ WFIFOW(fd,2) = j; // packet len
+ WFIFOSET(fd,j);
return 0;
}
@@ -1728,7 +1709,7 @@ static void char_auth_ok(int fd, struct char_session_data *sd)
int send_accounts_tologin(int tid, unsigned int tick, int id, int data);
-int parse_tologin(int fd)
+int parse_fromlogin(int fd)
{
int i;
struct char_session_data *sd;
@@ -1749,8 +1730,9 @@ int parse_tologin(int fd)
// hehe. no need to set user limit on SQL version. :P
// but char limitation is good way to maintain server. :D
- while(RFIFOREST(fd) >= 2) {
-// printf("parse_tologin : %d %d %x\n", fd, RFIFOREST(fd), RFIFOW(fd, 0));
+ while(RFIFOREST(fd) >= 2)
+ {
+// printf("parse_fromlogin : %d %d %x\n", fd, RFIFOREST(fd), RFIFOW(fd, 0));
switch(RFIFOW(fd,0)) {
case 0x2711:
@@ -2608,13 +2590,11 @@ int parse_frommap(int fd)
if (RFIFOREST(fd) < 35)
return 0;
{
- unsigned short name;
int map_id, map_fd = -1;
struct online_char_data* data;
struct mmo_charstatus* char_data;
- name = RFIFOW(fd,18);
- map_id = search_mapserver(name, ntohl(RFIFOL(fd,24)), ntohs(RFIFOW(fd,28))); //Locate mapserver by ip and port.
+ map_id = search_mapserver(RFIFOW(fd,18), ntohl(RFIFOL(fd,24)), ntohs(RFIFOW(fd,28))); //Locate mapserver by ip and port.
if (map_id >= 0)
map_fd = server_fd[map_id];
//Char should just had been saved before this packet, so this should be safe. [Skotlex]
@@ -2975,20 +2955,23 @@ int parse_frommap(int fd)
return 0;
}
+// Searches for the mapserver that has a given map (and optionally ip/port, if not -1).
+// If found, returns the server's index in the 'server' array (otherwise returns -1).
int search_mapserver(unsigned short map, uint32 ip, uint16 port)
{
int i, j;
-
+
for(i = 0; i < MAX_MAP_SERVERS; i++)
- if (server_fd[i] > 0)
+ {
+ if (server_fd[i] > 0
+ && (ip == (uint32)-1 || server[i].ip == ip)
+ && (port == (uint16)-1 || server[i].port == port))
+ {
for (j = 0; server[i].map[j]; j++)
- if (server[i].map[j] == map) {
- if (ip != (uint32)-1 && server[i].ip != ip)
- continue;
- if (port != (uint16)-1 && server[i].port != port)
- continue;
+ if (server[i].map[j] == map)
return i;
- }
+ }
+ }
return -1;
}
@@ -3615,7 +3598,7 @@ int check_connect_login_server(int tid, unsigned int tick, int id, int data)
login_fd = 0;
return 0;
}
- session[login_fd]->func_parse = parse_tologin;
+ session[login_fd]->func_parse = parse_fromlogin;
realloc_fifo(login_fd, FIFOSIZE_SERVERLINK, FIFOSIZE_SERVERLINK);
WFIFOHEAD(login_fd,86);
@@ -3705,16 +3688,16 @@ int char_lan_config_read(const char *lancfgName)
}
#endif //TXT_SQL_CONVERT
-void sql_config_read(const char *cfgName)
+void sql_config_read(const char* cfgName)
{
char line[1024], w1[1024], w2[1024];
- FILE *fp;
+ FILE* fp;
ShowInfo("Reading file %s...\n", cfgName);
if ((fp = fopen(cfgName, "r")) == NULL) {
- ShowFatalError("file not found: %s\n", cfgName);
- exit(1);
+ ShowError("file not found: %s\n", cfgName);
+ return;
}
while(fgets(line, sizeof(line), fp))
@@ -3725,96 +3708,93 @@ void sql_config_read(const char *cfgName)
if (sscanf(line, "%[^:]: %[^\r\n]", w1, w2) != 2)
continue;
- if(strcmpi(w1,"char_db")==0){
+ if(!strcmpi(w1,"char_db"))
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_read_method"))
+ char_gm_read = config_switch(w2);
//custom columns for login database
- }else if(strcmpi(w1,"login_db")==0){
- strcpy(login_db, w2);
- }else if(strcmpi(w1,"login_db_level")==0){
+ else if(!strcmpi(w1,"login_db"))
+ strcpy(login_db,w2);
+ else if(!strcmpi(w1,"login_db_level"))
strcpy(login_db_level,w2);
- }else if(strcmpi(w1,"login_db_account_id")==0){
+ else if(!strcmpi(w1,"login_db_account_id"))
strcpy(login_db_account_id,w2);
- }else if(strcmpi(w1,"lowest_gm_level")==0){
+ else if(!strcmpi(w1,"lowest_gm_level")) {
lowest_gm_level = atoi(w2);
- ShowStatus("set lowest_gm_level : %s\n",w2);
+ ShowStatus("set lowest_gm_level : %s\n", w2);
+ }
#endif
- }else if(strcmpi(w1,"scdata_db")==0){
+ else if(!strcmpi(w1,"scdata_db"))
strcpy(scdata_db,w2);
- }else if(strcmpi(w1,"cart_db")==0){
+ else if(!strcmpi(w1,"cart_db"))
strcpy(cart_db,w2);
- }else if(strcmpi(w1,"inventory_db")==0){
- strcpy(inventory_db,w2);
- }else if(strcmpi(w1,"charlog_db")==0){
+ else if(!strcmpi(w1,"inventory_db"))
+ strcpy(inventory_db, w2);
+ else if(!strcmpi(w1,"charlog_db"))
strcpy(charlog_db,w2);
- }else if(strcmpi(w1,"storage_db")==0){
+ else if(!strcmpi(w1,"storage_db"))
strcpy(storage_db,w2);
- }else if(strcmpi(w1,"reg_db")==0){
+ else if(!strcmpi(w1,"reg_db"))
strcpy(reg_db,w2);
- }else if(strcmpi(w1,"skill_db")==0){
+ else if(!strcmpi(w1,"skill_db"))
strcpy(skill_db,w2);
- }else if(strcmpi(w1,"interlog_db")==0){
+ else if(!strcmpi(w1,"interlog_db"))
strcpy(interlog_db,w2);
- }else if(strcmpi(w1,"memo_db")==0){
+ else if(!strcmpi(w1,"memo_db"))
strcpy(memo_db,w2);
- }else if(strcmpi(w1,"guild_db")==0){
+ else if(!strcmpi(w1,"guild_db"))
strcpy(guild_db,w2);
- }else if(strcmpi(w1,"guild_alliance_db")==0){
+ else if(!strcmpi(w1,"guild_alliance_db"))
strcpy(guild_alliance_db,w2);
- }else if(strcmpi(w1,"guild_castle_db")==0){
+ else if(!strcmpi(w1,"guild_castle_db"))
strcpy(guild_castle_db,w2);
- }else if(strcmpi(w1,"guild_expulsion_db")==0){
+ else if(!strcmpi(w1,"guild_expulsion_db"))
strcpy(guild_expulsion_db,w2);
- }else if(strcmpi(w1,"guild_member_db")==0){
+ else if(!strcmpi(w1,"guild_member_db"))
strcpy(guild_member_db,w2);
- }else if(strcmpi(w1,"guild_skill_db")==0){
+ else if(!strcmpi(w1,"guild_skill_db"))
strcpy(guild_skill_db,w2);
- }else if(strcmpi(w1,"guild_position_db")==0){
+ else if(!strcmpi(w1,"guild_position_db"))
strcpy(guild_position_db,w2);
- }else if(strcmpi(w1,"guild_storage_db")==0){
+ else if(!strcmpi(w1,"guild_storage_db"))
strcpy(guild_storage_db,w2);
- }else if(strcmpi(w1,"party_db")==0){
+ else if(!strcmpi(w1,"party_db"))
strcpy(party_db,w2);
- }else if(strcmpi(w1,"pet_db")==0){
+ else if(!strcmpi(w1,"pet_db"))
strcpy(pet_db,w2);
- }else if(strcmpi(w1,"friend_db")==0){
+ else if(!strcmpi(w1,"friend_db"))
strcpy(friend_db,w2);
#ifndef TXT_SQL_CONVERT
- }else if(strcmpi(w1,"db_path")==0){
+ else if(!strcmpi(w1,"db_path"))
strcpy(db_path,w2);
- //Map server option to use SQL db or not
- }else if(strcmpi(w1,"use_sql_db")==0){ // added for sql item_db read for char server [Valaris]
+ //Map server option to use SQL item/mob-db or not
+ else if(!strcmpi(w1,"use_sql_db")==0){
db_use_sqldbs = config_switch(w2);
ShowStatus("Using SQL dbs: %s\n",w2);
- }else if(strcmpi(w1,"item_db_db")==0){
+ }
+ else if(!strcmpi(w1,"item_db_db"))
strcpy(item_db_db,w2);
- }else if(strcmpi(w1,"item_db2_db")==0){
+ else if(!strcmpi(w1,"item_db2_db"))
strcpy(item_db2_db,w2);
#endif
//support the import command, just like any other config
- }else if(strcmpi(w1,"import")==0){
+ else if(!strcmpi(w1,"import"))
sql_config_read(w2);
- }
-
}
fclose(fp);
ShowInfo("Done reading %s.\n", cfgName);
}
#ifndef TXT_SQL_CONVERT
-int char_config_read(const char *cfgName)
+int char_config_read(const char* cfgName)
{
char line[1024], w1[1024], w2[1024];
FILE* fp = fopen(cfgName, "r");
if (fp == NULL) {
- ShowFatalError("Configuration file not found: %s.\n", cfgName);
- exit(1);
+ ShowError("Configuration file not found: %s.\n", cfgName);
+ return 1;
}
ShowInfo("Reading configuration file %s...\n", cfgName);
@@ -3968,7 +3948,6 @@ int char_config_read(const char *cfgName)
void do_final(void)
{
ShowInfo("Doing final stage...\n");
- //inter_save();
do_final_itemdb();
//check SQL save progress.
//wait until save char complete
@@ -4074,11 +4053,8 @@ int do_init(int argc, char **argv)
mmo_char_sql_init();
ShowInfo("char server initialized.\n");
-// ShowDebug("set parser -> parse_char()...\n");
set_defaultparse(parse_char);
-// ShowDebug("set terminate function -> do_final().....\n");
-
if ((naddr_ != 0) && (!login_ip || !char_ip))
{
char ip_str[16];
@@ -4124,32 +4100,32 @@ int do_init(int argc, char **argv)
{
//##TODO invoke a CONSOLE_START plugin event
}
-
+
//Cleaning the tables for NULL entrys @ startup [Sirius]
- //Chardb clean
- ShowInfo("Cleaning the '%s' table...\n", char_db);
- sprintf(tmp_sql,"DELETE FROM `%s` WHERE `account_id` = '0'", char_db);
- 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);
- }
-
- //guilddb clean
- ShowInfo("Cleaning the '%s' table...\n", guild_db);
- sprintf(tmp_sql,"DELETE FROM `%s` WHERE `guild_lv` = '0' AND `max_member` = '0' AND `exp` = '0' AND `next_exp` = '0' AND `average_lv` = '0'", guild_db);
- 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);
- }
-
- //guildmemberdb clean
- ShowInfo("Cleaning the '%s' table...\n", guild_member_db);
- sprintf(tmp_sql,"DELETE FROM `%s` WHERE `guild_id` = '0' AND `account_id` = '0' AND `char_id` = '0'", guild_member_db);
- 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);
- }
-
+ //Chardb clean
+ ShowInfo("Cleaning the '%s' table...\n", char_db);
+ sprintf(tmp_sql,"DELETE FROM `%s` WHERE `account_id` = '0'", char_db);
+ 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);
+ }
+
+ //guilddb clean
+ ShowInfo("Cleaning the '%s' table...\n", guild_db);
+ sprintf(tmp_sql,"DELETE FROM `%s` WHERE `guild_lv` = '0' AND `max_member` = '0' AND `exp` = '0' AND `next_exp` = '0' AND `average_lv` = '0'", guild_db);
+ 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);
+ }
+
+ //guildmemberdb clean
+ ShowInfo("Cleaning the '%s' table...\n", guild_member_db);
+ sprintf(tmp_sql,"DELETE FROM `%s` WHERE `guild_id` = '0' AND `account_id` = '0' AND `char_id` = '0'", guild_member_db);
+ 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);
+ }
+
ShowInfo("End of char server initilization function.\n");
ShowStatus("The char-server is "CL_GREEN"ready"CL_RESET" (Server is listening on the port %d).\n\n", char_port);
return 0;
@@ -4157,47 +4133,47 @@ int do_init(int argc, char **argv)
int char_child(int parent_id, int child_id)
{
- int tmp_id = 0;
- sprintf (tmp_sql, "SELECT `child` FROM `%s` WHERE `char_id` = '%d'", char_db, parent_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);
- }
- sql_res = mysql_store_result (&mysql_handle);
- sql_row = sql_res?mysql_fetch_row (sql_res):NULL;
- if (sql_row)
- tmp_id = atoi (sql_row[0]);
- else
- ShowError("CHAR: child Failed!\n");
- if (sql_res) mysql_free_result (sql_res);
- if ( tmp_id == child_id )
- return 1;
- else
- return 0;
+ int tmp_id = 0;
+ sprintf (tmp_sql, "SELECT `child` FROM `%s` WHERE `char_id` = '%d'", char_db, parent_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);
+ }
+ sql_res = mysql_store_result (&mysql_handle);
+ sql_row = sql_res?mysql_fetch_row (sql_res):NULL;
+ if (sql_row)
+ tmp_id = atoi (sql_row[0]);
+ else
+ ShowError("CHAR: child Failed!\n");
+ if (sql_res) mysql_free_result (sql_res);
+ if ( tmp_id == child_id )
+ return 1;
+ else
+ return 0;
}
-int char_married(int pl1,int pl2)
+int char_married(int pl1, int pl2)
{
- int tmp_id = 0;
- sprintf (tmp_sql, "SELECT `partner_id` FROM `%s` WHERE `char_id` = '%d'", char_db, pl1);
- 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);
- }
- sql_res = mysql_store_result (&mysql_handle);
- sql_row = sql_res?mysql_fetch_row (sql_res):NULL;
- if (sql_row)
- tmp_id = atoi (sql_row[0]);
- else
- ShowError("CHAR: married Failed!\n");
- if (sql_res) mysql_free_result (sql_res);
- if ( tmp_id == pl2 )
- return 1;
- else
- return 0;
+ int tmp_id = 0;
+ sprintf (tmp_sql, "SELECT `partner_id` FROM `%s` WHERE `char_id` = '%d'", char_db, pl1);
+ 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);
+ }
+ sql_res = mysql_store_result (&mysql_handle);
+ sql_row = sql_res?mysql_fetch_row (sql_res):NULL;
+ if (sql_row)
+ tmp_id = atoi (sql_row[0]);
+ else
+ ShowError("CHAR: married Failed!\n");
+ if (sql_res) mysql_free_result (sql_res);
+ if ( tmp_id == pl2 )
+ return 1;
+ else
+ return 0;
}
-int char_family(int pl1,int pl2,int pl3)
+int char_family(int pl1, int pl2, int pl3)
{
int charid, partnerid, childid;
sprintf (tmp_sql, "SELECT `char_id`,`partner_id`,`child` FROM `%s` WHERE `char_id` IN ('%d','%d','%d')", char_db, pl1, pl2, pl3);
diff --git a/src/char_sql/inter.c b/src/char_sql/inter.c
index 8f2386a91..fbff7b7fb 100644
--- a/src/char_sql/inter.c
+++ b/src/char_sql/inter.c
@@ -51,29 +51,29 @@ char main_chat_nick[16] = "Main";
// sending packet list
// NOTE: This variable ain't used at all! And it's confusing.. where do I add that the length of packet 0x2b07 is 10? x.x [Skotlex]
-int inter_send_packet_length[]={
- -1,-1,27,-1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- -1, 7, 0, 0, 0, 0, 0, 0, -1,11, 0, 0, 0, 0, 0, 0,
- 35,-1,11,15, 34,29, 7,-1, 0, 0, 0, 0, 0, 0, 0, 0,
- 10,-1,15, 0, 79,19, 7,-1, 0,-1,-1,-1, 14,67,186,-1,
- 9, 9,-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 11,-1, 7, 3, 36, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+int inter_send_packet_length[] = {
+ -1,-1,27,-1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 3800-
+ -1, 7, 0, 0, 0, 0, 0, 0, -1,11, 0, 0, 0, 0, 0, 0, // 3810-
+ 35,-1,11,15, 34,29, 7,-1, 0, 0, 0, 0, 0, 0, 0, 0, // 3820-
+ 10,-1,15, 0, 79,19, 7,-1, 0,-1,-1,-1, 14,67,186,-1, // 3830-
+ 9, 9,-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 3840-
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 3850-
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 3860-
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 3870-
+ 11,-1, 7, 3, 36, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 3880-
};
// recv. packet list
-int inter_recv_packet_length[]={
- -1,-1, 7,-1, -1,13,36, 0, 0, 0, 0, 0, 0, 0, 0, 0, //0x3000-0x300f
- 6,-1, 0, 0, 0, 0, 0, 0, 10,-1, 0, 0, 0, 0, 0, 0, //0x3010-0x301f
- -1, 6,-1,14, 14,19, 6,-1, 14,14, 0, 0, 0, 0, 0, 0, //0x3020-0x302f
- -1, 6,-1,-1, 55,19, 6,-1, 14,-1,-1,-1, 14,19,186,-1, //0x3030-0x303f
- 5, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 48,14,-1, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //0x3080-0x308f
- -1,10,-1, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0x3090 - 0x309f Homunculus packets [albator]
+int inter_recv_packet_length[] = {
+ -1,-1, 7,-1, -1,13,36, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 3000-
+ 6,-1, 0, 0, 0, 0, 0, 0, 10,-1, 0, 0, 0, 0, 0, 0, // 3010-
+ -1, 6,-1,14, 14,19, 6,-1, 14,14, 0, 0, 0, 0, 0, 0, // 3020-
+ -1, 6,-1,-1, 55,19, 6,-1, 14,-1,-1,-1, 14,19,186,-1, // 3030-
+ 5, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 3040-
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 3050-
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 3060-
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 3070-
+ 48,14,-1, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 3080-
+ -1,10,-1, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 3090- Homunculus packets [albator]
};
struct WisData {
@@ -187,86 +187,83 @@ int inter_accreg_sql_init(void)
/*==========================================
* read config file
*------------------------------------------*/
-static 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;
+ FILE* fp;
- fp=fopen(cfgName,"r");
- if(fp==NULL){
+ fp = fopen(cfgName, "r");
+ if(fp == NULL) {
ShowError("file not found: %s\n", cfgName);
return 1;
}
- ShowInfo("reading file %s...\n",cfgName);
+ ShowInfo("reading file %s...\n", cfgName);
while(fgets(line, sizeof(line), fp))
{
- i=sscanf(line,"%[^:]: %[^\r\n]",w1,w2);
- if(i!=2)
+ i = sscanf(line, "%[^:]: %[^\r\n]", w1, w2);
+ if(i != 2)
continue;
- if(strcmpi(w1,"char_server_ip")==0){
- strcpy(char_server_ip, w2);
- ShowStatus ("set char_server_ip : %s\n",w2);
- }
- else if(strcmpi(w1,"char_server_port")==0){
- char_server_port=atoi(w2);
- ShowStatus ("set char_server_port : %s\n",w2);
- }
- else if(strcmpi(w1,"char_server_id")==0){
- strcpy(char_server_id, w2);
- ShowStatus ("set char_server_id : %s\n",w2);
- }
- else if(strcmpi(w1,"char_server_pw")==0){
- strcpy(char_server_pw, w2);
- ShowStatus ("set char_server_pw : %s\n",w2);
- }
- else if(strcmpi(w1,"char_server_db")==0){
- strcpy(char_server_db, w2);
- ShowStatus ("set char_server_db : %s\n",w2);
- }
- else if(strcmpi(w1,"default_codepage")==0){
- strcpy(default_codepage, w2);
- ShowStatus ("set default_codepage : %s\n",w2);
+ if(!strcmpi(w1,"char_server_ip")) {
+ strcpy(char_server_ip,w2);
+ ShowStatus ("set char_server_ip : %s\n", w2);
+ } else
+ if(!strcmpi(w1,"char_server_port")) {
+ char_server_port = atoi(w2);
+ ShowStatus ("set char_server_port : %s\n", w2);
+ } else
+ if(!strcmpi(w1,"char_server_id")) {
+ strcpy(char_server_id,w2);
+ ShowStatus ("set char_server_id : %s\n", w2);
+ } else
+ if(!strcmpi(w1,"char_server_pw")) {
+ strcpy(char_server_pw,w2);
+ ShowStatus ("set char_server_pw : %s\n", w2);
+ } else
+ if(!strcmpi(w1,"char_server_db")) {
+ strcpy(char_server_db,w2);
+ ShowStatus ("set char_server_db : %s\n", w2);
+ } else
+ if(!strcmpi(w1,"default_codepage")) {
+ strcpy(default_codepage,w2);
+ ShowStatus ("set default_codepage : %s\n", w2);
}
//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){
+ else
+ if(!strcmpi(w1,"login_server_ip")) {
strcpy(login_server_ip, w2);
- ShowStatus ("set login_server_ip : %s\n",w2);
- }
- else if(strcmpi(w1,"login_server_port")==0){
- login_server_port=atoi(w2);
- ShowStatus ("set login_server_port : %s\n",w2);
- }
- else if(strcmpi(w1,"login_server_id")==0){
+ ShowStatus ("set login_server_ip : %s\n", w2);
+ } else
+ if(!strcmpi(w1,"login_server_port")) {
+ login_server_port = atoi(w2);
+ ShowStatus ("set login_server_port : %s\n", w2);
+ } else
+ if(!strcmpi(w1,"login_server_id")) {
strcpy(login_server_id, w2);
- ShowStatus ("set login_server_id : %s\n",w2);
- }
- else if(strcmpi(w1,"login_server_pw")==0){
+ ShowStatus ("set login_server_id : %s\n", w2);
+ } else
+ if(!strcmpi(w1,"login_server_pw")) {
strcpy(login_server_pw, w2);
- ShowStatus ("set login_server_pw : %s\n",w2);
- }
- else if(strcmpi(w1,"login_server_db")==0){
+ ShowStatus ("set login_server_pw : %s\n", w2);
+ } else
+ if(!strcmpi(w1,"login_server_db")) {
strcpy(login_server_db, w2);
- ShowStatus ("set login_server_db : %s\n",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){
+ else if(!strcmpi(w1,"party_share_level"))
+ party_share_level = atoi(w2);
+ else if(!strcmpi(w1,"log_inter"))
log_inter = atoi(w2);
- }
- else if(strcmpi(w1, "main_chat_nick")==0){ // Main chat nick [LuzZza]
- strcpy(main_chat_nick, w2); //
- }
+ else if(!strcmpi(w1,"main_chat_nick"))
+ strcpy(main_chat_nick, w2);
#endif //TXT_SQL_CONVERT
- else if(strcmpi(w1,"import")==0){
+ else if(!strcmpi(w1,"import"))
inter_config_read(w2);
- }
}
fclose(fp);
@@ -277,7 +274,7 @@ static int inter_config_read(const char *cfgName)
#ifndef TXT_SQL_CONVERT
// Save interlog into sql
-int inter_log(char *fmt,...)
+int inter_log(char* fmt, ...)
{
char str[255];
char temp_str[510]; //Needs be twice as long as str[] //Skotlex
@@ -438,7 +435,8 @@ int inter_sql_test (void)
}
// finalize
-void inter_final(void) {
+void inter_final(void)
+{
wis_db->destroy(wis_db, NULL);
inter_guild_sql_final();
@@ -451,7 +449,8 @@ void inter_final(void) {
return;
}
-int inter_mapif_init(int fd) {
+int inter_mapif_init(int fd)
+{
inter_guild_mapif_init(fd);
return 0;
@@ -461,20 +460,22 @@ int inter_mapif_init(int fd) {
//--------------------------------------------------------
// GM message sending
-int mapif_GMmessage(unsigned char *mes, int len, unsigned long color, int sfd) {
+int mapif_GMmessage(unsigned char *mes, int len, unsigned long color, int sfd)
+{
unsigned char buf[2048];
if (len > 2048) len = 2047; //Make it fit to avoid crashes. [Skotlex]
- WBUFW(buf, 0) = 0x3800;
- WBUFW(buf, 2) = len;
- WBUFL(buf, 4) = color;
- memcpy(WBUFP(buf, 8), mes, len-8);
+ WBUFW(buf,0) = 0x3800;
+ WBUFW(buf,2) = len;
+ WBUFL(buf,4) = color;
+ memcpy(WBUFP(buf,8), mes, len - 8);
mapif_sendallwos(sfd, buf, len);
return 0;
}
// Wis sending
-int mapif_wis_message(struct WisData *wd) {
+int mapif_wis_message(struct WisData *wd)
+{
unsigned char buf[2048];
if (wd->len > 2047-56) wd->len = 2047-56; //Force it to fit to avoid crashes. [Skotlex]
@@ -549,11 +550,11 @@ int mapif_send_gmaccounts()
WBUFW(buf,0) = 0x2b15;
for(i = 0; i < GM_num; i++) {
- WBUFL(buf, len) = gm_account[i].account_id;
- WBUFB(buf, len+4) = (unsigned char)gm_account[i].level;
+ WBUFL(buf,len) = gm_account[i].account_id;
+ WBUFB(buf,len+4) = (uint8)gm_account[i].level;
len += 5;
}
- WBUFW(buf, 2) = len;
+ WBUFW(buf,2) = len;
mapif_sendall(buf, len);
return 0;
@@ -588,7 +589,8 @@ int mapif_disconnectplayer(int fd, int account_id, int char_id, int reason)
//--------------------------------------------------------
// Existence check of WISP data
-int check_ttl_wisdata_sub(DBKey key, void *data, va_list ap) {
+int check_ttl_wisdata_sub(DBKey key, void *data, va_list ap)
+{
unsigned long tick;
struct WisData *wd = (struct WisData *)data;
tick = va_arg(ap, unsigned long);
@@ -599,7 +601,8 @@ int check_ttl_wisdata_sub(DBKey key, void *data, va_list ap) {
return 0;
}
-int check_ttl_wisdata(void) {
+int check_ttl_wisdata(void)
+{
unsigned long tick = gettick();
int i;
@@ -623,18 +626,18 @@ int check_ttl_wisdata(void) {
// GM message sending
int mapif_parse_GMmessage(int fd)
{
- RFIFOHEAD(fd);
- mapif_GMmessage(RFIFOP(fd, 8), RFIFOW(fd, 2), RFIFOL(fd, 4), fd);
+ mapif_GMmessage(RFIFOP(fd,8), RFIFOW(fd,2), RFIFOL(fd,4), fd);
return 0;
}
// Wisp/page request to send
-int mapif_parse_WisRequest(int fd) {
+int mapif_parse_WisRequest(int fd)
+{
struct WisData* wd;
static int wisid = 0;
char name[NAME_LENGTH], t_name[NAME_LENGTH*2]; //Needs space to allocate names with escaped chars [Skotlex]
- RFIFOHEAD(fd);
+
if ( fd <= 0 ) {return 0;} // check if we have a valid fd
if (RFIFOW(fd,2)-52 >= sizeof(wd->msg)) {
@@ -676,7 +679,7 @@ int mapif_parse_WisRequest(int fd) {
mapif_send(fd, buf, 27);
} else {
- CREATE(wd, struct WisData, 1);
+ CREATE(wd, struct WisData, 1);
// Whether the failure of previous wisp/page transmission (timeout)
check_ttl_wisdata();
@@ -703,10 +706,11 @@ int mapif_parse_WisRequest(int fd) {
// Wisp/page transmission result
-int mapif_parse_WisReply(int fd) {
+int mapif_parse_WisReply(int fd)
+{
int id, flag;
struct WisData *wd;
- RFIFOHEAD(fd);
+
id = RFIFOL(fd,2);
flag = RFIFOB(fd,6);
wd = idb_get(wis_db, id);
@@ -722,9 +726,10 @@ int mapif_parse_WisReply(int fd) {
}
// Received wisp message from map-server for ALL gm (just copy the message and resends it to ALL map-servers)
-int mapif_parse_WisToGM(int fd) {
+int mapif_parse_WisToGM(int fd)
+{
unsigned char buf[2048]; // 0x3003/0x3803 <packet_len>.w <wispname>.24B <min_gm_level>.w <message>.?B
- RFIFOHEAD(fd);
+
ShowDebug("Sent packet back!\n");
memcpy(WBUFP(buf,0), RFIFOP(fd,0), RFIFOW(fd,2));
WBUFW(buf, 0) = 0x3803;
@@ -738,7 +743,7 @@ int mapif_parse_Registry(int fd)
{
int j,p,len, max;
struct accreg *reg=accreg_pt;
- RFIFOHEAD(fd);
+
memset(accreg_pt,0,sizeof(struct accreg));
switch (RFIFOB(fd, 12)) {
case 3: //Character registry
@@ -770,26 +775,23 @@ int mapif_parse_Registry(int fd)
// Request the value of all registries.
int mapif_parse_RegistryRequest(int fd)
{
- RFIFOHEAD(fd);
//Load Char Registry
- if (RFIFOB(fd,12))
- mapif_account_reg_reply(fd,RFIFOL(fd,2),RFIFOL(fd,6),3);
+ if (RFIFOB(fd,12)) mapif_account_reg_reply(fd,RFIFOL(fd,2),RFIFOL(fd,6),3);
//Load Account Registry
- if (RFIFOB(fd,11))
- mapif_account_reg_reply(fd,RFIFOL(fd,2),RFIFOL(fd,6),2);
+ if (RFIFOB(fd,11)) mapif_account_reg_reply(fd,RFIFOL(fd,2),RFIFOL(fd,6),2);
//Ask Login Server for Account2 values.
- if (RFIFOB(fd,10))
- request_accreg2(RFIFOL(fd,2),RFIFOL(fd,6)-2);
+ if (RFIFOB(fd,10)) request_accreg2(RFIFOL(fd,2),RFIFOL(fd,6)-2);
return 1;
}
-static void mapif_namechange_ack(int fd, int account_id, int char_id, int type, int flag, char *name){
+static void mapif_namechange_ack(int fd, int account_id, int char_id, int type, int flag, char *name)
+{
WFIFOHEAD(fd, NAME_LENGTH+13);
- WFIFOW(fd, 0) =0x3806;
- WFIFOL(fd, 2) =account_id;
- WFIFOL(fd, 6) =char_id;
- WFIFOB(fd,10) =type;
- WFIFOB(fd,11) =flag;
+ WFIFOW(fd, 0) = 0x3806;
+ WFIFOL(fd, 2) = account_id;
+ WFIFOL(fd, 6) = char_id;
+ WFIFOB(fd,10) = type;
+ WFIFOB(fd,11) = flag;
memcpy(WFIFOP(fd, 12), name, NAME_LENGTH);
WFIFOSET(fd, NAME_LENGTH+13);
}
@@ -800,11 +802,10 @@ int mapif_parse_NameChangeRequest(int fd)
char* name;
int i;
- RFIFOHEAD(fd);
- account_id = RFIFOL(fd, 2);
- char_id = RFIFOL(fd, 6);
- type = RFIFOB(fd, 10);
- name = RFIFOP(fd, 11);
+ account_id = RFIFOL(fd,2);
+ char_id = RFIFOL(fd,6);
+ type = RFIFOB(fd,10);
+ name = RFIFOP(fd,11);
// Check Authorised letters/symbols in the name
if (char_name_option == 1) { // only letters/symbols in char_name_letters are authorised
@@ -833,22 +834,17 @@ int mapif_parse_NameChangeRequest(int fd)
int inter_parse_frommap(int fd)
{
int cmd;
- int len=0;
- RFIFOHEAD(fd);
- cmd=RFIFOW(fd,0);
+ int len = 0;
+ cmd = RFIFOW(fd,0);
// inter鯖管轄かを調べる
- if(cmd < 0x3000 || cmd >= 0x3000 + (sizeof(inter_recv_packet_length)/
- sizeof(inter_recv_packet_length[0]) ) )
+ if(cmd < 0x3000 || cmd >= 0x3000 + ARRAYLENGTH(inter_recv_packet_length) || inter_recv_packet_length[cmd - 0x3000] == 0)
return 0;
- if (inter_recv_packet_length[cmd-0x3000] == 0) //This is necessary, because otherwise we return 2 and the char server will just hang waiting for packets! [Skotlex]
- return 0;
-
// パケット長を調べる
if((len = inter_check_length(fd, inter_recv_packet_length[cmd - 0x3000])) == 0)
return 2;
- switch(cmd){
+ switch(cmd) {
case 0x3000: mapif_parse_GMmessage(fd); break;
case 0x3001: mapif_parse_WisRequest(fd); break;
case 0x3002: mapif_parse_WisReply(fd); break;
@@ -857,17 +853,15 @@ int inter_parse_frommap(int fd)
case 0x3005: mapif_parse_RegistryRequest(fd); break;
case 0x3006: mapif_parse_NameChangeRequest(fd); break;
default:
- if(inter_party_parse_frommap(fd))
- break;
- if(inter_guild_parse_frommap(fd))
- break;
- if(inter_storage_parse_frommap(fd))
+ if( inter_party_parse_frommap(fd)
+ || inter_guild_parse_frommap(fd)
+ || inter_storage_parse_frommap(fd)
+ || inter_pet_parse_frommap(fd)
+ || inter_homunculus_parse_frommap(fd)
+ )
break;
- if(inter_pet_parse_frommap(fd))
- break;
- if(inter_homunculus_parse_frommap(fd)) //albator
- break;
- return 0;
+ else
+ return 0;
}
RFIFOSKIP(fd, len);
@@ -877,9 +871,8 @@ int inter_parse_frommap(int fd)
// RFIFO check
int inter_check_length(int fd, int length)
{
- RFIFOHEAD(fd);
- if(length==-1){ // v-len packet
- if(RFIFOREST(fd)<4) // packet not yet
+ if(length == -1) { // v-len packet
+ if(RFIFOREST(fd) < 4) // packet not yet
return 0;
length = RFIFOW(fd, 2);
}