summaryrefslogtreecommitdiff
path: root/src/map
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/map
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/map')
-rw-r--r--src/map/Makefile103
-rw-r--r--src/map/Makefile.in148
-rw-r--r--src/map/atcommand.c41
-rw-r--r--src/map/battle.c1
-rw-r--r--src/map/charcommand.c1
-rw-r--r--src/map/clif.c1
-rw-r--r--src/map/guild.c6
-rw-r--r--src/map/intif.c2
-rw-r--r--src/map/itemdb.c496
-rw-r--r--src/map/log.c392
-rw-r--r--src/map/log.h8
-rw-r--r--src/map/mail.c464
-rw-r--r--src/map/mail.h4
-rw-r--r--src/map/map.c138
-rw-r--r--src/map/map.h53
-rw-r--r--src/map/mob.c112
-rw-r--r--src/map/npc.c1
-rw-r--r--src/map/party.c1
-rw-r--r--src/map/pc.c3
-rw-r--r--src/map/pet.c1
-rw-r--r--src/map/script.c372
-rw-r--r--src/map/skill.c1
-rw-r--r--src/map/status.c1
23 files changed, 1166 insertions, 1184 deletions
diff --git a/src/map/Makefile b/src/map/Makefile
deleted file mode 100644
index dcb14bb3a..000000000
--- a/src/map/Makefile
+++ /dev/null
@@ -1,103 +0,0 @@
-all txt: txtobj map-server
-
-sql: sqlobj map-server_sql
-
-txtobj:
- mkdir txtobj
-
-sqlobj:
- mkdir sqlobj
-
-COMMON_OBJ = ../common/obj/core.o ../common/obj/socket.o ../common/obj/timer.o \
- ../common/obj/db.o ../common/obj/plugins.o ../common/obj/lock.o \
- ../common/obj/nullpo.o ../common/obj/malloc.o ../common/obj/showmsg.o \
- ../common/obj/utils.o ../common/obj/strlib.o ../common/obj/grfio.o \
- ../common/obj/mapindex.o ../common/obj/ers.o
-
-COMMON_H = ../common/core.h ../common/socket.h ../common/timer.h ../common/db.h \
- ../common/plugins.h ../common/lock.h ../common/nullpo.h ../common/malloc.h \
- ../common/showmsg.h ../common/utils.h ../common/strlib.h ../common/grfio.h \
- ../common/mapindex.h
-
-OBJECTS = obj/map.o obj/chrif.o obj/clif.o obj/pc.o obj/status.o obj/npc.o \
- obj/npc_chat.o obj/chat.o obj/path.o obj/itemdb.o obj/mob.o obj/script.o \
- obj/storage.o obj/skill.o obj/atcommand.o obj/charcommand.o obj/battle.o \
- obj/intif.o obj/trade.o obj/party.o obj/vending.o obj/guild.o obj/pet.o \
- obj/log.o obj/mail.o obj/date.o obj/irc.o obj/unit.o obj/mercenary.o \
- $(COMMON_OBJ)
-
-map-server: $(OBJECTS:obj/%=txtobj/%)
- $(CC) -o ../../$@ $> $(LIBS) $(LIB_S)
-
-map-server_sql: $(OBJECTS:obj/%=sqlobj/%)
- $(CC) -o ../../$@ $> $(LIB_S)
-
-txtobj/%.o: %.c
- $(COMPILE.c) -DTXT_ONLY $(OUTPUT_OPTION) $<
-
-sqlobj/%.o: %.c
- $(COMPILE.c) $(OUTPUT_OPTION) $<
-
-clean:
- rm -rf *.o ../../map-server ../../map-server_sql sqlobj txtobj GNUmakefile
-
-# DO NOT DELETE
-
-txtobj/map.o: map.c map.h chrif.h clif.h npc.h pc.h mob.h chat.h skill.h itemdb.h storage.h party.h pet.h atcommand.h irc.h $(COMMON_H)
-txtobj/chrif.o: chrif.c map.h battle.h chrif.h clif.h intif.h pc.h npc.h $(COMMON_H)
-txtobj/clif.o: clif.c map.h chrif.h clif.h mob.h intif.h pc.h npc.h itemdb.h chat.h script.h storage.h party.h guild.h atcommand.h pet.h charcommand.h irc.h $(COMMON_H)
-txtobj/pc.o: pc.c map.h clif.h intif.h pc.h npc.h mob.h itemdb.h battle.h skill.h script.h party.h guild.h pet.h trade.h storage.h chat.h vending.h $(COMMON_H)
-txtobj/status.o: status.c pc.h map.h clif.h status.h mob.h itemdb.h battle.h skill.h script.h pet.h guild.h $(COMMON_H)
-txtobj/npc.o: npc.c map.h npc.h clif.h pc.h script.h mob.h itemdb.h battle.h $(COMMON_H)
-txtobj/npc_chat.o: npc_chat.c map.h npc.h clif.h pc.h script.h mob.h itemdb.h battle.h $(COMMON_H)
-txtobj/chat.o: chat.c map.h clif.h pc.h chat.h $(COMMON_H)
-txtobj/path.o: path.c map.h battle.h $(COMMON_H)
-txtobj/itemdb.o: itemdb.c map.h battle.h itemdb.h $(COMMON_H)
-txtobj/mob.o: mob.c map.h clif.h intif.h pc.h mob.h skill.h battle.h npc.h itemdb.h date.h irc.h $(COMMON_H)
-txtobj/script.o: script.c itemdb.h map.h pc.h mob.h clif.h intif.h npc.h script.h storage.h skill.h pet.h battle.h log.h irc.h $(COMMON_H)
-txtobj/storage.o: storage.c itemdb.h pc.h clif.h intif.h storage.h guild.h $(COMMON_H)
-txtobj/skill.o: skill.c skill.h map.h clif.h pc.h mob.h battle.h itemdb.h script.h date.h $(COMMON_H)
-txtobj/atcommand.o: atcommand.c atcommand.h itemdb.h pc.h map.h skill.h clif.h mob.h intif.h battle.h storage.h guild.h pet.h log.h $(COMMON_H)
-txtobj/battle.o: battle.c battle.h skill.h map.h mob.h pc.h pet.h guild.h $(COMMON_H)
-txtobj/intif.o: intif.c intif.h chrif.h clif.h party.h guild.h storage.h map.h battle.h pet.h $(COMMON_H)
-txtobj/trade.o: trade.c trade.h clif.h itemdb.h map.h pc.h npc.h $(COMMON_H)
-txtobj/party.o: party.c party.h clif.h intif.h pc.h map.h battle.h $(COMMON_H)
-txtobj/vending.o: vending.c vending.h clif.h itemdb.h map.h pc.h irc.h $(COMMON_H)
-txtobj/guild.o: guild.c guild.h storage.h battle.h clif.h intif.h pc.h npc.h map.h $(COMMON_H)
-txtobj/pet.o: pet.c pet.h map.h clif.h chrif.h intif.h pc.h itemdb.h battle.h mob.h npc.h script.h $(COMMON_H)
-txtobj/log.o: log.c log.h map.h $(COMMON_H)
-txtobj/charcommand.o: charcommand.c charcommand.h itemdb.h pc.h map.h skill.h clif.h mob.h intif.h battle.h storage.h guild.h pet.h log.h $(COMMON_H)
-txtobj/date.o: date.c date.h $(COMMON_H)
-txtobj/irc.o: irc.c irc.h map.h pc.h $(COMMON_H)
-txtobj/unit.o: unit.c unit.h $(COMMON_H)
-txtobj/mercenary.o: mercenary.c mercenary.h $(COMMON_H)
-
-sqlobj/map.o: map.c map.h chrif.h clif.h npc.h pc.h mob.h chat.h skill.h itemdb.h storage.h party.h pet.h atcommand.h log.h irc.h $(COMMON_H)
-sqlobj/chrif.o: chrif.c map.h battle.h chrif.h clif.h intif.h pc.h npc.h $(COMMON_H)
-sqlobj/clif.o: clif.c map.h chrif.h clif.h mob.h intif.h pc.h npc.h itemdb.h chat.h script.h storage.h party.h guild.h atcommand.h pet.h charcommand.h $(COMMON_H)
-sqlobj/pc.o: pc.c map.h clif.h intif.h pc.h npc.h mob.h itemdb.h battle.h skill.h script.h party.h guild.h pet.h trade.h storage.h chat.h vending.h log.h $(COMMON_H)
-sqlobj/status.o: status.c pc.h map.h clif.h status.h mob.h itemdb.h battle.h skill.h script.h pet.h guild.h $(COMMON_H)
-sqlobj/npc.o: npc.c map.h npc.h clif.h pc.h script.h mob.h itemdb.h battle.h $(COMMON_H)
-sqlobj/npc_chat.o: npc_chat.c map.h npc.h clif.h pc.h script.h mob.h itemdb.h battle.h $(COMMON_H)
-sqlobj/chat.o: chat.c map.h clif.h pc.h chat.h $(COMMON_H)
-sqlobj/path.o: path.c map.h battle.h $(COMMON_H)
-sqlobj/itemdb.o: itemdb.c map.h battle.h itemdb.h $(COMMON_H)
-sqlobj/mob.o: mob.c map.h clif.h intif.h pc.h mob.h skill.h battle.h npc.h itemdb.h log.h date.h irc.h $(COMMON_H)
-sqlobj/script.o: script.c itemdb.h map.h pc.h mob.h clif.h intif.h npc.h script.h storage.h skill.h pet.h battle.h log.h irc.h $(COMMON_H)
-sqlobj/storage.o: storage.c itemdb.h pc.h clif.h intif.h storage.h guild.h $(COMMON_H)
-sqlobj/skill.o: skill.c skill.h map.h clif.h pc.h mob.h battle.h itemdb.h script.h log.h date.h $(COMMON_H)
-sqlobj/atcommand.o: atcommand.c atcommand.h itemdb.h pc.h map.h skill.h clif.h mob.h intif.h battle.h storage.h guild.h pet.h log.h $(COMMON_H)
-sqlobj/battle.o: battle.c battle.h skill.h map.h mob.h pc.h pet.h guild.h $(COMMON_H)
-sqlobj/intif.o: intif.c intif.h chrif.h clif.h party.h guild.h storage.h map.h battle.h pet.h $(COMMON_H)
-sqlobj/trade.o: trade.c trade.h clif.h itemdb.h map.h pc.h npc.h log.h $(COMMON_H)
-sqlobj/party.o: party.c party.h clif.h intif.h pc.h map.h battle.h $(COMMON_H)
-sqlobj/vending.o: vending.c vending.h clif.h itemdb.h map.h pc.h log.h irc.h $(COMMON_H)
-sqlobj/guild.o: guild.c guild.h storage.h battle.h clif.h intif.h pc.h npc.h map.h irc.h $(COMMON_H)
-sqlobj/pet.o: pet.c pet.h map.h clif.h chrif.h intif.h pc.h itemdb.h battle.h mob.h npc.h script.h $(COMMON_H)
-sqlobj/mail.o: mail.c mail.h $(COMMON_H)
-sqlobj/log.o: log.c log.h map.h $(COMMON_H)
-sqlobj/charcommand.o: charcommand.c charcommand.h itemdb.h pc.h map.h skill.h clif.h mob.h intif.h battle.h storage.h guild.h pet.h log.h $(COMMON_H)
-sqlobj/date.o: date.c date.h $(COMMON_H)
-sqlobj/irc.o: irc.c irc.h map.h pc.h $(COMMON_H)
-sqlobj/unit.o: unit.c unit.h $(COMMON_H)
-sqlobj/mercenary.o: mercenary.c mercenary.h $(COMMON_H)
diff --git a/src/map/Makefile.in b/src/map/Makefile.in
new file mode 100644
index 000000000..1be112d9a
--- /dev/null
+++ b/src/map/Makefile.in
@@ -0,0 +1,148 @@
+
+HAVE_MYSQL=@HAVE_MYSQL@
+ifeq ($(HAVE_MYSQL),yes)
+ ALL_DEPENDS=txt sql
+ SQL_DEPENDS=obj_sql map-server_sql
+else
+ ALL_TARGET=txt
+ SQL_DEPENDS=needs_mysql
+endif
+
+HAVE_PCRE=@HAVE_PCRE@
+ifeq ($(HAVE_PCRE),yes)
+ PCRE_CFLAGS=-DPCRE_SUPPORT @PCRE_CFLAGS@
+else
+ PCRE_CFLAGS=
+endif
+
+
+#####################################################################
+.PHONY : all txt sql clean help
+
+all: $(ALL_DEPENDS)
+
+txt: obj_txt map-server
+
+sql: $(SQL_DEPENDS)
+
+clean:
+ rm -rf *.o ../../map-server@EXEEXT@ ../../map-server_sql@EXEEXT@ obj_txt obj_sql
+
+help:
+ifeq ($(HAVE_MYSQL),yes)
+ @echo "possible targets are 'sql' 'txt' 'all' 'clean' 'help'"
+ @echo "'sql' - map server (SQL version)"
+else
+ @echo "possible targets are 'txt' 'all' 'clean' 'help'"
+endif
+ @echo "'txt' - map server (TXT version)"
+ @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_txt:
+ -mkdir obj_txt
+
+obj_sql:
+ -mkdir obj_sql
+
+COMMON_OBJ = ../common/obj/core.o ../common/obj/socket.o ../common/obj/timer.o \
+ ../common/obj/db.o ../common/obj/plugins.o ../common/obj/lock.o \
+ ../common/obj/nullpo.o ../common/obj/malloc.o ../common/obj/showmsg.o \
+ ../common/obj/utils.o ../common/obj/strlib.o ../common/obj/grfio.o \
+ ../common/obj/mapindex.o ../common/obj/ers.o
+
+COMMON_H = ../common/core.h ../common/socket.h ../common/timer.h \
+ ../common/db.h ../common/plugins.h ../common/lock.h \
+ ../common/nullpo.h ../common/malloc.h ../common/showmsg.h \
+ ../common/utils.h ../common/strlib.h ../common/grfio.h \
+ ../common/mapindex.h ../common/ers.h
+
+COMMON_SQL_OBJ = $(COMMON_OBJ) ../common/obj_sql/sql.o
+
+COMMON_SQL_H = $(COMMON_H) ../common/sql.h
+
+MAP_OBJ = obj/map.o obj/chrif.o obj/clif.o obj/pc.o obj/status.o obj/npc.o \
+ obj/npc_chat.o obj/chat.o obj/path.o obj/itemdb.o obj/mob.o obj/script.o \
+ obj/storage.o obj/skill.o obj/atcommand.o obj/charcommand.o obj/battle.o \
+ obj/intif.o obj/trade.o obj/party.o obj/vending.o obj/guild.o obj/pet.o \
+ obj/log.o obj/mail.o obj/date.o obj/irc.o obj/unit.o obj/mercenary.o
+
+map-server: $(MAP_OBJ:obj/%=obj_txt/%) $(COMMON_OBJ)
+ @CC@ @LDFLAGS@ -o ../../map-server@EXEEXT@ $(MAP_OBJ:obj/%=obj_txt/%) $(COMMON_OBJ) @LIBS@ @PCRE_LIBS@
+
+map-server_sql: $(MAP_OBJ:obj/%=obj_sql/%) $(COMMON_SQL_OBJ)
+ @CC@ @LDFLAGS@ -o ../../map-server_sql@EXEEXT@ $(MAP_OBJ:obj/%=obj_sql/%) $(COMMON_SQL_OBJ) @LIBS@ @PCRE_LIBS@ @MYSQL_LIBS@
+
+obj_txt/%.o: %.c
+ @CC@ @CFLAGS@ $(PCRE_CFLAGS) -DTXT_ONLY @CPPFLAGS@ -c $(OUTPUT_OPTION) $<
+
+obj_sql/%.o: %.c
+ @CC@ @CFLAGS@ $(PCRE_CFLAGS) @MYSQL_CFLAGS@ @CPPFLAGS@ -c $(OUTPUT_OPTION) $<
+
+# DO NOT DELETE
+
+obj_txt/map.o: map.c map.h chrif.h clif.h npc.h pc.h mob.h chat.h skill.h itemdb.h storage.h party.h pet.h atcommand.h irc.h $(COMMON_H)
+obj_txt/chrif.o: chrif.c map.h battle.h chrif.h clif.h intif.h pc.h npc.h $(COMMON_H)
+obj_txt/clif.o: clif.c map.h chrif.h clif.h mob.h intif.h pc.h npc.h itemdb.h chat.h script.h storage.h party.h guild.h atcommand.h pet.h charcommand.h irc.h $(COMMON_H)
+obj_txt/pc.o: pc.c map.h clif.h intif.h pc.h npc.h mob.h itemdb.h battle.h skill.h script.h party.h guild.h pet.h trade.h storage.h chat.h vending.h $(COMMON_H)
+obj_txt/status.o: status.c pc.h map.h clif.h status.h mob.h itemdb.h battle.h skill.h script.h pet.h guild.h $(COMMON_H)
+obj_txt/npc.o: npc.c map.h npc.h clif.h pc.h script.h mob.h itemdb.h battle.h $(COMMON_H)
+obj_txt/npc_chat.o: npc_chat.c map.h npc.h clif.h pc.h script.h mob.h itemdb.h battle.h $(COMMON_H)
+obj_txt/chat.o: chat.c map.h clif.h pc.h chat.h $(COMMON_H)
+obj_txt/path.o: path.c map.h battle.h $(COMMON_H)
+obj_txt/itemdb.o: itemdb.c map.h battle.h itemdb.h $(COMMON_H)
+obj_txt/mob.o: mob.c map.h clif.h intif.h pc.h mob.h skill.h battle.h npc.h itemdb.h date.h irc.h $(COMMON_H)
+obj_txt/script.o: script.c itemdb.h map.h pc.h mob.h clif.h intif.h npc.h script.h storage.h skill.h pet.h battle.h log.h irc.h $(COMMON_H)
+obj_txt/storage.o: storage.c itemdb.h pc.h clif.h intif.h storage.h guild.h $(COMMON_H)
+obj_txt/skill.o: skill.c skill.h map.h clif.h pc.h mob.h battle.h itemdb.h script.h date.h $(COMMON_H)
+obj_txt/atcommand.o: atcommand.c atcommand.h itemdb.h pc.h map.h skill.h clif.h mob.h intif.h battle.h storage.h guild.h pet.h log.h $(COMMON_H)
+obj_txt/battle.o: battle.c battle.h skill.h map.h mob.h pc.h pet.h guild.h $(COMMON_H)
+obj_txt/intif.o: intif.c intif.h chrif.h clif.h party.h guild.h storage.h map.h battle.h pet.h $(COMMON_H)
+obj_txt/trade.o: trade.c trade.h clif.h itemdb.h map.h pc.h npc.h $(COMMON_H)
+obj_txt/party.o: party.c party.h clif.h intif.h pc.h map.h battle.h $(COMMON_H)
+obj_txt/vending.o: vending.c vending.h clif.h itemdb.h map.h pc.h irc.h $(COMMON_H)
+obj_txt/guild.o: guild.c guild.h storage.h battle.h clif.h intif.h pc.h npc.h map.h $(COMMON_H)
+obj_txt/pet.o: pet.c pet.h map.h clif.h chrif.h intif.h pc.h itemdb.h battle.h mob.h npc.h script.h $(COMMON_H)
+obj_txt/log.o: log.c log.h map.h $(COMMON_H)
+obj_txt/charcommand.o: charcommand.c charcommand.h itemdb.h pc.h map.h skill.h clif.h mob.h intif.h battle.h storage.h guild.h pet.h log.h $(COMMON_H)
+obj_txt/date.o: date.c date.h $(COMMON_H)
+obj_txt/irc.o: irc.c irc.h map.h pc.h $(COMMON_H)
+obj_txt/unit.o: unit.c unit.h $(COMMON_H)
+obj_txt/mercenary.o: mercenary.c mercenary.h $(COMMON_H)
+
+obj_sql/map.o: map.c map.h chrif.h clif.h npc.h pc.h mob.h chat.h skill.h itemdb.h storage.h party.h pet.h atcommand.h log.h irc.h $(COMMON_SQL_H)
+obj_sql/chrif.o: chrif.c map.h battle.h chrif.h clif.h intif.h pc.h npc.h $(COMMON_SQL_H)
+obj_sql/clif.o: clif.c map.h chrif.h clif.h mob.h intif.h pc.h npc.h itemdb.h chat.h script.h storage.h party.h guild.h atcommand.h pet.h charcommand.h $(COMMON_SQL_H)
+obj_sql/pc.o: pc.c map.h clif.h intif.h pc.h npc.h mob.h itemdb.h battle.h skill.h script.h party.h guild.h pet.h trade.h storage.h chat.h vending.h log.h $(COMMON_SQL_H)
+obj_sql/status.o: status.c pc.h map.h clif.h status.h mob.h itemdb.h battle.h skill.h script.h pet.h guild.h $(COMMON_SQL_H)
+obj_sql/npc.o: npc.c map.h npc.h clif.h pc.h script.h mob.h itemdb.h battle.h $(COMMON_SQL_H)
+obj_sql/npc_chat.o: npc_chat.c map.h npc.h clif.h pc.h script.h mob.h itemdb.h battle.h $(COMMON_SQL_H)
+obj_sql/chat.o: chat.c map.h clif.h pc.h chat.h $(COMMON_SQL_H)
+obj_sql/path.o: path.c map.h battle.h $(COMMON_SQL_H)
+obj_sql/itemdb.o: itemdb.c map.h battle.h itemdb.h $(COMMON_SQL_H)
+obj_sql/mob.o: mob.c map.h clif.h intif.h pc.h mob.h skill.h battle.h npc.h itemdb.h log.h date.h irc.h $(COMMON_SQL_H)
+obj_sql/script.o: script.c itemdb.h map.h pc.h mob.h clif.h intif.h npc.h script.h storage.h skill.h pet.h battle.h log.h irc.h $(COMMON_SQL_H)
+obj_sql/storage.o: storage.c itemdb.h pc.h clif.h intif.h storage.h guild.h $(COMMON_SQL_H)
+obj_sql/skill.o: skill.c skill.h map.h clif.h pc.h mob.h battle.h itemdb.h script.h log.h date.h $(COMMON_SQL_H)
+obj_sql/atcommand.o: atcommand.c atcommand.h itemdb.h pc.h map.h skill.h clif.h mob.h intif.h battle.h storage.h guild.h pet.h log.h $(COMMON_SQL_H)
+obj_sql/battle.o: battle.c battle.h skill.h map.h mob.h pc.h pet.h guild.h $(COMMON_SQL_H)
+obj_sql/intif.o: intif.c intif.h chrif.h clif.h party.h guild.h storage.h map.h battle.h pet.h $(COMMON_SQL_H)
+obj_sql/trade.o: trade.c trade.h clif.h itemdb.h map.h pc.h npc.h log.h $(COMMON_SQL_H)
+obj_sql/party.o: party.c party.h clif.h intif.h pc.h map.h battle.h $(COMMON_SQL_H)
+obj_sql/vending.o: vending.c vending.h clif.h itemdb.h map.h pc.h log.h irc.h $(COMMON_SQL_H)
+obj_sql/guild.o: guild.c guild.h storage.h battle.h clif.h intif.h pc.h npc.h map.h irc.h $(COMMON_SQL_H)
+obj_sql/pet.o: pet.c pet.h map.h clif.h chrif.h intif.h pc.h itemdb.h battle.h mob.h npc.h script.h $(COMMON_SQL_H)
+obj_sql/mail.o: mail.c mail.h $(COMMON_SQL_H)
+obj_sql/log.o: log.c log.h map.h $(COMMON_SQL_H)
+obj_sql/charcommand.o: charcommand.c charcommand.h itemdb.h pc.h map.h skill.h clif.h mob.h intif.h battle.h storage.h guild.h pet.h log.h $(COMMON_SQL_H)
+obj_sql/date.o: date.c date.h $(COMMON_SQL_H)
+obj_sql/irc.o: irc.c irc.h map.h pc.h $(COMMON_SQL_H)
+obj_sql/unit.o: unit.c unit.h $(COMMON_SQL_H)
+obj_sql/mercenary.o: mercenary.c mercenary.h $(COMMON_SQL_H)
diff --git a/src/map/atcommand.c b/src/map/atcommand.c
index 428ff017d..3ddac9a9d 100644
--- a/src/map/atcommand.c
+++ b/src/map/atcommand.c
@@ -10,6 +10,7 @@
#include "../common/malloc.h"
#include "../common/socket.h"
#include "../common/strlib.h"
+#include "../common/utils.h"
#include "atcommand.h"
#include "log.h"
@@ -273,6 +274,7 @@ ACMD_FUNC(checkmail); // [Valaris]
ACMD_FUNC(listmail); // [Valaris]
ACMD_FUNC(listnewmail); // [Valaris]
ACMD_FUNC(readmail); // [Valaris]
+ACMD_FUNC(deletemail); // [Valaris]
ACMD_FUNC(sendmail); // [Valaris]
ACMD_FUNC(sendprioritymail); // [Valaris]
ACMD_FUNC(deletemail); // [Valaris]
@@ -577,7 +579,7 @@ static AtCommandInfo atcommand_info[] = {
{ AtCommand_ListMail, "@listmail", 1, atcommand_listmail }, // [Valaris]
{ AtCommand_ListNewMail, "@listnewmail", 1, atcommand_listmail }, // [Valaris]
{ AtCommand_ReadMail, "@readmail", 1, atcommand_readmail }, // [Valaris]
- { AtCommand_DeleteMail, "@deletemail", 1, atcommand_readmail }, // [Valaris]
+ { AtCommand_DeleteMail, "@deletemail", 1, atcommand_deletemail }, // [Valaris]
{ AtCommand_SendMail, "@sendmail", 1, atcommand_sendmail }, // [Valaris]
{ AtCommand_SendPriorityMail, "@sendprioritymail",80, atcommand_sendmail }, // [Valaris]
{ AtCommand_RefreshOnline, "@refreshonline", 99, atcommand_refreshonline }, // [Valaris]
@@ -7898,11 +7900,11 @@ int atcommand_listmail(const int fd, struct map_session_data* sd, const char* co
nullpo_retr(-1, sd);
- if(strlen(command)==12)
+ if(strlen(command)==12) // @listnewmail
mail_check(sd,3);
- else if(strlen(command)==9)
+ else if(strlen(command)==9) // @listmail
mail_check(sd,2);
- else
+ else // @checkmail
mail_check(sd,1);
return 0;
}
@@ -7926,10 +7928,31 @@ int atcommand_readmail(const int fd, struct map_session_data* sd, const char* co
return 0;
}
- if(strlen(command)==11)
- mail_delete(sd,index);
- else
- mail_read(sd,index);
+ mail_read(sd,index);
+
+ return 0;
+}
+
+int atcommand_deletemail(const int fd, struct map_session_data* sd, const char* command, const char* message)
+{
+ int index;
+ if(!mail_server_enable)
+ return 0;
+
+ nullpo_retr(-1, sd);
+
+ if (!message || !*message) {
+ clif_displaymessage(sd->fd,"You must specify a message number.");
+ return 0;
+ }
+
+ index = atoi(message);
+ if (index < 1) {
+ clif_displaymessage(sd->fd,"Message number cannot be negative or zero.");
+ return 0;
+ }
+
+ mail_delete(sd,index);
return 0;
}
@@ -7954,7 +7977,7 @@ int atcommand_sendmail(const int fd, struct map_session_data* sd, const char* co
return 0;
}
- if(strlen(command)==17)
+ if(strlen(command)==17) // @sendprioritymail
mail_send(sd,name,text,1);
else
mail_send(sd,name,text,0);
diff --git a/src/map/battle.c b/src/map/battle.c
index 9264fbedf..2994dfa6a 100644
--- a/src/map/battle.c
+++ b/src/map/battle.c
@@ -8,6 +8,7 @@
#include "../common/showmsg.h"
#include "../common/ers.h"
#include "../common/strlib.h"
+#include "../common/utils.h"
#include "map.h"
#include "pc.h"
diff --git a/src/map/charcommand.c b/src/map/charcommand.c
index cfd3d59c8..88c32b307 100644
--- a/src/map/charcommand.c
+++ b/src/map/charcommand.c
@@ -6,6 +6,7 @@
#include "../common/timer.h"
#include "../common/nullpo.h"
#include "../common/showmsg.h"
+#include "../common/utils.h"
#include "log.h"
#include "clif.h"
diff --git a/src/map/clif.c b/src/map/clif.c
index 5845ee102..ff6ccb9cf 100644
--- a/src/map/clif.c
+++ b/src/map/clif.c
@@ -9,6 +9,7 @@
#include "../common/nullpo.h"
#include "../common/showmsg.h"
#include "../common/strlib.h"
+#include "../common/utils.h"
#include "map.h"
#include "chrif.h"
diff --git a/src/map/guild.c b/src/map/guild.c
index f9773d440..74cd0261a 100644
--- a/src/map/guild.c
+++ b/src/map/guild.c
@@ -9,6 +9,7 @@
#include "../common/showmsg.h"
#include "../common/ers.h"
#include "../common/strlib.h"
+#include "../common/utils.h"
#include "map.h"
#include "guild.h"
@@ -1922,12 +1923,11 @@ int guild_save_sub(int tid,unsigned int tick,int id,int data)
int guild_agit_break(struct mob_data *md)
{ // Run One NPC_Event[OnAgitBreak]
- char *evname;
+ char* evname;
if(!agit_flag) return 0; // Agit already End
- evname=(char *)aMallocA((strlen(md->npc_event) + 1)*sizeof(char));
- strcpy(evname,md->npc_event);
+ evname = aStrdup(md->npc_event);
// Now By User to Run [OnAgitBreak] NPC Event...
// It's a little impossible to null point with player disconnect in this!
// But Script will be stop, so nothing...
diff --git a/src/map/intif.c b/src/map/intif.c
index 9e7effef3..b6f457ee1 100644
--- a/src/map/intif.c
+++ b/src/map/intif.c
@@ -1497,7 +1497,7 @@ int intif_parse(int fd)
case 0x3802: intif_parse_WisEnd(fd); break;
case 0x3803: mapif_parse_WisToGM(fd); break;
case 0x3804: intif_parse_Registers(fd); break;
- case 0x3806: intif_parse_ChangeNameOk(fd); break;
+ case 0x3806: intif_parse_ChangeNameOk(fd); break;
case 0x3810: intif_parse_LoadStorage(fd); break;
case 0x3811: intif_parse_SaveStorage(fd); break;
case 0x3818: intif_parse_LoadGuildStorage(fd); break;
diff --git a/src/map/itemdb.c b/src/map/itemdb.c
index 1ba86cbc4..4ed47df61 100644
--- a/src/map/itemdb.c
+++ b/src/map/itemdb.c
@@ -615,369 +615,251 @@ static int itemdb_gendercheck(struct item_data *id)
if (id->look == W_WHIP && id->type == IT_WEAPON) //Whips are always female-only
return 0;
- return (battle_config.ignore_items_gender?2:id->sex);
+ return (battle_config.ignore_items_gender) ? 2 : id->sex;
}
-#ifndef TXT_ONLY
-/*======================================
- * SQL
- *======================================*/
-static int itemdb_read_sqldb(void)
-{
+/*==========================================
+ * processes one itemdb entry
+ *------------------------------------------*/
+static bool itemdb_parse_dbrow(char** str, char* source, int line)
+{
+ /*
+ +----+--------------+---------------+------+-----------+------------+--------+--------+---------+-------+-------+------------+-------------+---------------+-----------------+--------------+-------------+------------+------+--------+--------------+----------------+
+ | 00 | 01 | 02 | 03 | 04 | 05 | 06 | 07 | 08 | 09 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 |
+ +----+--------------+---------------+------+-----------+------------+--------+--------+---------+-------+-------+------------+-------------+---------------+-----------------+--------------+-------------+------------+------+--------+--------------+----------------+
+ | id | name_english | name_japanese | type | price_buy | price_sell | weight | attack | defence | range | slots | equip_jobs | equip_upper | equip_genders | equip_locations | weapon_level | equip_level | refineable | view | script | equip_script | unequip_script |
+ +----+--------------+---------------+------+-----------+------------+--------+--------+---------+-------+-------+------------+-------------+---------------+-----------------+--------------+-------------+------------+------+--------+--------------+----------------+
+ */
unsigned short nameid;
- struct item_data *id;
- char script[65535 + 2 + 1]; // Maximum length of MySQL TEXT type (65535) + 2 bytes for curly brackets + 1 byte for terminator
- char *item_db_name[] = { item_db_db, item_db2_db };
- long unsigned int ln = 0;
- int i;
-
- // ----------
-
- for (i = 0; i < 2; i++) {
- sprintf(tmp_sql, "SELECT * FROM `%s`", item_db_name[i]);
-
- // Execute the query; if the query execution succeeded...
- if (mysql_query(&mmysql_handle, tmp_sql) == 0) {
- sql_res = mysql_store_result(&mmysql_handle);
-
- // If the storage of the query result succeeded...
- if (sql_res) {
- // Parse each row in the query result into sql_row
- while ((sql_row = mysql_fetch_row(sql_res)))
- { /*Table structure is:
- 00 id
- 01 name_english
- 02 name_japanese
- 03 type
- 04 price_buy
- 05 price_sell
- 06 weight
- 07 attack
- 08 defence
- 09 range
- 10 slots
- 11 equip_jobs
- 12 equip_upper
- 13 equip_genders
- 14 equip_locations
- 15 weapon_level
- 16 equip_level
- 17 refineable
- 18 view
- 19 script
- 20 equip_script
- 21 unequip_script
- */
- nameid = atoi(sql_row[0]);
-
- // If the identifier is not within the valid range, process the next row
- if (nameid == 0)
- continue;
-
- ln++;
-
- // ----------
- id = itemdb_load(nameid);
-
- strncpy(id->name, sql_row[1], ITEM_NAME_LENGTH-1);
- strncpy(id->jname, sql_row[2], ITEM_NAME_LENGTH-1);
-
- id->type = atoi(sql_row[3]);
- if (id->type == IT_DELAYCONSUME)
- { //Items that are consumed upon target confirmation
- //(yggdrasil leaf, spells & pet lures) [Skotlex]
- id->type = IT_USABLE;
- id->flag.delay_consume=1;
- } else //In case of an itemdb reload and the item type changed.
- id->flag.delay_consume=0;
-
- // If price_buy is not NULL and price_sell is not NULL...
- if ((sql_row[4] != NULL) && (sql_row[5] != NULL)) {
- id->value_buy = atoi(sql_row[4]);
- id->value_sell = atoi(sql_row[5]);
- }
- // If price_buy is not NULL and price_sell is NULL...
- else if ((sql_row[4] != NULL) && (sql_row[5] == NULL)) {
- id->value_buy = atoi(sql_row[4]);
- id->value_sell = atoi(sql_row[4]) / 2;
- }
- // If price_buy is NULL and price_sell is not NULL...
- else if ((sql_row[4] == NULL) && (sql_row[5] != NULL)) {
- id->value_buy = atoi(sql_row[5]) * 2;
- id->value_sell = atoi(sql_row[5]);
- }
- // If price_buy is NULL and price_sell is NULL...
- if ((sql_row[4] == NULL) && (sql_row[5] == NULL)) {
- id->value_buy = 0;
- id->value_sell = 0;
- }
-
- id->weight = atoi(sql_row[6]);
- id->atk = (sql_row[7] != NULL) ? atoi(sql_row[7]) : 0;
- id->def = (sql_row[8] != NULL) ? atoi(sql_row[8]) : 0;
- id->range = (sql_row[9] != NULL) ? atoi(sql_row[9]) : 0;
- id->slot = (sql_row[10] != NULL) ? atoi(sql_row[10]) : 0;
- if (id->slot > MAX_SLOTS)
- {
- ShowWarning("itemdb_read_sqldb: Item %d (%s) specifies %d slots, but the server only supports up to %d\n", nameid, id->jname, id->slot, MAX_SLOTS);
- id->slot = MAX_SLOTS;
- }
- itemdb_jobid2mapid(id->class_base, (sql_row[11] != NULL) ? (unsigned int)strtoul(sql_row[11], NULL, 0) : 0);
- id->class_upper= (sql_row[12] != NULL) ? atoi(sql_row[12]) : 0;
- id->sex = (sql_row[13] != NULL) ? atoi(sql_row[13]) : 0;
- id->equip = (sql_row[14] != NULL) ? atoi(sql_row[14]) : 0;
- if (!id->equip && itemdb_isequip2(id))
- {
- ShowWarning("Item %d (%s) is an equipment with no equip-field! Making it an etc item.\n", nameid, id->jname);
- id->type = 3;
- }
- id->wlv = (sql_row[15] != NULL) ? atoi(sql_row[15]) : 0;
- id->elv = (sql_row[16] != NULL) ? atoi(sql_row[16]) : 0;
- id->flag.no_refine = (sql_row[17] == NULL || atoi(sql_row[17]) == 1)?0:1;
- id->look = (sql_row[18] != NULL) ? atoi(sql_row[18]) : 0;
- id->view_id = 0;
- id->sex = itemdb_gendercheck(id); //Apply gender filtering.
-
- // ----------
-
- if (id->script)
- script_free_code(id->script);
- if (sql_row[19] != NULL) {
- if (sql_row[19][0] == '{')
- id->script = parse_script(sql_row[19],item_db_name[i], ln, 0);
- else {
- sprintf(script, "{%s}", sql_row[19]);
- id->script = parse_script(script, item_db_name[i], ln, 0);
- }
- } else id->script = NULL;
+ struct item_data* id;
- if (id->equip_script)
- script_free_code(id->equip_script);
- if (sql_row[20] != NULL) {
- if (sql_row[20][0] == '{')
- id->equip_script = parse_script(sql_row[20], item_db_name[i], ln, 0);
- else {
- sprintf(script, "{%s}", sql_row[20]);
- id->equip_script = parse_script(script, item_db_name[i], ln, 0);
- }
- } else id->equip_script = NULL;
+ nameid = atoi(str[0]);
+ if(nameid <= 0)
+ return false;
- if (id->unequip_script)
- script_free_code(id->unequip_script);
- if (sql_row[21] != NULL) {
- if (sql_row[21][0] == '{')
- id->unequip_script = parse_script(sql_row[21],item_db_name[i], ln, 0);
- else {
- sprintf(script, "{%s}", sql_row[21]);
- id->unequip_script = parse_script(script, item_db_name[i], ln, 0);
- }
- } else id->unequip_script = NULL;
-
- // ----------
-
- id->flag.available = 1;
- id->flag.value_notdc = 0;
- id->flag.value_notoc = 0;
- }
+ //ID,Name,Jname,Type,Price,Sell,Weight,ATK,DEF,Range,Slot,Job,Job Upper,Gender,Loc,wLV,eLV,refineable,View
+ id = itemdb_load(nameid);
+ safestrncpy(id->name, str[1], ITEM_NAME_LENGTH-1);
+ safestrncpy(id->jname, str[2], ITEM_NAME_LENGTH-1);
+
+ id->type = atoi(str[3]);
+ if (id->type == IT_DELAYCONSUME)
+ { //Items that are consumed only after target confirmation
+ id->type = IT_USABLE;
+ id->flag.delay_consume = 1;
+ } else //In case of an itemdb reload and the item type changed.
+ id->flag.delay_consume = 0;
+
+ id->value_buy = atoi(str[4]);
+ id->value_sell = atoi(str[5]);
+ if (id->value_buy < id->value_sell * 2) id->value_buy = id->value_sell * 2; // prevent exploit
+ if (id->value_buy == 0 && id->value_sell > 0) id->value_buy = id->value_sell * 2;
+ if (id->value_sell == 0 && id->value_buy > 0) id->value_sell = id->value_buy / 2;
+
+ id->weight = atoi(str[6]);
+ id->atk = atoi(str[7]);
+ id->def = atoi(str[8]);
+ id->range = atoi(str[9]);
+ id->slot = atoi(str[10]);
+
+ if (id->slot > MAX_SLOTS)
+ {
+ ShowWarning("itemdb_parse_dbrow: Item %d (%s) specifies %d slots, but the server only supports up to %d\n", nameid, id->jname, id->slot, MAX_SLOTS);
+ id->slot = MAX_SLOTS;
+ }
+
+ itemdb_jobid2mapid(id->class_base, (unsigned int)strtoul(str[11],NULL,0));
+ id->class_upper = atoi(str[12]);
+ id->sex = atoi(str[13]);
+ id->equip = atoi(str[14]);
+
+ if (!id->equip && itemdb_isequip2(id))
+ {
+ ShowWarning("Item %d (%s) is an equipment with no equip-field! Making it an etc item.\n", nameid, id->jname);
+ id->type = IT_ETC;
+ }
+
+ id->wlv = atoi(str[15]);
+ id->elv = atoi(str[16]);
+ id->flag.no_refine = atoi(str[17]) ? 0 : 1; //FIXME: verify this
+ id->look = atoi(str[18]);
+
+ id->flag.available = 1;
+ id->flag.value_notdc = 0;
+ id->flag.value_notoc = 0;
+ id->view_id = 0;
+ id->sex = itemdb_gendercheck(id); //Apply gender filtering.
- ShowStatus("Done reading '"CL_WHITE"%lu"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", ln, item_db_name[i]);
- ln = 0;
- } else {
- ShowSQL("DB error (%s) - %s\n",item_db_name[i], mysql_error(&mmysql_handle));
- ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
- }
+ if (id->script)
+ script_free_code(id->script);
+ if (id->equip_script)
+ script_free_code(id->equip_script);
+ if (id->unequip_script)
+ script_free_code(id->unequip_script);
- // Free the query result
- mysql_free_result(sql_res);
- } else {
- ShowSQL("DB error (%s) - %s\n",item_db_name[i], mysql_error(&mmysql_handle));
- ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
- }
- }
+ if (*str[19])
+ id->script = parse_script(str[19], source, line, 0);
+ if (*str[20])
+ id->equip_script = parse_script(str[20], source, line, 0);
+ if (*str[21])
+ id->unequip_script = parse_script(str[21], source, line, 0);
- return 0;
+ return true;
}
-#endif /* not TXT_ONLY */
/*==========================================
* アイテムデータベースの読み込み
*------------------------------------------*/
static int itemdb_readdb(void)
{
- FILE *fp;
- char line[1024];
- int ln=0,lines=0;
- int nameid,j;
- char *str[32],*p,*np;
- struct item_data *id;
- int i=0;
- char *filename[]={ "item_db.txt","item_db2.txt" };
-
- for(i=0;i<2;i++){
- sprintf(line, "%s/%s", db_path, filename[i]);
- fp=fopen(line,"r");
- if(fp==NULL){
- if(i>0)
+ char* filename[] = { "item_db.txt", "item_db2.txt" };
+ int fi;
+
+ for(fi = 0; fi < 2; fi++)
+ {
+ uint32 lines = 0, count = 0;
+ char line[1024];
+
+ char path[256];
+ FILE* fp;
+
+ sprintf(path, "%s/%s", db_path, filename[fi]);
+ fp = fopen(path, "r");
+ if(fp == NULL) {
+ if(fi > 0)
continue;
- ShowFatalError("can't read %s\n",line);
- exit(1);
+ return -1;
}
- lines=0;
+ // process rows one by one
while(fgets(line, sizeof(line), fp))
{
- lines++;
- if(line[0]=='/' && line[1]=='/')
- continue;
- memset(str,0,sizeof(str));
- for(j=0,np=p=line;j<19 && p;j++){
- str[j]=p;
- p=strchr(p,',');
- if(p){ *p++=0; np=p; }
- }
- if(str[0]==NULL)
- continue;
+ char *str[32], *p, *np;
+ int i;
- nameid=atoi(str[0]);
- if(nameid<=0)
- continue;
- if (j < 19)
- { //Crash-fix on broken item lines. [Skotlex]
- ShowWarning("Reading %s: Insufficient fields for item with id %d, skipping.\n", filename[i], nameid);
+ lines++;
+ if(line[0] == '/' && line[1] == '/')
continue;
- }
- ln++;
-
- //ID,Name,Jname,Type,Price,Sell,Weight,ATK,DEF,Range,Slot,Job,Job Upper,Gender,Loc,wLV,eLV,refineable,View
- id=itemdb_load(nameid);
- strncpy(id->name, str[1], ITEM_NAME_LENGTH-1);
- strncpy(id->jname, str[2], ITEM_NAME_LENGTH-1);
- id->type=atoi(str[3]);
- if (id->type == IT_DELAYCONSUME)
- { //Items that are consumed upon target confirmation
- //(yggdrasil leaf, spells & pet lures) [Skotlex]
- id->type = IT_USABLE;
- id->flag.delay_consume=1;
- } else //In case of an itemdb reload and the item type changed.
- id->flag.delay_consume=0;
-
+ memset(str, 0, sizeof(str));
+ for(i = 0, np = p = line; i < 19 && p; i++)
{
- int buy = atoi(str[4]), sell = atoi(str[5]);
- // if buying price > selling price * 2 consider it valid and don't change it [celest]
- if (buy && sell && buy > sell*2){
- id->value_buy = buy;
- id->value_sell = sell;
- } else {
- // buy≠sell*2 は item_value_db.txt で指定してください。
- if (sell) { // sell値を優先とする
- id->value_buy = sell*2;
- id->value_sell = sell;
- } else {
- id->value_buy = buy;
- id->value_sell = buy/2;
- }
+ str[i] = p;
+ if ((p = strchr(p,',')) != NULL) {
+ *p++ = '\0'; np = p;
}
- // check for bad prices that can possibly cause exploits
- if (id->value_buy*75/100 < id->value_sell*124/100) {
- ShowWarning ("Item %s [%d] buying:%d < selling:%d\n",
- id->name, id->nameid, id->value_buy*75/100, id->value_sell*124/100);
- }
- }
- id->weight=atoi(str[6]);
- id->atk=atoi(str[7]);
- id->def=atoi(str[8]);
- id->range=atoi(str[9]);
- id->slot=atoi(str[10]);
- if (id->slot > MAX_SLOTS)
- {
- ShowWarning("itemdb_readdb: Item %d (%s) specifies %d slots, but the server only supports up to %d\n", nameid, id->jname, id->slot, MAX_SLOTS);
- id->slot = MAX_SLOTS;
- }
- itemdb_jobid2mapid(id->class_base, (unsigned int)strtoul(str[11],NULL,0));
- id->class_upper = atoi(str[12]);
- id->sex = atoi(str[13]);
- if(id->equip != atoi(str[14])){
- id->equip=atoi(str[14]);
- }
- if (!id->equip && itemdb_isequip2(id))
- {
- ShowWarning("Item %d (%s) is an equipment with no equip-field! Making it an etc item.\n", nameid, id->jname);
- id->type = 3;
- }
- id->wlv=atoi(str[15]);
- id->elv=atoi(str[16]);
- id->flag.no_refine = atoi(str[17])?0:1; //If the refine column is 1, no_refine is 0
- id->look=atoi(str[18]);
- id->flag.available=1;
- id->flag.value_notdc=0;
- id->flag.value_notoc=0;
- id->view_id=0;
- id->sex = itemdb_gendercheck(id); //Apply gender filtering.
-
- if (id->script) {
- script_free_code(id->script);
- id->script=NULL;
}
- if (id->equip_script) {
- script_free_code(id->equip_script);
- id->equip_script=NULL;
- }
- if (id->unequip_script) {
- script_free_code(id->unequip_script);
- id->unequip_script=NULL;
+
+ if (i < 19) {
+ ShowWarning("itemdb_readdb: Insufficient columns for item with id %d, skipping.\n", atoi(str[0]));
+ continue;
}
- if((p=strchr(np,'{'))==NULL)
+ if((p=strchr(np,'{')) == NULL)
continue;
-
str[19] = p; //Script
np = strchr(p,'}');
-
while (np && np[1] && np[1] != ',')
np = strchr(np+1,'}'); //Jump close brackets until the next field is found.
if (!np || !np[1]) {
- //Couldn't find the end of the script field.
- id->script = parse_script(str[19],filename[i],lines,0);
- continue;
+ continue; //Couldn't find the end of the script field.
}
np[1] = '\0'; //Set end of script
- id->script = parse_script(str[19],filename[i],lines,0);
- np+=2; //Skip to next field
+ np += 2; //Skip to next field
if(!np || (p=strchr(np,'{'))==NULL)
continue;
-
str[20] = p; //Equip Script
np = strchr(p,'}');
-
while (np && np[1] && np[1] != ',')
np = strchr(np+1,'}'); //Jump close brackets until the next field is found.
if (!np || !np[1]) {
- //Couldn't find the end of the script field.
- id->equip_script = parse_script(str[20],filename[i],lines,0);
- continue;
+ continue; //Couldn't find the end of the script field.
}
-
np[1] = '\0'; //Set end of script
- id->equip_script = parse_script(str[20],filename[i],lines,0);
- np+=2; //Skip comma, to next field
+ np += 2; //Skip comma, to next field
if(!np || (p=strchr(np,'{'))==NULL)
continue;
- //Unequip script, last column.
- id->unequip_script = parse_script(p,filename[i],lines,0);
+ str[21] = p; //Unequip script, last column.
+
+ if (!itemdb_parse_dbrow(str, filename[fi], lines))
+ continue;
+
+ count++;
}
+
fclose(fp);
- if (ln > 0) {
- ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n",ln,filename[i]);
+
+ ShowStatus("Done reading '"CL_WHITE"%lu"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", count, filename[fi]);
+ }
+
+ return 0;
+}
+
+#ifndef TXT_ONLY
+/*======================================
+ * item_db table reading
+ *======================================*/
+static int itemdb_read_sqldb(void)
+{
+ char* item_db_name[] = { item_db_db, item_db2_db };
+ int fi;
+
+ for (fi = 0; fi < 2; fi++)
+ {
+ uint32 lines = 0, count = 0;
+
+ // retrieve all rows from the item database
+ if( SQL_ERROR == Sql_Query(mmysql_handle, "SELECT * FROM `%s`", item_db_name[fi]) )
+ {
+ Sql_ShowDebug(mmysql_handle);
+ continue;
+ }
+
+ // process rows one by one
+ while( SQL_SUCCESS == Sql_NextRow(mmysql_handle) )
+ {
+ // wrap the result into a TXT-compatible format
+ char line[1024];
+ char* str[22];
+ char* p;
+ int i;
+
+ lines++;
+ for (i = 0, p = line; i < 22; i++)
+ {
+ char* data;
+ size_t len;
+ Sql_GetData(mmysql_handle, i, &data, &len);
+
+ if (data == NULL)
+ p[0] = '\0';
+ else if (i >= 19 && data[0] != '{') {
+ sprintf(p, "{ %s }", data); len+= 4;
+ } else
+ strcpy(p, data);
+ str[i] = p;
+ p+= len + 1;
+ }
+
+ if (!itemdb_parse_dbrow(str, item_db_name[fi], lines))
+ continue;
+
+ count++;
}
- ln=0; // reset to 0
+
+ // free the query result
+ Sql_FreeResult(mmysql_handle);
+
+ ShowStatus("Done reading '"CL_WHITE"%lu"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", count, item_db_name[fi]);
}
+
return 0;
}
+#endif /* not TXT_ONLY */
/*====================================
- * Removed item_value_db, don't re-add
+ * read all item-related databases
*------------------------------------*/
static void itemdb_read(void)
{
diff --git a/src/map/log.c b/src/map/log.c
index fdbb4470f..b5c4a3d9c 100644
--- a/src/map/log.c
+++ b/src/map/log.c
@@ -19,6 +19,8 @@ struct Log_Config log_config;
char timestring[255];
time_t curtime;
+static int should_log_item(int filter, int nameid, int amount); //log filter check
+
//FILTER OPTIONS
//0 = Don't log
//1 = Log any item
@@ -58,104 +60,105 @@ int should_log_item(int filter, int nameid, int amount)
int log_branch(struct map_session_data *sd)
{
-#ifndef TXT_ONLY
- char t_name[NAME_LENGTH*2];
-#endif
- FILE *logfp;
-
if(!log_config.enable_logs)
return 0;
+
nullpo_retr(0, sd);
+
#ifndef TXT_ONLY
if(log_config.sql_logs > 0)
{
- sprintf(tmp_sql, "INSERT DELAYED INTO `%s` (`branch_date`, `account_id`, `char_id`, `char_name`, `map`) VALUES (NOW(), '%d', '%d', '%s', '%s')",
- log_config.log_branch_db, sd->status.account_id, sd->status.char_id, jstrescapecpy(t_name, sd->status.name), mapindex_id2name(sd->mapindex));
- if(mysql_query(&logmysql_handle, tmp_sql))
+ SqlStmt* stmt;
+ stmt = SqlStmt_Malloc(logmysql_handle);
+ if( SQL_SUCCESS != SqlStmt_Prepare(stmt, "INSERT DELAYED INTO `%s` (`branch_date`, `account_id`, `char_id`, `char_name`, `map`) VALUES (NOW(), '%d', '%d', ?, '%s')", log_config.log_branch_db, sd->status.account_id, sd->status.char_id, sd->status.name, mapindex_id2name(sd->mapindex))
+ || SQL_SUCCESS != SqlStmt_BindParam(stmt, 0, SQLDT_STRING, sd->status.name, strnlen(sd->status.name, NAME_LENGTH))
+ || SQL_SUCCESS != SqlStmt_Execute(stmt) )
{
- ShowSQL("DB error - %s\n",mysql_error(&logmysql_handle));
- ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
+ SqlStmt_ShowDebug(stmt);
+ SqlStmt_Free(stmt);
return 0;
}
- return 1;
+ SqlStmt_Free(stmt);
}
+ else
#endif
- if((logfp=fopen(log_config.log_branch,"a+")) == NULL)
- return 0;
- time(&curtime);
- strftime(timestring, 254, "%m/%d/%Y %H:%M:%S", localtime(&curtime));
- fprintf(logfp,"%s - %s[%d:%d]\t%s\n", timestring, sd->status.name, sd->status.account_id, sd->status.char_id, mapindex_id2name(sd->mapindex));
- fclose(logfp);
+ {
+ FILE* logfp;
+ if((logfp = fopen(log_config.log_branch, "a+")) == NULL)
+ return 0;
+ time(&curtime);
+ strftime(timestring, 254, "%m/%d/%Y %H:%M:%S", localtime(&curtime));
+ fprintf(logfp,"%s - %s[%d:%d]\t%s\n", timestring, sd->status.name, sd->status.account_id, sd->status.char_id, mapindex_id2name(sd->mapindex));
+ fclose(logfp);
+ }
+
return 1;
}
int log_pick_pc(struct map_session_data *sd, const char *type, int nameid, int amount, struct item *itm)
{
- FILE *logfp;
- char *mapname;
-
nullpo_retr(0, sd);
- //Should we log this item? [Lupus]
- if (!should_log_item(log_config.filter,nameid, amount))
- return 0; //we skip logging this items set - they doesn't met our logging conditions [Lupus]
- mapname = (char*)mapindex_id2name(sd->mapindex);
-
- if(mapname==NULL)
- mapname="";
+ if (!should_log_item(log_config.filter, nameid, amount))
+ return 0; //we skip logging this item set - it doesn't meet our logging conditions [Lupus]
#ifndef TXT_ONLY
if(log_config.sql_logs > 0)
{
- if (itm==NULL) {
- //We log common item
- sprintf(tmp_sql, "INSERT DELAYED INTO `%s` (`time`, `char_id`, `type`, `nameid`, `amount`, `map`) VALUES (NOW(), '%d', '%s', '%d', '%d', '%s')",
- log_config.log_pick_db, sd->status.char_id, type, nameid, amount, mapname);
+ if (itm == NULL) {
+ //We log common item
+ if (SQL_ERROR == Sql_Query(logmysql_handle, "INSERT DELAYED INTO `%s` (`time`, `char_id`, `type`, `nameid`, `amount`, `map`) VALUES (NOW(), '%d', '%s', '%d', '%d', '%s')",
+ log_config.log_pick_db, sd->status.char_id, type, nameid, amount, mapindex_id2name(sd->mapindex)) )
+ {
+ Sql_ShowDebug(logmysql_handle);
+ return 0;
+ }
} else {
- //We log Extended item
- sprintf(tmp_sql, "INSERT DELAYED INTO `%s` (`time`, `char_id`, `type`, `nameid`, `amount`, `refine`, `card0`, `card1`, `card2`, `card3`, `map`) VALUES (NOW(), '%d', '%s', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%s')",
- log_config.log_pick_db, sd->status.char_id, type, itm->nameid, amount, itm->refine, itm->card[0], itm->card[1], itm->card[2], itm->card[3], mapname);
+ //We log Extended item
+ if (SQL_ERROR == Sql_Query(logmysql_handle, "INSERT DELAYED INTO `%s` (`time`, `char_id`, `type`, `nameid`, `amount`, `refine`, `card0`, `card1`, `card2`, `card3`, `map`) VALUES (NOW(), '%d', '%s', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%s')",
+ log_config.log_pick_db, sd->status.char_id, type, itm->nameid, amount, itm->refine, itm->card[0], itm->card[1], itm->card[2], itm->card[3], mapindex_id2name(sd->mapindex)) )
+ {
+ Sql_ShowDebug(logmysql_handle);
+ return 0;
+ }
}
+ }
+ else
+#endif
+ {
+ FILE* logfp;
- if(mysql_query(&logmysql_handle, tmp_sql))
- {
- ShowSQL("DB error - %s\n",mysql_error(&logmysql_handle));
- ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
+ if((logfp = fopen(log_config.log_pick, "a+")) == NULL)
return 0;
+ time(&curtime);
+ strftime(timestring, 254, "%m/%d/%Y %H:%M:%S", localtime(&curtime));
+
+ if (itm == NULL) {
+ //We log common item
+ fprintf(logfp,"%s - %d\t%s\t%d,%d,%s\n",
+ timestring, sd->status.char_id, type, nameid, amount, mapindex_id2name(sd->mapindex));
+
+ } else {
+ //We log Extended item
+ fprintf(logfp,"%s - %d\t%s\t%d,%d,%d,%d,%d,%d,%d,%s\n",
+ timestring, sd->status.char_id, type, itm->nameid, amount, itm->refine, itm->card[0], itm->card[1], itm->card[2], itm->card[3], mapindex_id2name(sd->mapindex));
}
- return 1;
+ fclose(logfp);
}
-#endif
- if((logfp=fopen(log_config.log_pick,"a+")) == NULL)
- return 0;
- time(&curtime);
- strftime(timestring, 254, "%m/%d/%Y %H:%M:%S", localtime(&curtime));
-
- if (itm==NULL) {
- //We log common item
- fprintf(logfp,"%s - %d\t%s\t%d,%d,%s\n",
- timestring, sd->status.char_id, type, nameid, amount, mapname);
-
- } else {
- //We log Extended item
- fprintf(logfp,"%s - %d\t%s\t%d,%d,%d,%d,%d,%d,%d,%s\n",
- timestring, sd->status.char_id, type, itm->nameid, amount, itm->refine, itm->card[0], itm->card[1], itm->card[2], itm->card[3], mapname);
- }
- fclose(logfp);
+
return 1; //Logged
}
//Mob picked item
int log_pick_mob(struct mob_data *md, const char *type, int nameid, int amount, struct item *itm)
{
- FILE *logfp;
- char *mapname;
+ char* mapname;
nullpo_retr(0, md);
- //Should we log this item? [Lupus]
- if (!should_log_item(log_config.filter,nameid, amount))
- return 0; //we skip logging this items set - they doesn't met our logging conditions [Lupus]
+
+ if (!should_log_item(log_config.filter, nameid, amount))
+ return 0; //we skip logging this item set - it doesn't meet our logging conditions [Lupus]
//either PLAYER or MOB (here we get map name and objects ID)
mapname = map[md->bl.m].name;
@@ -167,180 +170,200 @@ int log_pick_mob(struct mob_data *md, const char *type, int nameid, int amount,
{
if (itm==NULL) {
//We log common item
- sprintf(tmp_sql, "INSERT DELAYED INTO `%s` (`time`, `char_id`, `type`, `nameid`, `amount`, `map`) VALUES (NOW(), '%d', '%s', '%d', '%d', '%s')",
- log_config.log_pick_db, md->class_, type, nameid, amount, mapname);
+ if (SQL_ERROR == Sql_Query(logmysql_handle, "INSERT DELAYED INTO `%s` (`time`, `char_id`, `type`, `nameid`, `amount`, `map`) VALUES (NOW(), '%d', '%s', '%d', '%d', '%s')",
+ log_config.log_pick_db, md->class_, type, nameid, amount, mapname) )
+ {
+ Sql_ShowDebug(logmysql_handle);
+ return 0;
+ }
} else {
//We log Extended item
- sprintf(tmp_sql, "INSERT DELAYED INTO `%s` (`time`, `char_id`, `type`, `nameid`, `amount`, `refine`, `card0`, `card1`, `card2`, `card3`, `map`) VALUES (NOW(), '%d', '%s', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%s')",
- log_config.log_pick_db, md->class_, type, itm->nameid, amount, itm->refine, itm->card[0], itm->card[1], itm->card[2], itm->card[3], mapname);
+ if (SQL_ERROR == Sql_Query(logmysql_handle, "INSERT DELAYED INTO `%s` (`time`, `char_id`, `type`, `nameid`, `amount`, `refine`, `card0`, `card1`, `card2`, `card3`, `map`) VALUES (NOW(), '%d', '%s', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%s')",
+ log_config.log_pick_db, md->class_, type, itm->nameid, amount, itm->refine, itm->card[0], itm->card[1], itm->card[2], itm->card[3], mapname) )
+ {
+ Sql_ShowDebug(logmysql_handle);
+ return 0;
+ }
}
+ }
+ else
+#endif
+ {
+ FILE *logfp;
- if(mysql_query(&logmysql_handle, tmp_sql))
- {
- ShowSQL("DB error - %s\n",mysql_error(&logmysql_handle));
- ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
+ if((logfp=fopen(log_config.log_pick,"a+")) == NULL)
return 0;
+ time(&curtime);
+ strftime(timestring, 254, "%m/%d/%Y %H:%M:%S", localtime(&curtime));
+
+ if (itm==NULL) {
+ //We log common item
+ fprintf(logfp,"%s - %d\t%s\t%d,%d,%s\n",
+ timestring, md->class_, type, nameid, amount, mapname);
+
+ } else {
+ //We log Extended item
+ fprintf(logfp,"%s - %d\t%s\t%d,%d,%d,%d,%d,%d,%d,%s\n",
+ timestring, md->class_, type, itm->nameid, amount, itm->refine, itm->card[0], itm->card[1], itm->card[2], itm->card[3], mapname);
}
- return 1;
- }
-#endif
- if((logfp=fopen(log_config.log_pick,"a+")) == NULL)
- return 0;
- time(&curtime);
- strftime(timestring, 254, "%m/%d/%Y %H:%M:%S", localtime(&curtime));
-
- if (itm==NULL) {
- //We log common item
- fprintf(logfp,"%s - %d\t%s\t%d,%d,%s\n",
- timestring, md->class_, type, nameid, amount, mapname);
-
- } else {
- //We log Extended item
- fprintf(logfp,"%s - %d\t%s\t%d,%d,%d,%d,%d,%d,%d,%s\n",
- timestring, md->class_, type, itm->nameid, amount, itm->refine, itm->card[0], itm->card[1], itm->card[2], itm->card[3], mapname);
+ fclose(logfp);
}
- fclose(logfp);
+
return 1; //Logged
}
int log_zeny(struct map_session_data *sd, char *type, struct map_session_data *src_sd, int amount)
{
-// FILE *logfp;
- if(!log_config.enable_logs || (log_config.zeny!=1 && abs(amount)<log_config.zeny))
+ if(!log_config.enable_logs || (log_config.zeny != 1 && abs(amount) < log_config.zeny))
return 0;
nullpo_retr(0, sd);
+
#ifndef TXT_ONLY
if(log_config.sql_logs > 0)
{
- sprintf(tmp_sql, "INSERT DELAYED INTO `%s` (`time`, `char_id`, `src_id`, `type`, `amount`, `map`) VALUES (NOW(), '%d', '%d', '%s', '%d', '%s')",
- log_config.log_zeny_db, sd->status.char_id, src_sd->status.char_id, type, amount, mapindex_id2name(sd->mapindex));
- if(mysql_query(&logmysql_handle, tmp_sql))
+ if (SQL_ERROR == Sql_Query(logmysql_handle, "INSERT DELAYED INTO `%s` (`time`, `char_id`, `src_id`, `type`, `amount`, `map`) VALUES (NOW(), '%d', '%d', '%s', '%d', '%s')",
+ log_config.log_zeny_db, sd->status.char_id, src_sd->status.char_id, type, amount, mapindex_id2name(sd->mapindex)) )
{
- ShowSQL("DB error - %s\n",mysql_error(&logmysql_handle));
- ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
+ Sql_ShowDebug(logmysql_handle);
return 0;
}
- return 1;
}
+ else
#endif
-// if((logfp=fopen(log_config.log_zeny,"a+")) == NULL)
-// return 0;
-// time(&curtime);
-// strftime(timestring, 254, "%m/%d/%Y %H:%M:%S", localtime(&curtime));
-// fprintf(logfp,"%s - %s[%d]\t%s[%d]\t%d\n", timestring, sd->status.name, sd->status.account_id, target_sd->status.name, target_sd->status.account_id, sd->deal.zeny);
-// fclose(logfp);
-// return 1;
- return 0;
+ {
+ FILE* logfp;
+ if((logfp=fopen(log_config.log_zeny,"a+")) == NULL)
+ return 0;
+ time(&curtime);
+ strftime(timestring, 254, "%m/%d/%Y %H:%M:%S", localtime(&curtime));
+ fprintf(logfp, "%s - %s[%d]\t%s[%d]\t%d\t\n", timestring, src_sd->status.name, src_sd->status.account_id, sd->status.name, sd->status.account_id, amount);
+ fclose(logfp);
+ }
+
+ return 1;
}
int log_mvpdrop(struct map_session_data *sd, int monster_id, int *log_mvp)
{
- FILE *logfp;
-
if(!log_config.enable_logs)
return 0;
+
nullpo_retr(0, sd);
+
#ifndef TXT_ONLY
if(log_config.sql_logs > 0)
{
- sprintf(tmp_sql, "INSERT DELAYED INTO `%s` (`mvp_date`, `kill_char_id`, `monster_id`, `prize`, `mvpexp`, `map`) VALUES (NOW(), '%d', '%d', '%d', '%d', '%s') ", log_config.log_mvpdrop_db, sd->status.char_id, monster_id, log_mvp[0], log_mvp[1], mapindex_id2name(sd->mapindex));
- if(mysql_query(&logmysql_handle, tmp_sql))
+ if (SQL_ERROR == Sql_Query(logmysql_handle, "INSERT DELAYED INTO `%s` (`mvp_date`, `kill_char_id`, `monster_id`, `prize`, `mvpexp`, `map`) VALUES (NOW(), '%d', '%d', '%d', '%d', '%s') ",
+ log_config.log_mvpdrop_db, sd->status.char_id, monster_id, log_mvp[0], log_mvp[1], mapindex_id2name(sd->mapindex)) )
{
- ShowSQL("DB error - %s\n",mysql_error(&logmysql_handle));
- ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
+ Sql_ShowDebug(logmysql_handle);
return 0;
}
- return 1;
}
+ else
#endif
- if((logfp=fopen(log_config.log_mvpdrop,"a+")) == NULL)
- return 0;
- time(&curtime);
- strftime(timestring, 254, "%m/%d/%Y %H:%M:%S", localtime(&curtime));
- fprintf(logfp,"%s - %s[%d:%d]\t%d\t%d,%d\n", timestring, sd->status.name, sd->status.account_id, sd->status.char_id, monster_id, log_mvp[0], log_mvp[1]);
- fclose(logfp);
- return 0;
+ {
+ FILE* logfp;
+ if((logfp=fopen(log_config.log_mvpdrop,"a+")) == NULL)
+ return 0;
+ time(&curtime);
+ strftime(timestring, 254, "%m/%d/%Y %H:%M:%S", localtime(&curtime));
+ fprintf(logfp,"%s - %s[%d:%d]\t%d\t%d,%d\n", timestring, sd->status.name, sd->status.account_id, sd->status.char_id, monster_id, log_mvp[0], log_mvp[1]);
+ fclose(logfp);
+ }
+
+ return 1;
}
-int log_atcommand(struct map_session_data *sd, const char *message)
+int log_atcommand(struct map_session_data* sd, const char* message)
{
- FILE *logfp;
-#ifndef TXT_ONLY
- char t_name[NAME_LENGTH*2];
- char t_msg[CHAT_SIZE*2+1]; //These are the contents of an @ call, so there shouldn't be overflow danger here?
-#endif
-
if(!log_config.enable_logs)
return 0;
+
nullpo_retr(0, sd);
+
#ifndef TXT_ONLY
if(log_config.sql_logs > 0)
{
+ SqlStmt* stmt;
+
if (strlen(message) > CHAT_SIZE) {
if (battle_config.error_log)
- ShowError("log atcommand: Received message too long from player %s (%d:%d)!\n",
- sd->status.name, sd->status.account_id, sd->status.char_id);
+ ShowError("log atcommand: Received message too long from player %s (%d:%d)!\n", sd->status.name, sd->status.account_id, sd->status.char_id);
return 0;
}
- sprintf(tmp_sql, "INSERT DELAYED INTO `%s` (`atcommand_date`, `account_id`, `char_id`, `char_name`, `map`, `command`) VALUES(NOW(), '%d', '%d', '%s', '%s', '%s') ",
- log_config.log_gm_db, sd->status.account_id, sd->status.char_id, jstrescapecpy(t_name, sd->status.name), mapindex_id2name(sd->mapindex), jstrescapecpy(t_msg, (char *)message));
- if(mysql_query(&logmysql_handle, tmp_sql))
+
+ stmt = SqlStmt_Malloc(logmysql_handle);
+ if( SQL_SUCCESS != SqlStmt_Prepare(stmt, "INSERT DELAYED INTO `%s` (`atcommand_date`, `account_id`, `char_id`, `char_name`, `map`, `command`) VALUES (NOW(), '%d', '%d', ?, '%s', ?)", log_config.log_gm_db, sd->status.account_id, sd->status.char_id, sd->status.name, mapindex_id2name(sd->mapindex), message)
+ || SQL_SUCCESS != SqlStmt_BindParam(stmt, 0, SQLDT_STRING, sd->status.name, strnlen(sd->status.name, NAME_LENGTH))
+ || SQL_SUCCESS != SqlStmt_BindParam(stmt, 1, SQLDT_STRING, (char*)message, strnlen(message, 255))
+ || SQL_SUCCESS != SqlStmt_Execute(stmt) )
{
- ShowSQL("DB error - %s\n",mysql_error(&logmysql_handle));
- ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
+ SqlStmt_ShowDebug(stmt);
+ SqlStmt_Free(stmt);
return 0;
}
- return 1;
+ SqlStmt_Free(stmt);
}
+ else
#endif
- if((logfp=fopen(log_config.log_gm,"a+")) == NULL)
- return 0;
- time(&curtime);
- strftime(timestring, 254, "%m/%d/%Y %H:%M:%S", localtime(&curtime));
- fprintf(logfp,"%s - %s[%d]: %s\n",timestring,sd->status.name,sd->status.account_id,message);
- fclose(logfp);
+ {
+ FILE* logfp;
+ if((logfp = fopen(log_config.log_gm, "a+")) == NULL)
+ return 0;
+ time(&curtime);
+ strftime(timestring, 254, "%m/%d/%Y %H:%M:%S", localtime(&curtime));
+ fprintf(logfp, "%s - %s[%d]: %s\n", timestring, sd->status.name, sd->status.account_id, message);
+ fclose(logfp);
+ }
+
return 1;
}
-int log_npc(struct map_session_data *sd, const char *message)
-{ //[Lupus]
- FILE *logfp;
-#ifndef TXT_ONLY
- char t_name[NAME_LENGTH*2];
- char t_msg[255+1]; //it's 255 chars MAX.
-#endif
-
+int log_npc(struct map_session_data* sd, const char* message)
+{
if(!log_config.enable_logs)
return 0;
+
nullpo_retr(0, sd);
+
#ifndef TXT_ONLY
if(log_config.sql_logs > 0)
{
- sprintf(tmp_sql, "INSERT DELAYED INTO `%s` (`npc_date`, `account_id`, `char_id`, `char_name`, `map`, `mes`) VALUES(NOW(), '%d', '%d', '%s', '%s', '%s') ",
- log_config.log_npc_db, sd->status.account_id, sd->status.char_id, jstrescapecpy(t_name, sd->status.name), mapindex_id2name(sd->mapindex), jstrescapecpy(t_msg, (char *)message));
- if(mysql_query(&logmysql_handle, tmp_sql))
+ SqlStmt* stmt;
+ stmt = SqlStmt_Malloc(logmysql_handle);
+ if( SQL_SUCCESS != SqlStmt_Prepare(stmt, "INSERT DELAYED INTO `%s` (`npc_date`, `account_id`, `char_id`, `char_name`, `map`, `mes`) VALUES (NOW(), '%d', '%d', ?, '%s', ?)", log_config.log_npc_db, sd->status.account_id, sd->status.char_id, sd->status.name, mapindex_id2name(sd->mapindex), message)
+ || SQL_SUCCESS != SqlStmt_BindParam(stmt, 0, SQLDT_STRING, sd->status.name, strnlen(sd->status.name, NAME_LENGTH))
+ || SQL_SUCCESS != SqlStmt_BindParam(stmt, 1, SQLDT_STRING, (char*)message, strnlen(message, 255))
+ || SQL_SUCCESS != SqlStmt_Execute(stmt) )
{
- ShowSQL("DB error - %s\n",mysql_error(&logmysql_handle));
- ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
+ SqlStmt_ShowDebug(stmt);
+ SqlStmt_Free(stmt);
return 0;
}
- return 1;
+ SqlStmt_Free(stmt);
}
+ else
#endif
- if((logfp=fopen(log_config.log_npc,"a+")) == NULL)
- return 0;
- time(&curtime);
- strftime(timestring, 254, "%m/%d/%Y %H:%M:%S", localtime(&curtime));
- fprintf(logfp,"%s - %s[%d]: %s\n",timestring,sd->status.name,sd->status.account_id,message);
- fclose(logfp);
+ {
+ FILE* logfp;
+ if((logfp = fopen(log_config.log_npc, "a+")) == NULL)
+ return 0;
+ time(&curtime);
+ strftime(timestring, 254, "%m/%d/%Y %H:%M:%S", localtime(&curtime));
+ fprintf(logfp, "%s - %s[%d]: %s\n", timestring, sd->status.name, sd->status.account_id, message);
+ fclose(logfp);
+ }
+
return 1;
}
-
int log_chat(const char* type, int type_id, int src_charid, int src_accid, const char* map, int x, int y, const char* dst_charname, const char* message)
{
+ //FIXME: the actual filtering is being done by the calling code instead of in here, why!?
+
// Log CHAT (Global, Whisper, Party, Guild, Main chat)
// LOGGING FILTERS [Lupus]
//=============================================================
@@ -353,42 +376,45 @@ int log_chat(const char* type, int type_id, int src_charid, int src_accid, const
//16 - Log Main chat messages
//32 - Don't log anything when WOE is on
- FILE *logfp;
-#ifndef TXT_ONLY
- char t_charname[NAME_LENGTH*2];
- char t_msg[CHAT_SIZE*2+1]; //Chat line fully escaped, with an extra space just in case.
-#endif
-
//Check ON/OFF
if(log_config.chat <= 0)
return 0; //Deactivated
#ifndef TXT_ONLY
- if(log_config.sql_logs > 0){
+ if(log_config.sql_logs > 0)
+ {
+ SqlStmt* stmt;
+
if (strlen(message) > CHAT_SIZE) {
if (battle_config.error_log)
- ShowError("log chat: Received message too long from type %d (%d:%d)!\n",
- type_id, src_accid, src_charid);
+ ShowError("log chat: Received message too long from type %d (%d:%d)!\n", type_id, src_accid, src_charid);
return 0;
}
- sprintf(tmp_sql, "INSERT DELAYED INTO `%s` (`time`, `type`, `type_id`, `src_charid`, `src_accountid`, `src_map`, `src_map_x`, `src_map_y`, `dst_charname`, `message`) VALUES (NOW(), '%s', '%d', '%d', '%d', '%s', '%d', '%d', '%s', '%s')",
- log_config.log_chat_db, type, type_id, src_charid, src_accid, map, x, y, jstrescapecpy(t_charname, dst_charname), jstrescapecpy(t_msg, message));
-
- if(mysql_query(&logmysql_handle, tmp_sql)){
- ShowSQL("DB error - %s\n",mysql_error(&logmysql_handle));
- ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
- return 0;
+
+ stmt = SqlStmt_Malloc(logmysql_handle);
+ if( SQL_SUCCESS != SqlStmt_Prepare(stmt, "INSERT DELAYED INTO `%s` (`time`, `type`, `type_id`, `src_charid`, `src_accountid`, `src_map`, `src_map_x`, `src_map_y`, `dst_charname`, `message`) VALUES (NOW(), '%s', '%d', '%d', '%d', '%s', '%d', '%d', ?, ?)", log_config.log_chat_db, type, type_id, src_charid, src_accid, map, x, y)
+ || SQL_SUCCESS != SqlStmt_BindParam(stmt, 0, SQLDT_STRING, (char*)dst_charname, strnlen(dst_charname, NAME_LENGTH))
+ || SQL_SUCCESS != SqlStmt_BindParam(stmt, 1, SQLDT_STRING, (char*)message, strnlen(message, CHAT_SIZE))
+ || SQL_SUCCESS != SqlStmt_Execute(stmt) )
+ {
+ SqlStmt_ShowDebug(stmt);
+ SqlStmt_Free(stmt);
+ return 0;
}
- return 1;
+ SqlStmt_Free(stmt);
}
+ else
#endif
- if((logfp = fopen(log_config.log_chat, "a+")) == NULL)
- return 0;
- time(&curtime);
- strftime(timestring, 254, "%m/%d/%Y %H:%M:%S", localtime(&curtime));
- fprintf(logfp, "%s - %s,%d,%d,%d,%s,%d,%d,%s,%s\n",
- timestring, type, type_id, src_charid, src_accid, map, x, y, dst_charname, message);
- fclose(logfp);
+ {
+ FILE* logfp;
+ if((logfp = fopen(log_config.log_chat, "a+")) == NULL)
+ return 0;
+ time(&curtime);
+ strftime(timestring, 254, "%m/%d/%Y %H:%M:%S", localtime(&curtime));
+ fprintf(logfp, "%s - %s,%d,%d,%d,%s,%d,%d,%s,%s\n", timestring, type, type_id, src_charid, src_accid, map, x, y, dst_charname, message);
+ fclose(logfp);
+ }
+
return 1;
}
diff --git a/src/map/log.h b/src/map/log.h
index ee0b38beb..0065b77c0 100644
--- a/src/map/log.h
+++ b/src/map/log.h
@@ -9,12 +9,6 @@ struct map_session_data;
struct mob_data;
struct item;
-#ifndef TXT_ONLY
-
-extern char db_server_logdb[32];
-
-#endif //NOT TXT_ONLY
-
//New logs
int log_pick_pc(struct map_session_data *sd, const char *type, int nameid, int amount, struct item *itm);
int log_pick_mob(struct mob_data *md, const char *type, int nameid, int amount, struct item *itm);
@@ -30,8 +24,6 @@ int log_mvpdrop(struct map_session_data *sd, int monster_id, int *log_mvp);
int log_config_read(char *cfgName);
-int should_log_item(int filter, int nameid, int amount); //log filter check
-
enum log_what {
LOG_ALL = 0xFFF,
LOG_TRADES = 0x002,
diff --git a/src/map/mail.c b/src/map/mail.c
index 8433fbada..6e6dc0a91 100644
--- a/src/map/mail.c
+++ b/src/map/mail.c
@@ -2,9 +2,6 @@
// For more information, see LICENCE in the main folder
#ifndef TXT_ONLY
-// Mail System for eAthena SQL
-// Created by Valaris
-// moved all strings to msg_athena.conf [Lupus]
#include "../common/strlib.h"
#include "../common/socket.h"
@@ -27,318 +24,345 @@
int MAIL_CHECK_TIME = 120000;
int mail_timer;
-//extern char *msg_table[1000]; // Server messages (0-499 reserved for GM commands, 500-999 reserved for others)
-int mail_check(struct map_session_data *sd,int type)
+/// type: 0 - mail check at login, silent if there aren't any new messages
+/// 1 - @checkmail, just print the number of messages
+/// 2 - @listmail, shows both read and unread messages
+/// 3 - @listnewmail, shows only unread messages
+int mail_check(struct map_session_data* sd, int type)
{
- int i = 0, new_ = 0, priority = 0;
+ int i = 0, new_ = 0, priority = 0; // counters
char message[80];
nullpo_retr (0, sd);
- sprintf(tmp_sql,"SELECT `message_id`,`to_account_id`,`from_char_name`,`read_flag`,`priority`,`check_flag` "
- "FROM `%s` WHERE `to_account_id` = \"%d\" ORDER by `message_id`", mail_db, sd->status.account_id);
-
- if (mysql_query(&mail_handle, tmp_sql)) {
- ShowSQL("DB error - %s\n",mysql_error(&mail_handle));
- ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
+ // retrieve all existing messages for this player
+ if( SQL_ERROR == Sql_Query(mail_handle, "SELECT `message_id`,`to_account_id`,`from_char_name`,`read_flag`,`priority`,`check_flag` FROM `%s` WHERE `to_account_id` = %d ORDER by `message_id`", mail_db, sd->status.account_id) )
+ {
+ Sql_ShowDebug(mail_handle);
return 0;
}
- mail_res = mysql_store_result(&mail_handle);
- if(mail_res) {
- if (mysql_num_rows(mail_res) == 0) {
- //clif_displaymessage(sd->fd,"You have no messages.");
- clif_displaymessage(sd->fd, msg_txt(516));
+ if( Sql_NumRows(mail_handle) == 0)
+ {
+ clif_displaymessage(sd->fd, msg_txt(516)); // "You have no messages."
+ Sql_FreeResult(mail_handle);
+ return 0;
+ }
- mysql_free_result(mail_res);
- return 0;
+ while( SQL_SUCCESS == Sql_NextRow(mail_handle) )
+ {
+ char* data;
+ int message_id;
+ int to_account_id;
+ char from_char_name[NAME_LENGTH];
+ bool read_flag, priority_flag, check_flag;
+
+ Sql_GetData(mail_handle, 0, &data, NULL); message_id = atoi(data);
+ Sql_GetData(mail_handle, 1, &data, NULL); to_account_id = atoi(data);
+ Sql_GetData(mail_handle, 2, &data, NULL); safestrncpy(from_char_name, data, sizeof(from_char_name));
+ Sql_GetData(mail_handle, 3, &data, NULL); read_flag = (bool) atoi(data);
+ Sql_GetData(mail_handle, 4, &data, NULL); priority_flag = (bool) atoi(data);
+ Sql_GetData(mail_handle, 5, &data, NULL); check_flag = (bool) atoi(data);
+
+ i++;
+
+ if( !check_flag )
+ {
+ // mark this message as checked
+ if( SQL_ERROR == Sql_Query(mail_handle, "UPDATE `%s` SET `check_flag` = 1 WHERE `message_id` = %d", mail_db, message_id) )
+ Sql_ShowDebug(mail_handle);
}
- while ((mail_row = mysql_fetch_row(mail_res))) {
- i++;
- if(!atoi(mail_row[5])) {
- sprintf(tmp_sql,"UPDATE `%s` SET `check_flag`='1' WHERE `message_id`= \"%d\"", mail_db, atoi(mail_row[0]));
- if(mysql_query(&mail_handle, tmp_sql) ) {
- ShowSQL("DB error - %s\n",mysql_error(&mail_handle));
- ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
+ if( !read_flag )
+ {
+ new_++;
+ if(priority_flag)
+ priority++;
+
+ if( type == 2 || type == 3 )
+ {
+ if( priority_flag )
+ {
+ snprintf(message, 80, msg_txt(511), i, from_char_name);
+ clif_displaymessage(sd->fd, message); // "%d - From : %s (New - Priority)"
}
- }
-
- if(!atoi(mail_row[3])) {
- new_++;
- if(atoi(mail_row[4]))
- priority++;
- if(type==2 || type==3) {
- if(atoi(mail_row[4])) {
- snprintf(message, 80, msg_txt(511), i, mail_row[2]);
- clif_displaymessage(sd->fd, message);
- } else {
- //sprintf(message, "%d - From : %s (New)", i, mail_row[2]);
- snprintf(message, 80, msg_txt(512), i, mail_row[2]);
- clif_displaymessage(sd->fd, message);
- }
+ else
+ {
+ snprintf(message, 80, msg_txt(512), i, from_char_name);
+ clif_displaymessage(sd->fd, message); // "%d - From : %s (New)"
}
- } else if(type==2){
- snprintf(message, 80, msg_txt(513), i, mail_row[2]);
- clif_displaymessage(sd->fd, message);
}
}
+ else if( type == 2 )
+ {
+ snprintf(message, 80, msg_txt(513), i, from_char_name);
+ clif_displaymessage(sd->fd, message); // "%d - From : %s"
+ }
+ }
- mysql_free_result(mail_res);
- } else {
- ShowSQL("DB error - %s\n",mysql_error(&mail_handle));
- ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
- return 0;
- }
-
- if(i>0 && new_>0 && type==1) {
- //sprintf(message, "You have %d new messages.", new_);
+ Sql_FreeResult(mail_handle);
+
+ if( new_ > 0 && (type == 0 || type == 1) )
+ {
sprintf(message, msg_txt(514), new_);
-
- clif_displaymessage(sd->fd, jstrescape(message));
- }
- if(i>0 && new_>0 && priority>0 && type==1) {
- //sprintf(message, "You have %d unread priority messages.", priority);
- sprintf(message, msg_txt(515), priority);
- clif_displaymessage(sd->fd, jstrescape(message));
+ clif_displaymessage(sd->fd, message); // "You have %d unread messages."
+ if (priority > 0)
+ {
+ sprintf(message, msg_txt(515), priority);
+ clif_displaymessage(sd->fd, message); // "You have %d unread priority messages."
+ }
}
- if(!new_) {
- //clif_displaymessage(sd->fd, "You have no new messages.");
- clif_displaymessage(sd->fd, msg_txt(516));
+ if( new_ == 0 && type != 0 )
+ {
+ clif_displaymessage(sd->fd, msg_txt(516)); // "You have no unread messages."
}
return 0;
}
-int mail_read(struct map_session_data *sd, int message_id)
+/// displays the selected message
+int mail_read(struct map_session_data* sd, int index)
{
-
+ char* data;
+ int message_id;
+ char from_char_name[NAME_LENGTH];
char message[80];
+ bool read_flag, priority_flag, check_flag;
+ char output[100];
- nullpo_retr (0, sd);
+ nullpo_retr(0, sd);
- sprintf(tmp_sql,"SELECT `message_id`,`to_account_id`,`from_char_name`,`message`,`read_flag`,`priority`,`check_flag` from `%s` WHERE `to_account_id` = \"%d\" ORDER by `message_id` LIMIT %d, 1",mail_db,sd->status.account_id,message_id-1);
+ // retrieve the 'index'-th message
+ if( SQL_ERROR == Sql_Query(mail_handle, "SELECT `message_id`,`from_char_name`,`message`,`read_flag`,`priority`,`check_flag` from `%s` WHERE `to_account_id` = %d ORDER by `message_id` LIMIT %d, 1", mail_db, sd->status.account_id, index-1) )
+ {
+ Sql_ShowDebug(mail_handle);
+ return 0;
+ }
- if (mysql_query(&mail_handle, tmp_sql)) {
- ShowSQL("DB error - %s\n",mysql_error(&mail_handle));
- ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
+ if( 0 == Sql_NumRows(mail_handle) )
+ {
+ clif_displaymessage(sd->fd, msg_txt(517)); // "Message not found."
+ Sql_FreeResult(mail_handle);
return 0;
- }
-
- mail_res = mysql_store_result(&mail_handle);
- if(mail_res) {
- if (mysql_num_rows(mail_res) == 0) {
- mysql_free_result(mail_res);
- //clif_displaymessage(sd->fd, "Message not found.");
- clif_displaymessage(sd->fd, msg_txt(517));
- return 0;
- }
+ }
- if ((mail_row = mysql_fetch_row(mail_res))) {
- if(!atoi(mail_row[6])) {
- sprintf(tmp_sql,"UPDATE `%s` SET `check_flag`='1' WHERE `message_id`= \"%d\"", mail_db, atoi(mail_row[0]));
- if(mysql_query(&mail_handle, tmp_sql) ) {
- ShowSQL("DB error - %s\n",mysql_error(&mail_handle));
- ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
- }
- }
+ if( SQL_ERROR == Sql_NextRow(mail_handle) )
+ {
+ Sql_ShowDebug(mail_handle);
+ Sql_FreeResult(mail_handle);
+ return 0;
+ }
- //sprintf(message, "Reading message from %s", mail_row[2]);
- sprintf(message, msg_txt(518), mail_row[2]);
- clif_displaymessage(sd->fd, jstrescape(message));
+ Sql_GetData(mail_handle, 0, &data, NULL); message_id = atoi(data);
+ Sql_GetData(mail_handle, 1, &data, NULL); safestrncpy(from_char_name, data, sizeof(from_char_name));
+ Sql_GetData(mail_handle, 2, &data, NULL); safestrncpy(message, data, sizeof(message));
+ Sql_GetData(mail_handle, 3, &data, NULL); read_flag = (bool) atoi(data);
+ Sql_GetData(mail_handle, 4, &data, NULL); priority_flag = (bool) atoi(data);
+ Sql_GetData(mail_handle, 5, &data, NULL); check_flag = (bool) atoi(data);
- sprintf(message, "%s", mail_row[3]);
- clif_displaymessage(sd->fd, jstrescape(message));
+ Sql_FreeResult(mail_handle);
- sprintf(tmp_sql,"UPDATE `%s` SET `read_flag`='1' WHERE `message_id`= \"%d\"", mail_db, atoi(mail_row[0]));
- if(mysql_query(&mail_handle, tmp_sql) ) {
- ShowSQL("DB error - %s\n",mysql_error(&mail_handle));
- ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
- }
- }
+ // mark mail as checked
+ if( !check_flag )
+ {
+ if( SQL_ERROR == Sql_Query(mail_handle, "UPDATE `%s` SET `check_flag` = 1 WHERE `message_id` = %d", mail_db, message_id) )
+ Sql_ShowDebug(mail_handle);
+ }
- mysql_free_result(mail_res);
+ sprintf(output, msg_txt(518), from_char_name);
+ clif_displaymessage(sd->fd, output); // "Reading message from %s"
+ clif_displaymessage(sd->fd, message);
- } else {
- ShowSQL("DB error - %s\n",mysql_error(&mail_handle));
- ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
- }
+ if( SQL_ERROR == Sql_Query(mail_handle, "UPDATE `%s` SET `read_flag` = 1 WHERE `message_id` = %d", mail_db, message_id) )
+ {
+ Sql_ShowDebug(mail_handle);
+ }
return 0;
}
-int mail_delete(struct map_session_data *sd, int message_id)
+/// message deletion
+int mail_delete(struct map_session_data* sd, int index)
{
+ char* data;
+ int message_id;
+ bool read_flag, priority_flag, check_flag;
+
nullpo_retr (0, sd);
- sprintf(tmp_sql,"SELECT `message_id`,`to_account_id`,`read_flag`,`priority`,`check_flag` from `%s` WHERE `to_account_id` = \"%d\" ORDER by `message_id` LIMIT %d, 1",mail_db,sd->status.account_id,message_id-1);
+ if( SQL_ERROR == Sql_Query(mail_handle, "SELECT `message_id`,`read_flag`,`priority`,`check_flag` from `%s` WHERE `to_account_id` = %d ORDER by `message_id` LIMIT %d, 1", mail_db, sd->status.account_id, index-1) )
+ {
+ Sql_ShowDebug(mail_handle);
+ return 0;
+ }
- if (mysql_query(&mail_handle, tmp_sql)) {
- ShowSQL("DB error - %s\n",mysql_error(&mail_handle));
- ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
+ if( 0 == Sql_NumRows(mail_handle) )
+ {
+ clif_displaymessage(sd->fd, msg_txt(517)); // "Message not found."
+ Sql_FreeResult(mail_handle);
return 0;
- }
-
- mail_res = mysql_store_result(&mail_handle);
- if(mail_res) {
- if (mysql_num_rows(mail_res) == 0) {
- mysql_free_result(mail_res);
- //clif_displaymessage(sd->fd, "Message not found.");
- clif_displaymessage(sd->fd, msg_txt(517));
- return 0;
- }
+ }
+
+ if( SQL_ERROR == Sql_NextRow(mail_handle) )
+ {
+ Sql_ShowDebug(mail_handle);
+ Sql_FreeResult(mail_handle);
+ return 0;
+ }
- if ((mail_row = mysql_fetch_row(mail_res))) {
- if(!atoi(mail_row[2]) && atoi(mail_row[3])) {
- mysql_free_result(mail_res);
- //clif_displaymessage(sd->fd,"Cannot delete unread priority mail.");
- clif_displaymessage(sd->fd,msg_txt(519));
+ Sql_GetData(mail_handle, 0, &data, NULL); message_id = atoi(data);
+ Sql_GetData(mail_handle, 1, &data, NULL); read_flag = (bool)atoi(data);
+ Sql_GetData(mail_handle, 2, &data, NULL); priority_flag = (bool)atoi(data);
+ Sql_GetData(mail_handle, 3, &data, NULL); check_flag = (bool)atoi(data);
- return 0;
- }
- if(!atoi(mail_row[4])) {
- mysql_free_result(mail_res);
- //clif_displaymessage(sd->fd,"You have received new mail, use @listmail before deleting.");
- clif_displaymessage(sd->fd,msg_txt(520));
- return 0;
- }
- sprintf(tmp_sql,"DELETE FROM `%s` WHERE `message_id` = \"%d\"", mail_db, atoi(mail_row[0]));
- if(mysql_query(&mail_handle, tmp_sql) ) {
- mysql_free_result(mail_res);
- ShowSQL("DB error - %s\n",mysql_error(&mail_handle));
- ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
- return 0;
- }
- //else clif_displaymessage(sd->fd,"Message deleted.");
- else clif_displaymessage(sd->fd,msg_txt(521));
- }
+ Sql_FreeResult(mail_handle);
- mysql_free_result(mail_res);
+ if( !read_flag && priority_flag )
+ {
+ clif_displaymessage(sd->fd,msg_txt(519)); // "Cannot delete unread priority mail."
+ return 0;
+ }
- } else {
- ShowSQL("DB error - %s\n",mysql_error(&mail_handle));
- ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
+ if( !check_flag )
+ {
+ clif_displaymessage(sd->fd,msg_txt(520)); // "You have received new mail, use @listmail before deleting."
+ return 0;
}
+ if( SQL_ERROR == Sql_Query(mail_handle, "DELETE FROM `%s` WHERE `message_id` = %d", mail_db, message_id) )
+ {
+ Sql_ShowDebug(mail_handle);
+ return 0;
+ }
+
+ clif_displaymessage(sd->fd,msg_txt(521)); // "Message deleted."
+
return 0;
}
-int mail_send(struct map_session_data *sd, char *name, char *message, int flag)
+/// for sending normal and priority messages
+int mail_send(struct map_session_data* sd, char* name, char* message, int flag)
{
+ SqlStmt* stmt;
+
nullpo_retr (0, sd);
- if(pc_isGM(sd) < 80 && sd->mail_counter > 0) {
- //clif_displaymessage(sd->fd,"You must wait 10 minutes before sending another message");
- clif_displaymessage(sd->fd,msg_txt(522));
+ if( pc_isGM(sd) < 80 && sd->mail_counter > 0 )
+ {
+ clif_displaymessage(sd->fd,msg_txt(522)); // "You must wait 10 minutes before sending another message"
+ return 0;
+ }
+
+ if( strcmp(name,"*") == 0 && pc_isGM(sd) < 80 )
+ {
+ clif_displaymessage(sd->fd, msg_txt(523)); // "Access Denied."
return 0;
}
- if(strcmp(name,"*")==0) {
- if(pc_isGM(sd) < 80) {
- //clif_displaymessage(sd->fd, "Access Denied.");
- clif_displaymessage(sd->fd, msg_txt(523));
+ if( strcmp(name,"*") == 0 )
+ {
+ if( SQL_ERROR == Sql_Query(mail_handle, "SELECT DISTINCT `account_id` FROM `%s` WHERE `account_id` != '%d' ORDER BY `account_id`", char_db, sd->status.account_id) )
+ {
+ Sql_ShowDebug(mail_handle);
return 0;
}
- else
- sprintf(tmp_sql,"SELECT DISTINCT `account_id` FROM `%s` WHERE `account_id` <> '%d' ORDER BY `account_id`", char_db, sd->status.account_id);
}
else
- sprintf(tmp_sql,"SELECT `account_id`,`name` FROM `%s` WHERE `name` = \"%s\"", char_db, jstrescape(name));
-
- if (mysql_query(&mail_handle, tmp_sql)) {
- ShowSQL("DB error - %s\n",mysql_error(&mail_handle));
- ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
- return 0;
- }
-
- mail_res = mysql_store_result(&mail_handle);
- if(mail_res) {
- if (mysql_num_rows(mail_res) == 0) {
- mysql_free_result(mail_res);
- //clif_displaymessage(sd->fd,"Character does not exist.");
- clif_displaymessage(sd->fd,msg_txt(524));
+ {
+ char name_[2*NAME_LENGTH];
+ Sql_EscapeString(mail_handle, name_, name);
+ if( SQL_ERROR == Sql_Query(mail_handle, "SELECT `account_id` FROM `%s` WHERE `name` = '%s'", char_db, name_) )
+ {
+ Sql_ShowDebug(mail_handle);
return 0;
}
+ }
- while ((mail_row = mysql_fetch_row(mail_res))) {
- if(strcmp(name,"*")==0) {
- sprintf(tmp_sql, "INSERT DELAYED INTO `%s` (`to_account_id`,`from_account_id`,`from_char_name`,`message`,`priority`)"
- " VALUES ('%d', '%d', '%s', '%s', '%d')",mail_db, atoi(mail_row[0]), sd->status.account_id, sd->status.name, jstrescape(message), flag);
- }
- else {
- sprintf(tmp_sql, "INSERT DELAYED INTO `%s` (`to_account_id`,`to_char_name`,`from_account_id`,`from_char_name`,`message`,`priority`)"
- " VALUES ('%d', '%s', '%d', '%s', '%s', '%d')",mail_db, atoi(mail_row[0]), mail_row[1], sd->status.account_id, sd->status.name, jstrescape(message), flag);
- if(pc_isGM(sd) < 80)
- sd->mail_counter=5;
- }
+ if( 0 == Sql_NumRows(mail_handle) )
+ {
+ clif_displaymessage(sd->fd,msg_txt(524)); // "Character does not exist."
+ Sql_FreeResult(mail_handle);
+ return 0;
+ }
- if(mysql_query(&mail_handle, tmp_sql) ) {
- mysql_free_result(mail_res);
- ShowSQL("DB error - %s\n",mysql_error(&mail_handle));
- ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
- return 0;
- }
- }
+ stmt = SqlStmt_Malloc(mail_handle);
+ SqlStmt_Prepare(stmt, "INSERT DELAYED INTO `%s` (`to_account_id`,`to_char_name`,`from_account_id`,`from_char_name`,`message`,`priority`) VALUES (?, ?, '%d', ?, ?, '%d')", mail_db, sd->status.account_id, flag);
+ SqlStmt_BindParam(stmt, 1, SQLDT_STRING, name, strnlen(name, NAME_LENGTH));
+ SqlStmt_BindParam(stmt, 2, SQLDT_STRING, sd->status.name, strnlen(sd->status.name, NAME_LENGTH));
+ SqlStmt_BindParam(stmt, 3, SQLDT_STRING, message, strnlen(message, 80));
+
+ while( SQL_SUCCESS == Sql_NextRow(mail_handle) )
+ {
+ int id;
+ char* data;
+ Sql_GetData(mail_handle, 0, &data, NULL); id = atoi(data);
+ SqlStmt_BindParam(stmt, 0, SQLDT_INT, &id, sizeof(id));
+ if( SQL_ERROR == SqlStmt_Execute(stmt) )
+ SqlStmt_ShowDebug(stmt);
}
+ Sql_FreeResult(mail_handle);
+ SqlStmt_Free(stmt);
- //clif_displaymessage(sd->fd,"Mail has been sent.");
- clif_displaymessage(sd->fd,msg_txt(525));
+ if(pc_isGM(sd) < 80)
+ sd->mail_counter = 5;
+
+ clif_displaymessage(sd->fd,msg_txt(525)); // "Mail has been sent."
return 0;
}
-static int mail_check_timer_sub(struct map_session_data *sd, va_list va)
+/// invoked every MAIL_CHECK_TIME ms, decreases the send blocking counter
+static int mail_check_timer_sub(struct map_session_data* sd, va_list va)
{
- int id = va_arg(va, int);
- if(pc_isGM(sd) < 80 && sd->mail_counter > 0)
+ if(sd->mail_counter > 0)
sd->mail_counter--;
- if(sd->status.account_id==id)
- clif_displaymessage(sd->fd, msg_txt(526)); //you got new email.
return 0;
}
-int mail_check_timer(int tid,unsigned int tick,int id,int data)
+/// periodically checks for new messages and notifies about them
+int mail_check_timer(int tid, unsigned int tick, int id, int data)
{
if(mail_timer != tid)
return 0;
- sprintf(tmp_sql,"SELECT DISTINCT `to_account_id` FROM `%s` WHERE `read_flag` = '0' AND `check_flag` = '0'", mail_db);
+ mail_timer = add_timer(gettick() + MAIL_CHECK_TIME, mail_check_timer, 0, 0);
- if (mysql_query(&mail_handle, tmp_sql)) {
- ShowSQL("DB error - %s\n",mysql_error(&mail_handle));
- ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
- mail_timer=add_timer(gettick()+MAIL_CHECK_TIME,mail_check_timer,0,0);
+ // fetch account ids of people who received new mail since the last iteration
+ if( SQL_ERROR == Sql_Query(mail_handle, "SELECT DISTINCT `to_account_id` FROM `%s` WHERE `read_flag` = '0' AND `check_flag` = '0'", mail_db) )
+ {
+ Sql_ShowDebug(mail_handle);
return 0;
- }
+ }
- mail_res = mysql_store_result(&mail_handle);
+ while( SQL_SUCCESS == Sql_NextRow(mail_handle) )
+ {
+ char* id;
+ struct map_session_data* sd;
+ Sql_GetData(mail_handle, 0, &id, NULL);
+ if( (sd = map_id2sd(atoi(id))) != NULL )
+ clif_displaymessage(sd->fd, msg_txt(526)); // "You have new mail."
+ }
- if (mail_res) {
- if (mysql_num_rows(mail_res) == 0) {
- mysql_free_result(mail_res);
- mail_timer=add_timer(gettick()+MAIL_CHECK_TIME,mail_check_timer,0,0);
- return 0;
- }
+ Sql_FreeResult(mail_handle);
- while ((mail_row = mysql_fetch_row(mail_res)))
- clif_foreachclient(mail_check_timer_sub, atoi(mail_row[0]));
- }
+ // decrease the send-blocking counter
+ clif_foreachclient(mail_check_timer_sub);
- sprintf(tmp_sql,"UPDATE `%s` SET `check_flag`='1' WHERE `check_flag`= '0' ", mail_db);
- if(mysql_query(&mail_handle, tmp_sql) ) {
- ShowSQL("DB error - %s\n",mysql_error(&mail_handle));
- ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
- }
+ // The 'check_flag' indicates whether the player was informed about the message.
+ // All online players were notified by the above code, and offline players will get the notice at next login.
+ // Therefore it is safe to simply set the flag to '1' for all existing mails.
+ if( SQL_ERROR == Sql_Query(mail_handle, "UPDATE `%s` SET `check_flag` = 1 WHERE `check_flag` = 0", mail_db) )
+ Sql_ShowDebug(mail_handle);
- mail_timer=add_timer(gettick()+MAIL_CHECK_TIME,mail_check_timer,0,0);
return 0;
}
int do_init_mail(void)
{
- add_timer_func_list(mail_check_timer,"mail_check_timer");
- mail_timer=add_timer(gettick()+MAIL_CHECK_TIME,mail_check_timer,0,0);
+ add_timer_func_list(mail_check_timer, "mail_check_timer");
+ mail_timer = add_timer(gettick() + MAIL_CHECK_TIME, mail_check_timer, 0, 0);
+
return 0;
}
diff --git a/src/map/mail.h b/src/map/mail.h
index fca124ae4..f753d827b 100644
--- a/src/map/mail.h
+++ b/src/map/mail.h
@@ -5,8 +5,8 @@
#define _MAIL_H_
int mail_check(struct map_session_data *sd, int type);
-int mail_read(struct map_session_data *sd, int message_id);
-int mail_delete(struct map_session_data *sd, int message_id);
+int mail_read(struct map_session_data *sd, int index);
+int mail_delete(struct map_session_data *sd, int index);
int mail_send(struct map_session_data *sd, char *name, char *message, int flag);
int do_init_mail(void);
diff --git a/src/map/map.c b/src/map/map.c
index 7c1ba6c4c..2476e0e0e 100644
--- a/src/map/map.c
+++ b/src/map/map.c
@@ -11,6 +11,7 @@
#include "../common/version.h"
#include "../common/nullpo.h"
#include "../common/strlib.h"
+#include "../common/utils.h"
#include "map.h"
#include "chrif.h"
@@ -34,11 +35,8 @@
#include "mercenary.h" //[orn]
#include "atcommand.h"
#include "charcommand.h"
-
#include "log.h"
-
#include "irc.h"
-
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -50,10 +48,20 @@
#endif
#ifndef TXT_ONLY
-
#include "mail.h"
+#endif
-char tmp_sql[65535]="";
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdarg.h>
+#include <math.h>
+#ifndef _WIN32
+#include <unistd.h>
+#endif
+
+
+#ifndef TXT_ONLY
char default_codepage[32] = "";
int map_server_port = 3306;
@@ -61,9 +69,7 @@ char map_server_ip[32] = "127.0.0.1";
char map_server_id[32] = "ragnarok";
char map_server_pw[32] = "ragnarok";
char map_server_db[32] = "ragnarok";
-MYSQL mmysql_handle;
-MYSQL_RES* sql_res;
-MYSQL_ROW sql_row;
+Sql* mmysql_handle;
int db_use_sqldbs = 0;
char item_db_db[32] = "item_db";
@@ -79,9 +85,7 @@ int log_db_port = 3306;
char log_db_id[32] = "ragnarok";
char log_db_pw[32] = "ragnarok";
char log_db[32] = "log";
-MYSQL logmysql_handle;
-MYSQL_RES* logsql_res;
-MYSQL_ROW logsql_row;
+Sql* logmysql_handle;
// mail system
int mail_server_enable = 0;
@@ -91,9 +95,7 @@ char mail_server_id[32] = "ragnarok";
char mail_server_pw[32] = "ragnarok";
char mail_server_db[32] = "ragnarok";
char mail_db[32] = "mail";
-MYSQL mail_handle;
-MYSQL_RES* mail_res;
-MYSQL_ROW mail_row;
+Sql* mail_handle;
#endif /* not TXT_ONLY */
@@ -1096,7 +1098,7 @@ int map_foreachinpath(int (*func)(struct block_list*,va_list),int m,int x0,int y
if (length)
{ //Adjust final position to fit in the given area.
//TODO: Find an alternate method which does not requires a square root calculation.
- k = sqrt(magnitude2);
+ k = (int)sqrt(magnitude2);
mx1 = x0 + (x1 - x0)*length/k;
my1 = y0 + (y1 - y0)*length/k;
len_limit = MAGNITUDE2(x0,y0, mx1,my1);
@@ -2951,43 +2953,30 @@ int inter_config_read(char *cfgName)
*---------------------------------------*/
int map_sql_init(void)
{
- mysql_init(&mmysql_handle);
+ // main db connection
+ mmysql_handle = Sql_Malloc();
- //DB connection start
ShowInfo("Connecting to the Map DB Server....\n");
- if(!mysql_real_connect(&mmysql_handle, map_server_ip, map_server_id, map_server_pw,
- map_server_db ,map_server_port, (char *)NULL, 0)) {
- //pointer check
- ShowSQL("DB error - %s\n",mysql_error(&mmysql_handle));
- exit(1);
- }
- else {
- ShowStatus("connect success! (Map Server Connection)\n");
- }
+ if( SQL_ERROR == Sql_Connect(mmysql_handle, map_server_id, map_server_pw, map_server_ip, map_server_port, map_server_db) )
+ exit(1);
+ ShowStatus("connect success! (Map Server Connection)\n");
- if(mail_server_enable) { // mail system [Valaris]
- mysql_init(&mail_handle);
- ShowInfo("Connecting to the Mail DB Server....\n");
- if(!mysql_real_connect(&mail_handle, mail_server_ip, mail_server_id, mail_server_pw,
- mail_server_db ,mail_server_port, (char *)NULL, 0)) {
- ShowSQL("DB error - %s\n",mysql_error(&mail_handle));
- exit(1);
- }
- if( strlen(default_codepage) > 0 ) {
- sprintf( tmp_sql, "SET NAMES %s", default_codepage );
- if (mysql_query(&mail_handle, tmp_sql)) {
- ShowSQL("DB error - %s\n",mysql_error(&mail_handle));
- ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
- }
- }
- }
+ if( strlen(default_codepage) > 0 )
+ if ( SQL_ERROR == Sql_SetEncoding(mmysql_handle, default_codepage) )
+ Sql_ShowDebug(mmysql_handle);
- if( strlen(default_codepage) > 0 ) {
- sprintf( tmp_sql, "SET NAMES %s", default_codepage );
- if (mysql_query(&mmysql_handle, tmp_sql)) {
- ShowSQL("DB error - %s\n",mysql_error(&mmysql_handle));
- ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
- }
+ if(mail_server_enable)
+ {
+ // mail system
+ mail_handle = Sql_Malloc();
+
+ ShowInfo("Connecting to the Mail DB Server....\n");
+ if( SQL_ERROR == Sql_Connect(mail_handle, mail_server_id, mail_server_pw, mail_server_ip, mail_server_port, mail_server_db) )
+ exit(1);
+
+ if( strlen(default_codepage) > 0 )
+ if ( SQL_ERROR == Sql_SetEncoding(mail_handle, default_codepage) )
+ Sql_ShowDebug(mail_handle);
}
return 0;
@@ -2995,13 +2984,15 @@ int map_sql_init(void)
int map_sql_close(void)
{
- mysql_close(&mmysql_handle);
ShowStatus("Close Map DB Connection....\n");
+ Sql_Free(mmysql_handle);
+ mmysql_handle = NULL;
if (log_config.sql_logs)
{
- mysql_close(&logmysql_handle);
ShowStatus("Close Log DB Connection....\n");
+ Sql_Free(logmysql_handle);
+ logmysql_handle = NULL;
}
return 0;
@@ -3009,25 +3000,18 @@ int map_sql_close(void)
int log_sql_init(void)
{
- mysql_init(&logmysql_handle);
+ // log db connection
+ logmysql_handle = Sql_Malloc();
- //DB connection start
ShowInfo(""CL_WHITE"[SQL]"CL_RESET": Connecting to the Log Database "CL_WHITE"%s"CL_RESET" At "CL_WHITE"%s"CL_RESET"...\n",log_db,log_db_ip);
- if(!mysql_real_connect(&logmysql_handle, log_db_ip, log_db_id, log_db_pw,
- log_db ,log_db_port, (char *)NULL, 0)) {
- //pointer check
- ShowSQL("DB error - %s\n",mysql_error(&logmysql_handle));
- exit(1);
- }
-
+ if ( SQL_ERROR == Sql_Connect(logmysql_handle, log_db_id, log_db_pw, log_db_ip, log_db_port, log_db) )
+ exit(1);
ShowStatus(""CL_WHITE"[SQL]"CL_RESET": Successfully '"CL_GREEN"connected"CL_RESET"' to Database '"CL_WHITE"%s"CL_RESET"'.\n", log_db);
- if( strlen(default_codepage) > 0 ) {
- sprintf( tmp_sql, "SET NAMES %s", default_codepage );
- if (mysql_query(&logmysql_handle, tmp_sql)) {
- ShowSQL("DB error - %s\n",mysql_error(&logmysql_handle));
- ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
- }
- }
+
+ if( strlen(default_codepage) > 0 )
+ if ( SQL_ERROR == Sql_SetEncoding(logmysql_handle, default_codepage) )
+ Sql_ShowDebug(logmysql_handle);
+
return 0;
}
@@ -3037,31 +3021,25 @@ int log_sql_init(void)
int map_sql_ping(int tid, unsigned int tick, int id, int data)
{
ShowInfo("Pinging SQL server to keep connection alive...\n");
- mysql_ping(&mmysql_handle);
+ Sql_Ping(mmysql_handle);
if (log_config.sql_logs)
- mysql_ping(&logmysql_handle);
+ Sql_Ping(logmysql_handle);
if(mail_server_enable)
- mysql_ping(&mail_handle);
+ Sql_Ping(mail_handle);
return 0;
}
int sql_ping_init(void)
{
- int connection_timeout, connection_ping_interval;
+ uint32 connection_timeout, connection_ping_interval;
- // set a default value first
+ // set a default value
connection_timeout = 28800; // 8 hours
// ask the mysql server for the timeout value
- if (!mysql_query(&mmysql_handle, "SHOW VARIABLES LIKE 'wait_timeout'")
- && (sql_res = mysql_store_result(&mmysql_handle)) != NULL) {
- sql_row = mysql_fetch_row(sql_res);
- if (sql_row)
- connection_timeout = atoi(sql_row[1]);
- if (connection_timeout < 60)
- connection_timeout = 60;
- mysql_free_result(sql_res);
- }
+ Sql_GetTimeout(mmysql_handle, &connection_timeout);
+ if (connection_timeout < 60)
+ connection_timeout = 60;
// establish keepalive
connection_ping_interval = connection_timeout - 30; // 30-second reserve
diff --git a/src/map/map.h b/src/map/map.h
index 15a0ece81..cd28f0f14 100644
--- a/src/map/map.h
+++ b/src/map/map.h
@@ -795,7 +795,7 @@ struct map_session_data {
char fakename[NAME_LENGTH]; // fake names [Valaris]
#ifndef TXT_ONLY
- int mail_counter; // mail counter for mail system [Valaris]
+ int mail_counter; // mail counter for mail system (antiflood protection)
#endif
int duel_group; // duel vars [LuzZza]
@@ -1396,37 +1396,6 @@ extern char *MSG_CONF_NAME;
extern char *map_server_dns;
-#ifndef TXT_ONLY
-
-#ifdef WIN32
-#include <winsock2.h>
-#endif
-#include <mysql.h>
-
-extern char tmp_sql[65535];
-
-extern int db_use_sqldbs;
-extern MYSQL mmysql_handle;
-extern MYSQL_RES* sql_res ;
-extern MYSQL_ROW sql_row ;
-
-extern MYSQL logmysql_handle;
-extern MYSQL_RES* logsql_res ;
-extern MYSQL_ROW logsql_row ;
-
-extern int mail_server_enable;
-extern MYSQL mail_handle;
-extern MYSQL_RES* mail_res ;
-extern MYSQL_ROW mail_row ;
-
-extern char item_db_db[32];
-extern char item_db2_db[32];
-extern char mob_db_db[32];
-extern char mob_db2_db[32];
-extern char char_db[32];
-extern char mail_db[32];
-
-#endif /* not TXT_ONLY */
//Useful typedefs from jA [Skotlex]
typedef struct map_session_data TBL_PC;
typedef struct npc_data TBL_NPC;
@@ -1444,4 +1413,24 @@ typedef struct homun_data TBL_HOM;
extern int lowest_gm_level;
extern char main_chat_nick[16];
+#ifndef TXT_ONLY
+
+#include "../common/sql.h"
+
+extern int db_use_sqldbs;
+extern int mail_server_enable;
+
+extern Sql* mmysql_handle;
+extern Sql* logmysql_handle;
+extern Sql* mail_handle;
+
+extern char item_db_db[32];
+extern char item_db2_db[32];
+extern char mob_db_db[32];
+extern char mob_db2_db[32];
+extern char char_db[32];
+extern char mail_db[32];
+
+#endif /* not TXT_ONLY */
+
#endif /* _MAP_H_ */
diff --git a/src/map/mob.c b/src/map/mob.c
index 86d60a152..b5c83413c 100644
--- a/src/map/mob.c
+++ b/src/map/mob.c
@@ -9,6 +9,7 @@
#include "../common/showmsg.h"
#include "../common/ers.h"
#include "../common/strlib.h"
+#include "../common/utils.h"
#include "map.h"
#include "clif.h"
@@ -3210,7 +3211,10 @@ static unsigned int mob_drop_adjust(int rate, int rate_adjust, unsigned short ra
return cap_value(rate,rate_min,rate_max);
}
-int mob_parse_dbrow(char** str)
+/*==========================================
+ * processes one mobdb entry
+ *------------------------------------------*/
+static bool mob_parse_dbrow(char** str)
{
struct mob_db *db;
struct status_data *status;
@@ -3220,15 +3224,15 @@ int mob_parse_dbrow(char** str)
class_ = str[0] ? atoi(str[0]) : 0;
if (class_ == 0)
- return 0; //Leave blank lines alone... [Skotlex]
+ return false; //Leave blank lines alone... [Skotlex]
if (class_ <= 1000 || class_ > MAX_MOB_DB) {
ShowWarning("Mob with ID: %d not loaded. ID must be in range [%d-%d]\n", class_, 1000, MAX_MOB_DB);
- return 0;
+ return false;
}
if (pcdb_checkid(class_)) {
ShowWarning("Mob with ID: %d not loaded. That ID is reserved for player classes.\n");
- return 0;
+ return false;
}
if (mob_db_data[class_] == NULL)
@@ -3432,7 +3436,7 @@ int mob_parse_dbrow(char** str)
}
}
- return 1;
+ return true;
}
/*==========================================
@@ -3440,83 +3444,113 @@ int mob_parse_dbrow(char** str)
*------------------------------------------*/
static int mob_readdb(void)
{
- FILE *fp;
- char line[1024];
- char *filename[]={ "mob_db.txt","mob_db2.txt" };
- int i, fi;
- unsigned int ln = 0;
+ char* filename[] = { "mob_db.txt", "mob_db2.txt" };
+ int fi;
- for(fi = 0; fi < 2; fi++) {
- sprintf(line, "%s/%s", db_path, filename[fi]);
- fp = fopen(line, "r");
+ for(fi = 0; fi < 2; fi++)
+ {
+ uint32 lines = 0, count = 0;
+ char line[1024];
+ char path[256];
+ FILE* fp;
+
+ sprintf(path, "%s/%s", db_path, filename[fi]);
+ fp = fopen(path, "r");
if(fp == NULL) {
if(fi > 0)
continue;
return -1;
}
+ // process rows one by one
while(fgets(line, sizeof(line), fp))
{
char *str[38+2*MAX_MOB_DROP], *p, *np;
+ int i;
+ lines++;
if(line[0] == '/' && line[1] == '/')
continue;
- for(i = 0, p = line; i < 38 + 2*MAX_MOB_DROP; i++) {
+ for(i = 0, p = line; i < 38 + 2*MAX_MOB_DROP; i++)
+ {
+ str[i] = p;
if((np = strchr(p, ',')) != NULL) {
- str[i] = p; *np = 0; p = np + 1;
- } else
- str[i] = p;
+ *np = '\0'; p = np + 1;
+ }
}
if(i < 38 + 2*MAX_MOB_DROP) {
- ShowWarning("mob_readdb: Insufficient columns for mob with ID: %d\n", str[0] ? atoi(str[0]) : 0);
+ ShowWarning("mob_readdb: Insufficient columns for mob with id: %d, skipping.\n", atoi(str[0]));
continue;
}
if (!mob_parse_dbrow(str))
continue;
- ln++; // counts the number of correctly parsed entries
+ count++;
}
+
fclose(fp);
- ShowStatus("Done reading '"CL_WHITE"%lu"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", ln, filename[fi]);
- ln = 0;
+
+ ShowStatus("Done reading '"CL_WHITE"%lu"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", count, filename[fi]);
}
+
return 0;
}
#ifndef TXT_ONLY
/*==========================================
- * SQL reading
+ * mob_db table reading
*------------------------------------------*/
static int mob_read_sqldb(void)
{
- char *mob_db_name[] = { mob_db_db, mob_db2_db };
+ char* mob_db_name[] = { mob_db_db, mob_db2_db };
int fi;
- unsigned int ln = 0;
- for (fi = 0; fi < 2; fi++) {
- sprintf (tmp_sql, "SELECT * FROM `%s`", mob_db_name[fi]);
- if (mysql_query(&mmysql_handle, tmp_sql)) {
- ShowSQL("DB error (%s) - %s\n", mob_db_name[fi], mysql_error(&mmysql_handle));
- ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
+ for (fi = 0; fi < 2; fi++)
+ {
+ uint32 lines = 0, count = 0;
+
+ // retrieve all rows from the mob database
+ if( SQL_ERROR == Sql_Query(mmysql_handle, "SELECT * FROM `%s`", mob_db_name[fi]) )
+ {
+ Sql_ShowDebug(mmysql_handle);
continue;
}
- sql_res = mysql_store_result(&mmysql_handle);
- if (sql_res) {
- while((sql_row = mysql_fetch_row(sql_res))){
-
- if (!mob_parse_dbrow(sql_row))
- continue;
+
+ // process rows one by one
+ while( SQL_SUCCESS == Sql_NextRow(mmysql_handle) )
+ {
+ // wrap the result into a TXT-compatible format
+ char line[1024];
+ char* str[38+2*MAX_MOB_DROP];
+ char* p;
+ int i;
+
+ lines++;
+ for(i = 0, p = line; i < 38 + 2*MAX_MOB_DROP; i++)
+ {
+ char* data;
+ size_t len;
+ Sql_GetData(mmysql_handle, i, &data, &len);
- ln++; // counts the number of correctly parsed entries
+ strcpy(p, data);
+ str[i] = p;
+ p+= len + 1;
}
- mysql_free_result(sql_res);
- ShowStatus("Done reading '"CL_WHITE"%lu"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", ln, mob_db_name[fi]);
- ln = 0;
+ if (!mob_parse_dbrow(str))
+ continue;
+
+ count++;
}
+
+ // free the query result
+ Sql_FreeResult(mmysql_handle);
+
+ ShowStatus("Done reading '"CL_WHITE"%lu"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", count, mob_db_name[fi]);
+ count = 0;
}
return 0;
}
diff --git a/src/map/npc.c b/src/map/npc.c
index 4adf4b946..b469878eb 100644
--- a/src/map/npc.c
+++ b/src/map/npc.c
@@ -6,6 +6,7 @@
#include "../common/nullpo.h"
#include "../common/malloc.h"
#include "../common/showmsg.h"
+#include "../common/utils.h"
#include "../common/ers.h"
#include "../common/db.h"
#include "map.h"
diff --git a/src/map/party.c b/src/map/party.c
index e4b960342..284f00a77 100644
--- a/src/map/party.c
+++ b/src/map/party.c
@@ -7,6 +7,7 @@
#include "../common/nullpo.h"
#include "../common/malloc.h"
#include "../common/showmsg.h"
+#include "../common/utils.h"
#include "party.h"
#include "atcommand.h" //msg_txt()
diff --git a/src/map/pc.c b/src/map/pc.c
index 3dd2289c3..d6a41db37 100644
--- a/src/map/pc.c
+++ b/src/map/pc.c
@@ -8,6 +8,7 @@
#include "../common/showmsg.h"
#include "../common/socket.h" // RFIFO*()
#include "../common/timer.h"
+#include "../common/utils.h"
#include "atcommand.h" // get_atcommand_level()
#include "battle.h" // battle_config
@@ -742,7 +743,7 @@ int pc_authok(struct map_session_data *sd, int login_id2, time_t connect_until_t
#ifndef TXT_ONLY
if(mail_server_enable)
- mail_check(sd,1); // check mail at login [Valaris]
+ mail_check(sd,0); // check mail at login [Valaris]
#endif
// message of the limited time of the account
diff --git a/src/map/pet.c b/src/map/pet.c
index b593cbdff..9bebf27bc 100644
--- a/src/map/pet.c
+++ b/src/map/pet.c
@@ -6,6 +6,7 @@
#include "../common/nullpo.h"
#include "../common/malloc.h"
#include "../common/showmsg.h"
+#include "../common/utils.h"
#include "../common/ers.h"
#include "pc.h"
diff --git a/src/map/script.c b/src/map/script.c
index d423d433e..0a5b5fbc0 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -226,13 +226,10 @@ int potion_hp=0, potion_per_hp=0, potion_sp=0, potion_per_sp=0;
int potion_target=0;
#if !defined(TXT_ONLY) && defined(MAPREGSQL)
-// [zBuffer] SQL Mapreg Saving/Loading Database Declaration
char mapregsql_db[32] = "mapreg";
char mapregsql_db_varname[32] = "varname";
char mapregsql_db_index[32] = "index";
char mapregsql_db_value[32] = "value";
-char tmp_sql[65535];
-// --------------------------------------------------------
#endif
int get_com(unsigned char *script,int *pos);
@@ -3222,85 +3219,76 @@ void run_script_main(struct script_state *st)
/*==========================================
* マップ変数の変更
*------------------------------------------*/
-int mapreg_setreg(int num,int val)
+int mapreg_setreg(int num, int val)
{
#if !defined(TXT_ONLY) && defined(MAPREGSQL)
- int i=num>>24;
- char *name=str_buf+str_data[num&0x00ffffff].str;
- char tmp_str[64];
-#endif
+ int i = num >> 24;
+ char* name = str_buf + str_data[num&0x00ffffff].str;
- if(val!=0) {
+ if( val != 0 ) {
if(idb_put(mapreg_db,num,(void*)val))
;
-#if !defined(TXT_ONLY) && defined(MAPREGSQL)
else if(name[1] != '@') {
- sprintf(tmp_sql,"INSERT INTO `%s`(`%s`,`%s`,`%s`) VALUES ('%s','%d','%d')",mapregsql_db,mapregsql_db_varname,mapregsql_db_index,mapregsql_db_value,jstrescapecpy(tmp_str,name),i,val);
- if(mysql_query(&mmysql_handle,tmp_sql)){
- ShowSQL("DB error - %s\n",mysql_error(&mmysql_handle));
- ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
- }
+ char tmp_str[32*2+1];
+ Sql_EscapeStringLen(mmysql_handle, tmp_str, name, strnlen(name, 32));
+ if( SQL_ERROR == Sql_Query(mmysql_handle, "INSERT INTO `%s`(`%s`,`%s`,`%s`) VALUES ('%s','%d','%d')", mapregsql_db, mapregsql_db_varname, mapregsql_db_index, mapregsql_db_value, tmp_str, i, val) )
+ Sql_ShowDebug(mmysql_handle);
}
-#endif
- } else { // [zBuffer]
-#if !defined(TXT_ONLY) && defined(MAPREGSQL)
+ } else { // val == 0
if(name[1] != '@') { // Remove from database because it is unused.
- sprintf(tmp_sql,"DELETE FROM `%s` WHERE `%s`='%s' AND `%s`='%d'",mapregsql_db,mapregsql_db_varname,name,mapregsql_db_index,i);
- if(mysql_query(&mmysql_handle,tmp_sql)){
- ShowSQL("DB error - %s\n",mysql_error(&mmysql_handle));
- ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
- }
+ if( SQL_ERROR == Sql_Query(mmysql_handle, "DELETE FROM `%s` WHERE `%s`='%s' AND `%s`='%d'", mapregsql_db, mapregsql_db_varname, name, mapregsql_db_index, i) )
+ Sql_ShowDebug(mmysql_handle);
}
-#endif
idb_remove(mapreg_db,num);
}
+#else
+ if(val != 0)
+ idb_put(mapreg_db,num,(void*)val);
+ else
+ idb_remove(mapreg_db,num);
+#endif
- mapreg_dirty=1;
+ mapreg_dirty = 1;
return 1;
}
/*==========================================
* 文字列型マップ変数の変更
*------------------------------------------*/
-int mapreg_setregstr(int num,const char *str)
+int mapreg_setregstr(int num, const char* str)
{
- char *p;
-#if !defined(TXT_ONLY) && defined(MAPREGSQL)
- char tmp_str[64];
- char tmp_str2[512];
- int i=num>>24; // [zBuffer]
- char *name=str_buf+str_data[num&0x00ffffff].str;
-#endif
-
- if( str==NULL || *str==0 ){
#if !defined(TXT_ONLY) && defined(MAPREGSQL)
+ int i = num >> 24;
+ char* name = str_buf + str_data[num&0x00ffffff].str;
+
+ if( str==NULL || *str==0 ) {
if(name[1] != '@') {
- sprintf(tmp_sql,"DELETE FROM `%s` WHERE `%s`='%s' AND `%s`='%d'",mapregsql_db,mapregsql_db_varname,name,mapregsql_db_index,i);
- if(mysql_query(&mmysql_handle,tmp_sql)){
- ShowSQL("DB error - %s\n",mysql_error(&mmysql_handle));
- ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
- }
+ if( SQL_ERROR == Sql_Query(mmysql_handle, "DELETE FROM `%s` WHERE `%s`='%s' AND `%s`='%d'", mapregsql_db, mapregsql_db_varname, name, mapregsql_db_index, i) )
+ Sql_ShowDebug(mmysql_handle);
}
-#endif
idb_remove(mapregstr_db,num);
- mapreg_dirty=1;
+ mapreg_dirty = 1;
return 1;
}
- p=(char *)aMallocA((strlen(str)+1)*sizeof(char));
- strcpy(p,str);
- if (idb_put(mapregstr_db,num,p))
+ if (idb_put(mapregstr_db,num, aStrdup(str)))
;
-#if !defined(TXT_ONLY) && defined(MAPREGSQL)
- else if(name[1] != '@'){ //put returned null, so we must insert.
+ else if(name[1] != '@') { //put returned null, so we must insert.
// Someone is causing a database size infinite increase here without name[1] != '@' [Lance]
- sprintf(tmp_sql,"INSERT INTO `%s`(`%s`,`%s`,`%s`) VALUES ('%s','%d','%s')",mapregsql_db,mapregsql_db_varname,mapregsql_db_index,mapregsql_db_value,jstrescapecpy(tmp_str,name),i,jstrescapecpy(tmp_str2,p));
- if(mysql_query(&mmysql_handle,tmp_sql)){
- ShowSQL("DB error - %s\n",mysql_error(&mmysql_handle));
- ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
- }
+ char tmp_str[32*2+1];
+ char tmp_str2[255*2+1];
+ Sql_EscapeStringLen(mmysql_handle, tmp_str, name, strnlen(name, 32));
+ Sql_EscapeStringLen(mmysql_handle, tmp_str2, str, strnlen(str, 255));
+ if( SQL_ERROR == Sql_Query(mmysql_handle, "INSERT INTO `%s`(`%s`,`%s`,`%s`) VALUES ('%s','%d','%s')", mapregsql_db, mapregsql_db_varname, mapregsql_db_index, mapregsql_db_value, tmp_str, i, tmp_str2) )
+ Sql_ShowDebug(mmysql_handle);
}
+#else
+ if( str==NULL || *str==0 )
+ idb_remove(mapregstr_db,num);
+ else
+ idb_put(mapregstr_db,num,aStrdup(str));
#endif
- mapreg_dirty=1;
+
+ mapreg_dirty = 1;
return 1;
}
@@ -3310,83 +3298,87 @@ int mapreg_setregstr(int num,const char *str)
static int script_load_mapreg(void)
{
#if defined(TXT_ONLY) || !defined(MAPREGSQL)
- FILE *fp;
+ FILE* fp;
char line[1024];
- if( (fp=fopen(mapreg_txt,"rt"))==NULL )
+ if( (fp=fopen(mapreg_txt,"rt")) == NULL )
return -1;
while(fgets(line,sizeof(line),fp))
{
- char buf1[256],buf2[1024],*p;
+ char buf1[256],buf2[1024];
+ char* p;
int n,v,s,i;
if( sscanf(line,"%255[^,],%d\t%n",buf1,&i,&n)!=2 &&
(i=0,sscanf(line,"%[^\t]\t%n",buf1,&n)!=1) )
continue;
- if( buf1[strlen(buf1)-1]=='$' ){
- if( sscanf(line+n,"%[^\n\r]",buf2)!=1 ){
- ShowError("%s: %s broken data !\n",mapreg_txt,buf1);
+ if( buf1[strlen(buf1)-1] == '$' ) {
+ if( sscanf(line + n, "%[^\n\r]", buf2) != 1 ) {
+ ShowError("%s: %s broken data !\n", mapreg_txt, buf1);
continue;
}
- p=(char *)aMallocA((strlen(buf2) + 1)*sizeof(char));
- strcpy(p,buf2);
- s= add_str(buf1);
- idb_put(mapregstr_db,(i<<24)|s,p);
- }else{
- if( sscanf(line+n,"%d",&v)!=1 ){
- ShowError("%s: %s broken data !\n",mapreg_txt,buf1);
+ p = aStrdup(buf2);
+ s = add_str(buf1);
+ idb_put(mapregstr_db, (i<<24)|s, p);
+ } else {
+ if( sscanf(line + n, "%d", &v) != 1 ) {
+ ShowError("%s: %s broken data !\n", mapreg_txt, buf1);
continue;
}
- s= add_str(buf1);
- idb_put(mapreg_db,(i<<24)|s,(void*)v);
+ s = add_str(buf1);
+ idb_put(mapreg_db, (i<<24)|s, (void*)v);
}
}
fclose(fp);
- mapreg_dirty=0;
+
+ mapreg_dirty = 0;
return 0;
#else
- // SQL mapreg code start [zBuffer]
/*
- 0 1 2
- +-------------------------+
- | varname | index | value |
- +-------------------------+
- */
- unsigned int perfomance = (unsigned int)time(NULL);
- sprintf(tmp_sql,"SELECT * FROM `%s`",mapregsql_db);
- ShowInfo("Querying script_load_mapreg ...\n");
- if(mysql_query(&mmysql_handle, tmp_sql) ) {
- ShowSQL("DB error - %s\n",mysql_error(&mmysql_handle));
- ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
+ 0 1 2
+ +-------------------------+
+ | varname | index | value |
+ +-------------------------+
+ */
+
+ SqlStmt* stmt = SqlStmt_Malloc(mmysql_handle);
+ char varname[32+1];
+ int index;
+ char value[255+1];
+ uint32 length;
+
+ if ( SQL_ERROR == SqlStmt_Prepare(stmt, "SELECT `%s`, `%s`, `%s` FROM `%s`", mapregsql_db_varname, mapregsql_db_index, mapregsql_db_value, mapregsql_db)
+ || SQL_ERROR == SqlStmt_Execute(stmt)
+ ) {
+ SqlStmt_ShowDebug(stmt);
+ SqlStmt_Free(stmt);
return -1;
}
- ShowInfo("Success! Returning results ...\n");
- sql_res = mysql_store_result(&mmysql_handle);
- if (sql_res) {
- while ((sql_row = mysql_fetch_row(sql_res))) {
- char buf1[33], *p = NULL;
- int i,v,s;
- strcpy(buf1,sql_row[0]);
- if( buf1[strlen(buf1)-1]=='$' ){
- i = atoi(sql_row[1]);
- p=(char *)aMallocA((strlen(sql_row[2]) + 1)*sizeof(char));
- strcpy(p,sql_row[2]);
- s= add_str(buf1);
- idb_put(mapregstr_db,(i<<24)|s,p);
- }else{
- s= add_str(buf1);
- v= atoi(sql_row[2]);
- i = atoi(sql_row[1]);
- idb_put(mapreg_db,(i<<24)|s,(void *)v);
- }
- }
+
+ SqlStmt_BindColumn(stmt, 0, SQLDT_STRING, &varname[0], 32, &length, NULL);
+ SqlStmt_BindColumn(stmt, 1, SQLDT_INT, &index, 0, NULL, NULL);
+ SqlStmt_BindColumn(stmt, 2, SQLDT_STRING, &value[0], 255, NULL, NULL);
+
+ while ( SQL_SUCCESS == SqlStmt_NextRow(stmt) )
+ {
+ if( varname[length-1] == '$' ) {
+ int s = add_str(varname);
+ int i = index;
+ char* p = aStrdup(value);
+ idb_put(mapregstr_db, (i<<24)|s, p);
+ } else {
+ int s = add_str(varname);
+ int i = index;
+ int v = atoi(value);
+ idb_put(mapreg_db, (i<<24)|s, (void *)v);
+ }
}
- ShowInfo("Freeing results...\n");
- mysql_free_result(sql_res);
- mapreg_dirty=0;
- perfomance = (((unsigned int)time(NULL)) - perfomance);
- ShowInfo("SQL Mapreg Loading Completed Under %d Seconds.\n",perfomance);
+
+ SqlStmt_Free(stmt);
+
+ mapreg_dirty = 0;
return 0;
+
#endif /* TXT_ONLY */
}
/*==========================================
@@ -3394,56 +3386,50 @@ static int script_load_mapreg(void)
*------------------------------------------*/
static int script_save_mapreg_intsub(DBKey key,void *data,va_list ap)
{
-#if defined(TXT_ONLY) || !defined(MAPREGSQL)
- FILE *fp=va_arg(ap,FILE*);
int num=key.i&0x00ffffff, i=key.i>>24;
char *name=str_buf+str_data[num].str;
- if( name[1]!='@' ){
+
+#if defined(TXT_ONLY) || !defined(MAPREGSQL)
+ FILE *fp=va_arg(ap,FILE*);
+ if( name[1]!='@' ) {
if(i==0)
fprintf(fp,"%s\t%d\n", name, (int)data);
else
fprintf(fp,"%s,%d\t%d\n", name, i, (int)data);
}
- return 0;
#else
- int num=key.i&0x00ffffff, i=key.i>>24; // [zBuffer]
- char *name=str_buf+str_data[num].str;
if ( name[1] != '@') {
- sprintf(tmp_sql,"UPDATE `%s` SET `%s`='%d' WHERE `%s`='%s' AND `%s`='%d'",mapregsql_db,mapregsql_db_value,(int)data,mapregsql_db_varname,name,mapregsql_db_index,i);
- if(mysql_query(&mmysql_handle, tmp_sql) ) {
- ShowSQL("DB error - %s\n",mysql_error(&mmysql_handle));
- ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
- }
+ if( SQL_ERROR == Sql_Query(mmysql_handle, "UPDATE `%s` SET `%s`='%d' WHERE `%s`='%s' AND `%s`='%d'", mapregsql_db, mapregsql_db_value, (int)data, mapregsql_db_varname, name, mapregsql_db_index, i) )
+ Sql_ShowDebug(mmysql_handle);
}
- return 0;
#endif
+
+ return 0;
}
+
static int script_save_mapreg_strsub(DBKey key,void *data,va_list ap)
{
-#if defined(TXT_ONLY) || !defined(MAPREGSQL)
- FILE *fp=va_arg(ap,FILE*);
int num=key.i&0x00ffffff, i=key.i>>24;
char *name=str_buf+str_data[num].str;
- if( name[1]!='@' ){
+
+#if defined(TXT_ONLY) || !defined(MAPREGSQL)
+ FILE *fp=va_arg(ap,FILE*);
+ if( name[1]!='@' ) {
if(i==0)
fprintf(fp,"%s\t%s\n", name, (char *)data);
else
fprintf(fp,"%s,%d\t%s\n", name, i, (char *)data);
}
- return 0;
#else
- char tmp_str2[512];
- int num=key.i&0x00ffffff, i=key.i>>24;
- char *name=str_buf+str_data[num].str;
if ( name[1] != '@') {
- sprintf(tmp_sql,"UPDATE `%s` SET `%s`='%s' WHERE `%s`='%s' AND `%s`='%d'",mapregsql_db,mapregsql_db_value,jstrescapecpy(tmp_str2,(char *)data),mapregsql_db_varname,name,mapregsql_db_index,i);
- if(mysql_query(&mmysql_handle, tmp_sql) ) {
- ShowSQL("DB error - %s\n",mysql_error(&mmysql_handle));
- ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
- }
+ char tmp_str2[2*255+1];
+ Sql_EscapeStringLen(mmysql_handle, tmp_str2, (char*)data, strnlen((char*)data, 255));
+ if( SQL_ERROR == Sql_Query(mmysql_handle, "UPDATE `%s` SET `%s`='%s' WHERE `%s`='%s' AND `%s`='%d'", mapregsql_db, mapregsql_db_value, tmp_str2, mapregsql_db_varname, name, mapregsql_db_index, i) )
+ Sql_ShowDebug(mmysql_handle);
}
- return 0;
#endif
+
+ return 0;
}
static int script_save_mapreg(void)
{
@@ -3459,12 +3445,8 @@ static int script_save_mapreg(void)
mapregstr_db->foreach(mapregstr_db,script_save_mapreg_strsub,fp);
lock_fclose(fp,mapreg_txt,&lock);
#else
- unsigned int perfomance = (unsigned int)time(NULL);
- mapreg_db->foreach(mapreg_db,script_save_mapreg_intsub); // [zBuffer]
+ mapreg_db->foreach(mapreg_db,script_save_mapreg_intsub);
mapregstr_db->foreach(mapregstr_db,script_save_mapreg_strsub);
- perfomance = ((unsigned int)time(NULL) - perfomance);
- if(perfomance > 2)
- ShowWarning("Slow Query: MapregSQL Saving @ %d second(s).\n", perfomance);
#endif
mapreg_dirty=0;
return 0;
@@ -3688,9 +3670,8 @@ int do_init_script()
script_load_mapreg();
- add_timer_func_list(script_autosave_mapreg,"script_autosave_mapreg");
- add_timer_interval(gettick()+MAPREG_AUTOSAVE_INTERVAL,
- script_autosave_mapreg,0,0,MAPREG_AUTOSAVE_INTERVAL);
+ add_timer_func_list(script_autosave_mapreg, "script_autosave_mapreg");
+ add_timer_interval(gettick() + MAPREG_AUTOSAVE_INTERVAL, script_autosave_mapreg, 0, 0, MAPREG_AUTOSAVE_INTERVAL);
return 0;
}
@@ -12098,6 +12079,7 @@ BUILDIN_FUNC(checkcell)
// <--- [zBuffer] List of mathematics commands
// [zBuffer] List of dynamic var commands --->
+//FIXME: some other functions are using this private function
void setd_sub(struct script_state *st, TBL_PC *sd, char *varname, int elem, void *value, struct linkdb_node **ref)
{
set_reg(st, sd, add_str(varname)+(elem<<24), varname, value, ref);
@@ -12131,80 +12113,78 @@ BUILDIN_FUNC(setd)
BUILDIN_FUNC(query_sql)
{
#ifndef TXT_ONLY
- char *name = NULL;
- const char *query;
- int num, i = 0,j, nb_rows;
- struct { char * dst_var_name; char type; } row[32];
- TBL_PC *sd = (st->rid)? script_rid2sd(st) : NULL;
+ int i, j, nb_rows;
+ struct { char* dst_var_name; char type; } row[32];
+ TBL_PC* sd = (st->rid) ? script_rid2sd(st) : NULL;
- query = script_getstr(st,2);
- strcpy(tmp_sql, query);
- if(mysql_query(&mmysql_handle,tmp_sql)){
- ShowSQL("DB error - %s\n",mysql_error(&mmysql_handle));
- ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
- script_pushint(st,0);
+ const char* query = script_getstr(st,2);
+ if (SQL_ERROR == Sql_Query(mmysql_handle, query) )
+ {
+ Sql_ShowDebug(mmysql_handle);
+ script_pushint(st, 0);
return 1;
}
- // If some data was returned
- if((sql_res = mysql_store_result(&mmysql_handle))){
- // Count the number of rows to store
- nb_rows = mysql_num_fields(sql_res);
+ // Count the number of rows to store
+ nb_rows = Sql_NumColumns(mmysql_handle);
+ //FIXME: what sick mind would write something like this?
- // Can't store more row than variable
- if (nb_rows > st->end - (st->start+3))
- nb_rows = st->end - (st->start+3);
+ // Can't store more row than variable
+ if (nb_rows > st->end - (st->start+3))
+ nb_rows = st->end - (st->start+3);
- if (!nb_rows)
- {
- script_pushint(st,0);
- return 0; // Nothing to store
- }
+ if (!nb_rows)
+ {
+ script_pushint(st,0);
+ return 0; // Nothing to store
+ }
- if (nb_rows > 32)
- {
- ShowWarning("buildin_query_sql: too many rows!\n");
- script_pushint(st,0);
- return 1;
- }
+ if (nb_rows > 32)
+ {
+ ShowWarning("buildin_query_sql: too many rows!\n");
+ script_pushint(st,0);
+ return 1;
+ }
- memset(row, 0, sizeof(row));
- // Verify argument types
- for(j=0; j < nb_rows; j++)
- {
- if(!data_isreference(script_getdata(st, 3+j))){
- ShowWarning("buildin_query_sql: Parameter %d is not a variable!\n", j);
- script_pushint(st,0);
- return 0;
- } else {
- // Store type of variable (string = 0/int = 1)
- num=st->stack->stack_data[st->start+3+j].u.num;
- name=(char *)(str_buf+str_data[num&0x00ffffff].str);
- if(name[strlen(name)-1] != '$') {
- row[j].type = 1;
- }
- row[j].dst_var_name = name;
+ memset(row, 0, sizeof(row));
+ // Verify argument types
+ for(j=0; j < nb_rows; j++)
+ {
+ if(!data_isreference(script_getdata(st, 3+j))){
+ ShowWarning("buildin_query_sql: Parameter %d is not a variable!\n", j);
+ script_pushint(st,0);
+ return 0;
+ } else {
+ // Store type of variable (string = 0/int = 1)
+ int num = st->stack->stack_data[st->start+3+j].u.num;
+ char* name = str_buf + str_data[num&0x00ffffff].str;
+ if(name[strlen(name)-1] != '$') {
+ row[j].type = 1;
}
+ row[j].dst_var_name = name;
}
- // Store data
- while(i<128 && (sql_row = mysql_fetch_row(sql_res))){
- for(j=0; j < nb_rows; j++)
- {
- if (row[j].type == 1)
- setd_sub(st,sd, row[j].dst_var_name, i, (void *)atoi(sql_row[j]),script_getref(st,3+j));
- else
- setd_sub(st,sd, row[j].dst_var_name, i, (void *)sql_row[j],script_getref(st,3+j));
- }
- i++;
+ }
+ // Store data
+ for (i = 0; i < 128 && SQL_SUCCESS == Sql_NextRow(mmysql_handle); i++)
+ {
+ char* data;
+ Sql_GetData(mmysql_handle, j, &data, NULL);
+ for(j = 0; j < nb_rows; j++) {
+ if (row[j].type == 1)
+ setd_sub(st,sd, row[j].dst_var_name, i, (void *)atoi(data), script_getref(st,3+j));
+ else
+ setd_sub(st,sd, row[j].dst_var_name, i, (void *)data, script_getref(st,3+j));
}
- // Free data
- mysql_free_result(sql_res);
}
+ // Free data
+ Sql_FreeResult(mmysql_handle);
+
script_pushint(st,i);
#else
//for TXT version, we always return -1
script_pushint(st,-1);
#endif
+
return 0;
}
diff --git a/src/map/skill.c b/src/map/skill.c
index fc365b7d3..df7564629 100644
--- a/src/map/skill.c
+++ b/src/map/skill.c
@@ -7,6 +7,7 @@
#include "../common/malloc.h"
#include "../common/showmsg.h"
#include "../common/strlib.h"
+#include "../common/utils.h"
#include "../common/ers.h"
#include "skill.h"
diff --git a/src/map/status.c b/src/map/status.c
index b1e2bb1df..b5f0dbfe8 100644
--- a/src/map/status.c
+++ b/src/map/status.c
@@ -6,6 +6,7 @@
#include "../common/nullpo.h"
#include "../common/showmsg.h"
#include "../common/malloc.h"
+#include "../common/utils.h"
#include "pc.h"
#include "map.h"