From e49bce26d3de1a5c2afbe018a869ff8790294fc5 Mon Sep 17 00:00:00 2001 From: Ben Longbons Date: Wed, 16 Mar 2011 00:38:02 -0700 Subject: Use makefiles correctly and expand include dirs --- .gitignore | 12 +++- Makefile | 41 ++++++++--- make.defs | 36 ++++------ src/char/Makefile | 9 ++- src/char/char.c | 12 ++-- src/char/int_guild.c | 8 +-- src/char/int_party.c | 8 +-- src/char/inter.c | 10 +-- src/common/Makefile | 2 +- src/ladmin/Makefile | 3 +- src/ladmin/ladmin.c | 8 +-- src/ladmin/md5calc.c | 2 +- src/login/Makefile | 9 ++- src/login/login.c | 18 ++--- src/map/Makefile | 29 ++++---- src/map/atcommand.c | 8 +-- src/map/battle.c | 8 +-- src/map/chat.c | 6 +- src/map/chrif.c | 6 +- src/map/clif.c | 12 ++-- src/map/guild.c | 10 +-- src/map/intif.c | 6 +- src/map/itemdb.c | 8 +-- src/map/magic-interpreter-lexer.l | 140 +++++++++++++++++++++++++++++++++++++ src/map/magic-interpreter-parser.y | 2 +- src/map/magic-interpreter.h | 4 +- src/map/magic-interpreter.l | 140 ------------------------------------- src/map/map.c | 14 ++-- src/map/map.h | 2 +- src/map/mob.c | 10 +-- src/map/npc.c | 8 +-- src/map/party.c | 10 +-- src/map/path.c | 2 +- src/map/pc.c | 10 +-- src/map/script.c | 12 ++-- src/map/skill-pools.c | 6 +- src/map/skill.c | 6 +- src/map/tmw.c | 10 +-- src/map/trade.c | 2 +- src/tool/Makefile | 21 +++--- src/tool/adduser.c | 8 +-- src/tool/marriage-info.c | 6 +- src/webserver/Makefile | 19 ++--- 43 files changed, 356 insertions(+), 347 deletions(-) create mode 100644 src/map/magic-interpreter-lexer.l delete mode 100644 src/map/magic-interpreter.l diff --git a/.gitignore b/.gitignore index 70363ce..d289860 100644 --- a/.gitignore +++ b/.gitignore @@ -1,12 +1,22 @@ # files generated during make *.o +src/char/char char-server +src/ladmin/ladmin ladmin +src/login/login login-server +src/map/map map-server -GNUmakefile eathena-monitor magic-interpreter-parser.h magic-interpreter-parser.c magic-interpreter-lexer.c +magic-interpreter-parser.output +src/tool/adduser +src/tool/itemfrob +src/tool/mapfrob +src/tool/marriage-info +src/tool/eathena-monitor +src/webserver/webserver diff --git a/Makefile b/Makefile index a6b9350..bc90aa8 100644 --- a/Makefile +++ b/Makefile @@ -1,12 +1,35 @@ -# $Id$ include make.defs -all clean: src/common/Makefile src/login/Makefile src/char/Makefile src/map/Makefile src/ladmin/Makefile - cd src ; cd common ; $(MAKE) $(MKDEF) $@ ; cd .. - cd src ; cd login ; $(MAKE) $(MKDEF) $@ ; cd .. - cd src ; cd char ; $(MAKE) $(MKDEF) $@ ; cd .. - cd src ; cd map ; $(MAKE) $(MKDEF) $@ ; cd .. - cd src ; cd ladmin ; $(MAKE) $(MKDEF) $@ ; cd .. +all: login-server char-server map-server ladmin +common: + ${MAKE} -C src/common +login-server: common + ${MAKE} -C src/login + ${CP} src/login/login login-server +char-server: common + ${MAKE} -C src/char + ${CP} src/char/char char-server +map-server: common + ${MAKE} -C src/map + ${CP} src/map/map map-server +ladmin: common + ${MAKE} -C src/ladmin -tools: - cd src/tool && $(MAKE) $(MKDEF) && cd .. +clean: clean-common clean-login clean-char clean-map clean-ladmin clean-tools + +clean-common: + ${MAKE} -C src/common clean +clean-login: + ${MAKE} -C src/login clean +clean-char: + ${MAKE} -C src/char clean +clean-map: + ${MAKE} -C src/map clean +clean-ladmin: + ${MAKE} -C src/ladmin clean + +# This target is separate for historical reasons, and because it is optional +tools: common + ${MAKE} -C src/tool +clean-tools: + ${MAKE} -C src/tool clean diff --git a/make.defs b/make.defs index b9bc3fb..55710c4 100644 --- a/make.defs +++ b/make.defs @@ -1,28 +1,16 @@ -# Definitions for our funky-chicken build system +# defaults +CC = gcc +CFLAGS = -pipe -g -fno-strict-aliasing -O2 -Wall +CP = cp -f +# The below might cause problems sometimes +# CP = cp -lf +# CP = cp -sf -ifeq ($(shell uname -m), x86_64) -M32=-m32 -endif - -CC = gcc ${M32} -LEX=flex -BISON=bison +# works on both x86 and x86_64 +override CC += -m32 -PLATFORM = $(shell uname) -ifeq ($(findstring FreeBSD,$(PLATFORM)), FreeBSD) -MAKE = gmake +ifeq ($(findstring CYGWIN,$(shell uname)), CYGWIN) + override CFLAGS += -DFD_SETSIZE=4096 -DCYGWIN else -MAKE = make + override CFLAGS += -fstack-protector -Wno-pointer-sign endif - -OPT = -pipe -g -fno-strict-aliasing -O2 -Wall - -ifeq ($(findstring CYGWIN,$(PLATFORM)), CYGWIN) -OS_TYPE = -DCYGWIN -CFLAGS = $(OPT) -DFD_SETSIZE=4096 -I../common $(PACKETDEF) $(OS_TYPE) -else -OS_TYPE = -CFLAGS = $(OPT) -fstack-protector -Wno-pointer-sign -I../common $(PACKETDEF) $(OS_TYPE) -endif - -MKDEF = CC="$(CC)" CFLAGS="$(CFLAGS)" diff --git a/src/char/Makefile b/src/char/Makefile index 5eb4b51..6f2e4af 100644 --- a/src/char/Makefile +++ b/src/char/Makefile @@ -1,12 +1,11 @@ include ../../make.defs -all: char-server -txt: char-server +all: txt +txt: char COMMON_OBJ = ../common/core.o ../common/socket.o ../common/timer.o ../common/db.o ../common/lock.o ../common/malloc.o ../common/mt_rand.o COMMON_H = ../common/core.h ../common/socket.h ../common/timer.h ../common/mmo.h ../common/db.h ../common/lock.h ../common/timer.h ../common/malloc.h ../common/mt_rand.h -char-server: char.o inter.o int_party.o int_guild.o int_storage.o $(COMMON_OBJ) - $(CC) $(CFLAGS) -o ../../$@ $^ +char: char.o inter.o int_party.o int_guild.o int_storage.o $(COMMON_OBJ) char.o: char.c char.h inter.h $(COMMON_H) ../common/version.h inter.o: inter.c inter.h int_party.h int_guild.h int_storage.h char.h $(COMMON_H) @@ -15,4 +14,4 @@ int_guild.o: int_guild.c int_guild.h int_storage.h inter.h char.h $(COMMON_H) int_storage.o: int_storage.c int_storage.h int_guild.h inter.h char.h $(COMMON_H) clean: - rm -f *.o ../../char-server + rm -f *.o char diff --git a/src/char/char.c b/src/char/char.c index 07b1fb6..f4a91bd 100644 --- a/src/char/char.c +++ b/src/char/char.c @@ -18,12 +18,12 @@ #include #include -#include "core.h" -#include "socket.h" -#include "timer.h" -#include "mmo.h" -#include "version.h" -#include "lock.h" +#include "../common/core.h" +#include "../common/socket.h" +#include "../common/timer.h" +#include "../common/mmo.h" +#include "../common/version.h" +#include "../common/lock.h" #include "char.h" #include "inter.h" diff --git a/src/char/int_guild.c b/src/char/int_guild.c index 5b4fe30..e145b66 100644 --- a/src/char/int_guild.c +++ b/src/char/int_guild.c @@ -2,11 +2,11 @@ #include "inter.h" #include "int_guild.h" #include "int_storage.h" -#include "mmo.h" +#include "../common/mmo.h" #include "char.h" -#include "socket.h" -#include "db.h" -#include "lock.h" +#include "../common/socket.h" +#include "../common/db.h" +#include "../common/lock.h" #include #include diff --git a/src/char/int_party.c b/src/char/int_party.c index c501c74..c5ed033 100644 --- a/src/char/int_party.c +++ b/src/char/int_party.c @@ -1,11 +1,11 @@ // $Id: int_party.c,v 1.1.1.1 2004/09/10 17:26:51 MagicalTux Exp $ #include "inter.h" #include "int_party.h" -#include "mmo.h" +#include "../common/mmo.h" #include "char.h" -#include "socket.h" -#include "db.h" -#include "lock.h" +#include "../common/socket.h" +#include "../common/db.h" +#include "../common/lock.h" #include #include #include diff --git a/src/char/inter.c b/src/char/inter.c index 89a3e39..5bee90f 100644 --- a/src/char/inter.c +++ b/src/char/inter.c @@ -1,9 +1,9 @@ // $Id: inter.c,v 1.1.1.1 2004/09/10 17:26:51 MagicalTux Exp $ -#include "mmo.h" +#include "../common/mmo.h" #include "char.h" -#include "socket.h" -#include "timer.h" -#include "db.h" +#include "../common/socket.h" +#include "../common/timer.h" +#include "../common/db.h" #include #include @@ -11,7 +11,7 @@ #include "int_party.h" #include "int_guild.h" #include "int_storage.h" -#include "lock.h" +#include "../common/lock.h" #define WISDATA_TTL (60*1000) // Existence time of Wisp/page data (60 seconds) // that is the waiting time of answers of all map-servers diff --git a/src/common/Makefile b/src/common/Makefile index 27930bd..48e75d8 100644 --- a/src/common/Makefile +++ b/src/common/Makefile @@ -1,5 +1,5 @@ include ../../make.defs -txt sql all: core.o socket.o timer.o grfio.o db.o lock.o nullpo.o malloc.o mt_rand.o md5calc.o +all txt sql: core.o socket.o timer.o grfio.o db.o lock.o nullpo.o malloc.o mt_rand.o md5calc.o core.o: core.c core.h socket.o: socket.c socket.h mmo.h diff --git a/src/ladmin/Makefile b/src/ladmin/Makefile index 3221901..9199951 100644 --- a/src/ladmin/Makefile +++ b/src/ladmin/Makefile @@ -8,9 +8,8 @@ COMMON_OBJ = ../common/core.o ../common/socket.o ../common/timer.o ../common/db. COMMON_H = ../common/core.h ../common/socket.h ../common/timer.h ../common/mmo.h ../common/version.h ../common/db.h ../common/malloc.h ../common/mt_rand.h ladmin: ladmin.o md5calc.o $(COMMON_OBJ) - $(CC) -o ../../$@ ladmin.o md5calc.o $(COMMON_OBJ) ladmin.o: ladmin.c ladmin.h md5calc.h $(COMMON_H) md5calc.o: md5calc.c md5calc.h clean: - rm -f *.o ../../ladmin + rm -f *.o ladmin diff --git a/src/ladmin/ladmin.c b/src/ladmin/ladmin.c index 5ef9b6c..d7f4f5f 100644 --- a/src/ladmin/ladmin.c +++ b/src/ladmin/ladmin.c @@ -22,11 +22,11 @@ #include // valist #include // tolower -#include "core.h" -#include "socket.h" +#include "../common/core.h" +#include "../common/socket.h" #include "ladmin.h" -#include "version.h" -#include "mmo.h" +#include "../common/version.h" +#include "../common/mmo.h" #ifdef PASSWORDENC #include "md5calc.h" diff --git a/src/ladmin/md5calc.c b/src/ladmin/md5calc.c index cf9d958..ec1d8ec 100644 --- a/src/ladmin/md5calc.c +++ b/src/ladmin/md5calc.c @@ -10,7 +10,7 @@ #include "md5calc.h" #include #include -#include "mt_rand.h" +#include "../common/mt_rand.h" #ifndef UINT_MAX #define UINT_MAX 4294967295U diff --git a/src/login/Makefile b/src/login/Makefile index 32e14d7..185cffb 100644 --- a/src/login/Makefile +++ b/src/login/Makefile @@ -1,14 +1,13 @@ include ../../make.defs -all: login-server -txt: login-server +all: txt +txt: login COMMON_OBJ = ../common/core.o ../common/socket.o ../common/timer.o ../common/db.o ../common/lock.o ../common/malloc.o ../common/mt_rand.o ../common/md5calc.o COMMON_H = ../common/core.h ../common/socket.h ../common/timer.h ../common/mmo.h ../common/version.h ../common/db.h ../common/lock.h ../common/malloc.h ../common/mt_rand.h ../common/md5calc.h -login-server: login.o $(COMMON_OBJ) - $(CC) $(CFLAGS) -o ../../$@ login.o $(COMMON_OBJ) +login: $(COMMON_OBJ) login.o: login.c login.h $(COMMON_H) clean: - rm -f *.o ../../login-server + rm -f *.o login diff --git a/src/login/login.c b/src/login/login.c index 1db85ad..480533e 100644 --- a/src/login/login.c +++ b/src/login/login.c @@ -18,17 +18,17 @@ #include #include -#include "core.h" -#include "socket.h" -#include "timer.h" +#include "../common/core.h" +#include "../common/socket.h" +#include "../common/timer.h" #include "login.h" -#include "mmo.h" -#include "version.h" -#include "db.h" -#include "lock.h" -#include "mt_rand.h" +#include "../common/mmo.h" +#include "../common/version.h" +#include "../common/db.h" +#include "../common/lock.h" +#include "../common/mt_rand.h" -#include "md5calc.h" +#include "../common/md5calc.h" #ifdef MEMWATCH #include "memwatch.h" diff --git a/src/map/Makefile b/src/map/Makefile index a1a4381..c7c982e 100644 --- a/src/map/Makefile +++ b/src/map/Makefile @@ -2,27 +2,25 @@ include ../../make.defs all: txt -txt: obj map-server +txt: map obj: mkdir obj COMMON_OBJ = ../common/core.o ../common/socket.o ../common/timer.o ../common/grfio.o ../common/db.o ../common/lock.o ../common/nullpo.o ../common/malloc.o ../common/mt_rand.o ../common/md5calc.o -LIBS = -lz -lm +LDLIBS = -lz -lm -map-server: obj/tmw.o obj/magic-interpreter-lexer.o obj/magic-interpreter-parser.o obj/magic-interpreter-base.o obj/magic-expr.o obj/magic-stmt.o obj/magic.o obj/map.o obj/chrif.o obj/clif.o obj/pc.o obj/npc.o obj/chat.o obj/path.o obj/itemdb.o obj/mob.o obj/script.o obj/storage.o obj/skill.o obj/skill-pools.o obj/atcommand.o obj/battle.o obj/intif.o obj/trade.o obj/party.o obj/guild.o $(COMMON_OBJ) - $(CC) -o ../../$@ $^ $(LIBS) +map: obj/tmw.o obj/magic-interpreter-lexer.o obj/magic-interpreter-parser.o obj/magic-interpreter-base.o obj/magic-expr.o obj/magic-stmt.o obj/magic.o obj/map.o obj/chrif.o obj/clif.o obj/pc.o obj/npc.o obj/chat.o obj/path.o obj/itemdb.o obj/mob.o obj/script.o obj/storage.o obj/skill.o obj/skill-pools.o obj/atcommand.o obj/battle.o obj/intif.o obj/trade.o obj/party.o obj/guild.o $(COMMON_OBJ) + ${LINK.c} $^ ${LDLIBS} -o $@ +obj/%.o: %.c | obj + ${COMPILE.c} $< -o $@ -obj/%.o: %.c - $(COMPILE.c) $(OUTPUT_OPTION) $< +magic-interpreter-lexer.c: magic-interpreter-lexer.l +magic-interpreter-parser.c magic-interpreter-parser.h: magic-interpreter-parser.y +#The builtin yacc rule is insufficient, (but yacc can be used in place of bison) + ${YACC} $^ -d -o magic-interpreter-parser.c -magic-interpreter-lexer.c: magic-interpreter.l - $(LEX) -o magic-interpreter-lexer.c magic-interpreter.l - -magic-interpreter-parser.c: magic-interpreter-parser.y - $(BISON) -v -d -o magic-interpreter-parser.c magic-interpreter-parser.y - -obj/magic-interpreter-lexer.o: magic-interpreter-lexer.c magic-interpreter-parser.c magic-expr.h magic-interpreter.h chrif.h clif.h npc.h pc.h mob.h chat.h skill.h itemdb.h storage.h party.h atcommand.h ../common/core.h ../common/timer.h ../common/db.h ../common/grfio.h ../common/mmo.h +obj/magic-interpreter-lexer.o: magic-interpreter-lexer.c magic-interpreter-parser.h magic-expr.h magic-interpreter.h chrif.h clif.h npc.h pc.h mob.h chat.h skill.h itemdb.h storage.h party.h atcommand.h ../common/core.h ../common/timer.h ../common/db.h ../common/grfio.h ../common/mmo.h obj/magic-interpreter-parser.o: magic-interpreter-parser.c magic-expr.h magic-interpreter.h chrif.h clif.h npc.h pc.h mob.h chat.h skill.h itemdb.h storage.h party.h atcommand.h ../common/core.h ../common/timer.h ../common/db.h ../common/grfio.h ../common/mmo.h obj/magic-interpreter-base.o: magic-interpreter-base.c magic-expr-eval.h magic-interpreter-aux.h magic-expr.h magic-interpreter.h chrif.h clif.h npc.h pc.h mob.h chat.h skill.h itemdb.h storage.h party.h atcommand.h ../common/core.h ../common/timer.h ../common/db.h ../common/grfio.h ../common/mmo.h obj/magic-expr.o: magic-expr.c magic-expr-eval.h magic-interpreter-aux.h magic-expr.h magic-interpreter.h chrif.h clif.h npc.h pc.h mob.h chat.h skill.h itemdb.h storage.h party.h atcommand.h ../common/core.h ../common/timer.h ../common/db.h ../common/grfio.h ../common/mmo.h @@ -47,6 +45,9 @@ obj/intif.o: intif.c intif.h chrif.h clif.h party.h guild.h storage.h map.h batt obj/trade.o: trade.c trade.h clif.h itemdb.h map.h pc.h npc.h ../common/mmo.h obj/party.o: party.c party.h clif.h intif.h pc.h map.h battle.h ../common/db.h ../common/socket.h ../common/timer.h ../common/mmo.h obj/tmw.o: tmw.c tmw.h map.h clif.h +obj/guild.o: guild.c guild.h storage.h ../common/mmo.h ../common/utils.h \ + ../common/mt_rand.h ../common/timer.h ../common/socket.h \ + ../common/nullpo.h battle.h npc.h pc.h map.h mob.h intif.h clif.h tmw.h clean: - rm -rf *.o ../../map-server obj + rm -rf *.o map obj magic-interpreter-parser.c magic-interpreter-parser.h magic-interpreter-lexer.c diff --git a/src/map/atcommand.c b/src/map/atcommand.c index 681cccf..cb9e93c 100644 --- a/src/map/atcommand.c +++ b/src/map/atcommand.c @@ -10,9 +10,9 @@ #include #include -#include "socket.h" -#include "timer.h" -#include "nullpo.h" +#include "../common/socket.h" +#include "../common/timer.h" +#include "../common/nullpo.h" #include "atcommand.h" #include "battle.h" @@ -30,7 +30,7 @@ #include "skill.h" #include "trade.h" -#include "core.h" +#include "../common/core.h" #include "tmw.h" #define STATE_BLIND 0x10 diff --git a/src/map/battle.c b/src/map/battle.c index f81aaf0..c9e341d 100644 --- a/src/map/battle.c +++ b/src/map/battle.c @@ -6,9 +6,9 @@ #include "battle.h" -#include "timer.h" -#include "nullpo.h" -#include "malloc.h" +#include "../common/timer.h" +#include "../common/nullpo.h" +#include "../common/malloc.h" #include "clif.h" #include "guild.h" @@ -18,7 +18,7 @@ #include "pc.h" #include "skill.h" #include "../common/socket.h" -#include "mt_rand.h" +#include "../common/mt_rand.h" #ifdef MEMWATCH #include "memwatch.h" diff --git a/src/map/chat.c b/src/map/chat.c index 772ac4c..0163eed 100644 --- a/src/map/chat.c +++ b/src/map/chat.c @@ -3,9 +3,9 @@ #include #include -#include "db.h" -#include "nullpo.h" -#include "malloc.h" +#include "../common/db.h" +#include "../common/nullpo.h" +#include "../common/malloc.h" #include "map.h" #include "clif.h" #include "pc.h" diff --git a/src/map/chrif.c b/src/map/chrif.c index 4bcfa45..8bbeb59 100644 --- a/src/map/chrif.c +++ b/src/map/chrif.c @@ -13,8 +13,8 @@ #include #include -#include "socket.h" -#include "timer.h" +#include "../common/socket.h" +#include "../common/timer.h" #include "map.h" #include "battle.h" #include "chrif.h" @@ -22,7 +22,7 @@ #include "intif.h" #include "npc.h" #include "pc.h" -#include "nullpo.h" +#include "../common/nullpo.h" #include "itemdb.h" #ifdef MEMWATCH diff --git a/src/map/clif.c b/src/map/clif.c index ce79490..d630815 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -18,12 +18,12 @@ #endif #include -#include "socket.h" -#include "timer.h" -#include "malloc.h" -#include "version.h" -#include "nullpo.h" -#include "md5calc.h" +#include "../common/socket.h" +#include "../common/timer.h" +#include "../common/malloc.h" +#include "../common/version.h" +#include "../common/nullpo.h" +#include "../common/md5calc.h" #include "atcommand.h" #include "battle.h" diff --git a/src/map/guild.c b/src/map/guild.c index 1d328ea..4a7552a 100644 --- a/src/map/guild.c +++ b/src/map/guild.c @@ -5,11 +5,11 @@ #include "guild.h" #include "storage.h" -#include "db.h" -#include "timer.h" -#include "socket.h" -#include "nullpo.h" -#include "malloc.h" +#include "../common/db.h" +#include "../common/timer.h" +#include "../common/socket.h" +#include "../common/nullpo.h" +#include "../common/malloc.h" #include "battle.h" #include "npc.h" #include "pc.h" diff --git a/src/map/intif.c b/src/map/intif.c index efde695..629eade 100644 --- a/src/map/intif.c +++ b/src/map/intif.c @@ -18,9 +18,9 @@ #include #include -#include "nullpo.h" -#include "socket.h" -#include "timer.h" +#include "../common/nullpo.h" +#include "../common/socket.h" +#include "../common/timer.h" #include "battle.h" #include "chrif.h" diff --git a/src/map/itemdb.c b/src/map/itemdb.c index d589e35..dfa3d36 100644 --- a/src/map/itemdb.c +++ b/src/map/itemdb.c @@ -3,10 +3,10 @@ #include #include -#include "db.h" -#include "grfio.h" -#include "nullpo.h" -#include "malloc.h" +#include "../common/db.h" +#include "../common/grfio.h" +#include "../common/nullpo.h" +#include "../common/malloc.h" #include "map.h" #include "battle.h" #include "itemdb.h" diff --git a/src/map/magic-interpreter-lexer.l b/src/map/magic-interpreter-lexer.l new file mode 100644 index 0000000..2c9792f --- /dev/null +++ b/src/map/magic-interpreter-lexer.l @@ -0,0 +1,140 @@ +%{ +#include "magic-interpreter.h" +#include "magic-interpreter-parser.h" + +#ifdef HEADING +# undef HEADING +#endif + +#define FIXLOC magic_frontend_lloc.first_line = magic_frontend_lineno + +#define HEADING(dir) { magic_frontend_lval.i = dir; FIXLOC; return DIR; } + +%} + +%option yylineno +%option noyywrap +%option prefix="magic_frontend_" +%option nounput +%option noinput +%option bison-bridge bison-locations + +%% + +"S" HEADING(0); +"SW" HEADING(1); +"W" HEADING(2); +"NW" HEADING(3); +"N" HEADING(4); +"NE" HEADING(5); +"E" HEADING(6); +"SE" HEADING(7); +"=" {FIXLOC; return '=';} +"==" {FIXLOC; return EQ;} +"<>" {FIXLOC; return NEQ;} +"!=" {FIXLOC; return NEQ;} +">" {FIXLOC; return '>';} +"<" {FIXLOC; return '<';} +">=" {FIXLOC; return GTE;} +"<=" {FIXLOC; return LTE;} +"(" {FIXLOC; return '(';} +")" {FIXLOC; return ')';} +"+" {FIXLOC; return '+';} +"-" {FIXLOC; return '-';} +"*" {FIXLOC; return '*';} +"/" {FIXLOC; return '/';} +"%" {FIXLOC; return '%';} +"&&" {FIXLOC; return ANDAND;} +"||" {FIXLOC; return OROR;} +";" {FIXLOC; return ';';} +":" {FIXLOC; return ':';} +"," {FIXLOC; return ',';} +"@" {FIXLOC; return '@';} +"|" {FIXLOC; return '|';} +"[" {FIXLOC; return '[';} +"]" {FIXLOC; return ']';} +"&" {FIXLOC; return '&';} +"^" {FIXLOC; return '^';} +"." {FIXLOC; return '.';} +"<<" {FIXLOC; return SHL;} +">>" {FIXLOC; return SHR;} +"PROCEDURE" {FIXLOC; return PROCEDURE;} +"CALL" {FIXLOC; return CALL;} +"OR" {FIXLOC; return OR;} +"TO" {FIXLOC; return TO;} +"TOWARDS" {FIXLOC; return TOWARDS;} +"TELEPORT-ANCHOR" {FIXLOC; return TELEPORT_ANCHOR;} +"SILENT" {FIXLOC; return SILENT;} +"LOCAL" {FIXLOC; return LOCAL;} +"NONMAGIC" {FIXLOC; return NONMAGIC;} +"SPELL" {FIXLOC; return SPELL;} +"LET" {FIXLOC; return LET;} +"IN" {FIXLOC; return IN;} +"END" {FIXLOC; return END;} +"=>" {FIXLOC; return DARROW;} +"STRING" {FIXLOC; return STRING_TY;} +"REQUIRE" {FIXLOC; return REQUIRE;} +"CATALYSTS" {FIXLOC; return CATALYSTS;} +"COMPONENTS" {FIXLOC; return COMPONENTS;} +"MANA" {FIXLOC; return MANA;} +"CASTTIME" {FIXLOC; return CASTTIME;} +"SKIP" {FIXLOC; return SKIP;} +"ABORT" {FIXLOC; return ABORT;} +"BREAK" {FIXLOC; return BREAK;} +"EFFECT" {FIXLOC; return EFFECT;} +"ATEND" {FIXLOC; return ATEND;} +"ATTRIGGER" {FIXLOC; return ATTRIGGER;} +"CONST" {FIXLOC; return CONST;} +"PC" {FIXLOC; return PC_F;} +"NPC" {FIXLOC; return NPC_F;} +"MOB" {FIXLOC; return MOB_F;} +"ENTITY" {FIXLOC; return ENTITY_F;} +"TARGET" {FIXLOC; return TARGET_F;} +"IF" {FIXLOC; return IF;} +"THEN" {FIXLOC; return THEN;} +"ELSE" {FIXLOC; return ELSE;} +"FOREACH" {FIXLOC; return FOREACH;} +"FOR" {FIXLOC; return FOR;} +"DO" {FIXLOC; return DO;} +"WAIT" {FIXLOC; return SLEEP;} + +\{([^\}]|\\.)*\} { char *string = strdup(yytext); + magic_frontend_lval.s = string; + FIXLOC; + return SCRIPT_DATA; + } + +\"([^\"]|\\.)*\" { char *string = strdup(yytext + 1); + char *src = string; + char *dst = string; + while (*src && *src != '"') + if (*src == '\\') { + *dst++ = src[1]; + src += 2; + } else + *dst++ = *src++; + *dst = '\0'; /* terminate */ + magic_frontend_lval.s = string; + FIXLOC; + return STRING; + } + +"-"?[0-9]+ { magic_frontend_lval.i = atoi(yytext); + FIXLOC; + return INT; } + +"0x"[0-9a-fA-F]+ { magic_frontend_lval.i = strtol(yytext + 2, NULL, 16); + FIXLOC; + return INT; } + +[a-zA-Z][-_a-zA-Z0-9?!]* { magic_frontend_lval.s = strdup(yytext); + FIXLOC; + return ID; } + +"#".*$ /* Ignore comments */ +"//".*$ /* Ignore comments */ +[ \n\t\r] /* ignore whitespace */ +. fprintf(stderr, "%s: Unexpected character in line %d\n", MAGIC_CONFIG_FILE, magic_frontend_lineno); + + +%% diff --git a/src/map/magic-interpreter-parser.y b/src/map/magic-interpreter-parser.y index 04d5630..8484902 100644 --- a/src/map/magic-interpreter-parser.y +++ b/src/map/magic-interpreter-parser.y @@ -409,7 +409,7 @@ expr : value arg_list : /* empty */ { $$.args_nr = 0; } | arg_list_ne - { $$ = $1 } + { $$ = $1; } ; diff --git a/src/map/magic-interpreter.h b/src/map/magic-interpreter.h index 7db7d3e..006c8fb 100644 --- a/src/map/magic-interpreter.h +++ b/src/map/magic-interpreter.h @@ -8,8 +8,8 @@ #include #include -#include "malloc.h" -#include "nullpo.h" +#include "../common/malloc.h" +#include "../common/nullpo.h" #include "battle.h" #include "chat.h" diff --git a/src/map/magic-interpreter.l b/src/map/magic-interpreter.l deleted file mode 100644 index 2c9792f..0000000 --- a/src/map/magic-interpreter.l +++ /dev/null @@ -1,140 +0,0 @@ -%{ -#include "magic-interpreter.h" -#include "magic-interpreter-parser.h" - -#ifdef HEADING -# undef HEADING -#endif - -#define FIXLOC magic_frontend_lloc.first_line = magic_frontend_lineno - -#define HEADING(dir) { magic_frontend_lval.i = dir; FIXLOC; return DIR; } - -%} - -%option yylineno -%option noyywrap -%option prefix="magic_frontend_" -%option nounput -%option noinput -%option bison-bridge bison-locations - -%% - -"S" HEADING(0); -"SW" HEADING(1); -"W" HEADING(2); -"NW" HEADING(3); -"N" HEADING(4); -"NE" HEADING(5); -"E" HEADING(6); -"SE" HEADING(7); -"=" {FIXLOC; return '=';} -"==" {FIXLOC; return EQ;} -"<>" {FIXLOC; return NEQ;} -"!=" {FIXLOC; return NEQ;} -">" {FIXLOC; return '>';} -"<" {FIXLOC; return '<';} -">=" {FIXLOC; return GTE;} -"<=" {FIXLOC; return LTE;} -"(" {FIXLOC; return '(';} -")" {FIXLOC; return ')';} -"+" {FIXLOC; return '+';} -"-" {FIXLOC; return '-';} -"*" {FIXLOC; return '*';} -"/" {FIXLOC; return '/';} -"%" {FIXLOC; return '%';} -"&&" {FIXLOC; return ANDAND;} -"||" {FIXLOC; return OROR;} -";" {FIXLOC; return ';';} -":" {FIXLOC; return ':';} -"," {FIXLOC; return ',';} -"@" {FIXLOC; return '@';} -"|" {FIXLOC; return '|';} -"[" {FIXLOC; return '[';} -"]" {FIXLOC; return ']';} -"&" {FIXLOC; return '&';} -"^" {FIXLOC; return '^';} -"." {FIXLOC; return '.';} -"<<" {FIXLOC; return SHL;} -">>" {FIXLOC; return SHR;} -"PROCEDURE" {FIXLOC; return PROCEDURE;} -"CALL" {FIXLOC; return CALL;} -"OR" {FIXLOC; return OR;} -"TO" {FIXLOC; return TO;} -"TOWARDS" {FIXLOC; return TOWARDS;} -"TELEPORT-ANCHOR" {FIXLOC; return TELEPORT_ANCHOR;} -"SILENT" {FIXLOC; return SILENT;} -"LOCAL" {FIXLOC; return LOCAL;} -"NONMAGIC" {FIXLOC; return NONMAGIC;} -"SPELL" {FIXLOC; return SPELL;} -"LET" {FIXLOC; return LET;} -"IN" {FIXLOC; return IN;} -"END" {FIXLOC; return END;} -"=>" {FIXLOC; return DARROW;} -"STRING" {FIXLOC; return STRING_TY;} -"REQUIRE" {FIXLOC; return REQUIRE;} -"CATALYSTS" {FIXLOC; return CATALYSTS;} -"COMPONENTS" {FIXLOC; return COMPONENTS;} -"MANA" {FIXLOC; return MANA;} -"CASTTIME" {FIXLOC; return CASTTIME;} -"SKIP" {FIXLOC; return SKIP;} -"ABORT" {FIXLOC; return ABORT;} -"BREAK" {FIXLOC; return BREAK;} -"EFFECT" {FIXLOC; return EFFECT;} -"ATEND" {FIXLOC; return ATEND;} -"ATTRIGGER" {FIXLOC; return ATTRIGGER;} -"CONST" {FIXLOC; return CONST;} -"PC" {FIXLOC; return PC_F;} -"NPC" {FIXLOC; return NPC_F;} -"MOB" {FIXLOC; return MOB_F;} -"ENTITY" {FIXLOC; return ENTITY_F;} -"TARGET" {FIXLOC; return TARGET_F;} -"IF" {FIXLOC; return IF;} -"THEN" {FIXLOC; return THEN;} -"ELSE" {FIXLOC; return ELSE;} -"FOREACH" {FIXLOC; return FOREACH;} -"FOR" {FIXLOC; return FOR;} -"DO" {FIXLOC; return DO;} -"WAIT" {FIXLOC; return SLEEP;} - -\{([^\}]|\\.)*\} { char *string = strdup(yytext); - magic_frontend_lval.s = string; - FIXLOC; - return SCRIPT_DATA; - } - -\"([^\"]|\\.)*\" { char *string = strdup(yytext + 1); - char *src = string; - char *dst = string; - while (*src && *src != '"') - if (*src == '\\') { - *dst++ = src[1]; - src += 2; - } else - *dst++ = *src++; - *dst = '\0'; /* terminate */ - magic_frontend_lval.s = string; - FIXLOC; - return STRING; - } - -"-"?[0-9]+ { magic_frontend_lval.i = atoi(yytext); - FIXLOC; - return INT; } - -"0x"[0-9a-fA-F]+ { magic_frontend_lval.i = strtol(yytext + 2, NULL, 16); - FIXLOC; - return INT; } - -[a-zA-Z][-_a-zA-Z0-9?!]* { magic_frontend_lval.s = strdup(yytext); - FIXLOC; - return ID; } - -"#".*$ /* Ignore comments */ -"//".*$ /* Ignore comments */ -[ \n\t\r] /* ignore whitespace */ -. fprintf(stderr, "%s: Unexpected character in line %d\n", MAGIC_CONFIG_FILE, magic_frontend_lineno); - - -%% diff --git a/src/map/map.c b/src/map/map.c index 57183d1..e1adcef 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -9,11 +9,11 @@ #include #endif -#include "core.h" -#include "timer.h" -#include "db.h" -#include "grfio.h" -#include "malloc.h" +#include "../common/core.h" +#include "../common/timer.h" +#include "../common/db.h" +#include "../common/grfio.h" +#include "../common/malloc.h" #include "map.h" #include "chrif.h" @@ -32,8 +32,8 @@ #include "script.h" #include "guild.h" #include "atcommand.h" -#include "nullpo.h" -#include "socket.h" +#include "../common/nullpo.h" +#include "../common/socket.h" #include "magic.h" #ifdef MEMWATCH diff --git a/src/map/map.h b/src/map/map.h index 53f6dfc..a558397 100644 --- a/src/map/map.h +++ b/src/map/map.h @@ -7,7 +7,7 @@ #include #include #include -#include "mmo.h" +#include "../common/mmo.h" #ifndef MAX # define MAX(x,y) (((x)>(y)) ? (x) : (y)) diff --git a/src/map/mob.c b/src/map/mob.c index 7962114..99d1cc2 100644 --- a/src/map/mob.c +++ b/src/map/mob.c @@ -5,11 +5,11 @@ #include #include -#include "timer.h" -#include "socket.h" -#include "db.h" -#include "nullpo.h" -#include "malloc.h" +#include "../common/timer.h" +#include "../common/socket.h" +#include "../common/db.h" +#include "../common/nullpo.h" +#include "../common/malloc.h" #include "map.h" #include "clif.h" #include "intif.h" diff --git a/src/map/npc.c b/src/map/npc.c index 0335e9c..5fd8291 100644 --- a/src/map/npc.c +++ b/src/map/npc.c @@ -6,13 +6,13 @@ #include #include -#include "malloc.h" -#include "nullpo.h" -#include "timer.h" +#include "../common/malloc.h" +#include "../common/nullpo.h" +#include "../common/timer.h" #include "battle.h" #include "clif.h" -#include "db.h" +#include "../common/db.h" #include "intif.h" #include "itemdb.h" #include "map.h" diff --git a/src/map/party.c b/src/map/party.c index f87d390..4e59fae 100644 --- a/src/map/party.c +++ b/src/map/party.c @@ -4,11 +4,11 @@ #include #include "party.h" -#include "db.h" -#include "timer.h" -#include "socket.h" -#include "nullpo.h" -#include "malloc.h" +#include "../common/db.h" +#include "../common/timer.h" +#include "../common/socket.h" +#include "../common/nullpo.h" +#include "../common/malloc.h" #include "pc.h" #include "map.h" #include "battle.h" diff --git a/src/map/path.c b/src/map/path.c index 93ce960..7a864ed 100644 --- a/src/map/path.c +++ b/src/map/path.c @@ -5,7 +5,7 @@ #include "map.h" #include "battle.h" -#include "nullpo.h" +#include "../common/nullpo.h" #ifdef MEMWATCH #include "memwatch.h" diff --git a/src/map/pc.c b/src/map/pc.c index fb98bcb..fc2732f 100644 --- a/src/map/pc.c +++ b/src/map/pc.c @@ -5,12 +5,12 @@ #include #include -#include "socket.h" // [Valaris] -#include "timer.h" -#include "db.h" +#include "../common/socket.h" // [Valaris] +#include "../common/timer.h" +#include "../common/db.h" -#include "malloc.h" -#include "nullpo.h" +#include "../common/malloc.h" +#include "../common/nullpo.h" #include "atcommand.h" #include "battle.h" diff --git a/src/map/script.c b/src/map/script.c index 27567c3..0c01ac0 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -15,21 +15,21 @@ #include #include -#include "socket.h" -#include "timer.h" -#include "malloc.h" -#include "lock.h" +#include "../common/socket.h" +#include "../common/timer.h" +#include "../common/malloc.h" +#include "../common/lock.h" #include "atcommand.h" #include "battle.h" #include "chat.h" #include "chrif.h" #include "clif.h" -#include "db.h" +#include "../common/db.h" #include "guild.h" #include "intif.h" #include "itemdb.h" -#include "lock.h" +#include "../common/lock.h" #include "map.h" #include "mob.h" #include "npc.h" diff --git a/src/map/skill-pools.c b/src/map/skill-pools.c index d533ae3..50dafcb 100644 --- a/src/map/skill-pools.c +++ b/src/map/skill-pools.c @@ -3,9 +3,9 @@ #include #include -#include "timer.h" -#include "nullpo.h" -#include "malloc.h" +#include "../common/timer.h" +#include "../common/nullpo.h" +#include "../common/malloc.h" #include "magic.h" #include "battle.h" diff --git a/src/map/skill.c b/src/map/skill.c index 8a2b6b5..54ff545 100644 --- a/src/map/skill.c +++ b/src/map/skill.c @@ -6,9 +6,9 @@ #include #include -#include "timer.h" -#include "nullpo.h" -#include "malloc.h" +#include "../common/timer.h" +#include "../common/nullpo.h" +#include "../common/malloc.h" #include "magic.h" #include "battle.h" diff --git a/src/map/tmw.c b/src/map/tmw.c index a71c93c..c04c9c8 100644 --- a/src/map/tmw.c +++ b/src/map/tmw.c @@ -6,11 +6,11 @@ #include "tmw.h" -#include "socket.h" -#include "timer.h" -#include "malloc.h" -#include "version.h" -#include "nullpo.h" +#include "../common/socket.h" +#include "../common/timer.h" +#include "../common/malloc.h" +#include "../common/version.h" +#include "../common/nullpo.h" #include "atcommand.h" #include "battle.h" diff --git a/src/map/trade.c b/src/map/trade.c index 664d2fa..ae70f0d 100644 --- a/src/map/trade.c +++ b/src/map/trade.c @@ -9,7 +9,7 @@ #include "npc.h" #include "battle.h" #include "storage.h" -#include "nullpo.h" +#include "../common/nullpo.h" /*========================================== * 取引要請を相手に送る diff --git a/src/tool/Makefile b/src/tool/Makefile index 5d37183..87393fb 100644 --- a/src/tool/Makefile +++ b/src/tool/Makefile @@ -1,16 +1,17 @@ include ../../make.defs -BDIR=.. -COBJS=${BDIR}/common/timer.o ${BDIR}/common/malloc.o ${BDIR}/common/socket.o ${BDIR}/common/lock.o ${BDIR}/common/db.o ${BDIR}/char/int_storage.o ${BDIR}/char/inter.o ${BDIR}/char/int_party.o ${BDIR}/char/int_guild.o -MOBJS=${BDIR}/common/socket.o ${BDIR}/common/timer.o ${BDIR}/common/db.o ${BDIR}/common/lock.o ${BDIR}/common/malloc.o ${BDIR}/char/int_guild.o ${BDIR}/char/int_party.o ${BDIR}/char/int_storage.o ${BDIR}/char/inter.o +COBJS=../common/timer.o ../common/malloc.o ../common/socket.o ../common/lock.o ../common/db.o ../char/int_storage.o ../char/inter.o ../char/int_party.o ../char/int_guild.o +MOBJS=../common/socket.o ../common/timer.o ../common/db.o ../common/lock.o ../common/malloc.o ../char/int_guild.o ../char/int_party.o ../char/int_storage.o ../char/inter.o +all: adduser itemfrob mapfrob marriage-info eathena-monitor +adduser: adduser.o ../common/socket.o -all: ${COBJS} ${MOBJS} - $(CC) $(CFLAGS) -o adduser adduser.c $(BDIR)/common/socket.o - $(CC) $(CFLAGS) -I ${BDIR}/char -I ${BDIR}/common itemfrob.c -o itemfrob ${COBJS} - $(CC) $(CFLAGS) -I ${BDIR}/char -I ${BDIR}/common mapfrob.c -o mapfrob ${COBJS} - $(CC) $(CFLAGS) -I ${BDIR}/char -I ${BDIR}/common -I ${BDIR}/map -I ${BDIR}/login marriage-info.c -o marriage-info ${MOBJS} - $(CC) $(CFLAGS) -o ${BDIR}/../eathena-monitor eathena-monitor.c +itemfrob: itemfrob.o ${COBJS} +mapfrob: mapfrob.o ${COBJS} +marriage-info: marriage-info.o ${MOBJS} +eathena-monitor: eathena-monitor.c + $(CC) $(CFLAGS) -o eathena-monitor eathena-monitor.c clean: - rm -f adduser itemfrob mapfrob marriage-info ${BDIR}/../eathena-monitor + rm -f adduser itemfrob mapfrob marriage-info eathena-monitor rm -f *.exe + rm -f *.o diff --git a/src/tool/adduser.c b/src/tool/adduser.c index 6ebbdf1..1954b66 100644 --- a/src/tool/adduser.c +++ b/src/tool/adduser.c @@ -41,7 +41,7 @@ int main (int argc, char *argv[]) // Check to see if account.txt exists. printf ("Checking if '%s' file exists...\n", account_txt); - FILE *FPaccin = fopen_ (account_txt, "r"); + FILE *FPaccin = fopen (account_txt, "r"); if (FPaccin == NULL) { printf ("'%s' file not found!\n", account_txt); @@ -72,7 +72,7 @@ int main (int argc, char *argv[]) } } } - close (FPaccin); + fclose (FPaccin); printf ("File exists.\n"); printf ("Don't create an account if the login-server is online!!!\n"); @@ -105,11 +105,11 @@ int main (int argc, char *argv[]) scanf ("%s", &sex); } - FILE *FPaccout = fopen_ (account_txt, "r+"); + FILE *FPaccout = fopen (account_txt, "r+"); fseek (FPaccout, 0, SEEK_END); fprintf (FPaccout, "%i %s %s - %s -\r\n", next_id, username, password, sex); - close (FPaccout); + fclose (FPaccout); printf ("Account added.\n"); } diff --git a/src/tool/marriage-info.c b/src/tool/marriage-info.c index cd13843..9b91955 100644 --- a/src/tool/marriage-info.c +++ b/src/tool/marriage-info.c @@ -7,9 +7,9 @@ src/char/int_party.o src/char/int_storage.o src/char/inter.o #include #include -#include "login.h" -#include "mmo.h" -#include "char.c" +#include "../login/login.h" +#include "../common/mmo.h" +#include "../char/char.c" int mode; #define MODE_MARRIED 0 diff --git a/src/webserver/Makefile b/src/webserver/Makefile index 417fa7c..5bfa83f 100644 --- a/src/webserver/Makefile +++ b/src/webserver/Makefile @@ -1,20 +1,9 @@ include ../../make.defs -all: - #Generate framework... - $(CC) $(CFLAGS) -c parse.c - $(CC) $(CFLAGS) -c generate.c - $(CC) $(CFLAGS) -c htmlstyle.c - $(CC) $(CFLAGS) -c logs.c - - #Generate "pages"... - cd pages && $(CC) $(CFLAGS) -c about.c && cd .. - cd pages && $(CC) $(CFLAGS) -c sample.c && cd .. - cd pages && $(CC) $(CFLAGS) -c notdone.c && cd .. - - #Building the server... - $(CC) $(CFLAGS) -o webserver main.c parse.o generate.o htmlstyle.o \ - logs.o pages/about.o pages/sample.o pages/notdone.o +OBJ = main.o parse.o generate.o htmlstyle.o logs.o pages/about.o pages/sample.o pages/notdone.o +all: webserver +webserver: ${OBJ} + ${CC} ${CFLAGS} -o $@ ${OBJ} -- cgit v1.2.3-70-g09d2 From 9f36288ddb356608da0348814100873729c16a9d Mon Sep 17 00:00:00 2001 From: Ben Longbons Date: Wed, 16 Mar 2011 13:40:58 -0700 Subject: Fix makefile so tools depend on common, and copy eathena-monitor to root directory --- Makefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index bc90aa8..50226fd 100644 --- a/Makefile +++ b/Makefile @@ -29,7 +29,9 @@ clean-ladmin: ${MAKE} -C src/ladmin clean # This target is separate for historical reasons, and because it is optional -tools: common +tools: common eathena-monitor +eathena-monitor: ${MAKE} -C src/tool + ${CP} src/tool/eathena-monitor . clean-tools: ${MAKE} -C src/tool clean -- cgit v1.2.3-70-g09d2 From 81362204ace57c1af844bf784f5599cc91190f8b Mon Sep 17 00:00:00 2001 From: Ben Longbons Date: Wed, 16 Mar 2011 18:44:36 -0700 Subject: Fix top-level makefile to rebuild when sources change --- Makefile | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 50226fd..c34b691 100644 --- a/Makefile +++ b/Makefile @@ -1,18 +1,21 @@ include make.defs all: login-server char-server map-server ladmin -common: +tools: tool eathena-monitor + + +common: src/common ${MAKE} -C src/common -login-server: common +login-server: common src/login ${MAKE} -C src/login ${CP} src/login/login login-server -char-server: common +char-server: common src/char ${MAKE} -C src/char ${CP} src/char/char char-server -map-server: common +map-server: common src/map ${MAKE} -C src/map ${CP} src/map/map map-server -ladmin: common +ladmin: common src/ladmin ${MAKE} -C src/ladmin clean: clean-common clean-login clean-char clean-map clean-ladmin clean-tools @@ -29,9 +32,9 @@ clean-ladmin: ${MAKE} -C src/ladmin clean # This target is separate for historical reasons, and because it is optional -tools: common eathena-monitor -eathena-monitor: +tool: common src/tool ${MAKE} -C src/tool +eathena-monitor: tool ${CP} src/tool/eathena-monitor . clean-tools: ${MAKE} -C src/tool clean -- cgit v1.2.3-70-g09d2 From e271a81f87be3a193aa0b900a8218d4bda87469e Mon Sep 17 00:00:00 2001 From: Ben Longbons Date: Wed, 16 Mar 2011 18:48:00 -0700 Subject: Remove troublesome and redundant ladmin entry from .gitignore --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index d289860..2e84a3a 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,6 @@ src/char/char char-server src/ladmin/ladmin -ladmin src/login/login login-server src/map/map -- cgit v1.2.3-70-g09d2 From 5d8045704481038836ae37106b8ef5cdf0913a65 Mon Sep 17 00:00:00 2001 From: Ben Longbons Date: Thu, 17 Mar 2011 00:53:37 -0700 Subject: Rewrite monitor --- src/tool/eathena-monitor.c | 308 ++++++++++++++++++--------------------------- 1 file changed, 122 insertions(+), 186 deletions(-) diff --git a/src/tool/eathena-monitor.c b/src/tool/eathena-monitor.c index d0b3995..8713dff 100644 --- a/src/tool/eathena-monitor.c +++ b/src/tool/eathena-monitor.c @@ -1,73 +1,88 @@ /** * Name: eAthena processes monitor - * Author: Bartosz Waszak + * Original Author: Bartosz Waszak + * Rewrite Author: Ben Longbons * License: GPL * Compilation: * gcc -o eathena-monitor eathena-monitor.c -*/ + */ #include #include #include #include #include -#include -#if !defined(linux) && (defined(__sgi) || defined(__sun__) || defined(__sun) || defined(__sparc) || defined(__sparc__)) -#include -#endif - -#if defined (__FreeBSD__) || defined (__OpenBSD__) || defined (__NetBSD__) || defined (__APPLE__) -#include -#include -#endif - -#if defined(linux) || defined(__CYGWIN32__) || defined(__hpux) -#include -#endif - -#include -#include #include #include #include #include #define HOME getenv("HOME") -#define LOGIN_SERVER "login-server" -#define MAP_SERVER "map-server" -#define CHAR_SERVER "char-server" +#define LOGIN_SERVER "./login-server" +#define MAP_SERVER "./map-server" +#define CHAR_SERVER "./char-server" #define CONFIG "conf/eathena-monitor.conf" #define LOGFILE "log/eathena-monitor.log" -#ifndef PATH_MAX -#define PATH_MAX 4096 -#endif -#define IS_BLANK(ptr) \ - (((*(ptr)) == ' ') || ((*(ptr)) == '\b') || \ - ((*(ptr)) == '\n') || ((*(ptr)) == '\r')) -#define SKIP_BLANK(ptr) \ - { while (((*(ptr)) == ' ') || ((*(ptr)) == '\b') || \ - ((*(ptr)) == '\n') || ((*(ptr)) == '\r')) ptr++; } +#define SKIP_BLANK(ptr) ptr += skip_blank(ptr) +inline size_t skip_blank(const char* ptr) { + size_t i = 0; + while ( + (ptr[i] == ' ') || + (ptr[i] == '\b') || + (ptr[i] == '\n') || + (ptr[i] == '\r') + ) ptr++; + return i; +} -#define GOTO_EQL(ptr) \ - { while (((*(ptr)) != '\0') && ((*(ptr)) != '=') && \ - ((*(ptr)) != '\n') && ((*(ptr)) != '\r')) ptr++; } +#define GOTO_EQL(ptr) ptr += goto_eql(ptr) +inline size_t goto_eql(const char* ptr) { + size_t i = 0; + while ( + (ptr[i] != '\0') && + (ptr[i] != '=') && + (ptr[i] != '\n') && + (ptr[i] != '\r') + ) ptr++; + return i; +} -#define GOTO_EOL(ptr) \ - { while (((*(ptr)) != '\0') && \ - ((*(ptr)) != '\n') && ((*(ptr)) != '\r')) ptr++; } +#define GOTO_EOL(ptr) ptr += goto_newline(ptr) +inline size_t goto_newline(const char* ptr) { + size_t i = 0; + while ( + (ptr[i] != '\0') && + (ptr[i] != '\n') && + (ptr[i] != '\r') + ) ptr++; + return i; +} -char *workdir; -char *login_server; -char *map_server; -char *char_server; -char *config; -char *logfile; -unsigned int interval = 5; -unsigned int pid_login, pid_map, pid_char; -char use_login = 1; +// initialiized to $HOME/tmwserver +const char *workdir; +//the rest are relative to workdir +const char *login_server = LOGIN_SERVER; +const char *map_server = MAP_SERVER; +const char *char_server = CHAR_SERVER; +const char *logfile = LOGFILE; +// this variable is hard-coded, but the command-line is checked first +const char *config = CONFIG; + +pid_t pid_login, pid_map, pid_char; + +const char* make_path (const char* base, const char* path) { + size_t base_len = strlen(base); + size_t path_len = strlen(path); + char* out = malloc(base_len + 1 + path_len + 1); + memcpy(out, base, base_len); + out[base_len] = '/'; + memcpy(out + base_len + 1, path, path_len); + out[base_len + 1 + path_len] = '\0'; + return out; +} void parse_option (char *name, char *value) { if (!strcasecmp(name, "login_server")) { @@ -80,30 +95,24 @@ void parse_option (char *name, char *value) { workdir = strdup(value); } else if (!strcasecmp(name, "logfile")) { logfile = strdup(value); - } else if (!strcasecmp(name, "interval")) { - interval = atoi(strdup(value)); } else { - printf("WARNING: ingnoring invalid options '%s'\n", name); + fprintf(stderr, "WARNING: ingnoring invalid option '%s' = '%s'\n", name, value); } } -int read_config(char *filename) { +void read_config(const char *filename) { FILE *input; - char *str, *base; char string[1000]; - char *name; - char *value; - int errors = 0; if (!(input = fopen(filename,"r")) && !(input = fopen (config, "r"))) { - fprintf (stderr, "ERROR: Config file doesn't exist (%s and %s), using builtin defaults\n", filename, config); - return -1; + perror("Unable to load config file"); + return; } while (1) { - if (fgets (&string[0], sizeof (string) - 1, input) == NULL) + if (fgets (string, sizeof (string) - 1, input) == NULL) break; - str = &string[0]; + char *str = string, *name, *value; SKIP_BLANK(str); string[sizeof (string) - 1] = '\0'; if (*str == '#') @@ -127,162 +136,89 @@ int read_config(char *filename) { } fclose (input); - return(0); } -void start_process(char *exec) { - pid_t pid; - pid = fork(); - if (pid == 0) { - if (!fork()) { - execl(exec,exec,NULL); - exit(0); +pid_t start_process(const char *exec) { + const char *args[2] = {exec, NULL}; + pid_t pid = fork(); + if (pid == -1) { + fprintf(stderr, "Failed to fork"); + return 0; } - exit(0); + if (pid == 0) { + execv(exec, (char**)args); + perror("Failed to exec"); + kill(getppid(), SIGABRT); + exit(1); } - wait(0); + return pid; } +// Kill all children with the same signal we got, then ourself. +// Note that none of the servers do any signal handling themselves. void stop_process(int sig) { - system("killall map-server"); - system("killall login-server"); - system("killall char-server"); - exit(0); + if (pid_map) kill(pid_map, sig); + if (pid_login) kill(pid_login, sig); + if (pid_char) kill(pid_char, sig); + signal(sig, SIG_DFL); + raise(sig); } int main(int argc, char *argv[]) { - DIR *procdir; - FILE *log; - - int fd; - - char pathbuf[PATH_MAX]; - char link[PATH_MAX]; - char timestamp[256]; - - struct tm *tmp; - struct dirent *procdirp; - struct statfs sfs; - - unsigned int proc_login, proc_map, proc_char; - - time_t t; - size_t l_size; - - if ( statfs("/proc", &sfs) == -1 ) { - fprintf(stderr,"ERROR: /proc filesystem is unaccessible\n"); - return(255); - } - + // These are all the signals we are likely to get + // The shell handles stop/cont signal(SIGTERM, stop_process); signal(SIGINT, stop_process); + signal(SIGQUIT, stop_process); + signal(SIGABRT, stop_process); - workdir = (char *) malloc(sizeof(char) * 1024); - login_server = (char *) malloc(sizeof(char) * 1024); - char_server = (char *) malloc(sizeof(char) * 1024); - map_server = (char *) malloc(sizeof(char) * 1024); - logfile = (char *) malloc(sizeof(char) * 1024); - config = (char *) malloc(sizeof(char) * 1024); - - sprintf(workdir,"%s/tmwserver",HOME); - sprintf(login_server,"%s/%s", workdir, LOGIN_SERVER); - sprintf(map_server,"%s/%s", workdir, MAP_SERVER); - sprintf(char_server,"%s/%s", workdir, CHAR_SERVER); - sprintf(logfile,"%s/%s", workdir,LOGFILE); - sprintf(config,"%s/%s", workdir, CONFIG); - - read_config(argv[1]); + workdir = make_path(HOME, "tmwserver"); - chdir(workdir); + read_config(argc>1 ? argv[1] : NULL); - if (strlen(login_server) == 0) use_login = 0; + if (chdir(workdir) < 0) perror("Failed to change directory"), exit(1); printf ("Starting:\n"); - printf ("* interval: %d s\n", interval); printf ("* workdir: %s\n", workdir); - if (use_login) - printf ("* login_server: %s\n", login_server); - else - printf ("* login_server: (none)\n"); + printf ("* login_server: %s\n", login_server); printf ("* map_server: %s\n", map_server); printf ("* char_server: %s\n", char_server); - - if (fork()) { - exit(0); - } - - if ((fd = open("/dev/null", O_RDONLY)) != 0) { + { + //make sure all possible file descriptors are free for use by the servers + //if there are file descriptors higher than the max open from before the limit dropped, that's not our problem + int fd = sysconf(_SC_OPEN_MAX); + while (--fd > 2) + if (close(fd) == 0) + fprintf(stderr, "close fd %d\n", fd); + fd = open("/dev/null", O_RDWR); + if (fd < 0) perror("open /dev/null"), exit(1); dup2(fd, 0); - close(fd); - } - - if ((fd = open("/dev/null", O_WRONLY)) != 1) { dup2(fd, 1); close(fd); } - dup2(1, 2); - while (1) { - if (use_login) proc_login = 0; - proc_map = 0; - proc_char = 0; - - if ((procdir = opendir("/proc")) == NULL) { - fprintf(stderr,"ERROR: Cannot open /proc filesystem\n"); - return(255); + // write stuff to stderr + time_t t = time(NULL); + struct tm *tmp = localtime(&t); + char timestamp[256]; + strftime(timestamp, sizeof(timestamp), "%F %T", tmp); + + if (!pid_login) { + pid_login = start_process(login_server); + fprintf (stderr, "[%s] forked login server: %lu\n", timestamp, (unsigned long)pid_login); } - - while ((procdirp = readdir(procdir)) != NULL) { - if (strtok(procdirp->d_name, "0123456789") == NULL) { - sprintf(pathbuf, "%s%s%s", "/proc/", procdirp->d_name, "/exe"); - l_size = readlink(pathbuf, link, PATH_MAX); - - if (l_size != -1) { - link[l_size] = '\0'; - if (use_login && !strcmp(link, login_server)) { - proc_login = 1; - pid_login = (unsigned int) procdirp->d_name; - } - - if (!strcmp(link, char_server)) { - proc_char = 1; - pid_char = (unsigned int) procdirp->d_name; - } - - if (!strcmp(link, map_server)) { - proc_map = 1; - pid_map = (unsigned int) procdirp->d_name; - } - } - } + if (!pid_char) { + pid_char = start_process(char_server); + fprintf (stderr, "[%s] forked char server: %lu\n", timestamp, (unsigned long)pid_char); } - closedir(procdir); - - if (!(log = fopen (logfile,"a"))) { - log = fopen("/tmp/monitor.log","a"); + if (!pid_map) { + pid_map = start_process(map_server); + fprintf (stderr, "[%s] forked map server: %lu\n", timestamp, (unsigned long)pid_map); } - - t = time(NULL); - tmp = localtime(&t); - strftime(timestamp, sizeof(timestamp), "%F %X", tmp); - - if (use_login && proc_login == 0) { - fprintf (log,"[%d][%s] NOTICE: Login server is dead - restarting\n", getpid(), timestamp); - start_process(login_server); - sleep(2); - } - if (proc_char == 0) { - fprintf (log,"[%d][%s] NOTICE: Char server is dead - restarting\n", getpid(), timestamp); - start_process(char_server); - sleep(2); - } - if (proc_map == 0) { - fprintf (log,"[%d][%s] NOTICE: Map server is dead - restarting\n", getpid(), timestamp); - start_process(map_server); - sleep(2); - } - - fclose(log); - sleep(interval); + pid_t dead = wait(NULL); + if (dead < 0) perror("Failed to wait for child"), exit(1); + if (pid_login == dead) pid_login = 0; + if (pid_char == dead) pid_char = 0; + if (pid_map == dead) pid_map = 0; } } -- cgit v1.2.3-70-g09d2 From 0267f81e4b66e5f1740a91fc5cbb1d21b98d07ba Mon Sep 17 00:00:00 2001 From: Ben Longbons Date: Thu, 17 Mar 2011 19:58:36 -0700 Subject: Convert Japanese comments to UTF-8, and convert French from ISO-8859-1 char/char.c was munged as UTF-8 ladmin/ladmin.c was ISO-8859 txt-converter/char/char-converter.c was partially SHIFT-JIS (like most) but one line appears to have been in EUC-JP --- src/char/char.c | 70 ++--- src/ladmin/ladmin.c | 522 ++++++++++++++++---------------- src/txt-converter/char/char-converter.c | 6 +- 3 files changed, 299 insertions(+), 299 deletions(-) diff --git a/src/char/char.c b/src/char/char.c index 07b1fb6..33379d3 100644 --- a/src/char/char.c +++ b/src/char/char.c @@ -442,7 +442,7 @@ int mmo_char_fromstr (char *str, struct mmo_charstatus *p) } if (str[next] == '\n' || str[next] == '\r') - return 1; // �V�K�f�[�^ + return 1; // 新規データ next++; @@ -557,7 +557,7 @@ int mmo_char_fromstr (char *str, struct mmo_charstatus *p) for (i = 0; str[next] && str[next] != '\t' && str[next] != '\n' && str[next] != '\r'; i++) - { // global_reg����ȑO��athena.txt�݊��̂��߈ꉞ'\n'�`�F�b�N + { // global_reg実装以前のathena.txt互換のため一応'\n'チェック if (sscanf (str + next, "%[^,],%d%n", p->global_reg[i].str, &p->global_reg[i].value, &len) != 2) @@ -1851,17 +1851,17 @@ int disconnect_player (int accound_id) return 0; } -// �L�����폜�ɔ����f�[�^�폜 +// キャラ削除に伴うデータ削除 static int char_delete (struct mmo_charstatus *cs) { - // �M���h�E�� + // ギルド脱退 if (cs->guild_id) inter_guild_leave (cs->guild_id, cs->account_id, cs->char_id); - // �p�[�e�B�[�E�� + // パーティー脱退 if (cs->party_id) inter_party_leave (cs->party_id, cs->account_id); - // ���� + // 離婚 if (cs->partner_id) char_divorce (cs); @@ -2163,7 +2163,7 @@ int parse_tologin (int fd) RFIFOSKIP (fd, 8 + RFIFOL (fd, 4)); break; - // account_reg2�ύX�ʒm + // account_reg2変更通知 case 0x2729: if (RFIFOREST (fd) < 4 || RFIFOREST (fd) < RFIFOW (fd, 2)) return 0; @@ -2180,7 +2180,7 @@ int parse_tologin (int fd) reg[j].value = RFIFOL (fd, p + 32); } set_account_reg2 (acc, j, reg); - // ���C���O�C�����֎~���Ă����Α����K�v�͖��� + // 同垢ログインを禁止していれば送る必要は無い memcpy (buf, RFIFOP (fd, 0), RFIFOW (fd, 2)); WBUFW (buf, 0) = 0x2b11; mapif_sendall (buf, WBUFW (buf, 2)); @@ -2528,7 +2528,7 @@ int parse_frommap (int fd) RFIFOSKIP (fd, RFIFOW (fd, 2)); break; - // �F�ؗv�� + // 認証要求 case 0x2afc: if (RFIFOREST (fd) < 22) return 0; @@ -2578,7 +2578,7 @@ int parse_frommap (int fd) RFIFOSKIP (fd, 22); break; - // MAP�T�[�o�[���̃��[�U�[�����M + // MAPサーバー上のユーザー数受信 case 0x2aff: if (RFIFOREST (fd) < 6 || RFIFOREST (fd) < RFIFOW (fd, 2)) return 0; @@ -2610,7 +2610,7 @@ int parse_frommap (int fd) RFIFOSKIP (fd, 6 + i * 4); break; - // �L�����f�[�^�ۑ� + // キャラデータ保存 case 0x2b01: if (RFIFOREST (fd) < 4 || RFIFOREST (fd) < RFIFOW (fd, 2)) return 0; @@ -2626,7 +2626,7 @@ int parse_frommap (int fd) RFIFOSKIP (fd, RFIFOW (fd, 2)); break; - // �L�����Z���v�� + // キャラセレ要求 case 0x2b02: if (RFIFOREST (fd) < 18) return 0; @@ -2649,7 +2649,7 @@ int parse_frommap (int fd) RFIFOSKIP (fd, 18); break; - // �}�b�v�T�[�o�[�Ԉړ��v�� + // マップサーバー間移動要求 case 0x2b05: if (RFIFOREST (fd) < 49) return 0; @@ -2681,7 +2681,7 @@ int parse_frommap (int fd) RFIFOSKIP (fd, 49); break; - // �L���������� + // キャラ名検索 case 0x2b08: if (RFIFOREST (fd) < 6) return 0; @@ -2874,7 +2874,7 @@ int parse_frommap (int fd) // case 0x2b0f: not more used (available for futur usage) - // account_reg�ۑ��v�� + // account_reg保存要求 case 0x2b10: if (RFIFOREST (fd) < 4 || RFIFOREST (fd) < RFIFOW (fd, 2)) return 0; @@ -2890,7 +2890,7 @@ int parse_frommap (int fd) reg[j].value = RFIFOL (fd, p + 32); } set_account_reg2 (acc, j, reg); - // login�T�[�o�[�֑��� + // loginサーバーへ送る if (login_fd > 0) { // don't send request if no login-server WFIFOW (login_fd, 0) = 0x2728; @@ -2898,7 +2898,7 @@ int parse_frommap (int fd) RFIFOW (fd, 2)); WFIFOSET (login_fd, WFIFOW (login_fd, 2)); } - // ���[���h�ւ̓��C���O�C�����Ȃ�����map�T�[�o�[�ɑ����K�v�͂Ȃ� + // ワールドへの同垢ログインがなければmapサーバーに送る必要はない //memcpy(buf, RFIFOP(fd,0), RFIFOW(fd,2)); //WBUFW(buf,0) = 0x2b11; //mapif_sendall(buf, WBUFW(buf,2)); @@ -2925,15 +2925,15 @@ int parse_frommap (int fd) } default: - // inter server�����ɓn�� + // inter server処理に渡す { int r = inter_parse_frommap (fd); - if (r == 1) // �����ł��� + if (r == 1) // 処理できた break; - if (r == 2) // �p�P�b�g���������Ȃ� + if (r == 2) // パケット長が足りない return 0; } - // inter server�����ł��Ȃ��ꍇ�͐ؒf + // inter server処理でもない場合は切断 printf ("char: unknown packet 0x%04x (%d bytes to read in buffer)! (from map).\n", RFIFOW (fd, 0), RFIFOREST (fd)); @@ -2971,7 +2971,7 @@ int search_mapserver (char *map) return -1; } -// char_mapif�̏����������i���݂�inter_mapif�������̂݁j +// char_mapifの初期化処理(現在はinter_mapif初期化のみ) static int char_mapif_init (int fd) { return inter_mapif_init (fd); @@ -3027,7 +3027,7 @@ int parse_char (int fd) switch (RFIFOW (fd, 0)) { - case 0x20b: //20040622�Í���ragexe�Ή� + case 0x20b: //20040622暗号化ragexe対応 if (RFIFOREST (fd) < 19) return 0; RFIFOSKIP (fd, 19); @@ -3046,7 +3046,7 @@ int parse_char (int fd) RFIFOSKIP (fd, 50); break; - case 0x65: // �ڑ��v�� + case 0x65: // 接続要求 if (RFIFOREST (fd) < 17) return 0; { @@ -3139,7 +3139,7 @@ int parse_char (int fd) RFIFOSKIP (fd, 17); break; - case 0x66: // �L�����I�� + case 0x66: // キャラ選択 if (!sd || RFIFOREST (fd) < 3) return 0; @@ -3309,7 +3309,7 @@ int parse_char (int fd) RFIFOSKIP (fd, 3); break; - case 0x67: // �쐬 + case 0x67: // 作成 if (!sd || RFIFOREST (fd) < 37) return 0; i = make_new_char (fd, RFIFOP (fd, 2)); @@ -3510,7 +3510,7 @@ int parse_char (int fd) } break; - case 0x2af8: // �}�b�v�T�[�o�[���O�C�� + case 0x2af8: // マップサーバーログイン if (RFIFOREST (fd) < 60) return 0; WFIFOW (fd, 0) = 0x2af9; @@ -3559,13 +3559,13 @@ int parse_char (int fd) } break; - case 0x187: // Alive�M���H + case 0x187: // Alive信号? if (RFIFOREST (fd) < 6) return 0; RFIFOSKIP (fd, 6); break; - case 0x7530: // Athena���񏊓� + case 0x7530: // Athena情報所得 WFIFOW (fd, 0) = 0x7531; WFIFOB (fd, 2) = ATHENA_MAJOR_VERSION; WFIFOB (fd, 3) = ATHENA_MINOR_VERSION; @@ -3578,7 +3578,7 @@ int parse_char (int fd) RFIFOSKIP (fd, 2); return 0; - case 0x7532: // �ڑ��̐ؒf(default�Ə����͈ꏏ���������I�ɂ��邽��) + case 0x7532: // 接続の切断(defaultと処理は一緒だが明示的にするため) session[fd]->eof = 1; return 0; @@ -3591,7 +3591,7 @@ int parse_char (int fd) return 0; } -// �S�Ă�MAP�T�[�o�[�Ƀf�[�^���M�i���M����map�I�̐����Ԃ��j +// 全てのMAPサーバーにデータ送信(送信したmap鯖の数を返す) int mapif_sendall (char *buf, unsigned int len) { int i, c; @@ -3610,7 +3610,7 @@ int mapif_sendall (char *buf, unsigned int len) return c; } -// �����ȊO�̑S�Ă�MAP�T�[�o�[�Ƀf�[�^���M�i���M����map�I�̐����Ԃ��j +// 自分以外の全てのMAPサーバーにデータ送信(送信したmap鯖の数を返す) int mapif_sendallwos (int sfd, unsigned char *buf, unsigned int len) { int i, c; @@ -3629,7 +3629,7 @@ int mapif_sendallwos (int sfd, unsigned char *buf, unsigned int len) return c; } -// MAP�T�[�o�[�Ƀf�[�^���M�imap�I�����m�F�L���j +// MAPサーバーにデータ送信(map鯖生存確認有り) int mapif_send (int fd, unsigned char *buf, unsigned int len) { int i; @@ -3701,7 +3701,7 @@ int check_connect_login_server (int tid, unsigned int tick, int id, int data) //---------------------------------------------------------- // Return numerical value of a switch configuration by [Yor] -// on/off, english, fran�ais, deutsch, espanol +// on/off, english, français, deutsch, español //---------------------------------------------------------- int config_switch (const char *str) { @@ -4117,7 +4117,7 @@ int do_init (int argc, char **argv) update_online = time (NULL); create_online_files (); // update online players files at start of the server - inter_init ((argc > 2) ? argv[2] : inter_cfgName); // inter server ������ + inter_init ((argc > 2) ? argv[2] : inter_cfgName); // inter server 初期化 set_termfunc (do_final); set_defaultparse (parse_char); diff --git a/src/ladmin/ladmin.c b/src/ladmin/ladmin.c index 5ef9b6c..56cac60 100644 --- a/src/ladmin/ladmin.c +++ b/src/ladmin/ladmin.c @@ -57,7 +57,7 @@ int passenc = 2; // Encoding type of the password #else int passenc = 0; // Encoding type of the password #endif -char defaultlanguage = 'E'; // Default language (F: Franais/E: English) +char defaultlanguage = 'E'; // Default language (F: Français/E: English) // (if it's not 'F', default is English) char ladmin_log_filename[1024] = "log/ladmin.log"; char date_format[32] = "%Y-%m-%d %H:%M:%S"; @@ -316,7 +316,7 @@ char *makeordinal (int number) else if (number == 1) return "er"; else - return "me"; + return "ème"; } else { @@ -352,10 +352,10 @@ int verify_accountname (char *account_name) if (defaultlanguage == 'F') { printf - ("Caractre interdit trouv dans le nom du compte (%d%s caractre).\n", + ("Caractère interdit trouvé dans le nom du compte (%d%s caractère).\n", i + 1, makeordinal (i + 1)); ladmin_log - ("Caractre interdit trouv dans le nom du compte (%d%s caractre)." + ("Caractère interdit trouvé dans le nom du compte (%d%s caractère)." RETCODE, i + 1, makeordinal (i + 1)); } else @@ -376,9 +376,9 @@ int verify_accountname (char *account_name) if (defaultlanguage == 'F') { printf - ("Nom du compte trop court. Entrez un nom de compte de 4-23 caractres.\n"); + ("Nom du compte trop court. Entrez un nom de compte de 4-23 caractères.\n"); ladmin_log - ("Nom du compte trop court. Entrez un nom de compte de 4-23 caractres." + ("Nom du compte trop court. Entrez un nom de compte de 4-23 caractères." RETCODE); } else @@ -397,9 +397,9 @@ int verify_accountname (char *account_name) if (defaultlanguage == 'F') { printf - ("Nom du compte trop long. Entrez un nom de compte de 4-23 caractres.\n"); + ("Nom du compte trop long. Entrez un nom de compte de 4-23 caractères.\n"); ladmin_log - ("Nom du compte trop long. Entrez un nom de compte de 4-23 caractres." + ("Nom du compte trop long. Entrez un nom de compte de 4-23 caractères." RETCODE); } else @@ -470,7 +470,7 @@ int typepasswd (char *password) if (defaultlanguage == 'F') { ladmin_log - ("Aucun mot de passe n'a t donn. Demande d'un mot de passe." + ("Aucun mot de passe n'a été donné. Demande d'un mot de passe." RETCODE); } else @@ -490,7 +490,7 @@ int typepasswd (char *password) password1[i++] = letter; if (defaultlanguage == 'F') printf - ("\033[0m\033[1;36m R-entrez le mot de passe > \033[0;32;42m"); + ("\033[0m\033[1;36m Ré-entrez le mot de passe > \033[0;32;42m"); else printf ("\033[0m\033[1;36m Verify the password > \033[0;32;42m"); i = 0; @@ -506,9 +506,9 @@ int typepasswd (char *password) if (defaultlanguage == 'F') { printf - ("Erreur de vrification du mot de passe: Saisissez le mme mot de passe svp.\n"); + ("Erreur de vérification du mot de passe: Saisissez le même mot de passe svp.\n"); ladmin_log - ("Erreur de vrification du mot de passe: Saisissez le mme mot de passe svp." + ("Erreur de vérification du mot de passe: Saisissez le même mot de passe svp." RETCODE); ladmin_log (" Premier mot de passe: %s, second mot de passe: %s." RETCODE, password1, password2); @@ -551,10 +551,10 @@ int verify_password (char *password) if (defaultlanguage == 'F') { printf - ("Caractre interdit trouv dans le mot de passe (%d%s caractre).\n", + ("Caractère interdit trouvé dans le mot de passe (%d%s caractère).\n", i + 1, makeordinal (i + 1)); ladmin_log - ("Caractre interdit trouv dans le nom du compte (%d%s caractre)." + ("Caractère interdit trouvé dans le nom du compte (%d%s caractère)." RETCODE, i + 1, makeordinal (i + 1)); } else @@ -575,9 +575,9 @@ int verify_password (char *password) if (defaultlanguage == 'F') { printf - ("Nom du compte trop court. Entrez un nom de compte de 4-23 caractres.\n"); + ("Nom du compte trop court. Entrez un nom de compte de 4-23 caractères.\n"); ladmin_log - ("Nom du compte trop court. Entrez un nom de compte de 4-23 caractres." + ("Nom du compte trop court. Entrez un nom de compte de 4-23 caractères." RETCODE); } else @@ -596,9 +596,9 @@ int verify_password (char *password) if (defaultlanguage == 'F') { printf - ("Mot de passe trop long. Entrez un mot de passe de 4-23 caractres.\n"); + ("Mot de passe trop long. Entrez un mot de passe de 4-23 caractères.\n"); ladmin_log - ("Mot de passe trop long. Entrez un mot de passe de 4-23 caractres." + ("Mot de passe trop long. Entrez un mot de passe de 4-23 caractères." RETCODE); } else @@ -786,7 +786,7 @@ void display_help (char *param, int language) printf ("aide/help/?\n"); printf (" Affiche la description des commandes\n"); printf ("aide/help/? [commande]\n"); - printf (" Affiche la description de la commande specifie\n"); + printf (" Affiche la description de la commande specifiée\n"); } else if (strcmp (command, "help") == 0) { @@ -799,11 +799,11 @@ void display_help (char *param, int language) else if (strcmp (command, "add") == 0) { printf ("add \n"); - printf (" Cre un compte avec l'email par dfaut (a@a.com).\n"); + printf (" Crée un compte avec l'email par défaut (a@a.com).\n"); printf - (" Concernant le sexe, seule la premire lettre compte (F ou M).\n"); + (" Concernant le sexe, seule la première lettre compte (F ou M).\n"); printf - (" L'e-mail est a@a.com (e-mail par dfaut). C'est comme n'avoir aucun e-mail.\n"); + (" L'e-mail est a@a.com (e-mail par défaut). C'est comme n'avoir aucun e-mail.\n"); printf (" Lorsque motdepasse est omis, la saisie se fait sans que la frappe se voit.\n"); printf (" add testname Male testpass\n"); @@ -812,17 +812,17 @@ void display_help (char *param, int language) { printf ("ban/banish aaaa/mm/jj hh:mm:ss \n"); printf (" Change la date de fin de bannissement d'un compte.\n"); - printf (" Comme banset, mais est la fin.\n"); + printf (" Comme banset, mais est à la fin.\n"); } else if (strcmp (command, "banadd") == 0) { printf ("banadd \n"); printf - (" Ajoute ou soustrait du temps la date de banissement d'un compte.\n"); + (" Ajoute ou soustrait du temps à la date de banissement d'un compte.\n"); printf (" Les modificateurs sont construits comme suit:\n"); printf (" Valeur d'ajustement (-1, 1, +1, etc...)\n"); - printf (" Elment modifi:\n"); - printf (" a ou y: anne\n"); + printf (" Elément modifié:\n"); + printf (" a ou y: année\n"); printf (" m: mois\n"); printf (" j ou d: jour\n"); printf (" h: heure\n"); @@ -831,7 +831,7 @@ void display_help (char *param, int language) printf (" banadd testname +1m-2mn1s-6a\n"); printf (" Cette exemple ajoute 1 mois et une seconde, et soustrait 2 minutes\n"); - printf (" et 6 ans dans le mme temps.\n"); + printf (" et 6 ans dans le même temps.\n"); printf ("NOTE: Si vous modifez la date de banissement d'un compte non bani,\n"); printf @@ -841,30 +841,30 @@ void display_help (char *param, int language) { printf ("banset aaaa/mm/jj [hh:mm:ss]\n"); printf (" Change la date de fin de bannissement d'un compte.\n"); - printf (" Heure par dfaut [hh:mm:ss]: 23:59:59.\n"); + printf (" Heure par défaut [hh:mm:ss]: 23:59:59.\n"); printf ("banset 0\n"); - printf (" Dbanni un compte (0 = de-banni).\n"); + printf (" Débanni un compte (0 = de-banni).\n"); } else if (strcmp (command, "block") == 0) { printf ("block \n"); printf - (" Place le status d'un compte 5 (You have been blocked by the GM Team).\n"); + (" Place le status d'un compte à 5 (You have been blocked by the GM Team).\n"); printf - (" La commande est l'quivalent de state 5.\n"); + (" La commande est l'équivalent de state 5.\n"); } else if (strcmp (command, "check") == 0) { printf ("check \n"); printf - (" Vrifie la validit d'un mot de passe pour un compte\n"); + (" Vérifie la validité d'un mot de passe pour un compte\n"); printf (" NOTE: Le serveur n'enverra jamais un mot de passe.\n"); printf - (" C'est la seule mthode que vous possdez pour savoir\n"); + (" C'est la seule méthode que vous possédez pour savoir\n"); printf - (" si un mot de passe est le bon. L'autre mthode est\n"); + (" si un mot de passe est le bon. L'autre méthode est\n"); printf - (" d'avoir un accs ('physique') au fichier des comptes.\n"); + (" d'avoir un accès ('physique') au fichier des comptes.\n"); } else if (strcmp (command, "create") == 0) { @@ -878,7 +878,7 @@ void display_help (char *param, int language) printf ("del \n"); printf (" Supprime un compte.\n"); printf - (" La commande demande confirmation. Aprs confirmation, le compte est dtruit.\n"); + (" La commande demande confirmation. Après confirmation, le compte est détruit.\n"); } else if (strcmp (command, "email") == 0) { @@ -896,7 +896,7 @@ void display_help (char *param, int language) printf ("gm [Niveau_GM]\n"); printf (" Modifie le niveau de GM d'un compte.\n"); printf - (" Valeur par dfaut: 0 (suppression du niveau de GM).\n"); + (" Valeur par défaut: 0 (suppression du niveau de GM).\n"); printf (" gm nomtest 80\n"); } else if (strcmp (command, "id") == 0) @@ -913,26 +913,26 @@ void display_help (char *param, int language) { printf ("kami \n"); printf - (" Envoi un message gnral sur tous les serveurs de map (en jaune).\n"); + (" Envoi un message général sur tous les serveurs de map (en jaune).\n"); } else if (strcmp (command, "kamib") == 0) { printf ("kamib \n"); printf - (" Envoi un message gnral sur tous les serveurs de map (en bleu).\n"); + (" Envoi un message général sur tous les serveurs de map (en bleu).\n"); } else if (strcmp (command, "language") == 0) { printf ("language \n"); printf (" Change la langue d'affichage.\n"); - printf (" Langues possibles: 'Franais' ou 'English'.\n"); + printf (" Langues possibles: 'Français' ou 'English'.\n"); } else if (strcmp (command, "list") == 0) { printf ("list/ls [Premier_id [Dernier_id]]\n"); printf (" Affiche une liste de comptes.\n"); printf - (" 'Premier_id', 'Dernier_id': indique les identifiants de dpart et de fin.\n"); + (" 'Premier_id', 'Dernier_id': indique les identifiants de départ et de fin.\n"); printf (" La recherche par nom n'est pas possible avec cette commande.\n"); printf (" list 10 9999999\n"); @@ -961,9 +961,9 @@ void display_help (char *param, int language) else if (strcmp (command, "memo") == 0) { printf ("memo \n"); - printf (" Modifie le mmo d'un compte.\n"); + printf (" Modifie le mémo d'un compte.\n"); printf - (" 'memo': Il peut avoir jusqu' 253 caractres (avec des espaces ou non).\n"); + (" 'memo': Il peut avoir jusqu'à 253 caractères (avec des espaces ou non).\n"); } else if (strcmp (command, "name") == 0) { @@ -988,7 +988,7 @@ void display_help (char *param, int language) printf (" Cherche des comptes.\n"); printf (" Affiche les comptes dont les noms correspondent.\n"); // printf("search -r/-e/--expr/--regex \n"); -// printf(" Cherche des comptes par expression regulire.\n"); +// printf(" Cherche des comptes par expression regulière.\n"); // printf(" Affiche les comptes dont les noms correspondent.\n"); } else if (strcmp (command, "sex") == 0) @@ -1002,8 +1002,8 @@ void display_help (char *param, int language) printf ("state \n"); printf (" Change le statut d'un compte.\n"); printf - (" 'nouveaustatut': Le statut est le mme que celui du packet 0x006a + 1.\n"); - printf (" les possibilits sont:\n"); + (" 'nouveaustatut': Le statut est le même que celui du packet 0x006a + 1.\n"); + printf (" les possibilités sont:\n"); printf (" 0 = Compte ok\n"); printf (" 1 = Unregistered ID\n"); printf (" 2 = Incorrect Password\n"); @@ -1029,11 +1029,11 @@ void display_help (char *param, int language) { printf ("timeadd \n"); printf - (" Ajoute/soustrait du temps la limite de validit d'un compte.\n"); - printf (" Le modificateur est compos comme suit:\n"); + (" Ajoute/soustrait du temps à la limite de validité d'un compte.\n"); + printf (" Le modificateur est composé comme suit:\n"); printf (" Valeur modificatrice (-1, 1, +1, etc...)\n"); - printf (" Elment modifi:\n"); - printf (" a ou y: anne\n"); + printf (" Elément modifié:\n"); + printf (" a ou y: année\n"); printf (" m: mois\n"); printf (" j ou d: jour\n"); printf (" h: heure\n"); @@ -1042,36 +1042,36 @@ void display_help (char *param, int language) printf (" timeadd testname +1m-2mn1s-6a\n"); printf (" Cette exemple ajoute 1 mois et une seconde, et soustrait 2 minutes\n"); - printf (" et 6 ans dans le mme temps.\n"); + printf (" et 6 ans dans le même temps.\n"); printf - ("NOTE: Vous ne pouvez pas modifier une limite de validit illimite. Si vous\n"); + ("NOTE: Vous ne pouvez pas modifier une limite de validité illimitée. Si vous\n"); printf - (" dsirez le faire, c'est que vous voulez probablement crer un limite de\n"); + (" désirez le faire, c'est que vous voulez probablement créer un limite de\n"); printf - (" validit limite. Donc, en premier, fix une limite de valitid.\n"); + (" validité limitée. Donc, en premier, fixé une limite de valitidé.\n"); } else if (strcmp (command, "timeadd") == 0) { printf ("timeset aaaa/mm/jj [hh:mm:ss]\n"); - printf (" Change la limite de validit d'un compte.\n"); - printf (" Heure par dfaut [hh:mm:ss]: 23:59:59.\n"); + printf (" Change la limite de validité d'un compte.\n"); + printf (" Heure par défaut [hh:mm:ss]: 23:59:59.\n"); printf ("timeset 0\n"); printf - (" Donne une limite de validit illimite (0 = illimite).\n"); + (" Donne une limite de validité illimitée (0 = illimitée).\n"); } else if (strcmp (command, "unban") == 0) { printf ("unban/unbanish \n"); printf (" Ote le banissement d'un compte.\n"); printf - (" La commande est l'quivalent de banset 0.\n"); + (" La commande est l'équivalent de banset 0.\n"); } else if (strcmp (command, "unblock") == 0) { printf ("unblock \n"); - printf (" Place le status d'un compte 0 (Compte ok).\n"); + printf (" Place le status d'un compte à 0 (Compte ok).\n"); printf - (" La commande est l'quivalent de state 0.\n"); + (" La commande est l'équivalent de state 0.\n"); } else if (strcmp (command, "version") == 0) { @@ -1103,23 +1103,23 @@ void display_help (char *param, int language) printf (" aide/help/? [commande] -- Affiche l'aide de la commande\n"); printf - (" add -- Cre un compte (sans email)\n"); + (" add -- Crée un compte (sans email)\n"); printf (" ban/banish aaaa/mm/jj hh:mm:ss -- Fixe la date finale de banismnt\n"); printf - (" banadd/ba -- Ajout/soustrait du temps la\n"); + (" banadd/ba -- Ajout/soustrait du temps à la\n"); printf (" exemple: ba moncompte +1m-2mn1s-2y date finale de banissement\n"); printf (" banset/bs aaaa/mm/jj [hh:mm:ss] -- Change la date fin de banisemnt\n"); printf - (" banset/bs 0 -- D-banis un compte.\n"); + (" banset/bs 0 -- Dé-banis un compte.\n"); printf - (" block -- Mets le status d'un compte 5 (blocked by the GM Team)\n"); + (" block -- Mets le status d'un compte à 5 (blocked by the GM Team)\n"); printf - (" check -- Vrifie un mot de passe d'un compte\n"); + (" check -- Vérifie un mot de passe d'un compte\n"); printf - (" create -- Cre un compte (avec email)\n"); + (" create -- Crée un compte (avec email)\n"); printf (" del -- Supprime un compte\n"); printf @@ -1133,9 +1133,9 @@ void display_help (char *param, int language) printf (" info -- Affiche les infos sur un compte\n"); printf - (" kami -- Envoi un message gnral (en jaune)\n"); + (" kami -- Envoi un message général (en jaune)\n"); printf - (" kamib -- Envoi un message gnral (en bleu)\n"); + (" kamib -- Envoi un message général (en bleu)\n"); printf (" language -- Change la langue d'affichage.\n"); printf @@ -1168,17 +1168,17 @@ void display_help (char *param, int language) printf (" state -- Change le statut d'1 compte\n"); printf - (" timeadd/ta -- Ajout/soustrait du temps la\n"); + (" timeadd/ta -- Ajout/soustrait du temps à la\n"); printf - (" exemple: ta moncompte +1m-2mn1s-2y limite de validit\n"); + (" exemple: ta moncompte +1m-2mn1s-2y limite de validité\n"); printf - (" timeset/ts aaaa/mm/jj [hh:mm:ss] -- Change la limite de validit\n"); + (" timeset/ts aaaa/mm/jj [hh:mm:ss] -- Change la limite de validité\n"); printf - (" timeset/ts 0 -- limite de validit = illimite\n"); + (" timeset/ts 0 -- limite de validité = illimitée\n"); printf (" unban/unbanish -- Ote le banissement d'un compte\n"); printf - (" unblock -- Mets le status d'un compte 0 (Compte ok)\n"); + (" unblock -- Mets le status d'un compte à 0 (Compte ok)\n"); printf (" version -- Donne la version du login-serveur\n"); printf @@ -1332,7 +1332,7 @@ void display_help (char *param, int language) { printf ("language \n"); printf (" Change the language of displaying.\n"); - printf (" Possible languages: Franais or English.\n"); + printf (" Possible languages: Français or English.\n"); } else if (strcmp (command, "list") == 0) { @@ -1626,7 +1626,7 @@ int addaccount (char *param, int emailflag) ("Entrez un nom de compte, un sexe et un mot de passe svp.\n"); printf (" add nomtest Male motdepassetest\n"); ladmin_log - ("Nombre incorrect de paramtres pour crer un compte (commande 'add')." + ("Nombre incorrect de paramètres pour créer un compte (commande 'add')." RETCODE); } else @@ -1656,7 +1656,7 @@ int addaccount (char *param, int emailflag) printf (" create nomtest Male mo@mail.com motdepassetest\n"); ladmin_log - ("Nombre incorrect de paramtres pour crer un compte (commande 'create')." + ("Nombre incorrect de paramètres pour créer un compte (commande 'create')." RETCODE); } else @@ -1680,8 +1680,8 @@ int addaccount (char *param, int emailflag) /* for(i = 0; name[i]; i++) { if (strchr("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_", name[i]) == NULL) { if (defaultlanguage == 'F') { - printf("Caractre interdit (%c) trouv dans le nom du compte (%d%s caractre).\n", name[i], i+1, makeordinal(i+1)); - ladmin_log("Caractre interdit (%c) trouv dans le nom du compte (%d%s caractre)." RETCODE, name[i], i+1, makeordinal(i+1)); + printf("Caractère interdit (%c) trouvé dans le nom du compte (%d%s caractère).\n", name[i], i+1, makeordinal(i+1)); + ladmin_log("Caractère interdit (%c) trouvé dans le nom du compte (%d%s caractère)." RETCODE, name[i], i+1, makeordinal(i+1)); } else { printf("Illegal character (%c) found in the account name (%d%s character).\n", name[i], i+1, makeordinal(i+1)); ladmin_log("Illegal character (%c) found in the account name (%d%s character)." RETCODE, name[i], i+1, makeordinal(i+1)); @@ -1733,10 +1733,10 @@ int addaccount (char *param, int emailflag) if (defaultlanguage == 'F') { printf - ("Email trop longue [%s]. Entrez une e-mail de 39 caractres maximum svp.\n", + ("Email trop longue [%s]. Entrez une e-mail de 39 caractères maximum svp.\n", email); ladmin_log - ("Email trop longue [%s]. Entrez une e-mail de 39 caractres maximum svp." + ("Email trop longue [%s]. Entrez une e-mail de 39 caractères maximum svp." RETCODE, email); } else @@ -1780,7 +1780,7 @@ int addaccount (char *param, int emailflag) if (defaultlanguage == 'F') { ladmin_log - ("Envoi d'un requte au serveur de logins pour crer un compte." + ("Envoi d'un requête au serveur de logins pour créer un compte." RETCODE); } else @@ -1823,9 +1823,9 @@ int banaddaccount (char *param) printf (" banadd nomtest +1m-2mn1s-6y\n"); printf (" Cette exemple ajoute 1 mois et 1 seconde, et soustrait 2 minutes\n"); - printf (" et 6 ans dans le mme temps.\n"); + printf (" et 6 ans dans le même temps.\n"); ladmin_log - ("Nombre incorrect de paramtres pour modifier la fin de ban d'un compte (commande 'banadd')." + ("Nombre incorrect de paramètres pour modifier la fin de ban d'un compte (commande 'banadd')." RETCODE); } else @@ -1905,7 +1905,7 @@ int banaddaccount (char *param) if (defaultlanguage == 'F') { - printf (" anne: %d\n", year); + printf (" année: %d\n", year); printf (" mois: %d\n", month); printf (" jour: %d\n", day); printf (" heure: %d\n", hour); @@ -1930,8 +1930,8 @@ int banaddaccount (char *param) printf ("Vous devez entrer un ajustement avec cette commande, svp:\n"); printf (" Valeur d'ajustement (-1, 1, +1, etc...)\n"); - printf (" Element modifi:\n"); - printf (" a ou y: anne\n"); + printf (" Element modifié:\n"); + printf (" a ou y: année\n"); printf (" m: mois\n"); printf (" j ou d: jour\n"); printf (" h: heure\n"); @@ -1940,7 +1940,7 @@ int banaddaccount (char *param) printf (" banadd nomtest +1m-2mn1s-6y\n"); printf (" Cette exemple ajoute 1 mois et 1 seconde, et soustrait 2 minutes\n"); - printf (" et 6 ans dans le mme temps.\n"); + printf (" et 6 ans dans le même temps.\n"); ladmin_log ("Aucun ajustement n'est pas un ajustement (commande 'banadd')." RETCODE); @@ -1971,9 +1971,9 @@ int banaddaccount (char *param) if (defaultlanguage == 'F') { printf - ("Entrez un ajustement d'annes correct (de -127 127), svp.\n"); + ("Entrez un ajustement d'années correct (de -127 à 127), svp.\n"); ladmin_log - ("Ajustement de l'anne hors norme (commande 'banadd')." + ("Ajustement de l'année hors norme (commande 'banadd')." RETCODE); } else @@ -1991,7 +1991,7 @@ int banaddaccount (char *param) if (defaultlanguage == 'F') { printf - ("Entrez un ajustement de mois correct (de -255 255), svp.\n"); + ("Entrez un ajustement de mois correct (de -255 à 255), svp.\n"); ladmin_log ("Ajustement du mois hors norme (commande 'banadd')." RETCODE); } @@ -2010,7 +2010,7 @@ int banaddaccount (char *param) if (defaultlanguage == 'F') { printf - ("Entrez un ajustement de jours correct (de -32767 32767), svp.\n"); + ("Entrez un ajustement de jours correct (de -32767 à 32767), svp.\n"); ladmin_log ("Ajustement des jours hors norme (commande 'banadd')." RETCODE); } @@ -2029,7 +2029,7 @@ int banaddaccount (char *param) if (defaultlanguage == 'F') { printf - ("Entrez un ajustement d'heures correct (de -32767 32767), svp.\n"); + ("Entrez un ajustement d'heures correct (de -32767 à 32767), svp.\n"); ladmin_log ("Ajustement des heures hors norme (commande 'banadd')." RETCODE); @@ -2049,7 +2049,7 @@ int banaddaccount (char *param) if (defaultlanguage == 'F') { printf - ("Entrez un ajustement de minutes correct (de -32767 32767), svp.\n"); + ("Entrez un ajustement de minutes correct (de -32767 à 32767), svp.\n"); ladmin_log ("Ajustement des minutes hors norme (commande 'banadd')." RETCODE); @@ -2069,7 +2069,7 @@ int banaddaccount (char *param) if (defaultlanguage == 'F') { printf - ("Entrez un ajustement de secondes correct (de -32767 32767), svp.\n"); + ("Entrez un ajustement de secondes correct (de -32767 à 32767), svp.\n"); ladmin_log ("Ajustement des secondes hors norme (commande 'banadd')." RETCODE); @@ -2088,7 +2088,7 @@ int banaddaccount (char *param) if (defaultlanguage == 'F') { ladmin_log - ("Envoi d'un requte au serveur de logins pour modifier la date d'un bannissement." + ("Envoi d'un requête au serveur de logins pour modifier la date d'un bannissement." RETCODE); } else @@ -2141,7 +2141,7 @@ int bansetaccountsub (char *name, char *date, char *time) printf ("Entrez une date et une heure svp (format: aaaa/mm/jj hh:mm:ss).\n"); printf - ("Vous pouvez aussi mettre 0 la place si vous utilisez la commande 'banset'.\n"); + ("Vous pouvez aussi mettre 0 à la place si vous utilisez la commande 'banset'.\n"); ladmin_log ("Format incorrect pour la date/heure (commande'banset' ou 'ban')." RETCODE); @@ -2310,7 +2310,7 @@ int bansetaccountsub (char *name, char *date, char *time) printf ("Entrez une date et une heure svp (format: aaaa/mm/jj hh:mm:ss).\n"); printf - ("Vous pouvez aussi mettre 0 la place si vous utilisez la commande 'banset'.\n"); + ("Vous pouvez aussi mettre 0 à la place si vous utilisez la commande 'banset'.\n"); ladmin_log ("Date incorrecte. (command 'banset' ou 'ban')." RETCODE); } @@ -2331,7 +2331,7 @@ int bansetaccountsub (char *name, char *date, char *time) if (defaultlanguage == 'F') { ladmin_log - ("Envoi d'un requte au serveur de logins pour fixer un ban." + ("Envoi d'un requête au serveur de logins pour fixer un ban." RETCODE); } else @@ -2368,13 +2368,13 @@ int banaccount (char *param) printf ("Entrez un nom de compte, une date et une heure svp.\n"); printf (": banset aaaa/mm/jj [hh:mm:ss]\n"); - printf (" banset 0 (0 = d-bani)\n"); + printf (" banset 0 (0 = dé-bani)\n"); printf (" ban/banish aaaa/mm/jj hh:mm:ss \n"); printf (" unban/unbanish \n"); - printf (" Heure par dfaut [hh:mm:ss]: 23:59:59.\n"); + printf (" Heure par défaut [hh:mm:ss]: 23:59:59.\n"); ladmin_log - ("Nombre incorrect de paramtres pour fixer un ban (commande 'banset' ou 'ban')." + ("Nombre incorrect de paramètres pour fixer un ban (commande 'banset' ou 'ban')." RETCODE); } else @@ -2418,13 +2418,13 @@ int bansetaccount (char *param) printf ("Entrez un nom de compte, une date et une heure svp.\n"); printf (": banset aaaa/mm/jj [hh:mm:ss]\n"); - printf (" banset 0 (0 = d-bani)\n"); + printf (" banset 0 (0 = dé-bani)\n"); printf (" ban/banish aaaa/mm/jj hh:mm:ss \n"); printf (" unban/unbanish \n"); - printf (" Heure par dfaut [hh:mm:ss]: 23:59:59.\n"); + printf (" Heure par défaut [hh:mm:ss]: 23:59:59.\n"); ladmin_log - ("Nombre incorrect de paramtres pour fixer un ban (commande 'banset' ou 'ban')." + ("Nombre incorrect de paramètres pour fixer un ban (commande 'banset' ou 'ban')." RETCODE); } else @@ -2470,13 +2470,13 @@ int unbanaccount (char *param) printf ("Entrez un nom de compte svp.\n"); printf (": banset aaaa/mm/jj [hh:mm:ss]\n"); - printf (" banset 0 (0 = d-bani)\n"); + printf (" banset 0 (0 = dé-bani)\n"); printf (" ban/banish aaaa/mm/jj hh:mm:ss \n"); printf (" unban/unbanish \n"); - printf (" Heure par dfaut [hh:mm:ss]: 23:59:59.\n"); + printf (" Heure par défaut [hh:mm:ss]: 23:59:59.\n"); ladmin_log - ("Nombre incorrect de paramtres pour fixer un ban (commande 'unban')." + ("Nombre incorrect de paramètres pour fixer un ban (commande 'unban')." RETCODE); } else @@ -2520,7 +2520,7 @@ int checkaccount (char *param) printf ("Entrez un nom de compte svp.\n"); printf (" check testname motdepasse\n"); ladmin_log - ("Nombre incorrect de paramtres pour tester le mot d'un passe d'un compte (commande 'check')." + ("Nombre incorrect de paramètres pour tester le mot d'un passe d'un compte (commande 'check')." RETCODE); } else @@ -2550,7 +2550,7 @@ int checkaccount (char *param) if (defaultlanguage == 'F') { ladmin_log - ("Envoi d'un requte au serveur de logins pour test un mot de passe." + ("Envoi d'un requête au serveur de logins pour test un mot de passe." RETCODE); } else @@ -2589,7 +2589,7 @@ int delaccount (char *param) printf ("Entrez un nom de compte svp.\n"); printf (" del nomtestasupprimer\n"); ladmin_log - ("Aucun nom donn pour supprimer un compte (commande 'delete')." + ("Aucun nom donné pour supprimer un compte (commande 'delete')." RETCODE); } else @@ -2614,7 +2614,7 @@ int delaccount (char *param) { if (defaultlanguage == 'F') printf - ("\033[1;36m ** Etes-vous vraiment sr de vouloir SUPPRIMER le compte [$userid]? (o/n) > \033[0m"); + ("\033[1;36m ** Etes-vous vraiment sûr de vouloir SUPPRIMER le compte [$userid]? (o/n) > \033[0m"); else printf ("\033[1;36m ** Are you really sure to DELETE account [$userid]? (y/n) > \033[0m"); @@ -2629,9 +2629,9 @@ int delaccount (char *param) { if (defaultlanguage == 'F') { - printf ("Suppression annule.\n"); + printf ("Suppression annulée.\n"); ladmin_log - ("Suppression annule par l'utilisateur (commande 'delete')." + ("Suppression annulée par l'utilisateur (commande 'delete')." RETCODE); } else @@ -2646,7 +2646,7 @@ int delaccount (char *param) if (defaultlanguage == 'F') { ladmin_log - ("Envoi d'un requte au serveur de logins pour dtruire un compte." + ("Envoi d'un requête au serveur de logins pour détruire un compte." RETCODE); } else @@ -2681,7 +2681,7 @@ int changeemail (char *param) printf ("Entrez un nom de compte et une email svp.\n"); printf (" email testname nouveauemail\n"); ladmin_log - ("Nombre incorrect de paramtres pour changer l'email d'un compte (commande 'email')." + ("Nombre incorrect de paramètres pour changer l'email d'un compte (commande 'email')." RETCODE); } else @@ -2725,10 +2725,10 @@ int changeemail (char *param) if (defaultlanguage == 'F') { printf - ("Email trop longue [%s]. Entrez une e-mail de 39 caractres maximum svp.\n", + ("Email trop longue [%s]. Entrez une e-mail de 39 caractères maximum svp.\n", email); ladmin_log - ("Email trop longue [%s]. Entrez une e-mail de 39 caractres maximum svp." + ("Email trop longue [%s]. Entrez une e-mail de 39 caractères maximum svp." RETCODE, email); } else @@ -2764,7 +2764,7 @@ int changeemail (char *param) if (defaultlanguage == 'F') { ladmin_log - ("Envoi d'un requte au serveur de logins pour changer une email." + ("Envoi d'un requête au serveur de logins pour changer une email." RETCODE); } else @@ -2789,7 +2789,7 @@ int getlogincount () if (defaultlanguage == 'F') { ladmin_log - ("Envoi d'un requte au serveur de logins pour obtenir le nombre de joueurs en jeu." + ("Envoi d'un requête au serveur de logins pour obtenir le nombre de joueurs en jeu." RETCODE); } else @@ -2826,7 +2826,7 @@ int changegmlevel (char *param) printf ("Entrez un nom de compte et un niveau de GM svp.\n"); printf (" gm nomtest 80\n"); ladmin_log - ("Nombre incorrect de paramtres pour changer le Niveau de GM d'un compte (commande 'gm')." + ("Nombre incorrect de paramètres pour changer le Niveau de GM d'un compte (commande 'gm')." RETCODE); } else @@ -2850,10 +2850,10 @@ int changegmlevel (char *param) if (defaultlanguage == 'F') { printf - ("Niveau de GM incorrect [%d]. Entrez une valeur de 0 99 svp.\n", + ("Niveau de GM incorrect [%d]. Entrez une valeur de 0 à 99 svp.\n", GM_level); ladmin_log - ("Niveau de GM incorrect [%d]. La valeur peut tre de 0 99." + ("Niveau de GM incorrect [%d]. La valeur peut être de 0 à 99." RETCODE, GM_level); } else @@ -2871,7 +2871,7 @@ int changegmlevel (char *param) if (defaultlanguage == 'F') { ladmin_log - ("Envoi d'un requte au serveur de logins pour changer un niveau de GM." + ("Envoi d'un requête au serveur de logins pour changer un niveau de GM." RETCODE); } else @@ -2907,7 +2907,7 @@ int idaccount (char *param) printf ("Entrez un nom de compte svp.\n"); printf (" id nomtest\n"); ladmin_log - ("Aucun nom donn pour rechecher l'id d'un compte (commande 'id')." + ("Aucun nom donné pour rechecher l'id d'un compte (commande 'id')." RETCODE); } else @@ -2929,7 +2929,7 @@ int idaccount (char *param) if (defaultlanguage == 'F') { ladmin_log - ("Envoi d'un requte au serveur de logins pour connatre l'id d'un compte." + ("Envoi d'un requête au serveur de logins pour connaître l'id d'un compte." RETCODE); } else @@ -2956,7 +2956,7 @@ int infoaccount (int account_id) { printf ("Entrez un id ayant une valeur positive svp.\n"); ladmin_log - ("Une valeur ngative a t donn pour trouver le compte." + ("Une valeur négative a été donné pour trouver le compte." RETCODE); } else @@ -2971,7 +2971,7 @@ int infoaccount (int account_id) if (defaultlanguage == 'F') { ladmin_log - ("Envoi d'un requte au serveur de logins pour obtenir le information d'un compte (par l'id)." + ("Envoi d'un requête au serveur de logins pour obtenir le information d'un compte (par l'id)." RETCODE); } else @@ -3046,14 +3046,14 @@ int changelanguage (char *language) { printf ("Entrez une langue svp.\n"); printf (" language english\n"); - printf (" language franais\n"); + printf (" language français\n"); ladmin_log ("La langue est vide (commande 'language')." RETCODE); } else { printf ("Please input a language.\n"); printf (" language english\n"); - printf (" language franais\n"); + printf (" language français\n"); ladmin_log ("The language is void ('language' command)." RETCODE); } return 136; @@ -3065,8 +3065,8 @@ int changelanguage (char *language) defaultlanguage = language[0]; if (defaultlanguage == 'F') { - printf ("Changement de la langue d'affichage en Franais.\n"); - ladmin_log ("Changement de la langue d'affichage en Franais." + printf ("Changement de la langue d'affichage en Français.\n"); + ladmin_log ("Changement de la langue d'affichage en Français." RETCODE); } else @@ -3080,16 +3080,16 @@ int changelanguage (char *language) if (defaultlanguage == 'F') { printf - ("Langue non paramtre (langues possibles: 'Franais' ou 'English').\n"); + ("Langue non paramétrée (langues possibles: 'Français' ou 'English').\n"); ladmin_log - ("Langue non paramtre (Franais ou English ncessaire)." + ("Langue non paramétrée (Français ou English nécessaire)." RETCODE); } else { printf - ("Undefined language (possible languages: Franais or English).\n"); - ladmin_log ("Undefined language (must be Franais or English)." + ("Undefined language (possible languages: Français or English).\n"); + ladmin_log ("Undefined language (must be Français or English)." RETCODE); } } @@ -3151,7 +3151,7 @@ int listaccount (char *param, int type) if (defaultlanguage == 'F') { ladmin_log - ("Envoi d'un requte au serveur de logins pour obtenir la liste des comptes de %d %d." + ("Envoi d'un requête au serveur de logins pour obtenir la liste des comptes de %d à %d." RETCODE, list_first, list_last); } else @@ -3223,10 +3223,10 @@ int changememo (char *param) { // memo can be void if (defaultlanguage == 'F') { - printf ("Entrez un nom de compte et un mmo svp.\n"); + printf ("Entrez un nom de compte et un mémo svp.\n"); printf (" memo nomtest nouveau memo\n"); ladmin_log - ("Nombre incorrect de paramtres pour changer le mmo d'un compte (commande 'email')." + ("Nombre incorrect de paramètres pour changer le mémo d'un compte (commande 'email')." RETCODE); } else @@ -3249,10 +3249,10 @@ int changememo (char *param) { if (defaultlanguage == 'F') { - printf ("Mmo trop long (%d caractres).\n", strlen (memo)); - printf ("Entrez un mmo de 254 caractres maximum svp.\n"); + printf ("Mémo trop long (%d caractères).\n", strlen (memo)); + printf ("Entrez un mémo de 254 caractères maximum svp.\n"); ladmin_log - ("Mmo trop long (%d caractres). Entrez un mmo de 254 caractres maximum svp." + ("Mémo trop long (%d caractères). Entrez un mémo de 254 caractères maximum svp." RETCODE, strlen (memo)); } else @@ -3269,7 +3269,7 @@ int changememo (char *param) if (defaultlanguage == 'F') { ladmin_log - ("Envoi d'un requte au serveur de logins pour changer un mmo." + ("Envoi d'un requête au serveur de logins pour changer un mémo." RETCODE); } else @@ -3299,7 +3299,7 @@ int nameaccount (int id) { printf ("Entrez un id ayant une valeur positive svp.\n"); ladmin_log - ("Id ngatif donn pour rechecher le nom d'un compte (commande 'name')." + ("Id négatif donné pour rechecher le nom d'un compte (commande 'name')." RETCODE); } else @@ -3314,7 +3314,7 @@ int nameaccount (int id) if (defaultlanguage == 'F') ladmin_log - ("Envoi d'un requte au serveur de logins pour connatre le nom d'un compte." + ("Envoi d'un requête au serveur de logins pour connaître le nom d'un compte." RETCODE); else ladmin_log ("Request to login-server to know an account name." @@ -3348,7 +3348,7 @@ int changepasswd (char *param) printf ("Entrez un nom de compte svp.\n"); printf (" passwd nomtest nouveaumotdepasse\n"); ladmin_log - ("Nombre incorrect de paramtres pour changer le mot d'un passe d'un compte (commande 'password')." + ("Nombre incorrect de paramètres pour changer le mot d'un passe d'un compte (commande 'password')." RETCODE); } else @@ -3378,7 +3378,7 @@ int changepasswd (char *param) if (defaultlanguage == 'F') { ladmin_log - ("Envoi d'un requte au serveur de logins pour changer un mot de passe." + ("Envoi d'un requête au serveur de logins pour changer un mot de passe." RETCODE); } else @@ -3408,11 +3408,11 @@ int reloadGM () if (defaultlanguage == 'F') { ladmin_log - ("Demande de recharger le fichier de configuration des GM envoye." + ("Demande de recharger le fichier de configuration des GM envoyée." RETCODE); printf - ("Demande de recharger le fichier de configuration des GM envoye.\n"); - printf ("Vrifiez les comptes GM actuels (aprs rechargement):\n"); + ("Demande de recharger le fichier de configuration des GM envoyée.\n"); + printf ("Vérifiez les comptes GM actuels (après rechargement):\n"); } else { @@ -3445,7 +3445,7 @@ int changesex (char *param) printf ("Entrez un nom de compte et un sexe svp.\n"); printf (" sex nomtest Male\n"); ladmin_log - ("Nombre incorrect de paramtres pour changer le sexe d'un compte (commande 'sex')." + ("Nombre incorrect de paramètres pour changer le sexe d'un compte (commande 'sex')." RETCODE); } else @@ -3485,7 +3485,7 @@ int changesex (char *param) if (defaultlanguage == 'F') { ladmin_log - ("Envoi d'un requte au serveur de logins pour changer un sexe." + ("Envoi d'un requête au serveur de logins pour changer un sexe." RETCODE); } else @@ -3574,9 +3574,9 @@ int changestatesub (char *name, int state, char *error_message7) if (defaultlanguage == 'F') { printf - ("Message d'erreur trop court. Entrez un message de 1-19 caractres.\n"); + ("Message d'erreur trop court. Entrez un message de 1-19 caractères.\n"); ladmin_log - ("Message d'erreur trop court. Entrez un message de 1-19 caractres." + ("Message d'erreur trop court. Entrez un message de 1-19 caractères." RETCODE); } else @@ -3594,9 +3594,9 @@ int changestatesub (char *name, int state, char *error_message7) if (defaultlanguage == 'F') { printf - ("Message d'erreur trop long. Entrez un message de 1-19 caractres.\n"); + ("Message d'erreur trop long. Entrez un message de 1-19 caractères.\n"); ladmin_log - ("Message d'erreur trop long. Entrez un message de 1-19 caractres." + ("Message d'erreur trop long. Entrez un message de 1-19 caractères." RETCODE); } else @@ -3614,7 +3614,7 @@ int changestatesub (char *name, int state, char *error_message7) if (defaultlanguage == 'F') { ladmin_log - ("Envoi d'un requte au serveur de logins pour changer un statut." + ("Envoi d'un requête au serveur de logins pour changer un statut." RETCODE); } else @@ -3657,7 +3657,7 @@ int changestate (char *param) printf (" block \n"); printf (" unblock \n"); ladmin_log - ("Nombre incorrect de paramtres pour changer le statut d'un compte (commande 'state')." + ("Nombre incorrect de paramètres pour changer le statut d'un compte (commande 'state')." RETCODE); } else @@ -3699,7 +3699,7 @@ int unblockaccount (char *param) printf (" block \n"); printf (" unblock \n"); ladmin_log - ("Nombre incorrect de paramtres pour changer le statut d'un compte (commande 'unblock')." + ("Nombre incorrect de paramètres pour changer le statut d'un compte (commande 'unblock')." RETCODE); } else @@ -3741,7 +3741,7 @@ int blockaccount (char *param) printf (" block \n"); printf (" unblock \n"); ladmin_log - ("Nombre incorrect de paramtres pour changer le statut d'un compte (commande 'block')." + ("Nombre incorrect de paramètres pour changer le statut d'un compte (commande 'block')." RETCODE); } else @@ -3785,9 +3785,9 @@ int timeaddaccount (char *param) printf (" timeadd nomtest +1m-2mn1s-6y\n"); printf (" Cette exemple ajoute 1 mois et 1 seconde, et soustrait 2 minutes\n"); - printf (" et 6 ans dans le mme temps.\n"); + printf (" et 6 ans dans le même temps.\n"); ladmin_log - ("Nombre incorrect de paramtres pour modifier une date limite d'utilisation (commande 'timeadd')." + ("Nombre incorrect de paramètres pour modifier une date limite d'utilisation (commande 'timeadd')." RETCODE); } else @@ -3867,7 +3867,7 @@ int timeaddaccount (char *param) if (defaultlanguage == 'F') { - printf (" anne: %d\n", year); + printf (" année: %d\n", year); printf (" mois: %d\n", month); printf (" jour: %d\n", day); printf (" heure: %d\n", hour); @@ -3892,8 +3892,8 @@ int timeaddaccount (char *param) printf ("Vous devez entrer un ajustement avec cette commande, svp:\n"); printf (" Valeur d'ajustement (-1, 1, +1, etc...)\n"); - printf (" Elment modifi:\n"); - printf (" a ou y: anne\n"); + printf (" Elément modifié:\n"); + printf (" a ou y: année\n"); printf (" m: mois\n"); printf (" j ou d: jour\n"); printf (" h: heure\n"); @@ -3902,7 +3902,7 @@ int timeaddaccount (char *param) printf (" timeadd nomtest +1m-2mn1s-6y\n"); printf (" Cette exemple ajoute 1 mois et 1 seconde, et soustrait 2 minutes\n"); - printf (" et 6 ans dans le mme temps.\n"); + printf (" et 6 ans dans le même temps.\n"); ladmin_log ("Aucun ajustement n'est pas un ajustement (commande 'timeadd')." RETCODE); @@ -3933,9 +3933,9 @@ int timeaddaccount (char *param) if (defaultlanguage == 'F') { printf - ("Entrez un ajustement d'annes correct (de -127 127), svp.\n"); + ("Entrez un ajustement d'années correct (de -127 à 127), svp.\n"); ladmin_log - ("Ajustement de l'anne hors norme ('timeadd' command)." + ("Ajustement de l'année hors norme ('timeadd' command)." RETCODE); } else @@ -3953,7 +3953,7 @@ int timeaddaccount (char *param) if (defaultlanguage == 'F') { printf - ("Entrez un ajustement de mois correct (de -255 255), svp.\n"); + ("Entrez un ajustement de mois correct (de -255 à 255), svp.\n"); ladmin_log ("Ajustement du mois hors norme ('timeadd' command)." RETCODE); } @@ -3972,7 +3972,7 @@ int timeaddaccount (char *param) if (defaultlanguage == 'F') { printf - ("Entrez un ajustement de jours correct (de -32767 32767), svp.\n"); + ("Entrez un ajustement de jours correct (de -32767 à 32767), svp.\n"); ladmin_log ("Ajustement des jours hors norme ('timeadd' command)." RETCODE); } @@ -3991,7 +3991,7 @@ int timeaddaccount (char *param) if (defaultlanguage == 'F') { printf - ("Entrez un ajustement d'heures correct (de -32767 32767), svp.\n"); + ("Entrez un ajustement d'heures correct (de -32767 à 32767), svp.\n"); ladmin_log ("Ajustement des heures hors norme ('timeadd' command)." RETCODE); @@ -4011,7 +4011,7 @@ int timeaddaccount (char *param) if (defaultlanguage == 'F') { printf - ("Entrez un ajustement de minutes correct (de -32767 32767), svp.\n"); + ("Entrez un ajustement de minutes correct (de -32767 à 32767), svp.\n"); ladmin_log ("Ajustement des minutes hors norme ('timeadd' command)." RETCODE); @@ -4031,7 +4031,7 @@ int timeaddaccount (char *param) if (defaultlanguage == 'F') { printf - ("Entrez un ajustement de secondes correct (de -32767 32767), svp.\n"); + ("Entrez un ajustement de secondes correct (de -32767 à 32767), svp.\n"); ladmin_log ("Ajustement des secondes hors norme ('timeadd' command)." RETCODE); @@ -4050,7 +4050,7 @@ int timeaddaccount (char *param) if (defaultlanguage == 'F') { ladmin_log - ("Envoi d'un requte au serveur de logins pour modifier une date limite d'utilisation." + ("Envoi d'un requête au serveur de logins pour modifier une date limite d'utilisation." RETCODE); } else @@ -4100,10 +4100,10 @@ int timesetaccount (char *param) printf (": timeset aaaa/mm/jj [hh:mm:ss]\n"); printf - (" timeset 0 (0 = illimit)\n"); - printf (" Heure par dfaut [hh:mm:ss]: 23:59:59.\n"); + (" timeset 0 (0 = illimité)\n"); + printf (" Heure par défaut [hh:mm:ss]: 23:59:59.\n"); ladmin_log - ("Nombre incorrect de paramtres pour fixer une date limite d'utilisation (commande 'timeset')." + ("Nombre incorrect de paramètres pour fixer une date limite d'utilisation (commande 'timeset')." RETCODE); } else @@ -4312,7 +4312,7 @@ int timesetaccount (char *param) if (defaultlanguage == 'F') { ladmin_log - ("Envoi d'un requte au serveur de logins pour fixer une date limite d'utilisation." + ("Envoi d'un requête au serveur de logins pour fixer une date limite d'utilisation." RETCODE); } else @@ -4347,7 +4347,7 @@ int whoaccount (char *param) { printf ("Entrez un nom de compte svp.\n"); printf (" who nomtest\n"); - ladmin_log ("Aucun nom n'a t donn pour trouver le compte." + ladmin_log ("Aucun nom n'a été donné pour trouver le compte." RETCODE); } else @@ -4366,7 +4366,7 @@ int whoaccount (char *param) if (defaultlanguage == 'F') { ladmin_log - ("Envoi d'un requte au serveur de logins pour obtenir le information d'un compte (par le nom)." + ("Envoi d'un requête au serveur de logins pour obtenir le information d'un compte (par le nom)." RETCODE); } else @@ -4391,7 +4391,7 @@ int checkloginversion () { if (defaultlanguage == 'F') ladmin_log - ("Envoi d'un requte au serveur de logins pour obtenir sa version." + ("Envoi d'un requête au serveur de logins pour obtenir sa version." RETCODE); else ladmin_log ("Request to login-server to obtain its version." RETCODE); @@ -4428,7 +4428,7 @@ int prompt () if (defaultlanguage == 'F') { Iprintf - ("\033[32mPour afficher les commandes, tapez 'Entre'.\033[0m\n"); + ("\033[32mPour afficher les commandes, tapez 'Entrée'.\033[0m\n"); } else Iprintf ("\033[32mTo list the commands, type 'enter'.\033[0m\n"); @@ -4530,7 +4530,7 @@ int prompt () { if (defaultlanguage == 'F') { - ladmin_log ("Commande: '%s' (sans paramtre)" RETCODE, + ladmin_log ("Commande: '%s' (sans paramètre)" RETCODE, command, parameters); } else @@ -4543,7 +4543,7 @@ int prompt () { if (defaultlanguage == 'F') { - ladmin_log ("Commande: '%s', paramtres: '%s'" RETCODE, + ladmin_log ("Commande: '%s', paramètres: '%s'" RETCODE, command, parameters); } else @@ -4783,10 +4783,10 @@ int parse_fromlogin (int fd) printf ("Erreur de login:\n"); printf (" - mot de passe incorrect,\n"); printf - (" - systme d'administration non activ, ou\n"); - printf (" - IP non autorise.\n"); + (" - système d'administration non activé, ou\n"); + printf (" - IP non autorisée.\n"); ladmin_log - ("Erreur de login: mot de passe incorrect, systme d'administration non activ, ou IP non autorise." + ("Erreur de login: mot de passe incorrect, système d'administration non activé, ou IP non autorisée." RETCODE); } else @@ -4807,8 +4807,8 @@ int parse_fromlogin (int fd) { if (defaultlanguage == 'F') { - printf ("Connexion tablie.\n"); - ladmin_log ("Connexion tablie." RETCODE); + printf ("Connexion établie.\n"); + ladmin_log ("Connexion établie." RETCODE); printf ("Lecture de la version du serveur de login...\n"); ladmin_log @@ -4858,10 +4858,10 @@ int parse_fromlogin (int fd) WFIFOSET (login_fd, 20); if (defaultlanguage == 'F') { - Iprintf ("Rception de la clef MD5.\n"); - ladmin_log ("Rception de la clef MD5." RETCODE); - Iprintf ("Envoi du mot de passe crypt...\n"); - ladmin_log ("Envoi du mot de passe crypt..." + Iprintf ("Réception de la clef MD5.\n"); + ladmin_log ("Réception de la clef MD5." RETCODE); + Iprintf ("Envoi du mot de passe crypté...\n"); + ladmin_log ("Envoi du mot de passe crypté..." RETCODE); } else @@ -4920,14 +4920,14 @@ int parse_fromlogin (int fd) if (defaultlanguage == 'F') { ladmin_log - (" Rception d'une liste des comptes vide." + (" Réception d'une liste des comptes vide." RETCODE); if (list_count == 0) - printf ("Aucun compte trouv.\n"); + printf ("Aucun compte trouvé.\n"); else if (list_count == 1) - printf ("1 compte trouv.\n"); + printf ("1 compte trouvé.\n"); else - printf ("%d comptes trouvs.\n", list_count); + printf ("%d comptes trouvés.\n", list_count); } else { @@ -4950,7 +4950,7 @@ int parse_fromlogin (int fd) { int i; if (defaultlanguage == 'F') - ladmin_log (" Rception d'une liste des comptes." + ladmin_log (" Réception d'une liste des comptes." RETCODE); else ladmin_log (" Receiving of a accounts list." @@ -5047,7 +5047,7 @@ int parse_fromlogin (int fd) // asking of the following acounts if (defaultlanguage == 'F') ladmin_log - ("Envoi d'un requte au serveur de logins pour obtenir la liste des comptes de %d %d (complment)." + ("Envoi d'un requête au serveur de logins pour obtenir la liste des comptes de %d à %d (complément)." RETCODE, list_first, list_last); else ladmin_log @@ -5070,10 +5070,10 @@ int parse_fromlogin (int fd) if (defaultlanguage == 'F') { printf - ("Echec la cration du compte [%s]. Un compte identique existe dj.\n", + ("Echec à la création du compte [%s]. Un compte identique existe déjà.\n", RFIFOP (fd, 6)); ladmin_log - ("Echec la cration du compte [%s]. Un compte identique existe dj." + ("Echec à la création du compte [%s]. Un compte identique existe déjà." RETCODE, RFIFOP (fd, 6)); } else @@ -5090,9 +5090,9 @@ int parse_fromlogin (int fd) { if (defaultlanguage == 'F') { - printf ("Compte [%s] cr avec succs [id: %d].\n", + printf ("Compte [%s] créé avec succès [id: %d].\n", RFIFOP (fd, 6), RFIFOL (fd, 2)); - ladmin_log ("Compte [%s] cr avec succs [id: %d]." + ladmin_log ("Compte [%s] créé avec succès [id: %d]." RETCODE, RFIFOP (fd, 6), RFIFOL (fd, 2)); } else @@ -5137,10 +5137,10 @@ int parse_fromlogin (int fd) { if (defaultlanguage == 'F') { - printf ("Compte [%s][id: %d] SUPPRIME avec succs.\n", + printf ("Compte [%s][id: %d] SUPPRIME avec succès.\n", RFIFOP (fd, 6), RFIFOL (fd, 2)); ladmin_log - ("Compte [%s][id: %d] SUPPRIME avec succs." + ("Compte [%s][id: %d] SUPPRIME avec succès." RETCODE, RFIFOP (fd, 6), RFIFOL (fd, 2)); } else @@ -5189,10 +5189,10 @@ int parse_fromlogin (int fd) if (defaultlanguage == 'F') { printf - ("Modification du mot de passe du compte [%s][id: %d] russie.\n", + ("Modification du mot de passe du compte [%s][id: %d] réussie.\n", RFIFOP (fd, 6), RFIFOL (fd, 2)); ladmin_log - ("Modification du mot de passe du compte [%s][id: %d] russie." + ("Modification du mot de passe du compte [%s][id: %d] réussie." RETCODE, RFIFOP (fd, 6), RFIFOL (fd, 2)); } else @@ -5239,7 +5239,7 @@ int parse_fromlogin (int fd) if (defaultlanguage == 'F') { sprintf (tmpstr, - "Statut du compte [%s] chang avec succs en [", + "Statut du compte [%s] changé avec succès en [", RFIFOP (fd, 6)); } else @@ -5309,7 +5309,7 @@ int parse_fromlogin (int fd) if (defaultlanguage == 'F') { ladmin_log - (" Rception du nombre de joueurs en ligne." + (" Réception du nombre de joueurs en ligne." RETCODE); } else @@ -5324,7 +5324,7 @@ int parse_fromlogin (int fd) if (defaultlanguage == 'F') { printf - (" Aucun serveur n'est connect au login serveur.\n"); + (" Aucun serveur n'est connecté au login serveur.\n"); } else { @@ -5387,10 +5387,10 @@ int parse_fromlogin (int fd) if (defaultlanguage == 'F') { printf - ("Le mot de passe donn correspond bien au compte [%s][id: %d].\n", + ("Le mot de passe donné correspond bien au compte [%s][id: %d].\n", RFIFOP (fd, 6), RFIFOL (fd, 2)); ladmin_log - ("Le mot de passe donn correspond bien au compte [%s][id: %d]." + ("Le mot de passe donné correspond bien au compte [%s][id: %d]." RETCODE, RFIFOP (fd, 6), RFIFOL (fd, 2)); } else @@ -5418,10 +5418,10 @@ int parse_fromlogin (int fd) ("Echec de la modification du sexe du compte [%s].\n", RFIFOP (fd, 6)); printf - ("Le compte [%s] n'existe pas ou le sexe est dj celui demand.\n", + ("Le compte [%s] n'existe pas ou le sexe est déjà celui demandé.\n", RFIFOP (fd, 6)); ladmin_log - ("Echec de la modification du sexe du compte. Le compte [%s] n'existe pas ou le sexe est dj celui demand." + ("Echec de la modification du sexe du compte. Le compte [%s] n'existe pas ou le sexe est déjà celui demandé." RETCODE, RFIFOP (fd, 6)); } else @@ -5441,10 +5441,10 @@ int parse_fromlogin (int fd) if (defaultlanguage == 'F') { printf - ("Sexe du compte [%s][id: %d] chang avec succs.\n", + ("Sexe du compte [%s][id: %d] changé avec succès.\n", RFIFOP (fd, 6), RFIFOL (fd, 2)); ladmin_log - ("Sexe du compte [%s][id: %d] chang avec succs." + ("Sexe du compte [%s][id: %d] changé avec succès." RETCODE, RFIFOP (fd, 6), RFIFOL (fd, 2)); } else @@ -5472,12 +5472,12 @@ int parse_fromlogin (int fd) ("Echec de la modification du niveau de GM du compte [%s].\n", RFIFOP (fd, 6)); printf - ("Le compte [%s] n'existe pas, le niveau de GM est dj celui demand\n", + ("Le compte [%s] n'existe pas, le niveau de GM est déjà celui demandé\n", RFIFOP (fd, 6)); printf ("ou il est impossible de modifier le fichier des comptes GM.\n"); ladmin_log - ("Echec de la modification du niveau de GM du compte. Le compte [%s] n'existe pas, le niveau de GM est dj celui demand ou il est impossible de modifier le fichier des comptes GM." + ("Echec de la modification du niveau de GM du compte. Le compte [%s] n'existe pas, le niveau de GM est déjà celui demandé ou il est impossible de modifier le fichier des comptes GM." RETCODE, RFIFOP (fd, 6)); } else @@ -5499,10 +5499,10 @@ int parse_fromlogin (int fd) if (defaultlanguage == 'F') { printf - ("Niveau de GM du compte [%s][id: %d] chang avec succs.\n", + ("Niveau de GM du compte [%s][id: %d] changé avec succès.\n", RFIFOP (fd, 6), RFIFOL (fd, 2)); ladmin_log - ("Niveau de GM du compte [%s][id: %d] chang avec succs." + ("Niveau de GM du compte [%s][id: %d] changé avec succès." RETCODE, RFIFOP (fd, 6), RFIFOL (fd, 2)); } else @@ -5551,10 +5551,10 @@ int parse_fromlogin (int fd) if (defaultlanguage == 'F') { printf - ("Modification de l'e-mail du compte [%s][id: %d] russie.\n", + ("Modification de l'e-mail du compte [%s][id: %d] réussie.\n", RFIFOP (fd, 6), RFIFOL (fd, 2)); ladmin_log - ("Modification de l'e-mail du compte [%s][id: %d] russie." + ("Modification de l'e-mail du compte [%s][id: %d] réussie." RETCODE, RFIFOP (fd, 6), RFIFOL (fd, 2)); } else @@ -5579,10 +5579,10 @@ int parse_fromlogin (int fd) if (defaultlanguage == 'F') { printf - ("Echec du changement du mmo du compte [%s]. Le compte n'existe pas.\n", + ("Echec du changement du mémo du compte [%s]. Le compte n'existe pas.\n", RFIFOP (fd, 6)); ladmin_log - ("Echec du changement du mmo du compte [%s]. Le compte n'existe pas." + ("Echec du changement du mémo du compte [%s]. Le compte n'existe pas." RETCODE, RFIFOP (fd, 6)); } else @@ -5600,10 +5600,10 @@ int parse_fromlogin (int fd) if (defaultlanguage == 'F') { printf - ("Mmo du compte [%s][id: %d] chang avec succs.\n", + ("Mémo du compte [%s][id: %d] changé avec succès.\n", RFIFOP (fd, 6), RFIFOL (fd, 2)); ladmin_log - ("Mmo du compte [%s][id: %d] chang avec succs." + ("Mémo du compte [%s][id: %d] changé avec succès." RETCODE, RFIFOP (fd, 6), RFIFOL (fd, 2)); } else @@ -5718,10 +5718,10 @@ int parse_fromlogin (int fd) if (defaultlanguage == 'F') { printf - ("Echec du changement de la validit du compte [%s]. Le compte n'existe pas.\n", + ("Echec du changement de la validité du compte [%s]. Le compte n'existe pas.\n", RFIFOP (fd, 6)); ladmin_log - ("Echec du changement de la validit du compte [%s]. Le compte n'existe pas." + ("Echec du changement de la validité du compte [%s]. Le compte n'existe pas." RETCODE, RFIFOP (fd, 6)); } else @@ -5742,10 +5742,10 @@ int parse_fromlogin (int fd) if (defaultlanguage == 'F') { printf - ("Limite de validit du compte [%s][id: %d] change avec succs en [illimit].\n", + ("Limite de validité du compte [%s][id: %d] changée avec succès en [illimité].\n", RFIFOP (fd, 6), RFIFOL (fd, 2)); ladmin_log - ("Limite de validit du compte [%s][id: %d] change avec succs en [illimit]." + ("Limite de validité du compte [%s][id: %d] changée avec succès en [illimité]." RETCODE, RFIFOP (fd, 6), RFIFOL (fd, 2)); } else @@ -5766,10 +5766,10 @@ int parse_fromlogin (int fd) if (defaultlanguage == 'F') { printf - ("Limite de validit du compte [%s][id: %d] change avec succs pour tre jusqu'au %s.\n", + ("Limite de validité du compte [%s][id: %d] changée avec succès pour être jusqu'au %s.\n", RFIFOP (fd, 6), RFIFOL (fd, 2), tmpstr); ladmin_log - ("Limite de validit du compte [%s][id: %d] change avec succs pour tre jusqu'au %s." + ("Limite de validité du compte [%s][id: %d] changée avec succès pour être jusqu'au %s." RETCODE, RFIFOP (fd, 6), RFIFOL (fd, 2), tmpstr); } @@ -5821,10 +5821,10 @@ int parse_fromlogin (int fd) if (defaultlanguage == 'F') { printf - ("Date finale de banissement du compte [%s][id: %d] change avec succs en [d-bannie].\n", + ("Date finale de banissement du compte [%s][id: %d] changée avec succès en [dé-bannie].\n", RFIFOP (fd, 6), RFIFOL (fd, 2)); ladmin_log - ("Date finale de banissement du compte [%s][id: %d] change avec succs en [d-bannie]." + ("Date finale de banissement du compte [%s][id: %d] changée avec succès en [dé-bannie]." RETCODE, RFIFOP (fd, 6), RFIFOL (fd, 2)); } else @@ -5845,10 +5845,10 @@ int parse_fromlogin (int fd) if (defaultlanguage == 'F') { printf - ("Date finale de banissement du compte [%s][id: %d] change avec succs pour tre jusqu'au %s.\n", + ("Date finale de banissement du compte [%s][id: %d] changée avec succès pour être jusqu'au %s.\n", RFIFOP (fd, 6), RFIFOL (fd, 2), tmpstr); ladmin_log - ("Date finale de banissement du compte [%s][id: %d] change avec succs pour tre jusqu'au %s." + ("Date finale de banissement du compte [%s][id: %d] changée avec succès pour être jusqu'au %s." RETCODE, RFIFOP (fd, 6), RFIFOL (fd, 2), tmpstr); } @@ -5900,10 +5900,10 @@ int parse_fromlogin (int fd) if (defaultlanguage == 'F') { printf - ("Date finale de banissement du compte [%s][id: %d] change avec succs en [d-bannie].\n", + ("Date finale de banissement du compte [%s][id: %d] changée avec succès en [dé-bannie].\n", RFIFOP (fd, 6), RFIFOL (fd, 2)); ladmin_log - ("Date finale de banissement du compte [%s][id: %d] change avec succs en [d-bannie]." + ("Date finale de banissement du compte [%s][id: %d] changée avec succès en [dé-bannie]." RETCODE, RFIFOP (fd, 6), RFIFOL (fd, 2)); } else @@ -5924,10 +5924,10 @@ int parse_fromlogin (int fd) if (defaultlanguage == 'F') { printf - ("Date finale de banissement du compte [%s][id: %d] change avec succs pour tre jusqu'au %s.\n", + ("Date finale de banissement du compte [%s][id: %d] changée avec succès pour être jusqu'au %s.\n", RFIFOP (fd, 6), RFIFOL (fd, 2), tmpstr); ladmin_log - ("Date finale de banissement du compte [%s][id: %d] change avec succs pour tre jusqu'au %s." + ("Date finale de banissement du compte [%s][id: %d] changée avec succès pour être jusqu'au %s." RETCODE, RFIFOP (fd, 6), RFIFOL (fd, 2), tmpstr); } @@ -5974,9 +5974,9 @@ int parse_fromlogin (int fd) if (defaultlanguage == 'F') { printf - ("Message transmis au server de logins avec succs.\n"); + ("Message transmis au server de logins avec succès.\n"); ladmin_log - ("Message transmis au server de logins avec succs." + ("Message transmis au server de logins avec succès." RETCODE); } else @@ -6000,10 +6000,10 @@ int parse_fromlogin (int fd) if (defaultlanguage == 'F') { printf - ("Echec du changement de la validit du compte [%s]. Le compte n'existe pas.\n", + ("Echec du changement de la validité du compte [%s]. Le compte n'existe pas.\n", RFIFOP (fd, 6)); ladmin_log - ("Echec du changement de la validit du compte [%s]. Le compte n'existe pas." + ("Echec du changement de la validité du compte [%s]. Le compte n'existe pas." RETCODE, RFIFOP (fd, 6)); } else @@ -6024,14 +6024,14 @@ int parse_fromlogin (int fd) if (defaultlanguage == 'F') { printf - ("Limite de validit du compte [%s][id: %d] inchange.\n", + ("Limite de validité du compte [%s][id: %d] inchangée.\n", RFIFOP (fd, 6), RFIFOL (fd, 2)); printf - ("Le compte a une validit illimite ou\n"); + ("Le compte a une validité illimitée ou\n"); printf - ("la modification est impossible avec les ajustements demands.\n"); + ("la modification est impossible avec les ajustements demandés.\n"); ladmin_log - ("Limite de validit du compte [%s][id: %d] inchange. Le compte a une validit illimite ou la modification est impossible avec les ajustements demands." + ("Limite de validité du compte [%s][id: %d] inchangée. Le compte a une validité illimitée ou la modification est impossible avec les ajustements demandés." RETCODE, RFIFOP (fd, 6), RFIFOL (fd, 2)); } else @@ -6056,10 +6056,10 @@ int parse_fromlogin (int fd) if (defaultlanguage == 'F') { printf - ("Limite de validit du compte [%s][id: %d] change avec succs pour tre jusqu'au %s.\n", + ("Limite de validité du compte [%s][id: %d] changée avec succès pour être jusqu'au %s.\n", RFIFOP (fd, 6), RFIFOL (fd, 2), tmpstr); ladmin_log - ("Limite de validit du compte [%s][id: %d] change avec succs pour tre jusqu'au %s." + ("Limite de validité du compte [%s][id: %d] changée avec succès pour être jusqu'au %s." RETCODE, RFIFOP (fd, 6), RFIFOL (fd, 2), tmpstr); } @@ -6150,10 +6150,10 @@ int parse_fromlogin (int fd) if (defaultlanguage == 'F') { ladmin_log - ("Rception d'information concernant un compte." + ("Réception d'information concernant un compte." RETCODE); printf - ("Le compte a les caractristiques suivantes:\n"); + ("Le compte a les caractéristiques suivantes:\n"); } else { @@ -6267,18 +6267,18 @@ int parse_fromlogin (int fd) else printf (" Compteur: %d connexion.\n", RFIFOL (fd, 32)); - printf (" Dernire connexion le: %s (ip: %s)\n", + printf (" Dernière connexion le: %s (ip: %s)\n", lastlogin, last_ip); if (connect_until_time == 0) { - printf (" Limite de validit: illimit.\n"); + printf (" Limite de validité: illimité.\n"); } else { char tmpstr[128]; strftime (tmpstr, 24, date_format, localtime (&connect_until_time)); - printf (" Limite de validit: jusqu'au %s.\n", + printf (" Limite de validité: jusqu'au %s.\n", tmpstr); } } @@ -6402,7 +6402,7 @@ int Connect_login_server () //------------------------------------------------- // Return numerical value of a switch configuration -// on/off, english, franais, deutsch, espaol +// on/off, english, français, deutsch, español //------------------------------------------------- int config_switch (const char *str) { @@ -6430,7 +6430,7 @@ int ladmin_config_read (const char *cfgName) { if (defaultlanguage == 'F') { - printf ("\033[0mFichier de configuration (%s) non trouv.\n", + printf ("\033[0mFichier de configuration (%s) non trouvé.\n", cfgName); } else @@ -6443,7 +6443,7 @@ int ladmin_config_read (const char *cfgName) if (defaultlanguage == 'F') { Iprintf - ("\033[0m---Dbut de lecture du fichier de configuration Ladmin (%s)\n", + ("\033[0m---Début de lecture du fichier de configuration Ladmin (%s)\n", cfgName); } else @@ -6555,7 +6555,7 @@ int ladmin_config_read (const char *cfgName) if (defaultlanguage == 'F') { - Iprintf ("---Lecture du fichier de configuration Ladmin termine.\n"); + Iprintf ("---Lecture du fichier de configuration Ladmin terminée.\n"); } else { @@ -6621,7 +6621,7 @@ int do_init (int argc, char **argv) if (defaultlanguage == 'F') { - Iprintf ("Outil d'administration distance de eAthena.\n"); + Iprintf ("Outil d'administration à distance de eAthena.\n"); Iprintf ("(pour eAthena version %d.%d.%d.)\n", ATHENA_MAJOR_VERSION, ATHENA_MINOR_VERSION, ATHENA_REVISION); } @@ -6634,8 +6634,8 @@ int do_init (int argc, char **argv) if (defaultlanguage == 'F') { - ladmin_log ("Ladmin est prt." RETCODE); - Iprintf ("Ladmin est \033[1;32mprt\033[0m.\n\n"); + ladmin_log ("Ladmin est prêt." RETCODE); + Iprintf ("Ladmin est \033[1;32mprêt\033[0m.\n\n"); } else { diff --git a/src/txt-converter/char/char-converter.c b/src/txt-converter/char/char-converter.c index 8b4336f..9f292c0 100644 --- a/src/txt-converter/char/char-converter.c +++ b/src/txt-converter/char/char-converter.c @@ -80,7 +80,7 @@ int char_num, char_max; int max_connect_user = 0; int autosave_interval = DEFAULT_AUTOSAVE_INTERVAL; -// ʱ ġ(conf Ϸκ 缳 ) +// 段奄 是帖(conf 督析稽採斗 仙竺舛 亜管) struct point start_point = { "new_1-1.gat", 53, 111 }; int inter_pet_fromstr (char *str, struct s_pet *p) @@ -406,7 +406,7 @@ int mmo_char_fromstr (char *str, struct mmo_charstatus *p) } if (str[next] == '\n' || str[next] == '\r') - return 1; // VKf[^ + return 1; // 新規データ next++; @@ -521,7 +521,7 @@ int mmo_char_fromstr (char *str, struct mmo_charstatus *p) for (i = 0; str[next] && str[next] != '\t' && str[next] != '\n' && str[next] != '\r'; i++) - { // global_regȑOathena.txt݊̂߈ꉞ'\n'`FbN + { // global_reg実装以前のathena.txt互換のため一応'\n'チェック set = sscanf (str + next, "%[^,],%d%n", p->global_reg[i].str, &p->global_reg[i].value, &len); -- cgit v1.2.3-70-g09d2 From ee705b39fdbf0169613da263d12ae6694e5eee68 Mon Sep 17 00:00:00 2001 From: Ben Longbons Date: Thu, 17 Mar 2011 12:31:55 -0700 Subject: Remove duplicate md5calc --- src/ladmin/Makefile | 5 +- src/ladmin/ladmin.c | 2 +- src/ladmin/md5calc.c | 333 --------------------------------------------------- src/ladmin/md5calc.h | 11 -- 4 files changed, 3 insertions(+), 348 deletions(-) delete mode 100644 src/ladmin/md5calc.c delete mode 100644 src/ladmin/md5calc.h diff --git a/src/ladmin/Makefile b/src/ladmin/Makefile index 9199951..cb7e764 100644 --- a/src/ladmin/Makefile +++ b/src/ladmin/Makefile @@ -7,9 +7,8 @@ sql: ladmin COMMON_OBJ = ../common/core.o ../common/socket.o ../common/timer.o ../common/db.o ../common/malloc.o ../common/mt_rand.o COMMON_H = ../common/core.h ../common/socket.h ../common/timer.h ../common/mmo.h ../common/version.h ../common/db.h ../common/malloc.h ../common/mt_rand.h -ladmin: ladmin.o md5calc.o $(COMMON_OBJ) -ladmin.o: ladmin.c ladmin.h md5calc.h $(COMMON_H) -md5calc.o: md5calc.c md5calc.h +ladmin: ladmin.o ../common/md5calc.o $(COMMON_OBJ) +ladmin.o: ladmin.c ladmin.h ../common/md5calc.h $(COMMON_H) clean: rm -f *.o ladmin diff --git a/src/ladmin/ladmin.c b/src/ladmin/ladmin.c index d7f4f5f..4eb3e7a 100644 --- a/src/ladmin/ladmin.c +++ b/src/ladmin/ladmin.c @@ -29,7 +29,7 @@ #include "../common/mmo.h" #ifdef PASSWORDENC -#include "md5calc.h" +#include "../common/md5calc.h" #endif #ifdef MEMWATCH diff --git a/src/ladmin/md5calc.c b/src/ladmin/md5calc.c deleted file mode 100644 index ec1d8ec..0000000 --- a/src/ladmin/md5calc.c +++ /dev/null @@ -1,333 +0,0 @@ -// $Id: md5calc.c,v 1.1.1.1 2004/09/10 17:26:54 MagicalTux Exp $ -/*********************************************************** - * md5 calculation algorithm - * - * The source code referred to the following URL. - * http://www.geocities.co.jp/SiliconValley-Oakland/8878/lab17/lab17.html - * - ***********************************************************/ - -#include "md5calc.h" -#include -#include -#include "../common/mt_rand.h" - -#ifndef UINT_MAX -#define UINT_MAX 4294967295U -#endif - -// Global variable -static unsigned int *pX; - -// Stirng Table -static const unsigned int T[] = { - 0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee, //0 - 0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501, //4 - 0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be, //8 - 0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821, //12 - 0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa, //16 - 0xd62f105d, 0x2441453, 0xd8a1e681, 0xe7d3fbc8, //20 - 0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed, //24 - 0xa9e3e905, 0xfcefa3f8, 0x676f02d9, 0x8d2a4c8a, //28 - 0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c, //32 - 0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70, //36 - 0x289b7ec6, 0xeaa127fa, 0xd4ef3085, 0x4881d05, //40 - 0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665, //44 - 0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039, //48 - 0x655b59c3, 0x8f0ccc92, 0xffeff47d, 0x85845dd1, //52 - 0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1, //56 - 0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391 //60 -}; - -// ROTATE_LEFT The left is made to rotate x [ n-bit ]. This is diverted as it is from RFC. -#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) - -// The function used for other calculation -static unsigned int F (unsigned int X, unsigned int Y, unsigned int Z) -{ - return (X & Y) | (~X & Z); -} - -static unsigned int G (unsigned int X, unsigned int Y, unsigned int Z) -{ - return (X & Z) | (Y & ~Z); -} - -static unsigned int H (unsigned int X, unsigned int Y, unsigned int Z) -{ - return X ^ Y ^ Z; -} - -static unsigned int I (unsigned int X, unsigned int Y, unsigned int Z) -{ - return Y ^ (X | ~Z); -} - -static unsigned int Round (unsigned int a, unsigned int b, unsigned int FGHI, - unsigned int k, unsigned int s, unsigned int i) -{ - return b + ROTATE_LEFT (a + FGHI + pX[k] + T[i], s); -} - -static void Round1 (unsigned int *a, unsigned int b, unsigned int c, - unsigned int d, unsigned int k, unsigned int s, - unsigned int i) -{ - *a = Round (*a, b, F (b, c, d), k, s, i); -} - -static void Round2 (unsigned int *a, unsigned int b, unsigned int c, - unsigned int d, unsigned int k, unsigned int s, - unsigned int i) -{ - *a = Round (*a, b, G (b, c, d), k, s, i); -} - -static void Round3 (unsigned int *a, unsigned int b, unsigned int c, - unsigned int d, unsigned int k, unsigned int s, - unsigned int i) -{ - *a = Round (*a, b, H (b, c, d), k, s, i); -} - -static void Round4 (unsigned int *a, unsigned int b, unsigned int c, - unsigned int d, unsigned int k, unsigned int s, - unsigned int i) -{ - *a = Round (*a, b, I (b, c, d), k, s, i); -} - -static void MD5_Round_Calculate (const unsigned char *block, - unsigned int *A2, unsigned int *B2, - unsigned int *C2, unsigned int *D2) -{ - //create X It is since it is required. - unsigned int X[16]; //512bit 64byte - int j, k; - - //Save A as AA, B as BB, C as CC, and and D as DD (saving of A, B, C, and D) - unsigned int A = *A2, B = *B2, C = *C2, D = *D2; - unsigned int AA = A, BB = B, CC = C, DD = D; - - //It is a large region variable reluctantly because of calculation of a round. . . for Round1...4 - pX = X; - - //Copy block(padding_message) i into X - for (j = 0, k = 0; j < 64; j += 4, k++) - X[k] = ((unsigned int) block[j]) // 8byte*4 -> 32byte conversion - | (((unsigned int) block[j + 1]) << 8) // A function called Decode as used in the field of RFC - | (((unsigned int) block[j + 2]) << 16) - | (((unsigned int) block[j + 3]) << 24); - - //Round 1 - Round1 (&A, B, C, D, 0, 7, 0); - Round1 (&D, A, B, C, 1, 12, 1); - Round1 (&C, D, A, B, 2, 17, 2); - Round1 (&B, C, D, A, 3, 22, 3); - Round1 (&A, B, C, D, 4, 7, 4); - Round1 (&D, A, B, C, 5, 12, 5); - Round1 (&C, D, A, B, 6, 17, 6); - Round1 (&B, C, D, A, 7, 22, 7); - Round1 (&A, B, C, D, 8, 7, 8); - Round1 (&D, A, B, C, 9, 12, 9); - Round1 (&C, D, A, B, 10, 17, 10); - Round1 (&B, C, D, A, 11, 22, 11); - Round1 (&A, B, C, D, 12, 7, 12); - Round1 (&D, A, B, C, 13, 12, 13); - Round1 (&C, D, A, B, 14, 17, 14); - Round1 (&B, C, D, A, 15, 22, 15); - - //Round 2 - Round2 (&A, B, C, D, 1, 5, 16); - Round2 (&D, A, B, C, 6, 9, 17); - Round2 (&C, D, A, B, 11, 14, 18); - Round2 (&B, C, D, A, 0, 20, 19); - Round2 (&A, B, C, D, 5, 5, 20); - Round2 (&D, A, B, C, 10, 9, 21); - Round2 (&C, D, A, B, 15, 14, 22); - Round2 (&B, C, D, A, 4, 20, 23); - Round2 (&A, B, C, D, 9, 5, 24); - Round2 (&D, A, B, C, 14, 9, 25); - Round2 (&C, D, A, B, 3, 14, 26); - Round2 (&B, C, D, A, 8, 20, 27); - Round2 (&A, B, C, D, 13, 5, 28); - Round2 (&D, A, B, C, 2, 9, 29); - Round2 (&C, D, A, B, 7, 14, 30); - Round2 (&B, C, D, A, 12, 20, 31); - - //Round 3 - Round3 (&A, B, C, D, 5, 4, 32); - Round3 (&D, A, B, C, 8, 11, 33); - Round3 (&C, D, A, B, 11, 16, 34); - Round3 (&B, C, D, A, 14, 23, 35); - Round3 (&A, B, C, D, 1, 4, 36); - Round3 (&D, A, B, C, 4, 11, 37); - Round3 (&C, D, A, B, 7, 16, 38); - Round3 (&B, C, D, A, 10, 23, 39); - Round3 (&A, B, C, D, 13, 4, 40); - Round3 (&D, A, B, C, 0, 11, 41); - Round3 (&C, D, A, B, 3, 16, 42); - Round3 (&B, C, D, A, 6, 23, 43); - Round3 (&A, B, C, D, 9, 4, 44); - Round3 (&D, A, B, C, 12, 11, 45); - Round3 (&C, D, A, B, 15, 16, 46); - Round3 (&B, C, D, A, 2, 23, 47); - - //Round 4 - Round4 (&A, B, C, D, 0, 6, 48); - Round4 (&D, A, B, C, 7, 10, 49); - Round4 (&C, D, A, B, 14, 15, 50); - Round4 (&B, C, D, A, 5, 21, 51); - Round4 (&A, B, C, D, 12, 6, 52); - Round4 (&D, A, B, C, 3, 10, 53); - Round4 (&C, D, A, B, 10, 15, 54); - Round4 (&B, C, D, A, 1, 21, 55); - Round4 (&A, B, C, D, 8, 6, 56); - Round4 (&D, A, B, C, 15, 10, 57); - Round4 (&C, D, A, B, 6, 15, 58); - Round4 (&B, C, D, A, 13, 21, 59); - Round4 (&A, B, C, D, 4, 6, 60); - Round4 (&D, A, B, C, 11, 10, 61); - Round4 (&C, D, A, B, 2, 15, 62); - Round4 (&B, C, D, A, 9, 21, 63); - - // Then perform the following additions. (let's add) - *A2 = A + AA; - *B2 = B + BB; - *C2 = C + CC; - *D2 = D + DD; - - //The clearance of confidential information - memset (pX, 0, sizeof (X)); -} - -//------------------------------------------------------------------- -// The function for the exteriors - -/** output is the coded binary in the character sequence which wants to code string. */ -void MD5_String2binary (const char *string, char *output) -{ -//var - /*8bit */ - unsigned char padding_message[64]; //Extended message 512bit 64byte - unsigned char *pstring; //The position of string in the present scanning notes is held. - -// unsigned char digest[16]; - /*32bit */ - unsigned int string_byte_len, //The byte chief of string is held. - string_bit_len, //The bit length of string is held. - copy_len, //The number of bytes which is used by 1-3 and which remained - msg_digest[4]; //Message digest 128bit 4byte - unsigned int *A = &msg_digest[0], //The message digest in accordance with RFC (reference) - *B = &msg_digest[1], *C = &msg_digest[2], *D = &msg_digest[3]; - int i; - -//prog - //Step 3.Initialize MD Buffer (although it is the initialization; step 3 of A, B, C, and D -- unavoidable -- a head) - *A = 0x67452301; - *B = 0xefcdab89; - *C = 0x98badcfe; - *D = 0x10325476; - - //Step 1.Append Padding Bits (extension of a mark bit) - //1-1 - string_byte_len = strlen (string); //The byte chief of a character sequence is acquired. - pstring = (unsigned char *) string; //The position of the present character sequence is set. - - //1-2 Repeat calculation until length becomes less than 64 bytes. - for (i = string_byte_len; 64 <= i; i -= 64, pstring += 64) - MD5_Round_Calculate (pstring, A, B, C, D); - - //1-3 - copy_len = string_byte_len % 64; //The number of bytes which remained is computed. - strncpy ((char *) padding_message, (char *) pstring, copy_len); //A message is copied to an extended bit sequence. - memset (padding_message + copy_len, 0, 64 - copy_len); //It buries by 0 until it becomes extended bit length. - padding_message[copy_len] |= 0x80; //The next of a message is 1. - - //1-4 - //If 56 bytes or more (less than 64 bytes) of remainder becomes, it will calculate by extending to 64 bytes. - if (56 <= copy_len) - { - MD5_Round_Calculate (padding_message, A, B, C, D); - memset (padding_message, 0, 56); //56 bytes is newly fill uped with 0. - } - - //Step 2.Append Length (the information on length is added) - string_bit_len = string_byte_len * 8; //From the byte chief to bit length (32 bytes of low rank) - memcpy (&padding_message[56], &string_bit_len, 4); //32 bytes of low rank is set. - - //When bit length cannot be expressed in 32 bytes of low rank, it is a beam raising to a higher rank. - if (UINT_MAX / 8 < string_byte_len) - { - unsigned int high = (string_byte_len - UINT_MAX / 8) * 8; - memcpy (&padding_message[60], &high, 4); - } - else - memset (&padding_message[60], 0, 4); //In this case, it is good for a higher rank at 0. - - //Step 4.Process Message in 16-Word Blocks (calculation of MD5) - MD5_Round_Calculate (padding_message, A, B, C, D); - - //Step 5.Output (output) - memcpy (output, msg_digest, 16); -// memcpy (digest, msg_digest, and 16); //8 byte*4 < - 32byte conversion A function called Encode as used in the field of RFC -/* sprintf(output, - "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", - digest[ 0], digest[ 1], digest[ 2], digest[ 3], - digest[ 4], digest[ 5], digest[ 6], digest[ 7], - digest[ 8], digest[ 9], digest[10], digest[11], - digest[12], digest[13], digest[14], digest[15]);*/ -} - -/** output is the coded character sequence in the character sequence which wants to code string. */ -void MD5_String (const char *string, char *output) -{ - unsigned char digest[16]; - - MD5_String2binary (string, digest); - sprintf (output, - "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", - digest[0], digest[1], digest[2], digest[3], - digest[4], digest[5], digest[6], digest[7], - digest[8], digest[9], digest[10], digest[11], - digest[12], digest[13], digest[14], digest[15]); -} - -// Hash a password with a salt. -char *MD5_saltcrypt(const char *key, const char *salt) -{ - char buf[66], *sbuf = buf+32; - static char obuf[33]; - - // hash the key then the salt - // buf ends up as a 64char null terminated string - MD5_String(key, buf); - MD5_String(salt, sbuf); - - // Hash the buffer back into sbuf - MD5_String(buf, sbuf); - - snprintf(obuf, 32, "!%s$%s", salt, sbuf); - return(obuf); -} - -char *make_salt() { - static char salt[6]; - int i; - for (i=0; i<5; i++) - salt[i] = (char)((mt_rand() % 78) + 48); - salt[5] = '\0'; - return(salt); -} - -int pass_ok(const char *password, const char *crypted) { - char buf[40], *salt=buf+1; - - strncpy(buf, crypted, 40); - *strchr(buf, '$') = '\0'; - - if (!strcmp(crypted, MD5_saltcrypt(password, salt))) - return(1); - - return(0); -} diff --git a/src/ladmin/md5calc.h b/src/ladmin/md5calc.h deleted file mode 100644 index 3571466..0000000 --- a/src/ladmin/md5calc.h +++ /dev/null @@ -1,11 +0,0 @@ -// $Id: md5calc.h,v 1.1.1.1 2004/09/10 17:26:54 MagicalTux Exp $ -#ifndef _MD5CALC_H_ -#define _MD5CALC_H_ - -void MD5_String (const char *string, char *output); -void MD5_String2binary (const char *string, char *output); -char *MD5_saltcrypt(const char *key, const char *salt); -char *make_salt(); -int pass_ok(const char *password, const char *crypted); - -#endif -- cgit v1.2.3-70-g09d2 From 2f2e6b497412abebb3b55be68f05e3751a46fc9b Mon Sep 17 00:00:00 2001 From: Ben Longbons Date: Thu, 17 Mar 2011 12:36:14 -0700 Subject: Delete nonfunctional sql versions --- src/char_sql/Makefile | 22 - src/char_sql/char.c | 3750 ----------------------------- src/char_sql/char.h | 87 - src/char_sql/int_guild.c | 2111 ---------------- src/char_sql/int_guild.h | 10 - src/char_sql/int_party.c | 935 ------- src/char_sql/int_party.h | 8 - src/char_sql/int_pet.c | 383 --- src/char_sql/int_pet.h | 12 - src/char_sql/int_storage.c | 441 ---- src/char_sql/int_storage.h | 12 - src/char_sql/inter.c | 662 ----- src/char_sql/inter.h | 43 - src/char_sql/itemdb.c | 265 -- src/char_sql/itemdb.h | 35 - src/char_sql/make.sh | 11 - src/char_sql/readme.txt | 250 -- src/char_sql/strlib.c | 89 - src/char_sql/strlib.h | 10 - src/login_sql/Makefile | 19 - src/login_sql/login.c | 2073 ---------------- src/login_sql/login.h | 42 - src/login_sql/make.sh | 6 - src/login_sql/md5calc.c | 292 --- src/login_sql/md5calc.h | 7 - src/login_sql/readme.txt | 120 - src/login_sql/strlib.c | 64 - src/login_sql/strlib.h | 9 - src/login_sql/timer.h | 45 - src/txt-converter/char/Makefile | 15 - src/txt-converter/char/char-converter.c | 971 -------- src/txt-converter/char/char.h | 39 - src/txt-converter/char/int_guild.h | 10 - src/txt-converter/char/int_party.h | 11 - src/txt-converter/char/int_pet.h | 12 - src/txt-converter/char/int_storage.h | 11 - src/txt-converter/char/inter.h | 27 - src/txt-converter/char/strlib.c | 76 - src/txt-converter/char/strlib.h | 9 - src/txt-converter/common/mmo.h | 300 --- src/txt-converter/login/Makefile | 12 - src/txt-converter/login/login-converter.c | 282 --- 42 files changed, 13588 deletions(-) delete mode 100644 src/char_sql/Makefile delete mode 100644 src/char_sql/char.c delete mode 100644 src/char_sql/char.h delete mode 100644 src/char_sql/int_guild.c delete mode 100644 src/char_sql/int_guild.h delete mode 100644 src/char_sql/int_party.c delete mode 100644 src/char_sql/int_party.h delete mode 100644 src/char_sql/int_pet.c delete mode 100644 src/char_sql/int_pet.h delete mode 100644 src/char_sql/int_storage.c delete mode 100644 src/char_sql/int_storage.h delete mode 100644 src/char_sql/inter.c delete mode 100644 src/char_sql/inter.h delete mode 100644 src/char_sql/itemdb.c delete mode 100644 src/char_sql/itemdb.h delete mode 100644 src/char_sql/make.sh delete mode 100644 src/char_sql/readme.txt delete mode 100644 src/char_sql/strlib.c delete mode 100644 src/char_sql/strlib.h delete mode 100644 src/login_sql/Makefile delete mode 100644 src/login_sql/login.c delete mode 100644 src/login_sql/login.h delete mode 100644 src/login_sql/make.sh delete mode 100644 src/login_sql/md5calc.c delete mode 100644 src/login_sql/md5calc.h delete mode 100644 src/login_sql/readme.txt delete mode 100644 src/login_sql/strlib.c delete mode 100644 src/login_sql/strlib.h delete mode 100644 src/login_sql/timer.h delete mode 100644 src/txt-converter/char/Makefile delete mode 100644 src/txt-converter/char/char-converter.c delete mode 100644 src/txt-converter/char/char.h delete mode 100644 src/txt-converter/char/int_guild.h delete mode 100644 src/txt-converter/char/int_party.h delete mode 100644 src/txt-converter/char/int_pet.h delete mode 100644 src/txt-converter/char/int_storage.h delete mode 100644 src/txt-converter/char/inter.h delete mode 100644 src/txt-converter/char/strlib.c delete mode 100644 src/txt-converter/char/strlib.h delete mode 100644 src/txt-converter/common/mmo.h delete mode 100644 src/txt-converter/login/Makefile delete mode 100644 src/txt-converter/login/login-converter.c diff --git a/src/char_sql/Makefile b/src/char_sql/Makefile deleted file mode 100644 index 8f21f0b..0000000 --- a/src/char_sql/Makefile +++ /dev/null @@ -1,22 +0,0 @@ -include ../../make.defs - -all: char-server_sql -sql: char-server_sql - -COMMON_OBJ = ../common/core.o ../common/socket.o ../common/timer.o ../common/db.o ../common/malloc.o -COMMON_H = ../common/core.h ../common/socket.h ../common/timer.h ../common/db.h ../common/malloc.h - -char-server_sql: char.o inter.o int_party.o int_guild.o int_storage.o int_pet.o strlib.o itemdb.o $(COMMON_OBJ) - $(CC) -o ../../$@ $^ $(LIB_S) - -char.o: char.c char.h strlib.h itemdb.h -inter.o: inter.c inter.h int_party.h int_guild.h int_storage.h int_pet.h ../common/mmo.h char.h ../common/socket.h -int_party.o: int_party.c int_party.h inter.h ../common/mmo.h char.h ../common/socket.h ../common/timer.h ../common/db.h -int_guild.o: int_guild.c int_guild.h inter.h ../common/mmo.h char.h ../common/socket.h ../common/db.h -int_storage.o: int_storage.c int_storage.h char.h itemdb.h -int_pet.o: int_pet.c int_pet.h inter.h char.h ../common/mmo.h ../common/socket.h ../common/db.h -strlib.o: strlib.c strlib.h -itemdb.o: itemdb.c itemdb.h ../common/db.h ../common/mmo.h - -clean: - rm -f *.o ../../char-server_sql diff --git a/src/char_sql/char.c b/src/char_sql/char.c deleted file mode 100644 index 312d302..0000000 --- a/src/char_sql/char.c +++ /dev/null @@ -1,3750 +0,0 @@ -// $Id: char.c,v 1.16 2004/09/23 18:31:16 MouseJstr Exp $ -// original : char2.c 2003/03/14 11:58:35 Rev.1.5 -// -// original code from athena -// SQL conversion by Jioh L. Jung -// TXT 1.105 -#include - -#ifdef LCCWIN32 -#include -#pragma lib -#else -#include -#include -#include -#include -#include -#include -#endif - -#include "utils.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "char.h" -#include "strlib.h" -#include "itemdb.h" -#include "inter.h" - -#ifdef MEMWATCH -#include "memwatch.h" -#endif - -char char_db[256] = "char"; -char cart_db[256] = "cart_inventory"; -char inventory_db[256] = "inventory"; -char charlog_db[256] = "charlog"; -char storage_db[256] = "storage"; -char interlog_db[256] = "interlog"; -char reg_db[256] = "global_reg_value"; -char skill_db[256] = "skill"; -char memo_db[256] = "memo"; -char guild_db[256] = "guild"; -char guild_alliance_db[256] = "guild_alliance"; -char guild_castle_db[256] = "guild_castle"; -char guild_expulsion_db[256] = "guild_expulsion"; -char guild_member_db[256] = "guild_member"; -char guild_position_db[256] = "guild_position"; -char guild_skill_db[256] = "guild_skill"; -char guild_storage_db[256] = "guild_storage"; -char party_db[256] = "party"; -char pet_db[256] = "pet"; -char login_db[256] = "login"; - -char login_db_account_id[32] = "account_id"; -char login_db_level[32] = "level"; - -int lowest_gm_level = 1; - -unsigned char *SQL_CONF_NAME = "conf/inter_athena.conf"; - -struct mmo_map_server server[MAX_MAP_SERVERS]; -int server_fd[MAX_MAP_SERVERS]; -int server_freezeflag[MAX_MAP_SERVERS]; // Map-server anti-freeze system. Counter. 5 ok, 4...0 freezed - -int anti_freeze_enable = 0; -int ANTI_FREEZE_INTERVAL = 6; - -int login_fd, char_fd; -char userid[24]; -char passwd[24]; -char server_name[20]; -char wisp_server_name[24] = "Server"; -char login_ip_str[128]; -int login_ip; -int login_port = 6900; -char char_ip_str[128]; -int char_ip; -int char_port = 6121; -int char_maintenance; -int char_new; -int name_ignoring_case = 0; // Allow or not identical name for characters but with a different case by [Yor] -int char_name_option = 0; // Option to know which letters/symbols are authorised in the name of a character (0: all, 1: only those in char_name_letters, 2: all EXCEPT those in char_name_letters) by [Yor] -char char_name_letters[1024] = ""; // list of letters/symbols used to authorise or not a name of a character. by [Yor] - -char lan_map_ip[128]; // Lan map ip added by kashy -int subnetmaski[4]; // Subnetmask added by kashy -char unknown_char_name[1024] = "Unknown"; - -struct char_session_data -{ - int account_id, login_id1, login_id2, sex; - int found_char[9]; - char email[40]; // e-mail (default: a@a.com) by [Yor] - time_t connect_until_time; // # of seconds 1/1/1970 (timestamp): Validity limit of the account (0 = unlimited) -}; - -#define AUTH_FIFO_SIZE 256 -struct -{ - int account_id, char_id, login_id1, login_id2, ip, char_pos, delflag, - sex; - time_t connect_until_time; // # of seconds 1/1/1970 (timestamp): Validity limit of the account (0 = unlimited) -} auth_fifo[AUTH_FIFO_SIZE]; -int auth_fifo_pos = 0; - -int check_ip_flag = 1; // It's to check IP of a player between char-server and other servers (part of anti-hacking system) - -int char_id_count = 150000; -struct mmo_charstatus *char_dat; -int char_num, char_max; -int max_connect_user = 0; -int autosave_interval = DEFAULT_AUTOSAVE_INTERVAL; -int start_zeny = 500; -int start_weapon = 1201; -int start_armor = 2301; - -// check for exit signal -// 0 is saving complete -// other is char_id -unsigned int save_flag = 0; - -// start point (you can reset point on conf file) -struct point start_point = { "new_1-1.gat", 53, 111 }; - -struct gm_account *gm_account = NULL; -int GM_num = 0; - -//----------------------------------------------------- -// Function to suppress control characters in a string. -//----------------------------------------------------- -int remove_control_chars (unsigned char *str) -{ - int i; - int change = 0; - - for (i = 0; i < strlen (str); i++) - { - if (str[i] < 32) - { - str[i] = '_'; - change = 1; - } - } - - return change; -} - -//---------------------------------------------------------------------- -// Determine if an account (id) is a GM account -// and returns its level (or 0 if it isn't a GM account or if not found) -//---------------------------------------------------------------------- -// Removed since nothing GM related goes on in the char server [CLOWNISIUS] -int isGM (int account_id) -{ - int i; - - for (i = 0; i < GM_num; i++) - if (gm_account[i].account_id == account_id) - return gm_account[i].level; - return 0; -} - -void read_gm_account (void) -{ - if (gm_account != NULL) - free (gm_account); - GM_num = 0; - - sprintf (tmp_lsql, "SELECT `%s`,`%s` FROM `%s` WHERE `%s`>='%d'", - login_db_account_id, login_db_level, login_db, login_db_level, - lowest_gm_level); - if (mysql_query (&lmysql_handle, tmp_lsql)) - { - printf ("DB server Error (select %s to Memory)- %s\n", login_db, - mysql_error (&lmysql_handle)); - } - lsql_res = mysql_store_result (&lmysql_handle); - if (lsql_res) - { - gm_account = - calloc (sizeof (struct gm_account) * mysql_num_rows (lsql_res), - 1); - while ((lsql_row = mysql_fetch_row (lsql_res))) - { - gm_account[GM_num].account_id = atoi (lsql_row[0]); - gm_account[GM_num].level = atoi (lsql_row[1]); - GM_num++; - } - } - - mysql_free_result (lsql_res); -} - -//===================================================================================================== -int mmo_char_tosql (int char_id, struct mmo_charstatus *p) -{ - int i = 0, party_exist, guild_exist; - int eqcount = 1; - int noteqcount = 1; - char temp_str[32]; - - struct itemtemp mapitem; - if (char_id != p->char_id) - return 0; - - save_flag = p->char_id; - printf ("(\033[1;32m%d\033[0m) %s \trequest save char data - ", char_id, - char_dat[0].name); - -//for(testcount=1;testcount<50;testcount++){//---------------------------test count-------------------- -// printf("test count : %d\n", testcount); -// eqcount=1; -// noteqcount=1; -// dbeqcount=1; -// dbnoteqcount=1; -//----------------------------------------------------------------------------------------------------- - -//=========================================map inventory data > memory =============================== - //map inventory data - for (i = 0; i < MAX_INVENTORY; i++) - { - if (p->inventory[i].nameid > 0) - { - if (itemdb_isequip (p->inventory[i].nameid) == 1) - { - mapitem.equip[eqcount].flag = 0; - mapitem.equip[eqcount].id = p->inventory[i].id; - mapitem.equip[eqcount].nameid = p->inventory[i].nameid; - mapitem.equip[eqcount].amount = p->inventory[i].amount; - mapitem.equip[eqcount].equip = p->inventory[i].equip; - mapitem.equip[eqcount].identify = p->inventory[i].identify; - mapitem.equip[eqcount].refine = p->inventory[i].refine; - mapitem.equip[eqcount].attribute = p->inventory[i].attribute; - mapitem.equip[eqcount].card[0] = p->inventory[i].card[0]; - mapitem.equip[eqcount].card[1] = p->inventory[i].card[1]; - mapitem.equip[eqcount].card[2] = p->inventory[i].card[2]; - mapitem.equip[eqcount].card[3] = p->inventory[i].card[3]; - mapitem.equip[eqcount].broken = p->inventory[i].broken; - eqcount++; - } - else if (itemdb_isequip (p->inventory[i].nameid) == 0) - { - mapitem.notequip[noteqcount].flag = 0; - mapitem.notequip[noteqcount].id = p->inventory[i].id; - mapitem.notequip[noteqcount].nameid = p->inventory[i].nameid; - mapitem.notequip[noteqcount].amount = p->inventory[i].amount; - mapitem.notequip[noteqcount].equip = p->inventory[i].equip; - mapitem.notequip[noteqcount].identify = - p->inventory[i].identify; - mapitem.notequip[noteqcount].refine = p->inventory[i].refine; - mapitem.notequip[noteqcount].attribute = - p->inventory[i].attribute; - mapitem.notequip[noteqcount].card[0] = - p->inventory[i].card[0]; - mapitem.notequip[noteqcount].card[1] = - p->inventory[i].card[1]; - mapitem.notequip[noteqcount].card[2] = - p->inventory[i].card[2]; - mapitem.notequip[noteqcount].card[3] = - p->inventory[i].card[3]; - mapitem.notequip[noteqcount].broken = p->inventory[i].broken; - noteqcount++; - } - } - } - //printf("- Save item data to MySQL!\n"); - memitemdata_to_sql (mapitem, eqcount, noteqcount, p->char_id, - TABLE_INVENTORY); - -//=========================================map cart data > memory ==================================== - eqcount = 1; - noteqcount = 1; - - //map cart data - for (i = 0; i < MAX_CART; i++) - { - if (p->cart[i].nameid > 0) - { - if (itemdb_isequip (p->cart[i].nameid) == 1) - { - mapitem.equip[eqcount].flag = 0; - mapitem.equip[eqcount].id = p->cart[i].id; - mapitem.equip[eqcount].nameid = p->cart[i].nameid; - mapitem.equip[eqcount].amount = p->cart[i].amount; - mapitem.equip[eqcount].equip = p->cart[i].equip; - mapitem.equip[eqcount].identify = p->cart[i].identify; - mapitem.equip[eqcount].refine = p->cart[i].refine; - mapitem.equip[eqcount].attribute = p->cart[i].attribute; - mapitem.equip[eqcount].card[0] = p->cart[i].card[0]; - mapitem.equip[eqcount].card[1] = p->cart[i].card[1]; - mapitem.equip[eqcount].card[2] = p->cart[i].card[2]; - mapitem.equip[eqcount].card[3] = p->cart[i].card[3]; - mapitem.equip[eqcount].broken = p->cart[i].broken; - eqcount++; - } - else if (itemdb_isequip (p->cart[i].nameid) == 0) - { - mapitem.notequip[noteqcount].flag = 0; - mapitem.notequip[noteqcount].id = p->cart[i].id; - mapitem.notequip[noteqcount].nameid = p->cart[i].nameid; - mapitem.notequip[noteqcount].amount = p->cart[i].amount; - mapitem.notequip[noteqcount].equip = p->cart[i].equip; - mapitem.notequip[noteqcount].identify = p->cart[i].identify; - mapitem.notequip[noteqcount].refine = p->cart[i].refine; - mapitem.notequip[noteqcount].attribute = p->cart[i].attribute; - mapitem.notequip[noteqcount].card[0] = p->cart[i].card[0]; - mapitem.notequip[noteqcount].card[1] = p->cart[i].card[1]; - mapitem.notequip[noteqcount].card[2] = p->cart[i].card[2]; - mapitem.notequip[noteqcount].card[3] = p->cart[i].card[3]; - mapitem.notequip[noteqcount].broken = p->cart[i].broken; - noteqcount++; - } - } - } - - //printf("- Save cart data to MySQL!\n"); - memitemdata_to_sql (mapitem, eqcount, noteqcount, p->char_id, TABLE_CART); - -//===================================================================================================== - -//}//---------------------------test count------------------------------ - //check party_exist - party_exist = 0; - sprintf (tmp_sql, "SELECT count(*) FROM `%s` WHERE `party_id` = '%d'", - party_db, p->party_id); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error - %s\n", mysql_error (&mysql_handle)); - } - sql_res = mysql_store_result (&mysql_handle); - sql_row = mysql_fetch_row (sql_res); - if (sql_row) - party_exist = atoi (sql_row[0]); - mysql_free_result (sql_res); - - //check guild_exist - guild_exist = 0; - sprintf (tmp_sql, "SELECT count(*) FROM `%s` WHERE `guild_id` = '%d'", - guild_db, p->guild_id); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error - %s\n", mysql_error (&mysql_handle)); - } - sql_res = mysql_store_result (&mysql_handle); - sql_row = mysql_fetch_row (sql_res); - if (sql_row) - guild_exist = atoi (sql_row[0]); - mysql_free_result (sql_res); - - if (guild_exist == 0) - p->guild_id = 0; - if (party_exist == 0) - p->party_id = 0; - - //sql query - //`char`( `char_id`,`account_id`,`char_num`,`name`,`class`,`base_level`,`job_level`,`base_exp`,`job_exp`,`zeny`, //9 - //`str`,`agi`,`vit`,`int`,`dex`,`luk`, //15 - //`max_hp`,`hp`,`max_sp`,`sp`,`status_point`,`skill_point`, //21 - //`option`,`karma`,`manner`,`party_id`,`guild_id`,`pet_id`, //27 - //`hair`,`hair_color`,`clothes_color`,`weapon`,`shield`,`head_top`,`head_mid`,`head_bottom`, //35 - //`last_map`,`last_x`,`last_y`,`save_map`,`save_x`,`save_y`) - //printf("- Save char data to MySQL!\n"); - sprintf (tmp_sql, - "UPDATE `%s` SET `class`='%d', `base_level`='%d', `job_level`='%d'," - "`base_exp`='%d', `job_exp`='%d', `zeny`='%d'," - "`max_hp`='%d',`hp`='%d',`max_sp`='%d',`sp`='%d',`status_point`='%d',`skill_point`='%d'," - "`str`='%d',`agi`='%d',`vit`='%d',`int`='%d',`dex`='%d',`luk`='%d'," - "`option`='%d',`karma`='%d',`manner`='%d',`party_id`='%d',`guild_id`='%d',`pet_id`='%d'," - "`hair`='%d',`hair_color`='%d',`clothes_color`='%d',`weapon`='%d',`shield`='%d',`head_top`='%d',`head_mid`='%d',`head_bottom`='%d'," - "`last_map`='%s',`last_x`='%d',`last_y`='%d',`save_map`='%s',`save_x`='%d',`save_y`='%d',`partner_id`='%d' WHERE `account_id`='%d' AND `char_id` = '%d'", - char_db, p->class, p->base_level, p->job_level, p->base_exp, - p->job_exp, p->zeny, p->max_hp, p->hp, p->max_sp, p->sp, - p->status_point, p->skill_point, p->str, p->agi, p->vit, p->int_, - p->dex, p->luk, p->option, p->karma, p->manner, p->party_id, - p->guild_id, p->pet_id, p->hair, p->hair_color, p->clothes_color, - p->weapon, p->shield, p->head_top, p->head_mid, p->head_bottom, - p->last_point.map, p->last_point.x, p->last_point.y, - p->save_point.map, p->save_point.x, p->save_point.y, - p->partner_id, p->account_id, p->char_id); - - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (update `char`)- %s\n", - mysql_error (&mysql_handle)); - } - - //printf("- Save memo data to MySQL!\n"); - //`memo` (`memo_id`,`char_id`,`map`,`x`,`y`) - sprintf (tmp_sql, "DELETE FROM `%s` WHERE `char_id`='%d'", memo_db, - p->char_id); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (delete `memo`)- %s\n", - mysql_error (&mysql_handle)); - } - - //insert here. - for (i = 0; i < 10; i++) - { - if (p->memo_point[i].map[0]) - { - sprintf (tmp_sql, - "INSERT INTO `%s`(`char_id`,`map`,`x`,`y`) VALUES ('%d', '%s', '%d', '%d')", - memo_db, char_id, p->memo_point[i].map, - p->memo_point[i].x, p->memo_point[i].y); - if (mysql_query (&mysql_handle, tmp_sql)) - printf ("DB server Error (insert `memo`)- %s\n", - mysql_error (&mysql_handle)); - } - } - - //printf("- Save skill data to MySQL!\n"); - //`skill` (`char_id`, `id`, `lv`) - sprintf (tmp_sql, "DELETE FROM `%s` WHERE `char_id`='%d'", skill_db, - p->char_id); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (delete `skill`)- %s\n", - mysql_error (&mysql_handle)); - } - //printf("- Insert skill \n"); - //insert here. - for (i = 0; i < MAX_SKILL; i++) - { - if (p->skill[i].id) - { - if (p->skill[i].id && p->skill[i].flag != 1) - { - sprintf (tmp_sql, - "INSERT delayed INTO `%s`(`char_id`, `id`, `lv`) VALUES ('%d', '%d','%d')", - skill_db, char_id, p->skill[i].id, - (p->skill[i].flag == - 0) ? p->skill[i].lv : p->skill[i].flag - 2); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (insert `skill`)- %s\n", - mysql_error (&mysql_handle)); - } - } - } - } - - //printf("- Save global_reg_value data to MySQL!\n"); - //`global_reg_value` (`char_id`, `str`, `value`) - sprintf (tmp_sql, "DELETE FROM `%s` WHERE `type`=3 AND `char_id`='%d'", - reg_db, p->char_id); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (delete `global_reg_value`)- %s\n", - mysql_error (&mysql_handle)); - } - - //insert here. - for (i = 0; i < p->global_reg_num; i++) - { - if (p->global_reg[i].str) - { - if (p->global_reg[i].value != 0) - { - sprintf (tmp_sql, - "INSERT INTO `%s` (`char_id`, `str`, `value`) VALUES ('%d', '%s','%d')", - reg_db, char_id, jstrescapecpy (temp_str, - (unsigned char *) - p->global_reg[i]. - str), - p->global_reg[i].value); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf - ("DB server Error (insert `global_reg_value`)- %s\n", - mysql_error (&mysql_handle)); - } - } - } - } - printf ("saving char is done.\n"); - save_flag = 0; - - return 0; -} - -int memitemdata_to_sql (struct itemtemp mapitem, int eqcount, int noteqcount, - int char_id, int tableswitch) -{ - //equ - int i, j; - int dbeqcount = 1; - int dbnoteqcount = 1; - struct itemtemp dbitem; - char tablename[16]; - char selectoption[16]; - - switch (tableswitch) - { - case TABLE_INVENTORY: - sprintf (tablename, "%s", inventory_db); - sprintf (selectoption, "char_id"); - break; - case TABLE_CART: - sprintf (tablename, "%s", cart_db); - sprintf (selectoption, "char_id"); - break; - case TABLE_STORAGE: - sprintf (tablename, "%s", storage_db); - sprintf (selectoption, "account_id"); - break; - case TABLE_GUILD_STORAGE: - sprintf (tablename, "%s", guild_storage_db); - sprintf (selectoption, "guild_id"); - break; - } - //printf("Working Table : %s \n",tablename); - - //=======================================mysql database data > memory=============================================== - - sprintf (tmp_sql, - "SELECT `id`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `card0`, `card1`, `card2`, `card3` , `broken` " - "FROM `%s` WHERE `%s`='%d'", tablename, selectoption, char_id); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (select `%s` to Memory)- %s\n", tablename, - mysql_error (&mysql_handle)); - } - sql_res = mysql_store_result (&mysql_handle); - if (sql_res) - { - for (i = 0; (sql_row = mysql_fetch_row (sql_res)); i++) - { - if (itemdb_isequip (atoi (sql_row[1])) == 1) - { - dbitem.equip[dbeqcount].flag = 0; - dbitem.equip[dbeqcount].id = atoi (sql_row[0]); - dbitem.equip[dbeqcount].nameid = atoi (sql_row[1]); - dbitem.equip[dbeqcount].amount = atoi (sql_row[2]); - dbitem.equip[dbeqcount].equip = atoi (sql_row[3]); - dbitem.equip[dbeqcount].identify = atoi (sql_row[4]); - dbitem.equip[dbeqcount].refine = atoi (sql_row[5]); - dbitem.equip[dbeqcount].attribute = atoi (sql_row[6]); - dbitem.equip[dbeqcount].card[0] = atoi (sql_row[7]); - dbitem.equip[dbeqcount].card[1] = atoi (sql_row[8]); - dbitem.equip[dbeqcount].card[2] = atoi (sql_row[9]); - dbitem.equip[dbeqcount].card[3] = atoi (sql_row[10]); - dbitem.equip[dbeqcount].broken = atoi (sql_row[11]); - dbeqcount++; - } - else - { - dbitem.notequip[dbnoteqcount].flag = 0; - dbitem.notequip[dbnoteqcount].id = atoi (sql_row[0]); - dbitem.notequip[dbnoteqcount].nameid = atoi (sql_row[1]); - dbitem.notequip[dbnoteqcount].amount = atoi (sql_row[2]); - dbitem.notequip[dbnoteqcount].equip = atoi (sql_row[3]); - dbitem.notequip[dbnoteqcount].identify = atoi (sql_row[4]); - dbitem.notequip[dbnoteqcount].refine = atoi (sql_row[5]); - dbitem.notequip[dbnoteqcount].attribute = atoi (sql_row[6]); - dbitem.notequip[dbnoteqcount].card[0] = atoi (sql_row[7]); - dbitem.notequip[dbnoteqcount].card[1] = atoi (sql_row[8]); - dbitem.notequip[dbnoteqcount].card[2] = atoi (sql_row[9]); - dbitem.notequip[dbnoteqcount].card[3] = atoi (sql_row[10]); - dbitem.notequip[dbnoteqcount].broken = atoi (sql_row[11]); - dbnoteqcount++; - } - } - mysql_free_result (sql_res); - } - - //==============================================Memory data > SQL =============================== - //======================================Equip ITEM======================================= - if ((eqcount == 1) && (dbeqcount == 1)) - { //printf("%s Equip Empty\n",tablename); - //item empty - } - else - { - - for (i = 1; i < eqcount; i++) - { - for (j = 1; j < dbeqcount; j++) - { - if (mapitem.equip[i].flag == 1) - break; - if (!(dbitem.equip[j].flag == 1)) - { - if (mapitem.equip[i].nameid == dbitem.equip[j].nameid) - { - if ((mapitem.equip[i].equip == dbitem.equip[j].equip) - && (mapitem.equip[i].identify == - dbitem.equip[j].identify) - && (mapitem.equip[i].amount == - dbitem.equip[j].amount) - && (mapitem.equip[i].refine == - dbitem.equip[j].refine) - && (mapitem.equip[i].attribute == - dbitem.equip[j].attribute) - && (mapitem.equip[i].card[0] == - dbitem.equip[j].card[0]) - && (mapitem.equip[i].card[1] == - dbitem.equip[j].card[1]) - && (mapitem.equip[i].card[2] == - dbitem.equip[j].card[2]) - && (mapitem.equip[i].card[3] == - dbitem.equip[j].card[3]) - && (mapitem.equip[i].broken == - dbitem.equip[j].broken)) - { - mapitem.equip[i].flag = 1; - dbitem.equip[j].flag = 1; - //printf("the same item : %d , equip : %d , i : %d , flag : %d\n", mapitem.equip[i].nameid,mapitem.equip[i].equip , i, mapitem.equip[i].flag); //DEBUG-STRING - } - else - { - sprintf (tmp_sql, - "UPDATE `%s` SET `equip`='%d', `identify`='%d', `refine`='%d'," - "`attribute`='%d', `card0`='%d', `card1`='%d', `card2`='%d', `card3`='%d', `broken`='%d', `amount`='%d' WHERE `id`='%d' LIMIT 1", - tablename, mapitem.equip[i].equip, - mapitem.equip[i].identify, - mapitem.equip[i].refine, - mapitem.equip[i].attribute, - mapitem.equip[i].card[0], - mapitem.equip[i].card[1], - mapitem.equip[i].card[2], - mapitem.equip[i].card[3], - mapitem.equip[i].broken, - mapitem.equip[i].amount, - dbitem.equip[j].id); - //printf("%s\n",tmp_sql); - if (mysql_query (&mysql_handle, tmp_sql)) - printf - ("DB server Error (UPdate `equ %s`)- %s\n", - tablename, mysql_error (&mysql_handle)); - mapitem.equip[i].flag = 1; - dbitem.equip[j].flag = 1; - //printf("not the same item : %d ; i : %d ; flag : %d\n", mapitem.equip[i].nameid, i, mapitem.equip[i].flag); - } - } - } - } - } - - //printf("dbeqcount = %d\n",dbeqcount); - - for (i = 1; i < dbeqcount; i++) - { - //printf("dbitem.equip[i].flag = %d , dbitem.equip[i].id = %d\n",dbitem.equip[i].flag,dbitem.equip[i].id); - if (!(dbitem.equip[i].flag == 1)) - { - sprintf (tmp_sql, "DELETE from `%s` where `id`='%d'", - tablename, dbitem.equip[i].id); - //printf("%s", tmp_sql); - if (mysql_query (&mysql_handle, tmp_sql)) - printf ("DB server Error (DELETE `equ %s`)- %s\n", - tablename, mysql_error (&mysql_handle)); - } - } - for (i = 1; i < eqcount; i++) - { - if (!(mapitem.equip[i].flag == 1)) - { - sprintf (tmp_sql, - "INSERT INTO `%s`(`%s`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `card0`, `card1`, `card2`, `card3`, `broken`)" - " VALUES ( '%d','%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d')", - tablename, selectoption, char_id, - mapitem.equip[i].nameid, mapitem.equip[i].amount, - mapitem.equip[i].equip, mapitem.equip[i].identify, - mapitem.equip[i].refine, mapitem.equip[i].attribute, - mapitem.equip[i].card[0], mapitem.equip[i].card[1], - mapitem.equip[i].card[2], mapitem.equip[i].card[3], - mapitem.equip[i].broken); - //printf("%s", tmp_sql); - if (mysql_query (&mysql_handle, tmp_sql)) - printf ("DB server Error (INSERT `equ %s`)- %s\n", - tablename, mysql_error (&mysql_handle)); - } - } - - //======================================DEBUG================================================= - -// gettimeofday(&tv,NULL); -// strftime(tmpstr,24,"%Y-%m-%d %H:%M:%S",localtime(&(tv.tv_sec))); -// printf("\n\n"); -// printf("Working Table Name : EQU %s, Count : map %3d | db %3d \n",tablename ,eqcount ,dbeqcount); -// printf("*********************************************************************************\n"); -// printf("======================================MAP===================Char ID %10d===\n",char_id); -// printf("==flag ===name ===equip===ident===amoun===attri===card0===card1===card2===card3==\n"); -// for(j=1;jchar_id = char_id; - printf ("Loaded: "); - //`char`( `char_id`,`account_id`,`char_num`,`name`,`class`,`base_level`,`job_level`,`base_exp`,`job_exp`,`zeny`, //9 - //`str`,`agi`,`vit`,`int`,`dex`,`luk`, //15 - //`max_hp`,`hp`,`max_sp`,`sp`,`status_point`,`skill_point`, //21 - //`option`,`karma`,`manner`,`party_id`,`guild_id`,`pet_id`, //27 - //`hair`,`hair_color`,`clothes_color`,`weapon`,`shield`,`head_top`,`head_mid`,`head_bottom`, //35 - //`last_map`,`last_x`,`last_y`,`save_map`,`save_x`,`save_y`) - //splite 2 parts. cause veeeery long SQL syntax - - sprintf (tmp_sql, - "SELECT `char_id`,`account_id`,`char_num`,`name`,`class`,`base_level`,`job_level`,`base_exp`,`job_exp`,`zeny`," - "`str`,`agi`,`vit`,`int`,`dex`,`luk`, `max_hp`,`hp`,`max_sp`,`sp`,`status_point`,`skill_point` FROM `%s` WHERE `char_id` = '%d'", - char_db, char_id); - - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (select `char`)- %s\n", - mysql_error (&mysql_handle)); - } - - sql_res = mysql_store_result (&mysql_handle); - - if (sql_res) - { - sql_row = mysql_fetch_row (sql_res); - - p->char_id = char_id; - p->account_id = atoi (sql_row[1]); - p->char_num = atoi (sql_row[2]); - strcpy (p->name, sql_row[3]); - p->class = atoi (sql_row[4]); - p->base_level = atoi (sql_row[5]); - p->job_level = atoi (sql_row[6]); - p->base_exp = atoi (sql_row[7]); - p->job_exp = atoi (sql_row[8]); - p->zeny = atoi (sql_row[9]); - p->str = atoi (sql_row[10]); - p->agi = atoi (sql_row[11]); - p->vit = atoi (sql_row[12]); - p->int_ = atoi (sql_row[13]); - p->dex = atoi (sql_row[14]); - p->luk = atoi (sql_row[15]); - p->max_hp = atoi (sql_row[16]); - p->hp = atoi (sql_row[17]); - p->max_sp = atoi (sql_row[18]); - p->sp = atoi (sql_row[19]); - p->status_point = atoi (sql_row[20]); - p->skill_point = atoi (sql_row[21]); - //free mysql result. - mysql_free_result (sql_res); - } - else - printf ("char1 - failed\n"); //Error?! ERRRRRR WHAT THAT SAY!? - printf ("(\033[1;32m%d\033[0m)\033[1;32m%s\033[0m\t[", p->char_id, - p->name); - printf ("char1 "); - - sprintf (tmp_sql, - "SELECT `option`,`karma`,`manner`,`party_id`,`guild_id`,`pet_id`,`hair`,`hair_color`," - "`clothes_color`,`weapon`,`shield`,`head_top`,`head_mid`,`head_bottom`," - "`last_map`,`last_x`,`last_y`,`save_map`,`save_x`,`save_y`, `partner_id` FROM `%s` WHERE `char_id` = '%d'", - char_db, char_id); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (select `char2`)- %s\n", - mysql_error (&mysql_handle)); - } - - sql_res = mysql_store_result (&mysql_handle); - if (sql_res) - { - sql_row = mysql_fetch_row (sql_res); - - p->option = atoi (sql_row[0]); - p->karma = atoi (sql_row[1]); - p->manner = atoi (sql_row[2]); - p->party_id = atoi (sql_row[3]); - p->guild_id = atoi (sql_row[4]); - p->pet_id = atoi (sql_row[5]); - - p->hair = atoi (sql_row[6]); - p->hair_color = atoi (sql_row[7]); - p->clothes_color = atoi (sql_row[8]); - p->weapon = atoi (sql_row[9]); - p->shield = atoi (sql_row[10]); - p->head_top = atoi (sql_row[11]); - p->head_mid = atoi (sql_row[12]); - p->head_bottom = atoi (sql_row[13]); - strcpy (p->last_point.map, sql_row[14]); - p->last_point.x = atoi (sql_row[15]); - p->last_point.y = atoi (sql_row[16]); - strcpy (p->save_point.map, sql_row[17]); - p->save_point.x = atoi (sql_row[18]); - p->save_point.y = atoi (sql_row[19]); - p->partner_id = atoi (sql_row[20]); - - //free mysql result. - mysql_free_result (sql_res); - } - else - printf ("char2 - failed\n"); //Error?! ERRRRRR WHAT THAT SAY!? - - printf ("char2 "); - - //read memo data - //`memo` (`memo_id`,`char_id`,`map`,`x`,`y`) - sprintf (tmp_sql, "SELECT `map`,`x`,`y` FROM `%s` WHERE `char_id`='%d'", - memo_db, char_id); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (select `memo`)- %s\n", - mysql_error (&mysql_handle)); - } - sql_res = mysql_store_result (&mysql_handle); - - if (sql_res) - { - for (i = 0; (sql_row = mysql_fetch_row (sql_res)); i++) - { - strcpy (p->memo_point[i].map, sql_row[0]); - p->memo_point[i].x = atoi (sql_row[1]); - p->memo_point[i].y = atoi (sql_row[2]); - //i ++; - } - mysql_free_result (sql_res); - } - printf ("memo "); - - //read inventory - //`inventory` (`id`,`char_id`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `card0`, `card1`, `card2`, `card3`) - sprintf (tmp_sql, - "SELECT `id`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `card0`, `card1`, `card2`, `card3`, `broken` " - "FROM `%s` WHERE `char_id`='%d'", inventory_db, char_id); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (select `inventory`)- %s\n", - mysql_error (&mysql_handle)); - } - sql_res = mysql_store_result (&mysql_handle); - if (sql_res) - { - for (i = 0; (sql_row = mysql_fetch_row (sql_res)); i++) - { - p->inventory[i].id = atoi (sql_row[0]); - p->inventory[i].nameid = atoi (sql_row[1]); - p->inventory[i].amount = atoi (sql_row[2]); - p->inventory[i].equip = atoi (sql_row[3]); - p->inventory[i].identify = atoi (sql_row[4]); - p->inventory[i].refine = atoi (sql_row[5]); - p->inventory[i].attribute = atoi (sql_row[6]); - p->inventory[i].card[0] = atoi (sql_row[7]); - p->inventory[i].card[1] = atoi (sql_row[8]); - p->inventory[i].card[2] = atoi (sql_row[9]); - p->inventory[i].card[3] = atoi (sql_row[10]); - p->inventory[i].broken = atoi (sql_row[11]); - } - mysql_free_result (sql_res); - } - printf ("inventory "); - - //read cart. - //`cart_inventory` (`id`,`char_id`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `card0`, `card1`, `card2`, `card3`) - sprintf (tmp_sql, - "SELECT `id`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `card0`, `card1`, `card2`, `card3`, `broken` " - "FROM `%s` WHERE `char_id`='%d'", cart_db, char_id); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (select `cart_inventory`)- %s\n", - mysql_error (&mysql_handle)); - } - sql_res = mysql_store_result (&mysql_handle); - if (sql_res) - { - for (i = 0; (sql_row = mysql_fetch_row (sql_res)); i++) - { - p->cart[i].id = atoi (sql_row[0]); - p->cart[i].nameid = atoi (sql_row[1]); - p->cart[i].amount = atoi (sql_row[2]); - p->cart[i].equip = atoi (sql_row[3]); - p->cart[i].identify = atoi (sql_row[4]); - p->cart[i].refine = atoi (sql_row[5]); - p->cart[i].attribute = atoi (sql_row[6]); - p->cart[i].card[0] = atoi (sql_row[7]); - p->cart[i].card[1] = atoi (sql_row[8]); - p->cart[i].card[2] = atoi (sql_row[9]); - p->cart[i].card[3] = atoi (sql_row[10]); - p->cart[i].broken = atoi (sql_row[11]); - } - mysql_free_result (sql_res); - } - printf ("cart "); - - //read skill - //`skill` (`char_id`, `id`, `lv`) - sprintf (tmp_sql, "SELECT `id`, `lv` FROM `%s` WHERE `char_id`='%d'", - skill_db, char_id); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (select `skill`)- %s\n", - mysql_error (&mysql_handle)); - } - sql_res = mysql_store_result (&mysql_handle); - if (sql_res) - { - for (i = 0; (sql_row = mysql_fetch_row (sql_res)); i++) - { - n = atoi (sql_row[0]); - p->skill[n].id = n; //memory!? shit!. - p->skill[n].lv = atoi (sql_row[1]); - } - mysql_free_result (sql_res); - } - printf ("skill "); - - //global_reg - //`global_reg_value` (`char_id`, `str`, `value`) - sprintf (tmp_sql, - "SELECT `str`, `value` FROM `%s` WHERE `type`=3 AND `char_id`='%d'", - reg_db, char_id); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (select `global_reg_value`)- %s\n", - mysql_error (&mysql_handle)); - } - i = 0; - sql_res = mysql_store_result (&mysql_handle); - if (sql_res) - { - for (i = 0; (sql_row = mysql_fetch_row (sql_res)); i++) - { - strcpy (p->global_reg[i].str, sql_row[0]); - p->global_reg[i].value = atoi (sql_row[1]); - } - mysql_free_result (sql_res); - } - p->global_reg_num = i; - - if (online) - { - sprintf (tmp_sql, - "UPDATE `%s` SET `online`='%d' WHERE `char_id`='%d'", - char_db, online, char_id); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (set char online)- %s\n", - mysql_error (&mysql_handle)); - } - } - - printf ("global_reg]\n"); //ok. all data load successfuly! - - //printf("char cloade"); - - return 1; -} - -//========================================================================================================== -int mmo_char_sql_init (void) -{ - int i; - - printf ("init start.......\n"); - // memory initialize - // no need to set twice size in this routine. but some cause segmentation error. :P - printf ("initializing char memory...(%d byte)\n", - sizeof (struct mmo_charstatus) * 2); - CREATE (char_dat, struct mmo_charstatus, 2); - - memset (char_dat, 0, sizeof (struct mmo_charstatus) * 2); -/* Initialized in inter.c already [Wizputer] - // DB connection initialized - // for char-server session only - mysql_init(&mysql_handle); - printf("Connect DB server....(char server)\n"); - if(!mysql_real_connect(&mysql_handle, char_server_ip, char_server_id, char_server_pw, char_server_db ,char_server_port, (char *)NULL, 0)) { - // SQL connection pointer check - printf("%s\n",mysql_error(&mysql_handle)); - exit(1); - } else { - printf("connect success! (char server)\n"); - } -*/ - sprintf (tmp_sql, "SELECT count(*) FROM `%s`", char_db); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error - %s\n", mysql_error (&mysql_handle)); - } - sql_res = mysql_store_result (&mysql_handle); - sql_row = mysql_fetch_row (sql_res); - printf ("total char data -> '%s'.......\n", sql_row[0]); - i = atoi (sql_row[0]); - mysql_free_result (sql_res); - - if (i != 0) - { - sprintf (tmp_sql, "SELECT max(`char_id`) FROM `%s`", char_db); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error - %s\n", mysql_error (&mysql_handle)); - } - sql_res = mysql_store_result (&mysql_handle); - sql_row = mysql_fetch_row (sql_res); - char_id_count = atoi (sql_row[0]); - - mysql_free_result (sql_res); - } - else - printf ("set char_id_count: %d.......\n", char_id_count); - - sprintf (tmp_sql, "UPDATE `%s` SET `online`='0' WHERE `online`='1'", - char_db); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (reset_online `%s`)- %s\n", char_db, - mysql_error (&mysql_handle)); - } - printf ("init end.......\n"); - - return 0; -} - -//========================================================================================================== - -int make_new_char_sql (int fd, unsigned char *dat) -{ - struct char_session_data *sd; - char t_name[100]; - int i; - //aphostropy error check! - fixed! - jstrescapecpy (t_name, dat); - printf ("making new char -"); - - sd = session[fd]->session_data; - - // Check Authorised letters/symbols in the name of the character - if (char_name_option == 1) - { // only letters/symbols in char_name_letters are authorised - for (i = 0; i < strlen (dat); i++) - if (strchr (char_name_letters, dat[i]) == NULL) - return -1; - } - else if (char_name_option == 2) - { // letters/symbols in char_name_letters are forbidden - for (i = 0; i < strlen (dat); i++) - if (strchr (char_name_letters, dat[i]) != NULL) - return -1; - } // else, all letters/symbols are authorised (except control char removed before) - - //check stat error - if ((dat[24] + dat[25] + dat[26] + dat[27] + dat[28] + dat[29] != 5 * 6) - || (dat[30] >= 9) || (dat[33] <= 0) || (dat[33] >= 20) - || (dat[31] >= 9)) - { - - // check individual stat value - for (i = 24; i <= 29; i++) - { - if (dat[i] < 1 || dat[i] > 9) - { - return -1; - } - } - - // char.log to charlog - sprintf (tmp_sql, - "INSERT INTO `%s` (`time`, `char_msg`,`account_id`,`char_num`,`name`,`str`,`agi`,`vit`,`int`,`dex`,`luk`,`hair`,`hair_color`)" - "VALUES (NOW(), '%s', '%d', '%d', '%s', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d')", - charlog_db, "make new char error", sd->account_id, dat[30], - dat, dat[24], dat[25], dat[26], dat[27], dat[28], dat[29], - dat[33], dat[31]); - //query - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error - %s\n", mysql_error (&mysql_handle)); - } - printf ("make new char error %d-%d %s %d, %d, %d, %d, %d, %d %d, %d" - RETCODE, fd, dat[30], dat, dat[24], dat[25], dat[26], dat[27], - dat[28], dat[29], dat[33], dat[31]); - return -1; - } - - // char.log to charlog - sprintf (tmp_sql, - "INSERT INTO `%s`(`time`, `char_msg`,`account_id`,`char_num`,`name`,`str`,`agi`,`vit`,`int`,`dex`,`luk`,`hair`,`hair_color`)" - "VALUES (NOW(), '%s', '%d', '%d', '%s', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d')", - charlog_db, "make new char", sd->account_id, dat[30], dat, - dat[24], dat[25], dat[26], dat[27], dat[28], dat[29], dat[33], - dat[31]); - //query - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error - %s\n", mysql_error (&mysql_handle)); - } - printf ("make new char %d-%d %s %d, %d, %d, %d, %d, %d - %d, %d" RETCODE, - fd, dat[30], dat, dat[24], dat[25], dat[26], dat[27], dat[28], - dat[29], dat[33], dat[31]); - - sprintf (tmp_sql, "SELECT count(*) FROM `%s` WHERE `name` = '%s'", - char_db, t_name); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error - %s\n", mysql_error (&mysql_handle)); - return -1; - } - sql_res = mysql_store_result (&mysql_handle); - sql_row = mysql_fetch_row (sql_res); - printf ("\033[1;32m name check result : %s -\033[0m ", sql_row[0]); - if (atoi (sql_row[0]) > 0) - { - mysql_free_result (sql_res); - return -1; - } - else - mysql_free_result (sql_res); - - // check char slot. - sprintf (tmp_sql, - "SELECT count(*) FROM `%s` WHERE `account_id` = '%d' AND `char_num` = '%d'", - char_db, sd->account_id, dat[30]); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error - %s\n", mysql_error (&mysql_handle)); - } - sql_res = mysql_store_result (&mysql_handle); - sql_row = mysql_fetch_row (sql_res); - - //printf("slot check result : %s\n",sql_row[0]); - if (atoi (sql_row[0]) > 0) - { - mysql_free_result (sql_res); - return -1; - } - else - mysql_free_result (sql_res); - - char_id_count++; - - // make new char. - sprintf (tmp_sql, - "INSERT INTO `%s` (`char_id`,`account_id`,`char_num`,`name`,`zeny`,`str`,`agi`,`vit`,`int`,`dex`,`luk`,`max_hp`,`hp`,`max_sp`,`sp`,`hair`,`hair_color`)" - " VALUES ('%d', '%d', '%d', '%s', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d','%d', '%d','%d', '%d')", - char_db, char_id_count, sd->account_id, dat[30], t_name, - start_zeny, dat[24], dat[25], dat[26], dat[27], dat[28], dat[29], - (40 * (100 + dat[26]) / 100), (40 * (100 + dat[26]) / 100), - (11 * (100 + dat[27]) / 100), (11 * (100 + dat[27]) / 100), - dat[33], dat[31]); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (insert `char`)- %s\n", - mysql_error (&mysql_handle)); - } - - //`inventory` (`id`,`char_id`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `card0`, `card1`, `card2`, `card3`) - sprintf (tmp_sql, "INSERT INTO `%s` (`char_id`,`nameid`, `amount`, `equip`, `identify`) VALUES ('%d', '%d', '%d', '%d', '%d')", inventory_db, char_id_count, 1201, 1, 0x02, 1); //add Knife - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (insert `inventory`)- %s\n", - mysql_error (&mysql_handle)); - } - - sprintf (tmp_sql, "INSERT INTO `%s` (`char_id`,`nameid`, `amount`, `equip`, `identify`) VALUES ('%d', '%d', '%d', '%d', '%d')", inventory_db, char_id_count, 2301, 1, 0x10, 1); //add Cotton Shirt - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (insert `inventory`)- %s\n", - mysql_error (&mysql_handle)); - } - // respawn map and start point set - sprintf (tmp_sql, - "UPDATE `%s` SET `last_map`='%s',`last_x`='%d',`last_y`='%d',`save_map`='%s',`save_x`='%d',`save_y`='%d' WHERE `char_id` = '%d'", - char_db, start_point.map, start_point.x, start_point.y, - start_point.map, start_point.x, start_point.y, char_id_count); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (update `char`)- %s\n", - mysql_error (&mysql_handle)); - } - printf - ("making new char success - id:(\033[1;32m%d\033[0m\tname:\033[1;32%s\033[0m\n", - char_id_count, t_name); - return char_id_count; -} - -//========================================================================================================== - -void mmo_char_sync (void) -{ - printf ("mmo_char_sync() - nothing to do\n"); -} - -// to do -/////////////////////////// - -int mmo_char_sync_timer (int tid, unsigned int tick, int id, int data) -{ - printf ("mmo_char_sync_timer() tic - no works to do\n"); - return 0; -} - -int count_users (void) -{ - int i, users; - - if (login_fd > 0 && session[login_fd]) - { - users = 0; - for (i = 0; i < MAX_MAP_SERVERS; i++) - { - if (server_fd[i] >= 0) - { - users += server[i].users; - } - } - return users; - } - return 0; -} - -int mmo_char_send006b (int fd, struct char_session_data *sd) -{ - int i, j, found_num = 0; - struct mmo_charstatus *p = NULL; -// hehe. commented other. anyway there's no need to use older version. -// if use older packet version just uncomment that! -//#ifdef NEW_006b - const int offset = 24; -//#else -// int offset = 4; -//#endif - - printf ("mmo_char_send006b start.. (account:%d)\n", sd->account_id); -// printf("offset -> %d...\n",offset); - - //search char. - sprintf (tmp_sql, "SELECT `char_id` FROM `%s` WHERE `account_id` = '%d'", - char_db, sd->account_id); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error - %s\n", mysql_error (&mysql_handle)); - } - sql_res = mysql_store_result (&mysql_handle); - if (sql_res) - { - found_num = mysql_num_rows (sql_res); - printf ("number of chars: %d\n", found_num); - i = 0; - while ((sql_row = mysql_fetch_row (sql_res))) - { - sd->found_char[i] = atoi (sql_row[0]); - i++; - } - mysql_free_result (sql_res); - } - -// printf("char fetching end (total: %d)....\n", found_num); - - for (i = found_num; i < 9; i++) - sd->found_char[i] = -1; - - memset (WFIFOP (fd, 0), 0, offset + found_num * 106); - WFIFOW (fd, 0) = 0x6b; - WFIFOW (fd, 2) = offset + found_num * 106; - - printf ("(\033[1;13m%d\033[0m) Request Char Data:\n", sd->account_id); - - for (i = 0; i < found_num; i++) - { - mmo_char_fromsql (sd->found_char[i], char_dat, 0); - - p = &char_dat[0]; - - j = offset + (i * 106); // increase speed of code - - WFIFOL (fd, j) = p->char_id; - WFIFOL (fd, j + 4) = p->base_exp; - WFIFOL (fd, j + 8) = p->zeny; - WFIFOL (fd, j + 12) = p->job_exp; - WFIFOL (fd, j + 16) = p->job_level; - - WFIFOL (fd, j + 20) = 0; - WFIFOL (fd, j + 24) = 0; - WFIFOL (fd, j + 28) = p->option; - - WFIFOL (fd, j + 32) = p->karma; - WFIFOL (fd, j + 36) = p->manner; - - WFIFOW (fd, j + 40) = p->status_point; - WFIFOW (fd, j + 42) = (p->hp > 0x7fff) ? 0x7fff : p->hp; - WFIFOW (fd, j + 44) = (p->max_hp > 0x7fff) ? 0x7fff : p->max_hp; - WFIFOW (fd, j + 46) = (p->sp > 0x7fff) ? 0x7fff : p->sp; - WFIFOW (fd, j + 48) = (p->max_sp > 0x7fff) ? 0x7fff : p->max_sp; - WFIFOW (fd, j + 50) = DEFAULT_WALK_SPEED; // p->speed; - WFIFOW (fd, j + 52) = p->class; - WFIFOW (fd, j + 54) = p->hair; - WFIFOW (fd, j + 56) = p->weapon; - WFIFOW (fd, j + 58) = p->base_level; - WFIFOW (fd, j + 60) = p->skill_point; - WFIFOW (fd, j + 62) = p->head_bottom; - WFIFOW (fd, j + 64) = p->shield; - WFIFOW (fd, j + 66) = p->head_top; - WFIFOW (fd, j + 68) = p->head_mid; - WFIFOW (fd, j + 70) = p->hair_color; - WFIFOW (fd, j + 72) = p->clothes_color; - - memcpy (WFIFOP (fd, j + 74), p->name, 24); - - WFIFOB (fd, j + 98) = (p->str > 255) ? 255 : p->str; - WFIFOB (fd, j + 99) = (p->agi > 255) ? 255 : p->agi; - WFIFOB (fd, j + 100) = (p->vit > 255) ? 255 : p->vit; - WFIFOB (fd, j + 101) = (p->int_ > 255) ? 255 : p->int_; - WFIFOB (fd, j + 102) = (p->dex > 255) ? 255 : p->dex; - WFIFOB (fd, j + 103) = (p->luk > 255) ? 255 : p->luk; - WFIFOB (fd, j + 104) = p->char_num; - } - - WFIFOSET (fd, WFIFOW (fd, 2)); -// printf("mmo_char_send006b end..\n"); - return 0; -} - -int parse_tologin (int fd) -{ - int i; - struct char_session_data *sd; - - // only login-server can have an access to here. - // so, if it isn't the login-server, we disconnect the session. - //session eof check! - if (fd != login_fd || session[fd]->eof) - { - if (fd == login_fd) - { - printf - ("Char-server can't connect to login-server (connection #%d).\n", - fd); - login_fd = -1; - } - close (fd); - delete_session (fd); - return 0; - } - - sd = session[fd]->session_data; - - // hehe. no need to set user limite on SQL version. :P - // but char limitation is good way to maintain server. :D - while (RFIFOREST (fd) >= 2) - { -// printf("parse_tologin : %d %d %x\n", fd, RFIFOREST(fd), RFIFOW(fd, 0)); - - switch (RFIFOW (fd, 0)) - { - case 0x2711: - if (RFIFOREST (fd) < 3) - return 0; - if (RFIFOB (fd, 2)) - { - //printf("connect login server error : %d\n", RFIFOB(fd, 2)); - printf ("Can not connect to login-server.\n"); - printf - ("The server communication passwords (default s1/p1) is probably invalid.\n"); - printf - ("Also, please make sure your login db has the username/password present and the sex of the account is S.\n"); - printf - ("If you changed the communication passwords, change them back at map_athena.conf and char_athena.conf\n"); - return 0; - //exit(1); //fixed for server shutdown. - } - else - { - printf ("Connected to login-server (connection #%d).\n", - fd); - // if no map-server already connected, display a message... - for (i = 0; i < MAX_MAP_SERVERS; i++) - if (server_fd[i] >= 0 && server[i].map[0][0]) // if map-server online and at least 1 map - break; - if (i == MAX_MAP_SERVERS) - printf ("Awaiting maps from map-server.\n"); - } - RFIFOSKIP (fd, 3); - break; - - case 0x2713: - if (RFIFOREST (fd) < 51) - return 0; - for (i = 0; i < fd_max; i++) - { - if (session[i] && (sd = session[i]->session_data) - && sd->account_id == RFIFOL (fd, 2)) - { - if (RFIFOB (fd, 6) != 0) - { - WFIFOW (i, 0) = 0x6c; - WFIFOB (i, 2) = 0x42; - WFIFOSET (i, 3); - } - else if (max_connect_user == 0 - || count_users () < max_connect_user) - { -// if (max_connect_user == 0) -// printf("max_connect_user (unlimited) -> accepted.\n"); -// else -// printf("count_users(): %d < max_connect_user (%d) -> accepted.\n", count_users(), max_connect_user); - sd->connect_until_time = (time_t) RFIFOL (fd, 47); - // send characters to player - mmo_char_send006b (i, sd); - } - else - { - // refuse connection: too much online players -// printf("count_users(): %d < max_connect_use (%d) -> fail...\n", count_users(), max_connect_user); - WFIFOW (i, 0) = 0x6c; - WFIFOW (i, 2) = 0; - WFIFOSET (i, 3); - } - } - } - RFIFOSKIP (fd, 51); - break; - - case 0x2717: - if (RFIFOREST (fd) < 50) - return 0; - for (i = 0; i < fd_max; i++) - { - if (session[i] && (sd = session[i]->session_data)) - { - if (sd->account_id == RFIFOL (fd, 2)) - { - sd->connect_until_time = (time_t) RFIFOL (fd, 46); - break; - } - } - } - RFIFOSKIP (fd, 50); - break; - -/* case 0x2721: // gm reply. I don't want to support this function. - printf("0x2721:GM reply\n"); - { - int oldacc, newacc; - unsigned char buf[64]; - if (RFIFOREST(fd) < 10) - return 0; - oldacc = RFIFOL(fd, 2); - newacc = RFIFOL(fd, 6); - RFIFOSKIP(fd, 10); - if (newacc > 0) { - for(i=0;i map\n"); - } - break; -*/ - case 0x2723: // changesex reply (modified by [Yor]) - if (RFIFOREST (fd) < 7) - return 0; - { - int acc, sex; - unsigned char buf[16]; - - acc = RFIFOL (fd, 2); - sex = RFIFOB (fd, 6); - RFIFOSKIP (fd, 7); - if (acc > 0) - { - sprintf (tmp_sql, - "SELECT `char_id`,`class`,`skill_point` FROM `%s` WHERE `account_id` = '%d'", - char_db, acc); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (select `char`)- %s\n", - mysql_error (&mysql_handle)); - } - sql_res = mysql_store_result (&mysql_handle); - - if (sql_res) - { - sql_row = mysql_fetch_row (sql_res); - int char_id = atoi (sql_row[0]); - int jobclass = atoi (sql_row[1]); - int skill_point = atoi (sql_row[2]); - int class = jobclass; - if (jobclass == 19 || jobclass == 20 || - jobclass == 4020 || jobclass == 4021 || - jobclass == 4042 || jobclass == 4043) - { - // job modification - if (jobclass == 19 || jobclass == 20) - { - class = (sex) ? 19 : 20; - } - else if (jobclass == 4020 || jobclass == 4021) - { - class = (sex) ? 4020 : 4021; - } - else if (jobclass == 4042 || jobclass == 4043) - { - class = (sex) ? 4042 : 4043; - } - // remove specifical skills of classes 19,20 4020,4021 and 4042,4043 - sprintf (tmp_sql, - "SELECT `lv` FROM `%s` WHERE `char_id` = '%d' AND `id` >= '315' AND `id` <= '330'", - skill_db, char_id); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf - ("DB server Error (select `char`)- %s\n", - mysql_error (&mysql_handle)); - } - sql_res = mysql_store_result (&mysql_handle); - if (sql_res) - { - while ((sql_row = - mysql_fetch_row (sql_res))) - { - skill_point += atoi (sql_row[0]); - } - } - sprintf (tmp_sql, - "DELETE FROM `%s` WHERE `char_id` = '%d' AND `id` >= '315' AND `id` <= '330'", - skill_db, char_id); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf - ("DB server Error (select `char`)- %s\n", - mysql_error (&mysql_handle)); - } - } - // to avoid any problem with equipment and invalid sex, equipment is unequiped. - sprintf (tmp_sql, - "UPDATE `%s` SET `equip` = '0' WHERE `char_id` = '%d'", - inventory_db, char_id); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf - ("DB server Error (select `char`)- %s\n", - mysql_error (&mysql_handle)); - } - sprintf (tmp_sql, - "UPDATE `%s` SET `class`='%d' , `skill_point`='%d' , `weapon`='0' , `shield='0' , `head_top`='0' , `head_mid`='0' , `head_bottom`='0' WHERE `char_id` = '%d'", - char_db, class, skill_point, char_id); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf - ("DB server Error (select `char`)- %s\n", - mysql_error (&mysql_handle)); - } - } - } - // disconnect player if online on char-server - for (i = 0; i < fd_max; i++) - { - if (session[i] && (sd = session[i]->session_data)) - { - if (sd->account_id == acc) - { - session[i]->eof = 1; - break; - } - } - } - - WBUFW (buf, 0) = 0x2b0d; - WBUFL (buf, 2) = acc; - WBUFB (buf, 6) = sex; - - mapif_sendall (buf, 7); - } - break; - - // account_reg2変更通知 - case 0x2729: - if (RFIFOREST (fd) < 4 || RFIFOREST (fd) < RFIFOW (fd, 2)) - return 0; - { - struct global_reg reg[ACCOUNT_REG2_NUM]; - unsigned char buf[4096]; - int j, p, acc; - acc = RFIFOL (fd, 4); - for (p = 8, j = 0; - p < RFIFOW (fd, 2) && j < ACCOUNT_REG2_NUM; - p += 36, j++) - { - memcpy (reg[j].str, RFIFOP (fd, p), 32); - reg[j].value = RFIFOL (fd, p + 32); - } - // set_account_reg2(acc,j,reg); - // 同垢ログインを禁止していれば送る必要は無い - memcpy (buf, RFIFOP (fd, 0), RFIFOW (fd, 2)); - WBUFW (buf, 0) = 0x2b11; - mapif_sendall (buf, WBUFW (buf, 2)); - RFIFOSKIP (fd, RFIFOW (fd, 2)); -// printf("char: save_account_reg_reply\n"); - } - break; - - // State change of account/ban notification (from login-server) by [Yor] - case 0x2731: - if (RFIFOREST (fd) < 11) - return 0; - // send to all map-servers to disconnect the player - { - unsigned char buf[16]; - WBUFW (buf, 0) = 0x2b14; - WBUFL (buf, 2) = RFIFOL (fd, 2); - WBUFB (buf, 6) = RFIFOB (fd, 6); // 0: change of statut, 1: ban - WBUFL (buf, 7) = RFIFOL (fd, 7); // status or final date of a banishment - mapif_sendall (buf, 11); - } - // disconnect player if online on char-server - for (i = 0; i < fd_max; i++) - { - if (session[i] && (sd = session[i]->session_data)) - { - if (sd->account_id == RFIFOL (fd, 2)) - { - session[i]->eof = 1; - break; - } - } - } - RFIFOSKIP (fd, 11); - break; - - default: - printf ("set eof.\n"); - session[fd]->eof = 1; - return 0; - } - } - - RFIFOFLUSH (fd); - - return 0; -} - -//-------------------------------- -// Map-server anti-freeze system -//-------------------------------- -int map_anti_freeze_system (int tid, unsigned int tick, int id, int data) -{ - int i; - - for (i = 0; i < MAX_MAP_SERVERS; i++) - { - if (server_fd[i] >= 0) - { // if map-server is online - printf ("map_anti_freeze_system: server #%d, flag: %d.\n", i, - server_freezeflag[i]); - if (server_freezeflag[i]-- < 1) - { // Map-server anti-freeze system. Counter. 5 ok, 4...0 freezed - printf - ("Map-server anti-freeze system: char-server #%d is frozen -> disconnection.\n", - i); - session[server_fd[i]]->eof = 1; - sprintf (tmp_sql, - "DELETE FROM `ragsrvinfo` WHERE `index`='%d'", - server_fd[i]); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error - %s\n", - mysql_error (&mysql_handle)); - } - } - } - } - - return 0; -} - -int parse_frommap (int fd) -{ - int i = 0, j = 0; - int id; - - // Sometimes fd=0, and it will cause server crash. Don't know why. :( - if (fd <= 0) - { - printf ("parse_frommap error fd=0\n"); - return 0; - } - - for (id = 0; id < MAX_MAP_SERVERS; id++) - if (server_fd[id] == fd) - break; - if (id == MAX_MAP_SERVERS || session[fd]->eof) - { - if (id < MAX_MAP_SERVERS) - { - memset (&server[id], 0, sizeof (struct mmo_map_server)); - printf ("Map-server %d (session #%d) has disconnected.\n", id, - fd); - sprintf (tmp_sql, "DELETE FROM `ragsrvinfo` WHERE `index`='%d'", - server_fd[id]); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error - %s\n", - mysql_error (&mysql_handle)); - } - server_fd[id] = -1; - } - close (fd); - delete_session (fd); - return 0; - } - - while (RFIFOREST (fd) >= 2) - { -// printf("parse_frommap : %d %d %x\n", fd, RFIFOREST(fd), RFIFOW(fd,0)); - - switch (RFIFOW (fd, 0)) - { - case 0x2af7: - RFIFOSKIP (fd, 2); - read_gm_account (); - break; - - // mapserver -> map names recv. - case 0x2afa: - if (RFIFOREST (fd) < 4 || RFIFOREST (fd) < RFIFOW (fd, 2)) - return 0; - memset (server[id].map, 0, sizeof (server[id].map)); - j = 0; - for (i = 4; i < RFIFOW (fd, 2); i += 16) - { - memcpy (server[id].map[j], RFIFOP (fd, i), 16); -// printf("set map %d.%d : %s\n", id, j, server[id].map[j]); - j++; - } - i = server[id].ip; - { - unsigned char *p = (unsigned char *) &server[id].ip; - printf - ("Map-Server %d connected: %d maps, from IP %d.%d.%d.%d port %d.\n", - id, j, p[0], p[1], p[2], p[3], server[id].port); - printf ("Map-server %d loading complete.\n", id); - } - WFIFOW (fd, 0) = 0x2afb; - WFIFOB (fd, 2) = 0; - memcpy (WFIFOP (fd, 3), wisp_server_name, 24); // name for wisp to player - WFIFOSET (fd, 27); - { - unsigned char buf[16384]; - int x; - if (j == 0) - { - printf ("WARNING: Map-Server %d have NO maps.\n", id); - // Transmitting maps information to the other map-servers - } - else - { - WBUFW (buf, 0) = 0x2b04; - WBUFW (buf, 2) = j * 16 + 10; - WBUFL (buf, 4) = server[id].ip; - WBUFW (buf, 8) = server[id].port; - memcpy (WBUFP (buf, 10), RFIFOP (fd, 4), j * 16); - mapif_sendallwos (fd, buf, WBUFW (buf, 2)); - } - // Transmitting the maps of the other map-servers to the new map-server - for (x = 0; x < MAX_MAP_SERVERS; x++) - { - if (server_fd[x] >= 0 && x != id) - { - WFIFOW (fd, 0) = 0x2b04; - WFIFOL (fd, 4) = server[x].ip; - WFIFOW (fd, 8) = server[x].port; - j = 0; - for (i = 0; i < MAX_MAP_PER_SERVER; i++) - if (server[x].map[i][0]) - memcpy (WFIFOP (fd, 10 + (j++) * 16), - server[x].map[i], 16); - if (j > 0) - { - WFIFOW (fd, 2) = j * 16 + 10; - WFIFOSET (fd, WFIFOW (fd, 2)); - } - } - } - } - RFIFOSKIP (fd, RFIFOW (fd, 2)); - break; - - // auth request - case 0x2afc: - if (RFIFOREST (fd) < 22) - return 0; -// printf("(AUTH request) auth_fifo search %d %d %d\n", RFIFOL(fd, 2), RFIFOL(fd, 6), RFIFOL(fd, 10)); - for (i = 0; i < AUTH_FIFO_SIZE; i++) - { - if (auth_fifo[i].account_id == RFIFOL (fd, 2) && - auth_fifo[i].char_id == RFIFOL (fd, 6) && - auth_fifo[i].login_id1 == RFIFOL (fd, 10) && -#if CMP_AUTHFIFO_LOGIN2 != 0 - // here, it's the only area where it's possible that we doesn't know login_id2 (map-server asks just after 0x72 packet, that doesn't given the value) - (auth_fifo[i].login_id2 == RFIFOL (fd, 14) || RFIFOL (fd, 14) == 0) && // relate to the versions higher than 18 -#endif - (!check_ip_flag || auth_fifo[i].ip == RFIFOL (fd, 18)) - && !auth_fifo[i].delflag) - { - auth_fifo[i].delflag = 1; - WFIFOW (fd, 0) = 0x2afd; - WFIFOW (fd, 2) = 16 + sizeof (struct mmo_charstatus); - WFIFOL (fd, 4) = RFIFOL (fd, 2); - WFIFOL (fd, 8) = auth_fifo[i].login_id2; - WFIFOL (fd, 12) = - (unsigned long) auth_fifo[i].connect_until_time; - mmo_char_fromsql (auth_fifo[i].char_id, char_dat, 1); - char_dat[0].sex = auth_fifo[i].sex; - memcpy (WFIFOP (fd, 16), &char_dat[0], - sizeof (struct mmo_charstatus)); - WFIFOSET (fd, WFIFOW (fd, 2)); - //printf("auth_fifo search success (auth #%d, account %d, character: %d).\n", i, RFIFOL(fd,2), RFIFOL(fd,6)); - break; - } - } - if (i == AUTH_FIFO_SIZE) - { - WFIFOW (fd, 0) = 0x2afe; - WFIFOL (fd, 2) = RFIFOL (fd, 2); - WFIFOSET (fd, 6); -// printf("(AUTH request) auth_fifo search error!\n"); - } - RFIFOSKIP (fd, 22); - break; - - // set MAP user - case 0x2aff: - if (RFIFOREST (fd) < 6 || RFIFOREST (fd) < RFIFOW (fd, 2)) - return 0; - if (RFIFOW (fd, 4) != server[id].users) - printf ("map user: %d\n", RFIFOW (fd, 4)); - server[id].users = RFIFOW (fd, 4); - if (anti_freeze_enable) - server_freezeflag[id] = 5; // Map anti-freeze system. Counter. 5 ok, 4...0 freezed - RFIFOSKIP (fd, RFIFOW (fd, 2)); - break; - - // char saving - case 0x2b01: - i = 0; - if (RFIFOREST (fd) < 4 || RFIFOREST (fd) < RFIFOW (fd, 2)) - return 0; - //check account - sprintf (tmp_sql, - "SELECT count(*) FROM `%s` WHERE `account_id` = '%d' AND `char_id`='%d'", - char_db, RFIFOL (fd, 4), RFIFOL (fd, 8)); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error - %s\n", - mysql_error (&mysql_handle)); - } - sql_res = mysql_store_result (&mysql_handle); - if (sql_res) - { - sql_row = mysql_fetch_row (sql_res); - if (sql_row) - i = atoi (sql_row[0]); - } - mysql_free_result (sql_res); - - if (i == 1) - { - memcpy (&char_dat[0], RFIFOP (fd, 12), - sizeof (struct mmo_charstatus)); - mmo_char_tosql (RFIFOL (fd, 8), char_dat); - //save to DB - } - RFIFOSKIP (fd, RFIFOW (fd, 2)); - break; - - // req char selection - case 0x2b02: - if (RFIFOREST (fd) < 18) - return 0; - - if (auth_fifo_pos >= AUTH_FIFO_SIZE) - auth_fifo_pos = 0; - -// printf("(charselect) auth_fifo set %d - account_id:%08x login_id1:%08x\n", auth_fifo_pos, RFIFOL(fd, 2), RFIFOL(fd, 6)); - auth_fifo[auth_fifo_pos].account_id = RFIFOL (fd, 2); - auth_fifo[auth_fifo_pos].char_id = 0; - auth_fifo[auth_fifo_pos].login_id1 = RFIFOL (fd, 6); - auth_fifo[auth_fifo_pos].login_id2 = RFIFOL (fd, 10); - auth_fifo[auth_fifo_pos].delflag = 2; - auth_fifo[auth_fifo_pos].char_pos = 0; - auth_fifo[auth_fifo_pos].connect_until_time = 0; // unlimited/unknown time by default (not display in map-server) - auth_fifo[auth_fifo_pos].ip = RFIFOL (fd, 14); - auth_fifo_pos++; - - WFIFOW (fd, 0) = 0x2b03; - WFIFOL (fd, 2) = RFIFOL (fd, 2); - WFIFOB (fd, 6) = 0; - WFIFOSET (fd, 7); - - RFIFOSKIP (fd, 18); - break; - - // request "change map server" - case 0x2b05: - if (RFIFOREST (fd) < 49) - return 0; - - if (auth_fifo_pos >= AUTH_FIFO_SIZE) - auth_fifo_pos = 0; - - WFIFOW (fd, 0) = 0x2b06; - memcpy (WFIFOP (fd, 2), RFIFOP (fd, 2), 42); -// printf("(map change) auth_fifo set %d - account_id:%08x login_id1:%08x\n", auth_fifo_pos, RFIFOL(fd, 2), RFIFOL(fd, 6)); - auth_fifo[auth_fifo_pos].account_id = RFIFOL (fd, 2); - auth_fifo[auth_fifo_pos].login_id1 = RFIFOL (fd, 6); - auth_fifo[auth_fifo_pos].login_id2 = RFIFOL (fd, 10); - auth_fifo[auth_fifo_pos].char_id = RFIFOL (fd, 14); - auth_fifo[auth_fifo_pos].delflag = 0; - auth_fifo[auth_fifo_pos].sex = RFIFOB (fd, 44); - auth_fifo[auth_fifo_pos].ip = RFIFOL (fd, 45); - - sprintf (tmp_sql, - "SELECT count(*) FROM `%s` WHERE `account_id` = '%d' AND `char_id`='%d'", - char_db, RFIFOL (fd, 2), RFIFOL (fd, 14)); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error - %s\n", - mysql_error (&mysql_handle)); - } - sql_res = mysql_store_result (&mysql_handle); - - if ((sql_row = mysql_fetch_row (sql_res))) - { - i = atoi (sql_row[0]); - mysql_free_result (sql_res); - - auth_fifo[auth_fifo_pos].char_pos = - auth_fifo[auth_fifo_pos].char_id; - auth_fifo_pos++; - - WFIFOL (fd, 6) = 0; - break; - } - if (i == 0) - WFIFOW (fd, 6) = 1; - - WFIFOSET (fd, 44); - RFIFOSKIP (fd, 49); - break; - - // char name check - case 0x2b08: - if (RFIFOREST (fd) < 6) - return 0; - - sprintf (tmp_sql, - "SELECT `name` FROM `%s` WHERE `char_id`='%d'", - char_db, RFIFOL (fd, 2)); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error - %s\n", - mysql_error (&mysql_handle)); - } - sql_res = mysql_store_result (&mysql_handle); - - sql_row = mysql_fetch_row (sql_res); - - WFIFOW (fd, 0) = 0x2b09; - WFIFOL (fd, 2) = RFIFOL (fd, 2); - - if (sql_row) - memcpy (WFIFOP (fd, 6), sql_row[0], 24); - else - memcpy (WFIFOP (fd, 6), unknown_char_name, 24); - mysql_free_result (sql_res); - - WFIFOSET (fd, 30); - - RFIFOSKIP (fd, 6); - break; - -/* // I want become GM - fuck! - case 0x2b0a: - if(RFIFOREST(fd)<4) - return 0; - if(RFIFOREST(fd) login %d %s %d\n", RFIFOL(fd, 4), RFIFOP(fd, 8), RFIFOW(fd, 2)); - RFIFOSKIP(fd, RFIFOW(fd, 2)); - break; - */ - - // account_reg保存要求 - case 0x2b10: - if (RFIFOREST (fd) < 4 || RFIFOREST (fd) < RFIFOW (fd, 2)) - return 0; - { - struct global_reg reg[ACCOUNT_REG2_NUM]; - int j, p, acc; - acc = RFIFOL (fd, 4); - for (p = 8, j = 0; - p < RFIFOW (fd, 2) && j < ACCOUNT_REG2_NUM; - p += 36, j++) - { - memcpy (reg[j].str, RFIFOP (fd, p), 32); - reg[j].value = RFIFOL (fd, p + 32); - } - // set_account_reg2(acc,j,reg); - // loginサーバーへ送る - if (login_fd > 0) - { // don't send request if no login-server - WFIFOW (login_fd, 0) = 0x2728; - memcpy (WFIFOP (login_fd, 0), RFIFOP (fd, 0), - RFIFOW (fd, 2)); - WFIFOSET (login_fd, WFIFOW (login_fd, 2)); - } - // ワールドへの同垢ログインがなければmapサーバーに送る必要はない - //memcpy(buf,RFIFOP(fd,0),RFIFOW(fd,2)); - //WBUFW(buf,0)=0x2b11; - //mapif_sendall(buf,WBUFW(buf,2)); - RFIFOSKIP (fd, RFIFOW (fd, 2)); -// printf("char: save_account_reg (from map)\n"); - } - break; - - // Map server send information to change an email of an account -> login-server - case 0x2b0c: - if (RFIFOREST (fd) < 86) - return 0; - if (login_fd > 0) - { // don't send request if no login-server - memcpy (WFIFOP (login_fd, 0), RFIFOP (fd, 0), 86); // 0x2722 .L .40B .40B - WFIFOW (login_fd, 0) = 0x2722; - WFIFOSET (login_fd, 86); - } - RFIFOSKIP (fd, 86); - break; - - // Receiving from map-server a status change resquest. Transmission to login-server (by Yor) - case 0x2b0e: - if (RFIFOREST (fd) < 44) - return 0; - { - char character_name[24]; - int acc = RFIFOL (fd, 2); // account_id of who ask (-1 if nobody) - memcpy (character_name, RFIFOP (fd, 6), 24); - character_name[sizeof (character_name) - 1] = '\0'; - // prepare answer - WFIFOW (fd, 0) = 0x2b0f; // answer - WFIFOL (fd, 2) = acc; // who want do operation - WFIFOW (fd, 30) = RFIFOW (fd, 30); // type of operation: 1-block, 2-ban, 3-unblock, 4-unban - sprintf (tmp_sql, - "SELECT `account_id`,`name` FROM `%s` WHERE `name` = '%s'", - char_db, character_name); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (select `char`)- %s\n", - mysql_error (&mysql_handle)); - } - - sql_res = mysql_store_result (&mysql_handle); - - if (sql_res) - { - if (mysql_num_rows (sql_res)) - { - sql_row = mysql_fetch_row (sql_res); - memcpy (WFIFOP (fd, 6), sql_row[1], 24); // put correct name if found - WFIFOW (fd, 32) = 0; // answer: 0-login-server resquest done, 1-player not found, 2-gm level too low, 3-login-server offline - switch (RFIFOW (fd, 30)) - { - case 1: // block - if (acc == -1 - || isGM (acc) >= - isGM (atoi (sql_row[0]))) - { - if (login_fd > 0) - { // don't send request if no login-server - WFIFOW (login_fd, 0) = 0x2724; - WFIFOL (login_fd, 2) = atoi (sql_row[0]); // account value - WFIFOL (login_fd, 6) = 5; // status of the account - WFIFOSET (login_fd, 10); -// printf("char : status -> login: account %d, status: %d \n", char_dat[i].account_id, 5); - } - else - WFIFOW (fd, 32) = 3; // answer: 0-login-server resquest done, 1-player not found, 2-gm level too low, 3-login-server offline - } - else - WFIFOW (fd, 32) = 2; // answer: 0-login-server resquest done, 1-player not found, 2-gm level too low, 3-login-server offline - break; - case 2: // ban - if (acc == -1 - || isGM (acc) >= - isGM (atoi (sql_row[0]))) - { - if (login_fd > 0) - { // don't send request if no login-server - WFIFOW (login_fd, 0) = 0x2725; - WFIFOL (login_fd, 2) = atoi (sql_row[0]); // account value - WFIFOW (login_fd, 6) = RFIFOW (fd, 32); // year - WFIFOW (login_fd, 8) = RFIFOW (fd, 34); // month - WFIFOW (login_fd, 10) = RFIFOW (fd, 36); // day - WFIFOW (login_fd, 12) = RFIFOW (fd, 38); // hour - WFIFOW (login_fd, 14) = RFIFOW (fd, 40); // minute - WFIFOW (login_fd, 16) = RFIFOW (fd, 42); // second - WFIFOSET (login_fd, 18); -// printf("char : status -> login: account %d, ban: %dy %dm %dd %dh %dmn %ds\n", -// char_dat[i].account_id, (short)RFIFOW(fd,32), (short)RFIFOW(fd,34), (short)RFIFOW(fd,36), (short)RFIFOW(fd,38), (short)RFIFOW(fd,40), (short)RFIFOW(fd,42)); - } - else - WFIFOW (fd, 32) = 3; // answer: 0-login-server resquest done, 1-player not found, 2-gm level too low, 3-login-server offline - } - else - WFIFOW (fd, 32) = 2; // answer: 0-login-server resquest done, 1-player not found, 2-gm level too low, 3-login-server offline - break; - case 3: // unblock - if (acc == -1 - || isGM (acc) >= - isGM (atoi (sql_row[0]))) - { - if (login_fd > 0) - { // don't send request if no login-server - WFIFOW (login_fd, 0) = 0x2724; - WFIFOL (login_fd, 2) = atoi (sql_row[0]); // account value - WFIFOL (login_fd, 6) = 0; // status of the account - WFIFOSET (login_fd, 10); -// printf("char : status -> login: account %d, status: %d \n", char_dat[i].account_id, 0); - } - else - WFIFOW (fd, 32) = 3; // answer: 0-login-server resquest done, 1-player not found, 2-gm level too low, 3-login-server offline - } - else - WFIFOW (fd, 32) = 2; // answer: 0-login-server resquest done, 1-player not found, 2-gm level too low, 3-login-server offline - break; - case 4: // unban - if (acc == -1 - || isGM (acc) >= - isGM (atoi (sql_row[0]))) - { - if (login_fd > 0) - { // don't send request if no login-server - WFIFOW (login_fd, 0) = 0x272a; - WFIFOL (login_fd, 2) = atoi (sql_row[0]); // account value - WFIFOSET (login_fd, 6); -// printf("char : status -> login: account %d, unban request\n", char_dat[i].account_id); - } - else - WFIFOW (fd, 32) = 3; // answer: 0-login-server resquest done, 1-player not found, 2-gm level too low, 3-login-server offline - } - else - WFIFOW (fd, 32) = 2; // answer: 0-login-server resquest done, 1-player not found, 2-gm level too low, 3-login-server offline - break; - case 5: // changesex - if (acc == -1 - || isGM (acc) >= - isGM (atoi (sql_row[0]))) - { - if (login_fd > 0) - { // don't send request if no login-server - WFIFOW (login_fd, 0) = 0x2727; - WFIFOL (login_fd, 2) = atoi (sql_row[0]); // account value - WFIFOSET (login_fd, 6); -// printf("char : status -> login: account %d, change sex request\n", char_dat[i].account_id); - } - else - WFIFOW (fd, 32) = 3; // answer: 0-login-server resquest done, 1-player not found, 2-gm level too low, 3-login-server offline - } - else - WFIFOW (fd, 32) = 2; // answer: 0-login-server resquest done, 1-player not found, 2-gm level too low, 3-login-server offline - break; - } - } - else - { - // character name not found - memcpy (WFIFOP (fd, 6), character_name, 24); - WFIFOW (fd, 32) = 1; // answer: 0-login-server resquest done, 1-player not found, 2-gm level too low, 3-login-server offline - } - // send answer if a player ask, not if the server ask - if (acc != -1) - { - WFIFOSET (fd, 34); - } - } - } - RFIFOSKIP (fd, 44); - break; - - // Recieve rates [Wizputer] - case 0x2b16: - if (RFIFOREST (fd) < 6 || RFIFOREST (fd) < RFIFOW (fd, 8)) - return 0; - sprintf (tmp_sql, - "INSERT INTO `ragsrvinfo` SET `index`='%d',`name`='%s',`exp`='%d',`jexp`='%d',`drop`='%d',`motd`='%s'", - fd, server_name, RFIFOW (fd, 2), RFIFOW (fd, 4), - RFIFOW (fd, 6), RFIFOP (fd, 10)); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error - %s\n", - mysql_error (&mysql_handle)); - } - RFIFOSKIP (fd, RFIFOW (fd, 8)); - break; - - // Character disconnected set online 0 [Wizputer] - case 0x2b17: - if (RFIFOREST (fd) < 6) - return 0; - //printf("Setting %d char offline\n",RFIFOL(fd,2)); - sprintf (tmp_sql, - "UPDATE `%s` SET `online`='0' WHERE `char_id`='%d'", - char_db, RFIFOL (fd, 2)); - if (mysql_query (&mysql_handle, tmp_sql)) - printf ("DB server Error (update online `%s`)- %s\n", - char_db, mysql_error (&mysql_handle)); - RFIFOSKIP (fd, 6); - break; - - default: - // inter server - packet - { - int r = inter_parse_frommap (fd); - if (r == 1) - break; // processed - if (r == 2) - return 0; // need more packet - } - - // no inter server packet. no char server packet -> disconnect - printf ("parse_frommap: unknown packet %x! \n", - RFIFOW (fd, 0)); - session[fd]->eof = 1; - return 0; - } - } - return 0; -} - -int search_mapserver (char *map) -{ - int i, j; - char temp_map[16]; - int temp_map_len; - -// printf("Searching the map-server for map '%s'... ", map); - strncpy (temp_map, map, sizeof (temp_map)); - temp_map[sizeof (temp_map) - 1] = '\0'; - if (strchr (temp_map, '.') != NULL) - temp_map[strchr (temp_map, '.') - temp_map + 1] = '\0'; // suppress the '.gat', but conserve the '.' to be sure of the name of the map - - temp_map_len = strlen (temp_map); - for (i = 0; i < MAX_MAP_SERVERS; i++) - if (server_fd[i] >= 0) - for (j = 0; server[i].map[j][0]; j++) - //printf("%s : %s = %d\n", server[i].map[j], map, strncmp(server[i].map[j], temp_map, temp_map_len)); - if (strncmp (server[i].map[j], temp_map, temp_map_len) == 0) - { -// printf("found -> server #%d.\n", i); - return i; - } - -// printf("not found.\n"); - return -1; -} - -int char_mapif_init (int fd) -{ - return inter_mapif_init (fd); -} - -//----------------------------------------------------- -// Test to know if an IP come from LAN or WAN. by [Yor] -//----------------------------------------------------- -int lan_ip_check (unsigned char *p) -{ - int i; - int lancheck = 1; - int subneti[4]; - unsigned int k0, k1, k2, k3; - - sscanf (lan_map_ip, "%d.%d.%d.%d", &k0, &k1, &k2, &k3); - subneti[0] = k0; - subneti[1] = k1; - subneti[2] = k2; - subneti[3] = k3; - -// printf("lan_ip_check: to compare: %d.%d.%d.%d, network: %d.%d.%d.%d/%d.%d.%d.%d\n", -// p[0], p[1], p[2], p[3], -// subneti[0], subneti[1], subneti[2], subneti[3], -// subnetmaski[0], subnetmaski[1], subnetmaski[2], subnetmaski[3]); - for (i = 0; i < 4; i++) - { - if ((subneti[i] & subnetmaski[i]) != (p[i] & subnetmaski[i])) - { - lancheck = 0; - break; - } - } -// printf("LAN test (result): %s source\033[0m.\n", (lancheck) ? "\033[1;36mLAN" : "\033[1;32mWAN"); - return lancheck; -} - -int parse_char (int fd) -{ - int i, ch = 0; - char email[40]; - struct char_session_data *sd; - unsigned char *p = (unsigned char *) &session[fd]->client_addr.sin_addr; - - if (login_fd < 0 || session[fd]->eof) - { - if (fd == login_fd) - login_fd = -1; - close (fd); - delete_session (fd); - return 0; - } - - sd = session[fd]->session_data; - - while (RFIFOREST (fd) >= 2) - { -// if (RFIFOW(fd, 0) < 30000) -// printf("parse_char : %d %d %x\n", fd, RFIFOREST(fd), RFIFOW(fd, 0)); - - switch (RFIFOW (fd, 0)) - { - case 0x20b: //20040622 encryption ragexe correspondence - if (RFIFOREST (fd) < 19) - return 0; - RFIFOSKIP (fd, 19); - break; - - case 0x65: // request to connect - printf - ("request connect - account_id:%d/login_id1:%d/login_id2:%d\n", - RFIFOL (fd, 2), RFIFOL (fd, 6), RFIFOL (fd, 10)); - if (RFIFOREST (fd) < 17) - return 0; - { -/*removed from isGM setup - if (isGM(RFIFOL(fd,2))) - printf("Account Logged On; Account ID: %d (GM level %d).\n", RFIFOL(fd,2), isGM(RFIFOL(fd,2))); - else - printf("Account Logged On; Account ID: %d.\n", RFIFOL(fd,2)); -*/ - if (sd == NULL) - { - CREATE (session[fd]->session_data, - struct char_session_data, 1); - sd = session[fd]->session_data; - sd->connect_until_time = 0; // unknow or illimited (not displaying on map-server) - } - sd->account_id = RFIFOL (fd, 2); - sd->login_id1 = RFIFOL (fd, 6); - sd->login_id2 = RFIFOL (fd, 10); - sd->sex = RFIFOB (fd, 16); - - WFIFOL (fd, 0) = RFIFOL (fd, 2); - WFIFOSET (fd, 4); - - for (i = 0; i < AUTH_FIFO_SIZE; i++) - { - if (auth_fifo[i].account_id == sd->account_id && - auth_fifo[i].login_id1 == sd->login_id1 && -#if CMP_AUTHFIFO_LOGIN2 != 0 - auth_fifo[i].login_id2 == sd->login_id2 && // relate to the versions higher than 18 -#endif - (!check_ip_flag - || auth_fifo[i].ip == - session[fd]->client_addr.sin_addr.s_addr) - && auth_fifo[i].delflag == 2) - { - auth_fifo[i].delflag = 1; - - if (max_connect_user == 0 - || count_users () < max_connect_user) - { - if (login_fd > 0) - { // don't send request if no login-server - // request to login-server to obtain e-mail/time limit - WFIFOW (login_fd, 0) = 0x2716; - WFIFOL (login_fd, 2) = sd->account_id; - WFIFOSET (login_fd, 6); - } - // send characters to player - mmo_char_send006b (fd, sd); - } - else - { - // refuse connection (over populated) - WFIFOW (fd, 0) = 0x6c; - WFIFOW (fd, 2) = 0; - WFIFOSET (fd, 3); - } -// printf("connection request> set delflag 1(o:2)- account_id:%d/login_id1:%d(fifo_id:%d)\n", sd->account_id, sd->login_id1, i); - break; - } - } - if (i == AUTH_FIFO_SIZE) - { - if (login_fd > 0) - { // don't send request if no login-server - WFIFOW (login_fd, 0) = 0x2712; // ask login-server to authentify an account - WFIFOL (login_fd, 2) = sd->account_id; - WFIFOL (login_fd, 6) = sd->login_id1; - WFIFOL (login_fd, 10) = sd->login_id2; - WFIFOB (login_fd, 14) = sd->sex; - WFIFOL (login_fd, 15) = - session[fd]->client_addr.sin_addr.s_addr; - WFIFOSET (login_fd, 19); - } - else - { // if no login-server, we must refuse connection - WFIFOW (fd, 0) = 0x6c; - WFIFOW (fd, 2) = 0; - WFIFOSET (fd, 3); - } - } - } - RFIFOSKIP (fd, 17); - break; - - case 0x66: // char select -// printf("0x66> request connect - account_id:%d/char_num:%d\n",sd->account_id,RFIFOB(fd, 2)); - if (RFIFOREST (fd) < 3) - return 0; - - sprintf (tmp_sql, - "SELECT `char_id` FROM `%s` WHERE `account_id`='%d' AND `char_num`='%d'", - char_db, sd->account_id, RFIFOB (fd, 2)); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error - %s\n", - mysql_error (&mysql_handle)); - } - sql_res = mysql_store_result (&mysql_handle); - - sql_row = mysql_fetch_row (sql_res); - - if (sql_row) - mmo_char_fromsql (atoi (sql_row[0]), char_dat, 0); - else - { - mysql_free_result (sql_res); - RFIFOSKIP (fd, 3); - break; - } - - sprintf (tmp_sql, - "INSERT INTO `%s`(`time`, `account_id`,`char_num`,`name`) VALUES (NOW(), '%d', '%d', '%s')", - charlog_db, sd->account_id, RFIFOB (fd, 2), - char_dat[0].name); - //query - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error - %s\n", - mysql_error (&mysql_handle)); - } - printf - ("(\033[1;64m%d\033[0m) char selected (\033[1;32m%d\033[0m) \033[1;32m%s\033[0m" - RETCODE, sd->account_id, RFIFOB (fd, 2), - char_dat[0].name); - - i = search_mapserver (char_dat[0].last_point.map); - - // if map is not found, we check major cities - if (i < 0) - { - if ((i = search_mapserver ("prontera.gat")) >= 0) - { // check is done without 'gat'. - memcpy (char_dat[0].last_point.map, "prontera.gat", - 16); - char_dat[0].last_point.x = 273; // savepoint coordonates - char_dat[0].last_point.y = 354; - } - else if ((i = search_mapserver ("geffen.gat")) >= 0) - { // check is done without 'gat'. - memcpy (char_dat[0].last_point.map, "geffen.gat", 16); - char_dat[0].last_point.x = 120; // savepoint coordonates - char_dat[0].last_point.y = 100; - } - else if ((i = search_mapserver ("morocc.gat")) >= 0) - { // check is done without 'gat'. - memcpy (char_dat[0].last_point.map, "morocc.gat", 16); - char_dat[0].last_point.x = 160; // savepoint coordonates - char_dat[0].last_point.y = 94; - } - else if ((i = search_mapserver ("alberta.gat")) >= 0) - { // check is done without 'gat'. - memcpy (char_dat[0].last_point.map, "alberta.gat", - 16); - char_dat[0].last_point.x = 116; // savepoint coordonates - char_dat[0].last_point.y = 57; - } - else if ((i = search_mapserver ("payon.gat")) >= 0) - { // check is done without 'gat'. - memcpy (char_dat[0].last_point.map, "payon.gat", 16); - char_dat[0].last_point.x = 87; // savepoint coordonates - char_dat[0].last_point.y = 117; - } - else if ((i = search_mapserver ("izlude.gat")) >= 0) - { // check is done without 'gat'. - memcpy (char_dat[0].last_point.map, "izlude.gat", 16); - char_dat[0].last_point.x = 94; // savepoint coordonates - char_dat[0].last_point.y = 103; - } - else - { - int j; - // get first online server - i = 0; - for (j = 0; j < MAX_MAP_SERVERS; j++) - if (server_fd[j] >= 0 && server[j].map[0][0]) - { - i = j; - printf - ("Map-server #%d found with a map: '%s'.\n", - j, server[j].map[0]); - break; - } - // if no map-servers are connected, we send: server closed - if (j == MAX_MAP_SERVERS) - { - WFIFOW (fd, 0) = 0x81; - WFIFOL (fd, 2) = 1; // 01 = Server closed - WFIFOSET (fd, 3); - RFIFOSKIP (fd, 3); - break; - } - } - } - WFIFOW (fd, 0) = 0x71; - WFIFOL (fd, 2) = char_dat[0].char_id; - memcpy (WFIFOP (fd, 6), char_dat[0].last_point.map, 16); - //Lan check added by Kashy - if (lan_ip_check (p)) - WFIFOL (fd, 22) = inet_addr (lan_map_ip); - else - WFIFOL (fd, 22) = server[i].ip; - WFIFOW (fd, 26) = server[i].port; - WFIFOSET (fd, 28); - - if (auth_fifo_pos >= AUTH_FIFO_SIZE) - { - auth_fifo_pos = 0; - } -// printf("auth_fifo set (auth_fifo_pos:%d) - account_id:%d char_id:%d login_id1:%d\n", auth_fifo_pos, sd->account_id, char_dat[0].char_id, sd->login_id1); - auth_fifo[auth_fifo_pos].account_id = sd->account_id; - auth_fifo[auth_fifo_pos].char_id = char_dat[0].char_id; - auth_fifo[auth_fifo_pos].login_id1 = sd->login_id1; - auth_fifo[auth_fifo_pos].login_id2 = sd->login_id2; - auth_fifo[auth_fifo_pos].delflag = 0; - //auth_fifo[auth_fifo_pos].char_pos = sd->found_char[ch]; - auth_fifo[auth_fifo_pos].char_pos = 0; - auth_fifo[auth_fifo_pos].sex = sd->sex; - auth_fifo[auth_fifo_pos].connect_until_time = - sd->connect_until_time; - auth_fifo[auth_fifo_pos].ip = - session[fd]->client_addr.sin_addr.s_addr; - auth_fifo_pos++; -// printf("0x66> end\n"); - RFIFOSKIP (fd, 3); - break; - - case 0x67: // make new -// printf("0x67>request make new char\n"); - if (RFIFOREST (fd) < 37) - return 0; - i = make_new_char_sql (fd, RFIFOP (fd, 2)); - if (i < 0) - { - WFIFOW (fd, 0) = 0x6e; - WFIFOB (fd, 2) = 0x00; - WFIFOSET (fd, 3); - RFIFOSKIP (fd, 37); - break; - } - - WFIFOW (fd, 0) = 0x6d; - memset (WFIFOP (fd, 2), 0x00, 106); - - mmo_char_fromsql (i, char_dat, 0); - i = 0; - WFIFOL (fd, 2) = char_dat[i].char_id; - WFIFOL (fd, 2 + 4) = char_dat[i].base_exp; - WFIFOL (fd, 2 + 8) = char_dat[i].zeny; - WFIFOL (fd, 2 + 12) = char_dat[i].job_exp; - WFIFOL (fd, 2 + 16) = char_dat[i].job_level; - - WFIFOL (fd, 2 + 28) = char_dat[i].karma; - WFIFOL (fd, 2 + 32) = char_dat[i].manner; - - WFIFOW (fd, 2 + 40) = 0x30; - WFIFOW (fd, 2 + 42) = - (char_dat[i].hp > 0x7fff) ? 0x7fff : char_dat[i].hp; - WFIFOW (fd, 2 + 44) = - (char_dat[i].max_hp > - 0x7fff) ? 0x7fff : char_dat[i].max_hp; - WFIFOW (fd, 2 + 46) = - (char_dat[i].sp > 0x7fff) ? 0x7fff : char_dat[i].sp; - WFIFOW (fd, 2 + 48) = - (char_dat[i].max_sp > - 0x7fff) ? 0x7fff : char_dat[i].max_sp; - WFIFOW (fd, 2 + 50) = DEFAULT_WALK_SPEED; // char_dat[i].speed; - WFIFOW (fd, 2 + 52) = char_dat[i].class; - WFIFOW (fd, 2 + 54) = char_dat[i].hair; - - WFIFOW (fd, 2 + 58) = char_dat[i].base_level; - WFIFOW (fd, 2 + 60) = char_dat[i].skill_point; - - WFIFOW (fd, 2 + 64) = char_dat[i].shield; - WFIFOW (fd, 2 + 66) = char_dat[i].head_top; - WFIFOW (fd, 2 + 68) = char_dat[i].head_mid; - WFIFOW (fd, 2 + 70) = char_dat[i].hair_color; - - memcpy (WFIFOP (fd, 2 + 74), char_dat[i].name, 24); - - WFIFOB (fd, 2 + 98) = char_dat[i].str; - WFIFOB (fd, 2 + 99) = char_dat[i].agi; - WFIFOB (fd, 2 + 100) = char_dat[i].vit; - WFIFOB (fd, 2 + 101) = char_dat[i].int_; - WFIFOB (fd, 2 + 102) = char_dat[i].dex; - WFIFOB (fd, 2 + 103) = char_dat[i].luk; - WFIFOB (fd, 2 + 104) = char_dat[i].char_num; - - WFIFOSET (fd, 108); - RFIFOSKIP (fd, 37); - //to do - for (ch = 0; ch < 9; ch++) - { - if (sd->found_char[ch] == -1) - { - sd->found_char[ch] = char_dat[i].char_id; - break; - } - } - - case 0x68: // delete - if (RFIFOREST (fd) < 46) - return 0; - printf - ("\033[1;31m Request Char Del:\033[0m \033[1;32m%d\033[0m(\033[1;32m%d\033[0m)\n", - sd->account_id, RFIFOL (fd, 2)); - memcpy (email, RFIFOP (fd, 6), 40); - sprintf (tmp_sql, "SELECT `email` FROM `%s` WHERE `%s`='%d'", - login_db, login_db_account_id, sd->account_id); - if (mysql_query (&lmysql_handle, tmp_sql)) - { - printf - ("\033[1;31m DB server Error Delete Char data - %s \033[0m \n", - mysql_error (&lmysql_handle)); - } - sql_res = mysql_store_result (&lmysql_handle); - if (sql_res) - { - sql_row = mysql_fetch_row (sql_res); - if (strcmp (email, sql_row[0]) == 0) - { - mysql_free_result (sql_res); - } - else - { - WFIFOW (fd, 0) = 0x70; - WFIFOB (fd, 2) = 0; - WFIFOSET (fd, 3); - RFIFOSKIP (fd, 46); - mysql_free_result (sql_res); - break; - } - } - else - { - WFIFOW (fd, 0) = 0x70; - WFIFOB (fd, 2) = 0; - WFIFOSET (fd, 3); - RFIFOSKIP (fd, 46); - mysql_free_result (sql_res); - break; - } - sprintf (tmp_sql, - "SELECT `name`,`partner_id` FROM `%s` WHERE `char_id`='%d'", - char_db, RFIFOL (fd, 2)); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error - %s\n", - mysql_error (&mysql_handle)); - } - sql_res = mysql_store_result (&mysql_handle); - if (sql_res) - sql_row = mysql_fetch_row (sql_res); - - if (sql_res && sql_row[0]) - { - //delete char from SQL - sprintf (tmp_sql, "DELETE FROM `%s` WHERE `char_id`='%d'", - pet_db, RFIFOL (fd, 2)); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error - %s\n", - mysql_error (&mysql_handle)); - } - sprintf (tmp_sql, "DELETE FROM `%s` WHERE `char_id`='%d'", - inventory_db, RFIFOL (fd, 2)); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error - %s\n", - mysql_error (&mysql_handle)); - } - - sprintf (tmp_sql, "DELETE FROM `%s` WHERE `char_id`='%d'", - cart_db, RFIFOL (fd, 2)); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error - %s\n", - mysql_error (&mysql_handle)); - } - - sprintf (tmp_sql, "DELETE FROM `%s` WHERE `char_id`='%d'", - memo_db, RFIFOL (fd, 2)); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error - %s\n", - mysql_error (&mysql_handle)); - } - - sprintf (tmp_sql, "DELETE FROM `%s` WHERE `char_id`='%d'", - skill_db, RFIFOL (fd, 2)); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error - %s\n", - mysql_error (&mysql_handle)); - } - - sprintf (tmp_sql, "DELETE FROM `%s` WHERE `char_id`='%d'", - char_db, RFIFOL (fd, 2)); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error - %s\n", - mysql_error (&mysql_handle)); - } - - //Divorce [Wizputer] - if (sql_row[1] != 0) - { - char buf[64]; - sprintf (tmp_sql, - "UPDATE `%s` SET `partner_id`='0' WHERE `char_id`='%d'", - char_db, atoi (sql_row[1])); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error - %s\n", - mysql_error (&mysql_handle)); - } - sprintf (tmp_sql, - "DELETE FROM `%s` WHERE (`nameid`='%d' OR `nameid`='%d') AND `char_id`='%d'", - inventory_db, WEDDING_RING_M, WEDDING_RING_F, - atoi (sql_row[1])); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error - %s\n", - mysql_error (&mysql_handle)); - } - WBUFW (buf, 0) = 0x2b12; - WBUFL (buf, 2) = atoi (sql_row[0]); - WBUFL (buf, 6) = atoi (sql_row[1]); - mapif_sendall (buf, 10); - } - // Also delete info from guildtables. - sprintf (tmp_sql, "DELETE FROM `%s` WHERE `char_id`='%d'", - guild_member_db, RFIFOL (fd, 2)); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error - %s\n", - mysql_error (&mysql_handle)); - } - - sprintf (tmp_sql, - "SELECT `guild_id` FROM `%s` WHERE `master` = '%s'", - guild_db, sql_row[0]); - - if (mysql_query (&mysql_handle, tmp_sql) == 0) - { - sql_res = mysql_store_result (&mysql_handle); - - if (sql_res != NULL) - { - if (mysql_num_rows (sql_res) != 0) - { - sql_row = mysql_fetch_row (sql_res); - - sprintf (tmp_sql, - "DELETE FROM `%s` WHERE `guild_id` = '%d'", - guild_db, atoi (sql_row[0])); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error - %s\n", - mysql_error (&mysql_handle)); - } - - sprintf (tmp_sql, - "DELETE FROM `%s` WHERE `guild_id` = '%d'", - guild_member_db, atoi (sql_row[0])); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error - %s\n", - mysql_error (&mysql_handle)); - } - - sprintf (tmp_sql, - "DELETE FROM `%s` WHERE `guild_id` = '%d'", - guild_castle_db, atoi (sql_row[0])); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error - %s\n", - mysql_error (&mysql_handle)); - } - - sprintf (tmp_sql, - "DELETE FROM `%s` WHERE `guild_id` = '%d'", - guild_storage_db, atoi (sql_row[0])); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error - %s\n", - mysql_error (&mysql_handle)); - } - - sprintf (tmp_sql, - "DELETE FROM `%s` WHERE `guild_id` = '%d' OR `alliance_id` = '%d'", - guild_alliance_db, atoi (sql_row[0]), - atoi (sql_row[0])); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error - %s\n", - mysql_error (&mysql_handle)); - } - - sprintf (tmp_sql, - "DELETE FROM `%s` WHERE `guild_id` = '%d'", - guild_position_db, - atoi (sql_row[0])); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error - %s\n", - mysql_error (&mysql_handle)); - } - - sprintf (tmp_sql, - "DELETE FROM `%s` WHERE `guild_id` = '%d'", - guild_skill_db, atoi (sql_row[0])); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error - %s\n", - mysql_error (&mysql_handle)); - } - - sprintf (tmp_sql, - "DELETE FROM `%s` WHERE `guild_id` = '%d'", - guild_expulsion_db, - atoi (sql_row[0])); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error - %s\n", - mysql_error (&mysql_handle)); - } - - mysql_free_result (sql_res); - } - } - else - { - if (mysql_errno (&mysql_handle) != 0) - { - printf ("Database server error: %s\n", - mysql_error (&mysql_handle)); - } - } - } - else - { - printf ("DB server Error - %s\n", - mysql_error (&mysql_handle)); - } - } - - for (i = 0; i < 9; i++) - { - printf ("char comp: %d - %d (%d)\n", sd->found_char[i], - RFIFOL (fd, 2), sd->account_id); - if (sd->found_char[i] == RFIFOL (fd, 2)) - { - for (ch = i; ch < 9 - 1; ch++) - sd->found_char[ch] = sd->found_char[ch + 1]; - sd->found_char[8] = -1; - break; - } - } - if (i == 9) - { // reject - WFIFOW (fd, 0) = 0x70; - WFIFOB (fd, 2) = 0; - WFIFOSET (fd, 3); - } - else - { // deleted! - WFIFOW (fd, 0) = 0x6f; - WFIFOSET (fd, 2); - } - RFIFOSKIP (fd, 46); - break; - - case 0x2af8: // login as map-server - if (RFIFOREST (fd) < 60) - return 0; - WFIFOW (fd, 0) = 0x2af9; - for (i = 0; i < MAX_MAP_SERVERS; i++) - { - if (server_fd[i] < 0) - break; - } - if (i == MAX_MAP_SERVERS || strcmp (RFIFOP (fd, 2), userid) - || strcmp (RFIFOP (fd, 26), passwd)) - { - WFIFOB (fd, 2) = 3; - WFIFOSET (fd, 3); - } - else - { -// int len; - WFIFOB (fd, 2) = 0; - WFIFOSET (fd, 3); - session[fd]->func_parse = parse_frommap; - server_fd[i] = fd; - if (anti_freeze_enable) - server_freezeflag[i] = 5; // Map anti-freeze system. Counter. 5 ok, 4...0 freezed - server[i].ip = RFIFOL (fd, 54); - server[i].port = RFIFOW (fd, 58); - server[i].users = 0; - memset (server[i].map, 0, sizeof (server[i].map)); - realloc_fifo (fd, FIFOSIZE_SERVERLINK, - FIFOSIZE_SERVERLINK); - char_mapif_init (fd); - // send gm acccounts level to map-servers -/* removed by CLOWNISIUS due to isGM - len = 4; - WFIFOW(fd,0) = 0x2b15; - for(i = 0; i < GM_num; i++) { - WFIFOL(fd,len) = gm_account[i].account_id; - WFIFOB(fd,len+4) = (unsigned char)gm_account[i].level; - len += 5; - } - WFIFOW(fd,2) = len; - WFIFOSET(fd,len);*/ - } - RFIFOSKIP (fd, 60); - break; - - case 0x187: // Alive? - if (RFIFOREST (fd) < 6) - { - return 0; - } - RFIFOSKIP (fd, 6); - break; - - case 0x7530: // Athena info get - WFIFOW (fd, 0) = 0x7531; - WFIFOB (fd, 2) = ATHENA_MAJOR_VERSION; - WFIFOB (fd, 3) = ATHENA_MINOR_VERSION; - WFIFOB (fd, 4) = ATHENA_REVISION; - WFIFOB (fd, 5) = ATHENA_RELEASE_FLAG; - WFIFOB (fd, 6) = ATHENA_OFFICIAL_FLAG; - WFIFOB (fd, 7) = ATHENA_SERVER_INTER | ATHENA_SERVER_CHAR; - WFIFOW (fd, 8) = ATHENA_MOD_VERSION; - WFIFOSET (fd, 10); - RFIFOSKIP (fd, 2); - return 0; - - case 0x7532: // disconnect(default also disconnect) - default: - session[fd]->eof = 1; - return 0; - } - } - RFIFOFLUSH (fd); - - return 0; -} - -// MAP send all -int mapif_sendall (unsigned char *buf, unsigned int len) -{ - int i, c; - int fd; - - c = 0; - for (i = 0; i < MAX_MAP_SERVERS; i++) - { - if ((fd = server_fd[i]) >= 0) - { - memcpy (WFIFOP (fd, 0), buf, len); - WFIFOSET (fd, len); - c++; - } - } - - return c; -} - -int mapif_sendallwos (int sfd, unsigned char *buf, unsigned int len) -{ - int i, c; - int fd; - - c = 0; - for (i = 0, c = 0; i < MAX_MAP_SERVERS; i++) - { - if ((fd = server_fd[i]) >= 0 && fd != sfd) - { - memcpy (WFIFOP (fd, 0), buf, len); - WFIFOSET (fd, len); - c++; - } - } - - return c; -} - -int mapif_send (int fd, unsigned char *buf, unsigned int len) -{ - int i; - - if (fd >= 0) - { - for (i = 0; i < MAX_MAP_SERVERS; i++) - { - if (fd == server_fd[i]) - { - memcpy (WFIFOP (fd, 0), buf, len); - WFIFOSET (fd, len); - return 1; - } - } - } - return 0; -} - -int send_users_tologin (int tid, unsigned int tick, int id, int data) -{ - int users = count_users (); - char buf[16]; - - if (login_fd > 0 && session[login_fd]) - { - // send number of user to login server - WFIFOW (login_fd, 0) = 0x2714; - WFIFOL (login_fd, 2) = users; - WFIFOSET (login_fd, 6); - } - // send number of players to all map-servers - WBUFW (buf, 0) = 0x2b00; - WBUFL (buf, 2) = users; - mapif_sendall (buf, 6); - - return 0; -} - -int check_connect_login_server (int tid, unsigned int tick, int id, int data) -{ - if (login_fd <= 0 || session[login_fd] == NULL) - { - printf ("Attempt to connect to login-server...\n"); - login_fd = make_connection (login_ip, login_port); - session[login_fd]->func_parse = parse_tologin; - realloc_fifo (login_fd, FIFOSIZE_SERVERLINK, FIFOSIZE_SERVERLINK); - WFIFOW (login_fd, 0) = 0x2710; - memset (WFIFOP (login_fd, 2), 0, 24); - memcpy (WFIFOP (login_fd, 2), userid, - strlen (userid) < 24 ? strlen (userid) : 24); - memset (WFIFOP (login_fd, 26), 0, 24); - memcpy (WFIFOP (login_fd, 26), passwd, - strlen (passwd) < 24 ? strlen (passwd) : 24); - WFIFOL (login_fd, 50) = 0; - WFIFOL (login_fd, 54) = char_ip; - WFIFOL (login_fd, 58) = char_port; - memset (WFIFOP (login_fd, 60), 0, 20); - memcpy (WFIFOP (login_fd, 60), server_name, - strlen (server_name) < 20 ? strlen (server_name) : 20); - WFIFOW (login_fd, 80) = 0; - WFIFOW (login_fd, 82) = char_maintenance; - WFIFOW (login_fd, 84) = char_new; - WFIFOSET (login_fd, 86); - } - return 0; -} - -//---------------------------------------------------------- -// Return numerical value of a switch configuration by [Yor] -// on/off, english, français, deutsch, español -//---------------------------------------------------------- -int config_switch (const char *str) -{ - if (strcmpi (str, "on") == 0 || strcmpi (str, "yes") == 0 - || strcmpi (str, "oui") == 0 || strcmpi (str, "ja") == 0 - || strcmpi (str, "si") == 0) - return 1; - if (strcmpi (str, "off") == 0 || strcmpi (str, "no") == 0 - || strcmpi (str, "non") == 0 || strcmpi (str, "nein") == 0) - return 0; - - return atoi (str); -} - -// Lan Support conf reading added by Kashy -int char_lan_config_read (const char *lancfgName) -{ - char subnetmask[128]; - char line[1024], w1[1024], w2[1024]; - FILE *fp; - struct hostent *h = NULL; - - if ((fp = fopen_ (lancfgName, "r")) == NULL) - { - printf ("file not found: %s\n", lancfgName); - return 1; - } - - printf ("Start reading of Lan Support configuration file\n"); - - while (fgets (line, sizeof (line) - 1, fp)) - { - if (line[0] == '/' && line[1] == '/') - continue; - - if (sscanf (line, "%[^:]: %[^\r\n]", w1, w2) != 2) - continue; - - else if (strcmpi (w1, "lan_map_ip") == 0) - { - h = gethostbyname (w2); - if (h != NULL) - { - sprintf (lan_map_ip, "%d.%d.%d.%d", - (unsigned char) h->h_addr[0], - (unsigned char) h->h_addr[1], - (unsigned char) h->h_addr[2], - (unsigned char) h->h_addr[3]); - } - else - { - strncpy (lan_map_ip, w2, sizeof (lan_map_ip)); - lan_map_ip[sizeof (lan_map_ip) - 1] = 0; - } - printf ("set Lan_map_IP : %s\n", lan_map_ip); - } - - else if (strcmpi (w1, "subnetmask") == 0) - { - unsigned int k0, k1, k2, k3; - strcpy (subnetmask, w2); - sscanf (subnetmask, "%d.%d.%d.%d", &k0, &k1, &k2, &k3); - subnetmaski[0] = k0; - subnetmaski[1] = k1; - subnetmaski[2] = k2; - subnetmaski[3] = k3; - printf ("set subnetmask : %s\n", w2); - } - } - fclose_ (fp); - - printf ("End reading of Lan Support configuration file\n"); - return 0; -} - -void do_final (void) -{ - printf ("Doing final stage...\n"); - //mmo_char_sync(); - //inter_save(); - do_final_itemdb (); - //check SQL save progress. - //wait until save char complete - printf ("waiting until char saving complete...\n"); - do - { - sleep (0); - } - while (save_flag != 0); - - sprintf (tmp_sql, "UPDATE `%s` SET `online`='0' WHERE `online`='1'", - char_db); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (insert `char`)- %s\n", - mysql_error (&mysql_handle)); - } - - sprintf (tmp_sql, "DELETE FROM `ragsrvinfo"); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (insert `char`)- %s\n", - mysql_error (&mysql_handle)); - } - - if (gm_account != NULL) - free (gm_account); - - free (char_dat); - free (gm_account); - delete_session (login_fd); - delete_session (char_fd); - - mysql_close (&mysql_handle); - mysql_close (&lmysql_handle); - - printf ("ok! all done...\n"); -} - -void sql_config_read (const char *cfgName) -{ /* Kalaspuff, to get login_db */ - char line[1024], w1[1024], w2[1024]; - FILE *fp; - - printf ("reading configure: %s\n", cfgName); - - if ((fp = fopen_ (cfgName, "r")) == NULL) - { - printf ("file not found: %s\n", cfgName); - exit (1); - } - - while (fgets (line, sizeof (line) - 1, fp)) - { - if (line[0] == '/' && line[1] == '/') - continue; - - if (sscanf (line, "%[^:]: %[^\r\n]", w1, w2) != 2) - continue; - - if (strcmpi (w1, "login_db") == 0) - { - strcpy (login_db, w2); - } - else if (strcmpi (w1, "char_db") == 0) - { - strcpy (char_db, w2); - } - else if (strcmpi (w1, "cart_db") == 0) - { - strcpy (cart_db, w2); - } - else if (strcmpi (w1, "inventory_db") == 0) - { - strcpy (inventory_db, w2); - } - else if (strcmpi (w1, "charlog_db") == 0) - { - strcpy (charlog_db, w2); - } - else if (strcmpi (w1, "storage_db") == 0) - { - strcpy (storage_db, w2); - } - else if (strcmpi (w1, "reg_db") == 0) - { - strcpy (reg_db, w2); - } - else if (strcmpi (w1, "skill_db") == 0) - { - strcpy (skill_db, w2); - } - else if (strcmpi (w1, "interlog_db") == 0) - { - strcpy (interlog_db, w2); - } - else if (strcmpi (w1, "memo_db") == 0) - { - strcpy (memo_db, w2); - } - else if (strcmpi (w1, "guild_db") == 0) - { - strcpy (guild_db, w2); - } - else if (strcmpi (w1, "guild_alliance_db") == 0) - { - strcpy (guild_alliance_db, w2); - } - else if (strcmpi (w1, "guild_castle_db") == 0) - { - strcpy (guild_castle_db, w2); - } - else if (strcmpi (w1, "guild_expulsion_db") == 0) - { - strcpy (guild_expulsion_db, w2); - } - else if (strcmpi (w1, "guild_member_db") == 0) - { - strcpy (guild_member_db, w2); - } - else if (strcmpi (w1, "guild_skill_db") == 0) - { - strcpy (guild_skill_db, w2); - } - else if (strcmpi (w1, "guild_position_db") == 0) - { - strcpy (guild_position_db, w2); - } - else if (strcmpi (w1, "guild_storage_db") == 0) - { - strcpy (guild_storage_db, w2); - } - else if (strcmpi (w1, "party_db") == 0) - { - strcpy (party_db, w2); - } - else if (strcmpi (w1, "pet_db") == 0) - { - strcpy (pet_db, w2); - //Map server option to use SQL db or not - } - else if (strcmpi (w1, "use_sql_db") == 0) - { // added for sql item_db read for char server [Valaris] - if (strcmpi (w2, "yes")) - { - db_use_sqldbs = 1; - } - else if (strcmpi (w2, "no")) - { - db_use_sqldbs = 0; - } - printf ("Using SQL dbs: %s\n", w2); - //custom columns for login database - } - else if (strcmpi (w1, "login_db_level") == 0) - { - strcpy (login_db_level, w2); - } - else if (strcmpi (w1, "login_db_account_id") == 0) - { - strcpy (login_db_account_id, w2); - } - else if (strcmpi (w1, "lowest_gm_level") == 0) - { - lowest_gm_level = atoi (w2); - printf ("set lowest_gm_level : %s\n", w2); - } - } - fclose_ (fp); - printf ("reading configure done.....\n"); -} - -int char_config_read (const char *cfgName) -{ - struct hostent *h = NULL; - char line[1024], w1[1024], w2[1024]; - FILE *fp; - - if ((fp = fopen_ (cfgName, "r")) == NULL) - { - printf ("Configuration file not found: %s.\n", cfgName); - exit (1); - } - - while (fgets (line, sizeof (line) - 1, fp)) - { - if (line[0] == '/' && line[1] == '/') - continue; - - line[sizeof (line) - 1] = '\0'; - if (sscanf (line, "%[^:]: %[^\r\n]", w1, w2) != 2) - continue; - - remove_control_chars (w1); - remove_control_chars (w2); - if (strcmpi (w1, "userid") == 0) - { - memcpy (userid, w2, 24); - } - else if (strcmpi (w1, "passwd") == 0) - { - memcpy (passwd, w2, 24); - } - else if (strcmpi (w1, "server_name") == 0) - { - memcpy (server_name, w2, 16); - printf ("%s server has been intialized\n", w2); - } - else if (strcmpi (w1, "wisp_server_name") == 0) - { - if (strlen (w2) >= 4) - { - memcpy (wisp_server_name, w2, sizeof (wisp_server_name)); - wisp_server_name[sizeof (wisp_server_name) - 1] = '\0'; - } - } - else if (strcmpi (w1, "login_ip") == 0) - { - h = gethostbyname (w2); - if (h != NULL) - { - printf ("Login server IP address : %s -> %d.%d.%d.%d\n", w2, - (unsigned char) h->h_addr[0], - (unsigned char) h->h_addr[1], - (unsigned char) h->h_addr[2], - (unsigned char) h->h_addr[3]); - sprintf (login_ip_str, "%d.%d.%d.%d", - (unsigned char) h->h_addr[0], - (unsigned char) h->h_addr[1], - (unsigned char) h->h_addr[2], - (unsigned char) h->h_addr[3]); - } - else - memcpy (login_ip_str, w2, 16); - } - else if (strcmpi (w1, "login_port") == 0) - { - login_port = atoi (w2); - } - else if (strcmpi (w1, "char_ip") == 0) - { - h = gethostbyname (w2); - if (h != NULL) - { - printf ("Character server IP address : %s -> %d.%d.%d.%d\n", - w2, (unsigned char) h->h_addr[0], - (unsigned char) h->h_addr[1], - (unsigned char) h->h_addr[2], - (unsigned char) h->h_addr[3]); - sprintf (char_ip_str, "%d.%d.%d.%d", - (unsigned char) h->h_addr[0], - (unsigned char) h->h_addr[1], - (unsigned char) h->h_addr[2], - (unsigned char) h->h_addr[3]); - } - else - memcpy (char_ip_str, w2, 16); - } - else if (strcmpi (w1, "char_port") == 0) - { - char_port = atoi (w2); - } - else if (strcmpi (w1, "char_maintenance") == 0) - { - char_maintenance = atoi (w2); - } - else if (strcmpi (w1, "char_new") == 0) - { - char_new = atoi (w2); - } - else if (strcmpi (w1, "max_connect_user") == 0) - { - max_connect_user = atoi (w2); - if (max_connect_user < 0) - max_connect_user = 0; // unlimited online players - } - else if (strcmpi (w1, "check_ip_flag") == 0) - { - check_ip_flag = config_switch (w2); - } - else if (strcmpi (w1, "autosave_time") == 0) - { - autosave_interval = atoi (w2) * 1000; - if (autosave_interval <= 0) - autosave_interval = DEFAULT_AUTOSAVE_INTERVAL; - } - else if (strcmpi (w1, "start_point") == 0) - { - char map[32]; - int x, y; - if (sscanf (w2, "%[^,],%d,%d", map, &x, &y) < 3) - continue; - if (strstr (map, ".gat") != NULL) - { // Verify at least if '.gat' is in the map name - memcpy (start_point.map, map, 16); - start_point.x = x; - start_point.y = y; - } - } - else if (strcmpi (w1, "start_zeny") == 0) - { - start_zeny = atoi (w2); - if (start_zeny < 0) - start_zeny = 0; - } - else if (strcmpi (w1, "start_weapon") == 0) - { - start_zeny = atoi (w2); - if (start_weapon < 0) - start_weapon = 0; - } - else if (strcmpi (w1, "start_armor") == 0) - { - start_zeny = atoi (w2); - if (start_armor < 0) - start_armor = 0; - } - else if (strcmpi (w1, "unknown_char_name") == 0) - { - strcpy (unknown_char_name, w2); - unknown_char_name[24] = 0; - } - else if (strcmpi (w1, "name_ignoring_case") == 0) - { - name_ignoring_case = config_switch (w2); - } - else if (strcmpi (w1, "char_name_option") == 0) - { - char_name_option = atoi (w2); - } - else if (strcmpi (w1, "char_name_letters") == 0) - { - strcpy (char_name_letters, w2); - } - else if (strcmpi (w1, "check_ip_flag") == 0) - { - check_ip_flag = config_switch (w2); - // anti-freeze options [Valaris] - } - else if (strcmpi (w1, "anti_freeze_enable") == 0) - { - anti_freeze_enable = config_switch (w2); - } - else if (strcmpi (w1, "anti_freeze_interval") == 0) - { - ANTI_FREEZE_INTERVAL = atoi (w2); - if (ANTI_FREEZE_INTERVAL < 5) - ANTI_FREEZE_INTERVAL = 5; // minimum 5 seconds - } - else if (strcmpi (w1, "import") == 0) - { - char_config_read (w2); - } - } - fclose_ (fp); - -//Read ItemDB - do_init_itemdb (); - - return 0; -} - -int do_init (int argc, char **argv) -{ - int i; - - for (i = 0; i < MAX_MAP_SERVERS; i++) - { - memset (&server[i], 0, sizeof (struct mmo_map_server)); - server_fd[i] = -1; - } - - char_config_read ((argc < 2) ? CHAR_CONF_NAME : argv[1]); - char_lan_config_read ((argc > 1) ? argv[1] : LAN_CONF_NAME); - sql_config_read (SQL_CONF_NAME); - - printf ("charserver configuration reading done.....\n"); - - inter_init ((argc > 2) ? argv[2] : inter_cfgName); // inter server テハア篳ュ - printf ("interserver configuration reading done.....\n"); - - printf ("start char server initializing.....\n"); - mmo_char_sql_init (); - printf ("char server initializing done.....\n"); - - printf ("set parser -> parse_char().....\n"); - set_defaultparse (parse_char); - - printf ("set terminate function -> do_final().....\n"); - set_termfunc (do_final); - - printf ("open port %d.....\n", char_port); - char_fd = make_listen_port (char_port); - - login_ip = inet_addr (login_ip_str); - char_ip = inet_addr (char_ip_str); - - // send ALIVE PING to login server. - printf ("add interval tic (check_connect_login_server)....\n"); - i = add_timer_interval (gettick () + 10, check_connect_login_server, 0, 0, - 10 * 1000); - - // send USER COUNT PING to login server. - printf ("add interval tic (send_users_tologin)....\n"); - i = add_timer_interval (gettick () + 10, send_users_tologin, 0, 0, - 5 * 1000); - - //no need to set sync timer on SQL version. - //printf("add interval tic (mmo_char_sync_timer)....\n"); - //i = add_timer_interval(gettick() + 10, mmo_char_sync_timer, 0, 0, autosave_interval); - - if (anti_freeze_enable > 0) - { - add_timer_func_list (map_anti_freeze_system, - "map_anti_freeze_system"); - i = add_timer_interval (gettick () + 1000, map_anti_freeze_system, 0, 0, ANTI_FREEZE_INTERVAL * 1000); // checks every X seconds user specifies - } - - read_gm_account (); - - printf ("char server init func end (now unlimited loop start!)....\n"); - printf - ("The char-server is \033[1;32mready\033[0m (Server is listening on the port %d).\n\n", - char_port); - return 0; -} diff --git a/src/char_sql/char.h b/src/char_sql/char.h deleted file mode 100644 index b0b2770..0000000 --- a/src/char_sql/char.h +++ /dev/null @@ -1,87 +0,0 @@ -#include "../common/core.h" -#include "../common/socket.h" -#include "../common/timer.h" -#include "../common/mmo.h" -#include "../common/version.h" -#include "../common/db.h" - -#ifndef _CHAR_H_ -#define _CHAR_H_ - -#define MAX_MAP_SERVERS 30 - -#define LAN_CONF_NAME "conf/lan_support.conf" - -#define DEFAULT_AUTOSAVE_INTERVAL 300*1000 - -struct mmo_map_server -{ - long ip; - short port; - int users; - char map[MAX_MAP_PER_SERVER][16]; -}; -struct itemtmp -{ - int flag; //checked = 1 else 0 - int id; - short nameid; - short amount; - unsigned short equip; - char identify; - char refine; - char attribute; - short card[4]; - short broken; -}; -enum -{ - TABLE_INVENTORY, - TABLE_CART, - TABLE_STORAGE, - TABLE_GUILD_STORAGE, -}; -struct itemtemp -{ - struct itemtmp equip[MAX_GUILD_STORAGE], notequip[MAX_GUILD_STORAGE]; -}; -int memitemdata_to_sql (struct itemtemp mapitem, int eqcount, int noteqcount, - int char_id, int tableswitch); -int mapif_sendall (unsigned char *buf, unsigned int len); -int mapif_sendallwos (int fd, unsigned char *buf, unsigned int len); -int mapif_send (int fd, unsigned char *buf, unsigned int len); - -extern int autosave_interval; -extern char char_db[256]; -extern char cart_db[256]; -extern char inventory_db[256]; -extern char charlog_db[256]; -extern char storage_db[256]; -extern char interlog_db[256]; -extern char reg_db[256]; -extern char skill_db[256]; -extern char memo_db[256]; -extern char guild_db[256]; -extern char guild_alliance_db[256]; -extern char guild_castle_db[256]; -extern char guild_expulsion_db[256]; -extern char guild_member_db[256]; -extern char guild_position_db[256]; -extern char guild_skill_db[256]; -extern char guild_storage_db[256]; -extern char party_db[256]; -extern char pet_db[256]; - -int db_use_sqldbs; // added for sql item_db read for char server [Valaris] -extern char login_db_level[32]; -extern char login_db_account_id[32]; - -extern int lowest_gm_level; - -#endif - -#include "inter.h" -#include "int_pet.h" -#include "int_guild.h" -#include "int_party.h" -#include "int_storage.h" diff --git a/src/char_sql/int_guild.c b/src/char_sql/int_guild.c deleted file mode 100644 index 7b363a1..0000000 --- a/src/char_sql/int_guild.c +++ /dev/null @@ -1,2111 +0,0 @@ -// -// original code from athena -// SQL conversion by hack -// - -#include "char.h" -#include "strlib.h" -#include "int_storage.h" -#include "inter.h" -#include "int_guild.h" -#include "int_storage.h" -#include "mmo.h" -#include "socket.h" - -#include -#include -#include - -static struct guild *guild_pt; -static struct guild *guild_pt2; -static struct guild_castle *guildcastle_pt; -static int guild_newid = 10000; - -static int guild_exp[100]; - -int mapif_parse_GuildLeave (int fd, int guild_id, int account_id, - int char_id, int flag, const char *mes); -int mapif_guild_broken (int guild_id, int flag); -int guild_check_empty (struct guild *g); -int guild_calcinfo (struct guild *g); -int mapif_guild_basicinfochanged (int guild_id, int type, const void *data, - int len); -int mapif_guild_info (int fd, struct guild *g); -int guild_break_sub (void *key, void *data, va_list ap); - -// Save guild into sql -int inter_guild_tosql (struct guild *g, int flag) -{ - // 1 `guild` (`guild_id`, `name`,`master`,`guild_lv`,`connect_member`,`max_member`,`average_lv`,`exp`,`next_exp`,`skill_point`,`castle_id`,`mes1`,`mes2`,`emblem_len`,`emblem_id`,`emblem_data`) - // 2 `guild_member` (`guild_id`,`account_id`,`char_id`,`hair`,`hair_color`,`gender`,`class`,`lv`,`exp`,`exp_payper`,`online`,`position`,`rsv1`,`rsv2`,`name`) - // 4 `guild_position` (`guild_id`,`position`,`name`,`mode`,`exp_mode`) - // 8 `guild_alliance` (`guild_id`,`opposition`,`alliance_id`,`name`) - // 16 `guild_expulsion` (`guild_id`,`name`,`mes`,`acc`,`account_id`,`rsv1`,`rsv2`,`rsv3`) - // 32 `guild_skill` (`guild_id`,`id`,`lv`) - - char t_name[100], t_master[24], t_mes1[60], t_mes2[120], t_member[24], t_position[24], t_alliance[24]; // temporay storage for str convertion; - char t_ename[24], t_emes[40]; - char emblem_data[4096]; - int i = 0; - int guild_exist = 0, guild_member = 0, guild_online_member = 0; - - if (g->guild_id <= 0) - return -1; - - printf ("(\033[1;35m%d\033[0m) Request save guild - ", g->guild_id); - - jstrescapecpy (t_name, g->name); - - //printf("- Check if guild %d exists\n",g->guild_id); - sprintf (tmp_sql, "SELECT count(*) FROM `%s` WHERE `guild_id`='%d'", - guild_db, g->guild_id); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (delete `guild`)- %s\n", - mysql_error (&mysql_handle)); - } - sql_res = mysql_store_result (&mysql_handle); - if (sql_res != NULL && mysql_num_rows (sql_res) > 0) - { - sql_row = mysql_fetch_row (sql_res); - guild_exist = atoi (sql_row[0]); - //printf("- Check if guild %d exists : %s\n",g->guild_id,((guild_exist==0)?"No":"Yes")); - } - mysql_free_result (sql_res); //resource free - - if (guild_exist > 0) - { - // Check members in party - sprintf (tmp_sql, "SELECT count(*) FROM `%s` WHERE `guild_id`='%d'", - guild_member_db, g->guild_id); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error - %s\n", mysql_error (&mysql_handle)); - return -1; - } - sql_res = mysql_store_result (&mysql_handle); - if (sql_res != NULL && mysql_num_rows (sql_res) > 0) - { - sql_row = mysql_fetch_row (sql_res); - - guild_member = atoi (sql_row[0]); - // printf("- Check members in guild %d : %d \n",g->guild_id,guild_member); - - } - mysql_free_result (sql_res); //resource free - - // Delete old guild from sql - if (flag & 1 || guild_member == 0) - { - // printf("- Delete guild %d from guild\n",g->guild_id); - sprintf (tmp_sql, "DELETE FROM `%s` WHERE `guild_id`='%d'", - guild_db, g->guild_id); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (delete `guild`)- %s\n", - mysql_error (&mysql_handle)); - } - } - if (flag & 2 || guild_member == 0) - { - // printf("- Delete guild %d from guild_member\n",g->guild_id); - sprintf (tmp_sql, "DELETE FROM `%s` WHERE `guild_id`='%d'", - guild_member_db, g->guild_id); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (delete `guild_member`)- %s\n", - mysql_error (&mysql_handle)); - } - sprintf (tmp_sql, - "UPDATE `%s` SET `guild_id`='0' WHERE `guild_id`='%d'", - char_db, g->guild_id); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (update `char`)- %s\n", - mysql_error (&mysql_handle)); - } - } - if (flag & 32 || guild_member == 0) - { - // printf("- Delete guild %d from guild_skill\n",g->guild_id); - sprintf (tmp_sql, "DELETE FROM `%s` WHERE `guild_id`='%d'", - guild_skill_db, g->guild_id); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (delete `guild_skill`)- %s\n", - mysql_error (&mysql_handle)); - } - } - if (flag & 4 || guild_member == 0) - { - // printf("- Delete guild %d from guild_position\n",g->guild_id); - sprintf (tmp_sql, "DELETE FROM `%s` WHERE `guild_id`='%d'", - guild_position_db, g->guild_id); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (delete `guild_position`)- %s\n", - mysql_error (&mysql_handle)); - } - } - if (flag & 16 || guild_member == 0) - { - // printf("- Delete guild %d from guild_expulsion\n",g->guild_id); - sprintf (tmp_sql, "DELETE FROM `%s` WHERE `guild_id`='%d'", - guild_expulsion_db, g->guild_id); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (delete `guild_expulsion`)- %s\n", - mysql_error (&mysql_handle)); - } - } - if (flag & 8 || guild_member == 0) - { - // printf("- Delete guild %d from guild_alliance\n",g->guild_id); - sprintf (tmp_sql, - "DELETE FROM `%s` WHERE `guild_id`='%d' OR `alliance_id`='%d'", - guild_alliance_db, g->guild_id, g->guild_id); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (delete `guild_alliance`)- %s\n", - mysql_error (&mysql_handle)); - } - } - if (flag & 2 || guild_member == 0) - { - // printf("- Delete guild %d from char\n",g->guild_id); - sprintf (tmp_sql, - "UPDATE `%s` SET `guild_id`='0' WHERE `guild_id`='%d'", - char_db, g->guild_id); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (delete `guild_alliance`)- %s\n", - mysql_error (&mysql_handle)); - } - } - if (guild_member == 0) - { - // printf("- Delete guild %d from guild_castle\n",g->guild_id); - sprintf (tmp_sql, "DELETE FROM `%s` WHERE `guild_id`='%d'", - guild_castle_db, g->guild_id); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (delete `guild_castle`)- %s\n", - mysql_error (&mysql_handle)); - } - } - } - - guild_online_member = 0; - i = 0; - while (i < g->max_member) - { - if (g->member[i].account_id > 0) - guild_online_member++; - i++; - } - - // No member in guild , no need to create it in sql - if (guild_member <= 0 && guild_online_member <= 0) - { - inter_guild_storage_delete (g->guild_id); - printf ("No member in guild %d , break it! \n", g->guild_id); - return -2; - } - - // Insert new guild to sqlserver - if (flag & 1 || guild_member == 0) - { - int len = 0; - //printf("- Insert guild %d to guild\n",g->guild_id); - for (i = 0; i < g->emblem_len; i++) - { - len += - sprintf (emblem_data + len, "%02x", - (unsigned char) (g->emblem_data[i])); - //printf("%02x",(unsigned char)(g->emblem_data[i])); - } - emblem_data[len] = '\0'; - //printf("- emblem_len = %d \n",g->emblem_len); - sprintf (tmp_sql, "INSERT INTO `%s` " - "(`guild_id`, `name`,`master`,`guild_lv`,`connect_member`,`max_member`,`average_lv`,`exp`,`next_exp`,`skill_point`,`castle_id`,`mes1`,`mes2`,`emblem_len`,`emblem_id`,`emblem_data`) " - "VALUES ('%d', '%s', '%s', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%s', '%s', '%d', '%d', '%s')", - guild_db, g->guild_id, t_name, jstrescapecpy (t_master, - g->master), - g->guild_lv, g->connect_member, g->max_member, g->average_lv, - g->exp, g->next_exp, g->skill_point, g->castle_id, - jstrescapecpy (t_mes1, g->mes1), jstrescapecpy (t_mes2, - g->mes2), - g->emblem_len, g->emblem_id, emblem_data); - //printf(" %s\n",tmp_sql); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (insert `guild`)- %s\n", - mysql_error (&mysql_handle)); - } - } - - if (flag & 2 || guild_member == 0) - { - //printf("- Insert guild %d to guild_member\n",g->guild_id); - for (i = 0; i < g->max_member; i++) - { - if (g->member[i].account_id > 0) - { - struct guild_member *m = &g->member[i]; - sprintf (tmp_sql, "DELETE FROM `%s` WHERE `char_id`='%d'", - guild_member_db, m->char_id); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (delete `guild_member`)- %s\n", - mysql_error (&mysql_handle)); - } - sprintf (tmp_sql, "INSERT INTO `%s` " - "(`guild_id`,`account_id`,`char_id`,`hair`,`hair_color`,`gender`,`class`,`lv`,`exp`,`exp_payper`,`online`,`position`,`rsv1`,`rsv2`,`name`) " - "VALUES ('%d','%d','%d','%d','%d', '%d','%d','%d','%d','%d','%d','%d','%d','%d','%s')", - guild_member_db, g->guild_id, - m->account_id, m->char_id, - m->hair, m->hair_color, m->gender, - m->class, m->lv, m->exp, m->exp_payper, m->online, - m->position, 0, 0, jstrescapecpy (t_member, - m->name)); - //printf(" %s\n",tmp_sql); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (insert `guild_member`)- %s\n", - mysql_error (&mysql_handle)); - } - sprintf (tmp_sql, - "UPDATE `%s` SET `guild_id`='%d' WHERE `account_id`='%d' AND `char_id`='%d'", - char_db, g->guild_id, m->account_id, m->char_id); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (update `char`)- %s\n", - mysql_error (&mysql_handle)); - } - } - } - } - - if (flag & 4 || guild_member == 0) - { - //printf("- Insert guild %d to guild_position\n",g->guild_id); - for (i = 0; i < MAX_GUILDPOSITION; i++) - { - struct guild_position *p = &g->position[i]; - sprintf (tmp_sql, - "INSERT INTO `%s` (`guild_id`,`position`,`name`,`mode`,`exp_mode`) VALUES ('%d','%d', '%s','%d','%d')", - guild_position_db, g->guild_id, i, - jstrescapecpy (t_position, p->name), p->mode, - p->exp_mode); - //printf(" %s\n",tmp_sql); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (insert `guild_position`)- %s\n", - mysql_error (&mysql_handle)); - } - } - } - - if (flag & 8 || guild_member == 0) - { - //printf("- Insert guild %d to guild_alliance\n",g->guild_id); - for (i = 0; i < MAX_GUILDALLIANCE; i++) - { - struct guild_alliance *a = &g->alliance[i]; - if (a->guild_id > 0) - { - sprintf (tmp_sql, - "INSERT INTO `%s` (`guild_id`,`opposition`,`alliance_id`,`name`) " - "VALUES ('%d','%d','%d','%s')", guild_alliance_db, - g->guild_id, a->opposition, a->guild_id, - jstrescapecpy (t_alliance, a->name)); - //printf(" %s\n",tmp_sql); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (insert `guild_alliance`)- %s\n", - mysql_error (&mysql_handle)); - } - sprintf (tmp_sql, - "INSERT INTO `%s` (`guild_id`,`opposition`,`alliance_id`,`name`) " - "VALUES ('%d','%d','%d','%s')", guild_alliance_db, - a->guild_id, a->opposition, g->guild_id, t_name); - //printf(" %s\n",tmp_sql); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (insert `guild_alliance`)- %s\n", - mysql_error (&mysql_handle)); - } - } - } - } - - if (flag & 16 || guild_member == 0) - { - //printf("- Insert guild %d to guild_expulsion\n",g->guild_id); - for (i = 0; i < MAX_GUILDEXPLUSION; i++) - { - struct guild_explusion *e = &g->explusion[i]; - if (e->account_id > 0) - { - sprintf (tmp_sql, - "INSERT INTO `%s` (`guild_id`,`name`,`mes`,`acc`,`account_id`,`rsv1`,`rsv2`,`rsv3`) " - "VALUES ('%d','%s','%s','%s','%d','%d','%d','%d')", - guild_expulsion_db, g->guild_id, - jstrescapecpy (t_ename, e->name), - jstrescapecpy (t_emes, e->mes), e->acc, - e->account_id, e->rsv1, e->rsv2, e->rsv3); - //printf(" %s\n",tmp_sql); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf - ("DB server Error (insert `guild_expulsion`)- %s\n", - mysql_error (&mysql_handle)); - } - } - } - } - - if (flag & 32 || guild_member == 0) - { - //printf("- Insert guild %d to guild_skill\n",g->guild_id); - for (i = 0; i < MAX_GUILDSKILL; i++) - { - if (g->skill[i].id > 0) - { - sprintf (tmp_sql, - "INSERT INTO `%s` (`guild_id`,`id`,`lv`) VALUES ('%d','%d','%d')", - guild_skill_db, g->guild_id, g->skill[i].id, - g->skill[i].lv); - //printf("%s\n",tmp_sql); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (insert `guild_skill`)- %s\n", - mysql_error (&mysql_handle)); - } - } - } - } - - printf ("Save guild done\n"); - return 0; -} - -// Read guild from sql -int inter_guild_fromsql (int guild_id, struct guild *g) -{ - int i; - char emblem_data[4096]; - char *pstr; - - if (g == NULL) - return 0; - memset (g, 0, sizeof (struct guild)); - if (guild_id == 0) - return 0; - -// printf("Retrieve guild information from sql ......\n"); -// printf("- Read guild %d from sql \n",guild_id); - - sprintf (tmp_sql, - "SELECT `guild_id`, `name`,`master`,`guild_lv`,`connect_member`,`max_member`,`average_lv`,`exp`,`next_exp`,`skill_point`,`castle_id`,`mes1`,`mes2`,`emblem_len`,`emblem_id`,`emblem_data` " - "FROM `%s` WHERE `guild_id`='%d'", guild_db, guild_id); - //printf(" %s\n",tmp_sql); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (select `guild`)- %s\n", - mysql_error (&mysql_handle)); - return 0; - } - - sql_res = mysql_store_result (&mysql_handle); - if (sql_res != NULL && mysql_num_rows (sql_res) > 0) - { - sql_row = mysql_fetch_row (sql_res); - if (sql_row == NULL) - { - mysql_free_result (sql_res); - return 0; - } - - g->guild_id = atoi (sql_row[0]); - strncpy (g->name, sql_row[1], 24); - strncpy (g->master, sql_row[2], 24); - g->guild_lv = atoi (sql_row[3]); - g->connect_member = atoi (sql_row[4]); - g->max_member = atoi (sql_row[5]); - g->average_lv = atoi (sql_row[6]); - g->exp = atoi (sql_row[7]); - g->next_exp = atoi (sql_row[8]); - g->skill_point = atoi (sql_row[9]); - g->castle_id = atoi (sql_row[10]); - strncpy (g->mes1, sql_row[11], 60); - strncpy (g->mes2, sql_row[12], 120); - g->emblem_len = atoi (sql_row[13]); - g->emblem_id = atoi (sql_row[14]); - strncpy (emblem_data, sql_row[15], 4096); - for (i = 0, pstr = emblem_data; i < g->emblem_len; i++, pstr += 2) - { - int c1 = pstr[0], c2 = pstr[1], x1 = 0, x2 = 0; - if (c1 >= '0' && c1 <= '9') - x1 = c1 - '0'; - if (c1 >= 'a' && c1 <= 'f') - x1 = c1 - 'a' + 10; - if (c1 >= 'A' && c1 <= 'F') - x1 = c1 - 'A' + 10; - if (c2 >= '0' && c2 <= '9') - x2 = c2 - '0'; - if (c2 >= 'a' && c2 <= 'f') - x2 = c2 - 'a' + 10; - if (c2 >= 'A' && c2 <= 'F') - x2 = c2 - 'A' + 10; - g->emblem_data[i] = (x1 << 4) | x2; - } - } - mysql_free_result (sql_res); - - //printf("- Read guild_member %d from sql \n",guild_id); - sprintf (tmp_sql, - "SELECT `guild_id`,`account_id`,`char_id`,`hair`,`hair_color`,`gender`,`class`,`lv`,`exp`,`exp_payper`,`online`,`position`,`rsv1`,`rsv2`,`name` " - "FROM `%s` WHERE `guild_id`='%d' ORDER BY `position`", - guild_member_db, guild_id); - //printf(" %s\n",tmp_sql); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (select `guild_member`)- %s\n", - mysql_error (&mysql_handle)); - return 0; - } - sql_res = mysql_store_result (&mysql_handle); - if (sql_res != NULL && mysql_num_rows (sql_res) > 0) - { - int i; - for (i = 0; - ((sql_row = mysql_fetch_row (sql_res)) && i < g->max_member); - i++) - { - struct guild_member *m = &g->member[i]; - m->account_id = atoi (sql_row[1]); - m->char_id = atoi (sql_row[2]); - m->hair = atoi (sql_row[3]); - m->hair_color = atoi (sql_row[4]); - m->gender = atoi (sql_row[5]); - m->class = atoi (sql_row[6]); - m->lv = atoi (sql_row[7]); - m->exp = atoi (sql_row[8]); - m->exp_payper = atoi (sql_row[9]); - m->online = atoi (sql_row[10]); - m->position = atoi (sql_row[11]); - strncpy (m->name, sql_row[14], 24); - } - } - mysql_free_result (sql_res); - - //printf("- Read guild_position %d from sql \n",guild_id); - sprintf (tmp_sql, - "SELECT `guild_id`,`position`,`name`,`mode`,`exp_mode` FROM `%s` WHERE `guild_id`='%d'", - guild_position_db, guild_id); - //printf(" %s\n",tmp_sql); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (select `guild_position`)- %s\n", - mysql_error (&mysql_handle)); - return 0; - } - sql_res = mysql_store_result (&mysql_handle); - if (sql_res != NULL && mysql_num_rows (sql_res) > 0) - { - int i; - for (i = 0; - ((sql_row = mysql_fetch_row (sql_res)) && i < MAX_GUILDPOSITION); - i++) - { - int position = atoi (sql_row[1]); - struct guild_position *p = &g->position[position]; - strncpy (p->name, sql_row[2], 24); - p->mode = atoi (sql_row[3]); - p->exp_mode = atoi (sql_row[4]); - } - } - mysql_free_result (sql_res); - - //printf("- Read guild_alliance %d from sql \n",guild_id); - sprintf (tmp_sql, - "SELECT `guild_id`,`opposition`,`alliance_id`,`name` FROM `%s` WHERE `guild_id`='%d'", - guild_alliance_db, guild_id); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (select `guild_alliance`)- %s\n", - mysql_error (&mysql_handle)); - return 0; - } - sql_res = mysql_store_result (&mysql_handle); - if (sql_res != NULL && mysql_num_rows (sql_res) > 0) - { - int i; - for (i = 0; - ((sql_row = mysql_fetch_row (sql_res)) && i < MAX_GUILDALLIANCE); - i++) - { - struct guild_alliance *a = &g->alliance[i]; - a->opposition = atoi (sql_row[1]); - a->guild_id = atoi (sql_row[2]); - strncpy (a->name, sql_row[3], 24); - } - } - mysql_free_result (sql_res); - - //printf("- Read guild_expulsion %d from sql \n",guild_id); - sprintf (tmp_sql, - "SELECT `guild_id`,`name`,`mes`,`acc`,`account_id`,`rsv1`,`rsv2`,`rsv3` FROM `%s` WHERE `guild_id`='%d'", - guild_expulsion_db, guild_id); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (select `guild_expulsion`)- %s\n", - mysql_error (&mysql_handle)); - return 0; - } - sql_res = mysql_store_result (&mysql_handle); - if (sql_res != NULL && mysql_num_rows (sql_res) > 0) - { - int i; - for (i = 0; - ((sql_row = mysql_fetch_row (sql_res)) - && i < MAX_GUILDEXPLUSION); i++) - { - struct guild_explusion *e = &g->explusion[i]; - - strncpy (e->name, sql_row[1], 24); - strncpy (e->mes, sql_row[2], 40); - strncpy (e->acc, sql_row[3], 24); - e->account_id = atoi (sql_row[4]); - e->rsv1 = atoi (sql_row[5]); - e->rsv2 = atoi (sql_row[6]); - e->rsv3 = atoi (sql_row[7]); - - } - } - mysql_free_result (sql_res); - - //printf("- Read guild_skill %d from sql \n",guild_id); - sprintf (tmp_sql, - "SELECT `guild_id`,`id`,`lv` FROM `%s` WHERE `guild_id`='%d' ORDER BY `id`", - guild_skill_db, guild_id); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (select `guild_skill`)- %s\n", - mysql_error (&mysql_handle)); - return 0; - } - sql_res = mysql_store_result (&mysql_handle); - if (sql_res != NULL && mysql_num_rows (sql_res) > 0) - { - int i; - for (i = 0; - ((sql_row = mysql_fetch_row (sql_res)) && i < MAX_GUILDSKILL); - i++) - { - g->skill[i].id = atoi (sql_row[1]); - g->skill[i].lv = atoi (sql_row[2]); - } - } - mysql_free_result (sql_res); - -// printf("Successfully retrieve guild information from sql!\n"); - - return 0; - -} - -// Save guild_castle to sql -int inter_guildcastle_tosql (struct guild_castle *gc) -{ - // `guild_castle` (`castle_id`, `guild_id`, `economy`, `defense`, `triggerE`, `triggerD`, `nextTime`, `payTime`, `createTime`, `visibleC`, `visibleG0`, `visibleG1`, `visibleG2`, `visibleG3`, `visibleG4`, `visibleG5`, `visibleG6`, `visibleG7`) - - if (gc == NULL) - return 0; - //printf("Save to guild_castle\n"); - sprintf (tmp_sql, "DELETE FROM `%s` WHERE `castle_id`='%d'", - guild_castle_db, gc->castle_id); - //printf(" %s\n",tmp_sql); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error - %s\n", mysql_error (&mysql_handle)); - return 0; - } - - sprintf (tmp_sql, "INSERT INTO `%s` " - "(`castle_id`, `guild_id`, `economy`, `defense`, `triggerE`, `triggerD`, `nextTime`, `payTime`, `createTime`," - "`visibleC`, `visibleG0`, `visibleG1`, `visibleG2`, `visibleG3`, `visibleG4`, `visibleG5`, `visibleG6`, `visibleG7`," - "`Ghp0`, `Ghp1`, `Ghp2`, `Ghp3`, `Ghp4`, `Ghp5`, `Ghp6`, `Ghp7`)" - "VALUES ('%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d')", - guild_castle_db, gc->castle_id, gc->guild_id, gc->economy, - gc->defense, gc->triggerE, gc->triggerD, gc->nextTime, - gc->payTime, gc->createTime, gc->visibleC, gc->visibleG0, - gc->visibleG1, gc->visibleG2, gc->visibleG3, gc->visibleG4, - gc->visibleG5, gc->visibleG6, gc->visibleG7, gc->Ghp0, gc->Ghp1, - gc->Ghp2, gc->Ghp3, gc->Ghp4, gc->Ghp5, gc->Ghp6, gc->Ghp7); - //printf(" %s\n",tmp_sql); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error - %s\n", mysql_error (&mysql_handle)); - return 0; - } - - sprintf (tmp_sql, - "UPDATE `%s` SET `castle_id`='-1' WHERE `castle_id`='%d'", - guild_db, gc->castle_id); - //printf(" %s\n",tmp_sql); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error - %s\n", mysql_error (&mysql_handle)); - return 0; - } - - sprintf (tmp_sql, - "UPDATE `%s` SET `castle_id`='%d' WHERE `guild_id`='%d'", - guild_db, gc->castle_id, gc->guild_id); - //printf(" %s\n",tmp_sql); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error - %s\n", mysql_error (&mysql_handle)); - return 0; - } - - return 0; -} - -// Read guild_castle from sql -int inter_guildcastle_fromsql (int castle_id, struct guild_castle *gc) -{ - - if (gc == NULL) - return 0; - //printf("Read from guild_castle\n"); - memset (gc, 0, sizeof (struct guild_castle)); - gc->castle_id = castle_id; - if (castle_id == -1) - return 0; - sprintf (tmp_sql, - "SELECT `castle_id`, `guild_id`, `economy`, `defense`, `triggerE`, `triggerD`, `nextTime`, `payTime`, `createTime`, " - "`visibleC`, `visibleG0`, `visibleG1`, `visibleG2`, `visibleG3`, `visibleG4`, `visibleG5`, `visibleG6`, `visibleG7`," - "`Ghp0`, `Ghp1`, `Ghp2`, `Ghp3`, `Ghp4`, `Ghp5`, `Ghp6`, `Ghp7`" - " FROM `%s` WHERE `castle_id`='%d'", guild_castle_db, castle_id); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error - %s\n", mysql_error (&mysql_handle)); - return 0; - } - sql_res = mysql_store_result (&mysql_handle); - if (sql_res != NULL && mysql_num_rows (sql_res) > 0) - { - sql_row = mysql_fetch_row (sql_res); - if (sql_row == NULL) - { - mysql_free_result (sql_res); - return 0; - } - - gc->guild_id = atoi (sql_row[1]); - gc->economy = atoi (sql_row[2]); - gc->defense = atoi (sql_row[3]); - gc->triggerE = atoi (sql_row[4]); - gc->triggerD = atoi (sql_row[5]); - gc->nextTime = atoi (sql_row[6]); - gc->payTime = atoi (sql_row[7]); - gc->createTime = atoi (sql_row[8]); - gc->visibleC = atoi (sql_row[9]); - gc->visibleG0 = atoi (sql_row[10]); - gc->visibleG1 = atoi (sql_row[11]); - gc->visibleG2 = atoi (sql_row[12]); - gc->visibleG3 = atoi (sql_row[13]); - gc->visibleG4 = atoi (sql_row[14]); - gc->visibleG5 = atoi (sql_row[15]); - gc->visibleG6 = atoi (sql_row[16]); - gc->visibleG7 = atoi (sql_row[17]); - gc->Ghp0 = atoi (sql_row[18]); - gc->Ghp1 = atoi (sql_row[19]); - gc->Ghp2 = atoi (sql_row[20]); - gc->Ghp3 = atoi (sql_row[21]); - gc->Ghp4 = atoi (sql_row[22]); - gc->Ghp5 = atoi (sql_row[23]); - gc->Ghp6 = atoi (sql_row[24]); - gc->Ghp7 = atoi (sql_row[25]); - - //printf("Read Castle %d of guild %d from sql \n",castle_id,gc->guild_id); - - } - mysql_free_result (sql_res); //resource free - return 0; -} - -// Read exp_guild.txt -int inter_guild_readdb () -{ - int i; - FILE *fp; - char line[1024]; - for (i = 0; i < 100; i++) - guild_exp[i] = 0; - - fp = fopen_ ("db/exp_guild.txt", "r"); - if (fp == NULL) - { - printf ("can't read db/exp_guild.txt\n"); - return 1; - } - i = 0; - while (fgets (line, 256, fp) && i < 100) - { - if (line[0] == '/' && line[1] == '/') - continue; - guild_exp[i] = atoi (line); - i++; - } - fclose_ (fp); - - return 0; -} - -// Initialize guild sql -int inter_guild_sql_init () -{ - int i; - - printf ("interserver guild memory initialize.... (%d byte)\n", - sizeof (struct guild)); - guild_pt = calloc (sizeof (struct guild), 1); - guild_pt2 = calloc (sizeof (struct guild), 1); - guildcastle_pt = calloc (sizeof (struct guild_castle), 1); - - inter_guild_readdb (); // Read exp - - sprintf (tmp_sql, "UPDATE `%s` SET `online`='0'", guild_member_db); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (update `char`)- %s\n", - mysql_error (&mysql_handle)); - exit (0); - } - - sprintf (tmp_sql, "SELECT count(*) FROM `%s`", guild_db); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error - %s\n", mysql_error (&mysql_handle)); - exit (0); - } - sql_res = mysql_store_result (&mysql_handle); - sql_row = mysql_fetch_row (sql_res); - printf ("total guild data -> '%s'.......\n", sql_row[0]); - i = atoi (sql_row[0]); - mysql_free_result (sql_res); - - if (i > 0) - { - //set party_newid - sprintf (tmp_sql, "SELECT max(`guild_id`) FROM `%s`", guild_db); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error - %s\n", mysql_error (&mysql_handle)); - exit (0); - } - - sql_res = mysql_store_result (&mysql_handle); - sql_row = mysql_fetch_row (sql_res); - guild_newid = atoi (sql_row[0]) + 1; - mysql_free_result (sql_res); - } - - printf ("set guild_newid: %d.......\n", guild_newid); - - return 0; -} - -// Get guild by its name -struct guild *search_guildname (char *str) -{ - struct guild *g = guild_pt; - char t_name[24]; - int guild_id = 0; - printf ("search_guildname\n"); - sprintf (tmp_sql, "SELECT `guild_id` FROM `%s` WHERE `name`='%s'", - guild_db, jstrescapecpy (t_name, str)); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error - %s\n", mysql_error (&mysql_handle)); - } - sql_res = mysql_store_result (&mysql_handle); - if (sql_res != NULL && mysql_num_rows (sql_res) > 0) - { - sql_row = mysql_fetch_row (sql_res); - guild_id = atoi (sql_row[0]); - } - mysql_free_result (sql_res); - inter_guild_fromsql (guild_id, g); - return g; -} - -// Check if guild is empty -int guild_check_empty (struct guild *g) -{ - int i; - for (i = 0; i < g->max_member; i++) - { - if (g->member[i].account_id > 0) - { - return 0; - } - } - - // 誰もいないので解散 - mapif_guild_broken (g->guild_id, 0); - inter_guild_storage_delete (g->guild_id); - inter_guild_tosql (g, 255); - memset (g, 0, sizeof (struct guild)); - return 1; -} - -int guild_nextexp (int level) -{ - if (level < 100 && level > 0) // Change by hack - return guild_exp[level - 1]; - - return 0; -} - -// ギルドスキルがあるか確認 -int guild_checkskill (struct guild *g, int id) -{ - return g->skill[id - 10000].lv; -} - -// ギルドの情報の再計算 -int guild_calcinfo (struct guild *g) -{ - int i, c, nextexp; - struct guild before = *g; - - // スキルIDの設定 - for (i = 0; i < 5; i++) - g->skill[i].id = i + 10000; - - // ギルドレベル - if (g->guild_lv <= 0) - g->guild_lv = 1; - nextexp = guild_nextexp (g->guild_lv); - if (nextexp > 0) - { - while (g->exp >= nextexp && nextexp > 0) - { // Change by hack - g->exp -= nextexp; - g->guild_lv++; - g->skill_point++; - nextexp = guild_nextexp (g->guild_lv); - } - } - - // ギルドの次の経験値 - g->next_exp = guild_nextexp (g->guild_lv); - - // メンバ上限(ギルド拡張適用) - g->max_member = 100 + guild_checkskill (g, 10004) * 2; // Updated max_members [PoW] - - // 平均レベルとオンライン人数 - g->average_lv = 0; - g->connect_member = 0; - for (i = c = 0; i < g->max_member; i++) - { - if (g->member[i].account_id > 0) - { - g->average_lv += g->member[i].lv; - c++; - - if (g->member[i].online > 0) - g->connect_member++; - } - } - g->average_lv /= c; - - // 全データを送る必要がありそう - if (g->max_member != before.max_member || - g->guild_lv != before.guild_lv || - g->skill_point != before.skill_point) - { - mapif_guild_info (-1, g); - return 1; - } - - return 0; -} - -//------------------------------------------------------------------- -// map serverへの通信 - -// ギルド作成可否 -int mapif_guild_created (int fd, int account_id, struct guild *g) -{ - WFIFOW (fd, 0) = 0x3830; - WFIFOL (fd, 2) = account_id; - if (g != NULL) - { - WFIFOL (fd, 6) = g->guild_id; - printf ("int_guild: created! %d %s\n", g->guild_id, g->name); - } - else - { - WFIFOL (fd, 6) = 0; - } - WFIFOSET (fd, 10); - return 0; -} - -// ギルド情報見つからず -int mapif_guild_noinfo (int fd, int guild_id) -{ - WFIFOW (fd, 0) = 0x3831; - WFIFOW (fd, 2) = 8; - WFIFOL (fd, 4) = guild_id; - WFIFOSET (fd, 8); - printf ("int_guild: info not found %d\n", guild_id); - return 0; -} - -// ギルド情報まとめ送り -int mapif_guild_info (int fd, struct guild *g) -{ - unsigned char buf[16384]; - WBUFW (buf, 0) = 0x3831; - memcpy (buf + 4, g, sizeof (struct guild)); - WBUFW (buf, 2) = 4 + sizeof (struct guild); -// printf("int_guild: sizeof(guild)=%d\n",sizeof(struct guild)); - if (fd < 0) - mapif_sendall (buf, WBUFW (buf, 2)); - else - mapif_send (fd, buf, WBUFW (buf, 2)); -// printf("int_guild: info %d %s\n",p->guild_id,p->name); - return 0; -} - -// メンバ追加可否 -int mapif_guild_memberadded (int fd, int guild_id, int account_id, - int char_id, int flag) -{ - WFIFOW (fd, 0) = 0x3832; - WFIFOL (fd, 2) = guild_id; - WFIFOL (fd, 6) = account_id; - WFIFOL (fd, 10) = char_id; - WFIFOB (fd, 14) = flag; - WFIFOSET (fd, 15); - return 0; -} - -// 脱退/追放通知 -int mapif_guild_leaved (int guild_id, int account_id, int char_id, int flag, - const char *name, const char *mes) -{ - unsigned char buf[128]; - WBUFW (buf, 0) = 0x3834; - WBUFL (buf, 2) = guild_id; - WBUFL (buf, 6) = account_id; - WBUFL (buf, 10) = char_id; - WBUFB (buf, 14) = flag; - memcpy (WBUFP (buf, 15), mes, 40); - memcpy (WBUFP (buf, 55), name, 24); - mapif_sendall (buf, 79); - printf ("int_guild: guild leaved %d %d %s %s\n", guild_id, account_id, - name, mes); - return 0; -} - -// オンライン状態とLv更新通知 -int mapif_guild_memberinfoshort (struct guild *g, int idx) -{ - unsigned char buf[32]; - WBUFW (buf, 0) = 0x3835; - WBUFL (buf, 2) = g->guild_id; - WBUFL (buf, 6) = g->member[idx].account_id; - WBUFL (buf, 10) = g->member[idx].char_id; - WBUFB (buf, 14) = g->member[idx].online; - WBUFW (buf, 15) = g->member[idx].lv; - WBUFW (buf, 17) = g->member[idx].class; - mapif_sendall (buf, 19); - return 0; -} - -// 解散通知 -int mapif_guild_broken (int guild_id, int flag) -{ - unsigned char buf[16]; - WBUFW (buf, 0) = 0x3836; - WBUFL (buf, 2) = guild_id; - WBUFB (buf, 6) = flag; - mapif_sendall (buf, 7); - printf ("int_guild: broken %d\n", guild_id); - return 0; -} - -// ギルド内発言 -int mapif_guild_message (int guild_id, int account_id, char *mes, int len) -{ - unsigned char buf[512]; - WBUFW (buf, 0) = 0x3837; - WBUFW (buf, 2) = len + 12; - WBUFL (buf, 4) = guild_id; - WBUFL (buf, 8) = account_id; - memcpy (WBUFP (buf, 12), mes, len); - mapif_sendall (buf, len + 12); - return 0; -} - -// ギルド基本情報変更通知 -int mapif_guild_basicinfochanged (int guild_id, int type, const void *data, - int len) -{ - unsigned char buf[2048]; - WBUFW (buf, 0) = 0x3839; - WBUFW (buf, 2) = len + 10; - WBUFL (buf, 4) = guild_id; - WBUFW (buf, 8) = type; - memcpy (WBUFP (buf, 10), data, len); - mapif_sendall (buf, len + 10); - return 0; -} - -// ギルドメンバ情報変更通知 -int mapif_guild_memberinfochanged (int guild_id, int account_id, int char_id, - int type, const void *data, int len) -{ - unsigned char buf[2048]; - WBUFW (buf, 0) = 0x383a; - WBUFW (buf, 2) = len + 18; - WBUFL (buf, 4) = guild_id; - WBUFL (buf, 8) = account_id; - WBUFL (buf, 12) = char_id; - WBUFW (buf, 16) = type; - memcpy (WBUFP (buf, 18), data, len); - mapif_sendall (buf, len + 18); - return 0; -} - -// ギルドスキルアップ通知 -int mapif_guild_skillupack (int guild_id, int skill_num, int account_id) -{ - unsigned char buf[16]; - WBUFW (buf, 0) = 0x383c; - WBUFL (buf, 2) = guild_id; - WBUFL (buf, 6) = skill_num; - WBUFL (buf, 10) = account_id; - mapif_sendall (buf, 14); - return 0; -} - -// ギルド同盟/敵対通知 -int mapif_guild_alliance (int guild_id1, int guild_id2, int account_id1, - int account_id2, int flag, const char *name1, - const char *name2) -{ - unsigned char buf[128]; - WBUFW (buf, 0) = 0x383d; - WBUFL (buf, 2) = guild_id1; - WBUFL (buf, 6) = guild_id2; - WBUFL (buf, 10) = account_id1; - WBUFL (buf, 14) = account_id2; - WBUFB (buf, 18) = flag; - memcpy (WBUFP (buf, 19), name1, 24); - memcpy (WBUFP (buf, 43), name2, 24); - mapif_sendall (buf, 67); - return 0; -} - -// ギルド役職変更通知 -int mapif_guild_position (struct guild *g, int idx) -{ - unsigned char buf[128]; - WBUFW (buf, 0) = 0x383b; - WBUFW (buf, 2) = sizeof (struct guild_position) + 12; - WBUFL (buf, 4) = g->guild_id; - WBUFL (buf, 8) = idx; - memcpy (WBUFP (buf, 12), &g->position[idx], - sizeof (struct guild_position)); - mapif_sendall (buf, WBUFW (buf, 2)); - return 0; -} - -// ギルド告知変更通知 -int mapif_guild_notice (struct guild *g) -{ - unsigned char buf[256]; - WBUFW (buf, 0) = 0x383e; - WBUFL (buf, 2) = g->guild_id; - memcpy (WBUFP (buf, 6), g->mes1, 60); - memcpy (WBUFP (buf, 66), g->mes2, 120); - mapif_sendall (buf, 186); - return 0; -} - -// ギルドエンブレム変更通知 -int mapif_guild_emblem (struct guild *g) -{ - unsigned char buf[2048]; - WBUFW (buf, 0) = 0x383f; - WBUFW (buf, 2) = g->emblem_len + 12; - WBUFL (buf, 4) = g->guild_id; - WBUFL (buf, 8) = g->emblem_id; - memcpy (WBUFP (buf, 12), g->emblem_data, g->emblem_len); - mapif_sendall (buf, WBUFW (buf, 2)); - return 0; -} - -int mapif_guild_castle_dataload (int castle_id, int index, int value) // -{ - unsigned char buf[16]; - WBUFW (buf, 0) = 0x3840; - WBUFW (buf, 2) = castle_id; - WBUFB (buf, 4) = index; - WBUFL (buf, 5) = value; - mapif_sendall (buf, 9); - return 0; -} - -int mapif_guild_castle_datasave (int castle_id, int index, int value) // -{ - unsigned char buf[16]; - WBUFW (buf, 0) = 0x3841; - WBUFW (buf, 2) = castle_id; - WBUFB (buf, 4) = index; - WBUFL (buf, 5) = value; - mapif_sendall (buf, 9); - return 0; -} - -int mapif_guild_castle_alldataload (int fd) -{ - struct guild_castle *gc = guildcastle_pt; - int i, len = 4; - - WFIFOW (fd, 0) = 0x3842; - sprintf (tmp_sql, "SELECT * FROM `%s` ORDER BY `castle_id`", - guild_castle_db); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error - %s\n", mysql_error (&mysql_handle)); - } - sql_res = mysql_store_result (&mysql_handle); - if (sql_res != NULL && mysql_num_rows (sql_res) > 0) - { - for (i = 0; - ((sql_row = mysql_fetch_row (sql_res)) && i < MAX_GUILDCASTLE); - i++) - { - memset (gc, 0, sizeof (struct guild_castle)); - gc->castle_id = atoi (sql_row[0]); - gc->guild_id = atoi (sql_row[1]); - gc->economy = atoi (sql_row[2]); - gc->defense = atoi (sql_row[3]); - gc->triggerE = atoi (sql_row[4]); - gc->triggerD = atoi (sql_row[5]); - gc->nextTime = atoi (sql_row[6]); - gc->payTime = atoi (sql_row[7]); - gc->createTime = atoi (sql_row[8]); - gc->visibleC = atoi (sql_row[9]); - gc->visibleG0 = atoi (sql_row[10]); - gc->visibleG1 = atoi (sql_row[11]); - gc->visibleG2 = atoi (sql_row[12]); - gc->visibleG3 = atoi (sql_row[13]); - gc->visibleG4 = atoi (sql_row[14]); - gc->visibleG5 = atoi (sql_row[15]); - gc->visibleG6 = atoi (sql_row[16]); - gc->visibleG7 = atoi (sql_row[17]); - gc->Ghp0 = atoi (sql_row[18]); - gc->Ghp1 = atoi (sql_row[19]); - gc->Ghp2 = atoi (sql_row[20]); - gc->Ghp3 = atoi (sql_row[21]); - gc->Ghp4 = atoi (sql_row[22]); - gc->Ghp5 = atoi (sql_row[23]); - gc->Ghp6 = atoi (sql_row[24]); - gc->Ghp7 = atoi (sql_row[25]); - memcpy (WFIFOP (fd, len), gc, sizeof (struct guild_castle)); - len += sizeof (struct guild_castle); - } - } - mysql_free_result (sql_res); - WFIFOW (fd, 2) = len; - WFIFOSET (fd, len); - - return 0; -} - -//------------------------------------------------------------------- -// map serverからの通信 - -// ギルド作成要求 -int mapif_parse_CreateGuild (int fd, int account_id, char *name, - struct guild_member *master) -{ - struct guild *g; - int i; - - printf ("CreateGuild\n"); - g = search_guildname (name); - if (g != NULL && g->guild_id > 0) - { - printf ("int_guild: same name guild exists [%s]\n", name); - mapif_guild_created (fd, account_id, NULL); - return 0; - } - g = guild_pt; - memset (g, 0, sizeof (struct guild)); - g->guild_id = guild_newid++; - memcpy (g->name, name, 24); - memcpy (g->master, master->name, 24); - memcpy (&g->member[0], master, sizeof (struct guild_member)); - - g->position[0].mode = 0x11; - strcpy (g->position[0].name, "GuildMaster"); - strcpy (g->position[MAX_GUILDPOSITION - 1].name, "Newbie"); - for (i = 1; i < MAX_GUILDPOSITION - 1; i++) - sprintf (g->position[i].name, "Position %d", i + 1); - - // Initialize guild property - g->max_member = 100; - g->average_lv = master->lv; - g->castle_id = -1; - for (i = 0; i < 5; i++) - g->skill[i].id = i + 10000; - - // Save to sql - printf ("Create initialize OK!\n"); - i = inter_guild_tosql (g, 255); - - if (i < 0) - { - mapif_guild_created (fd, account_id, NULL); - return 0; - } - - // Report to client - mapif_guild_created (fd, account_id, g); - mapif_guild_info (fd, g); - - inter_log ("guild %s (id=%d) created by master %s (id=%d)" RETCODE, - name, g->guild_id, master->name, master->account_id); - - return 0; -} - -// Return guild info to client -int mapif_parse_GuildInfo (int fd, int guild_id) -{ - struct guild *g; - g = guild_pt; - inter_guild_fromsql (guild_id, g); - if (g != NULL && g->guild_id > 0) - { - guild_calcinfo (g); - mapif_guild_info (fd, g); - //inter_guild_tosql(g,1); // Change guild - } - else - mapif_guild_noinfo (fd, guild_id); - return 0; -} - -// Add member to guild -int mapif_parse_GuildAddMember (int fd, int guild_id, struct guild_member *m) -{ - struct guild *g; - int i; - g = guild_pt; - inter_guild_fromsql (guild_id, g); - - if (g == NULL || g->guild_id <= 0) - { - mapif_guild_memberadded (fd, guild_id, m->account_id, m->char_id, 1); - return 0; - } - - for (i = 0; i < g->max_member; i++) - { - if (g->member[i].account_id == 0) - { - - memcpy (&g->member[i], m, sizeof (struct guild_member)); - mapif_guild_memberadded (fd, guild_id, m->account_id, m->char_id, - 0); - guild_calcinfo (g); - mapif_guild_info (-1, g); - inter_guild_tosql (g, 3); // Change guild & guild_member - return 0; - } - } - mapif_guild_memberadded (fd, guild_id, m->account_id, m->char_id, 1); - //inter_guild_tosql(g,3); // Change guild & guild_member - return 0; -} - -// Delete member from guild -int mapif_parse_GuildLeave (int fd, int guild_id, int account_id, int char_id, - int flag, const char *mes) -{ - struct guild *g = NULL; - g = guild_pt; - inter_guild_fromsql (guild_id, g); - - if (g != NULL && g->guild_id > 0) - { - int i; - for (i = 0; i < g->max_member; i++) - { - if (g->member[i].account_id == account_id && - g->member[i].char_id == char_id) - { - printf ("%d %d\n", i, (int) (&g->member[i])); - printf ("%d %s\n", i, g->member[i].name); - - if (flag) - { // 追放の場合追放リストに入れる - int j; - for (j = 0; j < MAX_GUILDEXPLUSION; j++) - { - if (g->explusion[j].account_id == 0) - break; - } - if (j == MAX_GUILDEXPLUSION) - { // 一杯なので古いのを消す - for (j = 0; j < MAX_GUILDEXPLUSION - 1; j++) - g->explusion[j] = g->explusion[j + 1]; - j = MAX_GUILDEXPLUSION - 1; - } - g->explusion[j].account_id = account_id; - memcpy (g->explusion[j].acc, "dummy", 24); - memcpy (g->explusion[j].name, g->member[i].name, 24); - memcpy (g->explusion[j].mes, mes, 40); - } - - mapif_guild_leaved (guild_id, account_id, char_id, flag, - g->member[i].name, mes); - printf ("%d %d\n", i, (int) (&g->member[i])); - printf ("%d %s\n", i, (&g->member[i])->name); - memset (&g->member[i], 0, sizeof (struct guild_member)); - - if (guild_check_empty (g) == 0) - mapif_guild_info (-1, g); // まだ人がいるのでデータ送信 - /* - * else - * inter_guild_save(); // 解散したので一応セーブ - * return 0; */ - } - } - guild_calcinfo (g); - inter_guild_tosql (g, 19); // Change guild & guild_member & guild_expulsion - } - else - { - sprintf (tmp_sql, - "UPDATE `%s` SET `guild_id`='0' WHERE `account_id`='%d' AND `char_id`='%d'", - char_db, account_id, char_id); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (update `char`)- %s\n", - mysql_error (&mysql_handle)); - } - /* mapif_guild_leaved(guild_id,account_id,char_id,flag,g->member[i].name,mes); */ - } - - return 0; -} - -// Change member info -int mapif_parse_GuildChangeMemberInfoShort (int fd, int guild_id, - int account_id, int char_id, - int online, int lv, int class) -{ - // Could speed up by manipulating only guild_member - struct guild *g; - int i, alv, c; - g = guild_pt; - inter_guild_fromsql (guild_id, g); - - if (g == NULL || g->guild_id <= 0) - { - return 0; - } - - g->connect_member = 0; - - for (i = 0, alv = 0, c = 0; i < g->max_member; i++) - { - if (g->member[i].account_id == account_id && - g->member[i].char_id == char_id) - { - - g->member[i].online = online; - g->member[i].lv = lv; - g->member[i].class = class; - mapif_guild_memberinfoshort (g, i); - } - if (g->member[i].account_id > 0) - { - alv += g->member[i].lv; - c++; - } - if (g->member[i].online) - g->connect_member++; - } - // 平均レベル - g->average_lv = alv / c; - - inter_guild_tosql (g, 3); // Change guild & guild_member - - return 0; -} - -// BreakGuild -int mapif_parse_BreakGuild (int fd, int guild_id) -{ - struct guild *g; - g = guild_pt; - inter_guild_fromsql (guild_id, g); - if (g == NULL) - { - return 0; - } - - // Delete guild from sql - //printf("- Delete guild %d from guild\n",guild_id); - sprintf (tmp_sql, "DELETE FROM `%s` WHERE `guild_id`='%d'", guild_db, - guild_id); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (delete `guild`)- %s\n", - mysql_error (&mysql_handle)); - } - //printf("- Delete guild %d from guild_member\n",guild_id); - sprintf (tmp_sql, "DELETE FROM `%s` WHERE `guild_id`='%d'", - guild_member_db, guild_id); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (delete `guild_member`)- %s\n", - mysql_error (&mysql_handle)); - } - //printf("- Delete guild %d from guild_skill\n",guild_id); - sprintf (tmp_sql, "DELETE FROM `%s` WHERE `guild_id`='%d'", - guild_skill_db, guild_id); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (delete `guild_skill`)- %s\n", - mysql_error (&mysql_handle)); - } - //printf("- Delete guild %d from guild_position\n",guild_id); - sprintf (tmp_sql, "DELETE FROM `%s` WHERE `guild_id`='%d'", - guild_position_db, guild_id); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (delete `guild_position`)- %s\n", - mysql_error (&mysql_handle)); - } - //printf("- Delete guild %d from guild_expulsion\n",guild_id); - sprintf (tmp_sql, "DELETE FROM `%s` WHERE `guild_id`='%d'", - guild_expulsion_db, guild_id); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (delete `guild_expulsion`)- %s\n", - mysql_error (&mysql_handle)); - } - //printf("- Delete guild %d from guild_alliance\n",guild_id); - sprintf (tmp_sql, - "DELETE FROM `%s` WHERE `guild_id`='%d' OR `alliance_id`='%d'", - guild_alliance_db, guild_id, guild_id); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (delete `guild_position`)- %s\n", - mysql_error (&mysql_handle)); - } - - //printf("- Delete guild %d from guild_castle\n",guild_id); - sprintf (tmp_sql, "DELETE FROM `%s` WHERE `guild_id`='%d'", - guild_castle_db, guild_id); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (delete `guild_position`)- %s\n", - mysql_error (&mysql_handle)); - } - - //printf("- Update guild %d of char\n",guild_id); - sprintf (tmp_sql, "UPDATE `%s` SET `guild_id`='0' WHERE `guild_id`='%d'", - char_db, guild_id); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (delete `guild_position`)- %s\n", - mysql_error (&mysql_handle)); - } - - inter_guild_storage_delete (guild_id); - mapif_guild_broken (guild_id, 0); - - inter_log ("guild %s (id=%d) broken" RETCODE, g->name, guild_id); - - return 0; -} - -// ギルドメッセージ送信 -int mapif_parse_GuildMessage (int fd, int guild_id, int account_id, char *mes, - int len) -{ - return mapif_guild_message (guild_id, account_id, mes, len); -} - -// ギルド基本データ変更要求 -int mapif_parse_GuildBasicInfoChange (int fd, int guild_id, - int type, const char *data, int len) -{ - struct guild *g; -// int dd=*((int *)data); - short dw = *((short *) data); - g = guild_pt; - inter_guild_fromsql (guild_id, g); - - if (g == NULL || g->guild_id <= 0) - { - return 0; - } - switch (type) - { - case GBI_GUILDLV: - { - printf ("GBI_GUILDLV\n"); - if (dw > 0 && g->guild_lv + dw <= 50) - { - g->guild_lv += dw; - g->skill_point += dw; - } - else if (dw < 0 && g->guild_lv + dw >= 1) - g->guild_lv += dw; - mapif_guild_info (-1, g); - inter_guild_tosql (g, 1); - } - return 0; - default: - printf ("int_guild: GuildBasicInfoChange: Unknown type %d\n", - type); - break; - } - mapif_guild_basicinfochanged (guild_id, type, data, len); - //inter_guild_tosql(g,1); // Change guild - return 0; -} - -// ギルドメンバデータ変更要求 -int mapif_parse_GuildMemberInfoChange (int fd, int guild_id, int account_id, - int char_id, int type, - const char *data, int len) -{ - // Could make some improvement in speed, because only change guild_member - int i; - struct guild *g; - g = guild_pt; - inter_guild_fromsql (guild_id, g); - //printf("GuildMemberInfoChange %s \n",(type==GMI_EXP)?"GMI_EXP":"OTHER"); - - if (g == NULL) - { - return 0; - } - for (i = 0; i < g->max_member; i++) - if (g->member[i].account_id == account_id && - g->member[i].char_id == char_id) - break; - if (i == g->max_member) - { - printf ("int_guild: GuildMemberChange: Not found %d,%d in %d[%s]\n", - account_id, char_id, guild_id, g->name); - return 0; - } - switch (type) - { - case GMI_POSITION: // 役職 - g->member[i].position = *((int *) data); - break; - case GMI_EXP: - { // EXP - int exp, oldexp = g->member[i].exp; - exp = g->member[i].exp = *((unsigned int *) data); - g->exp += (exp - oldexp); - guild_calcinfo (g); // Lvアップ判断 - mapif_guild_basicinfochanged (guild_id, GBI_EXP, &g->exp, 4); - } break; - default: - printf ("int_guild: GuildMemberInfoChange: Unknown type %d\n", - type); - break; - } - mapif_guild_memberinfochanged (guild_id, account_id, char_id, type, data, - len); - inter_guild_tosql (g, 3); // Change guild & guild_member - return 0; -} - -// ギルド役職名変更要求 -int mapif_parse_GuildPosition (int fd, int guild_id, int idx, - struct guild_position *p) -{ - // Could make some improvement in speed, because only change guild_position - struct guild *g; - g = guild_pt; - inter_guild_fromsql (guild_id, g); - - if (g == NULL || idx < 0 || idx >= MAX_GUILDPOSITION) - { - return 0; - } - memcpy (&g->position[idx], p, sizeof (struct guild_position)); - mapif_guild_position (g, idx); - printf ("int_guild: position changed %d\n", idx); - inter_guild_tosql (g, 4); // Change guild_position - return 0; -} - -// ギルドスキルアップ要求 -int mapif_parse_GuildSkillUp (int fd, int guild_id, int skill_num, - int account_id) -{ - // Could make some improvement in speed, because only change guild_position - struct guild *g; - g = guild_pt; - inter_guild_fromsql (guild_id, g); - int idx = skill_num - 10000; - if (g == NULL || skill_num < 10000) - return 0; - //printf("GuildSkillUp\n"); - - if (g->skill_point > 0 && g->skill[idx].id > 0 && g->skill[idx].lv < 10) - { - g->skill[idx].lv++; - g->skill_point--; - if (guild_calcinfo (g) == 0) - mapif_guild_info (-1, g); - mapif_guild_skillupack (guild_id, skill_num, account_id); - printf ("int_guild: skill %d up\n", skill_num); - inter_guild_tosql (g, 33); // Change guild & guild_skill - } - - return 0; -} - -// ギルド同盟要求 -int mapif_parse_GuildAlliance (int fd, int guild_id1, int guild_id2, - int account_id1, int account_id2, int flag) -{ - // Could speed up - struct guild *g[2]; - int j, i; - g[0] = guild_pt; - g[1] = guild_pt2; - inter_guild_fromsql (guild_id1, g[0]); - inter_guild_fromsql (guild_id2, g[1]); - - if (g[0] == NULL || g[1] == NULL || g[0]->guild_id == 0 - || g[1]->guild_id == 0) - return 0; - - if (!(flag & 0x8)) - { - for (i = 0; i < 2 - (flag & 1); i++) - { - for (j = 0; j < MAX_GUILDALLIANCE; j++) - if (g[i]->alliance[j].guild_id == 0) - { - g[i]->alliance[j].guild_id = g[1 - i]->guild_id; - memcpy (g[i]->alliance[j].name, g[1 - i]->name, 24); - g[i]->alliance[j].opposition = flag & 1; - break; - } - } - } - else - { // 関係解消 - for (i = 0; i < 2 - (flag & 1); i++) - { - for (j = 0; j < MAX_GUILDALLIANCE; j++) - if (g[i]->alliance[j].guild_id == g[1 - i]->guild_id && - g[i]->alliance[j].opposition == (flag & 1)) - { - g[i]->alliance[j].guild_id = 0; - break; - } - } - } - mapif_guild_alliance (guild_id1, guild_id2, account_id1, account_id2, - flag, g[0]->name, g[1]->name); - inter_guild_tosql (g[0], 8); // Change guild_alliance - inter_guild_tosql (g[1], 8); // Change guild_alliance - return 0; -} - -// ギルド告知変更要求 -int mapif_parse_GuildNotice (int fd, int guild_id, const char *mes1, - const char *mes2) -{ - struct guild *g; - g = guild_pt; - inter_guild_fromsql (guild_id, g); - - if (g == NULL || g->guild_id <= 0) - return 0; - memcpy (g->mes1, mes1, 60); - memcpy (g->mes2, mes2, 120); - inter_guild_tosql (g, 1); // Change mes of guild - return mapif_guild_notice (g); -} - -// ギルドエンブレム変更要求 -int mapif_parse_GuildEmblem (int fd, int len, int guild_id, int dummy, - const char *data) -{ - struct guild *g; - g = guild_pt; - inter_guild_fromsql (guild_id, g); - - if (g == NULL || g->guild_id <= 0) - return 0; - memcpy (g->emblem_data, data, len); - g->emblem_len = len; - g->emblem_id++; - inter_guild_tosql (g, 1); // Change guild - return mapif_guild_emblem (g); -} - -int mapif_parse_GuildCastleDataLoad (int fd, int castle_id, int index) // -{ - struct guild_castle *gc = guildcastle_pt; - inter_guildcastle_fromsql (castle_id, gc); - if (gc == NULL || gc->castle_id == -1) - { - return mapif_guild_castle_dataload (castle_id, 0, 0); - } - switch (index) - { - case 1: - return mapif_guild_castle_dataload (gc->castle_id, index, - gc->guild_id); - break; - case 2: - return mapif_guild_castle_dataload (gc->castle_id, index, - gc->economy); - break; - case 3: - return mapif_guild_castle_dataload (gc->castle_id, index, - gc->defense); - break; - case 4: - return mapif_guild_castle_dataload (gc->castle_id, index, - gc->triggerE); - break; - case 5: - return mapif_guild_castle_dataload (gc->castle_id, index, - gc->triggerD); - break; - case 6: - return mapif_guild_castle_dataload (gc->castle_id, index, - gc->nextTime); - break; - case 7: - return mapif_guild_castle_dataload (gc->castle_id, index, - gc->payTime); - break; - case 8: - return mapif_guild_castle_dataload (gc->castle_id, index, - gc->createTime); - break; - case 9: - return mapif_guild_castle_dataload (gc->castle_id, index, - gc->visibleC); - break; - case 10: - return mapif_guild_castle_dataload (gc->castle_id, index, - gc->visibleG0); - break; - case 11: - return mapif_guild_castle_dataload (gc->castle_id, index, - gc->visibleG1); - break; - case 12: - return mapif_guild_castle_dataload (gc->castle_id, index, - gc->visibleG2); - break; - case 13: - return mapif_guild_castle_dataload (gc->castle_id, index, - gc->visibleG3); - break; - case 14: - return mapif_guild_castle_dataload (gc->castle_id, index, - gc->visibleG4); - break; - case 15: - return mapif_guild_castle_dataload (gc->castle_id, index, - gc->visibleG5); - break; - case 16: - return mapif_guild_castle_dataload (gc->castle_id, index, - gc->visibleG6); - break; - case 17: - return mapif_guild_castle_dataload (gc->castle_id, index, - gc->visibleG7); - break; - case 18: - return mapif_guild_castle_dataload (gc->castle_id, index, - gc->Ghp0); - break; // guardian HP [Valaris] - case 19: - return mapif_guild_castle_dataload (gc->castle_id, index, - gc->Ghp1); - break; - case 20: - return mapif_guild_castle_dataload (gc->castle_id, index, - gc->Ghp2); - break; - case 21: - return mapif_guild_castle_dataload (gc->castle_id, index, - gc->Ghp3); - break; - case 22: - return mapif_guild_castle_dataload (gc->castle_id, index, - gc->Ghp4); - break; - case 23: - return mapif_guild_castle_dataload (gc->castle_id, index, - gc->Ghp5); - break; - case 24: - return mapif_guild_castle_dataload (gc->castle_id, index, - gc->Ghp6); - break; - case 25: - return mapif_guild_castle_dataload (gc->castle_id, index, - gc->Ghp7); - break; // end additions [Valaris] - default: - printf - ("mapif_parse_GuildCastleDataLoad ERROR!! (Not found index=%d)\n", - index); - return 0; - } -} - -int mapif_parse_GuildCastleDataSave (int fd, int castle_id, int index, int value) // -{ - struct guild_castle *gc = guildcastle_pt; - inter_guildcastle_fromsql (castle_id, gc); - if (gc == NULL || gc->castle_id == -1) - { - return mapif_guild_castle_datasave (castle_id, index, value); - } - switch (index) - { - case 1: - if (gc->guild_id != value) - { - int gid = (value) ? value : gc->guild_id; - struct guild *g = guild_pt; - inter_guild_fromsql (gid, g); - inter_log ("guild %s (id=%d) %s castle id=%d" RETCODE, - (g) ? g->name : "??", gid, - (value) ? "occupy" : "abandon", index); - } - gc->guild_id = value; - break; - case 2: - gc->economy = value; - break; - case 3: - gc->defense = value; - break; - case 4: - gc->triggerE = value; - break; - case 5: - gc->triggerD = value; - break; - case 6: - gc->nextTime = value; - break; - case 7: - gc->payTime = value; - break; - case 8: - gc->createTime = value; - break; - case 9: - gc->visibleC = value; - break; - case 10: - gc->visibleG0 = value; - break; - case 11: - gc->visibleG1 = value; - break; - case 12: - gc->visibleG2 = value; - break; - case 13: - gc->visibleG3 = value; - break; - case 14: - gc->visibleG4 = value; - break; - case 15: - gc->visibleG5 = value; - break; - case 16: - gc->visibleG6 = value; - break; - case 17: - gc->visibleG7 = value; - break; - case 18: - gc->Ghp0 = value; - break; // guardian HP [Valaris] - case 19: - gc->Ghp1 = value; - break; - case 20: - gc->Ghp2 = value; - break; - case 21: - gc->Ghp3 = value; - break; - case 22: - gc->Ghp4 = value; - break; - case 23: - gc->Ghp5 = value; - break; - case 24: - gc->Ghp6 = value; - break; - case 25: - gc->Ghp7 = value; - break; // end additions [Valaris] - default: - printf - ("mapif_parse_GuildCastleDataSave ERROR!! (Not found index=%d)\n", - index); - return 0; - } - inter_guildcastle_tosql (gc); - return mapif_guild_castle_datasave (gc->castle_id, index, value); -} - -// ギルドチェック要求 -int mapif_parse_GuildCheck (int fd, int guild_id, int account_id, int char_id) -{ - // What does this mean? Check if belong to another guild? - return 0; -} - -// map server からの通信 -// ・1パケットのみ解析すること -// ・パケット長データはinter.cにセットしておくこと -// ・パケット長チェックや、RFIFOSKIPは呼び出し元で行われるので行ってはならない -// ・エラーなら0(false)、そうでないなら1(true)をかえさなければならない -int inter_guild_parse_frommap (int fd) -{ - switch (RFIFOW (fd, 0)) - { - case 0x3030: - mapif_parse_CreateGuild (fd, RFIFOL (fd, 4), RFIFOP (fd, 8), - (struct guild_member *) RFIFOP (fd, 32)); - break; - case 0x3031: - mapif_parse_GuildInfo (fd, RFIFOL (fd, 2)); - break; - case 0x3032: - mapif_parse_GuildAddMember (fd, RFIFOL (fd, 4), - (struct guild_member *) RFIFOP (fd, - 8)); - break; - case 0x3034: - mapif_parse_GuildLeave (fd, RFIFOL (fd, 2), RFIFOL (fd, 6), - RFIFOL (fd, 10), RFIFOB (fd, 14), - RFIFOP (fd, 15)); - break; - case 0x3035: - mapif_parse_GuildChangeMemberInfoShort (fd, RFIFOL (fd, 2), - RFIFOL (fd, 6), - RFIFOL (fd, 10), - RFIFOB (fd, 14), - RFIFOW (fd, 15), - RFIFOW (fd, 17)); - break; - case 0x3036: - mapif_parse_BreakGuild (fd, RFIFOL (fd, 2)); - break; - case 0x3037: - mapif_parse_GuildMessage (fd, RFIFOL (fd, 4), RFIFOL (fd, 8), - RFIFOP (fd, 12), RFIFOW (fd, 2) - 12); - break; - case 0x3038: - mapif_parse_GuildCheck (fd, RFIFOL (fd, 2), RFIFOL (fd, 6), - RFIFOL (fd, 10)); - break; - case 0x3039: - mapif_parse_GuildBasicInfoChange (fd, RFIFOL (fd, 4), - RFIFOW (fd, 8), RFIFOP (fd, 10), - RFIFOW (fd, 2) - 10); - break; - case 0x303A: - mapif_parse_GuildMemberInfoChange (fd, RFIFOL (fd, 4), - RFIFOL (fd, 8), RFIFOL (fd, - 12), - RFIFOW (fd, 16), RFIFOP (fd, - 18), - RFIFOW (fd, 2) - 18); - break; - case 0x303B: - mapif_parse_GuildPosition (fd, RFIFOL (fd, 4), RFIFOL (fd, 8), - (struct guild_position *) RFIFOP (fd, - 12)); - break; - case 0x303C: - mapif_parse_GuildSkillUp (fd, RFIFOL (fd, 2), RFIFOL (fd, 6), - RFIFOL (fd, 10)); - break; - case 0x303D: - mapif_parse_GuildAlliance (fd, RFIFOL (fd, 2), RFIFOL (fd, 6), - RFIFOL (fd, 10), RFIFOL (fd, 14), - RFIFOB (fd, 18)); - break; - case 0x303E: - mapif_parse_GuildNotice (fd, RFIFOL (fd, 2), RFIFOP (fd, 6), - RFIFOP (fd, 66)); - break; - case 0x303F: - mapif_parse_GuildEmblem (fd, RFIFOW (fd, 2) - 12, RFIFOL (fd, 4), - RFIFOL (fd, 8), RFIFOP (fd, 12)); - break; - case 0x3040: - mapif_parse_GuildCastleDataLoad (fd, RFIFOW (fd, 2), - RFIFOB (fd, 4)); - break; - case 0x3041: - mapif_parse_GuildCastleDataSave (fd, RFIFOW (fd, 2), - RFIFOB (fd, 4), RFIFOL (fd, 5)); - break; - - default: - return 0; - } - return 1; -} - -int inter_guild_mapif_init (int fd) -{ - return mapif_guild_castle_alldataload (fd); -} - -// サーバーから脱退要求(キャラ削除用) -int inter_guild_leave (int guild_id, int account_id, int char_id) -{ - return mapif_parse_GuildLeave (-1, guild_id, account_id, char_id, 0, - "**サーバー命令**"); -} diff --git a/src/char_sql/int_guild.h b/src/char_sql/int_guild.h deleted file mode 100644 index 9fa439c..0000000 --- a/src/char_sql/int_guild.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef _INT_GUILD_H_ -#define _INT_GUILD_H_ - -int inter_guild_parse_frommap (int fd); -int inter_guild_sql_init (); -int inter_guild_mapif_init (int fd); - -int inter_guild_leave (int guild_id, int account_id, int char_id); - -#endif diff --git a/src/char_sql/int_party.c b/src/char_sql/int_party.c deleted file mode 100644 index 45237de..0000000 --- a/src/char_sql/int_party.c +++ /dev/null @@ -1,935 +0,0 @@ -// -// original code from athena -// SQL conversion by hack -// - -#include "char.h" -#include "strlib.h" -#include "socket.h" -#include -#include -#include - -static struct party *party_pt; -static int party_newid = 100; - -int mapif_party_broken (int party_id, int flag); -int party_check_empty (struct party *p); -int mapif_parse_PartyLeave (int fd, int party_id, int account_id); - -// Save party to mysql -int inter_party_tosql (int party_id, struct party *p) -{ - // 'party' ('party_id','name','exp','item','leader') - - char t_name[100]; - char t_member[24]; - int party_member = 0, party_online_member = 0; - int party_exist = 0; - int leader_id = 0; - int i = 0; - - printf ("(\033[1;64m%d\033[0m) Request save party - ", party_id); - - jstrescapecpy (t_name, p->name); - - if (p == NULL || party_id == 0 || p->party_id == 0 - || party_id != p->party_id) - { - printf ("- Party pointer or party_id error \n"); - return 0; - } - - // Check if party exists - sprintf (tmp_sql, "SELECT count(*) FROM `%s` WHERE `party_id`='%d'", - party_db, party_id); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error - %s\n", mysql_error (&mysql_handle)); - return 0; - } - sql_res = mysql_store_result (&mysql_handle); - if (sql_res != NULL && mysql_num_rows (sql_res) > 0) - { - sql_row = mysql_fetch_row (sql_res); - party_exist = atoi (sql_row[0]); - //printf("- Check if party %d exists : %s\n",party_id,party_exist==0?"No":"Yes"); - } - mysql_free_result (sql_res); //resource free - - if (party_exist > 0) - { - // Check members in party - sprintf (tmp_sql, "SELECT count(*) FROM `%s` WHERE `party_id`='%d'", - char_db, party_id); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error - %s\n", mysql_error (&mysql_handle)); - return 0; - } - sql_res = mysql_store_result (&mysql_handle); - if (sql_res != NULL && mysql_num_rows (sql_res) > 0) - { - sql_row = mysql_fetch_row (sql_res); - - party_member = atoi (sql_row[0]); - // printf("- Check members in party %d : %d \n",party_id,party_member); - - } - mysql_free_result (sql_res); //resource free - - party_online_member = 0; - i = 0; - while (i < MAX_PARTY) - { - if (p->member[i].account_id > 0) - party_online_member++; - i++; - } - - //if (party_online_member==0) printf("- No member online \n"); else printf("- Some member %d online \n", party_online_member); - - if (party_member <= 0 && party_online_member == 0) - { - - // Delete the party, if has no member. - sprintf (tmp_sql, "DELETE FROM `%s` WHERE `party_id`='%d'", - party_db, party_id); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error - %s\n", - mysql_error (&mysql_handle)); - } - // printf("No member in party %d, break it \n",party_id); - memset (p, 0, sizeof (struct party)); - return 0; - } - else - { - // Update party information, if exists - - int i = 0; - - for (i = 0; i < MAX_PARTY; i++) - { - - if (p->member[i].account_id > 0) - { - sprintf (tmp_sql, - "UPDATE `%s` SET `party_id`='%d', `online`='%d' WHERE `account_id`='%d' AND `name`='%s'", - char_db, party_id, p->member[i].online, - p->member[i].account_id, jstrescapecpy (t_member, - p->member - [i].name)); - //printf("%s",tmp_sql); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (update `char`)- %s\n", - mysql_error (&mysql_handle)); - } - } - } - - sprintf (tmp_sql, - "UPDATE `%s` SET `name`='%s', `exp`='%d', `item`='%d', `leader_id`=`leader_id` WHERE `party_id`='%d'", - party_db, t_name, p->exp, p->item, party_id); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (inset/update `party`)- %s\n", - mysql_error (&mysql_handle)); - } - - // printf("- Update party %d information \n",party_id); - } - } - else - { - // Add new party, if not exist - int i = 0; - while (i < MAX_PARTY - && ((p->member[i].account_id > 0 && p->member[i].leader == 0) - || (p->member[i].account_id < 0))) - i++; - if (i < MAX_PARTY) - leader_id = p->member[i].account_id; - sprintf (tmp_sql, - "INSERT INTO `%s` (`party_id`, `name`, `exp`, `item`, `leader_id`) VALUES ('%d', '%s', '%d', '%d', '%d')", - party_db, party_id, t_name, p->exp, p->item, leader_id); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (inset/update `party`)- %s\n", - mysql_error (&mysql_handle)); - return 0; - } - - sprintf (tmp_sql, - "UPDATE `%s` SET `party_id`='%d', `online`='1' WHERE `account_id`='%d' AND `name`='%s'", - char_db, party_id, leader_id, jstrescapecpy (t_member, - p-> - member - [i].name)); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (inset/update `party`)- %s\n", - mysql_error (&mysql_handle)); - } - - //printf("- Insert new party %d \n",party_id); - } - - printf ("Party save success\n"); - return 0; - -} - -// Read party from mysql -int inter_party_fromsql (int party_id, struct party *p) -{ - int leader_id = 0; - printf ("(\033[1;64m%d\033[0m) Request load party - ", party_id); - - memset (p, 0, sizeof (struct party)); - - sprintf (tmp_sql, - "SELECT `party_id`, `name`,`exp`,`item`, `leader_id` FROM `%s` WHERE `party_id`='%d'", - party_db, party_id); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (select `party`)- %s\n", - mysql_error (&mysql_handle)); - return 0; - } - - sql_res = mysql_store_result (&mysql_handle); - if (sql_res != NULL && mysql_num_rows (sql_res) > 0) - { - sql_row = mysql_fetch_row (sql_res); - // printf("- Read party %d from MySQL\n",party_id); - p->party_id = party_id; - strcpy (p->name, sql_row[1]); - p->exp = atoi (sql_row[2]); - p->item = atoi (sql_row[3]); - leader_id = atoi (sql_row[4]); - } - else - { - mysql_free_result (sql_res); - // printf("- Cannot find party %d \n",party_id); - return 0; - } - - mysql_free_result (sql_res); - - // Load members - sprintf (tmp_sql, - "SELECT `account_id`, `name`,`base_level`,`last_map`,`online` FROM `%s` WHERE `party_id`='%d'", - char_db, party_id); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (select `party`)- %s\n", - mysql_error (&mysql_handle)); - return 0; - } - sql_res = mysql_store_result (&mysql_handle); - if (sql_res != NULL && mysql_num_rows (sql_res) > 0) - { - int i; - for (i = 0; (sql_row = mysql_fetch_row (sql_res)); i++) - { - struct party_member *m = &p->member[i]; - m->account_id = atoi (sql_row[0]); - if (m->account_id == leader_id) - m->leader = 1; - else - m->leader = 0; - strncpy (m->name, sql_row[1], sizeof (m->name)); - m->lv = atoi (sql_row[2]); - strncpy (m->map, sql_row[3], sizeof (m->map)); - m->online = atoi (sql_row[4]); - } - // printf("- %d members found in party %d \n",i,party_id); - } - mysql_free_result (sql_res); - - printf ("Party load success\n"); - return 0; - -} - -int inter_party_sql_init () -{ - int i; - - //memory alloc - printf ("interserver party memory initialize.... (%d byte)\n", - sizeof (struct party)); - party_pt = calloc (sizeof (struct party), 1); - - sprintf (tmp_sql, "UPDATE `%s` SET `online`='0'", char_db); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (update `char`)- %s\n", - mysql_error (&mysql_handle)); - } - - sprintf (tmp_sql, "SELECT count(*) FROM `%s`", party_db); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error - %s\n", mysql_error (&mysql_handle)); - } - sql_res = mysql_store_result (&mysql_handle); - sql_row = mysql_fetch_row (sql_res); - printf ("total party data -> '%s'.......\n", sql_row[0]); - i = atoi (sql_row[0]); - mysql_free_result (sql_res); - - if (i > 0) - { - //set party_newid - sprintf (tmp_sql, "SELECT max(`party_id`) FROM `%s`", party_db); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error - %s\n", mysql_error (&mysql_handle)); - } - - sql_res = mysql_store_result (&mysql_handle); - - sql_row = mysql_fetch_row (sql_res); - party_newid = atoi (sql_row[0]) + 1; - mysql_free_result (sql_res); - } - - printf ("set party_newid: %d.......\n", party_newid); - - return 0; -} - -// Search for the party according to its name -struct party *search_partyname (char *str) -{ - struct party *p = NULL; - int leader_id = 0; - char t_name[24]; - - sprintf (tmp_sql, - "SELECT `party_id`, `name`,`exp`,`item`,`leader_id` FROM `%s` WHERE `name`='%s'", - party_db, jstrescapecpy (t_name, str)); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (select `party`)- %s\n", - mysql_error (&mysql_handle)); - } - sql_res = mysql_store_result (&mysql_handle); - if (sql_res == NULL || mysql_num_rows (sql_res) <= 0) - { - mysql_free_result (sql_res); - return p; - } - sql_row = mysql_fetch_row (sql_res); - p = party_pt; - p->party_id = atoi (sql_row[0]); - strcpy (p->name, sql_row[1]); - p->exp = atoi (sql_row[2]); - p->item = atoi (sql_row[3]); - leader_id = atoi (sql_row[4]); - mysql_free_result (sql_res); - - // Load members - sprintf (tmp_sql, - "SELECT `account_id`, `name`,`base_level`,`last_map`,`online` FROM `%s` WHERE `party_id`='%d'", - char_db, p->party_id); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (select `party`)- %s\n", - mysql_error (&mysql_handle)); - return 0; - } - sql_res = mysql_store_result (&mysql_handle); - if (sql_res != NULL && mysql_num_rows (sql_res) > 0) - { - int i; - for (i = 0; (sql_row = mysql_fetch_row (sql_res)); i++) - { - struct party_member *m = &p->member[i]; - m->account_id = atoi (sql_row[0]); - if (m->account_id == leader_id) - m->leader = 1; - else - m->leader = 0; - strncpy (m->name, sql_row[1], sizeof (m->name)); - m->lv = atoi (sql_row[2]); - strncpy (m->map, sql_row[3], sizeof (m->map)); - m->online = atoi (sql_row[4]); - } - printf ("- %d members found in party %d \n", i, p->party_id); - } - mysql_free_result (sql_res); - - return p; -} - -// EXP公平分配できるかチェック -int party_check_exp_share (struct party *p) -{ - int i; - int maxlv = 0, minlv = 0x7fffffff; - for (i = 0; i < MAX_PARTY; i++) - { - int lv = p->member[i].lv; - if (p->member[i].online) - { - if (lv < minlv) - minlv = lv; - if (maxlv < lv) - maxlv = lv; - } - } - return (maxlv == 0 || maxlv - minlv <= party_share_level); -} - -// Is there any member in the party? -int party_check_empty (struct party *p) -{ - int i; - if (p == NULL || p->party_id == 0) - return 1; -// printf("party check empty %08X\n",(int)p); - for (i = 0; i < MAX_PARTY; i++) - { -// printf("%d acc=%d\n",i,p->member[i].account_id); - if (p->member[i].account_id > 0) - { - return 0; - } - } - // If there is no member, then break the party - mapif_party_broken (p->party_id, 0); - inter_party_tosql (p->party_id, p); - return 1; -} - -// Check if a member is in two party, not necessary :) -int party_check_conflict (int party_id, int account_id, char *nick) -{ - return 0; -} - -//------------------------------------------------------------------- -// map serverへの通信 - -// パーティ作成可否 -int mapif_party_created (int fd, int account_id, struct party *p) -{ - WFIFOW (fd, 0) = 0x3820; - WFIFOL (fd, 2) = account_id; - if (p != NULL) - { - WFIFOB (fd, 6) = 0; - WFIFOL (fd, 7) = p->party_id; - memcpy (WFIFOP (fd, 11), p->name, 24); - printf ("int_party: created! %d %s\n", p->party_id, p->name); - } - else - { - WFIFOB (fd, 6) = 1; - WFIFOL (fd, 7) = 0; - memcpy (WFIFOP (fd, 11), "error", 24); - } - WFIFOSET (fd, 35); - return 0; -} - -// パーティ情報見つからず -int mapif_party_noinfo (int fd, int party_id) -{ - WFIFOW (fd, 0) = 0x3821; - WFIFOW (fd, 2) = 8; - WFIFOL (fd, 4) = party_id; - WFIFOSET (fd, 8); - printf ("int_party: info not found %d\n", party_id); - return 0; -} - -// パーティ情報まとめ送り -int mapif_party_info (int fd, struct party *p) -{ - unsigned char buf[1024]; - WBUFW (buf, 0) = 0x3821; - memcpy (buf + 4, p, sizeof (struct party)); - WBUFW (buf, 2) = 4 + sizeof (struct party); - if (fd < 0) - mapif_sendall (buf, WBUFW (buf, 2)); - else - mapif_send (fd, buf, WBUFW (buf, 2)); -// printf("int_party: info %d %s\n",p->party_id,p->name); - return 0; -} - -// パーティメンバ追加可否 -int mapif_party_memberadded (int fd, int party_id, int account_id, int flag) -{ - WFIFOW (fd, 0) = 0x3822; - WFIFOL (fd, 2) = party_id; - WFIFOL (fd, 6) = account_id; - WFIFOB (fd, 10) = flag; - WFIFOSET (fd, 11); - return 0; -} - -// パーティ設定変更通知 -int mapif_party_optionchanged (int fd, struct party *p, int account_id, - int flag) -{ - unsigned char buf[16]; - WBUFW (buf, 0) = 0x3823; - WBUFL (buf, 2) = p->party_id; - WBUFL (buf, 6) = account_id; - WBUFW (buf, 10) = p->exp; - WBUFW (buf, 12) = p->item; - WBUFB (buf, 14) = flag; - if (flag == 0) - mapif_sendall (buf, 15); - else - mapif_send (fd, buf, 15); - //printf("int_party: option changed %d %d %d %d %d\n",p->party_id,account_id,p->exp,p->item,flag); - return 0; -} - -// パーティ脱退通知 -int mapif_party_leaved (int party_id, int account_id, char *name) -{ - unsigned char buf[64]; - WBUFW (buf, 0) = 0x3824; - WBUFL (buf, 2) = party_id; - WBUFL (buf, 6) = account_id; - memcpy (WBUFP (buf, 10), name, 24); - mapif_sendall (buf, 34); - //printf("int_party: party leaved %d %d %s\n",party_id,account_id,name); - return 0; -} - -// パーティマップ更新通知 -int mapif_party_membermoved (struct party *p, int idx) -{ - unsigned char buf[32]; - WBUFW (buf, 0) = 0x3825; - WBUFL (buf, 2) = p->party_id; - WBUFL (buf, 6) = p->member[idx].account_id; - memcpy (WBUFP (buf, 10), p->member[idx].map, 16); - WBUFB (buf, 26) = p->member[idx].online; - WBUFW (buf, 27) = p->member[idx].lv; - mapif_sendall (buf, 29); - return 0; -} - -// パーティ解散通知 -int mapif_party_broken (int party_id, int flag) -{ - unsigned char buf[16]; - WBUFW (buf, 0) = 0x3826; - WBUFL (buf, 2) = party_id; - WBUFB (buf, 6) = flag; - mapif_sendall (buf, 7); - //printf("int_party: broken %d\n",party_id); - return 0; -} - -// パーティ内発言 -int mapif_party_message (int party_id, int account_id, char *mes, int len) -{ - unsigned char buf[512]; - WBUFW (buf, 0) = 0x3827; - WBUFW (buf, 2) = len + 12; - WBUFL (buf, 4) = party_id; - WBUFL (buf, 8) = account_id; - memcpy (WBUFP (buf, 12), mes, len); - mapif_sendall (buf, len + 12); - return 0; -} - -//------------------------------------------------------------------- -// map serverからの通信 - -// Create Party -int mapif_parse_CreateParty (int fd, int account_id, char *name, char *nick, - char *map, int lv) -{ - struct party *p; - if ((p = search_partyname (name)) != NULL) - { -// printf("int_party: same name party exists [%s]\n",name); - mapif_party_created (fd, account_id, NULL); - return 0; - } - p = party_pt; - if (p == NULL) - { - printf ("int_party: out of memory !\n"); - mapif_party_created (fd, account_id, NULL); - return 0; - } - memset (p, 0, sizeof (struct party)); - p->party_id = party_newid++; - memcpy (p->name, name, 24); - p->exp = 0; - p->item = 0; - p->member[0].account_id = account_id; - memcpy (p->member[0].name, nick, 24); - memcpy (p->member[0].map, map, 16); - p->member[0].leader = 1; - p->member[0].online = 1; - p->member[0].lv = lv; - - inter_party_tosql (p->party_id, p); - - mapif_party_created (fd, account_id, p); - mapif_party_info (fd, p); - - return 0; -} - -// パーティ情報要求 -int mapif_parse_PartyInfo (int fd, int party_id) -{ - struct party *p = party_pt; - if (p == NULL) - { - printf ("int_party: out of memory !\n"); - return 0; - } - inter_party_fromsql (party_id, p); - - if (p->party_id >= 0) - mapif_party_info (fd, p); - else - mapif_party_noinfo (fd, party_id); - return 0; -} - -// パーティ追加要求 -int mapif_parse_PartyAddMember (int fd, int party_id, int account_id, - char *nick, char *map, int lv) -{ - struct party *p; - int i; - - p = party_pt; - if (p == NULL) - { - printf ("int_party: out of memory !\n"); - return 0; - } - inter_party_fromsql (party_id, p); - - if (p->party_id <= 0) - { - mapif_party_memberadded (fd, party_id, account_id, 1); - return 0; - } - - for (i = 0; i < MAX_PARTY; i++) - { - if (p->member[i].account_id == 0) - { - int flag = 0; - - p->member[i].account_id = account_id; - memcpy (p->member[i].name, nick, 24); - memcpy (p->member[i].map, map, 16); - p->member[i].leader = 0; - p->member[i].online = 1; - p->member[i].lv = lv; - mapif_party_memberadded (fd, party_id, account_id, 0); - mapif_party_info (-1, p); - - if (p->exp > 0 && !party_check_exp_share (p)) - { - p->exp = 0; - flag = 0x01; - } - if (flag) - mapif_party_optionchanged (fd, p, 0, 0); - - inter_party_tosql (party_id, p); - return 0; - } - } - mapif_party_memberadded (fd, party_id, account_id, 1); - //inter_party_tosql(party_id, p); - return 0; -} - -// パーティー設定変更要求 -int mapif_parse_PartyChangeOption (int fd, int party_id, int account_id, - int exp, int item) -{ - struct party *p; - int flag = 0; - - p = party_pt; - if (p == NULL) - { - printf ("int_party: out of memory !\n"); - return 0; - } - - inter_party_fromsql (party_id, p); - - if (p->party_id <= 0) - { - return 0; - } - - p->exp = exp; - if (exp > 0 && !party_check_exp_share (p)) - { - flag |= 0x01; - p->exp = 0; - } - - p->item = item; - - mapif_party_optionchanged (fd, p, account_id, flag); - inter_party_tosql (party_id, p); - return 0; -} - -// パーティ脱退要求 -int mapif_parse_PartyLeave (int fd, int party_id, int account_id) -{ - char t_member[24]; - struct party *p = party_pt; - if (p == NULL) - { - printf ("int_party: out of memory !\n"); - return 0; - } - - inter_party_fromsql (party_id, p); - - if (p->party_id >= 0) - { - int i, j; - for (i = 0; i < MAX_PARTY; i++) - { - - if (p->member[i].account_id == account_id) - { - //printf("p->member[i].account_id = %d , account_id = %d \n",p->member[i].account_id,account_id); - mapif_party_leaved (party_id, account_id, p->member[i].name); - - // Update char information, does the name need encoding? - sprintf (tmp_sql, - "UPDATE `%s` SET `party_id`='0', `online`='1' WHERE `party_id`='%d' AND `name`='%s'", - char_db, party_id, jstrescapecpy (t_member, - p-> - member[i].name)); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (update `char`)- %s\n", - mysql_error (&mysql_handle)); - } -// printf("Delete member %s from MySQL \n", p->member[i].name); - - if (p->member[i].leader == 1) - { - for (j = 0; j < MAX_PARTY; j++) - { - //printf("j = %d , p->member[j].account_id = %d , p->member[j].account_id = %d \n",j,p->member[j].account_id,p->member[j].account_id); - if (p->member[j].account_id > 0 && j != i) - { - mapif_party_leaved (party_id, - p->member[j].account_id, - p->member[j].name); - // Update char information, does the name need encoding? - sprintf (tmp_sql, - "UPDATE `%s` SET `party_id`='0', `online`='1' WHERE `party_id`='%d' AND `name`='%s'", - char_db, party_id, - jstrescapecpy (t_member, - p->member[i].name)); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf - ("DB server Error (update `char`)- %s\n", - mysql_error (&mysql_handle)); - } -// printf("Delete member %s from MySQL \n", p->member[j].name); - } - } - // Delete the party, if has no member. - sprintf (tmp_sql, - "DELETE FROM `%s` WHERE `party_id`='%d'", - party_db, party_id); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error - %s\n", - mysql_error (&mysql_handle)); - } -// printf("Leader breaks party %d \n",party_id); - memset (p, 0, sizeof (struct party)); - } - else - memset (&p->member[i], 0, sizeof (struct party_member)); - - break; - - } - } - if (party_check_empty (p) == 0) - mapif_party_info (-1, p); // まだ人がいるのでデータ送信 - /* - * else - * inter_party_tosql(party_id,p); // Break the party if no member - */ - } - else - { - sprintf (tmp_sql, - "UPDATE `%s` SET `party_id`='0' WHERE `party_id`='%d' AND `account_id`='%d' AND `online`='1'", - char_db, party_id, account_id); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (update `char`)- %s\n", - mysql_error (&mysql_handle)); - } - } - return 0; -} - -// When member goes to other map -int mapif_parse_PartyChangeMap (int fd, int party_id, int account_id, - char *map, int online, int lv) -{ - struct party *p; - int i; - - p = party_pt; - if (p == NULL) - { - printf ("int_party: out of memory !\n"); - return 0; - } - inter_party_fromsql (party_id, p); - - if (p->party_id <= 0) - { - return 0; - } - for (i = 0; i < MAX_PARTY; i++) - { - if (p->member[i].account_id == account_id) - { - int flag = 0; - - memcpy (p->member[i].map, map, 16); - p->member[i].online = online; - p->member[i].lv = lv; - mapif_party_membermoved (p, i); - - if (p->exp > 0 && !party_check_exp_share (p)) - { - p->exp = 0; - flag = 1; - } - if (flag) - mapif_party_optionchanged (fd, p, 0, 0); - break; - } - } - inter_party_tosql (party_id, p); - return 0; -} - -// パーティ解散要求 -int mapif_parse_BreakParty (int fd, int party_id) -{ - struct party *p; - - p = party_pt; - if (p == NULL) - { - printf ("int_party: out of memory !\n"); - return 0; - } - - inter_party_fromsql (party_id, p); - - if (p->party_id <= 0) - { - return 0; - } - inter_party_tosql (party_id, p); - - mapif_party_broken (fd, party_id); - return 0; -} - -// パーティメッセージ送信 -int mapif_parse_PartyMessage (int fd, int party_id, int account_id, char *mes, - int len) -{ - return mapif_party_message (party_id, account_id, mes, len); -} - -// パーティチェック要求 -int mapif_parse_PartyCheck (int fd, int party_id, int account_id, char *nick) -{ - return party_check_conflict (party_id, account_id, nick); -} - -// map server からの通信 -// ・1パケットのみ解析すること -// ・パケット長データはinter.cにセットしておくこと -// ・パケット長チェックや、RFIFOSKIPは呼び出し元で行われるので行ってはならない -// ・エラーなら0(false)、そうでないなら1(true)をかえさなければならない -int inter_party_parse_frommap (int fd) -{ - switch (RFIFOW (fd, 0)) - { - case 0x3020: - mapif_parse_CreateParty (fd, RFIFOL (fd, 2), RFIFOP (fd, 6), - RFIFOP (fd, 30), RFIFOP (fd, 54), - RFIFOW (fd, 70)); - break; - case 0x3021: - mapif_parse_PartyInfo (fd, RFIFOL (fd, 2)); - break; - case 0x3022: - mapif_parse_PartyAddMember (fd, RFIFOL (fd, 2), RFIFOL (fd, 6), - RFIFOP (fd, 10), RFIFOP (fd, 34), - RFIFOW (fd, 50)); - break; - case 0x3023: - mapif_parse_PartyChangeOption (fd, RFIFOL (fd, 2), RFIFOL (fd, 6), - RFIFOW (fd, 10), RFIFOW (fd, 12)); - break; - case 0x3024: - mapif_parse_PartyLeave (fd, RFIFOL (fd, 2), RFIFOL (fd, 6)); - break; - case 0x3025: - mapif_parse_PartyChangeMap (fd, RFIFOL (fd, 2), RFIFOL (fd, 6), - RFIFOP (fd, 10), RFIFOB (fd, 26), - RFIFOW (fd, 27)); - break; - case 0x3026: - mapif_parse_BreakParty (fd, RFIFOL (fd, 2)); - break; - case 0x3027: - mapif_parse_PartyMessage (fd, RFIFOL (fd, 4), RFIFOL (fd, 8), - RFIFOP (fd, 12), RFIFOW (fd, 2) - 12); - break; - case 0x3028: - mapif_parse_PartyCheck (fd, RFIFOL (fd, 2), RFIFOL (fd, 6), - RFIFOP (fd, 10)); - break; - default: - return 0; - } - return 1; -} - -// サーバーから脱退要求(キャラ削除用) -int inter_party_leave (int party_id, int account_id) -{ - return mapif_parse_PartyLeave (-1, party_id, account_id); -} diff --git a/src/char_sql/int_party.h b/src/char_sql/int_party.h deleted file mode 100644 index 264ef8b..0000000 --- a/src/char_sql/int_party.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef _INT_PARTY_H_ -#define _INT_PARTY_H_ - -int inter_party_parse_frommap (int fd); -int inter_party_sql_init (); -int inter_party_leave (int party_id, int account_id); - -#endif diff --git a/src/char_sql/int_pet.c b/src/char_sql/int_pet.c deleted file mode 100644 index 78e499d..0000000 --- a/src/char_sql/int_pet.c +++ /dev/null @@ -1,383 +0,0 @@ -// -// original code from athena -// SQL conversion by Jioh L. Jung -// -#include "char.h" -#include "strlib.h" - -#include -#include -#include - -struct s_pet *pet_pt; -static int pet_newid = 100; - -//--------------------------------------------------------- -int inter_pet_tosql (int pet_id, struct s_pet *p) -{ - //`pet` (`pet_id`, `class`,`name`,`account_id`,`char_id`,`level`,`egg_id`,`equip`,`intimate`,`hungry`,`rename_flag`,`incuvate`) - char t_name[100]; - - printf ("request save pet: %d.......\n", pet_id); - - jstrescapecpy (t_name, p->name); - - if (p->hungry < 0) - p->hungry = 0; - else if (p->hungry > 100) - p->hungry = 100; - if (p->intimate < 0) - p->intimate = 0; - else if (p->intimate > 1000) - p->intimate = 1000; - sprintf (tmp_sql, "SELECT * FROM `%s` WHERE `pet_id`='%d'", pet_db, - pet_id); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error - %s\n", mysql_error (&mysql_handle)); - } - sql_res = mysql_store_result (&mysql_handle); - if (sql_res != NULL && mysql_num_rows (sql_res) > 0) - //row reside -> updating - sprintf (tmp_sql, - "UPDATE `%s` SET `class`='%d',`name`='%s',`account_id`='%d',`char_id`='%d',`level`='%d',`egg_id`='%d',`equip`='%d',`intimate`='%d',`hungry`='%d',`rename_flag`='%d',`incuvate`='%d' WHERE `pet_id`='%d'", - pet_db, p->class, t_name, p->account_id, p->char_id, - p->level, p->egg_id, p->equip, p->intimate, p->hungry, - p->rename_flag, p->incuvate, p->pet_id); - else //no row -> insert - sprintf (tmp_sql, - "INSERT INTO `%s` (`pet_id`, `class`,`name`,`account_id`,`char_id`,`level`,`egg_id`,`equip`,`intimate`,`hungry`,`rename_flag`,`incuvate`) VALUES ('%d', '%d', '%s', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d')", - pet_db, pet_id, p->class, t_name, p->account_id, p->char_id, - p->level, p->egg_id, p->equip, p->intimate, p->hungry, - p->rename_flag, p->incuvate); - mysql_free_result (sql_res); //resource free - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (inset/update `pet`)- %s\n", - mysql_error (&mysql_handle)); - } - - printf ("pet save success.......\n"); - return 0; -} - -int inter_pet_fromsql (int pet_id, struct s_pet *p) -{ - - printf ("request load pet: %d.......\n", pet_id); - - memset (p, 0, sizeof (struct s_pet)); - - //`pet` (`pet_id`, `class`,`name`,`account_id`,`char_id`,`level`,`egg_id`,`equip`,`intimate`,`hungry`,`rename_flag`,`incuvate`) - - sprintf (tmp_sql, - "SELECT `pet_id`, `class`,`name`,`account_id`,`char_id`,`level`,`egg_id`,`equip`,`intimate`,`hungry`,`rename_flag`,`incuvate` FROM `%s` WHERE `pet_id`='%d'", - pet_db, pet_id); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (select `pet`)- %s\n", - mysql_error (&mysql_handle)); - return 0; - } - sql_res = mysql_store_result (&mysql_handle); - if (sql_res != NULL && mysql_num_rows (sql_res) > 0) - { - sql_row = mysql_fetch_row (sql_res); - - p->pet_id = pet_id; - p->class = atoi (sql_row[1]); - memcpy (p->name, sql_row[2], 24); - p->account_id = atoi (sql_row[3]); - p->char_id = atoi (sql_row[4]); - p->level = atoi (sql_row[5]); - p->egg_id = atoi (sql_row[6]); - p->equip = atoi (sql_row[7]); - p->intimate = atoi (sql_row[8]); - p->hungry = atoi (sql_row[9]); - p->rename_flag = atoi (sql_row[10]); - p->incuvate = atoi (sql_row[11]); - } - if (p->hungry < 0) - p->hungry = 0; - else if (p->hungry > 100) - p->hungry = 100; - if (p->intimate < 0) - p->intimate = 0; - else if (p->intimate > 1000) - p->intimate = 1000; - - mysql_free_result (sql_res); - - printf ("pet load success.......\n"); - return 0; -} - -//---------------------------------------------- - -int inter_pet_sql_init () -{ - int i; - - //memory alloc - printf ("interserver pet memory initialize.... (%d byte)\n", - sizeof (struct s_pet)); - pet_pt = calloc (sizeof (struct s_pet), 1); - - sprintf (tmp_sql, "SELECT count(*) FROM `%s`", pet_db); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error - %s\n", mysql_error (&mysql_handle)); - exit (0); - } - sql_res = mysql_store_result (&mysql_handle); - sql_row = mysql_fetch_row (sql_res); - printf ("total pet data -> '%s'.......\n", sql_row[0]); - i = atoi (sql_row[0]); - mysql_free_result (sql_res); - - if (i > 0) - { - //set pet_newid - sprintf (tmp_sql, "SELECT max(`pet_id`) FROM `%s`", pet_db); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error - %s\n", mysql_error (&mysql_handle)); - } - - sql_res = mysql_store_result (&mysql_handle); - - sql_row = mysql_fetch_row (sql_res); - pet_newid = atoi (sql_row[0]); - mysql_free_result (sql_res); - } - - printf ("set pet_newid: %d.......\n", pet_newid); - - return 0; -} - -//---------------------------------- -int inter_pet_delete (int pet_id) -{ - printf ("request delete pet: %d.......\n", pet_id); - - sprintf (tmp_sql, "DELETE FROM `%s` WHERE `pet_id`='%d'", pet_db, pet_id); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error - %s\n", mysql_error (&mysql_handle)); - } - return 0; -} - -//------------------------------------------------------ -int mapif_pet_created (int fd, int account_id, struct s_pet *p) -{ - WFIFOW (fd, 0) = 0x3880; - WFIFOL (fd, 2) = account_id; - if (p != NULL) - { - WFIFOB (fd, 6) = 0; - WFIFOL (fd, 7) = p->pet_id; - printf ("int_pet: created! %d %s\n", p->pet_id, p->name); - } - else - { - WFIFOB (fd, 6) = 1; - WFIFOL (fd, 7) = 0; - } - WFIFOSET (fd, 11); - - return 0; -} - -int mapif_pet_info (int fd, int account_id, struct s_pet *p) -{ - WFIFOW (fd, 0) = 0x3881; - WFIFOW (fd, 2) = sizeof (struct s_pet) + 9; - WFIFOL (fd, 4) = account_id; - WFIFOB (fd, 8) = 0; - memcpy (WFIFOP (fd, 9), p, sizeof (struct s_pet)); - WFIFOSET (fd, WFIFOW (fd, 2)); - - return 0; -} - -int mapif_pet_noinfo (int fd, int account_id) -{ - WFIFOW (fd, 0) = 0x3881; - WFIFOW (fd, 2) = sizeof (struct s_pet) + 9; - WFIFOL (fd, 4) = account_id; - WFIFOB (fd, 8) = 1; - memset (WFIFOP (fd, 9), 0, sizeof (struct s_pet)); - WFIFOSET (fd, WFIFOW (fd, 2)); - - return 0; -} - -int mapif_save_pet_ack (int fd, int account_id, int flag) -{ - WFIFOW (fd, 0) = 0x3882; - WFIFOL (fd, 2) = account_id; - WFIFOB (fd, 6) = flag; - WFIFOSET (fd, 7); - - return 0; -} - -int mapif_delete_pet_ack (int fd, int flag) -{ - WFIFOW (fd, 0) = 0x3883; - WFIFOB (fd, 2) = flag; - WFIFOSET (fd, 3); - - return 0; -} - -int mapif_create_pet (int fd, int account_id, int char_id, short pet_class, - short pet_lv, short pet_egg_id, short pet_equip, - short intimate, short hungry, char rename_flag, - char incuvate, char *pet_name) -{ - - memset (pet_pt, 0, sizeof (struct s_pet)); - pet_pt->pet_id = pet_newid++; - memcpy (pet_pt->name, pet_name, 24); - if (incuvate == 1) - pet_pt->account_id = pet_pt->char_id = 0; - else - { - pet_pt->account_id = account_id; - pet_pt->char_id = char_id; - } - pet_pt->class = pet_class; - pet_pt->level = pet_lv; - pet_pt->egg_id = pet_egg_id; - pet_pt->equip = pet_equip; - pet_pt->intimate = intimate; - pet_pt->hungry = hungry; - pet_pt->rename_flag = rename_flag; - pet_pt->incuvate = incuvate; - - if (pet_pt->hungry < 0) - pet_pt->hungry = 0; - else if (pet_pt->hungry > 100) - pet_pt->hungry = 100; - if (pet_pt->intimate < 0) - pet_pt->intimate = 0; - else if (pet_pt->intimate > 1000) - pet_pt->intimate = 1000; - - inter_pet_tosql (pet_pt->pet_id, pet_pt); - - mapif_pet_created (fd, account_id, pet_pt); - - return 0; -} - -int mapif_load_pet (int fd, int account_id, int char_id, int pet_id) -{ - memset (pet_pt, 0, sizeof (struct s_pet)); - - inter_pet_fromsql (pet_id, pet_pt); - - if (pet_pt != NULL) - { - if (pet_pt->incuvate == 1) - { - pet_pt->account_id = pet_pt->char_id = 0; - mapif_pet_info (fd, account_id, pet_pt); - } - else if (account_id == pet_pt->account_id - && char_id == pet_pt->char_id) - mapif_pet_info (fd, account_id, pet_pt); - else - mapif_pet_noinfo (fd, account_id); - } - else - mapif_pet_noinfo (fd, account_id); - - return 0; -} - -int mapif_save_pet (int fd, int account_id, struct s_pet *data) -{ - //here process pet save request. - int len = RFIFOW (fd, 2); - if (sizeof (struct s_pet) != len - 8) - { - printf ("inter pet: data size error %d %d\n", sizeof (struct s_pet), - len - 8); - } - - else - { - if (data->hungry < 0) - data->hungry = 0; - else if (data->hungry > 100) - data->hungry = 100; - if (data->intimate < 0) - data->intimate = 0; - else if (data->intimate > 1000) - data->intimate = 1000; - inter_pet_tosql (data->pet_id, data); - mapif_save_pet_ack (fd, account_id, 0); - } - - return 0; -} - -int mapif_delete_pet (int fd, int pet_id) -{ - mapif_delete_pet_ack (fd, inter_pet_delete (pet_id)); - - return 0; -} - -int mapif_parse_CreatePet (int fd) -{ - mapif_create_pet (fd, RFIFOL (fd, 2), RFIFOL (fd, 6), RFIFOW (fd, 10), - RFIFOW (fd, 12), RFIFOW (fd, 14), RFIFOW (fd, 16), - RFIFOL (fd, 18), RFIFOL (fd, 20), RFIFOB (fd, 22), - RFIFOB (fd, 23), RFIFOP (fd, 24)); - return 0; -} - -int mapif_parse_LoadPet (int fd) -{ - mapif_load_pet (fd, RFIFOL (fd, 2), RFIFOL (fd, 6), RFIFOL (fd, 10)); - return 0; -} - -int mapif_parse_SavePet (int fd) -{ - mapif_save_pet (fd, RFIFOL (fd, 4), (struct s_pet *) RFIFOP (fd, 8)); - return 0; -} - -int mapif_parse_DeletePet (int fd) -{ - mapif_delete_pet (fd, RFIFOL (fd, 2)); - return 0; -} - -int inter_pet_parse_frommap (int fd) -{ - switch (RFIFOW (fd, 0)) - { - case 0x3080: - mapif_parse_CreatePet (fd); - break; - case 0x3081: - mapif_parse_LoadPet (fd); - break; - case 0x3082: - mapif_parse_SavePet (fd); - break; - case 0x3083: - mapif_parse_DeletePet (fd); - break; - default: - return 0; - } - return 1; -} diff --git a/src/char_sql/int_pet.h b/src/char_sql/int_pet.h deleted file mode 100644 index 0941dbc..0000000 --- a/src/char_sql/int_pet.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef _INT_PET_H_ -#define _INT_PET_H_ - -int inter_pet_init (); -int inter_pet_save (); -int inter_pet_delete (int pet_id); - -int inter_pet_parse_frommap (int fd); -int inter_pet_sql_init (); -//extern char pet_txt[256]; - -#endif diff --git a/src/char_sql/int_storage.c b/src/char_sql/int_storage.c deleted file mode 100644 index 63198b1..0000000 --- a/src/char_sql/int_storage.c +++ /dev/null @@ -1,441 +0,0 @@ -// -// original code from athena -// SQL conversion by Jioh L. Jung -// -#include "char.h" -#include "itemdb.h" -#include -#include - -#define STORAGE_MEMINC 16 - -// reset by inter_config_read() -struct storage *storage_pt = NULL; -struct guild_storage *guild_storage_pt = NULL; - -// storage data -> DB conversion -int storage_tosql (int account_id, struct storage *p) -{ - int i; - int eqcount = 1; - int noteqcount = 1; - struct itemtemp mapitem; - for (i = 0; i < MAX_STORAGE; i++) - { - if (p->storage[i].nameid > 0) - { - if (itemdb_isequip (p->storage[i].nameid) == 1) - { - mapitem.equip[eqcount].flag = 0; - mapitem.equip[eqcount].id = p->storage[i].id; - mapitem.equip[eqcount].nameid = p->storage[i].nameid; - mapitem.equip[eqcount].amount = p->storage[i].amount; - mapitem.equip[eqcount].equip = p->storage[i].equip; - mapitem.equip[eqcount].identify = p->storage[i].identify; - mapitem.equip[eqcount].refine = p->storage[i].refine; - mapitem.equip[eqcount].attribute = p->storage[i].attribute; - mapitem.equip[eqcount].card[0] = p->storage[i].card[0]; - mapitem.equip[eqcount].card[1] = p->storage[i].card[1]; - mapitem.equip[eqcount].card[2] = p->storage[i].card[2]; - mapitem.equip[eqcount].card[3] = p->storage[i].card[3]; - mapitem.equip[eqcount].broken = p->storage[i].broken; - eqcount++; - } - else if (itemdb_isequip (p->storage[i].nameid) == 0) - { - mapitem.notequip[noteqcount].flag = 0; - mapitem.notequip[noteqcount].id = p->storage[i].id; - mapitem.notequip[noteqcount].nameid = p->storage[i].nameid; - mapitem.notequip[noteqcount].amount = p->storage[i].amount; - mapitem.notequip[noteqcount].equip = p->storage[i].equip; - mapitem.notequip[noteqcount].identify = - p->storage[i].identify; - mapitem.notequip[noteqcount].refine = p->storage[i].refine; - mapitem.notequip[noteqcount].attribute = - p->storage[i].attribute; - mapitem.notequip[noteqcount].card[0] = p->storage[i].card[0]; - mapitem.notequip[noteqcount].card[1] = p->storage[i].card[1]; - mapitem.notequip[noteqcount].card[2] = p->storage[i].card[2]; - mapitem.notequip[noteqcount].card[3] = p->storage[i].card[3]; - mapitem.notequip[noteqcount].broken = p->storage[i].broken; - noteqcount++; - } - } - } - - memitemdata_to_sql (mapitem, eqcount, noteqcount, account_id, - TABLE_STORAGE); - - //printf ("storage dump to DB - id: %d (total: %d)\n", account_id, j); - return 0; -} - -// DB -> storage data conversion -int storage_fromsql (int account_id, struct storage *p) -{ - int i = 0; - - memset (p, 0, sizeof (struct storage)); //clean up memory - p->storage_amount = 0; - p->account_id = account_id; - - // storage {`account_id`/`id`/`nameid`/`amount`/`equip`/`identify`/`refine`/`attribute`/`card0`/`card1`/`card2`/`card3`} - sprintf (tmp_sql, - "SELECT `id`,`nameid`,`amount`,`equip`,`identify`,`refine`,`attribute`,`card0`,`card1`,`card2`,`card3`,`broken` FROM `%s` WHERE `account_id`='%d'", - storage_db, account_id); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error - %s\n", mysql_error (&mysql_handle)); - } - sql_res = mysql_store_result (&mysql_handle); - - if (sql_res) - { - while ((sql_row = mysql_fetch_row (sql_res))) - { //start to fetch - p->storage[i].id = atoi (sql_row[0]); - p->storage[i].nameid = atoi (sql_row[1]); - p->storage[i].amount = atoi (sql_row[2]); - p->storage[i].equip = atoi (sql_row[3]); - p->storage[i].identify = atoi (sql_row[4]); - p->storage[i].refine = atoi (sql_row[5]); - p->storage[i].attribute = atoi (sql_row[6]); - p->storage[i].card[0] = atoi (sql_row[7]); - p->storage[i].card[1] = atoi (sql_row[8]); - p->storage[i].card[2] = atoi (sql_row[9]); - p->storage[i].card[3] = atoi (sql_row[10]); - p->storage[i].broken = atoi (sql_row[11]); - p->storage_amount = ++i; - } - mysql_free_result (sql_res); - } - - printf ("storage load complete from DB - id: %d (total: %d)\n", - account_id, p->storage_amount); - return 1; -} - -// Save guild_storage data to sql -int guild_storage_tosql (int guild_id, struct guild_storage *p) -{ - int i; - int eqcount = 1; - int noteqcount = 1; - struct itemtemp mapitem; - for (i = 0; i < MAX_GUILD_STORAGE; i++) - { - if (p->storage[i].nameid > 0) - { - if (itemdb_isequip (p->storage[i].nameid) == 1) - { - mapitem.equip[eqcount].flag = 0; - mapitem.equip[eqcount].id = p->storage[i].id; - mapitem.equip[eqcount].nameid = p->storage[i].nameid; - mapitem.equip[eqcount].amount = p->storage[i].amount; - mapitem.equip[eqcount].equip = p->storage[i].equip; - mapitem.equip[eqcount].identify = p->storage[i].identify; - mapitem.equip[eqcount].refine = p->storage[i].refine; - mapitem.equip[eqcount].attribute = p->storage[i].attribute; - mapitem.equip[eqcount].card[0] = p->storage[i].card[0]; - mapitem.equip[eqcount].card[1] = p->storage[i].card[1]; - mapitem.equip[eqcount].card[2] = p->storage[i].card[2]; - mapitem.equip[eqcount].card[3] = p->storage[i].card[3]; - mapitem.equip[eqcount].broken = p->storage[i].broken; - eqcount++; - } - else if (itemdb_isequip (p->storage[i].nameid) == 0) - { - mapitem.notequip[noteqcount].flag = 0; - mapitem.notequip[noteqcount].id = p->storage[i].id; - mapitem.notequip[noteqcount].nameid = p->storage[i].nameid; - mapitem.notequip[noteqcount].amount = p->storage[i].amount; - mapitem.notequip[noteqcount].equip = p->storage[i].equip; - mapitem.notequip[noteqcount].identify = - p->storage[i].identify; - mapitem.notequip[noteqcount].refine = p->storage[i].refine; - mapitem.notequip[noteqcount].attribute = - p->storage[i].attribute; - mapitem.notequip[noteqcount].card[0] = p->storage[i].card[0]; - mapitem.notequip[noteqcount].card[1] = p->storage[i].card[1]; - mapitem.notequip[noteqcount].card[2] = p->storage[i].card[2]; - mapitem.notequip[noteqcount].card[3] = p->storage[i].card[3]; - mapitem.notequip[noteqcount].broken = p->storage[i].broken; - noteqcount++; - } - } - } - - memitemdata_to_sql (mapitem, eqcount, noteqcount, guild_id, - TABLE_GUILD_STORAGE); - - printf ("guild storage save to DB - id: %d (total: %d)\n", guild_id, i); - return 0; -} - -// Load guild_storage data to mem -int guild_storage_fromsql (int guild_id, struct guild_storage *p) -{ - int i = 0; - struct guild_storage *gs = guild_storage_pt; - p = gs; - - memset (p, 0, sizeof (struct guild_storage)); //clean up memory - p->storage_amount = 0; - p->guild_id = guild_id; - - // storage {`guild_id`/`id`/`nameid`/`amount`/`equip`/`identify`/`refine`/`attribute`/`card0`/`card1`/`card2`/`card3`} - sprintf (tmp_sql, - "SELECT `id`,`nameid`,`amount`,`equip`,`identify`,`refine`,`attribute`,`card0`,`card1`,`card2`,`card3`,`broken` FROM `%s` WHERE `guild_id`='%d'", - guild_storage_db, guild_id); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error - %s\n", mysql_error (&mysql_handle)); - } - sql_res = mysql_store_result (&mysql_handle); - - if (sql_res) - { - while ((sql_row = mysql_fetch_row (sql_res))) - { //start to fetch - p->storage[i].id = atoi (sql_row[0]); - p->storage[i].nameid = atoi (sql_row[1]); - p->storage[i].amount = atoi (sql_row[2]); - p->storage[i].equip = atoi (sql_row[3]); - p->storage[i].identify = atoi (sql_row[4]); - p->storage[i].refine = atoi (sql_row[5]); - p->storage[i].attribute = atoi (sql_row[6]); - p->storage[i].card[0] = atoi (sql_row[7]); - p->storage[i].card[1] = atoi (sql_row[8]); - p->storage[i].card[2] = atoi (sql_row[9]); - p->storage[i].card[3] = atoi (sql_row[10]); - p->storage[i].broken = atoi (sql_row[11]); - p->storage_amount = ++i; - } - mysql_free_result (sql_res); - } - printf ("guild storage load complete from DB - id: %d (total: %d)\n", - guild_id, p->storage_amount); - return 0; -} - -//--------------------------------------------------------- -// storage data initialize -int inter_storage_sql_init () -{ - - //memory alloc - printf ("interserver storage memory initialize....(%d byte)\n", - sizeof (struct storage)); - storage_pt = calloc (sizeof (struct storage), 1); - guild_storage_pt = calloc (sizeof (struct guild_storage), 1); - memset (storage_pt, 0, sizeof (struct storage)); - memset (guild_storage_pt, 0, sizeof (struct guild_storage)); - - return 1; -} - -// 倉庫データ削除 -int inter_storage_delete (int account_id) -{ - sprintf (tmp_sql, "DELETE FROM `%s` WHERE `account_id`='%d'", storage_db, - account_id); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (delete `storage`)- %s\n", - mysql_error (&mysql_handle)); - } - return 0; -} - -int inter_guild_storage_delete (int guild_id) -{ - sprintf (tmp_sql, "DELETE FROM `%s` WHERE `guild_id`='%d'", - guild_storage_db, guild_id); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (delete `guild_storage`)- %s\n", - mysql_error (&mysql_handle)); - } - return 0; -} - -//--------------------------------------------------------- -// packet from map server - -// recive packet about storage data -int mapif_load_storage (int fd, int account_id) -{ - //load from DB - storage_fromsql (account_id, storage_pt); - WFIFOW (fd, 0) = 0x3810; - WFIFOW (fd, 2) = sizeof (struct storage) + 8; - WFIFOL (fd, 4) = account_id; - memcpy (WFIFOP (fd, 8), storage_pt, sizeof (struct storage)); - WFIFOSET (fd, WFIFOW (fd, 2)); - return 0; -} - -// send ack to map server which is "storage data save ok." -int mapif_save_storage_ack (int fd, int account_id) -{ - WFIFOW (fd, 0) = 0x3811; - WFIFOL (fd, 2) = account_id; - WFIFOB (fd, 6) = 0; - WFIFOSET (fd, 7); - return 0; -} - -int mapif_load_guild_storage (int fd, int account_id, int guild_id) -{ - int guild_exist = 0; - WFIFOW (fd, 0) = 0x3818; - - // Check if guild exists, I may write a function for this later, coz I use it several times. - //printf("- Check if guild %d exists\n",g->guild_id); - sprintf (tmp_sql, "SELECT count(*) FROM `%s` WHERE `guild_id`='%d'", - guild_db, guild_id); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (delete `guild`)- %s\n", - mysql_error (&mysql_handle)); - } - sql_res = mysql_store_result (&mysql_handle); - if (sql_res != NULL && mysql_num_rows (sql_res) > 0) - { - sql_row = mysql_fetch_row (sql_res); - guild_exist = atoi (sql_row[0]); - //printf("- Check if guild %d exists : %s\n",g->guild_id,((guild_exist==0)?"No":"Yes")); - } - mysql_free_result (sql_res); //resource free - - if (guild_exist == 1) - { - guild_storage_fromsql (guild_id, guild_storage_pt); - WFIFOW (fd, 2) = sizeof (struct guild_storage) + 12; - WFIFOL (fd, 4) = account_id; - WFIFOL (fd, 8) = guild_id; - memcpy (WFIFOP (fd, 12), guild_storage_pt, - sizeof (struct guild_storage)); - } - else - { - WFIFOW (fd, 2) = 12; - WFIFOL (fd, 4) = account_id; - WFIFOL (fd, 8) = 0; - } - WFIFOSET (fd, WFIFOW (fd, 2)); - - return 0; -} - -int mapif_save_guild_storage_ack (int fd, int account_id, int guild_id, - int fail) -{ - WFIFOW (fd, 0) = 0x3819; - WFIFOL (fd, 2) = account_id; - WFIFOL (fd, 6) = guild_id; - WFIFOB (fd, 10) = fail; - WFIFOSET (fd, 11); - return 0; -} - -//--------------------------------------------------------- -// packet from map server - -// recive request about storage data -int mapif_parse_LoadStorage (int fd) -{ - mapif_load_storage (fd, RFIFOL (fd, 2)); - return 0; -} - -// storage data recive and save -int mapif_parse_SaveStorage (int fd) -{ - int account_id = RFIFOL (fd, 4); - int len = RFIFOW (fd, 2); - - if (sizeof (struct storage) != len - 8) - { - printf ("inter storage: data size error %d %d\n", - sizeof (struct storage), len - 8); - } - else - { - memcpy (&storage_pt[0], RFIFOP (fd, 8), sizeof (struct storage)); - storage_tosql (account_id, storage_pt); - mapif_save_storage_ack (fd, account_id); - } - return 0; -} - -int mapif_parse_LoadGuildStorage (int fd) -{ - mapif_load_guild_storage (fd, RFIFOL (fd, 2), RFIFOL (fd, 6)); - return 0; -} - -int mapif_parse_SaveGuildStorage (int fd) -{ - int guild_exist = 0; - int guild_id = RFIFOL (fd, 8); - int len = RFIFOW (fd, 2); - if (sizeof (struct guild_storage) != len - 12) - { - printf ("inter storage: data size error %d %d\n", - sizeof (struct guild_storage), len - 12); - } - else - { - // Check if guild exists, I may write a function for this later, coz I use it several times. - //printf("- Check if guild %d exists\n",g->guild_id); - sprintf (tmp_sql, "SELECT count(*) FROM `%s` WHERE `guild_id`='%d'", - guild_db, guild_id); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (delete `guild`)- %s\n", - mysql_error (&mysql_handle)); - } - sql_res = mysql_store_result (&mysql_handle); - if (sql_res != NULL && mysql_num_rows (sql_res) > 0) - { - sql_row = mysql_fetch_row (sql_res); - guild_exist = atoi (sql_row[0]); - //printf("- Check if guild %d exists : %s\n",g->guild_id,((guild_exist==0)?"No":"Yes")); - } - mysql_free_result (sql_res); //resource free - - if (guild_exist == 1) - { - memcpy (guild_storage_pt, RFIFOP (fd, 12), - sizeof (struct guild_storage)); - guild_storage_tosql (guild_id, guild_storage_pt); - mapif_save_guild_storage_ack (fd, RFIFOL (fd, 4), guild_id, 0); - } - else - mapif_save_guild_storage_ack (fd, RFIFOL (fd, 4), guild_id, 1); - } - return 0; -} - -int inter_storage_parse_frommap (int fd) -{ - switch (RFIFOW (fd, 0)) - { - case 0x3010: - mapif_parse_LoadStorage (fd); - break; - case 0x3011: - mapif_parse_SaveStorage (fd); - break; - case 0x3018: - mapif_parse_LoadGuildStorage (fd); - break; - case 0x3019: - mapif_parse_SaveGuildStorage (fd); - break; - default: - return 0; - } - return 1; -} diff --git a/src/char_sql/int_storage.h b/src/char_sql/int_storage.h deleted file mode 100644 index 2a7efee..0000000 --- a/src/char_sql/int_storage.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef _INT_STORAGE_H_ -#define _INT_STORAGE_H_ - -int inter_storage_sql_init (); -int inter_storage_delete (int account_id); -int inter_guild_storage_delete (int guild_id); - -int inter_storage_parse_frommap (int fd); - -//extern char storage_txt[256]; - -#endif diff --git a/src/char_sql/inter.c b/src/char_sql/inter.c deleted file mode 100644 index 800beaf..0000000 --- a/src/char_sql/inter.c +++ /dev/null @@ -1,662 +0,0 @@ -// -// original code from athena -// SQL conversion by Jioh L. Jung -// - -#include -#include - -#include "char.h" -#include "strlib.h" -#include "inter.h" -#include "int_party.h" -#include "int_guild.h" -#include "int_storage.h" -#include "int_pet.h" -#include "lock.h" - -#define WISDATA_TTL (60*1000) // Wisデータの生存時間(60秒) -#define WISDELLIST_MAX 256 // Wisデータ削除リストの要素数 - -struct accreg -{ - int account_id, reg_num; - struct global_reg reg[ACCOUNT_REG_NUM]; -}; - -static struct accreg *accreg_pt; - -int party_share_level = 10; -MYSQL mysql_handle; -MYSQL_RES *sql_res; -MYSQL_ROW sql_row; -int sql_fields, sql_cnt; -char tmp_sql[65535]; - -MYSQL lmysql_handle; -char tmp_lsql[65535]; -MYSQL_RES *lsql_res; -MYSQL_ROW lsql_row; - -int char_server_port = 3306; -char char_server_ip[32] = "127.0.0.1"; -char char_server_id[32] = "ragnarok"; -char char_server_pw[32] = "ragnarok"; -char char_server_db[32] = "ragnarok"; - -int login_server_port = 3306; -char login_server_ip[32] = "127.0.0.1"; -char login_server_id[32] = "ragnarok"; -char login_server_pw[32] = "ragnarok"; -char login_server_db[32] = "ragnarok"; - -// sending packet list -int inter_send_packet_length[] = { - -1, -1, 27, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - -1, 7, 0, 0, 0, 0, 0, 0, -1, 11, 0, 0, 0, 0, 0, 0, - 35, -1, 11, 15, 34, 29, 7, -1, 0, 0, 0, 0, 0, 0, 0, 0, - 10, -1, 15, 0, 79, 19, 7, -1, 0, -1, -1, -1, 14, 67, 186, -1, - 9, 9, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 11, -1, 7, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -}; - -// recv. packet list -int inter_recv_packet_length[] = { - -1, -1, 7, 0, -1, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 6, -1, 0, 0, 0, 0, 0, 0, 10, -1, 0, 0, 0, 0, 0, 0, - 72, 6, 52, 14, 10, 29, 6, -1, 34, 0, 0, 0, 0, 0, 0, 0, - -1, 6, -1, 0, 55, 19, 6, -1, 14, -1, -1, -1, 14, 19, 186, -1, - 5, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 48, 14, -1, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -}; - -struct WisData -{ - int id, fd, count, len; - unsigned long tick; - unsigned char src[24], dst[24], msg[512]; -}; -static struct dbt *wis_db = NULL; -static int wis_dellist[WISDELLIST_MAX], wis_delnum; - -//-------------------------------------------------------- -// Save account_reg to sql (type=2) -int inter_accreg_tosql (int account_id, struct accreg *reg) -{ - - int j; - char temp_str[32]; - if (account_id <= 0) - return 0; - reg->account_id = account_id; - - //`global_reg_value` (`type`, `account_id`, `char_id`, `str`, `value`) - sprintf (tmp_sql, "DELETE FROM `%s` WHERE `type`=2 AND `account_id`='%d'", - reg_db, account_id); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (delete `global_reg_value`)- %s\n", - mysql_error (&mysql_handle)); - } - - if (reg->reg_num <= 0) - return 0; - - for (j = 0; j < reg->reg_num; j++) - { - if (reg->reg[j].str != NULL) - { - sprintf (tmp_sql, - "INSERT INTO `%s` (`type`, `account_id`, `str`, `value`) VALUES (2,'%d', '%s','%d')", - reg_db, reg->account_id, jstrescapecpy (temp_str, - reg->reg[j].str), - reg->reg[j].value); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (insert `global_reg_value`)- %s\n", - mysql_error (&mysql_handle)); - } - } - } - return 0; -} - -// Load account_reg from sql (type=2) -int inter_accreg_fromsql (int account_id, struct accreg *reg) -{ - int j = 0; - if (reg == NULL) - return 0; - memset (reg, 0, sizeof (struct accreg)); - reg->account_id = account_id; - - //`global_reg_value` (`type`, `account_id`, `char_id`, `str`, `value`) - sprintf (tmp_sql, - "SELECT `str`, `value` FROM `%s` WHERE `type`=2 AND `account_id`='%d'", - reg_db, reg->account_id); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (select `global_reg_value`)- %s\n", - mysql_error (&mysql_handle)); - } - sql_res = mysql_store_result (&mysql_handle); - - if (sql_res) - { - for (j = 0; (sql_row = mysql_fetch_row (sql_res)); j++) - { - memcpy (reg->reg[j].str, sql_row[0], 32); - reg->reg[j].value = atoi (sql_row[1]); - } - mysql_free_result (sql_res); - } - reg->reg_num = j; - return 0; -} - -// Initialize -int inter_accreg_sql_init () -{ - CREATE (accreg_pt, struct accreg, 1); - return 0; - -} - -/*========================================== - * read config file - *------------------------------------------ - */ -int inter_config_read (const char *cfgName) -{ - printf ("start reading interserver configuration: %s\n", cfgName); - int i; - char line[1024], w1[1024], w2[1024]; - FILE *fp; - - fp = fopen_ (cfgName, "r"); - if (fp == NULL) - { - printf ("file not found: %s\n", cfgName); - return 1; - } - while (fgets (line, 1020, fp)) - { - i = sscanf (line, "%[^:]: %[^\r\n]", w1, w2); - if (i != 2) - continue; - - if (strcmpi (w1, "char_server_ip") == 0) - { - strcpy (char_server_ip, w2); - printf ("set char_server_ip : %s\n", w2); - } - else if (strcmpi (w1, "char_server_port") == 0) - { - char_server_port = atoi (w2); - printf ("set char_server_port : %s\n", w2); - } - else if (strcmpi (w1, "char_server_id") == 0) - { - strcpy (char_server_id, w2); - printf ("set char_server_id : %s\n", w2); - } - else if (strcmpi (w1, "char_server_pw") == 0) - { - strcpy (char_server_pw, w2); - printf ("set char_server_pw : %s\n", w2); - } - else if (strcmpi (w1, "char_server_db") == 0) - { - strcpy (char_server_db, w2); - printf ("set char_server_db : %s\n", w2); - } - //Logins information to be read from the inter_athena.conf - //for character deletion (checks email in the loginDB) - - else if (strcmpi (w1, "login_server_ip") == 0) - { - strcpy (login_server_ip, w2); - printf ("set login_server_ip : %s\n", w2); - } - else if (strcmpi (w1, "login_server_port") == 0) - { - login_server_port = atoi (w2); - printf ("set login_server_port : %s\n", w2); - } - else if (strcmpi (w1, "login_server_id") == 0) - { - strcpy (login_server_id, w2); - printf ("set login_server_id : %s\n", w2); - } - else if (strcmpi (w1, "login_server_pw") == 0) - { - strcpy (login_server_pw, w2); - printf ("set login_server_pw : %s\n", w2); - } - else if (strcmpi (w1, "login_server_db") == 0) - { - strcpy (login_server_db, w2); - printf ("set login_server_db : %s\n", w2); - } - else if (strcmpi (w1, "party_share_level") == 0) - { - party_share_level = atoi (w2); - if (party_share_level < 0) - party_share_level = 0; - } - else if (strcmpi (w1, "import") == 0) - { - inter_config_read (w2); - } - else if (strcmpi (w1, "login_server_db") == 0) - { - strcpy (login_server_db, w2); - printf ("set login_server_db : %s\n", w2); - } - } - fclose_ (fp); - - printf ("success reading interserver configuration\n"); - - return 0; -} - -// Save interlog into sql -int inter_log (char *fmt, ...) -{ - char str[255]; - char temp_str[255]; - va_list ap; - va_start (ap, fmt); - - vsprintf (str, fmt, ap); - sprintf (tmp_sql, - "INSERT INTO `%s` (`time`, `log`) VALUES (NOW(), '%s')", - interlog_db, jstrescapecpy (temp_str, str)); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (insert `interlog`)- %s\n", - mysql_error (&mysql_handle)); - } - - va_end (ap); - return 0; -} - -// initialize -int inter_init (const char *file) -{ - //int i; - - printf ("interserver initialize...\n"); - inter_config_read (file); - - //DB connection initialized - mysql_init (&mysql_handle); - printf ("Connect Character DB server.... (Character Server)\n"); - if (!mysql_real_connect - (&mysql_handle, char_server_ip, char_server_id, char_server_pw, - char_server_db, char_server_port, (char *) NULL, 0)) - { - //pointer check - printf ("%s\n", mysql_error (&mysql_handle)); - exit (1); - } - else - { - printf ("Connect Success! (Character Server)\n"); - } - - mysql_init (&lmysql_handle); - printf ("Connect Character DB server.... (login server)\n"); - if (!mysql_real_connect - (&lmysql_handle, login_server_ip, login_server_id, login_server_pw, - login_server_db, login_server_port, (char *) NULL, 0)) - { - //pointer check - printf ("%s\n", mysql_error (&lmysql_handle)); - exit (1); - } - else - { - printf ("Connect Success! (Login Server)"); - } - wis_db = numdb_init (); - inter_guild_sql_init (); - inter_storage_sql_init (); - inter_party_sql_init (); - - inter_pet_sql_init (); - inter_accreg_sql_init (); - - //printf ("interserver timer initializing : %d sec...\n",autosave_interval); - //i=add_timer_interval(gettick()+autosave_interval,inter_save_timer,0,0,autosave_interval); - - return 0; -} - -int inter_mapif_init (int fd) -{ - inter_guild_mapif_init (fd); - - return 0; -} - -//-------------------------------------------------------- - -// GM message sending -int mapif_GMmessage (unsigned char *mes, int len) -{ - unsigned char buf[len]; - - WBUFW (buf, 0) = 0x3800; - WBUFW (buf, 2) = len; - memcpy (WBUFP (buf, 4), mes, len - 4); - mapif_sendall (buf, len); - printf ("\033[1;34m inter server: GM[len:%d] - '%s' \033[0m\n", len, mes); - return 0; -} - -// Wis sending -int mapif_wis_message (struct WisData *wd) -{ - unsigned char buf[56 + wd->len]; - - WBUFW (buf, 0) = 0x3801; - WBUFW (buf, 2) = 56 + wd->len; - WBUFL (buf, 4) = wd->id; - memcpy (WBUFP (buf, 8), wd->src, 24); - memcpy (WBUFP (buf, 32), wd->dst, 24); - memcpy (WBUFP (buf, 56), wd->msg, wd->len); - wd->count = mapif_sendall (buf, WBUFW (buf, 2)); - - return 0; -} - -// Wis sending result -int mapif_wis_end (struct WisData *wd, int flag) -{ - unsigned char buf[27]; - - WBUFW (buf, 0) = 0x3802; - memcpy (WBUFP (buf, 2), wd->src, 24); - WBUFB (buf, 26) = flag; - mapif_send (wd->fd, buf, 27); -// printf("inter server wis_end %d\n",flag); - return 0; -} - -int mapif_account_reg (int fd, unsigned char *src) -{ - unsigned char buf[WBUFW (src, 2)]; - memcpy (WBUFP (buf, 0), src, WBUFW (src, 2)); - WBUFW (buf, 0) = 0x3804; - mapif_sendallwos (fd, buf, WBUFW (buf, 2)); - return 0; -} - -// Send the requested account_reg -int mapif_account_reg_reply (int fd, int account_id) -{ - struct accreg *reg = accreg_pt; - inter_accreg_fromsql (account_id, reg); - - WFIFOW (fd, 0) = 0x3804; - WFIFOL (fd, 4) = account_id; - if (reg->reg_num == 0) - { - WFIFOW (fd, 2) = 8; - } - else - { - int j, p; - for (j = 0, p = 8; j < reg->reg_num; j++, p += 36) - { - memcpy (WFIFOP (fd, p), reg->reg[j].str, 32); - WFIFOL (fd, p + 32) = reg->reg[j].value; - } - WFIFOW (fd, 2) = p; - } - WFIFOSET (fd, WFIFOW (fd, 2)); - return 0; -} - -//-------------------------------------------------------- - -// Existence check of WISP data -int check_ttl_wisdata_sub (void *key, void *data, va_list ap) -{ - unsigned long tick; - struct WisData *wd = (struct WisData *) data; - tick = va_arg (ap, unsigned long); - - if (DIFF_TICK (tick, wd->tick) > WISDATA_TTL - && wis_delnum < WISDELLIST_MAX) - wis_dellist[wis_delnum++] = wd->id; - - return 0; -} - -int check_ttl_wisdata () -{ - unsigned long tick = gettick (); - int i; - - do - { - wis_delnum = 0; - numdb_foreach (wis_db, check_ttl_wisdata_sub, tick); - for (i = 0; i < wis_delnum; i++) - { - struct WisData *wd = numdb_search (wis_db, wis_dellist[i]); - printf ("inter: wis data id=%d time out : from %s to %s\n", - wd->id, wd->src, wd->dst); - // removed. not send information after a timeout. Just no answer for the player - //mapif_wis_end(wd, 1); // flag: 0: success to send wisper, 1: target character is not loged in?, 2: ignored by target - numdb_erase (wis_db, wd->id); - free (wd); - } - } - while (wis_delnum >= WISDELLIST_MAX); - - return 0; -} - -//-------------------------------------------------------- - -// GM message sending -int mapif_parse_GMmessage (int fd) -{ - mapif_GMmessage (RFIFOP (fd, 4), RFIFOW (fd, 2)); - return 0; -} - -// Wisp/page request to send -int mapif_parse_WisRequest (int fd) -{ - struct WisData *wd; - static int wisid = 0; - - if (RFIFOW (fd, 2) - 52 >= sizeof (wd->msg)) - { - printf ("inter: Wis message size too long.\n"); - return 0; - } - else if (RFIFOW (fd, 2) - 52 <= 0) - { // normaly, impossible, but who knows... - printf ("inter: Wis message doesn't exist.\n"); - return 0; - } - sprintf (tmp_sql, "SELECT `name` FROM `%s` WHERE `char_id`='%d'", char_db, - (int) RFIFOP (fd, 28)); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error - %s\n", mysql_error (&mysql_handle)); - } - sql_res = mysql_store_result (&mysql_handle); - - // search if character exists before to ask all map-servers - if (!(sql_row = mysql_fetch_row (sql_res))) - { - unsigned char buf[27]; - WBUFW (buf, 0) = 0x3802; - memcpy (WBUFP (buf, 2), RFIFOP (fd, 4), 24); - WBUFB (buf, 26) = 1; // flag: 0: success to send wisper, 1: target character is not loged in?, 2: ignored by target - mapif_send (fd, buf, 27); - // Character exists. So, ask all map-servers - } - else - { - // to be sure of the correct name, rewrite it - memset (RFIFOP (fd, 28), 0, 24); - strncpy (RFIFOP (fd, 28), sql_row[0], 24); - // if source is destination, don't ask other servers. - if (strcmp (RFIFOP (fd, 4), RFIFOP (fd, 28)) == 0) - { - unsigned char buf[27]; - WBUFW (buf, 0) = 0x3802; - memcpy (WBUFP (buf, 2), RFIFOP (fd, 4), 24); - WBUFB (buf, 26) = 1; // flag: 0: success to send wisper, 1: target character is not loged in?, 2: ignored by target - mapif_send (fd, buf, 27); - } - else - { - - CREATE (wd, struct WisData, 1); - - // Whether the failure of previous wisp/page transmission (timeout) - check_ttl_wisdata (); - - wd->id = ++wisid; - wd->fd = fd; - wd->len = RFIFOW (fd, 2) - 52; - memcpy (wd->src, RFIFOP (fd, 4), 24); - memcpy (wd->dst, RFIFOP (fd, 28), 24); - memcpy (wd->msg, RFIFOP (fd, 52), wd->len); - wd->tick = gettick (); - numdb_insert (wis_db, wd->id, wd); - mapif_wis_message (wd); - } - } - - return 0; -} - -// Wisp/page transmission result -int mapif_parse_WisReply (int fd) -{ - int id = RFIFOL (fd, 2), flag = RFIFOB (fd, 6); - struct WisData *wd = numdb_search (wis_db, id); - - if (wd == NULL) - return 0; // This wisp was probably suppress before, because it was timeout of because of target was found on another map-server - - if ((--wd->count) <= 0 || flag != 1) - { - mapif_wis_end (wd, flag); // flag: 0: success to send wisper, 1: target character is not loged in?, 2: ignored by target - numdb_erase (wis_db, id); - free (wd); - } - - return 0; -} - -// Save account_reg into sql (type=2) -int mapif_parse_AccReg (int fd) -{ - int j, p; - struct accreg *reg = accreg_pt; - int account_id = RFIFOL (fd, 4); - memset (accreg_pt, 0, sizeof (struct accreg)); - - for (j = 0, p = 8; j < ACCOUNT_REG_NUM && p < RFIFOW (fd, 2); - j++, p += 36) - { - memcpy (reg->reg[j].str, RFIFOP (fd, p), 32); - reg->reg[j].value = RFIFOL (fd, p + 32); - } - reg->reg_num = j; - - inter_accreg_tosql (account_id, reg); - mapif_account_reg (fd, RFIFOP (fd, 0)); // Send confirm message to map - return 0; -} - -// Request the value of account_reg -int mapif_parse_AccRegRequest (int fd) -{ -// printf("mapif: accreg request\n"); - return mapif_account_reg_reply (fd, RFIFOL (fd, 2)); -} - -//-------------------------------------------------------- -int inter_parse_frommap (int fd) -{ - int cmd = RFIFOW (fd, 0); - int len = 0; - - // inter鯖管轄かを調べる - if (cmd < 0x3000 || cmd >= 0x3000 + (sizeof (inter_recv_packet_length) / - sizeof (inter_recv_packet_length - [0]))) - return 0; - - // パケット長を調べる - if ((len = - inter_check_length (fd, - inter_recv_packet_length[cmd - 0x3000])) == 0) - return 2; - - switch (cmd) - { - case 0x3000: - mapif_parse_GMmessage (fd); - break; - case 0x3001: - mapif_parse_WisRequest (fd); - break; - case 0x3002: - mapif_parse_WisReply (fd); - break; - case 0x3004: - mapif_parse_AccReg (fd); - break; - case 0x3005: - mapif_parse_AccRegRequest (fd); - break; - default: - if (inter_party_parse_frommap (fd)) - break; - if (inter_guild_parse_frommap (fd)) - break; - if (inter_storage_parse_frommap (fd)) - break; - if (inter_pet_parse_frommap (fd)) - break; - return 0; - } - RFIFOSKIP (fd, len); - return 1; -} - -// RFIFO check -int inter_check_length (int fd, int length) -{ - if (length == -1) - { // v-len packet - if (RFIFOREST (fd) < 4) // packet not yet - return 0; - length = RFIFOW (fd, 2); - } - - if (RFIFOREST (fd) < length) // packet not yet - return 0; - - return length; -} diff --git a/src/char_sql/inter.h b/src/char_sql/inter.h deleted file mode 100644 index 3a31f4b..0000000 --- a/src/char_sql/inter.h +++ /dev/null @@ -1,43 +0,0 @@ -#ifndef _INTER_H_ -#define _INTER_H_ - -int inter_init (const char *file); -int inter_parse_frommap (int fd); -int inter_mapif_init (int fd); - -int inter_check_length (int fd, int length); - -int inter_log (char *fmt, ...); - -#define inter_cfgName "conf/inter_athena.conf" - -extern int party_share_level; -extern char inter_log_filename[1024]; - -//add include for DBMS(mysql) -#include - -extern MYSQL mysql_handle; -extern char tmp_sql[65535]; -extern MYSQL_RES *sql_res; -extern MYSQL_ROW sql_row; -extern int sql_cnt; - -extern MYSQL lmysql_handle; -extern char tmp_lsql[65535]; -extern MYSQL_RES *lsql_res; -extern MYSQL_ROW lsql_row; - -extern int char_server_port; -extern char char_server_ip[32]; -extern char char_server_id[32]; -extern char char_server_pw[32]; -extern char char_server_db[32]; - -extern int login_db_server_port; -extern char login_db_server_ip[32]; -extern char login_db_server_id[32]; -extern char login_db_server_pw[32]; -extern char login_db_server_db[32]; - -#endif diff --git a/src/char_sql/itemdb.c b/src/char_sql/itemdb.c deleted file mode 100644 index ee0801f..0000000 --- a/src/char_sql/itemdb.c +++ /dev/null @@ -1,265 +0,0 @@ -// $Id: itemdb.c,v 1.1.1.1 2004/09/10 17:44:48 MagicalTux Exp $ -#include -#include -#include - -#include "itemdb.h" -#include "db.h" -#include "inter.h" -#include "char.h" -#include "utils.h" - -#ifdef MEMWATCH -#include "memwatch.h" -#endif - -#define MAX_RANDITEM 2000 - -// ** ITEMDB_OVERRIDE_NAME_VERBOSE ** -// 定義すると、itemdb.txtとgrfで名前が異なる場合、表示します. -//#define ITEMDB_OVERRIDE_NAME_VERBOSE 1 - -char item_db_db[256] = "item_db"; // added to specify item_db sql table [Valaris] - -static struct dbt *item_db; - -/*========================================== - * DBの検索 - *------------------------------------------ - */ -struct item_data *itemdb_search (int nameid) -{ - struct item_data *id; - - id = numdb_search (item_db, nameid); - if (id) - return id; - - CREATE (id, struct item_data, 1); - - numdb_insert (item_db, nameid, id); - - if (nameid > 500 && nameid < 600) - id->type = 0; //heal item - else if (nameid > 600 && nameid < 700) - id->type = 2; //use item - else if ((nameid > 700 && nameid < 1100) || - (nameid > 7000 && nameid < 8000)) - id->type = 3; //correction - else if (nameid >= 1750 && nameid < 1771) - id->type = 10; //arrow - else if (nameid > 1100 && nameid < 2000) - id->type = 4; //weapon - else if ((nameid > 2100 && nameid < 3000) || - (nameid > 5000 && nameid < 6000)) - id->type = 5; //armor - else if (nameid > 4000 && nameid < 5000) - id->type = 6; //card - else if (nameid > 9000 && nameid < 10000) - id->type = 7; //egg - else if (nameid > 10000) - id->type = 8; //petequip - - return id; -} - -/*========================================== - * - *------------------------------------------ - */ -int itemdb_isequip (int nameid) -{ - int type = itemdb_type (nameid); - if (type == 0 || type == 2 || type == 3 || type == 6 || type == 10) - return 0; - return 1; -} - -/*========================================== - * - *------------------------------------------ - */ -int itemdb_isequip2 (struct item_data *data) -{ - if (data) - { - int type = data->type; - if (type == 0 || type == 2 || type == 3 || type == 6 || type == 10) - return 0; - else - return 1; - } - return 0; -} - -/*========================================== - * アイテムデータベースの読み込み - *------------------------------------------ - */ -static int itemdb_readdb (void) -{ - FILE *fp; - char line[1024]; - int ln = 0; - int nameid, j; - char *str[32], *p, *np; - struct item_data *id; - - fp = fopen_ ("db/item_db.txt", "r"); - if (fp == NULL) - { - printf ("can't read db/item_db.txt\n"); - exit (1); - } - while (fgets (line, 1020, fp)) - { - if (line[0] == '/' && line[1] == '/') - continue; - memset (str, 0, sizeof (str)); - for (j = 0, np = p = line; j < 17 && p; j++) - { - str[j] = p; - p = strchr (p, ','); - if (p) - { - *p++ = 0; - np = p; - } - } - if (str[0] == NULL) - continue; - - nameid = atoi (str[0]); - if (nameid <= 0 || nameid >= 20000) - continue; - ln++; - - //ID,Name,Jname,Type,Price,Sell,Weight,ATK,DEF,Range,Slot,Job,Gender,Loc,wLV,eLV,View - id = itemdb_search (nameid); - memcpy (id->name, str[1], 24); - memcpy (id->jname, str[2], 24); - id->type = atoi (str[3]); - - } - fclose_ (fp); - printf ("read db/item_db.txt done (count=%d)\n", ln); - return 0; -} - -static int itemdb_read_sqldb (void) // sql item_db read, shortened version of map-server item_db read [Valaris] -{ - unsigned int nameid; // Type should be "unsigned short int", but currently isn't for compatibility with numdb_insert() - struct item_data *id; - - // ---------- - - // Output query to retrieve all rows from the item database table - sprintf (tmp_sql, "SELECT * FROM `%s`", item_db_db); - - // Execute the query; if the query execution fails, output an error - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("Database server error (executing query for %s): %s\n", - item_db_db, mysql_error (&mysql_handle)); - } - - // Store the query result - sql_res = mysql_store_result (&mysql_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))) - { - nameid = atoi (sql_row[0]); - - // If the identifier is not within the valid range, process the next row - if (nameid == 0 || nameid >= 20000) - { // Should ">= 20000" be "> 20000"? - continue; - } - - // ---------- - - // Insert a new row into the item database -/* - id = calloc(sizeof(struct item_data), 1); - - if (id == NULL) { - printf("out of memory : itemdb_read_sqldb\n"); - exit(1); - } - - memset(id, 0, sizeof(struct item_data)); - numdb_insert(item_db, nameid, id); - - // ---------- -*/ - id = itemdb_search (nameid); - - memcpy (id->name, sql_row[1], 24); - memcpy (id->jname, sql_row[2], 24); - - id->type = atoi (sql_row[3]); - } - - // If the retrieval failed, output an error - if (mysql_errno (&mysql_handle)) - { - printf ("Database server error (retrieving rows from %s): %s\n", - item_db_db, mysql_error (&mysql_handle)); - } - - printf ("read %s done (count = %lu)\n", item_db_db, - (unsigned long) mysql_num_rows (sql_res)); - - // Free the query result - mysql_free_result (sql_res); - } - else - { - printf ("MySQL error (storing query result for %s): %s\n", item_db_db, - mysql_error (&mysql_handle)); - } - - return 0; -} - -static int itemdb_final (void *key, void *data, va_list ap) -{ - struct item_data *id; - - id = data; - if (id->use_script) - free (id->use_script); - if (id->equip_script) - free (id->equip_script); - free (id); - - return 0; -} - -/*========================================== - * - *------------------------------------------ - */ -void do_final_itemdb (void) -{ - if (item_db) - { - numdb_final (item_db, itemdb_final); - item_db = NULL; - } -} - -int do_init_itemdb (void) -{ - item_db = numdb_init (); - - if (db_use_sqldbs) // it db_use_sqldbs in inter config are yes, will read from item_db for char server display [Valaris] - itemdb_read_sqldb (); - else - itemdb_readdb (); - return 0; -} diff --git a/src/char_sql/itemdb.h b/src/char_sql/itemdb.h deleted file mode 100644 index 5d55c1b..0000000 --- a/src/char_sql/itemdb.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef _ITEMDB_H_ -#define _ITEMDB_H_ - -struct item_data -{ - int nameid; - char name[24], jname[24]; - int value_buy, value_sell, value_notdc, value_notoc; - int type; - int class; - int sex; - int equip; - int weight; - int atk; - int def; - int range; - int slot; - int look; - int elv; - int wlv; - char *use_script; // 回復とかも全部この中でやろうかなと - char *equip_script; // 攻撃,防御の属性設定もこの中で可能かな? - char available; -}; - -struct item_data *itemdb_search (int nameid); -#define itemdb_type(n) itemdb_search(n)->type - -int itemdb_isequip (int); -int itemdb_isequip2 (struct item_data *); - -void do_final_itemdb (void); -int do_init_itemdb (void); - -#endif diff --git a/src/char_sql/make.sh b/src/char_sql/make.sh deleted file mode 100644 index a4ca8b5..0000000 --- a/src/char_sql/make.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/sh - rsqlt=`rm -rf *.o` - gcc -c char.c -I/usr/local/include/mysql/ - gcc -c int_guild.c -I/usr/local/include/mysql/ - gcc -c int_party.c -I/usr/local/include/mysql/ - gcc -c int_pet.c -I/usr/local/include/mysql/ - gcc -c int_storage.c -I/usr/local/include/mysql/ - gcc -c inter.c -I/usr/local/include/mysql/ - gcc -c strlib.c - gcc -c itemdb.c -I../common/ - gcc -o ../char-server inter.o char.o int_pet.o int_storage.o int_guild.o int_party.o strlib.o itemdb.o ../common/core.o ../common/socket.o ../common/timer.o ../common/db.o -L/usr/local/lib/mysql -lmysqlclient -lz diff --git a/src/char_sql/readme.txt b/src/char_sql/readme.txt deleted file mode 100644 index 41b1144..0000000 --- a/src/char_sql/readme.txt +++ /dev/null @@ -1,250 +0,0 @@ -//Encoded with UTF-8 (UNICODE) -//--------------------------------------------- -// V.018 - Aarlex -1. ADD Makefile & GNUmakefile -2. fix guild_leave. -3. fix char select windows HP & SP value error. - -// V.017 - Aarlex -1. fix guild member view job update.(For mod-0728) - inter.c - int_guild.c - -// V.016 - by Aarlex -1. Add e-mail check when you Delete char data. -2. modify storage save func like 014. -2. remove Lan_support func. - -// v.014 - by Aarlex -I rewrite save function. -besause myfriend find that Mysql will use more than 40% CPU. -And log file is too big (4 days 22G ..= =+) -(maybe he sets autosave_time less then 1 min.) -but. i still rewrite save func. -char server will delete all of user item(inventory & Cart) data then insert them again before. -so i use two struct to save item data from map & database. -then compare two struct to get different . -AND add some debug message.but message maybe too much XD. - - -1. ADDED itemdb.c itemdb.h -2. modify mmo_char_tosql(). -3. ADDED memitemdata_to_sql(). -4. ADDED some debug message in memitemdata_to_sql(). -5. modify make.sh - -// v.013 - by Aarlex -1. some SQL sentance fix in old version Mysql . - -2. in_guild.c mapif_guild_leaved() - unsigned char buf[64] -> unsigned char buf[128] - -3. in_pet.c inter_pet_tosql() - if (sql_res) - > if (mysql_num_rows(sql_res)!=0) - -4. in_char.c mmo_char_send006b() - - WFIFOW(fd, offset+(i*106)+42) = char_dat[0].hp -> WFIFOW(fd,offset+(i*106)+42) = (char_dat[j].hp > 0x7fff)? 0x7fff:char_dat[j].hp; - WFIFOW(fd, offset+(i*106)+44) = char_dat[0].max_hp -> WFIFOW(fd,offset+(i*106)+44) = (char_dat[j].max_hp > 0x7fff)? 0x7fff:char_dat[j].max_hp; - WFIFOW(fd, offset+(i*106)+46) = char_dat[0].sp -> WFIFOW(fd,offset+(i*106)+46) = (char_dat[j].sp > 0x7fff)? 0x7fff:char_dat[j].sp - WFIFOW(fd, offset+(i*106)+48) = char_dat[0].max_sp -> WFIFOW(fd,offset+(i*106)+48) = (char_dat[j].max_sp > 0x7fff)? 0x7fff:char_dat[j].max_sp; - - in_char.c parse_char() - - WFIFOW(fd, offset+(i*106)+42) = char_dat[0].hp -> WFIFOW(fd,offset+(i*106)+42) = (char_dat[j].hp > 0x7fff)? 0x7fff:char_dat[j].hp; - WFIFOW(fd, offset+(i*106)+44) = char_dat[0].max_hp -> WFIFOW(fd,offset+(i*106)+44) = (char_dat[j].max_hp > 0x7fff)? 0x7fff:char_dat[j].max_hp; - WFIFOW(fd, offset+(i*106)+46) = char_dat[0].sp -> WFIFOW(fd,offset+(i*106)+46) = (char_dat[j].sp > 0x7fff)? 0x7fff:char_dat[j].sp - WFIFOW(fd, offset+(i*106)+48) = char_dat[0].max_sp -> WFIFOW(fd,offset+(i*106)+48) = (char_dat[j].max_sp > 0x7fff)? 0x7fff:char_dat[j].max_sp; - -// v.012 - by Jazz -1. 0627 official versionに合わせて修正しました. -2. no more binary files are supplied. - -//--------------------------------------------- -// v.011 - by Mark -1. Fixed a couple bugs which would cause segfaults under linux :) - -//--------------------------------------------- -// v.010 - by Jazz -1. added some debug info - for reporting. - -//--------------------------------------------- -// v.009 - by Jazz -1. code added for debug. -2. some SQL sentance fix. - -//--------------------------------------------- -// v.009 - by Jazz -1. fix crash bug. - pet db. - -//--------------------------------------------- -// v.008 - by Jazz -1. DB table fix. - char.fix-from.007.to.008.sql - -既存の table 構造には矢が装着解除される場合があります. - -item.equipは 'unsigned short' 形式です. -このために SQL tableを修正しなければなりません. - -修正コードは char.fix-from.007.to.008.sql です. -MySQLで一度行ってくれれば適用されます. 既存のデータは安全です. - -//--------------------------------------------- -// v.007 - by Jazz -1. domain 解釈に対する問題を修正しました. - -//--------------------------------------------- -// v.006 - by Jazz -1. crash bug fix. - when your pet DB is empty - -//--------------------------------------------- -// v.005 - by Jazz -1. 0590 official versionに合わせて修正しました. - -//--------------------------------------------- -// v.004 - by Jazz -1. 0586 official versionに合わせて修正しました. - -//--------------------------------------------- -// v.003 - by Jazz -1. officialの guild.c と party.c ファイルでまた再修正しました. - -//--------------------------------------------- -// v.002 - by Jazz -1. aphostropy 問題を解決しました. これは保安と連関がある問題です. -2. SQLの構造を修正しました. - -//--------------------------------------------- -// v.001 - by Jazz -1. 一番目安定 versionです. alpha versionに問題点を多数修正しました. - -//------------------------------------------------------------------------ -//For JAPANESE USER -Athena Char-Server for MySQL. 005 - -一応 guildと partyはよく呼び出しされる部分なので既存の athena char-serverが使っている file 基盤の構造を持って行きます. -これは, 一度にメモリーで皆読んで, もう一度に皆 fileで使う方が部下が少なくかかると思います. -そして char データに比べて, lostになっても問題がもっと少ないと判断してそうしました. - -MySQLバージョンの compileは MySQL Clients Libraryが必要です. windows(cygwin) バージョンにコンパイルされた binaryを添付しました. - -設置: -まだ text->DBの converterはまともに支援しないです. 内部的にちょっとバグが発見されてバグを修正中です. -できるだけ早く uploadをします. - -1. char.sqlを MySQLに dumpします. - -2. inter_athena.confに次を追加します. そして自分の DBサーバーの情報に合わせてくれます. -ここで windows(cygwin)の場合には localhostを使ってはいけないです. ipで書いてくれなければなりません. -localhostで使う場合 UNIX domain socketが作動するから連結が不可能になります. - -//3306 is default -db_server_port: 3306 -//DB ip -db_server_ip: 127.0.0.1 -//DB id -db_server_id: ragnarok -//DB pass -db_server_pw: ragnarok -//DB name -db_server_logindb: ragnarok - -3. MySQL バージョンは 2個の MySQL connect sessionを持ちます. -一つはキャラクターデータを読んで書くのに使われて, 二番目は inter serverのために連結します. - -開発とテスト環境は P4 2.4a/1024MB/WinXP pro(MediaCenter Edition 2K4 KR)/Cygwin GCC です. -本人が韓国人だから韓国語開発者の連絡も歓迎します. -韓国語と日本語の上手な方は連絡をください. 日本語の使用に難しさを感じています. - -現在 DarkWeissが login serverに MySQLを支援し始めました. -しかし athenaのそれは DarkWeiss よりもっとよく作動すると思います. - -contact : jazz@creper.com - -//------------------------------------------------------------------------ -//For KOREAN USER -Athena Char-Server for MySQL. 005 - -일단 guild와 party는 자주 호출되는 부분이라서 기존의 athena char-server가 사용하고 있는 file 기반의 구조를 가지고 갑니다. -이 것은, 한번에 메모리로 모두 읽고, 다시 한번에 모두 file로 쓰는 쪽이 부하가 적게 걸린다고 생각합니다. -그리고 char 데이터에 비해, lost가 되더라도 문제가 더 적다고 판단해서 그렇게 하였습니다. - -MySQL버전의 compile은 MySQL Clients Library가 필요합니다. windows(cygwin) 버전으로 컴파일된 binary를 첨부하였습니다. - -설치: -아직 text->DB의 converter는 제대로 지원하지 않습니다. 내부적으로 약간 버그가 발견되어 버그를 수정중입니다. -되도록 빨리 upload를 하겠습니다. - -1. char.sql을 MySQL에 dump합니다. - -2. inter_athena.conf에 다음을 추가 합니다. 그리고 자신의 DB서버의 정보에 맞추어 줍니다. -여기에서 windows(cygwin)의 경우에는 localhost를 쓰면 안됩니다. ip로 적어주어야 합니다. -localhost로 사용하는 경우 UNIX domain socket이 작동 하기 때문에 연결이 불가능해 집니다. - -//3306 is default -db_server_port: 3306 -//DB ip -db_server_ip: 127.0.0.1 -//DB id -db_server_id: ragnarok -//DB pass -db_server_pw: ragnarok -//DB name -db_server_logindb: ragnarok - -3. MySQL 버전은 2개의 MySQL connect session을 가집니다. -하나는 캐릭터 데이터를 읽고 쓰는데 사용되며, 두번째는 inter server를 위해서 연결합니다. - -개발과 테스트 환경은 P4 2.4a/1024MB/WinXP pro(MediaCenter Edition 2K4 KR)/Cygwin GCC 입니다. -본인이 한국인이기 때문에 한국어 개발자의 연락도 환영합니다. -한국어와 일본어가 능숙한 분은 연락을 주세요. 일본어의 사용에 어려움을 느끼고 있습니다. - -현재 DarkWeiss가 login server에 MySQL을 지원하기 시작했습니다. -하지만 athena의 그것은 DarkWeiss 보다 더 잘 작동한다고 생각합니다. - -contact : jazz@creper.com - -//------------------------------------------------------------------------ -//For ENGLISH USER -Athena Char-Server for MySQL. alpha 005 - -= hehe. My English is poor. and I have no time to write. :) - -anyway this version use guild and party data on text file base system. -It accesses many times, so memory dumping is useful for less cpu consume. - -MySQL version need MySQL Clients Library to compile. This include Win32-binary compiled by cygwin-gcc. - -Install: -not yet text->DB converter. I found some bug on it, so It's under debug progress. - -1. dump char.sql to MySQL. - -2. add below on inter_athena.conf. and set your own information. -do not use 'localhost' as domain on cygwin. you must set as ip. -if you use localhost on cygwin, cygwin tries to connect MySQL as UNIX domain socket. -but, MySQL does not support UNIX domain socket on windows. - -//3306 is default -db_server_port: 3306 -//DB ip -db_server_ip: 127.0.0.1 -//DB id -db_server_id: ragnarok -//DB pass -db_server_pw: ragnarok -//DB name -db_server_logindb: ragnarok - -3. MySQL version has 2 MySQL connect session. -one is for char-server and the other one is for inter-server. - -developement enviroment) - P4 2.4a/1024MB/WinXP pro(MediaCenter Edition 2K4 KR)/Cygwin GCC - -I'm korean, so contect if U're Korean developer. -Please contact me, If U can use Korean & Japanese well. - -DarkWeiss starts to support MySQL version of login server, but Athena's one works better, I thnik. - -contact : jazz@creper.com diff --git a/src/char_sql/strlib.c b/src/char_sql/strlib.c deleted file mode 100644 index 02911d1..0000000 --- a/src/char_sql/strlib.c +++ /dev/null @@ -1,89 +0,0 @@ -#include -#include -#include - -#include "strlib.h" -#include "utils.h" - -//----------------------------------------------- -// string lib. -unsigned char *jstrescape (unsigned char *pt) -{ - //copy from here - unsigned char *ptr; - int i = 0, j = 0; - - //copy string to temporary - CREATE (ptr, char, J_MAX_MALLOC_SIZE); - strcpy (ptr, pt); - - while (ptr[i] != '\0') - { - switch (ptr[i]) - { - case '\'': - pt[j++] = '\\'; - pt[j++] = ptr[i++]; - break; - case '\\': - pt[j++] = '\\'; - pt[j++] = ptr[i++]; - break; - default: - pt[j++] = ptr[i++]; - } - } - pt[j++] = '\0'; - free (ptr); - return (unsigned char *) &pt[0]; -} - -unsigned char *jstrescapecpy (unsigned char *pt, unsigned char *spt) -{ - //copy from here - int i = 0, j = 0; - - while (spt[i] != '\0') - { - switch (spt[i]) - { - case '\'': - pt[j++] = '\\'; - pt[j++] = spt[i++]; - break; - case '\\': - pt[j++] = '\\'; - pt[j++] = spt[i++]; - break; - default: - pt[j++] = spt[i++]; - } - } - pt[j++] = '\0'; - return (unsigned char *) &pt[0]; -} - -int jmemescapecpy (unsigned char *pt, unsigned char *spt, int size) -{ - //copy from here - int i = 0, j = 0; - - while (i < size) - { - switch (spt[i]) - { - case '\'': - pt[j++] = '\\'; - pt[j++] = spt[i++]; - break; - case '\\': - pt[j++] = '\\'; - pt[j++] = spt[i++]; - break; - default: - pt[j++] = spt[i++]; - } - } - // copy size is 0 ~ (j-1) - return j; -} diff --git a/src/char_sql/strlib.h b/src/char_sql/strlib.h deleted file mode 100644 index f8da756..0000000 --- a/src/char_sql/strlib.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef _J_STR_LIB_H_ -#define _J_STR_LIB_H_ -#define J_MAX_MALLOC_SIZE 65535 -// String function library. -// code by Jioh L. Jung (ziozzang@4wish.net) -// This code is under license "BSD" -unsigned char *jstrescape (unsigned char *pt); -unsigned char *jstrescapecpy (unsigned char *pt, unsigned char *spt); -int jmemescapecpy (unsigned char *pt, unsigned char *spt, int size); -#endif diff --git a/src/login_sql/Makefile b/src/login_sql/Makefile deleted file mode 100644 index 12fd7f3..0000000 --- a/src/login_sql/Makefile +++ /dev/null @@ -1,19 +0,0 @@ -include ../../make.defs - -all: login-server_sql -sql: login-server_sql - -shared_libs=all -COMMON_OBJ = ../common/core.o ../common/socket.o ../common/timer.o ../common/db.o ../common/malloc.o -COMMON_H = ../common/core.h ../common/socket.h ../common/timer.h ../common/mmo.h ../common/version.h ../common/db.h ../common/malloc.h - -login-server_sql: login.o md5calc.o strlib.o $(COMMON_OBJ) - $(CC) -o ../../$@ $^ $(LIB_S) - -login.o: login.c login.h md5calc.h strlib.h $(COMMON_H) -md5calc.o: md5calc.c md5calc.h -strlib.o: strlib.c strlib.h - -clean: - rm -f *.o ../../login-server_sql - diff --git a/src/login_sql/login.c b/src/login_sql/login.c deleted file mode 100644 index db58026..0000000 --- a/src/login_sql/login.c +++ /dev/null @@ -1,2073 +0,0 @@ -// $Id: login.c,v 1.6 2004/09/19 21:12:07 Valaris Exp $ -// original : login2.c 2003/01/28 02:29:17 Rev.1.1.1.1 -// txt version 1.100 - -#include - -#ifdef LCCWIN32 -#include -#pragma lib -#else -#include -#include -#include -#include -#include -#endif - -#include -#include -#include -#include -#include -#include -#include // for stat/lstat/fstat -#include -#include -#include -#include -#include - -//add include for DBMS(mysql) -#include - -#include "strlib.h" -#include "timer.h" -/* -#include "timer.h" -#include "core.h" -#include "socket.h" -#include "login.h" -#include "mmo.h" -#include "version.h" -#include "db.h" -*/ - -#include "../common/core.h" -#include "../common/socket.h" -#include "login.h" -#include "../common/mmo.h" -#include "../common/version.h" -#include "../common/db.h" -#include "../common/timer.h" - -#ifdef PASSWORDENC -#include "md5calc.h" -#endif - -#ifdef MEMWATCH -#include "memwatch.h" -#endif - -#define J_MAX_MALLOC_SIZE 65535 - -//----------------------------------------------------- -// global variable -//----------------------------------------------------- -int account_id_count = START_ACCOUNT_NUM; -int server_num; -int new_account_flag = 0; -int login_port = 6900; -char lan_char_ip[128]; // Lan char ip added by kashy -int subnetmaski[4]; // Subnetmask added by kashy - -struct mmo_char_server server[MAX_SERVERS]; -int server_fd[MAX_SERVERS]; -int server_freezeflag[MAX_SERVERS]; // Char-server anti-freeze system. Counter. 5 ok, 4...0 freezed -int anti_freeze_enable = 0; -int ANTI_FREEZE_INTERVAL = 15; - -int login_fd; - -char date_format[32] = "%Y-%m-%d %H:%M:%S"; -int auth_num = 0, auth_max = 0; - -int min_level_to_connect = 0; // minimum level of player/GM (0: player, 1-99: gm) to connect on the server -int check_ip_flag = 1; // It's to check IP of a player between login-server and char-server (part of anti-hacking system) - -MYSQL mysql_handle; - -int ipban = 1; -int dynamic_account_ban = 1; -int dynamic_account_ban_class = 0; -int dynamic_pass_failure_ban = 1; -int dynamic_pass_failure_ban_time = 5; -int dynamic_pass_failure_ban_how_many = 3; -int dynamic_pass_failure_ban_how_long = 60; - -int login_server_port = 3306; -char login_server_ip[32] = "127.0.0.1"; -char login_server_id[32] = "ragnarok"; -char login_server_pw[32] = "ragnarok"; -char login_server_db[32] = "ragnarok"; -int use_md5_passwds = 0; -char login_db[256] = "login"; -char loginlog_db[256] = "loginlog"; - -// added to help out custom login tables, without having to recompile -// source so options are kept in the login_athena.conf or the inter_athena.conf -char login_db_account_id[256] = "account_id"; -char login_db_userid[256] = "userid"; -char login_db_user_pass[256] = "user_pass"; -char login_db_level[256] = "level"; - -char tmpsql[65535], tmp_sql[65535]; - -//----------------------------------------------------- - -#define AUTH_FIFO_SIZE 256 -struct -{ - int account_id, login_id1, login_id2; - int ip, sex, delflag; -} auth_fifo[AUTH_FIFO_SIZE]; - -int auth_fifo_pos = 0; - -//----------------------------------------------------- - -static char md5key[20], md5keylen = 16; - -//----------------------------------------------------- -// check user level -//----------------------------------------------------- - -int isGM (int account_id) -{ - int level; - - MYSQL_RES *sql_res; - MYSQL_ROW sql_row; - level = 0; - sprintf (tmpsql, "SELECT `%s` FROM `%s` WHERE `%s`='%d'", login_db_level, - login_db, login_db_account_id, account_id); - if (mysql_query (&mysql_handle, tmpsql)) - { - printf ("DB server Error (select GM Level to Memory)- %s\n", - mysql_error (&mysql_handle)); - } - sql_res = mysql_store_result (&mysql_handle); - if (sql_res) - { - sql_row = mysql_fetch_row (sql_res); - level = atoi (sql_row[0]); - if (level > 99) - level = 99; - } - - if (level == 0) - { - return 0; - //not GM - } - - mysql_free_result (sql_res); - - return level; -} - -//----------------------------------------------------- -// Function to suppress control characters in a string. -//----------------------------------------------------- -int remove_control_chars (unsigned char *str) -{ - int i; - int change = 0; - - for (i = 0; str[i]; i++) - { - if (str[i] < 32) - { - str[i] = '_'; - change = 1; - } - } - - return change; -} - -//--------------------------------------------------- -// E-mail check: return 0 (not correct) or 1 (valid). -//--------------------------------------------------- -int e_mail_check (unsigned char *email) -{ - char ch; - unsigned char *last_arobas; - - // athena limits - if (strlen (email) < 3 || strlen (email) > 39) - return 0; - - // part of RFC limits (official reference of e-mail description) - if (strchr (email, '@') == NULL || email[strlen (email) - 1] == '@') - return 0; - - if (email[strlen (email) - 1] == '.') - return 0; - - last_arobas = strrchr (email, '@'); - - if (strstr (last_arobas, "@.") != NULL || - strstr (last_arobas, "..") != NULL) - return 0; - - for (ch = 1; ch < 32; ch++) - { - if (strchr (last_arobas, ch) != NULL) - { - return 0; - break; - } - } - - if (strchr (last_arobas, ' ') != NULL || - strchr (last_arobas, ';') != NULL) - return 0; - - // all correct - return 1; -} - -//----------------------------------------------------- -// Read Account database - mysql db -//----------------------------------------------------- -int mmo_auth_sqldb_init (void) -{ - - printf ("Login server init....\n"); - - // memory initialize - printf ("memory initialize....\n"); - - mysql_init (&mysql_handle); - - // DB connection start - printf ("Connect Login Database Server....\n"); - if (!mysql_real_connect - (&mysql_handle, login_server_ip, login_server_id, login_server_pw, - login_server_db, login_server_port, (char *) NULL, 0)) - { - // pointer check - printf ("%s\n", mysql_error (&mysql_handle)); - exit (1); - } - else - { - printf ("connect success!\n"); - } - - sprintf (tmpsql, - "INSERT INTO `%s`(`time`,`ip`,`user`,`rcode`,`log`) VALUES (NOW(), '', 'lserver', '100','login server started')", - loginlog_db); - - //query - if (mysql_query (&mysql_handle, tmpsql)) - { - printf ("DB server Error - %s\n", mysql_error (&mysql_handle)); - } - - return 0; -} - -//----------------------------------------------------- -// DB server connect check -//----------------------------------------------------- -void mmo_auth_sqldb_sync (void) -{ - // db connect check? or close? - // ping pong DB server -if losted? then connect try. else crash. -} - -//----------------------------------------------------- -// close DB -//----------------------------------------------------- -void mmo_db_close (void) -{ - - //set log. - sprintf (tmpsql, - "INSERT INTO `%s`(`time`,`ip`,`user`,`rcode`,`log`) VALUES (NOW(), '', 'lserver','100', 'login server shutdown')", - loginlog_db); - - //query - if (mysql_query (&mysql_handle, tmpsql)) - { - printf ("DB server Error - %s\n", mysql_error (&mysql_handle)); - } - - //delete all server status - sprintf (tmpsql, "DELETE FROM `sstatus`"); - //query - if (mysql_query (&mysql_handle, tmpsql)) - { - printf ("DB server Error - %s\n", mysql_error (&mysql_handle)); - } - - mysql_close (&mysql_handle); - printf ("close DB connect....\n"); - - int i, fd; - - for (i = 0; i < MAX_SERVERS; i++) - { - if ((fd = server_fd[i]) >= 0) - delete_session (fd); - } - delete_session (login_fd); -} - -//----------------------------------------------------- -// Make new account -//----------------------------------------------------- -int mmo_auth_sqldb_new (struct mmo_account *account, const char *tmpstr, - char sex) -{ - //no need on DB version - - printf ("Request new account.... - not support on this version\n"); - - return 0; -} - -//----------------------------------------------------- -// Make new account -//----------------------------------------------------- -int mmo_auth_new (struct mmo_account *account, const char *tmpstr, char sex) -{ - - return 0; -} - -#ifdef LCCWIN32 -extern void gettimeofday (struct timeval *t, struct timezone *dummy); -#endif - -//----------------------------------------------------- -// Auth -//----------------------------------------------------- -int mmo_auth (struct mmo_account *account, int fd) -{ - struct timeval tv; - time_t ban_until_time; - char tmpstr[256]; - char t_uid[256], t_pass[256]; - char user_password[256]; - - MYSQL_RES *sql_res; - MYSQL_ROW sql_row; - //int sql_fields, sql_cnt; - char md5str[64], md5bin[32]; - - char ip[16]; - - unsigned char *sin_addr = - (unsigned char *) &session[fd]->client_addr.sin_addr; - - printf ("auth start...\n"); - - sprintf (ip, "%d.%d.%d.%d", sin_addr[0], sin_addr[1], sin_addr[2], - sin_addr[3]); - - // auth start : time seed - gettimeofday (&tv, NULL); - strftime (tmpstr, 24, "%Y-%m-%d %H:%M:%S", gmtime (&(tv.tv_sec))); - sprintf (tmpstr + 19, ".%03d", (int) tv.tv_usec / 1000); - - jstrescapecpy (t_uid, account->userid); - jstrescapecpy (t_pass, account->passwd); - - // make query - sprintf (tmpsql, - "SELECT `%s`,`%s`,`%s`,`lastlogin`,`logincount`,`sex`,`connect_until`,`last_ip`,`ban_until`,`state`,`%s`" - " FROM `%s` WHERE `%s`='%s'", login_db_account_id, - login_db_userid, login_db_user_pass, login_db_level, login_db, - login_db_userid, t_uid); - //login {0-account_id/1-userid/2-user_pass/3-lastlogin/4-logincount/5-sex/6-connect_untl/7-last_ip/8-ban_until/9-state} - - // query - if (mysql_query (&mysql_handle, tmpsql)) - { - printf ("DB server Error - %s\n", mysql_error (&mysql_handle)); - } - sql_res = mysql_store_result (&mysql_handle); - if (sql_res) - { - sql_row = mysql_fetch_row (sql_res); //row fetching - if (!sql_row) - { - //there's no id. - printf ("auth failed no account %s %s %s\n", tmpstr, - account->userid, account->passwd); - mysql_free_result (sql_res); - return 0; - } - } - else - { - printf ("mmo_auth DB result error ! \n"); - return 0; - } - // Documented by CLOWNISIUS || LLRO || Gunstar lead this one with me - // IF changed to diferent returns~ you get diferent responses from your msgstringtable.txt - //Ireturn 2 == line 9 - //Ireturn 5 == line 311 - //Ireturn 6 == line 450 - //Ireturn 7 == line 440 - //Ireturn 8 == line 682 - //Ireturn 9 == line 704 - //Ireturn 10 == line 705 - //Ireturn 11 == line 706 - //Ireturn 12 == line 707 - //Ireturn 13 == line 708 - //Ireturn 14 == line 709 - //Ireturn 15 == line 710 - //Ireturn -1 == line 010 - // Check status - { - if (atoi (sql_row[9]) == -3) - { - //id is banned - mysql_free_result (sql_res); - return -3; - } - else if (atoi (sql_row[9]) == -2) - { //dynamic ban - //id is banned - mysql_free_result (sql_res); - //add IP list. - return -2; - } - - if (use_md5_passwds) - { - MD5_String (account->passwd, user_password); - } - else - { - jstrescapecpy (user_password, account->passwd); - } - printf ("account id ok encval:%d\n", account->passwdenc); - int encpasswdok = 0; -#ifdef PASSWORDENC - if (account->passwdenc > 0) - { - printf ("start md5calc..\n"); - int j = account->passwdenc; - if (j > 2) - j = 1; - do - { - if (j == 1) - { - sprintf (md5str, "%s%s", md5key, sql_row[2]); - } - else if (j == 2) - { - sprintf (md5str, "%s%s", sql_row[2], md5key); - } - else - md5str[0] = 0; - printf ("j:%d mdstr:%s\n", j, md5str); - MD5_String2binary (md5str, md5bin); - encpasswdok = (memcmp (user_password, md5bin, 16) == 0); - } - while (j < 2 && !encpasswdok && (j++) != account->passwdenc); - //printf("key[%s] md5 [%s] ", md5key, md5); - printf ("client [%s] accountpass [%s]\n", user_password, - sql_row[2]); - printf ("end md5calc..\n"); - } -#endif - if ((strcmp (user_password, sql_row[2]) && !encpasswdok)) - { - if (account->passwdenc == 0) - { - printf ("auth failed pass error %s %s %s" RETCODE, tmpstr, - account->userid, user_password); -#ifdef PASSWORDENC - } - else - { - char logbuf[1024], *p = logbuf; - int j; - p += sprintf (p, "auth failed pass error %s %s recv-md5[", - tmpstr, account->userid); - for (j = 0; j < 16; j++) - p += sprintf (p, "%02x", - ((unsigned char *) user_password)[j]); - p += sprintf (p, "] calc-md5["); - for (j = 0; j < 16; j++) - p += sprintf (p, "%02x", ((unsigned char *) md5bin)[j]); - p += sprintf (p, "] md5key["); - for (j = 0; j < md5keylen; j++) - p += sprintf (p, "%02x", ((unsigned char *) md5key)[j]); - p += sprintf (p, "]" RETCODE); - printf ("%s\n", p); -#endif - } - return 1; - } - printf ("auth ok %s %s" RETCODE, tmpstr, account->userid); - } - - if (atoi (sql_row[9])) - { - switch (atoi (sql_row[9])) - { // packet 0x006a value + 1 - case 1: // 0 = Unregistered ID - case 2: // 1 = Incorrect Password - case 3: // 2 = This ID is expired - case 4: // 3 = Rejected from Server - case 5: // 4 = You have been blocked by the GM Team - case 6: // 5 = Your Game's EXE file is not the latest version - case 7: // 6 = Your are Prohibited to log in until %s - case 8: // 7 = Server is jammed due to over populated - case 9: // 8 = No MSG (actually, all states after 9 except 99 are No MSG, use only this) - case 100: // 99 = This ID has been totally erased - printf ("Auth Error #%d\n", atoi (sql_row[9])); - return atoi (sql_row[9]) - 1; - break; - default: - return 99; // 99 = ID has been totally erased - break; - } - } - -/* -// do not remove this section. this is meant for future, and current forums usage -// as a login manager and CP for login server. [CLOWNISIUS] - if (atoi(sql_row[10]) == 1) { - return 4; - } - - if (atoi(sql_row[10]) >= 5) { - switch(atoi(sql_row[10])) { - case 5: - return 5; - break; - case 6: - return 7; - break; - case 7: - return 9; - break; - case 8: - return 10; - break; - case 9: - return 11; - break; - default: - return 10; - break; - } - } -*/ - ban_until_time = atol (sql_row[8]); - - //login {0-account_id/1-userid/2-user_pass/3-lastlogin/4-logincount/5-sex/6-connect_untl/7-last_ip/8-ban_until/9-state} - if (ban_until_time != 0) - { // if account is banned - strftime (tmpstr, 20, date_format, gmtime (&ban_until_time)); - tmpstr[19] = '\0'; - if (ban_until_time > time (NULL)) - { // always banned - return 6; // 6 = Your are Prohibited to log in until %s - } - else - { // ban is finished - // reset the ban time - sprintf (tmpsql, - "UPDATE `%s` SET `ban_until`='0' WHERE `%s`='%s'", - login_db, login_db_userid, t_uid); - if (mysql_query (&mysql_handle, tmpsql)) - { - printf ("DB server Error - %s\n", - mysql_error (&mysql_handle)); - } - } - } - - if (atol (sql_row[6]) != 0 && atol (sql_row[6]) < time (NULL)) - { - return 2; // 2 = This ID is expired - } - - account->account_id = atoi (sql_row[0]); - account->login_id1 = rand (); - account->login_id2 = rand (); - memcpy (tmpstr, sql_row[3], 19); - memcpy (account->lastlogin, tmpstr, 24); - account->sex = sql_row[5][0] == 'S' ? 2 : sql_row[5][0] == 'M'; - - sprintf (tmpsql, - "UPDATE `%s` SET `lastlogin` = NOW(), `logincount`=`logincount` +1, `last_ip`='%s' WHERE `%s` = '%s'", - login_db, ip, login_db_userid, sql_row[1]); - mysql_free_result (sql_res); //resource free - if (mysql_query (&mysql_handle, tmpsql)) - { - printf ("DB server Error - %s\n", mysql_error (&mysql_handle)); - } - - return -1; -} - -// Send to char -int charif_sendallwos (int sfd, unsigned char *buf, unsigned int len) -{ - int i, c; - int fd; - - c = 0; - for (i = 0; i < MAX_SERVERS; i++) - { - if ((fd = server_fd[i]) > 0 && fd != sfd) - { - memcpy (WFIFOP (fd, 0), buf, len); - WFIFOSET (fd, len); - c++; - } - } - - return c; -} - -//-------------------------------- -// Char-server anti-freeze system -//-------------------------------- -int char_anti_freeze_system (int tid, unsigned int tick, int id, int data) -{ - int i; - - for (i = 0; i < MAX_SERVERS; i++) - { - if (server_fd[i] >= 0) - { // if char-server is online -// printf("char_anti_freeze_system: server #%d '%s', flag: %d.\n", i, server[i].name, server_freezeflag[i]); - if (server_freezeflag[i]-- < 1) - { // Char-server anti-freeze system. Counter. 5 ok, 4...0 freezed - session[server_fd[i]]->eof = 1; - } - } - } - - return 0; -} - -//----------------------------------------------------- -// char-server packet parse -//----------------------------------------------------- -int parse_fromchar (int fd) -{ - int i, id; - MYSQL_RES *sql_res; - MYSQL_ROW sql_row = NULL; - - unsigned char *p = (unsigned char *) &session[fd]->client_addr.sin_addr; - char ip[16]; - - sprintf (ip, "%d.%d.%d.%d", p[0], p[1], p[2], p[3]); - - for (id = 0; id < MAX_SERVERS; id++) - if (server_fd[id] == fd) - break; - - if (id == MAX_SERVERS || session[fd]->eof) - { - if (id < MAX_SERVERS) - { - printf ("Char-server '%s' has disconnected.\n", server[id].name); - server_fd[id] = -1; - memset (&server[id], 0, sizeof (struct mmo_char_server)); - // server delete - sprintf (tmpsql, "DELETE FROM `sstatus` WHERE `index`='%d'", id); - // query - if (mysql_query (&mysql_handle, tmpsql)) - { - printf ("DB server Error - %s\n", - mysql_error (&mysql_handle)); - } - } - close (fd); - delete_session (fd); - return 0; - } - - while (RFIFOREST (fd) >= 2) - { -// printf("char_parse: %d %d packet case=%x\n", fd, RFIFOREST(fd), RFIFOW(fd, 0)); - - switch (RFIFOW (fd, 0)) - { - case 0x2712: - if (RFIFOREST (fd) < 19) - return 0; - { - int account_id; - account_id = RFIFOL (fd, 2); // speed up - for (i = 0; i < AUTH_FIFO_SIZE; i++) - { - if (auth_fifo[i].account_id == account_id && - auth_fifo[i].login_id1 == RFIFOL (fd, 6) && -#if CMP_AUTHFIFO_LOGIN2 != 0 - auth_fifo[i].login_id2 == RFIFOL (fd, 10) && // relate to the versions higher than 18 -#endif - auth_fifo[i].sex == RFIFOB (fd, 14) && -#if CMP_AUTHFIFO_IP != 0 - auth_fifo[i].ip == RFIFOL (fd, 15) && -#endif - !auth_fifo[i].delflag) - { - auth_fifo[i].delflag = 1; - printf ("auth -> %d\n", i); - break; - } - } - - if (i != AUTH_FIFO_SIZE) - { // send account_reg - int p; - time_t connect_until_time = 0; - char email[40] = ""; - account_id = RFIFOL (fd, 2); - sprintf (tmpsql, - "SELECT `email`,`connect_until` FROM `%s` WHERE `%s`='%d'", - login_db, login_db_account_id, account_id); - if (mysql_query (&mysql_handle, tmpsql)) - { - printf ("DB server Error - %s\n", - mysql_error (&mysql_handle)); - } - sql_res = mysql_store_result (&mysql_handle); - if (sql_res) - { - sql_row = mysql_fetch_row (sql_res); - connect_until_time = atol (sql_row[1]); - strcpy (email, sql_row[0]); - } - mysql_free_result (sql_res); - if (account_id > 0) - { - sprintf (tmpsql, - "SELECT `str`,`value` FROM `global_reg_value` WHERE `type`='1' AND `account_id`='%d'", - account_id); - if (mysql_query (&mysql_handle, tmpsql)) - { - printf ("DB server Error - %s\n", - mysql_error (&mysql_handle)); - } - sql_res = mysql_store_result (&mysql_handle); - if (sql_res) - { - WFIFOW (fd, 0) = 0x2729; - WFIFOL (fd, 4) = account_id; - for (p = 8; - (sql_row = mysql_fetch_row (sql_res)); - p += 36) - { - memcpy (WFIFOP (fd, p), sql_row[0], 32); - WFIFOL (fd, p + 32) = atoi (sql_row[1]); - } - WFIFOW (fd, 2) = p; - WFIFOSET (fd, p); - //printf("account_reg2 send : login->char (auth fifo)\n"); - WFIFOW (fd, 0) = 0x2713; - WFIFOL (fd, 2) = account_id; - WFIFOB (fd, 6) = 0; - memcpy (WFIFOP (fd, 7), email, 40); - WFIFOL (fd, 47) = - (unsigned long) connect_until_time; - WFIFOSET (fd, 51); - } - mysql_free_result (sql_res); - } - } - else - { - WFIFOW (fd, 0) = 0x2713; - WFIFOL (fd, 2) = account_id; - WFIFOB (fd, 6) = 1; - WFIFOSET (fd, 51); - } - } - RFIFOSKIP (fd, 19); - break; - - case 0x2714: - if (RFIFOREST (fd) < 6) - return 0; - // how many users on world? (update) - if (server[id].users != RFIFOL (fd, 2)) - printf ("set users %s : %d\n", server[id].name, - RFIFOL (fd, 2)); - server[id].users = RFIFOL (fd, 2); - if (anti_freeze_enable) - server_freezeflag[id] = 5; // Char anti-freeze system. Counter. 5 ok, 4...0 freezed - - sprintf (tmpsql, - "UPDATE `sstatus` SET `user` = '%d' WHERE `index` = '%d'", - server[id].users, id); - // query - if (mysql_query (&mysql_handle, tmpsql)) - { - printf ("DB server Error - %s\n", - mysql_error (&mysql_handle)); - } - RFIFOSKIP (fd, 6); - break; - - // We receive an e-mail/limited time request, because a player comes back from a map-server to the char-server - case 0x2716: - if (RFIFOREST (fd) < 6) - return 0; - { - int account_id; - time_t connect_until_time = 0; - char email[40] = ""; - account_id = RFIFOL (fd, 2); - sprintf (tmpsql, - "SELECT `email`,`connect_until` FROM `%s` WHERE `%s`='%d'", - login_db, login_db_account_id, account_id); - if (mysql_query (&mysql_handle, tmpsql)) - { - printf ("DB server Error - %s\n", - mysql_error (&mysql_handle)); - } - sql_res = mysql_store_result (&mysql_handle); - if (sql_res) - { - sql_row = mysql_fetch_row (sql_res); - connect_until_time = atol (sql_row[1]); - strcpy (email, sql_row[0]); - } - mysql_free_result (sql_res); - //printf("parse_fromchar: E-mail/limited time request from '%s' server (concerned account: %d)\n", server[id].name, RFIFOL(fd,2)); - WFIFOW (fd, 0) = 0x2717; - WFIFOL (fd, 2) = RFIFOL (fd, 2); - memcpy (WFIFOP (fd, 6), email, 40); - WFIFOL (fd, 46) = (unsigned long) connect_until_time; - WFIFOSET (fd, 50); - } - RFIFOSKIP (fd, 6); - break; - - case 0x2720: // GM - if (RFIFOREST (fd) < 4) - return 0; - if (RFIFOREST (fd) < RFIFOW (fd, 2)) - return 0; - //oldacc = RFIFOL(fd,4); - printf - ("change GM isn't support in this login server version.\n"); - printf ("change GM error 0 %s\n", RFIFOP (fd, 8)); - - RFIFOSKIP (fd, RFIFOW (fd, 2)); - WFIFOW (fd, 0) = 0x2721; - WFIFOL (fd, 2) = RFIFOL (fd, 4); // oldacc; - WFIFOL (fd, 6) = 0; // newacc; - WFIFOSET (fd, 10); - return 0; - - // Map server send information to change an email of an account via char-server - case 0x2722: // 0x2722 .L .40B .40B - if (RFIFOREST (fd) < 86) - return 0; - { - int acc; - char actual_email[40], new_email[40]; - acc = RFIFOL (fd, 2); - memcpy (actual_email, RFIFOP (fd, 6), 40); - memcpy (new_email, RFIFOP (fd, 46), 40); - if (e_mail_check (actual_email) == 0) - printf - ("Char-server '%s': Attempt to modify an e-mail on an account (@email GM command), but actual email is invalid (account: %d, ip: %s)" - RETCODE, server[id].name, acc, ip); - else if (e_mail_check (new_email) == 0) - printf - ("Char-server '%s': Attempt to modify an e-mail on an account (@email GM command) with a invalid new e-mail (account: %d, ip: %s)" - RETCODE, server[id].name, acc, ip); - else if (strcmpi (new_email, "a@a.com") == 0) - printf - ("Char-server '%s': Attempt to modify an e-mail on an account (@email GM command) with a default e-mail (account: %d, ip: %s)" - RETCODE, server[id].name, acc, ip); - else - { - sprintf (tmpsql, - "SELECT `%s`,`email` FROM `%s` WHERE `%s` = '%d'", - login_db_userid, login_db, - login_db_account_id, acc); - if (mysql_query (&mysql_handle, tmpsql)) - printf ("DB server Error - %s\n", - mysql_error (&mysql_handle)); - sql_res = mysql_store_result (&mysql_handle); - if (sql_res) - { - sql_row = mysql_fetch_row (sql_res); //row fetching - - if (strcmpi (sql_row[1], actual_email) == 0) - { - sprintf (tmpsql, - "UPDATE `%s` SET `email` = '%s' WHERE `%s` = '%d'", - login_db, new_email, - login_db_account_id, acc); - // query - if (mysql_query (&mysql_handle, tmpsql)) - { - printf ("DB server Error - %s\n", - mysql_error (&mysql_handle)); - } - printf - ("Char-server '%s': Modify an e-mail on an account (@email GM command) (account: %d (%s), new e-mail: %s, ip: %s)." - RETCODE, server[id].name, acc, - sql_row[0], actual_email, ip); - } - } - - } - } - RFIFOSKIP (fd, 86); - break; - - case 0x2724: // Receiving of map-server via char-server a status change resquest (by Yor) - if (RFIFOREST (fd) < 10) - return 0; - { - int acc, statut; - acc = RFIFOL (fd, 2); - statut = RFIFOL (fd, 6); - sprintf (tmpsql, - "SELECT `state` FROM `%s` WHERE `%s` = '%d'", - login_db, login_db_account_id, acc); - if (mysql_query (&mysql_handle, tmpsql)) - { - printf ("DB server Error - %s\n", - mysql_error (&mysql_handle)); - } - sql_res = mysql_store_result (&mysql_handle); - if (sql_res) - { - sql_row = mysql_fetch_row (sql_res); // row fetching - } - if (atoi (sql_row[0]) != statut && statut != 0) - { - unsigned char buf[16]; - WBUFW (buf, 0) = 0x2731; - WBUFL (buf, 2) = acc; - WBUFB (buf, 6) = 0; // 0: change of statut, 1: ban - WBUFL (buf, 7) = statut; // status or final date of a banishment - charif_sendallwos (-1, buf, 11); - } - sprintf (tmpsql, - "UPDATE `%s` SET `state` = '%d' WHERE `%s` = '%d'", - login_db, statut, login_db_account_id, acc); - //query - if (mysql_query (&mysql_handle, tmpsql)) - { - printf ("DB server Error - %s\n", - mysql_error (&mysql_handle)); - } - RFIFOSKIP (fd, 10); - } - return 0; - - case 0x2725: // Receiving of map-server via char-server a ban resquest (by Yor) - if (RFIFOREST (fd) < 18) - return 0; - { - int acc; - struct tm *tmtime; - time_t timestamp, tmptime; - acc = RFIFOL (fd, 2); - sprintf (tmpsql, - "SELECT `ban_until` FROM `%s` WHERE `%s` = '%d'", - login_db, login_db_account_id, acc); - if (mysql_query (&mysql_handle, tmpsql)) - { - printf ("DB server Error - %s\n", - mysql_error (&mysql_handle)); - } - sql_res = mysql_store_result (&mysql_handle); - if (sql_res) - { - sql_row = mysql_fetch_row (sql_res); // row fetching - } - tmptime = atol (sql_row[0]); - if (tmptime == 0 || tmptime < time (NULL)) - timestamp = time (NULL); - else - timestamp = tmptime; - tmtime = gmtime (×tamp); - tmtime->tm_year = - tmtime->tm_year + (short) RFIFOW (fd, 6); - tmtime->tm_mon = tmtime->tm_mon + (short) RFIFOW (fd, 8); - tmtime->tm_mday = - tmtime->tm_mday + (short) RFIFOW (fd, 10); - tmtime->tm_hour = - tmtime->tm_hour + (short) RFIFOW (fd, 12); - tmtime->tm_min = tmtime->tm_min + (short) RFIFOW (fd, 14); - tmtime->tm_sec = tmtime->tm_sec + (short) RFIFOW (fd, 16); - timestamp = timegm (tmtime); - if (timestamp != -1) - { - if (timestamp <= time (NULL)) - timestamp = 0; - if (tmptime != timestamp) - { - if (timestamp != 0) - { - unsigned char buf[16]; - WBUFW (buf, 0) = 0x2731; - WBUFL (buf, 2) = acc; - WBUFB (buf, 6) = 1; // 0: change of statut, 1: ban - WBUFL (buf, 7) = timestamp; // status or final date of a banishment - charif_sendallwos (-1, buf, 11); - } - printf ("Account: %d Banned until: %ld\n", acc, - timestamp); - sprintf (tmpsql, - "UPDATE `%s` SET `ban_until` = '%ld', `state`='7' WHERE `%s` = '%d'", - login_db, timestamp, login_db_account_id, - acc); - // query - if (mysql_query (&mysql_handle, tmpsql)) - { - printf ("DB server Error - %s\n", - mysql_error (&mysql_handle)); - } - } - } - RFIFOSKIP (fd, 18); - break; - } - return 0; - - case 0x2727: - if (RFIFOREST (fd) < 6) - return 0; - { - int acc, sex; - unsigned char buf[16]; - acc = RFIFOL (fd, 4); - sprintf (tmpsql, - "SELECT `sex` FROM `%s` WHERE `%s` = '%d'", - login_db, login_db_account_id, acc); - - if (mysql_query (&mysql_handle, tmpsql)) - { - printf ("DB server Error - %s\n", - mysql_error (&mysql_handle)); - return 0; - } - - sql_res = mysql_store_result (&mysql_handle); - - if (sql_res) - { - if (mysql_num_rows (sql_res) == 0) - { - mysql_free_result (sql_res); - return 0; - } - sql_row = mysql_fetch_row (sql_res); //row fetching - } - - if (strcmpi (sql_row[0], "M") == 0) - sex = 1; - else - sex = 0; - sprintf (tmpsql, - "UPDATE `%s` SET `sex` = '%c' WHERE `%s` = '%d'", - login_db, (sex == 0 ? 'M' : 'F'), - login_db_account_id, acc); - //query - if (mysql_query (&mysql_handle, tmpsql)) - { - printf ("DB server Error - %s\n", - mysql_error (&mysql_handle)); - } - WBUFW (buf, 0) = 0x2723; - WBUFL (buf, 2) = acc; - WBUFB (buf, 6) = sex; - charif_sendallwos (-1, buf, 7); - RFIFOSKIP (fd, 6); - } - return 0; - - case 0x2728: // save account_reg - if (RFIFOREST (fd) < 4 || RFIFOREST (fd) < RFIFOW (fd, 2)) - return 0; - { - int acc, p, j; - char str[32]; - char temp_str[32]; - int value; - acc = RFIFOL (fd, 4); - - if (acc > 0) - { - unsigned char buf[RFIFOW (fd, 2) + 1]; - for (p = 8, j = 0; - p < RFIFOW (fd, 2) && j < ACCOUNT_REG2_NUM; - p += 36, j++) - { - memcpy (str, RFIFOP (fd, p), 32); - value = RFIFOL (fd, p + 32); - sprintf (tmpsql, - "DELETE FROM `global_reg_value` WHERE `type`='1' AND `account_id`='%d' AND `str`='%s';", - acc, jstrescapecpy (temp_str, str)); - if (mysql_query (&mysql_handle, tmpsql)) - { - printf ("DB server Error - %s\n", - mysql_error (&mysql_handle)); - } - sprintf (tmpsql, - "INSERT INTO `global_reg_value` (`type`, `account_id`, `str`, `value`) VALUES ( 1 , '%d' , '%s' , '%d');", - acc, jstrescapecpy (temp_str, str), - value); - if (mysql_query (&mysql_handle, tmpsql)) - { - printf ("DB server Error - %s\n", - mysql_error (&mysql_handle)); - } - } - - // Send to char - memcpy (WBUFP (buf, 0), RFIFOP (fd, 0), - RFIFOW (fd, 2)); - WBUFW (buf, 0) = 0x2729; - charif_sendallwos (fd, buf, WBUFW (buf, 2)); - } - } - RFIFOSKIP (fd, RFIFOW (fd, 2)); - //printf("login: save account_reg (from char)\n"); - break; - - case 0x272a: // Receiving of map-server via char-server a unban resquest (by Yor) - if (RFIFOREST (fd) < 6) - return 0; - { - int acc; - acc = RFIFOL (fd, 2); - sprintf (tmpsql, - "SELECT `ban_until` FROM `%s` WHERE `%s` = '%d'", - login_db, login_db_account_id, acc); - if (mysql_query (&mysql_handle, tmpsql)) - { - printf ("DB server Error - %s\n", - mysql_error (&mysql_handle)); - } - sql_res = mysql_store_result (&mysql_handle); - if (sql_res) - { - sql_row = mysql_fetch_row (sql_res); //row fetching - } - if (atol (sql_row[0]) != 0) - { - sprintf (tmpsql, - "UPDATE `%s` SET `ban_until` = '0', `state`='0' WHERE `%s` = '%d'", - login_db, login_db_account_id, acc); - //query - if (mysql_query (&mysql_handle, tmpsql)) - { - printf ("DB server Error - %s\n", - mysql_error (&mysql_handle)); - } - break; - } - RFIFOSKIP (fd, 6); - } - return 0; - - default: - printf ("login: unknown packet %x! (from char).\n", - RFIFOW (fd, 0)); - session[fd]->eof = 1; - return 0; - } - } - - return 0; -} - -//Lan ip check added by Kashy -int lan_ip_check (unsigned char *p) -{ - int y; - int lancheck = 1; - int lancharip[4]; - - unsigned int k0, k1, k2, k3; - sscanf (lan_char_ip, "%d.%d.%d.%d", &k0, &k1, &k2, &k3); - lancharip[0] = k0; - lancharip[1] = k1; - lancharip[2] = k2; - lancharip[3] = k3; - - for (y = 0; y < 4; y++) - { - if ((lancharip[y] & subnetmaski[y]) != (p[y])) - lancheck = 0; - break; - } - - printf ("LAN check: %s.\n", - (lancheck) ? "\033[1;32mLAN\033[0m" : "\033[1;31mWAN\033[0m"); - return lancheck; -} - -//---------------------------------------------------------------------------------------- -// Default packet parsing (normal players or administation/char-server connection requests) -//---------------------------------------------------------------------------------------- -int parse_login (int fd) -{ - //int len; - - MYSQL_RES *sql_res; - MYSQL_ROW sql_row = NULL; - - char t_uid[100]; - //int sql_fields, sql_cnt; - struct mmo_account account; - - int result, i; - unsigned char *p = (unsigned char *) &session[fd]->client_addr.sin_addr; - char ip[16]; - - sprintf (ip, "%d.%d.%d.%d", p[0], p[1], p[2], p[3]); - - if (ipban > 0) - { - //ip ban - //p[0], p[1], p[2], p[3] - //request DB connection - //check - sprintf (tmpsql, - "SELECT count(*) FROM `ipbanlist` WHERE `list` = '%d.*.*.*' OR `list` = '%d.%d.*.*' OR `list` = '%d.%d.%d.*' OR `list` = '%d.%d.%d.%d'", - p[0], p[0], p[1], p[0], p[1], p[2], p[0], p[1], p[2], p[3]); - if (mysql_query (&mysql_handle, tmpsql)) - { - printf ("DB server Error - %s\n", mysql_error (&mysql_handle)); - } - - sql_res = mysql_store_result (&mysql_handle); - sql_row = mysql_fetch_row (sql_res); //row fetching - - if (atoi (sql_row[0]) > 0) - { - // ip ban ok. - printf ("packet from banned ip : %d.%d.%d.%d" RETCODE, p[0], p[1], - p[2], p[3]); - sprintf (tmpsql, - "INSERT INTO `%s`(`time`,`ip`,`user`,`rcode`,`log`) VALUES (NOW(), '%d.%d.%d.%d', 'unknown','-3', 'ip banned')", - loginlog_db, p[0], p[1], p[2], p[3]); - - // query - if (mysql_query (&mysql_handle, tmpsql)) - { - printf ("DB server Error - %s\n", - mysql_error (&mysql_handle)); - } - printf ("close session connection...\n"); - - // close connection - session[fd]->eof = 1; - - } - else - { - printf ("packet from ip (ban check ok) : %d.%d.%d.%d" RETCODE, - p[0], p[1], p[2], p[3]); - } - mysql_free_result (sql_res); - } - - if (session[fd]->eof) - { - for (i = 0; i < MAX_SERVERS; i++) - if (server_fd[i] == fd) - server_fd[i] = -1; - close (fd); - delete_session (fd); - return 0; - } - - while (RFIFOREST (fd) >= 2) - { - printf ("parse_login : %d %d packet case=%x\n", fd, RFIFOREST (fd), - RFIFOW (fd, 0)); - - switch (RFIFOW (fd, 0)) - { - case 0x200: // New alive packet: structure: 0x200 .24B. used to verify if client is always alive. - if (RFIFOREST (fd) < 26) - return 0; - RFIFOSKIP (fd, 26); - break; - - case 0x204: // New alive packet: structure: 0x204 .16B. (new ragexe from 22 june 2004) - if (RFIFOREST (fd) < 18) - return 0; - RFIFOSKIP (fd, 18); - break; - - case 0x64: // request client login - case 0x01dd: // request client login with encrypt - if (RFIFOREST (fd) < ((RFIFOW (fd, 0) == 0x64) ? 55 : 47)) - return 0; - - printf ("client connection request %s from %d.%d.%d.%d\n", - RFIFOP (fd, 6), p[0], p[1], p[2], p[3]); - - account.userid = RFIFOP (fd, 6); - account.passwd = RFIFOP (fd, 30); -#ifdef PASSWORDENC - account.passwdenc = - (RFIFOW (fd, 0) == 0x64) ? 0 : PASSWORDENC; -#else - account.passwdenc = 0; -#endif - result = mmo_auth (&account, fd); - - jstrescapecpy (t_uid, RFIFOP (fd, 6)); - if (result == -1) - { - int gm_level = isGM (account.account_id); - if (min_level_to_connect > gm_level) - { - WFIFOW (fd, 0) = 0x81; - WFIFOL (fd, 2) = 1; // 01 = Server closed - WFIFOSET (fd, 3); - } - else - { - if (p[0] != 127) - { - sprintf (tmpsql, - "INSERT INTO `%s`(`time`,`ip`,`user`,`rcode`,`log`) VALUES (NOW(), '%d.%d.%d.%d', '%s','100', 'login ok')", - loginlog_db, p[0], p[1], p[2], p[3], - t_uid); - //query - if (mysql_query (&mysql_handle, tmpsql)) - { - printf ("DB server Error - %s\n", - mysql_error (&mysql_handle)); - } - } - if (gm_level) - printf - ("Connection of the GM (level:%d) account '%s' accepted.\n", - gm_level, account.userid); - else - printf - ("Connection of the account '%s' accepted.\n", - account.userid); - server_num = 0; - for (i = 0; i < MAX_SERVERS; i++) - { - if (server_fd[i] >= 0) - { - //Lan check added by Kashy - if (lan_ip_check (p)) - WFIFOL (fd, 47 + server_num * 32) = - inet_addr (lan_char_ip); - else - WFIFOL (fd, 47 + server_num * 32) = - server[i].ip; - WFIFOW (fd, 47 + server_num * 32 + 4) = - server[i].port; - memcpy (WFIFOP (fd, 47 + server_num * 32 + 6), - server[i].name, 20); - WFIFOW (fd, 47 + server_num * 32 + 26) = - server[i].users; - WFIFOW (fd, 47 + server_num * 32 + 28) = - server[i].maintenance; - WFIFOW (fd, 47 + server_num * 32 + 30) = - server[i].new; - server_num++; - } - } - // if at least 1 char-server - if (server_num > 0) - { - WFIFOW (fd, 0) = 0x69; - WFIFOW (fd, 2) = 47 + 32 * server_num; - WFIFOL (fd, 4) = account.login_id1; - WFIFOL (fd, 8) = account.account_id; - WFIFOL (fd, 12) = account.login_id2; - WFIFOL (fd, 16) = 0; - memcpy (WFIFOP (fd, 20), account.lastlogin, 24); - WFIFOB (fd, 46) = account.sex; - WFIFOSET (fd, 47 + 32 * server_num); - if (auth_fifo_pos >= AUTH_FIFO_SIZE) - auth_fifo_pos = 0; - auth_fifo[auth_fifo_pos].account_id = - account.account_id; - auth_fifo[auth_fifo_pos].login_id1 = - account.login_id1; - auth_fifo[auth_fifo_pos].login_id2 = - account.login_id2; - auth_fifo[auth_fifo_pos].sex = account.sex; - auth_fifo[auth_fifo_pos].delflag = 0; - auth_fifo[auth_fifo_pos].ip = - session[fd]->client_addr.sin_addr.s_addr; - auth_fifo_pos++; - } - else - { - WFIFOW (fd, 0) = 0x81; - WFIFOL (fd, 2) = 1; // 01 = Server closed - WFIFOSET (fd, 3); - } - } - } - else - { - char tmp_sql[512]; - char error[64]; - sprintf (tmp_sql, - "INSERT INTO `%s`(`time`,`ip`,`user`,`rcode`,`log`) VALUES (NOW(), '%d.%d.%d.%d', '%s', '%d','login failed : %%s')", - loginlog_db, p[0], p[1], p[2], p[3], t_uid, - result); - switch ((result + 1)) - { - case -2: //-3 = Account Banned - sprintf (tmpsql, tmp_sql, "Account banned."); - sprintf (error, "Account banned."); - break; - case -1: //-2 = Dynamic Ban - sprintf (tmpsql, tmp_sql, - "dynamic ban (ip and account)."); - sprintf (error, "dynamic ban (ip and account)."); - break; - case 1: // 0 = Unregistered ID - sprintf (tmpsql, tmp_sql, "Unregisterd ID."); - sprintf (error, "Unregisterd ID."); - break; - case 2: // 1 = Incorrect Password - sprintf (tmpsql, tmp_sql, "Incorrect Password."); - sprintf (error, "Incorrect Password."); - break; - case 3: // 2 = This ID is expired - sprintf (tmpsql, tmp_sql, "Account Expired."); - sprintf (error, "Account Expired."); - break; - case 4: // 3 = Rejected from Server - sprintf (tmpsql, tmp_sql, - "Rejected from server."); - sprintf (error, "Rejected from server."); - break; - case 5: // 4 = You have been blocked by the GM Team - sprintf (tmpsql, tmp_sql, "Blocked by GM."); - sprintf (error, "Blocked by GM."); - break; - case 6: // 5 = Your Game's EXE file is not the latest version - sprintf (tmpsql, tmp_sql, "Not latest game EXE."); - sprintf (error, "Not latest game EXE."); - break; - case 7: // 6 = Your are Prohibited to log in until %s - sprintf (tmpsql, tmp_sql, "Banned."); - sprintf (error, "Banned."); - break; - case 8: // 7 = Server is jammed due to over populated - sprintf (tmpsql, tmp_sql, - "Server Over-population."); - sprintf (error, "Server Over-population."); - break; - case 9: // 8 = No MSG (actually, all states after 9 except 99 are No MSG, use only this) - sprintf (tmpsql, tmp_sql, " "); - sprintf (error, " "); - break; - case 100: // 99 = This ID has been totally erased - sprintf (tmpsql, tmp_sql, "Account gone."); - sprintf (error, "Account gone."); - break; - default: - sprintf (tmpsql, tmp_sql, "Uknown Error."); - sprintf (error, "Uknown Error."); - break; - } - //query - if (mysql_query (&mysql_handle, tmpsql)) - { - printf ("DB server Error - %s\n", - mysql_error (&mysql_handle)); - } - if ((result == 1) && (dynamic_pass_failure_ban != 0)) - { // failed password - sprintf (tmpsql, "SELECT count(*) FROM `%s` WHERE `ip` = '%d.%d.%d.%d' AND `rcode` = '1' AND `time` > NOW() - INTERVAL %d MINUTE", loginlog_db, p[0], p[1], p[2], p[3], dynamic_pass_failure_ban_time); //how many times filed account? in one ip. - if (mysql_query (&mysql_handle, tmpsql)) - { - printf ("DB server Error - %s\n", - mysql_error (&mysql_handle)); - } - //check query result - sql_res = mysql_store_result (&mysql_handle); - sql_row = mysql_fetch_row (sql_res); //row fetching - - if (atoi (sql_row[0]) >= - dynamic_pass_failure_ban_how_many) - { - sprintf (tmpsql, - "INSERT INTO `ipbanlist`(`list`,`btime`,`rtime`,`reason`) VALUES ('%d.%d.%d.*', NOW() , NOW() + INTERVAL %d MINUTE ,'Password error ban: %s')", - p[0], p[1], p[2], - dynamic_pass_failure_ban_how_long, - t_uid); - if (mysql_query (&mysql_handle, tmpsql)) - { - printf ("DB server Error - %s\n", - mysql_error (&mysql_handle)); - } - } - mysql_free_result (sql_res); - } - else if (result == -2) - { //dynamic banned - add ip to ban list. - sprintf (tmpsql, - "INSERT INTO `ipbanlist`(`list`,`btime`,`rtime`,`reason`) VALUES ('%d.%d.%d.*', NOW() , NOW() + INTERVAL 1 MONTH ,'Dynamic banned user id : %s')", - p[0], p[1], p[2], t_uid); - if (mysql_query (&mysql_handle, tmpsql)) - { - printf ("DB server Error - %s\n", - mysql_error (&mysql_handle)); - } - result = -3; - } - - sprintf (tmpsql, - "SELECT `ban_until` FROM `%s` WHERE `%s` = '%s'", - login_db, login_db_userid, t_uid); - if (mysql_query (&mysql_handle, tmpsql)) - { - printf ("DB server Error - %s\n", - mysql_error (&mysql_handle)); - } - sql_res = mysql_store_result (&mysql_handle); - if (sql_res) - { - sql_row = mysql_fetch_row (sql_res); //row fetching - } - //cannot connect login failed - memset (WFIFOP (fd, 0), '\0', 23); - WFIFOW (fd, 0) = 0x6a; - WFIFOB (fd, 2) = result; - if (result == 6) - { // 6 = Your are Prohibited to log in until %s - if (atol (sql_row[0]) != 0) - { // if account is banned, we send ban timestamp - char tmpstr[256]; - time_t ban_until_time; - ban_until_time = atol (sql_row[0]); - strftime (tmpstr, 20, date_format, - gmtime (&ban_until_time)); - tmpstr[19] = '\0'; - memcpy (WFIFOP (fd, 3), tmpstr, 20); - } - else - { // we send error message - memcpy (WFIFOP (fd, 3), error, 20); - } - } - WFIFOSET (fd, 23); - } - RFIFOSKIP (fd, (RFIFOW (fd, 0) == 0x64) ? 55 : 47); - break; - - case 0x01db: // request password key - if (session[fd]->session_data) - { - printf - ("login: abnormal request of MD5 key (already opened session).\n"); - session[fd]->eof = 1; - return 0; - } - printf ("Request Password key -%s\n", md5key); - RFIFOSKIP (fd, 2); - WFIFOW (fd, 0) = 0x01dc; - WFIFOW (fd, 2) = 4 + md5keylen; - memcpy (WFIFOP (fd, 4), md5key, md5keylen); - WFIFOSET (fd, WFIFOW (fd, 2)); - break; - - case 0x2710: // request Char-server connection - if (RFIFOREST (fd) < 86) - return 0; - { - sprintf (tmpsql, - "INSERT INTO `%s`(`time`,`ip`,`user`,`rcode`,`log`) VALUES (NOW(), '%d.%d.%d.%d', '%s@%s','100', 'charserver - %s@%d.%d.%d.%d:%d')", - loginlog_db, p[0], p[1], p[2], p[3], RFIFOP (fd, - 2), - RFIFOP (fd, 60), RFIFOP (fd, 60), RFIFOB (fd, - 54), - RFIFOB (fd, 55), RFIFOB (fd, 56), RFIFOB (fd, - 57), - RFIFOW (fd, 58)); - - //query - if (mysql_query (&mysql_handle, tmpsql)) - { - printf ("DB server Error - %s\n", - mysql_error (&mysql_handle)); - } - printf - ("server connection request %s @ %d.%d.%d.%d:%d (%d.%d.%d.%d)\n", - RFIFOP (fd, 60), RFIFOB (fd, 54), RFIFOB (fd, 55), - RFIFOB (fd, 56), RFIFOB (fd, 57), RFIFOW (fd, 58), - p[0], p[1], p[2], p[3]); - unsigned char *server_name; - account.userid = RFIFOP (fd, 2); - account.passwd = RFIFOP (fd, 26); - account.passwdenc = 0; - server_name = RFIFOP (fd, 60); - result = mmo_auth (&account, fd); - //printf("Result: %d - Sex: %d - Account ID: %d\n",result,account.sex,(int) account.account_id); - - if (result == -1 && account.sex == 2 - && account.account_id < MAX_SERVERS - && server_fd[account.account_id] == -1) - { - printf - ("Connection of the char-server '%s' accepted.\n", - server_name); - memset (&server[account.account_id], 0, - sizeof (struct mmo_char_server)); - server[account.account_id].ip = RFIFOL (fd, 54); - server[account.account_id].port = RFIFOW (fd, 58); - memcpy (server[account.account_id].name, - RFIFOP (fd, 60), 20); - server[account.account_id].users = 0; - server[account.account_id].maintenance = - RFIFOW (fd, 82); - server[account.account_id].new = RFIFOW (fd, 84); - server_fd[account.account_id] = fd; - if (anti_freeze_enable) - server_freezeflag[account.account_id] = 5; // Char-server anti-freeze system. Counter. 5 ok, 4...0 freezed - sprintf (tmpsql, - "DELETE FROM `sstatus` WHERE `index`='%ld'", - account.account_id); - //query - if (mysql_query (&mysql_handle, tmpsql)) - { - printf ("DB server Error - %s\n", - mysql_error (&mysql_handle)); - } - - jstrescapecpy (t_uid, - server[account.account_id].name); - sprintf (tmpsql, - "INSERT INTO `sstatus`(`index`,`name`,`user`) VALUES ( '%ld', '%s', '%d')", - account.account_id, - server[account.account_id].name, 0); - //query - if (mysql_query (&mysql_handle, tmpsql)) - { - printf ("DB server Error - %s\n", - mysql_error (&mysql_handle)); - } - WFIFOW (fd, 0) = 0x2711; - WFIFOB (fd, 2) = 0; - WFIFOSET (fd, 3); - session[fd]->func_parse = parse_fromchar; - realloc_fifo (fd, FIFOSIZE_SERVERLINK, - FIFOSIZE_SERVERLINK); - } - else - { - WFIFOW (fd, 0) = 0x2711; - WFIFOB (fd, 2) = 3; - WFIFOSET (fd, 3); - } - } - RFIFOSKIP (fd, 86); - return 0; - - case 0x7530: // request Athena information - WFIFOW (fd, 0) = 0x7531; - WFIFOB (fd, 2) = ATHENA_MAJOR_VERSION; - WFIFOB (fd, 3) = ATHENA_MINOR_VERSION; - WFIFOB (fd, 4) = ATHENA_REVISION; - WFIFOB (fd, 5) = ATHENA_RELEASE_FLAG; - WFIFOB (fd, 6) = ATHENA_OFFICIAL_FLAG; - WFIFOB (fd, 7) = ATHENA_SERVER_LOGIN; - WFIFOW (fd, 8) = ATHENA_MOD_VERSION; - WFIFOSET (fd, 10); - RFIFOSKIP (fd, 2); - printf ("Athena version check...\n"); - break; - - case 0x7532: - default: - printf ("End of connection (ip: %s)" RETCODE, ip); - session[fd]->eof = 1; - return 0; - } - } - - return 0; -} - -//------------------------------------------------- -// Return numerical value of a switch configuration -// on/off, english, fran軋is, deutsch, espal -//------------------------------------------------- -int config_switch (const char *str) -{ - if (strcmpi (str, "on") == 0 || strcmpi (str, "yes") == 0 - || strcmpi (str, "oui") == 0 || strcmpi (str, "ja") == 0 - || strcmpi (str, "si") == 0) - return 1; - if (strcmpi (str, "off") == 0 || strcmpi (str, "no") == 0 - || strcmpi (str, "non") == 0 || strcmpi (str, "nein") == 0) - return 0; - - return atoi (str); -} - -//Lan Support conf reading added by Kashy -int login_lan_config_read (const char *lancfgName) -{ - int i; - char subnetmask[128]; - char line[1024], w1[1024], w2[1024]; - FILE *fp; - - fp = fopen_ (lancfgName, "r"); - - if (fp == NULL) - { - printf ("file not found: %s\n", lancfgName); - return 1; - } - printf ("Start reading of Lan Support configuration file\n"); - while (fgets (line, sizeof (line) - 1, fp)) - { - if (line[0] == '/' && line[1] == '/') - continue; - - i = sscanf (line, "%[^:]: %[^\r\n]", w1, w2); - if (i != 2) - continue; - - else if (strcmpi (w1, "lan_char_ip") == 0) - { - strcpy (lan_char_ip, w2); - printf ("set Lan_Char_IP : %s\n", w2); - } - - else if (strcmpi (w1, "subnetmask") == 0) - { - strcpy (subnetmask, w2); - unsigned int k0, k1, k2, k3; - sscanf (subnetmask, "%d.%d.%d.%d", &k0, &k1, &k2, &k3); - subnetmaski[0] = k0; - subnetmaski[1] = k1; - subnetmaski[2] = k2; - subnetmaski[3] = k3; - printf ("set subnetmask : %s\n", w2); - } - } - fclose_ (fp); - - { - unsigned int a0, a1, a2, a3; - unsigned char p[4]; - sscanf (lan_char_ip, "%d.%d.%d.%d", &a0, &a1, &a2, &a3); - p[0] = a0; - p[1] = a1; - p[2] = a2; - p[3] = a3; - printf ("LAN test of LAN IP of the char-server: "); - if (lan_ip_check (p) == 0) - { - printf - ("\033[1;31m***ERROR: LAN IP of the char-server doesn't belong to the specified Sub-network\033[0m\n"); - } - } - - printf ("End reading of Lan Support configuration file\n"); - - return 0; -} - -//----------------------------------------------------- -//BANNED IP CHECK. -//----------------------------------------------------- -int ip_ban_check (int tid, unsigned int tick, int id, int data) -{ - - //query - if (mysql_query - (&mysql_handle, "DELETE FROM `ipbanlist` WHERE `rtime` <= NOW()")) - { - printf ("DB server Error - %s\n", mysql_error (&mysql_handle)); - } - - return 0; -} - -//----------------------------------------------------- -// reading configuration -//----------------------------------------------------- -int login_config_read (const char *cfgName) -{ - int i; - char line[1024], w1[1024], w2[1024]; - FILE *fp; - - fp = fopen_ (cfgName, "r"); - - if (fp == NULL) - { - printf ("Configuration file (%s) not found.\n", cfgName); - return 1; - } - printf ("start reading configuration...\n"); - while (fgets (line, sizeof (line) - 1, fp)) - { - if (line[0] == '/' && line[1] == '/') - continue; - - i = sscanf (line, "%[^:]: %[^\r\n]", w1, w2); - if (i != 2) - continue; - - else if (strcmpi (w1, "login_port") == 0) - { - login_port = atoi (w2); - printf ("set login_port : %s\n", w2); - } - else if (strcmpi (w1, "ipban") == 0) - { - ipban = atoi (w2); - printf ("set ipban : %d\n", ipban); - } - //account ban -> ip ban - else if (strcmpi (w1, "dynamic_account_ban") == 0) - { - dynamic_account_ban = atoi (w2); - printf ("set dynamic_account_ban : %d\n", dynamic_account_ban); - } - else if (strcmpi (w1, "dynamic_account_ban_class") == 0) - { - dynamic_account_ban_class = atoi (w2); - printf ("set dynamic_account_ban_class : %d\n", - dynamic_account_ban_class); - } - //dynamic password error ban - else if (strcmpi (w1, "dynamic_pass_failure_ban") == 0) - { - dynamic_pass_failure_ban = atoi (w2); - printf ("set dynamic_pass_failure_ban : %d\n", - dynamic_pass_failure_ban); - } - else if (strcmpi (w1, "dynamic_pass_failure_ban_time") == 0) - { - dynamic_pass_failure_ban_time = atoi (w2); - printf ("set dynamic_pass_failure_ban_time : %d\n", - dynamic_pass_failure_ban_time); - } - else if (strcmpi (w1, "dynamic_pass_failure_ban_how_many") == 0) - { - dynamic_pass_failure_ban_how_many = atoi (w2); - printf ("set dynamic_pass_failure_ban_how_many : %d\n", - dynamic_pass_failure_ban_how_many); - } - else if (strcmpi (w1, "dynamic_pass_failure_ban_how_long") == 0) - { - dynamic_pass_failure_ban_how_long = atoi (w2); - printf ("set dynamic_pass_failure_ban_how_long : %d\n", - dynamic_pass_failure_ban_how_long); - } - else if (strcmpi (w1, "anti_freeze_enable") == 0) - { - anti_freeze_enable = config_switch (w2); - } - else if (strcmpi (w1, "anti_freeze_interval") == 0) - { - ANTI_FREEZE_INTERVAL = atoi (w2); - if (ANTI_FREEZE_INTERVAL < 5) - ANTI_FREEZE_INTERVAL = 5; // minimum 5 seconds - } - else if (strcmpi (w1, "import") == 0) - { - login_config_read (w2); - } - else if (strcmpi (w1, "use_MD5_passwords") == 0) - { - if (!strcmpi (w2, "yes")) - { - use_md5_passwds = 1; - } - else if (!strcmpi (w2, "no")) - { - use_md5_passwds = 0; - } - printf ("Using MD5 Passwords: %s \n", w2); - } - else if (strcmpi (w1, "date_format") == 0) - { // note: never have more than 19 char for the date! - switch (atoi (w2)) - { - case 0: - strcpy (date_format, "%d-%m-%Y %H:%M:%S"); // 31-12-2004 23:59:59 - break; - case 1: - strcpy (date_format, "%m-%d-%Y %H:%M:%S"); // 12-31-2004 23:59:59 - break; - case 2: - strcpy (date_format, "%Y-%d-%m %H:%M:%S"); // 2004-31-12 23:59:59 - break; - case 3: - strcpy (date_format, "%Y-%m-%d %H:%M:%S"); // 2004-12-31 23:59:59 - break; - } - } - else if (strcmpi (w1, "min_level_to_connect") == 0) - { - min_level_to_connect = atoi (w2); - } - else if (strcmpi (w1, "check_ip_flag") == 0) - { - check_ip_flag = config_switch (w2); - } - } - fclose_ (fp); - printf ("End reading configuration...\n"); - return 0; -} - -void sql_config_read (const char *cfgName) -{ /* Kalaspuff, to get login_db */ - int i; - char line[1024], w1[1024], w2[1024]; - printf ("reading configure: %s\n", cfgName); - FILE *fp = fopen_ (cfgName, "r"); - if (fp == NULL) - { - printf ("file not found: %s\n", cfgName); - exit (1); - } - while (fgets (line, sizeof (line) - 1, fp)) - { - if (line[0] == '/' && line[1] == '/') - continue; - i = sscanf (line, "%[^:]: %[^\r\n]", w1, w2); - if (i != 2) - continue; - if (strcmpi (w1, "login_db") == 0) - { - strcpy (login_db, w2); - } - //add for DB connection - else if (strcmpi (w1, "login_server_ip") == 0) - { - strcpy (login_server_ip, w2); - printf ("set login_server_ip : %s\n", w2); - } - else if (strcmpi (w1, "login_server_port") == 0) - { - login_server_port = atoi (w2); - printf ("set login_server_port : %s\n", w2); - } - else if (strcmpi (w1, "login_server_id") == 0) - { - strcpy (login_server_id, w2); - printf ("set login_server_id : %s\n", w2); - } - else if (strcmpi (w1, "login_server_pw") == 0) - { - strcpy (login_server_pw, w2); - printf ("set login_server_pw : %s\n", w2); - } - else if (strcmpi (w1, "login_server_db") == 0) - { - strcpy (login_server_db, w2); - printf ("set login_server_db : %s\n", w2); - } - //added for custom column names for custom login table - else if (strcmpi (w1, "login_db_account_id") == 0) - { - strcpy (login_db_account_id, w2); - } - else if (strcmpi (w1, "login_db_userid") == 0) - { - strcpy (login_db_userid, w2); - } - else if (strcmpi (w1, "login_db_user_pass") == 0) - { - strcpy (login_db_user_pass, w2); - } - else if (strcmpi (w1, "login_db_level") == 0) - { - strcpy (login_db_level, w2); - } - //end of custom table config - else if (strcmpi (w1, "loginlog_db") == 0) - { - strcpy (loginlog_db, w2); - } - } - fclose_ (fp); - printf ("reading configure done.....\n"); -} - -int do_init (int argc, char **argv) -{ - //initialize login server - int i; - - //read login configue - login_config_read ((argc > 1) ? argv[1] : LOGIN_CONF_NAME); - sql_config_read (SQL_CONF_NAME); - login_lan_config_read ((argc > 1) ? argv[1] : LAN_CONF_NAME); - //Generate Passworded Key. - printf ("memset md5key \n"); - memset (md5key, 0, sizeof (md5key)); - printf ("memset md5key complete\n"); - printf ("memset keyleng\n"); - md5keylen = rand () % 4 + 12; - for (i = 0; i < md5keylen; i++) - md5key[i] = rand () % 255 + 1; - printf ("memset keyleng complete\n"); - - printf ("set FIFO Size\n"); - for (i = 0; i < AUTH_FIFO_SIZE; i++) - auth_fifo[i].delflag = 1; - printf ("set FIFO Size complete\n"); - - printf ("set max servers\n"); - for (i = 0; i < MAX_SERVERS; i++) - server_fd[i] = -1; - printf ("set max servers complete\n"); - //server port open & binding - - login_fd = make_listen_port (login_port); - - //Auth start - printf ("Running mmo_auth_sqldb_init()\n"); - mmo_auth_sqldb_init (); - printf ("finished mmo_auth_sqldb_init()\n"); - //sync account when terminating. - //but no need when you using DBMS (mysql) - set_termfunc (mmo_db_close); - - //set default parser as parse_login function - set_defaultparse (parse_login); - - if (anti_freeze_enable > 0) - { - add_timer_func_list (char_anti_freeze_system, - "char_anti_freeze_system"); - i = add_timer_interval (gettick () + 1000, char_anti_freeze_system, 0, - 0, ANTI_FREEZE_INTERVAL * 1000); - } - - // ban deleter timer - 1 minute term - printf ("add interval tic (ip_ban_check)....\n"); - i = add_timer_interval (gettick () + 10, ip_ban_check, 0, 0, 60 * 1000); - - printf - ("The login-server is \033[1;32mready\033[0m (Server is listening on the port %d).\n\n", - login_port); - - return 0; -} diff --git a/src/login_sql/login.h b/src/login_sql/login.h deleted file mode 100644 index 7eb3a84..0000000 --- a/src/login_sql/login.h +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef _LOGIN_H_ -#define _LOGIN_H_ - -#define MAX_SERVERS 30 - -#define LOGIN_CONF_NAME "conf/login_athena.conf" -#define SQL_CONF_NAME "conf/inter_athena.conf" -#define LAN_CONF_NAME "conf/lan_support.conf" - -#define PASSWORDENC 3 // A definition is given when making an encryption password correspond. - // It is 1 at the time of passwordencrypt. - // It is made into 2 at the time of passwordencrypt2. - // When it is made 3, it corresponds to both. - -#define START_ACCOUNT_NUM 2000000 -#define END_ACCOUNT_NUM 100000000 - -struct mmo_account -{ - char *userid; - char *passwd; - int passwdenc; - - long account_id; - long login_id1; - long login_id2; - long char_id; - char lastlogin[24]; - int sex; -}; - -struct mmo_char_server -{ - char name[20]; - long ip; - short port; - int users; - int maintenance; - int new; -}; - -#endif diff --git a/src/login_sql/make.sh b/src/login_sql/make.sh deleted file mode 100644 index 198d33b..0000000 --- a/src/login_sql/make.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh - rsqlt=`rm -rf *.o` - gcc -c login.c -I/usr/local/include/mysql/ - gcc -c md5calc.c -I/usr/local/include/mysql/ - gcc -c strlib.c - gcc -o login-server login.o strlib.o md5calc.o ../common/core.o ../common/socket.o ../common/timer.o ../common/db.o -L/usr/local/lib/mysql/ -lmysqlclient -lz diff --git a/src/login_sql/md5calc.c b/src/login_sql/md5calc.c deleted file mode 100644 index 0f0b65d..0000000 --- a/src/login_sql/md5calc.c +++ /dev/null @@ -1,292 +0,0 @@ -/*********************************************************** - * md5 calculation algorithm - * - * The source code referred to the following URL. - * http://www.geocities.co.jp/SiliconValley-Oakland/8878/lab17/lab17.html - * - ***********************************************************/ - -#include "md5calc.h" -#include -#include - -#ifndef UINT_MAX -#define UINT_MAX 4294967295U -#endif - -// Global variable -static unsigned int *pX; - -// Stirng Table -static const unsigned int T[] = { - 0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee, //0 - 0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501, //4 - 0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be, //8 - 0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821, //12 - 0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa, //16 - 0xd62f105d, 0x2441453, 0xd8a1e681, 0xe7d3fbc8, //20 - 0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed, //24 - 0xa9e3e905, 0xfcefa3f8, 0x676f02d9, 0x8d2a4c8a, //28 - 0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c, //32 - 0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70, //36 - 0x289b7ec6, 0xeaa127fa, 0xd4ef3085, 0x4881d05, //40 - 0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665, //44 - 0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039, //48 - 0x655b59c3, 0x8f0ccc92, 0xffeff47d, 0x85845dd1, //52 - 0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1, //56 - 0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391 //60 -}; - -// ROTATE_LEFT The left is made to rotate x [ n-bit ]. This is diverted as it is from RFC. -#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) - -// The function used for other calculation -static unsigned int F (unsigned int X, unsigned int Y, unsigned int Z) -{ - return (X & Y) | (~X & Z); -} - -static unsigned int G (unsigned int X, unsigned int Y, unsigned int Z) -{ - return (X & Z) | (Y & ~Z); -} - -static unsigned int H (unsigned int X, unsigned int Y, unsigned int Z) -{ - return X ^ Y ^ Z; -} - -static unsigned int I (unsigned int X, unsigned int Y, unsigned int Z) -{ - return Y ^ (X | ~Z); -} - -static unsigned int Round (unsigned int a, unsigned int b, unsigned int FGHI, - unsigned int k, unsigned int s, unsigned int i) -{ - return b + ROTATE_LEFT (a + FGHI + pX[k] + T[i], s); -} - -static void Round1 (unsigned int *a, unsigned int b, unsigned int c, - unsigned int d, unsigned int k, unsigned int s, - unsigned int i) -{ - *a = Round (*a, b, F (b, c, d), k, s, i); -} - -static void Round2 (unsigned int *a, unsigned int b, unsigned int c, - unsigned int d, unsigned int k, unsigned int s, - unsigned int i) -{ - *a = Round (*a, b, G (b, c, d), k, s, i); -} - -static void Round3 (unsigned int *a, unsigned int b, unsigned int c, - unsigned int d, unsigned int k, unsigned int s, - unsigned int i) -{ - *a = Round (*a, b, H (b, c, d), k, s, i); -} - -static void Round4 (unsigned int *a, unsigned int b, unsigned int c, - unsigned int d, unsigned int k, unsigned int s, - unsigned int i) -{ - *a = Round (*a, b, I (b, c, d), k, s, i); -} - -static void MD5_Round_Calculate (const unsigned char *block, - unsigned int *A2, unsigned int *B2, - unsigned int *C2, unsigned int *D2) -{ - //create X It is since it is required. - unsigned int X[16]; //512bit 64byte - int j, k; - - //Save A as AA, B as BB, C as CC, and and D as DD (saving of A, B, C, and D) - unsigned int A = *A2, B = *B2, C = *C2, D = *D2; - unsigned int AA = A, BB = B, CC = C, DD = D; - - //It is a large region variable reluctantly because of calculation of a round. . . for Round1...4 - pX = X; - - //Copy block(padding_message) i into X - for (j = 0, k = 0; j < 64; j += 4, k++) - X[k] = ((unsigned int) block[j]) // 8byte*4 -> 32byte conversion - | (((unsigned int) block[j + 1]) << 8) // A function called Decode as used in the field of RFC - | (((unsigned int) block[j + 2]) << 16) - | (((unsigned int) block[j + 3]) << 24); - - //Round 1 - Round1 (&A, B, C, D, 0, 7, 0); - Round1 (&D, A, B, C, 1, 12, 1); - Round1 (&C, D, A, B, 2, 17, 2); - Round1 (&B, C, D, A, 3, 22, 3); - Round1 (&A, B, C, D, 4, 7, 4); - Round1 (&D, A, B, C, 5, 12, 5); - Round1 (&C, D, A, B, 6, 17, 6); - Round1 (&B, C, D, A, 7, 22, 7); - Round1 (&A, B, C, D, 8, 7, 8); - Round1 (&D, A, B, C, 9, 12, 9); - Round1 (&C, D, A, B, 10, 17, 10); - Round1 (&B, C, D, A, 11, 22, 11); - Round1 (&A, B, C, D, 12, 7, 12); - Round1 (&D, A, B, C, 13, 12, 13); - Round1 (&C, D, A, B, 14, 17, 14); - Round1 (&B, C, D, A, 15, 22, 15); - - //Round 2 - Round2 (&A, B, C, D, 1, 5, 16); - Round2 (&D, A, B, C, 6, 9, 17); - Round2 (&C, D, A, B, 11, 14, 18); - Round2 (&B, C, D, A, 0, 20, 19); - Round2 (&A, B, C, D, 5, 5, 20); - Round2 (&D, A, B, C, 10, 9, 21); - Round2 (&C, D, A, B, 15, 14, 22); - Round2 (&B, C, D, A, 4, 20, 23); - Round2 (&A, B, C, D, 9, 5, 24); - Round2 (&D, A, B, C, 14, 9, 25); - Round2 (&C, D, A, B, 3, 14, 26); - Round2 (&B, C, D, A, 8, 20, 27); - Round2 (&A, B, C, D, 13, 5, 28); - Round2 (&D, A, B, C, 2, 9, 29); - Round2 (&C, D, A, B, 7, 14, 30); - Round2 (&B, C, D, A, 12, 20, 31); - - //Round 3 - Round3 (&A, B, C, D, 5, 4, 32); - Round3 (&D, A, B, C, 8, 11, 33); - Round3 (&C, D, A, B, 11, 16, 34); - Round3 (&B, C, D, A, 14, 23, 35); - Round3 (&A, B, C, D, 1, 4, 36); - Round3 (&D, A, B, C, 4, 11, 37); - Round3 (&C, D, A, B, 7, 16, 38); - Round3 (&B, C, D, A, 10, 23, 39); - Round3 (&A, B, C, D, 13, 4, 40); - Round3 (&D, A, B, C, 0, 11, 41); - Round3 (&C, D, A, B, 3, 16, 42); - Round3 (&B, C, D, A, 6, 23, 43); - Round3 (&A, B, C, D, 9, 4, 44); - Round3 (&D, A, B, C, 12, 11, 45); - Round3 (&C, D, A, B, 15, 16, 46); - Round3 (&B, C, D, A, 2, 23, 47); - - //Round 4 - Round4 (&A, B, C, D, 0, 6, 48); - Round4 (&D, A, B, C, 7, 10, 49); - Round4 (&C, D, A, B, 14, 15, 50); - Round4 (&B, C, D, A, 5, 21, 51); - Round4 (&A, B, C, D, 12, 6, 52); - Round4 (&D, A, B, C, 3, 10, 53); - Round4 (&C, D, A, B, 10, 15, 54); - Round4 (&B, C, D, A, 1, 21, 55); - Round4 (&A, B, C, D, 8, 6, 56); - Round4 (&D, A, B, C, 15, 10, 57); - Round4 (&C, D, A, B, 6, 15, 58); - Round4 (&B, C, D, A, 13, 21, 59); - Round4 (&A, B, C, D, 4, 6, 60); - Round4 (&D, A, B, C, 11, 10, 61); - Round4 (&C, D, A, B, 2, 15, 62); - Round4 (&B, C, D, A, 9, 21, 63); - - // Then perform the following additions. (let's add) - *A2 = A + AA; - *B2 = B + BB; - *C2 = C + CC; - *D2 = D + DD; - - //The clearance of confidential information - memset (pX, 0, sizeof (X)); -} - -//------------------------------------------------------------------- -// The function for the exteriors - -/** output is the coded binary in the character sequence which wants to code string. */ -void MD5_String2binary (const char *string, char *output) -{ -//var - /*8bit */ - unsigned char padding_message[64]; //Extended message 512bit 64byte - unsigned char *pstring; //The position of string in the present scanning notes is held. - -// unsigned char digest[16]; - /*32bit */ - unsigned int string_byte_len, //The byte chief of string is held. - string_bit_len, //The bit length of string is held. - copy_len, //The number of bytes which is used by 1-3 and which remained - msg_digest[4]; //Message digest 128bit 4byte - unsigned int *A = &msg_digest[0], //The message digest in accordance with RFC (reference) - *B = &msg_digest[1], *C = &msg_digest[2], *D = &msg_digest[3]; - int i; - -//prog - //Step 3.Initialize MD Buffer (although it is the initialization; step 3 of A, B, C, and D -- unavoidable -- a head) - *A = 0x67452301; - *B = 0xefcdab89; - *C = 0x98badcfe; - *D = 0x10325476; - - //Step 1.Append Padding Bits (extension of a mark bit) - //1-1 - string_byte_len = strlen (string); //The byte chief of a character sequence is acquired. - pstring = (unsigned char *) string; //The position of the present character sequence is set. - - //1-2 Repeat calculation until length becomes less than 64 bytes. - for (i = string_byte_len; 64 <= i; i -= 64, pstring += 64) - MD5_Round_Calculate (pstring, A, B, C, D); - - //1-3 - copy_len = string_byte_len % 64; //The number of bytes which remained is computed. - strncpy ((char *) padding_message, (char *) pstring, copy_len); //A message is copied to an extended bit sequence. - memset (padding_message + copy_len, 0, 64 - copy_len); //It buries by 0 until it becomes extended bit length. - padding_message[copy_len] |= 0x80; //The next of a message is 1. - - //1-4 - //If 56 bytes or more (less than 64 bytes) of remainder becomes, it will calculate by extending to 64 bytes. - if (56 <= copy_len) - { - MD5_Round_Calculate (padding_message, A, B, C, D); - memset (padding_message, 0, 56); //56 bytes is newly fill uped with 0. - } - - //Step 2.Append Length (the information on length is added) - string_bit_len = string_byte_len * 8; //From the byte chief to bit length (32 bytes of low rank) - memcpy (&padding_message[56], &string_bit_len, 4); //32 bytes of low rank is set. - - //When bit length cannot be expressed in 32 bytes of low rank, it is a beam raising to a higher rank. - if (UINT_MAX / 8 < string_byte_len) - { - unsigned int high = (string_byte_len - UINT_MAX / 8) * 8; - memcpy (&padding_message[60], &high, 4); - } - else - memset (&padding_message[60], 0, 4); //In this case, it is good for a higher rank at 0. - - //Step 4.Process Message in 16-Word Blocks (calculation of MD5) - MD5_Round_Calculate (padding_message, A, B, C, D); - - //Step 5.Output (output) - memcpy (output, msg_digest, 16); -// memcpy (digest, msg_digest, and 16); //8 byte*4 < - 32byte conversion A function called Encode as used in the field of RFC -/* sprintf(output, - "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", - digest[ 0], digest[ 1], digest[ 2], digest[ 3], - digest[ 4], digest[ 5], digest[ 6], digest[ 7], - digest[ 8], digest[ 9], digest[10], digest[11], - digest[12], digest[13], digest[14], digest[15]);*/ -} - -/** output is the coded character sequence in the character sequence which wants to code string. */ -void MD5_String (const char *string, char *output) -{ - unsigned char digest[16]; - - MD5_String2binary (string, digest); - sprintf (output, - "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", - digest[0], digest[1], digest[2], digest[3], - digest[4], digest[5], digest[6], digest[7], - digest[8], digest[9], digest[10], digest[11], - digest[12], digest[13], digest[14], digest[15]); -} diff --git a/src/login_sql/md5calc.h b/src/login_sql/md5calc.h deleted file mode 100644 index 16c122d..0000000 --- a/src/login_sql/md5calc.h +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef _MD5CALC_H_ -#define _MD5CALC_H_ - -void MD5_String (const char *string, char *output); -void MD5_String2binary (const char *string, char *output); - -#endif diff --git a/src/login_sql/readme.txt b/src/login_sql/readme.txt deleted file mode 100644 index b945af7..0000000 --- a/src/login_sql/readme.txt +++ /dev/null @@ -1,120 +0,0 @@ -// Encoded UTF-8 -//--------------------------------------------- -// 007 - by Jazz -1. 0590 official versionに合わせて修正しました. - -//--------------------------------------------- -// 006 - by Jazz -1. パスワード決まった回数間違い時自動 IP遮断具現. -2. login_athena.confを修正 - -//--------------------------------------------- -// 005 - by Jazz -1. 許容しない IDが接近の時自動で IP遮断機能具現. -2. 自動で遮断解除機能具現. - -//--------------------------------------------- -// 004 - by Jazz -1. aphostropy 問題を解決しました. これは保安と連関がある問題です. -2. SQLの構造を修正しました. -3. server 状態を SQLで出力. - -//--------------------------------------------- -// 003 - by Jazz -1. 接続記録を DBで出力. -2. IP基盤の接続遮断具現. - -//--------------------------------------------- -// 002 - by Jazz -1. いくつかの詳細問題点修正. - -//--------------------------------------------- -// 001 - by Jazz -1. 一番目安定 versionです. - - -// notice some.. -In this program, new parts are under BSD License. -and imported parts are under GPL as athena did. - -this program is not public license. but modification and editing are -unlimit permitted. but auther don't have any responsibility on that. - -this realase does not gurantee working perfectly. and, I would -answer neither that question nor technical one. - -I use... -P4 2.4Gh/512MB/WinXP/cygwin - -athena is under GPL license. -Ragnarok is Gravity's trademark. -login-db for athena is BSD license except code from original athena. -cygwin is Redhat's trademark. - -// About compile. -You need mysqlclient library to compile this. You can get this by -compiling mysql source. - -"-lmysqlclient" option needed when you did compile. - -some patch need on mysql when you did compile under cygwin. - -// 몇가지 정보에 대하여 - -이 프로그램에서 새로 만들어진 부분은 BSD 라이센스 아래에 배포 됩니다. -그리고 import 된 부분은 원래 athena의 GPL 라이센스 아래에 있습니다. - -이 프로그램은 public license가 아닙니다. 하지만 변경, 개조, 수정은 -무제한 허용되며 그에 대한 책임은 저자가 지지 않습니다. - -현재 이 릴리즈는 완벽히 동작함을 보장하지 않습니다. 그리고 그에 대한 -상담 또한 절대 받지 않습니다. - -기술적인 부분의 상담은 받지 않습니다. - -개발 환경 -P4 2.4Gh/512MB/WinXP/cygwin - -athena는 GPL 라이센스를 준수 합니다. -Ragnarok는 Gravity의 trademark입니다. -login-db for athena는 athena에서 가져온 부분을 제외하면 BSD 라이센스를 따릅니다. -cygwin은 Redhat의 trademark입니다. - -// 컴파일에 대하여. - -이 프로그램을 컴파일하기 위하여 mysqlclient에 대한 library가 필요합니다. -이는 mysql의 소스를 컴파일하면 얻을수 있습니다. - -컴파일시에 -lmysqlclient 옵션이 필요합니다. - -cygwin의 경우는 몇가지 패치가 필요합니다. - -// いくつかの情報に対して - -このプログラムで新たに作られた部分は BSD ライセンスの下に配布になります. -そして import になった部分は元々 athenaの GPL ライセンスの下にあります. - -このプログラムは public licenseではないです. しかし変更, 改造, 修正は -無制限許容されてそれに対する責任は著者が負けないです. - -現在このリリースは完壁に動作することを保障しないです. そして彼に大韓 -相談も絶対受けないです. - -技術的な部分の相談は受けないです. - -開発環境 -P4 2.4Gh/512MB/WinXP/cygwin - -athenaは GPL ライセンスを守ります. -Ragnarokは Gravityの trademarkです. -login-db for athenaは athenaから持って来た部分を除けば BSD ライセンスに付きます. -cygwinは Redhatの trademarkです. - -// コンパイルに対して. - -このプログラムをコンパイルするために mysqlclientに対する libraryが必要です. -これは mysqlのソースをコンパイルすれば得ることができます. - -コンパイルの時に -lmysqlclient オプションが必要です. - -cygwinの場合はいくつかのパッチが必要です. \ No newline at end of file diff --git a/src/login_sql/strlib.c b/src/login_sql/strlib.c deleted file mode 100644 index 5c87ef6..0000000 --- a/src/login_sql/strlib.c +++ /dev/null @@ -1,64 +0,0 @@ -#include -#include -#include - -#include "strlib.h" -#include "utils.h" - -//----------------------------------------------- -// string lib. -unsigned char *jstrescape (unsigned char *pt) -{ - //copy from here - unsigned char *ptr; - int i = 0, j = 0; - - //copy string to temporary - CREATE (ptr, char, J_MAX_MALLOC_SIZE); - strcpy (ptr, pt); - - while (ptr[i] != '\0') - { - switch (ptr[i]) - { - case '\'': - pt[j++] = '\\'; - pt[j++] = ptr[i++]; - break; - case '\\': - pt[j++] = '\\'; - pt[j++] = ptr[i++]; - break; - default: - pt[j++] = ptr[i++]; - } - } - pt[j++] = '\0'; - free (ptr); - return (unsigned char *) &pt[0]; -} - -unsigned char *jstrescapecpy (unsigned char *pt, unsigned char *spt) -{ - //copy from here - int i = 0, j = 0; - - while (spt[i] != '\0') - { - switch (spt[i]) - { - case '\'': - pt[j++] = '\\'; - pt[j++] = spt[i++]; - break; - case '\\': - pt[j++] = '\\'; - pt[j++] = spt[i++]; - break; - default: - pt[j++] = spt[i++]; - } - } - pt[j++] = '\0'; - return (unsigned char *) &pt[0]; -} diff --git a/src/login_sql/strlib.h b/src/login_sql/strlib.h deleted file mode 100644 index fadd30f..0000000 --- a/src/login_sql/strlib.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef _J_STR_LIB_H_ -#define _J_STR_LIB_H_ -#define J_MAX_MALLOC_SIZE 65535 -// String function library. -// code by Jioh L. Jung (ziozzang@4wish.net) -// This code is under license "BSD" -unsigned char *jstrescape (unsigned char *pt); -unsigned char *jstrescapecpy (unsigned char *pt, unsigned char *spt); -#endif diff --git a/src/login_sql/timer.h b/src/login_sql/timer.h deleted file mode 100644 index 8abc259..0000000 --- a/src/login_sql/timer.h +++ /dev/null @@ -1,45 +0,0 @@ -// original : core.h 2003/03/14 11:55:25 Rev 1.4 - -#ifndef _TIMER_H_ -#define _TIMER_H_ - -#define BASE_TICK 5 - -#define TIMER_ONCE_AUTODEL 1 -#define TIMER_INTERVAL 2 -#define TIMER_REMOVE_HEAP 16 - -#define DIFF_TICK(a,b) ((int)((a)-(b))) - -// Struct declaration - -struct TimerData -{ - unsigned int tick; - int (*func) (int, unsigned int, int, int); - int id; - int data; - int type; - int interval; - int heap_pos; -}; - -// Function prototype declaration - -unsigned int gettick_nocache (void); -unsigned int gettick (void); - -int add_timer (unsigned int, int (*)(int, unsigned int, int, int), int, int); -int add_timer_interval (unsigned int, int (*)(int, unsigned int, int, int), - int, int, int); -int delete_timer (int, int (*)(int, unsigned int, int, int)); - -int addtick_timer (int tid, unsigned int tick); -struct TimerData *get_timer (int tid); - -int do_timer (unsigned int tick); - -int add_timer_func_list (int (*)(int, unsigned int, int, int), char *); -char *search_timer_func_list (int (*)(int, unsigned int, int, int)); - -#endif // _TIMER_H_ diff --git a/src/txt-converter/char/Makefile b/src/txt-converter/char/Makefile deleted file mode 100644 index 47d97d3..0000000 --- a/src/txt-converter/char/Makefile +++ /dev/null @@ -1,15 +0,0 @@ -include ../../../make.defs - -all: char-converter -sql: char-converter - -COMMON_OBJ = ../../common/core.o ../../common/socket.o ../../common/timer.o ../../common/db.o ../../common/malloc.o - -char-converter: char-converter.o strlib.o $(COMMON_OBJ) - $(CC) -o ../../../$@ $^ $(LIB_S) - -char-converter.o: char-converter.c char.h strlib.h -strlib.o: strlib.c strlib.h -clean: - rm -f *.o ../../../char-converter - diff --git a/src/txt-converter/char/char-converter.c b/src/txt-converter/char/char-converter.c deleted file mode 100644 index 8b4336f..0000000 --- a/src/txt-converter/char/char-converter.c +++ /dev/null @@ -1,971 +0,0 @@ -// $Id: char-converter.c,v 1.1.1.1 2004/09/10 17:45:03 MagicalTux Exp $ -// original : char2.c 2003/03/14 11:58:35 Rev.1.5 - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define STORAGE_MEMINC 16 - -#include "char.h" -#include "strlib.h" - -#ifdef MEMWATCH -#include "memwatch.h" -#endif - -char pet_txt[256] = "save/pet.txt"; -char storage_txt[256] = "save/storage.txt"; - -MYSQL mysql_handle; -MYSQL_RES *sql_res; -MYSQL_ROW sql_row; -int sql_fields, sql_cnt; -char tmp_sql[65535]; - -int db_server_port = 3306; -char db_server_ip[16] = "127.0.0.1"; -char db_server_id[32] = "ragnarok"; -char db_server_pw[32] = "ragnarok"; -char db_server_logindb[32] = "ragnarok"; - -struct storage *storage = NULL; - -struct mmo_map_server server[MAX_MAP_SERVERS]; -int server_fd[MAX_MAP_SERVERS]; - -int login_fd; -char userid[24]; -char passwd[24]; -char server_name[20]; -char login_ip_str[16]; -int login_port = 6900; -char char_ip_str[16]; -int char_ip; -int char_port = 6121; -int char_maintenance; -int char_new; -char char_txt[256]; - -char t_name[256]; - -#define CHAR_STATE_WAITAUTH 0 -#define CHAR_STATE_AUTHOK 1 -struct char_session_data -{ - int state; - int account_id, login_id1, login_id2, sex; - int found_char[9]; -}; - -#define AUTH_FIFO_SIZE 256 -struct -{ - int account_id, char_id, login_id1, char_pos, delflag, sex; -} auth_fifo[AUTH_FIFO_SIZE]; -int auth_fifo_pos = 0; - -int char_id_count = 100000; -struct mmo_charstatus *char_dat; -int char_num, char_max; -int max_connect_user = 0; -int autosave_interval = DEFAULT_AUTOSAVE_INTERVAL; - -// ʱ ġ(conf Ϸκ 缳 ) -struct point start_point = { "new_1-1.gat", 53, 111 }; - -int inter_pet_fromstr (char *str, struct s_pet *p) -{ - int s; - int tmp_int[16]; - char tmp_str[256]; - - memset (p, 0, sizeof (struct s_pet)); - -// printf("sscanf pet main info\n"); - s = sscanf (str, "%d, %d,%[^\t]\t%d, %d, %d, %d, %d, %d, %d, %d, %d", - &tmp_int[0], &tmp_int[1], tmp_str, &tmp_int[2], &tmp_int[3], - &tmp_int[4], &tmp_int[5], &tmp_int[6], &tmp_int[7], - &tmp_int[8], &tmp_int[9], &tmp_int[10]); - - if (s != 12) - return 1; - - p->pet_id = tmp_int[0]; - p->class = tmp_int[1]; - memcpy (p->name, tmp_str, 24); - p->account_id = tmp_int[2]; - p->char_id = tmp_int[3]; - p->level = tmp_int[4]; - p->egg_id = tmp_int[5]; - p->equip = tmp_int[6]; - p->intimate = tmp_int[7]; - p->hungry = tmp_int[8]; - p->rename_flag = tmp_int[9]; - p->incuvate = tmp_int[10]; - - if (p->hungry < 0) - p->hungry = 0; - else if (p->hungry > 100) - p->hungry = 100; - if (p->intimate < 0) - p->intimate = 0; - else if (p->intimate > 1000) - p->intimate = 1000; - - return 0; -} - -//--------------------------------------------------------- -int inter_pet_tosql (int pet_id, struct s_pet *p) -{ - //`pet` (`pet_id`, `class`,`name`,`account_id`,`char_id`,`level`,`egg_id`,`equip`,`intimate`,`hungry`,`rename_flag`,`incuvate`) - - char tmp_sql[65535]; - MYSQL_RES *sql_res; - MYSQL_ROW sql_row; - - jstrescapecpy (t_name, p->name); - if (p->hungry < 0) - p->hungry = 0; - else if (p->hungry > 100) - p->hungry = 100; - if (p->intimate < 0) - p->intimate = 0; - else if (p->intimate > 1000) - p->intimate = 1000; - sprintf (tmp_sql, "SELECT * FROM `pet` WHERE `pet_id`='%d'", pet_id); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error - %s\n", mysql_error (&mysql_handle)); - } - sql_res = mysql_store_result (&mysql_handle); - sql_row = mysql_fetch_row (sql_res); //row fetching - if (!sql_row) //no row -> insert - sprintf (tmp_sql, - "INSERT INTO `pet` (`pet_id`, `class`,`name`,`account_id`,`char_id`,`level`,`egg_id`,`equip`,`intimate`,`hungry`,`rename_flag`,`incuvate`) VALUES ('%d', '%d', '%s', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d')", - p->pet_id, p->class, t_name, p->account_id, p->char_id, - p->level, p->egg_id, p->equip, p->intimate, p->hungry, - p->rename_flag, p->incuvate); - else //row reside -> updating - sprintf (tmp_sql, - "UPDATE `pet` SET `class`='%d',`name`='%s',`account_id`='%d',`char_id`='%d',`level`='%d',`egg_id`='%d',`equip`='%d',`intimate`='%d',`hungry`='%d',`rename_flag`='%d',`incuvate`='%d' WHERE `pet_id`='%d'", - p->class, t_name, p->account_id, p->char_id, p->level, - p->egg_id, p->equip, p->intimate, p->hungry, p->rename_flag, - p->incuvate, p->pet_id); - mysql_free_result (sql_res); //resource free - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error - %s\n", mysql_error (&mysql_handle)); - } - - printf ("pet dump success! - %d:%s\n", pet_id, p->name); - - return 0; -} - -int storage_tosql (int account_id, struct storage *p) -{ - // id -> DB dump - // storage {`account_id`/`id`/`nameid`/`amount`/`equip`/`identify`/`refine`/`attribute`/`card0`/`card1`/`card2`/`card3`} - int i, j; - - j = 0; - - //printf ("starting storage dump to DB - id: %d\n", account_id); - - //delete old data. - sprintf (tmp_sql, "DELETE FROM `storage` WHERE `account_id`='%d'", - account_id); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error - %s\n", mysql_error (&mysql_handle)); - } - - //printf ("all storage item was deleted ok\n"); - - for (i = 0; i < MAX_STORAGE; i++) - { - //printf ("save storage num: %d (%d:%d)\n",i, p->storage[i].nameid , p->storage[i].amount); - - if ((p->storage[i].nameid) && (p->storage[i].amount)) - { - sprintf (tmp_sql, - "INSERT INTO `storage` (`account_id`,`nameid`,`amount`,`equip`,`identify`,`refine`,`attribute`,`card0`,`card1`,`card2`,`card3`,`broken`) VALUES ('%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d')", - p->account_id, p->storage[i].nameid, - p->storage[i].amount, p->storage[i].equip, - p->storage[i].identify, p->storage[i].refine, - p->storage[i].attribute, p->storage[i].card[0], - p->storage[i].card[1], p->storage[i].card[2], - p->storage[i].card[3], p->storage[i].broken); - //printf ("%s\n",tmp_sql); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error - %s\n", - mysql_error (&mysql_handle)); - } - j++; - } - } - - printf ("storage dump to DB - id: %d (total: %d)\n", account_id, j); - return 0; -} - -// char to storage -int storage_fromstr (char *str, struct storage *p) -{ - int tmp_int[256]; - int set, next, len, i; - - set = sscanf (str, "%d, %d%n", &tmp_int[0], &tmp_int[1], &next); - p->storage_amount = tmp_int[1]; - - if (set != 2) - return 0; - if (str[next] == '\n' || str[next] == '\r') - return 1; - next++; - for (i = 0; str[next] && str[next] != '\t'; i++) - { - if (sscanf (str + next, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d%n", - &tmp_int[0], &tmp_int[1], &tmp_int[2], &tmp_int[3], - &tmp_int[4], &tmp_int[5], &tmp_int[6], - &tmp_int[7], &tmp_int[8], &tmp_int[9], &tmp_int[10], - &tmp_int[11], &len) == 12) - { - p->storage[i].id = tmp_int[0]; - p->storage[i].nameid = tmp_int[1]; - p->storage[i].amount = tmp_int[2]; - p->storage[i].equip = tmp_int[3]; - p->storage[i].identify = tmp_int[4]; - p->storage[i].refine = tmp_int[5]; - p->storage[i].attribute = tmp_int[6]; - p->storage[i].card[0] = tmp_int[7]; - p->storage[i].card[1] = tmp_int[8]; - p->storage[i].card[2] = tmp_int[9]; - p->storage[i].card[3] = tmp_int[10]; - p->storage[i].broken = tmp_int[11]; - next += len; - if (str[next] == ' ') - next++; - } - - else if (sscanf (str + next, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d%n", - &tmp_int[0], &tmp_int[1], &tmp_int[2], &tmp_int[3], - &tmp_int[4], &tmp_int[5], &tmp_int[6], - &tmp_int[7], &tmp_int[8], &tmp_int[9], &tmp_int[10], - &len) == 11) - { - p->storage[i].id = tmp_int[0]; - p->storage[i].nameid = tmp_int[1]; - p->storage[i].amount = tmp_int[2]; - p->storage[i].equip = tmp_int[3]; - p->storage[i].identify = tmp_int[4]; - p->storage[i].refine = tmp_int[5]; - p->storage[i].attribute = tmp_int[6]; - p->storage[i].card[0] = tmp_int[7]; - p->storage[i].card[1] = tmp_int[8]; - p->storage[i].card[2] = tmp_int[9]; - p->storage[i].card[3] = tmp_int[10]; - p->storage[i].broken = 0; - next += len; - if (str[next] == ' ') - next++; - } - - else - return 0; - } - return 1; -} - -///////////////////////////////// -int mmo_char_fromstr (char *str, struct mmo_charstatus *p) -{ - int tmp_int[256]; - int set, next, len, i; - - // initilialise character - memset (p, '\0', sizeof (struct mmo_charstatus)); - - // If it's not char structure of version 1008 and after - if ((set = sscanf (str, "%d\t%d,%d\t%[^\t]\t%d,%d,%d\t%d,%d,%d\t%d,%d,%d,%d\t%d,%d,%d,%d,%d,%d\t%d,%d" "\t%d,%d,%d\t%d,%d,%d\t%d,%d,%d\t%d,%d,%d,%d,%d" "\t%[^,],%d,%d\t%[^,],%d,%d,%d%n", &tmp_int[0], &tmp_int[1], &tmp_int[2], p->name, // - &tmp_int[3], &tmp_int[4], &tmp_int[5], &tmp_int[6], &tmp_int[7], &tmp_int[8], &tmp_int[9], &tmp_int[10], &tmp_int[11], &tmp_int[12], &tmp_int[13], &tmp_int[14], &tmp_int[15], &tmp_int[16], &tmp_int[17], &tmp_int[18], &tmp_int[19], &tmp_int[20], &tmp_int[21], &tmp_int[22], &tmp_int[23], // - &tmp_int[24], &tmp_int[25], &tmp_int[26], &tmp_int[27], &tmp_int[28], &tmp_int[29], &tmp_int[30], &tmp_int[31], &tmp_int[32], &tmp_int[33], &tmp_int[34], p->last_point.map, &tmp_int[35], &tmp_int[36], // - p->save_point.map, &tmp_int[37], &tmp_int[38], - &tmp_int[39], &next)) != 43) - { - tmp_int[39] = 0; // partner id - // If not char structure from version 384 to 1007 - if ((set = sscanf (str, "%d\t%d,%d\t%[^\t]\t%d,%d,%d\t%d,%d,%d\t%d,%d,%d,%d\t%d,%d,%d,%d,%d,%d\t%d,%d" "\t%d,%d,%d\t%d,%d,%d\t%d,%d,%d\t%d,%d,%d,%d,%d" "\t%[^,],%d,%d\t%[^,],%d,%d%n", &tmp_int[0], &tmp_int[1], &tmp_int[2], p->name, // - &tmp_int[3], &tmp_int[4], &tmp_int[5], &tmp_int[6], &tmp_int[7], &tmp_int[8], &tmp_int[9], &tmp_int[10], &tmp_int[11], &tmp_int[12], &tmp_int[13], &tmp_int[14], &tmp_int[15], &tmp_int[16], &tmp_int[17], &tmp_int[18], &tmp_int[19], &tmp_int[20], &tmp_int[21], &tmp_int[22], &tmp_int[23], // - &tmp_int[24], &tmp_int[25], &tmp_int[26], &tmp_int[27], &tmp_int[28], &tmp_int[29], &tmp_int[30], &tmp_int[31], &tmp_int[32], &tmp_int[33], &tmp_int[34], p->last_point.map, &tmp_int[35], &tmp_int[36], // - p->save_point.map, &tmp_int[37], &tmp_int[38], - &next)) != 42) - { - // It's char structure of a version before 384 - tmp_int[26] = 0; // pet id - set = sscanf (str, "%d\t%d,%d\t%[^\t]\t%d,%d,%d\t%d,%d,%d\t%d,%d,%d,%d\t%d,%d,%d,%d,%d,%d\t%d,%d" "\t%d,%d,%d\t%d,%d\t%d,%d,%d\t%d,%d,%d,%d,%d" "\t%[^,],%d,%d\t%[^,],%d,%d%n", &tmp_int[0], &tmp_int[1], &tmp_int[2], p->name, // - &tmp_int[3], &tmp_int[4], &tmp_int[5], &tmp_int[6], &tmp_int[7], &tmp_int[8], &tmp_int[9], &tmp_int[10], &tmp_int[11], &tmp_int[12], &tmp_int[13], &tmp_int[14], &tmp_int[15], &tmp_int[16], &tmp_int[17], &tmp_int[18], &tmp_int[19], &tmp_int[20], &tmp_int[21], &tmp_int[22], &tmp_int[23], // - &tmp_int[24], &tmp_int[25], // - &tmp_int[27], &tmp_int[28], &tmp_int[29], &tmp_int[30], &tmp_int[31], &tmp_int[32], &tmp_int[33], &tmp_int[34], p->last_point.map, &tmp_int[35], &tmp_int[36], // - p->save_point.map, &tmp_int[37], &tmp_int[38], - &next); - set += 2; - //printf("char: old char data ver.1\n"); - // Char structure of version 1007 or older - } - else - { - set++; - //printf("char: old char data ver.2\n"); - } - // Char structure of version 1008+ - } - else - { - //printf("char: new char data ver.3\n"); - } - if (set != 43) - return 0; - - p->char_id = tmp_int[0]; - p->account_id = tmp_int[1]; - p->char_num = tmp_int[2]; - p->class = tmp_int[3]; - p->base_level = tmp_int[4]; - p->job_level = tmp_int[5]; - p->base_exp = tmp_int[6]; - p->job_exp = tmp_int[7]; - p->zeny = tmp_int[8]; - p->hp = tmp_int[9]; - p->max_hp = tmp_int[10]; - p->sp = tmp_int[11]; - p->max_sp = tmp_int[12]; - p->str = tmp_int[13]; - p->agi = tmp_int[14]; - p->vit = tmp_int[15]; - p->int_ = tmp_int[16]; - p->dex = tmp_int[17]; - p->luk = tmp_int[18]; - p->status_point = tmp_int[19]; - p->skill_point = tmp_int[20]; - p->option = tmp_int[21]; - p->karma = tmp_int[22]; - p->manner = tmp_int[23]; - p->party_id = tmp_int[24]; - p->guild_id = tmp_int[25]; - p->pet_id = tmp_int[26]; - p->hair = tmp_int[27]; - p->hair_color = tmp_int[28]; - p->clothes_color = tmp_int[29]; - p->weapon = tmp_int[30]; - p->shield = tmp_int[31]; - p->head_top = tmp_int[32]; - p->head_mid = tmp_int[33]; - p->head_bottom = tmp_int[34]; - p->last_point.x = tmp_int[35]; - p->last_point.y = tmp_int[36]; - p->save_point.x = tmp_int[37]; - p->save_point.y = tmp_int[38]; - p->partner_id = tmp_int[39]; - - // Some checks - for (i = 0; i < char_num; i++) - { - if (char_dat[i].char_id == p->char_id) - { - printf - ("\033[1;31mmmo_auth_init: ******Error: a character has an identical id to another.\n"); - printf - (" character id #%d -> new character not readed.\n", - p->char_id); - printf (" Character saved in log file.\033[0m\n"); - return -1; - } - else if (strcmp (char_dat[i].name, p->name) == 0) - { - printf - ("\033[1;31mmmo_auth_init: ******Error: character name already exists.\n"); - printf - (" character name '%s' -> new character not readed.\n", - p->name); - printf (" Character saved in log file.\033[0m\n"); - return -2; - } - } - - if (str[next] == '\n' || str[next] == '\r') - return 1; // VKf[^ - - next++; - - for (i = 0; str[next] && str[next] != '\t'; i++) - { - set = - sscanf (str + next, "%[^,],%d,%d%n", p->memo_point[i].map, - &tmp_int[0], &tmp_int[1], &len); - if (set != 3) - return -3; - p->memo_point[i].x = tmp_int[0]; - p->memo_point[i].y = tmp_int[1]; - next += len; - if (str[next] == ' ') - next++; - } - - next++; - - for (i = 0; str[next] && str[next] != '\t'; i++) - { - if (sscanf (str + next, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d%n", - &tmp_int[0], &tmp_int[1], &tmp_int[2], &tmp_int[3], - &tmp_int[4], &tmp_int[5], &tmp_int[6], - &tmp_int[7], &tmp_int[8], &tmp_int[9], &tmp_int[10], - &tmp_int[11], &len) == 12) - { - // do nothing, it's ok - } - else if (sscanf (str + next, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d%n", - &tmp_int[0], &tmp_int[1], &tmp_int[2], &tmp_int[3], - &tmp_int[4], &tmp_int[5], &tmp_int[6], - &tmp_int[7], &tmp_int[8], &tmp_int[9], &tmp_int[10], - &len) == 11) - { - tmp_int[11] = 0; // broken doesn't exist in this version -> 0 - } - else // invalid structure - return -4; - p->inventory[i].id = tmp_int[0]; - p->inventory[i].nameid = tmp_int[1]; - p->inventory[i].amount = tmp_int[2]; - p->inventory[i].equip = tmp_int[3]; - p->inventory[i].identify = tmp_int[4]; - p->inventory[i].refine = tmp_int[5]; - p->inventory[i].attribute = tmp_int[6]; - p->inventory[i].card[0] = tmp_int[7]; - p->inventory[i].card[1] = tmp_int[8]; - p->inventory[i].card[2] = tmp_int[9]; - p->inventory[i].card[3] = tmp_int[10]; - p->inventory[i].broken = tmp_int[11]; - next += len; - if (str[next] == ' ') - next++; - } - - next++; - - for (i = 0; str[next] && str[next] != '\t'; i++) - { - if (sscanf (str + next, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d%n", - &tmp_int[0], &tmp_int[1], &tmp_int[2], &tmp_int[3], - &tmp_int[4], &tmp_int[5], &tmp_int[6], - &tmp_int[7], &tmp_int[8], &tmp_int[9], &tmp_int[10], - &tmp_int[11], &len) == 12) - { - // do nothing, it's ok - } - else if (sscanf (str + next, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d%n", - &tmp_int[0], &tmp_int[1], &tmp_int[2], &tmp_int[3], - &tmp_int[4], &tmp_int[5], &tmp_int[6], - &tmp_int[7], &tmp_int[8], &tmp_int[9], &tmp_int[10], - &len) == 11) - { - tmp_int[11] = 0; // broken doesn't exist in this version -> 0 - } - else // invalid structure - return -5; - p->cart[i].id = tmp_int[0]; - p->cart[i].nameid = tmp_int[1]; - p->cart[i].amount = tmp_int[2]; - p->cart[i].equip = tmp_int[3]; - p->cart[i].identify = tmp_int[4]; - p->cart[i].refine = tmp_int[5]; - p->cart[i].attribute = tmp_int[6]; - p->cart[i].card[0] = tmp_int[7]; - p->cart[i].card[1] = tmp_int[8]; - p->cart[i].card[2] = tmp_int[9]; - p->cart[i].card[3] = tmp_int[10]; - p->cart[i].broken = tmp_int[11]; - next += len; - if (str[next] == ' ') - next++; - } - - next++; - - for (i = 0; str[next] && str[next] != '\t'; i++) - { - set = sscanf (str + next, "%d,%d%n", &tmp_int[0], &tmp_int[1], &len); - if (set != 2) - return -6; - p->skill[tmp_int[0]].id = tmp_int[0]; - p->skill[tmp_int[0]].lv = tmp_int[1]; - next += len; - if (str[next] == ' ') - next++; - } - - next++; - - for (i = 0; - str[next] && str[next] != '\t' && str[next] != '\n' - && str[next] != '\r'; i++) - { // global_regȑOathena.txt݊̂߈ꉞ'\n'`FbN - set = - sscanf (str + next, "%[^,],%d%n", p->global_reg[i].str, - &p->global_reg[i].value, &len); - if (set != 2) - { - // because some scripts are not correct, the str can be "". So, we must check that. - // If it's, we must not refuse the character, but just this REG value. - // Character line will have something like: nov_2nd_cos,9 ,9 nov_1_2_cos_c,1 (here, ,9 is not good) - if (str[next] == ',' - && sscanf (str + next, ",%d%n", &p->global_reg[i].value, - &len) == 1) - i--; - else - return -7; - } - next += len; - if (str[next] == ' ') - next++; - } - p->global_reg_num = i; - - return 1; -} - -//========================================================================================================== -int mmo_char_tosql (int char_id, struct mmo_charstatus *p) -{ - int i, save_flag; - - save_flag = char_id; - printf ("request save char data... (%d)\n", char_id); - - //`char`( `char_id`,`account_id`,`char_num`,`name`,`class`,`base_level`,`job_level`,`base_exp`,`job_exp`,`zeny`, //9 - //`str`,`agi`,`vit`,`int`,`dex`,`luk`, //15 - //`max_hp`,`hp`,`max_sp`,`sp`,`status_point`,`skill_point`, //21 - //`option`,`karma`,`manner`,`party_id`,`guild_id`,`pet_id`, //27 - //`hair`,`hair_color`,`clothes_color`,`weapon`,`shield`,`head_top`,`head_mid`,`head_bottom`, //35 - //`last_map`,`last_x`,`last_y`,`save_map`,`save_x`,`save_y`) - sprintf (tmp_sql, - "INSERT INTO `char` SET `char_id`='%d', `account_id`='%d', `char_num`='%d', `name`='%s', `class`='%d', `base_level`='%d', `job_level`='%d'," - "`base_exp`='%d', `job_exp`='%d', `zeny`='%d'," - "`max_hp`='%d',`hp`='%d',`max_sp`='%d',`sp`='%d',`status_point`='%d',`skill_point`='%d'," - "`str`='%d',`agi`='%d',`vit`='%d',`int`='%d',`dex`='%d',`luk`='%d'," - "`option`='%d',`karma`='%d',`manner`='%d',`party_id`='%d',`guild_id`='%d',`pet_id`='%d'," - "`hair`='%d',`hair_color`='%d',`clothes_color`='%d',`weapon`='%d',`shield`='%d',`head_top`='%d',`head_mid`='%d',`head_bottom`='%d'," - "`last_map`='%s',`last_x`='%d',`last_y`='%d',`save_map`='%s',`save_x`='%d',`save_y`='%d', `partner_id` = '%d'", - char_id, p->account_id, p->char_num, p->name, p->class, - p->base_level, p->job_level, p->base_exp, p->job_exp, p->zeny, - p->max_hp, p->hp, p->max_sp, p->sp, p->status_point, - p->skill_point, p->str, p->agi, p->vit, p->int_, p->dex, p->luk, - p->option, p->karma, p->manner, p->party_id, p->guild_id, - p->pet_id, p->hair, p->hair_color, p->clothes_color, p->weapon, - p->shield, p->head_top, p->head_mid, p->head_bottom, - p->last_point.map, p->last_point.x, p->last_point.y, - p->save_point.map, p->save_point.x, p->save_point.y, - p->partner_id); - - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (update `char`)- %s\n", - mysql_error (&mysql_handle)); - } - - //`memo` (`memo_id`,`char_id`,`map`,`x`,`y`) - sprintf (tmp_sql, "DELETE FROM `memo` WHERE `char_id`='%d'", char_id); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (delete `memo`)- %s\n", - mysql_error (&mysql_handle)); - } - - //insert here. - for (i = 0; i < 10; i++) - { - if (p->memo_point[i].map[0]) - { - sprintf (tmp_sql, - "INSERT INTO `memo`(`char_id`,`map`,`x`,`y`) VALUES ('%d', '%s', '%d', '%d')", - char_id, p->memo_point[i].map, p->memo_point[i].x, - p->memo_point[i].y); - if (mysql_query (&mysql_handle, tmp_sql)) - printf ("DB server Error (insert `memo`)- %s\n", - mysql_error (&mysql_handle)); - } - } - //`inventory` (`id`,`char_id`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `card0`, `card1`, `card2`, `card3`, `broken`) - sprintf (tmp_sql, "DELETE FROM `inventory` WHERE `char_id`='%d'", - char_id); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (delete `inventory`)- %s\n", - mysql_error (&mysql_handle)); - } - - //insert here. - for (i = 0; i < MAX_INVENTORY; i++) - { - if (p->inventory[i].nameid) - { - sprintf (tmp_sql, - "INSERT INTO `inventory`(`id`,`char_id`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `card0`, `card1`, `card2`, `card3`, `broken`)" - " VALUES ('%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d')", - p->inventory[i].id, char_id, p->inventory[i].nameid, - p->inventory[i].amount, p->inventory[i].equip, - p->inventory[i].identify, p->inventory[i].refine, - p->inventory[i].attribute, p->inventory[i].card[0], - p->inventory[i].card[1], p->inventory[i].card[2], - p->inventory[i].card[3], p->inventory[i].broken); - if (mysql_query (&mysql_handle, tmp_sql)) - printf ("DB server Error (insert `inventory`)- %s\n", - mysql_error (&mysql_handle)); - } - } - - //`cart_inventory` (`id`,`char_id`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `card0`, `card1`, `card2`, `card3`, `broken`) - sprintf (tmp_sql, "DELETE FROM `cart_inventory` WHERE `char_id`='%d'", - char_id); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (delete `cart_inventory`)- %s\n", - mysql_error (&mysql_handle)); - } - - //insert here. - for (i = 0; i < MAX_CART; i++) - { - if (p->cart[i].nameid) - { - sprintf (tmp_sql, - "INSERT INTO `cart_inventory`(`id`,`char_id`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `card0`, `card1`, `card2`, `card3`, `broken`)" - " VALUES ('%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d' )", - p->cart[i].id, char_id, p->cart[i].nameid, - p->cart[i].amount, p->cart[i].equip, p->cart[i].identify, - p->cart[i].refine, p->cart[i].attribute, - p->cart[i].card[0], p->cart[i].card[1], - p->cart[i].card[2], p->cart[i].card[3], - p->cart[i].broken); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (insert `cart_inventory`)- %s\n", - mysql_error (&mysql_handle)); - } - } - } - - //`skill` (`char_id`, `id`, `lv`) - sprintf (tmp_sql, "DELETE FROM `skill` WHERE `char_id`='%d'", char_id); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (delete `skill`)- %s\n", - mysql_error (&mysql_handle)); - } - - //insert here. - for (i = 0; i < MAX_SKILL; i++) - { - if (p->skill[i].id) - { - if (p->skill[i].id && p->skill[i].flag != 1) - { - sprintf (tmp_sql, - "INSERT INTO `skill`(`char_id`,`id`, `lv`) VALUES ('%d', '%d', '%d')", - char_id, p->skill[i].id, - (p->skill[i].flag == - 0) ? p->skill[i].lv : p->skill[i].flag - 2); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (insert `skill`)- %s\n", - mysql_error (&mysql_handle)); - } - } - } - } - //`global_reg_value` (`char_id`, `str`, `value`) - sprintf (tmp_sql, "DELETE FROM `global_reg_value` WHERE `char_id`='%d'", - char_id); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (delete `global_reg_value`)- %s\n", - mysql_error (&mysql_handle)); - } - - //insert here. - for (i = 0; i < p->global_reg_num; i++) - { - if (p->global_reg[i].value != 0) - { - sprintf (tmp_sql, - "INSERT INTO `global_reg_value` (`char_id`, `str`, `value`) VALUES ('%d', '%s','%d')", - char_id, p->global_reg[i].str, p->global_reg[i].value); - if (mysql_query (&mysql_handle, tmp_sql)) - { - printf ("DB server Error (insert `global_reg_value`)- %s\n", - mysql_error (&mysql_handle)); - } - } - } - - printf ("saving char is done... (%d)\n", char_id); - save_flag = 0; - - return 0; -} - -//========================================================================================================== - -int mmo_char_init (void) -{ - char line[65536]; - struct s_pet *p; - int ret; - int i = 0, set, tmp_int[2], c = 0; - char input; - FILE *fp; - - //DB connection initialized - mysql_init (&mysql_handle); - printf ("Connect DB server.... (inter server)\n"); - if (!mysql_real_connect - (&mysql_handle, db_server_ip, db_server_id, db_server_pw, - db_server_logindb, db_server_port, (char *) NULL, 0)) - { - //pointer check - printf ("%s\n", mysql_error (&mysql_handle)); - exit (1); - } - else - { - printf ("connect success! (inter server)\n"); - } - - printf - ("Warning : Make sure you backup your databases before continuing!\n"); - printf - ("\nDo you wish to convert your Character Database to SQL? (y/n) : "); - input = getchar (); - if (input == 'y' || input == 'Y') - { - printf ("\nConverting Character Database...\n"); - fp = fopen_ ("save/athena.txt", "r"); - char_dat = malloc (sizeof (char_dat[0]) * 256); - char_max = 256; - if (fp == NULL) - return 0; - while (fgets (line, 65535, fp)) - { - if (char_num >= char_max) - { - char_max += 256; - char_dat = - realloc (char_dat, sizeof (char_dat[0]) * char_max); - } - memset (&char_dat[char_num], 0, sizeof (char_dat[0])); - ret = mmo_char_fromstr (line, &char_dat[char_num]); - if (ret) - { - mmo_char_tosql (char_dat[char_num].char_id, - &char_dat[char_num]); - printf ("convert %d -> DB\n", char_dat[char_num].char_id); - if (char_dat[char_num].char_id >= char_id_count) - char_id_count = char_dat[char_num].char_id + 1; - char_num++; - } - } - printf ("char data convert end\n"); - fclose_ (fp); - } - - while (getchar () != '\n'); - printf - ("\nDo you wish to convert your Storage Database to SQL? (y/n) : "); - input = getchar (); - if (input == 'y' || input == 'Y') - { - printf ("\nConverting Storage Database...\n"); - fp = fopen_ (storage_txt, "r"); - if (fp == NULL) - { - printf ("cant't read : %s\n", storage_txt); - return 0; - } - - while (fgets (line, 65535, fp)) - { - set = sscanf (line, "%d,%d", &tmp_int[0], &tmp_int[1]); - if (set == 2) - { - if (i == 0) - { - storage = malloc (sizeof (struct storage)); - } - else - { - storage = - realloc (storage, sizeof (struct storage) * (i + 1)); - } - memset (&storage[i], 0, sizeof (struct storage)); - storage[i].account_id = tmp_int[0]; - storage_fromstr (line, &storage[i]); - storage_tosql (tmp_int[0], &storage[i]); //to sql. (dump) - i++; - } - } - fclose_ (fp); - } - - while (getchar () != '\n'); - printf ("\nDo you wish to convert your Pet Database to SQL? (y/n) : "); - input = getchar (); - if (input == 'y' || input == 'Y') - { - printf ("\nConverting Pet Database...\n"); - if ((fp = fopen_ (pet_txt, "r")) == NULL) - return 1; - - p = malloc (sizeof (struct s_pet)); - while (fgets (line, sizeof (line), fp)) - { - if (p == NULL) - { - printf ("int_pet: out of memory!\n"); - exit (0); - } - if (inter_pet_fromstr (line, p) == 0 && p->pet_id > 0) - { - //pet dump - inter_pet_tosql (p->pet_id, p); - } - else - { - printf ("int_pet: broken data [%s] line %d\n", pet_txt, c); - } - c++; - } - fclose_ (fp); - } - - return 0; -} - -int inter_config_read (const char *cfgName) -{ - printf ("start reading interserver configuration: %s\n", cfgName); - int i; - char line[1024], w1[1024], w2[1024]; - FILE *fp; - - fp = fopen_ (cfgName, "r"); - if (fp == NULL) - { - printf ("file not found: %s\n", cfgName); - return 1; - } - while (fgets (line, 1020, fp)) - { - i = sscanf (line, "%[^:]:%s", w1, w2); - if (i != 2) - continue; - if (strcmpi (w1, "storage_txt") == 0) - { - printf ("set storage_txt : %s\n", w2); - strncpy (storage_txt, w2, sizeof (storage_txt)); - } - else if (strcmpi (w1, "pet_txt") == 0) - { - printf ("set pet_txt : %s\n", w2); - strncpy (pet_txt, w2, sizeof (pet_txt)); - } - //add for DB connection - else if (strcmpi (w1, "db_server_ip") == 0) - { - strcpy (db_server_ip, w2); - printf ("set db_server_ip : %s\n", w2); - } - else if (strcmpi (w1, "db_server_port") == 0) - { - db_server_port = atoi (w2); - printf ("set db_server_port : %s\n", w2); - } - else if (strcmpi (w1, "db_server_id") == 0) - { - strcpy (db_server_id, w2); - printf ("set db_server_id : %s\n", w2); - } - else if (strcmpi (w1, "db_server_pw") == 0) - { - strcpy (db_server_pw, w2); - printf ("set db_server_pw : %s\n", w2); - } - else if (strcmpi (w1, "db_server_logindb") == 0) - { - strcpy (db_server_logindb, w2); - printf ("set db_server_logindb : %s\n", w2); - } - } - fclose_ (fp); - - printf ("success reading interserver configuration\n"); - - return 0; -} - -int char_config_read (const char *cfgName) -{ - printf ("start reading interserver configuration: %s\n", cfgName); - int i; - char line[1024], w1[1024], w2[1024]; - FILE *fp; - - fp = fopen_ (cfgName, "r"); - if (fp == NULL) - { - printf ("file not found: %s\n", cfgName); - return 1; - } - - while (fgets (line, 1020, fp)) - { - if (line[0] == '/' && line[1] == '/') - continue; - - i = sscanf (line, "%[^:]:%s", w1, w2); - if (i != 2) - continue; - if (strcmpi (w1, "char_txt") == 0) - { - printf ("set char_txt : %s\n", w2); - strcpy (char_txt, w2); - } - } - fclose_ (fp); - printf ("reading configure done.....\n"); - - return 0; -} - -int do_init (int argc, char **argv) -{ - - char_config_read ((argc > 1) ? argv[1] : CHAR_CONF_NAME); - inter_config_read ((argc > 2) ? argv[2] : inter_cfgName); - - mmo_char_init (); - printf ("all conversion success!\n"); - exit (0); - return 0; -} diff --git a/src/txt-converter/char/char.h b/src/txt-converter/char/char.h deleted file mode 100644 index 6ea18a3..0000000 --- a/src/txt-converter/char/char.h +++ /dev/null @@ -1,39 +0,0 @@ -#include "../../common/core.h" -#include "../../common/socket.h" -#include "../../common/timer.h" -#include "../common/mmo.h" -#include "../../common/version.h" -#include "../../common/db.h" - -#ifndef _CHAR_H_ -#define _CHAR_H_ - -#define MAX_MAP_SERVERS 30 - -#define CHAR_CONF_NAME "conf/char_athena.conf" - -#define UNKNOWN_CHAR_NAME "Unknown" - -#define DEFAULT_AUTOSAVE_INTERVAL 300*1000 - -struct mmo_map_server -{ - long ip; - short port; - int users; - char map[MAX_MAP_PER_SERVER][16]; -}; - -int mapif_sendall (unsigned char *buf, unsigned int len); -int mapif_sendallwos (int fd, unsigned char *buf, unsigned int len); -int mapif_send (int fd, unsigned char *buf, unsigned int len); - -extern int autosave_interval; - -#endif - -#include "inter.h" -#include "int_pet.h" -#include "int_guild.h" -#include "int_party.h" -#include "int_storage.h" diff --git a/src/txt-converter/char/int_guild.h b/src/txt-converter/char/int_guild.h deleted file mode 100644 index 98aea58..0000000 --- a/src/txt-converter/char/int_guild.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef _INT_GUILD_H_ -#define _INT_GUILD_H_ - -int inter_guild_init (); -int inter_guild_save (); -int inter_guild_parse_frommap (int fd); - -extern char guild_txt[256]; - -#endif diff --git a/src/txt-converter/char/int_party.h b/src/txt-converter/char/int_party.h deleted file mode 100644 index 30fdd04..0000000 --- a/src/txt-converter/char/int_party.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef _INT_PARTY_H_ -#define _INT_PARTY_H_ - -int inter_party_init (); -int inter_party_save (); - -int inter_party_parse_frommap (int fd); - -extern char party_txt[256]; - -#endif diff --git a/src/txt-converter/char/int_pet.h b/src/txt-converter/char/int_pet.h deleted file mode 100644 index 7f1157c..0000000 --- a/src/txt-converter/char/int_pet.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef _INT_PET_H_ -#define _INT_PET_H_ - -int inter_pet_init (); -int inter_pet_save (); -int inter_pet_delete (int pet_id); - -int inter_pet_parse_frommap (int fd); - -//extern char pet_txt[256]; - -#endif diff --git a/src/txt-converter/char/int_storage.h b/src/txt-converter/char/int_storage.h deleted file mode 100644 index 1c5c3f9..0000000 --- a/src/txt-converter/char/int_storage.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef _INT_STORAGE_H_ -#define _INT_STORAGE_H_ - -int inter_storage_init (); -int inter_storage_save (); - -int inter_storage_parse_frommap (int fd); - -//extern char storage_txt[256]; - -#endif diff --git a/src/txt-converter/char/inter.h b/src/txt-converter/char/inter.h deleted file mode 100644 index 2662052..0000000 --- a/src/txt-converter/char/inter.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef _INTER_H_ -#define _INTER_H_ - -int inter_init (const char *file); -int inter_save (); -int inter_parse_frommap (int fd); - -int inter_check_length (int fd, int length); - -#define inter_cfgName "conf/inter_athena.conf" - -//add include for DBMS(mysql) -#include - -extern MYSQL mysql_handle; -extern char tmp_sql[65535]; -extern MYSQL_RES *sql_res; -extern MYSQL_ROW sql_row; -extern int sql_cnt; - -extern int db_server_port; -extern char db_server_ip[16]; -extern char db_server_id[32]; -extern char db_server_pw[32]; -extern char db_server_logindb[32]; - -#endif diff --git a/src/txt-converter/char/strlib.c b/src/txt-converter/char/strlib.c deleted file mode 100644 index 463b830..0000000 --- a/src/txt-converter/char/strlib.c +++ /dev/null @@ -1,76 +0,0 @@ -#include -#include -#include - -#include "strlib.h" - -//----------------------------------------------- -// string lib. -unsigned char *jstrescape (unsigned char *pt) -{ - //copy from here - unsigned char *ptr; - int i = 0, j = 0; - - //copy string to temporary - ptr = malloc (J_MAX_MALLOC_SIZE); - strcpy (ptr, pt); - - while (ptr[i] != '\0') - { - switch (ptr[i]) - { - case '\'': - pt[j++] = '\\'; - pt[j++] = ptr[i++]; - break; - default: - pt[j++] = ptr[i++]; - } - } - pt[j++] = '\0'; - free (ptr); - return (unsigned char *) &pt[0]; -} - -unsigned char *jstrescapecpy (unsigned char *pt, unsigned char *spt) -{ - //copy from here - int i = 0, j = 0; - - while (spt[i] != '\0') - { - switch (spt[i]) - { - case '\'': - pt[j++] = '\\'; - pt[j++] = spt[i++]; - break; - default: - pt[j++] = spt[i++]; - } - } - pt[j++] = '\0'; - return (unsigned char *) &pt[0]; -} - -int jmemescapecpy (unsigned char *pt, unsigned char *spt, int size) -{ - //copy from here - int i = 0, j = 0; - - while (i < size) - { - switch (spt[i]) - { - case '\'': - pt[j++] = '\\'; - pt[j++] = spt[i++]; - break; - default: - pt[j++] = spt[i++]; - } - } - // copy size is 0 ~ (j-1) - return j; -} diff --git a/src/txt-converter/char/strlib.h b/src/txt-converter/char/strlib.h deleted file mode 100644 index 962f1bc..0000000 --- a/src/txt-converter/char/strlib.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef _J_STR_H_ -#define _J_STR_H_ -#define J_MAX_MALLOC_SIZE 65535 -//string functions. -//code by Jioh L. Jung -unsigned char *jstrescape (unsigned char *pt); -unsigned char *jstrescapecpy (unsigned char *pt, unsigned char *spt); -int jmemescapecpy (unsigned char *pt, unsigned char *spt, int size); -#endif diff --git a/src/txt-converter/common/mmo.h b/src/txt-converter/common/mmo.h deleted file mode 100644 index 0295f6b..0000000 --- a/src/txt-converter/common/mmo.h +++ /dev/null @@ -1,300 +0,0 @@ -// Original : mmo.h 2003/03/14 12:07:02 Rev.1.7 - -#ifndef _MMO_H_ -#define _MMO_H_ - -#include - -#ifdef CYGWIN -// txtやlogなどの書き出すファイルの改行コード -#define RETCODE "\r\n" // (CR/LF:Windows系) -#else -#define RETCODE "\n" // (LF:Unix系) -#endif - -#define FIFOSIZE_SERVERLINK 128*1024 - -#define MAX_MAP_PER_SERVER 512 -#define MAX_INVENTORY 100 -#define MAX_AMOUNT 30000 -#define MAX_ZENY 1000000000 // 1G zeny -#define MAX_CART 100 -#define MAX_SKILL 450 -#define GLOBAL_REG_NUM 96 -#define ACCOUNT_REG_NUM 16 -#define ACCOUNT_REG2_NUM 16 -#define DEFAULT_WALK_SPEED 150 -#define MIN_WALK_SPEED 0 -#define MAX_WALK_SPEED 1000 -#define MAX_STORAGE 100 -#define MAX_GUILD_STORAGE 1000 -#define MAX_PARTY 12 -#define MAX_GUILD 140 // increased max guild members to accomodate for +2 increase for extension levels [Valaris] -#define MAX_GUILDPOSITION 56 // increased max guild positions to accomodate for all members [Valaris] -#define MAX_GUILDEXPLUSION 32 -#define MAX_GUILDALLIANCE 16 -#define MAX_GUILDSKILL 8 -#define MAX_GUILDCASTLE 24 // increased to include novice castles [Valaris] -#define MAX_GUILDLEVEL 50 - -#define MIN_HAIR_STYLE 0 -#define MAX_HAIR_STYLE 20 -#define MIN_HAIR_COLOR 0 -#define MAX_HAIR_COLOR 9 -#define MIN_CLOTH_COLOR 0 -#define MAX_CLOTH_COLOR 4 - -// for produce -#define MIN_ATTRIBUTE 0 -#define MAX_ATTRIBUTE 4 -#define ATTRIBUTE_NORMAL 0 -#define MIN_STAR 0 -#define MAX_STAR 3 - -#define MIN_PORTAL_MEMO 0 -#define MAX_PORTAL_MEMO 2 - -#define MAX_STATUS_TYPE 5 - -#define WEDDING_RING_M 2634 -#define WEDDING_RING_F 2635 - -#define CHAR_CONF_NAME "conf/char_athena.conf" - -struct item -{ - int id; - short nameid; - short amount; - unsigned short equip; - char identify; - char refine; - char attribute; - short card[4]; - short broken; -}; -struct point -{ - char map[24]; - short x, y; -}; -struct skill -{ - unsigned short id, lv, flag; -}; -struct global_reg -{ - char str[32]; - int value; -}; -struct s_pet -{ - int account_id; - int char_id; - int pet_id; - short class; - short level; - short egg_id; //pet egg id - short equip; //pet equip name_id - short intimate; //pet friendly - short hungry; //pet hungry - char name[24]; - char rename_flag; - char incuvate; -}; - -struct mmo_charstatus -{ - int char_id; - int account_id; - int partner_id; - - int base_exp, job_exp, zeny; - - short class; - short status_point, skill_point; - int hp, max_hp, sp, max_sp; - short option, karma, manner; - short hair, hair_color, clothes_color; - int party_id, guild_id, pet_id; - - short weapon, shield; - short head_top, head_mid, head_bottom; - - char name[24]; - unsigned char base_level, job_level; - short str, agi, vit, int_, dex, luk; - unsigned char char_num, sex; - - struct point last_point, save_point, memo_point[10]; - struct item inventory[MAX_INVENTORY], cart[MAX_CART]; - struct skill skill[MAX_SKILL]; - int global_reg_num; - struct global_reg global_reg[GLOBAL_REG_NUM]; - int account_reg_num; - struct global_reg account_reg[ACCOUNT_REG_NUM]; - int account_reg2_num; - struct global_reg account_reg2[ACCOUNT_REG2_NUM]; -}; - -struct storage -{ - int account_id; - short storage_status; - short storage_amount; - struct item storage[MAX_STORAGE]; -}; - -struct guild_storage -{ - int guild_id; - short storage_status; - short storage_amount; - struct item storage[MAX_GUILD_STORAGE]; -}; - -struct map_session_data; - -struct gm_account -{ - int account_id; - int level; -}; - -struct party_member -{ - int account_id; - char name[24], map[24]; - int leader, online, lv; - struct map_session_data *sd; -}; -struct party -{ - int party_id; - char name[24]; - int exp; - int item; - struct party_member member[MAX_PARTY]; -}; - -struct guild_member -{ - int account_id, char_id; - short hair, hair_color, gender, class, lv; - int exp, exp_payper; - short online, position; - int rsv1, rsv2; - char name[24]; - struct map_session_data *sd; -}; -struct guild_position -{ - char name[24]; - int mode; - int exp_mode; -}; -struct guild_alliance -{ - int opposition; - int guild_id; - char name[24]; -}; -struct guild_explusion -{ - char name[24]; - char mes[40]; - char acc[40]; - int account_id; - int rsv1, rsv2, rsv3; -}; -struct guild_skill -{ - int id, lv; -}; -struct guild -{ - int guild_id; - short guild_lv, connect_member, max_member, average_lv; - int exp, next_exp, skill_point, castle_id; - char name[24], master[24]; - struct guild_member member[MAX_GUILD]; - struct guild_position position[MAX_GUILDPOSITION]; - char mes1[60], mes2[120]; - int emblem_len, emblem_id; - char emblem_data[2048]; - struct guild_alliance alliance[MAX_GUILDALLIANCE]; - struct guild_explusion explusion[MAX_GUILDEXPLUSION]; - struct guild_skill skill[MAX_GUILDSKILL]; -}; -struct guild_castle -{ - int castle_id; - char map_name[24]; - char castle_name[24]; - int guild_id; - int economy; - int defense; - int triggerE; - int triggerD; - int nextTime; - int payTime; - int createTime; - int visibleC; - int visibleG0; - int visibleG1; - int visibleG2; - int visibleG3; - int visibleG4; - int visibleG5; - int visibleG6; - int visibleG7; - int Ghp0; // added Guardian HP [Valaris] - int Ghp1; - int Ghp2; - int Ghp3; - int Ghp4; - int Ghp5; - int Ghp6; - int Ghp7; - int GID0; - int GID1; - int GID2; - int GID3; - int GID4; - int GID5; - int GID6; - int GID7; // end addition [Valaris] - -}; -struct square -{ - int val1[5]; - int val2[5]; -}; - -enum -{ - GBI_EXP = 1, // ギルドのEXP - GBI_GUILDLV = 2, // ギルドのLv - GBI_SKILLPOINT = 3, // ギルドのスキルポイント - GBI_SKILLLV = 4, // ギルドスキルLv - - GMI_POSITION = 0, // メンバーの役職変更 - GMI_EXP = 1, // メンバーのEXP - -}; - -#ifndef strcmpi -#define strcmpi strcasecmp -#endif -#ifndef stricmp -#define stricmp strcasecmp -#endif -#ifndef strncmpi -#define strncmpi strncasecmp -#endif -#ifndef strnicmp -#define strnicmp strncasecmp -#endif - -#endif // _MMO_H_ diff --git a/src/txt-converter/login/Makefile b/src/txt-converter/login/Makefile deleted file mode 100644 index 832a21a..0000000 --- a/src/txt-converter/login/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -include ../../../make.defs -all: login-converter -sql: login-converter - -COMMON_OBJ = ../../common/core.o ../../common/socket.o ../../common/timer.o ../../common/db.o ../../common/malloc.o -COMMON_H = ../../common/core.h ../../common/socket.h ../../common/timer.h ../../common/mmo.h ../../common/version.h ../../common/db.h ../../common/malloc.h - -login-converter: login-converter.o ../../login_sql/md5calc.o ../../login_sql/strlib.o $(COMMON_OBJ) - $(CC) -o ../../../$@ $^ $(LIB_S) -login-converter.o: login-converter.c ../../login_sql/login.h ../../login_sql/md5calc.h ../../login_sql/strlib.h $(COMMON_H) -clean: - rm -f *.o ../../../login-converter diff --git a/src/txt-converter/login/login-converter.c b/src/txt-converter/login/login-converter.c deleted file mode 100644 index 477a0cc..0000000 --- a/src/txt-converter/login/login-converter.c +++ /dev/null @@ -1,282 +0,0 @@ -// $Id: login-converter.c,v 1.1.1.1 2004/09/10 17:45:03 MagicalTux Exp $ -// original : login2.c 2003/01/28 02:29:17 Rev.1.1.1.1 -// login data file to mysql conversion utility. -// -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include "../../common/core.h" -#include "../../common/socket.h" -#include "../../login/login.h" -#include "../../common/mmo.h" -#include "../../common/version.h" -#include "../../common/db.h" - -int account_id_count = START_ACCOUNT_NUM; -int server_num; -int new_account_flag = 0; -int login_port = 6900; - -struct mmo_char_server server[MAX_SERVERS]; -int server_fd[MAX_SERVERS]; - -#define AUTH_FIFO_SIZE 256 -struct -{ - int account_id, login_id1, login_id2; - int sex, delflag; -} auth_fifo[AUTH_FIFO_SIZE]; -int auth_fifo_pos = 0; -struct -{ - int account_id, sex; - char userid[24], pass[24], lastlogin[24]; - int logincount; - int state; // packet 0x006a value + 1 (0: compte OK) - char email[40]; // e-mail (by default: a@a.com) - char error_message[20]; // Message of error code #6 = Your are Prohibited to log in until %s (packet 0x006a) - time_t ban_until_time; // # of seconds 1/1/1970 (timestamp): ban time limit of the account (0 = no ban) - time_t connect_until_time; // # of seconds 1/1/1970 (timestamp): Validity limit of the account (0 = unlimited) - char last_ip[16]; // save of last IP of connection - char memo[255]; // a memo field - int account_reg2_num; - struct global_reg account_reg2[ACCOUNT_REG2_NUM]; -} *auth_dat; -int auth_num = 0, auth_max = 0; - -char login_account_id[256] = "account_id"; -char login_userid[256] = "userid"; -char login_user_pass[256] = "user_pass"; -char login_db[256] = "login"; - -static struct dbt *gm_account_db; - -int db_server_port = 3306; -char db_server_ip[16] = "127.0.0.1"; -char db_server_id[32] = "ragnarok"; -char db_server_pw[32] = "ragnarok"; -char db_server_logindb[32] = "ragnarok"; - -int isGM (int account_id) -{ - struct gm_account *p; - p = numdb_search (gm_account_db, account_id); - if (p == NULL) - return 0; - return p->level; -} - -int read_gm_account () -{ - char line[8192]; - struct gm_account *p; - FILE *fp; - int c = 0; - - gm_account_db = numdb_init (); - printf ("gm_account: read start\n"); - - if ((fp = fopen_ ("conf/GM_account.txt", "r")) == NULL) - return 1; - while (fgets (line, sizeof (line), fp)) - { - if (line[0] == '/' && line[1] == '/') - continue; - p = malloc (sizeof (struct gm_account)); - if (p == NULL) - { - printf ("gm_account: out of memory!\n"); - exit (0); - } - if (sscanf (line, "%d %d", &p->account_id, &p->level) != 2 - || p->level <= 0) - { - printf ("gm_account: broken data [conf/GM_account.txt] line %d\n", - c); - } - else - { - if (p->level > 99) - p->level = 99; - numdb_insert (gm_account_db, p->account_id, p); - } - c++; - } - fclose_ (fp); - printf ("gm_account: read done (%d gm account ID)\n", c); - return 0; -} - -int mmo_auth_init (void) -{ - MYSQL mysql_handle; - char tmpsql[1024]; - MYSQL_RES *sql_res; - MYSQL_ROW sql_row; - - mysql_init (&mysql_handle); - if (!mysql_real_connect - (&mysql_handle, db_server_ip, db_server_id, db_server_pw, - db_server_logindb, db_server_port, (char *) NULL, 0)) - { - //pointer check - printf ("%s\n", mysql_error (&mysql_handle)); - exit (1); - } - else - { - printf ("connect success!\n"); - } - printf ("convert start...\n"); - - FILE *fp; - int account_id, logincount, user_level, state, n, i; - char line[2048], userid[2048], pass[2048], lastlogin[2048], sex, - email[2048], error_message[2048], last_ip[2048], memo[2048]; - time_t ban_until_time; - time_t connect_until_time; - char t_uid[256]; - - fp = fopen_ ("save/account.txt", "r"); - auth_dat = malloc (sizeof (auth_dat[0]) * 256); - auth_max = 256; - if (fp == NULL) - return 0; - while (fgets (line, 1023, fp) != NULL) - { - - if (line[0] == '/' && line[1] == '/') - continue; - - i = sscanf (line, "%d\t%[^\t]\t%[^\t]\t%[^\t]\t%c\t%d\t%d\t" - "%[^\t]\t%[^\t]\t%ld\t%[^\t]\t%[^\t]\t%ld%n", - &account_id, userid, pass, lastlogin, &sex, &logincount, - &state, email, error_message, &connect_until_time, - last_ip, memo, &ban_until_time, &n); - - sprintf (tmpsql, - "SELECT `%s`,`%s`,`%s`,`lastlogin`,`logincount`,`sex`,`connect_until`,`last_ip`,`ban_until`,`state`" - " FROM `%s` WHERE `%s`='%s'", login_account_id, login_userid, - login_user_pass, login_db, login_userid, t_uid); - - if (mysql_query (&mysql_handle, tmpsql)) - { - printf ("DB server Error - %s\n", mysql_error (&mysql_handle)); - } - user_level = isGM (account_id); - printf ("userlevel: %s (%d)- %d\n", userid, account_id, user_level); - sql_res = mysql_store_result (&mysql_handle); - sql_row = mysql_fetch_row (sql_res); //row fetching - if (!sql_row) //no row -> insert - sprintf (tmpsql, - "INSERT INTO `login` (`account_id`, `userid`, `user_pass`, `lastlogin`, `sex`, `logincount`, `email`, `level`) VALUES (%d, '%s', '%s', '%s', '%c', %d, 'user@athena', %d);", - account_id, userid, pass, lastlogin, sex, logincount, - user_level); - else //row reside -> updating - sprintf (tmpsql, - "UPDATE `login` SET `account_id`='%d', `userid`='%s', `user_pass`='%s', `lastlogin`='%s', `sex`='%c', `logincount`='%d', `email`='user@athena', `level`='%d'\nWHERE `account_id`='%d';", - account_id, userid, pass, lastlogin, sex, logincount, - user_level, account_id); - printf ("Query: %s\n", tmpsql); - mysql_free_result (sql_res); //resource free - if (mysql_query (&mysql_handle, tmpsql)) - { - printf ("DB server Error - %s\n", mysql_error (&mysql_handle)); - } - } - fclose_ (fp); - - printf ("convert end...\n"); - - return 0; -} - -// アカウントデ??ベ?スの書き込み -void nowork (void) -{ - //null -} - -int login_config_read (const char *cfgName) -{ - int i; - char line[1024], w1[1024], w2[1024]; - FILE *fp; - - fp = fopen_ (cfgName, "r"); - - if (fp == NULL) - { - printf ("file not found: %s\n", cfgName); - return 1; - } - printf ("start reading configuration...\n"); - while (fgets (line, 1020, fp)) - { - if (line[0] == '/' && line[1] == '/') - continue; - - i = sscanf (line, "%[^:]:%s", w1, w2); - if (i != 2) - continue; - - //add for DB connection - if (strcmpi (w1, "db_server_ip") == 0) - { - strcpy (db_server_ip, w2); - printf ("set db_server_ip : %s\n", w2); - } - else if (strcmpi (w1, "db_server_port") == 0) - { - db_server_port = atoi (w2); - printf ("set db_server_port : %s\n", w2); - } - else if (strcmpi (w1, "db_server_id") == 0) - { - strcpy (db_server_id, w2); - printf ("set db_server_id : %s\n", w2); - } - else if (strcmpi (w1, "db_server_pw") == 0) - { - strcpy (db_server_pw, w2); - printf ("set db_server_pw : %s\n", w2); - } - else if (strcmpi (w1, "db_server_logindb") == 0) - { - strcpy (db_server_logindb, w2); - printf ("set db_server_logindb : %s\n", w2); - } - } - fclose_ (fp); - printf ("End reading configuration...\n"); - return 0; -} - -int do_init (int argc, char **argv) -{ - char input; - login_config_read ((argc > 1) ? argv[1] : LOGIN_CONF_NAME); - read_gm_account (); - - printf - ("\nWarning : Make sure you backup your databases before continuing!\n"); - printf ("\nDo you wish to convert your Login Database to SQL? (y/n) : "); - input = getchar (); - if (input == 'y' || input == 'Y') - mmo_auth_init (); - - exit (0); -} -- cgit v1.2.3-70-g09d2 From 0fa45b6d05f5533078a018afd6f7bb07b7875723 Mon Sep 17 00:00:00 2001 From: Ben Longbons Date: Thu, 17 Mar 2011 15:43:37 -0700 Subject: Changes that should have been caught earlier --- src/char/Makefile | 3 +-- src/common/Makefile | 4 ++-- src/ladmin/Makefile | 2 -- src/login/Makefile | 3 +-- src/map/Makefile | 4 +--- src/tool/eathena-monitor.c | 1 - 6 files changed, 5 insertions(+), 12 deletions(-) diff --git a/src/char/Makefile b/src/char/Makefile index 6f2e4af..308747d 100644 --- a/src/char/Makefile +++ b/src/char/Makefile @@ -1,7 +1,6 @@ include ../../make.defs -all: txt -txt: char +all: char COMMON_OBJ = ../common/core.o ../common/socket.o ../common/timer.o ../common/db.o ../common/lock.o ../common/malloc.o ../common/mt_rand.o COMMON_H = ../common/core.h ../common/socket.h ../common/timer.h ../common/mmo.h ../common/db.h ../common/lock.h ../common/timer.h ../common/malloc.h ../common/mt_rand.h diff --git a/src/common/Makefile b/src/common/Makefile index 48e75d8..549268b 100644 --- a/src/common/Makefile +++ b/src/common/Makefile @@ -1,12 +1,12 @@ include ../../make.defs -all txt sql: core.o socket.o timer.o grfio.o db.o lock.o nullpo.o malloc.o mt_rand.o md5calc.o +all: core.o socket.o timer.o grfio.o db.o lock.o nullpo.o malloc.o mt_rand.o md5calc.o core.o: core.c core.h socket.o: socket.c socket.h mmo.h timer.o: timer.c timer.h grfio.o: grfio.c grfio.h db.o: db.c db.h -lock.o: lock.h +lock.o: lock.c lock.h nullpo.o: nullpo.c nullpo.h malloc.o: malloc.c malloc.h mt_rand.o: mt_rand.c mt_rand.h diff --git a/src/ladmin/Makefile b/src/ladmin/Makefile index cb7e764..e873e69 100644 --- a/src/ladmin/Makefile +++ b/src/ladmin/Makefile @@ -1,8 +1,6 @@ include ../../make.defs all: ladmin -txt: ladmin -sql: ladmin COMMON_OBJ = ../common/core.o ../common/socket.o ../common/timer.o ../common/db.o ../common/malloc.o ../common/mt_rand.o COMMON_H = ../common/core.h ../common/socket.h ../common/timer.h ../common/mmo.h ../common/version.h ../common/db.h ../common/malloc.h ../common/mt_rand.h diff --git a/src/login/Makefile b/src/login/Makefile index 185cffb..8a7e5a6 100644 --- a/src/login/Makefile +++ b/src/login/Makefile @@ -1,7 +1,6 @@ include ../../make.defs -all: txt -txt: login +all: login COMMON_OBJ = ../common/core.o ../common/socket.o ../common/timer.o ../common/db.o ../common/lock.o ../common/malloc.o ../common/mt_rand.o ../common/md5calc.o COMMON_H = ../common/core.h ../common/socket.h ../common/timer.h ../common/mmo.h ../common/version.h ../common/db.h ../common/lock.h ../common/malloc.h ../common/mt_rand.h ../common/md5calc.h diff --git a/src/map/Makefile b/src/map/Makefile index c7c982e..f31279c 100644 --- a/src/map/Makefile +++ b/src/map/Makefile @@ -1,8 +1,6 @@ include ../../make.defs -all: txt - -txt: map +all: map obj: mkdir obj diff --git a/src/tool/eathena-monitor.c b/src/tool/eathena-monitor.c index 8713dff..04a48cf 100644 --- a/src/tool/eathena-monitor.c +++ b/src/tool/eathena-monitor.c @@ -155,7 +155,6 @@ pid_t start_process(const char *exec) { } // Kill all children with the same signal we got, then ourself. -// Note that none of the servers do any signal handling themselves. void stop_process(int sig) { if (pid_map) kill(pid_map, sig); if (pid_login) kill(pid_login, sig); -- cgit v1.2.3-70-g09d2 From a2306446c86b3333e69b082e41ae76ba71a42d9d Mon Sep 17 00:00:00 2001 From: Ben Longbons Date: Thu, 24 Mar 2011 13:57:13 -0700 Subject: Optimize common objects, and adjust other objects accordingly. Major changes still need to be made to each of the servers. --- .gitignore | 1 + make.defs | 10 +- src/char/Makefile | 4 +- src/char/char.c | 302 ++++----- src/char/int_guild.c | 62 +- src/char/int_party.c | 33 +- src/char/int_storage.c | 46 +- src/char/inter.c | 52 +- src/common/Makefile | 3 +- src/common/core.c | 132 +--- src/common/core.h | 23 +- src/common/db.c | 424 ++++++------- src/common/db.h | 102 +++- src/common/grfio.c | 1189 ++++-------------------------------- src/common/grfio.h | 29 +- src/common/lock.c | 27 +- src/common/lock.h | 11 +- src/common/malloc.c | 68 --- src/common/malloc.h | 27 - src/common/md5calc.c | 505 ++++++++------- src/common/md5calc.h | 67 +- src/common/mmo.h | 125 ++-- src/common/mt_rand.c | 86 ++- src/common/mt_rand.h | 26 +- src/common/nullpo.c | 56 +- src/common/nullpo.h | 254 ++------ src/common/sanity.h | 36 ++ src/common/socket.c | 420 +++++-------- src/common/socket.h | 197 +++--- src/common/timer.c | 328 ++++------ src/common/timer.h | 86 ++- src/common/utils.c | 121 ---- src/common/utils.h | 49 +- src/common/version.h | 43 +- src/ladmin/Makefile | 4 +- src/ladmin/ladmin.c | 86 ++- src/login/Makefile | 4 +- src/login/login.c | 336 +++++----- src/map/Makefile | 4 +- src/map/atcommand.c | 29 +- src/map/battle.c | 26 +- src/map/chat.c | 5 +- src/map/chrif.c | 33 +- src/map/clif.c | 56 +- src/map/clif.h | 2 +- src/map/guild.c | 77 +-- src/map/itemdb.c | 26 +- src/map/magic-expr.c | 5 +- src/map/magic-interpreter-base.c | 11 +- src/map/magic-interpreter-parser.y | 14 +- src/map/magic-interpreter.h | 1 - src/map/magic-stmt.c | 31 +- src/map/map.c | 125 ++-- src/map/map.h | 6 +- src/map/mob.c | 183 +++--- src/map/mob.h | 8 +- src/map/npc.c | 215 +++---- src/map/npc.h | 2 +- src/map/party.c | 26 +- src/map/pc.c | 125 ++-- src/map/pc.h | 10 +- src/map/script.c | 125 ++-- src/map/skill-pools.c | 2 +- src/map/skill.c | 225 ++++--- src/map/skill.h | 4 +- src/map/storage.c | 20 +- src/map/tmw.c | 3 +- src/tool/Makefile | 10 +- src/tool/eathena-monitor.c | 6 +- src/tool/itemfrob.c | 7 +- src/tool/mapfrob.c | 7 +- src/tool/marriage-info.c | 6 +- src/tool/moneycount/mmo.h | 15 - src/tool/skillfrob.c | 5 - 74 files changed, 2385 insertions(+), 4444 deletions(-) delete mode 100644 src/common/malloc.c delete mode 100644 src/common/malloc.h create mode 100644 src/common/sanity.h delete mode 100644 src/common/utils.c diff --git a/.gitignore b/.gitignore index 2e84a3a..0bba20b 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ src/char/char char-server src/ladmin/ladmin +/ladmin src/login/login login-server src/map/map diff --git a/make.defs b/make.defs index 55710c4..6f648e3 100644 --- a/make.defs +++ b/make.defs @@ -1,16 +1,20 @@ # defaults CC = gcc -CFLAGS = -pipe -g -fno-strict-aliasing -O2 -Wall +CFLAGS = -pipe -g -fno-strict-aliasing -Wall -Wextra -Werror=all -Werror=implicit-function-declaration CP = cp -f # The below might cause problems sometimes # CP = cp -lf # CP = cp -sf # works on both x86 and x86_64 -override CC += -m32 +override CC += -m32 -std=gnu99 ifeq ($(findstring CYGWIN,$(shell uname)), CYGWIN) override CFLAGS += -DFD_SETSIZE=4096 -DCYGWIN else - override CFLAGS += -fstack-protector -Wno-pointer-sign + override CFLAGS += -fstack-protector endif +# The default recipe is suboptimal +%.c: %.l + $(LEX) -o $@ $< + diff --git a/src/char/Makefile b/src/char/Makefile index 308747d..c448627 100644 --- a/src/char/Makefile +++ b/src/char/Makefile @@ -2,8 +2,8 @@ include ../../make.defs all: char -COMMON_OBJ = ../common/core.o ../common/socket.o ../common/timer.o ../common/db.o ../common/lock.o ../common/malloc.o ../common/mt_rand.o -COMMON_H = ../common/core.h ../common/socket.h ../common/timer.h ../common/mmo.h ../common/db.h ../common/lock.h ../common/timer.h ../common/malloc.h ../common/mt_rand.h +COMMON_OBJ = ../common/core.o ../common/socket.o ../common/timer.o ../common/db.o ../common/lock.o ../common/mt_rand.o +COMMON_H = ../common/core.h ../common/socket.h ../common/timer.h ../common/mmo.h ../common/db.h ../common/lock.h ../common/timer.h ../common/mt_rand.h char: char.o inter.o int_party.o int_guild.o int_storage.o $(COMMON_OBJ) char.o: char.c char.h inter.h $(COMMON_H) ../common/version.h diff --git a/src/char/char.c b/src/char/char.c index 5ac11d4..d340f1d 100644 --- a/src/char/char.c +++ b/src/char/char.c @@ -199,7 +199,7 @@ int search_character_index (char *character_name) for (i = 0; i < char_num; i++) { // Without case sensitive check (increase the number of similar character names found) - if (stricmp (char_dat[i].name, character_name) == 0) + if (strcasecmp (char_dat[i].name, character_name) == 0) { // Strict comparison (if found, we finish the function immediatly with correct value) if (strcmp (char_dat[i].name, character_name) == 0) @@ -427,7 +427,7 @@ int mmo_char_fromstr (char *str, struct mmo_charstatus *p) } } - if (strcmpi (wisp_server_name, p->name) == 0) + if (strcasecmp (wisp_server_name, p->name) == 0) { printf ("mmo_auth_init: ******WARNING: character name has wisp server name.\n"); @@ -592,18 +592,8 @@ int mmo_char_init (void) FILE *fp; char_max = 256; - char_dat = calloc (sizeof (struct mmo_charstatus) * 256, 1); - if (!char_dat) - { - printf ("out of memory: mmo_char_init (calloc of char_dat).\n"); - exit (1); - } - online_chars = calloc (sizeof (int) * 256, 1); - if (!online_chars) - { - printf ("out of memory: mmo_char_init (calloc of online_chars).\n"); - exit (1); - } + CREATE (char_dat, struct mmo_charstatus, 256); + CREATE (online_chars, int, 256); for (i = 0; i < char_max; i++) online_chars[i] = -1; @@ -640,27 +630,8 @@ int mmo_char_init (void) if (char_num >= char_max) { char_max += 256; - char_dat = - realloc (char_dat, sizeof (struct mmo_charstatus) * char_max); - if (!char_dat) - { - printf - ("Out of memory: mmo_char_init (realloc of char_dat).\n"); - char_log - ("Out of memory: mmo_char_init (realloc of char_dat)." - RETCODE); - exit (1); - } - online_chars = realloc (online_chars, sizeof (int) * char_max); - if (!online_chars) - { - printf - ("Out of memory: mmo_char_init (realloc of online_chars).\n"); - char_log - ("Out of memory: mmo_char_init (realloc of online_chars)." - RETCODE); - exit (1); - } + RECREATE (char_dat, struct mmo_charstatus, char_max); + RECREATE (online_chars, int, char_max); for (i = char_max - 256; i < char_max; i++) online_chars[i] = -1; } @@ -829,7 +800,7 @@ void mmo_char_sync (void) //---------------------------------------------------- // Function to save (in a periodic way) datas in files //---------------------------------------------------- -int mmo_char_sync_timer (int tid, unsigned int tick, int id, int data) +void mmo_char_sync_timer (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) { if (pid != 0) { @@ -839,14 +810,14 @@ int mmo_char_sync_timer (int tid, unsigned int tick, int id, int data) // Need to check status too? if (temp == 0) { - return 0; + return; } } // This can take a lot of time. Fork a child to handle the work and return at once // If we're unable to fork just continue running the function normally if ((pid = fork ()) > 0) - return 0; + return; mmo_char_sync (); inter_save (); @@ -854,8 +825,6 @@ int mmo_char_sync_timer (int tid, unsigned int tick, int id, int data) // If we're a child we should suicide now. if (pid == 0) _exit (0); - - return 0; } //---------------------------------------------------- @@ -972,7 +941,7 @@ int make_new_char (int fd, unsigned char *dat) { if ((name_ignoring_case != 0 && strcmp (char_dat[i].name, dat) == 0) || (name_ignoring_case == 0 - && strcmpi (char_dat[i].name, dat) == 0)) + && strcasecmp (char_dat[i].name, dat) == 0)) { char_log ("Make new char error (name already exists): (connection #%d, account: %d) slot %d, name: %s (actual name of other char: %s), stats: %d+%d+%d+%d+%d+%d=%d, hair: %d, hair color: %d." @@ -1009,25 +978,8 @@ int make_new_char (int fd, unsigned char *dat) if (char_num >= char_max) { char_max += 256; - char_dat = - realloc (char_dat, sizeof (struct mmo_charstatus) * char_max); - if (!char_dat) - { - printf ("Out of memory: make_new_char (realloc of char_dat).\n"); - char_log ("Out of memory: make_new_char (realloc of char_dat)." - RETCODE); - exit (1); - } - online_chars = realloc (online_chars, sizeof (int) * char_max); - if (!online_chars) - { - printf - ("Out of memory: make_new_char (realloc of online_chars).\n"); - char_log - ("Out of memory: make_new_char (realloc of online_chars)." - RETCODE); - exit (1); - } + RECREATE (char_dat, struct mmo_charstatus, char_max); + RECREATE (online_chars, int, char_max); for (j = char_max - 256; j < char_max; j++) online_chars[j] = -1; } @@ -1282,9 +1234,9 @@ void create_online_files (void) { char *p_name = char_dat[i].name; //speed up sorting when there are a lot of players. But very rarely players have same name. for (j = 0; j < players; j++) - if (stricmp (p_name, char_dat[id[j]].name) < 0 || + if (strcasecmp (p_name, char_dat[id[j]].name) < 0 || // if same name, we sort with case sensitive. - (stricmp (p_name, char_dat[id[j]].name) == 0 && + (strcasecmp (p_name, char_dat[id[j]].name) == 0 && strcmp (p_name, char_dat[id[j]].name) < 0)) { for (k = players; k > j; k--) @@ -1299,7 +1251,7 @@ void create_online_files (void) if (char_dat[i].zeny < char_dat[id[j]].zeny || // if same number of zenys, we sort by name. (char_dat[i].zeny == char_dat[id[j]].zeny && - stricmp (char_dat[i].name, + strcasecmp (char_dat[i].name, char_dat[id[j]].name) < 0)) { for (k = players; k > j; k--) @@ -1348,10 +1300,10 @@ void create_online_files (void) { int cpm_result; // A lot of player maps are identical. So, test if done often twice. for (j = 0; j < players; j++) - if ((cpm_result = strcmp (char_dat[i].last_point.map, char_dat[id[j]].last_point.map)) < 0 || // no map are identical and with upper cases (not use stricmp) + if ((cpm_result = strcmp (char_dat[i].last_point.map, char_dat[id[j]].last_point.map)) < 0 || // no map are identical and with upper cases (not use strcasecmp) // if same map name, we sort by name. (cpm_result == 0 && - stricmp (char_dat[i].name, + strcasecmp (char_dat[i].name, char_dat[id[j]].name) < 0)) { for (k = players; k > j; k--) @@ -1876,7 +1828,7 @@ static int char_delete (struct mmo_charstatus *cs) return 0; } -int parse_tologin (int fd) +void parse_tologin (int fd) { int i; struct char_session_data *sd; @@ -1894,7 +1846,7 @@ int parse_tologin (int fd) } close (fd); delete_session (fd); - return 0; + return; } sd = session[fd]->session_data; @@ -1907,7 +1859,7 @@ int parse_tologin (int fd) { case 0x2711: if (RFIFOREST (fd) < 3) - return 0; + return; if (RFIFOB (fd, 2)) { // printf("connect login server error : %d\n", RFIFOB(fd,2)); @@ -1936,7 +1888,7 @@ int parse_tologin (int fd) case 0x2713: if (RFIFOREST (fd) < 51) - return 0; + return; // printf("parse_tologin 2713 : %d\n", RFIFOB(fd,6)); for (i = 0; i < fd_max; i++) { @@ -1980,7 +1932,7 @@ int parse_tologin (int fd) // Receiving of an e-mail/time limit from the login-server (answer of a request because a player comes back from map-server to char-server) by [Yor] case 0x2717: if (RFIFOREST (fd) < 50) - return 0; + return; for (i = 0; i < fd_max; i++) { if (session[i] && (sd = session[i]->session_data)) @@ -2000,7 +1952,7 @@ int parse_tologin (int fd) case 0x2721: // gm reply if (RFIFOREST (fd) < 10) - return 0; + return; { unsigned char buf[10]; WBUFW (buf, 0) = 0x2b0b; @@ -2014,7 +1966,7 @@ int parse_tologin (int fd) case 0x2723: // changesex reply (modified by [Yor]) if (RFIFOREST (fd) < 7) - return 0; + return; { int acc, sex, i, j; unsigned char buf[7]; @@ -2079,7 +2031,7 @@ int parse_tologin (int fd) case 0x2726: // Request to send a broadcast message (no answer) if (RFIFOREST (fd) < 8 || RFIFOREST (fd) < (8 + RFIFOL (fd, 4))) - return 0; + return; if (RFIFOL (fd, 4) < 1) char_log ("Receiving a message for broadcast, but message is void." @@ -2166,7 +2118,7 @@ int parse_tologin (int fd) // account_reg2変更通知 case 0x2729: if (RFIFOREST (fd) < 4 || RFIFOREST (fd) < RFIFOW (fd, 2)) - return 0; + return; { struct global_reg reg[ACCOUNT_REG2_NUM]; unsigned char buf[4096]; @@ -2192,7 +2144,7 @@ int parse_tologin (int fd) case 0x7924: { // [Fate] Itemfrob package: forwarded from login-server if (RFIFOREST (fd) < 10) - return 0; + return; int source_id = RFIFOL (fd, 2); int dest_id = RFIFOL (fd, 6); unsigned char buf[10]; @@ -2240,7 +2192,7 @@ int parse_tologin (int fd) // Account deletion notification (from login-server) case 0x2730: if (RFIFOREST (fd) < 6) - return 0; + return; // Deletion of all characters of the account for (i = 0; i < char_num; i++) { @@ -2302,7 +2254,7 @@ int parse_tologin (int fd) // State change of account/ban notification (from login-server) by [Yor] case 0x2731: if (RFIFOREST (fd) < 11) - return 0; + return; // send to all map-servers to disconnect the player { unsigned char buf[11]; @@ -2320,14 +2272,12 @@ int parse_tologin (int fd) // Receiving GM acounts info from login-server (by [Yor]) case 0x2732: if (RFIFOREST (fd) < 4 || RFIFOREST (fd) < RFIFOW (fd, 2)) - return 0; + return; { char buf[32000]; if (gm_account != NULL) free (gm_account); - gm_account = - calloc (sizeof (struct gm_account) * - ((RFIFOW (fd, 2) - 4) / 5), 1); + CREATE (gm_account, struct gm_account, (RFIFOW (fd, 2) - 4) / 5); GM_num = 0; for (i = 4; i < RFIFOW (fd, 2); i = i + 5) { @@ -2353,7 +2303,7 @@ int parse_tologin (int fd) case 0x2741: // change password reply if (RFIFOREST (fd) < 7) - return 0; + return; { int acc, status, i; acc = RFIFOL (fd, 2); @@ -2378,18 +2328,17 @@ int parse_tologin (int fd) default: session[fd]->eof = 1; - return 0; + return; } } RFIFOFLUSH (fd); - - return 0; } //-------------------------------- // Map-server anti-freeze system //-------------------------------- -int map_anti_freeze_system (int tid, unsigned int tick, int id, int data) +typedef void (*timer_func) (timer_id, tick_t, custom_id_t, custom_data_t); +void map_anti_freeze_system (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) { int i; @@ -2411,11 +2360,9 @@ int map_anti_freeze_system (int tid, unsigned int tick, int id, int data) } } } - - return 0; } -int parse_frommap (int fd) +void parse_frommap (int fd) { int i, j; int id; @@ -2438,7 +2385,7 @@ int parse_frommap (int fd) } close (fd); delete_session (fd); - return 0; + return; } while (RFIFOREST (fd) >= 2) @@ -2461,7 +2408,7 @@ int parse_frommap (int fd) // Receiving map names list from the map-server case 0x2afa: if (RFIFOREST (fd) < 4 || RFIFOREST (fd) < RFIFOW (fd, 2)) - return 0; + return; memset (server[id].map, 0, sizeof (server[id].map)); j = 0; for (i = 4; i < RFIFOW (fd, 2); i += 16) @@ -2531,7 +2478,7 @@ int parse_frommap (int fd) // 認証要求 case 0x2afc: if (RFIFOREST (fd) < 22) - return 0; + return; //printf("auth_fifo search: account: %d, char: %d, secure: %08x-%08x\n", RFIFOL(fd,2), RFIFOL(fd,6), RFIFOL(fd,10), RFIFOL(fd,14)); for (i = 0; i < AUTH_FIFO_SIZE; i++) { @@ -2581,7 +2528,7 @@ int parse_frommap (int fd) // MAPサーバー上のユーザー数受信 case 0x2aff: if (RFIFOREST (fd) < 6 || RFIFOREST (fd) < RFIFOW (fd, 2)) - return 0; + return; server[id].users = RFIFOW (fd, 4); if (anti_freeze_enable) server_freezeflag[id] = 5; // Map anti-freeze system. Counter. 5 ok, 4...0 freezed @@ -2613,7 +2560,7 @@ int parse_frommap (int fd) // キャラデータ保存 case 0x2b01: if (RFIFOREST (fd) < 4 || RFIFOREST (fd) < RFIFOW (fd, 2)) - return 0; + return; for (i = 0; i < char_num; i++) { if (char_dat[i].account_id == RFIFOL (fd, 4) && @@ -2629,7 +2576,7 @@ int parse_frommap (int fd) // キャラセレ要求 case 0x2b02: if (RFIFOREST (fd) < 18) - return 0; + return; if (auth_fifo_pos >= AUTH_FIFO_SIZE) auth_fifo_pos = 0; //printf("auth_fifo set (auth #%d) - account: %d, secure: %08x-%08x\n", auth_fifo_pos, RFIFOL(fd,2), RFIFOL(fd,6), RFIFOL(fd,10)); @@ -2652,7 +2599,7 @@ int parse_frommap (int fd) // マップサーバー間移動要求 case 0x2b05: if (RFIFOREST (fd) < 49) - return 0; + return; if (auth_fifo_pos >= AUTH_FIFO_SIZE) auth_fifo_pos = 0; WFIFOW (fd, 0) = 0x2b06; @@ -2684,7 +2631,7 @@ int parse_frommap (int fd) // キャラ名検索 case 0x2b08: if (RFIFOREST (fd) < 6) - return 0; + return; for (i = 0; i < char_num; i++) { if (char_dat[i].char_id == RFIFOL (fd, 2)) @@ -2703,7 +2650,7 @@ int parse_frommap (int fd) // it is a request to become GM case 0x2b0a: if (RFIFOREST (fd) < 4 || RFIFOREST (fd) < RFIFOW (fd, 2)) - return 0; + return; // printf("parse_frommap: change gm -> login, account: %d, pass: '%s'.\n", RFIFOL(fd,4), RFIFOP(fd,8)); if (login_fd > 0) { // don't send request if no login-server @@ -2725,7 +2672,7 @@ int parse_frommap (int fd) // Map server send information to change an email of an account -> login-server case 0x2b0c: if (RFIFOREST (fd) < 86) - return 0; + return; if (login_fd > 0) { // don't send request if no login-server memcpy (WFIFOP (login_fd, 0), RFIFOP (fd, 0), 86); // 0x2722 .L .40B .40B @@ -2738,7 +2685,7 @@ int parse_frommap (int fd) // Map server ask char-server about a character name to do some operations (all operations are transmitted to login-server) case 0x2b0e: if (RFIFOREST (fd) < 44) - return 0; + return; { char character_name[24]; int acc = RFIFOL (fd, 2); // account_id of who ask (-1 if nobody) @@ -2877,7 +2824,7 @@ int parse_frommap (int fd) // account_reg保存要求 case 0x2b10: if (RFIFOREST (fd) < 4 || RFIFOREST (fd) < RFIFOW (fd, 2)) - return 0; + return; { struct global_reg reg[ACCOUNT_REG2_NUM]; int p, acc; @@ -2910,7 +2857,7 @@ int parse_frommap (int fd) // Map server is requesting a divorce case 0x2b16: if (RFIFOREST (fd) < 4) - return 0; + return; { for (i = 0; i < char_num; i++) if (char_dat[i].char_id == RFIFOL (fd, 2)) @@ -2931,17 +2878,16 @@ int parse_frommap (int fd) if (r == 1) // 処理できた break; if (r == 2) // パケット長が足りない - return 0; + return; } // inter server処理でもない場合は切断 printf ("char: unknown packet 0x%04x (%d bytes to read in buffer)! (from map).\n", RFIFOW (fd, 0), RFIFOREST (fd)); session[fd]->eof = 1; - return 0; + return; } } - return 0; } int search_mapserver (char *map) @@ -3002,7 +2948,7 @@ int lan_ip_check (unsigned char *p) return lancheck; } -int parse_char (int fd) +void parse_char (int fd) { int i, ch; char email[40]; @@ -3015,7 +2961,7 @@ int parse_char (int fd) login_fd = -1; close (fd); delete_session (fd); - return 0; + return; } sd = session[fd]->session_data; @@ -3029,13 +2975,13 @@ int parse_char (int fd) { case 0x20b: //20040622暗号化ragexe対応 if (RFIFOREST (fd) < 19) - return 0; + return; RFIFOSKIP (fd, 19); break; case 0x61: // change password request if (RFIFOREST (fd) < 50) - return 0; + return; { WFIFOW (login_fd, 0) = 0x2740; WFIFOL (login_fd, 2) = sd->account_id; @@ -3048,7 +2994,7 @@ int parse_char (int fd) case 0x65: // 接続要求 if (RFIFOREST (fd) < 17) - return 0; + return; { int GM_value; if ((GM_value = isGM (RFIFOL (fd, 2)))) @@ -3060,9 +3006,8 @@ int parse_char (int fd) RFIFOL (fd, 2)); if (sd == NULL) { - sd = session[fd]->session_data = - calloc (sizeof (struct char_session_data), 1); - memset (sd, 0, sizeof (struct char_session_data)); + CREATE (sd, struct char_session_data, 1); + session[fd]->session_data = sd; memcpy (sd->email, "no mail", 40); // put here a mail without '@' to refuse deletion if we don't receive the e-mail sd->connect_until_time = 0; // unknow or illimited (not displaying on map-server) } @@ -3141,7 +3086,7 @@ int parse_char (int fd) case 0x66: // キャラ選択 if (!sd || RFIFOREST (fd) < 3) - return 0; + return; char ip[16]; unsigned char *sin_addr = @@ -3311,7 +3256,7 @@ int parse_char (int fd) case 0x67: // 作成 if (!sd || RFIFOREST (fd) < 37) - return 0; + return; i = make_new_char (fd, RFIFOP (fd, 2)); if (i < 0) { @@ -3386,7 +3331,7 @@ int parse_char (int fd) case 0x68: // delete char //Yor's Fix if (!sd || RFIFOREST (fd) < 46) - return 0; + return; memcpy (email, RFIFOP (fd, 6), 40); if (e_mail_check (email) == 0) strncpy (email, "a@a.com", 40); // default e-mail @@ -3440,7 +3385,7 @@ int parse_char (int fd) } else { - /*if (strcmpi(email, sd->email) != 0) { // if it's an invalid email + /*if (strcasecmp(email, sd->email) != 0) { // if it's an invalid email * WFIFOW(fd, 0) = 0x70; * WFIFOB(fd, 2) = 0; // 00 = Incorrect Email address * WFIFOSET(fd, 3); @@ -3512,7 +3457,7 @@ int parse_char (int fd) case 0x2af8: // マップサーバーログイン if (RFIFOREST (fd) < 60) - return 0; + return; WFIFOW (fd, 0) = 0x2af9; for (i = 0; i < MAX_MAP_SERVERS; i++) { @@ -3555,13 +3500,13 @@ int parse_char (int fd) } WFIFOW (fd, 2) = len; WFIFOSET (fd, len); - return 0; + return; } break; case 0x187: // Alive信号? if (RFIFOREST (fd) < 6) - return 0; + return; RFIFOSKIP (fd, 6); break; @@ -3576,19 +3521,17 @@ int parse_char (int fd) WFIFOW (fd, 8) = ATHENA_MOD_VERSION; WFIFOSET (fd, 10); RFIFOSKIP (fd, 2); - return 0; + return; case 0x7532: // 接続の切断(defaultと処理は一緒だが明示的にするため) session[fd]->eof = 1; - return 0; + return; default: session[fd]->eof = 1; - return 0; + return; } } - RFIFOFLUSH (fd); - return 0; } // 全てのMAPサーバーにデータ送信(送信したmap鯖の数を返す) @@ -3649,7 +3592,7 @@ int mapif_send (int fd, unsigned char *buf, unsigned int len) return 0; } -int send_users_tologin (int tid, unsigned int tick, int id, int data) +void send_users_tologin (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) { int users = count_users (); char buf[16]; @@ -3665,17 +3608,15 @@ int send_users_tologin (int tid, unsigned int tick, int id, int data) WBUFW (buf, 0) = 0x2b00; WBUFL (buf, 2) = users; mapif_sendall (buf, 6); - - return 0; } -int check_connect_login_server (int tid, unsigned int tick, int id, int data) +void check_connect_login_server (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) { if (login_fd <= 0 || session[login_fd] == NULL) { printf ("Attempt to connect to login-server...\n"); if ((login_fd = make_connection (login_ip, login_port)) < 0) - return 0; + return; session[login_fd]->func_parse = parse_tologin; realloc_fifo (login_fd, FIFOSIZE_SERVERLINK, FIFOSIZE_SERVERLINK); WFIFOW (login_fd, 0) = 0x2710; @@ -3696,7 +3637,6 @@ int check_connect_login_server (int tid, unsigned int tick, int id, int data) WFIFOW (login_fd, 84) = char_new; WFIFOSET (login_fd, 86); } - return 0; } //---------------------------------------------------------- @@ -3705,12 +3645,12 @@ int check_connect_login_server (int tid, unsigned int tick, int id, int data) //---------------------------------------------------------- int config_switch (const char *str) { - if (strcmpi (str, "on") == 0 || strcmpi (str, "yes") == 0 - || strcmpi (str, "oui") == 0 || strcmpi (str, "ja") == 0 - || strcmpi (str, "si") == 0) + if (strcasecmp (str, "on") == 0 || strcasecmp (str, "yes") == 0 + || strcasecmp (str, "oui") == 0 || strcasecmp (str, "ja") == 0 + || strcasecmp (str, "si") == 0) return 1; - if (strcmpi (str, "off") == 0 || strcmpi (str, "no") == 0 - || strcmpi (str, "non") == 0 || strcmpi (str, "nein") == 0) + if (strcasecmp (str, "off") == 0 || strcasecmp (str, "no") == 0 + || strcasecmp (str, "non") == 0 || strcasecmp (str, "nein") == 0) return 0; return atoi (str); @@ -3756,7 +3696,7 @@ int lan_config_read (const char *lancfgName) remove_control_chars (w1); remove_control_chars (w2); - if (strcmpi (w1, "lan_map_ip") == 0) + if (strcasecmp (w1, "lan_map_ip") == 0) { // Read map-server Lan IP Address h = gethostbyname (w2); if (h != NULL) @@ -3774,7 +3714,7 @@ int lan_config_read (const char *lancfgName) } printf ("LAN IP of map-server: %s.\n", lan_map_ip); } - else if (strcmpi (w1, "subnet") == 0) + else if (strcasecmp (w1, "subnet") == 0) { // Read Subnetwork for (j = 0; j < 4; j++) subneti[j] = 0; @@ -3792,7 +3732,7 @@ int lan_config_read (const char *lancfgName) printf ("Sub-network of the map-server: %d.%d.%d.%d.\n", subneti[0], subneti[1], subneti[2], subneti[3]); } - else if (strcmpi (w1, "subnetmask") == 0) + else if (strcasecmp (w1, "subnetmask") == 0) { // Read Subnetwork Mask for (j = 0; j < 4; j++) subnetmaski[j] = 255; @@ -3859,21 +3799,21 @@ int char_config_read (const char *cfgName) remove_control_chars (w1); remove_control_chars (w2); - if (strcmpi (w1, "userid") == 0) + if (strcasecmp (w1, "userid") == 0) { memcpy (userid, w2, 24); } - else if (strcmpi (w1, "passwd") == 0) + else if (strcasecmp (w1, "passwd") == 0) { memcpy (passwd, w2, 24); } - else if (strcmpi (w1, "server_name") == 0) + else if (strcasecmp (w1, "server_name") == 0) { memcpy (server_name, w2, sizeof (server_name)); server_name[sizeof (server_name) - 1] = '\0'; printf ("%s server has been intialized\n", w2); } - else if (strcmpi (w1, "wisp_server_name") == 0) + else if (strcasecmp (w1, "wisp_server_name") == 0) { if (strlen (w2) >= 4) { @@ -3881,7 +3821,7 @@ int char_config_read (const char *cfgName) wisp_server_name[sizeof (wisp_server_name) - 1] = '\0'; } } - else if (strcmpi (w1, "login_ip") == 0) + else if (strcasecmp (w1, "login_ip") == 0) { h = gethostbyname (w2); if (h != NULL) @@ -3900,11 +3840,11 @@ int char_config_read (const char *cfgName) else memcpy (login_ip_str, w2, 16); } - else if (strcmpi (w1, "login_port") == 0) + else if (strcasecmp (w1, "login_port") == 0) { login_port = atoi (w2); } - else if (strcmpi (w1, "char_ip") == 0) + else if (strcasecmp (w1, "char_ip") == 0) { h = gethostbyname (w2); if (h != NULL) @@ -3923,51 +3863,51 @@ int char_config_read (const char *cfgName) else memcpy (char_ip_str, w2, 16); } - else if (strcmpi (w1, "char_port") == 0) + else if (strcasecmp (w1, "char_port") == 0) { char_port = atoi (w2); } - else if (strcmpi (w1, "char_maintenance") == 0) + else if (strcasecmp (w1, "char_maintenance") == 0) { char_maintenance = atoi (w2); } - else if (strcmpi (w1, "char_new") == 0) + else if (strcasecmp (w1, "char_new") == 0) { char_new = atoi (w2); } - else if (strcmpi (w1, "email_creation") == 0) + else if (strcasecmp (w1, "email_creation") == 0) { email_creation = config_switch (w2); } - else if (strcmpi (w1, "char_txt") == 0) + else if (strcasecmp (w1, "char_txt") == 0) { strcpy (char_txt, w2); } - else if (strcmpi (w1, "backup_txt") == 0) + else if (strcasecmp (w1, "backup_txt") == 0) { //By zanetheinsane strcpy (backup_txt, w2); } - else if (strcmpi (w1, "backup_txt_flag") == 0) + else if (strcasecmp (w1, "backup_txt_flag") == 0) { // The backup_txt file was created because char deletion bug existed. Now it's finish and that take a lot of time to create a second file when there are a lot of characters. By [Yor] backup_txt_flag = config_switch (w2); } - else if (strcmpi (w1, "max_connect_user") == 0) + else if (strcasecmp (w1, "max_connect_user") == 0) { max_connect_user = atoi (w2); if (max_connect_user < 0) max_connect_user = 0; // unlimited online players } - else if (strcmpi (w1, "check_ip_flag") == 0) + else if (strcasecmp (w1, "check_ip_flag") == 0) { check_ip_flag = config_switch (w2); } - else if (strcmpi (w1, "autosave_time") == 0) + else if (strcasecmp (w1, "autosave_time") == 0) { autosave_interval = atoi (w2) * 1000; if (autosave_interval <= 0) autosave_interval = DEFAULT_AUTOSAVE_INTERVAL; } - else if (strcmpi (w1, "start_point") == 0) + else if (strcasecmp (w1, "start_point") == 0) { char map[32]; int x, y; @@ -3980,85 +3920,85 @@ int char_config_read (const char *cfgName) start_point.y = y; } } - else if (strcmpi (w1, "start_zeny") == 0) + else if (strcasecmp (w1, "start_zeny") == 0) { start_zeny = atoi (w2); if (start_zeny < 0) start_zeny = 0; } - else if (strcmpi (w1, "start_weapon") == 0) + else if (strcasecmp (w1, "start_weapon") == 0) { start_weapon = atoi (w2); if (start_weapon < 0) start_weapon = 0; } - else if (strcmpi (w1, "start_armor") == 0) + else if (strcasecmp (w1, "start_armor") == 0) { start_armor = atoi (w2); if (start_armor < 0) start_armor = 0; } - else if (strcmpi (w1, "unknown_char_name") == 0) + else if (strcasecmp (w1, "unknown_char_name") == 0) { strcpy (unknown_char_name, w2); unknown_char_name[24] = 0; } - else if (strcmpi (w1, "char_log_filename") == 0) + else if (strcasecmp (w1, "char_log_filename") == 0) { strcpy (char_log_filename, w2); } - else if (strcmpi (w1, "name_ignoring_case") == 0) + else if (strcasecmp (w1, "name_ignoring_case") == 0) { name_ignoring_case = config_switch (w2); } - else if (strcmpi (w1, "char_name_option") == 0) + else if (strcasecmp (w1, "char_name_option") == 0) { char_name_option = atoi (w2); } - else if (strcmpi (w1, "char_name_letters") == 0) + else if (strcasecmp (w1, "char_name_letters") == 0) { strcpy (char_name_letters, w2); // online files options } - else if (strcmpi (w1, "online_txt_filename") == 0) + else if (strcasecmp (w1, "online_txt_filename") == 0) { strcpy (online_txt_filename, w2); } - else if (strcmpi (w1, "online_html_filename") == 0) + else if (strcasecmp (w1, "online_html_filename") == 0) { strcpy (online_html_filename, w2); } - else if (strcmpi (w1, "online_sorting_option") == 0) + else if (strcasecmp (w1, "online_sorting_option") == 0) { online_sorting_option = atoi (w2); } - else if (strcmpi (w1, "online_display_option") == 0) + else if (strcasecmp (w1, "online_display_option") == 0) { online_display_option = atoi (w2); } - else if (strcmpi (w1, "online_gm_display_min_level") == 0) + else if (strcasecmp (w1, "online_gm_display_min_level") == 0) { // minimum GM level to display 'GM' when we want to display it online_gm_display_min_level = atoi (w2); if (online_gm_display_min_level < 5) // send online file every 5 seconds to player is enough online_gm_display_min_level = 5; } - else if (strcmpi (w1, "online_refresh_html") == 0) + else if (strcasecmp (w1, "online_refresh_html") == 0) { online_refresh_html = atoi (w2); if (online_refresh_html < 1) online_refresh_html = 1; } - else if (strcmpi (w1, "anti_freeze_enable") == 0) + else if (strcasecmp (w1, "anti_freeze_enable") == 0) { anti_freeze_enable = config_switch (w2); } - else if (strcmpi (w1, "anti_freeze_interval") == 0) + else if (strcasecmp (w1, "anti_freeze_interval") == 0) { ANTI_FREEZE_INTERVAL = atoi (w2); if (ANTI_FREEZE_INTERVAL < 5) ANTI_FREEZE_INTERVAL = 5; // minimum 5 seconds } - else if (strcmpi (w1, "import") == 0) + else if (strcasecmp (w1, "import") == 0) { char_config_read (w2); } @@ -4068,7 +4008,7 @@ int char_config_read (const char *cfgName) return 0; } -void do_final (void) +void term_func (void) { int i; @@ -4119,15 +4059,14 @@ int do_init (int argc, char **argv) inter_init ((argc > 2) ? argv[2] : inter_cfgName); // inter server 初期化 - set_termfunc (do_final); +// set_termfunc (do_final); set_defaultparse (parse_char); char_fd = make_listen_port (char_port); - add_timer_func_list (check_connect_login_server, - "check_connect_login_server"); - add_timer_func_list (send_users_tologin, "send_users_tologin"); - add_timer_func_list (mmo_char_sync_timer, "mmo_char_sync_timer"); +// add_timer_func_list (check_connect_login_server, "check_connect_login_server"); +// add_timer_func_list (send_users_tologin, "send_users_tologin"); +// add_timer_func_list (mmo_char_sync_timer, "mmo_char_sync_timer"); i = add_timer_interval (gettick () + 1000, check_connect_login_server, 0, 0, 10 * 1000); @@ -4138,8 +4077,7 @@ int do_init (int argc, char **argv) if (anti_freeze_enable > 0) { - add_timer_func_list (map_anti_freeze_system, - "map_anti_freeze_system"); +// add_timer_func_list (map_anti_freeze_system, "map_anti_freeze_system"); i = add_timer_interval (gettick () + 1000, map_anti_freeze_system, 0, 0, ANTI_FREEZE_INTERVAL * 1000); // checks every X seconds user specifies } diff --git a/src/char/int_guild.c b/src/char/int_guild.c index e145b66..9715700 100644 --- a/src/char/int_guild.c +++ b/src/char/int_guild.c @@ -30,7 +30,7 @@ int guild_calcinfo (struct guild *g); int mapif_guild_basicinfochanged (int guild_id, int type, const void *data, int len); int mapif_guild_info (int fd, struct guild *g); -int guild_break_sub (void *key, void *data, va_list ap); +void guild_break_sub (db_key_t key, db_val_t data, va_list ap); // ギルドデータの文字列への変換 int inter_guild_tostr (char *str, struct guild *g) @@ -448,14 +448,7 @@ int inter_guild_init () guild_newid = i; continue; } - - g = calloc (sizeof (struct guild), 1); - if (g == NULL) - { - printf ("int_guild: out of memory!\n"); - exit (0); - } - memset (g, 0, sizeof (struct guild)); + CREATE (g, struct guild, 1); if (inter_guild_fromstr (line, g) == 0 && g->guild_id > 0) { if (g->guild_id >= guild_newid) @@ -483,13 +476,7 @@ int inter_guild_init () while (fgets (line, sizeof (line) - 1, fp)) { - gc = calloc (sizeof (struct guild_castle), 1); - if (gc == NULL) - { - printf ("int_guild: out of memory!\n"); - exit (0); - } - memset (gc, 0, sizeof (struct guild_castle)); + CREATE (gc, struct guild_castle, 1); if (inter_guildcastle_fromstr (line, gc) == 0) { numdb_insert (castle_db, gc->castle_id, gc); @@ -508,13 +495,7 @@ int inter_guild_init () //デフォルトデータを作成 for (i = 0; i < MAX_GUILDCASTLE; i++) { - gc = calloc (sizeof (struct guild_castle), 1); - if (gc == NULL) - { - printf ("int_guild: out of memory!\n"); - exit (0); - } - memset (gc, 0, sizeof (struct guild_castle)); + CREATE (gc, struct guild_castle, 1); gc->castle_id = i; gc->guild_id = 0; gc->economy = 0; @@ -562,7 +543,7 @@ struct guild *inter_guild_search (int guild_id) } // ギルドデータのセーブ用 -int inter_guild_save_sub (void *key, void *data, va_list ap) +void inter_guild_save_sub (db_key_t key, db_val_t data, va_list ap) { char line[16384]; FILE *fp; @@ -570,12 +551,10 @@ int inter_guild_save_sub (void *key, void *data, va_list ap) inter_guild_tostr (line, (struct guild *) data); fp = va_arg (ap, FILE *); fprintf (fp, "%s" RETCODE, line); - - return 0; } // ギルド城データのセーブ用 -int inter_castle_save_sub (void *key, void *data, va_list ap) +void inter_castle_save_sub (db_key_t key, db_val_t data, va_list ap) { char line[16384]; FILE *fp; @@ -583,8 +562,6 @@ int inter_castle_save_sub (void *key, void *data, va_list ap) inter_guildcastle_tostr (line, (struct guild_castle *) data); fp = va_arg (ap, FILE *); fprintf (fp, "%s" RETCODE, line); - - return 0; } // ギルドデータのセーブ @@ -617,16 +594,15 @@ int inter_guild_save () } // ギルド名検索用 -int search_guildname_sub (void *key, void *data, va_list ap) +void search_guildname_sub (db_key_t key, db_val_t data, va_list ap) { struct guild *g = (struct guild *) data, **dst; char *str; str = va_arg (ap, char *); dst = va_arg (ap, struct guild **); - if (strcmpi (g->name, str) == 0) + if (strcasecmp (g->name, str) == 0) *dst = g; - return 0; } // ギルド名検索 @@ -660,7 +636,7 @@ int guild_check_empty (struct guild *g) } // キャラの競合がないかチェック用 -int guild_check_conflict_sub (void *key, void *data, va_list ap) +void guild_check_conflict_sub (db_key_t key, db_val_t data, va_list ap) { struct guild *g = (struct guild *) data; int guild_id, account_id, char_id, i; @@ -670,7 +646,7 @@ int guild_check_conflict_sub (void *key, void *data, va_list ap) char_id = va_arg (ap, int); if (g->guild_id == guild_id) // 本来の所属なので問題なし - return 0; + return; for (i = 0; i < MAX_GUILD; i++) { @@ -683,8 +659,6 @@ int guild_check_conflict_sub (void *key, void *data, va_list ap) "**データ競合**"); } } - - return 0; } // キャラの競合がないかチェック @@ -1037,7 +1011,7 @@ int mapif_guild_castle_datasave (int castle_id, int index, int value) return 0; } -int mapif_guild_castle_alldataload_sub (void *key, void *data, va_list ap) +void mapif_guild_castle_alldataload_sub (db_key_t key, db_val_t data, va_list ap) { int fd = va_arg (ap, int); int *p = va_arg (ap, int *); @@ -1045,8 +1019,6 @@ int mapif_guild_castle_alldataload_sub (void *key, void *data, va_list ap) memcpy (WFIFOP (fd, *p), (struct guild_castle *) data, sizeof (struct guild_castle)); (*p) += sizeof (struct guild_castle); - - return 0; } int mapif_guild_castle_alldataload (int fd) @@ -1087,14 +1059,7 @@ int mapif_parse_CreateGuild (int fd, int account_id, char *name, mapif_guild_created (fd, account_id, NULL); return 0; } - g = calloc (sizeof (struct guild), 1); - if (g == NULL) - { - printf ("int_guild: CreateGuild: out of memory !\n"); - mapif_guild_created (fd, account_id, NULL); - exit (0); - } - memset (g, 0, sizeof (struct guild)); + CREATE (g, struct guild, 1); g->guild_id = guild_newid++; memcpy (g->name, name, 24); memcpy (g->master, master->name, 24); @@ -1263,7 +1228,7 @@ int mapif_parse_GuildChangeMemberInfoShort (int fd, int guild_id, } // ギルド解散処理用(同盟/敵対を解除) -int guild_break_sub (void *key, void *data, va_list ap) +void guild_break_sub (db_key_t key, db_val_t data, va_list ap) { struct guild *g = (struct guild *) data; int guild_id = va_arg (ap, int); @@ -1274,7 +1239,6 @@ int guild_break_sub (void *key, void *data, va_list ap) if (g->alliance[i].guild_id == guild_id) g->alliance[i].guild_id = 0; } - return 0; } // ギルド解散要求 diff --git a/src/char/int_party.c b/src/char/int_party.c index c5ed033..b728b1e 100644 --- a/src/char/int_party.c +++ b/src/char/int_party.c @@ -110,13 +110,7 @@ int inter_party_init () continue; } - p = calloc (sizeof (struct party), 1); - if (p == NULL) - { - printf ("int_party: out of memory!\n"); - exit (0); - } - memset (p, 0, sizeof (struct party)); + CREATE (p, struct party, 1); if (inter_party_fromstr (line, p) == 0 && p->party_id > 0) { if (p->party_id >= party_newid) @@ -139,7 +133,7 @@ int inter_party_init () } // パーティーデータのセーブ用 -int inter_party_save_sub (void *key, void *data, va_list ap) +void inter_party_save_sub (db_key_t key, db_val_t data, va_list ap) { char line[8192]; FILE *fp; @@ -147,8 +141,6 @@ int inter_party_save_sub (void *key, void *data, va_list ap) inter_party_tostr (line, (struct party *) data); fp = va_arg (ap, FILE *); fprintf (fp, "%s" RETCODE, line); - - return 0; } // パーティーデータのセーブ @@ -172,17 +164,15 @@ int inter_party_save () } // パーティ名検索用 -int search_partyname_sub (void *key, void *data, va_list ap) +void search_partyname_sub (db_key_t key, db_val_t data, va_list ap) { struct party *p = (struct party *) data, **dst; char *str; str = va_arg (ap, char *); dst = va_arg (ap, struct party **); - if (strcmpi (p->name, str) == 0) + if (strcasecmp (p->name, str) == 0) *dst = p; - - return 0; } // パーティ名検索 @@ -238,7 +228,7 @@ int party_check_empty (struct party *p) } // キャラの競合がないかチェック用 -int party_check_conflict_sub (void *key, void *data, va_list ap) +void party_check_conflict_sub (db_key_t key, db_val_t data, va_list ap) { struct party *p = (struct party *) data; int party_id, account_id, i; @@ -249,7 +239,7 @@ int party_check_conflict_sub (void *key, void *data, va_list ap) nick = va_arg (ap, char *); if (p->party_id == party_id) // 本来の所属なので問題なし - return 0; + return; for (i = 0; i < MAX_PARTY; i++) { @@ -262,8 +252,6 @@ int party_check_conflict_sub (void *key, void *data, va_list ap) mapif_parse_PartyLeave (-1, p->party_id, account_id); } } - - return 0; } // キャラの競合がないかチェック @@ -449,14 +437,7 @@ int mapif_parse_CreateParty (int fd, int account_id, char *name, char *nick, mapif_party_created (fd, account_id, NULL); return 0; } - p = calloc (sizeof (struct party), 1); - if (p == NULL) - { - printf ("int_party: out of memory !\n"); - mapif_party_created (fd, account_id, NULL); - return 0; - } - memset (p, 0, sizeof (struct party)); + CREATE (p, struct party, 1); p->party_id = party_newid++; memcpy (p->name, name, 24); p->exp = 0; diff --git a/src/char/int_storage.c b/src/char/int_storage.c index 744a59f..99af725 100644 --- a/src/char/int_storage.c +++ b/src/char/int_storage.c @@ -7,7 +7,6 @@ #include "../common/socket.h" #include "../common/db.h" #include "../common/lock.h" -#include "../common/malloc.h" #include "char.h" #include "inter.h" #include "int_storage.h" @@ -222,12 +221,7 @@ struct storage *account2storage (int account_id) s = (struct storage *) numdb_search (storage_db, account_id); if (s == NULL) { - s = (struct storage *) aCalloc (sizeof (struct storage), 1); - if (s == NULL) - { - printf ("int_storage: out of memory!\n"); - exit (0); - } + CREATE (s, struct storage, 1); memset (s, 0, sizeof (struct storage)); s->account_id = account_id; numdb_insert (storage_db, s->account_id, s); @@ -244,14 +238,7 @@ struct guild_storage *guild2storage (int guild_id) guild_id); if (gs == NULL) { - gs = (struct guild_storage *) - aCalloc (sizeof (struct guild_storage), 1); - if (gs == NULL) - { - printf ("int_storage: out of memory!\n"); - exit (0); - } -// memset(gs,0,sizeof(struct guild_storage)); aCalloc does this! [Skotlex] + CREATE (gs, struct guild_storage, 1); gs->guild_id = guild_id; numdb_insert (guild_storage_db, gs->guild_id, gs); } @@ -280,13 +267,7 @@ int inter_storage_init () while (fgets (line, 65535, fp)) { sscanf (line, "%d", &tmp_int); - s = (struct storage *) aCalloc (sizeof (struct storage), 1); - if (s == NULL) - { - printf ("int_storage: out of memory!\n"); - exit (0); - } -// memset(s,0,sizeof(struct storage)); aCalloc does this... + CREATE (s, struct storage, 1); s->account_id = tmp_int; if (s->account_id > 0 && storage_fromstr (line, s) == 0) { @@ -314,14 +295,7 @@ int inter_storage_init () while (fgets (line, 65535, fp)) { sscanf (line, "%d", &tmp_int); - gs = (struct guild_storage *) aCalloc (sizeof (struct guild_storage), - 1); - if (gs == NULL) - { - printf ("int_storage: out of memory!\n"); - exit (0); - } -// memset(gs,0,sizeof(struct guild_storage)); aCalloc... + CREATE (gs, struct guild_storage, 1); gs->guild_id = tmp_int; if (gs->guild_id > 0 && guild_storage_fromstr (line, gs) == 0) { @@ -340,20 +314,18 @@ int inter_storage_init () return 0; } -int storage_db_final (void *k, void *data, va_list ap) +void storage_db_final (db_key_t k, db_val_t data, va_list ap) { struct storage *p = (struct storage *) data; if (p) free (p); - return 0; } -int guild_storage_db_final (void *k, void *data, va_list ap) +void guild_storage_db_final (db_key_t k, db_val_t data, va_list ap) { struct guild_storage *p = (struct guild_storage *) data; if (p) free (p); - return 0; } void inter_storage_final () @@ -363,7 +335,7 @@ void inter_storage_final () return; } -int inter_storage_save_sub (void *key, void *data, va_list ap) +void inter_storage_save_sub (db_key_t key, db_val_t data, va_list ap) { char line[65536]; FILE *fp; @@ -371,7 +343,6 @@ int inter_storage_save_sub (void *key, void *data, va_list ap) fp = va_arg (ap, FILE *); if (*line) fprintf (fp, "%s" RETCODE, line); - return 0; } //--------------------------------------------------------- @@ -396,7 +367,7 @@ int inter_storage_save () return 0; } -int inter_guild_storage_save_sub (void *key, void *data, va_list ap) +void inter_guild_storage_save_sub (db_key_t key, db_val_t data, va_list ap) { char line[65536]; FILE *fp; @@ -409,7 +380,6 @@ int inter_guild_storage_save_sub (void *key, void *data, va_list ap) if (*line) fprintf (fp, "%s" RETCODE, line); } - return 0; } //--------------------------------------------------------- diff --git a/src/char/inter.c b/src/char/inter.c index 5bee90f..f563931 100644 --- a/src/char/inter.c +++ b/src/char/inter.c @@ -120,13 +120,7 @@ int inter_accreg_init () while (fgets (line, sizeof (line) - 1, fp)) { line[sizeof (line) - 1] = '\0'; - - reg = calloc (sizeof (struct accreg), 1); - if (reg == NULL) - { - printf ("inter: accreg: out of memory!\n"); - exit (0); - } + CREATE (reg, struct accreg, 1); if (inter_accreg_fromstr (line, reg) == 0 && reg->account_id > 0) { numdb_insert (accreg_db, reg->account_id, reg); @@ -146,7 +140,7 @@ int inter_accreg_init () } // アカウント変数のセーブ用 -int inter_accreg_save_sub (void *key, void *data, va_list ap) +void inter_accreg_save_sub (db_key_t key, db_val_t data, va_list ap) { char line[8192]; FILE *fp; @@ -158,8 +152,6 @@ int inter_accreg_save_sub (void *key, void *data, va_list ap) fp = va_arg (ap, FILE *); fprintf (fp, "%s" RETCODE, line); } - - return 0; } // アカウント変数のセーブ @@ -207,41 +199,41 @@ int inter_config_read (const char *cfgName) if (sscanf (line, "%[^:]: %[^\r\n]", w1, w2) != 2) continue; - if (strcmpi (w1, "storage_txt") == 0) + if (strcasecmp (w1, "storage_txt") == 0) { strncpy (storage_txt, w2, sizeof (storage_txt)); } - else if (strcmpi (w1, "party_txt") == 0) + else if (strcasecmp (w1, "party_txt") == 0) { strncpy (party_txt, w2, sizeof (party_txt)); } - else if (strcmpi (w1, "guild_txt") == 0) + else if (strcasecmp (w1, "guild_txt") == 0) { strncpy (guild_txt, w2, sizeof (guild_txt)); } - else if (strcmpi (w1, "castle_txt") == 0) + else if (strcasecmp (w1, "castle_txt") == 0) { strncpy (castle_txt, w2, sizeof (castle_txt)); } - else if (strcmpi (w1, "accreg_txt") == 0) + else if (strcasecmp (w1, "accreg_txt") == 0) { strncpy (accreg_txt, w2, sizeof (accreg_txt)); } - else if (strcmpi (w1, "guild_storage_txt") == 0) + else if (strcasecmp (w1, "guild_storage_txt") == 0) { strncpy (guild_storage_txt, w2, sizeof (guild_storage_txt)); } - else if (strcmpi (w1, "party_share_level") == 0) + else if (strcasecmp (w1, "party_share_level") == 0) { party_share_level = atoi (w2); if (party_share_level < 0) party_share_level = 0; } - else if (strcmpi (w1, "inter_log_filename") == 0) + else if (strcasecmp (w1, "inter_log_filename") == 0) { strncpy (inter_log_filename, w2, sizeof (inter_log_filename)); } - else if (strcmpi (w1, "import") == 0) + else if (strcasecmp (w1, "import") == 0) { inter_config_read (w2); } @@ -392,7 +384,7 @@ int mapif_account_reg_reply (int fd, int account_id) //-------------------------------------------------------- // Existence check of WISP data -int check_ttl_wisdata_sub (void *key, void *data, va_list ap) +void check_ttl_wisdata_sub (db_key_t key, db_val_t data, va_list ap) { unsigned long tick; struct WisData *wd = (struct WisData *) data; @@ -401,8 +393,6 @@ int check_ttl_wisdata_sub (void *key, void *data, va_list ap) if (DIFF_TICK (tick, wd->tick) > WISDATA_TTL && wis_delnum < WISDELLIST_MAX) wis_dellist[wis_delnum++] = wd->id; - - return 0; } int check_ttl_wisdata () @@ -485,13 +475,7 @@ int mapif_parse_WisRequest (int fd) } else { - - wd = (struct WisData *) calloc (sizeof (struct WisData), 1); - if (wd == NULL) - { - printf ("inter: WisRequest: out of memory !\n"); - return 0; - } + CREATE (wd, struct WisData, 1); // Whether the failure of previous wisp/page transmission (timeout) check_ttl_wisdata (); @@ -546,17 +530,13 @@ int mapif_parse_WisToGM (int fd) int mapif_parse_AccReg (int fd) { int j, p; - struct accreg *reg = numdb_search (accreg_db, RFIFOL (fd, 4)); + struct accreg *reg = numdb_search (accreg_db, (numdb_key_t)RFIFOL (fd, 4)); if (reg == NULL) { - if ((reg = calloc (sizeof (struct accreg), 1)) == NULL) - { - printf ("inter: accreg: out of memory !\n"); - exit (0); - } + CREATE (reg, struct accreg, 1); reg->account_id = RFIFOL (fd, 4); - numdb_insert (accreg_db, RFIFOL (fd, 4), reg); + numdb_insert (accreg_db, (numdb_key_t)RFIFOL (fd, 4), reg); } for (j = 0, p = 8; j < ACCOUNT_REG_NUM && p < RFIFOW (fd, 2); diff --git a/src/common/Makefile b/src/common/Makefile index 549268b..43552dc 100644 --- a/src/common/Makefile +++ b/src/common/Makefile @@ -1,5 +1,5 @@ include ../../make.defs -all: core.o socket.o timer.o grfio.o db.o lock.o nullpo.o malloc.o mt_rand.o md5calc.o +all: core.o socket.o timer.o grfio.o db.o lock.o nullpo.o mt_rand.o md5calc.o core.o: core.c core.h socket.o: socket.c socket.h mmo.h @@ -8,7 +8,6 @@ grfio.o: grfio.c grfio.h db.o: db.c db.h lock.o: lock.c lock.h nullpo.o: nullpo.c nullpo.h -malloc.o: malloc.c malloc.h mt_rand.o: mt_rand.c mt_rand.h md5calc.o: md5calc.c md5calc.h diff --git a/src/common/core.c b/src/common/core.c index bf48dfc..2b1b67c 100644 --- a/src/common/core.c +++ b/src/common/core.c @@ -1,11 +1,6 @@ -// $Id: core.c,v 1.1.1.1 2004/09/10 17:44:49 MagicalTux Exp $ -// original : core.c 2003/02/26 18:03:12 Rev 1.7 - #include #include -#ifndef LCCWIN32 #include -#endif #include #include @@ -14,84 +9,23 @@ #include "timer.h" #include "version.h" #include "mt_rand.h" +#include "nullpo.h" -#ifdef MEMWATCH -#include "memwatch.h" -#endif - -static void (*term_func) (void) = NULL; - -/*====================================== - * CORE : Set function - *-------------------------------------- - */ -void set_termfunc (void (*termfunc) (void)) -{ - term_func = termfunc; -} - -/*====================================== - * CORE : Signal Sub Function - *-------------------------------------- - */ +/// Defined by each server +extern int do_init (int, char **); +extern void term_func (void); -static void sig_proc (int sn) +static void chld_proc (int UNUSED) { - int i; - switch (sn) - { - case SIGINT: - case SIGTERM: - if (term_func) - term_func (); - for (i = 0; i < fd_max; i++) - { - if (!session[i]) - continue; - close (i); - } - exit (0); - break; - case SIGCHLD: - wait (&i); - break; - } + wait(NULL); } - -int eathena_interactive_session = 1; // [fate] interactive session: print pretty graphics - -/*====================================== - * CORE : Display title - *-------------------------------------- - */ - -static void display_title (void) +static void sig_proc (int UNUSED) { - // for help with the console colors look here: - // http://www.edoceo.com/liberum/?doc=printf-with-color - // some code explanation (used here): - // \033[2J : clear screen and go up/left (0, 0 position) - // \033[K : clear line from actual position to end of the line - // \033[0m : reset color parameter - // \033[1m : use bold for font - if (eathena_interactive_session) - { - printf ("\033[2J"); // clear screen and go up/left (0, 0 position in text) - printf ("\033[37;44m (=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=)\033[K\033[0m\n"); // white writing (37) on blue background (44), \033[K clean until end of file - printf ("\033[0;44m (\033[1;33m (c)2004 eAthena Development Team presents \033[0;44m)\033[K\033[0m\n"); // yellow writing (33) - printf ("\033[0;44m (\033[1m ______ __ __ \033[0;44m)\033[K\033[0m\n"); // 1: bold char, 0: normal char - printf ("\033[0;44m (\033[1m /\\ _ \\/\\ \\__/\\ \\ v%2d.%02d.%02d \033[0;44m)\033[K\033[0m\n", ATHENA_MAJOR_VERSION, ATHENA_MINOR_VERSION, ATHENA_REVISION); // 1: bold char, 0: normal char - printf ("\033[0;44m (\033[1m __\\ \\ \\_\\ \\ \\ ,_\\ \\ \\___ __ ___ __ \033[0;44m)\033[K\033[0m\n"); // 1: bold char, 0: normal char - printf ("\033[0;44m (\033[1m /'__`\\ \\ __ \\ \\ \\/\\ \\ _ `\\ /'__`\\/' _ `\\ /'__`\\ \033[0;44m)\033[K\033[0m\n"); // 1: bold char, 0: normal char - printf ("\033[0;44m (\033[1m /\\ __/\\ \\ \\/\\ \\ \\ \\_\\ \\ \\ \\ \\/\\ __//\\ \\/\\ \\/\\ \\_\\.\\_ \033[0;44m)\033[K\033[0m\n"); // 1: bold char, 0: normal char - printf ("\033[0;44m (\033[1m \\ \\____\\\\ \\_\\ \\_\\ \\__\\\\ \\_\\ \\_\\ \\____\\ \\_\\ \\_\\ \\__/.\\_\\ \033[0;44m)\033[K\033[0m\n"); // 1: bold char, 0: normal char - printf ("\033[0;44m (\033[1m \\/____/ \\/_/\\/_/\\/__/ \\/_/\\/_/\\/____/\\/_/\\/_/\\/__/\\/_/ \033[0;44m)\033[K\033[0m\n"); // 1: bold char, 0: normal char - printf ("\033[0;44m (\033[1m _ _ _ _ _ _ _ _ _ _ _ _ _ \033[0;44m)\033[K\033[0m\n"); // 1: bold char, 0: normal char - printf ("\033[0;44m (\033[1m / \\ / \\ / \\ / \\ / \\ / \\ / \\ / \\ / \\ / \\ / \\ / \\ / \\ \033[0;44m)\033[K\033[0m\n"); // 1: bold char, 0: normal char - printf ("\033[0;44m (\033[1m ( e | n | g | l | i | s | h ) ( A | t | h | e | n | a ) \033[0;44m)\033[K\033[0m\n"); // 1: bold char, 0: normal char - printf ("\033[0;44m (\033[1m \\_/ \\_/ \\_/ \\_/ \\_/ \\_/ \\_/ \\_/ \\_/ \\_/ \\_/ \\_/ \\_/ \033[0;44m)\033[K\033[0m\n"); // 1: bold char, 0: normal char - printf ("\033[37;44m (=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=)\033[K\033[0m\n\n"); // reset color - } + term_func (); + for (int i = 0; i < fd_max; i++) + if (session[i]) + close (i); + exit (0); } // Added by Gabuzomeu @@ -100,69 +34,45 @@ static void display_title (void) // (sigaction() is POSIX; signal() is not.) Taken from Stevens' _Advanced // Programming in the UNIX Environment_. // -#ifndef SIGPIPE -#define SIGPIPE SIGINT -#endif - -#ifndef POSIX -#define compat_signal(signo, func) signal(signo, func) -#else -sigfunc *compat_signal (int signo, sigfunc * func) +typedef void (*sigfunc)(int); +sigfunc compat_signal (int signo, sigfunc func) { struct sigaction sact, oact; sact.sa_handler = func; sigemptyset (&sact.sa_mask); sact.sa_flags = 0; -#ifdef SA_INTERRUPT - sact.sa_flags |= SA_INTERRUPT; /* SunOS */ -#endif if (sigaction (signo, &sact, &oact) < 0) - return (SIG_ERR); + return SIG_ERR; - return (oact.sa_handler); + return oact.sa_handler; } -#endif -/*====================================== - * CORE : MAINROUTINE - *-------------------------------------- - */ - -int runflag = 1; +bool runflag = true; int main (int argc, char **argv) { - int next; - - mt_seed (time (NULL) ^ getpid () ^ getppid ()); + /// Note that getpid() and getppid() may be very close + mt_seed (time (NULL) ^ (getpid () << 16) ^ (getppid () << 8)); - Net_Init (); do_socket (); compat_signal (SIGPIPE, SIG_IGN); compat_signal (SIGTERM, sig_proc); compat_signal (SIGINT, sig_proc); - compat_signal (SIGCHLD, sig_proc); + compat_signal (SIGCHLD, chld_proc); // Signal to create coredumps by system when necessary (crash) compat_signal (SIGSEGV, SIG_DFL); -#ifndef LCCWIN32 compat_signal (SIGBUS, SIG_DFL); compat_signal (SIGTRAP, SIG_DFL); -#endif compat_signal (SIGILL, SIG_DFL); - // [fate] detect interactive session - eathena_interactive_session = isatty (0); - display_title (); do_init (argc, argv); while (runflag) { - next = do_timer (gettick_nocache ()); - do_sendrecv (next); + do_sendrecv (do_timer (gettick_nocache ())); do_parsepacket (); } - return 0; } diff --git a/src/common/core.h b/src/common/core.h index 90d8303..6722ca2 100644 --- a/src/common/core.h +++ b/src/common/core.h @@ -1,12 +1,19 @@ -// original : core.h 2003/03/14 11:55:25 Rev 1.4 +#ifndef CORE_H +#define CORE_H +#include +/// core.c contains a server-independent main() function +/// and then runs a do_sendrecv loop -#ifndef _CORE_H_ -#define _CORE_H_ +/// When this is cleared, the server exits gracefully +/// only used by map server's GM command: @mapexit +extern bool runflag; -extern int runflag; +/// This is an external function defined by each server +/// This function must register stuff for the parse loop +extern int do_init (int, char **); -int do_init (int, char **); +/// Cleanup function called whenever a signal kills us +/// NOT currently called when exit() is called +extern void term_func (void); -void set_termfunc (void (*termfunc) (void)); - -#endif // _CORE_H_ +#endif // CORE_H diff --git a/src/common/db.c b/src/common/db.c index 07b08c8..cee17df 100644 --- a/src/common/db.c +++ b/src/common/db.c @@ -1,125 +1,93 @@ -// $Id: db.c,v 1.2 2004/09/23 14:43:06 MouseJstr Exp $ -// #define MALLOC_DBN +#include "db.h" + #include #include #include -#include "db.h" -#include "utils.h" -#ifdef MEMWATCH -#include "memwatch.h" -#endif +#include "utils.h" #define ROOT_SIZE 4096 -#ifdef MALLOC_DBN -static struct dbn *dbn_root[512], *dbn_free; -static int dbn_root_rest = 0, dbn_root_num = 0; - -static void *malloc_dbn (void) -{ - struct dbn *ret; - - if (dbn_free == NULL) - { - if (dbn_root_rest <= 0) - { - CREATE (dbn_root[dbn_root_num], struct dbn, ROOT_SIZE); - - dbn_root_rest = ROOT_SIZE; - dbn_root_num++; - } - return &(dbn_root[dbn_root_num - 1][--dbn_root_rest]); - } - ret = dbn_free; - dbn_free = dbn_free->parent; - return ret; -} - -static void free_dbn (struct dbn *add_dbn) -{ - add_dbn->parent = dbn_free; - dbn_free = add_dbn; -} -#endif -static int strdb_cmp (struct dbt *table, void *a, void *b) +static int strdb_cmp (struct dbt *table, const char *a, const char* b) { if (table->maxlen) return strncmp (a, b, table->maxlen); return strcmp (a, b); } -static unsigned int strdb_hash (struct dbt *table, void *a) +static hash_t strdb_hash (struct dbt *table, const char *a) { - int i; - unsigned int h; - unsigned char *p = a; - - i = table->maxlen; + size_t i = table->maxlen; if (i == 0) - i = 0x7fffffff; - for (h = 0; *p && --i >= 0;) + i = (size_t)-1; + hash_t h = 0; + const unsigned char *p = (const unsigned char*)a; + while (*p && i--) { h = (h * 33 + *p++) ^ (h >> 24); } return h; } -struct dbt *strdb_init (int maxlen) +struct dbt *strdb_init (size_t maxlen) { - int i; struct dbt *table; - CREATE (table, struct dbt, 1); - - table->cmp = strdb_cmp; - table->hash = strdb_hash; + table->type = DB_STRING; table->maxlen = maxlen; - for (i = 0; i < HASH_SIZE; i++) - table->ht[i] = NULL; return table; } -static int numdb_cmp (struct dbt *table, void *a, void *b) +static int numdb_cmp (numdb_key_t a, numdb_key_t b) { - int ia, ib; - - ia = (int) a; - ib = (int) b; - - if ((ia ^ ib) & 0x80000000) - return ia < 0 ? -1 : 1; - - return ia - ib; + if (a == b) + return 0; + if (a < b) + return -1; + return 1; } -static unsigned int numdb_hash (struct dbt *table, void *a) +static hash_t numdb_hash (numdb_key_t a) { - return (unsigned int) a; + return (hash_t) a; } struct dbt *numdb_init (void) { - int i; struct dbt *table; - CREATE (table, struct dbt, 1); - - table->cmp = numdb_cmp; - table->hash = numdb_hash; - table->maxlen = sizeof (int); - for (i = 0; i < HASH_SIZE; i++) - table->ht[i] = NULL; + table->type = DB_NUMBER; return table; } -void *db_search (struct dbt *table, void *key) +static int table_cmp (struct dbt *table, db_key_t a, db_key_t b) +{ + switch(table->type) + { + case DB_NUMBER: return numdb_cmp (a.i, b.i); + case DB_STRING: return strdb_cmp (table, a.s, b.s); + } + abort(); +} + +static hash_t table_hash (struct dbt *table, db_key_t key) +{ + switch(table->type) + { + case DB_NUMBER: return numdb_hash (key.i); + case DB_STRING: return strdb_hash (table, key.s); + } + abort(); +} + +/// Search for a node with the given key +db_val_t db_search (struct dbt *table, db_key_t key) { - struct dbn *p; + struct dbn *p = table->ht[table_hash (table, key) % HASH_SIZE]; - for (p = table->ht[table->hash (table, key) % HASH_SIZE]; p;) + while (p) { - int c = table->cmp (table, key, p->key); + int c = table_cmp (table, key, p->key); if (c == 0) return p->data; if (c < 0) @@ -130,52 +98,12 @@ void *db_search (struct dbt *table, void *key) return NULL; } -void *db_search2 (struct dbt *table, const char *key) -{ - int i, sp; - struct dbn *p, *pn, *stack[64]; - int slen = strlen (key); - - for (i = 0; i < HASH_SIZE; i++) - { - if ((p = table->ht[i]) == NULL) - continue; - sp = 0; - while (1) - { - if (strncasecmp (key, p->key, slen) == 0) - return p->data; - if ((pn = p->left) != NULL) - { - if (p->right) - { - stack[sp++] = p->right; - } - p = pn; - } - else - { - if (p->right) - { - p = p->right; - } - else - { - if (sp == 0) - break; - p = stack[--sp]; - } - } - } - } - return 0; -} - +// Tree maintainance methods static void db_rotate_left (struct dbn *p, struct dbn **root) { struct dbn *y = p->right; p->right = y->left; - if (y->left != 0) + if (y->left) y->left->parent = p; y->parent = p->parent; @@ -193,7 +121,7 @@ static void db_rotate_right (struct dbn *p, struct dbn **root) { struct dbn *y = p->left; p->left = y->right; - if (y->right != 0) + if (y->right) y->right->parent = p; y->parent = p->parent; @@ -211,7 +139,7 @@ static void db_rebalance (struct dbn *p, struct dbn **root) { p->color = RED; while (p != *root && p->parent->color == RED) - { // rootは必ず黒で親は赤いので親の親は必ず存在する + { if (p->parent == p->parent->parent->left) { struct dbn *y = p->parent->parent->right; @@ -260,23 +188,26 @@ static void db_rebalance (struct dbn *p, struct dbn **root) (*root)->color = BLACK; } +// param z = node to remove static void db_rebalance_erase (struct dbn *z, struct dbn **root) { - struct dbn *y = z, *x = NULL, *x_parent = NULL; + struct dbn *y = z; + struct dbn *x = NULL; - if (y->left == NULL) + if (!y->left) x = y->right; - else if (y->right == NULL) + else if (!y->right) x = y->left; else { y = y->right; - while (y->left != NULL) + while (y->left) y = y->left; x = y->right; } + struct dbn *x_parent = NULL; if (y != z) - { // 左右が両方埋まっていた時 yをzの位置に持ってきてzを浮かせる + { z->left->parent = y; y->left = z->left; if (y != z->right) @@ -305,7 +236,7 @@ static void db_rebalance_erase (struct dbn *z, struct dbn **root) y = z; } else - { // どちらか空いていた場合 xをzの位置に持ってきてzを浮かせる + { x_parent = y->parent; if (x) x->parent = y->parent; @@ -316,10 +247,9 @@ static void db_rebalance_erase (struct dbn *z, struct dbn **root) else z->parent->right = x; } - // ここまで色の移動の除いて通常の2分木と同じ if (y->color != RED) - { // 赤が消える分には影響無し - while (x != *root && (x == NULL || x->color == BLACK)) + { + while (x != *root && (!x || x->color == BLACK)) if (x == x_parent->left) { struct dbn *w = x_parent->right; @@ -330,17 +260,16 @@ static void db_rebalance_erase (struct dbn *z, struct dbn **root) db_rotate_left (x_parent, root); w = x_parent->right; } - if ((w->left == NULL || - w->left->color == BLACK) && - (w->right == NULL || w->right->color == BLACK)) + if ((!w->left || w->left->color == BLACK) && + (!w->right || w->right->color == BLACK)) { w->color = RED; x = x_parent; - x_parent = x_parent->parent; + x_parent = x->parent; } else { - if (w->right == NULL || w->right->color == BLACK) + if (!w->right|| w->right->color == BLACK) { if (w->left) w->left->color = BLACK; @@ -357,7 +286,8 @@ static void db_rebalance_erase (struct dbn *z, struct dbn **root) } } else - { // same as above, with right <-> left. + { + // same as above, with right <-> left. struct dbn *w = x_parent->left; if (w->color == RED) { @@ -366,9 +296,8 @@ static void db_rebalance_erase (struct dbn *z, struct dbn **root) db_rotate_right (x_parent, root); w = x_parent->left; } - if ((w->right == NULL || - w->right->color == BLACK) && - (w->left == NULL || w->left->color == BLACK)) + if ((!w->right || w->right->color == BLACK) && + (!w->left || w->left->color == BLACK)) { w->color = RED; x = x_parent; @@ -376,7 +305,7 @@ static void db_rebalance_erase (struct dbn *z, struct dbn **root) } else { - if (w->left == NULL || w->left->color == BLACK) + if (!w->left || w->left->color == BLACK) { if (w->right) w->right->color = BLACK; @@ -397,46 +326,33 @@ static void db_rebalance_erase (struct dbn *z, struct dbn **root) } } -struct dbn *db_insert (struct dbt *table, void *key, void *data) +struct dbn *db_insert (struct dbt *table, db_key_t key, db_val_t data) { - struct dbn *p, *priv; - int c, hash; - - hash = table->hash (table, key) % HASH_SIZE; - for (c = 0, priv = NULL, p = table->ht[hash]; p;) + hash_t hash = table_hash (table, key) % HASH_SIZE; + int c = 0; + struct dbn *prev = NULL; + struct dbn *p = table->ht[hash]; + while (p) { - c = table->cmp (table, key, p->key); + c = table_cmp (table, key, p->key); if (c == 0) - { // replace + { + // key found in table, replace + // Tell the user of the table to free the key and value if (table->release) - table->release (p, 3); + table->release (p->key, p->data); p->data = data; p->key = key; return p; } - priv = p; + // prev is always p->parent? + prev = p; if (c < 0) - { p = p->left; - } else - { p = p->right; - } } -#ifdef MALLOC_DBN - p = malloc_dbn (); -#else CREATE (p, struct dbn, 1); -#endif - if (p == NULL) - { - printf ("out of memory : db_insert\n"); - return NULL; - } - p->parent = NULL; - p->left = NULL; - p->right = NULL; p->key = key; p->data = data; p->color = RED; @@ -444,37 +360,28 @@ struct dbn *db_insert (struct dbt *table, void *key, void *data) { // hash entry is empty table->ht[hash] = p; p->color = BLACK; + return p; } + p->parent = prev; + if (c < 0) + prev->left = p; else + prev->right = p; + if (prev->color == RED) { - if (c < 0) - { // left node - priv->left = p; - p->parent = priv; - } - else - { // right node - priv->right = p; - p->parent = priv; - } - if (priv->color == RED) - { // must rebalance - db_rebalance (p, &table->ht[hash]); - } + // must rebalance + db_rebalance (p, &table->ht[hash]); } return p; } -void *db_erase (struct dbt *table, void *key) +db_val_t db_erase (struct dbt *table, db_key_t key) { - void *data; - struct dbn *p; - int c, hash; - - hash = table->hash (table, key) % HASH_SIZE; - for (c = 0, p = table->ht[hash]; p;) + hash_t hash = table_hash (table, key) % HASH_SIZE; + struct dbn *p = table->ht[hash]; + while (p) { - c = table->cmp (table, key, p->key); + int c = table_cmp (table, key, p->key); if (c == 0) break; if (c < 0) @@ -484,103 +391,156 @@ void *db_erase (struct dbt *table, void *key) } if (!p) return NULL; - data = p->data; + db_val_t data = p->data; db_rebalance_erase (p, &table->ht[hash]); -#ifdef MALLOC_DBN - free_dbn (p); -#else free (p); -#endif return data; } +#ifdef SMART_WALK_TREE +static inline void db_walk_tree (bool dealloc, struct dbn* p, db_func_t func, va_list ap) +{ + if (!p) + return; + if (!dealloc && !func) + { + fprintf(stderr, "DEBUG: Must walk tree to either free or invoke a function.\n"); + abort(); + } + if (p->parent) + { + fprintf(stderr, "DEBUG: Root nodes must not have parents\n"); + abort(); + } + while (true) + { + // apply_func loop + if (func) + func (p->key, p->data, ap); + if (p->left) + { + // continue descending + p = p->left; + continue; //goto apply_func; + } + if (p->right) + { + // descending the other side + p = p->right; + continue; //goto apply_func; + } + while (true) + { + // backtrack loop + if (!p->parent) + { + if (dealloc) + free (p); + // if we have already done both children, there is no more to do + return; + } + if (p->parent->left == p && p->parent->right) + { + // finished the left tree, now walk the right tree + p = p->parent->right; + if (dealloc) + free (p->parent->left); + break; //goto apply_func; + } + // p->parent->right == p + // or p->parent->left == p but p->parent->right == NULL + // keep backtracking + p = p->parent; + if (dealloc) + free (p->right?:p->left); + } //backtrack loop + } // apply_func loop +} +#endif // SMART_WALK_TREE -void db_foreach (struct dbt *table, int (*func) (void *, void *, va_list), - ...) +void db_foreach (struct dbt *table, db_func_t func, ...) { - int i, sp; - // red-black treeなので64個stackがあれば2^32個ノードまで大丈夫 - struct dbn *p, *pn, *stack[64]; va_list ap; - va_start (ap, func); - for (i = 0; i < HASH_SIZE; i++) + + for (int i = 0; i < HASH_SIZE; i++) { - if ((p = table->ht[i]) == NULL) +#ifdef SMART_WALK_TREE + db_walk_tree (false, table->ht[i], func, ap); +#else + struct dbn *p = table->ht[i]; + if (!p) continue; - sp = 0; + struct dbn *stack[64]; + int sp = 0; while (1) { func (p->key, p->data, ap); - if ((pn = p->left) != NULL) + struct dbn *pn = p->left; + if (pn) { if (p->right) - { stack[sp++] = p->right; - } p = pn; } - else + else // pn == NULL, time to do the right branch { if (p->right) - { p = p->right; - } else { if (sp == 0) break; p = stack[--sp]; } - } - } - } + } // if pn else if !pn + } // while true +#endif // else ! SMART_WALK_TREE + } // for i va_end (ap); } -void db_final (struct dbt *table, int (*func) (void *, void *, va_list), ...) +// This function is suspiciously similar to the previous +void db_final (struct dbt *table, db_func_t func, ...) { - int i, sp; - struct dbn *p, *pn, *stack[64]; va_list ap; - va_start (ap, func); - for (i = 0; i < HASH_SIZE; i++) + + for (int i = 0; i < HASH_SIZE; i++) { - if ((p = table->ht[i]) == NULL) +#ifdef SMART_WALK_TREE + db_walk_tree (true, table->ht[i], func, ap); +#else + struct dbn *p = table->ht[i]; + if (!p) continue; - sp = 0; + struct dbn *stack[64]; + int sp = 0; while (1) { if (func) func (p->key, p->data, ap); - if ((pn = p->left) != NULL) + struct dbn *pn = p->left; + if (pn) { if (p->right) - { stack[sp++] = p->right; - } } - else + else // pn == NULL, check the right { if (p->right) - { pn = p->right; - } else { if (sp == 0) break; pn = stack[--sp]; } - } -#ifdef MALLOC_DBN - free_dbn (p); -#else + } // if pn else if !pn free (p); -#endif p = pn; - } - } + } // while true +#endif // else ! SMART_WALK_TREE + } // for i free (table); va_end (ap); } diff --git a/src/common/db.h b/src/common/db.h index 8de32d5..7152854 100644 --- a/src/common/db.h +++ b/src/common/db.h @@ -1,49 +1,87 @@ -#ifndef _DB_H_ -#define _DB_H_ +// WARNING: there is a system header by this name +#ifndef DB_H +#define DB_H +# include "sanity.h" -#include +# include -#define HASH_SIZE (256+27) +/// Number of tree roots +// Somewhat arbitrary - larger wastes more space but is faster for large trees +// num % HASH_SIZE minimize collisions even for similar num +# define HASH_SIZE (256+27) -#define RED 0 -#define BLACK 1 +typedef enum dbn_color +{ + RED, + BLACK +} dbn_color; + +typedef intptr_t numdb_key_t; +typedef union db_key_t +{ + char *ms __attribute__((deprecated)); + const char* s; + numdb_key_t i; +} db_key_t; +typedef void* db_val_t; +typedef uint32_t hash_t; +typedef void (*db_func_t)(db_key_t, db_val_t, va_list); +/// DataBase Node struct dbn { struct dbn *parent, *left, *right; - int color; - void *key; - void *data; + dbn_color color; + db_key_t key; + db_val_t data; }; +typedef enum dbt_type +{ + DB_NUMBER, + DB_STRING, +} dbt_type; + +/// DataBase Table struct dbt { - int (*cmp) (struct dbt *, void *, void *); - unsigned int (*hash) (struct dbt *, void *); - // which 1 - key, 2 - data, 3 - both - void (*release) (struct dbn *, int which); - int maxlen; + dbt_type type; + /// Note, before replacement, key/values to be replaced + // TODO refactor to decrease/eliminate the uses of this? + void (*release) (db_key_t, db_val_t) __attribute__((deprecated)); + /// Maximum length of a string key - TODO refactor to ensure all strings are NUL-terminated + size_t maxlen __attribute__((deprecated)); + /// The root trees struct dbn *ht[HASH_SIZE]; }; -#define strdb_search(t,k) db_search((t),(void*)(k)) -#define strdb_insert(t,k,d) db_insert((t),(void*)(k),(void*)(d)) -#define strdb_erase(t,k) db_erase ((t),(void*)(k)) -#define strdb_foreach db_foreach -#define strdb_final db_final -#define numdb_search(t,k) db_search((t),(void*)(k)) -#define numdb_insert(t,k,d) db_insert((t),(void*)(k),(void*)(d)) -#define numdb_erase(t,k) db_erase ((t),(void*)(k)) -#define numdb_foreach db_foreach -#define numdb_final db_final - -struct dbt *strdb_init (int maxlen); +# define strdb_search(t,k) db_search((t),(db_key_t)(k)) +# define strdb_insert(t,k,d) db_insert((t),(db_key_t)(k),(db_val_t)(d)) +# define strdb_erase(t,k) db_erase ((t),(db_key_t)(k)) +# define strdb_foreach db_foreach +# define strdb_final db_final +# define numdb_search(t,k) db_search((t),(db_key_t)(k)) +# define numdb_insert(t,k,d) db_insert((t),(db_key_t)(k),(db_val_t)(d)) +# define numdb_erase(t,k) db_erase ((t),(db_key_t)(k)) +# define numdb_foreach db_foreach +# define numdb_final db_final + +/// Create a map from char* to void*, with strings possibly not null-terminated +struct dbt *strdb_init (size_t maxlen); +/// Create a map from int to void* struct dbt *numdb_init (void); -void *db_search (struct dbt *table, void *key); -void *db_search2 (struct dbt *table, const char *key); // [MouseJstr] -struct dbn *db_insert (struct dbt *table, void *key, void *data); -void *db_erase (struct dbt *table, void *key); -void db_foreach (struct dbt *, int (*)(void *, void *, va_list), ...); -void db_final (struct dbt *, int (*)(void *, void *, va_list), ...); +/// Return the value corresponding to the key, or NULL if not found +db_val_t db_search (struct dbt *table, db_key_t key); +/// Add or replace table[key] = data +// if it was already there, call release +struct dbn *db_insert (struct dbt *table, db_key_t key, db_val_t data); +/// Remove a key from the table, returning the data +db_val_t db_erase (struct dbt *table, db_key_t key); + +/// Execute a function for every element, in unspecified order +void db_foreach (struct dbt *, db_func_t, ...); +// opposite of init? Calls release for every element and frees memory +// This probably isn't really needed: we don't have to free memory while exiting +void db_final (struct dbt *, db_func_t, ...) __attribute__((deprecated)); #endif diff --git a/src/common/grfio.c b/src/common/grfio.c index b460dc6..5e03b7c 100644 --- a/src/common/grfio.c +++ b/src/common/grfio.c @@ -1,1159 +1,212 @@ -/********************************************************************* - * - * Ragnarok Online Emulator : grfio.c -- grf file I/O Module - *-------------------------------------------------------------------- - * special need library : zlib - ********************************************************************* - * $Id: grfio.c,v 1.2 2004/09/29 17:31:49 kalaspuff Exp $ - * - * 2002/12/18... the original edition - * 2003/01/23 ... Code correction - * 2003/02/01 ... An addition and decryption processing are improved for LocalFile and two or more GRF(s) check processing. - * 2003/02/02 ... Even if there is no grf it does not stop -- as -- correction - * 2003/02/02... grf reading specification can be added later -- as -- correction (grfio_add function addition) - * 2003/02 / 03... at the time of grfio_resourcecheck processing the entry addition processing method -- correction - * 2003/02/05... change of the processing in grfio_init - * 2003/02/23... a local file check -- GRFIO_LOCAL -- switch (Defoe -- Function Off) - * 2003/10/21 ... The data of alpha client was read. - * 2003/11/10 ... Ready new grf format. - * 2003/11/11 ... version check fix & bug fix - */ - +// Reads .gat files by name-mapping .wlk files #include #include #include -#include #include -#include - #include "utils.h" #include "grfio.h" #include "mmo.h" #include "socket.h" -#ifdef MEMWATCH -#include "memwatch.h" -#endif - -typedef unsigned char BYTE; -typedef unsigned short WORD; -typedef unsigned long DWORD; - -static char data_file[1024] = ""; // "data.grf"; -static char sdata_file[1024] = ""; // "sdata.grf"; -static char adata_file[1024] = ""; // "adata.grf"; -static char data_dir[1024] = ""; // "../"; - -// accessor to data_file,adata_file,sdata_file -char *grfio_setdatafile (const char *str) -{ - strcpy (data_file, str); - return data_file; -} - -char *grfio_setadatafile (const char *str) -{ - strcpy (adata_file, str); - return adata_file; -} - -char *grfio_setsdatafile (const char *str) -{ - strcpy (sdata_file, str); - return sdata_file; -} - //---------------------------- // file entry table struct //---------------------------- typedef struct { - int srclen; // compressed size - int srclen_aligned; // - int declen; // original size - int srcpos; - short next; - char cycle; - char type; - char fn[128 - 4 * 5]; // file name - char gentry; // read grf file select + size_t declen; + int16_t next; // next index into the filelist[] array, or -1 + char fn[128 - 4 - 2]; // file name } FILELIST; -//gentry ... 0 : It acquires from a local file. -// It acquires from the resource file of 1>=:gentry_table[gentry-1]. -// 1<=: Check a local file. -// If it is, after re-setting to 0, it acquires from a local file. -// If there is nothing, mark reversal will be carried out, and it will re-set, and will acquire from a resource file as well as 1>=. -//Since char defines *FILELIST.gentry, the maximum which can be added by grfio_add becomes by 127 pieces. +#define FILELIST_LIMIT 32768 // limit to number of filelists - if you increase this, change all shorts to int +#define FILELIST_ADDS 1024 // amount to increment when reallocing -#define GENTRY_LIMIT 127 -#define FILELIST_LIMIT 32768 // temporary maximum, and a theory top maximum are 2G. +static FILELIST *filelist = NULL; +/// Number of entries used +static uint16_t filelist_entrys = 0; +/// Number of FILELIST entries actually allocated +static uint16_t filelist_maxentry = 0; -static FILELIST *filelist; -static int filelist_entrys; -static int filelist_maxentry; +/// First index of the given hash, into the filelist[] array +static int16_t filelist_hash[256] = {[0 ... 255] = -1}; -static char **gentry_table; -static int gentry_entrys; -static int gentry_maxentry; - -//---------------------------- -// file list hash table -//---------------------------- -static int filelist_hash[256]; - -//---------------------------- -// grf decode data table -//---------------------------- -static unsigned char BitMaskTable[8] = { - 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 -}; - -static char BitSwapTable1[64] = { - 58, 50, 42, 34, 26, 18, 10, 2, 60, 52, 44, 36, 28, 20, 12, 4, - 62, 54, 46, 38, 30, 22, 14, 6, 64, 56, 48, 40, 32, 24, 16, 8, - 57, 49, 41, 33, 25, 17, 9, 1, 59, 51, 43, 35, 27, 19, 11, 3, - 61, 53, 45, 37, 29, 21, 13, 5, 63, 55, 47, 39, 31, 23, 15, 7 -}; - -static char BitSwapTable2[64] = { - 40, 8, 48, 16, 56, 24, 64, 32, 39, 7, 47, 15, 55, 23, 63, 31, - 38, 6, 46, 14, 54, 22, 62, 30, 37, 5, 45, 13, 53, 21, 61, 29, - 36, 4, 44, 12, 52, 20, 60, 28, 35, 3, 43, 11, 51, 19, 59, 27, - 34, 2, 42, 10, 50, 18, 58, 26, 33, 1, 41, 9, 49, 17, 57, 25 -}; - -static char BitSwapTable3[32] = { - 16, 7, 20, 21, 29, 12, 28, 17, 1, 15, 23, 26, 5, 18, 31, 10, - 2, 8, 24, 14, 32, 27, 3, 9, 19, 13, 30, 6, 22, 11, 4, 25 -}; - -static unsigned char NibbleData[4][64] = { - { - 0xef, 0x03, 0x41, 0xfd, 0xd8, 0x74, 0x1e, 0x47, 0x26, 0xef, 0xfb, 0x22, - 0xb3, 0xd8, 0x84, 0x1e, - 0x39, 0xac, 0xa7, 0x60, 0x62, 0xc1, 0xcd, 0xba, 0x5c, 0x96, 0x90, 0x59, - 0x05, 0x3b, 0x7a, 0x85, - 0x40, 0xfd, 0x1e, 0xc8, 0xe7, 0x8a, 0x8b, 0x21, 0xda, 0x43, 0x64, 0x9f, - 0x2d, 0x14, 0xb1, 0x72, - 0xf5, 0x5b, 0xc8, 0xb6, 0x9c, 0x37, 0x76, 0xec, 0x39, 0xa0, 0xa3, 0x05, - 0x52, 0x6e, 0x0f, 0xd9, - }, { - 0xa7, 0xdd, 0x0d, 0x78, 0x9e, 0x0b, 0xe3, 0x95, 0x60, 0x36, 0x36, - 0x4f, 0xf9, 0x60, 0x5a, 0xa3, - 0x11, 0x24, 0xd2, 0x87, 0xc8, 0x52, 0x75, 0xec, 0xbb, 0xc1, 0x4c, - 0xba, 0x24, 0xfe, 0x8f, 0x19, - 0xda, 0x13, 0x66, 0xaf, 0x49, 0xd0, 0x90, 0x06, 0x8c, 0x6a, 0xfb, - 0x91, 0x37, 0x8d, 0x0d, 0x78, - 0xbf, 0x49, 0x11, 0xf4, 0x23, 0xe5, 0xce, 0x3b, 0x55, 0xbc, 0xa2, - 0x57, 0xe8, 0x22, 0x74, 0xce, - }, { - 0x2c, 0xea, 0xc1, 0xbf, 0x4a, 0x24, 0x1f, 0xc2, 0x79, 0x47, 0xa2, - 0x7c, 0xb6, 0xd9, 0x68, 0x15, - 0x80, 0x56, 0x5d, 0x01, 0x33, 0xfd, 0xf4, 0xae, 0xde, 0x30, 0x07, - 0x9b, 0xe5, 0x83, 0x9b, 0x68, - 0x49, 0xb4, 0x2e, 0x83, 0x1f, 0xc2, 0xb5, 0x7c, 0xa2, 0x19, 0xd8, - 0xe5, 0x7c, 0x2f, 0x83, 0xda, - 0xf7, 0x6b, 0x90, 0xfe, 0xc4, 0x01, 0x5a, 0x97, 0x61, 0xa6, 0x3d, - 0x40, 0x0b, 0x58, 0xe6, 0x3d, - }, { - 0x4d, 0xd1, 0xb2, 0x0f, 0x28, 0xbd, 0xe4, 0x78, 0xf6, 0x4a, - 0x0f, 0x93, 0x8b, 0x17, 0xd1, 0xa4, - 0x3a, 0xec, 0xc9, 0x35, 0x93, 0x56, 0x7e, 0xcb, 0x55, 0x20, - 0xa0, 0xfe, 0x6c, 0x89, 0x17, 0x62, - 0x17, 0x62, 0x4b, 0xb1, 0xb4, 0xde, 0xd1, 0x87, 0xc9, 0x14, - 0x3c, 0x4a, 0x7e, 0xa8, 0xe2, 0x7d, - 0xa0, 0x9f, 0xf6, 0x5c, 0x6a, 0x09, 0x8d, 0xf0, 0x0f, 0xe3, - 0x53, 0x25, 0x95, 0x36, 0x28, 0xcb, - } -}; - -/*----------------- - * long data get - */ -static unsigned int getlong (unsigned char *p) +/// Hash a filename +static uint8_t filehash (const char *fname) { - return *p + p[1] * 256 + (p[2] + p[3] * 256) * 65536; -} - -/*========================================== - * Grf data decode : Subs - *------------------------------------------ - */ -static void NibbleSwap (BYTE * Src, int len) -{ - for (; 0 < len; len--, Src++) - { - *Src = (*Src >> 4) | (*Src << 4); - } -} - -static void BitConvert (BYTE * Src, char *BitSwapTable) -{ - int lop, prm; - BYTE tmp[8]; - *(DWORD *) tmp = *(DWORD *) (tmp + 4) = 0; - for (lop = 0; lop != 64; lop++) - { - prm = BitSwapTable[lop] - 1; - if (Src[(prm >> 3) & 7] & BitMaskTable[prm & 7]) - { - tmp[(lop >> 3) & 7] |= BitMaskTable[lop & 7]; - } - } - *(DWORD *) Src = *(DWORD *) tmp; - *(DWORD *) (Src + 4) = *(DWORD *) (tmp + 4); -} - -static void BitConvert4 (BYTE * Src) -{ - int lop, prm; - BYTE tmp[8]; - tmp[0] = ((Src[7] << 5) | (Src[4] >> 3)) & 0x3f; // ..0 vutsr - tmp[1] = ((Src[4] << 1) | (Src[5] >> 7)) & 0x3f; // ..srqpo n - tmp[2] = ((Src[4] << 5) | (Src[5] >> 3)) & 0x3f; // ..o nmlkj - tmp[3] = ((Src[5] << 1) | (Src[6] >> 7)) & 0x3f; // ..kjihg f - tmp[4] = ((Src[5] << 5) | (Src[6] >> 3)) & 0x3f; // ..g fedcb - tmp[5] = ((Src[6] << 1) | (Src[7] >> 7)) & 0x3f; // ..cba98 7 - tmp[6] = ((Src[6] << 5) | (Src[7] >> 3)) & 0x3f; // ..8 76543 - tmp[7] = ((Src[7] << 1) | (Src[4] >> 7)) & 0x3f; // ..43210 v - - for (lop = 0; lop != 4; lop++) - { - tmp[lop] = (NibbleData[lop][tmp[lop * 2]] & 0xf0) - | (NibbleData[lop][tmp[lop * 2 + 1]] & 0x0f); - } - - *(DWORD *) (tmp + 4) = 0; - for (lop = 0; lop != 32; lop++) - { - prm = BitSwapTable3[lop] - 1; - if (tmp[prm >> 3] & BitMaskTable[prm & 7]) - { - tmp[(lop >> 3) + 4] |= BitMaskTable[lop & 7]; - } - } - *(DWORD *) Src ^= *(DWORD *) (tmp + 4); -} - -static void decode_des_etc (BYTE * buf, int len, int type, int cycle) -{ - int lop, cnt = 0; - if (cycle < 3) - cycle = 3; - else if (cycle < 5) - cycle++; - else if (cycle < 7) - cycle += 9; - else - cycle += 15; - - for (lop = 0; lop * 8 < len; lop++, buf += 8) - { - if (lop < 20 || (type == 0 && lop % cycle == 0)) - { // des - BitConvert (buf, BitSwapTable1); - BitConvert4 (buf); - BitConvert (buf, BitSwapTable2); - } - else - { - if (cnt == 7 && type == 0) - { - int a; - BYTE tmp[8]; - *(DWORD *) tmp = *(DWORD *) buf; - *(DWORD *) (tmp + 4) = *(DWORD *) (buf + 4); - cnt = 0; - buf[0] = tmp[3]; - buf[1] = tmp[4]; - buf[2] = tmp[6]; - buf[3] = tmp[0]; - buf[4] = tmp[1]; - buf[5] = tmp[2]; - buf[6] = tmp[5]; - a = tmp[7]; - if (a == 0x00) - a = 0x2b; - else if (a == 0x2b) - a = 0x00; - else if (a == 0x01) - a = 0x68; - else if (a == 0x68) - a = 0x01; - else if (a == 0x48) - a = 0x77; - else if (a == 0x77) - a = 0x48; - else if (a == 0x60) - a = 0xff; - else if (a == 0xff) - a = 0x60; - else if (a == 0x6c) - a = 0x80; - else if (a == 0x80) - a = 0x6c; - else if (a == 0xb9) - a = 0xc0; - else if (a == 0xc0) - a = 0xb9; - else if (a == 0xeb) - a = 0xfe; - else if (a == 0xfe) - a = 0xeb; - buf[7] = a; - } - cnt++; - } - } -} - -/*========================================== - * Grf data decode sub : zip - *------------------------------------------ - */ -static int decode_zip (Bytef * dest, uLongf * destLen, const Bytef * source, - uLong sourceLen) -{ - z_stream stream; - int err; - - stream.next_in = (Bytef *) source; - stream.avail_in = (uInt) sourceLen; - /* Check for source > 64K on 16-bit machine: */ - if ((uLong) stream.avail_in != sourceLen) - return Z_BUF_ERROR; - - stream.next_out = dest; - stream.avail_out = (uInt) * destLen; - if ((uLong) stream.avail_out != *destLen) - return Z_BUF_ERROR; - - stream.zalloc = (alloc_func) 0; - stream.zfree = (free_func) 0; - - err = inflateInit (&stream); - if (err != Z_OK) - return err; - - err = inflate (&stream, Z_FINISH); - if (err != Z_STREAM_END) - { - inflateEnd (&stream); - return err == Z_OK ? Z_BUF_ERROR : err; - } - *destLen = stream.total_out; - - err = inflateEnd (&stream); - return err; -} - -/*********************************************************** - *** File List Sobroutines *** - ***********************************************************/ - -/*========================================== - * File List : Hash make - *------------------------------------------ - */ -static int filehash (unsigned char *fname) -{ - unsigned int hash = 0; + // Larger than the return type - upper bits are used in the process + uint32_t hash = 0; while (*fname) { - hash = ((hash << 1) + (hash >> 7) * 9 + tolower (*fname)); + hash = (hash << 1) + (hash >> 7) * 9 + (unsigned char)*fname; fname++; } - return hash & 255; -} - -/*========================================== - * File List : Hash initalize - *------------------------------------------ - */ -static void hashinit (void) -{ - int lop; - for (lop = 0; lop < 256; lop++) - filelist_hash[lop] = -1; + return hash; } -/*========================================== - * File List : File find - *------------------------------------------ - */ -FILELIST *filelist_find (char *fname) +/// Find the filelist entry for the given filename, or NULL if it is not +FILELIST *filelist_find (const char *fname) { - int hash; - - for (hash = filelist_hash[filehash (fname)]; hash >= 0; - hash = filelist[hash].next) + int16_t index = filelist_hash[filehash (fname)]; + while (index >= 0) { - if (strcasecmp (filelist[hash].fn, fname) == 0) - break; + if (strcmp (filelist[index].fn, fname) == 0) + return &filelist[index]; + index = filelist[index].next; } - - return (hash >= 0) ? &filelist[hash] : NULL; + return NULL; } -/*========================================== - * File List : Filelist add - *------------------------------------------ - */ -#define FILELIST_ADDS 1024 // number increment of file lists ` - +/// Copy a temporary entry into the hash map static FILELIST *filelist_add (FILELIST * entry) { - int hash; - if (filelist_entrys >= FILELIST_LIMIT) { - printf ("filelist limit : filelist_add\n"); + fprintf (stderr, "filelist limit : filelist_add\n"); exit (1); } if (filelist_entrys >= filelist_maxentry) { - FILELIST *new_filelist = (FILELIST *) realloc ((void *) filelist, - (filelist_maxentry + - FILELIST_ADDS) * - sizeof (FILELIST)); - if (new_filelist != NULL) - { - filelist = new_filelist; - memset (filelist + filelist_maxentry, '\0', - FILELIST_ADDS * sizeof (FILELIST)); - filelist_maxentry += FILELIST_ADDS; - } - else - { - printf ("out of memory : filelist_add\n"); - exit (1); - } + RECREATE(filelist, FILELIST, filelist_maxentry + FILELIST_ADDS); + memset (filelist + filelist_maxentry, '\0', + FILELIST_ADDS * sizeof (FILELIST)); + filelist_maxentry += FILELIST_ADDS; } - memcpy (&filelist[filelist_entrys], entry, sizeof (FILELIST)); - - hash = filehash (entry->fn); - filelist[filelist_entrys].next = filelist_hash[hash]; - filelist_hash[hash] = filelist_entrys; + uint16_t new_index = filelist_entrys++; + uint8_t hash = filehash (entry->fn); + entry->next = filelist_hash[hash]; + filelist_hash[hash] = new_index; - filelist_entrys++; + filelist[new_index] = *entry; - return &filelist[filelist_entrys - 1]; + return &filelist[new_index]; } static FILELIST *filelist_modify (FILELIST * entry) { - FILELIST *fentry; - if ((fentry = filelist_find (entry->fn)) != NULL) - { - int tmp = fentry->next; - memcpy (fentry, entry, sizeof (FILELIST)); - fentry->next = tmp; - } - else - { - fentry = filelist_add (entry); - } - return fentry; -} - -/*========================================== - * File List : filelist size adjust - *------------------------------------------ - */ -static void filelist_adjust (void) -{ - if (filelist != NULL) + FILELIST *fentry = filelist_find (entry->fn); + if (fentry) { - if (filelist_maxentry > filelist_entrys) - { - FILELIST *new_filelist = (FILELIST *) realloc ((void *) filelist, - filelist_entrys * - sizeof (FILELIST)); - if (new_filelist != NULL) - { - filelist = new_filelist; - filelist_maxentry = filelist_entrys; - } - else - { - printf ("out of memory : filelist\n"); - exit (1); - } - } + entry->next = fentry->next; + *fentry = *entry; + return fentry; } + return filelist_add (entry); } -/*********************************************************** - *** Grfio Sobroutines *** - ***********************************************************/ -/*========================================== - * Grfio : Resnametable replace - *------------------------------------------ - */ -char *grfio_resnametable (char *fname, char *lfname) +/// Change fname data/*.gat to lfname data/*.wlk +// TODO even if the file exists, don't keep reopening it every time one loads +void grfio_resnametable (const char *fname, char *lfname) { - FILE *fp; - char *p; - char w1[256], w2[256], restable[256], line[512]; - - sprintf (restable, "%sdata\\resnametable.txt", data_dir); + char restable[] = "data/resnametable.txt"; - for (p = &restable[0]; *p != 0; p++) - if (*p == '\\') - *p = '/'; - - fp = fopen_ (restable, "rb"); + FILE *fp = fopen_ (restable, "rb"); if (fp == NULL) { - printf ("%s not found\n", restable); - exit (1); // 1:not found error + fprintf(stderr, "No resnametable, can't look for %s\n", fname); + strcpy(lfname, fname); + char* ext = lfname + strlen(lfname) - 4; + if (!strcmp(ext, ".gat")) + strcpy(ext, ".wlk"); + return; } - while (fgets (line, 508, fp)) + char line[512]; + while (fgets (line, sizeof (line), fp)) { - if ((sscanf (line, "%[^#]#%[^#]#", w1, w2) == 2) - && (sscanf (fname, "%*5s%s", lfname) == 1) - && (!strcmpi (w1, lfname))) + char w1[256], w2[256]; + if ( + // line is of the form foo.gat#foo.wlk# + (sscanf (line, "%[^#]#%[^#]#", w1, w2) == 2) + // strip data/ from foo.gat before comparing + && (!strcmp (w1, fname + 5))) { - sprintf (lfname, "data\\%s", w2); + strcpy (lfname, "data/"); + strcpy (lfname + 5, w2); fclose_ (fp); - return lfname; + return; } } + fprintf(stderr, "Unable to find resource: %s\n", fname); fclose_ (fp); - return fname; - -} - -/*========================================== - * Grfio : Resource file size get - *------------------------------------------ - */ -int grfio_size (char *fname) -{ - FILELIST *entry; - - entry = filelist_find (fname); - - if (entry == NULL || entry->gentry < 0) - { // LocalFileCheck - char lfname[256], rname[256], *p; - FILELIST lentry; - struct stat st; - //printf("%s\t",fname); - sprintf (rname, "%s", grfio_resnametable (fname, lfname)); - //printf("%s\n",rname); - sprintf (lfname, "%s%s", data_dir, rname); - //printf("%s\n",lfname); - - for (p = &lfname[0]; *p != 0; p++) - if (*p == '\\') - *p = '/'; // * At the time of Unix - - if (stat (lfname, &st) == 0) - { - strncpy (lentry.fn, fname, sizeof (lentry.fn) - 1); - lentry.declen = st.st_size; - lentry.gentry = 0; // 0:LocalFile - entry = filelist_modify (&lentry); - } - else if (entry == NULL) - { - printf ("%s not found\n", fname); - //exit(1); - return -1; - } - } - return entry->declen; + strcpy(lfname, fname); + char* ext = lfname + strlen(lfname) - 4; + if (!strcmp(ext, ".gat")) + strcpy(ext, ".wlk"); + return; } -/*========================================== - * Grfio : Resource file read & size get - *------------------------------------------ - */ -void *grfio_reads (char *fname, int *size) +/// Size of resource +size_t grfio_size (const char *fname) { - FILE *in = NULL; - unsigned char *buf = NULL, *buf2 = NULL; - char *gfname; - FILELIST *entry; + FILELIST *entry = filelist_find (fname); + if (entry) + return entry->declen; - entry = filelist_find (fname); + char lfname[256]; + FILELIST lentry; + struct stat st; - if (entry == NULL || entry->gentry <= 0) - { // LocalFileCheck - char lfname[256], rname[256], *p; - FILELIST lentry; + grfio_resnametable (fname, lfname); - strncpy (lfname, fname, 255); - sprintf (rname, "%s", grfio_resnametable (fname, lfname)); - sprintf (lfname, "%s%s", data_dir, rname); - //printf("%s\n",lfname); - - for (p = &lfname[0]; *p != 0; p++) - if (*p == '\\') - *p = '/'; // * At the time of Unix - - in = fopen_ (lfname, "rb"); - if (in != NULL) - { - if (entry != NULL && entry->gentry == 0) - { - lentry.declen = entry->declen; - } - else - { - fseek (in, 0, 2); // SEEK_END - lentry.declen = ftell (in); - } - fseek (in, 0, 0); // SEEK_SET - buf2 = calloc (lentry.declen + 1024, 1); - if (buf2 == NULL) - { - printf ("file read memory allocate error : declen\n"); - goto errret; - } - if (!fread (buf2, 1, lentry.declen, in)) - goto errret; - fclose_ (in); - in = NULL; - strncpy (lentry.fn, fname, sizeof (lentry.fn) - 1); - lentry.gentry = 0; // 0:LocalFile - entry = filelist_modify (&lentry); - } - else - { - if (entry != NULL && entry->gentry < 0) - { - entry->gentry = -entry->gentry; // local file checked - } - else - { - printf ("%s not found\n", fname); - //goto errret; - free (buf2); - return NULL; - } - } - } - if (entry != NULL && entry->gentry > 0) - { // Archive[GRF] File Read - buf = calloc (entry->srclen_aligned + 1024, 1); - if (buf == NULL) - { - printf ("file read memory allocate error : srclen_aligned\n"); - goto errret; - } - gfname = gentry_table[entry->gentry - 1]; - in = fopen_ (gfname, "rb"); - if (in == NULL) - { - printf ("%s not found\n", gfname); - //goto errret; - free (buf); - return NULL; - } - fseek (in, entry->srcpos, 0); - if (!fread (buf, 1, entry->srclen_aligned, in)) - goto errret; - fclose_ (in); - buf2 = calloc (entry->declen + 1024, 1); - if (buf2 == NULL) - { - printf ("file decode memory allocate error\n"); - goto errret; - } - if (entry->type == 1 || entry->type == 3 || entry->type == 5) - { - uLongf len; - if (entry->cycle >= 0) - { - decode_des_etc (buf, entry->srclen_aligned, entry->cycle == 0, - entry->cycle); - } - len = entry->declen; - decode_zip (buf2, &len, buf, entry->srclen); - if (len != entry->declen) - { - printf ("decode_zip size miss match err: %d != %d\n", - (int) len, entry->declen); - goto errret; - } - } - else - { - memcpy (buf2, buf, entry->declen); - } - free (buf); - } - if (size != NULL && entry != NULL) - *size = entry->declen; - return buf2; - errret: - if (buf != NULL) - free (buf); - if (buf2 != NULL) - free (buf2); - if (in != NULL) - fclose_ (in); - exit (1); //return NULL; -} - -/*========================================== - * Grfio : Resource file read - *------------------------------------------ - */ -void *grfio_read (char *fname) -{ - return grfio_reads (fname, NULL); -} - -/*========================================== - * Resource filename decode - *------------------------------------------ - */ -static unsigned char *decode_filename (unsigned char *buf, int len) -{ - int lop; - for (lop = 0; lop < len; lop += 8) - { - NibbleSwap (&buf[lop], 8); - BitConvert (&buf[lop], BitSwapTable1); - BitConvert4 (&buf[lop]); - BitConvert (&buf[lop], BitSwapTable2); - } - return buf; -} - -/*========================================== - * Grfio : Entry table read - *------------------------------------------ - */ -static int grfio_entryread (char *gfname, int gentry) -{ - FILE *fp; - int grf_size, list_size; - unsigned char grf_header[0x2e]; - int lop, entry, entrys, ofs, grf_version; - unsigned char *fname; - unsigned char *grf_filelist; + for (char *p = lfname; *p; p++) + if (*p == '\\') + *p = '/'; - fp = fopen_ (gfname, "rb"); - if (fp == NULL) + if (stat (lfname, &st) == 0) { - printf ("%s not found\n", gfname); - return 1; // 1:not found error - } - - fseek (fp, 0, 2); // SEEK_END - grf_size = ftell (fp); - fseek (fp, 0, 0); // SEEK_SET - if (!fread (grf_header, 1, 0x2e, fp)) - return 2; - - if (strcmp (grf_header, "Master of Magic") - || fseek (fp, getlong (grf_header + 0x1e), 1)) - { // SEEK_CUR - fclose_ (fp); - printf ("%s read error\n", gfname); - return 2; // 2:file format error - } - - grf_version = getlong (grf_header + 0x2a) >> 8; - - if (grf_version == 0x01) - { //****** Grf version 01xx ****** - list_size = grf_size - ftell (fp); - grf_filelist = calloc (list_size, 1); - if (grf_filelist == NULL) - { - fclose_ (fp); - printf ("out of memory : grf_filelist\n"); - return 3; // 3:memory alloc error - } - if (!fread (grf_filelist, 1, list_size, fp)) - return 2; - fclose_ (fp); - - entrys = - getlong (grf_header + 0x26) - getlong (grf_header + 0x22) - 7; - - // Get an entry - for (entry = 0, ofs = 0; entry < entrys; entry++) - { - int ofs2, srclen, srccount, type; - char *period_ptr; - FILELIST aentry; - - ofs2 = ofs + getlong (grf_filelist + ofs) + 4; - type = grf_filelist[ofs2 + 12]; - if (type != 0) - { // Directory Index ... skip - fname = - decode_filename (grf_filelist + ofs + 6, - grf_filelist[ofs] - 6); - if (strlen (fname) > sizeof (aentry.fn) - 1) - { - printf ("file name too long : %s\n", fname); - free (grf_filelist); - exit (1); - } - srclen = 0; - if ((period_ptr = rindex (fname, '.')) != NULL) - { - for (lop = 0; lop < 4; lop++) - { - if (strcasecmp - (period_ptr, - ".gnd\0.gat\0.act\0.str" + lop * 5) == 0) - break; - } - srclen = - getlong (grf_filelist + ofs2) - - getlong (grf_filelist + ofs2 + 8) - 715; - if (lop == 4) - { - for (lop = 10, srccount = 1; srclen >= lop; - lop = lop * 10, srccount++); - } - else - { - srccount = 0; - } - } - else - { - srccount = 0; - } - - aentry.srclen = srclen; - aentry.srclen_aligned = - getlong (grf_filelist + ofs2 + 4) - 37579; - aentry.declen = getlong (grf_filelist + ofs2 + 8); - aentry.srcpos = getlong (grf_filelist + ofs2 + 13) + 0x2e; - aentry.cycle = srccount; - aentry.type = type; - strncpy (aentry.fn, fname, sizeof (aentry.fn) - 1); -#ifdef GRFIO_LOCAL - aentry.gentry = -(gentry + 1); // As Flag for making it a negative number carrying out the first time LocalFileCheck -#else - aentry.gentry = gentry + 1; // With no first time LocalFileCheck -#endif - filelist_modify (&aentry); - } - ofs = ofs2 + 17; - } - free (grf_filelist); - - } - else if (grf_version == 0x02) - { //****** Grf version 02xx ****** - unsigned char eheader[8]; - unsigned char *rBuf; - uLongf rSize, eSize; - - if (!fread (eheader, 1, 8, fp)) - return 4; - - rSize = getlong (eheader); // Read Size - eSize = getlong (eheader + 4); // Extend Size - - if (rSize > grf_size - ftell (fp)) - { - fclose_ (fp); - printf ("Illegal data format : grf compress entry size\n"); - return 4; - } - - rBuf = calloc (rSize, 1); // Get a Read Size - if (rBuf == NULL) - { - fclose_ (fp); - printf ("out of memory : grf compress entry table buffer\n"); - return 3; - } - grf_filelist = calloc (eSize, 1); // Get a Extend Size - if (grf_filelist == NULL) - { - free (rBuf); - fclose_ (fp); - printf ("out of memory : grf extract entry table buffer\n"); - return 3; - } - - if (!fread (rBuf, 1, rSize, fp)) - return 4; - - fclose_ (fp); - decode_zip (grf_filelist, &eSize, rBuf, rSize); // Decode function - list_size = eSize; - free (rBuf); - - entrys = getlong (grf_header + 0x26) - 7; - - // Get an entry - for (entry = 0, ofs = 0; entry < entrys; entry++) - { - int ofs2, srclen, srccount, type; - FILELIST aentry; - - fname = grf_filelist + ofs; - if (strlen (fname) > sizeof (aentry.fn) - 1) - { - printf ("grf : file name too long : %s\n", fname); - free (grf_filelist); - exit (1); - } - ofs2 = ofs + strlen (grf_filelist + ofs) + 1; - type = grf_filelist[ofs2 + 12]; - if (type == 1 || type == 3 || type == 5) - { - srclen = getlong (grf_filelist + ofs2); - if (grf_filelist[ofs2 + 12] == 3) - { - for (lop = 10, srccount = 1; srclen >= lop; - lop = lop * 10, srccount++); - } - else if (grf_filelist[ofs2 + 12] == 5) - { - srccount = 0; - } - else - { // if (grf_filelist[ofs2+12]==1) { - srccount = -1; - } - - aentry.srclen = srclen; - aentry.srclen_aligned = getlong (grf_filelist + ofs2 + 4); - aentry.declen = getlong (grf_filelist + ofs2 + 8); - aentry.srcpos = getlong (grf_filelist + ofs2 + 13) + 0x2e; - aentry.cycle = srccount; - aentry.type = type; - strncpy (aentry.fn, fname, sizeof (aentry.fn) - 1); -#ifdef GRFIO_LOCAL - aentry.gentry = -(gentry + 1); // As Flag for making it a negative number carrying out the first time LocalFileCheck -#else - aentry.gentry = gentry + 1; // With no first time LocalFileCheck -#endif - filelist_modify (&aentry); - } - ofs = ofs2 + 17; - } - free (grf_filelist); - + strncpy (lentry.fn, fname, sizeof (lentry.fn) - 1); + lentry.declen = st.st_size; + entry = filelist_modify (&lentry); } else - { //****** Grf Other version ****** - fclose_ (fp); - printf ("not support grf versions : %04x\n", - getlong (grf_header + 0x2a)); - return 4; - } - - filelist_adjust (); // Unnecessary area release of filelist - - return 0; // 0:no error -} - -/*========================================== - * Grfio : Resource file check - *------------------------------------------ - */ -static void grfio_resourcecheck () -{ - int size; - unsigned char *buf, *ptr; - char w1[256], w2[256], src[256], dst[256]; - FILELIST *entry; - - buf = grfio_reads ("data\\resnametable.txt", &size); - buf[size] = 0; - - for (ptr = buf; ptr - buf < size;) { - if (sscanf (ptr, "%[^#]#%[^#]#", w1, w2) == 2) - { - if (strstr (w2, "bmp")) - { - sprintf (src, "data\\texture\\%s", w1); - sprintf (dst, "data\\texture\\%s", w2); - } - else - { - sprintf (src, "data\\%s", w1); - sprintf (dst, "data\\%s", w2); - } - entry = filelist_find (dst); - if (entry != NULL) - { - FILELIST fentry; - memcpy (&fentry, entry, sizeof (FILELIST)); - strncpy (fentry.fn, src, sizeof (fentry.fn) - 1); - filelist_modify (&fentry); - } - else - { - //printf("file not found in data.grf : %s < %s\n",dst,src); - } - } - ptr = strchr (ptr, '\n'); // Next line - if (!ptr) - break; - ptr++; + printf ("%s not found\n", fname); + return 0; } - free (buf); - filelist_adjust (); // Unnecessary area release of filelist + return entry->declen; } -/*========================================== - * Grfio : Resource add - *------------------------------------------ - */ -#define GENTRY_ADDS 16 // The number increment of gentry_table entries - -int grfio_add (char *fname) +void *grfio_reads (const char *fname, size_t *size) { - int len, result; - char *buf; - - if (gentry_entrys >= GENTRY_LIMIT) - { - printf ("gentrys limit : grfio_add\n"); - exit (1); - } + char lfname[256]; + grfio_resnametable (fname, lfname); - printf ("%s file reading...\n", fname); + for (char *p = &lfname[0]; *p != 0; p++) + if (*p == '\\') + *p = '/'; // * At the time of Unix - if (gentry_entrys >= gentry_maxentry) + FILE *in = fopen_ (lfname, "rb"); + if (!in) { - char **new_gentry = (char **) realloc ((void *) gentry_table, - (gentry_maxentry + - GENTRY_ADDS) * - sizeof (char *)); - if (new_gentry != NULL) - { - int lop; - gentry_table = new_gentry; - gentry_maxentry += GENTRY_ADDS; - for (lop = gentry_entrys; lop < gentry_maxentry; lop++) - gentry_table[lop] = NULL; - } - else - { - printf ("out of memory : grfio_add\n"); - exit (1); - } - } - len = strlen (fname); - buf = calloc (len + 1, 1); - if (buf == NULL) - { - printf ("out of memory : gentry\n"); - exit (1); + fprintf (stderr, "%s not found\n", fname); + return NULL; } - strcpy (buf, fname); - gentry_table[gentry_entrys++] = buf; - - result = grfio_entryread (fname, gentry_entrys - 1); - - if (result == 0) + FILELIST lentry; + FILELIST *entry = filelist_find (fname); + if (entry) { - // Resource check - grfio_resourcecheck (); + lentry.declen = entry->declen; } - - return result; -} - -/*========================================== - * Grfio : Finalize - *------------------------------------------ - */ -void grfio_final (void) -{ - int lop; - - if (filelist != NULL) - free (filelist); - filelist = NULL; - filelist_entrys = filelist_maxentry = 0; - - if (gentry_table != NULL) + else { - for (lop = 0; lop < gentry_entrys; lop++) - { - if (gentry_table[lop] != NULL) - { - free (gentry_table[lop]); - } - } - free (gentry_table); + fseek (in, 0, SEEK_END); + lentry.declen = ftell (in); + fseek (in, 0, SEEK_SET); + strncpy (lentry.fn, fname, sizeof (lentry.fn) - 1); + entry = filelist_modify (&lentry); } - gentry_table = NULL; - gentry_entrys = gentry_maxentry = 0; -} - -/*========================================== - * Grfio : Initialize - *------------------------------------------ - */ -void grfio_init (char *fname) -{ - FILE *data_conf; - char line[1024], w1[1024], w2[1024]; - int result = 0, result2 = 0, result3 = 0; - - data_conf = fopen_ (fname, "r"); + uint8_t *buf2; + CREATE (buf2, uint8_t, lentry.declen + 1024); + if (!fread (buf2, 1, lentry.declen, in)) + exit(1); + fclose_ (in); + in = NULL; - // It will read, if there is grf-files.txt. - if (data_conf) - { - while (fgets (line, 1020, data_conf)) - { - if (sscanf (line, "%[^:]: %[^\r\n]", w1, w2) == 2) - { - if (strcmp (w1, "data") == 0) - strcpy (data_file, w2); - else if (strcmp (w1, "sdata") == 0) - strcpy (sdata_file, w2); - else if (strcmp (w1, "adata") == 0) - strcpy (adata_file, w2); - else if (strcmp (w1, "data_dir") == 0) - strcpy (data_dir, w2); - } - } - - fclose_ (data_conf); - printf ("read %s done\n", fname); - } // end of reading grf-files.txt - - hashinit (); // hash table initialization - - filelist = NULL; - filelist_entrys = filelist_maxentry = 0; - gentry_table = NULL; - gentry_entrys = gentry_maxentry = 0; - atexit (grfio_final); // End processing definition - - // Entry table reading - - if (strcmp (data_file, "") != 0) // If data directive exists in grf-files.txt (i.e. data_file is not equal to "") - result = grfio_add (data_file); // Primary data file - - if (strcmp (sdata_file, "") != 0) // If sdata directive exists in grf-files.txt (i.e. sdata_file is not equal to "") - result2 = grfio_add (sdata_file); // Sakray data file - - if (strcmp (adata_file, "") != 0) // If data directive exists in grf-files.txt (i.e. adata_file is not equal to "") - result3 = grfio_add (adata_file); // Alpha version data file - - if (result != 0 && result2 != 0 && result3 != 0) - { - printf ("not grf file readed exit!!\n"); - exit (1); // It ends, if a resource cannot read one. - } + if (size) + *size = entry->declen; + return buf2; } diff --git a/src/common/grfio.h b/src/common/grfio.h index 5d3f69c..4919a7b 100644 --- a/src/common/grfio.h +++ b/src/common/grfio.h @@ -1,16 +1,17 @@ -// $Id: grfio.h,v 1.1.1.1 2004/09/10 17:44:49 MagicalTux Exp $ -#ifndef _GRFIO_H_ -#define _GRFIO_H_ +/// Accessor to the .gat map virtual files +// Note .gat files are mapped to .wlk files by data/resnametable.txt +// Note that there currently is a 1-1 correlation between them, +// but it is possible for a single .wlk to have multiple .gats reference it +#ifndef GRFIO_H +#define GRFIO_H -void grfio_init (char *); // GRFIO Initialize -int grfio_add (char *); // GRFIO Resource file add -void *grfio_read (char *); // GRFIO data file read -void *grfio_reads (char *, int *); // GRFIO data file read & size get -int grfio_size (char *); // GRFIO data file size get +/// Load file into memory +# define grfio_read(resourcename) grfio_reads (resourcename, NULL) +/// Load file into memory and possibly record length +// For some reason, this allocates an extra 1024 bytes at the end +void *grfio_reads (const char *resourcename, size_t *size); +/// Get size of file +// This is only called once, and that is to check the existence of a file. +size_t grfio_size (const char *resourcename) __attribute__((deprecated)); -// Accessor to GRF filenames -char *grfio_setdatafile (const char *str); -char *grfio_setadatafile (const char *str); -char *grfio_setsdatafile (const char *str); - -#endif // _GRFIO_H_ +#endif // GRFIO_H diff --git a/src/common/lock.c b/src/common/lock.c index bed657f..dd42ef2 100644 --- a/src/common/lock.c +++ b/src/common/lock.c @@ -1,45 +1,36 @@ - #include #include #include "lock.h" #include "socket.h" -// 書き込みファイルの保護処理 -// (書き込みが終わるまで、旧ファイルを保管しておく) +/// Protected file writing +/// (Until the file is closed, it keeps the old file) -// 新しいファイルの書き込み開始 +// Start writing a tmpfile FILE *lock_fopen (const char *filename, int *info) { char newfile[512]; FILE *fp; int no = getpid (); - // 安全なファイル名を得る(手抜き) + // Get a filename that doesn't already exist do { sprintf (newfile, "%s_%d.tmp", filename, no++); } - while ((fp = fopen_ (newfile, "r")) && fclose_ (fp)); + while ((fp = fopen_ (newfile, "r")) && (fclose_ (fp), 1)); *info = --no; return fopen_ (newfile, "w"); } -// 旧ファイルを削除&新ファイルをリネーム -int lock_fclose (FILE * fp, const char *filename, int *info) +// Delete the old file and rename the new file +void lock_fclose (FILE * fp, const char *filename, int *info) { - int ret = 0; char newfile[512]; - if (fp != NULL) + if (fp) { - ret = fclose_ (fp); + fclose_ (fp); sprintf (newfile, "%s_%d.tmp", filename, *info); - remove (filename); - // このタイミングで落ちると最悪。 rename (newfile, filename); - return ret; - } - else - { - return 1; } } diff --git a/src/common/lock.h b/src/common/lock.h index 6175241..2f087fd 100644 --- a/src/common/lock.h +++ b/src/common/lock.h @@ -1,7 +1,8 @@ -#ifndef _LOCK_H_ -#define _LOCK_H_ - +#ifndef LOCK_H +#define LOCK_H +/// Locked FILE I/O +// Changes are made in a separate file until lock_fclose FILE *lock_fopen (const char *filename, int *info); -int lock_fclose (FILE * fp, const char *filename, int *info); +void lock_fclose (FILE * fp, const char *filename, int *info); -#endif +#endif // LOCK_H diff --git a/src/common/malloc.c b/src/common/malloc.c deleted file mode 100644 index 8d68bee..0000000 --- a/src/common/malloc.c +++ /dev/null @@ -1,68 +0,0 @@ -#include -#include -#include -#include "malloc.h" - -#define SHOW_MEMORY_ERROR(file, line, func, type, msg) \ - fprintf (stderr, "%s:%d: in func %s(): %s() error, %s\n", \ - file, line, func, type, msg) - -void *aMalloc_ (size_t size, const char *file, int line, const char *func) -{ - void *ret = malloc (size); - - /* printf ("%s:%d: in func %s(): malloc(%d)\n", file, line, func, size); */ - if (ret == NULL) - { - SHOW_MEMORY_ERROR (file, line, func, "malloc", "out of memory"); - exit (EXIT_FAILURE); - } - - return ret; -} - -void *aCalloc_ (size_t num, size_t size, const char *file, int line, - const char *func) -{ - void *ret = calloc (num, size); - - /* printf ("%s:%d: in func %s(): calloc(%d, %d)\n", file, line, func, num, - size); */ - if (ret == NULL) - { - SHOW_MEMORY_ERROR (file, line, func, "calloc", "out of memory"); - exit (EXIT_FAILURE); - } - - return ret; -} - -void *aRealloc_ (void *p, size_t size, const char *file, int line, - const char *func) -{ - void *ret = realloc (p, size); - - /* printf ("%s:%d: in func %s(): realloc(%p, %d)\n", file, line, func, p, - size); */ - if (ret == NULL) - { - SHOW_MEMORY_ERROR (file, line, func, "realloc", "out of memory"); - exit (EXIT_FAILURE); - } - - return ret; -} - -char *aStrdup_ (const char *p, const char *file, int line, const char *func) -{ - char *ret = strdup (p); - - /* printf ("%s:%d: in func %s(): strdup(%p)\n", file, line, func, p); */ - if (ret == NULL) - { - SHOW_MEMORY_ERROR (file, line, func, "strdup", "out of memory"); - exit (EXIT_FAILURE); - } - - return ret; -} diff --git a/src/common/malloc.h b/src/common/malloc.h deleted file mode 100644 index 5fc8cbe..0000000 --- a/src/common/malloc.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef _MALLOC_H_ -#define _MALLOC_H_ - -#if __STDC_VERSION__ < 199901L -# if __GNUC__ >= 2 -# define __func__ __FUNCTION__ -# else -# define __func__ "" -# endif -#endif - -#define ALC_MARK __FILE__, __LINE__, __func__ - -void *aMalloc_ (size_t, const char *, int, const char *); -void *aCalloc_ (size_t, size_t, const char *, int, const char *); -void *aRealloc_ (void *, size_t, const char *, int, const char *); -char *aStrdup_ (const char *, const char *, int, const char *); - -#define aMalloc(n) aMalloc_(n,ALC_MARK) -#define aMallocA(n) aMalloc_(n,ALC_MARK) -#define aCalloc(m,n) aCalloc_(m,n,ALC_MARK) -#define aCallocA(m,n) aCalloc_(m,n,ALC_MARK) -#define aRealloc(p,n) aRealloc_(p,n,ALC_MARK) -#define aStrdup(p) aStrdup_(p,ALC_MARK) -#define aFree(p) aFree_(p,ALC_MARK) - -#endif diff --git a/src/common/md5calc.c b/src/common/md5calc.c index 6069070..d5ebcf8 100644 --- a/src/common/md5calc.c +++ b/src/common/md5calc.c @@ -1,335 +1,310 @@ -// $Id: md5calc.c,v 1.1.1.1 2004/09/10 17:26:54 MagicalTux Exp $ -/*********************************************************** - * md5 calculation algorithm - * - * The source code referred to the following URL. - * http://www.geocities.co.jp/SiliconValley-Oakland/8878/lab17/lab17.html - * - ***********************************************************/ - #include "md5calc.h" #include -#include #include "mt_rand.h" -#ifndef UINT_MAX -#define UINT_MAX 4294967295U -#endif - -// Global variable -static unsigned int *pX; - -// Stirng Table -static const unsigned int T[] = { +// auxilary data +/* +sin() constant table +# Reformatted output of: +echo 'scale=40; obase=16; for (i=1;i<=64;i++) print 2^32 * sin(i), "\n"' | +bc | sed 's/^-//;s/^/0x/;s/\..*$/,/' +*/ +static const uint32_t T[64] = +{ + // used by round 1 0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee, //0 0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501, //4 0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be, //8 0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821, //12 + // used by round 2 0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa, //16 - 0xd62f105d, 0x2441453, 0xd8a1e681, 0xe7d3fbc8, //20 + 0xd62f105d, 0x02441453, 0xd8a1e681, 0xe7d3fbc8, //20 0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed, //24 0xa9e3e905, 0xfcefa3f8, 0x676f02d9, 0x8d2a4c8a, //28 + // used by round 3 0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c, //32 0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70, //36 - 0x289b7ec6, 0xeaa127fa, 0xd4ef3085, 0x4881d05, //40 + 0x289b7ec6, 0xeaa127fa, 0xd4ef3085, 0x04881d05, //40 0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665, //44 + // used by round 4 0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039, //48 0x655b59c3, 0x8f0ccc92, 0xffeff47d, 0x85845dd1, //52 0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1, //56 - 0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391 //60 + 0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391, //60 }; -// ROTATE_LEFT The left is made to rotate x [ n-bit ]. This is diverted as it is from RFC. -#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) +// auxilary functions +// note - the RFC defines these by non-CS conventions: or=v, and=(empty) +static inline uint32_t rotate_left(uint32_t val, unsigned shift) +{ + return val << shift | val >> (32-shift); +} -// The function used for other calculation -static unsigned int F (unsigned int X, unsigned int Y, unsigned int Z) +static inline uint32_t F(uint32_t X, uint32_t Y, uint32_t Z) { return (X & Y) | (~X & Z); } - -static unsigned int G (unsigned int X, unsigned int Y, unsigned int Z) +static inline uint32_t G(uint32_t X, uint32_t Y, uint32_t Z) { return (X & Z) | (Y & ~Z); } - -static unsigned int H (unsigned int X, unsigned int Y, unsigned int Z) +static inline uint32_t H(uint32_t X, uint32_t Y, uint32_t Z) { return X ^ Y ^ Z; } - -static unsigned int I (unsigned int X, unsigned int Y, unsigned int Z) +static inline uint32_t I(uint32_t X, uint32_t Y, uint32_t Z) { return Y ^ (X | ~Z); } -static unsigned int Round (unsigned int a, unsigned int b, unsigned int FGHI, - unsigned int k, unsigned int s, unsigned int i) +static const struct { - return b + ROTATE_LEFT (a + FGHI + pX[k] + T[i], s); + uint8_t k : 4; + uint8_t : 0; + uint8_t s : 5; +// uint8_t i : 6; just increments constantly, from 1 .. 64 over all rounds } +MD5_round1[16] = +{ + { 0, 7}, { 1, 12}, { 2, 17}, { 3, 22}, + { 4, 7}, { 5, 12}, { 6, 17}, { 7, 22}, + { 8, 7}, { 9, 12}, {10, 17}, {11, 22}, + {12, 7}, {13, 12}, {14, 17}, {15, 22}, +}, +MD5_round2[16] = +{ + { 1, 5}, { 6, 9}, {11, 14}, { 0, 20}, + { 5, 5}, {10, 9}, {15, 14}, { 4, 20}, + { 9, 5}, {14, 9}, { 3, 14}, { 8, 20}, + {13, 5}, { 2, 9}, { 7, 14}, {12, 20}, +}, +MD5_round3[16] = +{ + { 5, 4}, { 8, 11}, {11, 16}, {14, 23}, + { 1, 4}, { 4, 11}, { 7, 16}, {10, 23}, + {13, 4}, { 0, 11}, { 3, 16}, { 6, 23}, + { 9, 4}, {12, 11}, {15, 16}, { 2, 23}, +}, +MD5_round4[16] = +{ + { 0, 6}, { 7, 10}, {14, 15}, { 5, 21}, + {12, 6}, { 3, 10}, {10, 15}, { 1, 21}, + { 8, 6}, {15, 10}, { 6, 15}, {13, 21}, + { 4, 6}, {11, 10}, { 2, 15}, { 9, 21}, +}; -static void Round1 (unsigned int *a, unsigned int b, unsigned int c, - unsigned int d, unsigned int k, unsigned int s, - unsigned int i) + +void MD5_init(MD5_state* state) { - *a = Round (*a, b, F (b, c, d), k, s, i); + // in the RFC, these are specified as bytes, interpreted as little-endian + state->val[0] = 0x67452301; + state->val[1] = 0xEFCDAB89; + state->val[2] = 0x98BADCFE; + state->val[3] = 0x10325476; } -static void Round2 (unsigned int *a, unsigned int b, unsigned int c, - unsigned int d, unsigned int k, unsigned int s, - unsigned int i) +void MD5_do_block(MD5_state* state, MD5_block block) { - *a = Round (*a, b, G (b, c, d), k, s, i); +#define X block.data +#define a state->val[(16-i)%4] +#define b state->val[(17-i)%4] +#define c state->val[(18-i)%4] +#define d state->val[(19-i)%4] + // save the values + const MD5_state saved = *state; + // round 1 + for (int i=0; i<16; i++) + { +#define k MD5_round1[i].k +#define s MD5_round1[i].s + a = b + rotate_left(a + F(b,c,d) + X[k] + T[i+0x0], s); +#undef k +#undef s + } + // round 2 + for (int i=0; i<16; i++) + { +#define k MD5_round2[i].k +#define s MD5_round2[i].s + a = b + rotate_left(a + G(b,c,d) + X[k] + T[i+0x10], s); +#undef k +#undef s + } + // round 3 + for (int i=0; i<16; i++) + { +#define k MD5_round3[i].k +#define s MD5_round3[i].s + a = b + rotate_left(a + H(b,c,d) + X[k] + T[i+0x20], s); +#undef k +#undef s + } + // round 4 + for (int i=0; i<16; i++) + { +#define k MD5_round4[i].k +#define s MD5_round4[i].s + a = b + rotate_left(a + I(b,c,d) + X[k] + T[i+0x30], s); +#undef k +#undef s + } + // adjust state based on original + state->val[0] += saved.val[0]; + state->val[1] += saved.val[1]; + state->val[2] += saved.val[2]; + state->val[3] += saved.val[3]; +#undef a +#undef b +#undef c +#undef d } -static void Round3 (unsigned int *a, unsigned int b, unsigned int c, - unsigned int d, unsigned int k, unsigned int s, - unsigned int i) +void MD5_to_bin(MD5_state state, uint8_t out[0x10]) { - *a = Round (*a, b, H (b, c, d), k, s, i); + for (int i=0; i<0x10; i++) + out[i] = state.val[i/4] >> 8*(i%4); } -static void Round4 (unsigned int *a, unsigned int b, unsigned int c, - unsigned int d, unsigned int k, unsigned int s, - unsigned int i) +static const char hex[0x10] = "0123456789abcdef"; + +void MD5_to_str(MD5_state state, char out[0x21]) { - *a = Round (*a, b, I (b, c, d), k, s, i); + uint8_t bin[16]; + MD5_to_bin(state, bin); + for (int i=0; i<0x10; i++) + out[2*i] = hex[bin[i] >> 4], + out[2*i+1] = hex[bin[i] & 0xf]; + out[0x20] = '\0'; } -static void MD5_Round_Calculate (const unsigned char *block, - unsigned int *A2, unsigned int *B2, - unsigned int *C2, unsigned int *D2) +MD5_state MD5_from_string(const char* msg, const size_t msglen) { - //create X It is since it is required. - unsigned int X[16]; //512bit 64byte - int j, k; - - //Save A as AA, B as BB, C as CC, and and D as DD (saving of A, B, C, and D) - unsigned int A = *A2, B = *B2, C = *C2, D = *D2; - unsigned int AA = A, BB = B, CC = C, DD = D; - - //It is a large region variable reluctantly because of calculation of a round. . . for Round1...4 - pX = X; - - //Copy block(padding_message) i into X - for (j = 0, k = 0; j < 64; j += 4, k++) - X[k] = ((unsigned int) block[j]) // 8byte*4 -> 32byte conversion - | (((unsigned int) block[j + 1]) << 8) // A function called Decode as used in the field of RFC - | (((unsigned int) block[j + 2]) << 16) - | (((unsigned int) block[j + 3]) << 24); - - //Round 1 - Round1 (&A, B, C, D, 0, 7, 0); - Round1 (&D, A, B, C, 1, 12, 1); - Round1 (&C, D, A, B, 2, 17, 2); - Round1 (&B, C, D, A, 3, 22, 3); - Round1 (&A, B, C, D, 4, 7, 4); - Round1 (&D, A, B, C, 5, 12, 5); - Round1 (&C, D, A, B, 6, 17, 6); - Round1 (&B, C, D, A, 7, 22, 7); - Round1 (&A, B, C, D, 8, 7, 8); - Round1 (&D, A, B, C, 9, 12, 9); - Round1 (&C, D, A, B, 10, 17, 10); - Round1 (&B, C, D, A, 11, 22, 11); - Round1 (&A, B, C, D, 12, 7, 12); - Round1 (&D, A, B, C, 13, 12, 13); - Round1 (&C, D, A, B, 14, 17, 14); - Round1 (&B, C, D, A, 15, 22, 15); - - //Round 2 - Round2 (&A, B, C, D, 1, 5, 16); - Round2 (&D, A, B, C, 6, 9, 17); - Round2 (&C, D, A, B, 11, 14, 18); - Round2 (&B, C, D, A, 0, 20, 19); - Round2 (&A, B, C, D, 5, 5, 20); - Round2 (&D, A, B, C, 10, 9, 21); - Round2 (&C, D, A, B, 15, 14, 22); - Round2 (&B, C, D, A, 4, 20, 23); - Round2 (&A, B, C, D, 9, 5, 24); - Round2 (&D, A, B, C, 14, 9, 25); - Round2 (&C, D, A, B, 3, 14, 26); - Round2 (&B, C, D, A, 8, 20, 27); - Round2 (&A, B, C, D, 13, 5, 28); - Round2 (&D, A, B, C, 2, 9, 29); - Round2 (&C, D, A, B, 7, 14, 30); - Round2 (&B, C, D, A, 12, 20, 31); - - //Round 3 - Round3 (&A, B, C, D, 5, 4, 32); - Round3 (&D, A, B, C, 8, 11, 33); - Round3 (&C, D, A, B, 11, 16, 34); - Round3 (&B, C, D, A, 14, 23, 35); - Round3 (&A, B, C, D, 1, 4, 36); - Round3 (&D, A, B, C, 4, 11, 37); - Round3 (&C, D, A, B, 7, 16, 38); - Round3 (&B, C, D, A, 10, 23, 39); - Round3 (&A, B, C, D, 13, 4, 40); - Round3 (&D, A, B, C, 0, 11, 41); - Round3 (&C, D, A, B, 3, 16, 42); - Round3 (&B, C, D, A, 6, 23, 43); - Round3 (&A, B, C, D, 9, 4, 44); - Round3 (&D, A, B, C, 12, 11, 45); - Round3 (&C, D, A, B, 15, 16, 46); - Round3 (&B, C, D, A, 2, 23, 47); - - //Round 4 - Round4 (&A, B, C, D, 0, 6, 48); - Round4 (&D, A, B, C, 7, 10, 49); - Round4 (&C, D, A, B, 14, 15, 50); - Round4 (&B, C, D, A, 5, 21, 51); - Round4 (&A, B, C, D, 12, 6, 52); - Round4 (&D, A, B, C, 3, 10, 53); - Round4 (&C, D, A, B, 10, 15, 54); - Round4 (&B, C, D, A, 1, 21, 55); - Round4 (&A, B, C, D, 8, 6, 56); - Round4 (&D, A, B, C, 15, 10, 57); - Round4 (&C, D, A, B, 6, 15, 58); - Round4 (&B, C, D, A, 13, 21, 59); - Round4 (&A, B, C, D, 4, 6, 60); - Round4 (&D, A, B, C, 11, 10, 61); - Round4 (&C, D, A, B, 2, 15, 62); - Round4 (&B, C, D, A, 9, 21, 63); - - // Then perform the following additions. (let's add) - *A2 = A + AA; - *B2 = B + BB; - *C2 = C + CC; - *D2 = D + DD; - - //The clearance of confidential information - memset (pX, 0, sizeof (X)); + MD5_state state; + MD5_init(&state); + MD5_block block; + size_t rem = msglen; + while (rem >= 64) + { + for (int i=0; i<0x10; i++) + X[i] = msg[4*i+0] | msg[4*i+1]<<8 | msg[4*i+2]<<16 | msg[4*i+3]<<24; + MD5_do_block(&state, block); + msg += 64; + rem -= 64; + } + // now pad 1-512 bits + the 64-bit length - may be two blocks + uint8_t buf[0x40] = {}; + memcpy (buf, msg, rem); + buf[rem] = 0x80; // a single one bit + if (64 - rem > 8) + { + for (int i=0; i<8; i++) + buf[0x38+i] = (msglen*8) >> (i*8); + } + for (int i=0; i<0x10; i++) + X[i] = buf[4*i+0] | buf[4*i+1]<<8 | buf[4*i+2]<<16 | buf[4*i+3]<<24; + MD5_do_block(&state, block); + if (64 - rem <= 8) + { + memset(buf,'\0', 0x38); + for (int i=0; i<8; i++) + buf[0x38+i] = (msglen*8) >> (i*8); + for (int i=0; i<0x10; i++) + X[i] = buf[4*i+0] | buf[4*i+1]<<8 | buf[4*i+2]<<16 | buf[4*i+3]<<24; + MD5_do_block(&state, block); + } + return state; } -//------------------------------------------------------------------- -// The function for the exteriors - -/** output is the coded binary in the character sequence which wants to code string. */ -void MD5_String2binary (const char *string, char *output) +// This could be reimplemented without the strlen() +MD5_state MD5_from_cstring(const char* msg) { -//var - /*8bit */ - unsigned char padding_message[64]; //Extended message 512bit 64byte - unsigned char *pstring; //The position of string in the present scanning notes is held. - -// unsigned char digest[16]; - /*32bit */ - unsigned int string_byte_len, //The byte chief of string is held. - string_bit_len, //The bit length of string is held. - copy_len, //The number of bytes which is used by 1-3 and which remained - msg_digest[4]; //Message digest 128bit 4byte - unsigned int *A = &msg_digest[0], //The message digest in accordance with RFC (reference) - *B = &msg_digest[1], *C = &msg_digest[2], *D = &msg_digest[3]; - int i; + return MD5_from_string(msg, strlen(msg)); +} -//prog - //Step 3.Initialize MD Buffer (although it is the initialization; step 3 of A, B, C, and D -- unavoidable -- a head) - *A = 0x67452301; - *B = 0xefcdab89; - *C = 0x98badcfe; - *D = 0x10325476; +MD5_state MD5_from_FILE(FILE* in) { + uint64_t total_len = 0; - //Step 1.Append Padding Bits (extension of a mark bit) - //1-1 - string_byte_len = strlen (string); //The byte chief of a character sequence is acquired. - pstring = (unsigned char *) string; //The position of the present character sequence is set. + uint8_t buf[0x40]; + uint8_t block_len = 0; - //1-2 Repeat calculation until length becomes less than 64 bytes. - for (i = string_byte_len; 64 <= i; i -= 64, pstring += 64) - MD5_Round_Calculate (pstring, A, B, C, D); + MD5_state state; + MD5_init(&state); - //1-3 - copy_len = string_byte_len % 64; //The number of bytes which remained is computed. - strncpy ((char *) padding_message, (char *) pstring, copy_len); //A message is copied to an extended bit sequence. - memset (padding_message + copy_len, 0, 64 - copy_len); //It buries by 0 until it becomes extended bit length. - padding_message[copy_len] |= 0x80; //The next of a message is 1. + MD5_block block; - //1-4 - //If 56 bytes or more (less than 64 bytes) of remainder becomes, it will calculate by extending to 64 bytes. - if (56 <= copy_len) + while (true) { - MD5_Round_Calculate (padding_message, A, B, C, D); - memset (padding_message, 0, 56); //56 bytes is newly fill uped with 0. + size_t rv = fread(buf + block_len, 1, 0x40 - block_len, in); + if (!rv) + break; + total_len += 8*rv; // in bits + block_len += rv; + if (block_len != 0x40) + continue; + for (int i=0; i<0x10; i++) + X[i] = buf[4*i+0] | buf[4*i+1]<<8 | buf[4*i+2]<<16 | buf[4*i+3]<<24; + MD5_do_block(&state, block); + block_len = 0; } - - //Step 2.Append Length (the information on length is added) - string_bit_len = string_byte_len * 8; //From the byte chief to bit length (32 bytes of low rank) - memcpy (&padding_message[56], &string_bit_len, 4); //32 bytes of low rank is set. - - //When bit length cannot be expressed in 32 bytes of low rank, it is a beam raising to a higher rank. - if (UINT_MAX / 8 < string_byte_len) + // no more input, just pad and append the length + buf[block_len] = 0x80; + memset(buf + block_len + 1, '\0', 0x40 - block_len - 1); + if (block_len < 0x38) { - unsigned int high = (string_byte_len - UINT_MAX / 8) * 8; - memcpy (&padding_message[60], &high, 4); + for (int i=0; i<8; i++) + buf[0x38+i] = total_len >> i*8; } - else - memset (&padding_message[60], 0, 4); //In this case, it is good for a higher rank at 0. - - //Step 4.Process Message in 16-Word Blocks (calculation of MD5) - MD5_Round_Calculate (padding_message, A, B, C, D); - - //Step 5.Output (output) - memcpy (output, msg_digest, 16); -// memcpy (digest, msg_digest, and 16); //8 byte*4 < - 32byte conversion A function called Encode as used in the field of RFC -/* sprintf(output, - "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", - digest[ 0], digest[ 1], digest[ 2], digest[ 3], - digest[ 4], digest[ 5], digest[ 6], digest[ 7], - digest[ 8], digest[ 9], digest[10], digest[11], - digest[12], digest[13], digest[14], digest[15]);*/ + for (int i=0; i<0x10; i++) + X[i] = buf[4*i+0] | buf[4*i+1]<<8 | buf[4*i+2]<<16 | buf[4*i+3]<<24; + MD5_do_block(&state, block); + if (0x38 <= block_len) + { + memset(buf, '\0', 0x38); + for (int i=0; i<8; i++) + buf[0x38+i] = total_len >> i*8; + for (int i=0; i<0x10; i++) + X[i] = buf[4*i+0] | buf[4*i+1]<<8 | buf[4*i+2]<<16 | buf[4*i+3]<<24; + MD5_do_block(&state, block); + } + return state; } -/** output is the coded character sequence in the character sequence which wants to code string. */ -void MD5_String (const char *string, char *output) -{ - unsigned char digest[16]; - - MD5_String2binary (string, digest); - sprintf (output, - "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", - digest[0], digest[1], digest[2], digest[3], - digest[4], digest[5], digest[6], digest[7], - digest[8], digest[9], digest[10], digest[11], - digest[12], digest[13], digest[14], digest[15]); -} // Hash a password with a salt. -char *MD5_saltcrypt(const char *key, const char *salt) +// Whoever wrote this FAILS programming +const char *MD5_saltcrypt(const char *key, const char *salt) { - char buf[66], *sbuf = buf+32; - static char obuf[33]; + char buf[65]; - // hash the key then the salt - // buf ends up as a 64char null terminated string - MD5_String(key, buf); - MD5_String(salt, sbuf); + // hash the key then the salt + // buf ends up as a 64-char NUL-terminated string + MD5_to_str(MD5_from_cstring(key), buf); + MD5_to_str(MD5_from_cstring(salt), buf+32); - // Hash the buffer back into sbuf - MD5_String(buf, sbuf); + // Hash the buffer back into sbuf - this is stupid + // (luckily, putting the result into itself is safe) + MD5_to_str(MD5_from_cstring(buf), buf+32); - snprintf(obuf, 32, "!%s$%s", salt, sbuf); - return(obuf); + static char obuf[33]; + // This truncates the string, but we have to keep it like that for compatibility + snprintf(obuf, 32, "!%s$%s", salt, buf+32); + return obuf; } -char *make_salt() { - static char salt[6]; - int i; - for (i=0; i<5; i++) - salt[i] = (char)((mt_rand() % 78) + 48); - salt[5] = '\0'; - return(salt); +const char *make_salt() { + static char salt[6]; + for (int i=0; i<5; i++) + salt[i] = MPRAND(48, 78); + return salt; } -int pass_ok(const char *password, const char *crypted) { - char buf[40], *salt=buf+1; +bool pass_ok(const char *password, const char *crypted) { + char buf[40]; + strncpy(buf, crypted, 40); + char *salt = buf + 1; + *strchr(salt, '$') = '\0'; - strncpy(buf, crypted, 40); - *strchr(buf, '$') = '\0'; - - if (!strcmp(crypted, MD5_saltcrypt(password, salt))) - return(1); - - return(0); + return !strcmp(crypted, MD5_saltcrypt(password, salt)); } // [M|h]ashes up an IP address and a secret key @@ -337,13 +312,13 @@ int pass_ok(const char *password, const char *crypted) { in_addr_t MD5_ip(char *secret, in_addr_t ip) { char ipbuf[32]; - char obuf[16]; + uint8_t obuf[16]; union { struct bytes { - unsigned char b1; - unsigned char b2; - unsigned char b3; - unsigned char b4; + uint8_t b1; + uint8_t b2; + uint8_t b3; + uint8_t b4; } bytes; in_addr_t ip; } conv; @@ -351,7 +326,8 @@ in_addr_t MD5_ip(char *secret, in_addr_t ip) // MD5sum a secret + the IP address memset(&ipbuf, 0, sizeof(ipbuf)); snprintf(ipbuf, sizeof(ipbuf), "%lu%s", (unsigned long)ip, secret); - MD5_String2binary(ipbuf, obuf); + /// TODO stop it from being a cstring + MD5_to_bin(MD5_from_cstring(ipbuf), obuf); // Fold the md5sum to 32 bits, pack the bytes to an in_addr_t conv.bytes.b1 = obuf[0] ^ obuf[1] ^ obuf[8] ^ obuf[9]; @@ -361,4 +337,3 @@ in_addr_t MD5_ip(char *secret, in_addr_t ip) return conv.ip; } - diff --git a/src/common/md5calc.h b/src/common/md5calc.h index 5994376..cf1425f 100644 --- a/src/common/md5calc.h +++ b/src/common/md5calc.h @@ -1,13 +1,64 @@ -// $Id: md5calc.h,v 1.1.1.1 2004/09/10 17:26:54 MagicalTux Exp $ -#ifndef _MD5CALC_H_ -#define _MD5CALC_H_ +#ifndef MD5CALC_H +#define MD5CALC_H + +#include "sanity.h" + #include -void MD5_String (const char *string, char *output); -void MD5_String2binary (const char *string, char *output); -char *MD5_saltcrypt(const char *key, const char *salt); -char *make_salt(); -int pass_ok(const char *password, const char *crypted); +#include // uint32_t, uint8_t +#include // size_t +#include // FILE* + +/// The digest state - becomes the output +typedef struct +{ + // classically named {A,B,C,D} + // but use an so we can index + uint32_t val[4]; +} MD5_state; +typedef struct +{ + uint32_t data[16]; +} MD5_block; + +// Implementation +void MD5_init(MD5_state* state); +void MD5_do_block(MD5_state* state, MD5_block block); + +// Output formatting +void MD5_to_bin(MD5_state state, uint8_t out[0x10]); +void MD5_to_str(MD5_state state, char out[0x21]); + +// Convenience +MD5_state MD5_from_string(const char* msg, const size_t msglen); +MD5_state MD5_from_cstring(const char* msg); +MD5_state MD5_from_FILE(FILE* in); + + +/// Output in ASCII - with lowercase hex digits, null-terminated +// these may overlap safely +static void MD5_String (const char *string, char output[33]) __attribute__((deprecated)); +static inline void MD5_String (const char *string, char output[33]) { + MD5_to_str(MD5_from_cstring(string), output); +} +/// Output in binary +static void MD5_String2binary (const char *string, uint8_t output[16]) __attribute__((deprecated)); +static inline void MD5_String2binary (const char *string, uint8_t output[16]) { + MD5_to_bin(MD5_from_cstring(string), output); +} + +// statically-allocated output +// whoever wrote this fails basic understanding of +const char *MD5_saltcrypt(const char *key, const char *salt); + +/// return some random characters (statically allocated) +// Currently, returns a 5-char string +const char *make_salt(); + +/// check plaintext password against saved saltcrypt +bool pass_ok(const char *password, const char *crypted); + +/// This returns an in_addr_t because it is configurable whether it gets called at all in_addr_t MD5_ip(char *secret, in_addr_t ip); #endif diff --git a/src/common/mmo.h b/src/common/mmo.h index 279bf4a..906f5c1 100644 --- a/src/common/mmo.h +++ b/src/common/mmo.h @@ -1,69 +1,67 @@ -// $Id: mmo.h,v 1.3 2004/09/25 20:12:25 PoW Exp $ -// Original : mmo.h 2003/03/14 12:07:02 Rev.1.7 +/// Global structures and defines +#ifndef MMO_H +#define MMO_H -#ifndef _MMO_H_ -#define _MMO_H_ +# include +# include "utils.h" // LCCWIN32 -#include -#include "utils.h" // LCCWIN32 +# ifdef CYGWIN +# define RETCODE "\r\n" +# else +# define RETCODE "\n" +# endif -#ifdef CYGWIN -#define RETCODE "\r\n" // (CR/LF:Windows系) -#else -#define RETCODE "\n" // (LF:Unix系) -#endif - -#define FIFOSIZE_SERVERLINK 256*1024 +# define FIFOSIZE_SERVERLINK 256*1024 // set to 0 to not check IP of player between each server. // set to another value if you want to check (1) -#define CMP_AUTHFIFO_IP 1 - -#define CMP_AUTHFIFO_LOGIN2 1 - -#define MAX_MAP_PER_SERVER 512 -#define MAX_INVENTORY 100 -#define MAX_AMOUNT 30000 -#define MAX_ZENY 1000000000 // 1G zeny -#define MAX_CART 100 -#define MAX_SKILL 450 -#define GLOBAL_REG_NUM 96 -#define ACCOUNT_REG_NUM 16 -#define ACCOUNT_REG2_NUM 16 -#define DEFAULT_WALK_SPEED 150 -#define MIN_WALK_SPEED 0 -#define MAX_WALK_SPEED 1000 -#define MAX_STORAGE 300 -#define MAX_GUILD_STORAGE 1000 -#define MAX_PARTY 12 -#define MAX_GUILD 120 // increased max guild members to accomodate for +2 increase for extension levels [Valaris] (removed) [PoW] -#define MAX_GUILDPOSITION 20 // increased max guild positions to accomodate for all members [Valaris] (removed) [PoW] -#define MAX_GUILDEXPLUSION 32 -#define MAX_GUILDALLIANCE 16 -#define MAX_GUILDSKILL 8 -#define MAX_GUILDCASTLE 24 // increased to include novice castles [Valaris] -#define MAX_GUILDLEVEL 50 - -#define MIN_HAIR_STYLE battle_config.min_hair_style -#define MAX_HAIR_STYLE battle_config.max_hair_style -#define MIN_HAIR_COLOR battle_config.min_hair_color -#define MAX_HAIR_COLOR battle_config.max_hair_color -#define MIN_CLOTH_COLOR battle_config.min_cloth_color -#define MAX_CLOTH_COLOR battle_config.max_cloth_color +# define CMP_AUTHFIFO_IP 1 + +# define CMP_AUTHFIFO_LOGIN2 1 + +# define MAX_MAP_PER_SERVER 512 +# define MAX_INVENTORY 100 +# define MAX_AMOUNT 30000 +# define MAX_ZENY 1000000000 // 1G zeny +# define MAX_CART 100 +# define MAX_SKILL 450 +# define GLOBAL_REG_NUM 96 +# define ACCOUNT_REG_NUM 16 +# define ACCOUNT_REG2_NUM 16 +# define DEFAULT_WALK_SPEED 150 +# define MIN_WALK_SPEED 0 +# define MAX_WALK_SPEED 1000 +# define MAX_STORAGE 300 +# define MAX_GUILD_STORAGE 1000 +# define MAX_PARTY 12 +# define MAX_GUILD 120 // increased max guild members to accomodate for +2 increase for extension levels [Valaris] (removed) [PoW] +# define MAX_GUILDPOSITION 20 // increased max guild positions to accomodate for all members [Valaris] (removed) [PoW] +# define MAX_GUILDEXPLUSION 32 +# define MAX_GUILDALLIANCE 16 +# define MAX_GUILDSKILL 8 +# define MAX_GUILDCASTLE 24 // increased to include novice castles [Valaris] +# define MAX_GUILDLEVEL 50 + +# define MIN_HAIR_STYLE battle_config.min_hair_style +# define MAX_HAIR_STYLE battle_config.max_hair_style +# define MIN_HAIR_COLOR battle_config.min_hair_color +# define MAX_HAIR_COLOR battle_config.max_hair_color +# define MIN_CLOTH_COLOR battle_config.min_cloth_color +# define MAX_CLOTH_COLOR battle_config.max_cloth_color // for produce -#define MIN_ATTRIBUTE 0 -#define MAX_ATTRIBUTE 4 -#define ATTRIBUTE_NORMAL 0 -#define MIN_STAR 0 -#define MAX_STAR 3 +# define MIN_ATTRIBUTE 0 +# define MAX_ATTRIBUTE 4 +# define ATTRIBUTE_NORMAL 0 +# define MIN_STAR 0 +# define MAX_STAR 3 -#define MIN_PORTAL_MEMO 0 -#define MAX_PORTAL_MEMO 2 +# define MIN_PORTAL_MEMO 0 +# define MAX_PORTAL_MEMO 2 -#define MAX_STATUS_TYPE 5 +# define MAX_STATUS_TYPE 5 -#define CHAR_CONF_NAME "conf/char_athena.conf" +# define CHAR_CONF_NAME "conf/char_athena.conf" struct item { @@ -288,19 +286,4 @@ enum }; -#ifndef LCCWIN32 -#ifndef strcmpi -#define strcmpi strcasecmp -#endif -#ifndef stricmp -#define stricmp strcasecmp -#endif -#ifndef strncmpi -#define strncmpi strncasecmp -#endif -#ifndef strnicmp -#define strnicmp strncasecmp -#endif -#endif - -#endif // _MMO_H_ +#endif // MMO_H diff --git a/src/common/mt_rand.c b/src/common/mt_rand.c index 627d9dd..e4e8d12 100644 --- a/src/common/mt_rand.c +++ b/src/common/mt_rand.c @@ -48,71 +48,69 @@ #include #include "mt_rand.h" -#define N (624) /* length of state vector */ -#define M (397) /* a period parameter */ -#define K (0x9908B0DFU) /* a magic constant */ -#define hiBit(u) ((u) & 0x80000000U) /* mask all but highest bit of u */ -#define loBit(u) ((u) & 0x00000001U) /* mask all but lowest bit of u */ -#define loBits(u) ((u) & 0x7FFFFFFFU) /* mask the highest bit of u */ -#define mixBits(u, v) (hiBit(u)|loBits(v)) /* move hi bit of u to hi bit of v */ +#define N 624 // length of state vector +#define M 397 // a period parameter +#define K 0x9908B0DFU // a magic constant -static unsigned long state[N + 1]; /* state vector + 1 extra to not violate ANSI C */ -static unsigned long *next; /* next random value is computed from here */ -static int left = -1; /* can *next++ this many times before reloading */ +#define hiBit(u) ((u) & 0x80000000U) // mask all but highest bit of u +#define loBit(u) ((u) & 0x00000001U) // mask all but lowest bit of u +#define loBits(u) ((u) & 0x7FFFFFFFU) // mask the highest bit of u +#define mixBits(u, v) (hiBit(u)|loBits(v)) // move hi bit of u to hi bit of v -void mt_seed (unsigned long seed) +static uint32_t state[N+1]; // state vector the +1 is needed due to the coding +static uint32_t *next; // next random value is computed from here +static int left = -1; // can *next++ this many times before reloading + +void mt_seed (uint32_t seed) { - register unsigned long x = (seed | 1U) & 0xFFFFFFFFU, *s = state; - register int j; + uint32_t x = seed | 1U; + uint32_t *s = state; + left = 0; - for (left = 0, *s++ = x, j = N; --j; *s++ = (x *= 69069U) & 0xFFFFFFFFU); + for (int j = N; *s++ = x, --j; x *= 69069U); } -unsigned long mt_reload (void) +void mt_reload (void) { - register unsigned long *p0 = state, *p2 = state + 2, *pM = - state + M, s0, s1; - register int j; - + // if mt_seed has never been called if (left < -1) mt_seed (time (NULL)); - left = N - 1, next = state + 1; + // conceptually, these are indices into the state that wrap + uint32_t *p0 = state; + uint32_t *p2 = state + 2; + uint32_t *pM = state + M; + + uint32_t s0 = state[0]; + uint32_t s1 = state[1]; - for (s0 = state[0], s1 = state[1], j = N - M + 1; --j; - s0 = s1, s1 = *p2++) + // regenerate the lower N-M elements of the state + for (int j = N-M+1; --j != 0; s0 = s1, s1 = *p2++) *p0++ = *pM++ ^ (mixBits (s0, s1) >> 1) ^ (loBit (s1) ? K : 0U); - for (pM = state, j = M; --j; s0 = s1, s1 = *p2++) + pM = state; + // regenerate the next M-1 elements of the state + // note that s1 is set to state[N] at the end, but discarded + for (int j = M; --j != 0; s0 = s1, s1 = *p2++) *p0++ = *pM++ ^ (mixBits (s0, s1) >> 1) ^ (loBit (s1) ? K : 0U); - s1 = state[0], *p0 = - *pM ^ (mixBits (s0, s1) >> 1) ^ (loBit (s1) ? K : 0U); - s1 ^= (s1 >> 11); - s1 ^= (s1 << 7) & 0x9D2C5680U; - s1 ^= (s1 << 15) & 0xEFC60000U; - return (s1 ^ (s1 >> 18)); + // regenerate the last 1 element of the state + s1 = state[0]; + *p0 = *pM ^ (mixBits (s0, s1) >> 1) ^ (loBit (s1) ? K : 0U); + + // ready for the normal mt_random algorithm + left = N; + next = state; } -unsigned long mt_random (void) +uint32_t mt_random (void) { - unsigned long y; - if (--left < 0) - return (mt_reload ()); + mt_reload (); - y = *next++; + uint32_t y = *next++; y ^= (y >> 11); y ^= (y << 7) & 0x9D2C5680U; y ^= (y << 15) & 0xEFC60000U; - return (y ^ (y >> 18)); -} - -int mt_rand (void) -{ - unsigned long r = mt_random (); - while (r >> 16) - r = (r & 0xFFFF) + (r >> 16); - - return (r); + return y ^ (y >> 18); } diff --git a/src/common/mt_rand.h b/src/common/mt_rand.h index d798fee..95f30e5 100644 --- a/src/common/mt_rand.h +++ b/src/common/mt_rand.h @@ -1,9 +1,21 @@ -#ifndef __mt_rand_h -#define __mt_rand_h +#ifndef MT_RAND_H +#define MT_RAND_H -void mt_seed (unsigned long seed); -unsigned long mt_reload (void); -unsigned long mt_random (void); -int mt_rand (void); +# include "sanity.h" -#endif /* __mt_rand_h */ +/// Initialize the generator (called automatically with time() if you don't) +void mt_seed (uint32_t seed); +/// Get a random number +uint32_t mt_random (void); + +/** + * ModuloRand and ModuloPlusRand + * These macros are used to replace the vast number of calls to rand()%mod + * TODO eliminate the rest of the calls to rand() + * MRAND(10) returns 0..9 + * MPRAND(5,10) returns 5..14 + */ +# define MRAND(mod) (mt_random() % (mod)) +# define MPRAND(add, mod) ((add) + MRAND(mod)) + +#endif // MT_RAND_H diff --git a/src/common/nullpo.c b/src/common/nullpo.c index 3205293..de10517 100644 --- a/src/common/nullpo.c +++ b/src/common/nullpo.c @@ -2,21 +2,17 @@ #include #include #include "nullpo.h" -// #include "logs.h" // 布石してみる static void nullpo_info_core (const char *file, int line, const char *func, const char *fmt, va_list ap); -/*====================================== - * Nullチェック 及び 情報出力 - *-------------------------------------- - */ -int nullpo_chk_f (const char *file, int line, const char *func, - const void *target, const char *fmt, ...) +/// Null check and print format +bool nullpo_chk_f (const char *file, int line, const char *func, + const void *target, const char *fmt, ...) { va_list ap; - if (target != NULL) + if (target) return 0; va_start (ap, fmt); @@ -24,21 +20,17 @@ int nullpo_chk_f (const char *file, int line, const char *func, va_end (ap); return 1; } - -int nullpo_chk (const char *file, int line, const char *func, - const void *target) +bool nullpo_chk (const char *file, int line, const char *func, + const void *target) { - if (target != NULL) + if (target) return 0; nullpo_info_core (file, line, func, NULL, NULL); return 1; } -/*====================================== - * nullpo情報出力(外部呼出し向けラッパ) - *-------------------------------------- - */ +/// External functions void nullpo_info_f (const char *file, int line, const char *func, const char *fmt, ...) { @@ -48,39 +40,25 @@ void nullpo_info_f (const char *file, int line, const char *func, nullpo_info_core (file, line, func, fmt, ap); va_end (ap); } - void nullpo_info (const char *file, int line, const char *func) { nullpo_info_core (file, line, func, NULL, NULL); } -/*====================================== - * nullpo情報出力(Main) - *-------------------------------------- - */ +/// Actual output function static void nullpo_info_core (const char *file, int line, const char *func, const char *fmt, va_list ap) { - if (file == NULL) + if (!file) file = "??"; + if (!func || !*func) + func = "unknown"; - func = func == NULL ? "unknown" : func[0] == '\0' ? "unknown" : func; - - printf ("--- nullpo info --------------------------------------------\n"); - printf ("%s:%d: in func `%s'\n", file, line, func); - if (fmt != NULL) + fprintf (stderr, "%s:%d: in func `%s': NULL pointer\n", file, line, func); + if (fmt && *fmt) { - if (fmt[0] != '\0') - { - vprintf (fmt, ap); - - // 最後に改行したか確認 - if (fmt[strlen (fmt) - 1] != '\n') - printf ("\n"); - } + vfprintf (stderr, fmt, ap); + if (fmt[strlen (fmt) - 1] != '\n') + fputc('\n', stderr); } - printf ("--- end nullpo info ----------------------------------------\n"); - - // ここらでnullpoログをファイルに書き出せたら - // まとめて提出できるなと思っていたり。 } diff --git a/src/common/nullpo.h b/src/common/nullpo.h index baeacdc..9b33b4b 100644 --- a/src/common/nullpo.h +++ b/src/common/nullpo.h @@ -1,215 +1,61 @@ -#ifndef _NULLPO_H_ -#define _NULLPO_H_ - -#define NULLPO_CHECK 1 - // 全体のスイッチを宣言しているヘッダがあれば - // そこに移動していただけると - -#if __STDC_VERSION__ < 199901L -# if __GNUC__ >= 2 -# define __func__ __FUNCTION__ -# else -# define __func__ "" -# endif -#endif - -#ifdef LCCWIN32 -#define __attribute__(x) /* nothing */ -#endif - -#define NLP_MARK __FILE__, __LINE__, __func__ - -/*---------------------------------------------------------------------------- - * Macros - *---------------------------------------------------------------------------- - */ -/*====================================== - * Nullチェック 及び 情報出力後 return - *・展開するとifとかreturn等が出るので - * 一行単体で使ってください。 - *・nullpo_ret(x = func()); - * のような使用法も想定しています。 - *-------------------------------------- - * nullpo_ret(t) - * 戻り値 0固定 - * [引数] - * t チェック対象 - *-------------------------------------- - * nullpo_retv(t) - * 戻り値 なし - * [引数] - * t チェック対象 - *-------------------------------------- - * nullpo_retr(ret, t) - * 戻り値 指定 - * [引数] - * ret return(ret); - * t チェック対象 - *-------------------------------------- - * nullpo_ret_f(t, fmt, ...) - * 詳細情報出力用 - * 戻り値 0 - * [引数] - * t チェック対象 - * fmt ... vprintfに渡される - * 備考や関係変数の書き出しなどに - *-------------------------------------- - * nullpo_retv_f(t, fmt, ...) - * 詳細情報出力用 - * 戻り値 なし - * [引数] - * t チェック対象 - * fmt ... vprintfに渡される - * 備考や関係変数の書き出しなどに - *-------------------------------------- - * nullpo_retr_f(ret, t, fmt, ...) - * 詳細情報出力用 - * 戻り値 指定 - * [引数] - * ret return(ret); - * t チェック対象 - * fmt ... vprintfに渡される - * 備考や関係変数の書き出しなどに - *-------------------------------------- - */ - -#if NULLPO_CHECK - -#define nullpo_ret(t) \ - if (nullpo_chk(NLP_MARK, (void *)(t))) {return(0);} - -#define nullpo_retv(t) \ - if (nullpo_chk(NLP_MARK, (void *)(t))) {return;} - -#define nullpo_retr(ret, t) \ - if (nullpo_chk(NLP_MARK, (void *)(t))) {return(ret);} - -// 可変引数マクロに関する条件コンパイル -#if __STDC_VERSION__ >= 199901L -/* C99に対応 */ -#define nullpo_ret_f(t, fmt, ...) \ - if (nullpo_chk_f(NLP_MARK, (void *)(t), (fmt), __VA_ARGS__)) {return(0);} - -#define nullpo_retv_f(t, fmt, ...) \ - if (nullpo_chk_f(NLP_MARK, (void *)(t), (fmt), __VA_ARGS__)) {return;} - -#define nullpo_retr_f(ret, t, fmt, ...) \ - if (nullpo_chk_f(NLP_MARK, (void *)(t), (fmt), __VA_ARGS__)) {return(ret);} - -#elif __GNUC__ >= 2 -/* GCC用 */ -#define nullpo_ret_f(t, fmt, args...) \ - if (nullpo_chk_f(NLP_MARK, (void *)(t), (fmt), ## args)) {return(0);} - -#define nullpo_retv_f(t, fmt, args...) \ - if (nullpo_chk_f(NLP_MARK, (void *)(t), (fmt), ## args)) {return;} - -#define nullpo_retr_f(ret, t, fmt, args...) \ - if (nullpo_chk_f(NLP_MARK, (void *)(t), (fmt), ## args)) {return(ret);} - -#else - -/* その他の場合・・・ orz */ - -#endif - -#else /* NULLPO_CHECK */ -/* No Nullpo check */ - -// if((t)){;} -// 良い方法が思いつかなかったので・・・苦肉の策です。 -// 一応ワーニングは出ないはず - -#define nullpo_ret(t) if((t)){;} -#define nullpo_retv(t) if((t)){;} -#define nullpo_retr(ret, t) if((t)){;} - -// 可変引数マクロに関する条件コンパイル -#if __STDC_VERSION__ >= 199901L -/* C99に対応 */ -#define nullpo_ret_f(t, fmt, ...) if((t)){;} -#define nullpo_retv_f(t, fmt, ...) if((t)){;} -#define nullpo_retr_f(ret, t, fmt, ...) if((t)){;} - -#elif __GNUC__ >= 2 -/* GCC用 */ -#define nullpo_ret_f(t, fmt, args...) if((t)){;} -#define nullpo_retv_f(t, fmt, args...) if((t)){;} -#define nullpo_retr_f(ret, t, fmt, args...) if((t)){;} - -#else -/* その他の場合・・・ orz */ -#endif - -#endif /* NULLPO_CHECK */ - -/*---------------------------------------------------------------------------- - * Functions - *---------------------------------------------------------------------------- - */ -/*====================================== - * nullpo_chk - * Nullチェック 及び 情報出力 - * [引数] - * file __FILE__ - * line __LINE__ - * func __func__ (関数名) - * これらには NLP_MARK を使うとよい - * target チェック対象 - * [返り値] - * 0 OK - * 1 NULL - *-------------------------------------- - */ -int nullpo_chk (const char *file, int line, const char *func, +/// return wrappers for unexpected NULL pointers +#ifndef NULLPO_H +#define NULLPO_H +/// Comment this out to live dangerously +# define NULLPO_CHECK + +/// All functions print to standard error (was: standard output) +/// nullpo_ret(cond) - return 0 if given pointer is NULL +/// nullpo_retv(cond) - just return (function returns void) +/// nullpo_retr(rv, cond) - return given value instead +/// the _f variants take a printf-format string and arguments + +# ifdef NULLPO_CHECK +# define NLP_MARK __FILE__, __LINE__, __func__ +# define nullpo_ret(t) \ + if (nullpo_chk(NLP_MARK, t)) \ + return 0; +# define nullpo_retv(t) \ + if (nullpo_chk(NLP_MARK, t)) \ + return; +# define nullpo_retr(ret, t) \ + if (nullpo_chk(NLP_MARK, t)) \ + return ret; +# define nullpo_ret_f(t, fmt, ...) \ + if (nullpo_chk_f(NLP_MARK, t, fmt, ##__VA_ARGS__)) \ + return 0; +# define nullpo_retv_f(t, fmt, ...) \ + if (nullpo_chk_f(NLP_MARK, t, fmt, ##__VA_ARGS__)) \ + return; +# define nullpo_retr_f(ret, t, fmt, ...) \ + if (nullpo_chk_f(NLP_MARK, t, fmt, ##__VA_ARGS__)) \ + return ret; +# else // NULLPO_CHECK +# define nullpo_ret(t) t; +# define nullpo_retv(t) t; +# define nullpo_retr(ret, t) t; +# define nullpo_ret_f(t, fmt, ...) t; +# define nullpo_retv_f(t, fmt, ...) t; +# define nullpo_retr_f(ret, t, fmt, ...) t; +# endif // NULLPO_CHECK + +# include "sanity.h" + +/// Used by macros in this header +bool nullpo_chk (const char *file, int line, const char *func, const void *target); -/*====================================== - * nullpo_chk_f - * Nullチェック 及び 詳細な情報出力 - * [引数] - * file __FILE__ - * line __LINE__ - * func __func__ (関数名) - * これらには NLP_MARK を使うとよい - * target チェック対象 - * fmt ... vprintfに渡される - * 備考や関係変数の書き出しなどに - * [返り値] - * 0 OK - * 1 NULL - *-------------------------------------- - */ -int nullpo_chk_f (const char *file, int line, const char *func, +/// Used by macros in this header +bool nullpo_chk_f (const char *file, int line, const char *func, const void *target, const char *fmt, ...) __attribute__ ((format (printf, 5, 6))); -/*====================================== - * nullpo_info - * nullpo情報出力 - * [引数] - * file __FILE__ - * line __LINE__ - * func __func__ (関数名) - * これらには NLP_MARK を使うとよい - *-------------------------------------- - */ +/// Used only by map/battle.c void nullpo_info (const char *file, int line, const char *func); -/*====================================== - * nullpo_info_f - * nullpo詳細情報出力 - * [引数] - * file __FILE__ - * line __LINE__ - * func __func__ (関数名) - * これらには NLP_MARK を使うとよい - * fmt ... vprintfに渡される - * 備考や関係変数の書き出しなどに - *-------------------------------------- - */ +/// Not used void nullpo_info_f (const char *file, int line, const char *func, const char *fmt, ...) __attribute__ ((format (printf, 4, 5))); -#endif +#endif // NULLPO_H diff --git a/src/common/sanity.h b/src/common/sanity.h new file mode 100644 index 0000000..168671f --- /dev/null +++ b/src/common/sanity.h @@ -0,0 +1,36 @@ +/// return wrappers for unexpected NULL pointers +#ifndef SANITY_H +#define SANITY_H +# if __STDC_VERSION__ < 199901L +# error "Please compile in C99 mode" +# endif +# if __GNUC__ < 3 +// I don't specifically know what version this requires, +// but GCC 3 was the beginning of modern GCC +# error "Please upgrade your compiler to at least GCC 3" +# endif +# ifndef __i386__ +// Known platform dependencies: +// endianness for the [RW]FIFO.* macros +// possibly, some signal-handling +# error "Unsupported platform" +# endif +# ifdef __x86_64__ +// I'm working on it - I know there are some pointer-size assumptions. +# error "Sorry, this code is believed not to be 64-bit safe" +# error "please compile with -m32" +# endif + +/// A name for unused function arguments - can be repeated +# define UNUSED UNUSED_IMPL(__COUNTER__) +// Don't you just love the hoops the preprocessor makes you go through? +# define UNUSED_IMPL(arg) UNUSED_IMPL2(arg) +# define UNUSED_IMPL2(suffix) unused_ ## suffix __attribute__((unused)) +/// Convert conditions to use the bool type +# include +/// Convert type assumptions to use the standard types here +# include +/// size_t, NULL +# include + +#endif // SANITY_H diff --git a/src/common/socket.c b/src/common/socket.c index dbf19c1..7c86b1a 100644 --- a/src/common/socket.c +++ b/src/common/socket.c @@ -6,17 +6,11 @@ #include #include -#ifdef LCCWIN32 -#define WIN32_LEAN_AND_MEAN -#include -#include -#else #include #include #include #include #include -#endif #include #include @@ -25,191 +19,115 @@ #include "socket.h" #include "utils.h" -#ifdef MEMWATCH -#include "memwatch.h" -#endif - fd_set readfds; int fd_max; int currentuse; -int rfifo_size = 65536; -int wfifo_size = 65536; +const uint32_t rfifo_size = 65536; +const uint32_t wfifo_size = 65536; struct socket_data *session[FD_SETSIZE]; -static int null_parse (int fd); -static int (*default_func_parse) (int) = null_parse; +/// Discard all input +static void null_parse (int fd); +/// Default parser for new connections +static void (*default_func_parse) (int) = null_parse; -/*====================================== - * CORE : Set function - *-------------------------------------- - */ -void set_defaultparse (int (*defaultparse) (int)) +void set_defaultparse (void (*defaultparse) (int)) { default_func_parse = defaultparse; } -/*====================================== - * CORE : Socket Sub Function - *-------------------------------------- - */ - -static int recv_to_fifo (int fd) +/// Read from socket to the queue +static void recv_to_fifo (int fd) { - int len; - - //printf("recv_to_fifo : %d %d\n",fd,session[fd]->eof); if (session[fd]->eof) - return -1; - -#ifdef LCCWIN32 - len = - recv (fd, session[fd]->rdata + session[fd]->rdata_size, - RFIFOSPACE (fd), 0); -#else - len = - read (fd, session[fd]->rdata + session[fd]->rdata_size, - RFIFOSPACE (fd)); -#endif + return; -// printf (":::RECEIVE:::\n"); -// dump(session[fd]->rdata, len); printf ("\n"); + ssize_t len = read (fd, session[fd]->rdata + session[fd]->rdata_size, + RFIFOSPACE (fd)); - //{ int i; printf("recv %d : ",fd); for(i=0;irdata_size+i)); } printf("\n");} if (len > 0) { session[fd]->rdata_size += len; - if (!session[fd]->connected) - session[fd]->connected = 1; + session[fd]->connected = 1; } - else if (len <= 0) + else { - // value of connection is not necessary the same -// if (fd == 4) // Removed [Yor] -// printf("Char-Server Has Disconnected.\n"); -// else if (fd == 5) // Removed [Yor] -// printf("Attempt To Log In Successful.\n"); -// else if (fd == 7) // Removed [Yor] -// printf("Char-Server Has Disconnected.\n"); -// else if (fd == 8) // Removed [Valaris] -// printf("%s has logged off your server.\n",RFIFOP(fd,6)); // Removed [Valaris] - -// else if (fd != 8) // [Valaris] - printf ("set eof : connection #%d\n", fd); session[fd]->eof = 1; } - return 0; } -static int send_from_fifo (int fd) +static void send_from_fifo (int fd) { - int len; - - //printf("send_from_fifo : %d\n",fd); if (session[fd]->eof) - return -1; - -#ifdef LCCWIN32 - len = send (fd, session[fd]->wdata, session[fd]->wdata_size, 0); -#else - len = write (fd, session[fd]->wdata, session[fd]->wdata_size); -#endif + return; -// printf (":::SEND:::\n"); -// dump(session[fd]->wdata, len); printf ("\n"); + ssize_t len = write (fd, session[fd]->wdata, session[fd]->wdata_size); - //{ int i; printf("send %d : ",fd); for(i=0;iwdata[i]); } printf("\n");} if (len > 0) { - if (len < session[fd]->wdata_size) + session[fd]->wdata_size -= len; + if (len < (ssize_t)session[fd]->wdata_size) { memmove (session[fd]->wdata, session[fd]->wdata + len, - session[fd]->wdata_size - len); - session[fd]->wdata_size -= len; + session[fd]->wdata_size); } - else - { - session[fd]->wdata_size = 0; - } - if (!session[fd]->connected) - session[fd]->connected = 1; + session[fd]->connected = 1; } else { - printf ("set eof :%d\n", fd); session[fd]->eof = 1; } - return 0; } -static int null_parse (int fd) +static void null_parse (int fd) { printf ("null_parse : %d\n", fd); RFIFOSKIP (fd, RFIFOREST (fd)); - return 0; } -/*====================================== - * CORE : Socket Function - *-------------------------------------- - */ -static int connect_client (int listen_fd) +static void connect_client (int listen_fd) { - int fd; struct sockaddr_in client_address; - unsigned int len; - int result; - int yes = 1; // reuse fix - - //printf("connect_client : %d\n",listen_fd); - - printf ("used: %d, max FDs: %d, SOFT: %d\n", currentuse, FD_SETSIZE, - SOFT_LIMIT); - - len = sizeof (client_address); + socklen_t len = sizeof (client_address); - fd = accept (listen_fd, (struct sockaddr *) &client_address, &len); - if (fd_max <= fd) + int fd = accept (listen_fd, (struct sockaddr *) &client_address, &len); + if (fd == -1) { - fd_max = fd + 1; + perror ("accept"); + return; } - else if (fd == -1) + if (fd_max <= fd) { - perror ("accept"); - return -1; + fd_max = fd + 1; } if (!free_fds ()) - { // gracefully end the connecting if no free FD - printf ("softlimit reached, disconnecting : %d\n", fd); + { + fprintf (stderr, "softlimit reached, disconnecting : %d\n", fd); delete_session (fd); - return -1; + return; } -// setsockopt(fd,SOL_SOCKET,SO_REUSEADDR,NULL,0); - setsockopt (fd, SOL_SOCKET, SO_REUSEADDR, (char *) &yes, sizeof yes); // reuse fix -#ifdef SO_REUSEPORT -// setsockopt(fd,SOL_SOCKET,SO_REUSEPORT,NULL,0); - setsockopt (fd, SOL_SOCKET, SO_REUSEPORT, (char *) &yes, sizeof yes); //reuse fix -#endif -// setsockopt(fd,IPPROTO_TCP,TCP_NODELAY,NULL,0); - setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, (char *) &yes, sizeof yes); // reuse fix + const int yes = 1; + /// Allow to bind() again after the server restarts. + // Since the socket is still in the TIME_WAIT, there's a possibility + // that formerly lost packets might be delivered and confuse the server. + setsockopt (fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof yes); + /// Send packets as soon as possible + /// even if the kernel thinks there is too little for it to be worth it! + // I'm not convinced this is a good idea; although in minimizes the + // latency for an individual write, it increases traffic in general. + setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &yes, sizeof yes); FD_SET (fd, &readfds); -#ifdef LCCWIN32 - { - unsigned long val = 1; - ioctlsocket (fd, FIONBIO, &val); - } -#else - result = fcntl (fd, F_SETFL, O_NONBLOCK); -#endif + fcntl (fd, F_SETFL, O_NONBLOCK); CREATE (session[fd], struct socket_data, 1); - CREATE (session[fd]->rdata, unsigned char, rfifo_size); - CREATE (session[fd]->wdata, unsigned char, wfifo_size); + CREATE (session[fd]->rdata, uint8_t, rfifo_size); + CREATE (session[fd]->wdata, uint8_t, wfifo_size); session[fd]->max_rdata = rfifo_size; session[fd]->max_wdata = wfifo_size; @@ -221,59 +139,44 @@ static int connect_client (int listen_fd) session[fd]->connected = 0; currentuse++; - - //printf("new_session : %d %d\n",fd,session[fd]->eof); - return fd; } -int make_listen_port (int port) +int make_listen_port (uint16_t port) { struct sockaddr_in server_address; - int fd; - int result; - int yes = 1; // reuse fix - - fd = socket (AF_INET, SOCK_STREAM, 0); - if (fd_max <= fd) - fd_max = fd + 1; - else if (fd == -1) + int fd = socket (AF_INET, SOCK_STREAM, 0); + if (fd == -1) { - perror ("connect"); + perror ("socket"); return -1; } + if (fd_max <= fd) + fd_max = fd + 1; -#ifdef LCCWIN32 - { - unsigned long val = 1; - ioctlsocket (fd, FIONBIO, &val); - } -#else - result = fcntl (fd, F_SETFL, O_NONBLOCK); -#endif - -// setsockopt(fd,SOL_SOCKET,SO_REUSEADDR,NULL,0); - setsockopt (fd, SOL_SOCKET, SO_REUSEADDR, (char *) &yes, sizeof yes); // reuse fix -#ifdef SO_REUSEPORT -// setsockopt(fd,SOL_SOCKET,SO_REUSEPORT,NULL,0); - setsockopt (fd, SOL_SOCKET, SO_REUSEPORT, (char *) &yes, sizeof yes); //reuse fix -#endif -// setsockopt(fd,IPPROTO_TCP,TCP_NODELAY,NULL,0); - setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, (char *) &yes, sizeof yes); // reuse fix + fcntl (fd, F_SETFL, O_NONBLOCK); + + const int yes = 1; + /// Allow to bind() again after the server restarts. + // Since the socket is still in the TIME_WAIT, there's a possibility + // that formerly lost packets might be delivered and confuse the server. + setsockopt (fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof yes); + /// Send packets as soon as possible + /// even if the kernel thinks there is too little for it to be worth it! + // I'm not convinced this is a good idea; although in minimizes the + // latency for an individual write, it increases traffic in general. + setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &yes, sizeof yes); server_address.sin_family = AF_INET; server_address.sin_addr.s_addr = htonl (INADDR_ANY); server_address.sin_port = htons (port); - result = - bind (fd, (struct sockaddr *) &server_address, - sizeof (server_address)); - if (result == -1) + if (bind (fd, (struct sockaddr *) &server_address, + sizeof (server_address)) == -1) { perror ("bind"); exit (1); } - result = listen (fd, 5); - if (result == -1) + if (listen (fd, 5) == -1) { /* error */ perror ("listen"); exit (1); @@ -283,12 +186,6 @@ int make_listen_port (int port) CREATE (session[fd], struct socket_data, 1); - if (session[fd] == NULL) - { - printf ("out of memory : make_listen_port\n"); - exit (1); - } - memset (session[fd], 0, sizeof (*session[fd])); session[fd]->func_recv = connect_client; session[fd]->created = time (NULL); session[fd]->connected = 1; @@ -297,53 +194,45 @@ int make_listen_port (int port) return fd; } -int make_connection (long ip, int port) +int make_connection (uint32_t ip, uint16_t port) { struct sockaddr_in server_address; - int fd; - int result; - int yes = 1; // reuse fix - - fd = socket (AF_INET, SOCK_STREAM, 0); - if (fd_max <= fd) - fd_max = fd + 1; - else if (fd == -1) + int fd = socket (AF_INET, SOCK_STREAM, 0); + if (fd == -1) { perror ("socket"); return -1; } + if (fd_max <= fd) + fd_max = fd + 1; -// setsockopt(fd,SOL_SOCKET,SO_REUSEADDR,NULL,0); - setsockopt (fd, SOL_SOCKET, SO_REUSEADDR, (char *) &yes, sizeof yes); // reuse fix -#ifdef SO_REUSEPORT -// setsockopt(fd,SOL_SOCKET,SO_REUSEPORT,NULL,0); - setsockopt (fd, SOL_SOCKET, SO_REUSEPORT, (char *) &yes, sizeof yes); //reuse fix -#endif -// setsockopt(fd,IPPROTO_TCP,TCP_NODELAY,NULL,0); - setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, (char *) &yes, sizeof yes); // reuse fix + const int yes = 1; + /// Allow to bind() again after the server restarts. + // Since the socket is still in the TIME_WAIT, there's a possibility + // that formerly lost packets might be delivered and confuse the server. + setsockopt (fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof yes); + /// Send packets as soon as possible + /// even if the kernel thinks there is too little for it to be worth it! + // I'm not convinced this is a good idea; although in minimizes the + // latency for an individual write, it increases traffic in general. + setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &yes, sizeof yes); server_address.sin_family = AF_INET; server_address.sin_addr.s_addr = ip; server_address.sin_port = htons (port); -#ifdef LCCWIN32 - { - unsigned long val = 1; - ioctlsocket (fd, FIONBIO, &val); - } -#else - result = fcntl (fd, F_SETFL, O_NONBLOCK); -#endif + fcntl (fd, F_SETFL, O_NONBLOCK); - result = - connect (fd, (struct sockaddr *) (&server_address), - sizeof (struct sockaddr_in)); + /// Errors not caught - we must not block + /// Let the main select() loop detect when we know the state + connect (fd, (struct sockaddr *) &server_address, + sizeof (struct sockaddr_in)); FD_SET (fd, &readfds); CREATE (session[fd], struct socket_data, 1); - CREATE (session[fd]->rdata, unsigned char, rfifo_size); - CREATE (session[fd]->wdata, unsigned char, wfifo_size); + CREATE (session[fd]->rdata, uint8_t, rfifo_size); + CREATE (session[fd]->wdata, uint8_t, wfifo_size); session[fd]->max_rdata = rfifo_size; session[fd]->max_wdata = wfifo_size; @@ -357,51 +246,53 @@ int make_connection (long ip, int port) return fd; } -int delete_session (int fd) +void delete_session (int fd) { if (fd < 0 || fd >= FD_SETSIZE) - return -1; + return; + // If this was the highest fd, decrease it + // We could add a loop to decrement fd_max further for every null session, + // but this is cheap and good enough for the typical case + if (fd == fd_max - 1) + fd_max--; FD_CLR (fd, &readfds); if (session[fd]) { - if (session[fd]->rdata) - free (session[fd]->rdata); - if (session[fd]->wdata) - free (session[fd]->wdata); - if (session[fd]->session_data) - free (session[fd]->session_data); + free (session[fd]->rdata); + free (session[fd]->wdata); + free (session[fd]->session_data); free (session[fd]); } session[fd] = NULL; + + // just close() would try to keep sending buffers shutdown (fd, SHUT_RDWR); close (fd); currentuse--; if (currentuse < 0) { - printf ("delete_session: current sessions negative!\n"); + fprintf (stderr, "delete_session: current sessions negative!\n"); currentuse = 0; } - //printf("delete_session:%d\n",fd); - return 0; + return; } -int realloc_fifo (int fd, int rfifo_size, int wfifo_size) +void realloc_fifo (int fd, size_t rfifo_size, size_t wfifo_size) { struct socket_data *s = session[fd]; if (s->max_rdata != rfifo_size && s->rdata_size < rfifo_size) { - RECREATE (s->rdata, unsigned char, rfifo_size); + RECREATE (s->rdata, uint8_t, rfifo_size); s->max_rdata = rfifo_size; } if (s->max_wdata != wfifo_size && s->wdata_size < wfifo_size) { - RECREATE (s->wdata, unsigned char, wfifo_size); + RECREATE (s->wdata, uint8_t, wfifo_size); s->max_wdata = wfifo_size; } - return 0; } -int WFIFOSET (int fd, int len) +void WFIFOSET (int fd, size_t len) { struct socket_data *s = session[fd]; if (s->wdata_size + len + 16384 > s->max_wdata) @@ -409,64 +300,49 @@ int WFIFOSET (int fd, int len) realloc_fifo (fd, s->max_rdata, s->max_wdata << 1); printf ("socket: %d wdata expanded to %d bytes.\n", fd, s->max_wdata); } - s->wdata_size = (s->wdata_size + (len) + 2048 < s->max_wdata) ? - s->wdata_size + len : (printf ("socket: %d wdata lost !!\n", fd), - s->wdata_size); - return 0; + if (s->wdata_size + len + 2048 < s->max_wdata) + s->wdata_size += len; + else + fprintf (stderr, "socket: %d wdata lost !!\n", fd), abort (); } -int do_sendrecv (int next) +void do_sendrecv (uint32_t next) { - fd_set rfd, wfd; - struct timeval timeout; - int ret, i; - - rfd = readfds; + fd_set rfd = readfds, wfd; FD_ZERO (&wfd); - for (i = 0; i < fd_max; i++) + for (int i = 0; i < fd_max; i++) { - if (!session[i] && FD_ISSET (i, &readfds)) - { - printf ("force clr fds %d\n", i); - FD_CLR (i, &readfds); - continue; - } - if (!session[i]) - continue; - if (session[i]->wdata_size) + if (session[i] && session[i]->wdata_size) FD_SET (i, &wfd); } + struct timeval timeout; timeout.tv_sec = next / 1000; timeout.tv_usec = next % 1000 * 1000; - ret = select (fd_max, &rfd, &wfd, NULL, &timeout); - if (ret <= 0) - return 0; - for (i = 0; i < fd_max; i++) + if (select (fd_max, &rfd, &wfd, NULL, &timeout) <= 0) + return; + for (int i = 0; i < fd_max; i++) { if (!session[i]) continue; if (FD_ISSET (i, &wfd)) { - //printf("write:%d\n",i); if (session[i]->func_send) //send_from_fifo(i); session[i]->func_send (i); } if (FD_ISSET (i, &rfd)) { - //printf("read:%d\n",i); if (session[i]->func_recv) //recv_to_fifo(i); + //or connect_client(i); session[i]->func_recv (i); } } - return 0; } -int do_parsepacket (void) +void do_parsepacket (void) { - int i; - for (i = 0; i < fd_max; i++) + for (int i = 0; i < fd_max; i++) { if (!session[i]) continue; @@ -476,76 +352,54 @@ int do_parsepacket (void) printf ("Session #%d timed out\n", i); session[i]->eof = 1; } - if (session[i]->rdata_size == 0 && session[i]->eof == 0) + if (!session[i]->rdata_size && !session[i]->eof) continue; if (session[i]->func_parse) { session[i]->func_parse (i); + /// some func_parse may call delete_session if (!session[i]) continue; } + /// Reclaim buffer space for what was read RFIFOFLUSH (i); } - return 0; } void do_socket (void) { FD_ZERO (&readfds); - currentuse = 2; + currentuse = 3; } -int RFIFOSKIP (int fd, int len) +void RFIFOSKIP (int fd, size_t len) { struct socket_data *s = session[fd]; + s->rdata_pos += len; - if (s->rdata_size - s->rdata_pos - len < 0) + if (s->rdata_size < s->rdata_pos) { fprintf (stderr, "too many skip\n"); - exit (1); + abort (); } - - s->rdata_pos = s->rdata_pos + len; - - return 0; } -int Net_Init (void) +void fclose_ (FILE * fp) { -#ifdef LCCWIN32 - /* Start up the windows networking */ - WORD version_wanted = MAKEWORD (1, 1); - WSADATA wsaData; - - if (WSAStartup (version_wanted, &wsaData) != 0) - { - printf ("SYSERR: WinSock not available!\n"); - exit (1); - } -#endif - - return (0); -} - -int fclose_ (FILE * fp) -{ - int res = fclose (fp); - if (res == 0) - currentuse--; -// printf("file closed: used: %d\n",currentuse); - return res; + if (fclose (fp)) + perror ("fclose"), abort (); + currentuse--; } FILE *fopen_ (const char *path, const char *mode) { FILE *f = fopen (path, mode); - if (f != NULL) + if (f) currentuse++; -// printf("file opened: used: %d\n",currentuse); return f; } -int free_fds () +bool free_fds () { - return (currentuse + 1 < SOFT_LIMIT) ? 1 : 0; + return currentuse < SOFT_LIMIT; } diff --git a/src/common/socket.h b/src/common/socket.h index aa4f91f..0e15f5b 100644 --- a/src/common/socket.h +++ b/src/common/socket.h @@ -1,110 +1,135 @@ -// original : core.h 2003/03/14 11:55:25 Rev 1.4 - -#ifndef _SOCKET_H_ -#define _SOCKET_H_ - -#include - -#ifdef LCCWIN32 -#include -#else -#include -#include -#include -#endif -#include - -// define declaration - -#define RFIFOP(fd,pos) (session[fd]->rdata+session[fd]->rdata_pos+(pos)) -#define RFIFOB(fd,pos) (*(unsigned char*)(session[fd]->rdata+session[fd]->rdata_pos+(pos))) -#define RFIFOW(fd,pos) (*(unsigned short*)(session[fd]->rdata+session[fd]->rdata_pos+(pos))) -#define RFIFOL(fd,pos) (*(unsigned int*)(session[fd]->rdata+session[fd]->rdata_pos+(pos))) -//#define RFIFOSKIP(fd,len) ((session[fd]->rdata_size-session[fd]->rdata_pos-(len)<0) ? (fprintf(stderr,"too many skip\n"),exit(1)) : (session[fd]->rdata_pos+=(len))) -#define RFIFOREST(fd) (session[fd]->rdata_size-session[fd]->rdata_pos) -#define RFIFOFLUSH(fd) (memmove(session[fd]->rdata,RFIFOP(fd,0),RFIFOREST(fd)),session[fd]->rdata_size=RFIFOREST(fd),session[fd]->rdata_pos=0) -#define RFIFOSPACE(fd) (session[fd]->max_rdata-session[fd]->rdata_size) -#define RBUFP(p,pos) (((unsigned char*)(p))+(pos)) -#define RBUFB(p,pos) (*(unsigned char*)RBUFP((p),(pos))) -#define RBUFW(p,pos) (*(unsigned short*)RBUFP((p),(pos))) -#define RBUFL(p,pos) (*(unsigned int*)RBUFP((p),(pos))) - -#define WFIFOSPACE(fd) (session[fd]->max_wdata-session[fd]->wdata_size) -#define WFIFOP(fd,pos) (session[fd]->wdata+session[fd]->wdata_size+(pos)) -#define WFIFOB(fd,pos) (*(unsigned char*)(session[fd]->wdata+session[fd]->wdata_size+(pos))) -#define WFIFOW(fd,pos) (*(unsigned short*)(session[fd]->wdata+session[fd]->wdata_size+(pos))) -#define WFIFOL(fd,pos) (*(unsigned int*)(session[fd]->wdata+session[fd]->wdata_size+(pos))) -// use function instead of macro. -//#define WFIFOSET(fd,len) (session[fd]->wdata_size = (session[fd]->wdata_size+(len)+2048 < session[fd]->max_wdata) ? session[fd]->wdata_size+len : session[fd]->wdata_size) -#define WBUFP(p,pos) (((unsigned char*)(p))+(pos)) -#define WBUFB(p,pos) (*(unsigned char*)WBUFP((p),(pos))) -#define WBUFW(p,pos) (*(unsigned short*)WBUFP((p),(pos))) -#define WBUFL(p,pos) (*(unsigned int*)WBUFP((p),(pos))) - -#ifdef __INTERIX -#define FD_SETSIZE 4096 -#endif // __INTERIX - -/* Removed Cygwin FD_SETSIZE declarations, now are directly passed on to the compiler through Makefile [Valaris] */ +#ifndef SOCKET_H +#define SOCKET_H + +# include "sanity.h" + +# include + +# include +# include +# include + +# include + +/// Check how much can be read +# define RFIFOREST(fd) (session[fd]->rdata_size-session[fd]->rdata_pos) +/// Read from the queue +# define RFIFOP(fd,pos) (session[fd]->rdata+session[fd]->rdata_pos+(pos)) +# define RFIFOB(fd,pos) (*(uint8_t*)(RFIFOP(fd, pos))) +# define RFIFOW(fd,pos) (*(uint16_t*)(RFIFOP(fd, pos))) +# define RFIFOL(fd,pos) (*(uint32_t*)(RFIFOP(fd, pos))) +/// Done reading +void RFIFOSKIP (int fd, size_t len); +/// Internal - clean up by discarding handled bytes +// Atm this is also called in char/char.c, but that is unnecessary +# define RFIFOFLUSH(fd) (memmove(session[fd]->rdata,RFIFOP(fd,0),RFIFOREST(fd)),\ +session[fd]->rdata_size=RFIFOREST(fd),\ +session[fd]->rdata_pos=0) + +/// Used internally - how much room there is to read more data +# define RFIFOSPACE(fd) (session[fd]->max_rdata-session[fd]->rdata_size) + +/// Read from an arbitrary buffer +# define RBUFP(p,pos) (((uint8_t*)(p))+(pos)) +# define RBUFB(p,pos) (*(uint8_t*)RBUFP((p),(pos))) +# define RBUFW(p,pos) (*(uint16_t*)RBUFP((p),(pos))) +# define RBUFL(p,pos) (*(uint32_t*)RBUFP((p),(pos))) + + + +/// Unused - check how much data can be written +# define WFIFOSPACE(fd) (session[fd]->max_wdata-session[fd]->wdata_size) +/// Write to the queue +# define WFIFOP(fd,pos) (session[fd]->wdata+session[fd]->wdata_size+(pos)) +# define WFIFOB(fd,pos) (*(uint8_t*)(WFIFOP(fd,pos))) +# define WFIFOW(fd,pos) (*(uint16_t*)(WFIFOP(fd,pos))) +# define WFIFOL(fd,pos) (*(uint32_t*)(WFIFOP(fd,pos))) +/// Finish writing +void WFIFOSET (int fd, size_t len); + +/// Write to an arbitrary buffer +#define WBUFP(p,pos) (((uint8_t*)(p))+(pos)) +#define WBUFB(p,pos) (*(uint8_t*)WBUFP((p),(pos))) +#define WBUFW(p,pos) (*(uint16_t*)WBUFP((p),(pos))) +#define WBUFL(p,pos) (*(uint32_t*)WBUFP((p),(pos))) // Struct declaration struct socket_data { - int eof; + /// Checks whether a newly-connected socket actually does anything time_t created; - int connected; - unsigned char *rdata, *wdata; - int max_rdata, max_wdata; - int rdata_size, wdata_size; - int rdata_pos; - struct sockaddr_in client_addr; - int (*func_recv) (int); - int (*func_send) (int); - int (*func_parse) (int); - void *session_data; -}; + bool connected; -// Data prototype declaration + /// Flag needed since structure must be freed in a server-dependent manner + bool eof; -#ifdef LCCWIN32 + /// Since this is a single-threaded application, it can't block + /// These are the read/write queues + uint8_t *rdata, *wdata; + size_t max_rdata, max_wdata; + /// How much is actually in the queue + size_t rdata_size, wdata_size; + /// How much has already been read from the queue + /// Note that there is no need for a wdata_pos + size_t rdata_pos; -#undef FD_SETSIZE -#define FD_SETSIZE 4096 + struct sockaddr_in client_addr; -#endif + /// Send or recieve + /// Only called when select() indicates the socket is ready + /// If, after that, nothing is read, it sets eof + // These could probably be hard-coded with a little work + void (*func_recv) (int); + void (*func_send) (int); + /// This is the important one + /// Set to different functions depending on whether the connection + /// is a player or a server/ladmin + /// Can be set explicitly or via set_defaultparse + void (*func_parse) (int); + /// Server-specific data type + void *session_data; +}; // save file descriptors for important stuff -#define SOFT_LIMIT (FD_SETSIZE - 50) +# define SOFT_LIMIT (FD_SETSIZE - 50) // socket timeout to establish a full connection in seconds -#define CONNECT_TIMEOUT 15 +# define CONNECT_TIMEOUT 15 +/// Everyone who has connected +// note: call delete_session(i) to null out an element extern struct socket_data *session[FD_SETSIZE]; -extern int rfifo_size, wfifo_size; +/// Maximum used FD, +1 extern int fd_max; -// Function prototype declaration - -int make_listen_port (int); -int make_connection (long, int); -int delete_session (int); -int realloc_fifo (int fd, int rfifo_size, int wfifo_size); -int WFIFOSET (int fd, int len); -int RFIFOSKIP (int fd, int len); - -int do_sendrecv (int next); -int do_parsepacket (void); +/// open a socket, bind, and listen. Return an fd, or -1 if socket() fails, +/// but exit if bind() or listen() fails +int make_listen_port (uint16_t port); +/// Connect to an address, return a connected socket or -1 +// FIXME - this is IPv4 only! +int make_connection (uint32_t ip, uint16_t port); +/// free() the structure and close() the fd +void delete_session (int); +/// Make a the internal queues bigger +void realloc_fifo (int fd, size_t rfifo_size, size_t wfifo_size); +/// Update all sockets that can be read/written from the queues +void do_sendrecv (uint32_t next); +/// Call the parser function for every socket that has read data +void do_parsepacket (void); + +/// An init function void do_socket (void); -void set_defaultparse (int (*defaultparse) (int)); +/// Change the default parser for newly connected clients +// typically called once per server, but individual clients may identify +// themselves as servers +void set_defaultparse (void (*defaultparse) (int)); -int Net_Init (void); - -int fclose_ (FILE * fp); +/// Wrappers to track number of free FDs +void fclose_ (FILE * fp); FILE *fopen_ (const char *path, const char *mode); +bool free_fds (); -int free_fds (); - -#endif // _SOCKET_H_ +#endif // SOCKET_H diff --git a/src/common/timer.c b/src/common/timer.c index fca6f42..bf21c8e 100644 --- a/src/common/timer.c +++ b/src/common/timer.c @@ -1,184 +1,127 @@ -// $Id: timer.c,v 1.1.1.1 2004/09/10 17:44:49 MagicalTux Exp $ -// original : core.c 2003/02/26 18:03:12 Rev 1.7 - #include #include #include #include -#ifdef LCCWIN32 -#include -#else #include #include -#endif #include "timer.h" #include "utils.h" -#ifdef MEMWATCH -#include "memwatch.h" -#endif - static struct TimerData *timer_data; -static int timer_data_max, timer_data_num; -static int *free_timer_list; -static int free_timer_list_max, free_timer_list_pos; - -static int timer_heap_max; -static int *timer_heap = NULL; - -// for debug -struct timer_func_list -{ - int (*func) (int, unsigned int, int, int); - struct timer_func_list *next; - char *name; -}; -static struct timer_func_list *tfl_root; - -#if defined(LCCWIN32) -void gettimeofday (struct timeval *t, struct timezone *dummy) -{ - DWORD millisec = GetTickCount (); - - t->tv_sec = (int) (millisec / 1000); - t->tv_usec = (millisec % 1000) * 1000; -} - -#endif - -// -int add_timer_func_list (int (*func) (int, unsigned int, int, int), - char *name) -{ - struct timer_func_list *tfl; - - CREATE (tfl, struct timer_func_list, 1); - CREATE (tfl->name, char, strlen (name) + 1); - - tfl->next = tfl_root; - tfl->func = func; - strcpy (tfl->name, name); - tfl_root = tfl; - - return 0; -} - -char *search_timer_func_list (int (*func) (int, unsigned int, int, int)) -{ - struct timer_func_list *tfl; - for (tfl = tfl_root; tfl; tfl = tfl->next) - { - if (func == tfl->func) - return tfl->name; - } - return "???"; -} - -/*---------------------------- - * Get tick time - *----------------------------*/ -static unsigned int gettick_cache; -static int gettick_count; -unsigned int gettick_nocache (void) +static uint32_t timer_data_max, timer_data_num; +static timer_id *free_timer_list; +static uint32_t free_timer_list_max, free_timer_list_pos; + +/// Okay, I think I understand this structure now: +/// the timer heap is a magic queue that allows inserting timers and then popping them in order +/// designed to copy only log2(N) entries instead of N +// timer_heap[0] is the size (greatest index into the heap) +// timer_heap[1] is the first actual element +// timer_heap_max increases 256 at a time and never decreases +static uint32_t timer_heap_max = 256; +/// FIXME: refactor the code to put the size in a separate variable +//nontrivial because indices get multiplied +static timer_id *timer_heap = NULL; + + +static uint32_t gettick_cache; +static uint8_t gettick_count = 0; + +uint32_t gettick_nocache (void) { struct timeval tval; + // BUG: This will cause strange behavior if the system clock is changed! + // it should be reimplemented in terms of clock_gettime(CLOCK_MONOTONIC, ) gettimeofday (&tval, NULL); - gettick_count = 256; + gettick_count = 255; return gettick_cache = tval.tv_sec * 1000 + tval.tv_usec / 1000; } -unsigned int gettick (void) +uint32_t gettick (void) { - gettick_count--; - if (gettick_count < 0) - return gettick_nocache (); - return gettick_cache; + if (gettick_count--) + return gettick_cache; + return gettick_nocache (); } -/*====================================== - * CORE : Timer Heap - *-------------------------------------- - */ -static void push_timer_heap (int index) +static void push_timer_heap (timer_id index) { - int i, h; - - if (timer_heap == NULL || timer_heap[0] + 1 >= timer_heap_max) + if (timer_heap == NULL) { - int first = timer_heap == NULL; - timer_heap_max += 256; - RECREATE (timer_heap, int, timer_heap_max); - memset (timer_heap + (timer_heap_max - 256), 0, sizeof (int) * 256); - if (first) - timer_heap[0] = 0; + CREATE (timer_heap, timer_id, timer_heap_max); } - +// timer_heap[0] is the greatest index into the heap, which increases timer_heap[0]++; + if (timer_heap[0] >= timer_heap_max) + { + timer_heap_max += 256; + RECREATE (timer_heap, timer_id, timer_heap_max); + memset (timer_heap + (timer_heap_max - 256), 0, 4 * 256); + } - for (h = timer_heap[0] - 1, i = (h - 1) / 2; - h > 0 && DIFF_TICK (timer_data[index].tick, - timer_data[timer_heap[i + 1]].tick) < 0; - i = (h - 1) / 2) + timer_id h = timer_heap[0]-1, i = (h - 1) / 2; + while (h) { + // avoid wraparound problems, it really means this: + // timer_data[index].tick >= timer_data[timer_heap[i+1]].tick + if ( DIFF_TICK(timer_data[index].tick, timer_data[timer_heap[i+1]].tick) >= 0) + break; timer_heap[h + 1] = timer_heap[i + 1]; h = i; + i = (h - 1) / 2; } timer_heap[h + 1] = index; } -static int top_timer_heap () +static timer_id top_timer_heap () { - if (timer_heap == NULL || timer_heap[0] <= 0) + if (!timer_heap || !timer_heap[0]) return -1; - return timer_heap[1]; } -static int pop_timer_heap () +static timer_id pop_timer_heap () { - int i, h, k; - int ret, last; - - if (timer_heap == NULL || timer_heap[0] <= 0) + if (!timer_heap || !timer_heap[0]) return -1; - ret = timer_heap[1]; - last = timer_heap[timer_heap[0]]; + timer_id ret = timer_heap[1]; + timer_id last = timer_heap[timer_heap[0]]; timer_heap[0]--; + uint32_t h, k; for (h = 0, k = 2; k < timer_heap[0]; k = k * 2 + 2) { - if (DIFF_TICK - (timer_data[timer_heap[k + 1]].tick, - timer_data[timer_heap[k]].tick) > 0) + if (DIFF_TICK(timer_data[timer_heap[k + 1]].tick, timer_data[timer_heap[k]].tick) > 0) k--; timer_heap[h + 1] = timer_heap[k + 1], h = k; } if (k == timer_heap[0]) timer_heap[h + 1] = timer_heap[k], h = k - 1; - for (i = (h - 1) / 2; - h > 0 - && DIFF_TICK (timer_data[timer_heap[i + 1]].tick, - timer_data[last].tick) > 0; i = (h - 1) / 2) + uint32_t i = (h - 1) / 2; + while (h) { - timer_heap[h + 1] = timer_heap[i + 1], h = i; + if (DIFF_TICK(timer_data[timer_heap[i + 1]].tick, timer_data[last].tick) <= 0) + timer_heap[h + 1] = timer_heap[i + 1]; + h = i; + i = (h - 1) / 2; } timer_heap[h + 1] = last; return ret; } -int add_timer (unsigned int tick, int (*func) (int, unsigned int, int, int), - int id, int data) +timer_id add_timer (tick_t tick, timer_func func, custom_id_t id, custom_data_t data) { - struct TimerData *td; - int i; + timer_id i; if (free_timer_list_pos) { + // Retrieve a freed timer id instead of a new one + // I think it should be possible to avoid the loop somehow do { i = free_timer_list[--free_timer_list_pos]; @@ -187,12 +130,13 @@ int add_timer (unsigned int tick, int (*func) (int, unsigned int, int, int), } else i = timer_data_num; + + // I have no idea what this is doing if (i >= timer_data_num) - for (i = timer_data_num; i < timer_data_max && timer_data[i].type; - i++); + for (i = timer_data_num; i < timer_data_max && timer_data[i].type; i++) + ; if (i >= timer_data_num && i >= timer_data_max) { - int j; if (timer_data_max == 0) { timer_data_max = 256; @@ -202,143 +146,112 @@ int add_timer (unsigned int tick, int (*func) (int, unsigned int, int, int), { timer_data_max += 256; RECREATE (timer_data, struct TimerData, timer_data_max); - if (timer_data == NULL) - { - printf ("out of memory : add_timer timer_data\n"); - exit (1); - } memset (timer_data + (timer_data_max - 256), 0, sizeof (struct TimerData) * 256); } - for (j = timer_data_max - 256; j < timer_data_max; j++) - timer_data[j].type = 0; } - td = &timer_data[i]; - td->tick = tick; - td->func = func; - td->id = id; - td->data = data; - td->type = TIMER_ONCE_AUTODEL; - td->interval = 1000; + timer_data[i].tick = tick; + timer_data[i].func = func; + timer_data[i].id = id; + timer_data[i].data = data; + timer_data[i].type = TIMER_ONCE_AUTODEL; + timer_data[i].interval = 1000; push_timer_heap (i); if (i >= timer_data_num) timer_data_num = i + 1; return i; } -int add_timer_interval (unsigned int tick, - int (*func) (int, unsigned int, int, int), int id, - int data, int interval) +timer_id add_timer_interval (tick_t tick, timer_func func, custom_id_t id, + custom_data_t data, interdb_val_t interval) { - int tid; - tid = add_timer (tick, func, id, data); + timer_id tid = add_timer (tick, func, id, data); timer_data[tid].type = TIMER_INTERVAL; timer_data[tid].interval = interval; return tid; } -int delete_timer (int id, int (*func) (int, unsigned int, int, int)) +void delete_timer (timer_id id, timer_func func) { - if (id <= 0 || id >= timer_data_num) + if (id == 0 || id >= timer_data_num) { - printf ("delete_timer error : no such timer %d\n", id); - return -1; + fprintf (stderr, "delete_timer error : no such timer %d\n", id); + abort (); } if (timer_data[id].func != func) { - printf - ("delete_timer error : function dismatch %08x(%s) != %08x(%s)\n", - (int) timer_data[id].func, - search_timer_func_list (timer_data[id].func), (int) func, - search_timer_func_list (func)); - return -2; + fprintf (stderr, "Timer mismatch\n"); + abort (); } - // そのうち消えるにまかせる + // "to let them disappear" - is this just in case? timer_data[id].func = NULL; timer_data[id].type = TIMER_ONCE_AUTODEL; timer_data[id].tick -= 60 * 60 * 1000; - return 0; } -int addtick_timer (int tid, unsigned int tick) +tick_t addtick_timer (timer_id tid, interdb_val_t tick) { return timer_data[tid].tick += tick; } -struct TimerData *get_timer (int tid) +struct TimerData *get_timer (timer_id tid) { return &timer_data[tid]; } -int do_timer (unsigned int tick) +interdb_val_t do_timer (tick_t tick) { - int i, nextmin = 1000; - -#if 0 - static int disp_tick = 0; - if (DIFF_TICK (disp_tick, tick) < -5000 - || DIFF_TICK (disp_tick, tick) > 5000) - { - printf ("timer %d(%d + %d)\n", timer_data_num, timer_heap[0], - free_timer_list_pos); - disp_tick = tick; - } -#endif + timer_id i; + /// Number of milliseconds until it calls this again + // this says to wait 1 sec if all timers get popped + interdb_val_t nextmin = 1000; - while ((i = top_timer_heap ()) >= 0) + while ((i = top_timer_heap ()) != (timer_id)-1) { + // while the heap is not empty and if (DIFF_TICK (timer_data[i].tick, tick) > 0) { + /// Return the time until the next timer needs to goes off nextmin = DIFF_TICK (timer_data[i].tick, tick); break; } pop_timer_heap (); - timer_data[i].type |= TIMER_REMOVE_HEAP; if (timer_data[i].func) { if (DIFF_TICK (timer_data[i].tick, tick) < -1000) { - // 1秒以上の大幅な遅延が発生しているので、 - // timer処理タイミングを現在値とする事で - // 呼び出し時タイミング(引数のtick)相対で処理してる - // timer関数の次回処理タイミングを遅らせる - timer_data[i].func (i, tick, timer_data[i].id, - timer_data[i].data); + // If we are too far past the requested tick, call with the current tick instead to fix reregistering problems + timer_data[i].func (i, tick, timer_data[i].id, timer_data[i].data); } else { - timer_data[i].func (i, timer_data[i].tick, timer_data[i].id, - timer_data[i].data); + timer_data[i].func (i, timer_data[i].tick, timer_data[i].id, timer_data[i].data); } } - if (timer_data[i].type & TIMER_REMOVE_HEAP) + switch (timer_data[i].type) { - switch (timer_data[i].type & ~TIMER_REMOVE_HEAP) - { - case TIMER_ONCE_AUTODEL: - timer_data[i].type = 0; - if (free_timer_list_pos >= free_timer_list_max) - { - free_timer_list_max += 256; - RECREATE (free_timer_list, int, free_timer_list_max); - memset (free_timer_list + (free_timer_list_max - 256), - 0, 256 * sizeof (free_timer_list[0])); - } - free_timer_list[free_timer_list_pos++] = i; - break; - case TIMER_INTERVAL: - if (DIFF_TICK (timer_data[i].tick, tick) < -1000) - { - timer_data[i].tick = tick + timer_data[i].interval; - } - else - { - timer_data[i].tick += timer_data[i].interval; - } - timer_data[i].type &= ~TIMER_REMOVE_HEAP; - push_timer_heap (i); - break; - } + case TIMER_ONCE_AUTODEL: + timer_data[i].type = 0; + if (free_timer_list_pos >= free_timer_list_max) + { + free_timer_list_max += 256; + RECREATE (free_timer_list, uint32_t, free_timer_list_max); + memset (free_timer_list + (free_timer_list_max - 256), + 0, 256 * sizeof (timer_id)); + } + free_timer_list[free_timer_list_pos++] = i; + break; + case TIMER_INTERVAL: + if (DIFF_TICK (timer_data[i].tick, tick) < -1000) + { + timer_data[i].tick = tick + timer_data[i].interval; + } + else + { + timer_data[i].tick += timer_data[i].interval; + } + push_timer_heap (i); + break; } } @@ -346,8 +259,3 @@ int do_timer (unsigned int tick) nextmin = 10; return nextmin; } - -void timer_final () -{ - free (timer_data); -} diff --git a/src/common/timer.h b/src/common/timer.h index c6c4b52..4fa5db8 100644 --- a/src/common/timer.h +++ b/src/common/timer.h @@ -1,47 +1,67 @@ -// original : core.h 2003/03/14 11:55:25 Rev 1.4 +#ifndef TIMER_H +#define TIMER_H -#ifndef _TIMER_H_ -#define _TIMER_H_ +# include "sanity.h" -#define BASE_TICK 5 - -#define TIMER_ONCE_AUTODEL 1 -#define TIMER_INTERVAL 2 -#define TIMER_REMOVE_HEAP 16 - -#define DIFF_TICK(a,b) ((int)((a)-(b))) +enum TIMER_TYPE { + TIMER_ONCE_AUTODEL = 1, + TIMER_INTERVAL = 2, +}; +/// This is needed to produce a signed result when 2 ticks are subtracted +# define DIFF_TICK(a,b) ((int32_t)((a)-(b))) -// Struct declaration +// TODO replace with signed 64-bit to make code more clear and protect from the future +typedef uint32_t tick_t; +typedef uint32_t interdb_val_t; +typedef uint32_t timer_id; +// BUG: pointers are stored in here +typedef int32_t custom_id_t; +typedef int32_t custom_data_t; +typedef void (*timer_func) (timer_id, tick_t, custom_id_t, custom_data_t); struct TimerData { - unsigned int tick; - int (*func) (int, unsigned int, int, int); - int id; - int data; - int type; - int interval; - int heap_pos; + /// When it will be triggered + tick_t tick; + /// What will be done + timer_func func; + /// Arbitrary data. WARNING, callers are stupid and put pointers in here + // Should we change to void* or intptr_t ? + custom_id_t id; + custom_data_t data; + /// Type of timer - 0 initially + enum TIMER_TYPE type; + /// Repeat rate + uint32_t interval; }; -// Function prototype declaration - -unsigned int gettick_nocache (void); -unsigned int gettick (void); +/// Server time, in milliseconds, since the epoch, +/// but use of 32-bit integers means it wraps every 49 days. +// The only external caller of this function is the core.c main loop, but that makes sense +// in fact, it might make more sense if gettick() ALWAYS returned that cached value +tick_t gettick_nocache (void); +/// This function is called enough that it's worth caching the result for +/// the next 255 times +tick_t gettick (void); -int add_timer (unsigned int, int (*)(int, unsigned int, int, int), int, int); -int add_timer_interval (unsigned int, int (*)(int, unsigned int, int, int), - int, int, int); -int delete_timer (int, int (*)(int, unsigned int, int, int)); +timer_id add_timer (tick_t tick, timer_func func, custom_id_t id, + custom_data_t data); +timer_id add_timer_interval (tick_t tick, timer_func func, custom_id_t id, + custom_data_t data, interdb_val_t interval); +void delete_timer (timer_id, timer_func); -int addtick_timer (int tid, unsigned int tick); -struct TimerData *get_timer (int tid); +tick_t addtick_timer (timer_id tid, interdb_val_t tick); +struct TimerData *get_timer (timer_id tid); -int do_timer (unsigned int tick); +/// Do all timers scheduled before tick, and return the number of milliseconds until the next timer happens +interdb_val_t do_timer (tick_t tick); -int add_timer_func_list (int (*)(int, unsigned int, int, int), char *); -char *search_timer_func_list (int (*)(int, unsigned int, int, int)); +// debugging +static void add_timer_func_list (timer_func, char *) __attribute__((deprecated)); +static inline void add_timer_func_list (timer_func UNUSED, char *UNUSED) {} -extern void timer_final (); +// used to just call free(), which doesn't matter when we're exiting +static void timer_final () __attribute__((deprecated)); +static inline void timer_final() {}; -#endif // _TIMER_H_ +#endif // TIMER_H diff --git a/src/common/utils.c b/src/common/utils.c deleted file mode 100644 index 1433a5e..0000000 --- a/src/common/utils.c +++ /dev/null @@ -1,121 +0,0 @@ -#include -#include "utils.h" -#include - -void dump (unsigned char *buffer, int num) -{ - int icnt, jcnt; - - printf - (" Hex ASCII\n"); - printf - (" ----------------------------------------------- ----------------"); - - for (icnt = 0; icnt < num; icnt += 16) - { - printf ("\n%p ", &buffer[icnt]); - for (jcnt = icnt; jcnt < icnt + 16; ++jcnt) - { - if (jcnt < num) - { - printf ("%02hX ", buffer[jcnt]); - } - else - printf (" "); - } - - printf (" | "); - - for (jcnt = icnt; jcnt < icnt + 16; ++jcnt) - { - if (jcnt < num) - { - if (buffer[jcnt] > 31 && buffer[jcnt] < 127) - printf ("%c", buffer[jcnt]); - else - printf ("."); - } - else - printf (" "); - } - } - printf ("\n"); -} - -#ifdef LCCWIN32 -char *rindex (char *str, char c) -{ - char *sptr; - - sptr = str; - while (*sptr) - ++sptr; - if (c == '\0') - return (sptr); - while (str != sptr) - if (*sptr-- == c) - return (++sptr); - return (NULL); -} - -int strcasecmp (const char *arg1, const char *arg2) -{ - int chk, i; - - if (arg1 == NULL || arg2 == NULL) - { - printf ("SYSERR: str_cmp() passed a NULL pointer, %p or %p.\n", arg1, - arg2); - return (0); - } - - for (i = 0; arg1[i] || arg2[i]; i++) - if ((chk = LOWER (arg1[i]) - LOWER (arg2[i])) != 0) - return (chk); /* not equal */ - - return (0); -} - -int strncasecmp (const char *arg1, const char *arg2, int n) -{ - int chk, i; - - if (arg1 == NULL || arg2 == NULL) - { - printf ("SYSERR: strn_cmp() passed a NULL pointer, %p or %p.\n", arg1, - arg2); - return (0); - } - - for (i = 0; (arg1[i] || arg2[i]) && (n > 0); i++, n--) - if ((chk = LOWER (arg1[i]) - LOWER (arg2[i])) != 0) - return (chk); /* not equal */ - - return (0); -} - -void str_upper (char *name) -{ - - int len = strlen (name); - while (len--) - { - if (*name >= 'a' && *name <= 'z') - *name -= ('a' - 'A'); - name++; - } -} - -void str_lower (char *name) -{ - int len = strlen (name); - - while (len--) - { - if (*name >= 'A' && *name <= 'Z') - *name += ('a' - 'A'); - name++; - } -} - -#endif diff --git a/src/common/utils.h b/src/common/utils.h index 10c10ad..961d960 100644 --- a/src/common/utils.h +++ b/src/common/utils.h @@ -1,39 +1,18 @@ -#include "mt_rand.h" - -#ifndef NULL -#define NULL (void *)0 -#endif - -#define LOWER(c) (((c)>='A' && (c) <= 'Z') ? ((c)+('a'-'A')) : (c)) -#define UPPER(c) (((c)>='a' && (c) <= 'z') ? ((c)+('A'-'a')) : (c) ) - -/* strcasecmp -> stricmp -> str_cmp */ - -#ifdef LCCWIN32 -int strcasecmp (const char *arg1, const char *arg2); -int strncasecmp (const char *arg1, const char *arg2, int n); -void str_upper (char *name); -void str_lower (char *name); -char *rindex (char *str, char c); -#endif - -void dump (unsigned char *buffer, int num); - -#define CREATE(result, type, number) do {\ - if ((number) * sizeof(type) <= 0) \ - printf("SYSERR: Zero bytes or less requested at %s:%d.\n", __FILE__, __LINE__); \ +#ifndef UTILS_H +#define UTILS_H +/* +Notes about memory allocation in tmwAthena: +There used to be 3 sources of allocation: these macros, +a{C,M,Re}alloc in common/malloc.{h,c}, and direct calls. +I deleted malloc.{h,c} because it was redundant; +future calls should either use this or depend on the coming segfault. +*/ +# define CREATE(result, type, number) \ if (!((result) = (type *) calloc ((number), sizeof(type)))) \ - { perror("SYSERR: malloc failure"); abort(); } } while(0) + { perror("SYSERR: malloc failure"); abort(); } else (void)0 -#define RECREATE(result,type,number) do {\ +# define RECREATE(result,type,number) \ if (!((result) = (type *) realloc ((result), sizeof(type) * (number))))\ - { printf("SYSERR: realloc failure"); abort(); } } while(0) + { perror("SYSERR: realloc failure"); abort(); } else (void)0 -/* - * ModuloRand and ModuloPlusRand. These macros are used to replace the - * vast number of calls to rand()%mod .. - * MRAND(10), returns 0-9. - * MPRAND(5,10) returns 5-14. - */ -#define MRAND(mod) (int) (mt_random() % (mod)) -#define MPRAND(add, mod) add + MRAND(mod) +#endif //UTILS_H diff --git a/src/common/version.h b/src/common/version.h index cd9808e..46165aa 100644 --- a/src/common/version.h +++ b/src/common/version.h @@ -1,27 +1,24 @@ -// $Id: version.h,v 1.2 2004/09/22 09:49:06 PoW Exp $ -#ifndef _VERSION_H_ -#define _VERSION_H_ +/// Some constants to identify the version of (e)Athena +/// The values are different if the client connects (-1,'T','M','W',flags32) +// These numbers have never been changed while TMW +#ifndef VERSION_H +#define VERSION_H +//When a server receives a 0x7530 packet from an admin connection, +//it sends an 0x7531 packet with the following bytes +# define ATHENA_MAJOR_VERSION 1 // Major Version +# define ATHENA_MINOR_VERSION 0 // Minor Version +# define ATHENA_REVISION 0 // Revision -#define ATHENA_MAJOR_VERSION 1 // Major Version -#define ATHENA_MINOR_VERSION 0 // Minor Version -#define ATHENA_REVISION 0 // Revision +# define ATHENA_RELEASE_FLAG 1 // 1=Develop,0=Stable +# define ATHENA_OFFICIAL_FLAG 1 // 1=Mod,0=Official -#define ATHENA_RELEASE_FLAG 1 // 1=Develop,0=Stable -#define ATHENA_OFFICIAL_FLAG 1 // 1=Mod,0=Official +// and a bitmask of these (the char server sends char and inter) +# define ATHENA_SERVER_LOGIN 1 // login server +# define ATHENA_SERVER_CHAR 2 // char server +# define ATHENA_SERVER_INTER 4 // inter server +# define ATHENA_SERVER_MAP 8 // map server -#define ATHENA_SERVER_LOGIN 1 // login server -#define ATHENA_SERVER_CHAR 2 // char server -#define ATHENA_SERVER_INTER 4 // inter server -#define ATHENA_SERVER_MAP 8 // map server +// and this as two bytes +# define ATHENA_MOD_VERSION 1052 // mod version (patch No.) -// ATHENA_MOD_VERSIONはパッチ番号です。 -// これは無理に変えなくても気が向いたら変える程度の扱いで。 -// (毎回アップロードの度に変更するのも面倒と思われるし、そもそも -//  この項目を参照する人がいるかどうかで疑問だから。) -// その程度の扱いなので、サーバーに問い合わせる側も、あくまで目安程度の扱いで -// あんまり信用しないこと。 -// 鯖snapshotの時や、大きな変更があった場合は設定してほしいです。 -// C言語の仕様上、最初に0を付けると8進数になるので間違えないで下さい。 -#define ATHENA_MOD_VERSION 1052 // mod version (patch No.) - -#endif +#endif // VERSION_H diff --git a/src/ladmin/Makefile b/src/ladmin/Makefile index e873e69..4b4d2ec 100644 --- a/src/ladmin/Makefile +++ b/src/ladmin/Makefile @@ -2,8 +2,8 @@ include ../../make.defs all: ladmin -COMMON_OBJ = ../common/core.o ../common/socket.o ../common/timer.o ../common/db.o ../common/malloc.o ../common/mt_rand.o -COMMON_H = ../common/core.h ../common/socket.h ../common/timer.h ../common/mmo.h ../common/version.h ../common/db.h ../common/malloc.h ../common/mt_rand.h +COMMON_OBJ = ../common/core.o ../common/socket.o ../common/timer.o ../common/db.o ../common/mt_rand.o +COMMON_H = ../common/core.h ../common/socket.h ../common/timer.h ../common/mmo.h ../common/version.h ../common/db.h ../common/mt_rand.h ladmin: ladmin.o ../common/md5calc.o $(COMMON_OBJ) ladmin.o: ladmin.c ladmin.h ../common/md5calc.h $(COMMON_H) diff --git a/src/ladmin/ladmin.c b/src/ladmin/ladmin.c index 6848152..49f52ca 100644 --- a/src/ladmin/ladmin.c +++ b/src/ladmin/ladmin.c @@ -36,7 +36,7 @@ #include "memwatch.h" #endif -extern int eathena_interactive_session; // from core.c +int eathena_interactive_session; // from core.c #define Iprintf if (eathena_interactive_session) printf //-------------------------------INSTRUCTIONS------------------------------ @@ -4737,7 +4737,7 @@ int prompt () //------------------------------------------------------------- // Function: Parse receiving informations from the login-server //------------------------------------------------------------- -int parse_fromlogin (int fd) +void parse_fromlogin (int fd) { struct char_session_data *sd; @@ -4775,7 +4775,7 @@ int parse_fromlogin (int fd) { case 0x7919: // answer of a connection request if (RFIFOREST (fd) < 3) - return 0; + return; if (RFIFOB (fd, 2) != 0) { if (defaultlanguage == 'F') @@ -4834,7 +4834,7 @@ int parse_fromlogin (int fd) #ifdef PASSWORDENC case 0x01dc: // answer of a coding key request if (RFIFOREST (fd) < 4 || RFIFOREST (fd) < RFIFOW (fd, 2)) - return 0; + return; { char md5str[64] = "", md5bin[32], md5key[RFIFOW (fd, 2) - 4 + 1]; @@ -4851,7 +4851,7 @@ int parse_fromlogin (int fd) sizeof (loginserveradminpassword)); strcat (md5str, RFIFOP (fd, 4)); } - MD5_String2binary (md5str, md5bin); + MD5_to_bin(MD5_from_cstring(md5str), md5bin); WFIFOW (login_fd, 0) = 0x7918; // Request for administation login (encrypted password) WFIFOW (login_fd, 2) = passenc; // Encrypted type memcpy (WFIFOP (login_fd, 4), md5bin, 16); @@ -4880,7 +4880,7 @@ int parse_fromlogin (int fd) case 0x7531: // Displaying of the version of the login-server if (RFIFOREST (fd) < 10) - return 0; + return; Iprintf (" Login-Server [%s:%d]\n", loginserverip, loginserverport); if (((int) RFIFOB (login_fd, 5)) == 0) @@ -4914,7 +4914,7 @@ int parse_fromlogin (int fd) case 0x7921: // Displaying of the list of accounts if (RFIFOREST (fd) < 4 || RFIFOREST (fd) < RFIFOW (fd, 2)) - return 0; + return; if (RFIFOW (fd, 2) < 5) { if (defaultlanguage == 'F') @@ -5064,7 +5064,7 @@ int parse_fromlogin (int fd) case 0x7931: // Answer of login-server about an account creation if (RFIFOREST (fd) < 30) - return 0; + return; if (RFIFOL (fd, 2) == -1) { if (defaultlanguage == 'F') @@ -5111,7 +5111,7 @@ int parse_fromlogin (int fd) case 0x7933: // Answer of login-server about an account deletion if (RFIFOREST (fd) < 30) - return 0; + return; if (RFIFOL (fd, 2) == -1) { if (defaultlanguage == 'F') @@ -5159,7 +5159,7 @@ int parse_fromlogin (int fd) case 0x7935: // answer of the change of an account password if (RFIFOREST (fd) < 30) - return 0; + return; if (RFIFOL (fd, 2) == -1) { if (defaultlanguage == 'F') @@ -5211,7 +5211,7 @@ int parse_fromlogin (int fd) case 0x7937: // answer of the change of an account state if (RFIFOREST (fd) < 34) - return 0; + return; if (RFIFOL (fd, 2) == -1) { if (defaultlanguage == 'F') @@ -5301,7 +5301,7 @@ int parse_fromlogin (int fd) case 0x7939: // answer of the number of online players if (RFIFOREST (fd) < 4 || RFIFOREST (fd) < RFIFOW (fd, 2)) - return 0; + return; { // Get length of the received packet int i; @@ -5360,7 +5360,7 @@ int parse_fromlogin (int fd) case 0x793b: // answer of the check of a password if (RFIFOREST (fd) < 30) - return 0; + return; if (RFIFOL (fd, 2) == -1) { if (defaultlanguage == 'F') @@ -5409,7 +5409,7 @@ int parse_fromlogin (int fd) case 0x793d: // answer of the change of an account sex if (RFIFOREST (fd) < 30) - return 0; + return; if (RFIFOL (fd, 2) == -1) { if (defaultlanguage == 'F') @@ -5463,7 +5463,7 @@ int parse_fromlogin (int fd) case 0x793f: // answer of the change of an account GM level if (RFIFOREST (fd) < 30) - return 0; + return; if (RFIFOL (fd, 2) == -1) { if (defaultlanguage == 'F') @@ -5521,7 +5521,7 @@ int parse_fromlogin (int fd) case 0x7941: // answer of the change of an account email if (RFIFOREST (fd) < 30) - return 0; + return; if (RFIFOL (fd, 2) == -1) { if (defaultlanguage == 'F') @@ -5573,7 +5573,7 @@ int parse_fromlogin (int fd) case 0x7943: // answer of the change of an account memo if (RFIFOREST (fd) < 30) - return 0; + return; if (RFIFOL (fd, 2) == -1) { if (defaultlanguage == 'F') @@ -5622,7 +5622,7 @@ int parse_fromlogin (int fd) case 0x7945: // answer of an account id search if (RFIFOREST (fd) < 30) - return 0; + return; if (RFIFOL (fd, 2) == -1) { if (defaultlanguage == 'F') @@ -5667,7 +5667,7 @@ int parse_fromlogin (int fd) case 0x7947: // answer of an account name search if (RFIFOREST (fd) < 30) - return 0; + return; if (strcmp (RFIFOP (fd, 6), "") == 0) { if (defaultlanguage == 'F') @@ -5712,7 +5712,7 @@ int parse_fromlogin (int fd) case 0x7949: // answer of an account validity limit set if (RFIFOREST (fd) < 34) - return 0; + return; if (RFIFOL (fd, 2) == -1) { if (defaultlanguage == 'F') @@ -5791,7 +5791,7 @@ int parse_fromlogin (int fd) case 0x794b: // answer of an account ban set if (RFIFOREST (fd) < 34) - return 0; + return; if (RFIFOL (fd, 2) == -1) { if (defaultlanguage == 'F') @@ -5870,7 +5870,7 @@ int parse_fromlogin (int fd) case 0x794d: // answer of an account ban date/time changing if (RFIFOREST (fd) < 34) - return 0; + return; if (RFIFOL (fd, 2) == -1) { if (defaultlanguage == 'F') @@ -5949,7 +5949,7 @@ int parse_fromlogin (int fd) case 0x794f: // answer of a broadcast if (RFIFOREST (fd) < 4) - return 0; + return; if (RFIFOW (fd, 2) == (unsigned short) -1) { if (defaultlanguage == 'F') @@ -5994,7 +5994,7 @@ int parse_fromlogin (int fd) case 0x7951: // answer of an account validity limit changing if (RFIFOREST (fd) < 34) - return 0; + return; if (RFIFOL (fd, 2) == -1) { if (defaultlanguage == 'F') @@ -6082,7 +6082,7 @@ int parse_fromlogin (int fd) case 0x7953: // answer of a request about informations of an account (by account name/id) if (RFIFOREST (fd) < 150 || RFIFOREST (fd) < (150 + RFIFOW (fd, 148))) - return 0; + return; { char userid[24], error_message[20], lastlogin[24], last_ip[16], email[40], memo[255]; @@ -6328,14 +6328,12 @@ int parse_fromlogin (int fd) ("Remote administration has been disconnected (unknown packet).\n"); ladmin_log ("'End of connection, unknown packet." RETCODE); session[fd]->eof = 1; - return 0; + return; } } // if we don't wait new packets, do the prompt prompt (); - - return 0; } //------------------------------------ @@ -6406,12 +6404,12 @@ int Connect_login_server () //------------------------------------------------- int config_switch (const char *str) { - if (strcmpi (str, "on") == 0 || strcmpi (str, "yes") == 0 - || strcmpi (str, "oui") == 0 || strcmpi (str, "ja") == 0 - || strcmpi (str, "si") == 0) + if (strcasecmp (str, "on") == 0 || strcasecmp (str, "yes") == 0 + || strcasecmp (str, "oui") == 0 || strcasecmp (str, "ja") == 0 + || strcasecmp (str, "si") == 0) return 1; - if (strcmpi (str, "off") == 0 || strcmpi (str, "no") == 0 - || strcmpi (str, "non") == 0 || strcmpi (str, "nein") == 0) + if (strcasecmp (str, "off") == 0 || strcasecmp (str, "no") == 0 + || strcasecmp (str, "non") == 0 || strcasecmp (str, "nein") == 0) return 0; return atoi (str); @@ -6463,7 +6461,7 @@ int ladmin_config_read (const char *cfgName) remove_control_chars (w1); remove_control_chars (w2); - if (strcmpi (w1, "login_ip") == 0) + if (strcasecmp (w1, "login_ip") == 0) { struct hostent *h = gethostbyname (w2); if (h != NULL) @@ -6495,11 +6493,11 @@ int ladmin_config_read (const char *cfgName) else memcpy (loginserverip, w2, 16); } - else if (strcmpi (w1, "login_port") == 0) + else if (strcasecmp (w1, "login_port") == 0) { loginserverport = atoi (w2); } - else if (strcmpi (w1, "admin_pass") == 0) + else if (strcasecmp (w1, "admin_pass") == 0) { strncpy (loginserveradminpassword, w2, sizeof (loginserveradminpassword)); @@ -6507,25 +6505,25 @@ int ladmin_config_read (const char *cfgName) 1] = '\0'; #ifdef PASSWORDENC } - else if (strcmpi (w1, "passenc") == 0) + else if (strcasecmp (w1, "passenc") == 0) { passenc = atoi (w2); if (passenc < 0 || passenc > 2) passenc = 0; #endif } - else if (strcmpi (w1, "defaultlanguage") == 0) + else if (strcasecmp (w1, "defaultlanguage") == 0) { if (w2[0] == 'F' || w2[0] == 'E') defaultlanguage = w2[0]; } - else if (strcmpi (w1, "ladmin_log_filename") == 0) + else if (strcasecmp (w1, "ladmin_log_filename") == 0) { strncpy (ladmin_log_filename, w2, sizeof (ladmin_log_filename)); ladmin_log_filename[sizeof (ladmin_log_filename) - 1] = '\0'; } - else if (strcmpi (w1, "date_format") == 0) + else if (strcasecmp (w1, "date_format") == 0) { // note: never have more than 19 char for the date! switch (atoi (w2)) { @@ -6543,7 +6541,7 @@ int ladmin_config_read (const char *cfgName) break; } } - else if (strcmpi (w1, "import") == 0) + else if (strcasecmp (w1, "import") == 0) { ladmin_config_read (w2); } @@ -6568,7 +6566,7 @@ int ladmin_config_read (const char *cfgName) //-------------------------------------- // Function called at exit of the server //-------------------------------------- -void do_final (void) +void term_func (void) { if (already_exit_function == 0) @@ -6601,6 +6599,7 @@ void do_final (void) //------------------------ int do_init (int argc, char **argv) { + eathena_interactive_session = isatty (0); // read ladmin configuration ladmin_config_read ((argc > 1) ? argv[1] : LADMIN_CONF_NAME); @@ -6616,7 +6615,6 @@ int do_init (int argc, char **argv) srand (time (NULL)); - set_termfunc (do_final); set_defaultparse (parse_fromlogin); if (defaultlanguage == 'F') @@ -6645,7 +6643,7 @@ int do_init (int argc, char **argv) Connect_login_server (); - atexit (do_final); + atexit (term_func); return 0; } diff --git a/src/login/Makefile b/src/login/Makefile index 8a7e5a6..bc1e7c0 100644 --- a/src/login/Makefile +++ b/src/login/Makefile @@ -2,8 +2,8 @@ include ../../make.defs all: login -COMMON_OBJ = ../common/core.o ../common/socket.o ../common/timer.o ../common/db.o ../common/lock.o ../common/malloc.o ../common/mt_rand.o ../common/md5calc.o -COMMON_H = ../common/core.h ../common/socket.h ../common/timer.h ../common/mmo.h ../common/version.h ../common/db.h ../common/lock.h ../common/malloc.h ../common/mt_rand.h ../common/md5calc.h +COMMON_OBJ = ../common/core.o ../common/socket.o ../common/timer.o ../common/db.o ../common/lock.o ../common/mt_rand.o ../common/md5calc.o +COMMON_H = ../common/core.h ../common/socket.h ../common/timer.h ../common/mmo.h ../common/version.h ../common/db.h ../common/lock.h ../common/mt_rand.h ../common/md5calc.h login: $(COMMON_OBJ) login.o: login.c login.h $(COMMON_H) diff --git a/src/login/login.c b/src/login/login.c index 480533e..6788371 100644 --- a/src/login/login.c +++ b/src/login/login.c @@ -219,12 +219,7 @@ int read_gm_account () if ((line[0] == '/' && line[1] == '/') || line[0] == '\0' || line[0] == '\n' || line[0] == '\r') continue; - p = calloc (sizeof (struct gm_account), 1); - if (p == NULL) - { - printf ("read_gm_account: memory allocation failure (malloc)!\n"); - exit (0); - } + CREATE (p, struct gm_account, 1); if (sscanf (line, "%d %d", &p->account_id, &p->level) != 2 && sscanf (line, "%d: %d", &p->account_id, &p->level) != 2) printf @@ -492,7 +487,7 @@ int search_account_index (char *account_name) for (i = 0; i < auth_num; i++) { // Without case sensitive check (increase the number of similar account names found) - if (stricmp (auth_dat[i].userid, account_name) == 0) + if (strcasecmp (auth_dat[i].userid, account_name) == 0) { // Strict comparison (if found, we finish the function immediatly with correct value) if (strcmp (auth_dat[i].userid, account_name) == 0) @@ -551,7 +546,7 @@ int mmo_auth_init (void) int GM_count = 0; int server_count = 0; - auth_dat = calloc (sizeof (struct auth_dat) * 256, 1); + CREATE (auth_dat, struct auth_dat, 256); auth_max = 256; fp = fopen_ (account_filename, "r"); @@ -650,8 +645,7 @@ int mmo_auth_init (void) if (auth_num >= auth_max) { auth_max += 256; - auth_dat = - realloc (auth_dat, sizeof (struct auth_dat) * auth_max); + RECREATE (auth_dat, struct auth_dat, auth_max); } memset (&auth_dat[auth_num], '\0', sizeof (struct auth_dat)); @@ -830,8 +824,7 @@ int mmo_auth_init (void) if (auth_num >= auth_max) { auth_max += 256; - auth_dat = - realloc (auth_dat, sizeof (struct auth_dat) * auth_max); + RECREATE (auth_dat, struct auth_dat, auth_max); } memset (&auth_dat[auth_num], '\0', sizeof (struct auth_dat)); @@ -1046,12 +1039,18 @@ void mmo_auth_sync (void) return; } -// We want to sync the DB to disk as little as possible as it's fairly +void term_func (void) +{ + mmo_auth_sync (); +} + + +// We want to sync the DB to disk as little as possible as it's fairly // resource intensive. therefore most player-triggerable events that // update the account DB will not immideately trigger a save. Instead // we save periodicly on a timer. //----------------------------------------------------- -int check_auth_sync (int tid, unsigned int tick, int id, int data) +void check_auth_sync (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) { if (pid != 0) { @@ -1061,14 +1060,14 @@ int check_auth_sync (int tid, unsigned int tick, int id, int data) // Need to check status too? if (temp == 0) { - return 0; + return; } } // This can take a lot of time. Fork a child to handle the work and return at once // If we're unable to fork just continue running the function normally if ((pid = fork ()) > 0) - return 0; + return; mmo_auth_sync (); @@ -1076,7 +1075,7 @@ int check_auth_sync (int tid, unsigned int tick, int id, int data) if (pid == 0) _exit (0); - return 0; + return; } //-------------------------------------------------------------------- @@ -1128,14 +1127,14 @@ void send_GM_accounts () //----------------------------------------------------- // Check if GM file account have been changed //----------------------------------------------------- -int check_GM_file (int tid, unsigned int tick, int id, int data) +void check_GM_file (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) { struct stat file_stat; long new_time; // if we would not check if (gm_account_filename_check_timer < 1) - return 0; + return; // get last modify time/date if (stat (GM_account_filename, &file_stat)) @@ -1148,8 +1147,6 @@ int check_GM_file (int tid, unsigned int tick, int id, int data) read_gm_account (); send_GM_accounts (); } - - return 0; } //------------------------------------- @@ -1164,7 +1161,7 @@ int mmo_auth_new (struct mmo_account *account, char sex, char *email) if (auth_num >= auth_max) { auth_max += 256; - auth_dat = realloc (auth_dat, sizeof (struct auth_dat) * auth_max); + RECREATE (auth_dat, struct auth_dat, auth_max); } memset (&auth_dat[i], '\0', sizeof (struct auth_dat)); @@ -1446,7 +1443,7 @@ int mmo_auth (struct mmo_account *account, int fd) //------------------------------- // Char-server anti-freeze system //------------------------------- -int char_anti_freeze_system (int tid, unsigned int tick, int id, int data) +void char_anti_freeze_system (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) { int i; @@ -1468,14 +1465,12 @@ int char_anti_freeze_system (int tid, unsigned int tick, int id, int data) } } } - - return 0; } //-------------------------------- // Packet parsing for char-servers //-------------------------------- -int parse_fromchar (int fd) +void parse_fromchar (int fd) { int i, j, id; unsigned char *p = (unsigned char *) &session[fd]->client_addr.sin_addr; @@ -1498,7 +1493,7 @@ int parse_fromchar (int fd) } close (fd); delete_session (fd); - return 0; + return; } while (RFIFOREST (fd) >= 2) @@ -1523,7 +1518,7 @@ int parse_fromchar (int fd) case 0x2712: // request from char-server to authentify an account if (RFIFOREST (fd) < 19) - return 0; + return; { int acc; acc = RFIFOL (fd, 2); // speed up @@ -1598,7 +1593,7 @@ int parse_fromchar (int fd) case 0x2714: if (RFIFOREST (fd) < 6) - return 0; + return; //printf("parse_fromchar: Receiving of the users number of the server '%s': %d\n", server[id].name, RFIFOL(fd,2)); server[id].users = RFIFOL (fd, 2); if (anti_freeze_enable) @@ -1612,7 +1607,7 @@ int parse_fromchar (int fd) int acc; char email[40]; if (RFIFOREST (fd) < 46) - return 0; + return; acc = RFIFOL (fd, 2); // speed up memcpy (email, RFIFOP (fd, 6), 40); email[39] = '\0'; @@ -1649,7 +1644,7 @@ int parse_fromchar (int fd) } case 0x2716: if (RFIFOREST (fd) < 6) - return 0; + return; //printf("parse_fromchar: E-mail/limited time request from '%s' server (concerned account: %d)\n", server[id].name, RFIFOL(fd,2)); for (i = 0; i < auth_num; i++) { @@ -1678,7 +1673,7 @@ int parse_fromchar (int fd) case 0x2720: // To become GM request if (RFIFOREST (fd) < 4 || RFIFOREST (fd) < RFIFOW (fd, 2)) - return 0; + return; { int acc; unsigned char buf[10]; @@ -1765,12 +1760,12 @@ int parse_fromchar (int fd) charif_sendallwos (-1, buf, 10); } RFIFOSKIP (fd, RFIFOW (fd, 2)); - return 0; + return; // Map server send information to change an email of an account via char-server case 0x2722: // 0x2722 .L .40B .40B if (RFIFOREST (fd) < 86) - return 0; + return; { int acc; char actual_email[40], new_email[40]; @@ -1789,7 +1784,7 @@ int parse_fromchar (int fd) login_log ("Char-server '%s': Attempt to modify an e-mail on an account (@email GM command) with a invalid new e-mail (account: %d, ip: %s)" RETCODE, server[id].name, acc, ip); - else if (strcmpi (new_email, "a@a.com") == 0) + else if (strcasecmp (new_email, "a@a.com") == 0) login_log ("Char-server '%s': Attempt to modify an e-mail on an account (@email GM command) with a default e-mail (account: %d, ip: %s)" RETCODE, server[id].name, acc, ip); @@ -1799,7 +1794,7 @@ int parse_fromchar (int fd) { if (auth_dat[i].account_id == acc) { - if (strcmpi (auth_dat[i].email, actual_email) + if (strcasecmp (auth_dat[i].email, actual_email) == 0) { memcpy (auth_dat[i].email, new_email, 40); @@ -1829,7 +1824,7 @@ int parse_fromchar (int fd) // Receiving of map-server via char-server a status change resquest (by Yor) case 0x2724: if (RFIFOREST (fd) < 10) - return 0; + return; { int acc, statut; acc = RFIFOL (fd, 2); @@ -1874,11 +1869,11 @@ int parse_fromchar (int fd) } RFIFOSKIP (fd, 10); } - return 0; + return; case 0x2725: // Receiving of map-server via char-server a ban resquest (by Yor) if (RFIFOREST (fd) < 18) - return 0; + return; { int acc; acc = RFIFOL (fd, 2); @@ -1970,11 +1965,11 @@ int parse_fromchar (int fd) } RFIFOSKIP (fd, 18); } - return 0; + return; case 0x2727: // Change of sex (sex is reversed) if (RFIFOREST (fd) < 6) - return 0; + return; { int acc, sex; acc = RFIFOL (fd, 2); @@ -2020,11 +2015,11 @@ int parse_fromchar (int fd) } RFIFOSKIP (fd, 6); } - return 0; + return; case 0x2728: // We receive account_reg2 from a char-server, and we send them to other char-servers. if (RFIFOREST (fd) < 4 || RFIFOREST (fd) < RFIFOW (fd, 2)) - return 0; + return; { int acc, p; acc = RFIFOL (fd, 4); @@ -2071,7 +2066,7 @@ int parse_fromchar (int fd) case 0x272a: // Receiving of map-server via char-server a unban resquest (by Yor) if (RFIFOREST (fd) < 6) - return 0; + return; { int acc; acc = RFIFOL (fd, 2); @@ -2103,12 +2098,12 @@ int parse_fromchar (int fd) } RFIFOSKIP (fd, 6); } - return 0; + return; // request from char-server to change account password case 0x2740: // 0x2740 .L .24B .24B if (RFIFOREST (fd) < 54) - return 0; + return; { int acc; char actual_pass[24], new_pass[24]; @@ -2218,16 +2213,16 @@ int parse_fromchar (int fd) session[fd]->eof = 1; printf ("Char-server has been disconnected (unknown packet).\n"); - return 0; + return; } } - return 0; + return; } //--------------------------------------- // Packet parsing for administation login //--------------------------------------- -int parse_admin (int fd) +void parse_admin (int fd) { int i, j; unsigned char *p = (unsigned char *) &session[fd]->client_addr.sin_addr; @@ -2242,7 +2237,7 @@ int parse_admin (int fd) delete_session (fd); printf ("Remote administration has disconnected (session #%d).\n", fd); - return 0; + return; } while (RFIFOREST (fd) >= 2) @@ -2278,7 +2273,7 @@ int parse_admin (int fd) case 0x7920: // Request of an accounts list if (RFIFOREST (fd) < 10) - return 0; + return; { int st, ed, len; int id[auth_num]; @@ -2342,7 +2337,7 @@ int parse_admin (int fd) case 0x7924: { // [Fate] Itemfrob package: change item IDs if (RFIFOREST (fd) < 10) - return 0; + return; charif_sendallwos (-1, RFIFOP (fd, 0), 10); // forward package to char servers RFIFOSKIP (fd, 10); WFIFOW (fd, 0) = 0x7925; @@ -2352,7 +2347,7 @@ int parse_admin (int fd) case 0x7930: // Request for an account creation if (RFIFOREST (fd) < 91) - return 0; + return; { struct mmo_account ma; ma.userid = RFIFOP (fd, 2); @@ -2423,7 +2418,7 @@ int parse_admin (int fd) case 0x7932: // Request for an account deletion if (RFIFOREST (fd) < 26) - return 0; + return; WFIFOW (fd, 0) = 0x7933; WFIFOL (fd, 2) = -1; account_name = RFIFOP (fd, 2); @@ -2465,7 +2460,7 @@ int parse_admin (int fd) case 0x7934: // Request to change a password if (RFIFOREST (fd) < 50) - return 0; + return; WFIFOW (fd, 0) = 0x7935; WFIFOL (fd, 2) = -1; account_name = RFIFOP (fd, 2); @@ -2495,7 +2490,7 @@ int parse_admin (int fd) case 0x7936: // Request to modify a state if (RFIFOREST (fd) < 50) - return 0; + return; { char error_message[20]; int statut; @@ -2593,7 +2588,7 @@ int parse_admin (int fd) case 0x793a: // Request to password check if (RFIFOREST (fd) < 50) - return 0; + return; WFIFOW (fd, 0) = 0x793b; WFIFOL (fd, 2) = -1; account_name = RFIFOP (fd, 2); @@ -2635,7 +2630,7 @@ int parse_admin (int fd) case 0x793c: // Request to modify sex if (RFIFOREST (fd) < 27) - return 0; + return; WFIFOW (fd, 0) = 0x793d; WFIFOL (fd, 2) = -1; account_name = RFIFOP (fd, 2); @@ -2707,7 +2702,7 @@ int parse_admin (int fd) case 0x793e: // Request to modify GM level if (RFIFOREST (fd) < 27) - return 0; + return; WFIFOW (fd, 0) = 0x793f; WFIFOL (fd, 2) = -1; account_name = RFIFOP (fd, 2); @@ -2829,26 +2824,15 @@ int parse_admin (int fd) RETCODE, auth_dat[i].userid, acc, (int) new_gm_level, ip); } - if (lock_fclose - (fp2, GM_account_filename, - &lock) == 0) - { - WFIFOL (fd, 2) = acc; - login_log - ("'ladmin': Modification of a GM level (account: %s (%d), new GM level: %d, ip: %s)" - RETCODE, auth_dat[i].userid, acc, - (int) new_gm_level, ip); - // read and send new GM informations - read_gm_account (); - send_GM_accounts (); - } - else - { - login_log - ("'ladmin': Attempt to modify of a GM level - impossible to write GM accounts file (account: %s (%d), received GM level: %d, ip: %s)" - RETCODE, auth_dat[i].userid, acc, - (int) new_gm_level, ip); - } + lock_fclose(fp2, GM_account_filename, &lock); + WFIFOL (fd, 2) = acc; + login_log + ("'ladmin': Modification of a GM level (account: %s (%d), new GM level: %d, ip: %s)" + RETCODE, auth_dat[i].userid, acc, + (int) new_gm_level, ip); + // read and send new GM informations + read_gm_account (); + send_GM_accounts (); } else { @@ -2881,7 +2865,7 @@ int parse_admin (int fd) case 0x7940: // Request to modify e-mail if (RFIFOREST (fd) < 66) - return 0; + return; WFIFOW (fd, 0) = 0x7941; WFIFOL (fd, 2) = -1; account_name = RFIFOP (fd, 2); @@ -2925,7 +2909,7 @@ int parse_admin (int fd) case 0x7942: // Request to modify memo field if (RFIFOREST (fd) < 28 || RFIFOREST (fd) < (28 + RFIFOW (fd, 26))) - return 0; + return; WFIFOW (fd, 0) = 0x7943; WFIFOL (fd, 2) = -1; account_name = RFIFOP (fd, 2); @@ -2971,7 +2955,7 @@ int parse_admin (int fd) case 0x7944: // Request to found an account id if (RFIFOREST (fd) < 26) - return 0; + return; WFIFOW (fd, 0) = 0x7945; WFIFOL (fd, 2) = -1; account_name = RFIFOP (fd, 2); @@ -3000,7 +2984,7 @@ int parse_admin (int fd) case 0x7946: // Request to found an account name if (RFIFOREST (fd) < 6) - return 0; + return; WFIFOW (fd, 0) = 0x7947; WFIFOL (fd, 2) = RFIFOL (fd, 2); memset (WFIFOP (fd, 6), '\0', 24); @@ -3028,7 +3012,7 @@ int parse_admin (int fd) case 0x7948: // Request to change the validity limit (timestamp) (absolute value) if (RFIFOREST (fd) < 30) - return 0; + return; { time_t timestamp; char tmpstr[2048]; @@ -3066,7 +3050,7 @@ int parse_admin (int fd) case 0x794a: // Request to change the final date of a banishment (timestamp) (absolute value) if (RFIFOREST (fd) < 30) - return 0; + return; { time_t timestamp; char tmpstr[2048]; @@ -3122,7 +3106,7 @@ int parse_admin (int fd) case 0x794c: // Request to change the final date of a banishment (timestamp) (relative change) if (RFIFOREST (fd) < 38) - return 0; + return; { time_t timestamp; struct tm *tmtime; @@ -3229,7 +3213,7 @@ int parse_admin (int fd) case 0x794e: // Request to send a broadcast message if (RFIFOREST (fd) < 8 || RFIFOREST (fd) < (8 + RFIFOL (fd, 4))) - return 0; + return; WFIFOW (fd, 0) = 0x794f; WFIFOW (fd, 2) = -1; if (RFIFOL (fd, 4) < 1) @@ -3280,7 +3264,7 @@ int parse_admin (int fd) case 0x7950: // Request to change the validity limite (timestamp) (relative change) if (RFIFOREST (fd) < 38) - return 0; + return; { time_t timestamp; struct tm *tmtime; @@ -3384,7 +3368,7 @@ int parse_admin (int fd) case 0x7952: // Request about informations of an account (by account name) if (RFIFOREST (fd) < 26) - return 0; + return; WFIFOW (fd, 0) = 0x7953; WFIFOL (fd, 2) = -1; account_name = RFIFOP (fd, 2); @@ -3434,7 +3418,7 @@ int parse_admin (int fd) case 0x7954: // Request about information of an account (by account id) if (RFIFOREST (fd) < 6) - return 0; + return; WFIFOW (fd, 0) = 0x7953; WFIFOL (fd, 2) = RFIFOL (fd, 2); memset (WFIFOP (fd, 7), '\0', 24); @@ -3550,12 +3534,12 @@ int parse_admin (int fd) session[fd]->eof = 1; printf ("Remote administration has been disconnected (unknown packet).\n"); - return 0; + return; } //WFIFOW(fd,0) = 0x791f; //WFIFOSET(fd,2); } - return 0; + return; } //-------------------------------------------- @@ -3586,7 +3570,7 @@ int lan_ip_check (unsigned char *p) //---------------------------------------------------------------------------------------- // Default packet parsing (normal players or administation/char-server connexion requests) //---------------------------------------------------------------------------------------- -int parse_login (int fd) +void parse_login (int fd) { struct mmo_account account; int result, i, j; @@ -3600,7 +3584,7 @@ int parse_login (int fd) { close (fd); delete_session (fd); - return 0; + return; } while (RFIFOREST (fd) >= 2) @@ -3631,20 +3615,20 @@ int parse_login (int fd) { case 0x200: // New alive packet: structure: 0x200 .24B. used to verify if client is always alive. if (RFIFOREST (fd) < 26) - return 0; + return; RFIFOSKIP (fd, 26); break; case 0x204: // New alive packet: structure: 0x204 .16B. (new ragexe from 22 june 2004) if (RFIFOREST (fd) < 18) - return 0; + return; RFIFOSKIP (fd, 18); break; case 0x64: // Ask connection of a client case 0x01dd: // Ask connection of a client (encryption mode) if (RFIFOREST (fd) < ((RFIFOW (fd, 0) == 0x64) ? 55 : 47)) - return 0; + return; account.userid = RFIFOP (fd, 6); account.userid[23] = '\0'; @@ -3867,15 +3851,16 @@ int parse_login (int fd) printf ("login: abnormal request of MD5 key (already opened session).\n"); session[fd]->eof = 1; - return 0; + return; } - ld = session[fd]->session_data = calloc (sizeof (*ld), 1); + CREATE (ld, struct login_session_data, 1); + session[fd]->session_data = ld; if (!ld) { printf ("login: Request for md5 key: memory allocation failure (malloc)!\n"); session[fd]->eof = 1; - return 0; + return; } if (RFIFOW (fd, 0) == 0x01db) { @@ -3904,7 +3889,7 @@ int parse_login (int fd) case 0x2710: // Connection request of a char-server if (RFIFOREST (fd) < 86) - return 0; + return; { int GM_value, len; unsigned char *server_name; @@ -3930,7 +3915,7 @@ int parse_login (int fd) { // If this is the main server, and we don't already have a main server if (server_fd[0] <= 0 - && strcmpi (server_name, main_server) == 0) + && strcasecmp (server_name, main_server) == 0) { account.account_id = 0; } @@ -4006,7 +3991,7 @@ int parse_login (int fd) } } RFIFOSKIP (fd, 86); - return 0; + return; case 0x7530: // Request of the server version login_log ("Sending of the server version (ip: %s)" RETCODE, @@ -4024,12 +4009,12 @@ int parse_login (int fd) case 0x7532: // Request to end connection login_log ("End of connection (ip: %s)" RETCODE, ip); session[fd]->eof = 1; - return 0; + return; case 0x7918: // Request for administation login if (RFIFOREST (fd) < 4 || RFIFOREST (fd) < ((RFIFOW (fd, 2) == 0) ? 28 : 20)) - return 0; + return; WFIFOW (fd, 0) = 0x7919; WFIFOB (fd, 2) = 1; if (!check_ladminip @@ -4087,7 +4072,7 @@ int parse_login (int fd) strncpy (md5str, admin_pass, sizeof (admin_pass)); // 24 strcat (md5str, ld->md5key); // 20 } - MD5_String2binary (md5str, md5bin); + MD5_to_bin(MD5_from_cstring(md5str), md5bin); // If remote administration is enabled and password hash sent by client matches hash of password read from login server configuration file if ((admin_state == 1) && (memcmp (md5bin, RFIFOP (fd, 4), 16) == 0)) @@ -4173,10 +4158,10 @@ int parse_login (int fd) login_log ("End of connection, unknown packet (ip: %s)" RETCODE, ip); session[fd]->eof = 1; - return 0; + return; } } - return 0; + return; } //------------------------------------------------- @@ -4185,12 +4170,12 @@ int parse_login (int fd) //------------------------------------------------- int config_switch (const char *str) { - if (strcmpi (str, "on") == 0 || strcmpi (str, "yes") == 0 - || strcmpi (str, "oui") == 0 || strcmpi (str, "ja") == 0 - || strcmpi (str, "si") == 0) + if (strcasecmp (str, "on") == 0 || strcasecmp (str, "yes") == 0 + || strcasecmp (str, "oui") == 0 || strcasecmp (str, "ja") == 0 + || strcasecmp (str, "si") == 0) return 1; - if (strcmpi (str, "off") == 0 || strcmpi (str, "no") == 0 - || strcmpi (str, "non") == 0 || strcmpi (str, "nein") == 0) + if (strcasecmp (str, "off") == 0 || strcasecmp (str, "no") == 0 + || strcasecmp (str, "non") == 0 || strcasecmp (str, "nein") == 0) return 0; return atoi (str); @@ -4238,7 +4223,7 @@ int login_lan_config_read (const char *lancfgName) remove_control_chars (w1); remove_control_chars (w2); - if (strcmpi (w1, "lan_char_ip") == 0) + if (strcasecmp (w1, "lan_char_ip") == 0) { // Read Char-Server Lan IP Address h = gethostbyname (w2); if (h != NULL) @@ -4256,7 +4241,7 @@ int login_lan_config_read (const char *lancfgName) } printf ("LAN IP of char-server: %s.\n", lan_char_ip); } - else if (strcmpi (w1, "subnet") == 0) + else if (strcasecmp (w1, "subnet") == 0) { // Read Subnetwork for (j = 0; j < 4; j++) subneti[j] = 0; @@ -4274,7 +4259,7 @@ int login_lan_config_read (const char *lancfgName) printf ("Sub-network of the char-server: %d.%d.%d.%d.\n", subneti[0], subneti[1], subneti[2], subneti[3]); } - else if (strcmpi (w1, "subnetmask") == 0) + else if (strcasecmp (w1, "subnetmask") == 0) { // Read Subnetwork Mask for (j = 0; j < 4; j++) subnetmaski[j] = 255; @@ -4357,18 +4342,18 @@ int login_config_read (const char *cfgName) remove_control_chars (w1); remove_control_chars (w2); - if (strcmpi (w1, "admin_state") == 0) + if (strcasecmp (w1, "admin_state") == 0) { admin_state = config_switch (w2); } - else if (strcmpi (w1, "admin_pass") == 0) + else if (strcasecmp (w1, "admin_pass") == 0) { strncpy (admin_pass, w2, sizeof (admin_pass)); admin_pass[sizeof (admin_pass) - 1] = '\0'; } - else if (strcmpi (w1, "ladminallowip") == 0) + else if (strcasecmp (w1, "ladminallowip") == 0) { - if (strcmpi (w2, "clear") == 0) + if (strcasecmp (w2, "clear") == 0) { if (access_ladmin_allow) free (access_ladmin_allow); @@ -4377,27 +4362,23 @@ int login_config_read (const char *cfgName) } else { - if (strcmpi (w2, "all") == 0) + if (strcasecmp (w2, "all") == 0) { // reset all previous values if (access_ladmin_allow) free (access_ladmin_allow); // set to all - access_ladmin_allow = calloc (ACO_STRSIZE, 1); + CREATE (access_ladmin_allow, char, ACO_STRSIZE); access_ladmin_allownum = 1; - access_ladmin_allow[0] = '\0'; } else if (w2[0] && !(access_ladmin_allownum == 1 && access_ladmin_allow[0] == '\0')) { // don't add IP if already 'all' if (access_ladmin_allow) - access_ladmin_allow = - realloc (access_ladmin_allow, - (access_ladmin_allownum + - 1) * ACO_STRSIZE); + RECREATE (access_ladmin_allow, char, (access_ladmin_allownum + 1) * ACO_STRSIZE); else - access_ladmin_allow = calloc (ACO_STRSIZE, 1); + CREATE (access_ladmin_allow, char, ACO_STRSIZE); strncpy (access_ladmin_allow + (access_ladmin_allownum++) * ACO_STRSIZE, w2, ACO_STRSIZE); @@ -4406,44 +4387,44 @@ int login_config_read (const char *cfgName) } } } - else if (strcmpi (w1, "gm_pass") == 0) + else if (strcasecmp (w1, "gm_pass") == 0) { strncpy (gm_pass, w2, sizeof (gm_pass)); gm_pass[sizeof (gm_pass) - 1] = '\0'; } - else if (strcmpi (w1, "level_new_gm") == 0) + else if (strcasecmp (w1, "level_new_gm") == 0) { level_new_gm = atoi (w2); } - else if (strcmpi (w1, "new_account") == 0) + else if (strcasecmp (w1, "new_account") == 0) { new_account_flag = config_switch (w2); } - else if (strcmpi (w1, "login_port") == 0) + else if (strcasecmp (w1, "login_port") == 0) { login_port = atoi (w2); } - else if (strcmpi (w1, "account_filename") == 0) + else if (strcasecmp (w1, "account_filename") == 0) { strncpy (account_filename, w2, sizeof (account_filename)); account_filename[sizeof (account_filename) - 1] = '\0'; } - else if (strcmpi (w1, "gm_account_filename") == 0) + else if (strcasecmp (w1, "gm_account_filename") == 0) { strncpy (GM_account_filename, w2, sizeof (GM_account_filename)); GM_account_filename[sizeof (GM_account_filename) - 1] = '\0'; } - else if (strcmpi (w1, "gm_account_filename_check_timer") == 0) + else if (strcasecmp (w1, "gm_account_filename_check_timer") == 0) { gm_account_filename_check_timer = atoi (w2); } - else if (strcmpi (w1, "login_log_filename") == 0) + else if (strcasecmp (w1, "login_log_filename") == 0) { strncpy (login_log_filename, w2, sizeof (login_log_filename)); login_log_filename[sizeof (login_log_filename) - 1] = '\0'; } - else if (strcmpi (w1, "login_log_unknown_packets_filename") == 0) + else if (strcasecmp (w1, "login_log_unknown_packets_filename") == 0) { strncpy (login_log_unknown_packets_filename, w2, sizeof (login_log_unknown_packets_filename)); @@ -4451,23 +4432,23 @@ int login_config_read (const char *cfgName) (login_log_unknown_packets_filename) - 1] = '\0'; } - else if (strcmpi (w1, "save_unknown_packets") == 0) + else if (strcasecmp (w1, "save_unknown_packets") == 0) { save_unknown_packets = config_switch (w2); } - else if (strcmpi (w1, "display_parse_login") == 0) + else if (strcasecmp (w1, "display_parse_login") == 0) { display_parse_login = config_switch (w2); // 0: no, 1: yes } - else if (strcmpi (w1, "display_parse_admin") == 0) + else if (strcasecmp (w1, "display_parse_admin") == 0) { display_parse_admin = config_switch (w2); // 0: no, 1: yes } - else if (strcmpi (w1, "display_parse_fromchar") == 0) + else if (strcasecmp (w1, "display_parse_fromchar") == 0) { display_parse_fromchar = config_switch (w2); // 0: no, 1: yes (without packet 0x2714), 2: all packets } - else if (strcmpi (w1, "date_format") == 0) + else if (strcasecmp (w1, "date_format") == 0) { // note: never have more than 19 char for the date! switch (atoi (w2)) { @@ -4485,38 +4466,38 @@ int login_config_read (const char *cfgName) break; } } - else if (strcmpi (w1, "min_level_to_connect") == 0) + else if (strcasecmp (w1, "min_level_to_connect") == 0) { min_level_to_connect = atoi (w2); } - else if (strcmpi (w1, "add_to_unlimited_account") == 0) + else if (strcasecmp (w1, "add_to_unlimited_account") == 0) { add_to_unlimited_account = config_switch (w2); } - else if (strcmpi (w1, "start_limited_time") == 0) + else if (strcasecmp (w1, "start_limited_time") == 0) { start_limited_time = atoi (w2); } - else if (strcmpi (w1, "check_ip_flag") == 0) + else if (strcasecmp (w1, "check_ip_flag") == 0) { check_ip_flag = config_switch (w2); } - else if (strcmpi (w1, "order") == 0) + else if (strcasecmp (w1, "order") == 0) { access_order = atoi (w2); - if (strcmpi (w2, "deny,allow") == 0 || - strcmpi (w2, "deny, allow") == 0) + if (strcasecmp (w2, "deny,allow") == 0 || + strcasecmp (w2, "deny, allow") == 0) access_order = ACO_DENY_ALLOW; - if (strcmpi (w2, "allow,deny") == 0 || - strcmpi (w2, "allow, deny") == 0) + if (strcasecmp (w2, "allow,deny") == 0 || + strcasecmp (w2, "allow, deny") == 0) access_order = ACO_ALLOW_DENY; - if (strcmpi (w2, "mutual-failture") == 0 || - strcmpi (w2, "mutual-failure") == 0) + if (strcasecmp (w2, "mutual-failture") == 0 || + strcasecmp (w2, "mutual-failure") == 0) access_order = ACO_MUTUAL_FAILTURE; } - else if (strcmpi (w1, "allow") == 0) + else if (strcasecmp (w1, "allow") == 0) { - if (strcmpi (w2, "clear") == 0) + if (strcasecmp (w2, "clear") == 0) { if (access_allow) free (access_allow); @@ -4525,26 +4506,23 @@ int login_config_read (const char *cfgName) } else { - if (strcmpi (w2, "all") == 0) + if (strcasecmp (w2, "all") == 0) { // reset all previous values if (access_allow) free (access_allow); // set to all - access_allow = calloc (ACO_STRSIZE, 1); + CREATE (access_allow, char, ACO_STRSIZE); access_allownum = 1; - access_allow[0] = '\0'; } else if (w2[0] && !(access_allownum == 1 && access_allow[0] == '\0')) { // don't add IP if already 'all' if (access_allow) - access_allow = - realloc (access_allow, - (access_allownum + 1) * ACO_STRSIZE); + RECREATE (access_allow, char, (access_allownum + 1) * ACO_STRSIZE); else - access_allow = calloc (ACO_STRSIZE, 1); + CREATE (access_allow, char, ACO_STRSIZE); strncpy (access_allow + (access_allownum++) * ACO_STRSIZE, w2, ACO_STRSIZE); @@ -4553,9 +4531,9 @@ int login_config_read (const char *cfgName) } } } - else if (strcmpi (w1, "deny") == 0) + else if (strcasecmp (w1, "deny") == 0) { - if (strcmpi (w2, "clear") == 0) + if (strcasecmp (w2, "clear") == 0) { if (access_deny) free (access_deny); @@ -4564,26 +4542,23 @@ int login_config_read (const char *cfgName) } else { - if (strcmpi (w2, "all") == 0) + if (strcasecmp (w2, "all") == 0) { // reset all previous values if (access_deny) free (access_deny); // set to all - access_deny = calloc (ACO_STRSIZE, 1); + CREATE (access_deny, char, ACO_STRSIZE); access_denynum = 1; - access_deny[0] = '\0'; } else if (w2[0] && !(access_denynum == 1 && access_deny[0] == '\0')) { // don't add IP if already 'all' if (access_deny) - access_deny = - realloc (access_deny, - (access_denynum + 1) * ACO_STRSIZE); + RECREATE (access_deny, char, (access_denynum + 1) * ACO_STRSIZE); else - access_deny = calloc (ACO_STRSIZE, 1); + CREATE (access_deny, char, ACO_STRSIZE); strncpy (access_deny + (access_denynum++) * ACO_STRSIZE, w2, ACO_STRSIZE); @@ -4591,26 +4566,26 @@ int login_config_read (const char *cfgName) } } } - else if (strcmpi (w1, "anti_freeze_enable") == 0) + else if (strcasecmp (w1, "anti_freeze_enable") == 0) { anti_freeze_enable = config_switch (w2); } - else if (strcmpi (w1, "anti_freeze_interval") == 0) + else if (strcasecmp (w1, "anti_freeze_interval") == 0) { ANTI_FREEZE_INTERVAL = atoi (w2); if (ANTI_FREEZE_INTERVAL < 5) ANTI_FREEZE_INTERVAL = 5; // minimum 5 seconds } - else if (strcmpi (w1, "import") == 0) + else if (strcasecmp (w1, "import") == 0) { login_config_read (w2); } - else if (strcmpi (w1, "update_host") == 0) + else if (strcasecmp (w1, "update_host") == 0) { strncpy (update_host, w2, sizeof (update_host)); update_host[sizeof (update_host) - 1] = '\0'; } - else if (strcmpi (w1, "main_server") == 0) + else if (strcasecmp (w1, "main_server") == 0) { strncpy (main_server, w2, sizeof (main_server)); main_server[sizeof (main_server) - 1] = '\0'; @@ -5079,19 +5054,18 @@ int do_init (int argc, char **argv) read_gm_account (); mmo_auth_init (); - set_termfunc (mmo_auth_sync); +// set_termfunc (mmo_auth_sync); set_defaultparse (parse_login); login_fd = make_listen_port (login_port); - add_timer_func_list (check_auth_sync, "check_auth_sync"); +// add_timer_func_list (check_auth_sync, "check_auth_sync"); // Trigger auth sync every 5 minutes i = add_timer_interval (gettick () + 300000, check_auth_sync, 0, 0, 300000); if (anti_freeze_enable > 0) { - add_timer_func_list (char_anti_freeze_system, - "char_anti_freeze_system"); +// add_timer_func_list (char_anti_freeze_system, "char_anti_freeze_system"); i = add_timer_interval (gettick () + 1000, char_anti_freeze_system, 0, 0, ANTI_FREEZE_INTERVAL * 1000); } @@ -5100,7 +5074,7 @@ int do_init (int argc, char **argv) j = gm_account_filename_check_timer; if (j == 0) // if we would not to check, we check every 60 sec, just to have timer (if we change timer, is was not necessary to check if timer already exists) j = 60; - add_timer_func_list (check_GM_file, "check_GM_file"); +// add_timer_func_list (check_GM_file, "check_GM_file"); i = add_timer_interval (gettick () + j * 1000, check_GM_file, 0, 0, j * 1000); // every x sec we check if gm file has been changed login_log diff --git a/src/map/Makefile b/src/map/Makefile index f31279c..d340015 100644 --- a/src/map/Makefile +++ b/src/map/Makefile @@ -5,8 +5,8 @@ all: map obj: mkdir obj -COMMON_OBJ = ../common/core.o ../common/socket.o ../common/timer.o ../common/grfio.o ../common/db.o ../common/lock.o ../common/nullpo.o ../common/malloc.o ../common/mt_rand.o ../common/md5calc.o -LDLIBS = -lz -lm +COMMON_OBJ = ../common/core.o ../common/socket.o ../common/timer.o ../common/grfio.o ../common/db.o ../common/lock.o ../common/nullpo.o ../common/mt_rand.o ../common/md5calc.o +LDLIBS = -lm map: obj/tmw.o obj/magic-interpreter-lexer.o obj/magic-interpreter-parser.o obj/magic-interpreter-base.o obj/magic-expr.o obj/magic-stmt.o obj/magic.o obj/map.o obj/chrif.o obj/clif.o obj/pc.o obj/npc.o obj/chat.o obj/path.o obj/itemdb.o obj/mob.o obj/script.o obj/storage.o obj/skill.o obj/skill-pools.o obj/atcommand.o obj/battle.o obj/intif.o obj/trade.o obj/party.o obj/guild.o $(COMMON_OBJ) ${LINK.c} $^ ${LDLIBS} -o $@ diff --git a/src/map/atcommand.c b/src/map/atcommand.c index cb9e93c..6a09970 100644 --- a/src/map/atcommand.c +++ b/src/map/atcommand.c @@ -13,6 +13,7 @@ #include "../common/socket.h" #include "../common/timer.h" #include "../common/nullpo.h" +#include "../common/mt_rand.h" #include "atcommand.h" #include "battle.h" @@ -794,7 +795,7 @@ AtCommandType atcommand (const int level, const char *message, while (atcommand_info[i].type != AtCommand_Unknown) { - if (strcmpi (command + 1, atcommand_info[i].command + 1) == 0 + if (strcasecmp (command + 1, atcommand_info[i].command + 1) == 0 && level >= atcommand_info[i].level) { p[0] = atcommand_info[i].command[0]; // set correct first symbol for after. @@ -862,7 +863,7 @@ int msg_config_read (const char *cfgName) continue; if (sscanf (line, "%[^:]: %[^\r\n]", w1, w2) == 2) { - if (strcmpi (w1, "import") == 0) + if (strcasecmp (w1, "import") == 0) { msg_config_read (w2); } @@ -891,7 +892,7 @@ static AtCommandInfo *get_atcommandinfo_byname (const char *name) int i; for (i = 0; atcommand_info[i].type != AtCommand_Unknown; i++) - if (strcmpi (atcommand_info[i].command + 1, name) == 0) + if (strcasecmp (atcommand_info[i].command + 1, name) == 0) return &atcommand_info[i]; return NULL; @@ -930,9 +931,9 @@ int atcommand_config_read (const char *cfgName) p->level = 0; } - if (strcmpi (w1, "import") == 0) + if (strcasecmp (w1, "import") == 0) atcommand_config_read (w2); - else if (strcmpi (w1, "command_symbol") == 0 && w2[0] > 31 && w2[0] != '/' && // symbol of standard ragnarok GM commands + else if (strcasecmp (w1, "command_symbol") == 0 && w2[0] > 31 && w2[0] != '/' && // symbol of standard ragnarok GM commands w2[0] != '%') // symbol of party chat speaking command_symbol = w2[0]; } @@ -3506,7 +3507,7 @@ int atcommand_param (const int fd, struct map_session_data *sd, index = -1; for (i = 0; param[i] != NULL; i++) { - if (strcmpi (command, param[i]) == 0) + if (strcasecmp (command, param[i]) == 0) { index = i; break; @@ -7131,12 +7132,12 @@ int atcommand_email (const int fd, struct map_session_data *sd, clif_displaymessage (fd, msg_table[145]); // Invalid new email. Please enter a real e-mail. return -1; } - else if (strcmpi (new_email, "a@a.com") == 0) + else if (strcasecmp (new_email, "a@a.com") == 0) { clif_displaymessage (fd, msg_table[146]); // New email must be a real e-mail. return -1; } - else if (strcmpi (actual_email, new_email) == 0) + else if (strcasecmp (actual_email, new_email) == 0) { clif_displaymessage (fd, msg_table[147]); // New email must be different of the actual e-mail. return -1; @@ -7829,7 +7830,7 @@ atcommand_dropall (const int fd, struct map_session_data *sd, /*========================================== * @chardropall by [MouseJstr] - * + * * Throw all the characters possessions on the ground. Normally * done in response to them being disrespectful of a GM *------------------------------------------ @@ -7967,8 +7968,8 @@ atcommand_skillid (const int fd, struct map_session_data *sd, skillen = strlen (message); while (skill_names[idx].id != 0) { - if ((strnicmp (skill_names[idx].name, message, skillen) == 0) || - (strnicmp (skill_names[idx].desc, message, skillen) == 0)) + if ((strncasecmp (skill_names[idx].name, message, skillen) == 0) || + (strncasecmp (skill_names[idx].desc, message, skillen) == 0)) { char output[255]; sprintf (output, "skill %d: %s", skill_names[idx].id, @@ -8116,7 +8117,7 @@ atcommand_leaves (const int fd, struct map_session_data *sd, } /*========================================== - * + * *------------------------------------------ */ int atcommand_summon (const int fd, struct map_session_data *sd, @@ -8182,7 +8183,7 @@ atcommand_adjcmdlvl (const int fd, struct map_session_data *sd, } for (i = 0; atcommand_info[i].type != AtCommand_None; i++) - if (strcmpi (cmd, atcommand_info[i].command + 1) == 0) + if (strcasecmp (cmd, atcommand_info[i].command + 1) == 0) { atcommand_info[i].level = newlev; clif_displaymessage (fd, "@command level changed."); @@ -8230,7 +8231,7 @@ atcommand_adjgmlvl (const int fd, struct map_session_data *sd, * * Open a trade window with a remote player * - * If I have to jump to a remote player one more time, I am + * If I have to jump to a remote player one more time, I am * gonna scream! *------------------------------------------ */ diff --git a/src/map/battle.c b/src/map/battle.c index c9e341d..a6a803a 100644 --- a/src/map/battle.c +++ b/src/map/battle.c @@ -8,7 +8,6 @@ #include "../common/timer.h" #include "../common/nullpo.h" -#include "../common/malloc.h" #include "clif.h" #include "guild.h" @@ -1423,22 +1422,19 @@ struct battle_delay_damage_ int damage; int flag; }; -int battle_delay_damage_sub (int tid, unsigned int tick, int id, int data) +void battle_delay_damage_sub (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) { struct battle_delay_damage_ *dat = (struct battle_delay_damage_ *) data; if (dat && map_id2bl (id) == dat->src && dat->target->prev != NULL) battle_damage (dat->src, dat->target, dat->damage, dat->flag); free (dat); - return 0; } int battle_delay_damage (unsigned int tick, struct block_list *src, struct block_list *target, int damage, int flag) { - struct battle_delay_damage_ *dat = - (struct battle_delay_damage_ *) aCalloc (1, - sizeof (struct - battle_delay_damage_)); + struct battle_delay_damage_ *dat; + CREATE (dat, struct battle_delay_damage_, 1); nullpo_retr (0, src); nullpo_retr (0, target); @@ -5432,12 +5428,12 @@ int battle_check_range (struct block_list *src, struct block_list *bl, */ int battle_config_switch (const char *str) { - if (strcmpi (str, "on") == 0 || strcmpi (str, "yes") == 0 - || strcmpi (str, "oui") == 0 || strcmpi (str, "ja") == 0 - || strcmpi (str, "si") == 0) + if (strcasecmp (str, "on") == 0 || strcasecmp (str, "yes") == 0 + || strcasecmp (str, "oui") == 0 || strcasecmp (str, "ja") == 0 + || strcasecmp (str, "si") == 0) return 1; - if (strcmpi (str, "off") == 0 || strcmpi (str, "no") == 0 - || strcmpi (str, "non") == 0 || strcmpi (str, "nein") == 0) + if (strcasecmp (str, "off") == 0 || strcasecmp (str, "no") == 0 + || strcasecmp (str, "non") == 0 || strcasecmp (str, "nein") == 0) return 0; return atoi (str); } @@ -6118,10 +6114,10 @@ int battle_config_read (const char *cfgName) if (sscanf (line, "%[^:]:%s", w1, w2) != 2) continue; for (i = 0; i < sizeof (data) / (sizeof (data[0])); i++) - if (strcmpi (w1, data[i].str) == 0) + if (strcasecmp (w1, data[i].str) == 0) *data[i].val = battle_config_switch (w2); - if (strcmpi (w1, "import") == 0) + if (strcasecmp (w1, "import") == 0) battle_config_read (w2); } fclose_ (fp); @@ -6276,8 +6272,6 @@ int battle_config_read (const char *cfgName) if ((battle_config.packet_ver_flag & 63) == 0) // added by [Yor] battle_config.packet_ver_flag = 63; // accept all clients - add_timer_func_list (battle_delay_damage_sub, - "battle_delay_damage_sub"); } return 0; diff --git a/src/map/chat.c b/src/map/chat.c index 0163eed..00aadea 100644 --- a/src/map/chat.c +++ b/src/map/chat.c @@ -5,7 +5,6 @@ #include "../common/db.h" #include "../common/nullpo.h" -#include "../common/malloc.h" #include "map.h" #include "clif.h" #include "pc.h" @@ -29,7 +28,7 @@ int chat_createchat (struct map_session_data *sd, int limit, int pub, nullpo_retr (0, sd); - cd = aCalloc (1, sizeof (struct chat_data)); + cd = calloc (1, sizeof (struct chat_data)); cd->limit = limit; cd->pub = pub; @@ -280,7 +279,7 @@ int chat_createnpcchat (struct npc_data *nd, int limit, int pub, int trigger, nullpo_retr (1, nd); - cd = aCalloc (1, sizeof (struct chat_data)); + cd = calloc (1, sizeof (struct chat_data)); cd->limit = cd->trigger = limit; if (trigger > 0) diff --git a/src/map/chrif.c b/src/map/chrif.c index 8bbeb59..b80b4fd 100644 --- a/src/map/chrif.c +++ b/src/map/chrif.c @@ -1121,7 +1121,7 @@ void ladmin_itemfrob (int fd) * *------------------------------------------ */ -int chrif_parse (int fd) +void chrif_parse (int fd) { int packet_len, cmd; @@ -1138,7 +1138,7 @@ int chrif_parse (int fd) } close (fd); delete_session (fd); - return 0; + return; } while (RFIFOREST (fd) >= 2) @@ -1156,20 +1156,20 @@ int chrif_parse (int fd) if (r == 1) continue; // intifで処理した if (r == 2) - return 0; // intifで処理したが、データが足りない + return; // intifで処理したが、データが足りない session[fd]->eof = 1; - return 0; + return; } packet_len = packet_len_table[cmd - 0x2af8]; if (packet_len == -1) { if (RFIFOREST (fd) < 4) - return 0; + return; packet_len = RFIFOW (fd, 2); } if (RFIFOREST (fd) < packet_len) - return 0; + return; switch (cmd) { @@ -1235,12 +1235,10 @@ int chrif_parse (int fd) printf ("chrif_parse : unknown packet %d %d\n", fd, RFIFOW (fd, 0)); session[fd]->eof = 1; - return 0; + return; } RFIFOSKIP (fd, packet_len); } - - return 0; } /*========================================== @@ -1248,13 +1246,13 @@ int chrif_parse (int fd) * 今このmap鯖に繋がっているクライアント人数をchar鯖へ送る *------------------------------------------ */ -int send_users_tochar (int tid, unsigned int tick, int id, int data) +void send_users_tochar (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) { int users = 0, i; struct map_session_data *sd; if (char_fd <= 0 || session[char_fd] == NULL) - return 0; + return; WFIFOW (char_fd, 0) = 0x2aff; for (i = 0; i < fd_max; i++) @@ -1271,8 +1269,6 @@ int send_users_tochar (int tid, unsigned int tick, int id, int data) WFIFOW (char_fd, 2) = 6 + 4 * users; WFIFOW (char_fd, 4) = users; WFIFOSET (char_fd, 6 + 4 * users); - - return 0; } /*========================================== @@ -1280,21 +1276,19 @@ int send_users_tochar (int tid, unsigned int tick, int id, int data) * char鯖との接続を確認し、もし切れていたら再度接続する *------------------------------------------ */ -int check_connect_char_server (int tid, unsigned int tick, int id, int data) +void check_connect_char_server (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) { if (char_fd <= 0 || session[char_fd] == NULL) { printf ("Attempt to connect to char-server...\n"); chrif_state = 0; if ((char_fd = make_connection (char_ip, char_port)) < 0) - return 0; + return; session[char_fd]->func_parse = chrif_parse; realloc_fifo (char_fd, FIFOSIZE_SERVERLINK, FIFOSIZE_SERVERLINK); chrif_connect (char_fd); } - - return 0; } /*========================================== @@ -1303,9 +1297,8 @@ int check_connect_char_server (int tid, unsigned int tick, int id, int data) */ int do_init_chrif (void) { - add_timer_func_list (check_connect_char_server, - "check_connect_char_server"); - add_timer_func_list (send_users_tochar, "send_users_tochar"); +// add_timer_func_list (check_connect_char_server, "check_connect_char_server"); +// add_timer_func_list (send_users_tochar, "send_users_tochar"); add_timer_interval (gettick () + 1000, check_connect_char_server, 0, 0, 10 * 1000); add_timer_interval (gettick () + 1000, send_users_tochar, 0, 0, 5 * 1000); diff --git a/src/map/clif.c b/src/map/clif.c index d630815..8bbf112 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -20,10 +20,10 @@ #include "../common/socket.h" #include "../common/timer.h" -#include "../common/malloc.h" #include "../common/version.h" #include "../common/nullpo.h" #include "../common/md5calc.h" +#include "../common/mt_rand.h" #include "atcommand.h" #include "battle.h" @@ -755,15 +755,13 @@ int clif_clearchar (struct block_list *bl, int type) return 0; } -static int clif_clearchar_delay_sub (int tid, unsigned int tick, int id, - int data) +static void clif_clearchar_delay_sub (timer_id tid, tick_t tick, custom_id_t id, + custom_data_t data) { struct block_list *bl = (struct block_list *) id; clif_clearchar (bl, data); map_freeblock (bl); - - return 0; } int clif_clearchar_delay (unsigned int tick, struct block_list *bl, int type) @@ -775,7 +773,7 @@ int clif_clearchar_delay (unsigned int tick, struct block_list *bl, int type) exit (1); } memcpy (tmpbl, bl, sizeof (struct block_list)); - add_timer (tick, clif_clearchar_delay_sub, (int) tmpbl, type); + add_timer (tick, clif_clearchar_delay_sub, (custom_id_t) tmpbl, type); return 0; } @@ -1513,12 +1511,10 @@ void clif_quitsave (int fd, struct map_session_data *sd) * *------------------------------------------ */ -static int clif_waitclose (int tid, unsigned int tick, int id, int data) +static void clif_waitclose (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) { if (session[id]) session[id]->eof = 1; - - return 0; } /*========================================== @@ -5653,7 +5649,7 @@ int clif_combo_delay (struct block_list *bl, int wait) *白刃取り *------------------------------------------ */ -int clif_bladestop (struct block_list *src, struct block_list *dst, int bool) +int clif_bladestop (struct block_list *src, struct block_list *dst, int boolean) { unsigned char buf[32]; @@ -5663,7 +5659,7 @@ int clif_bladestop (struct block_list *src, struct block_list *dst, int bool) WBUFW (buf, 0) = 0x1d1; WBUFL (buf, 2) = src->id; WBUFL (buf, 6) = dst->id; - WBUFL (buf, 10) = bool; + WBUFL (buf, 10) = boolean; clif_send (buf, packet_len_table[0x1d1], src, AREA); @@ -8582,7 +8578,7 @@ void clif_parse_PartyMessage (int fd, struct map_session_data *sd) clif_displaymessage (fd, msg_txt (505)); return; } - + if (is_atcommand (fd, sd, message, 0) != AtCommand_None || (sd->sc_data && (sd->sc_data[SC_BERSERK].timer != -1 //バーサーク時は会話も不可 || sd->sc_data[SC_NOCHAT].timer != -1))) //チャット禁止 @@ -9907,7 +9903,7 @@ func_table clif_parse_func_table[0x220] = // *INDENT-ON* // Checks for packet flooding -int clif_check_packet_flood(fd, cmd) +int clif_check_packet_flood(int fd, int cmd) { struct map_session_data *sd = session[fd]->session_data; unsigned int rate, tick = gettick(); @@ -10025,7 +10021,7 @@ static char *clif_validate_chat (struct map_session_data *sd, int type, fd = sd->fd; msg_len = RFIFOW (fd, 2) - 4; name_len = strlen (sd->status.name); - /* + /* * At least one character is required in all instances. * Notes for length checks: * @@ -10063,9 +10059,9 @@ static char *clif_validate_chat (struct map_session_data *sd, int type, p = (char *) (type != 1) ? RFIFOP (fd, 4) : RFIFOP (fd, 28); buf_len = (type == 1) ? msg_len - min_len: msg_len; - /* + /* * The client attempted to exceed the maximum message length. - * + * * The conf suggests up to chat_maxline characters, after which the message * is truncated. But the previous behavior was to drop the message, so * we'll do that, too. @@ -10079,7 +10075,7 @@ static char *clif_validate_chat (struct map_session_data *sd, int type, /* We're leaving an extra eight bytes for public/global chat, 1 for NUL. */ buf_len += (type == 2) ? 8 + 1 : 1; - buf = (char *) aMalloc (buf_len); + buf = (char *) malloc (buf_len); memcpy ((type != 2) ? buf : buf + 8, p, (type != 2) ? buf_len - 1 : buf_len - 8 - 1); buf[buf_len - 1] = '\0'; @@ -10118,7 +10114,7 @@ static char *clif_validate_chat (struct map_session_data *sd, int type, * socket.cのdo_parsepacketから呼び出される *------------------------------------------ */ -static int clif_parse (int fd) +static void clif_parse (int fd) { int packet_len = 0, cmd = 0; struct map_session_data *sd = NULL; @@ -10158,11 +10154,11 @@ static int clif_parse (int fd) close (fd); if (fd) delete_session (fd); - return 0; + return; } if (RFIFOREST (fd) < 2) - return 0; // Too small (no packet number) + return; // Too small (no packet number) cmd = RFIFOW (fd, 0); @@ -10187,10 +10183,10 @@ static int clif_parse (int fd) session[fd]->eof = 1; break; } - return 0; + return; } else if (cmd >= 0x200) - return 0; + return; // パケット長を計算 packet_len = packet_len_table[cmd]; @@ -10198,19 +10194,19 @@ static int clif_parse (int fd) { if (RFIFOREST (fd) < 4) { - return 0; // Runt packet (variable length without a length sent) + return; // Runt packet (variable length without a length sent) } packet_len = RFIFOW (fd, 2); if (packet_len < 4 || packet_len > 32768) { session[fd]->eof = 1; - return 0; // Runt packet (variable out of bounds) + return; // Runt packet (variable out of bounds) } } if (RFIFOREST (fd) < packet_len) { - return 0; // Runt packet (sent legnth is too small) + return; // Runt packet (sent legnth is too small) } if (sd && sd->state.auth == 1 && sd->state.waitingdisconnect == 1) @@ -10223,7 +10219,7 @@ static int clif_parse (int fd) { // Flood triggered. Skip packet. RFIFOSKIP(sd->fd, packet_len); - return 0; + return; } clif_parse_func_table[cmd].func (fd, sd); @@ -10267,7 +10263,7 @@ static int clif_parse (int fd) { printf ("clif.c: cant write [%s] !!! data is lost !!!\n", packet_txt); - return 1; + return; } else { @@ -10306,8 +10302,6 @@ static int clif_parse (int fd) } } RFIFOSKIP (fd, packet_len); - - return 0; } /*========================================== @@ -10335,9 +10329,5 @@ int do_init_clif (void) exit (1); } - add_timer_func_list (clif_waitclose, "clif_waitclose"); - add_timer_func_list (clif_clearchar_delay_sub, - "clif_clearchar_delay_sub"); - return 0; } diff --git a/src/map/clif.h b/src/map/clif.h index a7da92d..d947f95 100644 --- a/src/map/clif.h +++ b/src/map/clif.h @@ -177,7 +177,7 @@ int clif_devotion (struct map_session_data *sd, int target); int clif_spiritball (struct map_session_data *sd); int clif_combo_delay (struct block_list *src, int wait); int clif_bladestop (struct block_list *src, struct block_list *dst, - int bool); + int boolean); int clif_changemapcell (int m, int x, int y, int cell_type, int type); int clif_status_change (struct block_list *bl, int type, int flag); diff --git a/src/map/guild.c b/src/map/guild.c index 4a7552a..6017b8e 100644 --- a/src/map/guild.c +++ b/src/map/guild.c @@ -9,7 +9,6 @@ #include "../common/timer.h" #include "../common/socket.h" #include "../common/nullpo.h" -#include "../common/malloc.h" #include "battle.h" #include "npc.h" #include "pc.h" @@ -72,8 +71,8 @@ int guild_checkskill (struct guild *g, int id) return g->skill[id - 10000].lv; } -int guild_payexp_timer (int tid, unsigned int tick, int id, int data); -int guild_gvg_eliminate_timer (int tid, unsigned int tick, int id, int data); +void guild_payexp_timer (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data); +void guild_gvg_eliminate_timer (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data); static int guild_read_castledb (void) { @@ -94,8 +93,7 @@ static int guild_read_castledb (void) if (line[0] == '/' && line[1] == '/') continue; memset (str, 0, sizeof (str)); - gc = (struct guild_castle *) aCalloc (1, - sizeof (struct guild_castle)); + CREATE (gc, struct guild_castle, 1); for (j = 0, p = line; j < 6 && p; j++) { str[j] = p; @@ -157,9 +155,6 @@ void do_init_guild (void) guild_read_castledb (); - add_timer_func_list (guild_gvg_eliminate_timer, - "guild_gvg_eliminate_timer"); - add_timer_func_list (guild_payexp_timer, "guild_payexp_timer"); add_timer_interval (gettick () + GUILD_PAYEXP_INVERVAL, guild_payexp_timer, 0, 0, GUILD_PAYEXP_INVERVAL); } @@ -170,15 +165,14 @@ struct guild *guild_search (int guild_id) return numdb_search (guild_db, guild_id); } -int guild_searchname_sub (void *key, void *data, va_list ap) +void guild_searchname_sub (db_key_t key, db_val_t data, va_list ap) { struct guild *g = (struct guild *) data, **dst; char *str; str = va_arg (ap, char *); dst = va_arg (ap, struct guild **); - if (strcmpi (g->name, str) == 0) + if (strcasecmp (g->name, str) == 0) *dst = g; - return 0; } // ギルド名検索 @@ -282,22 +276,22 @@ int guild_check_conflict (struct map_session_data *sd) } // ギルドのEXPキャッシュをinter鯖にフラッシュする -int guild_payexp_timer_sub (void *key, void *data, va_list ap) +void guild_payexp_timer_sub (db_key_t key, db_val_t data, va_list ap) { - int i, *dellist, *delp, dataid = (int) key; + int i, *dellist, *delp, dataid = key.i; struct guild_expcache *c; struct guild *g; - nullpo_retr (0, ap); - nullpo_retr (0, c = (struct guild_expcache *) data); - nullpo_retr (0, dellist = va_arg (ap, int *)); - nullpo_retr (0, delp = va_arg (ap, int *)); + nullpo_retv (ap); + nullpo_retv (c = (struct guild_expcache *) data); + nullpo_retv (dellist = va_arg (ap, int *)); + nullpo_retv (delp = va_arg (ap, int *)); if (*delp >= GUILD_PAYEXP_LIST || (g = guild_search (c->guild_id)) == NULL) - return 0; + return; if ((i = guild_getindex (g, c->account_id, 0 /*c->char_id*/)) < 0) - return 0; + return; g->member[i].exp += c->exp; intif_guild_change_memberinfo (g->guild_id, c->account_id, 0 /*char_id*/, @@ -307,10 +301,9 @@ int guild_payexp_timer_sub (void *key, void *data, va_list ap) dellist[(*delp)++] = dataid; free (c); - return 0; } -int guild_payexp_timer (int tid, unsigned int tick, int id, int data) +void guild_payexp_timer (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) { int dellist[GUILD_PAYEXP_LIST], delp = 0, i; numdb_foreach (guild_expcache_db, guild_payexp_timer_sub, dellist, &delp); @@ -318,7 +311,6 @@ int guild_payexp_timer (int tid, unsigned int tick, int id, int data) numdb_erase (guild_expcache_db, dellist[i]); // if(battle_config.etc_log) // printf("guild exp %d charactor's exp flushed !\n",delp); - return 0; } //------------------------------------------------------------------------ @@ -424,7 +416,7 @@ int guild_npc_request_info (int guild_id, const char *event) if (event == NULL || *event == 0) return guild_request_info (guild_id); - ev = (struct eventlist *) aCalloc (1, sizeof (struct eventlist)); + CREATE (ev, struct eventlist, 1); memcpy (ev->name, event, sizeof (ev->name)); ev->next = (struct eventlist *) numdb_search (guild_infoevent_db, guild_id); @@ -494,7 +486,7 @@ int guild_recv_info (struct guild *sg) if ((g = numdb_search (guild_db, sg->guild_id)) == NULL) { - g = (struct guild *) aCalloc (1, sizeof (struct guild)); + CREATE (g, struct guild, 1); numdb_insert (guild_db, sg->guild_id, g); before = *sg; @@ -1094,9 +1086,7 @@ int guild_payexp (struct map_session_data *sd, int exp) if ((c = numdb_search (guild_expcache_db, sd->status.account_id /*char_id*/)) == NULL) { - c = (struct guild_expcache *) aCalloc (1, - sizeof (struct - guild_expcache)); + CREATE (c, struct guild_expcache, 1); c->guild_id = sd->status.guild_id; c->account_id = sd->status.account_id; c->char_id = 0; @@ -1452,14 +1442,14 @@ int guild_allianceack (int guild_id1, int guild_id2, int account_id1, } // ギルド解散通知用 -int guild_broken_sub (void *key, void *data, va_list ap) +void guild_broken_sub (db_key_t key, db_val_t data, va_list ap) { struct guild *g = (struct guild *) data; int guild_id = va_arg (ap, int); int i, j; struct map_session_data *sd = NULL; - nullpo_retr (0, g); + nullpo_retv (g); for (i = 0; i < MAX_GUILDALLIANCE; i++) { // 関係を破棄 @@ -1472,7 +1462,6 @@ int guild_broken_sub (void *key, void *data, va_list ap) g->alliance[i].guild_id = 0; } } - return 0; } // ギルド解散通知 @@ -1548,7 +1537,7 @@ int guild_addcastleinfoevent (int castle_id, int index, const char *name) if (name == NULL || *name == 0) return 0; - ev = (struct eventlist *) aCalloc (1, sizeof (struct eventlist)); + CREATE (ev, struct eventlist, 1); memcpy (ev->name, name, sizeof (ev->name)); ev->next = numdb_search (guild_castleinfoevent_db, code); numdb_insert (guild_castleinfoevent_db, code, ev); @@ -1812,19 +1801,19 @@ int guild_agit_end (void) return 0; } -int guild_gvg_eliminate_timer (int tid, unsigned int tick, int id, int data) +void guild_gvg_eliminate_timer (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) { // Run One NPC_Event[OnAgitEliminate] size_t len = strlen ((const char *) data); - char *evname = (char *) aCalloc (len + 4, sizeof (char)); + char *evname; + CREATE (evname, char, len + 4); int c = 0; if (!agit_flag) - return 0; // Agit already End + return; // Agit already End memcpy (evname, (const char *) data, len - 5); strcpy (evname + len - 5, "Eliminate"); c = npc_event_do (evname); printf ("NPC_Event:[%s] Run (%d) Events.\n", evname, c); - return 0; } int guild_agit_break (struct mob_data *md) @@ -1833,7 +1822,7 @@ int guild_agit_break (struct mob_data *md) nullpo_retr (0, md); - evname = (char *) aCalloc (strlen (md->npc_event) + 1, sizeof (char)); + CREATE (evname, char, strlen (md->npc_event) + 1); strcpy (evname, md->npc_event); // Now By User to Run [OnAgitBreak] NPC Event... @@ -1891,40 +1880,32 @@ int guild_isallied (struct guild *g, struct guild_castle *gc) return 0; } -static int guild_db_final (void *key, void *data, va_list ap) +static void guild_db_final (db_key_t key, db_val_t data, va_list ap) { struct guild *g = data; free (g); - - return 0; } -static int castle_db_final (void *key, void *data, va_list ap) +static void castle_db_final (db_key_t key, db_val_t data, va_list ap) { struct guild_castle *gc = data; free (gc); - - return 0; } -static int guild_expcache_db_final (void *key, void *data, va_list ap) +static void guild_expcache_db_final (db_key_t key, db_val_t data, va_list ap) { struct guild_expcache *c = data; free (c); - - return 0; } -static int guild_infoevent_db_final (void *key, void *data, va_list ap) +static void guild_infoevent_db_final (db_key_t key, db_val_t data, va_list ap) { struct eventlist *ev = data; free (ev); - - return 0; } void do_final_guild (void) diff --git a/src/map/itemdb.c b/src/map/itemdb.c index dfa3d36..6557d43 100644 --- a/src/map/itemdb.c +++ b/src/map/itemdb.c @@ -6,13 +6,13 @@ #include "../common/db.h" #include "../common/grfio.h" #include "../common/nullpo.h" -#include "../common/malloc.h" #include "map.h" #include "battle.h" #include "itemdb.h" #include "script.h" #include "pc.h" #include "../common/socket.h" +#include "../common/mt_rand.h" #ifdef MEMWATCH #include "memwatch.h" @@ -49,17 +49,16 @@ void itemdb_reload (void); *------------------------------------------ */ // name = item alias, so we should find items aliases first. if not found then look for "jname" (full name) -int itemdb_searchname_sub (void *key, void *data, va_list ap) +void itemdb_searchname_sub (db_key_t key, db_val_t data, va_list ap) { struct item_data *item = (struct item_data *) data, **dst; char *str; str = va_arg (ap, char *); dst = va_arg (ap, struct item_data **); -// if( strcmpi(item->name,str)==0 || strcmp(item->jname,str)==0 || +// if( strcasecmp(item->name,str)==0 || strcmp(item->jname,str)==0 || // memcmp(item->name,str,24)==0 || memcmp(item->jname,str,24)==0 ) - if (strcmpi (item->name, str) == 0) //by lupus + if (strcasecmp (item->name, str) == 0) //by lupus *dst = item; - return 0; } /*========================================== @@ -72,7 +71,7 @@ int itemdb_searchjname_sub (void *key, void *data, va_list ap) char *str; str = va_arg (ap, char *); dst = va_arg (ap, struct item_data **); - if (strcmpi (item->jname, str) == 0) + if (strcasecmp (item->jname, str) == 0) *dst = item; return 0; } @@ -159,7 +158,7 @@ struct item_data *itemdb_search (int nameid) if (id) return id; - id = (struct item_data *) aCalloc (1, sizeof (struct item_data)); + id = (struct item_data *) calloc (1, sizeof (struct item_data)); numdb_insert (item_db, nameid, id); id->nameid = nameid; @@ -264,10 +263,9 @@ static int itemdb_read_itemslottable (void) char *buf, *p; int s; - buf = grfio_read ("data\\itemslottable.txt"); + buf = grfio_reads ("data\\itemslottable.txt", &s); if (buf == NULL) return -1; - s = grfio_size ("data\\itemslottable.txt"); buf[s] = 0; for (p = buf; p - buf < s;) { @@ -674,28 +672,26 @@ static int itemdb_read_noequip (void) * *------------------------------------------ */ -static int itemdb_final (void *key, void *data, va_list ap) +static void itemdb_final (db_key_t key, db_val_t data, va_list ap) { struct item_data *id; - nullpo_retr (0, id = data); + nullpo_retv (id = data); if (id->use_script) free (id->use_script); if (id->equip_script) free (id->equip_script); free (id); - - return 0; } void itemdb_reload (void) { /* - * + * * * itemdb_read(); - * + * */ do_init_itemdb (); diff --git a/src/map/magic-expr.c b/src/map/magic-expr.c index 18c293d..c3846e2 100644 --- a/src/map/magic-expr.c +++ b/src/map/magic-expr.c @@ -3,6 +3,8 @@ #include "itemdb.h" #include +#include "../common/mt_rand.h" + #define IS_SOLID(c) ((c) == 1 || (c) == 5) int map_is_solid (int m, int x, int y) @@ -180,7 +182,8 @@ static void intify (val_t * v) area_t *area_new (int ty) { - area_t *retval = (area_t *) aCalloc (sizeof (area_t), 1); + area_t *retval; + CREATE (retval, area_t, 1); retval->ty = ty; return retval; } diff --git a/src/map/magic-interpreter-base.c b/src/map/magic-interpreter-base.c index 9d21832..671f962 100644 --- a/src/map/magic-interpreter-base.c +++ b/src/map/magic-interpreter-base.c @@ -143,8 +143,9 @@ teleport_anchor_t *magic_find_anchor (char *name) static env_t *alloc_env (magic_conf_t * conf) { - env_t *env = (env_t *) aCalloc (sizeof (env_t), 1); - env->vars = (val_t *) aCalloc (sizeof (val_t), conf->vars_nr); + env_t *env; + CREATE (env, env_t, 1); + CREATE (env->vars, val_t, conf->vars_nr); env->base_env = conf; return env; } @@ -295,7 +296,7 @@ spellguard_can_satisfy (spellguard_check_t * check, character_t * caster, /* fprintf(stderr, "MC(%d/%s)? %d%d%d%d (%u <= %u)\n", caster->bl.id, caster->status.name, - retval, + retval, caster->cast_tick <= tick, check->mana <= caster->status.sp, check_prerequisites(caster, check->components), @@ -456,8 +457,8 @@ void spell_update_location (invocation_t * invocation) invocation_t *spell_instantiate (effect_set_t * effect_set, env_t * env) { - invocation_t *retval = - (invocation_t *) aCalloc (sizeof (invocation_t), 1); + invocation_t *retval; + CREATE (retval, invocation_t, 1); entity_t *caster; retval->env = env; diff --git a/src/map/magic-interpreter-parser.y b/src/map/magic-interpreter-parser.y index 8484902..c5ee41d 100644 --- a/src/map/magic-interpreter-parser.y +++ b/src/map/magic-interpreter-parser.y @@ -224,13 +224,13 @@ semicolons : /* empty */ proc_formals_list : /* empty */ - { $$ = aCalloc(sizeof(proc_t), 1); } + { CREATE ($$, proc_t, 1); } | proc_formals_list_ne { $$ = $1; } ; proc_formals_list_ne : ID - { $$ = aCalloc(sizeof(proc_t), 1); + { CREATE ($$, proc_t, 1); $$->args_nr = 1; $$->args = malloc(sizeof(int)); $$->args[0] = intern_id($1); @@ -414,7 +414,7 @@ arg_list : /* empty */ arg_list_ne : expr - { $$.args = aCalloc(sizeof(expr_t *), 1); + { CREATE($$.args, expr_t *, 1); $$.args_nr = 1; $$.args[0] = $1; } @@ -452,7 +452,7 @@ area : location spelldef : spellbody_list { $$ = new_spell($1); } | LET defs IN spellbody_list - { $$ = new_spell($4); + { $$ = new_spell($4); $$->letdefs_nr = $2.letdefs_nr; $$->letdefs = $2.letdefs; $$->spellguard = $4; @@ -693,7 +693,7 @@ effect_list : /* empty */ | effect semicolons effect_list { $$ = set_effect_continuation($1, $3); } ; - + %% @@ -743,7 +743,7 @@ add_spell(spell_t *spell, int line_nr) magic_conf.spells = realloc(magic_conf.spells, magic_conf.spells_nr * sizeof (spell_t*)); magic_conf.spells[index] = spell; - + } static void @@ -867,7 +867,7 @@ spellguard_implication(spellguard_t *a, spellguard_t *b) spellguard_implication(a->next, b); else a->next = b; - + return retval; } diff --git a/src/map/magic-interpreter.h b/src/map/magic-interpreter.h index 006c8fb..e9232bd 100644 --- a/src/map/magic-interpreter.h +++ b/src/map/magic-interpreter.h @@ -8,7 +8,6 @@ #include #include -#include "../common/malloc.h" #include "../common/nullpo.h" #include "battle.h" diff --git a/src/map/magic-stmt.c b/src/map/magic-stmt.c index b9833d6..4ae7e5d 100644 --- a/src/map/magic-stmt.c +++ b/src/map/magic-stmt.c @@ -64,8 +64,8 @@ static void clear_activation_record (cont_activation_record_t * ar) } } -static int -invocation_timer_callback (int _, unsigned int __, int id, int data) +static void +invocation_timer_callback (timer_id UNUSED, tick_t UNUSED, custom_id_t id, custom_data_t data) { invocation_t *invocation = (invocation_t *) map_id2bl (id); @@ -74,7 +74,6 @@ invocation_timer_callback (int _, unsigned int __, int id, int data) invocation->timer = 0; spell_execute (invocation); } - return 0; } static void clear_stack (invocation_t * invocation) @@ -224,12 +223,11 @@ static void char_update (character_t * character) character->bl.y); } -static int timer_callback_effect (int _, unsigned int __, int id, int data) +static void timer_callback_effect (timer_id UNUSED, tick_t UNUSED, custom_id_t id, custom_data_t data) { entity_t *target = map_id2bl (id); if (target) clif_misceffect (target, data); - return 0; } static void entity_effect (entity_t * entity, int effect_nr, int delay) @@ -247,14 +245,12 @@ void magic_unshroud (character_t * other_char) // entity_effect(&other_char->bl, MAGIC_EFFECT_REVEAL); } -static int -timer_callback_effect_npc_delete (int timer_id, unsigned int odelay, - int npc_id, int _) +static void +timer_callback_effect_npc_delete (timer_id UNUSED, tick_t odelay, + custom_id_t npc_id, custom_data_t UNUSED) { struct npc_data *effect_npc = (struct npc_data *) map_id2bl (npc_id); npc_free (effect_npc); - - return 0; } static struct npc_data *local_spell_effect (int m, int x, int y, int effect, @@ -370,15 +366,13 @@ static int op_message (env_t * env, int args_nr, val_t * args) return 0; } -static int -timer_callback_kill_npc (int timer_id, unsigned int odelay, int npc_id, - int data) +static void +timer_callback_kill_npc (timer_id UNUSED, tick_t odelay, custom_id_t npc_id, + custom_data_t data) { struct npc_data *npc = (struct npc_data *) map_id2bl (npc_id); if (npc) npc_free (npc); - - return 0; } static int op_messenger_npc (env_t * env, int args_nr, val_t * args) @@ -420,8 +414,8 @@ static void entity_warp (entity_t * target, int destm, int destx, int desty) // Warp part #1: update relevant data, interrupt trading etc.: pc_setpos (character, map_name, character->bl.x, character->bl.y, 0); // Warp part #2: now notify the client - clif_changemap (character, map_name, - character->bl.x, character->bl.y); + clif_changemap (character, map_name, + character->bl.x, character->bl.y); break; } case BL_MOB: @@ -1252,7 +1246,8 @@ static effect_t *run_call (invocation_t * invocation, cont_activation_record_t *ar; int args_nr = current->e.e_call.args_nr; int *formals = current->e.e_call.formals; - val_t *old_actuals = aCalloc (sizeof (val_t), args_nr); + val_t *old_actuals; + CREATE (old_actuals, val_t, args_nr); int i; ar = add_stack_entry (invocation, CONT_STACK_PROC, return_location); diff --git a/src/map/map.c b/src/map/map.c index e1adcef..8261e49 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -13,8 +13,7 @@ #include "../common/timer.h" #include "../common/db.h" #include "../common/grfio.h" -#include "../common/malloc.h" - +#include "../common/mt_rand.h" #include "map.h" #include "chrif.h" #include "clif.h" @@ -785,7 +784,7 @@ void map_foreachobject (int (*func) (struct block_list *, va_list), int type, * map.h内で#defineしてある *------------------------------------------ */ -int map_clearflooritem_timer (int tid, unsigned int tick, int id, int data) +void map_clearflooritem_timer (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) { struct flooritem_data *fitem = NULL; @@ -795,14 +794,12 @@ int map_clearflooritem_timer (int tid, unsigned int tick, int id, int data) { if (battle_config.error_log) printf ("map_clearflooritem_timer : error\n"); - return 1; + return; } if (data) delete_timer (fitem->cleartimer, map_clearflooritem_timer); clif_clearflooritem (fitem, 0); map_delobject (fitem->bl.id, BL_ITEM); - - return 0; } /*========================================== @@ -876,7 +873,7 @@ int map_addflooritem_any (struct item *item_data, int amount, int m, int x, return 0; r = mt_random (); - fitem = (struct flooritem_data *) aCalloc (1, sizeof (*fitem)); + CREATE (fitem, struct flooritem_data, 1); fitem->bl.type = BL_ITEM; fitem->bl.prev = fitem->bl.next = NULL; fitem->bl.m = m; @@ -1030,7 +1027,7 @@ void map_addchariddb (int charid, char *name) p = numdb_search (charid_db, charid); if (p == NULL) { // データベースにない - p = (struct charid2nick *) aCalloc (1, sizeof (struct charid2nick)); + CREATE (p, struct charid2nick, 1); p->req_id = 0; } else @@ -1061,7 +1058,7 @@ int map_reqchariddb (struct map_session_data *sd, int charid) p = numdb_search (charid_db, charid); if (p != NULL) // データベースにすでにある return 0; - p = (struct charid2nick *) aCalloc (1, sizeof (struct charid2nick)); + CREATE (p, struct charid2nick, 1); p->req_id = sd->bl.id; numdb_insert (charid_db, charid, p); return 0; @@ -1302,7 +1299,7 @@ struct map_session_data *map_nick2sd (char *nick) && pl_sd->state.auth) { // Without case sensitive check (increase the number of similar character names found) - if (strnicmp (pl_sd->status.name, nick, nicklen) == 0) + if (strncasecmp (pl_sd->status.name, nick, nicklen) == 0) { // Strict comparison (if found, we finish the function immediatly with correct value) if (strcmp (pl_sd->status.name, nick) == 0) @@ -1341,7 +1338,7 @@ struct block_list *map_id2bl (int id) * id_db内の全てにfuncを実行 *------------------------------------------ */ -int map_foreachiddb (int (*func) (void *, void *, va_list), ...) +int map_foreachiddb (db_func_t func, ...) { va_list ap = NULL; @@ -1573,10 +1570,7 @@ int map_setipport (char *name, unsigned long ip, int port) md = strdb_search (map_db, name); if (md == NULL) { // not exist -> add new data - mdos = - (struct map_data_other_server *) aCalloc (1, - sizeof (struct - map_data_other_server)); + CREATE (mdos, struct map_data_other_server, 1); memcpy (mdos->name, name, 24); mdos->gat = NULL; mdos->ip = ip; @@ -1609,7 +1603,7 @@ int map_setipport (char *name, unsigned long ip, int port) * 水場高さ設定 *------------------------------------------ */ -static struct +static struct Waterlist { char mapname[24]; int waterheight; @@ -1642,7 +1636,9 @@ static void map_readwater (char *watertxt) return; } if (waterlist == NULL) - waterlist = aCalloc (MAX_MAP_PER_SERVER, sizeof (*waterlist)); + { + CREATE (waterlist, struct Waterlist, MAX_MAP_PER_SERVER); + } while (fgets (line, 1020, fp) && n < MAX_MAP_PER_SERVER) { int wh, count; @@ -1777,7 +1773,8 @@ int map_readallmap (void) if (strstr (map[i].name, ".gat") == NULL) continue; sprintf (fn, "data\\%s", map[i].name); - if (grfio_size (fn) == -1) + // TODO - remove this, it is the last call to grfio_size, which is deprecated + if (!grfio_size (fn)) { map_delmap (map[i].name); maps_removed++; @@ -1825,7 +1822,7 @@ int map_readallmap (void) */ int map_addmap (char *mapname) { - if (strcmpi (mapname, "clear") == 0) + if (strcasecmp (mapname, "clear") == 0) { map_num = 0; return 0; @@ -1849,7 +1846,7 @@ int map_delmap (char *mapname) { int i; - if (strcmpi (mapname, "all") == 0) + if (strcasecmp (mapname, "all") == 0) { map_num = 0; return 0; @@ -1959,15 +1956,15 @@ int map_config_read (char *cfgName) continue; if (sscanf (line, "%[^:]: %[^\r\n]", w1, w2) == 2) { - if (strcmpi (w1, "userid") == 0) + if (strcasecmp (w1, "userid") == 0) { chrif_setuserid (w2); } - else if (strcmpi (w1, "passwd") == 0) + else if (strcasecmp (w1, "passwd") == 0) { chrif_setpasswd (w2); } - else if (strcmpi (w1, "char_ip") == 0) + else if (strcasecmp (w1, "char_ip") == 0) { h = gethostbyname (w2); if (h != NULL) @@ -1985,11 +1982,11 @@ int map_config_read (char *cfgName) } chrif_setip (w2); } - else if (strcmpi (w1, "char_port") == 0) + else if (strcasecmp (w1, "char_port") == 0) { chrif_setport (atoi (w2)); } - else if (strcmpi (w1, "map_ip") == 0) + else if (strcasecmp (w1, "map_ip") == 0) { h = gethostbyname (w2); if (h != NULL) @@ -2006,70 +2003,58 @@ int map_config_read (char *cfgName) } clif_setip (w2); } - else if (strcmpi (w1, "map_port") == 0) + else if (strcasecmp (w1, "map_port") == 0) { clif_setport (atoi (w2)); map_port = (atoi (w2)); } - else if (strcmpi (w1, "water_height") == 0) + else if (strcasecmp (w1, "water_height") == 0) { map_readwater (w2); } - else if (strcmpi (w1, "map") == 0) + else if (strcasecmp (w1, "map") == 0) { map_addmap (w2); } - else if (strcmpi (w1, "delmap") == 0) + else if (strcasecmp (w1, "delmap") == 0) { map_delmap (w2); } - else if (strcmpi (w1, "npc") == 0) + else if (strcasecmp (w1, "npc") == 0) { npc_addsrcfile (w2); } - else if (strcmpi (w1, "delnpc") == 0) + else if (strcasecmp (w1, "delnpc") == 0) { npc_delsrcfile (w2); } - else if (strcmpi (w1, "data_grf") == 0) - { - grfio_setdatafile (w2); - } - else if (strcmpi (w1, "sdata_grf") == 0) - { - grfio_setsdatafile (w2); - } - else if (strcmpi (w1, "adata_grf") == 0) - { - grfio_setadatafile (w2); - } - else if (strcmpi (w1, "autosave_time") == 0) + else if (strcasecmp (w1, "autosave_time") == 0) { autosave_interval = atoi (w2) * 1000; if (autosave_interval <= 0) autosave_interval = DEFAULT_AUTOSAVE_INTERVAL; } - else if (strcmpi (w1, "motd_txt") == 0) + else if (strcasecmp (w1, "motd_txt") == 0) { strcpy (motd_txt, w2); } - else if (strcmpi (w1, "help_txt") == 0) + else if (strcasecmp (w1, "help_txt") == 0) { strcpy (help_txt, w2); } - else if (strcmpi (w1, "mapreg_txt") == 0) + else if (strcasecmp (w1, "mapreg_txt") == 0) { strcpy (mapreg_txt, w2); } - else if (strcmpi (w1, "gm_log") == 0) + else if (strcasecmp (w1, "gm_log") == 0) { gm_logfile_name = strdup (w2); } - else if (strcmpi (w1, "log_file") == 0) + else if (strcasecmp (w1, "log_file") == 0) { map_set_logfile (w2); } - else if (strcmpi (w1, "import") == 0) + else if (strcasecmp (w1, "import") == 0) { map_config_read (w2); } @@ -2080,26 +2065,6 @@ int map_config_read (char *cfgName) return 0; } -int id_db_final (void *k, void *d, va_list ap) -{ - return 0; -} - -int map_db_final (void *k, void *d, va_list ap) -{ - return 0; -} - -int nick_db_final (void *k, void *d, va_list ap) -{ - return 0; -} - -int charid_db_final (void *k, void *d, va_list ap) -{ - return 0; -} - static int cleanup_sub (struct block_list *bl, va_list ap) { nullpo_retr (0, bl); @@ -2150,10 +2115,10 @@ void do_final (void) map_removenpc (); timer_final (); - numdb_final (id_db, id_db_final); - strdb_final (map_db, map_db_final); - strdb_final (nick_db, nick_db_final); - numdb_final (charid_db, charid_db_final); + numdb_final (id_db, NULL); + strdb_final (map_db, NULL); + strdb_final (nick_db, NULL); + numdb_final (charid_db, NULL); for (i = 0; i <= map_num; i++) { @@ -2190,6 +2155,10 @@ int compare_item (struct item *a, struct item *b) (a->card[2] == b->card[2]) && (a->card[3] == b->card[3])); } +// TODO move shutdown stuff here +void term_func (void) +{ +} /*====================================================== * Map-Server Init and Command-line Arguments [Valaris] *------------------------------------------------------ @@ -2203,7 +2172,6 @@ int do_init (int argc, char *argv[]) unsigned char *ATCOMMAND_CONF_FILENAME = "conf/atcommand_athena.conf"; unsigned char *SCRIPT_CONF_NAME = "conf/script_athena.conf"; unsigned char *MSG_CONF_NAME = "conf/msg_athena.conf"; - unsigned char *GRF_PATH_FILENAME = "conf/grf-files.txt"; for (i = 1; i < argc; i++) { @@ -2221,8 +2189,6 @@ int do_init (int argc, char *argv[]) SCRIPT_CONF_NAME = argv[i + 1]; else if (strcmp (argv[i], "--msg_config") == 0) MSG_CONF_NAME = argv[i + 1]; - else if (strcmp (argv[i], "--grf_path_file") == 0) - GRF_PATH_FILENAME = argv[i + 1]; } map_config_read (MAP_CONF_NAME); @@ -2238,12 +2204,9 @@ int do_init (int argc, char *argv[]) nick_db = strdb_init (24); charid_db = numdb_init (); - grfio_init (GRF_PATH_FILENAME); - map_readallmap (); - add_timer_func_list (map_clearflooritem_timer, - "map_clearflooritem_timer"); +// add_timer_func_list (map_clearflooritem_timer, "map_clearflooritem_timer"); do_init_chrif (); do_init_clif (); diff --git a/src/map/map.h b/src/map/map.h index a558397..5955418 100644 --- a/src/map/map.h +++ b/src/map/map.h @@ -8,6 +8,8 @@ #include #include #include "../common/mmo.h" +#include "../common/timer.h" +#include "../common/db.h" #ifndef MAX # define MAX(x,y) (((x)>(y)) ? (x) : (y)) @@ -762,7 +764,7 @@ void map_write_log (char *format, ...); #define MAP_LOG_PC(sd, fmt, args...) MAP_LOG("PC%d %d:%d,%d " fmt, sd->status.char_id, sd->bl.m, sd->bl.x, sd->bl.y, ## args) // 床アイテム関連 -int map_clearflooritem_timer (int, unsigned int, int, int); +void map_clearflooritem_timer (timer_id, tick_t, custom_id_t, custom_data_t); #define map_clearflooritem(id) map_clearflooritem_timer(0,0,id,1) int map_addflooritem_any (struct item *, int amount, int m, int x, int y, struct map_session_data **owners, @@ -787,7 +789,7 @@ int map_setipport (char *name, unsigned long ip, int port); int map_eraseipport (char *name, unsigned long ip, int port); void map_addiddb (struct block_list *); void map_deliddb (struct block_list *bl); -int map_foreachiddb (int (*)(void *, void *, va_list), ...); +int map_foreachiddb (db_func_t, ...); void map_addnickdb (struct map_session_data *); int map_scriptcont (struct map_session_data *sd, int id); /* Continues a script either on a spell or on an NPC */ struct map_session_data *map_nick2sd (char *); diff --git a/src/map/mob.c b/src/map/mob.c index 99d1cc2..3e3297d 100644 --- a/src/map/mob.c +++ b/src/map/mob.c @@ -9,7 +9,7 @@ #include "../common/socket.h" #include "../common/db.h" #include "../common/nullpo.h" -#include "../common/malloc.h" +#include "../common/mt_rand.h" #include "map.h" #include "clif.h" #include "intif.h" @@ -43,7 +43,7 @@ struct mob_db mob_db[2001]; */ static int distance (int, int, int, int); static int mob_makedummymobdb (int); -static int mob_timer (int, unsigned int, int, int); +static void mob_timer (timer_id, tick_t, custom_id_t, custom_data_t); int mobskill_use (struct mob_data *md, unsigned int tick, int event); int mobskill_deltimer (struct mob_data *md); int mob_skillid2skillidx (int class, int skillid); @@ -61,7 +61,7 @@ int mobdb_searchname (const char *str) for (i = 0; i < sizeof (mob_db) / sizeof (mob_db[0]); i++) { - if (strcmpi (mob_db[i].name, str) == 0 + if (strcasecmp (mob_db[i].name, str) == 0 || strcmp (mob_db[i].jname, str) == 0 || memcmp (mob_db[i].name, str, 24) == 0 || memcmp (mob_db[i].jname, str, 24) == 0) @@ -188,7 +188,7 @@ static void mob_mutate (struct mob_data *md, int stat, int intensity) // inten { int old_stat; int new_stat; - int real_intensity; // relative intensity + int real_intensity; // relative intensity const int mut_base = mutation_base[stat]; int sign = 1; @@ -399,11 +399,10 @@ int mob_once_spawn (struct map_session_data *sd, char *mapname, for (count = 0; count < amount; count++) { - md = (struct mob_data *) aCalloc (1, sizeof (struct mob_data)); - memset (md, '\0', sizeof *md); + md = (struct mob_data *) calloc (1, sizeof (struct mob_data)); if (mob_db[class].mode & 0x02) md->lootitem = - (struct item *) aCalloc (LOOTITEM_SIZE, sizeof (struct item)); + (struct item *) calloc (LOOTITEM_SIZE, sizeof (struct item)); else md->lootitem = NULL; @@ -1035,33 +1034,33 @@ int mob_changestate (struct mob_data *md, int state, int type) * It branches to a walk and an attack. *------------------------------------------ */ -static int mob_timer (int tid, unsigned int tick, int id, int data) +static void mob_timer (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) { struct mob_data *md; struct block_list *bl; if ((bl = map_id2bl (id)) == NULL) { //攻撃してきた敵がもういないのは正常のようだ - return 1; + return; } if (!bl || !bl->type || bl->type != BL_MOB) - return 1; + return; - nullpo_retr (1, md = (struct mob_data *) bl); + nullpo_retv (md = (struct mob_data *) bl); if (!md->bl.type || md->bl.type != BL_MOB) - return 1; + return; if (md->timer != tid) { if (battle_config.error_log == 1) printf ("mob_timer %d != %d\n", md->timer, tid); - return 0; + return; } md->timer = -1; if (md->bl.prev == NULL || md->state.state == MS_DEAD) - return 1; + return; map_freeblock_lock (); switch (md->state.state) @@ -1082,7 +1081,7 @@ static int mob_timer (int tid, unsigned int tick, int id, int data) break; } map_freeblock_unlock (); - return 0; + return; } /*========================================== @@ -1141,10 +1140,9 @@ int mob_walktoxy (struct mob_data *md, int x, int y, int easy) * mob spawn with delay (timer function) *------------------------------------------ */ -static int mob_delayspawn (int tid, unsigned int tick, int m, int n) +static void mob_delayspawn (timer_id tid, tick_t tick, custom_id_t m, custom_data_t n) { mob_spawn (m); - return 0; } /*========================================== @@ -2311,44 +2309,42 @@ static int mob_ai_sub_foreachclient (struct map_session_data *sd, va_list ap) * Serious processing for mob in PC field of view (interval timer function) *------------------------------------------ */ -static int mob_ai_hard (int tid, unsigned int tick, int id, int data) +static void mob_ai_hard (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) { clif_foreachclient (mob_ai_sub_foreachclient, tick); - - return 0; } /*========================================== * Negligent mode MOB AI (PC is not in near) *------------------------------------------ */ -static int mob_ai_sub_lazy (void *key, void *data, va_list app) +static void mob_ai_sub_lazy (db_key_t key, db_val_t data, va_list app) { struct mob_data *md = data; unsigned int tick; va_list ap; - nullpo_retr (0, md); - nullpo_retr (0, app); - nullpo_retr (0, ap = va_arg (app, va_list)); + nullpo_retv (md); + nullpo_retv (app); + nullpo_retv (ap = va_arg (app, va_list)); if (md == NULL) - return 0; + return; if (!md->bl.type || md->bl.type != BL_MOB) - return 0; + return; tick = va_arg (ap, unsigned int); if (DIFF_TICK (tick, md->last_thinktime) < MIN_MOBTHINKTIME * 10) - return 0; + return; md->last_thinktime = tick; if (md->bl.prev == NULL || md->skilltimer != -1) { if (DIFF_TICK (tick, md->next_walktime) > MIN_MOBTHINKTIME * 10) md->next_walktime = tick; - return 0; + return; } if (DIFF_TICK (md->next_walktime, tick) < 0 && @@ -2383,18 +2379,15 @@ static int mob_ai_sub_lazy (void *key, void *data, va_list app) md->next_walktime = tick + MPRAND (5000, 10000); } - return 0; } /*========================================== * Negligent processing for mob outside PC field of view (interval timer function) *------------------------------------------ */ -static int mob_ai_lazy (int tid, unsigned int tick, int id, int data) +static void mob_ai_lazy (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) { map_foreachiddb (mob_ai_sub_lazy, tick); - - return 0; } /*========================================== @@ -2421,13 +2414,13 @@ struct delay_item_drop2 * item drop with delay (timer function) *------------------------------------------ */ -static int mob_delay_item_drop (int tid, unsigned int tick, int id, int data) +static void mob_delay_item_drop (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) { struct delay_item_drop *ditem; struct item temp_item; int flag; - nullpo_retr (0, ditem = (struct delay_item_drop *) id); + nullpo_retv (ditem = (struct delay_item_drop *) id); memset (&temp_item, 0, sizeof (temp_item)); temp_item.nameid = ditem->nameid; @@ -2446,26 +2439,25 @@ static int mob_delay_item_drop (int tid, unsigned int tick, int id, int data) ditem->third_sd, 0); } free (ditem); - return 0; + return; } map_addflooritem (&temp_item, 1, ditem->m, ditem->x, ditem->y, ditem->first_sd, ditem->second_sd, ditem->third_sd, 0); free (ditem); - return 0; } /*========================================== * item drop (timer function)-lootitem with delay *------------------------------------------ */ -static int mob_delay_item_drop2 (int tid, unsigned int tick, int id, int data) +static void mob_delay_item_drop2 (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) { struct delay_item_drop2 *ditem; int flag; - nullpo_retr (0, ditem = (struct delay_item_drop2 *) id); + nullpo_retv (ditem = (struct delay_item_drop2 *) id); if (battle_config.item_auto_get == 1) { @@ -2480,7 +2472,7 @@ static int mob_delay_item_drop2 (int tid, unsigned int tick, int id, int data) ditem->second_sd, ditem->third_sd, 0); } free (ditem); - return 0; + return; } map_addflooritem (&ditem->item_data, ditem->item_data.amount, ditem->m, @@ -2488,7 +2480,6 @@ static int mob_delay_item_drop2 (int tid, unsigned int tick, int id, int data) ditem->third_sd, 0); free (ditem); - return 0; } /*========================================== @@ -2524,16 +2515,15 @@ int mob_catch_delete (struct mob_data *md, int type) return 0; } -int mob_timer_delete (int tid, unsigned int tick, int id, int data) +void mob_timer_delete (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) { struct block_list *bl = map_id2bl (id); struct mob_data *md; - nullpo_retr (0, bl); + nullpo_retv (bl); md = (struct mob_data *) bl; mob_catch_delete (md, 3); - return 0; } /*========================================== @@ -3009,10 +2999,8 @@ int mob_damage (struct block_list *src, struct mob_data *md, int damage, if (drop_rate <= MRAND (10000)) continue; - ditem = - (struct delay_item_drop *) aCalloc (1, - sizeof (struct - delay_item_drop)); + ditem = (struct delay_item_drop *) + calloc (1, sizeof (struct delay_item_drop)); ditem->nameid = mob_db[md->class].dropitem[i].nameid; ditem->amount = 1; ditem->m = md->bl.m; @@ -3021,8 +3009,7 @@ int mob_damage (struct block_list *src, struct mob_data *md, int damage, ditem->first_sd = mvp_sd; ditem->second_sd = second_sd; ditem->third_sd = third_sd; - add_timer (tick + 500 + i, mob_delay_item_drop, (int) ditem, - 0); + add_timer (tick + 500 + i, mob_delay_item_drop, (int) ditem, 0); } if (sd && sd->state.attack_type == BF_WEAPON) { @@ -3041,10 +3028,8 @@ int mob_damage (struct block_list *src, struct mob_data *md, int damage, if (sd->monster_drop_itemrate[i] <= MRAND (10000)) continue; - ditem = - (struct delay_item_drop *) aCalloc (1, - sizeof (struct - delay_item_drop)); + ditem = (struct delay_item_drop *) + calloc (1, sizeof (struct delay_item_drop)); ditem->nameid = sd->monster_drop_itemid[i]; ditem->amount = 1; ditem->m = md->bl.m; @@ -3068,10 +3053,8 @@ int mob_damage (struct block_list *src, struct mob_data *md, int damage, { struct delay_item_drop2 *ditem; - ditem = - (struct delay_item_drop2 *) aCalloc (1, - sizeof (struct - delay_item_drop2)); + ditem = (struct delay_item_drop2 *) + calloc (1, sizeof (struct delay_item_drop2)); memcpy (&ditem->item_data, &md->lootitem[i], sizeof (md->lootitem[0])); ditem->m = md->bl.m; @@ -3252,8 +3235,8 @@ int mob_class_change (struct mob_data *md, int *value) md->skilllv = 0; if (md->lootitem == NULL && mob_db[class].mode & 0x02) - md->lootitem = - (struct item *) aCalloc (LOOTITEM_SIZE, sizeof (struct item)); + md->lootitem = (struct item *) + calloc (LOOTITEM_SIZE, sizeof (struct item)); skill_clear_unitgroup (&md->bl); skill_cleartimerskill (&md->bl); @@ -3487,11 +3470,10 @@ int mob_summonslave (struct mob_data *md2, int *value, int amount, int flag) for (; amount > 0; amount--) { int x = 0, y = 0, c = 0, i = 0; - md = (struct mob_data *) aCalloc (1, sizeof (struct mob_data)); + md = (struct mob_data *) calloc (1, sizeof (struct mob_data)); if (mob_db[class].mode & 0x02) - md->lootitem = - (struct item *) aCalloc (LOOTITEM_SIZE, - sizeof (struct item)); + md->lootitem = (struct item *) + calloc (LOOTITEM_SIZE, sizeof (struct item)); else md->lootitem = NULL; @@ -3620,7 +3602,7 @@ int mob_skillid2skillidx (int class, int skillid) * スキル使用(詠唱完了、ID指定) *------------------------------------------ */ -int mobskill_castend_id (int tid, unsigned int tick, int id, int data) +void mobskill_castend_id (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) { struct mob_data *md = NULL; struct block_list *bl; @@ -3628,16 +3610,16 @@ int mobskill_castend_id (int tid, unsigned int tick, int id, int data) int range; if ((mbl = map_id2bl (id)) == NULL) //詠唱したMobがもういないというのは良くある正常処理 - return 0; + return; if ((md = (struct mob_data *) mbl) == NULL) { printf ("mobskill_castend_id nullpo mbl->id:%d\n", mbl->id); - return 0; + return; } if (md->bl.type != BL_MOB || md->bl.prev == NULL) - return 0; + return; if (md->skilltimer != tid) // タイマIDの確認 - return 0; + return; md->skilltimer = -1; //沈黙や状態異常など @@ -3646,13 +3628,13 @@ int mobskill_castend_id (int tid, unsigned int tick, int id, int data) if (md->opt1 > 0 || md->sc_data[SC_DIVINA].timer != -1 || md->sc_data[SC_ROKISWEIL].timer != -1 || md->sc_data[SC_STEELBODY].timer != -1) - return 0; + return; if (md->sc_data[SC_AUTOCOUNTER].timer != -1 && md->skillid != KN_AUTOCOUNTER) //オートカウンター - return 0; + return; if (md->sc_data[SC_BLADESTOP].timer != -1) //白刃取り - return 0; + return; if (md->sc_data[SC_BERSERK].timer != -1) //バーサーク - return 0; + return; } if (md->skillid != NPC_EMOTION) md->last_thinktime = tick + battle_get_adelay (&md->bl); @@ -3660,10 +3642,10 @@ int mobskill_castend_id (int tid, unsigned int tick, int id, int data) if ((bl = map_id2bl (md->skilltarget)) == NULL || bl->prev == NULL) { //スキルターゲットが存在しない //printf("mobskill_castend_id nullpo\n");//ターゲットがいないときはnullpoじゃなくて普通に終了 - return 0; + return; } if (md->bl.m != bl->m) - return 0; + return; if (md->skillid == PR_LEXAETERNA) { @@ -3672,7 +3654,7 @@ int mobskill_castend_id (int tid, unsigned int tick, int id, int data) && (sc_data[SC_FREEZE].timer != -1 || (sc_data[SC_STONE].timer != -1 && sc_data[SC_STONE].val2 == 0))) - return 0; + return; } else if (md->skillid == RG_BACKSTAP) { @@ -3680,17 +3662,17 @@ int mobskill_castend_id (int tid, unsigned int tick, int id, int data) battle_get_dir (bl); int dist = distance (md->bl.x, md->bl.y, bl->x, bl->y); if (bl->type != BL_SKILL && (dist == 0 || map_check_dir (dir, t_dir))) - return 0; + return; } if (((skill_get_inf (md->skillid) & 1) || (skill_get_inf2 (md->skillid) & 4)) && // 彼我敵対関係チェック battle_check_target (&md->bl, bl, BCT_ENEMY) <= 0) - return 0; + return; range = skill_get_range (md->skillid, md->skilllv); if (range < 0) range = battle_get_range (&md->bl) - (range + 1); if (range + battle_config.mob_skill_add_range < distance (md->bl.x, md->bl.y, bl->x, bl->y)) - return 0; + return; md->skilldelay[md->skillidx] = tick; @@ -3720,15 +3702,13 @@ int mobskill_castend_id (int tid, unsigned int tick, int id, int data) md->skilllv, tick, 0); break; } - - return 0; } /*========================================== * スキル使用(詠唱完了、場所指定) *------------------------------------------ */ -int mobskill_castend_pos (int tid, unsigned int tick, int id, int data) +void mobskill_castend_pos (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) { struct mob_data *md = NULL; struct block_list *bl; @@ -3736,15 +3716,15 @@ int mobskill_castend_pos (int tid, unsigned int tick, int id, int data) //mobskill_castend_id同様詠唱したMobが詠唱完了時にもういないというのはありそうなのでnullpoから除外 if ((bl = map_id2bl (id)) == NULL) - return 0; + return; - nullpo_retr (0, md = (struct mob_data *) bl); + nullpo_retv (md = (struct mob_data *) bl); if (md->bl.type != BL_MOB || md->bl.prev == NULL) - return 0; + return; if (md->skilltimer != tid) // タイマIDの確認 - return 0; + return; md->skilltimer = -1; if (md->sc_data) @@ -3752,13 +3732,13 @@ int mobskill_castend_pos (int tid, unsigned int tick, int id, int data) if (md->opt1 > 0 || md->sc_data[SC_DIVINA].timer != -1 || md->sc_data[SC_ROKISWEIL].timer != -1 || md->sc_data[SC_STEELBODY].timer != -1) - return 0; + return; if (md->sc_data[SC_AUTOCOUNTER].timer != -1 && md->skillid != KN_AUTOCOUNTER) //オートカウンター - return 0; + return; if (md->sc_data[SC_BLADESTOP].timer != -1) //白刃取り - return 0; + return; if (md->sc_data[SC_BERSERK].timer != -1) //バーサーク - return 0; + return; } if (battle_config.monster_skill_reiteration == 0) @@ -3789,7 +3769,7 @@ int mobskill_castend_pos (int tid, unsigned int tick, int id, int data) { if (skill_check_unit_range (md->bl.m, md->skillx, md->skilly, range, md->skillid) > 0) - return 0; + return; } } if (battle_config.monster_skill_nofootset == 1) @@ -3819,7 +3799,7 @@ int mobskill_castend_pos (int tid, unsigned int tick, int id, int data) { if (skill_check_unit_range2 (md->bl.m, md->skillx, md->skilly, range) > 0) - return 0; + return; } } @@ -3836,7 +3816,7 @@ int mobskill_castend_pos (int tid, unsigned int tick, int id, int data) c++; } if (c >= maxcount) - return 0; + return; } } @@ -3845,7 +3825,7 @@ int mobskill_castend_pos (int tid, unsigned int tick, int id, int data) range = battle_get_range (&md->bl) - (range + 1); if (range + battle_config.mob_skill_add_range < distance (md->bl.x, md->bl.y, md->skillx, md->skilly)) - return 0; + return; md->skilldelay[md->skillidx] = tick; if (battle_config.mob_skill_log == 1) @@ -3856,7 +3836,7 @@ int mobskill_castend_pos (int tid, unsigned int tick, int id, int data) skill_castend_pos2 (&md->bl, md->skillx, md->skilly, md->skillid, md->skilllv, tick, 0); - return 0; + return; } /*========================================== @@ -4292,7 +4272,7 @@ int mobskill_use (struct mob_data *md, unsigned int tick, int event) if (ms[i].target == MST_MASTER) { bl = &md->bl; - if (md->master_id) + if (md->master_id) bl = map_id2bl (md->master_id); } else @@ -5048,10 +5028,10 @@ static int mob_readskilldb (void) void mob_reload (void) { /* - * + * * * mob_read(); - * + * */ do_init_mob (); @@ -5069,15 +5049,6 @@ int do_init_mob (void) mob_read_randommonster (); mob_readskilldb (); - add_timer_func_list (mob_timer, "mob_timer"); - add_timer_func_list (mob_delayspawn, "mob_delayspawn"); - add_timer_func_list (mob_delay_item_drop, "mob_delay_item_drop"); - add_timer_func_list (mob_delay_item_drop2, "mob_delay_item_drop2"); - add_timer_func_list (mob_ai_hard, "mob_ai_hard"); - add_timer_func_list (mob_ai_lazy, "mob_ai_lazy"); - add_timer_func_list (mobskill_castend_id, "mobskill_castend_id"); - add_timer_func_list (mobskill_castend_pos, "mobskill_castend_pos"); - add_timer_func_list (mob_timer_delete, "mob_timer_delete"); add_timer_interval (gettick () + MIN_MOBTHINKTIME, mob_ai_hard, 0, 0, MIN_MOBTHINKTIME); add_timer_interval (gettick () + MIN_MOBTHINKTIME * 10, mob_ai_lazy, 0, 0, diff --git a/src/map/mob.h b/src/map/mob.h index 2463283..aff305b 100644 --- a/src/map/mob.h +++ b/src/map/mob.h @@ -1,7 +1,7 @@ // $Id: mob.h,v 1.4 2004/09/25 05:32:18 MouseJstr Exp $ #ifndef _MOB_H_ #define _MOB_H_ - +#include "../common/timer.h" #define MAX_RANDOMMONSTER 3 struct mob_skill @@ -129,7 +129,7 @@ int do_init_mob (void); int mob_delete (struct mob_data *md); int mob_catch_delete (struct mob_data *md, int type); -int mob_timer_delete (int tid, unsigned int tick, int id, int data); +void mob_timer_delete (timer_id, tick_t, custom_id_t, custom_data_t); int mob_deleteslave (struct mob_data *md); @@ -141,8 +141,8 @@ int mob_warp (struct mob_data *md, int m, int x, int y, int type); int mobskill_use (struct mob_data *md, unsigned int tick, int event); int mobskill_event (struct mob_data *md, int flag); -int mobskill_castend_id (int tid, unsigned int tick, int id, int data); -int mobskill_castend_pos (int tid, unsigned int tick, int id, int data); +void mobskill_castend_id (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data); +void mobskill_castend_pos (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data); int mob_summonslave (struct mob_data *md2, int *value, int amount, int flag); int mob_gvmobcheck (struct map_session_data *sd, struct block_list *bl); diff --git a/src/map/npc.c b/src/map/npc.c index 5fd8291..54b13d8 100644 --- a/src/map/npc.c +++ b/src/map/npc.c @@ -6,7 +6,6 @@ #include #include -#include "../common/malloc.h" #include "../common/nullpo.h" #include "../common/timer.h" @@ -63,7 +62,7 @@ int npc_enable_sub (struct block_list *bl, va_list ap) { struct map_session_data *sd; struct npc_data *nd; - char *name = (char *) aCalloc (50, sizeof (char)); + char *name = (char *) calloc (50, sizeof (char)); nullpo_retr (0, bl); nullpo_retr (0, ap); @@ -173,15 +172,14 @@ int npc_delete (struct npc_data *nd) * イベントの遅延実行 *------------------------------------------ */ -int npc_event_timer (int tid, unsigned int tick, int id, int data) +void npc_event_timer (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) { struct map_session_data *sd = map_id2sd (id); if (sd == NULL) - return 0; + return; npc_event (sd, (const char *) data, 0); free ((void *) data); - return 0; } int npc_timer_event (const char *eventname) // Added by RoVeRT @@ -294,18 +292,18 @@ int npc_event_export (void *key, void *data, va_list ap) * 全てのNPCのOn*イベント実行 *------------------------------------------ */ -int npc_event_doall_sub (void *key, void *data, va_list ap) +void npc_event_doall_sub (db_key_t key, db_val_t data, va_list ap) { - char *p = (char *) key; + const char *p = key.s; int rid, argc; argrec_t *argv; struct event_data *ev; int *c; const char *name; - nullpo_retr (0, ev = (struct event_data *) data); - nullpo_retr (0, ap); - nullpo_retr (0, c = va_arg (ap, int *)); + nullpo_retv (ev = (struct event_data *) data); + nullpo_retv (ap); + nullpo_retv (c = va_arg (ap, int *)); name = va_arg (ap, const char *); rid = va_arg (ap, int); @@ -318,8 +316,6 @@ int npc_event_doall_sub (void *key, void *data, va_list ap) argv); (*c)++; } - - return 0; } int npc_event_doall_l (const char *name, int rid, int argc, argrec_t * args) @@ -333,18 +329,18 @@ int npc_event_doall_l (const char *name, int rid, int argc, argrec_t * args) return c; } -int npc_event_do_sub (void *key, void *data, va_list ap) +void npc_event_do_sub (db_key_t key, db_val_t data, va_list ap) { - char *p = (char *) key; + const char *p = key.s; struct event_data *ev; int *c; const char *name; int rid, argc; argrec_t *argv; - nullpo_retr (0, ev = (struct event_data *) data); - nullpo_retr (0, ap); - nullpo_retr (0, c = va_arg (ap, int *)); + nullpo_retv (ev = (struct event_data *) data); + nullpo_retv (ap); + nullpo_retv (c = va_arg (ap, int *)); name = va_arg (ap, const char *); rid = va_arg (ap, int); @@ -357,8 +353,6 @@ int npc_event_do_sub (void *key, void *data, va_list ap) argv); (*c)++; } - - return 0; } int npc_event_do_l (const char *name, int rid, int argc, argrec_t * args) @@ -378,7 +372,7 @@ int npc_event_do_l (const char *name, int rid, int argc, argrec_t * args) * 時計イベント実行 *------------------------------------------ */ -int npc_event_do_clock (int tid, unsigned int tick, int id, int data) +void npc_event_do_clock (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) { time_t timer; struct tm *t; @@ -406,7 +400,6 @@ int npc_event_do_clock (int tid, unsigned int tick, int id, int data) c += npc_event_doall (buf); } memcpy (&ev_tm_b, t, sizeof (ev_tm_b)); - return c; } /*========================================== @@ -482,9 +475,9 @@ int npc_cleareventtimer (struct npc_data *nd) return 0; } -int npc_do_ontimer_sub (void *key, void *data, va_list ap) +void npc_do_ontimer_sub (db_key_t key, db_val_t data, va_list ap) { - char *p = (char *) key; + const char *p = key.s; struct event_data *ev = (struct event_data *) data; int *c = va_arg (ap, int *); // struct map_session_data *sd=va_arg(ap,struct map_session_data *); @@ -511,7 +504,6 @@ int npc_do_ontimer_sub (void *key, void *data, va_list ap) npc_deleventtimer (ev->nd, event); } } - return 0; } int npc_do_ontimer (int npc_id, struct map_session_data *sd, int option) @@ -567,7 +559,7 @@ int npc_timerevent_import (void *key, void *data, va_list ap) * タイマーイベント実行 *------------------------------------------ */ -int npc_timerevent (int tid, unsigned int tick, int id, int data) +void npc_timerevent (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) { int next, t; struct npc_data *nd = (struct npc_data *) map_id2bl (id); @@ -575,7 +567,7 @@ int npc_timerevent (int tid, unsigned int tick, int id, int data) if (nd == NULL || nd->u.scr.nexttimer < 0) { printf ("npc_timerevent: ??\n"); - return 0; + return; } nd->u.scr.timertick = tick; te = nd->u.scr.timer_event + nd->u.scr.nexttimer; @@ -590,7 +582,6 @@ int npc_timerevent (int tid, unsigned int tick, int id, int data) } run_script (nd->u.scr.script, te->pos, 0, nd->bl.id); - return 0; } /*========================================== @@ -770,9 +761,9 @@ int npc_event (struct map_session_data *sd, const char *eventname, return 0; } -int npc_command_sub (void *key, void *data, va_list ap) +void npc_command_sub (db_key_t key, db_val_t data, va_list ap) { - char *p = (char *) key; + const char *p = key.s; struct event_data *ev = (struct event_data *) data; char *npcname = va_arg (ap, char *); char *command = va_arg (ap, char *); @@ -786,8 +777,6 @@ int npc_command_sub (void *key, void *data, va_list ap) if (strcmp (command, temp) == 0) run_script (ev->nd->u.scr.script, ev->pos, 0, ev->nd->bl.id); } - - return 0; } int npc_command (struct map_session_data *sd, char *npcname, char *command) @@ -858,7 +847,7 @@ int npc_touch_areanpc (struct map_session_data *sd, int m, int x, int y) case MESSAGE: case SCRIPT: { - char *name = (char *) aCalloc (50, sizeof (char)); + char *name = calloc (50, 1); memcpy (name, map[m].npc[i]->name, 50); if (sd->areanpc_id == map[m].npc[i]->bl.id) @@ -1235,14 +1224,14 @@ void npc_addsrcfile (char *name) struct npc_src_list *new; size_t len; - if (strcmpi (name, "clear") == 0) + if (strcasecmp (name, "clear") == 0) { npc_clearsrcfile (); return; } len = sizeof (*new) + strlen (name); - new = (struct npc_src_list *) aCalloc (1, len); + new = (struct npc_src_list *) calloc (1, len); new->next = NULL; strncpy (new->name, name, strlen (name) + 1); if (npc_src_first == NULL) @@ -1261,7 +1250,7 @@ void npc_delsrcfile (char *name) { struct npc_src_list *p = npc_src_first, *pp = NULL, **lp = &npc_src_first; - if (strcmpi (name, "all") == 0) + if (strcasecmp (name, "all") == 0) { npc_clearsrcfile (); return; @@ -1302,7 +1291,7 @@ int npc_parse_warp (char *w1, char *w2, char *w3, char *w4) m = map_mapname2mapid (mapname); - nd = (struct npc_data *) aCalloc (1, sizeof (struct npc_data)); + nd = (struct npc_data *) calloc (1, sizeof (struct npc_data)); nd->bl.id = npc_get_new_npc_id (); nd->n = map_addnpc (m, nd); @@ -1377,7 +1366,7 @@ static int npc_parse_shop (char *w1, char *w2, char *w3, char *w4) } m = map_mapname2mapid (mapname); - nd = (struct npc_data *) aCalloc (1, sizeof (struct npc_data) + + nd = (struct npc_data *) calloc (1, sizeof (struct npc_data) + sizeof (nd->u.shop_item[0]) * (max + 1)); p = strchr (w4, ','); @@ -1440,9 +1429,8 @@ static int npc_parse_shop (char *w1, char *w2, char *w3, char *w4) nd->opt2 = 0; nd->opt3 = 0; - nd = (struct npc_data *) aRealloc (nd, - sizeof (struct npc_data) + - sizeof (nd->u.shop_item[0]) * pos); + nd = (struct npc_data *) + realloc (nd, sizeof (struct npc_data) + sizeof (nd->u.shop_item[0]) * pos); //printf("shop npc %s %d read done\n",mapname,nd->bl.id); npc_shop++; @@ -1460,33 +1448,29 @@ static int npc_parse_shop (char *w1, char *w2, char *w3, char *w4) * NPCのラベルデータコンバート *------------------------------------------ */ -int npc_convertlabel_db (void *key, void *data, va_list ap) +void npc_convertlabel_db (db_key_t key, db_val_t data, va_list ap) { - char *lname = (char *) key; + const char *lname = key.s; int pos = (int) data; struct npc_data *nd; struct npc_label_list *lst; int num; char *p = strchr (lname, ':'); - nullpo_retr (0, ap); - nullpo_retr (0, nd = va_arg (ap, struct npc_data *)); + nullpo_retv (ap); + nullpo_retv (nd = va_arg (ap, struct npc_data *)); lst = nd->u.scr.label_list; num = nd->u.scr.label_list_num; if (!lst) { - lst = - (struct npc_label_list *) aCalloc (1, - sizeof (struct - npc_label_list)); + lst = (struct npc_label_list *) + calloc (1, sizeof (struct npc_label_list)); num = 0; } else - lst = - (struct npc_label_list *) aRealloc (lst, - sizeof (struct npc_label_list) - * (num + 1)); + lst = (struct npc_label_list *) + realloc (lst, sizeof (struct npc_label_list) * (num + 1)); *p = '\0'; strncpy (lst[num].name, lname, sizeof(lst[num].name)-1); @@ -1495,7 +1479,6 @@ int npc_convertlabel_db (void *key, void *data, va_list ap) lst[num].pos = pos; nd->u.scr.label_list = lst; nd->u.scr.label_list_num = num + 1; - return 0; } /*========================================== @@ -1541,7 +1524,7 @@ static int npc_parse_script (char *w1, char *w2, char *w3, char *w4, if (strcmp (w2, "script") == 0) { // スクリプトの解析 - srcbuf = (char *) aCalloc (srcsize, sizeof (char)); + srcbuf = (char *) calloc (srcsize, sizeof (char)); if (strchr (first_line, '{')) { strcpy (srcbuf, strchr (first_line, '{')); @@ -1562,7 +1545,7 @@ static int npc_parse_script (char *w1, char *w2, char *w3, char *w4, if (strlen (srcbuf) + strlen (line) + 1 >= srcsize) { srcsize += 65536; - srcbuf = (char *) aRealloc (srcbuf, srcsize); + srcbuf = (char *) realloc (srcbuf, srcsize); memset (srcbuf + srcsize - 65536, '\0', 65536); } if (srcbuf[0] != '{') @@ -1608,7 +1591,7 @@ static int npc_parse_script (char *w1, char *w2, char *w3, char *w4, } // end of スクリプト解析 - nd = (struct npc_data *) aCalloc (1, sizeof (struct npc_data)); + nd = (struct npc_data *) calloc (1, sizeof (struct npc_data)); if (m == -1) { @@ -1702,7 +1685,7 @@ static int npc_parse_script (char *w1, char *w2, char *w3, char *w4, if (evflag) { // イベント型 struct event_data *ev = - (struct event_data *) aCalloc (1, sizeof (struct event_data)); + (struct event_data *) calloc (1, sizeof (struct event_data)); ev->nd = nd; ev->pos = 0; strdb_insert (ev_db, nd->exname, ev); @@ -1750,9 +1733,9 @@ static int npc_parse_script (char *w1, char *w2, char *w3, char *w4, struct event_data *ev; char *buf; // エクスポートされる - ev = (struct event_data *) aCalloc (1, + ev = (struct event_data *) calloc (1, sizeof (struct event_data)); - buf = (char *) aCalloc (50, sizeof (char)); + buf = (char *) calloc (50, sizeof (char)); if (strlen (lname) > 24) { printf ("npc_parse_script: label name error !\n"); @@ -1781,11 +1764,11 @@ static int npc_parse_script (char *w1, char *w2, char *w3, char *w4, struct npc_timerevent_list *te = nd->u.scr.timer_event; int j, k = nd->u.scr.timeramount; if (te == NULL) - te = (struct npc_timerevent_list *) aCalloc (1, + te = (struct npc_timerevent_list *) calloc (1, sizeof (struct npc_timerevent_list)); else - te = (struct npc_timerevent_list *) aRealloc (te, + te = (struct npc_timerevent_list *) realloc (te, sizeof (struct npc_timerevent_list) * (k + 1)); @@ -1826,7 +1809,7 @@ static int npc_parse_function (char *w1, char *w2, char *w3, char *w4, char *p; // スクリプトの解析 - srcbuf = (char *) aCalloc (srcsize, sizeof (char)); + srcbuf = (char *) calloc (srcsize, sizeof (char)); if (strchr (first_line, '{')) { strcpy (srcbuf, strchr (first_line, '{')); @@ -1847,7 +1830,7 @@ static int npc_parse_function (char *w1, char *w2, char *w3, char *w4, if (strlen (srcbuf) + strlen (line) + 1 >= srcsize) { srcsize += 65536; - srcbuf = (char *) aRealloc (srcbuf, srcsize); + srcbuf = (char *) realloc (srcbuf, srcsize); memset (srcbuf + srcsize - 65536, '\0', 65536); } if (srcbuf[0] != '{') @@ -1869,7 +1852,7 @@ static int npc_parse_function (char *w1, char *w2, char *w3, char *w4, return 1; } - p = (char *) aCalloc (50, sizeof (char)); + p = (char *) calloc (50, sizeof (char)); strncpy (p, w3, 49); strdb_insert (script_get_userfunc_db (), p, script); @@ -1917,7 +1900,7 @@ int npc_parse_mob (char *w1, char *w2, char *w3, char *w4) for (i = 0; i < num; i++) { - md = (struct mob_data *) aCalloc (1, sizeof (struct mob_data)); + md = (struct mob_data *) calloc (1, sizeof (struct mob_data)); md->bl.prev = NULL; md->bl.next = NULL; @@ -1949,7 +1932,7 @@ int npc_parse_mob (char *w1, char *w2, char *w3, char *w4) if (mob_db[class].mode & 0x02) md->lootitem = - (struct item *) aCalloc (LOOTITEM_SIZE, sizeof (struct item)); + (struct item *) calloc (LOOTITEM_SIZE, sizeof (struct item)); else md->lootitem = NULL; @@ -1993,7 +1976,7 @@ static int npc_parse_mapflag (char *w1, char *w2, char *w3, char *w4) return 1; //マップフラグ - if (strcmpi (w3, "nosave") == 0) + if (strcasecmp (w3, "nosave") == 0) { if (strcmp (w4, "SavePoint") == 0) { @@ -2009,51 +1992,51 @@ static int npc_parse_mapflag (char *w1, char *w2, char *w3, char *w4) } map[m].flag.nosave = 1; } - else if (strcmpi (w3, "nomemo") == 0) + else if (strcasecmp (w3, "nomemo") == 0) { map[m].flag.nomemo = 1; } - else if (strcmpi (w3, "noteleport") == 0) + else if (strcasecmp (w3, "noteleport") == 0) { map[m].flag.noteleport = 1; } - else if (strcmpi (w3, "nowarp") == 0) + else if (strcasecmp (w3, "nowarp") == 0) { map[m].flag.nowarp = 1; } - else if (strcmpi (w3, "nowarpto") == 0) + else if (strcasecmp (w3, "nowarpto") == 0) { map[m].flag.nowarpto = 1; } - else if (strcmpi (w3, "noreturn") == 0) + else if (strcasecmp (w3, "noreturn") == 0) { map[m].flag.noreturn = 1; } - else if (strcmpi (w3, "monster_noteleport") == 0) + else if (strcasecmp (w3, "monster_noteleport") == 0) { map[m].flag.monster_noteleport = 1; } - else if (strcmpi (w3, "nobranch") == 0) + else if (strcasecmp (w3, "nobranch") == 0) { map[m].flag.nobranch = 1; } - else if (strcmpi (w3, "nopenalty") == 0) + else if (strcasecmp (w3, "nopenalty") == 0) { map[m].flag.nopenalty = 1; } - else if (strcmpi (w3, "pvp") == 0) + else if (strcasecmp (w3, "pvp") == 0) { map[m].flag.pvp = 1; } - else if (strcmpi (w3, "pvp_noparty") == 0) + else if (strcasecmp (w3, "pvp_noparty") == 0) { map[m].flag.pvp_noparty = 1; } - else if (strcmpi (w3, "pvp_noguild") == 0) + else if (strcasecmp (w3, "pvp_noguild") == 0) { map[m].flag.pvp_noguild = 1; } - else if (strcmpi (w3, "pvp_nightmaredrop") == 0) + else if (strcasecmp (w3, "pvp_nightmaredrop") == 0) { if (sscanf (w4, "%[^,],%[^,],%d", drop_arg1, drop_arg2, &drop_per) == 3) @@ -2086,64 +2069,64 @@ static int npc_parse_mapflag (char *w1, char *w2, char *w3, char *w4) } } } - else if (strcmpi (w3, "pvp_nocalcrank") == 0) + else if (strcasecmp (w3, "pvp_nocalcrank") == 0) { map[m].flag.pvp_nocalcrank = 1; } - else if (strcmpi (w3, "gvg") == 0) + else if (strcasecmp (w3, "gvg") == 0) { map[m].flag.gvg = 1; } - else if (strcmpi (w3, "gvg_noparty") == 0) + else if (strcasecmp (w3, "gvg_noparty") == 0) { map[m].flag.gvg_noparty = 1; } - else if (strcmpi (w3, "nozenypenalty") == 0) + else if (strcasecmp (w3, "nozenypenalty") == 0) { map[m].flag.nozenypenalty = 1; } - else if (strcmpi (w3, "notrade") == 0) + else if (strcasecmp (w3, "notrade") == 0) { map[m].flag.notrade = 1; } - else if (strcmpi (w3, "noskill") == 0) + else if (strcasecmp (w3, "noskill") == 0) { map[m].flag.noskill = 1; } - else if (battle_config.pk_mode && strcmpi (w3, "nopvp") == 0) + else if (battle_config.pk_mode && strcasecmp (w3, "nopvp") == 0) { // nopvp for pk mode [Valaris] map[m].flag.nopvp = 1; map[m].flag.pvp = 0; } - else if (strcmpi (w3, "noicewall") == 0) + else if (strcasecmp (w3, "noicewall") == 0) { // noicewall [Valaris] map[m].flag.noicewall = 1; } - else if (strcmpi (w3, "snow") == 0) + else if (strcasecmp (w3, "snow") == 0) { // snow [Valaris] map[m].flag.snow = 1; } - else if (strcmpi (w3, "fog") == 0) + else if (strcasecmp (w3, "fog") == 0) { // fog [Valaris] map[m].flag.fog = 1; } - else if (strcmpi (w3, "sakura") == 0) + else if (strcasecmp (w3, "sakura") == 0) { // sakura [Valaris] map[m].flag.sakura = 1; } - else if (strcmpi (w3, "leaves") == 0) + else if (strcasecmp (w3, "leaves") == 0) { // leaves [Valaris] map[m].flag.leaves = 1; } - else if (strcmpi (w3, "rain") == 0) + else if (strcasecmp (w3, "rain") == 0) { // rain [Valaris] map[m].flag.rain = 1; } - else if (strcmpi (w3, "no_player_drops") == 0) + else if (strcasecmp (w3, "no_player_drops") == 0) { // no player drops [Jaxad0127] map[m].flag.no_player_drops = 1; } - else if (strcmpi (w3, "town") == 0) + else if (strcasecmp (w3, "town") == 0) { // town/safe zone [remoitnane] map[m].flag.town = 1; } @@ -2151,24 +2134,18 @@ static int npc_parse_mapflag (char *w1, char *w2, char *w3, char *w4) return 0; } -static int ev_db_final (void *key, void *data, va_list ap) +static void ev_db_final (db_key_t key, db_val_t data, va_list ap) { free (data); - if (strstr (key, "::") != NULL) - free (key); - return 0; -} - -static int npcname_db_final (void *key, void *data, va_list ap) -{ - return 0; + if (strstr (key.s, "::") != NULL) + free ((char*)key.s); } struct npc_data *npc_spawn_text (int m, int x, int y, int class, char *name, char *message) { struct npc_data *retval = - (struct npc_data *) aCalloc (1, sizeof (struct npc_data)); + (struct npc_data *) calloc (1, sizeof (struct npc_data)); retval->bl.id = npc_get_new_npc_id (); retval->bl.x = x; retval->bl.y = y; @@ -2259,8 +2236,6 @@ int do_final_npc (void) if (ev_db) strdb_final (ev_db, ev_db_final); - if (npcname_db) - strdb_final (npcname_db, npcname_db_final); for (i = START_NPC_NUM; i < npc_id; i++) { @@ -2284,12 +2259,10 @@ int do_final_npc (void) return 0; } -void ev_release (struct dbn *db, int which) +void ev_release (db_key_t key, db_val_t val) { - if (which & 0x1) - free (db->key); - if (which & 0x2) - free (db->data); + free ((char*)key.s); + free (val); } /*========================================== @@ -2361,7 +2334,7 @@ int do_init_npc (void) continue; } // マップの存在確認 - if (strcmp (w1, "-") != 0 && strcmpi (w1, "function") != 0) + if (strcmp (w1, "-") != 0 && strcasecmp (w1, "function") != 0) { sscanf (w1, "%[^,]", mapname); m = map_mapname2mapid (mapname); @@ -2371,17 +2344,17 @@ int do_init_npc (void) continue; } } - if (strcmpi (w2, "warp") == 0 && count > 3) + if (strcasecmp (w2, "warp") == 0 && count > 3) { npc_parse_warp (w1, w2, w3, w4); } - else if (strcmpi (w2, "shop") == 0 && count > 3) + else if (strcasecmp (w2, "shop") == 0 && count > 3) { npc_parse_shop (w1, w2, w3, w4); } - else if (strcmpi (w2, "script") == 0 && count > 3) + else if (strcasecmp (w2, "script") == 0 && count > 3) { - if (strcmpi (w1, "function") == 0) + if (strcasecmp (w1, "function") == 0) { npc_parse_function (w1, w2, w3, w4, line + w4pos, fp, &lines); @@ -2399,11 +2372,11 @@ int do_init_npc (void) { npc_parse_script (w1, w2, w3, w4, line + w4pos, fp, &lines); } - else if (strcmpi (w2, "monster") == 0 && count > 3) + else if (strcasecmp (w2, "monster") == 0 && count > 3) { npc_parse_mob (w1, w2, w3, w4); } - else if (strcmpi (w2, "mapflag") == 0 && count >= 3) + else if (strcasecmp (w2, "mapflag") == 0 && count >= 3) { npc_parse_mapflag (w1, w2, w3, w4); } @@ -2416,11 +2389,5 @@ int do_init_npc (void) printf ("\rNPCs Loaded: %d [Warps:%d Shops:%d Scripts:%d Mobs:%d]\n", npc_id - START_NPC_NUM, npc_warp, npc_shop, npc_script, npc_mob); - add_timer_func_list (npc_event_timer, "npc_event_timer"); - add_timer_func_list (npc_event_do_clock, "npc_event_do_clock"); - add_timer_func_list (npc_timerevent, "npc_timerevent"); - - //exit(1); - return 0; } diff --git a/src/map/npc.h b/src/map/npc.h index 4c08c02..248bad7 100644 --- a/src/map/npc.h +++ b/src/map/npc.h @@ -9,7 +9,7 @@ #define INVISIBLE_CLASS 32767 int npc_event_dequeue (struct map_session_data *sd); -int npc_event_timer (int tid, unsigned int tick, int id, int data); +void npc_event_timer (timer_id, tick_t, custom_id_t, custom_data_t); int npc_event (struct map_session_data *sd, const char *npcname, int); int npc_timer_event (const char *eventname); // Added by RoVeRT int npc_command (struct map_session_data *sd, char *npcname, char *command); diff --git a/src/map/party.c b/src/map/party.c index 4e59fae..cc35d2a 100644 --- a/src/map/party.c +++ b/src/map/party.c @@ -8,7 +8,6 @@ #include "../common/timer.h" #include "../common/socket.h" #include "../common/nullpo.h" -#include "../common/malloc.h" #include "pc.h" #include "map.h" #include "battle.h" @@ -25,15 +24,14 @@ static struct dbt *party_db; -int party_send_xyhp_timer (int tid, unsigned int tick, int id, int data); +void party_send_xyhp_timer (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data); /*========================================== * 終了 *------------------------------------------ */ -static int party_db_final (void *key, void *data, va_list ap) +static void party_db_final (db_key_t key, db_val_t data, va_list ap) { free (data); - return 0; } void do_final_party (void) @@ -46,7 +44,6 @@ void do_final_party (void) void do_init_party (void) { party_db = numdb_init (); - add_timer_func_list (party_send_xyhp_timer, "party_send_xyhp_timer"); add_timer_interval (gettick () + PARTY_SEND_XYHP_INVERVAL, party_send_xyhp_timer, 0, 0, PARTY_SEND_XYHP_INVERVAL); @@ -58,15 +55,14 @@ struct party *party_search (int party_id) return numdb_search (party_db, party_id); } -int party_searchname_sub (void *key, void *data, va_list ap) +void party_searchname_sub (db_key_t key, db_val_t data, va_list ap) { struct party *p = (struct party *) data, **dst; char *str; str = va_arg (ap, char *); dst = va_arg (ap, struct party **); - if (strcmpi (p->name, str) == 0) + if (strcasecmp (p->name, str) == 0) *dst = p; - return 0; } // パーティ名検索 @@ -120,7 +116,7 @@ int party_created (int account_id, int fail, int party_id, char *name) exit (1); } - p = (struct party *) aCalloc (1, sizeof (struct party)); + CREATE (p, struct party, 1); p->party_id = party_id; memcpy (p->name, name, 24); numdb_insert (party_db, party_id, p); @@ -205,7 +201,7 @@ int party_recv_info (struct party *sp) if ((p = numdb_search (party_db, sp->party_id)) == NULL) { - p = (struct party *) aCalloc (1, sizeof (struct party)); + CREATE (p, struct party, 1); numdb_insert (party_db, sp->party_id, p); // 最初のロードなのでユーザーのチェックを行う @@ -574,7 +570,7 @@ int party_send_movemap (struct map_session_data *sd) if (sd->party_sended != 0) // もうパーティデータは送信済み return 0; - // 競合確認 + // 競合確認 party_check_conflict (sd); // あるならパーティ情報送信 @@ -645,12 +641,12 @@ int party_check_conflict (struct map_session_data *sd) } // 位置やHP通知用 -int party_send_xyhp_timer_sub (void *key, void *data, va_list ap) +void party_send_xyhp_timer_sub (db_key_t key, db_val_t data, va_list ap) { struct party *p = (struct party *) data; int i; - nullpo_retr (0, p); + nullpo_retv (p); for (i = 0; i < MAX_PARTY; i++) { @@ -673,14 +669,12 @@ int party_send_xyhp_timer_sub (void *key, void *data, va_list ap) } } - return 0; } // 位置やHP通知 -int party_send_xyhp_timer (int tid, unsigned int tick, int id, int data) +void party_send_xyhp_timer (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) { numdb_foreach (party_db, party_send_xyhp_timer_sub, tick); - return 0; } // 位置通知クリア diff --git a/src/map/pc.c b/src/map/pc.c index fc2732f..ac03334 100644 --- a/src/map/pc.c +++ b/src/map/pc.c @@ -9,8 +9,8 @@ #include "../common/timer.h" #include "../common/db.h" -#include "../common/malloc.h" #include "../common/nullpo.h" +#include "../common/mt_rand.h" #include "atcommand.h" #include "battle.h" @@ -171,23 +171,21 @@ static int distance (int x0, int y0, int x1, int y1) return dx > dy ? dx : dy; } -static int pc_invincible_timer (int tid, unsigned int tick, int id, int data) +static void pc_invincible_timer (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) { struct map_session_data *sd; if ((sd = (struct map_session_data *) map_id2sd (id)) == NULL || sd->bl.type != BL_PC) - return 1; + return; if (sd->invincible_timer != tid) { if (battle_config.error_log) printf ("invincible_timer %d != %d\n", sd->invincible_timer, tid); - return 0; + return; } sd->invincible_timer = -1; - - return 0; } int pc_setinvincibletimer (struct map_session_data *sd, int val) @@ -213,20 +211,20 @@ int pc_delinvincibletimer (struct map_session_data *sd) return 0; } -static int pc_spiritball_timer (int tid, unsigned int tick, int id, int data) +static void pc_spiritball_timer (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) { struct map_session_data *sd; int i; if ((sd = (struct map_session_data *) map_id2sd (id)) == NULL || sd->bl.type != BL_PC) - return 1; + return; if (sd->spirit_timer[0] != tid) { if (battle_config.error_log) printf ("spirit_timer %d != %d\n", sd->spirit_timer[0], tid); - return 0; + return; } sd->spirit_timer[0] = -1; for (i = 1; i < sd->spiritball; i++) @@ -238,8 +236,6 @@ static int pc_spiritball_timer (int tid, unsigned int tick, int id, int data) if (sd->spiritball < 0) sd->spiritball = 0; clif_spiritball (sd); - - return 0; } int pc_addspiritball (struct map_session_data *sd, int interval, int max) @@ -4334,7 +4330,7 @@ static int calc_next_walk_step (struct map_session_data *sd) * 半歩進む(timer関数) *------------------------------------------ */ -static int pc_walk (int tid, unsigned int tick, int id, int data) +static void pc_walk (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) { struct map_session_data *sd; int i, ctype; @@ -4343,18 +4339,18 @@ static int pc_walk (int tid, unsigned int tick, int id, int data) sd = map_id2sd (id); if (sd == NULL) - return 0; + return; if (sd->walktimer != tid) { if (battle_config.error_log) printf ("pc_walk %d != %d\n", sd->walktimer, tid); - return 0; + return; } sd->walktimer = -1; if (sd->walkpath.path_pos >= sd->walkpath.path_len || sd->walkpath.path_pos != data) - return 0; + return; //歩いたので息吹のタイマーを初期化 sd->inchealspirithptick = 0; @@ -4367,13 +4363,13 @@ static int pc_walk (int tid, unsigned int tick, int id, int data) if (sd->state.change_walk_target) { pc_walktoxy_sub (sd); - return 0; + return; } } else { // マス目境界へ到着 if (sd->walkpath.path[sd->walkpath.path_pos] >= 8) - return 1; + return; x = sd->bl.x; y = sd->bl.y; @@ -4381,7 +4377,7 @@ static int pc_walk (int tid, unsigned int tick, int id, int data) if (ctype == 1 || ctype == 5) { pc_stop_walking (sd, 1); - return 0; + return; } sd->dir = sd->head_dir = sd->walkpath.path[sd->walkpath.path_pos]; dx = dirx[(int) sd->dir]; @@ -4390,7 +4386,7 @@ static int pc_walk (int tid, unsigned int tick, int id, int data) if (ctype == 1 || ctype == 5) { pc_walktoxy_sub (sd); - return 0; + return; } moveblock = (x / BLOCK_SIZE != (x + dx) / BLOCK_SIZE @@ -4465,8 +4461,6 @@ static int pc_walk (int tid, unsigned int tick, int id, int data) sd->walktimer = add_timer (tick + i, pc_walk, id, sd->walkpath.path_pos); } - - return 0; } /*========================================== @@ -4804,7 +4798,7 @@ struct pc_base_job pc_calc_base_job (int b_class) * PCの攻撃 (timer関数) *------------------------------------------ */ -int pc_attack_timer (int tid, unsigned int tick, int id, int data) +void pc_attack_timer (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) { struct map_session_data *sd; struct block_list *bl; @@ -4815,48 +4809,48 @@ int pc_attack_timer (int tid, unsigned int tick, int id, int data) sd = map_id2sd (id); if (sd == NULL) - return 0; + return; if (sd->attacktimer != tid) { if (battle_config.error_log) printf ("pc_attack_timer %d != %d\n", sd->attacktimer, tid); - return 0; + return; } sd->attacktimer = -1; if (sd->bl.prev == NULL) - return 0; + return; bl = map_id2bl (sd->attacktarget); if (bl == NULL || bl->prev == NULL) - return 0; + return; if (bl->type == BL_PC && pc_isdead ((struct map_session_data *) bl)) - return 0; + return; // 同じmapでないなら攻撃しない // PCが死んでても攻撃しない if (sd->bl.m != bl->m || pc_isdead (sd)) - return 0; + return; if (sd->opt1 > 0 || sd->status.option & 2 || sd->status.option & 16388) // 異常などで攻撃できない - return 0; + return; if (sd->sc_data[SC_AUTOCOUNTER].timer != -1) - return 0; + return; if (sd->sc_data[SC_BLADESTOP].timer != -1) - return 0; + return; if ((opt = battle_get_option (bl)) != NULL && *opt & 0x46) - return 0; + return; if (((sc_data = battle_get_sc_data (bl)) != NULL && sc_data[SC_TRICKDEAD].timer != -1) || ((sc_data = battle_get_sc_data (bl)) != NULL && sc_data[SC_BASILICA].timer != -1)) - return 0; + return; if (sd->skilltimer != -1 && pc_checkskill (sd, SA_FREECAST) <= 0) - return 0; + return; if (!battle_config.sdelay_attack_enable && pc_checkskill (sd, SA_FREECAST) <= 0) @@ -4864,12 +4858,12 @@ int pc_attack_timer (int tid, unsigned int tick, int id, int data) if (DIFF_TICK (tick, sd->canact_tick) < 0) { clif_skill_fail (sd, 1, 4, 0); - return 0; + return; } } if (sd->attackabletime > tick) - return 0; // cannot attack yet + return; // cannot attack yet attack_spell_delay = sd->attack_spell_delay; if (sd->attack_spell_override // [Fate] If we have an active attack spell, use that @@ -4889,7 +4883,7 @@ int pc_attack_timer (int tid, unsigned int tick, int id, int data) { // 届 かないので移動 //if(pc_can_reach(sd,bl->x,bl->y)) //clif_movetoattack(sd,bl); - return 0; + return; } if (dist <= range && !battle_check_range (&sd->bl, bl, range)) @@ -4944,8 +4938,6 @@ int pc_attack_timer (int tid, unsigned int tick, int id, int data) sd->attacktimer = add_timer (sd->attackabletime, pc_attack_timer, sd->bl.id, 0); } - - return 0; } /*========================================== @@ -5011,13 +5003,13 @@ int pc_stopattack (struct map_session_data *sd) return 0; } -int pc_follow_timer (int tid, unsigned int tick, int id, int data) +void pc_follow_timer (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) { struct map_session_data *sd, *bl; sd = map_id2sd (id); if (sd == NULL || sd->followtimer != tid) - return 0; + return; sd->followtimer = -1; @@ -5029,14 +5021,14 @@ int pc_follow_timer (int tid, unsigned int tick, int id, int data) bl = (struct map_session_data *) map_id2bl (sd->followtarget); if (bl == NULL) - return 0; + return; if (bl->bl.prev == NULL) break; if (bl->bl.type == BL_PC && pc_isdead ((struct map_session_data *) bl)) - return 0; + return; if (sd->skilltimer == -1 && sd->attacktimer == -1 && sd->walktimer == -1) @@ -5056,8 +5048,6 @@ int pc_follow_timer (int tid, unsigned int tick, int id, int data) sd->followtimer = add_timer (tick + sd->aspd, pc_follow_timer, sd->bl.id, 0); - - return 0; } int pc_follow (struct map_session_data *sd, int target_id) @@ -5677,8 +5667,8 @@ int pc_resetlvl (struct map_session_data *sd, int type) sd->status.skill_point = 0; sd->status.base_level = 1; sd->status.job_level = 1; - sd->status.base_exp = sd->status.base_exp = 0; - sd->status.job_exp = sd->status.job_exp = 0; + sd->status.base_exp = 0; + sd->status.job_exp = 0; if (sd->status.option != 0) sd->status.option = 0; @@ -7213,12 +7203,12 @@ int pc_percentrefinery (struct map_session_data *sd, struct item *item) * イベントタイマー処理 *------------------------------------------ */ -int pc_eventtimer (int tid, unsigned int tick, int id, int data) +void pc_eventtimer (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) { struct map_session_data *sd = map_id2sd (id); int i; if (sd == NULL) - return 0; + return; for (i = 0; i < MAX_EVENTTIMER; i++) { @@ -7235,8 +7225,6 @@ int pc_eventtimer (int tid, unsigned int tick, int id, int data) if (battle_config.error_log) printf ("pc_eventtimer: no such event timer\n"); } - - return 0; } /*========================================== @@ -7255,7 +7243,7 @@ int pc_addeventtimer (struct map_session_data *sd, int tick, const char *name) if (i < MAX_EVENTTIMER) { - char *evname = (char *) aCalloc (24, sizeof (char)); + char *evname = (char *) calloc (24, 1); strncpy (evname, name, 24); evname[23] = '\0'; sd->eventtimer[i] = add_timer (gettick () + tick, @@ -7811,20 +7799,19 @@ int pc_calc_pvprank (struct map_session_data *sd) * PVP順位計算(timer) *------------------------------------------ */ -int pc_calc_pvprank_timer (int tid, unsigned int tick, int id, int data) +void pc_calc_pvprank_timer (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) { struct map_session_data *sd = NULL; if (battle_config.pk_mode) // disable pvp ranking if pk_mode on [Valaris] - return 0; + return; sd = map_id2sd (id); if (sd == NULL) - return 0; + return; sd->pvp_timer = -1; if (pc_calc_pvprank (sd) > 0) sd->pvp_timer = add_timer (gettick () + PVP_CALCRANK_INTERVAL, pc_calc_pvprank_timer, id, data); - return 0; } /*========================================== @@ -8387,7 +8374,7 @@ static int pc_natural_heal_sub (struct map_session_data *sd, va_list ap) * HP/SP自然回復 (interval timer関数) *------------------------------------------ */ -int pc_natural_heal (int tid, unsigned int tick, int id, int data) +void pc_natural_heal (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) { natural_heal_tick = tick; natural_heal_diff_tick = @@ -8395,7 +8382,6 @@ int pc_natural_heal (int tid, unsigned int tick, int id, int data) clif_foreachclient (pc_natural_heal_sub); natural_heal_prev_tick = tick; - return 0; } /*========================================== @@ -8465,7 +8451,7 @@ static int pc_autosave_sub (struct map_session_data *sd, va_list ap) * 自動セーブ (timer関数) *------------------------------------------ */ -int pc_autosave (int tid, unsigned int tick, int id, int data) +void pc_autosave (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) { int interval; @@ -8478,8 +8464,6 @@ int pc_autosave (int tid, unsigned int tick, int id, int data) if (interval <= 0) interval = 1; add_timer (gettick () + interval, pc_autosave, 0, 0); - - return 0; } int pc_read_gm_account (int fd) @@ -8505,7 +8489,7 @@ int pc_read_gm_account (int fd) * timer to do the day *------------------------------------------ */ -int map_day_timer (int tid, unsigned int tick, int id, int data) +void map_day_timer (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) { // by [yor] struct map_session_data *pl_sd = NULL; int i; @@ -8530,15 +8514,13 @@ int map_day_timer (int tid, unsigned int tick, int id, int data) } } } - - return 0; } /*========================================== * timer to do the night *------------------------------------------ */ -int map_night_timer (int tid, unsigned int tick, int id, int data) +void map_night_timer (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) { // by [yor] struct map_session_data *pl_sd = NULL; int i; @@ -8563,8 +8545,6 @@ int map_night_timer (int tid, unsigned int tick, int id, int data) } } } - - return 0; } void pc_setstand (struct map_session_data *sd) @@ -8973,22 +8953,11 @@ int do_init_pc (void) // gm_account_db = numdb_init(); - add_timer_func_list (pc_walk, "pc_walk"); - add_timer_func_list (pc_attack_timer, "pc_attack_timer"); - add_timer_func_list (pc_natural_heal, "pc_natural_heal"); - add_timer_func_list (pc_invincible_timer, "pc_invincible_timer"); - add_timer_func_list (pc_eventtimer, "pc_eventtimer"); - add_timer_func_list (pc_calc_pvprank_timer, "pc_calc_pvprank_timer"); - add_timer_func_list (pc_autosave, "pc_autosave"); - add_timer_func_list (pc_spiritball_timer, "pc_spiritball_timer"); add_timer_interval ((natural_heal_prev_tick = gettick () + NATURAL_HEAL_INTERVAL), pc_natural_heal, 0, 0, NATURAL_HEAL_INTERVAL); add_timer (gettick () + autosave_interval, pc_autosave, 0, 0); - // add night/day timer (by [yor]) - add_timer_func_list (map_day_timer, "map_day_timer"); // by [yor] - add_timer_func_list (map_night_timer, "map_night_timer"); // by [yor] { int day_duration = battle_config.day_duration; int night_duration = battle_config.night_duration; diff --git a/src/map/pc.h b/src/map/pc.h index 20ae26e..742d9d4 100644 --- a/src/map/pc.h +++ b/src/map/pc.h @@ -169,7 +169,7 @@ int pc_addeventtimercount (struct map_session_data *sd, const char *name, int tick); int pc_calc_pvprank (struct map_session_data *sd); -int pc_calc_pvprank_timer (int tid, unsigned int tick, int id, int data); +void pc_calc_pvprank_timer (timer_id, tick_t, custom_id_t, custom_data_t); int pc_ismarried (struct map_session_data *sd); int pc_marriage (struct map_session_data *sd, @@ -202,9 +202,9 @@ enum { ADDITEM_EXIST, ADDITEM_NEW, ADDITEM_OVERAMOUNT }; // timer for night.day -int day_timer_tid; -int night_timer_tid; -int map_day_timer (int, unsigned int, int, int); // by [yor] -int map_night_timer (int, unsigned int, int, int); // by [yor] +timer_id day_timer_tid; +timer_id night_timer_tid; +void map_day_timer (timer_id, tick_t, custom_id_t, custom_data_t); // by [yor] +void map_night_timer (timer_id, tick_t, custom_id_t, custom_data_t); // by [yor] #endif diff --git a/src/map/script.c b/src/map/script.c index 0c01ac0..fb8b8af 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -17,8 +17,8 @@ #include "../common/socket.h" #include "../common/timer.h" -#include "../common/malloc.h" #include "../common/lock.h" +#include "../common/mt_rand.h" #include "atcommand.h" #include "battle.h" @@ -85,11 +85,6 @@ struct dbt *script_get_userfunc_db () return userfunc_db; } -int scriptlabel_final (void *k, void *d, va_list ap) -{ - return 0; -} - static char pos[11][100] = { "頭", "体", "左手", "右手", "ローブ", "靴", "アクセサリー1", "アクセサリー2", "頭2", "頭3", "装着していない" @@ -831,13 +826,13 @@ static int add_str (const unsigned char *p) if (str_num >= str_data_size) { str_data_size += 128; - str_data = aRealloc (str_data, sizeof (str_data[0]) * str_data_size); + str_data = realloc (str_data, sizeof (str_data[0]) * str_data_size); memset (str_data + (str_data_size - 128), '\0', 128); } while (str_pos + strlen (p) + 1 >= str_size) { str_size += 256; - str_buf = (char *) aRealloc (str_buf, str_size); + str_buf = (char *) realloc (str_buf, str_size); memset (str_buf + (str_size - 256), '\0', 256); } strcpy (str_buf + str_pos, p); @@ -860,7 +855,7 @@ static void check_script_buf (int size) if (script_pos + size >= script_size) { script_size += SCRIPT_BLOCK_SIZE; - script_buf = (char *) aRealloc (script_buf, script_size); + script_buf = (char *) realloc (script_buf, script_size); memset (script_buf + script_size - SCRIPT_BLOCK_SIZE, '\0', SCRIPT_BLOCK_SIZE); } @@ -1474,8 +1469,7 @@ unsigned char *parse_script (unsigned char *src, int line) read_constdb (); } first = 0; - script_buf = - (unsigned char *) aCalloc (SCRIPT_BLOCK_SIZE, sizeof (unsigned char)); + script_buf = (unsigned char *) calloc (SCRIPT_BLOCK_SIZE, 1); script_pos = 0; script_size = SCRIPT_BLOCK_SIZE; str_data[LABEL_NEXTLINE].type = C_NOP; @@ -1493,7 +1487,7 @@ unsigned char *parse_script (unsigned char *src, int line) // 外部用label dbの初期化 if (scriptlabel_db != NULL) - strdb_final (scriptlabel_db, scriptlabel_final); + strdb_final (scriptlabel_db, NULL); scriptlabel_db = strdb_init (50); // for error message @@ -1526,7 +1520,7 @@ unsigned char *parse_script (unsigned char *src, int line) exit (1); } set_label (l, script_pos); - strdb_insert (scriptlabel_db, p, script_pos); // 外部用label db登録 + strdb_insert (scriptlabel_db, (const char*)p, script_pos); // 外部用label db登録 *skip_word (p) = c; p = tmpp + 1; continue; @@ -1546,7 +1540,7 @@ unsigned char *parse_script (unsigned char *src, int line) add_scriptc (C_NOP); script_size = script_pos; - script_buf = (char *) aRealloc (script_buf, script_pos + 1); + script_buf = (char *) realloc (script_buf, script_pos + 1); // 未解決のラベルを解決 for (i = LABEL_START; i < str_num; i++) @@ -1772,7 +1766,7 @@ char *conv_str (struct script_state *st, struct script_data *data) if (data->type == C_INT) { char *buf; - buf = (char *) aCalloc (16, sizeof (char)); + buf = (char *) calloc (16, 1); sprintf (buf, "%d", data->u.num); data->type = C_STR; data->u.str = buf; @@ -1816,10 +1810,9 @@ void push_val (struct script_stack *stack, int type, int val) if (stack->sp >= stack->sp_max) { stack->sp_max += 64; - stack->stack_data = - (struct script_data *) aRealloc (stack->stack_data, - sizeof (stack->stack_data[0]) * - stack->sp_max); + stack->stack_data = (struct script_data *) + realloc (stack->stack_data, sizeof (stack->stack_data[0]) * + stack->sp_max); memset (stack->stack_data + (stack->sp_max - 64), 0, 64 * sizeof (*(stack->stack_data))); } @@ -1839,10 +1832,9 @@ void push_str (struct script_stack *stack, int type, unsigned char *str) if (stack->sp >= stack->sp_max) { stack->sp_max += 64; - stack->stack_data = - (struct script_data *) aRealloc (stack->stack_data, - sizeof (stack->stack_data[0]) * - stack->sp_max); + stack->stack_data = (struct script_data *) + realloc (stack->stack_data, sizeof (stack->stack_data[0]) * + stack->sp_max); memset (stack->stack_data + (stack->sp_max - 64), '\0', 64 * sizeof (*(stack->stack_data))); } @@ -2091,7 +2083,7 @@ int buildin_menu (struct script_state *st) st->state = RERUNLINE; sd->state.menu_or_input = 1; - buf = (char *) aCalloc (len + 1, sizeof (char)); + buf = (char *) calloc (len + 1, 1); buf[0] = 0; for (i = st->start + 2; menu_choices > 0; i += 2, --menu_choices) { @@ -3180,7 +3172,7 @@ char *buildin_getpartyname_sub (int party_id) if (p != NULL) { char *buf; - buf = (char *) aCalloc (24, sizeof (char)); + buf = (char *) calloc (24, 1); strcpy (buf, p->name); return buf; } @@ -3245,7 +3237,7 @@ char *buildin_getguildname_sub (int guild_id) if (g != NULL) { char *buf; - buf = (char *) aCalloc (24, sizeof (char)); + buf = (char *) calloc (24, 1); strcpy (buf, g->name); return buf; } @@ -3276,7 +3268,7 @@ char *buildin_getguildmaster_sub (int guild_id) if (g != NULL) { char *buf; - buf = (char *) aCalloc (24, sizeof (char)); + buf = (char *) calloc (24, 1); strncpy (buf, g->master, 23); return buf; } @@ -3332,7 +3324,7 @@ int buildin_strcharinfo (struct script_state *st) if (num == 0) { char *buf; - buf = (char *) aCalloc (24, sizeof (char)); + buf = (char *) calloc (24, 1); strncpy (buf, sd->status.name, 23); push_str (st->stack, C_STR, buf); } @@ -3407,7 +3399,7 @@ int buildin_getequipname (struct script_state *st) struct item_data *item; char *buf; - buf = (char *) aCalloc (64, sizeof (char)); + buf = (char *) calloc (64, 1); sd = script_rid2sd (st); num = conv_num (st, &(st->stack->stack_data[st->start + 2])); i = pc_checkequip (sd, equip[num - 1]); @@ -4208,7 +4200,7 @@ int buildin_gettimestr (struct script_state *st) fmtstr = conv_str (st, &(st->stack->stack_data[st->start + 2])); maxlen = conv_num (st, &(st->stack->stack_data[st->start + 3])); - tmpstr = (char *) aCalloc (maxlen + 1, sizeof (char)); + tmpstr = (char *) calloc (maxlen + 1, 1); strftime (tmpstr, maxlen, fmtstr, gmtime (&now)); tmpstr[maxlen] = '\0'; @@ -5773,7 +5765,7 @@ int buildin_getcastlename (struct script_state *st) { if (strcmp (mapname, gc->map_name) == 0) { - buf = (char *) aCalloc (24, sizeof (char)); + buf = (char *) calloc (24, 1); strncpy (buf, gc->castle_name, 23); break; } @@ -6451,7 +6443,7 @@ int buildin_getitemname (struct script_state *st) i_data = itemdb_search (item_id); } - item_name = (char *) aCalloc (24, sizeof (char)); + item_name = (char *) calloc (24, 1); if (i_data) strncpy (item_name, i_data->jname, 23); else @@ -7353,11 +7345,10 @@ void op_add (struct script_state *st) else { // ssの予定 char *buf; - buf = - (char *) - aCalloc (strlen (st->stack->stack_data[st->stack->sp - 1].u.str) + - strlen (st->stack->stack_data[st->stack->sp].u.str) + 1, - sizeof (char)); + buf = (char *) + calloc (strlen (st->stack->stack_data[st->stack->sp - 1].u.str) + + strlen (st->stack->stack_data[st->stack->sp].u.str) + 1, + 1); strcpy (buf, st->stack->stack_data[st->stack->sp - 1].u.str); strcat (buf, st->stack->stack_data[st->stack->sp].u.str); if (st->stack->stack_data[st->stack->sp - 1].type == C_STR) @@ -7772,9 +7763,8 @@ int run_script_main (unsigned char *script, int pos, int rid, int oid, { if (sd->npc_stackbuf) free (sd->npc_stackbuf); - sd->npc_stackbuf = - (char *) aCalloc (sizeof (stack->stack_data[0]) * - stack->sp_max, sizeof (char)); + sd->npc_stackbuf = (char *) + calloc (sizeof (stack->stack_data[0]) * stack->sp_max, 1); memcpy (sd->npc_stackbuf, stack->stack_data, sizeof (stack->stack_data[0]) * stack->sp_max); sd->npc_stack = stack->sp; @@ -7813,9 +7803,8 @@ int run_script_l (unsigned char *script, int pos, int rid, int oid, script = sd->npc_script; stack.sp = sd->npc_stack; stack.sp_max = sd->npc_stackmax; - stack.stack_data = - (struct script_data *) aCalloc (stack.sp_max, - sizeof (stack.stack_data[0])); + stack.stack_data = (struct script_data *) + calloc (stack.sp_max, sizeof (stack.stack_data[0])); memcpy (stack.stack_data, sd->npc_stackbuf, sizeof (stack.stack_data[0]) * stack.sp_max); free (sd->npc_stackbuf); @@ -7826,9 +7815,8 @@ int run_script_l (unsigned char *script, int pos, int rid, int oid, // スタック初期化 stack.sp = 0; stack.sp_max = 64; - stack.stack_data = - (struct script_data *) aCalloc (stack.sp_max, - sizeof (stack.stack_data[0])); + stack.stack_data = (struct script_data *) + calloc (stack.sp_max, sizeof (stack.stack_data[0])); } st.stack = &stack; st.pos = pos; @@ -7880,7 +7868,7 @@ int mapreg_setregstr (int num, const char *str) mapreg_dirty = 1; return 0; } - p = (char *) aCalloc (strlen (str) + 1, sizeof (char)); + p = (char *) calloc (strlen (str) + 1, 1); strcpy (p, str); numdb_insert (mapregstr_db, num, p); mapreg_dirty = 1; @@ -7913,7 +7901,7 @@ static int script_load_mapreg () printf ("%s: %s broken data !\n", mapreg_txt, buf1); continue; } - p = (char *) aCalloc (strlen (buf2) + 1, sizeof (char)); + p = (char *) calloc (strlen (buf2) + 1, 1); strcpy (p, buf2); s = add_str (buf1); numdb_insert (mapregstr_db, (i << 24) | s, p); @@ -7938,10 +7926,10 @@ static int script_load_mapreg () * 永続的マップ変数の書き込み *------------------------------------------ */ -static int script_save_mapreg_intsub (void *key, void *data, va_list ap) +static void script_save_mapreg_intsub (db_key_t key, db_val_t data, va_list ap) { FILE *fp = va_arg (ap, FILE *); - int num = ((int) key) & 0x00ffffff, i = ((int) key) >> 24; + int num = key.i & 0x00ffffff, i = key.i >> 24; char *name = str_buf + str_data[num].str; if (name[1] != '@') { @@ -7950,13 +7938,12 @@ static int script_save_mapreg_intsub (void *key, void *data, va_list ap) else fprintf (fp, "%s,%d\t%d\n", name, i, (int) data); } - return 0; } -static int script_save_mapreg_strsub (void *key, void *data, va_list ap) +static void script_save_mapreg_strsub (db_key_t key, db_val_t data, va_list ap) { FILE *fp = va_arg (ap, FILE *); - int num = ((int) key) & 0x00ffffff, i = ((int) key) >> 24; + int num = key.i & 0x00ffffff, i = key.i >> 24; char *name = str_buf + str_data[num].str; if (name[1] != '@') { @@ -7965,7 +7952,6 @@ static int script_save_mapreg_strsub (void *key, void *data, va_list ap) else fprintf (fp, "%s,%d\t%s\n", name, i, (char *) data); } - return 0; } static int script_save_mapreg () @@ -7982,12 +7968,11 @@ static int script_save_mapreg () return 0; } -static int script_autosave_mapreg (int tid, unsigned int tick, int id, - int data) +static void script_autosave_mapreg (timer_id tid, tick_t tick, custom_id_t id, + custom_data_t data) { if (mapreg_dirty) script_save_mapreg (); - return 0; } /*========================================== @@ -8043,11 +8028,11 @@ int script_config_read (char *cfgName) i = sscanf (line, "%[^:]: %[^\r\n]", w1, w2); if (i != 2) continue; - if (strcmpi (w1, "refine_posword") == 0) + if (strcasecmp (w1, "refine_posword") == 0) { set_posword (w2); } - if (strcmpi (w1, "import") == 0) + if (strcasecmp (w1, "import") == 0) { script_config_read (w2); } @@ -8061,27 +8046,16 @@ int script_config_read (char *cfgName) * 終了 *------------------------------------------ */ -static int mapreg_db_final (void *key, void *data, va_list ap) -{ - return 0; -} -static int mapregstr_db_final (void *key, void *data, va_list ap) +static void mapregstr_db_final (db_key_t key, db_val_t data, va_list ap) { free (data); - return 0; -} - -static int scriptlabel_db_final (void *key, void *data, va_list ap) -{ - return 0; } -static int userfunc_db_final (void *key, void *data, va_list ap) +static void userfunc_db_final (db_key_t key, db_val_t data, va_list ap) { - free (key); + free ((char*)key.s); free (data); - return 0; } int do_final_script () @@ -8092,11 +8066,11 @@ int do_final_script () free (script_buf); if (mapreg_db) - numdb_final (mapreg_db, mapreg_db_final); + numdb_final (mapreg_db, NULL); if (mapregstr_db) strdb_final (mapregstr_db, mapregstr_db_final); if (scriptlabel_db) - strdb_final (scriptlabel_db, scriptlabel_db_final); + strdb_final (scriptlabel_db, NULL); if (userfunc_db) strdb_final (userfunc_db, userfunc_db_final); @@ -8118,7 +8092,6 @@ int do_init_script () mapregstr_db = numdb_init (); 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); diff --git a/src/map/skill-pools.c b/src/map/skill-pools.c index 50dafcb..0c91360 100644 --- a/src/map/skill-pools.c +++ b/src/map/skill-pools.c @@ -5,7 +5,7 @@ #include "../common/timer.h" #include "../common/nullpo.h" -#include "../common/malloc.h" +#include "../common/mt_rand.h" #include "magic.h" #include "battle.h" diff --git a/src/map/skill.c b/src/map/skill.c index 54ff545..d8b64e8 100644 --- a/src/map/skill.c +++ b/src/map/skill.c @@ -8,7 +8,7 @@ #include "../common/timer.h" #include "../common/nullpo.h" -#include "../common/malloc.h" +#include "../common/mt_rand.h" #include "magic.h" #include "battle.h" @@ -2250,7 +2250,7 @@ int skill_area_sub_count (struct block_list *src, struct block_list *target, * *------------------------------------------ */ -static int skill_timerskill (int tid, unsigned int tick, int id, int data) +static void skill_timerskill (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) { struct map_session_data *sd = NULL; struct mob_data *md = NULL; @@ -2258,26 +2258,26 @@ static int skill_timerskill (int tid, unsigned int tick, int id, int data) struct skill_timerskill *skl = NULL; int range; - nullpo_retr (0, src); + nullpo_retv (src); if (src->prev == NULL) - return 0; + return; if (src->type == BL_PC) { - nullpo_retr (0, sd = (struct map_session_data *) src); + nullpo_retv (sd = (struct map_session_data *) src); skl = &sd->skilltimerskill[data]; } else if (src->type == BL_MOB) { - nullpo_retr (0, md = (struct mob_data *) src); + nullpo_retv (md = (struct mob_data *) src); skl = &md->skilltimerskill[data]; } else - return 0; + return; - nullpo_retr (0, skl); + nullpo_retv (skl); skl->timer = -1; if (skl->target_id) @@ -2295,17 +2295,17 @@ static int skill_timerskill (int tid, unsigned int tick, int id, int data) } } if (target == NULL) - return 0; + return; if (target->prev == NULL && skl->skill_id != RG_INTIMIDATE) - return 0; + return; if (src->m != target->m) - return 0; + return; if (sd && pc_isdead (sd)) - return 0; + return; if (target->type == BL_PC && pc_isdead ((struct map_session_data *) target) && skl->skill_id != RG_INTIMIDATE) - return 0; + return; switch (skl->skill_id) { @@ -2392,7 +2392,7 @@ static int skill_timerskill (int tid, unsigned int tick, int id, int data) else { if (src->m != skl->map) - return 0; + return; switch (skl->skill_id) { case WZ_METEOR: @@ -2410,8 +2410,6 @@ static int skill_timerskill (int tid, unsigned int tick, int id, int data) break; } } - - return 0; } /*========================================== @@ -5145,19 +5143,19 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, * スキル使用(詠唱完了、ID指定) *------------------------------------------ */ -int skill_castend_id (int tid, unsigned int tick, int id, int data) +void skill_castend_id (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) { struct map_session_data *sd = map_id2sd (id) /*,*target_sd=NULL */ ; struct block_list *bl; int range, inf2; - nullpo_retr (0, sd); + nullpo_retv ( sd); if (sd->bl.prev == NULL) //prevが無いのはありなの? - return 0; + return; if (sd->skillid != SA_CASTCANCEL && sd->skilltimer != tid) /* タイマIDの確認 */ - return 0; + return; if (sd->skillid != SA_CASTCANCEL && sd->skilltimer != -1 && pc_checkskill (sd, SA_FREECAST) > 0) { @@ -5172,14 +5170,14 @@ int skill_castend_id (int tid, unsigned int tick, int id, int data) sd->canact_tick = tick; sd->canmove_tick = tick; sd->skillitem = sd->skillitemlv = -1; - return 0; + return; } if (sd->bl.m != bl->m || pc_isdead (sd)) { //マップが違うか自分が死んでいる sd->canact_tick = tick; sd->canmove_tick = tick; sd->skillitem = sd->skillitemlv = -1; - return 0; + return; } if (sd->skillid == PR_LEXAETERNA) @@ -5194,7 +5192,7 @@ int skill_castend_id (int tid, unsigned int tick, int id, int data) sd->canact_tick = tick; sd->canmove_tick = tick; sd->skillitem = sd->skillitemlv = -1; - return 0; + return; } } else if (sd->skillid == RG_BACKSTAP) @@ -5208,7 +5206,7 @@ int skill_castend_id (int tid, unsigned int tick, int id, int data) sd->canact_tick = tick; sd->canmove_tick = tick; sd->skillitem = sd->skillitemlv = -1; - return 0; + return; } } @@ -5219,7 +5217,7 @@ int skill_castend_id (int tid, unsigned int tick, int id, int data) sd->canact_tick = tick; sd->canmove_tick = tick; sd->skillitem = sd->skillitemlv = -1; - return 0; + return; } if (inf2 & 0xC00 && sd->bl.id != bl->id) { @@ -5235,7 +5233,7 @@ int skill_castend_id (int tid, unsigned int tick, int id, int data) sd->canact_tick = tick; sd->canmove_tick = tick; sd->skillitem = sd->skillitemlv = -1; - return 0; + return; } } @@ -5261,7 +5259,7 @@ int skill_castend_id (int tid, unsigned int tick, int id, int data) sd->canact_tick = tick; sd->canmove_tick = tick; sd->skillitem = sd->skillitemlv = -1; - return 0; + return; } } if (!skill_check_condition (sd, 1)) @@ -5269,7 +5267,7 @@ int skill_castend_id (int tid, unsigned int tick, int id, int data) sd->canact_tick = tick; sd->canmove_tick = tick; sd->skillitem = sd->skillitemlv = -1; - return 0; + return; } sd->skillitem = sd->skillitemlv = -1; if (battle_config.skill_out_range_consume) @@ -5279,7 +5277,7 @@ int skill_castend_id (int tid, unsigned int tick, int id, int data) clif_skill_fail (sd, sd->skillid, 0, 0); sd->canact_tick = tick; sd->canmove_tick = tick; - return 0; + return; } } @@ -5308,8 +5306,6 @@ int skill_castend_id (int tid, unsigned int tick, int id, int data) sd->skilllv, tick, 0); break; } - - return 0; } /*========================================== @@ -5631,7 +5627,7 @@ int skill_castend_map (struct map_session_data *sd, int skill_num, skill_unitsetting (&sd->bl, sd->skillid, sd->skilllv, sd->skillx, sd->skilly, 0)) == NULL) return 0; - group->valstr = (char *) aCalloc (24, sizeof (char)); + CREATE (group->valstr, char, 24); memcpy (group->valstr, map, 24); group->val2 = (x << 16) | y; } @@ -7001,17 +6997,17 @@ int skill_unit_ondamaged (struct skill_unit *src, struct block_list *bl, * スキル使用(詠唱完了、場所指定) *------------------------------------------ */ -int skill_castend_pos (int tid, unsigned int tick, int id, int data) +void skill_castend_pos (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) { struct map_session_data *sd = map_id2sd (id) /*,*target_sd=NULL */ ; int range, maxcount; - nullpo_retr (0, sd); + nullpo_retv (sd); if (sd->bl.prev == NULL) - return 0; + return; if (sd->skilltimer != tid) /* タイマIDの確認 */ - return 0; + return; if (sd->skilltimer != -1 && pc_checkskill (sd, SA_FREECAST) > 0) { sd->speed = sd->prev_speed; @@ -7023,7 +7019,7 @@ int skill_castend_pos (int tid, unsigned int tick, int id, int data) sd->canact_tick = tick; sd->canmove_tick = tick; sd->skillitem = sd->skillitemlv = -1; - return 0; + return; } if (battle_config.pc_skill_reiteration == 0) @@ -7061,7 +7057,7 @@ int skill_castend_pos (int tid, unsigned int tick, int id, int data) sd->canact_tick = tick; sd->canmove_tick = tick; sd->skillitem = sd->skillitemlv = -1; - return 0; + return; } } } @@ -7098,7 +7094,7 @@ int skill_castend_pos (int tid, unsigned int tick, int id, int data) sd->canact_tick = tick; sd->canmove_tick = tick; sd->skillitem = sd->skillitemlv = -1; - return 0; + return; } } } @@ -7121,7 +7117,7 @@ int skill_castend_pos (int tid, unsigned int tick, int id, int data) sd->canact_tick = tick; sd->canmove_tick = tick; sd->skillitem = sd->skillitemlv = -1; - return 0; + return; } } } @@ -7138,7 +7134,7 @@ int skill_castend_pos (int tid, unsigned int tick, int id, int data) sd->canact_tick = tick; sd->canmove_tick = tick; sd->skillitem = sd->skillitemlv = -1; - return 0; + return; } } if (!skill_check_condition (sd, 1)) @@ -7146,7 +7142,7 @@ int skill_castend_pos (int tid, unsigned int tick, int id, int data) sd->canact_tick = tick; sd->canmove_tick = tick; sd->skillitem = sd->skillitemlv = -1; - return 0; + return; } sd->skillitem = sd->skillitemlv = -1; if (battle_config.skill_out_range_consume) @@ -7156,7 +7152,7 @@ int skill_castend_pos (int tid, unsigned int tick, int id, int data) clif_skill_fail (sd, sd->skillid, 0, 0); sd->canact_tick = tick; sd->canmove_tick = tick; - return 0; + return; } } @@ -7166,8 +7162,6 @@ int skill_castend_pos (int tid, unsigned int tick, int id, int data) skill_castend_pos2 (&sd->bl, sd->skillx, sd->skilly, sd->skillid, sd->skilllv, tick, 0); - - return 0; } /*========================================== @@ -7338,8 +7332,11 @@ static int skill_check_condition_mob_master_sub (struct block_list *bl, nullpo_retr (0, bl); nullpo_retr (0, ap); nullpo_retr (0, md = (struct mob_data *) bl); - nullpo_retr (0, src_id = va_arg (ap, int)); - nullpo_retr (0, mob_class = va_arg (ap, int)); + + if (!(src_id = va_arg (ap, int))) + return 0; + if (!(mob_class = va_arg (ap, int))) + return 0; nullpo_retr (0, c = va_arg (ap, int *)); if (md->class == mob_class && md->master_id == src_id) @@ -8418,7 +8415,6 @@ int skill_use_pos (struct map_session_data *sd, int skill_castcancel (struct block_list *bl, int type) { int inf; - int ret = 0; nullpo_retr (0, bl); @@ -8439,22 +8435,16 @@ int skill_castcancel (struct block_list *bl, int type) if (!type) { if ((inf = skill_get_inf (sd->skillid)) == 2 || inf == 32) - ret = delete_timer (sd->skilltimer, skill_castend_pos); + delete_timer (sd->skilltimer, skill_castend_pos); else - ret = delete_timer (sd->skilltimer, skill_castend_id); - if (ret < 0) - printf ("delete timer error : skillid : %d\n", - sd->skillid); + delete_timer (sd->skilltimer, skill_castend_id); } else { if ((inf = skill_get_inf (sd->skillid_old)) == 2 || inf == 32) - ret = delete_timer (sd->skilltimer, skill_castend_pos); + delete_timer (sd->skilltimer, skill_castend_pos); else - ret = delete_timer (sd->skilltimer, skill_castend_id); - if (ret < 0) - printf ("delete timer error : skillid : %d\n", - sd->skillid_old); + delete_timer (sd->skilltimer, skill_castend_id); } sd->skilltimer = -1; clif_skillcastcancel (bl); @@ -8469,14 +8459,12 @@ int skill_castcancel (struct block_list *bl, int type) if (md->skilltimer != -1) { if ((inf = skill_get_inf (md->skillid)) == 2 || inf == 32) - ret = delete_timer (md->skilltimer, mobskill_castend_pos); + delete_timer (md->skilltimer, mobskill_castend_pos); else - ret = delete_timer (md->skilltimer, mobskill_castend_id); + delete_timer (md->skilltimer, mobskill_castend_id); md->skilltimer = -1; clif_skillcastcancel (bl); } - if (ret < 0) - printf ("delete timer error : skillid : %d\n", md->skillid); return 0; } return 1; @@ -9496,7 +9484,7 @@ int skill_update_heal_animation (struct map_session_data *sd) * ステータス異常終了タイマー *------------------------------------------ */ -int skill_status_change_timer (int tid, unsigned int tick, int id, int data) +void skill_status_change_timer (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) { int type = data; struct block_list *bl; @@ -9505,8 +9493,8 @@ int skill_status_change_timer (int tid, unsigned int tick, int id, int data) //short *sc_count; //使ってない? if ((bl = map_id2bl (id)) == NULL) - return 0; //該当IDがすでに消滅しているというのはいかにもありそうなのでスルーしてみる - nullpo_retr (0, sc_data = battle_get_sc_data (bl)); + return; //該当IDがすでに消滅しているというのはいかにもありそうなのでスルーしてみる + nullpo_retv (sc_data = battle_get_sc_data (bl)); if (bl->type == BL_PC) sd = (struct map_session_data *) bl; @@ -9543,7 +9531,7 @@ int skill_status_change_timer (int tid, unsigned int tick, int id, int data) tick, skill_status_change_timer, bl->id, data); - return 0; + return; } } break; @@ -9562,7 +9550,7 @@ int skill_status_change_timer (int tid, unsigned int tick, int id, int data) 1000 + tick, skill_status_change_timer, bl->id, data); - return 0; + return; } } break; @@ -9581,7 +9569,7 @@ int skill_status_change_timer (int tid, unsigned int tick, int id, int data) 250 + tick, skill_status_change_timer, bl->id, data); - return 0; + return; } } break; @@ -9599,7 +9587,7 @@ int skill_status_change_timer (int tid, unsigned int tick, int id, int data) 250 + tick, skill_status_change_timer, bl->id, data); - return 0; + return; } } break; @@ -9613,7 +9601,7 @@ int skill_status_change_timer (int tid, unsigned int tick, int id, int data) sc_data[type].timer = add_timer (1000 * 600 + tick, skill_status_change_timer, bl->id, data); - return 0; + return; } } break; @@ -9626,7 +9614,7 @@ int skill_status_change_timer (int tid, unsigned int tick, int id, int data) sc_data[type].timer = add_timer (1000 + tick, skill_status_change_timer, bl->id, data); - return 0; + return; } break; @@ -9642,7 +9630,7 @@ int skill_status_change_timer (int tid, unsigned int tick, int id, int data) sc_data[type].timer = add_timer (150 + tick, skill_status_change_timer, bl->id, data); - return 0; + return; } } break; @@ -9654,7 +9642,7 @@ int skill_status_change_timer (int tid, unsigned int tick, int id, int data) add_timer (1000 * 600 + tick, skill_status_change_timer, bl->id, data); sc_data[type].val2 = 1; - return 0; + return; } break; @@ -9678,7 +9666,7 @@ int skill_status_change_timer (int tid, unsigned int tick, int id, int data) (unit->group->skill_id, unit->group->skill_lv) + tick, skill_status_change_timer, bl->id, data); - return 0; + return; } break; @@ -9697,7 +9685,7 @@ int skill_status_change_timer (int tid, unsigned int tick, int id, int data) (unit->group->skill_id, unit->group->skill_lv) / 10 + tick, skill_status_change_timer, bl->id, data); - return 0; + return; } break; @@ -9716,7 +9704,7 @@ int skill_status_change_timer (int tid, unsigned int tick, int id, int data) sc_data[type].timer = add_timer (1000 + tick, skill_status_change_timer, bl->id, data); - return 0; + return; } else if ((--sc_data[type].val3) > 0) { @@ -9740,7 +9728,7 @@ int skill_status_change_timer (int tid, unsigned int tick, int id, int data) sc_data[type].timer = add_timer (1000 + tick, skill_status_change_timer, bl->id, data); - return 0; + return; } break; case SC_POISON: @@ -9796,7 +9784,7 @@ int skill_status_change_timer (int tid, unsigned int tick, int id, int data) 10000 + tick, skill_status_change_timer, bl->id, data); - return 0; + return; } if (sd->status.max_hp <= sd->status.hp) skill_status_change_end (&sd->bl, SC_TENSIONRELAX, -1); @@ -9819,7 +9807,7 @@ int skill_status_change_timer (int tid, unsigned int tick, int id, int data) sc_data[type].timer = add_timer (1000 * 600 + tick, skill_status_change_timer, bl->id, data); - return 0; + return; case SC_DANCING: //ダンススキルの時間SP消費 { @@ -9869,7 +9857,7 @@ int skill_status_change_timer (int tid, unsigned int tick, int id, int data) 1000 + tick, skill_status_change_timer, bl->id, data); - return 0; + return; } } } @@ -9885,7 +9873,7 @@ int skill_status_change_timer (int tid, unsigned int tick, int id, int data) 15000 + tick, skill_status_change_timer, bl->id, data); - return 0; + return; } } break; @@ -9899,7 +9887,7 @@ int skill_status_change_timer (int tid, unsigned int tick, int id, int data) 10000 + tick, skill_status_change_timer, bl->id, data); - return 0; + return; } } break; @@ -9916,7 +9904,7 @@ int skill_status_change_timer (int tid, unsigned int tick, int id, int data) 60000 + tick, skill_status_change_timer, bl->id, data); - return 0; + return; } } break; @@ -9934,7 +9922,7 @@ int skill_status_change_timer (int tid, unsigned int tick, int id, int data) 1000 + tick, skill_status_change_timer, bl->id, data); - return 0; + return; } break; @@ -9944,7 +9932,7 @@ int skill_status_change_timer (int tid, unsigned int tick, int id, int data) } - return skill_status_change_end (bl, type, tid); + skill_status_change_end (bl, type, tid); } /*========================================== @@ -11153,8 +11141,7 @@ struct skill_unit_group *skill_initunitgroup (struct block_list *src, group->group_id = skill_unit_group_newid++; if (skill_unit_group_newid <= 0) skill_unit_group_newid = 10; - group->unit = - (struct skill_unit *) aCalloc (count, sizeof (struct skill_unit)); + CREATE (group->unit, struct skill_unit, count); group->unit_count = count; group->val1 = group->val2 = 0; group->skill_id = skillid; @@ -11493,15 +11480,13 @@ int skill_unit_timer_sub (struct block_list *bl, va_list ap) * スキルユニットタイマー処理 *------------------------------------------ */ -int skill_unit_timer (int tid, unsigned int tick, int id, int data) +void skill_unit_timer (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) { map_freeblock_lock (); map_foreachobject (skill_unit_timer_sub, BL_SKILL, tick); map_freeblock_unlock (); - - return 0; } /*========================================== @@ -11814,19 +11799,19 @@ int skill_unit_move_unit_group (struct skill_unit_group *group, int m, int dx, static int scan_stat (char *statname) { - if (!strcmpi (statname, "str")) + if (!strcasecmp (statname, "str")) return SP_STR; - if (!strcmpi (statname, "dex")) + if (!strcasecmp (statname, "dex")) return SP_DEX; - if (!strcmpi (statname, "agi")) + if (!strcasecmp (statname, "agi")) return SP_AGI; - if (!strcmpi (statname, "vit")) + if (!strcasecmp (statname, "vit")) return SP_VIT; - if (!strcmpi (statname, "int")) + if (!strcasecmp (statname, "int")) return SP_INT; - if (!strcmpi (statname, "luk")) + if (!strcasecmp (statname, "luk")) return SP_LUK; - if (!strcmpi (statname, "none")) + if (!strcasecmp (statname, "none")) return 0; else @@ -11911,18 +11896,18 @@ int skill_readdb (void) skill_db[i].num[k] = (split2[k]) ? atoi (split2[k]) : atoi (split2[0]); - if (strcmpi (split[9], "yes") == 0) + if (strcasecmp (split[9], "yes") == 0) skill_db[i].castcancel = 1; else skill_db[i].castcancel = 0; skill_db[i].cast_def_rate = atoi (split[9]); skill_db[i].inf2 = atoi (split[10]); skill_db[i].maxcount = atoi (split[11]); - if (strcmpi (split[13], "weapon") == 0) + if (strcasecmp (split[13], "weapon") == 0) skill_db[i].skill_type = BF_WEAPON; - else if (strcmpi (split[12], "magic") == 0) + else if (strcasecmp (split[12], "magic") == 0) skill_db[i].skill_type = BF_MAGIC; - else if (strcmpi (split[12], "misc") == 0) + else if (strcasecmp (split[12], "misc") == 0) skill_db[i].skill_type = BF_MISC; else skill_db[i].skill_type = 0; @@ -11938,12 +11923,12 @@ int skill_readdb (void) skill_db[i].blewcount[k] = (split2[k]) ? atoi (split2[k]) : atoi (split2[0]); - if (!strcmpi (split[15], "passive")) + if (!strcasecmp (split[15], "passive")) { skill_pool_register (i); skill_db[i].poolflags = SKILL_POOL_FLAG; } - else if (!strcmpi (split[15], "active")) + else if (!strcasecmp (split[15], "active")) { skill_pool_register (i); skill_db[i].poolflags = SKILL_POOL_FLAG | SKILL_POOL_ACTIVE; @@ -12086,29 +12071,29 @@ int skill_readdb (void) skill_db[i].weapon |= 1 << l; } - if (strcmpi (split[8], "hiding") == 0) + if (strcasecmp (split[8], "hiding") == 0) skill_db[i].state = ST_HIDING; - else if (strcmpi (split[8], "cloaking") == 0) + else if (strcasecmp (split[8], "cloaking") == 0) skill_db[i].state = ST_CLOAKING; - else if (strcmpi (split[8], "hidden") == 0) + else if (strcasecmp (split[8], "hidden") == 0) skill_db[i].state = ST_HIDDEN; - else if (strcmpi (split[8], "riding") == 0) + else if (strcasecmp (split[8], "riding") == 0) skill_db[i].state = ST_RIDING; - else if (strcmpi (split[8], "falcon") == 0) + else if (strcasecmp (split[8], "falcon") == 0) skill_db[i].state = ST_FALCON; - else if (strcmpi (split[8], "cart") == 0) + else if (strcasecmp (split[8], "cart") == 0) skill_db[i].state = ST_CART; - else if (strcmpi (split[8], "shield") == 0) + else if (strcasecmp (split[8], "shield") == 0) skill_db[i].state = ST_SHIELD; - else if (strcmpi (split[8], "sight") == 0) + else if (strcasecmp (split[8], "sight") == 0) skill_db[i].state = ST_SIGHT; - else if (strcmpi (split[8], "explosionspirits") == 0) + else if (strcasecmp (split[8], "explosionspirits") == 0) skill_db[i].state = ST_EXPLOSIONSPIRITS; - else if (strcmpi (split[8], "recover_weight_rate") == 0) + else if (strcasecmp (split[8], "recover_weight_rate") == 0) skill_db[i].state = ST_RECOV_WEIGHT_RATE; - else if (strcmpi (split[8], "move_enable") == 0) + else if (strcasecmp (split[8], "move_enable") == 0) skill_db[i].state = ST_MOVE_ENABLE; - else if (strcmpi (split[8], "water") == 0) + else if (strcasecmp (split[8], "water") == 0) skill_db[i].state = ST_WATER; else skill_db[i].state = ST_NONE; @@ -12275,10 +12260,10 @@ int skill_readdb (void) void skill_reload (void) { /* - * + * * * - * + * */ do_init_skill (); @@ -12292,12 +12277,6 @@ int do_init_skill (void) { skill_readdb (); - add_timer_func_list (skill_unit_timer, "skill_unit_timer"); - add_timer_func_list (skill_castend_id, "skill_castend_id"); - add_timer_func_list (skill_castend_pos, "skill_castend_pos"); - add_timer_func_list (skill_timerskill, "skill_timerskill"); - add_timer_func_list (skill_status_change_timer, - "skill_status_change_timer"); add_timer_interval (gettick () + SKILLUNITTIMER_INVERVAL, skill_unit_timer, 0, 0, SKILLUNITTIMER_INVERVAL); diff --git a/src/map/skill.h b/src/map/skill.h index 08f2e18..d0a698c 100644 --- a/src/map/skill.h +++ b/src/map/skill.h @@ -2,6 +2,8 @@ #ifndef _SKILL_H_ #define _SKILL_H_ +#include "../common/timer.h" + #include "map.h" #include "magic.h" @@ -149,7 +151,7 @@ int skill_status_effect (struct block_list *bl, int type, int val1, int val2, int skill_status_change_start (struct block_list *bl, int type, int val1, int val2, int val3, int val4, int tick, int flag); -int skill_status_change_timer (int tid, unsigned int tick, int id, int data); +void skill_status_change_timer (timer_id, tick_t, custom_id_t, custom_data_t); int skill_status_change_active (struct block_list *bl, int type); // [fate] int skill_encchant_eremental_end (struct block_list *bl, int type); int skill_status_change_end (struct block_list *bl, int type, int tid); diff --git a/src/map/storage.c b/src/map/storage.c index 84dedb3..4a0d934 100644 --- a/src/map/storage.c +++ b/src/map/storage.c @@ -7,7 +7,6 @@ #include "../common/db.h" #include "../common/nullpo.h" -#include "../common/malloc.h" #include "storage.h" #include "chrif.h" @@ -40,18 +39,16 @@ int storage_comp_item (const void *_i1, const void *_i2) return i1->nameid - i2->nameid; } -static int guild_storage_db_final (void *key, void *data, va_list ap) +static void guild_storage_db_final (db_key_t key, db_val_t data, va_list ap) { struct guild_storage *gstor = (struct guild_storage *) data; free (gstor); - return 0; } -static int storage_db_final (void *key, void *data, va_list ap) +static void storage_db_final (db_key_t key, db_val_t data, va_list ap) { struct storage *stor = (struct storage *) data; free (stor); - return 0; } void sortage_sortitem (struct storage *stor) @@ -87,7 +84,7 @@ void do_final_storage (void) // by [MC Cameri] numdb_final (guild_storage_db, guild_storage_db_final); } -static int storage_reconnect_sub (void *key, void *data, va_list ap) +static void storage_reconnect_sub (db_key_t key, db_val_t data, va_list ap) { //Parses storage and saves 'dirty' ones upon reconnect. [Skotlex] int type = va_arg (ap, int); if (type) @@ -102,7 +99,6 @@ static int storage_reconnect_sub (void *key, void *data, va_list ap) if (stor->dirty && stor->storage_status == 0) //Save closed storages. storage_storage_save (stor->account_id, stor->dirty == 2 ? 1 : 0); } - return 0; } //Function to be invoked upon server reconnection to char. To save all 'dirty' storages [Skotlex @@ -118,7 +114,7 @@ struct storage *account2storage (int account_id) (struct storage *) numdb_search (storage_db, account_id); if (stor == NULL) { - stor = (struct storage *) aCallocA (sizeof (struct storage), 1); + CREATE (stor, struct storage, 1); stor->account_id = account_id; numdb_insert (storage_db, stor->account_id, stor); } @@ -481,13 +477,7 @@ struct guild_storage *guild2storage (int guild_id) guild_id); if (gs == NULL) { - gs = (struct guild_storage *) - aCallocA (sizeof (struct guild_storage), 1); - if (gs == NULL) - { - printf ("storage: out of memory!\n"); - exit (0); - } + CREATE (gs, struct guild_storage, 1); gs->guild_id = guild_id; numdb_insert (guild_storage_db, gs->guild_id, gs); } diff --git a/src/map/tmw.c b/src/map/tmw.c index c04c9c8..3487c1d 100644 --- a/src/map/tmw.c +++ b/src/map/tmw.c @@ -8,7 +8,6 @@ #include "../common/socket.h" #include "../common/timer.h" -#include "../common/malloc.h" #include "../common/version.h" #include "../common/nullpo.h" @@ -30,7 +29,7 @@ #include "skill.h" #include "storage.h" #include "trade.h" - + int tmw_CheckChatSpam (struct map_session_data *sd, char *message) { nullpo_retr (1, sd); diff --git a/src/tool/Makefile b/src/tool/Makefile index 87393fb..8d51c25 100644 --- a/src/tool/Makefile +++ b/src/tool/Makefile @@ -1,15 +1,13 @@ include ../../make.defs -COBJS=../common/timer.o ../common/malloc.o ../common/socket.o ../common/lock.o ../common/db.o ../char/int_storage.o ../char/inter.o ../char/int_party.o ../char/int_guild.o -MOBJS=../common/socket.o ../common/timer.o ../common/db.o ../common/lock.o ../common/malloc.o ../char/int_guild.o ../char/int_party.o ../char/int_storage.o ../char/inter.o +OBJS =../common/timer.o ../common/socket.o ../common/db.o ../common/lock.o ../char/inter.o ../char/int_guild.o ../char/int_party.o ../char/int_storage.o all: adduser itemfrob mapfrob marriage-info eathena-monitor adduser: adduser.o ../common/socket.o -itemfrob: itemfrob.o ${COBJS} -mapfrob: mapfrob.o ${COBJS} -marriage-info: marriage-info.o ${MOBJS} +itemfrob: itemfrob.o ${OBJS} +mapfrob: mapfrob.o ${OBJS} +marriage-info: marriage-info.o ${OBJS} eathena-monitor: eathena-monitor.c - $(CC) $(CFLAGS) -o eathena-monitor eathena-monitor.c clean: rm -f adduser itemfrob mapfrob marriage-info eathena-monitor diff --git a/src/tool/eathena-monitor.c b/src/tool/eathena-monitor.c index 04a48cf..6e26706 100644 --- a/src/tool/eathena-monitor.c +++ b/src/tool/eathena-monitor.c @@ -27,7 +27,7 @@ #define SKIP_BLANK(ptr) ptr += skip_blank(ptr) -inline size_t skip_blank(const char* ptr) { +static inline size_t skip_blank(const char* ptr) { size_t i = 0; while ( (ptr[i] == ' ') || @@ -39,7 +39,7 @@ inline size_t skip_blank(const char* ptr) { } #define GOTO_EQL(ptr) ptr += goto_eql(ptr) -inline size_t goto_eql(const char* ptr) { +static inline size_t goto_eql(const char* ptr) { size_t i = 0; while ( (ptr[i] != '\0') && @@ -51,7 +51,7 @@ inline size_t goto_eql(const char* ptr) { } #define GOTO_EOL(ptr) ptr += goto_newline(ptr) -inline size_t goto_newline(const char* ptr) { +static inline size_t goto_newline(const char* ptr) { size_t i = 0; while ( (ptr[i] != '\0') && diff --git a/src/tool/itemfrob.c b/src/tool/itemfrob.c index bc9ff35..646ec73 100644 --- a/src/tool/itemfrob.c +++ b/src/tool/itemfrob.c @@ -4,6 +4,7 @@ #include #include #include "../common/mmo.h" +// Yes, this is intentional #include "../char/char.c" // Well, this is not terribly elegant, but I don't have that much time. @@ -37,7 +38,6 @@ int mmo_char_convert () fprintf (ofp, "%s" RETCODE, line); } } - fcloseall (); return 0; } @@ -128,8 +128,3 @@ int main (int argc, char *argv[]) return 0; } - -/* satisfy linker */ -void set_termfunc (void (*termfunc) (void)) -{ -}; diff --git a/src/tool/mapfrob.c b/src/tool/mapfrob.c index d410878..11983eb 100644 --- a/src/tool/mapfrob.c +++ b/src/tool/mapfrob.c @@ -4,6 +4,7 @@ #include #include #include "../common/mmo.h" +// Yes, this is intentional #include "../char/char.c" // Well, this is not terribly elegant, but I don't have that much time. @@ -63,7 +64,6 @@ int mmo_char_convert () fprintf (ofp, "%s" RETCODE, line); } } - fcloseall (); return 0; } @@ -127,8 +127,3 @@ int main (int argc, char *argv[]) return 0; } - -/* satisfy linker */ -void set_termfunc (void (*termfunc) (void)) -{ -}; diff --git a/src/tool/marriage-info.c b/src/tool/marriage-info.c index 9b91955..4d7cbc3 100644 --- a/src/tool/marriage-info.c +++ b/src/tool/marriage-info.c @@ -9,6 +9,7 @@ src/char/int_party.o src/char/int_storage.o src/char/inter.o #include #include "../login/login.h" #include "../common/mmo.h" +// Yes, this is intentional #include "../char/char.c" int mode; @@ -442,7 +443,6 @@ int mmo_char_dump() mmo_check_dumpworthy(&char_dat); } } - fcloseall(); return 0; } @@ -480,7 +480,3 @@ int main(int argc,char *argv[]) return 0; } - - -/* satisfy linker */ -void set_termfunc(void (*termfunc)(void)) {}; diff --git a/src/tool/moneycount/mmo.h b/src/tool/moneycount/mmo.h index 640065a..c7ab21f 100644 --- a/src/tool/moneycount/mmo.h +++ b/src/tool/moneycount/mmo.h @@ -310,20 +310,5 @@ enum }; -#ifndef LCCWIN32 -#ifndef strcmpi -#define strcmpi strcasecmp -#endif -#ifndef stricmp -#define stricmp strcasecmp -#endif -#ifndef strncmpi -#define strncmpi strncasecmp -#endif -#ifndef strnicmp -#define strnicmp strncasecmp -#endif -#endif - #endif // _MMO_H_ diff --git a/src/tool/skillfrob.c b/src/tool/skillfrob.c index ea68660..c7b6bb6 100644 --- a/src/tool/skillfrob.c +++ b/src/tool/skillfrob.c @@ -78,8 +78,3 @@ int main (int argc, char *argv[]) return 0; } - -/* satisfy linker */ -void set_termfunc (void (*termfunc) (void)) -{ -}; -- cgit v1.2.3-70-g09d2 From ef740ac0479a5a4f4240db63b84531599a26a983 Mon Sep 17 00:00:00 2001 From: Ben Longbons Date: Thu, 24 Mar 2011 20:24:47 -0700 Subject: Fix timer bugs in previous version The most visible effect of this was that the map-server would never actually connect with the char-server --- src/char/char.c | 1 - src/common/timer.c | 20 ++++++++------------ src/common/timer.h | 19 ++++++------------- src/map/map.c | 1 - src/map/npc.c | 2 ++ 5 files changed, 16 insertions(+), 27 deletions(-) diff --git a/src/char/char.c b/src/char/char.c index d340f1d..dc77c31 100644 --- a/src/char/char.c +++ b/src/char/char.c @@ -2337,7 +2337,6 @@ void parse_tologin (int fd) //-------------------------------- // Map-server anti-freeze system //-------------------------------- -typedef void (*timer_func) (timer_id, tick_t, custom_id_t, custom_data_t); void map_anti_freeze_system (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) { int i; diff --git a/src/common/timer.c b/src/common/timer.c index bf21c8e..915aeb4 100644 --- a/src/common/timer.c +++ b/src/common/timer.c @@ -20,7 +20,7 @@ static uint32_t free_timer_list_max, free_timer_list_pos; // timer_heap[0] is the size (greatest index into the heap) // timer_heap[1] is the first actual element // timer_heap_max increases 256 at a time and never decreases -static uint32_t timer_heap_max = 256; +static uint32_t timer_heap_max = 0; /// FIXME: refactor the code to put the size in a separate variable //nontrivial because indices get multiplied static timer_id *timer_heap = NULL; @@ -48,19 +48,14 @@ uint32_t gettick (void) static void push_timer_heap (timer_id index) { - if (timer_heap == NULL) + if (timer_heap == NULL || timer_heap[0] + 1 >= timer_heap_max) { timer_heap_max += 256; - CREATE (timer_heap, timer_id, timer_heap_max); + RECREATE (timer_heap, int, timer_heap_max); + memset (timer_heap + (timer_heap_max - 256), 0, sizeof (timer_id) * 256); } // timer_heap[0] is the greatest index into the heap, which increases timer_heap[0]++; - if (timer_heap[0] >= timer_heap_max) - { - timer_heap_max += 256; - RECREATE (timer_heap, timer_id, timer_heap_max); - memset (timer_heap + (timer_heap_max - 256), 0, 4 * 256); - } timer_id h = timer_heap[0]-1, i = (h - 1) / 2; while (h) @@ -104,7 +99,8 @@ static timer_id pop_timer_heap () uint32_t i = (h - 1) / 2; while (h) { - if (DIFF_TICK(timer_data[timer_heap[i + 1]].tick, timer_data[last].tick) <= 0) + if (DIFF_TICK (timer_data[timer_heap[i + 1]].tick, timer_data[last].tick) <= 0) + break; timer_heap[h + 1] = timer_heap[i + 1]; h = i; i = (h - 1) / 2; @@ -152,7 +148,7 @@ timer_id add_timer (tick_t tick, timer_func func, custom_id_t id, custom_data_t } timer_data[i].tick = tick; timer_data[i].func = func; - timer_data[i].id = id; + timer_data[i].id = id; timer_data[i].data = data; timer_data[i].type = TIMER_ONCE_AUTODEL; timer_data[i].interval = 1000; @@ -237,7 +233,7 @@ interdb_val_t do_timer (tick_t tick) free_timer_list_max += 256; RECREATE (free_timer_list, uint32_t, free_timer_list_max); memset (free_timer_list + (free_timer_list_max - 256), - 0, 256 * sizeof (timer_id)); + 0, 256 * sizeof (uint32_t)); } free_timer_list[free_timer_list_pos++] = i; break; diff --git a/src/common/timer.h b/src/common/timer.h index 4fa5db8..2a38e04 100644 --- a/src/common/timer.h +++ b/src/common/timer.h @@ -3,7 +3,8 @@ # include "sanity.h" -enum TIMER_TYPE { +enum TIMER_TYPE +{ TIMER_ONCE_AUTODEL = 1, TIMER_INTERVAL = 2, }; @@ -32,7 +33,7 @@ struct TimerData /// Type of timer - 0 initially enum TIMER_TYPE type; /// Repeat rate - uint32_t interval; + interdb_val_t interval; }; /// Server time, in milliseconds, since the epoch, @@ -44,24 +45,16 @@ tick_t gettick_nocache (void); /// the next 255 times tick_t gettick (void); -timer_id add_timer (tick_t tick, timer_func func, custom_id_t id, - custom_data_t data); -timer_id add_timer_interval (tick_t tick, timer_func func, custom_id_t id, - custom_data_t data, interdb_val_t interval); +timer_id add_timer (tick_t, timer_func, custom_id_t, custom_data_t); +timer_id add_timer_interval (tick_t, timer_func, custom_id_t, custom_data_t, interdb_val_t); void delete_timer (timer_id, timer_func); -tick_t addtick_timer (timer_id tid, interdb_val_t tick); +tick_t addtick_timer (timer_id, interdb_val_t); struct TimerData *get_timer (timer_id tid); /// Do all timers scheduled before tick, and return the number of milliseconds until the next timer happens interdb_val_t do_timer (tick_t tick); -// debugging -static void add_timer_func_list (timer_func, char *) __attribute__((deprecated)); -static inline void add_timer_func_list (timer_func UNUSED, char *UNUSED) {} -// used to just call free(), which doesn't matter when we're exiting -static void timer_final () __attribute__((deprecated)); -static inline void timer_final() {}; #endif // TIMER_H diff --git a/src/map/map.c b/src/map/map.c index 8261e49..7730b94 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -2113,7 +2113,6 @@ void do_final (void) delete_session (i); map_removenpc (); - timer_final (); numdb_final (id_db, NULL); strdb_final (map_db, NULL); diff --git a/src/map/npc.c b/src/map/npc.c index 54b13d8..85ac6e9 100644 --- a/src/map/npc.c +++ b/src/map/npc.c @@ -2236,6 +2236,8 @@ int do_final_npc (void) if (ev_db) strdb_final (ev_db, ev_db_final); + if (npcname_db) + strdb_final (npcname_db, NULL); for (i = START_NPC_NUM; i < npc_id; i++) { -- cgit v1.2.3-70-g09d2 From deec3c27f91a97d35aaf912422d1249ec609da05 Mon Sep 17 00:00:00 2001 From: Ben Longbons Date: Thu, 24 Mar 2011 22:57:06 -0700 Subject: Fix accidentally-named interdb_val_t --- src/common/timer.c | 8 ++++---- src/common/timer.h | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/common/timer.c b/src/common/timer.c index 915aeb4..f4be19b 100644 --- a/src/common/timer.c +++ b/src/common/timer.c @@ -159,7 +159,7 @@ timer_id add_timer (tick_t tick, timer_func func, custom_id_t id, custom_data_t } timer_id add_timer_interval (tick_t tick, timer_func func, custom_id_t id, - custom_data_t data, interdb_val_t interval) + custom_data_t data, interval_t interval) { timer_id tid = add_timer (tick, func, id, data); timer_data[tid].type = TIMER_INTERVAL; @@ -185,7 +185,7 @@ void delete_timer (timer_id id, timer_func func) timer_data[id].tick -= 60 * 60 * 1000; } -tick_t addtick_timer (timer_id tid, interdb_val_t tick) +tick_t addtick_timer (timer_id tid, interval_t tick) { return timer_data[tid].tick += tick; } @@ -195,12 +195,12 @@ struct TimerData *get_timer (timer_id tid) return &timer_data[tid]; } -interdb_val_t do_timer (tick_t tick) +interval_t do_timer (tick_t tick) { timer_id i; /// Number of milliseconds until it calls this again // this says to wait 1 sec if all timers get popped - interdb_val_t nextmin = 1000; + interval_t nextmin = 1000; while ((i = top_timer_heap ()) != (timer_id)-1) { diff --git a/src/common/timer.h b/src/common/timer.h index 2a38e04..e363a56 100644 --- a/src/common/timer.h +++ b/src/common/timer.h @@ -13,7 +13,7 @@ enum TIMER_TYPE // TODO replace with signed 64-bit to make code more clear and protect from the future typedef uint32_t tick_t; -typedef uint32_t interdb_val_t; +typedef uint32_t interval_t; typedef uint32_t timer_id; // BUG: pointers are stored in here typedef int32_t custom_id_t; @@ -33,7 +33,7 @@ struct TimerData /// Type of timer - 0 initially enum TIMER_TYPE type; /// Repeat rate - interdb_val_t interval; + interval_t interval; }; /// Server time, in milliseconds, since the epoch, @@ -46,14 +46,14 @@ tick_t gettick_nocache (void); tick_t gettick (void); timer_id add_timer (tick_t, timer_func, custom_id_t, custom_data_t); -timer_id add_timer_interval (tick_t, timer_func, custom_id_t, custom_data_t, interdb_val_t); +timer_id add_timer_interval (tick_t, timer_func, custom_id_t, custom_data_t, interval_t); void delete_timer (timer_id, timer_func); -tick_t addtick_timer (timer_id, interdb_val_t); +tick_t addtick_timer (timer_id, interval_t); struct TimerData *get_timer (timer_id tid); /// Do all timers scheduled before tick, and return the number of milliseconds until the next timer happens -interdb_val_t do_timer (tick_t tick); +interval_t do_timer (tick_t tick); -- cgit v1.2.3-70-g09d2 From 723fb5d3431b847526c433a13aa74485cfb564a3 Mon Sep 17 00:00:00 2001 From: Ben Longbons Date: Mon, 4 Apr 2011 17:38:25 -0700 Subject: Fix ## variables --- src/char/char.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/char/char.c b/src/char/char.c index dc77c31..59dea17 100644 --- a/src/char/char.c +++ b/src/char/char.c @@ -2839,9 +2839,9 @@ void parse_frommap (int fd) // loginサーバーへ送る if (login_fd > 0) { // don't send request if no login-server - WFIFOW (login_fd, 0) = 0x2728; memcpy (WFIFOP (login_fd, 0), RFIFOP (fd, 0), RFIFOW (fd, 2)); + WFIFOW (login_fd, 0) = 0x2728; WFIFOSET (login_fd, WFIFOW (login_fd, 2)); } // ワールドへの同垢ログインがなければmapサーバーに送る必要はない -- cgit v1.2.3-70-g09d2