summaryrefslogtreecommitdiff
path: root/src/txt-converter
diff options
context:
space:
mode:
authorFlavioJS <FlavioJS@54d463be-8e91-2dee-dedb-b68131a5f0ec>2007-09-20 11:09:36 +0000
committerFlavioJS <FlavioJS@54d463be-8e91-2dee-dedb-b68131a5f0ec>2007-09-20 11:09:36 +0000
commit5245e666a09df5f401c1329bf5ee1fc1b09b1d16 (patch)
treedcf032743e890fddd400b268b75a0868976b0a0b /src/txt-converter
parentd23c508bcc38520970156e5e25f14b03714878eb (diff)
downloadhercules-5245e666a09df5f401c1329bf5ee1fc1b09b1d16.tar.gz
hercules-5245e666a09df5f401c1329bf5ee1fc1b09b1d16.tar.bz2
hercules-5245e666a09df5f401c1329bf5ee1fc1b09b1d16.tar.xz
hercules-5245e666a09df5f401c1329bf5ee1fc1b09b1d16.zip
* Merged the tmpsql branch:
- Abstraction for the sql code (sql.c/h). - New configure script and makefiles. - Restored txt zeny logging code. (r10814) - Rewrote mapserver's sql code - itemdb, mobdb, mapreg, logs. (r10814) - Fixed a precedence issue (&& and ) in char_sql/char.c. (r10833) - Improved db reading code a bit for consistency. (r11077) - Added separate atcommand for mail deletion. (r11077) - Corrected a few messages that said "new" instead of "unread". (r11077) - Broadcast (*) messages now use "*" as the target's name (not ""). (r11077) - Moved StringBuf code from utils.c/h to strlib.c/h. (r11084 r11117) - Some misc login server cleanups (reformatting etc). (r11136) - Corrected/modified some header entries. (r11141 r11147 11148) - Adjusted VS project files. (r11147) - Adjusted the way the sql charserver does item saving. (r11192) - Corrected usage of reserved keyword 'friend' in mmo.h. (r11192) git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@11245 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/txt-converter')
-rw-r--r--src/txt-converter/Makefile24
-rw-r--r--src/txt-converter/Makefile.in68
-rw-r--r--src/txt-converter/char-converter.c1
-rw-r--r--src/txt-converter/login-converter.c39
4 files changed, 90 insertions, 42 deletions
diff --git a/src/txt-converter/Makefile b/src/txt-converter/Makefile
deleted file mode 100644
index 419029e19..000000000
--- a/src/txt-converter/Makefile
+++ /dev/null
@@ -1,24 +0,0 @@
-all sql: char-converter login-converter
-
-char-converter: char-converter.o ../common/obj/minicore.o \
- ../common/obj/malloc.o ../common/obj/showmsg.o ../common/obj/strlib.o \
- ../common/obj/mapindex.o ../common/obj/ers.o ../common/obj/utils.o \
- ../char/char.o ../char/int_pet.o ../char/int_storage.o ../char/inter.o \
- ../char/int_party.o ../char/int_guild.o \
- ../char_sql/char.o ../char_sql/int_pet.o ../char_sql/int_storage.o \
- ../char_sql/inter.o ../char_sql/int_party.o ../char_sql/int_guild.o
- $(CC) -o ../../tools/$@ $^ $(LIB_S)
-
-login-converter: login-converter.o ../common/obj/minicore.o ../common/obj/db.o ../common/obj/malloc.o ../common/obj/showmsg.o ../common/obj/ers.o ../common/obj/utils.o
- $(CC) -o ../../tools/$@ $^ $(LIB_S)
-
-clean:
- rm -f *.o ../../tools/login-converter ../../tools/char-converter GNUmakefile
-
-# DO NOT DELETE
-
-%.o: %.c
- $(COMPILE.c) -DTXT_SQL_CONVERT $(OUTPUT_OPTION) $<
-
-char-converter.o: char-converter.c
-login-converter.o: login-converter.c
diff --git a/src/txt-converter/Makefile.in b/src/txt-converter/Makefile.in
new file mode 100644
index 000000000..31d593743
--- /dev/null
+++ b/src/txt-converter/Makefile.in
@@ -0,0 +1,68 @@
+LOGIN_CONVERTER_OBJ = login-converter.o ../common/obj/minicore.o \
+ ../common/obj/malloc.o ../common/obj/strlib.o ../common/obj/showmsg.o \
+ ../common/obj/utils.o ../common/obj/ers.o ../common/obj/db.o \
+ ../common/obj_sql/sql.o
+CHAR_CONVERTER_OBJ = char-converter.o ../common/obj/minicore.o \
+ ../common/obj/malloc.o ../common/obj/strlib.o ../common/obj/showmsg.o \
+ ../common/obj/utils.o ../common/obj/ers.o ../common/obj/mapindex.o \
+ ../common/obj_sql/sql.o \
+ obj_txt/char.o obj_txt/int_pet.o obj_txt/int_storage.o obj_txt/inter.o \
+ obj_txt/int_party.o obj_txt/int_guild.o \
+ obj_sql/char.o obj_sql/int_pet.o obj_sql/int_storage.o \
+ obj_sql/inter.o obj_sql/int_party.o obj_sql/int_guild.o
+
+HAVE_MYSQL=@HAVE_MYSQL@
+ifeq ($(HAVE_MYSQL),yes)
+ LOGIN_CONVERTER_DEPENDS=$(LOGIN_CONVERTER_OBJ)
+ CHAR_CONVERTER_DEPENDS=obj $(CHAR_CONVERTER_OBJ)
+else
+ LOGIN_CONVERTER_DEPENDS=needs_mysql
+ CHAR_CONVERTER_DEPENDS=needs_mysql
+endif
+
+#####################################################################
+.PHONY : all login-converter char-converter clean help
+
+all: login-converter char-converter
+
+login-converter: $(LOGIN_CONVERTER_DEPENDS)
+ @CC@ @LDFLAGS@ -o ../../tools/login-converter@EXEEXT@ $(LOGIN_CONVERTER_OBJ) @LIBS@ @MYSQL_LIBS@
+
+char-converter: $(CHAR_CONVERTER_DEPENDS)
+ @CC@ @LDFLAGS@ -o ../../tools/char-converter@EXEEXT@ $(CHAR_CONVERTER_OBJ) @LIBS@ @MYSQL_LIBS@
+
+clean:
+ rm -rf *.o obj_txt obj_sql ../../tools/login-converter@EXEEXT@ ../../tools/char-converter@EXEEXT@
+
+help:
+ @echo "possible targets are 'login-converter' 'char-converter' 'all' 'clean' 'help'"
+ @echo "'login-converter' - login server converter"
+ @echo "'char-converter' - char server converter"
+ @echo "'all' - builds all above targets"
+ @echo "'clean' - cleans builds and objects"
+ @echo "'help' - outputs this message"
+
+#####################################################################
+
+needs_mysql:
+ @echo "MySQL not found or disabled by the configure script"
+ @exit 1
+
+obj:
+ -mkdir obj_txt
+ -mkdir obj_sql
+
+
+# DO NOT DELETE
+
+%.o: %.c
+ @CC@ @CFLAGS@ @MYSQL_CFLAGS@ @CPPFLAGS@ -DTXT_SQL_CONVERT -c $(OUTPUT_OPTION) $<
+
+obj_txt/%.o: ../char/%.c
+ @CC@ @CFLAGS@ @MYSQL_CFLAGS@ @CPPFLAGS@ -DTXT_SQL_CONVERT -c $(OUTPUT_OPTION) $<
+
+obj_sql/%.o: ../char_sql/%.c
+ @CC@ @CFLAGS@ @MYSQL_CFLAGS@ @CPPFLAGS@ -DTXT_SQL_CONVERT -c $(OUTPUT_OPTION) $<
+
+char-converter.o: char-converter.c
+login-converter.o: login-converter.c
diff --git a/src/txt-converter/char-converter.c b/src/txt-converter/char-converter.c
index 63c261604..8168e0ee3 100644
--- a/src/txt-converter/char-converter.c
+++ b/src/txt-converter/char-converter.c
@@ -7,6 +7,7 @@
#include "../common/strlib.h"
#include "../common/showmsg.h"
#include "../common/mapindex.h"
+#include "../common/utils.h"
#include "../char/char.h"
#include "../char/int_storage.h"
diff --git a/src/txt-converter/login-converter.c b/src/txt-converter/login-converter.c
index 6c194b9d5..114ec7735 100644
--- a/src/txt-converter/login-converter.c
+++ b/src/txt-converter/login-converter.c
@@ -6,16 +6,12 @@
#include "../common/core.h"
#include "../common/db.h"
#include "../common/showmsg.h"
+#include "../common/sql.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#ifdef WIN32
-#include <winsock2.h>
-#endif
-#include <mysql.h>
-
char login_account_id[256]="account_id";
char login_userid[256]="userid";
char login_user_pass[256]="user_pass";
@@ -90,8 +86,8 @@ int read_gm_account()
int convert_login(void)
{
- MYSQL mysql_handle;
- char tmpsql[1024];
+ Sql* mysql_handle;
+ SqlStmt* stmt;
int line_counter = 0;
FILE *fp;
int account_id, logincount, user_level, state, n, i;
@@ -100,11 +96,12 @@ int convert_login(void)
time_t connect_until_time;
char dummy[2048];
- mysql_init(&mysql_handle);
- if(!mysql_real_connect(&mysql_handle, db_server_ip, db_server_id, db_server_pw, db_server_logindb ,db_server_port, (char *)NULL, 0)) {
- //pointer check
- printf("%s\n",mysql_error(&mysql_handle));
- exit(1);
+ mysql_handle = Sql_Malloc();
+ if ( SQL_ERROR == Sql_Connect(mysql_handle, db_server_id, db_server_pw, db_server_ip, db_server_port, db_server_logindb) )
+ {
+ Sql_ShowDebug(mysql_handle);
+ Sql_Free(mysql_handle);
+ exit(1);
}
ShowStatus("Connect: Success!\n");
@@ -133,21 +130,27 @@ int convert_login(void)
user_level = isGM(account_id);
ShowInfo("Converting user (id: %d, name: %s, gm level: %d)\n", account_id, userid, user_level);
- sprintf(tmpsql,
+
+ stmt = SqlStmt_Malloc(mysql_handle);
+ if( SQL_ERROR == SqlStmt_Prepare(stmt,
"REPLACE INTO `login` "
"(`account_id`, `userid`, `user_pass`, `lastlogin`, `sex`, `logincount`, `email`, `level`, `error_message`, `connect_until`, `last_ip`, `memo`, `ban_until`, `state`) "
"VALUES "
- "(%d, '%s', '%s', '%s', '%c', %d, '%s', %d, '%s', %u, '%s', '%s', %u, %d)",
- account_id , userid, pass, lastlogin, sex, logincount, email, user_level, error_message, (uint32)connect_until_time, last_ip, memo, (uint32)ban_until_time, state);
- if(mysql_query(&mysql_handle, tmpsql) ) {
- ShowError("DB server Error - %s\n", mysql_error(&mysql_handle) );
- ShowError("Query: %s\n", tmpsql);
+ "(%d, ?, ?, '%s', '%c', %d, '%s', %d, '%s', %u, '%s', '%s', %u, %d)",
+ account_id, lastlogin, sex, logincount, email, user_level, error_message, (uint32)connect_until_time, last_ip, memo, (uint32)ban_until_time, state)
+ || SQL_ERROR == SqlStmt_BindParam(stmt, 0, SQLDT_STRING, userid, strnlen(userid, 255))
+ || SQL_ERROR == SqlStmt_BindParam(stmt, 1, SQLDT_STRING, pass, strnlen(pass, 32))
+ || SQL_ERROR == SqlStmt_Execute(stmt) )
+ {
+ SqlStmt_ShowDebug(stmt);
}
+ SqlStmt_Free(stmt);
//TODO: parse the rest of the line to read the login-stored account variables, and import them to `global_reg_value`
// then remove the 'dummy' buffer
}
fclose(fp);
+ Sql_Free(mysql_handle);
ShowStatus("Convert end...\n");