diff options
43 files changed, 343 insertions, 394 deletions
@@ -1,12 +1,21 @@ # files generated during make *.o +src/char/char char-server -ladmin +src/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 @@ -1,12 +1,40 @@ -# $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 +tools: tool eathena-monitor -tools: - cd src/tool && $(MAKE) $(MKDEF) && cd .. + +common: src/common + ${MAKE} -C src/common +login-server: common src/login + ${MAKE} -C src/login + ${CP} src/login/login login-server +char-server: common src/char + ${MAKE} -C src/char + ${CP} src/char/char char-server +map-server: common src/map + ${MAKE} -C src/map + ${CP} src/map/map map-server +ladmin: common src/ladmin + ${MAKE} -C src/ladmin + +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 +tool: common src/tool + ${MAKE} -C src/tool +eathena-monitor: tool + ${CP} src/tool/eathena-monitor . +clean-tools: + ${MAKE} -C src/tool clean @@ -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 33379d3..5ac11d4 100644 --- a/src/char/char.c +++ b/src/char/char.c @@ -18,12 +18,12 @@ #include <stdarg.h> #include <sys/wait.h> -#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 <string.h> #include <stdio.h> 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 <stdio.h> #include <stdlib.h> #include <string.h> 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 <string.h> #include <stdlib.h> @@ -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 56cac60..e8dcb3b 100644 --- a/src/ladmin/ladmin.c +++ b/src/ladmin/ladmin.c @@ -22,11 +22,11 @@ #include <stdarg.h> // valist #include <ctype.h> // 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 <string.h> #include <stdio.h> -#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 <netdb.h> #include <sys/wait.h> -#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 <time.h> #include <unistd.h> -#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 <stdlib.h> #include <string.h> -#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 <sys/types.h> #include <time.h> -#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 <time.h> -#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 <fcntl.h> #include <string.h> -#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 <stdlib.h> #include <string.h> -#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.l b/src/map/magic-interpreter-lexer.l index 2c9792f..2c9792f 100644 --- a/src/map/magic-interpreter.l +++ b/src/map/magic-interpreter-lexer.l 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 <string.h> #include <math.h> -#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/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 <netdb.h> #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 <time.h> #include <sys/time.h> #include <netinet/in.h> -#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 <stdarg.h> #include <string.h> -#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 <math.h> #include <time.h> -#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 <string.h> #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 <ctype.h> #include <time.h> -#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 <time.h> #include <math.h> -#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 <string.h> #include <time.h> -#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 <string.h> #include <time.h> -#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/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 <waszi@evil.org.pl> + * Original Author: Bartosz Waszak <waszi@evil.org.pl> + * Rewrite Author: Ben Longbons <b.r.longbons@gmail.com> * License: GPL * Compilation: * gcc -o eathena-monitor eathena-monitor.c -*/ + */ #include <unistd.h> #include <stdio.h> #include <string.h> #include <stdlib.h> #include <sys/types.h> -#include <sys/stat.h> -#if !defined(linux) && (defined(__sgi) || defined(__sun__) || defined(__sun) || defined(__sparc) || defined(__sparc__)) -#include <sys/statfs.h> -#endif - -#if defined (__FreeBSD__) || defined (__OpenBSD__) || defined (__NetBSD__) || defined (__APPLE__) -#include <sys/param.h> -#include <sys/mount.h> -#endif - -#if defined(linux) || defined(__CYGWIN32__) || defined(__hpux) -#include <sys/vfs.h> -#endif - -#include <dirent.h> -#include <errno.h> #include <time.h> #include <fcntl.h> #include <sys/wait.h> #include <signal.h> #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; } } 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 <stdio.h> #include <stdlib.h> -#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} |