summaryrefslogtreecommitdiff
path: root/src/char_sql/inter.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/char_sql/inter.c')
-rw-r--r--src/char_sql/inter.c139
1 files changed, 100 insertions, 39 deletions
diff --git a/src/char_sql/inter.c b/src/char_sql/inter.c
index b50afb9d7..83fcc967f 100644
--- a/src/char_sql/inter.c
+++ b/src/char_sql/inter.c
@@ -7,7 +7,7 @@
#include <stdlib.h>
#include "char.h"
-#include "strlib.h"
+#include "../common/strlib.h"
#include "inter.h"
#include "int_party.h"
#include "int_guild.h"
@@ -15,8 +15,6 @@
#include "int_pet.h"
#include "lock.h"
-#define mysql_query(_x, _y) debug_mysql_query(__FILE__, __LINE__, _x, _y)
-
#define WISDATA_TTL (60*1000) // Wisデータの生存時間(60秒)
#define WISDELLIST_MAX 256 // Wisデータ削除リストの要素数
@@ -36,6 +34,11 @@ MYSQL_ROW sql_row ;
int sql_fields, sql_cnt;
char tmp_sql[65535];
+MYSQL lmysql_handle;
+char tmp_lsql[65535];
+MYSQL_RES* lsql_res ;
+MYSQL_ROW lsql_row ;
+
int char_server_port = 3306;
char char_server_ip[32] = "127.0.0.1";
char char_server_id[32] = "ragnarok";
@@ -64,7 +67,7 @@ int inter_send_packet_length[]={
int inter_recv_packet_length[]={
-1,-1, 7, 0, -1, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
6,-1, 0, 0, 0, 0, 0, 0, 10,-1, 0, 0, 0, 0, 0, 0,
- 72, 6,52,14, 10,29, 6,-1, 34, 0, 0, 0, 0, 0, 0, 0,
+ 74, 6,52,14, 10,29, 6,-1, 34, 0, 0, 0, 0, 0, 0, 0,
-1, 6,-1, 0, 55,19, 6,-1, 14,-1,-1,-1, 14,19,186,-1,
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,
@@ -84,20 +87,20 @@ static int wis_dellist[WISDELLIST_MAX], wis_delnum;
//--------------------------------------------------------
// Save account_reg to sql (type=2)
int inter_accreg_tosql(int account_id,struct accreg *reg){
-
+
int j;
char temp_str[32];
if (account_id<=0) return 0;
reg->account_id=account_id;
-
+
//`global_reg_value` (`type`, `account_id`, `char_id`, `str`, `value`)
sprintf(tmp_sql,"DELETE FROM `%s` WHERE `type`=2 AND `account_id`='%d'",reg_db, account_id);
if(mysql_query(&mysql_handle, tmp_sql) ) {
printf("DB server Error (delete `global_reg_value`)- %s\n", mysql_error(&mysql_handle) );
}
-
+
if (reg->reg_num<=0) return 0;
-
+
for(j=0;j<reg->reg_num;j++){
if(reg->reg[j].str != NULL){
sprintf(tmp_sql,"INSERT INTO `%s` (`type`, `account_id`, `str`, `value`) VALUES (2,'%d', '%s','%d')",
@@ -117,7 +120,7 @@ int inter_accreg_fromsql(int account_id,struct accreg *reg)
if (reg==NULL) return 0;
memset(reg, 0, sizeof(struct accreg));
reg->account_id=account_id;
-
+
//`global_reg_value` (`type`, `account_id`, `char_id`, `str`, `value`)
sprintf (tmp_sql, "SELECT `str`, `value` FROM `%s` WHERE `type`=2 AND `account_id`='%d'",reg_db, reg->account_id);
if(mysql_query(&mysql_handle, tmp_sql) ) {
@@ -126,7 +129,7 @@ int inter_accreg_fromsql(int account_id,struct accreg *reg)
sql_res = mysql_store_result(&mysql_handle);
if (sql_res) {
- for(j=0;(sql_row = mysql_fetch_row(sql_res));j++){
+ for(j=0;(sql_row = mysql_fetch_row(sql_res));j++){
memcpy(reg->reg[j].str, sql_row[0],32);
reg->reg[j].value = atoi(sql_row[1]);
}
@@ -141,7 +144,7 @@ int inter_accreg_sql_init()
{
CREATE(accreg_pt, struct accreg, 1);
return 0;
-
+
}
/*==========================================
@@ -187,7 +190,7 @@ 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);
printf ("set login_server_ip : %s\n",w2);
@@ -223,7 +226,7 @@ int inter_config_read(const char *cfgName) {
}
}
fclose(fp);
-
+
printf ("success reading interserver configuration\n");
return 0;
@@ -241,7 +244,7 @@ int inter_log(char *fmt,...)
sprintf(tmp_sql,"INSERT INTO `%s` (`time`, `log`) VALUES (NOW(), '%s')",interlog_db, jstrescapecpy(temp_str,str));
if(mysql_query(&mysql_handle, tmp_sql) ) {
printf("DB server Error (insert `interlog`)- %s\n", mysql_error(&mysql_handle) );
- }
+ }
va_end(ap);
return 0;
@@ -252,37 +255,67 @@ int inter_log(char *fmt,...)
int inter_init(const char *file)
{
//int i;
-
+
printf ("interserver initialize...\n");
inter_config_read(file);
-
+
//DB connection initialized
mysql_init(&mysql_handle);
- printf("Connect to DB server....\n");
+ printf("Connect Character DB server.... (Character Server)\n");
if(!mysql_real_connect(&mysql_handle, char_server_ip, char_server_id, char_server_pw,
- char_server_db ,char_server_port, (char *)NULL, CLIENT_MULTI_STATEMENTS)) {
+ char_server_db ,char_server_port, (char *)NULL, 0)) {
//pointer check
printf("%s\n",mysql_error(&mysql_handle));
exit(1);
}
else {
- printf ("Connect Success!\n");
+ printf ("Connect Success! (Character Server)\n");
+ }
+
+ mysql_init(&lmysql_handle);
+ printf("Connect Character DB server.... (login server)\n");
+ if(!mysql_real_connect(&lmysql_handle, login_server_ip, login_server_id, login_server_pw,
+ login_server_db ,login_server_port, (char *)NULL, 0)) {
+ //pointer check
+ printf("%s\n",mysql_error(&lmysql_handle));
+ exit(1);
+ }else {
+ printf ("Connect Success! (Login Server)");
}
-
wis_db = numdb_init();
inter_guild_sql_init();
inter_storage_sql_init();
inter_party_sql_init();
-
+
inter_pet_sql_init();
inter_accreg_sql_init();
+ atexit(inter_final);
+
//printf ("interserver timer initializing : %d sec...\n",autosave_interval);
//i=add_timer_interval(gettick()+autosave_interval,inter_save_timer,0,0,autosave_interval);
return 0;
}
+// finalize
+int wis_db_final (void *k, void *data, va_list ap) {
+ struct WisData *p = (struct WisData *) data;
+ if (p) aFree(p);
+ return 0;
+}
+void inter_final() {
+ numdb_final(wis_db, wis_db_final);
+
+ inter_guild_sql_final();
+ inter_storage_sql_final();
+ inter_party_sql_final();
+ inter_pet_sql_final();
+
+ if (accreg_pt) aFree(accreg_pt);
+ return;
+}
+
int inter_mapif_init(int fd) {
inter_guild_mapif_init(fd);
@@ -293,13 +326,13 @@ int inter_mapif_init(int fd) {
//--------------------------------------------------------
// GM message sending
-int mapif_GMmessage(unsigned char *mes, int len) {
+int mapif_GMmessage(unsigned char *mes, int len, int sfd) {
unsigned char buf[len];
WBUFW(buf, 0) = 0x3800;
WBUFW(buf, 2) = len;
memcpy(WBUFP(buf, 4), mes, len-4);
- mapif_sendall(buf, len);
+ mapif_sendallwos(sfd, buf, len);
printf("\033[1;34m inter server: GM[len:%d] - '%s' \033[0m\n", len, mes);
return 0;
}
@@ -322,7 +355,7 @@ int mapif_wis_message(struct WisData *wd) {
int mapif_wis_end(struct WisData *wd,int flag)
{
unsigned char buf[27];
-
+
WBUFW(buf, 0)=0x3802;
memcpy(WBUFP(buf, 2),wd->src,24);
WBUFB(buf,26)=flag;
@@ -345,7 +378,7 @@ int mapif_account_reg_reply(int fd,int account_id)
{
struct accreg *reg=accreg_pt;
inter_accreg_fromsql(account_id,reg);
-
+
WFIFOW(fd,0)=0x3804;
WFIFOL(fd,4)=account_id;
if(reg->reg_num==0){
@@ -362,6 +395,27 @@ int mapif_account_reg_reply(int fd,int account_id)
return 0;
}
+int mapif_send_gmaccounts()
+{
+ int i, len = 4;
+ unsigned char buf[32000];
+
+ // forward the gm accounts to the map server
+ len = 4;
+ 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;
+ len += 5;
+ }
+ WBUFW(buf, 2) = len;
+ mapif_sendall(buf, len);
+
+ return 0;
+}
+
+
//--------------------------------------------------------
// Existence check of WISP data
@@ -384,12 +438,12 @@ int check_ttl_wisdata() {
wis_delnum = 0;
numdb_foreach(wis_db, check_ttl_wisdata_sub, tick);
for(i = 0; i < wis_delnum; i++) {
- struct WisData *wd = numdb_search(wis_db, wis_dellist[i]);
+ struct WisData *wd = (struct WisData*)numdb_search(wis_db, wis_dellist[i]);
printf("inter: wis data id=%d time out : from %s to %s\n", wd->id, wd->src, wd->dst);
// removed. not send information after a timeout. Just no answer for the player
//mapif_wis_end(wd, 1); // flag: 0: success to send wisper, 1: target character is not loged in?, 2: ignored by target
numdb_erase(wis_db, wd->id);
- free(wd);
+ aFree(wd);
}
} while(wis_delnum >= WISDELLIST_MAX);
@@ -401,7 +455,7 @@ int check_ttl_wisdata() {
// GM message sending
int mapif_parse_GMmessage(int fd)
{
- mapif_GMmessage(RFIFOP(fd, 4), RFIFOW(fd, 2));
+ mapif_GMmessage(RFIFOP(fd, 4), RFIFOW(fd, 2), fd);
return 0;
}
@@ -410,6 +464,7 @@ int mapif_parse_GMmessage(int fd)
int mapif_parse_WisRequest(int fd) {
struct WisData* wd;
static int wisid = 0;
+ char t_name[32];
if (RFIFOW(fd,2)-52 >= sizeof(wd->msg)) {
printf("inter: Wis message size too long.\n");
@@ -418,7 +473,8 @@ int mapif_parse_WisRequest(int fd) {
printf("inter: Wis message doesn't exist.\n");
return 0;
}
- sprintf (tmp_sql, "SELECT `name` FROM `%s` WHERE `char_id`='%d'",char_db, (int) RFIFOP(fd,28));
+ sprintf (tmp_sql, "SELECT `name` FROM `%s` WHERE `name`='%s'",
+ char_db, jstrescapecpy(t_name, (char *)RFIFOP(fd,28)));
if(mysql_query(&mysql_handle, tmp_sql) ) {
printf("DB server Error - %s\n", mysql_error(&mysql_handle) );
}
@@ -435,9 +491,9 @@ int mapif_parse_WisRequest(int fd) {
} else {
// to be sure of the correct name, rewrite it
memset(RFIFOP(fd,28), 0, 24);
- strncpy(RFIFOP(fd,28), sql_row[0], 24);
+ strncpy((char*)RFIFOP(fd,28), sql_row[0], 24);
// if source is destination, don't ask other servers.
- if (strcmp(RFIFOP(fd,4),RFIFOP(fd,28)) == 0) {
+ if (strcmp((char*)RFIFOP(fd,4),(char*)RFIFOP(fd,28)) == 0) {
unsigned char buf[27];
WBUFW(buf, 0) = 0x3802;
memcpy(WBUFP(buf, 2), RFIFOP(fd, 4), 24);
@@ -461,7 +517,12 @@ int mapif_parse_WisRequest(int fd) {
mapif_wis_message(wd);
}
}
-
+
+ //Freeing ... O.o
+ if(sql_res){
+ mysql_free_result(sql_res);
+ }
+
return 0;
}
@@ -469,7 +530,7 @@ int mapif_parse_WisRequest(int fd) {
// Wisp/page transmission result
int mapif_parse_WisReply(int fd) {
int id = RFIFOL(fd,2), flag = RFIFOB(fd,6);
- struct WisData *wd = numdb_search(wis_db, id);
+ struct WisData *wd = (struct WisData*)numdb_search(wis_db, id);
if (wd == NULL)
return 0; // This wisp was probably suppress before, because it was timeout of because of target was found on another map-server
@@ -477,7 +538,7 @@ int mapif_parse_WisReply(int fd) {
if ((--wd->count) <= 0 || flag != 1) {
mapif_wis_end(wd, flag); // flag: 0: success to send wisper, 1: target character is not loged in?, 2: ignored by target
numdb_erase(wis_db, id);
- free(wd);
+ aFree(wd);
}
return 0;
@@ -491,13 +552,13 @@ int mapif_parse_AccReg(int fd)
struct accreg *reg=accreg_pt;
int account_id = RFIFOL(fd,4);
memset(accreg_pt,0,sizeof(struct accreg));
-
+
for(j=0,p=8;j<ACCOUNT_REG_NUM && p<RFIFOW(fd,2);j++,p+=36){
memcpy(reg->reg[j].str,RFIFOP(fd,p),32);
reg->reg[j].value=RFIFOL(fd,p+32);
}
reg->reg_num=j;
-
+
inter_accreg_tosql(account_id,reg);
mapif_account_reg(fd,RFIFOP(fd,0)); // Send confirm message to map
return 0;
@@ -526,7 +587,7 @@ int inter_parse_frommap(int fd)
// パケット長を調べる
if( (len=inter_check_length(fd,inter_recv_packet_length[cmd-0x3000]))==0 )
return 2;
-
+
switch(cmd){
case 0x3000: mapif_parse_GMmessage(fd); break;
case 0x3001: mapif_parse_WisRequest(fd); break;
@@ -556,9 +617,9 @@ int inter_check_length(int fd, int length)
return 0;
length = RFIFOW(fd, 2);
}
-
+
if(RFIFOREST(fd)<length) // packet not yet
return 0;
-
+
return length;
}