summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.travis.yml21
-rw-r--r--COPYING12
-rw-r--r--Makefile (renamed from GNUmakefile)36
-rw-r--r--README34
-rw-r--r--doc/LICENCE340
-rw-r--r--doc/LICENCE_JA416
-rw-r--r--doc/mapserver-logging9
-rw-r--r--gpl-3.0.txt674
-rw-r--r--make.defs8
-rw-r--r--src/char/char.cpp3524
-rw-r--r--src/char/char.hpp30
-rw-r--r--src/char/int_guild.cpp1802
-rw-r--r--src/char/int_guild.hpp16
-rw-r--r--src/char/int_party.cpp587
-rw-r--r--src/char/int_party.hpp11
-rw-r--r--src/char/int_storage.cpp570
-rw-r--r--src/char/int_storage.hpp17
-rw-r--r--src/char/inter.cpp535
-rw-r--r--src/char/inter.hpp15
-rw-r--r--src/common/const_array.hpp175
-rw-r--r--src/common/core.cpp75
-rw-r--r--src/common/core.hpp8
-rw-r--r--src/common/cxxstdio.cpp33
-rw-r--r--src/common/cxxstdio.hpp297
-rw-r--r--src/common/db.cpp545
-rw-r--r--src/common/db.hpp181
-rw-r--r--src/common/extract.cpp68
-rw-r--r--src/common/extract.hpp166
-rw-r--r--src/common/grfio.cpp216
-rw-r--r--src/common/grfio.hpp17
-rw-r--r--src/common/lock.cpp46
-rw-r--r--src/common/lock.hpp11
-rw-r--r--src/common/md5calc.cpp39
-rw-r--r--src/common/md5calc.hpp20
-rw-r--r--src/common/mmo.hpp336
-rw-r--r--src/common/mt_rand.cpp117
-rw-r--r--src/common/mt_rand.hpp24
-rw-r--r--src/common/nullpo.cpp69
-rw-r--r--src/common/nullpo.hpp57
-rw-r--r--src/common/operators.hpp47
-rw-r--r--src/common/random.cpp8
-rw-r--r--src/common/random.hpp69
-rw-r--r--src/common/random.t.hpp23
-rw-r--r--src/common/random2.hpp74
-rw-r--r--src/common/sanity.hpp61
-rw-r--r--src/common/socket.cpp264
-rw-r--r--src/common/socket.hpp192
-rw-r--r--src/common/timer.cpp334
-rw-r--r--src/common/timer.hpp64
-rw-r--r--src/common/timer.t.hpp66
-rw-r--r--src/common/utils.cpp107
-rw-r--r--src/common/utils.hpp128
-rw-r--r--src/common/utils2.hpp230
-rw-r--r--src/ladmin/ladmin.cpp6393
-rw-r--r--src/ladmin/ladmin.hpp11
-rw-r--r--src/login/login.cpp4614
-rw-r--r--src/login/login.hpp41
-rw-r--r--src/map/atcommand.cpp6897
-rw-r--r--src/map/atcommand.hpp225
-rw-r--r--src/map/battle.cpp5401
-rw-r--r--src/map/battle.hpp540
-rw-r--r--src/map/battle.t.hpp223
-rw-r--r--src/map/chat.cpp308
-rw-r--r--src/map/chat.hpp27
-rw-r--r--src/map/chrif.cpp899
-rw-r--r--src/map/chrif.hpp52
-rw-r--r--src/map/clif.cpp9899
-rw-r--r--src/map/clif.hpp412
-rw-r--r--src/map/clif.t.hpp21
-rw-r--r--src/map/grfio.cpp72
-rw-r--r--src/map/grfio.hpp15
-rw-r--r--src/map/guild.cpp1922
-rw-r--r--src/map/guild.hpp95
-rw-r--r--src/map/intif.cpp1106
-rw-r--r--src/map/intif.hpp81
-rw-r--r--src/map/itemdb.cpp611
-rw-r--r--src/map/itemdb.hpp132
-rw-r--r--src/map/magic-expr-eval.hpp32
-rw-r--r--src/map/magic-expr.cpp1310
-rw-r--r--src/map/magic-expr.hpp57
-rw-r--r--src/map/magic-interpreter-aux.hpp16
-rw-r--r--src/map/magic-interpreter-base.cpp347
-rw-r--r--src/map/magic-interpreter-lexer.lpp179
-rw-r--r--src/map/magic-interpreter-parser.ypp708
-rw-r--r--src/map/magic-interpreter.hpp277
-rw-r--r--src/map/magic-interpreter.t.hpp159
-rw-r--r--src/map/magic-stmt.cpp1207
-rw-r--r--src/map/magic.cpp80
-rw-r--r--src/map/magic.hpp32
-rw-r--r--src/map/map.cpp1629
-rw-r--r--src/map/map.hpp786
-rw-r--r--src/map/map.t.hpp560
-rw-r--r--src/map/mob.cpp4103
-rw-r--r--src/map/mob.hpp214
-rw-r--r--src/map/mob.t.hpp41
-rw-r--r--src/map/npc.cpp1625
-rw-r--r--src/map/npc.hpp91
-rw-r--r--src/map/party.cpp414
-rw-r--r--src/map/party.hpp84
-rw-r--r--src/map/path.cpp305
-rw-r--r--src/map/pc.cpp7280
-rw-r--r--src/map/pc.hpp356
-rw-r--r--src/map/pc.t.hpp44
-rw-r--r--src/map/script.cpp6627
-rw-r--r--src/map/script.hpp77
-rw-r--r--src/map/skill-pools.cpp121
-rw-r--r--src/map/skill.cpp12155
-rw-r--r--src/map/skill.hpp936
-rw-r--r--src/map/skill.t.hpp116
-rw-r--r--src/map/storage.cpp627
-rw-r--r--src/map/storage.hpp61
-rw-r--r--src/map/tmw.cpp125
-rw-r--r--src/map/tmw.hpp15
-rw-r--r--src/map/trade.cpp229
-rw-r--r--src/map/trade.hpp16
-rw-r--r--src/poison.hpp16
-rw-r--r--src/tool/adduser.cpp115
-rw-r--r--src/tool/backup100
-rw-r--r--src/tool/cgi/addaccount.cgi204
-rw-r--r--src/tool/checkversion85
-rw-r--r--src/tool/convert.cpp302
-rw-r--r--src/tool/eathena-monitor.cpp125
-rw-r--r--src/tool/getlogincount122
-rwxr-xr-xsrc/tool/indent.sh8
-rwxr-xr-xsrc/tool/ipcheck.rb82
-rw-r--r--src/tool/itemfrob.cpp130
-rw-r--r--src/tool/itemsearch.cpp136
-rw-r--r--src/tool/ladmin3793
-rw-r--r--src/tool/mapcheck.sh34
-rw-r--r--src/tool/mapchecker.sh56
-rw-r--r--src/tool/mapfrob.cpp129
-rw-r--r--src/tool/marriage-info.cpp482
-rwxr-xr-xsrc/tool/marriage-info.sh20
-rw-r--r--src/tool/moneycount/athena_text.cpp263
-rw-r--r--src/tool/moneycount/athena_text.hpp9
-rw-r--r--src/tool/moneycount/inf.cpp1482
-rw-r--r--src/tool/moneycount/inf.hpp228
-rw-r--r--src/tool/moneycount/main.cpp180
-rw-r--r--src/tool/moneycount/mmo.hpp309
-rw-r--r--src/tool/moneycount/portability_exceptions.hpp33
-rw-r--r--src/tool/moneycount/portability_fixes.cpp39
-rw-r--r--src/tool/moneycount/portability_fixes.hpp127
-rw-r--r--src/tool/skillfrob.cpp80
-rwxr-xr-xsrc/tool/stats.sh44
-rw-r--r--src/warnings.hpp672
-rw-r--r--src/webserver/GNUmakefile7
-rw-r--r--src/webserver/doc/API.txt50
-rw-r--r--src/webserver/doc/README11
-rw-r--r--src/webserver/generate.cpp35
-rw-r--r--src/webserver/htmlstyle.cpp45
-rw-r--r--src/webserver/logs.cpp8
-rw-r--r--src/webserver/main.cpp145
-rw-r--r--src/webserver/pages/about.cpp6
-rw-r--r--src/webserver/pages/notdone.cpp6
-rw-r--r--src/webserver/pages/sample.cpp22
-rw-r--r--src/webserver/parse.cpp132
-rw-r--r--warnings27
157 files changed, 28931 insertions, 76830 deletions
diff --git a/.travis.yml b/.travis.yml
index 09037ed..2722936 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -12,14 +12,11 @@ notifications:
on_failure: always
## Are we going to want this on or off?
irc:
- # TMW irc doesn't work for some reason; freenode does ...
- # I'm leaving it like this because it's what I'd like to use.
- channels: "irc.themanaworld.org#tmw-dev"
+ channels: "chat.freenode.net#tmwa"
on_success: always
on_failure: always
## Commands before installing prerequisites
-before_install: export CC=${REAL_CC} CXX=${REAL_CXX}
# before_install: git submodule update --init --recursive
## Install prerequisites
@@ -39,26 +36,22 @@ install:
## Main test script
script:
- - make -k -j2 CC=${REAL_CC} CXX=${REAL_CXX}
+ - make -k -j2 CXX=${REAL_CXX} CPPFLAGS=-DQUIET
## Do something after the main test script
# after_script: ...
### The rest of the file creates a build matrix
-### containing gcc-4.4 through gcc-4.7 and clang-3.1
+### containing gcc-4.6 through gcc-4.7 and clang-3.1
## This doesn't work - travis defaults to plain gcc if unknown
-# compiler: gcc-4.4
-# compiler: gcc-4.5
# compiler: gcc-4.6
# compiler: gcc-4.7
# compiler: clang
## Environment variables to expand the build matrix
-## Needed because compiler: gcc overwrites CC and CXX
+## Needed because 'compiler: gcc' overwrites CXX
env:
- - REAL_CC=gcc-4.4 REAL_CXX=g++-4.4
- - REAL_CC=gcc-4.5 REAL_CXX=g++-4.5
- - REAL_CC=gcc-4.6 REAL_CXX=g++-4.6
- - REAL_CC=gcc-4.7 REAL_CXX=g++-4.7
- - REAL_CC=clang REAL_CXX=clang++
+ - REAL_CXX=g++-4.6
+ - REAL_CXX=g++-4.7
+ - REAL_CXX=clang++
diff --git a/COPYING b/COPYING
new file mode 100644
index 0000000..a5bc77a
--- /dev/null
+++ b/COPYING
@@ -0,0 +1,12 @@
+TmwAthena - an MMORPG server
+
+This software is available under GPL3+. See gpl-3.0.txt for specifics.
+
+
+History:
+
+Originally, tmwAthena was forked from eAthena in 2004.
+We don't have a list of copyright holders from this time.
+
+Until 2012, tmwAthena was GPL2+ and did not put per-file copyright notices.
+A list of copyright holders during this time is in the git history.
diff --git a/GNUmakefile b/Makefile
index bf270b4..56ab981 100644
--- a/GNUmakefile
+++ b/Makefile
@@ -5,7 +5,7 @@ default: login-server char-server map-server ladmin eathena-monitor
.DELETE_ON_ERROR:
include make.defs
-.PHONY: all clean common
+.PHONY: all clean common most
# With no prerequisites, no target should ever be implicitly deleted.
# With any prerequisites, those targets won't be (no patterns).
.SECONDARY:
@@ -36,17 +36,15 @@ ${BUILD_DIR}/map/%.o: src/map/%.cpp | ${BUILD_DIR}/map/.
$(COMPILE.cpp) -o $@ $<
${BUILD_DIR}/tool/%.o: src/tool/%.cpp | ${BUILD_DIR}/tool/.
$(COMPILE.cpp) -o $@ $<
-${BUILD_DIR}/webserver/%.o: src/webserver/%.cpp | ${BUILD_DIR}/webserver/.
- $(COMPILE.cpp) -o $@ $<
-${BUILD_DIR}/webserver/pages/%.o: src/webserver/pages/%.cpp | ${BUILD_DIR}/webserver/pages/.
- $(COMPILE.cpp) -o $@ $<
-PROGS = login-server char-server map-server ladmin eathena-monitor webserver
+MOSTPROGS = login-server char-server ladmin eathena-monitor
+PROGS = ${MOSTPROGS} map-server
# Things to actually make
all: ${PROGS}
+most: ${MOSTPROGS}
clean:
rm -rf ${PROGS} ${BUILD_DIR}/
-common: ${BUILD_DIR}/common/core.o ${BUILD_DIR}/common/db.o ${BUILD_DIR}/common/grfio.o ${BUILD_DIR}/common/lock.o ${BUILD_DIR}/common/md5calc.o ${BUILD_DIR}/common/mt_rand.o ${BUILD_DIR}/common/nullpo.o ${BUILD_DIR}/common/socket.o ${BUILD_DIR}/common/timer.o ${BUILD_DIR}/common/utils.o
+common: ${BUILD_DIR}/common/core.o ${BUILD_DIR}/common/db.o ${BUILD_DIR}/common/lock.o ${BUILD_DIR}/common/md5calc.o ${BUILD_DIR}/common/random.o ${BUILD_DIR}/common/nullpo.o ${BUILD_DIR}/common/socket.o ${BUILD_DIR}/common/timer.o ${BUILD_DIR}/common/utils.o ${BUILD_DIR}/common/cxxstdio.o ${BUILD_DIR}/common/extract.o
# Top level programs
login-server: ${BUILD_DIR}/login/login
@@ -59,20 +57,16 @@ ladmin: ${BUILD_DIR}/ladmin/ladmin
cp -f $< $@
eathena-monitor: ${BUILD_DIR}/tool/eathena-monitor
cp -f $< $@
-webserver: ${BUILD_DIR}/webserver/main
- cp -f $< $@
# Executable dependencies - generated by hand
-${BUILD_DIR}/char/char: ${BUILD_DIR}/char/char.o ${BUILD_DIR}/char/inter.o ${BUILD_DIR}/char/int_party.o ${BUILD_DIR}/char/int_guild.o ${BUILD_DIR}/char/int_storage.o ${BUILD_DIR}/common/core.o ${BUILD_DIR}/common/socket.o ${BUILD_DIR}/common/timer.o ${BUILD_DIR}/common/db.o ${BUILD_DIR}/common/lock.o ${BUILD_DIR}/common/mt_rand.o ${BUILD_DIR}/common/utils.o
-${BUILD_DIR}/ladmin/ladmin: ${BUILD_DIR}/ladmin/ladmin.o ${BUILD_DIR}/common/md5calc.o ${BUILD_DIR}/common/core.o ${BUILD_DIR}/common/socket.o ${BUILD_DIR}/common/timer.o ${BUILD_DIR}/common/db.o ${BUILD_DIR}/common/mt_rand.o ${BUILD_DIR}/common/utils.o
-${BUILD_DIR}/login/login: ${BUILD_DIR}/login/login.o ${BUILD_DIR}/common/core.o ${BUILD_DIR}/common/socket.o ${BUILD_DIR}/common/timer.o ${BUILD_DIR}/common/db.o ${BUILD_DIR}/common/lock.o ${BUILD_DIR}/common/mt_rand.o ${BUILD_DIR}/common/md5calc.o ${BUILD_DIR}/common/utils.o
-${BUILD_DIR}/map/map: ${BUILD_DIR}/map/map.o ${BUILD_DIR}/map/tmw.o ${BUILD_DIR}/map/magic-interpreter-lexer.o ${BUILD_DIR}/map/magic-interpreter-parser.o ${BUILD_DIR}/map/magic-interpreter-base.o ${BUILD_DIR}/map/magic-expr.o ${BUILD_DIR}/map/magic-stmt.o ${BUILD_DIR}/map/magic.o ${BUILD_DIR}/map/map.o ${BUILD_DIR}/map/chrif.o ${BUILD_DIR}/map/clif.o ${BUILD_DIR}/map/pc.o ${BUILD_DIR}/map/npc.o ${BUILD_DIR}/map/chat.o ${BUILD_DIR}/map/path.o ${BUILD_DIR}/map/itemdb.o ${BUILD_DIR}/map/mob.o ${BUILD_DIR}/map/script.o ${BUILD_DIR}/map/storage.o ${BUILD_DIR}/map/skill.o ${BUILD_DIR}/map/skill-pools.o ${BUILD_DIR}/map/atcommand.o ${BUILD_DIR}/map/battle.o ${BUILD_DIR}/map/intif.o ${BUILD_DIR}/map/trade.o ${BUILD_DIR}/map/party.o ${BUILD_DIR}/map/guild.o ${BUILD_DIR}/common/core.o ${BUILD_DIR}/common/socket.o ${BUILD_DIR}/common/timer.o ${BUILD_DIR}/common/grfio.o ${BUILD_DIR}/common/db.o ${BUILD_DIR}/common/lock.o ${BUILD_DIR}/common/nullpo.o ${BUILD_DIR}/common/mt_rand.o ${BUILD_DIR}/common/md5calc.o ${BUILD_DIR}/common/utils.o
-${BUILD_DIR}/tool/eathena-monitor: ${BUILD_DIR}/tool/eathena-monitor.o
-${BUILD_DIR}/tool/adduser: ${BUILD_DIR}/tool/adduser.o ${BUILD_DIR}/common/socket.o
-${BUILD_DIR}/tool/itemfrob: ${BUILD_DIR}/tool/itemfrob.o ${BUILD_DIR}/common/timer.o ${BUILD_DIR}/common/socket.o ${BUILD_DIR}/common/db.o ${BUILD_DIR}/common/lock.o ${BUILD_DIR}/char/inter.o ${BUILD_DIR}/char/int_guild.o ${BUILD_DIR}/char/int_party.o ${BUILD_DIR}/char/int_storage.o
-${BUILD_DIR}/tool/mapfrob: ${BUILD_DIR}/tool/mapfrob.o ${BUILD_DIR}/common/timer.o ${BUILD_DIR}/common/socket.o ${BUILD_DIR}/common/db.o ${BUILD_DIR}/common/lock.o ${BUILD_DIR}/char/inter.o ${BUILD_DIR}/char/int_guild.o ${BUILD_DIR}/char/int_party.o ${BUILD_DIR}/char/int_storage.o
-${BUILD_DIR}/tool/marriage-info: ${BUILD_DIR}/tool/marriage-info.o ${BUILD_DIR}/common/timer.o ${BUILD_DIR}/common/socket.o ${BUILD_DIR}/common/db.o ${BUILD_DIR}/common/lock.o ${BUILD_DIR}/char/inter.o ${BUILD_DIR}/char/int_guild.o ${BUILD_DIR}/char/int_party.o ${BUILD_DIR}/char/int_storage.o
-${BUILD_DIR}/webserver/main: ${BUILD_DIR}/webserver/main.o ${BUILD_DIR}/webserver/parse.o ${BUILD_DIR}/webserver/generate.o ${BUILD_DIR}/webserver/htmlstyle.o ${BUILD_DIR}/webserver/logs.o ${BUILD_DIR}/webserver/pages/about.o ${BUILD_DIR}/webserver/pages/sample.o ${BUILD_DIR}/webserver/pages/notdone.o
+${BUILD_DIR}/char/char: ${BUILD_DIR}/char/char.o ${BUILD_DIR}/char/inter.o ${BUILD_DIR}/char/int_party.o ${BUILD_DIR}/char/int_storage.o ${BUILD_DIR}/common/core.o ${BUILD_DIR}/common/socket.o ${BUILD_DIR}/common/timer.o ${BUILD_DIR}/common/db.o ${BUILD_DIR}/common/lock.o ${BUILD_DIR}/common/random.o ${BUILD_DIR}/common/utils.o ${BUILD_DIR}/common/cxxstdio.o ${BUILD_DIR}/common/extract.o
+${BUILD_DIR}/ladmin/ladmin: ${BUILD_DIR}/ladmin/ladmin.o ${BUILD_DIR}/common/md5calc.o ${BUILD_DIR}/common/core.o ${BUILD_DIR}/common/socket.o ${BUILD_DIR}/common/timer.o ${BUILD_DIR}/common/db.o ${BUILD_DIR}/common/random.o ${BUILD_DIR}/common/utils.o ${BUILD_DIR}/common/cxxstdio.o
+${BUILD_DIR}/login/login: ${BUILD_DIR}/login/login.o ${BUILD_DIR}/common/core.o ${BUILD_DIR}/common/socket.o ${BUILD_DIR}/common/timer.o ${BUILD_DIR}/common/db.o ${BUILD_DIR}/common/lock.o ${BUILD_DIR}/common/random.o ${BUILD_DIR}/common/md5calc.o ${BUILD_DIR}/common/utils.o ${BUILD_DIR}/common/cxxstdio.o ${BUILD_DIR}/common/extract.o
+${BUILD_DIR}/map/map: ${BUILD_DIR}/map/map.o ${BUILD_DIR}/map/tmw.o ${BUILD_DIR}/map/magic-interpreter-lexer.o ${BUILD_DIR}/map/magic-interpreter-parser.o ${BUILD_DIR}/map/magic-interpreter-base.o ${BUILD_DIR}/map/magic-expr.o ${BUILD_DIR}/map/magic-stmt.o ${BUILD_DIR}/map/magic.o ${BUILD_DIR}/map/map.o ${BUILD_DIR}/map/chrif.o ${BUILD_DIR}/map/clif.o ${BUILD_DIR}/map/pc.o ${BUILD_DIR}/map/npc.o ${BUILD_DIR}/map/chat.o ${BUILD_DIR}/map/path.o ${BUILD_DIR}/map/itemdb.o ${BUILD_DIR}/map/mob.o ${BUILD_DIR}/map/script.o ${BUILD_DIR}/map/storage.o ${BUILD_DIR}/map/skill.o ${BUILD_DIR}/map/skill-pools.o ${BUILD_DIR}/map/atcommand.o ${BUILD_DIR}/map/battle.o ${BUILD_DIR}/map/intif.o ${BUILD_DIR}/map/trade.o ${BUILD_DIR}/map/party.o ${BUILD_DIR}/common/core.o ${BUILD_DIR}/common/socket.o ${BUILD_DIR}/common/timer.o ${BUILD_DIR}/map/grfio.o ${BUILD_DIR}/common/db.o ${BUILD_DIR}/common/lock.o ${BUILD_DIR}/common/nullpo.o ${BUILD_DIR}/common/random.o ${BUILD_DIR}/common/md5calc.o ${BUILD_DIR}/common/utils.o ${BUILD_DIR}/common/cxxstdio.o ${BUILD_DIR}/common/extract.o
+${BUILD_DIR}/tool/eathena-monitor: ${BUILD_DIR}/tool/eathena-monitor.o ${BUILD_DIR}/common/utils.o
+
+# silence build warnings for code beyond my control
+${BUILD_DIR}/map/magic-interpreter-lexer.o ${BUILD_DIR}/map/magic-interpreter-parser.o : override WARNINGS=
# deps.make is *NOT* automatically rebuilt normally
# but the generated source files do need to be done first
@@ -80,10 +74,12 @@ deps.make: src/map/magic-interpreter-parser.cpp src/map/magic-interpreter-lexer.
for F in `find src/ -name '*.cpp'`; do \
${CXX} ${CPPFLAGS} -MM "$$F" -MT "$$(sed 's/src/$${BUILD_DIR}/;s/\.cpp/.o/' <<< "$$F")"; \
done > deps.make
+ echo '# vim: filetype=make' >> deps.make
include deps.make
prefix=/usr/local
+BACKUPS=numbered
install:
install -d ${prefix}/bin/
- install -t ${prefix}/bin/ $(wildcard ${PROGS})
+ install --backup=${BACKUPS} -t ${prefix}/bin/ $(wildcard ${PROGS})
diff --git a/README b/README
index d5b7a65..78cf174 100644
--- a/README
+++ b/README
@@ -1,32 +1,2 @@
-COMPILING TMW-EATHENA
-
-In addition to the basic build tools (GCC, Make, headers, ...), Bison, and
-Flex are needed. On Debian derivates, do:
-
- sudo apt-get install build-essential flex bison
-
-In addition, on 64-bit machines you need 32-bit compatibility headers. On
-Debian derivatives you need to install libc6-dev-i386:
-
- sudo apt-get install libc6-dev-i386
-
-If you're using make 3.81 instead of 3.82 (which isn't very unlikely), you
-will have to run the following command before running 'make':
-
- mkdir -p obj/{common,login,char,map,ladmin,tool}
-
-Finally, you're ready to run:
-
- make
-
-
-SERVER DATA AND CONFIGURATION
-
-This is just tmwAthena. We store our scripts, item and monster databases, etc.
-in a separate git repository called tmw-eathena-data, available at:
-
- http://github.com/themanaworld/tmwa-server-data
-
-Note that this repository contains more than just the contents of this data
-directory. Either set up symbolic links or just copy the server executables
-into it.
+For usage instructions, see:
+http://wiki.themanaworld.org/index.php/How_to_Develop
diff --git a/doc/LICENCE b/doc/LICENCE
deleted file mode 100644
index 5b6e7c6..0000000
--- a/doc/LICENCE
+++ /dev/null
@@ -1,340 +0,0 @@
- GNU GENERAL PUBLIC LICENSE
- Version 2, June 1991
-
- Copyright (C) 1989, 1991 Free Software Foundation, Inc.
- 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- Everyone is permitted to copy and distribute verbatim copies
- of this license document, but changing it is not allowed.
-
- Preamble
-
- The licenses for most software are designed to take away your
-freedom to share and change it. By contrast, the GNU General Public
-License is intended to guarantee your freedom to share and change free
-software--to make sure the software is free for all its users. This
-General Public License applies to most of the Free Software
-Foundation's software and to any other program whose authors commit to
-using it. (Some other Free Software Foundation software is covered by
-the GNU Library General Public License instead.) You can apply it to
-your programs, too.
-
- When we speak of free software, we are referring to freedom, not
-price. Our General Public Licenses are designed to make sure that you
-have the freedom to distribute copies of free software (and charge for
-this service if you wish), that you receive source code or can get it
-if you want it, that you can change the software or use pieces of it
-in new free programs; and that you know you can do these things.
-
- To protect your rights, we need to make restrictions that forbid
-anyone to deny you these rights or to ask you to surrender the rights.
-These restrictions translate to certain responsibilities for you if you
-distribute copies of the software, or if you modify it.
-
- For example, if you distribute copies of such a program, whether
-gratis or for a fee, you must give the recipients all the rights that
-you have. You must make sure that they, too, receive or can get the
-source code. And you must show them these terms so they know their
-rights.
-
- We protect your rights with two steps: (1) copyright the software, and
-(2) offer you this license which gives you legal permission to copy,
-distribute and/or modify the software.
-
- Also, for each author's protection and ours, we want to make certain
-that everyone understands that there is no warranty for this free
-software. If the software is modified by someone else and passed on, we
-want its recipients to know that what they have is not the original, so
-that any problems introduced by others will not reflect on the original
-authors' reputations.
-
- Finally, any free program is threatened constantly by software
-patents. We wish to avoid the danger that redistributors of a free
-program will individually obtain patent licenses, in effect making the
-program proprietary. To prevent this, we have made it clear that any
-patent must be licensed for everyone's free use or not licensed at all.
-
- The precise terms and conditions for copying, distribution and
-modification follow.
-
- GNU GENERAL PUBLIC LICENSE
- TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
-
- 0. This License applies to any program or other work which contains
-a notice placed by the copyright holder saying it may be distributed
-under the terms of this General Public License. The "Program", below,
-refers to any such program or work, and a "work based on the Program"
-means either the Program or any derivative work under copyright law:
-that is to say, a work containing the Program or a portion of it,
-either verbatim or with modifications and/or translated into another
-language. (Hereinafter, translation is included without limitation in
-the term "modification".) Each licensee is addressed as "you".
-
-Activities other than copying, distribution and modification are not
-covered by this License; they are outside its scope. The act of
-running the Program is not restricted, and the output from the Program
-is covered only if its contents constitute a work based on the
-Program (independent of having been made by running the Program).
-Whether that is true depends on what the Program does.
-
- 1. You may copy and distribute verbatim copies of the Program's
-source code as you receive it, in any medium, provided that you
-conspicuously and appropriately publish on each copy an appropriate
-copyright notice and disclaimer of warranty; keep intact all the
-notices that refer to this License and to the absence of any warranty;
-and give any other recipients of the Program a copy of this License
-along with the Program.
-
-You may charge a fee for the physical act of transferring a copy, and
-you may at your option offer warranty protection in exchange for a fee.
-
- 2. You may modify your copy or copies of the Program or any portion
-of it, thus forming a work based on the Program, and copy and
-distribute such modifications or work under the terms of Section 1
-above, provided that you also meet all of these conditions:
-
- a) You must cause the modified files to carry prominent notices
- stating that you changed the files and the date of any change.
-
- b) You must cause any work that you distribute or publish, that in
- whole or in part contains or is derived from the Program or any
- part thereof, to be licensed as a whole at no charge to all third
- parties under the terms of this License.
-
- c) If the modified program normally reads commands interactively
- when run, you must cause it, when started running for such
- interactive use in the most ordinary way, to print or display an
- announcement including an appropriate copyright notice and a
- notice that there is no warranty (or else, saying that you provide
- a warranty) and that users may redistribute the program under
- these conditions, and telling the user how to view a copy of this
- License. (Exception: if the Program itself is interactive but
- does not normally print such an announcement, your work based on
- the Program is not required to print an announcement.)
-
-These requirements apply to the modified work as a whole. If
-identifiable sections of that work are not derived from the Program,
-and can be reasonably considered independent and separate works in
-themselves, then this License, and its terms, do not apply to those
-sections when you distribute them as separate works. But when you
-distribute the same sections as part of a whole which is a work based
-on the Program, the distribution of the whole must be on the terms of
-this License, whose permissions for other licensees extend to the
-entire whole, and thus to each and every part regardless of who wrote it.
-
-Thus, it is not the intent of this section to claim rights or contest
-your rights to work written entirely by you; rather, the intent is to
-exercise the right to control the distribution of derivative or
-collective works based on the Program.
-
-In addition, mere aggregation of another work not based on the Program
-with the Program (or with a work based on the Program) on a volume of
-a storage or distribution medium does not bring the other work under
-the scope of this License.
-
- 3. You may copy and distribute the Program (or a work based on it,
-under Section 2) in object code or executable form under the terms of
-Sections 1 and 2 above provided that you also do one of the following:
-
- a) Accompany it with the complete corresponding machine-readable
- source code, which must be distributed under the terms of Sections
- 1 and 2 above on a medium customarily used for software interchange; or,
-
- b) Accompany it with a written offer, valid for at least three
- years, to give any third party, for a charge no more than your
- cost of physically performing source distribution, a complete
- machine-readable copy of the corresponding source code, to be
- distributed under the terms of Sections 1 and 2 above on a medium
- customarily used for software interchange; or,
-
- c) Accompany it with the information you received as to the offer
- to distribute corresponding source code. (This alternative is
- allowed only for noncommercial distribution and only if you
- received the program in object code or executable form with such
- an offer, in accord with Subsection b above.)
-
-The source code for a work means the preferred form of the work for
-making modifications to it. For an executable work, complete source
-code means all the source code for all modules it contains, plus any
-associated interface definition files, plus the scripts used to
-control compilation and installation of the executable. However, as a
-special exception, the source code distributed need not include
-anything that is normally distributed (in either source or binary
-form) with the major components (compiler, kernel, and so on) of the
-operating system on which the executable runs, unless that component
-itself accompanies the executable.
-
-If distribution of executable or object code is made by offering
-access to copy from a designated place, then offering equivalent
-access to copy the source code from the same place counts as
-distribution of the source code, even though third parties are not
-compelled to copy the source along with the object code.
-
- 4. You may not copy, modify, sublicense, or distribute the Program
-except as expressly provided under this License. Any attempt
-otherwise to copy, modify, sublicense or distribute the Program is
-void, and will automatically terminate your rights under this License.
-However, parties who have received copies, or rights, from you under
-this License will not have their licenses terminated so long as such
-parties remain in full compliance.
-
- 5. You are not required to accept this License, since you have not
-signed it. However, nothing else grants you permission to modify or
-distribute the Program or its derivative works. These actions are
-prohibited by law if you do not accept this License. Therefore, by
-modifying or distributing the Program (or any work based on the
-Program), you indicate your acceptance of this License to do so, and
-all its terms and conditions for copying, distributing or modifying
-the Program or works based on it.
-
- 6. Each time you redistribute the Program (or any work based on the
-Program), the recipient automatically receives a license from the
-original licensor to copy, distribute or modify the Program subject to
-these terms and conditions. You may not impose any further
-restrictions on the recipients' exercise of the rights granted herein.
-You are not responsible for enforcing compliance by third parties to
-this License.
-
- 7. If, as a consequence of a court judgment or allegation of patent
-infringement or for any other reason (not limited to patent issues),
-conditions are imposed on you (whether by court order, agreement or
-otherwise) that contradict the conditions of this License, they do not
-excuse you from the conditions of this License. If you cannot
-distribute so as to satisfy simultaneously your obligations under this
-License and any other pertinent obligations, then as a consequence you
-may not distribute the Program at all. For example, if a patent
-license would not permit royalty-free redistribution of the Program by
-all those who receive copies directly or indirectly through you, then
-the only way you could satisfy both it and this License would be to
-refrain entirely from distribution of the Program.
-
-If any portion of this section is held invalid or unenforceable under
-any particular circumstance, the balance of the section is intended to
-apply and the section as a whole is intended to apply in other
-circumstances.
-
-It is not the purpose of this section to induce you to infringe any
-patents or other property right claims or to contest validity of any
-such claims; this section has the sole purpose of protecting the
-integrity of the free software distribution system, which is
-implemented by public license practices. Many people have made
-generous contributions to the wide range of software distributed
-through that system in reliance on consistent application of that
-system; it is up to the author/donor to decide if he or she is willing
-to distribute software through any other system and a licensee cannot
-impose that choice.
-
-This section is intended to make thoroughly clear what is believed to
-be a consequence of the rest of this License.
-
- 8. If the distribution and/or use of the Program is restricted in
-certain countries either by patents or by copyrighted interfaces, the
-original copyright holder who places the Program under this License
-may add an explicit geographical distribution limitation excluding
-those countries, so that distribution is permitted only in or among
-countries not thus excluded. In such case, this License incorporates
-the limitation as if written in the body of this License.
-
- 9. The Free Software Foundation may publish revised and/or new versions
-of the General Public License from time to time. Such new versions will
-be similar in spirit to the present version, but may differ in detail to
-address new problems or concerns.
-
-Each version is given a distinguishing version number. If the Program
-specifies a version number of this License which applies to it and "any
-later version", you have the option of following the terms and conditions
-either of that version or of any later version published by the Free
-Software Foundation. If the Program does not specify a version number of
-this License, you may choose any version ever published by the Free Software
-Foundation.
-
- 10. If you wish to incorporate parts of the Program into other free
-programs whose distribution conditions are different, write to the author
-to ask for permission. For software which is copyrighted by the Free
-Software Foundation, write to the Free Software Foundation; we sometimes
-make exceptions for this. Our decision will be guided by the two goals
-of preserving the free status of all derivatives of our free software and
-of promoting the sharing and reuse of software generally.
-
- NO WARRANTY
-
- 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
-FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
-OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
-PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
-OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
-TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
-PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
-REPAIR OR CORRECTION.
-
- 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
-WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
-REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
-INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
-OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
-TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
-YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
-PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGES.
-
- END OF TERMS AND CONDITIONS
-
- How to Apply These Terms to Your New Programs
-
- If you develop a new program, and you want it to be of the greatest
-possible use to the public, the best way to achieve this is to make it
-free software which everyone can redistribute and change under these terms.
-
- To do so, attach the following notices to the program. It is safest
-to attach them to the start of each source file to most effectively
-convey the exclusion of warranty; and each file should have at least
-the "copyright" line and a pointer to where the full notice is found.
-
- <one line to give the program's name and a brief idea of what it does.>
- Copyright (C) <year> <name of author>
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-
-Also add information on how to contact you by electronic and paper mail.
-
-If the program is interactive, make it output a short notice like this
-when it starts in an interactive mode:
-
- Gnomovision version 69, Copyright (C) year name of author
- Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
- This is free software, and you are welcome to redistribute it
- under certain conditions; type `show c' for details.
-
-The hypothetical commands `show w' and `show c' should show the appropriate
-parts of the General Public License. Of course, the commands you use may
-be called something other than `show w' and `show c'; they could even be
-mouse-clicks or menu items--whatever suits your program.
-
-You should also get your employer (if you work as a programmer) or your
-school, if any, to sign a "copyright disclaimer" for the program, if
-necessary. Here is a sample; alter the names:
-
- Yoyodyne, Inc., hereby disclaims all copyright interest in the program
- `Gnomovision' (which makes passes at compilers) written by James Hacker.
-
- <signature of Ty Coon>, 1 April 1989
- Ty Coon, President of Vice
-
-This General Public License does not permit incorporating your program into
-proprietary programs. If your program is a subroutine library, you may
-consider it more useful to permit linking proprietary applications with the
-library. If this is what you want to do, use the GNU Library General
-Public License instead of this License.
diff --git a/doc/LICENCE_JA b/doc/LICENCE_JA
deleted file mode 100644
index fcf6801..0000000
--- a/doc/LICENCE_JA
+++ /dev/null
@@ -1,416 +0,0 @@
- GNU 一般公衆利用許諾契約書
- ãƒãƒ¼ã‚¸ãƒ§ãƒ³2ã€1991å¹´6月
- 日本語訳ã€2002å¹´5月20æ—¥
-
- Copyright (C) 1989, 1991 Free Software Foundation, Inc.
- 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- ã“ã®åˆ©ç”¨è¨±è«¾å¥‘約書をã€ä¸€å­—一å¥ãã®ã¾ã¾ã«è¤‡è£½ã—頒布ã™ã‚‹ã“ã¨ã¯è¨±å¯ã™ã‚‹ã€‚
- ã—ã‹ã—変更ã¯èªã‚ãªã„。
-
- This is an unofficial translation of the GNU General Public License
- into Japanese. It was not published by the Free Software Foundation,
- and does not legally state the distribution terms for software that
- uses the GNU GPL--only the original English text of the GNU GPL does
- that. However, we hope that this translation will help Japanese
- speakers understand the GNU GPL better.
-
- (訳: 以下ã¯GNU General Public Licenseã®éžå…¬å¼ãªæ—¥æœ¬èªžè¨³ã§ã™ã€‚ã“ã‚Œã¯ãƒ•
- リーソフトウェア財団(the Free Software Foundataion)ã«ã‚ˆã£ã¦ç™ºè¡¨ã•ã‚ŒãŸ
- ã‚‚ã®ã§ã¯ãªãã€GNU GPLã‚’é©ç”¨ã—ãŸã‚½ãƒ•ãƒˆã‚¦ã‚§ã‚¢ã®é ’布æ¡ä»¶ã‚’法的ã«æœ‰åŠ¹ãªå½¢
- ã§è¿°ã¹ãŸã‚‚ã®ã§ã¯ã‚ã‚Šã¾ã›ã‚“。頒布æ¡ä»¶ã¨ã—ã¦ã¯GNU GPLã®è‹±èªžç‰ˆãƒ†ã‚­ã‚¹ãƒˆã§
- 指定ã•ã‚Œã¦ã„ã‚‹ã‚‚ã®ã®ã¿ãŒæœ‰åŠ¹ã§ã™ã€‚ã—ã‹ã—ãªãŒã‚‰ã€ç§ãŸã¡ã¯ã“ã®ç¿»è¨³ãŒã€
- 日本語を使用ã™ã‚‹äººã€…ã«ã¨ã£ã¦GNU GPLをより良ãç†è§£ã™ã‚‹åŠ©ã‘ã¨ãªã‚‹ã“ã¨ã‚’
- 望んã§ã„ã¾ã™ã€‚)
-
- 翻訳㯠八田真行<mhatta@gnu.org>ãŒè¡Œã£ãŸã€‚原文ã¯
- http://www.gnu.org/licenses/gpl.txtã§ã‚る。誤訳ã®æŒ‡æ‘˜ã‚„改善案を歓迎ã™
- る。
- ã¯ã˜ã‚ã«
-
-ソフトウェアå‘ã‘ライセンスã®å¤§åŠã¯ã€ã‚ãªãŸãŒãã®ã‚½ãƒ•ãƒˆã‚¦ã‚§ã‚¢ã‚’共有ã—ãŸ
-り変更ã—ãŸã‚Šã™ã‚‹è‡ªç”±ã‚’奪ã†ã‚ˆã†ã«è¨­è¨ˆã•ã‚Œã¦ã„ã¾ã™ã€‚対照的ã«ã€GNU 一般公
-衆利用許諾契約書ã¯ã€ã‚ãªãŸãŒãƒ•ãƒªãƒ¼ã‚½ãƒ•ãƒˆã‚¦ã‚§ã‚¢ã‚’共有ã—ãŸã‚Šå¤‰æ›´ã—ãŸã‚Šã™
-る自由をä¿è¨¼ã™ã‚‹--ã™ãªã‚ã¡ã€ã‚½ãƒ•ãƒˆã‚¦ã‚§ã‚¢ãŒãã®ãƒ¦ãƒ¼ã‚¶ã™ã¹ã¦ã«ã¨ã£ã¦ãƒ•ãƒªãƒ¼
-ã§ã‚ã‚‹ã“ã¨ã‚’ä¿è¨¼ã™ã‚‹ã“ã¨ã‚’目的ã¨ã—ã¦ã„ã¾ã™ã€‚ã“ã®ä¸€èˆ¬å…¬è¡†åˆ©ç”¨è¨±è«¾å¥‘約書
-ã¯ãƒ•ãƒªãƒ¼ã‚½ãƒ•ãƒˆã‚¦ã‚§ã‚¢è²¡å›£ã®ã‚½ãƒ•ãƒˆã‚¦ã‚§ã‚¢ã®ã»ã¨ã‚“ã©ã«é©ç”¨ã•ã‚Œã¦ãŠã‚Šã€ã¾ãŸ
-GNU GPLã‚’é©ç”¨ã™ã‚‹ã¨æ±ºã‚ãŸãƒ•ãƒªãƒ¼ã‚½ãƒ•ãƒˆã‚¦ã‚§ã‚¢è²¡å›£ä»¥å¤–ã®ä½œè€…ã«ã‚ˆã‚‹ãƒ—ログ
-ラムã«ã‚‚é©ç”¨ã•ã‚Œã¦ã„ã¾ã™(ã„ãã¤ã‹ã®ãƒ•ãƒªãƒ¼ã‚½ãƒ•ãƒˆã‚¦ã‚§ã‚¢è²¡å›£ã®ã‚½ãƒ•ãƒˆã‚¦ã‚§
-ã‚¢ã«ã¯ã€GNU GPLã§ã¯ãªãGNU ライブラリ一般公衆利用許諾契約書ãŒé©ç”¨ã•ã‚Œ
-ã¦ã„ã‚‹ã“ã¨ã‚‚ã‚ã‚Šã¾ã™)。ã‚ãªãŸã‚‚ã¾ãŸã€ã”自分ã®ãƒ—ログラムã«GNU GPLã‚’é©ç”¨
-ã™ã‚‹ã“ã¨ãŒå¯èƒ½ã§ã™ã€‚
-
-ç§ãŸã¡ãŒãƒ•ãƒªãƒ¼ã‚½ãƒ•ãƒˆã‚¦ã‚§ã‚¢ã¨è¨€ã†ã¨ãã€ãã‚Œã¯åˆ©ç”¨ã®è‡ªç”±ã«ã¤ã„ã¦è¨€åŠã—ã¦
-ã„ã‚‹ã®ã§ã‚ã£ã¦ã€ä¾¡æ ¼ã¯å•é¡Œã«ã—ã¦ã„ã¾ã›ã‚“。ç§ãŸã¡ã®ä¸€èˆ¬å…¬è¡†åˆ©ç”¨è¨±è«¾å¥‘ç´„
-書ã¯ã€ã‚ãªãŸãŒãƒ•ãƒªãƒ¼ã‚½ãƒ•ãƒˆã‚¦ã‚§ã‚¢ã®è¤‡è£½ç‰©ã‚’頒布ã™ã‚‹è‡ªç”±ã‚’ä¿è¨¼ã™ã‚‹ã‚ˆã†è¨­
-計ã•ã‚Œã¦ã„ã¾ã™(希望ã«å¿œã˜ã¦ãã®ç¨®ã®ã‚µãƒ¼ãƒ“スã«æ‰‹æ•°æ–™ã‚’課ã™è‡ªç”±ã‚‚ä¿è¨¼ã•
-ã‚Œã¾ã™)。ã¾ãŸã€ã‚ãªãŸãŒã‚½ãƒ¼ã‚¹ã‚³ãƒ¼ãƒ‰ã‚’å—ã‘å–ã‚‹ã‹ã€ã‚ã‚‹ã„ã¯æœ›ã‚ã°ãれを
-入手ã™ã‚‹ã“ã¨ãŒå¯èƒ½ã§ã‚ã‚‹ã¨ã„ã†ã“ã¨ã€ã‚ãªãŸãŒã‚½ãƒ•ãƒˆã‚¦ã‚§ã‚¢ã‚’変更ã—ã€ãã®
-一部を新ãŸãªãƒ•ãƒªãƒ¼ã®ãƒ—ログラムã§åˆ©ç”¨ã§ãã‚‹ã¨ã„ã†ã“ã¨ã€ãã—ã¦ã€ä»¥ä¸Šã§è¿°
-ã¹ãŸã‚ˆã†ãªã“ã¨ãŒã§ãã‚‹ã¨ã„ã†ã“ã¨ãŒã‚ãªãŸã«çŸ¥ã‚‰ã•ã‚Œã‚‹ã¨ã„ã†ã“ã¨ã‚‚ä¿è¨¼ã•
-ã‚Œã¾ã™ã€‚
-
-ã‚ãªãŸã®æ¨©åˆ©ã‚’守るãŸã‚ã€ç§ãŸã¡ã¯èª°ã‹ãŒã‚ãªãŸã®æœ‰ã™ã‚‹ã“れらã®æ¨©åˆ©ã‚’å¦å®š
-ã™ã‚‹ã“ã¨ã‚„ã€ã“れらã®æ¨©åˆ©ã‚’放棄ã™ã‚‹ã‚ˆã†è¦æ±‚ã™ã‚‹ã“ã¨ã‚’ç¦æ­¢ã™ã‚‹ã¨ã„ã†åˆ¶é™
-を加ãˆã‚‹å¿…è¦ãŒã‚ã‚Šã¾ã™ã€‚よã£ã¦ã€ã‚ãªãŸãŒã‚½ãƒ•ãƒˆã‚¦ã‚§ã‚¢ã®è¤‡è£½ç‰©ã‚’頒布ã—ãŸ
-ã‚Šãれを変更ã—ãŸã‚Šã™ã‚‹å ´åˆã«ã¯ã€ã“れらã®åˆ¶é™ã®ãŸã‚ã«ã‚ãªãŸã«ã‚る種ã®è²¬
-ä»»ãŒç™ºç”Ÿã™ã‚‹ã“ã¨ã«ãªã‚Šã¾ã™ã€‚
-
-例ãˆã°ã€ã‚ãªãŸãŒãƒ•ãƒªãƒ¼ãªãƒ—ログラムã®è¤‡è£½ç‰©ã‚’頒布ã™ã‚‹å ´åˆã€æœ‰æ–™ã‹ç„¡æ–™ã«
-é–¢ã‚らãšã€ã‚ãªãŸã¯è‡ªåˆ†ãŒæœ‰ã™ã‚‹æ¨©åˆ©ã‚’å…¨ã¦å—領者ã«ä¸Žãˆãªã‘ã‚Œã°ãªã‚Šã¾ã›ã‚“。
-ã¾ãŸã€ã‚ãªãŸã¯å½¼ã‚‰ã‚‚ソースコードをå—ã‘å–ã‚‹ã‹æ‰‹ã«å…¥ã‚Œã‚‹ã“ã¨ãŒã§ãるよã†
-ä¿è¨¼ã—ãªã‘ã‚Œã°ãªã‚Šã¾ã›ã‚“。ãã—ã¦ã€ã‚ãªãŸã¯å½¼ã‚‰ã«å¯¾ã—ã¦ä»¥ä¸‹ã§è¿°ã¹ã‚‹æ¡ä»¶
-を示ã—ã€å½¼ã‚‰ã«è‡ªã‚‰ã®æŒã¤æ¨©åˆ©ã«ã¤ã„ã¦çŸ¥ã‚‰ã—ã‚るよã†ã«ã—ãªã‘ã‚Œã°ãªã‚Šã¾ã›
-ん。
-
-ç§ãŸã¡ã¯ã‚ãªãŸã®æ¨©åˆ©ã‚’二段階ã®æ‰‹é †ã‚’è¸ã‚“ã§ä¿è­·ã—ã¾ã™ã€‚(1) ã¾ãšã‚½ãƒ•ãƒˆã‚¦ã‚§
-ã‚¢ã«å¯¾ã—ã¦è‘—作権を主張ã—ã€ãã—㦠(2) ã‚ãªãŸã«å¯¾ã—ã¦ã€ã‚½ãƒ•ãƒˆã‚¦ã‚§ã‚¢ã®è¤‡
-製や頒布ã¾ãŸã¯æ”¹å¤‰ã«ã¤ã„ã¦ã®æ³•çš„ãªè¨±å¯ã‚’与ãˆã‚‹ã“ã®å¥‘約書をæ示ã—ã¾ã™ã€‚
-
-ã¾ãŸã€å„作者やç§ãŸã¡ã‚’ä¿è­·ã™ã‚‹ãŸã‚ã€ç§ãŸã¡ã¯ã“ã®ãƒ•ãƒªãƒ¼ã‚½ãƒ•ãƒˆã‚¦ã‚§ã‚¢ã«ã¯
-何ã®ä¿è¨¼ã‚‚ç„¡ã„ã¨ã„ã†ã“ã¨ã‚’誰もãŒç¢ºå®Ÿã«ç†è§£ã™ã‚‹ã‚ˆã†ã«ã—ã€ã¾ãŸã‚½ãƒ•ãƒˆã‚¦ã‚§
-ã‚¢ãŒèª°ã‹ä»–人ã«ã‚ˆã£ã¦æ”¹å¤‰ã•ã‚Œã€ãã‚ŒãŒæ¬¡ã€…ã¨é ’布ã•ã‚Œã¦ã„ã£ãŸã¨ã—ã¦ã‚‚ã€ã
-ã®å—領者ã¯å½¼ã‚‰ãŒæ‰‹ã«å…¥ã‚ŒãŸã‚½ãƒ•ãƒˆã‚¦ã‚§ã‚¢ãŒã‚ªãƒªã‚¸ãƒŠãƒ«ã®ãƒãƒ¼ã‚¸ãƒ§ãƒ³ã§ã¯ç„¡ã„
-ã“ã¨ã€ãã—ã¦åŽŸä½œè€…ã®å声ã¯ä»–人ã«ã‚ˆã£ã¦æŒã¡è¾¼ã¾ã‚ŒãŸå¯èƒ½æ€§ã®ã‚ã‚‹å•é¡Œã«ã‚ˆã£
-ã¦å½±éŸ¿ã•ã‚Œã‚‹ã“ã¨ãŒãªã„ã¨ã„ã†ã“ã¨ã‚’周知ã•ã›ãŸã„ã¨æ€ã„ã¾ã™ã€‚
-
-最後ã«ã€ã‚½ãƒ•ãƒˆã‚¦ã‚§ã‚¢ç‰¹è¨±ãŒã„ã‹ãªã‚‹ãƒ•ãƒªãƒ¼ã®ãƒ—ログラムã®å­˜åœ¨ã«ã‚‚ä¸æ–­ã®è„…
-å¨ã‚’投ã’ã‹ã‘ã¦ã„ã¾ã™ãŒã€ç§ãŸã¡ã¯ã€ãƒ•ãƒªãƒ¼ãªãƒ—ログラムã®å†é ’布者ãŒå€‹ã€…ã«
-特許ライセンスをå–å¾—ã™ã‚‹ã“ã¨ã«ã‚ˆã£ã¦ã€äº‹å®Ÿä¸Šãƒ—ログラムを独å çš„ã«ã—ã¦ã—
-ã¾ã†ã¨ã„ã†å±é™ºã‚’é¿ã‘ãŸã„ã¨æ€ã„ã¾ã™ã€‚ã“ã†ã„ã£ãŸäº‹æ…‹ã‚’予防ã™ã‚‹ãŸã‚ã€ç§ãŸ
-ã¡ã¯ã„ã‹ãªã‚‹ç‰¹è¨±ã‚‚誰もãŒè‡ªç”±ã«åˆ©ç”¨ã§ãるよã†ãƒ©ã‚¤ã‚»ãƒ³ã‚¹ã•ã‚Œã‚‹ã‹ã€å…¨ãラ
-イセンスã•ã‚Œãªã„ã‹ã®ã©ã¡ã‚‰ã‹ã§ãªã‘ã‚Œã°ãªã‚‰ãªã„ã“ã¨ã‚’明確ã«ã—ã¾ã—ãŸã€‚
-
-(訳注: 本契約書ã§ã€Œç‹¬å çš„(proprietary)ã€ã¨ã¯ã€ã‚½ãƒ•ãƒˆã‚¦ã‚§ã‚¢ã®åˆ©ç”¨ã‚„å†é ’
-布ã€æ”¹å¤‰ãŒç¦æ­¢ã•ã‚Œã¦ã„ã‚‹ã‹ã€è¨±å¯ã‚’å¾—ã‚‹ã“ã¨ãŒå¿…è¦ã¨ã•ã‚Œã¦ã„ã‚‹ã‹ã€ã‚ã‚‹ã„
-ã¯åŽ³ã—ã„制é™ãŒèª²ã›ã‚‰ã‚Œã¦ã„ã¦è‡ªç”±ã«ãã†ã™ã‚‹ã“ã¨ãŒäº‹å®Ÿä¸Šã§ããªããªã£ã¦ã„
-る状態ã®ã“ã¨ã‚’指ã™ã€‚詳ã—ãã¯
-http://www.gnu.org/philosophy/categories.ja.html#ProprietarySoftwareã‚’
-å‚ç…§ã›ã‚ˆã€‚)
-
-複製や頒布ã€æ”¹å¤‰ã«ã¤ã„ã¦ã®æ­£ç¢ºãªæ¡ä»¶ã¨åˆ¶ç´„を以下ã§è¿°ã¹ã¦ã„ãã¾ã™ã€‚
-
- GNU 一般公衆利用許諾契約書
- 複製ã€é ’布ã€æ”¹å¤‰ã«é–¢ã™ã‚‹æ¡ä»¶ã¨åˆ¶ç´„
-
-0. ã“ã®åˆ©ç”¨è¨±è«¾å¥‘約書ã¯ã€ãã®ãƒ—ログラム(ã¾ãŸã¯ãã®ä»–ã®è‘—作物)ã‚’ã“ã®ä¸€
-般公衆利用許諾契約書ã®å®šã‚ã‚‹æ¡ä»¶ã®ä¸‹ã§é ’布ã§ãã‚‹ã¨ã„ã†å‘ŠçŸ¥ãŒè‘—作権者ã«
-よã£ã¦è¨˜è¼‰ã•ã‚ŒãŸãƒ—ログラムã¾ãŸã¯ãã®ä»–ã®è‘—作物全般ã«é©ç”¨ã•ã‚Œã‚‹ã€‚以下ã§
-ã¯ã€ã€Œã€Žãƒ—ログラムã€ã€ã¨ã¯ãã®ã‚ˆã†ã«ã—ã¦ã“ã®å¥‘約書ãŒé©ç”¨ã•ã‚ŒãŸãƒ—ログラ
-ムや著作物全般をæ„味ã—ã€ã¾ãŸã€Œã€Žãƒ—ログラムã€ã‚’基ã«ã—ãŸè‘—作物ã€ã¨ã¯ã€Žãƒ—
-ログラムã€ã‚„ãã®ä»–著作権法ã®ä¸‹ã§æ´¾ç”Ÿç‰©ã¨è¦‹ãªã•ã‚Œã‚‹ã‚‚ã®å…¨èˆ¬ã‚’指ã™ã€‚ã™ãª
-ã‚ã¡ã€ã€Žãƒ—ログラムã€ã‹ãã®ä¸€éƒ¨ã‚’ã€å…¨ãåŒä¸€ã®ã¾ã¾ã‹ã€æ”¹å¤‰ã‚’加ãˆãŸã‹ã€ã‚
-ã‚‹ã„ã¯ä»–ã®è¨€èªžã«ç¿»è¨³ã•ã‚ŒãŸå½¢ã§å«ã‚€è‘—作物ã®ã“ã¨ã§ã‚ã‚‹(「改変ã€ã¨ã„ã†èªž
-ã®æœ¬æ¥ã®æ„味ã‹ã‚‰ã¯ãšã‚Œã‚‹ãŒã€ä»¥ä¸‹ã§ã¯ç¿»è¨³ã‚‚改変ã®ä¸€ç¨®ã¨è¦‹ãªã™)。ãã‚Œãž
-ã‚Œã®å¥‘約者ã¯ã€Œã‚ãªãŸã€ã¨è¡¨ç¾ã•ã‚Œã‚‹ã€‚
-
-複製や頒布ã€æ”¹å¤‰ä»¥å¤–ã®æ´»å‹•ã¯ã“ã®å¥‘約書ã§ã¯ã‚«ãƒãƒ¼ã•ã‚Œãªã„。ãれらã¯ã“ã®
-契約書ã®å¯¾è±¡å¤–ã§ã‚る。『プログラムã€ã‚’実行ã™ã‚‹è¡Œç‚ºè‡ªä½“ã«åˆ¶é™ã¯ãªã„。ã¾
-ãŸã€ãã®ã‚ˆã†ãªã€Žãƒ—ログラムã€ã®å‡ºåŠ›çµæžœã¯ã€ãã®å†…容ãŒã€Žãƒ—ログラムã€ã‚’基
-ã«ã—ãŸè‘—作物を構æˆã™ã‚‹å ´åˆã®ã¿ã“ã®å¥‘約書ã«ã‚ˆã£ã¦ä¿è­·ã•ã‚Œã‚‹(『プログラ
-ムã€ã‚’実行ã—ãŸã“ã¨ã«ã‚ˆã£ã¦ä½œæˆã•ã‚ŒãŸã¨ã„ã†ã“ã¨ã¨ã¯ç„¡é–¢ä¿‚ã§ã‚ã‚‹)。ã“ã®
-よã†ãªç·šå¼•ãã®å¦¥å½“性ã¯ã€ã€Žãƒ—ログラムã€ãŒä½•ã‚’ã™ã‚‹ã®ã‹ã«ä¾å­˜ã™ã‚‹ã€‚
-
-1. ãã‚Œãžã‚Œã®è¤‡è£½ç‰©ã«ãŠã„ã¦é©åˆ‡ãªè‘—作権表示ã¨ä¿è¨¼ã®å¦èªå£°æ˜Ž(disclaimer
-of warranty)を目立ã¤ã‚ˆã†é©åˆ‡ã«æŽ²è¼‰ã—ã€ã¾ãŸã“ã®å¥‘約書ãŠã‚ˆã³ä¸€åˆ‡ã®ä¿è¨¼ã®
-ä¸åœ¨ã«è§¦ã‚ŒãŸå‘ŠçŸ¥ã™ã¹ã¦ã‚’ãã®ã¾ã¾æ®‹ã—ã€ãã—ã¦ã“ã®å¥‘約書ã®è¤‡è£½ç‰©ã‚’『プロ
-グラムã€ã®ã„ã‹ãªã‚‹å—領者ã«ã‚‚『プログラムã€ã¨å…±ã«é ’布ã™ã‚‹é™ã‚Šã€ã‚ãªãŸã¯
-『プログラムã€ã®ã‚½ãƒ¼ã‚¹ã‚³ãƒ¼ãƒ‰ã®è¤‡è£½ç‰©ã‚’ã€ã‚ãªãŸãŒå—ã‘å–ã£ãŸé€šã‚Šã®å½¢ã§è¤‡
-製ã¾ãŸã¯é ’布ã™ã‚‹ã“ã¨ãŒã§ãる。媒体ã¯å•ã‚ãªã„。
-
-ã‚ãªãŸã¯ã€ç‰©ç†çš„ã«è¤‡è£½ç‰©ã‚’譲渡ã™ã‚‹ã¨ã„ã†è¡Œç‚ºã«é–¢ã—ã¦æ‰‹æ•°æ–™ã‚’課ã—ã¦ã‚‚良
-ã„ã—ã€å¸Œæœ›ã«ã‚ˆã£ã¦ã¯æ‰‹æ•°æ–™ã‚’å–ã£ã¦äº¤æ›ã«ãŠã‘ã‚‹ä¿è­·ã®ä¿è¨¼ã‚’æä¾›ã—ã¦ã‚‚良
-ã„。
-
-2. ã‚ãªãŸã¯è‡ªåˆ†ã®ã€Žãƒ—ログラムã€ã®è¤‡è£½ç‰©ã‹ãã®ä¸€éƒ¨ã‚’改変ã—ã¦ã€Žãƒ—ログラ
-ムã€ã‚’基ã«ã—ãŸè‘—作物を形æˆã—ã€ãã®ã‚ˆã†ãªæ”¹å¤‰ç‚¹ã‚„著作物を上記第1節ã®å®š
-ã‚ã‚‹æ¡ä»¶ã®ä¸‹ã§è¤‡è£½ã¾ãŸã¯é ’布ã™ã‚‹ã“ã¨ãŒã§ãる。ãŸã ã—ã€ãã®ãŸã‚ã«ã¯ä»¥ä¸‹
-ã®æ¡ä»¶ã™ã¹ã¦ã‚’満ãŸã—ã¦ã„ãªã‘ã‚Œã°ãªã‚‰ãªã„:
-
- a) ã‚ãªãŸãŒãれらã®ãƒ•ã‚¡ã‚¤ãƒ«ã‚’変更ã—ãŸã¨ã„ã†ã“ã¨ã¨å¤‰æ›´ã—ãŸæ—¥æ™‚ãŒè‰¯
- ã分ã‹ã‚‹ã‚ˆã†ã€æ”¹å¤‰ã•ã‚ŒãŸãƒ•ã‚¡ã‚¤ãƒ«ã«å‘Šç¤ºã—ãªã‘ã‚Œã°ãªã‚‰ãªã„。
-
- b) 『プログラムã€ã¾ãŸã¯ãã®ä¸€éƒ¨ã‚’å«ã‚€è‘—作物ã€ã‚ã‚‹ã„ã¯ã€Žãƒ—ログラムã€
- ã‹ãã®ä¸€éƒ¨ã‹ã‚‰æ´¾ç”Ÿã—ãŸè‘—作物を頒布ã‚ã‚‹ã„ã¯ç™ºè¡¨ã™ã‚‹å ´åˆã«ã¯ã€ãã®å…¨
- 体をã“ã®å¥‘約書ã®æ¡ä»¶ã«å¾“ã£ã¦ç¬¬ä¸‰è€…ã¸ç„¡å„Ÿã§åˆ©ç”¨è¨±è«¾ã—ãªã‘ã‚Œã°ãªã‚‰ãª
- ã„。
-
- c) 改変ã•ã‚ŒãŸãƒ—ログラムãŒã€é€šå¸¸å®Ÿè¡Œã™ã‚‹éš›ã«å¯¾è©±çš„ã«ã‚³ãƒžãƒ³ãƒ‰ã‚’読む
- よã†ã«ãªã£ã¦ã„ã‚‹ãªã‚‰ã°ã€ãã®ãƒ—ログラムを最も一般的ãªæ–¹æ³•ã§å¯¾è©±çš„ã«
- 実行ã™ã‚‹éš›ã€é©åˆ‡ãªè‘—作権表示ã€ç„¡ä¿è¨¼ã§ã‚ã‚‹ã“ã¨(ã‚ã‚‹ã„ã¯ã‚ãªãŸãŒä¿
- 証をæä¾›ã™ã‚‹ã¨ã„ã†ã“ã¨)ã€ãƒ¦ãƒ¼ã‚¶ãŒãƒ—ログラムをã“ã®å¥‘約書ã§è¿°ã¹ãŸæ¡
- 件ã®ä¸‹ã§é ’布ã™ã‚‹ã“ã¨ãŒã§ãã‚‹ã¨ã„ã†ã“ã¨ã€ãã—ã¦ã“ã®å¥‘約書ã®è¤‡è£½ç‰©ã‚’
- 閲覧ã™ã‚‹ã«ã¯ã©ã†ã—ãŸã‚‰ã‚ˆã„ã‹ã¨ã„ã†ãƒ¦ãƒ¼ã‚¶ã¸ã®èª¬æ˜Žã‚’å«ã‚€å‘ŠçŸ¥ãŒå°åˆ·ã•
- れるã‹ã€ã‚ã‚‹ã„ã¯ç”»é¢ã«è¡¨ç¤ºã•ã‚Œã‚‹ã‚ˆã†ã«ã—ãªã‘ã‚Œã°ãªã‚‰ãªã„(例外ã¨ã—
- ã¦ã€ã€Žãƒ—ログラムã€ãã®ã‚‚ã®ã¯å¯¾è©±çš„ã§ã‚ã£ã¦ã‚‚通常ãã®ã‚ˆã†ãªå‘ŠçŸ¥ã‚’å°
- 刷ã—ãªã„å ´åˆã«ã¯ã€ã€Žãƒ—ログラムã€ã‚’基ã«ã—ãŸã‚ãªãŸã®è‘—作物ã«ãã®ã‚ˆã†
- ãªå‘ŠçŸ¥ã‚’å°åˆ·ã•ã›ã‚‹å¿…è¦ã¯ãªã„)。
-
-以上ã®å¿…è¦æ¡ä»¶ã¯å…¨ä½“ã¨ã—ã¦ã®æ”¹å¤‰ã•ã‚ŒãŸè‘—作物ã«é©ç”¨ã•ã‚Œã‚‹ã€‚著作物ã®ä¸€éƒ¨
-ãŒã€Žãƒ—ログラムã€ã‹ã‚‰æ´¾ç”Ÿã—ãŸã‚‚ã®ã§ã¯ãªã„ã¨ç¢ºèªã§ãã€ãれら自身別ã®ç‹¬ç«‹
-ã—ãŸè‘—作物ã§ã‚ã‚‹ã¨åˆç†çš„ã«è€ƒãˆã‚‰ã‚Œã‚‹ãªã‚‰ã°ã€ã‚ãªãŸãŒãれらを別ã®è‘—作物
-ã¨ã—ã¦åˆ†ã‘ã¦é ’布ã™ã‚‹å ´åˆã€ãã†ã„ã£ãŸéƒ¨åˆ†ã«ã¯ã“ã®å¥‘約書ã¨ãã®æ¡ä»¶ã¯
-é©ç”¨ã•ã‚Œãªã„。ã—ã‹ã—ã€ã‚ãªãŸãŒåŒã˜éƒ¨åˆ†ã‚’『プログラムã€ã‚’基ã«ã—ãŸè‘—作物
-全体ã®ä¸€éƒ¨ã¨ã—ã¦é ’布ã™ã‚‹ãªã‚‰ã°ã€å…¨ä½“ã¨ã—ã¦ã®é ’布物ã¯ã€ã“ã®å¥‘約書ãŒ
-課ã™æ¡ä»¶ã«å¾“ã‚ãªã‘ã‚Œã°ãªã‚‰ãªã„。ã¨ã„ã†ã®ã¯ã€ã“ã®å¥‘約書ãŒä»–ã®å¥‘約者
-ã«ä¸Žãˆã‚‹è¨±å¯ã¯ã€Žãƒ—ログラムã€ä¸¸ã”ã¨å…¨ä½“ã«åŠã³ã€èª°ãŒæ›¸ã„ãŸã‹ã¯é–¢ä¿‚ãªãå„
-部分ã®ã™ã¹ã¦ã‚’ä¿è­·ã™ã‚‹ã‹ã‚‰ã§ã‚る。
-
-よã£ã¦ã€ã™ã¹ã¦ã‚ãªãŸã«ã‚ˆã£ã¦æ›¸ã‹ã‚ŒãŸè‘—作物ã«å¯¾ã—ã€æ¨©åˆ©ã‚’主張ã—ãŸã‚Šã‚ãª
-ãŸã®æ¨©åˆ©ã«ç•°è­°ã‚’申ã—ç«‹ã¦ã‚‹ã“ã¨ã¯ã“ã®ç¯€ã®æ„図ã™ã‚‹ã¨ã“ã‚ã§ã¯ãªã„。むã—ã‚ã€
-ãã®è¶£æ—¨ã¯ã€Žãƒ—ログラムã€ã‚’基ã«ã—ãŸæ´¾ç”Ÿç‰©ãªã„ã—集åˆè‘—作物ã®é ’布を管ç†ã™
-る権利を行使ã™ã‚‹ã¨ã„ã†ã“ã¨ã«ã‚る。
-
-ã¾ãŸã€ã€Žãƒ—ログラムã€ã‚’基ã«ã—ã¦ã„ãªã„ãã®ä»–ã®è‘—作物を『プログラムã€(ã‚
-ã‚‹ã„ã¯ã€Žãƒ—ログラムã€ã‚’基ã«ã—ãŸè‘—作物)ã¨ä¸€ç·’ã«é›†ã‚ãŸã ã‘ã®ã‚‚ã®ã‚’一巻ã®
-ä¿ç®¡è£…ç½®ãªã„ã—頒布媒体ã«åŽã‚ã¦ã‚‚ã€ãã®ä»–ã®è‘—作物ã¾ã§ã“ã®å¥‘約書ãŒä¿
-è­·ã™ã‚‹å¯¾è±¡ã«ãªã‚‹ã¨ã„ã†ã“ã¨ã«ã¯ãªã‚‰ãªã„。
-
-3. ã‚ãªãŸã¯ä¸Šè¨˜ç¬¬1節ãŠã‚ˆã³2節ã®æ¡ä»¶ã«å¾“ã„ã€ã€Žãƒ—ログラムã€(ã‚ã‚‹ã„ã¯ç¬¬2
-節ã«ãŠã‘る派生物)をオブジェクトコードãªã„ã—実行形å¼ã§è¤‡è£½ã¾ãŸã¯é ’布ã™
-ã‚‹ã“ã¨ãŒã§ãる。ãŸã ã—ã€ãã®å ´åˆã‚ãªãŸã¯ä»¥ä¸‹ã®ã†ã¡ã©ã‚Œã‹ä¸€ã¤ã‚’実施ã—ãª
-ã‘ã‚Œã°ãªã‚‰ãªã„:
-
- a) 著作物ã«ã€ã€Žãƒ—ログラムã€ã«å¯¾å¿œã—ãŸå®Œå…¨ã‹ã¤æ©Ÿæ¢°ã§èª­ã¿å–ã‚Šå¯èƒ½ãª
- ソースコードを添付ã™ã‚‹ã€‚ãŸã ã—ã€ã‚½ãƒ¼ã‚¹ã‚³ãƒ¼ãƒ‰ã¯ä¸Šè¨˜ç¬¬1節ãŠã‚ˆã³2節ã®
- æ¡ä»¶ã«å¾“ã„ソフトウェアã®äº¤æ›ã§ç¿’慣的ã«ä½¿ã‚れる媒体ã§é ’布ã—ãªã‘ã‚Œã°
- ãªã‚‰ãªã„。ã‚ã‚‹ã„ã¯ã€
-
- b) 著作物ã«ã€ã„ã‹ãªã‚‹ç¬¬ä¸‰è€…ã«å¯¾ã—ã¦ã‚‚ã€ã€Žãƒ—ログラムã€ã«å¯¾å¿œã—ãŸå®Œ
- å…¨ã‹ã¤æ©Ÿæ¢°ã§èª­ã¿å–ã‚Šå¯èƒ½ãªã‚½ãƒ¼ã‚¹ã‚³ãƒ¼ãƒ‰ã‚’ã€é ’布ã«è¦ã™ã‚‹ç‰©ç†çš„コスト
- を上回らãªã„程度ã®æ‰‹æ•°æ–™ã¨å¼•ãæ›ãˆã«æä¾›ã™ã‚‹æ—¨è¿°ã¹ãŸå°‘ãªãã¨ã‚‚3å¹´
- é–“ã¯æœ‰åŠ¹ãªæ›¸é¢ã«ãªã£ãŸç”³ã—出を添ãˆã‚‹ã€‚ãŸã ã—ã€ã‚½ãƒ¼ã‚¹ã‚³ãƒ¼ãƒ‰ã¯ä¸Šè¨˜ç¬¬
- 1節ãŠã‚ˆã³2節ã®æ¡ä»¶ã«å¾“ã„ソフトウェアã®äº¤æ›ã§ç¿’慣的ã«ä½¿ã‚れる媒体ã§
- 頒布ã—ãªã‘ã‚Œã°ãªã‚‰ãªã„。ã‚ã‚‹ã„ã¯ã€
-
- c) 対応ã™ã‚‹ã‚½ãƒ¼ã‚¹ã‚³ãƒ¼ãƒ‰é ’布ã®ç”³ã—出ã«éš›ã—ã¦ã€ã‚ãªãŸãŒå¾—ãŸæƒ…報を一
- ç·’ã«å¼•ã渡ã™(ã“ã®é¸æŠžè‚¢ã¯ã€å–¶åˆ©ã‚’目的ã¨ã—ãªã„頒布ã§ã‚ã£ã¦ã€ã‹ã¤ã‚
- ãªãŸãŒä¸Šè¨˜å°ç¯€bã§æŒ‡å®šã•ã‚Œã¦ã„るよã†ãªç”³ã—出ã¨å…±ã«ã‚ªãƒ–ジェクトコー
- ドã‚ã‚‹ã„ã¯å®Ÿè¡Œå½¢å¼ã®ãƒ—ログラムã—ã‹å…¥æ‰‹ã—ã¦ã„ãªã„å ´åˆã«é™ã‚Šè¨±å¯ã•ã‚Œ
- る)。
-
-著作物ã®ã‚½ãƒ¼ã‚¹ã‚³ãƒ¼ãƒ‰ã¨ã¯ã€ãã‚Œã«å¯¾ã—ã¦æ”¹å¤‰ã‚’加ãˆã‚‹ä¸Šã§å¥½ã¾ã—ã„ã¨ã•ã‚Œã‚‹
-著作物ã®å½¢å¼ã‚’æ„味ã™ã‚‹ã€‚ã‚る実行形å¼ã®è‘—作物ã«ã¨ã£ã¦å®Œå…¨ãªã‚½ãƒ¼ã‚¹ã‚³ãƒ¼ãƒ‰
-ã¨ã¯ã€ãã‚ŒãŒå«ã‚€ãƒ¢ã‚¸ãƒ¥ãƒ¼ãƒ«ã™ã¹ã¦ã®ã‚½ãƒ¼ã‚¹ã‚³ãƒ¼ãƒ‰å…¨éƒ¨ã«åŠ ãˆã€é–¢é€£ã™ã‚‹ã‚¤ãƒ³
-ターフェース定義ファイルã®ã™ã¹ã¦ã¨ãƒ©ã‚¤ãƒ–ラリã®ã‚³ãƒ³ãƒ‘イルやインストール
-を制御ã™ã‚‹ãŸã‚ã«ä½¿ã‚れるスクリプトをも加ãˆãŸã‚‚ã®ã‚’æ„味ã™ã‚‹ã€‚ã—ã‹ã—特別
-ãªä¾‹å¤–ã¨ã—ã¦ã€ãã®ã‚³ãƒ³ãƒãƒ¼ãƒãƒ³ãƒˆè‡ªä½“ãŒå®Ÿè¡Œå½¢å¼ã«ä»˜éšã™ã‚‹ã®ã§ã¯ç„¡ã„é™ã‚Šã€
-頒布ã•ã‚Œã‚‹ã‚‚ã®ã®ä¸­ã«ã€å®Ÿè¡Œå½¢å¼ãŒå®Ÿè¡Œã•ã‚Œã‚‹ã‚ªãƒšãƒ¬ãƒ¼ãƒ†ã‚£ãƒ³ã‚°ã‚·ã‚¹ãƒ†ãƒ ã®ä¸»
-è¦ãªã‚³ãƒ³ãƒãƒ¼ãƒãƒ³ãƒˆ(コンパイラやカーãƒãƒ«ç­‰)ã¨é€šå¸¸ä¸€ç·’ã«(ソースã‹ãƒã‚¤ãƒŠ
-リ形å¼ã®ã©ã¡ã‚‰ã‹ã§)頒布ã•ã‚Œã‚‹ã‚‚ã®ã‚’å«ã‚“ã§ã„ã‚‹å¿…è¦ã¯ãªã„ã¨ã™ã‚‹ã€‚
-
-実行形å¼ã¾ãŸã¯ã‚ªãƒ–ジェクトコードã®é ’布ãŒã€æŒ‡å®šã•ã‚ŒãŸå ´æ‰€ã‹ã‚‰ã‚³ãƒ”ーã™ã‚‹
-ãŸã‚ã®ã‚¢ã‚¯ã‚»ã‚¹æ‰‹æ®µã‚’æä¾›ã™ã‚‹ã“ã¨ã§ç‚ºã•ã‚Œã‚‹ã¨ã—ã¦ã€ãã®ä¸Šã§ã‚½ãƒ¼ã‚¹ã‚³ãƒ¼ãƒ‰
-ã‚‚åŒç­‰ã®ã‚¢ã‚¯ã‚»ã‚¹æ‰‹æ®µã«ã‚ˆã£ã¦åŒã˜å ´æ‰€ã‹ã‚‰ã‚³ãƒ”ーã§ãるよã†ã«ãªã£ã¦ã„ã‚‹ãª
-らã°ã€ç¬¬ä¸‰è€…ãŒã‚ªãƒ–ジェクトコードã¨ä¸€ç·’ã«ã‚½ãƒ¼ã‚¹ã‚‚強制的ã«ã‚³ãƒ”ーã•ã›ã‚‰ã‚Œ
-るよã†ã«ãªã£ã¦ã„ãªãã¦ã‚‚ソースコード頒布ã®æ¡ä»¶ã‚’満ãŸã—ã¦ã„ã‚‹ã‚‚ã®ã¨ã™ã‚‹ã€‚
-
-4. ã‚ãªãŸã¯ã€Žãƒ—ログラムã€ã‚’ã€ã“ã®å¥‘約書ã«ãŠã„ã¦æ˜Žç¢ºã«æ示ã•ã‚ŒãŸè¡Œ
-為を除ã複製や改変ã€ã‚µãƒ–ライセンスã€ã‚ã‚‹ã„ã¯é ’布ã—ã¦ã¯ãªã‚‰ãªã„。他ã«
-『プログラムã€ã‚’複製や改変ã€ã‚µãƒ–ライセンスã€ã‚ã‚‹ã„ã¯é ’布ã™ã‚‹ä¼ã¦ã¯ã™ã¹
-ã¦ç„¡åŠ¹ã§ã‚ã‚Šã€ã“ã®å¥‘約書ã®ä¸‹ã§ã®ã‚ãªãŸã®æ¨©åˆ©ã‚’自動的ã«çµ‚çµã•ã›ã‚‹ã“
-ã¨ã«ãªã‚ã†ã€‚ã—ã‹ã—ã€è¤‡è£½ç‰©ã‚„権利をã“ã®å¥‘約書ã«å¾“ã£ã¦ã‚ãªãŸã‹ã‚‰å¾—ãŸ
-人々ã«é–¢ã—ã¦ã¯ã€ãã®ã‚ˆã†ãªäººã€…ãŒã“ã®å¥‘約書ã«å®Œå…¨ã«å¾“ã£ã¦ã„ã‚‹é™ã‚Šå½¼
-らã®ãƒ©ã‚¤ã‚»ãƒ³ã‚¹ã¾ã§çµ‚çµã™ã‚‹ã“ã¨ã¯ãªã„。
-
-5. ã‚ãªãŸã¯ã“ã®å¥‘約書をå—諾ã™ã‚‹å¿…è¦ã¯ç„¡ã„。ã¨ã„ã†ã®ã¯ã€ã‚ãªãŸã¯ã“
-ã‚Œã«ç½²åã—ã¦ã„ãªã„ã‹ã‚‰ã§ã‚る。ã—ã‹ã—ã€ã“ã®å¥‘約書以外ã«ã‚ãªãŸã«å¯¾ã—
-ã¦ã€Žãƒ—ログラムã€ã‚„ãã®æ´¾ç”Ÿç‰©ã‚’変更ã€é ’布ã™ã‚‹è¨±å¯ã‚’与ãˆã‚‹ã‚‚ã®ã¯å­˜åœ¨ã—ãª
-ã„。ã“れらã®è¡Œç‚ºã¯ã€ã‚ãªãŸãŒã“ã®å¥‘約書をå—ã‘入れãªã„é™ã‚Šæ³•ã«ã‚ˆã£ã¦
-ç¦ã˜ã‚‰ã‚Œã¦ã„る。ãã“ã§ã€ã€Žãƒ—ログラムã€(ã‚ã‚‹ã„ã¯ã€Žãƒ—ログラムã€ã‚’基ã«ã—
-ãŸè‘—作物ã®ã™ã¹ã¦)を改変ãªã„ã—頒布ã™ã‚‹ã“ã¨ã«ã‚ˆã‚Šã€ã‚ãªãŸã¯è‡ªåˆ†ãŒãã®ã‚ˆ
-ã†ãªè¡Œç‚ºã‚’è¡Œã†ãŸã‚ã«ã“ã®å¥‘約書をå—諾ã—ãŸã¨ã„ã†ã“ã¨ã€ãã—ã¦ã€Žãƒ—ログ
-ラムã€ã¨ãã‚Œã«åŸºã¥ã著作物ã®è¤‡è£½ã‚„頒布ã€æ”¹å¤‰ã«ã¤ã„ã¦ã“ã®å¥‘約書ãŒèª²
-ã™åˆ¶ç´„ã¨æ¡ä»¶ã‚’ã™ã¹ã¦å—ã‘入れãŸã¨ã„ã†ã“ã¨ã‚’示ã—ãŸã‚‚ã®ã¨è¦‹ãªã™ã€‚
-
-6. ã‚ãªãŸãŒã€Žãƒ—ログラムã€(ã¾ãŸã¯ã€Žãƒ—ログラムã€ã‚’基ã«ã—ãŸè‘—作物全般)ã‚’
-å†é ’布ã™ã‚‹ãŸã³ã«ã€ãã®å—領者ã¯å…ƒã€…ã®ãƒ©ã‚¤ã‚»ãƒ³ã‚¹è¨±å¯è€…ã‹ã‚‰ã€ã“ã®å¥‘約書ã§
-指定ã•ã‚ŒãŸæ¡ä»¶ã¨åˆ¶ç´„ã®ä¸‹ã§ã€Žãƒ—ログラムã€ã‚’複製や頒布ã€ã‚ã‚‹ã„ã¯æ”¹å¤‰ã™ã‚‹
-許å¯ã‚’自動的ã«å¾—ã‚‹ã‚‚ã®ã¨ã™ã‚‹ã€‚ã‚ãªãŸã¯ã€å—領者ãŒã“ã“ã§èªã‚られãŸæ¨©åˆ©ã‚’
-行使ã™ã‚‹ã“ã¨ã«é–¢ã—ã¦ã“れ以上他ã®ã„ã‹ãªã‚‹åˆ¶é™ã‚‚課ã™ã“ã¨ãŒã§ããªã„。ã‚ãª
-ãŸã«ã¯ã€ç¬¬ä¸‰è€…ãŒã“ã®å¥‘約書ã«å¾“ã†ã“ã¨ã‚’強制ã™ã‚‹è²¬ä»»ã¯ãªã„。
-
-7. 特許侵害ã‚ã‚‹ã„ã¯ãã®ä»–ã®ç†ç”±(特許関係ã«é™ã‚‰ãªã„)ã‹ã‚‰ã€è£åˆ¤æ‰€ã®åˆ¤æ±º
-ã‚ã‚‹ã„ã¯ç”³ã—ç«‹ã¦ã®çµæžœã¨ã—ã¦ã‚ãªãŸã«(è£åˆ¤æ‰€å‘½ä»¤ã‚„契約ãªã©ã«ã‚ˆã‚Š)ã“ã®å¥‘
-約書ã®æ¡ä»¶ã¨çŸ›ç›¾ã™ã‚‹åˆ¶ç´„ãŒèª²ã•ã‚ŒãŸå ´åˆã§ã‚‚ã€ã‚ãªãŸãŒã“ã®å¥‘約書ã®æ¡ä»¶ã‚’
-å…除ã•ã‚Œã‚‹ã‚ã‘ã§ã¯ãªã„。もã—ã“ã®å¥‘約書ã®ä¸‹ã§ã‚ãªãŸã«èª²ã›ã‚‰ã‚ŒãŸè²¬ä»»ã¨ä»–
-ã®é–¢é€£ã™ã‚‹è²¬ä»»ã‚’åŒæ™‚ã«æº€ãŸã™ã‚ˆã†ãªå½¢ã§é ’布ã§ããªã„ãªã‚‰ã°ã€çµæžœã¨ã—ã¦ã‚
-ãªãŸã¯ã€Žãƒ—ログラムã€ã‚’頒布ã™ã‚‹ã“ã¨ãŒå…¨ãã§ããªã„ã¨ã„ã†ã“ã¨ã§ã‚る。例ãˆ
-ã°ç‰¹è¨±ãƒ©ã‚¤ã‚»ãƒ³ã‚¹ãŒã€ã‚ãªãŸã‹ã‚‰ç›´æŽ¥é–“接をå•ã‚ãšã‚³ãƒ”ーをå—ã‘å–ã£ãŸäººãŒèª°
-ã§ã‚‚『プログラムã€ã‚’使用料無料ã§å†é ’布ã™ã‚‹ã“ã¨ã‚’èªã‚ã¦ã„ãªã„å ´åˆã€ã‚ãª
-ãŸãŒãã®åˆ¶ç´„ã¨ã“ã®å¥‘約書を両方ã¨ã‚‚満ãŸã™ã«ã¯ã€Žãƒ—ログラムã€ã®é ’布を完全
-ã«ä¸­æ­¢ã™ã‚‹ã—ã‹ãªã„ã ã‚ã†ã€‚
-
-ã“ã®ç¯€ã®ä¸€éƒ¨åˆ†ãŒç‰¹å®šã®çŠ¶æ³ã®ä¸‹ã§ç„¡åŠ¹ãªã„ã—実施ä¸å¯èƒ½ãªå ´åˆã§ã‚‚ã€ç¯€ã®æ®‹
-ã‚Šã®éƒ¨åˆ†ã¯é©ç”¨ã•ã‚Œã‚‹ã‚ˆã†æ„図ã•ã‚Œã¦ã„る。ãã®ä»–ã®çŠ¶æ³ã§ã¯ç¯€ãŒå…¨ä½“ã¨ã—ã¦
-é©ç”¨ã•ã‚Œã‚‹ã‚ˆã†æ„図ã•ã‚Œã¦ã„る。
-
-特許やãã®ä»–ã®è²¡ç”£æ¨©ã‚’侵害ã—ãŸã‚Šã€ãã®ã‚ˆã†ãªæ¨©åˆ©ã®ä¸»å¼µã®åŠ¹åŠ›ã«ç•°è­°ã‚’å”±
-ãˆãŸã‚Šã™ã‚‹ã‚ˆã†ã‚ãªãŸã‚’誘惑ã™ã‚‹ã“ã¨ãŒã“ã®ç¯€ã®ç›®çš„ã§ã¯ãªã„。ã“ã®ç¯€ã«ã¯ã€
-人々ã«ã‚ˆã£ã¦ãƒ©ã‚¤ã‚»ãƒ³ã‚¹æ…£è¡Œã¨ã—ã¦å®Ÿç¾ã•ã‚Œã¦ããŸã€ãƒ•ãƒªãƒ¼ã‚½ãƒ•ãƒˆã‚¦ã‚§ã‚¢é ’布
-ã®ã‚·ã‚¹ãƒ†ãƒ ã®å®Œå…¨æ€§ã‚’è­·ã‚‹ã¨ã„ã†ç›®çš„ã—ã‹ãªã„。多ãã®äººã€…ãŒã€ãƒ•ãƒªãƒ¼ã‚½ãƒ•ãƒˆ
-ウェアã®é ’布システムãŒé¦–尾一貫ã—ã¦é©ç”¨ã•ã‚Œã¦ã„ã‚‹ã¨ã„ã†ä¿¡é ¼ã«åŸºã¥ãã€ã“
-ã®ã‚·ã‚¹ãƒ†ãƒ ã‚’通ã˜ã¦é ’布ã•ã‚Œã‚‹å¤šæ§˜ãªã‚½ãƒ•ãƒˆã‚¦ã‚§ã‚¢ã«å¯›å¤§ãªè²¢çŒ®ã‚’ã—ã¦ããŸã®
-ã¯äº‹å®Ÿã§ã‚ã‚‹ãŒã€äººãŒã©ã®ã‚ˆã†ãªã‚·ã‚¹ãƒ†ãƒ ã‚’通ã˜ã¦ã‚½ãƒ•ãƒˆã‚¦ã‚§ã‚¢ã‚’頒布ã—ãŸã„
-ã¨æ€ã†ã‹ã¯ã‚ãã¾ã§ã‚‚作者/寄与者次第ã§ã‚ã‚Šã€ã‚ãªãŸãŒé¸æŠžã‚’押ã—ã¤ã‘ã‚‹ã“
-ã¨ã¯ã§ããªã„。
-
-ã“ã®ç¯€ã¯ã€ã“ã®å¥‘約書ã®ã“ã®ç¯€ä»¥å¤–ã®éƒ¨åˆ†ã®ä¸€å¸°çµã«ãªã‚‹ã¨è€ƒãˆã‚‰ã‚Œã‚‹ã‚±ãƒ¼
-スを徹底的ã«æ˜Žã‚‰ã‹ã«ã™ã‚‹ã“ã¨ã‚’目的ã¨ã—ã¦ã„る。
-
-8. 『プログラムã€ã®é ’布や利用ãŒã€ã‚る国ã«ãŠã„ã¦ã¯ç‰¹è¨±ã¾ãŸã¯è‘—作権ãŒä¸»
-å¼µã•ã‚ŒãŸã‚¤ãƒ³ã‚¿ãƒ¼ãƒ•ã‚§ãƒ¼ã‚¹ã®ã„ãšã‚Œã‹ã«ã‚ˆã£ã¦åˆ¶é™ã•ã‚Œã¦ã„ã‚‹å ´åˆã€ã€Žãƒ—ログ
-ラムã€ã«ã“ã®å¥‘約書をé©ç”¨ã—ãŸå…ƒã®è‘—作権者ã¯ã€ãã†ã„ã£ãŸå›½ã€…を排除ã—
-ãŸæ˜Žç¢ºãªåœ°ç†çš„頒布制é™ã‚’加ãˆã€ãã“ã§æŽ’除ã•ã‚Œã¦ã„ãªã„国ã®ä¸­ã‚„ãれらã®å›½ã€…
-ã®é–“ã§ã®ã¿é ’布ãŒè¨±å¯ã•ã‚Œã‚‹ã‚ˆã†ã«ã—ã¦ã‚‚構ã‚ãªã„。ãã®å ´åˆã€ãã®ã‚ˆã†ãªåˆ¶
-é™ã¯ã“ã®å¥‘約書本文ã§æ›¸ã‹ã‚Œã¦ã„ã‚‹ã®ã¨åŒæ§˜ã«è¦‹ãªã•ã‚Œã‚‹ã€‚
-
-9. フリーソフトウェア財団ã¯ã€æ™‚ã«ã‚ˆã£ã¦æ”¹è¨‚ã¾ãŸã¯æ–°ç‰ˆã®ä¸€èˆ¬å…¬è¡†åˆ©ç”¨è¨±
-諾書を発表ã™ã‚‹ã“ã¨ãŒã§ãる。ãã®ã‚ˆã†ãªæ–°ç‰ˆã¯ç¾åœ¨ã®ãƒãƒ¼ã‚¸ãƒ§ãƒ³ã¨ãã®ç²¾ç¥ž
-ã«ãŠã„ã¦ã¯ä¼¼ãŸã‚‚ã®ã«ãªã‚‹ã ã‚ã†ãŒã€æ–°ãŸãªå•é¡Œã‚„懸念を解決ã™ã‚‹ãŸã‚細部ã§
-ã¯ç•°ãªã‚‹å¯èƒ½æ€§ãŒã‚る。
-
-ãã‚Œãžã‚Œã®ãƒãƒ¼ã‚¸ãƒ§ãƒ³ã«ã¯ã€è¦‹åˆ†ã‘ãŒä»˜ãよã†ã«ãƒãƒ¼ã‚¸ãƒ§ãƒ³ç•ªå·ãŒæŒ¯ã‚‰ã‚Œã¦ã„
-る。『プログラムã€ã«ãŠã„ã¦ãã‚Œã«é©ç”¨ã•ã‚Œã‚‹ã“ã®å¥‘約書ã®ãƒãƒ¼ã‚¸ãƒ§ãƒ³ç•ªå·ãŒ
-指定ã•ã‚Œã¦ã„ã¦ã€æ›´ã«ã€Œãれ以é™ã®ã„ã‹ãªã‚‹ãƒãƒ¼ã‚¸ãƒ§ãƒ³ã€ã‚‚é©ç”¨ã—ã¦è‰¯ã„ã¨ãªã£
-ã¦ã„ãŸå ´åˆã€ã‚ãªãŸã¯å¾“ã†æ¡ä»¶ã¨åˆ¶ç´„ã¨ã—ã¦ã€æŒ‡å®šã®ãƒãƒ¼ã‚¸ãƒ§ãƒ³ã‹ã€ãƒ•ãƒªãƒ¼ã‚½
-フトウェア財団ã«ã‚ˆã£ã¦ç™ºè¡Œã•ã‚ŒãŸæŒ‡å®šã®ãƒãƒ¼ã‚¸ãƒ§ãƒ³ä»¥é™ã®ç‰ˆã®ã©ã‚Œã‹ä¸€ã¤ã®
-ã©ã¡ã‚‰ã‹ã‚’é¸ã¶ã“ã¨ãŒå‡ºæ¥ã‚‹ã€‚『プログラムã€ã§ãƒ©ã‚¤ã‚»ãƒ³ã‚¹ã®ãƒãƒ¼ã‚¸ãƒ§ãƒ³ç•ªå·
-ãŒæŒ‡å®šã•ã‚Œã¦ã„ãªã„ãªã‚‰ã°ã€ã‚ãªãŸã¯ä»Šã¾ã§ã«ãƒ•ãƒªãƒ¼ã‚½ãƒ•ãƒˆã‚¦ã‚§ã‚¢è²¡å›£ã‹ã‚‰ç™º
-è¡Œã•ã‚ŒãŸãƒãƒ¼ã‚¸ãƒ§ãƒ³ã®ä¸­ã‹ã‚‰å¥½ãã«é¸ã‚“ã§æ§‹ã‚ãªã„。
-
-10. ã‚‚ã—ã‚ãªãŸãŒã€Žãƒ—ログラムã€ã®ä¸€éƒ¨ã‚’ã€ãã®é ’布æ¡ä»¶ãŒã“ã®å¥‘約書ã¨
-ç•°ãªã‚‹ä»–ã®ãƒ•ãƒªãƒ¼ãªãƒ—ログラムã¨çµ±åˆã—ãŸã„ãªã‚‰ã°ã€ä½œè€…ã«é€£çµ¡ã—ã¦è¨±å¯ã‚’求
-ã‚よ。フリーソフトウェア財団ãŒè‘—作権をä¿æœ‰ã™ã‚‹ã‚½ãƒ•ãƒˆã‚¦ã‚§ã‚¢ã«ã¤ã„ã¦ã¯ã€
-フリーソフトウェア財団ã«é€£çµ¡ã›ã‚ˆã€‚ç§ãŸã¡ã¯ã€ã“ã®ã‚ˆã†ãªå ´åˆã®ãŸã‚ã«ç‰¹åˆ¥
-ãªä¾‹å¤–を設ã‘ã‚‹ã“ã¨ã‚‚ã‚る。ç§ãŸã¡ãŒæ±ºå®šã‚’下ã™ã«ã‚ãŸã£ã¦ã¯ã€ç§ãŸã¡ã®ãƒ•ãƒªãƒ¼
-ソフトウェアã®æ´¾ç”Ÿç‰©ã™ã¹ã¦ãŒãƒ•ãƒªãƒ¼ãªçŠ¶æ…‹ã«ä¿ãŸã‚Œã‚‹ã¨ã„ã†ã“ã¨ã¨ã€ä¸€èˆ¬çš„
-ã«ã‚½ãƒ•ãƒˆã‚¦ã‚§ã‚¢ã®å…±æœ‰ã¨å†åˆ©ç”¨ã‚’促進ã™ã‚‹ã¨ã„ã†äºŒã¤ã®ç›®æ¨™ã‚’è¦æº–ã«æ¤œè¨Žã•ã‚Œ
-ã‚‹ã§ã‚ã‚ã†ã€‚
- ç„¡ä¿è¨¼ã«ã¤ã„ã¦
-
-11. 『プログラムã€ã¯ä»£ä¾¡ç„¡ã—ã«åˆ©ç”¨ãŒè¨±å¯ã•ã‚Œã‚‹ã®ã§ã€é©åˆ‡ãªæ³•ãŒèªã‚ã‚‹é™
-ã‚Šã«ãŠã„ã¦ã€ã€Žãƒ—ログラムã€ã«é–¢ã™ã‚‹ã„ã‹ãªã‚‹ä¿è¨¼ã‚‚存在ã—ãªã„。書é¢ã§åˆ¥ã«
-è¿°ã¹ã‚‹å ´åˆã‚’除ã„ã¦ã€è‘—作権者ã€ã¾ãŸã¯ãã®ä»–ã®å›£ä½“ã¯ã€ã€Žãƒ—ログラムã€ã‚’ã€
-表明ã•ã‚ŒãŸã‹è¨€å¤–ã«ã‹ã¯å•ã‚ãšã€å•†æ¥­çš„é©æ€§ã‚’ä¿è¨¼ã™ã‚‹ã»ã®ã‚ã‹ã—ã‚„ã‚る特定
-ã®ç›®çš„ã¸ã®é©åˆæ€§(ã«é™ã‚‰ã‚Œãªã„)ã‚’å«ã‚€ä¸€åˆ‡ã®ä¿è¨¼ç„¡ã—ã«ã€Œã‚ã‚‹ãŒã¾ã¾ã€ã§æ
-ä¾›ã™ã‚‹ã€‚『プログラムã€ã®è³ªã¨æ€§èƒ½ã«é–¢ã™ã‚‹ãƒªã‚¹ã‚¯ã®ã™ã¹ã¦ã¯ã‚ãªãŸã«å¸°å±žã™
-る。『プログラムã€ã«æ¬ é™¥ãŒã‚ã‚‹ã¨åˆ¤æ˜Žã—ãŸå ´åˆã€ã‚ãªãŸã¯å¿…è¦ãªä¿å®ˆç‚¹æ¤œã‚„
-補修ã€ä¿®æ­£ã«è¦ã™ã‚‹ã‚³ã‚¹ãƒˆã®ã™ã¹ã¦ã‚’引ãå—ã‘ã‚‹ã“ã¨ã«ãªã‚‹ã€‚
-
-12. é©åˆ‡ãªæ³•ã‹æ›¸é¢ã§ã®åŒæ„ã«ã‚ˆã£ã¦å‘½ãœã‚‰ã‚Œãªã„é™ã‚Šã€è‘—作権者ã€ã¾ãŸã¯ä¸Š
-記ã§è¨±å¯ã•ã‚Œã¦ã„る通りã«ã€Žãƒ—ログラムã€ã‚’改変ã¾ãŸã¯å†é ’布ã—ãŸãã®ä»–ã®å›£
-体ã¯ã€ã‚ãªãŸã«å¯¾ã—ã¦ã€Žãƒ—ログラムã€ã®åˆ©ç”¨ãªã„ã—利用ä¸èƒ½ã§ç”Ÿã˜ãŸä¸€èˆ¬çš„ã€
-特別的ã€å¶ç„¶çš„ã€å¿…然的ãªæ害(データã®æ¶ˆå¤±ã‚„ä¸æ­£ç¢ºãªå‡¦ç†ã€ã‚ãªãŸã‹ç¬¬ä¸‰
-者ãŒè¢«ã£ãŸæ失ã€ã‚ã‚‹ã„ã¯ã€Žãƒ—ログラムã€ãŒä»–ã®ã‚½ãƒ•ãƒˆã‚¦ã‚§ã‚¢ã¨ä¸€ç·’ã«å‹•ä½œã—
-ãªã„ã¨ã„ã†ä¸å…·åˆãªã©ã‚’å«ã‚€ãŒãれらã«é™ã‚‰ãªã„)ã«ä¸€åˆ‡ã®è²¬ä»»ã‚’è² ã‚ãªã„。
-ãã®ã‚ˆã†ãªæ害ãŒç”Ÿãšã‚‹å¯èƒ½æ€§ã«ã¤ã„ã¦å½¼ã‚‰ãŒå¿ å‘Šã•ã‚Œã¦ã„ãŸã¨ã—ã¦ã‚‚åŒæ§˜ã§
-ã‚る。
-
- æ¡ä»¶ã¨åˆ¶ç´„終ã‚ã‚Š
-
- 以上ã®æ¡é …ã‚’ã‚ãªãŸã®æ–°ã—ã„プログラムã«é©ç”¨ã™ã‚‹æ–¹æ³•
-
-ã‚ãªãŸãŒæ–°ã—ã„プログラムを開発ã—ãŸã¨ã—ã¦ã€å…¬è¡†ã«ã‚ˆã£ã¦ãã‚ŒãŒåˆ©ç”¨ã•ã‚Œã‚‹
-å¯èƒ½æ€§ã‚’最大ã«ã—ãŸã„ãªã‚‰ã€ãã®ãƒ—ログラムをã“ã®å¥‘約書ã®æ¡é …ã«å¾“ã£ã¦
-誰ã§ã‚‚å†é ’布ã‚ã‚‹ã„ã¯å¤‰æ›´ã§ãるよã†ãƒ•ãƒªãƒ¼ã‚½ãƒ•ãƒˆã‚¦ã‚§ã‚¢ã«ã™ã‚‹ã®ãŒæœ€å–„ã§ã™ã€‚
-
-ãã®ãŸã‚ã«ã¯ã€ãƒ—ログラムã«ä»¥ä¸‹ã®ã‚ˆã†ãªè¡¨ç¤ºã‚’添付ã—ã¦ãã ã•ã„。ãã®å ´åˆã€
-ä¿è¨¼ãŒæŽ’除ã•ã‚Œã¦ã„ã‚‹ã¨ã„ã†ã“ã¨ã‚’最も効果的ã«ä¼ãˆã‚‹ãŸã‚ã«ã€ãã‚Œãžã‚Œã®ã‚½ãƒ¼
-スファイルã®å†’é ­ã«è¡¨ç¤ºã‚’添付ã™ã‚Œã°æœ€ã‚‚安全ã§ã™ã€‚å°‘ãªãã¨ã‚‚ã€ã€Œè‘—作権表
-示ã€ã¨ã„ã†è¡Œã¨å…¨æ–‡ãŒã‚る場所ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã ã‘ã¯å„ファイルã«å«ã‚ã¦ç½®ã„ã¦
-ãã ã•ã„。
-
- <one line to give the program's name and a brief idea of what it does.>
- Copyright (C) <year> <name of author>
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
- (訳:
-
- <プログラムã®åå‰ã¨ã€ãã‚ŒãŒä½•ã‚’ã™ã‚‹ã‹ã«ã¤ã„ã¦ã®ç°¡å˜ãªèª¬æ˜Žã€‚>
- Copyright (C) <西暦年> <作者ã®åå‰>
-
- ã“ã®ãƒ—ログラムã¯ãƒ•ãƒªãƒ¼ã‚½ãƒ•ãƒˆã‚¦ã‚§ã‚¢ã§ã™ã€‚ã‚ãªãŸã¯ã“れをã€ãƒ•ãƒªãƒ¼ã‚½ãƒ•
- トウェア財団ã«ã‚ˆã£ã¦ç™ºè¡Œã•ã‚ŒãŸ GNU 一般公衆利用許諾契約書(ãƒãƒ¼ã‚¸ãƒ§
- ン2ã‹ã€å¸Œæœ›ã«ã‚ˆã£ã¦ã¯ãれ以é™ã®ãƒãƒ¼ã‚¸ãƒ§ãƒ³ã®ã†ã¡ã©ã‚Œã‹)ã®å®šã‚ã‚‹æ¡ä»¶
- ã®ä¸‹ã§å†é ’布ã¾ãŸã¯æ”¹å¤‰ã™ã‚‹ã“ã¨ãŒã§ãã¾ã™ã€‚
-
- ã“ã®ãƒ—ログラムã¯æœ‰ç”¨ã§ã‚ã‚‹ã“ã¨ã‚’願ã£ã¦é ’布ã•ã‚Œã¾ã™ãŒã€*å…¨ãã®ç„¡ä¿
- 証* ã§ã™ã€‚商業å¯èƒ½æ€§ã®ä¿è¨¼ã‚„特定ã®ç›®çš„ã¸ã®é©åˆæ€§ã¯ã€è¨€å¤–ã«ç¤ºã•ã‚ŒãŸ
- ã‚‚ã®ã‚‚å«ã‚å…¨ã存在ã—ã¾ã›ã‚“。詳ã—ãã¯GNU 一般公衆利用許諾契約書をã”
- 覧ãã ã•ã„。
-
- ã‚ãªãŸã¯ã“ã®ãƒ—ログラムã¨å…±ã«ã€GNU 一般公衆利用許諾契約書ã®è¤‡è£½ç‰©ã‚’
- 一部å—ã‘å–ã£ãŸã¯ãšã§ã™ã€‚ã‚‚ã—å—ã‘å–ã£ã¦ã„ãªã‘ã‚Œã°ã€ãƒ•ãƒªãƒ¼ã‚½ãƒ•ãƒˆã‚¦ã‚§
- ア財団ã¾ã§è«‹æ±‚ã—ã¦ãã ã•ã„(宛先㯠the Free Software Foundation,
- Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA)。
-
- )
-
-é›»å­ãªã„ã—ç´™ã®ãƒ¡ãƒ¼ãƒ«ã§ã‚ãªãŸã«å•ã„åˆã‚ã›ã‚‹æ–¹æ³•ã«ã¤ã„ã¦ã®æƒ…報も書ã加ãˆ
-ã¾ã—ょã†ã€‚
-
-プログラムãŒå¯¾è©±çš„ãªã‚‚ã®ãªã‚‰ã°ã€å¯¾è©±ãƒ¢ãƒ¼ãƒ‰ã§èµ·å‹•ã—ãŸéš›ã«å‡ºåŠ›ã¨ã—ã¦ä»¥ä¸‹
-ã®ã‚ˆã†ãªçŸ­ã„告知ãŒè¡¨ç¤ºã•ã‚Œã‚‹ã‚ˆã†ã«ã—ã¦ãã ã•ã„:
-
- Gnomovision version 69, Copyright (C) year name of author
- Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
- This is free software, and you are welcome to redistribute it
- under certain conditions; type `show c' for details.
-
- (訳:
-
- Gnomovision ãƒãƒ¼ã‚¸ãƒ§ãƒ³ 69, Copyright (C) å¹´ 作者ã®åå‰
- Gnomovision ã¯*å…¨ãã®ç„¡ä¿è¨¼*ã§æä¾›ã•ã‚Œã¾ã™ã€‚詳ã—ãã¯ã€Œshow wã€
- ã¨ã‚¿ã‚¤ãƒ—ã—ã¦ä¸‹ã•ã„。ã“ã‚Œã¯ãƒ•ãƒªãƒ¼ã‚½ãƒ•ãƒˆã‚¦ã‚§ã‚¢ã§ã‚ã‚Šã€ã‚ã‚‹æ¡ä»¶ã®ä¸‹ã§
- å†é ’布ã™ã‚‹ã“ã¨ãŒå¥¨åŠ±ã•ã‚Œã¦ã„ã¾ã™ã€‚詳ã—ãã¯ã€Œshow cã€ã¨ã‚¿ã‚¤ãƒ—ã—ã¦ä¸‹
- ã•ã„。
-
- )
-
-ã“ã“ã§ã€ä»®æƒ³çš„ãªã‚³ãƒžãƒ³ãƒ‰ã€Œshow wã€ã¨ã€Œshow cã€ã¯ä¸€èˆ¬å…¬è¡†åˆ©ç”¨è¨±è«¾å¥‘約書
-ã®é©åˆ‡ãªéƒ¨åˆ†ã‚’表示ã™ã‚‹ã‚ˆã†ã«ãªã£ã¦ã„ãªã‘ã‚Œã°ãªã‚Šã¾ã›ã‚“。もã¡ã‚ã‚“ã€ã‚ãª
-ãŸãŒä½¿ã†ã‚³ãƒžãƒ³ãƒ‰ã‚’「show wã€ã‚„「show cã€ã¨å‘¼ã¶å¿…然性ã¯ã‚ã‚Šã¾ã›ã‚“ã®ã§ã€
-ã‚ãªãŸã®ãƒ—ログラムã«åˆã‚ã›ã¦ãƒžã‚¦ã‚¹ã®ã‚¯ãƒªãƒƒã‚¯ã‚„メニューã®ã‚¢ã‚¤ãƒ†ãƒ ã«ã—ã¦
-ã‚‚çµæ§‹ã§ã™ã€‚
-
-ã¾ãŸã‚ãªãŸã¯ã€å¿…è¦ãªã‚‰ã°(プログラマーã¨ã—ã¦åƒã„ã¦ã„ãŸã‚‰)ã‚ãªãŸã®é›‡ç”¨ä¸»ã€
-ã‚ã‚‹ã„ã¯å ´åˆã«ã‚ˆã£ã¦ã¯å­¦æ ¡ã‹ã‚‰ã€ãã®ãƒ—ログラムã«é–¢ã™ã‚‹ã€Œè‘—作権放棄声明
-(copyright disclaimer)ã€ã«ç½²åã—ã¦ã‚‚らã†ã¹ãã§ã™ã€‚以下ã¯ä¾‹ã§ã™ã®ã§ã€å
-å‰ã‚’変ãˆã¦ãã ã•ã„:
-
- Yoyodyne, Inc., hereby disclaims all copyright interest in the program
- `Gnomovision' (which makes passes at compilers) written by James Hacker.
-
- <signature of Ty Coon>, 1 April 1989
- Ty Coon, President of Vice
-
- (訳:
-
- Yoyodyne社ã¯ã“ã“ã«ã€James Hackerã«ã‚ˆã£ã¦æ›¸ã‹ã‚ŒãŸãƒ—ログラム
- 「Gnomovisionã€(コンパイラã¸é€šã™ãƒ—ログラム)ã«é–¢ã™ã‚‹ä¸€åˆ‡ã®è‘—作権ã®åˆ©
- 益を放棄ã—ã¾ã™ã€‚
-
- <Ty Coonæ°ã®ç½²å>ã€1989å¹´4月1æ—¥
- Ty Coonã€å‰¯ç¤¾é•·
-
- )
-
-ã“ã®ä¸€èˆ¬å…¬è¡†åˆ©ç”¨è¨±è«¾å¥‘約書ã§ã¯ã€ã‚ãªãŸã®ãƒ—ログラムを独å çš„ãªãƒ—ログラム
-ã«çµ±åˆã™ã‚‹ã“ã¨ã‚’èªã‚ã¦ã„ã¾ã›ã‚“。ã‚ãªãŸã®ãƒ—ログラムãŒã‚µãƒ–ルーãƒãƒ³ãƒ©ã‚¤ãƒ–
-ラリãªã‚‰ã°ã€ç‹¬å çš„ãªã‚¢ãƒ—リケーションã¨ã‚ãªãŸã®ãƒ©ã‚¤ãƒ–ラリをリンクã™ã‚‹ã“
-ã¨ã‚’許å¯ã—ãŸã»ã†ãŒã‚ˆã‚Šä¾¿åˆ©ã§ã‚ã‚‹ã¨è€ƒãˆã‚‹ã‹ã‚‚ã—ã‚Œã¾ã›ã‚“。もã—ã“ã‚ŒãŒã‚ãª
-ãŸã®æœ›ã‚€ã“ã¨ãªã‚‰ã°ã€ã“ã®å¥‘約書ã®ä»£ã‚ã‚Šã«GNU ライブラリ一般公衆利用許諾
-契約書をé©ç”¨ã—ã¦ãã ã•ã„。
diff --git a/doc/mapserver-logging b/doc/mapserver-logging
index 983de1f..573c61f 100644
--- a/doc/mapserver-logging
+++ b/doc/mapserver-logging
@@ -5,6 +5,7 @@ LOGLINE ::= int'.'int <MESSAGE>
MESSAGE ::= 'log-start'
| 'log-start v2'
| 'log-start v3'
+ | 'log-start v4'
| <PC> <COORD> <PC-MESSAGE>
| <MOB> <MOB-MESSAGE>
@@ -22,14 +23,14 @@ STATPLACE ::= 'LOGIN' | 'STATUP' | 'STATUP2' | 'STATRESET'
XPPLACE ::= 'LOGIN' | 'LEVELUP'
-XPREASON ::= 'SCRIPTXP' 'HEALXP' 'KILLXP'
+XPREASON ::= 'SCRIPTXP' | 'HEALXP' | 'KILLXP' | 'SHAREXP' | 'UNKNOWNXP'
ZEROTARGET ::= 'null' | <TARGET>
MOB-MESSAGE ::= 'DEAD'
PC-MESSAGE ::= 'WPNDMG' <TARGET> int 'FOR' int WPN int # "WPNDMG MOB01 type FOR damage WPN weapon-item"
- | 'WPNINJURY' <TARGET> int 'FOR' int
+ | 'WPNINJURY' <TARGET> int 'FOR' int
| 'MOB-TO-MOB-DMG' 'FROM' <MOB> int 'TO' <MOB> int 'FOR' int # Summoned monster damage
| 'SPELLHEAL-INSTA' <PC> FOR int
| 'SPELLDMG' <MOB> FOR int BY spell-id
@@ -52,7 +53,7 @@ PC-MESSAGE ::= 'WPNDMG' <TARGET> int 'FOR' int WPN int # "WPNDMG MOB01 type F
| 'TRADEOK'
| 'STATUP'
| 'STATRESET'
- | 'STATUP'
+ | 'STATUP2'
NOTES:
------
@@ -67,4 +68,4 @@ Illegal items
Restricted access
-725, 726, 647, 646 \ No newline at end of file
+725, 726, 647, 646
diff --git a/gpl-3.0.txt b/gpl-3.0.txt
new file mode 100644
index 0000000..94a9ed0
--- /dev/null
+++ b/gpl-3.0.txt
@@ -0,0 +1,674 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The GNU General Public License is a free, copyleft license for
+software and other kinds of works.
+
+ The licenses for most software and other practical works are designed
+to take away your freedom to share and change the works. By contrast,
+the GNU General Public License is intended to guarantee your freedom to
+share and change all versions of a program--to make sure it remains free
+software for all its users. We, the Free Software Foundation, use the
+GNU General Public License for most of our software; it applies also to
+any other work released this way by its authors. You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+them if you wish), that you receive source code or can get it if you
+want it, that you can change the software or use pieces of it in new
+free programs, and that you know you can do these things.
+
+ To protect your rights, we need to prevent others from denying you
+these rights or asking you to surrender the rights. Therefore, you have
+certain responsibilities if you distribute copies of the software, or if
+you modify it: responsibilities to respect the freedom of others.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must pass on to the recipients the same
+freedoms that you received. You must make sure that they, too, receive
+or can get the source code. And you must show them these terms so they
+know their rights.
+
+ Developers that use the GNU GPL protect your rights with two steps:
+(1) assert copyright on the software, and (2) offer you this License
+giving you legal permission to copy, distribute and/or modify it.
+
+ For the developers' and authors' protection, the GPL clearly explains
+that there is no warranty for this free software. For both users' and
+authors' sake, the GPL requires that modified versions be marked as
+changed, so that their problems will not be attributed erroneously to
+authors of previous versions.
+
+ Some devices are designed to deny users access to install or run
+modified versions of the software inside them, although the manufacturer
+can do so. This is fundamentally incompatible with the aim of
+protecting users' freedom to change the software. The systematic
+pattern of such abuse occurs in the area of products for individuals to
+use, which is precisely where it is most unacceptable. Therefore, we
+have designed this version of the GPL to prohibit the practice for those
+products. If such problems arise substantially in other domains, we
+stand ready to extend this provision to those domains in future versions
+of the GPL, as needed to protect the freedom of users.
+
+ Finally, every program is threatened constantly by software patents.
+States should not allow patents to restrict development and use of
+software on general-purpose computers, but in those that do, we wish to
+avoid the special danger that patents applied to a free program could
+make it effectively proprietary. To prevent this, the GPL assures that
+patents cannot be used to render the program non-free.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ TERMS AND CONDITIONS
+
+ 0. Definitions.
+
+ "This License" refers to version 3 of the GNU General Public License.
+
+ "Copyright" also means copyright-like laws that apply to other kinds of
+works, such as semiconductor masks.
+
+ "The Program" refers to any copyrightable work licensed under this
+License. Each licensee is addressed as "you". "Licensees" and
+"recipients" may be individuals or organizations.
+
+ To "modify" a work means to copy from or adapt all or part of the work
+in a fashion requiring copyright permission, other than the making of an
+exact copy. The resulting work is called a "modified version" of the
+earlier work or a work "based on" the earlier work.
+
+ A "covered work" means either the unmodified Program or a work based
+on the Program.
+
+ To "propagate" a work means to do anything with it that, without
+permission, would make you directly or secondarily liable for
+infringement under applicable copyright law, except executing it on a
+computer or modifying a private copy. Propagation includes copying,
+distribution (with or without modification), making available to the
+public, and in some countries other activities as well.
+
+ To "convey" a work means any kind of propagation that enables other
+parties to make or receive copies. Mere interaction with a user through
+a computer network, with no transfer of a copy, is not conveying.
+
+ An interactive user interface displays "Appropriate Legal Notices"
+to the extent that it includes a convenient and prominently visible
+feature that (1) displays an appropriate copyright notice, and (2)
+tells the user that there is no warranty for the work (except to the
+extent that warranties are provided), that licensees may convey the
+work under this License, and how to view a copy of this License. If
+the interface presents a list of user commands or options, such as a
+menu, a prominent item in the list meets this criterion.
+
+ 1. Source Code.
+
+ The "source code" for a work means the preferred form of the work
+for making modifications to it. "Object code" means any non-source
+form of a work.
+
+ A "Standard Interface" means an interface that either is an official
+standard defined by a recognized standards body, or, in the case of
+interfaces specified for a particular programming language, one that
+is widely used among developers working in that language.
+
+ The "System Libraries" of an executable work include anything, other
+than the work as a whole, that (a) is included in the normal form of
+packaging a Major Component, but which is not part of that Major
+Component, and (b) serves only to enable use of the work with that
+Major Component, or to implement a Standard Interface for which an
+implementation is available to the public in source code form. A
+"Major Component", in this context, means a major essential component
+(kernel, window system, and so on) of the specific operating system
+(if any) on which the executable work runs, or a compiler used to
+produce the work, or an object code interpreter used to run it.
+
+ The "Corresponding Source" for a work in object code form means all
+the source code needed to generate, install, and (for an executable
+work) run the object code and to modify the work, including scripts to
+control those activities. However, it does not include the work's
+System Libraries, or general-purpose tools or generally available free
+programs which are used unmodified in performing those activities but
+which are not part of the work. For example, Corresponding Source
+includes interface definition files associated with source files for
+the work, and the source code for shared libraries and dynamically
+linked subprograms that the work is specifically designed to require,
+such as by intimate data communication or control flow between those
+subprograms and other parts of the work.
+
+ The Corresponding Source need not include anything that users
+can regenerate automatically from other parts of the Corresponding
+Source.
+
+ The Corresponding Source for a work in source code form is that
+same work.
+
+ 2. Basic Permissions.
+
+ All rights granted under this License are granted for the term of
+copyright on the Program, and are irrevocable provided the stated
+conditions are met. This License explicitly affirms your unlimited
+permission to run the unmodified Program. The output from running a
+covered work is covered by this License only if the output, given its
+content, constitutes a covered work. This License acknowledges your
+rights of fair use or other equivalent, as provided by copyright law.
+
+ You may make, run and propagate covered works that you do not
+convey, without conditions so long as your license otherwise remains
+in force. You may convey covered works to others for the sole purpose
+of having them make modifications exclusively for you, or provide you
+with facilities for running those works, provided that you comply with
+the terms of this License in conveying all material for which you do
+not control copyright. Those thus making or running the covered works
+for you must do so exclusively on your behalf, under your direction
+and control, on terms that prohibit them from making any copies of
+your copyrighted material outside their relationship with you.
+
+ Conveying under any other circumstances is permitted solely under
+the conditions stated below. Sublicensing is not allowed; section 10
+makes it unnecessary.
+
+ 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
+
+ No covered work shall be deemed part of an effective technological
+measure under any applicable law fulfilling obligations under article
+11 of the WIPO copyright treaty adopted on 20 December 1996, or
+similar laws prohibiting or restricting circumvention of such
+measures.
+
+ When you convey a covered work, you waive any legal power to forbid
+circumvention of technological measures to the extent such circumvention
+is effected by exercising rights under this License with respect to
+the covered work, and you disclaim any intention to limit operation or
+modification of the work as a means of enforcing, against the work's
+users, your or third parties' legal rights to forbid circumvention of
+technological measures.
+
+ 4. Conveying Verbatim Copies.
+
+ You may convey verbatim copies of the Program's source code as you
+receive it, in any medium, provided that you conspicuously and
+appropriately publish on each copy an appropriate copyright notice;
+keep intact all notices stating that this License and any
+non-permissive terms added in accord with section 7 apply to the code;
+keep intact all notices of the absence of any warranty; and give all
+recipients a copy of this License along with the Program.
+
+ You may charge any price or no price for each copy that you convey,
+and you may offer support or warranty protection for a fee.
+
+ 5. Conveying Modified Source Versions.
+
+ You may convey a work based on the Program, or the modifications to
+produce it from the Program, in the form of source code under the
+terms of section 4, provided that you also meet all of these conditions:
+
+ a) The work must carry prominent notices stating that you modified
+ it, and giving a relevant date.
+
+ b) The work must carry prominent notices stating that it is
+ released under this License and any conditions added under section
+ 7. This requirement modifies the requirement in section 4 to
+ "keep intact all notices".
+
+ c) You must license the entire work, as a whole, under this
+ License to anyone who comes into possession of a copy. This
+ License will therefore apply, along with any applicable section 7
+ additional terms, to the whole of the work, and all its parts,
+ regardless of how they are packaged. This License gives no
+ permission to license the work in any other way, but it does not
+ invalidate such permission if you have separately received it.
+
+ d) If the work has interactive user interfaces, each must display
+ Appropriate Legal Notices; however, if the Program has interactive
+ interfaces that do not display Appropriate Legal Notices, your
+ work need not make them do so.
+
+ A compilation of a covered work with other separate and independent
+works, which are not by their nature extensions of the covered work,
+and which are not combined with it such as to form a larger program,
+in or on a volume of a storage or distribution medium, is called an
+"aggregate" if the compilation and its resulting copyright are not
+used to limit the access or legal rights of the compilation's users
+beyond what the individual works permit. Inclusion of a covered work
+in an aggregate does not cause this License to apply to the other
+parts of the aggregate.
+
+ 6. Conveying Non-Source Forms.
+
+ You may convey a covered work in object code form under the terms
+of sections 4 and 5, provided that you also convey the
+machine-readable Corresponding Source under the terms of this License,
+in one of these ways:
+
+ a) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by the
+ Corresponding Source fixed on a durable physical medium
+ customarily used for software interchange.
+
+ b) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by a
+ written offer, valid for at least three years and valid for as
+ long as you offer spare parts or customer support for that product
+ model, to give anyone who possesses the object code either (1) a
+ copy of the Corresponding Source for all the software in the
+ product that is covered by this License, on a durable physical
+ medium customarily used for software interchange, for a price no
+ more than your reasonable cost of physically performing this
+ conveying of source, or (2) access to copy the
+ Corresponding Source from a network server at no charge.
+
+ c) Convey individual copies of the object code with a copy of the
+ written offer to provide the Corresponding Source. This
+ alternative is allowed only occasionally and noncommercially, and
+ only if you received the object code with such an offer, in accord
+ with subsection 6b.
+
+ d) Convey the object code by offering access from a designated
+ place (gratis or for a charge), and offer equivalent access to the
+ Corresponding Source in the same way through the same place at no
+ further charge. You need not require recipients to copy the
+ Corresponding Source along with the object code. If the place to
+ copy the object code is a network server, the Corresponding Source
+ may be on a different server (operated by you or a third party)
+ that supports equivalent copying facilities, provided you maintain
+ clear directions next to the object code saying where to find the
+ Corresponding Source. Regardless of what server hosts the
+ Corresponding Source, you remain obligated to ensure that it is
+ available for as long as needed to satisfy these requirements.
+
+ e) Convey the object code using peer-to-peer transmission, provided
+ you inform other peers where the object code and Corresponding
+ Source of the work are being offered to the general public at no
+ charge under subsection 6d.
+
+ A separable portion of the object code, whose source code is excluded
+from the Corresponding Source as a System Library, need not be
+included in conveying the object code work.
+
+ A "User Product" is either (1) a "consumer product", which means any
+tangible personal property which is normally used for personal, family,
+or household purposes, or (2) anything designed or sold for incorporation
+into a dwelling. In determining whether a product is a consumer product,
+doubtful cases shall be resolved in favor of coverage. For a particular
+product received by a particular user, "normally used" refers to a
+typical or common use of that class of product, regardless of the status
+of the particular user or of the way in which the particular user
+actually uses, or expects or is expected to use, the product. A product
+is a consumer product regardless of whether the product has substantial
+commercial, industrial or non-consumer uses, unless such uses represent
+the only significant mode of use of the product.
+
+ "Installation Information" for a User Product means any methods,
+procedures, authorization keys, or other information required to install
+and execute modified versions of a covered work in that User Product from
+a modified version of its Corresponding Source. The information must
+suffice to ensure that the continued functioning of the modified object
+code is in no case prevented or interfered with solely because
+modification has been made.
+
+ If you convey an object code work under this section in, or with, or
+specifically for use in, a User Product, and the conveying occurs as
+part of a transaction in which the right of possession and use of the
+User Product is transferred to the recipient in perpetuity or for a
+fixed term (regardless of how the transaction is characterized), the
+Corresponding Source conveyed under this section must be accompanied
+by the Installation Information. But this requirement does not apply
+if neither you nor any third party retains the ability to install
+modified object code on the User Product (for example, the work has
+been installed in ROM).
+
+ The requirement to provide Installation Information does not include a
+requirement to continue to provide support service, warranty, or updates
+for a work that has been modified or installed by the recipient, or for
+the User Product in which it has been modified or installed. Access to a
+network may be denied when the modification itself materially and
+adversely affects the operation of the network or violates the rules and
+protocols for communication across the network.
+
+ Corresponding Source conveyed, and Installation Information provided,
+in accord with this section must be in a format that is publicly
+documented (and with an implementation available to the public in
+source code form), and must require no special password or key for
+unpacking, reading or copying.
+
+ 7. Additional Terms.
+
+ "Additional permissions" are terms that supplement the terms of this
+License by making exceptions from one or more of its conditions.
+Additional permissions that are applicable to the entire Program shall
+be treated as though they were included in this License, to the extent
+that they are valid under applicable law. If additional permissions
+apply only to part of the Program, that part may be used separately
+under those permissions, but the entire Program remains governed by
+this License without regard to the additional permissions.
+
+ When you convey a copy of a covered work, you may at your option
+remove any additional permissions from that copy, or from any part of
+it. (Additional permissions may be written to require their own
+removal in certain cases when you modify the work.) You may place
+additional permissions on material, added by you to a covered work,
+for which you have or can give appropriate copyright permission.
+
+ Notwithstanding any other provision of this License, for material you
+add to a covered work, you may (if authorized by the copyright holders of
+that material) supplement the terms of this License with terms:
+
+ a) Disclaiming warranty or limiting liability differently from the
+ terms of sections 15 and 16 of this License; or
+
+ b) Requiring preservation of specified reasonable legal notices or
+ author attributions in that material or in the Appropriate Legal
+ Notices displayed by works containing it; or
+
+ c) Prohibiting misrepresentation of the origin of that material, or
+ requiring that modified versions of such material be marked in
+ reasonable ways as different from the original version; or
+
+ d) Limiting the use for publicity purposes of names of licensors or
+ authors of the material; or
+
+ e) Declining to grant rights under trademark law for use of some
+ trade names, trademarks, or service marks; or
+
+ f) Requiring indemnification of licensors and authors of that
+ material by anyone who conveys the material (or modified versions of
+ it) with contractual assumptions of liability to the recipient, for
+ any liability that these contractual assumptions directly impose on
+ those licensors and authors.
+
+ All other non-permissive additional terms are considered "further
+restrictions" within the meaning of section 10. If the Program as you
+received it, or any part of it, contains a notice stating that it is
+governed by this License along with a term that is a further
+restriction, you may remove that term. If a license document contains
+a further restriction but permits relicensing or conveying under this
+License, you may add to a covered work material governed by the terms
+of that license document, provided that the further restriction does
+not survive such relicensing or conveying.
+
+ If you add terms to a covered work in accord with this section, you
+must place, in the relevant source files, a statement of the
+additional terms that apply to those files, or a notice indicating
+where to find the applicable terms.
+
+ Additional terms, permissive or non-permissive, may be stated in the
+form of a separately written license, or stated as exceptions;
+the above requirements apply either way.
+
+ 8. Termination.
+
+ You may not propagate or modify a covered work except as expressly
+provided under this License. Any attempt otherwise to propagate or
+modify it is void, and will automatically terminate your rights under
+this License (including any patent licenses granted under the third
+paragraph of section 11).
+
+ However, if you cease all violation of this License, then your
+license from a particular copyright holder is reinstated (a)
+provisionally, unless and until the copyright holder explicitly and
+finally terminates your license, and (b) permanently, if the copyright
+holder fails to notify you of the violation by some reasonable means
+prior to 60 days after the cessation.
+
+ Moreover, your license from a particular copyright holder is
+reinstated permanently if the copyright holder notifies you of the
+violation by some reasonable means, this is the first time you have
+received notice of violation of this License (for any work) from that
+copyright holder, and you cure the violation prior to 30 days after
+your receipt of the notice.
+
+ Termination of your rights under this section does not terminate the
+licenses of parties who have received copies or rights from you under
+this License. If your rights have been terminated and not permanently
+reinstated, you do not qualify to receive new licenses for the same
+material under section 10.
+
+ 9. Acceptance Not Required for Having Copies.
+
+ You are not required to accept this License in order to receive or
+run a copy of the Program. Ancillary propagation of a covered work
+occurring solely as a consequence of using peer-to-peer transmission
+to receive a copy likewise does not require acceptance. However,
+nothing other than this License grants you permission to propagate or
+modify any covered work. These actions infringe copyright if you do
+not accept this License. Therefore, by modifying or propagating a
+covered work, you indicate your acceptance of this License to do so.
+
+ 10. Automatic Licensing of Downstream Recipients.
+
+ Each time you convey a covered work, the recipient automatically
+receives a license from the original licensors, to run, modify and
+propagate that work, subject to this License. You are not responsible
+for enforcing compliance by third parties with this License.
+
+ An "entity transaction" is a transaction transferring control of an
+organization, or substantially all assets of one, or subdividing an
+organization, or merging organizations. If propagation of a covered
+work results from an entity transaction, each party to that
+transaction who receives a copy of the work also receives whatever
+licenses to the work the party's predecessor in interest had or could
+give under the previous paragraph, plus a right to possession of the
+Corresponding Source of the work from the predecessor in interest, if
+the predecessor has it or can get it with reasonable efforts.
+
+ You may not impose any further restrictions on the exercise of the
+rights granted or affirmed under this License. For example, you may
+not impose a license fee, royalty, or other charge for exercise of
+rights granted under this License, and you may not initiate litigation
+(including a cross-claim or counterclaim in a lawsuit) alleging that
+any patent claim is infringed by making, using, selling, offering for
+sale, or importing the Program or any portion of it.
+
+ 11. Patents.
+
+ A "contributor" is a copyright holder who authorizes use under this
+License of the Program or a work on which the Program is based. The
+work thus licensed is called the contributor's "contributor version".
+
+ A contributor's "essential patent claims" are all patent claims
+owned or controlled by the contributor, whether already acquired or
+hereafter acquired, that would be infringed by some manner, permitted
+by this License, of making, using, or selling its contributor version,
+but do not include claims that would be infringed only as a
+consequence of further modification of the contributor version. For
+purposes of this definition, "control" includes the right to grant
+patent sublicenses in a manner consistent with the requirements of
+this License.
+
+ Each contributor grants you a non-exclusive, worldwide, royalty-free
+patent license under the contributor's essential patent claims, to
+make, use, sell, offer for sale, import and otherwise run, modify and
+propagate the contents of its contributor version.
+
+ In the following three paragraphs, a "patent license" is any express
+agreement or commitment, however denominated, not to enforce a patent
+(such as an express permission to practice a patent or covenant not to
+sue for patent infringement). To "grant" such a patent license to a
+party means to make such an agreement or commitment not to enforce a
+patent against the party.
+
+ If you convey a covered work, knowingly relying on a patent license,
+and the Corresponding Source of the work is not available for anyone
+to copy, free of charge and under the terms of this License, through a
+publicly available network server or other readily accessible means,
+then you must either (1) cause the Corresponding Source to be so
+available, or (2) arrange to deprive yourself of the benefit of the
+patent license for this particular work, or (3) arrange, in a manner
+consistent with the requirements of this License, to extend the patent
+license to downstream recipients. "Knowingly relying" means you have
+actual knowledge that, but for the patent license, your conveying the
+covered work in a country, or your recipient's use of the covered work
+in a country, would infringe one or more identifiable patents in that
+country that you have reason to believe are valid.
+
+ If, pursuant to or in connection with a single transaction or
+arrangement, you convey, or propagate by procuring conveyance of, a
+covered work, and grant a patent license to some of the parties
+receiving the covered work authorizing them to use, propagate, modify
+or convey a specific copy of the covered work, then the patent license
+you grant is automatically extended to all recipients of the covered
+work and works based on it.
+
+ A patent license is "discriminatory" if it does not include within
+the scope of its coverage, prohibits the exercise of, or is
+conditioned on the non-exercise of one or more of the rights that are
+specifically granted under this License. You may not convey a covered
+work if you are a party to an arrangement with a third party that is
+in the business of distributing software, under which you make payment
+to the third party based on the extent of your activity of conveying
+the work, and under which the third party grants, to any of the
+parties who would receive the covered work from you, a discriminatory
+patent license (a) in connection with copies of the covered work
+conveyed by you (or copies made from those copies), or (b) primarily
+for and in connection with specific products or compilations that
+contain the covered work, unless you entered into that arrangement,
+or that patent license was granted, prior to 28 March 2007.
+
+ Nothing in this License shall be construed as excluding or limiting
+any implied license or other defenses to infringement that may
+otherwise be available to you under applicable patent law.
+
+ 12. No Surrender of Others' Freedom.
+
+ If conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot convey a
+covered work so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you may
+not convey it at all. For example, if you agree to terms that obligate you
+to collect a royalty for further conveying from those to whom you convey
+the Program, the only way you could satisfy both those terms and this
+License would be to refrain entirely from conveying the Program.
+
+ 13. Use with the GNU Affero General Public License.
+
+ Notwithstanding any other provision of this License, you have
+permission to link or combine any covered work with a work licensed
+under version 3 of the GNU Affero General Public License into a single
+combined work, and to convey the resulting work. The terms of this
+License will continue to apply to the part which is the covered work,
+but the special requirements of the GNU Affero General Public License,
+section 13, concerning interaction through a network will apply to the
+combination as such.
+
+ 14. Revised Versions of this License.
+
+ The Free Software Foundation may publish revised and/or new versions of
+the GNU General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+ Each version is given a distinguishing version number. If the
+Program specifies that a certain numbered version of the GNU General
+Public License "or any later version" applies to it, you have the
+option of following the terms and conditions either of that numbered
+version or of any later version published by the Free Software
+Foundation. If the Program does not specify a version number of the
+GNU General Public License, you may choose any version ever published
+by the Free Software Foundation.
+
+ If the Program specifies that a proxy can decide which future
+versions of the GNU General Public License can be used, that proxy's
+public statement of acceptance of a version permanently authorizes you
+to choose that version for the Program.
+
+ Later license versions may give you additional or different
+permissions. However, no additional obligations are imposed on any
+author or copyright holder as a result of your choosing to follow a
+later version.
+
+ 15. Disclaimer of Warranty.
+
+ THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
+APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
+OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
+IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+ 16. Limitation of Liability.
+
+ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
+THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
+USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGES.
+
+ 17. Interpretation of Sections 15 and 16.
+
+ If the disclaimer of warranty and limitation of liability provided
+above cannot be given local legal effect according to their terms,
+reviewing courts shall apply local law that most closely approximates
+an absolute waiver of all civil liability in connection with the
+Program, unless a warranty or assumption of liability accompanies a
+copy of the Program in return for a fee.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+state the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the program's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+Also add information on how to contact you by electronic and paper mail.
+
+ If the program does terminal interaction, make it output a short
+notice like this when it starts in an interactive mode:
+
+ <program> Copyright (C) <year> <name of author>
+ This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, your program's commands
+might be different; for a GUI interface, you would use an "about box".
+
+ You should also get your employer (if you work as a programmer) or school,
+if any, to sign a "copyright disclaimer" for the program, if necessary.
+For more information on this, and how to apply and follow the GNU GPL, see
+<http://www.gnu.org/licenses/>.
+
+ The GNU General Public License does not permit incorporating your program
+into proprietary programs. If your program is a subroutine library, you
+may consider it more useful to permit linking proprietary applications with
+the library. If this is what you want to do, use the GNU Lesser General
+Public License instead of this License. But first, please read
+<http://www.gnu.org/philosophy/why-not-lgpl.html>.
diff --git a/make.defs b/make.defs
index 17b06a8..7e788c5 100644
--- a/make.defs
+++ b/make.defs
@@ -1,11 +1,15 @@
+# vim: filetype=make
+#
# defaults
CXX = g++
+
LEX = flex
BISON = bison
-CXXFLAGS = -pipe -g -O2 #@warnings
+CXXFLAGS = -pipe -g -O2 ${WARNINGS}
+WARNINGS = -include src/warnings.hpp
# works on both x86 and x86_64
-override CXX += -m32 -std=c++0x
+override CXX += -std=c++0x
# for linking
override CC = ${CXX}
diff --git a/src/char/char.cpp b/src/char/char.cpp
index c8b3e76..c3c22de 100644
--- a/src/char/char.cpp
+++ b/src/char/char.cpp
@@ -1,151 +1,177 @@
-// $Id: char.c,v 1.3 2004/09/13 16:52:16 Yor Exp $
-// original : char2.c 2003/03/14 11:58:35 Rev.1.5
+#include "char.hpp"
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <netinet/in.h>
-#include <sys/time.h>
-#include <time.h>
-#include <sys/ioctl.h>
-#include <unistd.h>
-#include <signal.h>
-#include <fcntl.h>
-#include <string.h>
#include <arpa/inet.h>
-#include <netdb.h>
-#include <stdarg.h>
+#include <sys/socket.h>
#include <sys/wait.h>
+#include <netdb.h>
+#include <unistd.h>
+
+#include <cstdlib>
+#include <cstring>
+#include <ctime>
+
+#include <fstream>
+
#include "../common/core.hpp"
+#include "../common/cxxstdio.hpp"
+#include "../common/db.hpp"
+#include "../common/extract.hpp"
+#include "../common/lock.hpp"
#include "../common/socket.hpp"
#include "../common/timer.hpp"
-#include "../common/mmo.hpp"
#include "../common/version.hpp"
-#include "../common/lock.hpp"
-#include "char.hpp"
#include "inter.hpp"
-#include "int_guild.hpp"
#include "int_party.hpp"
#include "int_storage.hpp"
-#ifdef MEMWATCH
-#include "memwatch.hpp"
-#endif
+#include "../poison.hpp"
+static
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;
+static
+int server_fd[MAX_MAP_SERVERS];
+static
+int server_freezeflag[MAX_MAP_SERVERS]; // Map-server anti-freeze system. Counter. 5 ok, 4...0 freezed
+static
+int anti_freeze_enable = 0;
+static
+std::chrono::seconds ANTI_FREEZE_INTERVAL = std::chrono::seconds(6);
+
+constexpr
+std::chrono::milliseconds DEFAULT_AUTOSAVE_INTERVAL =
+ std::chrono::minutes(5);
-int login_fd, char_fd;
+// TODO replace all string forms of IP addresses with class instances
+static
+int login_fd, char_fd;
+static
char userid[24];
+static
char passwd[24];
+static
char server_name[20];
+static
char wisp_server_name[24] = "Server";
+static
char login_ip_str[16];
-int login_ip;
-int login_port = 6900;
+static
+int login_ip;
+static
+int login_port = 6900;
+static
char char_ip_str[16];
-int char_ip;
-int char_port = 6121;
-int char_maintenance;
-int char_new;
-int email_creation = 0; // disabled by default
+static
+int char_ip;
+static
+int char_port = 6121;
+static
+int char_maintenance;
+static
+int char_new;
+static
+int email_creation = 0; // disabled by default
+static
char char_txt[1024];
-char backup_txt[1024]; //By zanetheinsane
-char 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. => option By [Yor]
+static
char unknown_char_name[1024] = "Unknown";
+static
char char_log_filename[1024] = "log/char.log";
//Added for lan support
+static
char lan_map_ip[128];
-int subneti[4];
-int subnetmaski[4];
-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]
+static
+int subneti[4];
+static
+int subnetmaski[4];
+static
+int name_ignoring_case = 0; // Allow or not identical name for characters but with a different case by [Yor]
+static
+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]
+static
char char_name_letters[1024] = ""; // list of letters/symbols authorised (or not) in a character name. by [Yor]
struct char_session_data
{
- int account_id, login_id1, login_id2, sex;
+ int account_id, login_id1, login_id2, sex;
unsigned short packet_tmw_version;
- int found_char[9];
+ 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)
+ TimeT connect_until_time; // # of seconds 1/1/1970 (timestamp): Validity limit of the account (0 = unlimited)
};
#define AUTH_FIFO_SIZE 256
+static
struct
{
- int account_id, char_id, login_id1, login_id2, ip, char_pos, delflag,
+ int account_id, char_id, login_id1, login_id2, ip, char_pos, delflag,
sex;
unsigned short packet_tmw_version;
- time_t connect_until_time; // # of seconds 1/1/1970 (timestamp): Validity limit of the account (0 = unlimited)
+ TimeT 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;
+static
+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)
+static
+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;
+static
+int char_id_count = 150000;
+static
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 = 1202;
+static
+int char_num, char_max;
+static
+int max_connect_user = 0;
+static
+std::chrono::milliseconds autosave_interval = DEFAULT_AUTOSAVE_INTERVAL;
+static
+int start_zeny = 500;
+static
+int start_weapon = 1201;
+static
+int start_armor = 1202;
// Initial position (it's possible to set it in conf file)
+static
struct point start_point = { "new_1-1.gat", 53, 111 };
+static
struct gm_account *gm_account = NULL;
-int GM_num = 0;
+static
+int GM_num = 0;
// online players by [Yor]
+static
char online_txt_filename[1024] = "online.txt";
+static
char online_html_filename[1024] = "online.html";
-int online_sorting_option = 0; // sorting option to display online players in online files
-int online_display_option = 1; // display options: to know which columns must be displayed
-int online_refresh_html = 20; // refresh time (in sec) of the html file in the explorer
-int online_gm_display_min_level = 20; // minimum GM level to display 'GM' when we want to display it
+static
+int online_sorting_option = 0; // sorting option to display online players in online files
+static
+int online_refresh_html = 20; // refresh time (in sec) of the html file in the explorer
+static
+int online_gm_display_min_level = 20; // minimum GM level to display 'GM' when we want to display it
+static
int *online_chars; // same size of char_dat, and id value of current server (or -1)
-time_t update_online; // to update online files when we receiving information from a server (not less than 8 seconds)
+static
+TimeT update_online; // to update online files when we receiving information from a server (not less than 8 seconds)
+static
pid_t pid = 0; // For forked DB writes
//------------------------------
// Writing function of logs file
//------------------------------
-int char_log (const char *fmt, ...)
+void char_log(const_string line)
{
- FILE *logfp;
- va_list ap;
- struct timeval tv;
- char tmpstr[2048];
-
- va_start (ap, fmt);
-
- logfp = fopen_ (char_log_filename, "a");
- if (logfp)
- {
- if (fmt[0] == '\0') // jump a line if no message
- fprintf (logfp, "\n");
- else
- {
- gettimeofday (&tv, NULL);
- strftime (tmpstr, 24, "%d-%m-%Y %H:%M:%S", gmtime (&(tv.tv_sec)));
- sprintf (tmpstr + 19, ".%03d: %s", (int) tv.tv_usec / 1000, fmt);
- vfprintf (logfp, tmpstr, ap);
- }
- fclose_ (logfp);
- }
-
- va_end (ap);
- return 0;
+ FILE *logfp = fopen_(char_log_filename, "a");
+ if (!logfp)
+ return;
+ log_with_timestamp(logfp, line);
+ fclose_(logfp);
}
//----------------------------------------------------------------------
@@ -153,9 +179,9 @@ int char_log (const char *fmt, ...)
// and returns its level (or 0 if it isn't a GM account or if not found)
//----------------------------------------------------------------------
static
-int isGM (int account_id)
+int isGM(int account_id)
{
- int i;
+ int i;
for (i = 0; i < GM_num; i++)
if (gm_account[i].account_id == account_id)
@@ -171,19 +197,19 @@ int isGM (int account_id)
// and returns index if only 1 character is found
// and similar to the searched name.
//----------------------------------------------
-int search_character_index (const char *character_name)
+int search_character_index(const char *character_name)
{
- int i, quantity, index;
+ int i, quantity, index;
quantity = 0;
index = -1;
for (i = 0; i < char_num; i++)
{
// Without case sensitive check (increase the number of similar character names found)
- if (strcasecmp (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)
+ if (strcmp(char_dat[i].name, character_name) == 0)
return i;
quantity++;
index = i;
@@ -201,7 +227,7 @@ int search_character_index (const char *character_name)
//-------------------------------------
// Return character name with the index
//-------------------------------------
-char *search_character_name (int index)
+char *search_character_name(int index)
{
if (index >= 0 && index < char_num)
@@ -214,485 +240,291 @@ char *search_character_name (int index)
// Function to create the character line (for save)
//-------------------------------------------------
__inline__ static
-int mmo_char_tostr (char *str, struct mmo_charstatus *p)
+std::string mmo_char_tostr(struct mmo_charstatus *p)
{
- int i;
- char *str_p = str;
-
// on multi-map server, sometimes it's posssible that last_point become void. (reason???) We check that to not lost character at restart.
if (p->last_point.map[0] == '\0')
{
- memcpy (p->last_point.map, "001-1.gat", 10);
+ memcpy(p->last_point.map, "001-1.gat", 10);
p->last_point.x = 273;
p->last_point.y = 354;
}
- str_p += sprintf (str_p, "%d\t%d,%d\t%s\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%s,%d,%d\t%s,%d,%d,%d\t", p->char_id, p->account_id, p->char_num, p->name, //
- p->pc_class, p->base_level, p->job_level, p->base_exp, p->job_exp, p->zeny, p->hp, p->max_hp, p->sp, p->max_sp, p->str, p->agi, p->vit, p->int_, p->dex, p->luk, p->status_point, p->skill_point, p->option, p->karma, p->manner, //
- p->party_id, p->guild_id, 0, 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);
- for (i = 0; i < 10; i++)
+ std::string str_p;
+ str_p += STRPRINTF(
+ "%d\t"
+ "%d,%d\t"
+ "%s\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"
+ "%s,%d,%d\t"
+ "%s,%d,%d,%d\t",
+ p->char_id,
+ p->account_id, p->char_num,
+ p->name,
+ p->species, p->base_level, p->job_level,
+ p->base_exp, p->job_exp, p->zeny,
+ p->hp, p->max_hp, p->sp, p->max_sp,
+ p->attrs[ATTR::STR], p->attrs[ATTR::AGI], p->attrs[ATTR::VIT], p->attrs[ATTR::INT], p->attrs[ATTR::DEX], p->attrs[ATTR::LUK],
+ p->status_point, p->skill_point,
+ p->option, p->karma, p->manner,
+ p->party_id, 0/*guild_id*/, 0/*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);
+ for (int i = 0; i < 10; i++)
if (p->memo_point[i].map[0])
{
- str_p +=
- sprintf (str_p, "%s,%d,%d", p->memo_point[i].map,
- p->memo_point[i].x, p->memo_point[i].y);
+ str_p += STRPRINTF("%s,%d,%d ",
+ p->memo_point[i].map, p->memo_point[i].x, p->memo_point[i].y);
}
- *(str_p++) = '\t';
+ str_p += '\t';
- for (i = 0; i < MAX_INVENTORY; i++)
+ for (int i = 0; i < MAX_INVENTORY; i++)
if (p->inventory[i].nameid)
{
- str_p += sprintf (str_p, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d ",
- p->inventory[i].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);
- }
- *(str_p++) = '\t';
-
- for (i = 0; i < MAX_CART; i++)
+ str_p += STRPRINTF("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d ",
+ p->inventory[i].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);
+ }
+ str_p += '\t';
+
+ for (int i = 0; i < MAX_CART; i++)
if (p->cart[i].nameid)
{
- str_p += sprintf (str_p, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d ",
- p->cart[i].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);
+ str_p += STRPRINTF("%d,%d,%d,%hhu,%d,%hd,%hhu,%d,%d,%d,%d,%d ",
+ p->cart[i].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);
}
- *(str_p++) = '\t';
+ str_p += '\t';
- for (i = 0; i < MAX_SKILL; i++)
- if (p->skill[i].id)
+ for (SkillID i : erange(SkillID(), MAX_SKILL))
+ if (p->skill[i].lv)
{
- str_p +=
- sprintf (str_p, "%d,%d ", p->skill[i].id,
- p->skill[i].lv | (p->skill[i].flags << 16));
+ str_p += STRPRINTF("%d,%d ",
+ i,
+ p->skill[i].lv | (uint16_t(p->skill[i].flags) << 16));
}
- *(str_p++) = '\t';
+ str_p += '\t';
- for (i = 0; i < p->global_reg_num; i++)
+ for (int i = 0; i < p->global_reg_num; i++)
if (p->global_reg[i].str[0])
- str_p +=
- sprintf (str_p, "%s,%d ", p->global_reg[i].str,
- p->global_reg[i].value);
- *(str_p++) = '\t';
+ str_p += STRPRINTF("%s,%d ",
+ p->global_reg[i].str,
+ p->global_reg[i].value);
+ str_p += '\t';
- *str_p = '\0';
- return 0;
+ return str_p;
+}
+
+static
+bool extract(const_string str, struct point *p)
+{
+ return extract(str, record<','>(&p->map, &p->x, &p->y));
+}
+
+struct skill_loader
+{
+ SkillID id;
+ uint16_t level;
+ SkillFlags flags;
+};
+
+static
+bool extract(const_string str, struct skill_loader *s)
+{
+ uint32_t flags_and_level;
+ if (!extract(str,
+ record<','>(&s->id, &flags_and_level)))
+ return false;
+ s->level = flags_and_level & 0xffff;
+ s->flags = SkillFlags(flags_and_level >> 16);
+ return true;
}
//-------------------------------------------------------------------------
// Function to set the character from the line (at read of characters file)
//-------------------------------------------------------------------------
static
-int mmo_char_fromstr (char *str, struct mmo_charstatus *p)
+bool extract(const_string 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->pc_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++)
+ memset(p, '\0', sizeof(struct mmo_charstatus));
+
+ uint32_t unused_guild_id, unused_pet_id;
+ std::vector<struct point> memos;
+ std::vector<struct item> inventory, cart;
+ std::vector<struct skill_loader> skills;
+ std::vector<struct global_reg> vars;
+ if (!extract(str,
+ record<'\t'>(
+ &p->char_id,
+ record<','>(&p->account_id, &p->char_num),
+ &p->name,
+ record<','>(&p->species, &p->base_level, &p->job_level),
+ record<','>(&p->base_exp, &p->job_exp, &p->zeny),
+ record<','>(&p->hp, &p->max_hp, &p->sp, &p->max_sp),
+ record<','>(&p->attrs[ATTR::STR], &p->attrs[ATTR::AGI], &p->attrs[ATTR::VIT], &p->attrs[ATTR::INT], &p->attrs[ATTR::DEX], &p->attrs[ATTR::LUK]),
+ record<','>(&p->status_point, &p->skill_point),
+ record<','>(&p->option, &p->karma, &p->manner),
+ record<','>(&p->party_id, &unused_guild_id, &unused_pet_id),
+ record<','>(&p->hair, &p->hair_color, &p->clothes_color),
+ record<','>(&p->weapon, &p->shield, &p->head_top, &p->head_mid, &p->head_bottom),
+ &p->last_point,
+ // somebody was silly and stuck partner id as a field
+ // of this, instead of adding a new \t
+ // or putting it elsewhere, like by pet/guild
+ record<','>(&p->save_point.map, &p->save_point.x, &p->save_point.y, &p->partner_id),
+ vrec<' '>(&memos),
+ vrec<' '>(&inventory),
+ vrec<' '>(&cart),
+ vrec<' '>(&skills),
+ vrec<' '>(&vars))))
+ return false;
+
+ if (strcmp(wisp_server_name, p->name) == 0)
+ return false;
+
+ for (int 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 (strcasecmp (wisp_server_name, p->name) == 0)
- {
- printf
- ("mmo_auth_init: ******WARNING: character name has wisp server name.\n");
- printf
- (" Character name '%s' = wisp server name '%s'.\n",
- p->name, wisp_server_name);
- printf
- (" Character readed. Suggestion: change the wisp server name.\n");
- char_log
- ("mmo_auth_init: ******WARNING: character name has wisp server name: Character name '%s' = wisp server name '%s'.\n",
- p->name, wisp_server_name);
- }
-
- 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%n", p->memo_point[i].map, &tmp_int[0],
- &tmp_int[1], &len) != 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++;
+ return false;
+ if (strcmp(char_dat[i].name, p->name) == 0)
+ return false;
}
- next++;
+ if (memos.size() > 10)
+ return false;
+ std::copy(memos.begin(), memos.end(), p->memo_point);
+ // number of memo points is not saved - it just detects map name '\0'
- 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++;
- }
+ if (inventory.size() > MAX_INVENTORY)
+ return false;
+ std::copy(inventory.begin(), inventory.end(), p->inventory);
+ // number of inventory items is not saved - it just detects nameid 0
- next++;
+ if (cart.size() > MAX_CART)
+ return false;
+ std::copy(cart.begin(), cart.end(), p->cart);
+ // number of cart items is not saved - it just detects nameid 0
- for (i = 0; str[next] && str[next] != '\t'; i++)
+ for (struct skill_loader& sk : skills)
{
- if (sscanf (str + next, "%d,%d%n", &tmp_int[0], &tmp_int[1], &len) !=
- 2)
- return -6;
- p->skill[tmp_int[0]].id = tmp_int[0];
- p->skill[tmp_int[0]].lv = tmp_int[1] & 0xffff;
- p->skill[tmp_int[0]].flags = ((tmp_int[1] >> 16) & 0xffff);
- next += len;
- if (str[next] == ' ')
- next++;
+ if (sk.id > MAX_SKILL)
+ return false;
+ p->skill[sk.id].lv = sk.level;
+ p->skill[sk.id].flags = sk.flags;
}
- next++;
-
- for (i = 0;
- str[next] && str[next] != '\t' && str[next] != '\n'
- && str[next] != '\r'; i++)
- { // global_reg実装以å‰ã®athena.txt互æ›ã®ãŸã‚一応'\n'ãƒã‚§ãƒƒã‚¯
- if (sscanf
- (str + next, "%[^,],%d%n", p->global_reg[i].str,
- &p->global_reg[i].value, &len) != 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;
+ if (vars.size() > GLOBAL_REG_NUM)
+ return false;
+ std::copy(vars.begin(), vars.end(), p->global_reg);
+ p->global_reg_num = vars.size();
- return 1;
+ return true;
}
//---------------------------------
// Function to read characters file
//---------------------------------
static
-int mmo_char_init (void)
+int mmo_char_init(void)
{
- char line[65536];
- int ret, line_count;
- FILE *fp;
-
char_max = 256;
- CREATE (char_dat, struct mmo_charstatus, 256);
- CREATE (online_chars, int, 256);
+ CREATE(char_dat, struct mmo_charstatus, 256);
+ CREATE(online_chars, int, 256);
for (int i = 0; i < char_max; i++)
online_chars[i] = -1;
char_num = 0;
- fp = fopen_ (char_txt, "r");
- if (fp == NULL)
+ std::ifstream in(char_txt);
+ if (!in.is_open())
{
- printf ("Characters file not found: %s.\n", char_txt);
- char_log ("Characters file not found: %s.\n", char_txt);
- char_log ("Id for the next created character: %d.\n",
+ PRINTF("Characters file not found: %s.\n", char_txt);
+ CHAR_LOG("Characters file not found: %s.\n", char_txt);
+ CHAR_LOG("Id for the next created character: %d.\n",
char_id_count);
return 0;
}
- line_count = 0;
- while (fgets (line, sizeof (line) - 1, fp))
+ int line_count = 0;
+ std::string line;
+ while (std::getline(in, line))
{
- int i, j;
line_count++;
if (line[0] == '/' && line[1] == '/')
continue;
- line[sizeof (line) - 1] = '\0';
+ if (line.back() == '\r')
+ {
+ line.back() = 0;
+ }
- j = 0;
- if (sscanf (line, "%d\t%%newid%%%n", &i, &j) == 1 && j > 0)
{
- if (char_id_count < i)
- char_id_count = i;
- continue;
+ int i, j = 0;
+ if (SSCANF(line, "%d\t%%newid%%%n", &i, &j) == 1 && j > 0)
+ {
+ if (char_id_count < i)
+ char_id_count = i;
+ continue;
+ }
}
if (char_num >= char_max)
{
char_max += 256;
- RECREATE (char_dat, struct mmo_charstatus, char_max);
- RECREATE (online_chars, int, char_max);
- for (i = char_max - 256; i < char_max; i++)
+ RECREATE(char_dat, struct mmo_charstatus, char_max);
+ RECREATE(online_chars, int, char_max);
+ for (int i = char_max - 256; i < char_max; i++)
online_chars[i] = -1;
}
- ret = mmo_char_fromstr (line, &char_dat[char_num]);
- if (ret > 0)
- { // negative value or zero for errors
- if (char_dat[char_num].char_id >= char_id_count)
- char_id_count = char_dat[char_num].char_id + 1;
- char_num++;
- }
- else
+ if (!extract(line, &char_dat[char_num]))
{
- printf
- ("mmo_char_init: in characters file, unable to read the line #%d.\n",
- line_count);
- printf (" -> Character saved in log file.\n");
- switch (ret)
- {
- case -1:
- char_log
- ("Duplicate character id in the next character line (character not readed):\n");
- break;
- case -2:
- char_log
- ("Duplicate character name in the next character line (character not readed):\n");
- break;
- case -3:
- char_log
- ("Invalid memo point structure in the next character line (character not readed):\n");
- break;
- case -4:
- char_log
- ("Invalid inventory item structure in the next character line (character not readed):\n");
- break;
- case -5:
- char_log
- ("Invalid cart item structure in the next character line (character not readed):\n");
- break;
- case -6:
- char_log
- ("Invalid skill structure in the next character line (character not readed):\n");
- break;
- case -7:
- char_log
- ("Invalid register structure in the next character line (character not readed):\n");
- break;
- default: // 0
- char_log
- ("Unabled to get a character in the next line - Basic structure of line (before inventory) is incorrect (character not readed):\n");
- break;
- }
- char_log ("%s", line);
+ CHAR_LOG("Char skipped\n%s", line);
+ continue;
}
+ if (char_dat[char_num].char_id >= char_id_count)
+ char_id_count = char_dat[char_num].char_id + 1;
+ char_num++;
}
- fclose_ (fp);
- if (char_num == 0)
- {
- printf ("mmo_char_init: No character found in %s.\n", char_txt);
- char_log ("mmo_char_init: No character found in %s.\n",
- char_txt);
- }
- else if (char_num == 1)
- {
- printf ("mmo_char_init: 1 character read in %s.\n", char_txt);
- char_log ("mmo_char_init: 1 character read in %s.\n", char_txt);
- }
- else
- {
- printf ("mmo_char_init: %d characters read in %s.\n", char_num,
- char_txt);
- char_log ("mmo_char_init: %d characters read in %s.\n",
- char_num, char_txt);
- }
+ PRINTF("mmo_char_init: %d characters read in %s.\n",
+ char_num, char_txt);
+ CHAR_LOG("mmo_char_init: %d characters read in %s.\n",
+ char_num, char_txt);
- char_log ("Id for the next created character: %d.\n",
- char_id_count);
+ CHAR_LOG("Id for the next created character: %d.\n",
+ char_id_count);
return 0;
}
@@ -701,67 +533,43 @@ int mmo_char_init (void)
// Function to save characters in files (speed up by [Yor])
//---------------------------------------------------------
static
-void mmo_char_sync (void)
+void mmo_char_sync(void)
{
- char line[65536];
- int i, j, k;
- int lock;
+ int i;
+ int lock;
FILE *fp;
// Data save
- fp = lock_fopen (char_txt, &lock);
+ fp = lock_fopen(char_txt, &lock);
if (fp == NULL)
{
- printf ("WARNING: Server can't not save characters.\n");
- char_log ("WARNING: Server can't not save characters.\n");
+ PRINTF("WARNING: Server can't not save characters.\n");
+ CHAR_LOG("WARNING: Server can't not save characters.\n");
}
else
{
for (i = 0; i < char_num; i++)
{
- // create only once the line, and save it in the 2 files (it's speeder than repeat twice the loop and create twice the line)
- mmo_char_tostr (line, &char_dat[i]); // use of sorted index
- fprintf (fp, "%s\n", line);
- }
- fprintf (fp, "%d\t%%newid%%\n", char_id_count);
- lock_fclose (fp, char_txt, &lock);
- }
-
- // Data save (backup)
- if (backup_txt_flag)
- { // 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. => option By [Yor]
- fp = lock_fopen (backup_txt, &lock);
- if (fp == NULL)
- {
- printf
- ("WARNING: Server can't not create backup of characters file.\n");
- char_log
- ("WARNING: Server can't not create backup of characters file.\n");
- return;
- }
- for (i = 0; i < char_num; i++)
- {
- // create only once the line, and save it in the 2 files (it's speeder than repeat twice the loop and create twice the line)
- mmo_char_tostr (line, &char_dat[i]); // use of sorted index
- fprintf (fp, "%s\n", line);
+ // use of sorted index
+ std::string line = mmo_char_tostr(&char_dat[i]);
+ fwrite(line.data(), 1, line.size(), fp);
+ fputc('\n', fp);
}
- fprintf (fp, "%d\t%%newid%%\n", char_id_count);
- lock_fclose (fp, backup_txt, &lock);
+ FPRINTF(fp, "%d\t%%newid%%\n", char_id_count);
+ lock_fclose(fp, char_txt, &lock);
}
-
- return;
}
//----------------------------------------------------
// Function to save (in a periodic way) datas in files
//----------------------------------------------------
static
-void mmo_char_sync_timer (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data)
+void mmo_char_sync_timer(TimerData *, tick_t)
{
if (pid != 0)
{
- int status;
- pid_t temp = waitpid (pid, &status, WNOHANG);
+ int status;
+ pid_t temp = waitpid(pid, &status, WNOHANG);
// Need to check status too?
if (temp == 0)
@@ -772,23 +580,24 @@ void mmo_char_sync_timer (timer_id tid, tick_t tick, custom_id_t id, custom_data
// 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)
+ if ((pid = fork()) > 0)
return;
- mmo_char_sync ();
- inter_save ();
+ mmo_char_sync();
+ inter_save();
// If we're a child we should suicide now.
if (pid == 0)
- _exit (0);
+ _exit(0);
}
//----------------------------------------------------
// Remove trailing whitespace from a name
//----------------------------------------------------
-static void remove_trailing_blanks (char *name)
+static
+void remove_trailing_blanks(char *name)
{
- char *tail = name + strlen (name) - 1;
+ char *tail = name + strlen(name) - 1;
while (tail > name && *tail == ' ')
*tail-- = 0;
@@ -797,7 +606,8 @@ static void remove_trailing_blanks (char *name)
//----------------------------------------------------
// Remove prefix whitespace from a name
//----------------------------------------------------
-static void remove_prefix_blanks (char *name)
+static
+void remove_prefix_blanks(char *name)
{
char *dst = name;
char *src = name;
@@ -811,32 +621,30 @@ static void remove_prefix_blanks (char *name)
// Function to create a new character
//-----------------------------------
static
-int make_new_char (int fd, unsigned char *dat)
+int make_new_char(int fd, const uint8_t *dat)
{
// ugh
- char *cdat = (char *)dat;
- int i, j;
+ char *cdat = reinterpret_cast<char *>(const_cast<uint8_t *>(dat));
+ int i, j;
struct char_session_data *sd = (struct char_session_data *)session[fd]->session_data;
// remove control characters from the name
cdat[23] = '\0';
- if (remove_control_chars (cdat))
+ if (remove_control_chars(cdat))
{
- char_log
- ("Make new char error (control char received in the name): (connection #%d, account: %d).\n",
+ CHAR_LOG("Make new char error (control char received in the name): (connection #%d, account: %d).\n",
fd, sd->account_id);
return -1;
}
// Eliminate whitespace
- remove_trailing_blanks (cdat);
- remove_prefix_blanks (cdat);
+ remove_trailing_blanks(cdat);
+ remove_prefix_blanks(cdat);
// check lenght of character name
- if (strlen (cdat) < 4)
+ if (strlen(cdat) < 4)
{
- char_log
- ("Make new char error (character name too small): (connection #%d, account: %d, name: '%s').\n",
+ CHAR_LOG("Make new char error (character name too small): (connection #%d, account: %d, name: '%s').\n",
fd, sd->account_id, cdat);
return -1;
}
@@ -845,10 +653,9 @@ int make_new_char (int fd, unsigned char *dat)
if (char_name_option == 1)
{ // only letters/symbols in char_name_letters are authorised
for (i = 0; cdat[i]; i++)
- if (strchr (char_name_letters, cdat[i]) == NULL)
+ if (strchr(char_name_letters, cdat[i]) == NULL)
{
- char_log
- ("Make new char error (invalid letter in the name): (connection #%d, account: %d), name: %s, invalid letter: %c.\n",
+ CHAR_LOG("Make new char error (invalid letter in the name): (connection #%d, account: %d), name: %s, invalid letter: %c.\n",
fd, sd->account_id, cdat, cdat[i]);
return -1;
}
@@ -856,10 +663,9 @@ int make_new_char (int fd, unsigned char *dat)
else if (char_name_option == 2)
{ // letters/symbols in char_name_letters are forbidden
for (i = 0; cdat[i]; i++)
- if (strchr (char_name_letters, cdat[i]) != NULL)
+ if (strchr(char_name_letters, cdat[i]) != NULL)
{
- char_log
- ("Make new char error (invalid letter in the name): (connection #%d, account: %d), name: %s, invalid letter: %c.\n",
+ CHAR_LOG("Make new char error (invalid letter in the name): (connection #%d, account: %d), name: %s, invalid letter: %c.\n",
fd, sd->account_id, cdat, cdat[i]);
return -1;
}
@@ -871,8 +677,7 @@ int make_new_char (int fd, unsigned char *dat)
dat[33] >= 20 || // hair style
dat[31] >= 12)
{ // hair color (dat[31] can not be negativ)
- char_log
- ("Make new char error (invalid values): (connection #%d, account: %d) slot %d, name: %s, stats: %d+%d+%d+%d+%d+%d=%d, hair: %d, hair color: %d\n",
+ CHAR_LOG("Make new char error (invalid values): (connection #%d, account: %d) slot %d, name: %s, stats: %d+%d+%d+%d+%d+%d=%d, hair: %d, hair color: %d\n",
fd, sd->account_id, dat[30], dat, dat[24], dat[25],
dat[26], dat[27], dat[28], dat[29],
dat[24] + dat[25] + dat[26] + dat[27] + dat[28] + dat[29],
@@ -885,8 +690,7 @@ int make_new_char (int fd, unsigned char *dat)
{
if (dat[i] < 1 || dat[i] > 9)
{
- char_log
- ("Make new char error (invalid stat value: not between 1 to 9): (connection #%d, account: %d) slot %d, name: %s, stats: %d+%d+%d+%d+%d+%d=%d, hair: %d, hair color: %d\n",
+ CHAR_LOG("Make new char error (invalid stat value: not between 1 to 9): (connection #%d, account: %d) slot %d, name: %s, stats: %d+%d+%d+%d+%d+%d=%d, hair: %d, hair color: %d\n",
fd, sd->account_id, dat[30], dat, dat[24], dat[25],
dat[26], dat[27], dat[28], dat[29],
dat[24] + dat[25] + dat[26] + dat[27] + dat[28] + dat[29],
@@ -897,12 +701,11 @@ int make_new_char (int fd, unsigned char *dat)
for (i = 0; i < char_num; i++)
{
- if ((name_ignoring_case != 0 && strcmp (char_dat[i].name, cdat) == 0)
+ if ((name_ignoring_case != 0 && strcmp(char_dat[i].name, cdat) == 0)
|| (name_ignoring_case == 0
- && strcasecmp (char_dat[i].name, cdat) == 0))
+ && strcasecmp(char_dat[i].name, cdat) == 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.\n",
+ 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.\n",
fd, sd->account_id, dat[30], cdat, char_dat[i].name,
dat[24], dat[25], dat[26], dat[27], dat[28], dat[29],
dat[24] + dat[25] + dat[26] + dat[27] + dat[28] + dat[29],
@@ -912,8 +715,7 @@ int make_new_char (int fd, unsigned char *dat)
if (char_dat[i].account_id == sd->account_id
&& char_dat[i].char_num == dat[30])
{
- char_log
- ("Make new char error (slot already used): (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.\n",
+ CHAR_LOG("Make new char error (slot already used): (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.\n",
fd, sd->account_id, dat[30], cdat, char_dat[i].name,
dat[24], dat[25], dat[26], dat[27], dat[28], dat[29],
dat[24] + dat[25] + dat[26] + dat[27] + dat[28] + dat[29],
@@ -922,10 +724,9 @@ int make_new_char (int fd, unsigned char *dat)
}
}
- if (strcmp (wisp_server_name, cdat) == 0)
+ if (strcmp(wisp_server_name, cdat) == 0)
{
- char_log
- ("Make new char error (name used is wisp name for server): (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.\n",
+ CHAR_LOG("Make new char error (name used is wisp name for server): (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.\n",
fd, sd->account_id, dat[30], cdat, char_dat[i].name,
dat[24], dat[25], dat[26], dat[27], dat[28], dat[29],
dat[24] + dat[25] + dat[26] + dat[27] + dat[28] + dat[29],
@@ -936,8 +737,8 @@ int make_new_char (int fd, unsigned char *dat)
if (char_num >= char_max)
{
char_max += 256;
- RECREATE (char_dat, struct mmo_charstatus, char_max);
- RECREATE (online_chars, int, char_max);
+ 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;
}
@@ -945,239 +746,81 @@ int make_new_char (int fd, unsigned char *dat)
char ip[16];
unsigned char *sin_addr =
(unsigned char *) &session[fd]->client_addr.sin_addr;
- sprintf (ip, "%d.%d.%d.%d", sin_addr[0], sin_addr[1], sin_addr[2],
+ sprintf(ip, "%d.%d.%d.%d", sin_addr[0], sin_addr[1], sin_addr[2],
sin_addr[3]);
- char_log
- ("Creation of New Character: (connection #%d, account: %d) slot %d, character Name: %s, stats: %d+%d+%d+%d+%d+%d=%d, hair: %d, hair color: %d. [%s]\n",
+ CHAR_LOG("Creation of New Character: (connection #%d, account: %d) slot %d, character Name: %s, stats: %d+%d+%d+%d+%d+%d=%d, hair: %d, hair color: %d. [%s]\n",
fd, sd->account_id, dat[30], cdat, dat[24], dat[25], dat[26],
dat[27], dat[28], dat[29],
dat[24] + dat[25] + dat[26] + dat[27] + dat[28] + dat[29], dat[33],
dat[31], ip);
- memset (&char_dat[i], 0, sizeof (struct mmo_charstatus));
+ memset(&char_dat[i], 0, sizeof(struct mmo_charstatus));
char_dat[i].char_id = char_id_count++;
char_dat[i].account_id = sd->account_id;
char_dat[i].char_num = dat[30];
- strcpy (char_dat[i].name, cdat);
- char_dat[i].pc_class = 0;
+ strcpy(char_dat[i].name, cdat);
+ char_dat[i].species = 0;
char_dat[i].base_level = 1;
char_dat[i].job_level = 1;
char_dat[i].base_exp = 0;
char_dat[i].job_exp = 0;
char_dat[i].zeny = start_zeny;
- char_dat[i].str = dat[24];
- char_dat[i].agi = dat[25];
- char_dat[i].vit = dat[26];
- char_dat[i].int_ = dat[27];
- char_dat[i].dex = dat[28];
- char_dat[i].luk = dat[29];
- char_dat[i].max_hp = 40 * (100 + char_dat[i].vit) / 100;
- char_dat[i].max_sp = 11 * (100 + char_dat[i].int_) / 100;
+ char_dat[i].attrs[ATTR::STR] = dat[24];
+ char_dat[i].attrs[ATTR::AGI] = dat[25];
+ char_dat[i].attrs[ATTR::VIT] = dat[26];
+ char_dat[i].attrs[ATTR::INT] = dat[27];
+ char_dat[i].attrs[ATTR::DEX] = dat[28];
+ char_dat[i].attrs[ATTR::LUK] = dat[29];
+ char_dat[i].max_hp = 40 * (100 + char_dat[i].attrs[ATTR::VIT]) / 100;
+ char_dat[i].max_sp = 11 * (100 + char_dat[i].attrs[ATTR::INT]) / 100;
char_dat[i].hp = char_dat[i].max_hp;
char_dat[i].sp = char_dat[i].max_sp;
char_dat[i].status_point = 0;
char_dat[i].skill_point = 0;
- char_dat[i].option = 0;
+ char_dat[i].option = static_cast<Option>(0x0000); // Option is only declared
char_dat[i].karma = 0;
char_dat[i].manner = 0;
char_dat[i].party_id = 0;
- char_dat[i].guild_id = 0;
+ //char_dat[i].guild_id = 0;
char_dat[i].hair = dat[33];
char_dat[i].hair_color = dat[31];
char_dat[i].clothes_color = 0;
char_dat[i].inventory[0].nameid = start_weapon; // Knife
char_dat[i].inventory[0].amount = 1;
- char_dat[i].inventory[0].equip = 0x02;
+ char_dat[i].inventory[0].equip = EPOS::WEAPON;
char_dat[i].inventory[0].identify = 1;
char_dat[i].inventory[0].broken = 0;
char_dat[i].inventory[1].nameid = start_armor; // Cotton Shirt
char_dat[i].inventory[1].amount = 1;
- char_dat[i].inventory[1].equip = 0x10;
+ char_dat[i].inventory[1].equip = EPOS::MISC1;
char_dat[i].inventory[1].identify = 1;
char_dat[i].inventory[1].broken = 0;
- char_dat[i].weapon = 1;
+ char_dat[i].weapon = ItemLook::BLADE;
char_dat[i].shield = 0;
char_dat[i].head_top = 0;
char_dat[i].head_mid = 0;
char_dat[i].head_bottom = 0;
- memcpy (&char_dat[i].last_point, &start_point, sizeof (start_point));
- memcpy (&char_dat[i].save_point, &start_point, sizeof (start_point));
+ memcpy(&char_dat[i].last_point, &start_point, sizeof(start_point));
+ memcpy(&char_dat[i].save_point, &start_point, sizeof(start_point));
char_num++;
return i;
}
-//----------------------------------------------------
-// This function return the name of the job (by [Yor])
-//----------------------------------------------------
-static
-const char *job_name (int pc_class)
-{
- switch (pc_class)
- {
- case 0:
- return "Novice";
- case 1:
- return "Swordsman";
- case 2:
- return "Mage";
- case 3:
- return "Archer";
- case 4:
- return "Acolyte";
- case 5:
- return "Merchant";
- case 6:
- return "Thief";
- case 7:
- return "Knight";
- case 8:
- return "Priest";
- case 9:
- return "Wizard";
- case 10:
- return "Blacksmith";
- case 11:
- return "Hunter";
- case 12:
- return "Assassin";
- case 13:
- return "Knight 2";
- case 14:
- return "Crusader";
- case 15:
- return "Monk";
- case 16:
- return "Sage";
- case 17:
- return "Rogue";
- case 18:
- return "Alchemist";
- case 19:
- return "Bard";
- case 20:
- return "Dancer";
- case 21:
- return "Crusader 2";
- case 22:
- return "Wedding";
- case 23:
- return "Super Novice";
- case 4001:
- return "Novice High";
- case 4002:
- return "Swordsman High";
- case 4003:
- return "Mage High";
- case 4004:
- return "Archer High";
- case 4005:
- return "Acolyte High";
- case 4006:
- return "Merchant High";
- case 4007:
- return "Thief High";
- case 4008:
- return "Lord Knight";
- case 4009:
- return "High Priest";
- case 4010:
- return "High Wizard";
- case 4011:
- return "Whitesmith";
- case 4012:
- return "Sniper";
- case 4013:
- return "Assassin Cross";
- case 4014:
- return "Peko Knight";
- case 4015:
- return "Paladin";
- case 4016:
- return "Champion";
- case 4017:
- return "Professor";
- case 4018:
- return "Stalker";
- case 4019:
- return "Creator";
- case 4020:
- return "Clown";
- case 4021:
- return "Gypsy";
- case 4022:
- return "Peko Paladin";
- case 4023:
- return "Baby Novice";
- case 4024:
- return "Baby Swordsman";
- case 4025:
- return "Baby Mage";
- case 4026:
- return "Baby Archer";
- case 4027:
- return "Baby Acolyte";
- case 4028:
- return "Baby Merchant";
- case 4029:
- return "Baby Thief";
- case 4030:
- return "Baby Knight";
- case 4031:
- return "Baby Priest";
- case 4032:
- return "Baby Wizard";
- case 4033:
- return "Baby Blacksmith";
- case 4034:
- return "Baby Hunter";
- case 4035:
- return "Baby Assassin";
- case 4036:
- return "Baby Peco Knight";
- case 4037:
- return "Baby Crusader";
- case 4038:
- return "Baby Monk";
- case 4039:
- return "Baby Sage";
- case 4040:
- return "Baby Rogue";
- case 4041:
- return "Baby Alchemist";
- case 4042:
- return "Baby Bard";
- case 4043:
- return "Baby Dancer";
- case 4044:
- return "Baby Peco Crusader";
- case 4045:
- return "Super Baby";
- }
- return "Unknown Job";
-}
-
//-------------------------------------------------------------
// Function to create the online files (txt and html). by [Yor]
//-------------------------------------------------------------
static
-void create_online_files (void)
+void create_online_files(void)
{
- int i, j, k, l; // for loops
- int players; // count the number of players
+ int i, j, k, l; // for loops
+ int players; // count the number of players
FILE *fp; // for the txt file
FILE *fp2; // for the html file
char temp[256]; // to prepare what we must display
- time_t time_server; // for number of seconds
- struct tm *datetime; // variable for time in structure ->tm_mday, ->tm_sec, ...
- int id[char_num];
-
- if (online_display_option == 0) // we display nothing, so return
- return;
-
- //char_log("Creation of online players files.\n");
+ int id[char_num];
// Get number of online players, id of each online players
players = 0;
@@ -1194,10 +837,10 @@ 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 (strcasecmp (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.
- (strcasecmp (p_name, char_dat[id[j]].name) == 0 &&
- strcmp (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--)
id[k] = id[k - 1];
@@ -1211,7 +854,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 &&
- strcasecmp (char_dat[i].name,
+ strcasecmp(char_dat[i].name,
char_dat[id[j]].name) < 0))
{
for (k = players; k > j; k--)
@@ -1236,34 +879,14 @@ void create_online_files (void)
break;
}
break;
- case 4: // by job (and job level)
- for (j = 0; j < players; j++)
- if (char_dat[i].pc_class < char_dat[id[j]].pc_class ||
- // if same job, we sort by job level.
- (char_dat[i].pc_class == char_dat[id[j]].pc_class &&
- char_dat[i].job_level <
- char_dat[id[j]].job_level) ||
- // if same job and job level, we sort by job exp.
- (char_dat[i].pc_class == char_dat[id[j]].pc_class &&
- char_dat[i].job_level ==
- char_dat[id[j]].job_level
- && char_dat[i].job_exp <
- char_dat[id[j]].job_exp))
- {
- for (k = players; k > j; k--)
- id[k] = id[k - 1];
- id[j] = i; // id[players]
- break;
- }
- break;
case 5: // by location map name
{
- int cpm_result; // A lot of player maps are identical. So, test if done often twice.
+ 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 strcasecmp)
+ 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 &&
- strcasecmp (char_dat[i].name,
+ strcasecmp(char_dat[i].name,
char_dat[id[j]].name) < 0))
{
for (k = players; k > j; k--)
@@ -1281,222 +904,99 @@ void create_online_files (void)
}
// write files
- fp = fopen_ (online_txt_filename, "w");
+ fp = fopen_(online_txt_filename, "w");
if (fp != NULL)
{
- fp2 = fopen_ (online_html_filename, "w");
+ fp2 = fopen_(online_html_filename, "w");
if (fp2 != NULL)
{
// get time
- time (&time_server); // get time in seconds since 1/1/1970
- datetime = localtime (&time_server); // convert seconds in structure
- strftime (temp, sizeof (temp), "%d %b %Y %X", datetime); // like sprintf, but only for date/time (05 dec 2003 15:12:52)
+#warning "Need to convert/check the PHP code"
+ timestamp_seconds_buffer timetemp;
+ stamp_time(timetemp);
// write heading
- fprintf (fp2, "<HTML>\n");
- fprintf (fp2, " <META http-equiv=\"Refresh\" content=\"%d\">\n", online_refresh_html); // update on client explorer every x seconds
- fprintf (fp2, " <HEAD>\n");
- fprintf (fp2, " <TITLE>Online Players on %s</TITLE>\n",
+ FPRINTF(fp2, "<HTML>\n");
+ FPRINTF(fp2, " <META http-equiv=\"Refresh\" content=\"%d\">\n", online_refresh_html); // update on client explorer every x seconds
+ FPRINTF(fp2, " <HEAD>\n");
+ FPRINTF(fp2, " <TITLE>Online Players on %s</TITLE>\n",
server_name);
- fprintf (fp2, " </HEAD>\n");
- fprintf (fp2, " <BODY>\n");
- fprintf (fp2, " <H3>Online Players on %s (%s):</H3>\n",
- server_name, temp);
- fprintf (fp, "Online Players on %s (%s):\n", server_name, temp);
- fprintf (fp, "\n");
+ FPRINTF(fp2, " </HEAD>\n");
+ FPRINTF(fp2, " <BODY>\n");
+ FPRINTF(fp2, " <H3>Online Players on %s (%s):</H3>\n",
+ server_name, timetemp);
+ FPRINTF(fp, "Online Players on %s (%s):\n", server_name, timetemp);
+ FPRINTF(fp, "\n");
// If we display at least 1 player
if (players > 0)
{
j = 0; // count the number of characters for the txt version and to set the separate line
- fprintf (fp2, " <table border=\"1\" cellspacing=\"1\">\n");
- fprintf (fp2, " <tr>\n");
- if ((online_display_option & 1)
- || (online_display_option & 64))
+ FPRINTF(fp2, " <table border=\"1\" cellspacing=\"1\">\n");
+ FPRINTF(fp2, " <tr>\n");
{
- fprintf (fp2, " <td><b>Name</b></td>\n");
- if (online_display_option & 64)
+ FPRINTF(fp2, " <td><b>Name</b></td>\n");
{
- fprintf (fp, "Name "); // 30
+ FPRINTF(fp, "Name "); // 30
j += 30;
}
- else
- {
- fprintf (fp, "Name "); // 25
- j += 25;
- }
- }
- if ((online_display_option & 6) == 6)
- {
- fprintf (fp2, " <td><b>Job (levels)</b></td>\n");
- fprintf (fp, "Job Levels "); // 27
- j += 27;
- }
- else if (online_display_option & 2)
- {
- fprintf (fp2, " <td><b>Job</b></td>\n");
- fprintf (fp, "Job "); // 19
- j += 19;
- }
- else if (online_display_option & 4)
- {
- fprintf (fp2, " <td><b>Levels</b></td>\n");
- fprintf (fp, " Levels "); // 8
- j += 8;
- }
- if (online_display_option & 24)
- { // 8 or 16
- fprintf (fp2, " <td><b>Location</b></td>\n");
- if (online_display_option & 16)
- {
- fprintf (fp, "Location ( x , y ) "); // 23
- j += 23;
- }
- else
- {
- fprintf (fp, "Location "); // 13
- j += 13;
- }
- }
- if (online_display_option & 32)
- {
- fprintf (fp2,
- " <td ALIGN=CENTER><b>zenys</b></td>\n");
- fprintf (fp, " Zenys "); // 16
- j += 16;
}
- fprintf (fp2, " </tr>\n");
- fprintf (fp, "\n");
+ FPRINTF(fp2, " </tr>\n");
+ FPRINTF(fp, "\n");
for (k = 0; k < j; k++)
- fprintf (fp, "-");
- fprintf (fp, "\n");
+ FPRINTF(fp, "-");
+ FPRINTF(fp, "\n");
// display each player.
for (i = 0; i < players; i++)
{
// get id of the character (more speed)
j = id[i];
- fprintf (fp2, " <tr>\n");
+ FPRINTF(fp2, " <tr>\n");
// displaying the character name
- if ((online_display_option & 1)
- || (online_display_option & 64))
{ // without/with 'GM' display
- strcpy (temp, char_dat[j].name);
- l = isGM (char_dat[j].account_id);
- if (online_display_option & 64)
+ strcpy(temp, char_dat[j].name);
+ l = isGM(char_dat[j].account_id);
{
if (l >= online_gm_display_min_level)
- fprintf (fp, "%-24s (GM) ", temp);
+ FPRINTF(fp, "%-24s (GM) ", temp);
else
- fprintf (fp, "%-24s ", temp);
+ FPRINTF(fp, "%-24s ", temp);
}
- else
- fprintf (fp, "%-24s ", temp);
// name of the character in the html (no < >, because that create problem in html code)
- fprintf (fp2, " <td>");
- if ((online_display_option & 64)
- && l >= online_gm_display_min_level)
- fprintf (fp2, "<b>");
+ FPRINTF(fp2, " <td>");
+ if (l >= online_gm_display_min_level)
+ FPRINTF(fp2, "<b>");
for (k = 0; temp[k]; k++)
{
switch (temp[k])
{
case '<': // <
- fprintf (fp2, "&lt;");
+ FPRINTF(fp2, "&lt;");
break;
case '>': // >
- fprintf (fp2, "&gt;");
+ FPRINTF(fp2, "&gt;");
break;
default:
- fprintf (fp2, "%c", temp[k]);
+ FPRINTF(fp2, "%c", temp[k]);
break;
};
}
- if ((online_display_option & 64)
- && l >= online_gm_display_min_level)
- fprintf (fp2, "</b> (GM)");
- fprintf (fp2, "</td>\n");
+ if (l >= online_gm_display_min_level)
+ FPRINTF(fp2, "</b> (GM)");
+ FPRINTF(fp2, "</td>\n");
}
- // displaying of the job
- if (online_display_option & 6)
- {
- const char *jobname = job_name (char_dat[j].pc_class);
- if ((online_display_option & 6) == 6)
- {
- fprintf (fp2, " <td>%s %d/%d</td>\n",
- jobname, char_dat[j].base_level,
- char_dat[j].job_level);
- fprintf (fp, "%-18s %3d/%3d ", jobname,
- char_dat[j].base_level,
- char_dat[j].job_level);
- }
- else if (online_display_option & 2)
- {
- fprintf (fp2, " <td>%s</td>\n", jobname);
- fprintf (fp, "%-18s ", jobname);
- }
- else if (online_display_option & 4)
- {
- fprintf (fp2, " <td>%d/%d</td>\n",
- char_dat[j].base_level,
- char_dat[j].job_level);
- fprintf (fp, "%3d/%3d ", char_dat[j].base_level,
- char_dat[j].job_level);
- }
- }
- // displaying of the map
- if (online_display_option & 24)
- { // 8 or 16
- // prepare map name
- memset (temp, 0, sizeof (temp));
- strncpy (temp, char_dat[j].last_point.map, 16);
- if (strchr (temp, '.') != NULL)
- temp[strchr (temp, '.') - temp] = '\0'; // suppress the '.gat'
- // write map name
- if (online_display_option & 16)
- { // map-name AND coordonates
- fprintf (fp2, " <td>%s (%d, %d)</td>\n",
- temp, char_dat[j].last_point.x,
- char_dat[j].last_point.y);
- fprintf (fp, "%-12s (%3d,%3d) ", temp,
- char_dat[j].last_point.x,
- char_dat[j].last_point.y);
- }
- else
- {
- fprintf (fp2, " <td>%s</td>\n", temp);
- fprintf (fp, "%-12s ", temp);
- }
- }
- // displaying number of zenys
- if (online_display_option & 32)
- {
- // write number of zenys
- if (char_dat[j].zeny == 0)
- { // if no zeny
- fprintf (fp2,
- " <td ALIGN=RIGHT>no zeny</td>\n");
- fprintf (fp, " no zeny ");
- }
- else
- {
- fprintf (fp2,
- " <td ALIGN=RIGHT>%d z</td>\n",
- char_dat[j].zeny);
- fprintf (fp, "%13d z ", char_dat[j].zeny);
- }
- }
- fprintf (fp, "\n");
- fprintf (fp2, " </tr>\n");
+ FPRINTF(fp, "\n");
+ FPRINTF(fp2, " </tr>\n");
}
- fprintf (fp2, " </table>\n");
- fprintf (fp, "\n");
+ FPRINTF(fp2, " </table>\n");
+ FPRINTF(fp, "\n");
}
// Displaying number of online players
if (players == 0)
{
- fprintf (fp2, " <p>No user is online.</p>\n");
- fprintf (fp, "No user is online.\n");
+ FPRINTF(fp2, " <p>No user is online.</p>\n");
+ FPRINTF(fp, "No user is online.\n");
// no display if only 1 player
}
else if (players == 1)
@@ -1504,14 +1004,14 @@ void create_online_files (void)
}
else
{
- fprintf (fp2, " <p>%d users are online.</p>\n", players);
- fprintf (fp, "%d users are online.\n", players);
+ FPRINTF(fp2, " <p>%d users are online.</p>\n", players);
+ FPRINTF(fp, "%d users are online.\n", players);
}
- fprintf (fp2, " </BODY>\n");
- fprintf (fp2, "</HTML>\n");
- fclose_ (fp2);
+ FPRINTF(fp2, " </BODY>\n");
+ FPRINTF(fp2, "</HTML>\n");
+ fclose_(fp2);
}
- fclose_ (fp);
+ fclose_(fp);
}
return;
@@ -1521,9 +1021,9 @@ void create_online_files (void)
// This function return the number of online players in all map-servers
//---------------------------------------------------------------------
static
-int count_users (void)
+int count_users(void)
{
- int i, users;
+ int i, users;
users = 0;
for (i = 0; i < MAX_MAP_SERVERS; i++)
@@ -1536,12 +1036,13 @@ int count_users (void)
//----------------------------------------
// [Fate] Find inventory item based on equipment mask, return view. ID must match view ID (!).
//----------------------------------------
-static int find_equip_view (struct mmo_charstatus *p, unsigned int equipmask)
+static
+int find_equip_view(struct mmo_charstatus *p, EPOS equipmask)
{
- int i;
+ int i;
for (i = 0; i < MAX_INVENTORY; i++)
if (p->inventory[i].nameid && p->inventory[i].amount
- && p->inventory[i].equip & equipmask)
+ && bool(p->inventory[i].equip & equipmask))
return p->inventory[i].nameid;
return 0;
}
@@ -1550,9 +1051,9 @@ static int find_equip_view (struct mmo_charstatus *p, unsigned int equipmask)
// Function to send characters to a player
//----------------------------------------
static
-int mmo_char_send006b (int fd, struct char_session_data *sd)
+int mmo_char_send006b(int fd, struct char_session_data *sd)
{
- int i, j, found_num;
+ int i, j, found_num;
struct mmo_charstatus *p;
const int offset = 24;
@@ -1570,78 +1071,78 @@ int mmo_char_send006b (int fd, struct char_session_data *sd)
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;
+ memset(WFIFOP(fd, 0), 0, offset + found_num * 106);
+ WFIFOW(fd, 0) = 0x6b;
+ WFIFOW(fd, 2) = offset + found_num * 106;
for (i = 0; i < found_num; i++)
{
p = &char_dat[sd->found_char[i]];
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) = 0; //p->job_level; // [Fate] We no longer reveal this to the player, as its meaning is weird.
-
- WFIFOW (fd, j + 20) = find_equip_view (p, 0x0040); // 9: shoes
- WFIFOW (fd, j + 22) = find_equip_view (p, 0x0004); // 10: gloves
- WFIFOW (fd, j + 24) = find_equip_view (p, 0x0008); // 11: cape
- WFIFOW (fd, j + 26) = find_equip_view (p, 0x0010); // 12: misc1
- 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->pc_class;
- WFIFOW (fd, j + 54) = p->hair;
+ 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) = 0; //p->job_level; // [Fate] We no longer reveal this to the player, as its meaning is weird.
+
+ WFIFOW(fd, j + 20) = find_equip_view(p, EPOS::SHOES);
+ WFIFOW(fd, j + 22) = find_equip_view(p, EPOS::GLOVES);
+ WFIFOW(fd, j + 24) = find_equip_view(p, EPOS::CAPE);
+ WFIFOW(fd, j + 26) = find_equip_view(p, EPOS::MISC1);
+ WFIFOL(fd, j + 28) = static_cast<uint16_t>(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) = static_cast<uint16_t>(DEFAULT_WALK_SPEED.count()); // p->speed;
+ WFIFOW(fd, j + 52) = p->species;
+ WFIFOW(fd, j + 54) = p->hair;
// WFIFOW(fd,j+56) = p->weapon; // dont send weapon since TMW does not support it
- WFIFOW (fd, j + 56) = 0;
- 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) = find_equip_view (p, 0x0080); // 13: misc2
+ WFIFOW(fd, j + 56) = 0;
+ 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) = find_equip_view(p, EPOS::MISC2);
// WFIFOW(fd,j+72) = p->clothes_color;
- memcpy (WFIFOP (fd, j + 74), p->name, 24);
+ 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;
+ WFIFOB(fd, j + 98) = min(p->attrs[ATTR::STR], 255);
+ WFIFOB(fd, j + 99) = min(p->attrs[ATTR::AGI], 255);
+ WFIFOB(fd, j + 100) = min(p->attrs[ATTR::VIT], 255);
+ WFIFOB(fd, j + 101) = min(p->attrs[ATTR::INT], 255);
+ WFIFOB(fd, j + 102) = min(p->attrs[ATTR::DEX], 255);
+ WFIFOB(fd, j + 103) = min(p->attrs[ATTR::LUK], 255);
+ WFIFOB(fd, j + 104) = p->char_num;
}
- WFIFOSET (fd, WFIFOW (fd, 2));
+ WFIFOSET(fd, WFIFOW(fd, 2));
return 0;
}
static
-int set_account_reg2 (int acc, int num, struct global_reg *reg)
+int set_account_reg2(int acc, int num, struct global_reg *reg)
{
- int i, c;
+ int i, c;
c = 0;
for (i = 0; i < char_num; i++)
{
if (char_dat[i].account_id == acc)
{
- memcpy (char_dat[i].account_reg2, reg,
- sizeof (char_dat[i].account_reg2));
+ memcpy(char_dat[i].account_reg2, reg,
+ sizeof(char_dat[i].account_reg2));
char_dat[i].account_reg2_num = num;
c++;
}
@@ -1651,9 +1152,9 @@ int set_account_reg2 (int acc, int num, struct global_reg *reg)
// Divorce a character from it's partner and let the map server know
static
-int char_divorce (struct mmo_charstatus *cs)
+int char_divorce(struct mmo_charstatus *cs)
{
- int i;
+ int i;
uint8_t buf[10];
if (cs == NULL)
@@ -1661,23 +1162,23 @@ int char_divorce (struct mmo_charstatus *cs)
if (cs->partner_id <= 0)
{
- WBUFW (buf, 0) = 0x2b12;
- WBUFL (buf, 2) = cs->char_id;
- WBUFL (buf, 6) = 0; // partner id 0 means failure
- mapif_sendall (buf, 10);
+ WBUFW(buf, 0) = 0x2b12;
+ WBUFL(buf, 2) = cs->char_id;
+ WBUFL(buf, 6) = 0; // partner id 0 means failure
+ mapif_sendall(buf, 10);
return 0;
}
- WBUFW (buf, 0) = 0x2b12;
- WBUFL (buf, 2) = cs->char_id;
+ WBUFW(buf, 0) = 0x2b12;
+ WBUFL(buf, 2) = cs->char_id;
for (i = 0; i < char_num; i++)
{
if (char_dat[i].char_id == cs->partner_id
&& char_dat[i].partner_id == cs->char_id)
{
- WBUFL (buf, 6) = cs->partner_id;
- mapif_sendall (buf, 10);
+ WBUFL(buf, 6) = cs->partner_id;
+ mapif_sendall(buf, 10);
cs->partner_id = 0;
char_dat[i].partner_id = 0;
return 0;
@@ -1686,17 +1187,17 @@ int char_divorce (struct mmo_charstatus *cs)
// Don't worry about this, as the map server should verify itself that the other doesn't have us as a partner, and so won't mess with their marriage
else if (char_dat[i].char_id == cs->partner_id)
{
- WBUFL (buf, 6) = cs->partner_id;
- mapif_sendall (buf, 10);
+ WBUFL(buf, 6) = cs->partner_id;
+ mapif_sendall(buf, 10);
cs->partner_id = 0;
return 0;
}
}
// Our partner wasn't found, so just clear our marriage
- WBUFL (buf, 6) = cs->partner_id;
+ WBUFL(buf, 6) = cs->partner_id;
cs->partner_id = 0;
- mapif_sendall (buf, 10);
+ mapif_sendall(buf, 10);
return 0;
}
@@ -1705,9 +1206,9 @@ int char_divorce (struct mmo_charstatus *cs)
// Force disconnection of an online player (with account value) by [Yor]
//----------------------------------------------------------------------
static
-int disconnect_player (int accound_id)
+int disconnect_player(int accound_id)
{
- int i;
+ int i;
struct char_session_data *sd;
// disconnect player if online on char-server
@@ -1727,32 +1228,29 @@ int disconnect_player (int accound_id)
}
// キャラ削除ã«ä¼´ã†ãƒ‡ãƒ¼ã‚¿å‰Šé™¤
-static int char_delete (struct mmo_charstatus *cs)
+static
+int char_delete(struct mmo_charstatus *cs)
{
-
- // ギルド脱退
- if (cs->guild_id)
- inter_guild_leave (cs->guild_id, cs->account_id, cs->char_id);
// パーティー脱退
if (cs->party_id)
- inter_party_leave (cs->party_id, cs->account_id);
+ inter_party_leave(cs->party_id, cs->account_id);
// 離婚
if (cs->partner_id)
- char_divorce (cs);
+ char_divorce(cs);
// Force the character (and all on the same account) to leave all map servers
{
unsigned char buf[6];
- WBUFW (buf, 0) = 0x2afe;
- WBUFL (buf, 2) = cs->account_id;
- mapif_sendall (buf, 6);
+ WBUFW(buf, 0) = 0x2afe;
+ WBUFL(buf, 2) = cs->account_id;
+ mapif_sendall(buf, 6);
}
return 0;
}
static
-void parse_tologin (int fd)
+void parse_tologin(int fd)
{
struct char_session_data *sd;
@@ -1762,42 +1260,37 @@ void parse_tologin (int fd)
{
if (fd == login_fd)
{
- printf
- ("Char-server can't connect to login-server (connection #%d).\n",
+ PRINTF("Char-server can't connect to login-server (connection #%d).\n",
fd);
login_fd = -1;
}
- close (fd);
- delete_session (fd);
+ delete_session(fd);
return;
}
sd = (struct char_session_data*)session[fd]->session_data;
- while (RFIFOREST (fd) >= 2)
+ while (RFIFOREST(fd) >= 2)
{
-// printf("parse_tologin: connection #%d, packet: 0x%x (with being read: %d bytes).\n", fd, RFIFOW(fd,0), RFIFOREST(fd));
+// PRINTF("parse_tologin: connection #%d, packet: 0x%x (with being read: %d bytes).\n", fd, RFIFOW(fd,0), RFIFOREST(fd));
- switch (RFIFOW (fd, 0))
+ switch (RFIFOW(fd, 0))
{
case 0x2711:
- if (RFIFOREST (fd) < 3)
+ if (RFIFOREST(fd) < 3)
return;
- if (RFIFOB (fd, 2))
+ 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 accounts file (default: accounts.txt) has those values present.\n");
- printf
- ("If you changed the communication passwords, change them back at map_athena.conf and char_athena.conf\n");
- exit (1);
+// 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 accounts file (default: accounts.txt) has those values present.\n");
+ PRINTF("If you changed the communication passwords, change them back at map_athena.conf and char_athena.conf\n");
+ exit(1);
}
else
{
- printf ("Connected to login-server (connection #%d).\n",
+ PRINTF("Connected to login-server (connection #%d).\n",
fd);
// if no map-server already connected, display a message...
int i;
@@ -1805,137 +1298,114 @@ void parse_tologin (int fd)
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");
+ PRINTF("Awaiting maps from map-server.\n");
}
- RFIFOSKIP (fd, 3);
+ RFIFOSKIP(fd, 3);
break;
case 0x2713:
- if (RFIFOREST (fd) < 51)
+ if (RFIFOREST(fd) < 51)
return;
-// printf("parse_tologin 2713 : %d\n", RFIFOB(fd,6));
+// PRINTF("parse_tologin 2713 : %d\n", RFIFOB(fd,6));
for (int i = 0; i < fd_max; i++)
{
if (session[i] && (sd = (struct char_session_data*)session[i]->session_data)
- && sd->account_id == RFIFOL (fd, 2))
+ && sd->account_id == RFIFOL(fd, 2))
{
- if (RFIFOB (fd, 6) != 0)
+ if (RFIFOB(fd, 6) != 0)
{
- WFIFOW (i, 0) = 0x6c;
- WFIFOB (i, 2) = 0x42;
- WFIFOSET (i, 3);
+ WFIFOW(i, 0) = 0x6c;
+ WFIFOB(i, 2) = 0x42;
+ WFIFOSET(i, 3);
}
else if (max_connect_user == 0
- || count_users () < max_connect_user)
+ || count_users() < max_connect_user)
{
// if (max_connect_user == 0)
-// printf("max_connect_user (unlimited) -> accepted.\n");
+// PRINTF("max_connect_user (unlimited) -> accepted.\n");
// else
-// printf("count_users(): %d < max_connect_user (%d) -> accepted.\n", count_users(), max_connect_user);
- memcpy (sd->email, RFIFOP (fd, 7), 40);
- if (e_mail_check (sd->email) == 0)
- strncpy (sd->email, "a@a.com", 40); // default e-mail
- sd->connect_until_time = (time_t) RFIFOL (fd, 47);
+// PRINTF("count_users(): %d < max_connect_user (%d) -> accepted.\n", count_users(), max_connect_user);
+ memcpy(sd->email, RFIFOP(fd, 7), 40);
+ if (e_mail_check(sd->email) == 0)
+ strzcpy(sd->email, "a@a.com", 40); // default e-mail
+ sd->connect_until_time = static_cast<time_t>(RFIFOL(fd, 47));
// send characters to player
- mmo_char_send006b (i, sd);
+ 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);
+// PRINTF("count_users(): %d < max_connect_use (%d) -> fail...\n", count_users(), max_connect_user);
+ WFIFOW(i, 0) = 0x6c;
+ WFIFOB(i, 2) = 0;
+ WFIFOSET(i, 3);
}
break;
}
}
- RFIFOSKIP (fd, 51);
+ RFIFOSKIP(fd, 51);
break;
// 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)
+ if (RFIFOREST(fd) < 50)
return;
for (int i = 0; i < fd_max; i++)
{
if (session[i] && (sd = (struct char_session_data*)session[i]->session_data))
{
- if (sd->account_id == RFIFOL (fd, 2))
+ if (sd->account_id == RFIFOL(fd, 2))
{
- memcpy (sd->email, RFIFOP (fd, 6), 40);
- if (e_mail_check (sd->email) == 0)
- strncpy (sd->email, "a@a.com", 40); // default e-mail
- sd->connect_until_time = (time_t) RFIFOL (fd, 46);
+ memcpy(sd->email, RFIFOP(fd, 6), 40);
+ if (e_mail_check(sd->email) == 0)
+ strzcpy(sd->email, "a@a.com", 40); // default e-mail
+ sd->connect_until_time = static_cast<time_t>(RFIFOL(fd, 46));
break;
}
}
}
- RFIFOSKIP (fd, 50);
+ RFIFOSKIP(fd, 50);
break;
case 0x2721: // gm reply
- if (RFIFOREST (fd) < 10)
+ if (RFIFOREST(fd) < 10)
return;
{
unsigned char buf[10];
- WBUFW (buf, 0) = 0x2b0b;
- WBUFL (buf, 2) = RFIFOL (fd, 2); // account
- WBUFL (buf, 6) = RFIFOL (fd, 6); // GM level
- mapif_sendall (buf, 10);
-// printf("parse_tologin: To become GM answer: char -> map.\n");
+ WBUFW(buf, 0) = 0x2b0b;
+ WBUFL(buf, 2) = RFIFOL(fd, 2); // account
+ WBUFL(buf, 6) = RFIFOL(fd, 6); // GM level
+ mapif_sendall(buf, 10);
+// PRINTF("parse_tologin: To become GM answer: char -> map.\n");
}
- RFIFOSKIP (fd, 10);
+ RFIFOSKIP(fd, 10);
break;
case 0x2723: // changesex reply (modified by [Yor])
- if (RFIFOREST (fd) < 7)
+ if (RFIFOREST(fd) < 7)
return;
{
- int acc, sex, i, j;
+ int acc, sex, i, j;
unsigned char buf[7];
- acc = RFIFOL (fd, 2);
- sex = RFIFOB (fd, 6);
- RFIFOSKIP (fd, 7);
+ acc = RFIFOL(fd, 2);
+ sex = RFIFOB(fd, 6);
+ RFIFOSKIP(fd, 7);
if (acc > 0)
{
for (i = 0; i < char_num; i++)
{
if (char_dat[i].account_id == acc)
{
- int jobclass = char_dat[i].pc_class;
char_dat[i].sex = sex;
// auth_fifo[i].sex = sex;
- if (jobclass == 19 || jobclass == 20 ||
- jobclass == 4020 || jobclass == 4021 ||
- jobclass == 4042 || jobclass == 4043)
- {
- // job modification
- if (jobclass == 19 || jobclass == 20)
- {
- char_dat[i].pc_class = (sex) ? 19 : 20;
- }
- else if (jobclass == 4020
- || jobclass == 4021)
- {
- char_dat[i].pc_class =
- (sex) ? 4020 : 4021;
- }
- else if (jobclass == 4042
- || jobclass == 4043)
- {
- char_dat[i].pc_class =
- (sex) ? 4042 : 4043;
- }
- }
// to avoid any problem with equipment and invalid sex, equipment is unequiped.
for (j = 0; j < MAX_INVENTORY; j++)
{
if (char_dat[i].inventory[j].nameid
- && char_dat[i].inventory[j].equip)
- char_dat[i].inventory[j].equip = 0;
+ && bool(char_dat[i].inventory[j].equip))
+ char_dat[i].inventory[j].equip = EPOS::ZERO;
}
- char_dat[i].weapon = 0;
+ char_dat[i].weapon = ItemLook::NONE;
char_dat[i].shield = 0;
char_dat[i].head_top = 0;
char_dat[i].head_mid = 0;
@@ -1943,22 +1413,21 @@ void parse_tologin (int fd)
}
}
// disconnect player if online on char-server
- disconnect_player (acc);
+ disconnect_player(acc);
}
- WBUFW (buf, 0) = 0x2b0d;
- WBUFL (buf, 2) = acc;
- WBUFB (buf, 6) = sex;
- mapif_sendall (buf, 7);
+ WBUFW(buf, 0) = 0x2b0d;
+ WBUFL(buf, 2) = acc;
+ WBUFB(buf, 6) = sex;
+ mapif_sendall(buf, 7);
}
break;
case 0x2726: // Request to send a broadcast message (no answer)
- if (RFIFOREST (fd) < 8
- || RFIFOREST (fd) < (8 + RFIFOL (fd, 4)))
+ if (RFIFOREST(fd) < 8
+ || RFIFOREST(fd) < (8 + RFIFOL(fd, 4)))
return;
- if (RFIFOL (fd, 4) < 1)
- char_log
- ("Receiving a message for broadcast, but message is void.\n");
+ if (RFIFOL(fd, 4) < 1)
+ CHAR_LOG("Receiving a message for broadcast, but message is void.\n");
else
{
int i;
@@ -1967,173 +1436,149 @@ void parse_tologin (int fd)
if (server_fd[i] >= 0)
break;
if (i == MAX_MAP_SERVERS)
- char_log
- ("'ladmin': Receiving a message for broadcast, but no map-server is online.\n");
+ CHAR_LOG("'ladmin': Receiving a message for broadcast, but no map-server is online.\n");
else
{
uint8_t buf[128];
- char message[RFIFOL (fd, 4) + 1]; // +1 to add a null terminated if not exist in the packet
- int lp;
+ char message[RFIFOL(fd, 4) + 1]; // +1 to add a null terminated if not exist in the packet
+ int lp;
char *p;
- memset (message, '\0', sizeof (message));
- memcpy (message, RFIFOP (fd, 8), RFIFOL (fd, 4));
- message[sizeof (message) - 1] = '\0';
- remove_control_chars (message);
+ memset(message, '\0', sizeof(message));
+ memcpy(message, RFIFOP(fd, 8), RFIFOL(fd, 4));
+ message[sizeof(message) - 1] = '\0';
+ remove_control_chars(message);
// remove all first spaces
p = message;
while (p[0] == ' ')
p++;
// if message is only composed of spaces
if (p[0] == '\0')
- char_log
- ("Receiving a message for broadcast, but message is only a lot of spaces.\n");
+ CHAR_LOG("Receiving a message for broadcast, but message is only a lot of spaces.\n");
// else send message to all map-servers
else
{
- if (RFIFOW (fd, 2) == 0)
+ if (RFIFOW(fd, 2) == 0)
{
- char_log
- ("'ladmin': Receiving a message for broadcast (message (in yellow): %s)\n",
- message);
+ const char *message_ptr = message;
+ CHAR_LOG("'ladmin': Receiving a message for broadcast (message (in yellow): %s)\n",
+ message_ptr);
lp = 4;
}
else
{
- char_log
- ("'ladmin': Receiving a message for broadcast (message (in blue): %s)\n",
- message);
+ const char *message_ptr = message;
+ CHAR_LOG("'ladmin': Receiving a message for broadcast (message (in blue): %s)\n",
+ message_ptr);
lp = 8;
}
- // split message to max 80 char
- while (p[0] != '\0')
- { // if not finish
- if (p[0] == ' ') // jump if first char is a space
- p++;
- else
- {
- char split[80];
- char *last_space;
- sscanf (p, "%79[^\t]", split); // max 79 char, any char (\t is control char and control char was removed before)
- split[sizeof (split) - 1] = '\0'; // last char always \0
- if ((last_space =
- strrchr (split, ' ')) != NULL)
- { // searching space from end of the string
- last_space[0] = '\0'; // replace it by NULL to have correct length of split
- p++; // to jump the new NULL
- }
- p += strlen (split);
- // send broadcast to all map-servers
- WBUFW (buf, 0) = 0x3800;
- WBUFW (buf, 2) = lp + strlen (split) + 1;
- WBUFL (buf, 4) = 0x65756c62; // only write if in blue (lp = 8)
- memcpy (WBUFP (buf, lp), split,
- strlen (split) + 1);
- mapif_sendall (buf, WBUFW (buf, 2));
- }
- }
+ // send broadcast to all map-servers
+ WBUFW(buf, 0) = 0x3800;
+ WBUFW(buf, 2) = lp + sizeof(message);
+ WBUFL(buf, 4) = 0x65756c62; // only write if in blue (lp = 8)
+ memcpy(WBUFP(buf, lp), message, sizeof(message));
+ mapif_sendall(buf, WBUFW(buf, 2));
}
}
}
- RFIFOSKIP (fd, 8 + RFIFOL (fd, 4));
+ RFIFOSKIP(fd, 8 + RFIFOL(fd, 4));
break;
// account_reg2変更通知
case 0x2729:
- if (RFIFOREST (fd) < 4 || RFIFOREST (fd) < RFIFOW (fd, 2))
+ if (RFIFOREST(fd) < 4 || RFIFOREST(fd) < RFIFOW(fd, 2))
return;
{
struct global_reg reg[ACCOUNT_REG2_NUM];
unsigned char buf[4096];
- int j, p, acc;
- acc = RFIFOL (fd, 4);
+ int j, p, acc;
+ acc = RFIFOL(fd, 4);
for (p = 8, j = 0;
- p < RFIFOW (fd, 2) && j < ACCOUNT_REG2_NUM;
+ 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);
+ memcpy(reg[j].str, RFIFOP(fd, p), 32);
+ reg[j].value = RFIFOL(fd, p + 32);
}
- set_account_reg2 (acc, j, reg);
+ 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");
+ 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;
case 0x7924:
{ // [Fate] Itemfrob package: forwarded from login-server
- if (RFIFOREST (fd) < 10)
+ if (RFIFOREST(fd) < 10)
return;
- int source_id = RFIFOL (fd, 2);
- int dest_id = RFIFOL (fd, 6);
+ int source_id = RFIFOL(fd, 2);
+ int dest_id = RFIFOL(fd, 6);
unsigned char buf[10];
- WBUFW (buf, 0) = 0x2afa;
- WBUFL (buf, 2) = source_id;
- WBUFL (buf, 6) = dest_id;
+ WBUFW(buf, 0) = 0x2afa;
+ WBUFL(buf, 2) = source_id;
+ WBUFL(buf, 6) = dest_id;
- mapif_sendall (buf, 10); // forward package to map servers
+ mapif_sendall(buf, 10); // forward package to map servers
for (int i = 0; i < char_num; i++)
{
struct mmo_charstatus *c = char_dat + i;
- struct storage *s = account2storage (c->account_id);
- int changes = 0;
- int j;
+ struct storage *s = account2storage(c->account_id);
+ int changes = 0;
+ int j;
#define FIX(v) if (v == source_id) {v = dest_id; ++changes; }
for (j = 0; j < MAX_INVENTORY; j++)
- FIX (c->inventory[j].nameid);
+ FIX(c->inventory[j].nameid);
for (j = 0; j < MAX_CART; j++)
- FIX (c->cart[j].nameid);
- FIX (c->weapon);
- FIX (c->shield);
- FIX (c->head_top);
- FIX (c->head_mid);
- FIX (c->head_bottom);
+ FIX(c->cart[j].nameid);
+ // FIX(c->weapon);
+ FIX(c->shield);
+ FIX(c->head_top);
+ FIX(c->head_mid);
+ FIX(c->head_bottom);
if (s)
for (j = 0; j < s->storage_amount; j++)
- FIX (s->storage_[j].nameid);
+ FIX(s->storage_[j].nameid);
#undef FIX
if (changes)
- char_log
- ("itemfrob(%d -> %d): `%s'(%d, account %d): changed %d times\n",
+ CHAR_LOG("itemfrob(%d -> %d): `%s'(%d, account %d): changed %d times\n",
source_id, dest_id, c->name, c->char_id,
c->account_id, changes);
}
- mmo_char_sync ();
- inter_storage_save ();
- RFIFOSKIP (fd, 10);
+ mmo_char_sync();
+ inter_storage_save();
+ RFIFOSKIP(fd, 10);
break;
}
// Account deletion notification (from login-server)
case 0x2730:
- if (RFIFOREST (fd) < 6)
+ if (RFIFOREST(fd) < 6)
return;
// Deletion of all characters of the account
for (int i = 0; i < char_num; i++)
{
- if (char_dat[i].account_id == RFIFOL (fd, 2))
+ if (char_dat[i].account_id == RFIFOL(fd, 2))
{
- char_delete (&char_dat[i]);
+ char_delete(&char_dat[i]);
if (i < char_num - 1)
{
- memcpy (&char_dat[i], &char_dat[char_num - 1],
- sizeof (struct mmo_charstatus));
+ memcpy(&char_dat[i], &char_dat[char_num - 1],
+ sizeof(struct mmo_charstatus));
// if moved character owns to deleted account, check again it's character
- if (char_dat[i].account_id == RFIFOL (fd, 2))
+ if (char_dat[i].account_id == RFIFOL(fd, 2))
{
i--;
// Correct moved character reference in the character's owner by [Yor]
}
else
{
- int j, k;
+ int j, k;
struct char_session_data *sd2;
for (j = 0; j < fd_max; j++)
{
@@ -2160,76 +1605,74 @@ void parse_tologin (int fd)
}
}
// Deletion of the storage
- inter_storage_delete (RFIFOL (fd, 2));
+ inter_storage_delete(RFIFOL(fd, 2));
// send to all map-servers to disconnect the player
{
unsigned char buf[6];
- WBUFW (buf, 0) = 0x2b13;
- WBUFL (buf, 2) = RFIFOL (fd, 2);
- mapif_sendall (buf, 6);
+ WBUFW(buf, 0) = 0x2b13;
+ WBUFL(buf, 2) = RFIFOL(fd, 2);
+ mapif_sendall(buf, 6);
}
// disconnect player if online on char-server
- disconnect_player (RFIFOL (fd, 2));
- RFIFOSKIP (fd, 6);
+ disconnect_player(RFIFOL(fd, 2));
+ RFIFOSKIP(fd, 6);
break;
// State change of account/ban notification (from login-server) by [Yor]
case 0x2731:
- if (RFIFOREST (fd) < 11)
+ if (RFIFOREST(fd) < 11)
return;
// send to all map-servers to disconnect the player
{
unsigned char buf[11];
- 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);
+ 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
- disconnect_player (RFIFOL (fd, 2));
- RFIFOSKIP (fd, 11);
+ disconnect_player(RFIFOL(fd, 2));
+ RFIFOSKIP(fd, 11);
break;
// Receiving GM acounts info from login-server (by [Yor])
case 0x2732:
- if (RFIFOREST (fd) < 4 || RFIFOREST (fd) < RFIFOW (fd, 2))
+ if (RFIFOREST(fd) < 4 || RFIFOREST(fd) < RFIFOW(fd, 2))
return;
{
uint8_t buf[32000];
if (gm_account != NULL)
- free (gm_account);
- CREATE (gm_account, struct gm_account, (RFIFOW (fd, 2) - 4) / 5);
+ free(gm_account);
+ CREATE(gm_account, struct gm_account, (RFIFOW(fd, 2) - 4) / 5);
GM_num = 0;
- for (int i = 4; i < RFIFOW (fd, 2); i = i + 5)
+ for (int i = 4; i < RFIFOW(fd, 2); i = i + 5)
{
- gm_account[GM_num].account_id = RFIFOL (fd, i);
- gm_account[GM_num].level = (int) RFIFOB (fd, i + 4);
- //printf("GM account: %d -> level %d\n", gm_account[GM_num].account_id, gm_account[GM_num].level);
+ gm_account[GM_num].account_id = RFIFOL(fd, i);
+ gm_account[GM_num].level = (int) RFIFOB(fd, i + 4);
+ //PRINTF("GM account: %d -> level %d\n", gm_account[GM_num].account_id, gm_account[GM_num].level);
GM_num++;
}
- printf
- ("From login-server: receiving of %d GM accounts information.\n",
+ PRINTF("From login-server: receiving of %d GM accounts information.\n",
GM_num);
- char_log
- ("From login-server: receiving of %d GM accounts information.\n",
+ CHAR_LOG("From login-server: receiving of %d GM accounts information.\n",
GM_num);
- create_online_files (); // update online players files (perhaps some online players change of GM level)
+ create_online_files(); // update online players files (perhaps some online players change of GM level)
// send new gm acccounts level to map-servers
- memcpy (buf, RFIFOP (fd, 0), RFIFOW (fd, 2));
- WBUFW (buf, 0) = 0x2b15;
- mapif_sendall (buf, RFIFOW (fd, 2));
+ memcpy(buf, RFIFOP(fd, 0), RFIFOW(fd, 2));
+ WBUFW(buf, 0) = 0x2b15;
+ mapif_sendall(buf, RFIFOW(fd, 2));
}
- RFIFOSKIP (fd, RFIFOW (fd, 2));
+ RFIFOSKIP(fd, RFIFOW(fd, 2));
break;
case 0x2741: // change password reply
- if (RFIFOREST (fd) < 7)
+ if (RFIFOREST(fd) < 7)
return;
{
- int acc, status, i;
- acc = RFIFOL (fd, 2);
- status = RFIFOB (fd, 6);
+ int acc, status, i;
+ acc = RFIFOL(fd, 2);
+ status = RFIFOB(fd, 6);
for (i = 0; i < fd_max; i++)
{
@@ -2237,15 +1680,15 @@ void parse_tologin (int fd)
{
if (sd->account_id == acc)
{
- WFIFOW (i, 0) = 0x62;
- WFIFOB (i, 2) = status;
- WFIFOSET (i, 3);
+ WFIFOW(i, 0) = 0x62;
+ WFIFOB(i, 2) = status;
+ WFIFOSET(i, 3);
break;
}
}
}
}
- RFIFOSKIP (fd, 7);
+ RFIFOSKIP(fd, 7);
break;
default:
@@ -2253,30 +1696,27 @@ void parse_tologin (int fd)
return;
}
}
- RFIFOFLUSH (fd);
}
//--------------------------------
// Map-server anti-freeze system
//--------------------------------
static
-void map_anti_freeze_system (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data)
+void map_anti_freeze_system(TimerData *, tick_t)
{
- int i;
+ int i;
- //printf("Entering in map_anti_freeze_system function to check freeze of servers.\n");
+ //PRINTF("Entering in map_anti_freeze_system function to check freeze of servers.\n");
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]);
+ //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 freezed -> disconnection.\n",
+ PRINTF("Map-server anti-freeze system: char-server #%d is freezed -> disconnection.\n",
i);
- char_log
- ("Map-server anti-freeze system: char-server #%d is freezed -> disconnection.\n",
+ CHAR_LOG("Map-server anti-freeze system: char-server #%d is freezed -> disconnection.\n",
i);
session[server_fd[i]]->eof = 1;
}
@@ -2285,10 +1725,10 @@ void map_anti_freeze_system (timer_id tid, tick_t tick, custom_id_t id, custom_d
}
static
-void parse_frommap (int fd)
+void parse_frommap(int fd)
{
- int i, j;
- int id;
+ int i, j;
+ int id;
for (id = 0; id < MAX_MAP_SERVERS; id++)
if (server_fd[id] == fd)
@@ -2297,162 +1737,155 @@ void parse_frommap (int fd)
{
if (id < MAX_MAP_SERVERS)
{
- printf ("Map-server %d (session #%d) has disconnected.\n", id,
+ PRINTF("Map-server %d (session #%d) has disconnected.\n", id,
fd);
- memset (&server[id], 0, sizeof (struct mmo_map_server));
+ memset(&server[id], 0, sizeof(struct mmo_map_server));
server_fd[id] = -1;
for (j = 0; j < char_num; j++)
if (online_chars[j] == fd)
online_chars[j] = -1;
- create_online_files (); // update online players files (to remove all online players of this server)
+ create_online_files(); // update online players files (to remove all online players of this server)
}
- close (fd);
- delete_session (fd);
+ delete_session(fd);
return;
}
- while (RFIFOREST (fd) >= 2)
+ while (RFIFOREST(fd) >= 2)
{
-// printf("parse_frommap: connection #%d, packet: 0x%x (with being read: %d bytes).\n", fd, RFIFOW(fd,0), RFIFOREST(fd));
+// PRINTF("parse_frommap: connection #%d, packet: 0x%x (with being read: %d bytes).\n", fd, RFIFOW(fd,0), RFIFOREST(fd));
- switch (RFIFOW (fd, 0))
+ switch (RFIFOW(fd, 0))
{
// request from map-server to reload GM accounts. Transmission to login-server (by Yor)
case 0x2af7:
if (login_fd > 0)
{ // don't send request if no login-server
- WFIFOW (login_fd, 0) = 0x2709;
- WFIFOSET (login_fd, 2);
-// printf("char : request from map-server to reload GM accounts -> login-server.\n");
+ WFIFOW(login_fd, 0) = 0x2709;
+ WFIFOSET(login_fd, 2);
+// PRINTF("char : request from map-server to reload GM accounts -> login-server.\n");
}
- RFIFOSKIP (fd, 2);
+ RFIFOSKIP(fd, 2);
break;
// Receiving map names list from the map-server
case 0x2afa:
- if (RFIFOREST (fd) < 4 || RFIFOREST (fd) < RFIFOW (fd, 2))
+ if (RFIFOREST(fd) < 4 || RFIFOREST(fd) < RFIFOW(fd, 2))
return;
- memset (server[id].map, 0, sizeof (server[id].map));
+ memset(server[id].map, 0, sizeof(server[id].map));
j = 0;
- for (i = 4; i < RFIFOW (fd, 2); i += 16)
+ 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]);
+ memcpy(server[id].map[j], RFIFOP(fd, i), 16);
+// PRINTF("set map %d.%d : %s\n", id, j, server[id].map[j]);
j++;
}
{
unsigned char *p = (unsigned char *) &server[id].ip;
- printf
- ("Map-Server %d connected: %d maps, from IP %d.%d.%d.%d port %d.\n",
+ 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);
- char_log
- ("Map-Server %d connected: %d maps, from IP %d.%d.%d.%d port %d. Map-server %d loading complete.\n",
+ PRINTF("Map-server %d loading complete.\n", id);
+ CHAR_LOG("Map-Server %d connected: %d maps, from IP %d.%d.%d.%d port %d. Map-server %d loading complete.\n",
id, j, p[0], p[1], p[2], p[3],
server[id].port, 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);
+ 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;
+ int x;
if (j == 0)
{
- printf ("WARNING: Map-Server %d have NO map.\n", id);
- char_log ("WARNING: Map-Server %d have NO map.\n",
+ PRINTF("WARNING: Map-Server %d have NO map.\n", id);
+ CHAR_LOG("WARNING: Map-Server %d have NO map.\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));
+ 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;
+ 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),
+ 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));
+ WFIFOW(fd, 2) = j * 16 + 10;
+ WFIFOSET(fd, WFIFOW(fd, 2));
}
}
}
}
- RFIFOSKIP (fd, RFIFOW (fd, 2));
+ RFIFOSKIP(fd, RFIFOW(fd, 2));
break;
// èªè¨¼è¦æ±‚
case 0x2afc:
- if (RFIFOREST (fd) < 22)
+ if (RFIFOREST(fd) < 22)
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));
+ //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++)
{
- 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
+ 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) &&
// 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].login_id2 == RFIFOL(fd, 14) || RFIFOL(fd, 14) == 0) && // relate to the versions higher than 18
+ (!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) = 18 + 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;
+ WFIFOW(fd, 0) = 0x2afd;
+ WFIFOW(fd, 2) = 18 + sizeof(struct mmo_charstatus);
+ WFIFOL(fd, 4) = RFIFOL(fd, 2);
+ WFIFOL(fd, 8) = auth_fifo[i].login_id2;
+ WFIFOL(fd, 12) = static_cast<time_t>(auth_fifo[i].connect_until_time);
char_dat[auth_fifo[i].char_pos].sex =
auth_fifo[i].sex;
- WFIFOW (fd, 16) = auth_fifo[i].packet_tmw_version;
- fprintf (stderr,
+ WFIFOW(fd, 16) = auth_fifo[i].packet_tmw_version;
+ FPRINTF(stderr,
"From queue index %d: recalling packet version %d\n",
i, auth_fifo[i].packet_tmw_version);
- memcpy (WFIFOP (fd, 18),
+ memcpy(WFIFOP(fd, 18),
&char_dat[auth_fifo[i].char_pos],
- 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));
+ 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_fifo search error! account %d not authentified.\n",
- RFIFOL (fd, 2));
+ WFIFOW(fd, 0) = 0x2afe;
+ WFIFOL(fd, 2) = RFIFOL(fd, 2);
+ WFIFOSET(fd, 6);
+ PRINTF("auth_fifo search error! account %d not authentified.\n",
+ RFIFOL(fd, 2));
}
- RFIFOSKIP (fd, 22);
+ RFIFOSKIP(fd, 22);
break;
// MAPサーãƒãƒ¼ä¸Šã®ãƒ¦ãƒ¼ã‚¶ãƒ¼æ•°å—ä¿¡
case 0x2aff:
- if (RFIFOREST (fd) < 6 || RFIFOREST (fd) < RFIFOW (fd, 2))
+ if (RFIFOREST(fd) < 6 || RFIFOREST(fd) < RFIFOW(fd, 2))
return;
- server[id].users = 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
// remove all previously online players of the server
@@ -2462,283 +1895,285 @@ void parse_frommap (int fd)
// add online players in the list by [Yor]
for (i = 0; i < server[id].users; i++)
{
- int char_id = RFIFOL (fd, 6 + i * 4);
+ int char_id = RFIFOL(fd, 6 + i * 4);
for (j = 0; j < char_num; j++)
if (char_dat[j].char_id == char_id)
{
online_chars[j] = id;
- //printf("%d\n", char_id);
+ //PRINTF("%d\n", char_id);
break;
}
}
- if (update_online < time (NULL))
- { // Time is done
- update_online = time (NULL) + 8;
- create_online_files (); // only every 8 sec. (normally, 1 server send users every 5 sec.) Don't update every time, because that takes time, but only every 2 connection.
+ if (update_online < TimeT::now())
+ {
+ // Time is done
+ update_online = static_cast<time_t>(TimeT::now()) + 8;
+ create_online_files();
+ // only every 8 sec. (normally, 1 server send users every 5 sec.) Don't update every time, because that takes time, but only every 2 connection.
// it set to 8 sec because is more than 5 (sec) and if we have more than 1 map-server, informations can be received in shifted.
}
- RFIFOSKIP (fd, 6 + i * 4);
+ RFIFOSKIP(fd, 6 + i * 4);
break;
// キャラデータä¿å­˜
case 0x2b01:
- if (RFIFOREST (fd) < 4 || RFIFOREST (fd) < RFIFOW (fd, 2))
+ if (RFIFOREST(fd) < 4 || RFIFOREST(fd) < RFIFOW(fd, 2))
return;
for (i = 0; i < char_num; i++)
{
- if (char_dat[i].account_id == RFIFOL (fd, 4) &&
- char_dat[i].char_id == RFIFOL (fd, 8))
+ if (char_dat[i].account_id == RFIFOL(fd, 4) &&
+ char_dat[i].char_id == RFIFOL(fd, 8))
break;
}
if (i != char_num)
- memcpy (&char_dat[i], RFIFOP (fd, 12),
- sizeof (struct mmo_charstatus));
- RFIFOSKIP (fd, RFIFOW (fd, 2));
+ memcpy(&char_dat[i], RFIFOP(fd, 12),
+ sizeof(struct mmo_charstatus));
+ RFIFOSKIP(fd, RFIFOW(fd, 2));
break;
// キャラセレè¦æ±‚
case 0x2b02:
- if (RFIFOREST (fd) < 18)
+ if (RFIFOREST(fd) < 18)
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));
- auth_fifo[auth_fifo_pos].account_id = RFIFOL (fd, 2);
+ //PRINTF("auth_fifo set (auth #%d) - account: %d, secure: %08x-%08x\n", auth_fifo_pos, RFIFOL(fd,2), RFIFOL(fd,6), RFIFOL(fd,10));
+ 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].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[auth_fifo_pos].connect_until_time = TimeT(); // 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);
+ WFIFOW(fd, 0) = 0x2b03;
+ WFIFOL(fd, 2) = RFIFOL(fd, 2);
+ WFIFOB(fd, 6) = 0;
+ WFIFOSET(fd, 7);
+ RFIFOSKIP(fd, 18);
break;
// マップサーãƒãƒ¼é–“移動è¦æ±‚
case 0x2b05:
- if (RFIFOREST (fd) < 49)
+ if (RFIFOREST(fd) < 49)
return;
if (auth_fifo_pos >= AUTH_FIFO_SIZE)
auth_fifo_pos = 0;
- WFIFOW (fd, 0) = 0x2b06;
- memcpy (WFIFOP (fd, 2), RFIFOP (fd, 2), 42);
- //printf("auth_fifo set (auth#%d) - account: %d, secure: 0x%08x-0x%08x\n", auth_fifo_pos, RFIFOL(fd,2), RFIFOL(fd,6), RFIFOL(fd,10));
- auth_fifo[auth_fifo_pos].account_id = RFIFOL (fd, 2);
- auth_fifo[auth_fifo_pos].char_id = RFIFOL (fd, 14);
- auth_fifo[auth_fifo_pos].login_id1 = RFIFOL (fd, 6);
- auth_fifo[auth_fifo_pos].login_id2 = RFIFOL (fd, 10);
+ WFIFOW(fd, 0) = 0x2b06;
+ memcpy(WFIFOP(fd, 2), RFIFOP(fd, 2), 42);
+ //PRINTF("auth_fifo set (auth#%d) - account: %d, secure: 0x%08x-0x%08x\n", auth_fifo_pos, RFIFOL(fd,2), RFIFOL(fd,6), RFIFOL(fd,10));
+ auth_fifo[auth_fifo_pos].account_id = RFIFOL(fd, 2);
+ auth_fifo[auth_fifo_pos].char_id = RFIFOL(fd, 14);
+ 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 = 0;
- auth_fifo[auth_fifo_pos].sex = RFIFOB (fd, 44);
- 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, 45);
+ auth_fifo[auth_fifo_pos].sex = RFIFOB(fd, 44);
+ auth_fifo[auth_fifo_pos].connect_until_time = TimeT(); // unlimited/unknown time by default (not display in map-server)
+ auth_fifo[auth_fifo_pos].ip = RFIFOL(fd, 45);
for (i = 0; i < char_num; i++)
- if (char_dat[i].account_id == RFIFOL (fd, 2) &&
- char_dat[i].char_id == RFIFOL (fd, 14))
+ if (char_dat[i].account_id == RFIFOL(fd, 2) &&
+ char_dat[i].char_id == RFIFOL(fd, 14))
{
auth_fifo[auth_fifo_pos].char_pos = i;
auth_fifo_pos++;
- WFIFOL (fd, 6) = 0;
+ WFIFOL(fd, 6) = 0;
break;
}
if (i == char_num)
- WFIFOW (fd, 6) = 1;
- WFIFOSET (fd, 44);
- RFIFOSKIP (fd, 49);
+ WFIFOW(fd, 6) = 1;
+ WFIFOSET(fd, 44);
+ RFIFOSKIP(fd, 49);
break;
// キャラå検索
case 0x2b08:
- if (RFIFOREST (fd) < 6)
+ if (RFIFOREST(fd) < 6)
return;
for (i = 0; i < char_num; i++)
{
- if (char_dat[i].char_id == RFIFOL (fd, 2))
+ if (char_dat[i].char_id == RFIFOL(fd, 2))
break;
}
- WFIFOW (fd, 0) = 0x2b09;
- WFIFOL (fd, 2) = RFIFOL (fd, 2);
+ WFIFOW(fd, 0) = 0x2b09;
+ WFIFOL(fd, 2) = RFIFOL(fd, 2);
if (i != char_num)
- memcpy (WFIFOP (fd, 6), char_dat[i].name, 24);
+ memcpy(WFIFOP(fd, 6), char_dat[i].name, 24);
else
- memcpy (WFIFOP (fd, 6), unknown_char_name, 24);
- WFIFOSET (fd, 30);
- RFIFOSKIP (fd, 6);
+ memcpy(WFIFOP(fd, 6), unknown_char_name, 24);
+ WFIFOSET(fd, 30);
+ RFIFOSKIP(fd, 6);
break;
// it is a request to become GM
case 0x2b0a:
- if (RFIFOREST (fd) < 4 || RFIFOREST (fd) < RFIFOW (fd, 2))
+ if (RFIFOREST(fd) < 4 || RFIFOREST(fd) < RFIFOW(fd, 2))
return;
-// printf("parse_frommap: change gm -> login, account: %d, pass: '%s'.\n", RFIFOL(fd,4), RFIFOP(fd,8));
+// 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
- WFIFOW (login_fd, 0) = 0x2720;
- memcpy (WFIFOP (login_fd, 2), RFIFOP (fd, 2),
- RFIFOW (fd, 2) - 2);
- WFIFOSET (login_fd, RFIFOW (fd, 2));
+ WFIFOW(login_fd, 0) = 0x2720;
+ memcpy(WFIFOP(login_fd, 2), RFIFOP(fd, 2),
+ RFIFOW(fd, 2) - 2);
+ WFIFOSET(login_fd, RFIFOW(fd, 2));
}
else
{
- WFIFOW (fd, 0) = 0x2b0b;
- WFIFOL (fd, 2) = RFIFOL (fd, 4);
- WFIFOL (fd, 6) = 0;
- WFIFOSET (fd, 10);
+ WFIFOW(fd, 0) = 0x2b0b;
+ WFIFOL(fd, 2) = RFIFOL(fd, 4);
+ WFIFOL(fd, 6) = 0;
+ WFIFOSET(fd, 10);
}
- RFIFOSKIP (fd, RFIFOW (fd, 2));
+ RFIFOSKIP(fd, RFIFOW(fd, 2));
break;
// Map server send information to change an email of an account -> login-server
case 0x2b0c:
- if (RFIFOREST (fd) < 86)
+ if (RFIFOREST(fd) < 86)
return;
if (login_fd > 0)
{ // don't send request if no login-server
- memcpy (WFIFOP (login_fd, 0), RFIFOP (fd, 0), 86); // 0x2722 <account_id>.L <actual_e-mail>.40B <new_e-mail>.40B
- WFIFOW (login_fd, 0) = 0x2722;
- WFIFOSET (login_fd, 86);
+ memcpy(WFIFOP(login_fd, 0), RFIFOP(fd, 0), 86); // 0x2722 <account_id>.L <actual_e-mail>.40B <new_e-mail>.40B
+ WFIFOW(login_fd, 0) = 0x2722;
+ WFIFOSET(login_fd, 86);
}
- RFIFOSKIP (fd, 86);
+ RFIFOSKIP(fd, 86);
break;
// 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)
+ if (RFIFOREST(fd) < 44)
return;
{
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';
+ 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, 5-changesex
+ 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, 5-changesex
// search character
- i = search_character_index (character_name);
+ i = search_character_index(character_name);
if (i >= 0)
{
- memcpy (WFIFOP (fd, 6), search_character_name (i), 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))
+ memcpy(WFIFOP(fd, 6), search_character_name(i), 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 (char_dat[i].account_id))
+ || isGM(acc) >=
+ isGM(char_dat[i].account_id))
{
if (login_fd > 0)
{ // don't send request if no login-server
- WFIFOW (login_fd, 0) = 0x2724;
- WFIFOL (login_fd, 2) = char_dat[i].account_id; // 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);
+ WFIFOW(login_fd, 0) = 0x2724;
+ WFIFOL(login_fd, 2) = char_dat[i].account_id; // 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
+ 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
+ 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 (char_dat[i].account_id))
+ || isGM(acc) >=
+ isGM(char_dat[i].account_id))
{
if (login_fd > 0)
{ // don't send request if no login-server
- WFIFOW (login_fd, 0) = 0x2725;
- WFIFOL (login_fd, 2) = char_dat[i].account_id; // 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",
+ WFIFOW(login_fd, 0) = 0x2725;
+ WFIFOL(login_fd, 2) = char_dat[i].account_id; // 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
+ 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
+ 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 (char_dat[i].account_id))
+ || isGM(acc) >=
+ isGM(char_dat[i].account_id))
{
if (login_fd > 0)
{ // don't send request if no login-server
- WFIFOW (login_fd, 0) = 0x2724;
- WFIFOL (login_fd, 2) = char_dat[i].account_id; // 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);
+ WFIFOW(login_fd, 0) = 0x2724;
+ WFIFOL(login_fd, 2) = char_dat[i].account_id; // 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
+ 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
+ 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 (char_dat[i].account_id))
+ || isGM(acc) >=
+ isGM(char_dat[i].account_id))
{
if (login_fd > 0)
{ // don't send request if no login-server
- WFIFOW (login_fd, 0) = 0x272a;
- WFIFOL (login_fd, 2) = char_dat[i].account_id; // account value
- WFIFOSET (login_fd, 6);
-// printf("char : status -> login: account %d, unban request\n", char_dat[i].account_id);
+ WFIFOW(login_fd, 0) = 0x272a;
+ WFIFOL(login_fd, 2) = char_dat[i].account_id; // 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
+ 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
+ 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 (char_dat[i].account_id))
+ || isGM(acc) >=
+ isGM(char_dat[i].account_id))
{
if (login_fd > 0)
{ // don't send request if no login-server
- WFIFOW (login_fd, 0) = 0x2727;
- WFIFOL (login_fd, 2) = char_dat[i].account_id; // account value
- WFIFOSET (login_fd, 6);
-// printf("char : status -> login: account %d, change sex request\n", char_dat[i].account_id);
+ WFIFOW(login_fd, 0) = 0x2727;
+ WFIFOL(login_fd, 2) = char_dat[i].account_id; // 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
+ 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
+ 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
+ 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);
+ WFIFOSET(fd, 34);
}
- RFIFOSKIP (fd, 44);
+ RFIFOSKIP(fd, 44);
break;
}
@@ -2746,50 +2181,50 @@ void parse_frommap (int fd)
// account_regä¿å­˜è¦æ±‚
case 0x2b10:
- if (RFIFOREST (fd) < 4 || RFIFOREST (fd) < RFIFOW (fd, 2))
+ if (RFIFOREST(fd) < 4 || RFIFOREST(fd) < RFIFOW(fd, 2))
return;
{
struct global_reg reg[ACCOUNT_REG2_NUM];
- int p, acc;
- acc = RFIFOL (fd, 4);
+ int p, acc;
+ acc = RFIFOL(fd, 4);
for (p = 8, j = 0;
- p < RFIFOW (fd, 2) && j < ACCOUNT_REG2_NUM;
+ 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);
+ memcpy(reg[j].str, RFIFOP(fd, p), 32);
+ reg[j].value = RFIFOL(fd, p + 32);
}
- set_account_reg2 (acc, j, reg);
+ set_account_reg2(acc, j, reg);
// loginサーãƒãƒ¼ã¸é€ã‚‹
if (login_fd > 0)
{ // don't send request if no login-server
- memcpy (WFIFOP (login_fd, 0), RFIFOP (fd, 0),
- RFIFOW (fd, 2));
- WFIFOW (login_fd, 0) = 0x2728;
- WFIFOSET (login_fd, WFIFOW (login_fd, 2));
+ memcpy(WFIFOP(login_fd, 0), RFIFOP(fd, 0),
+ RFIFOW(fd, 2));
+ WFIFOW(login_fd, 0) = 0x2728;
+ 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");
+ RFIFOSKIP(fd, RFIFOW(fd, 2));
+// PRINTF("char: save_account_reg (from map)\n");
break;
}
// Map server is requesting a divorce
case 0x2b16:
- if (RFIFOREST (fd) < 4)
+ if (RFIFOREST(fd) < 4)
return;
{
for (i = 0; i < char_num; i++)
- if (char_dat[i].char_id == RFIFOL (fd, 2))
+ if (char_dat[i].char_id == RFIFOL(fd, 2))
break;
if (i != char_num)
- char_divorce (&char_dat[i]);
+ char_divorce(&char_dat[i]);
- RFIFOSKIP (fd, 6);
+ RFIFOSKIP(fd, 6);
break;
}
@@ -2797,16 +2232,15 @@ void parse_frommap (int fd)
default:
// inter server処ç†ã«æ¸¡ã™
{
- int r = inter_parse_frommap (fd);
+ int r = inter_parse_frommap(fd);
if (r == 1) // 処ç†ã§ããŸ
break;
if (r == 2) // パケット長ãŒè¶³ã‚Šãªã„
return;
}
// inter server処ç†ã§ã‚‚ãªã„å ´åˆã¯åˆ‡æ–­
- printf
- ("char: unknown packet 0x%04x (%d bytes to read in buffer)! (from map).\n",
- RFIFOW (fd, 0), RFIFOREST (fd));
+ PRINTF("char: unknown packet 0x%04x (%zu bytes to read in buffer)! (from map).\n",
+ RFIFOW(fd, 0), RFIFOREST(fd));
session[fd]->eof = 1;
return;
}
@@ -2814,49 +2248,42 @@ void parse_frommap (int fd)
}
static
-int search_mapserver (const char *map)
+int search_mapserver(const char *map)
{
- int i, j;
+ int i, j;
char temp_map[16];
- int temp_map_len;
+ 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
+// PRINTF("Searching the map-server for map '%s'... ", map);
+ strzcpy(temp_map, map, sizeof(temp_map));
+ 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);
+ 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("%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);
+// PRINTF("found -> server #%d.\n", i);
return i;
}
-// printf("not found.\n");
+// PRINTF("not found.\n");
return -1;
}
-// char_mapifã®åˆæœŸåŒ–処ç†ï¼ˆç¾åœ¨ã¯inter_mapifåˆæœŸåŒ–ã®ã¿ï¼‰
-static int char_mapif_init (int fd)
-{
- return inter_mapif_init (fd);
-}
-
//-----------------------------------------------------
// Test to know if an IP come from LAN or WAN. by [Yor]
//-----------------------------------------------------
static
-int lan_ip_check (unsigned char *p)
+int lan_ip_check(unsigned char *p)
{
- int i;
- int lancheck = 1;
+ int i;
+ int lancheck = 1;
-// printf("lan_ip_check: to compare: %d.%d.%d.%d, network: %d.%d.%d.%d/%d.%d.%d.%d\n",
+// 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]);
@@ -2868,15 +2295,109 @@ int lan_ip_check (unsigned char *p)
break;
}
}
- printf ("LAN test (result): %s source\033[0m.\n",
+ PRINTF("LAN test (result): %s source\033[0m.\n",
(lancheck) ? "\033[1;36mLAN" : "\033[1;32mWAN");
return lancheck;
}
static
-void parse_char (int fd)
+void handle_x0066(int fd, struct char_session_data *sd, uint8_t rfifob_2, uint8_t *p)
+{
+ const char *ip = ip2str(session[fd]->client_addr.sin_addr);
+
+ // if we activated email creation and email is default email
+ if (email_creation != 0 && strcmp(sd->email, "a@a.com") == 0
+ && login_fd > 0)
+ { // to modify an e-mail, login-server must be online
+ WFIFOW(fd, 0) = 0x70;
+ WFIFOB(fd, 2) = 0; // 00 = Incorrect Email address
+ WFIFOSET(fd, 3);
+
+ // otherwise, load the character
+ }
+ else
+ {
+ int ch;
+ for (ch = 0; ch < 9; ch++)
+ if (sd->found_char[ch] >= 0
+ && char_dat[sd->found_char[ch]].char_num == rfifob_2)
+ break;
+ if (ch != 9)
+ {
+ CHAR_LOG("Character Selected, Account ID: %d, Character Slot: %d, Character Name: %s [%s]\n",
+ sd->account_id, rfifob_2,
+ char_dat[sd->found_char[ch]].name, ip);
+ // searching map server
+ int i = search_mapserver(char_dat[sd->found_char[ch]].last_point.map);
+ // if map is not found, we check major cities
+ if (i < 0)
+ {
+ int j;
+ // get first online server (with a map)
+ i = 0;
+ for (j = 0; j < MAX_MAP_SERVERS; j++)
+ if (server_fd[j] >= 0
+ && server[j].map[0][0])
+ { // change save point to one of map found on the server (the first)
+ i = j;
+ memcpy(char_dat[sd->found_char[ch]].last_point.map,
+ server[j].map[0], 16);
+ PRINTF("Map-server #%d found with a map: '%s'.\n",
+ j, server[j].map[0]);
+ // coordonates are unknown
+ break;
+ }
+ // if no map-server is connected, we send: server closed
+ if (j == MAX_MAP_SERVERS)
+ {
+ WFIFOW(fd, 0) = 0x81;
+ WFIFOB(fd, 2) = 1; // 01 = Server closed
+ WFIFOSET(fd, 3);
+ return;
+ }
+ }
+ WFIFOW(fd, 0) = 0x71;
+ WFIFOL(fd, 2) = char_dat[sd->found_char[ch]].char_id;
+ memcpy(WFIFOP(fd, 6),
+ char_dat[sd->found_char[ch]].last_point.map,
+ 16);
+ PRINTF("Character selection '%s' (account: %d, slot: %d) [%s]\n",
+ char_dat[sd->found_char[ch]].name,
+ sd->account_id, ch, ip);
+ PRINTF("--Send IP of map-server. ");
+ 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 #%d - account %d, char: %d, secure: %08x-%08x\n", auth_fifo_pos, sd->account_id, char_dat[sd->found_char[ch]].char_id, sd->login_id1, sd->login_id2);
+ auth_fifo[auth_fifo_pos].account_id = sd->account_id;
+ auth_fifo[auth_fifo_pos].char_id =
+ char_dat[sd->found_char[ch]].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].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[auth_fifo_pos].packet_tmw_version =
+ sd->packet_tmw_version;
+ auth_fifo_pos++;
+ }
+ }
+}
+
+static
+void parse_char(int fd)
{
- int i, ch;
+ int i, ch;
char email[40];
struct char_session_data *sd;
unsigned char *p = (unsigned char *) &session[fd]->client_addr.sin_addr;
@@ -2885,74 +2406,70 @@ void parse_char (int fd)
{ // disconnect any player (already connected to char-server or coming back from map-server) if login-server is diconnected.
if (fd == login_fd)
login_fd = -1;
- close (fd);
- delete_session (fd);
+ delete_session(fd);
return;
}
sd = (struct char_session_data*)session[fd]->session_data;
- while (RFIFOREST (fd) >= 2)
+ while (RFIFOREST(fd) >= 2)
{
// if (RFIFOW(fd,0) < 30000)
-// printf("parse_char: connection #%d, packet: 0x%x (with being read: %d bytes).\n", fd, RFIFOW(fd,0), RFIFOREST(fd));
+// PRINTF("parse_char: connection #%d, packet: 0x%x (with being read: %d bytes).\n", fd, RFIFOW(fd,0), RFIFOREST(fd));
- switch (RFIFOW (fd, 0))
+ switch (RFIFOW(fd, 0))
{
case 0x20b: //20040622æš—å·åŒ–ragexe対応
- if (RFIFOREST (fd) < 19)
+ if (RFIFOREST(fd) < 19)
return;
- RFIFOSKIP (fd, 19);
+ RFIFOSKIP(fd, 19);
break;
case 0x61: // change password request
- if (RFIFOREST (fd) < 50)
+ if (RFIFOREST(fd) < 50)
return;
{
- WFIFOW (login_fd, 0) = 0x2740;
- WFIFOL (login_fd, 2) = sd->account_id;
- memcpy (WFIFOP (login_fd, 6), RFIFOP (fd, 2), 24);
- memcpy (WFIFOP (login_fd, 30), RFIFOP (fd, 26), 24);
- WFIFOSET (login_fd, 54);
+ WFIFOW(login_fd, 0) = 0x2740;
+ WFIFOL(login_fd, 2) = sd->account_id;
+ memcpy(WFIFOP(login_fd, 6), RFIFOP(fd, 2), 24);
+ memcpy(WFIFOP(login_fd, 30), RFIFOP(fd, 26), 24);
+ WFIFOSET(login_fd, 54);
}
- RFIFOSKIP (fd, 50);
+ RFIFOSKIP(fd, 50);
break;
case 0x65: // 接続è¦æ±‚
- if (RFIFOREST (fd) < 17)
+ if (RFIFOREST(fd) < 17)
return;
{
- int GM_value;
- if ((GM_value = isGM (RFIFOL (fd, 2))))
- printf
- ("Account Logged On; Account ID: %d (GM level %d).\n",
- RFIFOL (fd, 2), GM_value);
+ int GM_value;
+ if ((GM_value = isGM(RFIFOL(fd, 2))))
+ PRINTF("Account Logged On; Account ID: %d (GM level %d).\n",
+ RFIFOL(fd, 2), GM_value);
else
- printf ("Account Logged On; Account ID: %d.\n",
- RFIFOL (fd, 2));
+ PRINTF("Account Logged On; Account ID: %d.\n",
+ RFIFOL(fd, 2));
if (sd == NULL)
{
- CREATE (sd, struct char_session_data, 1);
+ 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)
+ 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 = TimeT(); // 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->packet_tmw_version = RFIFOW (fd, 14);
- sd->sex = RFIFOB (fd, 16);
+ sd->account_id = RFIFOL(fd, 2);
+ sd->login_id1 = RFIFOL(fd, 6);
+ sd->login_id2 = RFIFOL(fd, 10);
+ sd->packet_tmw_version = RFIFOW(fd, 14);
+ sd->sex = RFIFOB(fd, 16);
// send back account_id
- WFIFOL (fd, 0) = RFIFOL (fd, 2);
- WFIFOSET (fd, 4);
+ WFIFOL(fd, 0) = RFIFOL(fd, 2);
+ WFIFOSET(fd, 4);
// search authentification
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)
@@ -2960,27 +2477,27 @@ void parse_char (int fd)
{
auth_fifo[i].delflag = 1;
if (max_connect_user == 0
- || count_users () < max_connect_user)
+ || 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);
+ WFIFOW(login_fd, 0) = 0x2716;
+ WFIFOL(login_fd, 2) = sd->account_id;
+ WFIFOSET(login_fd, 6);
}
// Record client version
auth_fifo[i].packet_tmw_version =
sd->packet_tmw_version;
// send characters to player
- mmo_char_send006b (fd, sd);
+ mmo_char_send006b(fd, sd);
}
else
{
// refuse connection (over populated)
- WFIFOW (fd, 0) = 0x6c;
- WFIFOW (fd, 2) = 0;
- WFIFOSET (fd, 3);
+ WFIFOW(fd, 0) = 0x6c;
+ WFIFOB(fd, 2) = 0;
+ WFIFOSET(fd, 3);
}
break;
}
@@ -2990,259 +2507,93 @@ void parse_char (int fd)
{
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; // relate to the versions higher than 18
- WFIFOB (login_fd, 14) = sd->sex;
- WFIFOL (login_fd, 15) =
+ 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; // relate to the versions higher than 18
+ WFIFOB(login_fd, 14) = sd->sex;
+ WFIFOL(login_fd, 15) =
session[fd]->client_addr.sin_addr.s_addr;
- WFIFOSET (login_fd, 19);
+ WFIFOSET(login_fd, 19);
}
else
{ // if no login-server, we must refuse connection
- WFIFOW (fd, 0) = 0x6c;
- WFIFOW (fd, 2) = 0;
- WFIFOSET (fd, 3);
+ WFIFOW(fd, 0) = 0x6c;
+ WFIFOB(fd, 2) = 0;
+ WFIFOSET(fd, 3);
}
}
}
- RFIFOSKIP (fd, 17);
+ RFIFOSKIP(fd, 17);
break;
case 0x66: // キャラé¸æŠž
- if (!sd || RFIFOREST (fd) < 3)
+ if (!sd || RFIFOREST(fd) < 3)
return;
- {
- const char *ip = ip2str(session[fd]->client_addr.sin_addr);
-
- // if we activated email creation and email is default email
- if (email_creation != 0 && strcmp (sd->email, "a@a.com") == 0
- && login_fd > 0)
- { // to modify an e-mail, login-server must be online
- WFIFOW (fd, 0) = 0x70;
- WFIFOB (fd, 2) = 0; // 00 = Incorrect Email address
- WFIFOSET (fd, 3);
-
- // otherwise, load the character
- }
- else
- {
- for (ch = 0; ch < 9; ch++)
- if (sd->found_char[ch] >= 0
- && char_dat[sd->found_char[ch]].char_num ==
- RFIFOB (fd, 2))
- break;
- if (ch != 9)
- {
- char_log
- ("Character Selected, Account ID: %d, Character Slot: %d, Character Name: %s [%s]\n",
- sd->account_id, RFIFOB (fd, 2),
- char_dat[sd->found_char[ch]].name, ip);
- // searching map server
- i = search_mapserver (char_dat
- [sd->found_char[ch]].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
- [sd->found_char[ch]].last_point.map,
- "prontera.gat", 16);
- char_dat[sd->found_char[ch]].last_point.x = 273; // savepoint coordonates
- char_dat[sd->found_char[ch]].last_point.y =
- 354;
- }
- else if ((i =
- search_mapserver ("geffen.gat")) >= 0)
- { // check is done without 'gat'.
- memcpy (char_dat
- [sd->found_char[ch]].last_point.map,
- "geffen.gat", 16);
- char_dat[sd->found_char[ch]].last_point.x = 120; // savepoint coordonates
- char_dat[sd->found_char[ch]].last_point.y =
- 100;
- }
- else if ((i =
- search_mapserver ("morocc.gat")) >= 0)
- { // check is done without 'gat'.
- memcpy (char_dat
- [sd->found_char[ch]].last_point.map,
- "morocc.gat", 16);
- char_dat[sd->found_char[ch]].last_point.x = 160; // savepoint coordonates
- char_dat[sd->found_char[ch]].last_point.y =
- 94;
- }
- else if ((i =
- search_mapserver ("alberta.gat")) >= 0)
- { // check is done without 'gat'.
- memcpy (char_dat
- [sd->found_char[ch]].last_point.map,
- "alberta.gat", 16);
- char_dat[sd->found_char[ch]].last_point.x = 116; // savepoint coordonates
- char_dat[sd->found_char[ch]].last_point.y =
- 57;
- }
- else if ((i =
- search_mapserver ("payon.gat")) >= 0)
- { // check is done without 'gat'.
- memcpy (char_dat
- [sd->found_char[ch]].last_point.map,
- "payon.gat", 16);
- char_dat[sd->found_char[ch]].last_point.x = 87; // savepoint coordonates
- char_dat[sd->found_char[ch]].last_point.y =
- 117;
- }
- else if ((i =
- search_mapserver ("izlude.gat")) >= 0)
- { // check is done without 'gat'.
- memcpy (char_dat
- [sd->found_char[ch]].last_point.map,
- "izlude.gat", 16);
- char_dat[sd->found_char[ch]].last_point.x = 94; // savepoint coordonates
- char_dat[sd->found_char[ch]].last_point.y =
- 103;
- }
- else
- {
- int j;
- // get first online server (with a map)
- i = 0;
- for (j = 0; j < MAX_MAP_SERVERS; j++)
- if (server_fd[j] >= 0
- && server[j].map[0][0])
- { // change save point to one of map found on the server (the first)
- i = j;
- memcpy (char_dat
- [sd->
- found_char[ch]].last_point.
- map, server[j].map[0], 16);
- printf
- ("Map-server #%d found with a map: '%s'.\n",
- j, server[j].map[0]);
- // coordonates are unknown
- break;
- }
- // if no map-server is 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[sd->found_char[ch]].char_id;
- memcpy (WFIFOP (fd, 6),
- char_dat[sd->found_char[ch]].last_point.map,
- 16);
- printf
- ("Character selection '%s' (account: %d, slot: %d) [%s]\n",
- char_dat[sd->found_char[ch]].name,
- sd->account_id, ch, ip);
- printf ("--Send IP of map-server. ");
- 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 #%d - account %d, char: %d, secure: %08x-%08x\n", auth_fifo_pos, sd->account_id, char_dat[sd->found_char[ch]].char_id, sd->login_id1, sd->login_id2);
- auth_fifo[auth_fifo_pos].account_id = sd->account_id;
- auth_fifo[auth_fifo_pos].char_id =
- char_dat[sd->found_char[ch]].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].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[auth_fifo_pos].packet_tmw_version =
- sd->packet_tmw_version;
- auth_fifo_pos++;
- }
- }
- }
- RFIFOSKIP (fd, 3);
+ handle_x0066(fd, sd, RFIFOB(fd, 2), p);
+ RFIFOSKIP(fd, 3);
break;
case 0x67: // 作æˆ
- if (!sd || RFIFOREST (fd) < 37)
+ if (!sd || RFIFOREST(fd) < 37)
return;
- i = make_new_char (fd, RFIFOP (fd, 2));
+ i = make_new_char(fd, static_cast<const uint8_t *>(RFIFOP(fd, 2)));
if (i < 0)
{
- WFIFOW (fd, 0) = 0x6e;
- WFIFOB (fd, 2) = 0x00;
- WFIFOSET (fd, 3);
- RFIFOSKIP (fd, 37);
+ WFIFOW(fd, 0) = 0x6e;
+ WFIFOB(fd, 2) = 0x00;
+ WFIFOSET(fd, 3);
+ RFIFOSKIP(fd, 37);
break;
}
- WFIFOW (fd, 0) = 0x6d;
- memset (WFIFOP (fd, 2), 0, 106);
+ WFIFOW(fd, 0) = 0x6d;
+ memset(WFIFOP(fd, 2), 0, 106);
- 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) = 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;
+ 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) =
+ WFIFOW(fd, 2 + 40) = 0x30;
+ WFIFOW(fd, 2 + 42) =
(char_dat[i].hp > 0x7fff) ? 0x7fff : char_dat[i].hp;
- WFIFOW (fd, 2 + 44) =
+ WFIFOW(fd, 2 + 44) =
(char_dat[i].max_hp >
0x7fff) ? 0x7fff : char_dat[i].max_hp;
- WFIFOW (fd, 2 + 46) =
+ WFIFOW(fd, 2 + 46) =
(char_dat[i].sp > 0x7fff) ? 0x7fff : char_dat[i].sp;
- WFIFOW (fd, 2 + 48) =
+ 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].pc_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 > 255) ? 255 : char_dat[i].str;
- WFIFOB (fd, 2 + 99) =
- (char_dat[i].agi > 255) ? 255 : char_dat[i].agi;
- WFIFOB (fd, 2 + 100) =
- (char_dat[i].vit > 255) ? 255 : char_dat[i].vit;
- WFIFOB (fd, 2 + 101) =
- (char_dat[i].int_ > 255) ? 255 : char_dat[i].int_;
- WFIFOB (fd, 2 + 102) =
- (char_dat[i].dex > 255) ? 255 : char_dat[i].dex;
- WFIFOB (fd, 2 + 103) =
- (char_dat[i].luk > 255) ? 255 : char_dat[i].luk;
- WFIFOB (fd, 2 + 104) = char_dat[i].char_num;
-
- WFIFOSET (fd, 108);
- RFIFOSKIP (fd, 37);
+ WFIFOW(fd, 2 + 50) = static_cast<uint16_t>(DEFAULT_WALK_SPEED.count()); // char_dat[i].speed;
+ WFIFOW(fd, 2 + 52) = char_dat[i].species;
+ 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) = min(char_dat[i].attrs[ATTR::STR], 255);
+ WFIFOB(fd, 2 + 99) = min(char_dat[i].attrs[ATTR::AGI], 255);
+ WFIFOB(fd, 2 + 100) = min(char_dat[i].attrs[ATTR::VIT], 255);
+ WFIFOB(fd, 2 + 101) = min(char_dat[i].attrs[ATTR::INT], 255);
+ WFIFOB(fd, 2 + 102) = min(char_dat[i].attrs[ATTR::DEX], 255);
+ WFIFOB(fd, 2 + 103) = min(char_dat[i].attrs[ATTR::LUK], 255);
+ WFIFOB(fd, 2 + 104) = char_dat[i].char_num;
+
+ WFIFOSET(fd, 108);
+ RFIFOSKIP(fd, 37);
for (ch = 0; ch < 9; ch++)
{
if (sd->found_char[ch] == -1)
@@ -3251,25 +2602,26 @@ void parse_char (int fd)
break;
}
}
+ break;
case 0x68: // delete char //Yor's Fix
- if (!sd || RFIFOREST (fd) < 46)
+ if (!sd || RFIFOREST(fd) < 46)
return;
- memcpy (email, RFIFOP (fd, 6), 40);
- if (e_mail_check (email) == 0)
- strncpy (email, "a@a.com", 40); // default e-mail
+ memcpy(email, RFIFOP(fd, 6), 40);
+ if (e_mail_check(email) == 0)
+ strzcpy(email, "a@a.com", 40); // default e-mail
// if we activated email creation and email is default email
- if (email_creation != 0 && strcmp (sd->email, "a@a.com") == 0
+ if (email_creation != 0 && strcmp(sd->email, "a@a.com") == 0
&& login_fd > 0)
{ // to modify an e-mail, login-server must be online
// if sended email is incorrect e-mail
- if (strcmp (email, "a@a.com") == 0)
+ if (strcmp(email, "a@a.com") == 0)
{
- WFIFOW (fd, 0) = 0x70;
- WFIFOB (fd, 2) = 0; // 00 = Incorrect Email address
- WFIFOSET (fd, 3);
- RFIFOSKIP (fd, 46);
+ WFIFOW(fd, 0) = 0x70;
+ WFIFOB(fd, 2) = 0; // 00 = Incorrect Email address
+ WFIFOSET(fd, 3);
+ RFIFOSKIP(fd, 46);
// we act like we have selected a character
}
else
@@ -3277,30 +2629,25 @@ void parse_char (int fd)
// we change the packet to set it like selection.
for (i = 0; i < 9; i++)
if (char_dat[sd->found_char[i]].char_id ==
- RFIFOL (fd, 2))
+ RFIFOL(fd, 2))
{
// we save new e-mail
- memcpy (sd->email, email, 40);
+ memcpy(sd->email, email, 40);
// we send new e-mail to login-server ('online' login-server is checked before)
- WFIFOW (login_fd, 0) = 0x2715;
- WFIFOL (login_fd, 2) = sd->account_id;
- memcpy (WFIFOP (login_fd, 6), email, 40);
- WFIFOSET (login_fd, 46);
- // skip part of the packet! (46, but leave the size of select packet: 3)
- RFIFOSKIP (fd, 43);
- // change value to put new packet (char selection)
- RFIFOW (fd, 0) = 0x66;
- RFIFOB (fd, 2) =
- char_dat[sd->found_char[i]].char_num;
- // not send packet, it's modify of actual packet
+ WFIFOW(login_fd, 0) = 0x2715;
+ WFIFOL(login_fd, 2) = sd->account_id;
+ memcpy(WFIFOP(login_fd, 6), email, 40);
+ WFIFOSET(login_fd, 46);
+ RFIFOSKIP(fd, 46);
+ handle_x0066(fd, sd, char_dat[sd->found_char[i]].char_num, p);
break;
}
if (i == 9)
{
- WFIFOW (fd, 0) = 0x70;
- WFIFOB (fd, 2) = 0; // 00 = Incorrect Email address
- WFIFOSET (fd, 3);
- RFIFOSKIP (fd, 46);
+ WFIFOW(fd, 0) = 0x70;
+ WFIFOB(fd, 2) = 0; // 00 = Incorrect Email address
+ WFIFOSET(fd, 3);
+ RFIFOSKIP(fd, 46);
}
}
@@ -3320,18 +2667,18 @@ void parse_char (int fd)
if (sd->found_char[i] >= 0
&& (cs =
&char_dat[sd->found_char[i]])->char_id ==
- RFIFOL (fd, 2))
+ RFIFOL(fd, 2))
{
- char_delete (cs); // deletion process
+ char_delete(cs); // deletion process
if (sd->found_char[i] != char_num - 1)
{
- memcpy (&char_dat[sd->found_char[i]],
+ memcpy(&char_dat[sd->found_char[i]],
&char_dat[char_num - 1],
- sizeof (struct mmo_charstatus));
+ sizeof(struct mmo_charstatus));
// Correct moved character reference in the character's owner
{
- int j, k;
+ int j, k;
struct char_session_data *sd2;
for (j = 0; j < fd_max; j++)
{
@@ -3361,89 +2708,88 @@ void parse_char (int fd)
for (ch = i; ch < 9 - 1; ch++)
sd->found_char[ch] = sd->found_char[ch + 1];
sd->found_char[8] = -1;
- WFIFOW (fd, 0) = 0x6f;
- WFIFOSET (fd, 2);
+ WFIFOW(fd, 0) = 0x6f;
+ WFIFOSET(fd, 2);
break;
}
}
if (i == 9)
{
- WFIFOW (fd, 0) = 0x70;
- WFIFOB (fd, 2) = 0;
- WFIFOSET (fd, 3);
+ WFIFOW(fd, 0) = 0x70;
+ WFIFOB(fd, 2) = 0;
+ WFIFOSET(fd, 3);
}
//}
- RFIFOSKIP (fd, 46);
+ RFIFOSKIP(fd, 46);
}
break;
case 0x2af8: // マップサーãƒãƒ¼ãƒ­ã‚°ã‚¤ãƒ³
- if (RFIFOREST (fd) < 60)
+ if (RFIFOREST(fd) < 60)
return;
- WFIFOW (fd, 0) = 0x2af9;
+ WFIFOW(fd, 0) = 0x2af9;
for (i = 0; i < MAX_MAP_SERVERS; i++)
{
if (server_fd[i] < 0)
break;
}
- if (i == MAX_MAP_SERVERS || strcmp ((const char *)RFIFOP (fd, 2), userid)
- || strcmp ((const char *)RFIFOP (fd, 26), passwd))
+ if (i == MAX_MAP_SERVERS || strcmp((const char *)RFIFOP(fd, 2), userid)
+ || strcmp((const char *)RFIFOP(fd, 26), passwd))
{
- WFIFOB (fd, 2) = 3;
- WFIFOSET (fd, 3);
- RFIFOSKIP (fd, 60);
+ WFIFOB(fd, 2) = 3;
+ WFIFOSET(fd, 3);
+ RFIFOSKIP(fd, 60);
}
else
{
- int len;
- WFIFOB (fd, 2) = 0;
+ int len;
+ WFIFOB(fd, 2) = 0;
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].ip = RFIFOL(fd, 54);
+ server[i].port = RFIFOW(fd, 58);
server[i].users = 0;
- memset (server[i].map, 0, sizeof (server[i].map));
- WFIFOSET (fd, 3);
- RFIFOSKIP (fd, 60);
- realloc_fifo (fd, FIFOSIZE_SERVERLINK,
+ memset(server[i].map, 0, sizeof(server[i].map));
+ WFIFOSET(fd, 3);
+ RFIFOSKIP(fd, 60);
+ realloc_fifo(fd, FIFOSIZE_SERVERLINK,
FIFOSIZE_SERVERLINK);
- char_mapif_init (fd);
// send gm acccounts level to map-servers
len = 4;
- WFIFOW (fd, 0) = 0x2b15;
+ WFIFOW(fd, 0) = 0x2b15;
for (i = 0; i < GM_num; i++)
{
- WFIFOL (fd, len) = gm_account[i].account_id;
- WFIFOB (fd, len + 4) =
+ 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);
+ WFIFOW(fd, 2) = len;
+ WFIFOSET(fd, len);
return;
}
break;
case 0x187: // Aliveä¿¡å·ï¼Ÿ
- if (RFIFOREST (fd) < 6)
+ if (RFIFOREST(fd) < 6)
return;
- RFIFOSKIP (fd, 6);
+ RFIFOSKIP(fd, 6);
break;
case 0x7530: // Athena情報所得
- 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);
+ 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;
case 0x7532: // 接続ã®åˆ‡æ–­(defaultã¨å‡¦ç†ã¯ä¸€ç·’ã ãŒæ˜Žç¤ºçš„ã«ã™ã‚‹ãŸã‚)
@@ -3458,18 +2804,18 @@ void parse_char (int fd)
}
// å…¨ã¦ã®MAPサーãƒãƒ¼ã«ãƒ‡ãƒ¼ã‚¿é€ä¿¡ï¼ˆé€ä¿¡ã—ãŸmap鯖ã®æ•°ã‚’è¿”ã™ï¼‰
-int mapif_sendall (const uint8_t *buf, unsigned int len)
+int mapif_sendall(const uint8_t *buf, unsigned int len)
{
- int i, c;
+ int i, c;
c = 0;
for (i = 0; i < MAX_MAP_SERVERS; i++)
{
- int fd;
+ int fd;
if ((fd = server_fd[i]) >= 0)
{
- memcpy (WFIFOP (fd, 0), buf, len);
- WFIFOSET (fd, len);
+ memcpy(WFIFOP(fd, 0), buf, len);
+ WFIFOSET(fd, len);
c++;
}
}
@@ -3477,18 +2823,18 @@ int mapif_sendall (const uint8_t *buf, unsigned int len)
}
// 自分以外ã®å…¨ã¦ã®MAPサーãƒãƒ¼ã«ãƒ‡ãƒ¼ã‚¿é€ä¿¡ï¼ˆé€ä¿¡ã—ãŸmap鯖ã®æ•°ã‚’è¿”ã™ï¼‰
-int mapif_sendallwos (int sfd, const uint8_t *buf, unsigned int len)
+int mapif_sendallwos(int sfd, const uint8_t *buf, unsigned int len)
{
- int i, c;
+ int i, c;
c = 0;
for (i = 0; i < MAX_MAP_SERVERS; i++)
{
- int fd;
+ int fd;
if ((fd = server_fd[i]) >= 0 && fd != sfd)
{
- memcpy (WFIFOP (fd, 0), buf, len);
- WFIFOSET (fd, len);
+ memcpy(WFIFOP(fd, 0), buf, len);
+ WFIFOSET(fd, len);
c++;
}
}
@@ -3496,9 +2842,9 @@ int mapif_sendallwos (int sfd, const uint8_t *buf, unsigned int len)
}
// MAPサーãƒãƒ¼ã«ãƒ‡ãƒ¼ã‚¿é€ä¿¡ï¼ˆmap鯖生存確èªæœ‰ã‚Šï¼‰
-int mapif_send (int fd, const uint8_t *buf, unsigned int len)
+int mapif_send(int fd, const uint8_t *buf, unsigned int len)
{
- int i;
+ int i;
if (fd >= 0)
{
@@ -3506,8 +2852,8 @@ int mapif_send (int fd, const uint8_t *buf, unsigned int len)
{
if (fd == server_fd[i])
{
- memcpy (WFIFOP (fd, 0), buf, len);
- WFIFOSET (fd, len);
+ memcpy(WFIFOP(fd, 0), buf, len);
+ WFIFOSET(fd, len);
return 1;
}
}
@@ -3516,51 +2862,51 @@ int mapif_send (int fd, const uint8_t *buf, unsigned int len)
}
static
-void send_users_tologin (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data)
+void send_users_tologin(TimerData *, tick_t)
{
- int users = count_users ();
+ int users = count_users();
uint8_t 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);
+ 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);
+ WBUFW(buf, 0) = 0x2b00;
+ WBUFL(buf, 2) = users;
+ mapif_sendall(buf, 6);
}
static
-void check_connect_login_server (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data)
+void check_connect_login_server(TimerData *, tick_t)
{
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)
+ PRINTF("Attempt to connect to login-server...\n");
+ if ((login_fd = make_connection(login_ip, login_port)) < 0)
return;
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);
+ 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);
}
}
@@ -3568,49 +2914,43 @@ void check_connect_login_server (timer_id tid, tick_t tick, custom_id_t id, cust
// Reading Lan Support configuration by [Yor]
//-------------------------------------------
static
-int lan_config_read (const char *lancfgName)
+int lan_config_read(const char *lancfgName)
{
- int j;
struct hostent *h = NULL;
- char line[1024], w1[1024], w2[1024];
- FILE *fp;
// set default configuration
- strncpy (lan_map_ip, "127.0.0.1", sizeof (lan_map_ip));
+ strzcpy(lan_map_ip, "127.0.0.1", sizeof(lan_map_ip));
subneti[0] = 127;
subneti[1] = 0;
subneti[2] = 0;
subneti[3] = 1;
- for (j = 0; j < 4; j++)
+ for (int j = 0; j < 4; j++)
subnetmaski[j] = 255;
- fp = fopen_ (lancfgName, "r");
+ std::ifstream in(lancfgName);
- if (fp == NULL)
+ if (!in.is_open())
{
- printf ("LAN support configuration file not found: %s\n", lancfgName);
+ PRINTF("LAN support configuration file not found: %s\n", lancfgName);
return 1;
}
- printf ("---start reading of Lan Support configuration...\n");
+ PRINTF("---start reading of Lan Support configuration...\n");
- while (fgets (line, sizeof (line) - 1, fp))
+ std::string line;
+ while (std::getline(in, line))
{
- if (line[0] == '/' && line[1] == '/')
- continue;
-
- line[sizeof (line) - 1] = '\0';
- if (sscanf (line, "%[^:]: %[^\r\n]", w1, w2) != 2)
+ std::string w1, w2;
+ if (!split_key_value(line, &w1, &w2))
continue;
- remove_control_chars (w1);
- remove_control_chars (w2);
- if (strcasecmp (w1, "lan_map_ip") == 0)
- { // Read map-server Lan IP Address
- h = gethostbyname (w2);
+ if (w1 == "lan_map_ip")
+ {
+ // Read map-server Lan IP Address
+ h = gethostbyname(w2.c_str());
if (h != NULL)
{
- sprintf (lan_map_ip, "%d.%d.%d.%d",
+ 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],
@@ -3618,383 +2958,361 @@ int lan_config_read (const char *lancfgName)
}
else
{
- strncpy (lan_map_ip, w2, sizeof (lan_map_ip));
- lan_map_ip[sizeof (lan_map_ip) - 1] = 0;
+ strzcpy(lan_map_ip, w2.c_str(), sizeof(lan_map_ip));
}
- printf ("LAN IP of map-server: %s.\n", lan_map_ip);
+ PRINTF("LAN IP of map-server: %s.\n", lan_map_ip);
}
- else if (strcasecmp (w1, "subnet") == 0)
- { // Read Subnetwork
- for (j = 0; j < 4; j++)
+ else if (w1 == "subnet")
+ {
+ // Read Subnetwork
+ for (int j = 0; j < 4; j++)
subneti[j] = 0;
- h = gethostbyname (w2);
+ h = gethostbyname(w2.c_str());
if (h != NULL)
{
- for (j = 0; j < 4; j++)
+ for (int j = 0; j < 4; j++)
subneti[j] = (unsigned char) h->h_addr[j];
}
else
{
- sscanf (w2, "%d.%d.%d.%d", &subneti[0], &subneti[1],
+ SSCANF(w2, "%d.%d.%d.%d", &subneti[0], &subneti[1],
&subneti[2], &subneti[3]);
}
- printf ("Sub-network of the map-server: %d.%d.%d.%d.\n",
+ PRINTF("Sub-network of the map-server: %d.%d.%d.%d.\n",
subneti[0], subneti[1], subneti[2], subneti[3]);
}
- else if (strcasecmp (w1, "subnetmask") == 0)
- { // Read Subnetwork Mask
- for (j = 0; j < 4; j++)
+ else if (w1 == "subnetmask")
+ {
+ // Read Subnetwork Mask
+ for (int j = 0; j < 4; j++)
subnetmaski[j] = 255;
- h = gethostbyname (w2);
+ h = gethostbyname(w2.c_str());
if (h != NULL)
{
- for (j = 0; j < 4; j++)
+ for (int j = 0; j < 4; j++)
subnetmaski[j] = (unsigned char) h->h_addr[j];
}
else
{
- sscanf (w2, "%d.%d.%d.%d", &subnetmaski[0], &subnetmaski[1],
+ SSCANF(w2, "%d.%d.%d.%d", &subnetmaski[0], &subnetmaski[1],
&subnetmaski[2], &subnetmaski[3]);
}
- printf ("Sub-network mask of the map-server: %d.%d.%d.%d.\n",
+ PRINTF("Sub-network mask of the map-server: %d.%d.%d.%d.\n",
subnetmaski[0], subnetmaski[1], subnetmaski[2],
subnetmaski[3]);
}
+ else
+ {
+ PRINTF("WARNING: unknown lan config key: %s\n", w1);
+ }
}
- fclose_ (fp);
// sub-network check of the map-server
{
- unsigned int a0, a1, a2, a3;
unsigned char p[4];
- sscanf (lan_map_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 map-server: ");
- if (lan_ip_check (p) == 0)
+ sscanf(lan_map_ip, "%hhu.%hhu.%hhu.%hhu", &p[0], &p[1], &p[2], &p[3]);
+ PRINTF("LAN test of LAN IP of the map-server: ");
+ if (lan_ip_check(p) == 0)
{
- printf
- ("\033[1;31m***ERROR: LAN IP of the map-server doesn't belong to the specified Sub-network.\033[0m\n");
+ PRINTF("\033[1;31m***ERROR: LAN IP of the map-server doesn't belong to the specified Sub-network.\033[0m\n");
}
}
- printf ("---End reading of Lan Support configuration...\n");
+ PRINTF("---End reading of Lan Support configuration...\n");
return 0;
}
static
-int char_config_read (const char *cfgName)
+int char_config_read(const char *cfgName)
{
struct hostent *h = NULL;
- char line[1024], w1[1024], w2[1024];
- FILE *fp = fopen_ (cfgName, "r");
- if (fp == NULL)
+ std::ifstream in(cfgName);
+
+ if (!in.is_open())
{
- printf ("Configuration file not found: %s.\n", cfgName);
- exit (1);
+ PRINTF("Configuration file not found: %s.\n", cfgName);
+ exit(1);
}
- while (fgets (line, sizeof (line) - 1, fp))
+ std::string line;
+ while (std::getline(in, line))
{
- if (line[0] == '/' && line[1] == '/')
+ std::string w1, w2;
+ if (!split_key_value(line, &w1, &w2))
continue;
- line[sizeof (line) - 1] = '\0';
- if (sscanf (line, "%[^:]: %[^\r\n]", w1, w2) != 2)
- continue;
-
- remove_control_chars (w1);
- remove_control_chars (w2);
- if (strcasecmp (w1, "userid") == 0)
- {
- memcpy (userid, w2, 24);
- }
- else if (strcasecmp (w1, "passwd") == 0)
- {
- memcpy (passwd, w2, 24);
- }
- else if (strcasecmp (w1, "server_name") == 0)
+ if (w1 == "userid")
+ strzcpy(userid, w2.c_str(), 24);
+ else if (w1 == "passwd")
+ strzcpy(passwd, w2.c_str(), 24);
+ else if (w1 == "server_name")
{
- memcpy (server_name, w2, sizeof (server_name));
- server_name[sizeof (server_name) - 1] = '\0';
- printf ("%s server has been intialized\n", w2);
+ strzcpy(server_name, w2.c_str(), sizeof(server_name));
+ PRINTF("%s server has been intialized\n", w2);
}
- else if (strcasecmp (w1, "wisp_server_name") == 0)
+ else if (w1 == "wisp_server_name")
{
- if (strlen (w2) >= 4)
- {
- strncpy (wisp_server_name, w2, sizeof (wisp_server_name));
- wisp_server_name[sizeof (wisp_server_name) - 1] = '\0';
- }
+ if (w2.size() >= 4)
+ strzcpy(wisp_server_name, w2.c_str(), sizeof(wisp_server_name));
}
- else if (strcasecmp (w1, "login_ip") == 0)
+ else if (w1 == "login_ip")
{
- h = gethostbyname (w2);
+ h = gethostbyname(w2.c_str());
if (h != NULL)
{
- printf ("Login server IP address : %s -> %d.%d.%d.%d\n", w2,
+ 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",
+ 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);
+ strzcpy(login_ip_str, w2.c_str(), 16);
}
- else if (strcasecmp (w1, "login_port") == 0)
+ else if (w1 == "login_port")
{
- login_port = atoi (w2);
+ login_port = atoi(w2.c_str());
}
- else if (strcasecmp (w1, "char_ip") == 0)
+ else if (w1 == "char_ip")
{
- h = gethostbyname (w2);
+ h = gethostbyname(w2.c_str());
if (h != NULL)
{
- printf ("Character server IP address : %s -> %d.%d.%d.%d\n",
+ 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",
+ 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);
+ strzcpy(char_ip_str, w2.c_str(), 16);
}
- else if (strcasecmp (w1, "char_port") == 0)
+ else if (w1 == "char_port")
{
- char_port = atoi (w2);
+ char_port = atoi(w2.c_str());
}
- else if (strcasecmp (w1, "char_maintenance") == 0)
+ else if (w1 == "char_maintenance")
{
- char_maintenance = atoi (w2);
+ char_maintenance = atoi(w2.c_str());
}
- else if (strcasecmp (w1, "char_new") == 0)
+ else if (w1 == "char_new")
{
- char_new = atoi (w2);
+ char_new = atoi(w2.c_str());
}
- else if (strcasecmp (w1, "email_creation") == 0)
+ else if (w1 == "email_creation")
{
- email_creation = config_switch (w2);
+ email_creation = config_switch(w2.c_str());
}
- else if (strcasecmp (w1, "char_txt") == 0)
+ else if (w1 == "char_txt")
{
- strcpy (char_txt, w2);
+ strzcpy(char_txt, w2.c_str(), sizeof(char_txt));
}
- else if (strcasecmp (w1, "backup_txt") == 0)
- { //By zanetheinsane
- strcpy (backup_txt, w2);
- }
- 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 (strcasecmp (w1, "max_connect_user") == 0)
+ else if (w1 == "max_connect_user")
{
- max_connect_user = atoi (w2);
+ max_connect_user = atoi(w2.c_str());
if (max_connect_user < 0)
max_connect_user = 0; // unlimited online players
}
- else if (strcasecmp (w1, "check_ip_flag") == 0)
+ else if (w1 == "check_ip_flag")
{
- check_ip_flag = config_switch (w2);
+ check_ip_flag = config_switch(w2.c_str());
}
- else if (strcasecmp (w1, "autosave_time") == 0)
+ else if (w1 == "autosave_time")
{
- autosave_interval = atoi (w2) * 1000;
- if (autosave_interval <= 0)
+ autosave_interval = std::chrono::seconds(atoi(w2.c_str()));
+ if (autosave_interval <= std::chrono::seconds::zero())
autosave_interval = DEFAULT_AUTOSAVE_INTERVAL;
}
- else if (strcasecmp (w1, "start_point") == 0)
+ else if (w1 == "start_point")
{
char map[32];
- int x, y;
- if (sscanf (w2, "%[^,],%d,%d", map, &x, &y) < 3)
+ int x, y;
+ if (SSCANF(w2, "%[^,],%d,%d", map, &x, &y) < 3)
continue;
- if (strstr (map, ".gat") != NULL)
+ if (strstr(map, ".gat") != NULL)
{ // Verify at least if '.gat' is in the map name
- memcpy (start_point.map, map, 16);
+ memcpy(start_point.map, map, 16);
start_point.x = x;
start_point.y = y;
}
}
- else if (strcasecmp (w1, "start_zeny") == 0)
+ else if (w1 == "start_zeny")
{
- start_zeny = atoi (w2);
+ start_zeny = atoi(w2.c_str());
if (start_zeny < 0)
start_zeny = 0;
}
- else if (strcasecmp (w1, "start_weapon") == 0)
+ else if (w1 == "start_weapon")
{
- start_weapon = atoi (w2);
+ start_weapon = atoi(w2.c_str());
if (start_weapon < 0)
start_weapon = 0;
}
- else if (strcasecmp (w1, "start_armor") == 0)
+ else if (w1 == "start_armor")
{
- start_armor = atoi (w2);
+ start_armor = atoi(w2.c_str());
if (start_armor < 0)
start_armor = 0;
}
- else if (strcasecmp (w1, "unknown_char_name") == 0)
+ else if (w1 == "unknown_char_name")
{
- strcpy (unknown_char_name, w2);
- unknown_char_name[24] = 0;
+ strzcpy(unknown_char_name, w2.c_str(), 24);
}
- else if (strcasecmp (w1, "char_log_filename") == 0)
+ else if (w1 == "char_log_filename")
{
- strcpy (char_log_filename, w2);
+ strzcpy(char_log_filename, w2.c_str(), sizeof(char_log_filename));
}
- else if (strcasecmp (w1, "name_ignoring_case") == 0)
+ else if (w1 == "name_ignoring_case")
{
- name_ignoring_case = config_switch (w2);
+ name_ignoring_case = config_switch(w2.c_str());
}
- else if (strcasecmp (w1, "char_name_option") == 0)
+ else if (w1 == "char_name_option")
{
- char_name_option = atoi (w2);
+ char_name_option = atoi(w2.c_str());
}
- else if (strcasecmp (w1, "char_name_letters") == 0)
+ else if (w1 == "char_name_letters")
{
- strcpy (char_name_letters, w2);
-// online files options
+ strzcpy(char_name_letters, w2.c_str(), sizeof(char_name_letters));
}
- else if (strcasecmp (w1, "online_txt_filename") == 0)
+ else if (w1 == "online_txt_filename")
{
- strcpy (online_txt_filename, w2);
+ strzcpy(online_txt_filename, w2.c_str(), sizeof(online_txt_filename));
}
- else if (strcasecmp (w1, "online_html_filename") == 0)
+ else if (w1 == "online_html_filename")
{
- strcpy (online_html_filename, w2);
+ strzcpy(online_html_filename, w2.c_str(), sizeof(online_html_filename));
}
- else if (strcasecmp (w1, "online_sorting_option") == 0)
+ else if (w1 == "online_sorting_option")
{
- online_sorting_option = atoi (w2);
+ online_sorting_option = atoi(w2.c_str());
}
- else if (strcasecmp (w1, "online_display_option") == 0)
- {
- online_display_option = atoi (w2);
- }
- else if (strcasecmp (w1, "online_gm_display_min_level") == 0)
+ else if (w1 == "online_gm_display_min_level")
{ // minimum GM level to display 'GM' when we want to display it
- online_gm_display_min_level = atoi (w2);
+ online_gm_display_min_level = atoi(w2.c_str());
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 (strcasecmp (w1, "online_refresh_html") == 0)
+ else if (w1 == "online_refresh_html")
{
- online_refresh_html = atoi (w2);
+ online_refresh_html = atoi(w2.c_str());
if (online_refresh_html < 1)
online_refresh_html = 1;
}
- else if (strcasecmp (w1, "anti_freeze_enable") == 0)
+ else if (w1 == "anti_freeze_enable")
+ {
+ anti_freeze_enable = config_switch(w2.c_str());
+ }
+ else if (w1 == "anti_freeze_interval")
{
- anti_freeze_enable = config_switch (w2);
+ ANTI_FREEZE_INTERVAL = std::max(
+ std::chrono::seconds(atoi(w2.c_str())),
+ std::chrono::seconds(5));
}
- else if (strcasecmp (w1, "anti_freeze_interval") == 0)
+ else if (w1 == "import")
{
- ANTI_FREEZE_INTERVAL = atoi (w2);
- if (ANTI_FREEZE_INTERVAL < 5)
- ANTI_FREEZE_INTERVAL = 5; // minimum 5 seconds
+ char_config_read(w2.c_str());
}
- else if (strcasecmp (w1, "import") == 0)
+ else
{
- char_config_read (w2);
+ PRINTF("WARNING: unknown char config key: %s\n", w1);
}
}
- fclose_ (fp);
return 0;
}
-void term_func (void)
+void term_func(void)
{
- int i;
+ int i;
// write online players files with no player
for (i = 0; i < char_num; i++)
online_chars[i] = -1;
- create_online_files ();
- free (online_chars);
+ create_online_files();
+ free(online_chars);
- mmo_char_sync ();
- inter_save ();
+ mmo_char_sync();
+ inter_save();
if (gm_account != NULL)
- free (gm_account);
+ free(gm_account);
- free (char_dat);
- delete_session (login_fd);
- delete_session (char_fd);
+ free(char_dat);
+ delete_session(login_fd);
+ delete_session(char_fd);
- char_log ("----End of char-server (normal end with closing of all files).\n");
+ CHAR_LOG("----End of char-server (normal end with closing of all files).\n");
}
-int do_init (int argc, char **argv)
+int do_init(int argc, char **argv)
{
- int i;
+ int i;
// a newline in the log...
- char_log ("");
- char_log ("The char-server starting...\n");
+ CHAR_LOG("");
+ CHAR_LOG("The char-server starting...\n");
- char_config_read ((argc < 2) ? CHAR_CONF_NAME : argv[1]);
- lan_config_read ((argc > 1) ? argv[1] : LOGIN_LAN_CONF_NAME);
+ char_config_read((argc < 2) ? CHAR_CONF_NAME : argv[1]);
+ lan_config_read((argc > 1) ? argv[1] : LOGIN_LAN_CONF_NAME);
- login_ip = inet_addr (login_ip_str);
- char_ip = inet_addr (char_ip_str);
+ login_ip = inet_addr(login_ip_str);
+ char_ip = inet_addr(char_ip_str);
for (i = 0; i < MAX_MAP_SERVERS; i++)
{
- memset (&server[i], 0, sizeof (struct mmo_map_server));
+ memset(&server[i], 0, sizeof(struct mmo_map_server));
server_fd[i] = -1;
}
- mmo_char_init ();
+ mmo_char_init();
- update_online = time (NULL);
- create_online_files (); // update online players files at start of the server
+ update_online = TimeT::now();
+ 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);
-
- 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");
-
- i = add_timer_interval (gettick () + 1000, check_connect_login_server, 0,
- 0, 10 * 1000);
- i = add_timer_interval (gettick () + 1000, send_users_tologin, 0, 0,
- 5 * 1000);
- i = add_timer_interval (gettick () + autosave_interval,
- mmo_char_sync_timer, 0, 0, autosave_interval);
+ set_defaultparse(parse_char);
+
+ char_fd = make_listen_port(char_port);
+
+ Timer(gettick() + std::chrono::seconds(1),
+ check_connect_login_server,
+ std::chrono::seconds(10)
+ ).detach();
+ Timer(gettick() + std::chrono::seconds(1),
+ send_users_tologin,
+ std::chrono::seconds(5)
+ ).detach();
+ Timer(gettick() + autosave_interval,
+ mmo_char_sync_timer,
+ autosave_interval
+ ).detach();
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
+ Timer(gettick() + std::chrono::seconds(1),
+ map_anti_freeze_system,
+ ANTI_FREEZE_INTERVAL
+ ).detach();
}
- char_log ("The char-server is ready (Server is listening on the port %d).\n",
+ CHAR_LOG("The char-server is ready (Server is listening on the port %d).\n",
char_port);
- printf
- ("The char-server is \033[1;32mready\033[0m (Server is listening on the port %d).\n\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/char.hpp b/src/char/char.hpp
index f93e86b..be9167e 100644
--- a/src/char/char.hpp
+++ b/src/char/char.hpp
@@ -1,33 +1,33 @@
-// $Id: char.h,v 1.1.1.1 2004/09/10 17:26:50 MagicalTux Exp $
#ifndef CHAR_HPP
#define CHAR_HPP
-#define MAX_MAP_SERVERS 30
+#include "../common/const_array.hpp"
+#include "../common/mmo.hpp"
-#define CHAR_CONF_NAME "conf/char_athena.conf"
+constexpr int MAX_MAP_SERVERS = 30;
-#define LOGIN_LAN_CONF_NAME "conf/lan_support.conf"
+#define CHAR_CONF_NAME "conf/char_athena.conf"
-#define DEFAULT_AUTOSAVE_INTERVAL 300*1000
+#define LOGIN_LAN_CONF_NAME "conf/lan_support.conf"
struct mmo_map_server
{
long ip;
short port;
- int users;
+ int users;
char map[MAX_MAP_PER_SERVER][16];
};
-int search_character_index (const char *character_name);
-char *search_character_name (int index);
+int search_character_index(const char *character_name);
+char *search_character_name(int index);
-int mapif_sendall (const uint8_t *buf, unsigned int len);
-int mapif_sendallwos (int fd, const uint8_t *buf, unsigned int len);
-int mapif_send (int fd, const uint8_t *buf, unsigned int len);
+int mapif_sendall(const uint8_t *buf, unsigned int len);
+int mapif_sendallwos(int fd, const uint8_t *buf, unsigned int len);
+int mapif_send(int fd, const uint8_t *buf, unsigned int len);
-__attribute__((format(printf, 1, 2)))
-int char_log (const char *fmt, ...);
+void char_log(const_string line);
-extern int autosave_interval;
+#define CHAR_LOG(fmt, ...) \
+ char_log(static_cast<const std::string&>(STRPRINTF(fmt, ## __VA_ARGS__)))
-#endif
+#endif // CHAR_HPP
diff --git a/src/char/int_guild.cpp b/src/char/int_guild.cpp
deleted file mode 100644
index 318297e..0000000
--- a/src/char/int_guild.cpp
+++ /dev/null
@@ -1,1802 +0,0 @@
-// $Id: int_guild.c,v 1.2 2004/09/25 19:36:53 Akitasha Exp $
-#include "inter.hpp"
-#include "int_guild.hpp"
-#include "int_storage.hpp"
-#include "../common/mmo.hpp"
-#include "char.hpp"
-#include "../common/socket.hpp"
-#include "../common/db.hpp"
-#include "../common/lock.hpp"
-
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-char guild_txt[1024] = "save/guild.txt";
-char castle_txt[1024] = "save/castle.txt";
-
-static struct dbt *guild_db;
-static struct dbt *castle_db;
-
-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);
-void guild_break_sub (db_key_t key, db_val_t data, va_list ap);
-
-// ギルドデータã®æ–‡å­—列ã¸ã®å¤‰æ›
-static
-int inter_guild_tostr (char *str, struct guild *g)
-{
- int i, c, len;
-
- // 基本データ
- len = sprintf (str, "%d\t%s\t%s\t%d,%d,%d,%d,%d\t%s#\t%s#\t",
- g->guild_id, g->name, g->master,
- g->guild_lv, g->max_member, g->exp, g->skill_point,
- g->castle_id, g->mes1, g->mes2);
- // メンãƒãƒ¼
- for (i = 0; i < g->max_member; i++)
- {
- struct guild_member *m = &g->member[i];
- len += sprintf (str + len, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\t%s\t",
- m->account_id, m->char_id,
- m->hair, m->hair_color, m->gender,
- m->pc_class, m->lv, m->exp, m->exp_payper, m->position,
- ((m->account_id > 0) ? m->name : "-"));
- }
- // å½¹è·
- for (i = 0; i < MAX_GUILDPOSITION; i++)
- {
- struct guild_position *p = &g->position[i];
- len +=
- sprintf (str + len, "%d,%d\t%s#\t", p->mode, p->exp_mode,
- p->name);
- }
- // エンブレム
- len += sprintf (str + len, "%d,%d,", g->emblem_len, g->emblem_id);
- for (i = 0; i < g->emblem_len; i++)
- {
- len +=
- sprintf (str + len, "%02x", (unsigned char) (g->emblem_data[i]));
- }
- len += sprintf (str + len, "$\t");
- // åŒç›Ÿãƒªã‚¹ãƒˆ
- c = 0;
- for (i = 0; i < MAX_GUILDALLIANCE; i++)
- if (g->alliance[i].guild_id > 0)
- c++;
- len += sprintf (str + len, "%d\t", c);
- for (i = 0; i < MAX_GUILDALLIANCE; i++)
- {
- GuildAlliance *a = &g->alliance[i];
- if (a->guild_id > 0)
- len +=
- sprintf (str + len, "%d,%d\t%s\t", a->guild_id, a->opposition,
- a->name);
- }
- // 追放リスト
- c = 0;
- for (i = 0; i < MAX_GUILDEXPLUSION; i++)
- if (g->explusion[i].account_id > 0)
- c++;
- len += sprintf (str + len, "%d\t", c);
- for (i = 0; i < MAX_GUILDEXPLUSION; i++)
- {
- GuildExpulsion *e = &g->explusion[i];
- if (e->account_id > 0)
- len += sprintf (str + len, "%d,%d,%d,%d\t%s\t%s\t%s#\t",
- e->account_id, e->rsv1, e->rsv2, e->rsv3,
- e->name, e->acc, e->mes);
- }
- // ギルドスキル
- for (i = 0; i < MAX_GUILDSKILL; i++)
- {
- len += sprintf (str + len, "%d,%d ", g->skill[i].id, g->skill[i].lv);
- }
- len += sprintf (str + len, "\t");
-
- return 0;
-}
-
-// ギルドデータã®æ–‡å­—列ã‹ã‚‰ã®å¤‰æ›
-static
-int inter_guild_fromstr (char *str, struct guild *g)
-{
- int i, j, c;
- int tmp_int[16];
- char tmp_str[4][256];
- char tmp_str2[4096];
- char *pstr;
-
- // 基本データ
- memset (g, 0, sizeof (struct guild));
- if (sscanf
- (str, "%d\t%[^\t]\t%[^\t]\t%d,%d,%d,%d,%d\t%[^\t]\t%[^\t]\t",
- &tmp_int[0], tmp_str[0], tmp_str[1], &tmp_int[1], &tmp_int[2],
- &tmp_int[3], &tmp_int[4], &tmp_int[5], tmp_str[2], tmp_str[3]) < 8)
- return 1;
-
- g->guild_id = tmp_int[0];
- g->guild_lv = tmp_int[1];
- g->max_member = tmp_int[2];
- g->exp = tmp_int[3];
- g->skill_point = tmp_int[4];
- g->castle_id = tmp_int[5];
- memcpy (g->name, tmp_str[0], 24);
- memcpy (g->master, tmp_str[1], 24);
- memcpy (g->mes1, tmp_str[2], 60);
- memcpy (g->mes2, tmp_str[3], 120);
- g->mes1[strlen (g->mes1) - 1] = 0;
- g->mes2[strlen (g->mes2) - 1] = 0;
-
- for (j = 0; j < 6 && str != NULL; j++) // ä½ç½®ã‚¹ã‚­ãƒƒãƒ—
- str = strchr (str + 1, '\t');
-// printf("GuildBaseInfo OK\n");
-
- // メンãƒãƒ¼
- for (i = 0; i < g->max_member; i++)
- {
- struct guild_member *m = &g->member[i];
- if (sscanf (str + 1, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\t%[^\t]\t",
- &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_str[0]) < 11)
- return 1;
- m->account_id = tmp_int[0];
- m->char_id = 0 /*tmp_int[1]*/;
- m->hair = tmp_int[2];
- m->hair_color = tmp_int[3];
- m->gender = tmp_int[4];
- m->pc_class = tmp_int[5];
- m->lv = tmp_int[6];
- m->exp = tmp_int[7];
- m->exp_payper = tmp_int[8];
- m->position = tmp_int[9];
- memcpy (m->name, tmp_str[0], 24);
-
- for (j = 0; j < 2 && str != NULL; j++) // ä½ç½®ã‚¹ã‚­ãƒƒãƒ—
- str = strchr (str + 1, '\t');
- }
-// printf("GuildMemberInfo OK\n");
- // å½¹è·
- i = 0;
- while (sscanf (str + 1, "%d,%d%n", &tmp_int[0], &tmp_int[1], &j) == 2
- && str[1 + j] == '\t')
- {
- struct guild_position *p = &g->position[i];
- if (sscanf
- (str + 1, "%d,%d\t%[^\t]\t", &tmp_int[0], &tmp_int[1],
- tmp_str[0]) < 3)
- return 1;
- p->mode = tmp_int[0];
- p->exp_mode = tmp_int[1];
- tmp_str[0][strlen (tmp_str[0]) - 1] = 0;
- memcpy (p->name, tmp_str[0], 24);
-
- for (j = 0; j < 2 && str != NULL; j++) // ä½ç½®ã‚¹ã‚­ãƒƒãƒ—
- str = strchr (str + 1, '\t');
- i++;
- }
-// printf("GuildPositionInfo OK\n");
- // エンブレム
- tmp_int[1] = 0;
- if (sscanf (str + 1, "%d,%d,%[^\t]\t", &tmp_int[0], &tmp_int[1], tmp_str2)
- < 3 && sscanf (str + 1, "%d,%[^\t]\t", &tmp_int[0], tmp_str2) < 2)
- return 1;
- g->emblem_len = tmp_int[0];
- g->emblem_id = tmp_int[1];
- for (i = 0, pstr = tmp_str2; 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;
- }
-// printf("GuildEmblemInfo OK\n");
- str = strchr (str + 1, '\t'); // ä½ç½®ã‚¹ã‚­ãƒƒãƒ—
-
- // åŒç›Ÿãƒªã‚¹ãƒˆ
- if (sscanf (str + 1, "%d\t", &c) < 1)
- return 1;
- str = strchr (str + 1, '\t'); // ä½ç½®ã‚¹ã‚­ãƒƒãƒ—
- for (i = 0; i < c; i++)
- {
- GuildAlliance *a = &g->alliance[i];
- if (sscanf
- (str + 1, "%d,%d\t%[^\t]\t", &tmp_int[0], &tmp_int[1],
- tmp_str[0]) < 3)
- return 1;
- a->guild_id = tmp_int[0];
- a->opposition = tmp_int[1];
- memcpy (a->name, tmp_str[0], 24);
-
- for (j = 0; j < 2 && str != NULL; j++) // ä½ç½®ã‚¹ã‚­ãƒƒãƒ—
- str = strchr (str + 1, '\t');
- }
-// printf("GuildAllianceInfo OK\n");
- // 追放リスト
- if (sscanf (str + 1, "%d\t", &c) < 1)
- return 1;
- str = strchr (str + 1, '\t'); // ä½ç½®ã‚¹ã‚­ãƒƒãƒ—
- for (i = 0; i < c; i++)
- {
- GuildExpulsion *e = &g->explusion[i];
- if (sscanf (str + 1, "%d,%d,%d,%d\t%[^\t]\t%[^\t]\t%[^\t]\t",
- &tmp_int[0], &tmp_int[1], &tmp_int[2], &tmp_int[3],
- tmp_str[0], tmp_str[1], tmp_str[2]) < 6)
- return 1;
- e->account_id = tmp_int[0];
- e->rsv1 = tmp_int[1];
- e->rsv2 = tmp_int[2];
- e->rsv3 = tmp_int[3];
- memcpy (e->name, tmp_str[0], 24);
- memcpy (e->acc, tmp_str[1], 24);
- tmp_str[2][strlen (tmp_str[2]) - 1] = 0;
- memcpy (e->mes, tmp_str[2], 40);
-
- for (j = 0; j < 4 && str != NULL; j++) // ä½ç½®ã‚¹ã‚­ãƒƒãƒ—
- str = strchr (str + 1, '\t');
- }
-// printf("GuildExplusionInfo OK\n");
- // ギルドスキル
- for (i = 0; i < MAX_GUILDSKILL; i++)
- {
- if (sscanf (str + 1, "%d,%d ", &tmp_int[0], &tmp_int[1]) < 2)
- break;
- g->skill[i].id = tmp_int[0];
- g->skill[i].lv = tmp_int[1];
- str = strchr (str + 1, ' ');
- }
- str = strchr (str + 1, '\t');
-// printf("GuildSkillInfo OK\n");
-
- return 0;
-}
-
-// ギルド城データã®æ–‡å­—列ã¸ã®å¤‰æ›
-static
-int inter_guildcastle_tostr (char *str, struct guild_castle *gc)
-{
- int len;
-
- len = sprintf (str, "%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", // added Guardian HP [Valaris]
- 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);
-
- return 0;
-}
-
-// ギルド城データã®æ–‡å­—列ã‹ã‚‰ã®å¤‰æ›
-static
-int inter_guildcastle_fromstr (char *str, struct guild_castle *gc)
-{
- int tmp_int[26];
-
- memset (gc, 0, sizeof (struct guild_castle));
- // new structure of guild castle
- if (sscanf
- (str,
- "%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",
- &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], &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]) == 26)
- {
- gc->castle_id = tmp_int[0];
- gc->guild_id = tmp_int[1];
- gc->economy = tmp_int[2];
- gc->defense = tmp_int[3];
- gc->triggerE = tmp_int[4];
- gc->triggerD = tmp_int[5];
- gc->nextTime = tmp_int[6];
- gc->payTime = tmp_int[7];
- gc->createTime = tmp_int[8];
- gc->visibleC = tmp_int[9];
- gc->visibleG0 = tmp_int[10];
- gc->visibleG1 = tmp_int[11];
- gc->visibleG2 = tmp_int[12];
- gc->visibleG3 = tmp_int[13];
- gc->visibleG4 = tmp_int[14];
- gc->visibleG5 = tmp_int[15];
- gc->visibleG6 = tmp_int[16];
- gc->visibleG7 = tmp_int[17];
- gc->Ghp0 = tmp_int[18];
- gc->Ghp1 = tmp_int[19];
- gc->Ghp2 = tmp_int[20];
- gc->Ghp3 = tmp_int[21];
- gc->Ghp4 = tmp_int[22];
- gc->Ghp5 = tmp_int[23];
- gc->Ghp6 = tmp_int[24];
- gc->Ghp7 = tmp_int[25]; // end additions [Valaris]
- // old structure of guild castle
- }
- else if (sscanf
- (str, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",
- &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], &tmp_int[12], &tmp_int[13],
- &tmp_int[14], &tmp_int[15], &tmp_int[16], &tmp_int[17]) == 18)
- {
- gc->castle_id = tmp_int[0];
- gc->guild_id = tmp_int[1];
- gc->economy = tmp_int[2];
- gc->defense = tmp_int[3];
- gc->triggerE = tmp_int[4];
- gc->triggerD = tmp_int[5];
- gc->nextTime = tmp_int[6];
- gc->payTime = tmp_int[7];
- gc->createTime = tmp_int[8];
- gc->visibleC = tmp_int[9];
- gc->visibleG0 = tmp_int[10];
- gc->visibleG1 = tmp_int[11];
- gc->visibleG2 = tmp_int[12];
- gc->visibleG3 = tmp_int[13];
- gc->visibleG4 = tmp_int[14];
- gc->visibleG5 = tmp_int[15];
- gc->visibleG6 = tmp_int[16];
- gc->visibleG7 = tmp_int[17];
- if (gc->visibleG0 == 1)
- gc->Ghp0 = 15670 + 2000 * gc->defense;
- else
- gc->Ghp0 = 0;
- if (gc->visibleG1 == 1)
- gc->Ghp1 = 15670 + 2000 * gc->defense;
- else
- gc->Ghp1 = 0;
- if (gc->visibleG2 == 1)
- gc->Ghp2 = 15670 + 2000 * gc->defense;
- else
- gc->Ghp2 = 0;
- if (gc->visibleG3 == 1)
- gc->Ghp3 = 30214 + 2000 * gc->defense;
- else
- gc->Ghp3 = 0;
- if (gc->visibleG4 == 1)
- gc->Ghp4 = 30214 + 2000 * gc->defense;
- else
- gc->Ghp4 = 0;
- if (gc->visibleG5 == 1)
- gc->Ghp5 = 28634 + 2000 * gc->defense;
- else
- gc->Ghp5 = 0;
- if (gc->visibleG6 == 1)
- gc->Ghp6 = 28634 + 2000 * gc->defense;
- else
- gc->Ghp6 = 0;
- if (gc->visibleG7 == 1)
- gc->Ghp7 = 28634 + 2000 * gc->defense;
- else
- gc->Ghp7 = 0;
- }
- else
- {
- return 1;
- }
-
- return 0;
-}
-
-// ギルド関連データベース読ã¿è¾¼ã¿
-static
-int inter_guild_readdb (void)
-{
- int i;
- FILE *fp;
- char line[1024];
-
- 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, sizeof (line) - 1, fp) && i < 100)
- {
- if (line[0] == '/' && line[1] == '/')
- continue;
- guild_exp[i] = atoi (line);
- i++;
- }
- fclose_ (fp);
-
- return 0;
-}
-
-// ギルドデータã®èª­ã¿è¾¼ã¿
-int inter_guild_init (void)
-{
- char line[16384];
- struct guild *g;
- struct guild_castle *gc;
- FILE *fp;
- int i, j, c = 0;
-
- inter_guild_readdb ();
-
- guild_db = numdb_init ();
- castle_db = numdb_init ();
-
- if ((fp = fopen_ (guild_txt, "r")) == NULL)
- return 1;
- while (fgets (line, sizeof (line) - 1, fp))
- {
- j = 0;
- if (sscanf (line, "%d\t%%newid%%\n%n", &i, &j) == 1 && j > 0
- && guild_newid <= i)
- {
- guild_newid = i;
- continue;
- }
- CREATE (g, struct guild, 1);
- if (inter_guild_fromstr (line, g) == 0 && g->guild_id > 0)
- {
- if (g->guild_id >= guild_newid)
- guild_newid = g->guild_id + 1;
- numdb_insert (guild_db, g->guild_id, g);
- guild_check_empty (g);
- guild_calcinfo (g);
- }
- else
- {
- printf ("int_guild: broken data [%s] line %d\n", guild_txt, c);
- free (g);
- }
- c++;
- }
- fclose_ (fp);
-// printf("int_guild: %s read done (%d guilds)\n", guild_txt, c);
-
- c = 0; //カウンタåˆæœŸåŒ–
-
- if ((fp = fopen_ (castle_txt, "r")) == NULL)
- {
- return 1;
- }
-
- while (fgets (line, sizeof (line) - 1, fp))
- {
- CREATE (gc, struct guild_castle, 1);
- if (inter_guildcastle_fromstr (line, gc) == 0)
- {
- numdb_insert (castle_db, gc->castle_id, gc);
- }
- else
- {
- printf ("int_guild: broken data [%s] line %d\n", castle_txt, c);
- free (gc);
- }
- c++;
- }
-
- if (!c)
- {
- printf (" %s - making Default Data...\n", castle_txt);
- //デフォルトデータを作æˆ
- for (i = 0; i < MAX_GUILDCASTLE; i++)
- {
- CREATE (gc, struct guild_castle, 1);
- gc->castle_id = i;
- gc->guild_id = 0;
- gc->economy = 0;
- gc->defense = 0;
- gc->triggerE = 0;
- gc->triggerD = 0;
- gc->nextTime = 0;
- gc->payTime = 0;
- gc->createTime = 0;
- gc->visibleC = 0;
- gc->visibleG0 = 0;
- gc->visibleG1 = 0;
- gc->visibleG2 = 0;
- gc->visibleG3 = 0;
- gc->visibleG4 = 0;
- gc->visibleG5 = 0;
- gc->visibleG6 = 0;
- gc->visibleG7 = 0;
- gc->Ghp0 = 0; // guardian HP [Valaris]
- gc->Ghp1 = 0;
- gc->Ghp2 = 0;
- gc->Ghp3 = 0;
- gc->Ghp4 = 0;
- gc->Ghp5 = 0;
- gc->Ghp6 = 0;
- gc->Ghp7 = 0; // end additions [Valaris]
- numdb_insert (castle_db, gc->castle_id, gc);
- }
- printf (" %s - making done\n", castle_txt);
- return 0;
- }
-
- fclose_ (fp);
-
- return 0;
-}
-
-struct guild *inter_guild_search (int guild_id)
-{
- struct guild *g = (struct guild *)numdb_search (guild_db, guild_id);
-
- return g;
-}
-
-// ギルドデータã®ã‚»ãƒ¼ãƒ–用
-static
-void inter_guild_save_sub (db_key_t key, db_val_t data, va_list ap)
-{
- char line[16384];
- FILE *fp;
-
- inter_guild_tostr (line, (struct guild *) data);
- fp = va_arg (ap, FILE *);
- fprintf (fp, "%s\n", line);
-}
-
-// ギルド城データã®ã‚»ãƒ¼ãƒ–用
-static
-void inter_castle_save_sub (db_key_t key, db_val_t data, va_list ap)
-{
- char line[16384];
- FILE *fp;
-
- inter_guildcastle_tostr (line, (struct guild_castle *) data);
- fp = va_arg (ap, FILE *);
- fprintf (fp, "%s\n", line);
-}
-
-// ギルドデータã®ã‚»ãƒ¼ãƒ–
-int inter_guild_save (void)
-{
- FILE *fp;
- int lock;
-
- if ((fp = lock_fopen (guild_txt, &lock)) == NULL)
- {
- printf ("int_guild: cant write [%s] !!! data is lost !!!\n",
- guild_txt);
- return 1;
- }
- numdb_foreach (guild_db, inter_guild_save_sub, fp);
-// fprintf(fp, "%d\t%%newid%%\n", guild_newid);
- lock_fclose (fp, guild_txt, &lock);
-// printf("int_guild: %s saved.\n", guild_txt);
-
- if ((fp = lock_fopen (castle_txt, &lock)) == NULL)
- {
- printf ("int_guild: cant write [%s] !!! data is lost !!!\n",
- castle_txt);
- return 1;
- }
- numdb_foreach (castle_db, inter_castle_save_sub, fp);
- lock_fclose (fp, castle_txt, &lock);
-
- return 0;
-}
-
-// ギルドå検索用
-static
-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 (strcasecmp (g->name, str) == 0)
- *dst = g;
-}
-
-// ギルドå検索
-static
-struct guild *search_guildname (const char *str)
-{
- struct guild *g = NULL;
- numdb_foreach (guild_db, search_guildname_sub, str, &g);
- return g;
-}
-
-// ギルドãŒç©ºã‹ã©ã†ã‹ãƒã‚§ãƒƒã‚¯
-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;
- }
- }
- // 誰もã„ãªã„ã®ã§è§£æ•£
- numdb_foreach (guild_db, guild_break_sub, g->guild_id);
- numdb_erase (guild_db, g->guild_id);
- inter_guild_storage_delete (g->guild_id);
- mapif_guild_broken (g->guild_id, 0);
- free (g);
-
- return 1;
-}
-
-// キャラã®ç«¶åˆãŒãªã„ã‹ãƒã‚§ãƒƒã‚¯ç”¨
-static
-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;
-
- guild_id = va_arg (ap, int);
- account_id = va_arg (ap, int);
- char_id = va_arg (ap, int);
-
- if (g->guild_id == guild_id) // 本æ¥ã®æ‰€å±žãªã®ã§å•é¡Œãªã—
- return;
-
- for (i = 0; i < MAX_GUILD; i++)
- {
- if (g->member[i].account_id == account_id)
- {
- // 別ã®ã‚®ãƒ«ãƒ‰ã«å½ã®æ‰€å±žãƒ‡ãƒ¼ã‚¿ãŒã‚ã‚‹ã®ã§è„±é€€
- printf ("int_guild: guild conflict! %d,%d %d!=%d\n", account_id,
- char_id, guild_id, g->guild_id);
- mapif_parse_GuildLeave (-1, g->guild_id, account_id, 0 /*char_id*/, 0,
- "**データ競åˆ**");
- }
- }
-}
-
-// キャラã®ç«¶åˆãŒãªã„ã‹ãƒã‚§ãƒƒã‚¯
-static
-int guild_check_conflict (int guild_id, int account_id, int char_id)
-{
- numdb_foreach (guild_db, guild_check_conflict_sub, guild_id, account_id,
- 0 /*char_id*/);
-
- return 0;
-}
-
-static
-int guild_nextexp (int level)
-{
- if (level < 100)
- return guild_exp[level - 1];
-
- return 0;
-}
-
-// ギルドスキルãŒã‚ã‚‹ã‹ç¢ºèª
-static
-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)
- { // レベルアップ処ç†
- 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;
-
- // å¹³å‡ãƒ¬ãƒ™ãƒ«ã¨ã‚ªãƒ³ãƒ©ã‚¤ãƒ³äººæ•°
- g->average_lv = 0;
- g->connect_member = 0;
- c = 0;
- for (i = 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ã¸ã®é€šä¿¡
-
-// ギルド作æˆå¯å¦
-static
-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;
-}
-
-// ギルド情報見ã¤ã‹ã‚‰ãš
-static
-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[4 + sizeof (struct guild)];
-
- 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;
-}
-
-// メンãƒè¿½åŠ å¯å¦
-static
-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) = 0 /*char_id*/;
- WFIFOB (fd, 14) = flag;
- WFIFOSET (fd, 15);
-
- return 0;
-}
-
-// 脱退/追放通知
-static
-int mapif_guild_leaved (int guild_id, int account_id, int char_id, int flag,
- const char *name, const char *mes)
-{
- unsigned char buf[79];
-
- WBUFW (buf, 0) = 0x3834;
- WBUFL (buf, 2) = guild_id;
- WBUFL (buf, 6) = account_id;
- WBUFL (buf, 10) = 0 /*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更新通知
-static
-int mapif_guild_memberinfoshort (struct guild *g, int idx)
-{
- unsigned char buf[19];
-
- WBUFW (buf, 0) = 0x3835;
- WBUFL (buf, 2) = g->guild_id;
- WBUFL (buf, 6) = g->member[idx].account_id;
- WBUFL (buf, 10) = 0 /*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].pc_class;
- mapif_sendall (buf, 19);
- return 0;
-}
-
-// 解散通知
-int mapif_guild_broken (int guild_id, int flag)
-{
- unsigned char buf[7];
-
- 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;
-}
-
-// ギルド内発言
-static
-int mapif_guild_message (int guild_id, int account_id, const char *mes, int len)
-{
- unsigned char buf[len + 12];
-
- 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;
-}
-
-// ギルドメンãƒæƒ…報変更通知
-static
-int mapif_guild_memberinfochanged (int guild_id, int account_id, int char_id,
- int type, const void *data, int len)
-{
- unsigned char buf[len + 18];
-
- WBUFW (buf, 0) = 0x383a;
- WBUFW (buf, 2) = len + 18;
- WBUFL (buf, 4) = guild_id;
- WBUFL (buf, 8) = account_id;
- WBUFL (buf, 12) = 0 /*char_id*/;
- WBUFW (buf, 16) = type;
- memcpy (WBUFP (buf, 18), data, len);
- mapif_sendall (buf, len + 18);
-
- return 0;
-}
-
-// ギルドスキルアップ通知
-static
-int mapif_guild_skillupack (int guild_id, int skill_num, int account_id)
-{
- unsigned char buf[14];
-
- 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;
-}
-
-// ギルドåŒç›Ÿ/敵対通知
-static
-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[67];
-
- 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;
-}
-
-// ギルド役è·å¤‰æ›´é€šçŸ¥
-static
-int mapif_guild_position (struct guild *g, int idx)
-{
- unsigned char buf[sizeof (struct guild_position) + 12];
-
- 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;
-}
-
-// ギルド告知変更通知
-static
-int mapif_guild_notice (struct guild *g)
-{
- unsigned char buf[186];
-
- 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;
-}
-
-// ギルドエンブレム変更通知
-static
-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;
-}
-
-static
-int mapif_guild_castle_dataload (int castle_id, int index, int value)
-{
- unsigned char buf[9];
-
- WBUFW (buf, 0) = 0x3840;
- WBUFW (buf, 2) = castle_id;
- WBUFB (buf, 4) = index;
- WBUFL (buf, 5) = value;
- mapif_sendall (buf, 9);
-
- return 0;
-}
-
-static
-int mapif_guild_castle_datasave (int castle_id, int index, int value)
-{
- unsigned char buf[9];
-
- WBUFW (buf, 0) = 0x3841;
- WBUFW (buf, 2) = castle_id;
- WBUFB (buf, 4) = index;
- WBUFL (buf, 5) = value;
- mapif_sendall (buf, 9);
-
- return 0;
-}
-
-static
-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 *);
-
- memcpy (WFIFOP (fd, *p), (struct guild_castle *) data,
- sizeof (struct guild_castle));
- (*p) += sizeof (struct guild_castle);
-}
-
-static
-int mapif_guild_castle_alldataload (int fd)
-{
- int len = 4;
-
- WFIFOW (fd, 0) = 0x3842;
- numdb_foreach (castle_db, mapif_guild_castle_alldataload_sub, fd, &len);
- WFIFOW (fd, 2) = len;
- WFIFOSET (fd, len);
-
- return 0;
-}
-
-//-------------------------------------------------------------------
-// map serverã‹ã‚‰ã®é€šä¿¡
-
-// ギルド作æˆè¦æ±‚
-static
-int mapif_parse_CreateGuild (int fd, int account_id, const char *name,
- struct guild_member *master)
-{
- struct guild *g;
- int i;
-
- for (i = 0; i < 24 && name[i]; i++)
- {
- if (!(name[i] & 0xe0) || name[i] == 0x7f)
- {
- printf ("int_guild: illeagal guild name [%s]\n", name);
- mapif_guild_created (fd, account_id, NULL);
- return 0;
- }
- }
-
- if ((g = search_guildname (name)) != NULL)
- {
- printf ("int_guild: same name guild exists [%s]\n", name);
- mapif_guild_created (fd, account_id, NULL);
- return 0;
- }
- CREATE (g, struct guild, 1);
- 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);
-
- // ã“ã“ã§ã‚®ãƒ«ãƒ‰æƒ…報計算ãŒå¿…è¦ã¨æ€ã‚れる
- g->max_member = 100;
- g->average_lv = master->lv;
- for (i = 0; i < 5; i++)
- g->skill[i].id = i + 10000;
-
- numdb_insert (guild_db, g->guild_id, g);
-
- mapif_guild_created (fd, account_id, g);
- mapif_guild_info (fd, g);
-
- inter_log ("guild %s (id=%d) created by master %s (id=%d)\n",
- name, g->guild_id, master->name, master->account_id);
-
- return 0;
-}
-
-// ギルド情報è¦æ±‚
-static
-int mapif_parse_GuildInfo (int fd, int guild_id)
-{
- struct guild *g = (struct guild *)numdb_search (guild_db, guild_id);
- if (g != NULL)
- {
- guild_calcinfo (g);
- mapif_guild_info (fd, g);
- }
- else
- mapif_guild_noinfo (fd, guild_id);
-
- return 0;
-}
-
-// ギルドメンãƒè¿½åŠ è¦æ±‚
-static
-int mapif_parse_GuildAddMember (int fd, int guild_id, struct guild_member *m)
-{
- struct guild *g = (struct guild *)numdb_search (guild_db, guild_id);
- if (g == NULL)
- {
- mapif_guild_memberadded (fd, guild_id, m->account_id, 0 /*char_id*/, 1);
- return 0;
- }
-
- for (int 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, 0 /*char_id*/,
- 0);
- guild_calcinfo (g);
- mapif_guild_info (-1, g);
-
- return 0;
- }
- }
- mapif_guild_memberadded (fd, guild_id, m->account_id, 0 /*char_id*/, 1);
-
- return 0;
-}
-
-// ギルド脱退/追放è¦æ±‚
-int mapif_parse_GuildLeave (int fd, int guild_id, int account_id, int char_id,
- int flag, const char *mes)
-{
- struct guild *g = (struct guild *)numdb_search (guild_db, guild_id);
- if (g != NULL)
- {
- for (int i = 0; i < MAX_GUILD; i++)
- {
- if (g->member[i].account_id == account_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, 0 /*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); // ã¾ã äººãŒã„ã‚‹ã®ã§ãƒ‡ãƒ¼ã‚¿é€ä¿¡
-
- return 0;
- }
- }
- }
- return 0;
-}
-
-// オンライン/Lv更新
-static
-int mapif_parse_GuildChangeMemberInfoShort (int fd, int guild_id,
- int account_id, int char_id,
- int online, int lv, int pc_class)
-{
- struct guild *g = (struct guild *)numdb_search (guild_db, guild_id);
- if (g == NULL)
- return 0;
-
- g->connect_member = 0;
-
- int alv = 0;
- int c = 0;
- for (int i = 0; i < MAX_GUILD; i++)
- {
- if (g->member[i].account_id == account_id)
- {
- g->member[i].online = online;
- g->member[i].lv = lv;
- g->member[i].pc_class = pc_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;
-
- return 0;
-}
-
-// ギルド解散処ç†ç”¨ï¼ˆåŒç›Ÿ/敵対を解除)
-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);
- int i;
-
- for (i = 0; i < MAX_GUILDALLIANCE; i++)
- {
- if (g->alliance[i].guild_id == guild_id)
- g->alliance[i].guild_id = 0;
- }
-}
-
-// ギルド解散è¦æ±‚
-static
-int mapif_parse_BreakGuild (int fd, int guild_id)
-{
- struct guild *g = (struct guild *)numdb_search (guild_db, guild_id);
- if (g == NULL)
- return 0;
-
- numdb_foreach (guild_db, guild_break_sub, guild_id);
- numdb_erase (guild_db, guild_id);
- inter_guild_storage_delete (guild_id);
- mapif_guild_broken (guild_id, 0);
-
- inter_log ("guild %s (id=%d) broken\n", g->name, guild_id);
- free (g);
-
- return 0;
-}
-
-// ギルドメッセージé€ä¿¡
-static
-int mapif_parse_GuildMessage (int fd, int guild_id, int account_id, const char *mes,
- int len)
-{
- return mapif_guild_message (guild_id, account_id, mes, len);
-}
-
-// ギルド基本データ変更è¦æ±‚
-static
-int mapif_parse_GuildBasicInfoChange (int fd, int guild_id, int type,
- const char *data, int len)
-{
- short dw = *((short *) data);
-
- struct guild *g = (struct guild *)numdb_search (guild_db, guild_id);
- if (g == NULL)
- return 0;
-
- switch (type)
- {
- case GBI_GUILDLV:
- 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);
- return 0;
- default:
- printf ("int_guild: GuildBasicInfoChange: Unknown type %d\n",
- type);
- break;
- }
- mapif_guild_basicinfochanged (guild_id, type, data, len);
-
- return 0;
-}
-
-// ギルドメンãƒãƒ‡ãƒ¼ã‚¿å¤‰æ›´è¦æ±‚
-static
-int mapif_parse_GuildMemberInfoChange (int fd, int guild_id, int account_id,
- int char_id, int type,
- const char *data, int len)
-{
- int i;
- struct guild *g = (struct guild *)numdb_search (guild_db, guild_id);
- if (g == NULL)
- return 0;
-
- for (i = 0; i < g->max_member; i++)
- if (g->member[i].account_id == account_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);
-
- return 0;
-}
-
-// ギルド役è·å変更è¦æ±‚
-static
-int mapif_parse_GuildPosition (int fd, int guild_id, int idx,
- struct guild_position *p)
-{
- struct guild *g = (struct guild *)numdb_search (guild_db, guild_id);
-
- 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);
-
- return 0;
-}
-
-// ギルドスキルアップè¦æ±‚
-static
-int mapif_parse_GuildSkillUp (int fd, int guild_id, int skill_num,
- int account_id)
-{
- struct guild *g = (struct guild *)numdb_search (guild_db, guild_id);
- int idx = skill_num - 10000;
-
- if (g == NULL || skill_num < 10000)
- return 0;
-
- 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);
- }
-
- return 0;
-}
-
-// ギルドåŒç›Ÿè¦æ±‚
-static
-int mapif_parse_GuildAlliance (int fd, int guild_id1, int guild_id2,
- int account_id1, int account_id2, int flag)
-{
- struct guild *g[2];
- int j, i;
-
- g[0] = (struct guild *)numdb_search (guild_db, guild_id1);
- g[1] = (struct guild *)numdb_search (guild_db, guild_id2);
- if (g[0] == NULL || g[1] == NULL)
- 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);
-
- return 0;
-}
-
-// ギルド告知変更è¦æ±‚
-static
-int mapif_parse_GuildNotice (int fd, int guild_id, const char *mes1,
- const char *mes2)
-{
- struct guild *g = (struct guild *)numdb_search (guild_db, guild_id);
- if (g == NULL)
- return 0;
- memcpy (g->mes1, mes1, 60);
- memcpy (g->mes2, mes2, 120);
-
- return mapif_guild_notice (g);
-}
-
-// ギルドエンブレム変更è¦æ±‚
-static
-int mapif_parse_GuildEmblem (int fd, int len, int guild_id, int dummy,
- const char *data)
-{
- struct guild *g = (struct guild *)numdb_search (guild_db, guild_id);
- if (g == NULL)
- return 0;
- memcpy (g->emblem_data, data, len);
- g->emblem_len = len;
- g->emblem_id++;
-
- return mapif_guild_emblem (g);
-}
-
-static
-int mapif_parse_GuildCastleDataLoad (int fd, int castle_id, int index)
-{
- struct guild_castle *gc = (struct guild_castle *)numdb_search (castle_db, castle_id);
-
- if (gc == NULL)
- {
- 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);
- case 2:
- return mapif_guild_castle_dataload (gc->castle_id, index,
- gc->economy);
- case 3:
- return mapif_guild_castle_dataload (gc->castle_id, index,
- gc->defense);
- case 4:
- return mapif_guild_castle_dataload (gc->castle_id, index,
- gc->triggerE);
- case 5:
- return mapif_guild_castle_dataload (gc->castle_id, index,
- gc->triggerD);
- case 6:
- return mapif_guild_castle_dataload (gc->castle_id, index,
- gc->nextTime);
- case 7:
- return mapif_guild_castle_dataload (gc->castle_id, index,
- gc->payTime);
- case 8:
- return mapif_guild_castle_dataload (gc->castle_id, index,
- gc->createTime);
- case 9:
- return mapif_guild_castle_dataload (gc->castle_id, index,
- gc->visibleC);
- case 10:
- return mapif_guild_castle_dataload (gc->castle_id, index,
- gc->visibleG0);
- case 11:
- return mapif_guild_castle_dataload (gc->castle_id, index,
- gc->visibleG1);
- case 12:
- return mapif_guild_castle_dataload (gc->castle_id, index,
- gc->visibleG2);
- case 13:
- return mapif_guild_castle_dataload (gc->castle_id, index,
- gc->visibleG3);
- case 14:
- return mapif_guild_castle_dataload (gc->castle_id, index,
- gc->visibleG4);
- case 15:
- return mapif_guild_castle_dataload (gc->castle_id, index,
- gc->visibleG5);
- case 16:
- return mapif_guild_castle_dataload (gc->castle_id, index,
- gc->visibleG6);
- case 17:
- return mapif_guild_castle_dataload (gc->castle_id, index,
- gc->visibleG7);
- case 18:
- return mapif_guild_castle_dataload (gc->castle_id, index, gc->Ghp0); // guardian HP [Valaris]
- case 19:
- return mapif_guild_castle_dataload (gc->castle_id, index,
- gc->Ghp1);
- case 20:
- return mapif_guild_castle_dataload (gc->castle_id, index,
- gc->Ghp2);
- case 21:
- return mapif_guild_castle_dataload (gc->castle_id, index,
- gc->Ghp3);
- case 22:
- return mapif_guild_castle_dataload (gc->castle_id, index,
- gc->Ghp4);
- case 23:
- return mapif_guild_castle_dataload (gc->castle_id, index,
- gc->Ghp5);
- case 24:
- return mapif_guild_castle_dataload (gc->castle_id, index,
- gc->Ghp6);
- case 25:
- return mapif_guild_castle_dataload (gc->castle_id, index, gc->Ghp7); // end additions [Valaris]
-
- default:
- printf
- ("mapif_parse_GuildCastleDataLoad ERROR!! (Not found index=%d)\n",
- index);
- return 0;
- }
-
- return 0;
-}
-
-static
-int mapif_parse_GuildCastleDataSave (int fd, int castle_id, int index,
- int value)
-{
- struct guild_castle *gc = (struct guild_castle *)numdb_search (castle_db, castle_id);
-
- if (gc == NULL)
- {
- 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 = (struct guild *)numdb_search (guild_db, gid);
- inter_log ("guild %s (id=%d) %s castle id=%d\n",
- (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;
- }
-
- return mapif_guild_castle_datasave (gc->castle_id, index, value);
-}
-
-// ギルドãƒã‚§ãƒƒã‚¯è¦æ±‚
-static
-int mapif_parse_GuildCheck (int fd, int guild_id, int account_id, int char_id)
-{
- return guild_check_conflict (guild_id, account_id, 0 /*char_id*/);
-}
-
-// 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), (const char *)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),
- (const char *)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),
- (const char *)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), (const char *)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), (const char *)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), (const char *)RFIFOP (fd, 6),
- (const char *)RFIFOP (fd, 66));
- break;
- case 0x303F:
- mapif_parse_GuildEmblem (fd, RFIFOW (fd, 2) - 12, RFIFOL (fd, 4),
- RFIFOL (fd, 8), (const char *)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, 0 /*char_id*/, 0,
- "**サーãƒãƒ¼å‘½ä»¤**");
-}
diff --git a/src/char/int_guild.hpp b/src/char/int_guild.hpp
deleted file mode 100644
index 2833e2d..0000000
--- a/src/char/int_guild.hpp
+++ /dev/null
@@ -1,16 +0,0 @@
-// $Id: int_guild.h,v 1.1.1.1 2004/09/10 17:26:51 MagicalTux Exp $
-#ifndef INT_GUILD_HPP
-#define INT_GUILD_HPP
-
-int inter_guild_init (void);
-int inter_guild_save (void);
-int inter_guild_parse_frommap (int fd);
-struct guild *inter_guild_search (int guild_id);
-int inter_guild_mapif_init (int fd);
-
-int inter_guild_leave (int guild_id, int account_id, int char_id);
-
-extern char guild_txt[1024];
-extern char castle_txt[1024];
-
-#endif
diff --git a/src/char/int_party.cpp b/src/char/int_party.cpp
index 6602ce5..8566f3c 100644
--- a/src/char/int_party.cpp
+++ b/src/char/int_party.cpp
@@ -1,204 +1,196 @@
-// $Id: int_party.c,v 1.1.1.1 2004/09/10 17:26:51 MagicalTux Exp $
-#include "inter.hpp"
#include "int_party.hpp"
-#include "../common/mmo.hpp"
-#include "char.hpp"
-#include "../common/socket.hpp"
+
+#include <cstdlib>
+#include <cstring>
+
+#include "../common/cxxstdio.hpp"
#include "../common/db.hpp"
#include "../common/lock.hpp"
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
+#include "../common/mmo.hpp"
+#include "../common/socket.hpp"
+
+#include "char.hpp"
+#include "inter.hpp"
+
+#include "../poison.hpp"
char party_txt[1024] = "save/party.txt";
-static struct dbt *party_db;
-static int party_newid = 100;
+static
+Map<int, struct party> party_db;
+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);
+static
+int mapif_party_broken(int party_id, int flag);
+static
+int party_check_empty(struct party *p);
+static
+void mapif_parse_PartyLeave(int fd, int party_id, int account_id);
// パーティデータã®æ–‡å­—列ã¸ã®å¤‰æ›
static
-int inter_party_tostr (char *str, struct party *p)
+std::string inter_party_tostr(struct party *p)
{
- int i, len;
-
- len =
- sprintf (str, "%d\t%s\t%d,%d\t", p->party_id, p->name, p->exp,
- p->item);
- for (i = 0; i < MAX_PARTY; i++)
+ std::string str = STRPRINTF(
+ "%d\t"
+ "%s\t"
+ "%d,%d\t",
+ p->party_id,
+ p->name,
+ p->exp, p->item);
+ for (int i = 0; i < MAX_PARTY; i++)
{
struct party_member *m = &p->member[i];
- len +=
- sprintf (str + len, "%d,%d\t%s\t", m->account_id, m->leader,
- ((m->account_id > 0) ? m->name : "NoMember"));
+ str += STRPRINTF(
+ "%d,%d\t"
+ "%s\t",
+ m->account_id, m->leader,
+ (m->account_id > 0) ? m->name : "NoMember");
}
- return 0;
+ return str;
}
// パーティデータã®æ–‡å­—列ã‹ã‚‰ã®å¤‰æ›
static
-int inter_party_fromstr (char *str, struct party *p)
+int inter_party_fromstr(char *str, struct party *p)
{
- int i, j;
- int tmp_int[16];
- char tmp_str[256];
-
- memset (p, 0, sizeof (struct party));
-
-// printf("sscanf party main info\n");
- if (sscanf
- (str, "%d\t%[^\t]\t%d,%d\t", &tmp_int[0], tmp_str, &tmp_int[1],
- &tmp_int[2]) != 4)
+ memset(p, 0, sizeof(struct party));
+
+ if (sscanf(str,
+ "%d\t"
+ "%[^\t]\t"
+ "%d,%d\t",
+ &p->party_id,
+ p->name,
+ &p->exp, &p->item) != 4)
return 1;
- p->party_id = tmp_int[0];
- strcpy (p->name, tmp_str);
- p->exp = tmp_int[1];
- p->item = tmp_int[2];
-// printf("%d [%s] %d %d\n", tmp_int[0], tmp_str[0], tmp_int[1], tmp_int[2]);
-
- for (j = 0; j < 3 && str != NULL; j++)
- str = strchr (str + 1, '\t');
+ for (int j = 0; j < 3 && str != NULL; j++)
+ str = strchr(str + 1, '\t');
- for (i = 0; i < MAX_PARTY; i++)
+ for (int i = 0; i < MAX_PARTY; i++)
{
struct party_member *m = &p->member[i];
if (str == NULL)
return 1;
-// printf("sscanf party member info %d\n", i);
- if (sscanf
- (str + 1, "%d,%d\t%[^\t]\t", &tmp_int[0], &tmp_int[1],
- tmp_str) != 3)
+ if (sscanf(str + 1,
+ "%d,%d\t"
+ "%[^\t]\t",
+ &m->account_id, &m->leader,
+ m->name) != 3)
return 1;
- m->account_id = tmp_int[0];
- m->leader = tmp_int[1];
- strncpy (m->name, tmp_str, sizeof (m->name));
-// printf(" %d %d [%s]\n", tmp_int[0], tmp_int[1], tmp_str);
-
- for (j = 0; j < 2 && str != NULL; j++)
- str = strchr (str + 1, '\t');
+ for (int j = 0; j < 2 && str != NULL; j++)
+ str = strchr(str + 1, '\t');
}
return 0;
}
// パーティデータã®ãƒ­ãƒ¼ãƒ‰
-int inter_party_init (void)
+int inter_party_init(void)
{
char line[8192];
- struct party *p;
FILE *fp;
- int c = 0;
- int i, j;
-
- party_db = numdb_init ();
+ int c = 0;
+ int i, j;
- if ((fp = fopen_ (party_txt, "r")) == NULL)
+ if ((fp = fopen_(party_txt, "r")) == NULL)
return 1;
- while (fgets (line, sizeof (line) - 1, fp))
+ // TODO: convert to use char_id, and change to extract()
+ while (fgets(line, sizeof(line) - 1, fp))
{
j = 0;
- if (sscanf (line, "%d\t%%newid%%\n%n", &i, &j) == 1 && j > 0
+ if (sscanf(line, "%d\t%%newid%%\n%n", &i, &j) == 1 && j > 0
&& party_newid <= i)
{
party_newid = i;
continue;
}
- CREATE (p, struct party, 1);
- if (inter_party_fromstr (line, p) == 0 && p->party_id > 0)
+ struct party p {};
+ if (inter_party_fromstr(line, &p) == 0 && p.party_id > 0)
{
- if (p->party_id >= party_newid)
- party_newid = p->party_id + 1;
- numdb_insert (party_db, p->party_id, p);
- party_check_empty (p);
+ if (p.party_id >= party_newid)
+ party_newid = p.party_id + 1;
+ party_db.insert(p.party_id, p);
+ party_check_empty(&p);
}
else
{
- printf ("int_party: broken data [%s] line %d\n", party_txt,
+ PRINTF("int_party: broken data [%s] line %d\n", party_txt,
c + 1);
- free (p);
}
c++;
}
- fclose_ (fp);
-// printf("int_party: %s read done (%d parties)\n", party_txt, c);
+ fclose_(fp);
+// PRINTF("int_party: %s read done (%d parties)\n", party_txt, c);
return 0;
}
// パーティーデータã®ã‚»ãƒ¼ãƒ–用
static
-void inter_party_save_sub (db_key_t key, db_val_t data, va_list ap)
+void inter_party_save_sub(struct party *data, FILE *fp)
{
- char line[8192];
- FILE *fp;
-
- inter_party_tostr (line, (struct party *) data);
- fp = va_arg (ap, FILE *);
- fprintf (fp, "%s\n", line);
+ std::string line = inter_party_tostr(data);
+ FPRINTF(fp, "%s\n", line);
}
// パーティーデータã®ã‚»ãƒ¼ãƒ–
-int inter_party_save (void)
+int inter_party_save(void)
{
FILE *fp;
- int lock;
+ int lock;
- if ((fp = lock_fopen (party_txt, &lock)) == NULL)
+ if ((fp = lock_fopen(party_txt, &lock)) == NULL)
{
- printf ("int_party: cant write [%s] !!! data is lost !!!\n",
+ PRINTF("int_party: cant write [%s] !!! data is lost !!!\n",
party_txt);
return 1;
}
- numdb_foreach (party_db, inter_party_save_sub, fp);
-// fprintf(fp, "%d\t%%newid%%\n", party_newid);
- lock_fclose (fp, party_txt, &lock);
-// printf("int_party: %s saved.\n", party_txt);
+ for (auto& pair : party_db)
+ inter_party_save_sub(&pair.second, fp);
+// FPRINTF(fp, "%d\t%%newid%%\n", party_newid);
+ lock_fclose(fp, party_txt, &lock);
+// PRINTF("int_party: %s saved.\n", party_txt);
return 0;
}
// パーティå検索用
static
-void search_partyname_sub (db_key_t key, db_val_t data, va_list ap)
+void search_partyname_sub(struct party *p, const char *str, struct party **dst)
{
- struct party *p = (struct party *) data, **dst;
- char *str;
-
- str = va_arg (ap, char *);
- dst = va_arg (ap, struct party **);
- if (strcasecmp (p->name, str) == 0)
+ if (strcasecmp(p->name, str) == 0)
*dst = p;
}
// パーティå検索
static
-struct party *search_partyname (const char *str)
+struct party *search_partyname(const char *str)
{
struct party *p = NULL;
- numdb_foreach (party_db, search_partyname_sub, str, &p);
+ for (auto& pair : party_db)
+ search_partyname_sub(&pair.second, str, &p);
return p;
}
// EXP公平分é…ã§ãã‚‹ã‹ãƒã‚§ãƒƒã‚¯
static
-int party_check_exp_share (struct party *p)
+int party_check_exp_share(struct party *p)
{
- int i;
- int maxlv = 0, minlv = 0x7fffffff;
+ int i;
+ int maxlv = 0, minlv = 0x7fffffff;
for (i = 0; i < MAX_PARTY; i++)
{
- int lv = p->member[i].lv;
+ int lv = p->member[i].lv;
if (p->member[i].online)
{
if (lv < minlv)
@@ -212,38 +204,32 @@ int party_check_exp_share (struct party *p)
}
// パーティãŒç©ºã‹ã©ã†ã‹ãƒã‚§ãƒƒã‚¯
-int party_check_empty (struct party *p)
+int party_check_empty(struct party *p)
{
- int i;
+ int i;
-// printf("party check empty %08X\n", (int)p);
+// 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);
+// PRINTF("%d acc=%d\n", i, p->member[i].account_id);
if (p->member[i].account_id > 0)
{
return 0;
}
}
// 誰もã„ãªã„ã®ã§è§£æ•£
- mapif_party_broken (p->party_id, 0);
- numdb_erase (party_db, p->party_id);
- free (p);
+ mapif_party_broken(p->party_id, 0);
+ party_db.erase(p->party_id);
return 1;
}
// キャラã®ç«¶åˆãŒãªã„ã‹ãƒã‚§ãƒƒã‚¯ç”¨
static
-void party_check_conflict_sub (db_key_t key, db_val_t data, va_list ap)
+void party_check_conflict_sub(struct party *p,
+ int party_id, int account_id, const char *nick)
{
- struct party *p = (struct party *) data;
- int party_id, account_id, i;
- char *nick;
-
- party_id = va_arg (ap, int);
- account_id = va_arg (ap, int);
- nick = va_arg (ap, char *);
+ int i;
if (p->party_id == party_id) // 本æ¥ã®æ‰€å±žãªã®ã§å•é¡Œãªã—
return;
@@ -251,22 +237,23 @@ void party_check_conflict_sub (db_key_t key, db_val_t data, va_list ap)
for (i = 0; i < MAX_PARTY; i++)
{
if (p->member[i].account_id == account_id
- && strcmp (p->member[i].name, nick) == 0)
+ && strcmp(p->member[i].name, nick) == 0)
{
// 別ã®ãƒ‘ーティã«å½ã®æ‰€å±žãƒ‡ãƒ¼ã‚¿ãŒã‚ã‚‹ã®ã§è„±é€€
- printf ("int_party: party conflict! %d %d %d\n", account_id,
+ PRINTF("int_party: party conflict! %d %d %d\n", account_id,
party_id, p->party_id);
- mapif_parse_PartyLeave (-1, p->party_id, account_id);
+ mapif_parse_PartyLeave(-1, p->party_id, account_id);
}
}
}
// キャラã®ç«¶åˆãŒãªã„ã‹ãƒã‚§ãƒƒã‚¯
static
-int party_check_conflict (int party_id, int account_id, const char *nick)
+int party_check_conflict(int party_id, int account_id, const char *nick)
{
- numdb_foreach (party_db, party_check_conflict_sub, party_id, account_id,
- nick);
+ for (auto& pair : party_db)
+ party_check_conflict_sub(&pair.second,
+ party_id, account_id, nick);
return 0;
}
@@ -276,90 +263,90 @@ int party_check_conflict (int party_id, int account_id, const char *nick)
// パーティ作æˆå¯å¦
static
-int mapif_party_created (int fd, int account_id, struct party *p)
+int mapif_party_created(int fd, int account_id, struct party *p)
{
- WFIFOW (fd, 0) = 0x3820;
- WFIFOL (fd, 2) = account_id;
+ 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);
+ 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);
+ WFIFOB(fd, 6) = 1;
+ WFIFOL(fd, 7) = 0;
+ memcpy(WFIFOP(fd, 11), "error", 24);
}
- WFIFOSET (fd, 35);
+ WFIFOSET(fd, 35);
return 0;
}
// パーティ情報見ã¤ã‹ã‚‰ãš
static
-int mapif_party_noinfo (int fd, int party_id)
+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);
+ 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;
}
// パーティ情報ã¾ã¨ã‚é€ã‚Š
static
-int mapif_party_info (int fd, struct party *p)
+int mapif_party_info(int fd, struct party *p)
{
- unsigned char buf[4 + sizeof (struct party)];
+ unsigned char buf[4 + sizeof(struct party)];
- WBUFW (buf, 0) = 0x3821;
- memcpy (buf + 4, p, sizeof (struct party));
- WBUFW (buf, 2) = 4 + sizeof (struct party);
+ 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));
+ 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);
+ mapif_send(fd, buf, WBUFW(buf, 2));
+// PRINTF("int_party: info %d %s\n", p->party_id, p->name);
return 0;
}
// パーティメンãƒè¿½åŠ å¯å¦
static
-int mapif_party_memberadded (int fd, int party_id, int account_id, int flag)
+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);
+ WFIFOW(fd, 0) = 0x3822;
+ WFIFOL(fd, 2) = party_id;
+ WFIFOL(fd, 6) = account_id;
+ WFIFOB(fd, 10) = flag;
+ WFIFOSET(fd, 11);
return 0;
}
// パーティ設定変更通知
static
-int mapif_party_optionchanged (int fd, struct party *p, int account_id,
+int mapif_party_optionchanged(int fd, struct party *p, int account_id,
int flag)
{
unsigned char buf[15];
- 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;
+ 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);
+ mapif_sendall(buf, 15);
else
- mapif_send (fd, buf, 15);
- printf ("int_party: option changed %d %d %d %d %d\n", p->party_id,
+ 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;
@@ -367,62 +354,62 @@ int mapif_party_optionchanged (int fd, struct party *p, int account_id,
// パーティ脱退通知
static
-int mapif_party_leaved (int party_id, int account_id, char *name)
+int mapif_party_leaved(int party_id, int account_id, char *name)
{
unsigned char buf[34];
- 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);
+ 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;
}
// パーティマップ更新通知
static
-int mapif_party_membermoved (struct party *p, int idx)
+int mapif_party_membermoved(struct party *p, int idx)
{
unsigned char buf[29];
- 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);
+ 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)
+int mapif_party_broken(int party_id, int flag)
{
unsigned char buf[7];
- 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);
+ 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;
}
// パーティ内発言
static
-int mapif_party_message (int party_id, int account_id, const char *mes, int len)
+int mapif_party_message(int party_id, int account_id, const char *mes, int len)
{
unsigned char buf[len + 12];
- 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);
+ 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;
}
@@ -432,70 +419,69 @@ int mapif_party_message (int party_id, int account_id, const char *mes, int len)
// パーティ
static
-int mapif_parse_CreateParty (int fd, int account_id, const char *name, const char *nick,
+int mapif_parse_CreateParty(int fd, int account_id, const char *name, const char *nick,
const char *map, int lv)
{
- struct party *p;
- int i;
+ int i;
for (i = 0; i < 24 && name[i]; i++)
{
if (!(name[i] & 0xe0) || name[i] == 0x7f)
{
- printf ("int_party: illegal party name [%s]\n", name);
- mapif_party_created (fd, account_id, NULL);
+ PRINTF("int_party: illegal party name [%s]\n", name);
+ mapif_party_created(fd, account_id, NULL);
return 0;
}
}
- if ((p = search_partyname (name)) != NULL)
+ if (search_partyname(name) != NULL)
{
- printf ("int_party: same name party exists [%s]\n", name);
- mapif_party_created (fd, account_id, NULL);
+ PRINTF("int_party: same name party exists [%s]\n", name);
+ mapif_party_created(fd, account_id, NULL);
return 0;
}
- CREATE (p, struct party, 1);
- 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;
-
- numdb_insert (party_db, p->party_id, p);
-
- mapif_party_created (fd, account_id, p);
- mapif_party_info (fd, p);
+ struct party p {};
+ 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;
+
+ party_db.insert(p.party_id, p);
+
+ mapif_party_created(fd, account_id, &p);
+ mapif_party_info(fd, &p);
return 0;
}
// パーティ情報è¦æ±‚
static
-int mapif_parse_PartyInfo (int fd, int party_id)
+int mapif_parse_PartyInfo(int fd, int party_id)
{
- struct party *p = (struct party *)numdb_search (party_db, party_id);
+ struct party *p = party_db.search(party_id);
if (p != NULL)
- mapif_party_info (fd, p);
+ mapif_party_info(fd, p);
else
- mapif_party_noinfo (fd, party_id);
+ mapif_party_noinfo(fd, party_id);
return 0;
}
// パーティ追加è¦æ±‚
static
-int mapif_parse_PartyAddMember (int fd, int party_id, int account_id,
+int mapif_parse_PartyAddMember(int fd, int party_id, int account_id,
const char *nick, const char *map, int lv)
{
- struct party *p = (struct party *)numdb_search (party_db, party_id);
+ struct party *p = party_db.search(party_id);
if (p == NULL)
{
- mapif_party_memberadded (fd, party_id, account_id, 1);
+ mapif_party_memberadded(fd, party_id, account_id, 1);
return 0;
}
@@ -503,44 +489,44 @@ int mapif_parse_PartyAddMember (int fd, int party_id, int account_id,
{
if (p->member[i].account_id == 0)
{
- int flag = 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);
+ 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);
+ mapif_party_memberadded(fd, party_id, account_id, 0);
+ mapif_party_info(-1, p);
- if (p->exp > 0 && !party_check_exp_share (p))
+ if (p->exp > 0 && !party_check_exp_share(p))
{
p->exp = 0;
flag = 0x01;
}
if (flag)
- mapif_party_optionchanged (fd, p, 0, 0);
+ mapif_party_optionchanged(fd, p, 0, 0);
return 0;
}
}
- mapif_party_memberadded (fd, party_id, account_id, 1);
+ mapif_party_memberadded(fd, party_id, account_id, 1);
return 0;
}
// パーティー設定変更è¦æ±‚
static
-int mapif_parse_PartyChangeOption (int fd, int party_id, int account_id,
+int mapif_parse_PartyChangeOption(int fd, int party_id, int account_id,
int exp, int item)
{
- struct party *p = (struct party *)numdb_search (party_db, party_id);
+ struct party *p = party_db.search(party_id);
if (p == NULL)
return 0;
p->exp = exp;
- int flag = 0;
- if (exp > 0 && !party_check_exp_share (p))
+ int flag = 0;
+ if (exp > 0 && !party_check_exp_share(p))
{
flag |= 0x01;
p->exp = 0;
@@ -548,94 +534,85 @@ int mapif_parse_PartyChangeOption (int fd, int party_id, int account_id,
p->item = item;
- mapif_party_optionchanged (fd, p, account_id, flag);
+ mapif_party_optionchanged(fd, p, account_id, flag);
return 0;
}
// パーティ脱退è¦æ±‚
-int mapif_parse_PartyLeave (int fd, int party_id, int account_id)
+void mapif_parse_PartyLeave(int, int party_id, int account_id)
{
- struct party *p = (struct party *)numdb_search (party_db, party_id);
- if (p != NULL)
+ struct party *p = party_db.search(party_id);
+ if (!p)
+ return;
+ for (int i = 0; i < MAX_PARTY; i++)
{
- for (int i = 0; i < MAX_PARTY; i++)
- {
- if (p->member[i].account_id == account_id)
- {
- mapif_party_leaved (party_id, account_id, p->member[i].name);
+ if (p->member[i].account_id != account_id)
+ continue;
+ mapif_party_leaved(party_id, account_id, p->member[i].name);
- memset (&p->member[i], 0, sizeof (struct party_member));
- if (party_check_empty (p) == 0)
- mapif_party_info (-1, p); // ã¾ã äººãŒã„ã‚‹ã®ã§ãƒ‡ãƒ¼ã‚¿é€ä¿¡
- return 0;
- }
- }
+ memset(&p->member[i], 0, sizeof(struct party_member));
+ if (party_check_empty(p) == 0)
+ mapif_party_info(-1, p); // ã¾ã äººãŒã„ã‚‹ã®ã§ãƒ‡ãƒ¼ã‚¿é€ä¿¡
+ return;
}
-
- return 0;
}
// パーティマップ更新è¦æ±‚
static
-int mapif_parse_PartyChangeMap (int fd, int party_id, int account_id,
+void mapif_parse_PartyChangeMap(int fd, int party_id, int account_id,
const char *map, int online, int lv)
{
- struct party *p = (struct party *)numdb_search (party_db, party_id);
+ struct party *p = party_db.search(party_id);
if (p == NULL)
- return 0;
+ return;
for (int i = 0; i < MAX_PARTY; i++)
{
- if (p->member[i].account_id == account_id)
- {
- int flag = 0;
+ if (p->member[i].account_id != account_id)
+ continue;
+ 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);
+ 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;
+ if (p->exp > 0 && !party_check_exp_share(p))
+ {
+ p->exp = 0;
+ flag = 1;
}
+ if (flag)
+ mapif_party_optionchanged(fd, p, 0, 0);
+ return;
}
-
- return 0;
}
// パーティ解散è¦æ±‚
static
-int mapif_parse_BreakParty (int fd, int party_id)
+void mapif_parse_BreakParty(int fd, int party_id)
{
- struct party *p = (struct party *)numdb_search (party_db, party_id);
+ struct party *p = party_db.search(party_id);
if (p == NULL)
- return 0;
-
- numdb_erase (party_db, party_id);
- mapif_party_broken (fd, party_id);
+ return;
- return 0;
+ party_db.erase(party_id);
+ mapif_party_broken(fd, party_id);
}
// パーティメッセージé€ä¿¡
static
-int mapif_parse_PartyMessage (int fd, int party_id, int account_id, const char *mes,
+int mapif_parse_PartyMessage(int, int party_id, int account_id, const char *mes,
int len)
{
- return mapif_party_message (party_id, account_id, mes, len);
+ return mapif_party_message(party_id, account_id, mes, len);
}
// パーティãƒã‚§ãƒƒã‚¯è¦æ±‚
static
-int mapif_parse_PartyCheck (int fd, int party_id, int account_id, const char *nick)
+int mapif_parse_PartyCheck(int, int party_id, int account_id, const char *nick)
{
- return party_check_conflict (party_id, account_id, nick);
+ return party_check_conflict(party_id, account_id, nick);
}
// map server ã‹ã‚‰ã®é€šä¿¡
@@ -643,45 +620,45 @@ int mapif_parse_PartyCheck (int fd, int party_id, int account_id, const char *ni
// ・パケット長データã¯inter.cã«ã‚»ãƒƒãƒˆã—ã¦ãŠãã“ã¨
// ・パケット長ãƒã‚§ãƒƒã‚¯ã‚„ã€RFIFOSKIPã¯å‘¼ã³å‡ºã—å…ƒã§è¡Œã‚れるã®ã§è¡Œã£ã¦ã¯ãªã‚‰ãªã„
// ・エラーãªã‚‰0(false)ã€ãã†ã§ãªã„ãªã‚‰1(true)ã‚’ã‹ãˆã•ãªã‘ã‚Œã°ãªã‚‰ãªã„
-int inter_party_parse_frommap (int fd)
+int inter_party_parse_frommap(int fd)
{
- switch (RFIFOW (fd, 0))
+ switch (RFIFOW(fd, 0))
{
case 0x3020:
- mapif_parse_CreateParty (fd, RFIFOL (fd, 2), (const char *)RFIFOP (fd, 6),
- (const char *)RFIFOP (fd, 30), (const char *)RFIFOP (fd, 54),
- RFIFOW (fd, 70));
+ mapif_parse_CreateParty(fd, RFIFOL(fd, 2), (const char *)RFIFOP(fd, 6),
+ (const char *)RFIFOP(fd, 30), (const char *)RFIFOP(fd, 54),
+ RFIFOW(fd, 70));
break;
case 0x3021:
- mapif_parse_PartyInfo (fd, RFIFOL (fd, 2));
+ mapif_parse_PartyInfo(fd, RFIFOL(fd, 2));
break;
case 0x3022:
- mapif_parse_PartyAddMember (fd, RFIFOL (fd, 2), RFIFOL (fd, 6),
- (const char *)RFIFOP (fd, 10), (const char *)RFIFOP (fd, 34),
- RFIFOW (fd, 50));
+ mapif_parse_PartyAddMember(fd, RFIFOL(fd, 2), RFIFOL(fd, 6),
+ (const char *)RFIFOP(fd, 10), (const char *)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));
+ 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));
+ mapif_parse_PartyLeave(fd, RFIFOL(fd, 2), RFIFOL(fd, 6));
break;
case 0x3025:
- mapif_parse_PartyChangeMap (fd, RFIFOL (fd, 2), RFIFOL (fd, 6),
- (const char *)RFIFOP (fd, 10), RFIFOB (fd, 26),
- RFIFOW (fd, 27));
+ mapif_parse_PartyChangeMap(fd, RFIFOL(fd, 2), RFIFOL(fd, 6),
+ (const char *)RFIFOP(fd, 10), RFIFOB(fd, 26),
+ RFIFOW(fd, 27));
break;
case 0x3026:
- mapif_parse_BreakParty (fd, RFIFOL (fd, 2));
+ mapif_parse_BreakParty(fd, RFIFOL(fd, 2));
break;
case 0x3027:
- mapif_parse_PartyMessage (fd, RFIFOL (fd, 4), RFIFOL (fd, 8),
- (const char *)RFIFOP (fd, 12), RFIFOW (fd, 2) - 12);
+ mapif_parse_PartyMessage(fd, RFIFOL(fd, 4), RFIFOL(fd, 8),
+ (const char *)RFIFOP(fd, 12), RFIFOW(fd, 2) - 12);
break;
case 0x3028:
- mapif_parse_PartyCheck (fd, RFIFOL (fd, 2), RFIFOL (fd, 6),
- (const char *)RFIFOP (fd, 10));
+ mapif_parse_PartyCheck(fd, RFIFOL(fd, 2), RFIFOL(fd, 6),
+ (const char *)RFIFOP(fd, 10));
break;
default:
return 0;
@@ -691,7 +668,7 @@ int inter_party_parse_frommap (int fd)
}
// サーãƒãƒ¼ã‹ã‚‰è„±é€€è¦æ±‚(キャラ削除用)
-int inter_party_leave (int party_id, int account_id)
+void inter_party_leave(int party_id, int account_id)
{
- return mapif_parse_PartyLeave (-1, party_id, account_id);
+ mapif_parse_PartyLeave(-1, party_id, account_id);
}
diff --git a/src/char/int_party.hpp b/src/char/int_party.hpp
index 93e8887..8a59b49 100644
--- a/src/char/int_party.hpp
+++ b/src/char/int_party.hpp
@@ -1,14 +1,13 @@
-// $Id: int_party.h,v 1.1.1.1 2004/09/10 17:26:51 MagicalTux Exp $
#ifndef INT_PARTY_HPP
#define INT_PARTY_HPP
-int inter_party_init (void);
-int inter_party_save (void);
+int inter_party_init(void);
+int inter_party_save(void);
-int inter_party_parse_frommap (int fd);
+int inter_party_parse_frommap(int fd);
-int inter_party_leave (int party_id, int account_id);
+void inter_party_leave(int party_id, int account_id);
extern char party_txt[1024];
-#endif
+#endif // INT_PARTY_HPP
diff --git a/src/char/int_storage.cpp b/src/char/int_storage.cpp
index a962b92..ba55538 100644
--- a/src/char/int_storage.cpp
+++ b/src/char/int_storage.cpp
@@ -1,442 +1,161 @@
-// $Id: int_storage.c,v 1.1.1.1 2004/09/10 17:26:51 MagicalTux Exp $
+#include "int_storage.hpp"
-#include <string.h>
-#include <stdlib.h>
+#include <cstdlib>
+#include <cstring>
-#include "../common/mmo.hpp"
-#include "../common/socket.hpp"
+#include <functional>
+#include <fstream>
+
+#include "../common/cxxstdio.hpp"
#include "../common/db.hpp"
+#include "../common/extract.hpp"
#include "../common/lock.hpp"
-#include "char.hpp"
-#include "inter.hpp"
-#include "int_storage.hpp"
-#include "int_guild.hpp"
+#include "../common/mmo.hpp"
+#include "../common/socket.hpp"
+
+#include "../poison.hpp"
// ファイルåã®ãƒ‡ãƒ•ã‚©ãƒ«ãƒˆ
// inter_config_read()ã§å†è¨­å®šã•ã‚Œã‚‹
char storage_txt[1024] = "save/storage.txt";
-char guild_storage_txt[1024] = "save/g_storage.txt";
-static struct dbt *storage_db;
-static struct dbt *guild_storage_db;
+static
+Map<int, struct storage> storage_db;
// 倉庫データを文字列ã«å¤‰æ›
static
-int storage_tostr (char *str, struct storage *p)
+std::string storage_tostr(struct storage *p)
{
- int i, f = 0;
- char *str_p = str;
- str_p += sprintf (str_p, "%d,%d\t", p->account_id, p->storage_amount);
+ std::string str = STRPRINTF(
+ "%d,%d\t",
+ p->account_id, p->storage_amount);
- for (i = 0; i < MAX_STORAGE; i++)
- if ((p->storage_[i].nameid) && (p->storage_[i].amount))
+ int f = 0;
+ for (int i = 0; i < MAX_STORAGE; i++)
+ if (p->storage_[i].nameid && p->storage_[i].amount)
{
- str_p += sprintf (str_p, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d ",
- p->storage_[i].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]);
+ str += STRPRINTF(
+ "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d ",
+ p->storage_[i].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]);
f++;
}
- *(str_p++) = '\t';
+ str += '\t';
- *str_p = '\0';
if (!f)
- str[0] = 0;
- return 0;
+ str.clear();
+ return str;
}
// 文字列を倉庫データã«å¤‰æ›
static
-int storage_fromstr (char *str, struct storage *p)
+bool extract(const_string str, struct storage *p)
{
- int tmp_int[256];
- int set, next, len, i;
+ std::vector<struct item> storage_items;
+ if (!extract(str,
+ record<'\t'>(
+ record<','>(
+ &p->account_id,
+ &p->storage_amount),
+ vrec<' '>(&storage_items))))
+ return false;
- set = sscanf (str, "%d,%d%n", &tmp_int[0], &tmp_int[1], &next);
- p->storage_amount = tmp_int[1];
+ if (p->account_id <= 0)
+ return false;
- if (set != 2)
- return 1;
- if (str[next] == '\n' || str[next] == '\r')
- return 0;
- next++;
- for (i = 0; str[next] && str[next] != '\t' && i < MAX_STORAGE; 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[10], &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];
- 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];
- next += len;
- if (str[next] == ' ')
- next++;
- }
+ if (storage_items.size() >= MAX_STORAGE)
+ return false;
+ std::copy(storage_items.begin(), storage_items.end(), p->storage_);
- else
- return 1;
- }
- if (i >= MAX_STORAGE && str[next] && str[next] != '\t')
- printf
- ("storage_fromstr: Found a storage line with more items than MAX_STORAGE (%d), remaining items have been discarded!\n",
- MAX_STORAGE);
- return 0;
-}
-
-static
-int guild_storage_tostr (char *str, struct guild_storage *p)
-{
- int i, f = 0;
- char *str_p = str;
- str_p += sprintf (str, "%d,%d\t", p->guild_id, p->storage_amount);
-
- for (i = 0; i < MAX_GUILD_STORAGE; i++)
- if ((p->storage_[i].nameid) && (p->storage_[i].amount))
- {
- str_p += sprintf (str_p, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d ",
- p->storage_[i].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]);
- f++;
- }
-
- *(str_p++) = '\t';
-
- *str_p = '\0';
- if (!f)
- str[0] = 0;
- return 0;
-}
-
-static
-int guild_storage_fromstr (char *str, struct guild_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 1;
- if (str[next] == '\n' || str[next] == '\r')
- return 0;
- next++;
- for (i = 0; str[next] && str[next] != '\t' && i < MAX_GUILD_STORAGE; 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[10], &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];
- 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];
- next += len;
- if (str[next] == ' ')
- next++;
- }
-
- else
- return 1;
- }
- if (i >= MAX_GUILD_STORAGE && str[next] && str[next] != '\t')
- printf
- ("guild_storage_fromstr: Found a storage line with more items than MAX_GUILD_STORAGE (%d), remaining items have been discarded!\n",
- MAX_GUILD_STORAGE);
- return 0;
+ return true;
}
// アカウントã‹ã‚‰å€‰åº«ãƒ‡ãƒ¼ã‚¿ã‚¤ãƒ³ãƒ‡ãƒƒã‚¯ã‚¹ã‚’得る(新è¦å€‰åº«è¿½åŠ å¯èƒ½ï¼‰
-struct storage *account2storage (int account_id)
+struct storage *account2storage(int account_id)
{
- struct storage *s;
- s = (struct storage *) numdb_search (storage_db, account_id);
+ struct storage *s = storage_db.search(account_id);
if (s == NULL)
{
- CREATE (s, struct storage, 1);
- memset (s, 0, sizeof (struct storage));
+ s = storage_db.init(account_id);
s->account_id = account_id;
- numdb_insert (storage_db, s->account_id, s);
}
return s;
}
-static
-struct guild_storage *guild2storage (int guild_id)
-{
- struct guild_storage *gs = NULL;
- if (inter_guild_search (guild_id) != NULL)
- {
- gs = (struct guild_storage *) numdb_search (guild_storage_db,
- guild_id);
- if (gs == NULL)
- {
- CREATE (gs, struct guild_storage, 1);
- gs->guild_id = guild_id;
- numdb_insert (guild_storage_db, gs->guild_id, gs);
- }
- }
- return gs;
-}
-
//---------------------------------------------------------
// 倉庫データを読ã¿è¾¼ã‚€
-int inter_storage_init (void)
+int inter_storage_init(void)
{
- char line[65536];
- int c = 0, tmp_int;
- struct storage *s;
- struct guild_storage *gs;
- FILE *fp;
-
- storage_db = numdb_init ();
+ int c = 0;
- fp = fopen_ (storage_txt, "r");
- if (fp == NULL)
+ std::ifstream in(storage_txt);
+ if (!in.is_open())
{
- printf ("cant't read : %s\n", storage_txt);
+ PRINTF("cant't read : %s\n", storage_txt);
return 1;
}
- while (fgets (line, 65535, fp))
- {
- sscanf (line, "%d", &tmp_int);
- CREATE (s, struct storage, 1);
- s->account_id = tmp_int;
- if (s->account_id > 0 && storage_fromstr (line, s) == 0)
- {
- numdb_insert (storage_db, s->account_id, s);
- }
- else
- {
- printf ("int_storage: broken data [%s] line %d\n", storage_txt,
- c);
- free (s);
- }
- c++;
- }
- fclose_ (fp);
-
- c = 0;
- guild_storage_db = numdb_init ();
- fp = fopen_ (guild_storage_txt, "r");
- if (fp == NULL)
- {
- printf ("cant't read : %s\n", guild_storage_txt);
- return 1;
- }
- while (fgets (line, 65535, fp))
+ std::string line;
+ while (std::getline(in, line))
{
- sscanf (line, "%d", &tmp_int);
- CREATE (gs, struct guild_storage, 1);
- gs->guild_id = tmp_int;
- if (gs->guild_id > 0 && guild_storage_fromstr (line, gs) == 0)
+ struct storage s {};
+ if (extract(line, &s))
{
- numdb_insert (guild_storage_db, gs->guild_id, gs);
+ storage_db.insert(s.account_id, s);
}
else
{
- printf ("int_storage: broken data [%s] line %d\n",
- guild_storage_txt, c);
- free (gs);
+ PRINTF("int_storage: broken data [%s] line %d\n",
+ storage_txt, c);
}
c++;
}
- fclose_ (fp);
return 0;
}
static
-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);
-}
-
-static
-void guild_storage_db_final (db_key_t k, db_val_t data, va_list ap)
+void inter_storage_save_sub(struct storage *data, FILE *fp)
{
- struct guild_storage *p = (struct guild_storage *) data;
- if (p)
- free (p);
-}
-
-void inter_storage_final (void)
-{
- numdb_final (storage_db, storage_db_final);
- numdb_final (guild_storage_db, guild_storage_db_final);
- return;
-}
-
-static
-void inter_storage_save_sub (db_key_t key, db_val_t data, va_list ap)
-{
- char line[65536];
- FILE *fp;
- storage_tostr (line, (struct storage *) data);
- fp = va_arg (ap, FILE *);
- if (*line)
- fprintf (fp, "%s\n", line);
+ std::string line = storage_tostr(data);
+ if (!line.empty())
+ FPRINTF(fp, "%s\n", line);
}
//---------------------------------------------------------
// 倉庫データを書ã込む
-int inter_storage_save (void)
+int inter_storage_save(void)
{
FILE *fp;
- int lock;
-
- if (!storage_db)
- return 1;
+ int lock;
- if ((fp = lock_fopen (storage_txt, &lock)) == NULL)
+ if ((fp = lock_fopen(storage_txt, &lock)) == NULL)
{
- printf ("int_storage: cant write [%s] !!! data is lost !!!\n",
+ PRINTF("int_storage: cant write [%s] !!! data is lost !!!\n",
storage_txt);
return 1;
}
- numdb_foreach (storage_db, inter_storage_save_sub, fp);
- lock_fclose (fp, storage_txt, &lock);
-// printf("int_storage: %s saved.\n",storage_txt);
- return 0;
-}
-
-static
-void inter_guild_storage_save_sub (db_key_t key, db_val_t data, va_list ap)
-{
- char line[65536];
- FILE *fp;
-
- if (inter_guild_search (((struct guild_storage *) data)->guild_id) !=
- NULL)
- {
- guild_storage_tostr (line, (struct guild_storage *) data);
- fp = va_arg (ap, FILE *);
- if (*line)
- fprintf (fp, "%s\n", line);
- }
-}
-
-//---------------------------------------------------------
-// 倉庫データを書ã込む
-int inter_guild_storage_save (void)
-{
- FILE *fp;
- int lock;
-
- if (!guild_storage_db)
- return 1;
-
- if ((fp = lock_fopen (guild_storage_txt, &lock)) == NULL)
- {
- printf ("int_storage: cant write [%s] !!! data is lost !!!\n",
- guild_storage_txt);
- return 1;
- }
- numdb_foreach (guild_storage_db, inter_guild_storage_save_sub, fp);
- lock_fclose (fp, guild_storage_txt, &lock);
-// printf("int_storage: %s saved.\n",guild_storage_txt);
+ for (auto& pair : storage_db)
+ inter_storage_save_sub(&pair.second, fp);
+ lock_fclose(fp, storage_txt, &lock);
+// PRINTF("int_storage: %s saved.\n",storage_txt);
return 0;
}
// 倉庫データ削除
-int inter_storage_delete (int account_id)
+void inter_storage_delete(int account_id)
{
- struct storage *s =
- (struct storage *) numdb_search (storage_db, account_id);
- if (s)
- {
- numdb_erase (storage_db, account_id);
- free (s);
- }
- return 0;
-}
-
-// ギルド倉庫データ削除
-int inter_guild_storage_delete (int guild_id)
-{
- struct guild_storage *gs =
- (struct guild_storage *) numdb_search (guild_storage_db, guild_id);
- if (gs)
- {
- numdb_erase (guild_storage_db, guild_id);
- free (gs);
- }
- return 0;
+ storage_db.erase(account_id);
}
//---------------------------------------------------------
@@ -444,60 +163,25 @@ int inter_guild_storage_delete (int guild_id)
// 倉庫データã®é€ä¿¡
static
-int mapif_load_storage (int fd, int account_id)
+int mapif_load_storage(int fd, int account_id)
{
- struct storage *s = account2storage (account_id);
- WFIFOW (fd, 0) = 0x3810;
- WFIFOW (fd, 2) = sizeof (struct storage) + 8;
- WFIFOL (fd, 4) = account_id;
- memcpy (WFIFOP (fd, 8), s, sizeof (struct storage));
- WFIFOSET (fd, WFIFOW (fd, 2));
+ struct storage *s = account2storage(account_id);
+ WFIFOW(fd, 0) = 0x3810;
+ WFIFOW(fd, 2) = sizeof(struct storage) + 8;
+ WFIFOL(fd, 4) = account_id;
+ memcpy(WFIFOP(fd, 8), s, sizeof(struct storage));
+ WFIFOSET(fd, WFIFOW(fd, 2));
return 0;
}
// 倉庫データä¿å­˜å®Œäº†é€ä¿¡
static
-int mapif_save_storage_ack (int fd, int account_id)
+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;
-}
-
-static
-int mapif_load_guild_storage (int fd, int account_id, int guild_id)
-{
- struct guild_storage *gs = guild2storage (guild_id);
- WFIFOW (fd, 0) = 0x3818;
- if (gs)
- {
- WFIFOW (fd, 2) = sizeof (struct guild_storage) + 12;
- WFIFOL (fd, 4) = account_id;
- WFIFOL (fd, 8) = guild_id;
- memcpy (WFIFOP (fd, 12), gs, 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;
-}
-
-static
-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);
+ WFIFOW(fd, 0) = 0x3811;
+ WFIFOL(fd, 2) = account_id;
+ WFIFOB(fd, 6) = 0;
+ WFIFOSET(fd, 7);
return 0;
}
@@ -506,61 +190,29 @@ int mapif_save_guild_storage_ack (int fd, int account_id, int guild_id,
// 倉庫データè¦æ±‚å—ä¿¡
static
-int mapif_parse_LoadStorage (int fd)
+int mapif_parse_LoadStorage(int fd)
{
- mapif_load_storage (fd, RFIFOL (fd, 2));
+ mapif_load_storage(fd, RFIFOL(fd, 2));
return 0;
}
// 倉庫データå—信&ä¿å­˜
static
-int mapif_parse_SaveStorage (int fd)
+int mapif_parse_SaveStorage(int fd)
{
struct storage *s;
- 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
+ int account_id = RFIFOL(fd, 4);
+ int len = RFIFOW(fd, 2);
+ if (sizeof(struct storage) != len - 8)
{
- s = account2storage (account_id);
- memcpy (s, RFIFOP (fd, 8), sizeof (struct storage));
- mapif_save_storage_ack (fd, account_id);
- }
- return 0;
-}
-
-static
-int mapif_parse_LoadGuildStorage (int fd)
-{
- mapif_load_guild_storage (fd, RFIFOL (fd, 2), RFIFOL (fd, 6));
- return 0;
-}
-
-static
-int mapif_parse_SaveGuildStorage (int fd)
-{
- struct guild_storage *gs;
- 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);
+ PRINTF("inter storage: data size error %zu %d\n",
+ sizeof(struct storage), len - 8);
}
else
{
- gs = guild2storage (guild_id);
- if (gs)
- {
- memcpy (gs, RFIFOP (fd, 12), sizeof (struct guild_storage));
- 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);
+ s = account2storage(account_id);
+ memcpy(s, RFIFOP(fd, 8), sizeof(struct storage));
+ mapif_save_storage_ack(fd, account_id);
}
return 0;
}
@@ -570,21 +222,15 @@ int mapif_parse_SaveGuildStorage (int fd)
// ・パケット長データã¯inter.cã«ã‚»ãƒƒãƒˆã—ã¦ãŠãã“ã¨
// ・パケット長ãƒã‚§ãƒƒã‚¯ã‚„ã€RFIFOSKIPã¯å‘¼ã³å‡ºã—å…ƒã§è¡Œã‚れるã®ã§è¡Œã£ã¦ã¯ãªã‚‰ãªã„
// ・エラーãªã‚‰0(false)ã€ãã†ã§ãªã„ãªã‚‰1(true)ã‚’ã‹ãˆã•ãªã‘ã‚Œã°ãªã‚‰ãªã„
-int inter_storage_parse_frommap (int fd)
+int inter_storage_parse_frommap(int fd)
{
- switch (RFIFOW (fd, 0))
+ switch (RFIFOW(fd, 0))
{
case 0x3010:
- mapif_parse_LoadStorage (fd);
+ 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);
+ mapif_parse_SaveStorage(fd);
break;
default:
return 0;
diff --git a/src/char/int_storage.hpp b/src/char/int_storage.hpp
index 9986f2d..691f16d 100644
--- a/src/char/int_storage.hpp
+++ b/src/char/int_storage.hpp
@@ -1,18 +1,13 @@
-// $Id: int_storage.h,v 1.1.1.1 2004/09/10 17:26:51 MagicalTux Exp $
#ifndef INT_STORAGE_HPP
#define INT_STORAGE_HPP
-int inter_storage_init (void);
-void inter_storage_final (void);
-int inter_storage_save (void);
-int inter_guild_storage_save (void);
-int inter_storage_delete (int account_id);
-int inter_guild_storage_delete (int guild_id);
-struct storage *account2storage (int account_id);
+int inter_storage_init(void);
+int inter_storage_save(void);
+void inter_storage_delete(int account_id);
+struct storage *account2storage(int account_id);
-int inter_storage_parse_frommap (int fd);
+int inter_storage_parse_frommap(int fd);
extern char storage_txt[1024];
-extern char guild_storage_txt[1024];
-#endif
+#endif // INT_STORAGE_HPP
diff --git a/src/char/inter.cpp b/src/char/inter.cpp
index 7752cb4..9efb28c 100644
--- a/src/char/inter.cpp
+++ b/src/char/inter.cpp
@@ -1,50 +1,50 @@
-// $Id: inter.c,v 1.1.1.1 2004/09/10 17:26:51 MagicalTux Exp $
-#include "../common/mmo.hpp"
-#include "char.hpp"
+#include "inter.hpp"
+
+#include <cassert>
+#include <cstdlib>
+#include <cstring>
+
+#include <fstream>
+#include <vector>
+
+#include "../common/cxxstdio.hpp"
+#include "../common/db.hpp"
+#include "../common/extract.hpp"
+#include "../common/lock.hpp"
#include "../common/socket.hpp"
#include "../common/timer.hpp"
-#include "../common/db.hpp"
-#include <string.h>
-#include <stdlib.h>
+#include "../common/utils.hpp"
-#include "inter.hpp"
+#include "char.hpp"
#include "int_party.hpp"
-#include "int_guild.hpp"
#include "int_storage.hpp"
-#include "../common/lock.hpp"
-#define WISDATA_TTL (60*1000) // Existence time of Wisp/page data (60 seconds)
- // that is the waiting time of answers of all map-servers
-#define WISDELLIST_MAX 256 // Number of elements of Wisp/page data deletion list
+#include "../poison.hpp"
+
+// Existence time of Wisp/page data (60 seconds)
+// that is the waiting time of answers of all map-servers
+constexpr std::chrono::minutes WISDATA_TTL = std::chrono::minutes(1);
+// Number of elements of Wisp/page data deletion list
+constexpr int WISDELLIST_MAX = 256;
char inter_log_filename[1024] = "log/inter.log";
+static
char accreg_txt[1024] = "save/accreg.txt";
-static struct dbt *accreg_db = NULL;
struct accreg
{
- int account_id, reg_num;
+ int account_id, reg_num;
struct global_reg reg[ACCOUNT_REG_NUM];
};
+static
+Map<int, struct accreg> accreg_db;
-int party_share_level = 10;
-
-// é€ä¿¡ãƒ‘ケット長リスト
-int inter_send_packet_length[] = {
- -1, -1, 27, -1, -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,
-};
+int party_share_level = 10;
// å—信パケット長リスト
-int inter_recv_packet_length[] = {
+static
+int inter_recv_packet_length[] = {
-1, -1, 7, -1, -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,
@@ -58,122 +58,104 @@ int inter_recv_packet_length[] = {
struct WisData
{
- int id, fd, count, len;
- unsigned long tick;
- unsigned char src[24], dst[24], msg[1024];
+ int id, fd, count;
+ tick_t tick;
+ unsigned char src[24], dst[24];
+ std::string msg;
};
-static struct dbt *wis_db = NULL;
-static int wis_dellist[WISDELLIST_MAX], wis_delnum;
+static
+Map<int, struct WisData> wis_db;
+static
+int wis_dellist[WISDELLIST_MAX], wis_delnum;
//--------------------------------------------------------
// アカウント変数を文字列ã¸å¤‰æ›
static
-int inter_accreg_tostr (char *str, struct accreg *reg)
+std::string inter_accreg_tostr(struct accreg *reg)
{
- int j;
- char *p = str;
-
- p += sprintf (p, "%d\t", reg->account_id);
- for (j = 0; j < reg->reg_num; j++)
- {
- p += sprintf (p, "%s,%d ", reg->reg[j].str, reg->reg[j].value);
- }
-
- return 0;
+ std::string str STRPRINTF("%d\t", reg->account_id);
+ for (int j = 0; j < reg->reg_num; j++)
+ str += STRPRINTF("%s,%d ", reg->reg[j].str, reg->reg[j].value);
+ return str;
}
// アカウント変数を文字列ã‹ã‚‰å¤‰æ›
static
-int inter_accreg_fromstr (const char *str, struct accreg *reg)
+bool extract(const_string str, struct accreg *reg)
{
- int j, v, n;
- char buf[128];
- const char *p = str;
-
- if (sscanf (p, "%d\t%n", &reg->account_id, &n) != 1
- || reg->account_id <= 0)
- return 1;
-
- for (j = 0, p += n; j < ACCOUNT_REG_NUM; j++, p += n)
- {
- if (sscanf (p, "%[^,],%d %n", buf, &v, &n) != 2)
- break;
- memcpy (reg->reg[j].str, buf, 32);
- reg->reg[j].value = v;
- }
- reg->reg_num = j;
-
- return 0;
+ std::vector<struct global_reg> vars;
+ if (!extract(str,
+ record<'\t'>(
+ &reg->account_id,
+ vrec<' '>(&vars))))
+ return false;
+ if (reg->account_id <= 0)
+ return false;
+
+ if (vars.size() > ACCOUNT_REG_NUM)
+ return false;
+ std::copy(vars.begin(), vars.end(), reg->reg);
+ reg->reg_num = vars.size();
+ return true;
}
// アカウント変数ã®èª­ã¿è¾¼ã¿
static
-int inter_accreg_init (void)
+int inter_accreg_init(void)
{
- char line[8192];
- FILE *fp;
- int c = 0;
- struct accreg *reg;
-
- accreg_db = numdb_init ();
+ int c = 0;
- if ((fp = fopen_ (accreg_txt, "r")) == NULL)
+ std::ifstream in(accreg_txt);
+ if (!in.is_open())
return 1;
- while (fgets (line, sizeof (line) - 1, fp))
+ std::string line;
+ while (std::getline(in, line))
{
- line[sizeof (line) - 1] = '\0';
- CREATE (reg, struct accreg, 1);
- if (inter_accreg_fromstr (line, reg) == 0 && reg->account_id > 0)
+ struct accreg reg {};
+ if (extract(line, &reg))
{
- numdb_insert (accreg_db, reg->account_id, reg);
+ accreg_db.insert(reg.account_id, reg);
}
else
{
- printf ("inter: accreg: broken data [%s] line %d\n", accreg_txt,
+ PRINTF("inter: accreg: broken data [%s] line %d\n", accreg_txt,
c);
- free (reg);
}
c++;
}
- fclose_ (fp);
-// printf("inter: %s read done (%d)\n", accreg_txt, c);
return 0;
}
// アカウント変数ã®ã‚»ãƒ¼ãƒ–用
static
-void inter_accreg_save_sub (db_key_t key, db_val_t data, va_list ap)
+void inter_accreg_save_sub(struct accreg *reg, FILE *fp)
{
- char line[8192];
- FILE *fp;
- struct accreg *reg = (struct accreg *) data;
-
if (reg->reg_num > 0)
{
- inter_accreg_tostr (line, reg);
- fp = va_arg (ap, FILE *);
- fprintf (fp, "%s\n", line);
+ std::string line = inter_accreg_tostr(reg);
+ fwrite(line.data(), 1, line.size(), fp);
+ fputc('\n', fp);
}
}
// アカウント変数ã®ã‚»ãƒ¼ãƒ–
static
-int inter_accreg_save (void)
+int inter_accreg_save(void)
{
FILE *fp;
- int lock;
+ int lock;
- if ((fp = lock_fopen (accreg_txt, &lock)) == NULL)
+ if ((fp = lock_fopen(accreg_txt, &lock)) == NULL)
{
- printf ("int_accreg: cant write [%s] !!! data is lost !!!\n",
+ PRINTF("int_accreg: cant write [%s] !!! data is lost !!!\n",
accreg_txt);
return 1;
}
- numdb_foreach (accreg_db, inter_accreg_save_sub, fp);
- lock_fclose (fp, accreg_txt, &lock);
-// printf("inter: %s saved.\n", accreg_txt);
+ for (auto& pair : accreg_db)
+ inter_accreg_save_sub(&pair.second, fp);
+ lock_fclose(fp, accreg_txt, &lock);
return 0;
}
@@ -185,119 +167,75 @@ int inter_accreg_save (void)
*------------------------------------------
*/
static
-int inter_config_read (const char *cfgName)
+int inter_config_read(const char *cfgName)
{
- char line[1024], w1[1024], w2[1024];
- FILE *fp;
-
- fp = fopen_ (cfgName, "r");
- if (fp == NULL)
+ std::ifstream in(cfgName);
+ if (!in.is_open())
{
- printf ("file not found: %s\n", cfgName);
+ PRINTF("file not found: %s\n", cfgName);
return 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)
+ std::string line;
+ while (std::getline(in, line))
+ {
+ std::string w1, w2;
+ if (!split_key_value(line, &w1, &w2))
continue;
- if (strcasecmp (w1, "storage_txt") == 0)
+ if (w1 == "storage_txt")
{
- strncpy (storage_txt, w2, sizeof (storage_txt));
+ strzcpy(storage_txt, w2.c_str(), sizeof(storage_txt));
}
- else if (strcasecmp (w1, "party_txt") == 0)
+ else if (w1 == "party_txt")
{
- strncpy (party_txt, w2, sizeof (party_txt));
+ strzcpy(party_txt, w2.c_str(), sizeof(party_txt));
}
- else if (strcasecmp (w1, "guild_txt") == 0)
+ else if (w1 == "accreg_txt")
{
- strncpy (guild_txt, w2, sizeof (guild_txt));
+ strzcpy(accreg_txt, w2.c_str(), sizeof(accreg_txt));
}
- else if (strcasecmp (w1, "castle_txt") == 0)
+ else if (w1 == "party_share_level")
{
- strncpy (castle_txt, w2, sizeof (castle_txt));
- }
- else if (strcasecmp (w1, "accreg_txt") == 0)
- {
- strncpy (accreg_txt, w2, sizeof (accreg_txt));
- }
- else if (strcasecmp (w1, "guild_storage_txt") == 0)
- {
- strncpy (guild_storage_txt, w2, sizeof (guild_storage_txt));
- }
- else if (strcasecmp (w1, "party_share_level") == 0)
- {
- party_share_level = atoi (w2);
+ party_share_level = atoi(w2.c_str());
if (party_share_level < 0)
party_share_level = 0;
}
- else if (strcasecmp (w1, "inter_log_filename") == 0)
+ else if (w1 == "inter_log_filename")
{
- strncpy (inter_log_filename, w2, sizeof (inter_log_filename));
+ strzcpy(inter_log_filename, w2.c_str(), sizeof(inter_log_filename));
}
- else if (strcasecmp (w1, "import") == 0)
+ else if (w1 == "import")
{
- inter_config_read (w2);
+ inter_config_read(w2.c_str());
+ }
+ else
+ {
+ PRINTF("WARNING: unknown inter config key: %s\n", w1);
}
}
- fclose_ (fp);
-
- return 0;
-}
-
-// ログ書ã出ã—
-int inter_log (const char *fmt, ...)
-{
- FILE *logfp;
- va_list ap;
-
- va_start (ap, fmt);
- logfp = fopen_ (inter_log_filename, "a");
- if (logfp)
- {
- vfprintf (logfp, fmt, ap);
- fclose_ (logfp);
- }
- va_end (ap);
return 0;
}
// セーブ
-int inter_save (void)
+int inter_save(void)
{
- inter_party_save ();
- inter_guild_save ();
- inter_storage_save ();
- inter_guild_storage_save ();
- inter_accreg_save ();
+ inter_party_save();
+ inter_storage_save();
+ inter_accreg_save();
return 0;
}
// åˆæœŸåŒ–
-int inter_init (const char *file)
+int inter_init(const char *file)
{
- inter_config_read (file);
-
- wis_db = numdb_init ();
-
- inter_party_init ();
- inter_guild_init ();
- inter_storage_init ();
- inter_accreg_init ();
-
- return 0;
-}
+ inter_config_read(file);
-// マップサーãƒãƒ¼æŽ¥ç¶š
-int inter_mapif_init (int fd)
-{
- inter_guild_mapif_init (fd);
+ inter_party_init();
+ inter_storage_init();
+ inter_accreg_init();
return 0;
}
@@ -307,87 +245,83 @@ int inter_mapif_init (int fd)
// GMメッセージé€ä¿¡
static
-int mapif_GMmessage (unsigned char *mes, int len)
+void mapif_GMmessage(const uint8_t *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("inter server: GM:%d %s\n", len, mes);
-
- return 0;
+ WBUFW(buf, 0) = 0x3800;
+ WBUFW(buf, 2) = len;
+ memcpy(WBUFP(buf, 4), mes, len - 4);
+ mapif_sendall(buf, len);
}
// Wisp/page transmission to all map-server
static
-int mapif_wis_message (struct WisData *wd)
+int mapif_wis_message(struct WisData *wd)
{
- unsigned char buf[56 + wd->len];
+ unsigned char buf[56 + wd->msg.size()];
- 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));
+ WBUFW(buf, 0) = 0x3801;
+ WBUFW(buf, 2) = 56 + wd->msg.size();
+ 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.data(), wd->msg.size());
+ wd->count = mapif_sendall(buf, WBUFW(buf, 2));
return 0;
}
// Wisp/page transmission result to map-server
static
-int mapif_wis_end (struct WisData *wd, int flag)
+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; // flag: 0: success to send wisper, 1: target character is not loged in?, 2: ignored by target
- mapif_send (wd->fd, buf, 27);
-// printf("inter server wis_end: flag: %d\n", flag);
+ WBUFW(buf, 0) = 0x3802;
+ memcpy(WBUFP(buf, 2), wd->src, 24);
+ WBUFB(buf, 26) = flag; // flag: 0: success to send wisper, 1: target character is not loged in?, 2: ignored by target
+ mapif_send(wd->fd, buf, 27);
return 0;
}
// アカウント変数é€ä¿¡
static
-int mapif_account_reg (int fd, unsigned char *src)
+int mapif_account_reg(int fd, const uint8_t *src)
{
- unsigned char buf[WBUFW (src, 2)];
+ unsigned char buf[RBUFW(src, 2)];
- memcpy (WBUFP (buf, 0), src, WBUFW (src, 2));
- WBUFW (buf, 0) = 0x3804;
- mapif_sendallwos (fd, buf, WBUFW (buf, 2));
+ memcpy(WBUFP(buf, 0), src, RBUFW(src, 2));
+ WBUFW(buf, 0) = 0x3804;
+ mapif_sendallwos(fd, buf, WBUFW(buf, 2));
return 0;
}
// アカウント変数è¦æ±‚返信
static
-int mapif_account_reg_reply (int fd, int account_id)
+int mapif_account_reg_reply(int fd, int account_id)
{
- struct accreg *reg = (struct accreg *)numdb_search (accreg_db, account_id);
+ struct accreg *reg = accreg_db.search(account_id);
- WFIFOW (fd, 0) = 0x3804;
- WFIFOL (fd, 4) = account_id;
+ WFIFOW(fd, 0) = 0x3804;
+ WFIFOL(fd, 4) = account_id;
if (reg == NULL)
{
- WFIFOW (fd, 2) = 8;
+ WFIFOW(fd, 2) = 8;
}
else
{
- int j, p;
+ 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;
+ memcpy(WFIFOP(fd, p), reg->reg[j].str, 32);
+ WFIFOL(fd, p + 32) = reg->reg[j].value;
}
- WFIFOW (fd, 2) = p;
+ WFIFOW(fd, 2) = p;
}
- WFIFOSET (fd, WFIFOW (fd, 2));
+ WFIFOSET(fd, WFIFOW(fd, 2));
return 0;
}
@@ -396,36 +330,33 @@ int mapif_account_reg_reply (int fd, int account_id)
// Existence check of WISP data
static
-void check_ttl_wisdata_sub (db_key_t key, db_val_t data, va_list ap)
+void check_ttl_wisdata_sub(struct WisData *wd, tick_t tick)
{
- unsigned long tick;
- struct WisData *wd = (struct WisData *) data;
- tick = va_arg (ap, unsigned long);
-
- if (DIFF_TICK (tick, wd->tick) > WISDATA_TTL
+ if (tick > wd->tick + WISDATA_TTL
&& wis_delnum < WISDELLIST_MAX)
wis_dellist[wis_delnum++] = wd->id;
}
static
-int check_ttl_wisdata (void)
+int check_ttl_wisdata(void)
{
- unsigned long tick = gettick ();
- int i;
+ tick_t tick = gettick();
+ int i;
do
{
wis_delnum = 0;
- numdb_foreach (wis_db, check_ttl_wisdata_sub, tick);
+ for (auto& pair : wis_db)
+ check_ttl_wisdata_sub(&pair.second, tick);
for (i = 0; i < wis_delnum; i++)
{
- struct WisData *wd = (struct WisData *)numdb_search (wis_db, wis_dellist[i]);
- printf ("inter: wis data id=%d time out : from %s to %s\n",
+ struct WisData *wd = wis_db.search(wis_dellist[i]);
+ assert (wd);
+ 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);
+ wis_db.erase(wd->id);
}
}
while (wis_delnum >= WISDELLIST_MAX);
@@ -438,72 +369,65 @@ int check_ttl_wisdata (void)
// GMメッセージé€ä¿¡
static
-int mapif_parse_GMmessage (int fd)
+int mapif_parse_GMmessage(int fd)
{
- mapif_GMmessage (RFIFOP (fd, 4), RFIFOW (fd, 2));
+ mapif_GMmessage(static_cast<const uint8_t *>(RFIFOP(fd, 4)), RFIFOW(fd, 2));
return 0;
}
// Wisp/page request to send
static
-int mapif_parse_WisRequest (int fd)
+int mapif_parse_WisRequest(int fd)
{
- struct WisData *wd;
static int wisid = 0;
- int index;
+ int index;
- 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)
+ if (RFIFOW(fd, 2) - 52 <= 0)
{ // normaly, impossible, but who knows...
- printf ("inter: Wis message doesn't exist.\n");
+ PRINTF("inter: Wis message doesn't exist.\n");
return 0;
}
// search if character exists before to ask all map-servers
- if ((index = search_character_index ((const char *)RFIFOP (fd, 28))) == -1)
+ if ((index = search_character_index((const char *)RFIFOP(fd, 28))) == -1)
{
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);
+ 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 ((char *)RFIFOP (fd, 28), search_character_name (index), 24);
+ strzcpy(static_cast<char *>(const_cast<void *>(RFIFOP(fd, 28))), search_character_name(index), 24);
// if source is destination, don't ask other servers.
- if (strcmp ((const char *)RFIFOP (fd, 4), (const char *)RFIFOP (fd, 28)) == 0)
+ if (strcmp((const char *)RFIFOP(fd, 4), (const char *)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);
+ 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);
+ struct WisData wd;
// 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);
+ check_ttl_wisdata();
+
+ wd.id = ++wisid;
+ wd.fd = fd;
+ size_t len = RFIFOW(fd, 2) - 52;
+ memcpy(wd.src, RFIFOP(fd, 4), 24);
+ memcpy(wd.dst, RFIFOP(fd, 28), 24);
+ wd.msg = std::string(static_cast<const char *>(RFIFOP(fd, 52)), len);
+ wd.tick = gettick();
+ wis_db.insert(wd.id, wd);
+ mapif_wis_message(&wd);
}
}
@@ -512,19 +436,18 @@ int mapif_parse_WisRequest (int fd)
// Wisp/page transmission result
static
-int mapif_parse_WisReply (int fd)
+int mapif_parse_WisReply(int fd)
{
- int id = RFIFOL (fd, 2), flag = RFIFOB (fd, 6);
- struct WisData *wd = (struct WisData *)numdb_search (wis_db, id);
+ int id = RFIFOL(fd, 2), flag = RFIFOB(fd, 6);
+ struct WisData *wd = wis_db.search(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);
+ mapif_wis_end(wd, flag); // flag: 0: success to send wisper, 1: target character is not loged in?, 2: ignored by target
+ wis_db.erase(id);
}
return 0;
@@ -532,50 +455,50 @@ int mapif_parse_WisReply (int fd)
// Received wisp message from map-server for ALL gm (just copy the message and resends it to ALL map-servers)
static
-int mapif_parse_WisToGM (int fd)
+int mapif_parse_WisToGM(int fd)
{
- unsigned char buf[RFIFOW (fd, 2)]; // 0x3003/0x3803 <packet_len>.w <wispname>.24B <min_gm_level>.w <message>.?B
+ unsigned char buf[RFIFOW(fd, 2)]; // 0x3003/0x3803 <packet_len>.w <wispname>.24B <min_gm_level>.w <message>.?B
- memcpy (WBUFP (buf, 0), RFIFOP (fd, 0), RFIFOW (fd, 2));
- WBUFW (buf, 0) = 0x3803;
- mapif_sendall (buf, RFIFOW (fd, 2));
+ memcpy(WBUFP(buf, 0), RFIFOP(fd, 0), RFIFOW(fd, 2));
+ WBUFW(buf, 0) = 0x3803;
+ mapif_sendall(buf, RFIFOW(fd, 2));
return 0;
}
// アカウント変数ä¿å­˜è¦æ±‚
static
-int mapif_parse_AccReg (int fd)
+int mapif_parse_AccReg(int fd)
{
- int j, p;
- struct accreg *reg = (struct accreg*)numdb_search (accreg_db, (numdb_key_t)RFIFOL (fd, 4));
+ int j, p;
+ struct accreg *reg = accreg_db.search(RFIFOL(fd, 4));
if (reg == NULL)
{
- CREATE (reg, struct accreg, 1);
- reg->account_id = RFIFOL (fd, 4);
- numdb_insert (accreg_db, (numdb_key_t)RFIFOL (fd, 4), reg);
+ int account_id = RFIFOL(fd, 4);
+ reg = accreg_db.init(account_id);
+ reg->account_id = account_id;
}
- for (j = 0, p = 8; j < ACCOUNT_REG_NUM && p < RFIFOW (fd, 2);
+ 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);
+ memcpy(reg->reg[j].str, RFIFOP(fd, p), 32);
+ reg->reg[j].value = RFIFOL(fd, p + 32);
}
reg->reg_num = j;
- mapif_account_reg (fd, RFIFOP (fd, 0)); // ä»–ã®MAPサーãƒãƒ¼ã«é€ä¿¡
+ // ä»–ã®MAPサーãƒãƒ¼ã«é€ä¿¡
+ mapif_account_reg(fd, static_cast<const uint8_t *>(RFIFOP(fd, 0)));
return 0;
}
// アカウント変数é€ä¿¡è¦æ±‚
static
-int mapif_parse_AccRegRequest (int fd)
+int mapif_parse_AccRegRequest(int fd)
{
-// printf("mapif: accreg request\n");
- return mapif_account_reg_reply (fd, RFIFOL (fd, 2));
+ return mapif_account_reg_reply(fd, RFIFOL(fd, 2));
}
//--------------------------------------------------------
@@ -583,71 +506,69 @@ int mapif_parse_AccRegRequest (int fd)
// map server ã‹ã‚‰ã®é€šä¿¡ï¼ˆï¼‘パケットã®ã¿è§£æžã™ã‚‹ã“ã¨ï¼‰
// エラーãªã‚‰0(false)ã€å‡¦ç†ã§ããŸãªã‚‰1ã€
// パケット長ãŒè¶³ã‚Šãªã‘ã‚Œã°2ã‚’ã‹ãˆã•ãªã‘ã‚Œã°ãªã‚‰ãªã„
-int inter_parse_frommap (int fd)
+int inter_parse_frommap(int fd)
{
- int cmd = RFIFOW (fd, 0);
- int len = 0;
+ 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])))
+ (sizeof(inter_recv_packet_length) /
+ sizeof(inter_recv_packet_length[0])))
return 0;
// パケット長を調ã¹ã‚‹
if ((len =
- inter_check_length (fd,
+ inter_check_length(fd,
inter_recv_packet_length[cmd - 0x3000])) == 0)
return 2;
switch (cmd)
{
case 0x3000:
- mapif_parse_GMmessage (fd);
+ mapif_parse_GMmessage(fd);
break;
case 0x3001:
- mapif_parse_WisRequest (fd);
+ mapif_parse_WisRequest(fd);
break;
case 0x3002:
- mapif_parse_WisReply (fd);
+ mapif_parse_WisReply(fd);
break;
case 0x3003:
- mapif_parse_WisToGM (fd);
+ mapif_parse_WisToGM(fd);
break;
case 0x3004:
- mapif_parse_AccReg (fd);
+ mapif_parse_AccReg(fd);
break;
case 0x3005:
- mapif_parse_AccRegRequest (fd);
+ mapif_parse_AccRegRequest(fd);
break;
default:
- if (inter_party_parse_frommap (fd))
- break;
- if (inter_guild_parse_frommap (fd))
+ if (inter_party_parse_frommap(fd))
break;
- if (inter_storage_parse_frommap (fd))
+ if (inter_storage_parse_frommap(fd))
break;
return 0;
}
- RFIFOSKIP (fd, len);
+ RFIFOSKIP(fd, len);
return 1;
}
// RFIFOã®ãƒ‘ケット長確èª
// å¿…è¦ãƒ‘ケット長ãŒã‚ã‚Œã°ãƒ‘ケット長ã€ã¾ã è¶³ã‚Šãªã‘ã‚Œã°0
-int inter_check_length (int fd, int length)
+int inter_check_length(int fd, int length)
{
if (length == -1)
{ // å¯å¤‰ãƒ‘ケット長
- if (RFIFOREST (fd) < 4) // パケット長ãŒæœªç€
+ if (RFIFOREST(fd) < 4) // パケット長ãŒæœªç€
return 0;
- length = RFIFOW (fd, 2);
+ length = RFIFOW(fd, 2);
}
- if (RFIFOREST (fd) < length) // パケットãŒæœªç€
+ if (RFIFOREST(fd) < length) // パケットãŒæœªç€
return 0;
return length;
diff --git a/src/char/inter.hpp b/src/char/inter.hpp
index 56960be..0adbf03 100644
--- a/src/char/inter.hpp
+++ b/src/char/inter.hpp
@@ -1,20 +1,15 @@
-// $Id: inter.h,v 1.1.1.1 2004/09/10 17:26:51 MagicalTux Exp $
#ifndef INTER_HPP
#define INTER_HPP
-int inter_init (const char *file);
-int inter_save (void);
-int inter_parse_frommap (int fd);
-int inter_mapif_init (int fd);
+int inter_init(const char *file);
+int inter_save(void);
+int inter_parse_frommap(int fd);
-int inter_check_length (int fd, int length);
-
-__attribute__((format(printf, 1, 2)))
-int inter_log (const char *fmt, ...);
+int inter_check_length(int fd, int length);
#define inter_cfgName "conf/inter_athena.conf"
extern int party_share_level;
extern char inter_log_filename[1024];
-#endif
+#endif // INTER_HPP
diff --git a/src/common/const_array.hpp b/src/common/const_array.hpp
new file mode 100644
index 0000000..93ae337
--- /dev/null
+++ b/src/common/const_array.hpp
@@ -0,0 +1,175 @@
+#ifndef CONST_ARRAY_HPP
+#define CONST_ARRAY_HPP
+// const_array.hpp - just a pointer-to-const and a length
+//
+// Copyright © 2011-2012 Ben Longbons <b.r.longbons@gmail.com>
+//
+// This file is part of The Mana World (Athena server)
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+#include "sanity.hpp"
+
+#include <cstring>
+
+#include <iterator>
+#include <ostream>
+#include <string>
+#include <vector>
+
+#ifdef WORKAROUND_GCC46_COMPILER
+// constexpr is buggy with templates in this version
+# define constexpr /* nothing */
+#endif
+
+// TODO see if I ever actually use this, and not the subclass
+template<class T>
+class const_array
+{
+ const T *d;
+ size_t n;
+public:
+ typedef const T *iterator;
+ typedef std::reverse_iterator<iterator> reverse_iterator;
+
+ constexpr
+ const_array(std::nullptr_t)
+ : d(nullptr), n(0)
+ {}
+
+ constexpr
+ const_array(const T *p, size_t z)
+ : d(p), n(z)
+ {}
+
+ constexpr
+ const_array(const T *b, const T *e)
+ : d(b), n(e - b)
+ {}
+
+ const_array(std::initializer_list<T> list)
+ : d(list.begin()), n(list.size())
+ {}
+
+ // Implicit conversion from std::vector
+ const_array(const std::vector<T>& v)
+ : d(v.data()), n(v.size())
+ {}
+
+ // but disallow conversion from a temporary
+ const_array(std::vector<T>&&) = delete;
+
+ // All methods are non-const to "encourage" you
+ // to always pass a const_array by value.
+ // After all, "const const_array" looks funny.
+ constexpr
+ const T *data() { return d; }
+ constexpr
+ size_t size() { return n; }
+ constexpr
+ bool empty() { return not n; }
+ constexpr explicit
+ operator bool() { return n; }
+
+ constexpr
+ std::pair<const_array, const_array> cut(size_t o)
+ {
+ return {const_array(d, o), const_array(d + o, n - o)};
+ }
+
+ constexpr
+ const_array first(size_t o)
+ {
+ return cut(o).first;
+ }
+
+ constexpr
+ const_array last(size_t l)
+ {
+ return cut(size() - l).second;
+ }
+
+ constexpr
+ const_array after(size_t o)
+ {
+ return cut(o).second;
+ }
+
+ constexpr
+ iterator begin() { return d; }
+ constexpr
+ iterator end() { return d + n; }
+ constexpr
+ reverse_iterator rbegin() { return reverse_iterator(end()); }
+ constexpr
+ reverse_iterator rend() { return reverse_iterator(begin()); }
+
+ constexpr
+ const T& front() { return *begin(); }
+ constexpr
+ const T& back() { return *rbegin(); }
+};
+
+// subclass just provides a simpler name and some conversions
+class const_string : public const_array<char>
+{
+public:
+ // Implicit conversion from C string.
+ constexpr
+ const_string(const char *z)
+ : const_array<char>(z, z ? strlen(z) : 0)
+ {}
+
+ // Same as parent constructor.
+ constexpr
+ const_string(const char *s, size_t l)
+ : const_array<char>(s, l)
+ {}
+
+ // Same as parent constructor.
+ constexpr
+ const_string(const char *b, const char *e)
+ : const_array<char>(b, e)
+ {}
+
+ // Same as parent constructor.
+ const_string(const std::vector<char> s)
+ : const_array<char>(s)
+ {}
+
+ // Implicit conversion from C++ string.
+ const_string(const std::string& s)
+ : const_array<char>(s.data(), s.size())
+ {}
+
+ // but disallow converion from a temporary.
+ const_string(std::string&&) = delete;
+
+ // allow being sloppy
+ constexpr
+ const_string(const_array<char> a)
+ : const_array<char>(a)
+ {}
+};
+#ifdef WORKAROUND_GCC46_COMPILER
+# undef constexpr
+#endif
+
+inline
+std::ostream& operator << (std::ostream& o, const_string s)
+{
+ return o.write(s.data(), s.size());
+}
+
+#endif // CONST_ARRAY_HPP
diff --git a/src/common/core.cpp b/src/common/core.cpp
index db26e31..994de93 100644
--- a/src/common/core.cpp
+++ b/src/common/core.cpp
@@ -1,15 +1,18 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <signal.h>
+#include "core.hpp"
+
#include <sys/wait.h>
-#include "core.hpp"
+#include <unistd.h>
+
+#include <csignal>
+#include <cstdlib>
+#include <ctime>
+
+#include "random.hpp"
#include "socket.hpp"
#include "timer.hpp"
-#include "version.hpp"
-#include "mt_rand.hpp"
-#include "nullpo.hpp"
+
+#include "../poison.hpp"
// Added by Gabuzomeu
//
@@ -17,13 +20,14 @@
// (sigaction() is POSIX; signal() is not.) Taken from Stevens' _Advanced
// Programming in the UNIX Environment_.
//
-typedef void (*sigfunc)(int);
-static sigfunc compat_signal (int signo, sigfunc func)
+typedef void(*sigfunc)(int);
+static
+sigfunc compat_signal(int signo, sigfunc func)
{
struct sigaction sact, oact;
sact.sa_handler = func;
- sigfillset (&sact.sa_mask);
+ sigfillset(&sact.sa_mask);
sigdelset(&sact.sa_mask, SIGSEGV);
sigdelset(&sact.sa_mask, SIGBUS);
sigdelset(&sact.sa_mask, SIGTRAP);
@@ -31,22 +35,24 @@ static sigfunc compat_signal (int signo, sigfunc func)
sigdelset(&sact.sa_mask, SIGFPE);
sact.sa_flags = 0;
- if (sigaction (signo, &sact, &oact) < 0)
+ if (sigaction(signo, &sact, &oact) < 0)
return SIG_ERR;
return oact.sa_handler;
}
-static void chld_proc (int UNUSED)
+static
+void chld_proc(int)
{
wait(NULL);
}
-static void sig_proc (int UNUSED)
+static __attribute__((noreturn))
+void sig_proc(int)
{
for (int i = 1; i < 31; ++i)
compat_signal(i, SIG_IGN);
- term_func ();
- _exit (0);
+ term_func();
+ _exit(0);
}
bool runflag = true;
@@ -60,34 +66,35 @@ bool runflag = true;
Unless you use SA_SIGINFO and *carefully* check the origin,
that means they must be SIG_DFL.
*/
-int main (int argc, char **argv)
+int main(int argc, char **argv)
{
- /// Note that getpid() and getppid() may be very close
- mt_seed (time (NULL) ^ (getpid () << 16) ^ (getppid () << 8));
-
- do_socket ();
+ do_socket();
- do_init (argc, argv);
+ do_init(argc, argv);
// set up exit handlers *after* the initialization has happened.
// This is because term_func is likely to depend on successful init.
- compat_signal (SIGPIPE, SIG_IGN);
- compat_signal (SIGTERM, sig_proc);
- compat_signal (SIGINT, sig_proc);
- compat_signal (SIGCHLD, chld_proc);
+ compat_signal(SIGPIPE, SIG_IGN);
+ compat_signal(SIGTERM, sig_proc);
+ compat_signal(SIGINT, sig_proc);
+ compat_signal(SIGCHLD, chld_proc);
// Signal to create coredumps by system when necessary (crash)
- compat_signal (SIGSEGV, SIG_DFL);
- compat_signal (SIGBUS, SIG_DFL);
- compat_signal (SIGTRAP, SIG_DFL);
- compat_signal (SIGILL, SIG_DFL);
- compat_signal (SIGFPE, SIG_DFL);
+ compat_signal(SIGSEGV, SIG_DFL);
+ compat_signal(SIGBUS, SIG_DFL);
+ compat_signal(SIGTRAP, SIG_DFL);
+ compat_signal(SIGILL, SIG_DFL);
+ compat_signal(SIGFPE, SIG_DFL);
- atexit (term_func);
+ atexit(term_func);
while (runflag)
{
- do_sendrecv (do_timer (gettick_nocache ()));
- do_parsepacket ();
+ // TODO - if timers take a long time to run, this
+ // may wait too long in sendrecv
+ tick_t now = milli_clock::now();
+ interval_t next = do_timer(now);
+ do_sendrecv(next);
+ do_parsepacket();
}
}
diff --git a/src/common/core.hpp b/src/common/core.hpp
index 8a52c55..0c11efb 100644
--- a/src/common/core.hpp
+++ b/src/common/core.hpp
@@ -1,6 +1,8 @@
#ifndef CORE_HPP
#define CORE_HPP
-#include <stdbool.h>
+
+#include "sanity.hpp"
+
/// core.c contains a server-independent main() function
/// and then runs a do_sendrecv loop
@@ -10,10 +12,10 @@ extern bool 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 **);
+extern int do_init(int, char **);
/// Cleanup function called whenever a signal kills us
/// or when if we manage to exit() gracefully.
-extern void term_func (void);
+extern void term_func(void);
#endif // CORE_HPP
diff --git a/src/common/cxxstdio.cpp b/src/common/cxxstdio.cpp
new file mode 100644
index 0000000..8f4001f
--- /dev/null
+++ b/src/common/cxxstdio.cpp
@@ -0,0 +1,33 @@
+#include "cxxstdio.hpp"
+// cxxstdio.cpp - pass C++ types through scanf/printf
+//
+// Copyright © 2013 Ben Longbons <b.r.longbons@gmail.com>
+//
+// This file is part of The Mana World (Athena server)
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+#include <cstdlib>
+
+namespace cxxstdio
+{
+StringConverter::~StringConverter()
+{
+ if (mid)
+ {
+ out = mid;
+ free(mid);
+ }
+}
+} // namespace cxxstdio
diff --git a/src/common/cxxstdio.hpp b/src/common/cxxstdio.hpp
new file mode 100644
index 0000000..96c3ca2
--- /dev/null
+++ b/src/common/cxxstdio.hpp
@@ -0,0 +1,297 @@
+#ifndef CXXSTDIO_HPP
+#define CXXSTDIO_HPP
+// cxxstdio.hpp - pass C++ types through scanf/printf
+//
+// Copyright © 2011-2013 Ben Longbons <b.r.longbons@gmail.com>
+//
+// This file is part of The Mana World (Athena server)
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+#include "sanity.hpp"
+
+#include <cstdarg>
+#include <cstdio>
+
+#include <string>
+
+#include "const_array.hpp"
+#include "utils2.hpp"
+
+
+namespace cxxstdio
+{
+ inline __attribute__((format(printf, 2, 0)))
+ int do_vprint(FILE *out, const char *fmt, va_list ap)
+ {
+ return vfprintf(out, fmt, ap);
+ }
+
+ inline __attribute__((format(printf, 2, 0)))
+ int do_vprint(std::string& out, const char *fmt, va_list ap)
+ {
+ int len;
+ {
+ va_list ap2;
+ va_copy(ap2, ap);
+ len = vsnprintf(nullptr, 0, fmt, ap2);
+ va_end(ap2);
+ }
+ char buffer[len + 1];
+ vsnprintf(buffer, len + 1, fmt, ap);
+
+ out = buffer;
+ return len;
+ }
+
+ inline __attribute__((format(scanf, 2, 0)))
+ int do_vscan(FILE *in, const char *fmt, va_list ap)
+ {
+ return vfscanf(in, fmt, ap);
+ }
+
+#if 0
+ inline __attribute__((format(scanf, 2, 0)))
+ int do_vscan(const char *in, const char *fmt, va_list ap)
+ {
+ return vsscanf(in, fmt, ap);
+ }
+#else
+ inline
+ int do_vscan(const char *, const char *, va_list) = delete;
+#endif
+
+ inline __attribute__((format(scanf, 2, 0)))
+ int do_vscan(const std::string& in, const char *fmt, va_list ap)
+ {
+ return vsscanf(in.c_str(), fmt, ap);
+ }
+
+
+ template<class T>
+ inline __attribute__((format(printf, 2, 3)))
+ int do_print(T&& t, const char *fmt, ...) throw()
+ {
+ int rv;
+ va_list ap;
+ va_start(ap, fmt);
+ rv = do_vprint(std::forward<T>(t), fmt, ap);
+ va_end(ap);
+ return rv;
+ }
+
+ template<class T>
+ inline __attribute__((format(scanf, 2, 3)))
+ int do_scan(T&& t, const char *fmt, ...) throw()
+ {
+ int rv;
+ va_list ap;
+ va_start(ap, fmt);
+ rv = do_vscan(std::forward<T>(t), fmt, ap);
+ va_end(ap);
+ return rv;
+ }
+
+
+ template<class T>
+ typename remove_enum<T>::type convert_for_printf(T v)
+ {
+ typedef typename remove_enum<T>::type repr_type;
+ return repr_type(v);
+ }
+
+ template<class T, typename = typename std::enable_if<!std::is_enum<T>::value>::type>
+ T& convert_for_scanf(T& v)
+ {
+ return v;
+ }
+
+#if 0
+ template<class E>
+ constexpr
+ E get_enum_min_value(decltype(E::min_value))
+ {
+ return E::min_value;
+ }
+ template<class E>
+ constexpr
+ E get_enum_min_value(E def)
+ {
+ return def;
+ }
+
+ template<class E>
+ constexpr
+ E get_enum_max_value(decltype(E::max_value))
+ {
+ return E::max_value;
+ }
+ template<class E>
+ constexpr
+ E get_enum_max_value(E def)
+ {
+ return def;
+ }
+#else
+ template<class E>
+ constexpr
+ E get_enum_min_value(E)
+ {
+ return E::min_value;
+ }
+ template<class E>
+ constexpr
+ E get_max_value(E)
+ {
+ return E::max_value;
+ }
+#endif
+
+ template<class E>
+ class EnumConverter
+ {
+ E& out;
+ typedef typename underlying_type<E>::type U;
+#if 0
+ constexpr static
+ U min_value = U(get_enum_min_value<E>(E(std::numeric_limits<U>::min())));
+ constexpr static
+ U max_value = U(get_enum_max_value<E>(E(std::numeric_limits<U>::max())));
+#else
+ constexpr static
+ U min_value = U(get_enum_min_value(E()));
+ constexpr static
+ U max_value = U(get_enum_max_value(E()));
+#endif
+ U mid;
+ public:
+ EnumConverter(E& e)
+ : out(e), mid(0)
+ {}
+ ~EnumConverter()
+ {
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wtype-limits"
+ if (min_value <= mid && mid <= max_value)
+#pragma GCC diagnostic pop
+ out = E(mid);
+ }
+ U *operator &()
+ {
+ return &mid;
+ }
+ };
+
+ template<class T, typename = typename std::enable_if<std::is_enum<T>::value>::type>
+ EnumConverter<T> convert_for_scanf(T& v)
+ {
+ return v;
+ }
+
+
+ inline
+ const char *convert_for_printf(const std::string& s)
+ {
+ return s.c_str();
+ }
+
+ class StringConverter
+ {
+ std::string& out;
+ char *mid;
+ public:
+ StringConverter(std::string& s)
+ : out(s), mid(nullptr)
+ {}
+ ~StringConverter();
+ char **operator &()
+ {
+ return &mid;
+ }
+ };
+
+ inline
+ StringConverter convert_for_scanf(std::string& s)
+ {
+ return StringConverter(s);
+ }
+
+ template<class Format>
+ class PrintFormatter
+ {
+ public:
+ template<class T, class... A>
+ static
+ int print(T&& t, A&&... a)
+ {
+ constexpr static
+ const char *print_format = Format::print_format();
+ return do_print(std::forward<T>(t), print_format,
+ convert_for_printf(std::forward<A>(a))...);
+ }
+ };
+
+ template<class Format>
+ class ScanFormatter
+ {
+ public:
+ template<class T, class... A>
+ static
+ int scan(T&& t, A&&... a)
+ {
+ constexpr static
+ const char *scan_format = Format::scan_format();
+ return do_scan(std::forward<T>(t), scan_format,
+ &convert_for_scanf(*a)...);
+ }
+ };
+
+#define FPRINTF(file, fmt, ...) \
+ ([&]() -> int \
+ { \
+ struct format_impl \
+ { \
+ constexpr static \
+ const char *print_format() { return fmt; } \
+ }; \
+ return cxxstdio::PrintFormatter<format_impl>::print(file, ## __VA_ARGS__); \
+ }())
+
+#define FSCANF(file, fmt, ...) \
+ ([&]() -> int \
+ { \
+ struct format_impl \
+ { \
+ constexpr static \
+ const char *scan_format() { return fmt; } \
+ }; \
+ return cxxstdio::ScanFormatter<format_impl>::scan(file, ## __VA_ARGS__); \
+ }())
+
+#define PRINTF(fmt, ...) FPRINTF(stdout, fmt, ## __VA_ARGS__)
+#define SPRINTF(str, fmt, ...) FPRINTF(str, fmt, ## __VA_ARGS__)
+#define SCANF(fmt, ...) FSCANF(stdin, fmt, ## __VA_ARGS__)
+#define SSCANF(str, fmt, ...) FSCANF(str, fmt, ## __VA_ARGS__)
+
+#define STRPRINTF(fmt, ...) \
+ ([&]() -> std::string \
+ { \
+ std::string _out_impl; \
+ SPRINTF(_out_impl, fmt, ## __VA_ARGS__);\
+ return _out_impl; \
+ }())
+
+} // namespace cxxstdio
+
+#endif // CXXSTDIO_HPP
diff --git a/src/common/db.cpp b/src/common/db.cpp
index 21a3597..cc58ad8 100644
--- a/src/common/db.cpp
+++ b/src/common/db.cpp
@@ -1,546 +1,3 @@
#include "db.hpp"
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "utils.hpp"
-
-#define ROOT_SIZE 4096
-
-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 hash_t strdb_hash (struct dbt *table, const char *a)
-{
- size_t i = table->maxlen;
- if (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 (size_t maxlen)
-{
- struct dbt *table;
- CREATE (table, struct dbt, 1);
- table->type = DB_STRING;
- table->maxlen = maxlen;
- return table;
-}
-
-static int numdb_cmp (numdb_key_t a, numdb_key_t b)
-{
- if (a == b)
- return 0;
- if (a < b)
- return -1;
- return 1;
-}
-
-static hash_t numdb_hash (numdb_key_t a)
-{
- return (hash_t) a;
-}
-
-struct dbt *numdb_init (void)
-{
- struct dbt *table;
- CREATE (table, struct dbt, 1);
- table->type = DB_NUMBER;
- return table;
-}
-
-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 = table->ht[table_hash (table, key) % HASH_SIZE];
-
- while (p)
- {
- int c = table_cmp (table, key, p->key);
- if (c == 0)
- return p->data;
- if (c < 0)
- p = p->left;
- else
- p = p->right;
- }
- return NULL;
-}
-
-// 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)
- y->left->parent = p;
- y->parent = p->parent;
-
- if (p == *root)
- *root = y;
- else if (p == p->parent->left)
- p->parent->left = y;
- else
- p->parent->right = y;
- y->left = p;
- p->parent = y;
-}
-
-static void db_rotate_right (struct dbn *p, struct dbn **root)
-{
- struct dbn *y = p->left;
- p->left = y->right;
- if (y->right)
- y->right->parent = p;
- y->parent = p->parent;
-
- if (p == *root)
- *root = y;
- else if (p == p->parent->right)
- p->parent->right = y;
- else
- p->parent->left = y;
- y->right = p;
- p->parent = y;
-}
-
-static void db_rebalance (struct dbn *p, struct dbn **root)
-{
- p->color = RED;
- while (p != *root && p->parent->color == RED)
- {
- if (p->parent == p->parent->parent->left)
- {
- struct dbn *y = p->parent->parent->right;
- if (y && y->color == RED)
- {
- p->parent->color = BLACK;
- y->color = BLACK;
- p->parent->parent->color = RED;
- p = p->parent->parent;
- }
- else
- {
- if (p == p->parent->right)
- {
- p = p->parent;
- db_rotate_left (p, root);
- }
- p->parent->color = BLACK;
- p->parent->parent->color = RED;
- db_rotate_right (p->parent->parent, root);
- }
- }
- else
- {
- struct dbn *y = p->parent->parent->left;
- if (y && y->color == RED)
- {
- p->parent->color = BLACK;
- y->color = BLACK;
- p->parent->parent->color = RED;
- p = p->parent->parent;
- }
- else
- {
- if (p == p->parent->left)
- {
- p = p->parent;
- db_rotate_right (p, root);
- }
- p->parent->color = BLACK;
- p->parent->parent->color = RED;
- db_rotate_left (p->parent->parent, root);
- }
- }
- }
- (*root)->color = BLACK;
-}
-
-// param z = node to remove
-static void db_rebalance_erase (struct dbn *z, struct dbn **root)
-{
- struct dbn *y = z;
- struct dbn *x = NULL;
-
- if (!y->left)
- x = y->right;
- else if (!y->right)
- x = y->left;
- else
- {
- y = y->right;
- while (y->left)
- y = y->left;
- x = y->right;
- }
- struct dbn *x_parent = NULL;
- if (y != z)
- {
- z->left->parent = y;
- y->left = z->left;
- if (y != z->right)
- {
- x_parent = y->parent;
- if (x)
- x->parent = y->parent;
- y->parent->left = x;
- y->right = z->right;
- z->right->parent = y;
- }
- else
- x_parent = y;
- if (*root == z)
- *root = y;
- else if (z->parent->left == z)
- z->parent->left = y;
- else
- z->parent->right = y;
- y->parent = z->parent;
- {
- dbn_color tmp = y->color;
- y->color = z->color;
- z->color = tmp;
- }
- y = z;
- }
- else
- {
- x_parent = y->parent;
- if (x)
- x->parent = y->parent;
- if (*root == z)
- *root = x;
- else if (z->parent->left == z)
- z->parent->left = x;
- else
- z->parent->right = x;
- }
- if (y->color != RED)
- {
- while (x != *root && (!x || x->color == BLACK))
- if (x == x_parent->left)
- {
- struct dbn *w = x_parent->right;
- if (w->color == RED)
- {
- w->color = BLACK;
- x_parent->color = RED;
- db_rotate_left (x_parent, root);
- w = x_parent->right;
- }
- if ((!w->left || w->left->color == BLACK) &&
- (!w->right || w->right->color == BLACK))
- {
- w->color = RED;
- x = x_parent;
- x_parent = x->parent;
- }
- else
- {
- if (!w->right|| w->right->color == BLACK)
- {
- if (w->left)
- w->left->color = BLACK;
- w->color = RED;
- db_rotate_right (w, root);
- w = x_parent->right;
- }
- w->color = x_parent->color;
- x_parent->color = BLACK;
- if (w->right)
- w->right->color = BLACK;
- db_rotate_left (x_parent, root);
- break;
- }
- }
- else
- {
- // same as above, with right <-> left.
- struct dbn *w = x_parent->left;
- if (w->color == RED)
- {
- w->color = BLACK;
- x_parent->color = RED;
- db_rotate_right (x_parent, root);
- w = x_parent->left;
- }
- if ((!w->right || w->right->color == BLACK) &&
- (!w->left || w->left->color == BLACK))
- {
- w->color = RED;
- x = x_parent;
- x_parent = x_parent->parent;
- }
- else
- {
- if (!w->left || w->left->color == BLACK)
- {
- if (w->right)
- w->right->color = BLACK;
- w->color = RED;
- db_rotate_left (w, root);
- w = x_parent->left;
- }
- w->color = x_parent->color;
- x_parent->color = BLACK;
- if (w->left)
- w->left->color = BLACK;
- db_rotate_right (x_parent, root);
- break;
- }
- }
- if (x)
- x->color = BLACK;
- }
-}
-
-struct dbn *db_insert (struct dbt *table, db_key_t key, db_val_t data)
-{
- 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);
- if (c == 0)
- {
- // key found in table, replace
- // Tell the user of the table to free the key and value
- if (table->release)
- table->release (p->key, p->data);
- p->data = data;
- p->key = key;
- return p;
- }
- // prev is always p->parent?
- prev = p;
- if (c < 0)
- p = p->left;
- else
- p = p->right;
- }
- CREATE (p, struct dbn, 1);
- p->key = key;
- p->data = data;
- p->color = RED;
- if (c == 0)
- { // 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)
- {
- // must rebalance
- db_rebalance (p, &table->ht[hash]);
- }
- return p;
-}
-
-db_val_t db_erase (struct dbt *table, db_key_t key)
-{
- hash_t hash = table_hash (table, key) % HASH_SIZE;
- struct dbn *p = table->ht[hash];
- while (p)
- {
- int c = table_cmp (table, key, p->key);
- if (c == 0)
- break;
- if (c < 0)
- p = p->left;
- else
- p = p->right;
- }
- if (!p)
- return NULL;
- db_val_t data = p->data;
- db_rebalance_erase (p, &table->ht[hash]);
- free (p);
- 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, db_func_t func, ...)
-{
- va_list ap;
- va_start (ap, func);
-
- for (int i = 0; i < HASH_SIZE; i++)
- {
-#ifdef SMART_WALK_TREE
- db_walk_tree (false, table->ht[i], func, ap);
-#else
- struct dbn *p = table->ht[i];
- if (!p)
- continue;
- struct dbn *stack[64];
- int sp = 0;
- while (1)
- {
- func (p->key, p->data, ap);
- struct dbn *pn = p->left;
- if (pn)
- {
- if (p->right)
- stack[sp++] = p->right;
- p = pn;
- }
- 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);
-}
-
-// This function is suspiciously similar to the previous
-void db_final (struct dbt *table, db_func_t func, ...)
-{
- va_list ap;
- va_start (ap, func);
-
- for (int i = 0; i < HASH_SIZE; i++)
- {
-#ifdef SMART_WALK_TREE
- db_walk_tree (true, table->ht[i], func, ap);
-#else
- struct dbn *p = table->ht[i];
- if (!p)
- continue;
- struct dbn *stack[64];
- int sp = 0;
- while (1)
- {
- if (func)
- func (p->key, p->data, ap);
- struct dbn *pn = p->left;
- if (pn)
- {
- if (p->right)
- stack[sp++] = p->right;
- }
- else // pn == NULL, check the right
- {
- if (p->right)
- pn = p->right;
- else
- {
- if (sp == 0)
- break;
- pn = stack[--sp];
- }
- } // if pn else if !pn
- free (p);
- p = pn;
- } // while true
-#endif // else ! SMART_WALK_TREE
- } // for i
- free (table);
- va_end (ap);
-}
+#include "../poison.hpp"
diff --git a/src/common/db.hpp b/src/common/db.hpp
index 62125d8..bd47928 100644
--- a/src/common/db.hpp
+++ b/src/common/db.hpp
@@ -1,90 +1,123 @@
-// WARNING: there is a system header by this name
#ifndef DB_HPP
#define DB_HPP
-# include "sanity.hpp"
+// db.hpp - convenience wrappers over std::map<K, V>
+//
+// Copyright © 2013 Ben Longbons <b.r.longbons@gmail.com>
+//
+// This file is part of The Mana World (Athena server)
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
-# include <stdarg.h>
+# include "sanity.hpp"
-/// 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)
+# include <map>
-typedef enum dbn_color
+template<class K, class V>
+class Map
{
- RED,
- BLACK
-} dbn_color;
+ typedef std::map<K, V> Impl;
-typedef intptr_t numdb_key_t;
-typedef union db_key_t
-{
- char *ms __attribute__((deprecated));
- const char* s;
- numdb_key_t i;
+ Impl impl;
+public:
+ Map() = default;
+ Map(std::initializer_list<std::pair<const K, V>> il)
+ : impl(il)
+ {}
+ typedef typename Impl::iterator iterator;
+ typedef typename Impl::const_iterator const_iterator;
- db_key_t(numdb_key_t n) : i(n) {}
- db_key_t(const char * z) : s(z) {}
-} 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);
+ iterator begin() { return impl.begin(); }
+ iterator end() { return impl.end(); }
+ const_iterator begin() const { return impl.begin(); }
+ const_iterator end() const { return impl.end(); }
-/// DataBase Node
-struct dbn
-{
- struct dbn *parent, *left, *right;
- dbn_color color;
- db_key_t key;
- db_val_t data;
-};
+ V *search(const K& k)
+ {
+ iterator it = impl.find(k);
+ if (it == impl.end())
+ return nullptr;
+ return &it->second;
+ }
+ const V *search(const K& k) const
+ {
+ const_iterator it = impl.find(k);
+ if (it == impl.end())
+ return nullptr;
+ return &it->second;
+ }
+ void insert(K k, V v)
+ {
+ // As far as I can tell, this is the simplest way to
+ // implement move-only insert-with-replacement.
+ iterator it = impl.lower_bound(k);
+ // invariant: if it is valid, it->first >= k
+ if (it != impl.end() && it->first == k)
+ it->second = std::move(v);
+ else
+ it = impl.insert(std::pair<K, V>(std::move(k), std::move(v))).first;
+ return (void)&it->second;
-typedef enum dbt_type
-{
- DB_NUMBER,
- DB_STRING,
-} dbt_type;
+ }
+ V *init(K k)
+ {
+ return &impl[k];
+ }
+ void erase(const K& k)
+ {
+ impl.erase(k);
+ }
+ void clear()
+ {
+ impl.clear();
+ }
+ bool empty()
+ {
+ return impl.empty();
+ }
+};
-/// DataBase Table
-struct dbt
+template<class K, class V>
+class DMap
{
- 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];
-};
+ typedef Map<K, V> Impl;
-# 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
+ Impl impl;
+public:
+ typedef typename Impl::iterator iterator;
+ typedef typename Impl::const_iterator const_iterator;
-/// 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);
-/// 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);
+ iterator begin() { return impl.begin(); }
+ iterator end() { return impl.end(); }
+ const_iterator begin() const { return impl.begin(); }
+ const_iterator end() const { return impl.end(); }
-/// 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));
+ V get(K k)
+ {
+ V *vp = impl.search(k);
+ return vp ? *vp : V();
+ }
+ void put(K k, V v)
+ {
+ if (v == V())
+ impl.erase(k);
+ else
+ impl.insert(k, v);
+ }
+ void clear()
+ {
+ impl.clear();
+ }
+};
-#endif
+#endif // DB_HPP
diff --git a/src/common/extract.cpp b/src/common/extract.cpp
new file mode 100644
index 0000000..5e89e19
--- /dev/null
+++ b/src/common/extract.cpp
@@ -0,0 +1,68 @@
+#include "extract.hpp"
+// extract.cpp - a simple, hierarchical, tokenizer
+//
+// Copyright © 2013 Ben Longbons <b.r.longbons@gmail.com>
+//
+// This file is part of The Mana World (Athena server)
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+bool extract(const_string str, const_string *rv)
+{
+ *rv = str;
+ return true;
+}
+
+bool extract(const_string str, std::string *rv)
+{
+ *rv = std::string(str.begin(), str.end());
+ return true;
+}
+
+bool extract(const_string str, struct global_reg *var)
+{
+ return extract(str,
+ record<','>(&var->str, &var->value));
+}
+
+bool extract(const_string str, struct item *it)
+{
+ return extract(str,
+ record<','>(
+ &it->id,
+ &it->nameid,
+ &it->amount,
+ &it->equip,
+ &it->identify,
+ &it->refine,
+ &it->attribute,
+ &it->card[0],
+ &it->card[1],
+ &it->card[2],
+ &it->card[3],
+ &it->broken))
+ || extract(str,
+ record<','>(
+ &it->id,
+ &it->nameid,
+ &it->amount,
+ &it->equip,
+ &it->identify,
+ &it->refine,
+ &it->attribute,
+ &it->card[0],
+ &it->card[1],
+ &it->card[2],
+ &it->card[3]));
+}
diff --git a/src/common/extract.hpp b/src/common/extract.hpp
new file mode 100644
index 0000000..ae1a74b
--- /dev/null
+++ b/src/common/extract.hpp
@@ -0,0 +1,166 @@
+#ifndef EXTRACT_HPP
+#define EXTRACT_HPP
+// extract.hpp - a simple, hierarchical, tokenizer
+//
+// Copyright © 2012-2013 Ben Longbons <b.r.longbons@gmail.com>
+//
+// This file is part of The Mana World (Athena server)
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+#include "sanity.hpp"
+
+#include <algorithm>
+
+#include "const_array.hpp"
+#include "mmo.hpp"
+#include "utils.hpp"
+
+template<class T, typename=typename std::enable_if<std::is_integral<T>::value && !std::is_same<T, char>::value>::type>
+bool extract(const_string str, T *iv)
+{
+ if (!str || str.size() > 20)
+ return false;
+ if (!((str.front() == '-' && std::is_signed<T>::value)
+ || ('0' <= str.front() && str.front() <= '9')))
+ return false;
+ char buf[20 + 1];
+ std::copy(str.begin(), str.end(), buf);
+ buf[str.size()] = '\0';
+
+ char *end;
+ errno = 0;
+ if (std::is_signed<T>::value)
+ {
+ long long v = strtoll(buf, &end, 10);
+ if (errno || *end)
+ return false;
+ *iv = v;
+ return *iv == v;
+ }
+ else
+ {
+ unsigned long long v = strtoull(buf, &end, 10);
+ if (errno || *end)
+ return false;
+ *iv = v;
+ return *iv == v;
+ }
+}
+
+inline
+bool extract(const_string str, TimeT *tv)
+{
+ return extract(str, &tv->value);
+}
+
+// extra typename=void to workaround some duplicate overload rule
+template<class T, typename=typename std::enable_if<std::is_enum<T>::value>::type, typename=void>
+bool extract(const_string str, T *iv)
+{
+ typedef typename underlying_type<T>::type U;
+ U v;
+ // defer to integer version
+ if (!extract(str, &v))
+ return false;
+ // TODO check bounds using enum min/max as in SSCANF
+ *iv = static_cast<T>(v);
+ return true;
+}
+
+bool extract(const_string str, const_string *rv);
+
+bool extract(const_string str, std::string *rv);
+
+template<size_t N>
+__attribute__((deprecated))
+bool extract(const_string str, char (*out)[N])
+{
+ if (str.size() >= N)
+ return false;
+ std::copy(str.begin(), str.end(), *out);
+ std::fill(*out + str.size() , *out + N, '\0');
+ return true;
+}
+
+// basically just a std::tuple
+// but it provides its data members publically
+template<char split, class... T>
+class Record;
+template<char split>
+class Record<split>
+{
+};
+template<char split, class F, class... R>
+class Record<split, F, R...>
+{
+public:
+ F frist;
+ Record<split, R...> rest;
+public:
+ Record(F f, R... r)
+ : frist(f), rest(r...)
+ {}
+};
+template<char split, class... T>
+Record<split, T...> record(T... t)
+{
+ return Record<split, T...>(t...);
+}
+
+template<char split>
+bool extract(const_string str, Record<split>)
+{
+ return !str;
+}
+template<char split, class F, class... R>
+bool extract(const_string str, Record<split, F, R...> rec)
+{
+ const char *s = std::find(str.begin(), str.end(), split);
+ if (s == str.end())
+ return sizeof...(R) == 0 && extract(str, rec.frist);
+ return extract(const_string(str.begin(), s), rec.frist)
+ && extract(const_string(s + 1, str.end()), rec.rest);
+}
+
+template<char split, class T>
+struct VRecord
+{
+ std::vector<T> *arr;
+};
+
+template<char split, class T>
+VRecord<split, T> vrec(std::vector<T> *arr)
+{
+ return {arr};
+}
+
+template<char split, class T>
+bool extract(const_string str, VRecord<split, T> rec)
+{
+ if (str.empty())
+ return true;
+ const char *s = std::find(str.begin(), str.end(), split);
+ rec.arr->emplace_back();
+ if (s == str.end())
+ return extract(str, &rec.arr->back());
+ return extract(const_string(str.begin(), s), &rec.arr->back())
+ && extract(const_string(s + 1, str.end()), rec);
+}
+
+bool extract(const_string str, struct global_reg *var);
+
+bool extract(const_string str, struct item *it);
+
+#endif // EXTRACT_HPP
diff --git a/src/common/grfio.cpp b/src/common/grfio.cpp
deleted file mode 100644
index dd1e707..0000000
--- a/src/common/grfio.cpp
+++ /dev/null
@@ -1,216 +0,0 @@
-// Reads .gat files by name-mapping .wlk files
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/stat.h>
-
-#include "utils.hpp"
-#include "grfio.hpp"
-#include "mmo.hpp"
-#include "socket.hpp"
-
-//----------------------------
-// file entry table struct
-//----------------------------
-typedef struct
-{
- size_t declen;
- int16_t next; // next index into the filelist[] array, or -1
- char fn[128 - 4 - 2]; // file name
-} FILELIST;
-
-#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
-
-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;
-
-/// First index of the given hash, into the filelist[] array
-#define l -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1
-static int16_t filelist_hash[256] = {l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l};
-#undef l
-
-/// Hash a filename
-static uint8_t filehash (const char *fname)
-{
- // Larger than the return type - upper bits are used in the process
- uint32_t hash = 0;
- while (*fname)
- {
- hash = (hash << 1) + (hash >> 7) * 9 + (unsigned char)*fname;
- fname++;
- }
- return hash;
-}
-
-/// Find the filelist entry for the given filename, or NULL if it is not
-static
-FILELIST *filelist_find (const char *fname)
-{
- int16_t index = filelist_hash[filehash (fname)];
- while (index >= 0)
- {
- if (strcmp (filelist[index].fn, fname) == 0)
- return &filelist[index];
- index = filelist[index].next;
- }
- return NULL;
-}
-
-/// Copy a temporary entry into the hash map
-static FILELIST *filelist_add (FILELIST * entry)
-{
- if (filelist_entrys >= FILELIST_LIMIT)
- {
- fprintf (stderr, "filelist limit : filelist_add\n");
- exit (1);
- }
-
- if (filelist_entrys >= filelist_maxentry)
- {
- RECREATE(filelist, FILELIST, filelist_maxentry + FILELIST_ADDS);
- memset (filelist + filelist_maxentry, '\0',
- FILELIST_ADDS * sizeof (FILELIST));
- filelist_maxentry += FILELIST_ADDS;
- }
-
- uint16_t new_index = filelist_entrys++;
- uint8_t hash = filehash (entry->fn);
- entry->next = filelist_hash[hash];
- filelist_hash[hash] = new_index;
-
- filelist[new_index] = *entry;
-
- return &filelist[new_index];
-}
-
-static FILELIST *filelist_modify (FILELIST * entry)
-{
- FILELIST *fentry = filelist_find (entry->fn);
- if (fentry)
- {
- entry->next = fentry->next;
- *fentry = *entry;
- return fentry;
- }
- return filelist_add (entry);
-}
-
-/// Change fname data/*.gat to lfname data/*.wlk
-// TODO even if the file exists, don't keep reopening it every time one loads
-static
-void grfio_resnametable (const char *fname, char *lfname)
-{
- char restable[] = "data/resnametable.txt";
-
- FILE *fp = fopen_ (restable, "rb");
- if (fp == NULL)
- {
- 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;
- }
-
- char line[512];
- while (fgets (line, sizeof (line), fp))
- {
- 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)))
- {
- strcpy (lfname, "data/");
- strcpy (lfname + 5, w2);
- fclose_ (fp);
- return;
- }
- }
- fprintf(stderr, "Unable to find resource: %s\n", fname);
- fclose_ (fp);
-
- strcpy(lfname, fname);
- char* ext = lfname + strlen(lfname) - 4;
- if (!strcmp(ext, ".gat"))
- strcpy(ext, ".wlk");
- return;
-}
-
-/// Size of resource
-size_t grfio_size (const char *fname)
-{
- FILELIST *entry = filelist_find (fname);
- if (entry)
- return entry->declen;
-
- char lfname[256];
- FILELIST lentry;
- struct stat st;
-
- grfio_resnametable (fname, lfname);
-
- for (char *p = lfname; *p; p++)
- if (*p == '\\')
- *p = '/';
-
- if (stat (lfname, &st) == 0)
- {
- strncpy (lentry.fn, fname, sizeof (lentry.fn) - 1);
- lentry.declen = st.st_size;
- entry = filelist_modify (&lentry);
- }
- else
- {
- printf ("%s not found\n", fname);
- return 0;
- }
- return entry->declen;
-}
-
-void *grfio_reads (const char *fname, size_t *size)
-{
- char lfname[256];
- grfio_resnametable (fname, lfname);
-
- for (char *p = &lfname[0]; *p != 0; p++)
- if (*p == '\\')
- *p = '/'; // * At the time of Unix
-
- FILE *in = fopen_ (lfname, "rb");
- if (!in)
- {
- fprintf (stderr, "%s not found\n", fname);
- return NULL;
- }
- FILELIST lentry;
- FILELIST *entry = filelist_find (fname);
- if (entry)
- {
- lentry.declen = entry->declen;
- }
- else
- {
- 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);
- }
- uint8_t *buf2;
- CREATE (buf2, uint8_t, lentry.declen + 1024);
- if (fread (buf2, 1, lentry.declen, in) != lentry.declen)
- exit(1);
- fclose_ (in);
- in = NULL;
-
- if (size)
- *size = entry->declen;
- return buf2;
-}
diff --git a/src/common/grfio.hpp b/src/common/grfio.hpp
deleted file mode 100644
index 3485904..0000000
--- a/src/common/grfio.hpp
+++ /dev/null
@@ -1,17 +0,0 @@
-/// 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_HPP
-#define GRFIO_HPP
-
-/// 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));
-
-#endif // GRFIO_HPP
diff --git a/src/common/lock.cpp b/src/common/lock.cpp
index 2ba9a0a..82856e1 100644
--- a/src/common/lock.cpp
+++ b/src/common/lock.cpp
@@ -1,36 +1,56 @@
-#include <unistd.h>
-#include <stdio.h>
#include "lock.hpp"
+
+#include <unistd.h>
+
+#include <cstdio>
+
+#include "cxxstdio.hpp"
#include "socket.hpp"
+#include "../poison.hpp"
+
+/// number of backups to keep
+static
+const int backup_count = 10;
+
/// 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)
+FILE *lock_fopen(const char *filename, int *info)
{
- char newfile[512];
FILE *fp;
- int no = getpid ();
+ int no = getpid();
// Get a filename that doesn't already exist
+ std::string newfile;
do
{
- sprintf (newfile, "%s_%d.tmp", filename, no++);
+ newfile = STRPRINTF("%s_%d.tmp", filename, no++);
+ fp = fopen_(newfile.c_str(), "wx");
}
- while ((fp = fopen_ (newfile, "r")) && (fclose_ (fp), 1));
+ while (!fp);
*info = --no;
- return fopen_ (newfile, "w");
+ return fp;
}
// Delete the old file and rename the new file
-void lock_fclose (FILE * fp, const char *filename, int *info)
+void lock_fclose(FILE *fp, const char *filename, int *info)
{
- char newfile[512];
if (fp)
{
- fclose_ (fp);
- sprintf (newfile, "%s_%d.tmp", filename, *info);
- rename (newfile, filename);
+ fclose_(fp);
+ int n = backup_count;
+ std::string old_filename = STRPRINTF("%s.%d", filename, n);
+ while (--n)
+ {
+ std::string newer_filename = STRPRINTF("%s.%d", filename, n);
+ rename(newer_filename.c_str(), old_filename.c_str());
+ old_filename = std::move(newer_filename);
+ }
+ rename(filename, old_filename.c_str());
+
+ std::string tmpfile = STRPRINTF("%s_%d.tmp", filename, *info);
+ rename(tmpfile.c_str(), filename);
}
}
diff --git a/src/common/lock.hpp b/src/common/lock.hpp
index 19c1302..f7ce2d8 100644
--- a/src/common/lock.hpp
+++ b/src/common/lock.hpp
@@ -1,8 +1,15 @@
#ifndef LOCK_HPP
#define LOCK_HPP
+
+#include "sanity.hpp"
+
+#include <cstdio>
+
+// TODO replace with a class
+
/// Locked FILE I/O
// Changes are made in a separate file until lock_fclose
-FILE *lock_fopen (const char *filename, int *info);
-void lock_fclose (FILE * fp, const char *filename, int *info);
+FILE *lock_fopen(const char *filename, int *info);
+void lock_fclose(FILE * fp, const char *filename, int *info);
#endif // LOCK_HPP
diff --git a/src/common/md5calc.cpp b/src/common/md5calc.cpp
index b0f8e5f..1625912 100644
--- a/src/common/md5calc.cpp
+++ b/src/common/md5calc.cpp
@@ -1,6 +1,10 @@
#include "md5calc.hpp"
-#include <string.h>
-#include "mt_rand.hpp"
+
+#include <cstring>
+
+#include "random.hpp"
+
+#include "../poison.hpp"
// auxilary data
/*
@@ -9,7 +13,8 @@ sin() constant table
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] =
+static
+const uint32_t T[64] =
{
// used by round 1
0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee, //0
@@ -35,29 +40,35 @@ static const uint32_t T[64] =
// 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)
+static
+uint32_t rotate_left(uint32_t val, unsigned shift)
{
return val << shift | val >> (32-shift);
}
-static inline uint32_t F(uint32_t X, uint32_t Y, uint32_t Z)
+static
+uint32_t F(uint32_t X, uint32_t Y, uint32_t Z)
{
return (X & Y) | (~X & Z);
}
-static inline uint32_t G(uint32_t X, uint32_t Y, uint32_t Z)
+static
+uint32_t G(uint32_t X, uint32_t Y, uint32_t Z)
{
return (X & Z) | (Y & ~Z);
}
-static inline uint32_t H(uint32_t X, uint32_t Y, uint32_t Z)
+static
+uint32_t H(uint32_t X, uint32_t Y, uint32_t Z)
{
return X ^ Y ^ Z;
}
-static inline uint32_t I(uint32_t X, uint32_t Y, uint32_t Z)
+static
+uint32_t I(uint32_t X, uint32_t Y, uint32_t Z)
{
return Y ^ (X | ~Z);
}
-static const struct
+static
+const struct
{
uint8_t k : 4;
uint8_t : 0;
@@ -165,7 +176,8 @@ void MD5_to_bin(MD5_state state, uint8_t out[0x10])
out[i] = state.val[i/4] >> 8*(i%4);
}
-static const char hex[] = "0123456789abcdef";
+static
+const char hex[] = "0123456789abcdef";
void MD5_to_str(MD5_state state, char out[0x21])
{
@@ -193,7 +205,7 @@ MD5_state MD5_from_string(const char* msg, const size_t msglen)
}
// now pad 1-512 bits + the 64-bit length - may be two blocks
uint8_t buf[0x40] = {};
- memcpy (buf, msg, rem);
+ memcpy(buf, msg, rem);
buf[rem] = 0x80; // a single one bit
if (64 - rem > 8)
{
@@ -293,8 +305,9 @@ const char *MD5_saltcrypt(const char *key, const char *salt)
const char *make_salt(void) {
static char salt[6];
- for (int i=0; i<5; i++)
- salt[i] = MPRAND(48, 78);
+ for (int i = 0; i < 5; i++)
+ // 126 would probably actually be okay
+ salt[i] = random_::in(48, 125);
return salt;
}
diff --git a/src/common/md5calc.hpp b/src/common/md5calc.hpp
index 2dfaecb..de19e0f 100644
--- a/src/common/md5calc.hpp
+++ b/src/common/md5calc.hpp
@@ -5,9 +5,9 @@
#include <netinet/in.h>
-#include <stdint.h> // uint32_t, uint8_t
-#include <stddef.h> // size_t
-#include <stdio.h> // FILE*
+#include <cstdint>
+#include <cstddef>
+#include <cstdio>
/// The digest state - becomes the output
typedef struct
@@ -35,18 +35,6 @@ 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);
@@ -61,4 +49,4 @@ bool pass_ok(const char *password, const char *crypted);
/// This returns an in_addr because it is configurable whether it gets called at all
struct in_addr MD5_ip(char *secret, struct in_addr ip);
-#endif
+#endif // MD5CALC_HPP
diff --git a/src/common/mmo.hpp b/src/common/mmo.hpp
index 151fa03..32d4285 100644
--- a/src/common/mmo.hpp
+++ b/src/common/mmo.hpp
@@ -2,39 +2,31 @@
#ifndef MMO_HPP
#define MMO_HPP
-# include <time.h>
-# include "utils.hpp" // LCCWIN32
-
-# 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
+# include "sanity.hpp"
+# include "timer.t.hpp"
+# include "utils.hpp"
+
+constexpr int FIFOSIZE_SERVERLINK = 256 * 1024;
+
+constexpr int MAX_MAP_PER_SERVER = 512;
+constexpr int MAX_INVENTORY = 100;
+constexpr int MAX_AMOUNT = 30000;
+constexpr int MAX_ZENY = 1000000000; // 1G zeny
+constexpr int MAX_CART = 100;
+
+enum class SkillID : uint16_t;
+constexpr SkillID MAX_SKILL = SkillID(474); // not 450
+constexpr SkillID get_enum_min_value(SkillID) { return SkillID(); }
+constexpr SkillID get_enum_max_value(SkillID) { return MAX_SKILL; }
+
+constexpr int GLOBAL_REG_NUM = 96;
+constexpr int ACCOUNT_REG_NUM = 16;
+constexpr int ACCOUNT_REG2_NUM = 16;
+constexpr interval_t DEFAULT_WALK_SPEED = std::chrono::milliseconds(150);
+constexpr interval_t MIN_WALK_SPEED = interval_t::zero();
+constexpr interval_t MAX_WALK_SPEED = std::chrono::seconds(1);
+constexpr int MAX_STORAGE = 300;
+constexpr int MAX_PARTY = 12;
# define MIN_HAIR_STYLE battle_config.min_hair_style
# define MAX_HAIR_STYLE battle_config.max_hair_style
@@ -43,29 +35,43 @@
# 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 CHAR_CONF_NAME "conf/char_athena.conf"
-# define MIN_PORTAL_MEMO 0
-# define MAX_PORTAL_MEMO 2
+namespace e
+{
+enum class EPOS : uint16_t
+{
+ ZERO = 0x0000,
-# define MAX_STATUS_TYPE 5
+ LEGS = 0x0001,
+ WEAPON = 0x0002,
+ GLOVES = 0x0004,
+ CAPE = 0x0008,
+ MISC1 = 0x0010,
+ SHIELD = 0x0020,
+ SHOES = 0x0040,
+ MISC2 = 0x0080,
+ HAT = 0x0100,
+ TORSO = 0x0200,
-# define CHAR_CONF_NAME "conf/char_athena.conf"
+ ARROW = 0x8000,
+};
+ENUM_BITWISE_OPERATORS(EPOS)
+
+constexpr EPOS get_enum_min_value(EPOS) { return EPOS(0x0000); }
+constexpr EPOS get_enum_max_value(EPOS) { return EPOS(0xffff); }
+}
+using e::EPOS;
struct item
{
- int id;
+ int id;
short nameid;
short amount;
- unsigned short equip;
- char identify;
- char refine;
- char attribute;
+ EPOS equip;
+ uint8_t identify;
+ uint8_t refine;
+ uint8_t attribute;
short card[4];
short broken;
};
@@ -76,38 +82,100 @@ struct point
short x, y;
};
-struct skill
+namespace e
+{
+enum class SkillFlags : uint16_t;
+}
+using e::SkillFlags;
+
+struct skill_value
{
- unsigned short id, lv, flags;
+ unsigned short lv;
+ SkillFlags flags;
};
struct global_reg
{
char str[32];
- int value;
+ int value;
+};
+
+// Option and Opt1..3 in map.hpp
+namespace e
+{
+enum class Option : uint16_t;
+constexpr Option get_enum_min_value(Option) { return Option(0x0000); }
+constexpr Option get_enum_max_value(Option) { return Option(0xffff); }
+}
+using e::Option;
+
+enum class ATTR
+{
+ STR = 0,
+ AGI = 1,
+ VIT = 2,
+ INT = 3,
+ DEX = 4,
+ LUK = 5,
+
+ COUNT = 6,
+};
+
+constexpr ATTR ATTRs[6] =
+{
+ ATTR::STR,
+ ATTR::AGI,
+ ATTR::VIT,
+ ATTR::INT,
+ ATTR::DEX,
+ ATTR::LUK,
+};
+
+enum class ItemLook : uint16_t
+{
+ NONE = 0,
+ BLADE = 1, // or some other common weapons
+ _2,
+ SETZER_AND_SCYTHE = 3,
+ _6,
+ STAFF = 10,
+ BOW = 11,
+ _13 = 13,
+ _14 = 14,
+ _16 = 16,
+ SINGLE_HANDED_COUNT = 17,
+
+ DUAL_BLADE = 0x11,
+ DUAL_2 = 0x12,
+ DUAL_6 = 0x13,
+ DUAL_12 = 0x14,
+ DUAL_16 = 0x15,
+ DUAL_26 = 0x16,
};
struct mmo_charstatus
{
- int char_id;
- int account_id;
- int partner_id;
+ int char_id;
+ int account_id;
+ int partner_id;
- int base_exp, job_exp, zeny;
+ int base_exp, job_exp, zeny;
- short pc_class;
+ short species;
short status_point, skill_point;
- int hp, max_hp, sp, max_sp;
- short option, karma, manner;
+ int hp, max_hp, sp, max_sp;
+ Option option;
+ short karma, manner;
short hair, hair_color, clothes_color;
- int party_id, guild_id;
+ int party_id;
- short weapon, shield;
+ ItemLook weapon;
+ short shield;
short head_top, head_mid, head_bottom;
char name[24];
unsigned char base_level, job_level;
- short str, agi, vit, int_, dex, luk;
+ earray<short, ATTR, ATTR::COUNT> attrs;
unsigned char char_num, sex;
unsigned long mapip;
@@ -115,169 +183,53 @@ struct mmo_charstatus
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;
+ earray<skill_value, SkillID, MAX_SKILL> skill;
+ int global_reg_num;
struct global_reg global_reg[GLOBAL_REG_NUM];
- int account_reg_num;
+ int account_reg_num;
struct global_reg account_reg[ACCOUNT_REG_NUM];
- int account_reg2_num;
+ int account_reg2_num;
struct global_reg account_reg2[ACCOUNT_REG2_NUM];
};
struct storage
{
- int dirty;
- int account_id;
+ int dirty;
+ int account_id;
short storage_status;
short storage_amount;
struct item storage_[MAX_STORAGE];
};
-struct guild_storage
-{
- int dirty;
- 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;
+ int account_id;
+ int level;
};
struct party_member
{
- int account_id;
+ int account_id;
char name[24], map[24];
- int leader, online, lv;
+ int leader, online, lv;
struct map_session_data *sd;
};
struct party
{
- int party_id;
+ int party_id;
char name[24];
- int exp;
- int item;
+ int exp;
+ int item;
struct party_member member[MAX_PARTY];
};
-struct guild_member
-{
- int account_id, char_id;
- short hair, hair_color, gender, pc_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 GuildAlliance
-{
- int opposition;
- int guild_id;
- char name[24];
-};
-
-struct GuildExpulsion
-{
- 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];
- GuildAlliance alliance[MAX_GUILDALLIANCE];
- GuildExpulsion explusion[MAX_GUILDEXPLUSION];
- struct guild_skill skill[MAX_GUILDSKILL];
-};
-
-struct guild_castle
-{
- int castle_id;
- char map_name[24];
- char castle_name[24];
- char castle_event[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
-
+ int val1[5];
+ int val2[5];
};
#endif // MMO_HPP
diff --git a/src/common/mt_rand.cpp b/src/common/mt_rand.cpp
deleted file mode 100644
index 676eca1..0000000
--- a/src/common/mt_rand.cpp
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
-// This is the ``Mersenne Twister'' random number generator MT19937, which
-// generates pseudorandom integers uniformly distributed in 0..(2^32 - 1)
-// starting from any odd seed in 0..(2^32 - 1). This version is a recode
-// by Shawn Cokus (Cokus@math.washington.edu) on March 8, 1998 of a version by
-// Takuji Nishimura (who had suggestions from Topher Cooper and Marc Rieffel in
-// July-August 1997).
-//
-// Effectiveness of the recoding (on Goedel2.math.washington.edu, a DEC Alpha
-// running OSF/1) using GCC -O3 as a compiler: before recoding: 51.6 sec. to
-// generate 300 million random numbers; after recoding: 24.0 sec. for the same
-// (i.e., 46.5% of original time), so speed is now about 12.5 million random
-// number generations per second on this machine.
-//
-// According to the URL <http://www.math.keio.ac.jp/~matumoto/emt.html>
-// (and paraphrasing a bit in places), the Mersenne Twister is ``designed
-// with consideration of the flaws of various existing generators,'' has
-// a period of 2^19937 - 1, gives a sequence that is 623-dimensionally
-// equidistributed, and ``has passed many stringent tests, including the
-// die-hard test of G. Marsaglia and the load test of P. Hellekalek and
-// S. Wegenkittl.'' It is efficient in memory usage (typically using 2506
-// to 5012 bytes of static data, depending on data type sizes, and the code
-// is quite short as well). It generates random numbers in batches of 624
-// at a time, so the caching and pipelining of modern systems is exploited.
-// It is also divide- and mod-free.
-//
-// This library is free software; you can redistribute it and/or modify it
-// under the terms of the GNU Library General Public License as published by
-// the Free Software Foundation (either version 2 of the License or, at your
-// option, any later version). This library is distributed in the hope that
-// it will be useful, but WITHOUT ANY WARRANTY, without even the implied
-// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
-// the GNU Library General Public License for more details. You should have
-// received a copy of the GNU Library General Public License along with this
-// library; if not, write to the Free Software Foundation, Inc., 59 Temple
-// Place, Suite 330, Boston, MA 02111-1307, USA.
-//
-// The code as Shawn received it included the following notice:
-//
-// Copyright (C) 1997 Makoto Matsumoto and Takuji Nishimura. When
-// you use this, send an e-mail to <matumoto@math.keio.ac.jp> with
-// an appropriate reference to your work.
-//
-// It would be nice to CC: <Cokus@math.washington.edu> when you write.
-//
-*/
-
-#include <time.h>
-#include "mt_rand.hpp"
-
-#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
-
-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)
-{
- uint32_t x = seed | 1U;
- uint32_t *s = state;
- left = 0;
-
- for (int j = N; *s++ = x, --j; x *= 69069U);
-}
-
-static
-void mt_reload (void)
-{
- // if mt_seed has never been called
- if (left < -1)
- mt_seed (time (NULL));
-
- // 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];
-
- // 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);
-
- 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);
-
- // 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;
-}
-
-uint32_t mt_random (void)
-{
- if (--left < 0)
- mt_reload ();
-
- uint32_t y = *next++;
- y ^= (y >> 11);
- y ^= (y << 7) & 0x9D2C5680U;
- y ^= (y << 15) & 0xEFC60000U;
- return y ^ (y >> 18);
-}
diff --git a/src/common/mt_rand.hpp b/src/common/mt_rand.hpp
deleted file mode 100644
index c7bae4e..0000000
--- a/src/common/mt_rand.hpp
+++ /dev/null
@@ -1,24 +0,0 @@
-#ifndef MT_RAND_HPP
-#define MT_RAND_HPP
-
-# include "sanity.hpp"
-
-/// 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
- */
-// The cast is essential because the result is sometimes
-// compared with a possibly negative number.
-// Because it's using modulus, high numbers shouldn't happen anyway.
-# define MRAND(mod) ((int)(mt_random() % (mod)))
-# define MPRAND(add, mod) ((add) + MRAND(mod))
-
-#endif // MT_RAND_HPP
diff --git a/src/common/nullpo.cpp b/src/common/nullpo.cpp
index 67c839f..423ed8c 100644
--- a/src/common/nullpo.cpp
+++ b/src/common/nullpo.cpp
@@ -1,71 +1,28 @@
-#include <stdio.h>
-#include <stdarg.h>
-#include <string.h>
#include "nullpo.hpp"
-static void nullpo_info_core (const char *file, int line, const char *func);
-__attribute__((format(printf, 4, 0)))
-static void nullpo_info_core (const char *file, int line, const char *func,
- const char *fmt, va_list ap);
+#include <cstdio>
-/// 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)
- return 0;
-
- va_start (ap, fmt);
- nullpo_info_core (file, line, func, fmt, ap);
- va_end (ap);
- return 1;
-}
-bool nullpo_chk (const char *file, int line, const char *func,
- const void *target)
-{
- if (target)
- return 0;
-
- nullpo_info_core (file, line, func);
- return 1;
-}
-
-/// External functions
-void nullpo_info_f (const char *file, int line, const char *func,
- const char *fmt, ...)
-{
- va_list ap;
-
- va_start (ap, fmt);
- 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);
-}
+#include "../poison.hpp"
/// Actual output function
-static void nullpo_info_core (const char *file, int line, const char *func)
+static
+void nullpo_info(const char *file, int line, const char *func)
{
if (!file)
file = "??";
if (!func || !*func)
func = "unknown";
- fprintf (stderr, "%s:%d: in func `%s': NULL pointer\n", file, line, func);
+ fprintf(stderr, "%s:%d: in func `%s': NULL pointer\n",
+ file, line, func);
}
-static void nullpo_info_core (const char *file, int line, const char *func,
- const char *fmt, va_list ap)
+bool nullpo_chk(const char *file, int line, const char *func,
+ const void *target)
{
- nullpo_info_core(file, line, func);
- if (fmt && *fmt)
- {
- vfprintf (stderr, fmt, ap);
- if (fmt[strlen (fmt) - 1] != '\n')
- fputc('\n', stderr);
- }
+ if (target)
+ return 0;
+
+ nullpo_info(file, line, func);
+ return 1;
}
diff --git a/src/common/nullpo.hpp b/src/common/nullpo.hpp
index 7aff691..305448f 100644
--- a/src/common/nullpo.hpp
+++ b/src/common/nullpo.hpp
@@ -1,61 +1,30 @@
/// return wrappers for unexpected NULL pointers
#ifndef NULLPO_HPP
#define NULLPO_HPP
-/// Comment this out to live dangerously
-# define NULLPO_CHECK
+/// Uncomment this to live dangerously
+/// (really exist to detect mostly-unused variables)
+//# define BUG_FREE
/// 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;
+# ifndef BUG_FREE
# define nullpo_retr(ret, t) \
- if (nullpo_chk(NLP_MARK, t)) \
+ if (nullpo_chk(__FILE__, __LINE__, __PRETTY_FUNCTION__, 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
+# else // BUG_FREE
+# define nullpo_retr(ret, t) /*t*/
+# endif // BUG_FREE
-# include "sanity.hpp"
+# define nullpo_ret(t) nullpo_retr(0, t)
+# define nullpo_retv(t) nullpo_retr(, t)
-/// Used by macros in this header
-bool nullpo_chk (const char *file, int line, const char *func,
- const void *target);
+# include "sanity.hpp"
/// 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)));
-
-/// Used only by map/battle.c
-void nullpo_info (const char *file, int line, const char *func);
-
-/// Not used
-void nullpo_info_f (const char *file, int line, const char *func,
- const char *fmt, ...)
- __attribute__ ((format (printf, 4, 5)));
+bool nullpo_chk(const char *file, int line, const char *func,
+ const void *target);
#endif // NULLPO_HPP
diff --git a/src/common/operators.hpp b/src/common/operators.hpp
new file mode 100644
index 0000000..3d44b81
--- /dev/null
+++ b/src/common/operators.hpp
@@ -0,0 +1,47 @@
+#ifndef OPERATORS_HPP
+#define OPERATORS_HPP
+
+namespace _operators
+{
+ class Comparable {};
+
+ template<class T>
+ bool operator == (T l, T r)
+ {
+ return l.value == r.value;
+ }
+
+ template<class T>
+ bool operator != (T l, T r)
+ {
+ return l.value != r.value;
+ }
+
+ template<class T>
+ bool operator < (T l, T r)
+ {
+ return l.value < r.value;
+ }
+
+ template<class T>
+ bool operator <= (T l, T r)
+ {
+ return l.value <= r.value;
+ }
+
+ template<class T>
+ bool operator > (T l, T r)
+ {
+ return l.value > r.value;
+ }
+
+ template<class T>
+ bool operator >= (T l, T r)
+ {
+ return l.value >= r.value;
+ }
+}
+
+using _operators::Comparable;
+
+#endif // OPERATORS_HPP
diff --git a/src/common/random.cpp b/src/common/random.cpp
new file mode 100644
index 0000000..273dcec
--- /dev/null
+++ b/src/common/random.cpp
@@ -0,0 +1,8 @@
+#include "random2.hpp"
+
+#include "../poison.hpp"
+
+namespace random_
+{
+ std::mt19937 generate{std::random_device()()};
+} // namespace random_
diff --git a/src/common/random.hpp b/src/common/random.hpp
new file mode 100644
index 0000000..44057ed
--- /dev/null
+++ b/src/common/random.hpp
@@ -0,0 +1,69 @@
+#ifndef RANDOM_HPP
+#define RANDOM_HPP
+
+# include "random.t.hpp"
+
+# include "sanity.hpp"
+
+# include <random>
+
+// This is not namespace random since that collides with a C function,
+// but this can be revisited when everything goes into namespace tmwa.
+namespace random_
+{
+ /// Get a random number from 0 .. 2**32 - 1
+ extern std::mt19937 generate;
+
+ /// Get a random number from 0 .. bound - 1
+ inline
+ int to(int bound)
+ {
+ std::uniform_int_distribution<int> dist(0, bound - 1);
+ return dist(generate);
+ }
+
+ /// Get a random number from low .. high (inclusive!)
+ inline
+ int in(int low, int high)
+ {
+ std::uniform_int_distribution<int> dist(low, high);
+ return dist(generate);
+ }
+
+ inline
+ bool coin()
+ {
+ // sigh, can't specify <bool> directly ...
+ std::uniform_int_distribution<int> dist(false, true);
+ return dist(generate);
+ }
+
+ inline
+ bool chance(Fraction f)
+ {
+ if (f.num <= 0)
+ return false;
+ if (f.num >= f.den)
+ return true;
+ return random_::to(f.den) < f.num;
+ }
+
+ // C is usually one of:
+ // std::vector<T>
+ // std::initializer_list<T>
+ // std::array<T, n>
+ template<class C>
+ auto choice(C&& c) -> decltype(*c.begin())
+ {
+ return *(c.begin() + random_::to(c.size()));
+ }
+
+ // allow bare braces
+ template<class T>
+ T choice(std::initializer_list<T>&& il)
+ {
+ return random_::choice(il);
+ }
+} // namespace random_
+
+#endif // RANDOM_HPP
diff --git a/src/common/random.t.hpp b/src/common/random.t.hpp
new file mode 100644
index 0000000..98a6c59
--- /dev/null
+++ b/src/common/random.t.hpp
@@ -0,0 +1,23 @@
+#ifndef RANDOM_T_HPP
+#define RANDOM_T_HPP
+
+namespace random_
+{
+ struct Fraction
+ {
+ int num, den;
+ };
+
+ template<class T, T den>
+ struct Fixed
+ {
+ T num;
+
+ operator Fraction()
+ {
+ return {num, den};
+ }
+ };
+} // namespace random_
+
+#endif // RANDOM_T_HPP
diff --git a/src/common/random2.hpp b/src/common/random2.hpp
new file mode 100644
index 0000000..86deddf
--- /dev/null
+++ b/src/common/random2.hpp
@@ -0,0 +1,74 @@
+#ifndef RANDOM2_HPP
+#define RANDOM2_HPP
+
+# include "random.hpp"
+# include "utils2.hpp"
+
+# include <algorithm>
+
+namespace random_
+{
+ namespace detail
+ {
+ struct RandomIterator
+ {
+ int bound;
+ int current;
+ bool frist;
+
+ void operator ++()
+ {
+ frist = false;
+ // TODO: reimplement in terms of LFSRs, so that certain
+ // blockage patterns don't favor adjacent cells.
+ current = current + 1;
+ if (current == bound)
+ current = 0;
+ }
+ int operator *()
+ {
+ return current;
+ }
+ };
+
+ inline
+ bool operator == (RandomIterator l, RandomIterator r)
+ {
+ return l.current == r.current && l.frist == r.frist;
+ }
+
+ inline
+ bool operator != (RandomIterator l, RandomIterator r)
+ {
+ return !(l == r);
+ }
+ }
+
+ /// Yield every cell from 0 .. bound - 1 in some order.
+ /// The starting position is random, but not the order itself.
+ ///
+ /// Expected usage:
+ /// for (int i : random_::iterator(vec.size()))
+ /// if (vec[i].okay())
+ /// return frob(vec[i]);
+ inline
+ IteratorPair<detail::RandomIterator> iterator(int bound)
+ {
+ int current = random_::to(bound);
+ return
+ {
+ detail::RandomIterator{bound, current, true},
+ detail::RandomIterator{bound, current, false}
+ };
+ }
+
+ /// similar to std::random_shuffle(c.begin(), c.end()), but guaranteed
+ /// to use a good source of randomness.
+ template<class C>
+ void shuffle(C&& c)
+ {
+ std::random_shuffle(c.begin(), c.end(), random_::to);
+ }
+} // namespace random_
+
+#endif // RANDOM2_HPP
diff --git a/src/common/sanity.hpp b/src/common/sanity.hpp
index 7ffd077..e54739f 100644
--- a/src/common/sanity.hpp
+++ b/src/common/sanity.hpp
@@ -1,31 +1,54 @@
/// return wrappers for unexpected NULL pointers
#ifndef SANITY_HPP
#define SANITY_HPP
+
# ifndef __cplusplus
# error "Please compile in C++ 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
+# endif // __cplusplus
+
+# if __GNUC__ < 4
+# error "Your compiler is absolutely ancient. You have no chance ..."
+# endif // __GNUC__ < 4
-/// A name for unused function arguments - can be repeated
-# define UNUSED /* empty works for C++ */
/// Convert type assumptions to use the standard types here
# include <cstdint>
/// size_t, NULL
# include <cstddef>
+# if __GNUC__ == 4
+// clang identifies as GCC 4.2, but is mostly okay.
+// Until a bug-free release of it happens, though, I won't recommend it.
+// (patched) clang 3.1 would be the requirement
+# if __GNUC_MINOR__ < 6 && !defined(__clang__)
+# error "Please upgrade to at least GCC 4.6"
+# endif // __GNUC_MINOR__ < 6 && !defined(__clang__)
+// temporary workaround for library issues
+// since __GLIBCXX__ is hard to use
+# if __GNUC_MINOR__ == 6
+# define WORKAROUND_GCC46_COMPILER
+# endif // __GNUC_MINOR__ == 6
+# ifdef __GLIBCXX__
+// versions of libstdc++ from gcc
+// 4.6.0, 4.6.1, 4.6.2, 4.6.3
+# if __GLIBCXX__ == 20110325 \
+ || __GLIBCXX__ == 20110627 \
+ || __GLIBCXX__ == 20111026 \
+ || __GLIBCXX__ == 20120301 \
+ || __GLIBCXX__ == 20121127 // prerelease in Debian wheezy
+# define WORKAROUND_GCC46_LIBRARY
+# endif // __GLIBCXX__ == ...
+# endif // defined __GLIBCXX__
+# if defined(WORKAROUND_GCC46_COMPILER) \
+ && !defined(WORKAROUND_GCC46_LIBRARY)
+# error "Unknown gcc 4.6.x release"
+# endif // compiler and not library
+# endif // __GNUC__ == 4
+
+# if not defined(__i386__) and not defined(__x86_64__)
+// Known platform dependencies:
+// endianness for the [RW]FIFO.* macros
+// possibly, some signal-handling
+# error "Unsupported platform use x86 / amd64 only"
+# endif // not __i386__
+
#endif // SANITY_HPP
diff --git a/src/common/socket.cpp b/src/common/socket.cpp
index fab3804..2acbeb8 100644
--- a/src/common/socket.cpp
+++ b/src/common/socket.cpp
@@ -1,51 +1,74 @@
-// $Id: socket.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 <stdio.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <errno.h>
+#include "socket.hpp"
-#include <sys/socket.h>
-#include <netinet/in.h>
+#include <arpa/inet.h>
#include <netinet/tcp.h>
-#include <sys/time.h>
-#include <unistd.h>
+#include <sys/socket.h>
+//#include <sys/types.h>
#include <fcntl.h>
-#include <string.h>
+#include <unistd.h>
-#include "mmo.hpp" // [Valaris] thanks to fov
-#include "socket.hpp"
+#include <cstdlib>
+#include <cstring>
+#include <ctime>
+
+#include "cxxstdio.hpp"
+//#include "mmo.hpp"
#include "utils.hpp"
+#include "../poison.hpp"
+
+static
fd_set readfds;
-int fd_max;
-int currentuse;
+int fd_max;
+static
+int currentuse;
+static
const uint32_t RFIFO_SIZE = 65536;
+static
const uint32_t WFIFO_SIZE = 65536;
struct socket_data *session[FD_SETSIZE];
+/// clean up by discarding handled bytes
+inline
+void RFIFOFLUSH(int fd)
+{
+ memmove(session[fd]->rdata, RFIFOP(fd, 0), RFIFOREST(fd));
+ session[fd]->rdata_size = RFIFOREST(fd);
+ session[fd]->rdata_pos = 0;
+}
+
+/// how much room there is to read more data
+inline
+size_t RFIFOSPACE(int fd)
+{
+ return session[fd]->max_rdata - session[fd]->rdata_size;
+}
+
+
/// Discard all input
-static void null_parse (int fd);
+static
+void null_parse(int fd);
/// Default parser for new connections
-static void (*default_func_parse) (int) = null_parse;
+static
+void(*default_func_parse)(int) = null_parse;
-void set_defaultparse (void (*defaultparse) (int))
+void set_defaultparse(void(*defaultparse)(int))
{
default_func_parse = defaultparse;
}
/// Read from socket to the queue
-static void recv_to_fifo (int fd)
+static
+void recv_to_fifo(int fd)
{
if (session[fd]->eof)
return;
- ssize_t len = read (fd, session[fd]->rdata + session[fd]->rdata_size,
- RFIFOSPACE (fd));
+ ssize_t len = read(fd, session[fd]->rdata + session[fd]->rdata_size,
+ RFIFOSPACE(fd));
if (len > 0)
{
@@ -58,19 +81,20 @@ static void recv_to_fifo (int fd)
}
}
-static void send_from_fifo (int fd)
+static
+void send_from_fifo(int fd)
{
if (session[fd]->eof)
return;
- ssize_t len = write (fd, session[fd]->wdata, session[fd]->wdata_size);
+ ssize_t len = write(fd, session[fd]->wdata, session[fd]->wdata_size);
if (len > 0)
{
session[fd]->wdata_size -= len;
if (session[fd]->wdata_size)
{
- memmove (session[fd]->wdata, session[fd]->wdata + len,
+ memmove(session[fd]->wdata, session[fd]->wdata + len,
session[fd]->wdata_size);
}
session[fd]->connected = 1;
@@ -81,32 +105,34 @@ static void send_from_fifo (int fd)
}
}
-static void null_parse (int fd)
+static
+void null_parse(int fd)
{
- printf ("null_parse : %d\n", fd);
- RFIFOSKIP (fd, RFIFOREST (fd));
+ PRINTF("null_parse : %d\n", fd);
+ RFIFOSKIP(fd, RFIFOREST(fd));
}
-static void connect_client (int listen_fd)
+static
+void connect_client(int listen_fd)
{
struct sockaddr_in client_address;
- socklen_t len = sizeof (client_address);
+ socklen_t len = sizeof(client_address);
- int fd = accept (listen_fd, (struct sockaddr *) &client_address, &len);
+ int fd = accept(listen_fd, (struct sockaddr *) &client_address, &len);
if (fd == -1)
{
- perror ("accept");
+ perror("accept");
return;
}
if (fd_max <= fd)
{
fd_max = fd + 1;
}
- if (!free_fds ())
+ if (!free_fds())
{
- fprintf (stderr, "softlimit reached, disconnecting : %d\n", fd);
- delete_session (fd);
+ FPRINTF(stderr, "softlimit reached, disconnecting : %d\n", fd);
+ delete_session(fd);
return;
}
@@ -114,11 +140,11 @@ static void connect_client (int listen_fd)
/// 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);
+ 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!
/// Testing shows this is indeed a good idea.
- setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &yes, sizeof yes);
+ setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &yes, sizeof yes);
// Linux-ism: Set socket options to optimize for thin streams
// See http://lwn.net/Articles/308919/ and
@@ -130,13 +156,13 @@ static void connect_client (int listen_fd)
setsockopt(fd, IPPROTO_TCP, TCP_THIN_DUPACK, &yes, sizeof yes);
#endif
- FD_SET (fd, &readfds);
+ FD_SET(fd, &readfds);
- fcntl (fd, F_SETFL, O_NONBLOCK);
+ fcntl(fd, F_SETFL, O_NONBLOCK);
- CREATE (session[fd], struct socket_data, 1);
- CREATE (session[fd]->rdata, uint8_t, RFIFO_SIZE);
- CREATE (session[fd]->wdata, uint8_t, WFIFO_SIZE);
+ CREATE(session[fd], struct socket_data, 1);
+ 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;
@@ -144,72 +170,72 @@ static void connect_client (int listen_fd)
session[fd]->func_send = send_from_fifo;
session[fd]->func_parse = default_func_parse;
session[fd]->client_addr = client_address;
- session[fd]->created = time (NULL);
+ session[fd]->created = TimeT::now();
session[fd]->connected = 0;
currentuse++;
}
-int make_listen_port (uint16_t port)
+int make_listen_port(uint16_t port)
{
struct sockaddr_in server_address;
- int fd = socket (AF_INET, SOCK_STREAM, 0);
+ int fd = socket(AF_INET, SOCK_STREAM, 0);
if (fd == -1)
{
- perror ("socket");
+ perror("socket");
return -1;
}
if (fd_max <= fd)
fd_max = fd + 1;
- fcntl (fd, F_SETFL, O_NONBLOCK);
+ 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);
+ 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);
+ 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);
+ server_address.sin_addr.s_addr = htonl(INADDR_ANY);
+ server_address.sin_port = htons(port);
- if (bind (fd, (struct sockaddr *) &server_address,
- sizeof (server_address)) == -1)
+ if (bind(fd, (struct sockaddr *) &server_address,
+ sizeof(server_address)) == -1)
{
- perror ("bind");
- exit (1);
+ perror("bind");
+ exit(1);
}
- if (listen (fd, 5) == -1)
+ if (listen(fd, 5) == -1)
{ /* error */
- perror ("listen");
- exit (1);
+ perror("listen");
+ exit(1);
}
- FD_SET (fd, &readfds);
+ FD_SET(fd, &readfds);
- CREATE (session[fd], struct socket_data, 1);
+ CREATE(session[fd], struct socket_data, 1);
session[fd]->func_recv = connect_client;
- session[fd]->created = time (NULL);
+ session[fd]->created = TimeT::now();
session[fd]->connected = 1;
currentuse++;
return fd;
}
-int make_connection (uint32_t ip, uint16_t port)
+int make_connection(uint32_t ip, uint16_t port)
{
struct sockaddr_in server_address;
- int fd = socket (AF_INET, SOCK_STREAM, 0);
+ int fd = socket(AF_INET, SOCK_STREAM, 0);
if (fd == -1)
{
- perror ("socket");
+ perror("socket");
return -1;
}
if (fd_max <= fd)
@@ -219,43 +245,43 @@ int make_connection (uint32_t ip, uint16_t port)
/// 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);
+ 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);
+ 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);
+ server_address.sin_port = htons(port);
- fcntl (fd, F_SETFL, O_NONBLOCK);
+ fcntl(fd, F_SETFL, O_NONBLOCK);
/// 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));
+ connect(fd, (struct sockaddr *) &server_address,
+ sizeof(struct sockaddr_in));
- FD_SET (fd, &readfds);
+ FD_SET(fd, &readfds);
- CREATE (session[fd], struct socket_data, 1);
- CREATE (session[fd]->rdata, uint8_t, RFIFO_SIZE);
- CREATE (session[fd]->wdata, uint8_t, WFIFO_SIZE);
+ CREATE(session[fd], struct socket_data, 1);
+ 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;
session[fd]->func_recv = recv_to_fifo;
session[fd]->func_send = send_from_fifo;
session[fd]->func_parse = default_func_parse;
- session[fd]->created = time (NULL);
+ session[fd]->created = TimeT::now();
session[fd]->connected = 1;
currentuse++;
return fd;
}
-void delete_session (int fd)
+void delete_session(int fd)
{
if (fd < 0 || fd >= FD_SETSIZE)
return;
@@ -264,151 +290,155 @@ void delete_session (int fd)
// but this is cheap and good enough for the typical case
if (fd == fd_max - 1)
fd_max--;
- FD_CLR (fd, &readfds);
+ FD_CLR(fd, &readfds);
if (session[fd])
{
- free (session[fd]->rdata);
- free (session[fd]->wdata);
- free (session[fd]->session_data);
- free (session[fd]);
+ 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);
+ shutdown(fd, SHUT_RDWR);
+ close(fd);
currentuse--;
if (currentuse < 0)
{
- fprintf (stderr, "delete_session: current sessions negative!\n");
+ FPRINTF(stderr, "delete_session: current sessions negative!\n");
currentuse = 0;
}
return;
}
-void realloc_fifo (int fd, size_t rfifo_size, size_t 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, uint8_t, 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, uint8_t, wfifo_size);
+ RECREATE(s->wdata, uint8_t, wfifo_size);
s->max_wdata = wfifo_size;
}
}
-void WFIFOSET (int fd, size_t len)
+void WFIFOSET(int fd, size_t len)
{
struct socket_data *s = session[fd];
if (s->wdata_size + len + 16384 > s->max_wdata)
{
- realloc_fifo (fd, s->max_rdata, s->max_wdata << 1);
- printf ("socket: %d wdata expanded to %d bytes.\n", fd, s->max_wdata);
+ realloc_fifo(fd, s->max_rdata, s->max_wdata << 1);
+ PRINTF("socket: %d wdata expanded to %zu bytes.\n", fd, s->max_wdata);
}
if (s->wdata_size + len + 2048 < s->max_wdata)
s->wdata_size += len;
else
- fprintf (stderr, "socket: %d wdata lost !!\n", fd), abort ();
+ FPRINTF(stderr, "socket: %d wdata lost !!\n", fd), abort();
}
-void do_sendrecv (uint32_t next)
+void do_sendrecv(interval_t next_ms)
{
fd_set rfd = readfds, wfd;
- FD_ZERO (&wfd);
+ FD_ZERO(&wfd);
for (int i = 0; i < fd_max; i++)
{
if (session[i] && session[i]->wdata_size)
- FD_SET (i, &wfd);
+ FD_SET(i, &wfd);
}
struct timeval timeout;
- timeout.tv_sec = next / 1000;
- timeout.tv_usec = next % 1000 * 1000;
- if (select (fd_max, &rfd, &wfd, NULL, &timeout) <= 0)
+ {
+ std::chrono::seconds next_s = std::chrono::duration_cast<std::chrono::seconds>(next_ms);
+ std::chrono::microseconds next_us = next_ms - next_s;
+ timeout.tv_sec = next_s.count();
+ timeout.tv_usec = next_us.count();
+ }
+ 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))
+ if (FD_ISSET(i, &wfd))
{
if (session[i]->func_send)
//send_from_fifo(i);
- session[i]->func_send (i);
+ session[i]->func_send(i);
}
- if (FD_ISSET (i, &rfd))
+ if (FD_ISSET(i, &rfd))
{
if (session[i]->func_recv)
//recv_to_fifo(i);
//or connect_client(i);
- session[i]->func_recv (i);
+ session[i]->func_recv(i);
}
}
}
-void do_parsepacket (void)
+void do_parsepacket(void)
{
for (int i = 0; i < fd_max; i++)
{
if (!session[i])
continue;
if (!session[i]->connected
- && time (NULL) - session[i]->created > CONNECT_TIMEOUT)
+ && static_cast<time_t>(TimeT::now()) - static_cast<time_t>(session[i]->created) > CONNECT_TIMEOUT)
{
- printf ("Session #%d timed out\n", i);
+ PRINTF("Session #%d timed out\n", i);
session[i]->eof = 1;
}
if (!session[i]->rdata_size && !session[i]->eof)
continue;
if (session[i]->func_parse)
{
- session[i]->func_parse (i);
+ 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);
+ RFIFOFLUSH(i);
}
}
-void do_socket (void)
+void do_socket(void)
{
- FD_ZERO (&readfds);
+ FD_ZERO(&readfds);
currentuse = 3;
}
-void RFIFOSKIP (int fd, size_t 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)
{
- fprintf (stderr, "too many skip\n");
- abort ();
+ FPRINTF(stderr, "too many skip\n");
+ abort();
}
}
-void fclose_ (FILE * fp)
+void fclose_(FILE * fp)
{
- if (fclose (fp))
- perror ("fclose"), abort ();
+ if (fclose(fp))
+ perror("fclose"), abort();
currentuse--;
}
-FILE *fopen_ (const char *path, const char *mode)
+FILE *fopen_(const char *path, const char *mode)
{
- FILE *f = fopen (path, mode);
+ FILE *f = fopen(path, mode);
if (f)
currentuse++;
return f;
}
-bool free_fds (void)
+bool free_fds(void)
{
return currentuse < SOFT_LIMIT;
}
diff --git a/src/common/socket.hpp b/src/common/socket.hpp
index 00f2df0..d7c6b9c 100644
--- a/src/common/socket.hpp
+++ b/src/common/socket.hpp
@@ -3,62 +3,19 @@
# include "sanity.hpp"
-# include <stdio.h>
-
-# include <sys/types.h>
-# include <sys/socket.h>
# include <netinet/in.h>
-# include <time.h>
+# include <cstdio>
-/// 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)))
+# include "utils.hpp"
+# include "timer.t.hpp"
// Struct declaration
struct socket_data
{
/// Checks whether a newly-connected socket actually does anything
- time_t created;
+ TimeT created;
bool connected;
/// Flag needed since structure must be freed in a server-dependent manner
@@ -80,22 +37,22 @@ struct socket_data
/// 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);
+ 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);
+ void(*func_parse)(int);
/// Server-specific data type
void *session_data;
};
// save file descriptors for important stuff
-# define SOFT_LIMIT (FD_SETSIZE - 50)
+constexpr int SOFT_LIMIT = FD_SETSIZE - 50;
// socket timeout to establish a full connection in seconds
-# define CONNECT_TIMEOUT 15
+constexpr int CONNECT_TIMEOUT = 15;
/// Everyone who has connected
// note: call delete_session(i) to null out an element
@@ -106,30 +63,139 @@ extern int fd_max;
/// 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);
+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);
+int make_connection(uint32_t ip, uint16_t port);
/// free() the structure and close() the fd
-void delete_session (int);
+void delete_session(int);
/// Make a the internal queues bigger
-void realloc_fifo (int fd, size_t rfifo_size, size_t wfifo_size);
+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);
+void do_sendrecv(interval_t next);
/// Call the parser function for every socket that has read data
-void do_parsepacket (void);
+void do_parsepacket(void);
/// An init function
-void do_socket (void);
+void do_socket(void);
/// 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));
+void set_defaultparse(void(*defaultparse)(int));
/// Wrappers to track number of free FDs
-void fclose_ (FILE * fp);
-FILE *fopen_ (const char *path, const char *mode);
-bool free_fds (void);
+void fclose_(FILE * fp);
+FILE *fopen_(const char *path, const char *mode);
+
+bool free_fds(void);
+
+
+
+/// Check how much can be read
+inline
+size_t RFIFOREST(int fd)
+{
+ return session[fd]->rdata_size - session[fd]->rdata_pos;
+}
+/// Read from the queue
+inline
+const void *RFIFOP(int fd, size_t pos)
+{
+ return session[fd]->rdata + session[fd]->rdata_pos + pos;
+}
+inline
+uint8_t RFIFOB(int fd, size_t pos)
+{
+ return *static_cast<const uint8_t *>(RFIFOP(fd, pos));
+}
+inline
+uint16_t RFIFOW(int fd, size_t pos)
+{
+ return *static_cast<const uint16_t *>(RFIFOP(fd, pos));
+}
+inline
+uint32_t RFIFOL(int fd, size_t pos)
+{
+ return *static_cast<const uint32_t *>(RFIFOP(fd, pos));
+}
+
+/// Done reading
+void RFIFOSKIP(int fd, size_t len);
+
+/// Read from an arbitrary buffer
+inline
+const void *RBUFP(const uint8_t *p, size_t pos)
+{
+ return p + pos;
+}
+inline
+uint8_t RBUFB(const uint8_t *p, size_t pos)
+{
+ return *static_cast<const uint8_t *>(RBUFP(p, pos));
+}
+inline
+uint16_t RBUFW(const uint8_t *p, size_t pos)
+{
+ return *static_cast<const uint16_t *>(RBUFP(p, pos));
+}
+inline
+uint32_t RBUFL(const uint8_t *p, size_t pos)
+{
+ return *static_cast<const uint32_t *>(RBUFP(p, pos));
+}
+
+
+/// Unused - check how much data can be written
+inline
+size_t WFIFOSPACE(int fd)
+{
+ return session[fd]->max_wdata - session[fd]->wdata_size;
+}
+/// Write to the queue
+inline
+void *WFIFOP(int fd, size_t pos)
+{
+ return session[fd]->wdata + session[fd]->wdata_size + pos;
+}
+inline
+uint8_t& WFIFOB(int fd, size_t pos)
+{
+ return *static_cast<uint8_t *>(WFIFOP(fd, pos));
+}
+inline
+uint16_t& WFIFOW(int fd, size_t pos)
+{
+ return *static_cast<uint16_t *>(WFIFOP(fd, pos));
+}
+inline
+uint32_t& WFIFOL(int fd, size_t pos)
+{
+ return *static_cast<uint32_t *>(WFIFOP(fd, pos));
+}
+/// Finish writing
+void WFIFOSET(int fd, size_t len);
+
+/// Write to an arbitrary buffer
+inline
+void *WBUFP(uint8_t *p, size_t pos)
+{
+ return p + pos;
+}
+inline
+uint8_t& WBUFB(uint8_t *p, size_t pos)
+{
+ return *static_cast<uint8_t *>(WBUFP(p, pos));
+}
+inline
+uint16_t& WBUFW(uint8_t *p, size_t pos)
+{
+ return *static_cast<uint16_t *>(WBUFP(p, pos));
+}
+inline
+uint32_t& WBUFL(uint8_t *p, size_t pos)
+{
+ return *static_cast<uint32_t *>(WBUFP(p, pos));
+}
#endif // SOCKET_HPP
diff --git a/src/common/timer.cpp b/src/common/timer.cpp
index 66aaa9b..7b115d9 100644
--- a/src/common/timer.cpp
+++ b/src/common/timer.cpp
@@ -1,257 +1,193 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/types.h>
+#include "timer.hpp"
-#include <sys/socket.h>
+#include <sys/stat.h>
#include <sys/time.h>
-#include "timer.hpp"
+#include <cassert>
+#include <cstring>
+
+#include <queue>
+
+#include "cxxstdio.hpp"
#include "utils.hpp"
-static struct TimerData *timer_data;
-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;
+#include "../poison.hpp"
+
+struct TimerData
+{
+ /// This will be reset on call, to avoid problems.
+ Timer *owner;
+
+ /// When it will be triggered
+ tick_t tick;
+ /// What will be done
+ timer_func func;
+ /// Repeat rate - 0 for oneshot
+ interval_t interval;
+
+ TimerData(Timer *o, tick_t t, timer_func f, interval_t i)
+ : owner(o)
+ , tick(t)
+ , func(std::move(f))
+ , interval(i)
+ {}
+};
+
+struct TimerCompare
+{
+ /// implement "less than"
+ bool operator() (TimerData *l, TimerData *r)
+ {
+ // C++ provides a max-heap, but we want
+ // the smallest tick to be the head (a min-heap).
+ return l->tick > r->tick;
+ }
+};
-/// 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 = 0;
-/// FIXME: refactor the code to put the size in a separate variable
-//nontrivial because indices get multiplied
-static timer_id *timer_heap = NULL;
+static
+std::priority_queue<TimerData *, std::vector<TimerData *>, TimerCompare> timer_heap;
-static uint32_t gettick_cache;
-static uint8_t gettick_count = 0;
+tick_t gettick_cache;
-uint32_t gettick_nocache (void)
+tick_t milli_clock::now(void) noexcept
{
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 = 255;
- return gettick_cache = tval.tv_sec * 1000 + tval.tv_usec / 1000;
+ gettimeofday(&tval, NULL);
+ return gettick_cache = tick_t(std::chrono::seconds(tval.tv_sec)
+ + std::chrono::duration_cast<std::chrono::milliseconds>(
+ std::chrono::microseconds(tval.tv_usec)));
}
-uint32_t gettick (void)
+static
+void do_nothing(TimerData *, tick_t)
{
- if (gettick_count--)
- return gettick_cache;
- return gettick_nocache ();
}
-static void push_timer_heap (timer_id index)
+void Timer::cancel()
{
- if (timer_heap == NULL || timer_heap[0] + 1 >= timer_heap_max)
- {
- timer_heap_max += 256;
- RECREATE (timer_heap, timer_id, 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]++;
-
- 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;
+ if (!td)
+ return;
+
+ assert (this == td->owner);
+ td->owner = nullptr;
+ td->func = do_nothing;
+ td->interval = interval_t::zero();
+ td = nullptr;
}
-static timer_id top_timer_heap (void)
+void Timer::detach()
{
- if (!timer_heap || !timer_heap[0])
- return -1;
- return timer_heap[1];
+ assert (this == td->owner);
+ td->owner = nullptr;
+ td = nullptr;
}
-static timer_id pop_timer_heap (void)
+static
+void push_timer_heap(TimerData *td)
{
- if (!timer_heap || !timer_heap[0])
- return -1;
- 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)
- 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;
-
- uint32_t i = (h - 1) / 2;
- while (h)
- {
- 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;
- }
- timer_heap[h + 1] = last;
+ timer_heap.push(td);
+}
- return ret;
+static
+TimerData *top_timer_heap(void)
+{
+ if (timer_heap.empty())
+ return nullptr;
+ return timer_heap.top();
}
-timer_id add_timer (tick_t tick, timer_func func, custom_id_t id, custom_data_t data)
+static
+void pop_timer_heap(void)
{
- timer_id i;
+ timer_heap.pop();
+}
- 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];
- }
- while (i >= timer_data_num && free_timer_list_pos > 0);
- }
- else
- i = timer_data_num;
+Timer::Timer(tick_t tick, timer_func func, interval_t interval)
+: td(new TimerData(this, tick, std::move(func), interval))
+{
+ assert (interval >= interval_t::zero());
- // 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++)
- ;
- if (i >= timer_data_num && i >= timer_data_max)
- {
- if (timer_data_max == 0)
- {
- timer_data_max = 256;
- CREATE (timer_data, struct TimerData, timer_data_max);
- }
- else
- {
- timer_data_max += 256;
- RECREATE (timer_data, struct TimerData, timer_data_max);
- memset (timer_data + (timer_data_max - 256), 0,
- sizeof (struct TimerData) * 256);
- }
- }
- 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;
+ push_timer_heap(td);
}
-timer_id add_timer_interval (tick_t tick, timer_func func, custom_id_t id,
- custom_data_t data, interval_t interval)
+Timer::Timer(Timer&& t)
+: td(t.td)
{
- timer_id tid = add_timer (tick, func, id, data);
- timer_data[tid].type = TIMER_INTERVAL;
- timer_data[tid].interval = interval;
- return tid;
+ t.td = nullptr;
+ if (td)
+ {
+ assert (td->owner == &t);
+ td->owner = this;
+ }
}
-void delete_timer (timer_id id, timer_func func)
+Timer& Timer::operator = (Timer&& t)
{
- if (id == 0 || id >= timer_data_num)
+ std::swap(td, t.td);
+ if (td)
{
- fprintf (stderr, "delete_timer error : no such timer %d\n", id);
- abort ();
+ assert (td->owner == &t);
+ td->owner = this;
}
- if (timer_data[id].func != func)
+ if (t.td)
{
- fprintf (stderr, "Timer mismatch\n");
- abort ();
+ assert (t.td->owner == this);
+ t.td->owner = &t;
}
- // "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;
-}
-
-tick_t addtick_timer (timer_id tid, interval_t tick)
-{
- return timer_data[tid].tick += tick;
+ return *this;
}
-struct TimerData *get_timer (timer_id tid)
+interval_t do_timer(tick_t tick)
{
- return &timer_data[tid];
-}
-
-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
- interval_t nextmin = 1000;
+ interval_t nextmin = std::chrono::seconds(1);
- while ((i = top_timer_heap ()) != (timer_id)-1)
+ while (TimerData *td = top_timer_heap())
{
// while the heap is not empty and
- if (DIFF_TICK (timer_data[i].tick, tick) > 0)
+ if (td->tick > tick)
{
/// Return the time until the next timer needs to goes off
- nextmin = DIFF_TICK (timer_data[i].tick, tick);
+ nextmin = td->tick - tick;
break;
}
- pop_timer_heap ();
- if (timer_data[i].func)
- {
- if (DIFF_TICK (timer_data[i].tick, tick) < -1000)
- {
- // 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);
- }
- }
- switch (timer_data[i].type)
+ pop_timer_heap();
+
+ // Prevent destroying the object we're in.
+ // Note: this would be surprising in an interval timer,
+ // but all interval timers do an immediate explicit detach().
+ if (td->owner)
+ td->owner->detach();
+ // If we are too far past the requested tick, call with
+ // the current tick instead to fix reregistration problems
+ if (td->tick + std::chrono::seconds(1) < tick)
+ td->func(td, tick);
+ else
+ td->func(td, td->tick);
+
+ if (td->interval == interval_t::zero())
{
- case TIMER_ONCE_AUTODEL:
- timer_data[i].type = TIMER_NONE;
- 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 (uint32_t));
- }
- 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;
+ delete td;
+ continue;
}
+ if (td->tick + std::chrono::seconds(1) < tick)
+ td->tick = tick + td->interval;
+ else
+ td->tick += td->interval;
+ push_timer_heap(td);
}
- if (nextmin < 10)
- nextmin = 10;
- return nextmin;
+ return std::max(nextmin, std::chrono::milliseconds(10));
+}
+
+tick_t file_modified(const char *name)
+{
+ struct stat buf;
+ if (stat(name, &buf))
+ return tick_t();
+ return tick_t(std::chrono::seconds(buf.st_mtime));
}
diff --git a/src/common/timer.hpp b/src/common/timer.hpp
index fdda344..c581377 100644
--- a/src/common/timer.hpp
+++ b/src/common/timer.hpp
@@ -1,61 +1,25 @@
#ifndef TIMER_HPP
#define TIMER_HPP
-# include "sanity.hpp"
+# include "timer.t.hpp"
-enum TIMER_TYPE
-{
- TIMER_NONE,
- TIMER_ONCE_AUTODEL,
- TIMER_INTERVAL,
-};
-/// This is needed to produce a signed result when 2 ticks are subtracted
-# define DIFF_TICK(a,b) ((int32_t)((a)-(b)))
+# include "sanity.hpp"
-// TODO replace with signed 64-bit to make code more clear and protect from the future
-typedef uint32_t tick_t;
-typedef uint32_t interval_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);
+// updated automatically when using milli_clock::now()
+// which is done only by core.cpp
+extern tick_t gettick_cache;
-struct TimerData
+inline
+tick_t gettick(void)
{
- /// 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
- interval_t interval;
-};
-
-/// 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);
-
-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, interval_t);
-void delete_timer (timer_id, timer_func);
-
-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
-interval_t do_timer (tick_t tick);
+ return gettick_cache;
+}
+/// Do all timers scheduled before tick, and return the number of
+/// milliseconds until the next timer happens
+interval_t do_timer(tick_t tick);
+/// Stat a file, and return its modification time, truncated to seconds.
+tick_t file_modified(const char *name);
#endif // TIMER_HPP
diff --git a/src/common/timer.t.hpp b/src/common/timer.t.hpp
new file mode 100644
index 0000000..ee9b5d2
--- /dev/null
+++ b/src/common/timer.t.hpp
@@ -0,0 +1,66 @@
+#ifndef TIMER_T_HPP
+#define TIMER_T_HPP
+
+# include <chrono>
+# include <functional>
+
+struct TimerData;
+
+/// An implementation of the C++ "clock" concept, exposing
+/// durations in milliseconds.
+class milli_clock
+{
+public:
+ typedef std::chrono::milliseconds duration;
+ typedef duration::rep rep;
+ typedef duration::period period;
+ typedef std::chrono::time_point<milli_clock, duration> time_point;
+ static const bool is_steady = true; // assumed - not necessarily true
+
+ static time_point now() noexcept;
+};
+
+/// A point in time.
+typedef milli_clock::time_point tick_t;
+/// The difference between two points in time.
+typedef milli_clock::duration interval_t;
+/// (to get additional arguments, use std::bind or a lambda).
+typedef std::function<void (TimerData *, tick_t)> timer_func;
+
+class Timer
+{
+ friend struct TimerData;
+ TimerData *td;
+
+ Timer(const Timer&) = delete;
+ Timer& operator = (const Timer&) = delete;
+public:
+ /// Don't own anything yet.
+ Timer() : td(nullptr) {}
+ /// Schedule a timer for the given tick.
+ /// If you do not wish to keep track of it, call disconnect().
+ /// Otherwise, you may cancel() or replace (operator =) it later.
+ ///
+ /// If the interval argument is given, the timer will reschedule
+ /// itself again forever. Otherwise, it will disconnect() itself
+ /// just BEFORE it is called.
+ Timer(tick_t tick, timer_func func, interval_t interval=interval_t::zero());
+
+ Timer(Timer&& t);
+ Timer& operator = (Timer&& t);
+ ~Timer() { cancel(); }
+
+ /// Cancel the delivery of this timer's function, and make it falsy.
+ /// Implementation note: this doesn't actually remove it, just sets
+ /// the functor to do_nothing, and waits for the tick before removing.
+ void cancel();
+ /// Make it falsy without cancelling the timer,
+ void detach();
+
+ /// Check if there is a timer connected.
+ explicit operator bool() { return td; }
+ /// Check if there is no connected timer.
+ bool operator !() { return !td; }
+};
+
+#endif // TIMER_T_HPP
diff --git a/src/common/utils.cpp b/src/common/utils.cpp
index fbdd87e..49dce34 100644
--- a/src/common/utils.cpp
+++ b/src/common/utils.cpp
@@ -1,18 +1,19 @@
#include "utils.hpp"
-#include <cstring>
-#include <cstdio>
-#include <cstdlib>
-
#include <netinet/in.h>
+#include <sys/time.h>
+
+#include <algorithm>
+
+#include "../poison.hpp"
//-----------------------------------------------------
// Function to suppress control characters in a string.
//-----------------------------------------------------
-int remove_control_chars (char *str)
+int remove_control_chars(char *str)
{
- int i;
- int change = 0;
+ int i;
+ int change = 0;
for (i = 0; str[i]; i++)
{
@@ -29,39 +30,38 @@ int remove_control_chars (char *str)
//---------------------------------------------------
// E-mail check: return 0 (not correct) or 1 (valid).
//---------------------------------------------------
-int e_mail_check (const char *email)
+int e_mail_check(const char *email)
{
char ch;
const char *last_arobas;
// athena limits
- if (strlen (email) < 3 || strlen (email) > 39)
+ 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] == '@')
+ if (strchr(email, '@') == NULL || email[strlen(email) - 1] == '@')
return 0;
- if (email[strlen (email) - 1] == '.')
+ if (email[strlen(email) - 1] == '.')
return 0;
- last_arobas = strrchr (email, '@');
+ last_arobas = strrchr(email, '@');
- if (strstr (last_arobas, "@.") != NULL ||
- strstr (last_arobas, "..") != NULL)
+ if (strstr(last_arobas, "@.") != NULL ||
+ strstr(last_arobas, "..") != NULL)
return 0;
for (ch = 1; ch < 32; ch++)
{
- if (strchr (last_arobas, ch) != NULL)
+ if (strchr(last_arobas, ch) != NULL)
{
return 0;
- break;
}
}
- if (strchr (last_arobas, ' ') != NULL ||
- strchr (last_arobas, ';') != NULL)
+ if (strchr(last_arobas, ' ') != NULL ||
+ strchr(last_arobas, ';') != NULL)
return 0;
// all correct
@@ -74,15 +74,15 @@ int e_mail_check (const char *email)
//-------------------------------------------------
int config_switch (const char *str)
{
- if (strcasecmp (str, "on") == 0 || strcasecmp (str, "yes") == 0
- || strcasecmp (str, "oui") == 0 || strcasecmp (str, "ja") == 0
- || strcasecmp (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 (strcasecmp (str, "off") == 0 || strcasecmp (str, "no") == 0
- || strcasecmp (str, "non") == 0 || strcasecmp (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);
+ return atoi(str);
}
const char *ip2str(struct in_addr ip, bool extra_dot)
@@ -95,3 +95,62 @@ const char *ip2str(struct in_addr ip, bool extra_dot)
sprintf(buf, "%d.%d.%d.%d", p[0], p[1], p[2], p[3]);
return buf;
}
+
+bool split_key_value(const std::string& line, std::string *w1, std::string *w2)
+{
+ std::string::const_iterator begin = line.begin(), end = line.end();
+
+ if (line[0] == '/' && line[1] == '/')
+ return false;
+ if (line.back() == '\r')
+ --end;
+ if (line.empty())
+ return false;
+
+ if (std::find_if(begin, end,
+ [](unsigned char c) { return c < ' '; }
+ ) != line.end())
+ return false;
+ std::string::const_iterator colon = std::find(begin, end, ':');
+ if (colon == end)
+ return false;
+ w1->assign(begin, colon);
+ ++colon;
+ while (std::isspace(*colon))
+ ++colon;
+ w2->assign(colon, end);
+ return true;
+}
+
+static_assert(sizeof(timestamp_seconds_buffer) == 20, "seconds buffer");
+static_assert(sizeof(timestamp_milliseconds_buffer) == 24, "millis buffer");
+
+void stamp_time(timestamp_seconds_buffer& out, TimeT *t)
+{
+ struct tm when = t ? *t : TimeT::now();
+ strftime(out, 20, "%Y-%m-%d %H:%M:%S", &when);
+}
+void stamp_time(timestamp_milliseconds_buffer& out)
+{
+ struct timeval tv;
+ gettimeofday(&tv, NULL);
+ struct tm when = TimeT(tv.tv_sec);
+ strftime(out, 20, "%Y-%m-%d %H:%M:%S", &when);
+ sprintf(out + 19, ".%03d", int(tv.tv_usec / 1000));
+}
+
+void log_with_timestamp(FILE *out, const_string line)
+{
+ if (!line)
+ {
+ fputc('\n', out);
+ return;
+ }
+ timestamp_milliseconds_buffer tmpstr;
+ stamp_time(tmpstr);
+ fwrite(tmpstr, 1, sizeof(tmpstr), out);
+ fputs(": ", out);
+ fwrite(line.data(), 1, line.size(), out);
+ if (line.back() != '\n')
+ fputc('\n', out);
+}
diff --git a/src/common/utils.hpp b/src/common/utils.hpp
index 1097bf7..33117ac 100644
--- a/src/common/utils.hpp
+++ b/src/common/utils.hpp
@@ -3,6 +3,15 @@
#include "sanity.hpp"
+#include <cstdio>
+#include <cstring>
+
+#include <string>
+
+#include "const_array.hpp"
+#include "operators.hpp"
+#include "utils2.hpp"
+
/*
Notes about memory allocation in tmwAthena:
There used to be 3 sources of allocation: these macros,
@@ -10,17 +19,122 @@ 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.
*/
+template<class T>
+void create_impl(T *& result, size_t number)
+{
+ result = (T *)calloc(number, sizeof(T));
+ if (!result && number)
+ {
+ perror("SYSERR: malloc failure");
+ abort();
+ }
+}
+template<class T>
+void recreate_impl(T *& result, size_t number)
+{
+ result = (T *)realloc(result, sizeof(T) * number);
+ if (!result && number)
+ {
+ perror("SYSERR: realloc failure");
+ abort();
+ }
+}
+
# define CREATE(result, type, number) \
- if (!((result) = (type *) calloc ((number), sizeof(type)))) \
- { perror("SYSERR: malloc failure"); abort(); } else (void)0
+ create_impl<type>(result, number)
-# define RECREATE(result,type,number) \
- if (!((result) = (type *) realloc ((result), sizeof(type) * (number))))\
- { perror("SYSERR: realloc failure"); abort(); } else (void)0
+# define RECREATE(result, type, number) \
+ recreate_impl<type>(result, number)
-int remove_control_chars (char *str);
-int e_mail_check (const char *email);
+int remove_control_chars(char *str);
+int e_mail_check(const char *email);
int config_switch (const char *str);
const char *ip2str(struct in_addr ip, bool extra_dot = false);
+bool split_key_value(const std::string& line, std::string *w1, std::string *w2);
+
+inline
+void strzcpy(char *dest, const char *src, size_t n)
+{
+ if (n)
+ {
+ strncpy(dest, src, n);
+ dest[n-1] = '\0';
+ }
+}
+
+// Exists in place of time_t, to give it a predictable printf-format.
+// (on x86 and amd64, time_t == long, but not on x32)
+static_assert(sizeof(long long) >= sizeof(time_t), "long long >= time_t");
+struct TimeT : Comparable
+{
+ long long value;
+
+ // conversion
+ TimeT(time_t t=0) : value(t) {}
+ TimeT(struct tm t) : value(timegm(&t)) {}
+ operator time_t() { return value; }
+ operator struct tm() { time_t v = value; return *gmtime(&v); }
+
+ explicit operator bool() { return value; }
+ bool operator !() { return !value; }
+
+ // prevent surprises
+ template<class T>
+ TimeT(T) = delete;
+ template<class T>
+ operator T() = delete;
+
+ static
+ TimeT now()
+ {
+ // poisoned, but this is still in header-land
+ return time(NULL);
+ }
+
+ bool error()
+ {
+ return value == -1;
+ }
+ bool okay()
+ {
+ return !error();
+ }
+};
+
+inline
+long long convert_for_printf(TimeT t)
+{
+ return t.value;
+}
+
+inline
+long long& convert_for_scanf(TimeT& t)
+{
+ return t.value;
+}
+
+typedef char timestamp_seconds_buffer[20];
+typedef char timestamp_milliseconds_buffer[24];
+void stamp_time(timestamp_seconds_buffer&, TimeT *t=nullptr);
+void stamp_time(timestamp_milliseconds_buffer&);
+
+void log_with_timestamp(FILE *out, const_string line);
+
+#define TIMESTAMP_DUMMY "YYYY-MM-DD HH:MM:SS"
+static_assert(sizeof(TIMESTAMP_DUMMY) == sizeof(timestamp_seconds_buffer),
+ "timestamp size");
+#define WITH_TIMESTAMP(str) str TIMESTAMP_DUMMY
+// str: prefix: YYYY-MM-DD HH:MM:SS
+// sizeof: 01234567890123456789012345678
+// str + sizeof: ^
+// -1: ^
+#define REPLACE_TIMESTAMP(str, t) \
+ stamp_time( \
+ reinterpret_cast<timestamp_seconds_buffer *>( \
+ str + sizeof(str) \
+ )[-1], \
+ &t \
+ )
+
#endif //UTILS_HPP
diff --git a/src/common/utils2.hpp b/src/common/utils2.hpp
new file mode 100644
index 0000000..5f02beb
--- /dev/null
+++ b/src/common/utils2.hpp
@@ -0,0 +1,230 @@
+#ifndef UTILS2_HPP
+#define UTILS2_HPP
+
+#include "sanity.hpp"
+
+#include <functional>
+#include <iterator>
+#include <memory>
+#include <type_traits>
+
+#ifdef __clang__
+# define FALLTHROUGH [[clang::fallthrough]]
+#else
+# define FALLTHROUGH /* fallthrough */
+#endif
+
+template<class T, class E, E max>
+struct earray
+{
+ // no ctor/dtor and one public member variable for easy initialization
+ T _data[size_t(max)];
+
+ T& operator[](E v)
+ {
+ return _data[size_t(v)];
+ }
+
+ const T& operator[](E v) const
+ {
+ return _data[size_t(v)];
+ }
+
+ T *begin()
+ {
+ return _data;
+ }
+
+ T *end()
+ {
+ return _data + size_t(max);
+ }
+};
+
+template<class T, class E>
+class eptr
+{
+ T *_data;
+public:
+ eptr(decltype(nullptr)=nullptr)
+ : _data(nullptr)
+ {}
+
+ template<E max>
+ eptr(earray<T, E, max>& arr)
+ : _data(arr._data)
+ {}
+
+ T& operator [](E v)
+ {
+ return _data[size_t(v)];
+ }
+
+ explicit operator bool()
+ {
+ return _data;
+ }
+
+ bool operator not()
+ {
+ return not _data;
+ }
+};
+
+template<class It>
+class IteratorPair
+{
+ It _b, _e;
+public:
+ IteratorPair(It b, It e)
+ : _b(b), _e(e)
+ {}
+
+ It begin() { return _b; }
+ It end() { return _e; }
+};
+
+template<class It>
+IteratorPair<It> iterator_pair(It b, It e)
+{
+ return {b, e};
+}
+
+// std::underlying_type isn't supported until gcc 4.7
+// this is a poor man's emulation
+template<class E>
+struct underlying_type
+{
+ static_assert(std::is_enum<E>::value, "Only enums have underlying type!");
+ typedef typename std::conditional<
+ std::is_signed<E>::value,
+ typename std::make_signed<E>::type,
+ typename std::make_unsigned<E>::type
+ >::type type;
+};
+
+template<class E, bool=std::is_enum<E>::value>
+struct remove_enum
+{
+ typedef E type;
+};
+template<class E>
+struct remove_enum<E, true>
+{
+ typedef typename underlying_type<E>::type type;
+};
+
+
+#define ENUM_BITWISE_OPERATORS(E) \
+inline \
+E operator & (E l, E r) \
+{ \
+ typedef underlying_type<E>::type U; \
+ return E(U(l) & U(r)); \
+} \
+inline \
+E operator | (E l, E r) \
+{ \
+ typedef underlying_type<E>::type U; \
+ return E(U(l) | U(r)); \
+} \
+inline \
+E operator ^ (E l, E r) \
+{ \
+ typedef underlying_type<E>::type U; \
+ return E(U(l) ^ U(r)); \
+} \
+inline \
+E& operator &= (E& l, E r) \
+{ \
+ return l = l & r; \
+} \
+inline \
+E& operator |= (E& l, E r) \
+{ \
+ return l = l | r; \
+} \
+inline \
+E& operator ^= (E& l, E r) \
+{ \
+ return l = l ^ r; \
+} \
+inline \
+E operator ~ (E r) \
+{ \
+ return E(-1) ^ r; \
+}
+
+template<class E>
+class EnumValueIterator
+{
+ typedef typename underlying_type<E>::type U;
+ E value;
+public:
+ EnumValueIterator(E v)
+ : value(v)
+ {}
+
+ E operator *()
+ {
+ return value;
+ }
+ EnumValueIterator& operator++ ()
+ {
+ value = E(U(value) + 1);
+ return *this;
+ }
+ EnumValueIterator& operator-- ()
+ {
+ value = E(U(value) - 1);
+ return *this;
+ }
+ friend bool operator == (EnumValueIterator l, EnumValueIterator r)
+ {
+ return l.value == r.value;
+ }
+ friend bool operator != (EnumValueIterator l, EnumValueIterator r)
+ {
+ return !(l == r);
+ }
+};
+
+template<class E>
+IteratorPair<EnumValueIterator<E>> erange(E b, E e)
+{
+ return {b, e};
+}
+
+namespace ph = std::placeholders;
+
+template<class A, class B>
+typename std::common_type<A, B>::type min(A a, B b)
+{
+ return a < b ? a : b;
+}
+
+template<class A, class B>
+typename std::common_type<A, B>::type max(A a, B b)
+{
+ return b < a ? a : b;
+}
+
+template<class T>
+struct is_array_of_unknown_bound
+: std::is_same<T, typename std::remove_extent<T>::type[]>
+{};
+
+template<class T, class... A>
+typename std::enable_if<!is_array_of_unknown_bound<T>::value, std::unique_ptr<T>>::type make_unique(A&&... a)
+{
+ return std::unique_ptr<T>(new T(a...));
+}
+
+template<class T>
+typename std::enable_if<is_array_of_unknown_bound<T>::value, std::unique_ptr<T>>::type make_unique(size_t sz)
+{
+ typedef typename std::remove_extent<T>::type E;
+ return std::unique_ptr<E[]>(new E[sz]);
+}
+
+#endif // UTILS2_HPP
diff --git a/src/ladmin/ladmin.cpp b/src/ladmin/ladmin.cpp
index dbad7bb..d6a30dd 100644
--- a/src/ladmin/ladmin.cpp
+++ b/src/ladmin/ladmin.cpp
@@ -1,66 +1,44 @@
-// $Id: ladmin.c,v 1.1.1.1 2004/09/10 17:26:52 MagicalTux Exp $
-///////////////////////////////////////////////////////////////////////////
-// EAthena login-server remote administration tool
-// Ladamin in C by [Yor]
-// if you modify this software, modify ladmin in tool too.
-///////////////////////////////////////////////////////////////////////////
-
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <netinet/in.h>
-#include <sys/time.h> // gettimeofday
-#include <time.h>
-#include <sys/ioctl.h>
-#include <unistd.h> // close
-#include <signal.h>
-#include <fcntl.h>
-#include <string.h> // str*
-#include <arpa/inet.h> // inet_addr
-#include <netdb.h> // gethostbyname
-#include <stdarg.h> // valist
-#include <ctype.h> // tolower
+#include <arpa/inet.h>
+#include <netdb.h>
+#include <unistd.h>
+
+#include <fstream>
+
+#include "../common/cxxstdio.hpp"
#include "../common/core.hpp"
+#include "../common/md5calc.hpp"
#include "../common/socket.hpp"
-#include "ladmin.hpp"
#include "../common/version.hpp"
-#include "../common/mmo.hpp"
+#include "../common/utils.hpp"
-#ifdef PASSWORDENC
-#include "../common/md5calc.hpp"
-#endif
+#include "../poison.hpp"
-#ifdef MEMWATCH
-#include "memwatch.hpp"
-#endif
+#define LADMIN_CONF_NAME "conf/ladmin_athena.conf"
-int eathena_interactive_session; // from core.c
-#define Iprintf if (eathena_interactive_session) printf
+static
+int eathena_interactive_session;
+#define Iprintf if (eathena_interactive_session) PRINTF
//-------------------------------INSTRUCTIONS------------------------------
// Set the variables below:
// IP of the login server.
// Port where the login-server listens incoming packets.
// Password of administration (same of config_athena.conf).
-// Displayed language of the sofware (if not correct, english is used).
// IMPORTANT:
// Be sure that you authorize remote administration in login-server
// (see login_athena.conf, 'admin_state' parameter)
//-------------------------------------------------------------------------
+static
char loginserverip[16] = "127.0.0.1"; // IP of login-server
-int loginserverport = 6900; // Port of login-server
+static
+int loginserverport = 6900; // Port of login-server
+static
char loginserveradminpassword[24] = "admin"; // Administration password
-#ifdef PASSWORDENC
-int passenc = 2; // Encoding type of the password
-#else
-int passenc = 0; // Encoding type of the password
-#endif
-char defaultlanguage = 'E'; // Default language (F: Français/E: English)
- // (if it's not 'F', default is English)
+static
+int passenc = 2; // Encoding type of the password
+static
char ladmin_log_filename[1024] = "log/ladmin.log";
-char date_format[32] = "%Y-%m-%d %H:%M:%S";
//-------------------------------------------------------------------------
// LIST of COMMANDs that you can type at the prompt:
// To use these commands you can only type only the first letters.
@@ -70,9 +48,9 @@ char date_format[32] = "%Y-%m-%d %H:%M:%S";
//
// Note: every time you must give a account_name, you can use "" or '' (spaces can be included)
//
-// aide/help/?
+// help/?
// Display the description of the commands
-// aide/help/? [command]
+// help/? [command]
// Display the description of the specified command
//
// add <account_name> <sex> <password>
@@ -148,9 +126,6 @@ char date_format[32] = "%Y-%m-%d %H:%M:%S";
// kamib <message>
// Sends a broadcast message on all map-server (in blue).
//
-// language <language>
-// Change the language of displaying.
-//
// list/ls [start_id [end_id]]
// Display a list of accounts.
// 'start_id', 'end_id': indicate end and start identifiers.
@@ -244,152 +219,88 @@ char date_format[32] = "%Y-%m-%d %H:%M:%S";
// Displays complete information of an account.
//
//-------------------------------------------------------------------------
-int login_fd;
-int login_ip;
-int bytes_to_read = 0; // flag to know if we waiting bytes from login-server
-char command[1024];
-char parameters[1024];
-int list_first, list_last, list_type, list_count; // parameter to display a list of accounts
-int already_exit_function = 0; // sometimes, the exit function is called twice... so, don't log twice the message
+static
+int login_fd;
+static
+int login_ip;
+static
+int bytes_to_read = 0; // flag to know if we waiting bytes from login-server
+static
+char parameters[1024]; // needs to be global since it's passed to the parse function
+// really should be added to session data
+static
+int list_first, list_last, list_type, list_count; // parameter to display a list of accounts
+static
+int already_exit_function = 0; // sometimes, the exit function is called twice... so, don't log twice the message
//------------------------------
// Writing function of logs file
//------------------------------
-static __attribute__((format(printf, 1, 2)))
-int ladmin_log (const char *fmt, ...);
-int ladmin_log (const char *fmt, ...)
+#define LADMIN_LOG(fmt, ...) \
+ ladmin_log(static_cast<const std::string&>(STRPRINTF(fmt, ## __VA_ARGS__)))
+static
+void ladmin_log(const_string line)
{
- FILE *logfp;
- va_list ap;
- struct timeval tv;
- char tmpstr[2048];
-
- va_start (ap, fmt);
-
- logfp = fopen_ (ladmin_log_filename, "a");
- if (logfp)
- {
- if (fmt[0] == '\0') // jump a line if no message
- fprintf (logfp, "\n");
- else
- {
- gettimeofday (&tv, NULL);
- strftime (tmpstr, 24, date_format, localtime (&(tv.tv_sec)));
- sprintf (tmpstr + strlen (tmpstr), ".%03d: %s",
- (int) tv.tv_usec / 1000, fmt);
- vfprintf (logfp, tmpstr, ap);
- }
- fclose_ (logfp);
- }
-
- va_end (ap);
- return 0;
+ FILE *logfp = fopen_(ladmin_log_filename, "a");
+ if (!logfp)
+ return;
+ log_with_timestamp(logfp, line);
+ fclose_(logfp);
}
//---------------------------------------------
// Function to return ordonal text of a number.
//---------------------------------------------
static
-const char *makeordinal (int number)
+const char *makeordinal(int number)
{
- if (defaultlanguage == 'F')
+ if ((number % 10) < 4 && (number % 10) != 0
+ && (number < 10 || number > 20))
{
- if (number == 0)
- return "";
- else if (number == 1)
- return "er";
+ if ((number % 10) == 1)
+ return "st";
+ else if ((number % 10) == 2)
+ return "nd";
else
- return "ème";
+ return "rd";
}
else
{
- if ((number % 10) < 4 && (number % 10) != 0
- && (number < 10 || number > 20))
- {
- if ((number % 10) == 1)
- return "st";
- else if ((number % 10) == 2)
- return "nd";
- else
- return "rd";
- }
- else
- {
- return "th";
- }
+ return "th";
}
- return "";
}
//-----------------------------------------------------------------------------------------
// Function to test of the validity of an account name (return 0 if incorrect, and 1 if ok)
//-----------------------------------------------------------------------------------------
static
-int verify_accountname (const char *account_name)
+int verify_accountname(const char *account_name)
{
- int i;
+ int i;
for (i = 0; account_name[i]; i++)
{
if (account_name[i] < 32)
{
- if (defaultlanguage == 'F')
- {
- printf
- ("Caractère interdit trouvé dans le nom du compte (%d%s caractère).\n",
- i + 1, makeordinal (i + 1));
- ladmin_log
- ("Caractère interdit trouvé dans le nom du compte (%d%s caractère).\n",
- i + 1, makeordinal (i + 1));
- }
- else
- {
- printf
- ("Illegal character found in the account name (%d%s character).\n",
- i + 1, makeordinal (i + 1));
- ladmin_log
- ("Illegal character found in the account name (%d%s character).\n",
- i + 1, makeordinal (i + 1));
- }
+ PRINTF("Illegal character found in the account name (%d%s character).\n",
+ i + 1, makeordinal(i + 1));
+ LADMIN_LOG("Illegal character found in the account name (%d%s character).\n",
+ i + 1, makeordinal(i + 1));
return 0;
}
}
- if (strlen (account_name) < 4)
+ if (strlen(account_name) < 4)
{
- if (defaultlanguage == 'F')
- {
- printf
- ("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 caractères.\n");
- }
- else
- {
- printf
- ("Account name is too short. Please input an account name of 4-23 bytes.\n");
- ladmin_log
- ("Account name is too short. Please input an account name of 4-23 bytes.\n");
- }
+ PRINTF("Account name is too short. Please input an account name of 4-23 bytes.\n");
+ LADMIN_LOG("Account name is too short. Please input an account name of 4-23 bytes.\n");
return 0;
}
- if (strlen (account_name) > 23)
+ if (strlen(account_name) > 23)
{
- if (defaultlanguage == 'F')
- {
- printf
- ("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 caractères.\n");
- }
- else
- {
- printf
- ("Account name is too long. Please input an account name of 4-23 bytes.\n");
- ladmin_log
- ("Account name is too long. Please input an account name of 4-23 bytes.\n");
- }
+ PRINTF("Account name is too long. Please input an account name of 4-23 bytes.\n");
+ LADMIN_LOG("Account name is too long. Please input an account name of 4-23 bytes.\n");
return 0;
}
@@ -400,75 +311,39 @@ int verify_accountname (const char *account_name)
// Sub-function: Input of a password
//----------------------------------
static
-int typepasswd (char *password)
+int typepasswd(char *password)
{
char password1[1023], password2[1023];
- int letter;
- int i;
+ int letter;
+ int i;
- if (defaultlanguage == 'F')
- {
- ladmin_log
- ("Aucun mot de passe n'a été donné. Demande d'un mot de passe.\n");
- }
- else
- {
- ladmin_log ("No password was given. Request to obtain a password.\n");
- }
+ LADMIN_LOG("No password was given. Request to obtain a password.\n");
- memset (password1, '\0', sizeof (password1));
- memset (password2, '\0', sizeof (password2));
- if (defaultlanguage == 'F')
- printf ("\033[1;36m Entrez le mot de passe > \033[0;32;42m");
- else
- printf ("\033[1;36m Type the password > \033[0;32;42m");
+ memset(password1, '\0', sizeof(password1));
+ memset(password2, '\0', sizeof(password2));
+ PRINTF("\033[1;36m Type the password > \033[0;32;42m");
i = 0;
- while ((letter = getchar ()) != '\n')
+ while ((letter = getchar()) != '\n')
password1[i++] = letter;
- if (defaultlanguage == 'F')
- printf
- ("\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");
+ PRINTF("\033[0m\033[1;36m Verify the password > \033[0;32;42m");
i = 0;
- while ((letter = getchar ()) != '\n')
+ while ((letter = getchar()) != '\n')
password2[i++] = letter;
- printf ("\033[0m");
- fflush (stdout);
- fflush (stdin);
+ PRINTF("\033[0m");
+ fflush(stdout);
+ fflush(stdin);
- if (strcmp (password1, password2) != 0)
+ if (strcmp(password1, password2) != 0)
{
- if (defaultlanguage == 'F')
- {
- printf
- ("Erreur de vérification du mot de passe: Saisissez le même mot de passe svp.\n");
- ladmin_log
- ("Erreur de vérification du mot de passe: Saisissez le même mot de passe svp.\n");
- ladmin_log (" Premier mot de passe: %s, second mot de passe: %s.\n",
- password1, password2);
- }
- else
- {
- printf
- ("Password verification failed. Please input same password.\n");
- ladmin_log
- ("Password verification failed. Please input same password.\n");
- ladmin_log (" First password: %s, second password: %s.\n",
- password1, password2);
- }
+ PRINTF("Password verification failed. Please input same password.\n");
+ LADMIN_LOG("Password verification failed. Please input same password.\n");
+ LADMIN_LOG(" First password: %s, second password: %s.\n",
+ password1, password2);
return 0;
}
- if (defaultlanguage == 'F')
- {
- ladmin_log ("Mot de passe saisi: %s.\n", password1);
- }
- else
- {
- ladmin_log ("Typed password: %s.\n", password1);
- }
- strcpy (password, password1);
+ LADMIN_LOG("Typed password: %s.\n", password1);
+ strcpy(password, password1);
return 1;
}
@@ -476,71 +351,33 @@ int typepasswd (char *password)
// Sub-function: Test of the validity of password (return 0 if incorrect, and 1 if ok)
//------------------------------------------------------------------------------------
static
-int verify_password (const char *password)
+int verify_password(const char *password)
{
- int i;
+ int i;
for (i = 0; password[i]; i++)
{
if (password[i] < 32)
{
- if (defaultlanguage == 'F')
- {
- printf
- ("Caractère interdit trouvé dans le mot de passe (%d%s caractère).\n",
- i + 1, makeordinal (i + 1));
- ladmin_log
- ("Caractère interdit trouvé dans le nom du compte (%d%s caractère).\n",
- i + 1, makeordinal (i + 1));
- }
- else
- {
- printf
- ("Illegal character found in the password (%d%s character).\n",
- i + 1, makeordinal (i + 1));
- ladmin_log
- ("Illegal character found in the password (%d%s character).\n",
- i + 1, makeordinal (i + 1));
- }
+ PRINTF("Illegal character found in the password (%d%s character).\n",
+ i + 1, makeordinal(i + 1));
+ LADMIN_LOG("Illegal character found in the password (%d%s character).\n",
+ i + 1, makeordinal(i + 1));
return 0;
}
}
- if (strlen (password) < 4)
+ if (strlen(password) < 4)
{
- if (defaultlanguage == 'F')
- {
- printf
- ("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 caractères.\n");
- }
- else
- {
- printf
- ("Account name is too short. Please input an account name of 4-23 bytes.\n");
- ladmin_log
- ("Account name is too short. Please input an account name of 4-23 bytes.\n");
- }
+ PRINTF("Account name is too short. Please input an account name of 4-23 bytes.\n");
+ LADMIN_LOG("Account name is too short. Please input an account name of 4-23 bytes.\n");
return 0;
}
- if (strlen (password) > 23)
+ if (strlen(password) > 23)
{
- if (defaultlanguage == 'F')
- {
- printf
- ("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 caractères.\n");
- }
- else
- {
- printf
- ("Password is too long. Please input a password of 4-23 bytes.\n");
- ladmin_log
- ("Password is too long. Please input a password of 4-23 bytes.\n");
- }
+ PRINTF("Password is too long. Please input a password of 4-23 bytes.\n");
+ LADMIN_LOG("Password is too long. Please input a password of 4-23 bytes.\n");
return 0;
}
@@ -551,126 +388,122 @@ int verify_password (const char *password)
// Sub-function: Check the name of a command (return complete name)
//-----------------------------------------------------------------
static
-int check_command (char *command)
+int check_command(char *command)
{
// help
- if (strncmp (command, "aide", 2) == 0 && strncmp (command, "aide", strlen (command)) == 0) // not 1 letter command: 'aide' or 'add'?
- strcpy (command, "aide");
- else if (strncmp (command, "help", 1) == 0
- && strncmp (command, "help", strlen (command)) == 0)
- strcpy (command, "help");
+ if (strncmp(command, "help", 1) == 0
+ && strncmp(command, "help", strlen(command)) == 0)
+ strcpy(command, "help");
// general commands
- else if (strncmp (command, "add", 2) == 0 && strncmp (command, "add", strlen (command)) == 0) // not 1 letter command: 'aide' or 'add'?
- strcpy (command, "add");
- else if ((strncmp (command, "ban", 3) == 0
- && strncmp (command, "ban", strlen (command)) == 0)
- || (strncmp (command, "banish", 4) == 0
- && strncmp (command, "banish", strlen (command)) == 0))
- strcpy (command, "ban");
- else if ((strncmp (command, "banadd", 4) == 0 && strncmp (command, "banadd", strlen (command)) == 0) || // not 1 letter command: 'ba' or 'bs'? 'banadd' or 'banset' ?
- strcmp (command, "ba") == 0)
- strcpy (command, "banadd");
- else if ((strncmp (command, "banset", 4) == 0 && strncmp (command, "banset", strlen (command)) == 0) || // not 1 letter command: 'ba' or 'bs'? 'banadd' or 'banset' ?
- strcmp (command, "bs") == 0)
- strcpy (command, "banset");
- else if (strncmp (command, "block", 2) == 0
- && strncmp (command, "block", strlen (command)) == 0)
- strcpy (command, "block");
- else if (strncmp (command, "check", 2) == 0 && strncmp (command, "check", strlen (command)) == 0) // not 1 letter command: 'check' or 'create'?
- strcpy (command, "check");
- else if (strncmp (command, "create", 2) == 0 && strncmp (command, "create", strlen (command)) == 0) // not 1 letter command: 'check' or 'create'?
- strcpy (command, "create");
- else if (strncmp (command, "delete", 1) == 0
- && strncmp (command, "delete", strlen (command)) == 0)
- strcpy (command, "delete");
- else if ((strncmp (command, "email", 2) == 0 && strncmp (command, "email", strlen (command)) == 0) || // not 1 letter command: 'email', 'end' or 'exit'?
- (strncmp (command, "e-mail", 2) == 0
- && strncmp (command, "e-mail", strlen (command)) == 0))
- strcpy (command, "email");
- else if (strncmp (command, "getcount", 2) == 0 && strncmp (command, "getcount", strlen (command)) == 0) // not 1 letter command: 'getcount' or 'gm'?
- strcpy (command, "getcount");
+ else if (strncmp(command, "add", 2) == 0 && strncmp(command, "add", strlen(command)) == 0)
+ strcpy(command, "add");
+ else if ((strncmp(command, "ban", 3) == 0
+ && strncmp(command, "ban", strlen(command)) == 0)
+ ||(strncmp(command, "banish", 4) == 0
+ && strncmp(command, "banish", strlen(command)) == 0))
+ strcpy(command, "ban");
+ else if ((strncmp(command, "banadd", 4) == 0 && strncmp(command, "banadd", strlen(command)) == 0) || // not 1 letter command: 'ba' or 'bs'? 'banadd' or 'banset' ?
+ strcmp(command, "ba") == 0)
+ strcpy(command, "banadd");
+ else if ((strncmp(command, "banset", 4) == 0 && strncmp(command, "banset", strlen(command)) == 0) || // not 1 letter command: 'ba' or 'bs'? 'banadd' or 'banset' ?
+ strcmp(command, "bs") == 0)
+ strcpy(command, "banset");
+ else if (strncmp(command, "block", 2) == 0
+ && strncmp(command, "block", strlen(command)) == 0)
+ strcpy(command, "block");
+ else if (strncmp(command, "check", 2) == 0 && strncmp(command, "check", strlen(command)) == 0) // not 1 letter command: 'check' or 'create'?
+ strcpy(command, "check");
+ else if (strncmp(command, "create", 2) == 0 && strncmp(command, "create", strlen(command)) == 0) // not 1 letter command: 'check' or 'create'?
+ strcpy(command, "create");
+ else if (strncmp(command, "delete", 1) == 0
+ && strncmp(command, "delete", strlen(command)) == 0)
+ strcpy(command, "delete");
+ else if ((strncmp(command, "email", 2) == 0 && strncmp(command, "email", strlen(command)) == 0) || // not 1 letter command: 'email', 'end' or 'exit'?
+ (strncmp(command, "e-mail", 2) == 0
+ && strncmp(command, "e-mail", strlen(command)) == 0))
+ strcpy(command, "email");
+ else if (strncmp(command, "getcount", 2) == 0 && strncmp(command, "getcount", strlen(command)) == 0) // not 1 letter command: 'getcount' or 'gm'?
+ strcpy(command, "getcount");
// else if (strncmp(command, "gm", 2) == 0 && strncmp(command, "gm", strlen(command)) == 0) // not 1 letter command: 'getcount' or 'gm'?
// strcpy(command, "gm");
// else if (strncmp(command, "id", 2) == 0 && strncmp(command, "id", strlen(command)) == 0) // not 1 letter command: 'id' or 'info'?
// strcpy(command, "id");
- else if (strncmp (command, "info", 2) == 0 && strncmp (command, "info", strlen (command)) == 0) // not 1 letter command: 'id' or 'info'?
- strcpy (command, "info");
+ else if (strncmp(command, "info", 2) == 0 && strncmp(command, "info", strlen(command)) == 0) // not 1 letter command: 'id' or 'info'?
+ strcpy(command, "info");
// else if (strncmp(command, "kami", 4) == 0 && strncmp(command, "kami", strlen(command)) == 0) // only all letters command: 'kami' or 'kamib'?
// strcpy(command, "kami");
// else if (strncmp(command, "kamib", 5) == 0 && strncmp(command, "kamib", strlen(command)) == 0) // only all letters command: 'kami' or 'kamib'?
// strcpy(command, "kamib");
- else if ((strncmp (command, "language", 2) == 0 && strncmp (command, "language", strlen (command)) == 0)) // not 1 letter command: 'language' or 'list'?
- strcpy (command, "language");
- else if ((strncmp (command, "list", 2) == 0 && strncmp (command, "list", strlen (command)) == 0) || // 'list' is default list command // not 1 letter command: 'language' or 'list'?
- strcmp (command, "ls") == 0)
- strcpy (command, "list");
- else if (strncmp (command, "itemfrob", 6) == 0)
- strcpy (command, "itemfrob");
- else if ((strncmp (command, "listban", 5) == 0
- && strncmp (command, "listban", strlen (command)) == 0)
- || (strncmp (command, "lsban", 3) == 0
- && strncmp (command, "lsban", strlen (command)) == 0)
- || strcmp (command, "lb") == 0)
- strcpy (command, "listban");
- else if ((strncmp (command, "listgm", 5) == 0
- && strncmp (command, "listgm", strlen (command)) == 0)
- || (strncmp (command, "lsgm", 3) == 0
- && strncmp (command, "lsgm", strlen (command)) == 0)
- || strcmp (command, "lg") == 0)
- strcpy (command, "listgm");
- else if ((strncmp (command, "listok", 5) == 0
- && strncmp (command, "listok", strlen (command)) == 0)
- || (strncmp (command, "lsok", 3) == 0
- && strncmp (command, "lsok", strlen (command)) == 0)
- || strcmp (command, "lo") == 0)
- strcpy (command, "listok");
- else if (strncmp (command, "memo", 1) == 0
- && strncmp (command, "memo", strlen (command)) == 0)
- strcpy (command, "memo");
- else if (strncmp (command, "name", 1) == 0
- && strncmp (command, "name", strlen (command)) == 0)
- strcpy (command, "name");
- else if ((strncmp (command, "password", 1) == 0
- && strncmp (command, "password", strlen (command)) == 0)
- || strcmp (command, "passwd") == 0)
- strcpy (command, "password");
- else if (strncmp (command, "reloadgm", 1) == 0
- && strncmp (command, "reloadgm", strlen (command)) == 0)
- strcpy (command, "reloadgm");
- else if (strncmp (command, "search", 3) == 0 && strncmp (command, "search", strlen (command)) == 0) // not 1 letter command: 'search', 'state' or 'sex'?
- strcpy (command, "search"); // not 2 letters command: 'search' or 'sex'?
+ else if ((strncmp(command, "list", 2) == 0 && strncmp(command, "list", strlen(command)) == 0) || // 'list' is default list command
+ strcmp(command, "ls") == 0)
+ strcpy(command, "list");
+ else if (strncmp(command, "itemfrob", 6) == 0)
+ strcpy(command, "itemfrob");
+ else if ((strncmp(command, "listban", 5) == 0
+ && strncmp(command, "listban", strlen(command)) == 0)
+ ||(strncmp(command, "lsban", 3) == 0
+ && strncmp(command, "lsban", strlen(command)) == 0)
+ || strcmp(command, "lb") == 0)
+ strcpy(command, "listban");
+ else if ((strncmp(command, "listgm", 5) == 0
+ && strncmp(command, "listgm", strlen(command)) == 0)
+ ||(strncmp(command, "lsgm", 3) == 0
+ && strncmp(command, "lsgm", strlen(command)) == 0)
+ || strcmp(command, "lg") == 0)
+ strcpy(command, "listgm");
+ else if ((strncmp(command, "listok", 5) == 0
+ && strncmp(command, "listok", strlen(command)) == 0)
+ ||(strncmp(command, "lsok", 3) == 0
+ && strncmp(command, "lsok", strlen(command)) == 0)
+ || strcmp(command, "lo") == 0)
+ strcpy(command, "listok");
+ else if (strncmp(command, "memo", 1) == 0
+ && strncmp(command, "memo", strlen(command)) == 0)
+ strcpy(command, "memo");
+ else if (strncmp(command, "name", 1) == 0
+ && strncmp(command, "name", strlen(command)) == 0)
+ strcpy(command, "name");
+ else if ((strncmp(command, "password", 1) == 0
+ && strncmp(command, "password", strlen(command)) == 0)
+ || strcmp(command, "passwd") == 0)
+ strcpy(command, "password");
+ else if (strncmp(command, "reloadgm", 1) == 0
+ && strncmp(command, "reloadgm", strlen(command)) == 0)
+ strcpy(command, "reloadgm");
+ else if (strncmp(command, "search", 3) == 0 && strncmp(command, "search", strlen(command)) == 0) // not 1 letter command: 'search', 'state' or 'sex'?
+ strcpy(command, "search"); // not 2 letters command: 'search' or 'sex'?
// else if (strncmp(command, "sex", 3) == 0 && strncmp(command, "sex", strlen(command)) == 0) // not 1 letter command: 'search', 'state' or 'sex'?
// strcpy(command, "sex"); // not 2 letters command: 'search' or 'sex'?
- else if (strncmp (command, "state", 2) == 0 && strncmp (command, "state", strlen (command)) == 0) // not 1 letter command: 'search', 'state' or 'sex'?
- strcpy (command, "state");
- else if ((strncmp (command, "timeadd", 5) == 0 && strncmp (command, "timeadd", strlen (command)) == 0) || // not 1 letter command: 'ta' or 'ts'? 'timeadd' or 'timeset'?
- strcmp (command, "ta") == 0)
- strcpy (command, "timeadd");
- else if ((strncmp (command, "timeset", 5) == 0 && strncmp (command, "timeset", strlen (command)) == 0) || // not 1 letter command: 'ta' or 'ts'? 'timeadd' or 'timeset'?
- strcmp (command, "ts") == 0)
- strcpy (command, "timeset");
- else if ((strncmp (command, "unban", 5) == 0
- && strncmp (command, "unban", strlen (command)) == 0)
- || (strncmp (command, "unbanish", 4) == 0
- && strncmp (command, "unbanish", strlen (command)) == 0))
- strcpy (command, "unban");
- else if (strncmp (command, "unblock", 4) == 0
- && strncmp (command, "unblock", strlen (command)) == 0)
- strcpy (command, "unblock");
- else if (strncmp (command, "version", 1) == 0
- && strncmp (command, "version", strlen (command)) == 0)
- strcpy (command, "version");
- else if (strncmp (command, "who", 1) == 0
- && strncmp (command, "who", strlen (command)) == 0)
- strcpy (command, "who");
+ else if (strncmp(command, "state", 2) == 0 && strncmp(command, "state", strlen(command)) == 0) // not 1 letter command: 'search', 'state' or 'sex'?
+ strcpy(command, "state");
+ else if ((strncmp(command, "timeadd", 5) == 0 && strncmp(command, "timeadd", strlen(command)) == 0) || // not 1 letter command: 'ta' or 'ts'? 'timeadd' or 'timeset'?
+ strcmp(command, "ta") == 0)
+ strcpy(command, "timeadd");
+ else if ((strncmp(command, "timeset", 5) == 0 && strncmp(command, "timeset", strlen(command)) == 0) || // not 1 letter command: 'ta' or 'ts'? 'timeadd' or 'timeset'?
+ strcmp(command, "ts") == 0)
+ strcpy(command, "timeset");
+ else if ((strncmp(command, "unban", 5) == 0
+ && strncmp(command, "unban", strlen(command)) == 0)
+ ||(strncmp(command, "unbanish", 4) == 0
+ && strncmp(command, "unbanish", strlen(command)) == 0))
+ strcpy(command, "unban");
+ else if (strncmp(command, "unblock", 4) == 0
+ && strncmp(command, "unblock", strlen(command)) == 0)
+ strcpy(command, "unblock");
+ else if (strncmp(command, "version", 1) == 0
+ && strncmp(command, "version", strlen(command)) == 0)
+ strcpy(command, "version");
+ else if (strncmp(command, "who", 1) == 0
+ && strncmp(command, "who", strlen(command)) == 0)
+ strcpy(command, "who");
// quit
- else if (strncmp (command, "quit", 1) == 0
- && strncmp (command, "quit", strlen (command)) == 0)
- strcpy (command, "quit");
- else if (strncmp (command, "exit", 2) == 0 && strncmp (command, "exit", strlen (command)) == 0) // not 1 letter command: 'email', 'end' or 'exit'?
- strcpy (command, "exit");
- else if (strncmp (command, "end", 2) == 0 && strncmp (command, "end", strlen (command)) == 0) // not 1 letter command: 'email', 'end' or 'exit'?
- strcpy (command, "end");
+ else if (strncmp(command, "quit", 1) == 0
+ && strncmp(command, "quit", strlen(command)) == 0)
+ strcpy(command, "quit");
+ else if (strncmp(command, "exit", 2) == 0 && strncmp(command, "exit", strlen(command)) == 0) // not 1 letter command: 'email', 'end' or 'exit'?
+ strcpy(command, "exit");
+ else if (strncmp(command, "end", 2) == 0 && strncmp(command, "end", strlen(command)) == 0) // not 1 letter command: 'email', 'end' or 'exit'?
+ strcpy(command, "end");
return 0;
}
@@ -679,859 +512,342 @@ int check_command (char *command)
// Sub-function: Display commands of ladmin
//-----------------------------------------
static
-void display_help (const char *param, int language)
+void display_help(const char *param)
{
char command[1023];
- int i;
+ int i;
- memset (command, '\0', sizeof (command));
+ memset(command, '\0', sizeof(command));
- if (sscanf (param, "%s ", command) < 1 || strlen (command) == 0)
- strcpy (command, ""); // any value that is not a command
+ if (sscanf(param, "%s ", command) < 1 || strlen(command) == 0)
+ strcpy(command, ""); // any value that is not a command
if (command[0] == '?')
{
- if (defaultlanguage == 'F')
- strcpy (command, "aide");
- else
- strcpy (command, "help");
+ strcpy(command, "help");
}
// lowercase for command
for (i = 0; command[i]; i++)
- command[i] = tolower (command[i]);
+ command[i] = tolower(command[i]);
// Analyse of the command
- check_command (command); // give complete name to the command
+ check_command(command); // give complete name to the command
+
+ LADMIN_LOG("Displaying of the commands or a command.\n");
- if (defaultlanguage == 'F')
+ if (strcmp(command, "help") == 0)
{
- ladmin_log ("Affichage des commandes ou d'une commande.\n");
+ PRINTF("help/?\n");
+ PRINTF(" Display the description of the commands\n");
+ PRINTF("help/? [command]\n");
+ PRINTF(" Display the description of the specified command\n");
+// general commands
}
- else
+ else if (strcmp(command, "add") == 0)
{
- ladmin_log ("Displaying of the commands or a command.\n");
+ PRINTF("add <account_name> <sex> <password>\n");
+ PRINTF(" Create an account with the default email (a@a.com).\n");
+ PRINTF(" Concerning the sex, only the first letter is used (F or M).\n");
+ PRINTF(" The e-mail is set to a@a.com (default e-mail). It's like to have no e-mail.\n");
+ PRINTF(" When the password is omitted,\n");
+ PRINTF(" the input is done without displaying of the pressed keys.\n");
+ PRINTF(" <example> add testname Male testpass\n");
}
-
- if (language == 1)
+ else if (strcmp(command, "ban") == 0)
{
- if (strcmp (command, "aide") == 0)
- {
- printf ("aide/help/?\n");
- printf (" Affiche la description des commandes\n");
- printf ("aide/help/? [commande]\n");
- printf (" Affiche la description de la commande specifiée\n");
- }
- else if (strcmp (command, "help") == 0)
- {
- printf ("aide/help/?\n");
- printf (" Display the description of the commands\n");
- printf ("aide/help/? [command]\n");
- printf (" Display the description of the specified command\n");
-// general commands
- }
- else if (strcmp (command, "add") == 0)
- {
- printf ("add <nomcompte> <sexe> <motdepasse>\n");
- printf (" Crée un compte avec l'email par défaut (a@a.com).\n");
- printf
- (" Concernant le sexe, seule la première lettre compte (F ou M).\n");
- printf
- (" 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 (" <exemple> add testname Male testpass\n");
- }
- else if (strcmp (command, "ban") == 0)
- {
- printf ("ban/banish aaaa/mm/jj hh:mm:ss <nom compte>\n");
- printf (" Change la date de fin de bannissement d'un compte.\n");
- printf (" Comme banset, mais <nom compte> est à la fin.\n");
- }
- else if (strcmp (command, "banadd") == 0)
- {
- printf ("banadd <nomcompte> <Modificateur>\n");
- printf
- (" 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 (" 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");
- printf (" mn: minute\n");
- printf (" s: seconde\n");
- printf (" <exemple> 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 même temps.\n");
- printf
- ("NOTE: Si vous modifez la date de banissement d'un compte non bani,\n");
- printf
- (" vous indiquez comme date (le moment actuel +- les ajustements)\n");
- }
- else if (strcmp (command, "banset") == 0)
- {
- printf ("banset <nomcompte> aaaa/mm/jj [hh:mm:ss]\n");
- printf (" Change la date de fin de bannissement d'un compte.\n");
- printf (" Heure par défaut [hh:mm:ss]: 23:59:59.\n");
- printf ("banset <nomcompte> 0\n");
- printf (" Débanni un compte (0 = de-banni).\n");
- }
- else if (strcmp (command, "block") == 0)
- {
- printf ("block <nom compte>\n");
- printf
- (" Place le status d'un compte à 5 (You have been blocked by the GM Team).\n");
- printf
- (" La commande est l'équivalent de state <nom_compte> 5.\n");
- }
- else if (strcmp (command, "check") == 0)
- {
- printf ("check <nomcompte> <motdepasse>\n");
- printf
- (" 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 méthode que vous possédez pour savoir\n");
- printf
- (" si un mot de passe est le bon. L'autre méthode est\n");
- printf
- (" d'avoir un accès ('physique') au fichier des comptes.\n");
- }
- else if (strcmp (command, "create") == 0)
- {
- printf ("create <nomcompte> <sexe> <email> <motdepasse>\n");
- printf (" Comme la commande add, mais avec l'e-mail en plus.\n");
- printf
- (" <exemple> create testname Male mon@mail.com testpass\n");
- }
- else if (strcmp (command, "delete") == 0)
- {
- printf ("del <nom compte>\n");
- printf (" Supprime un compte.\n");
- printf
- (" La commande demande confirmation. Après confirmation, le compte est détruit.\n");
- }
- else if (strcmp (command, "email") == 0)
- {
- printf ("email <nomcompte> <email>\n");
- printf (" Modifie l'e-mail d'un compte.\n");
- }
- else if (strcmp (command, "getcount") == 0)
- {
- printf ("getcount\n");
- printf
- (" Donne le nombre de joueurs en ligne par serveur de char.\n");
- }
- else if (strcmp (command, "gm") == 0)
- {
- printf ("gm <nomcompte> [Niveau_GM]\n");
- printf (" Modifie le niveau de GM d'un compte.\n");
- printf
- (" Valeur par défaut: 0 (suppression du niveau de GM).\n");
- printf (" <exemple> gm nomtest 80\n");
- }
- else if (strcmp (command, "id") == 0)
- {
- printf ("id <nom compte>\n");
- printf (" Donne l'id d'un compte.\n");
- }
- else if (strcmp (command, "info") == 0)
- {
- printf ("info <idcompte>\n");
- printf (" Affiche les informations sur un compte.\n");
- }
- else if (strcmp (command, "kami") == 0)
- {
- printf ("kami <message>\n");
- printf
- (" Envoi un message général sur tous les serveurs de map (en jaune).\n");
- }
- else if (strcmp (command, "kamib") == 0)
- {
- printf ("kamib <message>\n");
- printf
- (" Envoi un message général sur tous les serveurs de map (en bleu).\n");
- }
- else if (strcmp (command, "language") == 0)
- {
- printf ("language <langue>\n");
- printf (" Change la langue d'affichage.\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 départ et de fin.\n");
- printf
- (" La recherche par nom n'est pas possible avec cette commande.\n");
- printf (" <example> list 10 9999999\n");
- }
- else if (strcmp (command, "itemfrob") == 0)
- {
- printf ("Not localised yet.\n");
- }
- else if (strcmp (command, "listban") == 0)
- {
- printf ("listBan/lsBan [Premier_id [Dernier_id]]\n");
- printf
- (" Comme list/ls, mais seulement pour les comptes avec statut ou bannis.\n");
- }
- else if (strcmp (command, "listgm") == 0)
- {
- printf ("listGM/lsGM [Premier_id [Dernier_id]]\n");
- printf (" Comme list/ls, mais seulement pour les comptes GM.\n");
- }
- else if (strcmp (command, "listok") == 0)
- {
- printf ("listOK/lsOK [Premier_id [Dernier_id]]\n");
- printf
- (" Comme list/ls, mais seulement pour les comptes sans statut et non bannis.\n");
- }
- else if (strcmp (command, "memo") == 0)
- {
- printf ("memo <nomcompte> <memo>\n");
- printf (" Modifie le mémo d'un compte.\n");
- printf
- (" 'memo': Il peut avoir jusqu'à 253 caractères (avec des espaces ou non).\n");
- }
- else if (strcmp (command, "name") == 0)
- {
- printf ("name <idcompte>\n");
- printf (" Donne le nom d'un compte.\n");
- }
- else if (strcmp (command, "password") == 0)
- {
- printf ("passwd <nomcompte> <nouveaumotdepasse>\n");
- printf (" Change le mot de passe d'un compte.\n");
- printf (" Lorsque nouveaumotdepasse est omis,\n");
- printf (" la saisie se fait sans que la frappe ne se voit.\n");
- }
- else if (strcmp (command, "reloadgm") == 0)
- {
- printf ("reloadGM\n");
- printf (" Reload GM configuration file\n");
- }
- else if (strcmp (command, "search") == 0)
- {
- printf ("search <expression>\n");
- printf (" Cherche des comptes.\n");
- printf (" Affiche les comptes dont les noms correspondent.\n");
-// printf("search -r/-e/--expr/--regex <expression>\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)
- {
- printf ("sex <nomcompte> <sexe>\n");
- printf (" Modifie le sexe d'un compte.\n");
- printf (" <exemple> sex testname Male\n");
- }
- else if (strcmp (command, "state") == 0)
- {
- printf ("state <nomcompte> <nouveaustatut> <message_erreur_7>\n");
- printf (" Change le statut d'un compte.\n");
- printf
- (" '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");
- printf (" 3 = This ID is expired\n");
- printf (" 4 = Rejected from Server\n");
- printf
- (" 5 = You have been blocked by the GM Team\n");
- printf
- (" 6 = Your Game's EXE file is not the latest version\n");
- printf
- (" 7 = You are Prohibited to log in until...\n");
- printf
- (" 8 = Server is jammed due to over populated\n");
- printf (" 9 = No MSG\n");
- printf (" 100 = This ID has been totally erased\n");
- printf
- (" all other values are 'No MSG', then use state 9 please.\n");
- printf (" 'message_erreur_7': message du code erreur 6 =\n");
- printf
- (" = Your are Prohibited to log in until... (packet 0x006a)\n");
- }
- else if (strcmp (command, "timeadd") == 0)
- {
- printf ("timeadd <nomcompte> <modificateur>\n");
- printf
- (" 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 (" 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");
- printf (" mn: minute\n");
- printf (" s: seconde\n");
- printf (" <exemple> 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 même temps.\n");
- printf
- ("NOTE: Vous ne pouvez pas modifier une limite de validité illimitée. Si vous\n");
- printf
- (" désirez le faire, c'est que vous voulez probablement créer un limite de\n");
- printf
- (" validité limitée. Donc, en premier, fixé une limite de valitidé.\n");
- }
- else if (strcmp (command, "timeadd") == 0)
- {
- printf ("timeset <nomcompte> aaaa/mm/jj [hh:mm:ss]\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 <nomcompte> 0\n");
- printf
- (" Donne une limite de validité illimitée (0 = illimitée).\n");
- }
- else if (strcmp (command, "unban") == 0)
- {
- printf ("unban/unbanish <nom compte>\n");
- printf (" Ote le banissement d'un compte.\n");
- printf
- (" La commande est l'équivalent de banset <nom_compte> 0.\n");
- }
- else if (strcmp (command, "unblock") == 0)
- {
- printf ("unblock <nom compte>\n");
- printf (" Place le status d'un compte à 0 (Compte ok).\n");
- printf
- (" La commande est l'équivalent de state <nom_compte> 0.\n");
- }
- else if (strcmp (command, "version") == 0)
- {
- printf ("version\n");
- printf (" Affiche la version du login-serveur.\n");
- }
- else if (strcmp (command, "who") == 0)
- {
- printf ("who <nom compte>\n");
- printf (" Affiche les informations sur un compte.\n");
+ PRINTF("ban/banish yyyy/mm/dd hh:mm:ss <account name>\n");
+ PRINTF(" Changes the final date of a banishment of an account.\n");
+ PRINTF(" Like banset, but <account name> is at end.\n");
+ }
+ else if (strcmp(command, "banadd") == 0)
+ {
+ PRINTF("banadd <account_name> <modifier>\n");
+ PRINTF(" Adds or substracts time from the final date of a banishment of an account.\n");
+ PRINTF(" Modifier is done as follows:\n");
+ PRINTF(" Adjustment value (-1, 1, +1, etc...)\n");
+ PRINTF(" Modified element:\n");
+ PRINTF(" a or y: year\n");
+ PRINTF(" m: month\n");
+ PRINTF(" j or d: day\n");
+ PRINTF(" h: hour\n");
+ PRINTF(" mn: minute\n");
+ PRINTF(" s: second\n");
+ PRINTF(" <example> banadd testname +1m-2mn1s-6y\n");
+ PRINTF(" this example adds 1 month and 1 second, and substracts 2 minutes\n");
+ PRINTF(" and 6 years at the same time.\n");
+ PRINTF("NOTE: If you modify the final date of a non-banished account,\n");
+ PRINTF(" you fix the final date to (actual time +- adjustments)\n");
+ }
+ else if (strcmp(command, "banset") == 0)
+ {
+ PRINTF("banset <account_name> yyyy/mm/dd [hh:mm:ss]\n");
+ PRINTF(" Changes the final date of a banishment of an account.\n");
+ PRINTF(" Default time [hh:mm:ss]: 23:59:59.\n");
+ PRINTF("banset <account_name> 0\n");
+ PRINTF(" Set a non-banished account (0 = unbanished).\n");
+ }
+ else if (strcmp(command, "block") == 0)
+ {
+ PRINTF("block <account name>\n");
+ PRINTF(" Set state 5 (You have been blocked by the GM Team) to an account.\n");
+ PRINTF(" This command works like state <account_name> 5.\n");
+ }
+ else if (strcmp(command, "check") == 0)
+ {
+ PRINTF("check <account_name> <password>\n");
+ PRINTF(" Check the validity of a password for an account.\n");
+ PRINTF(" NOTE: Server will never sends back a password.\n");
+ PRINTF(" It's the only method you have to know if a password is correct.\n");
+ PRINTF(" The other method is to have a ('physical') access to the accounts file.\n");
+ }
+ else if (strcmp(command, "create") == 0)
+ {
+ PRINTF("create <account_name> <sex> <email> <password>\n");
+ PRINTF(" Like the 'add' command, but with e-mail moreover.\n");
+ PRINTF(" <example> create testname Male my@mail.com testpass\n");
+ }
+ else if (strcmp(command, "delete") == 0)
+ {
+ PRINTF("del <account name>\n");
+ PRINTF(" Remove an account.\n");
+ PRINTF(" This order requires confirmation. After confirmation, the account is deleted.\n");
+ }
+ else if (strcmp(command, "email") == 0)
+ {
+ PRINTF("email <account_name> <email>\n");
+ PRINTF(" Modify the e-mail of an account.\n");
+ }
+ else if (strcmp(command, "getcount") == 0)
+ {
+ PRINTF("getcount\n");
+ PRINTF(" Give the number of players online on all char-servers.\n");
+ }
+ else if (strcmp(command, "gm") == 0)
+ {
+ PRINTF("gm <account_name> [GM_level]\n");
+ PRINTF(" Modify the GM level of an account.\n");
+ PRINTF(" Default value remove GM level (GM level = 0).\n");
+ PRINTF(" <example> gm testname 80\n");
+ }
+ else if (strcmp(command, "id") == 0)
+ {
+ PRINTF("id <account name>\n");
+ PRINTF(" Give the id of an account.\n");
+ }
+ else if (strcmp(command, "info") == 0)
+ {
+ PRINTF("info <account_id>\n");
+ PRINTF(" Display complete information of an account.\n");
+ }
+ else if (strcmp(command, "kami") == 0)
+ {
+ PRINTF("kami <message>\n");
+ PRINTF(" Sends a broadcast message on all map-server (in yellow).\n");
+ }
+ else if (strcmp(command, "kamib") == 0)
+ {
+ PRINTF("kamib <message>\n");
+ PRINTF(" Sends a broadcast message on all map-server (in blue).\n");
+ }
+ else if (strcmp(command, "list") == 0)
+ {
+ PRINTF("list/ls [start_id [end_id]]\n");
+ PRINTF(" Display a list of accounts.\n");
+ PRINTF(" 'start_id', 'end_id': indicate end and start identifiers.\n");
+ PRINTF(" Research by name is not possible with this command.\n");
+ PRINTF(" <example> list 10 9999999\n");
+ }
+ else if (strcmp(command, "itemfrob") == 0)
+ {
+ PRINTF("itemfrob <source-id> <dest-id>\n");
+ PRINTF(" Translates item IDs for all accounts.\n");
+ PRINTF(" Any items matching the source item ID will be mapped to the dest-id.\n");
+ PRINTF(" <example> itemfrob 500 700\n");
+ }
+ else if (strcmp(command, "listban") == 0)
+ {
+ PRINTF("listBan/lsBan [start_id [end_id]]\n");
+ PRINTF(" Like list/ls, but only for accounts with state or banished.\n");
+ }
+ else if (strcmp(command, "listgm") == 0)
+ {
+ PRINTF("listGM/lsGM [start_id [end_id]]\n");
+ PRINTF(" Like list/ls, but only for GM accounts.\n");
+ }
+ else if (strcmp(command, "listok") == 0)
+ {
+ PRINTF("listOK/lsOK [start_id [end_id]]\n");
+ PRINTF(" Like list/ls, but only for accounts without state and not banished.\n");
+ }
+ else if (strcmp(command, "memo") == 0)
+ {
+ PRINTF("memo <account_name> <memo>\n");
+ PRINTF(" Modify the memo of an account.\n");
+ PRINTF(" 'memo': it can have until 253 characters (with spaces or not).\n");
+ }
+ else if (strcmp(command, "name") == 0)
+ {
+ PRINTF("name <account_id>\n");
+ PRINTF(" Give the name of an account.\n");
+ }
+ else if (strcmp(command, "password") == 0)
+ {
+ PRINTF("passwd <account_name> <new_password>\n");
+ PRINTF(" Change the password of an account.\n");
+ PRINTF(" When new password is omitted,\n");
+ PRINTF(" the input is done without displaying of the pressed keys.\n");
+ }
+ else if (strcmp(command, "reloadgm") == 0)
+ {
+ PRINTF("reloadGM\n");
+ PRINTF(" Reload GM configuration file\n");
+ }
+ else if (strcmp(command, "search") == 0)
+ {
+ PRINTF("search <expression>\n");
+ PRINTF(" Seek accounts.\n");
+ PRINTF(" Displays the accounts whose names correspond.\n");
+// PRINTF("search -r/-e/--expr/--regex <expression>\n");
+// PRINTF(" Seek accounts by regular expression.\n");
+// PRINTF(" Displays the accounts whose names correspond.\n");
+ }
+ else if (strcmp(command, "sex") == 0)
+ {
+ PRINTF("sex <account_name> <sex>\n");
+ PRINTF(" Modify the sex of an account.\n");
+ PRINTF(" <example> sex testname Male\n");
+ }
+ else if (strcmp(command, "state") == 0)
+ {
+ PRINTF("state <account_name> <new_state> <error_message_#7>\n");
+ PRINTF(" Change the state of an account.\n");
+ PRINTF(" 'new_state': state is the state of the packet 0x006a + 1.\n");
+ PRINTF(" The possibilities are:\n");
+ PRINTF(" 0 = Account ok\n");
+ PRINTF(" 1 = Unregistered ID\n");
+ PRINTF(" 2 = Incorrect Password\n");
+ PRINTF(" 3 = This ID is expired\n");
+ PRINTF(" 4 = Rejected from Server\n");
+ PRINTF(" 5 = You have been blocked by the GM Team\n");
+ PRINTF(" 6 = Your Game's EXE file is not the latest version\n");
+ PRINTF(" 7 = You are Prohibited to log in until...\n");
+ PRINTF(" 8 = Server is jammed due to over populated\n");
+ PRINTF(" 9 = No MSG\n");
+ PRINTF(" 100 = This ID has been totally erased\n");
+ PRINTF(" all other values are 'No MSG', then use state 9 please.\n");
+ PRINTF(" 'error_message_#7': message of the code error 6\n");
+ PRINTF(" = Your are Prohibited to log in until... (packet 0x006a)\n");
+ }
+ else if (strcmp(command, "timeadd") == 0)
+ {
+ PRINTF("timeadd <account_name> <modifier>\n");
+ PRINTF(" Adds or substracts time from the validity limit of an account.\n");
+ PRINTF(" Modifier is done as follows:\n");
+ PRINTF(" Adjustment value (-1, 1, +1, etc...)\n");
+ PRINTF(" Modified element:\n");
+ PRINTF(" a or y: year\n");
+ PRINTF(" m: month\n");
+ PRINTF(" j or d: day\n");
+ PRINTF(" h: hour\n");
+ PRINTF(" mn: minute\n");
+ PRINTF(" s: second\n");
+ PRINTF(" <example> timeadd testname +1m-2mn1s-6y\n");
+ PRINTF(" this example adds 1 month and 1 second, and substracts 2 minutes\n");
+ PRINTF(" and 6 years at the same time.\n");
+ PRINTF("NOTE: You can not modify a unlimited validity limit.\n");
+ PRINTF(" If you want modify it, you want probably create a limited validity limit.\n");
+ PRINTF(" So, at first, you must set the validity limit to a date/time.\n");
+ }
+ else if (strcmp(command, "timeadd") == 0)
+ {
+ PRINTF("timeset <account_name> yyyy/mm/dd [hh:mm:ss]\n");
+ PRINTF(" Changes the validity limit of an account.\n");
+ PRINTF(" Default time [hh:mm:ss]: 23:59:59.\n");
+ PRINTF("timeset <account_name> 0\n");
+ PRINTF(" Gives an unlimited validity limit (0 = unlimited).\n");
+ }
+ else if (strcmp(command, "unban") == 0)
+ {
+ PRINTF("unban/unbanish <account name>\n");
+ PRINTF(" Remove the banishment of an account.\n");
+ PRINTF(" This command works like banset <account_name> 0.\n");
+ }
+ else if (strcmp(command, "unblock") == 0)
+ {
+ PRINTF("unblock <account name>\n");
+ PRINTF(" Set state 0 (Account ok) to an account.\n");
+ PRINTF(" This command works like state <account_name> 0.\n");
+ }
+ else if (strcmp(command, "version") == 0)
+ {
+ PRINTF("version\n");
+ PRINTF(" Display the version of the login-server.\n");
+ }
+ else if (strcmp(command, "who") == 0)
+ {
+ PRINTF("who <account name>\n");
+ PRINTF(" Displays complete information of an account.\n");
// quit
- }
- else if (strcmp (command, "quit") == 0 ||
- strcmp (command, "exit") == 0 ||
- strcmp (command, "end") == 0)
- {
- printf ("quit/end/exit\n");
- printf (" Fin du programme d'administration.\n");
+ }
+ else if (strcmp(command, "quit") == 0 ||
+ strcmp(command, "exit") == 0 ||
+ strcmp(command, "end") == 0)
+ {
+ PRINTF("quit/end/exit\n");
+ PRINTF(" End of the program of administration.\n");
// unknown command
- }
- else
- {
- if (strlen (command) > 0)
- printf
- ("Commande inconnue [%s] pour l'aide. Affichage de toutes les commandes.\n",
- command);
- printf
- (" aide/help/? -- Affiche cet aide\n");
- printf
- (" aide/help/? [commande] -- Affiche l'aide de la commande\n");
- printf
- (" add <nomcompte> <sexe> <motdepasse> -- Crée un compte (sans email)\n");
- printf
- (" ban/banish aaaa/mm/jj hh:mm:ss <nom compte> -- Fixe la date finale de banismnt\n");
- printf
- (" banadd/ba <nomcompte> <modificateur> -- Ajout/soustrait du temps à la\n");
- printf
- (" exemple: ba moncompte +1m-2mn1s-2y date finale de banissement\n");
- printf
- (" banset/bs <nomcompte> aaaa/mm/jj [hh:mm:ss] -- Change la date fin de banisemnt\n");
- printf
- (" banset/bs <nomcompte> 0 -- Dé-banis un compte.\n");
- printf
- (" block <nom compte> -- Mets le status d'un compte à 5 (blocked by the GM Team)\n");
- printf
- (" check <nomcompte> <motdepasse> -- Vérifie un mot de passe d'un compte\n");
- printf
- (" create <nomcompte> <sexe> <email> <motdepasse> -- Crée un compte (avec email)\n");
- printf
- (" del <nom compte> -- Supprime un compte\n");
- printf
- (" email <nomcompte> <email> -- Modifie l'e-mail d'un compte\n");
- printf
- (" getcount -- Donne le nb de joueurs en ligne\n");
- printf
- (" gm <nomcompte> [Niveau_GM] -- Modifie le niveau de GM d'un compte\n");
- printf
- (" id <nom compte> -- Donne l'id d'un compte\n");
- printf
- (" info <idcompte> -- Affiche les infos sur un compte\n");
- printf
- (" kami <message> -- Envoi un message général (en jaune)\n");
- printf
- (" kamib <message> -- Envoi un message général (en bleu)\n");
- printf
- (" language <langue> -- Change la langue d'affichage.\n");
- printf
- (" list/ls [Premier_id [Dernier_id] ] -- Affiche une liste de comptes\n");
- printf
- (" listBan/lsBan [Premier_id [Dernier_id] ] -- Affiche une liste de comptes\n");
- printf
- (" avec un statut ou bannis\n");
- printf
- (" listGM/lsGM [Premier_id [Dernier_id] ] -- Affiche une liste de comptes GM\n");
- printf
- (" listOK/lsOK [Premier_id [Dernier_id] ] -- Affiche une liste de comptes\n");
- printf
- (" sans status et non bannis\n");
- printf
- (" memo <nomcompte> <memo> -- Modifie le memo d'un compte\n");
- printf
- (" name <idcompte> -- Donne le nom d'un compte\n");
- printf
- (" passwd <nomcompte> <nouveaumotdepasse> -- Change le mot de passe d'un compte\n");
- printf
- (" quit/end/exit -- Fin du programme d'administation\n");
- printf
- (" reloadGM -- Recharger le fichier de config des GM\n");
- printf
- (" search <expression> -- Cherche des comptes\n");
-// printf(" search -e/-r/--expr/--regex <expression> -- Cherche des comptes par REGEX\n");
- printf
- (" sex <nomcompte> <sexe> -- Modifie le sexe d'un compte\n");
- printf
- (" state <nomcompte> <nouveaustatut> <messageerr7> -- Change le statut d'1 compte\n");
- printf
- (" timeadd/ta <nomcompte> <modificateur> -- Ajout/soustrait du temps à la\n");
- printf
- (" exemple: ta moncompte +1m-2mn1s-2y limite de validité\n");
- printf
- (" timeset/ts <nomcompte> aaaa/mm/jj [hh:mm:ss] -- Change la limite de validité\n");
- printf
- (" timeset/ts <nomcompte> 0 -- limite de validité = illimitée\n");
- printf
- (" unban/unbanish <nom compte> -- Ote le banissement d'un compte\n");
- printf
- (" unblock <nom compte> -- Mets le status d'un compte à 0 (Compte ok)\n");
- printf
- (" version -- Donne la version du login-serveur\n");
- printf
- (" who <nom compte> -- Affiche les infos sur un compte\n");
- printf
- (" Note: Pour les noms de compte avec des espaces, tapez \"<nom compte>\" (ou ').\n");
- }
}
else
{
- if (strcmp (command, "aide") == 0)
- {
- printf ("aide/help/?\n");
- printf (" Display the description of the commands\n");
- printf ("aide/help/? [command]\n");
- printf (" Display the description of the specified command\n");
- }
- else if (strcmp (command, "help") == 0)
- {
- printf ("aide/help/?\n");
- printf (" Display the description of the commands\n");
- printf ("aide/help/? [command]\n");
- printf (" Display the description of the specified command\n");
-// general commands
- }
- else if (strcmp (command, "add") == 0)
- {
- printf ("add <account_name> <sex> <password>\n");
- printf
- (" Create an account with the default email (a@a.com).\n");
- printf
- (" Concerning the sex, only the first letter is used (F or M).\n");
- printf
- (" The e-mail is set to a@a.com (default e-mail). It's like to have no e-mail.\n");
- printf (" When the password is omitted,\n");
- printf
- (" the input is done without displaying of the pressed keys.\n");
- printf (" <example> add testname Male testpass\n");
- }
- else if (strcmp (command, "ban") == 0)
- {
- printf ("ban/banish yyyy/mm/dd hh:mm:ss <account name>\n");
- printf
- (" Changes the final date of a banishment of an account.\n");
- printf (" Like banset, but <account name> is at end.\n");
- }
- else if (strcmp (command, "banadd") == 0)
- {
- printf ("banadd <account_name> <modifier>\n");
- printf
- (" Adds or substracts time from the final date of a banishment of an account.\n");
- printf (" Modifier is done as follows:\n");
- printf (" Adjustment value (-1, 1, +1, etc...)\n");
- printf (" Modified element:\n");
- printf (" a or y: year\n");
- printf (" m: month\n");
- printf (" j or d: day\n");
- printf (" h: hour\n");
- printf (" mn: minute\n");
- printf (" s: second\n");
- printf (" <example> banadd testname +1m-2mn1s-6y\n");
- printf
- (" this example adds 1 month and 1 second, and substracts 2 minutes\n");
- printf (" and 6 years at the same time.\n");
- printf
- ("NOTE: If you modify the final date of a non-banished account,\n");
- printf
- (" you fix the final date to (actual time +- adjustments)\n");
- }
- else if (strcmp (command, "banset") == 0)
- {
- printf ("banset <account_name> yyyy/mm/dd [hh:mm:ss]\n");
- printf
- (" Changes the final date of a banishment of an account.\n");
- printf (" Default time [hh:mm:ss]: 23:59:59.\n");
- printf ("banset <account_name> 0\n");
- printf (" Set a non-banished account (0 = unbanished).\n");
- }
- else if (strcmp (command, "block") == 0)
- {
- printf ("block <account name>\n");
- printf
- (" Set state 5 (You have been blocked by the GM Team) to an account.\n");
- printf (" This command works like state <account_name> 5.\n");
- }
- else if (strcmp (command, "check") == 0)
- {
- printf ("check <account_name> <password>\n");
- printf (" Check the validity of a password for an account.\n");
- printf (" NOTE: Server will never sends back a password.\n");
- printf
- (" It's the only method you have to know if a password is correct.\n");
- printf
- (" The other method is to have a ('physical') access to the accounts file.\n");
- }
- else if (strcmp (command, "create") == 0)
- {
- printf ("create <account_name> <sex> <email> <password>\n");
- printf (" Like the 'add' command, but with e-mail moreover.\n");
- printf
- (" <example> create testname Male my@mail.com testpass\n");
- }
- else if (strcmp (command, "delete") == 0)
- {
- printf ("del <account name>\n");
- printf (" Remove an account.\n");
- printf
- (" This order requires confirmation. After confirmation, the account is deleted.\n");
- }
- else if (strcmp (command, "email") == 0)
- {
- printf ("email <account_name> <email>\n");
- printf (" Modify the e-mail of an account.\n");
- }
- else if (strcmp (command, "getcount") == 0)
- {
- printf ("getcount\n");
- printf
- (" Give the number of players online on all char-servers.\n");
- }
- else if (strcmp (command, "gm") == 0)
- {
- printf ("gm <account_name> [GM_level]\n");
- printf (" Modify the GM level of an account.\n");
- printf (" Default value remove GM level (GM level = 0).\n");
- printf (" <example> gm testname 80\n");
- }
- else if (strcmp (command, "id") == 0)
- {
- printf ("id <account name>\n");
- printf (" Give the id of an account.\n");
- }
- else if (strcmp (command, "info") == 0)
- {
- printf ("info <account_id>\n");
- printf (" Display complete information of an account.\n");
- }
- else if (strcmp (command, "kami") == 0)
- {
- printf ("kami <message>\n");
- printf
- (" Sends a broadcast message on all map-server (in yellow).\n");
- }
- else if (strcmp (command, "kamib") == 0)
- {
- printf ("kamib <message>\n");
- printf
- (" Sends a broadcast message on all map-server (in blue).\n");
- }
- else if (strcmp (command, "language") == 0)
- {
- printf ("language <language>\n");
- printf (" Change the language of displaying.\n");
- printf (" Possible languages: Français or English.\n");
- }
- else if (strcmp (command, "list") == 0)
- {
- printf ("list/ls [start_id [end_id]]\n");
- printf (" Display a list of accounts.\n");
- printf
- (" 'start_id', 'end_id': indicate end and start identifiers.\n");
- printf
- (" Research by name is not possible with this command.\n");
- printf (" <example> list 10 9999999\n");
- }
- else if (strcmp (command, "itemfrob") == 0)
- {
- printf ("itemfrob <source-id> <dest-id>\n");
- printf (" Translates item IDs for all accounts.\n");
- printf
- (" Any items matching the source item ID will be mapped to the dest-id.\n");
- printf (" <example> itemfrob 500 700\n");
- }
- else if (strcmp (command, "listban") == 0)
- {
- printf ("listBan/lsBan [start_id [end_id]]\n");
- printf
- (" Like list/ls, but only for accounts with state or banished.\n");
- }
- else if (strcmp (command, "listgm") == 0)
- {
- printf ("listGM/lsGM [start_id [end_id]]\n");
- printf (" Like list/ls, but only for GM accounts.\n");
- }
- else if (strcmp (command, "listok") == 0)
- {
- printf ("listOK/lsOK [start_id [end_id]]\n");
- printf
- (" Like list/ls, but only for accounts without state and not banished.\n");
- }
- else if (strcmp (command, "memo") == 0)
- {
- printf ("memo <account_name> <memo>\n");
- printf (" Modify the memo of an account.\n");
- printf
- (" 'memo': it can have until 253 characters (with spaces or not).\n");
- }
- else if (strcmp (command, "name") == 0)
- {
- printf ("name <account_id>\n");
- printf (" Give the name of an account.\n");
- }
- else if (strcmp (command, "password") == 0)
- {
- printf ("passwd <account_name> <new_password>\n");
- printf (" Change the password of an account.\n");
- printf (" When new password is omitted,\n");
- printf
- (" the input is done without displaying of the pressed keys.\n");
- }
- else if (strcmp (command, "reloadgm") == 0)
- {
- printf ("reloadGM\n");
- printf (" Reload GM configuration file\n");
- }
- else if (strcmp (command, "search") == 0)
- {
- printf ("search <expression>\n");
- printf (" Seek accounts.\n");
- printf (" Displays the accounts whose names correspond.\n");
-// printf("search -r/-e/--expr/--regex <expression>\n");
-// printf(" Seek accounts by regular expression.\n");
-// printf(" Displays the accounts whose names correspond.\n");
- }
- else if (strcmp (command, "sex") == 0)
- {
- printf ("sex <account_name> <sex>\n");
- printf (" Modify the sex of an account.\n");
- printf (" <example> sex testname Male\n");
- }
- else if (strcmp (command, "state") == 0)
- {
- printf ("state <account_name> <new_state> <error_message_#7>\n");
- printf (" Change the state of an account.\n");
- printf
- (" 'new_state': state is the state of the packet 0x006a + 1.\n");
- printf (" The possibilities are:\n");
- printf (" 0 = Account ok\n");
- printf (" 1 = Unregistered ID\n");
- printf (" 2 = Incorrect Password\n");
- printf (" 3 = This ID is expired\n");
- printf (" 4 = Rejected from Server\n");
- printf
- (" 5 = You have been blocked by the GM Team\n");
- printf
- (" 6 = Your Game's EXE file is not the latest version\n");
- printf
- (" 7 = You are Prohibited to log in until...\n");
- printf
- (" 8 = Server is jammed due to over populated\n");
- printf (" 9 = No MSG\n");
- printf (" 100 = This ID has been totally erased\n");
- printf
- (" all other values are 'No MSG', then use state 9 please.\n");
- printf (" 'error_message_#7': message of the code error 6\n");
- printf
- (" = Your are Prohibited to log in until... (packet 0x006a)\n");
- }
- else if (strcmp (command, "timeadd") == 0)
- {
- printf ("timeadd <account_name> <modifier>\n");
- printf
- (" Adds or substracts time from the validity limit of an account.\n");
- printf (" Modifier is done as follows:\n");
- printf (" Adjustment value (-1, 1, +1, etc...)\n");
- printf (" Modified element:\n");
- printf (" a or y: year\n");
- printf (" m: month\n");
- printf (" j or d: day\n");
- printf (" h: hour\n");
- printf (" mn: minute\n");
- printf (" s: second\n");
- printf (" <example> timeadd testname +1m-2mn1s-6y\n");
- printf
- (" this example adds 1 month and 1 second, and substracts 2 minutes\n");
- printf (" and 6 years at the same time.\n");
- printf ("NOTE: You can not modify a unlimited validity limit.\n");
- printf
- (" If you want modify it, you want probably create a limited validity limit.\n");
- printf
- (" So, at first, you must set the validity limit to a date/time.\n");
- }
- else if (strcmp (command, "timeadd") == 0)
- {
- printf ("timeset <account_name> yyyy/mm/dd [hh:mm:ss]\n");
- printf (" Changes the validity limit of an account.\n");
- printf (" Default time [hh:mm:ss]: 23:59:59.\n");
- printf ("timeset <account_name> 0\n");
- printf (" Gives an unlimited validity limit (0 = unlimited).\n");
- }
- else if (strcmp (command, "unban") == 0)
- {
- printf ("unban/unbanish <account name>\n");
- printf (" Remove the banishment of an account.\n");
- printf (" This command works like banset <account_name> 0.\n");
- }
- else if (strcmp (command, "unblock") == 0)
- {
- printf ("unblock <account name>\n");
- printf (" Set state 0 (Account ok) to an account.\n");
- printf (" This command works like state <account_name> 0.\n");
- }
- else if (strcmp (command, "version") == 0)
- {
- printf ("version\n");
- printf (" Display the version of the login-server.\n");
- }
- else if (strcmp (command, "who") == 0)
- {
- printf ("who <account name>\n");
- printf (" Displays complete information of an account.\n");
-// quit
- }
- else if (strcmp (command, "quit") == 0 ||
- strcmp (command, "exit") == 0 ||
- strcmp (command, "end") == 0)
- {
- printf ("quit/end/exit\n");
- printf (" End of the program of administration.\n");
-// unknown command
- }
- else
- {
- if (strlen (command) > 0)
- printf
- ("Unknown command [%s] for help. Displaying of all commands.\n",
- command);
- printf
- (" aide/help/? -- Display this help\n");
- printf
- (" aide/help/? [command] -- Display the help of the command\n");
- printf
- (" add <account_name> <sex> <password> -- Create an account with default email\n");
- printf
- (" ban/banish yyyy/mm/dd hh:mm:ss <account name> -- Change final date of a ban\n");
- printf
- (" banadd/ba <account_name> <modifier> -- Add or substract time from the final\n");
- printf
- (" example: ba apple +1m-2mn1s-2y date of a banishment of an account\n");
- printf
- (" banset/bs <account_name> yyyy/mm/dd [hh:mm:ss] -- Change final date of a ban\n");
- printf
- (" banset/bs <account_name> 0 -- Un-banish an account\n");
- printf
- (" block <account name> -- Set state 5 (blocked by the GM Team) to an account\n");
- printf
- (" check <account_name> <password> -- Check the validity of a password\n");
- printf
- (" create <account_name> <sex> <email> <passwrd> -- Create an account with email\n");
- printf
- (" del <account name> -- Remove an account\n");
- printf
- (" email <account_name> <email> -- Modify an email of an account\n");
- printf
- (" getcount -- Give the number of players online\n");
- printf
- (" gm <account_name> [GM_level] -- Modify the GM level of an account\n");
- printf
- (" id <account name> -- Give the id of an account\n");
- printf
- (" info <account_id> -- Display all information of an account\n");
- printf
- (" itemfrob <source-id> <dest-id> -- Map all items from one item ID to another\n");
- printf
- (" kami <message> -- Sends a broadcast message (in yellow)\n");
- printf
- (" kamib <message> -- Sends a broadcast message (in blue)\n");
- printf
- (" language <language> -- Change the language of displaying.\n");
- printf
- (" list/ls [First_id [Last_id]] -- Display a list of accounts\n");
- printf
- (" listBan/lsBan [First_id [Last_id] ] -- Display a list of accounts\n");
- printf
- (" with state or banished\n");
- printf
- (" listGM/lsGM [First_id [Last_id]] -- Display a list of GM accounts\n");
- printf
- (" listOK/lsOK [First_id [Last_id] ] -- Display a list of accounts\n");
- printf
- (" without state and not banished\n");
- printf
- (" memo <account_name> <memo> -- Modify the memo of an account\n");
- printf
- (" name <account_id> -- Give the name of an account\n");
- printf
- (" passwd <account_name> <new_password> -- Change the password of an account\n");
- printf
- (" quit/end/exit -- End of the program of administation\n");
- printf
- (" reloadGM -- Reload GM configuration file\n");
- printf
- (" search <expression> -- Seek accounts\n");
-// printf(" search -e/-r/--expr/--regex <expressn> -- Seek accounts by regular-expression\n");
- printf
- (" sex <nomcompte> <sexe> -- Modify the sex of an account\n");
- printf
- (" state <account_name> <new_state> <error_message_#7> -- Change the state\n");
- printf
- (" timeadd/ta <account_name> <modifier> -- Add or substract time from the\n");
- printf
- (" example: ta apple +1m-2mn1s-2y validity limit of an account\n");
- printf
- (" timeset/ts <account_name> yyyy/mm/dd [hh:mm:ss] -- Change the validify limit\n");
- printf
- (" timeset/ts <account_name> 0 -- Give a unlimited validity limit\n");
- printf
- (" unban/unbanish <account name> -- Remove the banishment of an account\n");
- printf
- (" unblock <account name> -- Set state 0 (Account ok) to an account\n");
- printf
- (" version -- Gives the version of the login-server\n");
- printf
- (" who <account name> -- Display all information of an account\n");
- printf
- (" who <account name> -- Display all information of an account\n");
- printf
- (" Note: To use spaces in an account name, type \"<account name>\" (or ').\n");
- }
+ if (strlen(command) > 0)
+ PRINTF("Unknown command [%s] for help. Displaying of all commands.\n",
+ command);
+ PRINTF(" help/? -- Display this help\n");
+ PRINTF(" help/? [command] -- Display the help of the command\n");
+ PRINTF(" add <account_name> <sex> <password> -- Create an account with default email\n");
+ PRINTF(" ban/banish yyyy/mm/dd hh:mm:ss <account name> -- Change final date of a ban\n");
+ PRINTF(" banadd/ba <account_name> <modifier> -- Add or substract time from the final\n");
+ PRINTF(" example: ba apple +1m-2mn1s-2y date of a banishment of an account\n");
+ PRINTF(" banset/bs <account_name> yyyy/mm/dd [hh:mm:ss] -- Change final date of a ban\n");
+ PRINTF(" banset/bs <account_name> 0 -- Un-banish an account\n");
+ PRINTF(" block <account name> -- Set state 5 (blocked by the GM Team) to an account\n");
+ PRINTF(" check <account_name> <password> -- Check the validity of a password\n");
+ PRINTF(" create <account_name> <sex> <email> <passwrd> -- Create an account with email\n");
+ PRINTF(" del <account name> -- Remove an account\n");
+ PRINTF(" email <account_name> <email> -- Modify an email of an account\n");
+ PRINTF(" getcount -- Give the number of players online\n");
+ PRINTF(" gm <account_name> [GM_level] -- Modify the GM level of an account\n");
+ PRINTF(" id <account name> -- Give the id of an account\n");
+ PRINTF(" info <account_id> -- Display all information of an account\n");
+ PRINTF(" itemfrob <source-id> <dest-id> -- Map all items from one item ID to another\n");
+ PRINTF(" kami <message> -- Sends a broadcast message (in yellow)\n");
+ PRINTF(" kamib <message> -- Sends a broadcast message (in blue)\n");
+ PRINTF(" list/ls [First_id [Last_id]] -- Display a list of accounts\n");
+ PRINTF(" listBan/lsBan [First_id [Last_id] ] -- Display a list of accounts\n");
+ PRINTF(" with state or banished\n");
+ PRINTF(" listGM/lsGM [First_id [Last_id]] -- Display a list of GM accounts\n");
+ PRINTF(" listOK/lsOK [First_id [Last_id] ] -- Display a list of accounts\n");
+ PRINTF(" without state and not banished\n");
+ PRINTF(" memo <account_name> <memo> -- Modify the memo of an account\n");
+ PRINTF(" name <account_id> -- Give the name of an account\n");
+ PRINTF(" passwd <account_name> <new_password> -- Change the password of an account\n");
+ PRINTF(" quit/end/exit -- End of the program of administation\n");
+ PRINTF(" reloadGM -- Reload GM configuration file\n");
+ PRINTF(" search <expression> -- Seek accounts\n");
+// PRINTF(" search -e/-r/--expr/--regex <expressn> -- Seek accounts by regular-expression\n");
+ PRINTF(" sex <nomcompte> <sexe> -- Modify the sex of an account\n");
+ PRINTF(" state <account_name> <new_state> <error_message_#7> -- Change the state\n");
+ PRINTF(" timeadd/ta <account_name> <modifier> -- Add or substract time from the\n");
+ PRINTF(" example: ta apple +1m-2mn1s-2y validity limit of an account\n");
+ PRINTF(" timeset/ts <account_name> yyyy/mm/dd [hh:mm:ss] -- Change the validify limit\n");
+ PRINTF(" timeset/ts <account_name> 0 -- Give a unlimited validity limit\n");
+ PRINTF(" unban/unbanish <account name> -- Remove the banishment of an account\n");
+ PRINTF(" unblock <account name> -- Set state 0 (Account ok) to an account\n");
+ PRINTF(" version -- Gives the version of the login-server\n");
+ PRINTF(" who <account name> -- Display all information of an account\n");
+ PRINTF(" who <account name> -- Display all information of an account\n");
+ PRINTF(" Note: To use spaces in an account name, type \"<account name>\" (or ').\n");
}
}
@@ -1539,191 +855,97 @@ void display_help (const char *param, int language)
// Sub-function: add an account
//-----------------------------
static
-int addaccount (const char *param, int emailflag)
+int addaccount(const char *param, int emailflag)
{
char name[1023], sex[1023], email[1023], password[1023];
// int i;
- memset (name, '\0', sizeof (name));
- memset (sex, '\0', sizeof (sex));
- memset (email, '\0', sizeof (email));
- memset (password, '\0', sizeof (password));
+ memset(name, '\0', sizeof(name));
+ memset(sex, '\0', sizeof(sex));
+ memset(email, '\0', sizeof(email));
+ memset(password, '\0', sizeof(password));
if (emailflag == 0)
{ // add command
- if (sscanf (param, "\"%[^\"]\" %s %[^\r\n]", name, sex, password) < 2 && // password can be void
- sscanf (param, "'%[^']' %s %[^\r\n]", name, sex, password) < 2 && // password can be void
- sscanf (param, "%s %s %[^\r\n]", name, sex, password) < 2)
+ if (sscanf(param, "\"%[^\"]\" %s %[^\r\n]", name, sex, password) < 2 && // password can be void
+ sscanf(param, "'%[^']' %s %[^\r\n]", name, sex, password) < 2 && // password can be void
+ sscanf(param, "%s %s %[^\r\n]", name, sex, password) < 2)
{ // password can be void
- if (defaultlanguage == 'F')
- {
- printf
- ("Entrez un nom de compte, un sexe et un mot de passe svp.\n");
- printf ("<exemple> add nomtest Male motdepassetest\n");
- ladmin_log
- ("Nombre incorrect de paramètres pour créer un compte (commande 'add').\n");
- }
- else
- {
- printf
- ("Please input an account name, a sex and a password.\n");
- printf ("<example> add testname Male testpass\n");
- ladmin_log
- ("Incomplete parameters to create an account ('add' command).\n");
- }
+ PRINTF("Please input an account name, a sex and a password.\n");
+ PRINTF("<example> add testname Male testpass\n");
+ LADMIN_LOG("Incomplete parameters to create an account ('add' command).\n");
return 136;
}
- strcpy (email, "a@a.com"); // default email
+ strcpy(email, "a@a.com"); // default email
}
else
{ // 1: create command
- if (sscanf (param, "\"%[^\"]\" %s %s %[^\r\n]", name, sex, email, password) < 3 && // password can be void
- sscanf (param, "'%[^']' %s %s %[^\r\n]", name, sex, email, password) < 3 && // password can be void
- sscanf (param, "%s %s %s %[^\r\n]", name, sex, email,
+ if (sscanf(param, "\"%[^\"]\" %s %s %[^\r\n]", name, sex, email, password) < 3 && // password can be void
+ sscanf(param, "'%[^']' %s %s %[^\r\n]", name, sex, email, password) < 3 && // password can be void
+ sscanf(param, "%s %s %s %[^\r\n]", name, sex, email,
password) < 3)
{ // password can be void
- if (defaultlanguage == 'F')
- {
- printf
- ("Entrez un nom de compte, un sexe et un mot de passe svp.\n");
- printf
- ("<exemple> create nomtest Male mo@mail.com motdepassetest\n");
- ladmin_log
- ("Nombre incorrect de paramètres pour créer un compte (commande 'create').\n");
- }
- else
- {
- printf
- ("Please input an account name, a sex and a password.\n");
- printf
- ("<example> create testname Male my@mail.com testpass\n");
- ladmin_log
- ("Incomplete parameters to create an account ('create' command).\n");
- }
+ PRINTF("Please input an account name, a sex and a password.\n");
+ PRINTF("<example> create testname Male my@mail.com testpass\n");
+ LADMIN_LOG("Incomplete parameters to create an account ('create' command).\n");
return 136;
}
}
- if (verify_accountname (name) == 0)
+ if (verify_accountname(name) == 0)
{
return 102;
}
-/* for(i = 0; name[i]; i++) {
- if (strchr("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_", name[i]) == NULL) {
- if (defaultlanguage == 'F') {
- 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).\n", 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).\n", name[i], i+1, makeordinal(i+1));
- }
- return 101;
- }
- }*/
-
- sex[0] = toupper (sex[0]);
- if (strchr ("MF", sex[0]) == NULL)
+ sex[0] = toupper(sex[0]);
+ if (strchr("MF", sex[0]) == NULL)
{
- if (defaultlanguage == 'F')
- {
- printf ("Sexe incorrect [%s]. Entrez M ou F svp.\n", sex);
- ladmin_log ("Sexe incorrect [%s]. Entrez M ou F svp.\n",
- sex);
- }
- else
- {
- printf ("Illegal gender [%s]. Please input M or F.\n", sex);
- ladmin_log ("Illegal gender [%s]. Please input M or F.\n",
- sex);
- }
+ PRINTF("Illegal gender [%s]. Please input M or F.\n", sex);
+ LADMIN_LOG("Illegal gender [%s]. Please input M or F.\n",
+ sex);
return 103;
}
- if (strlen (email) < 3)
+ if (strlen(email) < 3)
{
- if (defaultlanguage == 'F')
- {
- printf ("Email trop courte [%s]. Entrez une e-mail valide svp.\n",
- email);
- ladmin_log
- ("Email trop courte [%s]. Entrez une e-mail valide svp.\n",
- email);
- }
- else
- {
- printf ("Email is too short [%s]. Please input a valid e-mail.\n",
- email);
- ladmin_log
- ("Email is too short [%s]. Please input a valid e-mail.\n",
- email);
- }
+ PRINTF("Email is too short [%s]. Please input a valid e-mail.\n",
+ email);
+ LADMIN_LOG("Email is too short [%s]. Please input a valid e-mail.\n",
+ email);
return 109;
}
- if (strlen (email) > 39)
+ if (strlen(email) > 39)
{
- if (defaultlanguage == 'F')
- {
- printf
- ("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 caractères maximum svp.\n",
- email);
- }
- else
- {
- printf
- ("Email is too long [%s]. Please input an e-mail with 39 bytes at the most.\n",
- email);
- ladmin_log
- ("Email is too long [%s]. Please input an e-mail with 39 bytes at the most.\n",
- email);
- }
+ PRINTF("Email is too long [%s]. Please input an e-mail with 39 bytes at the most.\n",
+ email);
+ LADMIN_LOG("Email is too long [%s]. Please input an e-mail with 39 bytes at the most.\n",
+ email);
return 109;
}
- if (e_mail_check (email) == 0)
+ if (e_mail_check(email) == 0)
{
- if (defaultlanguage == 'F')
- {
- printf ("Email incorrecte [%s]. Entrez une e-mail valide svp.\n",
- email);
- ladmin_log ("Email incorrecte [%s]. Entrez une e-mail valide svp.\n",
- email);
- }
- else
- {
- printf ("Invalid email [%s]. Please input a valid e-mail.\n",
- email);
- ladmin_log ("Invalid email [%s]. Please input a valid e-mail.\n",
- email);
- }
+ PRINTF("Invalid email [%s]. Please input a valid e-mail.\n",
+ email);
+ LADMIN_LOG("Invalid email [%s]. Please input a valid e-mail.\n",
+ email);
return 109;
}
- if (strlen (password) == 0)
+ if (strlen(password) == 0)
{
- if (typepasswd (password) == 0)
+ if (typepasswd(password) == 0)
return 108;
}
- if (verify_password (password) == 0)
+ if (verify_password(password) == 0)
return 104;
- if (defaultlanguage == 'F')
- {
- ladmin_log
- ("Envoi d'un requête au serveur de logins pour créer un compte.\n");
- }
- else
- {
- ladmin_log ("Request to login-server to create an account.\n");
- }
+ LADMIN_LOG("Request to login-server to create an account.\n");
- WFIFOW (login_fd, 0) = 0x7930;
- memcpy (WFIFOP (login_fd, 2), name, 24);
- memcpy (WFIFOP (login_fd, 26), password, 24);
- WFIFOB (login_fd, 50) = sex[0];
- memcpy (WFIFOP (login_fd, 51), email, 40);
- WFIFOSET (login_fd, 91);
+ WFIFOW(login_fd, 0) = 0x7930;
+ memcpy(WFIFOP(login_fd, 2), name, 24);
+ memcpy(WFIFOP(login_fd, 26), password, 24);
+ WFIFOB(login_fd, 50) = sex[0];
+ memcpy(WFIFOP(login_fd, 51), email, 40);
+ WFIFOSET(login_fd, 91);
bytes_to_read = 1;
return 0;
@@ -1733,55 +955,40 @@ int addaccount (const char *param, int emailflag)
// Sub-function: Add/substract time to the final date of a banishment of an account
//---------------------------------------------------------------------------------
static
-int banaddaccount (const char *param)
+int banaddaccount(const char *param)
{
char name[1023], modif[1023];
- int year, month, day, hour, minute, second;
+ int year, month, day, hour, minute, second;
const char *p_modif;
- int value, i;
+ int value, i;
- memset (name, '\0', sizeof (name));
- memset (modif, '\0', sizeof (modif));
+ memset(name, '\0', sizeof(name));
+ memset(modif, '\0', sizeof(modif));
year = month = day = hour = minute = second = 0;
- if (sscanf (param, "\"%[^\"]\" %[^\r\n]", name, modif) < 2 &&
- sscanf (param, "'%[^']' %[^\r\n]", name, modif) < 2 &&
- sscanf (param, "%s %[^\r\n]", name, modif) < 2)
+ if (sscanf(param, "\"%[^\"]\" %[^\r\n]", name, modif) < 2 &&
+ sscanf(param, "'%[^']' %[^\r\n]", name, modif) < 2 &&
+ sscanf(param, "%s %[^\r\n]", name, modif) < 2)
{
- if (defaultlanguage == 'F')
- {
- printf ("Entrez un nom de compte et un modificateur svp.\n");
- printf (" <exemple> 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 même temps.\n");
- ladmin_log
- ("Nombre incorrect de paramètres pour modifier la fin de ban d'un compte (commande 'banadd').\n");
- }
- else
- {
- printf ("Please input an account name and a modifier.\n");
- printf (" <example>: banadd testname +1m-2mn1s-6y\n");
- printf
- (" this example adds 1 month and 1 second, and substracts 2 minutes\n");
- printf (" and 6 years at the same time.\n");
- ladmin_log
- ("Incomplete parameters to modify the ban date/time of an account ('banadd' command).\n");
- }
+ PRINTF("Please input an account name and a modifier.\n");
+ PRINTF(" <example>: banadd testname +1m-2mn1s-6y\n");
+ PRINTF(" this example adds 1 month and 1 second, and substracts 2 minutes\n");
+ PRINTF(" and 6 years at the same time.\n");
+ LADMIN_LOG("Incomplete parameters to modify the ban date/time of an account ('banadd' command).\n");
return 136;
}
- if (verify_accountname (name) == 0)
+ if (verify_accountname(name) == 0)
{
return 102;
}
// lowercase for modif
for (i = 0; modif[i]; i++)
- modif[i] = tolower (modif[i]);
+ modif[i] = tolower(modif[i]);
p_modif = modif;
- while (strlen (p_modif) > 0)
+ while (strlen(p_modif) > 0)
{
- value = atoi (p_modif);
+ value = atoi(p_modif);
if (value == 0)
{
p_modif++;
@@ -1790,7 +997,7 @@ int banaddaccount (const char *param)
{
if (p_modif[0] == '-' || p_modif[0] == '+')
p_modif++;
- while (strlen (p_modif) > 0 && p_modif[0] >= '0'
+ while (strlen(p_modif) > 0 && p_modif[0] >= '0'
&& p_modif[0] <= '9')
{
p_modif++;
@@ -1832,193 +1039,79 @@ int banaddaccount (const char *param)
}
}
- if (defaultlanguage == 'F')
- {
- printf (" année: %d\n", year);
- printf (" mois: %d\n", month);
- printf (" jour: %d\n", day);
- printf (" heure: %d\n", hour);
- printf (" minute: %d\n", minute);
- printf (" seconde: %d\n", second);
- }
- else
- {
- printf (" year: %d\n", year);
- printf (" month: %d\n", month);
- printf (" day: %d\n", day);
- printf (" hour: %d\n", hour);
- printf (" minute: %d\n", minute);
- printf (" second: %d\n", second);
- }
+ PRINTF(" year: %d\n", year);
+ PRINTF(" month: %d\n", month);
+ PRINTF(" day: %d\n", day);
+ PRINTF(" hour: %d\n", hour);
+ PRINTF(" minute: %d\n", minute);
+ PRINTF(" second: %d\n", second);
if (year == 0 && month == 0 && day == 0 && hour == 0 && minute == 0
&& second == 0)
{
- if (defaultlanguage == 'F')
- {
- 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: année\n");
- printf (" m: mois\n");
- printf (" j ou d: jour\n");
- printf (" h: heure\n");
- printf (" mn: minute\n");
- printf (" s: seconde\n");
- printf (" <exemple> 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 même temps.\n");
- ladmin_log
- ("Aucun ajustement n'est pas un ajustement (commande 'banadd').\n");
- }
- else
- {
- printf ("Please give an adjustment with this command:\n");
- printf (" Adjustment value (-1, 1, +1, etc...)\n");
- printf (" Modified element:\n");
- printf (" a or y: year\n");
- printf (" m: month\n");
- printf (" j or d: day\n");
- printf (" h: hour\n");
- printf (" mn: minute\n");
- printf (" s: second\n");
- printf (" <example> banadd testname +1m-2mn1s-6y\n");
- printf
- (" this example adds 1 month and 1 second, and substracts 2 minutes\n");
- printf (" and 6 years at the same time.\n");
- ladmin_log
- ("No adjustment isn't an adjustment ('banadd' command).\n");
- }
+ PRINTF("Please give an adjustment with this command:\n");
+ PRINTF(" Adjustment value (-1, 1, +1, etc...)\n");
+ PRINTF(" Modified element:\n");
+ PRINTF(" a or y: year\n");
+ PRINTF(" m: month\n");
+ PRINTF(" j or d: day\n");
+ PRINTF(" h: hour\n");
+ PRINTF(" mn: minute\n");
+ PRINTF(" s: second\n");
+ PRINTF(" <example> banadd testname +1m-2mn1s-6y\n");
+ PRINTF(" this example adds 1 month and 1 second, and substracts 2 minutes\n");
+ PRINTF(" and 6 years at the same time.\n");
+ LADMIN_LOG("No adjustment isn't an adjustment ('banadd' command).\n");
return 137;
}
if (year > 127 || year < -127)
{
- if (defaultlanguage == 'F')
- {
- printf
- ("Entrez un ajustement d'années correct (de -127 à 127), svp.\n");
- ladmin_log
- ("Ajustement de l'année hors norme (commande 'banadd').\n");
- }
- else
- {
- printf
- ("Please give a correct adjustment for the years (from -127 to 127).\n");
- ladmin_log
- ("Abnormal adjustement for the year ('banadd' command).\n");
- }
+ PRINTF("Please give a correct adjustment for the years (from -127 to 127).\n");
+ LADMIN_LOG("Abnormal adjustement for the year ('banadd' command).\n");
return 137;
}
if (month > 255 || month < -255)
{
- if (defaultlanguage == 'F')
- {
- printf
- ("Entrez un ajustement de mois correct (de -255 à 255), svp.\n");
- ladmin_log ("Ajustement du mois hors norme (commande 'banadd').\n");
- }
- else
- {
- printf
- ("Please give a correct adjustment for the months (from -255 to 255).\n");
- ladmin_log
- ("Abnormal adjustement for the month ('banadd' command).\n");
- }
+ PRINTF("Please give a correct adjustment for the months (from -255 to 255).\n");
+ LADMIN_LOG("Abnormal adjustement for the month ('banadd' command).\n");
return 137;
}
if (day > 32767 || day < -32767)
{
- if (defaultlanguage == 'F')
- {
- printf
- ("Entrez un ajustement de jours correct (de -32767 à 32767), svp.\n");
- ladmin_log ("Ajustement des jours hors norme (commande 'banadd').\n");
- }
- else
- {
- printf
- ("Please give a correct adjustment for the days (from -32767 to 32767).\n");
- ladmin_log
- ("Abnormal adjustement for the days ('banadd' command).\n");
- }
+ PRINTF("Please give a correct adjustment for the days (from -32767 to 32767).\n");
+ LADMIN_LOG("Abnormal adjustement for the days ('banadd' command).\n");
return 137;
}
if (hour > 32767 || hour < -32767)
{
- if (defaultlanguage == 'F')
- {
- printf
- ("Entrez un ajustement d'heures correct (de -32767 à 32767), svp.\n");
- ladmin_log
- ("Ajustement des heures hors norme (commande 'banadd').\n");
- }
- else
- {
- printf
- ("Please give a correct adjustment for the hours (from -32767 to 32767).\n");
- ladmin_log
- ("Abnormal adjustement for the hours ('banadd' command).\n");
- }
+ PRINTF("Please give a correct adjustment for the hours (from -32767 to 32767).\n");
+ LADMIN_LOG("Abnormal adjustement for the hours ('banadd' command).\n");
return 137;
}
if (minute > 32767 || minute < -32767)
{
- if (defaultlanguage == 'F')
- {
- printf
- ("Entrez un ajustement de minutes correct (de -32767 à 32767), svp.\n");
- ladmin_log
- ("Ajustement des minutes hors norme (commande 'banadd').\n");
- }
- else
- {
- printf
- ("Please give a correct adjustment for the minutes (from -32767 to 32767).\n");
- ladmin_log
- ("Abnormal adjustement for the minutes ('banadd' command).\n");
- }
+ PRINTF("Please give a correct adjustment for the minutes (from -32767 to 32767).\n");
+ LADMIN_LOG("Abnormal adjustement for the minutes ('banadd' command).\n");
return 137;
}
if (second > 32767 || second < -32767)
{
- if (defaultlanguage == 'F')
- {
- printf
- ("Entrez un ajustement de secondes correct (de -32767 à 32767), svp.\n");
- ladmin_log
- ("Ajustement des secondes hors norme (commande 'banadd').\n");
- }
- else
- {
- printf
- ("Please give a correct adjustment for the seconds (from -32767 to 32767).\n");
- ladmin_log
- ("Abnormal adjustement for the seconds ('banadd' command).\n");
- }
+ PRINTF("Please give a correct adjustment for the seconds (from -32767 to 32767).\n");
+ LADMIN_LOG("Abnormal adjustement for the seconds ('banadd' command).\n");
return 137;
}
- if (defaultlanguage == 'F')
- {
- ladmin_log
- ("Envoi d'un requête au serveur de logins pour modifier la date d'un bannissement.\n");
- }
- else
- {
- ladmin_log ("Request to login-server to modify a ban date/time.\n");
- }
-
- WFIFOW (login_fd, 0) = 0x794c;
- memcpy (WFIFOP (login_fd, 2), name, 24);
- WFIFOW (login_fd, 26) = (short) year;
- WFIFOW (login_fd, 28) = (short) month;
- WFIFOW (login_fd, 30) = (short) day;
- WFIFOW (login_fd, 32) = (short) hour;
- WFIFOW (login_fd, 34) = (short) minute;
- WFIFOW (login_fd, 36) = (short) second;
- WFIFOSET (login_fd, 38);
+ LADMIN_LOG("Request to login-server to modify a ban date/time.\n");
+
+ WFIFOW(login_fd, 0) = 0x794c;
+ memcpy(WFIFOP(login_fd, 2), name, 24);
+ WFIFOW(login_fd, 26) = (short) year;
+ WFIFOW(login_fd, 28) = (short) month;
+ WFIFOW(login_fd, 30) = (short) day;
+ WFIFOW(login_fd, 32) = (short) hour;
+ WFIFOW(login_fd, 34) = (short) minute;
+ WFIFOW(login_fd, 36) = (short) second;
+ WFIFOSET(login_fd, 38);
bytes_to_read = 1;
return 0;
@@ -2029,51 +1122,35 @@ int banaddaccount (const char *param)
// Set the final date of a banishment of an account
//-----------------------------------------------------------------------
static
-int bansetaccountsub (const char *name, const char *date, const char *time)
+int bansetaccountsub(const char *name, const char *date, const char *time_)
{
- int year, month, day, hour, minute, second;
- time_t ban_until_time; // # of seconds 1/1/1970 (timestamp): ban time limit of the account (0 = no ban)
- struct tm *tmtime;
-
+ int year, month, day, hour, minute, second;
year = month = day = hour = minute = second = 0;
- ban_until_time = 0;
- tmtime = localtime (&ban_until_time); // initialize
- if (verify_accountname (name) == 0)
+ // # of seconds 1/1/1970 (timestamp): ban time limit of the account (0 = no ban)
+ TimeT ban_until_time = TimeT();
+ struct tm tmtime = ban_until_time; // initialize
+
+ if (verify_accountname(name) == 0)
{
return 102;
}
- if (atoi (date) != 0 &&
- ((sscanf (date, "%d/%d/%d", &year, &month, &day) < 3 &&
- sscanf (date, "%d-%d-%d", &year, &month, &day) < 3 &&
- sscanf (date, "%d.%d.%d", &year, &month, &day) < 3) ||
- sscanf (time, "%d:%d:%d", &hour, &minute, &second) < 3))
+ if (atoi(date) != 0 &&
+ ((sscanf(date, "%d/%d/%d", &year, &month, &day) < 3 &&
+ sscanf(date, "%d-%d-%d", &year, &month, &day) < 3 &&
+ sscanf(date, "%d.%d.%d", &year, &month, &day) < 3) ||
+ sscanf(time_, "%d:%d:%d", &hour, &minute, &second) < 3))
{
- if (defaultlanguage == 'F')
- {
- 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");
- ladmin_log
- ("Format incorrect pour la date/heure (commande'banset' ou 'ban').\n");
- }
- else
- {
- printf
- ("Please input a date and a time (format: yyyy/mm/dd hh:mm:ss).\n");
- printf
- ("You can imput 0 instead of if you use 'banset' command.\n");
- ladmin_log
- ("Invalid format for the date/time ('banset' or 'ban' command).\n");
- }
+ PRINTF("Please input a date and a time (format: yyyy/mm/dd hh:mm:ss).\n");
+ PRINTF("You can imput 0 instead of if you use 'banset' command.\n");
+ LADMIN_LOG("Invalid format for the date/time ('banset' or 'ban' command).\n");
return 102;
}
- if (atoi (date) == 0)
+ if (atoi(date) == 0)
{
- ban_until_time = 0;
+ ban_until_time = TimeT();
}
else
{
@@ -2087,159 +1164,67 @@ int bansetaccountsub (const char *name, const char *date, const char *time)
}
if (month < 1 || month > 12)
{
- if (defaultlanguage == 'F')
- {
- printf ("Entrez un mois correct svp (entre 1 et 12).\n");
- ladmin_log
- ("Mois incorrect pour la date (command 'banset' ou 'ban').\n");
- }
- else
- {
- printf
- ("Please give a correct value for the month (from 1 to 12).\n");
- ladmin_log
- ("Invalid month for the date ('banset' or 'ban' command).\n");
- }
+ PRINTF("Please give a correct value for the month (from 1 to 12).\n");
+ LADMIN_LOG("Invalid month for the date ('banset' or 'ban' command).\n");
return 102;
}
month = month - 1;
if (day < 1 || day > 31)
{
- if (defaultlanguage == 'F')
- {
- printf ("Entrez un jour correct svp (entre 1 et 31).\n");
- ladmin_log
- ("Jour incorrect pour la date (command 'banset' ou 'ban').\n");
- }
- else
- {
- printf
- ("Please give a correct value for the day (from 1 to 31).\n");
- ladmin_log
- ("Invalid day for the date ('banset' or 'ban' command).\n");
- }
+ PRINTF("Please give a correct value for the day (from 1 to 31).\n");
+ LADMIN_LOG("Invalid day for the date ('banset' or 'ban' command).\n");
return 102;
}
if (((month == 3 || month == 5 || month == 8 || month == 10)
- && day > 30) || (month == 1 && day > 29))
+ && day > 30) ||(month == 1 && day > 29))
{
- if (defaultlanguage == 'F')
- {
- printf
- ("Entrez un jour correct en fonction du mois (%d) svp.\n",
- month);
- ladmin_log
- ("Jour incorrect pour ce mois correspondant (command 'banset' ou 'ban').\n");
- }
- else
- {
- printf
- ("Please give a correct value for a day of this month (%d).\n",
- month);
- ladmin_log
- ("Invalid day for this month ('banset' or 'ban' command).\n");
- }
+ PRINTF("Please give a correct value for a day of this month (%d).\n",
+ month);
+ LADMIN_LOG("Invalid day for this month ('banset' or 'ban' command).\n");
return 102;
}
if (hour < 0 || hour > 23)
{
- if (defaultlanguage == 'F')
- {
- printf ("Entrez une heure correcte svp (entre 0 et 23).\n");
- ladmin_log
- ("Heure incorrecte pour l'heure (command 'banset' ou 'ban').\n");
- }
- else
- {
- printf
- ("Please give a correct value for the hour (from 0 to 23).\n");
- ladmin_log
- ("Invalid hour for the time ('banset' or 'ban' command).\n");
- }
+ PRINTF("Please give a correct value for the hour (from 0 to 23).\n");
+ LADMIN_LOG("Invalid hour for the time ('banset' or 'ban' command).\n");
return 102;
}
if (minute < 0 || minute > 59)
{
- if (defaultlanguage == 'F')
- {
- printf
- ("Entrez des minutes correctes svp (entre 0 et 59).\n");
- ladmin_log
- ("Minute incorrecte pour l'heure (command 'banset' ou 'ban').\n");
- }
- else
- {
- printf
- ("Please give a correct value for the minutes (from 0 to 59).\n");
- ladmin_log
- ("Invalid minute for the time ('banset' or 'ban' command).\n");
- }
+ PRINTF("Please give a correct value for the minutes (from 0 to 59).\n");
+ LADMIN_LOG("Invalid minute for the time ('banset' or 'ban' command).\n");
return 102;
}
if (second < 0 || second > 59)
{
- if (defaultlanguage == 'F')
- {
- printf
- ("Entrez des secondes correctes svp (entre 0 et 59).\n");
- ladmin_log
- ("Seconde incorrecte pour l'heure (command 'banset' ou 'ban').\n");
- }
- else
- {
- printf
- ("Please give a correct value for the seconds (from 0 to 59).\n");
- ladmin_log
- ("Invalid second for the time ('banset' or 'ban' command).\n");
- }
+ PRINTF("Please give a correct value for the seconds (from 0 to 59).\n");
+ LADMIN_LOG("Invalid second for the time ('banset' or 'ban' command).\n");
return 102;
}
- tmtime->tm_year = year;
- tmtime->tm_mon = month;
- tmtime->tm_mday = day;
- tmtime->tm_hour = hour;
- tmtime->tm_min = minute;
- tmtime->tm_sec = second;
- tmtime->tm_isdst = -1; // -1: no winter/summer time modification
- ban_until_time = timegm (tmtime);
- if (ban_until_time == -1)
- {
- if (defaultlanguage == 'F')
- {
- printf ("Date incorrecte.\n");
- 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");
- ladmin_log ("Date incorrecte. (command 'banset' ou 'ban').\n");
- }
- else
- {
- printf ("Invalid date.\n");
- printf
- ("Please input a date and a time (format: yyyy/mm/dd hh:mm:ss).\n");
- printf
- ("You can imput 0 instead of if you use 'banset' command.\n");
- ladmin_log ("Invalid date. ('banset' or 'ban' command).\n");
- }
+ tmtime.tm_year = year;
+ tmtime.tm_mon = month;
+ tmtime.tm_mday = day;
+ tmtime.tm_hour = hour;
+ tmtime.tm_min = minute;
+ tmtime.tm_sec = second;
+ tmtime.tm_isdst = -1; // -1: no winter/summer time modification
+ ban_until_time = tmtime;
+ if (ban_until_time.error())
+ {
+ PRINTF("Invalid date.\n");
+ PRINTF("Please input a date and a time (format: yyyy/mm/dd hh:mm:ss).\n");
+ PRINTF("You can imput 0 instead of if you use 'banset' command.\n");
+ LADMIN_LOG("Invalid date. ('banset' or 'ban' command).\n");
return 102;
}
}
- if (defaultlanguage == 'F')
- {
- ladmin_log
- ("Envoi d'un requête au serveur de logins pour fixer un ban.\n");
- }
- else
- {
- ladmin_log ("Request to login-server to set a ban.\n");
- }
+ LADMIN_LOG("Request to login-server to set a ban.\n");
- WFIFOW (login_fd, 0) = 0x794a;
- memcpy (WFIFOP (login_fd, 2), name, 24);
- WFIFOL (login_fd, 26) = (int) ban_until_time;
- WFIFOSET (login_fd, 30);
+ WFIFOW(login_fd, 0) = 0x794a;
+ memcpy(WFIFOP(login_fd, 2), name, 24);
+ WFIFOL(login_fd, 26) = static_cast<time_t>(ban_until_time);
+ WFIFOSET(login_fd, 30);
bytes_to_read = 1;
return 0;
@@ -2249,149 +1234,89 @@ int bansetaccountsub (const char *name, const char *date, const char *time)
// Sub-function: Set the final date of a banishment of an account (ban)
//---------------------------------------------------------------------
static
-int banaccount (const char *param)
+int banaccount(const char *param)
{
- char name[1023], date[1023], time[1023];
-
- memset (name, '\0', sizeof (name));
- memset (date, '\0', sizeof (date));
- memset (time, '\0', sizeof (time));
-
- if (sscanf (param, "%s %s \"%[^\"]\"", date, time, name) < 3 &&
- sscanf (param, "%s %s '%[^']'", date, time, name) < 3 &&
- sscanf (param, "%s %s %[^\r\n]", date, time, name) < 3)
- {
- if (defaultlanguage == 'F')
- {
- printf ("Entrez un nom de compte, une date et une heure svp.\n");
- printf
- ("<exemple>: banset <nom_du_compte> aaaa/mm/jj [hh:mm:ss]\n");
- printf (" banset <nom_du_compte> 0 (0 = dé-bani)\n");
- printf
- (" ban/banish aaaa/mm/jj hh:mm:ss <nom du compte>\n");
- printf (" unban/unbanish <nom du compte>\n");
- printf (" Heure par défaut [hh:mm:ss]: 23:59:59.\n");
- ladmin_log
- ("Nombre incorrect de paramètres pour fixer un ban (commande 'banset' ou 'ban').\n");
- }
- else
- {
- printf ("Please input an account name, a date and a hour.\n");
- printf
- ("<example>: banset <account_name> yyyy/mm/dd [hh:mm:ss]\n");
- printf
- (" banset <account_name> 0 (0 = un-banished)\n");
- printf
- (" ban/banish yyyy/mm/dd hh:mm:ss <account name>\n");
- printf (" unban/unbanish <account name>\n");
- printf (" Default time [hh:mm:ss]: 23:59:59.\n");
- ladmin_log
- ("Incomplete parameters to set a ban ('banset' or 'ban' command).\n");
- }
+ char name[1023], date[1023], time_[1023];
+
+ memset(name, '\0', sizeof(name));
+ memset(date, '\0', sizeof(date));
+ memset(time_, '\0', sizeof(time_));
+
+ if (sscanf(param, "%s %s \"%[^\"]\"", date, time_, name) < 3 &&
+ sscanf(param, "%s %s '%[^']'", date, time_, name) < 3 &&
+ sscanf(param, "%s %s %[^\r\n]", date, time_, name) < 3)
+ {
+ PRINTF("Please input an account name, a date and a hour.\n");
+ PRINTF("<example>: banset <account_name> yyyy/mm/dd [hh:mm:ss]\n");
+ PRINTF(" banset <account_name> 0 (0 = un-banished)\n");
+ PRINTF(" ban/banish yyyy/mm/dd hh:mm:ss <account name>\n");
+ PRINTF(" unban/unbanish <account name>\n");
+ PRINTF(" Default time [hh:mm:ss]: 23:59:59.\n");
+ LADMIN_LOG("Incomplete parameters to set a ban ('banset' or 'ban' command).\n");
return 136;
}
- return bansetaccountsub (name, date, time);
+ return bansetaccountsub(name, date, time_);
}
//------------------------------------------------------------------------
// Sub-function: Set the final date of a banishment of an account (banset)
//------------------------------------------------------------------------
static
-int bansetaccount (const char *param)
+int bansetaccount(const char *param)
{
- char name[1023], date[1023], time[1023];
-
- memset (name, '\0', sizeof (name));
- memset (date, '\0', sizeof (date));
- memset (time, '\0', sizeof (time));
-
- if (sscanf (param, "\"%[^\"]\" %s %[^\r\n]", name, date, time) < 2 && // if date = 0, time can be void
- sscanf (param, "'%[^']' %s %[^\r\n]", name, date, time) < 2 && // if date = 0, time can be void
- sscanf (param, "%s %s %[^\r\n]", name, date, time) < 2)
- { // if date = 0, time can be void
- if (defaultlanguage == 'F')
- {
- printf ("Entrez un nom de compte, une date et une heure svp.\n");
- printf
- ("<exemple>: banset <nom_du_compte> aaaa/mm/jj [hh:mm:ss]\n");
- printf (" banset <nom_du_compte> 0 (0 = dé-bani)\n");
- printf
- (" ban/banish aaaa/mm/jj hh:mm:ss <nom du compte>\n");
- printf (" unban/unbanish <nom du compte>\n");
- printf (" Heure par défaut [hh:mm:ss]: 23:59:59.\n");
- ladmin_log
- ("Nombre incorrect de paramètres pour fixer un ban (commande 'banset' ou 'ban').\n");
- }
- else
- {
- printf ("Please input an account name, a date and a hour.\n");
- printf
- ("<example>: banset <account_name> yyyy/mm/dd [hh:mm:ss]\n");
- printf
- (" banset <account_name> 0 (0 = un-banished)\n");
- printf
- (" ban/banish yyyy/mm/dd hh:mm:ss <account name>\n");
- printf (" unban/unbanish <account name>\n");
- printf (" Default time [hh:mm:ss]: 23:59:59.\n");
- ladmin_log
- ("Incomplete parameters to set a ban ('banset' or 'ban' command).\n");
- }
+ char name[1023], date[1023], time_[1023];
+
+ memset(name, '\0', sizeof(name));
+ memset(date, '\0', sizeof(date));
+ memset(time_, '\0', sizeof(time_));
+
+ if (sscanf(param, "\"%[^\"]\" %s %[^\r\n]", name, date, time_) < 2 && // if date = 0, time_ can be void
+ sscanf(param, "'%[^']' %s %[^\r\n]", name, date, time_) < 2 && // if date = 0, time_ can be void
+ sscanf(param, "%s %s %[^\r\n]", name, date, time_) < 2)
+ { // if date = 0, time_ can be void
+ PRINTF("Please input an account name, a date and a hour.\n");
+ PRINTF("<example>: banset <account_name> yyyy/mm/dd [hh:mm:ss]\n");
+ PRINTF(" banset <account_name> 0 (0 = un-banished)\n");
+ PRINTF(" ban/banish yyyy/mm/dd hh:mm:ss <account name>\n");
+ PRINTF(" unban/unbanish <account name>\n");
+ PRINTF(" Default time [hh:mm:ss]: 23:59:59.\n");
+ LADMIN_LOG("Incomplete parameters to set a ban ('banset' or 'ban' command).\n");
return 136;
}
- if (time[0] == '\0')
- strcpy (time, "23:59:59");
+ if (time_[0] == '\0')
+ strcpy(time_, "23:59:59");
- return bansetaccountsub (name, date, time);
+ return bansetaccountsub(name, date, time_);
}
//-------------------------------------------------
// Sub-function: unbanishment of an account (unban)
//-------------------------------------------------
static
-int unbanaccount (const char *param)
+int unbanaccount(const char *param)
{
char name[1023];
- memset (name, '\0', sizeof (name));
+ memset(name, '\0', sizeof(name));
- if (strlen (param) == 0 ||
- (sscanf (param, "\"%[^\"]\"", name) < 1 &&
- sscanf (param, "'%[^']'", name) < 1 &&
- sscanf (param, "%[^\r\n]", name) < 1) || strlen (name) == 0)
+ if (strlen(param) == 0 ||
+ (sscanf(param, "\"%[^\"]\"", name) < 1 &&
+ sscanf(param, "'%[^']'", name) < 1 &&
+ sscanf(param, "%[^\r\n]", name) < 1) || strlen(name) == 0)
{
- if (defaultlanguage == 'F')
- {
- printf ("Entrez un nom de compte svp.\n");
- printf
- ("<exemple>: banset <nom_du_compte> aaaa/mm/jj [hh:mm:ss]\n");
- printf (" banset <nom_du_compte> 0 (0 = dé-bani)\n");
- printf
- (" ban/banish aaaa/mm/jj hh:mm:ss <nom du compte>\n");
- printf (" unban/unbanish <nom du compte>\n");
- printf (" Heure par défaut [hh:mm:ss]: 23:59:59.\n");
- ladmin_log
- ("Nombre incorrect de paramètres pour fixer un ban (commande 'unban').\n");
- }
- else
- {
- printf ("Please input an account name.\n");
- printf
- ("<example>: banset <account_name> yyyy/mm/dd [hh:mm:ss]\n");
- printf
- (" banset <account_name> 0 (0 = un-banished)\n");
- printf
- (" ban/banish yyyy/mm/dd hh:mm:ss <account name>\n");
- printf (" unban/unbanish <account name>\n");
- printf (" Default time [hh:mm:ss]: 23:59:59.\n");
- ladmin_log
- ("Incomplete parameters to set a ban ('unban' command).\n");
- }
+ PRINTF("Please input an account name.\n");
+ PRINTF("<example>: banset <account_name> yyyy/mm/dd [hh:mm:ss]\n");
+ PRINTF(" banset <account_name> 0 (0 = un-banished)\n");
+ PRINTF(" ban/banish yyyy/mm/dd hh:mm:ss <account name>\n");
+ PRINTF(" unban/unbanish <account name>\n");
+ PRINTF(" Default time [hh:mm:ss]: 23:59:59.\n");
+ LADMIN_LOG("Incomplete parameters to set a ban ('unban' command).\n");
return 136;
}
- return bansetaccountsub (name, "0", "");
+ return bansetaccountsub(name, "0", "");
}
//---------------------------------------------------------
@@ -2399,61 +1324,42 @@ int unbanaccount (const char *param)
// (Note: never send back a password with login-server!! security of passwords)
//---------------------------------------------------------
static
-int checkaccount (const char *param)
+int checkaccount(const char *param)
{
char name[1023], password[1023];
- memset (name, '\0', sizeof (name));
- memset (password, '\0', sizeof (password));
+ memset(name, '\0', sizeof(name));
+ memset(password, '\0', sizeof(password));
- if (sscanf (param, "\"%[^\"]\" %[^\r\n]", name, password) < 1 && // password can be void
- sscanf (param, "'%[^']' %[^\r\n]", name, password) < 1 && // password can be void
- sscanf (param, "%s %[^\r\n]", name, password) < 1)
+ if (sscanf(param, "\"%[^\"]\" %[^\r\n]", name, password) < 1 && // password can be void
+ sscanf(param, "'%[^']' %[^\r\n]", name, password) < 1 && // password can be void
+ sscanf(param, "%s %[^\r\n]", name, password) < 1)
{ // password can be void
- if (defaultlanguage == 'F')
- {
- printf ("Entrez un nom de compte svp.\n");
- printf ("<exemple> check testname motdepasse\n");
- ladmin_log
- ("Nombre incorrect de paramètres pour tester le mot d'un passe d'un compte (commande 'check').\n");
- }
- else
- {
- printf ("Please input an account name.\n");
- printf ("<example> check testname password\n");
- ladmin_log
- ("Incomplete parameters to check the password of an account ('check' command).\n");
- }
+ PRINTF("Please input an account name.\n");
+ PRINTF("<example> check testname password\n");
+ LADMIN_LOG("Incomplete parameters to check the password of an account ('check' command).\n");
return 136;
}
- if (verify_accountname (name) == 0)
+ if (verify_accountname(name) == 0)
{
return 102;
}
- if (strlen (password) == 0)
+ if (strlen(password) == 0)
{
- if (typepasswd (password) == 0)
+ if (typepasswd(password) == 0)
return 134;
}
- if (verify_password (password) == 0)
+ if (verify_password(password) == 0)
return 131;
- if (defaultlanguage == 'F')
- {
- ladmin_log
- ("Envoi d'un requête au serveur de logins pour test un mot de passe.\n");
- }
- else
- {
- ladmin_log ("Request to login-server to check a password.\n");
- }
+ LADMIN_LOG("Request to login-server to check a password.\n");
- WFIFOW (login_fd, 0) = 0x793a;
- memcpy (WFIFOP (login_fd, 2), name, 24);
- memcpy (WFIFOP (login_fd, 26), password, 24);
- WFIFOSET (login_fd, 50);
+ WFIFOW(login_fd, 0) = 0x793a;
+ memcpy(WFIFOP(login_fd, 2), name, 24);
+ memcpy(WFIFOP(login_fd, 26), password, 24);
+ WFIFOSET(login_fd, 50);
bytes_to_read = 1;
return 0;
@@ -2463,88 +1369,55 @@ int checkaccount (const char *param)
// Sub-function: Asking for deletion of an account
//------------------------------------------------
static
-int delaccount (const char *param)
+int delaccount(const char *param)
{
char name[1023];
char letter;
char confirm[1023];
- int i;
+ int i;
- memset (name, '\0', sizeof (name));
+ memset(name, '\0', sizeof(name));
- if (strlen (param) == 0 ||
- (sscanf (param, "\"%[^\"]\"", name) < 1 &&
- sscanf (param, "'%[^']'", name) < 1 &&
- sscanf (param, "%[^\r\n]", name) < 1) || strlen (name) == 0)
+ if (strlen(param) == 0 ||
+ (sscanf(param, "\"%[^\"]\"", name) < 1 &&
+ sscanf(param, "'%[^']'", name) < 1 &&
+ sscanf(param, "%[^\r\n]", name) < 1) || strlen(name) == 0)
{
- if (defaultlanguage == 'F')
- {
- printf ("Entrez un nom de compte svp.\n");
- printf ("<exemple> del nomtestasupprimer\n");
- ladmin_log
- ("Aucun nom donné pour supprimer un compte (commande 'delete').\n");
- }
- else
- {
- printf ("Please input an account name.\n");
- printf ("<example> del testnametodelete\n");
- ladmin_log
- ("No name given to delete an account ('delete' command).\n");
- }
+ PRINTF("Please input an account name.\n");
+ PRINTF("<example> del testnametodelete\n");
+ LADMIN_LOG("No name given to delete an account ('delete' command).\n");
return 136;
}
- if (verify_accountname (name) == 0)
+ if (verify_accountname(name) == 0)
{
return 102;
}
- memset (confirm, '\0', sizeof (confirm));
- while ((confirm[0] != 'o' || defaultlanguage != 'F') && confirm[0] != 'n'
- && (confirm[0] != 'y' || defaultlanguage == 'F'))
+ memset(confirm, '\0', sizeof(confirm));
+ while (confirm[0] != 'n'
+ && confirm[0] != 'y')
{
- if (defaultlanguage == 'F')
- printf
- ("\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");
- fflush (stdout);
- memset (confirm, '\0', sizeof (confirm));
+ PRINTF("\033[1;36m ** Are you really sure to DELETE account [$userid]? (y/n) > \033[0m");
+ fflush(stdout);
+ memset(confirm, '\0', sizeof(confirm));
i = 0;
- while ((letter = getchar ()) != '\n')
+ while ((letter = getchar()) != '\n')
confirm[i++] = letter;
}
if (confirm[0] == 'n')
{
- if (defaultlanguage == 'F')
- {
- printf ("Suppression annulée.\n");
- ladmin_log
- ("Suppression annulée par l'utilisateur (commande 'delete').\n");
- }
- else
- {
- printf ("Deletion canceled.\n");
- ladmin_log ("Deletion canceled by user ('delete' command).\n");
- }
+ PRINTF("Deletion canceled.\n");
+ LADMIN_LOG("Deletion canceled by user ('delete' command).\n");
return 121;
}
- if (defaultlanguage == 'F')
- {
- ladmin_log
- ("Envoi d'un requête au serveur de logins pour détruire un compte.\n");
- }
- else
- {
- ladmin_log ("Request to login-server to delete an acount.\n");
- }
+ LADMIN_LOG("Request to login-server to delete an acount.\n");
- WFIFOW (login_fd, 0) = 0x7932;
- memcpy (WFIFOP (login_fd, 2), name, 24);
- WFIFOSET (login_fd, 26);
+ WFIFOW(login_fd, 0) = 0x7932;
+ memcpy(WFIFOP(login_fd, 2), name, 24);
+ WFIFOSET(login_fd, 26);
bytes_to_read = 1;
return 0;
@@ -2554,114 +1427,59 @@ int delaccount (const char *param)
// Sub-function: Asking to modification of an account e-mail
//----------------------------------------------------------
static
-int changeemail (const char *param)
+int changeemail(const char *param)
{
char name[1023], email[1023];
- memset (name, '\0', sizeof (name));
- memset (email, '\0', sizeof (email));
+ memset(name, '\0', sizeof(name));
+ memset(email, '\0', sizeof(email));
- if (sscanf (param, "\"%[^\"]\" %[^\r\n]", name, email) < 2 &&
- sscanf (param, "'%[^']' %[^\r\n]", name, email) < 2 &&
- sscanf (param, "%s %[^\r\n]", name, email) < 2)
+ if (sscanf(param, "\"%[^\"]\" %[^\r\n]", name, email) < 2 &&
+ sscanf(param, "'%[^']' %[^\r\n]", name, email) < 2 &&
+ sscanf(param, "%s %[^\r\n]", name, email) < 2)
{
- if (defaultlanguage == 'F')
- {
- printf ("Entrez un nom de compte et une email svp.\n");
- printf ("<exemple> email testname nouveauemail\n");
- ladmin_log
- ("Nombre incorrect de paramètres pour changer l'email d'un compte (commande 'email').\n");
- }
- else
- {
- printf ("Please input an account name and an email.\n");
- printf ("<example> email testname newemail\n");
- ladmin_log
- ("Incomplete parameters to change the email of an account ('email' command).\n");
- }
+ PRINTF("Please input an account name and an email.\n");
+ PRINTF("<example> email testname newemail\n");
+ LADMIN_LOG("Incomplete parameters to change the email of an account ('email' command).\n");
return 136;
}
- if (verify_accountname (name) == 0)
+ if (verify_accountname(name) == 0)
{
return 102;
}
- if (strlen (email) < 3)
+ if (strlen(email) < 3)
{
- if (defaultlanguage == 'F')
- {
- printf ("Email trop courte [%s]. Entrez une e-mail valide svp.\n",
- email);
- ladmin_log
- ("Email trop courte [%s]. Entrez une e-mail valide svp.\n",
- email);
- }
- else
- {
- printf ("Email is too short [%s]. Please input a valid e-mail.\n",
- email);
- ladmin_log
- ("Email is too short [%s]. Please input a valid e-mail.\n",
- email);
- }
+ PRINTF("Email is too short [%s]. Please input a valid e-mail.\n",
+ email);
+ LADMIN_LOG("Email is too short [%s]. Please input a valid e-mail.\n",
+ email);
return 109;
}
- if (strlen (email) > 39)
+ if (strlen(email) > 39)
{
- if (defaultlanguage == 'F')
- {
- printf
- ("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 caractères maximum svp.\n",
- email);
- }
- else
- {
- printf
- ("Email is too long [%s]. Please input an e-mail with 39 bytes at the most.\n",
- email);
- ladmin_log
- ("Email is too long [%s]. Please input an e-mail with 39 bytes at the most.\n",
- email);
- }
+ PRINTF("Email is too long [%s]. Please input an e-mail with 39 bytes at the most.\n",
+ email);
+ LADMIN_LOG("Email is too long [%s]. Please input an e-mail with 39 bytes at the most.\n",
+ email);
return 109;
}
- if (e_mail_check (email) == 0)
+ if (e_mail_check(email) == 0)
{
- if (defaultlanguage == 'F')
- {
- printf ("Email incorrecte [%s]. Entrez une e-mail valide svp.\n",
- email);
- ladmin_log ("Email incorrecte [%s]. Entrez une e-mail valide svp.\n",
- email);
- }
- else
- {
- printf ("Invalid email [%s]. Please input a valid e-mail.\n",
- email);
- ladmin_log ("Invalid email [%s]. Please input a valid e-mail.\n",
- email);
- }
+ PRINTF("Invalid email [%s]. Please input a valid e-mail.\n",
+ email);
+ LADMIN_LOG("Invalid email [%s]. Please input a valid e-mail.\n",
+ email);
return 109;
}
- if (defaultlanguage == 'F')
- {
- ladmin_log
- ("Envoi d'un requête au serveur de logins pour changer une email.\n");
- }
- else
- {
- ladmin_log ("Request to login-server to change an email.\n");
- }
+ LADMIN_LOG("Request to login-server to change an email.\n");
- WFIFOW (login_fd, 0) = 0x7940;
- memcpy (WFIFOP (login_fd, 2), name, 24);
- memcpy (WFIFOP (login_fd, 26), email, 40);
- WFIFOSET (login_fd, 66);
+ WFIFOW(login_fd, 0) = 0x7940;
+ memcpy(WFIFOP(login_fd, 2), name, 24);
+ memcpy(WFIFOP(login_fd, 26), email, 40);
+ WFIFOSET(login_fd, 66);
bytes_to_read = 1;
return 0;
@@ -2671,21 +1489,12 @@ int changeemail (const char *param)
// Sub-function: Asking of the number of online players
//-----------------------------------------------------
static
-int getlogincount (void)
+int getlogincount(void)
{
- if (defaultlanguage == 'F')
- {
- ladmin_log
- ("Envoi d'un requête au serveur de logins pour obtenir le nombre de joueurs en jeu.\n");
- }
- else
- {
- ladmin_log
- ("Request to login-server to obtain the # of online players.\n");
- }
+ LADMIN_LOG("Request to login-server to obtain the # of online players.\n");
- WFIFOW (login_fd, 0) = 0x7938;
- WFIFOSET (login_fd, 2);
+ WFIFOW(login_fd, 0) = 0x7938;
+ WFIFOSET(login_fd, 2);
bytes_to_read = 1;
return 0;
@@ -2695,77 +1504,44 @@ int getlogincount (void)
// Sub-function: Asking to modify the GM level of an account
//----------------------------------------------------------
static
-int changegmlevel (const char *param)
+int changegmlevel(const char *param)
{
char name[1023];
- int GM_level;
+ int GM_level;
- memset (name, '\0', sizeof (name));
+ memset(name, '\0', sizeof(name));
GM_level = 0;
- if (sscanf (param, "\"%[^\"]\" %d", name, &GM_level) < 1 &&
- sscanf (param, "'%[^']' %d", name, &GM_level) < 1 &&
- sscanf (param, "%s %d", name, &GM_level) < 1)
+ if (sscanf(param, "\"%[^\"]\" %d", name, &GM_level) < 1 &&
+ sscanf(param, "'%[^']' %d", name, &GM_level) < 1 &&
+ sscanf(param, "%s %d", name, &GM_level) < 1)
{
- if (defaultlanguage == 'F')
- {
- printf ("Entrez un nom de compte et un niveau de GM svp.\n");
- printf ("<exemple> gm nomtest 80\n");
- ladmin_log
- ("Nombre incorrect de paramètres pour changer le Niveau de GM d'un compte (commande 'gm').\n");
- }
- else
- {
- printf ("Please input an account name and a GM level.\n");
- printf ("<example> gm testname 80\n");
- ladmin_log
- ("Incomplete parameters to change the GM level of an account ('gm' command).\n");
- }
+ PRINTF("Please input an account name and a GM level.\n");
+ PRINTF("<example> gm testname 80\n");
+ LADMIN_LOG("Incomplete parameters to change the GM level of an account ('gm' command).\n");
return 136;
}
- if (verify_accountname (name) == 0)
+ if (verify_accountname(name) == 0)
{
return 102;
}
if (GM_level < 0 || GM_level > 99)
{
- if (defaultlanguage == 'F')
- {
- printf
- ("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.\n",
- GM_level);
- }
- else
- {
- printf
- ("Illegal GM level [%d]. Please input a value from 0 to 99.\n",
- GM_level);
- ladmin_log
- ("Illegal GM level [%d]. The value can be from 0 to 99.\n",
- GM_level);
- }
+ PRINTF("Illegal GM level [%d]. Please input a value from 0 to 99.\n",
+ GM_level);
+ LADMIN_LOG("Illegal GM level [%d]. The value can be from 0 to 99.\n",
+ GM_level);
return 103;
}
- if (defaultlanguage == 'F')
- {
- ladmin_log
- ("Envoi d'un requête au serveur de logins pour changer un niveau de GM.\n");
- }
- else
- {
- ladmin_log ("Request to login-server to change a GM level.\n");
- }
+ LADMIN_LOG("Request to login-server to change a GM level.\n");
- WFIFOW (login_fd, 0) = 0x793e;
- memcpy (WFIFOP (login_fd, 2), name, 24);
- WFIFOB (login_fd, 26) = GM_level;
- WFIFOSET (login_fd, 27);
+ WFIFOW(login_fd, 0) = 0x793e;
+ memcpy(WFIFOP(login_fd, 2), name, 24);
+ WFIFOB(login_fd, 26) = GM_level;
+ WFIFOSET(login_fd, 27);
bytes_to_read = 1;
return 0;
@@ -2775,52 +1551,33 @@ int changegmlevel (const char *param)
// Sub-function: Asking to obtain an account id
//---------------------------------------------
static
-int idaccount (const char *param)
+int idaccount(const char *param)
{
char name[1023];
- memset (name, '\0', sizeof (name));
+ memset(name, '\0', sizeof(name));
- if (strlen (param) == 0 ||
- (sscanf (param, "\"%[^\"]\"", name) < 1 &&
- sscanf (param, "'%[^']'", name) < 1 &&
- sscanf (param, "%[^\r\n]", name) < 1) || strlen (name) == 0)
+ if (strlen(param) == 0 ||
+ (sscanf(param, "\"%[^\"]\"", name) < 1 &&
+ sscanf(param, "'%[^']'", name) < 1 &&
+ sscanf(param, "%[^\r\n]", name) < 1) || strlen(name) == 0)
{
- if (defaultlanguage == 'F')
- {
- printf ("Entrez un nom de compte svp.\n");
- printf ("<exemple> id nomtest\n");
- ladmin_log
- ("Aucun nom donné pour rechecher l'id d'un compte (commande 'id').\n");
- }
- else
- {
- printf ("Please input an account name.\n");
- printf ("<example> id testname\n");
- ladmin_log
- ("No name given to search an account id ('id' command).\n");
- }
+ PRINTF("Please input an account name.\n");
+ PRINTF("<example> id testname\n");
+ LADMIN_LOG("No name given to search an account id ('id' command).\n");
return 136;
}
- if (verify_accountname (name) == 0)
+ if (verify_accountname(name) == 0)
{
return 102;
}
- if (defaultlanguage == 'F')
- {
- ladmin_log
- ("Envoi d'un requête au serveur de logins pour connaître l'id d'un compte.\n");
- }
- else
- {
- ladmin_log ("Request to login-server to know an account id.\n");
- }
+ LADMIN_LOG("Request to login-server to know an account id.\n");
- WFIFOW (login_fd, 0) = 0x7944;
- memcpy (WFIFOP (login_fd, 2), name, 24);
- WFIFOSET (login_fd, 26);
+ WFIFOW(login_fd, 0) = 0x7944;
+ memcpy(WFIFOP(login_fd, 2), name, 24);
+ WFIFOSET(login_fd, 26);
bytes_to_read = 1;
return 0;
@@ -2830,38 +1587,20 @@ int idaccount (const char *param)
// Sub-function: Asking to displaying information about an account (by its id)
//----------------------------------------------------------------------------
static
-int infoaccount (int account_id)
+int infoaccount(int account_id)
{
if (account_id < 0)
{
- if (defaultlanguage == 'F')
- {
- printf ("Entrez un id ayant une valeur positive svp.\n");
- ladmin_log
- ("Une valeur négative a été donné pour trouver le compte.\n");
- }
- else
- {
- printf ("Please input a positive value for the id.\n");
- ladmin_log ("Negative value was given to found the account.\n");
- }
+ PRINTF("Please input a positive value for the id.\n");
+ LADMIN_LOG("Negative value was given to found the account.\n");
return 136;
}
- if (defaultlanguage == 'F')
- {
- ladmin_log
- ("Envoi d'un requête au serveur de logins pour obtenir le information d'un compte (par l'id).\n");
- }
- else
- {
- ladmin_log
- ("Request to login-server to obtain information about an account (by its id).\n");
- }
+ LADMIN_LOG("Request to login-server to obtain information about an account (by its id).\n");
- WFIFOW (login_fd, 0) = 0x7954;
- WFIFOL (login_fd, 2) = account_id;
- WFIFOSET (login_fd, 6);
+ WFIFOW(login_fd, 0) = 0x7954;
+ WFIFOL(login_fd, 2) = account_id;
+ WFIFOSET(login_fd, 6);
bytes_to_read = 1;
return 0;
@@ -2871,117 +1610,42 @@ int infoaccount (int account_id)
// Sub-function: Send a broadcast message
//---------------------------------------
static
-int sendbroadcast (short type, const char *message)
+int sendbroadcast(short type, const char *message)
{
- if (strlen (message) == 0)
+ if (strlen(message) == 0)
{
- if (defaultlanguage == 'F')
+ PRINTF("Please input a message.\n");
+ if (type == 0)
{
- printf ("Entrez un message svp.\n");
- if (type == 0)
- {
- printf ("<exemple> kami un message\n");
- }
- else
- {
- printf ("<exemple> kamib un message\n");
- }
- ladmin_log ("Le message est vide (commande 'kami(b)').\n");
+ PRINTF("<example> kami a message\n");
}
else
{
- printf ("Please input a message.\n");
- if (type == 0)
- {
- printf ("<example> kami a message\n");
- }
- else
- {
- printf ("<example> kamib a message\n");
- }
- ladmin_log ("The message is void ('kami(b)' command).\n");
+ PRINTF("<example> kamib a message\n");
}
+ LADMIN_LOG("The message is void ('kami(b)' command).\n");
return 136;
}
- WFIFOW (login_fd, 0) = 0x794e;
- WFIFOW (login_fd, 2) = type;
- WFIFOL (login_fd, 4) = strlen (message) + 1;
- memcpy (WFIFOP (login_fd, 8), message, strlen (message) + 1);
- WFIFOSET (login_fd, 8 + strlen (message) + 1);
+ WFIFOW(login_fd, 0) = 0x794e;
+ WFIFOW(login_fd, 2) = type;
+ WFIFOL(login_fd, 4) = strlen(message) + 1;
+ memcpy(WFIFOP(login_fd, 8), message, strlen(message) + 1);
+ WFIFOSET(login_fd, 8 + strlen(message) + 1);
bytes_to_read = 1;
return 0;
}
-//--------------------------------------------
-// Sub-function: Change language of displaying
-//--------------------------------------------
-static
-int changelanguage (char *language)
-{
- if (strlen (language) == 0)
- {
- if (defaultlanguage == 'F')
- {
- printf ("Entrez une langue svp.\n");
- printf ("<exemple> language english\n");
- printf (" language français\n");
- ladmin_log ("La langue est vide (commande 'language').\n");
- }
- else
- {
- printf ("Please input a language.\n");
- printf ("<example> language english\n");
- printf (" language français\n");
- ladmin_log ("The language is void ('language' command).\n");
- }
- return 136;
- }
-
- language[0] = toupper (language[0]);
- if (language[0] == 'F' || language[0] == 'E')
- {
- defaultlanguage = language[0];
- if (defaultlanguage == 'F')
- {
- printf ("Changement de la langue d'affichage en Français.\n");
- ladmin_log ("Changement de la langue d'affichage en Français.\n");
- }
- else
- {
- printf ("Displaying language changed to English.\n");
- ladmin_log ("Displaying language changed to English.\n");
- }
- }
- else
- {
- if (defaultlanguage == 'F')
- {
- printf
- ("Langue non paramétrée (langues possibles: 'Français' ou 'English').\n");
- ladmin_log
- ("Langue non paramétrée (Français ou English nécessaire).\n");
- }
- else
- {
- printf
- ("Undefined language (possible languages: Français or English).\n");
- ladmin_log ("Undefined language (must be Français or English).\n");
- }
- }
-
- return 0;
-}
//--------------------------------------------------------
// Sub-function: Asking to Displaying of the accounts list
//--------------------------------------------------------
static
-int listaccount (char *param, int type)
+int listaccount(char *param, int type)
{
//int list_first, list_last, list_type; // parameter to display a list of accounts
- int i;
+ int i;
list_type = type;
@@ -2996,7 +1660,7 @@ int listaccount (char *param, int type)
else if (list_type == 2)
{ // if search
for (i = 0; param[i]; i++)
- param[i] = tolower (param[i]);
+ param[i] = tolower(param[i]);
// get all accounts = use default
}
else if (list_type == 3)
@@ -3009,7 +1673,7 @@ int listaccount (char *param, int type)
}
else
{ // if list (list_type == 0)
- switch (sscanf (param, "%d %d", &list_first, &list_last))
+ switch (sscanf(param, "%d %d", &list_first, &list_last))
{
case 0:
// get all accounts = use default
@@ -3017,6 +1681,7 @@ int listaccount (char *param, int type)
case 1:
list_last = 0;
// use tests of the following value
+ FALLTHROUGH;
default:
if (list_first < 0)
list_first = 0;
@@ -3026,38 +1691,18 @@ int listaccount (char *param, int type)
}
}
- if (defaultlanguage == 'F')
- {
- ladmin_log
- ("Envoi d'un requête au serveur de logins pour obtenir la liste des comptes de %d à %d.\n",
- list_first, list_last);
- }
- else
- {
- ladmin_log
- ("Request to login-server to obtain the list of accounts from %d to %d.\n",
- list_first, list_last);
- }
+ LADMIN_LOG("Request to login-server to obtain the list of accounts from %d to %d.\n",
+ list_first, list_last);
- WFIFOW (login_fd, 0) = 0x7920;
- WFIFOL (login_fd, 2) = list_first;
- WFIFOL (login_fd, 6) = list_last;
- WFIFOSET (login_fd, 10);
+ WFIFOW(login_fd, 0) = 0x7920;
+ WFIFOL(login_fd, 2) = list_first;
+ WFIFOL(login_fd, 6) = list_last;
+ WFIFOSET(login_fd, 10);
bytes_to_read = 1;
// 0123456789 01 01234567890123456789012301234 012345 0123456789012345678901234567
- if (defaultlanguage == 'F')
- {
- Iprintf
- (" id_compte GM nom_utilisateur sexe count statut\n");
- }
- else
- {
- Iprintf
- ("account_id GM user_name sex count state\n");
- }
- Iprintf
- ("-------------------------------------------------------------------------------\n");
+ Iprintf("account_id GM user_name sex count state\n");
+ Iprintf("-------------------------------------------------------------------------------\n");
list_count = 0;
return 0;
@@ -3067,20 +1712,20 @@ int listaccount (char *param, int type)
// Sub-function: Frobnicate items
//--------------------------------------------------------
static
-int itemfrob (const char *param)
+int itemfrob(const char *param)
{
- int source_id, dest_id;
+ int source_id, dest_id;
- if (sscanf (param, "%d %d", &source_id, &dest_id) < 2)
+ if (sscanf(param, "%d %d", &source_id, &dest_id) < 2)
{
- printf ("You must provide the source and destination item IDs.\n");
+ PRINTF("You must provide the source and destination item IDs.\n");
return 1;
}
- WFIFOW (login_fd, 0) = 0x7924;
- WFIFOL (login_fd, 2) = source_id;
- WFIFOL (login_fd, 6) = dest_id;
- WFIFOSET (login_fd, 10);
+ WFIFOW(login_fd, 0) = 0x7924;
+ WFIFOL(login_fd, 2) = source_id;
+ WFIFOL(login_fd, 6) = dest_id;
+ WFIFOSET(login_fd, 10);
bytes_to_read = 1; // all logging is done to the three main servers
return 0;
@@ -3090,76 +1735,45 @@ int itemfrob (const char *param)
// Sub-function: Asking to modify a memo field
//--------------------------------------------
static
-int changememo (const char *param)
+int changememo(const char *param)
{
char name[1023], memo[1023];
- memset (name, '\0', sizeof (name));
- memset (memo, '\0', sizeof (memo));
+ memset(name, '\0', sizeof(name));
+ memset(memo, '\0', sizeof(memo));
- if (sscanf (param, "\"%[^\"]\" %[^\r\n]", name, memo) < 1 && // memo can be void
- sscanf (param, "'%[^']' %[^\r\n]", name, memo) < 1 && // memo can be void
- sscanf (param, "%s %[^\r\n]", name, memo) < 1)
+ if (sscanf(param, "\"%[^\"]\" %[^\r\n]", name, memo) < 1 && // memo can be void
+ sscanf(param, "'%[^']' %[^\r\n]", name, memo) < 1 && // memo can be void
+ sscanf(param, "%s %[^\r\n]", name, memo) < 1)
{ // memo can be void
- if (defaultlanguage == 'F')
- {
- printf ("Entrez un nom de compte et un mémo svp.\n");
- printf ("<exemple> memo nomtest nouveau memo\n");
- ladmin_log
- ("Nombre incorrect de paramètres pour changer le mémo d'un compte (commande 'email').\n");
- }
- else
- {
- printf ("Please input an account name and a memo.\n");
- printf ("<example> memo testname new memo\n");
- ladmin_log
- ("Incomplete parameters to change the memo of an account ('email' command).\n");
- }
+ PRINTF("Please input an account name and a memo.\n");
+ PRINTF("<example> memo testname new memo\n");
+ LADMIN_LOG("Incomplete parameters to change the memo of an account ('email' command).\n");
return 136;
}
- if (verify_accountname (name) == 0)
+ if (verify_accountname(name) == 0)
{
return 102;
}
- if (strlen (memo) > 254)
+ if (strlen(memo) > 254)
{
- if (defaultlanguage == 'F')
- {
- 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
- ("Mémo trop long (%d caractères). Entrez un mémo de 254 caractères maximum svp.\n",
- strlen (memo));
- }
- else
- {
- printf ("Memo is too long (%d characters).\n", strlen (memo));
- printf ("Please input a memo of 254 bytes at the maximum.\n");
- ladmin_log
- ("Email is too long (%d characters). Please input a memo of 254 bytes at the maximum.\n",
- strlen (memo));
- }
+ PRINTF("Memo is too long (%zu characters).\n", strlen(memo));
+ PRINTF("Please input a memo of 254 bytes at the maximum.\n");
+ LADMIN_LOG("Email is too long (%zu characters). Please input a memo of 254 bytes at the maximum.\n",
+ strlen(memo));
return 102;
}
- if (defaultlanguage == 'F')
- {
- ladmin_log
- ("Envoi d'un requête au serveur de logins pour changer un mémo.\n");
- }
- else
- {
- ladmin_log ("Request to login-server to change a memo.\n");
- }
+ LADMIN_LOG("Request to login-server to change a memo.\n");
- WFIFOW (login_fd, 0) = 0x7942;
- memcpy (WFIFOP (login_fd, 2), name, 24);
- WFIFOW (login_fd, 26) = strlen (memo);
- if (strlen (memo) > 0)
- memcpy (WFIFOP (login_fd, 28), memo, strlen (memo));
- WFIFOSET (login_fd, 28 + strlen (memo));
+ WFIFOW(login_fd, 0) = 0x7942;
+ memcpy(WFIFOP(login_fd, 2), name, 24);
+ WFIFOW(login_fd, 26) = strlen(memo);
+ if (strlen(memo) > 0)
+ memcpy(WFIFOP(login_fd, 28), memo, strlen(memo));
+ WFIFOSET(login_fd, 28 + strlen(memo));
bytes_to_read = 1;
return 0;
@@ -3169,34 +1783,20 @@ int changememo (const char *param)
// Sub-function: Asking to obtain an account name
//-----------------------------------------------
static
-int nameaccount (int id)
+int nameaccount(int id)
{
if (id < 0)
{
- if (defaultlanguage == 'F')
- {
- printf ("Entrez un id ayant une valeur positive svp.\n");
- ladmin_log
- ("Id négatif donné pour rechecher le nom d'un compte (commande 'name').\n");
- }
- else
- {
- printf ("Please input a positive value for the id.\n");
- ladmin_log
- ("Negativ id given to search an account name ('name' command).\n");
- }
+ PRINTF("Please input a positive value for the id.\n");
+ LADMIN_LOG("Negativ id given to search an account name ('name' command).\n");
return 136;
}
- if (defaultlanguage == 'F')
- ladmin_log
- ("Envoi d'un requête au serveur de logins pour connaître le nom d'un compte.\n");
- else
- ladmin_log ("Request to login-server to know an account name.\n");
+ LADMIN_LOG("Request to login-server to know an account name.\n");
- WFIFOW (login_fd, 0) = 0x7946;
- WFIFOL (login_fd, 2) = id;
- WFIFOSET (login_fd, 6);
+ WFIFOW(login_fd, 0) = 0x7946;
+ WFIFOL(login_fd, 2) = id;
+ WFIFOSET(login_fd, 6);
bytes_to_read = 1;
return 0;
@@ -3207,61 +1807,42 @@ int nameaccount (int id)
// (Note: never send back a password with login-server!! security of passwords)
//------------------------------------------
static
-int changepasswd (const char *param)
+int changepasswd(const char *param)
{
char name[1023], password[1023];
- memset (name, '\0', sizeof (name));
- memset (password, '\0', sizeof (password));
+ memset(name, '\0', sizeof(name));
+ memset(password, '\0', sizeof(password));
- if (sscanf (param, "\"%[^\"]\" %[^\r\n]", name, password) < 1 &&
- sscanf (param, "'%[^']' %[^\r\n]", name, password) < 1 &&
- sscanf (param, "%s %[^\r\n]", name, password) < 1)
+ if (sscanf(param, "\"%[^\"]\" %[^\r\n]", name, password) < 1 &&
+ sscanf(param, "'%[^']' %[^\r\n]", name, password) < 1 &&
+ sscanf(param, "%s %[^\r\n]", name, password) < 1)
{
- if (defaultlanguage == 'F')
- {
- printf ("Entrez un nom de compte svp.\n");
- printf ("<exemple> passwd nomtest nouveaumotdepasse\n");
- ladmin_log
- ("Nombre incorrect de paramètres pour changer le mot d'un passe d'un compte (commande 'password').\n");
- }
- else
- {
- printf ("Please input an account name.\n");
- printf ("<example> passwd testname newpassword\n");
- ladmin_log
- ("Incomplete parameters to change the password of an account ('password' command).\n");
- }
+ PRINTF("Please input an account name.\n");
+ PRINTF("<example> passwd testname newpassword\n");
+ LADMIN_LOG("Incomplete parameters to change the password of an account ('password' command).\n");
return 136;
}
- if (verify_accountname (name) == 0)
+ if (verify_accountname(name) == 0)
{
return 102;
}
- if (strlen (password) == 0)
+ if (strlen(password) == 0)
{
- if (typepasswd (password) == 0)
+ if (typepasswd(password) == 0)
return 134;
}
- if (verify_password (password) == 0)
+ if (verify_password(password) == 0)
return 131;
- if (defaultlanguage == 'F')
- {
- ladmin_log
- ("Envoi d'un requête au serveur de logins pour changer un mot de passe.\n");
- }
- else
- {
- ladmin_log ("Request to login-server to change a password.\n");
- }
+ LADMIN_LOG("Request to login-server to change a password.\n");
- WFIFOW (login_fd, 0) = 0x7934;
- memcpy (WFIFOP (login_fd, 2), name, 24);
- memcpy (WFIFOP (login_fd, 26), password, 24);
- WFIFOSET (login_fd, 50);
+ WFIFOW(login_fd, 0) = 0x7934;
+ memcpy(WFIFOP(login_fd, 2), name, 24);
+ memcpy(WFIFOP(login_fd, 26), password, 24);
+ WFIFOSET(login_fd, 50);
bytes_to_read = 1;
return 0;
@@ -3272,27 +1853,16 @@ int changepasswd (const char *param)
// this function have no answer
//----------------------------------------------------------------------
static
-int reloadGM (void)
+int reloadGM(char *params)
{
- WFIFOW (login_fd, 0) = 0x7955;
- WFIFOSET (login_fd, 2);
+ WFIFOW(login_fd, 0) = 0x7955;
+ WFIFOSET(login_fd, 2);
bytes_to_read = 0;
- if (defaultlanguage == 'F')
- {
- ladmin_log
- ("Demande de recharger le fichier de configuration des GM envoyée.\n");
- printf
- ("Demande de recharger le fichier de configuration des GM envoyée.\n");
- printf ("Vérifiez les comptes GM actuels (après rechargement):\n");
- }
- else
- {
- ladmin_log ("Request to reload the GM configuration file sended.\n");
- printf ("Request to reload the GM configuration file sended.\n");
- printf ("Check the actual GM accounts (after reloading):\n");
- }
- listaccount (parameters, 1); // 1: to list only GM
+ LADMIN_LOG("Request to reload the GM configuration file sended.\n");
+ PRINTF("Request to reload the GM configuration file sended.\n");
+ PRINTF("Check the actual GM accounts (after reloading):\n");
+ listaccount(params, 1); // 1: to list only GM
return 180;
}
@@ -3301,71 +1871,43 @@ int reloadGM (void)
// Sub-function: Asking to modify the sex of an account
//-----------------------------------------------------
static
-int changesex (const char *param)
+int changesex(const char *param)
{
char name[1023], sex[1023];
- memset (name, '\0', sizeof (name));
- memset (sex, '\0', sizeof (sex));
+ memset(name, '\0', sizeof(name));
+ memset(sex, '\0', sizeof(sex));
- if (sscanf (param, "\"%[^\"]\" %[^\r\n]", name, sex) < 2 &&
- sscanf (param, "'%[^']' %[^\r\n]", name, sex) < 2 &&
- sscanf (param, "%s %[^\r\n]", name, sex) < 2)
+ if (sscanf(param, "\"%[^\"]\" %[^\r\n]", name, sex) < 2 &&
+ sscanf(param, "'%[^']' %[^\r\n]", name, sex) < 2 &&
+ sscanf(param, "%s %[^\r\n]", name, sex) < 2)
{
- if (defaultlanguage == 'F')
- {
- printf ("Entrez un nom de compte et un sexe svp.\n");
- printf ("<exemple> sex nomtest Male\n");
- ladmin_log
- ("Nombre incorrect de paramètres pour changer le sexe d'un compte (commande 'sex').\n");
- }
- else
- {
- printf ("Please input an account name and a sex.\n");
- printf ("<example> sex testname Male\n");
- ladmin_log
- ("Incomplete parameters to change the sex of an account ('sex' command).\n");
- }
+ PRINTF("Please input an account name and a sex.\n");
+ PRINTF("<example> sex testname Male\n");
+ LADMIN_LOG("Incomplete parameters to change the sex of an account ('sex' command).\n");
return 136;
}
- if (verify_accountname (name) == 0)
+ if (verify_accountname(name) == 0)
{
return 102;
}
- sex[0] = toupper (sex[0]);
- if (strchr ("MF", sex[0]) == NULL)
+ sex[0] = toupper(sex[0]);
+ if (strchr("MF", sex[0]) == NULL)
{
- if (defaultlanguage == 'F')
- {
- printf ("Sexe incorrect [%s]. Entrez M ou F svp.\n", sex);
- ladmin_log ("Sexe incorrect [%s]. Entrez M ou F svp.\n",
- sex);
- }
- else
- {
- printf ("Illegal gender [%s]. Please input M or F.\n", sex);
- ladmin_log ("Illegal gender [%s]. Please input M or F.\n",
- sex);
- }
+ PRINTF("Illegal gender [%s]. Please input M or F.\n", sex);
+ LADMIN_LOG("Illegal gender [%s]. Please input M or F.\n",
+ sex);
return 103;
}
- if (defaultlanguage == 'F')
- {
- ladmin_log
- ("Envoi d'un requête au serveur de logins pour changer un sexe.\n");
- }
- else
- {
- ladmin_log ("Request to login-server to change a sex.\n");
- }
+ LADMIN_LOG("Request to login-server to change a sex.\n");
- WFIFOW (login_fd, 0) = 0x793c;
- memcpy (WFIFOP (login_fd, 2), name, 24);
- WFIFOB (login_fd, 26) = sex[0];
- WFIFOSET (login_fd, 27);
+ WFIFOW(login_fd, 0) = 0x793c;
+ memcpy(WFIFOP(login_fd, 2), name, 24);
+ WFIFOB(login_fd, 26) = sex[0];
+ WFIFOSET(login_fd, 27);
bytes_to_read = 1;
return 0;
@@ -3376,120 +1918,62 @@ int changesex (const char *param)
// Asking to modify the state of an account
//-------------------------------------------------------------------------
static
-int changestatesub (const char *name, int state, const char *error_message7)
+int changestatesub(const char *name, int state, const char *error_message7)
{
char error_message[1023]; // need to use, because we can modify error_message7
- memset (error_message, '\0', sizeof (error_message));
- strncpy (error_message, error_message7, sizeof (error_message) - 1);
+ memset(error_message, '\0', sizeof(error_message));
+ strncpy(error_message, error_message7, sizeof(error_message) - 1);
if ((state < 0 || state > 9) && state != 100)
{ // Valid values: 0: ok, or value of the 0x006a packet + 1
- if (defaultlanguage == 'F')
- {
- printf ("Entrez une des statuts suivantes svp:\n");
- printf
- (" 0 = Compte ok 6 = Your Game's EXE file is not the latest version\n");
- }
- else
- {
- printf ("Please input one of these states:\n");
- printf
- (" 0 = Account ok 6 = Your Game's EXE file is not the latest version\n");
- }
- printf
- (" 1 = Unregistered ID 7 = You are Prohibited to log in until + message\n");
- printf
- (" 2 = Incorrect Password 8 = Server is jammed due to over populated\n");
- printf (" 3 = This ID is expired 9 = No MSG\n");
- printf
- (" 4 = Rejected from Server 100 = This ID has been totally erased\n");
- printf (" 5 = You have been blocked by the GM Team\n");
- if (defaultlanguage == 'F')
- {
- printf ("<exemples> state nomtest 5\n");
- printf (" state nomtest 7 fin de votre ban\n");
- printf (" block <nom compte>\n");
- printf (" unblock <nom compte>\n");
- ladmin_log
- ("Valeur incorrecte pour le statut d'un compte (commande 'state', 'block' ou 'unblock').\n");
- }
- else
- {
- printf ("<examples> state testname 5\n");
- printf (" state testname 7 end of your ban\n");
- printf (" block <account name>\n");
- printf (" unblock <account name>\n");
- ladmin_log
- ("Invalid value for the state of an account ('state', 'block' or 'unblock' command).\n");
- }
+ PRINTF("Please input one of these states:\n");
+ PRINTF(" 0 = Account ok 6 = Your Game's EXE file is not the latest version\n");
+ PRINTF(" 1 = Unregistered ID 7 = You are Prohibited to log in until + message\n");
+ PRINTF(" 2 = Incorrect Password 8 = Server is jammed due to over populated\n");
+ PRINTF(" 3 = This ID is expired 9 = No MSG\n");
+ PRINTF(" 4 = Rejected from Server 100 = This ID has been totally erased\n");
+ PRINTF(" 5 = You have been blocked by the GM Team\n");
+ PRINTF("<examples> state testname 5\n");
+ PRINTF(" state testname 7 end of your ban\n");
+ PRINTF(" block <account name>\n");
+ PRINTF(" unblock <account name>\n");
+ LADMIN_LOG("Invalid value for the state of an account ('state', 'block' or 'unblock' command).\n");
return 151;
}
- if (verify_accountname (name) == 0)
+ if (verify_accountname(name) == 0)
{
return 102;
}
if (state != 7)
{
- strcpy (error_message, "-");
+ strcpy(error_message, "-");
}
else
{
- if (strlen (error_message) < 1)
+ if (strlen(error_message) < 1)
{
- if (defaultlanguage == 'F')
- {
- printf
- ("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 caractères.\n");
- }
- else
- {
- printf
- ("Error message is too short. Please input a message of 1-19 bytes.\n");
- ladmin_log
- ("Error message is too short. Please input a message of 1-19 bytes.\n");
- }
+ PRINTF("Error message is too short. Please input a message of 1-19 bytes.\n");
+ LADMIN_LOG("Error message is too short. Please input a message of 1-19 bytes.\n");
return 102;
}
- if (strlen (error_message) > 19)
+ if (strlen(error_message) > 19)
{
- if (defaultlanguage == 'F')
- {
- printf
- ("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 caractères.\n");
- }
- else
- {
- printf
- ("Error message is too long. Please input a message of 1-19 bytes.\n");
- ladmin_log
- ("Error message is too long. Please input a message of 1-19 bytes.\n");
- }
+ PRINTF("Error message is too long. Please input a message of 1-19 bytes.\n");
+ LADMIN_LOG("Error message is too long. Please input a message of 1-19 bytes.\n");
return 102;
}
}
- if (defaultlanguage == 'F')
- {
- ladmin_log
- ("Envoi d'un requête au serveur de logins pour changer un statut.\n");
- }
- else
- {
- ladmin_log ("Request to login-server to change a state.\n");
- }
+ LADMIN_LOG("Request to login-server to change a state.\n");
- WFIFOW (login_fd, 0) = 0x7936;
- memcpy (WFIFOP (login_fd, 2), name, 24);
- WFIFOL (login_fd, 26) = state;
- memcpy (WFIFOP (login_fd, 30), error_message, 20);
- WFIFOSET (login_fd, 50);
+ WFIFOW(login_fd, 0) = 0x7936;
+ memcpy(WFIFOP(login_fd, 2), name, 24);
+ WFIFOL(login_fd, 26) = state;
+ memcpy(WFIFOP(login_fd, 30), error_message, 20);
+ WFIFOSET(login_fd, 50);
bytes_to_read = 1;
return 0;
@@ -3499,181 +1983,124 @@ int changestatesub (const char *name, int state, const char *error_message7)
// Sub-function: Asking to modify the state of an account
//-------------------------------------------------------
static
-int changestate (const char *param)
+int changestate(const char *param)
{
char name[1023], error_message[1023];
- int state;
+ int state;
- memset (name, '\0', sizeof (name));
- memset (error_message, '\0', sizeof (error_message));
+ memset(name, '\0', sizeof(name));
+ memset(error_message, '\0', sizeof(error_message));
- if (sscanf (param, "\"%[^\"]\" %d %[^\r\n]", name, &state, error_message)
+ if (sscanf(param, "\"%[^\"]\" %d %[^\r\n]", name, &state, error_message)
< 2
- && sscanf (param, "'%[^']' %d %[^\r\n]", name, &state,
+ && sscanf(param, "'%[^']' %d %[^\r\n]", name, &state,
error_message) < 2
- && sscanf (param, "%s %d %[^\r\n]", name, &state, error_message) < 2)
- {
- if (defaultlanguage == 'F')
- {
- printf ("Entrez un nom de compte et un statut svp.\n");
- printf ("<exemples> state nomtest 5\n");
- printf (" state nomtest 7 fin de votre ban\n");
- printf (" block <nom compte>\n");
- printf (" unblock <nom compte>\n");
- ladmin_log
- ("Nombre incorrect de paramètres pour changer le statut d'un compte (commande 'state').\n");
- }
- else
- {
- printf ("Please input an account name and a state.\n");
- printf ("<examples> state testname 5\n");
- printf (" state testname 7 end of your ban\n");
- printf (" block <account name>\n");
- printf (" unblock <account name>\n");
- ladmin_log
- ("Incomplete parameters to change the state of an account ('state' command).\n");
- }
+ && sscanf(param, "%s %d %[^\r\n]", name, &state, error_message) < 2)
+ {
+ PRINTF("Please input an account name and a state.\n");
+ PRINTF("<examples> state testname 5\n");
+ PRINTF(" state testname 7 end of your ban\n");
+ PRINTF(" block <account name>\n");
+ PRINTF(" unblock <account name>\n");
+ LADMIN_LOG("Incomplete parameters to change the state of an account ('state' command).\n");
return 136;
}
- return changestatesub (name, state, error_message);
+ return changestatesub(name, state, error_message);
}
//-------------------------------------------
// Sub-function: Asking to unblock an account
//-------------------------------------------
static
-int unblockaccount (const char *param)
+int unblockaccount(const char *param)
{
char name[1023];
- memset (name, '\0', sizeof (name));
+ memset(name, '\0', sizeof(name));
- if (strlen (param) == 0 ||
- (sscanf (param, "\"%[^\"]\"", name) < 1 &&
- sscanf (param, "'%[^']'", name) < 1 &&
- sscanf (param, "%[^\r\n]", name) < 1) || strlen (name) == 0)
+ if (strlen(param) == 0 ||
+ (sscanf(param, "\"%[^\"]\"", name) < 1 &&
+ sscanf(param, "'%[^']'", name) < 1 &&
+ sscanf(param, "%[^\r\n]", name) < 1) || strlen(name) == 0)
{
- if (defaultlanguage == 'F')
- {
- printf ("Entrez un nom de compte svp.\n");
- printf ("<exemples> state nomtest 5\n");
- printf (" state nomtest 7 fin de votre ban\n");
- printf (" block <nom compte>\n");
- printf (" unblock <nom compte>\n");
- ladmin_log
- ("Nombre incorrect de paramètres pour changer le statut d'un compte (commande 'unblock').\n");
- }
- else
- {
- printf ("Please input an account name.\n");
- printf ("<examples> state testname 5\n");
- printf (" state testname 7 end of your ban\n");
- printf (" block <account name>\n");
- printf (" unblock <account name>\n");
- ladmin_log
- ("Incomplete parameters to change the state of an account ('unblock' command).\n");
- }
+ PRINTF("Please input an account name.\n");
+ PRINTF("<examples> state testname 5\n");
+ PRINTF(" state testname 7 end of your ban\n");
+ PRINTF(" block <account name>\n");
+ PRINTF(" unblock <account name>\n");
+ LADMIN_LOG("Incomplete parameters to change the state of an account ('unblock' command).\n");
return 136;
}
- return changestatesub (name, 0, "-"); // state 0, no error message
+ return changestatesub(name, 0, "-"); // state 0, no error message
}
//-------------------------------------------
// Sub-function: Asking to unblock an account
//-------------------------------------------
static
-int blockaccount (const char *param)
+int blockaccount(const char *param)
{
char name[1023];
- memset (name, '\0', sizeof (name));
+ memset(name, '\0', sizeof(name));
- if (strlen (param) == 0 ||
- (sscanf (param, "\"%[^\"]\"", name) < 1 &&
- sscanf (param, "'%[^']'", name) < 1 &&
- sscanf (param, "%[^\r\n]", name) < 1) || strlen (name) == 0)
+ if (strlen(param) == 0 ||
+ (sscanf(param, "\"%[^\"]\"", name) < 1 &&
+ sscanf(param, "'%[^']'", name) < 1 &&
+ sscanf(param, "%[^\r\n]", name) < 1) || strlen(name) == 0)
{
- if (defaultlanguage == 'F')
- {
- printf ("Entrez un nom de compte svp.\n");
- printf ("<exemples> state nomtest 5\n");
- printf (" state nomtest 7 fin de votre ban\n");
- printf (" block <nom compte>\n");
- printf (" unblock <nom compte>\n");
- ladmin_log
- ("Nombre incorrect de paramètres pour changer le statut d'un compte (commande 'block').\n");
- }
- else
- {
- printf ("Please input an account name.\n");
- printf ("<examples> state testname 5\n");
- printf (" state testname 7 end of your ban\n");
- printf (" block <account name>\n");
- printf (" unblock <account name>\n");
- ladmin_log
- ("Incomplete parameters to change the state of an account ('block' command).\n");
- }
+ PRINTF("Please input an account name.\n");
+ PRINTF("<examples> state testname 5\n");
+ PRINTF(" state testname 7 end of your ban\n");
+ PRINTF(" block <account name>\n");
+ PRINTF(" unblock <account name>\n");
+ LADMIN_LOG("Incomplete parameters to change the state of an account ('block' command).\n");
return 136;
}
- return changestatesub (name, 5, "-"); // state 5, no error message
+ return changestatesub(name, 5, "-"); // state 5, no error message
}
//---------------------------------------------------------------------
// Sub-function: Add/substract time to the validity limit of an account
//---------------------------------------------------------------------
static
-int timeaddaccount (const char *param)
+int timeaddaccount(const char *param)
{
char name[1023], modif[1023];
- int year, month, day, hour, minute, second;
+ int year, month, day, hour, minute, second;
const char *p_modif;
- int value, i;
+ int value, i;
- memset (name, '\0', sizeof (name));
- memset (modif, '\0', sizeof (modif));
+ memset(name, '\0', sizeof(name));
+ memset(modif, '\0', sizeof(modif));
year = month = day = hour = minute = second = 0;
- if (sscanf (param, "\"%[^\"]\" %[^\r\n]", name, modif) < 2 &&
- sscanf (param, "'%[^']' %[^\r\n]", name, modif) < 2 &&
- sscanf (param, "%s %[^\r\n]", name, modif) < 2)
+ if (sscanf(param, "\"%[^\"]\" %[^\r\n]", name, modif) < 2 &&
+ sscanf(param, "'%[^']' %[^\r\n]", name, modif) < 2 &&
+ sscanf(param, "%s %[^\r\n]", name, modif) < 2)
{
- if (defaultlanguage == 'F')
- {
- printf ("Entrez un nom de compte et un modificateur svp.\n");
- printf (" <exemple> 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 même temps.\n");
- ladmin_log
- ("Nombre incorrect de paramètres pour modifier une date limite d'utilisation (commande 'timeadd').\n");
- }
- else
- {
- printf ("Please input an account name and a modifier.\n");
- printf (" <example>: timeadd testname +1m-2mn1s-6y\n");
- printf
- (" this example adds 1 month and 1 second, and substracts 2 minutes\n");
- printf (" and 6 years at the same time.\n");
- ladmin_log
- ("Incomplete parameters to modify a limit time ('timeadd' command).\n");
- }
+ PRINTF("Please input an account name and a modifier.\n");
+ PRINTF(" <example>: timeadd testname +1m-2mn1s-6y\n");
+ PRINTF(" this example adds 1 month and 1 second, and substracts 2 minutes\n");
+ PRINTF(" and 6 years at the same time.\n");
+ LADMIN_LOG("Incomplete parameters to modify a limit time ('timeadd' command).\n");
return 136;
}
- if (verify_accountname (name) == 0)
+ if (verify_accountname(name) == 0)
{
return 102;
}
// lowercase for modif
for (i = 0; modif[i]; i++)
- modif[i] = tolower (modif[i]);
+ modif[i] = tolower(modif[i]);
p_modif = modif;
- while (strlen (p_modif) > 0)
+ while (strlen(p_modif) > 0)
{
- value = atoi (p_modif);
+ value = atoi(p_modif);
if (value == 0)
{
p_modif++;
@@ -3682,7 +2109,7 @@ int timeaddaccount (const char *param)
{
if (p_modif[0] == '-' || p_modif[0] == '+')
p_modif++;
- while (strlen (p_modif) > 0 && p_modif[0] >= '0'
+ while (strlen(p_modif) > 0 && p_modif[0] >= '0'
&& p_modif[0] <= '9')
{
p_modif++;
@@ -3724,193 +2151,79 @@ int timeaddaccount (const char *param)
}
}
- if (defaultlanguage == 'F')
- {
- printf (" année: %d\n", year);
- printf (" mois: %d\n", month);
- printf (" jour: %d\n", day);
- printf (" heure: %d\n", hour);
- printf (" minute: %d\n", minute);
- printf (" seconde: %d\n", second);
- }
- else
- {
- printf (" year: %d\n", year);
- printf (" month: %d\n", month);
- printf (" day: %d\n", day);
- printf (" hour: %d\n", hour);
- printf (" minute: %d\n", minute);
- printf (" second: %d\n", second);
- }
+ PRINTF(" year: %d\n", year);
+ PRINTF(" month: %d\n", month);
+ PRINTF(" day: %d\n", day);
+ PRINTF(" hour: %d\n", hour);
+ PRINTF(" minute: %d\n", minute);
+ PRINTF(" second: %d\n", second);
if (year == 0 && month == 0 && day == 0 && hour == 0 && minute == 0
&& second == 0)
{
- if (defaultlanguage == 'F')
- {
- printf
- ("Vous devez entrer un ajustement avec cette commande, svp:\n");
- printf (" Valeur d'ajustement (-1, 1, +1, etc...)\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");
- printf (" mn: minute\n");
- printf (" s: seconde\n");
- printf (" <exemple> 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 même temps.\n");
- ladmin_log
- ("Aucun ajustement n'est pas un ajustement (commande 'timeadd').\n");
- }
- else
- {
- printf ("Please give an adjustment with this command:\n");
- printf (" Adjustment value (-1, 1, +1, etc...)\n");
- printf (" Modified element:\n");
- printf (" a or y: year\n");
- printf (" m: month\n");
- printf (" j or d: day\n");
- printf (" h: hour\n");
- printf (" mn: minute\n");
- printf (" s: second\n");
- printf (" <example> timeadd testname +1m-2mn1s-6y\n");
- printf
- (" this example adds 1 month and 1 second, and substracts 2 minutes\n");
- printf (" and 6 years at the same time.\n");
- ladmin_log
- ("No adjustment isn't an adjustment ('timeadd' command).\n");
- }
+ PRINTF("Please give an adjustment with this command:\n");
+ PRINTF(" Adjustment value (-1, 1, +1, etc...)\n");
+ PRINTF(" Modified element:\n");
+ PRINTF(" a or y: year\n");
+ PRINTF(" m: month\n");
+ PRINTF(" j or d: day\n");
+ PRINTF(" h: hour\n");
+ PRINTF(" mn: minute\n");
+ PRINTF(" s: second\n");
+ PRINTF(" <example> timeadd testname +1m-2mn1s-6y\n");
+ PRINTF(" this example adds 1 month and 1 second, and substracts 2 minutes\n");
+ PRINTF(" and 6 years at the same time.\n");
+ LADMIN_LOG("No adjustment isn't an adjustment ('timeadd' command).\n");
return 137;
}
if (year > 127 || year < -127)
{
- if (defaultlanguage == 'F')
- {
- printf
- ("Entrez un ajustement d'années correct (de -127 à 127), svp.\n");
- ladmin_log
- ("Ajustement de l'année hors norme ('timeadd' command).\n");
- }
- else
- {
- printf
- ("Please give a correct adjustment for the years (from -127 to 127).\n");
- ladmin_log
- ("Abnormal adjustement for the year ('timeadd' command).\n");
- }
+ PRINTF("Please give a correct adjustment for the years (from -127 to 127).\n");
+ LADMIN_LOG("Abnormal adjustement for the year ('timeadd' command).\n");
return 137;
}
if (month > 255 || month < -255)
{
- if (defaultlanguage == 'F')
- {
- printf
- ("Entrez un ajustement de mois correct (de -255 à 255), svp.\n");
- ladmin_log ("Ajustement du mois hors norme ('timeadd' command).\n");
- }
- else
- {
- printf
- ("Please give a correct adjustment for the months (from -255 to 255).\n");
- ladmin_log
- ("Abnormal adjustement for the month ('timeadd' command).\n");
- }
+ PRINTF("Please give a correct adjustment for the months (from -255 to 255).\n");
+ LADMIN_LOG("Abnormal adjustement for the month ('timeadd' command).\n");
return 137;
}
if (day > 32767 || day < -32767)
{
- if (defaultlanguage == 'F')
- {
- printf
- ("Entrez un ajustement de jours correct (de -32767 à 32767), svp.\n");
- ladmin_log ("Ajustement des jours hors norme ('timeadd' command).\n");
- }
- else
- {
- printf
- ("Please give a correct adjustment for the days (from -32767 to 32767).\n");
- ladmin_log
- ("Abnormal adjustement for the days ('timeadd' command).\n");
- }
+ PRINTF("Please give a correct adjustment for the days (from -32767 to 32767).\n");
+ LADMIN_LOG("Abnormal adjustement for the days ('timeadd' command).\n");
return 137;
}
if (hour > 32767 || hour < -32767)
{
- if (defaultlanguage == 'F')
- {
- printf
- ("Entrez un ajustement d'heures correct (de -32767 à 32767), svp.\n");
- ladmin_log
- ("Ajustement des heures hors norme ('timeadd' command).\n");
- }
- else
- {
- printf
- ("Please give a correct adjustment for the hours (from -32767 to 32767).\n");
- ladmin_log
- ("Abnormal adjustement for the hours ('timeadd' command).\n");
- }
+ PRINTF("Please give a correct adjustment for the hours (from -32767 to 32767).\n");
+ LADMIN_LOG("Abnormal adjustement for the hours ('timeadd' command).\n");
return 137;
}
if (minute > 32767 || minute < -32767)
{
- if (defaultlanguage == 'F')
- {
- printf
- ("Entrez un ajustement de minutes correct (de -32767 à 32767), svp.\n");
- ladmin_log
- ("Ajustement des minutes hors norme ('timeadd' command).\n");
- }
- else
- {
- printf
- ("Please give a correct adjustment for the minutes (from -32767 to 32767).\n");
- ladmin_log
- ("Abnormal adjustement for the minutes ('timeadd' command).\n");
- }
+ PRINTF("Please give a correct adjustment for the minutes (from -32767 to 32767).\n");
+ LADMIN_LOG("Abnormal adjustement for the minutes ('timeadd' command).\n");
return 137;
}
if (second > 32767 || second < -32767)
{
- if (defaultlanguage == 'F')
- {
- printf
- ("Entrez un ajustement de secondes correct (de -32767 à 32767), svp.\n");
- ladmin_log
- ("Ajustement des secondes hors norme ('timeadd' command).\n");
- }
- else
- {
- printf
- ("Please give a correct adjustment for the seconds (from -32767 to 32767).\n");
- ladmin_log
- ("Abnormal adjustement for the seconds ('timeadd' command).\n");
- }
+ PRINTF("Please give a correct adjustment for the seconds (from -32767 to 32767).\n");
+ LADMIN_LOG("Abnormal adjustement for the seconds ('timeadd' command).\n");
return 137;
}
- if (defaultlanguage == 'F')
- {
- ladmin_log
- ("Envoi d'un requête au serveur de logins pour modifier une date limite d'utilisation.\n");
- }
- else
- {
- ladmin_log ("Request to login-server to modify a time limit.\n");
- }
-
- WFIFOW (login_fd, 0) = 0x7950;
- memcpy (WFIFOP (login_fd, 2), name, 24);
- WFIFOW (login_fd, 26) = (short) year;
- WFIFOW (login_fd, 28) = (short) month;
- WFIFOW (login_fd, 30) = (short) day;
- WFIFOW (login_fd, 32) = (short) hour;
- WFIFOW (login_fd, 34) = (short) minute;
- WFIFOW (login_fd, 36) = (short) second;
- WFIFOSET (login_fd, 38);
+ LADMIN_LOG("Request to login-server to modify a time limit.\n");
+
+ WFIFOW(login_fd, 0) = 0x7950;
+ memcpy(WFIFOP(login_fd, 2), name, 24);
+ WFIFOW(login_fd, 26) = (short) year;
+ WFIFOW(login_fd, 28) = (short) month;
+ WFIFOW(login_fd, 30) = (short) day;
+ WFIFOW(login_fd, 32) = (short) hour;
+ WFIFOW(login_fd, 34) = (short) minute;
+ WFIFOW(login_fd, 36) = (short) second;
+ WFIFOSET(login_fd, 38);
bytes_to_read = 1;
return 0;
@@ -3920,83 +2233,54 @@ int timeaddaccount (const char *param)
// Sub-function: Set a validity limit of an account
//-------------------------------------------------
static
-int timesetaccount (const char *param)
+int timesetaccount(const char *param)
{
- char name[1023], date[1023], time[1023];
- int year, month, day, hour, minute, second;
- time_t connect_until_time; // # of seconds 1/1/1970 (timestamp): Validity limit of the account (0 = unlimited)
- struct tm *tmtime;
-
- memset (name, '\0', sizeof (name));
- memset (date, '\0', sizeof (date));
- memset (time, '\0', sizeof (time));
+ char name[1023], date[1023], time_[1023];
+ int year, month, day, hour, minute, second;
+
+ memset(name, '\0', sizeof(name));
+ memset(date, '\0', sizeof(date));
+ memset(time_, '\0', sizeof(time_));
year = month = day = hour = minute = second = 0;
- connect_until_time = 0;
- tmtime = localtime (&connect_until_time); // initialize
-
- if (sscanf (param, "\"%[^\"]\" %s %[^\r\n]", name, date, time) < 2 && // if date = 0, time can be void
- sscanf (param, "'%[^']' %s %[^\r\n]", name, date, time) < 2 && // if date = 0, time can be void
- sscanf (param, "%s %s %[^\r\n]", name, date, time) < 2)
- { // if date = 0, time can be void
- if (defaultlanguage == 'F')
- {
- printf ("Entrez un nom de compte, une date et une heure svp.\n");
- printf
- ("<exemple>: timeset <nom_du_compte> aaaa/mm/jj [hh:mm:ss]\n");
- printf
- (" timeset <nom_du_compte> 0 (0 = illimité)\n");
- printf (" Heure par défaut [hh:mm:ss]: 23:59:59.\n");
- ladmin_log
- ("Nombre incorrect de paramètres pour fixer une date limite d'utilisation (commande 'timeset').\n");
- }
- else
- {
- printf ("Please input an account name, a date and a hour.\n");
- printf
- ("<example>: timeset <account_name> yyyy/mm/dd [hh:mm:ss]\n");
- printf
- (" timeset <account_name> 0 (0 = unlimited)\n");
- printf (" Default time [hh:mm:ss]: 23:59:59.\n");
- ladmin_log
- ("Incomplete parameters to set a limit time ('timeset' command).\n");
- }
+
+ // # of seconds 1/1/1970 (timestamp): Validity limit of the account (0 = unlimited)
+ TimeT connect_until_time = TimeT();
+ struct tm tmtime = connect_until_time; // initialize
+
+ if (sscanf(param, "\"%[^\"]\" %s %[^\r\n]", name, date, time_) < 2 && // if date = 0, time_ can be void
+ sscanf(param, "'%[^']' %s %[^\r\n]", name, date, time_) < 2 && // if date = 0, time_ can be void
+ sscanf(param, "%s %s %[^\r\n]", name, date, time_) < 2)
+ { // if date = 0, time_ can be void
+ PRINTF("Please input an account name, a date and a hour.\n");
+ PRINTF("<example>: timeset <account_name> yyyy/mm/dd [hh:mm:ss]\n");
+ PRINTF(" timeset <account_name> 0 (0 = unlimited)\n");
+ PRINTF(" Default time [hh:mm:ss]: 23:59:59.\n");
+ LADMIN_LOG("Incomplete parameters to set a limit time ('timeset' command).\n");
return 136;
}
- if (verify_accountname (name) == 0)
+ if (verify_accountname(name) == 0)
{
return 102;
}
- if (time[0] == '\0')
- strcpy (time, "23:59:59");
+ if (time_[0] == '\0')
+ strcpy(time_, "23:59:59");
- if (atoi (date) != 0 &&
- ((sscanf (date, "%d/%d/%d", &year, &month, &day) < 3 &&
- sscanf (date, "%d-%d-%d", &year, &month, &day) < 3 &&
- sscanf (date, "%d.%d.%d", &year, &month, &day) < 3 &&
- sscanf (date, "%d'%d'%d", &year, &month, &day) < 3) ||
- sscanf (time, "%d:%d:%d", &hour, &minute, &second) < 3))
+ if (atoi(date) != 0 &&
+ ((sscanf(date, "%d/%d/%d", &year, &month, &day) < 3 &&
+ sscanf(date, "%d-%d-%d", &year, &month, &day) < 3 &&
+ sscanf(date, "%d.%d.%d", &year, &month, &day) < 3 &&
+ sscanf(date, "%d'%d'%d", &year, &month, &day) < 3) ||
+ sscanf(time_, "%d:%d:%d", &hour, &minute, &second) < 3))
{
- if (defaultlanguage == 'F')
- {
- printf
- ("Entrez 0 ou une date et une heure svp (format: 0 ou aaaa/mm/jj hh:mm:ss).\n");
- ladmin_log
- ("Format incorrect pour la date/heure ('timeset' command).\n");
- }
- else
- {
- printf
- ("Please input 0 or a date and a time (format: 0 or yyyy/mm/dd hh:mm:ss).\n");
- ladmin_log
- ("Invalid format for the date/time ('timeset' command).\n");
- }
+ PRINTF("Please input 0 or a date and a time (format: 0 or yyyy/mm/dd hh:mm:ss).\n");
+ LADMIN_LOG("Invalid format for the date/time ('timeset' command).\n");
return 102;
}
- if (atoi (date) == 0)
+ if (atoi(date) == 0)
{
- connect_until_time = 0;
+ connect_until_time = TimeT();
}
else
{
@@ -4010,147 +2294,66 @@ int timesetaccount (const char *param)
}
if (month < 1 || month > 12)
{
- if (defaultlanguage == 'F')
- {
- printf ("Entrez un mois correct svp (entre 1 et 12).\n");
- ladmin_log ("Mois incorrect pour la date ('timeset' command).\n");
- }
- else
- {
- printf
- ("Please give a correct value for the month (from 1 to 12).\n");
- ladmin_log ("Invalid month for the date ('timeset' command).\n");
- }
+ PRINTF("Please give a correct value for the month (from 1 to 12).\n");
+ LADMIN_LOG("Invalid month for the date ('timeset' command).\n");
return 102;
}
month = month - 1;
if (day < 1 || day > 31)
{
- if (defaultlanguage == 'F')
- {
- printf ("Entrez un jour correct svp (entre 1 et 31).\n");
- ladmin_log ("Jour incorrect pour la date ('timeset' command).\n");
- }
- else
- {
- printf
- ("Please give a correct value for the day (from 1 to 31).\n");
- ladmin_log ("Invalid day for the date ('timeset' command).\n");
- }
+ PRINTF("Please give a correct value for the day (from 1 to 31).\n");
+ LADMIN_LOG("Invalid day for the date ('timeset' command).\n");
return 102;
}
if (((month == 3 || month == 5 || month == 8 || month == 10)
- && day > 30) || (month == 1 && day > 29))
+ && day > 30) ||(month == 1 && day > 29))
{
- if (defaultlanguage == 'F')
- {
- printf
- ("Entrez un jour correct en fonction du mois (%d) svp.\n",
- month);
- ladmin_log
- ("Jour incorrect pour ce mois correspondant ('timeset' command).\n");
- }
- else
- {
- printf
- ("Please give a correct value for a day of this month (%d).\n",
- month);
- ladmin_log ("Invalid day for this month ('timeset' command).\n");
- }
+ PRINTF("Please give a correct value for a day of this month (%d).\n",
+ month);
+ LADMIN_LOG("Invalid day for this month ('timeset' command).\n");
return 102;
}
if (hour < 0 || hour > 23)
{
- if (defaultlanguage == 'F')
- {
- printf ("Entrez une heure correcte svp (entre 0 et 23).\n");
- ladmin_log
- ("Heure incorrecte pour l'heure ('timeset' command).\n");
- }
- else
- {
- printf
- ("Please give a correct value for the hour (from 0 to 23).\n");
- ladmin_log ("Invalid hour for the time ('timeset' command).\n");
- }
+ PRINTF("Please give a correct value for the hour (from 0 to 23).\n");
+ LADMIN_LOG("Invalid hour for the time ('timeset' command).\n");
return 102;
}
if (minute < 0 || minute > 59)
{
- if (defaultlanguage == 'F')
- {
- printf
- ("Entrez des minutes correctes svp (entre 0 et 59).\n");
- ladmin_log
- ("Minute incorrecte pour l'heure ('timeset' command).\n");
- }
- else
- {
- printf
- ("Please give a correct value for the minutes (from 0 to 59).\n");
- ladmin_log ("Invalid minute for the time ('timeset' command).\n");
- }
+ PRINTF("Please give a correct value for the minutes (from 0 to 59).\n");
+ LADMIN_LOG("Invalid minute for the time ('timeset' command).\n");
return 102;
}
if (second < 0 || second > 59)
{
- if (defaultlanguage == 'F')
- {
- printf
- ("Entrez des secondes correctes svp (entre 0 et 59).\n");
- ladmin_log
- ("Seconde incorrecte pour l'heure ('timeset' command).\n");
- }
- else
- {
- printf
- ("Please give a correct value for the seconds (from 0 to 59).\n");
- ladmin_log ("Invalid second for the time ('timeset' command).\n");
- }
+ PRINTF("Please give a correct value for the seconds (from 0 to 59).\n");
+ LADMIN_LOG("Invalid second for the time ('timeset' command).\n");
return 102;
}
- tmtime->tm_year = year;
- tmtime->tm_mon = month;
- tmtime->tm_mday = day;
- tmtime->tm_hour = hour;
- tmtime->tm_min = minute;
- tmtime->tm_sec = second;
- tmtime->tm_isdst = -1; // -1: no winter/summer time modification
- connect_until_time = timegm (tmtime);
- if (connect_until_time == -1)
- {
- if (defaultlanguage == 'F')
- {
- printf ("Date incorrecte.\n");
- printf
- ("Ajoutez 0 ou une date et une heure svp (format: 0 ou aaaa/mm/jj hh:mm:ss).\n");
- ladmin_log ("Date incorrecte. ('timeset' command).\n");
- }
- else
- {
- printf ("Invalid date.\n");
- printf
- ("Please add 0 or a date and a time (format: 0 or yyyy/mm/dd hh:mm:ss).\n");
- ladmin_log ("Invalid date. ('timeset' command).\n");
- }
+ tmtime.tm_year = year;
+ tmtime.tm_mon = month;
+ tmtime.tm_mday = day;
+ tmtime.tm_hour = hour;
+ tmtime.tm_min = minute;
+ tmtime.tm_sec = second;
+ tmtime.tm_isdst = -1; // -1: no winter/summer time modification
+ connect_until_time = tmtime;
+ if (connect_until_time.error())
+ {
+ PRINTF("Invalid date.\n");
+ PRINTF("Please add 0 or a date and a time (format: 0 or yyyy/mm/dd hh:mm:ss).\n");
+ LADMIN_LOG("Invalid date. ('timeset' command).\n");
return 102;
}
}
- if (defaultlanguage == 'F')
- {
- ladmin_log
- ("Envoi d'un requête au serveur de logins pour fixer une date limite d'utilisation.\n");
- }
- else
- {
- ladmin_log ("Request to login-server to set a time limit.\n");
- }
+ LADMIN_LOG("Request to login-server to set a time limit.\n");
- WFIFOW (login_fd, 0) = 0x7948;
- memcpy (WFIFOP (login_fd, 2), name, 24);
- WFIFOL (login_fd, 26) = (int) connect_until_time;
- WFIFOSET (login_fd, 30);
+ WFIFOW(login_fd, 0) = 0x7948;
+ memcpy(WFIFOP(login_fd, 2), name, 24);
+ WFIFOL(login_fd, 26) = static_cast<time_t>(connect_until_time);
+ WFIFOSET(login_fd, 30);
bytes_to_read = 1;
return 0;
@@ -4160,50 +2363,32 @@ int timesetaccount (const char *param)
// Sub-function: Asking to displaying information about an account (by its name)
//------------------------------------------------------------------------------
static
-int whoaccount (const char *param)
+int whoaccount(const char *param)
{
char name[1023];
- memset (name, '\0', sizeof (name));
+ memset(name, '\0', sizeof(name));
- if (strlen (param) == 0 ||
- (sscanf (param, "\"%[^\"]\"", name) < 1 &&
- sscanf (param, "'%[^']'", name) < 1 &&
- sscanf (param, "%[^\r\n]", name) < 1) || strlen (name) == 0)
+ if (strlen(param) == 0 ||
+ (sscanf(param, "\"%[^\"]\"", name) < 1 &&
+ sscanf(param, "'%[^']'", name) < 1 &&
+ sscanf(param, "%[^\r\n]", name) < 1) || strlen(name) == 0)
{
- if (defaultlanguage == 'F')
- {
- printf ("Entrez un nom de compte svp.\n");
- printf ("<exemple> who nomtest\n");
- ladmin_log ("Aucun nom n'a été donné pour trouver le compte.\n");
- }
- else
- {
- printf ("Please input an account name.\n");
- printf ("<example> who testname\n");
- ladmin_log ("No name was given to found the account.\n");
- }
+ PRINTF("Please input an account name.\n");
+ PRINTF("<example> who testname\n");
+ LADMIN_LOG("No name was given to found the account.\n");
return 136;
}
- if (verify_accountname (name) == 0)
+ if (verify_accountname(name) == 0)
{
return 102;
}
- if (defaultlanguage == 'F')
- {
- ladmin_log
- ("Envoi d'un requête au serveur de logins pour obtenir le information d'un compte (par le nom).\n");
- }
- else
- {
- ladmin_log
- ("Request to login-server to obtain information about an account (by its name).\n");
- }
+ LADMIN_LOG("Request to login-server to obtain information about an account (by its name).\n");
- WFIFOW (login_fd, 0) = 0x7952;
- memcpy (WFIFOP (login_fd, 2), name, 24);
- WFIFOSET (login_fd, 26);
+ WFIFOW(login_fd, 0) = 0x7952;
+ memcpy(WFIFOP(login_fd, 2), name, 24);
+ WFIFOSET(login_fd, 26);
bytes_to_read = 1;
return 0;
@@ -4213,16 +2398,12 @@ int whoaccount (const char *param)
// Sub-function: Asking of the version of the login-server
//--------------------------------------------------------
static
-int checkloginversion (void)
+int checkloginversion(void)
{
- if (defaultlanguage == 'F')
- ladmin_log
- ("Envoi d'un requête au serveur de logins pour obtenir sa version.\n");
- else
- ladmin_log ("Request to login-server to obtain its version.\n");
+ LADMIN_LOG("Request to login-server to obtain its version.\n");
- WFIFOW (login_fd, 0) = 0x7530;
- WFIFOSET (login_fd, 2);
+ WFIFOW(login_fd, 0) = 0x7530;
+ WFIFOSET(login_fd, 2);
bytes_to_read = 1;
return 0;
@@ -4234,9 +2415,9 @@ int checkloginversion (void)
// and analyse the command.
//---------------------------------------------
static
-int prompt (void)
+int prompt(void)
{
- int i, j;
+ int i, j;
char buf[1024];
char *p;
@@ -4244,74 +2425,69 @@ int prompt (void)
while (bytes_to_read == 0)
{
// for help with the console colors look here:
- // http://www.edoceo.com/liberum/?doc=printf-with-color
+ // 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
- Iprintf ("\n");
- if (defaultlanguage == 'F')
- {
- Iprintf
- ("\033[32mPour afficher les commandes, tapez 'Entrée'.\033[0m\n");
- }
- else
- Iprintf ("\033[32mTo list the commands, type 'enter'.\033[0m\n");
- Iprintf ("\033[0;36mLadmin-> \033[0m");
- Iprintf ("\033[1m");
- fflush (stdout);
+ Iprintf("\n");
+ Iprintf("\033[32mTo list the commands, type 'enter'.\033[0m\n");
+ Iprintf("\033[0;36mLadmin-> \033[0m");
+ Iprintf("\033[1m");
+ fflush(stdout);
// get command and parameter
- memset (buf, '\0', sizeof (buf));
- fflush (stdin);
- if (!fgets (buf, 1023, stdin))
- exit (0);
+ memset(buf, '\0', sizeof(buf));
+ fflush(stdin);
+ if (!fgets(buf, 1023, stdin))
+ exit(0);
buf[1023] = '\0';
- Iprintf ("\033[0m");
- fflush (stdout);
+ Iprintf("\033[0m");
+ fflush(stdout);
- if (!eathena_interactive_session && !strlen (buf))
- exit (0);
+ if (!eathena_interactive_session && !strlen(buf))
+ exit(0);
// remove final \n
- if ((p = strrchr (buf, '\n')) != NULL)
+ if ((p = strrchr(buf, '\n')) != NULL)
p[0] = '\0';
// remove all control char
for (i = 0; buf[i]; i++)
if (buf[i] < 32)
{
// remove cursor control.
- if (buf[i] == 27 && buf[i + 1] == '[' && (buf[i + 2] == 'H' || // home position (cursor)
- buf[i + 2] == 'J' || // clear screen
- buf[i + 2] == 'A' || // up 1 line
- buf[i + 2] == 'B' || // down 1 line
- buf[i + 2] == 'C' || // right 1 position
- buf[i + 2] == 'D' || // left 1 position
- buf[i + 2] == 'G'))
- { // center cursor (windows)
+ if (buf[i] == 27
+ && buf[i + 1] == '['
+ && (buf[i + 2] == 'H' // home position (cursor)
+ || buf[i + 2] == 'J' // clear screen
+ || buf[i + 2] == 'A' // up 1 line
+ || buf[i + 2] == 'B' // down 1 line
+ || buf[i + 2] == 'C' // right 1 position
+ || buf[i + 2] == 'D' // left 1 position
+ || buf[i + 2] == 'G')) // center cursor (windows)
+ {
for (j = i; buf[j]; j++)
buf[j] = buf[j + 3];
}
else if (buf[i] == 27 && buf[i + 1] == '['
&& buf[i + 2] == '2' && buf[i + 3] == 'J')
- { // clear screen
+ {
+ // clear screen
for (j = i; buf[j]; j++)
buf[j] = buf[j + 4];
}
- else if (buf[i] == 27 && buf[i + 1] == '[' && buf[i + 3] == '~' && (buf[i + 2] == '1' || // home (windows)
- buf[i + 2] == '2' || // insert (windows)
- buf[i + 2] == '3' || // del (windows)
- buf[i + 2] == '4' || // end (windows)
- buf[i + 2] == '5' || // pgup (windows)
- buf
- [i
- +
- 2]
- ==
- '6'))
- { // pgdown (windows)
+ else if (buf[i] == 27
+ && buf[i + 1] == '['
+ && buf[i + 3] == '~'
+ && (buf[i + 2] == '1' // home (windows)
+ || buf[i + 2] == '2' // insert (windows)
+ || buf[i + 2] == '3' // del (windows)
+ || buf[i + 2] == '4' // end (windows)
+ || buf[i + 2] == '5' // pgup (windows)
+ || buf[i + 2] == '6')) // pgdown (windows)
+ {
for (j = i; buf[j]; j++)
buf[j] = buf[j + 4];
}
@@ -4324,236 +2500,190 @@ int prompt (void)
i--;
}
+ char command[1024];
// extract command name and parameters
- memset (command, '\0', sizeof (command));
- memset (parameters, '\0', sizeof (parameters));
- sscanf (buf, "%1023s %[^\n]", command, parameters);
+ memset(command, '\0', sizeof(command));
+ memset(parameters, '\0', sizeof(parameters));
+ sscanf(buf, "%1023s %[^\n]", command, parameters);
command[1023] = '\0';
parameters[1023] = '\0';
// lowercase for command line
for (i = 0; command[i]; i++)
- command[i] = tolower (command[i]);
+ command[i] = tolower(command[i]);
- if (command[0] == '?' || strlen (command) == 0)
+ if (command[0] == '?' || strlen(command) == 0)
{
- if (defaultlanguage == 'F')
- {
- strcpy (buf, "aide");
- strcpy (command, "aide");
- }
- else
- {
- strcpy (buf, "help");
- strcpy (command, "help");
- }
+ strcpy(buf, "help");
+ strcpy(command, "help");
}
// Analyse of the command
- check_command (command); // give complete name to the command
+ check_command(command); // give complete name to the command
- if (strlen (parameters) == 0)
+ if (strlen(parameters) == 0)
{
- if (defaultlanguage == 'F')
- {
- ladmin_log ("Commande: '%s' (sans paramètre)\n",
- command, parameters);
- }
- else
- {
- ladmin_log ("Command: '%s' (without parameters)\n",
- command, parameters);
- }
+ LADMIN_LOG("Command: '%s' (without parameters)\n",
+ command);
}
else
{
- if (defaultlanguage == 'F')
- {
- ladmin_log ("Commande: '%s', paramètres: '%s'\n",
- command, parameters);
- }
- else
- {
- ladmin_log ("Command: '%s', parameters: '%s'\n",
- command, parameters);
- }
+ LADMIN_LOG("Command: '%s', parameters: '%s'\n",
+ command, parameters);
}
// Analyse of the command
// help
- if (strcmp (command, "aide") == 0)
- {
- display_help (parameters, 1); // 1: french
- }
- else if (strcmp (command, "help") == 0)
+ if (strcmp(command, "help") == 0)
{
- display_help (parameters, 0); // 0: english
+ display_help(parameters);
// general commands
}
- else if (strcmp (command, "add") == 0)
- {
- addaccount (parameters, 0); // 0: no email
- }
- else if (strcmp (command, "ban") == 0)
+ else if (strcmp(command, "add") == 0)
{
- banaccount (parameters);
+ addaccount(parameters, 0); // 0: no email
}
- else if (strcmp (command, "banadd") == 0)
+ else if (strcmp(command, "ban") == 0)
{
- banaddaccount (parameters);
+ banaccount(parameters);
}
- else if (strcmp (command, "banset") == 0)
+ else if (strcmp(command, "banadd") == 0)
{
- bansetaccount (parameters);
+ banaddaccount(parameters);
}
- else if (strcmp (command, "block") == 0)
+ else if (strcmp(command, "banset") == 0)
{
- blockaccount (parameters);
+ bansetaccount(parameters);
}
- else if (strcmp (command, "check") == 0)
+ else if (strcmp(command, "block") == 0)
{
- checkaccount (parameters);
+ blockaccount(parameters);
}
- else if (strcmp (command, "create") == 0)
+ else if (strcmp(command, "check") == 0)
{
- addaccount (parameters, 1); // 1: with email
+ checkaccount(parameters);
}
- else if (strcmp (command, "delete") == 0)
+ else if (strcmp(command, "create") == 0)
{
- delaccount (parameters);
+ addaccount(parameters, 1); // 1: with email
}
- else if (strcmp (command, "email") == 0)
+ else if (strcmp(command, "delete") == 0)
{
- changeemail (parameters);
+ delaccount(parameters);
}
- else if (strcmp (command, "getcount") == 0)
+ else if (strcmp(command, "email") == 0)
{
- getlogincount ();
+ changeemail(parameters);
}
- else if (strcmp (command, "gm") == 0)
+ else if (strcmp(command, "getcount") == 0)
{
- changegmlevel (parameters);
+ getlogincount();
}
- else if (strcmp (command, "id") == 0)
+ else if (strcmp(command, "gm") == 0)
{
- idaccount (parameters);
+ changegmlevel(parameters);
}
- else if (strcmp (command, "info") == 0)
+ else if (strcmp(command, "id") == 0)
{
- infoaccount (atoi (parameters));
+ idaccount(parameters);
}
- else if (strcmp (command, "kami") == 0)
+ else if (strcmp(command, "info") == 0)
{
- sendbroadcast (0, parameters); // flag for normal
+ infoaccount(atoi(parameters));
}
- else if (strcmp (command, "kamib") == 0)
+ else if (strcmp(command, "kami") == 0)
{
- sendbroadcast (0x10, parameters); // flag for blue
+ sendbroadcast(0, parameters); // flag for normal
}
- else if (strcmp (command, "language") == 0)
+ else if (strcmp(command, "kamib") == 0)
{
- changelanguage (parameters);
+ sendbroadcast(0x10, parameters); // flag for blue
}
- else if (strcmp (command, "itemfrob") == 0)
+ else if (strcmp(command, "itemfrob") == 0)
{
- itemfrob (parameters); // 0: to list all
+ itemfrob(parameters); // 0: to list all
}
- else if (strcmp (command, "list") == 0)
+ else if (strcmp(command, "list") == 0)
{
- listaccount (parameters, 0); // 0: to list all
+ listaccount(parameters, 0); // 0: to list all
}
- else if (strcmp (command, "listban") == 0)
+ else if (strcmp(command, "listban") == 0)
{
- listaccount (parameters, 3); // 3: to list only accounts with state or bannished
+ listaccount(parameters, 3); // 3: to list only accounts with state or bannished
}
- else if (strcmp (command, "listgm") == 0)
+ else if (strcmp(command, "listgm") == 0)
{
- listaccount (parameters, 1); // 1: to list only GM
+ listaccount(parameters, 1); // 1: to list only GM
}
- else if (strcmp (command, "listok") == 0)
+ else if (strcmp(command, "listok") == 0)
{
- listaccount (parameters, 4); // 4: to list only accounts without state and not bannished
+ listaccount(parameters, 4); // 4: to list only accounts without state and not bannished
}
- else if (strcmp (command, "memo") == 0)
+ else if (strcmp(command, "memo") == 0)
{
- changememo (parameters);
+ changememo(parameters);
}
- else if (strcmp (command, "name") == 0)
+ else if (strcmp(command, "name") == 0)
{
- nameaccount (atoi (parameters));
+ nameaccount(atoi(parameters));
}
- else if (strcmp (command, "password") == 0)
+ else if (strcmp(command, "password") == 0)
{
- changepasswd (parameters);
+ changepasswd(parameters);
}
- else if (strcmp (command, "reloadgm") == 0)
+ else if (strcmp(command, "reloadgm") == 0)
{
- reloadGM ();
+ reloadGM(parameters);
}
- else if (strcmp (command, "search") == 0)
+ else if (strcmp(command, "search") == 0)
{ // no regex in C version
- listaccount (parameters, 2); // 2: to list with pattern
+ listaccount(parameters, 2); // 2: to list with pattern
}
- else if (strcmp (command, "sex") == 0)
+ else if (strcmp(command, "sex") == 0)
{
- changesex (parameters);
+ changesex(parameters);
}
- else if (strcmp (command, "state") == 0)
+ else if (strcmp(command, "state") == 0)
{
- changestate (parameters);
+ changestate(parameters);
}
- else if (strcmp (command, "timeadd") == 0)
+ else if (strcmp(command, "timeadd") == 0)
{
- timeaddaccount (parameters);
+ timeaddaccount(parameters);
}
- else if (strcmp (command, "timeset") == 0)
+ else if (strcmp(command, "timeset") == 0)
{
- timesetaccount (parameters);
+ timesetaccount(parameters);
}
- else if (strcmp (command, "unban") == 0)
+ else if (strcmp(command, "unban") == 0)
{
- unbanaccount (parameters);
+ unbanaccount(parameters);
}
- else if (strcmp (command, "unblock") == 0)
+ else if (strcmp(command, "unblock") == 0)
{
- unblockaccount (parameters);
+ unblockaccount(parameters);
}
- else if (strcmp (command, "version") == 0)
+ else if (strcmp(command, "version") == 0)
{
- checkloginversion ();
+ checkloginversion();
}
- else if (strcmp (command, "who") == 0)
+ else if (strcmp(command, "who") == 0)
{
- whoaccount (parameters);
+ whoaccount(parameters);
// quit
}
- else if (strcmp (command, "quit") == 0 ||
- strcmp (command, "exit") == 0 ||
- strcmp (command, "end") == 0)
+ else if (strcmp(command, "quit") == 0 ||
+ strcmp(command, "exit") == 0 ||
+ strcmp(command, "end") == 0)
{
- if (defaultlanguage == 'F')
- {
- printf ("Au revoir.\n");
- }
- else
- {
- printf ("Bye.\n");
- }
- exit (0);
+ PRINTF("Bye.\n");
+ exit(0);
// unknown command
}
else
{
- if (defaultlanguage == 'F')
- {
- printf ("Commande inconnue [%s].\n", buf);
- ladmin_log ("Commande inconnue [%s].\n", buf);
- }
- else
- {
- printf ("Unknown command [%s].\n", buf);
- ladmin_log ("Unknown command [%s].\n", buf);
- }
+ PRINTF("Unknown command [%s].\n", buf);
+ LADMIN_LOG("Unknown command [%s].\n", buf);
}
}
@@ -4564,1646 +2694,870 @@ int prompt (void)
// Function: Parse receiving informations from the login-server
//-------------------------------------------------------------
static
-void parse_fromlogin (int fd)
+void parse_fromlogin(int fd)
{
- struct char_session_data *sd;
-
if (session[fd]->eof)
{
- if (defaultlanguage == 'F')
- {
- printf
- ("Impossible de se connecter au serveur de login [%s:%d] !\n",
- loginserverip, loginserverport);
- ladmin_log
- ("Impossible de se connecter au serveur de login [%s:%d] !\n",
- loginserverip, loginserverport);
- }
- else
- {
- printf
- ("Impossible to have a connection with the login-server [%s:%d] !\n",
- loginserverip, loginserverport);
- ladmin_log
- ("Impossible to have a connection with the login-server [%s:%d] !\n",
- loginserverip, loginserverport);
- }
- close (fd);
- delete_session (fd);
- exit (0);
+ PRINTF("Impossible to have a connection with the login-server [%s:%d] !\n",
+ loginserverip, loginserverport);
+ LADMIN_LOG("Impossible to have a connection with the login-server [%s:%d] !\n",
+ loginserverip, loginserverport);
+ delete_session(fd);
+ exit(0);
}
-// printf("parse_fromlogin : %d %d %d\n", fd, RFIFOREST(fd), RFIFOW(fd,0));
- sd = (struct char_session_data *)session[fd]->session_data;
+// PRINTF("parse_fromlogin : %d %d %d\n", fd, RFIFOREST(fd), RFIFOW(fd,0));
- while (RFIFOREST (fd) >= 2)
+ while (RFIFOREST(fd) >= 2)
{
- switch (RFIFOW (fd, 0))
+ switch (RFIFOW(fd, 0))
{
case 0x7919: // answer of a connection request
- if (RFIFOREST (fd) < 3)
+ if (RFIFOREST(fd) < 3)
return;
- if (RFIFOB (fd, 2) != 0)
+ if (RFIFOB(fd, 2) != 0)
{
- if (defaultlanguage == 'F')
- {
- printf ("Erreur de login:\n");
- printf (" - mot de passe incorrect,\n");
- printf
- (" - système d'administration non activé, ou\n");
- printf (" - IP non autorisée.\n");
- ladmin_log
- ("Erreur de login: mot de passe incorrect, système d'administration non activé, ou IP non autorisée.\n");
- }
- else
- {
- printf ("Error at login:\n");
- printf (" - incorrect password,\n");
- printf
- (" - administration system not activated, or\n");
- printf (" - unauthorised IP.\n");
- ladmin_log
- ("Error at login: incorrect password, administration system not activated, or unauthorised IP.\n");
- }
+ PRINTF("Error at login:\n");
+ PRINTF(" - incorrect password,\n");
+ PRINTF(" - administration system not activated, or\n");
+ PRINTF(" - unauthorised IP.\n");
+ LADMIN_LOG("Error at login: incorrect password, administration system not activated, or unauthorised IP.\n");
session[fd]->eof = 1;
//bytes_to_read = 1; // not stop at prompt
}
else
{
- if (defaultlanguage == 'F')
- {
- printf ("Connexion établie.\n");
- ladmin_log ("Connexion établie.\n");
- printf
- ("Lecture de la version du serveur de login...\n");
- ladmin_log
- ("Lecture de la version du serveur de login...\n");
- }
- else
- {
- Iprintf ("Established connection.\n");
- ladmin_log ("Established connection.\n");
- Iprintf
- ("Reading of the version of the login-server...\n");
- ladmin_log
- ("Reading of the version of the login-server...\n");
- }
+ Iprintf("Established connection.\n");
+ LADMIN_LOG("Established connection.\n");
+ Iprintf("Reading of the version of the login-server...\n");
+ LADMIN_LOG("Reading of the version of the login-server...\n");
//bytes_to_read = 1; // unchanged
- checkloginversion ();
+ checkloginversion();
}
- RFIFOSKIP (fd, 3);
+ RFIFOSKIP(fd, 3);
break;
-#ifdef PASSWORDENC
case 0x01dc: // answer of a coding key request
- if (RFIFOREST (fd) < 4 || RFIFOREST (fd) < RFIFOW (fd, 2))
+ if (RFIFOREST(fd) < 4 || RFIFOREST(fd) < RFIFOW(fd, 2))
return;
{
char md5str[64] = "";
- uint8_t md5bin[32], md5key[RFIFOW (fd, 2) - 4 + 1];
- memcpy (md5key, RFIFOP (fd, 4), RFIFOW (fd, 2) - 4);
- md5key[sizeof (md5key) - 1] = '0';
+ uint8_t md5bin[32], md5key[RFIFOW(fd, 2) - 4 + 1];
+ memcpy(md5key, RFIFOP(fd, 4), RFIFOW(fd, 2) - 4);
+ md5key[sizeof(md5key) - 1] = '0';
if (passenc == 1)
{
- strncpy (md5str, (const char *)RFIFOP (fd, 4), RFIFOW (fd, 2) - 4);
- strcat (md5str, loginserveradminpassword);
+ strncpy(md5str, (const char *)RFIFOP(fd, 4), RFIFOW(fd, 2) - 4);
+ strcat(md5str, loginserveradminpassword);
}
else if (passenc == 2)
{
- strncpy (md5str, loginserveradminpassword,
- sizeof (loginserveradminpassword));
- strcat (md5str, (const char *)RFIFOP (fd, 4));
+ strncpy(md5str, loginserveradminpassword,
+ sizeof(loginserveradminpassword));
+ strcat(md5str, (const char *)RFIFOP(fd, 4));
}
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);
- WFIFOSET (login_fd, 20);
- if (defaultlanguage == 'F')
- {
- Iprintf ("Réception de la clef MD5.\n");
- ladmin_log ("Réception de la clef MD5.\n");
- Iprintf ("Envoi du mot de passe crypté...\n");
- ladmin_log ("Envoi du mot de passe crypté...\n");
- }
- else
- {
- Iprintf ("Receiving of the MD5 key.\n");
- ladmin_log ("Receiving of the MD5 key.\n");
- Iprintf ("Sending of the encrypted password...\n");
- ladmin_log ("Sending of the encrypted password...\n");
- }
+ 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);
+ WFIFOSET(login_fd, 20);
+ Iprintf("Receiving of the MD5 key.\n");
+ LADMIN_LOG("Receiving of the MD5 key.\n");
+ Iprintf("Sending of the encrypted password...\n");
+ LADMIN_LOG("Sending of the encrypted password...\n");
}
bytes_to_read = 1;
- RFIFOSKIP (fd, RFIFOW (fd, 2));
+ RFIFOSKIP(fd, RFIFOW(fd, 2));
break;
-#endif
case 0x7531: // Displaying of the version of the login-server
- if (RFIFOREST (fd) < 10)
+ if (RFIFOREST(fd) < 10)
return;
- Iprintf (" Login-Server [%s:%d]\n", loginserverip,
+ Iprintf(" Login-Server [%s:%d]\n", loginserverip,
loginserverport);
- if (((int) RFIFOB (login_fd, 5)) == 0)
+ if (((int) RFIFOB(login_fd, 5)) == 0)
{
- Iprintf (" eAthena version stable-%d.%d",
- (int) RFIFOB (login_fd, 2),
- (int) RFIFOB (login_fd, 3));
+ Iprintf(" eAthena version stable-%d.%d",
+ (int) RFIFOB(login_fd, 2),
+ (int) RFIFOB(login_fd, 3));
}
else
{
- Iprintf (" eAthena version dev-%d.%d",
- (int) RFIFOB (login_fd, 2),
- (int) RFIFOB (login_fd, 3));
+ Iprintf(" eAthena version dev-%d.%d",
+ (int) RFIFOB(login_fd, 2),
+ (int) RFIFOB(login_fd, 3));
}
- if (((int) RFIFOB (login_fd, 4)) == 0)
- Iprintf (" revision %d", (int) RFIFOB (login_fd, 4));
- if (((int) RFIFOB (login_fd, 6)) == 0)
+ if (((int) RFIFOB(login_fd, 4)) == 0)
+ Iprintf(" revision %d", (int) RFIFOB(login_fd, 4));
+ if (((int) RFIFOB(login_fd, 6)) == 0)
{
- Iprintf ("%d.\n", RFIFOW (login_fd, 8));
+ Iprintf("%d.\n", RFIFOW(login_fd, 8));
}
else
- Iprintf ("-mod%d.\n", RFIFOW (login_fd, 8));
+ Iprintf("-mod%d.\n", RFIFOW(login_fd, 8));
bytes_to_read = 0;
- RFIFOSKIP (fd, 10);
+ RFIFOSKIP(fd, 10);
break;
case 0x7925: // Itemfrob-OK
- RFIFOSKIP (fd, 2);
+ RFIFOSKIP(fd, 2);
bytes_to_read = 0;
break;
case 0x7921: // Displaying of the list of accounts
- if (RFIFOREST (fd) < 4 || RFIFOREST (fd) < RFIFOW (fd, 2))
+ if (RFIFOREST(fd) < 4 || RFIFOREST(fd) < RFIFOW(fd, 2))
return;
- if (RFIFOW (fd, 2) < 5)
+ if (RFIFOW(fd, 2) < 5)
{
- if (defaultlanguage == 'F')
+ LADMIN_LOG(" Receiving of a void accounts list.\n");
+ if (list_count == 0)
{
- ladmin_log
- (" Réception d'une liste des comptes vide.\n");
- if (list_count == 0)
- printf ("Aucun compte trouvé.\n");
- else if (list_count == 1)
- printf ("1 compte trouvé.\n");
- else
- printf ("%d comptes trouvés.\n", list_count);
+ Iprintf("No account found.\n");
}
- else
+ else if (list_count == 1)
{
- ladmin_log (" Receiving of a void accounts list.\n");
- if (list_count == 0)
- {
- Iprintf ("No account found.\n");
- }
- else if (list_count == 1)
- {
- Iprintf ("1 account found.\n");
- }
- else
- Iprintf ("%d accounts found.\n", list_count);
+ Iprintf("1 account found.\n");
}
+ else
+ Iprintf("%d accounts found.\n", list_count);
bytes_to_read = 0;
}
else
{
- int i;
- if (defaultlanguage == 'F')
- ladmin_log (" Réception d'une liste des comptes.\n");
- else
- ladmin_log (" Receiving of a accounts list.\n");
- for (i = 4; i < RFIFOW (fd, 2); i += 38)
+ int i;
+ LADMIN_LOG(" Receiving of a accounts list.\n");
+ for (i = 4; i < RFIFOW(fd, 2); i += 38)
{
- int j;
+ int j;
char userid[24];
char lower_userid[24];
- memcpy (userid, RFIFOP (fd, i + 5), sizeof (userid));
- userid[sizeof (userid) - 1] = '\0';
- memset (lower_userid, '\0', sizeof (lower_userid));
+ memcpy(userid, RFIFOP(fd, i + 5), sizeof(userid));
+ userid[sizeof(userid) - 1] = '\0';
+ memset(lower_userid, '\0', sizeof(lower_userid));
for (j = 0; userid[j]; j++)
- lower_userid[j] = tolower (userid[j]);
- list_first = RFIFOL (fd, i) + 1;
+ lower_userid[j] = tolower(userid[j]);
+ list_first = RFIFOL(fd, i) + 1;
// here are checks...
if (list_type == 0 ||
- (list_type == 1 && RFIFOB (fd, i + 4) > 0) ||
+ (list_type == 1 && RFIFOB(fd, i + 4) > 0) ||
(list_type == 2
- && strstr (lower_userid, parameters) != NULL)
- || (list_type == 3 && RFIFOL (fd, i + 34) != 0)
- || (list_type == 4 && RFIFOL (fd, i + 34) == 0))
+ && strstr(lower_userid, parameters) != NULL)
+ ||(list_type == 3 && RFIFOL(fd, i + 34) != 0)
+ ||(list_type == 4 && RFIFOL(fd, i + 34) == 0))
{
- printf ("%10d ", RFIFOL (fd, i));
- if (RFIFOB (fd, i + 4) == 0)
- printf (" ");
+ PRINTF("%10d ", RFIFOL(fd, i));
+ if (RFIFOB(fd, i + 4) == 0)
+ PRINTF(" ");
else
- printf ("%2d ", (int) RFIFOB (fd, i + 4));
- printf ("%-24s", userid);
- if (defaultlanguage == 'F')
- {
- if (RFIFOB (fd, i + 29) == 0)
- printf ("%-5s ", "Femme");
- else if (RFIFOB (fd, i + 29) == 1)
- printf ("%-5s ", "Male");
- else
- printf ("%-5s ", "Servr");
- }
+ PRINTF("%2d ", (int) RFIFOB(fd, i + 4));
+ PRINTF("%-24s", userid);
+ if (RFIFOB(fd, i + 29) == 0)
+ PRINTF("%-5s ", "Femal");
+ else if (RFIFOB(fd, i + 29) == 1)
+ PRINTF("%-5s ", "Male");
else
- {
- if (RFIFOB (fd, i + 29) == 0)
- printf ("%-5s ", "Femal");
- else if (RFIFOB (fd, i + 29) == 1)
- printf ("%-5s ", "Male");
- else
- printf ("%-5s ", "Servr");
- }
- printf ("%6d ", RFIFOL (fd, i + 30));
- switch (RFIFOL (fd, i + 34))
+ PRINTF("%-5s ", "Servr");
+ PRINTF("%6d ", RFIFOL(fd, i + 30));
+ switch (RFIFOL(fd, i + 34))
{
case 0:
- if (defaultlanguage == 'F')
- printf ("%-27s\n", "Compte Ok");
- else
- printf ("%-27s\n", "Account OK");
+ PRINTF("%-27s\n", "Account OK");
break;
case 1:
- printf ("%-27s\n", "Unregistered ID");
+ PRINTF("%-27s\n", "Unregistered ID");
break;
case 2:
- printf ("%-27s\n", "Incorrect Password");
+ PRINTF("%-27s\n", "Incorrect Password");
break;
case 3:
- printf ("%-27s\n", "This ID is expired");
+ PRINTF("%-27s\n", "This ID is expired");
break;
case 4:
- printf ("%-27s\n",
+ PRINTF("%-27s\n",
"Rejected from Server");
break;
case 5:
- printf ("%-27s\n", "Blocked by the GM Team"); // You have been blocked by the GM Team
+ PRINTF("%-27s\n", "Blocked by the GM Team"); // You have been blocked by the GM Team
break;
case 6:
- printf ("%-27s\n", "Your EXE file is too old"); // Your Game's EXE file is not the latest version
+ PRINTF("%-27s\n", "Your EXE file is too old"); // Your Game's EXE file is not the latest version
break;
case 7:
- printf ("%-27s\n", "Banishement or");
- printf (" Prohibited to login until...\n"); // You are Prohibited to log in until %s
+ PRINTF("%-27s\n", "Banishement or");
+ PRINTF(" Prohibited to login until...\n"); // You are Prohibited to log in until %s
break;
case 8:
- printf ("%-27s\n",
+ PRINTF("%-27s\n",
"Server is over populated");
break;
case 9:
- printf ("%-27s\n", "No MSG");
+ PRINTF("%-27s\n", "No MSG");
break;
default: // 100
- printf ("%-27s\n", "This ID is totally erased"); // This ID has been totally erased
+ PRINTF("%-27s\n", "This ID is totally erased"); // This ID has been totally erased
break;
}
list_count++;
}
}
// asking of the following acounts
- if (defaultlanguage == 'F')
- ladmin_log
- ("Envoi d'un requête au serveur de logins pour obtenir la liste des comptes de %d à %d (complément).\n",
- list_first, list_last);
- else
- ladmin_log
- ("Request to login-server to obtain the list of accounts from %d to %d (complement).\n",
- list_first, list_last);
- WFIFOW (login_fd, 0) = 0x7920;
- WFIFOL (login_fd, 2) = list_first;
- WFIFOL (login_fd, 6) = list_last;
- WFIFOSET (login_fd, 10);
+ LADMIN_LOG("Request to login-server to obtain the list of accounts from %d to %d (complement).\n",
+ list_first, list_last);
+ WFIFOW(login_fd, 0) = 0x7920;
+ WFIFOL(login_fd, 2) = list_first;
+ WFIFOL(login_fd, 6) = list_last;
+ WFIFOSET(login_fd, 10);
bytes_to_read = 1;
}
- RFIFOSKIP (fd, RFIFOW (fd, 2));
+ RFIFOSKIP(fd, RFIFOW(fd, 2));
break;
case 0x7931: // Answer of login-server about an account creation
- if (RFIFOREST (fd) < 30)
+ if (RFIFOREST(fd) < 30)
return;
- if (RFIFOL (fd, 2) == -1)
+ if (RFIFOL(fd, 2) == -1)
{
- if (defaultlanguage == 'F')
- {
- printf
- ("Echec à la création du compte [%s]. Un compte identique existe déjà.\n",
- RFIFOP (fd, 6));
- ladmin_log
- ("Echec à la création du compte [%s]. Un compte identique existe déjà.\n",
- RFIFOP (fd, 6));
- }
- else
- {
- printf
- ("Account [%s] creation failed. Same account already exists.\n",
- RFIFOP (fd, 6));
- ladmin_log
- ("Account [%s] creation failed. Same account already exists.\n",
- RFIFOP (fd, 6));
- }
+ PRINTF("Account [%s] creation failed. Same account already exists.\n",
+ static_cast<const char *>(RFIFOP(fd, 6)));
+ LADMIN_LOG("Account [%s] creation failed. Same account already exists.\n",
+ static_cast<const char *>(RFIFOP(fd, 6)));
}
else
{
- if (defaultlanguage == 'F')
- {
- printf ("Compte [%s] créé avec succès [id: %d].\n",
- RFIFOP (fd, 6), RFIFOL (fd, 2));
- ladmin_log ("Compte [%s] créé avec succès [id: %d].\n",
- RFIFOP (fd, 6), RFIFOL (fd, 2));
- }
- else
- {
- printf
- ("Account [%s] is successfully created [id: %d].\n",
- RFIFOP (fd, 6), RFIFOL (fd, 2));
- ladmin_log
- ("Account [%s] is successfully created [id: %d].\n",
- RFIFOP (fd, 6), RFIFOL (fd, 2));
- }
+ PRINTF("Account [%s] is successfully created [id: %d].\n",
+ static_cast<const char *>(RFIFOP(fd, 6)), RFIFOL(fd, 2));
+ LADMIN_LOG("Account [%s] is successfully created [id: %d].\n",
+ static_cast<const char *>(RFIFOP(fd, 6)), RFIFOL(fd, 2));
}
bytes_to_read = 0;
- RFIFOSKIP (fd, 30);
+ RFIFOSKIP(fd, 30);
break;
case 0x7933: // Answer of login-server about an account deletion
- if (RFIFOREST (fd) < 30)
+ if (RFIFOREST(fd) < 30)
return;
- if (RFIFOL (fd, 2) == -1)
+ if (RFIFOL(fd, 2) == -1)
{
- if (defaultlanguage == 'F')
- {
- printf
- ("Echec de la suppression du compte [%s]. Le compte n'existe pas.\n",
- RFIFOP (fd, 6));
- ladmin_log
- ("Echec de la suppression du compte [%s]. Le compte n'existe pas.\n",
- RFIFOP (fd, 6));
- }
- else
- {
- printf
- ("Account [%s] deletion failed. Account doesn't exist.\n",
- RFIFOP (fd, 6));
- ladmin_log
- ("Account [%s] deletion failed. Account doesn't exist.\n",
- RFIFOP (fd, 6));
- }
+ PRINTF("Account [%s] deletion failed. Account doesn't exist.\n",
+ static_cast<const char *>(RFIFOP(fd, 6)));
+ LADMIN_LOG("Account [%s] deletion failed. Account doesn't exist.\n",
+ static_cast<const char *>(RFIFOP(fd, 6)));
}
else
{
- if (defaultlanguage == 'F')
- {
- printf ("Compte [%s][id: %d] SUPPRIME avec succès.\n",
- RFIFOP (fd, 6), RFIFOL (fd, 2));
- ladmin_log
- ("Compte [%s][id: %d] SUPPRIME avec succès.\n",
- RFIFOP (fd, 6), RFIFOL (fd, 2));
- }
- else
- {
- printf
- ("Account [%s][id: %d] is successfully DELETED.\n",
- RFIFOP (fd, 6), RFIFOL (fd, 2));
- ladmin_log
- ("Account [%s][id: %d] is successfully DELETED.\n",
- RFIFOP (fd, 6), RFIFOL (fd, 2));
- }
+ PRINTF("Account [%s][id: %d] is successfully DELETED.\n",
+ static_cast<const char *>(RFIFOP(fd, 6)), RFIFOL(fd, 2));
+ LADMIN_LOG("Account [%s][id: %d] is successfully DELETED.\n",
+ static_cast<const char *>(RFIFOP(fd, 6)), RFIFOL(fd, 2));
}
bytes_to_read = 0;
- RFIFOSKIP (fd, 30);
+ RFIFOSKIP(fd, 30);
break;
case 0x7935: // answer of the change of an account password
- if (RFIFOREST (fd) < 30)
+ if (RFIFOREST(fd) < 30)
return;
- if (RFIFOL (fd, 2) == -1)
+ if (RFIFOL(fd, 2) == -1)
{
- if (defaultlanguage == 'F')
- {
- printf
- ("Echec de la modification du mot de passe du compte [%s].\n",
- RFIFOP (fd, 6));
- printf ("Le compte [%s] n'existe pas.\n",
- RFIFOP (fd, 6));
- ladmin_log
- ("Echec de la modification du mot de passe du compte. Le compte [%s] n'existe pas.\n",
- RFIFOP (fd, 6));
- }
- else
- {
- printf ("Account [%s] password changing failed.\n",
- RFIFOP (fd, 6));
- printf ("Account [%s] doesn't exist.\n",
- RFIFOP (fd, 6));
- ladmin_log
- ("Account password changing failed. The compte [%s] doesn't exist.\n",
- RFIFOP (fd, 6));
- }
+ PRINTF("Account [%s] password changing failed.\n",
+ static_cast<const char *>(RFIFOP(fd, 6)));
+ PRINTF("Account [%s] doesn't exist.\n",
+ static_cast<const char *>(RFIFOP(fd, 6)));
+ LADMIN_LOG("Account password changing failed. The compte [%s] doesn't exist.\n",
+ static_cast<const char *>(RFIFOP(fd, 6)));
}
else
{
- if (defaultlanguage == 'F')
- {
- printf
- ("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] réussie.\n",
- RFIFOP (fd, 6), RFIFOL (fd, 2));
- }
- else
- {
- printf
- ("Account [%s][id: %d] password successfully changed.\n",
- RFIFOP (fd, 6), RFIFOL (fd, 2));
- ladmin_log
- ("Account [%s][id: %d] password successfully changed.\n",
- RFIFOP (fd, 6), RFIFOL (fd, 2));
- }
+ PRINTF("Account [%s][id: %d] password successfully changed.\n",
+ static_cast<const char *>(RFIFOP(fd, 6)), RFIFOL(fd, 2));
+ LADMIN_LOG("Account [%s][id: %d] password successfully changed.\n",
+ static_cast<const char *>(RFIFOP(fd, 6)), RFIFOL(fd, 2));
}
bytes_to_read = 0;
- RFIFOSKIP (fd, 30);
+ RFIFOSKIP(fd, 30);
break;
case 0x7937: // answer of the change of an account state
- if (RFIFOREST (fd) < 34)
+ if (RFIFOREST(fd) < 34)
return;
- if (RFIFOL (fd, 2) == -1)
+ if (RFIFOL(fd, 2) == -1)
{
- if (defaultlanguage == 'F')
- {
- printf
- ("Echec du changement du statut du compte [%s]. Le compte n'existe pas.\n",
- RFIFOP (fd, 6));
- ladmin_log
- ("Echec du changement du statut du compte [%s]. Le compte n'existe pas.\n",
- RFIFOP (fd, 6));
- }
- else
- {
- printf
- ("Account [%s] state changing failed. Account doesn't exist.\n",
- RFIFOP (fd, 6));
- ladmin_log
- ("Account [%s] state changing failed. Account doesn't exist.\n",
- RFIFOP (fd, 6));
- }
+ PRINTF("Account [%s] state changing failed. Account doesn't exist.\n",
+ static_cast<const char *>(RFIFOP(fd, 6)));
+ LADMIN_LOG("Account [%s] state changing failed. Account doesn't exist.\n",
+ static_cast<const char *>(RFIFOP(fd, 6)));
}
else
{
- char tmpstr[256];
- if (defaultlanguage == 'F')
- {
- sprintf (tmpstr,
- "Statut du compte [%s] changé avec succès en [",
- RFIFOP (fd, 6));
- }
- else
- {
- sprintf (tmpstr,
- "Account [%s] state successfully changed in [",
- RFIFOP (fd, 6));
- }
- switch (RFIFOL (fd, 30))
+ std::string tmpstr = STRPRINTF(
+ "Account [%s] state successfully changed in [",
+ static_cast<const char *>(RFIFOP(fd, 6)));
+ switch (RFIFOL(fd, 30))
{
case 0:
- if (defaultlanguage == 'F')
- strcat (tmpstr, "0: Compte Ok");
- else
- strcat (tmpstr, "0: Account OK");
+ tmpstr += "0: Account OK";
break;
case 1:
- strcat (tmpstr, "1: Unregistered ID");
+ tmpstr += "1: Unregistered ID";
break;
case 2:
- strcat (tmpstr, "2: Incorrect Password");
+ tmpstr += "2: Incorrect Password";
break;
case 3:
- strcat (tmpstr, "3: This ID is expired");
+ tmpstr += "3: This ID is expired";
break;
case 4:
- strcat (tmpstr, "4: Rejected from Server");
+ tmpstr += "4: Rejected from Server";
break;
case 5:
- strcat (tmpstr,
- "5: You have been blocked by the GM Team");
+ tmpstr += "5: You have been blocked by the GM Team";
break;
case 6:
- strcat (tmpstr,
- "6: [Your Game's EXE file is not the latest version");
+ tmpstr += "6: [Your Game's EXE file is not the latest version";
break;
case 7:
- strcat (tmpstr,
- "7: You are Prohibited to log in until...");
+ tmpstr += "7: You are Prohibited to log in until...";
break;
case 8:
- strcat (tmpstr,
- "8: Server is jammed due to over populated");
+ tmpstr += "8: Server is jammed due to over populated";
break;
case 9:
- strcat (tmpstr, "9: No MSG");
+ tmpstr += "9: No MSG";
break;
default: // 100
- strcat (tmpstr, "100: This ID is totally erased");
+ tmpstr += "100: This ID is totally erased";
break;
}
- strcat (tmpstr, "]");
- printf ("%s\n", tmpstr);
- ladmin_log ("%s%s", tmpstr, "\n");
+ tmpstr += ']';
+ PRINTF("%s\n", tmpstr);
+ LADMIN_LOG("%s\n", tmpstr);
}
bytes_to_read = 0;
- RFIFOSKIP (fd, 34);
+ RFIFOSKIP(fd, 34);
break;
case 0x7939: // answer of the number of online players
- if (RFIFOREST (fd) < 4 || RFIFOREST (fd) < RFIFOW (fd, 2))
+ if (RFIFOREST(fd) < 4 || RFIFOREST(fd) < RFIFOW(fd, 2))
return;
{
// Get length of the received packet
- int i;
+ int i;
char name[20];
- if (defaultlanguage == 'F')
- {
- ladmin_log
- (" Réception du nombre de joueurs en ligne.\n");
- }
- else
- {
- ladmin_log
- (" Receiving of the number of online players.\n");
- }
+ LADMIN_LOG(" Receiving of the number of online players.\n");
// Read information of the servers
- if (RFIFOW (fd, 2) < 5)
+ if (RFIFOW(fd, 2) < 5)
{
- if (defaultlanguage == 'F')
- {
- printf
- (" Aucun serveur n'est connecté au login serveur.\n");
- }
- else
- {
- printf
- (" No server is connected to the login-server.\n");
- }
+ PRINTF(" No server is connected to the login-server.\n");
}
else
{
- if (defaultlanguage == 'F')
- {
- printf
- (" Nombre de joueurs en ligne (serveur: nb):\n");
- }
- else
- {
- printf
- (" Number of online players (server: number).\n");
- }
+ PRINTF(" Number of online players (server: number).\n");
// Displaying of result
- for (i = 4; i < RFIFOW (fd, 2); i += 32)
+ for (i = 4; i < RFIFOW(fd, 2); i += 32)
{
- memcpy (name, RFIFOP (fd, i + 6), sizeof (name));
- name[sizeof (name) - 1] = '\0';
- printf (" %-20s : %5d\n", name,
- RFIFOW (fd, i + 26));
+ memcpy(name, RFIFOP(fd, i + 6), sizeof(name));
+ name[sizeof(name) - 1] = '\0';
+ PRINTF(" %-20s : %5d\n", name,
+ RFIFOW(fd, i + 26));
}
}
}
bytes_to_read = 0;
- RFIFOSKIP (fd, RFIFOW (fd, 2));
+ RFIFOSKIP(fd, RFIFOW(fd, 2));
break;
case 0x793b: // answer of the check of a password
- if (RFIFOREST (fd) < 30)
+ if (RFIFOREST(fd) < 30)
return;
- if (RFIFOL (fd, 2) == -1)
+ if (RFIFOL(fd, 2) == -1)
{
- if (defaultlanguage == 'F')
- {
- printf
- ("Le compte [%s] n'existe pas ou le mot de passe est incorrect.\n",
- RFIFOP (fd, 6));
- ladmin_log
- ("Le compte [%s] n'existe pas ou le mot de passe est incorrect.\n",
- RFIFOP (fd, 6));
- }
- else
- {
- printf
- ("The account [%s] doesn't exist or the password is incorrect.\n",
- RFIFOP (fd, 6));
- ladmin_log
- ("The account [%s] doesn't exist or the password is incorrect.\n",
- RFIFOP (fd, 6));
- }
+ PRINTF("The account [%s] doesn't exist or the password is incorrect.\n",
+ static_cast<const char *>(RFIFOP(fd, 6)));
+ LADMIN_LOG("The account [%s] doesn't exist or the password is incorrect.\n",
+ static_cast<const char *>(RFIFOP(fd, 6)));
}
else
{
- if (defaultlanguage == 'F')
- {
- printf
- ("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].\n",
- RFIFOP (fd, 6), RFIFOL (fd, 2));
- }
- else
- {
- printf
- ("The proposed password is correct for the account [%s][id: %d].\n",
- RFIFOP (fd, 6), RFIFOL (fd, 2));
- ladmin_log
- ("The proposed password is correct for the account [%s][id: %d].\n",
- RFIFOP (fd, 6), RFIFOL (fd, 2));
- }
+ PRINTF("The proposed password is correct for the account [%s][id: %d].\n",
+ static_cast<const char *>(RFIFOP(fd, 6)), RFIFOL(fd, 2));
+ LADMIN_LOG("The proposed password is correct for the account [%s][id: %d].\n",
+ static_cast<const char *>(RFIFOP(fd, 6)), RFIFOL(fd, 2));
}
bytes_to_read = 0;
- RFIFOSKIP (fd, 30);
+ RFIFOSKIP(fd, 30);
break;
case 0x793d: // answer of the change of an account sex
- if (RFIFOREST (fd) < 30)
+ if (RFIFOREST(fd) < 30)
return;
- if (RFIFOL (fd, 2) == -1)
+ if (RFIFOL(fd, 2) == -1)
{
- if (defaultlanguage == 'F')
- {
- printf
- ("Echec de la modification du sexe du compte [%s].\n",
- RFIFOP (fd, 6));
- printf
- ("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 déjà celui demandé.\n",
- RFIFOP (fd, 6));
- }
- else
- {
- printf ("Account [%s] sex changing failed.\n",
- RFIFOP (fd, 6));
- printf
- ("Account [%s] doesn't exist or the sex is already the good sex.\n",
- RFIFOP (fd, 6));
- ladmin_log
- ("Account sex changing failed. The compte [%s] doesn't exist or the sex is already the good sex.\n",
- RFIFOP (fd, 6));
- }
+ PRINTF("Account [%s] sex changing failed.\n",
+ static_cast<const char *>(RFIFOP(fd, 6)));
+ PRINTF("Account [%s] doesn't exist or the sex is already the good sex.\n",
+ static_cast<const char *>(RFIFOP(fd, 6)));
+ LADMIN_LOG("Account sex changing failed. The compte [%s] doesn't exist or the sex is already the good sex.\n",
+ static_cast<const char *>(RFIFOP(fd, 6)));
}
else
{
- if (defaultlanguage == 'F')
- {
- printf
- ("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 succès.\n",
- RFIFOP (fd, 6), RFIFOL (fd, 2));
- }
- else
- {
- printf
- ("Account [%s][id: %d] sex successfully changed.\n",
- RFIFOP (fd, 6), RFIFOL (fd, 2));
- ladmin_log
- ("Account [%s][id: %d] sex successfully changed.\n",
- RFIFOP (fd, 6), RFIFOL (fd, 2));
- }
+ PRINTF("Account [%s][id: %d] sex successfully changed.\n",
+ static_cast<const char *>(RFIFOP(fd, 6)), RFIFOL(fd, 2));
+ LADMIN_LOG("Account [%s][id: %d] sex successfully changed.\n",
+ static_cast<const char *>(RFIFOP(fd, 6)), RFIFOL(fd, 2));
}
bytes_to_read = 0;
- RFIFOSKIP (fd, 30);
+ RFIFOSKIP(fd, 30);
break;
case 0x793f: // answer of the change of an account GM level
- if (RFIFOREST (fd) < 30)
+ if (RFIFOREST(fd) < 30)
return;
- if (RFIFOL (fd, 2) == -1)
+ if (RFIFOL(fd, 2) == -1)
{
- if (defaultlanguage == 'F')
- {
- printf
- ("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 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 déjà celui demandé ou il est impossible de modifier le fichier des comptes GM.\n",
- RFIFOP (fd, 6));
- }
- else
- {
- printf ("Account [%s] GM level changing failed.\n",
- RFIFOP (fd, 6));
- printf
- ("Account [%s] doesn't exist, the GM level is already the good GM level\n",
- RFIFOP (fd, 6));
- printf
- ("or it's impossible to modify the GM accounts file.\n");
- ladmin_log
- ("Account GM level changing failed. The compte [%s] doesn't exist, the GM level is already the good sex or it's impossible to modify the GM accounts file.\n",
- RFIFOP (fd, 6));
- }
+ PRINTF("Account [%s] GM level changing failed.\n",
+ static_cast<const char *>(RFIFOP(fd, 6)));
+ PRINTF("Account [%s] doesn't exist, the GM level is already the good GM level\n",
+ static_cast<const char *>(RFIFOP(fd, 6)));
+ PRINTF("or it's impossible to modify the GM accounts file.\n");
+ LADMIN_LOG("Account GM level changing failed. The compte [%s] doesn't exist, the GM level is already the good sex or it's impossible to modify the GM accounts file.\n",
+ static_cast<const char *>(RFIFOP(fd, 6)));
}
else
{
- if (defaultlanguage == 'F')
- {
- printf
- ("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 succès.\n",
- RFIFOP (fd, 6), RFIFOL (fd, 2));
- }
- else
- {
- printf
- ("Account [%s][id: %d] GM level successfully changed.\n",
- RFIFOP (fd, 6), RFIFOL (fd, 2));
- ladmin_log
- ("Account [%s][id: %d] GM level successfully changed.\n",
- RFIFOP (fd, 6), RFIFOL (fd, 2));
- }
+ PRINTF("Account [%s][id: %d] GM level successfully changed.\n",
+ static_cast<const char *>(RFIFOP(fd, 6)), RFIFOL(fd, 2));
+ LADMIN_LOG("Account [%s][id: %d] GM level successfully changed.\n",
+ static_cast<const char *>(RFIFOP(fd, 6)), RFIFOL(fd, 2));
}
bytes_to_read = 0;
- RFIFOSKIP (fd, 30);
+ RFIFOSKIP(fd, 30);
break;
case 0x7941: // answer of the change of an account email
- if (RFIFOREST (fd) < 30)
+ if (RFIFOREST(fd) < 30)
return;
- if (RFIFOL (fd, 2) == -1)
+ if (RFIFOL(fd, 2) == -1)
{
- if (defaultlanguage == 'F')
- {
- printf
- ("Echec de la modification de l'e-mail du compte [%s].\n",
- RFIFOP (fd, 6));
- printf ("Le compte [%s] n'existe pas.\n",
- RFIFOP (fd, 6));
- ladmin_log
- ("Echec de la modification de l'e-mail du compte. Le compte [%s] n'existe pas.\n",
- RFIFOP (fd, 6));
- }
- else
- {
- printf ("Account [%s] e-mail changing failed.\n",
- RFIFOP (fd, 6));
- printf ("Account [%s] doesn't exist.\n",
- RFIFOP (fd, 6));
- ladmin_log
- ("Account e-mail changing failed. The compte [%s] doesn't exist.\n",
- RFIFOP (fd, 6));
- }
+ PRINTF("Account [%s] e-mail changing failed.\n",
+ static_cast<const char *>(RFIFOP(fd, 6)));
+ PRINTF("Account [%s] doesn't exist.\n",
+ static_cast<const char *>(RFIFOP(fd, 6)));
+ LADMIN_LOG("Account e-mail changing failed. The compte [%s] doesn't exist.\n",
+ static_cast<const char *>(RFIFOP(fd, 6)));
}
else
{
- if (defaultlanguage == 'F')
- {
- printf
- ("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] réussie.\n",
- RFIFOP (fd, 6), RFIFOL (fd, 2));
- }
- else
- {
- printf
- ("Account [%s][id: %d] e-mail successfully changed.\n",
- RFIFOP (fd, 6), RFIFOL (fd, 2));
- ladmin_log
- ("Account [%s][id: %d] e-mail successfully changed.\n",
- RFIFOP (fd, 6), RFIFOL (fd, 2));
- }
+ PRINTF("Account [%s][id: %d] e-mail successfully changed.\n",
+ static_cast<const char *>(RFIFOP(fd, 6)), RFIFOL(fd, 2));
+ LADMIN_LOG("Account [%s][id: %d] e-mail successfully changed.\n",
+ static_cast<const char *>(RFIFOP(fd, 6)), RFIFOL(fd, 2));
}
bytes_to_read = 0;
- RFIFOSKIP (fd, 30);
+ RFIFOSKIP(fd, 30);
break;
case 0x7943: // answer of the change of an account memo
- if (RFIFOREST (fd) < 30)
+ if (RFIFOREST(fd) < 30)
return;
- if (RFIFOL (fd, 2) == -1)
+ if (RFIFOL(fd, 2) == -1)
{
- if (defaultlanguage == 'F')
- {
- printf
- ("Echec du changement du mémo du compte [%s]. Le compte n'existe pas.\n",
- RFIFOP (fd, 6));
- ladmin_log
- ("Echec du changement du mémo du compte [%s]. Le compte n'existe pas.\n",
- RFIFOP (fd, 6));
- }
- else
- {
- printf
- ("Account [%s] memo changing failed. Account doesn't exist.\n",
- RFIFOP (fd, 6));
- ladmin_log
- ("Account [%s] memo changing failed. Account doesn't exist.\n",
- RFIFOP (fd, 6));
- }
+ PRINTF("Account [%s] memo changing failed. Account doesn't exist.\n",
+ static_cast<const char *>(RFIFOP(fd, 6)));
+ LADMIN_LOG("Account [%s] memo changing failed. Account doesn't exist.\n",
+
+ static_cast<const char *>(RFIFOP(fd, 6)));
}
else
{
- if (defaultlanguage == 'F')
- {
- printf
- ("Mémo du compte [%s][id: %d] changé avec succès.\n",
- RFIFOP (fd, 6), RFIFOL (fd, 2));
- ladmin_log
- ("Mémo du compte [%s][id: %d] changé avec succès.\n",
- RFIFOP (fd, 6), RFIFOL (fd, 2));
- }
- else
- {
- printf
- ("Account [%s][id: %d] memo successfully changed.\n",
- RFIFOP (fd, 6), RFIFOL (fd, 2));
- ladmin_log
- ("Account [%s][id: %d] memo successfully changed.\n",
- RFIFOP (fd, 6), RFIFOL (fd, 2));
- }
+ PRINTF("Account [%s][id: %d] memo successfully changed.\n",
+ static_cast<const char *>(RFIFOP(fd, 6)), RFIFOL(fd, 2));
+ LADMIN_LOG("Account [%s][id: %d] memo successfully changed.\n",
+ static_cast<const char *>(RFIFOP(fd, 6)), RFIFOL(fd, 2));
}
bytes_to_read = 0;
- RFIFOSKIP (fd, 30);
+ RFIFOSKIP(fd, 30);
break;
case 0x7945: // answer of an account id search
- if (RFIFOREST (fd) < 30)
+ if (RFIFOREST(fd) < 30)
return;
- if (RFIFOL (fd, 2) == -1)
+ if (RFIFOL(fd, 2) == -1)
{
- if (defaultlanguage == 'F')
- {
- printf
- ("Impossible de trouver l'id du compte [%s]. Le compte n'existe pas.\n",
- RFIFOP (fd, 6));
- ladmin_log
- ("Impossible de trouver l'id du compte [%s]. Le compte n'existe pas.\n",
- RFIFOP (fd, 6));
- }
- else
- {
- printf
- ("Unable to find the account [%s] id. Account doesn't exist.\n",
- RFIFOP (fd, 6));
- ladmin_log
- ("Unable to find the account [%s] id. Account doesn't exist.\n",
- RFIFOP (fd, 6));
- }
+ PRINTF("Unable to find the account [%s] id. Account doesn't exist.\n",
+ static_cast<const char *>(RFIFOP(fd, 6)));
+ LADMIN_LOG("Unable to find the account [%s] id. Account doesn't exist.\n",
+ static_cast<const char *>(RFIFOP(fd, 6)));
}
else
{
- if (defaultlanguage == 'F')
- {
- printf ("Le compte [%s] a pour id: %d.\n",
- RFIFOP (fd, 6), RFIFOL (fd, 2));
- ladmin_log ("Le compte [%s] a pour id: %d.\n",
- RFIFOP (fd, 6), RFIFOL (fd, 2));
- }
- else
- {
- printf ("The account [%s] have the id: %d.\n",
- RFIFOP (fd, 6), RFIFOL (fd, 2));
- ladmin_log ("The account [%s] have the id: %d.\n",
- RFIFOP (fd, 6), RFIFOL (fd, 2));
- }
+ PRINTF("The account [%s] have the id: %d.\n",
+ static_cast<const char *>(RFIFOP(fd, 6)), RFIFOL(fd, 2));
+ LADMIN_LOG("The account [%s] have the id: %d.\n",
+ static_cast<const char *>(RFIFOP(fd, 6)), RFIFOL(fd, 2));
}
bytes_to_read = 0;
- RFIFOSKIP (fd, 30);
+ RFIFOSKIP(fd, 30);
break;
case 0x7947: // answer of an account name search
- if (RFIFOREST (fd) < 30)
+ if (RFIFOREST(fd) < 30)
return;
- if (strcmp ((const char *)RFIFOP (fd, 6), "") == 0)
+ if (strcmp((const char *)RFIFOP(fd, 6), "") == 0)
{
- if (defaultlanguage == 'F')
- {
- printf
- ("Impossible de trouver le nom du compte [%d]. Le compte n'existe pas.\n",
- RFIFOL (fd, 2));
- ladmin_log
- ("Impossible de trouver le nom du compte [%d]. Le compte n'existe pas.\n",
- RFIFOL (fd, 2));
- }
- else
- {
- printf
- ("Unable to find the account [%d] name. Account doesn't exist.\n",
- RFIFOL (fd, 2));
- ladmin_log
- ("Unable to find the account [%d] name. Account doesn't exist.\n",
- RFIFOL (fd, 2));
- }
+ PRINTF("Unable to find the account [%d] name. Account doesn't exist.\n",
+ RFIFOL(fd, 2));
+ LADMIN_LOG("Unable to find the account [%d] name. Account doesn't exist.\n",
+ RFIFOL(fd, 2));
}
else
{
- if (defaultlanguage == 'F')
- {
- printf ("Le compte [id: %d] a pour nom: %s.\n",
- RFIFOL (fd, 2), RFIFOP (fd, 6));
- ladmin_log ("Le compte [id: %d] a pour nom: %s.\n",
- RFIFOL (fd, 2), RFIFOP (fd, 6));
- }
- else
- {
- printf ("The account [id: %d] have the name: %s.\n",
- RFIFOL (fd, 2), RFIFOP (fd, 6));
- ladmin_log ("The account [id: %d] have the name: %s.\n",
- RFIFOL (fd, 2), RFIFOP (fd, 6));
- }
+ PRINTF("The account [id: %d] have the name: %s.\n",
+ RFIFOL(fd, 2), static_cast<const char *>(RFIFOP(fd, 6)));
+ LADMIN_LOG("The account [id: %d] have the name: %s.\n",
+ RFIFOL(fd, 2), static_cast<const char *>(RFIFOP(fd, 6)));
}
bytes_to_read = 0;
- RFIFOSKIP (fd, 30);
+ RFIFOSKIP(fd, 30);
break;
case 0x7949: // answer of an account validity limit set
- if (RFIFOREST (fd) < 34)
+ if (RFIFOREST(fd) < 34)
return;
- if (RFIFOL (fd, 2) == -1)
+ if (RFIFOL(fd, 2) == -1)
{
- if (defaultlanguage == 'F')
- {
- printf
- ("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.\n",
- RFIFOP (fd, 6));
- }
- else
- {
- printf
- ("Account [%s] validity limit changing failed. Account doesn't exist.\n",
- RFIFOP (fd, 6));
- ladmin_log
- ("Account [%s] validity limit changing failed. Account doesn't exist.\n",
- RFIFOP (fd, 6));
- }
+ PRINTF("Account [%s] validity limit changing failed. Account doesn't exist.\n",
+ static_cast<const char *>(RFIFOP(fd, 6)));
+ LADMIN_LOG("Account [%s] validity limit changing failed. Account doesn't exist.\n",
+ static_cast<const char *>(RFIFOP(fd, 6)));
}
else
{
- time_t timestamp = RFIFOL (fd, 30);
- if (timestamp == 0)
+ TimeT timestamp = static_cast<time_t>(RFIFOL(fd, 30));
+ if (!timestamp)
{
- if (defaultlanguage == 'F')
- {
- printf
- ("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] changée avec succès en [illimité].\n",
- RFIFOP (fd, 6), RFIFOL (fd, 2));
- }
- else
- {
- printf
- ("Validity Limit of the account [%s][id: %d] successfully changed to [unlimited].\n",
- RFIFOP (fd, 6), RFIFOL (fd, 2));
- ladmin_log
- ("Validity Limit of the account [%s][id: %d] successfully changed to [unlimited].\n",
- RFIFOP (fd, 6), RFIFOL (fd, 2));
- }
+ PRINTF("Validity Limit of the account [%s][id: %d] successfully changed to [unlimited].\n",
+ static_cast<const char *>(RFIFOP(fd, 6)), RFIFOL(fd, 2));
+ LADMIN_LOG("Validity Limit of the account [%s][id: %d] successfully changed to [unlimited].\n",
+ static_cast<const char *>(RFIFOP(fd, 6)), RFIFOL(fd, 2));
}
else
{
- char tmpstr[128];
- strftime (tmpstr, 24, date_format,
- localtime (&timestamp));
- if (defaultlanguage == 'F')
- {
- printf
- ("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] changée avec succès pour être jusqu'au %s.\n",
- RFIFOP (fd, 6), RFIFOL (fd, 2),
- tmpstr);
- }
- else
- {
- printf
- ("Validity Limit of the account [%s][id: %d] successfully changed to be until %s.\n",
- RFIFOP (fd, 6), RFIFOL (fd, 2), tmpstr);
- ladmin_log
- ("Validity Limit of the account [%s][id: %d] successfully changed to be until %s.\n",
- RFIFOP (fd, 6), RFIFOL (fd, 2),
- tmpstr);
- }
+ timestamp_seconds_buffer tmpstr;
+ stamp_time(tmpstr, &timestamp);
+ PRINTF("Validity Limit of the account [%s][id: %d] successfully changed to be until %s.\n",
+ static_cast<const char *>(RFIFOP(fd, 6)), RFIFOL(fd, 2), tmpstr);
+ LADMIN_LOG("Validity Limit of the account [%s][id: %d] successfully changed to be until %s.\n",
+ static_cast<const char *>(RFIFOP(fd, 6)), RFIFOL(fd, 2),
+ tmpstr);
}
}
bytes_to_read = 0;
- RFIFOSKIP (fd, 34);
+ RFIFOSKIP(fd, 34);
break;
case 0x794b: // answer of an account ban set
- if (RFIFOREST (fd) < 34)
+ if (RFIFOREST(fd) < 34)
return;
- if (RFIFOL (fd, 2) == -1)
+ if (RFIFOL(fd, 2) == -1)
{
- if (defaultlanguage == 'F')
- {
- printf
- ("Echec du changement de la date finale de banissement du compte [%s]. Le compte n'existe pas.\n",
- RFIFOP (fd, 6));
- ladmin_log
- ("Echec du changement de la date finale de banissement du compte [%s]. Le compte n'existe pas.\n",
- RFIFOP (fd, 6));
- }
- else
- {
- printf
- ("Account [%s] final date of banishment changing failed. Account doesn't exist.\n",
- RFIFOP (fd, 6));
- ladmin_log
- ("Account [%s] final date of banishment changing failed. Account doesn't exist.\n",
- RFIFOP (fd, 6));
- }
+ PRINTF("Account [%s] final date of banishment changing failed. Account doesn't exist.\n",
+ static_cast<const char *>(RFIFOP(fd, 6)));
+ LADMIN_LOG("Account [%s] final date of banishment changing failed. Account doesn't exist.\n",
+ static_cast<const char *>(RFIFOP(fd, 6)));
}
else
{
- time_t timestamp = RFIFOL (fd, 30);
- if (timestamp == 0)
+ TimeT timestamp = static_cast<time_t>(RFIFOL(fd, 30));
+ if (!timestamp)
{
- if (defaultlanguage == 'F')
- {
- printf
- ("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] changée avec succès en [dé-bannie].\n",
- RFIFOP (fd, 6), RFIFOL (fd, 2));
- }
- else
- {
- printf
- ("Final date of banishment of the account [%s][id: %d] successfully changed to [unbanished].\n",
- RFIFOP (fd, 6), RFIFOL (fd, 2));
- ladmin_log
- ("Final date of banishment of the account [%s][id: %d] successfully changed to [unbanished].\n",
- RFIFOP (fd, 6), RFIFOL (fd, 2));
- }
+ PRINTF("Final date of banishment of the account [%s][id: %d] successfully changed to [unbanished].\n",
+ static_cast<const char *>(RFIFOP(fd, 6)), RFIFOL(fd, 2));
+ LADMIN_LOG("Final date of banishment of the account [%s][id: %d] successfully changed to [unbanished].\n",
+ static_cast<const char *>(RFIFOP(fd, 6)), RFIFOL(fd, 2));
}
else
{
- char tmpstr[128];
- strftime (tmpstr, 24, date_format,
- localtime (&timestamp));
- if (defaultlanguage == 'F')
- {
- printf
- ("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] changée avec succès pour être jusqu'au %s.\n",
- RFIFOP (fd, 6), RFIFOL (fd, 2),
- tmpstr);
- }
- else
- {
- printf
- ("Final date of banishment of the account [%s][id: %d] successfully changed to be until %s.\n",
- RFIFOP (fd, 6), RFIFOL (fd, 2), tmpstr);
- ladmin_log
- ("Final date of banishment of the account [%s][id: %d] successfully changed to be until %s.\n",
- RFIFOP (fd, 6), RFIFOL (fd, 2),
- tmpstr);
- }
+ timestamp_seconds_buffer tmpstr;
+ stamp_time(tmpstr, &timestamp);
+ PRINTF("Final date of banishment of the account [%s][id: %d] successfully changed to be until %s.\n",
+ static_cast<const char *>(RFIFOP(fd, 6)), RFIFOL(fd, 2), tmpstr);
+ LADMIN_LOG("Final date of banishment of the account [%s][id: %d] successfully changed to be until %s.\n",
+ static_cast<const char *>(RFIFOP(fd, 6)), RFIFOL(fd, 2),
+ tmpstr);
}
}
bytes_to_read = 0;
- RFIFOSKIP (fd, 34);
+ RFIFOSKIP(fd, 34);
break;
case 0x794d: // answer of an account ban date/time changing
- if (RFIFOREST (fd) < 34)
+ if (RFIFOREST(fd) < 34)
return;
- if (RFIFOL (fd, 2) == -1)
+ if (RFIFOL(fd, 2) == -1)
{
- if (defaultlanguage == 'F')
- {
- printf
- ("Echec du changement de la date finale de banissement du compte [%s]. Le compte n'existe pas.\n",
- RFIFOP (fd, 6));
- ladmin_log
- ("Echec du changement de la date finale de banissement du compte [%s]. Le compte n'existe pas.\n",
- RFIFOP (fd, 6));
- }
- else
- {
- printf
- ("Account [%s] final date of banishment changing failed. Account doesn't exist.\n",
- RFIFOP (fd, 6));
- ladmin_log
- ("Account [%s] final date of banishment changing failed. Account doesn't exist.\n",
- RFIFOP (fd, 6));
- }
+ PRINTF("Account [%s] final date of banishment changing failed. Account doesn't exist.\n",
+ static_cast<const char *>(RFIFOP(fd, 6)));
+ LADMIN_LOG("Account [%s] final date of banishment changing failed. Account doesn't exist.\n",
+ static_cast<const char *>(RFIFOP(fd, 6)));
}
else
{
- time_t timestamp = RFIFOL (fd, 30);
- if (timestamp == 0)
+ TimeT timestamp = static_cast<time_t>(RFIFOL(fd, 30));
+ if (!timestamp)
{
- if (defaultlanguage == 'F')
- {
- printf
- ("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] changée avec succès en [dé-bannie].\n",
- RFIFOP (fd, 6), RFIFOL (fd, 2));
- }
- else
- {
- printf
- ("Final date of banishment of the account [%s][id: %d] successfully changed to [unbanished].\n",
- RFIFOP (fd, 6), RFIFOL (fd, 2));
- ladmin_log
- ("Final date of banishment of the account [%s][id: %d] successfully changed to [unbanished].\n",
- RFIFOP (fd, 6), RFIFOL (fd, 2));
- }
+ PRINTF("Final date of banishment of the account [%s][id: %d] successfully changed to [unbanished].\n",
+ static_cast<const char *>(RFIFOP(fd, 6)), RFIFOL(fd, 2));
+ LADMIN_LOG("Final date of banishment of the account [%s][id: %d] successfully changed to [unbanished].\n",
+ static_cast<const char *>(RFIFOP(fd, 6)), RFIFOL(fd, 2));
}
else
{
- char tmpstr[128];
- strftime (tmpstr, 24, date_format,
- localtime (&timestamp));
- if (defaultlanguage == 'F')
- {
- printf
- ("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] changée avec succès pour être jusqu'au %s.\n",
- RFIFOP (fd, 6), RFIFOL (fd, 2),
- tmpstr);
- }
- else
- {
- printf
- ("Final date of banishment of the account [%s][id: %d] successfully changed to be until %s.\n",
- RFIFOP (fd, 6), RFIFOL (fd, 2), tmpstr);
- ladmin_log
- ("Final date of banishment of the account [%s][id: %d] successfully changed to be until %s.\n",
- RFIFOP (fd, 6), RFIFOL (fd, 2),
- tmpstr);
- }
+ timestamp_seconds_buffer tmpstr;
+ stamp_time(tmpstr, &timestamp);
+ PRINTF("Final date of banishment of the account [%s][id: %d] successfully changed to be until %s.\n",
+ static_cast<const char *>(RFIFOP(fd, 6)), RFIFOL(fd, 2),
+ tmpstr);
+ LADMIN_LOG("Final date of banishment of the account [%s][id: %d] successfully changed to be until %s.\n",
+ static_cast<const char *>(RFIFOP(fd, 6)), RFIFOL(fd, 2),
+ tmpstr);
}
}
bytes_to_read = 0;
- RFIFOSKIP (fd, 34);
+ RFIFOSKIP(fd, 34);
break;
case 0x794f: // answer of a broadcast
- if (RFIFOREST (fd) < 4)
+ if (RFIFOREST(fd) < 4)
return;
- if (RFIFOW (fd, 2) == (unsigned short) -1)
+ if (RFIFOW(fd, 2) == (unsigned short) -1)
{
- if (defaultlanguage == 'F')
- {
- printf
- ("Echec de l'envoi du message. Aucun server de char en ligne.\n");
- ladmin_log
- ("Echec de l'envoi du message. Aucun server de char en ligne.\n");
- }
- else
- {
- printf
- ("Message sending failed. No online char-server.\n");
- ladmin_log
- ("Message sending failed. No online char-server.\n");
- }
+ PRINTF("Message sending failed. No online char-server.\n");
+ LADMIN_LOG("Message sending failed. No online char-server.\n");
}
else
{
- if (defaultlanguage == 'F')
- {
- printf
- ("Message transmis au server de logins avec succès.\n");
- ladmin_log
- ("Message transmis au server de logins avec succès.\n");
- }
- else
- {
- printf
- ("Message successfully sended to login-server.\n");
- ladmin_log
- ("Message successfully sended to login-server.\n");
- }
+ PRINTF("Message successfully sended to login-server.\n");
+ LADMIN_LOG("Message successfully sended to login-server.\n");
}
bytes_to_read = 0;
- RFIFOSKIP (fd, 4);
+ RFIFOSKIP(fd, 4);
break;
case 0x7951: // answer of an account validity limit changing
- if (RFIFOREST (fd) < 34)
+ if (RFIFOREST(fd) < 34)
return;
- if (RFIFOL (fd, 2) == -1)
+ if (RFIFOL(fd, 2) == -1)
{
- if (defaultlanguage == 'F')
- {
- printf
- ("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.\n",
- RFIFOP (fd, 6));
- }
- else
- {
- printf
- ("Account [%s] validity limit changing failed. Account doesn't exist.\n",
- RFIFOP (fd, 6));
- ladmin_log
- ("Account [%s] validity limit changing failed. Account doesn't exist.\n",
- RFIFOP (fd, 6));
- }
+ PRINTF("Account [%s] validity limit changing failed. Account doesn't exist.\n",
+ static_cast<const char *>(RFIFOP(fd, 6)));
+ LADMIN_LOG("Account [%s] validity limit changing failed. Account doesn't exist.\n",
+ static_cast<const char *>(RFIFOP(fd, 6)));
}
else
{
- time_t timestamp = RFIFOL (fd, 30);
- if (timestamp == 0)
+ TimeT timestamp = static_cast<time_t>(RFIFOL(fd, 30));
+ if (!timestamp)
{
- if (defaultlanguage == 'F')
- {
- printf
- ("Limite de validité du compte [%s][id: %d] inchangée.\n",
- RFIFOP (fd, 6), RFIFOL (fd, 2));
- printf
- ("Le compte a une validité illimitée ou\n");
- printf
- ("la modification est impossible avec les ajustements demandés.\n");
- ladmin_log
- ("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.\n",
- RFIFOP (fd, 6), RFIFOL (fd, 2));
- }
- else
- {
- printf
- ("Validity limit of the account [%s][id: %d] unchanged.\n",
- RFIFOP (fd, 6), RFIFOL (fd, 2));
- printf
- ("The account have an unlimited validity limit or\n");
- printf
- ("the changing is impossible with the proposed adjustments.\n");
- ladmin_log
- ("Validity limit of the account [%s][id: %d] unchanged. The account have an unlimited validity limit or the changing is impossible with the proposed adjustments.\n",
- RFIFOP (fd, 6), RFIFOL (fd, 2));
- }
+ PRINTF("Validity limit of the account [%s][id: %d] unchanged.\n",
+ static_cast<const char *>(RFIFOP(fd, 6)), RFIFOL(fd, 2));
+ PRINTF("The account have an unlimited validity limit or\n");
+ PRINTF("the changing is impossible with the proposed adjustments.\n");
+ LADMIN_LOG("Validity limit of the account [%s][id: %d] unchanged. The account have an unlimited validity limit or the changing is impossible with the proposed adjustments.\n",
+ static_cast<const char *>(RFIFOP(fd, 6)), RFIFOL(fd, 2));
}
else
{
- char tmpstr[128];
- strftime (tmpstr, 24, date_format,
- localtime (&timestamp));
- if (defaultlanguage == 'F')
- {
- printf
- ("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] changée avec succès pour être jusqu'au %s.\n",
- RFIFOP (fd, 6), RFIFOL (fd, 2),
- tmpstr);
- }
- else
- {
- printf
- ("Validity limit of the account [%s][id: %d] successfully changed to be until %s.\n",
- RFIFOP (fd, 6), RFIFOL (fd, 2), tmpstr);
- ladmin_log
- ("Validity limit of the account [%s][id: %d] successfully changed to be until %s.\n",
- RFIFOP (fd, 6), RFIFOL (fd, 2),
- tmpstr);
- }
+ timestamp_seconds_buffer tmpstr;
+ stamp_time(tmpstr, &timestamp);
+ PRINTF("Validity limit of the account [%s][id: %d] successfully changed to be until %s.\n",
+ static_cast<const char *>(RFIFOP(fd, 6)), RFIFOL(fd, 2),
+ tmpstr);
+ LADMIN_LOG("Validity limit of the account [%s][id: %d] successfully changed to be until %s.\n",
+ static_cast<const char *>( RFIFOP(fd, 6)), RFIFOL(fd, 2),
+ tmpstr);
}
}
bytes_to_read = 0;
- RFIFOSKIP (fd, 34);
+ RFIFOSKIP(fd, 34);
break;
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)))
+ if (RFIFOREST(fd) < 150
+ || RFIFOREST(fd) < (150 + RFIFOW(fd, 148)))
return;
{
char userid[24], error_message[20], lastlogin[24],
last_ip[16], email[40], memo[255];
- 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)
- memcpy (userid, RFIFOP (fd, 7), sizeof (userid));
- userid[sizeof (userid) - 1] = '\0';
- memcpy (error_message, RFIFOP (fd, 40),
- sizeof (error_message));
- error_message[sizeof (error_message) - 1] = '\0';
- memcpy (lastlogin, RFIFOP (fd, 60), sizeof (lastlogin));
- lastlogin[sizeof (lastlogin) - 1] = '\0';
- memcpy (last_ip, RFIFOP (fd, 84), sizeof (last_ip));
- last_ip[sizeof (last_ip) - 1] = '\0';
- memcpy (email, RFIFOP (fd, 100), sizeof (email));
- email[sizeof (email) - 1] = '\0';
- connect_until_time = (time_t) RFIFOL (fd, 140);
- ban_until_time = (time_t) RFIFOL (fd, 144);
- memset (memo, '\0', sizeof (memo));
- strncpy (memo, (const char *)RFIFOP (fd, 150), RFIFOW (fd, 148));
- if (RFIFOL (fd, 2) == -1)
- {
- if (defaultlanguage == 'F')
- {
- printf
- ("Impossible de trouver le compte [%s]. Le compte n'existe pas.\n",
- parameters);
- ladmin_log
- ("Impossible de trouver le compte [%s]. Le compte n'existe pas.\n",
- parameters);
- }
- else
- {
- printf
- ("Unabled to find the account [%s]. Account doesn't exist.\n",
- parameters);
- ladmin_log
- ("Unabled to find the account [%s]. Account doesn't exist.\n",
- parameters);
- }
- }
- else if (strlen (userid) == 0)
- {
- if (defaultlanguage == 'F')
- {
- printf
- ("Impossible de trouver le compte [id: %s]. Le compte n'existe pas.\n",
- parameters);
- ladmin_log
- ("Impossible de trouver le compte [id: %s]. Le compte n'existe pas.\n",
- parameters);
- }
- else
- {
- printf
- ("Unabled to find the account [id: %s]. Account doesn't exist.\n",
- parameters);
- ladmin_log
- ("Unabled to find the account [id: %s]. Account doesn't exist.\n",
- parameters);
- }
+ TimeT ban_until_time; // # of seconds 1/1/1970 (timestamp): ban time limit of the account (0 = no ban)
+ TimeT connect_until_time; // # of seconds 1/1/1970 (timestamp): Validity limit of the account (0 = unlimited)
+ memcpy(userid, RFIFOP(fd, 7), sizeof(userid));
+ userid[sizeof(userid) - 1] = '\0';
+ memcpy(error_message, RFIFOP(fd, 40),
+ sizeof(error_message));
+ error_message[sizeof(error_message) - 1] = '\0';
+ memcpy(lastlogin, RFIFOP(fd, 60), sizeof(lastlogin));
+ lastlogin[sizeof(lastlogin) - 1] = '\0';
+ memcpy(last_ip, RFIFOP(fd, 84), sizeof(last_ip));
+ last_ip[sizeof(last_ip) - 1] = '\0';
+ memcpy(email, RFIFOP(fd, 100), sizeof(email));
+ email[sizeof(email) - 1] = '\0';
+ connect_until_time = static_cast<time_t>(RFIFOL(fd, 140));
+ ban_until_time = static_cast<time_t>(RFIFOL(fd, 144));
+ memset(memo, '\0', sizeof(memo));
+ strncpy(memo, (const char *)RFIFOP(fd, 150), RFIFOW(fd, 148));
+ if (RFIFOL(fd, 2) == -1)
+ {
+ PRINTF("Unabled to find the account [%s]. Account doesn't exist.\n",
+ parameters);
+ LADMIN_LOG("Unabled to find the account [%s]. Account doesn't exist.\n",
+ parameters);
+ }
+ else if (strlen(userid) == 0)
+ {
+ PRINTF("Unabled to find the account [id: %s]. Account doesn't exist.\n",
+ parameters);
+ LADMIN_LOG("Unabled to find the account [id: %s]. Account doesn't exist.\n",
+ parameters);
}
else
{
- if (defaultlanguage == 'F')
- {
- ladmin_log
- ("Réception d'information concernant un compte.\n");
- printf
- ("Le compte a les caractéristiques suivantes:\n");
- }
- else
+ LADMIN_LOG("Receiving information about an account.\n");
+ PRINTF("The account is set with:\n");
+ if (RFIFOB(fd, 6) == 0)
{
- ladmin_log
- ("Receiving information about an account.\n");
- printf ("The account is set with:\n");
- }
- if (RFIFOB (fd, 6) == 0)
- {
- printf (" Id: %d (non-GM)\n", RFIFOL (fd, 2));
+ PRINTF(" Id: %d (non-GM)\n", RFIFOL(fd, 2));
}
else
{
- if (defaultlanguage == 'F')
- {
- printf (" Id: %d (GM niveau %d)\n",
- RFIFOL (fd, 2), (int) RFIFOB (fd, 6));
- }
- else
- {
- printf (" Id: %d (GM level %d)\n",
- RFIFOL (fd, 2), (int) RFIFOB (fd, 6));
- }
- }
- if (defaultlanguage == 'F')
- {
- printf (" Nom: '%s'\n", userid);
- if (RFIFOB (fd, 31) == 0)
- printf (" Sexe: Femme\n");
- else if (RFIFOB (fd, 31) == 1)
- printf (" Sexe: Male\n");
- else
- printf (" Sexe: Serveur\n");
+ PRINTF(" Id: %d (GM level %d)\n",
+ RFIFOL(fd, 2), (int) RFIFOB(fd, 6));
}
+ PRINTF(" Name: '%s'\n", userid);
+ if (RFIFOB(fd, 31) == 0)
+ PRINTF(" Sex: Female\n");
+ else if (RFIFOB(fd, 31) == 1)
+ PRINTF(" Sex: Male\n");
else
- {
- printf (" Name: '%s'\n", userid);
- if (RFIFOB (fd, 31) == 0)
- printf (" Sex: Female\n");
- else if (RFIFOB (fd, 31) == 1)
- printf (" Sex: Male\n");
- else
- printf (" Sex: Server\n");
- }
- printf (" E-mail: %s\n", email);
- switch (RFIFOL (fd, 36))
+ PRINTF(" Sex: Server\n");
+ PRINTF(" E-mail: %s\n", email);
+ switch (RFIFOL(fd, 36))
{
case 0:
- if (defaultlanguage == 'F')
- printf (" Statut: 0 [Compte Ok]\n");
- else
- printf (" Statut: 0 [Account OK]\n");
+ PRINTF(" Statut: 0 [Account OK]\n");
break;
case 1:
- printf (" Statut: 1 [Unregistered ID]\n");
+ PRINTF(" Statut: 1 [Unregistered ID]\n");
break;
case 2:
- printf (" Statut: 2 [Incorrect Password]\n");
+ PRINTF(" Statut: 2 [Incorrect Password]\n");
break;
case 3:
- printf (" Statut: 3 [This ID is expired]\n");
+ PRINTF(" Statut: 3 [This ID is expired]\n");
break;
case 4:
- printf
- (" Statut: 4 [Rejected from Server]\n");
+ PRINTF(" Statut: 4 [Rejected from Server]\n");
break;
case 5:
- printf
- (" Statut: 5 [You have been blocked by the GM Team]\n");
+ PRINTF(" Statut: 5 [You have been blocked by the GM Team]\n");
break;
case 6:
- printf
- (" Statut: 6 [Your Game's EXE file is not the latest version]\n");
+ PRINTF(" Statut: 6 [Your Game's EXE file is not the latest version]\n");
break;
case 7:
- printf
- (" Statut: 7 [You are Prohibited to log in until %s]\n",
+ PRINTF(" Statut: 7 [You are Prohibited to log in until %s]\n",
error_message);
break;
case 8:
- printf
- (" Statut: 8 [Server is jammed due to over populated]\n");
+ PRINTF(" Statut: 8 [Server is jammed due to over populated]\n");
break;
case 9:
- printf (" Statut: 9 [No MSG]\n");
+ PRINTF(" Statut: 9 [No MSG]\n");
break;
default: // 100
- printf
- (" Statut: %d [This ID is totally erased]\n",
- RFIFOL (fd, 36));
+ PRINTF(" Statut: %d [This ID is totally erased]\n",
+ RFIFOL(fd, 36));
break;
}
- if (defaultlanguage == 'F')
+ if (!ban_until_time)
{
- if (ban_until_time == 0)
- {
- printf (" Banissement: non banni.\n");
- }
- else
- {
- char tmpstr[128];
- strftime (tmpstr, 24, date_format,
- localtime (&ban_until_time));
- printf (" Banissement: jusqu'au %s.\n",
- tmpstr);
- }
- if (RFIFOL (fd, 32) > 1)
- printf (" Compteur: %d connexions.\n",
- RFIFOL (fd, 32));
- else
- printf (" Compteur: %d connexion.\n",
- RFIFOL (fd, 32));
- printf (" Dernière connexion le: %s (ip: %s)\n",
- lastlogin, last_ip);
- if (connect_until_time == 0)
- {
- 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",
- tmpstr);
- }
+ PRINTF(" Banishment: not banished.\n");
}
else
{
- if (ban_until_time == 0)
- {
- printf (" Banishment: not banished.\n");
- }
- else
- {
- char tmpstr[128];
- strftime (tmpstr, 24, date_format,
- localtime (&ban_until_time));
- printf (" Banishment: until %s.\n", tmpstr);
- }
- if (RFIFOL (fd, 32) > 1)
- printf (" Count: %d connections.\n",
- RFIFOL (fd, 32));
- else
- printf (" Count: %d connection.\n",
- RFIFOL (fd, 32));
- printf (" Last connection at: %s (ip: %s)\n",
- lastlogin, last_ip);
- if (connect_until_time == 0)
- {
- printf (" Validity limit: unlimited.\n");
- }
- else
- {
- char tmpstr[128];
- strftime (tmpstr, 24, date_format,
- localtime (&connect_until_time));
- printf (" Validity limit: until %s.\n",
- tmpstr);
- }
+ timestamp_seconds_buffer tmpstr;
+ stamp_time(tmpstr, &ban_until_time);
+ PRINTF(" Banishment: until %s.\n", tmpstr);
+ }
+ if (RFIFOL(fd, 32) > 1)
+ PRINTF(" Count: %d connections.\n",
+ RFIFOL(fd, 32));
+ else
+ PRINTF(" Count: %d connection.\n",
+ RFIFOL(fd, 32));
+ PRINTF(" Last connection at: %s (ip: %s)\n",
+ lastlogin, last_ip);
+ if (!connect_until_time)
+ {
+ PRINTF(" Validity limit: unlimited.\n");
+ }
+ else
+ {
+ timestamp_seconds_buffer tmpstr;
+ stamp_time(tmpstr, &connect_until_time);
+ PRINTF(" Validity limit: until %s.\n",
+ tmpstr);
}
- printf (" Memo: '%s'\n", memo);
+ PRINTF(" Memo: '%s'\n", memo);
}
}
bytes_to_read = 0;
- RFIFOSKIP (fd, 150 + RFIFOW (fd, 148));
+ RFIFOSKIP(fd, 150 + RFIFOW(fd, 148));
break;
default:
- printf
- ("Remote administration has been disconnected (unknown packet).\n");
- ladmin_log ("'End of connection, unknown packet.\n");
+ PRINTF("Remote administration has been disconnected (unknown packet).\n");
+ LADMIN_LOG("'End of connection, unknown packet.\n");
session[fd]->eof = 1;
return;
}
}
// if we don't wait new packets, do the prompt
- prompt ();
+ prompt();
}
//------------------------------------
// Function to connect to login-server
//------------------------------------
static
-int Connect_login_server (void)
+int Connect_login_server(void)
{
- if (defaultlanguage == 'F')
- {
- Iprintf ("Essai de connection au server de logins...\n");
- ladmin_log ("Essai de connection au server de logins...\n");
- }
- else
- {
- Iprintf ("Attempt to connect to login-server...\n");
- ladmin_log ("Attempt to connect to login-server...\n");
- }
+ Iprintf("Attempt to connect to login-server...\n");
+ LADMIN_LOG("Attempt to connect to login-server...\n");
- if ((login_fd = make_connection (login_ip, loginserverport)) < 0)
+ if ((login_fd = make_connection(login_ip, loginserverport)) < 0)
return 0;
-#ifdef PASSWORDENC
if (passenc == 0)
{
-#endif
- WFIFOW (login_fd, 0) = 0x7918; // Request for administation login
- WFIFOW (login_fd, 2) = 0; // no encrypted
- memcpy (WFIFOP (login_fd, 4), loginserveradminpassword, 24);
- WFIFOSET (login_fd, 28);
+ WFIFOW(login_fd, 0) = 0x7918; // Request for administation login
+ WFIFOW(login_fd, 2) = 0; // no encrypted
+ memcpy(WFIFOP(login_fd, 4), loginserveradminpassword, 24);
+ WFIFOSET(login_fd, 28);
bytes_to_read = 1;
- if (defaultlanguage == 'F')
- {
- Iprintf ("Envoi du mot de passe...\n");
- ladmin_log ("Envoi du mot de passe...\n");
- }
- else
- {
- Iprintf ("Sending of the password...\n");
- ladmin_log ("Sending of the password...\n");
- }
-#ifdef PASSWORDENC
+ Iprintf("Sending of the password...\n");
+ LADMIN_LOG("Sending of the password...\n");
}
else
{
- WFIFOW (login_fd, 0) = 0x791a; // Sending request about the coding key
- WFIFOSET (login_fd, 2);
+ WFIFOW(login_fd, 0) = 0x791a; // Sending request about the coding key
+ WFIFOSET(login_fd, 2);
bytes_to_read = 1;
- if (defaultlanguage == 'F')
- {
- Iprintf ("Demande de la clef MD5...\n");
- ladmin_log ("Demande de la clef MD5...\n");
- }
- else
- {
- Iprintf ("Request about the MD5 key...\n");
- ladmin_log ("Request about the MD5 key...\n");
- }
+ Iprintf("Request about the MD5 key...\n");
+ LADMIN_LOG("Request about the MD5 key...\n");
}
-#endif
return 0;
}
@@ -6212,147 +3566,74 @@ int Connect_login_server (void)
// Reading general configuration file
//-----------------------------------
static
-int ladmin_config_read (const char *cfgName)
+int ladmin_config_read(const char *cfgName)
{
- char line[1024], w1[1024], w2[1024];
- FILE *fp;
-
- fp = fopen_ (cfgName, "r");
- if (fp == NULL)
+ std::ifstream in(cfgName);
+ if (!in.is_open())
{
- if (defaultlanguage == 'F')
- {
- printf ("\033[0mFichier de configuration (%s) non trouvé.\n",
- cfgName);
- }
- else
- {
- printf ("\033[0mConfiguration file (%s) not found.\n", cfgName);
- }
+ PRINTF("\033[0mConfiguration file (%s) not found.\n", cfgName);
return 1;
}
- if (defaultlanguage == 'F')
- {
- Iprintf
- ("\033[0m---Début de lecture du fichier de configuration Ladmin (%s)\n",
- cfgName);
- }
- else
+ Iprintf("\033[0m---Start reading of Ladmin configuration file (%s)\n",
+ cfgName);
+ std::string line;
+ while (std::getline(in, line))
{
- Iprintf
- ("\033[0m---Start reading of Ladmin configuration file (%s)\n",
- cfgName);
- }
- while (fgets (line, sizeof (line) - 1, fp))
- {
- if (line[0] == '/' && line[1] == '/')
+ std::string w1, w2;
+ if (!split_key_value(line, &w1, &w2))
continue;
- line[sizeof (line) - 1] = '\0';
- if (sscanf (line, "%[^:]: %[^\r\n]", w1, w2) == 2)
+ if (w1 == "login_ip")
{
- remove_control_chars (w1);
- remove_control_chars (w2);
-
- if (strcasecmp (w1, "login_ip") == 0)
- {
- struct hostent *h = gethostbyname (w2);
- if (h != NULL)
- {
- if (defaultlanguage == 'F')
- {
- Iprintf
- ("Adresse du serveur de logins: %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]);
- }
- else
- {
- Iprintf
- ("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 (loginserverip, "%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 (loginserverip, w2, 16);
- }
- else if (strcasecmp (w1, "login_port") == 0)
- {
- loginserverport = atoi (w2);
- }
- else if (strcasecmp (w1, "admin_pass") == 0)
- {
- strncpy (loginserveradminpassword, w2,
- sizeof (loginserveradminpassword));
- loginserveradminpassword[sizeof (loginserveradminpassword) -
- 1] = '\0';
-#ifdef PASSWORDENC
- }
- else if (strcasecmp (w1, "passenc") == 0)
- {
- passenc = atoi (w2);
- if (passenc < 0 || passenc > 2)
- passenc = 0;
-#endif
- }
- else if (strcasecmp (w1, "defaultlanguage") == 0)
+ struct hostent *h = gethostbyname(w2.c_str());
+ if (h != NULL)
{
- if (w2[0] == 'F' || w2[0] == 'E')
- defaultlanguage = w2[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 (strcasecmp (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 (strcasecmp (w1, "import") == 0)
- {
- ladmin_config_read (w2);
+ Iprintf("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(loginserverip, "%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
+ strzcpy(loginserverip, w2.c_str(), 16);
+ }
+ else if (w1 == "login_port")
+ {
+ loginserverport = atoi(w2.c_str());
+ }
+ else if (w1 == "admin_pass")
+ {
+ strzcpy(loginserveradminpassword, w2.c_str(), sizeof(loginserveradminpassword));
+ }
+ else if (w1 == "passenc")
+ {
+ passenc = atoi(w2.c_str());
+ if (passenc < 0 || passenc > 2)
+ passenc = 0;
+ }
+ else if (w1 == "ladmin_log_filename")
+ {
+ strzcpy(ladmin_log_filename, w2.c_str(), sizeof(ladmin_log_filename));
+ }
+ else if (w1 == "import")
+ {
+ ladmin_config_read(w2.c_str());
+ }
+ else
+ {
+ PRINTF("WARNING: unknown ladmin config key: %s\n", w1);
}
}
- fclose_ (fp);
- login_ip = inet_addr (loginserverip);
+ login_ip = inet_addr(loginserverip);
- if (defaultlanguage == 'F')
- {
- Iprintf ("---Lecture du fichier de configuration Ladmin terminée.\n");
- }
- else
- {
- Iprintf ("---End reading of Ladmin configuration file.\n");
- }
+ Iprintf("---End reading of Ladmin configuration file.\n");
return 0;
}
@@ -6360,27 +3641,15 @@ int ladmin_config_read (const char *cfgName)
//--------------------------------------
// Function called at exit of the server
//--------------------------------------
-void term_func (void)
+void term_func(void)
{
if (already_exit_function == 0)
{
- delete_session (login_fd);
+ delete_session(login_fd);
- if (defaultlanguage == 'F')
- {
- Iprintf
- ("\033[0m----Fin de Ladmin (fin normale avec fermeture de tous les fichiers).\n");
- ladmin_log
- ("----Fin de Ladmin (fin normale avec fermeture de tous les fichiers).\n");
- }
- else
- {
- Iprintf
- ("\033[0m----End of Ladmin (normal end with closing of all files).\n");
- ladmin_log
- ("----End of Ladmin (normal end with closing of all files).\n");
- }
+ Iprintf("\033[0m----End of Ladmin (normal end with closing of all files).\n");
+ LADMIN_LOG("----End of Ladmin (normal end with closing of all files).\n");
already_exit_function = 1;
}
@@ -6389,51 +3658,25 @@ void term_func (void)
//------------------------
// Main function of ladmin
//------------------------
-int do_init (int argc, char **argv)
+int do_init(int argc, char **argv)
{
- eathena_interactive_session = isatty (0);
+ eathena_interactive_session = isatty(0);
// read ladmin configuration
- ladmin_config_read ((argc > 1) ? argv[1] : LADMIN_CONF_NAME);
+ ladmin_config_read((argc > 1) ? argv[1] : LADMIN_CONF_NAME);
- ladmin_log ("");
- if (defaultlanguage == 'F')
- {
- ladmin_log ("Fichier de configuration lu.\n");
- }
- else
- {
- ladmin_log ("Configuration file readed.\n");
- }
+ LADMIN_LOG("");
+ LADMIN_LOG("Configuration file readed.\n");
- srand (time (NULL));
+ set_defaultparse(parse_fromlogin);
- set_defaultparse (parse_fromlogin);
+ Iprintf("EAthena login-server administration tool.\n");
+ Iprintf("(for eAthena version %d.%d.%d.)\n", ATHENA_MAJOR_VERSION,
+ ATHENA_MINOR_VERSION, ATHENA_REVISION);
- if (defaultlanguage == 'F')
- {
- Iprintf ("Outil d'administration à distance de eAthena.\n");
- Iprintf ("(pour eAthena version %d.%d.%d.)\n", ATHENA_MAJOR_VERSION,
- ATHENA_MINOR_VERSION, ATHENA_REVISION);
- }
- else
- {
- Iprintf ("EAthena login-server administration tool.\n");
- Iprintf ("(for eAthena version %d.%d.%d.)\n", ATHENA_MAJOR_VERSION,
- ATHENA_MINOR_VERSION, ATHENA_REVISION);
- }
-
- if (defaultlanguage == 'F')
- {
- ladmin_log ("Ladmin est prêt.\n");
- Iprintf ("Ladmin est \033[1;32mprêt\033[0m.\n\n");
- }
- else
- {
- ladmin_log ("Ladmin is ready.\n");
- Iprintf ("Ladmin is \033[1;32mready\033[0m.\n\n");
- }
+ LADMIN_LOG("Ladmin is ready.\n");
+ Iprintf("Ladmin is \033[1;32mready\033[0m.\n\n");
- Connect_login_server ();
+ Connect_login_server();
return 0;
}
diff --git a/src/ladmin/ladmin.hpp b/src/ladmin/ladmin.hpp
deleted file mode 100644
index 77d7fe4..0000000
--- a/src/ladmin/ladmin.hpp
+++ /dev/null
@@ -1,11 +0,0 @@
-// $Id: ladmin.h,v 1.1.1.1 2004/09/10 17:26:52 MagicalTux Exp $
-#ifndef LADMIN_HPP
-#define LADMIN_HPP
-
-#define LADMIN_CONF_NAME "conf/ladmin_athena.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.
-
-#endif
diff --git a/src/login/login.cpp b/src/login/login.cpp
index ce3fd4e..e07b7cb 100644
--- a/src/login/login.cpp
+++ b/src/login/login.cpp
@@ -1,73 +1,120 @@
-// $Id: login.c,v 1.1.1.1 2004/09/10 17:26:53 MagicalTux Exp $
-// new version of the login-server by [Yor]
-
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <netinet/in.h>
-#include <sys/time.h>
-#include <time.h>
-#include <sys/ioctl.h>
-#include <sys/stat.h> // for stat/lstat/fstat
-#include <unistd.h>
-#include <signal.h>
-#include <fcntl.h>
-#include <string.h>
#include <arpa/inet.h>
-#include <netdb.h>
+#include <sys/types.h>
#include <sys/wait.h>
+#include <netdb.h>
+#include <unistd.h>
+
+#include <cstdlib>
+#include <cstring>
+#include <ctime>
+
+#include <algorithm>
+#include <fstream>
+#include <type_traits>
+
#include "../common/core.hpp"
+#include "../common/cxxstdio.hpp"
+#include "../common/db.hpp"
+#include "../common/extract.hpp"
+#include "../common/lock.hpp"
+#include "../common/md5calc.hpp"
+#include "../common/mmo.hpp"
+#include "../common/random.hpp"
#include "../common/socket.hpp"
#include "../common/timer.hpp"
-#include "login.hpp"
-#include "../common/mmo.hpp"
#include "../common/version.hpp"
-#include "../common/db.hpp"
-#include "../common/lock.hpp"
-#include "../common/mt_rand.hpp"
+#include "../common/utils.hpp"
-#include "../common/md5calc.hpp"
+#include "../poison.hpp"
-#ifdef MEMWATCH
-#include "memwatch.hpp"
-#endif
+constexpr int MAX_SERVERS = 30;
-#include <type_traits>
-static_assert(std::is_same<time_t, long>::value, "much code assumes time_t is a long");
+#define LOGIN_CONF_NAME "conf/login_athena.conf"
+#define LAN_CONF_NAME "conf/lan_support.conf"
+
+constexpr int START_ACCOUNT_NUM = 2000000;
+constexpr int END_ACCOUNT_NUM = 100000000;
-int account_id_count = START_ACCOUNT_NUM;
-int server_num;
-int new_account_flag = 0;
-int login_port = 6900;
+struct mmo_account
+{
+ char userid[24];
+ char passwd[24];
+ 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 is_new;
+};
+
+static
+int account_id_count = START_ACCOUNT_NUM;
+static
+int server_num;
+static
+int new_account_flag = 0;
+static
+int login_port = 6900;
+static
char lan_char_ip[16];
-int subneti[4];
-int subnetmaski[4];
+static
+int subneti[4];
+static
+int subnetmaski[4];
+static
char update_host[128] = "";
+static
char main_server[20] = "";
+static
char account_filename[1024] = "save/account.txt";
+static
char GM_account_filename[1024] = "conf/GM_account.txt";
+static
char login_log_filename[1024] = "log/login.log";
+static
char login_log_unknown_packets_filename[1024] =
"log/login_unknown_packets.log";
-char date_format[32] = "%Y-%m-%d %H:%M:%S";
-int save_unknown_packets = 0;
-long creation_time_GM_account_file;
-int gm_account_filename_check_timer = 15; // Timer to check if GM_account file has been changed and reload GM account automaticaly (in seconds; default: 15)
+static
+int save_unknown_packets = 0;
+static
+tick_t creation_time_GM_account_file;
+static
+std::chrono::seconds gm_account_filename_check_timer = std::chrono::seconds(15);
-int display_parse_login = 0; // 0: no, 1: yes
-int display_parse_admin = 0; // 0: no, 1: yes
-int display_parse_fromchar = 0; // 0: no, 1: yes (without packet 0x2714), 2: all packets
+static
+int display_parse_login = 0; // 0: no, 1: yes
+static
+int display_parse_admin = 0; // 0: no, 1: yes
+static
+int display_parse_fromchar = 0; // 0: no, 1: yes (without packet 0x2714), 2: all packets
+static
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;
+static
+int server_fd[MAX_SERVERS];
+static
+int server_freezeflag[MAX_SERVERS]; // Char-server anti-freeze system. Counter. 5 ok, 4...0 freezed
+static
+int anti_freeze_enable = 0;
+static
+std::chrono::seconds ANTI_FREEZE_INTERVAL = std::chrono::seconds(15);
-int login_fd;
+static
+int login_fd;
enum
{
@@ -77,95 +124,108 @@ enum
ACO_STRSIZE = 128,
};
-int access_order = ACO_DENY_ALLOW;
-int access_allownum = 0;
-int access_denynum = 0;
+static
+int access_order = ACO_DENY_ALLOW;
+static
+int access_allownum = 0;
+static
+int access_denynum = 0;
+static
char *access_allow = NULL;
+static
char *access_deny = NULL;
-int access_ladmin_allownum = 0;
+static
+int access_ladmin_allownum = 0;
+static
char *access_ladmin_allow = NULL;
-int min_level_to_connect = 0; // minimum level of player/GM (0: player, 1-99: gm) to connect on the server
-int add_to_unlimited_account = 0; // Give possibility or not to adjust (ladmin command: timeadd) the time of an unlimited account.
-int start_limited_time = -1; // Starting additional sec from now for the limited time at creation of accounts (-1: unlimited time, 0 or more: additional sec from now)
-int check_ip_flag = 1; // It's to check IP of a player between login-server and char-server (part of anti-hacking system)
+static
+int min_level_to_connect = 0; // minimum level of player/GM (0: player, 1-99: gm) to connect on the server
+static
+int add_to_unlimited_account = 0; // Give possibility or not to adjust (ladmin command: timeadd) the time of an unlimited account.
+static
+int start_limited_time = -1; // Starting additional sec from now for the limited time at creation of accounts (-1: unlimited time, 0 or more: additional sec from now)
+static
+int check_ip_flag = 1; // It's to check IP of a player between login-server and char-server (part of anti-hacking system)
struct login_session_data
{
- int md5keylen;
+ int md5keylen;
char md5key[20];
};
-#define AUTH_FIFO_SIZE 256
+constexpr int AUTH_FIFO_SIZE = 256;
struct
{
- int account_id, login_id1, login_id2;
- int ip, sex, delflag;
+ int account_id, login_id1, login_id2;
+ int ip, sex, delflag;
} auth_fifo[AUTH_FIFO_SIZE];
-int auth_fifo_pos = 0;
+static
+int auth_fifo_pos = 0;
+static
struct auth_dat
{
- int account_id, sex;
+ int account_id, sex;
char userid[24], pass[40], lastlogin[24];
- int logincount;
- int state; // packet 0x006a value + 1 (0: compte OK)
+ 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)
+ TimeT ban_until_time; // # of seconds 1/1/1970 (timestamp): ban time limit of the account (0 = no ban)
+ TimeT 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;
+ int account_reg2_num;
struct global_reg account_reg2[ACCOUNT_REG2_NUM];
} *auth_dat;
-int auth_num = 0, auth_max = 0;
+static
+int auth_num = 0, auth_max = 0;
-int admin_state = 0;
+static
+int admin_state = 0;
+static
char admin_pass[24] = "";
+static
char gm_pass[64] = "";
-int level_new_gm = 60;
+static
+int level_new_gm = 60;
-static struct dbt *gm_account_db;
+static
+Map<int, struct gm_account> gm_account_db;
+static
pid_t pid = 0; // For forked DB writes
-#define VERSION_2_UPDATEHOST 0x01 // client supports updatehost
-#define VERSION_2_SERVERORDER 0x02 // send servers in forward order
+namespace e
+{
+enum class VERSION_2 : uint8_t
+{
+ /// client supports updatehost
+ UPDATEHOST = 0x01,
+ /// send servers in forward order
+ SERVERORDER = 0x02,
+};
+ENUM_BITWISE_OPERATORS(VERSION_2)
+}
+using e::VERSION_2;
+
//------------------------------
// Writing function of logs file
//------------------------------
-static __attribute__((format(printf, 1, 2)))
-int login_log (const char *fmt, ...)
+#define LOGIN_LOG(fmt, ...) \
+ login_log(static_cast<const std::string&>(STRPRINTF(fmt, ## __VA_ARGS__)))
+static
+void login_log(const_string line)
{
- FILE *logfp;
- va_list ap;
- struct timeval tv;
- char tmpstr[2048];
-
- va_start (ap, fmt);
-
- logfp = fopen_ (login_log_filename, "a");
- if (logfp)
- {
- if (fmt[0] == '\0') // jump a line if no message
- fprintf (logfp, "\n");
- else
- {
- gettimeofday (&tv, NULL);
- strftime (tmpstr, 24, date_format, gmtime (&(tv.tv_sec)));
- sprintf (tmpstr + strlen (tmpstr), ".%03d: %s",
- (int) tv.tv_usec / 1000, fmt);
- vfprintf (logfp, tmpstr, ap);
- }
- fclose_ (logfp);
- }
-
- va_end (ap);
- return 0;
+ FILE *logfp = fopen_(login_log_filename, "a");
+ if (!logfp)
+ return;
+ log_with_timestamp(logfp, line);
+ fclose_(logfp);
}
//----------------------------------------------------------------------
@@ -173,9 +233,9 @@ int login_log (const char *fmt, ...)
// and returns its level (or 0 if it isn't a GM account or if not found)
//----------------------------------------------------------------------
static
-int isGM (int account_id)
+int isGM(int account_id)
{
- struct gm_account *p = (struct gm_account*) numdb_search (gm_account_db, account_id);
+ struct gm_account *p = gm_account_db.search(account_id);
if (p == NULL)
return 0;
return p->level;
@@ -185,96 +245,80 @@ int isGM (int account_id)
// Reading function of GM accounts file (and their level)
//-------------------------------------------------------
static
-int read_gm_account (void)
+int read_gm_account(void)
{
char line[512];
- struct gm_account *p;
FILE *fp;
- int c = 0;
- int GM_level;
- struct stat file_stat;
+ int c = 0;
+ int GM_level;
- free (gm_account_db);
- gm_account_db = numdb_init ();
+ gm_account_db.clear();
- // get last modify time/date
- if (stat (GM_account_filename, &file_stat))
- creation_time_GM_account_file = 0; // error
- else
- creation_time_GM_account_file = file_stat.st_mtime;
+ creation_time_GM_account_file = file_modified(GM_account_filename);
- if ((fp = fopen_ (GM_account_filename, "r")) == NULL)
+ if ((fp = fopen_(GM_account_filename, "r")) == NULL)
{
- printf ("read_gm_account: GM accounts file [%s] not found.\n",
+ PRINTF("read_gm_account: GM accounts file [%s] not found.\n",
GM_account_filename);
- printf
- (" Actually, there is no GM accounts on the server.\n");
- login_log ("read_gm_account: GM accounts file [%s] not found.\n",
+ PRINTF(" Actually, there is no GM accounts on the server.\n");
+ LOGIN_LOG("read_gm_account: GM accounts file [%s] not found.\n",
GM_account_filename);
- login_log
- (" Actually, there is no GM accounts on the server.\n");
+ LOGIN_LOG(" Actually, there is no GM accounts on the server.\n");
return 1;
}
// limited to 4000, because we send information to char-servers (more than 4000 GM accounts???)
// int (id) + int (level) = 8 bytes * 4000 = 32k (limit of packets in windows)
- while (fgets (line, sizeof (line) - 1, fp) && c < 4000)
+ while (fgets(line, sizeof(line) - 1, fp) && c < 4000)
{
if ((line[0] == '/' && line[1] == '/') || line[0] == '\0'
|| line[0] == '\n' || line[0] == '\r')
continue;
- 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
- ("read_gm_account: file [%s], invalid 'id_acount level' format.\n",
+ struct gm_account p {};
+ if (sscanf(line, "%d %d", &p.account_id, &p.level) != 2
+ && sscanf(line, "%d: %d", &p.account_id, &p.level) != 2)
+ PRINTF("read_gm_account: file [%s], invalid 'id_acount level' format.\n",
GM_account_filename);
- else if (p->level <= 0)
- printf
- ("read_gm_account: file [%s] %dth account (invalid level [0 or negative]: %d).\n",
- GM_account_filename, c + 1, p->level);
+ else if (p.level <= 0)
+ PRINTF("read_gm_account: file [%s] %dth account (invalid level [0 or negative]: %d).\n",
+ GM_account_filename, c + 1, p.level);
else
{
- if (p->level > 99)
+ if (p.level > 99)
{
- printf
- ("read_gm_account: file [%s] %dth account (invalid level, but corrected: %d->99).\n",
- GM_account_filename, c + 1, p->level);
- p->level = 99;
+ PRINTF("read_gm_account: file [%s] %dth account (invalid level, but corrected: %d->99).\n",
+ GM_account_filename, c + 1, p.level);
+ p.level = 99;
}
- if ((GM_level = isGM (p->account_id)) > 0)
+ if ((GM_level = isGM(p.account_id)) > 0)
{ // if it's not a new account
- if (GM_level == p->level)
- printf
- ("read_gm_account: GM account %d defined twice (same level: %d).\n",
- p->account_id, p->level);
+ if (GM_level == p.level)
+ PRINTF("read_gm_account: GM account %d defined twice (same level: %d).\n",
+ p.account_id, p.level);
else
- printf
- ("read_gm_account: GM account %d defined twice (levels: %d and %d).\n",
- p->account_id, GM_level, p->level);
+ PRINTF("read_gm_account: GM account %d defined twice (levels: %d and %d).\n",
+ p.account_id, GM_level, p.level);
}
- if (GM_level != p->level)
+ if (GM_level != p.level)
{ // if new account or new level
- numdb_insert (gm_account_db, p->account_id, p);
- //printf("GM account:%d, level: %d->%d\n", p->account_id, GM_level, p->level);
+ gm_account_db.insert(p.account_id, p);
+ //PRINTF("GM account:%d, level: %d->%d\n", p.account_id, GM_level, p.level);
if (GM_level == 0)
{ // if new account
c++;
if (c >= 4000)
{
- printf
- ("***WARNING: 4000 GM accounts found. Next GM accounts are not readed.\n");
- login_log
- ("***WARNING: 4000 GM accounts found. Next GM accounts are not readed.\n");
+ PRINTF("***WARNING: 4000 GM accounts found. Next GM accounts are not readed.\n");
+ LOGIN_LOG("***WARNING: 4000 GM accounts found. Next GM accounts are not readed.\n");
}
}
}
}
}
- fclose_ (fp);
+ fclose_(fp);
- printf ("read_gm_account: file '%s' readed (%d GM accounts found).\n",
+ PRINTF("read_gm_account: file '%s' readed (%d GM accounts found).\n",
GM_account_filename, c);
- login_log ("read_gm_account: file '%s' readed (%d GM accounts found).\n",
+ LOGIN_LOG("read_gm_account: file '%s' readed (%d GM accounts found).\n",
GM_account_filename, c);
return 0;
@@ -285,49 +329,47 @@ int read_gm_account (void)
// (ip: IP to be tested, str: mask x.x.x.x/# or x.x.x.x/y.y.y.y)
//--------------------------------------------------------------
static
-int check_ipmask (struct in_addr ip, const char *str)
+int check_ipmask(struct in_addr ip, const char *str)
{
- unsigned int mask = 0, i = 0, m, ip2, a0, a1, a2, a3;
- unsigned char *p = (unsigned char *) &ip2, *p2 = (unsigned char *) &mask;
-
- if (sscanf (str, "%d.%d.%d.%d/%n", &a0, &a1, &a2, &a3, &i) != 4 || i == 0)
+ unsigned int mask = 0, ip2;
+ unsigned char *p = (unsigned char *) &ip2,
+ *p2 = (unsigned char *) &mask;
+ int i = 0;
+ unsigned int m;
+
+ if (sscanf(str, "%hhu.%hhu.%hhu.%hhu/%n",
+ &p[0], &p[1], &p[2], &p[3], &i) != 4
+ || i == 0)
return 0;
- p[0] = a0;
- p[1] = a1;
- p[2] = a2;
- p[3] = a3;
- if (sscanf (str + i, "%d.%d.%d.%d", &a0, &a1, &a2, &a3) == 4)
+ if (sscanf(str + i, "%hhu.%hhu.%hhu.%hhu",
+ &p2[0], &p2[1], &p2[2], &p2[3]) == 4)
{
- p2[0] = a0;
- p2[1] = a1;
- p2[2] = a2;
- p2[3] = a3;
- mask = ntohl (mask);
+ mask = ntohl(mask);
}
- else if (sscanf (str + i, "%d", &m) == 1 && m <= 32)
+ else if (sscanf(str + i, "%u", &m) == 1 && m <= 32)
{
for (i = 0; i < m && i < 32; i++)
mask = (mask >> 1) | 0x80000000;
}
else
{
- printf ("check_ipmask: invalid mask [%s].\n", str);
+ PRINTF("check_ipmask: invalid mask [%s].\n", str);
return 0;
}
-// printf("Tested IP: %08x, network: %08x, network mask: %08x\n",
+// PRINTF("Tested IP: %08x, network: %08x, network mask: %08x\n",
// (unsigned int)ntohl(ip), (unsigned int)ntohl(ip2), (unsigned int)mask);
- return ((ntohl (ip.s_addr) & mask) == (ntohl (ip2) & mask));
+ return ((ntohl(ip.s_addr) & mask) == (ntohl(ip2) & mask));
}
//---------------------
// Access control by IP
//---------------------
static
-int check_ip (struct in_addr ip)
+int check_ip(struct in_addr ip)
{
- int i;
+ int i;
enum
{ ACF_DEF, ACF_ALLOW, ACF_DENY } flag = ACF_DEF;
@@ -348,7 +390,7 @@ int check_ip (struct in_addr ip)
for (i = 0; i < access_allownum; i++)
{
const char *p = access_allow + i * ACO_STRSIZE;
- if (memcmp (p, buf, strlen (p)) == 0 || check_ipmask (ip, p))
+ if (memcmp(p, buf, strlen(p)) == 0 || check_ipmask(ip, p))
{
flag = ACF_ALLOW;
if (access_order == ACO_ALLOW_DENY)
@@ -360,11 +402,10 @@ int check_ip (struct in_addr ip)
for (i = 0; i < access_denynum; i++)
{
const char *p = access_deny + i * ACO_STRSIZE;
- if (memcmp (p, buf, strlen (p)) == 0 || check_ipmask (ip, p))
+ if (memcmp(p, buf, strlen(p)) == 0 || check_ipmask(ip, p))
{
flag = ACF_DENY;
return 0; // At this point, if it's 'deny', we refuse connection.
- break;
}
}
@@ -379,9 +420,9 @@ int check_ip (struct in_addr ip)
// Access control by IP for ladmin
//--------------------------------
static
-int check_ladminip (struct in_addr ip)
+int check_ladminip(struct in_addr ip)
{
- int i;
+ int i;
if (access_ladmin_allownum == 0)
return 1; // When there is no restriction, all IP are authorised.
@@ -400,7 +441,7 @@ int check_ladminip (struct in_addr ip)
for (i = 0; i < access_ladmin_allownum; i++)
{
const char *p = access_ladmin_allow + i * ACO_STRSIZE;
- if (memcmp (p, buf, strlen (p)) == 0 || check_ipmask (ip, p))
+ if (memcmp(p, buf, strlen(p)) == 0 || check_ipmask(ip, p))
{
return 1;
}
@@ -418,19 +459,19 @@ int check_ladminip (struct in_addr ip)
// and similar to the searched name.
//-----------------------------------------------
static
-int search_account_index (char *account_name)
+int search_account_index(char *account_name)
{
- int i, quantity, index;
+ int i, quantity, index;
quantity = 0;
index = -1;
for (i = 0; i < auth_num; i++)
{
// Without case sensitive check (increase the number of similar account names found)
- if (strcasecmp (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)
+ if (strcmp(auth_dat[i].userid, account_name) == 0)
return i;
quantity++;
index = i;
@@ -449,462 +490,180 @@ int search_account_index (char *account_name)
// Create a string to save the account in the account file
//--------------------------------------------------------
static
-int mmo_auth_tostr (char *str, struct auth_dat *p)
+std::string mmo_auth_tostr(struct auth_dat *p)
{
- int i;
- char *str_p = str;
-
- str_p += sprintf (str_p, "%d\t%s\t%s\t%s\t%c\t%d\t%d\t"
- "%s\t%s\t%ld\t%s\t%s\t%ld\t",
- p->account_id, p->userid, p->pass, p->lastlogin,
- (p->sex == 2) ? 'S' : (p->sex ? 'M' : 'F'),
- p->logincount, p->state,
- p->email, p->error_message,
- p->connect_until_time, p->last_ip, p->memo,
- p->ban_until_time);
-
- for (i = 0; i < p->account_reg2_num; i++)
+ std::string str = STRPRINTF(
+ "%d\t"
+ "%s\t"
+ "%s\t"
+ "%s\t"
+ "%c\t"
+ "%d\t"
+ "%d\t"
+ "%s\t"
+ "%s\t"
+ "%lld\t"
+ "%s\t"
+ "%s\t"
+ "%lld\t",
+ p->account_id,
+ p->userid,
+ p->pass,
+ p->lastlogin,
+ (p->sex == 2) ? 'S' : (p->sex ? 'M' : 'F'),
+ p->logincount,
+ p->state,
+ p->email,
+ p->error_message,
+ p->connect_until_time,
+ p->last_ip,
+ p->memo,
+ p->ban_until_time);
+
+ for (int i = 0; i < p->account_reg2_num; i++)
if (p->account_reg2[i].str[0])
- str_p +=
- sprintf (str_p, "%s,%d ", p->account_reg2[i].str,
- p->account_reg2[i].value);
+ str += STRPRINTF("%s,%d ",
+ p->account_reg2[i].str, p->account_reg2[i].value);
- return 0;
+ return str;
+}
+
+static
+bool extract(const_string line, struct auth_dat *ad)
+{
+ std::vector<struct global_reg> vars;
+ const_string sex = nullptr; // really only 1 char
+ if (!extract(line,
+ record<'\t'>(
+ &ad->account_id,
+ &ad->userid,
+ &ad->pass,
+ &ad->lastlogin,
+ &sex,
+ &ad->logincount,
+ &ad->state,
+ &ad->email,
+ &ad->error_message,
+ &ad->connect_until_time,
+ &ad->last_ip,
+ &ad->memo,
+ &ad->ban_until_time,
+ vrec<' '>(&vars))))
+ return false;
+ if (ad->account_id > END_ACCOUNT_NUM)
+ return false;
+ for (int j = 0; j < auth_num; j++)
+ {
+ if (auth_dat[j].account_id == ad->account_id)
+ return false;
+ else if (strcmp(auth_dat[j].userid, ad->userid) == 0)
+ return false;
+ }
+ // If a password is not encrypted, we encrypt it now.
+ // A password beginning with ! and - in the memo field is our magic
+ if (ad->pass[0] != '!' && ad->memo[0] == '-') {
+ strcpy(ad->pass, MD5_saltcrypt(ad->pass, make_salt()));
+ ad->memo[0] = '!';
+ }
+
+ if (sex.size() != 1)
+ return false;
+ switch(sex.front())
+ {
+ case 'S': case 's': ad->sex = 2; break;
+ case 'M': case 'm': ad->sex = 1; break;
+ case 'F': case 'f': ad->sex = 0; break;
+ default: return false;
+ }
+
+ if (e_mail_check(ad->email) == 0)
+ strzcpy(ad->email, "a@a.com", 40);
+
+ if (ad->error_message[0] == '\0' || ad->state != 7)
+ // 7, because state is packet 0x006a value + 1
+ strzcpy(ad->error_message, "-", 20);
+
+ if (vars.size() > ACCOUNT_REG2_NUM)
+ return false;
+ std::copy(vars.begin(), vars.end(), ad->account_reg2);
+ ad->account_reg2_num = vars.size();
+
+ return true;
}
//---------------------------------
// Reading of the accounts database
//---------------------------------
static
-int mmo_auth_init (void)
+int mmo_auth_init(void)
{
- FILE *fp;
- int account_id, logincount, state, n, i, j, v;
- char line[2048], *p, 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 str[2048];
- int GM_count = 0;
- int server_count = 0;
-
- CREATE (auth_dat, struct auth_dat, 256);
+ int GM_count = 0;
+ int server_count = 0;
+
+ CREATE(auth_dat, struct auth_dat, 256);
auth_max = 256;
- fp = fopen_ (account_filename, "r");
- if (fp == NULL)
+ std::ifstream in(account_filename);
+ if (!in.is_open())
{
// no account file -> no account -> no login, including char-server (ERROR)
- printf
- ("\033[1;31mmmo_auth_init: Accounts file [%s] not found.\033[0m\n",
+ PRINTF("\033[1;31mmmo_auth_init: Accounts file [%s] not found.\033[0m\n",
account_filename);
return 0;
}
- while (fgets (line, sizeof (line) - 1, fp) != NULL)
+ std::string line;
+ while (std::getline(in, line))
{
if (line[0] == '/' && line[1] == '/')
continue;
- line[sizeof (line) - 1] = '\0';
- p = line;
-
- // database version reading (v2)
- if (((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)) == 13 && line[n] == '\t')
- ||
- ((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]%n", &account_id,
- userid, pass, lastlogin, &sex, &logincount, &state,
- email, error_message, &connect_until_time, last_ip,
- memo, &n)) == 12 && line[n] == '\t'))
+ if (line.back() == '\r')
{
- n = n + 1;
-
- // Some checks
- if (account_id > END_ACCOUNT_NUM)
- {
- printf
- ("\033[1;31mmmo_auth_init: ******Error: an account has an id higher than %d\n",
- END_ACCOUNT_NUM);
- printf
- (" account id #%d -> account not read (saved in log file).\033[0m\n",
- account_id);
- login_log
- ("mmmo_auth_init: ******Error: an account has an id higher than %d.\n",
- END_ACCOUNT_NUM);
- login_log
- (" account id #%d -> account not read (saved in next line):\n",
- account_id);
- login_log ("%s", line);
- continue;
- }
- userid[23] = '\0';
- remove_control_chars (userid);
- for (j = 0; j < auth_num; j++)
- {
- if (auth_dat[j].account_id == account_id)
- {
- printf
- ("\033[1;31mmmo_auth_init: ******Error: an account has an identical id to another.\n");
- printf
- (" account id #%d -> new account not read (saved in log file).\033[0m\n",
- account_id);
- login_log
- ("mmmo_auth_init: ******Error: an account has an identical id to another.\n");
- login_log
- (" account id #%d -> new account not read (saved in next line):\n",
- account_id);
- login_log ("%s", line);
- break;
- }
- else if (strcmp (auth_dat[j].userid, userid) == 0)
- {
- printf
- ("\033[1;31mmmo_auth_init: ******Error: account name already exists.\n");
- printf (" account name '%s' -> new account not read.\n", userid); // 2 lines, account name can be long.
- printf
- (" Account saved in log file.\033[0m\n");
- login_log
- ("mmmo_auth_init: ******Error: an account has an identical id to another.\n");
- login_log
- (" account id #%d -> new account not read (saved in next line):\n",
- account_id);
- login_log ("%s", line);
- break;
- }
- }
- if (j != auth_num)
- continue;
-
- if (auth_num >= auth_max)
- {
- auth_max += 256;
- RECREATE (auth_dat, struct auth_dat, auth_max);
- }
-
- memset (&auth_dat[auth_num], '\0', sizeof (struct auth_dat));
-
- auth_dat[auth_num].account_id = account_id;
-
- strncpy (auth_dat[auth_num].userid, userid, 24);
-
- memo[254] = '\0';
- remove_control_chars (memo);
- strncpy (auth_dat[auth_num].memo, memo, 255);
-
- pass[39] = '\0';
- remove_control_chars (pass);
- // If a password is not encrypted, we encrypt it now.
- // A password beginning with ! and - in the memo field is our magic
- if (pass[0] != '!' && memo[0] == '-') {
- strcpy(auth_dat[auth_num].pass, MD5_saltcrypt(pass, make_salt()));
- auth_dat[auth_num].memo[0] = '!';
- printf("encrypting pass: %s %s\n", pass, auth_dat[auth_num].pass);
- }
- else
- strcpy(auth_dat[auth_num].pass, pass);
-
- lastlogin[23] = '\0';
- remove_control_chars (lastlogin);
- strncpy (auth_dat[auth_num].lastlogin, lastlogin, 24);
-
- auth_dat[auth_num].sex = (sex == 'S'
- || sex == 's') ? 2 : (sex == 'M'
- || sex == 'm');
-
- if (logincount >= 0)
- auth_dat[auth_num].logincount = logincount;
- else
- auth_dat[auth_num].logincount = 0;
-
- if (state > 255)
- auth_dat[auth_num].state = 100;
- else if (state < 0)
- auth_dat[auth_num].state = 0;
- else
- auth_dat[auth_num].state = state;
-
- if (e_mail_check (email) == 0)
- {
- printf
- ("Account %s (%d): invalid e-mail (replaced par a@a.com).\n",
- auth_dat[auth_num].userid,
- auth_dat[auth_num].account_id);
- strncpy (auth_dat[auth_num].email, "a@a.com", 40);
- }
- else
- {
- remove_control_chars (email);
- strncpy (auth_dat[auth_num].email, email, 40);
- }
-
- error_message[19] = '\0';
- remove_control_chars (error_message);
- if (error_message[0] == '\0' || state != 7)
- { // 7, because state is packet 0x006a value + 1
- strncpy (auth_dat[auth_num].error_message, "-", 20);
- }
- else
- {
- strncpy (auth_dat[auth_num].error_message, error_message, 20);
- }
-
- if (i == 13)
- auth_dat[auth_num].ban_until_time = ban_until_time;
- else
- auth_dat[auth_num].ban_until_time = 0;
-
- auth_dat[auth_num].connect_until_time = connect_until_time;
-
- last_ip[15] = '\0';
- remove_control_chars (last_ip);
- strncpy (auth_dat[auth_num].last_ip, last_ip, 16);
-
- for (j = 0; j < ACCOUNT_REG2_NUM; j++)
- {
- p += n;
- if (sscanf (p, "%[^\t,],%d %n", str, &v, &n) != 2)
- {
- // We must check if a str is void. If it's, we can continue to read other REG2.
- // Account line will have something like: str2,9 ,9 str3,1 (here, ,9 is not good)
- if (p[0] == ',' && sscanf (p, ",%d %n", &v, &n) == 1)
- {
- j--;
- continue;
- }
- else
- break;
- }
- str[31] = '\0';
- remove_control_chars (str);
- strncpy (auth_dat[auth_num].account_reg2[j].str, str, 32);
- auth_dat[auth_num].account_reg2[j].value = v;
- }
- auth_dat[auth_num].account_reg2_num = j;
-
- if (isGM (account_id) > 0)
- GM_count++;
- if (auth_dat[auth_num].sex == 2)
- server_count++;
-
- auth_num++;
- if (account_id >= account_id_count)
- account_id_count = account_id + 1;
-
- // Old athena database version reading (v1)
+#ifdef WORKAROUND_GCC46_LIBRARY
+ line.resize(line.size() - 1);
+#else
+ line.pop_back();
+#endif
}
- else if ((i =
- sscanf (line, "%d\t%[^\t]\t%[^\t]\t%[^\t]\t%c\t%d\t%d\t%n",
- &account_id, userid, pass, lastlogin, &sex,
- &logincount, &state, &n)) >= 5)
- {
- if (account_id > END_ACCOUNT_NUM)
- {
- printf
- ("\033[1;31mmmo_auth_init: ******Error: an account has an id higher than %d\n",
- END_ACCOUNT_NUM);
- printf
- (" account id #%d -> account not read (saved in log file).\033[0m\n",
- account_id);
- login_log
- ("mmmo_auth_init: ******Error: an account has an id higher than %d.\n",
- END_ACCOUNT_NUM);
- login_log
- (" account id #%d -> account not read (saved in next line):\n",
- account_id);
- login_log ("%s", line);
- continue;
- }
- userid[23] = '\0';
- remove_control_chars (userid);
- for (j = 0; j < auth_num; j++)
- {
- if (auth_dat[j].account_id == account_id)
- {
- printf
- ("\033[1;31mmmo_auth_init: ******Error: an account has an identical id to another.\n");
- printf
- (" account id #%d -> new account not read (saved in log file).\033[0m\n",
- account_id);
- login_log
- ("mmmo_auth_init: ******Error: an account has an identical id to another.\n");
- login_log
- (" account id #%d -> new account not read (saved in next line):\n",
- account_id);
- login_log ("%s", line);
- break;
- }
- else if (strcmp (auth_dat[j].userid, userid) == 0)
- {
- printf
- ("\033[1;31mmmo_auth_init: ******Error: account name already exists.\n");
- printf (" account name '%s' -> new account not read.\n", userid); // 2 lines, account name can be long.
- printf
- (" Account saved in log file.\033[0m\n");
- login_log
- ("mmmo_auth_init: ******Error: an account has an identical id to another.\n");
- login_log
- (" account id #%d -> new account not read (saved in next line):\n",
- account_id);
- login_log ("%s", line);
- break;
- }
- }
- if (j != auth_num)
- continue;
-
- if (auth_num >= auth_max)
- {
- auth_max += 256;
- RECREATE (auth_dat, struct auth_dat, auth_max);
- }
-
- memset (&auth_dat[auth_num], '\0', sizeof (struct auth_dat));
-
- auth_dat[auth_num].account_id = account_id;
-
- strncpy (auth_dat[auth_num].userid, userid, 24);
-
- lastlogin[23] = '\0';
- remove_control_chars (lastlogin);
- strncpy (auth_dat[auth_num].lastlogin, lastlogin, 24);
-
- auth_dat[auth_num].sex = (sex == 'S'
- || sex == 's') ? 2 : (sex == 'M'
- || sex == 'm');
-
- if (i >= 6)
- {
- if (logincount >= 0)
- auth_dat[auth_num].logincount = logincount;
- else
- auth_dat[auth_num].logincount = 0;
- }
- else
- auth_dat[auth_num].logincount = 0;
+ if (std::find_if(line.begin(), line.end(),
+ [](unsigned char c) { return c < ' ' && c != '\t'; }
+ ) != line.end())
+ continue;
- if (i >= 7)
- {
- if (state > 255)
- auth_dat[auth_num].state = 100;
- else if (state < 0)
- auth_dat[auth_num].state = 0;
- else
- auth_dat[auth_num].state = state;
- }
+ struct auth_dat ad {};
+ if (!extract(line, &ad))
+ {
+ int i = 0;
+ if (SSCANF(line, "%d\t%%newid%%\n%n", &ad.account_id, &i) == 1
+ && i > 0 && ad.account_id > account_id_count)
+ account_id_count = ad.account_id;
else
- auth_dat[auth_num].state = 0;
-
- // Initialization of new data
- strncpy (auth_dat[auth_num].email, "a@a.com", 40);
- strncpy (auth_dat[auth_num].error_message, "-", 20);
- auth_dat[auth_num].ban_until_time = 0;
- auth_dat[auth_num].connect_until_time = 0;
- strncpy (auth_dat[auth_num].last_ip, "-", 16);
- strncpy (auth_dat[auth_num].memo, "!", 255);
+ LOGIN_LOG("Account skipped\n%s", line);
+ continue;
+ }
- for (j = 0; j < ACCOUNT_REG2_NUM; j++)
- {
- p += n;
- if (sscanf (p, "%[^\t,],%d %n", str, &v, &n) != 2)
- {
- // We must check if a str is void. If it's, we can continue to read other REG2.
- // Account line will have something like: str2,9 ,9 str3,1 (here, ,9 is not good)
- if (p[0] == ',' && sscanf (p, ",%d %n", &v, &n) == 1)
- {
- j--;
- continue;
- }
- else
- break;
- }
- str[31] = '\0';
- remove_control_chars (str);
- strncpy (auth_dat[auth_num].account_reg2[j].str, str, 32);
- auth_dat[auth_num].account_reg2[j].value = v;
- }
- auth_dat[auth_num].account_reg2_num = j;
+ if (auth_num >= auth_max)
+ {
+ auth_max += 256;
+ RECREATE(auth_dat, struct auth_dat, auth_max);
+ }
- if (isGM (account_id) > 0)
- GM_count++;
- if (auth_dat[auth_num].sex == 2)
- server_count++;
+ auth_dat[auth_num] = ad;
- auth_num++;
- if (account_id >= account_id_count)
- account_id_count = account_id + 1;
+ if (isGM(ad.account_id) > 0)
+ GM_count++;
+ if (auth_dat[auth_num].sex == 2)
+ server_count++;
- }
- else
- {
- i = 0;
- if (sscanf (line, "%d\t%%newid%%\n%n", &account_id, &i) == 1 &&
- i > 0 && account_id > account_id_count)
- account_id_count = account_id;
- }
+ auth_num++;
+ if (ad.account_id >= account_id_count)
+ account_id_count = ad.account_id + 1;
}
- fclose_ (fp);
- if (auth_num == 0)
- {
- printf ("mmo_auth_init: No account found in %s.\n", account_filename);
- sprintf (line, "No account found in %s.", account_filename);
- }
- else
- {
- if (auth_num == 1)
- {
- printf ("mmo_auth_init: 1 account read in %s,\n",
- account_filename);
- sprintf (line, "1 account read in %s,", account_filename);
- }
- else
- {
- printf ("mmo_auth_init: %d accounts read in %s,\n", auth_num,
- account_filename);
- sprintf (line, "%d accounts read in %s,", auth_num,
- account_filename);
- }
- if (GM_count == 0)
- {
- printf (" of which is no GM account, and ");
- sprintf (str, "%s of which is no GM account and", line);
- }
- else if (GM_count == 1)
- {
- printf (" of which is 1 GM account, and ");
- sprintf (str, "%s of which is 1 GM account and", line);
- }
- else
- {
- printf (" of which is %d GM accounts, and ",
- GM_count);
- sprintf (str, "%s of which is %d GM accounts and", line,
- GM_count);
- }
- if (server_count == 0)
- {
- printf ("no server account ('S').\n");
- sprintf (line, "%s no server account ('S').", str);
- }
- else if (server_count == 1)
- {
- printf ("1 server account ('S').\n");
- sprintf (line, "%s 1 server account ('S').", str);
- }
- else
- {
- printf ("%d server accounts ('S').\n", server_count);
- sprintf (line, "%s %d server accounts ('S').", str, server_count);
- }
- }
- login_log ("%s\n", line);
+ std::string str = STRPRINTF("%s has %d accounts (%d GMs, %d servers)\n",
+ account_filename, auth_num, GM_count, server_count);
+ PRINTF("%s: %s\n", __PRETTY_FUNCTION__, str);
+ LOGIN_LOG("%s\n", line);
return 0;
}
@@ -914,12 +673,11 @@ int mmo_auth_init (void)
// (accounts are sorted by id before save)
//------------------------------------------
static
-void mmo_auth_sync (void)
+void mmo_auth_sync(void)
{
FILE *fp;
- int i, j, k, lock;
- int id[auth_num];
- char line[65536];
+ int i, j, k, lock;
+ int id[auth_num];
// Sorting before save
for (i = 0; i < auth_num; i++)
@@ -938,29 +696,29 @@ void mmo_auth_sync (void)
}
// Data save
- fp = lock_fopen (account_filename, &lock);
+ fp = lock_fopen(account_filename, &lock);
if (fp == NULL)
return;
- fprintf (fp,
+ FPRINTF(fp,
"// Accounts file: here are saved all information about the accounts.\n");
- fprintf (fp,
+ FPRINTF(fp,
"// Structure: ID, account name, password, last login time, sex, # of logins, state, email, error message for state 7, validity time, last (accepted) login ip, memo field, ban timestamp, repeated(register text, register value)\n");
- fprintf (fp, "// Some explanations:\n");
- fprintf (fp,
+ FPRINTF(fp, "// Some explanations:\n");
+ FPRINTF(fp,
"// account name : between 4 to 23 char for a normal account (standard client can't send less than 4 char).\n");
- fprintf (fp, "// account password: between 4 to 23 char\n");
- fprintf (fp,
+ FPRINTF(fp, "// account password: between 4 to 23 char\n");
+ FPRINTF(fp,
"// sex : M or F for normal accounts, S for server accounts\n");
- fprintf (fp,
+ FPRINTF(fp,
"// state : 0: account is ok, 1 to 256: error code of packet 0x006a + 1\n");
- fprintf (fp,
+ FPRINTF(fp,
"// email : between 3 to 39 char (a@a.com is like no email)\n");
- fprintf (fp,
+ FPRINTF(fp,
"// error message : text for the state 7: 'Your are Prohibited to login until <text>'. Max 19 char\n");
- fprintf (fp,
+ FPRINTF(fp,
"// valitidy time : 0: unlimited account, <other value>: date calculated by addition of 1/1/1970 + value (number of seconds since the 1/1/1970)\n");
- fprintf (fp, "// memo field : max 254 char\n");
- fprintf (fp,
+ FPRINTF(fp, "// memo field : max 254 char\n");
+ FPRINTF(fp,
"// ban time : 0: no ban, <other value>: banned until the date: date calculated by addition of 1/1/1970 + value (number of seconds since the 1/1/1970)\n");
for (i = 0; i < auth_num; i++)
{
@@ -968,12 +726,12 @@ void mmo_auth_sync (void)
if (auth_dat[k].account_id < 0)
continue;
- mmo_auth_tostr (line, &auth_dat[k]);
- fprintf (fp, "%s\n", line);
+ std::string line = mmo_auth_tostr(&auth_dat[k]);
+ FPRINTF(fp, "%s\n", line);
}
- fprintf (fp, "%d\t%%newid%%\n", account_id_count);
+ FPRINTF(fp, "%d\t%%newid%%\n", account_id_count);
- lock_fclose (fp, account_filename, &lock);
+ lock_fclose(fp, account_filename, &lock);
return;
}
@@ -984,12 +742,12 @@ void mmo_auth_sync (void)
// we save periodicly on a timer.
//-----------------------------------------------------
static
-void check_auth_sync (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data)
+void check_auth_sync(TimerData *, tick_t)
{
if (pid != 0)
{
int status;
- pid_t temp = waitpid (pid, &status, WNOHANG);
+ pid_t temp = waitpid(pid, &status, WNOHANG);
// Need to check status too?
if (temp == 0)
@@ -1000,14 +758,14 @@ void check_auth_sync (timer_id tid, tick_t tick, custom_id_t id, custom_data_t d
// 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)
+ if ((pid = fork()) > 0)
return;
- mmo_auth_sync ();
+ mmo_auth_sync();
// If we're a child we should suicide now.
if (pid == 0)
- _exit (0);
+ _exit(0);
return;
}
@@ -1016,46 +774,42 @@ void check_auth_sync (timer_id tid, tick_t tick, custom_id_t id, custom_data_t d
// Packet send to all char-servers, except one (wos: without our self)
//--------------------------------------------------------------------
static
-int charif_sendallwos (int sfd, unsigned char *buf, unsigned int len)
+void charif_sendallwos(int sfd, const uint8_t *buf, size_t len)
{
- int i, c;
-
- for (i = 0, c = 0; i < MAX_SERVERS; i++)
+ for (int i = 0; i < MAX_SERVERS; i++)
{
- int fd;
- if ((fd = server_fd[i]) >= 0 && fd != sfd)
+ int fd = server_fd[i];
+ if (fd >= 0 && fd != sfd)
{
- memcpy (WFIFOP (fd, 0), buf, len);
- WFIFOSET (fd, len);
- c++;
+ memcpy(WFIFOP(fd, 0), buf, len);
+ WFIFOSET(fd, len);
}
}
- return c;
}
//-----------------------------------------------------
// Send GM accounts to all char-server
//-----------------------------------------------------
static
-void send_GM_accounts (void)
+void send_GM_accounts(void)
{
- int i;
+ int i;
uint8_t buf[32000];
- int GM_value;
- int len;
+ int GM_value;
+ int len;
len = 4;
- WBUFW (buf, 0) = 0x2732;
+ WBUFW(buf, 0) = 0x2732;
for (i = 0; i < auth_num; i++)
// send only existing accounts. We can not create a GM account when server is online.
- if ((GM_value = isGM (auth_dat[i].account_id)) > 0)
+ if ((GM_value = isGM(auth_dat[i].account_id)) > 0)
{
- WBUFL (buf, len) = auth_dat[i].account_id;
- WBUFB (buf, len + 4) = (unsigned char) GM_value;
+ WBUFL(buf, len) = auth_dat[i].account_id;
+ WBUFB(buf, len + 4) = (unsigned char) GM_value;
len += 5;
}
- WBUFW (buf, 2) = len;
- charif_sendallwos (-1, buf, len);
+ WBUFW(buf, 2) = len;
+ charif_sendallwos(-1, buf, len);
return;
}
@@ -1064,25 +818,19 @@ void send_GM_accounts (void)
// Check if GM file account have been changed
//-----------------------------------------------------
static
-void check_GM_file (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data)
+void check_GM_file(TimerData *, tick_t)
{
- struct stat file_stat;
- long new_time;
-
// if we would not check
- if (gm_account_filename_check_timer < 1)
+ if (gm_account_filename_check_timer == interval_t::zero())
return;
// get last modify time/date
- if (stat (GM_account_filename, &file_stat))
- new_time = 0; // error
- else
- new_time = file_stat.st_mtime;
+ tick_t new_time = file_modified(GM_account_filename);
if (new_time != creation_time_GM_account_file)
{
- read_gm_account ();
- send_GM_accounts ();
+ read_gm_account();
+ send_GM_accounts();
}
}
@@ -1090,32 +838,30 @@ void check_GM_file (timer_id tid, tick_t tick, custom_id_t id, custom_data_t dat
// Account creation (with e-mail check)
//-------------------------------------
static
-int mmo_auth_new (struct mmo_account *account, char sex, const char *email)
+int mmo_auth_new(struct mmo_account *account, char sex, const char *email)
{
- time_t timestamp, timestamp_temp;
- struct tm *tmtime;
- int i = auth_num;
+ int i = auth_num;
if (auth_num >= auth_max)
{
auth_max += 256;
- RECREATE (auth_dat, struct auth_dat, auth_max);
+ RECREATE(auth_dat, struct auth_dat, auth_max);
}
- memset (&auth_dat[i], '\0', sizeof (struct auth_dat));
+ memset(&auth_dat[i], '\0', sizeof(struct auth_dat));
- while (isGM (account_id_count) > 0)
+ while (isGM(account_id_count) > 0)
account_id_count++;
auth_dat[i].account_id = account_id_count++;
- strncpy (auth_dat[i].userid, account->userid, 24);
+ strncpy(auth_dat[i].userid, account->userid, 24);
auth_dat[i].userid[23] = '\0';
strcpy(auth_dat[i].pass, MD5_saltcrypt(account->passwd, make_salt()));
auth_dat[i].pass[39] = '\0';
- memcpy (auth_dat[i].lastlogin, "-", 2);
+ memcpy(auth_dat[i].lastlogin, "-", 2);
auth_dat[i].sex = (sex == 'M');
@@ -1123,62 +869,57 @@ int mmo_auth_new (struct mmo_account *account, char sex, const char *email)
auth_dat[i].state = 0;
- if (e_mail_check (email) == 0)
- strncpy (auth_dat[i].email, "a@a.com", 40);
+ if (e_mail_check(email) == 0)
+ strncpy(auth_dat[i].email, "a@a.com", 40);
else
- strncpy (auth_dat[i].email, email, 40);
+ strncpy(auth_dat[i].email, email, 40);
- strncpy (auth_dat[i].error_message, "-", 20);
+ strncpy(auth_dat[i].error_message, "-", 20);
- auth_dat[i].ban_until_time = 0;
+ auth_dat[i].ban_until_time = TimeT();
if (start_limited_time < 0)
- auth_dat[i].connect_until_time = 0; // unlimited
+ auth_dat[i].connect_until_time = TimeT(); // unlimited
else
- { // limited time
- timestamp = time (NULL) + start_limited_time;
- // double conversion to be sure that it is possible
- tmtime = gmtime (&timestamp);
- timestamp_temp = mktime (tmtime);
- if (timestamp_temp != -1 && (timestamp_temp + 3600) >= timestamp) // check possible value and overflow (and avoid summer/winter hour)
- auth_dat[i].connect_until_time = timestamp_temp;
- else
- auth_dat[i].connect_until_time = 0; // unlimited
+ {
+ // limited time
+ TimeT timestamp = static_cast<time_t>(TimeT::now()) + start_limited_time;
+ // there used to be a silly overflow check here, but it wasn't
+ // correct, and we don't support time-limited accounts.
+ auth_dat[i].connect_until_time = timestamp;
}
- strncpy (auth_dat[i].last_ip, "-", 16);
+ strncpy(auth_dat[i].last_ip, "-", 16);
- strncpy (auth_dat[i].memo, "!", 255);
+ strncpy(auth_dat[i].memo, "!", 255);
auth_dat[i].account_reg2_num = 0;
auth_num++;
- return (account_id_count - 1);
+ return(account_id_count - 1);
}
//---------------------------------------
// Check/authentification of a connection
//---------------------------------------
static
-int mmo_auth (struct mmo_account *account, int fd)
+int mmo_auth(struct mmo_account *account, int fd)
{
- int i;
- struct timeval tv;
- char tmpstr[256];
- int len, newaccount = 0;
+ int i;
+ int len, newaccount = 0;
#ifdef PASSWDENC
char md5str[64], md5bin[32];
#endif
const char *ip = ip2str(session[fd]->client_addr.sin_addr);
- len = strlen (account->userid) - 2;
+ len = strlen(account->userid) - 2;
// Account creation with _M/_F
if (account->passwdenc == 0 && account->userid[len] == '_' &&
(account->userid[len + 1] == 'F' || account->userid[len + 1] == 'M')
&& new_account_flag == 1 && account_id_count <= END_ACCOUNT_NUM
- && len >= 4 && strlen (account->passwd) >= 4)
+ && len >= 4 && strlen(account->passwd) >= 4)
{
if (new_account_flag == 1)
newaccount = 1;
@@ -1188,102 +929,40 @@ int mmo_auth (struct mmo_account *account, int fd)
// Strict account search
for (i = 0; i < auth_num; i++)
{
- if (strcmp (account->userid, auth_dat[i].userid) == 0)
+ if (strcmp(account->userid, auth_dat[i].userid) == 0)
break;
}
// if there is no creation request and strict account search fails, we do a no sensitive case research for index
if (newaccount == 0 && i == auth_num)
{
- i = search_account_index (account->userid);
+ i = search_account_index(account->userid);
if (i == -1)
i = auth_num;
else
- memcpy (account->userid, auth_dat[i].userid, 24); // for the possible tests/checks afterwards (copy correcte sensitive case).
+ memcpy(account->userid, auth_dat[i].userid, 24); // for the possible tests/checks afterwards (copy correcte sensitive case).
}
if (i != auth_num)
{
- int encpasswdok = 0;
- struct login_session_data *ld;
+ int encpasswdok = 0;
if (newaccount)
{
- login_log
- ("Attempt of creation of an already existant account (account: %s_%c, ip: %s)\n",
+ LOGIN_LOG("Attempt of creation of an already existant account (account: %s_%c, ip: %s)\n",
account->userid, account->userid[len + 1], ip);
return 9; // 9 = Account already exists
}
- ld = (struct login_session_data*) session[fd]->session_data;
-#ifdef PASSWORDENC
- if (account->passwdenc > 0)
- {
- int j = account->passwdenc;
- if (!ld)
- {
- login_log ("Md5 key not created (account: %s, ip: %s)\n",
- account->userid, ip);
- return 1; // 1 = Incorrect Password
- }
- if (j > 2)
- j = 1;
- do
- {
- if (j == 1)
- {
- strncpy (md5str, ld->md5key, sizeof (ld->md5key)); // 20
- strcat (md5str, auth_dat[i].pass); // 24
- }
- else if (j == 2)
- {
- strncpy (md5str, auth_dat[i].pass, sizeof (auth_dat[i].pass)); // 24
- strcat (md5str, ld->md5key); // 20
- }
- else
- md5str[0] = '\0';
- md5str[sizeof (md5str) - 1] = '\0'; // 64
- MD5_String2binary (md5str, md5bin);
- encpasswdok = (memcmp (account->passwd, md5bin, 16) == 0);
- }
- while (j < 2 && !encpasswdok && (j++) != account->passwdenc);
-// printf("key[%s] md5 [%s] ", md5key, md5);
-// printf("client [%s] accountpass [%s]\n", account->passwd, auth_dat[i].pass);
- }
-#endif
- if ((!pass_ok (account->passwd, auth_dat[i].pass)) && !encpasswdok)
+ if ((!pass_ok(account->passwd, auth_dat[i].pass)) && !encpasswdok)
{
if (account->passwdenc == 0)
- login_log
- ("Invalid password (account: %s, ip: %s)\n",
+ LOGIN_LOG("Invalid password (account: %s, ip: %s)\n",
account->userid, ip);
-#ifdef PASSWORDENC
- else
- {
- char logbuf[512], *p = logbuf;
- int j;
- p += sprintf (p,
- "Invalid password (account: %s, received md5[",
- account->userid);
- for (j = 0; j < 16; j++)
- p += sprintf (p, "%02x",
- ((unsigned char *) account->passwd)[j]);
- p += sprintf (p, "] calculated md5[");
- for (j = 0; j < 16; j++)
- p += sprintf (p, "%02x", ((unsigned char *) md5bin)[j]);
- p += sprintf (p, "] md5 key[");
- for (j = 0; j < ld->md5keylen; j++)
- p += sprintf (p, "%02x",
- ((unsigned char *) ld->md5key)[j]);
- p += sprintf (p, "], ip: %s)\n", ip);
- login_log (logbuf);
- }
-#endif
return 1; // 1 = Incorrect Password
}
if (auth_dat[i].state)
{
- login_log
- ("Connection refused (account: %s, state: %d, ip: %s)\n",
+ LOGIN_LOG("Connection refused (account: %s, state: %d, ip: %s)\n",
account->userid, auth_dat[i].state,
ip);
switch (auth_dat[i].state)
@@ -1299,77 +978,71 @@ int mmo_auth (struct mmo_account *account, int fd)
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
return auth_dat[i].state - 1;
- break;
default:
return 99; // 99 = ID has been totally erased
- break;
}
}
- if (auth_dat[i].ban_until_time != 0)
- { // if account is banned
- strftime (tmpstr, 20, date_format,
- gmtime (&auth_dat[i].ban_until_time));
- tmpstr[19] = '\0';
- if (auth_dat[i].ban_until_time > time (NULL))
- { // always banned
- login_log
- ("Connection refused (account: %s, banned until %s, ip: %s)\n",
+ if (auth_dat[i].ban_until_time)
+ {
+ // if account is banned
+ timestamp_seconds_buffer tmpstr;
+ stamp_time(tmpstr, &auth_dat[i].ban_until_time);
+ if (auth_dat[i].ban_until_time > TimeT::now())
+ {
+ // always banned
+ LOGIN_LOG("Connection refused (account: %s, banned until %s, ip: %s)\n",
account->userid, tmpstr, ip);
return 6; // 6 = Your are Prohibited to log in until %s
}
else
- { // ban is finished
- login_log
- ("End of ban (account: %s, previously banned until %s -> not more banned, ip: %s)\n",
+ {
+ // ban is finished
+ LOGIN_LOG("End of ban (account: %s, previously banned until %s -> not more banned, ip: %s)\n",
account->userid, tmpstr, ip);
- auth_dat[i].ban_until_time = 0; // reset the ban time
+ auth_dat[i].ban_until_time = TimeT(); // reset the ban time
}
}
- if (auth_dat[i].connect_until_time != 0
- && auth_dat[i].connect_until_time < time (NULL))
+ if (auth_dat[i].connect_until_time
+ && auth_dat[i].connect_until_time < TimeT::now())
{
- login_log
- ("Connection refused (account: %s, expired ID, ip: %s)\n",
+ LOGIN_LOG("Connection refused (account: %s, expired ID, ip: %s)\n",
account->userid, ip);
return 2; // 2 = This ID is expired
}
- login_log ("Authentification accepted (account: %s (id: %d), ip: %s)\n",
+ LOGIN_LOG("Authentification accepted (account: %s (id: %d), ip: %s)\n",
account->userid, auth_dat[i].account_id, ip);
}
else
{
if (newaccount == 0)
{
- login_log
- ("Unknown account (account: %s, ip: %s)\n",
+ LOGIN_LOG("Unknown account (account: %s, ip: %s)\n",
account->userid, ip);
return 0; // 0 = Unregistered ID
}
else
{
- int new_id =
- mmo_auth_new (account, account->userid[len + 1], "a@a.com");
- login_log
- ("Account creation and authentification accepted (account %s (id: %d), sex: %c, connection with _F/_M, ip: %s)\n",
+ int new_id =
+ mmo_auth_new(account, account->userid[len + 1], "a@a.com");
+ LOGIN_LOG("Account creation and authentification accepted (account %s (id: %d), sex: %c, connection with _F/_M, ip: %s)\n",
account->userid, new_id,
account->userid[len + 1], ip);
}
}
- gettimeofday (&tv, NULL);
- strftime (tmpstr, 24, date_format, gmtime (&(tv.tv_sec)));
- sprintf (tmpstr + strlen (tmpstr), ".%03d", (int) tv.tv_usec / 1000);
+ timestamp_milliseconds_buffer tmpstr;
+ stamp_time(tmpstr);
account->account_id = auth_dat[i].account_id;
- account->login_id1 = mt_random ();
- account->login_id2 = mt_random ();
- memcpy (account->lastlogin, auth_dat[i].lastlogin, 24);
- memcpy (auth_dat[i].lastlogin, tmpstr, 24);
+ account->login_id1 = random_::generate();
+ account->login_id2 = random_::generate();
+ memcpy(account->lastlogin, auth_dat[i].lastlogin, 24);
+ memcpy(auth_dat[i].lastlogin, tmpstr, 24);
account->sex = auth_dat[i].sex;
- strncpy (auth_dat[i].last_ip, ip, 16);
+ strncpy(auth_dat[i].last_ip, ip, 16);
auth_dat[i].logincount++;
return -1; // account OK
@@ -1379,23 +1052,21 @@ int mmo_auth (struct mmo_account *account, int fd)
// Char-server anti-freeze system
//-------------------------------
static
-void char_anti_freeze_system (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data)
+void char_anti_freeze_system(TimerData *, tick_t)
{
- int i;
+ int i;
- //printf("Entering in char_anti_freeze_system function to check freeze of servers.\n");
+ //PRINTF("Entering in char_anti_freeze_system function to check freeze of servers.\n");
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]);
+ //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
- printf
- ("Char-server anti-freeze system: char-server #%d '%s' is freezed -> disconnection.\n",
+ PRINTF("Char-server anti-freeze system: char-server #%d '%s' is freezed -> disconnection.\n",
i, server[i].name);
- login_log
- ("Char-server anti-freeze system: char-server #%d '%s' is freezed -> disconnection.\n",
+ LOGIN_LOG("Char-server anti-freeze system: char-server #%d '%s' is freezed -> disconnection.\n",
i, server[i].name);
session[server_fd[i]]->eof = 1;
}
@@ -1407,9 +1078,9 @@ void char_anti_freeze_system (timer_id tid, tick_t tick, custom_id_t id, custom_
// Packet parsing for char-servers
//--------------------------------
static
-void parse_fromchar (int fd)
+void parse_fromchar(int fd)
{
- int i, j, id;
+ int i, j, id;
const char *ip = ip2str(session[fd]->client_addr.sin_addr);
@@ -1420,89 +1091,81 @@ void parse_fromchar (int fd)
{
if (id < MAX_SERVERS)
{
- printf ("Char-server '%s' has disconnected.\n", server[id].name);
- login_log ("Char-server '%s' has disconnected (ip: %s).\n",
+ PRINTF("Char-server '%s' has disconnected.\n", server[id].name);
+ LOGIN_LOG("Char-server '%s' has disconnected (ip: %s).\n",
server[id].name, ip);
server_fd[id] = -1;
- memset (&server[id], 0, sizeof (struct mmo_char_server));
+ memset(&server[id], 0, sizeof(struct mmo_char_server));
}
- close (fd);
- delete_session (fd);
+ delete_session(fd);
return;
}
- while (RFIFOREST (fd) >= 2)
+ while (RFIFOREST(fd) >= 2)
{
- if (display_parse_fromchar == 2 || (display_parse_fromchar == 1 && RFIFOW (fd, 0) != 0x2714)) // 0x2714 is done very often (number of players)
- printf
- ("parse_fromchar: connection #%d, packet: 0x%x (with being read: %d bytes).\n",
- fd, RFIFOW (fd, 0), RFIFOREST (fd));
+ if (display_parse_fromchar == 2 || (display_parse_fromchar == 1 && RFIFOW(fd, 0) != 0x2714)) // 0x2714 is done very often (number of players)
+ PRINTF("parse_fromchar: connection #%d, packet: 0x%x (with being read: %zu bytes).\n",
+ fd, RFIFOW(fd, 0), RFIFOREST(fd));
- switch (RFIFOW (fd, 0))
+ switch (RFIFOW(fd, 0))
{
// request from map-server via char-server to reload GM accounts (by Yor).
case 0x2709:
- login_log
- ("Char-server '%s': Request to re-load GM configuration file (ip: %s).\n",
+ LOGIN_LOG("Char-server '%s': Request to re-load GM configuration file (ip: %s).\n",
server[id].name, ip);
- read_gm_account ();
+ read_gm_account();
// send GM accounts to all char-servers
- send_GM_accounts ();
- RFIFOSKIP (fd, 2);
+ send_GM_accounts();
+ RFIFOSKIP(fd, 2);
break;
case 0x2712: // request from char-server to authentify an account
- if (RFIFOREST (fd) < 19)
+ if (RFIFOREST(fd) < 19)
return;
{
- int acc;
- acc = RFIFOL (fd, 2); // speed up
+ int acc;
+ acc = RFIFOL(fd, 2); // speed up
for (i = 0; i < AUTH_FIFO_SIZE; i++)
{
if (auth_fifo[i].account_id == acc &&
- 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) &&
+ auth_fifo[i].login_id1 == RFIFOL(fd, 6) &&
+ auth_fifo[i].login_id2 == RFIFOL(fd, 10) && // relate to the versions higher than 18
+ auth_fifo[i].sex == RFIFOB(fd, 14) &&
(!check_ip_flag
- || auth_fifo[i].ip == RFIFOL (fd, 15))
+ || auth_fifo[i].ip == RFIFOL(fd, 15))
&& !auth_fifo[i].delflag)
{
- int p, k;
+ int p, k;
auth_fifo[i].delflag = 1;
- login_log
- ("Char-server '%s': authentification of the account %d accepted (ip: %s).\n",
+ LOGIN_LOG("Char-server '%s': authentification of the account %d accepted (ip: %s).\n",
server[id].name, acc, ip);
-// printf("%d\n", i);
+// PRINTF("%d\n", i);
for (k = 0; k < auth_num; k++)
{
if (auth_dat[k].account_id == acc)
{
- WFIFOW (fd, 0) = 0x2729; // Sending of the account_reg2
- WFIFOL (fd, 4) = acc;
+ WFIFOW(fd, 0) = 0x2729; // Sending of the account_reg2
+ WFIFOL(fd, 4) = acc;
for (p = 8, j = 0;
j < auth_dat[k].account_reg2_num;
p += 36, j++)
{
- memcpy (WFIFOP (fd, p),
+ memcpy(WFIFOP(fd, p),
auth_dat[k].
account_reg2[j].str, 32);
- WFIFOL (fd, p + 32) =
+ WFIFOL(fd, p + 32) =
auth_dat[k].account_reg2[j].value;
}
- WFIFOW (fd, 2) = p;
- WFIFOSET (fd, p);
-// printf("parse_fromchar: Sending of account_reg2: login->char (auth fifo)\n");
- WFIFOW (fd, 0) = 0x2713;
- WFIFOL (fd, 2) = acc;
- WFIFOB (fd, 6) = 0;
- memcpy (WFIFOP (fd, 7), auth_dat[k].email,
+ WFIFOW(fd, 2) = p;
+ WFIFOSET(fd, p);
+// PRINTF("parse_fromchar: Sending of account_reg2: login->char (auth fifo)\n");
+ WFIFOW(fd, 0) = 0x2713;
+ WFIFOL(fd, 2) = acc;
+ WFIFOB(fd, 6) = 0;
+ memcpy(WFIFOP(fd, 7), auth_dat[k].email,
40);
- WFIFOL (fd, 47) =
- (unsigned long)
- auth_dat[k].connect_until_time;
- WFIFOSET (fd, 51);
+ WFIFOL(fd, 47) = static_cast<time_t>(auth_dat[k].connect_until_time);
+ WFIFOSET(fd, 51);
break;
}
}
@@ -1512,215 +1175,192 @@ void parse_fromchar (int fd)
// authentification not found
if (i == AUTH_FIFO_SIZE)
{
- login_log
- ("Char-server '%s': authentification of the account %d REFUSED (ip: %s).\n",
+ LOGIN_LOG("Char-server '%s': authentification of the account %d REFUSED (ip: %s).\n",
server[id].name, acc, ip);
- WFIFOW (fd, 0) = 0x2713;
- WFIFOL (fd, 2) = acc;
- WFIFOB (fd, 6) = 1;
+ WFIFOW(fd, 0) = 0x2713;
+ WFIFOL(fd, 2) = acc;
+ WFIFOB(fd, 6) = 1;
// It is unnecessary to send email
// It is unnecessary to send validity date of the account
- WFIFOSET (fd, 51);
+ WFIFOSET(fd, 51);
}
}
- RFIFOSKIP (fd, 19);
+ RFIFOSKIP(fd, 19);
break;
case 0x2714:
- if (RFIFOREST (fd) < 6)
+ if (RFIFOREST(fd) < 6)
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);
+ //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)
server_freezeflag[id] = 5; // Char anti-freeze system. Counter. 5 ok, 4...0 freezed
- RFIFOSKIP (fd, 6);
+ RFIFOSKIP(fd, 6);
break;
// we receive a e-mail creation of an account with a default e-mail (no answer)
case 0x2715:
{
- int acc;
+ int acc;
char email[40];
- if (RFIFOREST (fd) < 46)
+ if (RFIFOREST(fd) < 46)
return;
- acc = RFIFOL (fd, 2); // speed up
- memcpy (email, RFIFOP (fd, 6), 40);
+ acc = RFIFOL(fd, 2); // speed up
+ memcpy(email, RFIFOP(fd, 6), 40);
email[39] = '\0';
- remove_control_chars (email);
- //printf("parse_fromchar: an e-mail creation of an account with a default e-mail: server '%s', account: %d, e-mail: '%s'.\n", server[id].name, acc, RFIFOP(fd,6));
- if (e_mail_check (email) == 0)
- login_log
- ("Char-server '%s': Attempt to create an e-mail on an account with a default e-mail REFUSED - e-mail is invalid (account: %d, ip: %s)\n",
+ remove_control_chars(email);
+ //PRINTF("parse_fromchar: an e-mail creation of an account with a default e-mail: server '%s', account: %d, e-mail: '%s'.\n", server[id].name, acc, RFIFOP(fd,6));
+ if (e_mail_check(email) == 0)
+ LOGIN_LOG("Char-server '%s': Attempt to create an e-mail on an account with a default e-mail REFUSED - e-mail is invalid (account: %d, ip: %s)\n",
server[id].name, acc, ip);
else
{
for (i = 0; i < auth_num; i++)
{
if (auth_dat[i].account_id == acc
- && (strcmp (auth_dat[i].email, "a@a.com") == 0
+ && (strcmp(auth_dat[i].email, "a@a.com") == 0
|| auth_dat[i].email[0] == '\0'))
{
- memcpy (auth_dat[i].email, email, 40);
- login_log
- ("Char-server '%s': Create an e-mail on an account with a default e-mail (account: %d, new e-mail: %s, ip: %s).\n",
+ memcpy(auth_dat[i].email, email, 40);
+ LOGIN_LOG("Char-server '%s': Create an e-mail on an account with a default e-mail (account: %d, new e-mail: %s, ip: %s).\n",
server[id].name, acc, email, ip);
break;
}
}
if (i == auth_num)
- login_log
- ("Char-server '%s': Attempt to create an e-mail on an account with a default e-mail REFUSED - account doesn't exist or e-mail of account isn't default e-mail (account: %d, ip: %s).\n",
+ LOGIN_LOG("Char-server '%s': Attempt to create an e-mail on an account with a default e-mail REFUSED - account doesn't exist or e-mail of account isn't default e-mail (account: %d, ip: %s).\n",
server[id].name, acc, ip);
}
- RFIFOSKIP (fd, 46);
+ RFIFOSKIP(fd, 46);
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)
+ if (RFIFOREST(fd) < 6)
return;
- //printf("parse_fromchar: E-mail/limited time request from '%s' server (concerned account: %d)\n", server[id].name, RFIFOL(fd,2));
+ //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++)
{
- if (auth_dat[i].account_id == RFIFOL (fd, 2))
+ if (auth_dat[i].account_id == RFIFOL(fd, 2))
{
- login_log
- ("Char-server '%s': e-mail of the account %d found (ip: %s).\n",
- server[id].name, RFIFOL (fd, 2), ip);
- WFIFOW (fd, 0) = 0x2717;
- WFIFOL (fd, 2) = RFIFOL (fd, 2);
- memcpy (WFIFOP (fd, 6), auth_dat[i].email, 40);
- WFIFOL (fd, 46) =
- (unsigned long) auth_dat[i].connect_until_time;
- WFIFOSET (fd, 50);
+ LOGIN_LOG("Char-server '%s': e-mail of the account %d found (ip: %s).\n",
+ server[id].name, RFIFOL(fd, 2), ip);
+ WFIFOW(fd, 0) = 0x2717;
+ WFIFOL(fd, 2) = RFIFOL(fd, 2);
+ memcpy(WFIFOP(fd, 6), auth_dat[i].email, 40);
+ WFIFOL(fd, 46) = static_cast<time_t>(auth_dat[i].connect_until_time);
+ WFIFOSET(fd, 50);
break;
}
}
if (i == auth_num)
{
- login_log
- ("Char-server '%s': e-mail of the account %d NOT found (ip: %s).\n",
- server[id].name, RFIFOL (fd, 2), ip);
+ LOGIN_LOG("Char-server '%s': e-mail of the account %d NOT found (ip: %s).\n",
+ server[id].name, RFIFOL(fd, 2), ip);
}
- RFIFOSKIP (fd, 6);
+ RFIFOSKIP(fd, 6);
break;
case 0x2720: // To become GM request
- if (RFIFOREST (fd) < 4 || RFIFOREST (fd) < RFIFOW (fd, 2))
+ if (RFIFOREST(fd) < 4 || RFIFOREST(fd) < RFIFOW(fd, 2))
return;
{
- int acc;
+ int acc;
unsigned char buf[10];
FILE *fp;
- acc = RFIFOL (fd, 4);
- //printf("parse_fromchar: Request to become a GM acount from %d account.\n", acc);
- WBUFW (buf, 0) = 0x2721;
- WBUFL (buf, 2) = acc;
- WBUFL (buf, 6) = 0;
- if (strcmp ((const char *)RFIFOP (fd, 8), gm_pass) == 0)
+ acc = RFIFOL(fd, 4);
+ //PRINTF("parse_fromchar: Request to become a GM acount from %d account.\n", acc);
+ WBUFW(buf, 0) = 0x2721;
+ WBUFL(buf, 2) = acc;
+ WBUFL(buf, 6) = 0;
+ if (strcmp((const char *)RFIFOP(fd, 8), gm_pass) == 0)
{
// only non-GM can become GM
- if (isGM (acc) == 0)
+ if (isGM(acc) == 0)
{
// if we autorise creation
if (level_new_gm > 0)
{
// if we can open the file to add the new GM
if ((fp =
- fopen_ (GM_account_filename,
+ fopen_(GM_account_filename,
"a")) != NULL)
{
- char tmpstr[24];
- struct timeval tv;
- gettimeofday (&tv, NULL);
- strftime (tmpstr, 23, date_format,
- gmtime (&(tv.tv_sec)));
- fprintf (fp,
+ timestamp_seconds_buffer tmpstr;
+ stamp_time(tmpstr);
+ FPRINTF(fp,
"\n// %s: @GM command on account %d\n%d %d\n",
tmpstr,
acc, acc, level_new_gm);
- fclose_ (fp);
- WBUFL (buf, 6) = level_new_gm;
- read_gm_account ();
- send_GM_accounts ();
- printf
- ("GM Change of the account %d: level 0 -> %d.\n",
+ fclose_(fp);
+ WBUFL(buf, 6) = level_new_gm;
+ read_gm_account();
+ send_GM_accounts();
+ PRINTF("GM Change of the account %d: level 0 -> %d.\n",
acc, level_new_gm);
- login_log
- ("Char-server '%s': GM Change of the account %d: level 0 -> %d (ip: %s).\n",
+ LOGIN_LOG("Char-server '%s': GM Change of the account %d: level 0 -> %d (ip: %s).\n",
server[id].name, acc,
level_new_gm, ip);
}
else
{
- printf
- ("Error of GM change (suggested account: %d, correct password, unable to add a GM account in GM accounts file)\n",
+ PRINTF("Error of GM change (suggested account: %d, correct password, unable to add a GM account in GM accounts file)\n",
acc);
- login_log
- ("Char-server '%s': Error of GM change (suggested account: %d, correct password, unable to add a GM account in GM accounts file, ip: %s).\n",
+ LOGIN_LOG("Char-server '%s': Error of GM change (suggested account: %d, correct password, unable to add a GM account in GM accounts file, ip: %s).\n",
server[id].name, acc, ip);
}
}
else
{
- printf
- ("Error of GM change (suggested account: %d, correct password, but GM creation is disable (level_new_gm = 0))\n",
+ PRINTF("Error of GM change (suggested account: %d, correct password, but GM creation is disable (level_new_gm = 0))\n",
acc);
- login_log
- ("Char-server '%s': Error of GM change (suggested account: %d, correct password, but GM creation is disable (level_new_gm = 0), ip: %s).\n",
+ LOGIN_LOG("Char-server '%s': Error of GM change (suggested account: %d, correct password, but GM creation is disable (level_new_gm = 0), ip: %s).\n",
server[id].name, acc, ip);
}
}
else
{
- printf
- ("Error of GM change (suggested account: %d (already GM), correct password).\n",
+ PRINTF("Error of GM change (suggested account: %d (already GM), correct password).\n",
acc);
- login_log
- ("Char-server '%s': Error of GM change (suggested account: %d (already GM), correct password, ip: %s).\n",
+ LOGIN_LOG("Char-server '%s': Error of GM change (suggested account: %d (already GM), correct password, ip: %s).\n",
server[id].name, acc, ip);
}
}
else
{
- printf
- ("Error of GM change (suggested account: %d, invalid password).\n",
+ PRINTF("Error of GM change (suggested account: %d, invalid password).\n",
acc);
- login_log
- ("Char-server '%s': Error of GM change (suggested account: %d, invalid password, ip: %s).\n",
+ LOGIN_LOG("Char-server '%s': Error of GM change (suggested account: %d, invalid password, ip: %s).\n",
server[id].name, acc, ip);
}
- charif_sendallwos (-1, buf, 10);
+ charif_sendallwos(-1, buf, 10);
}
- RFIFOSKIP (fd, RFIFOW (fd, 2));
+ RFIFOSKIP(fd, RFIFOW(fd, 2));
return;
// Map server send information to change an email of an account via char-server
case 0x2722: // 0x2722 <account_id>.L <actual_e-mail>.40B <new_e-mail>.40B
- if (RFIFOREST (fd) < 86)
+ if (RFIFOREST(fd) < 86)
return;
{
- int acc;
+ int acc;
char actual_email[40], new_email[40];
- acc = RFIFOL (fd, 2);
- memcpy (actual_email, RFIFOP (fd, 6), 40);
+ acc = RFIFOL(fd, 2);
+ memcpy(actual_email, RFIFOP(fd, 6), 40);
actual_email[39] = '\0';
- remove_control_chars (actual_email);
- memcpy (new_email, RFIFOP (fd, 46), 40);
+ remove_control_chars(actual_email);
+ memcpy(new_email, RFIFOP(fd, 46), 40);
new_email[39] = '\0';
- remove_control_chars (new_email);
- if (e_mail_check (actual_email) == 0)
- login_log
- ("Char-server '%s': Attempt to modify an e-mail on an account (@email GM command), but actual email is invalid (account: %d, ip: %s)\n",
+ remove_control_chars(new_email);
+ if (e_mail_check(actual_email) == 0)
+ LOGIN_LOG("Char-server '%s': Attempt to modify an e-mail on an account (@email GM command), but actual email is invalid (account: %d, ip: %s)\n",
server[id].name, acc, ip);
- else if (e_mail_check (new_email) == 0)
- 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)\n",
+ else if (e_mail_check(new_email) == 0)
+ 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)\n",
server[id].name, acc, ip);
- 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)\n",
+ 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)\n",
server[id].name, acc, ip);
else
{
@@ -1728,18 +1368,16 @@ void parse_fromchar (int fd)
{
if (auth_dat[i].account_id == acc)
{
- if (strcasecmp (auth_dat[i].email, actual_email)
+ if (strcasecmp(auth_dat[i].email, actual_email)
== 0)
{
- memcpy (auth_dat[i].email, new_email, 40);
- login_log
- ("Char-server '%s': Modify an e-mail on an account (@email GM command) (account: %d (%s), new e-mail: %s, ip: %s).\n",
+ memcpy(auth_dat[i].email, new_email, 40);
+ LOGIN_LOG("Char-server '%s': Modify an e-mail on an account (@email GM command) (account: %d (%s), new e-mail: %s, ip: %s).\n",
server[id].name, acc,
auth_dat[i].userid, new_email, ip);
}
else
- login_log
- ("Char-server '%s': Attempt to modify an e-mail on an account (@email GM command), but actual e-mail is incorrect (account: %d (%s), actual e-mail: %s, proposed e-mail: %s, ip: %s).\n",
+ LOGIN_LOG("Char-server '%s': Attempt to modify an e-mail on an account (@email GM command), but actual e-mail is incorrect (account: %d (%s), actual e-mail: %s, proposed e-mail: %s, ip: %s).\n",
server[id].name, acc,
auth_dat[i].userid,
auth_dat[i].email, actual_email, ip);
@@ -1747,40 +1385,38 @@ void parse_fromchar (int fd)
}
}
if (i == auth_num)
- login_log
- ("Char-server '%s': Attempt to modify an e-mail on an account (@email GM command), but account doesn't exist (account: %d, ip: %s).\n",
+ LOGIN_LOG("Char-server '%s': Attempt to modify an e-mail on an account (@email GM command), but account doesn't exist (account: %d, ip: %s).\n",
server[id].name, acc, ip);
}
}
- RFIFOSKIP (fd, 86);
+ RFIFOSKIP(fd, 86);
break;
// Receiving of map-server via char-server a status change resquest (by Yor)
case 0x2724:
- if (RFIFOREST (fd) < 10)
+ if (RFIFOREST(fd) < 10)
return;
{
- int acc, statut;
- acc = RFIFOL (fd, 2);
- statut = RFIFOL (fd, 6);
+ int acc, statut;
+ acc = RFIFOL(fd, 2);
+ statut = RFIFOL(fd, 6);
for (i = 0; i < auth_num; i++)
{
if (auth_dat[i].account_id == acc)
{
if (auth_dat[i].state != statut)
{
- login_log
- ("Char-server '%s': Status change (account: %d, new status %d, ip: %s).\n",
+ LOGIN_LOG("Char-server '%s': Status change (account: %d, new status %d, ip: %s).\n",
server[id].name, acc, statut,
ip);
if (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);
+ 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);
for (j = 0; j < AUTH_FIFO_SIZE; j++)
if (auth_fifo[j].account_id == acc)
auth_fifo[j].login_id1++; // to avoid reconnection error when come back from map-server (char-server will ask again the authentification)
@@ -1788,8 +1424,7 @@ void parse_fromchar (int fd)
auth_dat[i].state = statut;
}
else
- login_log
- ("Char-server '%s': Error of Status change - actual status is already the good status (account: %d, status %d, ip: %s).\n",
+ LOGIN_LOG("Char-server '%s': Error of Status change - actual status is already the good status (account: %d, status %d, ip: %s).\n",
server[id].name, acc, statut,
ip);
break;
@@ -1797,70 +1432,61 @@ void parse_fromchar (int fd)
}
if (i == auth_num)
{
- login_log
- ("Char-server '%s': Error of Status change (account: %d not found, suggested status %d, ip: %s).\n",
+ LOGIN_LOG("Char-server '%s': Error of Status change (account: %d not found, suggested status %d, ip: %s).\n",
server[id].name, acc, statut, ip);
}
- RFIFOSKIP (fd, 10);
+ RFIFOSKIP(fd, 10);
}
return;
case 0x2725: // Receiving of map-server via char-server a ban resquest (by Yor)
- if (RFIFOREST (fd) < 18)
+ if (RFIFOREST(fd) < 18)
return;
{
- int acc;
- acc = RFIFOL (fd, 2);
+ int acc;
+ acc = RFIFOL(fd, 2);
for (i = 0; i < auth_num; i++)
{
if (auth_dat[i].account_id == acc)
{
- time_t timestamp;
- struct tm *tmtime;
- if (auth_dat[i].ban_until_time == 0
- || auth_dat[i].ban_until_time < time (NULL))
- timestamp = time (NULL);
+ TimeT now = TimeT::now();
+ TimeT timestamp;
+ if (!auth_dat[i].ban_until_time
+ || auth_dat[i].ban_until_time < now)
+ timestamp = now;
else
timestamp = auth_dat[i].ban_until_time;
- tmtime = gmtime (&timestamp);
- 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)
+ struct tm tmtime = timestamp;
+ tmtime.tm_year += (short) RFIFOW(fd, 6);
+ tmtime.tm_mon += (short) RFIFOW(fd, 8);
+ tmtime.tm_mday += (short) RFIFOW(fd, 10);
+ tmtime.tm_hour += (short) RFIFOW(fd, 12);
+ tmtime.tm_min += (short) RFIFOW(fd, 14);
+ tmtime.tm_sec += (short) RFIFOW(fd, 16);
+ timestamp = tmtime;
+ if (timestamp.okay())
{
- if (timestamp <= time (NULL))
- timestamp = 0;
+ if (timestamp <= now)
+ timestamp = TimeT();
if (auth_dat[i].ban_until_time != timestamp)
{
- if (timestamp != 0)
+ if (timestamp)
{
unsigned char buf[16];
- char tmpstr[2048];
- strftime (tmpstr, 24, date_format,
- gmtime (&timestamp));
- login_log
- ("Char-server '%s': Ban request (account: %d, new final date of banishment: %ld (%s), ip: %s).\n",
- server[id].name, acc,
- timestamp,
- (timestamp ==
- 0 ? "no banishment" : tmpstr),
- ip);
- WBUFW (buf, 0) = 0x2731;
- WBUFL (buf, 2) =
+ timestamp_seconds_buffer tmpstr;
+ if (timestamp)
+ stamp_time(tmpstr, &timestamp);
+ LOGIN_LOG("Char-server '%s': Ban request (account: %d, new final date of banishment: %lld (%s), ip: %s).\n",
+ server[id].name, acc,
+ timestamp,
+ tmpstr,
+ ip);
+ WBUFW(buf, 0) = 0x2731;
+ WBUFL(buf, 2) =
auth_dat[i].account_id;
- 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);
+ WBUFB(buf, 6) = 1; // 0: change of statut, 1: ban
+ WBUFL(buf, 7) = static_cast<time_t>(timestamp); // status or final date of a banishment
+ charif_sendallwos(-1, buf, 11);
for (j = 0; j < AUTH_FIFO_SIZE; j++)
if (auth_fifo[j].account_id ==
acc)
@@ -1868,8 +1494,7 @@ void parse_fromchar (int fd)
}
else
{
- login_log
- ("Char-server '%s': Error of ban request (account: %d, new date unbans the account, ip: %s).\n",
+ LOGIN_LOG("Char-server '%s': Error of ban request (account: %d, new date unbans the account, ip: %s).\n",
server[id].name, acc,
ip);
}
@@ -1877,15 +1502,13 @@ void parse_fromchar (int fd)
}
else
{
- login_log
- ("Char-server '%s': Error of ban request (account: %d, no change for ban date, ip: %s).\n",
+ LOGIN_LOG("Char-server '%s': Error of ban request (account: %d, no change for ban date, ip: %s).\n",
server[id].name, acc, ip);
}
}
else
{
- login_log
- ("Char-server '%s': Error of ban request (account: %d, invalid date, ip: %s).\n",
+ LOGIN_LOG("Char-server '%s': Error of ban request (account: %d, invalid date, ip: %s).\n",
server[id].name, acc, ip);
}
break;
@@ -1893,28 +1516,26 @@ void parse_fromchar (int fd)
}
if (i == auth_num)
{
- login_log
- ("Char-server '%s': Error of ban request (account: %d not found, ip: %s).\n",
+ LOGIN_LOG("Char-server '%s': Error of ban request (account: %d not found, ip: %s).\n",
server[id].name, acc, ip);
}
- RFIFOSKIP (fd, 18);
+ RFIFOSKIP(fd, 18);
}
return;
case 0x2727: // Change of sex (sex is reversed)
- if (RFIFOREST (fd) < 6)
+ if (RFIFOREST(fd) < 6)
return;
{
- int acc, sex;
- acc = RFIFOL (fd, 2);
+ int acc, sex;
+ acc = RFIFOL(fd, 2);
for (i = 0; i < auth_num; i++)
{
-// printf("%d,", auth_dat[i].account_id);
+// PRINTF("%d,", auth_dat[i].account_id);
if (auth_dat[i].account_id == acc)
{
if (auth_dat[i].sex == 2)
- login_log
- ("Char-server '%s': Error of sex change - Server account (suggested account: %d, actual sex %d (Server), ip: %s).\n",
+ LOGIN_LOG("Char-server '%s': Error of sex change - Server account (suggested account: %d, actual sex %d (Server), ip: %s).\n",
server[id].name, acc,
auth_dat[i].sex, ip);
else
@@ -1924,8 +1545,7 @@ void parse_fromchar (int fd)
sex = 1;
else
sex = 0;
- login_log
- ("Char-server '%s': Sex change (account: %d, new sex %c, ip: %s).\n",
+ LOGIN_LOG("Char-server '%s': Sex change (account: %d, new sex %c, ip: %s).\n",
server[id].name, acc,
(sex == 2) ? 'S' : (sex ? 'M' : 'F'),
ip);
@@ -1933,92 +1553,87 @@ void parse_fromchar (int fd)
if (auth_fifo[j].account_id == acc)
auth_fifo[j].login_id1++; // to avoid reconnection error when come back from map-server (char-server will ask again the authentification)
auth_dat[i].sex = sex;
- WBUFW (buf, 0) = 0x2723;
- WBUFL (buf, 2) = acc;
- WBUFB (buf, 6) = sex;
- charif_sendallwos (-1, buf, 7);
+ WBUFW(buf, 0) = 0x2723;
+ WBUFL(buf, 2) = acc;
+ WBUFB(buf, 6) = sex;
+ charif_sendallwos(-1, buf, 7);
}
break;
}
}
if (i == auth_num)
{
- login_log
- ("Char-server '%s': Error of sex change (account: %d not found, sex would be reversed, ip: %s).\n",
+ LOGIN_LOG("Char-server '%s': Error of sex change (account: %d not found, sex would be reversed, ip: %s).\n",
server[id].name, acc, ip);
}
- RFIFOSKIP (fd, 6);
+ RFIFOSKIP(fd, 6);
}
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))
+ if (RFIFOREST(fd) < 4 || RFIFOREST(fd) < RFIFOW(fd, 2))
return;
{
- int acc, p;
- acc = RFIFOL (fd, 4);
+ int acc, p;
+ acc = RFIFOL(fd, 4);
for (i = 0; i < auth_num; i++)
{
if (auth_dat[i].account_id == acc)
{
- unsigned char buf[RFIFOW (fd, 2) + 1];
- login_log
- ("Char-server '%s': receiving (from the char-server) of account_reg2 (account: %d, ip: %s).\n",
+ unsigned char buf[RFIFOW(fd, 2) + 1];
+ LOGIN_LOG("Char-server '%s': receiving (from the char-server) of account_reg2 (account: %d, ip: %s).\n",
server[id].name, acc, ip);
for (p = 8, j = 0;
- p < RFIFOW (fd, 2) && j < ACCOUNT_REG2_NUM;
+ p < RFIFOW(fd, 2) && j < ACCOUNT_REG2_NUM;
p += 36, j++)
{
- memcpy (auth_dat[i].account_reg2[j].str,
- RFIFOP (fd, p), 32);
+ memcpy(auth_dat[i].account_reg2[j].str,
+ RFIFOP(fd, p), 32);
auth_dat[i].account_reg2[j].str[31] = '\0';
- remove_control_chars (auth_dat[i].account_reg2
+ remove_control_chars(auth_dat[i].account_reg2
[j].str);
auth_dat[i].account_reg2[j].value =
- RFIFOL (fd, p + 32);
+ RFIFOL(fd, p + 32);
}
auth_dat[i].account_reg2_num = j;
// Sending information towards the other char-servers.
- memcpy (WBUFP (buf, 0), RFIFOP (fd, 0),
- RFIFOW (fd, 2));
- WBUFW (buf, 0) = 0x2729;
- charif_sendallwos (fd, buf, WBUFW (buf, 2));
-// printf("parse_fromchar: receiving (from the char-server) of account_reg2 (account id: %d).\n", acc);
+ memcpy(WBUFP(buf, 0), RFIFOP(fd, 0),
+ RFIFOW(fd, 2));
+ WBUFW(buf, 0) = 0x2729;
+ charif_sendallwos(fd, buf, WBUFW(buf, 2));
+// PRINTF("parse_fromchar: receiving (from the char-server) of account_reg2 (account id: %d).\n", acc);
break;
}
}
if (i == auth_num)
{
-// printf("parse_fromchar: receiving (from the char-server) of account_reg2 (unknwon account id: %d).\n", acc);
- login_log
- ("Char-server '%s': receiving (from the char-server) of account_reg2 (account: %d not found, ip: %s).\n",
+// PRINTF("parse_fromchar: receiving (from the char-server) of account_reg2 (unknwon account id: %d).\n", acc);
+ LOGIN_LOG("Char-server '%s': receiving (from the char-server) of account_reg2 (account: %d not found, ip: %s).\n",
server[id].name, acc, ip);
}
}
- RFIFOSKIP (fd, RFIFOW (fd, 2));
+ RFIFOSKIP(fd, RFIFOW(fd, 2));
break;
case 0x272a: // Receiving of map-server via char-server a unban resquest (by Yor)
- if (RFIFOREST (fd) < 6)
+ if (RFIFOREST(fd) < 6)
return;
{
- int acc;
- acc = RFIFOL (fd, 2);
+ int acc;
+ acc = RFIFOL(fd, 2);
for (i = 0; i < auth_num; i++)
{
if (auth_dat[i].account_id == acc)
{
- if (auth_dat[i].ban_until_time != 0)
+ if (auth_dat[i].ban_until_time)
{
- auth_dat[i].ban_until_time = 0;
- login_log
- ("Char-server '%s': UnBan request (account: %d, ip: %s).\n",
+ auth_dat[i].ban_until_time = TimeT();
+ LOGIN_LOG("Char-server '%s': UnBan request (account: %d, ip: %s).\n",
server[id].name, acc, ip);
}
else
{
- login_log
- ("Char-server '%s': Error of UnBan request (account: %d, no change for unban date, ip: %s).\n",
+ LOGIN_LOG("Char-server '%s': Error of UnBan request (account: %d, no change for unban date, ip: %s).\n",
server[id].name, acc, ip);
}
break;
@@ -2026,45 +1641,43 @@ void parse_fromchar (int fd)
}
if (i == auth_num)
{
- login_log
- ("Char-server '%s': Error of UnBan request (account: %d not found, ip: %s).\n",
+ LOGIN_LOG("Char-server '%s': Error of UnBan request (account: %d not found, ip: %s).\n",
server[id].name, acc, ip);
}
- RFIFOSKIP (fd, 6);
+ RFIFOSKIP(fd, 6);
}
return;
// request from char-server to change account password
case 0x2740: // 0x2740 <account_id>.L <actual_password>.24B <new_password>.24B
- if (RFIFOREST (fd) < 54)
+ if (RFIFOREST(fd) < 54)
return;
{
- int acc;
+ int acc;
char actual_pass[24], new_pass[24];
- acc = RFIFOL (fd, 2);
- memcpy (actual_pass, RFIFOP (fd, 6), 24);
+ acc = RFIFOL(fd, 2);
+ memcpy(actual_pass, RFIFOP(fd, 6), 24);
actual_pass[23] = '\0';
- remove_control_chars (actual_pass);
- memcpy (new_pass, RFIFOP (fd, 30), 24);
+ remove_control_chars(actual_pass);
+ memcpy(new_pass, RFIFOP(fd, 30), 24);
new_pass[23] = '\0';
- remove_control_chars (new_pass);
+ remove_control_chars(new_pass);
- int status = 0;
+ int status = 0;
for (i = 0; i < auth_num; i++)
{
if (auth_dat[i].account_id == acc)
{
- if (pass_ok (actual_pass, auth_dat[i].pass))
+ if (pass_ok(actual_pass, auth_dat[i].pass))
{
- if (strlen (new_pass) < 4)
+ if (strlen(new_pass) < 4)
status = 3;
else
{
status = 1;
- strcpy (auth_dat[i].pass, MD5_saltcrypt(new_pass, make_salt()));
- login_log
- ("Char-server '%s': Change pass success (account: %d (%s), ip: %s.\n",
+ strcpy(auth_dat[i].pass, MD5_saltcrypt(new_pass, make_salt()));
+ LOGIN_LOG("Char-server '%s': Change pass success (account: %d (%s), ip: %s.\n",
server[id].name, acc,
auth_dat[i].userid, ip);
}
@@ -2072,80 +1685,75 @@ void parse_fromchar (int fd)
else
{
status = 2;
- login_log
- ("Char-server '%s': Attempt to modify a pass failed, wrong password. (account: %d (%s), ip: %s).\n",
+ LOGIN_LOG("Char-server '%s': Attempt to modify a pass failed, wrong password. (account: %d (%s), ip: %s).\n",
server[id].name, acc,
auth_dat[i].userid, ip);
}
break;
}
}
- WFIFOW (fd, 0) = 0x2741;
- WFIFOL (fd, 2) = acc;
- WFIFOB (fd, 6) = status; // 0: acc not found, 1: success, 2: password mismatch, 3: pass too short
- WFIFOSET (fd, 7);
+ WFIFOW(fd, 0) = 0x2741;
+ WFIFOL(fd, 2) = acc;
+ WFIFOB(fd, 6) = status; // 0: acc not found, 1: success, 2: password mismatch, 3: pass too short
+ WFIFOSET(fd, 7);
}
- RFIFOSKIP (fd, 54);
+ RFIFOSKIP(fd, 54);
break;
default:
{
FILE *logfp;
- char tmpstr[24];
- struct timeval tv;
- logfp = fopen_ (login_log_unknown_packets_filename, "a");
+ logfp = fopen_(login_log_unknown_packets_filename, "a");
if (logfp)
{
- gettimeofday (&tv, NULL);
- strftime (tmpstr, 23, date_format, gmtime (&(tv.tv_sec)));
- fprintf (logfp,
- "%s.%03d: receiving of an unknown packet -> disconnection\n",
- tmpstr, (int) tv.tv_usec / 1000);
- fprintf (logfp,
- "parse_fromchar: connection #%d (ip: %s), packet: 0x%x (with being read: %d).\n",
- fd, ip, RFIFOW (fd, 0), RFIFOREST (fd));
- fprintf (logfp, "Detail (in hex):\n");
- fprintf (logfp,
+ timestamp_milliseconds_buffer tmpstr;
+ stamp_time(tmpstr);
+ FPRINTF(logfp,
+ "%s: receiving of an unknown packet -> disconnection\n",
+ tmpstr);
+ FPRINTF(logfp,
+ "parse_fromchar: connection #%d (ip: %s), packet: 0x%x (with being read: %zu).\n",
+ fd, ip, RFIFOW(fd, 0), RFIFOREST(fd));
+ FPRINTF(logfp, "Detail (in hex):\n");
+ FPRINTF(logfp,
"---- 00-01-02-03-04-05-06-07 08-09-0A-0B-0C-0D-0E-0F\n");
- memset (tmpstr, '\0', sizeof (tmpstr));
- for (i = 0; i < RFIFOREST (fd); i++)
+ memset(tmpstr, '\0', sizeof(tmpstr));
+ for (i = 0; i < RFIFOREST(fd); i++)
{
if ((i & 15) == 0)
- fprintf (logfp, "%04X ", i);
- fprintf (logfp, "%02x ", RFIFOB (fd, i));
- if (RFIFOB (fd, i) > 0x1f)
- tmpstr[i % 16] = RFIFOB (fd, i);
+ FPRINTF(logfp, "%04X ", i);
+ FPRINTF(logfp, "%02x ", RFIFOB(fd, i));
+ if (RFIFOB(fd, i) > 0x1f)
+ tmpstr[i % 16] = RFIFOB(fd, i);
else
tmpstr[i % 16] = '.';
if ((i - 7) % 16 == 0) // -8 + 1
- fprintf (logfp, " ");
+ FPRINTF(logfp, " ");
else if ((i + 1) % 16 == 0)
{
- fprintf (logfp, " %s\n", tmpstr);
- memset (tmpstr, '\0', sizeof (tmpstr));
+ FPRINTF(logfp, " %s\n", tmpstr);
+ memset(tmpstr, '\0', sizeof(tmpstr));
}
}
if (i % 16 != 0)
{
for (j = i; j % 16 != 0; j++)
{
- fprintf (logfp, " ");
+ FPRINTF(logfp, " ");
if ((j - 7) % 16 == 0) // -8 + 1
- fprintf (logfp, " ");
+ FPRINTF(logfp, " ");
}
- fprintf (logfp, " %s\n", tmpstr);
+ FPRINTF(logfp, " %s\n", tmpstr);
}
- fprintf (logfp, "\n");
- fclose_ (logfp);
+ FPRINTF(logfp, "\n");
+ fclose_(logfp);
}
}
- printf
- ("parse_fromchar: Unknown packet 0x%x (from a char-server)! -> disconnection.\n",
- RFIFOW (fd, 0));
+ PRINTF("parse_fromchar: Unknown packet 0x%x (from a char-server)! -> disconnection.\n",
+ RFIFOW(fd, 0));
session[fd]->eof = 1;
- printf
- ("Char-server has been disconnected (unknown packet).\n");
+ PRINTF("Char-server has been disconnected (unknown packet).\n");
return;
}
}
@@ -2156,74 +1764,71 @@ void parse_fromchar (int fd)
// Packet parsing for administation login
//---------------------------------------
static
-void parse_admin (int fd)
+void parse_admin(int fd)
{
- int i, j;
- char *account_name;
+ int i, j;
+ char account_name[24];
const char *ip = ip2str(session[fd]->client_addr.sin_addr);
if (session[fd]->eof)
{
- close (fd);
- delete_session (fd);
- printf ("Remote administration has disconnected (session #%d).\n",
+ delete_session(fd);
+ PRINTF("Remote administration has disconnected (session #%d).\n",
fd);
return;
}
- while (RFIFOREST (fd) >= 2)
+ while (RFIFOREST(fd) >= 2)
{
if (display_parse_admin == 1)
- printf
- ("parse_admin: connection #%d, packet: 0x%x (with being read: %d).\n",
- fd, RFIFOW (fd, 0), RFIFOREST (fd));
+ PRINTF("parse_admin: connection #%d, packet: 0x%x (with being read: %zu).\n",
+ fd, RFIFOW(fd, 0), RFIFOREST(fd));
- switch (RFIFOW (fd, 0))
+ switch (RFIFOW(fd, 0))
{
case 0x7530: // Request of the server version
- login_log ("'ladmin': Sending of the server version (ip: %s)\n",
+ LOGIN_LOG("'ladmin': Sending of the server version (ip: %s)\n",
ip);
- 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);
+ 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);
break;
case 0x7532: // Request of end of connection
- login_log ("'ladmin': End of connection (ip: %s)\n",
+ LOGIN_LOG("'ladmin': End of connection (ip: %s)\n",
ip);
- RFIFOSKIP (fd, 2);
+ RFIFOSKIP(fd, 2);
session[fd]->eof = 1;
break;
case 0x7920: // Request of an accounts list
- if (RFIFOREST (fd) < 10)
+ if (RFIFOREST(fd) < 10)
return;
{
- int st, ed, len;
- int id[auth_num];
- st = RFIFOL (fd, 2);
- ed = RFIFOL (fd, 6);
- RFIFOSKIP (fd, 10);
- WFIFOW (fd, 0) = 0x7921;
+ int st, ed, len;
+ int id[auth_num];
+ st = RFIFOL(fd, 2);
+ ed = RFIFOL(fd, 6);
+ RFIFOSKIP(fd, 10);
+ WFIFOW(fd, 0) = 0x7921;
if (st < 0)
st = 0;
if (ed > END_ACCOUNT_NUM || ed < st || ed <= 0)
ed = END_ACCOUNT_NUM;
- login_log
- ("'ladmin': Sending an accounts list (ask: from %d to %d, ip: %s)\n",
+ LOGIN_LOG("'ladmin': Sending an accounts list (ask: from %d to %d, ip: %s)\n",
st, ed, ip);
// Sort before send
for (i = 0; i < auth_num; i++)
{
- int k;
+ int k;
id[i] = i;
for (j = 0; j < i; j++)
{
@@ -2243,363 +1848,332 @@ void parse_admin (int fd)
len = 4;
for (i = 0; i < auth_num && len < 30000; i++)
{
- int account_id = auth_dat[id[i]].account_id; // use sorted index
+ int account_id = auth_dat[id[i]].account_id; // use sorted index
if (account_id >= st && account_id <= ed)
{
j = id[i];
- WFIFOL (fd, len) = account_id;
- WFIFOB (fd, len + 4) =
- (unsigned char) isGM (account_id);
- memcpy (WFIFOP (fd, len + 5), auth_dat[j].userid,
+ WFIFOL(fd, len) = account_id;
+ WFIFOB(fd, len + 4) =
+ (unsigned char) isGM(account_id);
+ memcpy(WFIFOP(fd, len + 5), auth_dat[j].userid,
24);
- WFIFOB (fd, len + 29) = auth_dat[j].sex;
- WFIFOL (fd, len + 30) = auth_dat[j].logincount;
- if (auth_dat[j].state == 0 && auth_dat[j].ban_until_time != 0) // if no state and banished
- WFIFOL (fd, len + 34) = 7; // 6 = Your are Prohibited to log in until %s
+ WFIFOB(fd, len + 29) = auth_dat[j].sex;
+ WFIFOL(fd, len + 30) = auth_dat[j].logincount;
+ if (auth_dat[j].state == 0 && auth_dat[j].ban_until_time) // if no state and banished
+ WFIFOL(fd, len + 34) = 7; // 6 = Your are Prohibited to log in until %s
else
- WFIFOL (fd, len + 34) = auth_dat[j].state;
+ WFIFOL(fd, len + 34) = auth_dat[j].state;
len += 38;
}
}
- WFIFOW (fd, 2) = len;
- WFIFOSET (fd, len);
+ WFIFOW(fd, 2) = len;
+ WFIFOSET(fd, len);
}
break;
case 0x7924:
{ // [Fate] Itemfrob package: change item IDs
- if (RFIFOREST (fd) < 10)
+ if (RFIFOREST(fd) < 10)
return;
- charif_sendallwos (-1, RFIFOP (fd, 0), 10); // forward package to char servers
- RFIFOSKIP (fd, 10);
- WFIFOW (fd, 0) = 0x7925;
- WFIFOSET (fd, 2);
+ uint8_t buf[10];
+ memcpy(buf, RFIFOP(fd, 0), 10);
+ // forward package to char servers
+ charif_sendallwos(-1, buf, 10);
+ RFIFOSKIP(fd, 10);
+ WFIFOW(fd, 0) = 0x7925;
+ WFIFOSET(fd, 2);
break;
}
case 0x7930: // Request for an account creation
- if (RFIFOREST (fd) < 91)
+ if (RFIFOREST(fd) < 91)
return;
{
struct mmo_account ma;
- ma.userid = (char *)RFIFOP (fd, 2);
- ma.passwd = (char *)RFIFOP (fd, 26);
- memcpy (ma.lastlogin, "-", 2);
- ma.sex = RFIFOB (fd, 50);
- WFIFOW (fd, 0) = 0x7931;
- WFIFOL (fd, 2) = -1;
- memcpy (WFIFOP (fd, 6), RFIFOP (fd, 2), 24);
- if (strlen (ma.userid) > 23 || strlen (ma.passwd) > 23)
- {
- login_log
- ("'ladmin': Attempt to create an invalid account (account or pass is too long, ip: %s)\n",
- ip);
- }
- else if (strlen (ma.userid) < 4 || strlen (ma.passwd) < 4)
+ strzcpy(ma.userid, static_cast<const char *>(RFIFOP(fd, 2)), 24);
+ strzcpy(ma.passwd, static_cast<const char *>(RFIFOP(fd, 26)), 24);
+ memcpy(ma.lastlogin, "-", 2);
+ ma.sex = RFIFOB(fd, 50);
+ WFIFOW(fd, 0) = 0x7931;
+ WFIFOL(fd, 2) = -1;
+ memcpy(WFIFOP(fd, 6), ma.userid, 24);
+ if (strlen(ma.userid) < 4 || strlen(ma.passwd) < 4)
{
- login_log
- ("'ladmin': Attempt to create an invalid account (account or pass is too short, ip: %s)\n",
+ LOGIN_LOG("'ladmin': Attempt to create an invalid account (account or pass is too short, ip: %s)\n",
ip);
}
else if (ma.sex != 'F' && ma.sex != 'M')
{
- login_log
- ("'ladmin': Attempt to create an invalid account (account: %s, invalid sex, ip: %s)\n",
+ LOGIN_LOG("'ladmin': Attempt to create an invalid account (account: %s, invalid sex, ip: %s)\n",
ma.userid, ip);
}
else if (account_id_count > END_ACCOUNT_NUM)
{
- login_log
- ("'ladmin': Attempt to create an account, but there is no more available id number (account: %s, sex: %c, ip: %s)\n",
+ LOGIN_LOG("'ladmin': Attempt to create an account, but there is no more available id number (account: %s, sex: %c, ip: %s)\n",
ma.userid, ma.sex, ip);
}
else
{
- remove_control_chars (ma.userid);
- remove_control_chars (ma.passwd);
+ remove_control_chars(ma.userid);
+ remove_control_chars(ma.passwd);
for (i = 0; i < auth_num; i++)
{
- if (strncmp (auth_dat[i].userid, ma.userid, 24) ==
+ if (strncmp(auth_dat[i].userid, ma.userid, 24) ==
0)
{
- login_log
- ("'ladmin': Attempt to create an already existing account (account: %s ip: %s)\n",
+ LOGIN_LOG("'ladmin': Attempt to create an already existing account (account: %s ip: %s)\n",
auth_dat[i].userid, ip);
break;
}
}
if (i == auth_num)
{
- int new_id;
+ int new_id;
char email[40];
- memcpy (email, RFIFOP (fd, 51), 40);
- email[39] = '\0';
- remove_control_chars (email);
- new_id = mmo_auth_new (&ma, ma.sex, email);
- login_log
- ("'ladmin': Account creation (account: %s (id: %d), sex: %c, email: %s, ip: %s)\n",
+ strzcpy(email, static_cast<const char *>(RFIFOP(fd, 51)), 40);
+ remove_control_chars(email);
+ new_id = mmo_auth_new(&ma, ma.sex, email);
+ LOGIN_LOG("'ladmin': Account creation (account: %s (id: %d), sex: %c, email: %s, ip: %s)\n",
ma.userid, new_id,
ma.sex, auth_dat[i].email, ip);
- WFIFOL (fd, 2) = new_id;
+ WFIFOL(fd, 2) = new_id;
}
}
- WFIFOSET (fd, 30);
- RFIFOSKIP (fd, 91);
+ WFIFOSET(fd, 30);
+ RFIFOSKIP(fd, 91);
}
break;
case 0x7932: // Request for an account deletion
- if (RFIFOREST (fd) < 26)
+ if (RFIFOREST(fd) < 26)
return;
- WFIFOW (fd, 0) = 0x7933;
- WFIFOL (fd, 2) = -1;
- account_name = (char *)RFIFOP (fd, 2);
- account_name[23] = '\0';
- remove_control_chars (account_name);
- i = search_account_index (account_name);
+ WFIFOW(fd, 0) = 0x7933;
+ WFIFOL(fd, 2) = -1;
+ strzcpy(account_name, static_cast<const char *>(RFIFOP(fd, 2)), 24);
+ remove_control_chars(account_name);
+ i = search_account_index(account_name);
if (i != -1)
{
{
// Char-server is notified of deletion (for characters deletion).
- unsigned char buf[65535];
- WBUFW (buf, 0) = 0x2730;
- WBUFL (buf, 2) = auth_dat[i].account_id;
- charif_sendallwos (-1, buf, 6);
+ uint8_t buf[6];
+ WBUFW(buf, 0) = 0x2730;
+ WBUFL(buf, 2) = auth_dat[i].account_id;
+ charif_sendallwos(-1, buf, 6);
// send answer
- memcpy (WFIFOP (fd, 6), auth_dat[i].userid, 24);
- WFIFOL (fd, 2) = auth_dat[i].account_id;
+ memcpy(WFIFOP(fd, 6), auth_dat[i].userid, 24);
+ WFIFOL(fd, 2) = auth_dat[i].account_id;
// save deleted account in log file
- login_log
- ("'ladmin': Account deletion (account: %s, id: %d, ip: %s) - saved in next line:\n",
+ LOGIN_LOG("'ladmin': Account deletion (account: %s, id: %d, ip: %s) - saved in next line:\n",
auth_dat[i].userid, auth_dat[i].account_id,
ip);
}
{
- char buf[65535];
- mmo_auth_tostr (buf, &auth_dat[i]);
- login_log ("%s\n", buf);
+ std::string buf = mmo_auth_tostr(&auth_dat[i]);
+ LOGIN_LOG("%s\n", buf);
}
// delete account
- memset (auth_dat[i].userid, '\0',
- sizeof (auth_dat[i].userid));
+ memset(auth_dat[i].userid, '\0',
+ sizeof(auth_dat[i].userid));
auth_dat[i].account_id = -1;
}
else
{
- memcpy (WFIFOP (fd, 6), account_name, 24);
- login_log
- ("'ladmin': Attempt to delete an unknown account (account: %s, ip: %s)\n",
+ memcpy(WFIFOP(fd, 6), account_name, 24);
+ LOGIN_LOG("'ladmin': Attempt to delete an unknown account (account: %s, ip: %s)\n",
account_name, ip);
}
- WFIFOSET (fd, 30);
- RFIFOSKIP (fd, 26);
+ WFIFOSET(fd, 30);
+ RFIFOSKIP(fd, 26);
break;
case 0x7934: // Request to change a password
- if (RFIFOREST (fd) < 50)
+ if (RFIFOREST(fd) < 50)
return;
- WFIFOW (fd, 0) = 0x7935;
- WFIFOL (fd, 2) = -1;
- account_name = (char *)RFIFOP (fd, 2);
- account_name[23] = '\0';
- remove_control_chars (account_name);
- i = search_account_index (account_name);
+ WFIFOW(fd, 0) = 0x7935;
+ WFIFOL(fd, 2) = -1;
+ strzcpy(account_name, static_cast<const char *>(RFIFOP(fd, 2)), 24);
+ remove_control_chars(account_name);
+ i = search_account_index(account_name);
if (i != -1)
{
- memcpy (WFIFOP (fd, 6), auth_dat[i].userid, 24);
- strcpy (auth_dat[i].pass, MD5_saltcrypt((char *)RFIFOP (fd, 26), make_salt()));
- auth_dat[i].pass[39] = '\0';
- WFIFOL (fd, 2) = auth_dat[i].account_id;
- login_log
- ("'ladmin': Modification of a password (account: %s, new password: %s, ip: %s)\n",
+ memcpy(WFIFOP(fd, 6), auth_dat[i].userid, 24);
+ strzcpy(auth_dat[i].pass, MD5_saltcrypt(static_cast<const char *>(RFIFOP(fd, 26)), make_salt()), 40);
+ WFIFOL(fd, 2) = auth_dat[i].account_id;
+ LOGIN_LOG("'ladmin': Modification of a password (account: %s, new password: %s, ip: %s)\n",
auth_dat[i].userid, auth_dat[i].pass, ip);
}
else
{
- memcpy (WFIFOP (fd, 6), account_name, 24);
- login_log
- ("'ladmin': Attempt to modify the password of an unknown account (account: %s, ip: %s)\n",
+ memcpy(WFIFOP(fd, 6), account_name, 24);
+ LOGIN_LOG("'ladmin': Attempt to modify the password of an unknown account (account: %s, ip: %s)\n",
account_name, ip);
}
- WFIFOSET (fd, 30);
- RFIFOSKIP (fd, 50);
+ WFIFOSET(fd, 30);
+ RFIFOSKIP(fd, 50);
break;
case 0x7936: // Request to modify a state
- if (RFIFOREST (fd) < 50)
+ if (RFIFOREST(fd) < 50)
return;
{
char error_message[20];
- int statut;
- WFIFOW (fd, 0) = 0x7937;
- WFIFOL (fd, 2) = -1;
- account_name = (char *)RFIFOP (fd, 2);
- account_name[23] = '\0';
- remove_control_chars (account_name);
- statut = RFIFOL (fd, 26);
- memcpy (error_message, RFIFOP (fd, 30), 20);
- error_message[19] = '\0';
- remove_control_chars (error_message);
+ int statut;
+ WFIFOW(fd, 0) = 0x7937;
+ WFIFOL(fd, 2) = -1;
+ strzcpy(account_name, static_cast<const char *>(RFIFOP(fd, 2)), 24);
+ remove_control_chars(account_name);
+ statut = RFIFOL(fd, 26);
+ strzcpy(error_message, static_cast<const char *>(RFIFOP(fd, 30)), 20);
+ remove_control_chars(error_message);
if (statut != 7 || error_message[0] == '\0')
{ // 7: // 6 = Your are Prohibited to log in until %s
- strcpy (error_message, "-");
+ strcpy(error_message, "-");
}
- i = search_account_index (account_name);
+ i = search_account_index(account_name);
if (i != -1)
{
- memcpy (WFIFOP (fd, 6), auth_dat[i].userid, 24);
- WFIFOL (fd, 2) = auth_dat[i].account_id;
+ memcpy(WFIFOP(fd, 6), auth_dat[i].userid, 24);
+ WFIFOL(fd, 2) = auth_dat[i].account_id;
if (auth_dat[i].state == statut
- && strcmp (auth_dat[i].error_message,
+ && strcmp(auth_dat[i].error_message,
error_message) == 0)
- login_log
- ("'ladmin': Modification of a state, but the state of the account is already the good state (account: %s, received state: %d, ip: %s)\n",
+ LOGIN_LOG("'ladmin': Modification of a state, but the state of the account is already the good state (account: %s, received state: %d, ip: %s)\n",
account_name, statut, ip);
else
{
if (statut == 7)
- login_log
- ("'ladmin': Modification of a state (account: %s, new state: %d - prohibited to login until '%s', ip: %s)\n",
+ LOGIN_LOG("'ladmin': Modification of a state (account: %s, new state: %d - prohibited to login until '%s', ip: %s)\n",
auth_dat[i].userid, statut,
error_message, ip);
else
- login_log
- ("'ladmin': Modification of a state (account: %s, new state: %d, ip: %s)\n",
+ LOGIN_LOG("'ladmin': Modification of a state (account: %s, new state: %d, ip: %s)\n",
auth_dat[i].userid, statut, ip);
if (auth_dat[i].state == 0)
{
unsigned char buf[16];
- WBUFW (buf, 0) = 0x2731;
- WBUFL (buf, 2) = auth_dat[i].account_id;
- 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);
+ WBUFW(buf, 0) = 0x2731;
+ WBUFL(buf, 2) = auth_dat[i].account_id;
+ 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);
for (j = 0; j < AUTH_FIFO_SIZE; j++)
if (auth_fifo[j].account_id ==
auth_dat[i].account_id)
auth_fifo[j].login_id1++; // to avoid reconnection error when come back from map-server (char-server will ask again the authentification)
}
auth_dat[i].state = statut;
- memcpy (auth_dat[i].error_message, error_message,
+ memcpy(auth_dat[i].error_message, error_message,
20);
}
}
else
{
- memcpy (WFIFOP (fd, 6), account_name, 24);
- login_log
- ("'ladmin': Attempt to modify the state of an unknown account (account: %s, received state: %d, ip: %s)\n",
+ memcpy(WFIFOP(fd, 6), account_name, 24);
+ LOGIN_LOG("'ladmin': Attempt to modify the state of an unknown account (account: %s, received state: %d, ip: %s)\n",
account_name, statut, ip);
}
- WFIFOL (fd, 30) = statut;
+ WFIFOL(fd, 30) = statut;
}
- WFIFOSET (fd, 34);
- RFIFOSKIP (fd, 50);
+ WFIFOSET(fd, 34);
+ RFIFOSKIP(fd, 50);
break;
case 0x7938: // Request for servers list and # of online players
- login_log ("'ladmin': Sending of servers list (ip: %s)\n", ip);
+ LOGIN_LOG("'ladmin': Sending of servers list (ip: %s)\n", ip);
server_num = 0;
for (i = 0; i < MAX_SERVERS; i++)
{
if (server_fd[i] >= 0)
{
- WFIFOL (fd, 4 + server_num * 32) = server[i].ip;
- WFIFOW (fd, 4 + server_num * 32 + 4) = server[i].port;
- memcpy (WFIFOP (fd, 4 + server_num * 32 + 6),
+ WFIFOL(fd, 4 + server_num * 32) = server[i].ip;
+ WFIFOW(fd, 4 + server_num * 32 + 4) = server[i].port;
+ memcpy(WFIFOP(fd, 4 + server_num * 32 + 6),
server[i].name, 20);
- WFIFOW (fd, 4 + server_num * 32 + 26) =
+ WFIFOW(fd, 4 + server_num * 32 + 26) =
server[i].users;
- WFIFOW (fd, 4 + server_num * 32 + 28) =
+ WFIFOW(fd, 4 + server_num * 32 + 28) =
server[i].maintenance;
- WFIFOW (fd, 4 + server_num * 32 + 30) = server[i].is_new;
+ WFIFOW(fd, 4 + server_num * 32 + 30) = server[i].is_new;
server_num++;
}
}
- WFIFOW (fd, 0) = 0x7939;
- WFIFOW (fd, 2) = 4 + 32 * server_num;
- WFIFOSET (fd, 4 + 32 * server_num);
- RFIFOSKIP (fd, 2);
+ WFIFOW(fd, 0) = 0x7939;
+ WFIFOW(fd, 2) = 4 + 32 * server_num;
+ WFIFOSET(fd, 4 + 32 * server_num);
+ RFIFOSKIP(fd, 2);
break;
case 0x793a: // Request to password check
- if (RFIFOREST (fd) < 50)
+ if (RFIFOREST(fd) < 50)
return;
- WFIFOW (fd, 0) = 0x793b;
- WFIFOL (fd, 2) = -1;
- account_name = (char *)RFIFOP (fd, 2);
- account_name[23] = '\0';
- remove_control_chars (account_name);
- i = search_account_index (account_name);
+ WFIFOW(fd, 0) = 0x793b;
+ WFIFOL(fd, 2) = -1;
+ strzcpy(account_name, static_cast<const char *>(RFIFOP(fd, 2)), 24);
+ remove_control_chars(account_name);
+ i = search_account_index(account_name);
if (i != -1)
{
- memcpy (WFIFOP (fd, 6), auth_dat[i].userid, 24);
- if ( pass_ok((char *)RFIFOP (fd, 26), auth_dat[i].pass) )
+ memcpy(WFIFOP(fd, 6), auth_dat[i].userid, 24);
+ char pass[24];
+ strzcpy(pass, static_cast<const char *>(RFIFOP(fd, 26)), 24);
+ if (pass_ok(pass, auth_dat[i].pass))
{
- WFIFOL (fd, 2) = auth_dat[i].account_id;
- login_log
- ("'ladmin': Check of password OK (account: %s, password: %s, ip: %s)\n",
+ WFIFOL(fd, 2) = auth_dat[i].account_id;
+ LOGIN_LOG("'ladmin': Check of password OK (account: %s, password: %s, ip: %s)\n",
auth_dat[i].userid, auth_dat[i].pass,
ip);
}
else
{
- char pass[24];
- memcpy (pass, RFIFOP (fd, 26), 24);
- pass[23] = '\0';
- remove_control_chars (pass);
- login_log
- ("'ladmin': Failure of password check (account: %s, proposed pass: %s, ip: %s)\n",
+ remove_control_chars(pass);
+ LOGIN_LOG("'ladmin': Failure of password check (account: %s, proposed pass: %s, ip: %s)\n",
auth_dat[i].userid, pass, ip);
}
}
else
{
- memcpy (WFIFOP (fd, 6), account_name, 24);
- login_log
- ("'ladmin': Attempt to check the password of an unknown account (account: %s, ip: %s)\n",
+ memcpy(WFIFOP(fd, 6), account_name, 24);
+ LOGIN_LOG("'ladmin': Attempt to check the password of an unknown account (account: %s, ip: %s)\n",
account_name, ip);
}
- WFIFOSET (fd, 30);
- RFIFOSKIP (fd, 50);
+ WFIFOSET(fd, 30);
+ RFIFOSKIP(fd, 50);
break;
case 0x793c: // Request to modify sex
- if (RFIFOREST (fd) < 27)
+ if (RFIFOREST(fd) < 27)
return;
- WFIFOW (fd, 0) = 0x793d;
- WFIFOL (fd, 2) = -1;
- account_name = (char *)RFIFOP (fd, 2);
- account_name[23] = '\0';
- remove_control_chars (account_name);
- memcpy (WFIFOP (fd, 6), account_name, 24);
+ WFIFOW(fd, 0) = 0x793d;
+ WFIFOL(fd, 2) = -1;
+ strzcpy(account_name, static_cast<const char *>(RFIFOP(fd, 2)), 24);
+ remove_control_chars(account_name);
+ memcpy(WFIFOP(fd, 6), account_name, 24);
{
char sex;
- sex = RFIFOB (fd, 26);
+ sex = RFIFOB(fd, 26);
if (sex != 'F' && sex != 'M')
{
if (sex > 31)
- login_log
- ("'ladmin': Attempt to give an invalid sex (account: %s, received sex: %c, ip: %s)\n",
+ LOGIN_LOG("'ladmin': Attempt to give an invalid sex (account: %s, received sex: %c, ip: %s)\n",
account_name, sex, ip);
else
- login_log
- ("'ladmin': Attempt to give an invalid sex (account: %s, received sex: 'control char', ip: %s)\n",
+ LOGIN_LOG("'ladmin': Attempt to give an invalid sex (account: %s, received sex: 'control char', ip: %s)\n",
account_name, ip);
}
else
{
- i = search_account_index (account_name);
+ i = search_account_index(account_name);
if (i != -1)
{
- memcpy (WFIFOP (fd, 6), auth_dat[i].userid, 24);
+ memcpy(WFIFOP(fd, 6), auth_dat[i].userid, 24);
if (auth_dat[i].sex !=
((sex == 'S' || sex == 's') ? 2 : (sex == 'M'
|| sex ==
'm')))
{
unsigned char buf[16];
- WFIFOL (fd, 2) = auth_dat[i].account_id;
+ WFIFOL(fd, 2) = auth_dat[i].account_id;
for (j = 0; j < AUTH_FIFO_SIZE; j++)
if (auth_fifo[j].account_id ==
auth_dat[i].account_id)
@@ -2608,134 +2182,122 @@ void parse_admin (int fd)
|| sex ==
's') ? 2 : (sex == 'M'
|| sex == 'm');
- login_log
- ("'ladmin': Modification of a sex (account: %s, new sex: %c, ip: %s)\n",
+ LOGIN_LOG("'ladmin': Modification of a sex (account: %s, new sex: %c, ip: %s)\n",
auth_dat[i].userid, sex, ip);
// send to all char-server the change
- WBUFW (buf, 0) = 0x2723;
- WBUFL (buf, 2) = auth_dat[i].account_id;
- WBUFB (buf, 6) = auth_dat[i].sex;
- charif_sendallwos (-1, buf, 7);
+ WBUFW(buf, 0) = 0x2723;
+ WBUFL(buf, 2) = auth_dat[i].account_id;
+ WBUFB(buf, 6) = auth_dat[i].sex;
+ charif_sendallwos(-1, buf, 7);
}
else
{
- login_log
- ("'ladmin': Modification of a sex, but the sex is already the good sex (account: %s, sex: %c, ip: %s)\n",
+ LOGIN_LOG("'ladmin': Modification of a sex, but the sex is already the good sex (account: %s, sex: %c, ip: %s)\n",
auth_dat[i].userid, sex, ip);
}
}
else
{
- login_log
- ("'ladmin': Attempt to modify the sex of an unknown account (account: %s, received sex: %c, ip: %s)\n",
+ LOGIN_LOG("'ladmin': Attempt to modify the sex of an unknown account (account: %s, received sex: %c, ip: %s)\n",
account_name, sex, ip);
}
}
}
- WFIFOSET (fd, 30);
- RFIFOSKIP (fd, 27);
+ WFIFOSET(fd, 30);
+ RFIFOSKIP(fd, 27);
break;
case 0x793e: // Request to modify GM level
- if (RFIFOREST (fd) < 27)
+ if (RFIFOREST(fd) < 27)
return;
- WFIFOW (fd, 0) = 0x793f;
- WFIFOL (fd, 2) = -1;
- account_name = (char *)RFIFOP (fd, 2);
- account_name[23] = '\0';
- remove_control_chars (account_name);
- memcpy (WFIFOP (fd, 6), account_name, 24);
+ WFIFOW(fd, 0) = 0x793f;
+ WFIFOL(fd, 2) = -1;
+ strzcpy(account_name, static_cast<const char *>(RFIFOP(fd, 2)), 24);
+ remove_control_chars(account_name);
+ memcpy(WFIFOP(fd, 6), account_name, 24);
{
char new_gm_level;
- new_gm_level = RFIFOB (fd, 26);
+ new_gm_level = RFIFOB(fd, 26);
if (new_gm_level < 0 || new_gm_level > 99)
{
- login_log
- ("'ladmin': Attempt to give an invalid GM level (account: %s, received GM level: %d, ip: %s)\n",
+ LOGIN_LOG("'ladmin': Attempt to give an invalid GM level (account: %s, received GM level: %d, ip: %s)\n",
account_name, (int) new_gm_level, ip);
}
else
{
- i = search_account_index (account_name);
+ i = search_account_index(account_name);
if (i != -1)
{
- int acc = auth_dat[i].account_id;
- memcpy (WFIFOP (fd, 6), auth_dat[i].userid, 24);
- if (isGM (acc) != new_gm_level)
+ int acc = auth_dat[i].account_id;
+ memcpy(WFIFOP(fd, 6), auth_dat[i].userid, 24);
+ if (isGM(acc) != new_gm_level)
{
// modification of the file
FILE *fp, *fp2;
- int lock;
+ int lock;
char line[512];
- int GM_account, GM_level;
- int modify_flag;
- char tmpstr[24];
- struct timeval tv;
+ int GM_account, GM_level;
+ int modify_flag;
if ((fp2 =
- lock_fopen (GM_account_filename,
+ lock_fopen(GM_account_filename,
&lock)) != NULL)
{
if ((fp =
- fopen_ (GM_account_filename,
+ fopen_(GM_account_filename,
"r")) != NULL)
{
- gettimeofday (&tv, NULL);
- strftime (tmpstr, 23, date_format,
- gmtime (&(tv.tv_sec)));
+ timestamp_seconds_buffer tmpstr;
+ stamp_time(tmpstr);
modify_flag = 0;
// read/write GM file
- while (fgets
- (line, sizeof (line) - 1, fp))
+ while (fgets(line, sizeof(line) - 1, fp))
{
while (line[0] != '\0'
- && (line[strlen (line) - 1]
+ && (line[strlen(line) - 1]
== '\n'
- || line[strlen (line) -
+ || line[strlen(line) -
1] == '\r'))
- line[strlen (line) - 1] =
+ line[strlen(line) - 1] =
'\0';
if ((line[0] == '/'
&& line[1] == '/')
|| line[0] == '\0')
- fprintf (fp2, "%s\n",
+ FPRINTF(fp2, "%s\n",
line);
else
{
- if (sscanf
- (line, "%d %d",
+ if (sscanf(line, "%d %d",
&GM_account,
&GM_level) != 2
- && sscanf (line, "%d: %d",
+ && sscanf(line, "%d: %d",
&GM_account,
&GM_level) !=
2)
- fprintf (fp2,
+ FPRINTF(fp2,
"%s\n",
line);
else if (GM_account != acc)
- fprintf (fp2,
+ FPRINTF(fp2,
"%s\n",
line);
else if (new_gm_level < 1)
{
- fprintf (fp2,
+ FPRINTF(fp2,
"// %s: 'ladmin' GM level removed on account %d '%s' (previous level: %d)\n//%d %d\n",
tmpstr,
acc,
- auth_dat
- [i].userid,
+ auth_dat[i].userid,
GM_level, acc,
new_gm_level);
modify_flag = 1;
}
else
{
- fprintf (fp2,
+ FPRINTF(fp2,
"// %s: 'ladmin' GM level on account %d '%s' (previous level: %d)\n%d %d\n",
tmpstr,
acc,
- auth_dat
- [i].userid,
+ auth_dat[i].userid,
GM_level, acc,
new_gm_level);
modify_flag = 1;
@@ -2743,277 +2305,261 @@ void parse_admin (int fd)
}
}
if (modify_flag == 0)
- fprintf (fp2,
+ FPRINTF(fp2,
"// %s: 'ladmin' GM level on account %d '%s' (previous level: 0)\n%d %d\n",
tmpstr, acc,
auth_dat[i].userid, acc,
new_gm_level);
- fclose_ (fp);
+ fclose_(fp);
}
else
{
- login_log
- ("'ladmin': Attempt to modify of a GM level - impossible to read GM accounts file (account: %s (%d), received GM level: %d, ip: %s)\n",
+ LOGIN_LOG("'ladmin': Attempt to modify of a GM level - impossible to read GM accounts file (account: %s (%d), received GM level: %d, ip: %s)\n",
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)\n",
+ WFIFOL(fd, 2) = acc;
+ LOGIN_LOG("'ladmin': Modification of a GM level (account: %s (%d), new GM level: %d, ip: %s)\n",
auth_dat[i].userid, acc,
(int) new_gm_level, ip);
// read and send new GM informations
- read_gm_account ();
- send_GM_accounts ();
+ 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)\n",
+ 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)\n",
auth_dat[i].userid, acc,
(int) new_gm_level, ip);
}
}
else
{
- login_log
- ("'ladmin': Attempt to modify of a GM level, but the GM level is already the good GM level (account: %s (%d), GM level: %d, ip: %s)\n",
+ LOGIN_LOG("'ladmin': Attempt to modify of a GM level, but the GM level is already the good GM level (account: %s (%d), GM level: %d, ip: %s)\n",
auth_dat[i].userid, acc,
(int) new_gm_level, ip);
}
}
else
{
- login_log
- ("'ladmin': Attempt to modify the GM level of an unknown account (account: %s, received GM level: %d, ip: %s)\n",
+ LOGIN_LOG("'ladmin': Attempt to modify the GM level of an unknown account (account: %s, received GM level: %d, ip: %s)\n",
account_name, (int) new_gm_level,
ip);
}
}
}
- WFIFOSET (fd, 30);
- RFIFOSKIP (fd, 27);
+ WFIFOSET(fd, 30);
+ RFIFOSKIP(fd, 27);
break;
case 0x7940: // Request to modify e-mail
- if (RFIFOREST (fd) < 66)
+ if (RFIFOREST(fd) < 66)
return;
- WFIFOW (fd, 0) = 0x7941;
- WFIFOL (fd, 2) = -1;
- account_name = (char *)RFIFOP (fd, 2);
- account_name[23] = '\0';
- remove_control_chars (account_name);
- memcpy (WFIFOP (fd, 6), account_name, 24);
+ WFIFOW(fd, 0) = 0x7941;
+ WFIFOL(fd, 2) = -1;
+ strzcpy(account_name, static_cast<const char *>(RFIFOP(fd, 2)), 24);
+ remove_control_chars(account_name);
+ memcpy(WFIFOP(fd, 6), account_name, 24);
{
char email[40];
- memcpy (email, RFIFOP (fd, 26), 40);
- if (e_mail_check (email) == 0)
+ strzcpy(email, static_cast<const char *>(RFIFOP(fd, 26)), 40);
+ if (e_mail_check(email) == 0)
{
- login_log
- ("'ladmin': Attempt to give an invalid e-mail (account: %s, ip: %s)\n",
+ LOGIN_LOG("'ladmin': Attempt to give an invalid e-mail (account: %s, ip: %s)\n",
account_name, ip);
}
else
{
- remove_control_chars (email);
- i = search_account_index (account_name);
+ remove_control_chars(email);
+ i = search_account_index(account_name);
if (i != -1)
{
- memcpy (WFIFOP (fd, 6), auth_dat[i].userid, 24);
- memcpy (auth_dat[i].email, email, 40);
- WFIFOL (fd, 2) = auth_dat[i].account_id;
- login_log
- ("'ladmin': Modification of an email (account: %s, new e-mail: %s, ip: %s)\n",
+ memcpy(WFIFOP(fd, 6), auth_dat[i].userid, 24);
+ memcpy(auth_dat[i].email, email, 40);
+ WFIFOL(fd, 2) = auth_dat[i].account_id;
+ LOGIN_LOG("'ladmin': Modification of an email (account: %s, new e-mail: %s, ip: %s)\n",
auth_dat[i].userid, email, ip);
}
else
{
- login_log
- ("'ladmin': Attempt to modify the e-mail of an unknown account (account: %s, received e-mail: %s, ip: %s)\n",
+ LOGIN_LOG("'ladmin': Attempt to modify the e-mail of an unknown account (account: %s, received e-mail: %s, ip: %s)\n",
account_name, email, ip);
}
}
}
- WFIFOSET (fd, 30);
- RFIFOSKIP (fd, 66);
+ WFIFOSET(fd, 30);
+ RFIFOSKIP(fd, 66);
break;
case 0x7942: // Request to modify memo field
- if (RFIFOREST (fd) < 28
- || RFIFOREST (fd) < (28 + RFIFOW (fd, 26)))
+ if (RFIFOREST(fd) < 28
+ || RFIFOREST(fd) < (28 + RFIFOW(fd, 26)))
return;
- WFIFOW (fd, 0) = 0x7943;
- WFIFOL (fd, 2) = -1;
- account_name = (char *)RFIFOP (fd, 2);
- account_name[23] = '\0';
- remove_control_chars (account_name);
- i = search_account_index (account_name);
+ WFIFOW(fd, 0) = 0x7943;
+ WFIFOL(fd, 2) = -1;
+ strzcpy(account_name, static_cast<const char *>(RFIFOP(fd, 2)), 24);
+ remove_control_chars(account_name);
+ i = search_account_index(account_name);
if (i != -1)
{
- int size_of_memo = sizeof (auth_dat[i].memo);
- memcpy (WFIFOP (fd, 6), auth_dat[i].userid, 24);
- memset (auth_dat[i].memo, '\0', size_of_memo);
- if (RFIFOW (fd, 26) == 0)
+ int size_of_memo = sizeof(auth_dat[i].memo);
+ memcpy(WFIFOP(fd, 6), auth_dat[i].userid, 24);
+ memset(auth_dat[i].memo, '\0', size_of_memo);
+ if (RFIFOW(fd, 26) == 0)
{
- strncpy (auth_dat[i].memo, "!", size_of_memo);
+ strncpy(auth_dat[i].memo, "!", size_of_memo);
}
- else if (RFIFOW (fd, 26) > size_of_memo - 1)
+ else if (RFIFOW(fd, 26) > size_of_memo - 1)
{
- memcpy (auth_dat[i].memo, RFIFOP (fd, 28),
+ memcpy(auth_dat[i].memo, RFIFOP(fd, 28),
size_of_memo - 1);
}
else
{
- memcpy (auth_dat[i].memo, RFIFOP (fd, 28),
- RFIFOW (fd, 26));
+ memcpy(auth_dat[i].memo, RFIFOP(fd, 28),
+ RFIFOW(fd, 26));
}
auth_dat[i].memo[size_of_memo - 1] = '\0';
- remove_control_chars (auth_dat[i].memo);
- WFIFOL (fd, 2) = auth_dat[i].account_id;
- login_log
- ("'ladmin': Modification of a memo field (account: %s, new memo: %s, ip: %s)\n",
+ remove_control_chars(auth_dat[i].memo);
+ WFIFOL(fd, 2) = auth_dat[i].account_id;
+ LOGIN_LOG("'ladmin': Modification of a memo field (account: %s, new memo: %s, ip: %s)\n",
auth_dat[i].userid, auth_dat[i].memo, ip);
}
else
{
- memcpy (WFIFOP (fd, 6), account_name, 24);
- login_log
- ("'ladmin': Attempt to modify the memo field of an unknown account (account: %s, ip: %s)\n",
+ memcpy(WFIFOP(fd, 6), account_name, 24);
+ LOGIN_LOG("'ladmin': Attempt to modify the memo field of an unknown account (account: %s, ip: %s)\n",
account_name, ip);
}
- WFIFOSET (fd, 30);
- RFIFOSKIP (fd, 28 + RFIFOW (fd, 26));
+ WFIFOSET(fd, 30);
+ RFIFOSKIP(fd, 28 + RFIFOW(fd, 26));
break;
case 0x7944: // Request to found an account id
- if (RFIFOREST (fd) < 26)
+ if (RFIFOREST(fd) < 26)
return;
- WFIFOW (fd, 0) = 0x7945;
- WFIFOL (fd, 2) = -1;
- account_name = (char *)RFIFOP (fd, 2);
- account_name[23] = '\0';
- remove_control_chars (account_name);
- i = search_account_index (account_name);
+ WFIFOW(fd, 0) = 0x7945;
+ WFIFOL(fd, 2) = -1;
+ strzcpy(account_name, static_cast<const char *>(RFIFOP(fd, 2)), 24);
+ remove_control_chars(account_name);
+ i = search_account_index(account_name);
if (i != -1)
{
- memcpy (WFIFOP (fd, 6), auth_dat[i].userid, 24);
- WFIFOL (fd, 2) = auth_dat[i].account_id;
- login_log
- ("'ladmin': Request (by the name) of an account id (account: %s, id: %d, ip: %s)\n",
- auth_dat[i].userid, auth_dat[i].account_id,
- ip);
+ memcpy(WFIFOP(fd, 6), auth_dat[i].userid, 24);
+ WFIFOL(fd, 2) = auth_dat[i].account_id;
+ LOGIN_LOG("'ladmin': Request (by the name) of an account id (account: %s, id: %d, ip: %s)\n",
+ auth_dat[i].userid, auth_dat[i].account_id,
+ ip);
}
else
{
- memcpy (WFIFOP (fd, 6), account_name, 24);
- login_log
- ("'ladmin': ID request (by the name) of an unknown account (account: %s, ip: %s)\n",
- account_name, ip);
+ memcpy(WFIFOP(fd, 6), account_name, 24);
+ LOGIN_LOG("'ladmin': ID request (by the name) of an unknown account (account: %s, ip: %s)\n",
+ account_name, ip);
}
- WFIFOSET (fd, 30);
- RFIFOSKIP (fd, 26);
+ WFIFOSET(fd, 30);
+ RFIFOSKIP(fd, 26);
break;
case 0x7946: // Request to found an account name
- if (RFIFOREST (fd) < 6)
+ if (RFIFOREST(fd) < 6)
return;
- WFIFOW (fd, 0) = 0x7947;
- WFIFOL (fd, 2) = RFIFOL (fd, 2);
- memset (WFIFOP (fd, 6), '\0', 24);
+ WFIFOW(fd, 0) = 0x7947;
+ WFIFOL(fd, 2) = RFIFOL(fd, 2);
+ memset(WFIFOP(fd, 6), '\0', 24);
for (i = 0; i < auth_num; i++)
{
- if (auth_dat[i].account_id == RFIFOL (fd, 2))
+ if (auth_dat[i].account_id == RFIFOL(fd, 2))
{
- strncpy ((char *)WFIFOP (fd, 6), auth_dat[i].userid, 24);
- login_log
- ("'ladmin': Request (by id) of an account name (account: %s, id: %d, ip: %s)\n",
- auth_dat[i].userid, RFIFOL (fd, 2), ip);
+ strncpy((char *)WFIFOP(fd, 6), auth_dat[i].userid, 24);
+ LOGIN_LOG("'ladmin': Request (by id) of an account name (account: %s, id: %d, ip: %s)\n",
+ auth_dat[i].userid, RFIFOL(fd, 2), ip);
break;
}
}
if (i == auth_num)
{
- login_log
- ("'ladmin': Name request (by id) of an unknown account (id: %d, ip: %s)\n",
- RFIFOL (fd, 2), ip);
- strncpy ((char *)WFIFOP (fd, 6), "", 24);
+ LOGIN_LOG("'ladmin': Name request (by id) of an unknown account (id: %d, ip: %s)\n",
+ RFIFOL(fd, 2), ip);
+ strncpy((char *)WFIFOP(fd, 6), "", 24);
}
- WFIFOSET (fd, 30);
- RFIFOSKIP (fd, 6);
+ WFIFOSET(fd, 30);
+ RFIFOSKIP(fd, 6);
break;
case 0x7948: // Request to change the validity limit (timestamp) (absolute value)
- if (RFIFOREST (fd) < 30)
+ if (RFIFOREST(fd) < 30)
return;
{
- time_t timestamp;
- char tmpstr[2048];
- WFIFOW (fd, 0) = 0x7949;
- WFIFOL (fd, 2) = -1;
- account_name = (char *)RFIFOP (fd, 2);
- account_name[23] = '\0';
- remove_control_chars (account_name);
- timestamp = (time_t) RFIFOL (fd, 26);
- strftime (tmpstr, 24, date_format, gmtime (&timestamp));
- i = search_account_index (account_name);
+ WFIFOW(fd, 0) = 0x7949;
+ WFIFOL(fd, 2) = -1;
+ strzcpy(account_name, static_cast<const char *>(RFIFOP(fd, 2)), 24);
+ remove_control_chars(account_name);
+ TimeT timestamp = static_cast<time_t>(RFIFOL(fd, 26));
+ timestamp_seconds_buffer tmpstr = "unlimited";
+ if (timestamp)
+ stamp_time(tmpstr, &timestamp);
+ i = search_account_index(account_name);
if (i != -1)
{
- memcpy (WFIFOP (fd, 6), auth_dat[i].userid, 24);
- login_log
- ("'ladmin': Change of a validity limit (account: %s, new validity: %ld (%s), ip: %s)\n",
- auth_dat[i].userid, timestamp,
- (timestamp == 0 ? "unlimited" : tmpstr), ip);
+ memcpy(WFIFOP(fd, 6), auth_dat[i].userid, 24);
+ LOGIN_LOG("'ladmin': Change of a validity limit (account: %s, new validity: %lld (%s), ip: %s)\n",
+ auth_dat[i].userid,
+ timestamp,
+ tmpstr,
+ ip);
auth_dat[i].connect_until_time = timestamp;
- WFIFOL (fd, 2) = auth_dat[i].account_id;
+ WFIFOL(fd, 2) = auth_dat[i].account_id;
}
else
{
- memcpy (WFIFOP (fd, 6), account_name, 24);
- login_log
- ("'ladmin': Attempt to change the validity limit of an unknown account (account: %s, received validity: %ld (%s), ip: %s)\n", account_name, timestamp,
- (timestamp == 0 ? "unlimited" : tmpstr), ip);
+ memcpy(WFIFOP(fd, 6), account_name, 24);
+ LOGIN_LOG("'ladmin': Attempt to change the validity limit of an unknown account (account: %s, received validity: %lld (%s), ip: %s)\n",
+ account_name,
+ timestamp,
+ tmpstr,
+ ip);
}
- WFIFOL (fd, 30) = timestamp;
+ WFIFOL(fd, 30) = static_cast<time_t>(timestamp);
}
- WFIFOSET (fd, 34);
- RFIFOSKIP (fd, 30);
+ WFIFOSET(fd, 34);
+ RFIFOSKIP(fd, 30);
break;
case 0x794a: // Request to change the final date of a banishment (timestamp) (absolute value)
- if (RFIFOREST (fd) < 30)
+ if (RFIFOREST(fd) < 30)
return;
{
- time_t timestamp;
- char tmpstr[2048];
- WFIFOW (fd, 0) = 0x794b;
- WFIFOL (fd, 2) = -1;
- account_name = (char *)RFIFOP (fd, 2);
- account_name[23] = '\0';
- remove_control_chars (account_name);
- timestamp = (time_t) RFIFOL (fd, 26);
- if (timestamp <= time (NULL))
- timestamp = 0;
- strftime (tmpstr, 24, date_format, gmtime (&timestamp));
- i = search_account_index (account_name);
+ WFIFOW(fd, 0) = 0x794b;
+ WFIFOL(fd, 2) = -1;
+ strzcpy(account_name, static_cast<const char *>(RFIFOP(fd, 2)), 24);
+ remove_control_chars(account_name);
+ TimeT timestamp = static_cast<time_t>(RFIFOL(fd, 26));
+ if (timestamp <= TimeT::now())
+ timestamp = TimeT();
+ timestamp_seconds_buffer tmpstr = "no banishment";
+ if (timestamp)
+ stamp_time(tmpstr, &timestamp);
+ i = search_account_index(account_name);
if (i != -1)
{
- memcpy (WFIFOP (fd, 6), auth_dat[i].userid, 24);
- WFIFOL (fd, 2) = auth_dat[i].account_id;
- login_log
- ("'ladmin': Change of the final date of a banishment (account: %s, new final date of banishment: %ld (%s), ip: %s)\n",
- auth_dat[i].userid, timestamp,
- (timestamp == 0 ? "no banishment" : tmpstr), ip);
+ memcpy(WFIFOP(fd, 6), auth_dat[i].userid, 24);
+ WFIFOL(fd, 2) = auth_dat[i].account_id;
+ LOGIN_LOG("'ladmin': Change of the final date of a banishment (account: %s, new final date of banishment: %lld (%s), ip: %s)\n",
+ auth_dat[i].userid, timestamp,
+ tmpstr,
+ ip);
if (auth_dat[i].ban_until_time != timestamp)
{
- if (timestamp != 0)
+ if (timestamp)
{
unsigned char buf[16];
- WBUFW (buf, 0) = 0x2731;
- WBUFL (buf, 2) = auth_dat[i].account_id;
- 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);
+ WBUFW(buf, 0) = 0x2731;
+ WBUFL(buf, 2) = auth_dat[i].account_id;
+ WBUFB(buf, 6) = 1; // 0: change of statut, 1: ban
+ WBUFL(buf, 7) = static_cast<time_t>(timestamp); // status or final date of a banishment
+ charif_sendallwos(-1, buf, 11);
for (j = 0; j < AUTH_FIFO_SIZE; j++)
if (auth_fifo[j].account_id ==
auth_dat[i].account_id)
@@ -3024,82 +2570,71 @@ void parse_admin (int fd)
}
else
{
- memcpy (WFIFOP (fd, 6), account_name, 24);
- login_log
- ("'ladmin': Attempt to change the final date of a banishment of an unknown account (account: %s, received final date of banishment: %ld (%s), ip: %s)\n",
- account_name, timestamp,
- (timestamp == 0 ? "no banishment" : tmpstr), ip);
+ memcpy(WFIFOP(fd, 6), account_name, 24);
+ LOGIN_LOG("'ladmin': Attempt to change the final date of a banishment of an unknown account (account: %s, received final date of banishment: %lld (%s), ip: %s)\n",
+ account_name, timestamp,
+ tmpstr,
+ ip);
}
- WFIFOL (fd, 30) = timestamp;
+ WFIFOL(fd, 30) = static_cast<time_t>(timestamp);
}
- WFIFOSET (fd, 34);
- RFIFOSKIP (fd, 30);
+ WFIFOSET(fd, 34);
+ RFIFOSKIP(fd, 30);
break;
case 0x794c: // Request to change the final date of a banishment (timestamp) (relative change)
- if (RFIFOREST (fd) < 38)
+ if (RFIFOREST(fd) < 38)
return;
{
- time_t timestamp;
- struct tm *tmtime;
- char tmpstr[2048];
- WFIFOW (fd, 0) = 0x794d;
- WFIFOL (fd, 2) = -1;
- account_name = (char *)RFIFOP (fd, 2);
- account_name[23] = '\0';
- remove_control_chars (account_name);
- i = search_account_index (account_name);
+ WFIFOW(fd, 0) = 0x794d;
+ WFIFOL(fd, 2) = -1;
+ strzcpy(account_name, static_cast<const char *>(RFIFOP(fd, 2)), 24);
+ remove_control_chars(account_name);
+ i = search_account_index(account_name);
if (i != -1)
{
- WFIFOL (fd, 2) = auth_dat[i].account_id;
- memcpy (WFIFOP (fd, 6), auth_dat[i].userid, 24);
- if (auth_dat[i].ban_until_time == 0
- || auth_dat[i].ban_until_time < time (NULL))
- timestamp = time (NULL);
+ WFIFOL(fd, 2) = auth_dat[i].account_id;
+ memcpy(WFIFOP(fd, 6), auth_dat[i].userid, 24);
+ TimeT timestamp;
+ TimeT now = TimeT::now();
+ if (!auth_dat[i].ban_until_time
+ || auth_dat[i].ban_until_time < now)
+ timestamp = now;
else
timestamp = auth_dat[i].ban_until_time;
- tmtime = gmtime (&timestamp);
- tmtime->tm_year =
- tmtime->tm_year + (short) RFIFOW (fd, 26);
- tmtime->tm_mon =
- tmtime->tm_mon + (short) RFIFOW (fd, 28);
- tmtime->tm_mday =
- tmtime->tm_mday + (short) RFIFOW (fd, 30);
- tmtime->tm_hour =
- tmtime->tm_hour + (short) RFIFOW (fd, 32);
- tmtime->tm_min =
- tmtime->tm_min + (short) RFIFOW (fd, 34);
- tmtime->tm_sec =
- tmtime->tm_sec + (short) RFIFOW (fd, 36);
- timestamp = mktime (tmtime);
- if (timestamp != -1)
+ struct tm tmtime = timestamp;
+ tmtime.tm_year += (short) RFIFOW(fd, 26);
+ tmtime.tm_mon += (short) RFIFOW(fd, 28);
+ tmtime.tm_mday += (short) RFIFOW(fd, 30);
+ tmtime.tm_hour += (short) RFIFOW(fd, 32);
+ tmtime.tm_min += (short) RFIFOW(fd, 34);
+ tmtime.tm_sec += (short) RFIFOW(fd, 36);
+ timestamp = tmtime;
+ if (timestamp.okay())
{
- if (timestamp <= time (NULL))
- timestamp = 0;
- strftime (tmpstr, 24, date_format,
- gmtime (&timestamp));
- login_log
- ("'ladmin': Adjustment of a final date of a banishment (account: %s, (%+d y %+d m %+d d %+d h %+d mn %+d s) -> new validity: %ld (%s), ip: %s)\n",
- auth_dat[i].userid,
- (short) RFIFOW (fd, 26), (short) RFIFOW (fd,
- 28),
- (short) RFIFOW (fd, 30), (short) RFIFOW (fd,
- 32),
- (short) RFIFOW (fd, 34), (short) RFIFOW (fd,
- 36),
- timestamp,
- (timestamp == 0 ? "no banishment" : tmpstr),
- ip);
+ if (timestamp <= now)
+ timestamp = TimeT();
+ timestamp_seconds_buffer tmpstr = "no banishment";
+ if (timestamp)
+ stamp_time(tmpstr, &timestamp);
+ LOGIN_LOG("'ladmin': Adjustment of a final date of a banishment (account: %s, (%+d y %+d m %+d d %+d h %+d mn %+d s) -> new validity: %lld (%s), ip: %s)\n",
+ auth_dat[i].userid,
+ (short) RFIFOW(fd, 26), (short) RFIFOW(fd, 28),
+ (short) RFIFOW(fd, 30), (short) RFIFOW(fd, 32),
+ (short) RFIFOW(fd, 34), (short) RFIFOW(fd, 36),
+ timestamp,
+ tmpstr,
+ ip);
if (auth_dat[i].ban_until_time != timestamp)
{
- if (timestamp != 0)
+ if (timestamp)
{
unsigned char buf[16];
- WBUFW (buf, 0) = 0x2731;
- WBUFL (buf, 2) = auth_dat[i].account_id;
- 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);
+ WBUFW(buf, 0) = 0x2731;
+ WBUFL(buf, 2) = auth_dat[i].account_id;
+ WBUFB(buf, 6) = 1; // 0: change of statut, 1: ban
+ WBUFL(buf, 7) = static_cast<time_t>(timestamp); // status or final date of a banishment
+ charif_sendallwos(-1, buf, 11);
for (j = 0; j < AUTH_FIFO_SIZE; j++)
if (auth_fifo[j].account_id ==
auth_dat[i].account_id)
@@ -3110,48 +2645,41 @@ void parse_admin (int fd)
}
else
{
- strftime (tmpstr, 24, date_format,
- gmtime (&auth_dat[i].ban_until_time));
- login_log
- ("'ladmin': Impossible to adjust the final date of a banishment (account: %s, %ld (%s) + (%+d y %+d m %+d d %+d h %+d mn %+d s) -> ???, ip: %s)\n",
- auth_dat[i].userid,
- auth_dat[i].ban_until_time,
- (auth_dat[i].ban_until_time ==
- 0 ? "no banishment" : tmpstr),
- (short) RFIFOW (fd, 26), (short) RFIFOW (fd,
- 28),
- (short) RFIFOW (fd, 30), (short) RFIFOW (fd,
- 32),
- (short) RFIFOW (fd, 34), (short) RFIFOW (fd,
- 36),
- ip);
+ timestamp_seconds_buffer tmpstr = "no banishment";
+ if (auth_dat[i].ban_until_time)
+ stamp_time(tmpstr, &auth_dat[i].ban_until_time);
+ LOGIN_LOG("'ladmin': Impossible to adjust the final date of a banishment (account: %s, %lld (%s) + (%+d y %+d m %+d d %+d h %+d mn %+d s) -> ???, ip: %s)\n",
+ auth_dat[i].userid,
+ auth_dat[i].ban_until_time,
+ tmpstr,
+ (short) RFIFOW(fd, 26), (short) RFIFOW(fd, 28),
+ (short) RFIFOW(fd, 30), (short) RFIFOW(fd, 32),
+ (short) RFIFOW(fd, 34), (short) RFIFOW(fd, 36),
+ ip);
}
- WFIFOL (fd, 30) =
- (unsigned long) auth_dat[i].ban_until_time;
+ WFIFOL(fd, 30) = static_cast<time_t>(auth_dat[i].ban_until_time);
}
else
{
- memcpy (WFIFOP (fd, 6), account_name, 24);
- login_log
- ("'ladmin': Attempt to adjust the final date of a banishment of an unknown account (account: %s, ip: %s)\n",
- account_name, ip);
- WFIFOL (fd, 30) = 0;
+ memcpy(WFIFOP(fd, 6), account_name, 24);
+ LOGIN_LOG("'ladmin': Attempt to adjust the final date of a banishment of an unknown account (account: %s, ip: %s)\n",
+ account_name, ip);
+ WFIFOL(fd, 30) = 0;
}
}
- WFIFOSET (fd, 34);
- RFIFOSKIP (fd, 38);
+ WFIFOSET(fd, 34);
+ RFIFOSKIP(fd, 38);
break;
case 0x794e: // Request to send a broadcast message
- if (RFIFOREST (fd) < 8
- || RFIFOREST (fd) < (8 + RFIFOL (fd, 4)))
+ if (RFIFOREST(fd) < 8
+ || RFIFOREST(fd) < (8 + RFIFOL(fd, 4)))
return;
- WFIFOW (fd, 0) = 0x794f;
- WFIFOW (fd, 2) = -1;
- if (RFIFOL (fd, 4) < 1)
+ WFIFOW(fd, 0) = 0x794f;
+ WFIFOW(fd, 2) = -1;
+ if (RFIFOL(fd, 4) < 1)
{
- login_log
- ("'ladmin': Receiving a message for broadcast, but message is void (ip: %s)\n",
+ LOGIN_LOG("'ladmin': Receiving a message for broadcast, but message is void (ip: %s)\n",
ip);
}
else
@@ -3162,309 +2690,276 @@ void parse_admin (int fd)
break;
if (i == MAX_SERVERS)
{
- login_log
- ("'ladmin': Receiving a message for broadcast, but no char-server is online (ip: %s)\n",
+ LOGIN_LOG("'ladmin': Receiving a message for broadcast, but no char-server is online (ip: %s)\n",
ip);
}
else
{
uint8_t buf[32000];
char message[32000];
- WFIFOW (fd, 2) = 0;
- memset (message, '\0', sizeof (message));
- memcpy (message, RFIFOP (fd, 8), RFIFOL (fd, 4));
- message[sizeof (message) - 1] = '\0';
- remove_control_chars (message);
- if (RFIFOW (fd, 2) == 0)
- login_log
- ("'ladmin': Receiving a message for broadcast (message (in yellow): %s, ip: %s)\n",
+ WFIFOW(fd, 2) = 0;
+ memset(message, '\0', sizeof(message));
+ memcpy(message, RFIFOP(fd, 8), RFIFOL(fd, 4));
+ message[sizeof(message) - 1] = '\0';
+ remove_control_chars(message);
+ if (RFIFOW(fd, 2) == 0)
+ LOGIN_LOG("'ladmin': Receiving a message for broadcast (message (in yellow): %s, ip: %s)\n",
message, ip);
else
- login_log
- ("'ladmin': Receiving a message for broadcast (message (in blue): %s, ip: %s)\n",
+ LOGIN_LOG("'ladmin': Receiving a message for broadcast (message (in blue): %s, ip: %s)\n",
message, ip);
// send same message to all char-servers (no answer)
- memcpy (WBUFP (buf, 0), RFIFOP (fd, 0),
- 8 + RFIFOL (fd, 4));
- WBUFW (buf, 0) = 0x2726;
- charif_sendallwos (-1, buf, 8 + RFIFOL (fd, 4));
+ memcpy(WBUFP(buf, 0), RFIFOP(fd, 0),
+ 8 + RFIFOL(fd, 4));
+ WBUFW(buf, 0) = 0x2726;
+ charif_sendallwos(-1, buf, 8 + RFIFOL(fd, 4));
}
}
- WFIFOSET (fd, 4);
- RFIFOSKIP (fd, 8 + RFIFOL (fd, 4));
+ WFIFOSET(fd, 4);
+ RFIFOSKIP(fd, 8 + RFIFOL(fd, 4));
break;
case 0x7950: // Request to change the validity limite (timestamp) (relative change)
- if (RFIFOREST (fd) < 38)
+ if (RFIFOREST(fd) < 38)
return;
{
- time_t timestamp;
- struct tm *tmtime;
- char tmpstr[2048];
- char tmpstr2[2048];
- WFIFOW (fd, 0) = 0x7951;
- WFIFOL (fd, 2) = -1;
- account_name = (char *)RFIFOP (fd, 2);
- account_name[23] = '\0';
- remove_control_chars (account_name);
- i = search_account_index (account_name);
+ WFIFOW(fd, 0) = 0x7951;
+ WFIFOL(fd, 2) = -1;
+ strzcpy(account_name, static_cast<const char *>(RFIFOP(fd, 2)), 24);
+ remove_control_chars(account_name);
+ i = search_account_index(account_name);
if (i != -1)
{
- WFIFOL (fd, 2) = auth_dat[i].account_id;
- memcpy (WFIFOP (fd, 6), auth_dat[i].userid, 24);
- timestamp = auth_dat[i].connect_until_time;
- if (add_to_unlimited_account == 0 && timestamp == 0)
+ WFIFOL(fd, 2) = auth_dat[i].account_id;
+ memcpy(WFIFOP(fd, 6), auth_dat[i].userid, 24);
+ if (add_to_unlimited_account == 0 && !auth_dat[i].connect_until_time)
{
- login_log
- ("'ladmin': Attempt to adjust the validity limit of an unlimited account (account: %s, ip: %s)\n",
+ LOGIN_LOG("'ladmin': Attempt to adjust the validity limit of an unlimited account (account: %s, ip: %s)\n",
auth_dat[i].userid, ip);
- WFIFOL (fd, 30) = 0;
+ WFIFOL(fd, 30) = 0;
}
else
{
- if (timestamp == 0 || timestamp < time (NULL))
- timestamp = time (NULL);
- tmtime = gmtime (&timestamp);
- tmtime->tm_year =
- tmtime->tm_year + (short) RFIFOW (fd, 26);
- tmtime->tm_mon =
- tmtime->tm_mon + (short) RFIFOW (fd, 28);
- tmtime->tm_mday =
- tmtime->tm_mday + (short) RFIFOW (fd, 30);
- tmtime->tm_hour =
- tmtime->tm_hour + (short) RFIFOW (fd, 32);
- tmtime->tm_min =
- tmtime->tm_min + (short) RFIFOW (fd, 34);
- tmtime->tm_sec =
- tmtime->tm_sec + (short) RFIFOW (fd, 36);
- timestamp = mktime (tmtime);
- if (timestamp != -1)
+ TimeT now = TimeT::now();
+ TimeT timestamp;
+ if (!timestamp || timestamp < now)
+ timestamp = now;
+ struct tm tmtime = timestamp;
+ tmtime.tm_year += (short) RFIFOW(fd, 26);
+ tmtime.tm_mon += (short) RFIFOW(fd, 28);
+ tmtime.tm_mday += (short) RFIFOW(fd, 30);
+ tmtime.tm_hour += (short) RFIFOW(fd, 32);
+ tmtime.tm_min += (short) RFIFOW(fd, 34);
+ tmtime.tm_sec += (short) RFIFOW(fd, 36);
+ timestamp = tmtime;
+ if (timestamp.okay())
{
- strftime (tmpstr, 24, date_format,
- gmtime (&auth_dat
- [i].connect_until_time));
- strftime (tmpstr2, 24, date_format,
- gmtime (&timestamp));
- login_log
- ("'ladmin': Adjustment of a validity limit (account: %s, %ld (%s) + (%+d y %+d m %+d d %+d h %+d mn %+d s) -> new validity: %ld (%s), ip: %s)\n",
- auth_dat[i].userid,
- auth_dat[i].connect_until_time,
- (auth_dat[i].connect_until_time ==
- 0 ? "unlimited" : tmpstr),
- (short) RFIFOW (fd, 26),
- (short) RFIFOW (fd, 28),
- (short) RFIFOW (fd, 30),
- (short) RFIFOW (fd, 32),
- (short) RFIFOW (fd, 34),
- (short) RFIFOW (fd, 36), timestamp,
- (timestamp == 0 ? "unlimited" : tmpstr2),
- ip);
+ timestamp_seconds_buffer tmpstr = "unlimited";
+ timestamp_seconds_buffer tmpstr2 = "unlimited";
+ if (auth_dat[i].connect_until_time)
+ stamp_time(tmpstr, &auth_dat[i].connect_until_time);
+ if (timestamp)
+ stamp_time(tmpstr2, &timestamp);
+ LOGIN_LOG("'ladmin': Adjustment of a validity limit (account: %s, %lld (%s) + (%+d y %+d m %+d d %+d h %+d mn %+d s) -> new validity: %lld (%s), ip: %s)\n",
+ auth_dat[i].userid,
+ auth_dat[i].connect_until_time,
+ tmpstr,
+ (short) RFIFOW(fd, 26),
+ (short) RFIFOW(fd, 28),
+ (short) RFIFOW(fd, 30),
+ (short) RFIFOW(fd, 32),
+ (short) RFIFOW(fd, 34),
+ (short) RFIFOW(fd, 36),
+ timestamp,
+ tmpstr2,
+ ip);
auth_dat[i].connect_until_time = timestamp;
- WFIFOL (fd, 30) =
- (unsigned long)
- auth_dat[i].connect_until_time;
+ WFIFOL(fd, 30) = static_cast<time_t>(timestamp);
}
else
{
- strftime (tmpstr, 24, date_format,
- gmtime (&auth_dat
- [i].connect_until_time));
- login_log
- ("'ladmin': Impossible to adjust a validity limit (account: %s, %ld (%s) + (%+d y %+d m %+d d %+d h %+d mn %+d s) -> ???, ip: %s)\n",
- auth_dat[i].userid,
- auth_dat[i].connect_until_time,
- (auth_dat[i].connect_until_time ==
- 0 ? "unlimited" : tmpstr),
- (short) RFIFOW (fd, 26),
- (short) RFIFOW (fd, 28),
- (short) RFIFOW (fd, 30),
- (short) RFIFOW (fd, 32),
- (short) RFIFOW (fd, 34),
- (short) RFIFOW (fd, 36), ip);
- WFIFOL (fd, 30) = 0;
+ timestamp_seconds_buffer tmpstr = "unlimited";
+ if (auth_dat[i].connect_until_time)
+ stamp_time(tmpstr, &auth_dat[i].connect_until_time);
+ LOGIN_LOG("'ladmin': Impossible to adjust a validity limit (account: %s, %lld (%s) + (%+d y %+d m %+d d %+d h %+d mn %+d s) -> ???, ip: %s)\n",
+ auth_dat[i].userid,
+ auth_dat[i].connect_until_time,
+ tmpstr,
+ (short) RFIFOW(fd, 26),
+ (short) RFIFOW(fd, 28),
+ (short) RFIFOW(fd, 30),
+ (short) RFIFOW(fd, 32),
+ (short) RFIFOW(fd, 34),
+ (short) RFIFOW(fd, 36),
+ ip);
+ WFIFOL(fd, 30) = 0;
}
}
}
else
{
- memcpy (WFIFOP (fd, 6), account_name, 24);
- login_log
- ("'ladmin': Attempt to adjust the validity limit of an unknown account (account: %s, ip: %s)\n",
+ memcpy(WFIFOP(fd, 6), account_name, 24);
+ LOGIN_LOG("'ladmin': Attempt to adjust the validity limit of an unknown account (account: %s, ip: %s)\n",
account_name, ip);
- WFIFOL (fd, 30) = 0;
+ WFIFOL(fd, 30) = 0;
}
}
- WFIFOSET (fd, 34);
- RFIFOSKIP (fd, 38);
+ WFIFOSET(fd, 34);
+ RFIFOSKIP(fd, 38);
break;
case 0x7952: // Request about informations of an account (by account name)
- if (RFIFOREST (fd) < 26)
+ if (RFIFOREST(fd) < 26)
return;
- WFIFOW (fd, 0) = 0x7953;
- WFIFOL (fd, 2) = -1;
- account_name = (char *)RFIFOP (fd, 2);
- account_name[23] = '\0';
- remove_control_chars (account_name);
- i = search_account_index (account_name);
+ WFIFOW(fd, 0) = 0x7953;
+ WFIFOL(fd, 2) = -1;
+ strzcpy(account_name, static_cast<const char *>(RFIFOP(fd, 2)), 24);
+ remove_control_chars(account_name);
+ i = search_account_index(account_name);
if (i != -1)
{
- WFIFOL (fd, 2) = auth_dat[i].account_id;
- WFIFOB (fd, 6) =
- (unsigned char) isGM (auth_dat[i].account_id);
- memcpy (WFIFOP (fd, 7), auth_dat[i].userid, 24);
- WFIFOB (fd, 31) = auth_dat[i].sex;
- WFIFOL (fd, 32) = auth_dat[i].logincount;
- WFIFOL (fd, 36) = auth_dat[i].state;
- memcpy (WFIFOP (fd, 40), auth_dat[i].error_message, 20);
- memcpy (WFIFOP (fd, 60), auth_dat[i].lastlogin, 24);
- memcpy (WFIFOP (fd, 84), auth_dat[i].last_ip, 16);
- memcpy (WFIFOP (fd, 100), auth_dat[i].email, 40);
- WFIFOL (fd, 140) =
- (unsigned long) auth_dat[i].connect_until_time;
- WFIFOL (fd, 144) =
- (unsigned long) auth_dat[i].ban_until_time;
- WFIFOW (fd, 148) = strlen (auth_dat[i].memo);
+ WFIFOL(fd, 2) = auth_dat[i].account_id;
+ WFIFOB(fd, 6) =
+ (unsigned char) isGM(auth_dat[i].account_id);
+ memcpy(WFIFOP(fd, 7), auth_dat[i].userid, 24);
+ WFIFOB(fd, 31) = auth_dat[i].sex;
+ WFIFOL(fd, 32) = auth_dat[i].logincount;
+ WFIFOL(fd, 36) = auth_dat[i].state;
+ memcpy(WFIFOP(fd, 40), auth_dat[i].error_message, 20);
+ memcpy(WFIFOP(fd, 60), auth_dat[i].lastlogin, 24);
+ memcpy(WFIFOP(fd, 84), auth_dat[i].last_ip, 16);
+ memcpy(WFIFOP(fd, 100), auth_dat[i].email, 40);
+ WFIFOL(fd, 140) = static_cast<time_t>(auth_dat[i].connect_until_time);
+ WFIFOL(fd, 144) = static_cast<time_t>(auth_dat[i].ban_until_time);
+ WFIFOW(fd, 148) = strlen(auth_dat[i].memo);
if (auth_dat[i].memo[0])
{
- memcpy (WFIFOP (fd, 150), auth_dat[i].memo,
- strlen (auth_dat[i].memo));
+ memcpy(WFIFOP(fd, 150), auth_dat[i].memo,
+ strlen(auth_dat[i].memo));
}
- login_log
- ("'ladmin': Sending information of an account (request by the name; account: %s, id: %d, ip: %s)\n",
+ LOGIN_LOG("'ladmin': Sending information of an account (request by the name; account: %s, id: %d, ip: %s)\n",
auth_dat[i].userid, auth_dat[i].account_id,
ip);
- WFIFOSET (fd, 150 + strlen (auth_dat[i].memo));
+ WFIFOSET(fd, 150 + strlen(auth_dat[i].memo));
}
else
{
- memcpy (WFIFOP (fd, 7), account_name, 24);
- WFIFOW (fd, 148) = 0;
- login_log
- ("'ladmin': Attempt to obtain information (by the name) of an unknown account (account: %s, ip: %s)\n",
+ memcpy(WFIFOP(fd, 7), account_name, 24);
+ WFIFOW(fd, 148) = 0;
+ LOGIN_LOG("'ladmin': Attempt to obtain information (by the name) of an unknown account (account: %s, ip: %s)\n",
account_name, ip);
- WFIFOSET (fd, 150);
+ WFIFOSET(fd, 150);
}
- RFIFOSKIP (fd, 26);
+ RFIFOSKIP(fd, 26);
break;
case 0x7954: // Request about information of an account (by account id)
- if (RFIFOREST (fd) < 6)
+ if (RFIFOREST(fd) < 6)
return;
- WFIFOW (fd, 0) = 0x7953;
- WFIFOL (fd, 2) = RFIFOL (fd, 2);
- memset (WFIFOP (fd, 7), '\0', 24);
+ WFIFOW(fd, 0) = 0x7953;
+ WFIFOL(fd, 2) = RFIFOL(fd, 2);
+ memset(WFIFOP(fd, 7), '\0', 24);
for (i = 0; i < auth_num; i++)
{
- if (auth_dat[i].account_id == RFIFOL (fd, 2))
+ if (auth_dat[i].account_id == RFIFOL(fd, 2))
{
- login_log
- ("'ladmin': Sending information of an account (request by the id; account: %s, id: %d, ip: %s)\n",
- auth_dat[i].userid, RFIFOL (fd, 2), ip);
- WFIFOB (fd, 6) =
- (unsigned char) isGM (auth_dat[i].account_id);
- memcpy (WFIFOP (fd, 7), auth_dat[i].userid, 24);
- WFIFOB (fd, 31) = auth_dat[i].sex;
- WFIFOL (fd, 32) = auth_dat[i].logincount;
- WFIFOL (fd, 36) = auth_dat[i].state;
- memcpy (WFIFOP (fd, 40), auth_dat[i].error_message,
+ LOGIN_LOG("'ladmin': Sending information of an account (request by the id; account: %s, id: %d, ip: %s)\n",
+ auth_dat[i].userid, RFIFOL(fd, 2), ip);
+ WFIFOB(fd, 6) =
+ (unsigned char) isGM(auth_dat[i].account_id);
+ memcpy(WFIFOP(fd, 7), auth_dat[i].userid, 24);
+ WFIFOB(fd, 31) = auth_dat[i].sex;
+ WFIFOL(fd, 32) = auth_dat[i].logincount;
+ WFIFOL(fd, 36) = auth_dat[i].state;
+ memcpy(WFIFOP(fd, 40), auth_dat[i].error_message,
20);
- memcpy (WFIFOP (fd, 60), auth_dat[i].lastlogin, 24);
- memcpy (WFIFOP (fd, 84), auth_dat[i].last_ip, 16);
- memcpy (WFIFOP (fd, 100), auth_dat[i].email, 40);
- WFIFOL (fd, 140) =
- (unsigned long) auth_dat[i].connect_until_time;
- WFIFOL (fd, 144) =
- (unsigned long) auth_dat[i].ban_until_time;
- WFIFOW (fd, 148) = strlen (auth_dat[i].memo);
+ memcpy(WFIFOP(fd, 60), auth_dat[i].lastlogin, 24);
+ memcpy(WFIFOP(fd, 84), auth_dat[i].last_ip, 16);
+ memcpy(WFIFOP(fd, 100), auth_dat[i].email, 40);
+ WFIFOL(fd, 140) = static_cast<time_t>(auth_dat[i].connect_until_time);
+ WFIFOL(fd, 144) = static_cast<time_t>(auth_dat[i].ban_until_time);
+ WFIFOW(fd, 148) = strlen(auth_dat[i].memo);
if (auth_dat[i].memo[0])
{
- memcpy (WFIFOP (fd, 150), auth_dat[i].memo,
- strlen (auth_dat[i].memo));
+ memcpy(WFIFOP(fd, 150), auth_dat[i].memo,
+ strlen(auth_dat[i].memo));
}
- WFIFOSET (fd, 150 + strlen (auth_dat[i].memo));
+ WFIFOSET(fd, 150 + strlen(auth_dat[i].memo));
break;
}
}
if (i == auth_num)
{
- login_log
- ("'ladmin': Attempt to obtain information (by the id) of an unknown account (id: %d, ip: %s)\n",
- RFIFOL (fd, 2), ip);
- strncpy ((char *)WFIFOP (fd, 7), "", 24);
- WFIFOW (fd, 148) = 0;
- WFIFOSET (fd, 150);
+ LOGIN_LOG("'ladmin': Attempt to obtain information (by the id) of an unknown account (id: %d, ip: %s)\n",
+ RFIFOL(fd, 2), ip);
+ strncpy((char *)WFIFOP(fd, 7), "", 24);
+ WFIFOW(fd, 148) = 0;
+ WFIFOSET(fd, 150);
}
- RFIFOSKIP (fd, 6);
+ RFIFOSKIP(fd, 6);
break;
case 0x7955: // Request to reload GM file (no answer)
- login_log
- ("'ladmin': Request to re-load GM configuration file (ip: %s).\n",
+ LOGIN_LOG("'ladmin': Request to re-load GM configuration file (ip: %s).\n",
ip);
- read_gm_account ();
+ read_gm_account();
// send GM accounts to all char-servers
- send_GM_accounts ();
- RFIFOSKIP (fd, 2);
+ send_GM_accounts();
+ RFIFOSKIP(fd, 2);
break;
default:
{
FILE *logfp;
- char tmpstr[24];
- struct timeval tv;
- logfp = fopen_ (login_log_unknown_packets_filename, "a");
+ logfp = fopen_(login_log_unknown_packets_filename, "a");
if (logfp)
{
- gettimeofday (&tv, NULL);
- strftime (tmpstr, 23, date_format, gmtime (&(tv.tv_sec)));
- fprintf (logfp,
- "%s.%03d: receiving of an unknown packet -> disconnection\n",
- tmpstr, (int) tv.tv_usec / 1000);
- fprintf (logfp,
- "parse_admin: connection #%d (ip: %s), packet: 0x%x (with being read: %d).\n",
- fd, ip, RFIFOW (fd, 0), RFIFOREST (fd));
- fprintf (logfp, "Detail (in hex):\n");
- fprintf (logfp,
+ timestamp_milliseconds_buffer tmpstr;
+ FPRINTF(logfp,
+ "%s: receiving of an unknown packet -> disconnection\n",
+ tmpstr);
+ FPRINTF(logfp,
+ "parse_admin: connection #%d (ip: %s), packet: 0x%x (with being read: %zu).\n",
+ fd, ip, RFIFOW(fd, 0), RFIFOREST(fd));
+ FPRINTF(logfp, "Detail (in hex):\n");
+ FPRINTF(logfp,
"---- 00-01-02-03-04-05-06-07 08-09-0A-0B-0C-0D-0E-0F\n");
- memset (tmpstr, '\0', sizeof (tmpstr));
- for (i = 0; i < RFIFOREST (fd); i++)
+ memset(tmpstr, '\0', sizeof(tmpstr));
+ for (i = 0; i < RFIFOREST(fd); i++)
{
if ((i & 15) == 0)
- fprintf (logfp, "%04X ", i);
- fprintf (logfp, "%02x ", RFIFOB (fd, i));
- if (RFIFOB (fd, i) > 0x1f)
- tmpstr[i % 16] = RFIFOB (fd, i);
+ FPRINTF(logfp, "%04X ", i);
+ FPRINTF(logfp, "%02x ", RFIFOB (fd, i));
+ if (RFIFOB(fd, i) > 0x1f)
+ tmpstr[i % 16] = RFIFOB(fd, i);
else
tmpstr[i % 16] = '.';
if ((i - 7) % 16 == 0) // -8 + 1
- fprintf (logfp, " ");
+ FPRINTF(logfp, " ");
else if ((i + 1) % 16 == 0)
{
- fprintf (logfp, " %s\n", tmpstr);
- memset (tmpstr, '\0', sizeof (tmpstr));
+ FPRINTF(logfp, " %s\n", tmpstr);
+ memset(tmpstr, '\0', sizeof(tmpstr));
}
}
if (i % 16 != 0)
{
for (j = i; j % 16 != 0; j++)
{
- fprintf (logfp, " ");
+ FPRINTF(logfp, " ");
if ((j - 7) % 16 == 0) // -8 + 1
- fprintf (logfp, " ");
+ FPRINTF(logfp, " ");
}
- fprintf (logfp, " %s\n", tmpstr);
+ FPRINTF(logfp, " %s\n", tmpstr);
}
- fprintf (logfp, "\n");
- fclose_ (logfp);
+ FPRINTF(logfp, "\n");
+ fclose_(logfp);
}
}
- login_log
- ("'ladmin': End of connection, unknown packet (ip: %s)\n",
+ LOGIN_LOG("'ladmin': End of connection, unknown packet (ip: %s)\n",
ip);
session[fd]->eof = 1;
- printf
- ("Remote administration has been disconnected (unknown packet).\n");
+ PRINTF("Remote administration has been disconnected (unknown packet).\n");
return;
}
//WFIFOW(fd,0) = 0x791f;
@@ -3478,12 +2973,12 @@ void parse_admin (int fd)
//--------------------------------------------
// TODO fix to not take a ptr-to-uint8_t
static
-int lan_ip_check (unsigned char *p)
+int lan_ip_check(unsigned char *p)
{
- int i;
- int lancheck = 1;
+ int i;
+ int lancheck = 1;
-// printf("lan_ip_check: to compare: %d.%d.%d.%d, network: %d.%d.%d.%d/%d.%d.%d.%d\n",
+// 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]);
@@ -3495,7 +2990,7 @@ int lan_ip_check (unsigned char *p)
break;
}
}
- printf ("LAN test (result): %s source\033[0m.\n",
+ PRINTF("LAN test (result): %s source\033[0m.\n",
(lancheck) ? "\033[1;36mLAN" : "\033[1;32mWAN");
return lancheck;
}
@@ -3504,131 +2999,112 @@ int lan_ip_check (unsigned char *p)
// Default packet parsing (normal players or administation/char-server connexion requests)
//----------------------------------------------------------------------------------------
static
-void parse_login (int fd)
+void parse_login(int fd)
{
struct mmo_account account;
- int result, j;
+ int result, j;
unsigned char *p = (unsigned char *) &session[fd]->client_addr.sin_addr;
- int host_len;
+ int host_len;
const char *ip = ip2str(session[fd]->client_addr.sin_addr);
if (session[fd]->eof)
{
- close (fd);
- delete_session (fd);
+ delete_session(fd);
return;
}
- while (RFIFOREST (fd) >= 2)
+ while (RFIFOREST(fd) >= 2)
{
if (display_parse_login == 1)
{
- if (RFIFOW (fd, 0) == 0x64 || RFIFOW (fd, 0) == 0x01dd)
+ if (RFIFOW(fd, 0) == 0x64 || RFIFOW(fd, 0) == 0x01dd)
{
- if (RFIFOREST (fd) >= ((RFIFOW (fd, 0) == 0x64) ? 55 : 47))
- printf
- ("parse_login: connection #%d, packet: 0x%x (with being read: %d), account: %s.\n",
- fd, RFIFOW (fd, 0), RFIFOREST (fd), RFIFOP (fd, 6));
+ if (RFIFOREST(fd) >= ((RFIFOW(fd, 0) == 0x64) ? 55 : 47))
+ PRINTF("parse_login: connection #%d, packet: 0x%x (with being read: %zu), account: %s.\n",
+ fd, RFIFOW(fd, 0), RFIFOREST(fd),
+ static_cast<const char *>(RFIFOP(fd, 6)));
}
- else if (RFIFOW (fd, 0) == 0x2710)
+ else if (RFIFOW(fd, 0) == 0x2710)
{
- if (RFIFOREST (fd) >= 86)
- printf
- ("parse_login: connection #%d, packet: 0x%x (with being read: %d), server: %s.\n",
- fd, RFIFOW (fd, 0), RFIFOREST (fd), RFIFOP (fd, 60));
+ if (RFIFOREST(fd) >= 86)
+ PRINTF("parse_login: connection #%d, packet: 0x%x (with being read: %zu), server: %s.\n",
+ fd, RFIFOW(fd, 0), RFIFOREST(fd),
+ static_cast<const char *>(RFIFOP(fd, 60)));
}
else
- printf
- ("parse_login: connection #%d, packet: 0x%x (with being read: %d).\n",
- fd, RFIFOW (fd, 0), RFIFOREST (fd));
+ PRINTF("parse_login: connection #%d, packet: 0x%x (with being read: %zu).\n",
+ fd, RFIFOW(fd, 0), RFIFOREST(fd));
}
- switch (RFIFOW (fd, 0))
+ switch (RFIFOW(fd, 0))
{
case 0x200: // New alive packet: structure: 0x200 <account.userid>.24B. used to verify if client is always alive.
- if (RFIFOREST (fd) < 26)
+ if (RFIFOREST(fd) < 26)
return;
- RFIFOSKIP (fd, 26);
+ RFIFOSKIP(fd, 26);
break;
case 0x204: // New alive packet: structure: 0x204 <encrypted.account.userid>.16B. (new ragexe from 22 june 2004)
- if (RFIFOREST (fd) < 18)
+ if (RFIFOREST(fd) < 18)
return;
- RFIFOSKIP (fd, 18);
+ 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))
+ if (RFIFOREST(fd) < 55)
return;
- account.userid = (char *)RFIFOP (fd, 6);
- account.userid[23] = '\0';
- remove_control_chars (account.userid);
- account.passwd = (char *)RFIFOP (fd, 30);
- if (RFIFOW (fd, 0) == 0x64)
- {
- account.passwd[23] = '\0';
- remove_control_chars (account.passwd);
- }
-#ifdef PASSWORDENC
- account.passwdenc =
- (RFIFOW (fd, 0) == 0x64) ? 0 : PASSWORDENC;
-#else
+ strzcpy(account.userid, static_cast<const char *>(RFIFOP(fd, 6)), 24);
+ remove_control_chars(account.userid);
+ strzcpy(account.passwd, static_cast<const char *>(RFIFOP(fd, 30)), 24);
+ remove_control_chars(account.passwd);
account.passwdenc = 0;
-#endif
- if (RFIFOW (fd, 0) == 0x64)
- {
- login_log
- ("Request for connection (non encryption mode) of %s (ip: %s).\n",
- account.userid, ip);
- }
- else
- {
- login_log
- ("Request for connection (encryption mode) of %s (ip: %s).\n",
- account.userid, ip);
- }
+ LOGIN_LOG("Request for connection (non encryption mode) of %s (ip: %s).\n",
+ account.userid, ip);
- if (!check_ip (session[fd]->client_addr.sin_addr))
+ if (!check_ip(session[fd]->client_addr.sin_addr))
{
- login_log
- ("Connection refused: IP isn't authorised (deny/allow, ip: %s).\n",
+ LOGIN_LOG("Connection refused: IP isn't authorised (deny/allow, ip: %s).\n",
ip);
- WFIFOW (fd, 0) = 0x6a;
- WFIFOB (fd, 2) = 0x03;
- WFIFOSET (fd, 3);
- RFIFOSKIP (fd, (RFIFOW (fd, 0) == 0x64) ? 55 : 47);
+ WFIFOW(fd, 0) = 0x6a;
+ WFIFOB(fd, 2) = 0x03;
+ memset(WFIFOP(fd, 3), '\0', 20);
+ WFIFOSET(fd, 23);
+ RFIFOSKIP(fd, 55);
break;
}
- result = mmo_auth (&account, fd);
+ result = mmo_auth(&account, fd);
+ if (result == -1)
+ {
+ VERSION_2 version_2 = static_cast<VERSION_2>(RFIFOB(fd, 54));
+ if (!bool(version_2 & VERSION_2::UPDATEHOST)
+ || !bool(version_2 & VERSION_2::SERVERORDER))
+ result = 5; // client too old
+ }
if (result == -1)
{
- int gm_level = isGM (account.account_id);
+ int gm_level = isGM(account.account_id);
if (min_level_to_connect > gm_level)
{
- login_log
- ("Connection refused: the minimum GM level for connection is %d (account: %s, GM level: %d, ip: %s).\n",
+ LOGIN_LOG("Connection refused: the minimum GM level for connection is %d (account: %s, GM level: %d, ip: %s).\n",
min_level_to_connect, account.userid,
gm_level, ip);
- WFIFOW (fd, 0) = 0x81;
- WFIFOL (fd, 2) = 1; // 01 = Server closed
- WFIFOSET (fd, 3);
+ WFIFOW(fd, 0) = 0x81;
+ WFIFOB(fd, 2) = 1; // 01 = Server closed
+ WFIFOSET(fd, 3);
}
else
{
- int version_2 = RFIFOB (fd, 54); // version 2
+ // int version_2 = RFIFOB(fd, 54); // version 2
if (gm_level)
- printf
- ("Connection of the GM (level:%d) account '%s' accepted.\n",
+ PRINTF("Connection of the GM (level:%d) account '%s' accepted.\n",
gm_level, account.userid);
else
- printf
- ("Connection of the account '%s' accepted.\n",
+ PRINTF("Connection of the account '%s' accepted.\n",
account.userid);
/*
@@ -3639,85 +3115,60 @@ void parse_login (int fd)
* from the incoming 0x64 packet (the byte at offset 54). If bit 0 of this is set,
* then the client can safely accept the 0x63 packet. The "version 2" value is not
* otherwise used by eAthena.
+ *
+ * All supported clients now send both, so the check is removed.
*/
- if ((RFIFOW (fd, 0) == 0x64)
- && (version_2 & VERSION_2_UPDATEHOST))
+ // if (version_2 & VERSION_2_UPDATEHOST)
{
- host_len = (int) strlen (update_host);
+ host_len = (int) strlen(update_host);
if (host_len > 0)
{
- WFIFOW (fd, 0) = 0x63;
- WFIFOW (fd, 2) = 4 + host_len;
- memcpy (WFIFOP (fd, 4), update_host,
+ WFIFOW(fd, 0) = 0x63;
+ WFIFOW(fd, 2) = 4 + host_len;
+ memcpy(WFIFOP(fd, 4), update_host,
host_len);
- WFIFOSET (fd, 4 + host_len);
+ WFIFOSET(fd, 4 + host_len);
}
}
// Load list of char servers into outbound packet
server_num = 0;
- if (version_2 & VERSION_2_SERVERORDER)
- for (int i = 0; i < MAX_SERVERS; i++)
- {
- if (server_fd[i] >= 0)
- {
- 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].is_new;
- server_num++;
- }
- }
- else // Send them in reverse, as the client defaults to the second (!) one
- for (int i = MAX_SERVERS - 1; i >= 0; i--)
+ // if (version_2 & VERSION_2_SERVERORDER)
+ for (int i = 0; i < MAX_SERVERS; i++)
+ {
+ if (server_fd[i] >= 0)
{
- if (server_fd[i] >= 0)
- {
- 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].is_new;
- server_num++;
- }
+ 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].is_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; // in old version, that was for ip (not more used)
- memcpy (WFIFOP (fd, 20), account.lastlogin, 24); // in old version, that was for name (not more used)
- WFIFOB (fd, 46) = account.sex;
- WFIFOSET (fd, 47 + 32 * server_num);
+ 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; // in old version, that was for ip (not more used)
+ memcpy(WFIFOP(fd, 20), account.lastlogin, 24); // in old version, that was for name (not more used)
+ 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 =
@@ -3735,44 +3186,42 @@ void parse_login (int fd)
}
else
{
- login_log
- ("Connection refused: there is no char-server online (account: %s, ip: %s).\n",
+ LOGIN_LOG("Connection refused: there is no char-server online (account: %s, ip: %s).\n",
account.userid, ip);
- WFIFOW (fd, 0) = 0x81;
- WFIFOL (fd, 2) = 1; // 01 = Server closed
- WFIFOSET (fd, 3);
+ WFIFOW(fd, 0) = 0x81;
+ WFIFOB(fd, 2) = 1; // 01 = Server closed
+ WFIFOSET(fd, 3);
}
}
}
else
{
- memset (WFIFOP (fd, 0), '\0', 23);
- WFIFOW (fd, 0) = 0x6a;
- WFIFOB (fd, 2) = result;
+ 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
- int i = search_account_index (account.userid);
+ {
+ // 6 = Your are Prohibited to log in until %s
+ int i = search_account_index(account.userid);
if (i != -1)
{
- if (auth_dat[i].ban_until_time != 0)
- { // if account is banned, we send ban timestamp
- char tmpstr[256];
- strftime (tmpstr, 20, date_format,
- gmtime (&auth_dat
- [i].ban_until_time));
- tmpstr[19] = '\0';
- memcpy (WFIFOP (fd, 3), tmpstr, 20);
+ if (auth_dat[i].ban_until_time)
+ {
+ // if account is banned, we send ban timestamp
+ timestamp_seconds_buffer tmpstr;
+ stamp_time(tmpstr, &auth_dat[i].ban_until_time);
+ memcpy(WFIFOP(fd, 3), tmpstr, 20);
}
else
{ // we send error message
- memcpy (WFIFOP (fd, 3),
+ memcpy(WFIFOP(fd, 3),
auth_dat[i].error_message, 20);
}
}
}
- WFIFOSET (fd, 23);
+ WFIFOSET(fd, 23);
}
- RFIFOSKIP (fd, (RFIFOW (fd, 0) == 0x64) ? 55 : 47);
+ RFIFOSKIP(fd, (RFIFOW(fd, 0) == 0x64) ? 55 : 47);
break;
case 0x01db: // Sending request of the coding key
@@ -3781,79 +3230,73 @@ void parse_login (int fd)
struct login_session_data *ld;
if (session[fd]->session_data)
{
- printf
- ("login: abnormal request of MD5 key (already opened session).\n");
+ PRINTF("login: abnormal request of MD5 key (already opened session).\n");
session[fd]->eof = 1;
return;
}
- CREATE (ld, struct login_session_data, 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");
+ PRINTF("login: Request for md5 key: memory allocation failure (malloc)!\n");
session[fd]->eof = 1;
return;
}
- if (RFIFOW (fd, 0) == 0x01db)
+ if (RFIFOW(fd, 0) == 0x01db)
{
- login_log ("Sending request of the coding key (ip: %s)\n",
+ LOGIN_LOG("Sending request of the coding key (ip: %s)\n",
ip);
}
else
{
- login_log
- ("'ladmin': Sending request of the coding key (ip: %s)\n",
+ LOGIN_LOG("'ladmin': Sending request of the coding key (ip: %s)\n",
ip);
}
+ // TODO fix or get rid of this
// Creation of the coding key
- memset (ld->md5key, '\0', sizeof (ld->md5key));
- ld->md5keylen = rand () % 4 + 12;
+ memset(ld->md5key, '\0', sizeof(ld->md5key));
+ ld->md5keylen = random_::in(12, 15);
for (int i = 0; i < ld->md5keylen; i++)
- ld->md5key[i] = rand () % 255 + 1;
+ ld->md5key[i] = random_::in(1, 255);
- RFIFOSKIP (fd, 2);
- WFIFOW (fd, 0) = 0x01dc;
- WFIFOW (fd, 2) = 4 + ld->md5keylen;
- memcpy (WFIFOP (fd, 4), ld->md5key, ld->md5keylen);
- WFIFOSET (fd, WFIFOW (fd, 2));
+ RFIFOSKIP(fd, 2);
+ WFIFOW(fd, 0) = 0x01dc;
+ WFIFOW(fd, 2) = 4 + ld->md5keylen;
+ memcpy(WFIFOP(fd, 4), ld->md5key, ld->md5keylen);
+ WFIFOSET(fd, WFIFOW(fd, 2));
}
break;
case 0x2710: // Connection request of a char-server
- if (RFIFOREST (fd) < 86)
+ if (RFIFOREST(fd) < 86)
return;
{
- int GM_value, len;
- char *server_name;
- account.userid = (char *)RFIFOP (fd, 2);
- account.userid[23] = '\0';
- remove_control_chars (account.userid);
- account.passwd = (char *)RFIFOP (fd, 26);
- account.passwd[23] = '\0';
- remove_control_chars (account.passwd);
+ int GM_value, len;
+ char server_name[20];
+ strzcpy(account.userid, static_cast<const char *>(RFIFOP(fd, 2)), 24);
+ remove_control_chars(account.userid);
+ strzcpy(account.passwd, static_cast<const char *>(RFIFOP(fd, 26)), 24);
+ remove_control_chars(account.passwd);
account.passwdenc = 0;
- server_name = (char *)RFIFOP (fd, 60);
- server_name[19] = '\0';
- remove_control_chars (server_name);
- login_log
- ("Connection request of the char-server '%s' @ %d.%d.%d.%d:%d (ip: %s)\n",
- server_name, RFIFOB (fd, 54), RFIFOB (fd, 55),
- RFIFOB (fd, 56), RFIFOB (fd, 57), RFIFOW (fd, 58),
+ strzcpy(server_name, static_cast<const char *>(RFIFOP(fd, 60)), 20);
+ remove_control_chars(server_name);
+ LOGIN_LOG("Connection request of the char-server '%s' @ %d.%d.%d.%d:%d (ip: %s)\n",
+ server_name, RFIFOB(fd, 54), RFIFOB(fd, 55),
+ RFIFOB(fd, 56), RFIFOB(fd, 57), RFIFOW(fd, 58),
ip);
- result = mmo_auth (&account, fd);
+ result = mmo_auth(&account, fd);
if (result == -1 && account.sex == 2)
{
// If this is the main server, and we don't already have a main server
if (server_fd[0] <= 0
- && strcasecmp (server_name, main_server) == 0)
+ && strcasecmp(server_name, main_server) == 0)
{
account.account_id = 0;
}
else
{
- int i;
+ int i;
for (i = 1; i < MAX_SERVERS; i++)
{
if (server_fd[i] <= 0)
@@ -3869,227 +3312,209 @@ void parse_login (int fd)
&& account.account_id < MAX_SERVERS
&& server_fd[account.account_id] == -1)
{
- login_log
- ("Connection of the char-server '%s' accepted (account: %s, pass: %s, ip: %s)\n",
+ LOGIN_LOG("Connection of the char-server '%s' accepted (account: %s, pass: %s, ip: %s)\n",
server_name, account.userid,
account.passwd, ip);
- printf
- ("Connection of the char-server '%s' accepted.\n",
+ 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, 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, server_name,
20);
server[account.account_id].users = 0;
server[account.account_id].maintenance =
- RFIFOW (fd, 82);
- server[account.account_id].is_new = RFIFOW (fd, 84);
+ RFIFOW(fd, 82);
+ server[account.account_id].is_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
- WFIFOW (fd, 0) = 0x2711;
- WFIFOB (fd, 2) = 0;
- WFIFOSET (fd, 3);
+ WFIFOW(fd, 0) = 0x2711;
+ WFIFOB(fd, 2) = 0;
+ WFIFOSET(fd, 3);
session[fd]->func_parse = parse_fromchar;
- realloc_fifo (fd, FIFOSIZE_SERVERLINK,
+ realloc_fifo(fd, FIFOSIZE_SERVERLINK,
FIFOSIZE_SERVERLINK);
// send GM account to char-server
len = 4;
- WFIFOW (fd, 0) = 0x2732;
+ WFIFOW(fd, 0) = 0x2732;
for (int i = 0; i < auth_num; i++)
// send only existing accounts. We can not create a GM account when server is online.
if ((GM_value =
- isGM (auth_dat[i].account_id)) > 0)
+ isGM(auth_dat[i].account_id)) > 0)
{
- WFIFOL (fd, len) = auth_dat[i].account_id;
- WFIFOB (fd, len + 4) =
+ WFIFOL(fd, len) = auth_dat[i].account_id;
+ WFIFOB(fd, len + 4) =
(unsigned char) GM_value;
len += 5;
}
- WFIFOW (fd, 2) = len;
- WFIFOSET (fd, len);
+ WFIFOW(fd, 2) = len;
+ WFIFOSET(fd, len);
}
else
{
- login_log
- ("Connexion of the char-server '%s' REFUSED (account: %s, pass: %s, ip: %s)\n",
+ LOGIN_LOG("Connexion of the char-server '%s' REFUSED (account: %s, pass: %s, ip: %s)\n",
server_name, account.userid,
account.passwd, ip);
- WFIFOW (fd, 0) = 0x2711;
- WFIFOB (fd, 2) = 3;
- WFIFOSET (fd, 3);
+ WFIFOW(fd, 0) = 0x2711;
+ WFIFOB(fd, 2) = 3;
+ WFIFOSET(fd, 3);
}
}
- RFIFOSKIP (fd, 86);
+ RFIFOSKIP(fd, 86);
return;
case 0x7530: // Request of the server version
- login_log ("Sending of the server version (ip: %s)\n",
+ LOGIN_LOG("Sending of the server version (ip: %s)\n",
ip);
- WFIFOW (fd, 0) = 0x7531;
- WFIFOB (fd, 2) = -1;
- WFIFOB (fd, 3) = 'T';
- WFIFOB (fd, 4) = 'M';
- WFIFOB (fd, 5) = 'W';
- WFIFOL (fd, 6) = new_account_flag ? 1 : 0;
- WFIFOSET (fd, 10);
- RFIFOSKIP (fd, 2);
+ WFIFOW(fd, 0) = 0x7531;
+ WFIFOB(fd, 2) = -1;
+ WFIFOB(fd, 3) = 'T';
+ WFIFOB(fd, 4) = 'M';
+ WFIFOB(fd, 5) = 'W';
+ WFIFOL(fd, 6) = new_account_flag ? 1 : 0;
+ WFIFOSET(fd, 10);
+ RFIFOSKIP(fd, 2);
break;
case 0x7532: // Request to end connection
- login_log ("End of connection (ip: %s)\n", ip);
+ LOGIN_LOG("End of connection (ip: %s)\n", ip);
session[fd]->eof = 1;
return;
case 0x7918: // Request for administation login
- if (RFIFOREST (fd) < 4
- || RFIFOREST (fd) < ((RFIFOW (fd, 2) == 0) ? 28 : 20))
+ if (RFIFOREST(fd) < 4
+ || RFIFOREST(fd) < ((RFIFOW(fd, 2) == 0) ? 28 : 20))
return;
- WFIFOW (fd, 0) = 0x7919;
- WFIFOB (fd, 2) = 1;
- if (!check_ladminip
- (session[fd]->client_addr.sin_addr))
+ WFIFOW(fd, 0) = 0x7919;
+ WFIFOB(fd, 2) = 1;
+ if (!check_ladminip(session[fd]->client_addr.sin_addr))
{
- login_log
- ("'ladmin'-login: Connection in administration mode refused: IP isn't authorised (ladmin_allow, ip: %s).\n",
+ LOGIN_LOG("'ladmin'-login: Connection in administration mode refused: IP isn't authorised (ladmin_allow, ip: %s).\n",
ip);
}
else
{
struct login_session_data *ld = (struct login_session_data *)session[fd]->session_data;
- if (RFIFOW (fd, 2) == 0)
+ if (RFIFOW(fd, 2) == 0)
{ // non encrypted password
- char *password;
- password = (char *)RFIFOP (fd, 4);
- password[23] = '\0';
- remove_control_chars (password);
+ char password[24];
+ strzcpy(password, static_cast<const char *>(RFIFOP(fd, 4)), 24);
+ remove_control_chars(password);
// If remote administration is enabled and password sent by client matches password read from login server configuration file
if ((admin_state == 1)
- && (strcmp (password, admin_pass) == 0))
+ && (strcmp(password, admin_pass) == 0))
{
- login_log
- ("'ladmin'-login: Connection in administration mode accepted (non encrypted password: %s, ip: %s)\n",
+ LOGIN_LOG("'ladmin'-login: Connection in administration mode accepted (non encrypted password: %s, ip: %s)\n",
password, ip);
- printf
- ("Connection of a remote administration accepted (non encrypted password).\n");
- WFIFOB (fd, 2) = 0;
+ PRINTF("Connection of a remote administration accepted (non encrypted password).\n");
+ WFIFOB(fd, 2) = 0;
session[fd]->func_parse = parse_admin;
}
else if (admin_state != 1)
- login_log
- ("'ladmin'-login: Connection in administration mode REFUSED - remote administration is disabled (non encrypted password: %s, ip: %s)\n",
+ LOGIN_LOG("'ladmin'-login: Connection in administration mode REFUSED - remote administration is disabled (non encrypted password: %s, ip: %s)\n",
password, ip);
else
- login_log
- ("'ladmin'-login: Connection in administration mode REFUSED - invalid password (non encrypted password: %s, ip: %s)\n",
+ LOGIN_LOG("'ladmin'-login: Connection in administration mode REFUSED - invalid password (non encrypted password: %s, ip: %s)\n",
password, ip);
}
else
{ // encrypted password
if (!ld)
- printf
- ("'ladmin'-login: error! MD5 key not created/requested for an administration login.\n");
+ PRINTF("'ladmin'-login: error! MD5 key not created/requested for an administration login.\n");
else
{
char md5str[64] = "";
uint8_t md5bin[32];
- if (RFIFOW (fd, 2) == 1)
+ if (RFIFOW(fd, 2) == 1)
{
- strncpy (md5str, ld->md5key, sizeof (ld->md5key)); // 20
- strcat (md5str, admin_pass); // 24
+ strncpy(md5str, ld->md5key, sizeof(ld->md5key)); // 20
+ strcat(md5str, admin_pass); // 24
}
- else if (RFIFOW (fd, 2) == 2)
+ else if (RFIFOW(fd, 2) == 2)
{
- strncpy (md5str, admin_pass, sizeof (admin_pass)); // 24
- strcat (md5str, ld->md5key); // 20
+ strncpy(md5str, admin_pass, sizeof(admin_pass)); // 24
+ strcat(md5str, ld->md5key); // 20
}
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))
+ && (memcmp(md5bin, RFIFOP(fd, 4), 16) == 0))
{
- login_log
- ("'ladmin'-login: Connection in administration mode accepted (encrypted password, ip: %s)\n",
+ LOGIN_LOG("'ladmin'-login: Connection in administration mode accepted (encrypted password, ip: %s)\n",
ip);
- printf
- ("Connection of a remote administration accepted (encrypted password).\n");
- WFIFOB (fd, 2) = 0;
+ PRINTF("Connection of a remote administration accepted (encrypted password).\n");
+ WFIFOB(fd, 2) = 0;
session[fd]->func_parse = parse_admin;
}
else if (admin_state != 1)
- login_log
- ("'ladmin'-login: Connection in administration mode REFUSED - remote administration is disabled (encrypted password, ip: %s)\n",
+ LOGIN_LOG("'ladmin'-login: Connection in administration mode REFUSED - remote administration is disabled (encrypted password, ip: %s)\n",
ip);
else
- login_log
- ("'ladmin'-login: Connection in administration mode REFUSED - invalid password (encrypted password, ip: %s)\n",
+ LOGIN_LOG("'ladmin'-login: Connection in administration mode REFUSED - invalid password (encrypted password, ip: %s)\n",
ip);
}
}
}
- WFIFOSET (fd, 3);
- RFIFOSKIP (fd, (RFIFOW (fd, 2) == 0) ? 28 : 20);
+ WFIFOSET(fd, 3);
+ RFIFOSKIP(fd, (RFIFOW(fd, 2) == 0) ? 28 : 20);
break;
default:
if (save_unknown_packets)
{
FILE *logfp;
- char tmpstr[24];
- struct timeval tv;
- logfp = fopen_ (login_log_unknown_packets_filename, "a");
+ logfp = fopen_(login_log_unknown_packets_filename, "a");
if (logfp)
{
- gettimeofday (&tv, NULL);
- strftime (tmpstr, 23, date_format,
- gmtime (&(tv.tv_sec)));
- fprintf (logfp,
- "%s.%03d: receiving of an unknown packet -> disconnection\n",
- tmpstr, (int) tv.tv_usec / 1000);
- fprintf (logfp,
- "parse_login: connection #%d (ip: %s), packet: 0x%x (with being read: %d).\n",
- fd, ip, RFIFOW (fd, 0),
- RFIFOREST (fd));
- fprintf (logfp, "Detail (in hex):\n");
- fprintf (logfp,
+ timestamp_milliseconds_buffer tmpstr;
+ stamp_time(tmpstr);
+ FPRINTF(logfp,
+ "%s: receiving of an unknown packet -> disconnection\n",
+ tmpstr);
+ FPRINTF(logfp,
+ "parse_login: connection #%d (ip: %s), packet: 0x%x (with being read: %zu).\n",
+ fd, ip, RFIFOW(fd, 0),
+ RFIFOREST(fd));
+ FPRINTF(logfp, "Detail (in hex):\n");
+ FPRINTF(logfp,
"---- 00-01-02-03-04-05-06-07 08-09-0A-0B-0C-0D-0E-0F\n");
- memset (tmpstr, '\0', sizeof (tmpstr));
+ memset(tmpstr, '\0', sizeof(tmpstr));
int i;
- for (i = 0; i < RFIFOREST (fd); i++)
+ for (i = 0; i < RFIFOREST(fd); i++)
{
if ((i & 15) == 0)
- fprintf (logfp, "%04X ", i);
- fprintf (logfp, "%02x ", RFIFOB (fd, i));
- if (RFIFOB (fd, i) > 0x1f)
- tmpstr[i % 16] = RFIFOB (fd, i);
+ FPRINTF(logfp, "%04X ", i);
+ FPRINTF(logfp, "%02x ", RFIFOB(fd, i));
+ if (RFIFOB(fd, i) > 0x1f)
+ tmpstr[i % 16] = RFIFOB(fd, i);
else
tmpstr[i % 16] = '.';
if ((i - 7) % 16 == 0) // -8 + 1
- fprintf (logfp, " ");
+ FPRINTF(logfp, " ");
else if ((i + 1) % 16 == 0)
{
- fprintf (logfp, " %s\n", tmpstr);
- memset (tmpstr, '\0', sizeof (tmpstr));
+ FPRINTF(logfp, " %s\n", tmpstr);
+ memset(tmpstr, '\0', sizeof(tmpstr));
}
}
if (i % 16 != 0)
{
for (j = i; j % 16 != 0; j++)
{
- fprintf (logfp, " ");
+ FPRINTF(logfp, " ");
if ((j - 7) % 16 == 0) // -8 + 1
- fprintf (logfp, " ");
+ FPRINTF(logfp, " ");
}
- fprintf (logfp, " %s\n", tmpstr);
+ FPRINTF(logfp, " %s\n", tmpstr);
}
- fprintf (logfp, "\n");
- fclose_ (logfp);
+ FPRINTF(logfp, "\n");
+ fclose_(logfp);
}
}
- login_log ("End of connection, unknown packet (ip: %s)\n", ip);
+ LOGIN_LOG("End of connection, unknown packet (ip: %s)\n", ip);
session[fd]->eof = 1;
return;
}
@@ -4101,51 +3526,44 @@ void parse_login (int fd)
// Reading Lan Support configuration
//----------------------------------
static
-int login_lan_config_read (const char *lancfgName)
+int login_lan_config_read(const char *lancfgName)
{
- int j;
struct hostent *h = NULL;
- char line[1024], w1[1024], w2[1024];
- FILE *fp;
// set default configuration
- strncpy (lan_char_ip, "127.0.0.1", sizeof (lan_char_ip));
+ strncpy(lan_char_ip, "127.0.0.1", sizeof(lan_char_ip));
subneti[0] = 127;
subneti[1] = 0;
subneti[2] = 0;
subneti[3] = 1;
- for (j = 0; j < 4; j++)
+ for (int j = 0; j < 4; j++)
subnetmaski[j] = 255;
- fp = fopen_ (lancfgName, "r");
+ std::ifstream in(lancfgName);
- if (fp == NULL)
+ if (!in.is_open())
{
- printf
- ("***WARNING: LAN Support configuration file is not found: %s\n",
+ PRINTF("***WARNING: LAN Support configuration file is not found: %s\n",
lancfgName);
return 1;
}
- printf ("---Start reading Lan Support configuration file\n");
+ PRINTF("---Start reading Lan Support configuration file\n");
- while (fgets (line, sizeof (line) - 1, fp))
+ std::string line;
+ while (std::getline(in, line))
{
- if (line[0] == '/' && line[1] == '/')
- continue;
-
- line[sizeof (line) - 1] = '\0';
- if (sscanf (line, "%[^:]: %[^\r\n]", w1, w2) != 2)
+ std::string w1, w2;
+ if (!split_key_value(line, &w1, &w2))
continue;
- remove_control_chars (w1);
- remove_control_chars (w2);
- if (strcasecmp (w1, "lan_char_ip") == 0)
- { // Read Char-Server Lan IP Address
- h = gethostbyname (w2);
+ if (w1 == "lan_char_ip")
+ {
+ // Read Char-Server Lan IP Address
+ h = gethostbyname(w2.c_str());
if (h != NULL)
{
- sprintf (lan_char_ip, "%d.%d.%d.%d",
+ sprintf(lan_char_ip, "%d.%d.%d.%d",
(unsigned char) h->h_addr[0],
(unsigned char) h->h_addr[1],
(unsigned char) h->h_addr[2],
@@ -4153,79 +3571,75 @@ int login_lan_config_read (const char *lancfgName)
}
else
{
- strncpy (lan_char_ip, w2, sizeof (lan_char_ip));
- lan_char_ip[sizeof (lan_char_ip) - 1] = '\0';
+ strzcpy(lan_char_ip, w2.c_str(), sizeof(lan_char_ip));
}
- printf ("LAN IP of char-server: %s.\n", lan_char_ip);
+ PRINTF("LAN IP of char-server: %s.\n", lan_char_ip);
}
- else if (strcasecmp (w1, "subnet") == 0)
- { // Read Subnetwork
- for (j = 0; j < 4; j++)
+ else if (w1 == "subnet")
+ {
+ // Read Subnetwork
+ for (int j = 0; j < 4; j++)
subneti[j] = 0;
- h = gethostbyname (w2);
+ h = gethostbyname(w2.c_str());
if (h != NULL)
{
- for (j = 0; j < 4; j++)
+ for (int j = 0; j < 4; j++)
subneti[j] = (unsigned char) h->h_addr[j];
}
else
{
- sscanf (w2, "%d.%d.%d.%d", &subneti[0], &subneti[1],
+ SSCANF(w2, "%d.%d.%d.%d", &subneti[0], &subneti[1],
&subneti[2], &subneti[3]);
}
- printf ("Sub-network of the char-server: %d.%d.%d.%d.\n",
+ PRINTF("Sub-network of the char-server: %d.%d.%d.%d.\n",
subneti[0], subneti[1], subneti[2], subneti[3]);
}
- else if (strcasecmp (w1, "subnetmask") == 0)
+ else if (w1 == "subnetmask")
{ // Read Subnetwork Mask
- for (j = 0; j < 4; j++)
+ for (int j = 0; j < 4; j++)
subnetmaski[j] = 255;
- h = gethostbyname (w2);
+ h = gethostbyname(w2.c_str());
if (h != NULL)
{
- for (j = 0; j < 4; j++)
+ for (int j = 0; j < 4; j++)
subnetmaski[j] = (unsigned char) h->h_addr[j];
}
else
{
- sscanf (w2, "%d.%d.%d.%d", &subnetmaski[0], &subnetmaski[1],
+ SSCANF(w2, "%d.%d.%d.%d", &subnetmaski[0], &subnetmaski[1],
&subnetmaski[2], &subnetmaski[3]);
}
- printf ("Sub-network mask of the char-server: %d.%d.%d.%d.\n",
+ PRINTF("Sub-network mask of the char-server: %d.%d.%d.%d.\n",
subnetmaski[0], subnetmaski[1], subnetmaski[2],
subnetmaski[3]);
}
+ else
+ {
+ PRINTF("WARNING: unknown lan-config key: %s\n", w1);
+ }
}
- fclose_ (fp);
// log the LAN configuration
- login_log ("The LAN configuration of the server is set:\n");
- login_log ("- with LAN IP of char-server: %s.\n", lan_char_ip);
- login_log
- ("- with the sub-network of the char-server: %d.%d.%d.%d/%d.%d.%d.%d.\n",
+ LOGIN_LOG("The LAN configuration of the server is set:\n");
+ LOGIN_LOG("- with LAN IP of char-server: %s.\n", lan_char_ip);
+ LOGIN_LOG("- with the sub-network of the char-server: %d.%d.%d.%d/%d.%d.%d.%d.\n",
subneti[0], subneti[1], subneti[2], subneti[3],
subnetmaski[0], subnetmaski[1], subnetmaski[2], subnetmaski[3]);
// sub-network check of the char-server
{
- 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)
+ sscanf(lan_char_ip, "%hhu.%hhu.%hhu.%hhu",
+ &p[0], &p[1], &p[2], &p[3]);
+ 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");
- login_log
- ("***ERROR: LAN IP of the char-server doesn't belong to the specified Sub-network.\n");
+ PRINTF("\033[1;31m***ERROR: LAN IP of the char-server doesn't belong to the specified Sub-network\033[0m\n");
+ LOGIN_LOG("***ERROR: LAN IP of the char-server doesn't belong to the specified Sub-network.\n");
}
}
- printf ("---End reading of Lan Support configuration file\n");
+ PRINTF("---End reading of Lan Support configuration file\n");
return 0;
}
@@ -4234,284 +3648,239 @@ int login_lan_config_read (const char *lancfgName)
// Reading general configuration file
//-----------------------------------
static
-int login_config_read (const char *cfgName)
+int login_config_read(const char *cfgName)
{
- char line[1024], w1[1024], w2[1024];
- FILE *fp;
-
- fp = fopen_ (cfgName, "r");
- if (fp == NULL)
+ std::ifstream in(cfgName);
+ if (!in.is_open())
{
- printf ("Configuration file (%s) not found.\n", cfgName);
+ PRINTF("Configuration file (%s) not found.\n", cfgName);
return 1;
}
- printf ("---Start reading of Login Server configuration file (%s)\n",
+ PRINTF("---Start reading of Login Server configuration file (%s)\n",
cfgName);
- while (fgets (line, sizeof (line) - 1, fp))
+ std::string line;
+ while (std::getline(in, line))
{
- if (line[0] == '/' && line[1] == '/')
+ std::string w1, w2;
+ if (!split_key_value(line, &w1, &w2))
continue;
- line[sizeof (line) - 1] = '\0';
- if (sscanf (line, "%[^:]: %[^\r\n]", w1, w2) == 2)
+ if (w1 == "admin_state")
{
- remove_control_chars (w1);
- remove_control_chars (w2);
-
- if (strcasecmp (w1, "admin_state") == 0)
- {
- admin_state = config_switch (w2);
- }
- else if (strcasecmp (w1, "admin_pass") == 0)
+ admin_state = config_switch(w2.c_str());
+ }
+ else if (w1 == "admin_pass")
+ {
+ strzcpy(admin_pass, w2.c_str(), sizeof(admin_pass));
+ }
+ else if (w1 == "ladminallowip")
+ {
+ if (w2 == "clear")
{
- strncpy (admin_pass, w2, sizeof (admin_pass));
- admin_pass[sizeof (admin_pass) - 1] = '\0';
+ if (access_ladmin_allow)
+ free(access_ladmin_allow);
+ access_ladmin_allow = NULL;
+ access_ladmin_allownum = 0;
}
- else if (strcasecmp (w1, "ladminallowip") == 0)
+ else
{
- if (strcasecmp (w2, "clear") == 0)
+ if (w2 == "all")
{
+ // reset all previous values
if (access_ladmin_allow)
- free (access_ladmin_allow);
- access_ladmin_allow = NULL;
- access_ladmin_allownum = 0;
- }
- else
- {
- if (strcasecmp (w2, "all") == 0)
- {
- // reset all previous values
- if (access_ladmin_allow)
- free (access_ladmin_allow);
- // set to all
- CREATE (access_ladmin_allow, char, ACO_STRSIZE);
- access_ladmin_allownum = 1;
- }
- else if (w2[0]
- && !(access_ladmin_allownum == 1
- && access_ladmin_allow[0] == '\0'))
- { // don't add IP if already 'all'
- if (access_ladmin_allow)
- RECREATE (access_ladmin_allow, char, (access_ladmin_allownum + 1) * ACO_STRSIZE);
- else
- CREATE (access_ladmin_allow, char, ACO_STRSIZE);
- strncpy (access_ladmin_allow +
- (access_ladmin_allownum++) * ACO_STRSIZE, w2,
- ACO_STRSIZE);
- access_ladmin_allow[access_ladmin_allownum *
- ACO_STRSIZE - 1] = '\0';
- }
+ free(access_ladmin_allow);
+ // set to all
+ CREATE(access_ladmin_allow, char, ACO_STRSIZE);
+ access_ladmin_allownum = 1;
}
- }
- else if (strcasecmp (w1, "gm_pass") == 0)
- {
- strncpy (gm_pass, w2, sizeof (gm_pass));
- gm_pass[sizeof (gm_pass) - 1] = '\0';
- }
- else if (strcasecmp (w1, "level_new_gm") == 0)
- {
- level_new_gm = atoi (w2);
- }
- else if (strcasecmp (w1, "new_account") == 0)
- {
- new_account_flag = config_switch (w2);
- }
- else if (strcasecmp (w1, "login_port") == 0)
- {
- login_port = atoi (w2);
- }
- else if (strcasecmp (w1, "account_filename") == 0)
- {
- strncpy (account_filename, w2, sizeof (account_filename));
- account_filename[sizeof (account_filename) - 1] = '\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 (strcasecmp (w1, "gm_account_filename_check_timer") == 0)
- {
- gm_account_filename_check_timer = atoi (w2);
- }
- 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 (strcasecmp (w1, "login_log_unknown_packets_filename") == 0)
- {
- strncpy (login_log_unknown_packets_filename, w2,
- sizeof (login_log_unknown_packets_filename));
- login_log_unknown_packets_filename[sizeof
- (login_log_unknown_packets_filename)
- - 1] = '\0';
- }
- else if (strcasecmp (w1, "save_unknown_packets") == 0)
- {
- save_unknown_packets = config_switch (w2);
- }
- else if (strcasecmp (w1, "display_parse_login") == 0)
- {
- display_parse_login = config_switch (w2); // 0: no, 1: yes
- }
- else if (strcasecmp (w1, "display_parse_admin") == 0)
- {
- display_parse_admin = config_switch (w2); // 0: no, 1: yes
- }
- 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 (strcasecmp (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 (w2[0]
+ && !(access_ladmin_allownum == 1
+ && access_ladmin_allow[0] == '\0'))
+ { // don't add IP if already 'all'
+ if (access_ladmin_allow)
+ RECREATE(access_ladmin_allow, char, (access_ladmin_allownum + 1) * ACO_STRSIZE);
+ else
+ CREATE(access_ladmin_allow, char, ACO_STRSIZE);
+ strzcpy(access_ladmin_allow + (access_ladmin_allownum++) * ACO_STRSIZE,
+ w2.c_str(), ACO_STRSIZE);
}
}
- else if (strcasecmp (w1, "min_level_to_connect") == 0)
- {
- min_level_to_connect = atoi (w2);
- }
- else if (strcasecmp (w1, "add_to_unlimited_account") == 0)
- {
- add_to_unlimited_account = config_switch (w2);
- }
- else if (strcasecmp (w1, "start_limited_time") == 0)
- {
- start_limited_time = atoi (w2);
- }
- else if (strcasecmp (w1, "check_ip_flag") == 0)
- {
- check_ip_flag = config_switch (w2);
- }
- else if (strcasecmp (w1, "order") == 0)
+ }
+ else if (w1 == "gm_pass")
+ {
+ strzcpy(gm_pass, w2.c_str(), sizeof(gm_pass));
+ }
+ else if (w1 == "level_new_gm")
+ {
+ level_new_gm = atoi(w2.c_str());
+ }
+ else if (w1 == "new_account")
+ {
+ new_account_flag = config_switch(w2.c_str());
+ }
+ else if (w1 == "login_port")
+ {
+ login_port = atoi(w2.c_str());
+ }
+ else if (w1 == "account_filename")
+ {
+ strzcpy(account_filename, w2.c_str(), sizeof(account_filename));
+ }
+ else if (w1 == "gm_account_filename")
+ {
+ strzcpy(GM_account_filename, w2.c_str(), sizeof(GM_account_filename));
+ }
+ else if (w1 == "gm_account_filename_check_timer")
+ {
+ gm_account_filename_check_timer = std::chrono::seconds(atoi(w2.c_str()));
+ }
+ else if (w1 == "login_log_filename")
+ {
+ strzcpy(login_log_filename, w2.c_str(), sizeof(login_log_filename));
+ }
+ else if (w1 == "login_log_unknown_packets_filename")
+ {
+ strzcpy(login_log_unknown_packets_filename, w2.c_str(),
+ sizeof(login_log_unknown_packets_filename));
+ }
+ else if (w1 == "save_unknown_packets")
+ {
+ save_unknown_packets = config_switch(w2.c_str());
+ }
+ else if (w1 == "display_parse_login")
+ {
+ display_parse_login = config_switch(w2.c_str()); // 0: no, 1: yes
+ }
+ else if (w1 == "display_parse_admin")
+ {
+ display_parse_admin = config_switch(w2.c_str()); // 0: no, 1: yes
+ }
+ else if (w1 == "display_parse_fromchar")
+ {
+ display_parse_fromchar = config_switch(w2.c_str()); // 0: no, 1: yes (without packet 0x2714), 2: all packets
+ }
+ else if (w1 == "min_level_to_connect")
+ {
+ min_level_to_connect = atoi(w2.c_str());
+ }
+ else if (w1 == "add_to_unlimited_account")
+ {
+ add_to_unlimited_account = config_switch(w2.c_str());
+ }
+ else if (w1 == "start_limited_time")
+ {
+ start_limited_time = atoi(w2.c_str());
+ }
+ else if (w1 == "check_ip_flag")
+ {
+ check_ip_flag = config_switch(w2.c_str());
+ }
+ else if (w1 == "order")
+ {
+ access_order = atoi(w2.c_str());
+ if (w2 == "deny,allow" || w2 == "deny, allow")
+ access_order = ACO_DENY_ALLOW;
+ if (w2 == "allow,deny" || w2 == "allow, deny")
+ access_order = ACO_ALLOW_DENY;
+ if (w2 == "mutual-failture" || w2 == "mutual-failure")
+ access_order = ACO_MUTUAL_FAILTURE;
+ }
+ else if (w1 == "allow")
+ {
+ if (w2 == "clear")
{
- access_order = atoi (w2);
- if (strcasecmp (w2, "deny,allow") == 0 ||
- strcasecmp (w2, "deny, allow") == 0)
- access_order = ACO_DENY_ALLOW;
- if (strcasecmp (w2, "allow,deny") == 0 ||
- strcasecmp (w2, "allow, deny") == 0)
- access_order = ACO_ALLOW_DENY;
- if (strcasecmp (w2, "mutual-failture") == 0 ||
- strcasecmp (w2, "mutual-failure") == 0)
- access_order = ACO_MUTUAL_FAILTURE;
+ if (access_allow)
+ free(access_allow);
+ access_allow = NULL;
+ access_allownum = 0;
}
- else if (strcasecmp (w1, "allow") == 0)
+ else
{
- if (strcasecmp (w2, "clear") == 0)
+ if (w2 == "all")
{
+ // reset all previous values
if (access_allow)
- free (access_allow);
- access_allow = NULL;
- access_allownum = 0;
+ free(access_allow);
+ // set to all
+ CREATE(access_allow, char, ACO_STRSIZE);
+ access_allownum = 1;
}
- else
- {
- if (strcasecmp (w2, "all") == 0)
- {
- // reset all previous values
- if (access_allow)
- free (access_allow);
- // set to all
- CREATE (access_allow, char, ACO_STRSIZE);
- access_allownum = 1;
- }
- else if (w2[0]
- && !(access_allownum == 1
- && access_allow[0] == '\0'))
- { // don't add IP if already 'all'
- if (access_allow)
- RECREATE (access_allow, char, (access_allownum + 1) * ACO_STRSIZE);
- else
- CREATE (access_allow, char, ACO_STRSIZE);
- strncpy (access_allow +
- (access_allownum++) * ACO_STRSIZE, w2,
- ACO_STRSIZE);
- access_allow[access_allownum * ACO_STRSIZE - 1] =
- '\0';
- }
+ else if (w2[0]
+ && !(access_allownum == 1
+ && access_allow[0] == '\0'))
+ { // don't add IP if already 'all'
+ if (access_allow)
+ RECREATE(access_allow, char, (access_allownum + 1) * ACO_STRSIZE);
+ else
+ CREATE(access_allow, char, ACO_STRSIZE);
+ strzcpy(access_allow + (access_allownum++) * ACO_STRSIZE,
+ w2.c_str(), ACO_STRSIZE);
}
}
- else if (strcasecmp (w1, "deny") == 0)
+ }
+ else if (w1 == "deny")
+ {
+ if (w2 == "clear")
+ {
+ if (access_deny)
+ free(access_deny);
+ access_deny = NULL;
+ access_denynum = 0;
+ }
+ else
{
- if (strcasecmp (w2, "clear") == 0)
+ if (w2 == "all")
{
+ // reset all previous values
if (access_deny)
- free (access_deny);
- access_deny = NULL;
- access_denynum = 0;
+ free(access_deny);
+ // set to all
+ CREATE(access_deny, char, ACO_STRSIZE);
+ access_denynum = 1;
}
- else
- {
- if (strcasecmp (w2, "all") == 0)
- {
- // reset all previous values
- if (access_deny)
- free (access_deny);
- // set to all
- CREATE (access_deny, char, ACO_STRSIZE);
- access_denynum = 1;
- }
- else if (w2[0]
- && !(access_denynum == 1
- && access_deny[0] == '\0'))
- { // don't add IP if already 'all'
- if (access_deny)
- RECREATE (access_deny, char, (access_denynum + 1) * ACO_STRSIZE);
- else
- CREATE (access_deny, char, ACO_STRSIZE);
- strncpy (access_deny +
- (access_denynum++) * ACO_STRSIZE, w2,
- ACO_STRSIZE);
- access_deny[access_denynum * ACO_STRSIZE - 1] = '\0';
- }
+ else if (!w2.empty()
+ && !(access_denynum == 1
+ && access_deny[0] == '\0'))
+ { // don't add IP if already 'all'
+ if (access_deny)
+ RECREATE(access_deny, char, (access_denynum + 1) * ACO_STRSIZE);
+ else
+ CREATE(access_deny, char, ACO_STRSIZE);
+ strzcpy(access_deny + (access_denynum++) * ACO_STRSIZE,
+ w2.c_str(), ACO_STRSIZE);
}
}
- else if (strcasecmp (w1, "anti_freeze_enable") == 0)
- {
- anti_freeze_enable = config_switch (w2);
- }
- 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 (strcasecmp (w1, "import") == 0)
- {
- login_config_read (w2);
- }
- else if (strcasecmp (w1, "update_host") == 0)
- {
- strncpy (update_host, w2, sizeof (update_host));
- update_host[sizeof (update_host) - 1] = '\0';
- }
- else if (strcasecmp (w1, "main_server") == 0)
- {
- strncpy (main_server, w2, sizeof (main_server));
- main_server[sizeof (main_server) - 1] = '\0';
- }
+ }
+ else if (w1 == "anti_freeze_enable")
+ {
+ anti_freeze_enable = config_switch(w2.c_str());
+ }
+ else if (w1 == "anti_freeze_interval")
+ {
+ ANTI_FREEZE_INTERVAL = std::max(
+ std::chrono::seconds(atoi(w2.c_str())),
+ std::chrono::seconds(5));
+ }
+ else if (w1 == "import")
+ {
+ login_config_read(w2.c_str());
+ }
+ else if (w1 == "update_host")
+ {
+ strzcpy(update_host, w2.c_str(), sizeof(update_host));
+ }
+ else if (w1 == "main_server")
+ {
+ strzcpy(main_server, w2.c_str(), sizeof(main_server));
+ }
+ else
+ {
+ PRINTF("WARNING: unknown login config key: %s\n", w1);
}
}
- fclose_ (fp);
- printf ("---End reading of Login Server configuration file.\n");
+ PRINTF("---End reading of Login Server configuration file.\n");
return 0;
}
@@ -4520,12 +3889,11 @@ int login_config_read (const char *cfgName)
// Displaying of configuration warnings
//-------------------------------------
static
-void display_conf_warnings (void)
+void display_conf_warnings(void)
{
if (admin_state != 0 && admin_state != 1)
{
- printf
- ("***WARNING: Invalid value for admin_state parameter -> set to 0 (no remote admin).\n");
+ PRINTF("***WARNING: Invalid value for admin_state parameter -> set to 0 (no remote admin).\n");
admin_state = 0;
}
@@ -4533,137 +3901,117 @@ void display_conf_warnings (void)
{
if (admin_pass[0] == '\0')
{
- printf
- ("***WARNING: Administrator password is void (admin_pass).\n");
+ PRINTF("***WARNING: Administrator password is void (admin_pass).\n");
}
- else if (strcmp (admin_pass, "admin") == 0)
+ else if (strcmp(admin_pass, "admin") == 0)
{
- printf
- ("***WARNING: You are using the default administrator password (admin_pass).\n");
- printf (" We highly recommend that you change it.\n");
+ PRINTF("***WARNING: You are using the default administrator password (admin_pass).\n");
+ PRINTF(" We highly recommend that you change it.\n");
}
}
if (gm_pass[0] == '\0')
{
- printf ("***WARNING: 'To GM become' password is void (gm_pass).\n");
- printf
- (" We highly recommend that you set one password.\n");
+ PRINTF("***WARNING: 'To GM become' password is void (gm_pass).\n");
+ PRINTF(" We highly recommend that you set one password.\n");
}
- else if (strcmp (gm_pass, "gm") == 0)
+ else if (strcmp(gm_pass, "gm") == 0)
{
- printf
- ("***WARNING: You are using the default GM password (gm_pass).\n");
- printf (" We highly recommend that you change it.\n");
+ PRINTF("***WARNING: You are using the default GM password (gm_pass).\n");
+ PRINTF(" We highly recommend that you change it.\n");
}
if (level_new_gm < 0 || level_new_gm > 99)
{
- printf
- ("***WARNING: Invalid value for level_new_gm parameter -> set to 60 (default).\n");
+ PRINTF("***WARNING: Invalid value for level_new_gm parameter -> set to 60 (default).\n");
level_new_gm = 60;
}
if (new_account_flag != 0 && new_account_flag != 1)
{
- printf
- ("***WARNING: Invalid value for new_account parameter -> set to 0 (no new account).\n");
+ PRINTF("***WARNING: Invalid value for new_account parameter -> set to 0 (no new account).\n");
new_account_flag = 0;
}
if (login_port < 1024 || login_port > 65535)
{
- printf
- ("***WARNING: Invalid value for login_port parameter -> set to 6900 (default).\n");
+ PRINTF("***WARNING: Invalid value for login_port parameter -> set to 6900 (default).\n");
login_port = 6900;
}
- if (gm_account_filename_check_timer < 0)
+ if (gm_account_filename_check_timer.count() < 0)
{
- printf
- ("***WARNING: Invalid value for gm_account_filename_check_timer parameter.\n");
- printf (" -> set to 15 sec (default).\n");
- gm_account_filename_check_timer = 15;
+ PRINTF("***WARNING: Invalid value for gm_account_filename_check_timer parameter.\n");
+ PRINTF(" -> set to 15 sec (default).\n");
+ gm_account_filename_check_timer = std::chrono::seconds(15);
}
- else if (gm_account_filename_check_timer == 1)
+ else if (gm_account_filename_check_timer == std::chrono::seconds(1))
{
- printf
- ("***WARNING: Invalid value for gm_account_filename_check_timer parameter.\n");
- printf (" -> set to 2 sec (minimum value).\n");
- gm_account_filename_check_timer = 2;
+ PRINTF("***WARNING: Invalid value for gm_account_filename_check_timer parameter.\n");
+ PRINTF(" -> set to 2 sec (minimum value).\n");
+ gm_account_filename_check_timer = std::chrono::seconds(2);
}
if (save_unknown_packets != 0 && save_unknown_packets != 1)
{
- printf
- ("WARNING: Invalid value for save_unknown_packets parameter -> set to 0-no save.\n");
+ PRINTF("WARNING: Invalid value for save_unknown_packets parameter -> set to 0-no save.\n");
save_unknown_packets = 0;
}
if (display_parse_login != 0 && display_parse_login != 1)
{ // 0: no, 1: yes
- printf
- ("***WARNING: Invalid value for display_parse_login parameter\n");
- printf (" -> set to 0 (no display).\n");
+ PRINTF("***WARNING: Invalid value for display_parse_login parameter\n");
+ PRINTF(" -> set to 0 (no display).\n");
display_parse_login = 0;
}
if (display_parse_admin != 0 && display_parse_admin != 1)
{ // 0: no, 1: yes
- printf
- ("***WARNING: Invalid value for display_parse_admin parameter\n");
- printf (" -> set to 0 (no display).\n");
+ PRINTF("***WARNING: Invalid value for display_parse_admin parameter\n");
+ PRINTF(" -> set to 0 (no display).\n");
display_parse_admin = 0;
}
if (display_parse_fromchar < 0 || display_parse_fromchar > 2)
{ // 0: no, 1: yes (without packet 0x2714), 2: all packets
- printf
- ("***WARNING: Invalid value for display_parse_fromchar parameter\n");
- printf (" -> set to 0 (no display).\n");
+ PRINTF("***WARNING: Invalid value for display_parse_fromchar parameter\n");
+ PRINTF(" -> set to 0 (no display).\n");
display_parse_fromchar = 0;
}
if (min_level_to_connect < 0)
{ // 0: all players, 1-99 at least gm level x
- printf
- ("***WARNING: Invalid value for min_level_to_connect (%d) parameter\n",
+ PRINTF("***WARNING: Invalid value for min_level_to_connect (%d) parameter\n",
min_level_to_connect);
- printf (" -> set to 0 (any player).\n");
+ PRINTF(" -> set to 0 (any player).\n");
min_level_to_connect = 0;
}
else if (min_level_to_connect > 99)
{ // 0: all players, 1-99 at least gm level x
- printf
- ("***WARNING: Invalid value for min_level_to_connect (%d) parameter\n",
+ PRINTF("***WARNING: Invalid value for min_level_to_connect (%d) parameter\n",
min_level_to_connect);
- printf (" -> set to 99 (only GM level 99).\n");
+ PRINTF(" -> set to 99 (only GM level 99).\n");
min_level_to_connect = 99;
}
if (add_to_unlimited_account != 0 && add_to_unlimited_account != 1)
{ // 0: no, 1: yes
- printf
- ("***WARNING: Invalid value for add_to_unlimited_account parameter\n");
- printf
- (" -> set to 0 (impossible to add a time to an unlimited account).\n");
+ PRINTF("***WARNING: Invalid value for add_to_unlimited_account parameter\n");
+ PRINTF(" -> set to 0 (impossible to add a time to an unlimited account).\n");
add_to_unlimited_account = 0;
}
if (start_limited_time < -1)
{ // -1: create unlimited account, 0 or more: additionnal sec from now to create limited time
- printf
- ("***WARNING: Invalid value for start_limited_time parameter\n");
- printf
- (" -> set to -1 (new accounts are created with unlimited time).\n");
+ PRINTF("***WARNING: Invalid value for start_limited_time parameter\n");
+ PRINTF(" -> set to -1 (new accounts are created with unlimited time).\n");
start_limited_time = -1;
}
if (check_ip_flag != 0 && check_ip_flag != 1)
{ // 0: no, 1: yes
- printf ("***WARNING: Invalid value for check_ip_flag parameter\n");
- printf
- (" -> set to 1 (check players ip between login-server & char-server).\n");
+ PRINTF("***WARNING: Invalid value for check_ip_flag parameter\n");
+ PRINTF(" -> set to 1 (check players ip between login-server & char-server).\n");
check_ip_flag = 1;
}
@@ -4671,36 +4019,31 @@ void display_conf_warnings (void)
{
if (access_denynum == 1 && access_deny[0] == '\0')
{
- printf
- ("***WARNING: The IP security order is 'deny,allow' (allow if not deny).\n");
- printf (" And you refuse ALL IP.\n");
+ PRINTF("***WARNING: The IP security order is 'deny,allow' (allow if not deny).\n");
+ PRINTF(" And you refuse ALL IP.\n");
}
}
else if (access_order == ACO_ALLOW_DENY)
{
if (access_allownum == 0)
{
- printf
- ("***WARNING: The IP security order is 'allow,deny' (deny if not allow).\n");
- printf (" But, NO IP IS AUTHORISED!\n");
+ PRINTF("***WARNING: The IP security order is 'allow,deny' (deny if not allow).\n");
+ PRINTF(" But, NO IP IS AUTHORISED!\n");
}
}
else
{ // ACO_MUTUAL_FAILTURE
if (access_allownum == 0)
{
- printf
- ("***WARNING: The IP security order is 'mutual-failture'\n");
- printf
- (" (allow if in the allow list and not in the deny list).\n");
- printf (" But, NO IP IS AUTHORISED!\n");
+ PRINTF("***WARNING: The IP security order is 'mutual-failture'\n");
+ PRINTF(" (allow if in the allow list and not in the deny list).\n");
+ PRINTF(" But, NO IP IS AUTHORISED!\n");
}
else if (access_denynum == 1 && access_deny[0] == '\0')
{
- printf ("***WARNING: The IP security order is mutual-failture\n");
- printf
- (" (allow if in the allow list and not in the deny list).\n");
- printf (" But, you refuse ALL IP!\n");
+ PRINTF("***WARNING: The IP security order is mutual-failture\n");
+ PRINTF(" (allow if in the allow list and not in the deny list).\n");
+ PRINTF(" But, you refuse ALL IP!\n");
}
}
@@ -4711,195 +4054,178 @@ void display_conf_warnings (void)
// Save configuration in log file
//-------------------------------
static
-void save_config_in_log (void)
+void save_config_in_log(void)
{
- int i;
+ int i;
// a newline in the log...
- login_log ("");
- login_log ("The login-server starting...\n");
+ LOGIN_LOG("");
+ LOGIN_LOG("The login-server starting...\n");
// save configuration in log file
- login_log ("The configuration of the server is set:\n");
+ LOGIN_LOG("The configuration of the server is set:\n");
if (admin_state != 1)
- login_log ("- with no remote administration.\n");
+ LOGIN_LOG("- with no remote administration.\n");
else if (admin_pass[0] == '\0')
- login_log ("- with a remote administration with a VOID password.\n");
- else if (strcmp (admin_pass, "admin") == 0)
- login_log ("- with a remote administration with the DEFAULT password.\n");
+ LOGIN_LOG("- with a remote administration with a VOID password.\n");
+ else if (strcmp(admin_pass, "admin") == 0)
+ LOGIN_LOG("- with a remote administration with the DEFAULT password.\n");
else
- login_log
- ("- with a remote administration with the password of %d character(s).\n",
- strlen (admin_pass));
+ LOGIN_LOG("- with a remote administration with the password of %zu character(s).\n",
+ strlen(admin_pass));
if (access_ladmin_allownum == 0
|| (access_ladmin_allownum == 1 && access_ladmin_allow[0] == '\0'))
{
- login_log ("- to accept any IP for remote administration\n");
+ LOGIN_LOG("- to accept any IP for remote administration\n");
}
else
{
- login_log ("- to accept following IP for remote administration:\n");
+ LOGIN_LOG("- to accept following IP for remote administration:\n");
for (i = 0; i < access_ladmin_allownum; i++)
- login_log (" %s\n",
- (char *) (access_ladmin_allow + i * ACO_STRSIZE));
+ LOGIN_LOG(" %s\n",
+ access_ladmin_allow + i * ACO_STRSIZE);
}
if (gm_pass[0] == '\0')
- login_log ("- with a VOID 'To GM become' password (gm_pass).\n");
- else if (strcmp (gm_pass, "gm") == 0)
- login_log ("- with the DEFAULT 'To GM become' password (gm_pass).\n");
+ LOGIN_LOG("- with a VOID 'To GM become' password (gm_pass).\n");
+ else if (strcmp(gm_pass, "gm") == 0)
+ LOGIN_LOG("- with the DEFAULT 'To GM become' password (gm_pass).\n");
else
- login_log
- ("- with a 'To GM become' password (gm_pass) of %d character(s).\n",
- strlen (gm_pass));
+ LOGIN_LOG("- with a 'To GM become' password (gm_pass) of %zu character(s).\n",
+ strlen(gm_pass));
if (level_new_gm == 0)
- login_log ("- to refuse any creation of GM with @gm.\n");
+ LOGIN_LOG("- to refuse any creation of GM with @gm.\n");
else
- login_log ("- to create GM with level '%d' when @gm is used.\n",
+ LOGIN_LOG("- to create GM with level '%d' when @gm is used.\n",
level_new_gm);
if (new_account_flag == 1)
- login_log ("- to ALLOW new users (with _F/_M).\n");
+ LOGIN_LOG("- to ALLOW new users (with _F/_M).\n");
else
- login_log ("- to NOT ALLOW new users (with _F/_M).\n");
- login_log ("- with port: %d.\n", login_port);
- login_log ("- with the accounts file name: '%s'.\n",
+ LOGIN_LOG("- to NOT ALLOW new users (with _F/_M).\n");
+ LOGIN_LOG("- with port: %d.\n", login_port);
+ LOGIN_LOG("- with the accounts file name: '%s'.\n",
account_filename);
- login_log ("- with the GM accounts file name: '%s'.\n",
+ LOGIN_LOG("- with the GM accounts file name: '%s'.\n",
GM_account_filename);
- if (gm_account_filename_check_timer == 0)
- login_log ("- to NOT check GM accounts file modifications.\n");
+ if (gm_account_filename_check_timer == interval_t::zero())
+ LOGIN_LOG("- to NOT check GM accounts file modifications.\n");
else
- login_log
- ("- to check GM accounts file modifications every %d seconds.\n",
- gm_account_filename_check_timer);
+ LOGIN_LOG("- to check GM accounts file modifications every %d seconds.\n",
+ (int)gm_account_filename_check_timer.count());
// not necessary to log the 'login_log_filename', we are inside :)
- login_log ("- with the unknown packets file name: '%s'.\n",
+ LOGIN_LOG("- with the unknown packets file name: '%s'.\n",
login_log_unknown_packets_filename);
if (save_unknown_packets)
- login_log ("- to SAVE all unkown packets.\n");
+ LOGIN_LOG("- to SAVE all unkown packets.\n");
else
- login_log
- ("- to SAVE only unkown packets sending by a char-server or a remote administration.\n");
+ LOGIN_LOG("- to SAVE only unkown packets sending by a char-server or a remote administration.\n");
if (display_parse_login)
- login_log ("- to display normal parse packets on console.\n");
+ LOGIN_LOG("- to display normal parse packets on console.\n");
else
- login_log ("- to NOT display normal parse packets on console.\n");
+ LOGIN_LOG("- to NOT display normal parse packets on console.\n");
if (display_parse_admin)
- login_log ("- to display administration parse packets on console.\n");
+ LOGIN_LOG("- to display administration parse packets on console.\n");
else
- login_log ("- to NOT display administration parse packets on console.\n");
+ LOGIN_LOG("- to NOT display administration parse packets on console.\n");
if (display_parse_fromchar)
- login_log ("- to display char-server parse packets on console.\n");
+ LOGIN_LOG("- to display char-server parse packets on console.\n");
else
- login_log ("- to NOT display char-server parse packets on console.\n");
+ LOGIN_LOG("- to NOT display char-server parse packets on console.\n");
if (min_level_to_connect == 0) // 0: all players, 1-99 at least gm level x
- login_log ("- with no minimum level for connection.\n");
+ LOGIN_LOG("- with no minimum level for connection.\n");
else if (min_level_to_connect == 99)
- login_log ("- to accept only GM with level 99.\n");
+ LOGIN_LOG("- to accept only GM with level 99.\n");
else
- login_log ("- to accept only GM with level %d or more.\n",
+ LOGIN_LOG("- to accept only GM with level %d or more.\n",
min_level_to_connect);
if (add_to_unlimited_account)
- login_log
- ("- to authorize adjustment (with timeadd ladmin) on an unlimited account.\n");
+ LOGIN_LOG("- to authorize adjustment (with timeadd ladmin) on an unlimited account.\n");
else
- login_log
- ("- to refuse adjustment (with timeadd ladmin) on an unlimited account. You must use timeset (ladmin command) before.\n");
+ LOGIN_LOG("- to refuse adjustment (with timeadd ladmin) on an unlimited account. You must use timeset (ladmin command) before.\n");
if (start_limited_time < 0)
- login_log ("- to create new accounts with an unlimited time.\n");
+ LOGIN_LOG("- to create new accounts with an unlimited time.\n");
else if (start_limited_time == 0)
- login_log
- ("- to create new accounts with a limited time: time of creation.\n");
+ LOGIN_LOG("- to create new accounts with a limited time: time of creation.\n");
else
- login_log
- ("- to create new accounts with a limited time: time of creation + %d second(s).\n",
+ LOGIN_LOG("- to create new accounts with a limited time: time of creation + %d second(s).\n",
start_limited_time);
if (check_ip_flag)
- login_log
- ("- with control of players IP between login-server and char-server.\n");
+ LOGIN_LOG("- with control of players IP between login-server and char-server.\n");
else
- login_log
- ("- to not check players IP between login-server and char-server.\n");
+ LOGIN_LOG("- to not check players IP between login-server and char-server.\n");
if (access_order == ACO_DENY_ALLOW)
{
if (access_denynum == 0)
{
- login_log
- ("- with the IP security order: 'deny,allow' (allow if not deny). You refuse no IP.\n");
+ LOGIN_LOG("- with the IP security order: 'deny,allow' (allow if not deny). You refuse no IP.\n");
}
else if (access_denynum == 1 && access_deny[0] == '\0')
{
- login_log
- ("- with the IP security order: 'deny,allow' (allow if not deny). You refuse ALL IP.\n");
+ LOGIN_LOG("- with the IP security order: 'deny,allow' (allow if not deny). You refuse ALL IP.\n");
}
else
{
- login_log
- ("- with the IP security order: 'deny,allow' (allow if not deny). Refused IP are:\n");
+ LOGIN_LOG("- with the IP security order: 'deny,allow' (allow if not deny). Refused IP are:\n");
for (i = 0; i < access_denynum; i++)
- login_log (" %s\n",
- (char *) (access_deny + i * ACO_STRSIZE));
+ LOGIN_LOG(" %s\n",
+ access_deny + i * ACO_STRSIZE);
}
}
else if (access_order == ACO_ALLOW_DENY)
{
if (access_allownum == 0)
{
- login_log
- ("- with the IP security order: 'allow,deny' (deny if not allow). But, NO IP IS AUTHORISED!\n");
+ LOGIN_LOG("- with the IP security order: 'allow,deny' (deny if not allow). But, NO IP IS AUTHORISED!\n");
}
else if (access_allownum == 1 && access_allow[0] == '\0')
{
- login_log
- ("- with the IP security order: 'allow,deny' (deny if not allow). You authorise ALL IP.\n");
+ LOGIN_LOG("- with the IP security order: 'allow,deny' (deny if not allow). You authorise ALL IP.\n");
}
else
{
- login_log
- ("- with the IP security order: 'allow,deny' (deny if not allow). Authorised IP are:\n");
+ LOGIN_LOG("- with the IP security order: 'allow,deny' (deny if not allow). Authorised IP are:\n");
for (i = 0; i < access_allownum; i++)
- login_log (" %s\n",
- (char *) (access_allow + i * ACO_STRSIZE));
+ LOGIN_LOG(" %s\n",
+ access_allow + i * ACO_STRSIZE);
}
}
else
{ // ACO_MUTUAL_FAILTURE
- login_log
- ("- with the IP security order: 'mutual-failture' (allow if in the allow list and not in the deny list).\n");
+ LOGIN_LOG("- with the IP security order: 'mutual-failture' (allow if in the allow list and not in the deny list).\n");
if (access_allownum == 0)
{
- login_log (" But, NO IP IS AUTHORISED!\n");
+ LOGIN_LOG(" But, NO IP IS AUTHORISED!\n");
}
else if (access_denynum == 1 && access_deny[0] == '\0')
{
- login_log (" But, you refuse ALL IP!\n");
+ LOGIN_LOG(" But, you refuse ALL IP!\n");
}
else
{
if (access_allownum == 1 && access_allow[0] == '\0')
{
- login_log (" You authorise ALL IP.\n");
+ LOGIN_LOG(" You authorise ALL IP.\n");
}
else
{
- login_log (" Authorised IP are:\n");
+ LOGIN_LOG(" Authorised IP are:\n");
for (i = 0; i < access_allownum; i++)
- login_log (" %s\n",
- (char *) (access_allow + i * ACO_STRSIZE));
+ LOGIN_LOG(" %s\n",
+ access_allow + i * ACO_STRSIZE);
}
- login_log (" Refused IP are:\n");
+ LOGIN_LOG(" Refused IP are:\n");
for (i = 0; i < access_denynum; i++)
- login_log (" %s\n",
- (char *) (access_deny + i * ACO_STRSIZE));
+ LOGIN_LOG(" %s\n",
+ access_deny + i * ACO_STRSIZE);
}
}
}
@@ -4907,76 +4233,72 @@ void save_config_in_log (void)
//--------------------------------------
// Function called at exit of the server
//--------------------------------------
-void term_func (void)
+void term_func(void)
{
- int i, fd;
+ int i, fd;
- mmo_auth_sync ();
+ mmo_auth_sync();
- free (auth_dat);
- free (gm_account_db);
+ free(auth_dat);
+ gm_account_db.clear();
for (i = 0; i < MAX_SERVERS; i++)
{
if ((fd = server_fd[i]) >= 0)
- delete_session (fd);
+ delete_session(fd);
}
- delete_session (login_fd);
+ delete_session(login_fd);
- login_log
- ("----End of login-server (normal end with closing of all files).\n");
+ LOGIN_LOG("----End of login-server (normal end with closing of all files).\n");
}
//------------------------------
// Main function of login-server
//------------------------------
-int do_init (int argc, char **argv)
+int do_init(int argc, char **argv)
{
- int i, j;
-
// read login-server configuration
- login_config_read ((argc > 1) ? argv[1] : LOGIN_CONF_NAME);
- display_conf_warnings (); // not in login_config_read, because we can use 'import' option, and display same message twice or more
- save_config_in_log (); // not before, because log file name can be changed
- login_lan_config_read ((argc > 1) ? argv[1] : LAN_CONF_NAME);
+ login_config_read((argc > 1) ? argv[1] : LOGIN_CONF_NAME);
+ display_conf_warnings(); // not in login_config_read, because we can use 'import' option, and display same message twice or more
+ save_config_in_log(); // not before, because log file name can be changed
+ login_lan_config_read((argc > 1) ? argv[1] : LAN_CONF_NAME);
- for (i = 0; i < AUTH_FIFO_SIZE; i++)
+ for (int i = 0; i < AUTH_FIFO_SIZE; i++)
auth_fifo[i].delflag = 1;
- for (i = 0; i < MAX_SERVERS; i++)
+ for (int i = 0; i < MAX_SERVERS; i++)
server_fd[i] = -1;
- gm_account_db = numdb_init ();
-
- read_gm_account ();
- mmo_auth_init ();
+ read_gm_account();
+ mmo_auth_init();
// set_termfunc (mmo_auth_sync);
- set_defaultparse (parse_login);
- login_fd = make_listen_port (login_port);
+ set_defaultparse(parse_login);
+ login_fd = make_listen_port(login_port);
-// 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);
+ Timer(gettick() + std::chrono::minutes(5),
+ check_auth_sync,
+ std::chrono::minutes(5)
+ ).detach();
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);
+ Timer(gettick() + std::chrono::seconds(1),
+ char_anti_freeze_system,
+ ANTI_FREEZE_INTERVAL
+ ).detach();
}
// add timer to check GM accounts file modification
- 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");
- 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
- ("The login-server is ready (Server is listening on the port %d).\n",
+ std::chrono::seconds j = gm_account_filename_check_timer;
+ if (j == interval_t::zero())
+ j = std::chrono::minutes(1);
+ Timer(gettick() + j,
+ check_GM_file,
+ j).detach();
+
+ LOGIN_LOG("The login-server is ready (Server is listening on the port %d).\n",
login_port);
- printf
- ("The login-server is \033[1;32mready\033[0m (Server is listening on the port %d).\n\n",
+ 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/login.hpp b/src/login/login.hpp
deleted file mode 100644
index 49d1c12..0000000
--- a/src/login/login.hpp
+++ /dev/null
@@ -1,41 +0,0 @@
-// $Id: login.h,v 1.1.1.1 2004/09/10 17:26:53 MagicalTux Exp $
-#ifndef LOGIN_HPP
-#define LOGIN_HPP
-
-#define MAX_SERVERS 30
-
-#define LOGIN_CONF_NAME "conf/login_athena.conf"
-#define LAN_CONF_NAME "conf/lan_support.conf"
-// It seems we don't need to emulate RO's "password encryption" - MC/TMW
-//#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 is_new;
-};
-
-#endif
diff --git a/src/map/atcommand.cpp b/src/map/atcommand.cpp
index bca530e..5fffaa3 100644
--- a/src/map/atcommand.cpp
+++ b/src/map/atcommand.cpp
@@ -1,601 +1,379 @@
-// $Id: atcommand.c 148 2004-09-30 14:05:37Z MouseJstr $
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <ctype.h>
-#include <math.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <time.h>
-#include <unistd.h>
-
-#include <array>
+#include "atcommand.hpp"
+
+#include <cmath>
+#include <cstring>
+#include <ctime>
+#include "../common/core.hpp"
+#include "../common/cxxstdio.hpp"
+#include "../common/mmo.hpp"
+#include "../common/random.hpp"
+#include "../common/nullpo.hpp"
#include "../common/socket.hpp"
#include "../common/timer.hpp"
-#include "../common/nullpo.hpp"
-#include "../common/mt_rand.hpp"
+#include "../common/utils2.hpp"
-#include "atcommand.hpp"
#include "battle.hpp"
-#include "clif.hpp"
#include "chrif.hpp"
-#include "guild.hpp"
+#include "clif.hpp"
#include "intif.hpp"
#include "itemdb.hpp"
#include "map.hpp"
#include "mob.hpp"
#include "npc.hpp"
-#include "pc.hpp"
#include "party.hpp"
+#include "pc.hpp"
#include "script.hpp"
#include "skill.hpp"
-#include "trade.hpp"
-
-#include "../common/core.hpp"
+#include "storage.hpp"
#include "tmw.hpp"
+#include "trade.hpp"
-#define STATE_BLIND 0x10
-
-static char command_symbol = '@'; // first char of the commands (by [Yor])
-
-#define ATCOMMAND_FUNC(x) int atcommand_ ## x (const int fd, struct map_session_data* sd, const char* command, const char* message)
-ATCOMMAND_FUNC (setup);
-ATCOMMAND_FUNC (broadcast);
-ATCOMMAND_FUNC (localbroadcast);
-ATCOMMAND_FUNC (charwarp);
-//ATCOMMAND_FUNC (warp);
-ATCOMMAND_FUNC (where);
-//ATCOMMAND_FUNC (goto);
-ATCOMMAND_FUNC (jump);
-ATCOMMAND_FUNC (who);
-ATCOMMAND_FUNC (whogroup);
-ATCOMMAND_FUNC (whomap);
-ATCOMMAND_FUNC (whomapgroup);
-ATCOMMAND_FUNC (whogm); // by Yor
-ATCOMMAND_FUNC (save);
-ATCOMMAND_FUNC (load);
-ATCOMMAND_FUNC (speed);
-ATCOMMAND_FUNC (storage);
-ATCOMMAND_FUNC (guildstorage);
-ATCOMMAND_FUNC (option);
-ATCOMMAND_FUNC (hide);
-ATCOMMAND_FUNC (die);
-ATCOMMAND_FUNC (kill);
-ATCOMMAND_FUNC (alive);
-ATCOMMAND_FUNC (kami);
-ATCOMMAND_FUNC (heal);
-//ATCOMMAND_FUNC (item);
-ATCOMMAND_FUNC (itemreset);
-ATCOMMAND_FUNC (itemcheck);
-ATCOMMAND_FUNC (baselevelup);
-ATCOMMAND_FUNC (joblevelup);
-ATCOMMAND_FUNC (help);
-ATCOMMAND_FUNC (gm);
-ATCOMMAND_FUNC (pvpoff);
-ATCOMMAND_FUNC (pvpon);
-ATCOMMAND_FUNC (gvgoff);
-ATCOMMAND_FUNC (gvgon);
-ATCOMMAND_FUNC (model);
-ATCOMMAND_FUNC (go);
-//ATCOMMAND_FUNC (spawn);
-ATCOMMAND_FUNC (killmonster);
-ATCOMMAND_FUNC (killmonster2);
-ATCOMMAND_FUNC (refine);
-ATCOMMAND_FUNC (produce);
-ATCOMMAND_FUNC (memo);
-ATCOMMAND_FUNC (gat);
-ATCOMMAND_FUNC (packet);
-ATCOMMAND_FUNC (statuspoint);
-ATCOMMAND_FUNC (skillpoint);
-ATCOMMAND_FUNC (zeny);
-ATCOMMAND_FUNC (param);
-ATCOMMAND_FUNC (guildlevelup);
-//ATCOMMAND_FUNC (recall);
-ATCOMMAND_FUNC (recallall);
-ATCOMMAND_FUNC (revive);
-ATCOMMAND_FUNC (character_stats);
-ATCOMMAND_FUNC (character_stats_all);
-ATCOMMAND_FUNC (character_option);
-ATCOMMAND_FUNC (character_save);
-ATCOMMAND_FUNC (night);
-ATCOMMAND_FUNC (day);
-ATCOMMAND_FUNC (doom);
-ATCOMMAND_FUNC (doommap);
-ATCOMMAND_FUNC (raise);
-ATCOMMAND_FUNC (raisemap);
-ATCOMMAND_FUNC (character_baselevel);
-ATCOMMAND_FUNC (character_joblevel);
-ATCOMMAND_FUNC (kick);
-ATCOMMAND_FUNC (kickall);
-ATCOMMAND_FUNC (allskills);
-ATCOMMAND_FUNC (questskill);
-ATCOMMAND_FUNC (charquestskill);
-ATCOMMAND_FUNC (lostskill);
-ATCOMMAND_FUNC (charlostskill);
-ATCOMMAND_FUNC (party);
-ATCOMMAND_FUNC (guild);
-ATCOMMAND_FUNC (charskreset);
-ATCOMMAND_FUNC (charstreset);
-ATCOMMAND_FUNC (charreset);
-ATCOMMAND_FUNC (charstpoint);
-ATCOMMAND_FUNC (charmodel);
-ATCOMMAND_FUNC (charskpoint);
-ATCOMMAND_FUNC (charzeny);
-ATCOMMAND_FUNC (agitstart);
-ATCOMMAND_FUNC (agitend);
-ATCOMMAND_FUNC (reloaditemdb);
-ATCOMMAND_FUNC (reloadmobdb);
-ATCOMMAND_FUNC (reloadskilldb);
-ATCOMMAND_FUNC (reloadscript);
-ATCOMMAND_FUNC (reloadgmdb); // by Yor
-ATCOMMAND_FUNC (mapexit);
-ATCOMMAND_FUNC (idsearch);
-ATCOMMAND_FUNC (mapinfo);
-ATCOMMAND_FUNC (dye); //** by fritz
-ATCOMMAND_FUNC (hair_style); //** by fritz
-ATCOMMAND_FUNC (hair_color); //** by fritz
-ATCOMMAND_FUNC (all_stats); //** by fritz
-ATCOMMAND_FUNC (char_change_sex); // by Yor
-ATCOMMAND_FUNC (char_block); // by Yor
-ATCOMMAND_FUNC (char_ban); // by Yor
-ATCOMMAND_FUNC (char_unblock); // by Yor
-ATCOMMAND_FUNC (char_unban); // by Yor
-ATCOMMAND_FUNC (mount_peco); // by Valaris
-ATCOMMAND_FUNC (char_mount_peco); // by Yor
-ATCOMMAND_FUNC (guildspy); // [Syrus22]
-ATCOMMAND_FUNC (partyspy); // [Syrus22]
-ATCOMMAND_FUNC (guildrecall); // by Yor
-ATCOMMAND_FUNC (partyrecall); // by Yor
-ATCOMMAND_FUNC (enablenpc);
-ATCOMMAND_FUNC (disablenpc);
-ATCOMMAND_FUNC (servertime); // by Yor
-ATCOMMAND_FUNC (chardelitem); // by Yor
-ATCOMMAND_FUNC (jail); // by Yor
-ATCOMMAND_FUNC (unjail); // by Yor
-ATCOMMAND_FUNC (disguise); // [Valaris]
-ATCOMMAND_FUNC (undisguise); // by Yor
-ATCOMMAND_FUNC (ignorelist); // by Yor
-ATCOMMAND_FUNC (charignorelist); // by Yor
-ATCOMMAND_FUNC (inall); // by Yor
-ATCOMMAND_FUNC (exall); // by Yor
-ATCOMMAND_FUNC (chardisguise); // Kalaspuff
-ATCOMMAND_FUNC (charundisguise); // Kalaspuff
-ATCOMMAND_FUNC (email); // by Yor
-ATCOMMAND_FUNC (effect); //by Apple
-ATCOMMAND_FUNC (character_item_list); // by Yor
-ATCOMMAND_FUNC (character_storage_list); // by Yor
-ATCOMMAND_FUNC (character_cart_list); // by Yor
-ATCOMMAND_FUNC (addwarp); // by MouseJstr
-ATCOMMAND_FUNC (follow); // by MouseJstr
-ATCOMMAND_FUNC (skillon); // by MouseJstr
-ATCOMMAND_FUNC (skilloff); // by MouseJstr
-ATCOMMAND_FUNC (killer); // by MouseJstr
-ATCOMMAND_FUNC (npcmove); // by MouseJstr
-ATCOMMAND_FUNC (killable); // by MouseJstr
-ATCOMMAND_FUNC (charkillable); // by MouseJstr
-ATCOMMAND_FUNC (chareffect); // by MouseJstr
-ATCOMMAND_FUNC (chardye); // by MouseJstr
-ATCOMMAND_FUNC (charhairstyle); // by MouseJstr
-ATCOMMAND_FUNC (charhaircolor); // by MouseJstr
-ATCOMMAND_FUNC (dropall); // by MouseJstr
-ATCOMMAND_FUNC (chardropall); // by MouseJstr
-ATCOMMAND_FUNC (storeall); // by MouseJstr
-ATCOMMAND_FUNC (charstoreall); // by MouseJstr
-ATCOMMAND_FUNC (skillid); // by MouseJstr
-ATCOMMAND_FUNC (useskill); // by MouseJstr
-ATCOMMAND_FUNC (summon);
-ATCOMMAND_FUNC (rain);
-ATCOMMAND_FUNC (snow);
-ATCOMMAND_FUNC (sakura);
-ATCOMMAND_FUNC (fog);
-ATCOMMAND_FUNC (leaves);
-ATCOMMAND_FUNC (adjgmlvl); // by MouseJstr
-ATCOMMAND_FUNC (adjcmdlvl); // by MouseJstr
-ATCOMMAND_FUNC (trade); // by MouseJstr
-ATCOMMAND_FUNC (unmute); // [Valaris]
-ATCOMMAND_FUNC (char_wipe); // [Fate]
-ATCOMMAND_FUNC (set_magic); // [Fate]
-ATCOMMAND_FUNC (magic_info); // [Fate]
-ATCOMMAND_FUNC (log); // [Fate]
-ATCOMMAND_FUNC (tee); // [Fate]
-ATCOMMAND_FUNC (invisible); // [Fate]
-ATCOMMAND_FUNC (visible); // [Fate]
-ATCOMMAND_FUNC (list_nearby); // [Fate]
-ATCOMMAND_FUNC (iterate_forward_over_players); // [Fate]
-ATCOMMAND_FUNC (iterate_backwards_over_players); // [Fate]
-ATCOMMAND_FUNC (skillpool_info); // [Fate]
-ATCOMMAND_FUNC (skillpool_focus); // [Fate]
-ATCOMMAND_FUNC (skillpool_unfocus); // [Fate]
-ATCOMMAND_FUNC (skill_learn); // [Fate]
-ATCOMMAND_FUNC (wgm);
-ATCOMMAND_FUNC (ipcheck);
-ATCOMMAND_FUNC (doomspot);
+#include "../poison.hpp"
+
+#define ATCOMMAND_FUNC(x) static \
+int atcommand_##x(const int fd, struct map_session_data* sd, const char* command, const char* message)
+ATCOMMAND_FUNC(setup);
+ATCOMMAND_FUNC(broadcast);
+ATCOMMAND_FUNC(localbroadcast);
+ATCOMMAND_FUNC(charwarp);
+ATCOMMAND_FUNC(warp);
+ATCOMMAND_FUNC(where);
+ATCOMMAND_FUNC(goto);
+ATCOMMAND_FUNC(jump);
+ATCOMMAND_FUNC(who);
+ATCOMMAND_FUNC(whogroup);
+ATCOMMAND_FUNC(whomap);
+ATCOMMAND_FUNC(whomapgroup);
+ATCOMMAND_FUNC(whogm); // by Yor
+ATCOMMAND_FUNC(save);
+ATCOMMAND_FUNC(load);
+ATCOMMAND_FUNC(speed);
+ATCOMMAND_FUNC(storage);
+ATCOMMAND_FUNC(option);
+ATCOMMAND_FUNC(hide);
+ATCOMMAND_FUNC(die);
+ATCOMMAND_FUNC(kill);
+ATCOMMAND_FUNC(alive);
+ATCOMMAND_FUNC(kami);
+ATCOMMAND_FUNC(heal);
+ATCOMMAND_FUNC(item);
+ATCOMMAND_FUNC(itemreset);
+ATCOMMAND_FUNC(itemcheck);
+ATCOMMAND_FUNC(baselevelup);
+ATCOMMAND_FUNC(joblevelup);
+ATCOMMAND_FUNC(help);
+ATCOMMAND_FUNC(gm);
+ATCOMMAND_FUNC(pvpoff);
+ATCOMMAND_FUNC(pvpon);
+ATCOMMAND_FUNC(model);
+ATCOMMAND_FUNC(spawn);
+ATCOMMAND_FUNC(killmonster);
+ATCOMMAND_FUNC(killmonster2);
+ATCOMMAND_FUNC(gat);
+ATCOMMAND_FUNC(packet);
+ATCOMMAND_FUNC(statuspoint);
+ATCOMMAND_FUNC(skillpoint);
+ATCOMMAND_FUNC(zeny);
+template<ATTR attr>
+ATCOMMAND_FUNC(param);
+ATCOMMAND_FUNC(recall);
+ATCOMMAND_FUNC(recallall);
+ATCOMMAND_FUNC(revive);
+ATCOMMAND_FUNC(character_stats);
+ATCOMMAND_FUNC(character_stats_all);
+ATCOMMAND_FUNC(character_option);
+ATCOMMAND_FUNC(character_save);
+ATCOMMAND_FUNC(doom);
+ATCOMMAND_FUNC(doommap);
+ATCOMMAND_FUNC(raise);
+ATCOMMAND_FUNC(raisemap);
+ATCOMMAND_FUNC(character_baselevel);
+ATCOMMAND_FUNC(character_joblevel);
+ATCOMMAND_FUNC(kick);
+ATCOMMAND_FUNC(kickall);
+ATCOMMAND_FUNC(questskill);
+ATCOMMAND_FUNC(charquestskill);
+ATCOMMAND_FUNC(lostskill);
+ATCOMMAND_FUNC(charlostskill);
+ATCOMMAND_FUNC(party);
+ATCOMMAND_FUNC(charskreset);
+ATCOMMAND_FUNC(charstreset);
+ATCOMMAND_FUNC(charreset);
+ATCOMMAND_FUNC(charstpoint);
+ATCOMMAND_FUNC(charmodel);
+ATCOMMAND_FUNC(charskpoint);
+ATCOMMAND_FUNC(charzeny);
+ATCOMMAND_FUNC(reloaditemdb);
+ATCOMMAND_FUNC(reloadmobdb);
+ATCOMMAND_FUNC(reloadskilldb);
+ATCOMMAND_FUNC(reloadscript);
+ATCOMMAND_FUNC(reloadgmdb); // by Yor
+ATCOMMAND_FUNC(mapexit);
+ATCOMMAND_FUNC(idsearch);
+ATCOMMAND_FUNC(mapinfo);
+ATCOMMAND_FUNC(dye); //** by fritz
+ATCOMMAND_FUNC(hair_style); //** by fritz
+ATCOMMAND_FUNC(hair_color); //** by fritz
+ATCOMMAND_FUNC(all_stats); //** by fritz
+ATCOMMAND_FUNC(char_change_sex); // by Yor
+ATCOMMAND_FUNC(char_block); // by Yor
+ATCOMMAND_FUNC(char_ban); // by Yor
+ATCOMMAND_FUNC(char_unblock); // by Yor
+ATCOMMAND_FUNC(char_unban); // by Yor
+ATCOMMAND_FUNC(partyspy); // [Syrus22]
+ATCOMMAND_FUNC(partyrecall); // by Yor
+ATCOMMAND_FUNC(enablenpc);
+ATCOMMAND_FUNC(disablenpc);
+ATCOMMAND_FUNC(servertime); // by Yor
+ATCOMMAND_FUNC(chardelitem); // by Yor
+ATCOMMAND_FUNC(ignorelist); // by Yor
+ATCOMMAND_FUNC(charignorelist); // by Yor
+ATCOMMAND_FUNC(inall); // by Yor
+ATCOMMAND_FUNC(exall); // by Yor
+ATCOMMAND_FUNC(email); // by Yor
+ATCOMMAND_FUNC(effect); //by Apple
+ATCOMMAND_FUNC(character_item_list); // by Yor
+ATCOMMAND_FUNC(character_storage_list); // by Yor
+ATCOMMAND_FUNC(character_cart_list); // by Yor
+ATCOMMAND_FUNC(addwarp); // by MouseJstr
+ATCOMMAND_FUNC(killer); // by MouseJstr
+ATCOMMAND_FUNC(npcmove); // by MouseJstr
+ATCOMMAND_FUNC(killable); // by MouseJstr
+ATCOMMAND_FUNC(charkillable); // by MouseJstr
+ATCOMMAND_FUNC(chareffect); // by MouseJstr
+ATCOMMAND_FUNC(dropall); // by MouseJstr
+ATCOMMAND_FUNC(chardropall); // by MouseJstr
+ATCOMMAND_FUNC(storeall); // by MouseJstr
+ATCOMMAND_FUNC(charstoreall); // by MouseJstr
+ATCOMMAND_FUNC(summon);
+ATCOMMAND_FUNC(rain);
+ATCOMMAND_FUNC(snow);
+ATCOMMAND_FUNC(sakura);
+ATCOMMAND_FUNC(fog);
+ATCOMMAND_FUNC(leaves);
+ATCOMMAND_FUNC(adjgmlvl); // by MouseJstr
+ATCOMMAND_FUNC(adjcmdlvl); // by MouseJstr
+ATCOMMAND_FUNC(trade); // by MouseJstr
+ATCOMMAND_FUNC(char_wipe); // [Fate]
+ATCOMMAND_FUNC(set_magic); // [Fate]
+ATCOMMAND_FUNC(magic_info); // [Fate]
+ATCOMMAND_FUNC(log); // [Fate]
+ATCOMMAND_FUNC(tee); // [Fate]
+ATCOMMAND_FUNC(invisible); // [Fate]
+ATCOMMAND_FUNC(visible); // [Fate]
+ATCOMMAND_FUNC(list_nearby); // [Fate]
+ATCOMMAND_FUNC(iterate_forward_over_players); // [Fate]
+ATCOMMAND_FUNC(iterate_backwards_over_players); // [Fate]
+ATCOMMAND_FUNC(skillpool_info); // [Fate]
+ATCOMMAND_FUNC(skillpool_focus); // [Fate]
+ATCOMMAND_FUNC(skillpool_unfocus); // [Fate]
+ATCOMMAND_FUNC(skill_learn); // [Fate]
+ATCOMMAND_FUNC(wgm);
+ATCOMMAND_FUNC(ipcheck);
+ATCOMMAND_FUNC(doomspot);
/*==========================================
*AtCommandInfo atcommand_info[]構造体ã®å®šç¾©
*------------------------------------------
*/
+struct AtCommandInfo
+{
+ const char *command;
+ int level;
+ int(*proc)(const int, struct map_session_data *,
+ const char *command, const char *message);
+};
+
// First char of commands is configured in atcommand_athena.conf. Leave @ in this list for default value.
// to set default level, read atcommand_athena.conf first please.
-static AtCommandInfo atcommand_info[] = {
- {AtCommand_Setup, "@setup", 40, atcommand_setup},
- {AtCommand_CharWarp, "@charwarp", 60, atcommand_charwarp},
- {AtCommand_Warp, "@warp", 40, atcommand_warp},
- {AtCommand_Where, "@where", 1, atcommand_where},
- {AtCommand_Goto, "@goto", 20, atcommand_goto},
- {AtCommand_Jump, "@jump", 40, atcommand_jump},
- {AtCommand_Who, "@who", 20, atcommand_who},
- {AtCommand_WhoGroup, "@whogroup", 20, atcommand_whogroup},
- {AtCommand_WhoMap, "@whomap", 20, atcommand_whomap},
- {AtCommand_WhoMapGroup, "@whomapgroup", 20, atcommand_whomapgroup},
- {AtCommand_WhoGM, "@whogm", 20, atcommand_whogm}, // by Yor
- {AtCommand_Save, "@save", 40, atcommand_save},
- {AtCommand_Load, "@return", 40, atcommand_load},
- {AtCommand_Load, "@load", 40, atcommand_load},
- {AtCommand_Speed, "@speed", 40, atcommand_speed},
- {AtCommand_Storage, "@storage", 1, atcommand_storage},
- {AtCommand_GuildStorage, "@gstorage", 50, atcommand_guildstorage},
- {AtCommand_Option, "@option", 40, atcommand_option},
- {AtCommand_Hide, "@hide", 40, atcommand_hide}, // + /hide
- {AtCommand_Die, "@die", 1, atcommand_die},
- {AtCommand_Kill, "@kill", 60, atcommand_kill},
- {AtCommand_Alive, "@alive", 60, atcommand_alive},
- {AtCommand_Kami, "@kami", 40, atcommand_kami},
- {AtCommand_Heal, "@heal", 40, atcommand_heal},
- {AtCommand_Item, "@item", 60, atcommand_item},
- {AtCommand_ItemReset, "@itemreset", 40, atcommand_itemreset},
- {AtCommand_ItemCheck, "@itemcheck", 60, atcommand_itemcheck},
- {AtCommand_BaseLevelUp, "@blvl", 60, atcommand_baselevelup},
- {AtCommand_JobLevelUp, "@jlvl", 60, atcommand_joblevelup},
- {AtCommand_Help, "@help", 20, atcommand_help},
- {AtCommand_GM, "@gm", 100, atcommand_gm},
- {AtCommand_PvPOff, "@pvpoff", 40, atcommand_pvpoff},
- {AtCommand_PvPOn, "@pvpon", 40, atcommand_pvpon},
- {AtCommand_GvGOff, "@gvgoff", 40, atcommand_gvgoff},
- {AtCommand_GvGOff, "@gpvpoff", 40, atcommand_gvgoff},
- {AtCommand_GvGOn, "@gvgon", 40, atcommand_gvgon},
- {AtCommand_GvGOn, "@gpvpon", 40, atcommand_gvgon},
- {AtCommand_Model, "@model", 20, atcommand_model},
- {AtCommand_Go, "@go", 10, atcommand_go},
- {AtCommand_Spawn, "@spawn", 50, atcommand_spawn},
- {AtCommand_KillMonster, "@killmonster", 60, atcommand_killmonster},
- {AtCommand_KillMonster2, "@killmonster2", 40, atcommand_killmonster2},
- {AtCommand_Produce, "@produce", 60, atcommand_produce},
- {AtCommand_Memo, "@memo", 40, atcommand_memo},
- {AtCommand_GAT, "@gat", 99, atcommand_gat}, // debug function
- {AtCommand_Packet, "@packet", 99, atcommand_packet}, // debug function
- {AtCommand_StatusPoint, "@stpoint", 60, atcommand_statuspoint},
- {AtCommand_SkillPoint, "@skpoint", 60, atcommand_skillpoint},
- {AtCommand_Zeny, "@zeny", 60, atcommand_zeny},
- {AtCommand_Strength, "@str", 60, atcommand_param},
- {AtCommand_Agility, "@agi", 60, atcommand_param},
- {AtCommand_Vitality, "@vit", 60, atcommand_param},
- {AtCommand_Intelligence, "@int", 60, atcommand_param},
- {AtCommand_Dexterity, "@dex", 60, atcommand_param},
- {AtCommand_Luck, "@luk", 60, atcommand_param},
- {AtCommand_GuildLevelUp, "@guildlvl", 60, atcommand_guildlevelup},
- {AtCommand_Recall, "@recall", 60, atcommand_recall}, // + /recall
- {AtCommand_Revive, "@revive", 60, atcommand_revive},
- {AtCommand_CharacterStats, "@charstats", 40, atcommand_character_stats},
- {AtCommand_CharacterStatsAll, "@charstatsall", 40,
- atcommand_character_stats_all},
- {AtCommand_CharacterOption, "@charoption", 60,
- atcommand_character_option},
- {AtCommand_CharacterSave, "@charsave", 60, atcommand_character_save},
- {AtCommand_Night, "@night", 80, atcommand_night},
- {AtCommand_Day, "@day", 80, atcommand_day},
- {AtCommand_Doom, "@doom", 80, atcommand_doom},
- {AtCommand_DoomMap, "@doommap", 80, atcommand_doommap},
- {AtCommand_Raise, "@raise", 80, atcommand_raise},
- {AtCommand_RaiseMap, "@raisemap", 80, atcommand_raisemap},
- {AtCommand_CharacterBaseLevel, "@charbaselvl", 60,
- atcommand_character_baselevel},
- {AtCommand_CharacterJobLevel, "@charjlvl", 60,
- atcommand_character_joblevel},
- {AtCommand_Kick, "@kick", 20, atcommand_kick}, // + right click menu for GM "(name) force to quit"
- {AtCommand_KickAll, "@kickall", 99, atcommand_kickall},
- {AtCommand_AllSkills, "@allskills", 60, atcommand_allskills},
- {AtCommand_QuestSkill, "@questskill", 40, atcommand_questskill},
- {AtCommand_CharQuestSkill, "@charquestskill", 60,
- atcommand_charquestskill},
- {AtCommand_LostSkill, "@lostskill", 40, atcommand_lostskill},
- {AtCommand_CharLostSkill, "@charlostskill", 60, atcommand_charlostskill},
- {AtCommand_Party, "@party", 1, atcommand_party},
- {AtCommand_Guild, "@guild", 50, atcommand_guild},
- {AtCommand_AgitStart, "@agitstart", 60, atcommand_agitstart},
- {AtCommand_AgitEnd, "@agitend", 60, atcommand_agitend},
- {AtCommand_MapExit, "@mapexit", 99, atcommand_mapexit},
- {AtCommand_IDSearch, "@idsearch", 60, atcommand_idsearch},
- {AtCommand_MapMove, "@mapmove", 40, atcommand_warp}, // /mm command
- {AtCommand_Broadcast, "@broadcast", 40, atcommand_broadcast}, // /b and /nb command
- {AtCommand_LocalBroadcast, "@localbroadcast", 40, atcommand_localbroadcast}, // /lb and /nlb command
- {AtCommand_RecallAll, "@recallall", 80, atcommand_recallall},
- {AtCommand_CharSkReset, "@charskreset", 60, atcommand_charskreset},
- {AtCommand_CharStReset, "@charstreset", 60, atcommand_charstreset},
- {AtCommand_ReloadItemDB, "@reloaditemdb", 99, atcommand_reloaditemdb}, // admin command
- {AtCommand_ReloadMobDB, "@reloadmobdb", 99, atcommand_reloadmobdb}, // admin command
- {AtCommand_ReloadSkillDB, "@reloadskilldb", 99, atcommand_reloadskilldb}, // admin command
- {AtCommand_ReloadScript, "@reloadscript", 99, atcommand_reloadscript}, // admin command
- {AtCommand_ReloadGMDB, "@reloadgmdb", 99, atcommand_reloadgmdb}, // admin command
- {AtCommand_CharReset, "@charreset", 60, atcommand_charreset},
- {AtCommand_CharModel, "@charmodel", 50, atcommand_charmodel},
- {AtCommand_CharSKPoint, "@charskpoint", 60, atcommand_charskpoint},
- {AtCommand_CharSTPoint, "@charstpoint", 60, atcommand_charstpoint},
- {AtCommand_CharZeny, "@charzeny", 60, atcommand_charzeny},
- {AtCommand_MapInfo, "@mapinfo", 99, atcommand_mapinfo},
- {AtCommand_Dye, "@dye", 40, atcommand_dye}, // by fritz
- {AtCommand_Dye, "@ccolor", 40, atcommand_dye}, // by fritz
- {AtCommand_HairStyle, "@hairstyle", 40, atcommand_hair_style}, // by fritz
- {AtCommand_HairColor, "@haircolor", 40, atcommand_hair_color}, // by fritz
- {AtCommand_AllStats, "@allstats", 60, atcommand_all_stats}, // by fritz
- {AtCommand_CharChangeSex, "@charchangesex", 60, atcommand_char_change_sex}, // by Yor
- {AtCommand_CharBlock, "@block", 60, atcommand_char_block}, // by Yor
- {AtCommand_CharUnBlock, "@unblock", 60, atcommand_char_unblock}, // by Yor
- {AtCommand_CharBan, "@ban", 60, atcommand_char_ban}, // by Yor
- {AtCommand_CharUnBan, "@unban", 60, atcommand_char_unban}, // by Yor
- {AtCommand_MountPeco, "@mountpeco", 20, atcommand_mount_peco}, // by Valaris
- {AtCommand_CharMountPeco, "@charmountpeco", 50, atcommand_char_mount_peco}, // by Yor
- {AtCommand_GuildSpy, "@guildspy", 60, atcommand_guildspy}, // [Syrus22]
- {AtCommand_PartySpy, "@partyspy", 60, atcommand_partyspy}, // [Syrus22]
- {AtCommand_GuildRecall, "@guildrecall", 60, atcommand_guildrecall}, // by Yor
- {AtCommand_PartyRecall, "@partyrecall", 60, atcommand_partyrecall}, // by Yor
- {AtCommand_Enablenpc, "@enablenpc", 80, atcommand_enablenpc}, // []
- {AtCommand_Disablenpc, "@disablenpc", 80, atcommand_disablenpc}, // []
- {AtCommand_ServerTime, "@servertime", 0, atcommand_servertime}, // by Yor
- {AtCommand_CharDelItem, "@chardelitem", 60, atcommand_chardelitem}, // by Yor
- {AtCommand_ListNearby, "@listnearby", 40, atcommand_list_nearby}, // by Yor
- {AtCommand_Jail, "@jail", 60, atcommand_jail}, // by Yor
- {AtCommand_UnJail, "@unjail", 60, atcommand_unjail}, // by Yor
- {AtCommand_Disguise, "@disguise", 20, atcommand_disguise}, // [Valaris]
- {AtCommand_UnDisguise, "@undisguise", 20, atcommand_undisguise}, // by Yor
- {AtCommand_IgnoreList, "@ignorelist", 0, atcommand_ignorelist}, // by Yor
- {AtCommand_CharIgnoreList, "@charignorelist", 20, atcommand_charignorelist}, // by Yor
- {AtCommand_IgnoreList, "@inall", 20, atcommand_inall}, // by Yor
- {AtCommand_ExAll, "@exall", 20, atcommand_exall}, // by Yor
- {AtCommand_CharDisguise, "@chardisguise", 60, atcommand_chardisguise}, // Kalaspuff
- {AtCommand_CharUnDisguise, "@charundisguise", 60, atcommand_charundisguise}, // Kalaspuff
- {AtCommand_EMail, "@email", 0, atcommand_email}, // by Yor
- {AtCommand_Effect, "@effect", 40, atcommand_effect}, // by Apple
- {AtCommand_Char_Item_List, "@charitemlist", 40, atcommand_character_item_list}, // by Yor
- {AtCommand_Char_Storage_List, "@charstoragelist", 40, atcommand_character_storage_list}, // by Yor
- {AtCommand_Char_Cart_List, "@charcartlist", 40, atcommand_character_cart_list}, // by Yor
- {AtCommand_Follow, "@follow", 10, atcommand_follow}, // by MouseJstr
- {AtCommand_AddWarp, "@addwarp", 20, atcommand_addwarp}, // by MouseJstr
- {AtCommand_SkillOn, "@skillon", 20, atcommand_skillon}, // by MouseJstr
- {AtCommand_SkillOff, "@skilloff", 20, atcommand_skilloff}, // by MouseJstr
- {AtCommand_Killer, "@killer", 60, atcommand_killer}, // by MouseJstr
- {AtCommand_NpcMove, "@npcmove", 20, atcommand_npcmove}, // by MouseJstr
- {AtCommand_Killable, "@killable", 40, atcommand_killable}, // by MouseJstr
- {AtCommand_CharKillable, "@charkillable", 40, atcommand_charkillable}, // by MouseJstr
- {AtCommand_Chareffect, "@chareffect", 40, atcommand_chareffect}, // MouseJstr
- //{ AtCommand_Chardye, "@chardye", 40, atcommand_chardye }, // MouseJstr
- //{ AtCommand_Charhairstyle, "@charhairstyle", 40, atcommand_charhairstyle }, // MouseJstr
- //{ AtCommand_Charhaircolor, "@charhaircolor", 40, atcommand_charhaircolor }, // MouseJstr
- {AtCommand_Dropall, "@dropall", 40, atcommand_dropall}, // MouseJstr
- {AtCommand_Chardropall, "@chardropall", 40, atcommand_chardropall}, // MouseJstr
- {AtCommand_Storeall, "@storeall", 40, atcommand_storeall}, // MouseJstr
- {AtCommand_Charstoreall, "@charstoreall", 40, atcommand_charstoreall}, // MouseJstr
- {AtCommand_Skillid, "@skillid", 40, atcommand_skillid}, // MouseJstr
- {AtCommand_Useskill, "@useskill", 40, atcommand_useskill}, // MouseJstr
- {AtCommand_Rain, "@rain", 99, atcommand_rain},
- {AtCommand_Snow, "@snow", 99, atcommand_snow},
- {AtCommand_Sakura, "@sakura", 99, atcommand_sakura},
- {AtCommand_Fog, "@fog", 99, atcommand_fog},
- {AtCommand_Leaves, "@leaves", 99, atcommand_leaves},
- //{ AtCommand_Shuffle, "@shuffle", 99, atcommand_shuffle },
- //{ AtCommand_Maintenance, "@maintenance", 99, atcommand_maintenance },
- //{ AtCommand_Misceffect, "@misceffect", 60, atcommand_misceffect },
- {AtCommand_Summon, "@summon", 60, atcommand_summon},
- {AtCommand_AdjGmLvl, "@adjgmlvl", 99, atcommand_adjgmlvl},
- {AtCommand_AdjCmdLvl, "@adjcmdlvl", 99, atcommand_adjcmdlvl},
- {AtCommand_Trade, "@trade", 60, atcommand_trade},
- {AtCommand_UnMute, "@unmute", 60, atcommand_unmute}, // [Valaris]
- {AtCommand_UnMute, "@charwipe", 60, atcommand_char_wipe}, // [Fate]
- {AtCommand_SetMagic, "@setmagic", 99, atcommand_set_magic}, // [Fate]
- {AtCommand_MagicInfo, "@magicinfo", 60, atcommand_magic_info}, // [Fate]
- {AtCommand_Log, "@log", 60, atcommand_log}, // [Fate]
- {AtCommand_Log, "@l", 60, atcommand_log}, // [Fate]
- {AtCommand_Tee, "@tee", 60, atcommand_tee}, // [Fate]
- {AtCommand_Tee, "@t", 60, atcommand_tee}, // [Fate]
- {AtCommand_Invisible, "@invisible", 60, atcommand_invisible}, // [Fate]
- {AtCommand_Visible, "@visible", 60, atcommand_visible}, // [Fate]
- {AtCommand_IterateForward, "@hugo", 60, atcommand_iterate_forward_over_players}, // [Fate]
- {AtCommand_IterateBackward, "@linus", 60, atcommand_iterate_backwards_over_players}, // [Fate]
- {AtCommand_IterateBackward, "@sp-info", 40, atcommand_skillpool_info}, // [Fate]
- {AtCommand_IterateBackward, "@sp-focus", 80, atcommand_skillpool_focus}, // [Fate]
- {AtCommand_IterateBackward, "@sp-unfocus", 80, atcommand_skillpool_unfocus}, // [Fate]
- {AtCommand_IterateBackward, "@skill-learn", 80, atcommand_skill_learn}, // [Fate]
- {AtCommand_Wgm, "@wgm", 0, atcommand_wgm},
- {AtCommand_IpCheck, "@ipcheck", 60, atcommand_ipcheck},
- {AtCommand_DoomSpot, "@doomspot", 60, atcommand_doomspot},
+static
+AtCommandInfo atcommand_info[] = {
+ {"@setup", 40, atcommand_setup},
+ {"@charwarp", 60, atcommand_charwarp},
+ {"@warp", 40, atcommand_warp},
+ {"@where", 1, atcommand_where},
+ {"@goto", 20, atcommand_goto},
+ {"@jump", 40, atcommand_jump},
+ {"@who", 20, atcommand_who},
+ {"@whogroup", 20, atcommand_whogroup},
+ {"@whomap", 20, atcommand_whomap},
+ {"@whomapgroup", 20, atcommand_whomapgroup},
+ {"@whogm", 20, atcommand_whogm}, // by Yor
+ {"@save", 40, atcommand_save},
+ {"@return", 40, atcommand_load},
+ {"@load", 40, atcommand_load},
+ {"@speed", 40, atcommand_speed},
+ {"@storage", 1, atcommand_storage},
+ {"@option", 40, atcommand_option},
+ {"@hide", 40, atcommand_hide}, // + /hide
+ {"@die", 1, atcommand_die},
+ {"@kill", 60, atcommand_kill},
+ {"@alive", 60, atcommand_alive},
+ {"@kami", 40, atcommand_kami},
+ {"@heal", 40, atcommand_heal},
+ {"@item", 60, atcommand_item},
+ {"@itemreset", 40, atcommand_itemreset},
+ {"@itemcheck", 60, atcommand_itemcheck},
+ {"@blvl", 60, atcommand_baselevelup},
+ {"@jlvl", 60, atcommand_joblevelup},
+ {"@help", 20, atcommand_help},
+ {"@gm", 100, atcommand_gm},
+ {"@pvpoff", 40, atcommand_pvpoff},
+ {"@pvpon", 40, atcommand_pvpon},
+ {"@model", 20, atcommand_model},
+ {"@spawn", 50, atcommand_spawn},
+ {"@killmonster", 60, atcommand_killmonster},
+ {"@killmonster2", 40, atcommand_killmonster2},
+ {"@gat", 99, atcommand_gat}, // debug function
+ {"@packet", 99, atcommand_packet}, // debug function
+ {"@stpoint", 60, atcommand_statuspoint},
+ {"@skpoint", 60, atcommand_skillpoint},
+ {"@zeny", 60, atcommand_zeny},
+ {"@str", 60, atcommand_param<ATTR::STR>},
+ {"@agi", 60, atcommand_param<ATTR::AGI>},
+ {"@vit", 60, atcommand_param<ATTR::VIT>},
+ {"@int", 60, atcommand_param<ATTR::INT>},
+ {"@dex", 60, atcommand_param<ATTR::DEX>},
+ {"@luk", 60, atcommand_param<ATTR::LUK>},
+ {"@recall", 60, atcommand_recall}, // + /recall
+ {"@revive", 60, atcommand_revive},
+ {"@charstats", 40, atcommand_character_stats},
+ {"@charstatsall", 40, atcommand_character_stats_all},
+ {"@charoption", 60, atcommand_character_option},
+ {"@charsave", 60, atcommand_character_save},
+ {"@doom", 80, atcommand_doom},
+ {"@doommap", 80, atcommand_doommap},
+ {"@raise", 80, atcommand_raise},
+ {"@raisemap", 80, atcommand_raisemap},
+ {"@charbaselvl", 60, atcommand_character_baselevel},
+ {"@charjlvl", 60, atcommand_character_joblevel},
+ {"@kick", 20, atcommand_kick}, // + right click menu for GM "(name) force to quit"
+ {"@kickall", 99, atcommand_kickall},
+ {"@questskill", 40, atcommand_questskill},
+ {"@charquestskill", 60, atcommand_charquestskill},
+ {"@lostskill", 40, atcommand_lostskill},
+ {"@charlostskill", 60, atcommand_charlostskill},
+ {"@party", 1, atcommand_party},
+ {"@mapexit", 99, atcommand_mapexit},
+ {"@idsearch", 60, atcommand_idsearch},
+ {"@mapmove", 40, atcommand_warp}, // /mm command
+ {"@broadcast", 40, atcommand_broadcast}, // /b and /nb command
+ {"@localbroadcast", 40, atcommand_localbroadcast}, // /lb and /nlb command
+ {"@recallall", 80, atcommand_recallall},
+ {"@charskreset", 60, atcommand_charskreset},
+ {"@charstreset", 60, atcommand_charstreset},
+ {"@reloaditemdb", 99, atcommand_reloaditemdb}, // admin command
+ {"@reloadmobdb", 99, atcommand_reloadmobdb}, // admin command
+ {"@reloadskilldb", 99, atcommand_reloadskilldb}, // admin command
+ {"@reloadscript", 99, atcommand_reloadscript}, // admin command
+ {"@reloadgmdb", 99, atcommand_reloadgmdb}, // admin command
+ {"@charreset", 60, atcommand_charreset},
+ {"@charmodel", 50, atcommand_charmodel},
+ {"@charskpoint", 60, atcommand_charskpoint},
+ {"@charstpoint", 60, atcommand_charstpoint},
+ {"@charzeny", 60, atcommand_charzeny},
+ {"@mapinfo", 99, atcommand_mapinfo},
+ {"@dye", 40, atcommand_dye}, // by fritz
+ {"@ccolor", 40, atcommand_dye}, // by fritz
+ {"@hairstyle", 40, atcommand_hair_style}, // by fritz
+ {"@haircolor", 40, atcommand_hair_color}, // by fritz
+ {"@allstats", 60, atcommand_all_stats}, // by fritz
+ {"@charchangesex", 60, atcommand_char_change_sex}, // by Yor
+ {"@block", 60, atcommand_char_block}, // by Yor
+ {"@unblock", 60, atcommand_char_unblock}, // by Yor
+ {"@ban", 60, atcommand_char_ban}, // by Yor
+ {"@unban", 60, atcommand_char_unban}, // by Yor
+ {"@partyspy", 60, atcommand_partyspy}, // [Syrus22]
+ {"@partyrecall", 60, atcommand_partyrecall}, // by Yor
+ {"@enablenpc", 80, atcommand_enablenpc}, // []
+ {"@disablenpc", 80, atcommand_disablenpc}, // []
+ {"@servertime", 0, atcommand_servertime}, // by Yor
+ {"@chardelitem", 60, atcommand_chardelitem}, // by Yor
+ {"@listnearby", 40, atcommand_list_nearby}, // by Yor
+ {"@ignorelist", 0, atcommand_ignorelist}, // by Yor
+ {"@charignorelist", 20, atcommand_charignorelist}, // by Yor
+ {"@inall", 20, atcommand_inall}, // by Yor
+ {"@exall", 20, atcommand_exall}, // by Yor
+ {"@email", 0, atcommand_email}, // by Yor
+ {"@effect", 40, atcommand_effect}, // by Apple
+ {"@charitemlist", 40, atcommand_character_item_list}, // by Yor
+ {"@charstoragelist", 40, atcommand_character_storage_list}, // by Yor
+ {"@charcartlist", 40, atcommand_character_cart_list}, // by Yor
+ {"@addwarp", 20, atcommand_addwarp}, // by MouseJstr
+ {"@killer", 60, atcommand_killer}, // by MouseJstr
+ {"@npcmove", 20, atcommand_npcmove}, // by MouseJstr
+ {"@killable", 40, atcommand_killable}, // by MouseJstr
+ {"@charkillable", 40, atcommand_charkillable}, // by MouseJstr
+ {"@chareffect", 40, atcommand_chareffect}, // MouseJstr
+ {"@dropall", 40, atcommand_dropall}, // MouseJstr
+ {"@chardropall", 40, atcommand_chardropall}, // MouseJstr
+ {"@storeall", 40, atcommand_storeall}, // MouseJstr
+ {"@charstoreall", 40, atcommand_charstoreall}, // MouseJstr
+ {"@rain", 99, atcommand_rain},
+ {"@snow", 99, atcommand_snow},
+ {"@sakura", 99, atcommand_sakura},
+ {"@fog", 99, atcommand_fog},
+ {"@leaves", 99, atcommand_leaves},
+ {"@summon", 60, atcommand_summon},
+ {"@adjgmlvl", 99, atcommand_adjgmlvl},
+ {"@adjcmdlvl", 99, atcommand_adjcmdlvl},
+ {"@trade", 60, atcommand_trade},
+ {"@charwipe", 60, atcommand_char_wipe}, // [Fate]
+ {"@setmagic", 99, atcommand_set_magic}, // [Fate]
+ {"@magicinfo", 60, atcommand_magic_info}, // [Fate]
+ {"@log", 60, atcommand_log}, // [Fate]
+ {"@l", 60, atcommand_log}, // [Fate]
+ {"@tee", 60, atcommand_tee}, // [Fate]
+ {"@t", 60, atcommand_tee}, // [Fate]
+ {"@invisible", 60, atcommand_invisible}, // [Fate]
+ {"@visible", 60, atcommand_visible}, // [Fate]
+ {"@hugo", 60, atcommand_iterate_forward_over_players}, // [Fate]
+ {"@linus", 60, atcommand_iterate_backwards_over_players}, // [Fate]
+ {"@sp-info", 40, atcommand_skillpool_info}, // [Fate]
+ {"@sp-focus", 80, atcommand_skillpool_focus}, // [Fate]
+ {"@sp-unfocus", 80, atcommand_skillpool_unfocus}, // [Fate]
+ {"@skill-learn", 80, atcommand_skill_learn}, // [Fate]
+ {"@wgm", 0, atcommand_wgm},
+ {"@ipcheck", 60, atcommand_ipcheck},
+ {"@doomspot", 60, atcommand_doomspot},
// add new commands before this line
- {AtCommand_Unknown, NULL, 1, NULL}
+ {NULL, 1, NULL}
};
-/*====================================================
- * This function return the name of the job (by [Yor])
- *----------------------------------------------------
- */
-static
-const char *job_name (int pc_class)
-{
- switch (pc_class)
- {
- case 0:
- return "Novice";
- case 1:
- return "Swordsman";
- case 2:
- return "Mage";
- case 3:
- return "Archer";
- case 4:
- return "Acolyte";
- case 5:
- return "Merchant";
- case 6:
- return "Thief";
- case 7:
- return "Knight";
- case 8:
- return "Priest";
- case 9:
- return "Wizard";
- case 10:
- return "Blacksmith";
- case 11:
- return "Hunter";
- case 12:
- return "Assassin";
- case 13:
- return "Knight 2";
- case 14:
- return "Crusader";
- case 15:
- return "Monk";
- case 16:
- return "Sage";
- case 17:
- return "Rogue";
- case 18:
- return "Alchemist";
- case 19:
- return "Bard";
- case 20:
- return "Dancer";
- case 21:
- return "Crusader 2";
- case 22:
- return "Wedding";
- case 23:
- return "Super Novice";
- case 4001:
- return "Novice High";
- case 4002:
- return "Swordsman High";
- case 4003:
- return "Mage High";
- case 4004:
- return "Archer High";
- case 4005:
- return "Acolyte High";
- case 4006:
- return "Merchant High";
- case 4007:
- return "Thief High";
- case 4008:
- return "Lord Knight";
- case 4009:
- return "High Priest";
- case 4010:
- return "High Wizard";
- case 4011:
- return "Whitesmith";
- case 4012:
- return "Sniper";
- case 4013:
- return "Assassin Cross";
- case 4014:
- return "Peko Knight";
- case 4015:
- return "Paladin";
- case 4016:
- return "Champion";
- case 4017:
- return "Professor";
- case 4018:
- return "Stalker";
- case 4019:
- return "Creator";
- case 4020:
- return "Clown";
- case 4021:
- return "Gypsy";
- case 4022:
- return "Peko Paladin";
- case 4023:
- return "Baby Novice";
- case 4024:
- return "Baby Swordsman";
- case 4025:
- return "Baby Mage";
- case 4026:
- return "Baby Archer";
- case 4027:
- return "Baby Acolyte";
- case 4028:
- return "Baby Merchant";
- case 4029:
- return "Baby Thief";
- case 4030:
- return "Baby Knight";
- case 4031:
- return "Baby Priest";
- case 4032:
- return "Baby Wizard";
- case 4033:
- return "Baby Blacksmith";
- case 4034:
- return "Baby Hunter";
- case 4035:
- return "Baby Assassin";
- case 4036:
- return "Baby Peco Knight";
- case 4037:
- return "Baby Crusader";
- case 4038:
- return "Baby Monk";
- case 4039:
- return "Baby Sage";
- case 4040:
- return "Baby Rogue";
- case 4041:
- return "Baby Alchemist";
- case 4042:
- return "Baby Bard";
- case 4043:
- return "Baby Dancer";
- case 4044:
- return "Baby Peco Crusader";
- case 4045:
- return "Super Baby";
- }
- return "Unknown Job";
-}
-
/*==========================================
* get_atcommand_level @コマンドã®å¿…è¦ãƒ¬ãƒ™ãƒ«ã‚’å–å¾—
*------------------------------------------
*/
-int get_atcommand_level (const AtCommandType type)
+static
+int get_atcommand_level(const AtCommandInfo *type)
{
- int i;
-
- for (i = 0; atcommand_info[i].type != AtCommand_None; i++)
- if (atcommand_info[i].type == type)
- return atcommand_info[i].level;
+ if (type)
+ return type->level;
return 100; // 100: command can not be used
}
+static
+FILE *get_gm_log();
+
/*========================================
* At-command logging
*/
-void log_atcommand (struct map_session_data *sd, const char *fmt, ...)
+void log_atcommand(struct map_session_data *sd, const_string cmd)
{
- char message[512];
- va_list ap;
-
- va_start (ap, fmt);
- vsnprintf (message, 511, fmt, ap);
- va_end (ap);
-
- gm_log ("%s(%d,%d) %s(%d) : %s", map[sd->bl.m].name, sd->bl.x,
- sd->bl.y, sd->status.name, sd->status.account_id, message);
+ FILE *fp = get_gm_log();
+ if (!fp)
+ return;
+ timestamp_seconds_buffer tmpstr;
+ stamp_time(tmpstr);
+ fprintf(fp, "[%s] %s(%d,%d) %s(%d) : ",
+ tmpstr,
+ map[sd->bl.m].name, sd->bl.x, sd->bl.y,
+ sd->status.name, sd->status.account_id);
+ fwrite(cmd.data(), 1, cmd.size(), fp);
}
char *gm_logfile_name = NULL;
@@ -603,202 +381,157 @@ char *gm_logfile_name = NULL;
* Log a timestamped line to GM log file
*------------------------------------------
*/
-void gm_log (const char *fmt, ...)
+FILE *get_gm_log()
{
- static int last_logfile_nr = 0;
- static FILE *gm_logfile = NULL;
- time_t time_v;
- struct tm ctime;
- int month, year, logfile_nr;
- char message[512];
- va_list ap;
-
if (!gm_logfile_name)
- return;
+ return NULL;
- va_start (ap, fmt);
- vsnprintf (message, 511, fmt, ap);
- va_end (ap);
+ struct tm ctime = TimeT::now();
- time (&time_v);
- gmtime_r (&time_v, &ctime);
+ int year = ctime.tm_year + 1900;
+ int month = ctime.tm_mon + 1;
+ int logfile_nr = (year * 12) + month;
- year = ctime.tm_year + 1900;
- month = ctime.tm_mon + 1;
- logfile_nr = (year * 12) + month;
+ static FILE *gm_logfile = NULL;
+ static int last_logfile_nr = 0;
+ if (logfile_nr == last_logfile_nr)
+ return gm_logfile;
+ last_logfile_nr = logfile_nr;
- if (logfile_nr != last_logfile_nr)
- {
- char *fullname = (char *)malloc (strlen (gm_logfile_name) + 10);
- sprintf (fullname, "%s.%04d-%02d", gm_logfile_name, year, month);
+ std::string fullname = STRPRINTF("%s.%04d-%02d",
+ gm_logfile_name, year, month);
- if (gm_logfile)
- fclose_ (gm_logfile);
+ if (gm_logfile)
+ fclose_(gm_logfile);
- gm_logfile = fopen_ (fullname, "a");
- free (fullname);
+ gm_logfile = fopen_(fullname.c_str(), "a");
- if (!gm_logfile)
- {
- perror ("GM log file");
- gm_logfile_name = NULL;
- }
- last_logfile_nr = logfile_nr;
+ if (!gm_logfile)
+ {
+ perror("GM log file");
+ gm_logfile_name = NULL;
}
-
- fprintf (gm_logfile, "[%04d-%02d-%02d %02d:%02d:%02d] %s\n",
- year, month, ctime.tm_mday, ctime.tm_hour,
- ctime.tm_min, ctime.tm_sec, message);
-
- fflush (gm_logfile);
+ return gm_logfile;
}
+static
+AtCommandInfo *atcommand(const int level, const char *message);
/*==========================================
*is_atcommand @コマンドã«å­˜åœ¨ã™ã‚‹ã‹ã©ã†ã‹ç¢ºèªã™ã‚‹
*------------------------------------------
*/
-AtCommandType
-is_atcommand (const int fd, struct map_session_data *sd, const char *message,
- int gmlvl)
+bool is_atcommand(const int fd, struct map_session_data *sd,
+ const char *message, int gmlvl)
{
- AtCommandInfo info;
- AtCommandType type;
+ nullpo_retr(false, sd);
- nullpo_retr (AtCommand_None, sd);
+ if (!message || message[0] != '@')
+ return false;
- if (!message || !*message)
- return AtCommand_None;
+ AtCommandInfo *info = atcommand(gmlvl > 0 ? gmlvl : pc_isGM(sd), message);
- memset (&info, 0, sizeof (info));
+ if (!info)
+ {
+ std::string output = STRPRINTF("GM command not found: %s",
+ message);
+ clif_displaymessage(fd, output);
+ return true; // don't show in chat
+ }
- type = atcommand (gmlvl > 0 ? gmlvl : pc_isGM (sd), message, &info);
- if (type != AtCommand_None)
{
char command[100];
- char output[200];
const char *str = message;
const char *p = message;
- memset (command, '\0', sizeof (command));
- memset (output, '\0', sizeof (output));
- while (*p && !isspace (*p))
+ memset(command, '\0', sizeof(command));
+ while (*p && !isspace(*p))
p++;
- if (p - str >= sizeof (command)) // too long
- return AtCommand_Unknown;
- strncpy (command, str, p - str);
- while (isspace (*p))
+ if (p - str >= sizeof(command)) // too long
+ return true;
+ strncpy(command, str, p - str);
+ while (isspace(*p))
p++;
- if (type == AtCommand_Unknown || info.proc == NULL)
{
- sprintf (output, "%s is Unknown Command.", command);
- clif_displaymessage (fd, output);
- }
- else
- {
- if (info.proc (fd, sd, command, p) != 0)
+ if (info->proc(fd, sd, command, p) != 0)
{
// Command can not be executed
- sprintf (output, "%s failed.", command);
- clif_displaymessage (fd, output);
+ std::string output = STRPRINTF("%s failed.", command);
+ clif_displaymessage(fd, output);
}
else
{
- if (get_atcommand_level (type) != 0) // Don't log level 0 commands
- log_atcommand (sd, "%s %s", command, p);
+ if (get_atcommand_level(info) != 0) // Don't log level 0 commands
+ log_atcommand(sd, message);
}
}
- return info.type;
+ return true;
}
-
- return AtCommand_None;
}
/*==========================================
*
*------------------------------------------
*/
-AtCommandType atcommand (const int level, const char *message,
- struct AtCommandInfo * info)
+AtCommandInfo *atcommand(const int level, const char *message)
{
- char *p = (char *) message; // it's 'char' and not 'const char' to have possibility to modify the first character if necessary
+ const char *p = message;
- if (!info)
- return AtCommand_None;
if (battle_config.atc_gmonly != 0 && !level) // level = pc_isGM(sd)
- return AtCommand_None;
+ return nullptr;
if (!p || !*p)
{
- fprintf (stderr, "at command message is empty\n");
- return AtCommand_None;
+ FPRINTF(stderr, "at command message is empty\n");
+ return nullptr;
}
- if (*p == command_symbol)
+ if (*p == '@')
{ // check first char.
char command[101];
- int i = 0;
- memset (info, 0, sizeof (AtCommandInfo));
- sscanf (p, "%100s", command);
- command[sizeof (command) - 1] = '\0';
+ int i = 0;
+ sscanf(p, "%100s", command);
+ command[sizeof(command) - 1] = '\0';
- while (atcommand_info[i].type != AtCommand_Unknown)
+ while (atcommand_info[i].command)
{
- if (strcasecmp (command + 1, atcommand_info[i].command + 1) == 0
+ if (strcasecmp(command, atcommand_info[i].command) == 0
&& level >= atcommand_info[i].level)
{
- p[0] = atcommand_info[i].command[0]; // set correct first symbol for after.
- break;
+ return &atcommand_info[i];
}
i++;
}
-
- if (atcommand_info[i].type == AtCommand_Unknown)
- {
- // doesn't return Unknown if player is normal player (display the text, not display: unknown command)
- if (level == 0)
- return AtCommand_None;
- else
- return AtCommand_Unknown;
- }
- memcpy (info, &atcommand_info[i], sizeof atcommand_info[i]);
- }
- else
- {
- return AtCommand_None;
}
-
- return info->type;
+ return nullptr;
}
/*==========================================
*
*------------------------------------------
*/
-static int atkillmonster_sub (struct block_list *bl, va_list ap)
+static
+void atkillmonster_sub(struct block_list *bl, int flag)
{
- int flag = va_arg (ap, int);
-
- nullpo_retr (0, bl);
+ nullpo_retv(bl);
if (flag)
- mob_damage (NULL, (struct mob_data *) bl,
+ mob_damage(NULL, (struct mob_data *) bl,
((struct mob_data *) bl)->hp, 2);
else
- mob_delete ((struct mob_data *) bl);
-
- return 0;
+ mob_delete((struct mob_data *) bl);
}
/*==========================================
*
*------------------------------------------
*/
-static AtCommandInfo *get_atcommandinfo_byname (const char *name)
+static
+AtCommandInfo *get_atcommandinfo_byname(const char *name)
{
- int i;
+ int i;
- for (i = 0; atcommand_info[i].type != AtCommand_Unknown; i++)
- if (strcasecmp (atcommand_info[i].command + 1, name) == 0)
+ for (i = 0; atcommand_info[i].command; i++)
+ if (strcasecmp(atcommand_info[i].command + 1, name) == 0)
return &atcommand_info[i];
return NULL;
@@ -808,42 +541,39 @@ static AtCommandInfo *get_atcommandinfo_byname (const char *name)
*
*------------------------------------------
*/
-int atcommand_config_read (const char *cfgName)
+int atcommand_config_read(const char *cfgName)
{
char line[1024], w1[1024], w2[1024];
AtCommandInfo *p;
FILE *fp;
- if ((fp = fopen_ (cfgName, "r")) == NULL)
+ if ((fp = fopen_(cfgName, "r")) == NULL)
{
- printf ("At commands configuration file not found: %s\n", cfgName);
+ PRINTF("At commands configuration file not found: %s\n", cfgName);
return 1;
}
- while (fgets (line, sizeof (line) - 1, fp))
+ while (fgets(line, sizeof(line) - 1, fp))
{
if (line[0] == '/' && line[1] == '/')
continue;
- if (sscanf (line, "%1023[^:]:%1023s", w1, w2) != 2)
+ if (sscanf(line, "%1023[^:]:%1023s", w1, w2) != 2)
continue;
- p = get_atcommandinfo_byname (w1);
+ p = get_atcommandinfo_byname(w1);
if (p != NULL)
{
- p->level = atoi (w2);
+ p->level = atoi(w2);
if (p->level > 100)
p->level = 100;
else if (p->level < 0)
p->level = 0;
}
- if (strcasecmp (w1, "import") == 0)
- atcommand_config_read (w2);
- 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];
+ if (strcasecmp(w1, "import") == 0)
+ atcommand_config_read(w2);
}
- fclose_ (fp);
+ fclose_(fp);
return 0;
}
@@ -858,43 +588,43 @@ int atcommand_config_read (const char *cfgName)
* TAW Specific
*------------------------------------------
*/
-int atcommand_setup (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_setup(const int fd, struct map_session_data *sd,
+ const char *, const char *message)
{
- char buf[256];
char character[100];
- int level = 1;
+ int level = 1;
- memset (character, '\0', sizeof (character));
+ memset(character, '\0', sizeof(character));
if (!message || !*message
- || sscanf (message, "%d %99[^\n]", &level, character) < 2)
+ || sscanf(message, "%d %99[^\n]", &level, character) < 2)
{
- clif_displaymessage (fd, "Usage: @setup <level> <char name>");
+ clif_displaymessage(fd, "Usage: @setup <level> <char name>");
return -1;
}
level--;
- snprintf (buf, 255, "-255 %s", character);
- atcommand_character_baselevel (fd, sd, "@charbaselvl", buf);
+ std::string buf;
+ buf = STRPRINTF("-255 %s", character);
+ atcommand_character_baselevel(fd, sd, "@charbaselvl", buf.c_str());
- snprintf (buf, 255, "%d %s", level, character);
- atcommand_character_baselevel (fd, sd, "@charbaselvl", buf);
+ buf = STRPRINTF("%d %s", level, character);
+ atcommand_character_baselevel(fd, sd, "@charbaselvl", buf.c_str());
// Emote skill
- snprintf (buf, 255, "1 1 %s", character);
- atcommand_skill_learn(fd, sd, "@skill-learn", buf);
+ buf = STRPRINTF("1 1 %s", character);
+ atcommand_skill_learn(fd, sd, "@skill-learn", buf.c_str());
// Trade skill
- snprintf (buf, 255, "2 1 %s", character);
- atcommand_skill_learn(fd, sd, "@skill-learn", buf);
+ buf = STRPRINTF("2 1 %s", character);
+ atcommand_skill_learn(fd, sd, "@skill-learn", buf.c_str());
// Party skill
- snprintf (buf, 255, "2 2 %s", character);
- atcommand_skill_learn(fd, sd, "@skill-learn", buf);
+ STRPRINTF("2 2 %s", character);
+ atcommand_skill_learn(fd, sd, "@skill-learn", buf.c_str());
- snprintf (buf, 255, "018-1.gat 24 98 %s", character);
- atcommand_charwarp (fd, sd, "@charwarp", buf);
+ STRPRINTF("018-1.gat 24 98 %s", character);
+ atcommand_charwarp(fd, sd, "@charwarp", buf.c_str());
return (0);
@@ -904,81 +634,81 @@ int atcommand_setup (const int fd, struct map_session_data *sd,
* @rura+
*------------------------------------------
*/
-int atcommand_charwarp (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_charwarp(const int fd, struct map_session_data *sd,
+ const char *, const char *message)
{
char map_name[100];
char character[100];
- int x = 0, y = 0;
+ int x = 0, y = 0;
struct map_session_data *pl_sd;
- int m;
+ int m;
- memset (map_name, '\0', sizeof (map_name));
- memset (character, '\0', sizeof (character));
+ memset(map_name, '\0', sizeof(map_name));
+ memset(character, '\0', sizeof(character));
if (!message || !*message
- || sscanf (message, "%99s %d %d %99[^\n]", map_name, &x, &y,
+ || sscanf(message, "%99s %d %d %99[^\n]", map_name, &x, &y,
character) < 4)
{
- clif_displaymessage (fd,
+ clif_displaymessage(fd,
"Usage: @charwarp/@rura+ <mapname> <x> <y> <char name>");
return -1;
}
if (x <= 0)
- x = MRAND (399) + 1;
+ x = random_::in(1, 399);
if (y <= 0)
- y = MRAND (399) + 1;
- if (strstr (map_name, ".gat") == NULL && strstr (map_name, ".afm") == NULL && strlen (map_name) < 13) // 16 - 4 (.gat)
- strcat (map_name, ".gat");
+ y = random_::in(1, 399);
+ if (strstr(map_name, ".gat") == NULL && strstr(map_name, ".afm") == NULL && strlen(map_name) < 13) // 16 - 4 (.gat)
+ strcat(map_name, ".gat");
- if ((pl_sd = map_nick2sd (character)) != NULL)
+ if ((pl_sd = map_nick2sd(character)) != NULL)
{
- if (pc_isGM (sd) >= pc_isGM (pl_sd))
+ if (pc_isGM(sd) >= pc_isGM(pl_sd))
{ // you can rura+ only lower or same GM level
if (x > 0 && x < 800 && y > 0 && y < 800)
{
- m = map_mapname2mapid (map_name);
+ m = map_mapname2mapid(map_name);
if (m >= 0 && map[m].flag.nowarpto
- && battle_config.any_warp_GM_min_level > pc_isGM (sd))
+ && battle_config.any_warp_GM_min_level > pc_isGM(sd))
{
- clif_displaymessage (fd,
+ clif_displaymessage(fd,
"You are not authorised to warp someone to this map.");
return -1;
}
if (pl_sd->bl.m >= 0 && map[pl_sd->bl.m].flag.nowarp
- && battle_config.any_warp_GM_min_level > pc_isGM (sd))
+ && battle_config.any_warp_GM_min_level > pc_isGM(sd))
{
- clif_displaymessage (fd,
+ clif_displaymessage(fd,
"You are not authorised to warp this player from its actual map.");
return -1;
}
- if (pc_setpos (pl_sd, map_name, x, y, 3) == 0)
+ if (pc_setpos(pl_sd, map_name, x, y, BeingRemoveWhy::WARPED) == 0)
{
- clif_displaymessage (pl_sd->fd, "Warped.");
- clif_displaymessage (fd, "Player warped (message sends to player too).");
+ clif_displaymessage(pl_sd->fd, "Warped.");
+ clif_displaymessage(fd, "Player warped (message sends to player too).");
}
else
{
- clif_displaymessage (fd, "Map not found.");
+ clif_displaymessage(fd, "Map not found.");
return -1;
}
}
else
{
- clif_displaymessage (fd, "Coordinates out of range.");
+ clif_displaymessage(fd, "Coordinates out of range.");
return -1;
}
}
else
{
- clif_displaymessage (fd, "Your GM level don't authorise you to do this action on this player.");
+ clif_displaymessage(fd, "Your GM level don't authorise you to do this action on this player.");
return -1;
}
}
else
{
- clif_displaymessage (fd, "Character not found.");
+ clif_displaymessage(fd, "Character not found.");
return -1;
}
@@ -989,59 +719,59 @@ int atcommand_charwarp (const int fd, struct map_session_data *sd,
*
*------------------------------------------
*/
-int atcommand_warp (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_warp(const int fd, struct map_session_data *sd,
+ const char *, const char *message)
{
char map_name[100];
- int x = 0, y = 0;
- int m;
+ int x = 0, y = 0;
+ int m;
- memset (map_name, '\0', sizeof (map_name));
+ memset(map_name, '\0', sizeof(map_name));
if (!message || !*message
- || sscanf (message, "%99s %d %d", map_name, &x, &y) < 1)
+ || sscanf(message, "%99s %d %d", map_name, &x, &y) < 1)
{
- clif_displaymessage (fd,
+ clif_displaymessage(fd,
"Please, enter a map (usage: @warp <mapname> <x> <y>).");
return -1;
}
if (x <= 0)
- x = MRAND (399) + 1;
+ x = random_::in(1, 399);
if (y <= 0)
- y = MRAND (399) + 1;
+ y = random_::in(1, 399);
- if (strstr (map_name, ".gat") == NULL && strstr (map_name, ".afm") == NULL && strlen (map_name) < 13) // 16 - 4 (.gat)
- strcat (map_name, ".gat");
+ if (strstr(map_name, ".gat") == NULL && strstr(map_name, ".afm") == NULL && strlen(map_name) < 13) // 16 - 4 (.gat)
+ strcat(map_name, ".gat");
if (x > 0 && x < 800 && y > 0 && y < 800)
{
- m = map_mapname2mapid (map_name);
+ m = map_mapname2mapid(map_name);
if (m >= 0 && map[m].flag.nowarpto
- && battle_config.any_warp_GM_min_level > pc_isGM (sd))
+ && battle_config.any_warp_GM_min_level > pc_isGM(sd))
{
- clif_displaymessage (fd,
+ clif_displaymessage(fd,
"You are not authorised to warp you to this map.");
return -1;
}
if (sd->bl.m >= 0 && map[sd->bl.m].flag.nowarp
- && battle_config.any_warp_GM_min_level > pc_isGM (sd))
+ && battle_config.any_warp_GM_min_level > pc_isGM(sd))
{
- clif_displaymessage (fd,
+ clif_displaymessage(fd,
"You are not authorised to warp you from your actual map.");
return -1;
}
- if (pc_setpos (sd, map_name, x, y, 3) == 0)
- clif_displaymessage (fd, "Warped.");
+ if (pc_setpos(sd, map_name, x, y, BeingRemoveWhy::WARPED) == 0)
+ clif_displaymessage(fd, "Warped.");
else
{
- clif_displaymessage (fd, "Map not found.");
+ clif_displaymessage(fd, "Map not found.");
return -1;
}
}
else
{
- clif_displaymessage (fd, "Coordinates out of range.");
+ clif_displaymessage(fd, "Coordinates out of range.");
return -1;
}
@@ -1052,31 +782,30 @@ int atcommand_warp (const int fd, struct map_session_data *sd,
*
*------------------------------------------
*/
-int atcommand_where (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_where(const int fd, struct map_session_data *sd,
+ const char *, const char *message)
{
char character[100];
- char output[200];
struct map_session_data *pl_sd;
- memset (character, '\0', sizeof (character));
- memset (output, '\0', sizeof (output));
+ memset(character, '\0', sizeof(character));
- if (sscanf (message, "%99[^\n]", character) < 1)
- strcpy (character, sd->status.name);
+ if (sscanf(message, "%99[^\n]", character) < 1)
+ strcpy(character, sd->status.name);
- if ((pl_sd = map_nick2sd (character)) != NULL &&
+ if ((pl_sd = map_nick2sd(character)) != NULL &&
!((battle_config.hide_GM_session
- || (pl_sd->status.option & OPTION_HIDE))
- && (pc_isGM (pl_sd) > pc_isGM (sd))))
+ || bool(pl_sd->status.option & Option::HIDE))
+ && (pc_isGM(pl_sd) > pc_isGM(sd))))
{ // you can look only lower or same level
- sprintf (output, "%s: %s (%d,%d)", pl_sd->status.name, pl_sd->mapname,
- pl_sd->bl.x, pl_sd->bl.y);
- clif_displaymessage (fd, output);
+ std::string output = STRPRINTF("%s: %s (%d,%d)",
+ pl_sd->status.name,
+ pl_sd->mapname, pl_sd->bl.x, pl_sd->bl.y);
+ clif_displaymessage(fd, output);
}
else
{
- clif_displaymessage (fd, "Character not found.");
+ clif_displaymessage(fd, "Character not found.");
return -1;
}
@@ -1087,46 +816,44 @@ int atcommand_where (const int fd, struct map_session_data *sd,
*
*------------------------------------------
*/
-int atcommand_goto (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_goto(const int fd, struct map_session_data *sd,
+ const char *, const char *message)
{
char character[100];
- char output[200];
struct map_session_data *pl_sd;
- memset (character, '\0', sizeof (character));
- memset (output, '\0', sizeof (output));
+ memset(character, '\0', sizeof(character));
- if (!message || !*message || sscanf (message, "%99[^\n]", character) < 1)
+ if (!message || !*message || sscanf(message, "%99[^\n]", character) < 1)
{
- clif_displaymessage (fd,
+ clif_displaymessage(fd,
"Please, enter a player name (usage: @jumpto/@warpto/@goto <char name>).");
return -1;
}
- if ((pl_sd = map_nick2sd (character)) != NULL)
+ if ((pl_sd = map_nick2sd(character)) != NULL)
{
if (pl_sd->bl.m >= 0 && map[pl_sd->bl.m].flag.nowarpto
- && battle_config.any_warp_GM_min_level > pc_isGM (sd))
+ && battle_config.any_warp_GM_min_level > pc_isGM(sd))
{
- clif_displaymessage (fd,
+ clif_displaymessage(fd,
"You are not authorised to warp you to the map of this player.");
return -1;
}
if (sd->bl.m >= 0 && map[sd->bl.m].flag.nowarp
- && battle_config.any_warp_GM_min_level > pc_isGM (sd))
+ && battle_config.any_warp_GM_min_level > pc_isGM(sd))
{
- clif_displaymessage (fd,
+ clif_displaymessage(fd,
"You are not authorised to warp you from your actual map.");
return -1;
}
- pc_setpos (sd, pl_sd->mapname, pl_sd->bl.x, pl_sd->bl.y, 3);
- sprintf (output, "Jump to %s", character);
- clif_displaymessage (fd, output);
+ pc_setpos(sd, pl_sd->mapname, pl_sd->bl.x, pl_sd->bl.y, BeingRemoveWhy::WARPED);
+ std::string output = STRPRINTF("Jump to %s", character);
+ clif_displaymessage(fd, output);
}
else
{
- clif_displaymessage (fd, "Character not found.");
+ clif_displaymessage(fd, "Character not found.");
return -1;
}
@@ -1137,43 +864,39 @@ int atcommand_goto (const int fd, struct map_session_data *sd,
*
*------------------------------------------
*/
-int atcommand_jump (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_jump(const int fd, struct map_session_data *sd,
+ const char *, const char *message)
{
- char output[200];
- int x = 0, y = 0;
-
- memset (output, '\0', sizeof (output));
-
- sscanf (message, "%d %d", &x, &y);
+ int x = 0, y = 0;
+ sscanf(message, "%d %d", &x, &y);
if (x <= 0)
- x = MRAND (399) + 1;
+ x = random_::in(1, 399);
if (y <= 0)
- y = MRAND (399) + 1;
+ y = random_::in(1, 399);
if (x > 0 && x < 800 && y > 0 && y < 800)
{
if (sd->bl.m >= 0 && map[sd->bl.m].flag.nowarpto
- && battle_config.any_warp_GM_min_level > pc_isGM (sd))
+ && battle_config.any_warp_GM_min_level > pc_isGM(sd))
{
- clif_displaymessage (fd,
+ clif_displaymessage(fd,
"You are not authorised to warp you to your actual map.");
return -1;
}
if (sd->bl.m >= 0 && map[sd->bl.m].flag.nowarp
- && battle_config.any_warp_GM_min_level > pc_isGM (sd))
+ && battle_config.any_warp_GM_min_level > pc_isGM(sd))
{
- clif_displaymessage (fd,
+ clif_displaymessage(fd,
"You are not authorised to warp you from your actual map.");
return -1;
}
- pc_setpos (sd, sd->mapname, x, y, 3);
- sprintf (output, "Jump to %d %d", x, y);
- clif_displaymessage (fd, output);
+ pc_setpos(sd, sd->mapname, x, y, BeingRemoveWhy::WARPED);
+ std::string output = STRPRINTF("Jump to %d %d", x, y);
+ clif_displaymessage(fd, output);
}
else
{
- clif_displaymessage (fd, "Coordinates out of range.");
+ clif_displaymessage(fd, "Coordinates out of range.");
return -1;
}
@@ -1184,53 +907,54 @@ int atcommand_jump (const int fd, struct map_session_data *sd,
*
*------------------------------------------
*/
-int atcommand_who (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_who(const int fd, struct map_session_data *sd,
+ const char *, const char *message)
{
- char output[200];
struct map_session_data *pl_sd;
- int i, j, count;
- int pl_GM_level, GM_level;
+ int i, j, count;
+ int pl_GM_level, GM_level;
char match_text[100];
char player_name[24];
- memset (output, '\0', sizeof (output));
- memset (match_text, '\0', sizeof (match_text));
- memset (player_name, '\0', sizeof (player_name));
+ memset(match_text, '\0', sizeof(match_text));
+ memset(player_name, '\0', sizeof(player_name));
- if (sscanf (message, "%99[^\n]", match_text) < 1)
- strcpy (match_text, "");
+ if (sscanf(message, "%99[^\n]", match_text) < 1)
+ strcpy(match_text, "");
for (j = 0; match_text[j]; j++)
- match_text[j] = tolower (match_text[j]);
+ match_text[j] = tolower(match_text[j]);
count = 0;
- GM_level = pc_isGM (sd);
+ GM_level = pc_isGM(sd);
for (i = 0; i < fd_max; i++)
{
if (session[i] && (pl_sd = (struct map_session_data *)session[i]->session_data)
&& pl_sd->state.auth)
{
- pl_GM_level = pc_isGM (pl_sd);
+ pl_GM_level = pc_isGM(pl_sd);
if (!
((battle_config.hide_GM_session
- || (pl_sd->status.option & OPTION_HIDE))
+ || bool(pl_sd->status.option & Option::HIDE))
&& (pl_GM_level > GM_level)))
{ // you can look only lower or same level
- memcpy (player_name, pl_sd->status.name, 24);
+ memcpy(player_name, pl_sd->status.name, 24);
for (j = 0; player_name[j]; j++)
- player_name[j] = tolower (player_name[j]);
- if (strstr (player_name, match_text) != NULL)
- { // search with no case sensitive
+ player_name[j] = tolower(player_name[j]);
+ if (strstr(player_name, match_text) != NULL)
+ {
+ // search with no case sensitive
+ std::string output;
if (pl_GM_level > 0)
- sprintf (output,
- "Name: %s (GM:%d) | Location: %s %d %d",
- pl_sd->status.name, pl_GM_level,
- pl_sd->mapname, pl_sd->bl.x, pl_sd->bl.y);
+ output = STRPRINTF(
+ "Name: %s (GM:%d) | Location: %s %d %d",
+ pl_sd->status.name, pl_GM_level,
+ pl_sd->mapname, pl_sd->bl.x, pl_sd->bl.y);
else
- sprintf (output, "Name: %s | Location: %s %d %d",
- pl_sd->status.name, pl_sd->mapname,
- pl_sd->bl.x, pl_sd->bl.y);
- clif_displaymessage (fd, output);
+ output = STRPRINTF(
+ "Name: %s | Location: %s %d %d",
+ pl_sd->status.name, pl_sd->mapname,
+ pl_sd->bl.x, pl_sd->bl.y);
+ clif_displaymessage(fd, output);
count++;
}
}
@@ -1238,13 +962,13 @@ int atcommand_who (const int fd, struct map_session_data *sd,
}
if (count == 0)
- clif_displaymessage (fd, "No player found.");
+ clif_displaymessage(fd, "No player found.");
else if (count == 1)
- clif_displaymessage (fd, "1 player found.");
+ clif_displaymessage(fd, "1 player found.");
else
{
- sprintf (output, "%d players found.", count);
- clif_displaymessage (fd, output);
+ std::string output = STRPRINTF("%d players found.", count);
+ clif_displaymessage(fd, output);
}
return 0;
@@ -1254,69 +978,50 @@ int atcommand_who (const int fd, struct map_session_data *sd,
*
*------------------------------------------
*/
-int atcommand_whogroup (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_whogroup(const int fd, struct map_session_data *sd,
+ const char *, const char *message)
{
- char temp0[100];
- char temp1[100];
- char output[200];
struct map_session_data *pl_sd;
- int i, j, count;
- int pl_GM_level, GM_level;
+ int i, j, count;
+ int pl_GM_level, GM_level;
char match_text[100];
char player_name[24];
- struct guild *g;
struct party *p;
- memset (temp0, '\0', sizeof (temp0));
- memset (temp1, '\0', sizeof (temp1));
- memset (output, '\0', sizeof (output));
- memset (match_text, '\0', sizeof (match_text));
- memset (player_name, '\0', sizeof (player_name));
+ memset(match_text, '\0', sizeof(match_text));
+ memset(player_name, '\0', sizeof(player_name));
- if (sscanf (message, "%99[^\n]", match_text) < 1)
- strcpy (match_text, "");
+ if (sscanf(message, "%99[^\n]", match_text) < 1)
+ strcpy(match_text, "");
for (j = 0; match_text[j]; j++)
- match_text[j] = tolower (match_text[j]);
+ match_text[j] = tolower(match_text[j]);
count = 0;
- GM_level = pc_isGM (sd);
+ GM_level = pc_isGM(sd);
for (i = 0; i < fd_max; i++)
{
if (session[i] && (pl_sd = (struct map_session_data *)session[i]->session_data)
&& pl_sd->state.auth)
{
- pl_GM_level = pc_isGM (pl_sd);
+ pl_GM_level = pc_isGM(pl_sd);
if (!
((battle_config.hide_GM_session
- || (pl_sd->status.option & OPTION_HIDE))
+ || bool(pl_sd->status.option & Option::HIDE))
&& (pl_GM_level > GM_level)))
{ // you can look only lower or same level
- memcpy (player_name, pl_sd->status.name, 24);
+ memcpy(player_name, pl_sd->status.name, 24);
for (j = 0; player_name[j]; j++)
- player_name[j] = tolower (player_name[j]);
- if (strstr (player_name, match_text) != NULL)
+ player_name[j] = tolower(player_name[j]);
+ if (strstr(player_name, match_text) != NULL)
{ // search with no case sensitive
- g = guild_search (pl_sd->status.guild_id);
- if (g == NULL)
- sprintf (temp1, "None");
- else
- sprintf (temp1, "%s", g->name);
- p = party_search (pl_sd->status.party_id);
- if (p == NULL)
- sprintf (temp0, "None");
- else
- sprintf (temp0, "%s", p->name);
+ p = party_search(pl_sd->status.party_id);
+ const char *temp0 = p ? p->name : "None";
+ std::string output;
if (pl_GM_level > 0)
- sprintf (output,
- "Name: %s (GM:%d) | Party: '%s' | Guild: '%s'",
- pl_sd->status.name, pl_GM_level, temp0,
- temp1);
- else
- sprintf (output,
- "Name: %s | Party: '%s' | Guild: '%s'",
- pl_sd->status.name, temp0, temp1);
- clif_displaymessage (fd, output);
+ output = STRPRINTF(
+ "Name: %s (GM:%d) | Party: '%s'",
+ pl_sd->status.name, pl_GM_level, temp0);
+ clif_displaymessage(fd, output);
count++;
}
}
@@ -1324,13 +1029,13 @@ int atcommand_whogroup (const int fd, struct map_session_data *sd,
}
if (count == 0)
- clif_displaymessage (fd, "No player found.");
+ clif_displaymessage(fd, "No player found.");
else if (count == 1)
- clif_displaymessage (fd, "1 player found.");
+ clif_displaymessage(fd, "1 player found.");
else
{
- sprintf (output, "%d players found.", count);
- clif_displaymessage (fd, output);
+ std::string output = STRPRINTF("%d players found.", count);
+ clif_displaymessage(fd, output);
}
return 0;
@@ -1340,70 +1045,64 @@ int atcommand_whogroup (const int fd, struct map_session_data *sd,
*
*------------------------------------------
*/
-int atcommand_whomap (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_whomap(const int fd, struct map_session_data *sd,
+ const char *, const char *message)
{
- char output[200];
struct map_session_data *pl_sd;
- int i, count;
- int pl_GM_level, GM_level;
- int map_id;
+ int i, count;
+ int pl_GM_level, GM_level;
+ int map_id;
char map_name[100];
- memset (output, '\0', sizeof (output));
- memset (map_name, '\0', sizeof (map_name));
+ memset(map_name, '\0', sizeof(map_name));
if (!message || !*message)
map_id = sd->bl.m;
else
{
- sscanf (message, "%99s", map_name);
- if (strstr (map_name, ".gat") == NULL && strstr (map_name, ".afm") == NULL && strlen (map_name) < 13) // 16 - 4 (.gat)
- strcat (map_name, ".gat");
- if ((map_id = map_mapname2mapid (map_name)) < 0)
+ sscanf(message, "%99s", map_name);
+ if (strstr(map_name, ".gat") == NULL && strstr(map_name, ".afm") == NULL && strlen(map_name) < 13) // 16 - 4 (.gat)
+ strcat(map_name, ".gat");
+ if ((map_id = map_mapname2mapid(map_name)) < 0)
map_id = sd->bl.m;
}
count = 0;
- GM_level = pc_isGM (sd);
+ GM_level = pc_isGM(sd);
for (i = 0; i < fd_max; i++)
{
if (session[i] && (pl_sd = (struct map_session_data *)session[i]->session_data)
&& pl_sd->state.auth)
{
- pl_GM_level = pc_isGM (pl_sd);
+ pl_GM_level = pc_isGM(pl_sd);
if (!
((battle_config.hide_GM_session
- || (pl_sd->status.option & OPTION_HIDE))
+ || bool(pl_sd->status.option & Option::HIDE))
&& (pl_GM_level > GM_level)))
{ // you can look only lower or same level
if (pl_sd->bl.m == map_id)
{
+ std::string output;
if (pl_GM_level > 0)
- sprintf (output,
- "Name: %s (GM:%d) | Location: %s %d %d",
- pl_sd->status.name, pl_GM_level,
- pl_sd->mapname, pl_sd->bl.x, pl_sd->bl.y);
+ output = STRPRINTF(
+ "Name: %s (GM:%d) | Location: %s %d %d",
+ pl_sd->status.name, pl_GM_level,
+ pl_sd->mapname, pl_sd->bl.x, pl_sd->bl.y);
else
- sprintf (output, "Name: %s | Location: %s %d %d",
- pl_sd->status.name, pl_sd->mapname,
- pl_sd->bl.x, pl_sd->bl.y);
- clif_displaymessage (fd, output);
+ output = STRPRINTF(
+ "Name: %s | Location: %s %d %d",
+ pl_sd->status.name, pl_sd->mapname,
+ pl_sd->bl.x, pl_sd->bl.y);
+ clif_displaymessage(fd, output);
count++;
}
}
}
}
- if (count == 0)
- sprintf (output, "No player found in map '%s'.", map[map_id].name);
- else if (count == 1)
- sprintf (output, "1 player found in map '%s'.", map[map_id].name);
- else
- {
- sprintf (output, "%d players found in map '%s'.", count, map[map_id].name);
- }
- clif_displaymessage (fd, output);
+ std::string output = STRPRINTF("%d players found in map '%s'.",
+ count, map[map_id].name);
+ clif_displaymessage(fd, output);
return 0;
}
@@ -1412,86 +1111,71 @@ int atcommand_whomap (const int fd, struct map_session_data *sd,
*
*------------------------------------------
*/
-int atcommand_whomapgroup (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_whomapgroup(const int fd, struct map_session_data *sd,
+ const char *, const char *message)
{
- char temp0[100];
- char temp1[100];
- char output[200];
struct map_session_data *pl_sd;
- int i, count;
- int pl_GM_level, GM_level;
- int map_id = 0;
+ int i, count;
+ int pl_GM_level, GM_level;
+ int map_id = 0;
char map_name[100];
- struct guild *g;
struct party *p;
- memset (temp0, '\0', sizeof (temp0));
- memset (temp1, '\0', sizeof (temp1));
- memset (output, '\0', sizeof (output));
- memset (map_name, '\0', sizeof (map_name));
+ memset(map_name, '\0', sizeof(map_name));
if (!message || !*message)
map_id = sd->bl.m;
else
{
- sscanf (message, "%99s", map_name);
- if (strstr (map_name, ".gat") == NULL && strstr (map_name, ".afm") == NULL && strlen (map_name) < 13) // 16 - 4 (.gat)
- strcat (map_name, ".gat");
- if ((map_id = map_mapname2mapid (map_name)) < 0)
+ sscanf(message, "%99s", map_name);
+ if (strstr(map_name, ".gat") == NULL && strstr(map_name, ".afm") == NULL && strlen(map_name) < 13) // 16 - 4 (.gat)
+ strcat(map_name, ".gat");
+ if ((map_id = map_mapname2mapid(map_name)) < 0)
map_id = sd->bl.m;
}
count = 0;
- GM_level = pc_isGM (sd);
+ GM_level = pc_isGM(sd);
for (i = 0; i < fd_max; i++)
{
if (session[i] && (pl_sd = (struct map_session_data *)session[i]->session_data)
&& pl_sd->state.auth)
{
- pl_GM_level = pc_isGM (pl_sd);
+ pl_GM_level = pc_isGM(pl_sd);
if (!
((battle_config.hide_GM_session
- || (pl_sd->status.option & OPTION_HIDE))
+ || bool(pl_sd->status.option & Option::HIDE))
&& (pl_GM_level > GM_level)))
- { // you can look only lower or same level
+ {
+ // you can look only lower or same level
if (pl_sd->bl.m == map_id)
{
- g = guild_search (pl_sd->status.guild_id);
- if (g == NULL)
- sprintf (temp1, "None");
- else
- sprintf (temp1, "%s", g->name);
- p = party_search (pl_sd->status.party_id);
- if (p == NULL)
- sprintf (temp0, "None");
- else
- sprintf (temp0, "%s", p->name);
+ p = party_search(pl_sd->status.party_id);
+ const char *temp0 = p ? p->name : "None";
+ std::string output;
if (pl_GM_level > 0)
- sprintf (output,
- "Name: %s (GM:%d) | Party: '%s' | Guild: '%s'",
- pl_sd->status.name, pl_GM_level, temp0,
- temp1);
+ output = STRPRINTF("Name: %s (GM:%d) | Party: '%s'",
+ pl_sd->status.name, pl_GM_level, temp0);
else
- sprintf (output,
- "Name: %s | Party: '%s' | Guild: '%s'",
- pl_sd->status.name, temp0, temp1);
- clif_displaymessage (fd, output);
+ output = STRPRINTF("Name: %s | Party: '%s'",
+ pl_sd->status.name, temp0);
+ clif_displaymessage(fd, output);
count++;
}
}
}
}
+ std::string output;
if (count == 0)
- sprintf (output, "No player found in map '%s'.", map[map_id].name);
+ output = STRPRINTF("No player found in map '%s'.", map[map_id].name);
else if (count == 1)
- sprintf (output, "1 player found in map '%s'.", map[map_id].name);
+ output = STRPRINTF("1 player found in map '%s'.", map[map_id].name);
else
{
- sprintf (output, "%d players found in map '%s'.", count, map[map_id].name);
+ output = STRPRINTF("%d players found in map '%s'.", count, map[map_id].name);
}
- clif_displaymessage (fd, output);
+ clif_displaymessage(fd, output);
return 0;
}
@@ -1500,75 +1184,64 @@ int atcommand_whomapgroup (const int fd, struct map_session_data *sd,
*
*------------------------------------------
*/
-int atcommand_whogm (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_whogm(const int fd, struct map_session_data *sd,
+ const char *, const char *message)
{
- char temp0[100];
- char temp1[100];
- char output[200];
struct map_session_data *pl_sd;
- int i, j, count;
- int pl_GM_level, GM_level;
+ int i, j, count;
+ int pl_GM_level, GM_level;
char match_text[100];
char player_name[24];
- struct guild *g;
struct party *p;
- memset (temp0, '\0', sizeof (temp0));
- memset (temp1, '\0', sizeof (temp1));
- memset (output, '\0', sizeof (output));
- memset (match_text, '\0', sizeof (match_text));
- memset (player_name, '\0', sizeof (player_name));
+ memset(match_text, '\0', sizeof(match_text));
+ memset(player_name, '\0', sizeof(player_name));
- if (sscanf (message, "%99[^\n]", match_text) < 1)
- strcpy (match_text, "");
+ if (sscanf(message, "%99[^\n]", match_text) < 1)
+ strcpy(match_text, "");
for (j = 0; match_text[j]; j++)
- match_text[j] = tolower (match_text[j]);
+ match_text[j] = tolower(match_text[j]);
count = 0;
- GM_level = pc_isGM (sd);
+ GM_level = pc_isGM(sd);
for (i = 0; i < fd_max; i++)
{
if (session[i] && (pl_sd = (struct map_session_data *)session[i]->session_data)
&& pl_sd->state.auth)
{
- pl_GM_level = pc_isGM (pl_sd);
+ pl_GM_level = pc_isGM(pl_sd);
if (pl_GM_level > 0)
{
if (!
((battle_config.hide_GM_session
- || (pl_sd->status.option & OPTION_HIDE))
+ || bool(pl_sd->status.option & Option::HIDE))
&& (pl_GM_level > GM_level)))
- { // you can look only lower or same level
- memcpy (player_name, pl_sd->status.name, 24);
+ {
+ // you can look only lower or same level
+ memcpy(player_name, pl_sd->status.name, 24);
for (j = 0; player_name[j]; j++)
- player_name[j] = tolower (player_name[j]);
- if (strstr (player_name, match_text) != NULL)
- { // search with no case sensitive
- sprintf (output,
- "Name: %s (GM:%d) | Location: %s %d %d",
- pl_sd->status.name, pl_GM_level,
- pl_sd->mapname, pl_sd->bl.x, pl_sd->bl.y);
- clif_displaymessage (fd, output);
- sprintf (output,
- " BLvl: %d | Job: %s (Lvl: %d)",
- pl_sd->status.base_level,
- job_name (pl_sd->status.pc_class),
- pl_sd->status.job_level);
- clif_displaymessage (fd, output);
- g = guild_search (pl_sd->status.guild_id);
- if (g == NULL)
- sprintf (temp1, "None");
- else
- sprintf (temp1, "%s", g->name);
- p = party_search (pl_sd->status.party_id);
- if (p == NULL)
- sprintf (temp0, "None");
- else
- sprintf (temp0, "%s", p->name);
- sprintf (output, " Party: '%s' | Guild: '%s'",
- temp0, temp1);
- clif_displaymessage (fd, output);
+ player_name[j] = tolower(player_name[j]);
+ if (strstr(player_name, match_text) != NULL)
+ {
+ // search with no case sensitive
+ std::string output;
+ output = STRPRINTF(
+ "Name: %s (GM:%d) | Location: %s %d %d",
+ pl_sd->status.name, pl_GM_level,
+ pl_sd->mapname, pl_sd->bl.x, pl_sd->bl.y);
+ clif_displaymessage(fd, output);
+ output = STRPRINTF(
+ " BLvl: %d | Job: %s (Lvl: %d)",
+ pl_sd->status.base_level,
+ "Novice/Human",
+ pl_sd->status.job_level);
+ clif_displaymessage(fd, output);
+ p = party_search(pl_sd->status.party_id);
+ const char *temp0 = p ? p->name : "None";
+ output = STRPRINTF(
+ " Party: '%s'",
+ temp0);
+ clif_displaymessage(fd, output);
count++;
}
}
@@ -1577,13 +1250,13 @@ int atcommand_whogm (const int fd, struct map_session_data *sd,
}
if (count == 0)
- clif_displaymessage (fd, "No GM found.");
+ clif_displaymessage(fd, "No GM found.");
else if (count == 1)
- clif_displaymessage (fd, "1 GM found.");
+ clif_displaymessage(fd, "1 GM found.");
else
{
- sprintf (output, "%d GMs found.", count);
- clif_displaymessage (fd, output);
+ std::string output = STRPRINTF("%d GMs found.", count);
+ clif_displaymessage(fd, output);
}
return 0;
@@ -1593,15 +1266,15 @@ int atcommand_whogm (const int fd, struct map_session_data *sd,
*
*------------------------------------------
*/
-int atcommand_save (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_save(const int fd, struct map_session_data *sd,
+ const char *, const char *)
{
- nullpo_retr (-1, sd);
+ nullpo_retr(-1, sd);
- pc_setsavepoint (sd, sd->mapname, sd->bl.x, sd->bl.y);
- pc_makesavestatus (sd);
- chrif_save (sd);
- clif_displaymessage (fd, "Character data respawn point saved.");
+ pc_setsavepoint(sd, sd->mapname, sd->bl.x, sd->bl.y);
+ pc_makesavestatus(sd);
+ chrif_save(sd);
+ clif_displaymessage(fd, "Character data respawn point saved.");
return 0;
}
@@ -1610,30 +1283,30 @@ int atcommand_save (const int fd, struct map_session_data *sd,
*
*------------------------------------------
*/
-int atcommand_load (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_load(const int fd, struct map_session_data *sd,
+ const char *, const char *)
{
- int m;
+ int m;
- m = map_mapname2mapid (sd->status.save_point.map);
+ m = map_mapname2mapid(sd->status.save_point.map);
if (m >= 0 && map[m].flag.nowarpto
- && battle_config.any_warp_GM_min_level > pc_isGM (sd))
+ && battle_config.any_warp_GM_min_level > pc_isGM(sd))
{
- clif_displaymessage (fd,
+ clif_displaymessage(fd,
"You are not authorised to warp you to your save map.");
return -1;
}
if (sd->bl.m >= 0 && map[sd->bl.m].flag.nowarp
- && battle_config.any_warp_GM_min_level > pc_isGM (sd))
+ && battle_config.any_warp_GM_min_level > pc_isGM(sd))
{
- clif_displaymessage (fd,
+ clif_displaymessage(fd,
"You are not authorised to warp you from your actual map.");
return -1;
}
- pc_setpos (sd, sd->status.save_point.map, sd->status.save_point.x,
- sd->status.save_point.y, 0);
- clif_displaymessage (fd, "Warping to respawn point.");
+ pc_setpos(sd, sd->status.save_point.map, sd->status.save_point.x,
+ sd->status.save_point.y, BeingRemoveWhy::GONE);
+ clif_displaymessage(fd, "Warping to respawn point.");
return 0;
}
@@ -1642,38 +1315,35 @@ int atcommand_load (const int fd, struct map_session_data *sd,
*
*------------------------------------------
*/
-int atcommand_speed (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_speed(const int fd, struct map_session_data *sd,
+ const char *, const char *message)
{
- char output[200];
- int speed;
-
- memset (output, '\0', sizeof (output));
-
if (!message || !*message)
{
- sprintf (output,
- "Please, enter a speed value (usage: @speed <%d-%d>).",
- MIN_WALK_SPEED, MAX_WALK_SPEED);
- clif_displaymessage (fd, output);
+ std::string output = STRPRINTF(
+ "Please, enter a speed value (usage: @speed <%d-%d>).",
+ static_cast<uint32_t>(MIN_WALK_SPEED.count()),
+ static_cast<uint32_t>(MAX_WALK_SPEED.count()));
+ clif_displaymessage(fd, output);
return -1;
}
- speed = atoi (message);
+ interval_t speed = static_cast<interval_t>(atoi(message));
if (speed >= MIN_WALK_SPEED && speed <= MAX_WALK_SPEED)
{
sd->speed = speed;
//sd->walktimer = x;
//ã“ã®æ–‡ã‚’追加 by ã‚Œ
- clif_updatestatus (sd, SP_SPEED);
- clif_displaymessage (fd, "Speed changed.");
+ clif_updatestatus(sd, SP::SPEED);
+ clif_displaymessage(fd, "Speed changed.");
}
else
{
- sprintf (output,
- "Please, enter a valid speed value (usage: @speed <%d-%d>).",
- MIN_WALK_SPEED, MAX_WALK_SPEED);
- clif_displaymessage (fd, output);
+ std::string output = STRPRINTF(
+ "Please, enter a valid speed value (usage: @speed <%d-%d>).",
+ static_cast<uint32_t>(MIN_WALK_SPEED.count()),
+ static_cast<uint32_t>(MAX_WALK_SPEED.count()));
+ clif_displaymessage(fd, output);
return -1;
}
@@ -1684,26 +1354,26 @@ int atcommand_speed (const int fd, struct map_session_data *sd,
*
*------------------------------------------
*/
-int atcommand_storage (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_storage(const int fd, struct map_session_data *sd,
+ const char *, const char *)
{
struct storage *stor; //changes from Freya/Yor
- nullpo_retr (-1, sd);
+ nullpo_retr(-1, sd);
- if (sd->state.storage_flag)
+ if (sd->state.storage_open)
{
- clif_displaymessage (fd, "msg_table[250]");
+ clif_displaymessage(fd, "msg_table[250]");
return -1;
}
- if ((stor = account2storage2 (sd->status.account_id)) != NULL
+ if ((stor = account2storage2(sd->status.account_id)) != NULL
&& stor->storage_status == 1)
{
- clif_displaymessage (fd, "msg_table[250]");
+ clif_displaymessage(fd, "msg_table[250]");
return -1;
}
- storage_storageopen (sd);
+ storage_storageopen(sd);
return 0;
}
@@ -1712,107 +1382,32 @@ int atcommand_storage (const int fd, struct map_session_data *sd,
*
*------------------------------------------
*/
-int atcommand_guildstorage (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_option(const int fd, struct map_session_data *sd,
+ const char *, const char *message)
{
- struct storage *stor; //changes from Freya/Yor
- nullpo_retr (-1, sd);
-
- if (sd->status.guild_id > 0)
- {
- if (sd->state.storage_flag)
- {
- clif_displaymessage (fd, "msg_table[251]");
- return -1;
- }
- if ((stor = account2storage2 (sd->status.account_id)) != NULL
- && stor->storage_status == 1)
- {
- clif_displaymessage (fd, "msg_table[251]");
- return -1;
- }
- storage_guild_storageopen (sd);
- }
- else
- {
- clif_displaymessage (fd, "msg_table[252]");
- return -1;
- }
-
- return 0;
-}
-
-/*==========================================
- *
- *------------------------------------------
- */
-int atcommand_option (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
-{
- int param1 = 0, param2 = 0, param3 = 0;
- nullpo_retr (-1, sd);
+ int param1_ = 0, param2_ = 0, param3_ = 0;
+ nullpo_retr(-1, sd);
if (!message || !*message
- || sscanf (message, "%d %d %d", &param1, &param2, &param3) < 1
- || param1 < 0 || param2 < 0 || param3 < 0)
+ || sscanf(message, "%d %d %d", &param1_, &param2_, &param3_) < 1
+ || param1_ < 0 || param2_ < 0 || param3_ < 0)
{
- clif_displaymessage (fd,
+ clif_displaymessage(fd,
"Please, enter at least a option (usage: @option <param1:0+> <param2:0+> <param3:0+>).");
return -1;
}
+ Opt1 param1 = Opt1(param1_);
+ Opt2 param2 = Opt2(param2_);
+ Option param3 = Option(param3_);
+
sd->opt1 = param1;
sd->opt2 = param2;
- if (!(sd->status.option & CART_MASK) && param3 & CART_MASK)
- {
- clif_cart_itemlist (sd);
- clif_cart_equiplist (sd);
- clif_updatestatus (sd, SP_CARTINFO);
- }
sd->status.option = param3;
- // fix pecopeco display
- if (sd->status.pc_class == 13 || sd->status.pc_class == 21
- || sd->status.pc_class == 4014 || sd->status.pc_class == 4022)
- {
- if (!pc_isriding (sd))
- { // sd have the new value...
- if (sd->status.pc_class == 13)
- sd->status.pc_class = sd->view_class = 7;
- else if (sd->status.pc_class == 21)
- sd->status.pc_class = sd->view_class = 14;
- else if (sd->status.pc_class == 4014)
- sd->status.pc_class = sd->view_class = 4008;
- else if (sd->status.pc_class == 4022)
- sd->status.pc_class = sd->view_class = 4015;
- }
- }
- else
- {
- if (pc_isriding (sd))
- { // sd have the new value...
- if (sd->disguise > 0)
- { // temporary prevention of crash caused by peco + disguise, will look into a better solution [Valaris] (code added by [Yor])
- sd->status.option &= ~0x0020;
- }
- else
- {
- if (sd->status.pc_class == 7)
- sd->status.pc_class = sd->view_class = 13;
- else if (sd->status.pc_class == 14)
- sd->status.pc_class = sd->view_class = 21;
- else if (sd->status.pc_class == 4008)
- sd->status.pc_class = sd->view_class = 4014;
- else if (sd->status.pc_class == 4015)
- sd->status.pc_class = sd->view_class = 4022;
- else
- sd->status.option &= ~0x0020;
- }
- }
- }
- clif_changeoption (&sd->bl);
- pc_calcstatus (sd, 0);
- clif_displaymessage (fd, "Options changed.");
+ clif_changeoption(&sd->bl);
+ pc_calcstatus(sd, 0);
+ clif_displaymessage(fd, "Options changed.");
return 0;
}
@@ -1821,20 +1416,20 @@ int atcommand_option (const int fd, struct map_session_data *sd,
*
*------------------------------------------
*/
-int atcommand_hide (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_hide(const int fd, struct map_session_data *sd,
+ const char *, const char *)
{
- if (sd->status.option & OPTION_HIDE)
+ if (bool(sd->status.option & Option::HIDE))
{
- sd->status.option &= ~OPTION_HIDE;
- clif_displaymessage (fd, "Invisible: Off."); // Invisible: Off
+ sd->status.option &= ~Option::HIDE;
+ clif_displaymessage(fd, "Invisible: Off."); // Invisible: Off
}
else
{
- sd->status.option |= OPTION_HIDE;
- clif_displaymessage (fd, "Invisible: On."); // Invisible: On
+ sd->status.option |= Option::HIDE;
+ clif_displaymessage(fd, "Invisible: On."); // Invisible: On
}
- clif_changeoption (&sd->bl);
+ clif_changeoption(&sd->bl);
return 0;
}
@@ -1843,11 +1438,11 @@ int atcommand_hide (const int fd, struct map_session_data *sd,
*
*------------------------------------------
*/
-int atcommand_die (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_die(const int fd, struct map_session_data *sd,
+ const char *, const char *)
{
- pc_damage (NULL, sd, sd->status.hp + 1);
- clif_displaymessage (fd, "A pity! You've died.");
+ pc_damage(NULL, sd, sd->status.hp + 1);
+ clif_displaymessage(fd, "A pity! You've died.");
return 0;
}
@@ -1856,37 +1451,37 @@ int atcommand_die (const int fd, struct map_session_data *sd,
*
*------------------------------------------
*/
-int atcommand_kill (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_kill(const int fd, struct map_session_data *sd,
+ const char *, const char *message)
{
char character[100];
struct map_session_data *pl_sd;
- memset (character, '\0', sizeof (character));
+ memset(character, '\0', sizeof(character));
- if (!message || !*message || sscanf (message, "%99[^\n]", character) < 1)
+ if (!message || !*message || sscanf(message, "%99[^\n]", character) < 1)
{
- clif_displaymessage (fd,
+ clif_displaymessage(fd,
"Please, enter a player name (usage: @kill <char name>).");
return -1;
}
- if ((pl_sd = map_nick2sd (character)) != NULL)
+ if ((pl_sd = map_nick2sd(character)) != NULL)
{
- if (pc_isGM (sd) >= pc_isGM (pl_sd))
+ if (pc_isGM(sd) >= pc_isGM(pl_sd))
{ // you can kill only lower or same level
- pc_damage (NULL, pl_sd, pl_sd->status.hp + 1);
- clif_displaymessage (fd, "Character killed.");
+ pc_damage(NULL, pl_sd, pl_sd->status.hp + 1);
+ clif_displaymessage(fd, "Character killed.");
}
else
{
- clif_displaymessage (fd, "Your GM level don't authorise you to do this action on this player.");
+ clif_displaymessage(fd, "Your GM level don't authorise you to do this action on this player.");
return -1;
}
}
else
{
- clif_displaymessage (fd, "Character not found.");
+ clif_displaymessage(fd, "Character not found.");
return -1;
}
@@ -1897,18 +1492,18 @@ int atcommand_kill (const int fd, struct map_session_data *sd,
*
*------------------------------------------
*/
-int atcommand_alive (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_alive(const int fd, struct map_session_data *sd,
+ const char *, const char *)
{
sd->status.hp = sd->status.max_hp;
sd->status.sp = sd->status.max_sp;
- pc_setstand (sd);
- if (battle_config.pc_invincible_time > 0)
- pc_setinvincibletimer (sd, battle_config.pc_invincible_time);
- clif_updatestatus (sd, SP_HP);
- clif_updatestatus (sd, SP_SP);
- clif_resurrection (&sd->bl, 1);
- clif_displaymessage (fd, "You've been revived! It's a miracle!");
+ pc_setstand(sd);
+ if (static_cast<interval_t>(battle_config.pc_invincible_time) > interval_t::zero())
+ pc_setinvincibletimer(sd, static_cast<interval_t>(battle_config.pc_invincible_time));
+ clif_updatestatus(sd, SP::HP);
+ clif_updatestatus(sd, SP::SP);
+ clif_resurrection(&sd->bl, 1);
+ clif_displaymessage(fd, "You've been revived! It's a miracle!");
return 0;
}
@@ -1917,22 +1512,17 @@ int atcommand_alive (const int fd, struct map_session_data *sd,
*
*------------------------------------------
*/
-int atcommand_kami (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_kami(const int fd, struct map_session_data *,
+ const char *, const char *message)
{
- char output[200];
-
- memset (output, '\0', sizeof (output));
-
if (!message || !*message)
{
- clif_displaymessage (fd,
+ clif_displaymessage(fd,
"Please, enter a message (usage: @kami <message>).");
return -1;
}
- sscanf (message, "%199[^\n]", output);
- intif_GMmessage (output, strlen (output) + 1, 0);
+ intif_GMmessage(message, 0);
return 0;
}
@@ -1941,12 +1531,12 @@ int atcommand_kami (const int fd, struct map_session_data *sd,
*
*------------------------------------------
*/
-int atcommand_heal (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_heal(const int fd, struct map_session_data *sd,
+ const char *, const char *message)
{
- int hp = 0, sp = 0; // [Valaris] thanks to fov
+ int hp = 0, sp = 0; // [Valaris] thanks to fov
- sscanf (message, "%d %d", &hp, &sp);
+ sscanf(message, "%d %d", &hp, &sp);
if (hp == 0 && sp == 0)
{
@@ -1965,24 +1555,20 @@ int atcommand_heal (const int fd, struct map_session_data *sd,
sp = 1 - sd->status.sp;
}
- if (hp > 0) // display like heal
- clif_heal (fd, SP_HP, hp);
- else if (hp < 0) // display like damage
- clif_damage (&sd->bl, &sd->bl, gettick (), 0, 0, -hp, 0, 4, 0);
- if (sp > 0) // no display when we lost SP
- clif_heal (fd, SP_SP, sp);
+ if (hp < 0) // display like damage
+ clif_damage(&sd->bl, &sd->bl, gettick(), interval_t::zero(), interval_t::zero(), -hp, 0, DamageType::RETURNED, 0);
if (hp != 0 || sp != 0)
{
- pc_heal (sd, hp, sp);
+ pc_heal(sd, hp, sp);
if (hp >= 0 && sp >= 0)
- clif_displaymessage (fd, "HP, SP recovered.");
+ clif_displaymessage(fd, "HP, SP recovered.");
else
- clif_displaymessage (fd, "HP or/and SP modified.");
+ clif_displaymessage(fd, "HP or/and SP modified.");
}
else
{
- clif_displaymessage (fd, "HP and SP are already with the good value.");
+ clif_displaymessage(fd, "HP and SP are already with the good value.");
return -1;
}
@@ -1993,21 +1579,21 @@ int atcommand_heal (const int fd, struct map_session_data *sd,
* @item command (usage: @item <name/id_of_item> <quantity>)
*------------------------------------------
*/
-int atcommand_item (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_item(const int fd, struct map_session_data *sd,
+ const char *, const char *message)
{
char item_name[100];
- int number = 0, item_id, flag;
+ int number = 0, item_id;
struct item item_tmp;
struct item_data *item_data;
- int get_count, i;
+ int get_count, i;
- memset (item_name, '\0', sizeof (item_name));
+ memset(item_name, '\0', sizeof(item_name));
if (!message || !*message
- || sscanf (message, "%99s %d", item_name, &number) < 1)
+ || sscanf(message, "%99s %d", item_name, &number) < 1)
{
- clif_displaymessage (fd,
+ clif_displaymessage(fd,
"Please, enter an item name/id (usage: @item <item name or ID> [quantity]).");
return -1;
}
@@ -2016,33 +1602,35 @@ int atcommand_item (const int fd, struct map_session_data *sd,
number = 1;
item_id = 0;
- if ((item_data = itemdb_searchname (item_name)) != NULL ||
- (item_data = itemdb_exists (atoi (item_name))) != NULL)
+ if ((item_data = itemdb_searchname(item_name)) != NULL ||
+ (item_data = itemdb_exists(atoi(item_name))) != NULL)
item_id = item_data->nameid;
if (item_id >= 500)
{
get_count = number;
- if (item_data->type == 4 || item_data->type == 5 ||
- item_data->type == 7 || item_data->type == 8)
+ if (item_data->type == ItemType::WEAPON
+ || item_data->type == ItemType::ARMOR
+ || item_data->type == ItemType::_7
+ || item_data->type == ItemType::_8)
{
get_count = 1;
}
for (i = 0; i < number; i += get_count)
{
- memset (&item_tmp, 0, sizeof (item_tmp));
+ memset(&item_tmp, 0, sizeof(item_tmp));
item_tmp.nameid = item_id;
item_tmp.identify = 1;
- if ((flag =
- pc_additem ((struct map_session_data *) sd, &item_tmp,
- get_count)))
- clif_additem ((struct map_session_data *) sd, 0, 0, flag);
+ PickupFail flag;
+ if ((flag = pc_additem(sd, &item_tmp, get_count))
+ != PickupFail::OKAY)
+ clif_additem(sd, 0, 0, flag);
}
- clif_displaymessage (fd, "Item created.");
+ clif_displaymessage(fd, "Item created.");
}
else
{
- clif_displaymessage (fd, "Invalid item ID or name.");
+ clif_displaymessage(fd, "Invalid item ID or name.");
return -1;
}
@@ -2053,18 +1641,18 @@ int atcommand_item (const int fd, struct map_session_data *sd,
*
*------------------------------------------
*/
-int atcommand_itemreset (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_itemreset(const int fd, struct map_session_data *sd,
+ const char *, const char *)
{
- int i;
+ int i;
for (i = 0; i < MAX_INVENTORY; i++)
{
if (sd->status.inventory[i].amount
- && sd->status.inventory[i].equip == 0)
- pc_delitem (sd, i, sd->status.inventory[i].amount, 0);
+ && sd->status.inventory[i].equip == EPOS::ZERO)
+ pc_delitem(sd, i, sd->status.inventory[i].amount, 0);
}
- clif_displaymessage (fd, "All of your items have been removed.");
+ clif_displaymessage(fd, "All of your items have been removed.");
return 0;
}
@@ -2073,10 +1661,10 @@ int atcommand_itemreset (const int fd, struct map_session_data *sd,
*
*------------------------------------------
*/
-int atcommand_itemcheck (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_itemcheck(const int, struct map_session_data *sd,
+ const char *, const char *)
{
- pc_checkitem (sd);
+ pc_checkitem(sd);
return 0;
}
@@ -2085,14 +1673,14 @@ int atcommand_itemcheck (const int fd, struct map_session_data *sd,
*
*------------------------------------------
*/
-int atcommand_baselevelup (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_baselevelup(const int fd, struct map_session_data *sd,
+ const char *, const char *message)
{
- int level, i;
+ int level, i;
- if (!message || !*message || (level = atoi (message)) == 0)
+ if (!message || !*message || (level = atoi(message)) == 0)
{
- clif_displaymessage (fd,
+ clif_displaymessage(fd,
"Please, enter a level adjustement (usage: @blvl <number of levels>).");
return -1;
}
@@ -2101,7 +1689,7 @@ int atcommand_baselevelup (const int fd, struct map_session_data *sd,
{
if (sd->status.base_level == battle_config.maximum_level)
{ // check for max level by Valaris
- clif_displaymessage (fd, "Base level can't go any higher.");
+ clif_displaymessage(fd, "Base level can't go any higher.");
return -1;
} // End Addition
if (level > battle_config.maximum_level || level > (battle_config.maximum_level - sd->status.base_level)) // fix positiv overflow
@@ -2109,19 +1697,19 @@ int atcommand_baselevelup (const int fd, struct map_session_data *sd,
for (i = 1; i <= level; i++)
sd->status.status_point += (sd->status.base_level + i + 14) / 4;
sd->status.base_level += level;
- clif_updatestatus (sd, SP_BASELEVEL);
- clif_updatestatus (sd, SP_NEXTBASEEXP);
- clif_updatestatus (sd, SP_STATUSPOINT);
- pc_calcstatus (sd, 0);
- pc_heal (sd, sd->status.max_hp, sd->status.max_sp);
- clif_misceffect (&sd->bl, 0);
- clif_displaymessage (fd, "Base level raised.");
+ clif_updatestatus(sd, SP::BASELEVEL);
+ clif_updatestatus(sd, SP::NEXTBASEEXP);
+ clif_updatestatus(sd, SP::STATUSPOINT);
+ pc_calcstatus(sd, 0);
+ pc_heal(sd, sd->status.max_hp, sd->status.max_sp);
+ clif_misceffect(&sd->bl, 0);
+ clif_displaymessage(fd, "Base level raised.");
}
else
{
if (sd->status.base_level == 1)
{
- clif_displaymessage (fd, "Base level can't go any lower.");
+ clif_displaymessage(fd, "Base level can't go any lower.");
return -1;
}
if (level < -battle_config.maximum_level || level < (1 - sd->status.base_level)) // fix negativ overflow
@@ -2133,13 +1721,13 @@ int atcommand_baselevelup (const int fd, struct map_session_data *sd,
(sd->status.base_level + i + 14) / 4;
if (sd->status.status_point < 0)
sd->status.status_point = 0;
- clif_updatestatus (sd, SP_STATUSPOINT);
+ clif_updatestatus(sd, SP::STATUSPOINT);
} // to add: remove status points from stats
sd->status.base_level += level;
- clif_updatestatus (sd, SP_BASELEVEL);
- clif_updatestatus (sd, SP_NEXTBASEEXP);
- pc_calcstatus (sd, 0);
- clif_displaymessage (fd, "Base level lowered.");
+ clif_updatestatus(sd, SP::BASELEVEL);
+ clif_updatestatus(sd, SP::NEXTBASEEXP);
+ pc_calcstatus(sd, 0);
+ clif_displaymessage(fd, "Base level lowered.");
}
return 0;
@@ -2149,63 +1737,61 @@ int atcommand_baselevelup (const int fd, struct map_session_data *sd,
*
*------------------------------------------
*/
-int atcommand_joblevelup (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+// TODO: merge this with pc_setparam(SP::JOBLEVEL)
+// then fix the funny 50 and/or 10 limitation.
+int atcommand_joblevelup(const int fd, struct map_session_data *sd,
+ const char *, const char *message)
{
- int up_level = 50, level;
+ int up_level = 50, level;
- if (!message || !*message || (level = atoi (message)) == 0)
+ if (!message || !*message || (level = atoi(message)) == 0)
{
- clif_displaymessage (fd,
+ clif_displaymessage(fd,
"Please, enter a level adjustement (usage: @jlvl <number of levels>).");
return -1;
}
- if (sd->status.pc_class == 0 || sd->status.pc_class == 4001)
- up_level -= 40;
- else if ((sd->status.pc_class > 4007 && sd->status.pc_class < 4024)
- || sd->status.pc_class == 23)
- up_level += 20;
+ up_level -= 40;
if (level > 0)
{
if (sd->status.job_level == up_level)
{
- clif_displaymessage (fd, "Job level can't go any higher.");
+ clif_displaymessage(fd, "Job level can't go any higher.");
return -1;
}
if (level > up_level || level > (up_level - sd->status.job_level)) // fix positiv overflow
level = up_level - sd->status.job_level;
sd->status.job_level += level;
- clif_updatestatus (sd, SP_JOBLEVEL);
- clif_updatestatus (sd, SP_NEXTJOBEXP);
+ clif_updatestatus(sd, SP::JOBLEVEL);
+ clif_updatestatus(sd, SP::NEXTJOBEXP);
sd->status.skill_point += level;
- clif_updatestatus (sd, SP_SKILLPOINT);
- pc_calcstatus (sd, 0);
- clif_misceffect (&sd->bl, 1);
- clif_displaymessage (fd, "Job level raised.");
+ clif_updatestatus(sd, SP::SKILLPOINT);
+ pc_calcstatus(sd, 0);
+ clif_misceffect(&sd->bl, 1);
+ clif_displaymessage(fd, "Job level raised.");
}
else
{
if (sd->status.job_level == 1)
{
- clif_displaymessage (fd, "Job level can't go any lower.");
+ clif_displaymessage(fd, "Job level can't go any lower.");
return -1;
}
if (level < -up_level || level < (1 - sd->status.job_level)) // fix negativ overflow
level = 1 - sd->status.job_level;
sd->status.job_level += level;
- clif_updatestatus (sd, SP_JOBLEVEL);
- clif_updatestatus (sd, SP_NEXTJOBEXP);
+ clif_updatestatus(sd, SP::JOBLEVEL);
+ clif_updatestatus(sd, SP::NEXTJOBEXP);
if (sd->status.skill_point > 0)
{
sd->status.skill_point += level;
if (sd->status.skill_point < 0)
sd->status.skill_point = 0;
- clif_updatestatus (sd, SP_SKILLPOINT);
+ clif_updatestatus(sd, SP::SKILLPOINT);
} // to add: remove status points from skills
- pc_calcstatus (sd, 0);
- clif_displaymessage (fd, "Job level lowered.");
+ pc_calcstatus(sd, 0);
+ clif_displaymessage(fd, "Job level lowered.");
}
return 0;
@@ -2215,20 +1801,20 @@ int atcommand_joblevelup (const int fd, struct map_session_data *sd,
*
*------------------------------------------
*/
-int atcommand_help (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_help(const int fd, struct map_session_data *sd,
+ const char *, const char *)
{
char buf[2048], w1[2048], w2[2048];
- int i, gm_level;
+ int i, gm_level;
FILE *fp;
- memset (buf, '\0', sizeof (buf));
+ memset(buf, '\0', sizeof(buf));
- if ((fp = fopen_ (help_txt, "r")) != NULL)
+ if ((fp = fopen_(help_txt, "r")) != NULL)
{
- clif_displaymessage (fd, "Help commands:");
- gm_level = pc_isGM (sd);
- while (fgets (buf, sizeof (buf) - 1, fp) != NULL)
+ clif_displaymessage(fd, "Help commands:");
+ gm_level = pc_isGM(sd);
+ while (fgets(buf, sizeof(buf) - 1, fp) != NULL)
{
if (buf[0] == '/' && buf[1] == '/')
continue;
@@ -2240,16 +1826,16 @@ int atcommand_help (const int fd, struct map_session_data *sd,
break;
}
}
- if (sscanf (buf, "%2047[^:]:%2047[^\n]", w1, w2) < 2)
- clif_displaymessage (fd, buf);
- else if (gm_level >= atoi (w1))
- clif_displaymessage (fd, w2);
+ if (sscanf(buf, "%2047[^:]:%2047[^\n]", w1, w2) < 2)
+ clif_displaymessage(fd, buf);
+ else if (gm_level >= atoi(w1))
+ clif_displaymessage(fd, w2);
}
- fclose_ (fp);
+ fclose_(fp);
}
else
{
- clif_displaymessage (fd, "File help.txt not found.");
+ clif_displaymessage(fd, "File help.txt not found.");
return -1;
}
@@ -2260,28 +1846,28 @@ int atcommand_help (const int fd, struct map_session_data *sd,
*
*------------------------------------------
*/
-int atcommand_gm (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_gm(const int fd, struct map_session_data *sd,
+ const char *, const char *message)
{
char password[100];
- memset (password, '\0', sizeof (password));
+ memset(password, '\0', sizeof(password));
- if (!message || !*message || sscanf (message, "%99[^\n]", password) < 1)
+ if (!message || !*message || sscanf(message, "%99[^\n]", password) < 1)
{
- clif_displaymessage (fd,
+ clif_displaymessage(fd,
"Please, enter a password (usage: @gm <password>).");
return -1;
}
- if (pc_isGM (sd))
+ if (pc_isGM(sd))
{ // a GM can not use this function. only a normal player (become gm is not for gm!)
- clif_displaymessage (fd, "You already have some GM powers.");
+ clif_displaymessage(fd, "You already have some GM powers.");
return -1;
}
else
- chrif_changegm (sd->status.account_id, password,
- strlen (password) + 1);
+ chrif_changegm(sd->status.account_id, password,
+ strlen(password) + 1);
return 0;
}
@@ -2290,22 +1876,21 @@ int atcommand_gm (const int fd, struct map_session_data *sd,
*
*------------------------------------------
*/
-int atcommand_pvpoff (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_pvpoff(const int fd, struct map_session_data *sd,
+ const char *, const char *)
{
struct map_session_data *pl_sd;
- int i;
+ int i;
if (battle_config.pk_mode)
{ //disable command if server is in PK mode [Valaris]
- clif_displaymessage (fd, "This option cannot be used in PK Mode.");
+ clif_displaymessage(fd, "This option cannot be used in PK Mode.");
return -1;
}
if (map[sd->bl.m].flag.pvp)
{
map[sd->bl.m].flag.pvp = 0;
- clif_send0199 (sd->bl.m, 0);
for (i = 0; i < fd_max; i++)
{ //人数分ループ
if (session[i] && (pl_sd = (struct map_session_data *)session[i]->session_data)
@@ -2313,21 +1898,15 @@ int atcommand_pvpoff (const int fd, struct map_session_data *sd,
{
if (sd->bl.m == pl_sd->bl.m)
{
- clif_pvpset (pl_sd, 0, 0, 2);
- if (pl_sd->pvp_timer != -1)
- {
- delete_timer (pl_sd->pvp_timer,
- pc_calc_pvprank_timer);
- pl_sd->pvp_timer = -1;
- }
+ pl_sd->pvp_timer.cancel();
}
}
}
- clif_displaymessage (fd, "PvP: Off.");
+ clif_displaymessage(fd, "PvP: Off.");
}
else
{
- clif_displaymessage (fd, "PvP is already Off.");
+ clif_displaymessage(fd, "PvP is already Off.");
return -1;
}
@@ -2338,87 +1917,41 @@ int atcommand_pvpoff (const int fd, struct map_session_data *sd,
*
*------------------------------------------
*/
-int atcommand_pvpon (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_pvpon(const int fd, struct map_session_data *sd,
+ const char *, const char *)
{
struct map_session_data *pl_sd;
- int i;
+ int i;
if (battle_config.pk_mode)
{ //disable command if server is in PK mode [Valaris]
- clif_displaymessage (fd, "This option cannot be used in PK Mode.");
+ clif_displaymessage(fd, "This option cannot be used in PK Mode.");
return -1;
}
if (!map[sd->bl.m].flag.pvp && !map[sd->bl.m].flag.nopvp)
{
map[sd->bl.m].flag.pvp = 1;
- clif_send0199 (sd->bl.m, 1);
for (i = 0; i < fd_max; i++)
{
if (session[i] && (pl_sd = (struct map_session_data *)session[i]->session_data)
&& pl_sd->state.auth)
{
- if (sd->bl.m == pl_sd->bl.m && pl_sd->pvp_timer == -1)
+ if (sd->bl.m == pl_sd->bl.m && !pl_sd->pvp_timer)
{
- pl_sd->pvp_timer = add_timer (gettick () + 200,
- pc_calc_pvprank_timer,
- pl_sd->bl.id, 0);
+ pl_sd->pvp_timer = Timer(gettick() + std::chrono::milliseconds(200),
+ std::bind(pc_calc_pvprank_timer, ph::_1, ph::_2, pl_sd->bl.id));
pl_sd->pvp_rank = 0;
pl_sd->pvp_lastusers = 0;
pl_sd->pvp_point = 5;
}
}
}
- clif_displaymessage (fd, "PvP: On.");
- }
- else
- {
- clif_displaymessage (fd, "PvP is already On.");
- return -1;
- }
-
- return 0;
-}
-
-/*==========================================
- *
- *------------------------------------------
- */
-int atcommand_gvgoff (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
-{
- if (map[sd->bl.m].flag.gvg)
- {
- map[sd->bl.m].flag.gvg = 0;
- clif_send0199 (sd->bl.m, 0);
- clif_displaymessage (fd, "GvG: Off.");
- }
- else
- {
- clif_displaymessage (fd, "GvG is already Off.");
- return -1;
- }
-
- return 0;
-}
-
-/*==========================================
- *
- *------------------------------------------
- */
-int atcommand_gvgon (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
-{
- if (!map[sd->bl.m].flag.gvg)
- {
- map[sd->bl.m].flag.gvg = 1;
- clif_send0199 (sd->bl.m, 3);
- clif_displaymessage (fd, "GvG: On.");
+ clif_displaymessage(fd, "PvP: On.");
}
else
{
- clif_displaymessage (fd, "GvG is already On.");
+ clif_displaymessage(fd, "PvP is already On.");
return -1;
}
@@ -2429,23 +1962,21 @@ int atcommand_gvgon (const int fd, struct map_session_data *sd,
*
*------------------------------------------
*/
-int atcommand_model (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_model(const int fd, struct map_session_data *sd,
+ const char *, const char *message)
{
- int hair_style = 0, hair_color = 0, cloth_color = 0;
- char output[200];
-
- memset (output, '\0', sizeof (output));
+ int hair_style = 0, hair_color = 0, cloth_color = 0;
if (!message || !*message
- || sscanf (message, "%d %d %d", &hair_style, &hair_color,
+ || sscanf(message, "%d %d %d", &hair_style, &hair_color,
&cloth_color) < 1)
{
- sprintf (output,
- "Please, enter at least a value (usage: @model <hair ID: %d-%d> <hair color: %d-%d> <clothes color: %d-%d>).",
- MIN_HAIR_STYLE, MAX_HAIR_STYLE, MIN_HAIR_COLOR,
- MAX_HAIR_COLOR, MIN_CLOTH_COLOR, MAX_CLOTH_COLOR);
- clif_displaymessage (fd, output);
+ std::string output = STRPRINTF(
+ "Please, enter at least a value (usage: @model <hair ID: %d-%d> <hair color: %d-%d> <clothes color: %d-%d>).",
+ MIN_HAIR_STYLE, MAX_HAIR_STYLE,
+ MIN_HAIR_COLOR, MAX_HAIR_COLOR,
+ MIN_CLOTH_COLOR, MAX_CLOTH_COLOR);
+ clif_displaymessage(fd, output);
return -1;
}
@@ -2453,25 +1984,16 @@ int atcommand_model (const int fd, struct map_session_data *sd,
hair_color >= MIN_HAIR_COLOR && hair_color <= MAX_HAIR_COLOR &&
cloth_color >= MIN_CLOTH_COLOR && cloth_color <= MAX_CLOTH_COLOR)
{
- //æœã®è‰²å¤‰æ›´
- if (cloth_color != 0 && sd->status.sex == 1
- && (sd->status.pc_class == 12 || sd->status.pc_class == 17))
- {
- //æœã®è‰²æœªå®Ÿè£…è·ã®åˆ¤å®š
- clif_displaymessage (fd, "You can't use this command with this class.");
- return -1;
- }
- else
{
- pc_changelook (sd, LOOK_HAIR, hair_style);
- pc_changelook (sd, LOOK_HAIR_COLOR, hair_color);
- pc_changelook (sd, LOOK_CLOTHES_COLOR, cloth_color);
- clif_displaymessage (fd, "Appearence changed.");
+ pc_changelook(sd, LOOK::HAIR, hair_style);
+ pc_changelook(sd, LOOK::HAIR_COLOR, hair_color);
+ pc_changelook(sd, LOOK::CLOTHES_COLOR, cloth_color);
+ clif_displaymessage(fd, "Appearence changed.");
}
}
else
{
- clif_displaymessage (fd, "An invalid number was specified.");
+ clif_displaymessage(fd, "An invalid number was specified.");
return -1;
}
@@ -2482,40 +2004,30 @@ int atcommand_model (const int fd, struct map_session_data *sd,
* @dye && @ccolor
*------------------------------------------
*/
-int atcommand_dye (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_dye(const int fd, struct map_session_data *sd,
+ const char *, const char *message)
{
- int cloth_color = 0;
- char output[200];
-
- memset (output, '\0', sizeof (output));
+ int cloth_color = 0;
- if (!message || !*message || sscanf (message, "%d", &cloth_color) < 1)
+ if (!message || !*message || sscanf(message, "%d", &cloth_color) < 1)
{
- sprintf (output,
- "Please, enter a clothes color (usage: @dye/@ccolor <clothes color: %d-%d>).",
- MIN_CLOTH_COLOR, MAX_CLOTH_COLOR);
- clif_displaymessage (fd, output);
+ std::string output = STRPRINTF(
+ "Please, enter a clothes color (usage: @dye/@ccolor <clothes color: %d-%d>).",
+ MIN_CLOTH_COLOR, MAX_CLOTH_COLOR);
+ clif_displaymessage(fd, output);
return -1;
}
if (cloth_color >= MIN_CLOTH_COLOR && cloth_color <= MAX_CLOTH_COLOR)
{
- if (cloth_color != 0 && sd->status.sex == 1
- && (sd->status.pc_class == 12 || sd->status.pc_class == 17))
{
- clif_displaymessage (fd, "You can't use this command with this class.");
- return -1;
- }
- else
- {
- pc_changelook (sd, LOOK_CLOTHES_COLOR, cloth_color);
- clif_displaymessage (fd, "Appearence changed.");
+ pc_changelook(sd, LOOK::CLOTHES_COLOR, cloth_color);
+ clif_displaymessage(fd, "Appearence changed.");
}
}
else
{
- clif_displaymessage (fd, "An invalid number was specified.");
+ clif_displaymessage(fd, "An invalid number was specified.");
return -1;
}
@@ -2523,54 +2035,33 @@ int atcommand_dye (const int fd, struct map_session_data *sd,
}
/*==========================================
- * @chardye by [MouseJstr]
- *------------------------------------------
- */
-int
-atcommand_chardye (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
-{
- return 0;
-}
-
-/*==========================================
* @hairstyle && @hstyle
*------------------------------------------
*/
-int atcommand_hair_style (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_hair_style(const int fd, struct map_session_data *sd,
+ const char *, const char *message)
{
- int hair_style = 0;
- char output[200];
+ int hair_style = 0;
- memset (output, '\0', sizeof (output));
-
- if (!message || !*message || sscanf (message, "%d", &hair_style) < 1)
+ if (!message || !*message || sscanf(message, "%d", &hair_style) < 1)
{
- sprintf (output,
- "Please, enter a hair style (usage: @hairstyle/@hstyle <hair ID: %d-%d>).",
- MIN_HAIR_STYLE, MAX_HAIR_STYLE);
- clif_displaymessage (fd, output);
+ std::string output = STRPRINTF(
+ "Please, enter a hair style (usage: @hairstyle/@hstyle <hair ID: %d-%d>).",
+ MIN_HAIR_STYLE, MAX_HAIR_STYLE);
+ clif_displaymessage(fd, output);
return -1;
}
if (hair_style >= MIN_HAIR_STYLE && hair_style <= MAX_HAIR_STYLE)
{
- if (hair_style != 0 && sd->status.sex == 1
- && (sd->status.pc_class == 12 || sd->status.pc_class == 17))
- {
- clif_displaymessage (fd, "You can't use this command with this class.");
- return -1;
- }
- else
{
- pc_changelook (sd, LOOK_HAIR, hair_style);
- clif_displaymessage (fd, "Appearence changed.");
+ pc_changelook(sd, LOOK::HAIR, hair_style);
+ clif_displaymessage(fd, "Appearence changed.");
}
}
else
{
- clif_displaymessage (fd, "An invalid number was specified.");
+ clif_displaymessage(fd, "An invalid number was specified.");
return -1;
}
@@ -2578,315 +2069,35 @@ int atcommand_hair_style (const int fd, struct map_session_data *sd,
}
/*==========================================
- * @charhairstyle by [MouseJstr]
- *------------------------------------------
- */
-int
-atcommand_charhairstyle (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
-{
- return 0;
-}
-
-/*==========================================
* @haircolor && @hcolor
*------------------------------------------
*/
-int atcommand_hair_color (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_hair_color(const int fd, struct map_session_data *sd,
+ const char *, const char *message)
{
- int hair_color = 0;
- char output[200];
-
- memset (output, '\0', sizeof (output));
+ int hair_color = 0;
- if (!message || !*message || sscanf (message, "%d", &hair_color) < 1)
+ if (!message || !*message || sscanf(message, "%d", &hair_color) < 1)
{
- sprintf (output,
- "Please, enter a hair color (usage: @haircolor/@hcolor <hair color: %d-%d>).",
- MIN_HAIR_COLOR, MAX_HAIR_COLOR);
- clif_displaymessage (fd, output);
+ std::string output = STRPRINTF(
+ "Please, enter a hair color (usage: @haircolor/@hcolor <hair color: %d-%d>).",
+ MIN_HAIR_COLOR, MAX_HAIR_COLOR);
+ clif_displaymessage(fd, output);
return -1;
}
if (hair_color >= MIN_HAIR_COLOR && hair_color <= MAX_HAIR_COLOR)
{
- if (hair_color != 0 && sd->status.sex == 1
- && (sd->status.pc_class == 12 || sd->status.pc_class == 17))
{
- clif_displaymessage (fd, "You can't use this command with this class.");
- return -1;
- }
- else
- {
- pc_changelook (sd, LOOK_HAIR_COLOR, hair_color);
- clif_displaymessage (fd, "Appearence changed.");
+ pc_changelook(sd, LOOK::HAIR_COLOR, hair_color);
+ clif_displaymessage(fd, "Appearence changed.");
}
}
else
{
- clif_displaymessage (fd, "An invalid number was specified.");
- return -1;
- }
-
- return 0;
-}
-
-/*==========================================
- * @charhaircolor by [MouseJstr]
- *------------------------------------------
- */
-int
-atcommand_charhaircolor (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
-{
- return 0;
-}
-
-/*==========================================
- * @go [city_number/city_name]: improved by [yor] to add city names and help
- *------------------------------------------
- */
-int atcommand_go (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
-{
- int i;
- int town;
- char map_name[100];
- char output[200];
- int m;
-
- struct
- {
- char map[16];
- int x, y;
- } data[] =
- {
- {
- "prontera.gat", 156, 191}, // 0=Prontera
- {
- "morocc.gat", 156, 93}, // 1=Morroc
- {
- "geffen.gat", 119, 59}, // 2=Geffen
- {
- "payon.gat", 162, 233}, // 3=Payon
- {
- "alberta.gat", 192, 147}, // 4=Alberta
- {
- "izlude.gat", 128, 114}, // 5=Izlude
- {
- "aldebaran.gat", 140, 131}, // 6=Al de Baran
- {
- "xmas.gat", 147, 134}, // 7=Lutie
- {
- "comodo.gat", 209, 143}, // 8=Comodo
- {
- "yuno.gat", 157, 51}, // 9=Yuno
- {
- "amatsu.gat", 198, 84}, // 10=Amatsu
- {
- "gonryun.gat", 160, 120}, // 11=Gon Ryun
- {
- "umbala.gat", 89, 157}, // 12=Umbala
- {
- "niflheim.gat", 21, 153}, // 13=Niflheim
- {
- "louyang.gat", 217, 40}, // 14=Lou Yang
- {
- "new_1-1.gat", 53, 111}, // 15=Start point
- {
- "sec_pri.gat", 23, 61}, // 16=Prison
- };
-
- memset (map_name, '\0', sizeof (map_name));
- memset (output, '\0', sizeof (output));
-
- // get the number
- town = atoi (message);
-
- // if no value, display all value
- if (!message || !*message || sscanf (message, "%99s", map_name) < 1
- || town < -3 || town >= (int) (sizeof (data) / sizeof (data[0])))
- {
- clif_displaymessage (fd, "Invalid location number or name.");
- clif_displaymessage (fd, "Please, use one of this number/name:");
- clif_displaymessage (fd,
- "-3=(Memo point 2) 4=Alberta 11=Gon Ryun");
- clif_displaymessage (fd,
- "-2=(Memo point 1) 5=Izlude 12=Umbala");
- clif_displaymessage (fd,
- "-1=(Memo point 0) 6=Al de Baran 13=Niflheim");
- clif_displaymessage (fd,
- " 0=Prontera 7=Lutie 14=Lou Yang");
- clif_displaymessage (fd,
- " 1=Morroc 8=Comodo 15=Start point");
- clif_displaymessage (fd,
- " 2=Geffen 9=Yuno 16=Prison");
- clif_displaymessage (fd, " 3=Payon 10=Amatsu");
+ clif_displaymessage(fd, "An invalid number was specified.");
return -1;
}
- else
- {
- // get possible name of the city and add .gat if not in the name
- map_name[sizeof (map_name) - 1] = '\0';
- for (i = 0; map_name[i]; i++)
- map_name[i] = tolower (map_name[i]);
- if (strstr (map_name, ".gat") == NULL && strstr (map_name, ".afm") == NULL && strlen (map_name) < 13) // 16 - 4 (.gat)
- strcat (map_name, ".gat");
- // try to see if it's a name, and not a number (try a lot of possibilities, write errors and abbreviations too)
- if (strncmp (map_name, "prontera.gat", 3) == 0)
- { // 3 first characters
- town = 0;
- }
- else if (strncmp (map_name, "morocc.gat", 3) == 0)
- { // 3 first characters
- town = 1;
- }
- else if (strncmp (map_name, "geffen.gat", 3) == 0)
- { // 3 first characters
- town = 2;
- }
- else if (strncmp (map_name, "payon.gat", 3) == 0 || // 3 first characters
- strncmp (map_name, "paion.gat", 3) == 0)
- { // writing error (3 first characters)
- town = 3;
- }
- else if (strncmp (map_name, "alberta.gat", 3) == 0)
- { // 3 first characters
- town = 4;
- }
- else if (strncmp (map_name, "izlude.gat", 3) == 0 || // 3 first characters
- strncmp (map_name, "islude.gat", 3) == 0)
- { // writing error (3 first characters)
- town = 5;
- }
- else if (strncmp (map_name, "aldebaran.gat", 3) == 0 || // 3 first characters
- strcmp (map_name, "al.gat") == 0)
- { // al (de baran)
- town = 6;
- }
- else if (strncmp (map_name, "lutie.gat", 3) == 0 || // name of the city, not name of the map (3 first characters)
- strcmp (map_name, "christmas.gat") == 0 || // name of the symbol
- strncmp (map_name, "xmas.gat", 3) == 0 || // 3 first characters
- strncmp (map_name, "x-mas.gat", 3) == 0)
- { // writing error (3 first characters)
- town = 7;
- }
- else if (strncmp (map_name, "comodo.gat", 3) == 0)
- { // 3 first characters
- town = 8;
- }
- else if (strncmp (map_name, "yuno.gat", 3) == 0)
- { // 3 first characters
- town = 9;
- }
- else if (strncmp (map_name, "amatsu.gat", 3) == 0 || // 3 first characters
- strncmp (map_name, "ammatsu.gat", 3) == 0)
- { // writing error (3 first characters)
- town = 10;
- }
- else if (strncmp (map_name, "gonryun.gat", 3) == 0)
- { // 3 first characters
- town = 11;
- }
- else if (strncmp (map_name, "umbala.gat", 3) == 0)
- { // 3 first characters
- town = 12;
- }
- else if (strncmp (map_name, "niflheim.gat", 3) == 0)
- { // 3 first characters
- town = 13;
- }
- else if (strncmp (map_name, "louyang.gat", 3) == 0)
- { // 3 first characters
- town = 14;
- }
- else if (strncmp (map_name, "new_1-1.gat", 3) == 0 || // 3 first characters (or "newbies")
- strncmp (map_name, "startpoint.gat", 3) == 0 || // name of the position (3 first characters)
- strncmp (map_name, "begining.gat", 3) == 0)
- { // name of the position (3 first characters)
- town = 15;
- }
- else if (strncmp (map_name, "sec_pri.gat", 3) == 0 || // 3 first characters
- strncmp (map_name, "prison.gat", 3) == 0 || // name of the position (3 first characters)
- strncmp (map_name, "jails.gat", 3) == 0)
- { // name of the position
- town = 16;
- }
-
- if (town >= -3 && town <= -1)
- {
- if (sd->status.memo_point[-town - 1].map[0])
- {
- m = map_mapname2mapid (sd->status.memo_point[-town - 1].map);
- if (m >= 0 && map[m].flag.nowarpto
- && battle_config.any_warp_GM_min_level > pc_isGM (sd))
- {
- clif_displaymessage (fd,
- "You are not authorised to warp you to this memo map.");
- return -1;
- }
- if (sd->bl.m >= 0 && map[sd->bl.m].flag.nowarp
- && battle_config.any_warp_GM_min_level > pc_isGM (sd))
- {
- clif_displaymessage (fd,
- "You are not authorised to warp you from your actual map.");
- return -1;
- }
- if (pc_setpos
- (sd, sd->status.memo_point[-town - 1].map,
- sd->status.memo_point[-town - 1].x,
- sd->status.memo_point[-town - 1].y, 3) == 0)
- {
- clif_displaymessage (fd, "Warped.");
- }
- else
- {
- clif_displaymessage (fd, "Map not found.");
- return -1;
- }
- }
- else
- {
- sprintf (output, "Your memo point #%d doesn't exist.", -town - 1);
- clif_displaymessage (fd, output);
- return -1;
- }
- }
- else if (town >= 0 && town < (int) (sizeof (data) / sizeof (data[0])))
- {
- m = map_mapname2mapid (data[town].map);
- if (m >= 0 && map[m].flag.nowarpto
- && battle_config.any_warp_GM_min_level > pc_isGM (sd))
- {
- clif_displaymessage (fd,
- "You are not authorised to warp you to this destination map.");
- return -1;
- }
- if (sd->bl.m >= 0 && map[sd->bl.m].flag.nowarp
- && battle_config.any_warp_GM_min_level > pc_isGM (sd))
- {
- clif_displaymessage (fd,
- "You are not authorised to warp you from your actual map.");
- return -1;
- }
- if (pc_setpos (sd, data[town].map, data[town].x, data[town].y, 3)
- == 0)
- {
- clif_displaymessage (fd, "Warped.");
- }
- else
- {
- clif_displaymessage (fd, "Map not found.");
- return -1;
- }
- }
- else
- { // if you arrive here, you have an error in town variable when reading of names
- clif_displaymessage (fd, "Invalid location number or name.");
- return -1;
- }
- }
return 0;
}
@@ -2895,41 +2106,39 @@ int atcommand_go (const int fd, struct map_session_data *sd,
*
*------------------------------------------
*/
-int atcommand_spawn (const int fd, struct map_session_data *sd,
+int atcommand_spawn(const int fd, struct map_session_data *sd,
const char *command, const char *message)
{
char monster[100];
- char output[200];
- int mob_id;
- int number = 0;
- int x = 0, y = 0;
- int count;
- int i, j, k;
- int mx, my, range;
+ int mob_id;
+ int number = 0;
+ int x = 0, y = 0;
+ int count;
+ int i, j, k;
+ int mx, my, range;
- memset (monster, '\0', sizeof (monster));
- memset (output, '\0', sizeof (output));
+ memset(monster, '\0', sizeof(monster));
if (!message || !*message
- || sscanf (message, "%99s %d %d %d", monster, &number, &x, &y) < 1)
+ || sscanf(message, "%99s %d %d %d", monster, &number, &x, &y) < 1)
{
- clif_displaymessage (fd, "Give a monster name/id please.");
+ clif_displaymessage(fd, "Give a monster name/id please.");
return -1;
}
// If monster identifier/name argument is a name
- if ((mob_id = mobdb_searchname (monster)) == 0) // check name first (to avoid possible name begining by a number)
- mob_id = mobdb_checkid (atoi (monster));
+ if ((mob_id = mobdb_searchname(monster)) == 0) // check name first (to avoid possible name begining by a number)
+ mob_id = mobdb_checkid(atoi(monster));
if (mob_id == 0)
{
- clif_displaymessage (fd, "Invalid monster ID or name.");
+ clif_displaymessage(fd, "Invalid monster ID or name.");
return -1;
}
if (mob_id == 1288)
{
- clif_displaymessage (fd, "Cannot spawn emperium.");
+ clif_displaymessage(fd, "Cannot spawn emperium.");
return -1;
}
@@ -2942,43 +2151,44 @@ int atcommand_spawn (const int fd, struct map_session_data *sd,
number = battle_config.atc_spawn_quantity_limit;
if (battle_config.etc_log)
- printf ("%s monster='%s' id=%d count=%d (%d,%d)\n", command, monster,
+ PRINTF("%s monster='%s' id=%d count=%d (%d,%d)\n", command, monster,
mob_id, number, x, y);
count = 0;
- range = sqrt (number) / 2;
+ range = sqrt(number) / 2;
range = range * 2 + 5; // calculation of an odd number (+ 4 area around)
for (i = 0; i < number; i++)
{
j = 0;
k = 0;
while (j++ < 8 && k == 0)
- { // try 8 times to spawn the monster (needed for close area)
+ {
+ // try 8 times to spawn the monster (needed for close area)
if (x <= 0)
- mx = sd->bl.x + (MRAND (range) - (range / 2));
+ mx = sd->bl.x + random_::in(-range / 2, range / 2 );
else
mx = x;
if (y <= 0)
- my = sd->bl.y + (MRAND (range) - (range / 2));
+ my = sd->bl.y + random_::in(-range / 2, range / 2);
else
my = y;
- k = mob_once_spawn ((struct map_session_data *) sd, "this", mx,
- my, "", mob_id, 1, "");
+ k = mob_once_spawn(sd, "this", mx, my, "", mob_id, 1, "");
}
count += (k != 0) ? 1 : 0;
}
if (count != 0)
if (number == count)
- clif_displaymessage (fd, "All monster summoned!");
+ clif_displaymessage(fd, "All monster summoned!");
else
{
- sprintf (output, "%d monster(s) summoned!", count);
- clif_displaymessage (fd, output);
+ std::string output = STRPRINTF("%d monster(s) summoned!",
+ count);
+ clif_displaymessage(fd, output);
}
else
{
- clif_displaymessage (fd, "Invalid monster ID or name.");
+ clif_displaymessage(fd, "Invalid monster ID or name.");
return -1;
}
@@ -2990,28 +2200,28 @@ int atcommand_spawn (const int fd, struct map_session_data *sd,
*------------------------------------------
*/
static
-void atcommand_killmonster_sub (const int fd, struct map_session_data *sd,
+void atcommand_killmonster_sub(const int fd, struct map_session_data *sd,
const char *message, const int drop)
{
- int map_id;
+ int map_id;
char map_name[100];
- memset (map_name, '\0', sizeof (map_name));
+ memset(map_name, '\0', sizeof(map_name));
- if (!message || !*message || sscanf (message, "%99s", map_name) < 1)
+ if (!message || !*message || sscanf(message, "%99s", map_name) < 1)
map_id = sd->bl.m;
else
{
- if (strstr (map_name, ".gat") == NULL && strstr (map_name, ".afm") == NULL && strlen (map_name) < 13) // 16 - 4 (.gat)
- strcat (map_name, ".gat");
- if ((map_id = map_mapname2mapid (map_name)) < 0)
+ if (strstr(map_name, ".gat") == NULL && strstr(map_name, ".afm") == NULL && strlen(map_name) < 13) // 16 - 4 (.gat)
+ strcat(map_name, ".gat");
+ if ((map_id = map_mapname2mapid(map_name)) < 0)
map_id = sd->bl.m;
}
- map_foreachinarea (atkillmonster_sub, map_id, 0, 0, map[map_id].xs,
- map[map_id].ys, BL_MOB, drop);
+ map_foreachinarea(std::bind(atkillmonster_sub, ph::_1, drop), map_id, 0, 0, map[map_id].xs,
+ map[map_id].ys, BL::MOB);
- clif_displaymessage (fd, "All monsters killed!");
+ clif_displaymessage(fd, "All monsters killed!");
return;
}
@@ -3020,40 +2230,10 @@ void atcommand_killmonster_sub (const int fd, struct map_session_data *sd,
*
*------------------------------------------
*/
-int atcommand_killmonster (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
-{
- atcommand_killmonster_sub (fd, sd, message, 1);
-
- return 0;
-}
-
-/*==========================================
- *
- *------------------------------------------
- */
-static int atlist_nearby_sub (struct block_list *bl, va_list ap)
-{
- char buf[32];
- int fd = va_arg (ap, int);
- nullpo_retr (0, bl);
-
- sprintf (buf, " - \"%s\"", ((struct map_session_data *) bl)->status.name);
- clif_displaymessage (fd, buf);
-
- return 0;
-}
-
-/*==========================================
- *
- *------------------------------------------
- */
-int atcommand_list_nearby (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_killmonster(const int fd, struct map_session_data *sd,
+ const char *, const char *message)
{
- clif_displaymessage (fd, "Nearby players:");
- map_foreachinarea (atlist_nearby_sub, sd->bl.m, sd->bl.x - 1,
- sd->bl.y - 1, sd->bl.x + 1, sd->bl.x + 1, BL_PC, fd);
+ atcommand_killmonster_sub(fd, sd, message, 1);
return 0;
}
@@ -3062,157 +2242,39 @@ int atcommand_list_nearby (const int fd, struct map_session_data *sd,
*
*------------------------------------------
*/
-int atcommand_killmonster2 (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+static
+void atlist_nearby_sub(struct block_list *bl, int fd)
{
- atcommand_killmonster_sub (fd, sd, message, 0);
+ nullpo_retv(bl);
- return 0;
+ std::string buf = STRPRINTF(" - \"%s\"",
+ ((struct map_session_data *) bl)->status.name);
+ clif_displaymessage(fd, buf);
}
/*==========================================
*
*------------------------------------------
*/
-int atcommand_produce (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_list_nearby(const int fd, struct map_session_data *sd,
+ const char *, const char *)
{
- char item_name[100];
- int item_id, attribute = 0, star = 0;
- int flag = 0;
- struct item_data *item_data;
- struct item tmp_item;
- char output[200];
-
- memset (output, '\0', sizeof (output));
- memset (item_name, '\0', sizeof (item_name));
-
- if (!message || !*message
- || sscanf (message, "%99s %d %d", item_name, &attribute, &star) < 1)
- {
- clif_displaymessage (fd,
- "Please, enter at least an item name/id (usage: @produce <equip name or equip ID> <element> <# of very's>).");
- return -1;
- }
-
- item_id = 0;
- if ((item_data = itemdb_searchname (item_name)) != NULL ||
- (item_data = itemdb_exists (atoi (item_name))) != NULL)
- item_id = item_data->nameid;
-
- if (itemdb_exists (item_id) &&
- (item_id <= 500 || item_id > 1099) &&
- (item_id < 4001 || item_id > 4148) &&
- (item_id < 7001 || item_id > 10019) && itemdb_isequip (item_id))
- {
- if (attribute < MIN_ATTRIBUTE || attribute > MAX_ATTRIBUTE)
- attribute = ATTRIBUTE_NORMAL;
- if (star < MIN_STAR || star > MAX_STAR)
- star = 0;
- memset (&tmp_item, 0, sizeof tmp_item);
- tmp_item.nameid = item_id;
- tmp_item.amount = 1;
- tmp_item.identify = 1;
- tmp_item.card[0] = 0x00ff;
- tmp_item.card[1] = ((star * 5) << 8) + attribute;
- *((unsigned long *) (&tmp_item.card[2])) = sd->char_id;
- clif_produceeffect (sd, 0, item_id); // 製造エフェクトパケット
- clif_misceffect (&sd->bl, 3); // 他人ã«ã‚‚æˆåŠŸã‚’通知
- if ((flag = pc_additem (sd, &tmp_item, 1)))
- clif_additem (sd, 0, 0, flag);
- }
- else
- {
- if (battle_config.error_log)
- printf ("@produce NOT WEAPON [%d]\n", item_id);
- if (item_id != 0 && itemdb_exists (item_id))
- sprintf (output, "This item (%d: '%s') is not an equipment.", item_id, item_data->name);
- else
- sprintf (output, "%s", "This item is not an equipment.");
- clif_displaymessage (fd, output);
- return -1;
- }
+ clif_displaymessage(fd, "Nearby players:");
+ map_foreachinarea(std::bind(atlist_nearby_sub, ph::_1, fd),
+ sd->bl.m, sd->bl.x - 1, sd->bl.y - 1,
+ sd->bl.x + 1, sd->bl.x + 1, BL::PC);
return 0;
}
/*==========================================
- * Sub-function to display actual memo points
- *------------------------------------------
- */
-static
-void atcommand_memo_sub (struct map_session_data *sd)
-{
- int i;
- char output[200];
-
- memset (output, '\0', sizeof (output));
-
- clif_displaymessage (sd->fd,
- "Your actual memo positions are (except respawn point):");
- for (i = MIN_PORTAL_MEMO; i <= MAX_PORTAL_MEMO; i++)
- {
- if (sd->status.memo_point[i].map[0])
- sprintf (output, "%d - %s (%d,%d)", i,
- sd->status.memo_point[i].map, sd->status.memo_point[i].x,
- sd->status.memo_point[i].y);
- else
- sprintf (output, "%d - void", i);
- clif_displaymessage (sd->fd, output);
- }
-
- return;
-}
-
-/*==========================================
*
*------------------------------------------
*/
-int atcommand_memo (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_killmonster2(const int fd, struct map_session_data *sd,
+ const char *, const char *message)
{
- int position = 0;
- char output[200];
-
- memset (output, '\0', sizeof (output));
-
- if (!message || !*message || sscanf (message, "%d", &position) < 1)
- atcommand_memo_sub (sd);
- else
- {
- if (position >= MIN_PORTAL_MEMO && position <= MAX_PORTAL_MEMO)
- {
- if (sd->bl.m >= 0 && map[sd->bl.m].flag.nowarpto
- && battle_config.any_warp_GM_min_level > pc_isGM (sd))
- {
- clif_displaymessage (fd,
- "You are not authorised to memo this map.");
- return -1;
- }
- if (sd->status.memo_point[position].map[0])
- {
- sprintf (output, "You replace previous memo position %d - %s (%d,%d).", position, sd->status.memo_point[position].map, sd->status.memo_point[position].x, sd->status.memo_point[position].y);
- clif_displaymessage (fd, output);
- }
- memcpy (sd->status.memo_point[position].map, map[sd->bl.m].name,
- 24);
- sd->status.memo_point[position].x = sd->bl.x;
- sd->status.memo_point[position].y = sd->bl.y;
- clif_skill_memo (sd, 0);
- if (pc_checkskill (sd, AL_WARP) <= (position + 1))
- clif_displaymessage (fd, "Note: you don't have the 'Warp' skill level to use it.");
- atcommand_memo_sub (sd);
- }
- else
- {
- sprintf (output,
- "Please, enter a valid position (usage: @memo <memo_position:%d-%d>).",
- MIN_PORTAL_MEMO, MAX_PORTAL_MEMO);
- clif_displaymessage (fd, output);
- atcommand_memo_sub (sd);
- return -1;
- }
- }
+ atcommand_killmonster_sub(fd, sd, message, 0);
return 0;
}
@@ -3221,24 +2283,22 @@ int atcommand_memo (const int fd, struct map_session_data *sd,
*
*------------------------------------------
*/
-int atcommand_gat (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_gat(const int fd, struct map_session_data *sd,
+ const char *, const char *)
{
- char output[200];
- int y;
-
- memset (output, '\0', sizeof (output));
+ int y;
for (y = 2; y >= -2; y--)
{
- sprintf (output, "%s (x= %d, y= %d) %02X %02X %02X %02X %02X",
- map[sd->bl.m].name, sd->bl.x - 2, sd->bl.y + y,
- map_getcell (sd->bl.m, sd->bl.x - 2, sd->bl.y + y),
- map_getcell (sd->bl.m, sd->bl.x - 1, sd->bl.y + y),
- map_getcell (sd->bl.m, sd->bl.x, sd->bl.y + y),
- map_getcell (sd->bl.m, sd->bl.x + 1, sd->bl.y + y),
- map_getcell (sd->bl.m, sd->bl.x + 2, sd->bl.y + y));
- clif_displaymessage (fd, output);
+ std::string output = STRPRINTF(
+ "%s (x= %d, y= %d) %02X %02X %02X %02X %02X",
+ map[sd->bl.m].name, sd->bl.x - 2, sd->bl.y + y,
+ map_getcell(sd->bl.m, sd->bl.x - 2, sd->bl.y + y),
+ map_getcell(sd->bl.m, sd->bl.x - 1, sd->bl.y + y),
+ map_getcell(sd->bl.m, sd->bl.x, sd->bl.y + y),
+ map_getcell(sd->bl.m, sd->bl.x + 1, sd->bl.y + y),
+ map_getcell(sd->bl.m, sd->bl.x + 2, sd->bl.y + y));
+ clif_displaymessage(fd, output);
}
return 0;
@@ -3248,19 +2308,19 @@ int atcommand_gat (const int fd, struct map_session_data *sd,
*
*------------------------------------------
*/
-int atcommand_packet (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_packet(const int fd, struct map_session_data *sd,
+ const char *, const char *message)
{
- int x = 0, y = 0;
+ int type = 0, flag = 0;
- if (!message || !*message || sscanf (message, "%d %d", &x, &y) < 2)
+ if (!message || !*message || sscanf(message, "%d %d", &type, &flag) < 2)
{
- clif_displaymessage (fd,
+ clif_displaymessage(fd,
"Please, enter a status type/flag (usage: @packet <status type> <flag>).");
return -1;
}
- clif_status_change (&sd->bl, x, y);
+ clif_status_change(&sd->bl, StatusChange(type), flag);
return 0;
}
@@ -3269,14 +2329,14 @@ int atcommand_packet (const int fd, struct map_session_data *sd,
* @stpoint (Rewritten by [Yor])
*------------------------------------------
*/
-int atcommand_statuspoint (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_statuspoint(const int fd, struct map_session_data *sd,
+ const char *, const char *message)
{
- int point, new_status_point;
+ int point, new_status_point;
- if (!message || !*message || (point = atoi (message)) == 0)
+ if (!message || !*message || (point = atoi(message)) == 0)
{
- clif_displaymessage (fd,
+ clif_displaymessage(fd,
"Please, enter a number (usage: @stpoint <number of points>).");
return -1;
}
@@ -3290,15 +2350,15 @@ int atcommand_statuspoint (const int fd, struct map_session_data *sd,
if (new_status_point != (int) sd->status.status_point)
{
sd->status.status_point = (short) new_status_point;
- clif_updatestatus (sd, SP_STATUSPOINT);
- clif_displaymessage (fd, "Number of status points changed!");
+ clif_updatestatus(sd, SP::STATUSPOINT);
+ clif_displaymessage(fd, "Number of status points changed!");
}
else
{
if (point < 0)
- clif_displaymessage (fd, "Impossible to decrease the number/value.");
+ clif_displaymessage(fd, "Impossible to decrease the number/value.");
else
- clif_displaymessage (fd, "Impossible to increase the number/value.");
+ clif_displaymessage(fd, "Impossible to increase the number/value.");
return -1;
}
@@ -3309,14 +2369,14 @@ int atcommand_statuspoint (const int fd, struct map_session_data *sd,
* @skpoint (Rewritten by [Yor])
*------------------------------------------
*/
-int atcommand_skillpoint (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_skillpoint(const int fd, struct map_session_data *sd,
+ const char *, const char *message)
{
- int point, new_skill_point;
+ int point, new_skill_point;
- if (!message || !*message || (point = atoi (message)) == 0)
+ if (!message || !*message || (point = atoi(message)) == 0)
{
- clif_displaymessage (fd,
+ clif_displaymessage(fd,
"Please, enter a number (usage: @skpoint <number of points>).");
return -1;
}
@@ -3330,15 +2390,15 @@ int atcommand_skillpoint (const int fd, struct map_session_data *sd,
if (new_skill_point != (int) sd->status.skill_point)
{
sd->status.skill_point = (short) new_skill_point;
- clif_updatestatus (sd, SP_SKILLPOINT);
- clif_displaymessage (fd, "Number of skill points changed!");
+ clif_updatestatus(sd, SP::SKILLPOINT);
+ clif_displaymessage(fd, "Number of skill points changed!");
}
else
{
if (point < 0)
- clif_displaymessage (fd, "Impossible to decrease the number/value.");
+ clif_displaymessage(fd, "Impossible to decrease the number/value.");
else
- clif_displaymessage (fd, "Impossible to increase the number/value.");
+ clif_displaymessage(fd, "Impossible to increase the number/value.");
return -1;
}
@@ -3349,14 +2409,14 @@ int atcommand_skillpoint (const int fd, struct map_session_data *sd,
* @zeny (Rewritten by [Yor])
*------------------------------------------
*/
-int atcommand_zeny (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_zeny(const int fd, struct map_session_data *sd,
+ const char *, const char *message)
{
- int zeny, new_zeny;
+ int zeny, new_zeny;
- if (!message || !*message || (zeny = atoi (message)) == 0)
+ if (!message || !*message || (zeny = atoi(message)) == 0)
{
- clif_displaymessage (fd,
+ clif_displaymessage(fd,
"Please, enter an amount (usage: @zeny <amount>).");
return -1;
}
@@ -3370,15 +2430,15 @@ int atcommand_zeny (const int fd, struct map_session_data *sd,
if (new_zeny != sd->status.zeny)
{
sd->status.zeny = new_zeny;
- clif_updatestatus (sd, SP_ZENY);
- clif_displaymessage (fd, "Number of zenys changed!");
+ clif_updatestatus(sd, SP::ZENY);
+ clif_displaymessage(fd, "Number of zenys changed!");
}
else
{
if (zeny < 0)
- clif_displaymessage (fd, "Impossible to decrease the number/value.");
+ clif_displaymessage(fd, "Impossible to decrease the number/value.");
else
- clif_displaymessage (fd, "Impossible to increase the number/value.");
+ clif_displaymessage(fd, "Impossible to increase the number/value.");
return -1;
}
@@ -3389,66 +2449,43 @@ int atcommand_zeny (const int fd, struct map_session_data *sd,
*
*------------------------------------------
*/
-int atcommand_param (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+template<ATTR attr>
+int atcommand_param(const int fd, struct map_session_data *sd,
+ const char *, const char *message)
{
- int i, index, value = 0, new_value;
- const char *param[] =
- { "@str", "@agi", "@vit", "@int", "@dex", "@luk", NULL };
- short *status[] = {
- &sd->status.str, &sd->status.agi, &sd->status.vit,
- &sd->status.int_, &sd->status.dex, &sd->status.luk
- };
- char output[200];
+ int value = 0, new_value;
- memset (output, '\0', sizeof (output));
-
- if (!message || !*message || sscanf (message, "%d", &value) < 1
+ if (!message || !*message || sscanf(message, "%d", &value) < 1
|| value == 0)
{
- sprintf (output,
- "Please, enter a valid value (usage: @str,@agi,@vit,@int,@dex,@luk <+/-adjustement>).");
- clif_displaymessage (fd, output);
- return -1;
- }
- index = -1;
- for (i = 0; param[i] != NULL; i++)
- {
- if (strcasecmp (command, param[i]) == 0)
- {
- index = i;
- break;
- }
- }
- if (index < 0 || index > MAX_STATUS_TYPE)
- { // normaly impossible...
- sprintf (output,
- "Please, enter a valid value (usage: @str,@agi,@vit,@int,@dex,@luk <+/-adjustement>).");
- clif_displaymessage (fd, output);
+ // there was a clang bug here
+ // fortunately, STRPRINTF was not actually needed
+ clif_displaymessage(fd,
+ "Please, enter a valid value (usage: @str,@agi,@vit,@int,@dex,@luk <+/-adjustement>).");
return -1;
}
- new_value = (int) *status[index] + value;
+ new_value = (int) sd->status.attrs[attr] + value;
if (value > 0 && (value > battle_config.max_parameter || new_value > battle_config.max_parameter)) // fix positiv overflow
new_value = battle_config.max_parameter;
else if (value < 0 && (value < -battle_config.max_parameter || new_value < 1)) // fix negativ overflow
new_value = 1;
- if (new_value != (int) *status[index])
+ if (new_value != sd->status.attrs[attr])
{
- *status[index] = new_value;
- clif_updatestatus (sd, SP_STR + index);
- clif_updatestatus (sd, SP_USTR + index);
- pc_calcstatus (sd, 0);
- clif_displaymessage (fd, "Stat changed.");
+ sd->status.attrs[attr] = new_value;
+ clif_updatestatus(sd, attr_to_sp(attr));
+ clif_updatestatus(sd, attr_to_usp(attr));
+ pc_calcstatus(sd, 0);
+ clif_displaymessage(fd, "Stat changed.");
}
else
{
if (value < 0)
- clif_displaymessage (fd, "Impossible to decrease the number/value.");
+ clif_displaymessage(fd, "Impossible to decrease the number/value.");
else
- clif_displaymessage (fd, "Impossible to increase the number/value.");
+ clif_displaymessage(fd, "Impossible to increase the number/value.");
return -1;
}
@@ -3460,100 +2497,42 @@ int atcommand_param (const int fd, struct map_session_data *sd,
*------------------------------------------
*/
//** Stat all by fritz (rewritten by [Yor])
-int atcommand_all_stats (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_all_stats(const int fd, struct map_session_data *sd,
+ const char *, const char *message)
{
- int index, count, value = 0, new_value;
- short *status[] = {
- &sd->status.str, &sd->status.agi, &sd->status.vit,
- &sd->status.int_, &sd->status.dex, &sd->status.luk
- };
+ int count, value = 0, new_value;
- if (!message || !*message || sscanf (message, "%d", &value) < 1
+ if (!message || !*message || sscanf(message, "%d", &value) < 1
|| value == 0)
value = battle_config.max_parameter;
count = 0;
- for (index = 0; index < (int) (sizeof (status) / sizeof (status[0]));
- index++)
+ for (ATTR attr : ATTRs)
{
-
- new_value = (int) *status[index] + value;
+ new_value = sd->status.attrs[attr] + value;
if (value > 0 && (value > battle_config.max_parameter || new_value > battle_config.max_parameter)) // fix positiv overflow
new_value = battle_config.max_parameter;
else if (value < 0 && (value < -battle_config.max_parameter || new_value < 1)) // fix negativ overflow
new_value = 1;
- if (new_value != (int) *status[index])
+ if (new_value != sd->status.attrs[attr])
{
- *status[index] = new_value;
- clif_updatestatus (sd, SP_STR + index);
- clif_updatestatus (sd, SP_USTR + index);
- pc_calcstatus (sd, 0);
+ sd->status.attrs[attr] = new_value;
+ clif_updatestatus(sd, attr_to_sp(attr));
+ clif_updatestatus(sd, attr_to_usp(attr));
+ pc_calcstatus(sd, 0);
count++;
}
}
if (count > 0) // if at least 1 stat modified
- clif_displaymessage (fd, "All stats changed!");
+ clif_displaymessage(fd, "All stats changed!");
else
{
if (value < 0)
- clif_displaymessage (fd, "Impossible to decrease a stat.");
+ clif_displaymessage(fd, "Impossible to decrease a stat.");
else
- clif_displaymessage (fd, "Impossible to increase a stat.");
- return -1;
- }
-
- return 0;
-}
-
-/*==========================================
- *
- *------------------------------------------
- */
-int atcommand_guildlevelup (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
-{
- int level = 0;
- short added_level;
- struct guild *guild_info;
-
- if (!message || !*message || sscanf (message, "%d", &level) < 1
- || level == 0)
- {
- clif_displaymessage (fd,
- "Please, enter a valid level (usage: @guildlvl <# of levels>).");
- return -1;
- }
-
- if (sd->status.guild_id <= 0
- || (guild_info = guild_search (sd->status.guild_id)) == NULL)
- {
- clif_displaymessage (fd, "You're not in a guild.");
- return -1;
- }
- if (strcmp (sd->status.name, guild_info->master) != 0)
- {
- clif_displaymessage (fd, "You're not the master of your guild.");
- return -1;
- }
-
- added_level = (short) level;
- if (level > 0 && (level > MAX_GUILDLEVEL || added_level > ((short) MAX_GUILDLEVEL - guild_info->guild_lv))) // fix positiv overflow
- added_level = (short) MAX_GUILDLEVEL - guild_info->guild_lv;
- else if (level < 0 && (level < -MAX_GUILDLEVEL || added_level < (1 - guild_info->guild_lv))) // fix negativ overflow
- added_level = 1 - guild_info->guild_lv;
-
- if (added_level != 0)
- {
- intif_guild_change_basicinfo (guild_info->guild_id, GBI_GUILDLV,
- &added_level, 2);
- clif_displaymessage (fd, "Guild level changed.");
- }
- else
- {
- clif_displaymessage (fd, "Guild level change failed.");
+ clif_displaymessage(fd, "Impossible to increase a stat.");
return -1;
}
@@ -3564,54 +2543,52 @@ int atcommand_guildlevelup (const int fd, struct map_session_data *sd,
*
*------------------------------------------
*/
-int atcommand_recall (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_recall(const int fd, struct map_session_data *sd,
+ const char *, const char *message)
{
char character[100];
- char output[200];
struct map_session_data *pl_sd;
- memset (character, '\0', sizeof (character));
- memset (output, '\0', sizeof (output));
+ memset(character, '\0', sizeof(character));
- if (!message || !*message || sscanf (message, "%99[^\n]", character) < 1)
+ if (!message || !*message || sscanf(message, "%99[^\n]", character) < 1)
{
- clif_displaymessage (fd,
+ clif_displaymessage(fd,
"Please, enter a player name (usage: @recall <char name>).");
return -1;
}
- if ((pl_sd = map_nick2sd (character)) != NULL)
+ if ((pl_sd = map_nick2sd(character)) != NULL)
{
- if (pc_isGM (sd) >= pc_isGM (pl_sd))
+ if (pc_isGM(sd) >= pc_isGM(pl_sd))
{ // you can recall only lower or same level
if (sd->bl.m >= 0 && map[sd->bl.m].flag.nowarpto
- && battle_config.any_warp_GM_min_level > pc_isGM (sd))
+ && battle_config.any_warp_GM_min_level > pc_isGM(sd))
{
- clif_displaymessage (fd,
+ clif_displaymessage(fd,
"You are not authorised to warp somenone to your actual map.");
return -1;
}
if (pl_sd->bl.m >= 0 && map[pl_sd->bl.m].flag.nowarp
- && battle_config.any_warp_GM_min_level > pc_isGM (sd))
+ && battle_config.any_warp_GM_min_level > pc_isGM(sd))
{
- clif_displaymessage (fd,
+ clif_displaymessage(fd,
"You are not authorised to warp this player from its actual map.");
return -1;
}
- pc_setpos (pl_sd, sd->mapname, sd->bl.x, sd->bl.y, 2);
- sprintf (output, "%s recalled!", character);
- clif_displaymessage (fd, output);
+ pc_setpos(pl_sd, sd->mapname, sd->bl.x, sd->bl.y, BeingRemoveWhy::QUIT);
+ std::string output = STRPRINTF("%s recalled!", character);
+ clif_displaymessage(fd, output);
}
else
{
- clif_displaymessage (fd, "Your GM level don't authorise you to do this action on this player.");
+ clif_displaymessage(fd, "Your GM level don't authorise you to do this action on this player.");
return -1;
}
}
else
{
- clif_displaymessage (fd, "Character not found.");
+ clif_displaymessage(fd, "Character not found.");
return -1;
}
@@ -3622,35 +2599,35 @@ int atcommand_recall (const int fd, struct map_session_data *sd,
*
*------------------------------------------
*/
-int atcommand_revive (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_revive(const int fd, struct map_session_data *sd,
+ const char *, const char *message)
{
char character[100];
struct map_session_data *pl_sd;
- memset (character, '\0', sizeof (character));
+ memset(character, '\0', sizeof(character));
- if (!message || !*message || sscanf (message, "%99[^\n]", character) < 1)
+ if (!message || !*message || sscanf(message, "%99[^\n]", character) < 1)
{
- clif_displaymessage (fd,
+ clif_displaymessage(fd,
"Please, enter a player name (usage: @revive <char name>).");
return -1;
}
- if ((pl_sd = map_nick2sd (character)) != NULL)
+ if ((pl_sd = map_nick2sd(character)) != NULL)
{
pl_sd->status.hp = pl_sd->status.max_hp;
- pc_setstand (pl_sd);
- if (battle_config.pc_invincible_time > 0)
- pc_setinvincibletimer (sd, battle_config.pc_invincible_time);
- clif_updatestatus (pl_sd, SP_HP);
- clif_updatestatus (pl_sd, SP_SP);
- clif_resurrection (&pl_sd->bl, 1);
- clif_displaymessage (fd, "Character revived.");
+ pc_setstand(pl_sd);
+ if (static_cast<interval_t>(battle_config.pc_invincible_time) > interval_t::zero())
+ pc_setinvincibletimer(sd, static_cast<interval_t>(battle_config.pc_invincible_time));
+ clif_updatestatus(pl_sd, SP::HP);
+ clif_updatestatus(pl_sd, SP::SP);
+ clif_resurrection(&pl_sd->bl, 1);
+ clif_displaymessage(fd, "Character revived.");
}
else
{
- clif_displaymessage (fd, "Character not found.");
+ clif_displaymessage(fd, "Character not found.");
return -1;
}
@@ -3661,76 +2638,56 @@ int atcommand_revive (const int fd, struct map_session_data *sd,
*
*------------------------------------------
*/
-int atcommand_character_stats (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_character_stats(const int fd, struct map_session_data *,
+ const char *, const char *message)
{
char character[100];
- char job_jobname[100];
- char output[200];
struct map_session_data *pl_sd;
- int i;
- memset (character, '\0', sizeof (character));
- memset (job_jobname, '\0', sizeof (job_jobname));
- memset (output, '\0', sizeof (output));
+ memset(character, '\0', sizeof(character));
- if (!message || !*message || sscanf (message, "%99[^\n]", character) < 1)
+ if (!message || !*message || sscanf(message, "%99[^\n]", character) < 1)
{
- clif_displaymessage (fd,
+ clif_displaymessage(fd,
"Please, enter a player name (usage: @charstats <char name>).");
return -1;
}
- if ((pl_sd = map_nick2sd (character)) != NULL)
- {
- struct
- {
- const char *format;
- int value;
- } output_table[] =
- {
- {
- "Base Level - %d", pl_sd->status.base_level},
- {
- job_jobname, pl_sd->status.job_level},
- {
- "Hp - %d", pl_sd->status.hp},
- {
- "MaxHp - %d", pl_sd->status.max_hp},
- {
- "Sp - %d", pl_sd->status.sp},
- {
- "MaxSp - %d", pl_sd->status.max_sp},
- {
- "Str - %3d", pl_sd->status.str},
- {
- "Agi - %3d", pl_sd->status.agi},
- {
- "Vit - %3d", pl_sd->status.vit},
- {
- "Int - %3d", pl_sd->status.int_},
- {
- "Dex - %3d", pl_sd->status.dex},
- {
- "Luk - %3d", pl_sd->status.luk},
- {
- "Zeny - %d", pl_sd->status.zeny},
- {
- NULL, 0}
- };
- sprintf (job_jobname, "Job - %s %s", job_name (pl_sd->status.pc_class),
- "(level %d)");
- sprintf (output, "'%s' stats:", pl_sd->status.name);
- clif_displaymessage (fd, output);
- for (i = 0; output_table[i].format != NULL; i++)
- {
- sprintf (output, output_table[i].format, output_table[i].value);
- clif_displaymessage (fd, output);
- }
+ if ((pl_sd = map_nick2sd(character)) != NULL)
+ {
+ std::string output;
+ output = STRPRINTF("'%s' stats:", pl_sd->status.name);
+ clif_displaymessage(fd, output);
+ output = STRPRINTF("Base Level - %d", pl_sd->status.base_level),
+ clif_displaymessage(fd, output);
+ output = STRPRINTF("Job - Novice/Human (level %d)", pl_sd->status.job_level);
+ clif_displaymessage(fd, output);
+ output = STRPRINTF("Hp - %d", pl_sd->status.hp);
+ clif_displaymessage(fd, output);
+ output = STRPRINTF("MaxHp - %d", pl_sd->status.max_hp);
+ clif_displaymessage(fd, output);
+ output = STRPRINTF("Sp - %d", pl_sd->status.sp);
+ clif_displaymessage(fd, output);
+ output = STRPRINTF("MaxSp - %d", pl_sd->status.max_sp);
+ clif_displaymessage(fd, output);
+ output = STRPRINTF("Str - %3d", pl_sd->status.attrs[ATTR::STR]);
+ clif_displaymessage(fd, output);
+ output = STRPRINTF("Agi - %3d", pl_sd->status.attrs[ATTR::AGI]);
+ clif_displaymessage(fd, output);
+ output = STRPRINTF("Vit - %3d", pl_sd->status.attrs[ATTR::VIT]);
+ clif_displaymessage(fd, output);
+ output = STRPRINTF("Int - %3d", pl_sd->status.attrs[ATTR::INT]);
+ clif_displaymessage(fd, output);
+ output = STRPRINTF("Dex - %3d", pl_sd->status.attrs[ATTR::DEX]);
+ clif_displaymessage(fd, output);
+ output = STRPRINTF("Luk - %3d", pl_sd->status.attrs[ATTR::LUK]);
+ clif_displaymessage(fd, output);
+ output = STRPRINTF("Zeny - %d", pl_sd->status.zeny);
+ clif_displaymessage(fd, output);
}
else
{
- clif_displaymessage (fd, "Character not found.");
+ clif_displaymessage(fd, "Character not found.");
return -1;
}
@@ -3742,55 +2699,56 @@ int atcommand_character_stats (const int fd, struct map_session_data *sd,
*------------------------------------------
*/
//** Character Stats All by fritz
-int atcommand_character_stats_all (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_character_stats_all(const int fd, struct map_session_data *,
+ const char *, const char *)
{
- char output[1024], gmlevel[1024];
- int i;
- int count;
+ int i;
+ int count;
struct map_session_data *pl_sd;
- memset (output, '\0', sizeof (output));
- memset (gmlevel, '\0', sizeof (gmlevel));
-
count = 0;
for (i = 0; i < fd_max; i++)
{
if (session[i] && (pl_sd = (struct map_session_data *)session[i]->session_data)
&& pl_sd->state.auth)
{
-
- if (pc_isGM (pl_sd) > 0)
- sprintf (gmlevel, "| GM Lvl: %d", pc_isGM (pl_sd));
+ std::string gmlevel;
+ if (pc_isGM(pl_sd) > 0)
+ gmlevel = STRPRINTF("| GM Lvl: %d", pc_isGM(pl_sd));
else
- sprintf (gmlevel, " ");
-
- sprintf (output,
- "Name: %s | BLvl: %d | Job: %s (Lvl: %d) | HP: %d/%d | SP: %d/%d",
- pl_sd->status.name, pl_sd->status.base_level,
- job_name (pl_sd->status.pc_class), pl_sd->status.job_level,
- pl_sd->status.hp, pl_sd->status.max_hp, pl_sd->status.sp,
- pl_sd->status.max_sp);
- clif_displaymessage (fd, output);
- sprintf (output,
- "STR: %d | AGI: %d | VIT: %d | INT: %d | DEX: %d | LUK: %d | Zeny: %d %s",
- pl_sd->status.str, pl_sd->status.agi, pl_sd->status.vit,
- pl_sd->status.int_, pl_sd->status.dex, pl_sd->status.luk,
- pl_sd->status.zeny, gmlevel);
- clif_displaymessage (fd, output);
- clif_displaymessage (fd, "--------");
+ gmlevel = " ";
+
+ std::string output;
+ output = STRPRINTF(
+ "Name: %s | BLvl: %d | Job: Novice/Human (Lvl: %d) | HP: %d/%d | SP: %d/%d",
+ pl_sd->status.name, pl_sd->status.base_level,
+ pl_sd->status.job_level,
+ pl_sd->status.hp, pl_sd->status.max_hp,
+ pl_sd->status.sp, pl_sd->status.max_sp);
+ clif_displaymessage(fd, output);
+ output = STRPRINTF("STR: %d | AGI: %d | VIT: %d | INT: %d | DEX: %d | LUK: %d | Zeny: %d %s",
+ pl_sd->status.attrs[ATTR::STR],
+ pl_sd->status.attrs[ATTR::AGI],
+ pl_sd->status.attrs[ATTR::VIT],
+ pl_sd->status.attrs[ATTR::INT],
+ pl_sd->status.attrs[ATTR::DEX],
+ pl_sd->status.attrs[ATTR::LUK],
+ pl_sd->status.zeny,
+ gmlevel);
+ clif_displaymessage(fd, output);
+ clif_displaymessage(fd, "--------");
count++;
}
}
if (count == 0)
- clif_displaymessage (fd, "No player found.");
+ clif_displaymessage(fd, "No player found.");
else if (count == 1)
- clif_displaymessage (fd, "1 player found.");
+ clif_displaymessage(fd, "1 player found.");
else
{
- sprintf (output, "%d players found.", count);
- clif_displaymessage (fd, output);
+ std::string output = STRPRINTF("%d players found.", count);
+ clif_displaymessage(fd, output);
}
return 0;
@@ -3800,83 +2758,50 @@ int atcommand_character_stats_all (const int fd, struct map_session_data *sd,
*
*------------------------------------------
*/
-int atcommand_character_option (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_character_option(const int fd, struct map_session_data *sd,
+ const char *, const char *message)
{
char character[100];
- int opt1 = 0, opt2 = 0, opt3 = 0;
+ int opt1_ = 0, opt2_ = 0, opt3_ = 0;
struct map_session_data *pl_sd;
- memset (character, '\0', sizeof (character));
+ memset(character, '\0', sizeof(character));
if (!message || !*message
- || sscanf (message, "%d %d %d %99[^\n]", &opt1, &opt2, &opt3,
- character) < 4 || opt1 < 0 || opt2 < 0 || opt3 < 0)
+ || sscanf(message, "%d %d %d %99[^\n]", &opt1_, &opt2_, &opt3_,
+ character) < 4 || opt1_ < 0 || opt2_ < 0 || opt3_ < 0)
{
- clif_displaymessage (fd,
+ clif_displaymessage(fd,
"Please, enter valid options and a player name (usage: @charoption <param1> <param2> <param3> <charname>).");
return -1;
}
- if ((pl_sd = map_nick2sd (character)) != NULL)
+ Opt1 opt1 = Opt1(opt1_);
+ Opt2 opt2 = Opt2(opt2_);
+ Option opt3 = Option(opt3_);
+
+ if ((pl_sd = map_nick2sd(character)) != NULL)
{
- if (pc_isGM (sd) >= pc_isGM (pl_sd))
- { // you can change option only to lower or same level
+ if (pc_isGM(sd) >= pc_isGM(pl_sd))
+ {
+ // you can change option only to lower or same level
pl_sd->opt1 = opt1;
pl_sd->opt2 = opt2;
pl_sd->status.option = opt3;
- // fix pecopeco display
- if (pl_sd->status.pc_class == 13 || pl_sd->status.pc_class == 21
- || pl_sd->status.pc_class == 4014 || pl_sd->status.pc_class == 4022)
- {
- if (!pc_isriding (pl_sd))
- { // pl_sd have the new value...
- if (pl_sd->status.pc_class == 13)
- pl_sd->status.pc_class = pl_sd->view_class = 7;
- else if (pl_sd->status.pc_class == 21)
- pl_sd->status.pc_class = pl_sd->view_class = 14;
- else if (pl_sd->status.pc_class == 4014)
- pl_sd->status.pc_class = pl_sd->view_class = 4008;
- else if (pl_sd->status.pc_class == 4022)
- pl_sd->status.pc_class = pl_sd->view_class = 4015;
- }
- }
- else
- {
- if (pc_isriding (pl_sd))
- { // pl_sd have the new value...
- if (pl_sd->disguise > 0)
- { // temporary prevention of crash caused by peco + disguise, will look into a better solution [Valaris] (code added by [Yor])
- pl_sd->status.option &= ~0x0020;
- }
- else
- {
- if (pl_sd->status.pc_class == 7)
- pl_sd->status.pc_class = pl_sd->view_class = 13;
- else if (pl_sd->status.pc_class == 14)
- pl_sd->status.pc_class = pl_sd->view_class = 21;
- else if (pl_sd->status.pc_class == 4008)
- pl_sd->status.pc_class = pl_sd->view_class = 4014;
- else if (pl_sd->status.pc_class == 4015)
- pl_sd->status.pc_class = pl_sd->view_class = 4022;
- else
- pl_sd->status.option &= ~0x0020;
- }
- }
- }
- clif_changeoption (&pl_sd->bl);
- pc_calcstatus (pl_sd, 0);
- clif_displaymessage (fd, "Character's options changed.");
+
+ clif_changeoption(&pl_sd->bl);
+ pc_calcstatus(pl_sd, 0);
+ clif_displaymessage(fd, "Character's options changed.");
}
else
{
- clif_displaymessage (fd, "Your GM level don't authorise you to do this action on this player.");
+ clif_displaymessage(fd, "Your GM level don't authorise you to do this action on this player.");
return -1;
}
}
else
{
- clif_displaymessage (fd, "Character not found.");
+ clif_displaymessage(fd, "Character not found.");
return -1;
}
@@ -3887,35 +2812,35 @@ int atcommand_character_option (const int fd, struct map_session_data *sd,
* charchangesex command (usage: charchangesex <player_name>)
*------------------------------------------
*/
-int atcommand_char_change_sex (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_char_change_sex(const int fd, struct map_session_data *sd,
+ const char *, const char *message)
{
char character[100];
- memset (character, '\0', sizeof (character));
+ memset(character, '\0', sizeof(character));
- if (!message || !*message || sscanf (message, "%99[^\n]", character) < 1)
+ if (!message || !*message || sscanf(message, "%99[^\n]", character) < 1)
{
- clif_displaymessage (fd,
+ clif_displaymessage(fd,
"Please, enter a player name (usage: @charchangesex <name>).");
return -1;
}
// check player name
- if (strlen (character) < 4)
+ if (strlen(character) < 4)
{
- clif_displaymessage (fd, "Sorry, but a player name have at least 4 characters.");
+ clif_displaymessage(fd, "Sorry, but a player name have at least 4 characters.");
return -1;
}
- else if (strlen (character) > 23)
+ else if (strlen(character) > 23)
{
- clif_displaymessage (fd, "Sorry, but a player name have 23 characters maximum.");
+ clif_displaymessage(fd, "Sorry, but a player name have 23 characters maximum.");
return -1;
}
else
{
- chrif_char_ask_name (sd->status.account_id, character, 5, 0, 0, 0, 0, 0, 0); // type: 5 - changesex
- clif_displaymessage (fd, "Character name sends to char-server to ask it.");
+ chrif_char_ask_name(sd->status.account_id, character, 5, 0, 0, 0, 0, 0, 0); // type: 5 - changesex
+ clif_displaymessage(fd, "Character name sends to char-server to ask it.");
}
return 0;
@@ -3926,35 +2851,35 @@ int atcommand_char_change_sex (const int fd, struct map_session_data *sd,
* This command do a definitiv ban on a player
*------------------------------------------
*/
-int atcommand_char_block (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_char_block(const int fd, struct map_session_data *sd,
+ const char *, const char *message)
{
char character[100];
- memset (character, '\0', sizeof (character));
+ memset(character, '\0', sizeof(character));
- if (!message || !*message || sscanf (message, "%99[^\n]", character) < 1)
+ if (!message || !*message || sscanf(message, "%99[^\n]", character) < 1)
{
- clif_displaymessage (fd,
+ clif_displaymessage(fd,
"Please, enter a player name (usage: @block <name>).");
return -1;
}
// check player name
- if (strlen (character) < 4)
+ if (strlen(character) < 4)
{
- clif_displaymessage (fd, "Sorry, but a player name have at least 4 characters.");
+ clif_displaymessage(fd, "Sorry, but a player name have at least 4 characters.");
return -1;
}
- else if (strlen (character) > 23)
+ else if (strlen(character) > 23)
{
- clif_displaymessage (fd, "Sorry, but a player name have 23 characters maximum.");
+ clif_displaymessage(fd, "Sorry, but a player name have 23 characters maximum.");
return -1;
}
else
{
- chrif_char_ask_name (sd->status.account_id, character, 1, 0, 0, 0, 0, 0, 0); // type: 1 - block
- clif_displaymessage (fd, "Character name sends to char-server to ask it.");
+ chrif_char_ask_name(sd->status.account_id, character, 1, 0, 0, 0, 0, 0, 0); // type: 1 - block
+ clif_displaymessage(fd, "Character name sends to char-server to ask it.");
}
return 0;
@@ -3976,32 +2901,32 @@ int atcommand_char_block (const int fd, struct map_session_data *sd,
* this example adds 1 month and 1 second, and substracts 2 minutes and 6 years at the same time.
*------------------------------------------
*/
-int atcommand_char_ban (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_char_ban(const int fd, struct map_session_data *sd,
+ const char *, const char *message)
{
char modif[100], character[100];
char *modif_p;
- int year, month, day, hour, minute, second, value;
+ int year, month, day, hour, minute, second, value;
- memset (modif, '\0', sizeof (modif));
- memset (character, '\0', sizeof (character));
+ memset(modif, '\0', sizeof(modif));
+ memset(character, '\0', sizeof(character));
if (!message || !*message
- || sscanf (message, "%s %99[^\n]", modif, character) < 2)
+ || sscanf(message, "%s %99[^\n]", modif, character) < 2)
{
- clif_displaymessage (fd,
+ clif_displaymessage(fd,
"Please, enter ban time and a player name (usage: @charban/@ban/@banish/@charbanish <time> <name>).");
return -1;
}
- modif[sizeof (modif) - 1] = '\0';
- character[sizeof (character) - 1] = '\0';
+ modif[sizeof(modif) - 1] = '\0';
+ character[sizeof(character) - 1] = '\0';
modif_p = modif;
year = month = day = hour = minute = second = 0;
while (modif_p[0] != '\0')
{
- value = atoi (modif_p);
+ value = atoi(modif_p);
if (value == 0)
modif_p++;
else
@@ -4049,25 +2974,25 @@ int atcommand_char_ban (const int fd, struct map_session_data *sd,
if (year == 0 && month == 0 && day == 0 && hour == 0 && minute == 0
&& second == 0)
{
- clif_displaymessage (fd, "Invalid time for ban command.");
+ clif_displaymessage(fd, "Invalid time for ban command.");
return -1;
}
// check player name
- if (strlen (character) < 4)
+ if (strlen(character) < 4)
{
- clif_displaymessage (fd, "Sorry, but a player name have at least 4 characters.");
+ clif_displaymessage(fd, "Sorry, but a player name have at least 4 characters.");
return -1;
}
- else if (strlen (character) > 23)
+ else if (strlen(character) > 23)
{
- clif_displaymessage (fd, "Sorry, but a player name have 23 characters maximum.");
+ clif_displaymessage(fd, "Sorry, but a player name have 23 characters maximum.");
return -1;
}
else
{
- chrif_char_ask_name (sd->status.account_id, character, 2, year, month, day, hour, minute, second); // type: 2 - ban
- clif_displaymessage (fd, "Character name sends to char-server to ask it.");
+ chrif_char_ask_name(sd->status.account_id, character, 2, year, month, day, hour, minute, second); // type: 2 - ban
+ clif_displaymessage(fd, "Character name sends to char-server to ask it.");
}
return 0;
@@ -4077,36 +3002,36 @@ int atcommand_char_ban (const int fd, struct map_session_data *sd,
* charunblock command (usage: charunblock <player_name>)
*------------------------------------------
*/
-int atcommand_char_unblock (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_char_unblock(const int fd, struct map_session_data *sd,
+ const char *, const char *message)
{
char character[100];
- memset (character, '\0', sizeof (character));
+ memset(character, '\0', sizeof(character));
- if (!message || !*message || sscanf (message, "%99[^\n]", character) < 1)
+ if (!message || !*message || sscanf(message, "%99[^\n]", character) < 1)
{
- clif_displaymessage (fd,
+ clif_displaymessage(fd,
"Please, enter a player name (usage: @charunblock <player_name>).");
return -1;
}
// check player name
- if (strlen (character) < 4)
+ if (strlen(character) < 4)
{
- clif_displaymessage (fd, "Sorry, but a player name have at least 4 characters.");
+ clif_displaymessage(fd, "Sorry, but a player name have at least 4 characters.");
return -1;
}
- else if (strlen (character) > 23)
+ else if (strlen(character) > 23)
{
- clif_displaymessage (fd, "Sorry, but a player name have 23 characters maximum.");
+ clif_displaymessage(fd, "Sorry, but a player name have 23 characters maximum.");
return -1;
}
else
{
// send answer to login server via char-server
- chrif_char_ask_name (sd->status.account_id, character, 3, 0, 0, 0, 0, 0, 0); // type: 3 - unblock
- clif_displaymessage (fd, "Character name sends to char-server to ask it.");
+ chrif_char_ask_name(sd->status.account_id, character, 3, 0, 0, 0, 0, 0, 0); // type: 3 - unblock
+ clif_displaymessage(fd, "Character name sends to char-server to ask it.");
}
return 0;
@@ -4116,36 +3041,36 @@ int atcommand_char_unblock (const int fd, struct map_session_data *sd,
* charunban command (usage: charunban <player_name>)
*------------------------------------------
*/
-int atcommand_char_unban (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_char_unban(const int fd, struct map_session_data *sd,
+ const char *, const char *message)
{
char character[100];
- memset (character, '\0', sizeof (character));
+ memset(character, '\0', sizeof(character));
- if (!message || !*message || sscanf (message, "%99[^\n]", character) < 1)
+ if (!message || !*message || sscanf(message, "%99[^\n]", character) < 1)
{
- clif_displaymessage (fd,
+ clif_displaymessage(fd,
"Please, enter a player name (usage: @charunban <player_name>).");
return -1;
}
// check player name
- if (strlen (character) < 4)
+ if (strlen(character) < 4)
{
- clif_displaymessage (fd, "Sorry, but a player name have at least 4 characters.");
+ clif_displaymessage(fd, "Sorry, but a player name have at least 4 characters.");
return -1;
}
- else if (strlen (character) > 23)
+ else if (strlen(character) > 23)
{
- clif_displaymessage (fd, "Sorry, but a player name have 23 characters maximum.");
+ clif_displaymessage(fd, "Sorry, but a player name have 23 characters maximum.");
return -1;
}
else
{
// send answer to login server via char-server
- chrif_char_ask_name (sd->status.account_id, character, 4, 0, 0, 0, 0, 0, 0); // type: 4 - unban
- clif_displaymessage (fd, "Character name sends to char-server to ask it.");
+ chrif_char_ask_name(sd->status.account_id, character, 4, 0, 0, 0, 0, 0, 0); // type: 4 - unban
+ clif_displaymessage(fd, "Character name sends to char-server to ask it.");
}
return 0;
@@ -4155,128 +3080,62 @@ int atcommand_char_unban (const int fd, struct map_session_data *sd,
*
*------------------------------------------
*/
-int atcommand_character_save (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_character_save(const int fd, struct map_session_data *sd,
+ const char *, const char *message)
{
char map_name[100];
char character[100];
struct map_session_data *pl_sd;
- int x = 0, y = 0;
- int m;
+ int x = 0, y = 0;
+ int m;
- memset (map_name, '\0', sizeof (map_name));
- memset (character, '\0', sizeof (character));
+ memset(map_name, '\0', sizeof(map_name));
+ memset(character, '\0', sizeof(character));
if (!message || !*message
- || sscanf (message, "%99s %d %d %99[^\n]", map_name, &x, &y,
+ || sscanf(message, "%99s %d %d %99[^\n]", map_name, &x, &y,
character) < 4 || x < 0 || y < 0)
{
- clif_displaymessage (fd,
+ clif_displaymessage(fd,
"Please, enter a valid save point and a player name (usage: @charsave <map> <x> <y> <charname>).");
return -1;
}
- if (strstr (map_name, ".gat") == NULL && strstr (map_name, ".afm") == NULL && strlen (map_name) < 13) // 16 - 4 (.gat)
- strcat (map_name, ".gat");
+ if (strstr(map_name, ".gat") == NULL && strstr(map_name, ".afm") == NULL && strlen(map_name) < 13) // 16 - 4 (.gat)
+ strcat(map_name, ".gat");
- if ((pl_sd = map_nick2sd (character)) != NULL)
+ if ((pl_sd = map_nick2sd(character)) != NULL)
{
- if (pc_isGM (sd) >= pc_isGM (pl_sd))
+ if (pc_isGM(sd) >= pc_isGM(pl_sd))
{ // you can change save point only to lower or same gm level
- m = map_mapname2mapid (map_name);
+ m = map_mapname2mapid(map_name);
if (m < 0)
{
- clif_displaymessage (fd, "Map not found.");
+ clif_displaymessage(fd, "Map not found.");
return -1;
}
else
{
if (m >= 0 && map[m].flag.nowarpto
- && battle_config.any_warp_GM_min_level > pc_isGM (sd))
+ && battle_config.any_warp_GM_min_level > pc_isGM(sd))
{
- clif_displaymessage (fd,
+ clif_displaymessage(fd,
"You are not authorised to set this map as a save map.");
return -1;
}
- pc_setsavepoint (pl_sd, map_name, x, y);
- clif_displaymessage (fd, "Character's respawn point changed.");
+ pc_setsavepoint(pl_sd, map_name, x, y);
+ clif_displaymessage(fd, "Character's respawn point changed.");
}
}
else
{
- clif_displaymessage (fd, "Your GM level don't authorise you to do this action on this player.");
+ clif_displaymessage(fd, "Your GM level don't authorise you to do this action on this player.");
return -1;
}
}
else
{
- clif_displaymessage (fd, "Character not found.");
- return -1;
- }
-
- return 0;
-}
-
-/*==========================================
- *
- *------------------------------------------
- */
-int atcommand_night (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
-{
- struct map_session_data *pl_sd;
- int i;
-
- if (night_flag != 1)
- {
- night_flag = 1; // 0=day, 1=night [Yor]
- for (i = 0; i < fd_max; i++)
- {
- if (session[i] && (pl_sd = (struct map_session_data *)session[i]->session_data)
- && pl_sd->state.auth)
- {
- pl_sd->opt2 |= STATE_BLIND;
- clif_changeoption (&pl_sd->bl);
- clif_displaymessage (pl_sd->fd, "Night has fallen.");
- }
- }
- }
- else
- {
- clif_displaymessage (fd, "Sorry, it's already the night. Impossible to execute the command.");
- return -1;
- }
-
- return 0;
-}
-
-/*==========================================
- *
- *------------------------------------------
- */
-int atcommand_day (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
-{
- struct map_session_data *pl_sd;
- int i;
-
- if (night_flag != 0)
- {
- night_flag = 0; // 0=day, 1=night [Yor]
- for (i = 0; i < fd_max; i++)
- {
- if (session[i] && (pl_sd = (struct map_session_data *)session[i]->session_data)
- && pl_sd->state.auth)
- {
- pl_sd->opt2 &= ~STATE_BLIND;
- clif_changeoption (&pl_sd->bl);
- clif_displaymessage (pl_sd->fd, "Day has arrived.");
- }
- }
- }
- else
- {
- clif_displaymessage (fd, "Sorry, it's already the day. Impossible to execute the command.");
+ clif_displaymessage(fd, "Character not found.");
return -1;
}
@@ -4287,23 +3146,23 @@ int atcommand_day (const int fd, struct map_session_data *sd,
*
*------------------------------------------
*/
-int atcommand_doom (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_doom(const int fd, struct map_session_data *sd,
+ const char *, const char *)
{
struct map_session_data *pl_sd;
- int i;
+ int i;
for (i = 0; i < fd_max; i++)
{
if (session[i] && (pl_sd = (struct map_session_data *)session[i]->session_data)
&& pl_sd->state.auth && i != fd
- && pc_isGM (sd) >= pc_isGM (pl_sd))
+ && pc_isGM(sd) >= pc_isGM(pl_sd))
{ // you can doom only lower or same gm level
- pc_damage (NULL, pl_sd, pl_sd->status.hp + 1);
- clif_displaymessage (pl_sd->fd, "The holy messenger has given judgement.");
+ pc_damage(NULL, pl_sd, pl_sd->status.hp + 1);
+ clif_displaymessage(pl_sd->fd, "The holy messenger has given judgement.");
}
}
- clif_displaymessage (fd, "Judgement was made.");
+ clif_displaymessage(fd, "Judgement was made.");
return 0;
}
@@ -4312,23 +3171,23 @@ int atcommand_doom (const int fd, struct map_session_data *sd,
*
*------------------------------------------
*/
-int atcommand_doommap (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_doommap(const int fd, struct map_session_data *sd,
+ const char *, const char *)
{
struct map_session_data *pl_sd;
- int i;
+ int i;
for (i = 0; i < fd_max; i++)
{
if (session[i] && (pl_sd = (struct map_session_data *)session[i]->session_data)
&& pl_sd->state.auth && i != fd && sd->bl.m == pl_sd->bl.m
- && pc_isGM (sd) >= pc_isGM (pl_sd))
+ && pc_isGM(sd) >= pc_isGM(pl_sd))
{ // you can doom only lower or same gm level
- pc_damage (NULL, pl_sd, pl_sd->status.hp + 1);
- clif_displaymessage (pl_sd->fd, "The holy messenger has given judgement.");
+ pc_damage(NULL, pl_sd, pl_sd->status.hp + 1);
+ clif_displaymessage(pl_sd->fd, "The holy messenger has given judgement.");
}
}
- clif_displaymessage (fd, "Judgement was made.");
+ clif_displaymessage(fd, "Judgement was made.");
return 0;
}
@@ -4337,17 +3196,18 @@ int atcommand_doommap (const int fd, struct map_session_data *sd,
*
*------------------------------------------
*/
-static void atcommand_raise_sub (struct map_session_data *sd)
+static
+void atcommand_raise_sub(struct map_session_data *sd)
{
- if (sd && sd->state.auth && pc_isdead (sd))
+ if (sd && sd->state.auth && pc_isdead(sd))
{
sd->status.hp = sd->status.max_hp;
sd->status.sp = sd->status.max_sp;
- pc_setstand (sd);
- clif_updatestatus (sd, SP_HP);
- clif_updatestatus (sd, SP_SP);
- clif_resurrection (&sd->bl, 1);
- clif_displaymessage (sd->fd, "Mercy has been shown.");
+ pc_setstand(sd);
+ clif_updatestatus(sd, SP::HP);
+ clif_updatestatus(sd, SP::SP);
+ clif_resurrection(&sd->bl, 1);
+ clif_displaymessage(sd->fd, "Mercy has been shown.");
}
}
@@ -4355,17 +3215,17 @@ static void atcommand_raise_sub (struct map_session_data *sd)
*
*------------------------------------------
*/
-int atcommand_raise (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_raise(const int fd, struct map_session_data *,
+ const char *, const char *)
{
- int i;
+ int i;
for (i = 0; i < fd_max; i++)
{
if (session[i])
- atcommand_raise_sub ((struct map_session_data *)session[i]->session_data);
+ atcommand_raise_sub((struct map_session_data *)session[i]->session_data);
}
- clif_displaymessage (fd, "Mercy has been granted.");
+ clif_displaymessage(fd, "Mercy has been granted.");
return 0;
}
@@ -4374,19 +3234,19 @@ int atcommand_raise (const int fd, struct map_session_data *sd,
*
*------------------------------------------
*/
-int atcommand_raisemap (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_raisemap(const int fd, struct map_session_data *sd,
+ const char *, const char *)
{
struct map_session_data *pl_sd;
- int i;
+ int i;
for (i = 0; i < fd_max; i++)
{
if (session[i] && (pl_sd = (struct map_session_data *)session[i]->session_data)
&& pl_sd->state.auth && sd->bl.m == pl_sd->bl.m)
- atcommand_raise_sub (pl_sd);
+ atcommand_raise_sub(pl_sd);
}
- clif_displaymessage (fd, "Mercy has been granted.");
+ clif_displaymessage(fd, "Mercy has been granted.");
return 0;
}
@@ -4395,34 +3255,34 @@ int atcommand_raisemap (const int fd, struct map_session_data *sd,
* atcommand_character_baselevel @charbaselvlã§å¯¾è±¡ã‚­ãƒ£ãƒ©ã®ãƒ¬ãƒ™ãƒ«ã‚’上ã’ã‚‹
*------------------------------------------
*/
-int atcommand_character_baselevel (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_character_baselevel(const int fd, struct map_session_data *sd,
+ const char *, const char *message)
{
struct map_session_data *pl_sd;
char character[100];
- int level = 0, i;
+ int level = 0, i;
- memset (character, '\0', sizeof (character));
+ memset(character, '\0', sizeof(character));
if (!message || !*message
- || sscanf (message, "%d %99[^\n]", &level, character) < 2
+ || sscanf(message, "%d %99[^\n]", &level, character) < 2
|| level == 0)
{
- clif_displaymessage (fd,
+ clif_displaymessage(fd,
"Please, enter a level adjustement and a player name (usage: @charblvl <#> <nickname>).");
return -1;
}
- if ((pl_sd = map_nick2sd (character)) != NULL)
+ if ((pl_sd = map_nick2sd(character)) != NULL)
{
- if (pc_isGM (sd) >= pc_isGM (pl_sd))
+ if (pc_isGM(sd) >= pc_isGM(pl_sd))
{ // you can change base level only lower or same gm level
if (level > 0)
{
if (pl_sd->status.base_level == battle_config.maximum_level)
{ // check for max level by Valaris
- clif_displaymessage (fd, "Character's base level can't go any higher.");
+ clif_displaymessage(fd, "Character's base level can't go any higher.");
return 0;
} // End Addition
if (level > battle_config.maximum_level || level > (battle_config.maximum_level - pl_sd->status.base_level)) // fix positiv overflow
@@ -4433,19 +3293,19 @@ int atcommand_character_baselevel (const int fd, struct map_session_data *sd,
pl_sd->status.status_point +=
(pl_sd->status.base_level + i + 14) / 4;
pl_sd->status.base_level += level;
- clif_updatestatus (pl_sd, SP_BASELEVEL);
- clif_updatestatus (pl_sd, SP_NEXTBASEEXP);
- clif_updatestatus (pl_sd, SP_STATUSPOINT);
- pc_calcstatus (pl_sd, 0);
- pc_heal (pl_sd, pl_sd->status.max_hp, pl_sd->status.max_sp);
- clif_misceffect (&pl_sd->bl, 0);
- clif_displaymessage (fd, "Character's base level raised.");
+ clif_updatestatus(pl_sd, SP::BASELEVEL);
+ clif_updatestatus(pl_sd, SP::NEXTBASEEXP);
+ clif_updatestatus(pl_sd, SP::STATUSPOINT);
+ pc_calcstatus(pl_sd, 0);
+ pc_heal(pl_sd, pl_sd->status.max_hp, pl_sd->status.max_sp);
+ clif_misceffect(&pl_sd->bl, 0);
+ clif_displaymessage(fd, "Character's base level raised.");
}
else
{
if (pl_sd->status.base_level == 1)
{
- clif_displaymessage (fd, "Character's base level can't go any lower.");
+ clif_displaymessage(fd, "Character's base level can't go any lower.");
return -1;
}
if (level < -battle_config.maximum_level || level < (1 - pl_sd->status.base_level)) // fix negativ overflow
@@ -4457,28 +3317,28 @@ int atcommand_character_baselevel (const int fd, struct map_session_data *sd,
(pl_sd->status.base_level + i + 14) / 4;
if (pl_sd->status.status_point < 0)
pl_sd->status.status_point = 0;
- clif_updatestatus (pl_sd, SP_STATUSPOINT);
+ clif_updatestatus(pl_sd, SP::STATUSPOINT);
} // to add: remove status points from stats
pl_sd->status.base_level += level;
pl_sd->status.base_exp = 0;
- clif_updatestatus (pl_sd, SP_BASELEVEL);
- clif_updatestatus (pl_sd, SP_NEXTBASEEXP);
- clif_updatestatus (pl_sd, SP_BASEEXP);
- pc_calcstatus (pl_sd, 0);
- clif_displaymessage (fd, "Character's base level lowered.");
+ clif_updatestatus(pl_sd, SP::BASELEVEL);
+ clif_updatestatus(pl_sd, SP::NEXTBASEEXP);
+ clif_updatestatus(pl_sd, SP::BASEEXP);
+ pc_calcstatus(pl_sd, 0);
+ clif_displaymessage(fd, "Character's base level lowered.");
}
- // Reset their stat points to prevent extra points from stacking
- atcommand_charstreset(fd, sd,"@charstreset", character);
+ // Reset their stat points to prevent extra points from stacking
+ atcommand_charstreset(fd, sd,"@charstreset", character);
}
else
{
- clif_displaymessage (fd, "Your GM level don't authorise you to do this action on this player.");
+ clif_displaymessage(fd, "Your GM level don't authorise you to do this action on this player.");
return -1;
}
}
else
{
- clif_displaymessage (fd, "Character not found.");
+ clif_displaymessage(fd, "Character not found.");
return -1;
}
@@ -4489,86 +3349,81 @@ int atcommand_character_baselevel (const int fd, struct map_session_data *sd,
* atcommand_character_joblevel @charjoblvlã§å¯¾è±¡ã‚­ãƒ£ãƒ©ã®Jobレベルを上ã’ã‚‹
*------------------------------------------
*/
-int atcommand_character_joblevel (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_character_joblevel(const int fd, struct map_session_data *sd,
+ const char *, const char *message)
{
struct map_session_data *pl_sd;
char character[100];
- int max_level = 50, level = 0;
- //転生や養å­ã®å ´åˆã®å…ƒã®è·æ¥­ã‚’算出ã™ã‚‹
- struct pc_base_job pl_s_class;
+ int max_level = 50, level = 0;
- memset (character, '\0', sizeof (character));
+ memset(character, '\0', sizeof(character));
if (!message || !*message
- || sscanf (message, "%d %99[^\n]", &level, character) < 2
+ || sscanf(message, "%d %99[^\n]", &level, character) < 2
|| level == 0)
{
- clif_displaymessage (fd,
+ clif_displaymessage(fd,
"Please, enter a level adjustement and a player name (usage: @charjlvl <#> <nickname>).");
return -1;
}
- if ((pl_sd = map_nick2sd (character)) != NULL)
+ if ((pl_sd = map_nick2sd(character)) != NULL)
{
- pl_s_class = pc_calc_base_job (pl_sd->status.pc_class);
- if (pc_isGM (sd) >= pc_isGM (pl_sd))
- { // you can change job level only lower or same gm level
- if (pl_s_class.job == 0)
- max_level -= 40;
- if ((pl_s_class.job == 23) || (pl_s_class.upper == 1 && pl_s_class.type == 2)) //スパノビã¨è»¢ç”Ÿè·ã¯Jobレベルã®æœ€é«˜ãŒ70
- max_level += 20;
+ if (pc_isGM(sd) >= pc_isGM(pl_sd))
+ {
+ // you can change job level only lower or same gm level
+ max_level -= 40;
if (level > 0)
{
if (pl_sd->status.job_level == max_level)
{
- clif_displaymessage (fd, "Character's job level can't go any higher.");
+ clif_displaymessage(fd, "Character's job level can't go any higher.");
return -1;
}
if (pl_sd->status.job_level + level > max_level)
level = max_level - pl_sd->status.job_level;
pl_sd->status.job_level += level;
- clif_updatestatus (pl_sd, SP_JOBLEVEL);
- clif_updatestatus (pl_sd, SP_NEXTJOBEXP);
+ clif_updatestatus(pl_sd, SP::JOBLEVEL);
+ clif_updatestatus(pl_sd, SP::NEXTJOBEXP);
pl_sd->status.skill_point += level;
- clif_updatestatus (pl_sd, SP_SKILLPOINT);
- pc_calcstatus (pl_sd, 0);
- clif_misceffect (&pl_sd->bl, 1);
- clif_displaymessage (fd, "character's job level raised.");
+ clif_updatestatus(pl_sd, SP::SKILLPOINT);
+ pc_calcstatus(pl_sd, 0);
+ clif_misceffect(&pl_sd->bl, 1);
+ clif_displaymessage(fd, "character's job level raised.");
}
else
{
if (pl_sd->status.job_level == 1)
{
- clif_displaymessage (fd, "Character's job level can't go any lower.");
+ clif_displaymessage(fd, "Character's job level can't go any lower.");
return -1;
}
if (pl_sd->status.job_level + level < 1)
level = 1 - pl_sd->status.job_level;
pl_sd->status.job_level += level;
- clif_updatestatus (pl_sd, SP_JOBLEVEL);
- clif_updatestatus (pl_sd, SP_NEXTJOBEXP);
+ clif_updatestatus(pl_sd, SP::JOBLEVEL);
+ clif_updatestatus(pl_sd, SP::NEXTJOBEXP);
if (pl_sd->status.skill_point > 0)
{
pl_sd->status.skill_point += level;
if (pl_sd->status.skill_point < 0)
pl_sd->status.skill_point = 0;
- clif_updatestatus (pl_sd, SP_SKILLPOINT);
+ clif_updatestatus(pl_sd, SP::SKILLPOINT);
} // to add: remove status points from skills
- pc_calcstatus (pl_sd, 0);
- clif_displaymessage (fd, "Character's job level lowered.");
+ pc_calcstatus(pl_sd, 0);
+ clif_displaymessage(fd, "Character's job level lowered.");
}
}
else
{
- clif_displaymessage (fd, "Your GM level don't authorise you to do this action on this player.");
+ clif_displaymessage(fd, "Your GM level don't authorise you to do this action on this player.");
return -1;
}
}
else
{
- clif_displaymessage (fd, "Character not found.");
+ clif_displaymessage(fd, "Character not found.");
return -1;
}
@@ -4579,34 +3434,34 @@ int atcommand_character_joblevel (const int fd, struct map_session_data *sd,
*
*------------------------------------------
*/
-int atcommand_kick (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_kick(const int fd, struct map_session_data *sd,
+ const char *, const char *message)
{
struct map_session_data *pl_sd;
char character[100];
- memset (character, '\0', sizeof (character));
+ memset(character, '\0', sizeof(character));
- if (!message || !*message || sscanf (message, "%99[^\n]", character) < 1)
+ if (!message || !*message || sscanf(message, "%99[^\n]", character) < 1)
{
- clif_displaymessage (fd,
+ clif_displaymessage(fd,
"Please, enter a player name (usage: @kick <charname>).");
return -1;
}
- if ((pl_sd = map_nick2sd (character)) != NULL)
+ if ((pl_sd = map_nick2sd(character)) != NULL)
{
- if (pc_isGM (sd) >= pc_isGM (pl_sd)) // you can kick only lower or same gm level
- clif_GM_kick (sd, pl_sd, 1);
+ if (pc_isGM(sd) >= pc_isGM(pl_sd)) // you can kick only lower or same gm level
+ clif_GM_kick(sd, pl_sd, 1);
else
{
- clif_displaymessage (fd, "Your GM level don't authorise you to do this action on this player.");
+ clif_displaymessage(fd, "Your GM level don't authorise you to do this action on this player.");
return -1;
}
}
else
{
- clif_displaymessage (fd, "Character not found.");
+ clif_displaymessage(fd, "Character not found.");
return -1;
}
@@ -4617,23 +3472,23 @@ int atcommand_kick (const int fd, struct map_session_data *sd,
*
*------------------------------------------
*/
-int atcommand_kickall (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_kickall(const int fd, struct map_session_data *sd,
+ const char *, const char *)
{
struct map_session_data *pl_sd;
- int i;
+ int i;
for (i = 0; i < fd_max; i++)
{
if (session[i] && (pl_sd = (struct map_session_data *)session[i]->session_data)
- && pl_sd->state.auth && pc_isGM (sd) >= pc_isGM (pl_sd))
+ && pl_sd->state.auth && pc_isGM(sd) >= pc_isGM(pl_sd))
{ // you can kick only lower or same gm level
if (sd->status.account_id != pl_sd->status.account_id)
- clif_GM_kick (sd, pl_sd, 0);
+ clif_GM_kick(sd, pl_sd, 0);
}
}
- clif_displaymessage (fd, "All players have been kicked!");
+ clif_displaymessage(fd, "All players have been kicked!");
return 0;
}
@@ -4642,57 +3497,44 @@ int atcommand_kickall (const int fd, struct map_session_data *sd,
*
*------------------------------------------
*/
-int atcommand_allskills (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_questskill(const int fd, struct map_session_data *sd,
+ const char *, const char *message)
{
- pc_allskillup (sd); // all skills
- sd->status.skill_point = 0; // 0 skill points
- clif_updatestatus (sd, SP_SKILLPOINT); // update
- clif_displaymessage (fd, "You have received all skills.");
+ int skill_id_;
- return 0;
-}
-
-/*==========================================
- *
- *------------------------------------------
- */
-int atcommand_questskill (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
-{
- int skill_id;
-
- if (!message || !*message || (skill_id = atoi (message)) < 0)
+ if (!message || !*message || (skill_id_ = atoi(message)) < 0)
{
- clif_displaymessage (fd,
+ clif_displaymessage(fd,
"Please, enter a quest skill number (usage: @questskill <#:0+>).");
return -1;
}
- if (skill_id >= 0 && skill_id < MAX_SKILL_DB)
+ SkillID skill_id = SkillID(skill_id_);
+
+ if (/*skill_id >= SkillID() &&*/ skill_id < SkillID::MAX_SKILL_DB)
{
- if (skill_get_inf2 (skill_id) & 0x01)
+ if (skill_get_inf2(skill_id) & 0x01)
{
- if (pc_checkskill (sd, skill_id) == 0)
+ if (pc_checkskill(sd, skill_id) == 0)
{
- pc_skill (sd, skill_id, 1, 0);
- clif_displaymessage (fd, "You have learned the skill.");
+ pc_skill(sd, skill_id, 1, 0);
+ clif_displaymessage(fd, "You have learned the skill.");
}
else
{
- clif_displaymessage (fd, "You already have this quest skill.");
+ clif_displaymessage(fd, "You already have this quest skill.");
return -1;
}
}
else
{
- clif_displaymessage (fd, "This skill number doesn't exist or isn't a quest skill.");
+ clif_displaymessage(fd, "This skill number doesn't exist or isn't a quest skill.");
return -1;
}
}
else
{
- clif_displaymessage (fd, "This skill number doesn't exist.");
+ clif_displaymessage(fd, "This skill number doesn't exist.");
return -1;
}
@@ -4703,56 +3545,58 @@ int atcommand_questskill (const int fd, struct map_session_data *sd,
*
*------------------------------------------
*/
-int atcommand_charquestskill (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_charquestskill(const int fd, struct map_session_data *,
+ const char *, const char *message)
{
char character[100];
struct map_session_data *pl_sd;
- int skill_id = 0;
+ int skill_id_ = 0;
- memset (character, '\0', sizeof (character));
+ memset(character, '\0', sizeof(character));
if (!message || !*message
- || sscanf (message, "%d %99[^\n]", &skill_id, character) < 2
- || skill_id < 0)
+ || sscanf(message, "%d %99[^\n]", &skill_id_, character) < 2
+ || skill_id_ < 0)
{
- clif_displaymessage (fd,
+ clif_displaymessage(fd,
"Please, enter a quest skill number and a player name (usage: @charquestskill <#:0+> <char_name>).");
return -1;
}
- if (skill_id >= 0 && skill_id < MAX_SKILL_DB)
+ SkillID skill_id = SkillID(skill_id_);
+
+ if (/*skill_id >= SkillID() &&*/ skill_id < SkillID::MAX_SKILL_DB)
{
- if (skill_get_inf2 (skill_id) & 0x01)
+ if (skill_get_inf2(skill_id) & 0x01)
{
- if ((pl_sd = map_nick2sd (character)) != NULL)
+ if ((pl_sd = map_nick2sd(character)) != NULL)
{
- if (pc_checkskill (pl_sd, skill_id) == 0)
+ if (pc_checkskill(pl_sd, skill_id) == 0)
{
- pc_skill (pl_sd, skill_id, 1, 0);
- clif_displaymessage (fd, "This player has learned the skill.");
+ pc_skill(pl_sd, skill_id, 1, 0);
+ clif_displaymessage(fd, "This player has learned the skill.");
}
else
{
- clif_displaymessage (fd, "This player already has this quest skill.");
+ clif_displaymessage(fd, "This player already has this quest skill.");
return -1;
}
}
else
{
- clif_displaymessage (fd, "Character not found.");
+ clif_displaymessage(fd, "Character not found.");
return -1;
}
}
else
{
- clif_displaymessage (fd, "This skill number doesn't exist or isn't a quest skill.");
+ clif_displaymessage(fd, "This skill number doesn't exist or isn't a quest skill.");
return -1;
}
}
else
{
- clif_displaymessage (fd, "This skill number doesn't exist.");
+ clif_displaymessage(fd, "This skill number doesn't exist.");
return -1;
}
@@ -4763,44 +3607,46 @@ int atcommand_charquestskill (const int fd, struct map_session_data *sd,
*
*------------------------------------------
*/
-int atcommand_lostskill (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_lostskill(const int fd, struct map_session_data *sd,
+ const char *, const char *message)
{
- int skill_id;
+ int skill_id_;
- if (!message || !*message || (skill_id = atoi (message)) < 0)
+ if (!message || !*message || (skill_id_ = atoi(message)) < 0)
{
- clif_displaymessage (fd,
+ clif_displaymessage(fd,
"Please, enter a quest skill number (usage: @lostskill <#:0+>).");
return -1;
}
- if (skill_id >= 0 && skill_id < MAX_SKILL)
+ SkillID skill_id = SkillID(skill_id_);
+
+ if (/*skill_id >= SkillID() &&*/ skill_id < MAX_SKILL)
{
- if (skill_get_inf2 (skill_id) & 0x01)
+ if (skill_get_inf2(skill_id) & 0x01)
{
- if (pc_checkskill (sd, skill_id) > 0)
+ if (pc_checkskill(sd, skill_id) > 0)
{
sd->status.skill[skill_id].lv = 0;
- sd->status.skill[skill_id].flags = 0;
- clif_skillinfoblock (sd);
- clif_displaymessage (fd, "You have forgotten the skill.");
+ sd->status.skill[skill_id].flags = SkillFlags::ZERO;
+ clif_skillinfoblock(sd);
+ clif_displaymessage(fd, "You have forgotten the skill.");
}
else
{
- clif_displaymessage (fd, "You don't have this quest skill.");
+ clif_displaymessage(fd, "You don't have this quest skill.");
return -1;
}
}
else
{
- clif_displaymessage (fd, "This skill number doesn't exist or isn't a quest skill.");
+ clif_displaymessage(fd, "This skill number doesn't exist or isn't a quest skill.");
return -1;
}
}
else
{
- clif_displaymessage (fd, "This skill number doesn't exist.");
+ clif_displaymessage(fd, "This skill number doesn't exist.");
return -1;
}
@@ -4811,58 +3657,60 @@ int atcommand_lostskill (const int fd, struct map_session_data *sd,
*
*------------------------------------------
*/
-int atcommand_charlostskill (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_charlostskill(const int fd, struct map_session_data *,
+ const char *, const char *message)
{
char character[100];
struct map_session_data *pl_sd;
- int skill_id = 0;
+ int skill_id_ = 0;
- memset (character, '\0', sizeof (character));
+ memset(character, '\0', sizeof(character));
if (!message || !*message
- || sscanf (message, "%d %99[^\n]", &skill_id, character) < 2
- || skill_id < 0)
+ || sscanf(message, "%d %99[^\n]", &skill_id_, character) < 2
+ || skill_id_ < 0)
{
- clif_displaymessage (fd,
+ clif_displaymessage(fd,
"Please, enter a quest skill number and a player name (usage: @charlostskill <#:0+> <char_name>).");
return -1;
}
- if (skill_id >= 0 && skill_id < MAX_SKILL)
+ SkillID skill_id = SkillID(skill_id_);
+
+ if (/*skill_id >= SkillID() &&*/ skill_id < MAX_SKILL)
{
- if (skill_get_inf2 (skill_id) & 0x01)
+ if (skill_get_inf2(skill_id) & 0x01)
{
- if ((pl_sd = map_nick2sd (character)) != NULL)
+ if ((pl_sd = map_nick2sd(character)) != NULL)
{
- if (pc_checkskill (pl_sd, skill_id) > 0)
+ if (pc_checkskill(pl_sd, skill_id) > 0)
{
pl_sd->status.skill[skill_id].lv = 0;
- pl_sd->status.skill[skill_id].flags = 0;
- clif_skillinfoblock (pl_sd);
- clif_displaymessage (fd, "This player has forgotten the skill.");
+ pl_sd->status.skill[skill_id].flags = SkillFlags::ZERO;
+ clif_skillinfoblock(pl_sd);
+ clif_displaymessage(fd, "This player has forgotten the skill.");
}
else
{
- clif_displaymessage (fd, "This player doesn't have this quest skill.");
+ clif_displaymessage(fd, "This player doesn't have this quest skill.");
return -1;
}
}
else
{
- clif_displaymessage (fd, "Character not found.");
+ clif_displaymessage(fd, "Character not found.");
return -1;
}
}
else
{
- clif_displaymessage (fd, "This skill number doesn't exist or isn't a quest skill.");
+ clif_displaymessage(fd, "This skill number doesn't exist or isn't a quest skill.");
return -1;
}
}
else
{
- clif_displaymessage (fd, "This skill number doesn't exist.");
+ clif_displaymessage(fd, "This skill number doesn't exist.");
return -1;
}
@@ -4873,88 +3721,21 @@ int atcommand_charlostskill (const int fd, struct map_session_data *sd,
*
*------------------------------------------
*/
-int atcommand_party (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_party(const int fd, struct map_session_data *sd,
+ const char *, const char *message)
{
char party[100];
- memset (party, '\0', sizeof (party));
+ memset(party, '\0', sizeof(party));
- if (!message || !*message || sscanf (message, "%99[^\n]", party) < 1)
+ if (!message || !*message || sscanf(message, "%99[^\n]", party) < 1)
{
- clif_displaymessage (fd,
+ clif_displaymessage(fd,
"Please, enter a party name (usage: @party <party_name>).");
return -1;
}
- party_create (sd, party);
-
- return 0;
-}
-
-/*==========================================
- *
- *------------------------------------------
- */
-int atcommand_guild (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
-{
- char guild[100];
- int prev;
-
- memset (guild, '\0', sizeof (guild));
-
- if (!message || !*message || sscanf (message, "%99[^\n]", guild) < 1)
- {
- clif_displaymessage (fd,
- "Please, enter a guild name (usage: @guild <guild_name>).");
- return -1;
- }
-
- prev = battle_config.guild_emperium_check;
- battle_config.guild_emperium_check = 0;
- guild_create (sd, guild);
- battle_config.guild_emperium_check = prev;
-
- return 0;
-}
-
-/*==========================================
- *
- *------------------------------------------
- */
-int atcommand_agitstart (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
-{
- if (agit_flag == 1)
- {
- clif_displaymessage (fd, "Already it has started siege warfare.");
- return -1;
- }
-
- agit_flag = 1;
- guild_agit_start ();
- clif_displaymessage (fd, "Guild siege warfare start!");
-
- return 0;
-}
-
-/*==========================================
- *
- *------------------------------------------
- */
-int atcommand_agitend (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
-{
- if (agit_flag == 0)
- {
- clif_displaymessage (fd, "Siege warfare hasn't started yet.");
- return -1;
- }
-
- agit_flag = 0;
- guild_agit_end ();
- clif_displaymessage (fd, "Guild siege warfare end!");
+ party_create(sd, party);
return 0;
}
@@ -4963,11 +3744,11 @@ int atcommand_agitend (const int fd, struct map_session_data *sd,
* @mapexitã§ãƒžãƒƒãƒ—サーãƒãƒ¼ã‚’終了ã•ã›ã‚‹
*------------------------------------------
*/
-int atcommand_mapexit (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_mapexit(const int, struct map_session_data *sd,
+ const char *, const char *)
{
struct map_session_data *pl_sd;
- int i;
+ int i;
for (i = 0; i < fd_max; i++)
{
@@ -4975,10 +3756,10 @@ int atcommand_mapexit (const int fd, struct map_session_data *sd,
&& pl_sd->state.auth)
{
if (sd->status.account_id != pl_sd->status.account_id)
- clif_GM_kick (sd, pl_sd, 0);
+ clif_GM_kick(sd, pl_sd, 0);
}
}
- clif_GM_kick (sd, sd, 0);
+ clif_GM_kick(sd, sd, 0);
runflag = 0;
@@ -4989,39 +3770,37 @@ int atcommand_mapexit (const int fd, struct map_session_data *sd,
* idsearch <part_of_name>: revrited by [Yor]
*------------------------------------------
*/
-int atcommand_idsearch (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_idsearch(const int fd, struct map_session_data *,
+ const char *, const char *message)
{
char item_name[100];
- char output[200];
- int i, match;
+ int i, match;
struct item_data *item;
- memset (item_name, '\0', sizeof (item_name));
- memset (output, '\0', sizeof (output));
+ memset(item_name, '\0', sizeof(item_name));
- if (!message || !*message || sscanf (message, "%99s", item_name) < 0)
+ if (!message || !*message || sscanf(message, "%99s", item_name) < 0)
{
- clif_displaymessage (fd,
+ clif_displaymessage(fd,
"Please, enter a part of item name (usage: @idsearch <part_of_item_name>).");
return -1;
}
- sprintf (output, "The reference result of '%s' (name: id):", item_name);
- clif_displaymessage (fd, output);
+ std::string output = STRPRINTF("The reference result of '%s' (name: id):", item_name);
+ clif_displaymessage(fd, output);
match = 0;
for (i = 0; i < 20000; i++)
{
- if ((item = itemdb_exists (i)) != NULL
- && strstr (item->jname, item_name) != NULL)
+ if ((item = itemdb_exists(i)) != NULL
+ && strstr(item->jname, item_name) != NULL)
{
match++;
- sprintf (output, "%s: %d", item->jname, item->nameid);
- clif_displaymessage (fd, output);
+ output = STRPRINTF("%s: %d", item->jname, item->nameid);
+ clif_displaymessage(fd, output);
}
}
- sprintf (output, "It is %d affair above.", match);
- clif_displaymessage (fd, output);
+ output = STRPRINTF("It is %d affair above.", match);
+ clif_displaymessage(fd, output);
return 0;
}
@@ -5030,40 +3809,39 @@ int atcommand_idsearch (const int fd, struct map_session_data *sd,
* Character Skill Reset
*------------------------------------------
*/
-int atcommand_charskreset (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_charskreset(const int fd, struct map_session_data *sd,
+ const char *, const char *message)
{
char character[100];
- char output[200];
struct map_session_data *pl_sd;
- memset (character, '\0', sizeof (character));
- memset (output, '\0', sizeof (output));
+ memset(character, '\0', sizeof(character));
- if (!message || !*message || sscanf (message, "%99[^\n]", character) < 1)
+ if (!message || !*message || sscanf(message, "%99[^\n]", character) < 1)
{
- clif_displaymessage (fd,
+ clif_displaymessage(fd,
"Please, enter a player name (usage: @charskreset <charname>).");
return -1;
}
- if ((pl_sd = map_nick2sd (character)) != NULL)
+ if ((pl_sd = map_nick2sd(character)) != NULL)
{
- if (pc_isGM (sd) >= pc_isGM (pl_sd))
+ if (pc_isGM(sd) >= pc_isGM(pl_sd))
{ // you can reset skill points only lower or same gm level
- pc_resetskill (pl_sd);
- sprintf (output, "'%s' skill points reseted!", character);
- clif_displaymessage (fd, output);
+ pc_resetskill(pl_sd);
+ std::string output = STRPRINTF(
+ "'%s' skill points reseted!", character);
+ clif_displaymessage(fd, output);
}
else
{
- clif_displaymessage (fd, "Your GM level don't authorise you to do this action on this player.");
+ clif_displaymessage(fd, "Your GM level don't authorise you to do this action on this player.");
return -1;
}
}
else
{
- clif_displaymessage (fd, "Character not found.");
+ clif_displaymessage(fd, "Character not found.");
return -1;
}
@@ -5074,40 +3852,40 @@ int atcommand_charskreset (const int fd, struct map_session_data *sd,
* Character Stat Reset
*------------------------------------------
*/
-int atcommand_charstreset (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_charstreset(const int fd, struct map_session_data *sd,
+ const char *, const char *message)
{
char character[100];
- char output[200];
struct map_session_data *pl_sd;
- memset (character, '\0', sizeof (character));
- memset (output, '\0', sizeof (output));
+ memset(character, '\0', sizeof(character));
- if (!message || !*message || sscanf (message, "%99[^\n]", character) < 1)
+ if (!message || !*message || sscanf(message, "%99[^\n]", character) < 1)
{
- clif_displaymessage (fd,
+ clif_displaymessage(fd,
"Please, enter a player name (usage: @charstreset <charname>).");
return -1;
}
- if ((pl_sd = map_nick2sd (character)) != NULL)
+ if ((pl_sd = map_nick2sd(character)) != NULL)
{
- if (pc_isGM (sd) >= pc_isGM (pl_sd))
+ if (pc_isGM(sd) >= pc_isGM(pl_sd))
{ // you can reset stats points only lower or same gm level
- pc_resetstate (pl_sd);
- sprintf (output, "'%s' stats points reseted!", character);
- clif_displaymessage (fd, output);
+ pc_resetstate(pl_sd);
+ std::string output = STRPRINTF(
+ "'%s' stats points reseted!",
+ character);
+ clif_displaymessage(fd, output);
}
else
{
- clif_displaymessage (fd, "Your GM level don't authorise you to do this action on this player.");
+ clif_displaymessage(fd, "Your GM level don't authorise you to do this action on this player.");
return -1;
}
}
else
{
- clif_displaymessage (fd, "Character not found.");
+ clif_displaymessage(fd, "Character not found.");
return -1;
}
@@ -5118,43 +3896,42 @@ int atcommand_charstreset (const int fd, struct map_session_data *sd,
* Character Reset
*------------------------------------------
*/
-int atcommand_charreset (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_charreset(const int fd, struct map_session_data *sd,
+ const char *, const char *message)
{
char character[100];
- char output[200];
struct map_session_data *pl_sd;
- memset (character, '\0', sizeof (character));
- memset (output, '\0', sizeof (output));
+ memset(character, '\0', sizeof(character));
- if (!message || !*message || sscanf (message, "%99[^\n]", character) < 1)
+ if (!message || !*message || sscanf(message, "%99[^\n]", character) < 1)
{
- clif_displaymessage (fd,
+ clif_displaymessage(fd,
"Please, enter a player name (usage: @charreset <charname>).");
return -1;
}
- if ((pl_sd = map_nick2sd (character)) != NULL)
+ if ((pl_sd = map_nick2sd(character)) != NULL)
{
- if (pc_isGM (sd) >= pc_isGM (pl_sd))
+ if (pc_isGM(sd) >= pc_isGM(pl_sd))
{ // you can reset a character only for lower or same GM level
- pc_resetstate (pl_sd);
- pc_resetskill (pl_sd);
- pc_setglobalreg (pl_sd, "MAGIC_FLAGS", 0); // [Fate] Reset magic quest variables
- pc_setglobalreg (pl_sd, "MAGIC_EXP", 0); // [Fate] Reset magic experience
- sprintf (output, "'%s' skill and stats points reseted!", character);
- clif_displaymessage (fd, output);
+ pc_resetstate(pl_sd);
+ pc_resetskill(pl_sd);
+ pc_setglobalreg(pl_sd, "MAGIC_FLAGS", 0); // [Fate] Reset magic quest variables
+ pc_setglobalreg(pl_sd, "MAGIC_EXP", 0); // [Fate] Reset magic experience
+ std::string output = STRPRINTF(
+ "'%s' skill and stats points reseted!", character);
+ clif_displaymessage(fd, output);
}
else
{
- clif_displaymessage (fd, "Your GM level don't authorise you to do this action on this player.");
+ clif_displaymessage(fd, "Your GM level don't authorise you to do this action on this player.");
return -1;
}
}
else
{
- clif_displaymessage (fd, "Character not found.");
+ clif_displaymessage(fd, "Character not found.");
return -1;
}
@@ -5165,55 +3942,53 @@ int atcommand_charreset (const int fd, struct map_session_data *sd,
* Character Wipe
*------------------------------------------
*/
-int atcommand_char_wipe (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_char_wipe(const int fd, struct map_session_data *sd,
+ const char *, const char *message)
{
char character[100];
- char output[200];
struct map_session_data *pl_sd;
- memset (character, '\0', sizeof (character));
- memset (output, '\0', sizeof (output));
+ memset(character, '\0', sizeof(character));
- if (!message || !*message || sscanf (message, "%99[^\n]", character) < 1)
+ if (!message || !*message || sscanf(message, "%99[^\n]", character) < 1)
{
- clif_displaymessage (fd,
+ clif_displaymessage(fd,
"Please, enter a player name (usage: @charwipe <charname>).");
return -1;
}
- if ((pl_sd = map_nick2sd (character)) != NULL)
+ if ((pl_sd = map_nick2sd(character)) != NULL)
{
- if (pc_isGM (sd) >= pc_isGM (pl_sd))
+ if (pc_isGM(sd) >= pc_isGM(pl_sd))
{ // you can reset a character only for lower or same GM level
- int i;
+ int i;
// Reset base level
pl_sd->status.base_level = 1;
pl_sd->status.base_exp = 0;
- clif_updatestatus (pl_sd, SP_BASELEVEL);
- clif_updatestatus (pl_sd, SP_NEXTBASEEXP);
- clif_updatestatus (pl_sd, SP_BASEEXP);
+ clif_updatestatus(pl_sd, SP::BASELEVEL);
+ clif_updatestatus(pl_sd, SP::NEXTBASEEXP);
+ clif_updatestatus(pl_sd, SP::BASEEXP);
// Reset job level
pl_sd->status.job_level = 1;
pl_sd->status.job_exp = 0;
- clif_updatestatus (pl_sd, SP_JOBLEVEL);
- clif_updatestatus (pl_sd, SP_NEXTJOBEXP);
- clif_updatestatus (pl_sd, SP_JOBEXP);
+ clif_updatestatus(pl_sd, SP::JOBLEVEL);
+ clif_updatestatus(pl_sd, SP::NEXTJOBEXP);
+ clif_updatestatus(pl_sd, SP::JOBEXP);
// Zeny to 50
pl_sd->status.zeny = 50;
- clif_updatestatus (pl_sd, SP_ZENY);
+ clif_updatestatus(pl_sd, SP::ZENY);
// Clear inventory
for (i = 0; i < MAX_INVENTORY; i++)
{
if (sd->status.inventory[i].amount)
{
- if (sd->status.inventory[i].equip)
- pc_unequipitem (pl_sd, i, 0);
- pc_delitem (pl_sd, i, sd->status.inventory[i].amount, 0);
+ if (bool(sd->status.inventory[i].equip))
+ pc_unequipitem(pl_sd, i, CalcStatus::NOW);
+ pc_delitem(pl_sd, i, sd->status.inventory[i].amount, 0);
}
}
@@ -5222,29 +3997,29 @@ int atcommand_char_wipe (const int fd, struct map_session_data *sd,
item.nameid = 1201; // knife
item.identify = 1;
item.broken = 0;
- pc_additem (pl_sd, &item, 1);
+ pc_additem(pl_sd, &item, 1);
item.nameid = 1202; // shirt
- pc_additem (pl_sd, &item, 1);
+ pc_additem(pl_sd, &item, 1);
// Reset stats and skills
- pc_calcstatus (pl_sd, 0);
- pc_resetstate (pl_sd);
- pc_resetskill (pl_sd);
- pc_setglobalreg (pl_sd, "MAGIC_FLAGS", 0); // [Fate] Reset magic quest variables
- pc_setglobalreg (pl_sd, "MAGIC_EXP", 0); // [Fate] Reset magic experience
-
- sprintf (output, "%s: wiped.", character);
- clif_displaymessage (fd, output);
+ pc_calcstatus(pl_sd, 0);
+ pc_resetstate(pl_sd);
+ pc_resetskill(pl_sd);
+ pc_setglobalreg(pl_sd, "MAGIC_FLAGS", 0); // [Fate] Reset magic quest variables
+ pc_setglobalreg(pl_sd, "MAGIC_EXP", 0); // [Fate] Reset magic experience
+
+ std::string output = STRPRINTF("%s: wiped.", character);
+ clif_displaymessage(fd, output);
}
else
{
- clif_displaymessage (fd, "Your GM level don't authorise you to do this action on this player.");
+ clif_displaymessage(fd, "Your GM level don't authorise you to do this action on this player.");
return -1;
}
}
else
{
- clif_displaymessage (fd, "Character not found.");
+ clif_displaymessage(fd, "Character not found.");
return -1;
}
@@ -5255,61 +4030,51 @@ int atcommand_char_wipe (const int fd, struct map_session_data *sd,
* Character Model by chbrules
*------------------------------------------
*/
-int atcommand_charmodel (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_charmodel(const int fd, struct map_session_data *,
+ const char *, const char *message)
{
- int hair_style = 0, hair_color = 0, cloth_color = 0;
+ int hair_style = 0, hair_color = 0, cloth_color = 0;
struct map_session_data *pl_sd;
char character[100];
- char output[200];
- memset (character, '\0', sizeof (character));
- memset (output, '\0', sizeof (output));
+ memset(character, '\0', sizeof(character));
if (!message || !*message
- || sscanf (message, "%d %d %d %99[^\n]", &hair_style, &hair_color,
+ || sscanf(message, "%d %d %d %99[^\n]", &hair_style, &hair_color,
&cloth_color, character) < 4 || hair_style < 0
|| hair_color < 0 || cloth_color < 0)
{
- sprintf (output,
- "Please, enter a valid model and a player name (usage: @charmodel <hair ID: %d-%d> <hair color: %d-%d> <clothes color: %d-%d> <name>).",
- MIN_HAIR_STYLE, MAX_HAIR_STYLE, MIN_HAIR_COLOR,
- MAX_HAIR_COLOR, MIN_CLOTH_COLOR, MAX_CLOTH_COLOR);
- clif_displaymessage (fd, output);
+ std::string output = STRPRINTF(
+ "Please, enter a valid model and a player name (usage: @charmodel <hair ID: %d-%d> <hair color: %d-%d> <clothes color: %d-%d> <name>).",
+ MIN_HAIR_STYLE, MAX_HAIR_STYLE,
+ MIN_HAIR_COLOR, MAX_HAIR_COLOR,
+ MIN_CLOTH_COLOR, MAX_CLOTH_COLOR);
+ clif_displaymessage(fd, output);
return -1;
}
- if ((pl_sd = map_nick2sd (character)) != NULL)
+ if ((pl_sd = map_nick2sd(character)) != NULL)
{
if (hair_style >= MIN_HAIR_STYLE && hair_style <= MAX_HAIR_STYLE &&
hair_color >= MIN_HAIR_COLOR && hair_color <= MAX_HAIR_COLOR &&
cloth_color >= MIN_CLOTH_COLOR && cloth_color <= MAX_CLOTH_COLOR)
{
-
- if (cloth_color != 0 &&
- pl_sd->status.sex == 1 &&
- (pl_sd->status.pc_class == 12 || pl_sd->status.pc_class == 17))
- {
- clif_displaymessage (fd, "You can't use this command with this class.");
- return -1;
- }
- else
{
- pc_changelook (pl_sd, LOOK_HAIR, hair_style);
- pc_changelook (pl_sd, LOOK_HAIR_COLOR, hair_color);
- pc_changelook (pl_sd, LOOK_CLOTHES_COLOR, cloth_color);
- clif_displaymessage (fd, "Appearence changed.");
+ pc_changelook(pl_sd, LOOK::HAIR, hair_style);
+ pc_changelook(pl_sd, LOOK::HAIR_COLOR, hair_color);
+ pc_changelook(pl_sd, LOOK::CLOTHES_COLOR, cloth_color);
+ clif_displaymessage(fd, "Appearence changed.");
}
}
else
{
- clif_displaymessage (fd, "An invalid number was specified.");
+ clif_displaymessage(fd, "An invalid number was specified.");
return -1;
}
}
else
{
- clif_displaymessage (fd, "Character not found.");
+ clif_displaymessage(fd, "Character not found.");
return -1;
}
@@ -5320,26 +4085,26 @@ int atcommand_charmodel (const int fd, struct map_session_data *sd,
* Character Skill Point (Rewritten by [Yor])
*------------------------------------------
*/
-int atcommand_charskpoint (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_charskpoint(const int fd, struct map_session_data *,
+ const char *, const char *message)
{
struct map_session_data *pl_sd;
char character[100];
- int new_skill_point;
- int point = 0;
+ int new_skill_point;
+ int point = 0;
- memset (character, '\0', sizeof (character));
+ memset(character, '\0', sizeof(character));
if (!message || !*message
- || sscanf (message, "%d %99[^\n]", &point, character) < 2
+ || sscanf(message, "%d %99[^\n]", &point, character) < 2
|| point == 0)
{
- clif_displaymessage (fd,
+ clif_displaymessage(fd,
"Please, enter a number and a player name (usage: @charskpoint <amount> <name>).");
return -1;
}
- if ((pl_sd = map_nick2sd (character)) != NULL)
+ if ((pl_sd = map_nick2sd(character)) != NULL)
{
new_skill_point = (int) pl_sd->status.skill_point + point;
if (point > 0 && (point > 0x7FFF || new_skill_point > 0x7FFF)) // fix positiv overflow
@@ -5349,21 +4114,21 @@ int atcommand_charskpoint (const int fd, struct map_session_data *sd,
if (new_skill_point != (int) pl_sd->status.skill_point)
{
pl_sd->status.skill_point = new_skill_point;
- clif_updatestatus (pl_sd, SP_SKILLPOINT);
- clif_displaymessage (fd, "Character's number of skill points changed!");
+ clif_updatestatus(pl_sd, SP::SKILLPOINT);
+ clif_displaymessage(fd, "Character's number of skill points changed!");
}
else
{
if (point < 0)
- clif_displaymessage (fd, "Impossible to decrease the number/value.");
+ clif_displaymessage(fd, "Impossible to decrease the number/value.");
else
- clif_displaymessage (fd, "Impossible to increase the number/value.");
+ clif_displaymessage(fd, "Impossible to increase the number/value.");
return -1;
}
}
else
{
- clif_displaymessage (fd, "Character not found.");
+ clif_displaymessage(fd, "Character not found.");
return -1;
}
@@ -5374,26 +4139,26 @@ int atcommand_charskpoint (const int fd, struct map_session_data *sd,
* Character Status Point (rewritten by [Yor])
*------------------------------------------
*/
-int atcommand_charstpoint (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_charstpoint(const int fd, struct map_session_data *,
+ const char *, const char *message)
{
struct map_session_data *pl_sd;
char character[100];
- int new_status_point;
- int point = 0;
+ int new_status_point;
+ int point = 0;
- memset (character, '\0', sizeof (character));
+ memset(character, '\0', sizeof(character));
if (!message || !*message
- || sscanf (message, "%d %99[^\n]", &point, character) < 2
+ || sscanf(message, "%d %99[^\n]", &point, character) < 2
|| point == 0)
{
- clif_displaymessage (fd,
+ clif_displaymessage(fd,
"Please, enter a number and a player name (usage: @charstpoint <amount> <name>).");
return -1;
}
- if ((pl_sd = map_nick2sd (character)) != NULL)
+ if ((pl_sd = map_nick2sd(character)) != NULL)
{
new_status_point = (int) pl_sd->status.status_point + point;
if (point > 0 && (point > 0x7FFF || new_status_point > 0x7FFF)) // fix positiv overflow
@@ -5403,21 +4168,21 @@ int atcommand_charstpoint (const int fd, struct map_session_data *sd,
if (new_status_point != (int) pl_sd->status.status_point)
{
pl_sd->status.status_point = new_status_point;
- clif_updatestatus (pl_sd, SP_STATUSPOINT);
- clif_displaymessage (fd, "Character's number of status points changed!");
+ clif_updatestatus(pl_sd, SP::STATUSPOINT);
+ clif_displaymessage(fd, "Character's number of status points changed!");
}
else
{
if (point < 0)
- clif_displaymessage (fd, "Impossible to decrease the number/value.");
+ clif_displaymessage(fd, "Impossible to decrease the number/value.");
else
- clif_displaymessage (fd, "Impossible to increase the number/value.");
+ clif_displaymessage(fd, "Impossible to increase the number/value.");
return -1;
}
}
else
{
- clif_displaymessage (fd, "Character not found.");
+ clif_displaymessage(fd, "Character not found.");
return -1;
}
@@ -5428,24 +4193,24 @@ int atcommand_charstpoint (const int fd, struct map_session_data *sd,
* Character Zeny Point (Rewritten by [Yor])
*------------------------------------------
*/
-int atcommand_charzeny (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_charzeny(const int fd, struct map_session_data *,
+ const char *, const char *message)
{
struct map_session_data *pl_sd;
char character[100];
- int zeny = 0, new_zeny;
+ int zeny = 0, new_zeny;
- memset (character, '\0', sizeof (character));
+ memset(character, '\0', sizeof(character));
if (!message || !*message
- || sscanf (message, "%d %99[^\n]", &zeny, character) < 2 || zeny == 0)
+ || sscanf(message, "%d %99[^\n]", &zeny, character) < 2 || zeny == 0)
{
- clif_displaymessage (fd,
+ clif_displaymessage(fd,
"Please, enter a number and a player name (usage: @charzeny <zeny> <name>).");
return -1;
}
- if ((pl_sd = map_nick2sd (character)) != NULL)
+ if ((pl_sd = map_nick2sd(character)) != NULL)
{
new_zeny = pl_sd->status.zeny + zeny;
if (zeny > 0 && (zeny > MAX_ZENY || new_zeny > MAX_ZENY)) // fix positiv overflow
@@ -5455,21 +4220,21 @@ int atcommand_charzeny (const int fd, struct map_session_data *sd,
if (new_zeny != pl_sd->status.zeny)
{
pl_sd->status.zeny = new_zeny;
- clif_updatestatus (pl_sd, SP_ZENY);
- clif_displaymessage (fd, "Character's number of zenys changed!");
+ clif_updatestatus(pl_sd, SP::ZENY);
+ clif_displaymessage(fd, "Character's number of zenys changed!");
}
else
{
if (zeny < 0)
- clif_displaymessage (fd, "Impossible to decrease the number/value.");
+ clif_displaymessage(fd, "Impossible to decrease the number/value.");
else
- clif_displaymessage (fd, "Impossible to increase the number/value.");
+ clif_displaymessage(fd, "Impossible to increase the number/value.");
return -1;
}
}
else
{
- clif_displaymessage (fd, "Character not found.");
+ clif_displaymessage(fd, "Character not found.");
return -1;
}
@@ -5480,20 +4245,17 @@ int atcommand_charzeny (const int fd, struct map_session_data *sd,
* Recall All Characters Online To Your Location
*------------------------------------------
*/
-int atcommand_recallall (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_recallall(const int fd, struct map_session_data *sd,
+ const char *, const char *)
{
struct map_session_data *pl_sd;
- int i;
- int count;
- char output[200];
-
- memset (output, '\0', sizeof (output));
+ int i;
+ int count;
if (sd->bl.m >= 0 && map[sd->bl.m].flag.nowarpto
- && battle_config.any_warp_GM_min_level > pc_isGM (sd))
+ && battle_config.any_warp_GM_min_level > pc_isGM(sd))
{
- clif_displaymessage (fd,
+ clif_displaymessage(fd,
"You are not authorised to warp somenone to your actual map.");
return -1;
}
@@ -5504,92 +4266,23 @@ int atcommand_recallall (const int fd, struct map_session_data *sd,
if (session[i] && (pl_sd = (struct map_session_data *)session[i]->session_data)
&& pl_sd->state.auth
&& sd->status.account_id != pl_sd->status.account_id
- && pc_isGM (sd) >= pc_isGM (pl_sd))
+ && pc_isGM(sd) >= pc_isGM(pl_sd))
{ // you can recall only lower or same level
if (pl_sd->bl.m >= 0 && map[pl_sd->bl.m].flag.nowarp
- && battle_config.any_warp_GM_min_level > pc_isGM (sd))
+ && battle_config.any_warp_GM_min_level > pc_isGM(sd))
count++;
else
- pc_setpos (pl_sd, sd->mapname, sd->bl.x, sd->bl.y, 2);
+ pc_setpos(pl_sd, sd->mapname, sd->bl.x, sd->bl.y, BeingRemoveWhy::QUIT);
}
}
- clif_displaymessage (fd, "All characters recalled!");
+ clif_displaymessage(fd, "All characters recalled!");
if (count)
{
- sprintf (output,
- "Because you are not authorised to warp from some maps, %d player(s) have not been recalled.",
- count);
- clif_displaymessage (fd, output);
- }
-
- return 0;
-}
-
-/*==========================================
- * Recall online characters of a guild to your location
- *------------------------------------------
- */
-int atcommand_guildrecall (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
-{
- struct map_session_data *pl_sd;
- int i;
- char guild_name[100];
- char output[200];
- struct guild *g;
- int count;
-
- memset (guild_name, '\0', sizeof (guild_name));
- memset (output, '\0', sizeof (output));
-
- if (!message || !*message || sscanf (message, "%99[^\n]", guild_name) < 1)
- {
- clif_displaymessage (fd,
- "Please, enter a guild name/id (usage: @guildrecall <guild_name/id>).");
- return -1;
- }
-
- if (sd->bl.m >= 0 && map[sd->bl.m].flag.nowarpto
- && battle_config.any_warp_GM_min_level > pc_isGM (sd))
- {
- clif_displaymessage (fd,
- "You are not authorised to warp somenone to your actual map.");
- return -1;
- }
-
- if ((g = guild_searchname (guild_name)) != NULL || // name first to avoid error when name begin with a number
- (g = guild_search (atoi (message))) != NULL)
- {
- count = 0;
- for (i = 0; i < fd_max; i++)
- {
- if (session[i] && (pl_sd = (struct map_session_data *)session[i]->session_data)
- && pl_sd->state.auth
- && sd->status.account_id != pl_sd->status.account_id
- && pl_sd->status.guild_id == g->guild_id)
- {
- if (pl_sd->bl.m >= 0 && map[pl_sd->bl.m].flag.nowarp
- && battle_config.any_warp_GM_min_level > pc_isGM (sd))
- count++;
- else
- pc_setpos (pl_sd, sd->mapname, sd->bl.x, sd->bl.y, 2);
- }
- }
- sprintf (output, "All online characters of the %s guild are near you.", g->name);
- clif_displaymessage (fd, output);
- if (count)
- {
- sprintf (output,
- "Because you are not authorised to warp from some maps, %d player(s) have not been recalled.",
- count);
- clif_displaymessage (fd, output);
- }
- }
- else
- {
- clif_displaymessage (fd, "Incorrect name/ID, or no one from the guild is online.");
- return -1;
+ std::string output = STRPRINTF(
+ "Because you are not authorised to warp from some maps, %d player(s) have not been recalled.",
+ count);
+ clif_displaymessage(fd, output);
}
return 0;
@@ -5599,36 +4292,34 @@ int atcommand_guildrecall (const int fd, struct map_session_data *sd,
* Recall online characters of a party to your location
*------------------------------------------
*/
-int atcommand_partyrecall (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_partyrecall(const int fd, struct map_session_data *sd,
+ const char *, const char *message)
{
- int i;
+ int i;
struct map_session_data *pl_sd;
char party_name[100];
- char output[200];
struct party *p;
- int count;
+ int count;
- memset (party_name, '\0', sizeof (party_name));
- memset (output, '\0', sizeof (output));
+ memset(party_name, '\0', sizeof(party_name));
- if (!message || !*message || sscanf (message, "%99[^\n]", party_name) < 1)
+ if (!message || !*message || sscanf(message, "%99[^\n]", party_name) < 1)
{
- clif_displaymessage (fd,
+ clif_displaymessage(fd,
"Please, enter a party name/id (usage: @partyrecall <party_name/id>).");
return -1;
}
if (sd->bl.m >= 0 && map[sd->bl.m].flag.nowarpto
- && battle_config.any_warp_GM_min_level > pc_isGM (sd))
+ && battle_config.any_warp_GM_min_level > pc_isGM(sd))
{
- clif_displaymessage (fd,
+ clif_displaymessage(fd,
"You are not authorised to warp somenone to your actual map.");
return -1;
}
- if ((p = party_searchname (party_name)) != NULL || // name first to avoid error when name begin with a number
- (p = party_search (atoi (message))) != NULL)
+ if ((p = party_searchname(party_name)) != NULL || // name first to avoid error when name begin with a number
+ (p = party_search(atoi(message))) != NULL)
{
count = 0;
for (i = 0; i < fd_max; i++)
@@ -5639,25 +4330,25 @@ int atcommand_partyrecall (const int fd, struct map_session_data *sd,
&& pl_sd->status.party_id == p->party_id)
{
if (pl_sd->bl.m >= 0 && map[pl_sd->bl.m].flag.nowarp
- && battle_config.any_warp_GM_min_level > pc_isGM (sd))
+ && battle_config.any_warp_GM_min_level > pc_isGM(sd))
count++;
else
- pc_setpos (pl_sd, sd->mapname, sd->bl.x, sd->bl.y, 2);
+ pc_setpos(pl_sd, sd->mapname, sd->bl.x, sd->bl.y, BeingRemoveWhy::QUIT);
}
}
- sprintf (output, "All online characters of the %s party are near you.", p->name);
- clif_displaymessage (fd, output);
+ std::string output = STRPRINTF("All online characters of the %s party are near you.", p->name);
+ clif_displaymessage(fd, output);
if (count)
{
- sprintf (output,
- "Because you are not authorised to warp from some maps, %d player(s) have not been recalled.",
- count);
- clif_displaymessage (fd, output);
+ output = STRPRINTF(
+ "Because you are not authorised to warp from some maps, %d player(s) have not been recalled.",
+ count);
+ clif_displaymessage(fd, output);
}
}
else
{
- clif_displaymessage (fd, "Incorrect name or ID, or no one from the party is online.");
+ clif_displaymessage(fd, "Incorrect name or ID, or no one from the party is online.");
return -1;
}
@@ -5668,11 +4359,11 @@ int atcommand_partyrecall (const int fd, struct map_session_data *sd,
*
*------------------------------------------
*/
-int atcommand_reloaditemdb (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_reloaditemdb(const int fd, struct map_session_data *,
+ const char *, const char *)
{
- itemdb_reload ();
- clif_displaymessage (fd, "Item database reloaded.");
+ itemdb_reload();
+ clif_displaymessage(fd, "Item database reloaded.");
return 0;
}
@@ -5681,11 +4372,11 @@ int atcommand_reloaditemdb (const int fd, struct map_session_data *sd,
*
*------------------------------------------
*/
-int atcommand_reloadmobdb (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_reloadmobdb(const int fd, struct map_session_data *,
+ const char *, const char *)
{
- mob_reload ();
- clif_displaymessage (fd, "Monster database reloaded.");
+ mob_reload();
+ clif_displaymessage(fd, "Monster database reloaded.");
return 0;
}
@@ -5694,11 +4385,11 @@ int atcommand_reloadmobdb (const int fd, struct map_session_data *sd,
*
*------------------------------------------
*/
-int atcommand_reloadskilldb (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_reloadskilldb(const int fd, struct map_session_data *,
+ const char *, const char *)
{
- skill_reload ();
- clif_displaymessage (fd, "Skill database reloaded.");
+ skill_reload();
+ clif_displaymessage(fd, "Skill database reloaded.");
return 0;
}
@@ -5707,15 +4398,15 @@ int atcommand_reloadskilldb (const int fd, struct map_session_data *sd,
*
*------------------------------------------
*/
-int atcommand_reloadscript (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_reloadscript(const int fd, struct map_session_data *,
+ const char *, const char *)
{
- do_init_npc ();
- do_init_script ();
+ do_init_npc();
+ do_init_script();
- npc_event_do_oninit ();
+ npc_event_do_oninit();
- clif_displaymessage (fd, "Scripts reloaded.");
+ clif_displaymessage(fd, "Scripts reloaded.");
return 0;
}
@@ -5724,13 +4415,12 @@ int atcommand_reloadscript (const int fd, struct map_session_data *sd,
*
*------------------------------------------
*/
-int atcommand_reloadgmdb ( // by [Yor]
- const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_reloadgmdb(const int fd, struct map_session_data *,
+ const char *, const char *)
{
- chrif_reloadGMdb ();
+ chrif_reloadGMdb();
- clif_displaymessage (fd, "Login-server asked to reload GM accounts and their level.");
+ clif_displaymessage(fd, "Login-server asked to reload GM accounts and their level.");
return 0;
}
@@ -5744,93 +4434,86 @@ int atcommand_reloadgmdb ( // by [Yor]
* 3 = Shows the shops/chats in that map (not implemented)
*------------------------------------------
*/
-int atcommand_mapinfo (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_mapinfo(const int fd, struct map_session_data *sd,
+ const char *, const char *message)
{
struct map_session_data *pl_sd;
struct npc_data *nd = NULL;
struct chat_data *cd = NULL;
- char output[200], map_name[100];
- char direction[12];
- int m_id, i, chat_num, list = 0;
+ char map_name[100];
+ const char *direction = NULL;
+ int m_id, i, chat_num, list = 0;
- memset (output, '\0', sizeof (output));
- memset (map_name, '\0', sizeof (map_name));
- memset (direction, '\0', sizeof (direction));
+ memset(map_name, '\0', sizeof(map_name));
- sscanf (message, "%d %99[^\n]", &list, map_name);
+ sscanf(message, "%d %99[^\n]", &list, map_name);
if (list < 0 || list > 3)
{
- clif_displaymessage (fd,
+ clif_displaymessage(fd,
"Please, enter at least a valid list number (usage: @mapinfo <0-3> [map]).");
return -1;
}
if (map_name[0] == '\0')
- strcpy (map_name, sd->mapname);
- if (strstr (map_name, ".gat") == NULL && strstr (map_name, ".afm") == NULL && strlen (map_name) < 13) // 16 - 4 (.gat)
- strcat (map_name, ".gat");
+ strcpy(map_name, sd->mapname);
+ if (strstr(map_name, ".gat") == NULL && strstr(map_name, ".afm") == NULL && strlen(map_name) < 13) // 16 - 4 (.gat)
+ strcat(map_name, ".gat");
- if ((m_id = map_mapname2mapid (map_name)) < 0)
+ if ((m_id = map_mapname2mapid(map_name)) < 0)
{
- clif_displaymessage (fd, "Map not found.");
+ clif_displaymessage(fd, "Map not found.");
return -1;
}
- clif_displaymessage (fd, "------ Map Info ------");
- sprintf (output, "Map Name: %s", map_name);
- clif_displaymessage (fd, output);
- sprintf (output, "Players In Map: %d", map[m_id].users);
- clif_displaymessage (fd, output);
- sprintf (output, "NPCs In Map: %d", map[m_id].npc_num);
- clif_displaymessage (fd, output);
+ clif_displaymessage(fd, "------ Map Info ------");
+ std::string output = STRPRINTF("Map Name: %s", map_name);
+ clif_displaymessage(fd, output);
+ output = STRPRINTF("Players In Map: %d", map[m_id].users);
+ clif_displaymessage(fd, output);
+ output = STRPRINTF("NPCs In Map: %d", map[m_id].npc_num);
+ clif_displaymessage(fd, output);
chat_num = 0;
for (i = 0; i < fd_max; i++)
{
if (session[i] && (pl_sd = (struct map_session_data *)session[i]->session_data)
&& pl_sd->state.auth
- && (cd = (struct chat_data *) map_id2bl (pl_sd->chatID)))
+ && (cd = (struct chat_data *) map_id2bl(pl_sd->chatID)))
{
chat_num++;
}
}
- sprintf (output, "Chats In Map: %d", chat_num);
- clif_displaymessage (fd, output);
- clif_displaymessage (fd, "------ Map Flags ------");
- sprintf (output, "Player vs Player: %s | No Guild: %s | No Party: %s",
+ output = STRPRINTF("Chats In Map: %d", chat_num);
+ clif_displaymessage(fd, output);
+ clif_displaymessage(fd, "------ Map Flags ------");
+ output = STRPRINTF("Player vs Player: %s | No Party: %s",
(map[m_id].flag.pvp) ? "True" : "False",
- (map[m_id].flag.pvp_noguild) ? "True" : "False",
(map[m_id].flag.pvp_noparty) ? "True" : "False");
- clif_displaymessage (fd, output);
- sprintf (output, "Guild vs Guild: %s | No Party: %s",
- (map[m_id].flag.gvg) ? "True" : "False",
- (map[m_id].flag.gvg_noparty) ? "True" : "False");
- clif_displaymessage (fd, output);
- sprintf (output, "No Dead Branch: %s",
+ clif_displaymessage(fd, output);
+ output = STRPRINTF("No Dead Branch: %s",
(map[m_id].flag.nobranch) ? "True" : "False");
- clif_displaymessage (fd, output);
- sprintf (output, "No Memo: %s",
+ clif_displaymessage(fd, output);
+ output = STRPRINTF("No Memo: %s",
(map[m_id].flag.nomemo) ? "True" : "False");
- clif_displaymessage (fd, output);
- sprintf (output, "No Penalty: %s",
+ clif_displaymessage(fd, output);
+ output = STRPRINTF("No Penalty: %s",
(map[m_id].flag.nopenalty) ? "True" : "False");
- clif_displaymessage (fd, output);
- sprintf (output, "No Return: %s",
+ clif_displaymessage(fd, output);
+ output = STRPRINTF("No Return: %s",
(map[m_id].flag.noreturn) ? "True" : "False");
- clif_displaymessage (fd, output);
- sprintf (output, "No Save: %s",
+ clif_displaymessage(fd, output);
+ output = STRPRINTF("No Save: %s",
(map[m_id].flag.nosave) ? "True" : "False");
- clif_displaymessage (fd, output);
- sprintf (output, "No Teleport: %s",
+ clif_displaymessage(fd, output);
+ output = STRPRINTF("No Teleport: %s",
(map[m_id].flag.noteleport) ? "True" : "False");
- clif_displaymessage (fd, output);
- sprintf (output, "No Monster Teleport: %s",
+ clif_displaymessage(fd, output);
+ output = STRPRINTF("No Monster Teleport: %s",
(map[m_id].flag.monster_noteleport) ? "True" : "False");
- clif_displaymessage (fd, output);
- sprintf (output, "No Zeny Penalty: %s",
+ clif_displaymessage(fd, output);
+ output = STRPRINTF("No Zeny Penalty: %s",
(map[m_id].flag.nozenypenalty) ? "True" : "False");
- clif_displaymessage (fd, output);
+ clif_displaymessage(fd, output);
switch (list)
{
@@ -5838,217 +4521,94 @@ int atcommand_mapinfo (const int fd, struct map_session_data *sd,
// Do nothing. It's list 0, no additional display.
break;
case 1:
- clif_displaymessage (fd, "----- Players in Map -----");
+ clif_displaymessage(fd, "----- Players in Map -----");
for (i = 0; i < fd_max; i++)
{
if (session[i] && (pl_sd = (struct map_session_data *)session[i]->session_data)
&& pl_sd->state.auth
- && strcmp (pl_sd->mapname, map_name) == 0)
+ && strcmp(pl_sd->mapname, map_name) == 0)
{
- sprintf (output,
+ output = STRPRINTF(
"Player '%s' (session #%d) | Location: %d,%d",
pl_sd->status.name, i, pl_sd->bl.x, pl_sd->bl.y);
- clif_displaymessage (fd, output);
+ clif_displaymessage(fd, output);
}
}
break;
case 2:
- clif_displaymessage (fd, "----- NPCs in Map -----");
+ clif_displaymessage(fd, "----- NPCs in Map -----");
for (i = 0; i < map[m_id].npc_num;)
{
nd = map[m_id].npc[i];
switch (nd->dir)
{
- case 0:
- strcpy (direction, "North");
+ case DIR::S:
+ direction = "North";
break;
- case 1:
- strcpy (direction, "North West");
+ case DIR::SW:
+ direction = "North West";
break;
- case 2:
- strcpy (direction, "West");
+ case DIR::W:
+ direction = "West";
break;
- case 3:
- strcpy (direction, "South West");
+ case DIR::NW:
+ direction = "South West";
break;
- case 4:
- strcpy (direction, "South");
+ case DIR::N:
+ direction = "South";
break;
- case 5:
- strcpy (direction, "South East");
+ case DIR::NE:
+ direction = "South East";
break;
- case 6:
- strcpy (direction, "East");
+ case DIR::E:
+ direction = "East";
break;
- case 7:
- strcpy (direction, "North East");
+ case DIR::SE:
+ direction = "North East";
break;
+#if 0
case 9:
- strcpy (direction, "North");
+ direction = "North";
break;
+#endif
default:
- strcpy (direction, "Unknown");
+ direction = "Unknown";
break;
}
- sprintf (output,
+ output = STRPRINTF(
"NPC %d: %s | Direction: %s | Sprite: %d | Location: %d %d",
++i, nd->name, direction, nd->npc_class, nd->bl.x,
nd->bl.y);
- clif_displaymessage (fd, output);
+ clif_displaymessage(fd, output);
}
break;
case 3:
- clif_displaymessage (fd, "----- Chats in Map -----");
+ clif_displaymessage(fd, "----- Chats in Map -----");
for (i = 0; i < fd_max; i++)
{
if (session[i] && (pl_sd = (struct map_session_data *)session[i]->session_data)
&& pl_sd->state.auth
- && (cd = (struct chat_data *) map_id2bl (pl_sd->chatID))
- && strcmp (pl_sd->mapname, map_name) == 0
+ && (cd = (struct chat_data *) map_id2bl(pl_sd->chatID))
+ && strcmp(pl_sd->mapname, map_name) == 0
&& cd->usersd[0] == pl_sd)
{
- sprintf (output,
+ output = STRPRINTF(
"Chat %d: %s | Player: %s | Location: %d %d", i,
cd->title, pl_sd->status.name, cd->bl.x,
cd->bl.y);
- clif_displaymessage (fd, output);
- sprintf (output,
+ clif_displaymessage(fd, output);
+ output = STRPRINTF(
" Users: %d/%d | Password: %s | Public: %s",
cd->users, cd->limit, cd->pass,
(cd->pub) ? "Yes" : "No");
- clif_displaymessage (fd, output);
+ clif_displaymessage(fd, output);
}
}
break;
default: // normally impossible to arrive here
- clif_displaymessage (fd,
+ clif_displaymessage(fd,
"Please, enter at least a valid list number (usage: @mapinfo <0-3> [map]).");
return -1;
- break;
- }
-
- return 0;
-}
-
-/*==========================================
- *
- *------------------------------------------
- */
-int atcommand_mount_peco (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
-{
- if (sd->disguise > 0)
- { // temporary prevention of crash caused by peco + disguise, will look into a better solution [Valaris]
- clif_displaymessage (fd, "Cannot mount a Peco while in disguise.");
- return -1;
- }
-
- if (!pc_isriding (sd))
- { // if actually no peco
- if (sd->status.pc_class == 7 || sd->status.pc_class == 14
- || sd->status.pc_class == 4008 || sd->status.pc_class == 4015)
- {
- if (sd->status.pc_class == 7)
- sd->status.pc_class = sd->view_class = 13;
- else if (sd->status.pc_class == 14)
- sd->status.pc_class = sd->view_class = 21;
- else if (sd->status.pc_class == 4008)
- sd->status.pc_class = sd->view_class = 4014;
- else if (sd->status.pc_class == 4015)
- sd->status.pc_class = sd->view_class = 4022;
- pc_setoption (sd, sd->status.option | 0x0020);
- clif_displaymessage (fd, "Mounted Peco.");
- }
- else
- {
- clif_displaymessage (fd, "You can not mount a peco with your job.");
- return -1;
- }
- }
- else
- {
- if (sd->status.pc_class == 13)
- sd->status.pc_class = sd->view_class = 7;
- else if (sd->status.pc_class == 21)
- sd->status.pc_class = sd->view_class = 14;
- else if (sd->status.pc_class == 4014)
- sd->status.pc_class = sd->view_class = 4008;
- else if (sd->status.pc_class == 4022)
- sd->status.pc_class = sd->view_class = 4015;
- pc_setoption (sd, sd->status.option & ~0x0020);
- clif_displaymessage (fd, "Unmounted Peco.");
- }
-
- return 0;
-}
-
-/*==========================================
- *
- *------------------------------------------
- */
-int atcommand_char_mount_peco (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
-{
- char character[100];
- struct map_session_data *pl_sd;
-
- memset (character, '\0', sizeof (character));
-
- if (!message || !*message || sscanf (message, "%99[^\n]", character) < 1)
- {
- clif_displaymessage (fd,
- "Please, enter a player name (usage: @charmountpeco <char_name>).");
- return -1;
- }
-
- if ((pl_sd = map_nick2sd (character)) != NULL)
- {
- if (pl_sd->disguise > 0)
- { // temporary prevention of crash caused by peco + disguise, will look into a better solution [Valaris]
- clif_displaymessage (fd, "This player cannot mount a Peco while in disguise.");
- return -1;
- }
-
- if (!pc_isriding (pl_sd))
- { // if actually no peco
- if (pl_sd->status.pc_class == 7 || pl_sd->status.pc_class == 14
- || pl_sd->status.pc_class == 4008 || pl_sd->status.pc_class == 4015)
- {
- if (pl_sd->status.pc_class == 7)
- pl_sd->status.pc_class = pl_sd->view_class = 13;
- else if (pl_sd->status.pc_class == 14)
- pl_sd->status.pc_class = pl_sd->view_class = 21;
- else if (pl_sd->status.pc_class == 4008)
- pl_sd->status.pc_class = pl_sd->view_class = 4014;
- else if (pl_sd->status.pc_class == 4015)
- pl_sd->status.pc_class = pl_sd->view_class = 4022;
- pc_setoption (pl_sd, pl_sd->status.option | 0x0020);
- clif_displaymessage (fd, "Now, this player mounts a peco.");
- }
- else
- {
- clif_displaymessage (fd, "This player can not mount a peco with his/her job.");
- return -1;
- }
- }
- else
- {
- if (pl_sd->status.pc_class == 13)
- pl_sd->status.pc_class = pl_sd->view_class = 7;
- else if (pl_sd->status.pc_class == 21)
- pl_sd->status.pc_class = pl_sd->view_class = 14;
- else if (pl_sd->status.pc_class == 4014)
- pl_sd->status.pc_class = pl_sd->view_class = 4008;
- else if (pl_sd->status.pc_class == 4022)
- pl_sd->status.pc_class = pl_sd->view_class = 4015;
- pc_setoption (pl_sd, pl_sd->status.option & ~0x0020);
- clif_displaymessage (fd, "Now, this player has not more peco.");
- }
- }
- else
- {
- clif_displaymessage (fd, "Character not found.");
- return -1;
}
return 0;
@@ -6058,88 +4618,40 @@ int atcommand_char_mount_peco (const int fd, struct map_session_data *sd,
*Spy Commands by Syrus22
*------------------------------------------
*/
-int atcommand_guildspy (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
-{
- char guild_name[100];
- char output[200];
- struct guild *g;
-
- memset (guild_name, '\0', sizeof (guild_name));
- memset (output, '\0', sizeof (output));
-
- if (!message || !*message || sscanf (message, "%99[^\n]", guild_name) < 1)
- {
- clif_displaymessage (fd,
- "Please, enter a guild name/id (usage: @guildspy <guild_name/id>).");
- return -1;
- }
-
- if ((g = guild_searchname (guild_name)) != NULL || // name first to avoid error when name begin with a number
- (g = guild_search (atoi (message))) != NULL)
- {
- if (sd->guildspy == g->guild_id)
- {
- sd->guildspy = 0;
- sprintf (output, "No longer spying on the %s guild.", g->name);
- clif_displaymessage (fd, output);
- }
- else
- {
- sd->guildspy = g->guild_id;
- sprintf (output, "Spying on the %s guild.", g->name);
- clif_displaymessage (fd, output);
- }
- }
- else
- {
- clif_displaymessage (fd, "Incorrect name/ID, or no one from the guild is online.");
- return -1;
- }
-
- return 0;
-}
-
-/*==========================================
- *
- *------------------------------------------
- */
-int atcommand_partyspy (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_partyspy(const int fd, struct map_session_data *sd,
+ const char *, const char *message)
{
char party_name[100];
- char output[200];
struct party *p;
- memset (party_name, '\0', sizeof (party_name));
- memset (output, '\0', sizeof (output));
+ memset(party_name, '\0', sizeof(party_name));
- if (!message || !*message || sscanf (message, "%99[^\n]", party_name) < 1)
+ if (!message || !*message || sscanf(message, "%99[^\n]", party_name) < 1)
{
- clif_displaymessage (fd,
+ clif_displaymessage(fd,
"Please, enter a party name/id (usage: @partyspy <party_name/id>).");
return -1;
}
- if ((p = party_searchname (party_name)) != NULL || // name first to avoid error when name begin with a number
- (p = party_search (atoi (message))) != NULL)
+ if ((p = party_searchname(party_name)) != NULL || // name first to avoid error when name begin with a number
+ (p = party_search(atoi(message))) != NULL)
{
if (sd->partyspy == p->party_id)
{
sd->partyspy = 0;
- sprintf (output, "No longer spying on the %s party.", p->name);
- clif_displaymessage (fd, output);
+ std::string output = STRPRINTF("No longer spying on the %s party.", p->name);
+ clif_displaymessage(fd, output);
}
else
{
sd->partyspy = p->party_id;
- sprintf (output, "Spying on the %s party.", p->name);
- clif_displaymessage (fd, output);
+ std::string output = STRPRINTF("Spying on the %s party.", p->name);
+ clif_displaymessage(fd, output);
}
}
else
{
- clif_displaymessage (fd, "Incorrect name or ID, or no one from the party is online.");
+ clif_displaymessage(fd, "Incorrect name or ID, or no one from the party is online.");
return -1;
}
@@ -6150,28 +4662,28 @@ int atcommand_partyspy (const int fd, struct map_session_data *sd,
*
*------------------------------------------
*/
-int atcommand_enablenpc (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_enablenpc(const int fd, struct map_session_data *,
+ const char *, const char *message)
{
char NPCname[100];
- memset (NPCname, '\0', sizeof (NPCname));
+ memset(NPCname, '\0', sizeof(NPCname));
- if (!message || !*message || sscanf (message, "%99[^\n]", NPCname) < 1)
+ if (!message || !*message || sscanf(message, "%99[^\n]", NPCname) < 1)
{
- clif_displaymessage (fd,
+ clif_displaymessage(fd,
"Please, enter a NPC name (usage: @npcon <NPC_name>).");
return -1;
}
- if (npc_name2id (NPCname) != NULL)
+ if (npc_name2id(NPCname) != NULL)
{
- npc_enable (NPCname, 1);
- clif_displaymessage (fd, "Npc Enabled.");
+ npc_enable(NPCname, 1);
+ clif_displaymessage(fd, "Npc Enabled.");
}
else
{
- clif_displaymessage (fd, "This NPC doesn't exist.");
+ clif_displaymessage(fd, "This NPC doesn't exist.");
return -1;
}
@@ -6182,28 +4694,28 @@ int atcommand_enablenpc (const int fd, struct map_session_data *sd,
*
*------------------------------------------
*/
-int atcommand_disablenpc (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_disablenpc(const int fd, struct map_session_data *,
+ const char *, const char *message)
{
char NPCname[100];
- memset (NPCname, '\0', sizeof (NPCname));
+ memset(NPCname, '\0', sizeof(NPCname));
- if (!message || !*message || sscanf (message, "%99[^\n]", NPCname) < 1)
+ if (!message || !*message || sscanf(message, "%99[^\n]", NPCname) < 1)
{
- clif_displaymessage (fd,
+ clif_displaymessage(fd,
"Please, enter a NPC name (usage: @npcoff <NPC_name>).");
return -1;
}
- if (npc_name2id (NPCname) != NULL)
+ if (npc_name2id(NPCname) != NULL)
{
- npc_enable (NPCname, 0);
- clif_displaymessage (fd, "Npc Disabled.");
+ npc_enable(NPCname, 0);
+ clif_displaymessage(fd, "Npc Disabled.");
}
else
{
- clif_displaymessage (fd, "This NPC doesn't exist.");
+ clif_displaymessage(fd, "This NPC doesn't exist.");
return -1;
}
@@ -6211,128 +4723,21 @@ int atcommand_disablenpc (const int fd, struct map_session_data *sd,
}
/*==========================================
- * time in txt for time command (by [Yor])
- *------------------------------------------
- */
-static
-const char *txt_time (unsigned int duration)
-{
- int days, hours, minutes, seconds;
- char temp[256];
- static char temp1[256];
-
- memset (temp, '\0', sizeof (temp));
- memset (temp1, '\0', sizeof (temp1));
-
- if (duration < 0)
- duration = 0;
-
- days = duration / (60 * 60 * 24);
- duration = duration - (60 * 60 * 24 * days);
- hours = duration / (60 * 60);
- duration = duration - (60 * 60 * hours);
- minutes = duration / 60;
- seconds = duration - (60 * minutes);
-
- if (days < 2)
- sprintf (temp, "%d day", days);
- else
- sprintf (temp, "%d days", days);
- if (hours < 2)
- sprintf (temp1, "%s %d hour", temp, hours);
- else
- sprintf (temp1, "%s %d hours", temp, hours);
- if (minutes < 2)
- sprintf (temp, "%s %d minute", temp1, minutes);
- else
- sprintf (temp, "%s %d minutes", temp1, minutes);
- if (seconds < 2)
- sprintf (temp1, "%s and %d second", temp, seconds);
- else
- sprintf (temp1, "%s and %d seconds", temp, seconds);
-
- return temp1;
-}
-
-/*==========================================
* @time/@date/@server_date/@serverdate/@server_time/@servertime: Display the date/time of the server (by [Yor]
* Calculation management of GM modification (@day/@night GM commands) is done
*------------------------------------------
*/
-int atcommand_servertime (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_servertime(const int fd, struct map_session_data *,
+ const char *, const char *)
{
- struct TimerData *timer_data;
- struct TimerData *timer_data2;
- time_t time_server; // variable for number of seconds (used with time() function)
- struct tm *datetime; // variable for time in structure ->tm_mday, ->tm_sec, ...
- char temp[256];
-
- memset (temp, '\0', sizeof (temp));
+ timestamp_seconds_buffer tsbuf;
+ stamp_time(tsbuf);
+ std::string temp = STRPRINTF("Server time: %s", tsbuf);
+ clif_displaymessage(fd, temp);
- time (&time_server); // get time in seconds since 1/1/1970
- datetime = gmtime (&time_server); // convert seconds in structure
- // like sprintf, but only for date/time (Sunday, November 02 2003 15:12:52)
- strftime (temp, sizeof (temp) - 1, "Server time (normal time): %A, %B %d %Y %X.", datetime);
- clif_displaymessage (fd, temp);
-
- if (battle_config.night_duration == 0 && battle_config.day_duration == 0)
{
- if (night_flag == 0)
- clif_displaymessage (fd, "Game time: The game is in permanent daylight.");
- else
- clif_displaymessage (fd, "Game time: The game is in permanent night.");
- }
- else if (battle_config.night_duration == 0)
- if (night_flag == 1)
- { // we start with night
- timer_data = get_timer (day_timer_tid);
- sprintf (temp, "Game time: The game is actualy in night for %s.", txt_time ((timer_data->tick - gettick ()) / 1000));
- clif_displaymessage (fd, temp);
- clif_displaymessage (fd, "Game time: After, the game will be in permanent daylight.");
- }
- else
- clif_displaymessage (fd, "Game time: The game is in permanent daylight.");
- else if (battle_config.day_duration == 0)
- if (night_flag == 0)
- { // we start with day
- timer_data = get_timer (night_timer_tid);
- sprintf (temp, "Game time: The game is actualy in daylight for %s.", txt_time ((timer_data->tick - gettick ()) / 1000));
- clif_displaymessage (fd, temp);
- clif_displaymessage (fd, "Game time: After, the game will be in permanent night.");
- }
- else
- clif_displaymessage (fd, "Game time: The game is in permanent night.");
- else
- {
- if (night_flag == 0)
- {
- timer_data = get_timer (night_timer_tid);
- timer_data2 = get_timer (day_timer_tid);
- sprintf (temp, "Game time: The game is actualy in daylight for %s.", txt_time ((timer_data->tick - gettick ()) / 1000));
- clif_displaymessage (fd, temp);
- if (timer_data->tick > timer_data2->tick)
- sprintf (temp, "Game time: After, the game will be in night for %s.", txt_time ((timer_data->interval - abs (timer_data->tick - timer_data2->tick)) / 1000));
- else
- sprintf (temp, "Game time: After, the game will be in night for %s.", txt_time (abs (timer_data->tick - timer_data2->tick) / 1000));
- clif_displaymessage (fd, temp);
- sprintf (temp, "Game time: A day cycle has a normal duration of %s.", txt_time (timer_data->interval / 1000));
- clif_displaymessage (fd, temp);
- }
- else
- {
- timer_data = get_timer (day_timer_tid);
- timer_data2 = get_timer (night_timer_tid);
- sprintf (temp, "Game time: The game is actualy in night for %s.", txt_time ((timer_data->tick - gettick ()) / 1000));
- clif_displaymessage (fd, temp);
- if (timer_data->tick > timer_data2->tick)
- sprintf (temp, "Game time: After, the game will be in daylight for %s.", txt_time ((timer_data->interval - abs (timer_data->tick - timer_data2->tick)) / 1000));
- else
- sprintf (temp, "Game time: After, the game will be in daylight for %s.", txt_time (abs (timer_data->tick - timer_data2->tick) / 1000));
- clif_displaymessage (fd, temp);
- sprintf (temp, "Game time: A day cycle has a normal duration of %s.", txt_time (timer_data->interval / 1000));
- clif_displaymessage (fd, temp);
- }
+ if (0 == 0)
+ clif_displaymessage(fd, "Game time: The game is in permanent daylight.");
}
return 0;
@@ -6345,264 +4750,80 @@ int atcommand_servertime (const int fd, struct map_session_data *sd,
* Inspired from a old command created by RoVeRT
*------------------------------------------
*/
-int atcommand_chardelitem (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_chardelitem(const int fd, struct map_session_data *sd,
+ const char *, const char *message)
{
struct map_session_data *pl_sd;
char character[100];
char item_name[100];
- int i, number = 0, item_id, item_position, count;
- char output[200];
+ int i, number = 0, item_id, item_position, count;
struct item_data *item_data;
- memset (character, '\0', sizeof (character));
- memset (item_name, '\0', sizeof (item_name));
- memset (output, '\0', sizeof (output));
+ memset(character, '\0', sizeof(character));
+ memset(item_name, '\0', sizeof(item_name));
if (!message || !*message
- || sscanf (message, "%s %d %99[^\n]", item_name, &number,
+ || sscanf(message, "%s %d %99[^\n]", item_name, &number,
character) < 3 || number < 1)
{
- clif_displaymessage (fd,
+ clif_displaymessage(fd,
"Please, enter an item name/id, a quantity and a player name (usage: @chardelitem <item_name_or_ID> <quantity> <player>).");
return -1;
}
item_id = 0;
- if ((item_data = itemdb_searchname (item_name)) != NULL ||
- (item_data = itemdb_exists (atoi (item_name))) != NULL)
+ if ((item_data = itemdb_searchname(item_name)) != NULL ||
+ (item_data = itemdb_exists(atoi(item_name))) != NULL)
item_id = item_data->nameid;
if (item_id > 500)
{
- if ((pl_sd = map_nick2sd (character)) != NULL)
+ if ((pl_sd = map_nick2sd(character)) != NULL)
{
- if (pc_isGM (sd) >= pc_isGM (pl_sd))
+ if (pc_isGM(sd) >= pc_isGM(pl_sd))
{ // you can kill only lower or same level
- item_position = pc_search_inventory (pl_sd, item_id);
+ item_position = pc_search_inventory(pl_sd, item_id);
if (item_position >= 0)
{
count = 0;
for (i = 0; i < number && item_position >= 0; i++)
{
- pc_delitem (pl_sd, item_position, 1, 0);
+ pc_delitem(pl_sd, item_position, 1, 0);
count++;
- item_position = pc_search_inventory (pl_sd, item_id); // for next loop
+ item_position = pc_search_inventory(pl_sd, item_id); // for next loop
}
- sprintf (output, "%d item(s) removed by a GM.", count);
- clif_displaymessage (pl_sd->fd, output);
+ std::string output = STRPRINTF(
+ "%d item(s) removed by a GM.",
+ count);
+ clif_displaymessage(pl_sd->fd, output);
+
if (number == count)
- sprintf (output, "%d item(s) removed from the player.", count);
+ output = STRPRINTF("%d item(s) removed from the player.", count);
else
- sprintf (output, "%d item(s) removed. Player had only %d on %d items.", count, count, number);
- clif_displaymessage (fd, output);
+ output = STRPRINTF("%d item(s) removed. Player had only %d on %d items.", count, count, number);
+ clif_displaymessage(fd, output);
}
else
{
- clif_displaymessage (fd, "Character does not have the item.");
+ clif_displaymessage(fd, "Character does not have the item.");
return -1;
}
}
else
{
- clif_displaymessage (fd, "Your GM level don't authorise you to do this action on this player.");
- return -1;
- }
- }
- else
- {
- clif_displaymessage (fd, "Character not found.");
- return -1;
- }
- }
- else
- {
- clif_displaymessage (fd, "Invalid item ID or name.");
- return -1;
- }
-
- return 0;
-}
-
-/*==========================================
- * @jail <char_name> by [Yor]
- * Special warp! No check with nowarp and nowarpto flag
- *------------------------------------------
- */
-int atcommand_jail (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
-{
- char character[100];
- struct map_session_data *pl_sd;
- int x, y;
-
- memset (character, '\0', sizeof (character));
-
- if (!message || !*message || sscanf (message, "%99[^\n]", character) < 1)
- {
- clif_displaymessage (fd,
- "Please, enter a player name (usage: @jail <char_name>).");
- return -1;
- }
-
- if ((pl_sd = map_nick2sd (character)) != NULL)
- {
- if (pc_isGM (sd) >= pc_isGM (pl_sd))
- { // you can jail only lower or same GM
- switch (MRAND (2))
- {
- case 0:
- x = 24;
- y = 75;
- break;
- default:
- x = 49;
- y = 75;
- break;
- }
- if (pc_setpos (pl_sd, "sec_pri.gat", x, y, 3) == 0)
- {
- pc_setsavepoint (pl_sd, "sec_pri.gat", x, y); // Save Char Respawn Point in the jail room [Lupus]
- clif_displaymessage (pl_sd->fd, "GM has send you in jails.");
- clif_displaymessage (fd, "Player warped in jails.");
- }
- else
- {
- clif_displaymessage (fd, "Map not found.");
- return -1;
- }
- }
- else
- {
- clif_displaymessage (fd, "Your GM level don't authorise you to do this action on this player.");
- return -1;
- }
- }
- else
- {
- clif_displaymessage (fd, "Character not found.");
- return -1;
- }
-
- return 0;
-}
-
-/*==========================================
- * @unjail/@discharge <char_name> by [Yor]
- * Special warp! No check with nowarp and nowarpto flag
- *------------------------------------------
- */
-int atcommand_unjail (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
-{
- char character[100];
- struct map_session_data *pl_sd;
-
- memset (character, '\0', sizeof (character));
-
- if (!message || !*message || sscanf (message, "%99[^\n]", character) < 1)
- {
- clif_displaymessage (fd,
- "Please, enter a player name (usage: @unjail/@discharge <char_name>).");
- return -1;
- }
-
- if ((pl_sd = map_nick2sd (character)) != NULL)
- {
- if (pc_isGM (sd) >= pc_isGM (pl_sd))
- { // you can jail only lower or same GM
- if (pl_sd->bl.m != map_mapname2mapid ("sec_pri.gat"))
- {
- clif_displaymessage (fd, "This player is not in jails.");
- return -1;
- }
- else if (pc_setpos (pl_sd, "prontera.gat", 156, 191, 3) == 0)
- {
- pc_setsavepoint (pl_sd, "prontera.gat", 156, 191); // Save char respawn point in Prontera
- clif_displaymessage (pl_sd->fd, "GM has discharge you.");
- clif_displaymessage (fd, "Player warped to Prontera.");
- }
- else
- {
- clif_displaymessage (fd, "Map not found.");
+ clif_displaymessage(fd, "Your GM level don't authorise you to do this action on this player.");
return -1;
}
}
else
{
- clif_displaymessage (fd, "Your GM level don't authorise you to do this action on this player.");
- return -1;
- }
- }
- else
- {
- clif_displaymessage (fd, "Character not found.");
- return -1;
- }
-
- return 0;
-}
-
-/*==========================================
- * @disguise <mob_id> by [Valaris] (simplified by [Yor])
- *------------------------------------------
- */
-int atcommand_disguise (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
-{
- int mob_id;
-
- if (!message || !*message)
- {
- clif_displaymessage (fd,
- "Please, enter a Monster/NPC name/id (usage: @disguise <monster_name_or_monster_ID>).");
- return -1;
- }
-
- if ((mob_id = mobdb_searchname (message)) == 0) // check name first (to avoid possible name begining by a number)
- mob_id = atoi (message);
-
- if ((mob_id >= 46 && mob_id <= 125) || (mob_id >= 700 && mob_id <= 718) || // NPC
- (mob_id >= 721 && mob_id <= 755) || (mob_id >= 757 && mob_id <= 811) || // NPC
- (mob_id >= 813 && mob_id <= 834) || // NPC
- (mob_id > 1000 && mob_id < 1521))
- { // monsters
- if (pc_isriding (sd))
- { // temporary prevention of crash caused by peco + disguise, will look into a better solution [Valaris]
- clif_displaymessage (fd, "Cannot wear disguise while riding a Peco.");
+ clif_displaymessage(fd, "Character not found.");
return -1;
}
- sd->disguiseflag = 1; // set to override items with disguise script [Valaris]
- sd->disguise = mob_id;
- pc_setpos (sd, sd->mapname, sd->bl.x, sd->bl.y, 3);
- clif_displaymessage (fd, "Disguise applied.");
- }
- else
- {
- clif_displaymessage (fd, "Monster/NPC name/id hasn't been found.");
- return -1;
- }
-
- return 0;
-}
-
-/*==========================================
- * @undisguise by [Yor]
- *------------------------------------------
- */
-int atcommand_undisguise (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
-{
- if (sd->disguise)
- {
- clif_clearchar (&sd->bl, 9);
- sd->disguise = 0;
- pc_setpos (sd, sd->mapname, sd->bl.x, sd->bl.y, 3);
- clif_displaymessage (fd, "Undisguise applied.");
}
else
{
- clif_displaymessage (fd, "You're not disguised.");
+ clif_displaymessage(fd, "Invalid item ID or name.");
return -1;
}
@@ -6613,22 +4834,18 @@ int atcommand_undisguise (const int fd, struct map_session_data *sd,
* @broadcast by [Valaris]
*------------------------------------------
*/
-int atcommand_broadcast (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_broadcast(const int fd, struct map_session_data *sd,
+ const char *, const char *message)
{
- char output[200];
-
- memset (output, '\0', sizeof (output));
-
if (!message || !*message)
{
- clif_displaymessage (fd,
+ clif_displaymessage(fd,
"Please, enter a message (usage: @broadcast <message>).");
return -1;
}
- snprintf (output, 199, "%s : %s", sd->status.name, message);
- intif_GMmessage (output, strlen (output) + 1, 0);
+ std::string output = STRPRINTF("%s : %s", sd->status.name, message);
+ intif_GMmessage(output, 0);
return 0;
}
@@ -6637,23 +4854,19 @@ int atcommand_broadcast (const int fd, struct map_session_data *sd,
* @localbroadcast by [Valaris]
*------------------------------------------
*/
-int atcommand_localbroadcast (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_localbroadcast(const int fd, struct map_session_data *sd,
+ const char *, const char *message)
{
- char output[200];
-
- memset (output, '\0', sizeof (output));
-
if (!message || !*message)
{
- clif_displaymessage (fd,
+ clif_displaymessage(fd,
"Please, enter a message (usage: @localbroadcast <message>).");
return -1;
}
- snprintf (output, 199, "%s : %s", sd->status.name, message);
+ std::string output = STRPRINTF("%s : %s", sd->status.name, message);
- clif_GMmessage (&sd->bl, output, strlen (output) + 1, 1); // 1: ALL_SAMEMAP
+ clif_GMmessage(&sd->bl, output, 1); // 1: ALL_SAMEMAP
return 0;
}
@@ -6662,41 +4875,42 @@ int atcommand_localbroadcast (const int fd, struct map_session_data *sd,
* @ignorelist by [Yor]
*------------------------------------------
*/
-int atcommand_ignorelist (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_ignorelist(const int fd, struct map_session_data *sd,
+ const char *, const char *)
{
- char output[200];
- int count;
- int i;
-
- memset (output, '\0', sizeof (output));
+ int count;
+ int i;
count = 0;
- for (i = 0; i < (int) (sizeof (sd->ignore) / sizeof (sd->ignore[0])); i++)
+ for (i = 0; i < (int)(sizeof(sd->ignore) / sizeof(sd->ignore[0])); i++)
if (sd->ignore[i].name[0])
count++;
if (sd->ignoreAll == 0)
if (count == 0)
- clif_displaymessage (fd, "You accept any wisp (no wisper is refused).");
+ clif_displaymessage(fd, "You accept any wisp (no wisper is refused).");
else
{
- sprintf (output, "You accept any wisp, except thoses from %d player(s):", count);
- clif_displaymessage (fd, output);
+ std::string output = STRPRINTF(
+ "You accept any wisp, except thoses from %d player (s):",
+ count);
+ clif_displaymessage(fd, output);
}
else if (count == 0)
- clif_displaymessage (fd, "You refuse all wisps (no specifical wisper is refused).");
+ clif_displaymessage(fd, "You refuse all wisps (no specifical wisper is refused).");
else
{
- sprintf (output, "You refuse all wisps, AND refuse wisps from %d player(s):", count);
- clif_displaymessage (fd, output);
+ std::string output = STRPRINTF(
+ "You refuse all wisps, AND refuse wisps from %d player (s):",
+ count);
+ clif_displaymessage(fd, output);
}
if (count > 0)
- for (i = 0; i < (int) (sizeof (sd->ignore) / sizeof (sd->ignore[0]));
+ for (i = 0; i < (int)(sizeof(sd->ignore) / sizeof(sd->ignore[0]));
i++)
if (sd->ignore[i].name[0])
- clif_displaymessage (fd, sd->ignore[i].name);
+ clif_displaymessage(fd, sd->ignore[i].name);
return 0;
}
@@ -6705,30 +4919,28 @@ int atcommand_ignorelist (const int fd, struct map_session_data *sd,
* @charignorelist <player_name> by [Yor]
*------------------------------------------
*/
-int atcommand_charignorelist (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_charignorelist(const int fd, struct map_session_data *,
+ const char *, const char *message)
{
char character[100];
struct map_session_data *pl_sd;
- char output[200];
- int count;
- int i;
+ int count;
+ int i;
- memset (character, '\0', sizeof (character));
- memset (output, '\0', sizeof (output));
+ memset(character, '\0', sizeof(character));
- if (!message || !*message || sscanf (message, "%99[^\n]", character) < 1)
+ if (!message || !*message || sscanf(message, "%99[^\n]", character) < 1)
{
- clif_displaymessage (fd,
- "Please, enter a player name (usage: @charignorelist <char name>).");
+ clif_displaymessage(fd,
+ "Please, enter a player name (usage: @charignorelist <char name>).");
return -1;
}
- if ((pl_sd = map_nick2sd (character)) != NULL)
+ if ((pl_sd = map_nick2sd(character)) != NULL)
{
count = 0;
for (i = 0;
- i < (int) (sizeof (pl_sd->ignore) / sizeof (pl_sd->ignore[0]));
+ i < (int)(sizeof(pl_sd->ignore) / sizeof(pl_sd->ignore[0]));
i++)
if (pl_sd->ignore[i].name[0])
count++;
@@ -6736,37 +4948,45 @@ int atcommand_charignorelist (const int fd, struct map_session_data *sd,
if (pl_sd->ignoreAll == 0)
if (count == 0)
{
- sprintf (output, "'%s' accept any wisp (no wisper is refused).", pl_sd->status.name);
- clif_displaymessage (fd, output);
+ std::string output = STRPRINTF(
+ "'%s' accept any wisp (no wisper is refused).",
+ pl_sd->status.name);
+ clif_displaymessage(fd, output);
}
else
{
- sprintf (output, "'%s' accept any wisp, except thoses from %d player(s):", pl_sd->status.name, count);
- clif_displaymessage (fd, output);
+ std::string output = STRPRINTF(
+ "'%s' accept any wisp, except thoses from %d player(s):",
+ pl_sd->status.name, count);
+ clif_displaymessage(fd, output);
}
else if (count == 0)
{
- sprintf (output, "'%s' refuse all wisps (no specifical wisper is refused).", pl_sd->status.name);
- clif_displaymessage (fd, output);
+ std::string output = STRPRINTF(
+ "'%s' refuse all wisps (no specifical wisper is refused).",
+ pl_sd->status.name);
+ clif_displaymessage(fd, output);
}
else
{
- sprintf (output, "'%s' refuse all wisps, AND refuse wisps from %d player(s):", pl_sd->status.name, count);
- clif_displaymessage (fd, output);
+ std::string output = STRPRINTF(
+ "'%s' refuse all wisps, AND refuse wisps from %d player(s):",
+ pl_sd->status.name, count);
+ clif_displaymessage(fd, output);
}
if (count > 0)
for (i = 0;
i <
- (int) (sizeof (pl_sd->ignore) / sizeof (pl_sd->ignore[0]));
+ (int)(sizeof(pl_sd->ignore) / sizeof(pl_sd->ignore[0]));
i++)
if (pl_sd->ignore[i].name[0])
- clif_displaymessage (fd, pl_sd->ignore[i].name);
+ clif_displaymessage(fd, pl_sd->ignore[i].name);
}
else
{
- clif_displaymessage (fd, "Character not found.");
+ clif_displaymessage(fd, "Character not found.");
return -1;
}
@@ -6777,55 +4997,57 @@ int atcommand_charignorelist (const int fd, struct map_session_data *sd,
* @inall <player_name> by [Yor]
*------------------------------------------
*/
-int atcommand_inall (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_inall(const int fd, struct map_session_data *sd,
+ const char *, const char *message)
{
char character[100];
- char output[200];
struct map_session_data *pl_sd;
- memset (character, '\0', sizeof (character));
- memset (output, '\0', sizeof (output));
+ memset(character, '\0', sizeof(character));
- if (!message || !*message || sscanf (message, "%99[^\n]", character) < 1)
+ if (!message || !*message || sscanf(message, "%99[^\n]", character) < 1)
{
- clif_displaymessage (fd,
+ clif_displaymessage(fd,
"Please, enter a player name (usage: @inall <char name>).");
return -1;
}
- if ((pl_sd = map_nick2sd (character)) != NULL)
+ if ((pl_sd = map_nick2sd(character)) != NULL)
{
- if (pc_isGM (sd) >= pc_isGM (pl_sd))
+ if (pc_isGM(sd) >= pc_isGM(pl_sd))
{ // you can change wisp option only to lower or same level
if (pl_sd->ignoreAll == 0)
{
- sprintf (output, "'%s' already accepts all wispers.", pl_sd->status.name);
- clif_displaymessage (fd, output);
+ std::string output = STRPRINTF(
+ "'%s' already accepts all wispers.",
+ pl_sd->status.name);
+ clif_displaymessage(fd, output);
return -1;
}
else
{
pl_sd->ignoreAll = 0;
- sprintf (output, "'%s' now accepts all wispers.", pl_sd->status.name);
- clif_displaymessage (fd, output);
+ std::string output = STRPRINTF(
+ "'%s' now accepts all wispers.",
+ pl_sd->status.name);
+ clif_displaymessage(fd, output);
// message to player
- clif_displaymessage (pl_sd->fd, "A GM has authorised all wispers for you.");
- WFIFOW (pl_sd->fd, 0) = 0x0d2; // R 00d2 <type>.B <fail>.B: type: 0: deny, 1: allow, fail: 0: success, 1: fail
- WFIFOB (pl_sd->fd, 2) = 1;
- WFIFOB (pl_sd->fd, 3) = 0; // success
- WFIFOSET (pl_sd->fd, 4); // packet_len_table[0x0d2]
+ clif_displaymessage(pl_sd->fd, "A GM has authorised all wispers for you.");
+ WFIFOW(pl_sd->fd, 0) = 0x0d2; // R 00d2 <type>.B <fail>.B: type: 0: deny, 1: allow, fail: 0: success, 1: fail
+ WFIFOB(pl_sd->fd, 2) = 1;
+ WFIFOB(pl_sd->fd, 3) = 0; // success
+ WFIFOSET(pl_sd->fd, 4); // packet_len_table[0x0d2]
}
}
else
{
- clif_displaymessage (fd, "Your GM level don't authorise you to do this action on this player.");
+ clif_displaymessage(fd, "Your GM level don't authorise you to do this action on this player.");
return -1;
}
}
else
{
- clif_displaymessage (fd, "Character not found.");
+ clif_displaymessage(fd, "Character not found.");
return -1;
}
@@ -6836,174 +5058,57 @@ int atcommand_inall (const int fd, struct map_session_data *sd,
* @exall <player_name> by [Yor]
*------------------------------------------
*/
-int atcommand_exall (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_exall(const int fd, struct map_session_data *sd,
+ const char *, const char *message)
{
char character[100];
- char output[200];
struct map_session_data *pl_sd;
- memset (character, '\0', sizeof (character));
- memset (output, '\0', sizeof (output));
+ memset(character, '\0', sizeof(character));
- if (!message || !*message || sscanf (message, "%99[^\n]", character) < 1)
+ if (!message || !*message || sscanf(message, "%99[^\n]", character) < 1)
{
- clif_displaymessage (fd,
+ clif_displaymessage(fd,
"Please, enter a player name (usage: @exall <char name>).");
return -1;
}
- if ((pl_sd = map_nick2sd (character)) != NULL)
+ if ((pl_sd = map_nick2sd(character)) != NULL)
{
- if (pc_isGM (sd) >= pc_isGM (pl_sd))
+ if (pc_isGM(sd) >= pc_isGM(pl_sd))
{ // you can change wisp option only to lower or same level
if (pl_sd->ignoreAll == 1)
{
- sprintf (output, "'%s' already blocks all wispers.", pl_sd->status.name);
- clif_displaymessage (fd, output);
+ std::string output = STRPRINTF(
+ "'%s' already blocks all wispers.",
+ pl_sd->status.name);
+ clif_displaymessage(fd, output);
return -1;
}
else
{
pl_sd->ignoreAll = 1;
- sprintf (output, "'%s' blocks now all wispers.", pl_sd->status.name);
- clif_displaymessage (fd, output);
+ std::string output = STRPRINTF(
+ "'%s' blocks now all wispers.",
+ pl_sd->status.name);
+ clif_displaymessage(fd, output);
// message to player
- clif_displaymessage (pl_sd->fd, "A GM has blocked all wispers for you.");
- WFIFOW (pl_sd->fd, 0) = 0x0d2; // R 00d2 <type>.B <fail>.B: type: 0: deny, 1: allow, fail: 0: success, 1: fail
- WFIFOB (pl_sd->fd, 2) = 0;
- WFIFOB (pl_sd->fd, 3) = 0; // success
- WFIFOSET (pl_sd->fd, 4); // packet_len_table[0x0d2]
- }
- }
- else
- {
- clif_displaymessage (fd, "Your GM level don't authorise you to do this action on this player.");
- return -1;
- }
- }
- else
- {
- clif_displaymessage (fd, "Character not found.");
- return -1;
- }
-
- return 0;
-}
-
-/*==========================================
- * @chardisguise <mob_id> <character> by Kalaspuff (based off Valaris' and Yor's work)
- *------------------------------------------
- */
-int atcommand_chardisguise (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
-{
- int mob_id;
- char character[100];
- char mob_name[100];
- struct map_session_data *pl_sd;
-
- memset (character, '\0', sizeof (character));
- memset (mob_name, '\0', sizeof (mob_name));
-
- if (!message || !*message
- || sscanf (message, "%s %99[^\n]", mob_name, character) < 2)
- {
- clif_displaymessage (fd,
- "Please, enter a Monster/NPC name/id and a player name (usage: @chardisguise <monster_name_or_monster_ID> <char name>).");
- return -1;
- }
-
- if ((mob_id = mobdb_searchname (mob_name)) == 0) // check name first (to avoid possible name begining by a number)
- mob_id = atoi (mob_name);
-
- if ((pl_sd = map_nick2sd (character)) != NULL)
- {
- if (pc_isGM (sd) >= pc_isGM (pl_sd))
- { // you can disguise only lower or same level
- if ((mob_id >= 46 && mob_id <= 125) || (mob_id >= 700 && mob_id <= 718) || // NPC
- (mob_id >= 721 && mob_id <= 755) || (mob_id >= 757 && mob_id <= 811) || // NPC
- (mob_id >= 813 && mob_id <= 834) || // NPC
- (mob_id > 1000 && mob_id < 1521))
- { // monsters
- if (pc_isriding (pl_sd))
- { // temporary prevention of crash caused by peco + disguise, will look into a better solution [Valaris]
- clif_displaymessage (fd, "Character cannot wear disguise while riding a Peco.");
- return -1;
- }
- pl_sd->disguiseflag = 1; // set to override items with disguise script [Valaris]
- pl_sd->disguise = mob_id;
- pc_setpos (pl_sd, pl_sd->mapname, pl_sd->bl.x, pl_sd->bl.y,
- 3);
- clif_displaymessage (fd, "Character's disguise applied.");
- }
- else
- {
- clif_displaymessage (fd, "Monster/NPC name/id hasn't been found.");
- return -1;
- }
- }
- else
- {
- clif_displaymessage (fd, "Your GM level don't authorise you to do this action on this player.");
- return -1;
- }
- }
- else
- {
- clif_displaymessage (fd, "Character not found.");
- return -1;
- }
-
- return 0;
-}
-
-/*==========================================
- * @charundisguise <character> by Kalaspuff (based off Yor's work)
- *------------------------------------------
- */
-int atcommand_charundisguise (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
-{
- char character[100];
- struct map_session_data *pl_sd;
-
- memset (character, '\0', sizeof (character));
-
- if (!message || !*message || sscanf (message, "%99[^\n]", character) < 1)
- {
- clif_displaymessage (fd,
- "Please, enter a player name (usage: @charundisguise <char name>).");
- return -1;
- }
-
- if ((pl_sd = map_nick2sd (character)) != NULL)
- {
- if (pc_isGM (sd) >= pc_isGM (pl_sd))
- { // you can undisguise only lower or same level
- if (pl_sd->disguise)
- {
- clif_clearchar (&pl_sd->bl, 9);
- pl_sd->disguise = 0;
- pc_setpos (pl_sd, pl_sd->mapname, pl_sd->bl.x, pl_sd->bl.y,
- 3);
- clif_displaymessage (fd, "Character's undisguise applied.");
- }
- else
- {
- clif_displaymessage (fd, "Character is not disguised.");
- return -1;
+ clif_displaymessage(pl_sd->fd, "A GM has blocked all wispers for you.");
+ WFIFOW(pl_sd->fd, 0) = 0x0d2; // R 00d2 <type>.B <fail>.B: type: 0: deny, 1: allow, fail: 0: success, 1: fail
+ WFIFOB(pl_sd->fd, 2) = 0;
+ WFIFOB(pl_sd->fd, 3) = 0; // success
+ WFIFOSET(pl_sd->fd, 4); // packet_len_table[0x0d2]
}
}
else
{
- clif_displaymessage (fd, "Your GM level don't authorise you to do this action on this player.");
+ clif_displaymessage(fd, "Your GM level don't authorise you to do this action on this player.");
return -1;
}
}
else
{
- clif_displaymessage (fd, "Character not found.");
+ clif_displaymessage(fd, "Character not found.");
return -1;
}
@@ -7014,47 +5119,47 @@ int atcommand_charundisguise (const int fd, struct map_session_data *sd,
* @email <actual@email> <new@email> by [Yor]
*------------------------------------------
*/
-int atcommand_email (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_email(const int fd, struct map_session_data *sd,
+ const char *, const char *message)
{
char actual_email[100];
char new_email[100];
- memset (actual_email, '\0', sizeof (actual_email));
- memset (new_email, '\0', sizeof (new_email));
+ memset(actual_email, '\0', sizeof(actual_email));
+ memset(new_email, '\0', sizeof(new_email));
if (!message || !*message
- || sscanf (message, "%99s %99s", actual_email, new_email) < 2)
+ || sscanf(message, "%99s %99s", actual_email, new_email) < 2)
{
- clif_displaymessage (fd,
+ clif_displaymessage(fd,
"Please enter 2 emails (usage: @email <actual@email> <new@email>).");
return -1;
}
- if (e_mail_check (actual_email) == 0)
+ if (e_mail_check(actual_email) == 0)
{
- clif_displaymessage (fd, "Invalid actual email. If you have default e-mail, type a@a.com."); // Invalid actual email. If you have default e-mail, give a@a.com.
+ clif_displaymessage(fd, "Invalid actual email. If you have default e-mail, type a@a.com."); // Invalid actual email. If you have default e-mail, give a@a.com.
return -1;
}
- else if (e_mail_check (new_email) == 0)
+ else if (e_mail_check(new_email) == 0)
{
- clif_displaymessage (fd, "Invalid new email. Please enter a real e-mail.");
+ clif_displaymessage(fd, "Invalid new email. Please enter a real e-mail.");
return -1;
}
- else if (strcasecmp (new_email, "a@a.com") == 0)
+ else if (strcasecmp(new_email, "a@a.com") == 0)
{
- clif_displaymessage (fd, "New email must be a real e-mail.");
+ clif_displaymessage(fd, "New email must be a real e-mail.");
return -1;
}
- else if (strcasecmp (actual_email, new_email) == 0)
+ else if (strcasecmp(actual_email, new_email) == 0)
{
- clif_displaymessage (fd, "New email must be different of the actual e-mail.");
+ clif_displaymessage(fd, "New email must be different of the actual e-mail.");
return -1;
}
else
{
- chrif_changeemail (sd->status.account_id, actual_email, new_email);
- clif_displaymessage (fd, "Information sended to login-server via char-server.");
+ chrif_changeemail(sd->status.account_id, actual_email, new_email);
+ clif_displaymessage(fd, "Information sended to login-server via char-server.");
}
return 0;
@@ -7064,22 +5169,22 @@ int atcommand_email (const int fd, struct map_session_data *sd,
*@effect
*------------------------------------------
*/
-int atcommand_effect (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_effect(const int fd, struct map_session_data *sd,
+ const char *, const char *message)
{
struct map_session_data *pl_sd;
- int type = 0, flag = 0, i;
+ int type = 0, flag = 0, i;
- if (!message || !*message || sscanf (message, "%d %d", &type, &flag) < 2)
+ if (!message || !*message || sscanf(message, "%d %d", &type, &flag) < 2)
{
- clif_displaymessage (fd,
+ clif_displaymessage(fd,
"Please, enter at least a option (usage: @effect <type+>).");
return -1;
}
if (flag <= 0)
{
- clif_specialeffect (&sd->bl, type, flag);
- clif_displaymessage (fd, "Your Effect Has Changed."); // Your effect has changed.
+ clif_specialeffect(&sd->bl, type, flag);
+ clif_displaymessage(fd, "Your Effect Has Changed."); // Your effect has changed.
}
else
{
@@ -7088,8 +5193,8 @@ int atcommand_effect (const int fd, struct map_session_data *sd,
if (session[i] && (pl_sd = (struct map_session_data *)session[i]->session_data)
&& pl_sd->state.auth)
{
- clif_specialeffect (&pl_sd->bl, type, flag);
- clif_displaymessage (pl_sd->fd, "Your Effect Has Changed."); // Your effect has changed.
+ clif_specialeffect(&pl_sd->bl, type, flag);
+ clif_displaymessage(pl_sd->fd, "Your Effect Has Changed."); // Your effect has changed.
}
}
}
@@ -7101,30 +5206,27 @@ int atcommand_effect (const int fd, struct map_session_data *sd,
* @charitemlist <character>: Displays the list of a player's items.
*------------------------------------------
*/
-int
-atcommand_character_item_list (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_character_item_list(const int fd, struct map_session_data *sd,
+ const char *, const char *message)
{
struct map_session_data *pl_sd;
struct item_data *item_data, *item_temp;
- int i, j, equip, count, counter, counter2;
- char character[100], output[200], equipstr[100], outputtmp[200];
+ int i, j, count, counter, counter2;
+ char character[100], equipstr[100];
- memset (character, '\0', sizeof (character));
- memset (output, '\0', sizeof (output));
- memset (equipstr, '\0', sizeof (equipstr));
- memset (outputtmp, '\0', sizeof (outputtmp));
+ memset(character, '\0', sizeof(character));
+ memset(equipstr, '\0', sizeof(equipstr));
- if (!message || !*message || sscanf (message, "%99[^\n]", character) < 1)
+ if (!message || !*message || sscanf(message, "%99[^\n]", character) < 1)
{
- clif_displaymessage (fd,
+ clif_displaymessage(fd,
"Please, enter a player name (usage: @charitemlist <char name>).");
return -1;
}
- if ((pl_sd = map_nick2sd (character)) != NULL)
+ if ((pl_sd = map_nick2sd(character)) != NULL)
{
- if (pc_isGM (sd) >= pc_isGM (pl_sd))
+ if (pc_isGM(sd) >= pc_isGM(pl_sd))
{ // you can look items only lower or same level
counter = 0;
count = 0;
@@ -7132,55 +5234,59 @@ atcommand_character_item_list (const int fd, struct map_session_data *sd,
{
if (pl_sd->status.inventory[i].nameid > 0
&& (item_data =
- itemdb_search (pl_sd->status.inventory[i].nameid)) !=
+ itemdb_search(pl_sd->status.inventory[i].nameid)) !=
NULL)
{
counter = counter + pl_sd->status.inventory[i].amount;
count++;
if (count == 1)
{
- sprintf (output, "------ Items list of '%s' ------",
- pl_sd->status.name);
- clif_displaymessage (fd, output);
+ std::string output = STRPRINTF(
+ "------ Items list of '%s' ------",
+ pl_sd->status.name);
+ clif_displaymessage(fd, output);
}
- if ((equip = pl_sd->status.inventory[i].equip))
+ EPOS equip;
+ if (bool(equip = pl_sd->status.inventory[i].equip))
{
- strcpy (equipstr, "| equiped: ");
- if (equip & 4)
- strcat (equipstr, "robe/gargment, ");
- if (equip & 8)
- strcat (equipstr, "left accessory, ");
- if (equip & 16)
- strcat (equipstr, "body/armor, ");
- if ((equip & 34) == 2)
- strcat (equipstr, "right hand, ");
- if ((equip & 34) == 32)
- strcat (equipstr, "left hand, ");
- if ((equip & 34) == 34)
- strcat (equipstr, "both hands, ");
- if (equip & 64)
- strcat (equipstr, "feet, ");
- if (equip & 128)
- strcat (equipstr, "right accessory, ");
- if ((equip & 769) == 1)
- strcat (equipstr, "lower head, ");
- if ((equip & 769) == 256)
- strcat (equipstr, "top head, ");
- if ((equip & 769) == 257)
- strcat (equipstr, "lower/top head, ");
- if ((equip & 769) == 512)
- strcat (equipstr, "mid head, ");
- if ((equip & 769) == 512)
- strcat (equipstr, "lower/mid head, ");
- if ((equip & 769) == 769)
- strcat (equipstr, "lower/mid/top head, ");
+ strcpy(equipstr, "| equiped: ");
+ if (bool(equip & EPOS::GLOVES))
+ strcat(equipstr, "robe/gargment, ");
+ if (bool(equip & EPOS::CAPE))
+ strcat(equipstr, "left accessory, ");
+ if (bool(equip & EPOS::MISC1))
+ strcat(equipstr, "body/armor, ");
+ if ((equip & (EPOS::WEAPON | EPOS::SHIELD)) == EPOS::WEAPON)
+ strcat(equipstr, "right hand, ");
+ if ((equip & (EPOS::WEAPON | EPOS::SHIELD)) == EPOS::SHIELD)
+ strcat(equipstr, "left hand, ");
+ if ((equip & (EPOS::WEAPON | EPOS::SHIELD)) == (EPOS::WEAPON | EPOS::SHIELD))
+ strcat(equipstr, "both hands, ");
+ if (bool(equip & EPOS::SHOES))
+ strcat(equipstr, "feet, ");
+ if (bool(equip & EPOS::MISC2))
+ strcat(equipstr, "right accessory, ");
+ if ((equip & (EPOS::TORSO | EPOS::HAT | EPOS::LEGS)) == EPOS::LEGS)
+ strcat(equipstr, "lower head, ");
+ if ((equip & (EPOS::TORSO | EPOS::HAT | EPOS::LEGS)) == EPOS::HAT)
+ strcat(equipstr, "top head, ");
+ if ((equip & (EPOS::TORSO | EPOS::HAT | EPOS::LEGS)) == (EPOS::HAT | EPOS::LEGS))
+ strcat(equipstr, "lower/top head, ");
+ if ((equip & (EPOS::TORSO | EPOS::HAT | EPOS::LEGS)) == EPOS::TORSO)
+ strcat(equipstr, "mid head, ");
+ if ((equip & (EPOS::TORSO | EPOS::HAT | EPOS::LEGS)) == (EPOS::TORSO | EPOS::LEGS))
+ strcat(equipstr, "lower/mid head, ");
+ if ((equip & (EPOS::TORSO | EPOS::HAT | EPOS::LEGS)) == (EPOS::TORSO | EPOS::HAT | EPOS::LEGS))
+ strcat(equipstr, "lower/mid/top head, ");
// remove final ', '
- equipstr[strlen (equipstr) - 2] = '\0';
+ equipstr[strlen(equipstr) - 2] = '\0';
}
else
- memset (equipstr, '\0', sizeof (equipstr));
+ memset(equipstr, '\0', sizeof(equipstr));
+
+ std::string output;
if (sd->status.inventory[i].refine)
- sprintf (output, "%d %s %+d (%s %+d, id: %d) %s",
+ output = STRPRINTF("%d %s %+d (%s %+d, id: %d) %s",
pl_sd->status.inventory[i].amount,
item_data->name,
pl_sd->status.inventory[i].refine,
@@ -7188,61 +5294,70 @@ atcommand_character_item_list (const int fd, struct map_session_data *sd,
pl_sd->status.inventory[i].refine,
pl_sd->status.inventory[i].nameid, equipstr);
else
- sprintf (output, "%d %s (%s, id: %d) %s",
+ output = STRPRINTF("%d %s (%s, id: %d) %s",
pl_sd->status.inventory[i].amount,
item_data->name, item_data->jname,
pl_sd->status.inventory[i].nameid, equipstr);
- clif_displaymessage (fd, output);
- memset (output, '\0', sizeof (output));
+ clif_displaymessage(fd, output);
+
+ output.clear();
counter2 = 0;
for (j = 0; j < item_data->slot; j++)
{
if (pl_sd->status.inventory[i].card[j])
{
if ((item_temp =
- itemdb_search (pl_sd->status.
+ itemdb_search(pl_sd->status.
inventory[i].card[j])) !=
NULL)
{
- if (output[0] == '\0')
- sprintf (outputtmp,
- " -> (card(s): #%d %s (%s), ",
- ++counter2, item_temp->name,
- item_temp->jname);
+ if (output.empty())
+ output = STRPRINTF(
+ " -> (card(s): #%d %s (%s), ",
+ ++counter2,
+ item_temp->name,
+ item_temp->jname);
else
- sprintf (outputtmp, "#%d %s (%s), ",
- ++counter2, item_temp->name,
- item_temp->jname);
- strcat (output, outputtmp);
+ output += STRPRINTF(
+ "#%d %s (%s), ",
+ ++counter2,
+ item_temp->name,
+ item_temp->jname);
}
}
}
- if (output[0] != '\0')
+ if (!output.empty())
{
- output[strlen (output) - 2] = ')';
- output[strlen (output) - 1] = '\0';
- clif_displaymessage (fd, output);
+ // replace trailing ", "
+#ifdef WORKAROUND_GCC46_LIBRARY
+ output.resize(output.size() - 1);
+#else
+ output.pop_back();
+#endif
+ output.back() = ')';
+ clif_displaymessage(fd, output);
}
}
}
if (count == 0)
- clif_displaymessage (fd, "No item found on this player.");
+ clif_displaymessage(fd, "No item found on this player.");
else
{
- sprintf (output, "%d item(s) found in %d kind(s) of items.",
- counter, count);
- clif_displaymessage (fd, output);
+ std::string output = STRPRINTF(
+ "%d item(s) found in %d kind(s) of items.",
+ counter, count);
+ clif_displaymessage(fd, output);
}
}
else
{
- clif_displaymessage (fd, "Your GM level don't authorise you to do this action on this player.");
+ clif_displaymessage(fd, "Your GM level don't authorise you to do this action on this player.");
return -1;
}
}
else
{
- clif_displaymessage (fd, "Character not found.");
+ clif_displaymessage(fd, "Character not found.");
return -1;
}
@@ -7253,32 +5368,29 @@ atcommand_character_item_list (const int fd, struct map_session_data *sd,
* @charstoragelist <character>: Displays the items list of a player's storage.
*------------------------------------------
*/
-int
-atcommand_character_storage_list (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_character_storage_list(const int fd, struct map_session_data *sd,
+ const char *, const char *message)
{
struct storage *stor;
struct map_session_data *pl_sd;
struct item_data *item_data, *item_temp;
- int i, j, count, counter, counter2;
- char character[100], output[200], outputtmp[200];
+ int i, j, count, counter, counter2;
+ char character[100];
- memset (character, '\0', sizeof (character));
- memset (output, '\0', sizeof (output));
- memset (outputtmp, '\0', sizeof (outputtmp));
+ memset(character, '\0', sizeof(character));
- if (!message || !*message || sscanf (message, "%99[^\n]", character) < 1)
+ if (!message || !*message || sscanf(message, "%99[^\n]", character) < 1)
{
- clif_displaymessage (fd,
+ clif_displaymessage(fd,
"Please, enter a player name (usage: @charitemlist <char name>).");
return -1;
}
- if ((pl_sd = map_nick2sd (character)) != NULL)
+ if ((pl_sd = map_nick2sd(character)) != NULL)
{
- if (pc_isGM (sd) >= pc_isGM (pl_sd))
+ if (pc_isGM(sd) >= pc_isGM(pl_sd))
{ // you can look items only lower or same level
- if ((stor = account2storage2 (pl_sd->status.account_id)) != NULL)
+ if ((stor = account2storage2(pl_sd->status.account_id)) != NULL)
{
counter = 0;
count = 0;
@@ -7286,19 +5398,20 @@ atcommand_character_storage_list (const int fd, struct map_session_data *sd,
{
if (stor->storage_[i].nameid > 0
&& (item_data =
- itemdb_search (stor->storage_[i].nameid)) != NULL)
+ itemdb_search(stor->storage_[i].nameid)) != NULL)
{
counter = counter + stor->storage_[i].amount;
count++;
if (count == 1)
{
- sprintf (output,
+ std::string output = STRPRINTF(
"------ Storage items list of '%s' ------",
pl_sd->status.name);
- clif_displaymessage (fd, output);
+ clif_displaymessage(fd, output);
}
+ std::string output;
if (stor->storage_[i].refine)
- sprintf (output, "%d %s %+d (%s %+d, id: %d)",
+ output = STRPRINTF("%d %s %+d (%s %+d, id: %d)",
stor->storage_[i].amount,
item_data->name,
stor->storage_[i].refine,
@@ -7306,69 +5419,77 @@ atcommand_character_storage_list (const int fd, struct map_session_data *sd,
stor->storage_[i].refine,
stor->storage_[i].nameid);
else
- sprintf (output, "%d %s (%s, id: %d)",
+ output = STRPRINTF("%d %s (%s, id: %d)",
stor->storage_[i].amount,
item_data->name, item_data->jname,
stor->storage_[i].nameid);
- clif_displaymessage (fd, output);
- memset (output, '\0', sizeof (output));
+ clif_displaymessage(fd, output);
+
+ output.clear();
counter2 = 0;
for (j = 0; j < item_data->slot; j++)
{
if (stor->storage_[i].card[j])
{
if ((item_temp =
- itemdb_search (stor->
+ itemdb_search(stor->
storage_[i].card[j])) !=
NULL)
{
- if (output[0] == '\0')
- sprintf (outputtmp,
- " -> (card(s): #%d %s (%s), ",
- ++counter2, item_temp->name,
- item_temp->jname);
+ if (output.empty())
+ output = STRPRINTF(
+ " -> (card(s): #%d %s (%s), ",
+ ++counter2,
+ item_temp->name,
+ item_temp->jname);
else
- sprintf (outputtmp, "#%d %s (%s), ",
- ++counter2, item_temp->name,
- item_temp->jname);
- strcat (output, outputtmp);
+ output += STRPRINTF(
+ "#%d %s (%s), ",
+ ++counter2,
+ item_temp->name,
+ item_temp->jname);
}
}
}
- if (output[0] != '\0')
+ if (!output.empty())
{
- output[strlen (output) - 2] = ')';
- output[strlen (output) - 1] = '\0';
- clif_displaymessage (fd, output);
+ // replace last ", "
+#ifdef WORKAROUND_GCC46_LIBRARY
+ output.resize(output.size() - 1);
+#else
+ output.pop_back();
+#endif
+ output.back() = ')';
+ clif_displaymessage(fd, output);
}
}
}
if (count == 0)
- clif_displaymessage (fd,
+ clif_displaymessage(fd,
"No item found in the storage of this player.");
else
{
- sprintf (output,
+ std::string output = STRPRINTF(
"%d item(s) found in %d kind(s) of items.",
counter, count);
- clif_displaymessage (fd, output);
+ clif_displaymessage(fd, output);
}
}
else
{
- clif_displaymessage (fd, "This player has no storage.");
+ clif_displaymessage(fd, "This player has no storage.");
return -1;
}
}
else
{
- clif_displaymessage (fd, "Your GM level don't authorise you to do this action on this player.");
+ clif_displaymessage(fd, "Your GM level don't authorise you to do this action on this player.");
return -1;
}
}
else
{
- clif_displaymessage (fd, "Character not found.");
+ clif_displaymessage(fd, "Character not found.");
return -1;
}
@@ -7379,29 +5500,26 @@ atcommand_character_storage_list (const int fd, struct map_session_data *sd,
* @charcartlist <character>: Displays the items list of a player's cart.
*------------------------------------------
*/
-int
-atcommand_character_cart_list (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_character_cart_list(const int fd, struct map_session_data *sd,
+ const char *, const char *message)
{
struct map_session_data *pl_sd;
struct item_data *item_data, *item_temp;
- int i, j, count, counter, counter2;
- char character[100], output[200], outputtmp[200];
+ int i, j, count, counter, counter2;
+ char character[100];
- memset (character, '\0', sizeof (character));
- memset (output, '\0', sizeof (output));
- memset (outputtmp, '\0', sizeof (outputtmp));
+ memset(character, '\0', sizeof(character));
- if (!message || !*message || sscanf (message, "%99[^\n]", character) < 1)
+ if (!message || !*message || sscanf(message, "%99[^\n]", character) < 1)
{
- clif_displaymessage (fd,
+ clif_displaymessage(fd,
"Please, enter a player name (usage: @charitemlist <char name>).");
return -1;
}
- if ((pl_sd = map_nick2sd (character)) != NULL)
+ if ((pl_sd = map_nick2sd(character)) != NULL)
{
- if (pc_isGM (sd) >= pc_isGM (pl_sd))
+ if (pc_isGM(sd) >= pc_isGM(pl_sd))
{ // you can look items only lower or same level
counter = 0;
count = 0;
@@ -7409,81 +5527,91 @@ atcommand_character_cart_list (const int fd, struct map_session_data *sd,
{
if (pl_sd->status.cart[i].nameid > 0
&& (item_data =
- itemdb_search (pl_sd->status.cart[i].nameid)) != NULL)
+ itemdb_search(pl_sd->status.cart[i].nameid)) != NULL)
{
counter = counter + pl_sd->status.cart[i].amount;
count++;
if (count == 1)
{
- sprintf (output,
- "------ Cart items list of '%s' ------",
- pl_sd->status.name);
- clif_displaymessage (fd, output);
+ std::string output = STRPRINTF(
+ "------ Cart items list of '%s' ------",
+ pl_sd->status.name);
+ clif_displaymessage(fd, output);
}
+
+ std::string output;
if (pl_sd->status.cart[i].refine)
- sprintf (output, "%d %s %+d (%s %+d, id: %d)",
- pl_sd->status.cart[i].amount,
- item_data->name,
- pl_sd->status.cart[i].refine,
- item_data->jname,
- pl_sd->status.cart[i].refine,
- pl_sd->status.cart[i].nameid);
+ output = STRPRINTF("%d %s %+d (%s %+d, id: %d)",
+ pl_sd->status.cart[i].amount,
+ item_data->name,
+ pl_sd->status.cart[i].refine,
+ item_data->jname,
+ pl_sd->status.cart[i].refine,
+ pl_sd->status.cart[i].nameid);
else
- sprintf (output, "%d %s (%s, id: %d)",
- pl_sd->status.cart[i].amount,
- item_data->name, item_data->jname,
- pl_sd->status.cart[i].nameid);
- clif_displaymessage (fd, output);
- memset (output, '\0', sizeof (output));
+
+ output = STRPRINTF("%d %s (%s, id: %d)",
+ pl_sd->status.cart[i].amount,
+ item_data->name, item_data->jname,
+ pl_sd->status.cart[i].nameid);
+ clif_displaymessage(fd, output);
+
+ output.clear();
counter2 = 0;
for (j = 0; j < item_data->slot; j++)
{
if (pl_sd->status.cart[i].card[j])
{
if ((item_temp =
- itemdb_search (pl_sd->status.
+ itemdb_search(pl_sd->status.
cart[i].card[j])) != NULL)
{
- if (output[0] == '\0')
- sprintf (outputtmp,
- " -> (card(s): #%d %s (%s), ",
- ++counter2, item_temp->name,
- item_temp->jname);
+ if (output.empty())
+ output = STRPRINTF(
+ " -> (card(s): #%d %s (%s), ",
+ ++counter2,
+ item_temp->name,
+ item_temp->jname);
else
- sprintf (outputtmp, "#%d %s (%s), ",
- ++counter2, item_temp->name,
- item_temp->jname);
- strcat (output, outputtmp);
+ output += STRPRINTF(
+ "#%d %s (%s), ",
+ ++counter2,
+ item_temp->name,
+ item_temp->jname);
}
}
}
- if (output[0] != '\0')
+ if (!output.empty())
{
- output[strlen (output) - 2] = ')';
- output[strlen (output) - 1] = '\0';
- clif_displaymessage (fd, output);
+#ifdef WORKAROUND_GCC46_LIBRARY
+ output.resize(output.size() - 1);
+#else
+ output.pop_back();
+#endif
+ output.back() = '0';
+ clif_displaymessage(fd, output);
}
}
}
if (count == 0)
- clif_displaymessage (fd,
+ clif_displaymessage(fd,
"No item found in the cart of this player.");
else
{
- sprintf (output, "%d item(s) found in %d kind(s) of items.",
+ std::string output = STRPRINTF("%d item(s) found in %d kind(s) of items.",
counter, count);
- clif_displaymessage (fd, output);
+ clif_displaymessage(fd, output);
}
}
else
{
- clif_displaymessage (fd, "Your GM level don't authorise you to do this action on this player.");
+ clif_displaymessage(fd, "Your GM level don't authorise you to do this action on this player.");
return -1;
}
}
else
{
- clif_displaymessage (fd, "Character not found.");
+ clif_displaymessage(fd, "Character not found.");
return -1;
}
@@ -7495,16 +5623,15 @@ atcommand_character_cart_list (const int fd, struct map_session_data *sd,
* enable killing players even when not in pvp
*------------------------------------------
*/
-int
-atcommand_killer (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_killer(const int fd, struct map_session_data *sd,
+ const char *, const char *)
{
sd->special_state.killer = !sd->special_state.killer;
if (sd->special_state.killer)
- clif_displaymessage (fd, "You be a killa...");
+ clif_displaymessage(fd, "You be a killa...");
else
- clif_displaymessage (fd, "You gonna be own3d...");
+ clif_displaymessage(fd, "You gonna be own3d...");
return 0;
}
@@ -7514,16 +5641,15 @@ atcommand_killer (const int fd, struct map_session_data *sd,
* enable other people killing you
*------------------------------------------
*/
-int
-atcommand_killable (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_killable(const int fd, struct map_session_data *sd,
+ const char *, const char *)
{
sd->special_state.killable = !sd->special_state.killable;
if (sd->special_state.killable)
- clif_displaymessage (fd, "You gonna be own3d...");
+ clif_displaymessage(fd, "You gonna be own3d...");
else
- clif_displaymessage (fd, "You be a killa...");
+ clif_displaymessage(fd, "You be a killa...");
return 0;
}
@@ -7533,53 +5659,24 @@ atcommand_killable (const int fd, struct map_session_data *sd,
* enable another player to be killed
*------------------------------------------
*/
-int
-atcommand_charkillable (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_charkillable(const int fd, struct map_session_data *,
+ const char *, const char *message)
{
struct map_session_data *pl_sd = NULL;
if (!message || !*message)
return -1;
- if ((pl_sd = map_nick2sd ((char *) message)) == NULL)
+ if ((pl_sd = map_nick2sd(message)) == NULL)
return -1;
pl_sd->special_state.killable = !pl_sd->special_state.killable;
if (pl_sd->special_state.killable)
- clif_displaymessage (fd, "The player is now killable");
+ clif_displaymessage(fd, "The player is now killable");
else
- clif_displaymessage (fd, "The player is no longer killable");
-
- return 0;
-}
-
-/*==========================================
- * @skillon by MouseJstr
- * turn skills on for the map
- *------------------------------------------
- */
-int
-atcommand_skillon (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
-{
- map[sd->bl.m].flag.noskill = 0;
- clif_displaymessage (fd, "Map skills are on.");
- return 0;
-}
+ clif_displaymessage(fd, "The player is no longer killable");
-/*==========================================
- * @skilloff by MouseJstr
- * Turn skills off on the map
- *------------------------------------------
- */
-int
-atcommand_skilloff (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
-{
- map[sd->bl.m].flag.noskill = 1;
- clif_displaymessage (fd, "Map skills are off.");
return 0;
}
@@ -7589,12 +5686,11 @@ atcommand_skilloff (const int fd, struct map_session_data *sd,
* move a npc
*------------------------------------------
*/
-int
-atcommand_npcmove (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_npcmove(const int, struct map_session_data *sd,
+ const char *, const char *message)
{
char character[100];
- int x = 0, y = 0;
+ int x = 0, y = 0;
struct npc_data *nd = 0;
if (sd == NULL)
@@ -7603,19 +5699,19 @@ atcommand_npcmove (const int fd, struct map_session_data *sd,
if (!message || !*message)
return -1;
- memset (character, '\0', sizeof character);
+ memset(character, '\0', sizeof character);
- if (sscanf (message, "%d %d %99[^\n]", &x, &y, character) < 3)
+ if (sscanf(message, "%d %d %99[^\n]", &x, &y, character) < 3)
return -1;
- nd = npc_name2id (character);
+ nd = npc_name2id(character);
if (nd == NULL)
return -1;
- npc_enable (character, 0);
+ npc_enable(character, 0);
nd->bl.x = x;
nd->bl.y = y;
- npc_enable (character, 1);
+ npc_enable(character, 1);
return 0;
}
@@ -7626,90 +5722,55 @@ atcommand_npcmove (const int fd, struct map_session_data *sd,
* Create a new static warp point.
*------------------------------------------
*/
-int
-atcommand_addwarp (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_addwarp(const int fd, struct map_session_data *sd,
+ const char *, const char *message)
{
- char w1[64], w3[64], w4[64];
- char map[30], output[200];
- int x, y, ret;
+ char mapname[30];
+ int x, y, ret;
if (!message || !*message)
return -1;
- if (sscanf (message, "%99s %d %d[^\n]", map, &x, &y) < 3)
+ if (sscanf(message, "%29s %d %d[^\n]", mapname, &x, &y) < 3)
return -1;
- sprintf (w1, "%s,%d,%d", sd->mapname, sd->bl.x, sd->bl.y);
- sprintf (w3, "%s%d%d%d%d", map, sd->bl.x, sd->bl.y, x, y);
- sprintf (w4, "1,1,%s.gat,%d,%d", map, x, y);
+ std::string w1 = STRPRINTF("%s,%d,%d", sd->mapname, sd->bl.x, sd->bl.y);
+ std::string w3 = STRPRINTF("%s%d%d%d%d", mapname, sd->bl.x, sd->bl.y, x, y);
+ std::string w4 = STRPRINTF("1,1,%s.gat,%d,%d", mapname, x, y);
- ret = npc_parse_warp (w1, "warp", w3, w4);
+ ret = npc_parse_warp(w1.c_str(), "warp", w3.c_str(), w4.c_str());
- sprintf (output, "New warp NPC => %s", w3);
-
- clif_displaymessage (fd, output);
+ std::string output = STRPRINTF("New warp NPC => %s", w3);
+ clif_displaymessage(fd, output);
return ret;
}
/*==========================================
- * @follow by [MouseJstr]
- *
- * Follow a player .. staying no more then 5 spaces away
- *------------------------------------------
- */
-int
-atcommand_follow (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
-{
-#if 0
- struct map_session_data *pl_sd = NULL;
-
- if (!message || !*message)
- return -1;
- if ((pl_sd = map_nick2sd ((char *) message)) != NULL)
- pc_follow (sd, pl_sd->bl.id);
- else
- return 1;
-#endif
-
- /*
- * Command disabled - it's incompatible with the TMW
- * client.
- */
- clif_displaymessage (fd, "@follow command not available");
-
- return 0;
-
-}
-
-/*==========================================
* @chareffect by [MouseJstr]
*
* Create a effect localized on another character
*------------------------------------------
*/
-int
-atcommand_chareffect (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_chareffect(const int fd, struct map_session_data *,
+ const char *, const char *message)
{
struct map_session_data *pl_sd = NULL;
char target[255];
- int type = 0;
+ int type = 0;
if (!message || !*message
- || sscanf (message, "%d %s", &type, target) != 2)
+ || sscanf(message, "%d %s", &type, target) != 2)
{
- clif_displaymessage (fd, "usage: @chareffect <type+> <target>.");
+ clif_displaymessage(fd, "usage: @chareffect <type+> <target>.");
return -1;
}
- if ((pl_sd = map_nick2sd ((char *) target)) == NULL)
+ if ((pl_sd = map_nick2sd(target)) == NULL)
return -1;
- clif_specialeffect (&pl_sd->bl, type, 0);
- clif_displaymessage (fd, "Your Effect Has Changed."); // Your effect has changed.
+ clif_specialeffect(&pl_sd->bl, type, 0);
+ clif_displaymessage(fd, "Your Effect Has Changed."); // Your effect has changed.
return 0;
}
@@ -7720,18 +5781,17 @@ atcommand_chareffect (const int fd, struct map_session_data *sd,
* Drop all your possession on the ground
*------------------------------------------
*/
-int
-atcommand_dropall (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_dropall(const int, struct map_session_data *sd,
+ const char *, const char *)
{
- int i;
+ int i;
for (i = 0; i < MAX_INVENTORY; i++)
{
if (sd->status.inventory[i].amount)
{
- if (sd->status.inventory[i].equip != 0)
- pc_unequipitem (sd, i, 0);
- pc_dropitem (sd, i, sd->status.inventory[i].amount);
+ if (bool(sd->status.inventory[i].equip))
+ pc_unequipitem(sd, i, CalcStatus::NOW);
+ pc_dropitem(sd, i, sd->status.inventory[i].amount);
}
}
return 0;
@@ -7744,29 +5804,28 @@ atcommand_dropall (const int fd, struct map_session_data *sd,
* done in response to them being disrespectful of a GM
*------------------------------------------
*/
-int
-atcommand_chardropall (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_chardropall(const int fd, struct map_session_data *,
+ const char *, const char *message)
{
- int i;
+ int i;
struct map_session_data *pl_sd = NULL;
if (!message || !*message)
return -1;
- if ((pl_sd = map_nick2sd ((char *) message)) == NULL)
+ if ((pl_sd = map_nick2sd(message)) == NULL)
return -1;
for (i = 0; i < MAX_INVENTORY; i++)
{
if (pl_sd->status.inventory[i].amount)
{
- if (pl_sd->status.inventory[i].equip != 0)
- pc_unequipitem (pl_sd, i, 0);
- pc_dropitem (pl_sd, i, pl_sd->status.inventory[i].amount);
+ if (bool(pl_sd->status.inventory[i].equip))
+ pc_unequipitem(pl_sd, i, CalcStatus::NOW);
+ pc_dropitem(pl_sd, i, pl_sd->status.inventory[i].amount);
}
}
- clif_displaymessage (pl_sd->fd, "Ever play 52 card pickup?");
- clif_displaymessage (fd, "It is done");
+ clif_displaymessage(pl_sd->fd, "Ever play 52 card pickup?");
+ clif_displaymessage(fd, "It is done");
//clif_displaymessage(fd, "It is offical.. your a jerk");
return 0;
@@ -7779,22 +5838,21 @@ atcommand_chardropall (const int fd, struct map_session_data *sd,
* debugging easie
*------------------------------------------
*/
-int
-atcommand_storeall (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_storeall(const int fd, struct map_session_data *sd,
+ const char *, const char *)
{
- int i;
- nullpo_retr (-1, sd);
+ int i;
+ nullpo_retr(-1, sd);
- if (sd->state.storage_flag != 1)
+ if (!sd->state.storage_open)
{ //Open storage.
- switch (storage_storageopen (sd))
+ switch (storage_storageopen(sd))
{
case 2: //Try again
- clif_displaymessage (fd, "run this command again..");
+ clif_displaymessage(fd, "run this command again..");
return 0;
case 1: //Failure
- clif_displaymessage (fd,
+ clif_displaymessage(fd,
"You can't open the storage currently.");
return 1;
}
@@ -7803,14 +5861,14 @@ atcommand_storeall (const int fd, struct map_session_data *sd,
{
if (sd->status.inventory[i].amount)
{
- if (sd->status.inventory[i].equip != 0)
- pc_unequipitem (sd, i, 0);
- storage_storageadd (sd, i, sd->status.inventory[i].amount);
+ if (bool(sd->status.inventory[i].equip))
+ pc_unequipitem(sd, i, CalcStatus::NOW);
+ storage_storageadd(sd, i, sd->status.inventory[i].amount);
}
}
- storage_storageclose (sd);
+ storage_storageclose(sd);
- clif_displaymessage (fd, "It is done");
+ clif_displaymessage(fd, "It is done");
return 0;
}
@@ -7820,111 +5878,42 @@ atcommand_storeall (const int fd, struct map_session_data *sd,
* A way to screw with players who piss you off
*------------------------------------------
*/
-int
-atcommand_charstoreall (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_charstoreall(const int fd, struct map_session_data *sd,
+ const char *, const char *message)
{
- int i;
+ int i;
struct map_session_data *pl_sd = NULL;
if (!message || !*message)
return -1;
- if ((pl_sd = map_nick2sd ((char *) message)) == NULL)
+ if ((pl_sd = map_nick2sd(message)) == NULL)
return -1;
- if (storage_storageopen (pl_sd) == 1)
+ if (storage_storageopen(pl_sd) == 1)
{
- clif_displaymessage (fd,
+ clif_displaymessage(fd,
"Had to open the characters storage window...");
- clif_displaymessage (fd, "run this command again..");
+ clif_displaymessage(fd, "run this command again..");
return 0;
}
for (i = 0; i < MAX_INVENTORY; i++)
{
if (pl_sd->status.inventory[i].amount)
{
- if (pl_sd->status.inventory[i].equip != 0)
- pc_unequipitem (pl_sd, i, 0);
- storage_storageadd (pl_sd, i, sd->status.inventory[i].amount);
+ if (bool(pl_sd->status.inventory[i].equip))
+ pc_unequipitem(pl_sd, i, CalcStatus::NOW);
+ storage_storageadd(pl_sd, i, sd->status.inventory[i].amount);
}
}
- storage_storageclose (pl_sd);
+ storage_storageclose(pl_sd);
- clif_displaymessage (pl_sd->fd,
+ clif_displaymessage(pl_sd->fd,
"Everything you own has been put away for safe keeping.");
- clif_displaymessage (pl_sd->fd,
+ clif_displaymessage(pl_sd->fd,
"go to the nearest kafka to retrieve it..");
- clif_displaymessage (pl_sd->fd, " -- the management");
-
- clif_displaymessage (fd, "It is done");
-
- return 0;
-}
-
-/*==========================================
- * @skillid by [MouseJstr]
- *
- * lookup a skill by name
- *------------------------------------------
- */
-int
-atcommand_skillid (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
-{
- int skillen = 0, idx = 0;
- if (!message || !*message)
- return -1;
- skillen = strlen (message);
- while (skill_names[idx].id != 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,
- skill_names[idx].desc);
- clif_displaymessage (fd, output);
- }
- idx++;
- }
- return 0;
-}
-
-/*==========================================
- * @useskill by [MouseJstr]
- *
- * A way of using skills without having to find them in the skills menu
- *------------------------------------------
- */
-int
-atcommand_useskill (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
-{
- struct map_session_data *pl_sd = NULL;
- int skillnum;
- int skilllv;
- int inf;
- char target[255];
+ clif_displaymessage(pl_sd->fd, " -- the management");
- if (!message || !*message)
- return -1;
- if (sscanf (message, "%d %d %s", &skillnum, &skilllv, target) != 3)
- {
- clif_displaymessage (fd,
- "Usage: @useskill <skillnum> <skillv> <target>");
- return -1;
- }
- if ((pl_sd = map_nick2sd (target)) == NULL)
- {
- return -1;
- }
-
- inf = skill_get_inf (skillnum);
-
- if ((inf == 2) || (inf == 1))
- skill_use_pos (sd, pl_sd->bl.x, pl_sd->bl.y, skillnum, skilllv);
- else
- skill_use_id (sd, pl_sd->bl.id, skillnum, skilllv);
+ clif_displaymessage(fd, "It is done");
return 0;
}
@@ -7933,18 +5922,17 @@ atcommand_useskill (const int fd, struct map_session_data *sd,
* It is made to rain.
*------------------------------------------
*/
-int
-atcommand_rain (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_rain(const int, struct map_session_data *sd,
+ const char *, const char *)
{
- int effno = 0;
+ int effno = 0;
effno = 161;
- nullpo_retr (-1, sd);
+ nullpo_retr(-1, sd);
if (effno < 0 || map[sd->bl.m].flag.rain)
return -1;
map[sd->bl.m].flag.rain = 1;
- clif_specialeffect (&sd->bl, effno, 2);
+ clif_specialeffect(&sd->bl, effno, 2);
return 0;
}
@@ -7952,18 +5940,17 @@ atcommand_rain (const int fd, struct map_session_data *sd,
* It is made to snow.
*------------------------------------------
*/
-int
-atcommand_snow (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_snow(const int, struct map_session_data *sd,
+ const char *, const char *)
{
- int effno = 0;
+ int effno = 0;
effno = 162;
- nullpo_retr (-1, sd);
+ nullpo_retr(-1, sd);
if (effno < 0 || map[sd->bl.m].flag.snow)
return -1;
map[sd->bl.m].flag.snow = 1;
- clif_specialeffect (&sd->bl, effno, 2);
+ clif_specialeffect(&sd->bl, effno, 2);
return 0;
}
@@ -7971,18 +5958,17 @@ atcommand_snow (const int fd, struct map_session_data *sd,
* Cherry tree snowstorm is made to fall. (Sakura)
*------------------------------------------
*/
-int
-atcommand_sakura (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_sakura(const int, struct map_session_data *sd,
+ const char *, const char *)
{
- int effno = 0;
+ int effno = 0;
effno = 163;
- nullpo_retr (-1, sd);
+ nullpo_retr(-1, sd);
if (effno < 0 || map[sd->bl.m].flag.sakura)
return -1;
map[sd->bl.m].flag.sakura = 1;
- clif_specialeffect (&sd->bl, effno, 2);
+ clif_specialeffect(&sd->bl, effno, 2);
return 0;
}
@@ -7990,18 +5976,17 @@ atcommand_sakura (const int fd, struct map_session_data *sd,
* Fog hangs over.
*------------------------------------------
*/
-int
-atcommand_fog (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_fog(const int, struct map_session_data *sd,
+ const char *, const char *)
{
- int effno = 0;
+ int effno = 0;
effno = 233;
- nullpo_retr (-1, sd);
+ nullpo_retr(-1, sd);
if (effno < 0 || map[sd->bl.m].flag.fog)
return -1;
map[sd->bl.m].flag.fog = 1;
- clif_specialeffect (&sd->bl, effno, 2);
+ clif_specialeffect(&sd->bl, effno, 2);
return 0;
}
@@ -8010,18 +5995,17 @@ atcommand_fog (const int fd, struct map_session_data *sd,
* Fallen leaves fall.
*------------------------------------------
*/
-int
-atcommand_leaves (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_leaves(const int, struct map_session_data *sd,
+ const char *, const char *)
{
- int effno = 0;
+ int effno = 0;
effno = 333;
- nullpo_retr (-1, sd);
+ nullpo_retr(-1, sd);
if (effno < 0 || map[sd->bl.m].flag.leaves)
return -1;
map[sd->bl.m].flag.leaves = 1;
- clif_specialeffect (&sd->bl, effno, 2);
+ clif_specialeffect(&sd->bl, effno, 2);
return 0;
}
@@ -8029,42 +6013,43 @@ atcommand_leaves (const int fd, struct map_session_data *sd,
*
*------------------------------------------
*/
-int atcommand_summon (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_summon(const int, struct map_session_data *sd,
+ const char *, const char *message)
{
char name[100];
- int mob_id = 0;
- int x = 0;
- int y = 0;
- int id = 0;
+ int mob_id = 0;
+ int x = 0;
+ int y = 0;
+ int id = 0;
struct mob_data *md;
- unsigned int tick = gettick ();
+ tick_t tick = gettick();
- nullpo_retr (-1, sd);
+ nullpo_retr(-1, sd);
if (!message || !*message)
return -1;
- if (sscanf (message, "%99[^\n]", name) < 1)
+ if (sscanf(message, "%99[^\n]", name) < 1)
return -1;
- if ((mob_id = atoi (name)) == 0)
- mob_id = mobdb_searchname (name);
+ if ((mob_id = atoi(name)) == 0)
+ mob_id = mobdb_searchname(name);
if (mob_id == 0)
return -1;
- x = sd->bl.x + (MRAND (10) - 5);
- y = sd->bl.y + (MRAND (10) - 5);
+ x = sd->bl.x + random_::in(-5, 4);
+ y = sd->bl.y + random_::in(-5, 4);
- id = mob_once_spawn (sd, "this", x, y, "--ja--", mob_id, 1, "");
- if ((md = (struct mob_data *) map_id2bl (id)))
+ id = mob_once_spawn(sd, "this", x, y, "--ja--", mob_id, 1, "");
+ if ((md = (struct mob_data *) map_id2bl(id)))
{
md->master_id = sd->bl.id;
md->state.special_mob_ai = 1;
- md->mode = mob_db[md->mob_class].mode | 0x04;
- md->deletetimer = add_timer (tick + 60000, mob_timer_delete, id, 0);
- clif_misceffect (&md->bl, 344);
+ md->mode = mob_db[md->mob_class].mode | MobMode::AGGRESSIVE;
+ md->deletetimer = Timer(tick + std::chrono::minutes(1),
+ std::bind(mob_timer_delete, ph::_1, ph::_2,
+ id));
+ clif_misceffect(&md->bl, 344);
}
- clif_skill_poseffect (&sd->bl, AM_CALLHOMUN, 1, x, y, tick);
return 0;
}
@@ -8078,28 +6063,27 @@ int atcommand_summon (const int fd, struct map_session_data *sd,
* for short periods of time
*------------------------------------------
*/
-int
-atcommand_adjcmdlvl (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_adjcmdlvl(const int fd, struct map_session_data *,
+ const char *, const char *message)
{
- int i, newlev;
+ int i, newlev;
char cmd[100];
- if (!message || !*message || sscanf (message, "%d %s", &newlev, cmd) != 2)
+ if (!message || !*message || sscanf(message, "%d %s", &newlev, cmd) != 2)
{
- clif_displaymessage (fd, "usage: @adjcmdlvl <lvl> <command>.");
+ clif_displaymessage(fd, "usage: @adjcmdlvl <lvl> <command>.");
return -1;
}
- for (i = 0; atcommand_info[i].type != AtCommand_None; i++)
- if (strcasecmp (cmd, atcommand_info[i].command + 1) == 0)
+ for (i = 0; atcommand_info[i].command; i++)
+ if (strcasecmp(cmd, atcommand_info[i].command + 1) == 0)
{
atcommand_info[i].level = newlev;
- clif_displaymessage (fd, "@command level changed.");
+ clif_displaymessage(fd, "@command level changed.");
return 0;
}
- clif_displaymessage (fd, "@command not found.");
+ clif_displaymessage(fd, "@command not found.");
return -1;
}
@@ -8112,25 +6096,24 @@ atcommand_adjcmdlvl (const int fd, struct map_session_data *sd,
* for short periods of time
*------------------------------------------
*/
-int
-atcommand_adjgmlvl (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_adjgmlvl(const int fd, struct map_session_data *,
+ const char *, const char *message)
{
- int newlev;
+ int newlev;
char user[100];
struct map_session_data *pl_sd;
if (!message || !*message
- || sscanf (message, "%d %s", &newlev, user) != 2)
+ || sscanf(message, "%d %s", &newlev, user) != 2)
{
- clif_displaymessage (fd, "usage: @adjgmlvl <lvl> <user>.");
+ clif_displaymessage(fd, "usage: @adjgmlvl <lvl> <user>.");
return -1;
}
- if ((pl_sd = map_nick2sd ((char *) user)) == NULL)
+ if ((pl_sd = map_nick2sd(user)) == NULL)
return -1;
- pc_set_gm_level (pl_sd->status.account_id, newlev);
+ pc_set_gm_level(pl_sd->status.account_id, newlev);
return 0;
}
@@ -8144,442 +6127,432 @@ atcommand_adjgmlvl (const int fd, struct map_session_data *sd,
* gonna scream!
*------------------------------------------
*/
-int
-atcommand_trade (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_trade(const int, struct map_session_data *sd,
+ const char *, const char *message)
{
struct map_session_data *pl_sd = NULL;
if (!message || !*message)
return -1;
- if ((pl_sd = map_nick2sd ((char *) message)) != NULL)
+ if ((pl_sd = map_nick2sd(message)) != NULL)
{
- trade_traderequest (sd, pl_sd->bl.id);
+ trade_traderequest(sd, pl_sd->bl.id);
return 0;
}
return -1;
}
-/*===========================
- * @unmute [Valaris]
- *===========================
-*/
-int atcommand_unmute (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
-{
- struct map_session_data *pl_sd = NULL;
- if (!message || !*message)
- return -1;
-
- if ((pl_sd = map_nick2sd ((char *) message)) != NULL)
- {
- if (pl_sd->sc_data[SC_NOCHAT].timer != -1)
- {
- skill_status_change_end (&pl_sd->bl, SC_NOCHAT, -1);
- clif_displaymessage (sd->fd, "Player unmuted");
- }
- else
- clif_displaymessage (sd->fd, "Player is not muted");
- }
+/* Magic atcommands by Fate */
- return 0;
-}
+static
+SkillID magic_skills[] =
+{
+ SkillID::TMW_MAGIC,
+ SkillID::TMW_MAGIC_LIFE,
+ SkillID::TMW_MAGIC_WAR,
+ SkillID::TMW_MAGIC_TRANSMUTE,
+ SkillID::TMW_MAGIC_NATURE,
+ SkillID::TMW_MAGIC_ETHER,
+};
-/* Magic atcommands by Fate */
+constexpr
+size_t magic_skills_nr = sizeof(magic_skills) / sizeof(magic_skills[0]);
-static int magic_base = TMW_MAGIC;
-#define magic_skills_nr 6
-static const char *magic_skill_names[magic_skills_nr] =
- { "magic", "life", "war", "transmute", "nature", "astral" };
+static
+const char *magic_skill_names[magic_skills_nr] =
+{
+ "magic",
+ "life",
+ "war",
+ "transmute",
+ "nature",
+ "astral"
+};
-int
-atcommand_magic_info (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_magic_info(const int fd, struct map_session_data *,
+ const char *, const char *message)
{
char character[100];
- char buf[200];
struct map_session_data *pl_sd;
- memset (character, '\0', sizeof (character));
+ memset(character, '\0', sizeof(character));
- if (!message || !*message || sscanf (message, "%99[^\n]", character) < 1)
+ if (!message || !*message || sscanf(message, "%99[^\n]", character) < 1)
{
- clif_displaymessage (fd, "Usage: @magicinfo <char_name>");
+ clif_displaymessage(fd, "Usage: @magicinfo <char_name>");
return -1;
}
- if ((pl_sd = map_nick2sd (character)) != NULL)
+ if ((pl_sd = map_nick2sd(character)) != NULL)
{
- int i;
-
- sprintf (buf, "`%s' has the following magic skills:", character);
- clif_displaymessage (fd, buf);
+ std::string buf = STRPRINTF(
+ "`%s' has the following magic skills:",
+ character);
+ clif_displaymessage(fd, buf);
- for (i = 0; i < magic_skills_nr; i++)
+ for (size_t i = 0; i < magic_skills_nr; i++)
{
- sprintf (buf, "%d in %s", pl_sd->status.skill[i + magic_base].lv,
- magic_skill_names[i]);
- if (pl_sd->status.skill[i + magic_base].id == i + magic_base)
- clif_displaymessage (fd, buf);
+ SkillID sk = magic_skills[i];
+ buf = STRPRINTF(
+ "%d in %s",
+ pl_sd->status.skill[sk].lv,
+ magic_skill_names[i]);
+ if (pl_sd->status.skill[sk].lv)
+ clif_displaymessage(fd, buf);
}
return 0;
}
else
- clif_displaymessage (fd, "Character not found.");
+ clif_displaymessage(fd, "Character not found.");
return -1;
}
-static void set_skill (struct map_session_data *sd, int i, int level)
+static
+void set_skill(struct map_session_data *sd, SkillID i, int level)
{
- sd->status.skill[i].id = level ? i : 0;
sd->status.skill[i].lv = level;
}
-int
-atcommand_set_magic (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_set_magic(const int fd, struct map_session_data *,
+ const char *, const char *message)
{
char character[100];
char magic_type[20];
- int skill_index = -1; // 0: all
- int value;
+ int value;
struct map_session_data *pl_sd;
- memset (character, '\0', sizeof (character));
+ memset(character, '\0', sizeof(character));
if (!message || !*message
- || sscanf (message, "%19s %i %99[^\n]", magic_type, &value,
+ || sscanf(message, "%19s %i %99[^\n]", magic_type, &value,
character) < 1)
{
- clif_displaymessage (fd,
+ clif_displaymessage(fd,
"Usage: @setmagic <school> <value> <char-name>, where <school> is either `magic', one of the school names, or `all'.");
return -1;
}
- if (!strcasecmp ("all", magic_type))
- skill_index = 0;
+ SkillID skill_index = SkillID::NEGATIVE;
+ if (!strcasecmp("all", magic_type))
+ skill_index = SkillID::ZERO;
else
{
- int i;
- for (i = 0; i < magic_skills_nr; i++)
+ for (size_t i = 0; i < magic_skills_nr; i++)
{
- if (!strcasecmp (magic_skill_names[i], magic_type))
+ if (!strcasecmp(magic_skill_names[i], magic_type))
{
- skill_index = i + magic_base;
+ skill_index = magic_skills[i];
break;
}
}
}
- if (skill_index == -1)
+ if (skill_index == SkillID::NEGATIVE)
{
- clif_displaymessage (fd,
+ clif_displaymessage(fd,
"Incorrect school of magic. Use `magic', `nature', `life', `war', `transmute', `ether', or `all'.");
return -1;
}
- if ((pl_sd = map_nick2sd (character)) != NULL)
+ if ((pl_sd = map_nick2sd(character)) != NULL)
{
- int i;
- if (skill_index == 0)
- for (i = 0; i < magic_skills_nr; i++)
- set_skill (pl_sd, i + magic_base, value);
+ if (skill_index == SkillID::ZERO)
+ for (SkillID sk : magic_skills)
+ set_skill(pl_sd, sk, value);
else
- set_skill (pl_sd, skill_index, value);
+ set_skill(pl_sd, skill_index, value);
- clif_skillinfoblock (pl_sd);
+ clif_skillinfoblock(pl_sd);
return 0;
}
else
- clif_displaymessage (fd, "Character not found.");
+ clif_displaymessage(fd, "Character not found.");
return -1;
}
-int
-atcommand_log (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_log(const int, struct map_session_data *,
+ const char *, const char *)
{
- return 0; // only used for (implicit) logging
+ return 0;
+ // only used for (implicit) logging
}
-int
-atcommand_tee (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_tee(const int, struct map_session_data *sd,
+ const char *, const char *message)
{
- char *data = (char *)malloc (strlen (message) + 28);
- strcpy (data, sd->status.name);
- strcat (data, " : ");
- strcat (data, message);
- clif_message (&sd->bl, data);
+ char data[strlen(message) + 28];
+ strcpy(data, sd->status.name);
+ strcat(data, " : ");
+ strcat(data, message);
+ clif_message(&sd->bl, data);
return 0;
}
-int
-atcommand_invisible (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_invisible(const int, struct map_session_data *sd,
+ const char *, const char *)
{
- pc_invisibility (sd, 1);
+ pc_invisibility(sd, 1);
return 0;
}
-int
-atcommand_visible (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_visible(const int, struct map_session_data *sd,
+ const char *, const char *)
{
- pc_invisibility (sd, 0);
+ pc_invisibility(sd, 0);
return 0;
}
static
-int atcommand_jump_iterate (const int fd, struct map_session_data *sd,
- const char *command, const char *message,
- struct map_session_data *(*get_start) (void),
- struct map_session_data *(*get_next) (struct
- map_session_data
- * current))
-{
- char output[200];
+int atcommand_jump_iterate(const int fd, struct map_session_data *sd,
+ const char *, const char *,
+ struct map_session_data *(*get_start)(void),
+ struct map_session_data *(*get_next)(struct map_session_data*))
+{
struct map_session_data *pl_sd;
- memset (output, '\0', sizeof (output));
-
- pl_sd = (struct map_session_data *) map_id2bl (sd->followtarget);
+ pl_sd = (struct map_session_data *) map_id2bl(sd->followtarget);
if (pl_sd)
- pl_sd = get_next (pl_sd);
+ pl_sd = get_next(pl_sd);
if (!pl_sd)
- pl_sd = get_start ();
+ pl_sd = get_start();
if (pl_sd == sd)
{
- pl_sd = get_next (pl_sd);
+ pl_sd = get_next(pl_sd);
if (!pl_sd)
- pl_sd = get_start ();
+ pl_sd = get_start();
}
if (pl_sd->bl.m >= 0 && map[pl_sd->bl.m].flag.nowarpto
- && battle_config.any_warp_GM_min_level > pc_isGM (sd))
+ && battle_config.any_warp_GM_min_level > pc_isGM(sd))
{
- clif_displaymessage (fd,
+ clif_displaymessage(fd,
"You are not authorised to warp you to the map of this player.");
return -1;
}
if (sd->bl.m >= 0 && map[sd->bl.m].flag.nowarp
- && battle_config.any_warp_GM_min_level > pc_isGM (sd))
+ && battle_config.any_warp_GM_min_level > pc_isGM(sd))
{
- clif_displaymessage (fd,
+ clif_displaymessage(fd,
"You are not authorised to warp you from your actual map.");
return -1;
}
- pc_setpos (sd, map[pl_sd->bl.m].name, pl_sd->bl.x, pl_sd->bl.y, 3);
- sprintf (output, "Jump to %s", pl_sd->status.name);
- clif_displaymessage (fd, output);
+ pc_setpos(sd, map[pl_sd->bl.m].name, pl_sd->bl.x, pl_sd->bl.y, BeingRemoveWhy::WARPED);
+ std::string output = STRPRINTF("Jump to %s", pl_sd->status.name);
+ clif_displaymessage(fd, output);
sd->followtarget = pl_sd->bl.id;
return 0;
}
-int
-atcommand_iterate_forward_over_players (const int fd,
+int atcommand_iterate_forward_over_players(const int fd,
struct map_session_data *sd,
const char *command,
const char *message)
{
- return atcommand_jump_iterate (fd, sd, command, message,
+ return atcommand_jump_iterate(fd, sd, command, message,
map_get_first_session,
map_get_next_session);
}
-int
-atcommand_iterate_backwards_over_players (const int fd,
+int atcommand_iterate_backwards_over_players(const int fd,
struct map_session_data *sd,
const char *command,
const char *message)
{
- return atcommand_jump_iterate (fd, sd, command, message,
+ return atcommand_jump_iterate(fd, sd, command, message,
map_get_last_session,
map_get_prev_session);
}
-int atcommand_wgm (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_wgm(const int fd, struct map_session_data *sd,
+ const char *, const char *message)
{
if (tmw_CheckChatSpam(sd, message))
return 0;
- tmw_GmHackMsg ("%s: %s", sd->status.name, message);
- if (!pc_isGM (sd))
- clif_displaymessage (fd, "Message sent.");
+
+ tmw_GmHackMsg(static_cast<const std::string&>(STRPRINTF("[GM] %s: %s", sd->status.name, message)));
+ if (!pc_isGM(sd))
+ clif_displaymessage(fd, "Message sent.");
return 0;
}
-int atcommand_skillpool_info (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_skillpool_info(const int fd, struct map_session_data *,
+ const char *, const char *message)
{
char character[100];
struct map_session_data *pl_sd;
- if (!message || !*message || sscanf (message, "%99[^\n]", character) < 1)
+ if (!message || !*message || sscanf(message, "%99[^\n]", character) < 1)
{
- clif_displaymessage (fd, "Usage: @sp-info <char_name>");
+ clif_displaymessage(fd, "Usage: @sp-info <char_name>");
return -1;
}
- if ((pl_sd = map_nick2sd (character)) != NULL)
+ if ((pl_sd = map_nick2sd(character)) != NULL)
{
- char buf[200];
- int pool_skills[MAX_SKILL_POOL];
- int pool_skills_nr = skill_pool (pl_sd, pool_skills);
- int i;
+ SkillID pool_skills[MAX_SKILL_POOL];
+ int pool_skills_nr = skill_pool(pl_sd, pool_skills);
+ int i;
- sprintf (buf, "Active skills %d out of %d for %s:", pool_skills_nr,
- skill_pool_max (pl_sd), character);
- clif_displaymessage (fd, buf);
+ std::string buf = STRPRINTF(
+ "Active skills %d out of %d for %s:",
+ pool_skills_nr, skill_pool_max(pl_sd), character);
+ clif_displaymessage(fd, buf);
for (i = 0; i < pool_skills_nr; ++i)
{
- sprintf (buf, " - %s [%d]: power %d", skill_name (pool_skills[i]),
- pool_skills[i], skill_power (pl_sd, pool_skills[i]));
- clif_displaymessage (fd, buf);
+ buf = STRPRINTF(" - %s [%d]: power %d",
+ skill_name(pool_skills[i]),
+ pool_skills[i],
+ skill_power(pl_sd, pool_skills[i]));
+ clif_displaymessage(fd, buf);
}
- sprintf (buf, "Learned skills out of %d for %s:",
- skill_pool_skills_size, character);
- clif_displaymessage (fd, buf);
+ buf = STRPRINTF("Learned skills out of %d for %s:",
+ skill_pool_skills_size, character);
+ clif_displaymessage(fd, buf);
for (i = 0; i < skill_pool_skills_size; ++i)
{
- const char *name = skill_name (skill_pool_skills[i]);
- int lvl = pl_sd->status.skill[skill_pool_skills[i]].lv;
+ const char *name = skill_name(skill_pool_skills[i]);
+ int lvl = pl_sd->status.skill[skill_pool_skills[i]].lv;
if (lvl)
{
- sprintf (buf, " - %s [%d]: lvl %d", name,
- skill_pool_skills[i], lvl);
- clif_displaymessage (fd, buf);
+ buf = STRPRINTF(" - %s [%d]: lvl %d",
+ name, skill_pool_skills[i], lvl);
+ clif_displaymessage(fd, buf);
}
}
}
else
- clif_displaymessage (fd, "Character not found.");
+ clif_displaymessage(fd, "Character not found.");
return 0;
}
-int atcommand_skillpool_focus (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_skillpool_focus(const int fd, struct map_session_data *,
+ const char *, const char *message)
{
char character[100];
- int skill;
+ int skill_;
struct map_session_data *pl_sd;
if (!message || !*message
- || sscanf (message, "%d %99[^\n]", &skill, character) < 1)
+ || sscanf(message, "%d %99[^\n]", &skill_, character) < 1)
{
- clif_displaymessage (fd, "Usage: @sp-focus <skill-nr> <char_name>");
+ clif_displaymessage(fd, "Usage: @sp-focus <skill-nr> <char_name>");
return -1;
}
- if ((pl_sd = map_nick2sd (character)) != NULL)
+ SkillID skill = SkillID(skill_);
+
+ if ((pl_sd = map_nick2sd(character)) != NULL)
{
- if (skill_pool_activate (pl_sd, skill))
- clif_displaymessage (fd, "Activation failed.");
+ if (skill_pool_activate(pl_sd, skill))
+ clif_displaymessage(fd, "Activation failed.");
else
- clif_displaymessage (fd, "Activation successful.");
+ clif_displaymessage(fd, "Activation successful.");
}
else
- clif_displaymessage (fd, "Character not found.");
+ clif_displaymessage(fd, "Character not found.");
return 0;
}
-int atcommand_skillpool_unfocus (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_skillpool_unfocus(const int fd, struct map_session_data *,
+ const char *, const char *message)
{
char character[100];
- int skill;
+ int skill_;
struct map_session_data *pl_sd;
if (!message || !*message
- || sscanf (message, "%d %99[^\n]", &skill, character) < 1)
+ || sscanf(message, "%d %99[^\n]", &skill_, character) < 1)
{
- clif_displaymessage (fd, "Usage: @sp-unfocus <skill-nr> <char_name>");
+ clif_displaymessage(fd, "Usage: @sp-unfocus <skill-nr> <char_name>");
return -1;
}
- if ((pl_sd = map_nick2sd (character)) != NULL)
+ SkillID skill = SkillID(skill_);
+
+ if ((pl_sd = map_nick2sd(character)) != NULL)
{
- if (skill_pool_deactivate (pl_sd, skill))
- clif_displaymessage (fd, "Deactivation failed.");
+ if (skill_pool_deactivate(pl_sd, skill))
+ clif_displaymessage(fd, "Deactivation failed.");
else
- clif_displaymessage (fd, "Deactivation successful.");
+ clif_displaymessage(fd, "Deactivation successful.");
}
else
- clif_displaymessage (fd, "Character not found.");
+ clif_displaymessage(fd, "Character not found.");
return 0;
}
-int atcommand_skill_learn (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_skill_learn(const int fd, struct map_session_data *,
+ const char *, const char *message)
{
char character[100];
- int skill, level;
+ int skill_, level;
struct map_session_data *pl_sd;
if (!message || !*message
- || sscanf (message, "%d %d %99[^\n]", &skill, &level, character) < 1)
+ || sscanf(message, "%d %d %99[^\n]", &skill_, &level, character) < 1)
{
- clif_displaymessage (fd,
+ clif_displaymessage(fd,
"Usage: @skill-learn <skill-nr> <level> <char_name>");
return -1;
}
- if ((pl_sd = map_nick2sd (character)) != NULL)
+ SkillID skill = SkillID(skill_);
+
+ if ((pl_sd = map_nick2sd(character)) != NULL)
{
- set_skill (pl_sd, skill, level);
- clif_skillinfoblock (pl_sd);
+ set_skill(pl_sd, skill, level);
+ clif_skillinfoblock(pl_sd);
}
else
- clif_displaymessage (fd, "Character not found.");
+ clif_displaymessage(fd, "Character not found.");
return 0;
}
-int atcommand_ipcheck (const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+int atcommand_ipcheck(const int fd, struct map_session_data *,
+ const char *, const char *message)
{
struct map_session_data *pl_sd;
struct sockaddr_in sai;
- char output[200];
char character[25];
int i;
- socklen_t sa_len = sizeof (struct sockaddr);
+ socklen_t sa_len = sizeof(struct sockaddr);
unsigned long ip;
memset(character, '\0', sizeof(character));
- if (sscanf (message, "%24[^\n]", character) < 1)
+ if (sscanf(message, "%24[^\n]", character) < 1)
{
- clif_displaymessage (fd, "Usage: @ipcheck <char name>");
+ clif_displaymessage(fd, "Usage: @ipcheck <char name>");
return -1;
}
- if ((pl_sd = map_nick2sd (character)) == NULL)
+ if ((pl_sd = map_nick2sd(character)) == NULL)
{
- clif_displaymessage (fd, "Character not found.");
+ clif_displaymessage(fd, "Character not found.");
return -1;
}
- if (getpeername (pl_sd->fd, (struct sockaddr *)&sai, &sa_len))
+ if (getpeername(pl_sd->fd, (struct sockaddr *)&sai, &sa_len))
{
- clif_displaymessage (fd,
+ clif_displaymessage(fd,
"Guru Meditation Error: getpeername() failed");
return -1;
}
@@ -8594,43 +6567,43 @@ int atcommand_ipcheck (const int fd, struct map_session_data *sd,
if (session[i] && (pl_sd = (struct map_session_data *)session[i]->session_data)
&& pl_sd->state.auth)
{
- if (getpeername (pl_sd->fd, (struct sockaddr *)&sai, &sa_len))
+ if (getpeername(pl_sd->fd, (struct sockaddr *)&sai, &sa_len))
continue;
// Is checking GM levels really needed here?
if (ip == sai.sin_addr.s_addr)
{
- snprintf (output, sizeof(output),
- "Name: %s | Location: %s %d %d",
- pl_sd->status.name, pl_sd->mapname,
- pl_sd->bl.x, pl_sd->bl.y);
- clif_displaymessage (fd, output);
+ std::string output = STRPRINTF(
+ "Name: %s | Location: %s %d %d",
+ pl_sd->status.name, pl_sd->mapname,
+ pl_sd->bl.x, pl_sd->bl.y);
+ clif_displaymessage(fd, output);
}
}
}
- clif_displaymessage (fd, "End of list");
+ clif_displaymessage(fd, "End of list");
return 0;
}
int atcommand_doomspot(const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+ const char *, const char *)
{
struct map_session_data *pl_sd;
- int i;
+ int i;
for (i = 0; i < fd_max; i++)
{
if (session[i] && (pl_sd = (struct map_session_data *)session[i]->session_data)
&& pl_sd->state.auth && i != fd && sd->bl.m == pl_sd->bl.m
&& sd->bl.x == pl_sd->bl.x && sd->bl.y == pl_sd->bl.y
- && pc_isGM (sd) >= pc_isGM (pl_sd))
+ && pc_isGM(sd) >= pc_isGM(pl_sd))
{ // you can doom only lower or same gm level
- pc_damage (NULL, pl_sd, pl_sd->status.hp + 1);
- clif_displaymessage (pl_sd->fd, "The holy messenger has given judgement.");
+ pc_damage(NULL, pl_sd, pl_sd->status.hp + 1);
+ clif_displaymessage(pl_sd->fd, "The holy messenger has given judgement.");
}
}
- clif_displaymessage (fd, "Judgement was made.");
+ clif_displaymessage(fd, "Judgement was made.");
return 0;
}
diff --git a/src/map/atcommand.hpp b/src/map/atcommand.hpp
index d35cb4f..a226b76 100644
--- a/src/map/atcommand.hpp
+++ b/src/map/atcommand.hpp
@@ -1,225 +1,16 @@
-// $Id: atcommand.h 148 2004-09-30 14:05:37Z MouseJstr $
#ifndef ATCOMMAND_HPP
#define ATCOMMAND_HPP
-#include "map.hpp"
+#include "../common/const_array.hpp"
-enum AtCommandType
-{
- AtCommand_None = -1,
- AtCommand_Broadcast = 0,
- AtCommand_Setup,
- AtCommand_LocalBroadcast,
- AtCommand_MapMove,
- AtCommand_ResetState,
- AtCommand_CharWarp,
- AtCommand_Warp,
- AtCommand_Where,
- AtCommand_Goto,
- AtCommand_Jump,
- AtCommand_Who,
- AtCommand_WhoGroup,
- AtCommand_WhoMap,
- AtCommand_WhoMapGroup,
- AtCommand_WhoGM,
- AtCommand_Save,
- AtCommand_Load,
- AtCommand_Speed,
- AtCommand_Storage,
- AtCommand_GuildStorage,
- AtCommand_Option,
- AtCommand_Hide,
- AtCommand_Die,
- AtCommand_Kill,
- AtCommand_Alive,
- AtCommand_Kami,
- AtCommand_KamiB,
- AtCommand_Heal,
- AtCommand_Item,
- AtCommand_ItemReset,
- AtCommand_ItemCheck,
- AtCommand_BaseLevelUp,
- AtCommand_JobLevelUp,
- AtCommand_Help,
- AtCommand_GM,
- AtCommand_PvPOff,
- AtCommand_PvPOn,
- AtCommand_GvGOff,
- AtCommand_GvGOn,
- AtCommand_Model,
- AtCommand_Go,
- AtCommand_Spawn,
- AtCommand_Monster,
- AtCommand_KillMonster,
- AtCommand_KillMonster2,
- AtCommand_Produce,
- AtCommand_Memo,
- AtCommand_GAT,
- AtCommand_Packet,
- AtCommand_StatusPoint,
- AtCommand_SkillPoint,
- AtCommand_Zeny,
- AtCommand_Param,
- AtCommand_Strength,
- AtCommand_Agility,
- AtCommand_Vitality,
- AtCommand_Intelligence,
- AtCommand_Dexterity,
- AtCommand_Luck,
- AtCommand_GuildLevelUp,
- AtCommand_Recall,
- AtCommand_Revive,
- AtCommand_CharacterStats,
- AtCommand_CharacterStatsAll,
- AtCommand_CharacterOption,
- AtCommand_CharacterSave,
- AtCommand_CharacterLoad,
- AtCommand_Night,
- AtCommand_Day,
- AtCommand_Doom,
- AtCommand_DoomMap,
- AtCommand_Raise,
- AtCommand_RaiseMap,
- AtCommand_CharacterBaseLevel,
- AtCommand_CharacterJobLevel,
- AtCommand_Kick,
- AtCommand_KickAll,
- AtCommand_AllSkills,
- AtCommand_QuestSkill,
- AtCommand_CharQuestSkill,
- AtCommand_LostSkill,
- AtCommand_CharLostSkill,
- AtCommand_Party,
- AtCommand_Guild,
- AtCommand_AgitStart,
- AtCommand_AgitEnd,
- AtCommand_MapExit,
- AtCommand_IDSearch,
- AtCommand_CharSkReset,
- AtCommand_CharStReset,
- AtCommand_CharReset,
- //by chbrules
- AtCommand_CharModel,
- AtCommand_CharSKPoint,
- AtCommand_CharSTPoint,
- AtCommand_CharZeny,
- AtCommand_RecallAll,
- AtCommand_ReloadItemDB,
- AtCommand_ReloadMobDB,
- AtCommand_ReloadSkillDB,
- AtCommand_ReloadScript,
- AtCommand_ReloadGMDB,
- AtCommand_MapInfo,
- AtCommand_Dye,
- AtCommand_HairStyle,
- AtCommand_HairColor,
- AtCommand_AllStats,
- AtCommand_CharChangeSex, // by Yor
- AtCommand_CharBlock, // by Yor
- AtCommand_CharBan, // by Yor
- AtCommand_CharUnBlock, // by Yor
- AtCommand_CharUnBan, // by Yor
- AtCommand_MountPeco, // by Valaris
- AtCommand_CharMountPeco, // by Yor
- AtCommand_GuildSpy, // [Syrus22]
- AtCommand_PartySpy, // [Syrus22]
- AtCommand_GuildRecall, // by Yor
- AtCommand_PartyRecall, // by Yor
- AtCommand_Enablenpc,
- AtCommand_Disablenpc,
- AtCommand_ServerTime, // by Yor
- AtCommand_CharDelItem, // by Yor
- AtCommand_Jail, // by Yor
- AtCommand_UnJail, // by Yor
- AtCommand_Disguise, // [Valaris]
- AtCommand_UnDisguise, // by Yor
- AtCommand_IgnoreList, // by Yor
- AtCommand_CharIgnoreList, // by Yor
- AtCommand_InAll, // by Yor
- AtCommand_ExAll, // by Yor
- AtCommand_CharDisguise, // Kalaspuff
- AtCommand_CharUnDisguise, // Kalaspuff
- AtCommand_EMail, // by Yor
- AtCommand_Hatch,
- AtCommand_Effect, // by Apple
- AtCommand_Char_Item_List, // by Yor
- AtCommand_Char_Storage_List, // by Yor
- AtCommand_Char_Cart_List, // by Yor
- AtCommand_AddWarp, // by MouseJstr
- AtCommand_Follow, // by MouseJstr
- AtCommand_SkillOn, // by MouseJstr
- AtCommand_SkillOff, // by MouseJstr
- AtCommand_Killer, // by MouseJstr
- AtCommand_NpcMove, // by MouseJstr
- AtCommand_Killable, // by MouseJstr
- AtCommand_CharKillable, // by MouseJstr
- AtCommand_Chareffect, // by MouseJstr
- AtCommand_Chardye, // by MouseJstr
- AtCommand_Charhairstyle, // by MouseJstr
- AtCommand_Charhaircolor, // by MouseJstr
- AtCommand_Dropall, // by MouseJstr
- AtCommand_Chardropall, // by MouseJstr
- AtCommand_Storeall, // by MouseJstr
- AtCommand_Charstoreall, // by MouseJstr
- AtCommand_Skillid, // by MouseJstr
- AtCommand_Useskill, // by MouseJstr
- AtCommand_Summon,
- AtCommand_Rain,
- AtCommand_Snow,
- AtCommand_Sakura,
- AtCommand_Fog,
- AtCommand_Leaves,
- AtCommand_AdjGmLvl,
- AtCommand_AdjCmdLvl,
- AtCommand_Trade,
- AtCommand_UnMute,
- AtCommand_CharWipe,
- AtCommand_SetMagic,
- AtCommand_MagicInfo,
- AtCommand_Log,
- AtCommand_Tee,
- AtCommand_Invisible,
- AtCommand_Visible,
- AtCommand_IterateForward,
- AtCommand_IterateBackward,
- AtCommand_Wgm,
- AtCommand_IpCheck,
- AtCommand_ListNearby, // [fate]
- AtCommand_DoomSpot,
- // end
- AtCommand_Unknown,
- AtCommand_MAX
-};
+bool is_atcommand(const int fd, struct map_session_data *sd,
+ const char *message, int gmlvl);
-typedef enum AtCommandType AtCommandType;
+int atcommand_config_read(const char *cfgName);
-typedef struct AtCommandInfo
-{
- AtCommandType type;
- const char *command;
- int level;
- int (*proc) (const int, struct map_session_data *,
- const char *command, const char *message);
-} AtCommandInfo;
+void log_atcommand(struct map_session_data *sd, const_string cmd);
-AtCommandType is_atcommand (const int fd, struct map_session_data *sd,
- const char *message, int gmlvl);
+// only used by map.cpp
+extern char *gm_logfile_name;
-AtCommandType atcommand (const int level, const char *message,
- AtCommandInfo * info);
-int get_atcommand_level (const AtCommandType type);
-
-int atcommand_item (const int fd, struct map_session_data *sd, const char *command, const char *message); // [Valaris]
-int atcommand_warp (const int fd, struct map_session_data *sd, const char *command, const char *message); // [Yor]
-int atcommand_spawn (const int fd, struct map_session_data *sd, const char *command, const char *message); // [Valaris]
-int atcommand_goto (const int fd, struct map_session_data *sd, const char *command, const char *message); // [Yor]
-int atcommand_recall (const int fd, struct map_session_data *sd, const char *command, const char *message); // [Yor]
-
-int atcommand_config_read (const char *cfgName);
-
-__attribute__((format(printf, 2, 3)))
-void log_atcommand (struct map_session_data *sd, const char *fmt, ...);
-__attribute__((format(printf, 1, 2)))
-void gm_log (const char *fmt, ...);
-
-#endif
+#endif // ATCOMMAND_HPP
diff --git a/src/map/battle.cpp b/src/map/battle.cpp
index a636af4..97edeb3 100644
--- a/src/map/battle.cpp
+++ b/src/map/battle.cpp
@@ -1,60 +1,39 @@
-// $Id: battle.c,v 1.10 2004/09/29 21:08:17 Akitasha Exp $
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <math.h>
-
#include "battle.hpp"
-#include "../common/timer.hpp"
+#include <cstring>
+
+#include <fstream>
+
+#include "../common/cxxstdio.hpp"
+#include "../common/random.hpp"
#include "../common/nullpo.hpp"
#include "clif.hpp"
-#include "guild.hpp"
#include "itemdb.hpp"
#include "map.hpp"
#include "mob.hpp"
#include "pc.hpp"
#include "skill.hpp"
-#include "../common/socket.hpp"
-#include "../common/mt_rand.hpp"
-#ifdef MEMWATCH
-#include "memwatch.hpp"
-#endif
-
-int attr_fix_table[4][10][10];
+#include "../poison.hpp"
struct Battle_Config battle_config;
/*==========================================
- * 二点間ã®è·é›¢ã‚’è¿”ã™
- * 戻りã¯æ•´æ•°ã§0以上
- *------------------------------------------
- */
-static int distance (int x0, int y0, int x1, int y1)
-{
- int dx, dy;
-
- dx = abs (x0 - x1);
- dy = abs (y0 - y1);
- return dx > dy ? dx : dy;
-}
-
-/*==========================================
* 自分をロックã—ã¦ã„る対象ã®æ•°ã‚’è¿”ã™(汎用)
* 戻りã¯æ•´æ•°ã§0以上
*------------------------------------------
*/
-int battle_counttargeted (struct block_list *bl, struct block_list *src,
- int target_lv)
+static
+int battle_counttargeted(struct block_list *bl, struct block_list *src,
+ ATK target_lv)
{
- nullpo_retr (0, bl);
- if (bl->type == BL_PC)
- return pc_counttargeted ((struct map_session_data *) bl, src,
+ nullpo_ret(bl);
+ if (bl->type == BL::PC)
+ return pc_counttargeted((struct map_session_data *) bl, src,
target_lv);
- else if (bl->type == BL_MOB)
- return mob_counttargeted ((struct mob_data *) bl, src, target_lv);
+ else if (bl->type == BL::MOB)
+ return mob_counttargeted((struct mob_data *) bl, src, target_lv);
return 0;
}
@@ -63,13 +42,13 @@ int battle_counttargeted (struct block_list *bl, struct block_list *src,
* 戻りã¯æ•´æ•°ã§0以上
*------------------------------------------
*/
-int battle_get_class (struct block_list *bl)
+int battle_get_class(struct block_list *bl)
{
- nullpo_retr (0, bl);
- if (bl->type == BL_MOB && (struct mob_data *) bl)
+ nullpo_ret(bl);
+ if (bl->type == BL::MOB)
return ((struct mob_data *) bl)->mob_class;
- else if (bl->type == BL_PC && (struct map_session_data *) bl)
- return ((struct map_session_data *) bl)->status.pc_class;
+ else if (bl->type == BL::PC)
+ return 0;
else
return 0;
}
@@ -79,15 +58,15 @@ int battle_get_class (struct block_list *bl)
* 戻りã¯æ•´æ•°ã§0以上
*------------------------------------------
*/
-int battle_get_dir (struct block_list *bl)
+DIR battle_get_dir(struct block_list *bl)
{
- nullpo_retr (0, bl);
- if (bl->type == BL_MOB && (struct mob_data *) bl)
+ nullpo_retr(DIR::S, bl);
+ if (bl->type == BL::MOB)
return ((struct mob_data *) bl)->dir;
- else if (bl->type == BL_PC && (struct map_session_data *) bl)
+ else if (bl->type == BL::PC)
return ((struct map_session_data *) bl)->dir;
else
- return 0;
+ return DIR::S;
}
/*==========================================
@@ -95,12 +74,12 @@ int battle_get_dir (struct block_list *bl)
* 戻りã¯æ•´æ•°ã§0以上
*------------------------------------------
*/
-int battle_get_lv (struct block_list *bl)
+int battle_get_lv(struct block_list *bl)
{
- nullpo_retr (0, bl);
- if (bl->type == BL_MOB && (struct mob_data *) bl)
- return ((struct mob_data *) bl)->stats[MOB_LV];
- else if (bl->type == BL_PC && (struct map_session_data *) bl)
+ nullpo_ret(bl);
+ if (bl->type == BL::MOB)
+ return ((struct mob_data *) bl)->stats[mob_stat::LV];
+ else if (bl->type == BL::PC)
return ((struct map_session_data *) bl)->status.base_level;
else
return 0;
@@ -111,12 +90,12 @@ int battle_get_lv (struct block_list *bl)
* 戻りã¯æ•´æ•°ã§0以上
*------------------------------------------
*/
-int battle_get_range (struct block_list *bl)
+int battle_get_range(struct block_list *bl)
{
- nullpo_retr (0, bl);
- if (bl->type == BL_MOB && (struct mob_data *) bl)
+ nullpo_ret(bl);
+ if (bl->type == BL::MOB)
return mob_db[((struct mob_data *) bl)->mob_class].range;
- else if (bl->type == BL_PC && (struct map_session_data *) bl)
+ else if (bl->type == BL::PC)
return ((struct map_session_data *) bl)->attackrange;
else
return 0;
@@ -127,12 +106,12 @@ int battle_get_range (struct block_list *bl)
* 戻りã¯æ•´æ•°ã§0以上
*------------------------------------------
*/
-int battle_get_hp (struct block_list *bl)
+int battle_get_hp(struct block_list *bl)
{
- nullpo_retr (1, bl);
- if (bl->type == BL_MOB && (struct mob_data *) bl)
+ nullpo_retr(1, bl);
+ if (bl->type == BL::MOB)
return ((struct mob_data *) bl)->hp;
- else if (bl->type == BL_PC && (struct map_session_data *) bl)
+ else if (bl->type == BL::PC)
return ((struct map_session_data *) bl)->status.hp;
else
return 1;
@@ -143,42 +122,26 @@ int battle_get_hp (struct block_list *bl)
* 戻りã¯æ•´æ•°ã§0以上
*------------------------------------------
*/
-int battle_get_max_hp (struct block_list *bl)
+int battle_get_max_hp(struct block_list *bl)
{
- nullpo_retr (1, bl);
- if (bl->type == BL_PC && ((struct map_session_data *) bl))
+ nullpo_retr(1, bl);
+ if (bl->type == BL::PC && ((struct map_session_data *) bl))
return ((struct map_session_data *) bl)->status.max_hp;
else
{
- struct status_change *sc_data = battle_get_sc_data (bl);
- int max_hp = 1;
- if (bl->type == BL_MOB && ((struct mob_data *) bl))
+ int max_hp = 1;
+ if (bl->type == BL::MOB && ((struct mob_data *) bl))
{
- max_hp = ((struct mob_data *) bl)->stats[MOB_MAX_HP];
- if (mob_db[((struct mob_data *) bl)->mob_class].mexp > 0)
- {
- if (battle_config.mvp_hp_rate != 100)
- max_hp = (max_hp * battle_config.mvp_hp_rate) / 100;
- }
- else
+ max_hp = ((struct mob_data *) bl)->stats[mob_stat::MAX_HP];
{
if (battle_config.monster_hp_rate != 100)
max_hp = (max_hp * battle_config.monster_hp_rate) / 100;
}
}
- if (sc_data)
- {
- if (sc_data[SC_APPLEIDUN].timer != -1)
- max_hp +=
- ((5 + sc_data[SC_APPLEIDUN].val1 * 2 +
- ((sc_data[SC_APPLEIDUN].val2 + 1) >> 1) +
- sc_data[SC_APPLEIDUN].val3 / 10) * max_hp) / 100;
- }
if (max_hp < 1)
max_hp = 1;
return max_hp;
}
- return 1;
}
/*==========================================
@@ -186,35 +149,18 @@ int battle_get_max_hp (struct block_list *bl)
* 戻りã¯æ•´æ•°ã§0以上
*------------------------------------------
*/
-int battle_get_str (struct block_list *bl)
+int battle_get_str(struct block_list *bl)
{
- int str = 0;
- struct status_change *sc_data;
+ int str = 0;
+ eptr<struct status_change, StatusChange> sc_data;
- nullpo_retr (0, bl);
- sc_data = battle_get_sc_data (bl);
- if (bl->type == BL_MOB && ((struct mob_data *) bl))
- str = ((struct mob_data *) bl)->stats[MOB_STR];
- else if (bl->type == BL_PC && ((struct map_session_data *) bl))
- return ((struct map_session_data *) bl)->paramc[0];
+ nullpo_ret(bl);
+ sc_data = battle_get_sc_data(bl);
+ if (bl->type == BL::MOB && ((struct mob_data *) bl))
+ str = ((struct mob_data *) bl)->stats[mob_stat::STR];
+ else if (bl->type == BL::PC && ((struct map_session_data *) bl))
+ return ((struct map_session_data *) bl)->paramc[ATTR::STR];
- if (sc_data)
- {
- if (sc_data[SC_LOUD].timer != -1 && sc_data[SC_QUAGMIRE].timer == -1
- && bl->type != BL_PC)
- str += 4;
- if (sc_data[SC_BLESSING].timer != -1 && bl->type != BL_PC)
- { // ブレッシング
- int race = battle_get_race (bl);
- if (battle_check_undead (race, battle_get_elem_type (bl))
- || race == 6)
- str >>= 1; // 悪 é­”/ä¸æ­»
- else
- str += sc_data[SC_BLESSING].val1; // ãã®ä»–
- }
- if (sc_data[SC_TRUESIGHT].timer != -1 && bl->type != BL_PC) // トゥルーサイト
- str += 5;
- }
if (str < 0)
str = 0;
return str;
@@ -226,35 +172,18 @@ int battle_get_str (struct block_list *bl)
*------------------------------------------
*/
-int battle_get_agi (struct block_list *bl)
+int battle_get_agi(struct block_list *bl)
{
- int agi = 0;
- struct status_change *sc_data;
-
- nullpo_retr (0, bl);
- sc_data = battle_get_sc_data (bl);
- if (bl->type == BL_MOB && (struct mob_data *) bl)
- agi = ((struct mob_data *) bl)->stats[MOB_AGI];
- else if (bl->type == BL_PC && (struct map_session_data *) bl)
- agi = ((struct map_session_data *) bl)->paramc[1];
-
- if (sc_data)
- {
- if (sc_data[SC_INCREASEAGI].timer != -1 && sc_data[SC_QUAGMIRE].timer == -1 && sc_data[SC_DONTFORGETME].timer == -1 && bl->type != BL_PC) // 速度増加(PCã¯pc.cã§)
- agi += 2 + sc_data[SC_INCREASEAGI].val1;
-
- if (sc_data[SC_CONCENTRATE].timer != -1
- && sc_data[SC_QUAGMIRE].timer == -1 && bl->type != BL_PC)
- agi += agi * (2 + sc_data[SC_CONCENTRATE].val1) / 100;
+ int agi = 0;
+ eptr<struct status_change, StatusChange> sc_data;
- if (sc_data[SC_DECREASEAGI].timer != -1) // 速度減少
- agi -= 2 + sc_data[SC_DECREASEAGI].val1;
+ nullpo_ret(bl);
+ sc_data = battle_get_sc_data(bl);
+ if (bl->type == BL::MOB)
+ agi = ((struct mob_data *) bl)->stats[mob_stat::AGI];
+ else if (bl->type == BL::PC)
+ agi = ((struct map_session_data *) bl)->paramc[ATTR::AGI];
- if (sc_data[SC_QUAGMIRE].timer != -1) // クァグマイア
- agi >>= 1;
- if (sc_data[SC_TRUESIGHT].timer != -1 && bl->type != BL_PC) // トゥルーサイト
- agi += 5;
- }
if (agi < 0)
agi = 0;
return agi;
@@ -265,24 +194,17 @@ int battle_get_agi (struct block_list *bl)
* 戻りã¯æ•´æ•°ã§0以上
*------------------------------------------
*/
-int battle_get_vit (struct block_list *bl)
+int battle_get_vit(struct block_list *bl)
{
- int vit = 0;
- struct status_change *sc_data;
-
- nullpo_retr (0, bl);
- sc_data = battle_get_sc_data (bl);
- if (bl->type == BL_MOB && (struct mob_data *) bl)
- vit = ((struct mob_data *) bl)->stats[MOB_VIT];
- else if (bl->type == BL_PC && (struct map_session_data *) bl)
- vit = ((struct map_session_data *) bl)->paramc[2];
- if (sc_data)
- {
- if (sc_data[SC_STRIPARMOR].timer != -1 && bl->type != BL_PC)
- vit = vit * 60 / 100;
- if (sc_data[SC_TRUESIGHT].timer != -1 && bl->type != BL_PC) // トゥルーサイト
- vit += 5;
- }
+ int vit = 0;
+ eptr<struct status_change, StatusChange> sc_data;
+
+ nullpo_ret(bl);
+ sc_data = battle_get_sc_data(bl);
+ if (bl->type == BL::MOB)
+ vit = ((struct mob_data *) bl)->stats[mob_stat::VIT];
+ else if (bl->type == BL::PC)
+ vit = ((struct map_session_data *) bl)->paramc[ATTR::VIT];
if (vit < 0)
vit = 0;
@@ -294,34 +216,18 @@ int battle_get_vit (struct block_list *bl)
* 戻りã¯æ•´æ•°ã§0以上
*------------------------------------------
*/
-int battle_get_int (struct block_list *bl)
+int battle_get_int(struct block_list *bl)
{
- int int_ = 0;
- struct status_change *sc_data;
+ int int_ = 0;
+ eptr<struct status_change, StatusChange> sc_data;
- nullpo_retr (0, bl);
- sc_data = battle_get_sc_data (bl);
- if (bl->type == BL_MOB && (struct mob_data *) bl)
- int_ = ((struct mob_data *) bl)->stats[MOB_INT];
- else if (bl->type == BL_PC && (struct map_session_data *) bl)
- int_ = ((struct map_session_data *) bl)->paramc[3];
+ nullpo_ret(bl);
+ sc_data = battle_get_sc_data(bl);
+ if (bl->type == BL::MOB)
+ int_ = ((struct mob_data *) bl)->stats[mob_stat::INT];
+ else if (bl->type == BL::PC)
+ int_ = ((struct map_session_data *) bl)->paramc[ATTR::INT];
- if (sc_data)
- {
- if (sc_data[SC_BLESSING].timer != -1 && bl->type != BL_PC)
- { // ブレッシング
- int race = battle_get_race (bl);
- if (battle_check_undead (race, battle_get_elem_type (bl))
- || race == 6)
- int_ >>= 1; // 悪 é­”/ä¸æ­»
- else
- int_ += sc_data[SC_BLESSING].val1; // ãã®ä»–
- }
- if (sc_data[SC_STRIPHELM].timer != -1 && bl->type != BL_PC)
- int_ = int_ * 60 / 100;
- if (sc_data[SC_TRUESIGHT].timer != -1 && bl->type != BL_PC) // トゥルーサイト
- int_ += 5;
- }
if (int_ < 0)
int_ = 0;
return int_;
@@ -332,39 +238,18 @@ int battle_get_int (struct block_list *bl)
* 戻りã¯æ•´æ•°ã§0以上
*------------------------------------------
*/
-int battle_get_dex (struct block_list *bl)
+int battle_get_dex(struct block_list *bl)
{
- int dex = 0;
- struct status_change *sc_data;
+ int dex = 0;
+ eptr<struct status_change, StatusChange> sc_data;
- nullpo_retr (0, bl);
- sc_data = battle_get_sc_data (bl);
- if (bl->type == BL_MOB && (struct mob_data *) bl)
- dex = ((struct mob_data *) bl)->stats[MOB_DEX];
- else if (bl->type == BL_PC && (struct map_session_data *) bl)
- dex = ((struct map_session_data *) bl)->paramc[4];
+ nullpo_ret(bl);
+ sc_data = battle_get_sc_data(bl);
+ if (bl->type == BL::MOB)
+ dex = ((struct mob_data *) bl)->stats[mob_stat::DEX];
+ else if (bl->type == BL::PC)
+ dex = ((struct map_session_data *) bl)->paramc[ATTR::DEX];
- if (sc_data)
- {
- if (sc_data[SC_CONCENTRATE].timer != -1
- && sc_data[SC_QUAGMIRE].timer == -1 && bl->type != BL_PC)
- dex += dex * (2 + sc_data[SC_CONCENTRATE].val1) / 100;
-
- if (sc_data[SC_BLESSING].timer != -1 && bl->type != BL_PC)
- { // ブレッシング
- int race = battle_get_race (bl);
- if (battle_check_undead (race, battle_get_elem_type (bl))
- || race == 6)
- dex >>= 1; // 悪 é­”/ä¸æ­»
- else
- dex += sc_data[SC_BLESSING].val1; // ãã®ä»–
- }
-
- if (sc_data[SC_QUAGMIRE].timer != -1) // クァグマイア
- dex >>= 1;
- if (sc_data[SC_TRUESIGHT].timer != -1 && bl->type != BL_PC) // トゥルーサイト
- dex += 5;
- }
if (dex < 0)
dex = 0;
return dex;
@@ -375,27 +260,18 @@ int battle_get_dex (struct block_list *bl)
* 戻りã¯æ•´æ•°ã§0以上
*------------------------------------------
*/
-int battle_get_luk (struct block_list *bl)
+int battle_get_luk(struct block_list *bl)
{
- int luk = 0;
- struct status_change *sc_data;
+ int luk = 0;
+ eptr<struct status_change, StatusChange> sc_data;
- nullpo_retr (0, bl);
- sc_data = battle_get_sc_data (bl);
- if (bl->type == BL_MOB && (struct mob_data *) bl)
- luk = ((struct mob_data *) bl)->stats[MOB_LUK];
- else if (bl->type == BL_PC && (struct map_session_data *) bl)
- luk = ((struct map_session_data *) bl)->paramc[5];
+ nullpo_ret(bl);
+ sc_data = battle_get_sc_data(bl);
+ if (bl->type == BL::MOB)
+ luk = ((struct mob_data *) bl)->stats[mob_stat::LUK];
+ else if (bl->type == BL::PC)
+ luk = ((struct map_session_data *) bl)->paramc[ATTR::LUK];
- if (sc_data)
- {
- if (sc_data[SC_GLORIA].timer != -1 && bl->type != BL_PC) // グロリア(PCã¯pc.cã§)
- luk += 30;
- if (sc_data[SC_CURSE].timer != -1) // 呪ã„
- luk = 0;
- if (sc_data[SC_TRUESIGHT].timer != -1 && bl->type != BL_PC) // トゥルーサイト
- luk += 5;
- }
if (luk < 0)
luk = 0;
return luk;
@@ -406,34 +282,24 @@ int battle_get_luk (struct block_list *bl)
* 戻りã¯æ•´æ•°ã§1以上
*------------------------------------------
*/
-int battle_get_flee (struct block_list *bl)
+static
+int battle_get_flee(struct block_list *bl)
{
- int flee = 1;
- struct status_change *sc_data;
+ int flee = 1;
+ eptr<struct status_change, StatusChange> sc_data;
- nullpo_retr (1, bl);
- sc_data = battle_get_sc_data (bl);
- if (bl->type == BL_PC && (struct map_session_data *) bl)
+ nullpo_retr(1, bl);
+ sc_data = battle_get_sc_data(bl);
+ if (bl->type == BL::PC)
flee = ((struct map_session_data *) bl)->flee;
else
- flee = battle_get_agi (bl) + battle_get_lv (bl);
+ flee = battle_get_agi(bl) + battle_get_lv(bl);
if (sc_data)
{
- if (sc_data[SC_WHISTLE].timer != -1 && bl->type != BL_PC)
- flee +=
- flee * (sc_data[SC_WHISTLE].val1 + sc_data[SC_WHISTLE].val2 +
- (sc_data[SC_WHISTLE].val3 >> 16)) / 100;
- if (sc_data[SC_BLIND].timer != -1 && bl->type != BL_PC)
- flee -= flee * 25 / 100;
- if (sc_data[SC_WINDWALK].timer != -1 && bl->type != BL_PC) // ウィンドウォーク
- flee += flee * (sc_data[SC_WINDWALK].val2) / 100;
- if (sc_data[SC_SPIDERWEB].timer != -1 && bl->type != BL_PC) //スパイダーウェブ
- flee -= flee * 50 / 100;
-
- if (battle_is_unarmed (bl))
- flee += (skill_power_bl (bl, TMW_BRAWLING) >> 3); // +25 for 200
- flee += skill_power_bl (bl, TMW_SPEED) >> 3;
+ if (battle_is_unarmed(bl))
+ flee += (skill_power_bl(bl, SkillID::TMW_BRAWLING) >> 3); // +25 for 200
+ flee += skill_power_bl(bl, SkillID::TMW_SPEED) >> 3;
}
if (flee < 1)
flee = 1;
@@ -445,34 +311,23 @@ int battle_get_flee (struct block_list *bl)
* 戻りã¯æ•´æ•°ã§1以上
*------------------------------------------
*/
-int battle_get_hit (struct block_list *bl)
+static
+int battle_get_hit(struct block_list *bl)
{
- int hit = 1;
- struct status_change *sc_data;
+ int hit = 1;
+ eptr<struct status_change, StatusChange> sc_data;
- nullpo_retr (1, bl);
- sc_data = battle_get_sc_data (bl);
- if (bl->type == BL_PC && (struct map_session_data *) bl)
+ nullpo_retr(1, bl);
+ sc_data = battle_get_sc_data(bl);
+ if (bl->type == BL::PC)
hit = ((struct map_session_data *) bl)->hit;
else
- hit = battle_get_dex (bl) + battle_get_lv (bl);
+ hit = battle_get_dex(bl) + battle_get_lv(bl);
if (sc_data)
{
- if (sc_data[SC_HUMMING].timer != -1 && bl->type != BL_PC) //
- hit +=
- hit * (sc_data[SC_HUMMING].val1 * 2 +
- sc_data[SC_HUMMING].val2 +
- sc_data[SC_HUMMING].val3) / 100;
- if (sc_data[SC_BLIND].timer != -1 && bl->type != BL_PC) // 呪ã„
- hit -= hit * 25 / 100;
- if (sc_data[SC_TRUESIGHT].timer != -1 && bl->type != BL_PC) // トゥルーサイト
- hit += 3 * (sc_data[SC_TRUESIGHT].val1);
- if (sc_data[SC_CONCENTRATION].timer != -1 && bl->type != BL_PC) //コンセントレーション
- hit += (hit * (10 * (sc_data[SC_CONCENTRATION].val1))) / 100;
-
- if (battle_is_unarmed (bl))
- hit += (skill_power_bl (bl, TMW_BRAWLING) >> 4); // +12 for 200
+ if (battle_is_unarmed(bl))
+ hit += (skill_power_bl(bl, SkillID::TMW_BRAWLING) >> 4); // +12 for 200
}
if (hit < 1)
hit = 1;
@@ -484,32 +339,28 @@ int battle_get_hit (struct block_list *bl)
* 戻りã¯æ•´æ•°ã§1以上
*------------------------------------------
*/
-int battle_get_flee2 (struct block_list *bl)
+static
+int battle_get_flee2(struct block_list *bl)
{
- int flee2 = 1;
- struct status_change *sc_data;
+ int flee2 = 1;
+ eptr<struct status_change, StatusChange> sc_data;
- nullpo_retr (1, bl);
- sc_data = battle_get_sc_data (bl);
- if (bl->type == BL_PC && (struct map_session_data *) bl)
+ nullpo_retr(1, bl);
+ sc_data = battle_get_sc_data(bl);
+ if (bl->type == BL::PC)
{
- flee2 = battle_get_luk (bl) + 10;
+ flee2 = battle_get_luk(bl) + 10;
flee2 +=
((struct map_session_data *) bl)->flee2 -
- (((struct map_session_data *) bl)->paramc[5] + 10);
+ (((struct map_session_data *) bl)->paramc[ATTR::LUK] + 10);
}
else
- flee2 = battle_get_luk (bl) + 1;
+ flee2 = battle_get_luk(bl) + 1;
- if (sc_data)
{
- if (sc_data[SC_WHISTLE].timer != -1 && bl->type != BL_PC)
- flee2 += (sc_data[SC_WHISTLE].val1 + sc_data[SC_WHISTLE].val2
- + (sc_data[SC_WHISTLE].val3 & 0xffff)) * 10;
-
- if (battle_is_unarmed (bl))
- flee2 += (skill_power_bl (bl, TMW_BRAWLING) >> 3); // +25 for 200
- flee2 += skill_power_bl (bl, TMW_SPEED) >> 3;
+ if (battle_is_unarmed(bl))
+ flee2 += (skill_power_bl(bl, SkillID::TMW_BRAWLING) >> 3); // +25 for 200
+ flee2 += skill_power_bl(bl, SkillID::TMW_SPEED) >> 3;
}
if (flee2 < 1)
flee2 = 1;
@@ -522,34 +373,23 @@ int battle_get_flee2 (struct block_list *bl)
*------------------------------------------
*/
static
-int battle_get_critical (struct block_list *bl)
+int battle_get_critical(struct block_list *bl)
{
- int critical = 1;
- struct status_change *sc_data;
+ int critical = 1;
+ eptr<struct status_change, StatusChange> sc_data;
- nullpo_retr (1, bl);
- sc_data = battle_get_sc_data (bl);
- if (bl->type == BL_PC && (struct map_session_data *) bl)
+ nullpo_retr(1, bl);
+ sc_data = battle_get_sc_data(bl);
+ if (bl->type == BL::PC)
{
- critical = battle_get_luk (bl) * 2 + 10;
+ critical = battle_get_luk(bl) * 2 + 10;
critical +=
((struct map_session_data *) bl)->critical -
- ((((struct map_session_data *) bl)->paramc[5] * 3) + 10);
+ ((((struct map_session_data *) bl)->paramc[ATTR::LUK] * 3) + 10);
}
else
- critical = battle_get_luk (bl) * 3 + 1;
+ critical = battle_get_luk(bl) * 3 + 1;
- if (sc_data)
- {
- if (sc_data[SC_FORTUNE].timer != -1 && bl->type != BL_PC)
- critical +=
- (10 + sc_data[SC_FORTUNE].val1 + sc_data[SC_FORTUNE].val2 +
- sc_data[SC_FORTUNE].val3) * 10;
- if (sc_data[SC_EXPLOSIONSPIRITS].timer != -1 && bl->type != BL_PC)
- critical += sc_data[SC_EXPLOSIONSPIRITS].val2;
- if (sc_data[SC_TRUESIGHT].timer != -1 && bl->type != BL_PC) //トゥルーサイト
- critical += critical * sc_data[SC_TRUESIGHT].val1 / 100;
- }
if (critical < 1)
critical = 1;
return critical;
@@ -560,31 +400,23 @@ int battle_get_critical (struct block_list *bl)
* 戻りã¯æ•´æ•°ã§1以上
*------------------------------------------
*/
-int battle_get_baseatk (struct block_list *bl)
+static
+int battle_get_baseatk(struct block_list *bl)
{
- struct status_change *sc_data;
- int batk = 1;
+ eptr<struct status_change, StatusChange> sc_data;
+ int batk = 1;
- nullpo_retr (1, bl);
- sc_data = battle_get_sc_data (bl);
- if (bl->type == BL_PC && (struct map_session_data *) bl)
+ nullpo_retr(1, bl);
+ sc_data = battle_get_sc_data(bl);
+ if (bl->type == BL::PC)
batk = ((struct map_session_data *) bl)->base_atk; //設定ã•ã‚Œã¦ã„ã‚‹base_atk
else
{ //ãれ以外ãªã‚‰
- int str, dstr;
- str = battle_get_str (bl); //STR
+ int str, dstr;
+ str = battle_get_str(bl); //STR
dstr = str / 10;
batk = dstr * dstr + str; //base_atkを計算ã™ã‚‹
}
- if (sc_data)
- { //状態異常ã‚ã‚Š
- if (sc_data[SC_PROVOKE].timer != -1 && bl->type != BL_PC) //PCã§ãƒ—ロボック(SM_PROVOKE)状態
- batk = batk * (100 + 2 * sc_data[SC_PROVOKE].val1) / 100; //base_atk増加
- if (sc_data[SC_CURSE].timer != -1) //呪ã‚ã‚Œã¦ã„ãŸã‚‰
- batk -= batk * 25 / 100; //base_atkãŒ25%減少
- if (sc_data[SC_CONCENTRATION].timer != -1 && bl->type != BL_PC) //コンセントレーション
- batk += batk * (5 * sc_data[SC_CONCENTRATION].val1) / 100;
- }
if (batk < 1)
batk = 1; //base_atkã¯æœ€ä½Žã§ã‚‚1
return batk;
@@ -595,27 +427,19 @@ int battle_get_baseatk (struct block_list *bl)
* 戻りã¯æ•´æ•°ã§0以上
*------------------------------------------
*/
-int battle_get_atk (struct block_list *bl)
+static
+int battle_get_atk(struct block_list *bl)
{
- struct status_change *sc_data;
- int atk = 0;
+ eptr<struct status_change, StatusChange> sc_data;
+ int atk = 0;
- nullpo_retr (0, bl);
- sc_data = battle_get_sc_data (bl);
- if (bl->type == BL_PC && (struct map_session_data *) bl)
+ nullpo_ret(bl);
+ sc_data = battle_get_sc_data(bl);
+ if (bl->type == BL::PC)
atk = ((struct map_session_data *) bl)->watk;
- else if (bl->type == BL_MOB && (struct mob_data *) bl)
- atk = ((struct mob_data *) bl)->stats[MOB_ATK1];
+ else if (bl->type == BL::MOB)
+ atk = ((struct mob_data *) bl)->stats[mob_stat::ATK1];
- if (sc_data)
- {
- if (sc_data[SC_PROVOKE].timer != -1 && bl->type != BL_PC)
- atk = atk * (100 + 2 * sc_data[SC_PROVOKE].val1) / 100;
- if (sc_data[SC_CURSE].timer != -1)
- atk -= atk * 25 / 100;
- if (sc_data[SC_CONCENTRATION].timer != -1 && bl->type != BL_PC) //コンセントレーション
- atk += atk * (5 * sc_data[SC_CONCENTRATION].val1) / 100;
- }
if (atk < 0)
atk = 0;
return atk;
@@ -627,17 +451,11 @@ int battle_get_atk (struct block_list *bl)
*------------------------------------------
*/
static
-int battle_get_atk_ (struct block_list *bl)
+int battle_get_atk_(struct block_list *bl)
{
- nullpo_retr (0, bl);
- if (bl->type == BL_PC && (struct map_session_data *) bl)
- {
- int atk = ((struct map_session_data *) bl)->watk_;
-
- if (((struct map_session_data *) bl)->sc_data[SC_CURSE].timer != -1)
- atk -= atk * 25 / 100;
- return atk;
- }
+ nullpo_ret(bl);
+ if (bl->type == BL::PC)
+ return ((struct map_session_data *) bl)->watk_;
else
return 0;
}
@@ -647,41 +465,22 @@ int battle_get_atk_ (struct block_list *bl)
* 戻りã¯æ•´æ•°ã§0以上
*------------------------------------------
*/
-int battle_get_atk2 (struct block_list *bl)
+static
+int battle_get_atk2(struct block_list *bl)
{
- nullpo_retr (0, bl);
- if (bl->type == BL_PC && (struct map_session_data *) bl)
+ nullpo_ret(bl);
+ if (bl->type == BL::PC)
return ((struct map_session_data *) bl)->watk2;
else
{
- struct status_change *sc_data = battle_get_sc_data (bl);
- int atk2 = 0;
- if (bl->type == BL_MOB && (struct mob_data *) bl)
- atk2 = ((struct mob_data *) bl)->stats[MOB_ATK2];
- if (sc_data)
- {
- if (sc_data[SC_IMPOSITIO].timer != -1)
- atk2 += sc_data[SC_IMPOSITIO].val1 * 5;
- if (sc_data[SC_PROVOKE].timer != -1)
- atk2 = atk2 * (100 + 2 * sc_data[SC_PROVOKE].val1) / 100;
- if (sc_data[SC_CURSE].timer != -1)
- atk2 -= atk2 * 25 / 100;
- if (sc_data[SC_DRUMBATTLE].timer != -1)
- atk2 += sc_data[SC_DRUMBATTLE].val2;
- if (sc_data[SC_NIBELUNGEN].timer != -1
- && (battle_get_element (bl) / 10) >= 8)
- atk2 += sc_data[SC_NIBELUNGEN].val2;
- if (sc_data[SC_STRIPWEAPON].timer != -1)
- atk2 = atk2 * 90 / 100;
- if (sc_data[SC_CONCENTRATION].timer != -1) //コンセントレーション
- atk2 += atk2 * (5 * sc_data[SC_CONCENTRATION].val1) / 100;
- }
+ int atk2 = 0;
+ if (bl->type == BL::MOB)
+ atk2 = ((struct mob_data *) bl)->stats[mob_stat::ATK2];
if (atk2 < 0)
atk2 = 0;
return atk2;
}
- return 0;
}
/*==========================================
@@ -690,10 +489,10 @@ int battle_get_atk2 (struct block_list *bl)
*------------------------------------------
*/
static
-int battle_get_atk_2 (struct block_list *bl)
+int battle_get_atk_2(struct block_list *bl)
{
- nullpo_retr (0, bl);
- if (bl->type == BL_PC)
+ nullpo_ret(bl);
+ if (bl->type == BL::PC)
return ((struct map_session_data *) bl)->watk_2;
else
return 0;
@@ -705,22 +504,19 @@ int battle_get_atk_2 (struct block_list *bl)
*------------------------------------------
*/
static
-int battle_get_matk1 (struct block_list *bl)
+int battle_get_matk1(struct block_list *bl)
{
- struct status_change *sc_data;
- nullpo_retr (0, bl);
- sc_data = battle_get_sc_data (bl);
- if (bl->type == BL_MOB)
+ eptr<struct status_change, StatusChange> sc_data;
+ nullpo_ret(bl);
+ sc_data = battle_get_sc_data(bl);
+ if (bl->type == BL::MOB)
{
- int matk, int_ = battle_get_int (bl);
+ int matk, int_ = battle_get_int(bl);
matk = int_ + (int_ / 5) * (int_ / 5);
- if (sc_data)
- if (sc_data[SC_MINDBREAKER].timer != -1 && bl->type != BL_PC)
- matk = matk * (100 + 2 * sc_data[SC_MINDBREAKER].val1) / 100;
return matk;
}
- else if (bl->type == BL_PC && (struct map_session_data *) bl)
+ else if (bl->type == BL::PC)
return ((struct map_session_data *) bl)->matk1;
else
return 0;
@@ -732,21 +528,17 @@ int battle_get_matk1 (struct block_list *bl)
*------------------------------------------
*/
static
-int battle_get_matk2 (struct block_list *bl)
+int battle_get_matk2(struct block_list *bl)
{
- struct status_change *sc_data = battle_get_sc_data (bl);
- nullpo_retr (0, bl);
- if (bl->type == BL_MOB)
+ nullpo_ret(bl);
+ if (bl->type == BL::MOB)
{
- int matk, int_ = battle_get_int (bl);
+ int matk, int_ = battle_get_int(bl);
matk = int_ + (int_ / 7) * (int_ / 7);
- if (sc_data)
- if (sc_data[SC_MINDBREAKER].timer != -1 && bl->type != BL_PC)
- matk = matk * (100 + 2 * sc_data[SC_MINDBREAKER].val1) / 100;
return matk;
}
- else if (bl->type == BL_PC && (struct map_session_data *) bl)
+ else if (bl->type == BL::PC)
return ((struct map_session_data *) bl)->matk2;
else
return 0;
@@ -757,67 +549,30 @@ int battle_get_matk2 (struct block_list *bl)
* 戻りã¯æ•´æ•°ã§0以上
*------------------------------------------
*/
-int battle_get_def (struct block_list *bl)
+int battle_get_def(struct block_list *bl)
{
- struct status_change *sc_data;
- int def = 0, skilltimer = -1, skillid = 0;
+ eptr<struct status_change, StatusChange> sc_data;
+ int def = 0;
- nullpo_retr (0, bl);
- sc_data = battle_get_sc_data (bl);
- if (bl->type == BL_PC && (struct map_session_data *) bl)
+ nullpo_ret(bl);
+ sc_data = battle_get_sc_data(bl);
+ if (bl->type == BL::PC)
{
def = ((struct map_session_data *) bl)->def;
- skilltimer = ((struct map_session_data *) bl)->skilltimer;
- skillid = ((struct map_session_data *) bl)->skillid;
}
- else if (bl->type == BL_MOB && (struct mob_data *) bl)
+ else if (bl->type == BL::MOB)
{
- def = ((struct mob_data *) bl)->stats[MOB_DEF];
- skilltimer = ((struct mob_data *) bl)->skilltimer;
- skillid = ((struct mob_data *) bl)->skillid;
+ def = ((struct mob_data *) bl)->stats[mob_stat::DEF];
}
if (def < 1000000)
{
if (sc_data)
{
- //キーピング時ã¯DEF100
- if (sc_data[SC_KEEPING].timer != -1)
- def = 100;
- //プロボック時ã¯æ¸›ç®—
- if (sc_data[SC_PROVOKE].timer != -1 && bl->type != BL_PC)
- def = (def * (100 - 6 * sc_data[SC_PROVOKE].val1) + 50) / 100;
- //戦太鼓ã®éŸ¿ã時ã¯åŠ ç®—
- if (sc_data[SC_DRUMBATTLE].timer != -1 && bl->type != BL_PC)
- def += sc_data[SC_DRUMBATTLE].val3;
//毒ã«ã‹ã‹ã£ã¦ã„る時ã¯æ¸›ç®—
- if (sc_data[SC_POISON].timer != -1 && bl->type != BL_PC)
+ if (sc_data[StatusChange::SC_POISON].timer
+ && bl->type != BL::PC)
def = def * 75 / 100;
- //ストリップシールド時ã¯æ¸›ç®—
- if (sc_data[SC_STRIPSHIELD].timer != -1 && bl->type != BL_PC)
- def = def * 85 / 100;
- //シグナムクルシス時ã¯æ¸›ç®—
- if (sc_data[SC_SIGNUMCRUCIS].timer != -1 && bl->type != BL_PC)
- def = def * (100 - sc_data[SC_SIGNUMCRUCIS].val2) / 100;
- //æ°¸é ã®æ··æ²Œæ™‚ã¯DEF0ã«ãªã‚‹
- if (sc_data[SC_ETERNALCHAOS].timer != -1 && bl->type != BL_PC)
- def = 0;
- //å‡çµã€çŸ³åŒ–時ã¯å³ã‚·ãƒ•ãƒˆ
- if (sc_data[SC_FREEZE].timer != -1
- || (sc_data[SC_STONE].timer != -1
- && sc_data[SC_STONE].val2 == 0))
- def >>= 1;
- //コンセントレーション時ã¯æ¸›ç®—
- if (sc_data[SC_CONCENTRATION].timer != -1 && bl->type != BL_PC)
- def =
- (def * (100 - 5 * sc_data[SC_CONCENTRATION].val1)) / 100;
- }
- //詠唱中ã¯è© å”±æ™‚減算率ã«åŸºã¥ã„ã¦æ¸›ç®—
- if (skilltimer != -1)
- {
- int def_rate = skill_get_castdef (skillid);
- if (def_rate != 0)
- def = (def * (100 - def_rate)) / 100;
}
}
if (def < 0)
@@ -830,38 +585,29 @@ int battle_get_def (struct block_list *bl)
* 戻りã¯æ•´æ•°ã§0以上
*------------------------------------------
*/
-int battle_get_mdef (struct block_list *bl)
+int battle_get_mdef(struct block_list *bl)
{
- struct status_change *sc_data;
- int mdef = 0;
+ eptr<struct status_change, StatusChange> sc_data;
+ int mdef = 0;
- nullpo_retr (0, bl);
- sc_data = battle_get_sc_data (bl);
- if (bl->type == BL_PC && (struct map_session_data *) bl)
+ nullpo_ret(bl);
+ sc_data = battle_get_sc_data(bl);
+ if (bl->type == BL::PC)
mdef = ((struct map_session_data *) bl)->mdef;
- else if (bl->type == BL_MOB && (struct mob_data *) bl)
- mdef = ((struct mob_data *) bl)->stats[MOB_MDEF];
+ else if (bl->type == BL::MOB)
+ mdef = ((struct mob_data *) bl)->stats[mob_stat::MDEF];
if (mdef < 1000000)
{
if (sc_data)
{
//ãƒãƒªã‚¢ãƒ¼çŠ¶æ…‹æ™‚ã¯MDEF100
- if (mdef < 90 && sc_data[SC_MBARRIER].timer != -1)
+ if (mdef < 90 && sc_data[StatusChange::SC_MBARRIER].timer)
{
- mdef += sc_data[SC_MBARRIER].val1;
+ mdef += sc_data[StatusChange::SC_MBARRIER].val1;
if (mdef > 90)
mdef = 90;
}
- if (sc_data[SC_BARRIER].timer != -1)
- mdef = 100;
- //å‡çµã€çŸ³åŒ–時ã¯1.25å€
- if (sc_data[SC_FREEZE].timer != -1
- || (sc_data[SC_STONE].timer != -1
- && sc_data[SC_STONE].val2 == 0))
- mdef = mdef * 125 / 100;
- if (sc_data[SC_MINDBREAKER].timer != -1 && bl->type != BL_PC)
- mdef -= (mdef * 6 * sc_data[SC_MINDBREAKER].val1) / 100;
}
}
if (mdef < 0)
@@ -874,29 +620,23 @@ int battle_get_mdef (struct block_list *bl)
* 戻りã¯æ•´æ•°ã§1以上
*------------------------------------------
*/
-int battle_get_def2 (struct block_list *bl)
+int battle_get_def2(struct block_list *bl)
{
- struct status_change *sc_data;
- int def2 = 1;
+ eptr<struct status_change, StatusChange> sc_data;
+ int def2 = 1;
- nullpo_retr (1, bl);
- sc_data = battle_get_sc_data (bl);
- if (bl->type == BL_PC)
+ nullpo_retr(1, bl);
+ sc_data = battle_get_sc_data(bl);
+ if (bl->type == BL::PC)
def2 = ((struct map_session_data *) bl)->def2;
- else if (bl->type == BL_MOB)
- def2 = ((struct mob_data *) bl)->stats[MOB_VIT];
+ else if (bl->type == BL::MOB)
+ def2 = ((struct mob_data *) bl)->stats[mob_stat::VIT];
if (sc_data)
{
- if (sc_data[SC_ANGELUS].timer != -1 && bl->type != BL_PC)
- def2 = def2 * (110 + 5 * sc_data[SC_ANGELUS].val1) / 100;
- if (sc_data[SC_PROVOKE].timer != -1 && bl->type != BL_PC)
- def2 = (def2 * (100 - 6 * sc_data[SC_PROVOKE].val1) + 50) / 100;
- if (sc_data[SC_POISON].timer != -1 && bl->type != BL_PC)
+ if (sc_data[StatusChange::SC_POISON].timer
+ && bl->type != BL::PC)
def2 = def2 * 75 / 100;
- //コンセントレーション時ã¯æ¸›ç®—
- if (sc_data[SC_CONCENTRATION].timer != -1 && bl->type != BL_PC)
- def2 = def2 * (100 - 5 * sc_data[SC_CONCENTRATION].val1) / 100;
}
if (def2 < 1)
def2 = 1;
@@ -908,25 +648,20 @@ int battle_get_def2 (struct block_list *bl)
* 戻りã¯æ•´æ•°ã§0以上
*------------------------------------------
*/
-int battle_get_mdef2 (struct block_list *bl)
+int battle_get_mdef2(struct block_list *bl)
{
- int mdef2 = 0;
- struct status_change *sc_data = battle_get_sc_data (bl);
+ int mdef2 = 0;
- nullpo_retr (0, bl);
- if (bl->type == BL_MOB)
+ nullpo_ret(bl);
+ if (bl->type == BL::MOB)
mdef2 =
- ((struct mob_data *) bl)->stats[MOB_INT] +
- (((struct mob_data *) bl)->stats[MOB_VIT] >> 1);
- else if (bl->type == BL_PC)
+ ((struct mob_data *) bl)->stats[mob_stat::INT] +
+ (((struct mob_data *) bl)->stats[mob_stat::VIT] >> 1);
+ else if (bl->type == BL::PC)
mdef2 =
((struct map_session_data *) bl)->mdef2 +
- (((struct map_session_data *) bl)->paramc[2] >> 1);
- if (sc_data)
- {
- if (sc_data[SC_MINDBREAKER].timer != -1 && bl->type != BL_PC)
- mdef2 -= (mdef2 * 6 * sc_data[SC_MINDBREAKER].val1) / 100;
- }
+ (((struct map_session_data *) bl)->paramc[ATTR::VIT] >> 1);
+
if (mdef2 < 0)
mdef2 = 0;
return mdef2;
@@ -938,58 +673,19 @@ int battle_get_mdef2 (struct block_list *bl)
* Speedã¯å°ã•ã„ã»ã†ãŒç§»å‹•é€Ÿåº¦ãŒé€Ÿã„
*------------------------------------------
*/
-int battle_get_speed (struct block_list *bl)
+interval_t battle_get_speed(struct block_list *bl)
{
- nullpo_retr (1000, bl);
- if (bl->type == BL_PC && (struct map_session_data *) bl)
+ nullpo_retr(std::chrono::seconds(1), bl);
+ if (bl->type == BL::PC)
return ((struct map_session_data *) bl)->speed;
else
{
- struct status_change *sc_data = battle_get_sc_data (bl);
- int speed = 1000;
- if (bl->type == BL_MOB && (struct mob_data *) bl)
- speed = ((struct mob_data *) bl)->stats[MOB_SPEED];
+ interval_t speed = std::chrono::seconds(1);
+ if (bl->type == BL::MOB)
+ speed = static_cast<interval_t>(((struct mob_data *) bl)->stats[mob_stat::SPEED]);
- if (sc_data)
- {
- //速度増加時ã¯25%減算
- if (sc_data[SC_INCREASEAGI].timer != -1
- && sc_data[SC_DONTFORGETME].timer == -1)
- speed -= speed * 25 / 100;
- //速度減少時ã¯25%加算
- if (sc_data[SC_DECREASEAGI].timer != -1)
- speed = speed * 125 / 100;
- //クァグマイア時ã¯50%加算
- if (sc_data[SC_QUAGMIRE].timer != -1)
- speed = speed * 3 / 2;
- //ç§ã‚’忘れãªã„ã§â€¦æ™‚ã¯åŠ ç®—
- if (sc_data[SC_DONTFORGETME].timer != -1)
- speed =
- speed * (100 + sc_data[SC_DONTFORGETME].val1 * 2 +
- sc_data[SC_DONTFORGETME].val2 +
- (sc_data[SC_DONTFORGETME].val3 & 0xffff)) / 100;
- //金剛時ã¯25%加算
- if (sc_data[SC_STEELBODY].timer != -1)
- speed = speed * 125 / 100;
- //ディフェンダー時ã¯åŠ ç®—
- if (sc_data[SC_DEFENDER].timer != -1)
- speed = (speed * (155 - sc_data[SC_DEFENDER].val1 * 5)) / 100;
- //踊り状態ã¯4å€é…ã„
- if (sc_data[SC_DANCING].timer != -1)
- speed *= 4;
- //呪ã„時ã¯450加算
- if (sc_data[SC_CURSE].timer != -1)
- speed = speed + 450;
- //ウィンドウォーク時ã¯Lv*2%減算
- if (sc_data[SC_WINDWALK].timer != -1)
- speed -= (speed * (sc_data[SC_WINDWALK].val1 * 2)) / 100;
- }
- if (speed < 1)
- speed = 1;
- return speed;
+ return std::max(speed, std::chrono::milliseconds(1));
}
-
- return 1000;
}
/*==========================================
@@ -997,423 +693,213 @@ int battle_get_speed (struct block_list *bl)
* aDelayã¯å°ã•ã„ã»ã†ãŒæ”»æ’ƒé€Ÿåº¦ãŒé€Ÿã„
*------------------------------------------
*/
-int battle_get_adelay (struct block_list *bl)
+// TODO figure out what all the doubling is about
+interval_t battle_get_adelay(struct block_list *bl)
{
- nullpo_retr (4000, bl);
- if (bl->type == BL_PC && (struct map_session_data *) bl)
- return (((struct map_session_data *) bl)->aspd << 1);
+ nullpo_retr(std::chrono::seconds(4), bl);
+ if (bl->type == BL::PC)
+ return ((struct map_session_data *) bl)->aspd * 2;
else
{
- struct status_change *sc_data = battle_get_sc_data (bl);
- int adelay = 4000, aspd_rate = 100, i;
- if (bl->type == BL_MOB && (struct mob_data *) bl)
- adelay = ((struct mob_data *) bl)->stats[MOB_ADELAY];
+ eptr<struct status_change, StatusChange> sc_data = battle_get_sc_data(bl);
+ interval_t adelay = std::chrono::seconds(4);
+ int aspd_rate = 100;
+ if (bl->type == BL::MOB)
+ adelay = static_cast<interval_t>(((struct mob_data *) bl)->stats[mob_stat::ADELAY]);
if (sc_data)
{
- //ツーãƒãƒ³ãƒ‰ã‚¯ã‚¤ãƒƒã‚±ãƒ³ä½¿ç”¨æ™‚ã§ã‚¯ã‚¡ã‚°ãƒžã‚¤ã‚¢ã§ã‚‚ç§ã‚’忘れãªã„ã§â€¦ã§ã‚‚ãªã„時ã¯3割減算
- if (sc_data[SC_TWOHANDQUICKEN].timer != -1 && sc_data[SC_QUAGMIRE].timer == -1 && sc_data[SC_DONTFORGETME].timer == -1) // 2HQ
- aspd_rate -= 30;
- //アドレナリンラッシュ使用時ã§ãƒ„ーãƒãƒ³ãƒ‰ã‚¯ã‚¤ãƒƒã‚±ãƒ³ã§ã‚‚クァグマイアã§ã‚‚ç§ã‚’忘れãªã„ã§â€¦ã§ã‚‚ãªã„時ã¯
- if (sc_data[SC_ADRENALINE].timer != -1
- && sc_data[SC_TWOHANDQUICKEN].timer == -1
- && sc_data[SC_QUAGMIRE].timer == -1
- && sc_data[SC_DONTFORGETME].timer == -1)
- { // アドレナリンラッシュ
- //使用者ã¨ãƒ‘ーティメンãƒãƒ¼ã§æ ¼å·®ãŒå‡ºã‚‹è¨­å®šã§ãªã‘ã‚Œã°3割減算
- if (sc_data[SC_ADRENALINE].val2
- || !battle_config.party_skill_penaly)
- aspd_rate -= 30;
- //ãã†ã§ãªã‘ã‚Œã°2.5割減算
- else
- aspd_rate -= 25;
- }
- //スピアクィッケン時ã¯æ¸›ç®—
- if (sc_data[SC_SPEARSQUICKEN].timer != -1 && sc_data[SC_ADRENALINE].timer == -1 && sc_data[SC_TWOHANDQUICKEN].timer == -1 && sc_data[SC_QUAGMIRE].timer == -1 && sc_data[SC_DONTFORGETME].timer == -1) // スピアクィッケン
- aspd_rate -= sc_data[SC_SPEARSQUICKEN].val2;
- //夕日ã®ã‚¢ã‚µã‚·ãƒ³ã‚¯ãƒ­ã‚¹æ™‚ã¯æ¸›ç®—
- if (sc_data[SC_ASSNCROS].timer != -1 && // 夕陽ã®ã‚¢ã‚µã‚·ãƒ³ã‚¯ãƒ­ã‚¹
- sc_data[SC_TWOHANDQUICKEN].timer == -1
- && sc_data[SC_ADRENALINE].timer == -1
- && sc_data[SC_SPEARSQUICKEN].timer == -1
- && sc_data[SC_DONTFORGETME].timer == -1)
- aspd_rate -=
- 5 + sc_data[SC_ASSNCROS].val1 +
- sc_data[SC_ASSNCROS].val2 + sc_data[SC_ASSNCROS].val3;
- //ç§ã‚’忘れãªã„ã§â€¦æ™‚ã¯åŠ ç®—
- if (sc_data[SC_DONTFORGETME].timer != -1) // ç§ã‚’忘れãªã„ã§
- aspd_rate +=
- sc_data[SC_DONTFORGETME].val1 * 3 +
- sc_data[SC_DONTFORGETME].val2 +
- (sc_data[SC_DONTFORGETME].val3 >> 16);
- //金剛時25%加算
- if (sc_data[SC_STEELBODY].timer != -1) // 金剛
- aspd_rate += 25;
- //増速ãƒãƒ¼ã‚·ãƒ§ãƒ³ä½¿ç”¨æ™‚ã¯æ¸›ç®—
- if (sc_data[i = SC_SPEEDPOTION2].timer != -1
- || sc_data[i = SC_SPEEDPOTION1].timer != -1
- || sc_data[i = SC_SPEEDPOTION0].timer != -1)
- aspd_rate -= sc_data[i].val1;
+ if (sc_data[StatusChange::SC_SPEEDPOTION0].timer)
+ aspd_rate -= sc_data[StatusChange::SC_SPEEDPOTION0].val1;
// Fate's `haste' spell works the same as the above
- if (sc_data[SC_HASTE].timer != -1)
- aspd_rate -= sc_data[SC_HASTE].val1;
- //ディフェンダー時ã¯åŠ ç®—
- if (sc_data[SC_DEFENDER].timer != -1)
- adelay += (1100 - sc_data[SC_DEFENDER].val1 * 100);
+ if (sc_data[StatusChange::SC_HASTE].timer)
+ aspd_rate -= sc_data[StatusChange::SC_HASTE].val1;
}
if (aspd_rate != 100)
adelay = adelay * aspd_rate / 100;
- if (adelay < battle_config.monster_max_aspd << 1)
- adelay = battle_config.monster_max_aspd << 1;
- return adelay;
+ return std::max(adelay, static_cast<interval_t>(battle_config.monster_max_aspd) * 2);
}
- return 4000;
}
-int battle_get_amotion (struct block_list *bl)
+interval_t battle_get_amotion(struct block_list *bl)
{
- nullpo_retr (2000, bl);
- if (bl->type == BL_PC && (struct map_session_data *) bl)
+ nullpo_retr(std::chrono::seconds(2), bl);
+ if (bl->type == BL::PC)
return ((struct map_session_data *) bl)->amotion;
else
{
- struct status_change *sc_data = battle_get_sc_data (bl);
- int amotion = 2000, aspd_rate = 100, i;
- if (bl->type == BL_MOB && (struct mob_data *) bl)
- amotion = mob_db[((struct mob_data *) bl)->mob_class].amotion;
+ eptr<struct status_change, StatusChange> sc_data = battle_get_sc_data(bl);
+ interval_t amotion = std::chrono::seconds(2);
+ int aspd_rate = 100;
+ if (bl->type == BL::MOB)
+ amotion = static_cast<interval_t>(mob_db[((struct mob_data *) bl)->mob_class].amotion);
if (sc_data)
{
- if (sc_data[SC_TWOHANDQUICKEN].timer != -1 && sc_data[SC_QUAGMIRE].timer == -1 && sc_data[SC_DONTFORGETME].timer == -1) // 2HQ
- aspd_rate -= 30;
- if (sc_data[SC_ADRENALINE].timer != -1
- && sc_data[SC_TWOHANDQUICKEN].timer == -1
- && sc_data[SC_QUAGMIRE].timer == -1
- && sc_data[SC_DONTFORGETME].timer == -1)
- { // アドレナリンラッシュ
- if (sc_data[SC_ADRENALINE].val2
- || !battle_config.party_skill_penaly)
- aspd_rate -= 30;
- else
- aspd_rate -= 25;
- }
- if (sc_data[SC_SPEARSQUICKEN].timer != -1 && sc_data[SC_ADRENALINE].timer == -1 && sc_data[SC_TWOHANDQUICKEN].timer == -1 && sc_data[SC_QUAGMIRE].timer == -1 && sc_data[SC_DONTFORGETME].timer == -1) // スピアクィッケン
- aspd_rate -= sc_data[SC_SPEARSQUICKEN].val2;
- if (sc_data[SC_ASSNCROS].timer != -1 && // 夕陽ã®ã‚¢ã‚µã‚·ãƒ³ã‚¯ãƒ­ã‚¹
- sc_data[SC_TWOHANDQUICKEN].timer == -1
- && sc_data[SC_ADRENALINE].timer == -1
- && sc_data[SC_SPEARSQUICKEN].timer == -1
- && sc_data[SC_DONTFORGETME].timer == -1)
- aspd_rate -=
- 5 + sc_data[SC_ASSNCROS].val1 +
- sc_data[SC_ASSNCROS].val2 + sc_data[SC_ASSNCROS].val3;
- if (sc_data[SC_DONTFORGETME].timer != -1) // ç§ã‚’忘れãªã„ã§
- aspd_rate +=
- sc_data[SC_DONTFORGETME].val1 * 3 +
- sc_data[SC_DONTFORGETME].val2 +
- (sc_data[SC_DONTFORGETME].val3 >> 16);
- if (sc_data[SC_STEELBODY].timer != -1) // 金剛
- aspd_rate += 25;
- if (sc_data[i = SC_SPEEDPOTION2].timer != -1
- || sc_data[i = SC_SPEEDPOTION1].timer != -1
- || sc_data[i = SC_SPEEDPOTION0].timer != -1)
- aspd_rate -= sc_data[i].val1;
- if (sc_data[SC_HASTE].timer != -1)
- aspd_rate -= sc_data[SC_HASTE].val1;
- if (sc_data[SC_DEFENDER].timer != -1)
- amotion += (550 - sc_data[SC_DEFENDER].val1 * 50);
+ if (sc_data[StatusChange::SC_SPEEDPOTION0].timer)
+ aspd_rate -= sc_data[StatusChange::SC_SPEEDPOTION0].val1;
+ if (sc_data[StatusChange::SC_HASTE].timer)
+ aspd_rate -= sc_data[StatusChange::SC_HASTE].val1;
}
if (aspd_rate != 100)
amotion = amotion * aspd_rate / 100;
- if (amotion < battle_config.monster_max_aspd)
- amotion = battle_config.monster_max_aspd;
- return amotion;
+ return std::max(amotion, static_cast<interval_t>(battle_config.monster_max_aspd));
}
- return 2000;
}
-int battle_get_dmotion (struct block_list *bl)
+interval_t battle_get_dmotion(struct block_list *bl)
{
- int ret;
- struct status_change *sc_data;
-
- nullpo_retr (0, bl);
- sc_data = battle_get_sc_data (bl);
- if (bl->type == BL_MOB && (struct mob_data *) bl)
+ nullpo_retr(interval_t::zero(), bl);
+ if (bl->type == BL::MOB)
{
- ret = mob_db[((struct mob_data *) bl)->mob_class].dmotion;
- if (battle_config.monster_damage_delay_rate != 100)
- ret = ret * battle_config.monster_damage_delay_rate / 400;
+ return static_cast<interval_t>(mob_db[((struct mob_data *) bl)->mob_class].dmotion);
}
- else if (bl->type == BL_PC && (struct map_session_data *) bl)
+ else if (bl->type == BL::PC)
{
- ret = ((struct map_session_data *) bl)->dmotion;
- if (battle_config.pc_damage_delay_rate != 100)
- ret = ret * battle_config.pc_damage_delay_rate / 400;
+ return ((struct map_session_data *) bl)->dmotion;
}
else
- return 2000;
-
- if ((sc_data && sc_data[SC_ENDURE].timer != -1) ||
- (bl->type == BL_PC
- && ((struct map_session_data *) bl)->special_state.infinite_endure))
- ret = 0;
-
- return ret;
+ return std::chrono::seconds(2);
}
-int battle_get_element (struct block_list *bl)
+LevelElement battle_get_element(struct block_list *bl)
{
- int ret = 20;
- struct status_change *sc_data;
+ LevelElement ret = {2, Element::neutral};
- nullpo_retr (ret, bl);
- sc_data = battle_get_sc_data (bl);
- if (bl->type == BL_MOB && (struct mob_data *) bl) // 10ã®ä½ï¼Lv*2ã€ï¼‘ã®ä½ï¼å±žæ€§
+ nullpo_retr(ret, bl);
+ if (bl->type == BL::MOB) // 10ã®ä½ï¼Lv*2ã€ï¼‘ã®ä½ï¼å±žæ€§
ret = ((struct mob_data *) bl)->def_ele;
- else if (bl->type == BL_PC && (struct map_session_data *) bl)
- ret = 20 + ((struct map_session_data *) bl)->def_ele; // 防御属性Lv1
-
- if (sc_data)
- {
- if (sc_data[SC_BENEDICTIO].timer != -1) // è–体é™ç¦
- ret = 26;
- if (sc_data[SC_FREEZE].timer != -1) // å‡çµ
- ret = 21;
- if (sc_data[SC_STONE].timer != -1 && sc_data[SC_STONE].val2 == 0)
- ret = 22;
- }
-
- return ret;
-}
-
-int battle_get_attack_element (struct block_list *bl)
-{
- int ret = 0;
- struct status_change *sc_data = battle_get_sc_data (bl);
-
- nullpo_retr (0, bl);
- if (bl->type == BL_MOB && (struct mob_data *) bl)
- ret = 0;
- else if (bl->type == BL_PC && (struct map_session_data *) bl)
- ret = ((struct map_session_data *) bl)->atk_ele;
-
- if (sc_data)
- {
- if (sc_data[SC_FROSTWEAPON].timer != -1) // フロストウェãƒãƒ³
- ret = 1;
- if (sc_data[SC_SEISMICWEAPON].timer != -1) // サイズミックウェãƒãƒ³
- ret = 2;
- if (sc_data[SC_FLAMELAUNCHER].timer != -1) // フレームランãƒãƒ£ãƒ¼
- ret = 3;
- if (sc_data[SC_LIGHTNINGLOADER].timer != -1) // ライトニングローダー
- ret = 4;
- if (sc_data[SC_ENCPOISON].timer != -1) // エンãƒãƒ£ãƒ³ãƒˆãƒã‚¤ã‚ºãƒ³
- ret = 5;
- if (sc_data[SC_ASPERSIO].timer != -1) // アスペルシオ
- ret = 6;
- }
return ret;
}
-int battle_get_attack_element2 (struct block_list *bl)
-{
- nullpo_retr (0, bl);
- if (bl->type == BL_PC && (struct map_session_data *) bl)
- {
- int ret = ((struct map_session_data *) bl)->atk_ele_;
- struct status_change *sc_data =
- ((struct map_session_data *) bl)->sc_data;
-
- if (sc_data)
- {
- if (sc_data[SC_FROSTWEAPON].timer != -1) // フロストウェãƒãƒ³
- ret = 1;
- if (sc_data[SC_SEISMICWEAPON].timer != -1) // サイズミックウェãƒãƒ³
- ret = 2;
- if (sc_data[SC_FLAMELAUNCHER].timer != -1) // フレームランãƒãƒ£ãƒ¼
- ret = 3;
- if (sc_data[SC_LIGHTNINGLOADER].timer != -1) // ライトニングローダー
- ret = 4;
- if (sc_data[SC_ENCPOISON].timer != -1) // エンãƒãƒ£ãƒ³ãƒˆãƒã‚¤ã‚ºãƒ³
- ret = 5;
- if (sc_data[SC_ASPERSIO].timer != -1) // アスペルシオ
- ret = 6;
- }
- return ret;
- }
- return 0;
-}
-
-int battle_get_party_id (struct block_list *bl)
+int battle_get_party_id(struct block_list *bl)
{
- nullpo_retr (0, bl);
- if (bl->type == BL_PC && (struct map_session_data *) bl)
+ nullpo_ret(bl);
+ if (bl->type == BL::PC)
return ((struct map_session_data *) bl)->status.party_id;
- else if (bl->type == BL_MOB && (struct mob_data *) bl)
+ else if (bl->type == BL::MOB)
{
struct mob_data *md = (struct mob_data *) bl;
if (md->master_id > 0)
return -md->master_id;
return -md->bl.id;
}
- else if (bl->type == BL_SKILL && (struct skill_unit *) bl)
- return ((struct skill_unit *) bl)->group->party_id;
- else
- return 0;
-}
-
-int battle_get_guild_id (struct block_list *bl)
-{
- nullpo_retr (0, bl);
- if (bl->type == BL_PC && (struct map_session_data *) bl)
- return ((struct map_session_data *) bl)->status.guild_id;
- else if (bl->type == BL_MOB && (struct mob_data *) bl)
- return ((struct mob_data *) bl)->mob_class;
- else if (bl->type == BL_SKILL && (struct skill_unit *) bl)
- return ((struct skill_unit *) bl)->group->guild_id;
- else
- return 0;
+ return 0;
}
-int battle_get_race (struct block_list *bl)
+Race battle_get_race(struct block_list *bl)
{
- nullpo_retr (0, bl);
- if (bl->type == BL_MOB && (struct mob_data *) bl)
+ nullpo_retr(Race::formless, bl);
+ if (bl->type == BL::MOB)
return mob_db[((struct mob_data *) bl)->mob_class].race;
- else if (bl->type == BL_PC && (struct map_session_data *) bl)
- return 7;
- else
- return 0;
-}
-
-int battle_get_size (struct block_list *bl)
-{
- nullpo_retr (1, bl);
- if (bl->type == BL_MOB && (struct mob_data *) bl)
- return mob_db[((struct mob_data *) bl)->mob_class].size;
- else if (bl->type == BL_PC && (struct map_session_data *) bl)
- return 1;
+ else if (bl->type == BL::PC)
+ return Race::demihuman;
else
- return 1;
+ return Race::formless;
}
-int battle_get_mode (struct block_list *bl)
+MobMode battle_get_mode(struct block_list *bl)
{
- nullpo_retr (0x01, bl);
- if (bl->type == BL_MOB && (struct mob_data *) bl)
+ nullpo_retr(MobMode::CAN_MOVE, bl);
+ if (bl->type == BL::MOB)
return mob_db[((struct mob_data *) bl)->mob_class].mode;
- else
- return 0x01; // ã¨ã‚Šã‚ãˆãšå‹•ãã¨ã„ã†ã“ã¨ã§1
+ // ã¨ã‚Šã‚ãˆãšå‹•ãã¨ã„ã†ã“ã¨ã§1
+ return MobMode::CAN_MOVE;
}
-int battle_get_mexp (struct block_list *bl)
-{
- nullpo_retr (0, bl);
- if (bl->type == BL_MOB && (struct mob_data *) bl)
- {
- const struct mob_data *mob = (struct mob_data *) bl;
- const int retval =
- (mob_db[mob->mob_class].mexp *
- (int) (mob->stats[MOB_XP_BONUS])) >> MOB_XP_BONUS_SHIFT;
- fprintf (stderr, "Modifier of %x: -> %d\n", mob->stats[MOB_XP_BONUS],
- retval);
- return retval;
- }
- else
- return 0;
-}
-
-int battle_get_stat (int stat_id /* SP_VIT or similar */ ,
- struct block_list *bl)
+int battle_get_stat(SP stat_id, struct block_list *bl)
{
switch (stat_id)
{
- case SP_STR:
- return battle_get_str (bl);
- case SP_AGI:
- return battle_get_agi (bl);
- case SP_DEX:
- return battle_get_dex (bl);
- case SP_VIT:
- return battle_get_vit (bl);
- case SP_INT:
- return battle_get_int (bl);
- case SP_LUK:
- return battle_get_luk (bl);
+ case SP::STR:
+ return battle_get_str(bl);
+ case SP::AGI:
+ return battle_get_agi(bl);
+ case SP::DEX:
+ return battle_get_dex(bl);
+ case SP::VIT:
+ return battle_get_vit(bl);
+ case SP::INT:
+ return battle_get_int(bl);
+ case SP::LUK:
+ return battle_get_luk(bl);
default:
return 0;
}
}
// StatusChangeç³»ã®æ‰€å¾—
-struct status_change *battle_get_sc_data (struct block_list *bl)
+eptr<struct status_change, StatusChange> battle_get_sc_data(struct block_list *bl)
{
- nullpo_retr (NULL, bl);
- if (bl->type == BL_MOB && (struct mob_data *) bl)
- return ((struct mob_data *) bl)->sc_data;
- else if (bl->type == BL_PC && (struct map_session_data *) bl)
- return ((struct map_session_data *) bl)->sc_data;
- return NULL;
+ nullpo_retr(nullptr, bl);
+
+ switch (bl->type)
+ {
+ case BL::MOB:
+ return ((struct mob_data *)(bl))->sc_data;
+ case BL::PC:
+ return ((struct map_session_data *)(bl))->sc_data;
+ }
+ return nullptr;
}
-short *battle_get_sc_count (struct block_list *bl)
+short *battle_get_sc_count(struct block_list *bl)
{
- nullpo_retr (NULL, bl);
- if (bl->type == BL_MOB && (struct mob_data *) bl)
+ nullpo_retr(NULL, bl);
+ if (bl->type == BL::MOB)
return &((struct mob_data *) bl)->sc_count;
- else if (bl->type == BL_PC && (struct map_session_data *) bl)
+ else if (bl->type == BL::PC)
return &((struct map_session_data *) bl)->sc_count;
return NULL;
}
-short *battle_get_opt1 (struct block_list *bl)
+Opt1 *battle_get_opt1(struct block_list *bl)
{
- nullpo_retr (0, bl);
- if (bl->type == BL_MOB && (struct mob_data *) bl)
+ nullpo_ret(bl);
+ if (bl->type == BL::MOB)
return &((struct mob_data *) bl)->opt1;
- else if (bl->type == BL_PC && (struct map_session_data *) bl)
+ else if (bl->type == BL::PC)
return &((struct map_session_data *) bl)->opt1;
- else if (bl->type == BL_NPC && (struct npc_data *) bl)
+ else if (bl->type == BL::NPC && (struct npc_data *) bl)
return &((struct npc_data *) bl)->opt1;
return 0;
}
-short *battle_get_opt2 (struct block_list *bl)
+Opt2 *battle_get_opt2(struct block_list *bl)
{
- nullpo_retr (0, bl);
- if (bl->type == BL_MOB && (struct mob_data *) bl)
+ nullpo_ret(bl);
+ if (bl->type == BL::MOB)
return &((struct mob_data *) bl)->opt2;
- else if (bl->type == BL_PC && (struct map_session_data *) bl)
+ else if (bl->type == BL::PC)
return &((struct map_session_data *) bl)->opt2;
- else if (bl->type == BL_NPC && (struct npc_data *) bl)
+ else if (bl->type == BL::NPC && (struct npc_data *) bl)
return &((struct npc_data *) bl)->opt2;
return 0;
}
-short *battle_get_opt3 (struct block_list *bl)
+Opt3 *battle_get_opt3(struct block_list *bl)
{
- nullpo_retr (0, bl);
- if (bl->type == BL_MOB && (struct mob_data *) bl)
+ nullpo_ret(bl);
+ if (bl->type == BL::MOB)
return &((struct mob_data *) bl)->opt3;
- else if (bl->type == BL_PC && (struct map_session_data *) bl)
+ else if (bl->type == BL::PC)
return &((struct map_session_data *) bl)->opt3;
- else if (bl->type == BL_NPC && (struct npc_data *) bl)
+ else if (bl->type == BL::NPC && (struct npc_data *) bl)
return &((struct npc_data *) bl)->opt3;
return 0;
}
-short *battle_get_option (struct block_list *bl)
+Option *battle_get_option(struct block_list *bl)
{
- nullpo_retr (0, bl);
- if (bl->type == BL_MOB && (struct mob_data *) bl)
+ nullpo_ret(bl);
+ if (bl->type == BL::MOB)
return &((struct mob_data *) bl)->option;
- else if (bl->type == BL_PC && (struct map_session_data *) bl)
+ else if (bl->type == BL::PC)
return &((struct map_session_data *) bl)->status.option;
- else if (bl->type == BL_NPC && (struct npc_data *) bl)
+ else if (bl->type == BL::NPC && (struct npc_data *) bl)
return &((struct npc_data *) bl)->option;
return 0;
}
@@ -1424,45 +910,15 @@ short *battle_get_option (struct block_list *bl)
struct battle_delay_damage_
{
struct block_list *src, *target;
- int damage;
- int flag;
+ int damage;
+ int flag;
};
-static
-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);
-}
-
-int battle_delay_damage (unsigned int tick, struct block_list *src,
- struct block_list *target, int damage, int flag)
-{
- struct battle_delay_damage_ *dat;
- CREATE (dat, struct battle_delay_damage_, 1);
-
- nullpo_retr (0, src);
- nullpo_retr (0, target);
-
- dat->src = src;
- dat->target = target;
- dat->damage = damage;
- dat->flag = flag;
- add_timer (tick, battle_delay_damage_sub, src->id, (int) dat);
- return 0;
-}
// 実際ã«HPã‚’æ“作
-int battle_damage (struct block_list *bl, struct block_list *target,
+int battle_damage(struct block_list *bl, struct block_list *target,
int damage, int flag)
{
- struct map_session_data *sd = NULL;
- struct status_change *sc_data = battle_get_sc_data (target);
- short *sc_count;
- int i;
-
- nullpo_retr (0, target); //blã¯NULLã§å‘¼ã°ã‚Œã‚‹ã“ã¨ãŒã‚ã‚‹ã®ã§ä»–ã§ãƒã‚§ãƒƒã‚¯
+ nullpo_ret(target); //blã¯NULLã§å‘¼ã°ã‚Œã‚‹ã“ã¨ãŒã‚ã‚‹ã®ã§ä»–ã§ãƒã‚§ãƒƒã‚¯
if (damage == 0)
return 0;
@@ -1474,371 +930,90 @@ int battle_damage (struct block_list *bl, struct block_list *target,
{
if (bl->prev == NULL)
return 0;
-
- if (bl->type == BL_PC)
- sd = (struct map_session_data *) bl;
}
if (damage < 0)
- return battle_heal (bl, target, -damage, 0, flag);
-
- if (!flag && (sc_count = battle_get_sc_count (target)) != NULL
- && *sc_count > 0)
- {
- // å‡çµã€çŸ³åŒ–ã€ç¡çœ ã‚’消去
- if (sc_data[SC_FREEZE].timer != -1)
- skill_status_change_end (target, SC_FREEZE, -1);
- if (sc_data[SC_STONE].timer != -1 && sc_data[SC_STONE].val2 == 0)
- skill_status_change_end (target, SC_STONE, -1);
- if (sc_data[SC_SLEEP].timer != -1)
- skill_status_change_end (target, SC_SLEEP, -1);
- }
+ return battle_heal(bl, target, -damage, 0, flag);
- if (target->type == BL_MOB)
+ if (target->type == BL::MOB)
{ // MOB
struct mob_data *md = (struct mob_data *) target;
- if (md && md->skilltimer != -1 && md->state.skillcastcancel) // 詠唱妨害
- skill_castcancel (target, 0);
- return mob_damage (bl, md, damage, 0);
+ if (md && md->skilltimer && md->state.skillcastcancel) // 詠唱妨害
+ skill_castcancel(target, 0);
+ return mob_damage(bl, md, damage, 0);
}
- else if (target->type == BL_PC)
+ else if (target->type == BL::PC)
{ // PC
struct map_session_data *tsd = (struct map_session_data *) target;
- if (tsd && tsd->sc_data && tsd->sc_data[SC_DEVOTION].val1)
- { // ディボーションをã‹ã‘られã¦ã„ã‚‹
- struct map_session_data *md =
- map_id2sd (tsd->sc_data[SC_DEVOTION].val1);
- if (md && skill_devotion3 (&md->bl, target->id))
- {
- skill_devotion (md, target->id);
- }
- else if (md && bl)
- for (i = 0; i < 5; i++)
- if (md->dev.val1[i] == target->id)
- {
- clif_damage (bl, &md->bl, gettick (), 0, 0,
- damage, 0, 0, 0);
- pc_damage (&md->bl, md, damage);
-
- return 0;
- }
- }
-
- if (tsd && tsd->skilltimer != -1)
- { // 詠唱妨害
- // フェンカードや妨害ã•ã‚Œãªã„スキルã‹ã®æ¤œæŸ»
- if ((!tsd->special_state.no_castcancel || map[bl->m].flag.gvg)
- && tsd->state.skillcastcancel
- && !tsd->special_state.no_castcancel2)
- skill_castcancel (target, 0);
- }
-
- return pc_damage (bl, tsd, damage);
+ return pc_damage(bl, tsd, damage);
}
- else if (target->type == BL_SKILL)
- return skill_unit_ondamaged ((struct skill_unit *) target, bl, damage,
- gettick ());
return 0;
}
-int battle_heal (struct block_list *bl, struct block_list *target, int hp,
+int battle_heal(struct block_list *bl, struct block_list *target, int hp,
int sp, int flag)
{
- nullpo_retr (0, target); //blã¯NULLã§å‘¼ã°ã‚Œã‚‹ã“ã¨ãŒã‚ã‚‹ã®ã§ä»–ã§ãƒã‚§ãƒƒã‚¯
+ nullpo_ret(target); //blã¯NULLã§å‘¼ã°ã‚Œã‚‹ã“ã¨ãŒã‚ã‚‹ã®ã§ä»–ã§ãƒã‚§ãƒƒã‚¯
- if (target->type == BL_PC
- && pc_isdead ((struct map_session_data *) target))
+ if (target->type == BL::PC
+ && pc_isdead((struct map_session_data *) target))
return 0;
if (hp == 0 && sp == 0)
return 0;
if (hp < 0)
- return battle_damage (bl, target, -hp, flag);
+ return battle_damage(bl, target, -hp, flag);
- if (target->type == BL_MOB)
- return mob_heal ((struct mob_data *) target, hp);
- else if (target->type == BL_PC)
- return pc_heal ((struct map_session_data *) target, hp, sp);
+ if (target->type == BL::MOB)
+ return mob_heal((struct mob_data *) target, hp);
+ else if (target->type == BL::PC)
+ return pc_heal((struct map_session_data *) target, hp, sp);
return 0;
}
// 攻撃åœæ­¢
-int battle_stopattack (struct block_list *bl)
+int battle_stopattack(struct block_list *bl)
{
- nullpo_retr (0, bl);
- if (bl->type == BL_MOB)
- return mob_stopattack ((struct mob_data *) bl);
- else if (bl->type == BL_PC)
- return pc_stopattack ((struct map_session_data *) bl);
+ nullpo_ret(bl);
+ if (bl->type == BL::MOB)
+ return mob_stopattack((struct mob_data *) bl);
+ else if (bl->type == BL::PC)
+ return pc_stopattack((struct map_session_data *) bl);
return 0;
}
// 移動åœæ­¢
-int battle_stopwalking (struct block_list *bl, int type)
+int battle_stopwalking(struct block_list *bl, int type)
{
- nullpo_retr (0, bl);
- if (bl->type == BL_MOB)
- return mob_stop_walking ((struct mob_data *) bl, type);
- else if (bl->type == BL_PC)
- return pc_stop_walking ((struct map_session_data *) bl, type);
+ nullpo_ret(bl);
+ if (bl->type == BL::MOB)
+ return mob_stop_walking((struct mob_data *) bl, type);
+ else if (bl->type == BL::PC)
+ return pc_stop_walking((struct map_session_data *) bl, type);
return 0;
}
/*==========================================
- * ダメージã®å±žæ€§ä¿®æ­£
- *------------------------------------------
- */
-int battle_attr_fix (int damage, int atk_elem, int def_elem)
-{
- int def_type = def_elem % 10, def_lv = def_elem / 10 / 2;
-
- if (atk_elem < 0 || atk_elem > 9 || def_type < 0 || def_type > 9 ||
- def_lv < 1 || def_lv > 4)
- { // 属 性値ãŒãŠã‹ã—ã„ã®ã§ã¨ã‚Šã‚ãˆãšãã®ã¾ã¾è¿”ã™
- if (battle_config.error_log)
- printf
- ("battle_attr_fix: unknown attr type: atk=%d def_type=%d def_lv=%d\n",
- atk_elem, def_type, def_lv);
- return damage;
- }
-
- return damage * attr_fix_table[def_lv - 1][atk_elem][def_type] / 100;
-}
-
-/*==========================================
* ダメージ最終計算
*------------------------------------------
*/
-int battle_calc_damage (struct block_list *src, struct block_list *bl,
- int damage, int div_, int skill_num, int skill_lv,
- int flag)
+static
+int battle_calc_damage(struct block_list *, struct block_list *bl,
+ int damage, int div_,
+ SkillID, int, BF flag)
{
- struct map_session_data *sd = NULL;
struct mob_data *md = NULL;
- struct status_change *sc_data, *sc;
- short *sc_count;
- int class_;
- nullpo_retr (0, bl);
+ nullpo_ret(bl);
- class_ = battle_get_class (bl);
- if (bl->type == BL_MOB)
+ if (bl->type == BL::MOB)
md = (struct mob_data *) bl;
- else
- sd = (struct map_session_data *) bl;
- sc_data = battle_get_sc_data (bl);
- sc_count = battle_get_sc_count (bl);
-
- if (sc_count != NULL && *sc_count > 0)
- {
-
- if (sc_data[SC_SAFETYWALL].timer != -1 && damage > 0
- && flag & BF_WEAPON && flag & BF_SHORT
- && skill_num != NPC_GUIDEDATTACK)
- {
- // セーフティウォール
- struct skill_unit *unit =
- (struct skill_unit *) sc_data[SC_SAFETYWALL].val2;
- if (unit && unit->alive && (--unit->group->val2) <= 0)
- skill_delunit (unit);
- skill_unit_move (bl, gettick (), 1); // é‡ã­æŽ›ã‘ãƒã‚§ãƒƒã‚¯
- damage = 0;
- }
- if (sc_data[SC_PNEUMA].timer != -1 && damage > 0 && flag & BF_WEAPON
- && flag & BF_LONG && skill_num != NPC_GUIDEDATTACK)
- {
- // ニューマ
- damage = 0;
- }
-
- if (sc_data[SC_ROKISWEIL].timer != -1 && damage > 0 &&
- flag & BF_MAGIC)
- {
- // ニューマ
- damage = 0;
- }
-
- if (sc_data[SC_AETERNA].timer != -1 && damage > 0)
- { // レックスエーテルナ
- damage <<= 1;
- skill_status_change_end (bl, SC_AETERNA, -1);
- }
-
- //属性場ã®ãƒ€ãƒ¡ãƒ¼ã‚¸å¢—加
- if (sc_data[SC_VOLCANO].timer != -1)
- { // ボルケーノ
- if (flag & BF_SKILL && skill_get_pl (skill_num) == 3)
- damage += damage * sc_data[SC_VOLCANO].val4 / 100;
- else if (!(flag & BF_SKILL) && (battle_get_attack_element (bl) == 3))
- damage += damage * sc_data[SC_VOLCANO].val4 / 100;
- }
-
- if (sc_data[SC_VIOLENTGALE].timer != -1)
- { // ãƒã‚¤ã‚ªãƒ¬ãƒ³ãƒˆã‚²ã‚¤ãƒ«
- if (flag & BF_SKILL && skill_get_pl (skill_num) == 4)
- damage += damage * sc_data[SC_VIOLENTGALE].val4 / 100;
- else if (!(flag & BF_SKILL) && (battle_get_attack_element (bl) == 4))
- damage += damage * sc_data[SC_VIOLENTGALE].val4 / 100;
- }
-
- if (sc_data[SC_DELUGE].timer != -1)
- { // デリュージ
- if (flag & BF_SKILL && skill_get_pl (skill_num) == 1)
- damage += damage * sc_data[SC_DELUGE].val4 / 100;
- else if (!(flag & BF_SKILL) && (battle_get_attack_element (bl) == 1))
- damage += damage * sc_data[SC_DELUGE].val4 / 100;
- }
-
- if (sc_data[SC_ENERGYCOAT].timer != -1 && damage > 0
- && flag & BF_WEAPON)
- { // エナジーコート
- if (sd)
- {
- if (sd->status.sp > 0)
- {
- int per = sd->status.sp * 5 / (sd->status.max_sp + 1);
- sd->status.sp -= sd->status.sp * (per * 5 + 10) / 1000;
- if (sd->status.sp < 0)
- sd->status.sp = 0;
- damage -= damage * ((per + 1) * 6) / 100;
- clif_updatestatus (sd, SP_SP);
- }
- if (sd->status.sp <= 0)
- skill_status_change_end (bl, SC_ENERGYCOAT, -1);
- }
- else
- damage -= damage * (sc_data[SC_ENERGYCOAT].val1 * 6) / 100;
- }
-
- if (sc_data[SC_KYRIE].timer != -1 && damage > 0)
- { // キリエエレイソン
- sc = &sc_data[SC_KYRIE];
- sc->val2 -= damage;
- if (flag & BF_WEAPON)
- {
- if (sc->val2 >= 0)
- damage = 0;
- else
- damage = -sc->val2;
- }
- if ((--sc->val3) <= 0 || (sc->val2 <= 0)
- || skill_num == AL_HOLYLIGHT)
- skill_status_change_end (bl, SC_KYRIE, -1);
- }
-
- if (sc_data[SC_BASILICA].timer != -1 && damage > 0)
- {
- // ニューマ
- damage = 0;
- }
- if (sc_data[SC_LANDPROTECTOR].timer != -1 && damage > 0
- && flag & BF_MAGIC)
- {
- // ニューマ
- damage = 0;
- }
-
- if (sc_data[SC_AUTOGUARD].timer != -1 && damage > 0
- && flag & BF_WEAPON)
- {
- if (MRAND (100) < sc_data[SC_AUTOGUARD].val2)
- {
- damage = 0;
- clif_skill_nodamage (bl, bl, CR_AUTOGUARD,
- sc_data[SC_AUTOGUARD].val1, 1);
- if (sd)
- sd->canmove_tick = gettick () + 300;
- else if (md)
- md->canmove_tick = gettick () + 300;
- }
- }
-// -- moonsoul (chance to block attacks with new Lord Knight skill parrying)
-//
- if (sc_data[SC_PARRYING].timer != -1 && damage > 0
- && flag & BF_WEAPON)
- {
- if (MRAND (100) < sc_data[SC_PARRYING].val2)
- {
- damage = 0;
- clif_skill_nodamage (bl, bl, LK_PARRYING,
- sc_data[SC_PARRYING].val1, 1);
- }
- }
- // リジェクトソード
- if (sc_data[SC_REJECTSWORD].timer != -1 && damage > 0
- && flag & BF_WEAPON
- &&
- ((src->type == BL_PC
- && ((struct map_session_data *) src)->status.weapon == (1 || 2
- || 3))
- || src->type == BL_MOB))
- {
- if (MRAND (100) < (10 + 5 * sc_data[SC_REJECTSWORD].val1))
- { //å射確率ã¯10+5*Lv
- damage = damage * 50 / 100;
- battle_damage (bl, src, damage, 0);
- //ダメージを与ãˆãŸã®ã¯è‰¯ã„ã‚“ã ãŒã€ã“ã“ã‹ã‚‰ã©ã†ã—ã¦è¡¨ç¤ºã™ã‚‹ã‚“ã ã‹ã‚ã‹ã‚“ã­ã‡
- //エフェクトもã“ã‚Œã§ã„ã„ã®ã‹ã‚ã‹ã‚“ã­ã‡
- clif_skill_nodamage (bl, bl, ST_REJECTSWORD,
- sc_data[SC_REJECTSWORD].val1, 1);
- if ((--sc_data[SC_REJECTSWORD].val2) <= 0)
- skill_status_change_end (bl, SC_REJECTSWORD, -1);
- }
- }
- }
-
- if (class_ == 1288 || class_ == 1287 || class_ == 1286 || class_ == 1285)
- {
-// if(class == 1288) {
- if (class_ == 1288 && flag & BF_SKILL)
- damage = 0;
- if (src->type == BL_PC)
- {
- struct guild *g =
- guild_search (((struct map_session_data *) src)->
- status.guild_id);
- struct guild_castle *gc = guild_mapname2gc (map[bl->m].name);
- if (!((struct map_session_data *) src)->status.guild_id)
- damage = 0;
- if (gc && agit_flag == 0 && class_ != 1288) // guardians cannot be damaged during non-woe [Valaris]
- damage = 0; // end woe check [Valaris]
- if (g == NULL)
- damage = 0; //ギルド未加入ãªã‚‰ãƒ€ãƒ¡ãƒ¼ã‚¸ç„¡ã—
- else if ((gc != NULL) && guild_isallied (g, gc))
- damage = 0; //自å é ˜ã‚®ãƒ«ãƒ‰ã®ã‚¨ãƒ³ãƒšãªã‚‰ãƒ€ãƒ¡ãƒ¼ã‚¸ç„¡ã—
- else if (g && guild_checkskill (g, GD_APPROVAL) <= 0)
- damage = 0; //æ­£è¦ã‚®ãƒ«ãƒ‰æ‰¿èªãŒãªã„ã¨ãƒ€ãƒ¡ãƒ¼ã‚¸ç„¡ã—
- else if (battle_config.guild_max_castles != 0
- && guild_checkcastles (g) >=
- battle_config.guild_max_castles)
- damage = 0; // [MouseJstr]
- }
- else
- damage = 0;
- }
-
- if (map[bl->m].flag.gvg && damage > 0)
- { //GvG
- if (flag & BF_WEAPON)
- {
- if (flag & BF_SHORT)
- damage = damage * battle_config.gvg_short_damage_rate / 100;
- if (flag & BF_LONG)
- damage = damage * battle_config.gvg_long_damage_rate / 100;
- }
- if (flag & BF_MAGIC)
- damage = damage * battle_config.gvg_magic_damage_rate / 100;
- if (flag & BF_MISC)
- damage = damage * battle_config.gvg_misc_damage_rate / 100;
- if (damage < 1)
- damage = 1;
- }
-
- if (battle_config.skill_min_damage || flag & BF_MISC)
+ if (battle_config.skill_min_damage
+ || bool(flag & BF::MISC))
{
if (div_ < 255)
{
@@ -1850,258 +1025,56 @@ int battle_calc_damage (struct block_list *src, struct block_list *bl,
}
if (md != NULL && md->hp > 0 && damage > 0) // åæ’ƒãªã©ã®MOBスキル判定
- mobskill_event (md, flag);
+ mobskill_event(md, flag);
return damage;
}
-/*==========================================
- * 修練ダメージ
- *------------------------------------------
- */
static
-int battle_addmastery (struct map_session_data *sd, struct block_list *target,
- int dmg, int type)
-{
- int damage, skill;
- int race = battle_get_race (target);
- int weapon;
- damage = 0;
-
- nullpo_retr (0, sd);
-
- // デーモンベイン(+3 〜 +30) vs ä¸æ­» or 悪魔 (死人ã¯å«ã‚ãªã„?)
- if ((skill = pc_checkskill (sd, AL_DEMONBANE)) > 0
- && (battle_check_undead (race, battle_get_elem_type (target))
- || race == 6))
- damage += (skill * 3);
-
- // ビーストベイン(+4 〜 +40) vs 動物 or 昆虫
- if ((skill = pc_checkskill (sd, HT_BEASTBANE)) > 0
- && (race == 2 || race == 4))
- damage += (skill * 4);
-
- if (type == 0)
- weapon = sd->weapontype1;
- else
- weapon = sd->weapontype2;
- switch (weapon)
- {
- case 0x01: // 短剣 (Updated By AppleGirl)
- case 0x02: // 1HS
- {
- // 剣修練(+4 〜 +40) 片手剣 短剣å«ã‚€
- if ((skill = pc_checkskill (sd, SM_SWORD)) > 0)
- {
- damage += (skill * 4);
- }
- break;
- }
- case 0x03: // 2HS
- {
- // 両手剣修練(+4 〜 +40) 両手剣
- if ((skill = pc_checkskill (sd, SM_TWOHAND)) > 0)
- {
- damage += (skill * 4);
- }
- break;
- }
- case 0x04: // 1HL
- {
- // æ§ä¿®ç·´(+4 〜 +40,+5 〜 +50) æ§
- if ((skill = pc_checkskill (sd, KN_SPEARMASTERY)) > 0)
- {
- if (!pc_isriding (sd))
- damage += (skill * 4); // ペコã«ä¹—ã£ã¦ãªã„
- else
- damage += (skill * 5); // ペコã«ä¹—ã£ã¦ã‚‹
- }
- break;
- }
- case 0x05: // 2HL
- {
- // æ§ä¿®ç·´(+4 〜 +40,+5 〜 +50) æ§
- if ((skill = pc_checkskill (sd, KN_SPEARMASTERY)) > 0)
- {
- if (!pc_isriding (sd))
- damage += (skill * 4); // ペコã«ä¹—ã£ã¦ãªã„
- else
- damage += (skill * 5); // ペコã«ä¹—ã£ã¦ã‚‹
- }
- break;
- }
- case 0x06: // 片手斧
- {
- if ((skill = pc_checkskill (sd, AM_AXEMASTERY)) > 0)
- {
- damage += (skill * 3);
- }
- break;
- }
- case 0x07: // Axe by Tato
- {
- if ((skill = pc_checkskill (sd, AM_AXEMASTERY)) > 0)
- {
- damage += (skill * 3);
- }
- break;
- }
- case 0x08: // メイス
- {
- // メイス修練(+3 〜 +30) メイス
- if ((skill = pc_checkskill (sd, PR_MACEMASTERY)) > 0)
- {
- damage += (skill * 3);
- }
- break;
- }
- case 0x09: // ãªã—?
- break;
- case 0x0a: // æ–
- break;
- case 0x0b: // 弓
- break;
- case 0x00: // 素手
- case 0x0c: // Knuckles
- {
- // 鉄拳(+3 〜 +30) 素手,ナックル
- if ((skill = pc_checkskill (sd, MO_IRONHAND)) > 0)
- {
- damage += (skill * 3);
- }
- break;
- }
- case 0x0d: // Musical Instrument
- {
- // 楽器ã®ç·´ç¿’(+3 〜 +30) 楽器
- if ((skill = pc_checkskill (sd, BA_MUSICALLESSON)) > 0)
- {
- damage += (skill * 3);
- }
- break;
- }
- case 0x0e: // Dance Mastery
- {
- // Dance Lesson Skill Effect(+3 damage for every lvl = +30) éž­
- if ((skill = pc_checkskill (sd, DC_DANCINGLESSON)) > 0)
- {
- damage += (skill * 3);
- }
- break;
- }
- case 0x0f: // Book
- {
- // Advance Book Skill Effect(+3 damage for every lvl = +30) {
- if ((skill = pc_checkskill (sd, SA_ADVANCEDBOOK)) > 0)
- {
- damage += (skill * 3);
- }
- break;
- }
- case 0x10: // Katars
- {
- // カタール修練(+3 〜 +30) カタール
- if ((skill = pc_checkskill (sd, AS_KATAR)) > 0)
- {
- //ソニックブロー時ã¯åˆ¥å‡¦ç†ï¼ˆ1æ’ƒã«ä»˜ã1/8é©å¿œ)
- damage += (skill * 3);
- }
- break;
- }
- }
- damage = dmg + damage;
- return (damage);
-}
-
-static struct Damage battle_calc_mob_weapon_attack (struct block_list *src,
+struct Damage battle_calc_mob_weapon_attack(struct block_list *src,
struct block_list *target,
- int skill_num,
- int skill_lv, int wflag)
+ SkillID skill_num,
+ int skill_lv, int)
{
struct map_session_data *tsd = NULL;
struct mob_data *md = (struct mob_data *) src, *tmd = NULL;
- int hitrate, flee, cri = 0, atkmin, atkmax;
- int luk, target_count = 1;
- int def1 = battle_get_def (target);
- int def2 = battle_get_def2 (target);
- int t_vit = battle_get_vit (target);
- struct Damage wd;
- int damage, damage2 = 0, type, div_, blewcount =
- skill_get_blewcount (skill_num, skill_lv);
- int flag, skill, ac_flag = 0, dmg_lv = 0;
- int t_mode = 0, t_race = 0, t_size = 1, s_race = 0, s_ele = 0;
- struct status_change *sc_data, *t_sc_data;
- short *sc_count;
- short *option, *opt1, *opt2;
-
- //returnå‰ã®å‡¦ç†ãŒã‚ã‚‹ã®ã§æƒ…報出力部ã®ã¿å¤‰æ›´
- if (src == NULL || target == NULL || md == NULL)
- {
- nullpo_info (NLP_MARK);
- memset (&wd, 0, sizeof (wd));
- return wd;
- }
-
- s_race = battle_get_race (src);
- s_ele = battle_get_attack_element (src);
- sc_data = battle_get_sc_data (src);
- sc_count = battle_get_sc_count (src);
- option = battle_get_option (src);
- opt1 = battle_get_opt1 (src);
- opt2 = battle_get_opt2 (src);
+ int hitrate, flee, cri = 0, atkmin, atkmax;
+ int target_count = 1;
+ int def1 = battle_get_def(target);
+ int def2 = battle_get_def2(target);
+ int t_vit = battle_get_vit(target);
+ struct Damage wd {};
+ int damage, damage2 = 0;
+ DamageType type;
+ int div_;
+ BF flag;
+ int ac_flag = 0;
+ ATK dmg_lv = ATK::ZERO;
+ eptr<struct status_change, StatusChange> sc_data, t_sc_data;
+
+ nullpo_retr(wd, src);
+ nullpo_retr(wd, target);
+ nullpo_retr(wd, md);
+
+ sc_data = battle_get_sc_data(src);
// ターゲット
- if (target->type == BL_PC)
+ if (target->type == BL::PC)
tsd = (struct map_session_data *) target;
- else if (target->type == BL_MOB)
+ else if (target->type == BL::MOB)
tmd = (struct mob_data *) target;
- t_race = battle_get_race (target);
- t_size = battle_get_size (target);
- t_mode = battle_get_mode (target);
- t_sc_data = battle_get_sc_data (target);
-
- if ((skill_num == 0
- || (target->type == BL_PC && battle_config.pc_auto_counter_type & 2)
- || (target->type == BL_MOB
- && battle_config.monster_auto_counter_type & 2))
- && skill_lv >= 0)
- {
- if (skill_num != CR_GRANDCROSS && t_sc_data
- && t_sc_data[SC_AUTOCOUNTER].timer != -1)
- {
- int dir = map_calc_dir (src, target->x, target->y), t_dir =
- battle_get_dir (target);
- int dist = distance (src->x, src->y, target->x, target->y);
- if (dist <= 0 || map_check_dir (dir, t_dir))
- {
- memset (&wd, 0, sizeof (wd));
- t_sc_data[SC_AUTOCOUNTER].val3 = 0;
- t_sc_data[SC_AUTOCOUNTER].val4 = 1;
- if (sc_data && sc_data[SC_AUTOCOUNTER].timer == -1)
- {
- int range = battle_get_range (target);
- if ((target->type == BL_PC
- && ((struct map_session_data *) target)->
- status.weapon != 11 && dist <= range + 1)
- || (target->type == BL_MOB && range <= 3
- && dist <= range + 1))
- t_sc_data[SC_AUTOCOUNTER].val3 = src->id;
- }
- return wd;
- }
- else
- ac_flag = 1;
- }
- }
- flag = BF_SHORT | BF_WEAPON | BF_NORMAL; // 攻撃ã®ç¨®é¡žã®è¨­å®š
+ MobMode t_mode = battle_get_mode(target);
+ t_sc_data = battle_get_sc_data(target);
+
+ flag = BF::SHORT | BF::WEAPON | BF::NORMAL; // 攻撃ã®ç¨®é¡žã®è¨­å®š
// 回é¿çŽ‡è¨ˆç®—ã€å›žé¿åˆ¤å®šã¯å¾Œã§
- flee = battle_get_flee (target);
+ flee = battle_get_flee(target);
if (battle_config.agi_penaly_type > 0
|| battle_config.vit_penaly_type > 0)
target_count +=
- battle_counttargeted (target, src,
- battle_config.agi_penaly_count_lv);
+ battle_counttargeted(target, src,
+ ATK(battle_config.agi_penaly_count_lv)); // FIXME
if (battle_config.agi_penaly_type > 0)
{
if (target_count >= battle_config.agi_penaly_count)
@@ -2122,325 +1095,72 @@ static struct Damage battle_calc_mob_weapon_attack (struct block_list *src,
flee = 1;
}
}
- hitrate = battle_get_hit (src) - flee + 80;
+ hitrate = battle_get_hit(src) - flee + 80;
- type = 0; // normal
+ type = DamageType::NORMAL;
div_ = 1; // single attack
- luk = battle_get_luk (src);
-
if (battle_config.enemy_str)
- damage = battle_get_baseatk (src);
+ damage = battle_get_baseatk(src);
else
damage = 0;
- if (skill_num == HW_MAGICCRASHER)
- { /* マジッククラッシャーã¯MATKã§æ®´ã‚‹ */
- atkmin = battle_get_matk1 (src);
- atkmax = battle_get_matk2 (src);
- }
- else
{
- atkmin = battle_get_atk (src);
- atkmax = battle_get_atk2 (src);
+ atkmin = battle_get_atk(src);
+ atkmax = battle_get_atk2(src);
}
if (mob_db[md->mob_class].range > 3)
- flag = (flag & ~BF_RANGEMASK) | BF_LONG;
+ flag = (flag & ~BF::RANGEMASK) | BF::LONG;
if (atkmin > atkmax)
atkmin = atkmax;
- if (sc_data != NULL && sc_data[SC_MAXIMIZEPOWER].timer != -1)
- { // マキシマイズパワー
- atkmin = atkmax;
- }
-
- cri = battle_get_critical (src);
- cri -= battle_get_luk (target) * 3;
+ cri = battle_get_critical(src);
+ cri -= battle_get_luk(target) * 3;
if (battle_config.enemy_critical_rate != 100)
{
cri = cri * battle_config.enemy_critical_rate / 100;
if (cri < 1)
cri = 1;
}
- if (t_sc_data != NULL && t_sc_data[SC_SLEEP].timer != -1) // ç¡çœ ä¸­ã¯ã‚¯ãƒªãƒ†ã‚£ã‚«ãƒ«ãŒå€ã«
- cri <<= 1;
if (ac_flag)
cri = 1000;
- if (skill_num == KN_AUTOCOUNTER)
- {
- if (!(battle_config.monster_auto_counter_type & 1))
- cri = 1000;
- else
- cri <<= 1;
- }
-
if (tsd && tsd->critical_def)
cri = cri * (100 - tsd->critical_def) / 100;
- if ((skill_num == 0 || skill_num == KN_AUTOCOUNTER) && skill_lv >= 0 && battle_config.enemy_critical && (MRAND (1000)) < cri) // 判定(スキルã®å ´åˆã¯ç„¡è¦–)
+ if ((skill_num == SkillID::ZERO)
+ && skill_lv >= 0 && battle_config.enemy_critical
+ && random_::chance({cri, 1000}))
+ // 判定(スキルã®å ´åˆã¯ç„¡è¦–)
// 敵ã®åˆ¤å®š
{
damage += atkmax;
- type = 0x0a;
+ type = DamageType::CRITICAL;
}
else
{
- int vitbonusmax;
+ int vitbonusmax;
if (atkmax > atkmin)
- damage += atkmin + MRAND ((atkmax - atkmin + 1));
+ damage += random_::in(atkmin, atkmax);
else
damage += atkmin;
- // スキル修正1(攻撃力å€åŒ–系)
- // オーãƒãƒ¼ãƒˆãƒ©ã‚¹ãƒˆ(+5% 〜 +25%),他攻撃系スキルã®å ´åˆã“ã“ã§è£œæ­£
- // ãƒãƒƒã‚·ãƒ¥,マグナムブレイク,
- // ボーリングãƒãƒƒã‚·ãƒ¥,スピアブーメラン,ブランディッシュスピア,スピアスタッブ,
- // メマーナイト,カートレボリューション
- // ダブルストレイフィング,アローシャワー,ãƒãƒ£ãƒ¼ã‚¸ã‚¢ãƒ­ãƒ¼,
- // ソニックブロー
- if (sc_data)
- { //状態異常中ã®ãƒ€ãƒ¡ãƒ¼ã‚¸è¿½åŠ 
- if (sc_data[SC_OVERTHRUST].timer != -1) // オーãƒãƒ¼ãƒˆãƒ©ã‚¹ãƒˆ
- damage += damage * (5 * sc_data[SC_OVERTHRUST].val1) / 100;
- if (sc_data[SC_TRUESIGHT].timer != -1) // トゥルーサイト
- damage += damage * (2 * sc_data[SC_TRUESIGHT].val1) / 100;
- if (sc_data[SC_BERSERK].timer != -1) // ãƒãƒ¼ã‚µãƒ¼ã‚¯
- damage += damage * 50 / 100;
- }
- if (skill_num > 0)
+ if (skill_num != SkillID::ZERO && skill_num != SkillID::NEGATIVE)
{
- int i;
- if ((i = skill_get_pl (skill_num)) > 0)
- s_ele = i;
-
- flag = (flag & ~BF_SKILLMASK) | BF_SKILL;
- switch (skill_num)
- {
- case SM_BASH: // ãƒãƒƒã‚·ãƒ¥
- damage = damage * (100 + 30 * skill_lv) / 100;
- hitrate = (hitrate * (100 + 5 * skill_lv)) / 100;
- break;
- case SM_MAGNUM: // マグナムブレイク
- damage =
- damage * (5 * skill_lv + (wflag) ? 65 : 115) / 100;
- break;
- case MC_MAMMONITE: // メマーナイト
- damage = damage * (100 + 50 * skill_lv) / 100;
- break;
- case AC_DOUBLE: // ダブルストレイフィング
- damage = damage * (180 + 20 * skill_lv) / 100;
- div_ = 2;
- flag = (flag & ~BF_RANGEMASK) | BF_LONG;
- break;
- case AC_SHOWER: // アローシャワー
- damage = damage * (75 + 5 * skill_lv) / 100;
- flag = (flag & ~BF_RANGEMASK) | BF_LONG;
- break;
- case AC_CHARGEARROW: // ãƒãƒ£ãƒ¼ã‚¸ã‚¢ãƒ­ãƒ¼
- damage = damage * 150 / 100;
- flag = (flag & ~BF_RANGEMASK) | BF_LONG;
- break;
- case KN_PIERCE: // ピアース
- damage = damage * (100 + 10 * skill_lv) / 100;
- hitrate = hitrate * (100 + 5 * skill_lv) / 100;
- div_ = t_size + 1;
- damage *= div_;
- break;
- case KN_SPEARSTAB: // スピアスタブ
- damage = damage * (100 + 15 * skill_lv) / 100;
- break;
- case KN_SPEARBOOMERANG: // スピアブーメラン
- damage = damage * (100 + 50 * skill_lv) / 100;
- flag = (flag & ~BF_RANGEMASK) | BF_LONG;
- break;
- case KN_BRANDISHSPEAR: // ブランディッシュスピア
- damage = damage * (100 + 20 * skill_lv) / 100;
- if (skill_lv > 3 && wflag == 1)
- damage2 += damage / 2;
- if (skill_lv > 6 && wflag == 1)
- damage2 += damage / 4;
- if (skill_lv > 9 && wflag == 1)
- damage2 += damage / 8;
- if (skill_lv > 6 && wflag == 2)
- damage2 += damage / 2;
- if (skill_lv > 9 && wflag == 2)
- damage2 += damage / 4;
- if (skill_lv > 9 && wflag == 3)
- damage2 += damage / 2;
- damage += damage2;
- blewcount = 0;
- break;
- case KN_BOWLINGBASH: // ボウリングãƒãƒƒã‚·ãƒ¥
- damage = damage * (100 + 50 * skill_lv) / 100;
- blewcount = 0;
- break;
- case KN_AUTOCOUNTER:
- if (battle_config.monster_auto_counter_type & 1)
- hitrate += 20;
- else
- hitrate = 1000000;
- flag = (flag & ~BF_SKILLMASK) | BF_NORMAL;
- break;
- case AS_SONICBLOW: // ソニックブロウ
- damage = damage * (300 + 50 * skill_lv) / 100;
- div_ = 8;
- break;
- case TF_SPRINKLESAND: // ç ‚ã¾ã
- damage = damage * 125 / 100;
- break;
- case MC_CARTREVOLUTION: // カートレボリューション
- damage = (damage * 150) / 100;
- break;
- // 以下MOB
- case NPC_COMBOATTACK: // 多段攻撃
- div_ = skill_get_num (skill_num, skill_lv);
- damage *= div_;
- break;
- case NPC_RANDOMATTACK: // ランダムATK攻撃
- damage = damage * (MPRAND (50, 150)) / 100;
- break;
- // 属性攻撃(é©å½“)
- case NPC_WATERATTACK:
- case NPC_GROUNDATTACK:
- case NPC_FIREATTACK:
- case NPC_WINDATTACK:
- case NPC_POISONATTACK:
- case NPC_HOLYATTACK:
- case NPC_DARKNESSATTACK:
- case NPC_TELEKINESISATTACK:
- damage = damage * (100 + 25 * (skill_lv - 1)) / 100;
- break;
- case NPC_GUIDEDATTACK:
- hitrate = 1000000;
- break;
- case NPC_RANGEATTACK:
- flag = (flag & ~BF_RANGEMASK) | BF_LONG;
- break;
- case NPC_PIERCINGATT:
- flag = (flag & ~BF_RANGEMASK) | BF_SHORT;
- break;
- case RG_BACKSTAP: // ãƒãƒƒã‚¯ã‚¹ã‚¿ãƒ–
- damage = damage * (300 + 40 * skill_lv) / 100;
- hitrate = 1000000;
- break;
- case RG_RAID: // サプライズアタック
- damage = damage * (100 + 40 * skill_lv) / 100;
- break;
- case RG_INTIMIDATE: // インティミデイト
- damage = damage * (100 + 30 * skill_lv) / 100;
- break;
- case CR_SHIELDCHARGE: // シールドãƒãƒ£ãƒ¼ã‚¸
- damage = damage * (100 + 20 * skill_lv) / 100;
- flag = (flag & ~BF_RANGEMASK) | BF_SHORT;
- s_ele = 0;
- break;
- case CR_SHIELDBOOMERANG: // シールドブーメラン
- damage = damage * (100 + 30 * skill_lv) / 100;
- flag = (flag & ~BF_RANGEMASK) | BF_LONG;
- s_ele = 0;
- break;
- case CR_HOLYCROSS: // ホーリークロス
- damage = damage * (100 + 35 * skill_lv) / 100;
- div_ = 2;
- break;
- case CR_GRANDCROSS:
- hitrate = 1000000;
- break;
- case AM_DEMONSTRATION: // デモンストレーション
- damage = damage * (100 + 20 * skill_lv) / 100;
- damage2 = damage2 * (100 + 20 * skill_lv) / 100;
- break;
- case AM_ACIDTERROR: // アシッドテラー
- damage = damage * (100 + 40 * skill_lv) / 100;
- damage2 = damage2 * (100 + 40 * skill_lv) / 100;
- break;
- case MO_FINGEROFFENSIVE: //指弾
- damage = damage * (100 + 50 * skill_lv) / 100;
- div_ = 1;
- break;
- case MO_INVESTIGATE: // 発 å‹
- if (def1 < 1000000)
- damage =
- damage * (100 + 75 * skill_lv) / 100 * (def1 +
- def2) /
- 100;
- hitrate = 1000000;
- s_ele = 0;
- break;
- case MO_EXTREMITYFIST: // 阿修羅覇鳳拳
- damage = damage * 8 + 250 + (skill_lv * 150);
- hitrate = 1000000;
- s_ele = 0;
- break;
- case MO_CHAINCOMBO: // 連打掌
- damage = damage * (150 + 50 * skill_lv) / 100;
- div_ = 4;
- break;
- case BA_MUSICALSTRIKE: // ミュージカルストライク
- damage = damage * (100 + 50 * skill_lv) / 100;
- flag = (flag & ~BF_RANGEMASK) | BF_LONG;
- break;
- case DC_THROWARROW: // 矢撃ã¡
- damage = damage * (100 + 50 * skill_lv) / 100;
- flag = (flag & ~BF_RANGEMASK) | BF_LONG;
- break;
- case MO_COMBOFINISH: // 猛é¾æ‹³
- damage = damage * (240 + 60 * skill_lv) / 100;
- break;
- case CH_TIGERFIST: // ä¼è™Žæ‹³
- damage = damage * (100 + 20 * skill_lv) / 100;
- break;
- case CH_CHAINCRUSH: // 連柱崩撃
- damage = damage * (100 + 20 * skill_lv) / 100;
- div_ = skill_get_num (skill_num, skill_lv);
- break;
- case CH_PALMSTRIKE: // 猛虎硬派山
- damage = damage * (50 + 100 * skill_lv) / 100;
- break;
- case LK_SPIRALPIERCE: /* スパイラルピアース */
- damage = damage * (100 + 50 * skill_lv) / 100; //増加é‡ãŒåˆ†ã‹ã‚‰ãªã„ã®ã§é©å½“ã«
- div_ = 5;
- if (tsd)
- tsd->canmove_tick = gettick () + 1000;
- else if (tmd)
- tmd->canmove_tick = gettick () + 1000;
- break;
- case LK_HEADCRUSH: /* ヘッドクラッシュ */
- damage = damage * (100 + 20 * skill_lv) / 100;
- break;
- case LK_JOINTBEAT: /* ジョイントビート */
- damage = damage * (50 + 10 * skill_lv) / 100;
- break;
- case ASC_METEORASSAULT: /* メテオアサルト */
- damage = damage * (40 + 40 * skill_lv) / 100;
- break;
- case SN_SHARPSHOOTING: /* シャープシューティング */
- damage += damage * (30 * skill_lv) / 100;
- break;
- case CG_ARROWVULCAN: /* アローãƒãƒ«ã‚«ãƒ³ */
- damage = damage * (160 + 40 * skill_lv) / 100;
- div_ = 9;
- break;
- case AS_SPLASHER: /* ベナムスプラッシャー */
- damage = damage * (200 + 20 * skill_lv) / 100;
- break;
- }
+ flag = (flag & ~BF::SKILLMASK) | BF::SKILL;
}
- if (skill_num != NPC_CRITICALSLASH)
{
// 対 象ã®é˜²å¾¡åŠ›ã«ã‚ˆã‚‹ãƒ€ãƒ¡ãƒ¼ã‚¸ã®æ¸›å°‘
// ディãƒã‚¤ãƒ³ãƒ—ロテクション(ã“ã“ã§ã„ã„ã®ã‹ãªï¼Ÿï¼‰
- if (skill_num != MO_INVESTIGATE && skill_num != MO_EXTREMITYFIST
- && skill_num != KN_AUTOCOUNTER && def1 < 1000000)
+ if (def1 < 1000000)
{ //DEF, VIT無視
- int t_def;
+ int t_def;
target_count =
- 1 + battle_counttargeted (target, src,
- battle_config.vit_penaly_count_lv);
+ 1 + battle_counttargeted(target, src,
+ ATK(battle_config.vit_penaly_count_lv)); // FIXME
if (battle_config.vit_penaly_type > 0)
{
if (target_count >= battle_config.vit_penaly_count)
@@ -2493,24 +1213,13 @@ static struct Damage battle_calc_mob_weapon_attack (struct block_list *src,
}
}
t_def = def2 * 8 / 10;
- if (battle_check_undead (s_race, battle_get_elem_type (src))
- || s_race == 6)
- if (tsd && (skill = pc_checkskill (tsd, AL_DP)) > 0)
- t_def += skill * 3;
vitbonusmax = (t_vit / 20) * (t_vit / 20) - 1;
- if (battle_config.monster_defense_type)
- {
- damage =
- damage - (def1 * battle_config.monster_defense_type) -
- t_def -
- ((vitbonusmax < 1) ? 0 : MRAND ((vitbonusmax + 1)));
- }
- else
{
- damage =
- damage * (100 - def1) / 100 - t_def -
- ((vitbonusmax < 1) ? 0 : MRAND ((vitbonusmax + 1)));
+ damage = damage * (100 - def1) / 100;
+ damage -= t_def;
+ if (vitbonusmax > 0)
+ damage -= random_::in(0, vitbonusmax);
}
}
}
@@ -2523,143 +1232,68 @@ static struct Damage battle_calc_mob_weapon_attack (struct block_list *src,
// 回é¿ä¿®æ­£
if (hitrate < 1000000)
hitrate = ((hitrate > 95) ? 95 : ((hitrate < 5) ? 5 : hitrate));
- if (hitrate < 1000000 && // 必中攻撃
- (t_sc_data != NULL && (t_sc_data[SC_SLEEP].timer != -1 || // ç¡çœ ã¯å¿…中
- t_sc_data[SC_STAN].timer != -1 || // スタンã¯å¿…中
- t_sc_data[SC_FREEZE].timer != -1 || (t_sc_data[SC_STONE].timer != -1 && t_sc_data[SC_STONE].val2 == 0)))) // å‡çµã¯å¿…中
- hitrate = 1000000;
- if (type == 0 && MRAND (100) >= hitrate)
+
+ if (type == DamageType::NORMAL && !random_::chance({hitrate, 100}))
{
damage = damage2 = 0;
- dmg_lv = ATK_FLEE;
+ dmg_lv = ATK::FLEE;
}
else
{
- dmg_lv = ATK_DEF;
- }
-
- if (tsd)
- {
- int cardfix = 100, i;
- cardfix = cardfix * (100 - tsd->subele[s_ele]) / 100; // 属 性ã«ã‚ˆã‚‹ãƒ€ãƒ¡ãƒ¼ã‚¸è€æ€§
- cardfix = cardfix * (100 - tsd->subrace[s_race]) / 100; // 種æ—ã«ã‚ˆã‚‹ãƒ€ãƒ¡ãƒ¼ã‚¸è€æ€§
- if (mob_db[md->mob_class].mode & 0x20)
- cardfix = cardfix * (100 - tsd->subrace[10]) / 100;
- else
- cardfix = cardfix * (100 - tsd->subrace[11]) / 100;
- for (i = 0; i < tsd->add_def_class_count; i++)
- {
- if (tsd->add_def_classid[i] == md->mob_class)
- {
- cardfix = cardfix * (100 - tsd->add_def_classrate[i]) / 100;
- break;
- }
- }
- if (flag & BF_LONG)
- cardfix = cardfix * (100 - tsd->long_attack_def_rate) / 100;
- if (flag & BF_SHORT)
- cardfix = cardfix * (100 - tsd->near_attack_def_rate) / 100;
- damage = damage * cardfix / 100;
- }
- if (t_sc_data)
- {
- int cardfix = 100;
- if (t_sc_data[SC_DEFENDER].timer != -1 && flag & BF_LONG)
- cardfix = cardfix * (100 - t_sc_data[SC_DEFENDER].val2) / 100;
- if (cardfix != 100)
- damage = damage * cardfix / 100;
- }
- if (t_sc_data && t_sc_data[SC_ASSUMPTIO].timer != -1)
- { //アシャンプティオ
- if (!map[target->m].flag.pvp)
- damage = damage / 3;
- else
- damage = damage / 2;
+ dmg_lv = ATK::DEF;
}
if (damage < 0)
damage = 0;
- // 属 性ã®é©ç”¨
- if (!((battle_config.mob_ghostring_fix == 1) && (battle_get_element (target) == 8) && (target->type == BL_PC))) // [MouseJstr]
- if (skill_num != 0 || s_ele != 0
- || !battle_config.mob_attack_attr_none)
- damage =
- battle_attr_fix (damage, s_ele, battle_get_element (target));
-
- if (sc_data && sc_data[SC_AURABLADE].timer != -1) /* オーラブレード 必中 */
- damage += sc_data[SC_AURABLADE].val1 * 10;
- if (skill_num == PA_PRESSURE) /* プレッシャー 必中? */
- damage = 700 + 100 * skill_lv;
-
- // インベナム修正
- if (skill_num == TF_POISON)
- {
- damage =
- battle_attr_fix (damage + 15 * skill_lv, s_ele,
- battle_get_element (target));
- }
- if (skill_num == MC_CARTREVOLUTION)
- {
- damage = battle_attr_fix (damage, 0, battle_get_element (target));
- }
-
// 完全回é¿ã®åˆ¤å®š
- if (skill_num == 0 && skill_lv >= 0 && tsd != NULL
- && MRAND (1000) < battle_get_flee2 (target))
+ if (skill_num == SkillID::ZERO && skill_lv >= 0 && tsd != NULL
+ && random_::chance({battle_get_flee2(target), 1000}))
{
damage = 0;
- type = 0x0b;
- dmg_lv = ATK_LUCKY;
+ type = DamageType::FLEE2;
+ dmg_lv = ATK::LUCKY;
}
if (battle_config.enemy_perfect_flee)
{
- if (skill_num == 0 && skill_lv >= 0 && tmd != NULL
- && MRAND (1000) < battle_get_flee2 (target))
+ if (skill_num == SkillID::ZERO && skill_lv >= 0 && tmd != NULL
+ && random_::chance({battle_get_flee2(target), 1000}))
{
damage = 0;
- type = 0x0b;
- dmg_lv = ATK_LUCKY;
+ type = DamageType::FLEE2;
+ dmg_lv = ATK::LUCKY;
}
}
// if(def1 >= 1000000 && damage > 0)
- if (t_mode & 0x40 && damage > 0)
+ if (bool(t_mode & MobMode::PLANT) && damage > 0)
damage = 1;
- if (tsd && tsd->special_state.no_weapon_damage)
- damage = 0;
-
- if (skill_num != CR_GRANDCROSS)
- damage =
- battle_calc_damage (src, target, damage, div_, skill_num,
- skill_lv, flag);
+ damage = battle_calc_damage(src, target, damage, div_,
+ skill_num, skill_lv, flag);
wd.damage = damage;
wd.damage2 = 0;
wd.type = type;
wd.div_ = div_;
- wd.amotion = battle_get_amotion (src);
- if (skill_num == KN_AUTOCOUNTER)
- wd.amotion >>= 1;
- wd.dmotion = battle_get_dmotion (target);
- wd.blewcount = blewcount;
+ wd.amotion = battle_get_amotion(src);
+ wd.dmotion = battle_get_dmotion(target);
wd.flag = flag;
wd.dmg_lv = dmg_lv;
return wd;
}
-int battle_is_unarmed (struct block_list *bl)
+int battle_is_unarmed(struct block_list *bl)
{
if (!bl)
return 0;
- if (bl->type == BL_PC)
+ if (bl->type == BL::PC)
{
struct map_session_data *sd = (struct map_session_data *) bl;
- return (sd->equip_index[EQUIP_SHIELD] == -1
- && sd->equip_index[EQUIP_WEAPON] == -1);
+ return (sd->equip_index[EQUIP::SHIELD] == -1
+ && sd->equip_index[EQUIP::WEAPON] == -1);
}
else
return 0;
@@ -2670,104 +1304,57 @@ int battle_is_unarmed (struct block_list *bl)
* PCã®æ­¦å™¨ã«ã‚ˆã‚‹æ”»æ’ƒ
*-------------------------------------------------------------------------
*/
-static struct Damage battle_calc_pc_weapon_attack (struct block_list *src,
+static
+struct Damage battle_calc_pc_weapon_attack(struct block_list *src,
struct block_list *target,
- int skill_num,
- int skill_lv, int wflag)
+ SkillID skill_num,
+ int skill_lv, int)
{
struct map_session_data *sd = (struct map_session_data *) src, *tsd =
NULL;
struct mob_data *tmd = NULL;
- int hitrate, flee, cri = 0, atkmin, atkmax;
- int dex, luk, target_count = 1;
- int def1 = battle_get_def (target);
- int def2 = battle_get_def2 (target);
- int t_vit = battle_get_vit (target);
- struct Damage wd;
- int damage, damage2, damage3 = 0, damage4 = 0, type, div_, blewcount =
- skill_get_blewcount (skill_num, skill_lv);
- int flag, skill, dmg_lv = 0;
- int t_mode = 0, t_race = 0, t_size = 1, s_race = 7, s_ele = 0;
- struct status_change *sc_data, *t_sc_data;
- short *sc_count;
- short *option, *opt1, *opt2;
- int atkmax_ = 0, atkmin_ = 0, s_ele_; //二刀æµç”¨
- int watk, watk_, cardfix, t_ele;
- int da = 0, i, t_class, ac_flag = 0;
- int idef_flag = 0, idef_flag_ = 0;
- int target_distance;
-
- //returnå‰ã®å‡¦ç†ãŒã‚ã‚‹ã®ã§æƒ…報出力部ã®ã¿å¤‰æ›´
- if (src == NULL || target == NULL || sd == NULL)
- {
- nullpo_info (NLP_MARK);
- memset (&wd, 0, sizeof (wd));
- return wd;
- }
+ int hitrate, flee, cri = 0, atkmin, atkmax;
+ int dex, target_count = 1;
+ int def1 = battle_get_def(target);
+ int def2 = battle_get_def2(target);
+ int t_vit = battle_get_vit(target);
+ struct Damage wd {};
+ int damage, damage2;
+ DamageType type;
+ int div_;
+ BF flag;
+ ATK dmg_lv = ATK::ZERO;
+ eptr<struct status_change, StatusChange> sc_data, t_sc_data;
+ int atkmax_ = 0, atkmin_ = 0; //二刀æµç”¨
+ int watk, watk_;
+ bool da = false;
+ int ac_flag = 0;
+ int target_distance;
+
+ nullpo_retr(wd, src);
+ nullpo_retr(wd, target);
+ nullpo_retr(wd, sd);
// アタッカー
- s_race = battle_get_race (src); //種æ—
- s_ele = battle_get_attack_element (src); //属性
- s_ele_ = battle_get_attack_element2 (src); //左手属性
- sc_data = battle_get_sc_data (src); //ステータス異常
- sc_count = battle_get_sc_count (src); //ステータス異常ã®æ•°
- option = battle_get_option (src); //é·¹ã¨ã‹ãƒšã‚³ã¨ã‹ã‚«ãƒ¼ãƒˆã¨ã‹
- opt1 = battle_get_opt1 (src); //石化ã€å‡çµã€ã‚¹ã‚¿ãƒ³ã€ç¡çœ ã€æš—é—‡
- opt2 = battle_get_opt2 (src); //毒ã€å‘ªã„ã€æ²ˆé»™ã€æš—闇?
-
- if (skill_num != CR_GRANDCROSS) //グランドクロスã§ãªã„ãªã‚‰
- sd->state.attack_type = BF_WEAPON; //攻撃タイプã¯æ­¦å™¨æ”»æ’ƒ
+ sc_data = battle_get_sc_data(src); //ステータス異常
+
+ sd->state.attack_type = BF::WEAPON; //攻撃タイプã¯æ­¦å™¨æ”»æ’ƒ
// ターゲット
- if (target->type == BL_PC) //対象ãŒPCãªã‚‰
+ if (target->type == BL::PC) //対象ãŒPCãªã‚‰
tsd = (struct map_session_data *) target; //tsdã«ä»£å…¥(tmdã¯NULL)
- else if (target->type == BL_MOB) //対象ãŒMobãªã‚‰
+ else if (target->type == BL::MOB) //対象ãŒMobãªã‚‰
tmd = (struct mob_data *) target; //tmdã«ä»£å…¥(tsdã¯NULL)
- t_race = battle_get_race (target); //対象ã®ç¨®æ—
- t_ele = battle_get_elem_type (target); //対象ã®å±žæ€§
- t_size = battle_get_size (target); //対象ã®ã‚µã‚¤ã‚º
- t_mode = battle_get_mode (target); //対象ã®Mode
- t_sc_data = battle_get_sc_data (target); //対象ã®ã‚¹ãƒ†ãƒ¼ã‚¿ã‚¹ç•°å¸¸
-
-//オートカウンター処ç†ã“ã“ã‹ã‚‰
- if ((skill_num == 0
- || (target->type == BL_PC && battle_config.pc_auto_counter_type & 2)
- || (target->type == BL_MOB
- && battle_config.monster_auto_counter_type & 2))
- && skill_lv >= 0)
- {
- if (skill_num != CR_GRANDCROSS && t_sc_data
- && t_sc_data[SC_AUTOCOUNTER].timer != -1)
- { //グランドクロスã§ãªãã€å¯¾è±¡ãŒã‚ªãƒ¼ãƒˆã‚«ã‚¦ãƒ³ã‚¿ãƒ¼çŠ¶æ…‹ã®å ´åˆ
- int dir = map_calc_dir (src, target->x, target->y), t_dir =
- battle_get_dir (target);
- int dist = distance (src->x, src->y, target->x, target->y);
- if (dist <= 0 || map_check_dir (dir, t_dir))
- { //対象ã¨ã®è·é›¢ãŒ0以下ã€ã¾ãŸã¯å¯¾è±¡ã®æ­£é¢ï¼Ÿ
- memset (&wd, 0, sizeof (wd));
- t_sc_data[SC_AUTOCOUNTER].val3 = 0;
- t_sc_data[SC_AUTOCOUNTER].val4 = 1;
- if (sc_data && sc_data[SC_AUTOCOUNTER].timer == -1)
- { //自分ãŒã‚ªãƒ¼ãƒˆã‚«ã‚¦ãƒ³ã‚¿ãƒ¼çŠ¶æ…‹
- int range = battle_get_range (target);
- if ((target->type == BL_PC && ((struct map_session_data *) target)->status.weapon != 11 && dist <= range + 1) || //対象ãŒPCã§æ­¦å™¨ãŒå¼“矢ã§ãªã射程内
- (target->type == BL_MOB && range <= 3 && dist <= range + 1)) //ã¾ãŸã¯å¯¾è±¡ãŒMobã§å°„程ãŒ3以下ã§å°„程内
- t_sc_data[SC_AUTOCOUNTER].val3 = src->id;
- }
- return wd; //ダメージ構造体を返ã—ã¦çµ‚了
- }
- else
- ac_flag = 1;
- }
- }
-//オートカウンター処ç†ã“ã“ã¾ã§
+ MobMode t_mode = battle_get_mode(target); //対象ã®Mode
+ t_sc_data = battle_get_sc_data(target); //対象ã®ã‚¹ãƒ†ãƒ¼ã‚¿ã‚¹ç•°å¸¸
- flag = BF_SHORT | BF_WEAPON | BF_NORMAL; // 攻撃ã®ç¨®é¡žã®è¨­å®š
+ flag = BF::SHORT | BF::WEAPON | BF::NORMAL; // 攻撃ã®ç¨®é¡žã®è¨­å®š
// 回é¿çŽ‡è¨ˆç®—ã€å›žé¿åˆ¤å®šã¯å¾Œã§
- flee = battle_get_flee (target);
+ flee = battle_get_flee(target);
if (battle_config.agi_penaly_type > 0 || battle_config.vit_penaly_type > 0) //AGIã€VITペナルティ設定ãŒæœ‰åŠ¹
- target_count += battle_counttargeted (target, src, battle_config.agi_penaly_count_lv); //対象ã®æ•°ã‚’算出
+ target_count += battle_counttargeted(target, src,
+ ATK(battle_config.agi_penaly_count_lv)); //対象ã®æ•°ã‚’算出
if (battle_config.agi_penaly_type > 0)
{
if (target_count >= battle_config.agi_penaly_count)
@@ -2788,34 +1375,28 @@ static struct Damage battle_calc_pc_weapon_attack (struct block_list *src,
flee = 1; //回é¿çŽ‡ã¯æœ€ä½Žã§ã‚‚1
}
}
- hitrate = battle_get_hit (src) - flee + 80; //命中率計算
+ hitrate = battle_get_hit(src) - flee + 80; //命中率計算
{ // [fate] Reduce hit chance by distance
- int dx = abs (src->x - target->x);
- int dy = abs (src->y - target->y);
- int malus_dist;
+ int dx = abs(src->x - target->x);
+ int dy = abs(src->y - target->y);
+ int malus_dist;
- target_distance = MAX (dx, dy);
+ target_distance = max(dx, dy);
malus_dist =
- MAX (0, target_distance - (skill_power (sd, AC_OWL) / 75));
+ max(0, target_distance - (skill_power(sd, SkillID::AC_OWL) / 75));
hitrate -= (malus_dist * (malus_dist + 1));
}
- dex = battle_get_dex (src); //DEX
- luk = battle_get_luk (src); //LUK
- watk = battle_get_atk (src); //ATK
- watk_ = battle_get_atk_ (src); //ATK左手
+ dex = battle_get_dex(src); //DEX
+ watk = battle_get_atk(src); //ATK
+ watk_ = battle_get_atk_(src); //ATK左手
- type = 0; // normal
+ type = DamageType::NORMAL;
div_ = 1; // single attack
- if (skill_num == HW_MAGICCRASHER)
- { /* マジッククラッシャーã¯MATKã§æ®´ã‚‹ */
- damage = damage2 = battle_get_matk1 (src); //damega,damega2åˆç™»å ´ã€base_atkã®å–å¾—
- }
- else
{
- damage = damage2 = battle_get_baseatk (&sd->bl); //damega,damega2åˆç™»å ´ã€base_atkã®å–å¾—
+ damage = damage2 = battle_get_baseatk(&sd->bl); //damega,damega2åˆç™»å ´ã€base_atkã®å–å¾—
}
if (sd->attackrange > 2)
{ // [fate] ranged weapon?
@@ -2832,45 +1413,23 @@ static struct Damage battle_calc_pc_weapon_attack (struct block_list *src,
atkmin = atkmin_ = dex; //最低ATKã¯DEXã§åˆæœŸåŒ–?
sd->state.arrow_atk = 0; //arrow_atkåˆæœŸåŒ–
- if (sd->equip_index[9] >= 0 && sd->inventory_data[sd->equip_index[9]])
+ if (sd->equip_index[EQUIP::WEAPON] >= 0 && sd->inventory_data[sd->equip_index[EQUIP::WEAPON]])
atkmin =
atkmin * (80 +
- sd->inventory_data[sd->equip_index[9]]->wlv * 20) / 100;
- if (sd->equip_index[8] >= 0 && sd->inventory_data[sd->equip_index[8]])
+ sd->inventory_data[sd->equip_index[EQUIP::WEAPON]]->wlv * 20) / 100;
+ if (sd->equip_index[EQUIP::SHIELD] >= 0 && sd->inventory_data[sd->equip_index[EQUIP::SHIELD]])
atkmin_ =
atkmin_ * (80 +
- sd->inventory_data[sd->equip_index[8]]->wlv * 20) /
+ sd->inventory_data[sd->equip_index[EQUIP::SHIELD]]->wlv * 20) /
100;
- if (sd->status.weapon == 11)
+ if (sd->status.weapon == ItemLook::BOW)
{ //武器ãŒå¼“矢ã®å ´åˆ
atkmin = watk * ((atkmin < watk) ? atkmin : watk) / 100; //弓用最低ATK計算
- flag = (flag & ~BF_RANGEMASK) | BF_LONG; //é è·é›¢æ”»æ’ƒãƒ•ãƒ©ã‚°ã‚’有効
- if (sd->arrow_ele > 0) //属性矢ãªã‚‰å±žæ€§ã‚’矢ã®å±žæ€§ã«å¤‰æ›´
- s_ele = sd->arrow_ele;
+ flag = (flag & ~BF::RANGEMASK) | BF::LONG; //é è·é›¢æ”»æ’ƒãƒ•ãƒ©ã‚°ã‚’有効
sd->state.arrow_atk = 1; //arrow_atk有効化
}
- // サイズ修正
- // ペコ騎乗ã—ã¦ã„ã¦ã€æ§ã§æ”»æ’ƒã—ãŸå ´åˆã¯ä¸­åž‹ã®ã‚µã‚¤ã‚ºä¿®æ­£ã‚’100ã«ã™ã‚‹
- // ウェãƒãƒ³ãƒ‘ーフェクション,ドレイクC
- if (((sd->special_state.no_sizefix)
- || (pc_isriding (sd)
- && (sd->status.weapon == 4 || sd->status.weapon == 5)
- && t_size == 1) || skill_num == MO_EXTREMITYFIST))
- { //ペコ騎乗ã—ã¦ã„ã¦ã€æ§ã§ä¸­åž‹ã‚’攻撃
- atkmax = watk;
- atkmax_ = watk_;
- }
- else
{
- atkmax = (watk * sd->atkmods[t_size]) / 100;
- atkmin = (atkmin * sd->atkmods[t_size]) / 100;
- atkmax_ = (watk_ * sd->atkmods_[t_size]) / 100;
- atkmin_ = (atkmin_ * sd->atkmods[t_size]) / 100;
- }
- if ((sc_data != NULL && sc_data[SC_WEAPONPERFECTION].timer != -1)
- || (sd->special_state.no_sizefix))
- { // ウェãƒãƒ³ãƒ‘ーフェクション || ドレイクカード
atkmax = watk;
atkmax_ = watk_;
}
@@ -2880,70 +1439,37 @@ static struct Damage battle_calc_pc_weapon_attack (struct block_list *src,
if (atkmin_ > atkmax_)
atkmin_ = atkmax_;
- if (sc_data != NULL && sc_data[SC_MAXIMIZEPOWER].timer != -1)
- { // マキシマイズパワー
- atkmin = atkmax;
- atkmin_ = atkmax_;
- }
-
- //ダブルアタック判定
- if (sd->weapontype1 == 0x01)
- {
- if (skill_num == 0 && skill_lv >= 0
- && (skill = pc_checkskill (sd, TF_DOUBLE)) > 0)
- da = (MRAND (100) < (skill * 5)) ? 1 : 0;
- }
-
- //三段掌
- if (skill_num == 0 && skill_lv >= 0
- && (skill = pc_checkskill (sd, MO_TRIPLEATTACK)) > 0
- && sd->status.weapon <= 16 && !sd->state.arrow_atk)
- {
- da = (MRAND (100) < (30 - skill)) ? 2 : 0;
- }
-
- if (sd->double_rate > 0 && da == 0 && skill_num == 0 && skill_lv >= 0)
- da = (MRAND (100) < sd->double_rate) ? 1 : 0;
+ if (sd->double_rate > 0 && skill_num == SkillID::ZERO && skill_lv >= 0)
+ da = random_::chance({sd->double_rate, 100});
// éŽå‰°ç²¾éŒ¬ãƒœãƒ¼ãƒŠã‚¹
if (sd->overrefine > 0)
- damage += MPRAND (1, sd->overrefine);
+ damage += random_::in(1, sd->overrefine);
if (sd->overrefine_ > 0)
- damage2 += MPRAND (1, sd->overrefine_);
+ damage2 += random_::in(1, sd->overrefine_);
- if (da == 0)
+ if (!da)
{ //ダブルアタックãŒç™ºå‹•ã—ã¦ã„ãªã„
// クリティカル計算
- cri = battle_get_critical (src);
+ cri = battle_get_critical(src);
if (sd->state.arrow_atk)
cri += sd->arrow_cri;
- if (sd->status.weapon == 16)
+ if (sd->status.weapon == ItemLook::_16)
// カタールã®å ´åˆã€ã‚¯ãƒªãƒ†ã‚£ã‚«ãƒ«ã‚’å€ã«
cri <<= 1;
- cri -= battle_get_luk (target) * 3;
- if (t_sc_data != NULL && t_sc_data[SC_SLEEP].timer != -1) // ç¡çœ ä¸­ã¯ã‚¯ãƒªãƒ†ã‚£ã‚«ãƒ«ãŒå€ã«
- cri <<= 1;
+ cri -= battle_get_luk(target) * 3;
if (ac_flag)
cri = 1000;
-
- if (skill_num == KN_AUTOCOUNTER)
- {
- if (!(battle_config.pc_auto_counter_type & 1))
- cri = 1000;
- else
- cri <<= 1;
- }
-
- if (skill_num == SN_SHARPSHOOTING && MRAND (100) < 50)
- cri = 1000;
}
if (tsd && tsd->critical_def)
cri = cri * (100 - tsd->critical_def) / 100;
- if (da == 0 && (skill_num == 0 || skill_num == KN_AUTOCOUNTER || skill_num == SN_SHARPSHOOTING) && skill_lv >= 0 && //ダブルアタックãŒç™ºå‹•ã—ã¦ã„ãªã„
- (MRAND (1000)) < cri) // 判定(スキルã®å ´åˆã¯ç„¡è¦–)
+ //ダブルアタックãŒç™ºå‹•ã—ã¦ã„ãªã„
+ // 判定(スキルã®å ´åˆã¯ç„¡è¦–)
+ if (!da && skill_num == SkillID::ZERO && skill_lv >= 0
+ && random_::chance({cri, 1000}))
{
damage += atkmax;
damage2 += atkmax_;
@@ -2954,49 +1480,18 @@ static struct Damage battle_calc_pc_weapon_attack (struct block_list *src,
}
if (sd->state.arrow_atk)
damage += sd->arrow_atk;
- type = 0x0a;
-
-/* if(def1 < 1000000) {
- if(sd->def_ratio_atk_ele & (1<<t_ele) || sd->def_ratio_atk_race & (1<<t_race)) {
- damage = (damage * (def1 + def2))/100;
- idef_flag = 1;
- }
- if(sd->def_ratio_atk_ele_ & (1<<t_ele) || sd->def_ratio_atk_race_ & (1<<t_race)) {
- damage2 = (damage2 * (def1 + def2))/100;
- idef_flag_ = 1;
- }
- if(t_mode & 0x20) {
- if(!idef_flag && sd->def_ratio_atk_race & (1<<10)) {
- damage = (damage * (def1 + def2))/100;
- idef_flag = 1;
- }
- if(!idef_flag_ && sd->def_ratio_atk_race_ & (1<<10)) {
- damage2 = (damage2 * (def1 + def2))/100;
- idef_flag_ = 1;
- }
- }
- else {
- if(!idef_flag && sd->def_ratio_atk_race & (1<<11)) {
- damage = (damage * (def1 + def2))/100;
- idef_flag = 1;
- }
- if(!idef_flag_ && sd->def_ratio_atk_race_ & (1<<11)) {
- damage2 = (damage2 * (def1 + def2))/100;
- idef_flag_ = 1;
- }
- }
- }*/
+ type = DamageType::CRITICAL;
}
else
{
- int vitbonusmax;
+ int vitbonusmax;
if (atkmax > atkmin)
- damage += atkmin + MRAND ((atkmax - atkmin + 1));
+ damage += random_::in(atkmin, atkmax);
else
damage += atkmin;
if (atkmax_ > atkmin_)
- damage2 += atkmin_ + MRAND ((atkmax_ - atkmin_ + 1));
+ damage2 += random_::in(atkmin_, atkmax_);
else
damage2 += atkmin_;
if (sd->atk_rate != 100)
@@ -3008,562 +1503,24 @@ static struct Damage battle_calc_pc_weapon_attack (struct block_list *src,
if (sd->state.arrow_atk)
{
if (sd->arrow_atk > 0)
- damage += MRAND ((sd->arrow_atk + 1));
+ damage += random_::in(0, sd->arrow_atk);
hitrate += sd->arrow_hit;
}
- if (skill_num != MO_INVESTIGATE && def1 < 1000000)
- {
- if (sd->def_ratio_atk_ele & (1 << t_ele)
- || sd->def_ratio_atk_race & (1 << t_race))
- {
- damage = (damage * (def1 + def2)) / 100;
- idef_flag = 1;
- }
- if (sd->def_ratio_atk_ele_ & (1 << t_ele)
- || sd->def_ratio_atk_race_ & (1 << t_race))
- {
- damage2 = (damage2 * (def1 + def2)) / 100;
- idef_flag_ = 1;
- }
- if (t_mode & 0x20)
- {
- if (!idef_flag && sd->def_ratio_atk_race & (1 << 10))
- {
- damage = (damage * (def1 + def2)) / 100;
- idef_flag = 1;
- }
- if (!idef_flag_ && sd->def_ratio_atk_race_ & (1 << 10))
- {
- damage2 = (damage2 * (def1 + def2)) / 100;
- idef_flag_ = 1;
- }
- }
- else
- {
- if (!idef_flag && sd->def_ratio_atk_race & (1 << 11))
- {
- damage = (damage * (def1 + def2)) / 100;
- idef_flag = 1;
- }
- if (!idef_flag_ && sd->def_ratio_atk_race_ & (1 << 11))
- {
- damage2 = (damage2 * (def1 + def2)) / 100;
- idef_flag_ = 1;
- }
- }
- }
-
- // スキル修正1(攻撃力å€åŒ–系)
- // オーãƒãƒ¼ãƒˆãƒ©ã‚¹ãƒˆ(+5% 〜 +25%),他攻撃系スキルã®å ´åˆã“ã“ã§è£œæ­£
- // ãƒãƒƒã‚·ãƒ¥,マグナムブレイク,
- // ボーリングãƒãƒƒã‚·ãƒ¥,スピアブーメラン,ブランディッシュスピア,スピアスタッブ,
- // メマーナイト,カートレボリューション
- // ダブルストレイフィング,アローシャワー,ãƒãƒ£ãƒ¼ã‚¸ã‚¢ãƒ­ãƒ¼,
- // ソニックブロー
- if (sc_data)
- { //状態異常中ã®ãƒ€ãƒ¡ãƒ¼ã‚¸è¿½åŠ 
- if (sc_data[SC_OVERTHRUST].timer != -1)
- { // オーãƒãƒ¼ãƒˆãƒ©ã‚¹ãƒˆ
- damage += damage * (5 * sc_data[SC_OVERTHRUST].val1) / 100;
- damage2 += damage2 * (5 * sc_data[SC_OVERTHRUST].val1) / 100;
- }
- if (sc_data[SC_TRUESIGHT].timer != -1)
- { // トゥルーサイト
- damage += damage * (2 * sc_data[SC_TRUESIGHT].val1) / 100;
- damage2 += damage2 * (2 * sc_data[SC_TRUESIGHT].val1) / 100;
- }
- if (sc_data[SC_BERSERK].timer != -1)
- { // ãƒãƒ¼ã‚µãƒ¼ã‚¯
- damage += damage * 50 / 100;
- damage2 += damage2 * 50 / 100;
- }
- }
-
- if (skill_num > 0)
+ if (skill_num != SkillID::ZERO && skill_num != SkillID::NEGATIVE)
{
- int i;
- if ((i = skill_get_pl (skill_num)) > 0)
- s_ele = s_ele_ = i;
-
- flag = (flag & ~BF_SKILLMASK) | BF_SKILL;
- switch (skill_num)
- {
- case SM_BASH: // ãƒãƒƒã‚·ãƒ¥
- damage = damage * (100 + 30 * skill_lv) / 100;
- damage2 = damage2 * (100 + 30 * skill_lv) / 100;
- hitrate = (hitrate * (100 + 5 * skill_lv)) / 100;
- break;
- case SM_MAGNUM: // マグナムブレイク
- damage =
- damage * (5 * skill_lv + (wflag) ? 65 : 115) / 100;
- damage2 =
- damage2 * (5 * skill_lv + (wflag) ? 65 : 115) / 100;
- break;
- case MC_MAMMONITE: // メマーナイト
- damage = damage * (100 + 50 * skill_lv) / 100;
- damage2 = damage2 * (100 + 50 * skill_lv) / 100;
- break;
- case AC_DOUBLE: // ダブルストレイフィング
- if (!sd->state.arrow_atk && sd->arrow_atk > 0)
- {
- int arr = MRAND ((sd->arrow_atk + 1));
- damage += arr;
- damage2 += arr;
- }
- damage = damage * (180 + 20 * skill_lv) / 100;
- damage2 = damage2 * (180 + 20 * skill_lv) / 100;
- div_ = 2;
- if (sd->arrow_ele > 0)
- {
- s_ele = sd->arrow_ele;
- s_ele_ = sd->arrow_ele;
- }
- flag = (flag & ~BF_RANGEMASK) | BF_LONG;
- sd->state.arrow_atk = 1;
- break;
- case AC_SHOWER: // アローシャワー
- if (!sd->state.arrow_atk && sd->arrow_atk > 0)
- {
- int arr = MRAND ((sd->arrow_atk + 1));
- damage += arr;
- damage2 += arr;
- }
- damage = damage * (75 + 5 * skill_lv) / 100;
- damage2 = damage2 * (75 + 5 * skill_lv) / 100;
- if (sd->arrow_ele > 0)
- {
- s_ele = sd->arrow_ele;
- s_ele_ = sd->arrow_ele;
- }
- flag = (flag & ~BF_RANGEMASK) | BF_LONG;
- sd->state.arrow_atk = 1;
- break;
- case AC_CHARGEARROW: // ãƒãƒ£ãƒ¼ã‚¸ã‚¢ãƒ­ãƒ¼
- if (!sd->state.arrow_atk && sd->arrow_atk > 0)
- {
- int arr = MRAND ((sd->arrow_atk + 1));
- damage += arr;
- damage2 += arr;
- }
- damage = damage * 150 / 100;
- damage2 = damage2 * 150 / 100;
- if (sd->arrow_ele > 0)
- {
- s_ele = sd->arrow_ele;
- s_ele_ = sd->arrow_ele;
- }
- flag = (flag & ~BF_RANGEMASK) | BF_LONG;
- sd->state.arrow_atk = 1;
- break;
- case KN_PIERCE: // ピアース
- damage = damage * (100 + 10 * skill_lv) / 100;
- damage2 = damage2 * (100 + 10 * skill_lv) / 100;
- hitrate = hitrate * (100 + 5 * skill_lv) / 100;
- div_ = t_size + 1;
- damage *= div_;
- damage2 *= div_;
- break;
- case KN_SPEARSTAB: // スピアスタブ
- damage = damage * (100 + 15 * skill_lv) / 100;
- damage2 = damage2 * (100 + 15 * skill_lv) / 100;
- break;
- case KN_SPEARBOOMERANG: // スピアブーメラン
- damage = damage * (100 + 50 * skill_lv) / 100;
- damage2 = damage2 * (100 + 50 * skill_lv) / 100;
- flag = (flag & ~BF_RANGEMASK) | BF_LONG;
- break;
- case KN_BRANDISHSPEAR: // ブランディッシュスピア
- damage = damage * (100 + 20 * skill_lv) / 100;
- damage2 = damage2 * (100 + 20 * skill_lv) / 100;
- if (skill_lv > 3 && wflag == 1)
- damage3 += damage / 2;
- if (skill_lv > 6 && wflag == 1)
- damage3 += damage / 4;
- if (skill_lv > 9 && wflag == 1)
- damage3 += damage / 8;
- if (skill_lv > 6 && wflag == 2)
- damage3 += damage / 2;
- if (skill_lv > 9 && wflag == 2)
- damage3 += damage / 4;
- if (skill_lv > 9 && wflag == 3)
- damage3 += damage / 2;
- damage += damage3;
- if (skill_lv > 3 && wflag == 1)
- damage4 += damage2 / 2;
- if (skill_lv > 6 && wflag == 1)
- damage4 += damage2 / 4;
- if (skill_lv > 9 && wflag == 1)
- damage4 += damage2 / 8;
- if (skill_lv > 6 && wflag == 2)
- damage4 += damage2 / 2;
- if (skill_lv > 9 && wflag == 2)
- damage4 += damage2 / 4;
- if (skill_lv > 9 && wflag == 3)
- damage4 += damage2 / 2;
- damage2 += damage4;
- blewcount = 0;
- break;
- case KN_BOWLINGBASH: // ボウリングãƒãƒƒã‚·ãƒ¥
- damage = damage * (100 + 50 * skill_lv) / 100;
- damage2 = damage2 * (100 + 50 * skill_lv) / 100;
- blewcount = 0;
- break;
- case KN_AUTOCOUNTER:
- if (battle_config.pc_auto_counter_type & 1)
- hitrate += 20;
- else
- hitrate = 1000000;
- flag = (flag & ~BF_SKILLMASK) | BF_NORMAL;
- break;
- case AS_SONICBLOW: // ソニックブロウ
- hitrate += 30; // hitrate +30, thanks to midas
- damage = damage * (300 + 50 * skill_lv) / 100;
- damage2 = damage2 * (300 + 50 * skill_lv) / 100;
- div_ = 8;
- break;
- case TF_SPRINKLESAND: // ç ‚ã¾ã
- damage = damage * 125 / 100;
- damage2 = damage2 * 125 / 100;
- break;
- case MC_CARTREVOLUTION: // カートレボリューション
- if (sd->cart_max_weight > 0 && sd->cart_weight > 0)
- {
- damage =
- (damage *
- (150 + pc_checkskill (sd, BS_WEAPONRESEARCH) +
- (sd->cart_weight * 100 /
- sd->cart_max_weight))) / 100;
- damage2 =
- (damage2 *
- (150 + pc_checkskill (sd, BS_WEAPONRESEARCH) +
- (sd->cart_weight * 100 /
- sd->cart_max_weight))) / 100;
- }
- else
- {
- damage = (damage * 150) / 100;
- damage2 = (damage2 * 150) / 100;
- }
- break;
- // 以下MOB
- case NPC_COMBOATTACK: // 多段攻撃
- div_ = skill_get_num (skill_num, skill_lv);
- damage *= div_;
- damage2 *= div_;
- break;
- case NPC_RANDOMATTACK: // ランダムATK攻撃
- damage = damage * (MPRAND (50, 150)) / 100;
- damage2 = damage2 * (MPRAND (50, 150)) / 100;
- break;
- // 属性攻撃(é©å½“)
- case NPC_WATERATTACK:
- case NPC_GROUNDATTACK:
- case NPC_FIREATTACK:
- case NPC_WINDATTACK:
- case NPC_POISONATTACK:
- case NPC_HOLYATTACK:
- case NPC_DARKNESSATTACK:
- case NPC_TELEKINESISATTACK:
- damage = damage * (100 + 25 * skill_lv) / 100;
- damage2 = damage2 * (100 + 25 * skill_lv) / 100;
- break;
- case NPC_GUIDEDATTACK:
- hitrate = 1000000;
- break;
- case NPC_RANGEATTACK:
- flag = (flag & ~BF_RANGEMASK) | BF_LONG;
- break;
- case NPC_PIERCINGATT:
- flag = (flag & ~BF_RANGEMASK) | BF_SHORT;
- break;
- case RG_BACKSTAP: // ãƒãƒƒã‚¯ã‚¹ã‚¿ãƒ–
- if (battle_config.backstab_bow_penalty == 1
- && sd->status.weapon == 11)
- {
- damage = (damage * (300 + 40 * skill_lv) / 100) / 2;
- damage2 = (damage2 * (300 + 40 * skill_lv) / 100) / 2;
- }
- else
- {
- damage = damage * (300 + 40 * skill_lv) / 100;
- damage2 = damage2 * (300 + 40 * skill_lv) / 100;
- }
- hitrate = 1000000;
- break;
- case RG_RAID: // サプライズアタック
- damage = damage * (100 + 40 * skill_lv) / 100;
- damage2 = damage2 * (100 + 40 * skill_lv) / 100;
- break;
- case RG_INTIMIDATE: // インティミデイト
- damage = damage * (100 + 30 * skill_lv) / 100;
- damage2 = damage2 * (100 + 30 * skill_lv) / 100;
- break;
- case CR_SHIELDCHARGE: // シールドãƒãƒ£ãƒ¼ã‚¸
- damage = damage * (100 + 20 * skill_lv) / 100;
- damage2 = damage2 * (100 + 20 * skill_lv) / 100;
- flag = (flag & ~BF_RANGEMASK) | BF_SHORT;
- s_ele = 0;
- break;
- case CR_SHIELDBOOMERANG: // シールドブーメラン
- damage = damage * (100 + 30 * skill_lv) / 100;
- damage2 = damage2 * (100 + 30 * skill_lv) / 100;
- flag = (flag & ~BF_RANGEMASK) | BF_LONG;
- s_ele = 0;
- break;
- case CR_HOLYCROSS: // ホーリークロス
- damage = damage * (100 + 35 * skill_lv) / 100;
- damage2 = damage2 * (100 + 35 * skill_lv) / 100;
- div_ = 2;
- break;
- case CR_GRANDCROSS:
- hitrate = 1000000;
- break;
- case AM_DEMONSTRATION: // デモンストレーション
- damage = damage * (100 + 20 * skill_lv) / 100;
- damage2 = damage2 * (100 + 20 * skill_lv) / 100;
- break;
- case AM_ACIDTERROR: // アシッドテラー
- damage = damage * (100 + 40 * skill_lv) / 100;
- damage2 = damage2 * (100 + 40 * skill_lv) / 100;
- break;
- case MO_FINGEROFFENSIVE: //指弾
- if (battle_config.finger_offensive_type == 0)
- {
- damage =
- damage * (100 +
- 50 * skill_lv) / 100 *
- sd->spiritball_old;
- damage2 =
- damage2 * (100 +
- 50 * skill_lv) / 100 *
- sd->spiritball_old;
- div_ = sd->spiritball_old;
- }
- else
- {
- damage = damage * (100 + 50 * skill_lv) / 100;
- damage2 = damage2 * (100 + 50 * skill_lv) / 100;
- div_ = 1;
- }
- break;
- case MO_INVESTIGATE: // 発 å‹
- if (def1 < 1000000)
- {
- damage =
- damage * (100 + 75 * skill_lv) / 100 * (def1 +
- def2) /
- 100;
- damage2 =
- damage2 * (100 + 75 * skill_lv) / 100 * (def1 +
- def2) /
- 100;
- }
- hitrate = 1000000;
- s_ele = 0;
- s_ele_ = 0;
- break;
- case MO_EXTREMITYFIST: // 阿修羅覇鳳拳
- damage =
- damage * (8 + ((sd->status.sp) / 10)) + 250 +
- (skill_lv * 150);
- damage2 =
- damage2 * (8 + ((sd->status.sp) / 10)) + 250 +
- (skill_lv * 150);
- sd->status.sp = 0;
- clif_updatestatus (sd, SP_SP);
- hitrate = 1000000;
- s_ele = 0;
- s_ele_ = 0;
- break;
- case MO_CHAINCOMBO: // 連打掌
- damage = damage * (150 + 50 * skill_lv) / 100;
- damage2 = damage2 * (150 + 50 * skill_lv) / 100;
- div_ = 4;
- break;
- case MO_COMBOFINISH: // 猛é¾æ‹³
- damage = damage * (240 + 60 * skill_lv) / 100;
- damage2 = damage2 * (240 + 60 * skill_lv) / 100;
- break;
- case BA_MUSICALSTRIKE: // ミュージカルストライク
- if (!sd->state.arrow_atk && sd->arrow_atk > 0)
- {
- int arr = MRAND ((sd->arrow_atk + 1));
- damage += arr;
- damage2 += arr;
- }
- damage = damage * (100 + 50 * skill_lv) / 100;
- damage2 = damage2 * (100 + 50 * skill_lv) / 100;
- if (sd->arrow_ele > 0)
- {
- s_ele = sd->arrow_ele;
- s_ele_ = sd->arrow_ele;
- }
- flag = (flag & ~BF_RANGEMASK) | BF_LONG;
- sd->state.arrow_atk = 1;
- break;
- case DC_THROWARROW: // 矢撃ã¡
- if (!sd->state.arrow_atk && sd->arrow_atk > 0)
- {
- int arr = MRAND ((sd->arrow_atk + 1));
- damage += arr;
- damage2 += arr;
- }
- damage = damage * (100 + 50 * skill_lv) / 100;
- damage2 = damage2 * (100 + 50 * skill_lv) / 100;
- if (sd->arrow_ele > 0)
- {
- s_ele = sd->arrow_ele;
- s_ele_ = sd->arrow_ele;
- }
- flag = (flag & ~BF_RANGEMASK) | BF_LONG;
- sd->state.arrow_atk = 1;
- break;
- case CH_TIGERFIST: // ä¼è™Žæ‹³
- damage = damage * (100 + 20 * skill_lv) / 100;
- damage2 = damage2 * (100 + 20 * skill_lv) / 100;
- break;
- case CH_CHAINCRUSH: // 連柱崩撃
- damage = damage * (100 + 20 * skill_lv) / 100;
- damage2 = damage2 * (100 + 20 * skill_lv) / 100;
- div_ = skill_get_num (skill_num, skill_lv);
- break;
- case CH_PALMSTRIKE: // 猛虎硬派山
- damage = damage * (50 + 100 * skill_lv) / 100;
- damage2 = damage2 * (50 + 100 * skill_lv) / 100;
- break;
- case LK_SPIRALPIERCE: /* スパイラルピアース */
- damage = damage * (100 + 50 * skill_lv) / 100; //増加é‡ãŒåˆ†ã‹ã‚‰ãªã„ã®ã§é©å½“ã«
- damage2 = damage2 * (100 + 50 * skill_lv) / 100; //増加é‡ãŒåˆ†ã‹ã‚‰ãªã„ã®ã§é©å½“ã«
- div_ = 5;
- if (tsd)
- tsd->canmove_tick = gettick () + 1000;
- else if (tmd)
- tmd->canmove_tick = gettick () + 1000;
- break;
- case LK_HEADCRUSH: /* ヘッドクラッシュ */
- damage = damage * (100 + 20 * skill_lv) / 100;
- damage2 = damage2 * (100 + 20 * skill_lv) / 100;
- break;
- case LK_JOINTBEAT: /* ジョイントビート */
- damage = damage * (50 + 10 * skill_lv) / 100;
- damage2 = damage2 * (50 + 10 * skill_lv) / 100;
- break;
- case ASC_METEORASSAULT: /* メテオアサルト */
- damage = damage * (40 + 40 * skill_lv) / 100;
- damage2 = damage2 * (40 + 40 * skill_lv) / 100;
- break;
- case SN_SHARPSHOOTING: /* シャープシューティング */
- damage += damage * (30 * skill_lv) / 100;
- damage2 += damage2 * (30 * skill_lv) / 100;
- break;
- case CG_ARROWVULCAN: /* アローãƒãƒ«ã‚«ãƒ³ */
- damage = damage * (160 + 40 * skill_lv) / 100;
- damage2 = damage2 * (160 + 40 * skill_lv) / 100;
- div_ = 9;
- break;
- case AS_SPLASHER: /* ベナムスプラッシャー */
- damage =
- damage * (200 + 20 * skill_lv +
- 20 * pc_checkskill (sd,
- AS_POISONREACT)) / 100;
- damage2 =
- damage2 * (200 + 20 * skill_lv +
- 20 * pc_checkskill (sd,
- AS_POISONREACT)) / 100;
- break;
- case PA_SACRIFICE:
- if (sd)
- {
- int hp, mhp, damage3;
- hp = battle_get_hp (src);
- mhp = battle_get_max_hp (src);
- damage3 = mhp * ((skill_lv / 2) + (50 / 100)) / 100;
- damage =
- (((skill_lv * 15) + 90) / 100) * damage3 / 100;
- damage2 =
- (((skill_lv * 15) + 90) / 100) * damage3 / 100;
- }
- break;
- case ASC_BREAKER: // -- moonsoul (special damage for ASC_BREAKER skill)
- if (sd)
- {
- int damage3;
- int mdef1 = battle_get_mdef (target);
- int mdef2 = battle_get_mdef2 (target);
- int imdef_flag = 0;
-
- damage =
- ((damage * 5) +
- (skill_lv * battle_get_int (src) * 5) +
- MRAND (500) + 500) / 2;
- damage2 =
- ((damage2 * 5) +
- (skill_lv * battle_get_int (src) * 5) +
- MRAND (500) + 500) / 2;
- damage3 = damage;
- hitrate = 1000000;
-
- if (sd->ignore_mdef_ele & (1 << t_ele)
- || sd->ignore_mdef_race & (1 << t_race))
- imdef_flag = 1;
- if (t_mode & 0x20)
- {
- if (sd->ignore_mdef_race & (1 << 10))
- imdef_flag = 1;
- }
- else
- {
- if (sd->ignore_mdef_race & (1 << 11))
- imdef_flag = 1;
- }
- if (!imdef_flag)
- {
- if (battle_config.magic_defense_type)
- {
- damage3 =
- damage3 -
- (mdef1 *
- battle_config.magic_defense_type) -
- mdef2;
- }
- else
- {
- damage3 =
- (damage3 * (100 - mdef1)) / 100 - mdef2;
- }
- }
-
- if (damage3 < 1)
- damage3 = 1;
-
- damage3 =
- battle_attr_fix (damage2, s_ele_,
- battle_get_element (target));
- }
- break;
- }
- }
- if (da == 2)
- { //三段掌ãŒç™ºå‹•ã—ã¦ã„ã‚‹ã‹
- type = 0x08;
- div_ = 255; //三段掌用ã«â€¦
- damage =
- damage * (100 +
- 20 * pc_checkskill (sd, MO_TRIPLEATTACK)) / 100;
+ flag = (flag & ~BF::SKILLMASK) | BF::SKILL;
}
- if (skill_num != NPC_CRITICALSLASH)
{
// 対 象ã®é˜²å¾¡åŠ›ã«ã‚ˆã‚‹ãƒ€ãƒ¡ãƒ¼ã‚¸ã®æ¸›å°‘
// ディãƒã‚¤ãƒ³ãƒ—ロテクション(ã“ã“ã§ã„ã„ã®ã‹ãªï¼Ÿï¼‰
- if (skill_num != MO_INVESTIGATE && skill_num != MO_EXTREMITYFIST
- && skill_num != KN_AUTOCOUNTER && def1 < 1000000)
+ if (def1 < 1000000)
{ //DEF, VIT無視
- int t_def;
+ int t_def;
target_count =
- 1 + battle_counttargeted (target, src,
- battle_config.vit_penaly_count_lv);
+ 1 + battle_counttargeted(target, src,
+ ATK(battle_config.vit_penaly_count_lv)); // FIXME
if (battle_config.vit_penaly_type > 0)
{
if (target_count >= battle_config.vit_penaly_count)
@@ -3617,105 +1574,30 @@ static struct Damage battle_calc_pc_weapon_attack (struct block_list *src,
}
t_def = def2 * 8 / 10;
vitbonusmax = (t_vit / 20) * (t_vit / 20) - 1;
- if (sd->ignore_def_ele & (1 << t_ele)
- || sd->ignore_def_race & (1 << t_race))
- idef_flag = 1;
- if (sd->ignore_def_ele_ & (1 << t_ele)
- || sd->ignore_def_race_ & (1 << t_race))
- idef_flag_ = 1;
- if (t_mode & 0x20)
- {
- if (sd->ignore_def_race & (1 << 10))
- idef_flag = 1;
- if (sd->ignore_def_race_ & (1 << 10))
- idef_flag_ = 1;
- }
- else
- {
- if (sd->ignore_def_race & (1 << 11))
- idef_flag = 1;
- if (sd->ignore_def_race_ & (1 << 11))
- idef_flag_ = 1;
- }
- if (!idef_flag)
{
- if (battle_config.player_defense_type)
- {
- damage =
- damage -
- (def1 * battle_config.player_defense_type) -
- t_def -
- ((vitbonusmax <
- 1) ? 0 : MRAND ((vitbonusmax + 1)));
- }
- else
{
- damage =
- damage * (100 - def1) / 100 - t_def -
- ((vitbonusmax <
- 1) ? 0 : MRAND ((vitbonusmax + 1)));
+ damage = damage * (100 - def1) / 100;
+ damage -= t_def;
+ if (vitbonusmax > 0)
+ damage -= random_::in(0, vitbonusmax);
}
}
- if (!idef_flag_)
{
- if (battle_config.player_defense_type)
{
- damage2 =
- damage2 -
- (def1 * battle_config.player_defense_type) -
- t_def -
- ((vitbonusmax <
- 1) ? 0 : MRAND ((vitbonusmax + 1)));
- }
- else
- {
- damage2 =
- damage2 * (100 - def1) / 100 - t_def -
- ((vitbonusmax <
- 1) ? 0 : MRAND ((vitbonusmax + 1)));
+ damage2 = damage2 * (100 - def1) / 100;
+ damage2 -= t_def;
+ if (vitbonusmax > 0)
+ damage2 -= random_::in(0, vitbonusmax);
}
}
}
}
}
// 精錬ダメージã®è¿½åŠ 
- if (skill_num != MO_INVESTIGATE && skill_num != MO_EXTREMITYFIST)
{ //DEF, VIT無視
- damage += battle_get_atk2 (src);
- damage2 += battle_get_atk_2 (src);
- }
- if (skill_num == CR_SHIELDBOOMERANG)
- {
- if (sd->equip_index[8] >= 0)
- {
- int index = sd->equip_index[8];
- if (sd->inventory_data[index]
- && sd->inventory_data[index]->type == 5)
- {
- damage += sd->inventory_data[index]->weight / 10;
- damage +=
- sd->status.inventory[index].refine * pc_getrefinebonus (0,
- 1);
- }
- }
- }
- if (skill_num == LK_SPIRALPIERCE)
- { /* スパイラルピアース */
- if (sd->equip_index[9] >= 0)
- { //é‡é‡ã§è¿½åŠ ãƒ€ãƒ¡ãƒ¼ã‚¸ã‚‰ã—ã„ã®ã§ã‚·ãƒ¼ãƒ«ãƒ‰ãƒ–ーメランをå‚考ã«è¿½åŠ 
- int index = sd->equip_index[9];
- if (sd->inventory_data[index]
- && sd->inventory_data[index]->type == 4)
- {
- damage +=
- (int) (double) (sd->inventory_data[index]->weight *
- (0.8 * skill_lv * 4 / 10));
- damage +=
- sd->status.inventory[index].refine * pc_getrefinebonus (0,
- 1);
- }
- }
+ damage += battle_get_atk2(src);
+ damage2 += battle_get_atk_2(src);
}
// 0未満ã ã£ãŸå ´åˆ1ã«è£œæ­£
@@ -3726,222 +1608,35 @@ static struct Damage battle_calc_pc_weapon_attack (struct block_list *src,
// スキル修正2(修練系)
// 修練ダメージ(å³æ‰‹ã®ã¿) ソニックブロー時ã¯åˆ¥å‡¦ç†ï¼ˆ1æ’ƒã«ä»˜ã1/8é©å¿œ)
- if (skill_num != MO_INVESTIGATE && skill_num != MO_EXTREMITYFIST
- && skill_num != CR_GRANDCROSS)
{ //修練ダメージ無視
- damage = battle_addmastery (sd, target, damage, 0);
- damage2 = battle_addmastery (sd, target, damage2, 1);
}
if (sd->perfect_hit > 0)
{
- if (MRAND (100) < sd->perfect_hit)
+ if (random_::chance({sd->perfect_hit, 100}))
hitrate = 1000000;
}
// 回é¿ä¿®æ­£
hitrate = (hitrate < 5) ? 5 : hitrate;
- if (hitrate < 1000000 && // 必中攻撃
- (t_sc_data != NULL && (t_sc_data[SC_SLEEP].timer != -1 || // ç¡çœ ã¯å¿…中
- t_sc_data[SC_STAN].timer != -1 || // スタンã¯å¿…中
- t_sc_data[SC_FREEZE].timer != -1 || (t_sc_data[SC_STONE].timer != -1 && t_sc_data[SC_STONE].val2 == 0)))) // å‡çµã¯å¿…中
- hitrate = 1000000;
- if (type == 0 && MRAND (100) >= hitrate)
+ if (type == DamageType::NORMAL && !random_::chance({hitrate, 100}))
{
damage = damage2 = 0;
- dmg_lv = ATK_FLEE;
- }
- else
- {
- dmg_lv = ATK_DEF;
- }
- // スキル修正3(武器研究)
- if ((skill = pc_checkskill (sd, BS_WEAPONRESEARCH)) > 0)
- {
- damage += skill * 2;
- damage2 += skill * 2;
- }
- //Advanced Katar Research by zanetheinsane
- if (sd->weapontype1 == 0x10 || sd->weapontype2 == 0x10)
- {
- if ((skill = pc_checkskill (sd, ASC_KATAR)) > 0)
- {
- damage += (damage * ((skill * 2) + 10)) / 100;
- }
- }
-
-//スキルã«ã‚ˆã‚‹ãƒ€ãƒ¡ãƒ¼ã‚¸è£œæ­£ã“ã“ã¾ã§
-
-//カードã«ã‚ˆã‚‹ãƒ€ãƒ¡ãƒ¼ã‚¸è¿½åŠ å‡¦ç†ã“ã“ã‹ã‚‰
- cardfix = 100;
- if (!sd->state.arrow_atk)
- { //弓矢以外
- if (!battle_config.left_cardfix_to_right)
- { //左手カード補正設定無ã—
- cardfix = cardfix * (100 + sd->addrace[t_race]) / 100; // 種æ—ã«ã‚ˆã‚‹ãƒ€ãƒ¡ãƒ¼ã‚¸ä¿®æ­£
- cardfix = cardfix * (100 + sd->addele[t_ele]) / 100; // 属性ã«ã‚ˆã‚‹ãƒ€ãƒ¡ãƒ¼ã‚¸ä¿®æ­£
- cardfix = cardfix * (100 + sd->addsize[t_size]) / 100; // サイズã«ã‚ˆã‚‹ãƒ€ãƒ¡ãƒ¼ã‚¸ä¿®æ­£
- }
- else
- {
- cardfix = cardfix * (100 + sd->addrace[t_race] + sd->addrace_[t_race]) / 100; // 種æ—ã«ã‚ˆã‚‹ãƒ€ãƒ¡ãƒ¼ã‚¸ä¿®æ­£(左手ã«ã‚ˆã‚‹è¿½åŠ ã‚ã‚Š)
- cardfix = cardfix * (100 + sd->addele[t_ele] + sd->addele_[t_ele]) / 100; // 属性ã«ã‚ˆã‚‹ãƒ€ãƒ¡ãƒ¼ã‚¸ä¿®æ­£(左手ã«ã‚ˆã‚‹è¿½åŠ ã‚ã‚Š)
- cardfix = cardfix * (100 + sd->addsize[t_size] + sd->addsize_[t_size]) / 100; // サイズã«ã‚ˆã‚‹ãƒ€ãƒ¡ãƒ¼ã‚¸ä¿®æ­£(左手ã«ã‚ˆã‚‹è¿½åŠ ã‚ã‚Š)
- }
+ dmg_lv = ATK::FLEE;
}
else
- { //弓矢
- cardfix = cardfix * (100 + sd->addrace[t_race] + sd->arrow_addrace[t_race]) / 100; // 種æ—ã«ã‚ˆã‚‹ãƒ€ãƒ¡ãƒ¼ã‚¸ä¿®æ­£(弓矢ã«ã‚ˆã‚‹è¿½åŠ ã‚ã‚Š)
- cardfix = cardfix * (100 + sd->addele[t_ele] + sd->arrow_addele[t_ele]) / 100; // 属性ã«ã‚ˆã‚‹ãƒ€ãƒ¡ãƒ¼ã‚¸ä¿®æ­£(弓矢ã«ã‚ˆã‚‹è¿½åŠ ã‚ã‚Š)
- cardfix = cardfix * (100 + sd->addsize[t_size] + sd->arrow_addsize[t_size]) / 100; // サイズã«ã‚ˆã‚‹ãƒ€ãƒ¡ãƒ¼ã‚¸ä¿®æ­£(弓矢ã«ã‚ˆã‚‹è¿½åŠ ã‚ã‚Š)
- }
- if (t_mode & 0x20)
- { //ボス
- if (!sd->state.arrow_atk)
- { //弓矢攻撃以外ãªã‚‰
- if (!battle_config.left_cardfix_to_right) //左手カード補正設定無ã—
- cardfix = cardfix * (100 + sd->addrace[10]) / 100; //ボスモンスターã«è¿½åŠ ãƒ€ãƒ¡ãƒ¼ã‚¸
- else //左手カード補正設定ã‚ã‚Š
- cardfix = cardfix * (100 + sd->addrace[10] + sd->addrace_[10]) / 100; //ボスモンスターã«è¿½åŠ ãƒ€ãƒ¡ãƒ¼ã‚¸(左手ã«ã‚ˆã‚‹è¿½åŠ ã‚ã‚Š)
- }
- else //弓矢攻撃
- cardfix = cardfix * (100 + sd->addrace[10] + sd->arrow_addrace[10]) / 100; //ボスモンスターã«è¿½åŠ ãƒ€ãƒ¡ãƒ¼ã‚¸(弓矢ã«ã‚ˆã‚‹è¿½åŠ ã‚ã‚Š)
- }
- else
- { //ボスã˜ã‚ƒãªã„
- if (!sd->state.arrow_atk)
- { //弓矢攻撃以外
- if (!battle_config.left_cardfix_to_right) //左手カード補正設定無ã—
- cardfix = cardfix * (100 + sd->addrace[11]) / 100; //ボス以外モンスターã«è¿½åŠ ãƒ€ãƒ¡ãƒ¼ã‚¸
- else //左手カード補正設定ã‚ã‚Š
- cardfix = cardfix * (100 + sd->addrace[11] + sd->addrace_[11]) / 100; //ボス以外モンスターã«è¿½åŠ ãƒ€ãƒ¡ãƒ¼ã‚¸(左手ã«ã‚ˆã‚‹è¿½åŠ ã‚ã‚Š)
- }
- else
- cardfix = cardfix * (100 + sd->addrace[11] + sd->arrow_addrace[11]) / 100; //ボス以外モンスターã«è¿½åŠ ãƒ€ãƒ¡ãƒ¼ã‚¸(弓矢ã«ã‚ˆã‚‹è¿½åŠ ã‚ã‚Š)
- }
- //特定Class用補正処ç†(少女ã®æ—¥è¨˜â†’ボンゴン用?)
- t_class = battle_get_class (target);
- for (i = 0; i < sd->add_damage_class_count; i++)
{
- if (sd->add_damage_classid[i] == t_class)
- {
- cardfix = cardfix * (100 + sd->add_damage_classrate[i]) / 100;
- break;
- }
+ dmg_lv = ATK::DEF;
}
- if (skill_num != CR_GRANDCROSS || !battle_config.gx_cardfix)
- damage = damage * cardfix / 100; //カード補正ã«ã‚ˆã‚‹ãƒ€ãƒ¡ãƒ¼ã‚¸å¢—加
-//カードã«ã‚ˆã‚‹ãƒ€ãƒ¡ãƒ¼ã‚¸å¢—加処ç†ã“ã“ã¾ã§
-
-//カードã«ã‚ˆã‚‹ãƒ€ãƒ¡ãƒ¼ã‚¸è¿½åŠ å‡¦ç†(左手)ã“ã“ã‹ã‚‰
- cardfix = 100;
- if (!battle_config.left_cardfix_to_right)
- { //左手カード補正設定無ã—
- cardfix = cardfix * (100 + sd->addrace_[t_race]) / 100; // 種æ—ã«ã‚ˆã‚‹ãƒ€ãƒ¡ãƒ¼ã‚¸ä¿®æ­£å·¦æ‰‹
- cardfix = cardfix * (100 + sd->addele_[t_ele]) / 100; // 属 性ã«ã‚ˆã‚‹ãƒ€ãƒ¡ãƒ¼ã‚¸ä¿®æ­£å·¦æ‰‹
- cardfix = cardfix * (100 + sd->addsize_[t_size]) / 100; // サイズã«ã‚ˆã‚‹ãƒ€ãƒ¡ãƒ¼ã‚¸ä¿®æ­£å·¦æ‰‹
- if (t_mode & 0x20) //ボス
- cardfix = cardfix * (100 + sd->addrace_[10]) / 100; //ボスモンスターã«è¿½åŠ ãƒ€ãƒ¡ãƒ¼ã‚¸å·¦æ‰‹
- else
- cardfix = cardfix * (100 + sd->addrace_[11]) / 100; //ボス以外モンスターã«è¿½åŠ ãƒ€ãƒ¡ãƒ¼ã‚¸å·¦æ‰‹
- }
- //特定Class用補正処ç†å·¦æ‰‹(少女ã®æ—¥è¨˜â†’ボンゴン用?)
- for (i = 0; i < sd->add_damage_class_count_; i++)
- {
- if (sd->add_damage_classid_[i] == t_class)
- {
- cardfix = cardfix * (100 + sd->add_damage_classrate_[i]) / 100;
- break;
- }
- }
- if (skill_num != CR_GRANDCROSS)
- damage2 = damage2 * cardfix / 100; //カード補正ã«ã‚ˆã‚‹å·¦æ‰‹ãƒ€ãƒ¡ãƒ¼ã‚¸å¢—加
-//カードã«ã‚ˆã‚‹ãƒ€ãƒ¡ãƒ¼ã‚¸å¢—加処ç†(左手)ã“ã“ã¾ã§
-
-// -- moonsoul (cardfix for magic damage portion of ASC_BREAKER)
- if (skill_num == ASC_BREAKER)
- damage3 = damage3 * cardfix / 100;
-
-//カードã«ã‚ˆã‚‹ãƒ€ãƒ¡ãƒ¼ã‚¸æ¸›è¡°å‡¦ç†ã“ã“ã‹ã‚‰
- if (tsd)
- { //対象ãŒPCã®å ´åˆ
- cardfix = 100;
- cardfix = cardfix * (100 - tsd->subrace[s_race]) / 100; // 種æ—ã«ã‚ˆã‚‹ãƒ€ãƒ¡ãƒ¼ã‚¸è€æ€§
- cardfix = cardfix * (100 - tsd->subele[s_ele]) / 100; // 属性ã«ã‚ˆã‚‹ãƒ€ãƒ¡ãƒ¼ã‚¸è€æ€§
- if (battle_get_mode (src) & 0x20)
- cardfix = cardfix * (100 - tsd->subrace[10]) / 100; //ボスã‹ã‚‰ã®æ”»æ’ƒã¯ãƒ€ãƒ¡ãƒ¼ã‚¸æ¸›å°‘
- else
- cardfix = cardfix * (100 - tsd->subrace[11]) / 100; //ボス以外ã‹ã‚‰ã®æ”»æ’ƒã¯ãƒ€ãƒ¡ãƒ¼ã‚¸æ¸›å°‘
- //特定Class用補正処ç†å·¦æ‰‹(少女ã®æ—¥è¨˜â†’ボンゴン用?)
- for (i = 0; i < tsd->add_def_class_count; i++)
- {
- if (tsd->add_def_classid[i] == sd->status.pc_class)
- {
- cardfix = cardfix * (100 - tsd->add_def_classrate[i]) / 100;
- break;
- }
- }
- if (flag & BF_LONG)
- cardfix = cardfix * (100 - tsd->long_attack_def_rate) / 100; //é è·é›¢æ”»æ’ƒã¯ãƒ€ãƒ¡ãƒ¼ã‚¸æ¸›å°‘(ホルンCã¨ã‹)
- if (flag & BF_SHORT)
- cardfix = cardfix * (100 - tsd->near_attack_def_rate) / 100; //è¿‘è·é›¢æ”»æ’ƒã¯ãƒ€ãƒ¡ãƒ¼ã‚¸æ¸›å°‘(該当無ã—?)
- damage = damage * cardfix / 100; //カード補正ã«ã‚ˆã‚‹ãƒ€ãƒ¡ãƒ¼ã‚¸æ¸›å°‘
- damage2 = damage2 * cardfix / 100; //カード補正ã«ã‚ˆã‚‹å·¦æ‰‹ãƒ€ãƒ¡ãƒ¼ã‚¸æ¸›å°‘
- }
-//カードã«ã‚ˆã‚‹ãƒ€ãƒ¡ãƒ¼ã‚¸æ¸›è¡°å‡¦ç†ã“ã“ã¾ã§
-
-//対象ã«ã‚¹ãƒ†ãƒ¼ã‚¿ã‚¹ç•°å¸¸ãŒã‚ã‚‹å ´åˆã®ãƒ€ãƒ¡ãƒ¼ã‚¸æ¸›ç®—処ç†ã“ã“ã‹ã‚‰
- if (t_sc_data)
- {
- cardfix = 100;
- if (t_sc_data[SC_DEFENDER].timer != -1 && flag & BF_LONG) //ディフェンダー状態ã§é è·é›¢æ”»æ’ƒ
- cardfix = cardfix * (100 - t_sc_data[SC_DEFENDER].val2) / 100; //ディフェンダーã«ã‚ˆã‚‹æ¸›è¡°
- if (cardfix != 100)
- {
- damage = damage * cardfix / 100; //ディフェンダー補正ã«ã‚ˆã‚‹ãƒ€ãƒ¡ãƒ¼ã‚¸æ¸›å°‘
- damage2 = damage2 * cardfix / 100; //ディフェンダー補正ã«ã‚ˆã‚‹å·¦æ‰‹ãƒ€ãƒ¡ãƒ¼ã‚¸æ¸›å°‘
- }
- if (t_sc_data[SC_ASSUMPTIO].timer != -1)
- { //アスムプティオ
- if (!map[target->m].flag.pvp)
- {
- damage = damage / 3;
- damage2 = damage2 / 3;
- }
- else
- {
- damage = damage / 2;
- damage2 = damage2 / 2;
- }
- }
- }
-//対象ã«ã‚¹ãƒ†ãƒ¼ã‚¿ã‚¹ç•°å¸¸ãŒã‚ã‚‹å ´åˆã®ãƒ€ãƒ¡ãƒ¼ã‚¸æ¸›ç®—処ç†ã“ã“ã¾ã§
if (damage < 0)
damage = 0;
if (damage2 < 0)
damage2 = 0;
- // 属 性ã®é©ç”¨
- damage = battle_attr_fix (damage, s_ele, battle_get_element (target));
- damage2 = battle_attr_fix (damage2, s_ele_, battle_get_element (target));
-
// 星ã®ã‹ã‘らã€æ°—çƒã®é©ç”¨
damage += sd->star;
damage2 += sd->star_;
- damage += sd->spiritball * 3;
- damage2 += sd->spiritball * 3;
-
- if (sc_data && sc_data[SC_AURABLADE].timer != -1)
- { /* オーラブレード 必中 */
- damage += sc_data[SC_AURABLADE].val1 * 10;
- damage2 += sc_data[SC_AURABLADE].val1 * 10;
- }
- if (skill_num == PA_PRESSURE)
- { /* プレッシャー 必中? */
- damage = 700 + 100 * skill_lv;
- damage2 = 700 + 100 * skill_lv;
- }
// >二刀æµã®å·¦å³ãƒ€ãƒ¡ãƒ¼ã‚¸è¨ˆç®—誰ã‹ã‚„ã£ã¦ãã‚Œã‡ã‡ã‡ã‡ãˆãˆãˆï¼
// >map_session_data ã«å·¦æ‰‹ãƒ€ãƒ¡ãƒ¼ã‚¸(atk,atk2)追加ã—ã¦
@@ -3950,23 +1645,22 @@ static struct Damage battle_calc_pc_weapon_attack (struct block_list *src,
// pc_calcstatus()ã§ãƒ‡ãƒ¼ã‚¿ã‚’入力ã—ã¦ã„ã¾ã™
//左手ã®ã¿æ­¦å™¨è£…å‚™
- if (sd->weapontype1 == 0 && sd->weapontype2 > 0)
+ if (sd->weapontype1 == ItemLook::NONE
+ && sd->weapontype2 != ItemLook::NONE)
{
damage = damage2;
damage2 = 0;
}
// å³æ‰‹ã€å·¦æ‰‹ä¿®ç·´ã®é©ç”¨
- if (sd->status.weapon > 16)
+ if (sd->status.weapon >= ItemLook::SINGLE_HANDED_COUNT)
{ // 二刀æµã‹?
- int dmg = damage, dmg2 = damage2;
+ int dmg = damage, dmg2 = damage2;
// å³æ‰‹ä¿®ç·´(60% 〜 100%) å³æ‰‹å…¨èˆ¬
- skill = pc_checkskill (sd, AS_RIGHT);
- damage = damage * (50 + (skill * 10)) / 100;
+ damage = damage * 50 / 100;
if (dmg > 0 && damage < 1)
damage = 1;
// 左手修練(40% 〜 80%) 左手全般
- skill = pc_checkskill (sd, AS_LEFT);
- damage2 = damage2 * (30 + (skill * 10)) / 100;
+ damage2 = damage2 * 30 / 100;
if (dmg2 > 0 && damage2 < 1)
damage2 = 1;
}
@@ -3974,57 +1668,44 @@ static struct Damage battle_calc_pc_weapon_attack (struct block_list *src,
damage2 = 0;
// å³æ‰‹,短剣ã®ã¿
- if (da == 1)
+ if (da)
{ //ダブルアタックãŒç™ºå‹•ã—ã¦ã„ã‚‹ã‹
div_ = 2;
damage += damage;
- type = 0x08;
+ type = DamageType::DOUBLED;
}
- if (sd->status.weapon == 16)
+ if (sd->status.weapon == ItemLook::_16)
{
// カタール追撃ダメージ
- skill = pc_checkskill (sd, TF_DOUBLE);
- damage2 = damage * (1 + (skill * 2)) / 100;
+ damage2 = damage * 1 / 100;
if (damage > 0 && damage2 < 1)
damage2 = 1;
}
- // インベナム修正
- if (skill_num == TF_POISON)
- {
- damage =
- battle_attr_fix (damage + 15 * skill_lv, s_ele,
- battle_get_element (target));
- }
- if (skill_num == MC_CARTREVOLUTION)
- {
- damage = battle_attr_fix (damage, 0, battle_get_element (target));
- }
-
// 完全回é¿ã®åˆ¤å®š
- if (skill_num == 0 && skill_lv >= 0 && tsd != NULL && div_ < 255
- && MRAND (1000) < battle_get_flee2 (target))
+ if (skill_num == SkillID::ZERO && skill_lv >= 0 && tsd != NULL && div_ < 255
+ && random_::chance({battle_get_flee2(target), 1000}))
{
damage = damage2 = 0;
- type = 0x0b;
- dmg_lv = ATK_LUCKY;
+ type = DamageType::FLEE2;
+ dmg_lv = ATK::LUCKY;
}
// 対象ãŒå®Œå…¨å›žé¿ã‚’ã™ã‚‹è¨­å®šãŒONãªã‚‰
if (battle_config.enemy_perfect_flee)
{
- if (skill_num == 0 && skill_lv >= 0 && tmd != NULL && div_ < 255
- && MRAND (1000) < battle_get_flee2 (target))
+ if (skill_num == SkillID::ZERO && skill_lv >= 0 && tmd != NULL && div_ < 255
+ && random_::chance({battle_get_flee2(target), 1000}))
{
damage = damage2 = 0;
- type = 0x0b;
- dmg_lv = ATK_LUCKY;
+ type = DamageType::FLEE2;
+ dmg_lv = ATK::LUCKY;
}
}
//Mobã®Modeã«é ‘強フラグãŒç«‹ã£ã¦ã„ã‚‹ã¨ãã®å‡¦ç†
- if (t_mode & 0x40)
+ if (bool(t_mode & MobMode::PLANT))
{
if (damage > 0)
damage = 1;
@@ -4032,26 +1713,21 @@ static struct Damage battle_calc_pc_weapon_attack (struct block_list *src,
damage2 = 1;
}
- //bNoWeaponDamage(設定アイテム無ã—?)ã§ã‚°ãƒ©ãƒ³ãƒ‰ã‚¯ãƒ­ã‚¹ã˜ã‚ƒãªã„å ´åˆã¯ãƒ€ãƒ¡ãƒ¼ã‚¸ãŒ0
- if (tsd && tsd->special_state.no_weapon_damage
- && skill_num != CR_GRANDCROSS)
- damage = damage2 = 0;
-
- if (skill_num != CR_GRANDCROSS && (damage > 0 || damage2 > 0))
+ if (damage > 0 || damage2 > 0)
{
if (damage2 < 1) // ダメージ最終修正
damage =
- battle_calc_damage (src, target, damage, div_, skill_num,
+ battle_calc_damage(src, target, damage, div_, skill_num,
skill_lv, flag);
else if (damage < 1) // å³æ‰‹ãŒãƒŸã‚¹ï¼Ÿ
damage2 =
- battle_calc_damage (src, target, damage2, div_, skill_num,
+ battle_calc_damage(src, target, damage2, div_, skill_num,
skill_lv, flag);
else
{ // 両 手/カタールã®å ´åˆã¯ã¡ã‚‡ã£ã¨è¨ˆç®—ã‚„ã‚„ã“ã—ã„
- int d1 = damage + damage2, d2 = damage2;
+ int d1 = damage + damage2, d2 = damage2;
damage =
- battle_calc_damage (src, target, damage + damage2, div_,
+ battle_calc_damage(src, target, damage + damage2, div_,
skill_num, skill_lv, flag);
damage2 = (d2 * 100 / d1) * damage / 100;
if (damage > 1 && damage2 < 1)
@@ -4060,36 +1736,12 @@ static struct Damage battle_calc_pc_weapon_attack (struct block_list *src,
}
}
- /* For executioner card [Valaris] */
- if (src->type == BL_PC && sd->random_attack_increase_add > 0
- && sd->random_attack_increase_per > 0 && skill_num == 0)
- {
- if (MRAND (100) < sd->random_attack_increase_per)
- {
- if (damage > 0)
- damage *= sd->random_attack_increase_add / 100;
- if (damage2 > 0)
- damage2 *= sd->random_attack_increase_add / 100;
- }
- }
- /* End addition */
-
-// -- moonsoul (final combination of phys, mag damage for ASC_BREAKER)
- if (skill_num == ASC_BREAKER)
- {
- damage += damage3;
- damage2 += damage3;
- }
-
wd.damage = damage;
wd.damage2 = damage2;
wd.type = type;
wd.div_ = div_;
- wd.amotion = battle_get_amotion (src);
- if (skill_num == KN_AUTOCOUNTER)
- wd.amotion >>= 1;
- wd.dmotion = battle_get_dmotion (target);
- wd.blewcount = blewcount;
+ wd.amotion = battle_get_amotion(src);
+ wd.dmotion = battle_get_dmotion(target);
wd.flag = flag;
wd.dmg_lv = dmg_lv;
@@ -4100,77 +1752,21 @@ static struct Damage battle_calc_pc_weapon_attack (struct block_list *src,
* 武器ダメージ計算
*------------------------------------------
*/
-struct Damage battle_calc_weapon_attack (struct block_list *src,
+static
+struct Damage battle_calc_weapon_attack(struct block_list *src,
struct block_list *target,
- int skill_num, int skill_lv,
+ SkillID skill_num, int skill_lv,
int wflag)
{
- struct Damage wd;
+ struct Damage wd {};
- //returnå‰ã®å‡¦ç†ãŒã‚ã‚‹ã®ã§æƒ…報出力部ã®ã¿å¤‰æ›´
- if (src == NULL || target == NULL)
- {
- nullpo_info (NLP_MARK);
- memset (&wd, 0, sizeof (wd));
- return wd;
- }
+ nullpo_retr(wd, src);
+ nullpo_retr(wd, target);
- else if (src->type == BL_PC)
- wd = battle_calc_pc_weapon_attack (src, target, skill_num, skill_lv, wflag); // weapon breaking [Valaris]
- else if (src->type == BL_MOB)
- wd = battle_calc_mob_weapon_attack (src, target, skill_num, skill_lv,
- wflag);
- else
- memset (&wd, 0, sizeof (wd));
-
- if (battle_config.equipment_breaking && src->type == BL_PC
- && (wd.damage > 0 || wd.damage2 > 0))
- {
- struct map_session_data *sd = (struct map_session_data *) src;
- if (sd->status.weapon && sd->status.weapon != 11)
- {
- int breakrate = 1;
- if (target->type == BL_PC && sd->sc_data[SC_MELTDOWN].timer != -1)
- {
- breakrate += 100 * sd->sc_data[SC_MELTDOWN].val1;
- if (MRAND (10000) <
- breakrate * battle_config.equipment_break_rate / 100
- || breakrate >= 10000)
- pc_breakweapon ((struct map_session_data *) target);
- }
- if (sd->sc_data[SC_OVERTHRUST].timer != -1)
- breakrate += 20 * sd->sc_data[SC_OVERTHRUST].val1;
- if (wd.type == 0x0a)
- breakrate *= 2;
- if (MRAND (10000) <
- breakrate * battle_config.equipment_break_rate / 100
- || breakrate >= 10000)
- {
- pc_breakweapon (sd);
- memset (&wd, 0, sizeof (wd));
- }
- }
- }
-
- if (battle_config.equipment_breaking && target->type == BL_PC
- && (wd.damage > 0 || wd.damage2 > 0))
- {
- int breakrate = 1;
- if (src->type == BL_PC
- && ((struct map_session_data *) src)->
- sc_data[SC_MELTDOWN].timer != -1)
- breakrate +=
- 70 *
- ((struct map_session_data *) src)->sc_data[SC_MELTDOWN].val1;
- if (wd.type == 0x0a)
- breakrate *= 2;
- if (MRAND (10000) <
- breakrate * battle_config.equipment_break_rate / 100
- || breakrate >= 10000)
- {
- pc_breakarmor ((struct map_session_data *) target);
- }
- }
+ if (src->type == BL::PC)
+ wd = battle_calc_pc_weapon_attack(src, target, skill_num, skill_lv, wflag); // weapon breaking [Valaris]
+ else if (src->type == BL::MOB)
+ wd = battle_calc_mob_weapon_attack(src, target, skill_num, skill_lv, wflag);
return wd;
}
@@ -4179,223 +1775,50 @@ struct Damage battle_calc_weapon_attack (struct block_list *src,
* 魔法ダメージ計算
*------------------------------------------
*/
-struct Damage battle_calc_magic_attack (struct block_list *bl,
+static
+struct Damage battle_calc_magic_attack(struct block_list *bl,
struct block_list *target,
- int skill_num, int skill_lv, int flag)
+ SkillID skill_num, int skill_lv, int)
{
- int mdef1 = battle_get_mdef (target);
- int mdef2 = battle_get_mdef2 (target);
- int matk1, matk2, damage = 0, div_ = 1, blewcount =
- skill_get_blewcount (skill_num, skill_lv), rdamage = 0;
- struct Damage md;
- int aflag;
- int normalmagic_flag = 1;
- int ele = 0, race = 7, t_ele = 0, t_race = 7, t_mode =
- 0, cardfix, t_class, i;
- struct map_session_data *sd = NULL, *tsd = NULL;
- struct mob_data *tmd = NULL;
-
- //returnå‰ã®å‡¦ç†ãŒã‚ã‚‹ã®ã§æƒ…報出力部ã®ã¿å¤‰æ›´
- if (bl == NULL || target == NULL)
- {
- nullpo_info (NLP_MARK);
- memset (&md, 0, sizeof (md));
- return md;
- }
+ int mdef1 = battle_get_mdef(target);
+ int mdef2 = battle_get_mdef2(target);
+ int matk1, matk2, damage = 0, div_ = 1;
+ struct Damage md {};
+ int normalmagic_flag = 1;
+ struct map_session_data *sd = NULL;
- matk1 = battle_get_matk1 (bl);
- matk2 = battle_get_matk2 (bl);
- ele = skill_get_pl (skill_num);
- race = battle_get_race (bl);
- t_ele = battle_get_elem_type (target);
- t_race = battle_get_race (target);
- t_mode = battle_get_mode (target);
+ nullpo_retr(md, bl);
+ nullpo_retr(md, target);
-#define MATK_FIX( a,b ) { matk1=matk1*(a)/(b); matk2=matk2*(a)/(b); }
+ matk1 = battle_get_matk1(bl);
+ matk2 = battle_get_matk2(bl);
+ MobMode t_mode = battle_get_mode(target);
- if (bl->type == BL_PC && (sd = (struct map_session_data *) bl))
+ if (bl->type == BL::PC && (sd = (struct map_session_data *) bl))
{
- sd->state.attack_type = BF_MAGIC;
+ sd->state.attack_type = BF::MAGIC;
if (sd->matk_rate != 100)
- MATK_FIX (sd->matk_rate, 100);
+ {
+ matk1 = matk1 * sd->matk_rate / 100;
+ matk2 = matk2 * sd->matk_rate / 100;
+ }
sd->state.arrow_atk = 0;
}
- if (target->type == BL_PC)
- tsd = (struct map_session_data *) target;
- else if (target->type == BL_MOB)
- tmd = (struct mob_data *) target;
-
- aflag = BF_MAGIC | BF_LONG | BF_SKILL;
-
- if (skill_num > 0)
- {
- switch (skill_num)
- { // 基本ダメージ計算(スキルã”ã¨ã«å‡¦ç†)
- // ヒールorè–体
- case AL_HEAL:
- case PR_BENEDICTIO:
- damage = skill_calc_heal (bl, skill_lv) / 2;
- normalmagic_flag = 0;
- break;
- case PR_ASPERSIO: /* アスペルシオ */
- damage = 40; //固定ダメージ
- normalmagic_flag = 0;
- break;
- case PR_SANCTUARY: // サンクãƒãƒ¥ã‚¢ãƒª
- damage = (skill_lv > 6) ? 388 : skill_lv * 50;
- normalmagic_flag = 0;
- blewcount |= 0x10000;
- break;
- case ALL_RESURRECTION:
- case PR_TURNUNDEAD: // 攻撃リザレクションã¨ã‚¿ãƒ¼ãƒ³ã‚¢ãƒ³ãƒ‡ãƒƒãƒ‰
- if (target->type != BL_PC
- && battle_check_undead (t_race, t_ele))
- {
- int hp, mhp, thres;
- hp = battle_get_hp (target);
- mhp = battle_get_max_hp (target);
- thres = (skill_lv * 20) + battle_get_luk (bl) +
- battle_get_int (bl) + battle_get_lv (bl) +
- ((200 - hp * 200 / mhp));
- if (thres > 700)
- thres = 700;
-// if(battle_config.battle_log)
-// printf("ã‚¿ãƒ¼ãƒ³ã‚¢ãƒ³ãƒ‡ãƒƒãƒ‰ï¼ ç¢ºçŽ‡%d ‰(åƒåˆ†çŽ‡)\n", thres);
- if (MRAND (1000) < thres && !(t_mode & 0x20)) // æˆåŠŸ
- damage = hp;
- else // 失敗
- damage =
- battle_get_lv (bl) + battle_get_int (bl) +
- skill_lv * 10;
- }
- normalmagic_flag = 0;
- break;
- case MG_NAPALMBEAT: // ナパームビート(分散計算込ã¿ï¼‰
- MATK_FIX (70 + skill_lv * 10, 100);
- if (flag > 0)
- {
- MATK_FIX (1, flag);
- }
- else
- {
- if (battle_config.error_log)
- printf
- ("battle_calc_magic_attack(): napam enemy count=0 !\n");
- }
- break;
- case MG_FIREBALL: // ファイヤーボール
- {
- const int drate[] = { 100, 90, 70 };
- if (flag > 2)
- matk1 = matk2 = 0;
- else
- MATK_FIX ((95 + skill_lv * 5) * drate[flag], 10000);
- }
- break;
- case MG_FIREWALL: // ファイヤーウォール
-/*
- if( (t_ele!=3 && !battle_check_undead(t_race,t_ele)) || target->type==BL_PC ) //PCã¯ç«å±žæ€§ã§ã‚‚飛ã¶ï¼Ÿãã‚‚ãもダメージå—ã‘る?
- blewcount |= 0x10000;
- else
- blewcount = 0;
-*/
- if ((t_ele == 3 || battle_check_undead (t_race, t_ele))
- && target->type != BL_PC)
- blewcount = 0;
- else
- blewcount |= 0x10000;
- MATK_FIX (1, 2);
- break;
- case MG_THUNDERSTORM: // サンダーストーム
- MATK_FIX (80, 100);
- break;
- case MG_FROSTDIVER: // フロストダイãƒ
- MATK_FIX (100 + skill_lv * 10, 100);
- break;
- case WZ_FROSTNOVA: // フロストダイãƒ
- MATK_FIX (((100 + skill_lv * 10) * (2 / 3)), 100);
- break;
- case WZ_FIREPILLAR: // ファイヤーピラー
- if (mdef1 < 1000000)
- mdef1 = mdef2 = 0; // MDEF無視
- MATK_FIX (1, 5);
- matk1 += 50;
- matk2 += 50;
- break;
- case WZ_SIGHTRASHER:
- MATK_FIX (100 + skill_lv * 20, 100);
- break;
- case WZ_METEOR:
- case WZ_JUPITEL: // ユピテルサンダー
- break;
- case WZ_VERMILION: // ロードオブãƒãƒ¼ãƒŸãƒªã‚ªãƒ³
- MATK_FIX (skill_lv * 20 + 80, 100);
- break;
- case WZ_WATERBALL: // ウォーターボール
- matk1 += skill_lv * 30;
- matk2 += skill_lv * 30;
- break;
- case WZ_STORMGUST: // ストームガスト
- MATK_FIX (skill_lv * 40 + 100, 100);
- blewcount |= 0x10000;
- break;
- case AL_HOLYLIGHT: // ホーリーライト
- MATK_FIX (125, 100);
- break;
- case AL_RUWACH:
- MATK_FIX (145, 100);
- break;
- case HW_NAPALMVULCAN: // ナパームビート(分散計算込ã¿ï¼‰
- MATK_FIX (70 + skill_lv * 10, 100);
- if (flag > 0)
- {
- MATK_FIX (1, flag);
- }
- else
- {
- if (battle_config.error_log)
- printf
- ("battle_calc_magic_attack(): napalmvulcan enemy count=0 !\n");
- }
- break;
- }
- }
+ BF aflag = BF::MAGIC | BF::LONG | BF::SKILL;
if (normalmagic_flag)
- { // 一般魔法ダメージ計算
- int imdef_flag = 0;
+ {
+ // 一般魔法ダメージ計算
if (matk1 > matk2)
- damage = matk2 + MRAND ((matk1 - matk2 + 1));
+ damage = random_::in(matk2, matk1);
else
damage = matk2;
- if (sd)
- {
- if (sd->ignore_mdef_ele & (1 << t_ele)
- || sd->ignore_mdef_race & (1 << t_race))
- imdef_flag = 1;
- if (t_mode & 0x20)
- {
- if (sd->ignore_mdef_race & (1 << 10))
- imdef_flag = 1;
- }
- else
- {
- if (sd->ignore_mdef_race & (1 << 11))
- imdef_flag = 1;
- }
- }
- if (!imdef_flag)
+
{
- if (battle_config.magic_defense_type)
- {
- damage =
- damage - (mdef1 * battle_config.magic_defense_type) -
- mdef2;
- }
- else
{
- damage = (damage * (100 - mdef1)) / 100 - mdef2;
+ damage = (damage * (100 - mdef1)) / 100;
+ damage -= mdef2;
}
}
@@ -4403,108 +1826,26 @@ struct Damage battle_calc_magic_attack (struct block_list *bl,
damage = 1;
}
- if (sd)
- {
- cardfix = 100;
- cardfix = cardfix * (100 + sd->magic_addrace[t_race]) / 100;
- cardfix = cardfix * (100 + sd->magic_addele[t_ele]) / 100;
- if (t_mode & 0x20)
- cardfix = cardfix * (100 + sd->magic_addrace[10]) / 100;
- else
- cardfix = cardfix * (100 + sd->magic_addrace[11]) / 100;
- t_class = battle_get_class (target);
- for (i = 0; i < sd->add_magic_damage_class_count; i++)
- {
- if (sd->add_magic_damage_classid[i] == t_class)
- {
- cardfix =
- cardfix * (100 + sd->add_magic_damage_classrate[i]) / 100;
- break;
- }
- }
- damage = damage * cardfix / 100;
- }
-
- if (tsd)
- {
- int s_class = battle_get_class (bl);
- cardfix = 100;
- cardfix = cardfix * (100 - tsd->subele[ele]) / 100; // 属 性ã«ã‚ˆã‚‹ãƒ€ãƒ¡ãƒ¼ã‚¸è€æ€§
- cardfix = cardfix * (100 - tsd->subrace[race]) / 100; // 種æ—ã«ã‚ˆã‚‹ãƒ€ãƒ¡ãƒ¼ã‚¸è€æ€§
- cardfix = cardfix * (100 - tsd->magic_subrace[race]) / 100;
- if (battle_get_mode (bl) & 0x20)
- cardfix = cardfix * (100 - tsd->magic_subrace[10]) / 100;
- else
- cardfix = cardfix * (100 - tsd->magic_subrace[11]) / 100;
- for (i = 0; i < tsd->add_mdef_class_count; i++)
- {
- if (tsd->add_mdef_classid[i] == s_class)
- {
- cardfix = cardfix * (100 - tsd->add_mdef_classrate[i]) / 100;
- break;
- }
- }
- cardfix = cardfix * (100 - tsd->magic_def_rate) / 100;
- damage = damage * cardfix / 100;
- }
if (damage < 0)
damage = 0;
- damage = battle_attr_fix (damage, ele, battle_get_element (target)); // 属 性修正
-
- if (skill_num == CR_GRANDCROSS)
- { // グランドクロス
- struct Damage wd;
- wd = battle_calc_weapon_attack (bl, target, skill_num, skill_lv,
- flag);
- damage = (damage + wd.damage) * (100 + 40 * skill_lv) / 100;
- if (battle_config.gx_dupele)
- damage = battle_attr_fix (damage, ele, battle_get_element (target)); //属性2回ã‹ã‹ã‚‹
- if (bl == target)
- damage = damage / 2; //åå‹•ã¯åŠåˆ†
- }
-
- div_ = skill_get_num (skill_num, skill_lv);
+ div_ = skill_get_num(skill_num, skill_lv);
- if (div_ > 1 && skill_num != WZ_VERMILION)
+ if (div_ > 1)
damage *= div_;
// if(mdef1 >= 1000000 && damage > 0)
- if (t_mode & 0x40 && damage > 0)
+ if (bool(t_mode & MobMode::PLANT) && damage > 0)
damage = 1;
- if (tsd && tsd->special_state.no_magic_damage)
- {
- if (battle_config.gtb_pvp_only != 0)
- { // [MouseJstr]
- if ((map[target->m].flag.pvp || map[target->m].flag.gvg)
- && target->type == BL_PC)
- damage = (damage * (100 - battle_config.gtb_pvp_only)) / 100;
- }
- else
- damage = 0; // 黄 金蟲カード(魔法ダメージï¼ï¼‰
- }
-
- damage = battle_calc_damage (bl, target, damage, div_, skill_num, skill_lv, aflag); // 最終修正
-
- /* magic_damage_return by [AppleGirl] and [Valaris] */
- if (target->type == BL_PC && tsd && tsd->magic_damage_return > 0)
- {
- rdamage += damage * tsd->magic_damage_return / 100;
- if (rdamage < 1)
- rdamage = 1;
- clif_damage (target, bl, gettick (), 0, 0, rdamage, 0, 0, 0);
- battle_damage (target, bl, rdamage, 0);
- }
- /* end magic_damage_return */
+ damage = battle_calc_damage(bl, target, damage, div_, skill_num, skill_lv, aflag); // 最終修正
md.damage = damage;
md.div_ = div_;
- md.amotion = battle_get_amotion (bl);
- md.dmotion = battle_get_dmotion (target);
+ md.amotion = battle_get_amotion(bl);
+ md.dmotion = battle_get_dmotion(target);
md.damage2 = 0;
- md.type = 0;
- md.blewcount = blewcount;
+ md.type = DamageType::NORMAL;
md.flag = aflag;
return md;
@@ -4514,153 +1855,61 @@ struct Damage battle_calc_magic_attack (struct block_list *bl,
* ãã®ä»–ダメージ計算
*------------------------------------------
*/
-struct Damage battle_calc_misc_attack (struct block_list *bl,
+static
+struct Damage battle_calc_misc_attack(struct block_list *bl,
struct block_list *target,
- int skill_num, int skill_lv, int flag)
+ SkillID skill_num, int skill_lv, int)
{
- int int_ = battle_get_int (bl);
-// int luk=battle_get_luk(bl);
- int dex = battle_get_dex (bl);
- int skill, ele, race, cardfix;
- struct map_session_data *sd = NULL, *tsd = NULL;
- int damage = 0, div_ = 1, blewcount =
- skill_get_blewcount (skill_num, skill_lv);
- struct Damage md;
- int damagefix = 1;
-
- int aflag = BF_MISC | BF_LONG | BF_SKILL;
-
- //returnå‰ã®å‡¦ç†ãŒã‚ã‚‹ã®ã§æƒ…報出力部ã®ã¿å¤‰æ›´
- if (bl == NULL || target == NULL)
- {
- nullpo_info (NLP_MARK);
- memset (&md, 0, sizeof (md));
- return md;
- }
+ struct map_session_data *sd = NULL;
+ int damage = 0, div_ = 1;
+ struct Damage md {};
+ int damagefix = 1;
+
+ BF aflag = BF::MISC | BF::LONG | BF::SKILL;
+
+ nullpo_retr(md, bl);
+ nullpo_retr(md, target);
- if (bl->type == BL_PC && (sd = (struct map_session_data *) bl))
+ if (bl->type == BL::PC && (sd = (struct map_session_data *) bl))
{
- sd->state.attack_type = BF_MISC;
+ sd->state.attack_type = BF::MISC;
sd->state.arrow_atk = 0;
}
- if (target->type == BL_PC)
- tsd = (struct map_session_data *) target;
-
switch (skill_num)
{
-
- case HT_LANDMINE: // ランドマイン
- damage = skill_lv * (dex + 75) * (100 + int_) / 100;
- break;
-
- case HT_BLASTMINE: // ブラストマイン
- damage = skill_lv * (dex / 2 + 50) * (100 + int_) / 100;
- break;
-
- case HT_CLAYMORETRAP: // クレイモアートラップ
- damage = skill_lv * (dex / 2 + 75) * (100 + int_) / 100;
- break;
-
- case HT_BLITZBEAT: // ブリッツビート
- if (sd == NULL || (skill = pc_checkskill (sd, HT_STEELCROW)) <= 0)
- skill = 0;
- damage = (dex / 10 + int_ / 2 + skill * 3 + 40) * 2;
- if (flag > 1)
- damage /= flag;
- break;
-
- case TF_THROWSTONE: // 石投ã’
- damage = 30;
- damagefix = 0;
- break;
-
- case BA_DISSONANCE: // ä¸å”和音
- damage =
- (skill_lv) * 20 + pc_checkskill (sd, BA_MUSICALLESSON) * 3;
- break;
-
- case NPC_SELFDESTRUCTION: // 自爆
- damage = battle_get_hp (bl) - (bl == target ? 1 : 0);
- damagefix = 0;
- break;
-
- case NPC_SMOKING: // ã‚¿ãƒã‚³ã‚’å¸ã†
- damage = 3;
+ case SkillID::NPC_SELFDESTRUCTION: // 自爆
+ damage = battle_get_hp(bl) - (bl == target ? 1 : 0);
damagefix = 0;
break;
-
- case NPC_DARKBREATH:
- {
- struct status_change *sc_data = battle_get_sc_data (target);
- int hitrate =
- battle_get_hit (bl) - battle_get_flee (target) + 80;
- hitrate = ((hitrate > 95) ? 95 : ((hitrate < 5) ? 5 : hitrate));
- if (sc_data
- && (sc_data[SC_SLEEP].timer != -1
- || sc_data[SC_STAN].timer != -1
- || sc_data[SC_FREEZE].timer != -1
- || (sc_data[SC_STONE].timer != -1
- && sc_data[SC_STONE].val2 == 0)))
- hitrate = 1000000;
- if (MRAND (100) < hitrate)
- {
- damage = 500 + (skill_lv - 1) * 1000 + MRAND (1000);
- if (damage > 9999)
- damage = 9999;
- }
- }
- break;
- case SN_FALCONASSAULT: /* ファルコンアサルト */
- skill = pc_checkskill (sd, HT_BLITZBEAT);
- damage =
- (100 + 50 * skill_lv +
- (dex / 10 + int_ / 2 + skill * 3 + 40) * 2);
- break;
}
- ele = skill_get_pl (skill_num);
- race = battle_get_race (bl);
-
if (damagefix)
{
- if (damage < 1 && skill_num != NPC_DARKBREATH)
+ if (damage < 1)
damage = 1;
-
- if (tsd)
- {
- cardfix = 100;
- cardfix = cardfix * (100 - tsd->subele[ele]) / 100; // 属性ã«ã‚ˆã‚‹ãƒ€ãƒ¡ãƒ¼ã‚¸è€æ€§
- cardfix = cardfix * (100 - tsd->subrace[race]) / 100; // 種æ—ã«ã‚ˆã‚‹ãƒ€ãƒ¡ãƒ¼ã‚¸è€æ€§
- cardfix = cardfix * (100 - tsd->misc_def_rate) / 100;
- damage = damage * cardfix / 100;
- }
- if (damage < 0)
- damage = 0;
- damage = battle_attr_fix (damage, ele, battle_get_element (target)); // 属性修正
}
- div_ = skill_get_num (skill_num, skill_lv);
+ div_ = skill_get_num(skill_num, skill_lv);
if (div_ > 1)
damage *= div_;
if (damage > 0
&& (damage < div_
- || (battle_get_def (target) >= 1000000
- && battle_get_mdef (target) >= 1000000)))
+ || (battle_get_def(target) >= 1000000
+ && battle_get_mdef(target) >= 1000000)))
{
damage = div_;
}
- damage = battle_calc_damage (bl, target, damage, div_, skill_num, skill_lv, aflag); // 最終修正
+ damage = battle_calc_damage(bl, target, damage, div_, skill_num, skill_lv, aflag); // 最終修正
md.damage = damage;
md.div_ = div_;
- md.amotion = battle_get_amotion (bl);
- md.dmotion = battle_get_dmotion (target);
+ md.amotion = battle_get_amotion(bl);
+ md.dmotion = battle_get_dmotion(target);
md.damage2 = 0;
- md.type = 0;
- md.blewcount = blewcount;
+ md.type = DamageType::NORMAL;
md.flag = aflag;
return md;
@@ -4670,28 +1919,28 @@ struct Damage battle_calc_misc_attack (struct block_list *bl,
* ダメージ計算一括処ç†ç”¨
*------------------------------------------
*/
-struct Damage battle_calc_attack (int attack_type,
+struct Damage battle_calc_attack(BF attack_type,
struct block_list *bl,
- struct block_list *target, int skill_num,
+ struct block_list *target, SkillID skill_num,
int skill_lv, int flag)
{
struct Damage d;
- memset (&d, 0, sizeof (d));
+ memset(&d, 0, sizeof(d));
switch (attack_type)
{
- case BF_WEAPON:
- return battle_calc_weapon_attack (bl, target, skill_num, skill_lv,
+ case BF::WEAPON:
+ return battle_calc_weapon_attack(bl, target, skill_num, skill_lv,
flag);
- case BF_MAGIC:
- return battle_calc_magic_attack (bl, target, skill_num, skill_lv,
+ case BF::MAGIC:
+ return battle_calc_magic_attack(bl, target, skill_num, skill_lv,
flag);
- case BF_MISC:
- return battle_calc_misc_attack (bl, target, skill_num, skill_lv,
+ case BF::MISC:
+ return battle_calc_misc_attack(bl, target, skill_num, skill_lv,
flag);
default:
if (battle_config.error_log)
- printf ("battle_calc_attack: unknwon attack type ! %d\n",
+ PRINTF("battle_calc_attack: unknwon attack type ! %d\n",
attack_type);
break;
}
@@ -4702,550 +1951,220 @@ struct Damage battle_calc_attack (int attack_type,
* 通常攻撃処ç†ã¾ã¨ã‚
*------------------------------------------
*/
-int battle_weapon_attack (struct block_list *src, struct block_list *target,
- unsigned int tick, int flag)
+ATK battle_weapon_attack(struct block_list *src, struct block_list *target,
+ tick_t tick)
{
struct map_session_data *sd = NULL;
- struct status_change *sc_data = battle_get_sc_data (src), *t_sc_data =
- battle_get_sc_data (target);
- short *opt1;
- int race = 7, ele = 0;
- int damage, rdamage = 0;
+ eptr<struct status_change, StatusChange> t_sc_data = battle_get_sc_data(target);
struct Damage wd;
- nullpo_retr (0, src);
- nullpo_retr (0, target);
+ nullpo_retr(ATK::ZERO, src);
+ nullpo_retr(ATK::ZERO, target);
- if (src->type == BL_PC)
+ if (src->type == BL::PC)
sd = (struct map_session_data *) src;
if (src->prev == NULL || target->prev == NULL)
- return 0;
- if (src->type == BL_PC && pc_isdead (sd))
- return 0;
- if (target->type == BL_PC
- && pc_isdead ((struct map_session_data *) target))
- return 0;
+ return ATK::ZERO;
+ if (src->type == BL::PC && pc_isdead(sd))
+ return ATK::ZERO;
+ if (target->type == BL::PC
+ && pc_isdead((struct map_session_data *) target))
+ return ATK::ZERO;
- opt1 = battle_get_opt1 (src);
- if (opt1 && *opt1 > 0)
+ Opt1 *opt1 = battle_get_opt1(src);
+ if (opt1 != NULL && bool(*opt1))
{
- battle_stopattack (src);
- return 0;
- }
- if (sc_data && sc_data[SC_BLADESTOP].timer != -1)
- {
- battle_stopattack (src);
- return 0;
+ battle_stopattack(src);
+ return ATK::ZERO;
}
- race = battle_get_race (target);
- ele = battle_get_elem_type (target);
- if (battle_check_target (src, target, BCT_ENEMY) > 0 &&
- battle_check_range (src, target, 0))
+ if (battle_check_target(src, target, BCT_ENEMY) > 0 &&
+ battle_check_range(src, target, 0))
{
// 攻撃対象ã¨ãªã‚Šã†ã‚‹ã®ã§æ”»æ’ƒ
- if (sd && sd->status.weapon == 11)
+ if (sd && sd->status.weapon == ItemLook::BOW)
{
- if (sd->equip_index[10] >= 0)
+ if (sd->equip_index[EQUIP::ARROW] >= 0)
{
if (battle_config.arrow_decrement)
- pc_delitem (sd, sd->equip_index[10], 1, 0);
+ pc_delitem(sd, sd->equip_index[EQUIP::ARROW], 1, 0);
}
else
{
- clif_arrow_fail (sd, 0);
- return 0;
+ clif_arrow_fail(sd, 0);
+ return ATK::ZERO;
}
}
- if (flag & 0x8000)
- {
- if (sd && battle_config.pc_attack_direction_change)
- sd->dir = sd->head_dir =
- map_calc_dir (src, target->x, target->y);
- else if (src->type == BL_MOB
- && battle_config.monster_attack_direction_change)
- ((struct mob_data *) src)->dir =
- map_calc_dir (src, target->x, target->y);
- wd = battle_calc_weapon_attack (src, target, KN_AUTOCOUNTER,
- flag & 0xff, 0);
- }
- else
- wd = battle_calc_weapon_attack (src, target, 0, 0, 0);
+ wd = battle_calc_weapon_attack(src, target, SkillID::ZERO, 0, 0);
// significantly increase injuries for hasted characters
- if (wd.damage > 0 && (t_sc_data[SC_HASTE].timer != -1))
+ if (wd.damage > 0 && t_sc_data[StatusChange::SC_HASTE].timer)
{
- wd.damage = (wd.damage * (16 + t_sc_data[SC_HASTE].val1)) >> 4;
+ wd.damage = (wd.damage * (16 + t_sc_data[StatusChange::SC_HASTE].val1)) >> 4;
}
if (wd.damage > 0
- && t_sc_data[SC_PHYS_SHIELD].timer != -1 && target->type == BL_PC)
+ && t_sc_data[StatusChange::SC_PHYS_SHIELD].timer
+ && target->type == BL::PC)
{
- int reduction = t_sc_data[SC_PHYS_SHIELD].val1;
+ int reduction = t_sc_data[StatusChange::SC_PHYS_SHIELD].val1;
if (reduction > wd.damage)
reduction = wd.damage;
wd.damage -= reduction;
- MAP_LOG_PC (((struct map_session_data *) target),
+ MAP_LOG_PC(((struct map_session_data *) target),
"MAGIC-ABSORB-DMG %d", reduction);
}
- if ((damage = wd.damage + wd.damage2) > 0 && src != target)
- {
- if (wd.flag & BF_SHORT)
- {
- if (target->type == BL_PC)
- {
- struct map_session_data *tsd =
- (struct map_session_data *) target;
- if (tsd && tsd->short_weapon_damage_return > 0)
- {
- rdamage +=
- damage * tsd->short_weapon_damage_return / 100;
- if (rdamage < 1)
- rdamage = 1;
- }
- }
- if (t_sc_data && t_sc_data[SC_REFLECTSHIELD].timer != -1)
- {
- rdamage +=
- damage * t_sc_data[SC_REFLECTSHIELD].val2 / 100;
- if (rdamage < 1)
- rdamage = 1;
- }
- }
- else if (wd.flag & BF_LONG)
- {
- if (target->type == BL_PC)
- {
- struct map_session_data *tsd =
- (struct map_session_data *) target;
- if (tsd && tsd->long_weapon_damage_return > 0)
- {
- rdamage +=
- damage * tsd->long_weapon_damage_return / 100;
- if (rdamage < 1)
- rdamage = 1;
- }
- }
- }
-
- if (rdamage > 0)
- clif_damage (src, src, tick, wd.amotion, 0, rdamage, 1, 4, 0);
- }
-
- if (wd.div_ == 255 && sd)
- { //三段掌
- int delay =
- 1000 - 4 * battle_get_agi (src) - 2 * battle_get_dex (src);
- int skilllv;
- if (wd.damage + wd.damage2 < battle_get_hp (target))
- {
- if ((skilllv = pc_checkskill (sd, MO_CHAINCOMBO)) > 0)
- delay += 300 * battle_config.combo_delay_rate / 100; //追加ディレイをconfã«ã‚ˆã‚Šèª¿æ•´
-
- skill_status_change_start (src, SC_COMBO, MO_TRIPLEATTACK,
- skilllv, 0, 0, delay, 0);
- }
- sd->attackabletime = sd->canmove_tick = tick + delay;
- clif_combo_delay (src, delay);
- clif_skill_damage (src, target, tick, wd.amotion, wd.dmotion,
- wd.damage, 3, MO_TRIPLEATTACK,
- pc_checkskill (sd, MO_TRIPLEATTACK), -1);
- }
- else
{
- clif_damage (src, target, tick, wd.amotion, wd.dmotion,
+ clif_damage(src, target, tick, wd.amotion, wd.dmotion,
wd.damage, wd.div_, wd.type, wd.damage2);
- //二刀æµå·¦æ‰‹ã¨ã‚«ã‚¿ãƒ¼ãƒ«è¿½æ’ƒã®ãƒŸã‚¹è¡¨ç¤º(ç„¡ç†ã‚„り〜)
- if (sd && sd->status.weapon >= 16 && wd.damage2 == 0)
- clif_damage (src, target, tick + 10, wd.amotion, wd.dmotion,
- 0, 1, 0, 0);
+ if (sd
+ && (sd->status.weapon == ItemLook::_16
+ || sd->status.weapon >= ItemLook::SINGLE_HANDED_COUNT)
+ && wd.damage2 == 0)
+ clif_damage(src, target, tick + std::chrono::milliseconds(10),
+ wd.amotion, wd.dmotion, 0, 1, DamageType::NORMAL, 0);
}
- if (sd && sd->splash_range > 0 && (wd.damage > 0 || wd.damage2 > 0))
- skill_castend_damage_id (src, target, 0, -1, tick, 0);
- map_freeblock_lock ();
- if (src->type == BL_PC)
+ map_freeblock_lock();
+
+ if (src->type == BL::PC)
{
- int weapon_index = sd->equip_index[9];
- int weapon = 0;
+ int weapon_index = sd->equip_index[EQUIP::WEAPON];
+ int weapon = 0;
if (sd->inventory_data[weapon_index]
- && sd->status.inventory[weapon_index].equip & 0x2)
+ && bool(sd->status.inventory[weapon_index].equip & EPOS::WEAPON))
weapon = sd->inventory_data[weapon_index]->nameid;
- MAP_LOG ("PC%d %d:%d,%d WPNDMG %s%d %d FOR %d WPN %d",
+ MAP_LOG("PC%d %d:%d,%d WPNDMG %s%d %d FOR %d WPN %d",
sd->status.char_id, src->m, src->x, src->y,
- (target->type == BL_PC) ? "PC" : "MOB",
+ (target->type == BL::PC) ? "PC" : "MOB",
(target->type ==
- BL_PC) ? ((struct map_session_data *) target)->
+ BL::PC) ? ((struct map_session_data *) target)->
status.char_id : target->id,
- (target->type ==
- BL_PC) ? 0 : ((struct mob_data *) target)->mob_class,
+ battle_get_class(target),
wd.damage + wd.damage2, weapon);
}
- if (target->type == BL_PC)
+ if (target->type == BL::PC)
{
struct map_session_data *sd2 = (struct map_session_data *) target;
- MAP_LOG ("PC%d %d:%d,%d WPNINJURY %s%d %d FOR %d",
+ MAP_LOG("PC%d %d:%d,%d WPNINJURY %s%d %d FOR %d",
sd2->status.char_id, target->m, target->x, target->y,
- (src->type == BL_PC) ? "PC" : "MOB",
- (src->type ==
- BL_PC) ? ((struct map_session_data *) src)->
- status.char_id : src->id,
- (src->type ==
- BL_PC) ? 0 : ((struct mob_data *) src)->mob_class,
+ (src->type == BL::PC) ? "PC" : "MOB",
+ (src->type == BL::PC)
+ ? ((struct map_session_data *) src)->status.char_id
+ : src->id,
+ battle_get_class(src),
wd.damage + wd.damage2);
}
- battle_damage (src, target, (wd.damage + wd.damage2), 0);
+ battle_damage(src, target, (wd.damage + wd.damage2), 0);
if (target->prev != NULL &&
- (target->type != BL_PC
- || (target->type == BL_PC
- && !pc_isdead ((struct map_session_data *) target))))
+ (target->type != BL::PC
+ || (target->type == BL::PC
+ && !pc_isdead((struct map_session_data *) target))))
{
if (wd.damage > 0 || wd.damage2 > 0)
{
- skill_additional_effect (src, target, 0, 0, BF_WEAPON, tick);
- if (sd)
- {
- if (sd->weapon_coma_ele[ele] > 0
- && MRAND (10000) < sd->weapon_coma_ele[ele])
- battle_damage (src, target,
- battle_get_max_hp (target), 1);
- if (sd->weapon_coma_race[race] > 0
- && MRAND (10000) < sd->weapon_coma_race[race])
- battle_damage (src, target,
- battle_get_max_hp (target), 1);
- if (battle_get_mode (target) & 0x20)
- {
- if (sd->weapon_coma_race[10] > 0
- && MRAND (10000) < sd->weapon_coma_race[10])
- battle_damage (src, target,
- battle_get_max_hp (target), 1);
- }
- else
- {
- if (sd->weapon_coma_race[11] > 0
- && MRAND (10000) < sd->weapon_coma_race[11])
- battle_damage (src, target,
- battle_get_max_hp (target), 1);
- }
- }
- }
- }
- if (sc_data && sc_data[SC_AUTOSPELL].timer != -1
- && MRAND (100) < sc_data[SC_AUTOSPELL].val4)
- {
- int skilllv = sc_data[SC_AUTOSPELL].val3, i, f = 0;
- i = MRAND (100);
- if (i >= 50)
- skilllv -= 2;
- else if (i >= 15)
- skilllv--;
- if (skilllv < 1)
- skilllv = 1;
- if (sd)
- {
- int sp = skill_get_sp (sc_data[SC_AUTOSPELL].val2,
- skilllv) * 2 / 3;
- if (sd->status.sp >= sp)
- {
- if ((i = skill_get_inf (sc_data[SC_AUTOSPELL].val2) == 2)
- || i == 32)
- f = skill_castend_pos2 (src, target->x, target->y,
- sc_data[SC_AUTOSPELL].val2,
- skilllv, tick, flag);
- else
- {
- switch (skill_get_nk (sc_data[SC_AUTOSPELL].val2))
- {
- case 0:
- case 2:
- f = skill_castend_damage_id (src, target,
- sc_data
- [SC_AUTOSPELL].val2,
- skilllv, tick,
- flag);
- break;
- case 1: /* 支æ´ç³» */
- if ((sc_data[SC_AUTOSPELL].val2 == AL_HEAL
- || (sc_data[SC_AUTOSPELL].val2 ==
- ALL_RESURRECTION
- && target->type != BL_PC))
- && battle_check_undead (race, ele))
- f = skill_castend_damage_id (src, target,
- sc_data
- [SC_AUTOSPELL].val2,
- skilllv,
- tick, flag);
- else
- f = skill_castend_nodamage_id (src,
- target,
- sc_data
- [SC_AUTOSPELL].val2,
- skilllv,
- tick,
- flag);
- break;
- }
- }
- if (!f)
- pc_heal (sd, 0, -sp);
- }
- }
- else
- {
- if ((i = skill_get_inf (sc_data[SC_AUTOSPELL].val2) == 2)
- || i == 32)
- skill_castend_pos2 (src, target->x, target->y,
- sc_data[SC_AUTOSPELL].val2, skilllv,
- tick, flag);
- else
- {
- switch (skill_get_nk (sc_data[SC_AUTOSPELL].val2))
- {
- case 0:
- case 2:
- skill_castend_damage_id (src, target,
- sc_data
- [SC_AUTOSPELL].val2,
- skilllv, tick, flag);
- break;
- case 1: /* 支æ´ç³» */
- if ((sc_data[SC_AUTOSPELL].val2 == AL_HEAL
- || (sc_data[SC_AUTOSPELL].val2 ==
- ALL_RESURRECTION
- && target->type != BL_PC))
- && battle_check_undead (race, ele))
- skill_castend_damage_id (src, target,
- sc_data
- [SC_AUTOSPELL].val2,
- skilllv, tick, flag);
- else
- skill_castend_nodamage_id (src, target,
- sc_data
- [SC_AUTOSPELL].val2,
- skilllv, tick,
- flag);
- break;
- }
- }
+ skill_additional_effect(src, target, SkillID::ZERO, 0);
}
}
if (sd)
{
- if (sd->autospell_id > 0 && sd->autospell_lv > 0
- && MRAND (100) < sd->autospell_rate)
- {
- int skilllv = sd->autospell_lv, i, f = 0, sp;
- i = MRAND (100);
- if (i >= 50)
- skilllv -= 2;
- else if (i >= 15)
- skilllv--;
- if (skilllv < 1)
- skilllv = 1;
- sp = skill_get_sp (sd->autospell_id, skilllv) * 2 / 3;
- if (sd->status.sp >= sp)
- {
- if ((i = skill_get_inf (sd->autospell_id) == 2)
- || i == 32)
- f = skill_castend_pos2 (src, target->x, target->y,
- sd->autospell_id, skilllv,
- tick, flag);
- else
- {
- switch (skill_get_nk (sd->autospell_id))
- {
- case 0:
- case 2:
- f = skill_castend_damage_id (src, target,
- sd->autospell_id,
- skilllv, tick,
- flag);
- break;
- case 1: /* 支æ´ç³» */
- if ((sd->autospell_id == AL_HEAL
- || (sd->autospell_id == ALL_RESURRECTION
- && target->type != BL_PC))
- && battle_check_undead (race, ele))
- f = skill_castend_damage_id (src, target,
- sd->autospell_id,
- skilllv,
- tick, flag);
- else
- f = skill_castend_nodamage_id (src,
- target,
- sd->autospell_id,
- skilllv,
- tick,
- flag);
- break;
- }
- }
- if (!f)
- pc_heal (sd, 0, -sp);
- }
- }
- if (wd.flag & BF_WEAPON && src != target
+ if (bool(wd.flag & BF::WEAPON)
+ && src != target
&& (wd.damage > 0 || wd.damage2 > 0))
{
- int hp = 0, sp = 0;
+ int hp = 0, sp = 0;
if (sd->hp_drain_rate && wd.damage > 0
- && MRAND (100) < sd->hp_drain_rate)
+ && random_::chance({sd->hp_drain_rate, 100}))
{
hp += (wd.damage * sd->hp_drain_per) / 100;
}
if (sd->hp_drain_rate_ && wd.damage2 > 0
- && MRAND (100) < sd->hp_drain_rate_)
+ && random_::chance({sd->hp_drain_rate_, 100}))
{
hp += (wd.damage2 * sd->hp_drain_per_) / 100;
}
if (sd->sp_drain_rate && wd.damage > 0
- && MRAND (100) < sd->sp_drain_rate)
+ && random_::chance({sd->sp_drain_rate, 100}))
{
sp += (wd.damage * sd->sp_drain_per) / 100;
}
if (sd->sp_drain_rate_ && wd.damage2 > 0
- && MRAND (100) < sd->sp_drain_rate_)
+ && random_::chance({sd->sp_drain_rate_, 100}))
{
sp += (wd.damage2 * sd->sp_drain_per_) / 100;
}
if (hp || sp)
- pc_heal (sd, hp, sp);
+ pc_heal(sd, hp, sp);
}
}
- if (rdamage > 0)
- battle_damage (target, src, rdamage, 0);
- if (t_sc_data && t_sc_data[SC_AUTOCOUNTER].timer != -1
- && t_sc_data[SC_AUTOCOUNTER].val4 > 0)
- {
- if (t_sc_data[SC_AUTOCOUNTER].val3 == src->id)
- battle_weapon_attack (target, src, tick,
- 0x8000 |
- t_sc_data[SC_AUTOCOUNTER].val1);
- skill_status_change_end (target, SC_AUTOCOUNTER, -1);
- }
- if (t_sc_data && t_sc_data[SC_BLADESTOP_WAIT].timer != -1)
- {
- int lv = t_sc_data[SC_BLADESTOP_WAIT].val1;
- skill_status_change_end (target, SC_BLADESTOP_WAIT, -1);
- skill_status_change_start (src, SC_BLADESTOP, lv, 1, (int) src,
- (int) target,
- skill_get_time2 (MO_BLADESTOP, lv), 0);
- skill_status_change_start (target, SC_BLADESTOP, lv, 2,
- (int) target, (int) src,
- skill_get_time2 (MO_BLADESTOP, lv), 0);
- }
- if (t_sc_data && t_sc_data[SC_SPLASHER].timer != -1) //æ®´ã£ãŸã®ã§å¯¾è±¡ã®ãƒ™ãƒŠãƒ ã‚¹ãƒ—ラッシャー状態を解除
- skill_status_change_end (target, SC_SPLASHER, -1);
-
- map_freeblock_unlock ();
+ map_freeblock_unlock();
}
return wd.dmg_lv;
}
-int battle_check_undead (int race, int element)
+bool battle_check_undead(Race race, Element element)
{
if (battle_config.undead_detect_type == 0)
{
- if (element == 9)
- return 1;
+ return element == Element::undead;
}
else if (battle_config.undead_detect_type == 1)
{
- if (race == 1)
- return 1;
+ return race == Race::undead;
}
else
{
- if (element == 9 || race == 1)
- return 1;
+ return element == Element::undead || race == Race::undead;
}
- return 0;
}
/*==========================================
* 敵味方判定(1=肯定,0=å¦å®š,-1=エラー)
* flag&0xf0000 = 0x00000:敵ã˜ã‚ƒãªã„ã‹åˆ¤å®šï¼ˆret:1ï¼æ•µã§ã¯ãªã„)
- * = 0x10000:パーティー判定(ret:1=パーティーメンãƒ)
- * = 0x20000:å…¨ã¦(ret:1=敵味方両方)
- * = 0x40000:敵ã‹åˆ¤å®š(ret:1=敵)
- * = 0x50000:パーティーã˜ã‚ƒãªã„ã‹åˆ¤å®š(ret:1=パーティã§ãªã„)
+ * = 0x10000:パーティー判定(ret:1=パーティーメンãƒ)
+ * = 0x20000:å…¨ã¦(ret:1=敵味方両方)
+ * = 0x40000:敵ã‹åˆ¤å®š(ret:1=敵)
+ * = 0x50000:パーティーã˜ã‚ƒãªã„ã‹åˆ¤å®š(ret:1=パーティã§ãªã„)
*------------------------------------------
*/
-int battle_check_target (struct block_list *src, struct block_list *target,
- int flag)
+int battle_check_target(struct block_list *src, struct block_list *target,
+ BCT flag)
{
- int s_p, s_g, t_p, t_g;
+ int s_p, t_p;
struct block_list *ss = src;
- nullpo_retr (0, src);
- nullpo_retr (0, target);
+ nullpo_ret(src);
+ nullpo_ret(target);
- if (flag & 0x40000)
+ if (flag & BCT_ENEMY)
{ // å転フラグ
- int ret = battle_check_target (src, target, flag & 0x30000);
+ int ret = battle_check_target(src, target, flag & (BCT_PARTY | BCT_ALL));
if (ret != -1)
return !ret;
return -1;
}
- if (flag & 0x20000)
+ if (flag & BCT_ALL)
{
- if (target->type == BL_MOB || target->type == BL_PC)
+ if (target->type == BL::MOB || target->type == BL::PC)
return 1;
else
return -1;
}
- if (src->type == BL_SKILL && target->type == BL_SKILL) // 対象ãŒã‚¹ã‚­ãƒ«ãƒ¦ãƒ‹ãƒƒãƒˆãªã‚‰ç„¡æ¡ä»¶è‚¯å®š
- return -1;
-
- if (target->type == BL_PC
- && ((struct map_session_data *) target)->invincible_timer != -1)
+ if (target->type == BL::PC
+ && ((struct map_session_data *) target)->invincible_timer)
return -1;
- if (target->type == BL_SKILL)
- {
- switch (((struct skill_unit *) target)->group->unit_id)
- {
- case 0x8d:
- case 0x8f:
- case 0x98:
- return 0;
- break;
- }
- }
-
- // スキルユニットã®å ´åˆã€è¦ªã‚’求ã‚ã‚‹
- if (src->type == BL_SKILL)
- {
- int inf2 =
- skill_get_inf2 (((struct skill_unit *) src)->group->skill_id);
- if ((ss =
- map_id2bl (((struct skill_unit *) src)->group->src_id)) == NULL)
- return -1;
- if (ss->prev == NULL)
- return -1;
- if (inf2 & 0x80 && (map[src->m].flag.pvp || pc_iskiller ((struct map_session_data *) src, (struct map_session_data *) target)) && // [MouseJstr]
- !(target->type == BL_PC
- && pc_isinvisible ((struct map_session_data *) target)))
- return 0;
- if (ss == target)
- {
- if (inf2 & 0x100)
- return 0;
- if (inf2 & 0x200)
- return -1;
- }
- }
// Mobã§master_idãŒã‚ã£ã¦special_mob_aiãªã‚‰ã€å¬å–šä¸»ã‚’求ã‚ã‚‹
- if (src->type == BL_MOB)
+ if (src->type == BL::MOB)
{
struct mob_data *md = (struct mob_data *) src;
if (md && md->master_id > 0)
@@ -5254,7 +2173,7 @@ int battle_check_target (struct block_list *src, struct block_list *target,
return 1;
if (md->state.special_mob_ai)
{
- if (target->type == BL_MOB)
+ if (target->type == BL::MOB)
{ //special_mob_aiã§å¯¾è±¡ãŒMob
struct mob_data *tmd = (struct mob_data *) target;
if (tmd)
@@ -5271,7 +2190,7 @@ int battle_check_target (struct block_list *src, struct block_list *target,
}
}
}
- if ((ss = map_id2bl (md->master_id)) == NULL)
+ if ((ss = map_id2bl(md->master_id)) == NULL)
return -1;
}
}
@@ -5279,25 +2198,23 @@ int battle_check_target (struct block_list *src, struct block_list *target,
if (src == target || ss == target) // åŒã˜ãªã‚‰è‚¯å®š
return 1;
- if (target->type == BL_PC
- && pc_isinvisible ((struct map_session_data *) target))
+ if (target->type == BL::PC
+ && pc_isinvisible((struct map_session_data *) target))
return -1;
if (src->prev == NULL || // 死んã§ã‚‹ãªã‚‰ã‚¨ãƒ©ãƒ¼
- (src->type == BL_PC && pc_isdead ((struct map_session_data *) src)))
+ (src->type == BL::PC && pc_isdead((struct map_session_data *) src)))
return -1;
- if ((ss->type == BL_PC && target->type == BL_MOB) ||
- (ss->type == BL_MOB && target->type == BL_PC))
+ if ((ss->type == BL::PC && target->type == BL::MOB) ||
+ (ss->type == BL::MOB && target->type == BL::PC))
return 0; // PCvsMOBãªã‚‰å¦å®š
- s_p = battle_get_party_id (ss);
- s_g = battle_get_guild_id (ss);
+ s_p = battle_get_party_id(ss);
- t_p = battle_get_party_id (target);
- t_g = battle_get_guild_id (target);
+ t_p = battle_get_party_id(target);
- if (flag & 0x10000)
+ if (flag & BCT_PARTY)
{
if (s_p && t_p && s_p == t_p) // åŒã˜ãƒ‘ーティãªã‚‰è‚¯å®šï¼ˆå‘³æ–¹ï¼‰
return 1;
@@ -5305,61 +2222,20 @@ int battle_check_target (struct block_list *src, struct block_list *target,
return 0;
}
- if (ss->type == BL_MOB && s_g > 0 && t_g > 0 && s_g == t_g) // åŒã˜ã‚®ãƒ«ãƒ‰/mobクラスãªã‚‰è‚¯å®šï¼ˆå‘³æ–¹ï¼‰
- return 1;
-
-//printf("ss:%d src:%d target:%d flag:0x%x %d %d ",ss->id,src->id,target->id,flag,src->type,target->type);
-//printf("p:%d %d g:%d %d\n",s_p,t_p,s_g,t_g);
+//PRINTF("ss:%d src:%d target:%d flag:0x%x %d %d ",ss->id,src->id,target->id,flag,src->type,target->type);
+//PRINTF("p:%d %d g:%d %d\n",s_p,t_p,s_g,t_g);
- if (ss->type == BL_PC && target->type == BL_PC)
+ if (ss->type == BL::PC && target->type == BL::PC)
{ // 両方PVPモードãªã‚‰å¦å®šï¼ˆæ•µï¼‰
- struct skill_unit *su = NULL;
- if (src->type == BL_SKILL)
- su = (struct skill_unit *) src;
if (map[ss->m].flag.pvp
- || pc_iskiller ((struct map_session_data *) ss,
+ || pc_iskiller((struct map_session_data *) ss,
(struct map_session_data *) target))
{ // [MouseJstr]
- if (su && su->group->target_flag == BCT_NOENEMY)
- return 1;
- else if (battle_config.pk_mode
- && (((struct map_session_data *) ss)->status.pc_class == 0
- || ((struct map_session_data *) target)->
- status.pc_class == 0))
+ if (battle_config.pk_mode)
return 1; // prevent novice engagement in pk_mode [Valaris]
else if (map[ss->m].flag.pvp_noparty && s_p > 0 && t_p > 0
&& s_p == t_p)
return 1;
- else if (map[ss->m].flag.pvp_noguild && s_g > 0 && t_g > 0
- && s_g == t_g)
- return 1;
- return 0;
- }
- if (map[src->m].flag.gvg)
- {
- struct guild *g = NULL;
- if (su && su->group->target_flag == BCT_NOENEMY)
- return 1;
- if (s_g > 0 && s_g == t_g)
- return 1;
- if (map[src->m].flag.gvg_noparty && s_p > 0 && t_p > 0
- && s_p == t_p)
- return 1;
- if ((g = guild_search (s_g)))
- {
- int i;
- for (i = 0; i < MAX_GUILDALLIANCE; i++)
- {
- if (g->alliance[i].guild_id > 0
- && g->alliance[i].guild_id == t_g)
- {
- if (g->alliance[i].opposition)
- return 0; //敵対ギルドãªã‚‰ç„¡æ¡ä»¶ã«æ•µ
- else
- return 1; //åŒç›Ÿã‚®ãƒ«ãƒ‰ãªã‚‰ç„¡æ¡ä»¶ã«å‘³æ–¹
- }
- }
- }
return 0;
}
}
@@ -5371,19 +2247,19 @@ int battle_check_target (struct block_list *src, struct block_list *target,
* 射程判定
*------------------------------------------
*/
-int battle_check_range (struct block_list *src, struct block_list *bl,
+int battle_check_range(struct block_list *src, struct block_list *bl,
int range)
{
- int dx, dy;
+ int dx, dy;
struct walkpath_data wpd;
- int arange;
+ int arange;
- nullpo_retr (0, src);
- nullpo_retr (0, bl);
+ nullpo_ret(src);
+ nullpo_ret(bl);
- dx = abs (bl->x - src->x);
- dy = abs (bl->y - src->y);
+ dx = abs(bl->x - src->x);
+ dy = abs(bl->y - src->y);
arange = ((dx > dy) ? dx : dy);
if (src->m != bl->m) // é•ã†ãƒžãƒƒãƒ—
@@ -5402,42 +2278,22 @@ int battle_check_range (struct block_list *src, struct block_list *bl,
wpd.path_len = 0;
wpd.path_pos = 0;
wpd.path_half = 0;
- if (path_search (&wpd, src->m, src->x, src->y, bl->x, bl->y, 0x10001) !=
+ if (path_search(&wpd, src->m, src->x, src->y, bl->x, bl->y, 0x10001) !=
-1)
return 1;
dx = (dx > 0) ? 1 : ((dx < 0) ? -1 : 0);
dy = (dy > 0) ? 1 : ((dy < 0) ? -1 : 0);
- return (path_search (&wpd, src->m, src->x + dx, src->y + dy,
+ return (path_search(&wpd, src->m, src->x + dx, src->y + dy,
bl->x - dx, bl->y - dy, 0x10001) != -1) ? 1 : 0;
}
/*==========================================
- * Return numerical value of a switch configuration (modified by [Yor])
- * on/off, english, fran軋is, deutsch, espal
- *------------------------------------------
- */
-int battle_config_switch (const char *str)
-{
- if (strcasecmp (str, "on") == 0 || strcasecmp (str, "yes") == 0
- || strcasecmp (str, "oui") == 0 || strcasecmp (str, "ja") == 0
- || strcasecmp (str, "si") == 0)
- return 1;
- if (strcasecmp (str, "off") == 0 || strcasecmp (str, "no") == 0
- || strcasecmp (str, "non") == 0 || strcasecmp (str, "nein") == 0)
- return 0;
- return atoi (str);
-}
-
-/*==========================================
* 設定ファイルを読ã¿è¾¼ã‚€
*------------------------------------------
*/
-int battle_config_read (const char *cfgName)
+int battle_config_read(const char *cfgName)
{
- int i;
- char line[1024], w1[1024], w2[1024];
- FILE *fp;
static int count = 0;
if ((count++) == 0)
@@ -5456,21 +2312,16 @@ int battle_config_read (const char *cfgName)
battle_config.skill_out_range_consume = 1;
battle_config.mob_skill_add_range = 0;
battle_config.pc_damage_delay = 1;
- battle_config.pc_damage_delay_rate = 100;
battle_config.defnotenemy = 1;
battle_config.random_monster_checklv = 1;
battle_config.attr_recover = 1;
- battle_config.flooritem_lifetime = LIFETIME_FLOORITEM * 1000;
+ battle_config.flooritem_lifetime = (int)std::chrono::duration_cast<std::chrono::milliseconds>(LIFETIME_FLOORITEM).count();
battle_config.item_auto_get = 0;
battle_config.drop_pickup_safety_zone = 20;
battle_config.item_first_get_time = 3000;
battle_config.item_second_get_time = 1000;
battle_config.item_third_get_time = 1000;
- battle_config.mvp_item_first_get_time = 10000;
- battle_config.mvp_item_second_get_time = 10000;
- battle_config.mvp_item_third_get_time = 2000;
- battle_config.drop_rate0item = 0;
battle_config.base_exp_rate = 100;
battle_config.job_exp_rate = 100;
battle_config.pvp_exp = 1;
@@ -5481,30 +2332,23 @@ int battle_config_read (const char *cfgName)
battle_config.zeny_penalty = 0;
battle_config.restart_hp_rate = 0;
battle_config.restart_sp_rate = 0;
- battle_config.mvp_item_rate = 100;
- battle_config.mvp_exp_rate = 100;
- battle_config.mvp_hp_rate = 100;
battle_config.monster_hp_rate = 100;
battle_config.monster_max_aspd = 199;
battle_config.atc_gmonly = 0;
battle_config.gm_allskill = 0;
battle_config.gm_allequip = 0;
battle_config.gm_skilluncond = 0;
- battle_config.guild_max_castles = 0;
battle_config.skillfree = 0;
battle_config.skillup_limit = 0;
battle_config.wp_rate = 100;
battle_config.pp_rate = 100;
battle_config.monster_active_enable = 1;
- battle_config.monster_damage_delay_rate = 100;
battle_config.monster_loot_type = 0;
battle_config.mob_skill_use = 1;
battle_config.mob_count_rate = 100;
battle_config.quest_skill_learn = 0;
battle_config.quest_skill_reset = 1;
battle_config.basic_skill_check = 1;
- battle_config.guild_emperium_check = 1;
- battle_config.guild_exp_limit = 50;
battle_config.pc_invincible_time = 5000;
battle_config.skill_min_damage = 0;
battle_config.finger_offensive_type = 0;
@@ -5540,25 +2384,17 @@ int battle_config_read (const char *cfgName)
battle_config.agi_penaly_type = 0;
battle_config.agi_penaly_count = 3;
battle_config.agi_penaly_num = 0;
- battle_config.agi_penaly_count_lv = ATK_FLEE;
+ battle_config.agi_penaly_count_lv = static_cast<int>(ATK::FLEE); // FIXME
battle_config.vit_penaly_type = 0;
battle_config.vit_penaly_count = 3;
battle_config.vit_penaly_num = 0;
- battle_config.vit_penaly_count_lv = ATK_DEF;
- battle_config.player_defense_type = 0;
- battle_config.monster_defense_type = 0;
- battle_config.magic_defense_type = 0;
+ battle_config.vit_penaly_count_lv = static_cast<int>(ATK::DEF); // FIXME
battle_config.pc_skill_reiteration = 0;
battle_config.monster_skill_reiteration = 0;
battle_config.pc_skill_nofootset = 0;
battle_config.monster_skill_nofootset = 0;
battle_config.pc_cloak_check_type = 0;
battle_config.monster_cloak_check_type = 0;
- battle_config.gvg_short_damage_rate = 100;
- battle_config.gvg_long_damage_rate = 100;
- battle_config.gvg_magic_damage_rate = 100;
- battle_config.gvg_misc_damage_rate = 100;
- battle_config.gvg_eliminate_time = 7000;
battle_config.mob_changetarget_byskill = 0;
battle_config.pc_attack_direction_change = 1;
battle_config.monster_attack_direction_change = 1;
@@ -5590,34 +2426,12 @@ int battle_config_read (const char *cfgName)
battle_config.invite_request_check = 1;
battle_config.skill_removetrap_type = 0;
battle_config.disp_experience = 0;
- battle_config.item_rate_common = 100;
- battle_config.item_rate_equip = 100;
- battle_config.item_rate_card = 100;
- battle_config.item_rate_heal = 100; // Added by Valaris
- battle_config.item_rate_use = 100; // End
- battle_config.item_drop_common_min = 1; // Added by TyrNemesis^
- battle_config.item_drop_common_max = 10000;
- battle_config.item_drop_equip_min = 1;
- battle_config.item_drop_equip_max = 10000;
- battle_config.item_drop_card_min = 1;
- battle_config.item_drop_card_max = 10000;
- battle_config.item_drop_mvp_min = 1;
- battle_config.item_drop_mvp_max = 10000; // End Addition
- battle_config.item_drop_heal_min = 1; // Added by Valaris
- battle_config.item_drop_heal_max = 10000;
- battle_config.item_drop_use_min = 1;
- battle_config.item_drop_use_max = 10000; // End
battle_config.prevent_logout = 1; // Added by RoVeRT
battle_config.maximum_level = 255; // Added by Valaris
battle_config.drops_by_luk = 0; // [Valaris]
- battle_config.equipment_breaking = 0; // [Valaris]
- battle_config.equipment_break_rate = 100; // [Valaris]
battle_config.pk_mode = 0; // [Valaris]
battle_config.multi_level_up = 0; // [Valaris]
battle_config.backstab_bow_penalty = 0; // Akaru
- battle_config.night_at_start = 0; // added by [Yor]
- battle_config.day_duration = 2 * 60 * 60 * 1000; // added by [Yor] (2 hours)
- battle_config.night_duration = 30 * 60 * 1000; // added by [Yor] (30 minutes)
battle_config.show_mob_hp = 0; // [Valaris]
battle_config.hack_info_GM_level = 60; // added by [Yor] (default: 60, GM level)
battle_config.any_warp_GM_min_level = 20; // added by [Yor]
@@ -5649,478 +2463,212 @@ int battle_config_read (const char *cfgName)
battle_config.mob_splash_radius = -1;
}
- fp = fopen_ (cfgName, "r");
- if (fp == NULL)
+ std::ifstream in(cfgName);
+ if (!in.is_open())
{
- printf ("file not found: %s\n", cfgName);
+ PRINTF("file not found: %s\n", cfgName);
return 1;
}
- while (fgets (line, 1020, fp))
+
+ std::string line;
+ while (std::getline(in, line))
{
+ // s/{"\([a-zA-Z_0-9]*\)", &battle_config.\1}/BATTLE_CONFIG_VAR(\1)/
const struct
{
- char str[128];
+ const char *str;
int *val;
} data[] =
{
- {
- "warp_point_debug", &battle_config.warp_point_debug},
- {
- "enemy_critical", &battle_config.enemy_critical},
- {
- "enemy_critical_rate", &battle_config.enemy_critical_rate},
- {
- "enemy_str", &battle_config.enemy_str},
- {
- "enemy_perfect_flee", &battle_config.enemy_perfect_flee},
- {
- "casting_rate", &battle_config.cast_rate},
- {
- "delay_rate", &battle_config.delay_rate},
- {
- "delay_dependon_dex", &battle_config.delay_dependon_dex},
- {
- "skill_delay_attack_enable",
- &battle_config.sdelay_attack_enable},
- {
- "left_cardfix_to_right", &battle_config.left_cardfix_to_right},
- {
- "player_skill_add_range", &battle_config.pc_skill_add_range},
- {
- "skill_out_range_consume",
- &battle_config.skill_out_range_consume},
- {
- "monster_skill_add_range", &battle_config.mob_skill_add_range},
- {
- "player_damage_delay", &battle_config.pc_damage_delay},
- {
- "player_damage_delay_rate",
- &battle_config.pc_damage_delay_rate},
- {
- "defunit_not_enemy", &battle_config.defnotenemy},
- {
- "random_monster_checklv",
- &battle_config.random_monster_checklv},
- {
- "attribute_recover", &battle_config.attr_recover},
- {
- "flooritem_lifetime", &battle_config.flooritem_lifetime},
- {
- "item_auto_get", &battle_config.item_auto_get},
- {
- "drop_pickup_safety_zone",
- &battle_config.drop_pickup_safety_zone},
- {
- "item_first_get_time", &battle_config.item_first_get_time},
- {
- "item_second_get_time", &battle_config.item_second_get_time},
- {
- "item_third_get_time", &battle_config.item_third_get_time},
- {
- "mvp_item_first_get_time",
- &battle_config.mvp_item_first_get_time},
- {
- "mvp_item_second_get_time",
- &battle_config.mvp_item_second_get_time},
- {
- "mvp_item_third_get_time",
- &battle_config.mvp_item_third_get_time},
- {
- "item_rate", &battle_config.item_rate},
- {
- "drop_rate0item", &battle_config.drop_rate0item},
- {
- "base_exp_rate", &battle_config.base_exp_rate},
- {
- "job_exp_rate", &battle_config.job_exp_rate},
- {
- "pvp_exp", &battle_config.pvp_exp},
- {
- "gtb_pvp_only", &battle_config.gtb_pvp_only},
- {
- "guild_max_castles", &battle_config.guild_max_castles},
- {
- "death_penalty_type", &battle_config.death_penalty_type},
- {
- "death_penalty_base", &battle_config.death_penalty_base},
- {
- "death_penalty_job", &battle_config.death_penalty_job},
- {
- "zeny_penalty", &battle_config.zeny_penalty},
- {
- "restart_hp_rate", &battle_config.restart_hp_rate},
- {
- "restart_sp_rate", &battle_config.restart_sp_rate},
- {
- "mvp_hp_rate", &battle_config.mvp_hp_rate},
- {
- "mvp_item_rate", &battle_config.mvp_item_rate},
- {
- "mvp_exp_rate", &battle_config.mvp_exp_rate},
- {
- "monster_hp_rate", &battle_config.monster_hp_rate},
- {
- "monster_max_aspd", &battle_config.monster_max_aspd},
- {
- "atcommand_gm_only", &battle_config.atc_gmonly},
- {
- "atcommand_spawn_quantity_limit",
- &battle_config.atc_spawn_quantity_limit},
- {
- "gm_all_skill", &battle_config.gm_allskill},
- {
- "gm_all_skill_add_abra", &battle_config.gm_allskill_addabra},
- {
- "gm_all_equipment", &battle_config.gm_allequip},
- {
- "gm_skill_unconditional", &battle_config.gm_skilluncond},
- {
- "player_skillfree", &battle_config.skillfree},
- {
- "player_skillup_limit", &battle_config.skillup_limit},
- {
- "weapon_produce_rate", &battle_config.wp_rate},
- {
- "potion_produce_rate", &battle_config.pp_rate},
- {
- "monster_active_enable", &battle_config.monster_active_enable},
- {
- "monster_damage_delay_rate",
- &battle_config.monster_damage_delay_rate},
- {
- "monster_loot_type", &battle_config.monster_loot_type},
- {
- "mob_skill_use", &battle_config.mob_skill_use},
- {
- "mob_count_rate", &battle_config.mob_count_rate},
- {
- "quest_skill_learn", &battle_config.quest_skill_learn},
- {
- "quest_skill_reset", &battle_config.quest_skill_reset},
- {
- "basic_skill_check", &battle_config.basic_skill_check},
- {
- "guild_emperium_check", &battle_config.guild_emperium_check},
- {
- "guild_exp_limit", &battle_config.guild_exp_limit},
- {
- "player_invincible_time", &battle_config.pc_invincible_time},
- {
- "skill_min_damage", &battle_config.skill_min_damage},
- {
- "finger_offensive_type", &battle_config.finger_offensive_type},
- {
- "heal_exp", &battle_config.heal_exp},
- {
- "resurrection_exp", &battle_config.resurrection_exp},
- {
- "shop_exp", &battle_config.shop_exp},
- {
- "combo_delay_rate", &battle_config.combo_delay_rate},
- {
- "item_check", &battle_config.item_check},
- {
- "wedding_modifydisplay", &battle_config.wedding_modifydisplay},
- {
- "natural_healhp_interval",
- &battle_config.natural_healhp_interval},
- {
- "natural_healsp_interval",
- &battle_config.natural_healsp_interval},
- {
- "natural_heal_skill_interval",
- &battle_config.natural_heal_skill_interval},
- {
- "natural_heal_weight_rate",
- &battle_config.natural_heal_weight_rate},
- {
- "itemheal_regeneration_factor",
- &battle_config.itemheal_regeneration_factor},
- {
- "item_name_override_grffile",
- &battle_config.item_name_override_grffile},
- {
- "arrow_decrement", &battle_config.arrow_decrement},
- {
- "max_aspd", &battle_config.max_aspd},
- {
- "max_hp", &battle_config.max_hp},
- {
- "max_sp", &battle_config.max_sp},
- {
- "max_lv", &battle_config.max_lv},
- {
- "max_parameter", &battle_config.max_parameter},
- {
- "max_cart_weight", &battle_config.max_cart_weight},
- {
- "player_skill_log", &battle_config.pc_skill_log},
- {
- "monster_skill_log", &battle_config.mob_skill_log},
- {
- "battle_log", &battle_config.battle_log},
- {
- "save_log", &battle_config.save_log},
- {
- "error_log", &battle_config.error_log},
- {
- "etc_log", &battle_config.etc_log},
- {
- "save_clothcolor", &battle_config.save_clothcolor},
- {
- "undead_detect_type", &battle_config.undead_detect_type},
- {
- "player_auto_counter_type",
- &battle_config.pc_auto_counter_type},
- {
- "monster_auto_counter_type",
- &battle_config.monster_auto_counter_type},
- {
- "agi_penaly_type", &battle_config.agi_penaly_type},
- {
- "agi_penaly_count", &battle_config.agi_penaly_count},
- {
- "agi_penaly_num", &battle_config.agi_penaly_num},
- {
- "agi_penaly_count_lv", &battle_config.agi_penaly_count_lv},
- {
- "vit_penaly_type", &battle_config.vit_penaly_type},
- {
- "vit_penaly_count", &battle_config.vit_penaly_count},
- {
- "vit_penaly_num", &battle_config.vit_penaly_num},
- {
- "vit_penaly_count_lv", &battle_config.vit_penaly_count_lv},
- {
- "player_defense_type", &battle_config.player_defense_type},
- {
- "monster_defense_type", &battle_config.monster_defense_type},
- {
- "magic_defense_type", &battle_config.magic_defense_type},
- {
- "player_skill_reiteration",
- &battle_config.pc_skill_reiteration},
- {
- "monster_skill_reiteration",
- &battle_config.monster_skill_reiteration},
- {
- "player_skill_nofootset", &battle_config.pc_skill_nofootset},
- {
- "monster_skill_nofootset",
- &battle_config.monster_skill_nofootset},
- {
- "player_cloak_check_type", &battle_config.pc_cloak_check_type},
- {
- "monster_cloak_check_type",
- &battle_config.monster_cloak_check_type},
- {
- "gvg_short_attack_damage_rate",
- &battle_config.gvg_short_damage_rate},
- {
- "gvg_long_attack_damage_rate",
- &battle_config.gvg_long_damage_rate},
- {
- "gvg_magic_attack_damage_rate",
- &battle_config.gvg_magic_damage_rate},
- {
- "gvg_misc_attack_damage_rate",
- &battle_config.gvg_misc_damage_rate},
- {
- "gvg_eliminate_time", &battle_config.gvg_eliminate_time},
- {
- "mob_changetarget_byskill",
- &battle_config.mob_changetarget_byskill},
- {
- "player_attack_direction_change",
- &battle_config.pc_attack_direction_change},
- {
- "monster_attack_direction_change",
- &battle_config.monster_attack_direction_change},
- {
- "player_land_skill_limit", &battle_config.pc_land_skill_limit},
- {
- "monster_land_skill_limit",
- &battle_config.monster_land_skill_limit},
- {
- "party_skill_penaly", &battle_config.party_skill_penaly},
- {
- "monster_class_change_full_recover",
- &battle_config.monster_class_change_full_recover},
- {
- "produce_item_name_input",
- &battle_config.produce_item_name_input},
- {
- "produce_potion_name_input",
- &battle_config.produce_potion_name_input},
- {
- "making_arrow_name_input",
- &battle_config.making_arrow_name_input},
- {
- "holywater_name_input", &battle_config.holywater_name_input},
- {
- "display_delay_skill_fail",
- &battle_config.display_delay_skill_fail},
- {
- "chat_warpportal", &battle_config.chat_warpportal},
- {
- "mob_warpportal", &battle_config.mob_warpportal},
- {
- "dead_branch_active", &battle_config.dead_branch_active},
- {
- "show_steal_in_same_party",
- &battle_config.show_steal_in_same_party},
- {
- "enable_upper_class", &battle_config.enable_upper_class},
- {
- "mob_attack_attr_none", &battle_config.mob_attack_attr_none},
- {
- "mob_ghostring_fix", &battle_config.mob_ghostring_fix},
- {
- "pc_attack_attr_none", &battle_config.pc_attack_attr_none},
- {
- "gx_allhit", &battle_config.gx_allhit},
- {
- "gx_cardfix", &battle_config.gx_cardfix},
- {
- "gx_dupele", &battle_config.gx_dupele},
- {
- "gx_disptype", &battle_config.gx_disptype},
- {
- "player_skill_partner_check",
- &battle_config.player_skill_partner_check},
- {
- "hide_GM_session", &battle_config.hide_GM_session},
- {
- "unit_movement_type", &battle_config.unit_movement_type},
- {
- "invite_request_check", &battle_config.invite_request_check},
- {
- "skill_removetrap_type", &battle_config.skill_removetrap_type},
- {
- "disp_experience", &battle_config.disp_experience},
- {
- "castle_defense_rate", &battle_config.castle_defense_rate},
- {
- "riding_weight", &battle_config.riding_weight},
- {
- "item_rate_common", &battle_config.item_rate_common}, // Added by RoVeRT
- {
- "item_rate_equip", &battle_config.item_rate_equip},
- {
- "item_rate_card", &battle_config.item_rate_card}, // End Addition
- {
- "item_rate_heal", &battle_config.item_rate_heal}, // Added by Valaris
- {
- "item_rate_use", &battle_config.item_rate_use}, // End
- {
- "item_drop_common_min", &battle_config.item_drop_common_min}, // Added by TyrNemesis^
- {
- "item_drop_common_max", &battle_config.item_drop_common_max},
- {
- "item_drop_equip_min", &battle_config.item_drop_equip_min},
- {
- "item_drop_equip_max", &battle_config.item_drop_equip_max},
- {
- "item_drop_card_min", &battle_config.item_drop_card_min},
- {
- "item_drop_card_max", &battle_config.item_drop_card_max},
- {
- "item_drop_mvp_min", &battle_config.item_drop_mvp_min},
- {
- "item_drop_mvp_max", &battle_config.item_drop_mvp_max}, // End Addition
- {
- "prevent_logout", &battle_config.prevent_logout}, // Added by RoVeRT
- {
- "alchemist_summon_reward", &battle_config.alchemist_summon_reward}, // [Valaris]
- {
- "maximum_level", &battle_config.maximum_level}, // [Valaris]
- {
- "drops_by_luk", &battle_config.drops_by_luk}, // [Valaris]
- {
- "monsters_ignore_gm", &battle_config.monsters_ignore_gm}, // [Valaris]
- {
- "equipment_breaking", &battle_config.equipment_breaking}, // [Valaris]
- {
- "equipment_break_rate", &battle_config.equipment_break_rate}, // [Valaris]
- {
- "pk_mode", &battle_config.pk_mode}, // [Valaris]
- {
- "multi_level_up", &battle_config.multi_level_up}, // [Valaris]
- {
- "backstab_bow_penalty", &battle_config.backstab_bow_penalty},
- {
- "night_at_start", &battle_config.night_at_start}, // added by [Yor]
- {
- "day_duration", &battle_config.day_duration}, // added by [Yor]
- {
- "night_duration", &battle_config.night_duration}, // added by [Yor]
- {
- "show_mob_hp", &battle_config.show_mob_hp}, // [Valaris]
- {
- "hack_info_GM_level", &battle_config.hack_info_GM_level}, // added by [Yor]
- {
- "any_warp_GM_min_level", &battle_config.any_warp_GM_min_level}, // added by [Yor]
- {
- "packet_ver_flag", &battle_config.packet_ver_flag}, // added by [Yor]
- {
- "min_hair_style", &battle_config.min_hair_style}, // added by [MouseJstr]
- {
- "max_hair_style", &battle_config.max_hair_style}, // added by [MouseJstr]
- {
- "min_hair_color", &battle_config.min_hair_color}, // added by [MouseJstr]
- {
- "max_hair_color", &battle_config.max_hair_color}, // added by [MouseJstr]
- {
- "min_cloth_color", &battle_config.min_cloth_color}, // added by [MouseJstr]
- {
- "max_cloth_color", &battle_config.max_cloth_color}, // added by [MouseJstr]
- {
- "castrate_dex_scale", &battle_config.castrate_dex_scale}, // added by [MouseJstr]
- {
- "area_size", &battle_config.area_size}, // added by [MouseJstr]
- {
- "muting_players", &battle_config.muting_players}, // added by [Apple]
- {
- "chat_lame_penalty", &battle_config.chat_lame_penalty},
- {
- "chat_spam_threshold", &battle_config.chat_spam_threshold},
- {
- "chat_spam_flood", &battle_config.chat_spam_flood},
- {
- "chat_spam_ban", &battle_config.chat_spam_ban},
- {
- "chat_spam_warn", &battle_config.chat_spam_warn},
- {
- "chat_maxline", &battle_config.chat_maxline},
- {
- "packet_spam_threshold", &battle_config.packet_spam_threshold},
- {
- "packet_spam_flood", &battle_config.packet_spam_flood},
- {
- "packet_spam_kick", &battle_config.packet_spam_kick},
- {
- "mask_ip_gms", &battle_config.mask_ip_gms},
- {
- "mob_splash_radius", &battle_config.mob_splash_radius},
+ {"warp_point_debug", &battle_config.warp_point_debug},
+ {"enemy_critical", &battle_config.enemy_critical},
+ {"enemy_critical_rate", &battle_config.enemy_critical_rate},
+ {"enemy_str", &battle_config.enemy_str},
+ {"enemy_perfect_flee", &battle_config.enemy_perfect_flee},
+ {"casting_rate", &battle_config.cast_rate},
+ {"delay_rate", &battle_config.delay_rate},
+ {"delay_dependon_dex", &battle_config.delay_dependon_dex},
+ {"skill_delay_attack_enable", &battle_config.sdelay_attack_enable},
+ {"left_cardfix_to_right", &battle_config.left_cardfix_to_right},
+ {"player_skill_add_range", &battle_config.pc_skill_add_range},
+ {"skill_out_range_consume", &battle_config.skill_out_range_consume},
+ {"monster_skill_add_range", &battle_config.mob_skill_add_range},
+ {"player_damage_delay", &battle_config.pc_damage_delay},
+ {"defunit_not_enemy", &battle_config.defnotenemy},
+ {"random_monster_checklv", &battle_config.random_monster_checklv},
+ {"attribute_recover", &battle_config.attr_recover},
+ {"flooritem_lifetime", &battle_config.flooritem_lifetime},
+ {"item_auto_get", &battle_config.item_auto_get},
+ {"drop_pickup_safety_zone", &battle_config.drop_pickup_safety_zone},
+ {"item_first_get_time", &battle_config.item_first_get_time},
+ {"item_second_get_time", &battle_config.item_second_get_time},
+ {"item_third_get_time", &battle_config.item_third_get_time},
+ {"base_exp_rate", &battle_config.base_exp_rate},
+ {"job_exp_rate", &battle_config.job_exp_rate},
+ {"pvp_exp", &battle_config.pvp_exp},
+ {"gtb_pvp_only", &battle_config.gtb_pvp_only},
+ {"death_penalty_type", &battle_config.death_penalty_type},
+ {"death_penalty_base", &battle_config.death_penalty_base},
+ {"death_penalty_job", &battle_config.death_penalty_job},
+ {"zeny_penalty", &battle_config.zeny_penalty},
+ {"restart_hp_rate", &battle_config.restart_hp_rate},
+ {"restart_sp_rate", &battle_config.restart_sp_rate},
+ {"monster_hp_rate", &battle_config.monster_hp_rate},
+ {"monster_max_aspd", &battle_config.monster_max_aspd},
+ {"atcommand_gm_only", &battle_config.atc_gmonly},
+ {"atcommand_spawn_quantity_limit", &battle_config.atc_spawn_quantity_limit},
+ {"gm_all_skill", &battle_config.gm_allskill},
+ {"gm_all_skill_add_abra", &battle_config.gm_allskill_addabra},
+ {"gm_all_equipment", &battle_config.gm_allequip},
+ {"gm_skill_unconditional", &battle_config.gm_skilluncond},
+ {"player_skillfree", &battle_config.skillfree},
+ {"player_skillup_limit", &battle_config.skillup_limit},
+ {"weapon_produce_rate", &battle_config.wp_rate},
+ {"potion_produce_rate", &battle_config.pp_rate},
+ {"monster_active_enable", &battle_config.monster_active_enable},
+ {"monster_loot_type", &battle_config.monster_loot_type},
+ {"mob_skill_use", &battle_config.mob_skill_use},
+ {"mob_count_rate", &battle_config.mob_count_rate},
+ {"quest_skill_learn", &battle_config.quest_skill_learn},
+ {"quest_skill_reset", &battle_config.quest_skill_reset},
+ {"basic_skill_check", &battle_config.basic_skill_check},
+ {"player_invincible_time", &battle_config.pc_invincible_time},
+ {"skill_min_damage", &battle_config.skill_min_damage},
+ {"finger_offensive_type", &battle_config.finger_offensive_type},
+ {"heal_exp", &battle_config.heal_exp},
+ {"resurrection_exp", &battle_config.resurrection_exp},
+ {"shop_exp", &battle_config.shop_exp},
+ {"combo_delay_rate", &battle_config.combo_delay_rate},
+ {"item_check", &battle_config.item_check},
+ {"wedding_modifydisplay", &battle_config.wedding_modifydisplay},
+ {"natural_healhp_interval", &battle_config.natural_healhp_interval},
+ {"natural_healsp_interval", &battle_config.natural_healsp_interval},
+ {"natural_heal_skill_interval", &battle_config.natural_heal_skill_interval},
+ {"natural_heal_weight_rate", &battle_config.natural_heal_weight_rate},
+ {"itemheal_regeneration_factor", &battle_config.itemheal_regeneration_factor},
+ {"item_name_override_grffile", &battle_config.item_name_override_grffile},
+ {"arrow_decrement", &battle_config.arrow_decrement},
+ {"max_aspd", &battle_config.max_aspd},
+ {"max_hp", &battle_config.max_hp},
+ {"max_sp", &battle_config.max_sp},
+ {"max_lv", &battle_config.max_lv},
+ {"max_parameter", &battle_config.max_parameter},
+ {"max_cart_weight", &battle_config.max_cart_weight},
+ {"player_skill_log", &battle_config.pc_skill_log},
+ {"monster_skill_log", &battle_config.mob_skill_log},
+ {"battle_log", &battle_config.battle_log},
+ {"save_log", &battle_config.save_log},
+ {"error_log", &battle_config.error_log},
+ {"etc_log", &battle_config.etc_log},
+ {"save_clothcolor", &battle_config.save_clothcolor},
+ {"undead_detect_type", &battle_config.undead_detect_type},
+ {"player_auto_counter_type", &battle_config.pc_auto_counter_type},
+ {"monster_auto_counter_type", &battle_config.monster_auto_counter_type},
+ {"agi_penaly_type", &battle_config.agi_penaly_type},
+ {"agi_penaly_count", &battle_config.agi_penaly_count},
+ {"agi_penaly_num", &battle_config.agi_penaly_num},
+ {"agi_penaly_count_lv", &battle_config.agi_penaly_count_lv},
+ {"vit_penaly_type", &battle_config.vit_penaly_type},
+ {"vit_penaly_count", &battle_config.vit_penaly_count},
+ {"vit_penaly_num", &battle_config.vit_penaly_num},
+ {"vit_penaly_count_lv", &battle_config.vit_penaly_count_lv},
+ {"player_skill_reiteration", &battle_config.pc_skill_reiteration},
+ {"monster_skill_reiteration", &battle_config.monster_skill_reiteration},
+ {"player_skill_nofootset", &battle_config.pc_skill_nofootset},
+ {"monster_skill_nofootset", &battle_config.monster_skill_nofootset},
+ {"player_cloak_check_type", &battle_config.pc_cloak_check_type},
+ {"monster_cloak_check_type", &battle_config.monster_cloak_check_type},
+ {"mob_changetarget_byskill", &battle_config.mob_changetarget_byskill},
+ {"player_attack_direction_change", &battle_config.pc_attack_direction_change},
+ {"monster_attack_direction_change", &battle_config.monster_attack_direction_change},
+ {"player_land_skill_limit", &battle_config.pc_land_skill_limit},
+ {"monster_land_skill_limit", &battle_config.monster_land_skill_limit},
+ {"party_skill_penaly", &battle_config.party_skill_penaly},
+ {"monster_class_change_full_recover", &battle_config.monster_class_change_full_recover},
+ {"produce_item_name_input", &battle_config.produce_item_name_input},
+ {"produce_potion_name_input", &battle_config.produce_potion_name_input},
+ {"making_arrow_name_input", &battle_config.making_arrow_name_input},
+ {"holywater_name_input", &battle_config.holywater_name_input},
+ {"display_delay_skill_fail", &battle_config.display_delay_skill_fail},
+ {"chat_warpportal", &battle_config.chat_warpportal},
+ {"mob_warpportal", &battle_config.mob_warpportal},
+ {"dead_branch_active", &battle_config.dead_branch_active},
+ {"show_steal_in_same_party", &battle_config.show_steal_in_same_party},
+ {"enable_upper_class", &battle_config.enable_upper_class},
+ {"mob_attack_attr_none", &battle_config.mob_attack_attr_none},
+ {"mob_ghostring_fix", &battle_config.mob_ghostring_fix},
+ {"pc_attack_attr_none", &battle_config.pc_attack_attr_none},
+ {"gx_allhit", &battle_config.gx_allhit},
+ {"gx_cardfix", &battle_config.gx_cardfix},
+ {"gx_dupele", &battle_config.gx_dupele},
+ {"gx_disptype", &battle_config.gx_disptype},
+ {"player_skill_partner_check", &battle_config.player_skill_partner_check},
+ {"hide_GM_session", &battle_config.hide_GM_session},
+ {"unit_movement_type", &battle_config.unit_movement_type},
+ {"invite_request_check", &battle_config.invite_request_check},
+ {"skill_removetrap_type", &battle_config.skill_removetrap_type},
+ {"disp_experience", &battle_config.disp_experience},
+ {"riding_weight", &battle_config.riding_weight},
+ {"prevent_logout", &battle_config.prevent_logout}, // Added by RoVeRT
+ {"alchemist_summon_reward", &battle_config.alchemist_summon_reward}, // [Valaris]
+ {"maximum_level", &battle_config.maximum_level}, // [Valaris]
+ {"drops_by_luk", &battle_config.drops_by_luk}, // [Valaris]
+ {"monsters_ignore_gm", &battle_config.monsters_ignore_gm}, // [Valaris]
+ {"pk_mode", &battle_config.pk_mode}, // [Valaris]
+ {"multi_level_up", &battle_config.multi_level_up}, // [Valaris]
+ {"backstab_bow_penalty", &battle_config.backstab_bow_penalty},
+ {"show_mob_hp", &battle_config.show_mob_hp}, // [Valaris]
+ {"hack_info_GM_level", &battle_config.hack_info_GM_level}, // added by [Yor]
+ {"any_warp_GM_min_level", &battle_config.any_warp_GM_min_level}, // added by [Yor]
+ {"packet_ver_flag", &battle_config.packet_ver_flag}, // added by [Yor]
+ {"min_hair_style", &battle_config.min_hair_style}, // added by [MouseJstr]
+ {"max_hair_style", &battle_config.max_hair_style}, // added by [MouseJstr]
+ {"min_hair_color", &battle_config.min_hair_color}, // added by [MouseJstr]
+ {"max_hair_color", &battle_config.max_hair_color}, // added by [MouseJstr]
+ {"min_cloth_color", &battle_config.min_cloth_color}, // added by [MouseJstr]
+ {"max_cloth_color", &battle_config.max_cloth_color}, // added by [MouseJstr]
+ {"castrate_dex_scale", &battle_config.castrate_dex_scale}, // added by [MouseJstr]
+ {"area_size", &battle_config.area_size}, // added by [MouseJstr]
+ {"chat_lame_penalty", &battle_config.chat_lame_penalty},
+ {"chat_spam_threshold", &battle_config.chat_spam_threshold},
+ {"chat_spam_flood", &battle_config.chat_spam_flood},
+ {"chat_spam_ban", &battle_config.chat_spam_ban},
+ {"chat_spam_warn", &battle_config.chat_spam_warn},
+ {"chat_maxline", &battle_config.chat_maxline},
+ {"packet_spam_threshold", &battle_config.packet_spam_threshold},
+ {"packet_spam_flood", &battle_config.packet_spam_flood},
+ {"packet_spam_kick", &battle_config.packet_spam_kick},
+ {"mask_ip_gms", &battle_config.mask_ip_gms},
+ {"mob_splash_radius", &battle_config.mob_splash_radius},
};
- if (line[0] == '/' && line[1] == '/')
+ std::string w1, w2;
+ if (!split_key_value(line, &w1, &w2))
continue;
- if (sscanf (line, "%[^:]:%s", w1, w2) != 2)
+
+ if (w1 == "import")
+ {
+ battle_config_read(w2.c_str());
continue;
- for (i = 0; i < sizeof (data) / (sizeof (data[0])); i++)
- if (strcasecmp (w1, data[i].str) == 0)
- *data[i].val = battle_config_switch (w2);
+ }
+
+ for (auto datum : data)
+ if (w1 == datum.str)
+ {
+ *datum.val = config_switch(w2.c_str());
+ goto continue_outer;
+ }
- if (strcasecmp (w1, "import") == 0)
- battle_config_read (w2);
+ PRINTF("WARNING: unknown battle conf key: %s\n", w1);
+
+ continue_outer:
+ ;
}
- fclose_ (fp);
if (--count == 0)
{
- if (battle_config.flooritem_lifetime < 1000)
- battle_config.flooritem_lifetime = LIFETIME_FLOORITEM * 1000;
+ if (static_cast<interval_t>(battle_config.flooritem_lifetime) < std::chrono::seconds(1))
+ battle_config.flooritem_lifetime = (int)std::chrono::duration_cast<std::chrono::milliseconds>(LIFETIME_FLOORITEM).count();
if (battle_config.restart_hp_rate < 0)
battle_config.restart_hp_rate = 0;
else if (battle_config.restart_hp_rate > 100)
@@ -6129,12 +2677,12 @@ int battle_config_read (const char *cfgName)
battle_config.restart_sp_rate = 0;
else if (battle_config.restart_sp_rate > 100)
battle_config.restart_sp_rate = 100;
- if (battle_config.natural_healhp_interval < NATURAL_HEAL_INTERVAL)
- battle_config.natural_healhp_interval = NATURAL_HEAL_INTERVAL;
- if (battle_config.natural_healsp_interval < NATURAL_HEAL_INTERVAL)
- battle_config.natural_healsp_interval = NATURAL_HEAL_INTERVAL;
- if (battle_config.natural_heal_skill_interval < NATURAL_HEAL_INTERVAL)
- battle_config.natural_heal_skill_interval = NATURAL_HEAL_INTERVAL;
+ if (battle_config.natural_healhp_interval < NATURAL_HEAL_INTERVAL.count())
+ battle_config.natural_healhp_interval = NATURAL_HEAL_INTERVAL.count();
+ if (battle_config.natural_healsp_interval < NATURAL_HEAL_INTERVAL.count())
+ battle_config.natural_healsp_interval = NATURAL_HEAL_INTERVAL.count();
+ if (battle_config.natural_heal_skill_interval < NATURAL_HEAL_INTERVAL.count())
+ battle_config.natural_heal_skill_interval = NATURAL_HEAL_INTERVAL.count();
if (battle_config.natural_heal_weight_rate < 50)
battle_config.natural_heal_weight_rate = 50;
if (battle_config.natural_heal_weight_rate > 101)
@@ -6173,41 +2721,6 @@ int battle_config_read (const char *cfgName)
if (battle_config.vit_penaly_count < 2)
battle_config.vit_penaly_count = 2;
- if (battle_config.guild_exp_limit > 99)
- battle_config.guild_exp_limit = 99;
- if (battle_config.guild_exp_limit < 0)
- battle_config.guild_exp_limit = 0;
-
- if (battle_config.castle_defense_rate < 0)
- battle_config.castle_defense_rate = 0;
- if (battle_config.castle_defense_rate > 100)
- battle_config.castle_defense_rate = 100;
- if (battle_config.item_drop_common_min < 1) // Added by TyrNemesis^
- battle_config.item_drop_common_min = 1;
- if (battle_config.item_drop_common_max > 10000)
- battle_config.item_drop_common_max = 10000;
- if (battle_config.item_drop_equip_min < 1)
- battle_config.item_drop_equip_min = 1;
- if (battle_config.item_drop_equip_max > 10000)
- battle_config.item_drop_equip_max = 10000;
- if (battle_config.item_drop_card_min < 1)
- battle_config.item_drop_card_min = 1;
- if (battle_config.item_drop_card_max > 10000)
- battle_config.item_drop_card_max = 10000;
- if (battle_config.item_drop_mvp_min < 1)
- battle_config.item_drop_mvp_min = 1;
- if (battle_config.item_drop_mvp_max > 10000)
- battle_config.item_drop_mvp_max = 10000; // End Addition
-
- if (battle_config.night_at_start < 0) // added by [Yor]
- battle_config.night_at_start = 0;
- else if (battle_config.night_at_start > 1) // added by [Yor]
- battle_config.night_at_start = 1;
- if (battle_config.day_duration < 0) // added by [Yor]
- battle_config.day_duration = 0;
- if (battle_config.night_duration < 0) // added by [Yor]
- battle_config.night_duration = 0;
-
if (battle_config.hack_info_GM_level < 0) // added by [Yor]
battle_config.hack_info_GM_level = 0;
else if (battle_config.hack_info_GM_level > 100)
diff --git a/src/map/battle.hpp b/src/map/battle.hpp
index 5f2a22f..6d9d8dd 100644
--- a/src/map/battle.hpp
+++ b/src/map/battle.hpp
@@ -1,357 +1,267 @@
-// $Id: battle.h,v 1.6 2004/09/29 21:08:17 Akitasha Exp $
#ifndef BATTLE_HPP
#define BATTLE_HPP
+#include "battle.t.hpp"
+
+#include "../common/timer.t.hpp"
+
+#include "magic-interpreter.t.hpp"
+#include "map.t.hpp"
+#include "skill.t.hpp"
+
// ダメージ
struct Damage
{
- int damage, damage2;
- int type, div_;
- int amotion, dmotion;
- int blewcount;
- int flag;
- int dmg_lv; //囲ã¾ã‚Œæ¸›ç®—計算用 0:スキル攻撃 ATK_LUCKY,ATK_FLEE,ATK_DEF
+ int damage, damage2;
+ DamageType type;
+ int div_;
+ interval_t amotion, dmotion;
+ BF flag;
+ ATK dmg_lv;
};
-// 属性表(読ã¿è¾¼ã¿ã¯pc.cã€battle_attr_fixã§ä½¿ç”¨ï¼‰
-extern int attr_fix_table[4][10][10];
-
struct map_session_data;
struct mob_data;
struct block_list;
// ダメージ計算
-struct Damage battle_calc_attack (int attack_type,
- struct block_list *bl,
- struct block_list *target, int skill_num,
- int skill_lv, int flag);
-struct Damage battle_calc_weapon_attack (struct block_list *bl,
- struct block_list *target,
- int skill_num, int skill_lv,
- int flag);
-struct Damage battle_calc_magic_attack (struct block_list *bl,
- struct block_list *target,
- int skill_num, int skill_lv,
- int flag);
-struct Damage battle_calc_misc_attack (struct block_list *bl,
- struct block_list *target,
- int skill_num, int skill_lv, int flag);
-
-// 属性修正計算
-int battle_attr_fix (int damage, int atk_elem, int def_elem);
-
-// ダメージ最終計算
-int battle_calc_damage (struct block_list *src, struct block_list *bl,
- int damage, int div_, int skill_num, int skill_lv,
- int flag);
-enum
-{ // 最終計算ã®ãƒ•ãƒ©ã‚°
- BF_WEAPON = 0x0001,
- BF_MAGIC = 0x0002,
- BF_MISC = 0x0004,
- BF_SHORT = 0x0010,
- BF_LONG = 0x0040,
- BF_SKILL = 0x0100,
- BF_NORMAL = 0x0200,
- BF_WEAPONMASK = 0x000f,
- BF_RANGEMASK = 0x00f0,
- BF_SKILLMASK = 0x0f00,
-};
+struct Damage battle_calc_attack(BF attack_type,
+ struct block_list *bl, struct block_list *target,
+ SkillID skill_num, int skill_lv, int flag);
// 実際ã«HPを増減
-int battle_delay_damage (unsigned int tick, struct block_list *src,
- struct block_list *target, int damage, int flag);
-int battle_damage (struct block_list *bl, struct block_list *target,
- int damage, int flag);
-int battle_heal (struct block_list *bl, struct block_list *target, int hp,
- int sp, int flag);
+int battle_damage(struct block_list *bl, struct block_list *target,
+ int damage, int flag);
+int battle_heal(struct block_list *bl, struct block_list *target, int hp,
+ int sp, int flag);
// 攻撃や移動を止ã‚ã‚‹
-int battle_stopattack (struct block_list *bl);
-int battle_stopwalking (struct block_list *bl, int type);
+int battle_stopattack(struct block_list *bl);
+int battle_stopwalking(struct block_list *bl, int type);
// 通常攻撃処ç†ã¾ã¨ã‚
-int battle_weapon_attack (struct block_list *bl, struct block_list *target,
- unsigned int tick, int flag);
-
-// å„種パラメータを得る
-int battle_counttargeted (struct block_list *bl, struct block_list *src,
- int target_lv);
-int battle_is_unarmed (struct block_list *bl);
-int battle_get_class (struct block_list *bl);
-int battle_get_dir (struct block_list *bl);
-int battle_get_lv (struct block_list *bl);
-int battle_get_range (struct block_list *bl);
-int battle_get_hp (struct block_list *bl);
-int battle_get_max_hp (struct block_list *bl);
-int battle_get_str (struct block_list *bl);
-int battle_get_agi (struct block_list *bl);
-int battle_get_vit (struct block_list *bl);
-int battle_get_int (struct block_list *bl);
-int battle_get_dex (struct block_list *bl);
-int battle_get_luk (struct block_list *bl);
-int battle_get_hit (struct block_list *bl);
-int battle_get_flee (struct block_list *bl);
-int battle_get_def (struct block_list *bl);
-int battle_get_mdef (struct block_list *bl);
-int battle_get_flee2 (struct block_list *bl);
-int battle_get_def2 (struct block_list *bl);
-int battle_get_mdef2 (struct block_list *bl);
-int battle_get_baseatk (struct block_list *bl);
-int battle_get_atk (struct block_list *bl);
-int battle_get_atk2 (struct block_list *bl);
-int battle_get_speed (struct block_list *bl);
-int battle_get_adelay (struct block_list *bl);
-int battle_get_amotion (struct block_list *bl);
-int battle_get_dmotion (struct block_list *bl);
-int battle_get_element (struct block_list *bl);
-int battle_get_attack_element (struct block_list *bl);
-int battle_get_attack_element2 (struct block_list *bl); //左手武器属性å–å¾—
-#define battle_get_elem_type(bl) (battle_get_element(bl)%10)
-#define battle_get_elem_level(bl) (battle_get_element(bl)/10/2)
-int battle_get_party_id (struct block_list *bl);
-int battle_get_guild_id (struct block_list *bl);
-int battle_get_race (struct block_list *bl);
-int battle_get_size (struct block_list *bl);
-int battle_get_mode (struct block_list *bl);
-int battle_get_mexp (struct block_list *bl);
-int battle_get_stat (int stat_id /* SP_VIT or similar */ ,
- struct block_list *bl);
-
-struct status_change *battle_get_sc_data (struct block_list *bl);
-short *battle_get_sc_count (struct block_list *bl);
-short *battle_get_opt1 (struct block_list *bl);
-short *battle_get_opt2 (struct block_list *bl);
-short *battle_get_opt3 (struct block_list *bl);
-short *battle_get_option (struct block_list *bl);
+ATK battle_weapon_attack(struct block_list *bl, struct block_list *target,
+ tick_t tick);
-enum
+int battle_is_unarmed(struct block_list *bl);
+int battle_get_class(struct block_list *bl);
+DIR battle_get_dir(struct block_list *bl);
+int battle_get_lv(struct block_list *bl);
+int battle_get_range(struct block_list *bl);
+int battle_get_hp(struct block_list *bl);
+int battle_get_max_hp(struct block_list *bl);
+int battle_get_str(struct block_list *bl);
+int battle_get_agi(struct block_list *bl);
+int battle_get_vit(struct block_list *bl);
+int battle_get_int(struct block_list *bl);
+int battle_get_dex(struct block_list *bl);
+int battle_get_luk(struct block_list *bl);
+int battle_get_def(struct block_list *bl);
+int battle_get_mdef(struct block_list *bl);
+int battle_get_def2(struct block_list *bl);
+int battle_get_mdef2(struct block_list *bl);
+interval_t battle_get_speed(struct block_list *bl);
+interval_t battle_get_adelay(struct block_list *bl);
+interval_t battle_get_amotion(struct block_list *bl);
+interval_t battle_get_dmotion(struct block_list *bl);
+LevelElement battle_get_element(struct block_list *bl);
+inline
+Element battle_get_elem_type(struct block_list *bl)
{
- BCT_NOENEMY = 0x00000,
- BCT_PARTY = 0x10000,
- BCT_ENEMY = 0x40000,
- BCT_NOPARTY = 0x50000,
- BCT_ALL = 0x20000,
- BCT_NOONE = 0x60000,
-};
-
-int battle_check_undead (int race, int element);
-int battle_check_target (struct block_list *src, struct block_list *target,
- int flag);
-int battle_check_range (struct block_list *src, struct block_list *bl,
- int range);
+ return battle_get_element(bl).element;
+}
+int battle_get_party_id(struct block_list *bl);
+Race battle_get_race(struct block_list *bl);
+MobMode battle_get_mode(struct block_list *bl);
+int battle_get_stat(SP stat_id, struct block_list *bl);
-// 設定
+eptr<struct status_change, StatusChange> battle_get_sc_data(struct block_list *bl);
+short *battle_get_sc_count(struct block_list *bl);
+Opt1 *battle_get_opt1(struct block_list *bl);
+Opt2 *battle_get_opt2(struct block_list *bl);
+Opt3 *battle_get_opt3(struct block_list *bl);
+Option *battle_get_option(struct block_list *bl);
-int battle_config_switch (const char *str); // [Valaris]
+bool battle_check_undead(Race race, Element element);
+int battle_check_target(struct block_list *src, struct block_list *target,
+ BCT flag);
+int battle_check_range(struct block_list *src, struct block_list *bl,
+ int range);
extern struct Battle_Config
{
- int warp_point_debug;
- int enemy_critical;
- int enemy_critical_rate;
- int enemy_str;
- int enemy_perfect_flee;
- int cast_rate, delay_rate, delay_dependon_dex;
- int sdelay_attack_enable;
- int left_cardfix_to_right;
- int pc_skill_add_range;
- int skill_out_range_consume;
- int mob_skill_add_range;
- int pc_damage_delay;
- int pc_damage_delay_rate;
- int defnotenemy;
- int random_monster_checklv;
- int attr_recover;
- int flooritem_lifetime;
- int item_auto_get;
- int item_first_get_time;
- int item_second_get_time;
- int item_third_get_time;
- int mvp_item_first_get_time;
- int mvp_item_second_get_time;
- int mvp_item_third_get_time;
- int item_rate, base_exp_rate, job_exp_rate; // removed item rate, depreciated
- int drop_rate0item;
- int death_penalty_type;
- int death_penalty_base, death_penalty_job;
- int pvp_exp; // [MouseJstr]
- int gtb_pvp_only; // [MouseJstr]
- int zeny_penalty;
- int restart_hp_rate;
- int restart_sp_rate;
- int mvp_item_rate, mvp_exp_rate;
- int mvp_hp_rate;
- int monster_hp_rate;
- int monster_max_aspd;
- int atc_gmonly;
- int atc_spawn_quantity_limit;
- int gm_allskill;
- int gm_allskill_addabra;
- int gm_allequip;
- int gm_skilluncond;
- int skillfree;
- int skillup_limit;
- int wp_rate;
- int pp_rate;
- int monster_active_enable;
- int monster_damage_delay_rate;
- int monster_loot_type;
- int mob_skill_use;
- int mob_count_rate;
- int quest_skill_learn;
- int quest_skill_reset;
- int basic_skill_check;
- int guild_emperium_check;
- int guild_exp_limit;
- int guild_max_castles;
- int pc_invincible_time;
- int skill_min_damage;
- int finger_offensive_type;
- int heal_exp;
- int resurrection_exp;
- int shop_exp;
- int combo_delay_rate;
- int item_check;
- int wedding_modifydisplay;
- int natural_healhp_interval;
- int natural_healsp_interval;
- int natural_heal_skill_interval;
- int natural_heal_weight_rate;
- int item_name_override_grffile;
- int arrow_decrement;
- int max_aspd;
- int max_hp;
- int max_sp;
- int max_lv;
- int max_parameter;
- int max_cart_weight;
- int pc_skill_log;
- int mob_skill_log;
- int battle_log;
- int save_log;
- int error_log;
- int etc_log;
- int save_clothcolor;
- int undead_detect_type;
- int pc_auto_counter_type;
- int monster_auto_counter_type;
- int agi_penaly_type;
- int agi_penaly_count;
- int agi_penaly_num;
- int vit_penaly_type;
- int vit_penaly_count;
- int vit_penaly_num;
- int player_defense_type;
- int monster_defense_type;
- int magic_defense_type;
- int pc_skill_reiteration;
- int monster_skill_reiteration;
- int pc_skill_nofootset;
- int monster_skill_nofootset;
- int pc_cloak_check_type;
- int monster_cloak_check_type;
- int gvg_short_damage_rate;
- int gvg_long_damage_rate;
- int gvg_magic_damage_rate;
- int gvg_misc_damage_rate;
- int gvg_eliminate_time;
- int mob_changetarget_byskill;
- int pc_attack_direction_change;
- int monster_attack_direction_change;
- int pc_undead_nofreeze;
- int pc_land_skill_limit;
- int monster_land_skill_limit;
- int party_skill_penaly;
- int monster_class_change_full_recover;
- int produce_item_name_input;
- int produce_potion_name_input;
- int making_arrow_name_input;
- int holywater_name_input;
- int display_delay_skill_fail;
- int chat_warpportal;
- int mob_warpportal;
- int dead_branch_active;
- int show_steal_in_same_party;
- int enable_upper_class;
- int mob_attack_attr_none;
- int mob_ghostring_fix;
- int pc_attack_attr_none;
- int item_rate_common, item_rate_card, item_rate_equip, item_rate_heal, item_rate_use; // Added by RoVeRT, Additional Heal and Usable item rate by Val
- int item_drop_common_min, item_drop_common_max; // Added by TyrNemesis^
- int item_drop_card_min, item_drop_card_max;
- int item_drop_equip_min, item_drop_equip_max;
- int item_drop_mvp_min, item_drop_mvp_max; // End Addition
- int item_drop_heal_min, item_drop_heal_max; // Added by Valatris
- int item_drop_use_min, item_drop_use_max; //End
+ int warp_point_debug;
+ int enemy_critical;
+ int enemy_critical_rate;
+ int enemy_str;
+ int enemy_perfect_flee;
+ int cast_rate, delay_rate, delay_dependon_dex;
+ int sdelay_attack_enable;
+ int left_cardfix_to_right;
+ int pc_skill_add_range;
+ int skill_out_range_consume;
+ int mob_skill_add_range;
+ int pc_damage_delay;
+ int defnotenemy;
+ int random_monster_checklv;
+ int attr_recover;
+ int flooritem_lifetime;
+ int item_auto_get;
+ int item_first_get_time;
+ int item_second_get_time;
+ int item_third_get_time;
+ int base_exp_rate, job_exp_rate;
+ int death_penalty_type;
+ int death_penalty_base, death_penalty_job;
+ int pvp_exp; // [MouseJstr]
+ int gtb_pvp_only; // [MouseJstr]
+ int zeny_penalty;
+ int restart_hp_rate;
+ int restart_sp_rate;
+ int monster_hp_rate;
+ int monster_max_aspd;
+ int atc_gmonly;
+ int atc_spawn_quantity_limit;
+ int gm_allskill;
+ int gm_allskill_addabra;
+ int gm_allequip;
+ int gm_skilluncond;
+ int skillfree;
+ int skillup_limit;
+ int wp_rate;
+ int pp_rate;
+ int monster_active_enable;
+ int monster_loot_type;
+ int mob_skill_use;
+ int mob_count_rate;
+ int quest_skill_learn;
+ int quest_skill_reset;
+ int basic_skill_check;
+ int pc_invincible_time;
+ int skill_min_damage;
+ int finger_offensive_type;
+ int heal_exp;
+ int resurrection_exp;
+ int shop_exp;
+ int combo_delay_rate;
+ int item_check;
+ int wedding_modifydisplay;
+ int natural_healhp_interval;
+ int natural_healsp_interval;
+ int natural_heal_skill_interval;
+ int natural_heal_weight_rate;
+ int item_name_override_grffile;
+ int arrow_decrement;
+ int max_aspd;
+ int max_hp;
+ int max_sp;
+ int max_lv;
+ int max_parameter;
+ int max_cart_weight;
+ int pc_skill_log;
+ int mob_skill_log;
+ int battle_log;
+ int save_log;
+ int error_log;
+ int etc_log;
+ int save_clothcolor;
+ int undead_detect_type;
+ int pc_auto_counter_type;
+ int monster_auto_counter_type;
+ int agi_penaly_type;
+ int agi_penaly_count;
+ int agi_penaly_num;
+ int vit_penaly_type;
+ int vit_penaly_count;
+ int vit_penaly_num;
+ int pc_skill_reiteration;
+ int monster_skill_reiteration;
+ int pc_skill_nofootset;
+ int monster_skill_nofootset;
+ int pc_cloak_check_type;
+ int monster_cloak_check_type;
+ int mob_changetarget_byskill;
+ int pc_attack_direction_change;
+ int monster_attack_direction_change;
+ int pc_undead_nofreeze;
+ int pc_land_skill_limit;
+ int monster_land_skill_limit;
+ int party_skill_penaly;
+ int monster_class_change_full_recover;
+ int produce_item_name_input;
+ int produce_potion_name_input;
+ int making_arrow_name_input;
+ int holywater_name_input;
+ int display_delay_skill_fail;
+ int chat_warpportal;
+ int mob_warpportal;
+ int dead_branch_active;
+ int show_steal_in_same_party;
+ int enable_upper_class;
+ int mob_attack_attr_none;
+ int mob_ghostring_fix;
+ int pc_attack_attr_none;
- int prevent_logout; // Added by RoVeRT
+ int prevent_logout; // Added by RoVeRT
- int alchemist_summon_reward; // [Valaris]
- int maximum_level;
- int drops_by_luk;
- int monsters_ignore_gm;
- int equipment_breaking;
- int equipment_break_rate;
- int multi_level_up;
- int pk_mode;
- int show_mob_hp; // end additions [Valaris]
+ int alchemist_summon_reward; // [Valaris]
+ int maximum_level;
+ int drops_by_luk;
+ int monsters_ignore_gm;
+ int multi_level_up;
+ int pk_mode;
+ int show_mob_hp; // end additions [Valaris]
- int agi_penaly_count_lv;
- int vit_penaly_count_lv;
+ int agi_penaly_count_lv;
+ int vit_penaly_count_lv;
- int gx_allhit;
- int gx_cardfix;
- int gx_dupele;
- int gx_disptype;
- int player_skill_partner_check;
- int hide_GM_session;
- int unit_movement_type;
- int invite_request_check;
- int skill_removetrap_type;
- int disp_experience;
- int castle_defense_rate;
- int riding_weight;
- int backstab_bow_penalty;
+ int gx_allhit;
+ int gx_cardfix;
+ int gx_dupele;
+ int gx_disptype;
+ int player_skill_partner_check;
+ int hide_GM_session;
+ int unit_movement_type;
+ int invite_request_check;
+ int skill_removetrap_type;
+ int disp_experience;
+ int riding_weight;
+ int backstab_bow_penalty;
- int night_at_start; // added by [Yor]
- int day_duration; // added by [Yor]
- int night_duration; // added by [Yor]
- int hack_info_GM_level; // added by [Yor]
- int any_warp_GM_min_level; // added by [Yor]
- int packet_ver_flag; // added by [Yor]
- int muting_players; // added by [Apple]
+ int hack_info_GM_level; // added by [Yor]
+ int any_warp_GM_min_level; // added by [Yor]
+ int packet_ver_flag; // added by [Yor]
- int min_hair_style; // added by [MouseJstr]
- int max_hair_style; // added by [MouseJstr]
- int min_hair_color; // added by [MouseJstr]
- int max_hair_color; // added by [MouseJstr]
- int min_cloth_color; // added by [MouseJstr]
- int max_cloth_color; // added by [MouseJstr]
+ int min_hair_style; // added by [MouseJstr]
+ int max_hair_style; // added by [MouseJstr]
+ int min_hair_color; // added by [MouseJstr]
+ int max_hair_color; // added by [MouseJstr]
+ int min_cloth_color; // added by [MouseJstr]
+ int max_cloth_color; // added by [MouseJstr]
- int castrate_dex_scale; // added by [MouseJstr]
- int area_size; // added by [MouseJstr]
+ int castrate_dex_scale; // added by [MouseJstr]
+ int area_size; // added by [MouseJstr]
- int chat_lame_penalty;
- int chat_spam_threshold;
- int chat_spam_flood;
- int chat_spam_ban;
- int chat_spam_warn;
- int chat_maxline;
+ int chat_lame_penalty;
+ int chat_spam_threshold;
+ int chat_spam_flood;
+ int chat_spam_ban;
+ int chat_spam_warn;
+ int chat_maxline;
- int packet_spam_threshold;
- int packet_spam_flood;
- int packet_spam_kick;
+ int packet_spam_threshold;
+ int packet_spam_flood;
+ int packet_spam_kick;
- int mask_ip_gms;
+ int mask_ip_gms;
- int drop_pickup_safety_zone; // [Fate] Max. distance to an object dropped by a kill by self in which dropsteal protection works
- int itemheal_regeneration_factor; // [Fate] itemheal speed factor
+ int drop_pickup_safety_zone; // [Fate] Max. distance to an object dropped by a kill by self in which dropsteal protection works
+ int itemheal_regeneration_factor; // [Fate] itemheal speed factor
- int mob_splash_radius;
+ int mob_splash_radius;
} battle_config;
-int battle_config_read (const char *cfgName);
+int battle_config_read(const char *cfgName);
-#endif
+#endif // BATTLE_HPP
diff --git a/src/map/battle.t.hpp b/src/map/battle.t.hpp
new file mode 100644
index 0000000..e374298
--- /dev/null
+++ b/src/map/battle.t.hpp
@@ -0,0 +1,223 @@
+#ifndef BATTLE_T_HPP
+#define BATTLE_T_HPP
+
+#include "../common/utils2.hpp"
+
+namespace e
+{
+enum class BF : uint16_t
+{
+ ZERO = 0x0000,
+ NEGATIVE_1 = 0xffff,
+
+ WEAPON = 0x0001,
+ MAGIC = 0x0002,
+ MISC = 0x0004,
+ SHORT = 0x0010,
+ LONG = 0x0040,
+ SKILL = 0x0100,
+ NORMAL = 0x0200,
+ WEAPONMASK = 0x000f,
+ RANGEMASK = 0x00f0,
+ SKILLMASK = 0x0f00,
+};
+ENUM_BITWISE_OPERATORS(BF)
+}
+using e::BF;
+
+struct BCT
+{
+ // former representation:
+ uint8_t lo; // 0x 00 00 00 ff
+ uint8_t mid; // 0x 00 00 ff 00
+ uint8_t classic:4; // 0x 00 0f 00 00
+ uint8_t level:4; // 0x 00 f0 00 00
+ uint8_t unused; // 0x ff 00 00 00
+
+ explicit
+ operator bool() { return lo || mid || classic || level || unused; }
+};
+
+constexpr
+BCT operator & (BCT l, BCT r) { return {uint8_t(l.lo & r.lo), uint8_t(l.mid & r.mid), uint8_t(l.classic & r.classic), uint8_t(l.level & r.level), uint8_t(l.unused & r.unused) }; }
+constexpr
+BCT operator | (BCT l, BCT r) { return {uint8_t(l.lo | r.lo), uint8_t(l.mid | r.mid), uint8_t(l.classic | r.classic), uint8_t(l.level | r.level), uint8_t(l.unused | r.unused) }; }
+constexpr
+BCT operator ^ (BCT l, BCT r) { return {uint8_t(l.lo ^ r.lo), uint8_t(l.mid ^ r.mid), uint8_t(l.classic ^ r.classic), uint8_t(l.level ^ r.level), uint8_t(l.unused ^ r.unused) }; }
+inline
+BCT& operator &= (BCT& l, BCT r) { return l = l & r; }
+inline
+BCT& operator |= (BCT& l, BCT r) { return l = l & r; }
+inline
+BCT& operator ^= (BCT& l, BCT r) { return l = l & r; }
+// BCT operator ~(BCT r);
+
+constexpr
+bool operator == (BCT l, BCT r) { return l.lo == r.lo && l.mid == r.mid && l.classic == r.classic && l.level == r.level && l.unused == r.unused; }
+constexpr
+bool operator != (BCT l, BCT r) { return !(l == r); }
+
+constexpr
+BCT BCT_NOENEMY = {0x00, 0x00, 0x0, 0x0, 0x00};
+constexpr
+BCT BCT_ZERO = BCT_NOENEMY;
+constexpr
+BCT BCT_PARTY = {0x00, 0x00, 0x1, 0x0, 0x00};
+constexpr
+BCT BCT_ENEMY = {0x00, 0x00, 0x4, 0x0, 0x00};
+constexpr
+BCT BCT_NOPARTY = {0x00, 0x00, 0x5, 0x0, 0x00};
+constexpr
+BCT BCT_ALL = {0x00, 0x00, 0x2, 0x0, 0x00};
+constexpr
+BCT BCT_NOONE = {0x00, 0x00, 0x6, 0x0, 0x00};
+
+constexpr
+BCT BCT_lo_x01 = {0x01, 0x00, 0x0, 0x0, 0x00};
+constexpr
+BCT BCT_lo_x02 = {0x02, 0x00, 0x0, 0x0, 0x00};
+constexpr
+BCT BCT_mid_x05 = {0x00, 0x05, 0x0, 0x0, 0x00};
+constexpr
+BCT BCT_mid_x80 = {0x00, 0x80, 0x0, 0x0, 0x00};
+
+constexpr
+BCT BCT_highnib = {0x00, 0x00, 0x0, 0xf, 0x00};
+
+enum class Element : uint8_t
+{
+ neutral = 0,
+ water = 1,
+ earth = 2,
+ fire = 3,
+ wind = 4,
+ poison = 5,
+ _holy = 6,
+ dark = 7,
+ _spirit = 8,
+ undead = 9,
+
+ COUNT = 10,
+};
+
+enum class Race : uint8_t
+{
+ formless = 0,
+ undead = 1,
+ _brute = 2,
+ plant = 3,
+ _insect = 4,
+ _fish = 5,
+ _demon = 6,
+ demihuman = 7,
+ _angel = 8,
+ _dragon = 9,
+ // special - one of these is applied in addition
+ boss = 10,
+ other = 11,
+
+ COUNT = 12,
+};
+
+struct LevelElement
+{
+ uint8_t level;
+ Element element;
+
+ static
+ LevelElement unpack(int packed)
+ {
+ LevelElement le;
+ le.element = static_cast<Element>(packed % 10);
+ le.level = packed / 10;
+ return le;
+ }
+ int pack() const
+ {
+ return level * 10 + static_cast<uint8_t>(element);
+ }
+};
+
+namespace e
+{
+enum class Elements : uint16_t
+{
+ ZERO = 0x0000,
+ neutral = 1 << 0,
+ water = 1 << 1,
+ earth = 1 << 2,
+ fire = 1 << 3,
+ wind = 1 << 4,
+ poison = 1 << 5,
+ _holy = 1 << 6,
+ dark = 1 << 7,
+ _spirit = 1 << 8,
+ undead = 1 << 9,
+};
+ENUM_BITWISE_OPERATORS(Elements)
+
+enum class Races : uint16_t
+{
+ ZERO = 0x0000,
+ formless = 1 << 0,
+ undead = 1 << 1,
+ _brute = 1 << 2,
+ plant = 1 << 3,
+ _insect = 1 << 4,
+ _fish = 1 << 5,
+ _demon = 1 << 6,
+ demihuman = 1 << 7,
+ _angel = 1 << 8,
+ _dragon = 1 << 9,
+ // special - one of these is applied in addition
+ boss = 1 << 10,
+ other = 1 << 11,
+};
+ENUM_BITWISE_OPERATORS(Races)
+}
+using e::Elements;
+using e::Races;
+
+constexpr
+earray<Elements, Element, Element::COUNT> element_shift //=
+{{
+ Elements::neutral,
+ Elements::water,
+ Elements::earth,
+ Elements::fire,
+ Elements::wind,
+ Elements::poison,
+ Elements::_holy,
+ Elements::dark,
+ Elements::_spirit,
+ Elements::undead,
+}};
+
+constexpr
+earray<Races, Race, Race::COUNT> race_shift //=
+{{
+ Races::formless,
+ Races::undead,
+ Races::_brute,
+ Races::plant,
+ Races::_insect,
+ Races::_fish,
+ Races::_demon,
+ Races::demihuman,
+ Races::_angel,
+ Races::_dragon,
+ Races::boss,
+ Races::other,
+}};
+
+enum class DamageType : uint8_t
+{
+ NORMAL = 0x00,
+ TAKEITEM = 0x01,
+ RETURNED = 0x04,
+ DOUBLED = 0x08,
+ CRITICAL = 0x0a,
+ FLEE2 = 0x0b,
+};
+
+#endif // BATTLE_T_HPP
diff --git a/src/map/chat.cpp b/src/map/chat.cpp
index cb274f8..0d3bb95 100644
--- a/src/map/chat.cpp
+++ b/src/map/chat.cpp
@@ -1,117 +1,33 @@
-// $Id: chat.c,v 1.2 2004/09/22 02:59:47 Akitasha Exp $
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "../common/db.hpp"
-#include "../common/nullpo.hpp"
-#include "map.hpp"
-#include "clif.hpp"
-#include "pc.hpp"
#include "chat.hpp"
-#include "npc.hpp"
-
-#ifdef MEMWATCH
-#include "memwatch.hpp"
-#endif
-
-int chat_triggerevent (struct chat_data *cd);
-
-/*==========================================
- * ãƒãƒ£ãƒƒãƒˆãƒ«ãƒ¼ãƒ ä½œæˆ
- *------------------------------------------
- */
-int chat_createchat (struct map_session_data *sd, int limit, int pub,
- const char *pass, const char *title, int titlelen)
-{
- struct chat_data *cd;
-
- nullpo_retr (0, sd);
-
- CREATE(cd, struct chat_data, 1);
-
- cd->limit = limit;
- cd->pub = pub;
- cd->users = 1;
- memcpy (cd->pass, pass, 8);
- if (titlelen >= sizeof (cd->title) - 1)
- titlelen = sizeof (cd->title) - 1;
- memcpy (cd->title, title, titlelen);
- cd->title[titlelen] = 0;
-
- cd->owner = (struct block_list **) (&cd->usersd[0]);
- cd->usersd[0] = sd;
- cd->bl.m = sd->bl.m;
- cd->bl.x = sd->bl.x;
- cd->bl.y = sd->bl.y;
- cd->bl.type = BL_CHAT;
-
- cd->bl.id = map_addobject (&cd->bl);
- if (cd->bl.id == 0)
- {
- clif_createchat (sd, 1);
- free (cd);
- return 0;
- }
- pc_setchatid (sd, cd->bl.id);
-
- clif_createchat (sd, 0);
- clif_dispchat (cd, 0);
-
- return 0;
-}
-
-/*==========================================
- * 既存ãƒãƒ£ãƒƒãƒˆãƒ«ãƒ¼ãƒ ã«å‚加
- *------------------------------------------
- */
-int chat_joinchat (struct map_session_data *sd, int chatid, const char *pass)
-{
- struct chat_data *cd;
-
- nullpo_retr (0, sd);
-
- cd = (struct chat_data *) map_id2bl (chatid);
- if (cd == NULL)
- return 1;
- if (cd->bl.m != sd->bl.m || cd->limit <= cd->users)
- {
- clif_joinchatfail (sd, 0);
- return 0;
- }
- if (cd->pub == 0 && strncmp (pass, cd->pass, 8))
- {
- clif_joinchatfail (sd, 1);
- return 0;
- }
+#include <cstdlib>
+#include <cstring>
- cd->usersd[cd->users] = sd;
- cd->users++;
-
- pc_setchatid (sd, cd->bl.id);
+#include "../common/nullpo.hpp"
- clif_joinchatok (sd, cd); // æ–°ãŸã«å‚加ã—ãŸäººã«ã¯å…¨å“¡ã®ãƒªã‚¹ãƒˆ
- clif_addchat (cd, sd); // æ—¢ã«ä¸­ã«å±…ãŸäººã«ã¯è¿½åŠ ã—ãŸäººã®å ±å‘Š
- clif_dispchat (cd, 0); // 周囲ã®äººã«ã¯äººæ•°å¤‰åŒ–報告
+#include "map.hpp"
+#include "npc.hpp"
+#include "pc.hpp"
- chat_triggerevent (cd); // イベント
+#include "../poison.hpp"
- return 0;
-}
+static
+int chat_triggerevent(struct chat_data *cd);
+static
+int chat_npckickall(struct chat_data *cd);
/*==========================================
* ãƒãƒ£ãƒƒãƒˆãƒ«ãƒ¼ãƒ ã‹ã‚‰æŠœã‘ã‚‹
*------------------------------------------
*/
-int chat_leavechat (struct map_session_data *sd)
+int chat_leavechat(struct map_session_data *sd)
{
struct chat_data *cd;
- int i, leavechar;
+ int i, leavechar;
- nullpo_retr (1, sd);
+ nullpo_retr(1, sd);
- cd = (struct chat_data *) map_id2bl (sd->chatID);
+ cd = (struct chat_data *) map_id2bl(sd->chatID);
if (cd == NULL)
return 1;
@@ -126,144 +42,25 @@ int chat_leavechat (struct map_session_data *sd)
if (leavechar < 0) // ãã®chatã«æ‰€å±žã—ã¦ã„ãªã„らã—ã„ (ãƒã‚°æ™‚ã®ã¿)
return -1;
- if (leavechar == 0 && cd->users > 1 && (*cd->owner)->type == BL_PC)
- {
- // 所有者ã ã£ãŸ&ä»–ã«äººãŒå±…ã‚‹&PCã®ãƒãƒ£ãƒƒãƒˆ
- clif_changechatowner (cd, cd->usersd[1]);
- clif_clearchat (cd, 0);
- }
-
- // 抜ã‘ã‚‹PCã«ã‚‚é€ã‚‹ã®ã§usersを減らã™å‰ã«å®Ÿè¡Œ
- clif_leavechat (cd, sd);
-
cd->users--;
- pc_setchatid (sd, 0);
+ pc_setchatid(sd, 0);
- if (cd->users == 0 && (*cd->owner)->type == BL_PC)
+ if (cd->users == 0 && (*cd->owner)->type == BL::PC)
{
// 全員居ãªããªã£ãŸ&PCã®ãƒãƒ£ãƒƒãƒˆãªã®ã§æ¶ˆã™
- clif_clearchat (cd, 0);
- map_delobject (cd->bl.id, BL_CHAT); // freeã¾ã§ã—ã¦ãれる
+ map_delobject(cd->bl.id, BL::CHAT); // freeã¾ã§ã—ã¦ãれる
}
else
{
for (i = leavechar; i < cd->users; i++)
cd->usersd[i] = cd->usersd[i + 1];
- if (leavechar == 0 && (*cd->owner)->type == BL_PC)
+ if (leavechar == 0 && (*cd->owner)->type == BL::PC)
{
// PCã®ãƒãƒ£ãƒƒãƒˆãªã®ã§æ‰€æœ‰è€…ãŒæŠœã‘ãŸã®ã§ä½ç½®å¤‰æ›´
cd->bl.x = cd->usersd[0]->bl.x;
cd->bl.y = cd->usersd[0]->bl.y;
}
- clif_dispchat (cd, 0);
- }
-
- return 0;
-}
-
-/*==========================================
- * ãƒãƒ£ãƒƒãƒˆãƒ«ãƒ¼ãƒ ã®æŒã¡ä¸»ã‚’譲る
- *------------------------------------------
- */
-int chat_changechatowner (struct map_session_data *sd, const char *nextownername)
-{
- struct chat_data *cd;
- struct map_session_data *tmp_sd;
- int i, nextowner;
-
- nullpo_retr (1, sd);
-
- cd = (struct chat_data *) map_id2bl (sd->chatID);
- if (cd == NULL || (struct block_list *) sd != (*cd->owner))
- return 1;
-
- for (i = 1, nextowner = -1; i < cd->users; i++)
- {
- if (strcmp (cd->usersd[i]->status.name, nextownername) == 0)
- {
- nextowner = i;
- break;
- }
- }
- if (nextowner < 0) // ãã‚“ãªäººã¯å±…ãªã„
- return -1;
-
- clif_changechatowner (cd, cd->usersd[nextowner]);
- // 一旦消ã™
- clif_clearchat (cd, 0);
-
- // userlistã®é †ç•ªå¤‰æ›´ (0ãŒæ‰€æœ‰è€…ãªã®ã§)
- if ((tmp_sd = cd->usersd[0]) == NULL)
- return 1; //ã‚ã‚Šãˆã‚‹ã®ã‹ãªï¼Ÿ
- cd->usersd[0] = cd->usersd[nextowner];
- cd->usersd[nextowner] = tmp_sd;
-
- // æ–°ã—ã„所有者ã®ä½ç½®ã¸å¤‰æ›´
- cd->bl.x = cd->usersd[0]->bl.x;
- cd->bl.y = cd->usersd[0]->bl.y;
-
- // å†åº¦è¡¨ç¤º
- clif_dispchat (cd, 0);
-
- return 0;
-}
-
-/*==========================================
- * ãƒãƒ£ãƒƒãƒˆã®çŠ¶æ…‹(タイトル等)を変更
- *------------------------------------------
- */
-int chat_changechatstatus (struct map_session_data *sd, int limit, int pub,
- const char *pass, const char *title, int titlelen)
-{
- struct chat_data *cd;
-
- nullpo_retr (1, sd);
-
- cd = (struct chat_data *) map_id2bl (sd->chatID);
- if (cd == NULL || (struct block_list *) sd != (*cd->owner))
- return 1;
-
- cd->limit = limit;
- cd->pub = pub;
- memcpy (cd->pass, pass, 8);
- if (titlelen >= sizeof (cd->title) - 1)
- titlelen = sizeof (cd->title) - 1;
- memcpy (cd->title, title, titlelen);
- cd->title[titlelen] = 0;
-
- clif_changechatstatus (cd);
- clif_dispchat (cd, 0);
-
- return 0;
-}
-
-/*==========================================
- * ãƒãƒ£ãƒƒãƒˆãƒ«ãƒ¼ãƒ ã‹ã‚‰è¹´ã‚Šå‡ºã™
- *------------------------------------------
- */
-int chat_kickchat (struct map_session_data *sd, const char *kickusername)
-{
- struct chat_data *cd;
- int i, kickuser;
-
- nullpo_retr (1, sd);
-
- cd = (struct chat_data *) map_id2bl (sd->chatID);
- if (cd == NULL || (struct block_list *) sd != (*cd->owner))
- return 1;
-
- for (i = 0, kickuser = -1; i < cd->users; i++)
- {
- if (strcmp (cd->usersd[i]->status.name, kickusername) == 0)
- {
- kickuser = i;
- break;
- }
}
- if (kickuser < 0) // ãã‚“ãªäººã¯å±…ãªã„
- return -1;
-
- chat_leavechat (cd->usersd[kickuser]);
return 0;
}
@@ -272,44 +69,42 @@ int chat_kickchat (struct map_session_data *sd, const char *kickusername)
* npcãƒãƒ£ãƒƒãƒˆãƒ«ãƒ¼ãƒ ä½œæˆ
*------------------------------------------
*/
-int chat_createnpcchat (struct npc_data *nd, int limit, int pub, int trigger,
+int chat_createnpcchat(struct npc_data *nd, int limit, int pub, int trigger,
const char *title, int titlelen, const char *ev)
{
struct chat_data *cd;
- nullpo_retr (1, nd);
+ nullpo_retr(1, nd);
- CREATE (cd, struct chat_data, 1);
+ CREATE(cd, struct chat_data, 1);
cd->limit = cd->trigger = limit;
if (trigger > 0)
cd->trigger = trigger;
cd->pub = pub;
cd->users = 0;
- memcpy (cd->pass, "", 8);
- if (titlelen >= sizeof (cd->title) - 1)
- titlelen = sizeof (cd->title) - 1;
- memcpy (cd->title, title, titlelen);
+ memcpy(cd->pass, "", 8);
+ if (titlelen >= sizeof(cd->title) - 1)
+ titlelen = sizeof(cd->title) - 1;
+ memcpy(cd->title, title, titlelen);
cd->title[titlelen] = 0;
cd->bl.m = nd->bl.m;
cd->bl.x = nd->bl.x;
cd->bl.y = nd->bl.y;
- cd->bl.type = BL_CHAT;
+ cd->bl.type = BL::CHAT;
cd->owner_ = (struct block_list *) nd;
cd->owner = &cd->owner_;
- memcpy (cd->npc_event, ev, sizeof (cd->npc_event));
+ memcpy(cd->npc_event, ev, sizeof(cd->npc_event));
- cd->bl.id = map_addobject (&cd->bl);
+ cd->bl.id = map_addobject(&cd->bl);
if (cd->bl.id == 0)
{
- free (cd);
+ free(cd);
return 0;
}
nd->chat_id = cd->bl.id;
- clif_dispchat (cd, 0);
-
return 0;
}
@@ -317,16 +112,16 @@ int chat_createnpcchat (struct npc_data *nd, int limit, int pub, int trigger,
* npcãƒãƒ£ãƒƒãƒˆãƒ«ãƒ¼ãƒ å‰Šé™¤
*------------------------------------------
*/
-int chat_deletenpcchat (struct npc_data *nd)
+int chat_deletenpcchat(struct npc_data *nd)
{
struct chat_data *cd;
- nullpo_retr (0, nd);
- nullpo_retr (0, cd = (struct chat_data *) map_id2bl (nd->chat_id));
+ nullpo_ret(nd);
+ cd = (struct chat_data *) map_id2bl(nd->chat_id);
+ nullpo_ret(cd);
- chat_npckickall (cd);
- clif_clearchat (cd, 0);
- map_delobject (cd->bl.id, BL_CHAT); // freeã¾ã§ã—ã¦ãれる
+ chat_npckickall(cd);
+ map_delobject(cd->bl.id, BL::CHAT); // freeã¾ã§ã—ã¦ãれる
nd->chat_id = 0;
return 0;
@@ -336,12 +131,12 @@ int chat_deletenpcchat (struct npc_data *nd)
* è¦å®šäººæ•°ä»¥ä¸Šã§ã‚¤ãƒ™ãƒ³ãƒˆãŒå®šç¾©ã•ã‚Œã¦ã‚‹ãªã‚‰å®Ÿè¡Œ
*------------------------------------------
*/
-int chat_triggerevent (struct chat_data *cd)
+int chat_triggerevent(struct chat_data *cd)
{
- nullpo_retr (0, cd);
+ nullpo_ret(cd);
if (cd->users >= cd->trigger && cd->npc_event[0])
- npc_event_do (cd->npc_event);
+ npc_event_do(cd->npc_event);
return 0;
}
@@ -349,12 +144,12 @@ int chat_triggerevent (struct chat_data *cd)
* イベントã®æœ‰åŠ¹åŒ–
*------------------------------------------
*/
-int chat_enableevent (struct chat_data *cd)
+int chat_enableevent(struct chat_data *cd)
{
- nullpo_retr (0, cd);
+ nullpo_ret(cd);
cd->trigger &= 0x7f;
- chat_triggerevent (cd);
+ chat_triggerevent(cd);
return 0;
}
@@ -362,9 +157,9 @@ int chat_enableevent (struct chat_data *cd)
* イベントã®ç„¡åŠ¹åŒ–
*------------------------------------------
*/
-int chat_disableevent (struct chat_data *cd)
+int chat_disableevent(struct chat_data *cd)
{
- nullpo_retr (0, cd);
+ nullpo_ret(cd);
cd->trigger |= 0x80;
return 0;
@@ -374,22 +169,13 @@ int chat_disableevent (struct chat_data *cd)
* ãƒãƒ£ãƒƒãƒˆãƒ«ãƒ¼ãƒ ã‹ã‚‰å…¨å“¡è¹´ã‚Šå‡ºã™
*------------------------------------------
*/
-int chat_npckickall (struct chat_data *cd)
+int chat_npckickall(struct chat_data *cd)
{
- nullpo_retr (0, cd);
+ nullpo_ret(cd);
while (cd->users > 0)
{
- chat_leavechat (cd->usersd[cd->users - 1]);
+ chat_leavechat(cd->usersd[cd->users - 1]);
}
return 0;
}
-
-/*==========================================
- * 終了
- *------------------------------------------
- */
-int do_final_chat (void)
-{
- return 0;
-}
diff --git a/src/map/chat.hpp b/src/map/chat.hpp
index fca9217..ead7b49 100644
--- a/src/map/chat.hpp
+++ b/src/map/chat.hpp
@@ -1,25 +1,12 @@
-// $Id: chat.h,v 1.3 2004/09/25 05:32:18 MouseJstr Exp $
#ifndef CHAT_HPP
#define CHAT_HPP
-#include "map.hpp"
+int chat_leavechat(struct map_session_data *);
-int chat_createchat (struct map_session_data *, int, int, const char *, const char *,
- int);
-int chat_joinchat (struct map_session_data *, int, const char *);
-int chat_leavechat (struct map_session_data *);
-int chat_changechatowner (struct map_session_data *, const char *);
-int chat_changechatstatus (struct map_session_data *, int, int, const char *,
- const char *, int);
-int chat_kickchat (struct map_session_data *, const char *);
+int chat_createnpcchat(struct npc_data *nd, int limit, int pub, int trigger,
+ const char *title, int titlelen, const char *ev);
+int chat_deletenpcchat(struct npc_data *nd);
+int chat_enableevent(struct chat_data *cd);
+int chat_disableevent(struct chat_data *cd);
-int chat_createnpcchat (struct npc_data *nd, int limit, int pub, int trigger,
- const char *title, int titlelen, const char *ev);
-int chat_deletenpcchat (struct npc_data *nd);
-int chat_enableevent (struct chat_data *cd);
-int chat_disableevent (struct chat_data *cd);
-int chat_npckickall (struct chat_data *cd);
-
-int do_final_chat (void);
-
-#endif
+#endif // CHAT_HPP
diff --git a/src/map/chrif.cpp b/src/map/chrif.cpp
index 24d5d26..6742f88 100644
--- a/src/map/chrif.cpp
+++ b/src/map/chrif.cpp
@@ -1,71 +1,66 @@
-// $Id: chrif.c,v 1.6 2004/09/25 11:39:17 MouseJstr Exp $
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#ifdef LCCWIN32
-#include <winsock.h>
-#else
-#include <unistd.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
+#include "chrif.hpp"
+
#include <arpa/inet.h>
-#endif
-#include <sys/types.h>
-#include <time.h>
+#include <cstring>
+
+#include "../common/cxxstdio.hpp"
+#include "../common/nullpo.hpp"
#include "../common/socket.hpp"
#include "../common/timer.hpp"
-#include "map.hpp"
+#include "../common/utils.hpp"
+
#include "battle.hpp"
-#include "chrif.hpp"
#include "clif.hpp"
#include "intif.hpp"
+#include "itemdb.hpp"
+#include "map.hpp"
#include "npc.hpp"
#include "pc.hpp"
-#include "../common/nullpo.hpp"
-#include "itemdb.hpp"
+#include "storage.hpp"
-#ifdef MEMWATCH
-#include "memwatch.hpp"
-#endif
+#include "../poison.hpp"
-static const int packet_len_table[0x20] = {
+static
+const int packet_len_table[0x20] = {
60, 3, 10, 27, 22, -1, 6, -1, // 2af8-2aff
6, -1, 18, 7, -1, 49, 44, 0, // 2b00-2b07
6, 30, -1, 10, 86, 7, 44, 34, // 2b08-2b0f
-1, -1, 10, 6, 11, -1, 0, 0, // 2b10-2b17
};
-int char_fd;
-int srvinfo;
-static char char_ip_str[16];
-static int char_ip;
-static int char_port = 6121;
-static char userid[24], passwd[24];
-static int chrif_state;
+int char_fd;
+static
+char char_ip_str[16];
+static
+int char_ip;
+static
+int char_port = 6121;
+static
+char userid[24], passwd[24];
+static
+int chrif_state;
// 設定ファイル読ã¿è¾¼ã¿é–¢ä¿‚
/*==========================================
*
*------------------------------------------
*/
-void chrif_setuserid (char *id)
+void chrif_setuserid(const char *id)
{
- strncpy (userid, id, sizeof(userid)-1);
- userid[sizeof(userid)-1] = '\0';
+ strzcpy(userid, id, sizeof(userid));
}
/*==========================================
*
*------------------------------------------
*/
-void chrif_setpasswd (char *pwd)
+void chrif_setpasswd(const char *pwd)
{
- strncpy (passwd, pwd, sizeof(passwd)-1);
- passwd[sizeof(passwd)-1] = '\0';
+ strzcpy(passwd, pwd, sizeof(passwd));
}
-char *chrif_getpasswd (void)
+char *chrif_getpasswd(void)
{
return passwd;
}
@@ -74,18 +69,17 @@ char *chrif_getpasswd (void)
*
*------------------------------------------
*/
-void chrif_setip (char *ip)
+void chrif_setip(const char *ip)
{
- strncpy (char_ip_str, ip, sizeof(char_ip_str)-1);
- char_ip_str[sizeof(char_ip_str)-1] = '\0';
- char_ip = inet_addr (char_ip_str);
+ strzcpy(char_ip_str, ip, sizeof(char_ip_str));
+ char_ip = inet_addr(char_ip_str);
}
/*==========================================
*
*------------------------------------------
*/
-void chrif_setport (int port)
+void chrif_setport(int port)
{
char_port = port;
}
@@ -94,7 +88,7 @@ void chrif_setport (int port)
*
*------------------------------------------
*/
-int chrif_isconnect (void)
+int chrif_isconnect(void)
{
return chrif_state == 2;
}
@@ -103,28 +97,25 @@ int chrif_isconnect (void)
*
*------------------------------------------
*/
-int chrif_save (struct map_session_data *sd)
+int chrif_save(struct map_session_data *sd)
{
- nullpo_retr (-1, sd);
+ nullpo_retr(-1, sd);
if (char_fd < 0)
return -1;
- pc_makesavestatus (sd);
+ pc_makesavestatus(sd);
- WFIFOW (char_fd, 0) = 0x2b01;
- WFIFOW (char_fd, 2) = sizeof (sd->status) + 12;
- WFIFOL (char_fd, 4) = sd->bl.id;
- WFIFOL (char_fd, 8) = sd->char_id;
- memcpy (WFIFOP (char_fd, 12), &sd->status, sizeof (sd->status));
- WFIFOSET (char_fd, WFIFOW (char_fd, 2));
+ WFIFOW(char_fd, 0) = 0x2b01;
+ WFIFOW(char_fd, 2) = sizeof(sd->status) + 12;
+ WFIFOL(char_fd, 4) = sd->bl.id;
+ WFIFOL(char_fd, 8) = sd->char_id;
+ memcpy(WFIFOP(char_fd, 12), &sd->status, sizeof(sd->status));
+ WFIFOSET(char_fd, WFIFOW(char_fd, 2));
//For data sync
- if (sd->state.storage_flag == 1)
- storage_storage_save (sd->status.account_id, 0);
- else if (sd->state.storage_flag == 2)
- storage_guild_storagesave (sd->status.account_id, sd->status.guild_id,
- 0);
+ if (sd->state.storage_open)
+ storage_storage_save(sd->status.account_id, 0);
return 0;
}
@@ -134,15 +125,15 @@ int chrif_save (struct map_session_data *sd)
*------------------------------------------
*/
static
-int chrif_connect (int fd)
+int chrif_connect(int fd)
{
- WFIFOW (fd, 0) = 0x2af8;
- memcpy (WFIFOP (fd, 2), userid, 24);
- memcpy (WFIFOP (fd, 26), passwd, 24);
- WFIFOL (fd, 50) = 0;
- WFIFOL (fd, 54) = clif_getip ().s_addr;
- WFIFOW (fd, 58) = clif_getport (); // [Valaris] thanks to fov
- WFIFOSET (fd, 60);
+ WFIFOW(fd, 0) = 0x2af8;
+ memcpy(WFIFOP(fd, 2), userid, 24);
+ memcpy(WFIFOP(fd, 26), passwd, 24);
+ WFIFOL(fd, 50) = 0;
+ WFIFOL(fd, 54) = clif_getip().s_addr;
+ WFIFOW(fd, 58) = clif_getport(); // [Valaris] thanks to fov
+ WFIFOSET(fd, 60);
return 0;
}
@@ -152,18 +143,18 @@ int chrif_connect (int fd)
*------------------------------------------
*/
static
-int chrif_sendmap (int fd)
+int chrif_sendmap(int fd)
{
- int i;
+ int i;
- WFIFOW (fd, 0) = 0x2afa;
+ WFIFOW(fd, 0) = 0x2afa;
for (i = 0; i < map_num; i++)
if (map[i].alias[0] != '\0') // [MouseJstr] map aliasing
- memcpy (WFIFOP (fd, 4 + i * 16), map[i].alias, 16);
+ memcpy(WFIFOP(fd, 4 + i * 16), map[i].alias, 16);
else
- memcpy (WFIFOP (fd, 4 + i * 16), map[i].name, 16);
- WFIFOW (fd, 2) = 4 + i * 16;
- WFIFOSET (fd, WFIFOW (fd, 2));
+ memcpy(WFIFOP(fd, 4 + i * 16), map[i].name, 16);
+ WFIFOW(fd, 2) = 4 + i * 16;
+ WFIFOSET(fd, WFIFOW(fd, 2));
return 0;
}
@@ -173,24 +164,24 @@ int chrif_sendmap (int fd)
*------------------------------------------
*/
static
-int chrif_recvmap (int fd)
+int chrif_recvmap(int fd)
{
- int i, j, port;
+ int i, j, port;
if (chrif_state < 2) // ã¾ã æº–備中
return -1;
struct in_addr ip;
- ip.s_addr = RFIFOL (fd, 4);
- port = RFIFOW (fd, 8);
- for (i = 10, j = 0; i < RFIFOW (fd, 2); i += 16, j++)
+ ip.s_addr = RFIFOL(fd, 4);
+ port = RFIFOW(fd, 8);
+ for (i = 10, j = 0; i < RFIFOW(fd, 2); i += 16, j++)
{
- map_setipport ((const char *)RFIFOP (fd, i), ip, port);
+ map_setipport((const char *)RFIFOP(fd, i), ip, port);
// if (battle_config.etc_log)
-// printf("recv map %d %s\n", j, RFIFOP(fd,i));
+// PRINTF("recv map %d %s\n", j, RFIFOP(fd,i));
}
if (battle_config.etc_log)
- printf ("recv map on %s:%d (%d maps)\n", ip2str(ip), port, j);
+ PRINTF("recv map on %s:%d (%d maps)\n", ip2str(ip), port, j);
return 0;
}
@@ -199,12 +190,12 @@ int chrif_recvmap (int fd)
* マップ鯖間移動ã®ãŸã‚ã®ãƒ‡ãƒ¼ã‚¿æº–å‚™è¦æ±‚
*------------------------------------------
*/
-int chrif_changemapserver (struct map_session_data *sd, char *name, int x,
+int chrif_changemapserver(struct map_session_data *sd, char *name, int x,
int y, struct in_addr ip, short port)
{
- int i, s_ip;
+ int i, s_ip;
- nullpo_retr (-1, sd);
+ nullpo_retr(-1, sd);
s_ip = 0;
for (i = 0; i < fd_max; i++)
@@ -214,19 +205,19 @@ int chrif_changemapserver (struct map_session_data *sd, char *name, int x,
break;
}
- WFIFOW (char_fd, 0) = 0x2b05;
- WFIFOL (char_fd, 2) = sd->bl.id;
- WFIFOL (char_fd, 6) = sd->login_id1;
- WFIFOL (char_fd, 10) = sd->login_id2;
- WFIFOL (char_fd, 14) = sd->status.char_id;
- memcpy (WFIFOP (char_fd, 18), name, 16);
- WFIFOW (char_fd, 34) = x;
- WFIFOW (char_fd, 36) = y;
- WFIFOL (char_fd, 38) = ip.s_addr;
- WFIFOL (char_fd, 42) = port;
- WFIFOB (char_fd, 44) = sd->status.sex;
- WFIFOL (char_fd, 45) = s_ip;
- WFIFOSET (char_fd, 49);
+ WFIFOW(char_fd, 0) = 0x2b05;
+ WFIFOL(char_fd, 2) = sd->bl.id;
+ WFIFOL(char_fd, 6) = sd->login_id1;
+ WFIFOL(char_fd, 10) = sd->login_id2;
+ WFIFOL(char_fd, 14) = sd->status.char_id;
+ memcpy(WFIFOP(char_fd, 18), name, 16);
+ WFIFOW(char_fd, 34) = x;
+ WFIFOW(char_fd, 36) = y;
+ WFIFOL(char_fd, 38) = ip.s_addr;
+ WFIFOL(char_fd, 42) = port;
+ WFIFOB(char_fd, 44) = sd->status.sex;
+ WFIFOL(char_fd, 45) = s_ip;
+ WFIFOSET(char_fd, 49);
return 0;
}
@@ -236,22 +227,22 @@ int chrif_changemapserver (struct map_session_data *sd, char *name, int x,
*------------------------------------------
*/
static
-int chrif_changemapserverack (int fd)
+int chrif_changemapserverack(int fd)
{
- struct map_session_data *sd = map_id2sd (RFIFOL (fd, 2));
+ struct map_session_data *sd = map_id2sd(RFIFOL(fd, 2));
- if (sd == NULL || sd->status.char_id != RFIFOL (fd, 14))
+ if (sd == NULL || sd->status.char_id != RFIFOL(fd, 14))
return -1;
- if (RFIFOL (fd, 6) == 1)
+ if (RFIFOL(fd, 6) == 1)
{
if (battle_config.error_log)
- printf ("map server change failed.\n");
- pc_authfail (sd->fd);
+ PRINTF("map server change failed.\n");
+ pc_authfail(sd->fd);
return 0;
}
- clif_changemapserver (sd, (const char *)RFIFOP (fd, 18), RFIFOW (fd, 34),
- RFIFOW (fd, 36), in_addr{RFIFOL (fd, 38)}, RFIFOW (fd, 42));
+ clif_changemapserver(sd, (const char *)RFIFOP(fd, 18), RFIFOW(fd, 34),
+ RFIFOW(fd, 36), in_addr{RFIFOL(fd, 38)}, RFIFOW(fd, 42));
return 0;
}
@@ -261,25 +252,25 @@ int chrif_changemapserverack (int fd)
*------------------------------------------
*/
static
-int chrif_connectack (int fd)
+int chrif_connectack(int fd)
{
- if (RFIFOB (fd, 2))
+ if (RFIFOB(fd, 2))
{
- printf ("Connected to char-server failed %d.\n", RFIFOB (fd, 2));
- exit (1);
+ PRINTF("Connected to char-server failed %d.\n", RFIFOB(fd, 2));
+ exit(1);
}
- printf ("Connected to char-server (connection #%d).\n", fd);
+ PRINTF("Connected to char-server (connection #%d).\n", fd);
chrif_state = 1;
- chrif_sendmap (fd);
+ chrif_sendmap(fd);
- printf ("chrif: OnCharIfInit event done. (%d events)\n",
- npc_event_doall ("OnCharIfInit"));
- printf ("chrif: OnInterIfInit event done. (%d events)\n",
- npc_event_doall ("OnInterIfInit"));
+ PRINTF("chrif: OnCharIfInit event done. (%d events)\n",
+ npc_event_doall("OnCharIfInit"));
+ PRINTF("chrif: OnInterIfInit event done. (%d events)\n",
+ npc_event_doall("OnInterIfInit"));
// <Agit> Run Event [AgitInit]
-// printf("NPC_Event:[OnAgitInit] do (%d) events (Agit Initialize).\n", npc_event_doall("OnAgitInit"));
+// PRINTF("NPC_Event:[OnAgitInit] do (%d) events (Agit Initialize).\n", npc_event_doall("OnAgitInit"));
return 0;
}
@@ -289,16 +280,16 @@ int chrif_connectack (int fd)
*------------------------------------------
*/
static
-int chrif_sendmapack (int fd)
+int chrif_sendmapack(int fd)
{
- if (RFIFOB (fd, 2))
+ if (RFIFOB(fd, 2))
{
- printf ("chrif : send map list to char server failed %d\n",
- RFIFOB (fd, 2));
- exit (1);
+ PRINTF("chrif : send map list to char server failed %d\n",
+ RFIFOB(fd, 2));
+ exit(1);
}
- memcpy (wisp_server_name, RFIFOP (fd, 3), 24);
+ memcpy(wisp_server_name, RFIFOP(fd, 3), 24);
chrif_state = 2;
@@ -309,11 +300,11 @@ int chrif_sendmapack (int fd)
*
*------------------------------------------
*/
-int chrif_authreq (struct map_session_data *sd)
+int chrif_authreq(struct map_session_data *sd)
{
- int i;
+ int i;
- nullpo_retr (-1, sd);
+ nullpo_retr(-1, sd);
if (!sd || !char_fd || !sd->bl.id || !sd->login_id1)
return -1;
@@ -321,13 +312,13 @@ int chrif_authreq (struct map_session_data *sd)
for (i = 0; i < fd_max; i++)
if (session[i] && session[i]->session_data == sd)
{
- WFIFOW (char_fd, 0) = 0x2afc;
- WFIFOL (char_fd, 2) = sd->bl.id;
- WFIFOL (char_fd, 6) = sd->char_id;
- WFIFOL (char_fd, 10) = sd->login_id1;
- WFIFOL (char_fd, 14) = sd->login_id2;
- WFIFOL (char_fd, 18) = session[i]->client_addr.sin_addr.s_addr;
- WFIFOSET (char_fd, 22);
+ WFIFOW(char_fd, 0) = 0x2afc;
+ WFIFOL(char_fd, 2) = sd->bl.id;
+ WFIFOL(char_fd, 6) = sd->char_id;
+ WFIFOL(char_fd, 10) = sd->login_id1;
+ WFIFOL(char_fd, 14) = sd->login_id2;
+ WFIFOL(char_fd, 18) = session[i]->client_addr.sin_addr.s_addr;
+ WFIFOSET(char_fd, 22);
break;
}
@@ -338,11 +329,11 @@ int chrif_authreq (struct map_session_data *sd)
*
*------------------------------------------
*/
-int chrif_charselectreq (struct map_session_data *sd)
+int chrif_charselectreq(struct map_session_data *sd)
{
- int i, s_ip;
+ int i, s_ip;
- nullpo_retr (-1, sd);
+ nullpo_retr(-1, sd);
if (!sd || !char_fd || !sd->bl.id || !sd->login_id1)
return -1;
@@ -355,12 +346,12 @@ int chrif_charselectreq (struct map_session_data *sd)
break;
}
- WFIFOW (char_fd, 0) = 0x2b02;
- WFIFOL (char_fd, 2) = sd->bl.id;
- WFIFOL (char_fd, 6) = sd->login_id1;
- WFIFOL (char_fd, 10) = sd->login_id2;
- WFIFOL (char_fd, 14) = s_ip;
- WFIFOSET (char_fd, 18);
+ WFIFOW(char_fd, 0) = 0x2b02;
+ WFIFOL(char_fd, 2) = sd->bl.id;
+ WFIFOL(char_fd, 6) = sd->login_id1;
+ WFIFOL(char_fd, 10) = sd->login_id2;
+ WFIFOL(char_fd, 14) = s_ip;
+ WFIFOSET(char_fd, 18);
return 0;
}
@@ -369,14 +360,14 @@ int chrif_charselectreq (struct map_session_data *sd)
* キャラåå•ã„åˆã‚ã›
*------------------------------------------
*/
-int chrif_searchcharid (int char_id)
+int chrif_searchcharid(int char_id)
{
if (!char_id)
return -1;
- WFIFOW (char_fd, 0) = 0x2b08;
- WFIFOL (char_fd, 2) = char_id;
- WFIFOSET (char_fd, 6);
+ WFIFOW(char_fd, 0) = 0x2b08;
+ WFIFOL(char_fd, 2) = char_id;
+ WFIFOSET(char_fd, 6);
return 0;
}
@@ -385,16 +376,16 @@ int chrif_searchcharid (int char_id)
* GMã«å¤‰åŒ–è¦æ±‚
*------------------------------------------
*/
-int chrif_changegm (int id, const char *pass, int len)
+int chrif_changegm(int id, const char *pass, int len)
{
if (battle_config.etc_log)
- printf ("chrif_changegm: account: %d, password: '%s'.\n", id, pass);
+ PRINTF("chrif_changegm: account: %d, password: '%s'.\n", id, pass);
- WFIFOW (char_fd, 0) = 0x2b0a;
- WFIFOW (char_fd, 2) = len + 8;
- WFIFOL (char_fd, 4) = id;
- memcpy (WFIFOP (char_fd, 8), pass, len);
- WFIFOSET (char_fd, len + 8);
+ WFIFOW(char_fd, 0) = 0x2b0a;
+ WFIFOW(char_fd, 2) = len + 8;
+ WFIFOL(char_fd, 4) = id;
+ memcpy(WFIFOP(char_fd, 8), pass, len);
+ WFIFOSET(char_fd, len + 8);
return 0;
}
@@ -403,19 +394,18 @@ int chrif_changegm (int id, const char *pass, int len)
* Change Email
*------------------------------------------
*/
-int chrif_changeemail (int id, const char *actual_email,
+int chrif_changeemail(int id, const char *actual_email,
const char *new_email)
{
if (battle_config.etc_log)
- printf
- ("chrif_changeemail: account: %d, actual_email: '%s', new_email: '%s'.\n",
+ PRINTF("chrif_changeemail: account: %d, actual_email: '%s', new_email: '%s'.\n",
id, actual_email, new_email);
- WFIFOW (char_fd, 0) = 0x2b0c;
- WFIFOL (char_fd, 2) = id;
- memcpy (WFIFOP (char_fd, 6), actual_email, 40);
- memcpy (WFIFOP (char_fd, 46), new_email, 40);
- WFIFOSET (char_fd, 86);
+ WFIFOW(char_fd, 0) = 0x2b0c;
+ WFIFOL(char_fd, 2) = id;
+ memcpy(WFIFOP(char_fd, 6), actual_email, 40);
+ memcpy(WFIFOP(char_fd, 46), new_email, 40);
+ WFIFOSET(char_fd, 86);
return 0;
}
@@ -431,25 +421,25 @@ int chrif_changeemail (int id, const char *actual_email,
* 5: changesex
*------------------------------------------
*/
-int chrif_char_ask_name (int id, char *character_name, short operation_type,
+int chrif_char_ask_name(int id, char *character_name, short operation_type,
int year, int month, int day, int hour, int minute,
int second)
{
- WFIFOW (char_fd, 0) = 0x2b0e;
- WFIFOL (char_fd, 2) = id; // account_id of who ask (for answer) -1 if nobody
- memcpy (WFIFOP (char_fd, 6), character_name, 24);
- WFIFOW (char_fd, 30) = operation_type; // type of operation
+ WFIFOW(char_fd, 0) = 0x2b0e;
+ WFIFOL(char_fd, 2) = id; // account_id of who ask (for answer) -1 if nobody
+ memcpy(WFIFOP(char_fd, 6), character_name, 24);
+ WFIFOW(char_fd, 30) = operation_type; // type of operation
if (operation_type == 2)
{
- WFIFOW (char_fd, 32) = year;
- WFIFOW (char_fd, 34) = month;
- WFIFOW (char_fd, 36) = day;
- WFIFOW (char_fd, 38) = hour;
- WFIFOW (char_fd, 40) = minute;
- WFIFOW (char_fd, 42) = second;
+ WFIFOW(char_fd, 32) = year;
+ WFIFOW(char_fd, 34) = month;
+ WFIFOW(char_fd, 36) = day;
+ WFIFOW(char_fd, 38) = hour;
+ WFIFOW(char_fd, 40) = minute;
+ WFIFOW(char_fd, 42) = second;
}
- printf ("chrif : sended 0x2b0e\n");
- WFIFOSET (char_fd, 44);
+ PRINTF("chrif : sended 0x2b0e\n");
+ WFIFOSET(char_fd, 44);
return 0;
}
@@ -471,169 +461,167 @@ int chrif_char_ask_name (int id, char *character_name, short operation_type,
*------------------------------------------
*/
static
-int chrif_char_ask_name_answer (int fd)
+int chrif_char_ask_name_answer(int fd)
{
- int acc;
+ int acc;
struct map_session_data *sd;
- char output[256];
char player_name[24];
- acc = RFIFOL (fd, 2); // account_id of who has asked (-1 if nobody)
- memcpy (player_name, RFIFOP (fd, 6), sizeof (player_name));
- player_name[sizeof (player_name) - 1] = '\0';
+ acc = RFIFOL(fd, 2); // account_id of who has asked (-1 if nobody)
+ memcpy(player_name, RFIFOP(fd, 6), sizeof(player_name));
+ player_name[sizeof(player_name) - 1] = '\0';
- sd = map_id2sd (acc);
+ sd = map_id2sd(acc);
if (acc >= 0 && sd != NULL)
{
- if (RFIFOW (fd, 32) == 1) // player not found
- sprintf (output, "The player '%s' doesn't exist.", player_name);
+ std::string output;
+ if (RFIFOW(fd, 32) == 1) // player not found
+ output = STRPRINTF("The player '%s' doesn't exist.",
+ player_name);
else
{
- switch (RFIFOW (fd, 30))
+ switch (RFIFOW(fd, 30))
{
case 1: // block
- switch (RFIFOW (fd, 32))
+ switch (RFIFOW(fd, 32))
{
case 0: // login-server resquest done
- sprintf (output,
- "Login-server has been asked to block the player '%s'.",
- player_name);
+ output = STRPRINTF(
+ "Login-server has been asked to block the player '%s'.",
+ player_name);
break;
//case 1: // player not found
case 2: // gm level too low
- sprintf (output,
- "Your GM level don't authorise you to block the player '%s'.",
- player_name);
+ output = STRPRINTF(
+ "Your GM level don't authorise you to block the player '%s'.",
+ player_name);
break;
case 3: // login-server offline
- sprintf (output,
- "Login-server is offline. Impossible to block the the player '%s'.",
- player_name);
+ output = STRPRINTF(
+ "Login-server is offline. Impossible to block the the player '%s'.",
+ player_name);
break;
}
break;
case 2: // ban
- switch (RFIFOW (fd, 32))
+ switch (RFIFOW(fd, 32))
{
case 0: // login-server resquest done
- sprintf (output,
- "Login-server has been asked to ban the player '%s'.",
- player_name);
+ output = STRPRINTF(
+ "Login-server has been asked to ban the player '%s'.",
+ player_name);
break;
//case 1: // player not found
case 2: // gm level too low
- sprintf (output,
- "Your GM level don't authorise you to ban the player '%s'.",
- player_name);
+ output = STRPRINTF(
+ "Your GM level don't authorise you to ban the player '%s'.",
+ player_name);
break;
case 3: // login-server offline
- sprintf (output,
- "Login-server is offline. Impossible to ban the the player '%s'.",
- player_name);
+ output = STRPRINTF(
+ "Login-server is offline. Impossible to ban the the player '%s'.",
+ player_name);
break;
}
break;
case 3: // unblock
- switch (RFIFOW (fd, 32))
+ switch (RFIFOW(fd, 32))
{
case 0: // login-server resquest done
- sprintf (output,
- "Login-server has been asked to unblock the player '%s'.",
- player_name);
+ output = STRPRINTF(
+ "Login-server has been asked to unblock the player '%s'.",
+ player_name);
break;
//case 1: // player not found
case 2: // gm level too low
- sprintf (output,
- "Your GM level don't authorise you to unblock the player '%s'.",
- player_name);
+ output = STRPRINTF(
+ "Your GM level don't authorise you to unblock the player '%s'.",
+ player_name);
break;
case 3: // login-server offline
- sprintf (output,
- "Login-server is offline. Impossible to unblock the the player '%s'.",
- player_name);
+ output = STRPRINTF(
+ "Login-server is offline. Impossible to unblock the the player '%s'.",
+ player_name);
break;
}
break;
case 4: // unban
- switch (RFIFOW (fd, 32))
+ switch (RFIFOW(fd, 32))
{
case 0: // login-server resquest done
- sprintf (output,
- "Login-server has been asked to unban the player '%s'.",
- player_name);
+ output = STRPRINTF(
+ "Login-server has been asked to unban the player '%s'.",
+ player_name);
break;
//case 1: // player not found
case 2: // gm level too low
- sprintf (output,
- "Your GM level don't authorise you to unban the player '%s'.",
- player_name);
+ output = STRPRINTF(
+ "Your GM level don't authorise you to unban the player '%s'.",
+ player_name);
break;
case 3: // login-server offline
- sprintf (output,
- "Login-server is offline. Impossible to unban the the player '%s'.",
- player_name);
+ output = STRPRINTF(
+ "Login-server is offline. Impossible to unban the the player '%s'.",
+ player_name);
break;
}
break;
case 5: // changesex
- switch (RFIFOW (fd, 32))
+ switch (RFIFOW(fd, 32))
{
case 0: // login-server resquest done
- sprintf (output,
- "Login-server has been asked to change the sex of the player '%s'.",
- player_name);
+ output = STRPRINTF(
+ "Login-server has been asked to change the sex of the player '%s'.",
+ player_name);
break;
//case 1: // player not found
case 2: // gm level too low
- sprintf (output,
- "Your GM level don't authorise you to change the sex of the player '%s'.",
- player_name);
+ output = STRPRINTF(
+ "Your GM level don't authorise you to change the sex of the player '%s'.",
+ player_name);
break;
case 3: // login-server offline
- sprintf (output,
- "Login-server is offline. Impossible to change the sex of the the player '%s'.",
- player_name);
+ output = STRPRINTF(
+ "Login-server is offline. Impossible to change the sex of the the player '%s'.",
+ player_name);
break;
}
break;
}
}
- if (output[0] != '\0')
- {
- output[sizeof (output) - 1] = '\0';
- clif_displaymessage (sd->fd, output);
- }
+ if (!output.empty())
+ clif_displaymessage(sd->fd, output);
}
else
- printf ("chrif_char_ask_name_answer failed - player not online.\n");
+ PRINTF("chrif_char_ask_name_answer failed - player not online.\n");
return 0;
}
/*==========================================
- * End of GM change (@GM) (modified by Yor)
+ * End of GM change(@GM) (modified by Yor)
*------------------------------------------
*/
static
-int chrif_changedgm (int fd)
+int chrif_changedgm(int fd)
{
- int acc, level;
+ int acc, level;
struct map_session_data *sd = NULL;
- acc = RFIFOL (fd, 2);
- level = RFIFOL (fd, 6);
+ acc = RFIFOL(fd, 2);
+ level = RFIFOL(fd, 6);
- sd = map_id2sd (acc);
+ sd = map_id2sd(acc);
if (battle_config.etc_log)
- printf ("chrif_changedgm: account: %d, GM level 0 -> %d.\n", acc,
+ PRINTF("chrif_changedgm: account: %d, GM level 0 -> %d.\n", acc,
level);
if (sd != NULL)
{
if (level > 0)
- clif_displaymessage (sd->fd, "GM modification success.");
+ clif_displaymessage(sd->fd, "GM modification success.");
else
- clif_displaymessage (sd->fd, "Failure of GM modification.");
+ clif_displaymessage(sd->fd, "Failure of GM modification.");
}
return 0;
@@ -644,68 +632,42 @@ int chrif_changedgm (int fd)
*------------------------------------------
*/
static
-int chrif_changedsex (int fd)
+int chrif_changedsex(int fd)
{
- int acc, sex, i;
+ int acc, sex, i;
struct map_session_data *sd;
- struct pc_base_job s_class;
- acc = RFIFOL (fd, 2);
- sex = RFIFOL (fd, 6);
+ acc = RFIFOL(fd, 2);
+ sex = RFIFOL(fd, 6);
if (battle_config.etc_log)
- printf ("chrif_changedsex %d.\n", acc);
- sd = map_id2sd (acc);
+ PRINTF("chrif_changedsex %d.\n", acc);
+ sd = map_id2sd(acc);
if (acc > 0)
{
if (sd != NULL && sd->status.sex != sex)
{
- s_class = pc_calc_base_job (sd->status.pc_class);
- if (sd->status.sex == 0)
- {
- sd->status.sex = 1;
- sd->sex = 1;
- }
- else if (sd->status.sex == 1)
- {
- sd->status.sex = 0;
- sd->sex = 0;
- }
+ sd->sex = sd->status.sex = !sd->status.sex;
// to avoid any problem with equipment and invalid sex, equipment is unequiped.
for (i = 0; i < MAX_INVENTORY; i++)
{
if (sd->status.inventory[i].nameid
- && sd->status.inventory[i].equip)
- pc_unequipitem ((struct map_session_data *) sd, i, 0);
- }
- // reset skill of some job
- if (s_class.job == 19 || s_class.job == 4020
- || s_class.job == 4042 || s_class.job == 20
- || s_class.job == 4021 || s_class.job == 4043)
- {
-
- clif_updatestatus (sd, SP_SKILLPOINT);
- // change job if necessary
- if (s_class.job == 20 || s_class.job == 4021
- || s_class.job == 4043)
- sd->status.pc_class -= 1;
- else if (s_class.job == 19 || s_class.job == 4020
- || s_class.job == 4042)
- sd->status.pc_class += 1;
+ && bool(sd->status.inventory[i].equip))
+ pc_unequipitem(sd, i, CalcStatus::NOW);
}
// save character
- chrif_save (sd);
+ chrif_save(sd);
sd->login_id1++; // change identify, because if player come back in char within the 5 seconds, he can change its characters
// do same modify in login-server for the account, but no in char-server (it ask again login_id1 to login, and don't remember it)
- clif_displaymessage (sd->fd,
+ clif_displaymessage(sd->fd,
"Your sex has been changed (need disconexion by the server)...");
- clif_setwaitclose (sd->fd); // forced to disconnect for the change
+ clif_setwaitclose(sd->fd); // forced to disconnect for the change
}
}
else
{
if (sd != NULL)
{
- printf ("chrif_changedsex failed.\n");
+ PRINTF("chrif_changedsex failed.\n");
}
}
@@ -716,10 +678,10 @@ int chrif_changedsex (int fd)
* アカウント変数ä¿å­˜è¦æ±‚
*------------------------------------------
*/
-int chrif_saveaccountreg2 (struct map_session_data *sd)
+int chrif_saveaccountreg2(struct map_session_data *sd)
{
- int p, j;
- nullpo_retr (-1, sd);
+ int p, j;
+ nullpo_retr(-1, sd);
p = 8;
for (j = 0; j < sd->status.account_reg2_num; j++)
@@ -727,15 +689,15 @@ int chrif_saveaccountreg2 (struct map_session_data *sd)
struct global_reg *reg = &sd->status.account_reg2[j];
if (reg->str[0] && reg->value != 0)
{
- memcpy (WFIFOP (char_fd, p), reg->str, 32);
- WFIFOL (char_fd, p + 32) = reg->value;
+ memcpy(WFIFOP(char_fd, p), reg->str, 32);
+ WFIFOL(char_fd, p + 32) = reg->value;
p += 36;
}
}
- WFIFOW (char_fd, 0) = 0x2b10;
- WFIFOW (char_fd, 2) = p;
- WFIFOL (char_fd, 4) = sd->bl.id;
- WFIFOSET (char_fd, p);
+ WFIFOW(char_fd, 0) = 0x2b10;
+ WFIFOW(char_fd, 2) = p;
+ WFIFOL(char_fd, 4) = sd->bl.id;
+ WFIFOSET(char_fd, p);
return 0;
}
@@ -745,22 +707,22 @@ int chrif_saveaccountreg2 (struct map_session_data *sd)
*------------------------------------------
*/
static
-int chrif_accountreg2 (int fd)
+int chrif_accountreg2(int fd)
{
- int j, p;
+ int j, p;
struct map_session_data *sd;
- if ((sd = map_id2sd (RFIFOL (fd, 4))) == NULL)
+ if ((sd = map_id2sd(RFIFOL(fd, 4))) == NULL)
return 1;
- for (p = 8, j = 0; p < RFIFOW (fd, 2) && j < ACCOUNT_REG2_NUM;
+ for (p = 8, j = 0; p < RFIFOW(fd, 2) && j < ACCOUNT_REG2_NUM;
p += 36, j++)
{
- memcpy (sd->status.account_reg2[j].str, RFIFOP (fd, p), 32);
- sd->status.account_reg2[j].value = RFIFOL (fd, p + 32);
+ memcpy(sd->status.account_reg2[j].str, RFIFOP(fd, p), 32);
+ sd->status.account_reg2[j].value = RFIFOL(fd, p + 32);
}
sd->status.account_reg2_num = j;
-// printf("chrif: accountreg2\n");
+// PRINTF("chrif: accountreg2\n");
return 0;
}
@@ -772,14 +734,14 @@ int chrif_accountreg2 (int fd)
*------------------------------------------
*/
static
-int chrif_divorce (int char_id, int partner_id)
+int chrif_divorce(int char_id, int partner_id)
{
struct map_session_data *sd = NULL;
if (!char_id || !partner_id)
return 0;
- sd = map_nick2sd (map_charid2nick (char_id));
+ sd = map_nick2sd(map_charid2nick(char_id));
if (sd && sd->status.partner_id == partner_id)
{
sd->status.partner_id = 0;
@@ -787,11 +749,12 @@ int chrif_divorce (int char_id, int partner_id)
if (sd->npc_flags.divorce)
{
sd->npc_flags.divorce = 0;
- map_scriptcont (sd, sd->npc_id);
+ map_scriptcont(sd, sd->npc_id);
}
}
- nullpo_retr (0, sd = map_nick2sd (map_charid2nick (partner_id)));
+ sd = map_nick2sd(map_charid2nick(partner_id));
+ nullpo_ret(sd);
if (sd->status.partner_id == char_id)
sd->status.partner_id = 0;
@@ -803,14 +766,14 @@ int chrif_divorce (int char_id, int partner_id)
* Needed to divorce when partner is not connected to map server
*-------------------------------------
*/
-int chrif_send_divorce (int char_id)
+int chrif_send_divorce(int char_id)
{
if (char_fd < 0)
return -1;
- WFIFOW (char_fd, 0) = 0x2b16;
- WFIFOL (char_fd, 2) = char_id;
- WFIFOSET (char_fd, 6);
+ WFIFOW(char_fd, 0) = 0x2b16;
+ WFIFOL(char_fd, 2) = char_id;
+ WFIFOSET(char_fd, 6);
return 0;
}
@@ -819,29 +782,29 @@ int chrif_send_divorce (int char_id)
*------------------------------------------
*/
static
-int chrif_accountdeletion (int fd)
+int chrif_accountdeletion(int fd)
{
- int acc;
+ int acc;
struct map_session_data *sd;
- acc = RFIFOL (fd, 2);
+ acc = RFIFOL(fd, 2);
if (battle_config.etc_log)
- printf ("chrif_accountdeletion %d.\n", acc);
- sd = map_id2sd (acc);
+ PRINTF("chrif_accountdeletion %d.\n", acc);
+ sd = map_id2sd(acc);
if (acc > 0)
{
if (sd != NULL)
{
sd->login_id1++; // change identify, because if player come back in char within the 5 seconds, he can change its characters
- clif_displaymessage (sd->fd,
+ clif_displaymessage(sd->fd,
"Your account has been deleted (disconnection)...");
- clif_setwaitclose (sd->fd); // forced to disconnect for the change
+ clif_setwaitclose(sd->fd); // forced to disconnect for the change
}
}
else
{
if (sd != NULL)
- printf ("chrif_accountdeletion failed - player not online.\n");
+ PRINTF("chrif_accountdeletion failed - player not online.\n");
}
return 0;
@@ -852,87 +815,85 @@ int chrif_accountdeletion (int fd)
*------------------------------------------
*/
static
-int chrif_accountban (int fd)
+int chrif_accountban(int fd)
{
- int acc;
+ int acc;
struct map_session_data *sd;
- acc = RFIFOL (fd, 2);
+ acc = RFIFOL(fd, 2);
if (battle_config.etc_log)
- printf ("chrif_accountban %d.\n", acc);
- sd = map_id2sd (acc);
+ PRINTF("chrif_accountban %d.\n", acc);
+ sd = map_id2sd(acc);
if (acc > 0)
{
if (sd != NULL)
{
sd->login_id1++; // change identify, because if player come back in char within the 5 seconds, he can change its characters
- if (RFIFOB (fd, 6) == 0)
+ if (RFIFOB(fd, 6) == 0)
{ // 0: change of statut, 1: ban
- switch (RFIFOL (fd, 7))
+ switch (RFIFOL(fd, 7))
{ // status or final date of a banishment
case 1: // 0 = Unregistered ID
- clif_displaymessage (sd->fd,
+ clif_displaymessage(sd->fd,
"Your account has 'Unregistered'.");
break;
case 2: // 1 = Incorrect Password
- clif_displaymessage (sd->fd,
+ clif_displaymessage(sd->fd,
"Your account has an 'Incorrect Password'...");
break;
case 3: // 2 = This ID is expired
- clif_displaymessage (sd->fd,
+ clif_displaymessage(sd->fd,
"Your account has expired.");
break;
case 4: // 3 = Rejected from Server
- clif_displaymessage (sd->fd,
+ clif_displaymessage(sd->fd,
"Your account has been rejected from server.");
break;
case 5: // 4 = You have been blocked by the GM Team
- clif_displaymessage (sd->fd,
+ clif_displaymessage(sd->fd,
"Your account has been blocked by the GM Team.");
break;
case 6: // 5 = Your Game's EXE file is not the latest version
- clif_displaymessage (sd->fd,
+ clif_displaymessage(sd->fd,
"Your Game's EXE file is not the latest version.");
break;
case 7: // 6 = Your are Prohibited to log in until %s
- clif_displaymessage (sd->fd,
+ clif_displaymessage(sd->fd,
"Your account has been prohibited to log in.");
break;
case 8: // 7 = Server is jammed due to over populated
- clif_displaymessage (sd->fd,
+ clif_displaymessage(sd->fd,
"Server is jammed due to over populated.");
break;
case 9: // 8 = No MSG (actually, all states after 9 except 99 are No MSG, use only this)
- clif_displaymessage (sd->fd,
+ clif_displaymessage(sd->fd,
"Your account has not more authorised.");
break;
case 100: // 99 = This ID has been totally erased
- clif_displaymessage (sd->fd,
+ clif_displaymessage(sd->fd,
"Your account has been totally erased.");
break;
default:
- clif_displaymessage (sd->fd,
+ clif_displaymessage(sd->fd,
"Your account has not more authorised.");
break;
}
}
- else if (RFIFOB (fd, 6) == 1)
- { // 0: change of statut, 1: ban
- time_t timestamp;
- char tmpstr[2048];
- timestamp = (time_t) RFIFOL (fd, 7); // status or final date of a banishment
- strcpy (tmpstr, "Your account has been banished until ");
- strftime (tmpstr + strlen (tmpstr), 24, "%d-%m-%Y %H:%M:%S",
- gmtime (&timestamp));
- clif_displaymessage (sd->fd, tmpstr);
+ else if (RFIFOB(fd, 6) == 1)
+ {
+ // 0: change of statut, 1: ban
+ TimeT timestamp = static_cast<time_t>(RFIFOL(fd, 7)); // status or final date of a banishment
+ char tmpstr[] = WITH_TIMESTAMP("Your account has been banished until ");
+ REPLACE_TIMESTAMP(tmpstr, timestamp);
+ clif_displaymessage(sd->fd, tmpstr);
}
- clif_setwaitclose (sd->fd); // forced to disconnect for the change
+ clif_setwaitclose(sd->fd); // forced to disconnect for the change
}
}
else
{
if (sd != NULL)
- printf ("chrif_accountban failed - player not online.\n");
+ PRINTF("chrif_accountban failed - player not online.\n");
}
return 0;
@@ -943,10 +904,10 @@ int chrif_accountban (int fd)
*------------------------------------------
*/
static
-int chrif_recvgmaccounts (int fd)
+int chrif_recvgmaccounts(int fd)
{
- printf ("From login-server: receiving of %d GM accounts information.\n",
- pc_read_gm_account (fd));
+ PRINTF("From login-server: receiving of %d GM accounts information.\n",
+ pc_read_gm_account(fd));
return 0;
}
@@ -955,70 +916,11 @@ int chrif_recvgmaccounts (int fd)
* Request to reload GM accounts and their levels: send to char-server by [Yor]
*------------------------------------------
*/
-int chrif_reloadGMdb (void)
-{
-
- WFIFOW (char_fd, 0) = 0x2af7;
- WFIFOSET (char_fd, 2);
-
- return 0;
-}
-
-/*==========================================
- * Send rates and motd to char server [Wizputer]
- *------------------------------------------
- */
-int chrif_ragsrvinfo (int base_rate, int job_rate, int drop_rate)
+int chrif_reloadGMdb(void)
{
- char buf[256];
- FILE *fp;
- int i;
-
- WFIFOW (char_fd, 0) = 0x2b16;
- WFIFOW (char_fd, 2) = base_rate;
- WFIFOW (char_fd, 4) = job_rate;
- WFIFOW (char_fd, 6) = drop_rate;
- if ((fp = fopen_ (motd_txt, "r")) != NULL)
- {
- if (fgets (buf, 250, fp) != NULL)
- {
- for (i = 0; buf[i]; i++)
- {
- if (buf[i] == '\r' || buf[i] == '\n')
- {
- buf[i] = 0;
- break;
- }
- }
- WFIFOW (char_fd, 8) = sizeof (buf) + 10;
- memcpy (WFIFOP (char_fd, 10), buf, sizeof (buf));
- }
- fclose_ (fp);
- }
- else
- {
- WFIFOW (char_fd, 8) = sizeof (buf) + 10;
- memcpy (WFIFOP (char_fd, 10), buf, sizeof (buf));
- }
- WFIFOSET (char_fd, WFIFOW (char_fd, 8));
-
- return 0;
-}
-
-/*=========================================
- * Tell char-server charcter disconnected [Wizputer]
- *-----------------------------------------
- */
-
-int chrif_char_offline (struct map_session_data *sd)
-{
- if (char_fd < 0)
- return -1;
-
- WFIFOW (char_fd, 0) = 0x2b17;
- WFIFOL (char_fd, 2) = sd->status.char_id;
- WFIFOSET (char_fd, 6);
+ WFIFOW(char_fd, 0) = 0x2af7;
+ WFIFOSET(char_fd, 2);
return 0;
}
@@ -1028,45 +930,46 @@ int chrif_char_offline (struct map_session_data *sd)
*----------------------------------------
*/
-static void ladmin_itemfrob_fix_item (int source, int dest, struct item *item)
+static
+void ladmin_itemfrob_fix_item(int source, int dest, struct item *item)
{
if (item && item->nameid == source)
{
item->nameid = dest;
- item->equip = 0;
+ item->equip = EPOS::ZERO;
}
}
-static int ladmin_itemfrob_c2 (struct block_list *bl, int source_id,
- int dest_id)
+static
+void ladmin_itemfrob_c2(struct block_list *bl, int source_id, int dest_id)
{
#define IFIX(v) if (v == source_id) {v = dest_id; }
#define FIX(item) ladmin_itemfrob_fix_item(source_id, dest_id, &item)
if (!bl)
- return 0;
+ return;
switch (bl->type)
{
- case BL_PC:
+ case BL::PC:
{
struct map_session_data *pc = (struct map_session_data *) bl;
- struct storage *stor = account2storage2 (pc->status.account_id);
- int j;
+ struct storage *stor = account2storage2(pc->status.account_id);
+ int j;
for (j = 0; j < MAX_INVENTORY; j++)
- IFIX (pc->status.inventory[j].nameid);
+ IFIX(pc->status.inventory[j].nameid);
for (j = 0; j < MAX_CART; j++)
- IFIX (pc->status.cart[j].nameid);
- IFIX (pc->status.weapon);
- IFIX (pc->status.shield);
- IFIX (pc->status.head_top);
- IFIX (pc->status.head_mid);
- IFIX (pc->status.head_bottom);
+ IFIX(pc->status.cart[j].nameid);
+ // IFIX(pc->status.weapon);
+ IFIX(pc->status.shield);
+ IFIX(pc->status.head_top);
+ IFIX(pc->status.head_mid);
+ IFIX(pc->status.head_bottom);
if (stor)
for (j = 0; j < stor->storage_amount; j++)
- FIX (stor->storage_[j]);
+ FIX(stor->storage_[j]);
for (j = 0; j < MAX_INVENTORY; j++)
{
@@ -1074,8 +977,8 @@ static int ladmin_itemfrob_c2 (struct block_list *bl, int source_id,
if (item && item->nameid == source_id)
{
item->nameid = dest_id;
- if (item->equip)
- pc_unequipitem (pc, j, 0);
+ if (bool(item->equip))
+ pc_unequipitem(pc, j, CalcStatus::NOW);
item->nameid = dest_id;
}
}
@@ -1083,51 +986,46 @@ static int ladmin_itemfrob_c2 (struct block_list *bl, int source_id,
break;
}
- case BL_MOB:
+ case BL::MOB:
{
struct mob_data *mob = (struct mob_data *) bl;
- int i;
+ int i;
for (i = 0; i < mob->lootitem_count; i++)
- FIX (mob->lootitem[i]);
+ FIX(mob->lootitem[i]);
break;
}
- case BL_ITEM:
+ case BL::ITEM:
{
struct flooritem_data *item = (struct flooritem_data *) bl;
- FIX (item->item_data);
+ FIX(item->item_data);
break;
}
}
#undef FIX
#undef IFIX
-
- return 0;
}
static
-int ladmin_itemfrob_c (struct block_list *bl, va_list va_args)
+void ladmin_itemfrob_c(struct block_list *bl, int source_id, int dest_id)
{
- int source_id = va_arg (va_args, int);
- int dest_id = va_arg (va_args, int);
- return ladmin_itemfrob_c2 (bl, source_id, dest_id);
+ ladmin_itemfrob_c2(bl, source_id, dest_id);
}
static
-void ladmin_itemfrob (int fd)
+void ladmin_itemfrob(int fd)
{
- int source_id = RFIFOL (fd, 2);
- int dest_id = RFIFOL (fd, 6);
- struct block_list *bl = (struct block_list *) map_get_first_session ();
+ int source_id = RFIFOL(fd, 2);
+ int dest_id = RFIFOL(fd, 6);
+ struct block_list *bl = (struct block_list *) map_get_first_session();
// flooritems
- map_foreachobject (ladmin_itemfrob_c, 0 /* any object */ , source_id,
- dest_id);
+ map_foreachobject(std::bind(ladmin_itemfrob_c, ph::_1, source_id, dest_id), BL::NUL /* any object */);
// player characters (and, hopefully, mobs)
while (bl->next)
{
- ladmin_itemfrob_c2 (bl, source_id, dest_id);
+ ladmin_itemfrob_c2(bl, source_id, dest_id);
bl = bl->next;
}
}
@@ -1137,9 +1035,9 @@ void ladmin_itemfrob (int fd)
*------------------------------------------
*/
static
-void chrif_parse (int fd)
+void chrif_parse(int fd)
{
- int packet_len, cmd;
+ int packet_len, cmd;
// only char-server can have an access to here.
// so, if it isn't the char-server, we disconnect the session (fd != char_fd).
@@ -1147,27 +1045,25 @@ void chrif_parse (int fd)
{
if (fd == char_fd)
{
- printf
- ("Map-server can't connect to char-server (connection #%d).\n",
+ PRINTF("Map-server can't connect to char-server (connection #%d).\n",
fd);
char_fd = -1;
}
- close (fd);
- delete_session (fd);
+ delete_session(fd);
return;
}
- while (RFIFOREST (fd) >= 2)
+ while (RFIFOREST(fd) >= 2)
{
- cmd = RFIFOW (fd, 0);
+ cmd = RFIFOW(fd, 0);
if (cmd < 0x2af8
|| cmd >=
0x2af8 +
- (sizeof (packet_len_table) / sizeof (packet_len_table[0]))
+ (sizeof(packet_len_table) / sizeof(packet_len_table[0]))
|| packet_len_table[cmd - 0x2af8] == 0)
{
- int r = intif_parse (fd); // intifã«æ¸¡ã™
+ int r = intif_parse(fd); // intifã«æ¸¡ã™
if (r == 1)
continue; // intifã§å‡¦ç†ã—ãŸ
@@ -1180,80 +1076,80 @@ void chrif_parse (int fd)
packet_len = packet_len_table[cmd - 0x2af8];
if (packet_len == -1)
{
- if (RFIFOREST (fd) < 4)
+ if (RFIFOREST(fd) < 4)
return;
- packet_len = RFIFOW (fd, 2);
+ packet_len = RFIFOW(fd, 2);
}
- if (RFIFOREST (fd) < packet_len)
+ if (RFIFOREST(fd) < packet_len)
return;
switch (cmd)
{
case 0x2af9:
- chrif_connectack (fd);
+ chrif_connectack(fd);
break;
case 0x2afa:
- ladmin_itemfrob (fd);
+ ladmin_itemfrob(fd);
break;
case 0x2afb:
- chrif_sendmapack (fd);
+ chrif_sendmapack(fd);
break;
case 0x2afd:
- pc_authok (RFIFOL (fd, 4), RFIFOL (fd, 8),
- (time_t) RFIFOL (fd, 12), RFIFOW (fd, 16),
- (struct mmo_charstatus *) RFIFOP (fd, 18));
+ pc_authok(RFIFOL(fd, 4), RFIFOL(fd, 8),
+ static_cast<time_t>(RFIFOL(fd, 12)), RFIFOW(fd, 16),
+ (const struct mmo_charstatus *) RFIFOP(fd, 18));
break;
case 0x2afe:
- pc_authfail (RFIFOL (fd, 2));
+ pc_authfail(RFIFOL(fd, 2));
break;
case 0x2b00:
- map_setusers (RFIFOL (fd, 2));
+ map_setusers(RFIFOL(fd, 2));
break;
case 0x2b03:
- clif_charselectok (RFIFOL (fd, 2));
+ clif_charselectok(RFIFOL(fd, 2));
break;
case 0x2b04:
- chrif_recvmap (fd);
+ chrif_recvmap(fd);
break;
case 0x2b06:
- chrif_changemapserverack (fd);
+ chrif_changemapserverack(fd);
break;
case 0x2b09:
- map_addchariddb (RFIFOL (fd, 2), (const char *)RFIFOP (fd, 6));
+ map_addchariddb(RFIFOL(fd, 2), (const char *)RFIFOP(fd, 6));
break;
case 0x2b0b:
- chrif_changedgm (fd);
+ chrif_changedgm(fd);
break;
case 0x2b0d:
- chrif_changedsex (fd);
+ chrif_changedsex(fd);
break;
case 0x2b0f:
- chrif_char_ask_name_answer (fd);
+ chrif_char_ask_name_answer(fd);
break;
case 0x2b11:
- chrif_accountreg2 (fd);
+ chrif_accountreg2(fd);
break;
case 0x2b12:
- chrif_divorce (RFIFOL (fd, 2), RFIFOL (fd, 6));
+ chrif_divorce(RFIFOL(fd, 2), RFIFOL(fd, 6));
break;
case 0x2b13:
- chrif_accountdeletion (fd);
+ chrif_accountdeletion(fd);
break;
case 0x2b14:
- chrif_accountban (fd);
+ chrif_accountban(fd);
break;
case 0x2b15:
- chrif_recvgmaccounts (fd);
+ chrif_recvgmaccounts(fd);
break;
default:
if (battle_config.error_log)
- printf ("chrif_parse : unknown packet %d %d\n", fd,
- RFIFOW (fd, 0));
+ PRINTF("chrif_parse : unknown packet %d %d\n", fd,
+ RFIFOW(fd, 0));
session[fd]->eof = 1;
return;
}
- RFIFOSKIP (fd, packet_len);
+ RFIFOSKIP(fd, packet_len);
}
}
@@ -1263,29 +1159,29 @@ void chrif_parse (int fd)
*------------------------------------------
*/
static
-void send_users_tochar (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data)
+void send_users_tochar(TimerData *, tick_t)
{
- int users = 0, i;
+ int users = 0, i;
struct map_session_data *sd;
if (char_fd <= 0 || session[char_fd] == NULL)
return;
- WFIFOW (char_fd, 0) = 0x2aff;
+ WFIFOW(char_fd, 0) = 0x2aff;
for (i = 0; i < fd_max; i++)
{
if (session[i] && (sd = (struct map_session_data *)session[i]->session_data) && sd->state.auth &&
!((battle_config.hide_GM_session
|| sd->state.shroud_active
- || (sd->status.option & OPTION_HIDE)) && pc_isGM (sd)))
+ || bool(sd->status.option & Option::HIDE)) && pc_isGM(sd)))
{
- WFIFOL (char_fd, 6 + 4 * users) = sd->status.char_id;
+ WFIFOL(char_fd, 6 + 4 * users) = sd->status.char_id;
users++;
}
}
- WFIFOW (char_fd, 2) = 6 + 4 * users;
- WFIFOW (char_fd, 4) = users;
- WFIFOSET (char_fd, 6 + 4 * users);
+ WFIFOW(char_fd, 2) = 6 + 4 * users;
+ WFIFOW(char_fd, 4) = users;
+ WFIFOSET(char_fd, 6 + 4 * users);
}
/*==========================================
@@ -1294,18 +1190,18 @@ void send_users_tochar (timer_id tid, tick_t tick, custom_id_t id, custom_data_t
*------------------------------------------
*/
static
-void check_connect_char_server (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data)
+void check_connect_char_server(TimerData *, tick_t)
{
if (char_fd <= 0 || session[char_fd] == NULL)
{
- printf ("Attempt to connect to char-server...\n");
+ PRINTF("Attempt to connect to char-server...\n");
chrif_state = 0;
- if ((char_fd = make_connection (char_ip, char_port)) < 0)
+ if ((char_fd = make_connection(char_ip, char_port)) < 0)
return;
session[char_fd]->func_parse = chrif_parse;
- realloc_fifo (char_fd, FIFOSIZE_SERVERLINK, FIFOSIZE_SERVERLINK);
+ realloc_fifo(char_fd, FIFOSIZE_SERVERLINK, FIFOSIZE_SERVERLINK);
- chrif_connect (char_fd);
+ chrif_connect(char_fd);
}
}
@@ -1315,11 +1211,14 @@ void check_connect_char_server (timer_id tid, tick_t tick, custom_id_t id, custo
*/
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_interval (gettick () + 1000, check_connect_char_server, 0, 0,
- 10 * 1000);
- add_timer_interval (gettick () + 1000, send_users_tochar, 0, 0, 5 * 1000);
+ Timer(gettick() + std::chrono::seconds(1),
+ check_connect_char_server,
+ std::chrono::seconds(10)
+ ).detach();
+ Timer(gettick() + std::chrono::seconds(1),
+ send_users_tochar,
+ std::chrono::seconds(5)
+ ).detach();
return 0;
}
diff --git a/src/map/chrif.hpp b/src/map/chrif.hpp
index 82bfe0d..2816e9f 100644
--- a/src/map/chrif.hpp
+++ b/src/map/chrif.hpp
@@ -1,36 +1,36 @@
-// $Id: chrif.h,v 1.3 2004/09/25 11:39:17 MouseJstr Exp $
#ifndef CHRIF_HPP
#define CHRIF_HPP
-void chrif_setuserid (char *);
-void chrif_setpasswd (char *);
-char *chrif_getpasswd (void);
+void chrif_setuserid(const char *);
+void chrif_setpasswd(const char *);
+char *chrif_getpasswd(void);
-void chrif_setip (char *);
-void chrif_setport (int);
+void chrif_setip(const char *);
+void chrif_setport(int);
-int chrif_isconnect (void);
+int chrif_isconnect(void);
-int chrif_authreq (struct map_session_data *);
-int chrif_save (struct map_session_data *);
-int chrif_charselectreq (struct map_session_data *);
+int chrif_authreq(struct map_session_data *);
+int chrif_save(struct map_session_data *);
+int chrif_charselectreq(struct map_session_data *);
-int chrif_changemapserver (struct map_session_data *sd, char *name, int x,
- int y, struct in_addr ip, short port);
+int chrif_changemapserver(struct map_session_data *sd,
+ char *name, int x, int y,
+ struct in_addr ip, short port);
-int chrif_searchcharid (int char_id);
-int chrif_changegm (int id, const char *pass, int len);
-int chrif_changeemail (int id, const char *actual_email,
- const char *new_email);
-int chrif_char_ask_name (int id, char *character_name, short operation_type,
- int year, int month, int day, int hour, int minute,
- int second);
-int chrif_saveaccountreg2 (struct map_session_data *sd);
-int chrif_reloadGMdb (void);
-int chrif_ragsrvinfo (int base_rate, int job_rate, int drop_rate);
-int chrif_char_offline (struct map_session_data *sd);
-int chrif_send_divorce (int char_id);
+int chrif_searchcharid(int char_id);
+int chrif_changegm(int id, const char *pass, int len);
+int chrif_changeemail(int id, const char *actual_email,
+ const char *new_email);
+int chrif_char_ask_name(int id, char *character_name, short operation_type,
+ int year, int month, int day, int hour, int minute, int second);
+int chrif_saveaccountreg2(struct map_session_data *sd);
+int chrif_reloadGMdb(void);
+int chrif_send_divorce(int char_id);
-int do_init_chrif (void);
+int do_init_chrif (void);
-#endif
+// only used by intif.cpp
+extern int char_fd;
+
+#endif // CHRIF_HPP
diff --git a/src/map/clif.cpp b/src/map/clif.cpp
index fd22160..1deb1f3 100644
--- a/src/map/clif.cpp
+++ b/src/map/clif.cpp
@@ -1,105 +1,66 @@
-// $Id: clif.c 164 2004-10-01 16:46:58Z $
-
-#define DUMP_UNKNOWN_PACKET 1
-
-#include <stdio.h>
-#include <ctype.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdarg.h>
-#include <sys/types.h>
-#ifdef LCCWIN32
-#include <winsock.h>
-#else
-#include <unistd.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
+#include "clif.hpp"
+
#include <arpa/inet.h>
-#endif
-#include <time.h>
+#include <cstdlib>
+#include <cstring>
+#include <ctime>
+
+#include "../common/cxxstdio.hpp"
+#include "../common/md5calc.hpp"
+#include "../common/random.hpp"
+#include "../common/nullpo.hpp"
#include "../common/socket.hpp"
#include "../common/timer.hpp"
#include "../common/version.hpp"
-#include "../common/nullpo.hpp"
-#include "../common/md5calc.hpp"
-#include "../common/mt_rand.hpp"
#include "atcommand.hpp"
#include "battle.hpp"
-#include "chat.hpp"
#include "chrif.hpp"
-#include "clif.hpp"
-#include "guild.hpp"
#include "intif.hpp"
#include "itemdb.hpp"
#include "magic.hpp"
#include "map.hpp"
-#include "mob.hpp"
#include "npc.hpp"
#include "party.hpp"
#include "pc.hpp"
-#include "script.hpp"
#include "skill.hpp"
#include "storage.hpp"
#include "tmw.hpp"
#include "trade.hpp"
-#ifdef MEMWATCH
-#include "memwatch.hpp"
-#endif
+#include "../poison.hpp"
+
+#define DUMP_UNKNOWN_PACKET 1
+
+constexpr int EMOTE_IGNORED = 0x0e;
+
+// functions list. Rate is how many milliseconds are required between
+// calls. Packets exceeding this rate will be dropped. flood_rates in
+// map.h must be the same length as this table. rate 0 is default
+// rate -1 is unlimited
+
+typedef void (*clif_func)(int fd, struct map_session_data *sd);
+struct func_table
+{
+ interval_t rate;
+ int len;
+ clif_func func;
-#define STATE_BLIND 0x10
-#define EMOTE_IGNORED 0x0e
-
-static const int packet_len_table[0x220] = {
- 10, 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, 0,
-//#0x0040
- 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, -1, 55, 17, 3, 37, 46, -1, 23, -1, 3, 108, 3, 2,
- 3, 28, 19, 11, 3, -1, 9, 5, 54, 53, 58, 60, 41, 2, 6, 6,
-//#0x0080
- 7, 3, 2, 2, 2, 5, 16, 12, 10, 7, 29, 23, -1, -1, -1, 0, // 0x8b unknown... size 2 or 23?
- 7, 22, 28, 2, 6, 30, -1, -1, 3, -1, -1, 5, 9, 17, 17, 6,
- 23, 6, 6, -1, -1, -1, -1, 8, 7, 6, 7, 4, 7, 0, -1, 6,
- 8, 8, 3, 3, -1, 6, 6, -1, 7, 6, 2, 5, 6, 44, 5, 3,
-//#0x00C0
- 7, 2, 6, 8, 6, 7, -1, -1, -1, -1, 3, 3, 6, 6, 2, 27,
- 3, 4, 4, 2, -1, -1, 3, -1, 6, 14, 3, -1, 28, 29, -1, -1,
- 30, 30, 26, 2, 6, 26, 3, 3, 8, 19, 5, 2, 3, 2, 2, 2,
- 3, 2, 6, 8, 21, 8, 8, 2, 2, 26, 3, -1, 6, 27, 30, 10,
-
-//#0x0100
- 2, 6, 6, 30, 79, 31, 10, 10, -1, -1, 4, 6, 6, 2, 11, -1,
- 10, 39, 4, 10, 31, 35, 10, 18, 2, 13, 15, 20, 68, 2, 3, 16,
- 6, 14, -1, -1, 21, 8, 8, 8, 8, 8, 2, 2, 3, 4, 2, -1,
- 6, 86, 6, -1, -1, 7, -1, 6, 3, 16, 4, 4, 4, 6, 24, 26,
-//#0x0140
- 22, 14, 6, 10, 23, 19, 6, 39, 8, 9, 6, 27, -1, 2, 6, 6,
- 110, 6, -1, -1, -1, -1, -1, 6, -1, 54, 66, 54, 90, 42, 6, 42,
- -1, -1, -1, -1, -1, 30, -1, 3, 14, 3, 30, 10, 43, 14, 186, 182,
- 14, 30, 10, 3, -1, 6, 106, -1, 4, 5, 4, -1, 6, 7, -1, -1,
-//#0x0180
- 6, 3, 106, 10, 10, 34, 0, 6, 8, 4, 4, 4, 29, -1, 10, 6,
- 90, 86, 24, 6, 30, 102, 9, 4, 8, 4, 14, 10, -1, 6, 2, 6,
- 3, 3, 35, 5, 11, 26, -1, 4, 4, 6, 10, 12, 6, -1, 4, 4,
- 11, 7, -1, 67, 12, 18, 114, 6, 3, 6, 26, 26, 26, 26, 2, 3,
-//#0x01C0, Set 0x1d5=-1
- 2, 14, 10, -1, 22, 22, 4, 2, 13, 97, 0, 9, 9, 30, 6, 28,
- 8, 14, 10, 35, 6, -1, 4, 11, 54, 53, 60, 2, -1, 47, 33, 6,
- 30, 8, 34, 14, 2, 6, 26, 2, 28, 81, 6, 10, 26, 2, -1, -1,
- -1, -1, 20, 10, 32, 9, 34, 14, 2, 6, 48, 56, -1, 4, 5, 10,
-//#0x200
- 26, -1, 26, 10, 18, 26, 11, 34, 14, 36, 10, 19, 10, -1, 24, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ // ctor exists because interval_t must be explicit
+ func_table(int r, int l, clif_func f)
+ : rate(r), len(l), func(f)
+ {}
};
+constexpr int VAR = -1;
+
+extern // not really - defined below
+func_table clif_parse_func_table[0x0220];
+
+
// local define
-enum
+enum class SendWho
{
ALL_CLIENT,
ALL_SAMEMAP,
@@ -116,42 +77,65 @@ enum
PARTY_SAMEMAP_WOS,
PARTY_AREA,
PARTY_AREA_WOS,
- GUILD,
- GUILD_WOS,
- GUILD_SAMEMAP, // [Valaris]
- GUILD_SAMEMAP_WOS,
- GUILD_AREA,
- GUILD_AREA_WOS, // end additions [Valaris]
- SELF
+ SELF,
};
-#define WBUFPOS(p,pos,x,y) { unsigned char *__p = (p); __p+=(pos); __p[0] = (x)>>2; __p[1] = ((x)<<6) | (((y)>>4)&0x3f); __p[2] = (y)<<4; }
-#define WBUFPOS2(p,pos,x0,y0,x1,y1) { unsigned char *__p = (p); __p+=(pos); __p[0] = (x0)>>2; __p[1] = ((x0)<<6) | (((y0)>>4)&0x3f); __p[2] = ((y0)<<4) | (((x1)>>6)&0x0f); __p[3]=((x1)<<2) | (((y1)>>8)&0x03); __p[4]=(y1); }
+inline
+void WBUFPOS(uint8_t *p, size_t pos, uint16_t x, uint16_t y)
+{
+ p += pos;
+ p[0] = x >> 2;
+ p[1] = (x << 6) | ((y >> 4) & 0x3f);
+ p[2] = y << 4;
+}
+inline
+void WBUFPOS2(uint8_t *p, size_t pos, uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1)
+{
+ p += pos;
+ p[0] = x0 >> 2;
+ p[1] = (x0 << 6) | ((y0 >> 4) & 0x3f);
+ p[2] = (y0 << 4) | ((x1 >> 6) & 0x0f);
+ p[3] = (x1 << 2) | ((y1 >> 8) & 0x03);
+ p[4] = y1;
+}
+
+inline
+void WFIFOPOS(int fd, size_t pos, uint16_t x, uint16_t y)
+{
+ WBUFPOS(static_cast<uint8_t *>(WFIFOP(fd, pos)), 0, x, y);
+}
+inline
+void WFIFOPOS2(int fd, size_t pos, uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1)
+{
+ WBUFPOS2(static_cast<uint8_t *>(WFIFOP(fd, pos)), 0, x0, y0, x1, y1);
+}
-#define WFIFOPOS(fd,pos,x,y) { WBUFPOS (WFIFOP(fd,pos),0,x,y); }
-#define WFIFOPOS2(fd,pos,x0,y0,x1,y1) { WBUFPOS2(WFIFOP(fd,pos),0,x0,y0,x1,y1); }
+static
+char map_ip_str[16];
+static
+struct in_addr map_ip;
+static
+int map_port = 5121;
-static char map_ip_str[16];
-static struct in_addr map_ip;
-static int map_port = 5121;
-int map_fd;
-char talkie_mes[80];
+static
+int clif_changelook_towards(struct block_list *bl, LOOK type, int val,
+ struct map_session_data *dstsd);
/*==========================================
* map鯖ã®ip設定
*------------------------------------------
*/
-void clif_setip (const char *ip)
+void clif_setip(const char *ip)
{
- memcpy (map_ip_str, ip, 16);
- map_ip.s_addr = inet_addr (map_ip_str);
+ memcpy(map_ip_str, ip, 16);
+ map_ip.s_addr = inet_addr(map_ip_str);
}
/*==========================================
* map鯖ã®port設定
*------------------------------------------
*/
-void clif_setport (int port)
+void clif_setport(int port)
{
map_port = port;
}
@@ -160,7 +144,7 @@ void clif_setport (int port)
* map鯖ã®ip読ã¿å‡ºã—
*------------------------------------------
*/
-struct in_addr clif_getip (void)
+struct in_addr clif_getip(void)
{
return map_ip;
}
@@ -169,7 +153,7 @@ struct in_addr clif_getip (void)
* map鯖ã®port読ã¿å‡ºã—
*------------------------------------------
*/
-int clif_getport (void)
+int clif_getport(void)
{
return map_port;
}
@@ -178,16 +162,16 @@ int clif_getport (void)
*
*------------------------------------------
*/
-int clif_countusers (void)
+int clif_countusers(void)
{
- int users = 0, i;
+ int users = 0, i;
struct map_session_data *sd;
for (i = 0; i < fd_max; i++)
{
if (session[i] && (sd = (struct map_session_data *)session[i]->session_data) && sd
&& sd->state.auth && !(battle_config.hide_GM_session
- && pc_isGM (sd)))
+ && pc_isGM(sd)))
users++;
}
return users;
@@ -197,109 +181,96 @@ int clif_countusers (void)
* å…¨ã¦ã®clientã«å¯¾ã—ã¦func()実行
*------------------------------------------
*/
-int clif_foreachclient (int (*func) (struct map_session_data *, va_list), ...)
+int clif_foreachclient(std::function<void(struct map_session_data *)> func)
{
- int i;
- va_list ap;
+ int i;
struct map_session_data *sd;
- va_start (ap, func);
for (i = 0; i < fd_max; i++)
{
if (session[i] && (sd = (struct map_session_data *)session[i]->session_data) && sd
&& sd->state.auth)
- func (sd, ap);
+ func(sd);
}
- va_end (ap);
return 0;
}
-static int is_deaf (struct block_list *bl)
+static
+int is_deaf(struct block_list *bl)
{
struct map_session_data *sd = (struct map_session_data *) bl;
- if (!bl || bl->type != BL_PC)
+ if (!bl || bl->type != BL::PC)
return 0;
return sd->special_state.deaf;
}
-static void clif_emotion_towards (struct block_list *bl,
+static
+void clif_emotion_towards(struct block_list *bl,
struct block_list *target, int type);
-static char *clif_validate_chat (struct map_session_data *sd, int type,
- char **message, size_t *message_len);
+static
+char *clif_validate_chat(struct map_session_data *sd, int type,
+ const char **message, size_t *message_len);
/*==========================================
- * clif_sendã§AREA*指定時用
+ * clif_sendã§SendWho::AREA*指定時用
*------------------------------------------
*/
static
-int clif_send_sub (struct block_list *bl, va_list ap)
+void clif_send_sub(struct block_list *bl, const unsigned char *buf, int len,
+ struct block_list *src_bl, SendWho type)
{
- unsigned char *buf;
- int len;
- struct block_list *src_bl;
- int type;
- struct map_session_data *sd;
-
- nullpo_retr (0, bl);
- nullpo_retr (0, ap);
- nullpo_retr (0, sd = (struct map_session_data *) bl);
-
- buf = va_arg (ap, unsigned char *);
- len = va_arg (ap, int);
- nullpo_retr (0, src_bl = va_arg (ap, struct block_list *));
- type = va_arg (ap, int);
+ nullpo_retv(bl);
+ struct map_session_data *sd = (struct map_session_data *) bl;
switch (type)
{
- case AREA_WOS:
+ case SendWho::AREA_WOS:
if (bl && bl == src_bl)
- return 0;
+ return;
break;
- case AREA_CHAT_WOC:
- if (is_deaf (bl)
- && !(bl->type == BL_PC
- && pc_isGM ((struct map_session_data *) src_bl)))
+ case SendWho::AREA_CHAT_WOC:
+ if (is_deaf(bl)
+ && !(bl->type == BL::PC
+ && pc_isGM((struct map_session_data *) src_bl)))
{
- clif_emotion_towards (src_bl, bl, EMOTE_IGNORED);
- return 0;
+ clif_emotion_towards(src_bl, bl, EMOTE_IGNORED);
+ return;
}
- /* fall through... */
- case AREA_WOC:
+ FALLTHROUGH;
+ case SendWho::AREA_WOC:
if ((sd && sd->chatID) || (bl && bl == src_bl))
- return 0;
+ return;
break;
- case AREA_WOSC:
+ case SendWho::AREA_WOSC:
if ((sd) && sd->chatID
&& sd->chatID == ((struct map_session_data *) src_bl)->chatID)
- return 0;
+ return;
break;
}
if (session[sd->fd] != NULL)
{
- if (WFIFOP (sd->fd, 0) == buf)
+ if (WFIFOP(sd->fd, 0) == buf)
{
- printf ("WARNING: Invalid use of clif_send function\n");
- printf
- (" Packet x%4x use a WFIFO of a player instead of to use a buffer.\n",
- WBUFW (buf, 0));
- printf (" Please correct your code.\n");
+ PRINTF("WARNING: Invalid use of clif_send function\n");
+ PRINTF(" Packet x%4x use a WFIFO of a player instead of to use a buffer.\n",
+ RBUFW(buf, 0));
+ PRINTF(" Please correct your code.\n");
// don't send to not move the pointer of the packet for next sessions in the loop
}
else
{
- if (packet_len_table[RBUFW (buf, 0)])
- { // packet must exist
- memcpy (WFIFOP (sd->fd, 0), buf, len);
- WFIFOSET (sd->fd, len);
+ if (clif_parse_func_table[RBUFW(buf, 0)].len)
+ {
+ // packet must exist
+ memcpy(WFIFOP(sd->fd, 0), buf, len);
+ WFIFOSET(sd->fd, len);
}
}
}
-
- return 0;
}
/*==========================================
@@ -307,35 +278,34 @@ int clif_send_sub (struct block_list *bl, va_list ap)
*------------------------------------------
*/
static
-int clif_send (const uint8_t *buf, int len, struct block_list *bl, int type)
+int clif_send(const uint8_t *buf, int len, struct block_list *bl, SendWho type)
{
- int i;
+ int i;
struct map_session_data *sd;
struct chat_data *cd;
struct party *p = NULL;
- struct guild *g = NULL;
- int x0 = 0, x1 = 0, y0 = 0, y1 = 0;
+ int x0 = 0, x1 = 0, y0 = 0, y1 = 0;
- if (type != ALL_CLIENT)
+ if (type != SendWho::ALL_CLIENT)
{
- nullpo_retr (0, bl);
+ nullpo_ret(bl);
- if (bl->type == BL_PC)
+ if (bl->type == BL::PC)
{
struct map_session_data *sd2 = (struct map_session_data *) bl;
- if (sd2->status.option & OPTION_INVISIBILITY)
+ if (bool(sd2->status.option & Option::INVISIBILITY))
{
// Obscure hidden GMs
switch (type)
{
- case AREA:
- case AREA_WOC:
- type = SELF;
+ case SendWho::AREA:
+ case SendWho::AREA_WOC:
+ type = SendWho::SELF;
break;
- case AREA_WOS:
- case AREA_WOSC:
+ case SendWho::AREA_WOS:
+ case SendWho::AREA_WOSC:
return 1;
default:
@@ -347,95 +317,94 @@ int clif_send (const uint8_t *buf, int len, struct block_list *bl, int type)
switch (type)
{
- case ALL_CLIENT: // 全クライアントã«é€ä¿¡
+ case SendWho::ALL_CLIENT: // 全クライアントã«é€ä¿¡
for (i = 0; i < fd_max; i++)
{
if (session[i] && (sd = (struct map_session_data *)session[i]->session_data) != NULL
&& sd->state.auth)
{
- if (packet_len_table[RBUFW (buf, 0)])
+ if (clif_parse_func_table[RBUFW(buf, 0)].len)
{ // packet must exist
- memcpy (WFIFOP (i, 0), buf, len);
- WFIFOSET (i, len);
+ memcpy(WFIFOP(i, 0), buf, len);
+ WFIFOSET(i, len);
}
}
}
break;
- case ALL_SAMEMAP: // åŒã˜ãƒžãƒƒãƒ—ã®å…¨ã‚¯ãƒ©ã‚¤ã‚¢ãƒ³ãƒˆã«é€ä¿¡
+ case SendWho::ALL_SAMEMAP: // åŒã˜ãƒžãƒƒãƒ—ã®å…¨ã‚¯ãƒ©ã‚¤ã‚¢ãƒ³ãƒˆã«é€ä¿¡
for (i = 0; i < fd_max; i++)
{
if (session[i] && (sd = (struct map_session_data *)session[i]->session_data) != NULL
&& sd->state.auth && sd->bl.m == bl->m)
{
- if (packet_len_table[RBUFW (buf, 0)])
+ if (clif_parse_func_table[RBUFW(buf, 0)].len)
{ // packet must exist
- memcpy (WFIFOP (i, 0), buf, len);
- WFIFOSET (i, len);
+ memcpy(WFIFOP(i, 0), buf, len);
+ WFIFOSET(i, len);
}
}
}
break;
- case AREA:
- case AREA_WOS:
- case AREA_WOC:
- case AREA_WOSC:
- map_foreachinarea (clif_send_sub, bl->m, bl->x - AREA_SIZE,
- bl->y - AREA_SIZE, bl->x + AREA_SIZE,
- bl->y + AREA_SIZE, BL_PC, buf, len, bl, type);
+ case SendWho::AREA:
+ case SendWho::AREA_WOS:
+ case SendWho::AREA_WOC:
+ case SendWho::AREA_WOSC:
+ map_foreachinarea(std::bind(clif_send_sub, ph::_1, buf, len, bl, type),
+ bl->m, bl->x - AREA_SIZE, bl->y - AREA_SIZE,
+ bl->x + AREA_SIZE, bl->y + AREA_SIZE, BL::PC);
break;
- case AREA_CHAT_WOC:
- map_foreachinarea (clif_send_sub, bl->m, bl->x - (AREA_SIZE),
- bl->y - (AREA_SIZE),
- bl->x + (AREA_SIZE),
- bl->y + (AREA_SIZE), BL_PC, buf, len, bl,
- AREA_CHAT_WOC);
+ case SendWho::AREA_CHAT_WOC:
+ map_foreachinarea(std::bind(clif_send_sub, ph::_1, buf, len, bl, SendWho::AREA_CHAT_WOC),
+ bl->m, bl->x - (AREA_SIZE), bl->y - (AREA_SIZE),
+ bl->x + (AREA_SIZE), bl->y + (AREA_SIZE), BL::PC);
break;
- case CHAT:
- case CHAT_WOS:
+ case SendWho::CHAT:
+ case SendWho::CHAT_WOS:
cd = (struct chat_data *) bl;
- if (bl->type == BL_PC)
+ if (bl->type == BL::PC)
{
sd = (struct map_session_data *) bl;
- cd = (struct chat_data *) map_id2bl (sd->chatID);
+ cd = (struct chat_data *) map_id2bl(sd->chatID);
}
- else if (bl->type != BL_CHAT)
+ else if (bl->type != BL::CHAT)
break;
if (cd == NULL)
break;
for (i = 0; i < cd->users; i++)
{
- if (type == CHAT_WOS
+ if (type == SendWho::CHAT_WOS
&& cd->usersd[i] == (struct map_session_data *) bl)
continue;
- if (packet_len_table[RBUFW (buf, 0)])
+ if (clif_parse_func_table[RBUFW(buf, 0)].len)
{ // packet must exist
- memcpy (WFIFOP (cd->usersd[i]->fd, 0), buf, len);
- WFIFOSET (cd->usersd[i]->fd, len);
+ memcpy(WFIFOP(cd->usersd[i]->fd, 0), buf, len);
+ WFIFOSET(cd->usersd[i]->fd, len);
}
}
break;
- case PARTY_AREA: // åŒã˜ç”»é¢å†…ã®å…¨ãƒ‘ーティーメンãƒã«é€ä¿¡
- case PARTY_AREA_WOS: // 自分以外ã®åŒã˜ç”»é¢å†…ã®å…¨ãƒ‘ーティーメンãƒã«é€ä¿¡
+ case SendWho::PARTY_AREA: // åŒã˜ç”»é¢å†…ã®å…¨ãƒ‘ーティーメンãƒã«é€ä¿¡
+ case SendWho::PARTY_AREA_WOS: // 自分以外ã®åŒã˜ç”»é¢å†…ã®å…¨ãƒ‘ーティーメンãƒã«é€ä¿¡
x0 = bl->x - AREA_SIZE;
y0 = bl->y - AREA_SIZE;
x1 = bl->x + AREA_SIZE;
y1 = bl->y + AREA_SIZE;
- case PARTY: // 全パーティーメンãƒã«é€ä¿¡
- case PARTY_WOS: // 自分以外ã®å…¨ãƒ‘ーティーメンãƒã«é€ä¿¡
- case PARTY_SAMEMAP: // åŒã˜ãƒžãƒƒãƒ—ã®å…¨ãƒ‘ーティーメンãƒã«é€ä¿¡
- case PARTY_SAMEMAP_WOS: // 自分以外ã®åŒã˜ãƒžãƒƒãƒ—ã®å…¨ãƒ‘ーティーメンãƒã«é€ä¿¡
- if (bl->type == BL_PC)
+ FALLTHROUGH;
+ case SendWho::PARTY: // 全パーティーメンãƒã«é€ä¿¡
+ case SendWho::PARTY_WOS: // 自分以外ã®å…¨ãƒ‘ーティーメンãƒã«é€ä¿¡
+ case SendWho::PARTY_SAMEMAP: // åŒã˜ãƒžãƒƒãƒ—ã®å…¨ãƒ‘ーティーメンãƒã«é€ä¿¡
+ case SendWho::PARTY_SAMEMAP_WOS: // 自分以外ã®åŒã˜ãƒžãƒƒãƒ—ã®å…¨ãƒ‘ーティーメンãƒã«é€ä¿¡
+ if (bl->type == BL::PC)
{
sd = (struct map_session_data *) bl;
if (sd->partyspy > 0)
{
- p = party_search (sd->partyspy);
+ p = party_search(sd->partyspy);
}
else
{
if (sd->status.party_id > 0)
- p = party_search (sd->status.party_id);
+ p = party_search(sd->status.party_id);
}
}
if (p)
@@ -444,21 +413,21 @@ int clif_send (const uint8_t *buf, int len, struct block_list *bl, int type)
{
if ((sd = p->member[i].sd) != NULL)
{
- if (sd->bl.id == bl->id && (type == PARTY_WOS ||
- type == PARTY_SAMEMAP_WOS
+ if (sd->bl.id == bl->id && (type == SendWho::PARTY_WOS ||
+ type == SendWho::PARTY_SAMEMAP_WOS
|| type ==
- PARTY_AREA_WOS))
+ SendWho::PARTY_AREA_WOS))
continue;
- if (type != PARTY && type != PARTY_WOS && bl->m != sd->bl.m) // マップãƒã‚§ãƒƒã‚¯
+ if (type != SendWho::PARTY && type != SendWho::PARTY_WOS && bl->m != sd->bl.m) // マップãƒã‚§ãƒƒã‚¯
continue;
- if ((type == PARTY_AREA || type == PARTY_AREA_WOS) &&
+ if ((type == SendWho::PARTY_AREA || type == SendWho::PARTY_AREA_WOS) &&
(sd->bl.x < x0 || sd->bl.y < y0 ||
sd->bl.x > x1 || sd->bl.y > y1))
continue;
- if (packet_len_table[RBUFW (buf, 0)])
+ if (clif_parse_func_table[RBUFW(buf, 0)].len)
{ // packet must exist
- memcpy (WFIFOP (sd->fd, 0), buf, len);
- WFIFOSET (sd->fd, len);
+ memcpy(WFIFOP(sd->fd, 0), buf, len);
+ WFIFOSET(sd->fd, len);
}
}
}
@@ -469,118 +438,28 @@ int clif_send (const uint8_t *buf, int len, struct block_list *bl, int type)
{
if (sd->partyspy == p->party_id)
{
- if (packet_len_table[RBUFW (buf, 0)])
+ if (clif_parse_func_table[RBUFW(buf, 0)].len)
{ // packet must exist
- memcpy (WFIFOP (sd->fd, 0), buf, len);
- WFIFOSET (sd->fd, len);
+ memcpy(WFIFOP(sd->fd, 0), buf, len);
+ WFIFOSET(sd->fd, len);
}
}
}
}
}
break;
- case SELF:
+ case SendWho::SELF:
sd = (struct map_session_data *) bl;
- if (packet_len_table[RBUFW (buf, 0)])
+ if (clif_parse_func_table[RBUFW(buf, 0)].len)
{ // packet must exist
- memcpy (WFIFOP (sd->fd, 0), buf, len);
- WFIFOSET (sd->fd, len);
- }
- break;
-
-/* New definitions for guilds [Valaris] */
-
- case GUILD_AREA:
- case GUILD_AREA_WOS:
- x0 = bl->x - AREA_SIZE;
- y0 = bl->y - AREA_SIZE;
- x1 = bl->x + AREA_SIZE;
- y1 = bl->y + AREA_SIZE;
- case GUILD:
- case GUILD_WOS:
- if (bl && bl->type == BL_PC)
- { // guildspy [Syrus22]
- sd = (struct map_session_data *) bl;
- if (sd->guildspy > 0)
- {
- g = guild_search (sd->guildspy);
- }
- else
- {
- if (sd->status.guild_id > 0)
- g = guild_search (sd->status.guild_id);
- }
- }
- if (g)
- {
- for (i = 0; i < g->max_member; i++)
- {
- if ((sd = g->member[i].sd) != NULL)
- {
- if (type == GUILD_WOS && sd->bl.id == bl->id)
- continue;
- if (packet_len_table[RBUFW (buf, 0)])
- { // packet must exist
- memcpy (WFIFOP (sd->fd, 0), buf, len);
- WFIFOSET (sd->fd, len);
- }
- }
- }
- for (i = 0; i < fd_max; i++)
- {
- if (session[i] && (sd = (struct map_session_data *)session[i]->session_data) != NULL
- && sd->state.auth)
- {
- if (sd->guildspy == g->guild_id)
- {
- if (packet_len_table[RBUFW (buf, 0)])
- { // packet must exist
- memcpy (WFIFOP (sd->fd, 0), buf, len);
- WFIFOSET (sd->fd, len);
- }
- }
- }
- }
- }
- break;
- case GUILD_SAMEMAP:
- case GUILD_SAMEMAP_WOS:
- if (bl->type == BL_PC)
- {
- sd = (struct map_session_data *) bl;
- if (sd->status.guild_id > 0)
- g = guild_search (sd->status.guild_id);
- }
- if (g)
- {
- for (i = 0; i < g->max_member; i++)
- {
- if ((sd = g->member[i].sd) != NULL)
- {
- if (sd->bl.id == bl->id && (type == GUILD_WOS ||
- type == GUILD_SAMEMAP_WOS
- || type ==
- GUILD_AREA_WOS))
- continue;
- if (type != GUILD && type != GUILD_WOS && bl->m != sd->bl.m) // マップãƒã‚§ãƒƒã‚¯
- continue;
- if ((type == GUILD_AREA || type == GUILD_AREA_WOS) &&
- (sd->bl.x < x0 || sd->bl.y < y0 ||
- sd->bl.x > x1 || sd->bl.y > y1))
- continue;
- if (packet_len_table[RBUFW (buf, 0)])
- { // packet must exist
- memcpy (WFIFOP (sd->fd, 0), buf, len);
- WFIFOSET (sd->fd, len);
- }
- }
- }
+ memcpy(WFIFOP(sd->fd, 0), buf, len);
+ WFIFOSET(sd->fd, len);
}
break;
default:
if (battle_config.error_log)
- printf ("clif_send ã¾ã ä½œã£ã¦ãªã„よー\n");
+ PRINTF("clif_send ã¾ã ä½œã£ã¦ãªã„よー\n");
return -1;
}
@@ -594,11 +473,11 @@ int clif_send (const uint8_t *buf, int len, struct block_list *bl, int type)
*
*------------------------------------------
*/
-int clif_authok (struct map_session_data *sd)
+int clif_authok(struct map_session_data *sd)
{
- int fd;
+ int fd;
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
if (!sd)
return 0;
@@ -608,12 +487,12 @@ int clif_authok (struct map_session_data *sd)
fd = sd->fd;
- WFIFOW (fd, 0) = 0x73;
- WFIFOL (fd, 2) = gettick ();
- WFIFOPOS (fd, 6, sd->bl.x, sd->bl.y);
- WFIFOB (fd, 9) = 5;
- WFIFOB (fd, 10) = 5;
- WFIFOSET (fd, packet_len_table[0x73]);
+ WFIFOW(fd, 0) = 0x73;
+ WFIFOL(fd, 2) = gettick().time_since_epoch().count();
+ WFIFOPOS(fd, 6, sd->bl.x, sd->bl.y);
+ WFIFOB(fd, 9) = 5;
+ WFIFOB(fd, 10) = 5;
+ WFIFOSET(fd, clif_parse_func_table[0x73].len);
return 0;
}
@@ -622,16 +501,16 @@ int clif_authok (struct map_session_data *sd)
*
*------------------------------------------
*/
-int clif_authfail_fd (int fd, int type)
+int clif_authfail_fd(int fd, int type)
{
if (!fd || !session[fd])
return 0;
- WFIFOW (fd, 0) = 0x81;
- WFIFOL (fd, 2) = type;
- WFIFOSET (fd, packet_len_table[0x81]);
+ WFIFOW(fd, 0) = 0x81;
+ WFIFOL(fd, 2) = type;
+ WFIFOSET(fd, clif_parse_func_table[0x81].len);
- clif_setwaitclose (fd);
+ clif_setwaitclose(fd);
return 0;
}
@@ -640,21 +519,21 @@ int clif_authfail_fd (int fd, int type)
*
*------------------------------------------
*/
-int clif_charselectok (int id)
+int clif_charselectok(int id)
{
struct map_session_data *sd;
- int fd;
+ int fd;
- if ((sd = map_id2sd (id)) == NULL)
+ if ((sd = map_id2sd(id)) == NULL)
return 1;
if (!sd->fd)
return 1;
fd = sd->fd;
- WFIFOW (fd, 0) = 0xb3;
- WFIFOB (fd, 2) = 1;
- WFIFOSET (fd, packet_len_table[0xb3]);
+ WFIFOW(fd, 0) = 0xb3;
+ WFIFOB(fd, 2) = 1;
+ WFIFOSET(fd, clif_parse_func_table[0xb3].len);
return 0;
}
@@ -663,43 +542,44 @@ int clif_charselectok (int id)
*
*------------------------------------------
*/
-static int clif_set009e (struct flooritem_data *fitem, uint8_t *buf)
+static
+int clif_set009e(struct flooritem_data *fitem, uint8_t *buf)
{
- int view;
+ int view;
- nullpo_retr (0, fitem);
+ nullpo_ret(fitem);
//009e <ID>.l <name ID>.w <identify flag>.B <X>.w <Y>.w <subX>.B <subY>.B <amount>.w
- WBUFW (buf, 0) = 0x9e;
- WBUFL (buf, 2) = fitem->bl.id;
- if ((view = itemdb_viewid (fitem->item_data.nameid)) > 0)
- WBUFW (buf, 6) = view;
+ WBUFW(buf, 0) = 0x9e;
+ WBUFL(buf, 2) = fitem->bl.id;
+ if ((view = itemdb_viewid(fitem->item_data.nameid)) > 0)
+ WBUFW(buf, 6) = view;
else
- WBUFW (buf, 6) = fitem->item_data.nameid;
- WBUFB (buf, 8) = fitem->item_data.identify;
- WBUFW (buf, 9) = fitem->bl.x;
- WBUFW (buf, 11) = fitem->bl.y;
- WBUFB (buf, 13) = fitem->subx;
- WBUFB (buf, 14) = fitem->suby;
- WBUFW (buf, 15) = fitem->item_data.amount;
+ WBUFW(buf, 6) = fitem->item_data.nameid;
+ WBUFB(buf, 8) = fitem->item_data.identify;
+ WBUFW(buf, 9) = fitem->bl.x;
+ WBUFW(buf, 11) = fitem->bl.y;
+ WBUFB(buf, 13) = fitem->subx;
+ WBUFB(buf, 14) = fitem->suby;
+ WBUFW(buf, 15) = fitem->item_data.amount;
- return packet_len_table[0x9e];
+ return clif_parse_func_table[0x9e].len;
}
/*==========================================
*
*------------------------------------------
*/
-int clif_dropflooritem (struct flooritem_data *fitem)
+int clif_dropflooritem(struct flooritem_data *fitem)
{
uint8_t buf[64];
- nullpo_retr (0, fitem);
+ nullpo_ret(fitem);
if (fitem->item_data.nameid <= 0)
return 0;
- clif_set009e (fitem, buf);
- clif_send (buf, packet_len_table[0x9e], &fitem->bl, AREA);
+ clif_set009e(fitem, buf);
+ clif_send(buf, clif_parse_func_table[0x9e].len, &fitem->bl, SendWho::AREA);
return 0;
}
@@ -708,23 +588,23 @@ int clif_dropflooritem (struct flooritem_data *fitem)
*
*------------------------------------------
*/
-int clif_clearflooritem (struct flooritem_data *fitem, int fd)
+int clif_clearflooritem(struct flooritem_data *fitem, int fd)
{
unsigned char buf[16];
- nullpo_retr (0, fitem);
+ nullpo_ret(fitem);
- WBUFW (buf, 0) = 0xa1;
- WBUFL (buf, 2) = fitem->bl.id;
+ WBUFW(buf, 0) = 0xa1;
+ WBUFL(buf, 2) = fitem->bl.id;
if (fd == 0)
{
- clif_send (buf, packet_len_table[0xa1], &fitem->bl, AREA);
+ clif_send(buf, clif_parse_func_table[0xa1].len, &fitem->bl, SendWho::AREA);
}
else
{
- memcpy (WFIFOP (fd, 0), buf, 6);
- WFIFOSET (fd, packet_len_table[0xa1]);
+ memcpy(WFIFOP(fd, 0), buf, 6);
+ WFIFOSET(fd, clif_parse_func_table[0xa1].len);
}
return 0;
@@ -734,45 +614,48 @@ int clif_clearflooritem (struct flooritem_data *fitem, int fd)
*
*------------------------------------------
*/
-int clif_clearchar (struct block_list *bl, int type)
+int clif_clearchar(struct block_list *bl, BeingRemoveWhy type)
{
unsigned char buf[16];
- nullpo_retr (0, bl);
+ nullpo_ret(bl);
- WBUFW (buf, 0) = 0x80;
- WBUFL (buf, 2) = bl->id;
- if (type == 9)
+ WBUFW(buf, 0) = 0x80;
+ WBUFL(buf, 2) = bl->id;
+ if (type == BeingRemoveWhy::DISGUISE)
{
- WBUFB (buf, 6) = 0;
- clif_send (buf, packet_len_table[0x80], bl, AREA);
+ WBUFB(buf, 6) = static_cast<uint8_t>(BeingRemoveWhy::GONE);
+ clif_send(buf, clif_parse_func_table[0x80].len, bl, SendWho::AREA);
}
else
{
- WBUFB (buf, 6) = type;
- clif_send (buf, packet_len_table[0x80], bl,
- type == 1 ? AREA : AREA_WOS);
+ WBUFB(buf, 6) = static_cast<uint8_t>(type);
+ clif_send(buf, clif_parse_func_table[0x80].len, bl,
+ type == BeingRemoveWhy::DEAD ? SendWho::AREA : SendWho::AREA_WOS);
}
return 0;
}
-static void clif_clearchar_delay_sub (timer_id tid, tick_t tick, custom_id_t id,
- custom_data_t data)
+static
+void clif_clearchar_delay_sub(TimerData *, tick_t,
+ struct block_list *bl, BeingRemoveWhy type)
{
- struct block_list *bl = (struct block_list *) id;
-
- clif_clearchar (bl, data);
- map_freeblock (bl);
+ clif_clearchar(bl, type);
+ map_freeblock(bl);
}
-int clif_clearchar_delay (unsigned int tick, struct block_list *bl, int type)
+int clif_clearchar_delay(tick_t tick,
+ struct block_list *bl, BeingRemoveWhy type)
{
struct block_list *tmpbl;
- CREATE (tmpbl, struct block_list, 1);
+ CREATE(tmpbl, struct block_list, 1);
- memcpy (tmpbl, bl, sizeof (struct block_list));
- add_timer (tick, clif_clearchar_delay_sub, (custom_id_t) tmpbl, type);
+ memcpy(tmpbl, bl, sizeof(struct block_list));
+ Timer(tick,
+ std::bind(clif_clearchar_delay_sub, ph::_1, ph::_2,
+ tmpbl, type)
+ ).detach();
return 0;
}
@@ -781,544 +664,286 @@ int clif_clearchar_delay (unsigned int tick, struct block_list *bl, int type)
*
*------------------------------------------
*/
-int clif_clearchar_id (int id, int type, int fd)
+int clif_clearchar_id(int id, BeingRemoveWhy type, int fd)
{
unsigned char buf[16];
- WBUFW (buf, 0) = 0x80;
- WBUFL (buf, 2) = id;
- WBUFB (buf, 6) = type;
- memcpy (WFIFOP (fd, 0), buf, 7);
- WFIFOSET (fd, packet_len_table[0x80]);
+ WBUFW(buf, 0) = 0x80;
+ WBUFL(buf, 2) = id;
+ WBUFB(buf, 6) = static_cast<uint8_t>(type);
+ memcpy(WFIFOP(fd, 0), buf, 7);
+ WFIFOSET(fd, clif_parse_func_table[0x80].len);
return 0;
}
-/*
-static int current_weapon(struct map_session_data *sd)
-{
- if (sd->attack_spell_override)
- return sd->attack_spell_look_override;
- else {
- return sd->status.weapon;
- }
-}
-*/
-
/*==========================================
*
*------------------------------------------
*/
-static int clif_set0078 (struct map_session_data *sd, unsigned char *buf)
-{
- int level = 0;
-
- nullpo_retr (0, sd);
-
- if (sd->disguise > 23 && sd->disguise < 4001)
- { // mob disguises [Valaris]
- WBUFW (buf, 0) = 0x78;
- WBUFL (buf, 2) = sd->bl.id;
- WBUFW (buf, 6) = battle_get_speed (&sd->bl);
- WBUFW (buf, 8) = sd->opt1;
- WBUFW (buf, 10) = sd->opt2;
- WBUFW (buf, 12) = sd->status.option;
- WBUFW (buf, 14) = sd->disguise;
- WBUFW (buf, 42) = 0;
- WBUFB (buf, 44) = 0;
- WBUFPOS (buf, 46, sd->bl.x, sd->bl.y);
- WBUFB (buf, 48) |= sd->dir & 0x0f;
- WBUFB (buf, 49) = 5;
- WBUFB (buf, 50) = 5;
- WBUFB (buf, 51) = 0;
- WBUFW (buf, 52) =
- ((level =
- battle_get_lv (&sd->bl)) >
- battle_config.max_lv) ? battle_config.max_lv : level;
-
- return packet_len_table[0x78];
- }
-
- WBUFW (buf, 0) = 0x1d8;
- WBUFL (buf, 2) = sd->bl.id;
- WBUFW (buf, 6) = sd->speed;
- WBUFW (buf, 8) = sd->opt1;
- WBUFW (buf, 10) = sd->opt2;
- WBUFW (buf, 12) = sd->status.option;
- WBUFW (buf, 14) = sd->view_class;
- WBUFW (buf, 16) = sd->status.hair;
+static
+int clif_set0078(struct map_session_data *sd, unsigned char *buf)
+{
+ nullpo_ret(sd);
+
+ WBUFW(buf, 0) = 0x1d8;
+ WBUFL(buf, 2) = sd->bl.id;
+ WBUFW(buf, 6) = static_cast<uint16_t>(sd->speed.count());
+ WBUFW(buf, 8) = static_cast<uint16_t>(sd->opt1);
+ WBUFW(buf, 10) = static_cast<uint16_t>(sd->opt2);
+ WBUFW(buf, 12) = static_cast<uint16_t>(sd->status.option);
+ WBUFW(buf, 14) = sd->status.species;
+ WBUFW(buf, 16) = sd->status.hair;
if (sd->attack_spell_override)
- WBUFB (buf, 18) = sd->attack_spell_look_override;
+ WBUFW(buf, 18) = sd->attack_spell_look_override;
else
{
- if (sd->equip_index[9] >= 0 && sd->inventory_data[sd->equip_index[9]]
- && sd->view_class != 22)
+ if (sd->equip_index[EQUIP::WEAPON] >= 0
+ && sd->inventory_data[sd->equip_index[EQUIP::WEAPON]])
{
- if (sd->inventory_data[sd->equip_index[9]]->view_id > 0)
- WBUFW (buf, 18) =
- sd->inventory_data[sd->equip_index[9]]->view_id;
+ if (sd->inventory_data[sd->equip_index[EQUIP::WEAPON]]->view_id > 0)
+ WBUFW(buf, 18) =
+ sd->inventory_data[sd->equip_index[EQUIP::WEAPON]]->view_id;
else
- WBUFW (buf, 18) =
- sd->status.inventory[sd->equip_index[9]].nameid;
+ WBUFW(buf, 18) =
+ sd->status.inventory[sd->equip_index[EQUIP::WEAPON]].nameid;
}
else
- WBUFW (buf, 18) = 0;
+ WBUFW(buf, 18) = 0;
}
- if (sd->equip_index[8] >= 0 && sd->equip_index[8] != sd->equip_index[9]
- && sd->inventory_data[sd->equip_index[8]] && sd->view_class != 22)
+ if (sd->equip_index[EQUIP::SHIELD] >= 0
+ && sd->equip_index[EQUIP::SHIELD] != sd->equip_index[EQUIP::WEAPON]
+ && sd->inventory_data[sd->equip_index[EQUIP::SHIELD]])
{
- if (sd->inventory_data[sd->equip_index[8]]->view_id > 0)
- WBUFW (buf, 20) = sd->inventory_data[sd->equip_index[8]]->view_id;
+ if (sd->inventory_data[sd->equip_index[EQUIP::SHIELD]]->view_id > 0)
+ WBUFW(buf, 20) = sd->inventory_data[sd->equip_index[EQUIP::SHIELD]]->view_id;
else
- WBUFW (buf, 20) = sd->status.inventory[sd->equip_index[8]].nameid;
+ WBUFW(buf, 20) = sd->status.inventory[sd->equip_index[EQUIP::SHIELD]].nameid;
}
else
- WBUFW (buf, 20) = 0;
- WBUFW (buf, 22) = sd->status.head_bottom;
- WBUFW (buf, 24) = sd->status.head_top;
- WBUFW (buf, 26) = sd->status.head_mid;
- WBUFW (buf, 28) = sd->status.hair_color;
- WBUFW (buf, 30) = sd->status.clothes_color;
- WBUFW (buf, 32) = sd->head_dir;
- WBUFL (buf, 34) = sd->status.guild_id;
- WBUFW (buf, 38) = sd->guild_emblem_id;
- WBUFW (buf, 40) = sd->status.manner;
- WBUFW (buf, 42) = sd->opt3;
- WBUFB (buf, 44) = sd->status.karma;
- WBUFB (buf, 45) = sd->sex;
- WBUFPOS (buf, 46, sd->bl.x, sd->bl.y);
- WBUFB (buf, 48) |= sd->dir & 0x0f;
- WBUFW (buf, 49) = (pc_isGM (sd) == 60 || pc_isGM (sd) == 99) ? 0x80 : 0;
- WBUFB (buf, 51) = sd->state.dead_sit;
- WBUFW (buf, 52) = 0;
-
- return packet_len_table[0x1d8];
+ WBUFW(buf, 20) = 0;
+ WBUFW(buf, 22) = sd->status.head_bottom;
+ WBUFW(buf, 24) = sd->status.head_top;
+ WBUFW(buf, 26) = sd->status.head_mid;
+ WBUFW(buf, 28) = sd->status.hair_color;
+ WBUFW(buf, 30) = sd->status.clothes_color;
+ WBUFW(buf, 32) = static_cast<uint8_t>(sd->head_dir);
+ WBUFL(buf, 34) = 0 /*guild_id*/;
+ WBUFW(buf, 38) = 0 /*guild_emblem_id*/;
+ WBUFW(buf, 40) = sd->status.manner;
+ WBUFW(buf, 42) = uint16_t(sd->opt3);
+ WBUFB(buf, 44) = sd->status.karma;
+ WBUFB(buf, 45) = sd->sex;
+ WBUFPOS(buf, 46, sd->bl.x, sd->bl.y);
+ // work around ICE in gcc 4.6
+ uint8_t dir = static_cast<uint8_t>(sd->dir);
+ WBUFB(buf, 48) |= dir;
+ WBUFW(buf, 49) = (pc_isGM(sd) == 60 || pc_isGM(sd) == 99) ? 0x80 : 0;
+ WBUFB(buf, 51) = sd->state.dead_sit;
+ WBUFW(buf, 52) = 0;
+
+ return clif_parse_func_table[0x1d8].len;
}
/*==========================================
*
*------------------------------------------
*/
-static int clif_set007b (struct map_session_data *sd, unsigned char *buf)
-{
- int level = 0;
- nullpo_retr (0, sd);
-
- if (sd->disguise > 23 && sd->disguise < 4001)
- { // mob disguises [Valaris]
- WBUFW (buf, 0) = 0x7b;
- WBUFL (buf, 2) = sd->bl.id;
- WBUFW (buf, 6) = battle_get_speed (&sd->bl);
- WBUFW (buf, 8) = sd->opt1;
- WBUFW (buf, 10) = sd->opt2;
- WBUFW (buf, 12) = sd->status.option;
- WBUFW (buf, 14) = sd->disguise;
- WBUFL (buf, 22) = gettick ();
- WBUFW (buf, 46) = 0;
- WBUFB (buf, 48) = 0;
- WBUFPOS2 (buf, 50, sd->bl.x, sd->bl.y, sd->to_x, sd->to_y);
- WBUFB (buf, 55) = 0;
- WBUFB (buf, 56) = 5;
- WBUFB (buf, 57) = 5;
- WBUFW (buf, 58) =
- ((level =
- battle_get_lv (&sd->bl)) >
- battle_config.max_lv) ? battle_config.max_lv : level;
-
- return packet_len_table[0x7b];
- }
-
- WBUFW (buf, 0) = 0x1da;
- WBUFL (buf, 2) = sd->bl.id;
- WBUFW (buf, 6) = sd->speed;
- WBUFW (buf, 8) = sd->opt1;
- WBUFW (buf, 10) = sd->opt2;
- WBUFW (buf, 12) = sd->status.option;
- WBUFW (buf, 14) = sd->view_class;
- WBUFW (buf, 16) = sd->status.hair;
- if (sd->equip_index[9] >= 0 && sd->inventory_data[sd->equip_index[9]]
- && sd->view_class != 22)
- {
- if (sd->inventory_data[sd->equip_index[9]]->view_id > 0)
- WBUFW (buf, 18) = sd->inventory_data[sd->equip_index[9]]->view_id;
+static
+int clif_set007b(struct map_session_data *sd, unsigned char *buf)
+{
+ nullpo_ret(sd);
+
+ WBUFW(buf, 0) = 0x1da;
+ WBUFL(buf, 2) = sd->bl.id;
+ WBUFW(buf, 6) = static_cast<uint16_t>(sd->speed.count());
+ WBUFW(buf, 8) = static_cast<uint16_t>(sd->opt1);
+ WBUFW(buf, 10) = static_cast<uint16_t>(sd->opt2);
+ WBUFW(buf, 12) = static_cast<uint16_t>(sd->status.option);
+ WBUFW(buf, 14) = sd->status.species;
+ WBUFW(buf, 16) = sd->status.hair;
+ if (sd->equip_index[EQUIP::WEAPON] >= 0
+ && sd->inventory_data[sd->equip_index[EQUIP::WEAPON]])
+ {
+ if (sd->inventory_data[sd->equip_index[EQUIP::WEAPON]]->view_id > 0)
+ WBUFW(buf, 18) = sd->inventory_data[sd->equip_index[EQUIP::WEAPON]]->view_id;
else
- WBUFW (buf, 18) = sd->status.inventory[sd->equip_index[9]].nameid;
+ WBUFW(buf, 18) = sd->status.inventory[sd->equip_index[EQUIP::WEAPON]].nameid;
}
else
- WBUFW (buf, 18) = 0;
- if (sd->equip_index[8] >= 0 && sd->equip_index[8] != sd->equip_index[9]
- && sd->inventory_data[sd->equip_index[8]] && sd->view_class != 22)
+ WBUFW(buf, 18) = 0;
+ if (sd->equip_index[EQUIP::SHIELD] >= 0
+ && sd->equip_index[EQUIP::SHIELD] != sd->equip_index[EQUIP::WEAPON]
+ && sd->inventory_data[sd->equip_index[EQUIP::SHIELD]])
{
- if (sd->inventory_data[sd->equip_index[8]]->view_id > 0)
- WBUFW (buf, 20) = sd->inventory_data[sd->equip_index[8]]->view_id;
+ if (sd->inventory_data[sd->equip_index[EQUIP::SHIELD]]->view_id > 0)
+ WBUFW(buf, 20) = sd->inventory_data[sd->equip_index[EQUIP::SHIELD]]->view_id;
else
- WBUFW (buf, 20) = sd->status.inventory[sd->equip_index[8]].nameid;
+ WBUFW(buf, 20) = sd->status.inventory[sd->equip_index[EQUIP::SHIELD]].nameid;
}
else
- WBUFW (buf, 20) = 0;
- WBUFW (buf, 22) = sd->status.head_bottom;
- WBUFL (buf, 24) = gettick ();
- WBUFW (buf, 28) = sd->status.head_top;
- WBUFW (buf, 30) = sd->status.head_mid;
- WBUFW (buf, 32) = sd->status.hair_color;
- WBUFW (buf, 34) = sd->status.clothes_color;
- WBUFW (buf, 36) = sd->head_dir;
- WBUFL (buf, 38) = sd->status.guild_id;
- WBUFW (buf, 42) = sd->guild_emblem_id;
- WBUFW (buf, 44) = sd->status.manner;
- WBUFW (buf, 46) = sd->opt3;
- WBUFB (buf, 48) = sd->status.karma;
- WBUFB (buf, 49) = sd->sex;
- WBUFPOS2 (buf, 50, sd->bl.x, sd->bl.y, sd->to_x, sd->to_y);
- WBUFW (buf, 55) = pc_isGM (sd) == 60 ? 0x80 : 0;
- WBUFB (buf, 57) = 5;
- WBUFW (buf, 58) = 0;
-
- return packet_len_table[0x1da];
-}
-
-/*==========================================
- * クラスãƒã‚§ãƒ³ã‚¸ typeã¯Mobã®å ´åˆã¯1ã§ä»–ã¯0?
- *------------------------------------------
- */
-int clif_npc_class_change (struct block_list *bl, int npc_class, int type)
-{
- uint8_t buf[16];
-
- nullpo_retr (0, bl);
-
- if (npc_class >= MAX_PC_CLASS)
- {
- WBUFW (buf, 0) = 0x1b0;
- WBUFL (buf, 2) = bl->id;
- WBUFB (buf, 6) = type;
- WBUFL (buf, 7) = npc_class;
-
- clif_send (buf, packet_len_table[0x1b0], bl, AREA);
- }
- return 0;
-}
-
-/*==========================================
- *
- *------------------------------------------
- */
-int clif_mob_class_change (struct mob_data *md, int class_)
-{
- uint8_t buf[16];
- int view = mob_get_viewclass (class_);
-
- nullpo_retr (0, md);
-
- if (view >= MAX_PC_CLASS)
- {
- WBUFW (buf, 0) = 0x1b0;
- WBUFL (buf, 2) = md->bl.id;
- WBUFB (buf, 6) = 1;
- WBUFL (buf, 7) = view;
-
- clif_send (buf, packet_len_table[0x1b0], &md->bl, AREA);
- }
- return 0;
-}
-
-// mob equipment [Valaris]
-
-int clif_mob_equip (struct mob_data *md, int nameid)
-{
- unsigned char buf[16];
-
- nullpo_retr (0, md);
-
- memset (buf, 0, packet_len_table[0x1a4]);
-
- WBUFW (buf, 0) = 0x1a4;
- WBUFB (buf, 2) = 3;
- WBUFL (buf, 3) = md->bl.id;
- WBUFL (buf, 7) = nameid;
-
- clif_send (buf, packet_len_table[0x1a4], &md->bl, AREA);
-
- return 0;
+ WBUFW(buf, 20) = 0;
+ WBUFW(buf, 22) = sd->status.head_bottom;
+ WBUFL(buf, 24) = gettick().time_since_epoch().count();
+ WBUFW(buf, 28) = sd->status.head_top;
+ WBUFW(buf, 30) = sd->status.head_mid;
+ WBUFW(buf, 32) = sd->status.hair_color;
+ WBUFW(buf, 34) = sd->status.clothes_color;
+ WBUFW(buf, 36) = static_cast<uint8_t>(sd->head_dir);
+ WBUFL(buf, 38) = 0/*guild_id*/;
+ WBUFW(buf, 42) = 0/*guild_emblem_id*/;
+ WBUFW(buf, 44) = sd->status.manner;
+ WBUFW(buf, 46) = uint16_t(sd->opt3);
+ WBUFB(buf, 48) = sd->status.karma;
+ WBUFB(buf, 49) = sd->sex;
+ WBUFPOS2(buf, 50, sd->bl.x, sd->bl.y, sd->to_x, sd->to_y);
+ WBUFW(buf, 55) = pc_isGM(sd) == 60 ? 0x80 : 0;
+ WBUFB(buf, 57) = 5;
+ WBUFW(buf, 58) = 0;
+
+ return clif_parse_func_table[0x1da].len;
}
/*==========================================
* MOB表示1
*------------------------------------------
*/
-static int clif_mob0078 (struct mob_data *md, unsigned char *buf)
-{
- int level;
-
- memset (buf, 0, packet_len_table[0x78]);
-
- nullpo_retr (0, md);
-
- WBUFW (buf, 0) = 0x78;
- WBUFL (buf, 2) = md->bl.id;
- WBUFW (buf, 6) = battle_get_speed (&md->bl);
- WBUFW (buf, 8) = md->opt1;
- WBUFW (buf, 10) = md->opt2;
- WBUFW (buf, 12) = md->option;
- WBUFW (buf, 14) = mob_get_viewclass (md->mob_class);
- if ((mob_get_viewclass (md->mob_class) <= 23)
- || (mob_get_viewclass (md->mob_class) == 812)
- || (mob_get_viewclass (md->mob_class) >= 4001))
- {
- WBUFW (buf, 12) |= mob_db[md->mob_class].option;
- WBUFW (buf, 16) = mob_get_hair (md->mob_class);
- WBUFW (buf, 18) = mob_get_weapon (md->mob_class);
- WBUFW (buf, 20) = mob_get_head_buttom (md->mob_class);
- WBUFW (buf, 22) = mob_get_shield (md->mob_class);
- WBUFW (buf, 24) = mob_get_head_top (md->mob_class);
- WBUFW (buf, 26) = mob_get_head_mid (md->mob_class);
- WBUFW (buf, 28) = mob_get_hair_color (md->mob_class);
- WBUFW (buf, 30) = mob_get_clothes_color (md->mob_class); //Add for player monster dye - Valaris
- WBUFB (buf, 45) = mob_get_sex (md->mob_class);
- }
-
- if (md->mob_class >= 1285 && md->mob_class <= 1287)
- { // Added guardian emblems [Valaris]
- struct guild *g;
- struct guild_castle *gc = guild_mapname2gc (map[md->bl.m].name);
- if (gc && gc->guild_id > 0)
- {
- g = guild_search (gc->guild_id);
- if (g)
- {
- WBUFL (buf, 26) = gc->guild_id;
- WBUFL (buf, 22) = g->emblem_id;
- }
- }
- } // End addition
-
- WBUFPOS (buf, 46, md->bl.x, md->bl.y);
- WBUFB (buf, 48) |= md->dir & 0x0f;
- WBUFB (buf, 49) = 5;
- WBUFB (buf, 50) = 5;
- WBUFW (buf, 52) =
+static
+int clif_mob0078(struct mob_data *md, unsigned char *buf)
+{
+ int level;
+
+ memset(buf, 0, clif_parse_func_table[0x78].len);
+
+ nullpo_ret(md);
+
+ WBUFW(buf, 0) = 0x78;
+ WBUFL(buf, 2) = md->bl.id;
+ WBUFW(buf, 6) = static_cast<uint16_t>(battle_get_speed(&md->bl).count());
+ WBUFW(buf, 8) = static_cast<uint16_t>(md->opt1);
+ WBUFW(buf, 10) = static_cast<uint16_t>(md->opt2);
+ WBUFW(buf, 12) = static_cast<uint16_t>(md->option);
+ WBUFW(buf, 14) = md->mob_class;
+ // snip: stuff do do with disguise as a PC
+ WBUFPOS(buf, 46, md->bl.x, md->bl.y);
+ // work around ICE in gcc 4.6
+ uint8_t dir = static_cast<uint8_t>(md->dir);
+ WBUFB(buf, 48) |= dir;
+ WBUFB(buf, 49) = 5;
+ WBUFB(buf, 50) = 5;
+ WBUFW(buf, 52) =
((level =
- battle_get_lv (&md->bl)) >
+ battle_get_lv(&md->bl)) >
battle_config.max_lv) ? battle_config.max_lv : level;
- return packet_len_table[0x78];
+ return clif_parse_func_table[0x78].len;
}
/*==========================================
* MOB表示2
*------------------------------------------
*/
-static int clif_mob007b (struct mob_data *md, unsigned char *buf)
+static
+int clif_mob007b(struct mob_data *md, unsigned char *buf)
{
- int level;
+ int level;
- memset (buf, 0, packet_len_table[0x7b]);
+ memset(buf, 0, clif_parse_func_table[0x7b].len);
- nullpo_retr (0, md);
-
- WBUFW (buf, 0) = 0x7b;
- WBUFL (buf, 2) = md->bl.id;
- WBUFW (buf, 6) = battle_get_speed (&md->bl);
- WBUFW (buf, 8) = md->opt1;
- WBUFW (buf, 10) = md->opt2;
- WBUFW (buf, 12) = md->option;
- WBUFW (buf, 14) = mob_get_viewclass (md->mob_class);
- if ((mob_get_viewclass (md->mob_class) < 24)
- || (mob_get_viewclass (md->mob_class) > 4000))
- {
- WBUFW (buf, 12) |= mob_db[md->mob_class].option;
- WBUFW (buf, 16) = mob_get_hair (md->mob_class);
- WBUFW (buf, 18) = mob_get_weapon (md->mob_class);
- WBUFW (buf, 20) = mob_get_head_buttom (md->mob_class);
- WBUFL (buf, 22) = gettick ();
- WBUFW (buf, 26) = mob_get_shield (md->mob_class);
- WBUFW (buf, 28) = mob_get_head_top (md->mob_class);
- WBUFW (buf, 30) = mob_get_head_mid (md->mob_class);
- WBUFW (buf, 32) = mob_get_hair_color (md->mob_class);
- WBUFW (buf, 34) = mob_get_clothes_color (md->mob_class); //Add for player monster dye - Valaris
- WBUFB (buf, 49) = mob_get_sex (md->mob_class);
- }
- else
- WBUFL (buf, 22) = gettick ();
+ nullpo_ret(md);
- if (md->mob_class >= 1285 && md->mob_class <= 1287)
- { // Added guardian emblems [Valaris]
- struct guild *g;
- struct guild_castle *gc = guild_mapname2gc (map[md->bl.m].name);
- if (gc && gc->guild_id > 0)
- {
- g = guild_search (gc->guild_id);
- if (g)
- {
- WBUFL (buf, 28) = gc->guild_id;
- WBUFL (buf, 24) = g->emblem_id;
- }
- }
- } // End addition
+ WBUFW(buf, 0) = 0x7b;
+ WBUFL(buf, 2) = md->bl.id;
+ WBUFW(buf, 6) = static_cast<uint16_t>(battle_get_speed(&md->bl).count());
+ WBUFW(buf, 8) = static_cast<uint16_t>(md->opt1);
+ WBUFW(buf, 10) = static_cast<uint16_t>(md->opt2);
+ WBUFW(buf, 12) = static_cast<uint16_t>(md->option);
+ WBUFW(buf, 14) = md->mob_class;
+ // snip: stuff for monsters disguised as PCs
+ WBUFL(buf, 22) = gettick().time_since_epoch().count();
- WBUFPOS2 (buf, 50, md->bl.x, md->bl.y, md->to_x, md->to_y);
- WBUFB (buf, 56) = 5;
- WBUFB (buf, 57) = 5;
- WBUFW (buf, 58) =
+ WBUFPOS2(buf, 50, md->bl.x, md->bl.y, md->to_x, md->to_y);
+ WBUFB(buf, 56) = 5;
+ WBUFB(buf, 57) = 5;
+ WBUFW(buf, 58) =
((level =
- battle_get_lv (&md->bl)) >
+ battle_get_lv(&md->bl)) >
battle_config.max_lv) ? battle_config.max_lv : level;
- return packet_len_table[0x7b];
+ return clif_parse_func_table[0x7b].len;
}
/*==========================================
*
*------------------------------------------
*/
-static int clif_npc0078 (struct npc_data *nd, unsigned char *buf)
+static
+int clif_npc0078(struct npc_data *nd, unsigned char *buf)
{
- struct guild *g;
-
- nullpo_retr (0, nd);
-
- memset (buf, 0, packet_len_table[0x78]);
-
- WBUFW (buf, 0) = 0x78;
- WBUFL (buf, 2) = nd->bl.id;
- WBUFW (buf, 6) = nd->speed;
- WBUFW (buf, 14) = nd->npc_class;
- if ((nd->npc_class == 722) && (nd->u.scr.guild_id > 0)
- && ((g = guild_search (nd->u.scr.guild_id)) != NULL))
- {
- WBUFL (buf, 22) = g->emblem_id;
- WBUFL (buf, 26) = g->guild_id;
- }
- WBUFPOS (buf, 46, nd->bl.x, nd->bl.y);
- WBUFB (buf, 48) |= nd->dir & 0x0f;
- WBUFB (buf, 49) = 5;
- WBUFB (buf, 50) = 5;
+ nullpo_ret(nd);
- return packet_len_table[0x78];
-}
+ memset(buf, 0, clif_parse_func_table[0x78].len);
-/*==========================================
- *
- *------------------------------------------
- */
-static int clif_set01e1 (struct map_session_data *sd, unsigned char *buf)
-{
- nullpo_retr (0, sd);
+ WBUFW(buf, 0) = 0x78;
+ WBUFL(buf, 2) = nd->bl.id;
+ WBUFW(buf, 6) = static_cast<uint16_t>(nd->speed.count());
+ WBUFW(buf, 14) = nd->npc_class;
+ WBUFPOS(buf, 46, nd->bl.x, nd->bl.y);
+ // work around ICE in gcc 4.6
+ uint8_t dir = static_cast<uint8_t>(nd->dir);
+ WBUFB(buf, 48) |= dir;
+ WBUFB(buf, 49) = 5;
+ WBUFB(buf, 50) = 5;
- WBUFW (buf, 0) = 0x1e1;
- WBUFL (buf, 2) = sd->bl.id;
- WBUFW (buf, 6) = sd->spiritball;
-
- return packet_len_table[0x1e1];
-}
-
-/*==========================================
- *
- *------------------------------------------
- */
-static int clif_set0192 (int fd, int m, int x, int y, int type)
-{
- WFIFOW (fd, 0) = 0x192;
- WFIFOW (fd, 2) = x;
- WFIFOW (fd, 4) = y;
- WFIFOW (fd, 6) = type;
- memcpy (WFIFOP (fd, 8), map[m].name, 16);
- WFIFOSET (fd, packet_len_table[0x192]);
-
- return 0;
+ return clif_parse_func_table[0x78].len;
}
/* These indices are derived from equip_pos in pc.c and some guesswork */
-static int equip_points[LOOK_LAST + 1] = {
- -1, /* 0: base */
- -1, /* 1: hair */
- 9, /* 2: weapon */
- 4, /* 3: head botom -- leg armour */
- 6, /* 4: head top -- hat */
- 5, /* 5: head mid -- torso armour */
- -1, /* 6: hair colour */
- -1, /* 6: clothes colour */
- 8, /* 6: shield */
- 2, /* 9: shoes */
- 3, /* gloves */
- 1, /* cape */
- 7, /* misc1 */
- 0, /* misc2 */
-};
+static
+earray<EQUIP, LOOK, LOOK::COUNT> equip_points //=
+{{
+ EQUIP::NONE, // base
+ EQUIP::NONE, // hair
+ EQUIP::WEAPON, // weapon
+ EQUIP::LEGS, // head botom -- leg armour
+ EQUIP::HAT, // head top -- hat
+ EQUIP::TORSO, // head mid -- torso armour
+ EQUIP::NONE, // hair colour
+ EQUIP::NONE, // clothes colour
+ EQUIP::SHIELD, // shield
+ EQUIP::SHOES, // shoes
+ EQUIP::GLOVES, // gloves
+ EQUIP::CAPE, // cape
+ EQUIP::MISC1, // misc1
+ EQUIP::MISC2, // misc2
+}};
/*==========================================
*
*------------------------------------------
*/
-int clif_spawnpc (struct map_session_data *sd)
+int clif_spawnpc(struct map_session_data *sd)
{
unsigned char buf[128];
- nullpo_retr (0, sd);
-
- if (sd->disguise > 23 && sd->disguise < 4001)
- { // mob disguises [Valaris]
- clif_clearchar (&sd->bl, 9);
-
- memset (buf, 0, packet_len_table[0x119]);
-
- WBUFW (buf, 0) = 0x119;
- WBUFL (buf, 2) = sd->bl.id;
- WBUFW (buf, 6) = 0;
- WBUFW (buf, 8) = 0;
- WBUFW (buf, 10) = 0x40;
- WBUFB (buf, 12) = 0;
-
- clif_send (buf, packet_len_table[0x119], &sd->bl, SELF);
-
- memset (buf, 0, packet_len_table[0x7c]);
-
- WBUFW (buf, 0) = 0x7c;
- WBUFL (buf, 2) = sd->bl.id;
- WBUFW (buf, 6) = sd->speed;
- WBUFW (buf, 8) = sd->opt1;
- WBUFW (buf, 10) = sd->opt2;
- WBUFW (buf, 12) = sd->status.option;
- WBUFW (buf, 20) = sd->disguise;
- WBUFPOS (buf, 36, sd->bl.x, sd->bl.y);
- clif_send (buf, packet_len_table[0x7c], &sd->bl, AREA);
- }
-
- clif_set0078 (sd, buf);
-
- WBUFW (buf, 0) = 0x1d9;
- WBUFW (buf, 51) = 0;
- clif_send (buf, packet_len_table[0x1d9], &sd->bl, AREA_WOS);
-
- if (sd->spiritball > 0)
- clif_spiritball (sd);
+ nullpo_ret(sd);
- if (sd->status.guild_id > 0)
- { // force display of guild emblem [Valaris]
- struct guild *g = guild_search (sd->status.guild_id);
- if (g)
- clif_guild_emblem (sd, g);
- } // end addition [Valaris]
+ clif_set0078(sd, buf);
- if (sd->status.pc_class == 13 || sd->status.pc_class == 21
- || sd->status.pc_class == 4014 || sd->status.pc_class == 4022)
- pc_setoption (sd, sd->status.option | 0x0020); // [Valaris]
-
- if ((pc_isriding (sd) && pc_checkskill (sd, KN_RIDING) > 0)
- && (sd->status.pc_class == 7 || sd->status.pc_class == 14
- || sd->status.pc_class == 4008 || sd->status.pc_class == 4015))
- pc_setriding (sd); // update peco riders for people upgrading athena [Valaris]
+ WBUFW(buf, 0) = 0x1d9;
+ WBUFW(buf, 51) = 0;
+ clif_send(buf, clif_parse_func_table[0x1d9].len, &sd->bl, SendWho::AREA_WOS);
if (map[sd->bl.m].flag.snow)
- clif_specialeffect (&sd->bl, 162, 1);
+ clif_specialeffect(&sd->bl, 162, 1);
if (map[sd->bl.m].flag.fog)
- clif_specialeffect (&sd->bl, 233, 1);
+ clif_specialeffect(&sd->bl, 233, 1);
if (map[sd->bl.m].flag.sakura)
- clif_specialeffect (&sd->bl, 163, 1);
+ clif_specialeffect(&sd->bl, 163, 1);
if (map[sd->bl.m].flag.leaves)
- clif_specialeffect (&sd->bl, 333, 1);
+ clif_specialeffect(&sd->bl, 333, 1);
if (map[sd->bl.m].flag.rain)
- clif_specialeffect (&sd->bl, 161, 1);
+ clif_specialeffect(&sd->bl, 161, 1);
// clif_changelook_accessories(&sd->bl, NULL);
@@ -1329,66 +954,65 @@ int clif_spawnpc (struct map_session_data *sd)
*
*------------------------------------------
*/
-int clif_spawnnpc (struct npc_data *nd)
+int clif_spawnnpc(struct npc_data *nd)
{
unsigned char buf[64];
- int len;
+ int len;
- nullpo_retr (0, nd);
+ nullpo_ret(nd);
if (nd->npc_class < 0 || nd->flag & 1 || nd->npc_class == INVISIBLE_CLASS)
return 0;
- memset (buf, 0, packet_len_table[0x7c]);
+ memset(buf, 0, clif_parse_func_table[0x7c].len);
- WBUFW (buf, 0) = 0x7c;
- WBUFL (buf, 2) = nd->bl.id;
- WBUFW (buf, 6) = nd->speed;
- WBUFW (buf, 20) = nd->npc_class;
- WBUFPOS (buf, 36, nd->bl.x, nd->bl.y);
+ WBUFW(buf, 0) = 0x7c;
+ WBUFL(buf, 2) = nd->bl.id;
+ WBUFW(buf, 6) = static_cast<uint16_t>(nd->speed.count());
+ WBUFW(buf, 20) = nd->npc_class;
+ WBUFPOS(buf, 36, nd->bl.x, nd->bl.y);
- clif_send (buf, packet_len_table[0x7c], &nd->bl, AREA);
+ clif_send(buf, clif_parse_func_table[0x7c].len, &nd->bl, SendWho::AREA);
- len = clif_npc0078 (nd, buf);
- clif_send (buf, len, &nd->bl, AREA);
+ len = clif_npc0078(nd, buf);
+ clif_send(buf, len, &nd->bl, SendWho::AREA);
return 0;
}
-int
-clif_spawn_fake_npc_for_player (struct map_session_data *sd, int fake_npc_id)
+int clif_spawn_fake_npc_for_player(struct map_session_data *sd, int fake_npc_id)
{
- int fd;
+ int fd;
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
fd = sd->fd;
if (!fd)
return 0;
- WFIFOW (fd, 0) = 0x7c;
- WFIFOL (fd, 2) = fake_npc_id;
- WFIFOW (fd, 6) = 0;
- WFIFOW (fd, 8) = 0;
- WFIFOW (fd, 10) = 0;
- WFIFOW (fd, 12) = 0;
- WFIFOW (fd, 20) = 127;
- WFIFOPOS (fd, 36, sd->bl.x, sd->bl.y);
- WFIFOSET (fd, packet_len_table[0x7c]);
-
- WFIFOW (fd, 0) = 0x78;
- WFIFOL (fd, 2) = fake_npc_id;
- WFIFOW (fd, 6) = 0;
- WFIFOW (fd, 8) = 0;
- WFIFOW (fd, 10) = 0;
- WFIFOW (fd, 12) = 0;
- WFIFOW (fd, 14) = 127; // identifies as NPC
- WFIFOW (fd, 20) = 127;
- WFIFOPOS (fd, 46, sd->bl.x, sd->bl.y);
- WFIFOPOS (fd, 36, sd->bl.x, sd->bl.y);
- WFIFOB (fd, 49) = 5;
- WFIFOB (fd, 50) = 5;
- WFIFOSET (fd, packet_len_table[0x78]);
+ WFIFOW(fd, 0) = 0x7c;
+ WFIFOL(fd, 2) = fake_npc_id;
+ WFIFOW(fd, 6) = 0;
+ WFIFOW(fd, 8) = 0;
+ WFIFOW(fd, 10) = 0;
+ WFIFOW(fd, 12) = 0;
+ WFIFOW(fd, 20) = 127;
+ WFIFOPOS(fd, 36, sd->bl.x, sd->bl.y);
+ WFIFOSET(fd, clif_parse_func_table[0x7c].len);
+
+ WFIFOW(fd, 0) = 0x78;
+ WFIFOL(fd, 2) = fake_npc_id;
+ WFIFOW(fd, 6) = 0;
+ WFIFOW(fd, 8) = 0;
+ WFIFOW(fd, 10) = 0;
+ WFIFOW(fd, 12) = 0;
+ WFIFOW(fd, 14) = 127; // identifies as NPC
+ WFIFOW(fd, 20) = 127;
+ WFIFOPOS(fd, 46, sd->bl.x, sd->bl.y);
+ WFIFOPOS(fd, 36, sd->bl.x, sd->bl.y);
+ WFIFOB(fd, 49) = 5;
+ WFIFOB(fd, 50) = 5;
+ WFIFOSET(fd, clif_parse_func_table[0x78].len);
return 0;
}
@@ -1397,33 +1021,29 @@ clif_spawn_fake_npc_for_player (struct map_session_data *sd, int fake_npc_id)
*
*------------------------------------------
*/
-int clif_spawnmob (struct mob_data *md)
+int clif_spawnmob(struct mob_data *md)
{
unsigned char buf[64];
- int len;
+ int len;
- nullpo_retr (0, md);
+ nullpo_ret(md);
- if (mob_get_viewclass (md->mob_class) > 23)
{
- memset (buf, 0, packet_len_table[0x7c]);
-
- WBUFW (buf, 0) = 0x7c;
- WBUFL (buf, 2) = md->bl.id;
- WBUFW (buf, 6) = md->stats[MOB_SPEED];
- WBUFW (buf, 8) = md->opt1;
- WBUFW (buf, 10) = md->opt2;
- WBUFW (buf, 12) = md->option;
- WBUFW (buf, 20) = mob_get_viewclass (md->mob_class);
- WBUFPOS (buf, 36, md->bl.x, md->bl.y);
- clif_send (buf, packet_len_table[0x7c], &md->bl, AREA);
- }
+ memset(buf, 0, clif_parse_func_table[0x7c].len);
- len = clif_mob0078 (md, buf);
- clif_send (buf, len, &md->bl, AREA);
+ WBUFW(buf, 0) = 0x7c;
+ WBUFL(buf, 2) = md->bl.id;
+ WBUFW(buf, 6) = md->stats[mob_stat::SPEED];
+ WBUFW(buf, 8) = uint16_t(md->opt1);
+ WBUFW(buf, 10) = uint16_t(md->opt2);
+ WBUFW(buf, 12) = uint16_t(md->option);
+ WBUFW(buf, 20) = md->mob_class;
+ WBUFPOS(buf, 36, md->bl.x, md->bl.y);
+ clif_send(buf, clif_parse_func_table[0x7c].len, &md->bl, SendWho::AREA);
+ }
- if (mob_get_equip (md->mob_class) > 0) // mob equipment [Valaris]
- clif_mob_equip (md, mob_get_equip (md->mob_class));
+ len = clif_mob0078(md, buf);
+ clif_send(buf, len, &md->bl, SendWho::AREA);
return 0;
}
@@ -1433,16 +1053,16 @@ int clif_spawnmob (struct mob_data *md)
*------------------------------------------
*/
static
-int clif_servertick (struct map_session_data *sd)
+int clif_servertick(struct map_session_data *sd)
{
- int fd;
+ int fd;
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
fd = sd->fd;
- WFIFOW (fd, 0) = 0x7f;
- WFIFOL (fd, 2) = sd->server_tick;
- WFIFOSET (fd, packet_len_table[0x7f]);
+ WFIFOW(fd, 0) = 0x7f;
+ WFIFOL(fd, 2) = sd->server_tick.time_since_epoch().count();
+ WFIFOSET(fd, clif_parse_func_table[0x7f].len);
return 0;
}
@@ -1451,18 +1071,18 @@ int clif_servertick (struct map_session_data *sd)
*
*------------------------------------------
*/
-int clif_walkok (struct map_session_data *sd)
+int clif_walkok(struct map_session_data *sd)
{
- int fd;
+ int fd;
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
fd = sd->fd;
- WFIFOW (fd, 0) = 0x87;
- WFIFOL (fd, 2) = gettick ();;
- WFIFOPOS2 (fd, 6, sd->bl.x, sd->bl.y, sd->to_x, sd->to_y);
- WFIFOB (fd, 11) = 0;
- WFIFOSET (fd, packet_len_table[0x87]);
+ WFIFOW(fd, 0) = 0x87;
+ WFIFOL(fd, 2) = gettick().time_since_epoch().count();
+ WFIFOPOS2(fd, 6, sd->bl.x, sd->bl.y, sd->to_x, sd->to_y);
+ WFIFOB(fd, 11) = 0;
+ WFIFOSET(fd, clif_parse_func_table[0x87].len);
return 0;
}
@@ -1471,28 +1091,19 @@ int clif_walkok (struct map_session_data *sd)
*
*------------------------------------------
*/
-int clif_movechar (struct map_session_data *sd)
+int clif_movechar(struct map_session_data *sd)
{
- int fd;
- int len;
+ int len;
unsigned char buf[256];
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
- fd = sd->fd;
+ len = clif_set007b(sd, buf);
- len = clif_set007b (sd, buf);
-
- if (sd->disguise > 23 && sd->disguise < 4001)
- {
- clif_send (buf, len, &sd->bl, AREA);
- return 0;
- }
- else
- clif_send (buf, len, &sd->bl, AREA_WOS);
+ clif_send(buf, len, &sd->bl, SendWho::AREA_WOS);
if (battle_config.save_clothcolor == 1 && sd->status.clothes_color > 0)
- clif_changelook (&sd->bl, LOOK_CLOTHES_COLOR,
+ clif_changelook(&sd->bl, LOOK::CLOTHES_COLOR,
sd->status.clothes_color);
return 0;
@@ -1503,17 +1114,20 @@ int clif_movechar (struct map_session_data *sd)
*------------------------------------------
*/
static
-void clif_quitsave (int fd, struct map_session_data *sd)
+void clif_quitsave(int, struct map_session_data *sd)
{
- map_quit (sd);
+ map_quit(sd);
}
/*==========================================
*
*------------------------------------------
*/
-static void clif_waitclose (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data)
+static
+void clif_waitclose(TimerData *, tick_t, int id)
{
+ // TODO: what happens if the player disconnects
+ // and someone else connects?
if (session[id])
session[id]->eof = 1;
}
@@ -1522,31 +1136,31 @@ static void clif_waitclose (timer_id tid, tick_t tick, custom_id_t id, custom_da
*
*------------------------------------------
*/
-void clif_setwaitclose (int fd)
+void clif_setwaitclose(int fd)
{
- add_timer (gettick () + 5000, clif_waitclose, fd, 0);
+ Timer(gettick() + std::chrono::seconds(5),
+ std::bind(clif_waitclose, ph::_1, ph::_2,
+ fd)
+ ).detach();
}
/*==========================================
*
*------------------------------------------
*/
-int clif_changemap (struct map_session_data *sd, const char *mapname, int x, int y)
+int clif_changemap(struct map_session_data *sd, const char *mapname, int x, int y)
{
- int fd;
+ int fd;
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
fd = sd->fd;
- WFIFOW (fd, 0) = 0x91;
- memcpy (WFIFOP (fd, 2), mapname, 16);
- WFIFOW (fd, 18) = x;
- WFIFOW (fd, 20) = y;
- WFIFOSET (fd, packet_len_table[0x91]);
-
- if (sd->disguise > 23 && sd->disguise < 4001) // mob disguises [Valaris]
- clif_spawnpc (sd);
+ WFIFOW(fd, 0) = 0x91;
+ memcpy(WFIFOP(fd, 2), mapname, 16);
+ WFIFOW(fd, 18) = x;
+ WFIFOW(fd, 20) = y;
+ WFIFOSET(fd, clif_parse_func_table[0x91].len);
return 0;
}
@@ -1555,21 +1169,21 @@ int clif_changemap (struct map_session_data *sd, const char *mapname, int x, int
*
*------------------------------------------
*/
-int clif_changemapserver (struct map_session_data *sd, const char *mapname, int x,
+int clif_changemapserver(struct map_session_data *sd, const char *mapname, int x,
int y, struct in_addr ip, int port)
{
- int fd;
+ int fd;
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
fd = sd->fd;
- WFIFOW (fd, 0) = 0x92;
- memcpy (WFIFOP (fd, 2), mapname, 16);
- WFIFOW (fd, 18) = x;
- WFIFOW (fd, 20) = y;
- WFIFOL (fd, 22) = ip.s_addr;
- WFIFOW (fd, 26) = port;
- WFIFOSET (fd, packet_len_table[0x92]);
+ WFIFOW(fd, 0) = 0x92;
+ memcpy(WFIFOP(fd, 2), mapname, 16);
+ WFIFOW(fd, 18) = x;
+ WFIFOW(fd, 20) = y;
+ WFIFOL(fd, 22) = ip.s_addr;
+ WFIFOW(fd, 26) = port;
+ WFIFOSET(fd, clif_parse_func_table[0x92].len);
return 0;
}
@@ -1578,18 +1192,18 @@ int clif_changemapserver (struct map_session_data *sd, const char *mapname, int
*
*------------------------------------------
*/
-int clif_fixpos (struct block_list *bl)
+int clif_fixpos(struct block_list *bl)
{
uint8_t buf[16];
- nullpo_retr (0, bl);
+ nullpo_ret(bl);
- WBUFW (buf, 0) = 0x88;
- WBUFL (buf, 2) = bl->id;
- WBUFW (buf, 6) = bl->x;
- WBUFW (buf, 8) = bl->y;
+ WBUFW(buf, 0) = 0x88;
+ WBUFL(buf, 2) = bl->id;
+ WBUFW(buf, 6) = bl->x;
+ WBUFW(buf, 8) = bl->y;
- clif_send (buf, packet_len_table[0x88], bl, AREA);
+ clif_send(buf, clif_parse_func_table[0x88].len, bl, SendWho::AREA);
return 0;
}
@@ -1598,16 +1212,16 @@ int clif_fixpos (struct block_list *bl)
*
*------------------------------------------
*/
-int clif_npcbuysell (struct map_session_data *sd, int id)
+int clif_npcbuysell(struct map_session_data *sd, int id)
{
- int fd;
+ int fd;
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
fd = sd->fd;
- WFIFOW (fd, 0) = 0xc4;
- WFIFOL (fd, 2) = id;
- WFIFOSET (fd, packet_len_table[0xc4]);
+ WFIFOW(fd, 0) = 0xc4;
+ WFIFOL(fd, 2) = id;
+ WFIFOSET(fd, clif_parse_func_table[0xc4].len);
return 0;
}
@@ -1616,32 +1230,30 @@ int clif_npcbuysell (struct map_session_data *sd, int id)
*
*------------------------------------------
*/
-int clif_buylist (struct map_session_data *sd, struct npc_data *nd)
+int clif_buylist(struct map_session_data *sd, struct npc_data *nd)
{
struct item_data *id;
- int fd, i, val;
+ int fd, i, val;
- nullpo_retr (0, sd);
- nullpo_retr (0, nd);
+ nullpo_ret(sd);
+ nullpo_ret(nd);
fd = sd->fd;
- WFIFOW (fd, 0) = 0xc6;
+ WFIFOW(fd, 0) = 0xc6;
for (i = 0; nd->u.shop_item[i].nameid > 0; i++)
{
- id = itemdb_search (nd->u.shop_item[i].nameid);
+ id = itemdb_search(nd->u.shop_item[i].nameid);
val = nd->u.shop_item[i].value;
- WFIFOL (fd, 4 + i * 11) = val;
- if (!id->flag.value_notdc)
- val = pc_modifybuyvalue (sd, val);
- WFIFOL (fd, 8 + i * 11) = val;
- WFIFOB (fd, 12 + i * 11) = id->type;
+ WFIFOL(fd, 4 + i * 11) = val; // base price
+ WFIFOL(fd, 8 + i * 11) = val; // actual price
+ WFIFOB(fd, 12 + i * 11) = uint8_t(id->type);
if (id->view_id > 0)
- WFIFOW (fd, 13 + i * 11) = id->view_id;
+ WFIFOW(fd, 13 + i * 11) = id->view_id;
else
- WFIFOW (fd, 13 + i * 11) = nd->u.shop_item[i].nameid;
+ WFIFOW(fd, 13 + i * 11) = nd->u.shop_item[i].nameid;
}
- WFIFOW (fd, 2) = i * 11 + 4;
- WFIFOSET (fd, WFIFOW (fd, 2));
+ WFIFOW(fd, 2) = i * 11 + 4;
+ WFIFOSET(fd, WFIFOW(fd, 2));
return 0;
}
@@ -1650,14 +1262,14 @@ int clif_buylist (struct map_session_data *sd, struct npc_data *nd)
*
*------------------------------------------
*/
-int clif_selllist (struct map_session_data *sd)
+int clif_selllist(struct map_session_data *sd)
{
- int fd, i, c = 0, val;
+ int fd, i, c = 0, val;
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
fd = sd->fd;
- WFIFOW (fd, 0) = 0xc7;
+ WFIFOW(fd, 0) = 0xc7;
for (i = 0; i < MAX_INVENTORY; i++)
{
if (sd->status.inventory[i].nameid > 0 && sd->inventory_data[i])
@@ -1665,16 +1277,14 @@ int clif_selllist (struct map_session_data *sd)
val = sd->inventory_data[i]->value_sell;
if (val < 0)
continue;
- WFIFOW (fd, 4 + c * 10) = i + 2;
- WFIFOL (fd, 6 + c * 10) = val;
- if (!sd->inventory_data[i]->flag.value_notoc)
- val = pc_modifysellvalue (sd, val);
- WFIFOL (fd, 10 + c * 10) = val;
+ WFIFOW(fd, 4 + c * 10) = i + 2;
+ WFIFOL(fd, 6 + c * 10) = val; // base price
+ WFIFOL(fd, 10 + c * 10) = val; // actual price
c++;
}
}
- WFIFOW (fd, 2) = c * 10 + 4;
- WFIFOSET (fd, WFIFOW (fd, 2));
+ WFIFOW(fd, 2) = c * 10 + 4;
+ WFIFOSET(fd, WFIFOW(fd, 2));
return 0;
}
@@ -1683,18 +1293,18 @@ int clif_selllist (struct map_session_data *sd)
*
*------------------------------------------
*/
-int clif_scriptmes (struct map_session_data *sd, int npcid, const char *mes)
+int clif_scriptmes(struct map_session_data *sd, int npcid, const char *mes)
{
- int fd;
+ int fd;
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
fd = sd->fd;
- WFIFOW (fd, 0) = 0xb4;
- WFIFOW (fd, 2) = strlen (mes) + 9;
- WFIFOL (fd, 4) = npcid;
- strcpy ((char *)WFIFOP (fd, 8), mes);
- WFIFOSET (fd, WFIFOW (fd, 2));
+ WFIFOW(fd, 0) = 0xb4;
+ WFIFOW(fd, 2) = strlen(mes) + 9;
+ WFIFOL(fd, 4) = npcid;
+ strcpy((char *)WFIFOP(fd, 8), mes);
+ WFIFOSET(fd, WFIFOW(fd, 2));
return 0;
}
@@ -1703,16 +1313,16 @@ int clif_scriptmes (struct map_session_data *sd, int npcid, const char *mes)
*
*------------------------------------------
*/
-int clif_scriptnext (struct map_session_data *sd, int npcid)
+int clif_scriptnext(struct map_session_data *sd, int npcid)
{
- int fd;
+ int fd;
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
fd = sd->fd;
- WFIFOW (fd, 0) = 0xb5;
- WFIFOL (fd, 2) = npcid;
- WFIFOSET (fd, packet_len_table[0xb5]);
+ WFIFOW(fd, 0) = 0xb5;
+ WFIFOL(fd, 2) = npcid;
+ WFIFOSET(fd, clif_parse_func_table[0xb5].len);
return 0;
}
@@ -1721,16 +1331,16 @@ int clif_scriptnext (struct map_session_data *sd, int npcid)
*
*------------------------------------------
*/
-int clif_scriptclose (struct map_session_data *sd, int npcid)
+int clif_scriptclose(struct map_session_data *sd, int npcid)
{
- int fd;
+ int fd;
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
fd = sd->fd;
- WFIFOW (fd, 0) = 0xb6;
- WFIFOL (fd, 2) = npcid;
- WFIFOSET (fd, packet_len_table[0xb6]);
+ WFIFOW(fd, 0) = 0xb6;
+ WFIFOL(fd, 2) = npcid;
+ WFIFOSET(fd, clif_parse_func_table[0xb6].len);
return 0;
}
@@ -1739,18 +1349,18 @@ int clif_scriptclose (struct map_session_data *sd, int npcid)
*
*------------------------------------------
*/
-int clif_scriptmenu (struct map_session_data *sd, int npcid, const char *mes)
+int clif_scriptmenu(struct map_session_data *sd, int npcid, const char *mes)
{
- int fd;
+ int fd;
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
fd = sd->fd;
- WFIFOW (fd, 0) = 0xb7;
- WFIFOW (fd, 2) = strlen (mes) + 8;
- WFIFOL (fd, 4) = npcid;
- strcpy ((char *)WFIFOP (fd, 8), mes);
- WFIFOSET (fd, WFIFOW (fd, 2));
+ WFIFOW(fd, 0) = 0xb7;
+ WFIFOW(fd, 2) = strlen(mes) + 8;
+ WFIFOL(fd, 4) = npcid;
+ strcpy((char *)WFIFOP(fd, 8), mes);
+ WFIFOSET(fd, WFIFOW(fd, 2));
return 0;
}
@@ -1759,16 +1369,16 @@ int clif_scriptmenu (struct map_session_data *sd, int npcid, const char *mes)
*
*------------------------------------------
*/
-int clif_scriptinput (struct map_session_data *sd, int npcid)
+int clif_scriptinput(struct map_session_data *sd, int npcid)
{
- int fd;
+ int fd;
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
fd = sd->fd;
- WFIFOW (fd, 0) = 0x142;
- WFIFOL (fd, 2) = npcid;
- WFIFOSET (fd, packet_len_table[0x142]);
+ WFIFOW(fd, 0) = 0x142;
+ WFIFOL(fd, 2) = npcid;
+ WFIFOSET(fd, clif_parse_func_table[0x142].len);
return 0;
}
@@ -1777,16 +1387,16 @@ int clif_scriptinput (struct map_session_data *sd, int npcid)
*
*------------------------------------------
*/
-int clif_scriptinputstr (struct map_session_data *sd, int npcid)
+int clif_scriptinputstr(struct map_session_data *sd, int npcid)
{
- int fd;
+ int fd;
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
fd = sd->fd;
- WFIFOW (fd, 0) = 0x1d4;
- WFIFOL (fd, 2) = npcid;
- WFIFOSET (fd, packet_len_table[0x1d4]);
+ WFIFOW(fd, 0) = 0x1d4;
+ WFIFOL(fd, 2) = npcid;
+ WFIFOSET(fd, clif_parse_func_table[0x1d4].len);
return 0;
}
@@ -1795,22 +1405,22 @@ int clif_scriptinputstr (struct map_session_data *sd, int npcid)
*
*------------------------------------------
*/
-int clif_viewpoint (struct map_session_data *sd, int npc_id, int type, int x,
+int clif_viewpoint(struct map_session_data *sd, int npc_id, int type, int x,
int y, int id, int color)
{
- int fd;
+ int fd;
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
fd = sd->fd;
- WFIFOW (fd, 0) = 0x144;
- WFIFOL (fd, 2) = npc_id;
- WFIFOL (fd, 6) = type;
- WFIFOL (fd, 10) = x;
- WFIFOL (fd, 14) = y;
- WFIFOB (fd, 18) = id;
- WFIFOL (fd, 19) = color;
- WFIFOSET (fd, packet_len_table[0x144]);
+ WFIFOW(fd, 0) = 0x144;
+ WFIFOL(fd, 2) = npc_id;
+ WFIFOL(fd, 6) = type;
+ WFIFOL(fd, 10) = x;
+ WFIFOL(fd, 14) = y;
+ WFIFOB(fd, 18) = id;
+ WFIFOL(fd, 19) = color;
+ WFIFOSET(fd, clif_parse_func_table[0x144].len);
return 0;
}
@@ -1819,17 +1429,17 @@ int clif_viewpoint (struct map_session_data *sd, int npc_id, int type, int x,
*
*------------------------------------------
*/
-int clif_cutin (struct map_session_data *sd, const char *image, int type)
+int clif_cutin(struct map_session_data *sd, const char *image, int type)
{
- int fd;
+ int fd;
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
fd = sd->fd;
- WFIFOW (fd, 0) = 0x1b3;
- memcpy (WFIFOP (fd, 2), image, 64);
- WFIFOB (fd, 66) = type;
- WFIFOSET (fd, packet_len_table[0x1b3]);
+ WFIFOW(fd, 0) = 0x1b3;
+ memcpy(WFIFOP(fd, 2), image, 64);
+ WFIFOB(fd, 66) = type;
+ WFIFOSET(fd, clif_parse_func_table[0x1b3].len);
return 0;
}
@@ -1838,31 +1448,27 @@ int clif_cutin (struct map_session_data *sd, const char *image, int type)
*
*------------------------------------------
*/
-int clif_additem (struct map_session_data *sd, int n, int amount, int fail)
+int clif_additem(struct map_session_data *sd, int n, int amount, PickupFail fail)
{
- int fd, j;
- unsigned char *buf;
+ nullpo_ret(sd);
- nullpo_retr (0, sd);
-
- fd = sd->fd;
- buf = WFIFOP (fd, 0);
- if (fail)
+ int fd = sd->fd;
+ if (fail != PickupFail::OKAY)
{
- WBUFW (buf, 0) = 0xa0;
- WBUFW (buf, 2) = n + 2;
- WBUFW (buf, 4) = amount;
- WBUFW (buf, 6) = 0;
- WBUFB (buf, 8) = 0;
- WBUFB (buf, 9) = 0;
- WBUFB (buf, 10) = 0;
- WBUFW (buf, 11) = 0;
- WBUFW (buf, 13) = 0;
- WBUFW (buf, 15) = 0;
- WBUFW (buf, 17) = 0;
- WBUFW (buf, 19) = 0;
- WBUFB (buf, 21) = 0;
- WBUFB (buf, 22) = fail;
+ WFIFOW(fd, 0) = 0xa0;
+ WFIFOW(fd, 2) = n + 2;
+ WFIFOW(fd, 4) = amount;
+ WFIFOW(fd, 6) = 0;
+ WFIFOB(fd, 8) = 0;
+ WFIFOB(fd, 9) = 0;
+ WFIFOB(fd, 10) = 0;
+ WFIFOW(fd, 11) = 0;
+ WFIFOW(fd, 13) = 0;
+ WFIFOW(fd, 15) = 0;
+ WFIFOW(fd, 17) = 0;
+ WFIFOW(fd, 19) = 0;
+ WFIFOB(fd, 21) = 0;
+ WFIFOB(fd, 22) = uint8_t(fail);
}
else
{
@@ -1870,59 +1476,60 @@ int clif_additem (struct map_session_data *sd, int n, int amount, int fail)
|| sd->inventory_data[n] == NULL)
return 1;
- WBUFW (buf, 0) = 0xa0;
- WBUFW (buf, 2) = n + 2;
- WBUFW (buf, 4) = amount;
+ WFIFOW(fd, 0) = 0xa0;
+ WFIFOW(fd, 2) = n + 2;
+ WFIFOW(fd, 4) = amount;
if (sd->inventory_data[n]->view_id > 0)
- WBUFW (buf, 6) = sd->inventory_data[n]->view_id;
+ WFIFOW(fd, 6) = sd->inventory_data[n]->view_id;
else
- WBUFW (buf, 6) = sd->status.inventory[n].nameid;
- WBUFB (buf, 8) = sd->status.inventory[n].identify;
+ WFIFOW(fd, 6) = sd->status.inventory[n].nameid;
+ WFIFOB(fd, 8) = sd->status.inventory[n].identify;
if (sd->status.inventory[n].broken == 1)
- WBUFB (buf, 9) = 1; // is weapon broken [Valaris]
+ WFIFOB(fd, 9) = 1; // is weapon broken [Valaris]
else
- WBUFB (buf, 9) = sd->status.inventory[n].attribute;
- WBUFB (buf, 10) = sd->status.inventory[n].refine;
+ WFIFOB(fd, 9) = sd->status.inventory[n].attribute;
+ WFIFOB(fd, 10) = sd->status.inventory[n].refine;
if (sd->status.inventory[n].card[0] == 0x00ff
|| sd->status.inventory[n].card[0] == 0x00fe
|| sd->status.inventory[n].card[0] == (short) 0xff00)
{
- WBUFW (buf, 11) = sd->status.inventory[n].card[0];
- WBUFW (buf, 13) = sd->status.inventory[n].card[1];
- WBUFW (buf, 15) = sd->status.inventory[n].card[2];
- WBUFW (buf, 17) = sd->status.inventory[n].card[3];
+ WFIFOW(fd, 11) = sd->status.inventory[n].card[0];
+ WFIFOW(fd, 13) = sd->status.inventory[n].card[1];
+ WFIFOW(fd, 15) = sd->status.inventory[n].card[2];
+ WFIFOW(fd, 17) = sd->status.inventory[n].card[3];
}
else
{
+ int j;
if (sd->status.inventory[n].card[0] > 0
- && (j = itemdb_viewid (sd->status.inventory[n].card[0])) > 0)
- WBUFW (buf, 11) = j;
+ && (j = itemdb_viewid(sd->status.inventory[n].card[0])) > 0)
+ WFIFOW(fd, 11) = j;
else
- WBUFW (buf, 11) = sd->status.inventory[n].card[0];
+ WFIFOW(fd, 11) = sd->status.inventory[n].card[0];
if (sd->status.inventory[n].card[1] > 0
- && (j = itemdb_viewid (sd->status.inventory[n].card[1])) > 0)
- WBUFW (buf, 13) = j;
+ && (j = itemdb_viewid(sd->status.inventory[n].card[1])) > 0)
+ WFIFOW(fd, 13) = j;
else
- WBUFW (buf, 13) = sd->status.inventory[n].card[1];
+ WFIFOW(fd, 13) = sd->status.inventory[n].card[1];
if (sd->status.inventory[n].card[2] > 0
- && (j = itemdb_viewid (sd->status.inventory[n].card[2])) > 0)
- WBUFW (buf, 15) = j;
+ && (j = itemdb_viewid(sd->status.inventory[n].card[2])) > 0)
+ WFIFOW(fd, 15) = j;
else
- WBUFW (buf, 15) = sd->status.inventory[n].card[2];
+ WFIFOW(fd, 15) = sd->status.inventory[n].card[2];
if (sd->status.inventory[n].card[3] > 0
- && (j = itemdb_viewid (sd->status.inventory[n].card[3])) > 0)
- WBUFW (buf, 17) = j;
+ && (j = itemdb_viewid(sd->status.inventory[n].card[3])) > 0)
+ WFIFOW(fd, 17) = j;
else
- WBUFW (buf, 17) = sd->status.inventory[n].card[3];
+ WFIFOW(fd, 17) = sd->status.inventory[n].card[3];
}
- WBUFW (buf, 19) = pc_equippoint (sd, n);
- WBUFB (buf, 21) =
- (sd->inventory_data[n]->type ==
- 7) ? 4 : sd->inventory_data[n]->type;
- WBUFB (buf, 22) = fail;
+ WFIFOW(fd, 19) = uint16_t(pc_equippoint(sd, n));
+ WFIFOB(fd, 21) = uint8_t(sd->inventory_data[n]->type == ItemType::_7
+ ? ItemType::WEAPON
+ : sd->inventory_data[n]->type);
+ WFIFOB(fd, 22) = uint8_t(fail);
}
- WFIFOSET (fd, packet_len_table[0xa0]);
+ WFIFOSET(fd, clif_parse_func_table[0xa0].len);
return 0;
}
@@ -1930,18 +1537,18 @@ int clif_additem (struct map_session_data *sd, int n, int amount, int fail)
*
*------------------------------------------
*/
-int clif_delitem (struct map_session_data *sd, int n, int amount)
+int clif_delitem(struct map_session_data *sd, int n, int amount)
{
- int fd;
+ int fd;
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
fd = sd->fd;
- WFIFOW (fd, 0) = 0xaf;
- WFIFOW (fd, 2) = n + 2;
- WFIFOW (fd, 4) = amount;
+ WFIFOW(fd, 0) = 0xaf;
+ WFIFOW(fd, 2) = n + 2;
+ WFIFOW(fd, 4) = amount;
- WFIFOSET (fd, packet_len_table[0xaf]);
+ WFIFOSET(fd, clif_parse_func_table[0xaf].len);
return 0;
}
@@ -1950,51 +1557,49 @@ int clif_delitem (struct map_session_data *sd, int n, int amount)
*
*------------------------------------------
*/
-int clif_itemlist (struct map_session_data *sd)
+int clif_itemlist(struct map_session_data *sd)
{
- int i, n, fd, arrow = -1;
- unsigned char *buf;
-
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
- fd = sd->fd;
- buf = WFIFOP (fd, 0);
- WBUFW (buf, 0) = 0x1ee;
- for (i = 0, n = 0; i < MAX_INVENTORY; i++)
+ int n = 0;
+ int arrow = -1;
+ int fd = sd->fd;
+ WFIFOW(fd, 0) = 0x1ee;
+ for (int i = 0; i < MAX_INVENTORY; i++)
{
if (sd->status.inventory[i].nameid <= 0
|| sd->inventory_data[i] == NULL
- || itemdb_isequip2 (sd->inventory_data[i]))
+ || itemdb_isequip2(sd->inventory_data[i]))
continue;
- WBUFW (buf, n * 18 + 4) = i + 2;
+ WFIFOW(fd, n * 18 + 4) = i + 2;
if (sd->inventory_data[i]->view_id > 0)
- WBUFW (buf, n * 18 + 6) = sd->inventory_data[i]->view_id;
+ WFIFOW(fd, n * 18 + 6) = sd->inventory_data[i]->view_id;
else
- WBUFW (buf, n * 18 + 6) = sd->status.inventory[i].nameid;
- WBUFB (buf, n * 18 + 8) = sd->inventory_data[i]->type;
- WBUFB (buf, n * 18 + 9) = sd->status.inventory[i].identify;
- WBUFW (buf, n * 18 + 10) = sd->status.inventory[i].amount;
- if (sd->inventory_data[i]->equip == 0x8000)
+ WFIFOW(fd, n * 18 + 6) = sd->status.inventory[i].nameid;
+ WFIFOB(fd, n * 18 + 8) = uint8_t(sd->inventory_data[i]->type);
+ WFIFOB(fd, n * 18 + 9) = sd->status.inventory[i].identify;
+ WFIFOW(fd, n * 18 + 10) = sd->status.inventory[i].amount;
+ if (sd->inventory_data[i]->equip == EPOS::ARROW)
{
- WBUFW (buf, n * 18 + 12) = 0x8000;
- if (sd->status.inventory[i].equip)
+ WFIFOW(fd, n * 18 + 12) = uint16_t(EPOS::ARROW);
+ if (bool(sd->status.inventory[i].equip))
arrow = i; // ã¤ã„ã§ã«çŸ¢è£…å‚™ãƒã‚§ãƒƒã‚¯
}
else
- WBUFW (buf, n * 18 + 12) = 0;
- WBUFW (buf, n * 18 + 14) = sd->status.inventory[i].card[0];
- WBUFW (buf, n * 18 + 16) = sd->status.inventory[i].card[1];
- WBUFW (buf, n * 18 + 18) = sd->status.inventory[i].card[2];
- WBUFW (buf, n * 18 + 20) = sd->status.inventory[i].card[3];
+ WFIFOW(fd, n * 18 + 12) = uint16_t(EPOS::ZERO);
+ WFIFOW(fd, n * 18 + 14) = sd->status.inventory[i].card[0];
+ WFIFOW(fd, n * 18 + 16) = sd->status.inventory[i].card[1];
+ WFIFOW(fd, n * 18 + 18) = sd->status.inventory[i].card[2];
+ WFIFOW(fd, n * 18 + 20) = sd->status.inventory[i].card[3];
n++;
}
if (n)
{
- WBUFW (buf, 2) = 4 + n * 18;
- WFIFOSET (fd, WFIFOW (fd, 2));
+ WFIFOW(fd, 2) = 4 + n * 18;
+ WFIFOSET(fd, WFIFOW(fd, 2));
}
if (arrow >= 0)
- clif_arrowequip (sd, arrow);
+ clif_arrowequip(sd, arrow);
return 0;
}
@@ -2002,76 +1607,75 @@ int clif_itemlist (struct map_session_data *sd)
*
*------------------------------------------
*/
-int clif_equiplist (struct map_session_data *sd)
+int clif_equiplist(struct map_session_data *sd)
{
- int i, j, n, fd;
- unsigned char *buf;
-
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
- fd = sd->fd;
- buf = WFIFOP (fd, 0);
- WBUFW (buf, 0) = 0xa4;
- for (i = 0, n = 0; i < MAX_INVENTORY; i++)
+ int fd = sd->fd;
+ WFIFOW(fd, 0) = 0xa4;
+ int n = 0;
+ for (int i = 0; i < MAX_INVENTORY; i++)
{
if (sd->status.inventory[i].nameid <= 0
|| sd->inventory_data[i] == NULL
- || !itemdb_isequip2 (sd->inventory_data[i]))
+ || !itemdb_isequip2(sd->inventory_data[i]))
continue;
- WBUFW (buf, n * 20 + 4) = i + 2;
+ WFIFOW(fd, n * 20 + 4) = i + 2;
if (sd->inventory_data[i]->view_id > 0)
- WBUFW (buf, n * 20 + 6) = sd->inventory_data[i]->view_id;
+ WFIFOW(fd, n * 20 + 6) = sd->inventory_data[i]->view_id;
else
- WBUFW (buf, n * 20 + 6) = sd->status.inventory[i].nameid;
- WBUFB (buf, n * 20 + 8) =
- (sd->inventory_data[i]->type ==
- 7) ? 4 : sd->inventory_data[i]->type;
- WBUFB (buf, n * 20 + 9) = sd->status.inventory[i].identify;
- WBUFW (buf, n * 20 + 10) = pc_equippoint (sd, i);
- WBUFW (buf, n * 20 + 12) = sd->status.inventory[i].equip;
+ WFIFOW(fd, n * 20 + 6) = sd->status.inventory[i].nameid;
+ WFIFOB(fd, n * 20 + 8) = uint8_t(
+ sd->inventory_data[i]->type == ItemType::_7
+ ? ItemType::WEAPON
+ : sd->inventory_data[i]->type);
+ WFIFOB(fd, n * 20 + 9) = sd->status.inventory[i].identify;
+ WFIFOW(fd, n * 20 + 10) = uint16_t(pc_equippoint(sd, i));
+ WFIFOW(fd, n * 20 + 12) = uint16_t(sd->status.inventory[i].equip);
if (sd->status.inventory[i].broken == 1)
- WBUFB (buf, n * 20 + 14) = 1; // is weapon broken [Valaris]
+ WFIFOB(fd, n * 20 + 14) = 1; // is weapon broken [Valaris]
else
- WBUFB (buf, n * 20 + 14) = sd->status.inventory[i].attribute;
- WBUFB (buf, n * 20 + 15) = sd->status.inventory[i].refine;
+ WFIFOB(fd, n * 20 + 14) = sd->status.inventory[i].attribute;
+ WFIFOB(fd, n * 20 + 15) = sd->status.inventory[i].refine;
if (sd->status.inventory[i].card[0] == 0x00ff
|| sd->status.inventory[i].card[0] == 0x00fe
|| sd->status.inventory[i].card[0] == (short) 0xff00)
{
- WBUFW (buf, n * 20 + 16) = sd->status.inventory[i].card[0];
- WBUFW (buf, n * 20 + 18) = sd->status.inventory[i].card[1];
- WBUFW (buf, n * 20 + 20) = sd->status.inventory[i].card[2];
- WBUFW (buf, n * 20 + 22) = sd->status.inventory[i].card[3];
+ WFIFOW(fd, n * 20 + 16) = sd->status.inventory[i].card[0];
+ WFIFOW(fd, n * 20 + 18) = sd->status.inventory[i].card[1];
+ WFIFOW(fd, n * 20 + 20) = sd->status.inventory[i].card[2];
+ WFIFOW(fd, n * 20 + 22) = sd->status.inventory[i].card[3];
}
else
{
+ int j;
if (sd->status.inventory[i].card[0] > 0
- && (j = itemdb_viewid (sd->status.inventory[i].card[0])) > 0)
- WBUFW (buf, n * 20 + 16) = j;
+ && (j = itemdb_viewid(sd->status.inventory[i].card[0])) > 0)
+ WFIFOW(fd, n * 20 + 16) = j;
else
- WBUFW (buf, n * 20 + 16) = sd->status.inventory[i].card[0];
+ WFIFOW(fd, n * 20 + 16) = sd->status.inventory[i].card[0];
if (sd->status.inventory[i].card[1] > 0
- && (j = itemdb_viewid (sd->status.inventory[i].card[1])) > 0)
- WBUFW (buf, n * 20 + 18) = j;
+ && (j = itemdb_viewid(sd->status.inventory[i].card[1])) > 0)
+ WFIFOW(fd, n * 20 + 18) = j;
else
- WBUFW (buf, n * 20 + 18) = sd->status.inventory[i].card[1];
+ WFIFOW(fd, n * 20 + 18) = sd->status.inventory[i].card[1];
if (sd->status.inventory[i].card[2] > 0
- && (j = itemdb_viewid (sd->status.inventory[i].card[2])) > 0)
- WBUFW (buf, n * 20 + 20) = j;
+ && (j = itemdb_viewid(sd->status.inventory[i].card[2])) > 0)
+ WFIFOW(fd, n * 20 + 20) = j;
else
- WBUFW (buf, n * 20 + 20) = sd->status.inventory[i].card[2];
+ WFIFOW(fd, n * 20 + 20) = sd->status.inventory[i].card[2];
if (sd->status.inventory[i].card[3] > 0
- && (j = itemdb_viewid (sd->status.inventory[i].card[3])) > 0)
- WBUFW (buf, n * 20 + 22) = j;
+ && (j = itemdb_viewid(sd->status.inventory[i].card[3])) > 0)
+ WFIFOW(fd, n * 20 + 22) = j;
else
- WBUFW (buf, n * 20 + 22) = sd->status.inventory[i].card[3];
+ WFIFOW(fd, n * 20 + 22) = sd->status.inventory[i].card[3];
}
n++;
}
if (n)
{
- WBUFW (buf, 2) = 4 + n * 20;
- WFIFOSET (fd, WFIFOW (fd, 2));
+ WFIFOW(fd, 2) = 4 + n * 20;
+ WFIFOSET(fd, WFIFOW(fd, 2));
}
return 0;
}
@@ -2080,45 +1684,44 @@ int clif_equiplist (struct map_session_data *sd)
* カプラã•ã‚“ã«é ã‘ã¦ã‚る消耗å“&åŽé›†å“リスト
*------------------------------------------
*/
-int clif_storageitemlist (struct map_session_data *sd, struct storage *stor)
+int clif_storageitemlist(struct map_session_data *sd, struct storage *stor)
{
- struct item_data *id;
- int i, n, fd;
- unsigned char *buf;
-
- nullpo_retr (0, sd);
- nullpo_retr (0, stor);
+ nullpo_ret(sd);
+ nullpo_ret(stor);
- fd = sd->fd;
- buf = WFIFOP (fd, 0);
- WBUFW (buf, 0) = 0x1f0;
- for (i = 0, n = 0; i < MAX_STORAGE; i++)
+ int fd = sd->fd;
+ WFIFOW(fd, 0) = 0x1f0;
+ int n = 0;
+ for (int i = 0; i < MAX_STORAGE; i++)
{
if (stor->storage_[i].nameid <= 0)
continue;
- nullpo_retr (0, id = itemdb_search (stor->storage_[i].nameid));
- if (itemdb_isequip2 (id))
+
+ struct item_data *id;
+ id = itemdb_search(stor->storage_[i].nameid);
+ nullpo_ret(id);
+ if (itemdb_isequip2(id))
continue;
- WBUFW (buf, n * 18 + 4) = i + 1;
+ WFIFOW(fd, n * 18 + 4) = i + 1;
if (id->view_id > 0)
- WBUFW (buf, n * 18 + 6) = id->view_id;
+ WFIFOW(fd, n * 18 + 6) = id->view_id;
else
- WBUFW (buf, n * 18 + 6) = stor->storage_[i].nameid;
- WBUFB (buf, n * 18 + 8) = id->type;;
- WBUFB (buf, n * 18 + 9) = stor->storage_[i].identify;
- WBUFW (buf, n * 18 + 10) = stor->storage_[i].amount;
- WBUFW (buf, n * 18 + 12) = 0;
- WBUFW (buf, n * 18 + 14) = stor->storage_[i].card[0];
- WBUFW (buf, n * 18 + 16) = stor->storage_[i].card[1];
- WBUFW (buf, n * 18 + 18) = stor->storage_[i].card[2];
- WBUFW (buf, n * 18 + 20) = stor->storage_[i].card[3];
+ WFIFOW(fd, n * 18 + 6) = stor->storage_[i].nameid;
+ WFIFOB(fd, n * 18 + 8) = uint8_t(id->type);
+ WFIFOB(fd, n * 18 + 9) = stor->storage_[i].identify;
+ WFIFOW(fd, n * 18 + 10) = stor->storage_[i].amount;
+ WFIFOW(fd, n * 18 + 12) = 0;
+ WFIFOW(fd, n * 18 + 14) = stor->storage_[i].card[0];
+ WFIFOW(fd, n * 18 + 16) = stor->storage_[i].card[1];
+ WFIFOW(fd, n * 18 + 18) = stor->storage_[i].card[2];
+ WFIFOW(fd, n * 18 + 20) = stor->storage_[i].card[3];
n++;
}
if (n)
{
- WBUFW (buf, 2) = 4 + n * 18;
- WFIFOSET (fd, WFIFOW (fd, 2));
+ WFIFOW(fd, 2) = 4 + n * 18;
+ WFIFOSET(fd, WFIFOW(fd, 2));
}
return 0;
}
@@ -2127,206 +1730,77 @@ int clif_storageitemlist (struct map_session_data *sd, struct storage *stor)
* カプラã•ã‚“ã«é ã‘ã¦ã‚る装備リスト
*------------------------------------------
*/
-int clif_storageequiplist (struct map_session_data *sd, struct storage *stor)
+int clif_storageequiplist(struct map_session_data *sd, struct storage *stor)
{
- struct item_data *id;
- int i, j, n, fd;
- unsigned char *buf;
-
- nullpo_retr (0, sd);
- nullpo_retr (0, stor);
+ nullpo_ret(sd);
+ nullpo_ret(stor);
- fd = sd->fd;
- buf = WFIFOP (fd, 0);
- WBUFW (buf, 0) = 0xa6;
- for (i = 0, n = 0; i < MAX_STORAGE; i++)
+ int fd = sd->fd;
+ WFIFOW(fd, 0) = 0xa6;
+ int n = 0;
+ for (int i = 0; i < MAX_STORAGE; i++)
{
if (stor->storage_[i].nameid <= 0)
continue;
- nullpo_retr (0, id = itemdb_search (stor->storage_[i].nameid));
- if (!itemdb_isequip2 (id))
- continue;
- WBUFW (buf, n * 20 + 4) = i + 1;
- if (id->view_id > 0)
- WBUFW (buf, n * 20 + 6) = id->view_id;
- else
- WBUFW (buf, n * 20 + 6) = stor->storage_[i].nameid;
- WBUFB (buf, n * 20 + 8) = id->type;
- WBUFB (buf, n * 20 + 9) = stor->storage_[i].identify;
- WBUFW (buf, n * 20 + 10) = id->equip;
- WBUFW (buf, n * 20 + 12) = stor->storage_[i].equip;
- if (stor->storage_[i].broken == 1)
- WBUFB (buf, n * 20 + 14) = 1; //is weapon broken [Valaris]
- else
- WBUFB (buf, n * 20 + 14) = stor->storage_[i].attribute;
- WBUFB (buf, n * 20 + 15) = stor->storage_[i].refine;
- if (stor->storage_[i].card[0] == 0x00ff
- || stor->storage_[i].card[0] == 0x00fe
- || stor->storage_[i].card[0] == (short) 0xff00)
- {
- WBUFW (buf, n * 20 + 16) = stor->storage_[i].card[0];
- WBUFW (buf, n * 20 + 18) = stor->storage_[i].card[1];
- WBUFW (buf, n * 20 + 20) = stor->storage_[i].card[2];
- WBUFW (buf, n * 20 + 22) = stor->storage_[i].card[3];
- }
- else
- {
- if (stor->storage_[i].card[0] > 0
- && (j = itemdb_viewid (stor->storage_[i].card[0])) > 0)
- WBUFW (buf, n * 20 + 16) = j;
- else
- WBUFW (buf, n * 20 + 16) = stor->storage_[i].card[0];
- if (stor->storage_[i].card[1] > 0
- && (j = itemdb_viewid (stor->storage_[i].card[1])) > 0)
- WBUFW (buf, n * 20 + 18) = j;
- else
- WBUFW (buf, n * 20 + 18) = stor->storage_[i].card[1];
- if (stor->storage_[i].card[2] > 0
- && (j = itemdb_viewid (stor->storage_[i].card[2])) > 0)
- WBUFW (buf, n * 20 + 20) = j;
- else
- WBUFW (buf, n * 20 + 20) = stor->storage_[i].card[2];
- if (stor->storage_[i].card[3] > 0
- && (j = itemdb_viewid (stor->storage_[i].card[3])) > 0)
- WBUFW (buf, n * 20 + 22) = j;
- else
- WBUFW (buf, n * 20 + 22) = stor->storage_[i].card[3];
- }
- n++;
- }
- if (n)
- {
- WBUFW (buf, 2) = 4 + n * 20;
- WFIFOSET (fd, WFIFOW (fd, 2));
- }
- return 0;
-}
-
-/*==========================================
- *
- *------------------------------------------
- */
-int clif_guildstorageitemlist (struct map_session_data *sd,
- struct guild_storage *stor)
-{
- struct item_data *id;
- int i, n, fd;
- unsigned char *buf;
-
- nullpo_retr (0, sd);
- nullpo_retr (0, stor);
-
- fd = sd->fd;
- buf = WFIFOP (fd, 0);
-
- WBUFW (buf, 0) = 0x1f0;
- for (i = 0, n = 0; i < MAX_GUILD_STORAGE; i++)
- {
- if (stor->storage_[i].nameid <= 0)
- continue;
- nullpo_retr (0, id = itemdb_search (stor->storage_[i].nameid));
- if (itemdb_isequip2 (id))
- continue;
-
- WBUFW (buf, n * 18 + 4) = i + 1;
- if (id->view_id > 0)
- WBUFW (buf, n * 18 + 6) = id->view_id;
- else
- WBUFW (buf, n * 18 + 6) = stor->storage_[i].nameid;
- WBUFB (buf, n * 18 + 8) = id->type;;
- WBUFB (buf, n * 18 + 9) = stor->storage_[i].identify;
- WBUFW (buf, n * 18 + 10) = stor->storage_[i].amount;
- WBUFW (buf, n * 18 + 12) = 0;
- WBUFW (buf, n * 18 + 14) = stor->storage_[i].card[0];
- WBUFW (buf, n * 18 + 16) = stor->storage_[i].card[1];
- WBUFW (buf, n * 18 + 18) = stor->storage_[i].card[2];
- WBUFW (buf, n * 18 + 20) = stor->storage_[i].card[3];
- n++;
- }
- if (n)
- {
- WBUFW (buf, 2) = 4 + n * 18;
- WFIFOSET (fd, WFIFOW (fd, 2));
- }
- return 0;
-}
-
-/*==========================================
- *
- *------------------------------------------
- */
-int clif_guildstorageequiplist (struct map_session_data *sd,
- struct guild_storage *stor)
-{
- struct item_data *id;
- int i, j, n, fd;
- unsigned char *buf;
-
- nullpo_retr (0, sd);
-
- fd = sd->fd;
- buf = WFIFOP (fd, 0);
- WBUFW (buf, 0) = 0xa6;
- for (i = 0, n = 0; i < MAX_GUILD_STORAGE; i++)
- {
- if (stor->storage_[i].nameid <= 0)
+ struct item_data *id;
+ id = itemdb_search(stor->storage_[i].nameid);
+ nullpo_ret(id);
+ if (!itemdb_isequip2(id))
continue;
- nullpo_retr (0, id = itemdb_search (stor->storage_[i].nameid));
- if (!itemdb_isequip2 (id))
- continue;
- WBUFW (buf, n * 20 + 4) = i + 1;
+ WFIFOW(fd, n * 20 + 4) = i + 1;
if (id->view_id > 0)
- WBUFW (buf, n * 20 + 6) = id->view_id;
+ WFIFOW(fd, n * 20 + 6) = id->view_id;
else
- WBUFW (buf, n * 20 + 6) = stor->storage_[i].nameid;
- WBUFB (buf, n * 20 + 8) = id->type;
- WBUFB (buf, n * 20 + 9) = stor->storage_[i].identify;
- WBUFW (buf, n * 20 + 10) = id->equip;
- WBUFW (buf, n * 20 + 12) = stor->storage_[i].equip;
+ WFIFOW(fd, n * 20 + 6) = stor->storage_[i].nameid;
+ WFIFOB(fd, n * 20 + 8) = uint8_t(id->type);
+ WFIFOB(fd, n * 20 + 9) = stor->storage_[i].identify;
+ WFIFOW(fd, n * 20 + 10) = uint16_t(id->equip);
+ WFIFOW(fd, n * 20 + 12) = uint16_t(stor->storage_[i].equip);
if (stor->storage_[i].broken == 1)
- WBUFB (buf, n * 20 + 14) = 1; // is weapon broken [Valaris]
+ WFIFOB(fd, n * 20 + 14) = 1; //is weapon broken [Valaris]
else
- WBUFB (buf, n * 20 + 14) = stor->storage_[i].attribute;
- WBUFB (buf, n * 20 + 15) = stor->storage_[i].refine;
+ WFIFOB(fd, n * 20 + 14) = stor->storage_[i].attribute;
+ WFIFOB(fd, n * 20 + 15) = stor->storage_[i].refine;
if (stor->storage_[i].card[0] == 0x00ff
|| stor->storage_[i].card[0] == 0x00fe
|| stor->storage_[i].card[0] == (short) 0xff00)
{
- WBUFW (buf, n * 20 + 16) = stor->storage_[i].card[0];
- WBUFW (buf, n * 20 + 18) = stor->storage_[i].card[1];
- WBUFW (buf, n * 20 + 20) = stor->storage_[i].card[2];
- WBUFW (buf, n * 20 + 22) = stor->storage_[i].card[3];
+ WFIFOW(fd, n * 20 + 16) = stor->storage_[i].card[0];
+ WFIFOW(fd, n * 20 + 18) = stor->storage_[i].card[1];
+ WFIFOW(fd, n * 20 + 20) = stor->storage_[i].card[2];
+ WFIFOW(fd, n * 20 + 22) = stor->storage_[i].card[3];
}
else
{
+ int j;
if (stor->storage_[i].card[0] > 0
- && (j = itemdb_viewid (stor->storage_[i].card[0])) > 0)
- WBUFW (buf, n * 20 + 16) = j;
+ && (j = itemdb_viewid(stor->storage_[i].card[0])) > 0)
+ WFIFOW(fd, n * 20 + 16) = j;
else
- WBUFW (buf, n * 20 + 16) = stor->storage_[i].card[0];
+ WFIFOW(fd, n * 20 + 16) = stor->storage_[i].card[0];
if (stor->storage_[i].card[1] > 0
- && (j = itemdb_viewid (stor->storage_[i].card[1])) > 0)
- WBUFW (buf, n * 20 + 18) = j;
+ && (j = itemdb_viewid(stor->storage_[i].card[1])) > 0)
+ WFIFOW(fd, n * 20 + 18) = j;
else
- WBUFW (buf, n * 20 + 18) = stor->storage_[i].card[1];
+ WFIFOW(fd, n * 20 + 18) = stor->storage_[i].card[1];
if (stor->storage_[i].card[2] > 0
- && (j = itemdb_viewid (stor->storage_[i].card[2])) > 0)
- WBUFW (buf, n * 20 + 20) = j;
+ && (j = itemdb_viewid(stor->storage_[i].card[2])) > 0)
+ WFIFOW(fd, n * 20 + 20) = j;
else
- WBUFW (buf, n * 20 + 20) = stor->storage_[i].card[2];
+ WFIFOW(fd, n * 20 + 20) = stor->storage_[i].card[2];
if (stor->storage_[i].card[3] > 0
- && (j = itemdb_viewid (stor->storage_[i].card[3])) > 0)
- WBUFW (buf, n * 20 + 22) = j;
+ && (j = itemdb_viewid(stor->storage_[i].card[3])) > 0)
+ WFIFOW(fd, n * 20 + 22) = j;
else
- WBUFW (buf, n * 20 + 22) = stor->storage_[i].card[3];
+ WFIFOW(fd, n * 20 + 22) = stor->storage_[i].card[3];
}
n++;
}
if (n)
{
- WBUFW (buf, 2) = 4 + n * 20;
- WFIFOSET (fd, WFIFOW (fd, 2));
+ WFIFOW(fd, 2) = 4 + n * 20;
+ WFIFOSET(fd, WFIFOW(fd, 2));
}
return 0;
}
@@ -2336,239 +1810,170 @@ int clif_guildstorageequiplist (struct map_session_data *sd,
* 表示専用数字ã¯ã“ã®ä¸­ã§è¨ˆç®—ã—ã¦é€ã‚‹
*------------------------------------------
*/
-int clif_updatestatus (struct map_session_data *sd, int type)
+int clif_updatestatus(struct map_session_data *sd, SP type)
{
- int fd, len = 8;
+ int fd, len = 8;
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
fd = sd->fd;
- WFIFOW (fd, 0) = 0xb0;
- WFIFOW (fd, 2) = type;
+ WFIFOW(fd, 0) = 0xb0;
+ WFIFOW(fd, 2) = static_cast<uint16_t>(type);
switch (type)
{
// 00b0
- case SP_WEIGHT:
- pc_checkweighticon (sd);
- WFIFOW (fd, 0) = 0xb0;
- WFIFOW (fd, 2) = type;
- WFIFOL (fd, 4) = sd->weight;
- break;
- case SP_MAXWEIGHT:
- WFIFOL (fd, 4) = sd->max_weight;
+ case SP::WEIGHT:
+ pc_checkweighticon(sd);
+ // is this because pc_checkweighticon can send other packets?
+ WFIFOW(fd, 0) = 0xb0;
+ WFIFOW(fd, 2) = static_cast<uint16_t>(type);
+ WFIFOL(fd, 4) = sd->weight;
break;
- case SP_SPEED:
- WFIFOL (fd, 4) = sd->speed;
+ case SP::MAXWEIGHT:
+ WFIFOL(fd, 4) = sd->max_weight;
break;
- case SP_BASELEVEL:
- WFIFOL (fd, 4) = sd->status.base_level;
+ case SP::SPEED:
+ // ...
+ WFIFOL(fd, 4) = static_cast<uint16_t>(sd->speed.count());
break;
- case SP_JOBLEVEL:
- WFIFOL (fd, 4) = 0;
+ case SP::BASELEVEL:
+ WFIFOL(fd, 4) = sd->status.base_level;
break;
- case SP_MANNER:
- WFIFOL (fd, 4) = sd->status.manner;
- clif_changestatus (&sd->bl, SP_MANNER, sd->status.manner);
+ case SP::JOBLEVEL:
+ WFIFOL(fd, 4) = 0;
break;
- case SP_STATUSPOINT:
- WFIFOL (fd, 4) = sd->status.status_point;
+ case SP::STATUSPOINT:
+ WFIFOL(fd, 4) = sd->status.status_point;
break;
- case SP_SKILLPOINT:
- WFIFOL (fd, 4) = sd->status.skill_point;
+ case SP::SKILLPOINT:
+ WFIFOL(fd, 4) = sd->status.skill_point;
break;
- case SP_HIT:
- WFIFOL (fd, 4) = sd->hit;
+ case SP::HIT:
+ WFIFOL(fd, 4) = sd->hit;
break;
- case SP_FLEE1:
- WFIFOL (fd, 4) = sd->flee;
+ case SP::FLEE1:
+ WFIFOL(fd, 4) = sd->flee;
break;
- case SP_FLEE2:
- WFIFOL (fd, 4) = sd->flee2 / 10;
+ case SP::FLEE2:
+ WFIFOL(fd, 4) = sd->flee2 / 10;
break;
- case SP_MAXHP:
- WFIFOL (fd, 4) = sd->status.max_hp;
+ case SP::MAXHP:
+ WFIFOL(fd, 4) = sd->status.max_hp;
break;
- case SP_MAXSP:
- WFIFOL (fd, 4) = sd->status.max_sp;
+ case SP::MAXSP:
+ WFIFOL(fd, 4) = sd->status.max_sp;
break;
- case SP_HP:
- WFIFOL (fd, 4) = sd->status.hp;
+ case SP::HP:
+ WFIFOL(fd, 4) = sd->status.hp;
break;
- case SP_SP:
- WFIFOL (fd, 4) = sd->status.sp;
+ case SP::SP:
+ WFIFOL(fd, 4) = sd->status.sp;
break;
- case SP_ASPD:
- WFIFOL (fd, 4) = sd->aspd;
+ case SP::ASPD:
+ WFIFOL(fd, 4) = static_cast<uint16_t>(sd->aspd.count());
break;
- case SP_ATK1:
- WFIFOL (fd, 4) = sd->base_atk + sd->watk;
+ case SP::ATK1:
+ WFIFOL(fd, 4) = sd->base_atk + sd->watk;
break;
- case SP_DEF1:
- WFIFOL (fd, 4) = sd->def;
+ case SP::DEF1:
+ WFIFOL(fd, 4) = sd->def;
break;
- case SP_MDEF1:
- WFIFOL (fd, 4) = sd->mdef;
+ case SP::MDEF1:
+ WFIFOL(fd, 4) = sd->mdef;
break;
- case SP_ATK2:
- WFIFOL (fd, 4) = sd->watk2;
+ case SP::ATK2:
+ WFIFOL(fd, 4) = sd->watk2;
break;
- case SP_DEF2:
- WFIFOL (fd, 4) = sd->def2;
+ case SP::DEF2:
+ WFIFOL(fd, 4) = sd->def2;
break;
- case SP_MDEF2:
- WFIFOL (fd, 4) = sd->mdef2;
+ case SP::MDEF2:
+ WFIFOL(fd, 4) = sd->mdef2;
break;
- case SP_CRITICAL:
- WFIFOL (fd, 4) = sd->critical / 10;
+ case SP::CRITICAL:
+ WFIFOL(fd, 4) = sd->critical / 10;
break;
- case SP_MATK1:
- WFIFOL (fd, 4) = sd->matk1;
+ case SP::MATK1:
+ WFIFOL(fd, 4) = sd->matk1;
break;
- case SP_MATK2:
- WFIFOL (fd, 4) = sd->matk2;
+ case SP::MATK2:
+ WFIFOL(fd, 4) = sd->matk2;
break;
- case SP_ZENY:
- trade_verifyzeny (sd);
- WFIFOW (fd, 0) = 0xb1;
+ case SP::ZENY:
+ trade_verifyzeny(sd);
+ WFIFOW(fd, 0) = 0xb1;
if (sd->status.zeny < 0)
sd->status.zeny = 0;
- WFIFOL (fd, 4) = sd->status.zeny;
+ WFIFOL(fd, 4) = sd->status.zeny;
break;
- case SP_BASEEXP:
- WFIFOW (fd, 0) = 0xb1;
- WFIFOL (fd, 4) = sd->status.base_exp;
+ case SP::BASEEXP:
+ WFIFOW(fd, 0) = 0xb1;
+ WFIFOL(fd, 4) = sd->status.base_exp;
break;
- case SP_JOBEXP:
- WFIFOW (fd, 0) = 0xb1;
- WFIFOL (fd, 4) = sd->status.job_exp;
+ case SP::JOBEXP:
+ WFIFOW(fd, 0) = 0xb1;
+ WFIFOL(fd, 4) = sd->status.job_exp;
break;
- case SP_NEXTBASEEXP:
- WFIFOW (fd, 0) = 0xb1;
- WFIFOL (fd, 4) = pc_nextbaseexp (sd);
+ case SP::NEXTBASEEXP:
+ WFIFOW(fd, 0) = 0xb1;
+ WFIFOL(fd, 4) = pc_nextbaseexp(sd);
break;
- case SP_NEXTJOBEXP:
- WFIFOW (fd, 0) = 0xb1;
- WFIFOL (fd, 4) = pc_nextjobexp (sd);
+ case SP::NEXTJOBEXP:
+ WFIFOW(fd, 0) = 0xb1;
+ WFIFOL(fd, 4) = pc_nextjobexp(sd);
break;
// 00be 終了
- case SP_USTR:
- case SP_UAGI:
- case SP_UVIT:
- case SP_UINT:
- case SP_UDEX:
- case SP_ULUK:
- WFIFOW (fd, 0) = 0xbe;
- WFIFOB (fd, 4) =
- pc_need_status_point (sd, type - SP_USTR + SP_STR);
+ case SP::USTR:
+ case SP::UAGI:
+ case SP::UVIT:
+ case SP::UINT:
+ case SP::UDEX:
+ case SP::ULUK:
+ WFIFOW(fd, 0) = 0xbe;
+ WFIFOB(fd, 4) = pc_need_status_point(sd, usp_to_sp(type));
len = 5;
break;
// 013a 終了
- case SP_ATTACKRANGE:
- WFIFOW (fd, 0) = 0x13a;
- WFIFOW (fd, 2) = (sd->attack_spell_override)
+ case SP::ATTACKRANGE:
+ WFIFOW(fd, 0) = 0x13a;
+ WFIFOW(fd, 2) = (sd->attack_spell_override)
? sd->attack_spell_range : sd->attackrange;
len = 4;
break;
// 0141 終了
- case SP_STR:
- WFIFOW (fd, 0) = 0x141;
- WFIFOL (fd, 2) = type;
- WFIFOL (fd, 6) = sd->status.str;
- WFIFOL (fd, 10) = sd->paramb[0] + sd->parame[0];
- len = 14;
- break;
- case SP_AGI:
- WFIFOW (fd, 0) = 0x141;
- WFIFOL (fd, 2) = type;
- WFIFOL (fd, 6) = sd->status.agi;
- WFIFOL (fd, 10) = sd->paramb[1] + sd->parame[1];
- len = 14;
- break;
- case SP_VIT:
- WFIFOW (fd, 0) = 0x141;
- WFIFOL (fd, 2) = type;
- WFIFOL (fd, 6) = sd->status.vit;
- WFIFOL (fd, 10) = sd->paramb[2] + sd->parame[2];
- len = 14;
- break;
- case SP_INT:
- WFIFOW (fd, 0) = 0x141;
- WFIFOL (fd, 2) = type;
- WFIFOL (fd, 6) = sd->status.int_;
- WFIFOL (fd, 10) = sd->paramb[3] + sd->parame[3];
- len = 14;
- break;
- case SP_DEX:
- WFIFOW (fd, 0) = 0x141;
- WFIFOL (fd, 2) = type;
- WFIFOL (fd, 6) = sd->status.dex;
- WFIFOL (fd, 10) = sd->paramb[4] + sd->parame[4];
- len = 14;
- break;
- case SP_LUK:
- WFIFOW (fd, 0) = 0x141;
- WFIFOL (fd, 2) = type;
- WFIFOL (fd, 6) = sd->status.luk;
- WFIFOL (fd, 10) = sd->paramb[5] + sd->parame[5];
- len = 14;
- break;
-
- case SP_CARTINFO:
- WFIFOW (fd, 0) = 0x121;
- WFIFOW (fd, 2) = sd->cart_num;
- WFIFOW (fd, 4) = sd->cart_max_num;
- WFIFOL (fd, 6) = sd->cart_weight;
- WFIFOL (fd, 10) = sd->cart_max_weight;
+ case SP::STR:
+ case SP::AGI:
+ case SP::VIT:
+ case SP::INT:
+ case SP::DEX:
+ case SP::LUK:
+ {
+ ATTR attr = sp_to_attr(type);
+ WFIFOW(fd, 0) = 0x141;
+ WFIFOL(fd, 2) = uint16_t(type);
+ WFIFOL(fd, 6) = sd->status.attrs[attr];
+ WFIFOL(fd, 10) = sd->paramb[attr] + sd->parame[attr];
len = 14;
+ }
break;
- case SP_GM:
- WFIFOL (fd, 4) = pc_isGM (sd);
+ case SP::GM:
+ WFIFOL(fd, 4) = pc_isGM(sd);
break;
default:
if (battle_config.error_log)
- printf ("clif_updatestatus : make %d routine\n", type);
+ PRINTF("clif_updatestatus : make %d routine\n",
+ type);
return 1;
}
- WFIFOSET (fd, len);
-
- return 0;
-}
-
-int clif_changestatus (struct block_list *bl, int type, int val)
-{
- unsigned char buf[12];
- struct map_session_data *sd = NULL;
-
- nullpo_retr (0, bl);
+ WFIFOSET(fd, len);
- if (bl->type == BL_PC)
- sd = (struct map_session_data *) bl;
-
-//printf("clif_changestatus id:%d type:%d val:%d\n",bl->id,type,val);
- if (sd)
- {
- WBUFW (buf, 0) = 0x1ab;
- WBUFL (buf, 2) = bl->id;
- WBUFW (buf, 6) = type;
- switch (type)
- {
- case SP_MANNER:
- WBUFL (buf, 8) = val;
- break;
- default:
- if (battle_config.error_log)
- printf ("clif_changestatus : make %d routine\n", type);
- return 1;
- }
- clif_send (buf, packet_len_table[0x1ab], bl, AREA_WOS);
- }
return 0;
}
@@ -2576,108 +1981,102 @@ int clif_changestatus (struct block_list *bl, int type, int val)
*
*------------------------------------------
*/
-int clif_changelook (struct block_list *bl, int type, int val)
+int clif_changelook(struct block_list *bl, LOOK type, int val)
{
- return clif_changelook_towards (bl, type, val, NULL);
+ return clif_changelook_towards(bl, type, val, NULL);
}
-int clif_changelook_towards (struct block_list *bl, int type, int val,
+int clif_changelook_towards(struct block_list *bl, LOOK type, int val,
struct map_session_data *dstsd)
{
- unsigned char rbuf[32];
- unsigned char *buf = dstsd ? WFIFOP (dstsd->fd, 0) : rbuf; // pick target buffer or general-purpose one
+ unsigned char buf[32];
struct map_session_data *sd = NULL;
- nullpo_retr (0, bl);
+ nullpo_ret(bl);
- if (bl->type == BL_PC)
+ if (bl->type == BL::PC)
sd = (struct map_session_data *) bl;
- if (sd && sd->disguise > 23 && sd->disguise < 4001) // mob disguises [Valaris]
- return 0;
-
- if (sd && sd->status.option & OPTION_INVISIBILITY)
+ if (sd && bool(sd->status.option & Option::INVISIBILITY))
return 0;
if (sd
- && (type == LOOK_WEAPON || type == LOOK_SHIELD || type >= LOOK_SHOES))
+ && (type == LOOK::WEAPON || type == LOOK::SHIELD || type >= LOOK::SHOES))
{
- WBUFW (buf, 0) = 0x1d7;
- WBUFL (buf, 2) = bl->id;
- if (type >= LOOK_SHOES)
+ WBUFW(buf, 0) = 0x1d7;
+ WBUFL(buf, 2) = bl->id;
+ if (type >= LOOK::SHOES)
{
- int equip_point = equip_points[type];
+ EQUIP equip_point = equip_points[type];
- WBUFB (buf, 6) = type;
+ WBUFB(buf, 6) = uint16_t(type);
if (sd->equip_index[equip_point] >= 0
&& sd->inventory_data[sd->equip_index[equip_point]])
{
if (sd->
inventory_data[sd->equip_index[equip_point]]->view_id > 0)
- WBUFW (buf, 7) =
+ WBUFW(buf, 7) =
sd->inventory_data[sd->
equip_index[equip_point]]->view_id;
else
- WBUFW (buf, 7) =
+ WBUFW(buf, 7) =
sd->status.inventory[sd->
equip_index[equip_point]].nameid;
}
else
- WBUFW (buf, 7) = 0;
- WBUFW (buf, 9) = 0;
+ WBUFW(buf, 7) = 0;
+ WBUFW(buf, 9) = 0;
}
else
{
- WBUFB (buf, 6) = 2;
+ WBUFB(buf, 6) = 2;
if (sd->attack_spell_override)
- WBUFW (buf, 7) = sd->attack_spell_look_override;
+ WBUFW(buf, 7) = sd->attack_spell_look_override;
else
{
- if (sd->equip_index[9] >= 0
- && sd->inventory_data[sd->equip_index[9]]
- && sd->view_class != 22)
+ if (sd->equip_index[EQUIP::WEAPON] >= 0
+ && sd->inventory_data[sd->equip_index[EQUIP::WEAPON]])
{
- if (sd->inventory_data[sd->equip_index[9]]->view_id > 0)
- WBUFW (buf, 7) =
- sd->inventory_data[sd->equip_index[9]]->view_id;
+ if (sd->inventory_data[sd->equip_index[EQUIP::WEAPON]]->view_id > 0)
+ WBUFW(buf, 7) =
+ sd->inventory_data[sd->equip_index[EQUIP::WEAPON]]->view_id;
else
- WBUFW (buf, 7) =
- sd->status.inventory[sd->equip_index[9]].nameid;
+ WBUFW(buf, 7) =
+ sd->status.inventory[sd->equip_index[EQUIP::WEAPON]].nameid;
}
else
- WBUFW (buf, 7) = 0;
+ WBUFW(buf, 7) = 0;
}
- if (sd->equip_index[8] >= 0
- && sd->equip_index[8] != sd->equip_index[9]
- && sd->inventory_data[sd->equip_index[8]]
- && sd->view_class != 22)
+ if (sd->equip_index[EQUIP::SHIELD] >= 0
+ && sd->equip_index[EQUIP::SHIELD] != sd->equip_index[EQUIP::WEAPON]
+ && sd->inventory_data[sd->equip_index[EQUIP::SHIELD]])
{
- if (sd->inventory_data[sd->equip_index[8]]->view_id > 0)
- WBUFW (buf, 9) =
- sd->inventory_data[sd->equip_index[8]]->view_id;
+ if (sd->inventory_data[sd->equip_index[EQUIP::SHIELD]]->view_id > 0)
+ WBUFW(buf, 9) =
+ sd->inventory_data[sd->equip_index[EQUIP::SHIELD]]->view_id;
else
- WBUFW (buf, 9) =
- sd->status.inventory[sd->equip_index[8]].nameid;
+ WBUFW(buf, 9) =
+ sd->status.inventory[sd->equip_index[EQUIP::SHIELD]].nameid;
}
else
- WBUFW (buf, 9) = 0;
+ WBUFW(buf, 9) = 0;
}
if (dstsd)
- WFIFOSET (dstsd->fd, packet_len_table[0x1d7]);
+ clif_send(buf, clif_parse_func_table[0x1d7].len, &dstsd->bl, SendWho::SELF);
else
- clif_send (buf, packet_len_table[0x1d7], bl, AREA);
+ clif_send(buf, clif_parse_func_table[0x1d7].len, bl, SendWho::AREA);
}
else
{
- WBUFW (buf, 0) = 0x1d7;
- WBUFL (buf, 2) = bl->id;
- WBUFB (buf, 6) = type;
- WBUFW (buf, 7) = val;
- WBUFW (buf, 9) = 0;
+ WBUFW(buf, 0) = 0x1d7;
+ WBUFL(buf, 2) = bl->id;
+ WBUFB(buf, 6) = uint8_t(type);
+ WBUFW(buf, 7) = val;
+ WBUFW(buf, 9) = 0;
if (dstsd)
- WFIFOSET (dstsd->fd, packet_len_table[0x1d7]);
+ clif_send(buf, clif_parse_func_table[0x1d7].len, &dstsd->bl, SendWho::SELF);
else
- clif_send (buf, packet_len_table[0x1d7], bl, AREA);
+ clif_send(buf, clif_parse_func_table[0x1d7].len, bl, SendWho::AREA);
}
return 0;
}
@@ -2687,57 +2086,54 @@ int clif_changelook_towards (struct block_list *bl, int type, int val,
*------------------------------------------
*/
static
-int clif_initialstatus (struct map_session_data *sd)
+int clif_initialstatus(struct map_session_data *sd)
{
- int fd;
- unsigned char *buf;
+ nullpo_ret(sd);
- nullpo_retr (0, sd);
+ int fd = sd->fd;
- fd = sd->fd;
- buf = WFIFOP (fd, 0);
-
- WBUFW (buf, 0) = 0xbd;
- WBUFW (buf, 2) = sd->status.status_point;
- WBUFB (buf, 4) = (sd->status.str > 255) ? 255 : sd->status.str;
- WBUFB (buf, 5) = pc_need_status_point (sd, SP_STR);
- WBUFB (buf, 6) = (sd->status.agi > 255) ? 255 : sd->status.agi;
- WBUFB (buf, 7) = pc_need_status_point (sd, SP_AGI);
- WBUFB (buf, 8) = (sd->status.vit > 255) ? 255 : sd->status.vit;
- WBUFB (buf, 9) = pc_need_status_point (sd, SP_VIT);
- WBUFB (buf, 10) = (sd->status.int_ > 255) ? 255 : sd->status.int_;
- WBUFB (buf, 11) = pc_need_status_point (sd, SP_INT);
- WBUFB (buf, 12) = (sd->status.dex > 255) ? 255 : sd->status.dex;
- WBUFB (buf, 13) = pc_need_status_point (sd, SP_DEX);
- WBUFB (buf, 14) = (sd->status.luk > 255) ? 255 : sd->status.luk;
- WBUFB (buf, 15) = pc_need_status_point (sd, SP_LUK);
-
- WBUFW (buf, 16) = sd->base_atk + sd->watk;
- WBUFW (buf, 18) = sd->watk2; //atk bonus
- WBUFW (buf, 20) = sd->matk1;
- WBUFW (buf, 22) = sd->matk2;
- WBUFW (buf, 24) = sd->def; // def
- WBUFW (buf, 26) = sd->def2;
- WBUFW (buf, 28) = sd->mdef; // mdef
- WBUFW (buf, 30) = sd->mdef2;
- WBUFW (buf, 32) = sd->hit;
- WBUFW (buf, 34) = sd->flee;
- WBUFW (buf, 36) = sd->flee2 / 10;
- WBUFW (buf, 38) = sd->critical / 10;
- WBUFW (buf, 40) = sd->status.karma;
- WBUFW (buf, 42) = sd->status.manner;
-
- WFIFOSET (fd, packet_len_table[0xbd]);
-
- clif_updatestatus (sd, SP_STR);
- clif_updatestatus (sd, SP_AGI);
- clif_updatestatus (sd, SP_VIT);
- clif_updatestatus (sd, SP_INT);
- clif_updatestatus (sd, SP_DEX);
- clif_updatestatus (sd, SP_LUK);
-
- clif_updatestatus (sd, SP_ATTACKRANGE);
- clif_updatestatus (sd, SP_ASPD);
+ WFIFOW(fd, 0) = 0xbd;
+ WFIFOW(fd, 2) = sd->status.status_point;
+
+ WFIFOB(fd, 4) = min(sd->status.attrs[ATTR::STR], 255);
+ WFIFOB(fd, 5) = pc_need_status_point(sd, SP::STR);
+ WFIFOB(fd, 6) = min(sd->status.attrs[ATTR::AGI], 255);
+ WFIFOB(fd, 7) = pc_need_status_point(sd, SP::AGI);
+ WFIFOB(fd, 8) = min(sd->status.attrs[ATTR::VIT], 255);
+ WFIFOB(fd, 9) = pc_need_status_point(sd, SP::VIT);
+ WFIFOB(fd, 10) = min(sd->status.attrs[ATTR::INT], 255);
+ WFIFOB(fd, 11) = pc_need_status_point(sd, SP::INT);
+ WFIFOB(fd, 12) = min(sd->status.attrs[ATTR::DEX], 255);
+ WFIFOB(fd, 13) = pc_need_status_point(sd, SP::DEX);
+ WFIFOB(fd, 14) = min(sd->status.attrs[ATTR::LUK], 255);
+ WFIFOB(fd, 15) = pc_need_status_point(sd, SP::LUK);
+
+ WFIFOW(fd, 16) = sd->base_atk + sd->watk;
+ WFIFOW(fd, 18) = sd->watk2; //atk bonus
+ WFIFOW(fd, 20) = sd->matk1;
+ WFIFOW(fd, 22) = sd->matk2;
+ WFIFOW(fd, 24) = sd->def; // def
+ WFIFOW(fd, 26) = sd->def2;
+ WFIFOW(fd, 28) = sd->mdef; // mdef
+ WFIFOW(fd, 30) = sd->mdef2;
+ WFIFOW(fd, 32) = sd->hit;
+ WFIFOW(fd, 34) = sd->flee;
+ WFIFOW(fd, 36) = sd->flee2 / 10;
+ WFIFOW(fd, 38) = sd->critical / 10;
+ WFIFOW(fd, 40) = sd->status.karma;
+ WFIFOW(fd, 42) = sd->status.manner;
+
+ WFIFOSET(fd, clif_parse_func_table[0xbd].len);
+
+ clif_updatestatus(sd, SP::STR);
+ clif_updatestatus(sd, SP::AGI);
+ clif_updatestatus(sd, SP::VIT);
+ clif_updatestatus(sd, SP::INT);
+ clif_updatestatus(sd, SP::DEX);
+ clif_updatestatus(sd, SP::LUK);
+
+ clif_updatestatus(sd, SP::ATTACKRANGE);
+ clif_updatestatus(sd, SP::ASPD);
return 0;
}
@@ -2746,20 +2142,20 @@ int clif_initialstatus (struct map_session_data *sd)
*矢装備
*------------------------------------------
*/
-int clif_arrowequip (struct map_session_data *sd, int val)
+int clif_arrowequip(struct map_session_data *sd, int val)
{
- int fd;
+ int fd;
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
if (sd->attacktarget && sd->attacktarget > 0) // [Valaris]
sd->attacktarget = 0;
fd = sd->fd;
- WFIFOW (fd, 0) = 0x013c;
- WFIFOW (fd, 2) = val + 2; //矢ã®ã‚¢ã‚¤ãƒ†ãƒ ID
+ WFIFOW(fd, 0) = 0x013c;
+ WFIFOW(fd, 2) = val + 2; //矢ã®ã‚¢ã‚¤ãƒ†ãƒ ID
- WFIFOSET (fd, packet_len_table[0x013c]);
+ WFIFOSET(fd, clif_parse_func_table[0x013c].len);
return 0;
}
@@ -2768,17 +2164,17 @@ int clif_arrowequip (struct map_session_data *sd, int val)
*
*------------------------------------------
*/
-int clif_arrow_fail (struct map_session_data *sd, int type)
+int clif_arrow_fail(struct map_session_data *sd, int type)
{
- int fd;
+ int fd;
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
fd = sd->fd;
- WFIFOW (fd, 0) = 0x013b;
- WFIFOW (fd, 2) = type;
+ WFIFOW(fd, 0) = 0x013b;
+ WFIFOW(fd, 2) = type;
- WFIFOSET (fd, packet_len_table[0x013b]);
+ WFIFOSET(fd, clif_parse_func_table[0x013b].len);
return 0;
}
@@ -2787,18 +2183,18 @@ int clif_arrow_fail (struct map_session_data *sd, int type)
*
*------------------------------------------
*/
-int clif_statusupack (struct map_session_data *sd, int type, int ok, int val)
+int clif_statusupack(struct map_session_data *sd, SP type, int ok, int val)
{
- int fd;
+ int fd;
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
fd = sd->fd;
- WFIFOW (fd, 0) = 0xbc;
- WFIFOW (fd, 2) = type;
- WFIFOB (fd, 4) = ok;
- WFIFOB (fd, 5) = val;
- WFIFOSET (fd, packet_len_table[0xbc]);
+ WFIFOW(fd, 0) = 0xbc;
+ WFIFOW(fd, 2) = uint16_t(type);
+ WFIFOB(fd, 4) = ok;
+ WFIFOB(fd, 5) = val;
+ WFIFOSET(fd, clif_parse_func_table[0xbc].len);
return 0;
}
@@ -2807,18 +2203,18 @@ int clif_statusupack (struct map_session_data *sd, int type, int ok, int val)
*
*------------------------------------------
*/
-int clif_equipitemack (struct map_session_data *sd, int n, int pos, int ok)
+int clif_equipitemack(struct map_session_data *sd, int n, EPOS pos, int ok)
{
- int fd;
+ int fd;
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
fd = sd->fd;
- WFIFOW (fd, 0) = 0xaa;
- WFIFOW (fd, 2) = n + 2;
- WFIFOW (fd, 4) = pos;
- WFIFOB (fd, 6) = ok;
- WFIFOSET (fd, packet_len_table[0xaa]);
+ WFIFOW(fd, 0) = 0xaa;
+ WFIFOW(fd, 2) = n + 2;
+ WFIFOW(fd, 4) = uint16_t(pos);
+ WFIFOB(fd, 6) = ok;
+ WFIFOSET(fd, clif_parse_func_table[0xaa].len);
return 0;
}
@@ -2827,18 +2223,18 @@ int clif_equipitemack (struct map_session_data *sd, int n, int pos, int ok)
*
*------------------------------------------
*/
-int clif_unequipitemack (struct map_session_data *sd, int n, int pos, int ok)
+int clif_unequipitemack(struct map_session_data *sd, int n, EPOS pos, int ok)
{
- int fd;
+ int fd;
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
fd = sd->fd;
- WFIFOW (fd, 0) = 0xac;
- WFIFOW (fd, 2) = n + 2;
- WFIFOW (fd, 4) = pos;
- WFIFOB (fd, 6) = ok;
- WFIFOSET (fd, packet_len_table[0xac]);
+ WFIFOW(fd, 0) = 0xac;
+ WFIFOW(fd, 2) = n + 2;
+ WFIFOW(fd, 4) = uint16_t(pos);
+ WFIFOB(fd, 6) = ok;
+ WFIFOSET(fd, clif_parse_func_table[0xac].len);
return 0;
}
@@ -2847,17 +2243,17 @@ int clif_unequipitemack (struct map_session_data *sd, int n, int pos, int ok)
*
*------------------------------------------
*/
-int clif_misceffect (struct block_list *bl, int type)
+int clif_misceffect(struct block_list *bl, int type)
{
uint8_t buf[32];
- nullpo_retr (0, bl);
+ nullpo_ret(bl);
- WBUFW (buf, 0) = 0x19b;
- WBUFL (buf, 2) = bl->id;
- WBUFL (buf, 6) = type;
+ WBUFW(buf, 0) = 0x19b;
+ WBUFL(buf, 2) = bl->id;
+ WBUFL(buf, 6) = type;
- clif_send (buf, packet_len_table[0x19b], bl, AREA);
+ clif_send(buf, clif_parse_func_table[0x19b].len, bl, SendWho::AREA);
return 0;
}
@@ -2866,54 +2262,24 @@ int clif_misceffect (struct block_list *bl, int type)
* 表示オプション変更
*------------------------------------------
*/
-int clif_changeoption (struct block_list *bl)
+int clif_changeoption(struct block_list *bl)
{
uint8_t buf[32];
- short option;
- struct status_change *sc_data;
- static const int omask[] = { 0x10, 0x20 };
- static const int scnum[] = { SC_FALCON, SC_RIDING };
- int i;
-
- nullpo_retr (0, bl);
-
- option = *battle_get_option (bl);
- sc_data = battle_get_sc_data (bl);
-
- WBUFW (buf, 0) = 0x119;
- WBUFL (buf, 2) = bl->id;
- WBUFW (buf, 6) = *battle_get_opt1 (bl);
- WBUFW (buf, 8) = *battle_get_opt2 (bl);
- WBUFW (buf, 10) = option;
- WBUFB (buf, 12) = 0; // ??
-
- if (bl->type == BL_PC)
- { // disguises [Valaris]
- struct map_session_data *sd = ((struct map_session_data *) bl);
- if (sd && sd->disguise > 23 && sd->disguise < 4001)
- {
- clif_send (buf, packet_len_table[0x119], bl, AREA_WOS);
- clif_spawnpc (sd);
- }
- else
- clif_send (buf, packet_len_table[0x119], bl, AREA);
- }
- else
- clif_send (buf, packet_len_table[0x119], bl, AREA);
+ eptr<struct status_change, StatusChange> sc_data;
- // アイコンã®è¡¨ç¤º
- for (i = 0; i < sizeof (omask) / sizeof (omask[0]); i++)
- {
- if (option & omask[i])
- {
- if (sc_data[scnum[i]].timer == -1)
- skill_status_change_start (bl, scnum[i], 0, 0, 0, 0, 0, 0);
- }
- else
- {
- skill_status_change_end (bl, scnum[i], -1);
- }
- }
+ nullpo_ret(bl);
+
+ Option option = *battle_get_option(bl);
+ sc_data = battle_get_sc_data(bl);
+
+ WBUFW(buf, 0) = 0x119;
+ WBUFL(buf, 2) = bl->id;
+ WBUFW(buf, 6) = uint16_t(*battle_get_opt1(bl));
+ WBUFW(buf, 8) = uint16_t(*battle_get_opt2(bl));
+ WBUFW(buf, 10) = uint16_t(option);
+ WBUFB(buf, 12) = 0; // ??
+
+ clif_send(buf, clif_parse_func_table[0x119].len, bl, SendWho::AREA);
return 0;
}
@@ -2922,244 +2288,36 @@ int clif_changeoption (struct block_list *bl)
*
*------------------------------------------
*/
-int clif_useitemack (struct map_session_data *sd, int index, int amount,
+int clif_useitemack(struct map_session_data *sd, int index, int amount,
int ok)
{
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
if (!ok)
{
- int fd = sd->fd;
- WFIFOW (fd, 0) = 0xa8;
- WFIFOW (fd, 2) = index + 2;
- WFIFOW (fd, 4) = amount;
- WFIFOB (fd, 6) = ok;
- WFIFOSET (fd, packet_len_table[0xa8]);
+ int fd = sd->fd;
+ WFIFOW(fd, 0) = 0xa8;
+ WFIFOW(fd, 2) = index + 2;
+ WFIFOW(fd, 4) = amount;
+ WFIFOB(fd, 6) = ok;
+ WFIFOSET(fd, clif_parse_func_table[0xa8].len);
}
else
{
uint8_t buf[32];
- WBUFW (buf, 0) = 0x1c8;
- WBUFW (buf, 2) = index + 2;
+ WBUFW(buf, 0) = 0x1c8;
+ WBUFW(buf, 2) = index + 2;
if (sd->inventory_data[index]
&& sd->inventory_data[index]->view_id > 0)
- WBUFW (buf, 4) = sd->inventory_data[index]->view_id;
+ WBUFW(buf, 4) = sd->inventory_data[index]->view_id;
else
- WBUFW (buf, 4) = sd->status.inventory[index].nameid;
- WBUFL (buf, 6) = sd->bl.id;
- WBUFW (buf, 10) = amount;
- WBUFB (buf, 12) = ok;
- clif_send (buf, packet_len_table[0x1c8], &sd->bl, SELF);
- }
-
- return 0;
-}
-
-/*==========================================
- *
- *------------------------------------------
- */
-int clif_createchat (struct map_session_data *sd, int fail)
-{
- int fd;
-
- nullpo_retr (0, sd);
-
- fd = sd->fd;
- WFIFOW (fd, 0) = 0xd6;
- WFIFOB (fd, 2) = fail;
- WFIFOSET (fd, packet_len_table[0xd6]);
-
- return 0;
-}
-
-/*==========================================
- *
- *------------------------------------------
- */
-int clif_dispchat (struct chat_data *cd, int fd)
-{
- uint8_t buf[128]; // 最大title(60ãƒã‚¤ãƒˆ)+17
-
- if (cd == NULL || *cd->owner == NULL)
- return 1;
-
- WBUFW (buf, 0) = 0xd7;
- WBUFW (buf, 2) = strlen (cd->title) + 17;
- WBUFL (buf, 4) = (*cd->owner)->id;
- WBUFL (buf, 8) = cd->bl.id;
- WBUFW (buf, 12) = cd->limit;
- WBUFW (buf, 14) = cd->users;
- WBUFB (buf, 16) = cd->pub;
- strcpy ((char *)WBUFP (buf, 17), cd->title);
- if (fd)
- {
- memcpy (WFIFOP (fd, 0), buf, WBUFW (buf, 2));
- WFIFOSET (fd, WBUFW (buf, 2));
- }
- else
- {
- clif_send (buf, WBUFW (buf, 2), *cd->owner, AREA_WOSC);
- }
-
- return 0;
-}
-
-/*==========================================
- * chatã®çŠ¶æ…‹å¤‰æ›´æˆåŠŸ
- * 外部ã®äººç”¨ã¨å‘½ä»¤ã‚³ãƒ¼ãƒ‰(d7->df)ãŒé•ã†ã ã‘
- *------------------------------------------
- */
-int clif_changechatstatus (struct chat_data *cd)
-{
- uint8_t buf[128]; // 最大title(60ãƒã‚¤ãƒˆ)+17
-
- if (cd == NULL || cd->usersd[0] == NULL)
- return 1;
-
- WBUFW (buf, 0) = 0xdf;
- WBUFW (buf, 2) = strlen (cd->title) + 17;
- WBUFL (buf, 4) = cd->usersd[0]->bl.id;
- WBUFL (buf, 8) = cd->bl.id;
- WBUFW (buf, 12) = cd->limit;
- WBUFW (buf, 14) = cd->users;
- WBUFB (buf, 16) = cd->pub;
- strcpy ((char *)WBUFP (buf, 17), cd->title);
- clif_send (buf, WBUFW (buf, 2), &cd->usersd[0]->bl, CHAT);
-
- return 0;
-}
-
-/*==========================================
- *
- *------------------------------------------
- */
-int clif_clearchat (struct chat_data *cd, int fd)
-{
- uint8_t buf[32];
-
- nullpo_retr (0, cd);
-
- WBUFW (buf, 0) = 0xd8;
- WBUFL (buf, 2) = cd->bl.id;
- if (fd)
- {
- memcpy (WFIFOP (fd, 0), buf, packet_len_table[0xd8]);
- WFIFOSET (fd, packet_len_table[0xd8]);
- }
- else
- {
- clif_send (buf, packet_len_table[0xd8], *cd->owner, AREA_WOSC);
- }
-
- return 0;
-}
-
-/*==========================================
- *
- *------------------------------------------
- */
-int clif_joinchatfail (struct map_session_data *sd, int fail)
-{
- int fd;
-
- nullpo_retr (0, sd);
-
- fd = sd->fd;
-
- WFIFOW (fd, 0) = 0xda;
- WFIFOB (fd, 2) = fail;
- WFIFOSET (fd, packet_len_table[0xda]);
-
- return 0;
-}
-
-/*==========================================
- *
- *------------------------------------------
- */
-int clif_joinchatok (struct map_session_data *sd, struct chat_data *cd)
-{
- int fd;
- int i;
-
- nullpo_retr (0, sd);
- nullpo_retr (0, cd);
-
- fd = sd->fd;
- WFIFOW (fd, 0) = 0xdb;
- WFIFOW (fd, 2) = 8 + (28 * cd->users);
- WFIFOL (fd, 4) = cd->bl.id;
- for (i = 0; i < cd->users; i++)
- {
- WFIFOL (fd, 8 + i * 28) = (i != 0) || ((*cd->owner)->type == BL_NPC);
- memcpy (WFIFOP (fd, 8 + i * 28 + 4), cd->usersd[i]->status.name, 24);
+ WBUFW(buf, 4) = sd->status.inventory[index].nameid;
+ WBUFL(buf, 6) = sd->bl.id;
+ WBUFW(buf, 10) = amount;
+ WBUFB(buf, 12) = ok;
+ clif_send(buf, clif_parse_func_table[0x1c8].len, &sd->bl, SendWho::SELF);
}
- WFIFOSET (fd, WFIFOW (fd, 2));
-
- return 0;
-}
-
-/*==========================================
- *
- *------------------------------------------
- */
-int clif_addchat (struct chat_data *cd, struct map_session_data *sd)
-{
- uint8_t buf[32];
-
- nullpo_retr (0, sd);
- nullpo_retr (0, cd);
-
- WBUFW (buf, 0) = 0x0dc;
- WBUFW (buf, 2) = cd->users;
- memcpy (WBUFP (buf, 4), sd->status.name, 24);
- clif_send (buf, packet_len_table[0xdc], &sd->bl, CHAT_WOS);
-
- return 0;
-}
-
-/*==========================================
- *
- *------------------------------------------
- */
-int clif_changechatowner (struct chat_data *cd, struct map_session_data *sd)
-{
- uint8_t buf[64];
-
- nullpo_retr (0, sd);
- nullpo_retr (0, cd);
-
- WBUFW (buf, 0) = 0xe1;
- WBUFL (buf, 2) = 1;
- memcpy (WBUFP (buf, 6), cd->usersd[0]->status.name, 24);
- WBUFW (buf, 30) = 0xe1;
- WBUFL (buf, 32) = 0;
- memcpy (WBUFP (buf, 36), sd->status.name, 24);
-
- clif_send (buf, packet_len_table[0xe1] * 2, &sd->bl, CHAT);
-
- return 0;
-}
-
-/*==========================================
- *
- *------------------------------------------
- */
-int clif_leavechat (struct chat_data *cd, struct map_session_data *sd)
-{
- uint8_t buf[32];
-
- nullpo_retr (0, sd);
- nullpo_retr (0, cd);
-
- WBUFW (buf, 0) = 0xdd;
- WBUFW (buf, 2) = cd->users - 1;
- memcpy (WBUFP (buf, 4), sd->status.name, 24);
- WBUFB (buf, 28) = 0;
-
- clif_send (buf, packet_len_table[0xdd], &sd->bl, CHAT);
return 0;
}
@@ -3168,16 +2326,16 @@ int clif_leavechat (struct chat_data *cd, struct map_session_data *sd)
* å–り引ãè¦è«‹å—ã‘
*------------------------------------------
*/
-int clif_traderequest (struct map_session_data *sd, const char *name)
+int clif_traderequest(struct map_session_data *sd, const char *name)
{
- int fd;
+ int fd;
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
fd = sd->fd;
- WFIFOW (fd, 0) = 0xe5;
- strcpy ((char *)WFIFOP (fd, 2), name);
- WFIFOSET (fd, packet_len_table[0xe5]);
+ WFIFOW(fd, 0) = 0xe5;
+ strcpy((char *)WFIFOP(fd, 2), name);
+ WFIFOSET(fd, clif_parse_func_table[0xe5].len);
return 0;
}
@@ -3186,16 +2344,16 @@ int clif_traderequest (struct map_session_data *sd, const char *name)
* å–り引ãè¦æ±‚応答
*------------------------------------------
*/
-int clif_tradestart (struct map_session_data *sd, int type)
+int clif_tradestart(struct map_session_data *sd, int type)
{
- int fd;
+ int fd;
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
fd = sd->fd;
- WFIFOW (fd, 0) = 0xe7;
- WFIFOB (fd, 2) = type;
- WFIFOSET (fd, packet_len_table[0xe7]);
+ WFIFOW(fd, 0) = 0xe7;
+ WFIFOB(fd, 2) = type;
+ WFIFOSET(fd, clif_parse_func_table[0xe7].len);
return 0;
}
@@ -3204,80 +2362,80 @@ int clif_tradestart (struct map_session_data *sd, int type)
* 相手方ã‹ã‚‰ã®ã‚¢ã‚¤ãƒ†ãƒ è¿½åŠ 
*------------------------------------------
*/
-int clif_tradeadditem (struct map_session_data *sd,
+int clif_tradeadditem(struct map_session_data *sd,
struct map_session_data *tsd, int index, int amount)
{
- int fd, j;
+ int fd, j;
- nullpo_retr (0, sd);
- nullpo_retr (0, tsd);
+ nullpo_ret(sd);
+ nullpo_ret(tsd);
fd = tsd->fd;
- WFIFOW (fd, 0) = 0xe9;
- WFIFOL (fd, 2) = amount;
+ WFIFOW(fd, 0) = 0xe9;
+ WFIFOL(fd, 2) = amount;
if (index == 0)
{
- WFIFOW (fd, 6) = 0; // type id
- WFIFOB (fd, 8) = 0; //identify flag
- WFIFOB (fd, 9) = 0; // attribute
- WFIFOB (fd, 10) = 0; //refine
- WFIFOW (fd, 11) = 0; //card (4w)
- WFIFOW (fd, 13) = 0; //card (4w)
- WFIFOW (fd, 15) = 0; //card (4w)
- WFIFOW (fd, 17) = 0; //card (4w)
+ WFIFOW(fd, 6) = 0; // type id
+ WFIFOB(fd, 8) = 0; //identify flag
+ WFIFOB(fd, 9) = 0; // attribute
+ WFIFOB(fd, 10) = 0; //refine
+ WFIFOW(fd, 11) = 0; //card (4w)
+ WFIFOW(fd, 13) = 0; //card (4w)
+ WFIFOW(fd, 15) = 0; //card (4w)
+ WFIFOW(fd, 17) = 0; //card (4w)
}
else
{
index -= 2;
if (sd->inventory_data[index]
&& sd->inventory_data[index]->view_id > 0)
- WFIFOW (fd, 6) = sd->inventory_data[index]->view_id;
+ WFIFOW(fd, 6) = sd->inventory_data[index]->view_id;
else
- WFIFOW (fd, 6) = sd->status.inventory[index].nameid; // type id
- WFIFOB (fd, 8) = sd->status.inventory[index].identify; //identify flag
+ WFIFOW(fd, 6) = sd->status.inventory[index].nameid; // type id
+ WFIFOB(fd, 8) = sd->status.inventory[index].identify; //identify flag
if (sd->status.inventory[index].broken == 1)
- WFIFOB (fd, 9) = 1; // is broke weapon [Valaris]
+ WFIFOB(fd, 9) = 1; // is broke weapon [Valaris]
else
- WFIFOB (fd, 9) = sd->status.inventory[index].attribute; // attribute
- WFIFOB (fd, 10) = sd->status.inventory[index].refine; //refine
+ WFIFOB(fd, 9) = sd->status.inventory[index].attribute; // attribute
+ WFIFOB(fd, 10) = sd->status.inventory[index].refine; //refine
if (sd->status.inventory[index].card[0] == 0x00ff
|| sd->status.inventory[index].card[0] == 0x00fe
|| sd->status.inventory[index].card[0] == (short) 0xff00)
{
- WFIFOW (fd, 11) = sd->status.inventory[index].card[0]; //card (4w)
- WFIFOW (fd, 13) = sd->status.inventory[index].card[1]; //card (4w)
- WFIFOW (fd, 15) = sd->status.inventory[index].card[2]; //card (4w)
- WFIFOW (fd, 17) = sd->status.inventory[index].card[3]; //card (4w)
+ WFIFOW(fd, 11) = sd->status.inventory[index].card[0]; //card (4w)
+ WFIFOW(fd, 13) = sd->status.inventory[index].card[1]; //card (4w)
+ WFIFOW(fd, 15) = sd->status.inventory[index].card[2]; //card (4w)
+ WFIFOW(fd, 17) = sd->status.inventory[index].card[3]; //card (4w)
}
else
{
if (sd->status.inventory[index].card[0] > 0
&& (j =
- itemdb_viewid (sd->status.inventory[index].card[0])) > 0)
- WFIFOW (fd, 11) = j;
+ itemdb_viewid(sd->status.inventory[index].card[0])) > 0)
+ WFIFOW(fd, 11) = j;
else
- WFIFOW (fd, 11) = sd->status.inventory[index].card[0];
+ WFIFOW(fd, 11) = sd->status.inventory[index].card[0];
if (sd->status.inventory[index].card[1] > 0
&& (j =
- itemdb_viewid (sd->status.inventory[index].card[1])) > 0)
- WFIFOW (fd, 13) = j;
+ itemdb_viewid(sd->status.inventory[index].card[1])) > 0)
+ WFIFOW(fd, 13) = j;
else
- WFIFOW (fd, 13) = sd->status.inventory[index].card[1];
+ WFIFOW(fd, 13) = sd->status.inventory[index].card[1];
if (sd->status.inventory[index].card[2] > 0
&& (j =
- itemdb_viewid (sd->status.inventory[index].card[2])) > 0)
- WFIFOW (fd, 15) = j;
+ itemdb_viewid(sd->status.inventory[index].card[2])) > 0)
+ WFIFOW(fd, 15) = j;
else
- WFIFOW (fd, 15) = sd->status.inventory[index].card[2];
+ WFIFOW(fd, 15) = sd->status.inventory[index].card[2];
if (sd->status.inventory[index].card[3] > 0
&& (j =
- itemdb_viewid (sd->status.inventory[index].card[3])) > 0)
- WFIFOW (fd, 17) = j;
+ itemdb_viewid(sd->status.inventory[index].card[3])) > 0)
+ WFIFOW(fd, 17) = j;
else
- WFIFOW (fd, 17) = sd->status.inventory[index].card[3];
+ WFIFOW(fd, 17) = sd->status.inventory[index].card[3];
}
}
- WFIFOSET (fd, packet_len_table[0xe9]);
+ WFIFOSET(fd, clif_parse_func_table[0xe9].len);
return 0;
}
@@ -3286,20 +2444,19 @@ int clif_tradeadditem (struct map_session_data *sd,
* アイテム追加æˆåŠŸ/失敗
*------------------------------------------
*/
-int clif_tradeitemok (struct map_session_data *sd, int index, int amount,
+int clif_tradeitemok(struct map_session_data *sd, int index, int amount,
int fail)
{
- int fd;
+ int fd;
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
fd = sd->fd;
- WFIFOW (fd, 0) = 0x1b1;
- //WFIFOW(fd,0)=0xea;
- WFIFOW (fd, 2) = index;
- WFIFOW (fd, 4) = amount;
- WFIFOB (fd, 6) = fail;
- WFIFOSET (fd, packet_len_table[0x1b1]);
+ WFIFOW(fd, 0) = 0x1b1;
+ WFIFOW(fd, 2) = index;
+ WFIFOW(fd, 4) = amount;
+ WFIFOB(fd, 6) = fail;
+ WFIFOSET(fd, clif_parse_func_table[0x1b1].len);
return 0;
}
@@ -3308,16 +2465,16 @@ int clif_tradeitemok (struct map_session_data *sd, int index, int amount,
* å–り引ãok押ã—
*------------------------------------------
*/
-int clif_tradedeal_lock (struct map_session_data *sd, int fail)
+int clif_tradedeal_lock(struct map_session_data *sd, int fail)
{
- int fd;
+ int fd;
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
fd = sd->fd;
- WFIFOW (fd, 0) = 0xec;
- WFIFOB (fd, 2) = fail; // 0=you 1=the other person
- WFIFOSET (fd, packet_len_table[0xec]);
+ WFIFOW(fd, 0) = 0xec;
+ WFIFOB(fd, 2) = fail; // 0=you 1=the other person
+ WFIFOSET(fd, clif_parse_func_table[0xec].len);
return 0;
}
@@ -3326,15 +2483,15 @@ int clif_tradedeal_lock (struct map_session_data *sd, int fail)
* å–り引ããŒã‚­ãƒ£ãƒ³ã‚»ãƒ«ã•ã‚Œã¾ã—ãŸ
*------------------------------------------
*/
-int clif_tradecancelled (struct map_session_data *sd)
+int clif_tradecancelled(struct map_session_data *sd)
{
- int fd;
+ int fd;
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
fd = sd->fd;
- WFIFOW (fd, 0) = 0xee;
- WFIFOSET (fd, packet_len_table[0xee]);
+ WFIFOW(fd, 0) = 0xee;
+ WFIFOSET(fd, clif_parse_func_table[0xee].len);
return 0;
}
@@ -3343,16 +2500,16 @@ int clif_tradecancelled (struct map_session_data *sd)
* å–り引ã完了
*------------------------------------------
*/
-int clif_tradecompleted (struct map_session_data *sd, int fail)
+int clif_tradecompleted(struct map_session_data *sd, int fail)
{
- int fd;
+ int fd;
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
fd = sd->fd;
- WFIFOW (fd, 0) = 0xf0;
- WFIFOB (fd, 2) = fail;
- WFIFOSET (fd, packet_len_table[0xf0]);
+ WFIFOW(fd, 0) = 0xf0;
+ WFIFOB(fd, 2) = fail;
+ WFIFOSET(fd, clif_parse_func_table[0xf0].len);
return 0;
}
@@ -3361,19 +2518,19 @@ int clif_tradecompleted (struct map_session_data *sd, int fail)
* カプラ倉庫ã®ã‚¢ã‚¤ãƒ†ãƒ æ•°ã‚’æ›´æ–°
*------------------------------------------
*/
-int clif_updatestorageamount (struct map_session_data *sd,
+int clif_updatestorageamount(struct map_session_data *sd,
struct storage *stor)
{
- int fd;
+ int fd;
- nullpo_retr (0, sd);
- nullpo_retr (0, stor);
+ nullpo_ret(sd);
+ nullpo_ret(stor);
fd = sd->fd;
- WFIFOW (fd, 0) = 0xf2; // update storage amount
- WFIFOW (fd, 2) = stor->storage_amount; //items
- WFIFOW (fd, 4) = MAX_STORAGE; //items max
- WFIFOSET (fd, packet_len_table[0xf2]);
+ WFIFOW(fd, 0) = 0xf2; // update storage amount
+ WFIFOW(fd, 2) = stor->storage_amount; //items
+ WFIFOW(fd, 4) = MAX_STORAGE; //items max
+ WFIFOSET(fd, clif_parse_func_table[0xf2].len);
return 0;
}
@@ -3382,146 +2539,61 @@ int clif_updatestorageamount (struct map_session_data *sd,
* カプラ倉庫ã«ã‚¢ã‚¤ãƒ†ãƒ ã‚’追加ã™ã‚‹
*------------------------------------------
*/
-int clif_storageitemadded (struct map_session_data *sd, struct storage *stor,
+int clif_storageitemadded(struct map_session_data *sd, struct storage *stor,
int index, int amount)
{
- int fd, j;
-
- nullpo_retr (0, sd);
- nullpo_retr (0, stor);
-
- fd = sd->fd;
- WFIFOW (fd, 0) = 0xf4; // Storage item added
- WFIFOW (fd, 2) = index + 1; // index
- WFIFOL (fd, 4) = amount; // amount
-/* if((view = itemdb_viewid(stor->storage_[index].nameid)) > 0)
- WFIFOW(fd,8) =view;
- else*/
- WFIFOW (fd, 8) = stor->storage_[index].nameid;
- WFIFOB (fd, 10) = stor->storage_[index].identify; //identify flag
- if (stor->storage_[index].broken == 1)
- WFIFOB (fd, 11) = 1; // is weapon broken [Valaris]
- else
- WFIFOB (fd, 11) = stor->storage_[index].attribute; // attribute
- WFIFOB (fd, 12) = stor->storage_[index].refine; //refine
- if (stor->storage_[index].card[0] == 0x00ff
- || stor->storage_[index].card[0] == 0x00fe
- || stor->storage_[index].card[0] == (short) 0xff00)
- {
- WFIFOW (fd, 13) = stor->storage_[index].card[0]; //card (4w)
- WFIFOW (fd, 15) = stor->storage_[index].card[1]; //card (4w)
- WFIFOW (fd, 17) = stor->storage_[index].card[2]; //card (4w)
- WFIFOW (fd, 19) = stor->storage_[index].card[3]; //card (4w)
- }
- else
- {
- if (stor->storage_[index].card[0] > 0
- && (j = itemdb_viewid (stor->storage_[index].card[0])) > 0)
- WFIFOW (fd, 13) = j;
- else
- WFIFOW (fd, 13) = stor->storage_[index].card[0];
- if (stor->storage_[index].card[1] > 0
- && (j = itemdb_viewid (stor->storage_[index].card[1])) > 0)
- WFIFOW (fd, 15) = j;
- else
- WFIFOW (fd, 15) = stor->storage_[index].card[1];
- if (stor->storage_[index].card[2] > 0
- && (j = itemdb_viewid (stor->storage_[index].card[2])) > 0)
- WFIFOW (fd, 17) = j;
- else
- WFIFOW (fd, 17) = stor->storage_[index].card[2];
- if (stor->storage_[index].card[3] > 0
- && (j = itemdb_viewid (stor->storage_[index].card[3])) > 0)
- WFIFOW (fd, 19) = j;
- else
- WFIFOW (fd, 19) = stor->storage_[index].card[3];
- }
- WFIFOSET (fd, packet_len_table[0xf4]);
-
- return 0;
-}
-
-/*==========================================
- *
- *------------------------------------------
- */
-int clif_updateguildstorageamount (struct map_session_data *sd,
- struct guild_storage *stor)
-{
- int fd;
+ int fd, j;
- nullpo_retr (0, sd);
- nullpo_retr (0, stor);
+ nullpo_ret(sd);
+ nullpo_ret(stor);
fd = sd->fd;
- WFIFOW (fd, 0) = 0xf2; // update storage amount
- WFIFOW (fd, 2) = stor->storage_amount; //items
- WFIFOW (fd, 4) = MAX_GUILD_STORAGE; //items max
- WFIFOSET (fd, packet_len_table[0xf2]);
-
- return 0;
-}
-
-/*==========================================
- *
- *------------------------------------------
- */
-int clif_guildstorageitemadded (struct map_session_data *sd,
- struct guild_storage *stor, int index,
- int amount)
-{
- int view, fd, j;
-
- nullpo_retr (0, sd);
- nullpo_retr (0, stor);
-
- fd = sd->fd;
- WFIFOW (fd, 0) = 0xf4; // Storage item added
- WFIFOW (fd, 2) = index + 1; // index
- WFIFOL (fd, 4) = amount; // amount
- if ((view = itemdb_viewid (stor->storage_[index].nameid)) > 0)
- WFIFOW (fd, 8) = view;
- else
- WFIFOW (fd, 8) = stor->storage_[index].nameid; // id
- WFIFOB (fd, 10) = stor->storage_[index].identify; //identify flag
+ WFIFOW(fd, 0) = 0xf4; // Storage item added
+ WFIFOW(fd, 2) = index + 1; // index
+ WFIFOL(fd, 4) = amount; // amount
+/* if ((view = itemdb_viewid(stor->storage_[index].nameid)) > 0)
+ WFIFOW(fd,8) =view;
+ else*/
+ WFIFOW(fd, 8) = stor->storage_[index].nameid;
+ WFIFOB(fd, 10) = stor->storage_[index].identify; //identify flag
if (stor->storage_[index].broken == 1)
- WFIFOB (fd, 11) = 1; // is weapon broken [Valaris]
+ WFIFOB(fd, 11) = 1; // is weapon broken [Valaris]
else
- WFIFOB (fd, 11) = stor->storage_[index].attribute; // attribute
- WFIFOB (fd, 12) = stor->storage_[index].refine; //refine
+ WFIFOB(fd, 11) = stor->storage_[index].attribute; // attribute
+ WFIFOB(fd, 12) = stor->storage_[index].refine; //refine
if (stor->storage_[index].card[0] == 0x00ff
|| stor->storage_[index].card[0] == 0x00fe
|| stor->storage_[index].card[0] == (short) 0xff00)
{
- WFIFOW (fd, 13) = stor->storage_[index].card[0]; //card (4w)
- WFIFOW (fd, 15) = stor->storage_[index].card[1]; //card (4w)
- WFIFOW (fd, 17) = stor->storage_[index].card[2]; //card (4w)
- WFIFOW (fd, 19) = stor->storage_[index].card[3]; //card (4w)
+ WFIFOW(fd, 13) = stor->storage_[index].card[0]; //card (4w)
+ WFIFOW(fd, 15) = stor->storage_[index].card[1]; //card (4w)
+ WFIFOW(fd, 17) = stor->storage_[index].card[2]; //card (4w)
+ WFIFOW(fd, 19) = stor->storage_[index].card[3]; //card (4w)
}
else
{
if (stor->storage_[index].card[0] > 0
- && (j = itemdb_viewid (stor->storage_[index].card[0])) > 0)
- WFIFOW (fd, 13) = j;
+ && (j = itemdb_viewid(stor->storage_[index].card[0])) > 0)
+ WFIFOW(fd, 13) = j;
else
- WFIFOW (fd, 13) = stor->storage_[index].card[0];
+ WFIFOW(fd, 13) = stor->storage_[index].card[0];
if (stor->storage_[index].card[1] > 0
- && (j = itemdb_viewid (stor->storage_[index].card[1])) > 0)
- WFIFOW (fd, 15) = j;
+ && (j = itemdb_viewid(stor->storage_[index].card[1])) > 0)
+ WFIFOW(fd, 15) = j;
else
- WFIFOW (fd, 15) = stor->storage_[index].card[1];
+ WFIFOW(fd, 15) = stor->storage_[index].card[1];
if (stor->storage_[index].card[2] > 0
- && (j = itemdb_viewid (stor->storage_[index].card[2])) > 0)
- WFIFOW (fd, 17) = j;
+ && (j = itemdb_viewid(stor->storage_[index].card[2])) > 0)
+ WFIFOW(fd, 17) = j;
else
- WFIFOW (fd, 17) = stor->storage_[index].card[2];
+ WFIFOW(fd, 17) = stor->storage_[index].card[2];
if (stor->storage_[index].card[3] > 0
- && (j = itemdb_viewid (stor->storage_[index].card[3])) > 0)
- WFIFOW (fd, 19) = j;
+ && (j = itemdb_viewid(stor->storage_[index].card[3])) > 0)
+ WFIFOW(fd, 19) = j;
else
- WFIFOW (fd, 19) = stor->storage_[index].card[3];
+ WFIFOW(fd, 19) = stor->storage_[index].card[3];
}
- WFIFOSET (fd, packet_len_table[0xf4]);
+ WFIFOSET(fd, clif_parse_func_table[0xf4].len);
return 0;
}
@@ -3530,18 +2602,18 @@ int clif_guildstorageitemadded (struct map_session_data *sd,
* カプラ倉庫ã‹ã‚‰ã‚¢ã‚¤ãƒ†ãƒ ã‚’å–り去る
*------------------------------------------
*/
-int clif_storageitemremoved (struct map_session_data *sd, int index,
+int clif_storageitemremoved(struct map_session_data *sd, int index,
int amount)
{
- int fd;
+ int fd;
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
fd = sd->fd;
- WFIFOW (fd, 0) = 0xf6; // Storage item removed
- WFIFOW (fd, 2) = index + 1;
- WFIFOL (fd, 4) = amount;
- WFIFOSET (fd, packet_len_table[0xf6]);
+ WFIFOW(fd, 0) = 0xf6; // Storage item removed
+ WFIFOW(fd, 2) = index + 1;
+ WFIFOL(fd, 4) = amount;
+ WFIFOSET(fd, clif_parse_func_table[0xf6].len);
return 0;
}
@@ -3550,27 +2622,24 @@ int clif_storageitemremoved (struct map_session_data *sd, int index,
* カプラ倉庫を閉ã˜ã‚‹
*------------------------------------------
*/
-int clif_storageclose (struct map_session_data *sd)
+int clif_storageclose(struct map_session_data *sd)
{
- int fd;
+ int fd;
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
fd = sd->fd;
- WFIFOW (fd, 0) = 0xf8; // Storage Closed
- WFIFOSET (fd, packet_len_table[0xf8]);
+ WFIFOW(fd, 0) = 0xf8; // Storage Closed
+ WFIFOSET(fd, clif_parse_func_table[0xf8].len);
return 0;
}
-void
-clif_changelook_accessories (struct block_list *bl,
+void clif_changelook_accessories(struct block_list *bl,
struct map_session_data *dest)
{
- int i;
-
- for (i = LOOK_SHOES; i <= LOOK_LAST; i++)
- clif_changelook_towards (bl, i, 0, dest);
+ for (LOOK i = LOOK::SHOES; i < LOOK::COUNT; i = LOOK(uint8_t(i) + 1))
+ clif_changelook_towards(bl, i, 0, dest);
}
//
@@ -3581,49 +2650,34 @@ clif_changelook_accessories (struct block_list *bl,
*------------------------------------------
*/
static
-void clif_getareachar_pc (struct map_session_data *sd,
+void clif_getareachar_pc(struct map_session_data *sd,
struct map_session_data *dstsd)
{
- int len;
+ int len;
- if (dstsd->status.option & OPTION_INVISIBILITY)
+ if (bool(dstsd->status.option & Option::INVISIBILITY))
return;
- nullpo_retv (sd);
- nullpo_retv (dstsd);
+ nullpo_retv(sd);
+ nullpo_retv(dstsd);
- if (dstsd->walktimer != -1)
+ if (dstsd->walktimer)
{
- len = clif_set007b (dstsd, WFIFOP (sd->fd, 0));
- WFIFOSET (sd->fd, len);
+ len = clif_set007b(dstsd, static_cast<uint8_t *>(WFIFOP(sd->fd, 0)));
+ WFIFOSET(sd->fd, len);
}
else
{
- len = clif_set0078 (dstsd, WFIFOP (sd->fd, 0));
- WFIFOSET (sd->fd, len);
+ len = clif_set0078(dstsd, static_cast<uint8_t *>(WFIFOP(sd->fd, 0)));
+ WFIFOSET(sd->fd, len);
}
- if (dstsd->chatID)
- {
- struct chat_data *cd;
- cd = (struct chat_data *) map_id2bl (dstsd->chatID);
- if (cd->usersd[0] == dstsd)
- clif_dispchat (cd, sd->fd);
- }
- if (dstsd->spiritball > 0)
- {
- clif_set01e1 (dstsd, WFIFOP (sd->fd, 0));
- WFIFOSET (sd->fd, packet_len_table[0x1e1]);
- }
if (battle_config.save_clothcolor == 1 && dstsd->status.clothes_color > 0)
- clif_changelook (&dstsd->bl, LOOK_CLOTHES_COLOR,
+ clif_changelook(&dstsd->bl, LOOK::CLOTHES_COLOR,
dstsd->status.clothes_color);
- if (sd->status.manner < 0)
- clif_changestatus (&sd->bl, SP_MANNER, sd->status.manner);
-
- clif_changelook_accessories (&sd->bl, dstsd);
- clif_changelook_accessories (&dstsd->bl, sd);
+ clif_changelook_accessories(&sd->bl, dstsd);
+ clif_changelook_accessories(&dstsd->bl, sd);
}
/*==========================================
@@ -3631,42 +2685,33 @@ void clif_getareachar_pc (struct map_session_data *sd,
*------------------------------------------
*/
static
-void clif_getareachar_npc (struct map_session_data *sd, struct npc_data *nd)
+void clif_getareachar_npc(struct map_session_data *sd, struct npc_data *nd)
{
- int len;
+ int len;
- nullpo_retv (sd);
- nullpo_retv (nd);
+ nullpo_retv(sd);
+ nullpo_retv(nd);
if (nd->npc_class < 0 || nd->flag & 1 || nd->npc_class == INVISIBLE_CLASS)
return;
- len = clif_npc0078 (nd, WFIFOP (sd->fd, 0));
- WFIFOSET (sd->fd, len);
-
- if (nd->chat_id)
- {
- clif_dispchat ((struct chat_data *) map_id2bl (nd->chat_id), sd->fd);
- }
-
+ len = clif_npc0078(nd, static_cast<uint8_t *>(WFIFOP(sd->fd, 0)));
+ WFIFOSET(sd->fd, len);
}
/*==========================================
* 移動åœæ­¢
*------------------------------------------
*/
-int clif_movemob (struct mob_data *md)
+int clif_movemob(struct mob_data *md)
{
unsigned char buf[256];
- int len;
-
- nullpo_retr (0, md);
+ int len;
- len = clif_mob007b (md, buf);
- clif_send (buf, len, &md->bl, AREA);
+ nullpo_ret(md);
- if (mob_get_equip (md->mob_class) > 0) // mob equipment [Valaris]
- clif_mob_equip (md, mob_get_equip (md->mob_class));
+ len = clif_mob007b(md, buf);
+ clif_send(buf, len, &md->bl, SendWho::AREA);
return 0;
}
@@ -3675,22 +2720,22 @@ int clif_movemob (struct mob_data *md)
* モンスターã®ä½ç½®ä¿®æ­£
*------------------------------------------
*/
-int clif_fixmobpos (struct mob_data *md)
+int clif_fixmobpos(struct mob_data *md)
{
unsigned char buf[256];
- int len;
+ int len;
- nullpo_retr (0, md);
+ nullpo_ret(md);
- if (md->state.state == MS_WALK)
+ if (md->state.state == MS::WALK)
{
- len = clif_mob007b (md, buf);
- clif_send (buf, len, &md->bl, AREA);
+ len = clif_mob007b(md, buf);
+ clif_send(buf, len, &md->bl, SendWho::AREA);
}
else
{
- len = clif_mob0078 (md, buf);
- clif_send (buf, len, &md->bl, AREA);
+ len = clif_mob0078(md, buf);
+ clif_send(buf, len, &md->bl, SendWho::AREA);
}
return 0;
@@ -3700,24 +2745,24 @@ int clif_fixmobpos (struct mob_data *md)
* PCã®ä½ç½®ä¿®æ­£
*------------------------------------------
*/
-int clif_fixpcpos (struct map_session_data *sd)
+int clif_fixpcpos(struct map_session_data *sd)
{
unsigned char buf[256];
- int len;
+ int len;
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
- if (sd->walktimer != -1)
+ if (sd->walktimer)
{
- len = clif_set007b (sd, buf);
- clif_send (buf, len, &sd->bl, AREA);
+ len = clif_set007b(sd, buf);
+ clif_send(buf, len, &sd->bl, SendWho::AREA);
}
else
{
- len = clif_set0078 (sd, buf);
- clif_send (buf, len, &sd->bl, AREA);
+ len = clif_set0078(sd, buf);
+ clif_send(buf, len, &sd->bl, SendWho::AREA);
}
- clif_changelook_accessories (&sd->bl, NULL);
+ clif_changelook_accessories(&sd->bl, NULL);
return 0;
}
@@ -3726,49 +2771,29 @@ int clif_fixpcpos (struct map_session_data *sd)
* 通常攻撃エフェクト&ダメージ
*------------------------------------------
*/
-int clif_damage (struct block_list *src, struct block_list *dst,
- unsigned int tick, int sdelay, int ddelay, int damage,
- int div, int type, int damage2)
+int clif_damage(struct block_list *src, struct block_list *dst,
+ tick_t tick, interval_t sdelay, interval_t ddelay, int damage,
+ int div, DamageType type, int damage2)
{
unsigned char buf[256];
- struct status_change *sc_data;
+ eptr<struct status_change, StatusChange> sc_data;
- nullpo_retr (0, src);
- nullpo_retr (0, dst);
+ nullpo_ret(src);
+ nullpo_ret(dst);
- sc_data = battle_get_sc_data (dst);
-
- if (type != 4 && dst->type == BL_PC
- && ((struct map_session_data *) dst)->special_state.infinite_endure)
- type = 9;
- if (sc_data)
- {
- if (type != 4 && sc_data[SC_ENDURE].timer != -1)
- type = 9;
- if (sc_data[SC_HALLUCINATION].timer != -1)
- {
- if (damage > 0)
- damage =
- damage * (5 + sc_data[SC_HALLUCINATION].val1) +
- MRAND (100);
- if (damage2 > 0)
- damage2 =
- damage2 * (5 + sc_data[SC_HALLUCINATION].val1) +
- MRAND (100);
- }
- }
+ sc_data = battle_get_sc_data(dst);
- WBUFW (buf, 0) = 0x8a;
- WBUFL (buf, 2) = src->id;
- WBUFL (buf, 6) = dst->id;
- WBUFL (buf, 10) = tick;
- WBUFL (buf, 14) = sdelay;
- WBUFL (buf, 18) = ddelay;
- WBUFW (buf, 22) = (damage > 0x7fff) ? 0x7fff : damage;
- WBUFW (buf, 24) = div;
- WBUFB (buf, 26) = type;
- WBUFW (buf, 27) = damage2;
- clif_send (buf, packet_len_table[0x8a], src, AREA);
+ WBUFW(buf, 0) = 0x8a;
+ WBUFL(buf, 2) = src->id;
+ WBUFL(buf, 6) = dst->id;
+ WBUFL(buf, 10) = tick.time_since_epoch().count();
+ WBUFL(buf, 14) = sdelay.count();
+ WBUFL(buf, 18) = ddelay.count();
+ WBUFW(buf, 22) = (damage > 0x7fff) ? 0x7fff : damage;
+ WBUFW(buf, 24) = div;
+ WBUFB(buf, 26) = static_cast<uint8_t>(type);
+ WBUFW(buf, 27) = damage2;
+ clif_send(buf, clif_parse_func_table[0x8a].len, src, SendWho::AREA);
return 0;
}
@@ -3778,25 +2803,22 @@ int clif_damage (struct block_list *src, struct block_list *dst,
*------------------------------------------
*/
static
-void clif_getareachar_mob (struct map_session_data *sd, struct mob_data *md)
+void clif_getareachar_mob(struct map_session_data *sd, struct mob_data *md)
{
- int len;
- nullpo_retv (sd);
- nullpo_retv (md);
+ int len;
+ nullpo_retv(sd);
+ nullpo_retv(md);
- if (md->state.state == MS_WALK)
+ if (md->state.state == MS::WALK)
{
- len = clif_mob007b (md, WFIFOP (sd->fd, 0));
- WFIFOSET (sd->fd, len);
+ len = clif_mob007b(md, static_cast<uint8_t *>(WFIFOP(sd->fd, 0)));
+ WFIFOSET(sd->fd, len);
}
else
{
- len = clif_mob0078 (md, WFIFOP (sd->fd, 0));
- WFIFOSET (sd->fd, len);
+ len = clif_mob0078(md, static_cast<uint8_t *>(WFIFOP(sd->fd, 0)));
+ WFIFOSET(sd->fd, len);
}
-
- if (mob_get_equip (md->mob_class) > 0) // mob equipment [Valaris]
- clif_mob_equip (md, mob_get_equip (md->mob_class));
}
/*==========================================
@@ -3804,127 +2826,30 @@ void clif_getareachar_mob (struct map_session_data *sd, struct mob_data *md)
*------------------------------------------
*/
static
-void clif_getareachar_item (struct map_session_data *sd,
+void clif_getareachar_item(struct map_session_data *sd,
struct flooritem_data *fitem)
{
- int view, fd;
+ int view, fd;
- nullpo_retv (sd);
- nullpo_retv (fitem);
+ nullpo_retv(sd);
+ nullpo_retv(fitem);
fd = sd->fd;
//009d <ID>.l <item ID>.w <identify flag>.B <X>.w <Y>.w <amount>.w <subX>.B <subY>.B
- WFIFOW (fd, 0) = 0x9d;
- WFIFOL (fd, 2) = fitem->bl.id;
- if ((view = itemdb_viewid (fitem->item_data.nameid)) > 0)
- WFIFOW (fd, 6) = view;
+ WFIFOW(fd, 0) = 0x9d;
+ WFIFOL(fd, 2) = fitem->bl.id;
+ if ((view = itemdb_viewid(fitem->item_data.nameid)) > 0)
+ WFIFOW(fd, 6) = view;
else
- WFIFOW (fd, 6) = fitem->item_data.nameid;
- WFIFOB (fd, 8) = fitem->item_data.identify;
- WFIFOW (fd, 9) = fitem->bl.x;
- WFIFOW (fd, 11) = fitem->bl.y;
- WFIFOW (fd, 13) = fitem->item_data.amount;
- WFIFOB (fd, 15) = fitem->subx;
- WFIFOB (fd, 16) = fitem->suby;
-
- WFIFOSET (fd, packet_len_table[0x9d]);
-}
-
-/*==========================================
- * 場所スキルエフェクトãŒè¦–ç•Œã«å…¥ã‚‹
- *------------------------------------------
- */
-static
-int clif_getareachar_skillunit (struct map_session_data *sd,
- struct skill_unit *unit)
-{
- int fd;
- struct block_list *bl;
-
- nullpo_retr (0, unit);
+ WFIFOW(fd, 6) = fitem->item_data.nameid;
+ WFIFOB(fd, 8) = fitem->item_data.identify;
+ WFIFOW(fd, 9) = fitem->bl.x;
+ WFIFOW(fd, 11) = fitem->bl.y;
+ WFIFOW(fd, 13) = fitem->item_data.amount;
+ WFIFOB(fd, 15) = fitem->subx;
+ WFIFOB(fd, 16) = fitem->suby;
- fd = sd->fd;
- bl = map_id2bl (unit->group->src_id);
- memset (WFIFOP (fd, 0), 0, packet_len_table[0x1c9]);
- WFIFOW (fd, 0) = 0x1c9;
- WFIFOL (fd, 2) = unit->bl.id;
- WFIFOL (fd, 6) = unit->group->src_id;
- WFIFOW (fd, 10) = unit->bl.x;
- WFIFOW (fd, 12) = unit->bl.y;
- WFIFOB (fd, 14) = unit->group->unit_id;
- WFIFOB (fd, 15) = 1;
- WFIFOL (fd, 15 + 1) = 0; //1-4調ã¹ãŸé™ã‚Šå›ºå®š
- WFIFOL (fd, 15 + 5) = 0; //5-8調ã¹ãŸé™ã‚Šå›ºå®š
- //9-12マップã”ã¨ã§ä¸€å®šã®77-80ã¨ã¯ã¾ãŸé•ã†4ãƒã‚¤ãƒˆã®ã‹ãªã‚Šå¤§ããªæ•°å­—
- WFIFOL (fd, 15 + 13) = unit->bl.y - 0x12; //13-16ユニットã®Y座標-18ã£ã½ã„(Y:17ã§FF FF FF FF)
- WFIFOL (fd, 15 + 17) = 0x004f37dd; //17-20調ã¹ãŸé™ã‚Šå›ºå®š
- WFIFOL (fd, 15 + 21) = 0x0012f674; //21-24調ã¹ãŸé™ã‚Šå›ºå®š
- WFIFOL (fd, 15 + 25) = 0x0012f664; //25-28調ã¹ãŸé™ã‚Šå›ºå®š
- WFIFOL (fd, 15 + 29) = 0x0012f654; //29-32調ã¹ãŸé™ã‚Šå›ºå®š
- WFIFOL (fd, 15 + 33) = 0x77527bbc; //33-36調ã¹ãŸé™ã‚Šå›ºå®š
- //37-39
- WFIFOB (fd, 15 + 40) = 0x2d; //40調ã¹ãŸé™ã‚Šå›ºå®š
- WFIFOL (fd, 15 + 41) = 0; //41-44調ã¹ãŸé™ã‚Š0固定
- WFIFOL (fd, 15 + 45) = 0; //45-48調ã¹ãŸé™ã‚Š0固定
- WFIFOL (fd, 15 + 49) = 0; //49-52調ã¹ãŸé™ã‚Š0固定
- WFIFOL (fd, 15 + 53) = 0x0048d919; //53-56調ã¹ãŸé™ã‚Šå›ºå®š
- WFIFOL (fd, 15 + 57) = 0x0000003e; //57-60調ã¹ãŸé™ã‚Šå›ºå®š
- WFIFOL (fd, 15 + 61) = 0x0012f66c; //61-64調ã¹ãŸé™ã‚Šå›ºå®š
- //65-68
- //69-72
- if (bl)
- WFIFOL (fd, 15 + 73) = bl->y; //73-76術者ã®Y座標
- WFIFOL (fd, 15 + 77) = unit->bl.m; //77-80マップIDã‹ãªã?ã‹ãªã‚Š2ãƒã‚¤ãƒˆã§è¶³ã‚Šãã†ãªæ•°å­—
- WFIFOB (fd, 15 + 81) = 0xaa; //81終端文字0xaa
-
- /* Graffiti [Valaris] */
- if (unit->group->unit_id == 0xb0)
- {
- WFIFOL (fd, 15) = 1;
- WFIFOL (fd, 16) = 1;
- memcpy (WFIFOP (fd, 17), unit->group->valstr, 80);
- }
-
- WFIFOSET (fd, packet_len_table[0x1c9]);
- if (unit->group->skill_id == WZ_ICEWALL)
- clif_set0192 (fd, unit->bl.m, unit->bl.x, unit->bl.y, 5);
-
- return 0;
-}
-
-/*==========================================
- * 場所スキルエフェクトãŒè¦–ç•Œã‹ã‚‰æ¶ˆãˆã‚‹
- *------------------------------------------
- */
-static
-int clif_clearchar_skillunit (struct skill_unit *unit, int fd)
-{
- nullpo_retr (0, unit);
-
- WFIFOW (fd, 0) = 0x120;
- WFIFOL (fd, 2) = unit->bl.id;
- WFIFOSET (fd, packet_len_table[0x120]);
- if (unit->group->skill_id == WZ_ICEWALL)
- clif_set0192 (fd, unit->bl.m, unit->bl.x, unit->bl.y, unit->val2);
-
- return 0;
-}
-
-/*==========================================
- *
- *------------------------------------------
- */
-int clif_01ac (struct block_list *bl)
-{
- uint8_t buf[32];
-
- nullpo_retr (0, bl);
-
- WBUFW (buf, 0) = 0x1ac;
- WBUFL (buf, 2) = bl->id;
-
- clif_send (buf, packet_len_table[0x1ac], bl, AREA);
- return 0;
+ WFIFOSET(fd, clif_parse_func_table[0x9d].len);
}
/*==========================================
@@ -3932,205 +2857,170 @@ int clif_01ac (struct block_list *bl)
*------------------------------------------
*/
static
-int clif_getareachar (struct block_list *bl, va_list ap)
+void clif_getareachar(struct block_list *bl, struct map_session_data *sd)
{
- struct map_session_data *sd;
-
- nullpo_retr (0, bl);
- nullpo_retr (0, ap);
-
- sd = va_arg (ap, struct map_session_data *);
+ nullpo_retv(bl);
switch (bl->type)
{
- case BL_PC:
+ case BL::PC:
if (sd == (struct map_session_data *) bl)
break;
- clif_getareachar_pc (sd, (struct map_session_data *) bl);
+ clif_getareachar_pc(sd, (struct map_session_data *) bl);
break;
- case BL_NPC:
- clif_getareachar_npc (sd, (struct npc_data *) bl);
+ case BL::NPC:
+ clif_getareachar_npc(sd, (struct npc_data *) bl);
break;
- case BL_MOB:
- clif_getareachar_mob (sd, (struct mob_data *) bl);
+ case BL::MOB:
+ clif_getareachar_mob(sd, (struct mob_data *) bl);
break;
- case BL_ITEM:
- clif_getareachar_item (sd, (struct flooritem_data *) bl);
- break;
- case BL_SKILL:
- clif_getareachar_skillunit (sd, (struct skill_unit *) bl);
+ case BL::ITEM:
+ clif_getareachar_item(sd, (struct flooritem_data *) bl);
break;
default:
if (battle_config.error_log)
- printf ("get area char ??? %d\n", bl->type);
+ PRINTF("get area char ??? %d\n",
+ bl->type);
break;
}
- return 0;
}
/*==========================================
*
*------------------------------------------
*/
-int clif_pcoutsight (struct block_list *bl, va_list ap)
+void clif_pcoutsight(struct block_list *bl, struct map_session_data *sd)
{
- struct map_session_data *sd, *dstsd;
+ struct map_session_data *dstsd;
- nullpo_retr (0, bl);
- nullpo_retr (0, ap);
- nullpo_retr (0, sd = va_arg (ap, struct map_session_data *));
+ nullpo_retv(bl);
+ nullpo_retv(sd);
switch (bl->type)
{
- case BL_PC:
+ case BL::PC:
dstsd = (struct map_session_data *) bl;
if (sd != dstsd)
{
- clif_clearchar_id (dstsd->bl.id, 0, sd->fd);
- clif_clearchar_id (sd->bl.id, 0, dstsd->fd);
- if (dstsd->chatID)
- {
- struct chat_data *cd;
- cd = (struct chat_data *) map_id2bl (dstsd->chatID);
- if (cd->usersd[0] == dstsd)
- clif_dispchat (cd, sd->fd);
- }
+ clif_clearchar_id(dstsd->bl.id, BeingRemoveWhy::GONE, sd->fd);
+ clif_clearchar_id(sd->bl.id, BeingRemoveWhy::GONE, dstsd->fd);
}
break;
- case BL_NPC:
+ case BL::NPC:
if (((struct npc_data *) bl)->npc_class != INVISIBLE_CLASS)
- clif_clearchar_id (bl->id, 0, sd->fd);
+ clif_clearchar_id(bl->id, BeingRemoveWhy::GONE, sd->fd);
break;
- case BL_MOB:
- clif_clearchar_id (bl->id, 0, sd->fd);
+ case BL::MOB:
+ clif_clearchar_id(bl->id, BeingRemoveWhy::GONE, sd->fd);
break;
- case BL_ITEM:
- clif_clearflooritem ((struct flooritem_data *) bl, sd->fd);
- break;
- case BL_SKILL:
- clif_clearchar_skillunit ((struct skill_unit *) bl, sd->fd);
+ case BL::ITEM:
+ clif_clearflooritem((struct flooritem_data *) bl, sd->fd);
break;
}
- return 0;
}
/*==========================================
*
*------------------------------------------
*/
-int clif_pcinsight (struct block_list *bl, va_list ap)
+void clif_pcinsight(struct block_list *bl, struct map_session_data *sd)
{
- struct map_session_data *sd, *dstsd;
+ struct map_session_data *dstsd;
- nullpo_retr (0, bl);
- nullpo_retr (0, ap);
- nullpo_retr (0, sd = va_arg (ap, struct map_session_data *));
+ nullpo_retv(bl);
+ nullpo_retv(sd);
switch (bl->type)
{
- case BL_PC:
+ case BL::PC:
dstsd = (struct map_session_data *) bl;
if (sd != dstsd)
{
- clif_getareachar_pc (sd, dstsd);
- clif_getareachar_pc (dstsd, sd);
+ clif_getareachar_pc(sd, dstsd);
+ clif_getareachar_pc(dstsd, sd);
}
break;
- case BL_NPC:
- clif_getareachar_npc (sd, (struct npc_data *) bl);
- break;
- case BL_MOB:
- clif_getareachar_mob (sd, (struct mob_data *) bl);
+ case BL::NPC:
+ clif_getareachar_npc(sd, (struct npc_data *) bl);
break;
- case BL_ITEM:
- clif_getareachar_item (sd, (struct flooritem_data *) bl);
+ case BL::MOB:
+ clif_getareachar_mob(sd, (struct mob_data *) bl);
break;
- case BL_SKILL:
- clif_getareachar_skillunit (sd, (struct skill_unit *) bl);
+ case BL::ITEM:
+ clif_getareachar_item(sd, (struct flooritem_data *) bl);
break;
}
-
- return 0;
}
/*==========================================
*
*------------------------------------------
*/
-int clif_moboutsight (struct block_list *bl, va_list ap)
+void clif_moboutsight(struct block_list *bl, struct mob_data *md)
{
struct map_session_data *sd;
- struct mob_data *md;
- nullpo_retr (0, bl);
- nullpo_retr (0, ap);
- nullpo_retr (0, md = va_arg (ap, struct mob_data *));
+ nullpo_retv(bl);
+ nullpo_retv(md);
- if (bl->type == BL_PC && (sd = (struct map_session_data *) bl))
+ if (bl->type == BL::PC && (sd = (struct map_session_data *) bl))
{
- clif_clearchar_id (md->bl.id, 0, sd->fd);
+ clif_clearchar_id(md->bl.id, BeingRemoveWhy::GONE, sd->fd);
}
-
- return 0;
}
/*==========================================
*
*------------------------------------------
*/
-int clif_mobinsight (struct block_list *bl, va_list ap)
+void clif_mobinsight(struct block_list *bl, struct mob_data *md)
{
struct map_session_data *sd;
- struct mob_data *md;
- nullpo_retr (0, bl);
- nullpo_retr (0, ap);
+ nullpo_retv(bl);
+ nullpo_retv(md);
- md = va_arg (ap, struct mob_data *);
- if (bl->type == BL_PC && (sd = (struct map_session_data *) bl))
+ if (bl->type == BL::PC && (sd = (struct map_session_data *) bl))
{
- clif_getareachar_mob (sd, md);
+ clif_getareachar_mob(sd, md);
}
-
- return 0;
}
/*==========================================
*
*------------------------------------------
*/
-int clif_skillinfo (struct map_session_data *sd, int skillid, int type,
+int clif_skillinfo(struct map_session_data *sd, SkillID skillid, int type,
int range)
{
- int fd, id;
+ int fd;
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
fd = sd->fd;
- if ((id = sd->status.skill[skillid].id) <= 0)
+ if (!sd->status.skill[skillid].lv)
return 0;
- WFIFOW (fd, 0) = 0x147;
- WFIFOW (fd, 2) = id;
+ WFIFOW(fd, 0) = 0x147;
+ WFIFOW(fd, 2) = static_cast<uint16_t>(skillid);
if (type < 0)
- WFIFOW (fd, 4) = skill_get_inf (id);
+ WFIFOW(fd, 4) = skill_get_inf(skillid);
else
- WFIFOW (fd, 4) = type;
- WFIFOW (fd, 6) = 0;
- WFIFOW (fd, 8) = sd->status.skill[skillid].lv;
- WFIFOW (fd, 10) = skill_get_sp (id, sd->status.skill[skillid].lv);
+ WFIFOW(fd, 4) = type;
+ WFIFOW(fd, 6) = 0;
+ WFIFOW(fd, 8) = sd->status.skill[skillid].lv;
+ WFIFOW(fd, 10) = skill_get_sp(skillid, sd->status.skill[skillid].lv);
if (range < 0)
{
- range = skill_get_range (id, sd->status.skill[skillid].lv);
+ range = skill_get_range(skillid, sd->status.skill[skillid].lv);
if (range < 0)
- range = battle_get_range (&sd->bl) - (range + 1);
- WFIFOW (fd, 12) = range;
+ range = battle_get_range(&sd->bl) - (range + 1);
+ WFIFOW(fd, 12) = range;
}
else
- WFIFOW (fd, 12) = range;
- memset (WFIFOP (fd, 14), 0, 24);
- WFIFOB (fd, 38) =
- (sd->status.skill[skillid].lv < skill_get_max_raise (id)) ? 1 : 0;
- WFIFOSET (fd, packet_len_table[0x147]);
+ WFIFOW(fd, 12) = range;
+ memset(WFIFOP(fd, 14), 0, 24);
+ WFIFOB(fd, 38) = sd->status.skill[skillid].lv < skill_get_max_raise(skillid);
+ WFIFOSET(fd, clif_parse_func_table[0x147].len);
return 0;
}
@@ -4139,40 +3029,38 @@ int clif_skillinfo (struct map_session_data *sd, int skillid, int type,
* スキルリストをé€ä¿¡ã™ã‚‹
*------------------------------------------
*/
-int clif_skillinfoblock (struct map_session_data *sd)
+int clif_skillinfoblock(struct map_session_data *sd)
{
- int fd;
- int i, c, len = 4, id, range;
+ int fd;
+ int len = 4, range;
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
fd = sd->fd;
- WFIFOW (fd, 0) = 0x10f;
- for (i = c = 0; i < MAX_SKILL; i++)
+ WFIFOW(fd, 0) = 0x10f;
+ for (SkillID i : erange(SkillID(), MAX_SKILL))
{
- if ((id = sd->status.skill[i].id) != 0 && (sd->tmw_version >= 1))
- { // [Fate] Version 1 and later don't crash because of bad skill IDs anymore
- WFIFOW (fd, len) = id;
- WFIFOW (fd, len + 2) = skill_get_inf (id);
- WFIFOW (fd, len + 4) =
- skill_db[i].poolflags | (sd->status.
- skill[i].flags &
- (SKILL_POOL_ACTIVATED));
- WFIFOW (fd, len + 6) = sd->status.skill[i].lv;
- WFIFOW (fd, len + 8) = skill_get_sp (id, sd->status.skill[i].lv);
- range = skill_get_range (id, sd->status.skill[i].lv);
+ if (sd->status.skill[i].lv && sd->tmw_version >= 1)
+ {
+ // [Fate] Version 1 and later don't crash because of bad skill IDs anymore
+ WFIFOW(fd, len) = static_cast<uint16_t>(i);
+ WFIFOW(fd, len + 2) = skill_get_inf(i);
+ WFIFOW(fd, len + 4) = static_cast<uint16_t>(
+ skill_db[i].poolflags
+ | (sd->status.skill[i].flags & SkillFlags::POOL_ACTIVATED));
+ WFIFOW(fd, len + 6) = sd->status.skill[i].lv;
+ WFIFOW(fd, len + 8) = skill_get_sp(i, sd->status.skill[i].lv);
+ range = skill_get_range(i, sd->status.skill[i].lv);
if (range < 0)
- range = battle_get_range (&sd->bl) - (range + 1);
- WFIFOW (fd, len + 10) = range;
- memset (WFIFOP (fd, len + 12), 0, 24);
- WFIFOB (fd, len + 36) =
- (sd->status.skill[i].lv < skill_get_max_raise (id)) ? 1 : 0;
+ range = battle_get_range(&sd->bl) - (range + 1);
+ WFIFOW(fd, len + 10) = range;
+ memset(WFIFOP(fd, len + 12), 0, 24);
+ WFIFOB(fd, len + 36) = sd->status.skill[i].lv < skill_get_max_raise(i);
len += 37;
- c++;
}
}
- WFIFOW (fd, 2) = len;
- WFIFOSET (fd, len);
+ WFIFOW(fd, 2) = len;
+ WFIFOSET(fd, len);
return 0;
}
@@ -4181,47 +3069,23 @@ int clif_skillinfoblock (struct map_session_data *sd)
* スキル割り振り通知
*------------------------------------------
*/
-int clif_skillup (struct map_session_data *sd, int skill_num)
+int clif_skillup(struct map_session_data *sd, SkillID skill_num)
{
- int range, fd;
+ int range, fd;
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
fd = sd->fd;
- WFIFOW (fd, 0) = 0x10e;
- WFIFOW (fd, 2) = skill_num;
- WFIFOW (fd, 4) = sd->status.skill[skill_num].lv;
- WFIFOW (fd, 6) = skill_get_sp (skill_num, sd->status.skill[skill_num].lv);
- range = skill_get_range (skill_num, sd->status.skill[skill_num].lv);
+ WFIFOW(fd, 0) = 0x10e;
+ WFIFOW(fd, 2) = uint16_t(skill_num);
+ WFIFOW(fd, 4) = sd->status.skill[skill_num].lv;
+ WFIFOW(fd, 6) = skill_get_sp(skill_num, sd->status.skill[skill_num].lv);
+ range = skill_get_range(skill_num, sd->status.skill[skill_num].lv);
if (range < 0)
- range = battle_get_range (&sd->bl) - (range + 1);
- WFIFOW (fd, 8) = range;
- WFIFOB (fd, 10) =
- (sd->status.skill[skill_num].lv <
- skill_get_max_raise (sd->status.skill[skill_num].id)) ? 1 : 0;
- WFIFOSET (fd, packet_len_table[0x10e]);
-
- return 0;
-}
-
-/*==========================================
- * スキル詠唱エフェクトをé€ä¿¡ã™ã‚‹
- *------------------------------------------
- */
-int clif_skillcasting (struct block_list *bl,
- int src_id, int dst_id, int dst_x, int dst_y,
- int skill_num, int casttime)
-{
- unsigned char buf[32];
- WBUFW (buf, 0) = 0x13e;
- WBUFL (buf, 2) = src_id;
- WBUFL (buf, 6) = dst_id;
- WBUFW (buf, 10) = dst_x;
- WBUFW (buf, 12) = dst_y;
- WBUFW (buf, 14) = skill_num; //魔法詠唱スキル
- WBUFL (buf, 16) = skill_get_pl (skill_num); //属性
- WBUFL (buf, 20) = casttime; //skill詠唱時間
- clif_send (buf, packet_len_table[0x13e], bl, AREA);
+ range = battle_get_range(&sd->bl) - (range + 1);
+ WFIFOW(fd, 8) = range;
+ WFIFOB(fd, 10) = sd->status.skill[skill_num].lv < skill_get_max_raise(skill_num);
+ WFIFOSET(fd, clif_parse_func_table[0x10e].len);
return 0;
}
@@ -4230,15 +3094,15 @@ int clif_skillcasting (struct block_list *bl,
*
*------------------------------------------
*/
-int clif_skillcastcancel (struct block_list *bl)
+int clif_skillcastcancel(struct block_list *bl)
{
unsigned char buf[16];
- nullpo_retr (0, bl);
+ nullpo_ret(bl);
- WBUFW (buf, 0) = 0x1b9;
- WBUFL (buf, 2) = bl->id;
- clif_send (buf, packet_len_table[0x1b9], bl, AREA);
+ WBUFW(buf, 0) = 0x1b9;
+ WBUFL(buf, 2) = bl->id;
+ clif_send(buf, clif_parse_func_table[0x1b9].len, bl, SendWho::AREA);
return 0;
}
@@ -4247,12 +3111,12 @@ int clif_skillcastcancel (struct block_list *bl)
* スキル詠唱失敗
*------------------------------------------
*/
-int clif_skill_fail (struct map_session_data *sd, int skill_id, int type,
+int clif_skill_fail(struct map_session_data *sd, SkillID skill_id, int type,
int btype)
{
- int fd;
+ int fd;
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
fd = sd->fd;
@@ -4261,13 +3125,13 @@ int clif_skill_fail (struct map_session_data *sd, int skill_id, int type,
return 0;
}
- WFIFOW (fd, 0) = 0x110;
- WFIFOW (fd, 2) = skill_id;
- WFIFOW (fd, 4) = btype;
- WFIFOW (fd, 6) = 0;
- WFIFOB (fd, 8) = 0;
- WFIFOB (fd, 9) = type;
- WFIFOSET (fd, packet_len_table[0x110]);
+ WFIFOW(fd, 0) = 0x110;
+ WFIFOW(fd, 2) = uint16_t(skill_id);
+ WFIFOW(fd, 4) = btype;
+ WFIFOW(fd, 6) = 0;
+ WFIFOB(fd, 8) = 0;
+ WFIFOB(fd, 9) = type;
+ WFIFOSET(fd, clif_parse_func_table[0x110].len);
return 0;
}
@@ -4276,322 +3140,49 @@ int clif_skill_fail (struct map_session_data *sd, int skill_id, int type,
* スキル攻撃エフェクト&ダメージ
*------------------------------------------
*/
-int clif_skill_damage (struct block_list *src, struct block_list *dst,
- unsigned int tick, int sdelay, int ddelay, int damage,
- int div, int skill_id, int skill_lv, int type)
+int clif_skill_damage(struct block_list *src, struct block_list *dst,
+ tick_t tick, interval_t sdelay, interval_t ddelay, int damage,
+ int div, SkillID skill_id, int skill_lv, int type)
{
unsigned char buf[64];
- struct status_change *sc_data;
-
- nullpo_retr (0, src);
- nullpo_retr (0, dst);
-
- sc_data = battle_get_sc_data (dst);
-
- if (type != 5 && dst->type == BL_PC
- && ((struct map_session_data *) dst)->special_state.infinite_endure)
- type = 9;
- if (sc_data)
- {
- if (type != 5 && sc_data[SC_ENDURE].timer != -1)
- type = 9;
- if (sc_data[SC_HALLUCINATION].timer != -1 && damage > 0)
- damage =
- damage * (5 + sc_data[SC_HALLUCINATION].val1) + MRAND (100);
- }
-
- WBUFW (buf, 0) = 0x1de;
- WBUFW (buf, 2) = skill_id;
- WBUFL (buf, 4) = src->id;
- WBUFL (buf, 8) = dst->id;
- WBUFL (buf, 12) = tick;
- WBUFL (buf, 16) = sdelay;
- WBUFL (buf, 20) = ddelay;
- WBUFL (buf, 24) = damage;
- WBUFW (buf, 28) = skill_lv;
- WBUFW (buf, 30) = div;
- WBUFB (buf, 32) = (type > 0) ? type : skill_get_hit (skill_id);
- clif_send (buf, packet_len_table[0x1de], src, AREA);
-
- return 0;
-}
-
-/*==========================================
- * å¹ã飛ã°ã—スキル攻撃エフェクト&ダメージ
- *------------------------------------------
- */
-int clif_skill_damage2 (struct block_list *src, struct block_list *dst,
- unsigned int tick, int sdelay, int ddelay, int damage,
- int div, int skill_id, int skill_lv, int type)
-{
- unsigned char buf[64];
- struct status_change *sc_data;
-
- nullpo_retr (0, src);
- nullpo_retr (0, dst);
-
- sc_data = battle_get_sc_data (dst);
-
- if (type != 5 && dst->type == BL_PC
- && ((struct map_session_data *) dst)->special_state.infinite_endure)
- type = 9;
- if (sc_data)
- {
- if (type != 5 && sc_data[SC_ENDURE].timer != -1)
- type = 9;
- if (sc_data[SC_HALLUCINATION].timer != -1 && damage > 0)
- damage =
- damage * (5 + sc_data[SC_HALLUCINATION].val1) + MRAND (100);
- }
-
- WBUFW (buf, 0) = 0x115;
- WBUFW (buf, 2) = skill_id;
- WBUFL (buf, 4) = src->id;
- WBUFL (buf, 8) = dst->id;
- WBUFL (buf, 12) = tick;
- WBUFL (buf, 16) = sdelay;
- WBUFL (buf, 20) = ddelay;
- WBUFW (buf, 24) = dst->x;
- WBUFW (buf, 26) = dst->y;
- WBUFW (buf, 28) = damage;
- WBUFW (buf, 30) = skill_lv;
- WBUFW (buf, 32) = div;
- WBUFB (buf, 34) = (type > 0) ? type : skill_get_hit (skill_id);
- clif_send (buf, packet_len_table[0x115], src, AREA);
-
- return 0;
-}
-
-/*==========================================
- * 支æ´/回復スキルエフェクト
- *------------------------------------------
- */
-int clif_skill_nodamage (struct block_list *src, struct block_list *dst,
- int skill_id, int heal, int fail)
-{
- unsigned char buf[32];
-
- nullpo_retr (0, src);
- nullpo_retr (0, dst);
-
- WBUFW (buf, 0) = 0x11a;
- WBUFW (buf, 2) = skill_id;
- WBUFW (buf, 4) = (heal > 0x7fff) ? 0x7fff : heal;
- WBUFL (buf, 6) = dst->id;
- WBUFL (buf, 10) = src->id;
- WBUFB (buf, 14) = fail;
- clif_send (buf, packet_len_table[0x11a], src, AREA);
-
- return 0;
-}
+ eptr<struct status_change, StatusChange> sc_data;
-/*==========================================
- * 場所スキルエフェクト
- *------------------------------------------
- */
-int clif_skill_poseffect (struct block_list *src, int skill_id, int val,
- int x, int y, int tick)
-{
- unsigned char buf[32];
+ nullpo_ret(src);
+ nullpo_ret(dst);
- nullpo_retr (0, src);
+ sc_data = battle_get_sc_data(dst);
- WBUFW (buf, 0) = 0x117;
- WBUFW (buf, 2) = skill_id;
- WBUFL (buf, 4) = src->id;
- WBUFW (buf, 8) = val;
- WBUFW (buf, 10) = x;
- WBUFW (buf, 12) = y;
- WBUFL (buf, 14) = tick;
- clif_send (buf, packet_len_table[0x117], src, AREA);
+ WBUFW(buf, 0) = 0x1de;
+ WBUFW(buf, 2) = uint16_t(skill_id);
+ WBUFL(buf, 4) = src->id;
+ WBUFL(buf, 8) = dst->id;
+ WBUFL(buf, 12) = static_cast<uint32_t>(tick.time_since_epoch().count());
+ WBUFL(buf, 16) = static_cast<uint32_t>(sdelay.count());
+ WBUFL(buf, 20) = static_cast<uint32_t>(ddelay.count());
+ WBUFL(buf, 24) = damage;
+ WBUFW(buf, 28) = skill_lv;
+ WBUFW(buf, 30) = div;
+ WBUFB(buf, 32) = (type > 0) ? type : skill_get_hit(skill_id);
+ clif_send(buf, clif_parse_func_table[0x1de].len, src, SendWho::AREA);
return 0;
}
/*==========================================
- * 場所スキルエフェクト表示
- *------------------------------------------
- */
-int clif_skill_setunit (struct skill_unit *unit)
-{
- unsigned char buf[128];
- struct block_list *bl;
-
- nullpo_retr (0, unit);
-
- bl = map_id2bl (unit->group->src_id);
-
- memset (WBUFP (buf, 0), 0, packet_len_table[0x1c9]);
- WBUFW (buf, 0) = 0x1c9;
- WBUFL (buf, 2) = unit->bl.id;
- WBUFL (buf, 6) = unit->group->src_id;
- WBUFW (buf, 10) = unit->bl.x;
- WBUFW (buf, 12) = unit->bl.y;
- WBUFB (buf, 14) = unit->group->unit_id;
- WBUFB (buf, 15) = 1;
- WBUFL (buf, 15 + 1) = 0; //1-4調ã¹ãŸé™ã‚Šå›ºå®š
- WBUFL (buf, 15 + 5) = 0; //5-8調ã¹ãŸé™ã‚Šå›ºå®š
- //9-12マップã”ã¨ã§ä¸€å®šã®77-80ã¨ã¯ã¾ãŸé•ã†4ãƒã‚¤ãƒˆã®ã‹ãªã‚Šå¤§ããªæ•°å­—
- WBUFL (buf, 15 + 13) = unit->bl.y - 0x12; //13-16ユニットã®Y座標-18ã£ã½ã„(Y:17ã§FF FF FF FF)
- WBUFL (buf, 15 + 17) = 0x004f37dd; //17-20調ã¹ãŸé™ã‚Šå›ºå®š(0x1b2ã§0x004fdbddã ã£ãŸ)
- WBUFL (buf, 15 + 21) = 0x0012f674; //21-24調ã¹ãŸé™ã‚Šå›ºå®š
- WBUFL (buf, 15 + 25) = 0x0012f664; //25-28調ã¹ãŸé™ã‚Šå›ºå®š
- WBUFL (buf, 15 + 29) = 0x0012f654; //29-32調ã¹ãŸé™ã‚Šå›ºå®š
- WBUFL (buf, 15 + 33) = 0x77527bbc; //33-36調ã¹ãŸé™ã‚Šå›ºå®š
- //37-39
- WBUFB (buf, 15 + 40) = 0x2d; //40調ã¹ãŸé™ã‚Šå›ºå®š
- WBUFL (buf, 15 + 41) = 0; //41-44調ã¹ãŸé™ã‚Š0固定
- WBUFL (buf, 15 + 45) = 0; //45-48調ã¹ãŸé™ã‚Š0固定
- WBUFL (buf, 15 + 49) = 0; //49-52調ã¹ãŸé™ã‚Š0固定
- WBUFL (buf, 15 + 53) = 0x0048d919; //53-56調ã¹ãŸé™ã‚Šå›ºå®š(0x01b2ã§0x00495119ã ã£ãŸ)
- WBUFL (buf, 15 + 57) = 0x0000003e; //57-60調ã¹ãŸé™ã‚Šå›ºå®š
- WBUFL (buf, 15 + 61) = 0x0012f66c; //61-64調ã¹ãŸé™ã‚Šå›ºå®š
- //65-68
- //69-72
- if (bl)
- WBUFL (buf, 15 + 73) = bl->y; //73-76術者ã®Y座標
- WBUFL (buf, 15 + 77) = unit->bl.m; //77-80マップIDã‹ãªã?ã‹ãªã‚Š2ãƒã‚¤ãƒˆã§è¶³ã‚Šãã†ãªæ•°å­—
- WBUFB (buf, 15 + 81) = 0xaa; //81終端文字0xaa
-
- /* Graffiti [Valaris] */
- if (unit->group->unit_id == 0xb0)
- {
- WBUFL (buf, 15) = 1;
- WBUFL (buf, 16) = 1;
- memcpy (WBUFP (buf, 17), unit->group->valstr, 80);
- }
-
- clif_send (buf, packet_len_table[0x1c9], &unit->bl, AREA);
- return 0;
-}
-
-/*==========================================
- * 場所スキルエフェクト削除
- *------------------------------------------
- */
-int clif_skill_delunit (struct skill_unit *unit)
-{
- unsigned char buf[16];
-
- nullpo_retr (0, unit);
-
- WBUFW (buf, 0) = 0x120;
- WBUFL (buf, 2) = unit->bl.id;
- clif_send (buf, packet_len_table[0x120], &unit->bl, AREA);
- return 0;
-}
-
-/*==========================================
- * ワープ場所é¸æŠž
- *------------------------------------------
- */
-int clif_skill_warppoint (struct map_session_data *sd, int skill_num,
- const char *map1, const char *map2,
- const char *map3, const char *map4)
-{
- int fd;
-
- nullpo_retr (0, sd);
-
- fd = sd->fd;
- WFIFOW (fd, 0) = 0x11c;
- WFIFOW (fd, 2) = skill_num;
- memcpy (WFIFOP (fd, 4), map1, 16);
- memcpy (WFIFOP (fd, 20), map2, 16);
- memcpy (WFIFOP (fd, 36), map3, 16);
- memcpy (WFIFOP (fd, 52), map4, 16);
- WFIFOSET (fd, packet_len_table[0x11c]);
- return 0;
-}
-
-/*==========================================
- * メモ応答
- *------------------------------------------
- */
-int clif_skill_memo (struct map_session_data *sd, int flag)
-{
- int fd;
-
- nullpo_retr (0, sd);
-
- fd = sd->fd;
-
- WFIFOW (fd, 0) = 0x11e;
- WFIFOB (fd, 2) = flag;
- WFIFOSET (fd, packet_len_table[0x11e]);
- return 0;
-}
-
-int clif_skill_teleportmessage (struct map_session_data *sd, int flag)
-{
- int fd;
-
- nullpo_retr (0, sd);
-
- fd = sd->fd;
- WFIFOW (fd, 0) = 0x189;
- WFIFOW (fd, 2) = flag;
- WFIFOSET (fd, packet_len_table[0x189]);
- return 0;
-}
-
-/*==========================================
- * モンスター情報
- *------------------------------------------
- */
-int clif_skill_estimation (struct map_session_data *sd,
- struct block_list *dst)
-{
- struct mob_data *md;
- unsigned char buf[64];
- int i;
-
- nullpo_retr (0, sd);
- nullpo_retr (0, dst);
-
- if (dst->type != BL_MOB)
- return 0;
- if ((md = (struct mob_data *) dst) == NULL)
- return 0;
-
- WBUFW (buf, 0) = 0x18c;
- WBUFW (buf, 2) = mob_get_viewclass (md->mob_class);
- WBUFW (buf, 4) = mob_db[md->mob_class].lv;
- WBUFW (buf, 6) = mob_db[md->mob_class].size;
- WBUFL (buf, 8) = md->hp;
- WBUFW (buf, 12) = battle_get_def2 (&md->bl);
- WBUFW (buf, 14) = mob_db[md->mob_class].race;
- WBUFW (buf, 16) =
- battle_get_mdef2 (&md->bl) - (mob_db[md->mob_class].vit >> 1);
- WBUFW (buf, 18) = battle_get_elem_type (&md->bl);
- for (i = 0; i < 9; i++)
- WBUFB (buf, 20 + i) = battle_attr_fix (100, i + 1, md->def_ele);
-
- if (sd->status.party_id > 0)
- clif_send (buf, packet_len_table[0x18c], &sd->bl, PARTY_AREA);
- else
- {
- memcpy (WFIFOP (sd->fd, 0), buf, packet_len_table[0x18c]);
- WFIFOSET (sd->fd, packet_len_table[0x18c]);
- }
- return 0;
-}
-
-/*==========================================
* 状態異常アイコン/メッセージ表示
*------------------------------------------
*/
-int clif_status_change (struct block_list *bl, int type, int flag)
+int clif_status_change(struct block_list *bl, StatusChange type, int flag)
{
unsigned char buf[16];
- nullpo_retr (0, bl);
+ nullpo_ret(bl);
- WBUFW (buf, 0) = 0x0196;
- WBUFW (buf, 2) = type;
- WBUFL (buf, 4) = bl->id;
- WBUFB (buf, 8) = flag;
- clif_send (buf, packet_len_table[0x196], bl, AREA);
+ WBUFW(buf, 0) = 0x0196;
+ WBUFW(buf, 2) = uint16_t(type);
+ WBUFL(buf, 4) = bl->id;
+ WBUFB(buf, 8) = flag;
+ clif_send(buf, clif_parse_func_table[0x196].len, bl, SendWho::AREA);
return 0;
}
@@ -4599,170 +3190,56 @@ int clif_status_change (struct block_list *bl, int type, int flag)
* Send message (modified by [Yor])
*------------------------------------------
*/
-int clif_displaymessage (int fd, const char *mes)
+void clif_displaymessage(int fd, const_string mes)
{
- int len_mes = strlen (mes);
-
- if (len_mes > 0)
- { // don't send a void message (it's not displaying on the client chat). @help can send void line.
- WFIFOW (fd, 0) = 0x8e;
- WFIFOW (fd, 2) = 5 + len_mes; // 4 + len + NULL teminate
- memcpy (WFIFOP (fd, 4), mes, len_mes + 1);
- WFIFOSET (fd, 5 + len_mes);
+ if (mes)
+ {
+ // don't send a void message (it's not displaying on the client chat). @help can send void line.
+ WFIFOW(fd, 0) = 0x8e;
+ WFIFOW(fd, 2) = 5 + mes.size(); // 4 + len + NULL teminate
+ memcpy(WFIFOP(fd, 4), mes.data(), mes.size());
+ WFIFOB(fd, 4 + mes.size()) = '\0';
+ WFIFOSET(fd, 5 + mes.size());
}
-
- return 0;
}
/*==========================================
* 天ã®å£°ã‚’é€ä¿¡ã™ã‚‹
*------------------------------------------
*/
-int clif_GMmessage (struct block_list *bl, const char *mes, int len, int flag)
+void clif_GMmessage(struct block_list *bl, const_string mes, int flag)
{
- unsigned char lbuf[255];
- unsigned char *buf =
- ((len + 16) >= sizeof (lbuf)) ? (unsigned char*)malloc (len + 16) : lbuf;
- int lp = (flag & 0x10) ? 8 : 4;
+ unsigned char buf[mes.size() + 16];
+ int lp = (flag & 0x10) ? 8 : 4;
- WBUFW (buf, 0) = 0x9a;
- WBUFW (buf, 2) = len + lp;
- WBUFL (buf, 4) = 0x65756c62;
- memcpy (WBUFP (buf, lp), mes, len);
+ WBUFW(buf, 0) = 0x9a;
+ WBUFW(buf, 2) = mes.size() + 1 + lp;
+ WBUFL(buf, 4) = 0x65756c62;
+ memcpy(WBUFP(buf, lp), mes.data(), mes.size());
+ WBUFB(buf, lp + mes.size()) = '\0';
flag &= 0x07;
- clif_send (buf, WBUFW (buf, 2), bl,
- (flag == 1) ? ALL_SAMEMAP :
- (flag == 2) ? AREA : (flag == 3) ? SELF : ALL_CLIENT);
- if (buf != lbuf)
- free (buf);
- return 0;
-}
-
-/*==========================================
- * HPSP回復エフェクトをé€ä¿¡ã™ã‚‹
- *------------------------------------------
- */
-int clif_heal (int fd, int type, int val)
-{
- WFIFOW (fd, 0) = 0x13d;
- WFIFOW (fd, 2) = type;
- WFIFOW (fd, 4) = val;
- WFIFOSET (fd, packet_len_table[0x13d]);
-
- return 0;
+ clif_send(buf, WBUFW(buf, 2), bl,
+ (flag == 1) ? SendWho::ALL_SAMEMAP :
+ (flag == 2) ? SendWho::AREA :
+ (flag == 3) ? SendWho::SELF :
+ SendWho::ALL_CLIENT);
}
/*==========================================
* 復活ã™ã‚‹
*------------------------------------------
*/
-int clif_resurrection (struct block_list *bl, int type)
+int clif_resurrection(struct block_list *bl, int type)
{
unsigned char buf[16];
- nullpo_retr (0, bl);
-
- if (bl->type == BL_PC)
- { // disguises [Valaris]
- struct map_session_data *sd = ((struct map_session_data *) bl);
- if (sd && sd->disguise > 23 && sd->disguise < 4001)
- clif_spawnpc (sd);
- }
-
- WBUFW (buf, 0) = 0x148;
- WBUFL (buf, 2) = bl->id;
- WBUFW (buf, 6) = type;
-
- clif_send (buf, packet_len_table[0x148], bl, type == 1 ? AREA : AREA_WOS);
-
- return 0;
-}
-
-/*==========================================
- * PVP実装?(仮)
- *------------------------------------------
- */
-int clif_set0199 (int fd, int type)
-{
- WFIFOW (fd, 0) = 0x199;
- WFIFOW (fd, 2) = type;
- WFIFOSET (fd, packet_len_table[0x199]);
-
- return 0;
-}
-
-/*==========================================
- * PVP実装?(仮)
- *------------------------------------------
- */
-int clif_pvpset (struct map_session_data *sd, int pvprank, int pvpnum,
- int type)
-{
- nullpo_retr (0, sd);
-
- if (map[sd->bl.m].flag.nopvp)
- return 0;
+ nullpo_ret(bl);
- if (type == 2)
- {
- WFIFOW (sd->fd, 0) = 0x19a;
- WFIFOL (sd->fd, 2) = sd->bl.id;
- if (pvprank <= 0)
- pc_calc_pvprank (sd);
- WFIFOL (sd->fd, 6) = pvprank;
- WFIFOL (sd->fd, 10) = pvpnum;
- WFIFOSET (sd->fd, packet_len_table[0x19a]);
- }
- else
- {
- uint8_t buf[32];
+ WBUFW(buf, 0) = 0x148;
+ WBUFL(buf, 2) = bl->id;
+ WBUFW(buf, 6) = type;
- WBUFW (buf, 0) = 0x19a;
- WBUFL (buf, 2) = sd->bl.id;
- if (sd->status.option & 0x46)
- WBUFL (buf, 6) = -1;
- else if (pvprank <= 0)
- pc_calc_pvprank (sd);
- WBUFL (buf, 6) = pvprank;
- WBUFL (buf, 10) = pvpnum;
- if (!type)
- clif_send (buf, packet_len_table[0x19a], &sd->bl, AREA);
- else
- clif_send (buf, packet_len_table[0x19a], &sd->bl, ALL_SAMEMAP);
- }
-
- return 0;
-}
-
-/*==========================================
- *
- *------------------------------------------
- */
-int clif_send0199 (int m, int type)
-{
- struct block_list bl;
- uint8_t buf[16];
-
- bl.m = m;
- WBUFW (buf, 0) = 0x199;
- WBUFW (buf, 2) = type;
- clif_send (buf, packet_len_table[0x199], &bl, ALL_SAMEMAP);
-
- return 0;
-}
-
-/*==========================================
- * 精錬エフェクトをé€ä¿¡ã™ã‚‹
- *------------------------------------------
- */
-int clif_refine (int fd, struct map_session_data *sd, int fail, int index,
- int val)
-{
- WFIFOW (fd, 0) = 0x188;
- WFIFOW (fd, 2) = fail;
- WFIFOW (fd, 4) = index + 2;
- WFIFOW (fd, 6) = val;
- WFIFOSET (fd, packet_len_table[0x188]);
+ clif_send(buf, clif_parse_func_table[0x148].len, bl, type == 1 ? SendWho::AREA : SendWho::AREA_WOS);
return 0;
}
@@ -4771,13 +3248,13 @@ int clif_refine (int fd, struct map_session_data *sd, int fail, int index,
* Wisp/page is transmitted to the destination player
*------------------------------------------
*/
-int clif_wis_message (int fd, const char *nick, const char *mes, int mes_len) // R 0097 <len>.w <nick>.24B <message>.?B
+int clif_wis_message(int fd, const char *nick, const char *mes, int mes_len) // R 0097 <len>.w <nick>.24B <message>.?B
{
- WFIFOW (fd, 0) = 0x97;
- WFIFOW (fd, 2) = mes_len + 24 + 4;
- memcpy (WFIFOP (fd, 4), nick, 24);
- memcpy (WFIFOP (fd, 28), mes, mes_len);
- WFIFOSET (fd, WFIFOW (fd, 2));
+ WFIFOW(fd, 0) = 0x97;
+ WFIFOW(fd, 2) = mes_len + 24 + 4;
+ memcpy(WFIFOP(fd, 4), nick, 24);
+ memcpy(WFIFOP(fd, 28), mes, mes_len);
+ WFIFOSET(fd, WFIFOW(fd, 2));
return 0;
}
@@ -4785,432 +3262,11 @@ int clif_wis_message (int fd, const char *nick, const char *mes, int mes_len)
* The transmission result of Wisp/page is transmitted to the source player
*------------------------------------------
*/
-int clif_wis_end (int fd, int flag) // R 0098 <type>.B: 0: success to send wisper, 1: target character is not loged in?, 2: ignored by target
-{
- WFIFOW (fd, 0) = 0x98;
- WFIFOW (fd, 2) = flag;
- WFIFOSET (fd, packet_len_table[0x98]);
- return 0;
-}
-
-/*==========================================
- * キャラIDåå‰å¼•ãçµæžœã‚’é€ä¿¡ã™ã‚‹
- *------------------------------------------
- */
-int clif_solved_charname (struct map_session_data *sd, int char_id)
+int clif_wis_end(int fd, int flag) // R 0098 <type>.B: 0: success to send wisper, 1: target character is not loged in?, 2: ignored by target
{
- char *p = map_charid2nick (char_id);
- int fd;
-
- nullpo_retr (0, sd);
-
- fd = sd->fd;
- if (p != NULL)
- {
- WFIFOW (fd, 0) = 0x194;
- WFIFOL (fd, 2) = char_id;
- memcpy (WFIFOP (fd, 6), p, 24);
- WFIFOSET (fd, packet_len_table[0x194]);
- }
- else
- {
- map_reqchariddb (sd, char_id);
- chrif_searchcharid (char_id);
- }
- return 0;
-}
-
-/*==========================================
- * カードã®æŒ¿å…¥å¯èƒ½ãƒªã‚¹ãƒˆã‚’è¿”ã™
- *------------------------------------------
- */
-int clif_use_card (struct map_session_data *sd, int idx)
-{
- nullpo_retr (0, sd);
-
- if (sd->inventory_data[idx])
- {
- int i, c;
- int ep = sd->inventory_data[idx]->equip;
- int fd = sd->fd;
- WFIFOW (fd, 0) = 0x017b;
-
- for (i = c = 0; i < MAX_INVENTORY; i++)
- {
- int j;
-
- if (sd->inventory_data[i] == NULL)
- continue;
- if (sd->inventory_data[i]->type != 4 && sd->inventory_data[i]->type != 5) // 武器防具ã˜ã‚ƒãªã„
- continue;
- if (sd->status.inventory[i].card[0] == 0x00ff) // 製造武器
- continue;
- if (sd->status.inventory[i].card[0] == (short) 0xff00
- || sd->status.inventory[i].card[0] == 0x00fe)
- continue;
- if (sd->status.inventory[i].identify == 0) // 未鑑定
- continue;
-
- if ((sd->inventory_data[i]->equip & ep) == 0) // 装備個所ãŒé•ã†
- continue;
- if (sd->inventory_data[i]->type == 4 && ep == 32) // 盾カードã¨ä¸¡æ‰‹æ­¦å™¨
- continue;
-
- for (j = 0; j < sd->inventory_data[i]->slot; j++)
- {
- if (sd->status.inventory[i].card[j] == 0)
- break;
- }
- if (j == sd->inventory_data[i]->slot) // ã™ã§ã«ã‚«ãƒ¼ãƒ‰ãŒä¸€æ¯
- continue;
-
- WFIFOW (fd, 4 + c * 2) = i + 2;
- c++;
- }
- WFIFOW (fd, 2) = 4 + c * 2;
- WFIFOSET (fd, WFIFOW (fd, 2));
- }
-
- return 0;
-}
-
-/*==========================================
- * カードã®æŒ¿å…¥çµ‚了
- *------------------------------------------
- */
-int clif_insert_card (struct map_session_data *sd, int idx_equip,
- int idx_card, int flag)
-{
- int fd;
-
- nullpo_retr (0, sd);
-
- fd = sd->fd;
- WFIFOW (fd, 0) = 0x17d;
- WFIFOW (fd, 2) = idx_equip + 2;
- WFIFOW (fd, 4) = idx_card + 2;
- WFIFOB (fd, 6) = flag;
- WFIFOSET (fd, packet_len_table[0x17d]);
- return 0;
-}
-
-/*==========================================
- * 鑑定å¯èƒ½ã‚¢ã‚¤ãƒ†ãƒ ãƒªã‚¹ãƒˆé€ä¿¡
- *------------------------------------------
- */
-int clif_item_identify_list (struct map_session_data *sd)
-{
- int i, c;
- int fd;
-
- nullpo_retr (0, sd);
-
- fd = sd->fd;
-
- WFIFOW (fd, 0) = 0x177;
- for (i = c = 0; i < MAX_INVENTORY; i++)
- {
- if (sd->status.inventory[i].nameid > 0
- && sd->status.inventory[i].identify != 1)
- {
- WFIFOW (fd, c * 2 + 4) = i + 2;
- c++;
- }
- }
- if (c > 0)
- {
- WFIFOW (fd, 2) = c * 2 + 4;
- WFIFOSET (fd, WFIFOW (fd, 2));
- }
- return 0;
-}
-
-/*==========================================
- * 鑑定çµæžœ
- *------------------------------------------
- */
-int clif_item_identified (struct map_session_data *sd, int idx, int flag)
-{
- int fd;
-
- nullpo_retr (0, sd);
-
- fd = sd->fd;
- WFIFOW (fd, 0) = 0x179;
- WFIFOW (fd, 2) = idx + 2;
- WFIFOB (fd, 4) = flag;
- WFIFOSET (fd, packet_len_table[0x179]);
- return 0;
-}
-
-/*==========================================
- * ä¿®ç†å¯èƒ½ã‚¢ã‚¤ãƒ†ãƒ ãƒªã‚¹ãƒˆé€ä¿¡
- * ※実際ã®ãƒ‘ケットãŒã‚ã‹ã‚‰ãªã„ã®ã§å‹•ä½œã—ã¾ã›ã‚“
- *------------------------------------------
- */
-int clif_item_repair_list (struct map_session_data *sd)
-{
- int i, c;
- int fd;
-
- nullpo_retr (0, sd);
-
- fd = sd->fd;
-
- WFIFOW (fd, 0) = 0x0;
- for (i = c = 0; i < MAX_INVENTORY; i++)
- {
- if (sd->status.inventory[i].nameid > 0
- && sd->status.inventory[i].broken != 0)
- {
- WFIFOW (fd, c * 2 + 4) = i + 2;
- c++;
- }
- }
- if (c > 0)
- {
- WFIFOW (fd, 2) = c * 2 + 4;
- WFIFOSET (fd, WFIFOW (fd, 2));
- }
- return 0;
-}
-
-/*==========================================
- * アイテムã«ã‚ˆã‚‹ä¸€æ™‚çš„ãªã‚¹ã‚­ãƒ«åŠ¹æžœ
- *------------------------------------------
- */
-int clif_item_skill (struct map_session_data *sd, int skillid, int skilllv,
- const char *name)
-{
- int range, fd;
-
- nullpo_retr (0, sd);
-
- fd = sd->fd;
- WFIFOW (fd, 0) = 0x147;
- WFIFOW (fd, 2) = skillid;
- WFIFOW (fd, 4) = skill_get_inf (skillid);
- WFIFOW (fd, 6) = 0;
- WFIFOW (fd, 8) = skilllv;
- WFIFOW (fd, 10) = skill_get_sp (skillid, skilllv);
- range = skill_get_range (skillid, skilllv);
- if (range < 0)
- range = battle_get_range (&sd->bl) - (range + 1);
- WFIFOW (fd, 12) = range;
- memcpy (WFIFOP (fd, 14), name, 24);
- WFIFOB (fd, 38) = 0;
- WFIFOSET (fd, packet_len_table[0x147]);
- return 0;
-}
-
-/*==========================================
- * カートã«ã‚¢ã‚¤ãƒ†ãƒ è¿½åŠ 
- *------------------------------------------
- */
-int clif_cart_additem (struct map_session_data *sd, int n, int amount,
- int fail)
-{
- int view, j, fd;
- unsigned char *buf;
-
- nullpo_retr (0, sd);
-
- fd = sd->fd;
- buf = WFIFOP (fd, 0);
- if (n < 0 || n >= MAX_CART || sd->status.cart[n].nameid <= 0)
- return 1;
-
- WBUFW (buf, 0) = 0x124;
- WBUFW (buf, 2) = n + 2;
- WBUFL (buf, 4) = amount;
- if ((view = itemdb_viewid (sd->status.cart[n].nameid)) > 0)
- WBUFW (buf, 8) = view;
- else
- WBUFW (buf, 8) = sd->status.cart[n].nameid;
- WBUFB (buf, 10) = sd->status.cart[n].identify;
- if (sd->status.cart[n].broken == 1) //is weapon broken [Valaris]
- WBUFB (buf, 11) = 1;
- else
- WBUFB (buf, 11) = sd->status.cart[n].attribute;
- WBUFB (buf, 12) = sd->status.cart[n].refine;
- if (sd->status.cart[n].card[0] == 0x00ff
- || sd->status.cart[n].card[0] == 0x00fe
- || sd->status.cart[n].card[0] == (short) 0xff00)
- {
- WBUFW (buf, 13) = sd->status.cart[n].card[0];
- WBUFW (buf, 15) = sd->status.cart[n].card[1];
- WBUFW (buf, 17) = sd->status.cart[n].card[2];
- WBUFW (buf, 19) = sd->status.cart[n].card[3];
- }
- else
- {
- if (sd->status.cart[n].card[0] > 0
- && (j = itemdb_viewid (sd->status.cart[n].card[0])) > 0)
- WBUFW (buf, 13) = j;
- else
- WBUFW (buf, 13) = sd->status.cart[n].card[0];
- if (sd->status.cart[n].card[1] > 0
- && (j = itemdb_viewid (sd->status.cart[n].card[1])) > 0)
- WBUFW (buf, 15) = j;
- else
- WBUFW (buf, 15) = sd->status.cart[n].card[1];
- if (sd->status.cart[n].card[2] > 0
- && (j = itemdb_viewid (sd->status.cart[n].card[2])) > 0)
- WBUFW (buf, 17) = j;
- else
- WBUFW (buf, 17) = sd->status.cart[n].card[2];
- if (sd->status.cart[n].card[3] > 0
- && (j = itemdb_viewid (sd->status.cart[n].card[3])) > 0)
- WBUFW (buf, 19) = j;
- else
- WBUFW (buf, 19) = sd->status.cart[n].card[3];
- }
- WFIFOSET (fd, packet_len_table[0x124]);
- return 0;
-}
-
-/*==========================================
- * カートã‹ã‚‰ã‚¢ã‚¤ãƒ†ãƒ å‰Šé™¤
- *------------------------------------------
- */
-int clif_cart_delitem (struct map_session_data *sd, int n, int amount)
-{
- int fd;
-
- nullpo_retr (0, sd);
-
- fd = sd->fd;
-
- WFIFOW (fd, 0) = 0x125;
- WFIFOW (fd, 2) = n + 2;
- WFIFOL (fd, 4) = amount;
-
- WFIFOSET (fd, packet_len_table[0x125]);
-
- return 0;
-}
-
-/*==========================================
- * カートã®ã‚¢ã‚¤ãƒ†ãƒ ãƒªã‚¹ãƒˆ
- *------------------------------------------
- */
-int clif_cart_itemlist (struct map_session_data *sd)
-{
- struct item_data *id;
- int i, n, fd;
- unsigned char *buf;
-
- nullpo_retr (0, sd);
-
- fd = sd->fd;
- buf = WFIFOP (fd, 0);
- WBUFW (buf, 0) = 0x1ef;
- for (i = 0, n = 0; i < MAX_CART; i++)
- {
- if (sd->status.cart[i].nameid <= 0)
- continue;
- id = itemdb_search (sd->status.cart[i].nameid);
- if (itemdb_isequip2 (id))
- continue;
- WBUFW (buf, n * 18 + 4) = i + 2;
- if (id->view_id > 0)
- WBUFW (buf, n * 18 + 6) = id->view_id;
- else
- WBUFW (buf, n * 18 + 6) = sd->status.cart[i].nameid;
- WBUFB (buf, n * 18 + 8) = id->type;
- WBUFB (buf, n * 18 + 9) = sd->status.cart[i].identify;
- WBUFW (buf, n * 18 + 10) = sd->status.cart[i].amount;
- WBUFW (buf, n * 18 + 12) = 0;
- WBUFW (buf, n * 18 + 14) = sd->status.cart[i].card[0];
- WBUFW (buf, n * 18 + 16) = sd->status.cart[i].card[1];
- WBUFW (buf, n * 18 + 18) = sd->status.cart[i].card[2];
- WBUFW (buf, n * 18 + 20) = sd->status.cart[i].card[3];
- n++;
- }
- if (n)
- {
- WBUFW (buf, 2) = 4 + n * 18;
- WFIFOSET (fd, WFIFOW (fd, 2));
- }
- return 0;
-}
-
-/*==========================================
- * カートã®è£…å‚™å“リスト
- *------------------------------------------
- */
-int clif_cart_equiplist (struct map_session_data *sd)
-{
- struct item_data *id;
- int i, j, n, fd;
- unsigned char *buf;
-
- nullpo_retr (0, sd);
-
- fd = sd->fd;
- buf = WFIFOP (fd, 0);
-
- WBUFW (buf, 0) = 0x122;
- for (i = 0, n = 0; i < MAX_INVENTORY; i++)
- {
- if (sd->status.cart[i].nameid <= 0)
- continue;
- id = itemdb_search (sd->status.cart[i].nameid);
- if (!itemdb_isequip2 (id))
- continue;
- WBUFW (buf, n * 20 + 4) = i + 2;
- if (id->view_id > 0)
- WBUFW (buf, n * 20 + 6) = id->view_id;
- else
- WBUFW (buf, n * 20 + 6) = sd->status.cart[i].nameid;
- WBUFB (buf, n * 20 + 8) = id->type;
- WBUFB (buf, n * 20 + 9) = sd->status.cart[i].identify;
- WBUFW (buf, n * 20 + 10) = id->equip;
- WBUFW (buf, n * 20 + 12) = sd->status.cart[i].equip;
- if (sd->status.cart[i].broken == 1)
- WBUFB (buf, n * 20 + 14) = 1; //is weapon broken [Valaris]
- else
- WBUFB (buf, n * 20 + 14) = sd->status.cart[i].attribute;
- WBUFB (buf, n * 20 + 15) = sd->status.cart[i].refine;
- if (sd->status.cart[i].card[0] == 0x00ff
- || sd->status.cart[i].card[0] == 0x00fe
- || sd->status.cart[i].card[0] == (short) 0xff00)
- {
- WBUFW (buf, n * 20 + 16) = sd->status.cart[i].card[0];
- WBUFW (buf, n * 20 + 18) = sd->status.cart[i].card[1];
- WBUFW (buf, n * 20 + 20) = sd->status.cart[i].card[2];
- WBUFW (buf, n * 20 + 22) = sd->status.cart[i].card[3];
- }
- else
- {
- if (sd->status.cart[i].card[0] > 0
- && (j = itemdb_viewid (sd->status.cart[i].card[0])) > 0)
- WBUFW (buf, n * 20 + 16) = j;
- else
- WBUFW (buf, n * 20 + 16) = sd->status.cart[i].card[0];
- if (sd->status.cart[i].card[1] > 0
- && (j = itemdb_viewid (sd->status.cart[i].card[1])) > 0)
- WBUFW (buf, n * 20 + 18) = j;
- else
- WBUFW (buf, n * 20 + 18) = sd->status.cart[i].card[1];
- if (sd->status.cart[i].card[2] > 0
- && (j = itemdb_viewid (sd->status.cart[i].card[2])) > 0)
- WBUFW (buf, n * 20 + 20) = j;
- else
- WBUFW (buf, n * 20 + 20) = sd->status.cart[i].card[2];
- if (sd->status.cart[i].card[3] > 0
- && (j = itemdb_viewid (sd->status.cart[i].card[3])) > 0)
- WBUFW (buf, n * 20 + 22) = j;
- else
- WBUFW (buf, n * 20 + 22) = sd->status.cart[i].card[3];
- }
- n++;
- }
- if (n)
- {
- WBUFW (buf, 2) = 4 + n * 20;
- WFIFOSET (fd, WFIFOW (fd, 2));
- }
+ WFIFOW(fd, 0) = 0x98;
+ WFIFOW(fd, 2) = flag;
+ WFIFOSET(fd, clif_parse_func_table[0x98].len);
return 0;
}
@@ -5226,16 +3282,16 @@ int clif_cart_equiplist (struct map_session_data *sd)
* 2 The character is already in a party.
*------------------------------------------
*/
-int clif_party_created (struct map_session_data *sd, int flag)
+int clif_party_created(struct map_session_data *sd, int flag)
{
- int fd;
+ int fd;
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
fd = sd->fd;
- WFIFOW (fd, 0) = 0xfa;
- WFIFOB (fd, 2) = flag;
- WFIFOSET (fd, packet_len_table[0xfa]);
+ WFIFOW(fd, 0) = 0xfa;
+ WFIFOB(fd, 2) = flag;
+ WFIFOSET(fd, clif_parse_func_table[0xfa].len);
return 0;
}
@@ -5243,16 +3299,16 @@ int clif_party_created (struct map_session_data *sd, int flag)
* パーティ情報é€ä¿¡
*------------------------------------------
*/
-int clif_party_info (struct party *p, int fd)
+int clif_party_info(struct party *p, int fd)
{
unsigned char buf[1024];
- int i, c;
+ int i, c;
struct map_session_data *sd = NULL;
- nullpo_retr (0, p);
+ nullpo_ret(p);
- WBUFW (buf, 0) = 0xfb;
- memcpy (WBUFP (buf, 4), p->name, 24);
+ WBUFW(buf, 0) = 0xfb;
+ memcpy(WBUFP(buf, 4), p->name, 24);
for (i = c = 0; i < MAX_PARTY; i++)
{
struct party_member *m = &p->member[i];
@@ -5260,23 +3316,23 @@ int clif_party_info (struct party *p, int fd)
{
if (sd == NULL)
sd = m->sd;
- WBUFL (buf, 28 + c * 46) = m->account_id;
- memcpy (WBUFP (buf, 28 + c * 46 + 4), m->name, 24);
- memcpy (WBUFP (buf, 28 + c * 46 + 28), m->map, 16);
- WBUFB (buf, 28 + c * 46 + 44) = (m->leader) ? 0 : 1;
- WBUFB (buf, 28 + c * 46 + 45) = (m->online) ? 0 : 1;
+ WBUFL(buf, 28 + c * 46) = m->account_id;
+ memcpy(WBUFP(buf, 28 + c * 46 + 4), m->name, 24);
+ memcpy(WBUFP(buf, 28 + c * 46 + 28), m->map, 16);
+ WBUFB(buf, 28 + c * 46 + 44) = (m->leader) ? 0 : 1;
+ WBUFB(buf, 28 + c * 46 + 45) = (m->online) ? 0 : 1;
c++;
}
}
- WBUFW (buf, 2) = 28 + c * 46;
+ WBUFW(buf, 2) = 28 + c * 46;
if (fd >= 0)
{ // fdãŒè¨­å®šã•ã‚Œã¦ã‚‹ãªã‚‰ãã‚Œã«é€ã‚‹
- memcpy (WFIFOP (fd, 0), buf, WBUFW (buf, 2));
- WFIFOSET (fd, WFIFOW (fd, 2));
+ memcpy(WFIFOP(fd, 0), buf, WBUFW(buf, 2));
+ WFIFOSET(fd, WFIFOW(fd, 2));
return 9;
}
if (sd != NULL)
- clif_send (buf, WBUFW (buf, 2), &sd->bl, PARTY);
+ clif_send(buf, WBUFW(buf, 2), &sd->bl, SendWho::PARTY);
return 0;
}
@@ -5287,24 +3343,24 @@ int clif_party_info (struct party *p, int fd)
* (R 00fe <sender_ID>.l <party_name>.24B)
*------------------------------------------
*/
-int clif_party_invite (struct map_session_data *sd,
+int clif_party_invite(struct map_session_data *sd,
struct map_session_data *tsd)
{
- int fd;
+ int fd;
struct party *p;
- nullpo_retr (0, sd);
- nullpo_retr (0, tsd);
+ nullpo_ret(sd);
+ nullpo_ret(tsd);
fd = tsd->fd;
- if (!(p = party_search (sd->status.party_id)))
+ if (!(p = party_search(sd->status.party_id)))
return 0;
- WFIFOW (fd, 0) = 0xfe;
- WFIFOL (fd, 2) = sd->status.account_id;
- memcpy (WFIFOP (fd, 6), p->name, 24);
- WFIFOSET (fd, packet_len_table[0xfe]);
+ WFIFOW(fd, 0) = 0xfe;
+ WFIFOL(fd, 2) = sd->status.account_id;
+ memcpy(WFIFOP(fd, 6), p->name, 24);
+ WFIFOSET(fd, clif_parse_func_table[0xfe].len);
return 0;
}
@@ -5322,17 +3378,17 @@ int clif_party_invite (struct map_session_data *sd,
* 4 The character is in the same party.
*------------------------------------------
*/
-int clif_party_inviteack (struct map_session_data *sd, const char *nick, int flag)
+int clif_party_inviteack(struct map_session_data *sd, const char *nick, int flag)
{
- int fd;
+ int fd;
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
fd = sd->fd;
- WFIFOW (fd, 0) = 0xfd;
- memcpy (WFIFOP (fd, 2), nick, 24);
- WFIFOB (fd, 26) = flag;
- WFIFOSET (fd, packet_len_table[0xfd]);
+ WFIFOW(fd, 0) = 0xfd;
+ memcpy(WFIFOP(fd, 2), nick, 24);
+ WFIFOB(fd, 26) = flag;
+ WFIFOSET(fd, clif_parse_func_table[0xfd].len);
return 0;
}
@@ -5343,32 +3399,32 @@ int clif_party_inviteack (struct map_session_data *sd, const char *nick, int fla
* 0x100=一人ã«ã®ã¿é€ä¿¡
*------------------------------------------
*/
-int clif_party_option (struct party *p, struct map_session_data *sd, int flag)
+int clif_party_option(struct party *p, struct map_session_data *sd, int flag)
{
unsigned char buf[16];
- nullpo_retr (0, p);
+ nullpo_ret(p);
// if(battle_config.etc_log)
-// printf("clif_party_option: %d %d %d\n",p->exp,p->item,flag);
+// PRINTF("clif_party_option: %d %d %d\n",p->exp,p->item,flag);
if (sd == NULL && flag == 0)
{
- int i;
+ int i;
for (i = 0; i < MAX_PARTY; i++)
- if ((sd = map_id2sd (p->member[i].account_id)) != NULL)
+ if ((sd = map_id2sd(p->member[i].account_id)) != NULL)
break;
}
if (sd == NULL)
return 0;
- WBUFW (buf, 0) = 0x101;
- WBUFW (buf, 2) = ((flag & 0x01) ? 2 : p->exp);
- WBUFW (buf, 4) = ((flag & 0x10) ? 2 : p->item);
+ WBUFW(buf, 0) = 0x101;
+ WBUFW(buf, 2) = ((flag & 0x01) ? 2 : p->exp);
+ WBUFW(buf, 4) = ((flag & 0x10) ? 2 : p->item);
if (flag == 0)
- clif_send (buf, packet_len_table[0x101], &sd->bl, PARTY);
+ clif_send(buf, clif_parse_func_table[0x101].len, &sd->bl, SendWho::PARTY);
else
{
- memcpy (WFIFOP (sd->fd, 0), buf, packet_len_table[0x101]);
- WFIFOSET (sd->fd, packet_len_table[0x101]);
+ memcpy(WFIFOP(sd->fd, 0), buf, clif_parse_func_table[0x101].len);
+ WFIFOSET(sd->fd, clif_parse_func_table[0x101].len);
}
return 0;
}
@@ -5377,18 +3433,18 @@ int clif_party_option (struct party *p, struct map_session_data *sd, int flag)
* パーティ脱退(脱退å‰ã«å‘¼ã¶ã“ã¨ï¼‰
*------------------------------------------
*/
-int clif_party_leaved (struct party *p, struct map_session_data *sd,
+int clif_party_leaved(struct party *p, struct map_session_data *sd,
int account_id, const char *name, int flag)
{
unsigned char buf[64];
- int i;
+ int i;
- nullpo_retr (0, p);
+ nullpo_ret(p);
- WBUFW (buf, 0) = 0x105;
- WBUFL (buf, 2) = account_id;
- memcpy (WBUFP (buf, 6), name, 24);
- WBUFB (buf, 30) = flag & 0x0f;
+ WBUFW(buf, 0) = 0x105;
+ WBUFL(buf, 2) = account_id;
+ memcpy(WBUFP(buf, 6), name, 24);
+ WBUFB(buf, 30) = flag & 0x0f;
if ((flag & 0xf0) == 0)
{
@@ -5397,12 +3453,12 @@ int clif_party_leaved (struct party *p, struct map_session_data *sd,
if ((sd = p->member[i].sd) != NULL)
break;
if (sd != NULL)
- clif_send (buf, packet_len_table[0x105], &sd->bl, PARTY);
+ clif_send(buf, clif_parse_func_table[0x105].len, &sd->bl, SendWho::PARTY);
}
else if (sd != NULL)
{
- memcpy (WFIFOP (sd->fd, 0), buf, packet_len_table[0x105]);
- WFIFOSET (sd->fd, packet_len_table[0x105]);
+ memcpy(WFIFOP(sd->fd, 0), buf, clif_parse_func_table[0x105].len);
+ WFIFOSET(sd->fd, clif_parse_func_table[0x105].len);
}
return 0;
}
@@ -5411,12 +3467,13 @@ int clif_party_leaved (struct party *p, struct map_session_data *sd,
* パーティメッセージé€ä¿¡
*------------------------------------------
*/
-int clif_party_message (struct party *p, int account_id, const char *mes, int len)
+int clif_party_message(struct party *p, int account_id, const char *mes, int len)
{
- struct map_session_data *sd;
- int i;
+ // always set, but clang is not smart enough
+ struct map_session_data *sd = nullptr;
+ int i;
- nullpo_retr (0, p);
+ nullpo_ret(p);
for (i = 0; i < MAX_PARTY; i++)
{
@@ -5426,11 +3483,11 @@ int clif_party_message (struct party *p, int account_id, const char *mes, int le
if (sd != NULL)
{
unsigned char buf[1024];
- WBUFW (buf, 0) = 0x109;
- WBUFW (buf, 2) = len + 8;
- WBUFL (buf, 4) = account_id;
- memcpy (WBUFP (buf, 8), mes, len);
- clif_send (buf, len + 8, &sd->bl, PARTY);
+ WBUFW(buf, 0) = 0x109;
+ WBUFW(buf, 2) = len + 8;
+ WBUFL(buf, 4) = account_id;
+ memcpy(WBUFP(buf, 8), mes, len);
+ clif_send(buf, len + 8, &sd->bl, SendWho::PARTY);
}
return 0;
}
@@ -5439,19 +3496,19 @@ int clif_party_message (struct party *p, int account_id, const char *mes, int le
* パーティ座標通知
*------------------------------------------
*/
-int clif_party_xy (struct party *p, struct map_session_data *sd)
+int clif_party_xy(struct party *, struct map_session_data *sd)
{
unsigned char buf[16];
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
- WBUFW (buf, 0) = 0x107;
- WBUFL (buf, 2) = sd->status.account_id;
- WBUFW (buf, 6) = sd->bl.x;
- WBUFW (buf, 8) = sd->bl.y;
- clif_send (buf, packet_len_table[0x107], &sd->bl, PARTY_SAMEMAP_WOS);
+ WBUFW(buf, 0) = 0x107;
+ WBUFL(buf, 2) = sd->status.account_id;
+ WBUFW(buf, 6) = sd->bl.x;
+ WBUFW(buf, 8) = sd->bl.y;
+ clif_send(buf, clif_parse_func_table[0x107].len, &sd->bl, SendWho::PARTY_SAMEMAP_WOS);
// if(battle_config.etc_log)
-// printf("clif_party_xy %d\n",sd->status.account_id);
+// PRINTF("clif_party_xy %d\n",sd->status.account_id);
return 0;
}
@@ -5459,44 +3516,20 @@ int clif_party_xy (struct party *p, struct map_session_data *sd)
* パーティHP通知
*------------------------------------------
*/
-int clif_party_hp (struct party *p, struct map_session_data *sd)
+int clif_party_hp(struct party *, struct map_session_data *sd)
{
unsigned char buf[16];
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
- WBUFW (buf, 0) = 0x106;
- WBUFL (buf, 2) = sd->status.account_id;
- WBUFW (buf, 6) = (sd->status.hp > 0x7fff) ? 0x7fff : sd->status.hp;
- WBUFW (buf, 8) =
+ WBUFW(buf, 0) = 0x106;
+ WBUFL(buf, 2) = sd->status.account_id;
+ WBUFW(buf, 6) = (sd->status.hp > 0x7fff) ? 0x7fff : sd->status.hp;
+ WBUFW(buf, 8) =
(sd->status.max_hp > 0x7fff) ? 0x7fff : sd->status.max_hp;
- clif_send (buf, packet_len_table[0x106], &sd->bl, PARTY_AREA_WOS);
+ clif_send(buf, clif_parse_func_table[0x106].len, &sd->bl, SendWho::PARTY_AREA_WOS);
// if(battle_config.etc_log)
-// printf("clif_party_hp %d\n",sd->status.account_id);
- return 0;
-}
-
-/*==========================================
- * パーティ場所移動(未使用)
- *------------------------------------------
- */
-int clif_party_move (struct party *p, struct map_session_data *sd, int online)
-{
- unsigned char buf[128];
-
- nullpo_retr (0, sd);
- nullpo_retr (0, p);
-
- WBUFW (buf, 0) = 0x104;
- WBUFL (buf, 2) = sd->status.account_id;
- WBUFL (buf, 6) = 0;
- WBUFW (buf, 10) = sd->bl.x;
- WBUFW (buf, 12) = sd->bl.y;
- WBUFB (buf, 14) = !online;
- memcpy (WBUFP (buf, 15), p->name, 24);
- memcpy (WBUFP (buf, 39), sd->status.name, 24);
- memcpy (WBUFP (buf, 63), map[sd->bl.m].name, 16);
- clif_send (buf, packet_len_table[0x104], &sd->bl, PARTY);
+// PRINTF("clif_party_hp %d\n",sd->status.account_id);
return 0;
}
@@ -5504,199 +3537,22 @@ int clif_party_move (struct party *p, struct map_session_data *sd, int online)
* 攻撃ã™ã‚‹ãŸã‚ã«ç§»å‹•ãŒå¿…è¦
*------------------------------------------
*/
-int clif_movetoattack (struct map_session_data *sd, struct block_list *bl)
-{
- int fd;
-
- nullpo_retr (0, sd);
- nullpo_retr (0, bl);
-
- fd = sd->fd;
- WFIFOW (fd, 0) = 0x139;
- WFIFOL (fd, 2) = bl->id;
- WFIFOW (fd, 6) = bl->x;
- WFIFOW (fd, 8) = bl->y;
- WFIFOW (fd, 10) = sd->bl.x;
- WFIFOW (fd, 12) = sd->bl.y;
- WFIFOW (fd, 14) = sd->attackrange;
- WFIFOSET (fd, packet_len_table[0x139]);
- return 0;
-}
-
-/*==========================================
- * 製造エフェクト
- *------------------------------------------
- */
-int clif_produceeffect (struct map_session_data *sd, int flag, int nameid)
+int clif_movetoattack(struct map_session_data *sd, struct block_list *bl)
{
- int view, fd;
-
- nullpo_retr (0, sd);
-
- fd = sd->fd;
- // åå‰ã®ç™»éŒ²ã¨é€ä¿¡ã‚’å…ˆã«ã—ã¦ãŠã
- if (map_charid2nick (sd->status.char_id) == NULL)
- map_addchariddb (sd->status.char_id, sd->status.name);
- clif_solved_charname (sd, sd->status.char_id);
-
- WFIFOW (fd, 0) = 0x18f;
- WFIFOW (fd, 2) = flag;
- if ((view = itemdb_viewid (nameid)) > 0)
- WFIFOW (fd, 4) = view;
- else
- WFIFOW (fd, 4) = nameid;
- WFIFOSET (fd, packet_len_table[0x18f]);
- return 0;
-}
-
-/*==========================================
- * オートスペル リストé€ä¿¡
- *------------------------------------------
- */
-int clif_autospell (struct map_session_data *sd, int skilllv)
-{
- int fd;
+ int fd;
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
+ nullpo_ret(bl);
fd = sd->fd;
- WFIFOW (fd, 0) = 0x1cd;
-
- if (skilllv > 0 && pc_checkskill (sd, MG_NAPALMBEAT) > 0)
- WFIFOL (fd, 2) = MG_NAPALMBEAT;
- else
- WFIFOL (fd, 2) = 0x00000000;
- if (skilllv > 1 && pc_checkskill (sd, MG_COLDBOLT) > 0)
- WFIFOL (fd, 6) = MG_COLDBOLT;
- else
- WFIFOL (fd, 6) = 0x00000000;
- if (skilllv > 1 && pc_checkskill (sd, MG_FIREBOLT) > 0)
- WFIFOL (fd, 10) = MG_FIREBOLT;
- else
- WFIFOL (fd, 10) = 0x00000000;
- if (skilllv > 1 && pc_checkskill (sd, MG_LIGHTNINGBOLT) > 0)
- WFIFOL (fd, 14) = MG_LIGHTNINGBOLT;
- else
- WFIFOL (fd, 14) = 0x00000000;
- if (skilllv > 4 && pc_checkskill (sd, MG_SOULSTRIKE) > 0)
- WFIFOL (fd, 18) = MG_SOULSTRIKE;
- else
- WFIFOL (fd, 18) = 0x00000000;
- if (skilllv > 7 && pc_checkskill (sd, MG_FIREBALL) > 0)
- WFIFOL (fd, 22) = MG_FIREBALL;
- else
- WFIFOL (fd, 22) = 0x00000000;
- if (skilllv > 9 && pc_checkskill (sd, MG_FROSTDIVER) > 0)
- WFIFOL (fd, 26) = MG_FROSTDIVER;
- else
- WFIFOL (fd, 26) = 0x00000000;
-
- WFIFOSET (fd, packet_len_table[0x1cd]);
- return 0;
-}
-
-/*==========================================
- * ディボーションã®é’ã„糸
- *------------------------------------------
- */
-int clif_devotion (struct map_session_data *sd, int target)
-{
- unsigned char buf[56];
- int n;
-
- nullpo_retr (0, sd);
-
- WBUFW (buf, 0) = 0x1cf;
- WBUFL (buf, 2) = sd->bl.id;
-// WBUFL(buf,6)=target;
- for (n = 0; n < 5; n++)
- WBUFL (buf, 6 + 4 * n) = sd->dev.val2[n];
-// WBUFL(buf,10+4*n)=0;
- WBUFB (buf, 26) = 8;
- WBUFB (buf, 27) = 0;
-
- clif_send (buf, packet_len_table[0x1cf], &sd->bl, AREA);
- return 0;
-}
-
-/*==========================================
- * æ°£çƒ
- *------------------------------------------
- */
-int clif_spiritball (struct map_session_data *sd)
-{
- unsigned char buf[16];
-
- nullpo_retr (0, sd);
-
- WBUFW (buf, 0) = 0x1d0;
- WBUFL (buf, 2) = sd->bl.id;
- WBUFW (buf, 6) = sd->spiritball;
- clif_send (buf, packet_len_table[0x1d0], &sd->bl, AREA);
- return 0;
-}
-
-/*==========================================
- *
- *------------------------------------------
- */
-int clif_combo_delay (struct block_list *bl, int wait)
-{
- unsigned char buf[32];
-
- nullpo_retr (0, bl);
-
- WBUFW (buf, 0) = 0x1d2;
- WBUFL (buf, 2) = bl->id;
- WBUFL (buf, 6) = wait;
- clif_send (buf, packet_len_table[0x1d2], bl, AREA);
-
- return 0;
-}
-
-/*==========================================
- *白刃å–ã‚Š
- *------------------------------------------
- */
-int clif_bladestop (struct block_list *src, struct block_list *dst, int boolean)
-{
- unsigned char buf[32];
-
- nullpo_retr (0, src);
- nullpo_retr (0, dst);
-
- WBUFW (buf, 0) = 0x1d1;
- WBUFL (buf, 2) = src->id;
- WBUFL (buf, 6) = dst->id;
- WBUFL (buf, 10) = boolean;
-
- clif_send (buf, packet_len_table[0x1d1], src, AREA);
-
- return 0;
-}
-
-/*==========================================
- *
- *------------------------------------------
- */
-int clif_changemapcell (int m, int x, int y, int cell_type, int type)
-{
- struct block_list bl;
- uint8_t buf[32];
-
- bl.m = m;
- bl.x = x;
- bl.y = y;
- WBUFW (buf, 0) = 0x192;
- WBUFW (buf, 2) = x;
- WBUFW (buf, 4) = y;
- WBUFW (buf, 6) = cell_type;
- memcpy (WBUFP (buf, 8), map[m].name, 16);
- if (!type)
- clif_send (buf, packet_len_table[0x192], &bl, AREA);
- else
- clif_send (buf, packet_len_table[0x192], &bl, ALL_SAMEMAP);
-
+ WFIFOW(fd, 0) = 0x139;
+ WFIFOL(fd, 2) = bl->id;
+ WFIFOW(fd, 6) = bl->x;
+ WFIFOW(fd, 8) = bl->y;
+ WFIFOW(fd, 10) = sd->bl.x;
+ WFIFOW(fd, 12) = sd->bl.y;
+ WFIFOW(fd, 14) = sd->attackrange;
+ WFIFOSET(fd, clif_parse_func_table[0x139].len);
return 0;
}
@@ -5704,764 +3560,15 @@ int clif_changemapcell (int m, int x, int y, int cell_type, int type)
* MVPエフェクト
*------------------------------------------
*/
-int clif_mvp_effect (struct map_session_data *sd)
+int clif_mvp_effect(struct map_session_data *sd)
{
unsigned char buf[16];
- nullpo_retr (0, sd);
-
- WBUFW (buf, 0) = 0x10c;
- WBUFL (buf, 2) = sd->bl.id;
- clif_send (buf, packet_len_table[0x10c], &sd->bl, AREA);
- return 0;
-}
+ nullpo_ret(sd);
-/*==========================================
- * MVPアイテム所得
- *------------------------------------------
- */
-int clif_mvp_item (struct map_session_data *sd, int nameid)
-{
- int view, fd;
-
- nullpo_retr (0, sd);
-
- fd = sd->fd;
- WFIFOW (fd, 0) = 0x10a;
- if ((view = itemdb_viewid (nameid)) > 0)
- WFIFOW (fd, 2) = view;
- else
- WFIFOW (fd, 2) = nameid;
- WFIFOSET (fd, packet_len_table[0x10a]);
- return 0;
-}
-
-/*==========================================
- * MVP経験値所得
- *------------------------------------------
- */
-int clif_mvp_exp (struct map_session_data *sd, int exp)
-{
- int fd;
-
- nullpo_retr (0, sd);
-
- fd = sd->fd;
- WFIFOW (fd, 0) = 0x10b;
- WFIFOL (fd, 2) = exp;
- WFIFOSET (fd, packet_len_table[0x10b]);
- return 0;
-}
-
-/*==========================================
- * ギルド作æˆå¯å¦é€šçŸ¥
- * Relay the result of guild creation.
- *
- * (R 0167 <flag>.B)
- *
- * flag:
- * 0 The guild was created.
- * 1 The character is already in a guild.
- * 2 The guild name is invalid/taken.
- * 3 The Emperium item is required.
- *------------------------------------------
- */
-int clif_guild_created (struct map_session_data *sd, int flag)
-{
- int fd;
-
- nullpo_retr (0, sd);
-
- fd = sd->fd;
- WFIFOW (fd, 0) = 0x167;
- WFIFOB (fd, 2) = flag;
- WFIFOSET (fd, packet_len_table[0x167]);
- return 0;
-}
-
-/*==========================================
- * ギルド所属通知
- *------------------------------------------
- */
-int clif_guild_belonginfo (struct map_session_data *sd, struct guild *g)
-{
- int ps, fd;
-
- nullpo_retr (0, sd);
- nullpo_retr (0, g);
-
- fd = sd->fd;
- ps = guild_getposition (sd, g);
-
- memset (WFIFOP (fd, 0), 0, packet_len_table[0x16c]);
- WFIFOW (fd, 0) = 0x16c;
- WFIFOL (fd, 2) = g->guild_id;
- WFIFOL (fd, 6) = g->emblem_id;
- WFIFOL (fd, 10) = g->position[ps].mode;
- memcpy (WFIFOP (fd, 19), g->name, 24);
- WFIFOSET (fd, packet_len_table[0x16c]);
- return 0;
-}
-
-/*==========================================
- * ギルドメンãƒãƒ­ã‚°ã‚¤ãƒ³é€šçŸ¥
- *------------------------------------------
- */
-int clif_guild_memberlogin_notice (struct guild *g, int idx, int flag)
-{
- unsigned char buf[64];
-
- nullpo_retr (0, g);
-
- WBUFW (buf, 0) = 0x16d;
- WBUFL (buf, 2) = g->member[idx].account_id;
- WBUFL (buf, 6) = 0;
- WBUFL (buf, 10) = flag;
- if (g->member[idx].sd == NULL)
- {
- struct map_session_data *sd = guild_getavailablesd (g);
- if (sd != NULL)
- clif_send (buf, packet_len_table[0x16d], &sd->bl, GUILD);
- }
- else
- clif_send (buf, packet_len_table[0x16d], &g->member[idx].sd->bl,
- GUILD_WOS);
- return 0;
-}
-
-/*==========================================
- * ギルドマスター通知(14dã¸ã®å¿œç­”)
- *------------------------------------------
- */
-static
-int clif_guild_masterormember (struct map_session_data *sd)
-{
- int type = 0x57, fd;
- struct guild *g;
-
- nullpo_retr (0, sd);
-
- fd = sd->fd;
- g = guild_search (sd->status.guild_id);
- if (g != NULL && strcmp (g->master, sd->status.name) == 0)
- type = 0xd7;
- WFIFOW (fd, 0) = 0x14e;
- WFIFOL (fd, 2) = type;
- WFIFOSET (fd, packet_len_table[0x14e]);
- return 0;
-}
-
-/*==========================================
- * Basic Info (Territories [Valaris])
- *------------------------------------------
- */
-int clif_guild_basicinfo (struct map_session_data *sd)
-{
- int fd, i, t = 0;
- struct guild *g;
- struct guild_castle *gc = NULL;
-
- nullpo_retr (0, sd);
-
- fd = sd->fd;
- g = guild_search (sd->status.guild_id);
- if (g == NULL)
- return 0;
-
- WFIFOW (fd, 0) = 0x1b6; //0x150;
- WFIFOL (fd, 2) = g->guild_id;
- WFIFOL (fd, 6) = g->guild_lv;
- WFIFOL (fd, 10) = g->connect_member;
- WFIFOL (fd, 14) = g->max_member;
- WFIFOL (fd, 18) = g->average_lv;
- WFIFOL (fd, 22) = g->exp;
- WFIFOL (fd, 26) = g->next_exp;
- WFIFOL (fd, 30) = 0; // 上ç´
- WFIFOL (fd, 34) = 0; // VW(性格ã®æ‚ªã•ï¼Ÿï¼šæ€§å‘グラフ左å³ï¼‰
- WFIFOL (fd, 38) = 0; // RF(正義ã®åº¦åˆã„?:性å‘グラフ上下)
- WFIFOL (fd, 42) = 0; // 人数?
- memcpy (WFIFOP (fd, 46), g->name, 24);
- memcpy (WFIFOP (fd, 70), g->master, 24);
-
- for (i = 0; i < MAX_GUILDCASTLE; i++)
- {
- gc = guild_castle_search (i);
- if (!gc)
- continue;
- if (g->guild_id == gc->guild_id)
- t++;
- }
-
- if (t == 1)
- memcpy (WFIFOP (fd, 94), "One Castle", 20);
- else if (t == 2)
- memcpy (WFIFOP (fd, 94), "Two Castles", 20);
- else if (t == 3)
- memcpy (WFIFOP (fd, 94), "Three Castles", 20);
- else if (t == 4)
- memcpy (WFIFOP (fd, 94), "Four Castles", 20);
- else if (t == 5)
- memcpy (WFIFOP (fd, 94), "Five Castles", 20);
- else if (t == 6)
- memcpy (WFIFOP (fd, 94), "Six Castles", 20);
- else if (t == 7)
- memcpy (WFIFOP (fd, 94), "Seven Castles", 20);
- else if (t == 8)
- memcpy (WFIFOP (fd, 94), "Eight Castles", 20);
- else if (t == 9)
- memcpy (WFIFOP (fd, 94), "Nine Castles", 20);
- else if (t == 10)
- memcpy (WFIFOP (fd, 94), "Ten Castles", 20);
- else if (t == 11)
- memcpy (WFIFOP (fd, 94), "Eleven Castles", 20);
- else if (t == 12)
- memcpy (WFIFOP (fd, 94), "Twelve Castles", 20);
- else if (t == 13)
- memcpy (WFIFOP (fd, 94), "Thirteen Castles", 20);
- else if (t == 14)
- memcpy (WFIFOP (fd, 94), "Fourteen Castles", 20);
- else if (t == 15)
- memcpy (WFIFOP (fd, 94), "Fifteen Castles", 20);
- else if (t == 16)
- memcpy (WFIFOP (fd, 94), "Sixteen Castles", 20);
- else if (t == 17)
- memcpy (WFIFOP (fd, 94), "Seventeen Castles", 20);
- else if (t == 18)
- memcpy (WFIFOP (fd, 94), "Eighteen Castles", 20);
- else if (t == 19)
- memcpy (WFIFOP (fd, 94), "Nineteen Castles", 20);
- else if (t == 20)
- memcpy (WFIFOP (fd, 94), "Twenty Castles", 20);
- else if (t == 21)
- memcpy (WFIFOP (fd, 94), "Twenty One Castles", 20);
- else if (t == 22)
- memcpy (WFIFOP (fd, 94), "Twenty Two Castles", 20);
- else if (t == 23)
- memcpy (WFIFOP (fd, 94), "Twenty Three Castles", 20);
- else if (t == 24)
- memcpy (WFIFOP (fd, 94), "Twenty Four Castles", 20);
- else if (t == MAX_GUILDCASTLE)
- memcpy (WFIFOP (fd, 94), "Total Domination", 20);
- else
- memcpy (WFIFOP (fd, 94), "None Taken", 20);
-
- WFIFOSET (fd, packet_len_table[WFIFOW (fd, 0)]);
- clif_guild_emblem (sd, g); // Guild emblem vanish fix [Valaris]
- return 0;
-}
-
-/*==========================================
- * ギルドåŒç›Ÿ/敵対情報
- *------------------------------------------
- */
-int clif_guild_allianceinfo (struct map_session_data *sd)
-{
- int fd, i, c;
- struct guild *g;
-
- nullpo_retr (0, sd);
-
- fd = sd->fd;
- g = guild_search (sd->status.guild_id);
- if (g == NULL)
- return 0;
- WFIFOW (fd, 0) = 0x14c;
- for (i = c = 0; i < MAX_GUILDALLIANCE; i++)
- {
- GuildAlliance *a = &g->alliance[i];
- if (a->guild_id > 0)
- {
- WFIFOL (fd, c * 32 + 4) = a->opposition;
- WFIFOL (fd, c * 32 + 8) = a->guild_id;
- memcpy (WFIFOP (fd, c * 32 + 12), a->name, 24);
- c++;
- }
- }
- WFIFOW (fd, 2) = c * 32 + 4;
- WFIFOSET (fd, WFIFOW (fd, 2));
- return 0;
-}
-
-/*==========================================
- * ギルドメンãƒãƒ¼ãƒªã‚¹ãƒˆ
- *------------------------------------------
- */
-int clif_guild_memberlist (struct map_session_data *sd)
-{
- int fd;
- int i, c;
- struct guild *g;
-
- nullpo_retr (0, sd);
-
- fd = sd->fd;
- g = guild_search (sd->status.guild_id);
- if (g == NULL)
- return 0;
-
- WFIFOW (fd, 0) = 0x154;
- for (i = 0, c = 0; i < g->max_member; i++)
- {
- struct guild_member *m = &g->member[i];
- if (m->account_id == 0)
- continue;
- WFIFOL (fd, c * 104 + 4) = m->account_id;
- WFIFOL (fd, c * 104 + 8) = 0;
- WFIFOW (fd, c * 104 + 12) = m->hair;
- WFIFOW (fd, c * 104 + 14) = m->hair_color;
- WFIFOW (fd, c * 104 + 16) = m->gender;
- WFIFOW (fd, c * 104 + 18) = m->pc_class;
- WFIFOW (fd, c * 104 + 20) = m->lv;
- WFIFOL (fd, c * 104 + 22) = m->exp;
- WFIFOL (fd, c * 104 + 26) = m->online;
- WFIFOL (fd, c * 104 + 30) = m->position;
- memset (WFIFOP (fd, c * 104 + 34), 0, 50); // メモ?
- memcpy (WFIFOP (fd, c * 104 + 84), m->name, 24);
- c++;
- }
- WFIFOW (fd, 2) = c * 104 + 4;
- WFIFOSET (fd, WFIFOW (fd, 2));
- return 0;
-}
-
-/*==========================================
- * ギルド役è·åリスト
- *------------------------------------------
- */
-static
-int clif_guild_positionnamelist (struct map_session_data *sd)
-{
- int i, fd;
- struct guild *g;
-
- nullpo_retr (0, sd);
-
- fd = sd->fd;
- g = guild_search (sd->status.guild_id);
- if (g == NULL)
- return 0;
- WFIFOW (fd, 0) = 0x166;
- for (i = 0; i < MAX_GUILDPOSITION; i++)
- {
- WFIFOL (fd, i * 28 + 4) = i;
- memcpy (WFIFOP (fd, i * 28 + 8), g->position[i].name, 24);
- }
- WFIFOW (fd, 2) = i * 28 + 4;
- WFIFOSET (fd, WFIFOW (fd, 2));
- return 0;
-}
-
-/*==========================================
- * ギルド役è·æƒ…報リスト
- *------------------------------------------
- */
-static
-int clif_guild_positioninfolist (struct map_session_data *sd)
-{
- int i, fd;
- struct guild *g;
-
- nullpo_retr (0, sd);
-
- fd = sd->fd;
- g = guild_search (sd->status.guild_id);
- if (g == NULL)
- return 0;
- WFIFOW (fd, 0) = 0x160;
- for (i = 0; i < MAX_GUILDPOSITION; i++)
- {
- struct guild_position *p = &g->position[i];
- WFIFOL (fd, i * 16 + 4) = i;
- WFIFOL (fd, i * 16 + 8) = p->mode;
- WFIFOL (fd, i * 16 + 12) = i;
- WFIFOL (fd, i * 16 + 16) = p->exp_mode;
- }
- WFIFOW (fd, 2) = i * 16 + 4;
- WFIFOSET (fd, WFIFOW (fd, 2));
- return 0;
-}
-
-/*==========================================
- * ギルド役è·å¤‰æ›´é€šçŸ¥
- *------------------------------------------
- */
-int clif_guild_positionchanged (struct guild *g, int idx)
-{
- struct map_session_data *sd;
- unsigned char buf[128];
-
- nullpo_retr (0, g);
-
- WBUFW (buf, 0) = 0x174;
- WBUFW (buf, 2) = 44;
- WBUFL (buf, 4) = idx;
- WBUFL (buf, 8) = g->position[idx].mode;
- WBUFL (buf, 12) = idx;
- WBUFL (buf, 16) = g->position[idx].exp_mode;
- memcpy (WBUFP (buf, 20), g->position[idx].name, 24);
- if ((sd = guild_getavailablesd (g)) != NULL)
- clif_send (buf, WBUFW (buf, 2), &sd->bl, GUILD);
- return 0;
-}
-
-/*==========================================
- * ギルドメンãƒå¤‰æ›´é€šçŸ¥
- *------------------------------------------
- */
-int clif_guild_memberpositionchanged (struct guild *g, int idx)
-{
- struct map_session_data *sd;
- unsigned char buf[64];
-
- nullpo_retr (0, g);
-
- WBUFW (buf, 0) = 0x156;
- WBUFW (buf, 2) = 16;
- WBUFL (buf, 4) = g->member[idx].account_id;
- WBUFL (buf, 8) = 0;
- WBUFL (buf, 12) = g->member[idx].position;
- if ((sd = guild_getavailablesd (g)) != NULL)
- clif_send (buf, WBUFW (buf, 2), &sd->bl, GUILD);
- return 0;
-}
-
-/*==========================================
- * ギルドエンブレムé€ä¿¡
- *------------------------------------------
- */
-int clif_guild_emblem (struct map_session_data *sd, struct guild *g)
-{
- int fd;
-
- nullpo_retr (0, sd);
- nullpo_retr (0, g);
-
- fd = sd->fd;
-
- if (g->emblem_len <= 0)
- return 0;
- WFIFOW (fd, 0) = 0x152;
- WFIFOW (fd, 2) = g->emblem_len + 12;
- WFIFOL (fd, 4) = g->guild_id;
- WFIFOL (fd, 8) = g->emblem_id;
- memcpy (WFIFOP (fd, 12), g->emblem_data, g->emblem_len);
- WFIFOSET (fd, WFIFOW (fd, 2));
- return 0;
-}
-
-/*==========================================
- * ギルドスキルé€ä¿¡
- *------------------------------------------
- */
-int clif_guild_skillinfo (struct map_session_data *sd)
-{
- int fd;
- int i, id, c;
- struct guild *g;
-
- nullpo_retr (0, sd);
-
- fd = sd->fd;
- g = guild_search (sd->status.guild_id);
- if (g == NULL)
- return 0;
- WFIFOW (fd, 0) = 0x0162;
- WFIFOW (fd, 4) = g->skill_point;
- for (i = c = 0; i < MAX_GUILDSKILL; i++)
- {
- if (g->skill[i].id > 0)
- {
- WFIFOW (fd, c * 37 + 6) = id = g->skill[i].id;
- WFIFOW (fd, c * 37 + 8) = guild_skill_get_inf (id);
- WFIFOW (fd, c * 37 + 10) = 0;
- WFIFOW (fd, c * 37 + 12) = g->skill[i].lv;
- WFIFOW (fd, c * 37 + 14) =
- guild_skill_get_sp (id, g->skill[i].lv);
- WFIFOW (fd, c * 37 + 16) = guild_skill_get_range (id);
- memset (WFIFOP (fd, c * 37 + 18), 0, 24);
- WFIFOB (fd, c * 37 + 42) = //up;
- (g->skill[i].lv < guild_skill_get_max (id)) ? 1 : 0;
- c++;
- }
- }
- WFIFOW (fd, 2) = c * 37 + 6;
- WFIFOSET (fd, WFIFOW (fd, 2));
- return 0;
-}
-
-/*==========================================
- * ギルド告知é€ä¿¡
- *------------------------------------------
- */
-int clif_guild_notice (struct map_session_data *sd, struct guild *g)
-{
- int fd;
-
- nullpo_retr (0, sd);
- nullpo_retr (0, g);
-
- fd = sd->fd;
- if (*g->mes1 == 0 && *g->mes2 == 0)
- return 0;
- WFIFOW (fd, 0) = 0x16f;
- memcpy (WFIFOP (fd, 2), g->mes1, 60);
- memcpy (WFIFOP (fd, 62), g->mes2, 120);
- WFIFOSET (fd, packet_len_table[0x16f]);
- return 0;
-}
-
-/*==========================================
- * ギルドメンãƒå‹§èª˜
- *------------------------------------------
- */
-int clif_guild_invite (struct map_session_data *sd, struct guild *g)
-{
- int fd;
-
- nullpo_retr (0, sd);
- nullpo_retr (0, g);
-
- fd = sd->fd;
- WFIFOW (fd, 0) = 0x16a;
- WFIFOL (fd, 2) = g->guild_id;
- memcpy (WFIFOP (fd, 6), g->name, 24);
- WFIFOSET (fd, packet_len_table[0x16a]);
- return 0;
-}
-
-/*==========================================
- * ギルドメンãƒå‹§èª˜çµæžœ
- *------------------------------------------
- */
-int clif_guild_inviteack (struct map_session_data *sd, int flag)
-{
- int fd;
-
- nullpo_retr (0, sd);
-
- fd = sd->fd;
- WFIFOW (fd, 0) = 0x169;
- WFIFOB (fd, 2) = flag;
- WFIFOSET (fd, packet_len_table[0x169]);
- return 0;
-}
-
-/*==========================================
- * ギルドメンãƒè„±é€€é€šçŸ¥
- *------------------------------------------
- */
-int clif_guild_leave (struct map_session_data *sd, const char *name,
- const char *mes)
-{
- unsigned char buf[128];
-
- nullpo_retr (0, sd);
-
- WBUFW (buf, 0) = 0x15a;
- memcpy (WBUFP (buf, 2), name, 24);
- memcpy (WBUFP (buf, 26), mes, 40);
- clif_send (buf, packet_len_table[0x15a], &sd->bl, GUILD);
- return 0;
-}
-
-/*==========================================
- * ギルドメンãƒè¿½æ”¾é€šçŸ¥
- *------------------------------------------
- */
-int clif_guild_explusion (struct map_session_data *sd, const char *name,
- const char *mes, int account_id)
-{
- unsigned char buf[128];
-
- nullpo_retr (0, sd);
-
- WBUFW (buf, 0) = 0x15c;
- memcpy (WBUFP (buf, 2), name, 24);
- memcpy (WBUFP (buf, 26), mes, 40);
- memcpy (WBUFP (buf, 66), "dummy", 24);
- clif_send (buf, packet_len_table[0x15c], &sd->bl, GUILD);
- return 0;
-}
-
-/*==========================================
- * ギルド追放メンãƒãƒªã‚¹ãƒˆ
- *------------------------------------------
- */
-static
-int clif_guild_explusionlist (struct map_session_data *sd)
-{
- int fd;
- int i, c;
- struct guild *g;
-
- nullpo_retr (0, sd);
-
- fd = sd->fd;
- g = guild_search (sd->status.guild_id);
- if (g == NULL)
- return 0;
- WFIFOW (fd, 0) = 0x163;
- for (i = c = 0; i < MAX_GUILDEXPLUSION; i++)
- {
- GuildExpulsion *e = &g->explusion[i];
- if (e->account_id > 0)
- {
- memcpy (WFIFOP (fd, c * 88 + 4), e->name, 24);
- memcpy (WFIFOP (fd, c * 88 + 28), e->acc, 24);
- memcpy (WFIFOP (fd, c * 88 + 52), e->mes, 44);
- c++;
- }
- }
- WFIFOW (fd, 2) = c * 88 + 4;
- WFIFOSET (fd, WFIFOW (fd, 2));
- return 0;
-}
-
-/*==========================================
- * ギルド会話
- *------------------------------------------
- */
-int clif_guild_message (struct guild *g, int account_id, const char *mes,
- int len)
-{
- struct map_session_data *sd;
- unsigned char lbuf[255];
- unsigned char *buf = lbuf;
- if (len + 32 >= sizeof (lbuf))
- buf = (unsigned char *)malloc (len + 32);
- WBUFW (buf, 0) = 0x17f;
- WBUFW (buf, 2) = len + 4;
- memcpy (WBUFP (buf, 4), mes, len);
-
- if ((sd = guild_getavailablesd (g)) != NULL)
- clif_send (buf, WBUFW (buf, 2), &sd->bl, GUILD);
- if (buf != lbuf)
- free (buf);
- return 0;
-}
-
-/*==========================================
- * ギルドスキル割り振り通知
- *------------------------------------------
- */
-int clif_guild_skillup (struct map_session_data *sd, int skill_num, int lv)
-{
- int fd;
-
- nullpo_retr (0, sd);
-
- fd = sd->fd;
- WFIFOW (fd, 0) = 0x10e;
- WFIFOW (fd, 2) = skill_num;
- WFIFOW (fd, 4) = lv;
- WFIFOW (fd, 6) = guild_skill_get_sp (skill_num, lv);
- WFIFOW (fd, 8) = guild_skill_get_range (skill_num);
- WFIFOB (fd, 10) = 1;
- WFIFOSET (fd, 11);
- return 0;
-}
-
-/*==========================================
- * ギルドåŒç›Ÿè¦è«‹
- *------------------------------------------
- */
-int clif_guild_reqalliance (struct map_session_data *sd, int account_id,
- const char *name)
-{
- int fd;
-
- nullpo_retr (0, sd);
-
- fd = sd->fd;
- WFIFOW (fd, 0) = 0x171;
- WFIFOL (fd, 2) = account_id;
- memcpy (WFIFOP (fd, 6), name, 24);
- WFIFOSET (fd, packet_len_table[0x171]);
- return 0;
-}
-
-/*==========================================
- * ギルドåŒç›Ÿçµæžœ
- *------------------------------------------
- */
-int clif_guild_allianceack (struct map_session_data *sd, int flag)
-{
- int fd;
-
- nullpo_retr (0, sd);
-
- fd = sd->fd;
- WFIFOW (fd, 0) = 0x173;
- WFIFOL (fd, 2) = flag;
- WFIFOSET (fd, packet_len_table[0x173]);
- return 0;
-}
-
-/*==========================================
- * ギルド関係解消通知
- *------------------------------------------
- */
-int clif_guild_delalliance (struct map_session_data *sd, int guild_id,
- int flag)
-{
- int fd;
-
- nullpo_retr (0, sd);
-
- fd = sd->fd;
- WFIFOW (fd, 0) = 0x184;
- WFIFOL (fd, 2) = guild_id;
- WFIFOL (fd, 6) = flag;
- WFIFOSET (fd, packet_len_table[0x184]);
- return 0;
-}
-
-/*==========================================
- * ギルド敵対çµæžœ
- *------------------------------------------
- */
-int clif_guild_oppositionack (struct map_session_data *sd, int flag)
-{
- int fd;
-
- nullpo_retr (0, sd);
-
- fd = sd->fd;
- WFIFOW (fd, 0) = 0x181;
- WFIFOB (fd, 2) = flag;
- WFIFOSET (fd, packet_len_table[0x181]);
- return 0;
-}
-
-/*==========================================
- * ギルド関係追加
- *------------------------------------------
- */
-/*int clif_guild_allianceadded(struct guild *g,int idx)
-{
- unsigned char buf[64];
- WBUFW(fd,0)=0x185;
- WBUFL(fd,2)=g->alliance[idx].opposition;
- WBUFL(fd,6)=g->alliance[idx].guild_id;
- memcpy(WBUFP(fd,10),g->alliance[idx].name,24);
- clif_send(buf,packet_len_table[0x185],guild_getavailablesd(g),GUILD);
- return 0;
-}*/
-
-/*==========================================
- * ギルド解散通知
- *------------------------------------------
- */
-int clif_guild_broken (struct map_session_data *sd, int flag)
-{
- int fd;
-
- nullpo_retr (0, sd);
-
- fd = sd->fd;
- WFIFOW (fd, 0) = 0x15e;
- WFIFOL (fd, 2) = flag;
- WFIFOSET (fd, packet_len_table[0x15e]);
+ WBUFW(buf, 0) = 0x10c;
+ WBUFL(buf, 2) = sd->bl.id;
+ clif_send(buf, clif_parse_func_table[0x10c].len, &sd->bl, SendWho::AREA);
return 0;
}
@@ -6469,261 +3576,120 @@ int clif_guild_broken (struct map_session_data *sd, int flag)
* エモーション
*------------------------------------------
*/
-void clif_emotion (struct block_list *bl, int type)
+void clif_emotion(struct block_list *bl, int type)
{
unsigned char buf[8];
- nullpo_retv (bl);
+ nullpo_retv(bl);
- WBUFW (buf, 0) = 0xc0;
- WBUFL (buf, 2) = bl->id;
- WBUFB (buf, 6) = type;
- clif_send (buf, packet_len_table[0xc0], bl, AREA);
+ WBUFW(buf, 0) = 0xc0;
+ WBUFL(buf, 2) = bl->id;
+ WBUFB(buf, 6) = type;
+ clif_send(buf, clif_parse_func_table[0xc0].len, bl, SendWho::AREA);
}
-static void clif_emotion_towards (struct block_list *bl,
+static
+void clif_emotion_towards(struct block_list *bl,
struct block_list *target, int type)
{
unsigned char buf[8];
- int len = packet_len_table[0xc0];
+ int len = clif_parse_func_table[0xc0].len;
struct map_session_data *sd = (struct map_session_data *) target;
- nullpo_retv (bl);
- nullpo_retv (target);
+ nullpo_retv(bl);
+ nullpo_retv(target);
- if (target->type != BL_PC)
+ if (target->type != BL::PC)
return;
- WBUFW (buf, 0) = 0xc0;
- WBUFL (buf, 2) = bl->id;
- WBUFB (buf, 6) = type;
-
- memcpy (WFIFOP (sd->fd, 0), buf, len);
- WFIFOSET (sd->fd, len);
-}
-
-/*==========================================
- * トーキーボックス
- *------------------------------------------
- */
-void clif_talkiebox (struct block_list *bl, const char *talkie)
-{
- unsigned char buf[86];
-
- nullpo_retv (bl);
+ WBUFW(buf, 0) = 0xc0;
+ WBUFL(buf, 2) = bl->id;
+ WBUFB(buf, 6) = type;
- WBUFW (buf, 0) = 0x191;
- WBUFL (buf, 2) = bl->id;
- memcpy (WBUFP (buf, 6), talkie, 80);
- clif_send (buf, packet_len_table[0x191], bl, AREA);
+ memcpy(WFIFOP(sd->fd, 0), buf, len);
+ WFIFOSET(sd->fd, len);
}
/*==========================================
- * çµå©šã‚¨ãƒ•ã‚§ã‚¯ãƒˆ
- *------------------------------------------
- */
-void clif_wedding_effect (struct block_list *bl)
-{
- unsigned char buf[6];
-
- nullpo_retv (bl);
-
- WBUFW (buf, 0) = 0x1ea;
- WBUFL (buf, 2) = bl->id;
- clif_send (buf, packet_len_table[0x1ea], bl, AREA);
-}
-
-/*==========================================
- * ã‚ãªãŸã«é€¢ã„ãŸã„使用時åå‰å«ã³
- *------------------------------------------
-
-void clif_callpartner(struct map_session_data *sd)
-{
- unsigned char buf[26];
- char *p;
-
- nullpo_retv(sd);
-
- if(sd->status.partner_id){
- WBUFW(buf,0)=0x1e6;
- p = map_charid2nick(sd->status.partner_id);
- if(p){
- memcpy(WBUFP(buf,2),p,24);
- }else{
- map_reqchariddb(sd,sd->status.partner_id);
- chrif_searchcharid(sd->status.partner_id);
- WBUFB(buf,2) = 0;
- }
- clif_send(buf,packet_len_table[0x1e6]&sd->bl,AREA);
- }
- return;
-}
-*/
-/*==========================================
* 座る
*------------------------------------------
*/
-void clif_sitting (int fd, struct map_session_data *sd)
+void clif_sitting(int, struct map_session_data *sd)
{
unsigned char buf[64];
- nullpo_retv (sd);
-
- WBUFW (buf, 0) = 0x8a;
- WBUFL (buf, 2) = sd->bl.id;
- WBUFB (buf, 26) = 2;
- clif_send (buf, packet_len_table[0x8a], &sd->bl, AREA);
-}
-
-/*==========================================
- *
- *------------------------------------------
- */
-int clif_disp_onlyself (struct map_session_data *sd, const char *mes, int len)
-{
- unsigned char lbuf[255];
- unsigned char *buf =
- (len + 32 >= sizeof (lbuf)) ? (unsigned char *)malloc (len + 32) : lbuf;
-
- nullpo_retr (0, sd);
-
- WBUFW (buf, 0) = 0x17f;
- WBUFW (buf, 2) = len + 8;
- memcpy (WBUFP (buf, 4), mes, len + 4);
-
- clif_send (buf, WBUFW (buf, 2), &sd->bl, SELF);
+ nullpo_retv(sd);
- if (buf != lbuf)
- free (buf);
-
- return 0;
+ WBUFW(buf, 0) = 0x8a;
+ WBUFL(buf, 2) = sd->bl.id;
+ WBUFB(buf, 26) = 2;
+ clif_send(buf, clif_parse_func_table[0x8a].len, &sd->bl, SendWho::AREA);
}
/*==========================================
*
*------------------------------------------
*/
-
-int clif_GM_kickack (struct map_session_data *sd, int id)
+static
+int clif_GM_kickack(struct map_session_data *sd, int id)
{
- int fd;
+ int fd;
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
fd = sd->fd;
- WFIFOW (fd, 0) = 0xcd;
- WFIFOL (fd, 2) = id;
- WFIFOSET (fd, packet_len_table[0xcd]);
+ WFIFOW(fd, 0) = 0xcd;
+ WFIFOL(fd, 2) = id;
+ WFIFOSET(fd, clif_parse_func_table[0xcd].len);
return 0;
}
-void clif_parse_QuitGame (int fd, struct map_session_data *sd);
+static
+void clif_parse_QuitGame(int fd, struct map_session_data *sd);
-int clif_GM_kick (struct map_session_data *sd, struct map_session_data *tsd,
+int clif_GM_kick(struct map_session_data *sd, struct map_session_data *tsd,
int type)
{
- nullpo_retr (0, tsd);
+ nullpo_ret(tsd);
if (type)
- clif_GM_kickack (sd, tsd->status.account_id);
- tsd->opt1 = tsd->opt2 = 0;
- clif_parse_QuitGame (tsd->fd, tsd);
-
- return 0;
-}
-
-/*==========================================
- * Wisæ‹’å¦è¨±å¯å¿œç­”
- *------------------------------------------
- */
-static
-int clif_wisexin (struct map_session_data *sd, int type, int flag)
-{
- int fd;
-
- nullpo_retr (0, sd);
-
- fd = sd->fd;
- WFIFOW (fd, 0) = 0xd1;
- WFIFOB (fd, 2) = type;
- WFIFOB (fd, 3) = flag;
- WFIFOSET (fd, packet_len_table[0xd1]);
-
- return 0;
-}
-
-/*==========================================
- * Wis全拒å¦è¨±å¯å¿œç­”
- *------------------------------------------
- */
-static
-int clif_wisall (struct map_session_data *sd, int type, int flag)
-{
- int fd;
-
- nullpo_retr (0, sd);
-
- fd = sd->fd;
- WFIFOW (fd, 0) = 0xd2;
- WFIFOB (fd, 2) = type;
- WFIFOB (fd, 3) = flag;
- WFIFOSET (fd, packet_len_table[0xd2]);
+ clif_GM_kickack(sd, tsd->status.account_id);
+ tsd->opt1 = Opt1::ZERO;
+ tsd->opt2 = Opt2::ZERO;
+ clif_parse_QuitGame(tsd->fd, tsd);
return 0;
}
-/*==========================================
- * サウンドエフェクト
- *------------------------------------------
- */
-void clif_soundeffect (struct map_session_data *sd, struct block_list *bl,
- const char *name, int type)
-{
- int fd;
-
- nullpo_retv (sd);
- nullpo_retv (bl);
-
- fd = sd->fd;
- WFIFOW (fd, 0) = 0x1d3;
- memcpy (WFIFOP (fd, 2), name, 24);
- WFIFOB (fd, 26) = type;
- WFIFOL (fd, 27) = 0;
- WFIFOL (fd, 31) = bl->id;
- WFIFOSET (fd, packet_len_table[0x1d3]);
-
- return;
-}
-
// displaying special effects (npcs, weather, etc) [Valaris]
-int clif_specialeffect (struct block_list *bl, int type, int flag)
+int clif_specialeffect(struct block_list *bl, int type, int flag)
{
unsigned char buf[24];
- nullpo_retr (0, bl);
+ nullpo_ret(bl);
- memset (buf, 0, packet_len_table[0x19b]);
+ memset(buf, 0, clif_parse_func_table[0x19b].len);
- WBUFW (buf, 0) = 0x19b;
- WBUFL (buf, 2) = bl->id;
- WBUFL (buf, 6) = type;
+ WBUFW(buf, 0) = 0x19b;
+ WBUFL(buf, 2) = bl->id;
+ WBUFL(buf, 6) = type;
if (flag == 2)
{
struct map_session_data *sd = NULL;
- int i;
+ int i;
for (i = 0; i < fd_max; i++)
{
if (session[i] && (sd = (struct map_session_data *)session[i]->session_data) != NULL
&& sd->state.auth && sd->bl.m == bl->m)
- clif_specialeffect (&sd->bl, type, 1);
+ clif_specialeffect(&sd->bl, type, 1);
}
}
else if (flag == 1)
- clif_send (buf, packet_len_table[0x19b], bl, SELF);
+ clif_send(buf, clif_parse_func_table[0x19b].len, bl, SendWho::SELF);
else if (!flag)
- clif_send (buf, packet_len_table[0x19b], bl, AREA);
+ clif_send(buf, clif_parse_func_table[0x19b].len, bl, SendWho::AREA);
return 0;
@@ -6738,49 +3704,49 @@ int clif_specialeffect (struct block_list *bl, int type, int flag)
*------------------------------------------
*/
static
-void clif_parse_WantToConnection (int fd, struct map_session_data *sd)
+void clif_parse_WantToConnection(int fd, struct map_session_data *sd)
{
struct map_session_data *old_sd;
- int account_id; // account_id in the packet
+ int account_id; // account_id in the packet
if (sd)
{
if (battle_config.error_log)
- printf ("clif_parse_WantToConnection : invalid request?\n");
+ PRINTF("clif_parse_WantToConnection : invalid request?\n");
return;
}
- if (RFIFOW (fd, 0) == 0x72)
+ if (RFIFOW(fd, 0) == 0x72)
{
- account_id = RFIFOL (fd, 2);
+ account_id = RFIFOL(fd, 2);
}
else
return; // Not the auth packet
- WFIFOL (fd, 0) = account_id;
- WFIFOSET (fd, 4);
+ WFIFOL(fd, 0) = account_id;
+ WFIFOSET(fd, 4);
// if same account already connected, we disconnect the 2 sessions
- if ((old_sd = map_id2sd (account_id)) != NULL)
+ if ((old_sd = map_id2sd(account_id)) != NULL)
{
- clif_authfail_fd (fd, 2); // same id
- clif_authfail_fd (old_sd->fd, 2); // same id
- printf
- ("clif_parse_WantToConnection: Double connection for account %d (sessions: #%d (new) and #%d (old)).\n",
+ clif_authfail_fd(fd, 2); // same id
+ clif_authfail_fd(old_sd->fd, 2); // same id
+ PRINTF("clif_parse_WantToConnection: Double connection for account %d (sessions: #%d (new) and #%d (old)).\n",
account_id, fd, old_sd->fd);
}
else
{
- CREATE (sd, struct map_session_data, 1);
+ CREATE(sd, struct map_session_data, 1);
session[fd]->session_data = sd;
sd->fd = fd;
- pc_setnewpc (sd, account_id, RFIFOL (fd, 6), RFIFOL (fd, 10),
- RFIFOL (fd, 14), RFIFOB (fd, 18), fd);
+ pc_setnewpc(sd, account_id, RFIFOL(fd, 6), RFIFOL(fd, 10),
+ tick_t(static_cast<interval_t>(RFIFOL(fd, 14))),
+ RFIFOB(fd, 18));
- map_addiddb (&sd->bl);
+ map_addiddb(&sd->bl);
- chrif_authreq (sd);
+ chrif_authreq(sd);
}
return;
@@ -6792,11 +3758,11 @@ void clif_parse_WantToConnection (int fd, struct map_session_data *sd)
*------------------------------------------
*/
static
-void clif_parse_LoadEndAck (int fd, struct map_session_data *sd)
+void clif_parse_LoadEndAck(int, struct map_session_data *sd)
{
// struct item_data* item;
- int i;
- nullpo_retv (sd);
+ int i;
+ nullpo_retv(sd);
if (sd->bl.prev != NULL)
return;
@@ -6804,144 +3770,88 @@ void clif_parse_LoadEndAck (int fd, struct map_session_data *sd)
// 接続ok時
//clif_authok();
if (sd->npc_id)
- npc_event_dequeue (sd);
- clif_skillinfoblock (sd);
- pc_checkitem (sd);
+ npc_event_dequeue(sd);
+ clif_skillinfoblock(sd);
+ pc_checkitem(sd);
//guild_info();
// loadendack時
// next exp
- clif_updatestatus (sd, SP_NEXTBASEEXP);
- clif_updatestatus (sd, SP_NEXTJOBEXP);
+ clif_updatestatus(sd, SP::NEXTBASEEXP);
+ clif_updatestatus(sd, SP::NEXTJOBEXP);
// skill point
- clif_updatestatus (sd, SP_SKILLPOINT);
+ clif_updatestatus(sd, SP::SKILLPOINT);
// item
- clif_itemlist (sd);
- clif_equiplist (sd);
- // cart
- if (pc_iscarton (sd))
- {
- clif_cart_itemlist (sd);
- clif_cart_equiplist (sd);
- clif_updatestatus (sd, SP_CARTINFO);
- }
+ clif_itemlist(sd);
+ clif_equiplist(sd);
// param all
- clif_initialstatus (sd);
+ clif_initialstatus(sd);
// party
- party_send_movemap (sd);
- // guild
- guild_send_memberinfoshort (sd, 1);
+ party_send_movemap(sd);
// 119
// 78
if (battle_config.pc_invincible_time > 0)
{
- if (map[sd->bl.m].flag.gvg)
- pc_setinvincibletimer (sd, battle_config.pc_invincible_time << 1);
- else
- pc_setinvincibletimer (sd, battle_config.pc_invincible_time);
+ pc_setinvincibletimer(sd, static_cast<interval_t>(battle_config.pc_invincible_time));
}
- map_addblock (&sd->bl); // ブロック登録
- clif_spawnpc (sd); // spawn
+ map_addblock(&sd->bl); // ブロック登録
+ clif_spawnpc(sd); // spawn
// weight max , now
- clif_updatestatus (sd, SP_MAXWEIGHT);
- clif_updatestatus (sd, SP_WEIGHT);
+ clif_updatestatus(sd, SP::MAXWEIGHT);
+ clif_updatestatus(sd, SP::WEIGHT);
// pvp
- if (sd->pvp_timer != -1 && !battle_config.pk_mode)
- delete_timer (sd->pvp_timer, pc_calc_pvprank_timer);
+ if (!battle_config.pk_mode)
+ sd->pvp_timer.cancel();
+
if (map[sd->bl.m].flag.pvp)
{
if (!battle_config.pk_mode)
- { // remove pvp stuff for pk_mode [Valaris]
- sd->pvp_timer =
- add_timer (gettick () + 200, pc_calc_pvprank_timer, sd->bl.id,
- 0);
+ {
+ // remove pvp stuff for pk_mode [Valaris]
+ sd->pvp_timer = Timer(gettick() + std::chrono::milliseconds(200),
+ std::bind(pc_calc_pvprank_timer, ph::_1, ph::_2,
+ sd->bl.id));
sd->pvp_rank = 0;
sd->pvp_lastusers = 0;
sd->pvp_point = 5;
}
- clif_set0199 (sd->fd, 1);
}
else
{
- sd->pvp_timer = -1;
- }
- if (map[sd->bl.m].flag.gvg)
- {
- clif_set0199 (sd->fd, 3);
+ // sd->pvp_timer = nullptr;
}
- if (sd->state.connect_new)
- {
- sd->state.connect_new = 0;
- if (sd->status.pc_class != sd->view_class)
- clif_changelook (&sd->bl, LOOK_BASE, sd->view_class);
-
-/* Stop players from spawning inside castles [Valaris] */
-
- {
- struct guild_castle *gc = guild_mapname2gc (map[sd->bl.m].name);
- if (gc)
- pc_setpos (sd, sd->status.save_point.map,
- sd->status.save_point.x, sd->status.save_point.y,
- 2);
- }
-
-/* End Addition [Valaris] */
-
- }
+ sd->state.connect_new = 0;
// view equipment item
- clif_changelook (&sd->bl, LOOK_WEAPON, 0);
+ clif_changelook(&sd->bl, LOOK::WEAPON, static_cast<uint16_t>(ItemLook::NONE));
if (battle_config.save_clothcolor == 1 && sd->status.clothes_color > 0)
- clif_changelook (&sd->bl, LOOK_CLOTHES_COLOR,
+ clif_changelook(&sd->bl, LOOK::CLOTHES_COLOR,
sd->status.clothes_color);
- if (sd->status.hp < sd->status.max_hp >> 2
- && pc_checkskill (sd, SM_AUTOBERSERK) > 0
- && (sd->sc_data[SC_PROVOKE].timer == -1
- || sd->sc_data[SC_PROVOKE].val2 == 0))
- // オートãƒãƒ¼ã‚µãƒ¼ã‚¯ç™ºå‹•
- skill_status_change_start (&sd->bl, SC_PROVOKE, 10, 1, 0, 0, 0, 0);
-
-// if(time(&timer) < ((weddingtime=pc_readglobalreg(sd,"PC_WEDDING_TIME")) + 3600))
-// skill_status_change_start(&sd->bl,SC_WEDDING,0,weddingtime,0,0,36000,0);
-
- if (battle_config.muting_players && sd->status.manner < 0)
- skill_status_change_start (&sd->bl, SC_NOCHAT, 0, 0, 0, 0, 0, 0);
-
// option
- clif_changeoption (&sd->bl);
- if (sd->sc_data[SC_TRICKDEAD].timer != -1)
- skill_status_change_end (&sd->bl, SC_TRICKDEAD, -1);
- if (sd->sc_data[SC_SIGNUMCRUCIS].timer != -1
- && !battle_check_undead (7, sd->def_ele))
- skill_status_change_end (&sd->bl, SC_SIGNUMCRUCIS, -1);
- if (sd->special_state.infinite_endure
- && sd->sc_data[SC_ENDURE].timer == -1)
- skill_status_change_start (&sd->bl, SC_ENDURE, 10, 1, 0, 0, 0, 0);
+ clif_changeoption(&sd->bl);
for (i = 0; i < MAX_INVENTORY; i++)
{
- if (sd->status.inventory[i].equip
- && sd->status.inventory[i].equip & 0x0002
+ if (bool(sd->status.inventory[i].equip)
+ && bool(sd->status.inventory[i].equip & EPOS::WEAPON)
&& sd->status.inventory[i].broken == 1)
- skill_status_change_start (&sd->bl, SC_BROKNWEAPON, 0, 0, 0, 0, 0,
- 0);
- if (sd->status.inventory[i].equip
- && sd->status.inventory[i].equip & 0x0010
+ skill_status_change_start(&sd->bl, StatusChange::SC_BROKNWEAPON, 0, interval_t::zero());
+ if (bool(sd->status.inventory[i].equip)
+ && bool(sd->status.inventory[i].equip & EPOS::MISC1)
&& sd->status.inventory[i].broken == 1)
- skill_status_change_start (&sd->bl, SC_BROKNARMOR, 0, 0, 0, 0, 0,
- 0);
+ skill_status_change_start(&sd->bl, StatusChange::SC_BROKNARMOR, 0, interval_t::zero());
}
// clif_changelook_accessories(sd, NULL);
- map_foreachinarea (clif_getareachar, sd->bl.m, sd->bl.x - AREA_SIZE,
+ map_foreachinarea(std::bind(clif_getareachar, ph::_1, sd), sd->bl.m, sd->bl.x - AREA_SIZE,
sd->bl.y - AREA_SIZE, sd->bl.x + AREA_SIZE,
- sd->bl.y + AREA_SIZE, 0, sd);
+ sd->bl.y + AREA_SIZE, BL::NUL);
}
/*==========================================
@@ -6949,13 +3859,13 @@ void clif_parse_LoadEndAck (int fd, struct map_session_data *sd)
*------------------------------------------
*/
static
-void clif_parse_TickSend (int fd, struct map_session_data *sd)
+void clif_parse_TickSend(int fd, struct map_session_data *sd)
{
- nullpo_retv (sd);
+ nullpo_retv(sd);
- sd->client_tick = RFIFOL (fd, 2);
- sd->server_tick = gettick ();
- clif_servertick (sd);
+ sd->client_tick = tick_t(static_cast<interval_t>(RFIFOL(fd, 2)));
+ sd->server_tick = gettick();
+ clif_servertick(sd);
}
/*==========================================
@@ -6963,49 +3873,39 @@ void clif_parse_TickSend (int fd, struct map_session_data *sd)
*------------------------------------------
*/
static
-void clif_parse_WalkToXY (int fd, struct map_session_data *sd)
+void clif_parse_WalkToXY(int fd, struct map_session_data *sd)
{
- int x, y;
+ int x, y;
- nullpo_retv (sd);
+ nullpo_retv(sd);
- if (pc_isdead (sd))
+ if (pc_isdead(sd))
{
- clif_clearchar_area (&sd->bl, 1);
+ clif_clearchar(&sd->bl, BeingRemoveWhy::DEAD);
return;
}
- if (sd->npc_id != 0 || sd->state.storage_flag)
- return;
-
- if (sd->skilltimer != -1 && pc_checkskill (sd, SA_FREECAST) <= 0) // フリーキャスト
+ if (sd->npc_id != 0 || sd->state.storage_open)
return;
if (sd->chatID)
return;
- if (sd->canmove_tick > gettick ())
+ if (sd->canmove_tick > gettick())
return;
// ステータス異常やãƒã‚¤ãƒ‡ã‚£ãƒ³ã‚°ä¸­(トンãƒãƒ«ãƒ‰ãƒ©ã‚¤ãƒ–ç„¡)ã§å‹•ã‘ãªã„
- if ((sd->opt1 > 0 && sd->opt1 != 6) || sd->sc_data[SC_ANKLE].timer != -1 || //アンクルスãƒã‚¢
- sd->sc_data[SC_AUTOCOUNTER].timer != -1 || //オートカウンター
- sd->sc_data[SC_TRICKDEAD].timer != -1 || //死んã ãµã‚Š
- sd->sc_data[SC_BLADESTOP].timer != -1 || //白刃å–ã‚Š
- sd->sc_data[SC_SPIDERWEB].timer != -1 || //スパイダーウェッブ
- (sd->sc_data[SC_DANCING].timer != -1 && sd->sc_data[SC_DANCING].val4)) //åˆå¥ã‚¹ã‚­ãƒ«æ¼”å¥ä¸­ã¯å‹•ã‘ãªã„
- return;
- if ((sd->status.option & 2) && pc_checkskill (sd, RG_TUNNELDRIVE) <= 0)
+ if (bool(sd->opt1) && sd->opt1 != (Opt1::_stone6))
return;
- if (sd->invincible_timer != -1)
- pc_delinvincibletimer (sd);
+ if (sd->invincible_timer)
+ pc_delinvincibletimer(sd);
- pc_stopattack (sd);
+ pc_stopattack(sd);
- x = RFIFOB (fd, 2) * 4 + (RFIFOB (fd, 3) >> 6);
- y = ((RFIFOB (fd, 3) & 0x3f) << 4) + (RFIFOB (fd, 4) >> 4);
- pc_walktoxy (sd, x, y);
+ x = RFIFOB(fd, 2) * 4 + (RFIFOB(fd, 3) >> 6);
+ y = ((RFIFOB(fd, 3) & 0x3f) << 4) + (RFIFOB(fd, 4) >> 4);
+ pc_walktoxy(sd, x, y);
}
@@ -7013,41 +3913,33 @@ void clif_parse_WalkToXY (int fd, struct map_session_data *sd)
*
*------------------------------------------
*/
-void clif_parse_QuitGame (int fd, struct map_session_data *sd)
+void clif_parse_QuitGame(int fd, struct map_session_data *sd)
{
- unsigned int tick = gettick ();
- struct skill_unit_group *sg;
+ tick_t tick = gettick();
- nullpo_retv (sd);
+ nullpo_retv(sd);
- WFIFOW (fd, 0) = 0x18b;
- if ((!pc_isdead (sd)
- && (sd->opt1
- || (sd->opt2 && !(night_flag == 1 && sd->opt2 == STATE_BLIND))))
- || sd->skilltimer != -1 || (DIFF_TICK (tick, sd->canact_tick) < 0)
- || (sd->sc_data && sd->sc_data[SC_DANCING].timer != -1
- && sd->sc_data[SC_DANCING].val4
- && (sg = (struct skill_unit_group *) sd->sc_data[SC_DANCING].val2)
- && sg->src_id == sd->bl.id))
+ WFIFOW(fd, 0) = 0x18b;
+ if ((!pc_isdead(sd) && (sd->opt1 != Opt1::ZERO || sd->opt2 != Opt2::ZERO))
+ || (tick < sd->canact_tick))
{
- WFIFOW (fd, 2) = 1;
- WFIFOSET (fd, packet_len_table[0x18b]);
+ WFIFOW(fd, 2) = 1;
+ WFIFOSET(fd, clif_parse_func_table[0x18b].len);
return;
}
/* Rovert's prevent logout option fixed [Valaris] */
- if ((battle_config.prevent_logout
- && (gettick () - sd->canlog_tick) >= 10000)
- || (!battle_config.prevent_logout))
+ if (!battle_config.prevent_logout
+ || tick >= sd->canlog_tick + std::chrono::seconds(10))
{
- clif_setwaitclose (fd);
- WFIFOW (fd, 2) = 0;
+ clif_setwaitclose(fd);
+ WFIFOW(fd, 2) = 0;
}
else
{
- WFIFOW (fd, 2) = 1;
+ WFIFOW(fd, 2) = 1;
}
- WFIFOSET (fd, packet_len_table[0x18b]);
+ WFIFOSET(fd, clif_parse_func_table[0x18b].len);
}
@@ -7056,59 +3948,40 @@ void clif_parse_QuitGame (int fd, struct map_session_data *sd)
*------------------------------------------
*/
static
-void clif_parse_GetCharNameRequest (int fd, struct map_session_data *sd)
+void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd)
{
struct block_list *bl;
- int account_id;
+ int account_id;
- account_id = RFIFOL (fd, 2);
- bl = map_id2bl (account_id);
+ account_id = RFIFOL(fd, 2);
+ bl = map_id2bl(account_id);
if (bl == NULL)
return;
- WFIFOW (fd, 0) = 0x95;
- WFIFOL (fd, 2) = account_id;
+ WFIFOW(fd, 0) = 0x95;
+ WFIFOL(fd, 2) = account_id;
switch (bl->type)
{
- case BL_PC:
+ case BL::PC:
{
struct map_session_data *ssd = (struct map_session_data *) bl;
- nullpo_retv (ssd);
+ nullpo_retv(ssd);
if (ssd->state.shroud_active)
- memset (WFIFOP (fd, 6), 0, 24);
+ memset(WFIFOP(fd, 6), 0, 24);
else
- memcpy (WFIFOP (fd, 6), ssd->status.name, 24);
- WFIFOSET (fd, packet_len_table[0x95]);
+ memcpy(WFIFOP(fd, 6), ssd->status.name, 24);
+ WFIFOSET(fd, clif_parse_func_table[0x95].len);
- struct guild *g = NULL;
struct party *p = NULL;
- const char *guild_name = "", *guild_pos = "", *party_name = "";
+ const char *party_name = "";
int send = 0;
- if (ssd->status.guild_id > 0 && (g = guild_search (ssd->status.guild_id)) != NULL)
- {
- // there used to be a comment near here, but the code has changed slightly
- // ギルド所属ãªã‚‰ãƒ‘ケット0195ã‚’è¿”ã™
- // google says that means: 0195 return if the packet belongs Guild
- int i, ps = -1;
- for (i = 0; i < g->max_member; i++)
- {
- if (g->member[i].account_id == ssd->status.account_id)
- ps = g->member[i].position;
- }
- if (ps >= 0 && ps < MAX_GUILDPOSITION)
- {
- guild_name = g->name;
- guild_pos = g->position[ps].name;
- send = 1;
- }
- }
- if (ssd->status.party_id > 0 && (p = party_search (ssd->status.party_id)) != NULL)
+ if (ssd->status.party_id > 0 && (p = party_search(ssd->status.party_id)) != NULL)
{
party_name = p->name;
send = 1;
@@ -7116,37 +3989,37 @@ void clif_parse_GetCharNameRequest (int fd, struct map_session_data *sd)
if (send)
{
- WFIFOW (fd, 0) = 0x195;
- WFIFOL (fd, 2) = account_id;
- memcpy (WFIFOP (fd, 6), party_name, 24);
- memcpy (WFIFOP (fd, 30), guild_name, 24);
- memcpy (WFIFOP (fd, 54), guild_pos, 24);
- memcpy (WFIFOP (fd, 78), guild_pos, 24); // We send this value twice because the client expects it
- WFIFOSET (fd, packet_len_table[0x195]);
+ WFIFOW(fd, 0) = 0x195;
+ WFIFOL(fd, 2) = account_id;
+ memcpy(WFIFOP(fd, 6), party_name, 24);
+ memcpy(WFIFOP(fd, 30), "", 24);
+ memcpy(WFIFOP(fd, 54), "", 24);
+ memcpy(WFIFOP(fd, 78), "", 24); // We send this value twice because the client expects it
+ WFIFOSET(fd, clif_parse_func_table[0x195].len);
}
if (pc_isGM(sd) >= battle_config.hack_info_GM_level)
{
struct in_addr ip = ssd->ip;
- WFIFOW (fd, 0) = 0x20C;
+ WFIFOW(fd, 0) = 0x20C;
// Mask the IP using the char-server password
if (battle_config.mask_ip_gms)
- ip = MD5_ip(chrif_getpasswd (), ssd->ip);
+ ip = MD5_ip(chrif_getpasswd(), ssd->ip);
- WFIFOL (fd, 2) = account_id;
- WFIFOL (fd, 6) = ip.s_addr;
- WFIFOSET (fd, packet_len_table[0x20C]);
+ WFIFOL(fd, 2) = account_id;
+ WFIFOL(fd, 6) = ip.s_addr;
+ WFIFOSET(fd, clif_parse_func_table[0x20C].len);
}
}
break;
- case BL_NPC:
- memcpy (WFIFOP (fd, 6), ((struct npc_data *) bl)->name, 24);
+ case BL::NPC:
+ memcpy(WFIFOP(fd, 6), ((struct npc_data *) bl)->name, 24);
{
- char *start = (char *)WFIFOP (fd, 6);
- char *end = strchr (start, '#'); // [fate] elim hashed out/invisible names for the client
+ char *start = (char *)WFIFOP(fd, 6);
+ char *end = strchr(start, '#'); // [fate] elim hashed out/invisible names for the client
if (end)
while (*end)
*end++ = 0;
@@ -7155,21 +4028,21 @@ void clif_parse_GetCharNameRequest (int fd, struct map_session_data *sd)
while (*start == '_')
*start++ = ' ';
}
- WFIFOSET (fd, packet_len_table[0x95]);
+ WFIFOSET(fd, clif_parse_func_table[0x95].len);
break;
- case BL_MOB:
+ case BL::MOB:
{
struct mob_data *md = (struct mob_data *) bl;
- nullpo_retv (md);
+ nullpo_retv(md);
- memcpy (WFIFOP (fd, 6), md->name, 24);
- WFIFOSET (fd, packet_len_table[0x95]);
+ memcpy(WFIFOP(fd, 6), md->name, 24);
+ WFIFOSET(fd, clif_parse_func_table[0x95].len);
}
break;
default:
if (battle_config.error_log)
- printf ("clif_parse_GetCharNameRequest : bad type %d(%d)\n",
+ PRINTF("clif_parse_GetCharNameRequest : bad type %d (%d)\n",
bl->type, account_id);
break;
}
@@ -7183,75 +4056,73 @@ void clif_parse_GetCharNameRequest (int fd, struct map_session_data *sd)
*------------------------------------------
*/
static
-void clif_parse_GlobalMessage (int fd, struct map_session_data *sd)
+void clif_parse_GlobalMessage(int fd, struct map_session_data *sd)
{
- int msg_len = RFIFOW (fd, 2) - 4; /* Header (2) + length (2). */
+ int msg_len = RFIFOW(fd, 2) - 4; /* Header(2) + length(2). */
size_t message_len = 0;
// sometimes uint8_t
char *buf = NULL;
- char *message = NULL; /* The message text only. */
+ const char *message = NULL; /* The message text only. */
- nullpo_retv (sd);
+ nullpo_retv(sd);
- if (!(buf = clif_validate_chat (sd, 2, &message, &message_len)))
+ if (!(buf = clif_validate_chat(sd, 2, &message, &message_len)))
{
- clif_displaymessage (fd, "Your message could not be sent.");
+ clif_displaymessage(fd, "Your message could not be sent.");
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)))//ãƒãƒ£ãƒƒãƒˆç¦æ­¢
+ if (is_atcommand(fd, sd, message, 0)) //ãƒãƒ£ãƒƒãƒˆç¦æ­¢
{
- free (buf);
+ free(buf);
return;
}
- if (!magic_message (sd, buf, msg_len))
+ if (!magic_message(sd, buf, msg_len))
{
/* Don't send chat that results in an automatic ban. */
- if (tmw_CheckChatSpam (sd, message))
+ if (tmw_CheckChatSpam(sd, message))
{
- free (buf);
- clif_displaymessage (fd, "Your message could not be sent.");
+ free(buf);
+ clif_displaymessage(fd, "Your message could not be sent.");
return;
}
/* It's not a spell/magic message, so send the message to others. */
- WBUFW (buf, 0) = 0x8d;
- WBUFW (buf, 2) = msg_len + 8; /* Header (2) + length (2) + ID (4). */
- WBUFL (buf, 4) = sd->bl.id;
+ WBUFW(reinterpret_cast<uint8_t *>(buf), 0) = 0x8d;
+ WBUFW(reinterpret_cast<uint8_t *>(buf), 2) = msg_len + 8; /* Header(2) + length(2) + ID(4). */
+ WBUFL(reinterpret_cast<uint8_t *>(buf), 4) = sd->bl.id;
// evil multiuse buffer!
- clif_send ((const uint8_t *)buf, msg_len + 8, &sd->bl,
- sd->chatID ? CHAT_WOS : AREA_CHAT_WOC);
+ clif_send((const uint8_t *)buf, msg_len + 8, &sd->bl,
+ sd->chatID ? SendWho::CHAT_WOS : SendWho::AREA_CHAT_WOC);
}
/* Send the message back to the speaker. */
- memcpy (WFIFOP (fd, 0), RFIFOP (fd, 0), RFIFOW (fd, 2));
- WFIFOW (fd, 0) = 0x8e;
- WFIFOSET (fd, WFIFOW (fd, 2));
+ memcpy(WFIFOP(fd, 0), RFIFOP(fd, 0), RFIFOW(fd, 2));
+ WFIFOW(fd, 0) = 0x8e;
+ WFIFOSET(fd, WFIFOW(fd, 2));
- free (buf);
+ free(buf);
return;
}
-int clif_message (struct block_list *bl, const char *msg)
+int clif_message(struct block_list *bl, const char *msg)
{
- unsigned short msg_len = strlen (msg) + 1;
+ unsigned short msg_len = strlen(msg) + 1;
unsigned char buf[512];
if (msg_len + 16 > 512)
return 0;
- nullpo_retr (0, bl);
+ nullpo_ret(bl);
- WBUFW (buf, 0) = 0x8d;
- WBUFW (buf, 2) = msg_len + 8;
- WBUFL (buf, 4) = bl->id;
- memcpy (WBUFP (buf, 8), msg, msg_len);
+ WBUFW(buf, 0) = 0x8d;
+ WBUFW(buf, 2) = msg_len + 8;
+ WBUFL(buf, 4) = bl->id;
+ memcpy(WBUFP(buf, 8), msg, msg_len);
- clif_send (buf, WBUFW (buf, 2), bl, AREA);
+ clif_send(buf, WBUFW(buf, 2), bl, SendWho::AREA);
return 0;
}
@@ -7261,58 +4132,28 @@ int clif_message (struct block_list *bl, const char *msg)
*------------------------------------------
*/
static
-void clif_parse_MapMove (int fd, struct map_session_data *sd)
-{
-// /m /mapmove (as @rura GM command)
- char output[100];
- char map_name[17];
-
- nullpo_retv (sd);
-
- memset (output, '\0', sizeof (output));
- memset (map_name, '\0', sizeof (map_name));
-
- if ((battle_config.atc_gmonly == 0 || pc_isGM (sd)) &&
- (pc_isGM (sd) >= get_atcommand_level (AtCommand_MapMove)))
- {
- memcpy (map_name, RFIFOP (fd, 2), 16);
- sprintf (output, "%s %d %d", map_name, RFIFOW (fd, 18),
- RFIFOW (fd, 20));
- log_atcommand (sd, "@warp %s", output);
- atcommand_warp (fd, sd, "@warp", output);
- }
-
- return;
-}
-
-/*==========================================
- *
- *------------------------------------------
- */
-static
-void clif_parse_ChangeDir (int fd, struct map_session_data *sd)
+void clif_parse_ChangeDir(int fd, struct map_session_data *sd)
{
unsigned char buf[64];
- short dir;
- nullpo_retv (sd);
+ nullpo_retv(sd);
-// RFIFOW(fd,2); // Apparently does nothing?
- dir = RFIFOB (fd, 4);
+ // RFIFOW(fd, 2) is always 0
+ DIR dir = static_cast<DIR>(RFIFOB(fd, 4));
+ if (dir >= DIR::COUNT)
+ return;
if (dir == sd->dir)
return;
- pc_setdir (sd, dir);
+ pc_setdir(sd, dir);
- WBUFW (buf, 0) = 0x9c;
- WBUFL (buf, 2) = sd->bl.id;
- WBUFW (buf, 6) = 0;
- WBUFB (buf, 8) = dir;
- if (sd->disguise > 23 && sd->disguise < 4001) // mob disguises [Valaris]
- clif_send (buf, packet_len_table[0x9c], &sd->bl, AREA);
- else
- clif_send (buf, packet_len_table[0x9c], &sd->bl, AREA_WOS);
+ WBUFW(buf, 0) = 0x9c;
+ WBUFL(buf, 2) = sd->bl.id;
+ WBUFW(buf, 6) = 0;
+ WBUFB(buf, 8) = static_cast<uint8_t>(dir);
+
+ clif_send(buf, clif_parse_func_table[0x9c].len, &sd->bl, SendWho::AREA_WOS);
}
@@ -7321,22 +4162,22 @@ void clif_parse_ChangeDir (int fd, struct map_session_data *sd)
*------------------------------------------
*/
static
-void clif_parse_Emotion (int fd, struct map_session_data *sd)
+void clif_parse_Emotion(int fd, struct map_session_data *sd)
{
unsigned char buf[64];
- nullpo_retv (sd);
+ nullpo_retv(sd);
if (battle_config.basic_skill_check == 0
- || pc_checkskill (sd, NV_EMOTE) >= 1)
+ || pc_checkskill(sd, SkillID::NV_EMOTE) >= 1)
{
- WBUFW (buf, 0) = 0xc0;
- WBUFL (buf, 2) = sd->bl.id;
- WBUFB (buf, 6) = RFIFOB (fd, 2);
- clif_send (buf, packet_len_table[0xc0], &sd->bl, AREA);
+ WBUFW(buf, 0) = 0xc0;
+ WBUFL(buf, 2) = sd->bl.id;
+ WBUFB(buf, 6) = RFIFOB(fd, 2);
+ clif_send(buf, clif_parse_func_table[0xc0].len, &sd->bl, SendWho::AREA);
}
else
- clif_skill_fail (sd, 1, 0, 1);
+ clif_skill_fail(sd, SkillID::ONE, 0, 1);
}
/*==========================================
@@ -7344,11 +4185,11 @@ void clif_parse_Emotion (int fd, struct map_session_data *sd)
*------------------------------------------
*/
static
-void clif_parse_HowManyConnections (int fd, struct map_session_data *sd)
+void clif_parse_HowManyConnections(int fd, struct map_session_data *)
{
- WFIFOW (fd, 0) = 0xc2;
- WFIFOL (fd, 2) = map_getusers ();
- WFIFOSET (fd, packet_len_table[0xc2]);
+ WFIFOW(fd, 0) = 0xc2;
+ WFIFOL(fd, 2) = map_getusers();
+ WFIFOSET(fd, clif_parse_func_table[0xc2].len);
}
/*==========================================
@@ -7356,68 +4197,64 @@ void clif_parse_HowManyConnections (int fd, struct map_session_data *sd)
*------------------------------------------
*/
static
-void clif_parse_ActionRequest (int fd, struct map_session_data *sd)
+void clif_parse_ActionRequest(int fd, struct map_session_data *sd)
{
- unsigned int tick;
unsigned char buf[64];
- int action_type, target_id;
+ int action_type, target_id;
- nullpo_retv (sd);
+ nullpo_retv(sd);
- if (pc_isdead (sd))
+ if (pc_isdead(sd))
{
- clif_clearchar_area (&sd->bl, 1);
+ clif_clearchar(&sd->bl, BeingRemoveWhy::DEAD);
return;
}
- if (sd->npc_id != 0 || sd->opt1 > 0 || sd->status.option & 2 || sd->state.storage_flag ||
- (sd->sc_data && (sd->sc_data[SC_AUTOCOUNTER].timer != -1 || //オートカウンター
- sd->sc_data[SC_BLADESTOP].timer != -1 || //白刃å–ã‚Š
- sd->sc_data[SC_DANCING].timer != -1)))
+ if (sd->npc_id != 0
+ || bool(sd->opt1)
+ || sd->state.storage_open)
return;
- tick = gettick ();
+ tick_t tick = gettick();
- pc_stop_walking (sd, 0);
- pc_stopattack (sd);
+ pc_stop_walking(sd, 0);
+ pc_stopattack(sd);
- target_id = RFIFOL (fd, 2);
- action_type = RFIFOB (fd, 6);
+ target_id = RFIFOL(fd, 2);
+ action_type = RFIFOB(fd, 6);
switch (action_type)
{
case 0x00: // once attack
case 0x07: // continuous attack
- if (sd->sc_data[SC_WEDDING].timer != -1 || sd->view_class == 22
- || sd->status.option & OPTION_HIDE)
+ if (bool(sd->status.option & Option::HIDE))
return;
- if (!battle_config.sdelay_attack_enable
- && pc_checkskill (sd, SA_FREECAST) <= 0)
+ if (!battle_config.sdelay_attack_enable)
{
- if (DIFF_TICK (tick, sd->canact_tick) < 0)
+ if (tick < sd->canact_tick)
{
- clif_skill_fail (sd, 1, 4, 0);
+ clif_skill_fail(sd, SkillID::ONE, 4, 0);
return;
}
}
- if (sd->invincible_timer != -1)
- pc_delinvincibletimer (sd);
+ if (sd->invincible_timer)
+ pc_delinvincibletimer(sd);
if (sd->attacktarget > 0) // [Valaris]
sd->attacktarget = 0;
- pc_attack (sd, target_id, action_type != 0);
+ pc_attack(sd, target_id, action_type != 0);
break;
case 0x02: // sitdown
- pc_stop_walking (sd, 1);
- skill_gangsterparadise (sd, 1); // ギャングスターパラダイス設定
- pc_setsit (sd);
- clif_sitting (fd, sd);
+ pc_stop_walking(sd, 1);
+ skill_gangsterparadise(sd, 1); // ギャングスターパラダイス設定
+ pc_setsit(sd);
+ clif_sitting(fd, sd);
break;
case 0x03: // standup
- skill_gangsterparadise (sd, 0); // ギャングスターパラダイス解除
- pc_setstand (sd);
- WBUFW (buf, 0) = 0x8a;
- WBUFL (buf, 2) = sd->bl.id;
- WBUFB (buf, 26) = 3;
- clif_send (buf, packet_len_table[0x8a], &sd->bl, AREA);
+ skill_gangsterparadise(sd, 0); // ギャングスターパラダイス解除
+ pc_setstand(sd);
+ WBUFW(buf, 0) = 0x8a;
+ WBUFL(buf, 2) = sd->bl.id;
+ WBUFB(buf, 26) = 3;
+ clif_send(buf, clif_parse_func_table[0x8a].len, &sd->bl, SendWho::AREA);
break;
}
}
@@ -7427,39 +4264,35 @@ void clif_parse_ActionRequest (int fd, struct map_session_data *sd)
*------------------------------------------
*/
static
-void clif_parse_Restart (int fd, struct map_session_data *sd)
+void clif_parse_Restart(int fd, struct map_session_data *sd)
{
- nullpo_retv (sd);
+ nullpo_retv(sd);
- switch (RFIFOB (fd, 2))
+ switch (RFIFOB(fd, 2))
{
case 0x00:
- if (pc_isdead (sd))
+ if (pc_isdead(sd))
{
- pc_setstand (sd);
- pc_setrestartvalue (sd, 3);
- pc_setpos (sd, sd->status.save_point.map,
+ pc_setstand(sd);
+ pc_setrestartvalue(sd, 3);
+ pc_setpos(sd, sd->status.save_point.map,
sd->status.save_point.x, sd->status.save_point.y,
- 2);
+ BeingRemoveWhy::QUIT);
}
break;
case 0x01:
- /*if(!pc_isdead(sd) && (sd->opt1 || (sd->opt2 && !(night_flag == 1 && sd->opt2 == STATE_BLIND))))
- * return; */
-
/* Rovert's Prevent logout option - Fixed [Valaris] */
- if ((battle_config.prevent_logout
- && (gettick () - sd->canlog_tick) >= 10000)
- || (!battle_config.prevent_logout))
+ if (!battle_config.prevent_logout
+ || gettick() >= sd->canlog_tick + std::chrono::seconds(10))
{
- chrif_charselectreq (sd);
+ chrif_charselectreq(sd);
}
else
{
- WFIFOW (fd, 0) = 0x18b;
- WFIFOW (fd, 2) = 1;
+ WFIFOW(fd, 0) = 0x18b;
+ WFIFOW(fd, 2) = 1;
- WFIFOSET (fd, packet_len_table[0x018b]);
+ WFIFOSET(fd, clif_parse_func_table[0x018b].len);
}
break;
}
@@ -7476,34 +4309,32 @@ void clif_parse_Restart (int fd, struct map_session_data *sd)
*------------------------------------------
*/
static
-void clif_parse_Wis (int fd, struct map_session_data *sd)
+void clif_parse_Wis(int fd, struct map_session_data *sd)
{
size_t message_len = 0;
char *buf = NULL;
- char *message = NULL; /* The message text only. */
+ const char *message = NULL; /* The message text only. */
struct map_session_data *dstsd = NULL;
- nullpo_retv (sd);
+ nullpo_retv(sd);
- if (!(buf = clif_validate_chat (sd, 1, &message, &message_len)))
+ if (!(buf = clif_validate_chat(sd, 1, &message, &message_len)))
{
- clif_displaymessage (fd, "Your message could not be sent.");
+ clif_displaymessage(fd, "Your message could not be sent.");
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)))
+ if (is_atcommand(fd, sd, message, 0))
{
- free (buf);
+ free(buf);
return;
}
/* Don't send chat that results in an automatic ban. */
- if (tmw_CheckChatSpam (sd, message))
+ if (tmw_CheckChatSpam(sd, message))
{
- free (buf);
- clif_displaymessage (fd, "Your message could not be sent.");
+ free(buf);
+ clif_displaymessage(fd, "Your message could not be sent.");
return;
}
@@ -7513,75 +4344,50 @@ void clif_parse_Wis (int fd, struct map_session_data *sd)
* conflict (for instance, "Test" versus "test"), the char-server must
* settle the discrepancy.
*/
- if (!(dstsd = map_nick2sd ((const char *)RFIFOP (fd, 4)))
- || strcmp (dstsd->status.name, (const char *)RFIFOP (fd, 4)) != 0)
- intif_wis_message (sd, (const char *)RFIFOP (fd, 4), message, RFIFOW (fd, 2) - 28);
+ if (!(dstsd = map_nick2sd((const char *)RFIFOP(fd, 4)))
+ || strcmp(dstsd->status.name, (const char *)RFIFOP(fd, 4)) != 0)
+ intif_wis_message(sd, (const char *)RFIFOP(fd, 4), message, RFIFOW(fd, 2) - 28);
else
{
/* Refuse messages addressed to self. */
if (dstsd->fd == fd)
{
const char *mes = "You cannot page yourself.";
- clif_wis_message (fd, wisp_server_name, mes, strlen (mes) + 1);
+ clif_wis_message(fd, wisp_server_name, mes, strlen(mes) + 1);
}
else
{
/* The target is ignoring all whispers. */
if (dstsd->ignoreAll == 1)
/* Ignored by target. */
- clif_wis_end (fd, 2);
+ clif_wis_end(fd, 2);
else
{
int i;
- size_t end = sizeof (dstsd->ignore) / sizeof (dstsd->ignore[0]);
+ size_t end = sizeof(dstsd->ignore) / sizeof(dstsd->ignore[0]);
/* See if the source player is being ignored. */
for (i = 0; i < end; ++i)
- if (strcmp (dstsd->ignore[i].name, sd->status.name) == 0)
+ if (strcmp(dstsd->ignore[i].name, sd->status.name) == 0)
{
/* Ignored by target. */
- clif_wis_end (fd, 2);
+ clif_wis_end(fd, 2);
break;
}
/* The player is not being ignored. */
if (i == end)
{
- clif_wis_message (dstsd->fd, sd->status.name, message,
- RFIFOW (fd, 2) - 28);
+ clif_wis_message(dstsd->fd, sd->status.name, message,
+ RFIFOW(fd, 2) - 28);
/* The whisper was sent successfully. */
- clif_wis_end (fd, 0);
+ clif_wis_end(fd, 0);
}
}
}
}
- free (buf);
-}
-
-/*==========================================
- *
- *------------------------------------------
- */
-static
-void clif_parse_GMmessage (int fd, struct map_session_data *sd)
-{
- char m[512];
- char output[200];
- nullpo_retv (sd);
-
- if ((battle_config.atc_gmonly == 0 || pc_isGM (sd)) &&
- (pc_isGM (sd) >= get_atcommand_level (AtCommand_Broadcast)))
- {
- strncpy (m, (const char *)RFIFOP (fd, 4), RFIFOW (fd, 2) - 4);
- m[RFIFOW (fd, 2) - 4] = 0;
- log_atcommand (sd, "/announce %s", m);
-
- memset (output, '\0', sizeof (output));
- snprintf (output, 199, "%s : %s", sd->status.name, m);
-
- intif_GMmessage (output, strlen (output) + 1, 0);
- }
+ free(buf);
}
/*==========================================
@@ -7589,40 +4395,37 @@ void clif_parse_GMmessage (int fd, struct map_session_data *sd)
*------------------------------------------
*/
static
-void clif_parse_TakeItem (int fd, struct map_session_data *sd)
+void clif_parse_TakeItem(int fd, struct map_session_data *sd)
{
struct flooritem_data *fitem;
- int map_object_id;
+ int map_object_id;
- nullpo_retv (sd);
+ nullpo_retv(sd);
- map_object_id = RFIFOL (fd, 2);
- fitem = (struct flooritem_data *) map_id2bl (map_object_id);
+ map_object_id = RFIFOL(fd, 2);
+ fitem = (struct flooritem_data *) map_id2bl(map_object_id);
- if (pc_isdead (sd))
+ if (pc_isdead(sd))
{
- clif_clearchar_area (&sd->bl, 1);
+ clif_clearchar(&sd->bl, BeingRemoveWhy::DEAD);
return;
}
- if (sd->npc_id != 0 || sd->opt1 > 0 || (sd->sc_data &&
- (sd->sc_data[SC_TRICKDEAD].timer != -1 || //死んã ãµã‚Š
- sd->sc_data[SC_BLADESTOP].timer != -1 || //白刃å–ã‚Š
- sd->sc_data[SC_BERSERK].timer != -1 || //ãƒãƒ¼ã‚µãƒ¼ã‚¯
- sd->sc_data[SC_NOCHAT].timer != -1))) //会話ç¦æ­¢
+ if (sd->npc_id != 0
+ || sd->opt1 != Opt1::ZERO) //会話ç¦æ­¢
return;
if (fitem == NULL || fitem->bl.m != sd->bl.m)
return;
- if (abs (sd->bl.x - fitem->bl.x) >= 2
- || abs (sd->bl.y - fitem->bl.y) >= 2)
+ if (abs(sd->bl.x - fitem->bl.x) >= 2
+ || abs(sd->bl.y - fitem->bl.y) >= 2)
return; // too far away to pick up
if (sd->state.shroud_active && sd->state.shroud_disappears_on_pickup)
- magic_unshroud (sd);
+ magic_unshroud(sd);
- pc_takeitem (sd, fitem);
+ pc_takeitem(sd, fitem);
}
/*==========================================
@@ -7630,15 +4433,15 @@ void clif_parse_TakeItem (int fd, struct map_session_data *sd)
*------------------------------------------
*/
static
-void clif_parse_DropItem (int fd, struct map_session_data *sd)
+void clif_parse_DropItem(int fd, struct map_session_data *sd)
{
- int item_index, item_amount;
+ int item_index, item_amount;
- nullpo_retv (sd);
+ nullpo_retv(sd);
- if (pc_isdead (sd))
+ if (pc_isdead(sd))
{
- clif_clearchar_area (&sd->bl, 1);
+ clif_clearchar(&sd->bl, BeingRemoveWhy::DEAD);
return;
}
if (map[sd->bl.m].flag.no_player_drops)
@@ -7646,19 +4449,17 @@ void clif_parse_DropItem (int fd, struct map_session_data *sd)
clif_displaymessage(sd->fd, "Can't drop items here.");
return;
}
- if (sd->npc_id != 0 || sd->opt1 > 0 ||
- (sd->sc_data && (sd->sc_data[SC_AUTOCOUNTER].timer != -1 || //オートカウンター
- sd->sc_data[SC_BLADESTOP].timer != -1 || //白刃å–ã‚Š
- sd->sc_data[SC_BERSERK].timer != -1))) //ãƒãƒ¼ã‚µãƒ¼ã‚¯
+ if (sd->npc_id != 0
+ || sd->opt1 != Opt1::ZERO)
{
clif_displaymessage(sd->fd, "Can't drop items right now.");
return;
}
- item_index = RFIFOW (fd, 2) - 2;
- item_amount = RFIFOW (fd, 4);
+ item_index = RFIFOW(fd, 2) - 2;
+ item_amount = RFIFOW(fd, 4);
- pc_dropitem (sd, item_index, item_amount);
+ pc_dropitem(sd, item_index, item_amount);
}
/*==========================================
@@ -7666,26 +4467,23 @@ void clif_parse_DropItem (int fd, struct map_session_data *sd)
*------------------------------------------
*/
static
-void clif_parse_UseItem (int fd, struct map_session_data *sd)
+void clif_parse_UseItem(int fd, struct map_session_data *sd)
{
- nullpo_retv (sd);
+ nullpo_retv(sd);
- if (pc_isdead (sd))
+ if (pc_isdead(sd))
{
- clif_clearchar_area (&sd->bl, 1);
+ clif_clearchar(&sd->bl, BeingRemoveWhy::DEAD);
return;
}
- if (sd->npc_id != 0 || sd->opt1 > 0 || (sd->sc_data &&
- (sd->sc_data[SC_TRICKDEAD].timer != -1 || //死んã ãµã‚Š
- sd->sc_data[SC_BLADESTOP].timer != -1 || //白刃å–ã‚Š
- sd->sc_data[SC_BERSERK].timer != -1 || //ãƒãƒ¼ã‚µãƒ¼ã‚¯
- sd->sc_data[SC_NOCHAT].timer != -1))) //会話ç¦æ­¢
+ if (sd->npc_id != 0
+ || sd->opt1 != Opt1::ZERO) //会話ç¦æ­¢
return;
- if (sd->invincible_timer != -1)
- pc_delinvincibletimer (sd);
+ if (sd->invincible_timer)
+ pc_delinvincibletimer(sd);
- pc_useitem (sd, RFIFOW (fd, 2) - 2);
+ pc_useitem(sd, RFIFOW(fd, 2) - 2);
}
/*==========================================
@@ -7693,24 +4491,20 @@ void clif_parse_UseItem (int fd, struct map_session_data *sd)
*------------------------------------------
*/
static
-void clif_parse_EquipItem (int fd, struct map_session_data *sd)
+void clif_parse_EquipItem(int fd, struct map_session_data *sd)
{
- int index;
+ int index;
- nullpo_retv (sd);
+ nullpo_retv(sd);
- if (pc_isdead (sd))
+ if (pc_isdead(sd))
{
- clif_clearchar_area (&sd->bl, 1);
+ clif_clearchar(&sd->bl, BeingRemoveWhy::DEAD);
return;
}
- index = RFIFOW (fd, 2) - 2;
+ index = RFIFOW(fd, 2) - 2;
if (sd->npc_id != 0)
return;
- if (sd->sc_data
- && (sd->sc_data[SC_BLADESTOP].timer != -1
- || sd->sc_data[SC_BERSERK].timer != -1))
- return;
if (sd->status.inventory[index].identify != 1)
{ // 未鑑定
@@ -7723,9 +4517,13 @@ void clif_parse_EquipItem (int fd, struct map_session_data *sd)
//ペット用装備ã§ã‚ã‚‹ã‹ãªã„ã‹
if (sd->inventory_data[index])
{
- if (sd->inventory_data[index]->type == 10)
- RFIFOW (fd, 4) = 0x8000; // 矢を無ç†ã‚„り装備ã§ãるよã†ã«ï¼ˆâˆ’−;
- pc_equipitem (sd, index, RFIFOW (fd, 4));
+ EPOS epos = EPOS(RFIFOW(fd, 4));
+ if (sd->inventory_data[index]->type == ItemType::ARROW)
+ // 矢を無ç†ã‚„り装備ã§ãるよã†ã«ï¼ˆâˆ’−;
+ epos = EPOS::ARROW;
+
+ // Note: the EPOS argument to pc_equipitem is actually ignored
+ pc_equipitem(sd, index, epos);
}
}
@@ -7734,32 +4532,27 @@ void clif_parse_EquipItem (int fd, struct map_session_data *sd)
*------------------------------------------
*/
static
-void clif_parse_UnequipItem (int fd, struct map_session_data *sd)
+void clif_parse_UnequipItem(int fd, struct map_session_data *sd)
{
- int index;
+ int index;
- nullpo_retv (sd);
+ nullpo_retv(sd);
- if (pc_isdead (sd))
+ if (pc_isdead(sd))
{
- clif_clearchar_area (&sd->bl, 1);
+ clif_clearchar(&sd->bl, BeingRemoveWhy::DEAD);
return;
}
- index = RFIFOW (fd, 2) - 2;
- if (sd->status.inventory[index].broken == 1 && sd->sc_data
- && sd->sc_data[SC_BROKNWEAPON].timer != -1)
- skill_status_change_end (&sd->bl, SC_BROKNWEAPON, -1);
- if (sd->status.inventory[index].broken == 1 && sd->sc_data
- && sd->sc_data[SC_BROKNARMOR].timer != -1)
- skill_status_change_end (&sd->bl, SC_BROKNARMOR, -1);
- if (sd->sc_data
- && (sd->sc_data[SC_BLADESTOP].timer != -1
- || sd->sc_data[SC_BERSERK].timer != -1))
- return;
+ index = RFIFOW(fd, 2) - 2;
+ if (sd->status.inventory[index].broken == 1 && sd->sc_data[StatusChange::SC_BROKNWEAPON].timer)
+ skill_status_change_end(&sd->bl, StatusChange::SC_BROKNWEAPON, nullptr);
+ if (sd->status.inventory[index].broken == 1 && sd->sc_data[StatusChange::SC_BROKNARMOR].timer)
+ skill_status_change_end(&sd->bl, StatusChange::SC_BROKNARMOR, nullptr);
- if (sd->npc_id != 0 || sd->opt1 > 0)
+ if (sd->npc_id != 0
+ || sd->opt1 != Opt1::ZERO)
return;
- pc_unequipitem (sd, index, 0);
+ pc_unequipitem(sd, index, CalcStatus::NOW);
}
/*==========================================
@@ -7767,18 +4560,18 @@ void clif_parse_UnequipItem (int fd, struct map_session_data *sd)
*------------------------------------------
*/
static
-void clif_parse_NpcClicked (int fd, struct map_session_data *sd)
+void clif_parse_NpcClicked(int fd, struct map_session_data *sd)
{
- nullpo_retv (sd);
+ nullpo_retv(sd);
- if (pc_isdead (sd))
+ if (pc_isdead(sd))
{
- clif_clearchar_area (&sd->bl, 1);
+ clif_clearchar(&sd->bl, BeingRemoveWhy::DEAD);
return;
}
if (sd->npc_id != 0)
return;
- npc_click (sd, RFIFOL (fd, 2));
+ npc_click(sd, RFIFOL(fd, 2));
}
/*==========================================
@@ -7786,9 +4579,9 @@ void clif_parse_NpcClicked (int fd, struct map_session_data *sd)
*------------------------------------------
*/
static
-void clif_parse_NpcBuySellSelected (int fd, struct map_session_data *sd)
+void clif_parse_NpcBuySellSelected(int fd, struct map_session_data *sd)
{
- npc_buysellsel (sd, RFIFOL (fd, 2), RFIFOB (fd, 6));
+ npc_buysellsel(sd, RFIFOL(fd, 2), RFIFOB(fd, 6));
}
/*==========================================
@@ -7796,71 +4589,17 @@ void clif_parse_NpcBuySellSelected (int fd, struct map_session_data *sd)
*------------------------------------------
*/
static
-void clif_parse_NpcBuyListSend (int fd, struct map_session_data *sd)
+void clif_parse_NpcBuyListSend(int fd, struct map_session_data *sd)
{
- int fail = 0, n;
- unsigned short *item_list;
-
- n = (RFIFOW (fd, 2) - 4) / 4;
- item_list = (unsigned short *) RFIFOP (fd, 4);
+ int n = (RFIFOW(fd, 2) - 4) / 4;
+ // really an array of pairs of uint16_t
+ const uint16_t *item_list = static_cast<const uint16_t *>(RFIFOP(fd, 4));
- fail = npc_buylist (sd, n, item_list);
-
- WFIFOW (fd, 0) = 0xca;
- WFIFOB (fd, 2) = fail;
- WFIFOSET (fd, packet_len_table[0xca]);
-}
-
-/*==========================================
- *
- *------------------------------------------
- */
-static
-void clif_parse_NpcSellListSend (int fd, struct map_session_data *sd)
-{
- int fail = 0, n;
- unsigned short *item_list;
-
- n = (RFIFOW (fd, 2) - 4) / 4;
- item_list = (unsigned short *) RFIFOP (fd, 4);
-
- fail = npc_selllist (sd, n, item_list);
-
- WFIFOW (fd, 0) = 0xcb;
- WFIFOB (fd, 2) = fail;
- WFIFOSET (fd, packet_len_table[0xcb]);
-}
-
-/*==========================================
- *
- *------------------------------------------
- */
-static
-void clif_parse_CreateChatRoom (int fd, struct map_session_data *sd)
-{
- chat_createchat (sd, RFIFOW (fd, 4), RFIFOB (fd, 6), (const char *)RFIFOP (fd, 7),
- (const char *)RFIFOP (fd, 15), RFIFOW (fd, 2) - 15);
-}
-
-/*==========================================
- *
- *------------------------------------------
- */
-static
-void clif_parse_ChatAddMember (int fd, struct map_session_data *sd)
-{
- chat_joinchat (sd, RFIFOL (fd, 2), (const char *)RFIFOP (fd, 6));
-}
+ int fail = npc_buylist(sd, n, item_list);
-/*==========================================
- *
- *------------------------------------------
- */
-static
-void clif_parse_ChatRoomStatusChange (int fd, struct map_session_data *sd)
-{
- chat_changechatstatus (sd, RFIFOW (fd, 4), RFIFOB (fd, 6), (const char *)RFIFOP (fd, 7),
- (const char *)RFIFOP (fd, 15), RFIFOW (fd, 2) - 15);
+ WFIFOW(fd, 0) = 0xca;
+ WFIFOB(fd, 2) = fail;
+ WFIFOSET(fd, clif_parse_func_table[0xca].len);
}
/*==========================================
@@ -7868,29 +4607,17 @@ void clif_parse_ChatRoomStatusChange (int fd, struct map_session_data *sd)
*------------------------------------------
*/
static
-void clif_parse_ChangeChatOwner (int fd, struct map_session_data *sd)
+void clif_parse_NpcSellListSend(int fd, struct map_session_data *sd)
{
- chat_changechatowner (sd, (const char *)RFIFOP (fd, 6));
-}
+ int n = (RFIFOW(fd, 2) - 4) / 4;
+ // really an array of pairs of uint16_t
+ const uint16_t *item_list = static_cast<const uint16_t *>(RFIFOP(fd, 4));
-/*==========================================
- *
- *------------------------------------------
- */
-static
-void clif_parse_KickFromChat (int fd, struct map_session_data *sd)
-{
- chat_kickchat (sd, (const char *)RFIFOP (fd, 2));
-}
+ int fail = npc_selllist(sd, n, item_list);
-/*==========================================
- *
- *------------------------------------------
- */
-static
-void clif_parse_ChatLeave (int fd, struct map_session_data *sd)
-{
- chat_leavechat (sd);
+ WFIFOW(fd, 0) = 0xcb;
+ WFIFOB(fd, 2) = fail;
+ WFIFOSET(fd, clif_parse_func_table[0xcb].len);
}
/*==========================================
@@ -7898,17 +4625,17 @@ void clif_parse_ChatLeave (int fd, struct map_session_data *sd)
*------------------------------------------
*/
static
-void clif_parse_TradeRequest (int fd, struct map_session_data *sd)
+void clif_parse_TradeRequest(int, struct map_session_data *sd)
{
- nullpo_retv (sd);
+ nullpo_retv(sd);
if (battle_config.basic_skill_check == 0
- || pc_checkskill (sd, NV_TRADE) >= 1)
+ || pc_checkskill(sd, SkillID::NV_TRADE) >= 1)
{
- trade_traderequest (sd, RFIFOL (sd->fd, 2));
+ trade_traderequest(sd, RFIFOL(sd->fd, 2));
}
else
- clif_skill_fail (sd, 1, 0, 0);
+ clif_skill_fail(sd, SkillID::ONE, 0, 0);
}
/*==========================================
@@ -7916,11 +4643,11 @@ void clif_parse_TradeRequest (int fd, struct map_session_data *sd)
*------------------------------------------
*/
static
-void clif_parse_TradeAck (int fd, struct map_session_data *sd)
+void clif_parse_TradeAck(int, struct map_session_data *sd)
{
- nullpo_retv (sd);
+ nullpo_retv(sd);
- trade_tradeack (sd, RFIFOB (sd->fd, 2));
+ trade_tradeack(sd, RFIFOB(sd->fd, 2));
}
/*==========================================
@@ -7928,11 +4655,11 @@ void clif_parse_TradeAck (int fd, struct map_session_data *sd)
*------------------------------------------
*/
static
-void clif_parse_TradeAddItem (int fd, struct map_session_data *sd)
+void clif_parse_TradeAddItem(int, struct map_session_data *sd)
{
- nullpo_retv (sd);
+ nullpo_retv(sd);
- trade_tradeadditem (sd, RFIFOW (sd->fd, 2), RFIFOL (sd->fd, 4));
+ trade_tradeadditem(sd, RFIFOW(sd->fd, 2), RFIFOL(sd->fd, 4));
}
/*==========================================
@@ -7940,9 +4667,9 @@ void clif_parse_TradeAddItem (int fd, struct map_session_data *sd)
*------------------------------------------
*/
static
-void clif_parse_TradeOk (int fd, struct map_session_data *sd)
+void clif_parse_TradeOk(int, struct map_session_data *sd)
{
- trade_tradeok (sd);
+ trade_tradeok(sd);
}
/*==========================================
@@ -7950,9 +4677,9 @@ void clif_parse_TradeOk (int fd, struct map_session_data *sd)
*------------------------------------------
*/
static
-void clif_parse_TradeCansel (int fd, struct map_session_data *sd)
+void clif_parse_TradeCansel(int, struct map_session_data *sd)
{
- trade_tradecancel (sd);
+ trade_tradecancel(sd);
}
/*==========================================
@@ -7960,9 +4687,9 @@ void clif_parse_TradeCansel (int fd, struct map_session_data *sd)
*------------------------------------------
*/
static
-void clif_parse_TradeCommit (int fd, struct map_session_data *sd)
+void clif_parse_TradeCommit(int, struct map_session_data *sd)
{
- trade_tradecommit (sd);
+ trade_tradecommit(sd);
}
/*==========================================
@@ -7970,72 +4697,9 @@ void clif_parse_TradeCommit (int fd, struct map_session_data *sd)
*------------------------------------------
*/
static
-void clif_parse_StopAttack (int fd, struct map_session_data *sd)
-{
- pc_stopattack (sd);
-}
-
-/*==========================================
- * カートã¸ã‚¢ã‚¤ãƒ†ãƒ ã‚’移ã™
- *------------------------------------------
- */
-static
-void clif_parse_PutItemToCart (int fd, struct map_session_data *sd)
-{
- nullpo_retv (sd);
-
- if (sd->npc_id != 0 || sd->trade_partner != 0)
- return;
- pc_putitemtocart (sd, RFIFOW (fd, 2) - 2, RFIFOL (fd, 4));
-}
-
-/*==========================================
- * カートã‹ã‚‰ã‚¢ã‚¤ãƒ†ãƒ ã‚’出ã™
- *------------------------------------------
- */
-static
-void clif_parse_GetItemFromCart (int fd, struct map_session_data *sd)
-{
- nullpo_retv (sd);
-
- if (sd->npc_id != 0 || sd->trade_partner != 0)
- return;
- pc_getitemfromcart (sd, RFIFOW (fd, 2) - 2, RFIFOL (fd, 4));
-}
-
-/*==========================================
- * 付属å“(é·¹,ペコ,カート)ã‚’ã¯ãšã™
- *------------------------------------------
- */
-static
-void clif_parse_RemoveOption (int fd, struct map_session_data *sd)
+void clif_parse_StopAttack(int, struct map_session_data *sd)
{
- if (pc_isriding (sd))
- { // jobchange when removing peco [Valaris]
- if (sd->status.pc_class == 13)
- sd->status.pc_class = sd->view_class = 7;
-
- if (sd->status.pc_class == 21)
- sd->status.pc_class = sd->view_class = 14;
-
- if (sd->status.pc_class == 4014)
- sd->status.pc_class = sd->view_class = 4008;
-
- if (sd->status.pc_class == 4022)
- sd->status.pc_class = sd->view_class = 4015;
- }
-
- pc_setoption (sd, 0);
-}
-
-/*==========================================
- * ãƒã‚§ãƒ³ã‚¸ã‚«ãƒ¼ãƒˆ
- *------------------------------------------
- */
-static
-void clif_parse_ChangeCart (int fd, struct map_session_data *sd)
-{
- pc_setcart (sd, RFIFOW (fd, 2));
+ pc_stopattack(sd);
}
/*==========================================
@@ -8043,9 +4707,9 @@ void clif_parse_ChangeCart (int fd, struct map_session_data *sd)
*------------------------------------------
*/
static
-void clif_parse_StatusUp (int fd, struct map_session_data *sd)
+void clif_parse_StatusUp(int fd, struct map_session_data *sd)
{
- pc_statusup (sd, RFIFOW (fd, 2));
+ pc_statusup(sd, SP(RFIFOW(fd, 2)));
}
/*==========================================
@@ -8053,196 +4717,9 @@ void clif_parse_StatusUp (int fd, struct map_session_data *sd)
*------------------------------------------
*/
static
-void clif_parse_SkillUp (int fd, struct map_session_data *sd)
+void clif_parse_SkillUp(int fd, struct map_session_data *sd)
{
- pc_skillup (sd, RFIFOW (fd, 2));
-}
-
-/*==========================================
- * スキル使用(ID指定)
- *------------------------------------------
- */
-static
-void clif_parse_UseSkillToId (int fd, struct map_session_data *sd)
-{
- int skillnum, skilllv, lv, target_id;
- unsigned int tick = gettick ();
-
- nullpo_retv (sd);
-
- if (map[sd->bl.m].flag.noskill)
- return;
- if (sd->chatID || sd->npc_id != 0 || sd->state.storage_flag)
- return;
-
- skilllv = RFIFOW (fd, 2);
- skillnum = RFIFOW (fd, 4);
- target_id = RFIFOL (fd, 6);
-
- if (sd->skilltimer != -1)
- {
- if (skillnum != SA_CASTCANCEL)
- return;
- }
- else if (DIFF_TICK (tick, sd->canact_tick) < 0)
- {
- clif_skill_fail (sd, skillnum, 4, 0);
- return;
- }
-
- if ((sd->sc_data[SC_TRICKDEAD].timer != -1 && skillnum != NV_TRICKDEAD) ||
- sd->sc_data[SC_BERSERK].timer != -1
- || sd->sc_data[SC_NOCHAT].timer != -1
- || sd->sc_data[SC_WEDDING].timer != -1 || sd->view_class == 22)
- return;
- if (sd->invincible_timer != -1)
- pc_delinvincibletimer (sd);
- if (sd->skillitem >= 0 && sd->skillitem == skillnum)
- {
- if (skilllv != sd->skillitemlv)
- skilllv = sd->skillitemlv;
- skill_use_id (sd, target_id, skillnum, skilllv);
- }
- else
- {
- sd->skillitem = sd->skillitemlv = -1;
- if (skillnum == MO_EXTREMITYFIST)
- {
- if ((sd->sc_data[SC_COMBO].timer == -1
- || (sd->sc_data[SC_COMBO].val1 != MO_COMBOFINISH
- && sd->sc_data[SC_COMBO].val1 != CH_CHAINCRUSH)))
- {
- if (!sd->state.skill_flag)
- {
- sd->state.skill_flag = 1;
- clif_skillinfo (sd, MO_EXTREMITYFIST, 1, -1);
- return;
- }
- else if (sd->bl.id == target_id)
- {
- clif_skillinfo (sd, MO_EXTREMITYFIST, 1, -1);
- return;
- }
- }
- }
- if ((lv = pc_checkskill (sd, skillnum)) > 0)
- {
- if (skilllv > lv)
- skilllv = lv;
- skill_use_id (sd, target_id, skillnum, skilllv);
- if (sd->state.skill_flag)
- sd->state.skill_flag = 0;
- }
- }
-}
-
-/*==========================================
- * スキル使用(場所指定)
- *------------------------------------------
- */
-static
-void clif_parse_UseSkillToPos (int fd, struct map_session_data *sd)
-{
- int skillnum, skilllv, lv, x, y;
- unsigned int tick = gettick ();
- int skillmoreinfo;
-
- nullpo_retv (sd);
-
- if (map[sd->bl.m].flag.noskill)
- return;
- if (sd->npc_id != 0 || sd->state.storage_flag)
- return;
- if (sd->chatID)
- return;
-
- skillmoreinfo = -1;
- skilllv = RFIFOW (fd, 2);
- skillnum = RFIFOW (fd, 4);
- x = RFIFOW (fd, 6);
- y = RFIFOW (fd, 8);
- if (RFIFOW (fd, 0) == 0x190)
- skillmoreinfo = 10;
-
- if (skillmoreinfo != -1)
- {
- if (pc_issit (sd))
- {
- clif_skill_fail (sd, skillnum, 0, 0);
- return;
- }
- memcpy (talkie_mes, RFIFOP (fd, skillmoreinfo), 80);
- }
-
- if (sd->skilltimer != -1)
- return;
- else if (DIFF_TICK (tick, sd->canact_tick) < 0)
- {
- clif_skill_fail (sd, skillnum, 4, 0);
- return;
- }
-
- if ((sd->sc_data[SC_TRICKDEAD].timer != -1 && skillnum != NV_TRICKDEAD) ||
- sd->sc_data[SC_BERSERK].timer != -1
- || sd->sc_data[SC_NOCHAT].timer != -1
- || sd->sc_data[SC_WEDDING].timer != -1 || sd->view_class == 22)
- return;
- if (sd->invincible_timer != -1)
- pc_delinvincibletimer (sd);
- if (sd->skillitem >= 0 && sd->skillitem == skillnum)
- {
- if (skilllv != sd->skillitemlv)
- skilllv = sd->skillitemlv;
- skill_use_pos (sd, x, y, skillnum, skilllv);
- }
- else
- {
- sd->skillitem = sd->skillitemlv = -1;
- if ((lv = pc_checkskill (sd, skillnum)) > 0)
- {
- if (skilllv > lv)
- skilllv = lv;
- skill_use_pos (sd, x, y, skillnum, skilllv);
- }
- }
-}
-
-/*==========================================
- * スキル使用(map指定)
- *------------------------------------------
- */
-static
-void clif_parse_UseSkillMap (int fd, struct map_session_data *sd)
-{
- nullpo_retv (sd);
-
- if (map[sd->bl.m].flag.noskill)
- return;
- if (sd->chatID)
- return;
-
- if (sd->npc_id != 0 || (sd->sc_data &&
- (sd->sc_data[SC_TRICKDEAD].timer != -1 ||
- sd->sc_data[SC_BERSERK].timer != -1 ||
- sd->sc_data[SC_NOCHAT].timer != -1 ||
- sd->sc_data[SC_WEDDING].timer != -1 ||
- sd->view_class == 22)))
- return;
-
- if (sd->invincible_timer != -1)
- pc_delinvincibletimer (sd);
-
- skill_castend_map (sd, RFIFOW (fd, 2), (const char *)RFIFOP (fd, 4));
-}
-
-/*==========================================
- * メモè¦æ±‚
- *------------------------------------------
- */
-static
-void clif_parse_RequestMemo (int fd, struct map_session_data *sd)
-{
- pc_memo (sd, -1);
+ pc_skillup(sd, SkillID(RFIFOW(fd, 2)));
}
/*==========================================
@@ -8250,12 +4727,12 @@ void clif_parse_RequestMemo (int fd, struct map_session_data *sd)
*------------------------------------------
*/
static
-void clif_parse_NpcSelectMenu (int fd, struct map_session_data *sd)
+void clif_parse_NpcSelectMenu(int fd, struct map_session_data *sd)
{
- nullpo_retv (sd);
+ nullpo_retv(sd);
- sd->npc_menu = RFIFOB (fd, 6);
- map_scriptcont (sd, RFIFOL (fd, 2));
+ sd->npc_menu = RFIFOB(fd, 6);
+ map_scriptcont(sd, RFIFOL(fd, 2));
}
/*==========================================
@@ -8263,9 +4740,9 @@ void clif_parse_NpcSelectMenu (int fd, struct map_session_data *sd)
*------------------------------------------
*/
static
-void clif_parse_NpcNextClicked (int fd, struct map_session_data *sd)
+void clif_parse_NpcNextClicked(int fd, struct map_session_data *sd)
{
- map_scriptcont (sd, RFIFOL (fd, 2));
+ map_scriptcont(sd, RFIFOL(fd, 2));
}
/*==========================================
@@ -8273,17 +4750,12 @@ void clif_parse_NpcNextClicked (int fd, struct map_session_data *sd)
*------------------------------------------
*/
static
-void clif_parse_NpcAmountInput (int fd, struct map_session_data *sd)
+void clif_parse_NpcAmountInput(int fd, struct map_session_data *sd)
{
- nullpo_retv (sd);
+ nullpo_retv(sd);
-#define RFIFOL_(fd,pos) (*(int*)(session[fd]->rdata+session[fd]->rdata_pos+(pos)))
- //Input Value overflow Exploit FIX
- sd->npc_amount = RFIFOL_ (fd, 6); //fixed by Lupus. npc_amount is (int) but was RFIFOL changing it to (unsigned int)
-
-#undef RFIFOL_
-
- map_scriptcont (sd, RFIFOL (fd, 2));
+ sd->npc_amount = RFIFOL(fd, 6);
+ map_scriptcont(sd, RFIFOL(fd, 2));
}
/*==========================================
@@ -8293,12 +4765,12 @@ void clif_parse_NpcAmountInput (int fd, struct map_session_data *sd)
*------------------------------------------
*/
static
-void clif_parse_NpcStringInput (int fd, struct map_session_data *sd)
+void clif_parse_NpcStringInput(int fd, struct map_session_data *sd)
{
- int len;
- nullpo_retv (sd);
+ int len;
+ nullpo_retv(sd);
- len = RFIFOW (fd, 2) - 8;
+ len = RFIFOW(fd, 2) - 8;
/*
* If we check for equal to 0, too, we'll freeze clients that send (or
@@ -8307,17 +4779,17 @@ void clif_parse_NpcStringInput (int fd, struct map_session_data *sd)
if (len < 0)
return;
- if (len >= sizeof (sd->npc_str) - 1)
+ if (len >= sizeof(sd->npc_str) - 1)
{
- printf ("clif_parse_NpcStringInput(): Input string too long!\n");
- len = sizeof (sd->npc_str) - 1;
+ PRINTF("clif_parse_NpcStringInput(): Input string too long!\n");
+ len = sizeof(sd->npc_str) - 1;
}
if (len > 0)
- strncpy (sd->npc_str, (const char *)RFIFOP (fd, 8), len);
+ strncpy(sd->npc_str, (const char *)RFIFOP(fd, 8), len);
sd->npc_str[len] = '\0';
- map_scriptcont (sd, RFIFOL (fd, 4));
+ map_scriptcont(sd, RFIFOL(fd, 4));
}
/*==========================================
@@ -8325,112 +4797,9 @@ void clif_parse_NpcStringInput (int fd, struct map_session_data *sd)
*------------------------------------------
*/
static
-void clif_parse_NpcCloseClicked (int fd, struct map_session_data *sd)
-{
- map_scriptcont (sd, RFIFOL (fd, 2));
-}
-
-/*==========================================
- * アイテム鑑定
- *------------------------------------------
- */
-static
-void clif_parse_ItemIdentify (int fd, struct map_session_data *sd)
-{
- pc_item_identify (sd, RFIFOW (fd, 2) - 2);
-}
-
-/*==========================================
- * オートスペルå—ä¿¡
- *------------------------------------------
- */
-static
-void clif_parse_AutoSpell (int fd, struct map_session_data *sd)
-{
- skill_autospell (sd, RFIFOW (fd, 2));
-}
-
-/*==========================================
- * カード使用
- *------------------------------------------
- */
-static
-void clif_parse_UseCard (int fd, struct map_session_data *sd)
-{
- clif_use_card (sd, RFIFOW (fd, 2) - 2);
-}
-
-/*==========================================
- * カード挿入装備é¸æŠž
- *------------------------------------------
- */
-static
-void clif_parse_InsertCard (int fd, struct map_session_data *sd)
-{
- pc_insert_card (sd, RFIFOW (fd, 2) - 2, RFIFOW (fd, 4) - 2);
-}
-
-/*==========================================
- * 0193 キャラIDåå‰å¼•ã
- *------------------------------------------
- */
-static
-void clif_parse_SolveCharName (int fd, struct map_session_data *sd)
-{
- int char_id;
-
- char_id = RFIFOL (fd, 2);
- clif_solved_charname (sd, char_id);
-}
-
-/*==========================================
- * 0197 /resetskill /resetstate
- *------------------------------------------
- */
-static
-void clif_parse_ResetChar (int fd, struct map_session_data *sd)
-{
- nullpo_retv (sd);
-
- if (battle_config.atc_gmonly == 0 || pc_isGM (sd))
- {
- switch (RFIFOW (fd, 2))
- {
- case 0:
- log_atcommand (sd, "@charstreset %s", sd->status.name);
- if (pc_isGM (sd) >=
- get_atcommand_level (AtCommand_ResetState))
- pc_resetstate (sd);
- break;
- case 1:
- log_atcommand (sd, "@charskreset %s", sd->status.name);
- if (pc_isGM (sd) >=
- get_atcommand_level (AtCommand_ResetState))
- pc_resetskill (sd);
- break;
- }
- }
-}
-
-/*==========================================
- * 019c /lbç­‰
- *------------------------------------------
- */
-static
-void clif_parse_LGMmessage (int fd, struct map_session_data *sd)
+void clif_parse_NpcCloseClicked(int fd, struct map_session_data *sd)
{
- unsigned char buf[64];
-
- nullpo_retv (sd);
-
- if ((battle_config.atc_gmonly == 0 || pc_isGM (sd)) &&
- (pc_isGM (sd) >= get_atcommand_level (AtCommand_LocalBroadcast)))
- {
- WBUFW (buf, 0) = 0x9a;
- WBUFW (buf, 2) = RFIFOW (fd, 2);
- memcpy (WBUFP (buf, 4), RFIFOP (fd, 4), RFIFOW (fd, 2) - 4);
- clif_send (buf, RFIFOW (fd, 2), &sd->bl, ALL_SAMEMAP);
- }
+ map_scriptcont(sd, RFIFOL(fd, 2));
}
/*==========================================
@@ -8438,23 +4807,21 @@ void clif_parse_LGMmessage (int fd, struct map_session_data *sd)
*------------------------------------------
*/
static
-void clif_parse_MoveToKafra (int fd, struct map_session_data *sd)
+void clif_parse_MoveToKafra(int fd, struct map_session_data *sd)
{
- int item_index, item_amount;
+ int item_index, item_amount;
- nullpo_retv (sd);
+ nullpo_retv(sd);
- item_index = RFIFOW (fd, 2) - 2;
- item_amount = RFIFOL (fd, 4);
+ item_index = RFIFOW(fd, 2) - 2;
+ item_amount = RFIFOL(fd, 4);
if ((sd->npc_id != 0 && !sd->npc_flags.storage) || sd->trade_partner != 0
- || !sd->state.storage_flag)
+ || !sd->state.storage_open)
return;
- if (sd->state.storage_flag == 1)
- storage_storageadd (sd, item_index, item_amount);
- else if (sd->state.storage_flag == 2)
- storage_guild_storageadd (sd, item_index, item_amount);
+ if (sd->state.storage_open)
+ storage_storageadd(sd, item_index, item_amount);
}
/*==========================================
@@ -8462,61 +4829,21 @@ void clif_parse_MoveToKafra (int fd, struct map_session_data *sd)
*------------------------------------------
*/
static
-void clif_parse_MoveFromKafra (int fd, struct map_session_data *sd)
+void clif_parse_MoveFromKafra(int fd, struct map_session_data *sd)
{
- int item_index, item_amount;
+ int item_index, item_amount;
- nullpo_retv (sd);
+ nullpo_retv(sd);
- item_index = RFIFOW (fd, 2) - 1;
- item_amount = RFIFOL (fd, 4);
+ item_index = RFIFOW(fd, 2) - 1;
+ item_amount = RFIFOL(fd, 4);
if ((sd->npc_id != 0 && !sd->npc_flags.storage) || sd->trade_partner != 0
- || !sd->state.storage_flag)
+ || !sd->state.storage_open)
return;
- if (sd->state.storage_flag == 1)
- storage_storageget (sd, item_index, item_amount);
- else if (sd->state.storage_flag == 2)
- storage_guild_storageget (sd, item_index, item_amount);
-}
-
-/*==========================================
- * カプラ倉庫ã¸ã‚«ãƒ¼ãƒˆã‹ã‚‰å…¥ã‚Œã‚‹
- *------------------------------------------
- */
-static
-void clif_parse_MoveToKafraFromCart (int fd, struct map_session_data *sd)
-{
- nullpo_retv (sd);
-
- if ((sd->npc_id != 0 && !sd->npc_flags.storage) || sd->trade_partner != 0
- || !sd->state.storage_flag)
- return;
- if (sd->state.storage_flag == 1)
- storage_storageaddfromcart (sd, RFIFOW (fd, 2) - 2, RFIFOL (fd, 4));
- else if (sd->state.storage_flag == 2)
- storage_guild_storageaddfromcart (sd, RFIFOW (fd, 2) - 2,
- RFIFOL (fd, 4));
-}
-
-/*==========================================
- * カプラ倉庫ã‹ã‚‰å‡ºã™
- *------------------------------------------
- */
-static
-void clif_parse_MoveFromKafraToCart (int fd, struct map_session_data *sd)
-{
- nullpo_retv (sd);
-
- if ((sd->npc_id != 0 && !sd->npc_flags.storage) || sd->trade_partner != 0
- || !sd->state.storage_flag)
- return;
- if (sd->state.storage_flag == 1)
- storage_storagegettocart (sd, RFIFOW (fd, 2) - 1, RFIFOL (fd, 4));
- else if (sd->state.storage_flag == 2)
- storage_guild_storagegettocart (sd, RFIFOW (fd, 2) - 1,
- RFIFOL (fd, 4));
+ if (sd->state.storage_open)
+ storage_storageget(sd, item_index, item_amount);
}
/*==========================================
@@ -8524,14 +4851,12 @@ void clif_parse_MoveFromKafraToCart (int fd, struct map_session_data *sd)
*------------------------------------------
*/
static
-void clif_parse_CloseKafra (int fd, struct map_session_data *sd)
+void clif_parse_CloseKafra(int, struct map_session_data *sd)
{
- nullpo_retv (sd);
+ nullpo_retv(sd);
- if (sd->state.storage_flag == 1)
- storage_storageclose (sd);
- else if (sd->state.storage_flag == 2)
- storage_guild_storageclose (sd);
+ if (sd->state.storage_open)
+ storage_storageclose(sd);
}
/*==========================================
@@ -8542,39 +4867,15 @@ void clif_parse_CloseKafra (int fd, struct map_session_data *sd)
*------------------------------------------
*/
static
-void clif_parse_CreateParty (int fd, struct map_session_data *sd)
-{
- if (battle_config.basic_skill_check == 0
- || pc_checkskill (sd, NV_PARTY) >= 2)
- {
- party_create (sd, (const char *)RFIFOP (fd, 2));
- }
- else
- clif_skill_fail (sd, 1, 0, 4);
-}
-
-/*==========================================
- * パーティを作る
- * Process request to create a party.
- *
- * (S 01e8 <party_name>.24B <exp>.B <itm>.B)
- *
- * Note: Upstream eAthena uses this to
- * specify experience/item sharing,
- * respectively, but it was left
- * incomplete here.
- *------------------------------------------
- */
-static
-void clif_parse_CreateParty2 (int fd, struct map_session_data *sd)
+void clif_parse_CreateParty(int fd, struct map_session_data *sd)
{
if (battle_config.basic_skill_check == 0
- || pc_checkskill (sd, NV_PARTY) >= 2)
+ || pc_checkskill(sd, SkillID::NV_PARTY) >= 2)
{
- party_create (sd, (const char *)RFIFOP (fd, 2));
+ party_create(sd, (const char *)RFIFOP(fd, 2));
}
else
- clif_skill_fail (sd, 1, 0, 4);
+ clif_skill_fail(sd, SkillID::ONE, 0, 4);
}
/*==========================================
@@ -8585,9 +4886,9 @@ void clif_parse_CreateParty2 (int fd, struct map_session_data *sd)
*------------------------------------------
*/
static
-void clif_parse_PartyInvite (int fd, struct map_session_data *sd)
+void clif_parse_PartyInvite(int fd, struct map_session_data *sd)
{
- party_invite (sd, RFIFOL (fd, 2));
+ party_invite(sd, RFIFOL(fd, 2));
}
/*==========================================
@@ -8598,17 +4899,17 @@ void clif_parse_PartyInvite (int fd, struct map_session_data *sd)
*------------------------------------------
*/
static
-void clif_parse_ReplyPartyInvite (int fd, struct map_session_data *sd)
+void clif_parse_ReplyPartyInvite(int fd, struct map_session_data *sd)
{
if (battle_config.basic_skill_check == 0
- || pc_checkskill (sd, NV_PARTY) >= 1)
+ || pc_checkskill(sd, SkillID::NV_PARTY) >= 1)
{
- party_reply_invite (sd, RFIFOL (fd, 2), RFIFOL (fd, 6));
+ party_reply_invite(sd, RFIFOL(fd, 2), RFIFOL(fd, 6));
}
else
{
- party_reply_invite (sd, RFIFOL (fd, 2), 0);
- clif_skill_fail (sd, 1, 0, 4);
+ party_reply_invite(sd, RFIFOL(fd, 2), 0);
+ clif_skill_fail(sd, SkillID::ONE, 0, 4);
}
}
@@ -8617,9 +4918,9 @@ void clif_parse_ReplyPartyInvite (int fd, struct map_session_data *sd)
*------------------------------------------
*/
static
-void clif_parse_LeaveParty (int fd, struct map_session_data *sd)
+void clif_parse_LeaveParty(int, struct map_session_data *sd)
{
- party_leave (sd);
+ party_leave(sd);
}
/*==========================================
@@ -8627,9 +4928,9 @@ void clif_parse_LeaveParty (int fd, struct map_session_data *sd)
*------------------------------------------
*/
static
-void clif_parse_RemovePartyMember (int fd, struct map_session_data *sd)
+void clif_parse_RemovePartyMember(int fd, struct map_session_data *sd)
{
- party_removemember (sd, RFIFOL (fd, 2), (const char *)RFIFOP (fd, 6));
+ party_removemember(sd, RFIFOL(fd, 2), (const char *)RFIFOP(fd, 6));
}
/*==========================================
@@ -8637,9 +4938,9 @@ void clif_parse_RemovePartyMember (int fd, struct map_session_data *sd)
*------------------------------------------
*/
static
-void clif_parse_PartyChangeOption (int fd, struct map_session_data *sd)
+void clif_parse_PartyChangeOption(int fd, struct map_session_data *sd)
{
- party_changeoption (sd, RFIFOW (fd, 2), RFIFOW (fd, 4));
+ party_changeoption(sd, RFIFOW(fd, 2), RFIFOW(fd, 4));
}
/*==========================================
@@ -8651,1381 +4952,646 @@ void clif_parse_PartyChangeOption (int fd, struct map_session_data *sd)
*------------------------------------------
*/
static
-void clif_parse_PartyMessage (int fd, struct map_session_data *sd)
-{
- size_t message_len = 0;
- char *buf = NULL;
- char *message = NULL; /* The message text only. */
-
- nullpo_retv (sd);
-
- if (!(buf = clif_validate_chat (sd, 0, &message, &message_len)))
- {
- clif_displaymessage (fd, "Your message could not be sent.");
- 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))) //ãƒãƒ£ãƒƒãƒˆç¦æ­¢
- {
- free (buf);
- return;
- }
-
- /* Don't send chat that results in an automatic ban. */
- if (tmw_CheckChatSpam (sd, message))
- {
- free (buf);
- clif_displaymessage (fd, "Your message could not be sent.");
- return;
- }
-
- party_send_message (sd, message, RFIFOW (fd, 2) - 4);
- free (buf);
-}
-
-/*==========================================
- * /monster /item rewriten by [Yor]
- *------------------------------------------
- */
-static
-void clif_parse_GM_Monster_Item (int fd, struct map_session_data *sd)
-{
- char monster_item_name[25];
-
- nullpo_retv (sd);
-
- memset (monster_item_name, '\0', sizeof (monster_item_name));
-
- if (battle_config.atc_gmonly == 0 || pc_isGM (sd))
- {
- memcpy (monster_item_name, RFIFOP (fd, 2), 24);
-
- if (mobdb_searchname (monster_item_name) != 0)
- {
- if (pc_isGM (sd) >= get_atcommand_level (AtCommand_Monster))
- {
- log_atcommand (sd, "@spawn %s", monster_item_name);
- atcommand_spawn (fd, sd, "@spawn", monster_item_name); // as @spawn
- }
- }
- else if (itemdb_searchname (monster_item_name) != NULL)
- {
- if (pc_isGM (sd) >= get_atcommand_level (AtCommand_Item))
- {
- log_atcommand (sd, "@item %s", monster_item_name);
- atcommand_item (fd, sd, "@item", monster_item_name); // as @item
- }
- }
-
- }
-}
-
-/*==========================================
- * ギルドを作る
- * Process request to create a guild.
- *
- * (S 0165 <account_ID>.l <guild_name>.24B)
- *
- * Note: The account ID seems to be ignored.
- *------------------------------------------
- */
-static
-void clif_parse_CreateGuild (int fd, struct map_session_data *sd)
-{
- guild_create (sd, (const char *)RFIFOP (fd, 6));
-}
-
-/*==========================================
- * ギルドマスターã‹ã©ã†ã‹ç¢ºèª
- *------------------------------------------
- */
-static
-void clif_parse_GuildCheckMaster (int fd, struct map_session_data *sd)
-{
- clif_guild_masterormember (sd);
-}
-
-/*==========================================
- * ギルド情報è¦æ±‚
- *------------------------------------------
- */
-static
-void clif_parse_GuildReqeustInfo (int fd, struct map_session_data *sd)
-{
- switch (RFIFOL (fd, 2))
- {
- case 0: // ギルド基本情報ã€åŒç›Ÿæ•µå¯¾æƒ…å ±
- clif_guild_basicinfo (sd);
- clif_guild_allianceinfo (sd);
- break;
- case 1: // メンãƒãƒ¼ãƒªã‚¹ãƒˆã€å½¹è·åリスト
- clif_guild_positionnamelist (sd);
- clif_guild_memberlist (sd);
- break;
- case 2: // å½¹è·åリストã€å½¹è·æƒ…報リスト
- clif_guild_positionnamelist (sd);
- clif_guild_positioninfolist (sd);
- break;
- case 3: // スキルリスト
- clif_guild_skillinfo (sd);
- break;
- case 4: // 追放リスト
- clif_guild_explusionlist (sd);
- break;
- default:
- if (battle_config.error_log)
- printf ("clif: guild request info: unknown type %d\n",
- RFIFOL (fd, 2));
- break;
- }
-}
-
-/*==========================================
- * ギルド役è·å¤‰æ›´
- *------------------------------------------
- */
-static
-void clif_parse_GuildChangePositionInfo (int fd, struct map_session_data *sd)
-{
- struct guild *g;
- int i, ps;
-
- nullpo_retv (sd);
-
- g = guild_search (sd->status.guild_id);
-
- if (g == NULL)
- return;
-
- if ((ps = guild_getposition (sd, g)) < 0
- || (!(g->position[ps].mode & 0x0010) && strcmp (g->master, sd->status.name)))
- return;
-
- for (i = 4; i < RFIFOW (fd, 2); i += 40)
- {
- guild_change_position (sd, RFIFOL (fd, i), RFIFOL (fd, i + 4),
- RFIFOL (fd, i + 12), (const char *)RFIFOP (fd, i + 16));
- }
-}
-
-/*==========================================
- * ギルドメンãƒå½¹è·å¤‰æ›´
- *------------------------------------------
- */
-static
-void clif_parse_GuildChangeMemberPosition (int fd,
- struct map_session_data *sd)
-{
- struct guild *g;
- int i, ps;
-
- nullpo_retv (sd);
-
- g = guild_search (sd->status.guild_id);
-
- if (g == NULL)
- return;
-
- if ((ps = guild_getposition (sd, g)) < 0
- || (!(g->position[ps].mode & 0x0010) && strcmp (g->master, sd->status.name)))
- return;
-
- for (i = 4; i < RFIFOW (fd, 2); i += 12)
- {
- guild_change_memberposition (sd->status.guild_id,
- RFIFOL (fd, i), RFIFOL (fd, i + 4),
- RFIFOL (fd, i + 8));
- }
-}
-
-/*==========================================
- * ギルドエンブレムè¦æ±‚
- *------------------------------------------
- */
-static
-void clif_parse_GuildRequestEmblem (int fd, struct map_session_data *sd)
-{
- struct guild *g = guild_search (RFIFOL (fd, 2));
- if (g != NULL)
- clif_guild_emblem (sd, g);
-}
-
-/*==========================================
- * ギルドエンブレム変更
- *------------------------------------------
- */
-static
-void clif_parse_GuildChangeEmblem (int fd, struct map_session_data *sd)
-{
- guild_change_emblem (sd, RFIFOW (fd, 2) - 4, (const char *)RFIFOP (fd, 4));
-}
-
-/*==========================================
- * ギルド告知変更
- *------------------------------------------
- */
-static
-void clif_parse_GuildChangeNotice (int fd, struct map_session_data *sd)
-{
- guild_change_notice (sd, RFIFOL (fd, 2), (const char *)RFIFOP (fd, 6), (const char *)RFIFOP (fd, 66));
-}
-
-/*==========================================
- * ギルド勧誘
- *------------------------------------------
- */
-static
-void clif_parse_GuildInvite (int fd, struct map_session_data *sd)
-{
- guild_invite (sd, RFIFOL (fd, 2));
-}
-
-/*==========================================
- * ギルド勧誘返信
- *------------------------------------------
- */
-static
-void clif_parse_GuildReplyInvite (int fd, struct map_session_data *sd)
-{
- guild_reply_invite (sd, RFIFOL (fd, 2), RFIFOB (fd, 6));
-}
-
-/*==========================================
- * ギルド脱退
- *------------------------------------------
- */
-static
-void clif_parse_GuildLeave (int fd, struct map_session_data *sd)
-{
- guild_leave (sd, RFIFOL (fd, 2), RFIFOL (fd, 6), RFIFOL (fd, 10),
- (const char *)RFIFOP (fd, 14));
-}
-
-/*==========================================
- * ギルド追放
- *------------------------------------------
- */
-static
-void clif_parse_GuildExplusion (int fd, struct map_session_data *sd)
-{
- guild_explusion (sd, RFIFOL (fd, 2), RFIFOL (fd, 6), RFIFOL (fd, 10),
- (const char *)RFIFOP (fd, 14));
-}
-
-/*==========================================
- * ギルド会話
- * Validate and process transmission of a
- * guild message.
- *
- * (S 017e <len>.w <message>.?B)
- *------------------------------------------
- */
-static
-void clif_parse_GuildMessage (int fd, struct map_session_data *sd)
+void clif_parse_PartyMessage(int fd, struct map_session_data *sd)
{
size_t message_len = 0;
char *buf = NULL;
- char *message = NULL; /* The message text only. */
+ const char *message = NULL; /* The message text only. */
- nullpo_retv (sd);
+ nullpo_retv(sd);
- if (!(buf = clif_validate_chat (sd, 2, &message, &message_len)))
+ if (!(buf = clif_validate_chat(sd, 0, &message, &message_len)))
{
- clif_displaymessage (fd, "Your message could not be sent.");
+ clif_displaymessage(fd, "Your message could not be sent.");
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))) //ãƒãƒ£ãƒƒãƒˆç¦æ­¢
+ if (is_atcommand(fd, sd, message, 0)) //ãƒãƒ£ãƒƒãƒˆç¦æ­¢
{
- free (buf);
+ free(buf);
return;
}
/* Don't send chat that results in an automatic ban. */
- if (tmw_CheckChatSpam (sd, message))
- {
- free (buf);
- clif_displaymessage (fd, "Your message could not be sent.");
- return;
- }
-
- guild_send_message (sd, buf + 8, RFIFOW (fd, 2) - 4);
- free (buf);
-}
-
-/*==========================================
- * ギルドåŒç›Ÿè¦æ±‚
- *------------------------------------------
- */
-static
-void clif_parse_GuildRequestAlliance (int fd, struct map_session_data *sd)
-{
- guild_reqalliance (sd, RFIFOL (fd, 2));
-}
-
-/*==========================================
- * ギルドåŒç›Ÿè¦æ±‚返信
- *------------------------------------------
- */
-static
-void clif_parse_GuildReplyAlliance (int fd, struct map_session_data *sd)
-{
- guild_reply_reqalliance (sd, RFIFOL (fd, 2), RFIFOL (fd, 6));
-}
-
-/*==========================================
- * ギルド関係解消
- *------------------------------------------
- */
-static
-void clif_parse_GuildDelAlliance (int fd, struct map_session_data *sd)
-{
- guild_delalliance (sd, RFIFOL (fd, 2), RFIFOL (fd, 6));
-}
-
-/*==========================================
- * ギルド敵対
- *------------------------------------------
- */
-static
-void clif_parse_GuildOpposition (int fd, struct map_session_data *sd)
-{
- guild_opposition (sd, RFIFOL (fd, 2));
-}
-
-/*==========================================
- * ギルド解散
- *------------------------------------------
- */
-static
-void clif_parse_GuildBreak (int fd, struct map_session_data *sd)
-{
- guild_break (sd, (const char *)RFIFOP (fd, 2));
-}
-
-// Kick (right click menu for GM "(name) force to quit")
-static
-void clif_parse_GMKick (int fd, struct map_session_data *sd)
-{
- struct block_list *target;
- int tid = RFIFOL (fd, 2);
-
- nullpo_retv (sd);
-
- if ((battle_config.atc_gmonly == 0 || pc_isGM (sd)) &&
- (pc_isGM (sd) >= get_atcommand_level (AtCommand_Kick)))
- {
- target = map_id2bl (tid);
- if (target)
- {
- if (target->type == BL_PC)
- {
- struct map_session_data *tsd =
- (struct map_session_data *) target;
- log_atcommand (sd, "@kick %s", tsd->status.name);
- if (pc_isGM (sd) > pc_isGM (tsd))
- clif_GM_kick (sd, tsd, 1);
- else
- clif_GM_kickack (sd, 0);
- }
- else if (target->type == BL_MOB)
- {
- struct mob_data *md = (struct mob_data *) target;
- sd->state.attack_type = 0;
- mob_damage (&sd->bl, md, md->hp, 2);
- }
- else
- clif_GM_kickack (sd, 0);
- }
- else
- clif_GM_kickack (sd, 0);
- }
-}
-
-/*==========================================
- * /shift
- *------------------------------------------
- */
-static
-void clif_parse_Shift (int fd, struct map_session_data *sd)
-{ // Rewriten by [Yor]
- char player_name[25];
-
- nullpo_retv (sd);
-
- memset (player_name, '\0', sizeof (player_name));
-
- if ((battle_config.atc_gmonly == 0 || pc_isGM (sd)) &&
- (pc_isGM (sd) >= get_atcommand_level (AtCommand_Goto)))
- {
- memcpy (player_name, RFIFOP (fd, 2), 24);
- log_atcommand (sd, "@goto %s", player_name);
- atcommand_goto (fd, sd, "@goto", player_name); // as @jumpto
- }
-
- return;
-}
-
-/*==========================================
- * /recall
- *------------------------------------------
- */
-static
-void clif_parse_Recall (int fd, struct map_session_data *sd)
-{ // Added by RoVeRT
- char player_name[25];
-
- nullpo_retv (sd);
-
- memset (player_name, '\0', sizeof (player_name));
-
- if ((battle_config.atc_gmonly == 0 || pc_isGM (sd)) &&
- (pc_isGM (sd) >= get_atcommand_level (AtCommand_Recall)))
- {
- memcpy (player_name, RFIFOP (fd, 2), 24);
- log_atcommand (sd, "@recall %s", player_name);
- atcommand_recall (fd, sd, "@recall", player_name); // as @recall
- }
-
- return;
-}
-
-static
-void clif_parse_GMHide (int fd, struct map_session_data *sd)
-{ // Modified by [Yor]
- nullpo_retv (sd);
-
- //printf("%2x %2x %2x\n", RFIFOW(fd,0), RFIFOW(fd,2), RFIFOW(fd,4)); // R 019d <Option_value>.2B <flag>.2B
- if ((battle_config.atc_gmonly == 0 || pc_isGM (sd)) &&
- (pc_isGM (sd) >= get_atcommand_level (AtCommand_Hide)))
+ if (tmw_CheckChatSpam(sd, message))
{
- log_atcommand (sd, "@hide");
- if (sd->status.option & OPTION_HIDE)
- { // OPTION_HIDE = 0x40
- sd->status.option &= ~OPTION_HIDE; // OPTION_HIDE = 0x40
- clif_displaymessage (fd, "Invisible: Off.");
- }
- else
- {
- sd->status.option |= OPTION_HIDE; // OPTION_HIDE = 0x40
- clif_displaymessage (fd, "Invisible: On.");
- }
- clif_changeoption (&sd->bl);
- }
-}
-
-/*==========================================
- * GMã«ã‚ˆã‚‹ãƒãƒ£ãƒƒãƒˆç¦æ­¢æ™‚間付与
- *------------------------------------------
- */
-static
-void clif_parse_GMReqNoChat (int fd, struct map_session_data *sd)
-{
- int tid = RFIFOL (fd, 2);
- int type = RFIFOB (fd, 6);
- int limit = RFIFOW (fd, 7);
- struct block_list *bl = map_id2bl (tid);
- struct map_session_data *dstsd;
- int dstfd;
-
- nullpo_retv (sd);
-
- if (!battle_config.muting_players)
- {
- clif_displaymessage (fd, "Muting is disabled.");
+ free(buf);
+ clif_displaymessage(fd, "Your message could not be sent.");
return;
}
- if (type == 0)
- limit = 0 - limit;
- if (bl->type == BL_PC && (dstsd = (struct map_session_data *) bl))
- {
- if ((tid == bl->id && type == 2 && !pc_isGM (sd))
- || (pc_isGM (sd) > pc_isGM (dstsd)))
- {
- dstfd = dstsd->fd;
- WFIFOW (dstfd, 0) = 0x14b;
- WFIFOB (dstfd, 2) = (type == 2) ? 1 : type;
- memcpy (WFIFOP (dstfd, 3), sd->status.name, 24);
- WFIFOSET (dstfd, packet_len_table[0x14b]);
- dstsd->status.manner -= limit;
- if (dstsd->status.manner < 0)
- skill_status_change_start (bl, SC_NOCHAT, 0, 0, 0, 0, 0, 0);
- else
- {
- dstsd->status.manner = 0;
- skill_status_change_end (bl, SC_NOCHAT, -1);
- }
- printf ("name:%s type:%d limit:%d manner:%d\n",
- dstsd->status.name, type, limit, dstsd->status.manner);
- }
- }
-
- return;
-}
-
-/*==========================================
- * GMã«ã‚ˆã‚‹ãƒãƒ£ãƒƒãƒˆç¦æ­¢æ™‚é–“å‚照(?)
- *------------------------------------------
- */
-static
-void clif_parse_GMReqNoChatCount (int fd, struct map_session_data *sd)
-{
- int tid = RFIFOL (fd, 2);
-
- WFIFOW (fd, 0) = 0x1e0;
- WFIFOL (fd, 2) = tid;
- sprintf ((char *)WFIFOP (fd, 6), "%d", tid);
-// memcpy(WFIFOP(fd,6),"TESTNAME",24);
- WFIFOSET (fd, packet_len_table[0x1e0]);
-
- return;
-}
-
-static
-void clif_parse_PMIgnore (int fd, struct map_session_data *sd)
-{ // Rewritten by [Yor]
- char output[1024];
- char *nick; // S 00cf <nick>.24B <type>.B: 00 (/ex nick) deny speech from nick, 01 (/in nick) allow speech from nick
- int i;
- int pos;
-
- memset (output, '\0', sizeof (output));
-
- nick = (char *)RFIFOP (fd, 2); // speed up
- //printf("Ignore: char '%s' state: %d\n", nick, RFIFOB(fd,26));
- // we ask for deny (we add nick only if it's not already exist
- if (RFIFOB (fd, 26) == 0)
- { // type
- if (strlen (nick) >= 4 && strlen (nick) < 24)
- { // do something only if nick can be exist
- pos = -1;
- for (i = 0; i < (sizeof (sd->ignore) / sizeof (sd->ignore[0]));
- i++)
- {
- if (strcmp (sd->ignore[i].name, nick) == 0)
- break;
- else if (pos == -1 && sd->ignore[i].name[0] == '\0')
- pos = i;
- }
- WFIFOW (fd, 0) = 0x0d1; // R 00d1 <type>.B <fail>.B: type: 0: deny, 1: allow, fail: 0: success, 1: fail
- WFIFOB (fd, 2) = 0;
- // if a position is found and name not found, we add it in the list
- if (pos != -1
- && i == (sizeof (sd->ignore) / sizeof (sd->ignore[0])))
- {
- memcpy (sd->ignore[pos].name, nick, 24);
- WFIFOB (fd, 3) = 0; // success
- WFIFOSET (fd, packet_len_table[0x0d1]);
- if (strcmp (wisp_server_name, nick) == 0)
- { // to found possible bot users that automaticaly ignores people.
- sprintf (output,
- "Character '%s' (account: %d) has tried to block wisps from '%s' (wisp name of the server). Bot user?",
- sd->status.name, sd->status.account_id,
- wisp_server_name);
- intif_wis_message_to_gm (wisp_server_name,
- battle_config.hack_info_GM_level,
- output, strlen (output) + 1);
- // send something to be inform and force bot to ignore twice... If GM receiving block + block again, it's a bot :)
- clif_wis_message (fd, wisp_server_name,
- "Add me in your ignore list, doesn't block my wisps.",
- strlen
- ("Add me in your ignore list, doesn't block my wisps.")
- + 1);
- }
- }
- else
- {
- WFIFOB (fd, 3) = 1; // fail
- if (i == (sizeof (sd->ignore) / sizeof (sd->ignore[0])))
- {
- clif_wis_message (fd, wisp_server_name,
- "You can not block more people.",
- strlen
- ("You can not block more people.") + 1);
- if (strcmp (wisp_server_name, nick) == 0)
- { // to found possible bot users that automaticaly ignores people.
- sprintf (output,
- "Character '%s' (account: %d) has tried to block wisps from '%s' (wisp name of the server). Bot user?",
- sd->status.name, sd->status.account_id,
- wisp_server_name);
- intif_wis_message_to_gm (wisp_server_name,
- battle_config.hack_info_GM_level,
- output, strlen (output) + 1);
- }
- }
- else
- {
- clif_wis_message (fd, wisp_server_name,
- "This player is already blocked.",
- strlen
- ("This player is already blocked.") +
- 1);
- if (strcmp (wisp_server_name, nick) == 0)
- { // to found possible bot users that automaticaly ignores people.
- sprintf (output,
- "Character '%s' (account: %d) has tried AGAIN to block wisps from '%s' (wisp name of the server). Bot user?",
- sd->status.name, sd->status.account_id,
- wisp_server_name);
- intif_wis_message_to_gm (wisp_server_name,
- battle_config.hack_info_GM_level,
- output, strlen (output) + 1);
- }
- }
- }
- }
- else
- clif_wis_message (fd, wisp_server_name,
- "It's impossible to block this player.",
- strlen ("It's impossible to block this player.")
- + 1);
- // we ask for allow (we remove all same nick if exist)
- }
- else
- {
- if (strlen (nick) >= 4 && strlen (nick) < 24)
- { // do something only if nick can be exist
- WFIFOW (fd, 0) = 0x0d1; // R 00d1 <type>.B <fail>.B: type: 0: deny, 1: allow, fail: 0: success, 1: fail
- WFIFOB (fd, 2) = 1;
- for (i = 0; i < (sizeof (sd->ignore) / sizeof (sd->ignore[0]));
- i++)
- if (strcmp (sd->ignore[i].name, nick) == 0)
- {
- memset (sd->ignore[i].name, 0,
- sizeof (sd->ignore[i].name));
- WFIFOB (fd, 3) = 0; // success
- WFIFOSET (fd, packet_len_table[0x0d1]);
- break;
- }
- if (i == (sizeof (sd->ignore) / sizeof (sd->ignore[0])))
- {
- WFIFOB (fd, 3) = 1; // fail
- WFIFOSET (fd, packet_len_table[0x0d1]);
- clif_wis_message (fd, wisp_server_name,
- "This player is not blocked by you.",
- strlen
- ("This player is not blocked by you.") + 1);
- }
- }
- else
- clif_wis_message (fd, wisp_server_name,
- "It's impossible to unblock this player.",
- strlen
- ("It's impossible to unblock this player.") +
- 1);
- }
-
-// for(i = 0; i < (sizeof(sd->ignore) / sizeof(sd->ignore[0])); i++) // for debug only
-// if (sd->ignore[i].name[0] != '\0')
-// printf("Ignored player: '%s'\n", sd->ignore[i].name);
-
- return;
+ party_send_message(sd, message, RFIFOW(fd, 2) - 4);
+ free(buf);
}
+// 4144 wants this, but I don't like it ...
static
-void clif_parse_PMIgnoreAll (int fd, struct map_session_data *sd)
+void clif_parse_PMIgnoreAll(int fd, struct map_session_data *sd)
{ // Rewritten by [Yor]
- //printf("Ignore all: state: %d\n", RFIFOB(fd,2));
- if (RFIFOB (fd, 2) == 0)
+ //PRINTF("Ignore all: state: %d\n", RFIFOB(fd,2));
+ if (RFIFOB(fd, 2) == 0)
{ // S 00d0 <type>len.B: 00 (/exall) deny all speech, 01 (/inall) allow all speech
- WFIFOW (fd, 0) = 0x0d2; // R 00d2 <type>.B <fail>.B: type: 0: deny, 1: allow, fail: 0: success, 1: fail
- WFIFOB (fd, 2) = 0;
+ WFIFOW(fd, 0) = 0x0d2; // R 00d2 <type>.B <fail>.B: type: 0: deny, 1: allow, fail: 0: success, 1: fail
+ WFIFOB(fd, 2) = 0;
if (sd->ignoreAll == 0)
{
sd->ignoreAll = 1;
- WFIFOB (fd, 3) = 0; // success
- WFIFOSET (fd, packet_len_table[0x0d2]);
+ WFIFOB(fd, 3) = 0; // success
+ WFIFOSET(fd, clif_parse_func_table[0x0d2].len);
}
else
{
- WFIFOB (fd, 3) = 1; // fail
- WFIFOSET (fd, packet_len_table[0x0d2]);
- clif_wis_message (fd, wisp_server_name,
+ WFIFOB(fd, 3) = 1; // fail
+ WFIFOSET(fd, clif_parse_func_table[0x0d2].len);
+ clif_wis_message(fd, wisp_server_name,
"You already block everyone.",
- strlen ("You already block everyone.") + 1);
+ strlen("You already block everyone.") + 1);
}
}
else
{
- WFIFOW (fd, 0) = 0x0d2; // R 00d2 <type>.B <fail>.B: type: 0: deny, 1: allow, fail: 0: success, 1: fail
- WFIFOB (fd, 2) = 1;
+ WFIFOW(fd, 0) = 0x0d2; // R 00d2 <type>.B <fail>.B: type: 0: deny, 1: allow, fail: 0: success, 1: fail
+ WFIFOB(fd, 2) = 1;
if (sd->ignoreAll == 1)
{
sd->ignoreAll = 0;
- WFIFOB (fd, 3) = 0; // success
- WFIFOSET (fd, packet_len_table[0x0d2]);
+ WFIFOB(fd, 3) = 0; // success
+ WFIFOSET(fd, clif_parse_func_table[0x0d2].len);
}
else
{
- WFIFOB (fd, 3) = 1; // fail
- WFIFOSET (fd, packet_len_table[0x0d2]);
- clif_wis_message (fd, wisp_server_name,
+ WFIFOB(fd, 3) = 1; // fail
+ WFIFOSET(fd, clif_parse_func_table[0x0d2].len);
+ clif_wis_message(fd, wisp_server_name,
"You already allow everyone.",
- strlen ("You already allow everyone.") + 1);
+ strlen("You already allow everyone.") + 1);
}
}
return;
}
-static
-void clif_parse_skillMessage (int fd, struct map_session_data *sd)
-{ // Added by RoVeRT
- int skillid, skilllv, x, y;
- char *mes;
-
- skilllv = RFIFOW (fd, 2);
- skillid = RFIFOW (fd, 4);
-
- y = RFIFOB (fd, 6);
- x = RFIFOB (fd, 8);
-
- mes = (char *)RFIFOP (fd, 10);
-
- // skill 220 = graffiti
-// printf("skill: %d %d location: %3d %3d message: %s\n", skillid, skilllv, x, y, (char*)mes);
-}
-
-static
-int monk (struct map_session_data *sd, struct block_list *target, int type)
-{
-//R 01d1 <Monk id>L <Target monster id>L <Bool>L
- int fd = sd->fd;
- WFIFOW (fd, 0) = 0x1d1;
- WFIFOL (fd, 2) = sd->bl.id;
- WFIFOL (fd, 6) = target->id;
- WFIFOL (fd, 10) = type;
- WFIFOSET (fd, packet_len_table[0x1d1]);
-
- return 0;
-}
-
-/*==========================================
- * スパノビã®/doridoriã«ã‚ˆã‚‹SPR2å€
- *------------------------------------------
- */
-static
-void clif_parse_sn_doridori (int fd, struct map_session_data *sd)
-{
- if (sd)
- sd->doridori_counter = 1;
-
- return;
-}
-
-/*==========================================
- * スパノビã®çˆ†è£‚波動
- *------------------------------------------
- */
-static
-void clif_parse_sn_explosionspirits (int fd, struct map_session_data *sd)
-{
- if (sd)
- {
- int nextbaseexp = pc_nextbaseexp (sd);
- struct pc_base_job s_class = pc_calc_base_job (sd->status.pc_class);
- if (battle_config.etc_log)
- {
- if (nextbaseexp != 0)
- printf ("SuperNovice explosionspirits!! %d %d %d %d\n",
- sd->bl.id, s_class.job, sd->status.base_exp,
- (int) ((double) 1000 * sd->status.base_exp /
- nextbaseexp));
- else
- printf ("SuperNovice explosionspirits!! %d %d %d 000\n",
- sd->bl.id, s_class.job, sd->status.base_exp);
- }
- if (s_class.job == 23 && sd->status.base_exp > 0 && nextbaseexp > 0
- && (int) ((double) 1000 * sd->status.base_exp / nextbaseexp) %
- 100 == 0)
- {
- clif_skill_nodamage (&sd->bl, &sd->bl, MO_EXPLOSIONSPIRITS, 5, 1);
- skill_status_change_start (&sd->bl,
- SkillStatusChangeTable
- [MO_EXPLOSIONSPIRITS], 5, 0, 0, 0,
- skill_get_time (MO_EXPLOSIONSPIRITS,
- 5), 0);
- }
- }
- return;
-}
-
-// functions list. Rate is how many milliseconds are required between
-// calls. Packets exceeding this rate will be dropped. flood_rates in
-// map.h must be the same length as this table. rate 0 is default
-// rate -1 is unlimited
-typedef struct func_table
-{
- void (*func)(int fd, struct map_session_data *sd);
- int rate;
-} func_table;
-// *INDENT-OFF*
-func_table clif_parse_func_table[0x220] =
-{
- { NULL, 0 }, // 0
- { NULL, 0 }, // 1
- { NULL, 0 }, // 2
- { NULL, 0 }, // 3
- { NULL, 0 }, // 4
- { NULL, 0 }, // 5
- { NULL, 0 }, // 6
- { NULL, 0 }, // 7
- { NULL, 0 }, // 8
- { NULL, 0 }, // 9
- { NULL, 0 }, // a
- { NULL, 0 }, // b
- { NULL, 0 }, // c
- { NULL, 0 }, // d
- { NULL, 0 }, // e
- { NULL, 0 }, // f
- { NULL, 0 }, // 10
- { NULL, 0 }, // 11
- { NULL, 0 }, // 12
- { NULL, 0 }, // 13
- { NULL, 0 }, // 14
- { NULL, 0 }, // 15
- { NULL, 0 }, // 16
- { NULL, 0 }, // 17
- { NULL, 0 }, // 18
- { NULL, 0 }, // 19
- { NULL, 0 }, // 1a
- { NULL, 0 }, // 1b
- { NULL, 0 }, // 1c
- { NULL, 0 }, // 1d
- { NULL, 0 }, // 1e
- { NULL, 0 }, // 1f
- { NULL, 0 }, // 20
- { NULL, 0 }, // 21
- { NULL, 0 }, // 22
- { NULL, 0 }, // 23
- { NULL, 0 }, // 24
- { NULL, 0 }, // 25
- { NULL, 0 }, // 26
- { NULL, 0 }, // 27
- { NULL, 0 }, // 28
- { NULL, 0 }, // 29
- { NULL, 0 }, // 2a
- { NULL, 0 }, // 2b
- { NULL, 0 }, // 2c
- { NULL, 0 }, // 2d
- { NULL, 0 }, // 2e
- { NULL, 0 }, // 2f
- { NULL, 0 }, // 30
- { NULL, 0 }, // 31
- { NULL, 0 }, // 32
- { NULL, 0 }, // 33
- { NULL, 0 }, // 34
- { NULL, 0 }, // 35
- { NULL, 0 }, // 36
- { NULL, 0 }, // 37
- { NULL, 0 }, // 38
- { NULL, 0 }, // 39
- { NULL, 0 }, // 3a
- { NULL, 0 }, // 3b
- { NULL, 0 }, // 3c
- { NULL, 0 }, // 3d
- { NULL, 0 }, // 3e
- { NULL, 0 }, // 3f
- { NULL, 0 }, // 40
- { NULL, 0 }, // 41
- { NULL, 0 }, // 42
- { NULL, 0 }, // 43
- { NULL, 0 }, // 44
- { NULL, 0 }, // 45
- { NULL, 0 }, // 46
- { NULL, 0 }, // 47
- { NULL, 0 }, // 48
- { NULL, 0 }, // 49
- { NULL, 0 }, // 4a
- { NULL, 0 }, // 4b
- { NULL, 0 }, // 4c
- { NULL, 0 }, // 4d
- { NULL, 0 }, // 4e
- { NULL, 0 }, // 4f
- { NULL, 0 }, // 50
- { NULL, 0 }, // 51
- { NULL, 0 }, // 52
- { NULL, 0 }, // 53
- { NULL, 0 }, // 54
- { NULL, 0 }, // 55
- { NULL, 0 }, // 56
- { NULL, 0 }, // 57
- { NULL, 0 }, // 58
- { NULL, 0 }, // 59
- { NULL, 0 }, // 5a
- { NULL, 0 }, // 5b
- { NULL, 0 }, // 5c
- { NULL, 0 }, // 5d
- { NULL, 0 }, // 5e
- { NULL, 0 }, // 5f
- { NULL, 0 }, // 60
- { NULL, 0 }, // 61
- { NULL, 0 }, // 62
- { NULL, 0 }, // 63
- { NULL, 0 }, // 64
- { NULL, 0 }, // 65
- { NULL, 0 }, // 66
- { NULL, 0 }, // 67
- { NULL, 0 }, // 68
- { NULL, 0 }, // 69
- { NULL, 0 }, // 6a
- { NULL, 0 }, // 6b
- { NULL, 0 }, // 6c
- { NULL, 0 }, // 6d
- { NULL, 0 }, // 6e
- { NULL, 0 }, // 6f
- { NULL, 0 }, // 70
- { NULL, 0 }, // 71
- { clif_parse_WantToConnection, 0 }, // 72
- { NULL, 0 }, // 73
- { NULL, 0 }, // 74
- { NULL, 0 }, // 75
- { NULL, 0 }, // 76
- { NULL, 0 }, // 77
- { NULL, 0 }, // 78
- { NULL, 0 }, // 79
- { NULL, 0 }, // 7a
- { NULL, 0 }, // 7b
- { NULL, 0 }, // 7c
- { clif_parse_LoadEndAck, -1 }, // 7d
- { clif_parse_TickSend, 0 }, // 7e
- { NULL, 0 }, // 7f
- { NULL, 0 }, // 80
- { NULL, 0 }, // 81
- { NULL, 0 }, // 82
- { NULL, 0 }, // 83
- { NULL, 0 }, // 84
- { clif_parse_WalkToXY, -1 }, // 85 Walk code limits this on it's own
- { NULL, 0 }, // 86
- { NULL, 0 }, // 87
- { NULL, 0 }, // 88
- { clif_parse_ActionRequest, 1000 }, // 89 Special case - see below
- { NULL, 0 }, // 8a
- { NULL, 0 }, // 8b
- { clif_parse_GlobalMessage, 300 }, // 8c
- { NULL, 0 }, // 8d
- { NULL, 0 }, // 8e
- { NULL, 0 }, // 8f
- { clif_parse_NpcClicked, 500 }, // 90
- { NULL, 0 }, // 91
- { NULL, 0 }, // 92
- { NULL, 0 }, // 93
- { clif_parse_GetCharNameRequest, -1 }, // 94
- { NULL, 0 }, // 95
- { clif_parse_Wis, 300 }, // 96
- { NULL, 0 }, // 97
- { NULL, 0 }, // 98
- { clif_parse_GMmessage, 300 }, // 99
- { NULL, 0 }, // 9a
- { clif_parse_ChangeDir, -1 }, // 9b
- { NULL, 0 }, // 9c
- { NULL, 0 }, // 9d
- { NULL, 0 }, // 9e
- { clif_parse_TakeItem, 400 }, // 9f
- { NULL, 0 }, // a0
- { NULL, 0 }, // a1
- { clif_parse_DropItem, 50 }, // a2
- { NULL, 0 }, // a3
- { NULL, 0 }, // a4
- { NULL, 0 }, // a5
- { NULL, 0 }, // a6
- { clif_parse_UseItem, 0 }, // a7
- { NULL, 0 }, // a8
- { clif_parse_EquipItem, -1 }, // a9 Special case - outfit window (not implemented yet - needs to allow bursts)
- { NULL, 0 }, // aa
- { clif_parse_UnequipItem, -1 }, // ab Special case - outfit window (not implemented yet - needs to allow bursts)
- { NULL, 0 }, // ac
- { NULL, 0 }, // ad
- { NULL, 0 }, // ae
- { NULL, 0 }, // af
- { NULL, 0 }, // b0
- { NULL, 0 }, // b1
- { clif_parse_Restart, 0 }, // b2
- { NULL, 0 }, // b3
- { NULL, 0 }, // b4
- { NULL, 0 }, // b5
- { NULL, 0 }, // b6
- { NULL, 0 }, // b7
- { clif_parse_NpcSelectMenu, 0 }, // b8
- { clif_parse_NpcNextClicked, -1 }, // b9
- { NULL, 0 }, // ba
- { clif_parse_StatusUp, -1 }, // bb People click this very quickly
- { NULL, 0 }, // bc
- { NULL, 0 }, // bd
- { NULL, 0 }, // be
- { clif_parse_Emotion, 1000 }, // bf
- { NULL, 0 }, // c0
- { clif_parse_HowManyConnections, 0 }, // c1
- { NULL, 0 }, // c2
- { NULL, 0 }, // c3
- { NULL, 0 }, // c4
- { clif_parse_NpcBuySellSelected, 0 }, // c5
- { NULL, 0 }, // c6
- { NULL, 0 }, // c7
- { clif_parse_NpcBuyListSend, -1 }, // c8
- { clif_parse_NpcSellListSend, -1 }, // c9 Selling multiple 1-slot items
- { NULL, 0 }, // ca
- { NULL, 0 }, // cb
- { clif_parse_GMKick, 0 }, // cc
- { NULL, 0 }, // cd
- { NULL, 0 }, // ce
- { clif_parse_PMIgnore, 0 }, // cf
- { clif_parse_PMIgnoreAll, 0 }, // d0
- { NULL, 0 }, // d1
- { NULL, 0 }, // d2
- { NULL, 0 }, // d3
- { NULL, 0 }, // d4
- { clif_parse_CreateChatRoom, 1000 }, // d5
- { NULL, 0 }, // d6
- { NULL, 0 }, // d7
- { NULL, 0 }, // d8
- { clif_parse_ChatAddMember, 0 }, // d9
- { NULL, 0 }, // da
- { NULL, 0 }, // db
- { NULL, 0 }, // dc
- { NULL, 0 }, // dd
- { clif_parse_ChatRoomStatusChange, 0 }, // de
- { NULL, 0 }, // df
- { clif_parse_ChangeChatOwner, 0 }, // e0
- { NULL, 0 }, // e1
- { clif_parse_KickFromChat, 0 }, // e2
- { clif_parse_ChatLeave, 0 }, // e3
- { clif_parse_TradeRequest, 2000 }, // e4
- { NULL, 0 }, // e5
- { clif_parse_TradeAck, 0 }, // e6
- { NULL, 0 }, // e7
- { clif_parse_TradeAddItem, 0 }, // e8
- { NULL, 0 }, // e9
- { NULL, 0 }, // ea
- { clif_parse_TradeOk, 0 }, // eb
- { NULL, 0 }, // ec
- { clif_parse_TradeCansel, 0 }, // ed
- { NULL, 0 }, // ee
- { clif_parse_TradeCommit, 0 }, // ef
- { NULL, 0 }, // f0
- { NULL, 0 }, // f1
- { NULL, 0 }, // f2
- { clif_parse_MoveToKafra, -1 }, // f3
- { NULL, 0 }, // f4
- { clif_parse_MoveFromKafra, -1 }, // f5
- { NULL, 0 }, // f6
- { clif_parse_CloseKafra, 0 }, // f7
- { NULL, 0 }, // f8
- { clif_parse_CreateParty, 2000 }, // f9
- { NULL, 0 }, // fa
- { NULL, 0 }, // fb
- { clif_parse_PartyInvite, 2000 }, // fc
- { NULL, 0 }, // fd
- { NULL, 0 }, // fe
- { clif_parse_ReplyPartyInvite, 0 }, // ff
- { clif_parse_LeaveParty, 0 }, // 100
- { NULL, 0 }, // 101
- { clif_parse_PartyChangeOption, 0 }, // 102
- { clif_parse_RemovePartyMember, 0 }, // 103
- { NULL, 0 }, // 104
- { NULL, 0 }, // 105
- { NULL, 0 }, // 106
- { NULL, 0 }, // 107
- { clif_parse_PartyMessage, 300 }, // 108
- { NULL, 0 }, // 109
- { NULL, 0 }, // 10a
- { NULL, 0 }, // 10b
- { NULL, 0 }, // 10c
- { NULL, 0 }, // 10d
- { NULL, 0 }, // 10e
- { NULL, 0 }, // 10f
- { NULL, 0 }, // 110
- { NULL, 0 }, // 111
- { clif_parse_SkillUp, -1 }, // 112
- { clif_parse_UseSkillToId, 0 }, // 113
- { NULL, 0 }, // 114
- { NULL, 0 }, // 115
- { clif_parse_UseSkillToPos, 0 }, // 116
- { NULL, 0 }, // 117
- { clif_parse_StopAttack, 0 }, // 118
- { NULL, 0 }, // 119
- { NULL, 0 }, // 11a
- { clif_parse_UseSkillMap, 0 }, // 11b
- { NULL, 0 }, // 11c
- { clif_parse_RequestMemo, 0 }, // 11d
- { NULL, 0 }, // 11e
- { NULL, 0 }, // 11f
- { NULL, 0 }, // 120
- { NULL, 0 }, // 121
- { NULL, 0 }, // 122
- { NULL, 0 }, // 123
- { NULL, 0 }, // 124
- { NULL, 0 }, // 125
- { clif_parse_PutItemToCart, 0 }, // 126
- { clif_parse_GetItemFromCart, 0 }, // 127
- { clif_parse_MoveFromKafraToCart, 0 }, // 128
- { clif_parse_MoveToKafraFromCart, 0 }, // 129
- { clif_parse_RemoveOption, 0 }, // 12a
- { NULL, 0 }, // 12b
- { NULL, 0 }, // 12c
- { NULL, 0 }, // 12d
- { NULL, 0 }, // 12e
- { NULL, 0 }, // 12f
- { NULL, 0 }, // 130
- { NULL, 0 }, // 131
- { NULL, 0 }, // 132
- { NULL, 0 }, // 133
- { NULL, 0 }, // 134
- { NULL, 0 }, // 135
- { NULL, 0 }, // 136
- { NULL, 0 }, // 137
- { NULL, 0 }, // 138
- { NULL, 0 }, // 139
- { NULL, 0 }, // 13a
- { NULL, 0 }, // 13b
- { NULL, 0 }, // 13c
- { NULL, 0 }, // 13d
- { NULL, 0 }, // 13e
- { clif_parse_GM_Monster_Item, 0 }, // 13f
- { clif_parse_MapMove, 0 }, // 140
- { NULL, 0 }, // 141
- { NULL, 0 }, // 142
- { clif_parse_NpcAmountInput, 300 }, // 143
- { NULL, 0 }, // 144
- { NULL, 0 }, // 145
- { clif_parse_NpcCloseClicked, 300 }, // 146
- { NULL, 0 }, // 147
- { NULL, 0 }, // 148
- { clif_parse_GMReqNoChat, 0 }, // 149
- { NULL, 0 }, // 14a
- { NULL, 0 }, // 14b
- { NULL, 0 }, // 14c
- { clif_parse_GuildCheckMaster, 0 }, // 14d
- { NULL, 0 }, // 14e
- { clif_parse_GuildReqeustInfo, 0 }, // 14f
- { NULL, 0 }, // 150
- { clif_parse_GuildRequestEmblem, 0 }, // 151
- { NULL, 0 }, // 152
- { clif_parse_GuildChangeEmblem, 0 }, // 153
- { NULL, 0 }, // 154
- { clif_parse_GuildChangeMemberPosition, 0 }, // 155
- { NULL, 0 }, // 156
- { NULL, 0 }, // 157
- { NULL, 0 }, // 158
- { clif_parse_GuildLeave, 0 }, // 159
- { NULL, 0 }, // 15a
- { clif_parse_GuildExplusion, 0 }, // 15b
- { NULL, 0 }, // 15c
- { clif_parse_GuildBreak, 0 }, // 15d
- { NULL, 0 }, // 15e
- { NULL, 0 }, // 15f
- { NULL, 0 }, // 160
- { clif_parse_GuildChangePositionInfo, 0 }, // 161
- { NULL, 0 }, // 162
- { NULL, 0 }, // 163
- { NULL, 0 }, // 164
- { clif_parse_CreateGuild, 0 }, // 165
- { NULL, 0 }, // 166
- { NULL, 0 }, // 167
- { clif_parse_GuildInvite, 2000 }, // 168
- { NULL, 0 }, // 169
- { NULL, 0 }, // 16a
- { clif_parse_GuildReplyInvite, 0 }, // 16b
- { NULL, 0 }, // 16c
- { NULL, 0 }, // 16d
- { clif_parse_GuildChangeNotice, 0 }, // 16e
- { NULL, 0 }, // 16f
- { clif_parse_GuildRequestAlliance, 0 }, // 170
- { NULL, 0 }, // 171
- { clif_parse_GuildReplyAlliance, 0 }, // 172
- { NULL, 0 }, // 173
- { NULL, 0 }, // 174
- { NULL, 0 }, // 175
- { NULL, 0 }, // 176
- { NULL, 0 }, // 177
- { clif_parse_ItemIdentify, 0 }, // 178
- { NULL, 0 }, // 179
- { clif_parse_UseCard, 0 }, // 17a
- { NULL, 0 }, // 17b
- { clif_parse_InsertCard, 0 }, // 17c
- { NULL, 0 }, // 17d
- { clif_parse_GuildMessage, 300 }, // 17e
- { NULL, 0 }, // 17f
- { clif_parse_GuildOpposition, 0 }, // 180
- { NULL, 0 }, // 181
- { NULL, 0 }, // 182
- { clif_parse_GuildDelAlliance, 0 }, // 183
- { NULL, 0 }, // 184
- { NULL, 0 }, // 185
- { NULL, 0 }, // 186
- { NULL, 0 }, // 187
- { NULL, 0 }, // 188
- { NULL, 0 }, // 189
- { clif_parse_QuitGame, 0 }, // 18a
- { NULL, 0 }, // 18b
- { NULL, 0 }, // 18c
- { NULL, 0 }, // 18d
- { NULL, 0 }, // 18e
- { NULL, 0 }, // 18f
- { clif_parse_UseSkillToPos, 0 }, // 190
- { NULL, 0 }, // 191
- { NULL, 0 }, // 192
- { clif_parse_SolveCharName, 0 }, // 193
- { NULL, 0 }, // 194
- { NULL, 0 }, // 195
- { NULL, 0 }, // 196
- { clif_parse_ResetChar, 0 }, // 197
- { NULL, 0 }, // 198
- { NULL, 0 }, // 199
- { NULL, 0 }, // 19a
- { NULL, 0 }, // 19b
- { clif_parse_LGMmessage, 0 }, // 19c
- { clif_parse_GMHide, 300 }, // 19d
- { NULL, 0 }, // 19e
- { NULL, 0 }, // 19f
- { NULL, 0 }, // 1a0
- { NULL, 0 }, // 1a1
- { NULL, 0 }, // 1a2
- { NULL, 0 }, // 1a3
- { NULL, 0 }, // 1a4
- { NULL, 0 }, // 1a5
- { NULL, 0 }, // 1a6
- { NULL, 0 }, // 1a7
- { NULL, 0 }, // 1a8
- { NULL, 0 }, // 1a9
- { NULL, 0 }, // 1aa
- { NULL, 0 }, // 1ab
- { NULL, 0 }, // 1ac
- { NULL, 0 }, // 1ad
- { NULL, 0 }, // 1ae
- { clif_parse_ChangeCart, 0 }, // 1af
- { NULL, 0 }, // 1b0
- { NULL, 0 }, // 1b1
- { NULL, 0 }, // 1b2
- { NULL, 0 }, // 1b3
- { NULL, 0 }, // 1b4
- { NULL, 0 }, // 1b5
- { NULL, 0 }, // 1b6
- { NULL, 0 }, // 1b7
- { NULL, 0 }, // 1b8
- { NULL, 0 }, // 1b9
- { clif_parse_Shift, 300 }, // 1ba
- { clif_parse_Shift, 300 }, // 1bb
- { clif_parse_Recall, 300 }, // 1bc
- { clif_parse_Recall, 300 }, // 1bd
- { NULL, 0 }, // 1be
- { NULL, 0 }, // 1bf
- { NULL, 0 }, // 1c0
- { NULL, 0 }, // 1c1
- { NULL, 0 }, // 1c2
- { NULL, 0 }, // 1c3
- { NULL, 0 }, // 1c4
- { NULL, 0 }, // 1c5
- { NULL, 0 }, // 1c6
- { NULL, 0 }, // 1c7
- { NULL, 0 }, // 1c8
- { NULL, 0 }, // 1c9
- { NULL, 0 }, // 1ca
- { NULL, 0 }, // 1cb
- { NULL, 0 }, // 1cc
- { NULL, 0 }, // 1cd
- { clif_parse_AutoSpell, 0 }, // 1ce
- { NULL, 0 }, // 1cf
- { NULL, 0 }, // 1d0
- { NULL, 0 }, // 1d1
- { NULL, 0 }, // 1d2
- { NULL, 0 }, // 1d3
- { NULL, 0 }, // 1d4
- { clif_parse_NpcStringInput, 300 }, // 1d5
- { NULL, 0 }, // 1d6
- { NULL, 0 }, // 1d7
- { NULL, 0 }, // 1d8
- { NULL, 0 }, // 1d9
- { NULL, 0 }, // 1da
- { NULL, 0 }, // 1db
- { NULL, 0 }, // 1dc
- { NULL, 0 }, // 1dd
- { NULL, 0 }, // 1de
- { clif_parse_GMReqNoChatCount, 0 }, // 1df
- { NULL, 0 }, // 1e0
- { NULL, 0 }, // 1e1
- { NULL, 0 }, // 1e2
- { NULL, 0 }, // 1e3
- { NULL, 0 }, // 1e4
- { NULL, 0 }, // 1e5
- { NULL, 0 }, // 1e6
- { clif_parse_sn_doridori, 0 }, // 1e7
- { clif_parse_CreateParty2, 1000 }, // 1e8
- { NULL, 0 }, // 1e9
- { NULL, 0 }, // 1ea
- { NULL, 0 }, // 1eb
- { NULL, 0 }, // 1ec
- { clif_parse_sn_explosionspirits, 0 }, // 1ed
- { NULL, 0 }, // 1ee
- { NULL, 0 }, // 1ef
- { NULL, 0 }, // 1f0
- { NULL, 0 }, // 1f1
- { NULL, 0 }, // 1f2
- { NULL, 0 }, // 1f3
- { NULL, 0 }, // 1f4
- { NULL, 0 }, // 1f5
- { NULL, 0 }, // 1f6
- { NULL, 0 }, // 1f7
- { NULL, 0 }, // 1f8
- { NULL, 0 }, // 1f9
- { NULL, 0 }, // 1fa
- { NULL, 0 }, // 1fb
- { NULL, 0 }, // 1fc
- { NULL, 0 }, // 1fd
- { NULL, 0 }, // 1fe
- { NULL, 0 }, // 1ff
- { NULL, 0 }, // 200
- { NULL, 0 }, // 201
- { NULL, 0 }, // 202
- { NULL, 0 }, // 203
- { NULL, 0 }, // 204
- { NULL, 0 }, // 205
- { NULL, 0 }, // 206
- { NULL, 0 }, // 207
- { NULL, 0 }, // 208
- { NULL, 0 }, // 209
- { NULL, 0 }, // 20a
- { NULL, 0 }, // 20b
- { NULL, 0 }, // 20c
- { NULL, 0 }, // 20d
- { NULL, 0 }, // 20e
- { NULL, 0 }, // 20f
- { NULL, 0 }, // 210
- { NULL, 0 }, // 211
- { NULL, 0 }, // 212
- { NULL, 0 }, // 213
- { NULL, 0 }, // 214
- { NULL, 0 }, // 215
- { NULL, 0 }, // 216
- { NULL, 0 }, // 217
- { NULL, 0 }, // 218
- { NULL, 0 }, // 219
- { NULL, 0 }, // 21a
- { NULL, 0 }, // 21b
- { NULL, 0 }, // 21c
- { NULL, 0 }, // 21d
- { NULL, 0 }, // 21e
- { NULL, 0 }, // 21f
+func_table clif_parse_func_table[0x0220] =
+{
+ {0, 10, NULL, }, // 0x0000
+ {0, 0, NULL, }, // 0x0001
+ {0, 0, NULL, }, // 0x0002
+ {0, 0, NULL, }, // 0x0003
+ {0, 0, NULL, }, // 0x0004
+ {0, 0, NULL, }, // 0x0005
+ {0, 0, NULL, }, // 0x0006
+ {0, 0, NULL, }, // 0x0007
+ {0, 0, NULL, }, // 0x0008
+ {0, 0, NULL, }, // 0x0009
+ {0, 0, NULL, }, // 0x000a
+ {0, 0, NULL, }, // 0x000b
+ {0, 0, NULL, }, // 0x000c
+ {0, 0, NULL, }, // 0x000d
+ {0, 0, NULL, }, // 0x000e
+ {0, 0, NULL, }, // 0x000f
+ {0, 0, NULL, }, // 0x0010
+ {0, 0, NULL, }, // 0x0011
+ {0, 0, NULL, }, // 0x0012
+ {0, 0, NULL, }, // 0x0013
+ {0, 0, NULL, }, // 0x0014
+ {0, 0, NULL, }, // 0x0015
+ {0, 0, NULL, }, // 0x0016
+ {0, 0, NULL, }, // 0x0017
+ {0, 0, NULL, }, // 0x0018
+ {0, 0, NULL, }, // 0x0019
+ {0, 0, NULL, }, // 0x001a
+ {0, 0, NULL, }, // 0x001b
+ {0, 0, NULL, }, // 0x001c
+ {0, 0, NULL, }, // 0x001d
+ {0, 0, NULL, }, // 0x001e
+ {0, 0, NULL, }, // 0x001f
+ {0, 0, NULL, }, // 0x0020
+ {0, 0, NULL, }, // 0x0021
+ {0, 0, NULL, }, // 0x0022
+ {0, 0, NULL, }, // 0x0023
+ {0, 0, NULL, }, // 0x0024
+ {0, 0, NULL, }, // 0x0025
+ {0, 0, NULL, }, // 0x0026
+ {0, 0, NULL, }, // 0x0027
+ {0, 0, NULL, }, // 0x0028
+ {0, 0, NULL, }, // 0x0029
+ {0, 0, NULL, }, // 0x002a
+ {0, 0, NULL, }, // 0x002b
+ {0, 0, NULL, }, // 0x002c
+ {0, 0, NULL, }, // 0x002d
+ {0, 0, NULL, }, // 0x002e
+ {0, 0, NULL, }, // 0x002f
+ {0, 0, NULL, }, // 0x0030
+ {0, 0, NULL, }, // 0x0031
+ {0, 0, NULL, }, // 0x0032
+ {0, 0, NULL, }, // 0x0033
+ {0, 0, NULL, }, // 0x0034
+ {0, 0, NULL, }, // 0x0035
+ {0, 0, NULL, }, // 0x0036
+ {0, 0, NULL, }, // 0x0037
+ {0, 0, NULL, }, // 0x0038
+ {0, 0, NULL, }, // 0x0039
+ {0, 0, NULL, }, // 0x003a
+ {0, 0, NULL, }, // 0x003b
+ {0, 0, NULL, }, // 0x003c
+ {0, 0, NULL, }, // 0x003d
+ {0, 0, NULL, }, // 0x003e
+ {0, 0, NULL, }, // 0x003f
+ {0, 0, NULL, }, // 0x0040
+ {0, 0, NULL, }, // 0x0041
+ {0, 0, NULL, }, // 0x0042
+ {0, 0, NULL, }, // 0x0043
+ {0, 0, NULL, }, // 0x0044
+ {0, 0, NULL, }, // 0x0045
+ {0, 0, NULL, }, // 0x0046
+ {0, 0, NULL, }, // 0x0047
+ {0, 0, NULL, }, // 0x0048
+ {0, 0, NULL, }, // 0x0049
+ {0, 0, NULL, }, // 0x004a
+ {0, 0, NULL, }, // 0x004b
+ {0, 0, NULL, }, // 0x004c
+ {0, 0, NULL, }, // 0x004d
+ {0, 0, NULL, }, // 0x004e
+ {0, 0, NULL, }, // 0x004f
+ {0, 0, NULL, }, // 0x0050
+ {0, 0, NULL, }, // 0x0051
+ {0, 0, NULL, }, // 0x0052
+ {0, 0, NULL, }, // 0x0053
+ {0, 0, NULL, }, // 0x0054
+ {0, 0, NULL, }, // 0x0055
+ {0, 0, NULL, }, // 0x0056
+ {0, 0, NULL, }, // 0x0057
+ {0, 0, NULL, }, // 0x0058
+ {0, 0, NULL, }, // 0x0059
+ {0, 0, NULL, }, // 0x005a
+ {0, 0, NULL, }, // 0x005b
+ {0, 0, NULL, }, // 0x005c
+ {0, 0, NULL, }, // 0x005d
+ {0, 0, NULL, }, // 0x005e
+ {0, 0, NULL, }, // 0x005f
+ {0, 0, NULL, }, // 0x0060
+ {0, 0, NULL, }, // 0x0061
+ {0, 0, NULL, }, // 0x0062
+ {0, VAR,NULL, }, // 0x0063
+ {0, 55, NULL, }, // 0x0064
+ {0, 17, NULL, }, // 0x0065
+ {0, 3, NULL, }, // 0x0066
+ {0, 37, NULL, }, // 0x0067
+ {0, 46, NULL, }, // 0x0068
+ {0, VAR,NULL, }, // 0x0069
+ {0, 23, NULL, }, // 0x006a
+ {0, VAR,NULL, }, // 0x006b
+ {0, 3, NULL, }, // 0x006c
+ {0, 108,NULL, }, // 0x006d
+ {0, 3, NULL, }, // 0x006e
+ {0, 2, NULL, }, // 0x006f
+ {0, 3, NULL, }, // 0x0070
+ {0, 28, NULL, }, // 0x0071
+ {0, 19, clif_parse_WantToConnection, }, // 0x0072
+ {0, 11, NULL, }, // 0x0073
+ {0, 3, NULL, }, // 0x0074
+ {0, VAR,NULL, }, // 0x0075
+ {0, 9, NULL, }, // 0x0076
+ {0, 5, NULL, }, // 0x0077
+ {0, 54, NULL, }, // 0x0078
+ {0, 53, NULL, }, // 0x0079
+ {0, 58, NULL, }, // 0x007a
+ {0, 60, NULL, }, // 0x007b
+ {0, 41, NULL, }, // 0x007c
+ {-1, 2, clif_parse_LoadEndAck, }, // 0x007d
+ {0, 6, clif_parse_TickSend, }, // 0x007e
+ {0, 6, NULL, }, // 0x007f
+ {0, 7, NULL, }, // 0x0080
+ {0, 3, NULL, }, // 0x0081
+ {0, 2, NULL, }, // 0x0082
+ {0, 2, NULL, }, // 0x0083
+ {0, 2, NULL, }, // 0x0084
+ {-1, 5, clif_parse_WalkToXY, }, // 0x0085 Walk code limits this on it's own
+ {0, 16, NULL, }, // 0x0086
+ {0, 12, NULL, }, // 0x0087
+ {0, 10, NULL, }, // 0x0088
+ {1000, 7, clif_parse_ActionRequest, }, // 0x0089 Special case - see below
+ {0, 29, NULL, }, // 0x008a
+ {0, 23, NULL, }, // 0x008b unknown... size 2 or 23?
+ {300, VAR,clif_parse_GlobalMessage, }, // 0x008c
+ {0, VAR,NULL, }, // 0x008d
+ {0, VAR,NULL, }, // 0x008e
+ {0, 0, NULL, }, // 0x008f
+ {500, 7, clif_parse_NpcClicked, }, // 0x0090
+ {0, 22, NULL, }, // 0x0091
+ {0, 28, NULL, }, // 0x0092
+ {0, 2, NULL, }, // 0x0093
+ {-1, 6, clif_parse_GetCharNameRequest, }, // 0x0094
+ {0, 30, NULL, }, // 0x0095
+ {300, VAR,clif_parse_Wis, }, // 0x0096
+ {0, VAR,NULL, }, // 0x0097
+ {0, 3, NULL, }, // 0x0098
+ {300, VAR,NULL, }, // 0x0099
+ {0, VAR,NULL, }, // 0x009a
+ {-1, 5, clif_parse_ChangeDir, }, // 0x009b
+ {0, 9, NULL, }, // 0x009c
+ {0, 17, NULL, }, // 0x009d
+ {0, 17, NULL, }, // 0x009e
+ {400, 6, clif_parse_TakeItem, }, // 0x009f
+ {0, 23, NULL, }, // 0x00a0
+ {0, 6, NULL, }, // 0x00a1
+ {50, 6, clif_parse_DropItem, }, // 0x00a2
+ {0, VAR,NULL, }, // 0x00a3
+ {0, VAR,NULL, }, // 0x00a4
+ {0, VAR,NULL, }, // 0x00a5
+ {0, VAR,NULL, }, // 0x00a6
+ {0, 8, clif_parse_UseItem, }, // 0x00a7
+ {0, 7, NULL, }, // 0x00a8
+ {-1, 6, clif_parse_EquipItem, }, // 0x00a9 Special case - outfit window (not implemented yet - needs to allow bursts)
+ {0, 7, NULL, }, // 0x00aa
+ {-1, 4, clif_parse_UnequipItem, }, // 0x00ab Special case - outfit window (not implemented yet - needs to allow bursts)
+ {0, 7, NULL, }, // 0x00ac
+ {0, 0, NULL, }, // 0x00ad
+ {0, VAR,NULL, }, // 0x00ae
+ {0, 6, NULL, }, // 0x00af
+ {0, 8, NULL, }, // 0x00b0
+ {0, 8, NULL, }, // 0x00b1
+ {0, 3, clif_parse_Restart, }, // 0x00b2
+ {0, 3, NULL, }, // 0x00b3
+ {0, VAR,NULL, }, // 0x00b4
+ {0, 6, NULL, }, // 0x00b5
+ {0, 6, NULL, }, // 0x00b6
+ {0, VAR,NULL, }, // 0x00b7
+ {0, 7, clif_parse_NpcSelectMenu, }, // 0x00b8
+ {-1, 6, clif_parse_NpcNextClicked, }, // 0x00b9
+ {0, 2, NULL, }, // 0x00ba
+ {-1, 5, clif_parse_StatusUp, }, // 0x00bb People click this very quickly
+ {0, 6, NULL, }, // 0x00bc
+ {0, 44, NULL, }, // 0x00bd
+ {0, 5, NULL, }, // 0x00be
+ {1000, 3, clif_parse_Emotion, }, // 0x00bf
+ {0, 7, NULL, }, // 0x00c0
+ {0, 2, clif_parse_HowManyConnections, }, // 0x00c1
+ {0, 6, NULL, }, // 0x00c2
+ {0, 8, NULL, }, // 0x00c3
+ {0, 6, NULL, }, // 0x00c4
+ {0, 7, clif_parse_NpcBuySellSelected, }, // 0x00c5
+ {0, VAR,NULL, }, // 0x00c6
+ {0, VAR,NULL, }, // 0x00c7
+ {-1, VAR,clif_parse_NpcBuyListSend, }, // 0x00c8
+ {-1, VAR,clif_parse_NpcSellListSend, }, // 0x00c9 Selling multiple 1-slot items
+ {0, 3, NULL, }, // 0x00ca
+ {0, 3, NULL, }, // 0x00cb
+ {0, 6, NULL, }, // 0x00cc
+ {0, 6, NULL, }, // 0x00cd
+ {0, 2, NULL, }, // 0x00ce
+ {0, 27, NULL, }, // 0x00cf
+ {0, 3, clif_parse_PMIgnoreAll, }, // 0x00d0
+ {0, 4, NULL, }, // 0x00d1
+ {0, 4, NULL, }, // 0x00d2
+ {0, 2, NULL, }, // 0x00d3
+ {0, VAR,NULL, }, // 0x00d4
+ {0, VAR,NULL, }, // 0x00d5
+ {0, 3, NULL, }, // 0x00d6
+ {0, VAR,NULL, }, // 0x00d7
+ {0, 6, NULL, }, // 0x00d8
+ {0, 14, NULL, }, // 0x00d9
+ {0, 3, NULL, }, // 0x00da
+ {0, VAR,NULL, }, // 0x00db
+ {0, 28, NULL, }, // 0x00dc
+ {0, 29, NULL, }, // 0x00dd
+ {0, VAR,NULL, }, // 0x00de
+ {0, VAR,NULL, }, // 0x00df
+ {0, 30, NULL, }, // 0x00e0
+ {0, 30, NULL, }, // 0x00e1
+ {0, 26, NULL, }, // 0x00e2
+ {0, 2, NULL, }, // 0x00e3
+ {2000, 6, clif_parse_TradeRequest, }, // 0x00e4
+ {0, 26, NULL, }, // 0x00e5
+ {0, 3, clif_parse_TradeAck, }, // 0x00e6
+ {0, 3, NULL, }, // 0x00e7
+ {0, 8, clif_parse_TradeAddItem, }, // 0x00e8
+ {0, 19, NULL, }, // 0x00e9
+ {0, 5, NULL, }, // 0x00ea
+ {0, 2, clif_parse_TradeOk, }, // 0x00eb
+ {0, 3, NULL, }, // 0x00ec
+ {0, 2, clif_parse_TradeCansel, }, // 0x00ed
+ {0, 2, NULL, }, // 0x00ee
+ {0, 2, clif_parse_TradeCommit, }, // 0x00ef
+ {0, 3, NULL, }, // 0x00f0
+ {0, 2, NULL, }, // 0x00f1
+ {0, 6, NULL, }, // 0x00f2
+ {-1, 8, clif_parse_MoveToKafra, }, // 0x00f3
+ {0, 21, NULL, }, // 0x00f4
+ {-1, 8, clif_parse_MoveFromKafra, }, // 0x00f5
+ {0, 8, NULL, }, // 0x00f6
+ {0, 2, clif_parse_CloseKafra, }, // 0x00f7
+ {0, 2, NULL, }, // 0x00f8
+ {2000, 26, clif_parse_CreateParty, }, // 0x00f9
+ {0, 3, NULL, }, // 0x00fa
+ {0, VAR,NULL, }, // 0x00fb
+ {2000, 6, clif_parse_PartyInvite, }, // 0x00fc
+ {0, 27, NULL, }, // 0x00fd
+ {0, 30, NULL, }, // 0x00fe
+ {0, 10, clif_parse_ReplyPartyInvite, }, // 0x00ff
+ {0, 2, clif_parse_LeaveParty, }, // 0x0100
+ {0, 6, NULL, }, // 0x0101
+ {0, 6, clif_parse_PartyChangeOption, }, // 0x0102
+ {0, 30, clif_parse_RemovePartyMember, }, // 0x0103
+ {0, 79, NULL, }, // 0x0104
+ {0, 31, NULL, }, // 0x0105
+ {0, 10, NULL, }, // 0x0106
+ {0, 10, NULL, }, // 0x0107
+ {300, VAR,clif_parse_PartyMessage, }, // 0x0108
+ {0, VAR,NULL, }, // 0x0109
+ {0, 4, NULL, }, // 0x010a
+ {0, 6, NULL, }, // 0x010b
+ {0, 6, NULL, }, // 0x010c
+ {0, 2, NULL, }, // 0x010d
+ {0, 11, NULL, }, // 0x010e
+ {0, VAR,NULL, }, // 0x010f
+ {0, 10, NULL, }, // 0x0110
+ {0, 39, NULL, }, // 0x0111
+ {-1, 4, clif_parse_SkillUp, }, // 0x0112
+ {0, 10, NULL, }, // 0x0113
+ {0, 31, NULL, }, // 0x0114
+ {0, 35, NULL, }, // 0x0115
+ {0, 10, NULL, }, // 0x0116
+ {0, 18, NULL, }, // 0x0117
+ {0, 2, clif_parse_StopAttack, }, // 0x0118
+ {0, 13, NULL, }, // 0x0119
+ {0, 15, NULL, }, // 0x011a
+ {0, 20, NULL, }, // 0x011b
+ {0, 68, NULL, }, // 0x011c
+ {0, 2, NULL, }, // 0x011d
+ {0, 3, NULL, }, // 0x011e
+ {0, 16, NULL, }, // 0x011f
+ {0, 6, NULL, }, // 0x0120
+ {0, 14, NULL, }, // 0x0121
+ {0, VAR,NULL, }, // 0x0122
+ {0, VAR,NULL, }, // 0x0123
+ {0, 21, NULL, }, // 0x0124
+ {0, 8, NULL, }, // 0x0125
+ {0, 8, NULL, }, // 0x0126
+ {0, 8, NULL, }, // 0x0127
+ {0, 8, NULL, }, // 0x0128
+ {0, 8, NULL, }, // 0x0129
+ {0, 2, NULL, }, // 0x012a
+ {0, 2, NULL, }, // 0x012b
+ {0, 3, NULL, }, // 0x012c
+ {0, 4, NULL, }, // 0x012d
+ {0, 2, NULL, }, // 0x012e
+ {0, VAR,NULL, }, // 0x012f
+ {0, 6, NULL, }, // 0x0130
+ {0, 86, NULL, }, // 0x0131
+ {0, 6, NULL, }, // 0x0132
+ {0, VAR,NULL, }, // 0x0133
+ {0, VAR,NULL, }, // 0x0134
+ {0, 7, NULL, }, // 0x0135
+ {0, VAR,NULL, }, // 0x0136
+ {0, 6, NULL, }, // 0x0137
+ {0, 3, NULL, }, // 0x0138
+ {0, 16, NULL, }, // 0x0139
+ {0, 4, NULL, }, // 0x013a
+ {0, 4, NULL, }, // 0x013b
+ {0, 4, NULL, }, // 0x013c
+ {0, 6, NULL, }, // 0x013d
+ {0, 24, NULL, }, // 0x013e
+ {0, 26, NULL, }, // 0x013f
+ {0, 22, NULL, }, // 0x0140
+ {0, 14, NULL, }, // 0x0141
+ {0, 6, NULL, }, // 0x0142
+ {300, 10, clif_parse_NpcAmountInput, }, // 0x0143
+ {0, 23, NULL, }, // 0x0144
+ {0, 19, NULL, }, // 0x0145
+ {300, 6, clif_parse_NpcCloseClicked, }, // 0x0146
+ {0, 39, NULL, }, // 0x0147
+ {0, 8, NULL, }, // 0x0148
+ {0, 9, NULL, }, // 0x0149
+ {0, 6, NULL, }, // 0x014a
+ {0, 27, NULL, }, // 0x014b
+ {0, VAR,NULL, }, // 0x014c
+ {0, 2, NULL, }, // 0x014d
+ {0, 6, NULL, }, // 0x014e
+ {0, 6, NULL, }, // 0x014f
+ {0, 110,NULL, }, // 0x0150
+ {0, 6, NULL, }, // 0x0151
+ {0, VAR,NULL, }, // 0x0152
+ {0, VAR,NULL, }, // 0x0153
+ {0, VAR,NULL, }, // 0x0154
+ {0, VAR,NULL, }, // 0x0155
+ {0, VAR,NULL, }, // 0x0156
+ {0, 6, NULL, }, // 0x0157
+ {0, VAR,NULL, }, // 0x0158
+ {0, 54, NULL, }, // 0x0159
+ {0, 66, NULL, }, // 0x015a
+ {0, 54, NULL, }, // 0x015b
+ {0, 90, NULL, }, // 0x015c
+ {0, 42, NULL, }, // 0x015d
+ {0, 6, NULL, }, // 0x015e
+ {0, 42, NULL, }, // 0x015f
+ {0, VAR,NULL, }, // 0x0160
+ {0, VAR,NULL, }, // 0x0161
+ {0, VAR,NULL, }, // 0x0162
+ {0, VAR,NULL, }, // 0x0163
+ {0, VAR,NULL, }, // 0x0164
+ {0, 30, NULL, }, // 0x0165
+ {0, VAR,NULL, }, // 0x0166
+ {0, 3, NULL, }, // 0x0167
+ {0, 14, NULL, }, // 0x0168
+ {0, 3, NULL, }, // 0x0169
+ {0, 30, NULL, }, // 0x016a
+ {0, 10, NULL, }, // 0x016b
+ {0, 43, NULL, }, // 0x016c
+ {0, 14, NULL, }, // 0x016d
+ {0, 186,NULL, }, // 0x016e
+ {0, 182,NULL, }, // 0x016f
+ {0, 14, NULL, }, // 0x0170
+ {0, 30, NULL, }, // 0x0171
+ {0, 10, NULL, }, // 0x0172
+ {0, 3, NULL, }, // 0x0173
+ {0, VAR,NULL, }, // 0x0174
+ {0, 6, NULL, }, // 0x0175
+ {0, 106,NULL, }, // 0x0176
+ {0, VAR,NULL, }, // 0x0177
+ {0, 4, NULL, }, // 0x0178
+ {0, 5, NULL, }, // 0x0179
+ {0, 4, NULL, }, // 0x017a
+ {0, VAR,NULL, }, // 0x017b
+ {0, 6, NULL, }, // 0x017c
+ {0, 7, NULL, }, // 0x017d
+ {0, VAR,NULL, }, // 0x017e
+ {0, VAR,NULL, }, // 0x017f
+ {0, 6, NULL, }, // 0x0180
+ {0, 3, NULL, }, // 0x0181
+ {0, 106,NULL, }, // 0x0182
+ {0, 10, NULL, }, // 0x0183
+ {0, 10, NULL, }, // 0x0184
+ {0, 34, NULL, }, // 0x0185
+ {0, 0, NULL, }, // 0x0186
+ {0, 6, NULL, }, // 0x0187
+ {0, 8, NULL, }, // 0x0188
+ {0, 4, NULL, }, // 0x0189
+ {0, 4, clif_parse_QuitGame, }, // 0x018a
+ {0, 4, NULL, }, // 0x018b
+ {0, 29, NULL, }, // 0x018c
+ {0, VAR,NULL, }, // 0x018d
+ {0, 10, NULL, }, // 0x018e
+ {0, 6, NULL, }, // 0x018f
+ {0, 90, NULL, }, // 0x0190
+ {0, 86, NULL, }, // 0x0191
+ {0, 24, NULL, }, // 0x0192
+ {0, 6, NULL, }, // 0x0193
+ {0, 30, NULL, }, // 0x0194
+ {0, 102,NULL, }, // 0x0195
+ {0, 9, NULL, }, // 0x0196
+ {0, 4, NULL, }, // 0x0197
+ {0, 8, NULL, }, // 0x0198
+ {0, 4, NULL, }, // 0x0199
+ {0, 14, NULL, }, // 0x019a
+ {0, 10, NULL, }, // 0x019b
+ {0, VAR,NULL, }, // 0x019c
+ {300, 6, NULL, }, // 0x019d
+ {0, 2, NULL, }, // 0x019e
+ {0, 6, NULL, }, // 0x019f
+ {0, 3, NULL, }, // 0x01a0
+ {0, 3, NULL, }, // 0x01a1
+ {0, 35, NULL, }, // 0x01a2
+ {0, 5, NULL, }, // 0x01a3
+ {0, 11, NULL, }, // 0x01a4
+ {0, 26, NULL, }, // 0x01a5
+ {0, VAR,NULL, }, // 0x01a6
+ {0, 4, NULL, }, // 0x01a7
+ {0, 4, NULL, }, // 0x01a8
+ {0, 6, NULL, }, // 0x01a9
+ {0, 10, NULL, }, // 0x01aa
+ {0, 12, NULL, }, // 0x01ab
+ {0, 6, NULL, }, // 0x01ac
+ {0, VAR,NULL, }, // 0x01ad
+ {0, 4, NULL, }, // 0x01ae
+ {0, 4, NULL, }, // 0x01af
+ {0, 11, NULL, }, // 0x01b0
+ {0, 7, NULL, }, // 0x01b1
+ {0, VAR,NULL, }, // 0x01b2
+ {0, 67, NULL, }, // 0x01b3
+ {0, 12, NULL, }, // 0x01b4
+ {0, 18, NULL, }, // 0x01b5
+ {0, 114,NULL, }, // 0x01b6
+ {0, 6, NULL, }, // 0x01b7
+ {0, 3, NULL, }, // 0x01b8
+ {0, 6, NULL, }, // 0x01b9
+ {0, 26, NULL, }, // 0x01ba
+ {0, 26, NULL, }, // 0x01bb
+ {0, 26, NULL, }, // 0x01bc
+ {0, 26, NULL, }, // 0x01bd
+ {0, 2, NULL, }, // 0x01be
+ {0, 3, NULL, }, // 0x01bf
+ {0, 2, NULL, }, // 0x01c0
+ {0, 14, NULL, }, // 0x01c1
+ {0, 10, NULL, }, // 0x01c2
+ {0, VAR,NULL, }, // 0x01c3
+ {0, 22, NULL, }, // 0x01c4
+ {0, 22, NULL, }, // 0x01c5
+ {0, 4, NULL, }, // 0x01c6
+ {0, 2, NULL, }, // 0x01c7
+ {0, 13, NULL, }, // 0x01c8
+ {0, 97, NULL, }, // 0x01c9
+ {0, 0, NULL, }, // 0x01ca
+ {0, 9, NULL, }, // 0x01cb
+ {0, 9, NULL, }, // 0x01cc
+ {0, 30, NULL, }, // 0x01cd
+ {0, 6, NULL, }, // 0x01ce
+ {0, 28, NULL, }, // 0x01cf
+ {0, 8, NULL, }, // 0x01d0
+ {0, 14, NULL, }, // 0x01d1
+ {0, 10, NULL, }, // 0x01d2
+ {0, 35, NULL, }, // 0x01d3
+ {0, 6, NULL, }, // 0x01d4
+ {300, VAR,clif_parse_NpcStringInput, }, // 0x01d5 - set to -1
+ {0, 4, NULL, }, // 0x01d6
+ {0, 11, NULL, }, // 0x01d7
+ {0, 54, NULL, }, // 0x01d8
+ {0, 53, NULL, }, // 0x01d9
+ {0, 60, NULL, }, // 0x01da
+ {0, 2, NULL, }, // 0x01db
+ {0, VAR,NULL, }, // 0x01dc
+ {0, 47, NULL, }, // 0x01dd
+ {0, 33, NULL, }, // 0x01de
+ {0, 6, NULL, }, // 0x01df
+ {0, 30, NULL, }, // 0x01e0
+ {0, 8, NULL, }, // 0x01e1
+ {0, 34, NULL, }, // 0x01e2
+ {0, 14, NULL, }, // 0x01e3
+ {0, 2, NULL, }, // 0x01e4
+ {0, 6, NULL, }, // 0x01e5
+ {0, 26, NULL, }, // 0x01e6
+ {0, 2, NULL, }, // 0x01e7
+ {0, 28, NULL, }, // 0x01e8
+ {0, 81, NULL, }, // 0x01e9
+ {0, 6, NULL, }, // 0x01ea
+ {0, 10, NULL, }, // 0x01eb
+ {0, 26, NULL, }, // 0x01ec
+ {0, 2, NULL, }, // 0x01ed
+ {0, VAR,NULL, }, // 0x01ee
+ {0, VAR,NULL, }, // 0x01ef
+ {0, VAR,NULL, }, // 0x01f0
+ {0, VAR,NULL, }, // 0x01f1
+ {0, 20, NULL, }, // 0x01f2
+ {0, 10, NULL, }, // 0x01f3
+ {0, 32, NULL, }, // 0x01f4
+ {0, 9, NULL, }, // 0x01f5
+ {0, 34, NULL, }, // 0x01f6
+ {0, 14, NULL, }, // 0x01f7
+ {0, 2, NULL, }, // 0x01f8
+ {0, 6, NULL, }, // 0x01f9
+ {0, 48, NULL, }, // 0x01fa
+ {0, 56, NULL, }, // 0x01fb
+ {0, VAR,NULL, }, // 0x01fc
+ {0, 4, NULL, }, // 0x01fd
+ {0, 5, NULL, }, // 0x01fe
+ {0, 10, NULL, }, // 0x01ff
+ {0, 26, NULL, }, // 0x0200
+ {0, VAR,NULL, }, // 0x0201
+ {0, 26, NULL, }, // 0x0202
+ {0, 10, NULL, }, // 0x0203
+ {0, 18, NULL, }, // 0x0204
+ {0, 26, NULL, }, // 0x0205
+ {0, 11, NULL, }, // 0x0206
+ {0, 34, NULL, }, // 0x0207
+ {0, 14, NULL, }, // 0x0208
+ {0, 36, NULL, }, // 0x0209
+ {0, 10, NULL, }, // 0x020a
+ {0, 19, NULL, }, // 0x020b
+ {0, 10, NULL, }, // 0x020c
+ {0, VAR,NULL, }, // 0x020d
+ {0, 24, NULL, }, // 0x020e
+ {0, 0, NULL, }, // 0x020f
+ {0, 0, NULL, }, // 0x0210
+ {0, 0, NULL, }, // 0x0211
+ {0, 0, NULL, }, // 0x0212
+ {0, 0, NULL, }, // 0x0213
+ {0, 0, NULL, }, // 0x0214
+ {0, 0, NULL, }, // 0x0215
+ {0, 0, NULL, }, // 0x0216
+ {0, 0, NULL, }, // 0x0217
+ {0, 0, NULL, }, // 0x0218
+ {0, 0, NULL, }, // 0x0219
+ {0, 0, NULL, }, // 0x021a
+ {0, 0, NULL, }, // 0x021b
+ {0, 0, NULL, }, // 0x021c
+ {0, 0, NULL, }, // 0x021d
+ {0, 0, NULL, }, // 0x021e
+ {0, 0, NULL, }, // 0x021f
};
-// *INDENT-ON*
// Checks for packet flooding
static
int clif_check_packet_flood(int fd, int cmd)
{
struct map_session_data *sd = (struct map_session_data *)session[fd]->session_data;
- unsigned int rate, tick = gettick();
+ tick_t tick = gettick();
// sd will not be set if the client hasn't requested
// WantToConnection yet. Do not apply flood logic to GMs
// as approved bots (GMlvl1) should not have to work around
// flood logic.
- if (!sd || pc_isGM(sd) || clif_parse_func_table[cmd].rate == -1)
- return 0;
+ if (!sd || pc_isGM(sd) || clif_parse_func_table[cmd].rate == static_cast<interval_t>(-1))
+ return 0;
// Timer has wrapped
if (tick < sd->flood_rates[cmd])
@@ -10035,17 +5601,18 @@ int clif_check_packet_flood(int fd, int cmd)
}
// Default rate is 100ms
- if ((rate = clif_parse_func_table[cmd].rate) == 0)
- rate = 100;
+ interval_t rate = clif_parse_func_table[cmd].rate;
+ if (rate == interval_t::zero())
+ rate = std::chrono::milliseconds(100);
// ActionRequest - attacks are allowed a faster rate than sit/stand
if (cmd == 0x89)
{
- int action_type = RFIFOB (fd, 6);
+ int action_type = RFIFOB(fd, 6);
if (action_type == 0x00 || action_type == 0x07)
- rate = 20;
+ rate = std::chrono::milliseconds(20);
else
- rate = 1000;
+ rate = std::chrono::seconds(1);
}
// Restore this code when mana1.0 is released
@@ -10064,12 +5631,12 @@ int clif_check_packet_flood(int fd, int cmd)
// They are flooding
if (tick < sd->flood_rates[cmd] + rate)
{
- time_t now = time(NULL);
+ TimeT now = TimeT::now();
// If it's a nasty flood we log and possibly kick
if (now > sd->packet_flood_reset_due)
{
- sd->packet_flood_reset_due = now + battle_config.packet_spam_threshold;
+ sd->packet_flood_reset_due = static_cast<time_t>(now) + battle_config.packet_spam_threshold;
sd->packet_flood_in = 0;
}
@@ -10077,7 +5644,7 @@ int clif_check_packet_flood(int fd, int cmd)
if (sd->packet_flood_in >= battle_config.packet_spam_flood)
{
- printf("packet flood detected from %s [0x%x]\n", sd->status.name, cmd);
+ PRINTF("packet flood detected from %s [0x%x]\n", sd->status.name, cmd);
if (battle_config.packet_spam_kick)
{
session[fd]->eof = 1; // Kick
@@ -10093,9 +5660,12 @@ int clif_check_packet_flood(int fd, int cmd)
return 0;
}
-#define WARN_MALFORMED_MSG(sd, msg) \
- printf ("clif_validate_chat(): %s (ID %d) sent a malformed" \
- " message: %s.\n", sd->status.name, sd->status.account_id, msg)
+inline
+void WARN_MALFORMED_MSG(struct map_session_data *sd, const char *msg)
+{
+ PRINTF("clif_validate_chat(): %s (ID %d) sent a malformed message: %s.\n",
+ sd->status.name, sd->status.account_id, msg);
+}
/**
* Validate message integrity (inspired by upstream source (eAthena)).
*
@@ -10108,8 +5678,9 @@ int clif_check_packet_flood(int fd, int cmd)
* @param[out] message_len the length of the actual text, excluding NUL
* @return a dynamically allocated copy of the message, or NULL upon failure
*/
-static char *clif_validate_chat (struct map_session_data *sd, int type,
- char **message, size_t *message_len)
+static
+char *clif_validate_chat(struct map_session_data *sd, int type,
+ const char **message, size_t *message_len)
{
int fd;
unsigned int buf_len; /* Actual message length. */
@@ -10117,12 +5688,11 @@ static char *clif_validate_chat (struct map_session_data *sd, int type,
unsigned int min_len; /* Minimum message length. */
size_t name_len; /* Sender's name length. */
char *buf = NULL; /* Copy of actual message data. */
- char *p = NULL; /* Temporary pointer to message. */
*message = NULL;
*message_len = 0;
- nullpo_retr (NULL, sd);
+ nullpo_retr(NULL, sd);
/*
* Don't send chat in the period between the ban and the connection's
* closure.
@@ -10131,8 +5701,8 @@ static char *clif_validate_chat (struct map_session_data *sd, int type,
return NULL;
fd = sd->fd;
- msg_len = RFIFOW (fd, 2) - 4;
- name_len = strlen (sd->status.name);
+ 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:
@@ -10148,14 +5718,14 @@ static char *clif_validate_chat (struct map_session_data *sd, int type,
/* The player just sent the header (2) and length (2) words. */
if (!msg_len)
{
- WARN_MALFORMED_MSG (sd, "no message sent");
+ WARN_MALFORMED_MSG(sd, "no message sent");
return NULL;
}
/* The client sent (or claims to have sent) an empty message. */
if (msg_len == min_len)
{
- WARN_MALFORMED_MSG (sd, "empty message");
+ WARN_MALFORMED_MSG(sd, "empty message");
return NULL;
}
@@ -10163,12 +5733,12 @@ static char *clif_validate_chat (struct map_session_data *sd, int type,
if (type == 1 && msg_len < min_len)
{
/* Disallow malformed messages. */
- clif_setwaitclose (fd);
- WARN_MALFORMED_MSG (sd, "illegal target name");
+ clif_setwaitclose(fd);
+ WARN_MALFORMED_MSG(sd, "illegal target name");
return NULL;
}
- p = (char *) ((type != 1) ? RFIFOP (fd, 4) : RFIFOP (fd, 28));
+ const char *p = static_cast<const char *>((type != 1) ? RFIFOP(fd, 4) : RFIFOP(fd, 28));
buf_len = (type == 1) ? msg_len - min_len: msg_len;
/*
@@ -10180,15 +5750,15 @@ static char *clif_validate_chat (struct map_session_data *sd, int type,
*/
if (buf_len >= battle_config.chat_maxline)
{
- WARN_MALFORMED_MSG (sd, "exceeded maximum message length");
+ WARN_MALFORMED_MSG(sd, "exceeded maximum message length");
return NULL;
}
/* We're leaving an extra eight bytes for public/global chat, 1 for NUL. */
buf_len += (type == 2) ? 8 + 1 : 1;
- buf = (char *) malloc (buf_len);
- memcpy ((type != 2) ? buf : buf + 8, p,
+ 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';
p = (type != 2) ? buf : buf + 8;
@@ -10201,15 +5771,15 @@ static char *clif_validate_chat (struct map_session_data *sd, int type,
}
else
{
- char *pos = NULL;
+ const char *pos = NULL;
if (!(pos = strstr(p, " : "))
- || strncmp (p, sd->status.name, name_len)
+ || strncmp(p, sd->status.name, name_len)
|| pos - p != name_len)
{
- free (buf);
+ free(buf);
/* Disallow malformed/spoofed messages. */
- clif_setwaitclose (fd);
- WARN_MALFORMED_MSG (sd, "spoofed name/invalid format");
+ clif_setwaitclose(fd);
+ WARN_MALFORMED_MSG(sd, "spoofed name/invalid format");
return NULL;
}
/* Step beyond the separator. */
@@ -10226,51 +5796,50 @@ static char *clif_validate_chat (struct map_session_data *sd, int type,
* socket.cã®do_parsepacketã‹ã‚‰å‘¼ã³å‡ºã•ã‚Œã‚‹
*------------------------------------------
*/
-static void clif_parse (int fd)
+static
+void clif_parse(int fd)
{
- int packet_len = 0, cmd = 0;
+ int packet_len = 0, cmd = 0;
struct map_session_data *sd = (struct map_session_data *)session[fd]->session_data;
if (!sd || (sd && !sd->state.auth))
{
- if (RFIFOREST (fd) < 2)
+ if (RFIFOREST(fd) < 2)
{ // too small a packet disconnect
session[fd]->eof = 1;
}
- if (RFIFOW (fd, 0) != 0x72)
+ if (RFIFOW(fd, 0) != 0x72)
{ // first packet not auth, disconnect
session[fd]->eof = 1;
}
}
// 接続ãŒåˆ‡ã‚Œã¦ã‚‹ã®ã§å¾Œå§‹æœ«
- if (!chrif_isconnect () || session[fd]->eof)
+ if (!chrif_isconnect() || session[fd]->eof)
{ // char鯖ã«ç¹‹ãŒã£ã¦ãªã„é–“ã¯æŽ¥ç¶šç¦æ­¢ (!chrif_isconnect())
if (sd && sd->state.auth)
{
- pc_logout (sd);
- clif_quitsave (fd, sd);
+ pc_logout(sd);
+ clif_quitsave(fd, sd);
if (sd->status.name != NULL)
- printf ("Player [%s] has logged off your server.\n", sd->status.name); // Player logout display [Valaris]
+ PRINTF("Player [%s] has logged off your server.\n", sd->status.name); // Player logout display [Valaris]
else
- printf ("Player with account [%d] has logged off your server.\n", sd->bl.id); // Player logout display [Yor]
+ PRINTF("Player with account [%d] has logged off your server.\n", sd->bl.id); // Player logout display [Yor]
}
else if (sd)
{ // not authentified! (refused by char-server or disconnect before to be authentified)
- printf ("Player with account [%d] has logged off your server (not auth account).\n", sd->bl.id); // Player logout display [Yor]
- map_deliddb (&sd->bl); // account_id has been included in the DB before auth answer
+ PRINTF("Player with account [%d] has logged off your server (not auth account).\n", sd->bl.id); // Player logout display [Yor]
+ map_deliddb(&sd->bl); // account_id has been included in the DB before auth answer
}
if (fd)
- close (fd);
- if (fd)
- delete_session (fd);
+ delete_session(fd);
return;
}
- if (RFIFOREST (fd) < 2)
+ if (RFIFOREST(fd) < 2)
return; // Too small (no packet number)
- cmd = RFIFOW (fd, 0);
+ cmd = RFIFOW(fd, 0);
// 管ç†ç”¨ãƒ‘ケット処ç†
if (cmd >= 30000)
@@ -10278,16 +5847,16 @@ static void clif_parse (int fd)
switch (cmd)
{
case 0x7530: // Athena情報所得
- 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_MAP;
- WFIFOW (fd, 8) = ATHENA_MOD_VERSION;
- WFIFOSET (fd, 10);
- RFIFOSKIP (fd, 2);
+ 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_MAP;
+ WFIFOW(fd, 8) = ATHENA_MOD_VERSION;
+ WFIFOSET(fd, 10);
+ RFIFOSKIP(fd, 2);
break;
case 0x7532: // 接続ã®åˆ‡æ–­
session[fd]->eof = 1;
@@ -10299,14 +5868,14 @@ static void clif_parse (int fd)
return;
// パケット長を計算
- packet_len = packet_len_table[cmd];
- if (packet_len == -1)
+ packet_len = clif_parse_func_table[cmd].len;
+ if (packet_len == VAR)
{
- if (RFIFOREST (fd) < 4)
+ if (RFIFOREST(fd) < 4)
{
return; // Runt packet (variable length without a length sent)
}
- packet_len = RFIFOW (fd, 2);
+ packet_len = RFIFOW(fd, 2);
if (packet_len < 4 || packet_len > 32768)
{
session[fd]->eof = 1;
@@ -10314,7 +5883,7 @@ static void clif_parse (int fd)
}
}
- if (RFIFOREST (fd) < packet_len)
+ if (RFIFOREST(fd) < packet_len)
{
return; // Runt packet (sent legnth is too small)
}
@@ -10332,7 +5901,7 @@ static void clif_parse (int fd)
return;
}
- clif_parse_func_table[cmd].func (fd, sd);
+ clif_parse_func_table[cmd].func(fd, sd);
}
else
{
@@ -10340,78 +5909,76 @@ static void clif_parse (int fd)
if (battle_config.error_log)
{
if (fd)
- printf ("\nclif_parse: session #%d, packet 0x%x, lenght %d\n",
+ PRINTF("\nclif_parse: session #%d, packet 0x%x, lenght %d\n",
fd, cmd, packet_len);
#ifdef DUMP_UNKNOWN_PACKET
{
- int i;
+ int i;
FILE *fp;
char packet_txt[256] = "save/packet.txt";
- time_t now;
- printf
- ("---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F");
+ PRINTF("---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F");
for (i = 0; i < packet_len; i++)
{
if ((i & 15) == 0)
- printf ("\n%04X ", i);
- printf ("%02X ", RFIFOB (fd, i));
+ PRINTF("\n%04X ", i);
+ PRINTF("%02X ", RFIFOB(fd, i));
}
if (sd && sd->state.auth)
{
if (sd->status.name != NULL)
- printf
- ("\nAccount ID %d, character ID %d, player name %s.\n",
+ PRINTF("\nAccount ID %d, character ID %d, player name %s.\n",
sd->status.account_id, sd->status.char_id,
sd->status.name);
else
- printf ("\nAccount ID %d.\n", sd->bl.id);
+ PRINTF("\nAccount ID %d.\n", sd->bl.id);
}
else if (sd) // not authentified! (refused by char-server or disconnect before to be authentified)
- printf ("\nAccount ID %d.\n", sd->bl.id);
+ PRINTF("\nAccount ID %d.\n", sd->bl.id);
- if ((fp = fopen_ (packet_txt, "a")) == NULL)
+ if ((fp = fopen_(packet_txt, "a")) == NULL)
{
- printf ("clif.c: cant write [%s] !!! data is lost !!!\n",
+ PRINTF("clif.c: cant write [%s] !!! data is lost !!!\n",
packet_txt);
return;
}
else
{
- time (&now);
+ timestamp_seconds_buffer now;
+ stamp_time(now);
if (sd && sd->state.auth)
{
if (sd->status.name != NULL)
- fprintf (fp,
- "%sPlayer with account ID %d (character ID %d, player name %s) sent wrong packet:\n",
- asctime (gmtime (&now)),
- sd->status.account_id,
- sd->status.char_id, sd->status.name);
+ FPRINTF(fp,
+ "%s\nPlayer with account ID %d (character ID %d, player name %s) sent wrong packet:\n",
+ now,
+ sd->status.account_id,
+ sd->status.char_id, sd->status.name);
else
- fprintf (fp,
- "%sPlayer with account ID %d sent wrong packet:\n",
- asctime (gmtime (&now)), sd->bl.id);
+ FPRINTF(fp,
+ "%s\nPlayer with account ID %d sent wrong packet:\n",
+ now, sd->bl.id);
}
else if (sd) // not authentified! (refused by char-server or disconnect before to be authentified)
- fprintf (fp,
- "%sPlayer with account ID %d sent wrong packet:\n",
- asctime (gmtime (&now)), sd->bl.id);
+ FPRINTF(fp,
+ "%s\nPlayer with account ID %d sent wrong packet:\n",
+ now, sd->bl.id);
- fprintf (fp,
+ FPRINTF(fp,
"\t---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F");
for (i = 0; i < packet_len; i++)
{
if ((i & 15) == 0)
- fprintf (fp, "\n\t%04X ", i);
- fprintf (fp, "%02X ", RFIFOB (fd, i));
+ FPRINTF(fp, "\n\t%04X ", i);
+ FPRINTF(fp, "%02X ", RFIFOB(fd, i));
}
- fprintf (fp, "\n\n");
- fclose_ (fp);
+ FPRINTF(fp, "\n\n");
+ fclose_(fp);
}
}
#endif
}
}
- RFIFOSKIP (fd, packet_len);
+ RFIFOSKIP(fd, packet_len);
}
/*==========================================
@@ -10420,24 +5987,8 @@ static void clif_parse (int fd)
*/
int do_init_clif (void)
{
- int i;
-
- set_defaultparse (clif_parse);
- for (i = 0; i < 10; i++)
- {
- if (make_listen_port (map_port))
- break;
-#ifdef LCCWIN32
- Sleep (20000);
-#else
- sleep (20);
-#endif
- }
- if (i == 10)
- {
- printf ("cant bind game port\n");
- exit (1);
- }
+ set_defaultparse(clif_parse);
+ make_listen_port(map_port);
return 0;
}
diff --git a/src/map/clif.hpp b/src/map/clif.hpp
index 01f6a50..df0a48b 100644
--- a/src/map/clif.hpp
+++ b/src/map/clif.hpp
@@ -1,280 +1,164 @@
-// $Id: clif.h,v 1.4 2004/09/25 05:32:18 MouseJstr Exp $
#ifndef CLIF_HPP
#define CLIF_HPP
-#include <sys/types.h>
-
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-
-#include "map.hpp"
-
-void clif_setip (const char *);
-void clif_setport (int);
-
-struct in_addr clif_getip (void);
-int clif_getport (void);
-int clif_countusers (void);
-void clif_setwaitclose (int);
-
-int clif_authok (struct map_session_data *);
-int clif_authfail_fd (int, int);
-int clif_charselectok (int);
-int clif_dropflooritem (struct flooritem_data *);
-int clif_clearflooritem (struct flooritem_data *, int);
-int clif_clearchar (struct block_list *, int); // area or fd
-int clif_clearchar_delay (unsigned int, struct block_list *, int);
-#define clif_clearchar_area(bl,type) clif_clearchar(bl,type)
-int clif_clearchar_id (int, int, int);
-int clif_spawnpc (struct map_session_data *); //area
-int clif_spawnnpc (struct npc_data *); // area
-int clif_spawn_fake_npc_for_player (struct map_session_data *sd,
- int fake_npc_id);
-int clif_spawnmob (struct mob_data *); // area
-int clif_walkok (struct map_session_data *); // self
-int clif_movechar (struct map_session_data *); // area
-int clif_movemob (struct mob_data *); //area
-int clif_changemap (struct map_session_data *, const char *, int, int); //self
-int clif_changemapserver (struct map_session_data *, const char *, int, int, struct in_addr, int); //self
-int clif_fixpos (struct block_list *); // area
-int clif_fixmobpos (struct mob_data *md);
-int clif_fixpcpos (struct map_session_data *sd);
-int clif_npcbuysell (struct map_session_data *, int); //self
-int clif_buylist (struct map_session_data *, struct npc_data *); //self
-int clif_selllist (struct map_session_data *); //self
-int clif_scriptmes (struct map_session_data *, int, const char *); //self
-int clif_scriptnext (struct map_session_data *, int); //self
-int clif_scriptclose (struct map_session_data *, int); //self
-int clif_scriptmenu (struct map_session_data *, int, const char *); //self
-int clif_scriptinput (struct map_session_data *, int); //self
-int clif_scriptinputstr (struct map_session_data *sd, int npcid); // self
-int clif_cutin (struct map_session_data *, const char *, int); //self
-int clif_viewpoint (struct map_session_data *, int, int, int, int, int, int); //self
-int clif_additem (struct map_session_data *, int, int, int); //self
-int clif_delitem (struct map_session_data *, int, int); //self
-int clif_updatestatus (struct map_session_data *, int); //self
-int clif_changestatus (struct block_list *, int, int); //area
-int clif_damage (struct block_list *, struct block_list *, unsigned int, int, int, int, int, int, int); // area
-#define clif_takeitem(src,dst) clif_damage(src,dst,0,0,0,0,0,1,0)
-int clif_changelook (struct block_list *, int, int); // area
-int clif_changelook_towards (struct block_list *, int, int, struct map_session_data *dst); // area or target
-void clif_changelook_accessories (struct block_list *bl, struct map_session_data *dst); // area or target; list gloves, boots etc.
-int clif_arrowequip (struct map_session_data *sd, int val); //self
-int clif_arrow_fail (struct map_session_data *sd, int type); //self
-int clif_statusupack (struct map_session_data *, int, int, int); // self
-int clif_equipitemack (struct map_session_data *, int, int, int); // self
-int clif_unequipitemack (struct map_session_data *, int, int, int); // self
-int clif_misceffect (struct block_list *, int); // area
-int clif_changeoption (struct block_list *); // area
-int clif_useitemack (struct map_session_data *, int, int, int); // self
-
-int clif_createchat (struct map_session_data *, int); // self
-int clif_dispchat (struct chat_data *, int); // area or fd
-int clif_joinchatfail (struct map_session_data *, int); // self
-int clif_joinchatok (struct map_session_data *, struct chat_data *); // self
-int clif_addchat (struct chat_data *, struct map_session_data *); // chat
-int clif_changechatowner (struct chat_data *, struct map_session_data *); // chat
-int clif_clearchat (struct chat_data *, int); // area or fd
-int clif_leavechat (struct chat_data *, struct map_session_data *); // chat
-int clif_changechatstatus (struct chat_data *); // chat
-
-void clif_emotion (struct block_list *bl, int type);
-void clif_talkiebox (struct block_list *bl, const char *talkie);
-void clif_wedding_effect (struct block_list *bl);
-void clif_sitting (int fd, struct map_session_data *sd);
-//void clif_callpartner(struct map_session_data *sd);
-//void clif_sitting(struct map_session_data *sd);
-void clif_soundeffect (struct map_session_data *sd, struct block_list *bl,
- const char *name, int type);
+#include "clif.t.hpp"
+
+#include <functional>
+
+#include "../common/const_array.hpp"
+#include "../common/timer.t.hpp"
+
+#include "battle.t.hpp"
+#include "map.t.hpp"
+#include "pc.t.hpp"
+#include "skill.t.hpp"
+
+void clif_setip(const char *);
+void clif_setport(int);
+
+struct in_addr clif_getip(void);
+int clif_getport(void);
+int clif_countusers(void);
+void clif_setwaitclose(int);
+
+int clif_authok(struct map_session_data *);
+int clif_authfail_fd(int, int);
+int clif_charselectok(int);
+int clif_dropflooritem(struct flooritem_data *);
+int clif_clearflooritem(struct flooritem_data *, int);
+int clif_clearchar(struct block_list *, BeingRemoveWhy); // area or fd
+int clif_clearchar_delay(tick_t, struct block_list *, BeingRemoveWhy);
+int clif_clearchar_id(int, BeingRemoveWhy, int);
+int clif_spawnpc(struct map_session_data *); //area
+int clif_spawnnpc(struct npc_data *); // area
+int clif_spawn_fake_npc_for_player(struct map_session_data *sd,
+ int fake_npc_id);
+int clif_spawnmob(struct mob_data *); // area
+int clif_walkok(struct map_session_data *); // self
+int clif_movechar(struct map_session_data *); // area
+int clif_movemob(struct mob_data *); //area
+int clif_changemap(struct map_session_data *, const char *, int, int); //self
+int clif_changemapserver(struct map_session_data *, const char *, int, int, struct in_addr, int); //self
+int clif_fixpos(struct block_list *); // area
+int clif_fixmobpos(struct mob_data *md);
+int clif_fixpcpos(struct map_session_data *sd);
+int clif_npcbuysell(struct map_session_data *, int); //self
+int clif_buylist(struct map_session_data *, struct npc_data *); //self
+int clif_selllist(struct map_session_data *); //self
+int clif_scriptmes(struct map_session_data *, int, const char *); //self
+int clif_scriptnext(struct map_session_data *, int); //self
+int clif_scriptclose(struct map_session_data *, int); //self
+int clif_scriptmenu(struct map_session_data *, int, const char *); //self
+int clif_scriptinput(struct map_session_data *, int); //self
+int clif_scriptinputstr(struct map_session_data *sd, int npcid); // self
+int clif_cutin(struct map_session_data *, const char *, int); //self
+int clif_viewpoint(struct map_session_data *, int, int, int, int, int, int); //self
+int clif_additem(struct map_session_data *, int, int, PickupFail); //self
+int clif_delitem(struct map_session_data *, int, int); //self
+int clif_updatestatus(struct map_session_data *, SP); //self
+int clif_damage(struct block_list *, struct block_list *,
+ tick_t, interval_t, interval_t,
+ int, int, DamageType, int); // area
+inline
+int clif_takeitem(struct block_list *src, struct block_list *dst)
+{
+ return clif_damage(src, dst, tick_t(), interval_t::zero(), interval_t::zero(), 0, 0, DamageType::TAKEITEM, 0);
+}
+int clif_changelook(struct block_list *, LOOK, int); // area
+void clif_changelook_accessories(struct block_list *bl, struct map_session_data *dst); // area or target; list gloves, boots etc.
+int clif_arrowequip(struct map_session_data *sd, int val); //self
+int clif_arrow_fail(struct map_session_data *sd, int type); //self
+int clif_statusupack(struct map_session_data *, SP, int, int); // self
+int clif_equipitemack(struct map_session_data *, int, EPOS, int); // self
+int clif_unequipitemack(struct map_session_data *, int, EPOS, int); // self
+int clif_misceffect(struct block_list *, int); // area
+int clif_changeoption(struct block_list *); // area
+int clif_useitemack(struct map_session_data *, int, int, int); // self
+
+void clif_emotion(struct block_list *bl, int type);
+void clif_sitting(int fd, struct map_session_data *sd);
// trade
-int clif_traderequest (struct map_session_data *sd, const char *name);
-int clif_tradestart (struct map_session_data *sd, int type);
-int clif_tradeadditem (struct map_session_data *sd,
- struct map_session_data *tsd, int index, int amount);
-int clif_tradeitemok (struct map_session_data *sd, int index, int amount,
- int fail);
-int clif_tradedeal_lock (struct map_session_data *sd, int fail);
-int clif_tradecancelled (struct map_session_data *sd);
-int clif_tradecompleted (struct map_session_data *sd, int fail);
+int clif_traderequest(struct map_session_data *sd, const char *name);
+int clif_tradestart(struct map_session_data *sd, int type);
+int clif_tradeadditem(struct map_session_data *sd,
+ struct map_session_data *tsd, int index, int amount);
+int clif_tradeitemok(struct map_session_data *sd, int index, int amount,
+ int fail);
+int clif_tradedeal_lock(struct map_session_data *sd, int fail);
+int clif_tradecancelled(struct map_session_data *sd);
+int clif_tradecompleted(struct map_session_data *sd, int fail);
// storage
-#include "storage.hpp"
-int clif_storageitemlist (struct map_session_data *sd, struct storage *stor);
-int clif_storageequiplist (struct map_session_data *sd,
- struct storage *stor);
-int clif_updatestorageamount (struct map_session_data *sd,
- struct storage *stor);
-int clif_storageitemadded (struct map_session_data *sd, struct storage *stor,
- int index, int amount);
-int clif_storageitemremoved (struct map_session_data *sd, int index,
- int amount);
-int clif_storageclose (struct map_session_data *sd);
-int clif_guildstorageitemlist (struct map_session_data *sd,
- struct guild_storage *stor);
-int clif_guildstorageequiplist (struct map_session_data *sd,
- struct guild_storage *stor);
-int clif_updateguildstorageamount (struct map_session_data *sd,
- struct guild_storage *stor);
-int clif_guildstorageitemadded (struct map_session_data *sd,
- struct guild_storage *stor, int index,
- int amount);
-
-int clif_pcinsight (struct block_list *, va_list); // map_forallinmovearea callback
-int clif_pcoutsight (struct block_list *, va_list); // map_forallinmovearea callback
-int clif_mobinsight (struct block_list *, va_list); // map_forallinmovearea callback
-int clif_moboutsight (struct block_list *, va_list); // map_forallinmovearea callback
-
-int clif_npc_class_change (struct block_list *bl, int npc_class, int type);
-int clif_mob_class_change (struct mob_data *md, int mob_class);
-int clif_mob_equip (struct mob_data *md, int nameid); // [Valaris]
-
-int clif_skillinfo (struct map_session_data *sd, int skillid, int type,
- int range);
-int clif_skillinfoblock (struct map_session_data *sd);
-int clif_skillup (struct map_session_data *sd, int skill_num);
-
-int clif_skillcasting (struct block_list *bl,
- int src_id, int dst_id, int dst_x, int dst_y,
- int skill_num, int casttime);
-int clif_skillcastcancel (struct block_list *bl);
-int clif_skill_fail (struct map_session_data *sd, int skill_id, int type,
- int btype);
-int clif_skill_damage (struct block_list *src, struct block_list *dst,
- unsigned int tick, int sdelay, int ddelay, int damage,
- int div, int skill_id, int skill_lv, int type);
-int clif_skill_damage2 (struct block_list *src, struct block_list *dst,
- unsigned int tick, int sdelay, int ddelay,
- int damage, int div, int skill_id, int skill_lv,
- int type);
-int clif_skill_nodamage (struct block_list *src, struct block_list *dst,
- int skill_id, int heal, int fail);
-int clif_skill_poseffect (struct block_list *src, int skill_id, int val,
- int x, int y, int tick);
-int clif_skill_estimation (struct map_session_data *sd,
- struct block_list *dst);
-int clif_skill_warppoint (struct map_session_data *sd, int skill_num,
- const char *map1, const char *map2,
- const char *map3, const char *map4);
-int clif_skill_memo (struct map_session_data *sd, int flag);
-int clif_skill_teleportmessage (struct map_session_data *sd, int flag);
-
-int clif_produceeffect (struct map_session_data *sd, int flag, int nameid);
-
-int clif_skill_setunit (struct skill_unit *unit);
-int clif_skill_delunit (struct skill_unit *unit);
-
-int clif_01ac (struct block_list *bl);
-
-int clif_autospell (struct map_session_data *sd, int skilllv);
-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 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);
-
-int clif_wis_message (int fd, const char *nick, const char *mes, int mes_len);
-int clif_wis_end (int fd, int flag);
-
-int clif_solved_charname (struct map_session_data *sd, int char_id);
-
-int clif_use_card (struct map_session_data *sd, int idx);
-int clif_insert_card (struct map_session_data *sd, int idx_equip,
- int idx_card, int flag);
-
-int clif_itemlist (struct map_session_data *sd);
-int clif_equiplist (struct map_session_data *sd);
-
-int clif_cart_additem (struct map_session_data *, int, int, int);
-int clif_cart_delitem (struct map_session_data *, int, int);
-int clif_cart_itemlist (struct map_session_data *sd);
-int clif_cart_equiplist (struct map_session_data *sd);
-
-int clif_item_identify_list (struct map_session_data *sd);
-int clif_item_identified (struct map_session_data *sd, int idx, int flag);
-int clif_item_repair_list (struct map_session_data *sd);
-
-int clif_item_skill (struct map_session_data *sd, int skillid, int skilllv,
- const char *name);
-
-int clif_mvp_effect (struct map_session_data *sd);
-int clif_mvp_item (struct map_session_data *sd, int nameid);
-int clif_mvp_exp (struct map_session_data *sd, int exp);
-
-int clif_movetoattack (struct map_session_data *sd, struct block_list *bl);
+int clif_storageitemlist(struct map_session_data *sd, struct storage *stor);
+int clif_storageequiplist(struct map_session_data *sd,
+ struct storage *stor);
+int clif_updatestorageamount(struct map_session_data *sd,
+ struct storage *stor);
+int clif_storageitemadded(struct map_session_data *sd, struct storage *stor,
+ int index, int amount);
+int clif_storageitemremoved(struct map_session_data *sd, int index,
+ int amount);
+int clif_storageclose(struct map_session_data *sd);
+
+// map_forallinmovearea callbacks
+void clif_pcinsight(struct block_list *, struct map_session_data *);
+void clif_pcoutsight(struct block_list *, struct map_session_data *);
+void clif_mobinsight(struct block_list *, struct mob_data *);
+void clif_moboutsight(struct block_list *, struct mob_data *);
+
+int clif_skillinfo(struct map_session_data *sd, SkillID skillid, int type,
+ int range);
+int clif_skillinfoblock(struct map_session_data *sd);
+int clif_skillup(struct map_session_data *sd, SkillID skill_num);
+
+int clif_skillcastcancel(struct block_list *bl);
+int clif_skill_fail(struct map_session_data *sd, SkillID skill_id, int type,
+ int btype);
+int clif_skill_damage(struct block_list *src, struct block_list *dst,
+ tick_t tick, interval_t sdelay, interval_t ddelay, int damage,
+ int div, SkillID skill_id, int skill_lv, int type);
+
+int clif_status_change(struct block_list *bl,
+ StatusChange type, int flag);
+
+int clif_wis_message(int fd, const char *nick, const char *mes, int mes_len);
+int clif_wis_end(int fd, int flag);
+
+int clif_itemlist(struct map_session_data *sd);
+int clif_equiplist(struct map_session_data *sd);
+
+int clif_mvp_effect(struct map_session_data *sd);
+
+int clif_movetoattack(struct map_session_data *sd, struct block_list *bl);
// party
-int clif_party_created (struct map_session_data *sd, int flag);
-int clif_party_info (struct party *p, int fd);
-int clif_party_invite (struct map_session_data *sd,
- struct map_session_data *tsd);
-int clif_party_inviteack (struct map_session_data *sd, const char *nick, int flag);
-int clif_party_option (struct party *p, struct map_session_data *sd,
- int flag);
-int clif_party_leaved (struct party *p, struct map_session_data *sd,
- int account_id, const char *name, int flag);
-int clif_party_message (struct party *p, int account_id, const char *mes, int len);
-int clif_party_move (struct party *p, struct map_session_data *sd,
- int online);
-int clif_party_xy (struct party *p, struct map_session_data *sd);
-int clif_party_hp (struct party *p, struct map_session_data *sd);
-
-// guild
-int clif_guild_created (struct map_session_data *sd, int flag);
-int clif_guild_belonginfo (struct map_session_data *sd, struct guild *g);
-int clif_guild_basicinfo (struct map_session_data *sd);
-int clif_guild_allianceinfo (struct map_session_data *sd);
-int clif_guild_memberlist (struct map_session_data *sd);
-int clif_guild_skillinfo (struct map_session_data *sd);
-int clif_guild_memberlogin_notice (struct guild *g, int idx, int flag);
-int clif_guild_invite (struct map_session_data *sd, struct guild *g);
-int clif_guild_inviteack (struct map_session_data *sd, int flag);
-int clif_guild_leave (struct map_session_data *sd, const char *name,
- const char *mes);
-int clif_guild_explusion (struct map_session_data *sd, const char *name,
- const char *mes, int account_id);
-int clif_guild_positionchanged (struct guild *g, int idx);
-int clif_guild_memberpositionchanged (struct guild *g, int idx);
-int clif_guild_emblem (struct map_session_data *sd, struct guild *g);
-int clif_guild_notice (struct map_session_data *sd, struct guild *g);
-int clif_guild_message (struct guild *g, int account_id, const char *mes,
- int len);
-int clif_guild_skillup (struct map_session_data *sd, int skill_num, int lv);
-int clif_guild_reqalliance (struct map_session_data *sd, int account_id,
- const char *name);
-int clif_guild_allianceack (struct map_session_data *sd, int flag);
-int clif_guild_delalliance (struct map_session_data *sd, int guild_id,
- int flag);
-int clif_guild_oppositionack (struct map_session_data *sd, int flag);
-int clif_guild_broken (struct map_session_data *sd, int flag);
+int clif_party_created(struct map_session_data *sd, int flag);
+int clif_party_info(struct party *p, int fd);
+int clif_party_invite(struct map_session_data *sd,
+ struct map_session_data *tsd);
+int clif_party_inviteack(struct map_session_data *sd, const char *nick, int flag);
+int clif_party_option(struct party *p, struct map_session_data *sd,
+ int flag);
+int clif_party_leaved(struct party *p, struct map_session_data *sd,
+ int account_id, const char *name, int flag);
+int clif_party_message(struct party *p, int account_id, const char *mes, int len);
+int clif_party_xy(struct party *p, struct map_session_data *sd);
+int clif_party_hp(struct party *p, struct map_session_data *sd);
// atcommand
-int clif_displaymessage (int fd, const char *mes);
-int clif_disp_onlyself (struct map_session_data *sd, const char *mes, int len);
-int clif_GMmessage (struct block_list *bl, const char *mes, int len, int flag);
-int clif_heal (int fd, int type, int val);
-int clif_resurrection (struct block_list *bl, int type);
-int clif_set0199 (int fd, int type);
-int clif_pvpset (struct map_session_data *sd, int pvprank, int pvpnum,
- int type);
-int clif_send0199 (int map, int type);
-int clif_refine (int fd, struct map_session_data *sd, int fail, int index,
- int val);
+void clif_displaymessage(int fd, const_string mes);
+void clif_GMmessage(struct block_list *bl, const_string mes, int flag);
+int clif_resurrection(struct block_list *bl, int type);
-int clif_specialeffect (struct block_list *bl, int type, int flag); // special effects [Valaris]
-int clif_message (struct block_list *bl, const char *msg); // messages (from mobs/npcs) [Valaris]
+int clif_specialeffect(struct block_list *bl, int type, int flag); // special effects [Valaris]
+int clif_message(struct block_list *bl, const char *msg); // messages (from mobs/npcs) [Valaris]
-int clif_GM_kickack (struct map_session_data *sd, int id);
-int clif_GM_kick (struct map_session_data *sd, struct map_session_data *tsd,
- int type);
+int clif_GM_kick(struct map_session_data *sd, struct map_session_data *tsd,
+ int type);
-int clif_foreachclient (int (*)(struct map_session_data *, va_list), ...);
+int clif_foreachclient(std::function<void(struct map_session_data *)>);
-int do_final_clif (void);
-int do_init_clif (void);
+int do_init_clif (void);
-#endif
+#endif // CLIF_HPP
diff --git a/src/map/clif.t.hpp b/src/map/clif.t.hpp
new file mode 100644
index 0000000..38394e9
--- /dev/null
+++ b/src/map/clif.t.hpp
@@ -0,0 +1,21 @@
+#ifndef CLIF_T_HPP
+#define CLIF_T_HPP
+
+#include <cstdint>
+
+enum class BeingRemoveWhy : uint8_t
+{
+ // general disappearance
+ GONE = 0,
+ // only case handled specially in client
+ DEAD = 1,
+ QUIT = 2,
+ WARPED = 3,
+ // handled specially in clif_clearchar - sent as 0 over network
+ DISGUISE = 9,
+
+ // handled speciall in mob_warp - not actually sent over network
+ NEGATIVE1 = 0xff,
+};
+
+#endif // CLIF_T_HPP
diff --git a/src/map/grfio.cpp b/src/map/grfio.cpp
new file mode 100644
index 0000000..a190d1b
--- /dev/null
+++ b/src/map/grfio.cpp
@@ -0,0 +1,72 @@
+// Reads .gat files by name-mapping .wlk files
+#include "grfio.hpp"
+
+#include <sys/stat.h>
+
+#include <fcntl.h>
+#include <unistd.h>
+
+#include <cassert>
+#include <cstdio>
+#include <cstring>
+
+#include <fstream>
+#include <map>
+
+#include "../common/cxxstdio.hpp"
+#include "../common/extract.hpp"
+
+#include "../poison.hpp"
+
+static
+std::map<std::string, std::string> load_resnametable()
+{
+ std::ifstream in("data/resnametable.txt");
+ if (!in.is_open())
+ {
+ fprintf(stderr, "Missing data/resnametable.txt");
+ abort();
+ }
+ std::map<std::string, std::string> out;
+
+ std::string line;
+ while (std::getline(in, line))
+ {
+ std::string key, value;
+ if (!extract(line,
+ record<'#'>(&key, &value)))
+ continue;
+ out[key] = value;
+ }
+ return out;
+}
+
+/// Change *.gat to *.wlk
+static
+std::string grfio_resnametable(const_string rname)
+{
+ static
+ std::map<std::string, std::string> resnametable = load_resnametable();
+
+ return resnametable.at(std::string(rname.begin(), rname.end()));
+}
+
+std::vector<uint8_t> grfio_reads(const_string rname)
+{
+ std::string lfname = "data/" + grfio_resnametable(rname);
+
+ int fd = open(lfname.c_str(), O_RDONLY);
+ if (fd == -1)
+ {
+ FPRINTF(stderr, "Resource %s (file %s) not found\n",
+ std::string(rname.begin(), rname.end()), lfname);
+ return {};
+ }
+ off_t len = lseek(fd, 0, SEEK_END);
+ assert (len != -1);
+ std::vector<uint8_t> buffer(len);
+ int err = pread(fd, buffer.data(), len, 0);
+ assert (err == len);
+ close(fd);
+ return buffer;
+}
diff --git a/src/map/grfio.hpp b/src/map/grfio.hpp
new file mode 100644
index 0000000..fd7b871
--- /dev/null
+++ b/src/map/grfio.hpp
@@ -0,0 +1,15 @@
+#ifndef GRFIO_HPP
+#define GRFIO_HPP
+
+#include <cstdint>
+
+#include <vector>
+
+#include "../common/const_array.hpp"
+
+/// Load a resource into memory, subject to data/resnametable.txt.
+/// Normally, resourcename is xxx-y.gat and the file is xxx-y.wlk.
+/// Currently there is exactly one .wlk per .gat, but multiples are fine.
+std::vector<uint8_t> grfio_reads(const_string resourcename);
+
+#endif // GRFIO_HPP
diff --git a/src/map/guild.cpp b/src/map/guild.cpp
deleted file mode 100644
index eba856d..0000000
--- a/src/map/guild.cpp
+++ /dev/null
@@ -1,1922 +0,0 @@
-// $Id: guild.c,v 1.5 2004/09/25 05:32:18 MouseJstr Exp $
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "guild.hpp"
-#include "storage.hpp"
-#include "../common/db.hpp"
-#include "../common/timer.hpp"
-#include "../common/socket.hpp"
-#include "../common/nullpo.hpp"
-#include "battle.hpp"
-#include "npc.hpp"
-#include "pc.hpp"
-#include "map.hpp"
-#include "mob.hpp"
-#include "intif.hpp"
-#include "clif.hpp"
-#include "tmw.hpp"
-
-#ifdef MEMWATCH
-#include "memwatch.hpp"
-#endif
-
-static struct dbt *guild_db;
-static struct dbt *castle_db;
-static struct dbt *guild_expcache_db;
-static struct dbt *guild_infoevent_db;
-static struct dbt *guild_castleinfoevent_db;
-
-struct eventlist
-{
- char name[50];
- struct eventlist *next;
-};
-
-// ギルドã®EXPキャッシュã®ãƒ•ãƒ©ãƒƒã‚·ãƒ¥ã«é–¢é€£ã™ã‚‹å®šæ•°
-#define GUILD_PAYEXP_INVERVAL 10000 // é–“éš”(キャッシュã®æœ€å¤§ç”Ÿå­˜æ™‚é–“ã€ãƒŸãƒªç§’)
-#define GUILD_PAYEXP_LIST 8192 // キャッシュã®æœ€å¤§æ•°
-
-// ギルドã®EXPキャッシュ
-struct guild_expcache
-{
- int guild_id, account_id, char_id, exp;
-};
-
-// ギルドスキルdbã®ã‚¢ã‚¯ã‚»ã‚µï¼ˆä»Šã¯ç›´æ‰“ã¡ã§ä»£ç”¨ï¼‰
-int guild_skill_get_inf (int id)
-{
- return 0;
-}
-
-int guild_skill_get_sp (int id, int lv)
-{
- return 0;
-}
-
-int guild_skill_get_range (int id)
-{
- return 0;
-}
-
-int guild_skill_get_max (int id)
-{
- return (id == 10004) ? 10 : 1;
-}
-
-// ギルドスキルãŒã‚ã‚‹ã‹ç¢ºèª
-int guild_checkskill (struct guild *g, int id)
-{
- return g->skill[id - 10000].lv;
-}
-
-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)
-{
- FILE *fp;
- char line[1024];
- int j, ln = 0;
- char *str[32], *p;
- struct guild_castle *gc;
-
- if ((fp = fopen_ ("db/castle_db.txt", "r")) == NULL)
- {
- printf ("can't read db/castle_db.txt\n");
- return -1;
- }
-
- while (fgets (line, 1020, fp))
- {
- if (line[0] == '/' && line[1] == '/')
- continue;
- memset (str, 0, sizeof (str));
- CREATE (gc, struct guild_castle, 1);
- for (j = 0, p = line; j < 6 && p; j++)
- {
- str[j] = p;
- p = strchr (p, ',');
- if (p)
- *p++ = 0;
- }
-
- gc->guild_id = 0; // <Agit> Clear Data for Initialize
- gc->economy = 0;
- gc->defense = 0;
- gc->triggerE = 0;
- gc->triggerD = 0;
- gc->nextTime = 0;
- gc->payTime = 0;
- gc->createTime = 0;
- gc->visibleC = 0;
- gc->visibleG0 = 0;
- gc->visibleG1 = 0;
- gc->visibleG2 = 0;
- gc->visibleG3 = 0;
- gc->visibleG4 = 0;
- gc->visibleG5 = 0;
- gc->visibleG6 = 0;
- gc->visibleG7 = 0;
- gc->Ghp0 = 0;
- gc->Ghp1 = 0;
- gc->Ghp2 = 0;
- gc->Ghp3 = 0;
- gc->Ghp4 = 0;
- gc->Ghp5 = 0;
- gc->Ghp6 = 0;
- gc->Ghp7 = 0; // guardian HP [Valaris]
-
- gc->castle_id = atoi (str[0]);
- memcpy (gc->map_name, str[1], 24);
- memcpy (gc->castle_name, str[2], 24);
- memcpy (gc->castle_event, str[3], 24);
-
- numdb_insert (castle_db, gc->castle_id, gc);
-
- //intif_guild_castle_info(gc->castle_id);
-
- ln++;
- }
- fclose_ (fp);
- printf ("read db/castle_db.txt done (count=%d)\n", ln);
- return 0;
-}
-
-// åˆæœŸåŒ–
-void do_init_guild (void)
-{
- guild_db = numdb_init ();
- castle_db = numdb_init ();
- guild_expcache_db = numdb_init ();
- guild_infoevent_db = numdb_init ();
- guild_castleinfoevent_db = numdb_init ();
-
- guild_read_castledb ();
-
- add_timer_interval (gettick () + GUILD_PAYEXP_INVERVAL,
- guild_payexp_timer, 0, 0, GUILD_PAYEXP_INVERVAL);
-}
-
-// 検索
-struct guild *guild_search (int guild_id)
-{
- return (struct guild *)numdb_search (guild_db, guild_id);
-}
-
-static
-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 (strcasecmp (g->name, str) == 0)
- *dst = g;
-}
-
-// ギルドå検索
-struct guild *guild_searchname (const char *str)
-{
- struct guild *g = NULL;
- numdb_foreach (guild_db, guild_searchname_sub, str, &g);
- return g;
-}
-
-struct guild_castle *guild_castle_search (int gcid)
-{
- return (struct guild_castle *)numdb_search (castle_db, gcid);
-}
-
-// mapnameã«å¯¾å¿œã—ãŸã‚¢ã‚¸ãƒˆã®gcã‚’è¿”ã™
-struct guild_castle *guild_mapname2gc (const char *mapname)
-{
- int i;
- struct guild_castle *gc = NULL;
- for (i = 0; i < MAX_GUILDCASTLE; i++)
- {
- gc = guild_castle_search (i);
- if (!gc)
- continue;
- if (strcmp (gc->map_name, mapname) == 0)
- return gc;
- }
- return NULL;
-}
-
-// ログイン中ã®ã‚®ãƒ«ãƒ‰ãƒ¡ãƒ³ãƒãƒ¼ã®ï¼‘人ã®sdã‚’è¿”ã™
-struct map_session_data *guild_getavailablesd (struct guild *g)
-{
- int i;
-
- nullpo_retr (NULL, g);
-
- for (i = 0; i < g->max_member; i++)
- if (g->member[i].sd != NULL)
- return g->member[i].sd;
- return NULL;
-}
-
-// ギルドメンãƒãƒ¼ã®ã‚¤ãƒ³ãƒ‡ãƒƒã‚¯ã‚¹ã‚’è¿”ã™
-int guild_getindex (struct guild *g, int account_id, int char_id)
-{
- int i;
- if (g == NULL)
- return -1;
- for (i = 0; i < g->max_member; i++)
- if (g->member[i].account_id == account_id)
- return i;
- return -1;
-}
-
-// ギルドメンãƒãƒ¼ã®å½¹è·ã‚’è¿”ã™
-int guild_getposition (struct map_session_data *sd, struct guild *g)
-{
- int i;
-
- nullpo_retr (-1, sd);
-
- if (g == NULL && (g = guild_search (sd->status.guild_id)) == NULL)
- return -1;
- for (i = 0; i < g->max_member; i++)
- if (g->member[i].account_id == sd->status.account_id)
- return g->member[i].position;
- return -1;
-}
-
-// メンãƒãƒ¼æƒ…å ±ã®ä½œæˆ
-static
-void guild_makemember (struct guild_member *m, struct map_session_data *sd)
-{
- nullpo_retv (sd);
-
- memset (m, 0, sizeof (struct guild_member));
- m->account_id = sd->status.account_id;
- m->char_id = 0;
- m->hair = sd->status.hair;
- m->hair_color = sd->status.hair_color;
- m->gender = sd->sex;
- m->pc_class = sd->status.pc_class;
- m->lv = sd->status.base_level;
- m->exp = 0;
- m->exp_payper = 0;
- m->online = 1;
- m->position = MAX_GUILDPOSITION - 1;
- memcpy (m->name, sd->status.name, 24);
- return;
-}
-
-// ギルド競åˆç¢ºèª
-static
-int guild_check_conflict (struct map_session_data *sd)
-{
- nullpo_retr (0, sd);
-
- intif_guild_checkconflict (sd->status.guild_id,
- sd->status.account_id, 0 /*char_id*/);
- return 0;
-}
-
-// ギルドã®EXPキャッシュをinter鯖ã«ãƒ•ãƒ©ãƒƒã‚·ãƒ¥ã™ã‚‹
-static
-void guild_payexp_timer_sub (db_key_t key, db_val_t data, va_list ap)
-{
- int i, *dellist, *delp, dataid = key.i;
- struct guild_expcache *c;
- struct guild *g;
-
- 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;
- if ((i = guild_getindex (g, c->account_id, 0 /*c->char_id*/)) < 0)
- return;
-
- g->member[i].exp += c->exp;
- intif_guild_change_memberinfo (g->guild_id, c->account_id, 0 /*char_id*/,
- GMI_EXP, &g->member[i].exp,
- sizeof (g->member[i].exp));
- c->exp = 0;
-
- dellist[(*delp)++] = dataid;
- free (c);
-}
-
-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);
- for (i = 0; i < delp; i++)
- numdb_erase (guild_expcache_db, dellist[i]);
-// if(battle_config.etc_log)
-// printf("guild exp %d charactor's exp flushed !\n",delp);
-}
-
-//------------------------------------------------------------------------
-
-/* Process a guild creation request. */
-int guild_create (struct map_session_data *sd, const char *name)
-{
- char pname[24];
-
- nullpo_retr (0, sd);
-
- strncpy (pname, name, 24);
- pname[23] = '\0';
- tmw_TrimStr (pname);
-
- /* The guild name is empty/invalid. */
- if (!*pname)
- clif_guild_created (sd, 2);
-
- /* Make sure the character isn't already in a guild. */
- if (sd->status.guild_id == 0)
- {
- /*
- * A special item is required to create a guild. This is specified
- * in battle_athena.conf as guild_emperium_check. This item will
- * be removed from the player's inventory when used to create a
- * guild.
- */
- if (!battle_config.guild_emperium_check
- || pc_search_inventory (sd,
- battle_config.guild_emperium_check) >= 0)
- {
- struct guild_member m;
- guild_makemember (&m, sd);
- m.position = 0;
- intif_guild_create (pname, &m);
- }
- else
- clif_guild_created (sd, 3);
- }
- else
- clif_guild_created (sd, 1);
-
- return 0;
-}
-
-/* Relay the result of a guild creation request. */
-int guild_created (int account_id, int guild_id)
-{
- struct map_session_data *sd = map_id2sd (account_id);
-
- if (!sd)
- return 0;
-
- /* The guild name is valid and not already taken. */
- if (guild_id > 0)
- {
- struct guild *g;
- sd->status.guild_id = guild_id;
- sd->guild_sended = 0;
-
- if ((g = (struct guild *)numdb_search (guild_db, guild_id)) != NULL)
- {
- printf ("guild_created(): ID already exists!\n");
- exit (1);
- }
-
- /* The guild was created successfully. */
- clif_guild_created (sd, 0);
-
- if (battle_config.guild_emperium_check)
- pc_delitem (sd,
- pc_search_inventory (sd,
- battle_config.
- guild_emperium_check), 1, 0);
- }
- else
- clif_guild_created (sd, 2);
-
- return 0;
-}
-
-// 情報è¦æ±‚
-int guild_request_info (int guild_id)
-{
-// if(battle_config.etc_log)
-// printf("guild_request_info\n");
- return intif_guild_request_info (guild_id);
-}
-
-// イベント付ã情報è¦æ±‚
-int guild_npc_request_info (int guild_id, const char *event)
-{
- struct eventlist *ev;
-
- if (guild_search (guild_id))
- {
- if (event && *event)
- npc_event_do (event);
- return 0;
- }
-
- if (event == NULL || *event == 0)
- return guild_request_info (guild_id);
-
- CREATE (ev, struct eventlist, 1);
- memcpy (ev->name, event, sizeof (ev->name));
- ev->next =
- (struct eventlist *) numdb_search (guild_infoevent_db, guild_id);
- numdb_insert (guild_infoevent_db, guild_id, ev);
- return guild_request_info (guild_id);
-}
-
-// 所属キャラã®ç¢ºèª
-static
-int guild_check_member (const struct guild *g)
-{
- int i;
- struct map_session_data *sd;
-
- nullpo_retr (0, g);
-
- for (i = 0; i < fd_max; i++)
- {
- if (session[i] && (sd = (struct map_session_data *)session[i]->session_data) && sd->state.auth)
- {
- if (sd->status.guild_id == g->guild_id)
- {
- int j, f = 1;
- for (j = 0; j < MAX_GUILD; j++)
- { // データãŒã‚ã‚‹ã‹
- if (g->member[j].account_id == sd->status.account_id)
- f = 0;
- }
- if (f)
- {
- sd->status.guild_id = 0;
- sd->guild_sended = 0;
- sd->guild_emblem_id = 0;
- if (battle_config.error_log)
- printf ("guild: check_member %d[%s] is not member\n",
- sd->status.account_id, sd->status.name);
- }
- }
- }
- }
- return 0;
-}
-
-// 情報所得失敗(ãã®IDã®ã‚­ãƒ£ãƒ©ã‚’全部未所属ã«ã™ã‚‹ï¼‰
-int guild_recv_noinfo (int guild_id)
-{
- int i;
- struct map_session_data *sd;
- for (i = 0; i < fd_max; i++)
- {
- if (session[i] && (sd = (struct map_session_data *)session[i]->session_data) && sd->state.auth)
- {
- if (sd->status.guild_id == guild_id)
- sd->status.guild_id = 0;
- }
- }
- return 0;
-}
-
-// 情報所得
-int guild_recv_info (struct guild *sg)
-{
- struct guild *g, before;
- int i, bm, m;
- struct eventlist *ev, *ev2;
-
- nullpo_retr (0, sg);
-
- if ((g = (struct guild *)numdb_search (guild_db, sg->guild_id)) == NULL)
- {
- CREATE (g, struct guild, 1);
- numdb_insert (guild_db, sg->guild_id, g);
- before = *sg;
-
- // 最åˆã®ãƒ­ãƒ¼ãƒ‰ãªã®ã§ãƒ¦ãƒ¼ã‚¶ãƒ¼ã®ãƒã‚§ãƒƒã‚¯ã‚’è¡Œã†
- guild_check_member (sg);
- }
- else
- before = *g;
- memcpy (g, sg, sizeof (struct guild));
-
- for (i = bm = m = 0; i < g->max_member; i++)
- { // sdã®è¨­å®šã¨äººæ•°ã®ç¢ºèª
- if (g->member[i].account_id > 0)
- {
- struct map_session_data *sd = map_id2sd (g->member[i].account_id);
- g->member[i].sd = (sd != NULL &&
- sd->status.guild_id ==
- g->guild_id) ? sd : NULL;
- m++;
- }
- else
- g->member[i].sd = NULL;
- if (before.member[i].account_id > 0)
- bm++;
- }
-
- for (i = 0; i < g->max_member; i++)
- { // 情報ã®é€ä¿¡
- struct map_session_data *sd = g->member[i].sd;
- if (sd == NULL)
- continue;
-
- if (before.guild_lv != g->guild_lv || bm != m ||
- before.max_member != g->max_member)
- {
- clif_guild_basicinfo (sd); // 基本情報é€ä¿¡
- clif_guild_emblem (sd, g); // エンブレムé€ä¿¡
- }
-
- if (bm != m)
- { // メンãƒãƒ¼æƒ…å ±é€ä¿¡
- clif_guild_memberlist (g->member[i].sd);
- }
-
- if (before.skill_point != g->skill_point)
- clif_guild_skillinfo (sd); // スキル情報é€ä¿¡
-
- if (sd->guild_sended == 0)
- { // 未é€ä¿¡ãªã‚‰æ‰€å±žæƒ…報もé€ã‚‹
- clif_guild_belonginfo (sd, g);
- clif_guild_notice (sd, g);
- sd->guild_emblem_id = g->emblem_id;
- sd->guild_sended = 1;
- }
- }
-
- // イベントã®ç™ºç”Ÿ
- if ((ev = (struct eventlist *)numdb_search (guild_infoevent_db, sg->guild_id)) != NULL)
- {
- numdb_erase (guild_infoevent_db, sg->guild_id);
- for (; ev; ev2 = ev->next, free (ev), ev = ev2)
- {
- npc_event_do (ev->name);
- }
- }
-
- return 0;
-}
-
-// ギルドã¸ã®å‹§èª˜
-int guild_invite (struct map_session_data *sd, int account_id)
-{
- struct map_session_data *tsd;
- struct guild *g;
- int i;
-
- nullpo_retr (0, sd);
-
- tsd = map_id2sd (account_id);
- g = guild_search (sd->status.guild_id);
-
- if (tsd == NULL || g == NULL)
- return 0;
- if (!battle_config.invite_request_check)
- {
- if (tsd->party_invite > 0 || tsd->trade_partner)
- { // 相手ãŒå–引中ã‹ã©ã†ã‹
- clif_guild_inviteack (sd, 0);
- return 0;
- }
- }
- if (tsd->status.guild_id > 0 || tsd->guild_invite > 0)
- { // 相手ã®æ‰€å±žç¢ºèª
- clif_guild_inviteack (sd, 0);
- return 0;
- }
-
- // 定員確èª
- for (i = 0; i < g->max_member; i++)
- if (g->member[i].account_id == 0)
- break;
- if (i == g->max_member)
- {
- clif_guild_inviteack (sd, 3);
- return 0;
- }
-
- tsd->guild_invite = sd->status.guild_id;
- tsd->guild_invite_account = sd->status.account_id;
-
- clif_guild_invite (tsd, g);
- return 0;
-}
-
-// ギルド勧誘ã¸ã®è¿”ç­”
-int guild_reply_invite (struct map_session_data *sd, int guild_id, int flag)
-{
- struct map_session_data *tsd;
-
- nullpo_retr (0, sd);
- nullpo_retr (0, tsd = map_id2sd (sd->guild_invite_account));
-
- if (sd->guild_invite != guild_id) // 勧誘ã¨ã‚®ãƒ«ãƒ‰IDãŒé•ã†
- return 0;
-
- if (flag == 1)
- { // 承諾
- struct guild_member m;
- struct guild *g;
- int i;
-
- // 定員確èª
- if ((g = guild_search (tsd->status.guild_id)) == NULL)
- {
- sd->guild_invite = 0;
- sd->guild_invite_account = 0;
- return 0;
- }
- for (i = 0; i < g->max_member; i++)
- if (g->member[i].account_id == 0)
- break;
- if (i == g->max_member)
- {
- sd->guild_invite = 0;
- sd->guild_invite_account = 0;
- clif_guild_inviteack (tsd, 3);
- return 0;
- }
-
- //inter鯖ã¸è¿½åŠ è¦æ±‚
- guild_makemember (&m, sd);
- intif_guild_addmember (sd->guild_invite, &m);
- return 0;
- }
- else
- { // æ‹’å¦
- sd->guild_invite = 0;
- sd->guild_invite_account = 0;
- if (tsd == NULL)
- return 0;
- clif_guild_inviteack (tsd, 1);
- }
- return 0;
-}
-
-// ギルドメンãƒãŒè¿½åŠ ã•ã‚ŒãŸ
-int guild_member_added (int guild_id, int account_id, int char_id, int flag)
-{
- struct map_session_data *sd = map_id2sd (account_id), *sd2;
- struct guild *g;
-
- if ((g = guild_search (guild_id)) == NULL)
- return 0;
-
- if ((sd == NULL || sd->guild_invite == 0) && flag == 0)
- {
- // キャラå´ã«ç™»éŒ²ã§ããªã‹ã£ãŸãŸã‚脱退è¦æ±‚を出ã™
- if (battle_config.error_log)
- printf ("guild: member added error %d is not online\n",
- account_id);
- intif_guild_leave (guild_id, account_id, 0 /*char_id*/, 0, "**登録失敗**");
- return 0;
- }
- sd->guild_invite = 0;
- sd->guild_invite_account = 0;
-
- sd2 = map_id2sd (sd->guild_invite_account);
-
- if (flag == 1)
- { // 失敗
- if (sd2 != NULL)
- clif_guild_inviteack (sd2, 3);
- return 0;
- }
-
- // æˆåŠŸ
- sd->guild_sended = 0;
- sd->status.guild_id = guild_id;
-
- if (sd2 != NULL)
- clif_guild_inviteack (sd2, 2);
-
- // ã„ã¡ãŠã†ç«¶åˆç¢ºèª
- guild_check_conflict (sd);
-
- return 0;
-}
-
-// ギルド脱退è¦æ±‚
-int guild_leave (struct map_session_data *sd, int guild_id,
- int account_id, int char_id, const char *mes)
-{
- struct guild *g;
- int i;
-
- nullpo_retr (0, sd);
-
- g = guild_search (sd->status.guild_id);
-
- if (g == NULL)
- return 0;
-
- if (sd->status.account_id != account_id ||
- sd->status.guild_id != guild_id)
- return 0;
-
- for (i = 0; i < g->max_member; i++)
- { // 所属ã—ã¦ã„ã‚‹ã‹
- if (g->member[i].account_id == sd->status.account_id)
- {
- intif_guild_leave (g->guild_id, sd->status.account_id,
- sd->status.char_id, 0, mes);
- return 0;
- }
- }
- return 0;
-}
-
-// ギルド追放è¦æ±‚
-int guild_explusion (struct map_session_data *sd, int guild_id,
- int account_id, int char_id, const char *mes)
-{
- struct guild *g;
- int i, ps;
-
- nullpo_retr (0, sd);
-
- g = guild_search (sd->status.guild_id);
-
- if (g == NULL)
- return 0;
-
- if (sd->status.guild_id != guild_id)
- return 0;
-
- if ((ps = guild_getposition (sd, g)) < 0
- || !(g->position[ps].mode & 0x0010))
- return 0; // 処罰権é™ç„¡ã—
-
- for (i = 0; i < g->max_member; i++)
- { // 所属ã—ã¦ã„ã‚‹ã‹
- if (g->member[i].account_id == account_id)
- {
- intif_guild_leave (g->guild_id, account_id, 0 /*char_id*/, 1, mes);
- return 0;
- }
- }
- return 0;
-}
-
-// ギルドメンãƒãŒè„±é€€ã—ãŸ
-int guild_member_leaved (int guild_id, int account_id, int char_id, int flag,
- const char *name, const char *mes)
-{
- struct map_session_data *sd = map_id2sd (account_id);
- struct guild *g = guild_search (guild_id);
- int i;
-
- if (g != NULL)
- {
- int i;
- for (i = 0; i < g->max_member; i++)
- if (g->member[i].account_id == account_id)
- {
- struct map_session_data *sd2 = sd;
- if (sd2 == NULL)
- sd2 = guild_getavailablesd (g);
- else
- {
- if (flag == 0)
- clif_guild_leave (sd2, name, mes);
- else
- clif_guild_explusion (sd2, name, mes, account_id);
- }
- g->member[i].account_id = 0;
- g->member[i].sd = NULL;
- }
- }
- if (sd != NULL && sd->status.guild_id == guild_id)
- {
- if (sd->state.storage_flag == 2) //Close the guild storage.
- storage_guild_storageclose (sd);
- sd->status.guild_id = 0;
- sd->guild_emblem_id = 0;
- sd->guild_sended = 0;
- }
-
- // メンãƒãƒ¼ãƒªã‚¹ãƒˆã‚’全員ã«å†é€šçŸ¥
- for (i = 0; i < g->max_member; i++)
- {
- if (g->member[i].sd != NULL)
- clif_guild_memberlist (g->member[i].sd);
- }
-
- return 0;
-}
-
-// ギルドメンãƒã®ã‚ªãƒ³ãƒ©ã‚¤ãƒ³çŠ¶æ…‹/Lvæ›´æ–°é€ä¿¡
-int guild_send_memberinfoshort (struct map_session_data *sd, int online)
-{
- struct guild *g;
-
- nullpo_retr (0, sd);
-
- if (sd->status.guild_id <= 0)
- return 0;
- g = guild_search (sd->status.guild_id);
- if (g == NULL)
- return 0;
-
- intif_guild_memberinfoshort (g->guild_id,
- sd->status.account_id, 0 /*char_id*/,
- online, sd->status.base_level,
- sd->status.pc_class);
-
- if (!online)
- { // ログアウトã™ã‚‹ãªã‚‰sdをクリアã—ã¦çµ‚了
- int i =
- guild_getindex (g, sd->status.account_id, 0 /*char_id*/);
- if (i >= 0)
- g->member[i].sd = NULL;
- return 0;
- }
-
- if (sd->guild_sended != 0) // ギルドåˆæœŸé€ä¿¡ãƒ‡ãƒ¼ã‚¿ã¯é€ä¿¡æ¸ˆã¿
- return 0;
-
- // 競åˆç¢ºèª
- guild_check_conflict (sd);
-
- // ã‚ã‚‹ãªã‚‰ã‚®ãƒ«ãƒ‰åˆæœŸé€ä¿¡ãƒ‡ãƒ¼ã‚¿é€ä¿¡
- if ((g = guild_search (sd->status.guild_id)) != NULL)
- {
- guild_check_member (g); // 所属を確èªã™ã‚‹
- if (sd->status.guild_id == g->guild_id)
- {
- clif_guild_belonginfo (sd, g);
- clif_guild_notice (sd, g);
- sd->guild_sended = 1;
- sd->guild_emblem_id = g->emblem_id;
- }
- }
- return 0;
-}
-
-// ギルドメンãƒã®ã‚ªãƒ³ãƒ©ã‚¤ãƒ³çŠ¶æ…‹/Lv更新通知
-int guild_recv_memberinfoshort (int guild_id, int account_id, int char_id,
- int online, int lv, int pc_class)
-{
- int i, alv, c, idx = 0, om = 0, oldonline = -1;
- struct guild *g = guild_search (guild_id);
- if (g == NULL)
- return 0;
- for (i = 0, alv = 0, c = 0, om = 0; i < g->max_member; i++)
- {
- struct guild_member *m = &g->member[i];
- if (m->account_id == account_id)
- {
- oldonline = m->online;
- m->online = online;
- m->lv = lv;
- m->pc_class = pc_class;
- idx = i;
- }
- if (m->account_id > 0)
- {
- alv += m->lv;
- c++;
- }
- if (m->online)
- om++;
- }
- if (idx == g->max_member)
- {
- if (battle_config.error_log)
- printf ("guild: not found member %d,%d on %d[%s]\n", account_id,
- char_id, guild_id, g->name);
- return 0;
- }
- g->average_lv = alv / c;
- g->connect_member = om;
-
- if (oldonline != online) // オンライン状態ãŒå¤‰ã‚ã£ãŸã®ã§é€šçŸ¥
- clif_guild_memberlogin_notice (g, idx, online);
-
- for (i = 0; i < g->max_member; i++)
- { // sdå†è¨­å®š
- struct map_session_data *sd = map_id2sd (g->member[i].account_id);
- g->member[i].sd = (sd != NULL &&
- sd->status.guild_id == guild_id) ? sd : NULL;
- }
-
- // ã“ã“ã«ã‚¯ãƒ©ã‚¤ã‚¢ãƒ³ãƒˆã«é€ä¿¡å‡¦ç†ãŒå¿…è¦
-
- return 0;
-}
-
-// ギルド会話é€ä¿¡
-int guild_send_message (struct map_session_data *sd, const char *mes, int len)
-{
- nullpo_retr (0, sd);
-
- if (sd->status.guild_id == 0)
- return 0;
- intif_guild_message (sd->status.guild_id, sd->status.account_id, mes,
- len);
- return 0;
-}
-
-// ギルド会話å—ä¿¡
-int guild_recv_message (int guild_id, int account_id, const char *mes, int len)
-{
- struct guild *g;
- if ((g = guild_search (guild_id)) == NULL)
- return 0;
- clif_guild_message (g, account_id, mes, len);
- return 0;
-}
-
-// ギルドメンãƒã®å½¹è·å¤‰æ›´
-int guild_change_memberposition (int guild_id, int account_id, int char_id,
- int idx)
-{
- return intif_guild_change_memberinfo (guild_id, account_id, 0 /*char_id*/,
- GMI_POSITION, &idx, sizeof (idx));
-}
-
-// ギルドメンãƒã®å½¹è·å¤‰æ›´é€šçŸ¥
-int guild_memberposition_changed (struct guild *g, int idx, int pos)
-{
- nullpo_retr (0, g);
-
- g->member[idx].position = pos;
- clif_guild_memberpositionchanged (g, idx);
- return 0;
-}
-
-// ギルド役è·å¤‰æ›´
-int guild_change_position (struct map_session_data *sd, int idx,
- int mode, int exp_mode, const char *name)
-{
- struct guild_position p;
-
- nullpo_retr (0, sd);
-
- if (exp_mode > battle_config.guild_exp_limit)
- exp_mode = battle_config.guild_exp_limit;
- if (exp_mode < 0)
- exp_mode = 0;
- p.mode = mode;
- p.exp_mode = exp_mode;
- memcpy (p.name, name, 24);
- return intif_guild_position (sd->status.guild_id, idx, &p);
-}
-
-// ギルド役è·å¤‰æ›´é€šçŸ¥
-int guild_position_changed (int guild_id, int idx, struct guild_position *p)
-{
- struct guild *g = guild_search (guild_id);
- if (g == NULL)
- return 0;
- memcpy (&g->position[idx], p, sizeof (struct guild_position));
- clif_guild_positionchanged (g, idx);
- return 0;
-}
-
-// ギルド告知変更
-int guild_change_notice (struct map_session_data *sd, int guild_id,
- const char *mes1, const char *mes2)
-{
- struct guild *g;
- int ps;
-
- nullpo_retr (0, sd);
-
- g = guild_search (sd->status.guild_id);
-
- if (g == NULL)
- return 0;
-
- if ((ps = guild_getposition (sd, g)) < 0
- || !(g->position[ps].mode & 0x0010))
- return 0;
-
- if (guild_id != sd->status.guild_id)
- return 0;
-
- return intif_guild_notice (guild_id, mes1, mes2);
-}
-
-// ギルド告知変更通知
-int guild_notice_changed (int guild_id, const char *mes1, const char *mes2)
-{
- int i;
- struct map_session_data *sd;
- struct guild *g = guild_search (guild_id);
- if (g == NULL)
- return 0;
-
- memcpy (g->mes1, mes1, 60);
- memcpy (g->mes2, mes2, 120);
-
- for (i = 0; i < g->max_member; i++)
- {
- if ((sd = g->member[i].sd) != NULL)
- clif_guild_notice (sd, g);
- }
- return 0;
-}
-
-// ギルドエンブレム変更
-int guild_change_emblem (struct map_session_data *sd, int len,
- const char *data)
-{
- struct guild *g;
- int ps;
-
- nullpo_retr (0, sd);
-
- g = guild_search (sd->status.guild_id);
-
- if (g == NULL)
- return 0;
-
- if ((ps = guild_getposition (sd, g)) < 0
- || !(g->position[ps].mode & 0x0010))
- return 0;
-
- return intif_guild_emblem (sd->status.guild_id, len, data);
-}
-
-// ギルドエンブレム変更通知
-int guild_emblem_changed (int len, int guild_id, int emblem_id,
- const char *data)
-{
- int i;
- struct map_session_data *sd;
- struct guild *g = guild_search (guild_id);
- if (g == NULL)
- return 0;
-
- memcpy (g->emblem_data, data, len);
- g->emblem_len = len;
- g->emblem_id = emblem_id;
-
- for (i = 0; i < g->max_member; i++)
- {
- if ((sd = g->member[i].sd) != NULL)
- {
- sd->guild_emblem_id = emblem_id;
- clif_guild_belonginfo (sd, g);
- clif_guild_emblem (sd, g);
- }
- }
- return 0;
-}
-
-// ギルドã®EXP上ç´
-int guild_payexp (struct map_session_data *sd, int exp)
-{
- struct guild *g;
- struct guild_expcache *c;
- int per, exp2;
-
- nullpo_retr (0, sd);
-
- if (sd->status.guild_id == 0
- || (g = guild_search (sd->status.guild_id)) == NULL)
- return 0;
- if ((per = g->position[guild_getposition (sd, g)].exp_mode) <= 0)
- return 0;
- if (per > 100)
- per = 100;
-
- if ((exp2 = exp * per / 100) <= 0)
- return 0;
-
- if ((c = (struct guild_expcache *)numdb_search (guild_expcache_db, sd->status.account_id /*char_id*/)) == NULL)
- {
- CREATE (c, struct guild_expcache, 1);
- c->guild_id = sd->status.guild_id;
- c->account_id = sd->status.account_id;
- c->char_id = 0;
- c->exp = exp2;
- numdb_insert (guild_expcache_db, c->account_id /*char_id*/, c);
- }
- else
- {
- c->exp += exp2;
- }
- return exp2;
-}
-
-// スキルãƒã‚¤ãƒ³ãƒˆå‰²ã‚ŠæŒ¯ã‚Š
-int guild_skillup (struct map_session_data *sd, int skill_num)
-{
- struct guild *g;
- int idx;
-
- nullpo_retr (0, sd);
-
- if (sd->status.guild_id == 0
- || (g = guild_search (sd->status.guild_id)) == NULL)
- return 0;
- if (strcmp (sd->status.name, g->master))
- return 0;
-
- if (g->skill_point > 0 &&
- g->skill[(idx = skill_num - 10000)].id != 0 &&
- g->skill[idx].lv < guild_skill_get_max (skill_num))
- {
- intif_guild_skillup (g->guild_id, skill_num, sd->status.account_id);
- }
- return 0;
-}
-
-// スキルãƒã‚¤ãƒ³ãƒˆå‰²ã‚ŠæŒ¯ã‚Šé€šçŸ¥
-int guild_skillupack (int guild_id, int skill_num, int account_id)
-{
- struct map_session_data *sd = map_id2sd (account_id);
- struct guild *g = guild_search (guild_id);
- int i;
- if (g == NULL)
- return 0;
- if (sd != NULL)
- clif_guild_skillup (sd, skill_num, g->skill[skill_num - 10000].lv);
- // 全員ã«é€šçŸ¥
- for (i = 0; i < g->max_member; i++)
- if ((sd = g->member[i].sd) != NULL)
- clif_guild_skillinfo (sd);
- return 0;
-}
-
-// ギルドåŒç›Ÿæ•°æ‰€å¾—
-static
-int guild_get_alliance_count (struct guild *g, int flag)
-{
- int i, c;
-
- nullpo_retr (0, g);
-
- for (i = c = 0; i < MAX_GUILDALLIANCE; i++)
- {
- if (g->alliance[i].guild_id > 0 && g->alliance[i].opposition == flag)
- c++;
- }
- return c;
-}
-
-// ギルドåŒç›Ÿè¦æ±‚
-int guild_reqalliance (struct map_session_data *sd, int account_id)
-{
- struct map_session_data *tsd = map_id2sd (account_id);
- struct guild *g[2];
- int i, ps;
-
- if (agit_flag)
- { // Disable alliance creation during woe [Valaris]
- clif_displaymessage (sd->fd,
- "Alliances cannot be made during Guild Wars!");
- return 0;
- } // end addition [Valaris]
-
- nullpo_retr (0, sd);
-
- if (tsd == NULL || tsd->status.guild_id <= 0)
- return 0;
-
- g[0] = guild_search (sd->status.guild_id);
- g[1] = guild_search (tsd->status.guild_id);
-
- if (g[0] == NULL || g[1] == NULL)
- return 0;
-
- if ((ps = guild_getposition (sd, g[0])) < 0
- || !(g[0]->position[ps].mode & 0x0010))
- return 0;
-
- if (guild_get_alliance_count (g[0], 0) > 3) // åŒç›Ÿæ•°ç¢ºèª
- clif_guild_allianceack (sd, 4);
- if (guild_get_alliance_count (g[1], 0) > 3)
- clif_guild_allianceack (sd, 3);
-
- if (tsd->guild_alliance > 0)
- { // 相手ãŒåŒç›Ÿè¦è«‹çŠ¶æ…‹ã‹ã©ã†ã‹ç¢ºèª
- clif_guild_allianceack (sd, 1);
- return 0;
- }
-
- for (i = 0; i < MAX_GUILDALLIANCE; i++)
- { // ã™ã§ã«åŒç›ŸçŠ¶æ…‹ã‹ç¢ºèª
- if (g[0]->alliance[i].guild_id == tsd->status.guild_id &&
- g[0]->alliance[i].opposition == 0)
- {
- clif_guild_allianceack (sd, 0);
- return 0;
- }
- }
-
- tsd->guild_alliance = sd->status.guild_id;
- tsd->guild_alliance_account = sd->status.account_id;
-
- clif_guild_reqalliance (tsd, sd->status.account_id, g[0]->name);
- return 0;
-}
-
-// ギルド勧誘ã¸ã®è¿”ç­”
-int guild_reply_reqalliance (struct map_session_data *sd, int account_id,
- int flag)
-{
- struct map_session_data *tsd;
-
- nullpo_retr (0, sd);
- nullpo_retr (0, tsd = map_id2sd (account_id));
-
- if (sd->guild_alliance != tsd->status.guild_id) // 勧誘ã¨ã‚®ãƒ«ãƒ‰IDãŒé•ã†
- return 0;
-
- if (flag == 1)
- { // 承諾
- int i;
-
- struct guild *g; // åŒç›Ÿæ•°å†ç¢ºèª
- if ((g = guild_search (sd->status.guild_id)) == NULL ||
- guild_get_alliance_count (g, 0) > 3)
- {
- clif_guild_allianceack (sd, 4);
- clif_guild_allianceack (tsd, 3);
- return 0;
- }
- if ((g = guild_search (tsd->status.guild_id)) == NULL ||
- guild_get_alliance_count (g, 0) > 3)
- {
- clif_guild_allianceack (sd, 3);
- clif_guild_allianceack (tsd, 4);
- return 0;
- }
-
- // 敵対関係ãªã‚‰æ•µå¯¾ã‚’æ­¢ã‚ã‚‹
- if ((g = guild_search (sd->status.guild_id)) == NULL)
- return 0;
- for (i = 0; i < MAX_GUILDALLIANCE; i++)
- {
- if (g->alliance[i].guild_id == tsd->status.guild_id &&
- g->alliance[i].opposition == 1)
- intif_guild_alliance (sd->status.guild_id,
- tsd->status.guild_id,
- sd->status.account_id,
- tsd->status.account_id, 9);
- }
- if ((g = guild_search (tsd->status.guild_id)) == NULL)
- return 0;
- for (i = 0; i < MAX_GUILDALLIANCE; i++)
- {
- if (g->alliance[i].guild_id == sd->status.guild_id &&
- g->alliance[i].opposition == 1)
- intif_guild_alliance (tsd->status.guild_id,
- sd->status.guild_id,
- tsd->status.account_id,
- sd->status.account_id, 9);
- }
-
- // inter鯖ã¸åŒç›Ÿè¦è«‹
- intif_guild_alliance (sd->status.guild_id, tsd->status.guild_id,
- sd->status.account_id, tsd->status.account_id,
- 0);
- return 0;
- }
- else
- { // æ‹’å¦
- sd->guild_alliance = 0;
- sd->guild_alliance_account = 0;
- if (tsd != NULL)
- clif_guild_allianceack (tsd, 3);
- }
- return 0;
-}
-
-// ギルド関係解消
-int guild_delalliance (struct map_session_data *sd, int guild_id, int flag)
-{
- if (agit_flag)
- { // Disable alliance breaking during woe [Valaris]
- clif_displaymessage (sd->fd,
- "Alliances cannot be broken during Guild Wars!");
- return 0;
- } // end addition [Valaris]
-
- struct guild *g;
- int ps;
-
- nullpo_retr (0, sd);
-
- g = guild_search (sd->status.guild_id);
-
- if (g == NULL)
- return 0;
-
- if ((ps = guild_getposition (sd, g)) < 0
- || !(g->position[ps].mode & 0x0010))
- return 0;
-
- intif_guild_alliance (sd->status.guild_id, guild_id,
- sd->status.account_id, 0, flag | 8);
- return 0;
-}
-
-// ギルド敵対
-int guild_opposition (struct map_session_data *sd, int account_id /*char_id*/)
-{
- struct map_session_data *tsd = map_id2sd (account_id /*char_id*/);
- struct guild *g;
- int i, ps;
-
- nullpo_retr (0, sd);
-
- g = guild_search (sd->status.guild_id);
- if (g == NULL || tsd == NULL)
- return 0;
-
- if ((ps = guild_getposition (sd, g)) < 0
- || !(g->position[ps].mode & 0x0010))
- return 0;
-
- if (guild_get_alliance_count (g, 1) > 3) // 敵対数確èª
- clif_guild_oppositionack (sd, 1);
-
- for (i = 0; i < MAX_GUILDALLIANCE; i++)
- { // ã™ã§ã«é–¢ä¿‚ã‚’æŒã£ã¦ã„ã‚‹ã‹ç¢ºèª
- if (g->alliance[i].guild_id == tsd->status.guild_id)
- {
- if (g->alliance[i].opposition == 1)
- { // ã™ã§ã«æ•µå¯¾
- clif_guild_oppositionack (sd, 2);
- return 0;
- }
- else // åŒç›Ÿç ´æ£„
- intif_guild_alliance (sd->status.guild_id,
- tsd->status.guild_id,
- sd->status.account_id,
- tsd->status.account_id, 8);
- }
- }
-
- // inter鯖ã«æ•µå¯¾è¦è«‹
- intif_guild_alliance (sd->status.guild_id, tsd->status.guild_id,
- sd->status.account_id, tsd->status.account_id, 1);
- return 0;
-}
-
-// ギルドåŒç›Ÿ/敵対通知
-int guild_allianceack (int guild_id1, int guild_id2, int account_id1,
- int account_id2, int flag, const char *name1,
- const char *name2)
-{
- struct guild *g[2];
- int guild_id[2] = { guild_id1, guild_id2 };
- const char *guild_name[2] = { name1, name2 };
- struct map_session_data *sd[2] =
- { map_id2sd (account_id1), map_id2sd (account_id2) };
- int j, i;
-
- g[0] = guild_search (guild_id1);
- g[1] = guild_search (guild_id2);
-
- if (sd[0] != NULL && (flag & 0x0f) == 0)
- {
- sd[0]->guild_alliance = 0;
- sd[0]->guild_alliance_account = 0;
- }
-
- if (flag & 0x70)
- { // 失敗
- for (i = 0; i < 2 - (flag & 1); i++)
- if (sd[i] != NULL)
- clif_guild_allianceack (sd[i],
- ((flag >> 4) == i + 1) ? 3 : 4);
- return 0;
- }
-// if(battle_config.etc_log)
-// printf("guild alliance_ack %d %d %d %d %d %s %s\n",guild_id1,guild_id2,account_id1,account_id2,flag,name1,name2);
-
- if (!(flag & 0x08))
- { // 関係追加
- for (i = 0; i < 2 - (flag & 1); i++)
- if (g[i] != NULL)
- for (j = 0; j < MAX_GUILDALLIANCE; j++)
- if (g[i]->alliance[j].guild_id == 0)
- {
- g[i]->alliance[j].guild_id = guild_id[1 - i];
- memcpy (g[i]->alliance[j].name, guild_name[1 - i],
- 24);
- g[i]->alliance[j].opposition = flag & 1;
- break;
- }
- }
- else
- { // 関係解消
- for (i = 0; i < 2 - (flag & 1); i++)
- {
- if (g[i] != NULL)
- for (j = 0; j < MAX_GUILDALLIANCE; j++)
- if (g[i]->alliance[j].guild_id == guild_id[1 - i] &&
- g[i]->alliance[j].opposition == (flag & 1))
- {
- g[i]->alliance[j].guild_id = 0;
- break;
- }
- if (sd[i] != NULL) // 解消通知
- clif_guild_delalliance (sd[i], guild_id[1 - i], (flag & 1));
- }
- }
-
- if ((flag & 0x0f) == 0)
- { // åŒç›Ÿé€šçŸ¥
- if (sd[1] != NULL)
- clif_guild_allianceack (sd[1], 2);
- }
- else if ((flag & 0x0f) == 1)
- { // 敵対通知
- if (sd[0] != NULL)
- clif_guild_oppositionack (sd[0], 0);
- }
-
- for (i = 0; i < 2 - (flag & 1); i++)
- { // åŒç›Ÿ/敵対リストã®å†é€ä¿¡
- struct map_session_data *sd;
- if (g[i] != NULL)
- for (j = 0; j < g[i]->max_member; j++)
- if ((sd = g[i]->member[j].sd) != NULL)
- clif_guild_allianceinfo (sd);
- }
- return 0;
-}
-
-// ギルド解散通知用
-static
-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_retv (g);
-
- for (i = 0; i < MAX_GUILDALLIANCE; i++)
- { // 関係を破棄
- if (g->alliance[i].guild_id == guild_id)
- {
- for (j = 0; j < g->max_member; j++)
- if ((sd = g->member[j].sd) != NULL)
- clif_guild_delalliance (sd, guild_id,
- g->alliance[i].opposition);
- g->alliance[i].guild_id = 0;
- }
- }
-}
-
-// ギルド解散通知
-int guild_broken (int guild_id, int flag)
-{
- struct guild *g = guild_search (guild_id);
- struct map_session_data *sd;
- int i;
- if (flag != 0 || g == NULL)
- return 0;
-
- for (i = 0; i < g->max_member; i++)
- { // ギルド解散を通知
- if ((sd = g->member[i].sd) != NULL)
- {
- if (sd->state.storage_flag == 2)
- storage_guild_storage_quit (sd, 1);
- sd->status.guild_id = 0;
- sd->guild_sended = 0;
- clif_guild_broken (g->member[i].sd, 0);
- }
- }
-
- numdb_foreach (guild_db, guild_broken_sub, guild_id);
- numdb_erase (guild_db, guild_id);
- guild_storage_delete (guild_id);
- free (g);
- return 0;
-}
-
-// ギルド解散
-int guild_break (struct map_session_data *sd, const char *name)
-{
- struct guild *g;
- int i;
-
- nullpo_retr (0, sd);
-
- if ((g = guild_search (sd->status.guild_id)) == NULL)
- return 0;
- if (strcmp (g->name, name) != 0)
- return 0;
- if (strcmp (sd->status.name, g->master) != 0)
- return 0;
- for (i = 0; i < g->max_member; i++)
- {
- if (g->member[i].account_id > 0
- && (g->member[i].account_id != sd->status.account_id))
- break;
- }
- if (i < g->max_member)
- {
- clif_guild_broken (sd, 2);
- return 0;
- }
-
- intif_guild_break (g->guild_id);
- return 0;
-}
-
-// ギルド城データè¦æ±‚
-int guild_castledataload (int castle_id, int index)
-{
- return intif_guild_castle_dataload (castle_id, index);
-}
-
-// ギルド城情報所得時イベント追加
-int guild_addcastleinfoevent (int castle_id, int index, const char *name)
-{
- struct eventlist *ev;
- int code = castle_id | (index << 16);
-
- if (name == NULL || *name == 0)
- return 0;
-
- CREATE (ev, struct eventlist, 1);
- memcpy (ev->name, name, sizeof (ev->name));
- ev->next = (struct eventlist *)numdb_search (guild_castleinfoevent_db, code);
- numdb_insert (guild_castleinfoevent_db, code, ev);
- return 0;
-}
-
-// ギルド城データè¦æ±‚返信
-int guild_castledataloadack (int castle_id, int index, int value)
-{
- struct guild_castle *gc = guild_castle_search (castle_id);
- int code = castle_id | (index << 16);
- struct eventlist *ev, *ev2;
-
- if (gc == NULL)
- {
- return 0;
- }
- switch (index)
- {
- case 1:
- 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 ("guild_castledataloadack ERROR!! (Not found index=%d)\n",
- index);
- return 0;
- }
- if ((ev = (struct eventlist *)numdb_search (guild_castleinfoevent_db, code)) != NULL)
- {
- numdb_erase (guild_castleinfoevent_db, code);
- for (; ev; ev2 = ev->next, free (ev), ev = ev2)
- {
- npc_event_do (ev->name);
- }
- }
- return 1;
-}
-
-// ギルド城データ変更è¦æ±‚
-int guild_castledatasave (int castle_id, int index, int value)
-{
- return intif_guild_castle_datasave (castle_id, index, value);
-}
-
-// ギルド城データ変更通知
-int guild_castledatasaveack (int castle_id, int index, int value)
-{
- struct guild_castle *gc = guild_castle_search (castle_id);
- if (gc == NULL)
- {
- return 0;
- }
- switch (index)
- {
- case 1:
- 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 ("guild_castledatasaveack ERROR!! (Not found index=%d)\n",
- index);
- return 0;
- }
- return 1;
-}
-
-// ギルドデータ一括å—信(åˆæœŸåŒ–時)
-int guild_castlealldataload (int len, struct guild_castle *gc)
-{
- int i;
- int n = (len - 4) / sizeof (struct guild_castle), ev = -1;
-
- nullpo_retr (0, gc);
-
- // イベント付ãã§è¦æ±‚ã™ã‚‹ãƒ‡ãƒ¼ã‚¿ä½ç½®ã‚’探ã™(最後ã®å æ‹ ãƒ‡ãƒ¼ã‚¿)
- for (i = 0; i < n; i++)
- {
- if ((gc + i)->guild_id)
- ev = i;
- }
-
- // 城データ格ç´ã¨ã‚®ãƒ«ãƒ‰æƒ…å ±è¦æ±‚
- for (i = 0; i < n; i++, gc++)
- {
- struct guild_castle *c = guild_castle_search (gc->castle_id);
- if (!c)
- {
- printf ("guild_castlealldataload ??\n");
- continue;
- }
- memcpy (&c->guild_id, &gc->guild_id,
- sizeof (struct guild_castle) - ((int) &c->guild_id -
- (int) c));
- if (c->guild_id)
- {
- if (i != ev)
- guild_request_info (c->guild_id);
- else
- guild_npc_request_info (c->guild_id, "::OnAgitInit");
- }
- }
- if (ev == -1)
- npc_event_doall ("OnAgitInit");
- return 0;
-}
-
-int guild_agit_start (void)
-{ // Run All NPC_Event[OnAgitStart]
- int c = npc_event_doall ("OnAgitStart");
- printf ("NPC_Event:[OnAgitStart] Run (%d) Events by @AgitStart.\n", c);
- return 0;
-}
-
-int guild_agit_end (void)
-{ // Run All NPC_Event[OnAgitEnd]
- int c = npc_event_doall ("OnAgitEnd");
- printf ("NPC_Event:[OnAgitEnd] Run (%d) Events by @AgitEnd.\n", c);
- return 0;
-}
-
-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;
- CREATE (evname, char, len + 4);
- int c = 0;
-
- if (!agit_flag)
- 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);
-}
-
-int guild_agit_break (struct mob_data *md)
-{ // Run One NPC_Event[OnAgitBreak]
- char *evname;
-
- nullpo_retr (0, md);
-
- CREATE (evname, char, strlen (md->npc_event) + 1);
-
- strcpy (evname, md->npc_event);
-// Now By User to Run [OnAgitBreak] NPC Event...
-// It's a little impossible to null point with player disconnect in this!
-// But Script will be stop, so nothing...
-// Maybe will be changed in the futher..
-// int c = npc_event_do(evname);
- if (!agit_flag)
- return 0; // Agit already End
- add_timer (gettick () + battle_config.gvg_eliminate_time,
- guild_gvg_eliminate_timer, md->bl.m, (int) evname);
- return 0;
-}
-
-// [MouseJstr]
-// How many castles does this guild have?
-int guild_checkcastles (struct guild *g)
-{
- int i, nb_cas = 0, id, cas_id = 0;
- struct guild_castle *gc;
- id = g->guild_id;
- for (i = 0; i < MAX_GUILDCASTLE; i++)
- {
- gc = guild_castle_search (i);
- cas_id = gc->guild_id;
- if (g->guild_id == cas_id)
- nb_cas = nb_cas + 1;
- } //end for
- return nb_cas;
-}
-
-// [MouseJstr]
-// is this guild allied with this castle?
-int guild_isallied (struct guild *g, struct guild_castle *gc)
-{
- int i;
-
- nullpo_retr (0, g);
-
- if (g->guild_id == gc->guild_id)
- return 1;
-
- if (gc->guild_id == 0)
- return 0;
-
- for (i = 0; i < MAX_GUILDALLIANCE; i++)
- if (g->alliance[i].guild_id == gc->guild_id)
- {
- if (g->alliance[i].opposition == 0)
- return 1;
- else
- return 0;
- }
-
- return 0;
-}
-
-static void guild_db_final (db_key_t key, db_val_t data, va_list ap)
-{
- free (data);
-}
-
-static void castle_db_final (db_key_t key, db_val_t data, va_list ap)
-{
- free (data);
-}
-
-static void guild_expcache_db_final (db_key_t key, db_val_t data, va_list ap)
-{
- free (data);
-}
-
-static void guild_infoevent_db_final (db_key_t key, db_val_t data, va_list ap)
-{
- free (data);
-}
-
-void do_final_guild (void)
-{
- if (guild_db)
- numdb_final (guild_db, guild_db_final);
- if (castle_db)
- numdb_final (castle_db, castle_db_final);
- if (guild_expcache_db)
- numdb_final (guild_expcache_db, guild_expcache_db_final);
- if (guild_infoevent_db)
- numdb_final (guild_infoevent_db, guild_infoevent_db_final);
- if (guild_castleinfoevent_db)
- numdb_final (guild_castleinfoevent_db, guild_infoevent_db_final);
-}
diff --git a/src/map/guild.hpp b/src/map/guild.hpp
deleted file mode 100644
index 983934c..0000000
--- a/src/map/guild.hpp
+++ /dev/null
@@ -1,95 +0,0 @@
-// $Id: guild.h,v 1.4 2004/09/25 05:32:18 MouseJstr Exp $
-#ifndef GUILD_HPP
-#define GUILD_HPP
-
-struct map_session_data;
-struct mob_data;
-struct guild;
-struct guild_member;
-struct guild_position;
-struct guild_castle;
-
-int guild_skill_get_inf (int id);
-int guild_skill_get_sp (int id, int lv);
-int guild_skill_get_range (int id);
-int guild_skill_get_max (int id);
-
-int guild_checkskill (struct guild *g, int id);
-int guild_checkcastles (struct guild *g); // [MouseJstr]
-int guild_isallied (struct guild *g, struct guild_castle *gc);
-
-void do_init_guild (void);
-struct guild *guild_search (int guild_id);
-struct guild *guild_searchname (const char *str);
-struct guild_castle *guild_castle_search (int gcid);
-
-struct guild_castle *guild_mapname2gc (const char *mapname);
-
-struct map_session_data *guild_getavailablesd (struct guild *g);
-int guild_getindex (struct guild *g, int account_id, int char_id);
-int guild_getposition (struct map_session_data *sd, struct guild *g);
-int guild_payexp (struct map_session_data *sd, int exp);
-
-int guild_create (struct map_session_data *sd, const char *name);
-int guild_created (int account_id, int guild_id);
-int guild_request_info (int guild_id);
-int guild_recv_noinfo (int guild_id);
-int guild_recv_info (struct guild *sg);
-int guild_npc_request_info (int guild_id, const char *ev);
-int guild_invite (struct map_session_data *sd, int account_id);
-int guild_reply_invite (struct map_session_data *sd, int guild_id, int flag);
-int guild_member_added (int guild_id, int account_id, int char_id, int flag);
-int guild_leave (struct map_session_data *sd, int guild_id,
- int account_id, int char_id, const char *mes);
-int guild_member_leaved (int guild_id, int account_id, int char_id, int flag,
- const char *name, const char *mes);
-int guild_explusion (struct map_session_data *sd, int guild_id,
- int account_id, int char_id, const char *mes);
-int guild_skillup (struct map_session_data *sd, int skill_num);
-int guild_reqalliance (struct map_session_data *sd, int account_id);
-int guild_reply_reqalliance (struct map_session_data *sd, int account_id,
- int flag);
-int guild_alliance (int guild_id1, int guild_id2, int account_id1,
- int account_id2);
-int guild_allianceack (int guild_id1, int guild_id2, int account_id1,
- int account_id2, int flag, const char *name1,
- const char *name2);
-int guild_delalliance (struct map_session_data *sd, int guild_id, int flag);
-int guild_opposition (struct map_session_data *sd, int char_id);
-
-int guild_send_memberinfoshort (struct map_session_data *sd, int online);
-int guild_recv_memberinfoshort (int guild_id, int account_id, int char_id,
- int online, int lv, int class_);
-int guild_change_memberposition (int guild_id, int account_id, int char_id,
- int idx);
-int guild_memberposition_changed (struct guild *g, int idx, int pos);
-int guild_change_position (struct map_session_data *sd, int idx,
- int mode, int exp_mode, const char *name);
-int guild_position_changed (int guild_id, int idx, struct guild_position *p);
-int guild_change_notice (struct map_session_data *sd, int guild_id,
- const char *mes1, const char *mes2);
-int guild_notice_changed (int guild_id, const char *mes1, const char *mes2);
-int guild_change_emblem (struct map_session_data *sd, int len,
- const char *data);
-int guild_emblem_changed (int len, int guild_id, int emblem_id,
- const char *data);
-int guild_send_message (struct map_session_data *sd, const char *mes, int len);
-int guild_recv_message (int guild_id, int account_id, const char *mes, int len);
-int guild_skillupack (int guild_id, int skill_num, int account_id);
-int guild_break (struct map_session_data *sd, const char *name);
-int guild_broken (int guild_id, int flag);
-
-int guild_addcastleinfoevent (int castle_id, int index, const char *name);
-int guild_castledataload (int castle_id, int index);
-int guild_castledataloadack (int castle_id, int index, int value);
-int guild_castledatasave (int castle_id, int index, int value);
-int guild_castledatasaveack (int castle_id, int index, int value);
-int guild_castlealldataload (int len, struct guild_castle *gc);
-
-int guild_agit_start (void);
-int guild_agit_end (void);
-int guild_agit_break (struct mob_data *md);
-
-void do_final_guild (void);
-
-#endif
diff --git a/src/map/intif.cpp b/src/map/intif.cpp
index dfbc665..6c8edf5 100644
--- a/src/map/intif.cpp
+++ b/src/map/intif.cpp
@@ -1,42 +1,24 @@
-// $Id: intif.c,v 1.2 2004/09/25 05:32:18 MouseJstr Exp $
-#include <sys/types.h>
-#ifdef LCCWIN32
-#include <winsock.h>
-#else
-#include <sys/socket.h>
-#include <netinet/in.h>
-#endif
-#include <stdio.h>
-#include <stdlib.h>
-#ifndef LCCWIN32
-#include <sys/time.h>
-#include <sys/ioctl.h>
-#include <unistd.h>
-#include <arpa/inet.h>
-#endif
-#include <signal.h>
-#include <fcntl.h>
-#include <string.h>
+#include "intif.hpp"
+
+#include <cstdlib>
+#include <cstring>
+#include "../common/cxxstdio.hpp"
#include "../common/nullpo.hpp"
#include "../common/socket.hpp"
-#include "../common/timer.hpp"
#include "battle.hpp"
#include "chrif.hpp"
#include "clif.hpp"
-#include "guild.hpp"
-#include "intif.hpp"
#include "map.hpp"
#include "party.hpp"
#include "pc.hpp"
#include "storage.hpp"
-#ifdef MEMWATCH
-#include "memwatch.hpp"
-#endif
+#include "../poison.hpp"
-static const int packet_len_table[] = {
+static
+const int packet_len_table[] = {
-1, -1, 27, -1, -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,
@@ -48,40 +30,37 @@ static const int packet_len_table[] = {
11, -1, 7, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
};
-extern int char_fd; // inter serverã®fdã¯char_fdを使ã†
-#define inter_fd (char_fd) // エイリアス
//-----------------------------------------------------------------
// inter serverã¸ã®é€ä¿¡
// Message for all GMs on all map servers
-int intif_GMmessage (const char *mes, int len, int flag)
+void intif_GMmessage(const_string mes, int flag)
{
- int lp = (flag & 0x10) ? 8 : 4;
- WFIFOW (inter_fd, 0) = 0x3000;
- WFIFOW (inter_fd, 2) = lp + len;
- WFIFOL (inter_fd, 4) = 0x65756c62;
- memcpy (WFIFOP (inter_fd, lp), mes, len);
- WFIFOSET (inter_fd, WFIFOW (inter_fd, 2));
-
- return 0;
+ int lp = (flag & 0x10) ? 8 : 4;
+ WFIFOW(char_fd, 0) = 0x3000;
+ WFIFOW(char_fd, 2) = lp + mes.size() + 1;
+ WFIFOL(char_fd, 4) = 0x65756c62;
+ memcpy(WFIFOP(char_fd, lp), mes.data(), mes.size());
+ WFIFOB(char_fd, lp + mes.size()) = '\0';
+ WFIFOSET(char_fd, WFIFOW(char_fd, 2));
}
// The transmission of Wisp/Page to inter-server (player not found on this server)
-int intif_wis_message (struct map_session_data *sd, const char *nick, const char *mes,
+int intif_wis_message(struct map_session_data *sd, const char *nick, const char *mes,
int mes_len)
{
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
- WFIFOW (inter_fd, 0) = 0x3001;
- WFIFOW (inter_fd, 2) = mes_len + 52;
- memcpy (WFIFOP (inter_fd, 4), sd->status.name, 24);
- memcpy (WFIFOP (inter_fd, 28), nick, 24);
- memcpy (WFIFOP (inter_fd, 52), mes, mes_len);
- WFIFOSET (inter_fd, WFIFOW (inter_fd, 2));
+ WFIFOW(char_fd, 0) = 0x3001;
+ WFIFOW(char_fd, 2) = mes_len + 52;
+ memcpy(WFIFOP(char_fd, 4), sd->status.name, 24);
+ memcpy(WFIFOP(char_fd, 28), nick, 24);
+ memcpy(WFIFOP(char_fd, 52), mes, mes_len);
+ WFIFOSET(char_fd, WFIFOW(char_fd, 2));
if (battle_config.etc_log)
- printf ("intif_wis_message from %s to %s (message: '%s')\n",
+ PRINTF("intif_wis_message from %s to %s (message: '%s')\n",
sd->status.name, nick, mes);
return 0;
@@ -89,437 +68,200 @@ int intif_wis_message (struct map_session_data *sd, const char *nick, const char
// The reply of Wisp/page
static
-int intif_wis_replay (int id, int flag)
+int intif_wis_replay(int id, int flag)
{
- WFIFOW (inter_fd, 0) = 0x3002;
- WFIFOL (inter_fd, 2) = id;
- WFIFOB (inter_fd, 6) = flag; // flag: 0: success to send wisper, 1: target character is not loged in?, 2: ignored by target
- WFIFOSET (inter_fd, 7);
+ WFIFOW(char_fd, 0) = 0x3002;
+ WFIFOL(char_fd, 2) = id;
+ WFIFOB(char_fd, 6) = flag; // flag: 0: success to send wisper, 1: target character is not loged in?, 2: ignored by target
+ WFIFOSET(char_fd, 7);
if (battle_config.etc_log)
- printf ("intif_wis_replay: id: %d, flag:%d\n", id, flag);
+ PRINTF("intif_wis_replay: id: %d, flag:%d\n", id, flag);
return 0;
}
// The transmission of GM only Wisp/Page from server to inter-server
-int intif_wis_message_to_gm (const char *Wisp_name, int min_gm_level, const char *mes,
+int intif_wis_message_to_gm(const char *Wisp_name, int min_gm_level, const char *mes,
int mes_len)
{
- WFIFOW (inter_fd, 0) = 0x3003;
- WFIFOW (inter_fd, 2) = mes_len + 30;
- memcpy (WFIFOP (inter_fd, 4), Wisp_name, 24);
- WFIFOW (inter_fd, 28) = (short) min_gm_level;
- memcpy (WFIFOP (inter_fd, 30), mes, mes_len);
- WFIFOSET (inter_fd, WFIFOW (inter_fd, 2));
+ WFIFOW(char_fd, 0) = 0x3003;
+ WFIFOW(char_fd, 2) = mes_len + 30;
+ memcpy(WFIFOP(char_fd, 4), Wisp_name, 24);
+ WFIFOW(char_fd, 28) = (short) min_gm_level;
+ memcpy(WFIFOP(char_fd, 30), mes, mes_len);
+ WFIFOSET(char_fd, WFIFOW(char_fd, 2));
if (battle_config.etc_log)
- printf
- ("intif_wis_message_to_gm: from: '%s', min level: %d, message: '%s'.\n",
+ PRINTF("intif_wis_message_to_gm: from: '%s', min level: %d, message: '%s'.\n",
Wisp_name, min_gm_level, mes);
return 0;
}
// アカウント変数é€ä¿¡
-int intif_saveaccountreg (struct map_session_data *sd)
+int intif_saveaccountreg(struct map_session_data *sd)
{
- int j, p;
+ int j, p;
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
- WFIFOW (inter_fd, 0) = 0x3004;
- WFIFOL (inter_fd, 4) = sd->bl.id;
+ WFIFOW(char_fd, 0) = 0x3004;
+ WFIFOL(char_fd, 4) = sd->bl.id;
for (j = 0, p = 8; j < sd->status.account_reg_num; j++, p += 36)
{
- memcpy (WFIFOP (inter_fd, p), sd->status.account_reg[j].str, 32);
- WFIFOL (inter_fd, p + 32) = sd->status.account_reg[j].value;
+ memcpy(WFIFOP(char_fd, p), sd->status.account_reg[j].str, 32);
+ WFIFOL(char_fd, p + 32) = sd->status.account_reg[j].value;
}
- WFIFOW (inter_fd, 2) = p;
- WFIFOSET (inter_fd, p);
+ WFIFOW(char_fd, 2) = p;
+ WFIFOSET(char_fd, p);
return 0;
}
// アカウント変数è¦æ±‚
-int intif_request_accountreg (struct map_session_data *sd)
+int intif_request_accountreg(struct map_session_data *sd)
{
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
- WFIFOW (inter_fd, 0) = 0x3005;
- WFIFOL (inter_fd, 2) = sd->bl.id;
- WFIFOSET (inter_fd, 6);
+ WFIFOW(char_fd, 0) = 0x3005;
+ WFIFOL(char_fd, 2) = sd->bl.id;
+ WFIFOSET(char_fd, 6);
return 0;
}
// 倉庫データè¦æ±‚
-int intif_request_storage (int account_id)
+int intif_request_storage(int account_id)
{
- WFIFOW (inter_fd, 0) = 0x3010;
- WFIFOL (inter_fd, 2) = account_id;
- WFIFOSET (inter_fd, 6);
+ WFIFOW(char_fd, 0) = 0x3010;
+ WFIFOL(char_fd, 2) = account_id;
+ WFIFOSET(char_fd, 6);
return 0;
}
// 倉庫データé€ä¿¡
-int intif_send_storage (struct storage *stor)
-{
- nullpo_retr (0, stor);
- WFIFOW (inter_fd, 0) = 0x3011;
- WFIFOW (inter_fd, 2) = sizeof (struct storage) + 8;
- WFIFOL (inter_fd, 4) = stor->account_id;
- memcpy (WFIFOP (inter_fd, 8), stor, sizeof (struct storage));
- WFIFOSET (inter_fd, WFIFOW (inter_fd, 2));
- return 0;
-}
-
-int intif_request_guild_storage (int account_id, int guild_id)
-{
- WFIFOW (inter_fd, 0) = 0x3018;
- WFIFOL (inter_fd, 2) = account_id;
- WFIFOL (inter_fd, 6) = guild_id;
- WFIFOSET (inter_fd, 10);
- return 0;
-}
-
-int intif_send_guild_storage (int account_id, struct guild_storage *gstor)
+int intif_send_storage(struct storage *stor)
{
- WFIFOW (inter_fd, 0) = 0x3019;
- WFIFOW (inter_fd, 2) = sizeof (struct guild_storage) + 12;
- WFIFOL (inter_fd, 4) = account_id;
- WFIFOL (inter_fd, 8) = gstor->guild_id;
- memcpy (WFIFOP (inter_fd, 12), gstor, sizeof (struct guild_storage));
- WFIFOSET (inter_fd, WFIFOW (inter_fd, 2));
+ nullpo_ret(stor);
+ WFIFOW(char_fd, 0) = 0x3011;
+ WFIFOW(char_fd, 2) = sizeof(struct storage) + 8;
+ WFIFOL(char_fd, 4) = stor->account_id;
+ memcpy(WFIFOP(char_fd, 8), stor, sizeof(struct storage));
+ WFIFOSET(char_fd, WFIFOW(char_fd, 2));
return 0;
}
// パーティ作æˆè¦æ±‚
-int intif_create_party (struct map_session_data *sd, const char *name)
+int intif_create_party(struct map_session_data *sd, const char *name)
{
- nullpo_retr (0, sd);
-
- WFIFOW (inter_fd, 0) = 0x3020;
- WFIFOL (inter_fd, 2) = sd->status.account_id;
- memcpy (WFIFOP (inter_fd, 6), name, 24);
- memcpy (WFIFOP (inter_fd, 30), sd->status.name, 24);
- memcpy (WFIFOP (inter_fd, 54), map[sd->bl.m].name, 16);
- WFIFOW (inter_fd, 70) = sd->status.base_level;
- WFIFOSET (inter_fd, 72);
+ nullpo_ret(sd);
+
+ WFIFOW(char_fd, 0) = 0x3020;
+ WFIFOL(char_fd, 2) = sd->status.account_id;
+ memcpy(WFIFOP(char_fd, 6), name, 24);
+ memcpy(WFIFOP(char_fd, 30), sd->status.name, 24);
+ memcpy(WFIFOP(char_fd, 54), map[sd->bl.m].name, 16);
+ WFIFOW(char_fd, 70) = sd->status.base_level;
+ WFIFOSET(char_fd, 72);
// if(battle_config.etc_log)
-// printf("intif: create party\n");
+// PRINTF("intif: create party\n");
return 0;
}
// パーティ情報è¦æ±‚
-int intif_request_partyinfo (int party_id)
+int intif_request_partyinfo(int party_id)
{
- WFIFOW (inter_fd, 0) = 0x3021;
- WFIFOL (inter_fd, 2) = party_id;
- WFIFOSET (inter_fd, 6);
+ WFIFOW(char_fd, 0) = 0x3021;
+ WFIFOL(char_fd, 2) = party_id;
+ WFIFOSET(char_fd, 6);
// if(battle_config.etc_log)
-// printf("intif: request party info\n");
+// PRINTF("intif: request party info\n");
return 0;
}
// パーティ追加è¦æ±‚
-int intif_party_addmember (int party_id, int account_id)
+int intif_party_addmember(int party_id, int account_id)
{
struct map_session_data *sd;
- sd = map_id2sd (account_id);
+ sd = map_id2sd(account_id);
// if(battle_config.etc_log)
-// printf("intif: party add member %d %d\n",party_id,account_id);
+// PRINTF("intif: party add member %d %d\n",party_id,account_id);
if (sd != NULL)
{
- WFIFOW (inter_fd, 0) = 0x3022;
- WFIFOL (inter_fd, 2) = party_id;
- WFIFOL (inter_fd, 6) = account_id;
- memcpy (WFIFOP (inter_fd, 10), sd->status.name, 24);
- memcpy (WFIFOP (inter_fd, 34), map[sd->bl.m].name, 16);
- WFIFOW (inter_fd, 50) = sd->status.base_level;
- WFIFOSET (inter_fd, 52);
+ WFIFOW(char_fd, 0) = 0x3022;
+ WFIFOL(char_fd, 2) = party_id;
+ WFIFOL(char_fd, 6) = account_id;
+ memcpy(WFIFOP(char_fd, 10), sd->status.name, 24);
+ memcpy(WFIFOP(char_fd, 34), map[sd->bl.m].name, 16);
+ WFIFOW(char_fd, 50) = sd->status.base_level;
+ WFIFOSET(char_fd, 52);
}
return 0;
}
// パーティ設定変更
-int intif_party_changeoption (int party_id, int account_id, int exp, int item)
+int intif_party_changeoption(int party_id, int account_id, int exp, int item)
{
- WFIFOW (inter_fd, 0) = 0x3023;
- WFIFOL (inter_fd, 2) = party_id;
- WFIFOL (inter_fd, 6) = account_id;
- WFIFOW (inter_fd, 10) = exp;
- WFIFOW (inter_fd, 12) = item;
- WFIFOSET (inter_fd, 14);
+ WFIFOW(char_fd, 0) = 0x3023;
+ WFIFOL(char_fd, 2) = party_id;
+ WFIFOL(char_fd, 6) = account_id;
+ WFIFOW(char_fd, 10) = exp;
+ WFIFOW(char_fd, 12) = item;
+ WFIFOSET(char_fd, 14);
return 0;
}
// パーティ脱退è¦æ±‚
-int intif_party_leave (int party_id, int account_id)
+int intif_party_leave(int party_id, int account_id)
{
// if(battle_config.etc_log)
-// printf("intif: party leave %d %d\n",party_id,account_id);
- WFIFOW (inter_fd, 0) = 0x3024;
- WFIFOL (inter_fd, 2) = party_id;
- WFIFOL (inter_fd, 6) = account_id;
- WFIFOSET (inter_fd, 10);
+// PRINTF("intif: party leave %d %d\n",party_id,account_id);
+ WFIFOW(char_fd, 0) = 0x3024;
+ WFIFOL(char_fd, 2) = party_id;
+ WFIFOL(char_fd, 6) = account_id;
+ WFIFOSET(char_fd, 10);
return 0;
}
// パーティ移動è¦æ±‚
-int intif_party_changemap (struct map_session_data *sd, int online)
+int intif_party_changemap(struct map_session_data *sd, int online)
{
if (sd != NULL)
{
- WFIFOW (inter_fd, 0) = 0x3025;
- WFIFOL (inter_fd, 2) = sd->status.party_id;
- WFIFOL (inter_fd, 6) = sd->status.account_id;
- memcpy (WFIFOP (inter_fd, 10), map[sd->bl.m].name, 16);
- WFIFOB (inter_fd, 26) = online;
- WFIFOW (inter_fd, 27) = sd->status.base_level;
- WFIFOSET (inter_fd, 29);
+ WFIFOW(char_fd, 0) = 0x3025;
+ WFIFOL(char_fd, 2) = sd->status.party_id;
+ WFIFOL(char_fd, 6) = sd->status.account_id;
+ memcpy(WFIFOP(char_fd, 10), map[sd->bl.m].name, 16);
+ WFIFOB(char_fd, 26) = online;
+ WFIFOW(char_fd, 27) = sd->status.base_level;
+ WFIFOSET(char_fd, 29);
}
// if(battle_config.etc_log)
-// printf("party: change map\n");
- return 0;
-}
-
-// パーティー解散è¦æ±‚
-int intif_break_party (int party_id)
-{
- WFIFOW (inter_fd, 0) = 0x3026;
- WFIFOL (inter_fd, 2) = party_id;
- WFIFOSET (inter_fd, 6);
+// PRINTF("party: change map\n");
return 0;
}
// パーティ会話é€ä¿¡
-int intif_party_message (int party_id, int account_id, const char *mes, int len)
+int intif_party_message(int party_id, int account_id, const char *mes, int len)
{
// if(battle_config.etc_log)
-// printf("intif_party_message: %s\n",mes);
- WFIFOW (inter_fd, 0) = 0x3027;
- WFIFOW (inter_fd, 2) = len + 12;
- WFIFOL (inter_fd, 4) = party_id;
- WFIFOL (inter_fd, 8) = account_id;
- memcpy (WFIFOP (inter_fd, 12), mes, len);
- WFIFOSET (inter_fd, len + 12);
+// PRINTF("intif_party_message: %s\n",mes);
+ WFIFOW(char_fd, 0) = 0x3027;
+ WFIFOW(char_fd, 2) = len + 12;
+ WFIFOL(char_fd, 4) = party_id;
+ WFIFOL(char_fd, 8) = account_id;
+ memcpy(WFIFOP(char_fd, 12), mes, len);
+ WFIFOSET(char_fd, len + 12);
return 0;
}
// パーティ競åˆãƒã‚§ãƒƒã‚¯è¦æ±‚
-int intif_party_checkconflict (int party_id, int account_id, const char *nick)
-{
- WFIFOW (inter_fd, 0) = 0x3028;
- WFIFOL (inter_fd, 2) = party_id;
- WFIFOL (inter_fd, 6) = account_id;
- memcpy (WFIFOP (inter_fd, 10), nick, 24);
- WFIFOSET (inter_fd, 34);
- return 0;
-}
-
-// ギルド作æˆè¦æ±‚
-int intif_guild_create (const char *name, const struct guild_member *master)
-{
- nullpo_retr (0, master);
-
- WFIFOW (inter_fd, 0) = 0x3030;
- WFIFOW (inter_fd, 2) = sizeof (struct guild_member) + 32;
- WFIFOL (inter_fd, 4) = master->account_id;
- memcpy (WFIFOP (inter_fd, 8), name, 24);
- memcpy (WFIFOP (inter_fd, 32), master, sizeof (struct guild_member));
- WFIFOSET (inter_fd, WFIFOW (inter_fd, 2));
- return 0;
-}
-
-// ギルド情報è¦æ±‚
-int intif_guild_request_info (int guild_id)
-{
- WFIFOW (inter_fd, 0) = 0x3031;
- WFIFOL (inter_fd, 2) = guild_id;
- WFIFOSET (inter_fd, 6);
- return 0;
-}
-
-// ギルドメンãƒè¿½åŠ è¦æ±‚
-int intif_guild_addmember (int guild_id, struct guild_member *m)
-{
- WFIFOW (inter_fd, 0) = 0x3032;
- WFIFOW (inter_fd, 2) = sizeof (struct guild_member) + 8;
- WFIFOL (inter_fd, 4) = guild_id;
- memcpy (WFIFOP (inter_fd, 8), m, sizeof (struct guild_member));
- WFIFOSET (inter_fd, WFIFOW (inter_fd, 2));
- return 0;
-}
-
-// ギルドメンãƒè„±é€€/追放è¦æ±‚
-int intif_guild_leave (int guild_id, int account_id, int char_id, int flag,
- const char *mes)
-{
- WFIFOW (inter_fd, 0) = 0x3034;
- WFIFOL (inter_fd, 2) = guild_id;
- WFIFOL (inter_fd, 6) = account_id;
- WFIFOL (inter_fd, 10) = char_id;
- WFIFOB (inter_fd, 14) = flag;
- memcpy (WFIFOP (inter_fd, 15), mes, 40);
- WFIFOSET (inter_fd, 55);
- return 0;
-}
-
-// ギルドメンãƒã®ã‚ªãƒ³ãƒ©ã‚¤ãƒ³çŠ¶æ³/Lvæ›´æ–°è¦æ±‚
-int intif_guild_memberinfoshort (int guild_id,
- int account_id, int char_id, int online,
- int lv, int class_)
-{
- WFIFOW (inter_fd, 0) = 0x3035;
- WFIFOL (inter_fd, 2) = guild_id;
- WFIFOL (inter_fd, 6) = account_id;
- WFIFOL (inter_fd, 10) = char_id;
- WFIFOB (inter_fd, 14) = online;
- WFIFOW (inter_fd, 15) = lv;
- WFIFOW (inter_fd, 17) = class_;
- WFIFOSET (inter_fd, 19);
- return 0;
-}
-
-// ギルド解散通知
-int intif_guild_break (int guild_id)
-{
- WFIFOW (inter_fd, 0) = 0x3036;
- WFIFOL (inter_fd, 2) = guild_id;
- WFIFOSET (inter_fd, 6);
- return 0;
-}
-
-// ギルド会話é€ä¿¡
-int intif_guild_message (int guild_id, int account_id, const char *mes, int len)
-{
- WFIFOW (inter_fd, 0) = 0x3037;
- WFIFOW (inter_fd, 2) = len + 12;
- WFIFOL (inter_fd, 4) = guild_id;
- WFIFOL (inter_fd, 8) = account_id;
- memcpy (WFIFOP (inter_fd, 12), mes, len);
- WFIFOSET (inter_fd, len + 12);
- return 0;
-}
-
-// ギルド競åˆãƒã‚§ãƒƒã‚¯è¦æ±‚
-int intif_guild_checkconflict (int guild_id, int account_id, int char_id)
-{
- WFIFOW (inter_fd, 0) = 0x3038;
- WFIFOL (inter_fd, 2) = guild_id;
- WFIFOL (inter_fd, 6) = account_id;
- WFIFOL (inter_fd, 10) = char_id;
- WFIFOSET (inter_fd, 14);
- return 0;
-}
-
-// ギルド基本情報変更è¦æ±‚
-int intif_guild_change_basicinfo (int guild_id, int type, const void *data,
- int len)
-{
- WFIFOW (inter_fd, 0) = 0x3039;
- WFIFOW (inter_fd, 2) = len + 10;
- WFIFOL (inter_fd, 4) = guild_id;
- WFIFOW (inter_fd, 8) = type;
- memcpy (WFIFOP (inter_fd, 10), data, len);
- WFIFOSET (inter_fd, len + 10);
- return 0;
-}
-
-// ギルドメンãƒæƒ…報変更è¦æ±‚
-int intif_guild_change_memberinfo (int guild_id, int account_id, int char_id,
- int type, const void *data, int len)
-{
- WFIFOW (inter_fd, 0) = 0x303a;
- WFIFOW (inter_fd, 2) = len + 18;
- WFIFOL (inter_fd, 4) = guild_id;
- WFIFOL (inter_fd, 8) = account_id;
- WFIFOL (inter_fd, 12) = char_id;
- WFIFOW (inter_fd, 16) = type;
- memcpy (WFIFOP (inter_fd, 18), data, len);
- WFIFOSET (inter_fd, len + 18);
- return 0;
-}
-
-// ギルド役è·å¤‰æ›´è¦æ±‚
-int intif_guild_position (int guild_id, int idx, struct guild_position *p)
-{
- WFIFOW (inter_fd, 0) = 0x303b;
- WFIFOW (inter_fd, 2) = sizeof (struct guild_position) + 12;
- WFIFOL (inter_fd, 4) = guild_id;
- WFIFOL (inter_fd, 8) = idx;
- memcpy (WFIFOP (inter_fd, 12), p, sizeof (struct guild_position));
- WFIFOSET (inter_fd, WFIFOW (inter_fd, 2));
- return 0;
-}
-
-// ギルドスキルアップè¦æ±‚
-int intif_guild_skillup (int guild_id, int skill_num, int account_id)
-{
- WFIFOW (inter_fd, 0) = 0x303c;
- WFIFOL (inter_fd, 2) = guild_id;
- WFIFOL (inter_fd, 6) = skill_num;
- WFIFOL (inter_fd, 10) = account_id;
- WFIFOSET (inter_fd, 14);
- return 0;
-}
-
-// ギルドåŒç›Ÿ/敵対è¦æ±‚
-int intif_guild_alliance (int guild_id1, int guild_id2, int account_id1,
- int account_id2, int flag)
-{
- WFIFOW (inter_fd, 0) = 0x303d;
- WFIFOL (inter_fd, 2) = guild_id1;
- WFIFOL (inter_fd, 6) = guild_id2;
- WFIFOL (inter_fd, 10) = account_id1;
- WFIFOL (inter_fd, 14) = account_id2;
- WFIFOB (inter_fd, 18) = flag;
- WFIFOSET (inter_fd, 19);
- return 0;
-}
-
-// ギルド告知変更è¦æ±‚
-int intif_guild_notice (int guild_id, const char *mes1, const char *mes2)
+int intif_party_checkconflict(int party_id, int account_id, const char *nick)
{
- WFIFOW (inter_fd, 0) = 0x303e;
- WFIFOL (inter_fd, 2) = guild_id;
- memcpy (WFIFOP (inter_fd, 6), mes1, 60);
- memcpy (WFIFOP (inter_fd, 66), mes2, 120);
- WFIFOSET (inter_fd, 186);
- return 0;
-}
-
-// ギルドエンブレム変更è¦æ±‚
-int intif_guild_emblem (int guild_id, int len, const char *data)
-{
- if (guild_id <= 0 || len < 0 || len > 2000)
- return 0;
- WFIFOW (inter_fd, 0) = 0x303f;
- WFIFOW (inter_fd, 2) = len + 12;
- WFIFOL (inter_fd, 4) = guild_id;
- WFIFOL (inter_fd, 8) = 0;
- memcpy (WFIFOP (inter_fd, 12), data, len);
- WFIFOSET (inter_fd, len + 12);
- return 0;
-}
-
-//ç¾åœ¨ã®ã‚®ãƒ«ãƒ‰åŸŽå é ˜ã‚®ãƒ«ãƒ‰ã‚’調ã¹ã‚‹
-int intif_guild_castle_dataload (int castle_id, int index)
-{
- WFIFOW (inter_fd, 0) = 0x3040;
- WFIFOW (inter_fd, 2) = castle_id;
- WFIFOB (inter_fd, 4) = index;
- WFIFOSET (inter_fd, 5);
- return 0;
-}
-
-//ギルド城å é ˜ã‚®ãƒ«ãƒ‰å¤‰æ›´è¦æ±‚
-int intif_guild_castle_datasave (int castle_id, int index, int value)
-{
- WFIFOW (inter_fd, 0) = 0x3041;
- WFIFOW (inter_fd, 2) = castle_id;
- WFIFOB (inter_fd, 4) = index;
- WFIFOL (inter_fd, 5) = value;
- WFIFOSET (inter_fd, 9);
+ WFIFOW(char_fd, 0) = 0x3028;
+ WFIFOL(char_fd, 2) = party_id;
+ WFIFOL(char_fd, 6) = account_id;
+ memcpy(WFIFOP(char_fd, 10), nick, 24);
+ WFIFOSET(char_fd, 34);
return 0;
}
@@ -528,573 +270,290 @@ int intif_guild_castle_datasave (int castle_id, int index, int value)
// Wisp/Page reception
static
-int intif_parse_WisMessage (int fd)
+int intif_parse_WisMessage(int fd)
{ // rewritten by [Yor]
struct map_session_data *sd;
- int i;
+ int i;
if (battle_config.etc_log)
- printf
- ("intif_parse_wismessage: id: %d, from: %s, to: %s, message: '%s'\n",
- RFIFOL (fd, 4), RFIFOP (fd, 8), RFIFOP (fd, 32), RFIFOP (fd,
- 56));
- sd = map_nick2sd ((const char *)RFIFOP (fd, 32)); // Searching destination player
- if (sd != NULL && strcmp (sd->status.name, (const char *)RFIFOP (fd, 32)) == 0)
+ PRINTF("intif_parse_wismessage: id: %d, from: %s, to: %s, message: '%s'\n",
+ RFIFOL(fd, 4),
+ static_cast<const char *>(RFIFOP(fd, 8)),
+ static_cast<const char *>(RFIFOP(fd, 32)),
+ static_cast<const char *>(RFIFOP(fd, 56)));
+ sd = map_nick2sd((const char *)RFIFOP(fd, 32)); // Searching destination player
+ if (sd != NULL && strcmp(sd->status.name, (const char *)RFIFOP(fd, 32)) == 0)
{ // exactly same name (inter-server have checked the name before)
// if player ignore all
if (sd->ignoreAll == 1)
- intif_wis_replay (RFIFOL (fd, 4), 2); // flag: 0: success to send wisper, 1: target character is not loged in?, 2: ignored by target
+ intif_wis_replay(RFIFOL(fd, 4), 2); // flag: 0: success to send wisper, 1: target character is not loged in?, 2: ignored by target
else
{
- const char *wisp_source = (const char *)RFIFOP (fd, 8); // speed up
+ const char *wisp_source = (const char *)RFIFOP(fd, 8); // speed up
// if player ignore the source character
- for (i = 0; i < (sizeof (sd->ignore) / sizeof (sd->ignore[0]));
+ for (i = 0; i < (sizeof(sd->ignore) / sizeof(sd->ignore[0]));
i++)
- if (strcmp (sd->ignore[i].name, wisp_source) == 0)
+ if (strcmp(sd->ignore[i].name, wisp_source) == 0)
{
- intif_wis_replay (RFIFOL (fd, 4), 2); // flag: 0: success to send wisper, 1: target character is not loged in?, 2: ignored by target
+ intif_wis_replay(RFIFOL(fd, 4), 2); // flag: 0: success to send wisper, 1: target character is not loged in?, 2: ignored by target
break;
}
// if source player not found in ignore list
- if (i == (sizeof (sd->ignore) / sizeof (sd->ignore[0])))
+ if (i == (sizeof(sd->ignore) / sizeof(sd->ignore[0])))
{
- clif_wis_message (sd->fd, (const char *)RFIFOP (fd, 8), (const char *)RFIFOP (fd, 56),
- RFIFOW (fd, 2) - 56);
- intif_wis_replay (RFIFOL (fd, 4), 0); // flag: 0: success to send wisper, 1: target character is not loged in?, 2: ignored by target
+ clif_wis_message(sd->fd, (const char *)RFIFOP(fd, 8), (const char *)RFIFOP(fd, 56),
+ RFIFOW(fd, 2) - 56);
+ intif_wis_replay(RFIFOL(fd, 4), 0); // flag: 0: success to send wisper, 1: target character is not loged in?, 2: ignored by target
}
}
}
else
- intif_wis_replay (RFIFOL (fd, 4), 1); // flag: 0: success to send wisper, 1: target character is not loged in?, 2: ignored by target
+ intif_wis_replay(RFIFOL(fd, 4), 1); // flag: 0: success to send wisper, 1: target character is not loged in?, 2: ignored by target
return 0;
}
// Wisp/page transmission result reception
static
-int intif_parse_WisEnd (int fd)
+int intif_parse_WisEnd(int fd)
{
struct map_session_data *sd;
if (battle_config.etc_log)
- printf ("intif_parse_wisend: player: %s, flag: %d\n", RFIFOP (fd, 2), RFIFOB (fd, 26)); // flag: 0: success to send wisper, 1: target character is not loged in?, 2: ignored by target
- sd = map_nick2sd ((const char *)RFIFOP (fd, 2));
+ // flag: 0: success to send wisper, 1: target character is not loged in?, 2: ignored by target
+ PRINTF("intif_parse_wisend: player: %s, flag: %d\n",
+ static_cast<const char *>(RFIFOP(fd, 2)), RFIFOB(fd, 26));
+ sd = map_nick2sd((const char *)RFIFOP(fd, 2));
if (sd != NULL)
- clif_wis_end (sd->fd, RFIFOB (fd, 26));
+ clif_wis_end(sd->fd, RFIFOB(fd, 26));
return 0;
}
// Received wisp message from map-server via char-server for ALL gm
static
-int mapif_parse_WisToGM (int fd)
+int mapif_parse_WisToGM(int fd)
{ // 0x3003/0x3803 <packet_len>.w <wispname>.24B <min_gm_level>.w <message>.?B
- int i, min_gm_level, len;
+ int i, min_gm_level, len;
struct map_session_data *pl_sd;
char Wisp_name[24];
char mbuf[255];
- if (RFIFOW (fd, 2) - 30 <= 0)
+ if (RFIFOW(fd, 2) - 30 <= 0)
return 0;
- len = RFIFOW (fd, 2) - 30;
- char *message = ((len) >= 255) ? (char *) malloc (len) : mbuf;
+ len = RFIFOW(fd, 2) - 30;
+ char *message = ((len) >= 255) ? (char *) malloc(len) : mbuf;
- min_gm_level = (int) RFIFOW (fd, 28);
- memcpy (Wisp_name, RFIFOP (fd, 4), 24);
+ min_gm_level = (int) RFIFOW(fd, 28);
+ memcpy(Wisp_name, RFIFOP(fd, 4), 24);
Wisp_name[23] = '\0';
- memcpy (message, RFIFOP (fd, 30), len);
+ memcpy(message, RFIFOP(fd, 30), len);
message[len - 1] = '\0';
// information is sended to all online GM
for (i = 0; i < fd_max; i++)
if (session[i] && (pl_sd = (struct map_session_data *)session[i]->session_data)
&& pl_sd->state.auth)
- if (pc_isGM (pl_sd) >= min_gm_level)
- clif_wis_message (i, Wisp_name, message,
- strlen (message) + 1);
+ if (pc_isGM(pl_sd) >= min_gm_level)
+ clif_wis_message(i, Wisp_name, message,
+ strlen(message) + 1);
if (message != mbuf)
- free (message);
+ free(message);
return 0;
}
// アカウント変数通知
static
-int intif_parse_AccountReg (int fd)
+int intif_parse_AccountReg(int fd)
{
- int j, p;
+ int j, p;
struct map_session_data *sd;
- if ((sd = map_id2sd (RFIFOL (fd, 4))) == NULL)
+ if ((sd = map_id2sd(RFIFOL(fd, 4))) == NULL)
return 1;
- for (p = 8, j = 0; p < RFIFOW (fd, 2) && j < ACCOUNT_REG_NUM;
+ for (p = 8, j = 0; p < RFIFOW(fd, 2) && j < ACCOUNT_REG_NUM;
p += 36, j++)
{
- memcpy (sd->status.account_reg[j].str, RFIFOP (fd, p), 32);
- sd->status.account_reg[j].value = RFIFOL (fd, p + 32);
+ memcpy(sd->status.account_reg[j].str, RFIFOP(fd, p), 32);
+ sd->status.account_reg[j].value = RFIFOL(fd, p + 32);
}
sd->status.account_reg_num = j;
-// printf("intif: accountreg\n");
+// PRINTF("intif: accountreg\n");
return 0;
}
// 倉庫データå—ä¿¡
static
-int intif_parse_LoadStorage (int fd)
+int intif_parse_LoadStorage(int fd)
{
struct storage *stor;
struct map_session_data *sd;
- sd = map_id2sd (RFIFOL (fd, 4));
+ sd = map_id2sd(RFIFOL(fd, 4));
if (sd == NULL)
{
if (battle_config.error_log)
- printf ("intif_parse_LoadStorage: user not found %d\n",
- RFIFOL (fd, 4));
+ PRINTF("intif_parse_LoadStorage: user not found %d\n",
+ RFIFOL(fd, 4));
return 1;
}
- stor = account2storage (RFIFOL (fd, 4));
+ stor = account2storage(RFIFOL(fd, 4));
if (stor->storage_status == 1)
{ // Already open.. lets ignore this update
if (battle_config.error_log)
- printf
- ("intif_parse_LoadStorage: storage received for a client already open (User %d:%d)\n",
+ PRINTF("intif_parse_LoadStorage: storage received for a client already open (User %d:%d)\n",
sd->status.account_id, sd->status.char_id);
return 1;
}
if (stor->dirty)
{ // Already have storage, and it has been modified and not saved yet! Exploit! [Skotlex]
if (battle_config.error_log)
- printf
- ("intif_parse_LoadStorage: received storage for an already modified non-saved storage! (User %d:%d)\n",
+ PRINTF("intif_parse_LoadStorage: received storage for an already modified non-saved storage! (User %d:%d)\n",
sd->status.account_id, sd->status.char_id);
return 1;
}
- if (RFIFOW (fd, 2) - 8 != sizeof (struct storage))
+ if (RFIFOW(fd, 2) - 8 != sizeof(struct storage))
{
if (battle_config.error_log)
- printf ("intif_parse_LoadStorage: data size error %d %d\n",
- RFIFOW (fd, 2) - 8, sizeof (struct storage));
+ PRINTF("intif_parse_LoadStorage: data size error %d %zu\n",
+ RFIFOW(fd, 2) - 8, sizeof(struct storage));
return 1;
}
if (battle_config.save_log)
- printf ("intif_openstorage: %d\n", RFIFOL (fd, 4));
- memcpy (stor, RFIFOP (fd, 8), sizeof (struct storage));
+ PRINTF("intif_openstorage: %d\n", RFIFOL(fd, 4));
+ memcpy(stor, RFIFOP(fd, 8), sizeof(struct storage));
stor->dirty = 0;
stor->storage_status = 1;
- sd->state.storage_flag = 1;
- clif_storageitemlist (sd, stor);
- clif_storageequiplist (sd, stor);
- clif_updatestorageamount (sd, stor);
+ sd->state.storage_open = 1;
+ clif_storageitemlist(sd, stor);
+ clif_storageequiplist(sd, stor);
+ clif_updatestorageamount(sd, stor);
return 0;
}
// 倉庫データé€ä¿¡æˆåŠŸ
static
-int intif_parse_SaveStorage (int fd)
+int intif_parse_SaveStorage(int fd)
{
if (battle_config.save_log)
- printf ("intif_savestorage: done %d %d\n", RFIFOL (fd, 2),
- RFIFOB (fd, 6));
- storage_storage_saved (RFIFOL (fd, 2));
- return 0;
-}
-
-static
-int intif_parse_LoadGuildStorage (int fd)
-{
- struct guild_storage *gstor;
- struct map_session_data *sd;
- int guild_id;
-
- guild_id = RFIFOL (fd, 8);
- if (guild_id > 0)
- {
- gstor = guild2storage (guild_id);
- if (!gstor)
- {
- if (battle_config.error_log)
- printf
- ("intif_parse_LoadGuildStorage: error guild_id %d not exist\n",
- guild_id);
- return 1;
- }
- if (RFIFOW (fd, 2) - 12 != sizeof (struct guild_storage))
- {
- gstor->storage_status = 0;
- if (battle_config.error_log)
- printf
- ("intif_parse_LoadGuildStorage: data size error %d %d\n",
- RFIFOW (fd, 2) - 12, sizeof (struct guild_storage));
- return 1;
- }
- sd = map_id2sd (RFIFOL (fd, 4));
- if (sd == NULL)
- {
- if (battle_config.error_log)
- printf ("intif_parse_LoadGuildStorage: user not found %d\n",
- RFIFOL (fd, 4));
- return 1;
- }
- if (gstor->storage_status == 1)
- { // Already open.. lets ignore this update
- if (battle_config.error_log)
- printf
- ("intif_parse_LoadGuildStorage: storage received for a client already open (User %d:%d)\n",
- sd->status.account_id, sd->status.char_id);
- return 1;
- }
- if (gstor->dirty)
- { // Already have storage, and it has been modified and not saved yet! Exploit! [Skotlex]
- if (battle_config.error_log)
- printf
- ("intif_parse_LoadGuildStorage: received storage for an already modified non-saved storage! (User %d:%d)\n",
- sd->status.account_id, sd->status.char_id);
- return 1;
- }
- if (battle_config.save_log)
- printf ("intif_open_guild_storage: %d\n", RFIFOL (fd, 4));
- memcpy (gstor, RFIFOP (fd, 12), sizeof (struct guild_storage));
- gstor->storage_status = 1;
- sd->state.storage_flag = 2;
- clif_guildstorageitemlist (sd, gstor);
- clif_guildstorageequiplist (sd, gstor);
- clif_updateguildstorageamount (sd, gstor);
- }
- return 0;
-}
-
-static
-int intif_parse_SaveGuildStorage (int fd)
-{
- if (battle_config.save_log)
- {
- printf ("intif_save_guild_storage: done %d %d %d\n", RFIFOL (fd, 2),
- RFIFOL (fd, 6), RFIFOB (fd, 10));
- }
- storage_guild_storagesaved ( /*RFIFOL(fd,2), */ RFIFOL (fd, 6));
+ PRINTF("intif_savestorage: done %d %d\n", RFIFOL(fd, 2),
+ RFIFOB(fd, 6));
+ storage_storage_saved(RFIFOL(fd, 2));
return 0;
}
// パーティ作æˆå¯å¦
static
-int intif_parse_PartyCreated (int fd)
+int intif_parse_PartyCreated(int fd)
{
if (battle_config.etc_log)
- printf ("intif: party created\n");
- party_created (RFIFOL (fd, 2), RFIFOB (fd, 6), RFIFOL (fd, 7),
- (const char *)RFIFOP (fd, 11));
+ PRINTF("intif: party created\n");
+ party_created(RFIFOL(fd, 2), RFIFOB(fd, 6), RFIFOL(fd, 7),
+ (const char *)RFIFOP(fd, 11));
return 0;
}
// パーティ情報
static
-int intif_parse_PartyInfo (int fd)
+int intif_parse_PartyInfo(int fd)
{
- if (RFIFOW (fd, 2) == 8)
+ if (RFIFOW(fd, 2) == 8)
{
if (battle_config.error_log)
- printf ("intif: party noinfo %d\n", RFIFOL (fd, 4));
- party_recv_noinfo (RFIFOL (fd, 4));
+ PRINTF("intif: party noinfo %d\n", RFIFOL(fd, 4));
+ party_recv_noinfo(RFIFOL(fd, 4));
return 0;
}
-// printf("intif: party info %d\n",RFIFOL(fd,4));
- if (RFIFOW (fd, 2) != sizeof (struct party) + 4)
+// PRINTF("intif: party info %d\n",RFIFOL(fd,4));
+ if (RFIFOW(fd, 2) != sizeof(struct party) + 4)
{
if (battle_config.error_log)
- printf ("intif: party info : data size error %d %d %d\n",
- RFIFOL (fd, 4), RFIFOW (fd, 2),
- sizeof (struct party) + 4);
+ PRINTF("intif: party info : data size error %d %d %zu\n",
+ RFIFOL(fd, 4), RFIFOW(fd, 2),
+ sizeof(struct party) + 4);
}
- party_recv_info ((struct party *) RFIFOP (fd, 4));
+ party_recv_info(static_cast<const struct party *>(RFIFOP(fd, 4)));
return 0;
}
// パーティ追加通知
static
-int intif_parse_PartyMemberAdded (int fd)
+int intif_parse_PartyMemberAdded(int fd)
{
if (battle_config.etc_log)
- printf ("intif: party member added %d %d %d\n", RFIFOL (fd, 2),
- RFIFOL (fd, 6), RFIFOB (fd, 10));
- party_member_added (RFIFOL (fd, 2), RFIFOL (fd, 6), RFIFOB (fd, 10));
+ PRINTF("intif: party member added %d %d %d\n", RFIFOL(fd, 2),
+ RFIFOL(fd, 6), RFIFOB(fd, 10));
+ party_member_added(RFIFOL(fd, 2), RFIFOL(fd, 6), RFIFOB(fd, 10));
return 0;
}
// パーティ設定変更通知
static
-int intif_parse_PartyOptionChanged (int fd)
+int intif_parse_PartyOptionChanged(int fd)
{
- party_optionchanged (RFIFOL (fd, 2), RFIFOL (fd, 6), RFIFOW (fd, 10),
- RFIFOW (fd, 12), RFIFOB (fd, 14));
+ party_optionchanged(RFIFOL(fd, 2), RFIFOL(fd, 6), RFIFOW(fd, 10),
+ RFIFOW(fd, 12), RFIFOB(fd, 14));
return 0;
}
// パーティ脱退通知
static
-int intif_parse_PartyMemberLeaved (int fd)
+int intif_parse_PartyMemberLeaved(int fd)
{
if (battle_config.etc_log)
- printf ("intif: party member leaved %d %d %s\n", RFIFOL (fd, 2),
- RFIFOL (fd, 6), (const char *)RFIFOP (fd, 10));
- party_member_leaved (RFIFOL (fd, 2), RFIFOL (fd, 6), (const char *)RFIFOP (fd, 10));
+ PRINTF("intif: party member leaved %d %d %s\n", RFIFOL(fd, 2),
+ RFIFOL(fd, 6), (const char *)RFIFOP(fd, 10));
+ party_member_leaved(RFIFOL(fd, 2), RFIFOL(fd, 6), (const char *)RFIFOP(fd, 10));
return 0;
}
// パーティ解散通知
static
-int intif_parse_PartyBroken (int fd)
+int intif_parse_PartyBroken(int fd)
{
- party_broken (RFIFOL (fd, 2));
+ party_broken(RFIFOL(fd, 2));
return 0;
}
// パーティ移動通知
static
-int intif_parse_PartyMove (int fd)
+int intif_parse_PartyMove(int fd)
{
// if(battle_config.etc_log)
-// printf("intif: party move %d %d %s %d %d\n",RFIFOL(fd,2),RFIFOL(fd,6),RFIFOP(fd,10),RFIFOB(fd,26),RFIFOW(fd,27));
- party_recv_movemap (RFIFOL (fd, 2), RFIFOL (fd, 6), (const char *)RFIFOP (fd, 10),
- RFIFOB (fd, 26), RFIFOW (fd, 27));
+// PRINTF("intif: party move %d %d %s %d %d\n",RFIFOL(fd,2),RFIFOL(fd,6),RFIFOP(fd,10),RFIFOB(fd,26),RFIFOW(fd,27));
+ party_recv_movemap(RFIFOL(fd, 2), RFIFOL(fd, 6), (const char *)RFIFOP(fd, 10),
+ RFIFOB(fd, 26), RFIFOW(fd, 27));
return 0;
}
// パーティメッセージ
static
-int intif_parse_PartyMessage (int fd)
+int intif_parse_PartyMessage(int fd)
{
// if(battle_config.etc_log)
-// printf("intif_parse_PartyMessage: %s\n",RFIFOP(fd,12));
- party_recv_message (RFIFOL (fd, 4), RFIFOL (fd, 8), (const char *)RFIFOP (fd, 12),
- RFIFOW (fd, 2) - 12);
+// PRINTF("intif_parse_PartyMessage: %s\n",RFIFOP(fd,12));
+ party_recv_message(RFIFOL(fd, 4), RFIFOL(fd, 8), (const char *)RFIFOP(fd, 12),
+ RFIFOW(fd, 2) - 12);
return 0;
}
-// ギルド作æˆå¯å¦
-static
-int intif_parse_GuildCreated (int fd)
-{
- guild_created (RFIFOL (fd, 2), RFIFOL (fd, 6));
- return 0;
-}
-
-// ギルド情報
-static
-int intif_parse_GuildInfo (int fd)
-{
- if (RFIFOW (fd, 2) == 8)
- {
- if (battle_config.error_log)
- printf ("intif: guild noinfo %d\n", RFIFOL (fd, 4));
- guild_recv_noinfo (RFIFOL (fd, 4));
- return 0;
- }
-
-// if(battle_config.etc_log)
-// printf("intif: guild info %d\n",RFIFOL(fd,4));
- if (RFIFOW (fd, 2) != sizeof (struct guild) + 4)
- {
- if (battle_config.error_log)
- printf ("intif: guild info : data size error\n %d %d %d",
- RFIFOL (fd, 4), RFIFOW (fd, 2),
- sizeof (struct guild) + 4);
- }
- guild_recv_info ((struct guild *) RFIFOP (fd, 4));
- return 0;
-}
-
-// ギルドメンãƒè¿½åŠ é€šçŸ¥
-static
-int intif_parse_GuildMemberAdded (int fd)
-{
- if (battle_config.etc_log)
- printf ("intif: guild member added %d %d %d %d\n", RFIFOL (fd, 2),
- RFIFOL (fd, 6), RFIFOL (fd, 10), RFIFOB (fd, 14));
- guild_member_added (RFIFOL (fd, 2), RFIFOL (fd, 6), RFIFOL (fd, 10),
- RFIFOB (fd, 14));
- return 0;
-}
-
-// ギルドメンãƒè„±é€€/追放通知
-static
-int intif_parse_GuildMemberLeaved (int fd)
-{
- guild_member_leaved (RFIFOL (fd, 2), RFIFOL (fd, 6), RFIFOL (fd, 10),
- RFIFOB (fd, 14), (const char *)RFIFOP (fd, 55), (const char *)RFIFOP (fd, 15));
- return 0;
-}
-
-// ギルドメンãƒã‚ªãƒ³ãƒ©ã‚¤ãƒ³çŠ¶æ…‹/Lv変更通知
-static
-int intif_parse_GuildMemberInfoShort (int fd)
-{
- guild_recv_memberinfoshort (RFIFOL (fd, 2), RFIFOL (fd, 6),
- RFIFOL (fd, 10), RFIFOB (fd, 14), RFIFOW (fd,
- 15),
- RFIFOW (fd, 17));
- return 0;
-}
-
-// ギルド解散通知
-static
-int intif_parse_GuildBroken (int fd)
-{
- guild_broken (RFIFOL (fd, 2), RFIFOB (fd, 6));
- return 0;
-}
-
-// ギルド基本情報変更通知
-static
-int intif_parse_GuildBasicInfoChanged (int fd)
-{
- int type = RFIFOW (fd, 8), guild_id = RFIFOL (fd, 4);
- void *data = RFIFOP (fd, 10);
- struct guild *g = guild_search (guild_id);
- short dw = *((short *) data);
- int dd = *((int *) data);
- if (g == NULL)
- return 0;
- switch (type)
- {
- case GBI_EXP:
- g->exp = dd;
- break;
- case GBI_GUILDLV:
- g->guild_lv = dw;
- break;
- case GBI_SKILLPOINT:
- g->skill_point = dd;
- break;
- }
- return 0;
-}
-
-// ギルドメンãƒæƒ…報変更通知
-static
-int intif_parse_GuildMemberInfoChanged (int fd)
-{
- int type = RFIFOW (fd, 16), guild_id = RFIFOL (fd, 4);
- int account_id = RFIFOL (fd, 8), char_id = RFIFOL (fd, 12);
- void *data = RFIFOP (fd, 18);
- struct guild *g = guild_search (guild_id);
- int idx, dd = *((int *) data);
- if (g == NULL)
- return 0;
- idx = guild_getindex (g, account_id, char_id);
- switch (type)
- {
- case GMI_POSITION:
- g->member[idx].position = dd;
- guild_memberposition_changed (g, idx, dd);
- break;
- case GMI_EXP:
- g->member[idx].exp = dd;
- break;
- }
- return 0;
-}
-
-// ギルド役è·å¤‰æ›´é€šçŸ¥
-static
-int intif_parse_GuildPosition (int fd)
-{
- if (RFIFOW (fd, 2) != sizeof (struct guild_position) + 12)
- {
- if (battle_config.error_log)
- printf ("intif: guild info : data size error\n %d %d %d",
- RFIFOL (fd, 4), RFIFOW (fd, 2),
- sizeof (struct guild_position) + 12);
- }
- guild_position_changed (RFIFOL (fd, 4), RFIFOL (fd, 8),
- (struct guild_position *) RFIFOP (fd, 12));
- return 0;
-}
-
-// ギルドスキル割り振り通知
-static
-int intif_parse_GuildSkillUp (int fd)
-{
- guild_skillupack (RFIFOL (fd, 2), RFIFOL (fd, 6), RFIFOL (fd, 10));
- return 0;
-}
-
-// ギルドåŒç›Ÿ/敵対通知
-static
-int intif_parse_GuildAlliance (int fd)
-{
- guild_allianceack (RFIFOL (fd, 2), RFIFOL (fd, 6), RFIFOL (fd, 10),
- RFIFOL (fd, 14), RFIFOB (fd, 18), (const char *)RFIFOP (fd, 19),
- (const char *)RFIFOP (fd, 43));
- return 0;
-}
-
-// ギルド告知変更通知
-static
-int intif_parse_GuildNotice (int fd)
-{
- guild_notice_changed (RFIFOL (fd, 2), (const char *)RFIFOP (fd, 6), (const char *)RFIFOP (fd, 66));
- return 0;
-}
-
-// ギルドエンブレム変更通知
-static
-int intif_parse_GuildEmblem (int fd)
-{
- guild_emblem_changed (RFIFOW (fd, 2) - 12, RFIFOL (fd, 4), RFIFOL (fd, 8),
- (const char *)RFIFOP (fd, 12));
- return 0;
-}
-
-// ギルド会話å—ä¿¡
-static
-int intif_parse_GuildMessage (int fd)
-{
- guild_recv_message (RFIFOL (fd, 4), RFIFOL (fd, 8), (const char *)RFIFOP (fd, 12),
- RFIFOW (fd, 2) - 12);
- return 0;
-}
-
-// ギルド城データè¦æ±‚返信
-static
-int intif_parse_GuildCastleDataLoad (int fd)
-{
- return guild_castledataloadack (RFIFOW (fd, 2), RFIFOB (fd, 4),
- RFIFOL (fd, 5));
-}
-
-// ギルド城データ変更通知
-static
-int intif_parse_GuildCastleDataSave (int fd)
-{
- return guild_castledatasaveack (RFIFOW (fd, 2), RFIFOB (fd, 4),
- RFIFOL (fd, 5));
-}
-
-// ギルド城データ一括å—ä¿¡(åˆæœŸåŒ–時)
-static
-int intif_parse_GuildCastleAllDataLoad (int fd)
-{
- return guild_castlealldataload (RFIFOW (fd, 2),
- (struct guild_castle *) RFIFOP (fd, 4));
-}
-
//-----------------------------------------------------------------
// inter serverã‹ã‚‰ã®é€šä¿¡
// エラーãŒã‚ã‚Œã°0(false)ã‚’è¿”ã™ã“ã¨
// パケットãŒå‡¦ç†ã§ãã‚Œã°1,パケット長ãŒè¶³ã‚Šãªã‘ã‚Œã°2ã‚’è¿”ã™ã“ã¨
-int intif_parse (int fd)
+int intif_parse(int fd)
{
- int packet_len;
- int cmd = RFIFOW (fd, 0);
+ int packet_len;
+ int cmd = RFIFOW(fd, 0);
// パケットã®ID確èª
if (cmd < 0x3800
|| cmd >=
- 0x3800 + (sizeof (packet_len_table) / sizeof (packet_len_table[0]))
+ 0x3800 + (sizeof(packet_len_table) / sizeof(packet_len_table[0]))
|| packet_len_table[cmd - 0x3800] == 0)
{
return 0;
@@ -1103,13 +562,13 @@ int intif_parse (int fd)
packet_len = packet_len_table[cmd - 0x3800];
if (packet_len == -1)
{
- if (RFIFOREST (fd) < 4)
+ if (RFIFOREST(fd) < 4)
return 2;
- packet_len = RFIFOW (fd, 2);
+ packet_len = RFIFOW(fd, 2);
}
// if(battle_config.etc_log)
-// printf("intif_parse %d %x %d %d\n",fd,cmd,packet_len,RFIFOREST(fd));
- if (RFIFOREST (fd) < packet_len)
+// PRINTF("intif_parse %d %x %d %d\n",fd,cmd,packet_len,RFIFOREST(fd));
+ if (RFIFOREST(fd) < packet_len)
{
return 2;
}
@@ -1117,118 +576,59 @@ int intif_parse (int fd)
switch (cmd)
{
case 0x3800:
- clif_GMmessage (NULL, (const char *)RFIFOP (fd, 4), packet_len - 4, 0);
+ clif_GMmessage(NULL,
+ const_string((const char *)RFIFOP(fd, 4),
+ (packet_len - 4) - 1), 0);
break;
case 0x3801:
- intif_parse_WisMessage (fd);
+ intif_parse_WisMessage(fd);
break;
case 0x3802:
- intif_parse_WisEnd (fd);
+ intif_parse_WisEnd(fd);
break;
case 0x3803:
- mapif_parse_WisToGM (fd);
+ mapif_parse_WisToGM(fd);
break;
case 0x3804:
- intif_parse_AccountReg (fd);
+ intif_parse_AccountReg(fd);
break;
case 0x3810:
- intif_parse_LoadStorage (fd);
+ intif_parse_LoadStorage(fd);
break;
case 0x3811:
- intif_parse_SaveStorage (fd);
- break;
- case 0x3818:
- intif_parse_LoadGuildStorage (fd);
- break;
- case 0x3819:
- intif_parse_SaveGuildStorage (fd);
+ intif_parse_SaveStorage(fd);
break;
case 0x3820:
- intif_parse_PartyCreated (fd);
+ intif_parse_PartyCreated(fd);
break;
case 0x3821:
- intif_parse_PartyInfo (fd);
+ intif_parse_PartyInfo(fd);
break;
case 0x3822:
- intif_parse_PartyMemberAdded (fd);
+ intif_parse_PartyMemberAdded(fd);
break;
case 0x3823:
- intif_parse_PartyOptionChanged (fd);
+ intif_parse_PartyOptionChanged(fd);
break;
case 0x3824:
- intif_parse_PartyMemberLeaved (fd);
+ intif_parse_PartyMemberLeaved(fd);
break;
case 0x3825:
- intif_parse_PartyMove (fd);
+ intif_parse_PartyMove(fd);
break;
case 0x3826:
- intif_parse_PartyBroken (fd);
+ intif_parse_PartyBroken(fd);
break;
case 0x3827:
- intif_parse_PartyMessage (fd);
- break;
- case 0x3830:
- intif_parse_GuildCreated (fd);
- break;
- case 0x3831:
- intif_parse_GuildInfo (fd);
- break;
- case 0x3832:
- intif_parse_GuildMemberAdded (fd);
- break;
- case 0x3834:
- intif_parse_GuildMemberLeaved (fd);
- break;
- case 0x3835:
- intif_parse_GuildMemberInfoShort (fd);
- break;
- case 0x3836:
- intif_parse_GuildBroken (fd);
- break;
- case 0x3837:
- intif_parse_GuildMessage (fd);
- break;
- case 0x3839:
- intif_parse_GuildBasicInfoChanged (fd);
- break;
- case 0x383a:
- intif_parse_GuildMemberInfoChanged (fd);
- break;
- case 0x383b:
- intif_parse_GuildPosition (fd);
- break;
- case 0x383c:
- intif_parse_GuildSkillUp (fd);
- break;
- case 0x383d:
- intif_parse_GuildAlliance (fd);
- break;
- case 0x383e:
- intif_parse_GuildNotice (fd);
- break;
- case 0x383f:
- intif_parse_GuildEmblem (fd);
- break;
- case 0x3840:
- intif_parse_GuildCastleDataLoad (fd);
- break;
- case 0x3841:
- intif_parse_GuildCastleDataSave (fd);
- break;
- case 0x3842:
- intif_parse_GuildCastleAllDataLoad (fd);
+ intif_parse_PartyMessage(fd);
break;
- //case 0x3880: intif_parse_CreateP.et(fd); break;
- //case 0x3881: intif_parse_RecvP.etData(fd); break;
- //case 0x3882: intif_parse_SaveP.etOk(fd); break;
- //case 0x3883: intif_parse_DeleteP.etOk(fd); break;
default:
if (battle_config.error_log)
- printf ("intif_parse : unknown packet %d %x\n", fd,
- RFIFOW (fd, 0));
+ PRINTF("intif_parse : unknown packet %d %x\n", fd,
+ RFIFOW(fd, 0));
return 0;
}
// パケット読ã¿é£›ã°ã—
- RFIFOSKIP (fd, packet_len);
+ RFIFOSKIP(fd, packet_len);
return 1;
}
diff --git a/src/map/intif.hpp b/src/map/intif.hpp
index fcca523..25f69e3 100644
--- a/src/map/intif.hpp
+++ b/src/map/intif.hpp
@@ -1,56 +1,31 @@
-// $Id: intif.h,v 1.2 2004/09/25 05:32:18 MouseJstr Exp $
#ifndef INTIF_HPP
#define INTIF_HPP
-int intif_parse (int fd);
-
-int intif_GMmessage (const char *mes, int len, int flag);
-
-int intif_wis_message (struct map_session_data *sd, const char *nick, const char *mes,
- int mes_len);
-int intif_wis_message_to_gm (const char *Wisp_name, int min_gm_level, const char *mes,
- int mes_len);
-
-int intif_saveaccountreg (struct map_session_data *sd);
-int intif_request_accountreg (struct map_session_data *sd);
-
-int intif_request_storage (int account_id);
-int intif_send_storage (struct storage *stor);
-int intif_request_guild_storage (int account_id, int guild_id);
-int intif_send_guild_storage (int account_id, struct guild_storage *gstor);
-
-int intif_create_party (struct map_session_data *sd, const char *name);
-int intif_request_partyinfo (int party_id);
-int intif_party_addmember (int party_id, int account_id);
-int intif_party_changeoption (int party_id, int account_id, int exp,
- int item);
-int intif_party_leave (int party_id, int accound_id);
-int intif_party_changemap (struct map_session_data *sd, int online);
-int intif_break_party (int party_id);
-int intif_party_message (int party_id, int account_id, const char *mes, int len);
-int intif_party_checkconflict (int party_id, int account_id, const char *nick);
-
-int intif_guild_create (const char *name, const struct guild_member *master);
-int intif_guild_request_info (int guild_id);
-int intif_guild_addmember (int guild_id, struct guild_member *m);
-int intif_guild_leave (int guild_id, int account_id, int char_id, int flag,
- const char *mes);
-int intif_guild_memberinfoshort (int guild_id, int account_id, int char_id,
- int online, int lv, int class_);
-int intif_guild_break (int guild_id);
-int intif_guild_message (int guild_id, int account_id, const char *mes, int len);
-int intif_guild_checkconflict (int guild_id, int account_id, int char_id);
-int intif_guild_change_basicinfo (int guild_id, int type, const void *data,
- int len);
-int intif_guild_change_memberinfo (int guild_id, int account_id, int char_id,
- int type, const void *data, int len);
-int intif_guild_position (int guild_id, int idx, struct guild_position *p);
-int intif_guild_skillup (int guild_id, int skill_num, int account_id);
-int intif_guild_alliance (int guild_id1, int guild_id2, int account_id1,
- int account_id2, int flag);
-int intif_guild_notice (int guild_id, const char *mes1, const char *mes2);
-int intif_guild_emblem (int guild_id, int len, const char *data);
-int intif_guild_castle_dataload (int castle_id, int index);
-int intif_guild_castle_datasave (int castle_id, int index, int value);
-
-#endif
+#include "../common/const_array.hpp"
+
+int intif_parse(int fd);
+
+void intif_GMmessage(const_string mes, int flag);
+
+int intif_wis_message(struct map_session_data *sd, const char *nick, const char *mes,
+ int mes_len);
+int intif_wis_message_to_gm(const char *Wisp_name, int min_gm_level, const char *mes,
+ int mes_len);
+
+int intif_saveaccountreg(struct map_session_data *sd);
+int intif_request_accountreg(struct map_session_data *sd);
+
+int intif_request_storage(int account_id);
+int intif_send_storage(struct storage *stor);
+
+int intif_create_party(struct map_session_data *sd, const char *name);
+int intif_request_partyinfo(int party_id);
+int intif_party_addmember(int party_id, int account_id);
+int intif_party_changeoption(int party_id, int account_id, int exp,
+ int item);
+int intif_party_leave(int party_id, int accound_id);
+int intif_party_changemap(struct map_session_data *sd, int online);
+int intif_party_message(int party_id, int account_id, const char *mes, int len);
+int intif_party_checkconflict(int party_id, int account_id, const char *nick);
+
+#endif // INTIF_HPP
diff --git a/src/map/itemdb.cpp b/src/map/itemdb.cpp
index 03e59d6..f60dc53 100644
--- a/src/map/itemdb.cpp
+++ b/src/map/itemdb.cpp
@@ -1,164 +1,80 @@
-// $Id: itemdb.c,v 1.3 2004/09/25 05:32:18 MouseJstr Exp $
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
+#include "itemdb.hpp"
+
+#include <cstdlib>
+#include <cstring>
+#include "../common/cxxstdio.hpp"
#include "../common/db.hpp"
-#include "../common/grfio.hpp"
+#include "../common/random.hpp"
#include "../common/nullpo.hpp"
-#include "map.hpp"
-#include "battle.hpp"
-#include "itemdb.hpp"
-#include "script.hpp"
-#include "pc.hpp"
#include "../common/socket.hpp"
-#include "../common/mt_rand.hpp"
-#ifdef MEMWATCH
-#include "memwatch.hpp"
-#endif
+#include "../poison.hpp"
-#define MAX_RANDITEM 2000
+constexpr int MAX_RANDITEM = 2000;
// ** ITEMDB_OVERRIDE_NAME_VERBOSE **
// 定義ã™ã‚‹ã¨ã€itemdb.txtã¨grfã§åå‰ãŒç•°ãªã‚‹å ´åˆã€è¡¨ç¤ºã—ã¾ã™.
//#define ITEMDB_OVERRIDE_NAME_VERBOSE 1
-static struct dbt *item_db;
-
-static struct random_item_data blue_box[MAX_RANDITEM],
- violet_box[MAX_RANDITEM], card_album[MAX_RANDITEM],
- gift_box[MAX_RANDITEM], scroll[MAX_RANDITEM];
-static int blue_box_count = 0, violet_box_count = 0, card_album_count =
- 0, gift_box_count = 0, scroll_count = 0;
-static int blue_box_default = 0, violet_box_default = 0, card_album_default =
- 0, gift_box_default = 0, scroll_default = 0;
+static
+Map<int, struct item_data> item_db;
// Function declarations
-static void itemdb_read (void);
-static int itemdb_readdb (void);
-static int itemdb_read_randomitem (void);
-static int itemdb_read_itemavail (void);
-static int itemdb_read_itemnametable (void);
-static int itemdb_read_noequip (void);
-
-/*==========================================
- * åå‰ã§æ¤œç´¢ç”¨
- *------------------------------------------
- */
-// name = item alias, so we should find items aliases first. if not found then look for "jname" (full name)
static
-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( strcasecmp(item->name,str)==0 || strcmp(item->jname,str)==0 ||
-// memcmp(item->name,str,24)==0 || memcmp(item->jname,str,24)==0 )
- if (strcasecmp (item->name, str) == 0) //by lupus
- *dst = item;
-}
+void itemdb_read(void);
+static
+int itemdb_readdb(void);
+static
+int itemdb_read_itemavail(void);
+static
+int itemdb_read_noequip(void);
/*==========================================
* åå‰ã§æ¤œç´¢ç”¨
*------------------------------------------
*/
+// name = item alias, so we should find items aliases first. if not found then look for "jname" (full name)
static
-int itemdb_searchjname_sub (void *key, void *data, va_list ap)
+void itemdb_searchname_sub(struct item_data *item, const char *str, struct item_data **dst)
{
- struct item_data *item = (struct item_data *) data, **dst;
- char *str;
- str = va_arg (ap, char *);
- dst = va_arg (ap, struct item_data **);
- if (strcasecmp (item->jname, str) == 0)
+ if (strcasecmp(item->name, str) == 0) //by lupus
*dst = item;
- return 0;
}
/*==========================================
* åå‰ã§æ¤œç´¢
*------------------------------------------
*/
-struct item_data *itemdb_searchname (const char *str)
+struct item_data *itemdb_searchname(const char *str)
{
struct item_data *item = NULL;
- numdb_foreach (item_db, itemdb_searchname_sub, str, &item);
+ for (auto& pair : item_db)
+ itemdb_searchname_sub(&pair.second, str, &item);
return item;
}
/*==========================================
- * 箱系アイテム検索
- *------------------------------------------
- */
-int itemdb_searchrandomid (int flags)
-{
- int nameid = 0, i, index, count;
- struct random_item_data *list = NULL;
-
- struct
- {
- int nameid, count;
- struct random_item_data *list;
- } data[] =
- {
- {
- 0, 0, NULL},
- {
- blue_box_default, blue_box_count, blue_box},
- {
- violet_box_default, violet_box_count, violet_box},
- {
- card_album_default, card_album_count, card_album},
- {
- gift_box_default, gift_box_count, gift_box},
- {
- scroll_default, scroll_count, scroll},};
-
- if (flags >= 1 && flags <= 5)
- {
- nameid = data[flags].nameid;
- count = data[flags].count;
- list = data[flags].list;
-
- if (count > 0)
- {
- for (i = 0; i < 1000; i++)
- {
- index = MRAND (count);
- if (MRAND (1000000) < list[index].per)
- {
- nameid = list[index].nameid;
- break;
- }
- }
- }
- }
- return nameid;
-}
-
-/*==========================================
* DBã®å­˜åœ¨ç¢ºèª
*------------------------------------------
*/
-struct item_data *itemdb_exists (int nameid)
+struct item_data *itemdb_exists(int nameid)
{
- return (struct item_data *)numdb_search (item_db, nameid);
+ return item_db.search(nameid);
}
/*==========================================
* DBã®æ¤œç´¢
*------------------------------------------
*/
-struct item_data *itemdb_search (int nameid)
+struct item_data *itemdb_search(int nameid)
{
- struct item_data *id = (struct item_data *)numdb_search (item_db, nameid);
+ struct item_data *id = item_db.search(nameid);
if (id)
return id;
- id = (struct item_data *) calloc (1, sizeof (struct item_data));
- numdb_insert (item_db, nameid, id);
+ id = item_db.init(nameid);
id->nameid = nameid;
id->value_buy = 10;
@@ -173,21 +89,21 @@ struct item_data *itemdb_search (int nameid)
id->view_id = 0;
if (nameid > 500 && nameid < 600)
- id->type = 0; //heal item
+ id->type = ItemType::USE;
else if (nameid > 600 && nameid < 700)
- id->type = 2; //use item
+ id->type = ItemType::_2;
else if ((nameid > 700 && nameid < 1100) ||
(nameid > 7000 && nameid < 8000))
- id->type = 3; //correction
+ id->type = ItemType::JUNK;
else if (nameid >= 1750 && nameid < 1771)
- id->type = 10; //arrow
+ id->type = ItemType::ARROW;
else if (nameid > 1100 && nameid < 2000)
- id->type = 4; //weapon
+ id->type = ItemType::WEAPON;
else if ((nameid > 2100 && nameid < 3000) ||
(nameid > 5000 && nameid < 6000))
- id->type = 5; //armor
+ id->type = ItemType::ARMOR;
else if (nameid > 4000 && nameid < 5000)
- id->type = 6; //card
+ id->type = ItemType::_6;
return id;
}
@@ -196,135 +112,85 @@ struct item_data *itemdb_search (int nameid)
*
*------------------------------------------
*/
-int itemdb_isequip (int nameid)
+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;
+ ItemType type = itemdb_type(nameid);
+ return !(type == ItemType::USE
+ || type == ItemType::_2
+ || type == ItemType::JUNK
+ || type == ItemType::_6
+ || type == ItemType::ARROW);
}
/*==========================================
*
*------------------------------------------
*/
-int itemdb_isequip2 (struct item_data *data)
+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;
-}
-
-/*==========================================
- *
- *------------------------------------------
- */
-int itemdb_isequip3 (int nameid)
-{
- int type = itemdb_type (nameid);
- if (type == 4 || type == 5 || type == 8)
- return 1;
- return 0;
+ if (!data)
+ return false;
+ ItemType type = data->type;
+ return !(type == ItemType::USE
+ || type == ItemType::_2
+ || type == ItemType::JUNK
+ || type == ItemType::_6
+ || type == ItemType::ARROW);
}
/*==========================================
- * æ¨ã¦ã‚‰ã‚Œã‚‹ã‚¢ã‚¤ãƒ†ãƒ ã¯1ã€ãã†ã§ãªã„アイテムã¯0
- *------------------------------------------
- */
-int itemdb_isdropable (int nameid)
-{
- //çµå©šæŒ‡è¼ªã¯æ¨ã¦ã‚‰ã‚Œãªã„
- switch (nameid)
- {
- case 2634: //çµå©šæŒ‡è¼ª
- case 2635: //çµå©šæŒ‡è¼ª
- return 0;
- }
-
- return 1;
-}
-
-//
-// åˆæœŸåŒ–
-//
-/*==========================================
*
*------------------------------------------
*/
-static int itemdb_read_itemslottable (void)
+int itemdb_isequip3(int nameid)
{
- char *buf, *p;
- size_t s;
-
- buf = (char *)grfio_reads ("data\\itemslottable.txt", &s);
- if (buf == NULL)
- return -1;
- buf[s] = 0;
- for (p = buf; p - buf < s;)
- {
- int nameid, equip;
- sscanf (p, "%d#%d#", &nameid, &equip);
- itemdb_search (nameid)->equip = equip;
- p = strchr (p, 10);
- if (!p)
- break;
- p++;
- p = strchr (p, 10);
- if (!p)
- break;
- p++;
- }
- free (buf);
-
- return 0;
+ ItemType type = itemdb_type(nameid);
+ return (type == ItemType::WEAPON
+ || type == ItemType::ARMOR
+ || type == ItemType::_8);
}
/*==========================================
* アイテムデータベースã®èª­ã¿è¾¼ã¿
*------------------------------------------
*/
-static int itemdb_readdb (void)
+static
+int itemdb_readdb(void)
{
FILE *fp;
char line[1024];
- int ln = 0, lines = 0;
- int nameid, j;
+ int ln = 0, lines = 0;
+ int nameid, j;
char *str[32], *p, *np;
struct item_data *id;
- int i = 0;
+ int i = 0;
const char *filename[] = { "db/item_db.txt", "db/item_db2.txt" };
for (i = 0; i < 2; i++)
{
- fp = fopen_ (filename[i], "r");
+ fp = fopen_(filename[i], "r");
if (fp == NULL)
{
if (i > 0)
continue;
- printf ("can't read %s\n", filename[i]);
- exit (1);
+ PRINTF("can't read %s\n", filename[i]);
+ exit(1);
}
lines = 0;
- while (fgets (line, 1020, fp))
+ while (fgets(line, 1020, fp))
{
lines++;
if (line[0] == '/' && line[1] == '/')
continue;
- memset (str, 0, sizeof (str));
+ memset(str, 0, sizeof(str));
for (j = 0, np = p = line; j < 17 && p; j++)
{
while (*p == '\t' || *p == ' ')
p++;
str[j] = p;
- p = strchr (p, ',');
+ p = strchr(p, ',');
if (p)
{
*p++ = 0;
@@ -334,18 +200,18 @@ static int itemdb_readdb (void)
if (str[0] == NULL)
continue;
- nameid = atoi (str[0]);
+ 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]);
- id->value_buy = atoi (str[4]);
- id->value_sell = atoi (str[5]);
+ id = itemdb_search(nameid);
+ memcpy(id->name, str[1], 24);
+ memcpy(id->jname, str[2], 24);
+ id->type = ItemType(atoi(str[3]));
+ id->value_buy = atoi(str[4]);
+ id->value_sell = atoi(str[5]);
if (id->value_buy == 0 && id->value_sell == 0)
{
}
@@ -357,17 +223,17 @@ static int itemdb_readdb (void)
{
id->value_sell = id->value_buy / 2;
}
- id->weight = atoi (str[6]);
- id->atk = atoi (str[7]);
- id->def = atoi (str[8]);
- id->range = atoi (str[9]);
- id->magic_bonus = atoi (str[10]);
- id->slot = atoi (str[11]);
- id->sex = atoi (str[12]);
- id->equip = atoi (str[13]);
- id->wlv = atoi (str[14]);
- id->elv = atoi (str[15]);
- id->look = atoi (str[16]);
+ id->weight = atoi(str[6]);
+ id->atk = atoi(str[7]);
+ id->def = atoi(str[8]);
+ id->range = atoi(str[9]);
+ id->magic_bonus = atoi(str[10]);
+ id->slot = atoi(str[11]);
+ id->sex = atoi(str[12]);
+ id->equip = EPOS(atoi(str[13]));
+ id->wlv = atoi(str[14]);
+ id->elv = atoi(str[15]);
+ id->look = static_cast<ItemLook>(atoi(str[16]));
id->flag.available = 1;
id->flag.value_notdc = 0;
id->flag.value_notoc = 0;
@@ -376,16 +242,16 @@ static int itemdb_readdb (void)
id->use_script = NULL;
id->equip_script = NULL;
- if ((p = strchr (np, '{')) == NULL)
+ if ((p = strchr(np, '{')) == NULL)
continue;
- id->use_script = parse_script (p, lines);
+ id->use_script = parse_script(p, lines);
- if ((p = strchr (p + 1, '{')) == NULL)
+ if ((p = strchr(p + 1, '{')) == NULL)
continue;
- id->equip_script = parse_script (p, lines);
+ id->equip_script = parse_script(p, lines);
}
- fclose_ (fp);
- printf ("read %s done (count=%d)\n", filename[i], ln);
+ fclose_(fp);
+ PRINTF("read %s done (count=%d)\n", filename[i], ln);
}
return 0;
}
@@ -393,124 +259,34 @@ static int itemdb_readdb (void)
// Removed item_value_db, don't re-add!
/*==========================================
- * ランダムアイテム出ç¾ãƒ‡ãƒ¼ã‚¿ã®èª­ã¿è¾¼ã¿
- *------------------------------------------
- */
-static int itemdb_read_randomitem (void)
-{
- FILE *fp;
- char line[1024];
- int ln = 0;
- int nameid, i, j;
- char *str[10], *p;
-
- const struct
- {
- char filename[64];
- struct random_item_data *pdata;
- int *pcount, *pdefault;
- } data[] =
- {
- {
- "db/item_bluebox.txt", blue_box, &blue_box_count,
- &blue_box_default},
- {
- "db/item_violetbox.txt", violet_box, &violet_box_count,
- &violet_box_default},
- {
- "db/item_cardalbum.txt", card_album, &card_album_count,
- &card_album_default},
- {
- "db/item_giftbox.txt", gift_box, &gift_box_count,
- &gift_box_default},
- {
- "db/item_scroll.txt", scroll, &scroll_count, &scroll_default},};
-
- for (i = 0; i < sizeof (data) / sizeof (data[0]); i++)
- {
- struct random_item_data *pd = data[i].pdata;
- int *pc = data[i].pcount;
- int *pdefault = data[i].pdefault;
- const char *fn = data[i].filename;
-
- *pdefault = 0;
- if ((fp = fopen_ (fn, "r")) == NULL)
- {
- printf ("can't read %s\n", fn);
- continue;
- }
-
- while (fgets (line, 1020, fp))
- {
- if (line[0] == '/' && line[1] == '/')
- continue;
- memset (str, 0, sizeof (str));
- for (j = 0, p = line; j < 3 && p; j++)
- {
- str[j] = p;
- p = strchr (p, ',');
- if (p)
- *p++ = 0;
- }
-
- if (str[0] == NULL)
- continue;
-
- nameid = atoi (str[0]);
- if (nameid < 0 || nameid >= 20000)
- continue;
- if (nameid == 0)
- {
- if (str[2])
- *pdefault = atoi (str[2]);
- continue;
- }
-
- if (str[2])
- {
- pd[*pc].nameid = nameid;
- pd[(*pc)++].per = atoi (str[2]);
- }
-
- if (ln >= MAX_RANDITEM)
- break;
- ln++;
- }
- fclose_ (fp);
- printf ("read %s done (count=%d)\n", fn, *pc);
- }
-
- return 0;
-}
-
-/*==========================================
* アイテム使用å¯èƒ½ãƒ•ãƒ©ã‚°ã®ã‚ªãƒ¼ãƒãƒ¼ãƒ©ã‚¤ãƒ‰
*------------------------------------------
*/
-static int itemdb_read_itemavail (void)
+static
+int itemdb_read_itemavail(void)
{
FILE *fp;
char line[1024];
- int ln = 0;
- int nameid, j, k;
+ int ln = 0;
+ int nameid, j, k;
char *str[10], *p;
- if ((fp = fopen_ ("db/item_avail.txt", "r")) == NULL)
+ if ((fp = fopen_("db/item_avail.txt", "r")) == NULL)
{
- printf ("can't read db/item_avail.txt\n");
+ PRINTF("can't read db/item_avail.txt\n");
return -1;
}
- while (fgets (line, 1020, fp))
+ while (fgets(line, 1020, fp))
{
struct item_data *id;
if (line[0] == '/' && line[1] == '/')
continue;
- memset (str, 0, sizeof (str));
+ memset(str, 0, sizeof(str));
for (j = 0, p = line; j < 2 && p; j++)
{
str[j] = p;
- p = strchr (p, ',');
+ p = strchr(p, ',');
if (p)
*p++ = 0;
}
@@ -518,10 +294,10 @@ static int itemdb_read_itemavail (void)
if (str[0] == NULL)
continue;
- nameid = atoi (str[0]);
- if (nameid < 0 || nameid >= 20000 || !(id = itemdb_exists (nameid)))
+ nameid = atoi(str[0]);
+ if (nameid < 0 || nameid >= 20000 || !(id = itemdb_exists(nameid)))
continue;
- k = atoi (str[1]);
+ k = atoi(str[1]);
if (k > 0)
{
id->flag.available = 1;
@@ -531,92 +307,8 @@ static int itemdb_read_itemavail (void)
id->flag.available = 0;
ln++;
}
- fclose_ (fp);
- printf ("read db/item_avail.txt done (count=%d)\n", ln);
- return 0;
-}
-
-/*==========================================
- * アイテムã®åå‰ãƒ†ãƒ¼ãƒ–ルを読ã¿è¾¼ã‚€
- *------------------------------------------
- */
-static int itemdb_read_itemnametable (void)
-{
- char *buf, *p;
- size_t s;
-
- buf = (char *)grfio_reads ("data\\idnum2itemdisplaynametable.txt", &s);
-
- if (buf == NULL)
- return -1;
-
- buf[s] = 0;
- for (p = buf; p - buf < s;)
- {
- int nameid;
- char buf2[64];
-
- if (sscanf (p, "%d#%[^#]#", &nameid, buf2) == 2)
- {
-
-#ifdef ITEMDB_OVERRIDE_NAME_VERBOSE
- if (itemdb_exists (nameid) &&
- strncmp (itemdb_search (nameid)->jname, buf2, 24) != 0)
- {
- printf ("[override] %d %s => %s\n", nameid,
- itemdb_search (nameid)->jname, buf2);
- }
-#endif
-
- memcpy (itemdb_search (nameid)->jname, buf2, 24);
- }
-
- p = strchr (p, 10);
- if (!p)
- break;
- p++;
- }
- free (buf);
- printf ("read data\\idnum2itemdisplaynametable.txt done.\n");
-
- return 0;
-}
-
-/*==========================================
- * カードイラストã®ãƒªã‚½ãƒ¼ã‚¹åå‰ãƒ†ãƒ¼ãƒ–ルを読ã¿è¾¼ã‚€
- *------------------------------------------
- */
-static int itemdb_read_cardillustnametable (void)
-{
- char *buf, *p;
- size_t s;
-
- buf = (char *)grfio_reads ("data\\num2cardillustnametable.txt", &s);
-
- if (buf == NULL)
- return -1;
-
- buf[s] = 0;
- for (p = buf; p - buf < s;)
- {
- int nameid;
- char buf2[64];
-
- if (sscanf (p, "%d#%[^#]#", &nameid, buf2) == 2)
- {
- strcat (buf2, ".bmp");
- memcpy (itemdb_search (nameid)->cardillustname, buf2, 64);
-// printf("%d %s\n",nameid,itemdb_search(nameid)->cardillustname);
- }
-
- p = strchr (p, 10);
- if (!p)
- break;
- p++;
- }
- free (buf);
- printf ("read data\\num2cardillustnametable.txt done.\n");
-
+ fclose_(fp);
+ PRINTF("read db/item_avail.txt done (count=%d)\n", ln);
return 0;
}
@@ -624,46 +316,47 @@ static int itemdb_read_cardillustnametable (void)
* 装備制é™ãƒ•ã‚¡ã‚¤ãƒ«èª­ã¿å‡ºã—
*------------------------------------------
*/
-static int itemdb_read_noequip (void)
+static
+int itemdb_read_noequip(void)
{
FILE *fp;
char line[1024];
- int ln = 0;
- int nameid, j;
+ int ln = 0;
+ int nameid, j;
char *str[32], *p;
struct item_data *id;
- if ((fp = fopen_ ("db/item_noequip.txt", "r")) == NULL)
+ if ((fp = fopen_("db/item_noequip.txt", "r")) == NULL)
{
- printf ("can't read db/item_noequip.txt\n");
+ PRINTF("can't read db/item_noequip.txt\n");
return -1;
}
- while (fgets (line, 1020, fp))
+ while (fgets(line, 1020, fp))
{
if (line[0] == '/' && line[1] == '/')
continue;
- memset (str, 0, sizeof (str));
+ memset(str, 0, sizeof(str));
for (j = 0, p = line; j < 2 && p; j++)
{
str[j] = p;
- p = strchr (p, ',');
+ p = strchr(p, ',');
if (p)
*p++ = 0;
}
if (str[0] == NULL)
continue;
- nameid = atoi (str[0]);
- if (nameid <= 0 || nameid >= 20000 || !(id = itemdb_exists (nameid)))
+ nameid = atoi(str[0]);
+ if (nameid <= 0 || nameid >= 20000 || !(id = itemdb_exists(nameid)))
continue;
- id->flag.no_equip = atoi (str[1]);
+ id->flag.no_equip = atoi(str[1]);
ln++;
}
- fclose_ (fp);
- printf ("read db/item_noequip.txt done (count=%d)\n", ln);
+ fclose_(fp);
+ PRINTF("read db/item_noequip.txt done (count=%d)\n", ln);
return 0;
}
@@ -671,20 +364,16 @@ static int itemdb_read_noequip (void)
*
*------------------------------------------
*/
-static void itemdb_final (db_key_t key, db_val_t data, va_list ap)
+static
+void itemdb_final(struct item_data *id)
{
- struct item_data *id;
-
- nullpo_retv (id = (struct item_data *)data);
-
if (id->use_script)
- free (const_cast<ScriptCode *>(id->use_script));
+ free(const_cast<ScriptCode *>(id->use_script));
if (id->equip_script)
- free (const_cast<ScriptCode *>(id->equip_script));
- free (id);
+ free(const_cast<ScriptCode *>(id->equip_script));
}
-void itemdb_reload (void)
+void itemdb_reload(void)
{
/*
*
@@ -693,34 +382,34 @@ void itemdb_reload (void)
*
*/
- do_init_itemdb ();
+ do_init_itemdb();
}
/*==========================================
*
*------------------------------------------
*/
-void do_final_itemdb (void)
+void do_final_itemdb(void)
{
- if (item_db)
- {
- numdb_final (item_db, itemdb_final);
- item_db = NULL;
- }
+ for (auto& pair : item_db)
+ itemdb_final(&pair.second);
+ item_db.clear();
}
/*
-static FILE *dfp;
-static int itemdebug(void *key,void *data,va_list ap){
-// struct item_data *id=(struct item_data *)data;
- fprintf(dfp,"%6d",(int)key);
- return 0;
+static
+FILE *dfp;
+static
+int itemdebug(void *key,void *data,_va_list ap){
+// struct item_data *id=(struct item_data *)data;
+ FPRINTF(dfp,"%6d", (int)key);
+ return 0;
}
void itemdebugtxt()
{
- dfp=fopen_("itemdebug.txt","wt");
- numdb_foreach(item_db,itemdebug);
- fclose_(dfp);
+ dfp=fopen_("itemdebug.txt","wt");
+ numdb_foreach(item_db,itemdebug);
+ fclose_(dfp);
}
*/
@@ -728,27 +417,19 @@ void itemdebugtxt()
* Removed item_value_db, don't re-add
*------------------------------------
*/
-static void itemdb_read (void)
+static
+void itemdb_read(void)
{
- itemdb_read_itemslottable ();
- itemdb_readdb ();
- itemdb_read_randomitem ();
- itemdb_read_itemavail ();
- itemdb_read_noequip ();
- itemdb_read_cardillustnametable ();
- if (!battle_config.item_name_override_grffile)
- itemdb_read_itemnametable ();
+ itemdb_readdb();
+ itemdb_read_itemavail();
+ itemdb_read_noequip();
}
/*==========================================
*
*------------------------------------------
*/
-int do_init_itemdb (void)
+void do_init_itemdb(void)
{
- item_db = numdb_init ();
-
- itemdb_read ();
-
- return 0;
+ itemdb_read();
}
diff --git a/src/map/itemdb.hpp b/src/map/itemdb.hpp
index e03892d..279c7a8 100644
--- a/src/map/itemdb.hpp
+++ b/src/map/itemdb.hpp
@@ -1,31 +1,32 @@
-// $Id: itemdb.h,v 1.3 2004/09/25 05:32:18 MouseJstr Exp $
#ifndef ITEMDB_HPP
#define ITEMDB_HPP
-#include "map.hpp"
+#include "../common/mmo.hpp"
+
+#include "map.t.hpp"
#include "script.hpp"
struct item_data
{
- int nameid;
+ int nameid;
char name[24], jname[24];
char prefix[24], suffix[24];
char cardillustname[64];
- int value_buy;
- int value_sell;
- int type;
- int sex;
- int equip;
- int weight;
- int atk;
- int def;
- int range;
- int magic_bonus;
- int slot;
- int look;
- int elv;
- int wlv;
- int refine;
+ int value_buy;
+ int value_sell;
+ ItemType type;
+ int sex;
+ EPOS equip;
+ int weight;
+ int atk;
+ int def;
+ int range;
+ int magic_bonus;
+ int slot;
+ ItemLook look;
+ int elv;
+ int wlv;
+ int refine;
const ScriptCode *use_script;
const ScriptCode *equip_script;
struct
@@ -37,47 +38,78 @@ struct item_data
unsigned no_drop:1;
unsigned no_use:1;
} flag;
- int view_id;
+ int view_id;
};
struct random_item_data
{
- int nameid;
- int per;
+ int nameid;
+ int per;
};
-struct item_data *itemdb_searchname (const char *name);
-struct item_data *itemdb_search (int nameid);
-struct item_data *itemdb_exists (int nameid);
-#define itemdb_type(n) itemdb_search(n)->type
-#define itemdb_atk(n) itemdb_search(n)->atk
-#define itemdb_def(n) itemdb_search(n)->def
-#define itemdb_look(n) itemdb_search(n)->look
-#define itemdb_weight(n) itemdb_search(n)->weight
-#define itemdb_equip(n) itemdb_search(n)->equip
-#define itemdb_usescript(n) itemdb_search(n)->use_script
-#define itemdb_equipscript(n) itemdb_search(n)->equip_script
-#define itemdb_wlv(n) itemdb_search(n)->wlv
-#define itemdb_range(n) itemdb_search(n)->range
-#define itemdb_slot(n) itemdb_search(n)->slot
-#define itemdb_available(n) (itemdb_exists(n) && itemdb_search(n)->flag.available)
-#define itemdb_viewid(n) (itemdb_search(n)->view_id)
+struct item_data *itemdb_searchname(const char *name);
+struct item_data *itemdb_search(int nameid);
+struct item_data *itemdb_exists(int nameid);
-int itemdb_searchrandomid (int flags);
+inline
+ItemType itemdb_type(int n)
+{
+ return itemdb_search(n)->type;
+}
+inline
+ItemLook itemdb_look(int n)
+{
+ return itemdb_search(n)->look;
+}
+inline
+int itemdb_weight(int n)
+{
+ return itemdb_search(n)->weight;
+}
+inline
+const ScriptCode *itemdb_equipscript(int n)
+{
+ return itemdb_search(n)->equip_script;
+}
+inline
+int itemdb_wlv(int n)
+{
+ return itemdb_search(n)->wlv;
+}
+inline
+bool itemdb_available(int n)
+{
+ return itemdb_exists(n) && itemdb_search(n)->flag.available;
+}
+inline
+int itemdb_viewid(int n)
+{
+ return itemdb_search(n)->view_id;
+}
-#define itemdb_value_buy(n) itemdb_search(n)->value_buy
-#define itemdb_value_sell(n) itemdb_search(n)->value_sell
-#define itemdb_value_notdc(n) itemdb_search(n)->flag.value_notdc
-#define itemdb_value_notoc(n) itemdb_search(n)->flag.value_notoc
+inline
+int itemdb_value_sell(int n)
+{
+ return itemdb_search(n)->value_sell;
+}
+inline
+int itemdb_value_notdc(int n)
+{
+ return itemdb_search(n)->flag.value_notdc;
+}
+inline
+int itemdb_value_notoc(int n)
+{
+ return itemdb_search(n)->flag.value_notoc;
+}
-int itemdb_isequip (int);
-int itemdb_isequip2 (struct item_data *);
-int itemdb_isequip3 (int);
-int itemdb_isdropable (int nameid);
+int itemdb_isequip(int);
+int itemdb_isequip2(struct item_data *);
+int itemdb_isequip3(int);
-void itemdb_reload (void);
+void itemdb_reload(void);
-void do_final_itemdb (void);
-int do_init_itemdb (void);
+void do_final_itemdb(void);
+void do_init_itemdb(void);
-#endif
+#endif // ITEMDB_HPP
diff --git a/src/map/magic-expr-eval.hpp b/src/map/magic-expr-eval.hpp
index a08b964..d6decd9 100644
--- a/src/map/magic-expr-eval.hpp
+++ b/src/map/magic-expr-eval.hpp
@@ -1,20 +1,20 @@
-#ifndef MAGIC_EXPR_EVAL
-#define MAGIC_EXPR_EVAL
+#ifndef MAGIC_EXPR_EVAL_HPP
+#define MAGIC_EXPR_EVAL_HPP
-/* Helper definitions for dealing with functions and operations */
+#include "../common/utils2.hpp"
+
+#include "magic-interpreter.hpp"
-static int heading_x[8] = { 0, -1, -1, -1, 0, 1, 1, 1 };
-static int heading_y[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };
+/* Helper definitions for dealing with functions and operations */
-int magic_signature_check (const char *opname, const char *funname, const char *signature,
- int args_nr, val_t * args, int line, int column);
+int magic_signature_check(const char *opname, const char *funname, const char *signature,
+ int args_nr, val_t *args, int line, int column);
-void
-magic_area_rect (int *m, int *x, int *y, int *width, int *height,
- area_t * area);
+void magic_area_rect(int *m, int *x, int *y, int *width, int *height,
+ area_t *area);
#define ARGINT(x) args[x].v.v_int
-#define ARGDIR(x) args[x].v.v_int
+#define ARGDIR(x) args[x].v.v_dir
#define ARGSTR(x) args[x].v.v_string
#define ARGENTITY(x) args[x].v.v_entity
#define ARGLOCATION(x) args[x].v.v_location
@@ -23,7 +23,7 @@ magic_area_rect (int *m, int *x, int *y, int *width, int *height,
#define ARGINVOCATION(x) args[x].v.v_invocation
#define RESULTINT result->v.v_int
-#define RESULTDIR result->v.v_int
+#define RESULTDIR result->v.v_dir
#define RESULTSTR result->v.v_string
#define RESULTENTITY result->v.v_entity
#define RESULTLOCATION result->v.v_location
@@ -31,13 +31,13 @@ magic_area_rect (int *m, int *x, int *y, int *width, int *height,
#define RESULTSPELL result->v.v_spell
#define RESULTINVOCATION result->v.v_invocation
-#define TY(x) args[x].ty
-#define ETY(x) ARGENTITY(x)->type
+#define ARG_TYPE(x) args[x].ty
+#define ENTITY_TYPE(x) ARGENTITY(x)->type
#define ARGPC(x) ((struct map_session_data *)ARGENTITY(x))
#define ARGNPC(x) ((struct map_session_data *)ARGENTITY(x))
#define ARGMOB(x) ((struct map_session_data *)ARGENTITY(x))
-#define ARG_MAY_BE_AREA(x) (TY(x) == TY_AREA || TY(x) == TY_LOCATION)
+#define ARG_MAY_BE_AREA(x) (ARG_TYPE(x) == TYPE::AREA || ARG_TYPE(x) == TYPE::LOCATION)
-#endif /* !defined(MAGIC_EXPR_EVAL) */
+#endif // MAGIC_EXPR_EVAL_HPP
diff --git a/src/map/magic-expr.cpp b/src/map/magic-expr.cpp
index 4b4e3a3..4a72a38 100644
--- a/src/map/magic-expr.cpp
+++ b/src/map/magic-expr.cpp
@@ -1,47 +1,49 @@
-#include "magic-expr.hpp"
#include "magic-expr-eval.hpp"
-#include "itemdb.hpp"
-#include <math.h>
+#include "magic-expr.hpp"
+#include "magic-interpreter-aux.hpp"
-#include "../common/mt_rand.hpp"
+#include <cmath>
-#define IS_SOLID(c) ((c) == 1 || (c) == 5)
+#include "../common/cxxstdio.hpp"
+#include "../common/random.hpp"
-int map_is_solid (int m, int x, int y)
-{
- return (IS_SOLID (map_getcell (m, x, y)));
-}
+#include "battle.hpp"
+#include "npc.hpp"
+#include "pc.hpp"
+#include "itemdb.hpp"
-#undef IS_SOLID
+#include "../poison.hpp"
-static void free_area (area_t * area)
+static
+void free_area(area_t *area)
{
if (!area)
return;
switch (area->ty)
{
- case AREA_UNION:
- free_area (area->a.a_union[0]);
- free_area (area->a.a_union[1]);
+ case AREA::UNION:
+ free_area(area->a.a_union[0]);
+ free_area(area->a.a_union[1]);
break;
default:
break;
}
- free (area);
+ free(area);
}
-static area_t *dup_area (area_t * area)
+static
+area_t *dup_area(area_t *area)
{
- area_t *retval = (area_t *)malloc (sizeof (area_t));
+ area_t *retval = (area_t *)malloc(sizeof(area_t));
*retval = *area;
switch (area->ty)
{
- case AREA_UNION:
- retval->a.a_union[0] = dup_area (retval->a.a_union[0]);
- retval->a.a_union[1] = dup_area (retval->a.a_union[1]);
+ case AREA::UNION:
+ retval->a.a_union[0] = dup_area(retval->a.a_union[0]);
+ retval->a.a_union[1] = dup_area(retval->a.a_union[1]);
break;
default:
break;
@@ -50,17 +52,17 @@ static area_t *dup_area (area_t * area)
return retval;
}
-void magic_copy_var (val_t * dest, val_t * src)
+void magic_copy_var(val_t *dest, val_t *src)
{
*dest = *src;
switch (dest->ty)
{
- case TY_STRING:
- dest->v.v_string = strdup (dest->v.v_string);
+ case TYPE::STRING:
+ dest->v.v_string = strdup(dest->v.v_string);
break;
- case TY_AREA:
- dest->v.v_area = dup_area (dest->v.v_area);
+ case TYPE::AREA:
+ dest->v.v_area = dup_area(dest->v.v_area);
break;
default:
break;
@@ -68,15 +70,15 @@ void magic_copy_var (val_t * dest, val_t * src)
}
-void magic_clear_var (val_t * v)
+void magic_clear_var(val_t *v)
{
switch (v->ty)
{
- case TY_STRING:
- free (v->v.v_string);
+ case TYPE::STRING:
+ free(v->v.v_string);
break;
- case TY_AREA:
- free_area (v->v.v_area);
+ case TYPE::AREA:
+ free_area(v->v.v_area);
break;
default:
break;
@@ -84,116 +86,120 @@ void magic_clear_var (val_t * v)
}
static
-const char *show_entity (entity_t * entity)
+const char *show_entity(entity_t *entity)
{
switch (entity->type)
{
- case BL_PC:
+ case BL::PC:
return ((struct map_session_data *) entity)->status.name;
- case BL_NPC:
+ case BL::NPC:
return ((struct npc_data *) entity)->name;
- case BL_MOB:
+ case BL::MOB:
return ((struct mob_data *) entity)->name;
- case BL_ITEM:
+ case BL::ITEM:
/* Sorry about this one... */
return ((struct item_data
*) (&((struct flooritem_data *) entity)->
item_data))->name;
- case BL_SKILL:
- return "%skill";
- case BL_SPELL:
+ case BL::SPELL:
return "%invocation(ERROR:this-should-not-be-an-entity)";
default:
return "%unknown-entity";
}
}
-static void stringify (val_t * v, int within_op)
+static
+void stringify(val_t *v, int within_op)
{
static const char *dirs[8] =
- { "south", "south-west", "west", "north-west", "north", "north-east",
+ {
+ "south", "south-west",
+ "west", "north-west",
+ "north", "north-east",
"east", "south-east"
};
- char *buf;
+ std::string buf;
switch (v->ty)
{
- case TY_UNDEF:
- buf = strdup ("UNDEF");
+ case TYPE::UNDEF:
+ buf = "UNDEF";
break;
- case TY_INT:
- buf = (char *)malloc (32);
- sprintf (buf, "%i", v->v.v_int);
+ case TYPE::INT:
+ buf = STRPRINTF("%i", v->v.v_int);
break;
- case TY_STRING:
+ case TYPE::STRING:
return;
- case TY_DIR:
- buf = strdup (dirs[v->v.v_int]);
+ case TYPE::DIR:
+ buf = dirs[v->v.v_int];
break;
- case TY_ENTITY:
- buf = strdup (show_entity (v->v.v_entity));
+ case TYPE::ENTITY:
+ buf = show_entity(v->v.v_entity);
break;
- case TY_LOCATION:
- buf = (char *) malloc (128);
- sprintf (buf, "<\"%s\", %d, %d>", map[v->v.v_location.m].name,
- v->v.v_location.x, v->v.v_location.y);
+ case TYPE::LOCATION:
+ buf = STRPRINTF("<\"%s\", %d, %d>",
+ map[v->v.v_location.m].name,
+ v->v.v_location.x,
+ v->v.v_location.y);
break;
- case TY_AREA:
- buf = strdup ("%area");
- free_area (v->v.v_area);
+ case TYPE::AREA:
+ buf = "%area";
+ free_area(v->v.v_area);
break;
- case TY_SPELL:
- buf = strdup (v->v.v_spell->name);
+ case TYPE::SPELL:
+ buf = v->v.v_spell->name;
break;
- case TY_INVOCATION:
+ case TYPE::INVOCATION:
{
invocation_t *invocation = within_op
- ? v->v.v_invocation : (invocation_t *) map_id2bl (v->v.v_int);
- buf = strdup (invocation->spell->name);
+ ? v->v.v_invocation
+ : (invocation_t *) map_id2bl(v->v.v_int);
+ buf = invocation->spell->name;
}
break;
default:
- fprintf (stderr, "[magic] INTERNAL ERROR: Cannot stringify %d\n",
- v->ty);
+ FPRINTF(stderr, "[magic] INTERNAL ERROR: Cannot stringify %d\n",
+ v->ty);
return;
}
- v->v.v_string = buf;
- v->ty = TY_STRING;
+ v->v.v_string = strdup(buf.c_str());
+ v->ty = TYPE::STRING;
}
-static void intify (val_t * v)
+static
+void intify(val_t *v)
{
- if (v->ty == TY_INT)
+ if (v->ty == TYPE::INT)
return;
- magic_clear_var (v);
- v->ty = TY_INT;
+ magic_clear_var(v);
+ v->ty = TYPE::INT;
v->v.v_int = 1;
}
static
-area_t *area_new (int ty)
+area_t *area_new(AREA ty)
{
area_t *retval;
- CREATE (retval, area_t, 1);
+ CREATE(retval, area_t, 1);
retval->ty = ty;
return retval;
}
static
-area_t *area_union (area_t * area, area_t * other_area)
+area_t *area_union(area_t *area, area_t *other_area)
{
- area_t *retval = area_new (AREA_UNION);
+ area_t *retval = area_new(AREA::UNION);
retval->a.a_union[0] = area;
retval->a.a_union[1] = other_area;
retval->size = area->size + other_area->size; /* Assume no overlap */
@@ -203,256 +209,277 @@ area_t *area_union (area_t * area, area_t * other_area)
/**
* Turns location into area, leaves other types untouched
*/
-static void make_area (val_t * v)
+static
+void make_area(val_t *v)
{
- if (v->ty == TY_LOCATION)
+ if (v->ty == TYPE::LOCATION)
{
- area_t *a = (area_t *)malloc (sizeof (area_t));
- v->ty = TY_AREA;
- a->ty = AREA_LOCATION;
+ area_t *a = (area_t *)malloc(sizeof(area_t));
+ v->ty = TYPE::AREA;
+ a->ty = AREA::LOCATION;
a->a.a_loc = v->v.v_location;
v->v.v_area = a;
}
}
-static void make_location (val_t * v)
+static
+void make_location(val_t *v)
{
- if (v->ty == TY_AREA && v->v.v_area->ty == AREA_LOCATION)
+ if (v->ty == TYPE::AREA && v->v.v_area->ty == AREA::LOCATION)
{
location_t location = v->v.v_area->a.a_loc;
- free_area (v->v.v_area);
- v->ty = TY_LOCATION;
+ free_area(v->v.v_area);
+ v->ty = TYPE::LOCATION;
v->v.v_location = location;
}
}
-static void make_spell (val_t * v)
+static
+void make_spell(val_t *v)
{
- if (v->ty == TY_INVOCATION)
+ if (v->ty == TYPE::INVOCATION)
{
invocation_t *invoc = v->v.v_invocation; //(invocation_t *) map_id2bl(v->v.v_int);
if (!invoc)
- v->ty = TY_FAIL;
+ v->ty = TYPE::FAIL;
else
{
- v->ty = TY_SPELL;
+ v->ty = TYPE::SPELL;
v->v.v_spell = invoc->spell;
}
}
}
-static int fun_add (env_t * env, int args_nr, val_t * result, val_t * args)
+static
+int fun_add(env_t *, int, val_t *result, val_t *args)
{
- if (TY (0) == TY_INT && TY (1) == TY_INT)
+ if (ARG_TYPE(0) == TYPE::INT && ARG_TYPE(1) == TYPE::INT)
{
/* Integer addition */
- RESULTINT = ARGINT (0) + ARGINT (1);
- result->ty = TY_INT;
+ RESULTINT = ARGINT(0) + ARGINT(1);
+ result->ty = TYPE::INT;
}
- else if (ARG_MAY_BE_AREA (0) && ARG_MAY_BE_AREA (1))
+ else if (ARG_MAY_BE_AREA(0) && ARG_MAY_BE_AREA(1))
{
/* Area union */
- make_area (&args[0]);
- make_area (&args[1]);
- RESULTAREA = area_union (ARGAREA (0), ARGAREA (1));
- ARGAREA (0) = NULL;
- ARGAREA (1) = NULL;
- result->ty = TY_AREA;
+ make_area(&args[0]);
+ make_area(&args[1]);
+ RESULTAREA = area_union(ARGAREA(0), ARGAREA(1));
+ ARGAREA(0) = NULL;
+ ARGAREA(1) = NULL;
+ result->ty = TYPE::AREA;
}
else
{
/* Anything else -> string concatenation */
- stringify (&args[0], 1);
- stringify (&args[1], 1);
+ stringify(&args[0], 1);
+ stringify(&args[1], 1);
/* Yes, we could speed this up. */
RESULTSTR =
- (char *) malloc (1 + strlen (ARGSTR (0)) + strlen (ARGSTR (1)));
- strcpy (RESULTSTR, ARGSTR (0));
- strcat (RESULTSTR, ARGSTR (1));
- result->ty = TY_STRING;
+ (char *) malloc(1 + strlen(ARGSTR(0)) + strlen(ARGSTR(1)));
+ strcpy(RESULTSTR, ARGSTR(0));
+ strcat(RESULTSTR, ARGSTR(1));
+ result->ty = TYPE::STRING;
}
return 0;
}
-static int fun_sub (env_t * env, int args_nr, val_t * result, val_t * args)
+static
+int fun_sub(env_t *, int, val_t *result, val_t *args)
{
- RESULTINT = ARGINT (0) - ARGINT (1);
+ RESULTINT = ARGINT(0) - ARGINT(1);
return 0;
}
-static int fun_mul (env_t * env, int args_nr, val_t * result, val_t * args)
+static
+int fun_mul(env_t *, int, val_t *result, val_t *args)
{
- RESULTINT = ARGINT (0) * ARGINT (1);
+ RESULTINT = ARGINT(0) * ARGINT(1);
return 0;
}
-static int fun_div (env_t * env, int args_nr, val_t * result, val_t * args)
+static
+int fun_div(env_t *, int, val_t *result, val_t *args)
{
- if (!ARGINT (1))
+ if (!ARGINT(1))
return 1; /* division by zero */
- RESULTINT = ARGINT (0) / ARGINT (1);
+ RESULTINT = ARGINT(0) / ARGINT(1);
return 0;
}
-static int fun_mod (env_t * env, int args_nr, val_t * result, val_t * args)
+static
+int fun_mod(env_t *, int, val_t *result, val_t *args)
{
- if (!ARGINT (1))
+ if (!ARGINT(1))
return 1; /* division by zero */
- RESULTINT = ARGINT (0) % ARGINT (1);
+ RESULTINT = ARGINT(0) % ARGINT(1);
return 0;
}
-static int fun_or (env_t * env, int args_nr, val_t * result, val_t * args)
+static
+int fun_or(env_t *, int, val_t *result, val_t *args)
{
- RESULTINT = ARGINT (0) || ARGINT (1);
+ RESULTINT = ARGINT(0) || ARGINT(1);
return 0;
}
-static int fun_and (env_t * env, int args_nr, val_t * result, val_t * args)
+static
+int fun_and(env_t *, int, val_t *result, val_t *args)
{
- RESULTINT = ARGINT (0) && ARGINT (1);
+ RESULTINT = ARGINT(0) && ARGINT(1);
return 0;
}
-static int fun_not (env_t * env, int args_nr, val_t * result, val_t * args)
+static
+int fun_not(env_t *, int, val_t *result, val_t *args)
{
- RESULTINT = !ARGINT (0);
+ RESULTINT = !ARGINT(0);
return 0;
}
-static int fun_neg (env_t * env, int args_nr, val_t * result, val_t * args)
+static
+int fun_neg(env_t *, int, val_t *result, val_t *args)
{
- RESULTINT = ~ARGINT (0);
+ RESULTINT = ~ARGINT(0);
return 0;
}
-static int fun_gte (env_t * env, int args_nr, val_t * result, val_t * args)
+static
+int fun_gte(env_t *, int, val_t *result, val_t *args)
{
- if (TY (0) == TY_STRING || TY (1) == TY_STRING)
+ if (ARG_TYPE(0) == TYPE::STRING || ARG_TYPE(1) == TYPE::STRING)
{
- stringify (&args[0], 1);
- stringify (&args[1], 1);
- RESULTINT = strcmp (ARGSTR (0), ARGSTR (1)) >= 0;
+ stringify(&args[0], 1);
+ stringify(&args[1], 1);
+ RESULTINT = strcmp(ARGSTR(0), ARGSTR(1)) >= 0;
}
else
{
- intify (&args[0]);
- intify (&args[1]);
- RESULTINT = ARGINT (0) >= ARGINT (1);
+ intify(&args[0]);
+ intify(&args[1]);
+ RESULTINT = ARGINT(0) >= ARGINT(1);
}
return 0;
}
-static int fun_gt (env_t * env, int args_nr, val_t * result, val_t * args)
+static
+int fun_gt(env_t *, int, val_t *result, val_t *args)
{
- if (TY (0) == TY_STRING || TY (1) == TY_STRING)
+ if (ARG_TYPE(0) == TYPE::STRING || ARG_TYPE(1) == TYPE::STRING)
{
- stringify (&args[0], 1);
- stringify (&args[1], 1);
- RESULTINT = strcmp (ARGSTR (0), ARGSTR (1)) > 0;
+ stringify(&args[0], 1);
+ stringify(&args[1], 1);
+ RESULTINT = strcmp(ARGSTR(0), ARGSTR(1)) > 0;
}
else
{
- intify (&args[0]);
- intify (&args[1]);
- RESULTINT = ARGINT (0) > ARGINT (1);
+ intify(&args[0]);
+ intify(&args[1]);
+ RESULTINT = ARGINT(0) > ARGINT(1);
}
return 0;
}
-static int fun_eq (env_t * env, int args_nr, val_t * result, val_t * args)
+static
+int fun_eq(env_t *, int, val_t *result, val_t *args)
{
- if (TY (0) == TY_STRING || TY (1) == TY_STRING)
+ if (ARG_TYPE(0) == TYPE::STRING || ARG_TYPE(1) == TYPE::STRING)
{
- stringify (&args[0], 1);
- stringify (&args[1], 1);
- RESULTINT = strcmp (ARGSTR (0), ARGSTR (1)) == 0;
+ stringify(&args[0], 1);
+ stringify(&args[1], 1);
+ RESULTINT = strcmp(ARGSTR(0), ARGSTR(1)) == 0;
}
- else if (TY (0) == TY_DIR && TY (1) == TY_DIR)
- RESULTINT = ARGDIR (0) == ARGDIR (1);
- else if (TY (0) == TY_ENTITY && TY (1) == TY_ENTITY)
- RESULTINT = ARGENTITY (0) == ARGENTITY (1);
- else if (TY (0) == TY_LOCATION && TY (1) == TY_LOCATION)
- RESULTINT = (ARGLOCATION (0).x == ARGLOCATION (1).x
- && ARGLOCATION (0).y == ARGLOCATION (1).y
- && ARGLOCATION (0).m == ARGLOCATION (1).m);
- else if (TY (0) == TY_AREA && TY (1) == TY_AREA)
- RESULTINT = ARGAREA (0) == ARGAREA (1); /* Probably not that great an idea... */
- else if (TY (0) == TY_SPELL && TY (1) == TY_SPELL)
- RESULTINT = ARGSPELL (0) == ARGSPELL (1);
- else if (TY (0) == TY_INVOCATION && TY (1) == TY_INVOCATION)
- RESULTINT = ARGINVOCATION (0) == ARGINVOCATION (1);
+ else if (ARG_TYPE(0) == TYPE::DIR && ARG_TYPE(1) == TYPE::DIR)
+ RESULTINT = ARGDIR(0) == ARGDIR(1);
+ else if (ARG_TYPE(0) == TYPE::ENTITY && ARG_TYPE(1) == TYPE::ENTITY)
+ RESULTINT = ARGENTITY(0) == ARGENTITY(1);
+ else if (ARG_TYPE(0) == TYPE::LOCATION && ARG_TYPE(1) == TYPE::LOCATION)
+ RESULTINT = (ARGLOCATION(0).x == ARGLOCATION(1).x
+ && ARGLOCATION(0).y == ARGLOCATION(1).y
+ && ARGLOCATION(0).m == ARGLOCATION(1).m);
+ else if (ARG_TYPE(0) == TYPE::AREA && ARG_TYPE(1) == TYPE::AREA)
+ RESULTINT = ARGAREA(0) == ARGAREA(1); /* Probably not that great an idea... */
+ else if (ARG_TYPE(0) == TYPE::SPELL && ARG_TYPE(1) == TYPE::SPELL)
+ RESULTINT = ARGSPELL(0) == ARGSPELL(1);
+ else if (ARG_TYPE(0) == TYPE::INVOCATION && ARG_TYPE(1) == TYPE::INVOCATION)
+ RESULTINT = ARGINVOCATION(0) == ARGINVOCATION(1);
else
{
- intify (&args[0]);
- intify (&args[1]);
- RESULTINT = ARGINT (0) == ARGINT (1);
+ intify(&args[0]);
+ intify(&args[1]);
+ RESULTINT = ARGINT(0) == ARGINT(1);
}
return 0;
}
-static int fun_bitand (env_t * env, int args_nr, val_t * result, val_t * args)
+static
+int fun_bitand(env_t *, int, val_t *result, val_t *args)
{
- RESULTINT = ARGINT (0) & ARGINT (1);
+ RESULTINT = ARGINT(0) & ARGINT(1);
return 0;
}
-static int fun_bitor (env_t * env, int args_nr, val_t * result, val_t * args)
+static
+int fun_bitor(env_t *, int, val_t *result, val_t *args)
{
- RESULTINT = ARGINT (0) | ARGINT (1);
+ RESULTINT = ARGINT(0) | ARGINT(1);
return 0;
}
-static int fun_bitxor (env_t * env, int args_nr, val_t * result, val_t * args)
+static
+int fun_bitxor(env_t *, int, val_t *result, val_t *args)
{
- RESULTINT = ARGINT (0) ^ ARGINT (1);
+ RESULTINT = ARGINT(0) ^ ARGINT(1);
return 0;
}
-static int fun_bitshl (env_t * env, int args_nr, val_t * result, val_t * args)
+static
+int fun_bitshl(env_t *, int, val_t *result, val_t *args)
{
- RESULTINT = ARGINT (0) << ARGINT (1);
+ RESULTINT = ARGINT(0) << ARGINT(1);
return 0;
}
-static int fun_bitshr (env_t * env, int args_nr, val_t * result, val_t * args)
+static
+int fun_bitshr(env_t *, int, val_t *result, val_t *args)
{
- RESULTINT = ARGINT (0) >> ARGINT (1);
+ RESULTINT = ARGINT(0) >> ARGINT(1);
return 0;
}
-static int fun_max (env_t * env, int args_nr, val_t * result, val_t * args)
+static
+int fun_max(env_t *, int, val_t *result, val_t *args)
{
- RESULTINT = MAX (ARGINT (0), ARGINT (1));
+ RESULTINT = max(ARGINT(0), ARGINT(1));
return 0;
}
-static int fun_min (env_t * env, int args_nr, val_t * result, val_t * args)
+static
+int fun_min(env_t *, int, val_t *result, val_t *args)
{
- RESULTINT = MIN (ARGINT (0), ARGINT (1));
+ RESULTINT = min(ARGINT(0), ARGINT(1));
return 0;
}
-static int
-fun_if_then_else (env_t * env, int args_nr, val_t * result, val_t * args)
+static
+int fun_if_then_else(env_t *, int, val_t *result, val_t *args)
{
- if (ARGINT (0))
- magic_copy_var (result, &args[1]);
+ if (ARGINT(0))
+ magic_copy_var(result, &args[1]);
else
- magic_copy_var (result, &args[2]);
+ magic_copy_var(result, &args[2]);
return 0;
}
-void
-magic_area_rect (int *m, int *x, int *y, int *width, int *height,
- area_t * area)
+void magic_area_rect(int *m, int *x, int *y, int *width, int *height,
+ area_t *area)
{
switch (area->ty)
{
- case AREA_UNION:
+ case AREA::UNION:
break;
- case AREA_LOCATION:
+ case AREA::LOCATION:
*m = area->a.a_loc.m;
*x = area->a.a_loc.x;
*y = area->a.a_loc.y;
@@ -460,7 +487,7 @@ magic_area_rect (int *m, int *x, int *y, int *width, int *height,
*height = 1;
break;
- case AREA_RECT:
+ case AREA::RECT:
*m = area->a.a_rect.loc.m;
*x = area->a.a_rect.loc.x;
*y = area->a.a_rect.loc.y;
@@ -468,38 +495,38 @@ magic_area_rect (int *m, int *x, int *y, int *width, int *height,
*height = area->a.a_rect.height;
break;
- case AREA_BAR:
+ case AREA::BAR:
{
- int tx = area->a.a_bar.loc.x;
- int ty = area->a.a_bar.loc.y;
- int twidth = area->a.a_bar.width;
- int tdepth = area->a.a_bar.width;
+ int tx = area->a.a_bar.loc.x;
+ int ty = area->a.a_bar.loc.y;
+ int twidth = area->a.a_bar.width;
+ int tdepth = area->a.a_bar.width;
*m = area->a.a_bar.loc.m;
switch (area->a.a_bar.dir)
{
- case DIR_S:
+ case DIR::S:
*x = tx - twidth;
*y = ty;
*width = twidth * 2 + 1;
*height = tdepth;
break;
- case DIR_W:
+ case DIR::W:
*x = tx - tdepth;
*y = ty - twidth;
*width = tdepth;
*height = twidth * 2 + 1;
break;
- case DIR_N:
+ case DIR::N:
*x = tx - twidth;
*y = ty - tdepth;
*width = twidth * 2 + 1;
*height = tdepth;
break;
- case DIR_E:
+ case DIR::E:
*x = tx;
*y = ty - twidth;
*width = tdepth;
@@ -507,7 +534,7 @@ magic_area_rect (int *m, int *x, int *y, int *width, int *height,
break;
default:
- fprintf (stderr,
+ FPRINTF(stderr,
"Error: Trying to compute area of NE/SE/NW/SW-facing bar");
*x = tx;
*y = ty;
@@ -518,124 +545,162 @@ magic_area_rect (int *m, int *x, int *y, int *width, int *height,
}
}
-int magic_location_in_area (int m, int x, int y, area_t * area)
+int magic_location_in_area(int m, int x, int y, area_t *area)
{
switch (area->ty)
{
- case AREA_UNION:
- return magic_location_in_area (m, x, y, area->a.a_union[0])
- || magic_location_in_area (m, x, y, area->a.a_union[1]);
- case AREA_LOCATION:
- case AREA_RECT:
- case AREA_BAR:
+ case AREA::UNION:
+ return magic_location_in_area(m, x, y, area->a.a_union[0])
+ || magic_location_in_area(m, x, y, area->a.a_union[1]);
+ case AREA::LOCATION:
+ case AREA::RECT:
+ case AREA::BAR:
{
- int am;
- int ax, ay, awidth, aheight;
- magic_area_rect (&am, &ax, &ay, &awidth, &aheight, area);
+ int am;
+ int ax, ay, awidth, aheight;
+ magic_area_rect(&am, &ax, &ay, &awidth, &aheight, area);
return (am == m
&& (x >= ax) && (y >= ay)
&& (x < ax + awidth) && (y < ay + aheight));
}
default:
- fprintf (stderr, "INTERNAL ERROR: Invalid area\n");
+ FPRINTF(stderr, "INTERNAL ERROR: Invalid area\n");
return 0;
}
}
-static int fun_is_in (env_t * env, int args_nr, val_t * result, val_t * args)
+static
+int fun_is_in(env_t *, int, val_t *result, val_t *args)
{
- RESULTINT = magic_location_in_area (ARGLOCATION (0).m,
- ARGLOCATION (0).x,
- ARGLOCATION (0).y, ARGAREA (1));
+ RESULTINT = magic_location_in_area(ARGLOCATION(0).m,
+ ARGLOCATION(0).x,
+ ARGLOCATION(0).y, ARGAREA(1));
return 0;
}
-static int fun_skill (env_t * env, int args_nr, val_t * result, val_t * args)
+static
+int fun_skill(env_t *, int, val_t *result, val_t *args)
{
- if (ETY (0) != BL_PC
- || ARGINT (1) < 0
- || ARGINT (1) >= MAX_SKILL
- || ARGPC (0)->status.skill[ARGINT (1)].id != ARGINT (1))
+ if (ENTITY_TYPE(0) != BL::PC
+ // don't convert to enum until after the range check
+ || ARGINT(1) < 0
+ || ARGINT(1) >= uint16_t(MAX_SKILL))
+ {
RESULTINT = 0;
+ }
else
- RESULTINT = ARGPC (0)->status.skill[ARGINT (1)].lv;
+ {
+ SkillID id = static_cast<SkillID>(ARGINT(1));
+ RESULTINT = ARGPC(0)->status.skill[id].lv;
+ }
return 0;
}
-static int
-fun_has_shroud (env_t * env, int args_nr, val_t * result, val_t * args)
+static
+int fun_has_shroud(env_t *, int, val_t *result, val_t *args)
{
- RESULTINT = (ETY (0) == BL_PC && ARGPC (0)->state.shroud_active);
+ RESULTINT = (ENTITY_TYPE(0) == BL::PC && ARGPC(0)->state.shroud_active);
return 0;
}
-#define BATTLE_GETTER(name) static int fun_get_##name(env_t *env, int args_nr, val_t *result, val_t *args) { RESULTINT = battle_get_##name(ARGENTITY(0)); return 0; }
-
-BATTLE_GETTER (str);
-BATTLE_GETTER (agi);
-BATTLE_GETTER (vit);
-BATTLE_GETTER (dex);
-BATTLE_GETTER (luk);
-BATTLE_GETTER (int);
-BATTLE_GETTER (lv);
-BATTLE_GETTER (hp);
-BATTLE_GETTER (mdef);
-BATTLE_GETTER (def);
-BATTLE_GETTER (max_hp);
-BATTLE_GETTER (dir);
+#define BATTLE_GETTER(name) \
+static \
+int fun_get_##name(env_t *, int, val_t *result, val_t *args) \
+{ \
+ RESULTINT = battle_get_##name(ARGENTITY(0)); \
+ return 0; \
+}
+
+BATTLE_GETTER(str)
+BATTLE_GETTER(agi)
+BATTLE_GETTER(vit)
+BATTLE_GETTER(dex)
+BATTLE_GETTER(luk)
+BATTLE_GETTER(int)
+BATTLE_GETTER(lv)
+BATTLE_GETTER(hp)
+BATTLE_GETTER(mdef)
+BATTLE_GETTER(def)
+BATTLE_GETTER(max_hp)
+static
+int fun_get_dir(env_t *, int, val_t *result, val_t *args)
+{
+ RESULTDIR = battle_get_dir(ARGENTITY(0));
+ return 0;
+}
-#define MMO_GETTER(name) static int fun_get_##name(env_t *env, int args_nr, val_t *result, val_t *args) { \
- if (ETY(0) == BL_PC) \
- RESULTINT = ARGPC(0)->status.name; \
- else \
- RESULTINT = 0; \
- return 0; }
+#define MMO_GETTER(name) \
+static \
+int fun_get_##name(env_t *, int, val_t *result, val_t *args) \
+{ \
+ if (ENTITY_TYPE(0) == BL::PC) \
+ RESULTINT = ARGPC(0)->status.name; \
+ else \
+ RESULTINT = 0; \
+ return 0; \
+}
-MMO_GETTER (sp);
-MMO_GETTER (max_sp);
+MMO_GETTER(sp)
+MMO_GETTER(max_sp)
-static int
-fun_name_of (env_t * env, int args_nr, val_t * result, val_t * args)
+static
+int fun_name_of(env_t *, int, val_t *result, val_t *args)
{
- if (TY (0) == TY_ENTITY)
+ if (ARG_TYPE(0) == TYPE::ENTITY)
{
- RESULTSTR = strdup (show_entity (ARGENTITY (0)));
+ RESULTSTR = strdup(show_entity(ARGENTITY(0)));
return 0;
}
- else if (TY (0) == TY_SPELL)
+ else if (ARG_TYPE(0) == TYPE::SPELL)
{
- RESULTSTR = strdup (ARGSPELL (0)->name);
+ RESULTSTR = strdup(ARGSPELL(0)->name);
return 0;
}
- else if (TY (0) == TY_INVOCATION)
+ else if (ARG_TYPE(0) == TYPE::INVOCATION)
{
- RESULTSTR = strdup (ARGINVOCATION (0)->spell->name);
+ RESULTSTR = strdup(ARGINVOCATION(0)->spell->name);
return 0;
}
return 1;
}
/* [Freeyorp] I'm putting this one in as name_of seems to have issues with summoned or spawned mobs. */
-static int
-fun_mob_id (env_t * env, int args_nr, val_t * result, val_t * args)
+static
+int fun_mob_id(env_t *, int, val_t *result, val_t *args)
{
- if (ETY (0) != BL_MOB) return 1;
- RESULTINT = ((struct mob_data *) (ARGENTITY(0)))->mob_class;
+ if (ENTITY_TYPE(0) != BL::MOB)
+ return 1;
+ RESULTINT = ((struct mob_data *)(ARGENTITY(0)))->mob_class;
return 0;
}
-#define COPY_LOCATION(dest, src) (dest).x = (src).x; (dest).y = (src).y; (dest).m = (src).m;
+inline
+void COPY_LOCATION(entity_t& dest, location_t& src)
+{
+ dest.x = src.x;
+ dest.y = src.y;
+ dest.m = src.m;
+}
+
+inline
+void COPY_LOCATION(location_t& dest, entity_t& src)
+{
+ dest.x = src.x;
+ dest.y = src.y;
+ dest.m = src.m;
+}
-static int
-fun_location (env_t * env, int args_nr, val_t * result, val_t * args)
+static
+int fun_location(env_t *, int, val_t *result, val_t *args)
{
- COPY_LOCATION (RESULTLOCATION, *(ARGENTITY (0)));
+ COPY_LOCATION(RESULTLOCATION, *(ARGENTITY(0)));
return 0;
}
-static int fun_random (env_t * env, int args_nr, val_t * result, val_t * args)
+static
+int fun_random(env_t *, int, val_t *result, val_t *args)
{
- int delta = ARGINT (0);
+ int delta = ARGINT(0);
if (delta < 0)
delta = -delta;
if (delta == 0)
@@ -643,94 +708,98 @@ static int fun_random (env_t * env, int args_nr, val_t * result, val_t * args)
RESULTINT = 0;
return 0;
}
- RESULTINT = MRAND (delta);
+ RESULTINT = random_::to(delta);
- if (ARGINT (0) < 0)
+ if (ARGINT(0) < 0)
RESULTINT = -RESULTINT;
return 0;
}
-static int
-fun_random_dir (env_t * env, int args_nr, val_t * result, val_t * args)
+static
+int fun_random_dir(env_t *, int, val_t *result, val_t *args)
{
- if (ARGINT (0))
- RESULTDIR = mt_random () & 0x7;
+ if (ARGINT(0))
+ RESULTDIR = random_::choice({DIR::S, DIR::SW, DIR::W, DIR::NW, DIR::N, DIR::NE, DIR::E, DIR::SE});
else
- RESULTDIR = (mt_random () & 0x3) * 2;
+ RESULTDIR = random_::choice({DIR::S, DIR::W, DIR::N, DIR::E});
return 0;
}
-static int
-fun_hash_entity (env_t * env, int args_nr, val_t * result, val_t * args)
+static
+int fun_hash_entity(env_t *, int, val_t *result, val_t *args)
{
- RESULTINT = ARGENTITY (0)->id;
+ RESULTINT = ARGENTITY(0)->id;
return 0;
}
-int // ret -1: not a string, ret 1: no such item, ret 0: OK
-magic_find_item (val_t * args, int index, struct item *item, int *stackable)
+int // ret -1: not a string, ret 1: no such item, ret 0: OK
+magic_find_item(val_t *args, int index, struct item *item, int *stackable)
{
struct item_data *item_data;
- int must_add_sequentially;
+ int must_add_sequentially;
- if (TY (index) == TY_INT)
- item_data = itemdb_exists (ARGINT (index));
- else if (TY (index) == TY_STRING)
- item_data = itemdb_searchname (ARGSTR (index));
+ if (ARG_TYPE(index) == TYPE::INT)
+ item_data = itemdb_exists(ARGINT(index));
+ else if (ARG_TYPE(index) == TYPE::STRING)
+ item_data = itemdb_searchname(ARGSTR(index));
else
return -1;
if (!item_data)
return 1;
- must_add_sequentially = (item_data->type == 4 || item_data->type == 5 || item_data->type == 7 || item_data->type == 8); /* Very elegant. */
+ // Very elegant.
+ must_add_sequentially = (
+ item_data->type == ItemType::WEAPON
+ || item_data->type == ItemType::ARMOR
+ || item_data->type == ItemType::_7
+ || item_data->type == ItemType::_8);
if (stackable)
*stackable = !must_add_sequentially;
- memset (item, 0, sizeof (struct item));
+ memset(item, 0, sizeof(struct item));
item->nameid = item_data->nameid;
item->identify = 1;
return 0;
}
-static int
-fun_count_item (env_t * env, int args_nr, val_t * result, val_t * args)
+static
+int fun_count_item(env_t *, int, val_t *result, val_t *args)
{
- character_t *chr = (ETY (0) == BL_PC) ? ARGPC (0) : NULL;
- int stackable;
+ character_t *chr = (ENTITY_TYPE(0) == BL::PC) ? ARGPC(0) : NULL;
+ int stackable;
struct item item;
- GET_ARG_ITEM (1, item, stackable);
+ GET_ARG_ITEM(1, item, stackable);
if (!chr)
return 1;
- RESULTINT = pc_count_all_items (chr, item.nameid);
+ RESULTINT = pc_count_all_items(chr, item.nameid);
return 0;
}
-static int
-fun_is_equipped (env_t * env, int args_nr, val_t * result, val_t * args)
+static
+int fun_is_equipped(env_t *, int, val_t *result, val_t *args)
{
- character_t *chr = (ETY (0) == BL_PC) ? ARGPC (0) : NULL;
- int stackable;
+ character_t *chr = (ENTITY_TYPE(0) == BL::PC) ? ARGPC(0) : NULL;
+ int stackable;
struct item item;
- int i;
- int retval = 0;
+ bool retval = false;
- GET_ARG_ITEM (1, item, stackable);
+ GET_ARG_ITEM(1, item, stackable);
if (!chr)
return 1;
- for (i = 0; i < 11; i++)
+ for (EQUIP i : EQUIPs)
if (chr->equip_index[i] >= 0
&& chr->status.inventory[chr->equip_index[i]].nameid ==
item.nameid)
{
- retval = i + 1;
+ retval = true;
break;
}
@@ -738,48 +807,51 @@ fun_is_equipped (env_t * env, int args_nr, val_t * result, val_t * args)
return 0;
}
-static int
-fun_is_married (env_t * env, int args_nr, val_t * result, val_t * args)
+static
+int fun_is_married(env_t *, int, val_t *result, val_t *args)
{
- RESULTINT = (ETY (0) == BL_PC && ARGPC (0)->status.partner_id);
+ RESULTINT = (ENTITY_TYPE(0) == BL::PC && ARGPC(0)->status.partner_id);
return 0;
}
-static int
-fun_is_dead (env_t * env, int args_nr, val_t * result, val_t * args)
+static
+int fun_is_dead(env_t *, int, val_t *result, val_t *args)
{
- RESULTINT = (ETY (0) == BL_PC && pc_isdead (ARGPC (0)));
+ RESULTINT = (ENTITY_TYPE(0) == BL::PC && pc_isdead(ARGPC(0)));
return 0;
}
-static int fun_is_pc (env_t * env, int args_nr, val_t * result, val_t * args)
+static
+int fun_is_pc(env_t *, int, val_t *result, val_t *args)
{
- RESULTINT = (ETY (0) == BL_PC);
+ RESULTINT = (ENTITY_TYPE(0) == BL::PC);
return 0;
}
-static int
-fun_partner (env_t * env, int args_nr, val_t * result, val_t * args)
+static
+int fun_partner(env_t *, int, val_t *result, val_t *args)
{
- if (ETY (0) == BL_PC && ARGPC (0)->status.partner_id)
+ if (ENTITY_TYPE(0) == BL::PC && ARGPC(0)->status.partner_id)
{
RESULTENTITY =
(entity_t *)
- map_nick2sd (map_charid2nick (ARGPC (0)->status.partner_id));
+ map_nick2sd(map_charid2nick(ARGPC(0)->status.partner_id));
return 0;
}
else
return 1;
}
-static int
-fun_awayfrom (env_t * env, int args_nr, val_t * result, val_t * args)
-{
- location_t *loc = &ARGLOCATION (0);
- int dx = heading_x[ARGDIR (1)];
- int dy = heading_y[ARGDIR (1)];
- int distance = ARGINT (2);
- while (distance-- && !map_is_solid (loc->m, loc->x + dx, loc->y + dy))
+static
+int fun_awayfrom(env_t *, int, val_t *result, val_t *args)
+{
+ location_t *loc = &ARGLOCATION(0);
+ int dx = dirx[ARGDIR(1)];
+ int dy = diry[ARGDIR(1)];
+ int distance = ARGINT(2);
+ while (distance--
+ && !bool(read_gat(loc->m, loc->x + dx, loc->y + dy)
+ & MapCell::UNWALKABLE))
{
loc->x += dx;
loc->y += dy;
@@ -789,101 +861,104 @@ fun_awayfrom (env_t * env, int args_nr, val_t * result, val_t * args)
return 0;
}
-static int fun_failed (env_t * env, int args_nr, val_t * result, val_t * args)
+static
+int fun_failed(env_t *, int, val_t *result, val_t *args)
{
- RESULTINT = TY (0) == TY_FAIL;
+ RESULTINT = ARG_TYPE(0) == TYPE::FAIL;
return 0;
}
-static int fun_npc (env_t * env, int args_nr, val_t * result, val_t * args)
+static
+int fun_npc(env_t *, int, val_t *result, val_t *args)
{
- RESULTENTITY = (entity_t *) npc_name2id (ARGSTR (0));
+ RESULTENTITY = (entity_t *) npc_name2id(ARGSTR(0));
return RESULTENTITY == NULL;
}
-static int fun_pc (env_t * env, int args_nr, val_t * result, val_t * args)
+static
+int fun_pc(env_t *, int, val_t *result, val_t *args)
{
- RESULTENTITY = (entity_t *) map_nick2sd (ARGSTR (0));
+ RESULTENTITY = (entity_t *) map_nick2sd(ARGSTR(0));
return RESULTENTITY == NULL;
}
-static int
-fun_distance (env_t * env, int args_nr, val_t * result, val_t * args)
+static
+int fun_distance(env_t *, int, val_t *result, val_t *args)
{
- if (ARGLOCATION (0).m != ARGLOCATION (1).m)
- RESULTINT = INT_MAX;
+ if (ARGLOCATION(0).m != ARGLOCATION(1).m)
+ RESULTINT = 0x7fffffff;
else
- RESULTINT = MAX (abs (ARGLOCATION (0).x - ARGLOCATION (1).x),
- abs (ARGLOCATION (0).y - ARGLOCATION (1).y));
+ RESULTINT = max(abs(ARGLOCATION(0).x - ARGLOCATION(1).x),
+ abs(ARGLOCATION(0).y - ARGLOCATION(1).y));
return 0;
}
-static int
-fun_rdistance (env_t * env, int args_nr, val_t * result, val_t * args)
+static
+int fun_rdistance(env_t *, int, val_t *result, val_t *args)
{
- if (ARGLOCATION (0).m != ARGLOCATION (1).m)
- RESULTINT = INT_MAX;
+ if (ARGLOCATION(0).m != ARGLOCATION(1).m)
+ RESULTINT = 0x7fffffff;
else
{
- int dx = ARGLOCATION (0).x - ARGLOCATION (1).x;
- int dy = ARGLOCATION (0).y - ARGLOCATION (1).y;
- RESULTINT = (int) (sqrt ((dx * dx) + (dy * dy)));
+ int dx = ARGLOCATION(0).x - ARGLOCATION(1).x;
+ int dy = ARGLOCATION(0).y - ARGLOCATION(1).y;
+ RESULTINT = (int)(sqrt((dx * dx) + (dy * dy)));
}
return 0;
}
-static int fun_anchor (env_t * env, int args_nr, val_t * result, val_t * args)
+static
+int fun_anchor(env_t *env, int, val_t *result, val_t *args)
{
- teleport_anchor_t *anchor = magic_find_anchor (ARGSTR (0));
+ teleport_anchor_t *anchor = magic_find_anchor(ARGSTR(0));
if (!anchor)
return 1;
- magic_eval (env, result, anchor->location);
+ magic_eval(env, result, anchor->location);
- make_area (result);
- if (result->ty != TY_AREA)
+ make_area(result);
+ if (result->ty != TYPE::AREA)
{
- magic_clear_var (result);
+ magic_clear_var(result);
return 1;
}
return 0;
}
-static int
-fun_line_of_sight (env_t * env, int args_nr, val_t * result, val_t * args)
+static
+int fun_line_of_sight(env_t *, int, val_t *result, val_t *args)
{
entity_t e1, e2;
- COPY_LOCATION (e1, ARGLOCATION (0));
- COPY_LOCATION (e2, ARGLOCATION (1));
+ COPY_LOCATION(e1, ARGLOCATION(0));
+ COPY_LOCATION(e2, ARGLOCATION(1));
- RESULTINT = battle_check_range (&e1, &e2, 0);
+ RESULTINT = battle_check_range(&e1, &e2, 0);
return 0;
}
-void magic_random_location (location_t * dest, area_t * area)
+void magic_random_location(location_t *dest, area_t *area)
{
switch (area->ty)
{
- case AREA_UNION:
+ case AREA::UNION:
{
- int rv = MRAND (area->size);
- if (rv < area->a.a_union[0]->size)
- magic_random_location (dest, area->a.a_union[0]);
+ if (random_::chance({area->a.a_union[0]->size, area->size}))
+ magic_random_location(dest, area->a.a_union[0]);
else
- magic_random_location (dest, area->a.a_union[1]);
+ magic_random_location(dest, area->a.a_union[1]);
break;
}
- case AREA_LOCATION:
- case AREA_RECT:
- case AREA_BAR:
+ case AREA::LOCATION:
+ case AREA::RECT:
+ case AREA::BAR:
{
- int m, x, y, w, h;
- magic_area_rect (&m, &x, &y, &w, &h, area);
+ int m, x, y, w, h;
+ magic_area_rect(&m, &x, &y, &w, &h, area);
if (w <= 1)
w = 1;
@@ -891,73 +966,49 @@ void magic_random_location (location_t * dest, area_t * area)
if (h <= 1)
h = 1;
- x += MRAND (w);
- y += MRAND (h);
-
- if (!map_is_solid (m, x, y))
- {
- int start_x = x;
- int start_y = y;
- int i;
- int initial_dir = mt_random () & 0x7;
- int dir = initial_dir;
-
- /* try all directions, up to a distance to 10, for a free slot */
- do
- {
- x = start_x;
- y = start_y;
-
- for (i = 0; i < 10 && map_is_solid (m, x, y); i++)
- {
- x += heading_x[dir];
- y += heading_y[dir];
- }
-
- dir = (dir + 1) & 0x7;
- }
- while (map_is_solid (m, x, y) && dir != initial_dir);
-
- }
- /* We've tried our best. If the map is still solid, the engine will automatically randomise the target location if we try to warp. */
+ // This is not exactly the same as the old logic,
+ // but it's better.
+ auto pair = map_randfreecell(m, x, y, w, h);
dest->m = m;
- dest->x = x;
- dest->y = y;
+ dest->x = pair.first;
+ dest->y = pair.second;
break;
}
default:
- fprintf (stderr, "Unknown area type %d\n", area->ty);
+ FPRINTF(stderr, "Unknown area type %d\n",
+ area->ty);
}
}
-static int
-fun_pick_location (env_t * env, int args_nr, val_t * result, val_t * args)
+static
+int fun_pick_location(env_t *, int, val_t *result, val_t *args)
{
- magic_random_location (&result->v.v_location, ARGAREA (0));
+ magic_random_location(&result->v.v_location, ARGAREA(0));
return 0;
}
-static int
-fun_read_script_int (env_t * env, int args_nr, val_t * result, val_t * args)
+static
+int fun_read_script_int(env_t *, int, val_t *result, val_t *args)
{
- entity_t *subject_p = ARGENTITY (0);
- char *var_name = ARGSTR (1);
+ entity_t *subject_p = ARGENTITY(0);
+ char *var_name = ARGSTR(1);
- if (subject_p->type != BL_PC)
+ if (subject_p->type != BL::PC)
return 1;
- RESULTINT = pc_readglobalreg ((character_t *) subject_p, var_name);
+ RESULTINT = pc_readglobalreg((character_t *) subject_p, var_name);
return 0;
}
-static int fun_rbox (env_t * env, int args_nr, val_t * result, val_t * args)
+static
+int fun_rbox(env_t *, int, val_t *result, val_t *args)
{
- location_t loc = ARGLOCATION (0);
- int radius = ARGINT (1);
+ location_t loc = ARGLOCATION(0);
+ int radius = ARGINT(1);
- RESULTAREA = area_new (AREA_RECT);
+ RESULTAREA = area_new(AREA::RECT);
RESULTAREA->a.a_rect.loc.m = loc.m;
RESULTAREA->a.a_rect.loc.x = loc.x - radius;
RESULTAREA->a.a_rect.loc.y = loc.y - radius;
@@ -967,79 +1018,83 @@ static int fun_rbox (env_t * env, int args_nr, val_t * result, val_t * args)
return 0;
}
-static int
-fun_running_status_update (env_t * env, int args_nr, val_t * result,
- val_t * args)
+static
+int fun_running_status_update(env_t *, int, val_t *result, val_t *args)
{
- if (ETY (0) != BL_PC && ETY (0) != BL_MOB)
+ if (ENTITY_TYPE(0) != BL::PC && ENTITY_TYPE(0) != BL::MOB)
return 1;
- RESULTINT = battle_get_sc_data (ARGENTITY (0))[ARGINT (1)].timer != -1;
+ StatusChange sc = StatusChange(ARGINT(1));
+ RESULTINT = bool(battle_get_sc_data(ARGENTITY(0))[sc].timer);
return 0;
}
-static int
-fun_status_option (env_t * env, int args_nr, val_t * result, val_t * args)
+static
+int fun_status_option(env_t *, int, val_t *result, val_t *args)
{
RESULTINT =
- ((((struct map_session_data *) ARGENTITY (0))->
- status.option & ARGINT (0)) != 0);
+ (bool(((struct map_session_data *) ARGENTITY(0))->
+ status.option & Option(ARGINT(0))));
return 0;
}
-static int
-fun_element (env_t * env, int args_nr, val_t * result, val_t * args)
+static
+int fun_element(env_t *, int, val_t *result, val_t *args)
{
- RESULTINT = battle_get_element (ARGENTITY (0)) % 10;
+ RESULTINT = static_cast<int>(battle_get_element(ARGENTITY(0)).element);
return 0;
}
-static int
-fun_element_level (env_t * env, int args_nr, val_t * result, val_t * args)
+static
+int fun_element_level(env_t *, int, val_t *result, val_t *args)
{
- RESULTINT = battle_get_element (ARGENTITY (0)) / 10;
+ RESULTINT = battle_get_element(ARGENTITY(0)).level;
return 0;
}
-static int fun_index (env_t * env, int args_nr, val_t * result, val_t * args)
+static
+int fun_index(env_t *, int, val_t *result, val_t *args)
{
- RESULTINT = ARGSPELL (0)->index;
+ RESULTINT = ARGSPELL(0)->index;
return 0;
}
-static int
-fun_is_exterior (env_t * env, int args_nr, val_t * result, val_t * args)
+static
+int fun_is_exterior(env_t *, int, val_t *result, val_t *args)
{
- RESULTINT = map[ARGLOCATION (0).m].name[4] == '1';
+ RESULTINT = map[ARGLOCATION(0).m].name[4] == '1';
return 0;
}
-static int
-fun_contains_string (env_t * env, int args_nr, val_t * result, val_t * args)
+static
+int fun_contains_string(env_t *, int, val_t *result, val_t *args)
{
- RESULTINT = NULL != strstr (ARGSTR (0), ARGSTR (1));
+ RESULTINT = NULL != strstr(ARGSTR(0), ARGSTR(1));
return 0;
}
-static int fun_strstr (env_t * env, int args_nr, val_t * result, val_t * args)
+static
+int fun_strstr(env_t *, int, val_t *result, val_t *args)
{
- char *offset = strstr (ARGSTR (0), ARGSTR (1));
- RESULTINT = offset - ARGSTR (0);
+ char *offset = strstr(ARGSTR(0), ARGSTR(1));
+ RESULTINT = offset - ARGSTR(0);
return offset == NULL;
}
-static int fun_strlen (env_t * env, int args_nr, val_t * result, val_t * args)
+static
+int fun_strlen(env_t *, int, val_t *result, val_t *args)
{
- RESULTINT = strlen (ARGSTR (0));
+ RESULTINT = strlen(ARGSTR(0));
return 0;
}
-static int fun_substr (env_t * env, int args_nr, val_t * result, val_t * args)
+static
+int fun_substr(env_t *, int, val_t *result, val_t *args)
{
- const char *src = ARGSTR (0);
- const int slen = strlen (src);
- int offset = ARGINT (1);
- int len = ARGINT (2);
+ const char *src = ARGSTR(0);
+ const int slen = strlen(src);
+ int offset = ARGINT(1);
+ int len = ARGINT(2);
if (len < 0)
len = 0;
@@ -1052,57 +1107,59 @@ static int fun_substr (env_t * env, int args_nr, val_t * result, val_t * args)
if (offset + len > slen)
len = slen - offset;
- RESULTSTR = (char *) calloc (1, 1 + len);
- memcpy (RESULTSTR, src + offset, len);
+ RESULTSTR = (char *) calloc(1, 1 + len);
+ memcpy(RESULTSTR, src + offset, len);
return 0;
}
-static int fun_sqrt (env_t * env, int args_nr, val_t * result, val_t * args)
+static
+int fun_sqrt(env_t *, int, val_t *result, val_t *args)
{
- RESULTINT = (int) sqrt (ARGINT (0));
+ RESULTINT = (int) sqrt(ARGINT(0));
return 0;
}
-static int
-fun_map_level (env_t * env, int args_nr, val_t * result, val_t * args)
+static
+int fun_map_level(env_t *, int, val_t *result, val_t *args)
{
- RESULTINT = map[ARGLOCATION (0).m].name[4] - '0';
+ RESULTINT = map[ARGLOCATION(0).m].name[4] - '0';
return 0;
}
-static int fun_map_nr (env_t * env, int args_nr, val_t * result, val_t * args)
+static
+int fun_map_nr(env_t *, int, val_t *result, val_t *args)
{
- const char *mapname = map[ARGLOCATION (0).m].name;
+ const char *mapname = map[ARGLOCATION(0).m].name;
RESULTINT = ((mapname[0] - '0') * 100)
+ ((mapname[1] - '0') * 10) + ((mapname[2] - '0'));
return 0;
}
-static int
-fun_dir_towards (env_t * env, int args_nr, val_t * result, val_t * args)
+static
+int fun_dir_towards(env_t *, int, val_t *result, val_t *args)
{
- int dx;
- int dy;
+ int dx;
+ int dy;
- if (ARGLOCATION (0).m != ARGLOCATION (1).m)
+ if (ARGLOCATION(0).m != ARGLOCATION(1).m)
return 1;
- dx = ARGLOCATION (1).x - ARGLOCATION (0).x;
- dy = ARGLOCATION (1).y - ARGLOCATION (0).y;
+ dx = ARGLOCATION(1).x - ARGLOCATION(0).x;
+ dy = ARGLOCATION(1).y - ARGLOCATION(0).y;
- if (ARGINT (1))
+ if (ARGINT(1))
{
/* 8-direction mode */
- if (abs (dx) > abs (dy) * 2)
+ if (abs(dx) > abs(dy) * 2)
{ /* east or west */
if (dx < 0)
RESULTINT = 2 /* west */ ;
else
RESULTINT = 6 /* east */ ;
}
- else if (abs (dy) > abs (dx) * 2)
+ else if (abs(dy) > abs(dx) * 2)
{ /* north or south */
if (dy > 0)
RESULTINT = 0 /* south */ ;
@@ -1127,7 +1184,7 @@ fun_dir_towards (env_t * env, int args_nr, val_t * result, val_t * args)
else
{
/* 4-direction mode */
- if (abs (dx) > abs (dy))
+ if (abs(dx) > abs(dy))
{ /* east or west */
if (dx < 0)
RESULTINT = 2 /* west */ ;
@@ -1146,21 +1203,20 @@ fun_dir_towards (env_t * env, int args_nr, val_t * result, val_t * args)
return 0;
}
-static int
-fun_extract_healer_xp (env_t * env, int args_nr, val_t * result, val_t * args)
+static
+int fun_extract_healer_xp(env_t *, int, val_t *result, val_t *args)
{
- character_t *sd = (ETY (0) == BL_PC) ? ARGPC (0) : NULL;
+ character_t *sd = (ENTITY_TYPE(0) == BL::PC) ? ARGPC(0) : NULL;
if (!sd)
RESULTINT = 0;
else
- RESULTINT = pc_extract_healer_exp (sd, ARGINT (1));
+ RESULTINT = pc_extract_healer_exp(sd, ARGINT(1));
return 0;
}
-#define BATTLE_RECORD2(sname, name) { sname, "e", 'i', fun_get_##name }
-#define BATTLE_RECORD(name) BATTLE_RECORD2(#name, name)
-static fun_t functions[] = {
+static
+fun_t functions[] = {
{"+", "..", '.', fun_add},
{"-", "ii", 'i', fun_sub},
{"*", "ii", 'i', fun_mul},
@@ -1183,19 +1239,19 @@ static fun_t functions[] = {
{"is_in", "la", 'i', fun_is_in},
{"if_then_else", "i__", '_', fun_if_then_else},
{"skill", "ei", 'i', fun_skill},
- BATTLE_RECORD (str),
- BATTLE_RECORD (agi),
- BATTLE_RECORD (vit),
- BATTLE_RECORD (dex),
- BATTLE_RECORD (luk),
- BATTLE_RECORD (int),
- BATTLE_RECORD2 ("level", lv),
- BATTLE_RECORD (mdef),
- BATTLE_RECORD (def),
- BATTLE_RECORD (hp),
- BATTLE_RECORD (max_hp),
- BATTLE_RECORD (sp),
- BATTLE_RECORD (max_sp),
+ {"str", "e", 'i', fun_get_str},
+ {"agi", "e", 'i', fun_get_agi},
+ {"vit", "e", 'i', fun_get_vit},
+ {"dex", "e", 'i', fun_get_dex},
+ {"luk", "e", 'i', fun_get_luk},
+ {"int", "e", 'i', fun_get_int},
+ {"level", "e", 'i', fun_get_lv},
+ {"mdef", "e", 'i', fun_get_mdef},
+ {"def", "e", 'i', fun_get_def},
+ {"hp", "e", 'i', fun_get_hp},
+ {"max_hp", "e", 'i', fun_get_max_hp},
+ {"sp", "e", 'i', fun_get_sp},
+ {"max_sp", "e", 'i', fun_get_max_sp},
{"dir", "e", 'd', fun_get_dir},
{"name_of", ".", 's', fun_name_of},
{"mob_id", "e", 'i', fun_mob_id},
@@ -1239,17 +1295,19 @@ static fun_t functions[] = {
{NULL, NULL, '.', NULL}
};
-static int functions_are_sorted = 0;
+static
+int functions_are_sorted = 0;
static
-int compare_fun (const void *lhs, const void *rhs)
+int compare_fun(const void *lhs, const void *rhs)
{
- return strcmp (((fun_t *) lhs)->name, ((fun_t *) rhs)->name);
+ return strcmp(((const fun_t *) lhs)->name, ((const fun_t *) rhs)->name);
}
-fun_t *magic_get_fun (const char *name, int *index)
+fun_t *magic_get_fun(const char *name, int *index)
{
- static int functions_nr;
+ static
+int functions_nr;
fun_t *result;
fun_t key;
@@ -1261,12 +1319,12 @@ fun_t *magic_get_fun (const char *name, int *index)
++it;
functions_nr = it - functions;
- qsort (functions, functions_nr, sizeof (fun_t), compare_fun);
+ qsort(functions, functions_nr, sizeof(fun_t), compare_fun);
functions_are_sorted = 1;
}
key.name = name;
- result = (fun_t *) bsearch (&key, functions, functions_nr, sizeof (fun_t),
+ result = (fun_t *) bsearch(&key, functions, functions_nr, sizeof(fun_t),
compare_fun);
if (result && index)
@@ -1275,19 +1333,20 @@ fun_t *magic_get_fun (const char *name, int *index)
return result;
}
-static int // 1 on failure
-eval_location (env_t * env, location_t * dest, e_location_t * expr)
+static
+int // 1 on failure
+eval_location(env_t *env, location_t *dest, e_location_t *expr)
{
val_t m, x, y;
- magic_eval (env, &m, expr->m);
- magic_eval (env, &x, expr->x);
- magic_eval (env, &y, expr->y);
+ magic_eval(env, &m, expr->m);
+ magic_eval(env, &x, expr->x);
+ magic_eval(env, &y, expr->y);
- if (CHECK_TYPE (&m, TY_STRING)
- && CHECK_TYPE (&x, TY_INT) && CHECK_TYPE (&y, TY_INT))
+ if (CHECK_TYPE(&m, TYPE::STRING)
+ && CHECK_TYPE(&x, TYPE::INT) && CHECK_TYPE(&y, TYPE::INT))
{
- int map_id = map_mapname2mapid (m.v.v_string);
- magic_clear_var (&m);
+ int map_id = map_mapname2mapid(m.v.v_string);
+ magic_clear_var(&m);
if (map_id < 0)
return 1;
dest->m = map_id;
@@ -1297,36 +1356,37 @@ eval_location (env_t * env, location_t * dest, e_location_t * expr)
}
else
{
- magic_clear_var (&m);
- magic_clear_var (&x);
- magic_clear_var (&y);
+ magic_clear_var(&m);
+ magic_clear_var(&x);
+ magic_clear_var(&y);
return 1;
}
}
-static area_t *eval_area (env_t * env, e_area_t * expr)
+static
+area_t *eval_area(env_t *env, e_area_t *expr)
{
- area_t *area = (area_t *)malloc (sizeof (area_t));
+ area_t *area = (area_t *)malloc(sizeof(area_t));
area->ty = expr->ty;
switch (expr->ty)
{
- case AREA_LOCATION:
+ case AREA::LOCATION:
area->size = 1;
- if (eval_location (env, &area->a.a_loc, &expr->a.a_loc))
+ if (eval_location(env, &area->a.a_loc, &expr->a.a_loc))
{
- free (area);
+ free(area);
return NULL;
}
else
return area;
- case AREA_UNION:
+ case AREA::UNION:
{
- int i, fail = 0;
+ int i, fail = 0;
for (i = 0; i < 2; i++)
{
- area->a.a_union[i] = eval_area (env, expr->a.a_union[i]);
+ area->a.a_union[i] = eval_area(env, expr->a.a_union[i]);
if (!area->a.a_union[i])
fail = 1;
}
@@ -1336,152 +1396,153 @@ static area_t *eval_area (env_t * env, e_area_t * expr)
for (i = 0; i < 2; i++)
{
if (area->a.a_union[i])
- free_area (area->a.a_union[i]);
+ free_area(area->a.a_union[i]);
}
- free (area);
+ free(area);
return NULL;
}
area->size = area->a.a_union[0]->size + area->a.a_union[1]->size;
return area;
}
- case AREA_RECT:
+ case AREA::RECT:
{
val_t width, height;
- magic_eval (env, &width, expr->a.a_rect.width);
- magic_eval (env, &height, expr->a.a_rect.height);
+ magic_eval(env, &width, expr->a.a_rect.width);
+ magic_eval(env, &height, expr->a.a_rect.height);
area->a.a_rect.width = width.v.v_int;
area->a.a_rect.height = height.v.v_int;
- if (CHECK_TYPE (&width, TY_INT)
- && CHECK_TYPE (&height, TY_INT)
- && !eval_location (env, &(area->a.a_rect.loc),
+ if (CHECK_TYPE(&width, TYPE::INT)
+ && CHECK_TYPE(&height, TYPE::INT)
+ && !eval_location(env, &(area->a.a_rect.loc),
&expr->a.a_rect.loc))
{
area->size = area->a.a_rect.width * area->a.a_rect.height;
- magic_clear_var (&width);
- magic_clear_var (&height);
+ magic_clear_var(&width);
+ magic_clear_var(&height);
return area;
}
else
{
- free (area);
- magic_clear_var (&width);
- magic_clear_var (&height);
+ free(area);
+ magic_clear_var(&width);
+ magic_clear_var(&height);
return NULL;
}
}
- case AREA_BAR:
+ case AREA::BAR:
{
val_t width, depth, dir;
- magic_eval (env, &width, expr->a.a_bar.width);
- magic_eval (env, &depth, expr->a.a_bar.depth);
- magic_eval (env, &dir, expr->a.a_bar.dir);
+ magic_eval(env, &width, expr->a.a_bar.width);
+ magic_eval(env, &depth, expr->a.a_bar.depth);
+ magic_eval(env, &dir, expr->a.a_bar.dir);
area->a.a_bar.width = width.v.v_int;
area->a.a_bar.depth = depth.v.v_int;
- area->a.a_bar.dir = dir.v.v_int;
+ area->a.a_bar.dir = dir.v.v_dir;
- if (CHECK_TYPE (&width, TY_INT)
- && CHECK_TYPE (&depth, TY_INT)
- && CHECK_TYPE (&dir, TY_DIR)
- && !eval_location (env, &area->a.a_bar.loc,
+ if (CHECK_TYPE(&width, TYPE::INT)
+ && CHECK_TYPE(&depth, TYPE::INT)
+ && CHECK_TYPE(&dir, TYPE::DIR)
+ && !eval_location(env, &area->a.a_bar.loc,
&expr->a.a_bar.loc))
{
area->size =
(area->a.a_bar.width * 2 + 1) * area->a.a_bar.depth;
- magic_clear_var (&width);
- magic_clear_var (&depth);
- magic_clear_var (&dir);
+ magic_clear_var(&width);
+ magic_clear_var(&depth);
+ magic_clear_var(&dir);
return area;
}
else
{
- free (area);
- magic_clear_var (&width);
- magic_clear_var (&depth);
- magic_clear_var (&dir);
+ free(area);
+ magic_clear_var(&width);
+ magic_clear_var(&depth);
+ magic_clear_var(&dir);
return NULL;
}
}
default:
- fprintf (stderr, "INTERNAL ERROR: Unknown area type %d\n",
- area->ty);
- free (area);
+ FPRINTF(stderr, "INTERNAL ERROR: Unknown area type %d\n",
+ area->ty);
+ free(area);
return NULL;
}
}
-static int type_key (char ty_key)
+static
+TYPE type_key(char ty_key)
{
switch (ty_key)
{
case 'i':
- return TY_INT;
+ return TYPE::INT;
case 'd':
- return TY_DIR;
+ return TYPE::DIR;
case 's':
- return TY_STRING;
+ return TYPE::STRING;
case 'e':
- return TY_ENTITY;
+ return TYPE::ENTITY;
case 'l':
- return TY_LOCATION;
+ return TYPE::LOCATION;
case 'a':
- return TY_AREA;
+ return TYPE::AREA;
case 'S':
- return TY_SPELL;
+ return TYPE::SPELL;
case 'I':
- return TY_INVOCATION;
+ return TYPE::INVOCATION;
default:
- return -1;
+ return TYPE::NEGATIVE_1;
}
}
-int magic_signature_check (const char *opname, const char *funname, const char *signature,
- int args_nr, val_t * args, int line, int column)
+int magic_signature_check(const char *opname, const char *funname, const char *signature,
+ int args_nr, val_t *args, int line, int column)
{
- int i;
+ int i;
for (i = 0; i < args_nr; i++)
{
val_t *arg = &args[i];
char ty_key = signature[i];
- int ty = arg->ty;
- int desired_ty = type_key (ty_key);
+ TYPE ty = arg->ty;
+ TYPE desired_ty = type_key(ty_key);
- if (ty == TY_ENTITY)
+ if (ty == TYPE::ENTITY)
{
/* Dereference entities in preparation for calling function */
- arg->v.v_entity = map_id2bl (arg->v.v_int);
+ arg->v.v_entity = map_id2bl(arg->v.v_int);
if (!arg->v.v_entity)
- ty = arg->ty = TY_FAIL;
+ ty = arg->ty = TYPE::FAIL;
}
- else if (ty == TY_INVOCATION)
+ else if (ty == TYPE::INVOCATION)
{
- arg->v.v_invocation = (invocation_t *) map_id2bl (arg->v.v_int);
+ arg->v.v_invocation = (invocation_t *) map_id2bl(arg->v.v_int);
if (!arg->v.v_entity)
- ty = arg->ty = TY_FAIL;
+ ty = arg->ty = TYPE::FAIL;
}
if (!ty_key)
{
- fprintf (stderr,
+ FPRINTF(stderr,
"[magic-eval]: L%d:%d: Too many arguments (%d) to %s `%s'\n",
line, column, args_nr, opname, funname);
return 1;
}
- if (ty == TY_FAIL && ty_key != '_')
+ if (ty == TYPE::FAIL && ty_key != '_')
return 1; /* Fail `in a sane way': This is a perfectly permissible error */
- if (ty == desired_ty || desired_ty < 0 /* `dontcare' */ )
+ if (ty == desired_ty || desired_ty == TYPE::NEGATIVE_1)
continue;
- if (ty == TY_UNDEF)
+ if (ty == TYPE::UNDEF)
{
- fprintf (stderr,
+ FPRINTF(stderr,
"[magic-eval]: L%d:%d: Argument #%d to %s `%s' undefined\n",
line, column, i + 1, opname, funname);
return 1;
@@ -1490,20 +1551,20 @@ int magic_signature_check (const char *opname, const char *funname, const char *
/* If we are here, we have a type mismatch but no failure _yet_. Try to coerce. */
switch (desired_ty)
{
- case TY_INT:
- intify (arg);
+ case TYPE::INT:
+ intify(arg);
break; /* 100% success rate */
- case TY_STRING:
- stringify (arg, 1);
+ case TYPE::STRING:
+ stringify(arg, 1);
break; /* 100% success rate */
- case TY_AREA:
- make_area (arg);
+ case TYPE::AREA:
+ make_area(arg);
break; /* Only works for locations */
- case TY_LOCATION:
- make_location (arg);
+ case TYPE::LOCATION:
+ make_location(arg);
break; /* Only works for some areas */
- case TY_SPELL:
- make_spell (arg);
+ case TYPE::SPELL:
+ make_spell(arg);
break; /* Only works for still-active invocatoins */
default:
break; /* We'll fail right below */
@@ -1512,10 +1573,11 @@ int magic_signature_check (const char *opname, const char *funname, const char *
ty = arg->ty;
if (ty != desired_ty)
{ /* Coercion failed? */
- if (ty != TY_FAIL)
- fprintf (stderr,
+ if (ty != TYPE::FAIL)
+ FPRINTF(stderr,
"[magic-eval]: L%d:%d: Argument #%d to %s `%s' of incorrect type (%d)\n",
- line, column, i + 1, opname, funname, ty);
+ line, column, i + 1, opname, funname,
+ ty);
return 1;
}
}
@@ -1525,149 +1587,139 @@ int magic_signature_check (const char *opname, const char *funname, const char *
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wshadow"
-void magic_eval (env_t * env, val_t * dest, expr_t * expr)
+void magic_eval(env_t *env, val_t *dest, expr_t *expr)
{
-#ifdef RECENT_GCC
#pragma GCC diagnostic pop
-#endif
switch (expr->ty)
{
- case EXPR_VAL:
- magic_copy_var (dest, &expr->e.e_val);
+ case EXPR::VAL:
+ magic_copy_var(dest, &expr->e.e_val);
break;
- case EXPR_LOCATION:
- if (eval_location (env, &dest->v.v_location, &expr->e.e_location))
- dest->ty = TY_FAIL;
+ case EXPR::LOCATION:
+ if (eval_location(env, &dest->v.v_location, &expr->e.e_location))
+ dest->ty = TYPE::FAIL;
else
- dest->ty = TY_LOCATION;
+ dest->ty = TYPE::LOCATION;
break;
- case EXPR_AREA:
- if ((dest->v.v_area = eval_area (env, &expr->e.e_area)))
- dest->ty = TY_AREA;
+ case EXPR::AREA:
+ if ((dest->v.v_area = eval_area(env, &expr->e.e_area)))
+ dest->ty = TYPE::AREA;
else
- dest->ty = TY_FAIL;
+ dest->ty = TYPE::FAIL;
break;
- case EXPR_FUNAPP:
+ case EXPR::FUNAPP:
{
val_t arguments[MAX_ARGS];
- int args_nr = expr->e.e_funapp.args_nr;
- int i;
+ int args_nr = expr->e.e_funapp.args_nr;
+ int i;
fun_t *f = functions + expr->e.e_funapp.id;
for (i = 0; i < args_nr; ++i)
- magic_eval (env, &arguments[i], expr->e.e_funapp.args[i]);
- if (magic_signature_check
- ("function", f->name, f->signature, args_nr, arguments,
+ magic_eval(env, &arguments[i], expr->e.e_funapp.args[i]);
+ if (magic_signature_check("function", f->name, f->signature, args_nr, arguments,
expr->e.e_funapp.line_nr, expr->e.e_funapp.column)
- || f->fun (env, args_nr, dest, arguments))
- dest->ty = TY_FAIL;
+ || f->fun(env, args_nr, dest, arguments))
+ dest->ty = TYPE::FAIL;
else
{
- int dest_ty = type_key (f->ret_ty);
- if (dest_ty != -1)
+ TYPE dest_ty = type_key(f->ret_ty);
+ if (dest_ty != TYPE::NEGATIVE_1)
dest->ty = dest_ty;
/* translate entity back into persistent int */
- if (dest->ty == TY_ENTITY)
+ if (dest->ty == TYPE::ENTITY)
{
if (dest->v.v_entity)
dest->v.v_int = dest->v.v_entity->id;
else
- dest->ty = TY_FAIL;
+ dest->ty = TYPE::FAIL;
}
}
for (i = 0; i < args_nr; ++i)
- magic_clear_var (&arguments[i]);
+ magic_clear_var(&arguments[i]);
break;
}
- case EXPR_ID:
+ case EXPR::ID:
{
- val_t v = VAR (expr->e.e_id);
- magic_copy_var (dest, &v);
+ val_t v = VAR(expr->e.e_id);
+ magic_copy_var(dest, &v);
break;
}
- case EXPR_SPELLFIELD:
+ case EXPR::SPELLFIELD:
{
val_t v;
- int id = expr->e.e_field.id;
- magic_eval (env, &v, expr->e.e_field.expr);
+ int id = expr->e.e_field.id;
+ magic_eval(env, &v, expr->e.e_field.expr);
- if (v.ty == TY_INVOCATION)
+ if (v.ty == TYPE::INVOCATION)
{
- invocation_t *t = (invocation_t *) map_id2bl (v.v.v_int);
+ invocation_t *t = (invocation_t *) map_id2bl(v.v.v_int);
if (!t)
- dest->ty = TY_UNDEF;
+ dest->ty = TYPE::UNDEF;
else
{
-#ifdef RECENT_GCC
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wshadow"
-#endif
env_t *env = t->env;
-#ifdef RECENT_GCC
#pragma GCC diagnostic pop
-#endif
- val_t val = VAR (id);
- magic_copy_var (dest, &val);
+ val_t val = VAR(id);
+ magic_copy_var(dest, &val);
}
}
else
{
- fprintf (stderr,
+ FPRINTF(stderr,
"[magic] Attempt to access field %s on non-spell\n",
env->base_env->var_name[id]);
- dest->ty = TY_FAIL;
+ dest->ty = TYPE::FAIL;
}
break;
}
default:
- fprintf (stderr,
+ FPRINTF(stderr,
"[magic] INTERNAL ERROR: Unknown expression type %d\n",
expr->ty);
break;
}
}
-#ifndef RECENT_GCC
-#pragma GCC diagnostic pop
-#endif
-int magic_eval_int (env_t * env, expr_t * expr)
+int magic_eval_int(env_t *env, expr_t *expr)
{
val_t result;
- magic_eval (env, &result, expr);
+ magic_eval(env, &result, expr);
- if (result.ty == TY_FAIL || result.ty == TY_UNDEF)
+ if (result.ty == TYPE::FAIL || result.ty == TYPE::UNDEF)
return 0;
- intify (&result);
+ intify(&result);
return result.v.v_int;
}
-char *magic_eval_str (env_t * env, expr_t * expr)
+char *magic_eval_str(env_t *env, expr_t *expr)
{
val_t result;
- magic_eval (env, &result, expr);
+ magic_eval(env, &result, expr);
- if (result.ty == TY_FAIL || result.ty == TY_UNDEF)
- return strdup ("?");
+ if (result.ty == TYPE::FAIL || result.ty == TYPE::UNDEF)
+ return strdup("?");
- stringify (&result, 0);
+ stringify(&result, 0);
return result.v.v_string;
}
-expr_t *magic_new_expr (int ty)
+expr_t *magic_new_expr(EXPR ty)
{
- expr_t *expr = (expr_t *) malloc (sizeof (expr_t));
+ expr_t *expr = (expr_t *) malloc(sizeof(expr_t));
expr->ty = ty;
return expr;
}
diff --git a/src/map/magic-expr.hpp b/src/map/magic-expr.hpp
index 7a251df..419c833 100644
--- a/src/map/magic-expr.hpp
+++ b/src/map/magic-expr.hpp
@@ -1,18 +1,7 @@
#ifndef MAGIC_EXPR_HPP
#define MAGIC_EXPR_HPP
-#include "magic-interpreter.hpp"
-#include "magic-interpreter-aux.hpp"
-
-#ifndef MAX
-# define MAX(x,y) (((x)>(y)) ? (x) : (y))
-#endif
-#ifndef MIN
-# define MIN(x,y) (((x)<(y)) ? (x) : (y))
-#endif
-#ifndef INT_MAX
-# define INT_MAX (1<<30) // It's more than that, but this is quite sufficient for our purposes.
-#endif
+#include "magic-interpreter.hpp"
/*
* Argument types:
@@ -32,14 +21,14 @@ typedef struct fun
const char *name;
const char *signature;
char ret_ty;
- int (*fun) (env_t * env, int args_nr, val_t * result, val_t * args);
+ int(*fun)(env_t *env, int args_nr, val_t *result, val_t *args);
} fun_t;
typedef struct op
{
const char *name;
const char *signature;
- int (*op) (env_t * env, int args_nr, val_t * args);
+ int(*op)(env_t *env, int args_nr, val_t *args);
} op_t;
/**
@@ -47,49 +36,49 @@ typedef struct op
* @param name The name to look up
* @return A function of that name, or NULL, and a function index
*/
-fun_t *magic_get_fun (const char *name, int *index);
+fun_t *magic_get_fun(const char *name, int *index);
/**
* Retrieves an operation by name
* @param name The name to look up
* @return An operation of that name, or NULL, and a function index
*/
-op_t *magic_get_op (char *name, int *index);
+op_t *magic_get_op(char *name, int *index);
/**
* Evaluates an expression and stores the result in `dest'
*/
-void magic_eval (env_t * env, val_t * dest, expr_t * expr);
+void magic_eval(env_t *env, val_t *dest, expr_t *expr);
/**
* Evaluates an expression and coerces the result into an integer
*/
-int magic_eval_int (env_t * env, expr_t * expr);
+int magic_eval_int(env_t *env, expr_t *expr);
/**
* Evaluates an expression and coerces the result into a string
*/
-char *magic_eval_str (env_t * env, expr_t * expr);
-
-int map_is_solid (int m, int x, int y);
-
-expr_t *magic_new_expr (int ty);
-
-void magic_clear_var (val_t * v);
-
-void magic_copy_var (val_t * dest, val_t * src);
-
-void magic_random_location (location_t * dest, area_t * area);
+char *magic_eval_str(env_t *env, expr_t *expr);
-int // ret -1: not a string, ret 1: no such item, ret 0: OK
+expr_t *magic_new_expr(EXPR ty);
+void magic_clear_var(val_t *v);
+void magic_copy_var(val_t *dest, val_t *src);
+void magic_random_location(location_t *dest, area_t *area);
- magic_find_item (val_t * args, int index, struct item *item, int *stackable);
+// ret -1: not a string, ret 1: no such item, ret 0: OK
+int magic_find_item(val_t *args, int index, struct item *item, int *stackable);
-#define GET_ARG_ITEM(index, dest, stackable) switch(magic_find_item(args, index, &dest, &stackable)) { case -1 : return 1; case 1 : return 0; }
+#define GET_ARG_ITEM(index, dest, stackable) \
+ switch (magic_find_item(args, index, &dest, &stackable)) \
+ { \
+ case -1: return 1; \
+ case 1: return 0; \
+ default: break; \
+ }
-int magic_location_in_area (int m, int x, int y, area_t * area);
+int magic_location_in_area(int m, int x, int y, area_t *area);
-#endif /* !defined(MAGIC_EXPR_H_) */
+#endif // MAGIC_EXPR_HPP
diff --git a/src/map/magic-interpreter-aux.hpp b/src/map/magic-interpreter-aux.hpp
index ea05b88..4bb0a82 100644
--- a/src/map/magic-interpreter-aux.hpp
+++ b/src/map/magic-interpreter-aux.hpp
@@ -1,8 +1,18 @@
#ifndef MAGIC_INTERPRETER_AUX_HPP
#define MAGIC_INTERPRETER_AUX_HPP
-#define CHECK_TYPE(v, t) ((v)->ty == t)
+#include "magic-interpreter.t.hpp"
-#define VAR(i) ((!env->vars || env->vars[i].ty == TY_UNDEF)? env->base_env->vars[i] : env->vars[i])
+template<class T>
+bool CHECK_TYPE(T *v, TYPE t)
+{
+ return v->ty == t;
+}
-#endif /* !defined(MAGIC_INTERPRETER_AUX_H_) */
+// FIXME: macro capture!
+#define VAR(i) \
+ ((!env->vars || env->vars[i].ty == TYPE::UNDEF) \
+ ? env->base_env->vars[i] \
+ : env->vars[i])
+
+#endif // MAGIC_INTERPRETER_AUX_HPP
diff --git a/src/map/magic-interpreter-base.cpp b/src/map/magic-interpreter-base.cpp
index 0305192..26d75af 100644
--- a/src/map/magic-interpreter-base.cpp
+++ b/src/map/magic-interpreter-base.cpp
@@ -1,34 +1,49 @@
-#include "magic.hpp"
+#include "magic-interpreter-aux.hpp"
#include "magic-interpreter.hpp"
+
+#include "../common/cxxstdio.hpp"
+#include "../common/timer.hpp"
+
#include "magic-expr.hpp"
-#include "magic-interpreter-aux.hpp"
-static void set_int_p (val_t * v, int i, int t)
+#include "pc.hpp"
+
+#include "../poison.hpp"
+
+static
+void set_int_p(val_t *v, int i, TYPE t)
{
v->ty = t;
v->v.v_int = i;
}
-#define set_int(v, i) set_int_p(v, i, TY_INT)
-#define set_dir(v, i) set_int_p(v, i, TY_DIR)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-macros"
+
+#define set_int(v, i) set_int_p(v, i, TYPE::INT)
+#define set_dir(v, i) set_int_p(v, i, TYPE::DIR)
#define SETTER(tty, dyn_ty, field) (val_t *v, tty x) { v->ty = dyn_ty; v->v.field = x; }
-static void set_string SETTER (char *, TY_STRING, v_string);
+static
+void set_string SETTER(char *, TYPE::STRING, v_string)
-static void set_entity (val_t * v, entity_t * e)
+static
+void set_entity(val_t *v, entity_t *e)
{
- v->ty = TY_ENTITY;
+ v->ty = TYPE::ENTITY;
v->v.v_int = e->id;
}
-static void set_invocation (val_t * v, invocation_t * i)
+static
+void set_invocation(val_t *v, invocation_t *i)
{
- v->ty = TY_INVOCATION;
+ v->ty = TYPE::INVOCATION;
v->v.v_int = i->bl.id;
}
-static void set_spell SETTER (spell_t *, TY_SPELL, v_spell);
+static
+void set_spell SETTER(spell_t *, TYPE::SPELL, v_spell)
#define setenv(f, v, x) f(&(env->vars[v]), x)
@@ -41,29 +56,33 @@ static void set_spell SETTER (spell_t *, TY_SPELL, v_spell);
#define set_env_invocation(v, x) setenv(set_invocation, v, x)
#define set_env_spell(v, x) setenv(set_spell, v, x)
+#pragma GCC diagnostic pop
+
magic_conf_t magic_conf; /* Global magic conf */
env_t magic_default_env = { &magic_conf, NULL };
-static int spells_sorted = 0;
+static
+int spells_sorted = 0;
const char *magic_find_invocation(const char *spellname)
{
- int i;
+ int i;
- for (i = 0; i < abs (magic_conf.spells_nr); i++)
- if (!strcmp (magic_conf.spells[i]->name, spellname))
+ for (i = 0; i < abs(magic_conf.spells_nr); i++)
+ if (!strcmp(magic_conf.spells[i]->name, spellname))
return magic_conf.spells[i]->invocation;
return NULL;
}
-static int spell_compare (const void *lhs, const void *rhs)
+static
+int spell_compare(const void *lhs, const void *rhs)
{
- return strcmp ((*((spell_t **) lhs))->invocation,
- (*((spell_t **) rhs))->invocation);
+ return strcmp((*((const spell_t *const*) lhs))->invocation,
+ (*((const spell_t *const*) rhs))->invocation);
}
-spell_t *magic_find_spell (char *invocation)
+spell_t *magic_find_spell(char *invocation)
{
spell_t key;
spell_t *keyp = &key;
@@ -71,7 +90,7 @@ spell_t *magic_find_spell (char *invocation)
if (!spells_sorted)
{
- qsort (magic_conf.spells, magic_conf.spells_nr, sizeof (spell_t *),
+ qsort(magic_conf.spells, magic_conf.spells_nr, sizeof(spell_t *),
spell_compare);
spells_sorted = 1;
}
@@ -80,8 +99,8 @@ spell_t *magic_find_spell (char *invocation)
retval =
((spell_t **)
- bsearch (&keyp, magic_conf.spells, magic_conf.spells_nr,
- sizeof (spell_t *), spell_compare));
+ bsearch(&keyp, magic_conf.spells, magic_conf.spells_nr,
+ sizeof(spell_t *), spell_compare));
if (!retval)
return NULL;
@@ -93,24 +112,25 @@ spell_t *magic_find_spell (char *invocation)
/* Spell anchors */
/* -------------------------------------------------------------------------------- */
-static int compare_teleport_anchor (const void *lhs, const void *rhs)
+static
+int compare_teleport_anchor(const void *lhs, const void *rhs)
{
- return strcmp ((*((teleport_anchor_t **) lhs))->invocation,
- (*((teleport_anchor_t **) rhs))->invocation);
+ return strcmp((*((const teleport_anchor_t *const*) lhs))->invocation,
+ (*((const teleport_anchor_t *const*) rhs))->invocation);
}
const char *magic_find_anchor_invocation(const char *anchor_name)
{
- int i;
+ int i;
- for (i = 0; i < abs (magic_conf.anchors_nr); i++)
- if (!strcmp (magic_conf.anchors[i]->name, anchor_name))
+ for (i = 0; i < abs(magic_conf.anchors_nr); i++)
+ if (!strcmp(magic_conf.anchors[i]->name, anchor_name))
return magic_conf.anchors[i]->invocation;
return NULL;
}
-teleport_anchor_t *magic_find_anchor (char *name)
+teleport_anchor_t *magic_find_anchor(char *name)
{
teleport_anchor_t key;
teleport_anchor_t *keyp = &key;
@@ -118,17 +138,17 @@ teleport_anchor_t *magic_find_anchor (char *name)
if (magic_conf.anchors_nr > 0)
{ /* unsorted */
- qsort (magic_conf.anchors, magic_conf.anchors_nr,
- sizeof (teleport_anchor_t *), compare_teleport_anchor);
+ qsort(magic_conf.anchors, magic_conf.anchors_nr,
+ sizeof(teleport_anchor_t *), compare_teleport_anchor);
magic_conf.anchors_nr = -magic_conf.anchors_nr;
}
key.invocation = name;
- retval = (teleport_anchor_t **) bsearch (&keyp,
+ retval = (teleport_anchor_t **) bsearch(&keyp,
magic_conf.anchors,
-magic_conf.anchors_nr,
- sizeof (teleport_anchor_t *),
+ sizeof(teleport_anchor_t *),
compare_teleport_anchor);
if (!retval)
@@ -141,83 +161,86 @@ teleport_anchor_t *magic_find_anchor (char *name)
/* Spell guard checks */
/* -------------------------------------------------------------------------------- */
-static env_t *alloc_env (magic_conf_t * conf)
+static
+env_t *alloc_env(magic_conf_t *conf)
{
env_t *env;
- CREATE (env, env_t, 1);
- CREATE (env->vars, val_t, conf->vars_nr);
+ CREATE(env, env_t, 1);
+ CREATE(env->vars, val_t, conf->vars_nr);
env->base_env = conf;
return env;
}
-static env_t *clone_env (env_t * src)
+static
+env_t *clone_env(env_t *src)
{
- env_t *retval = alloc_env (src->base_env);
- int i;
+ env_t *retval = alloc_env(src->base_env);
+ int i;
for (i = 0; i < src->base_env->vars_nr; i++)
- magic_copy_var (&retval->vars[i], &src->vars[i]);
+ magic_copy_var(&retval->vars[i], &src->vars[i]);
return retval;
}
-void magic_free_env (env_t * env)
+void magic_free_env(env_t *env)
{
- int i;
+ int i;
for (i = 0; i < env->base_env->vars_nr; i++)
- magic_clear_var (&env->vars[i]);
- free (env);
+ magic_clear_var(&env->vars[i]);
+ free(env);
}
-env_t *spell_create_env (magic_conf_t * conf, spell_t * spell,
- character_t * caster, int spellpower, char *param)
+env_t *spell_create_env(magic_conf_t *conf, spell_t *spell,
+ character_t *caster, int spellpower, char *param)
{
- env_t *env = alloc_env (conf);
+ env_t *env = alloc_env(conf);
switch (spell->spellarg_ty)
{
- case SPELLARG_STRING:
- set_env_string (spell->arg, param);
+ case SPELLARG::STRING:
+ set_env_string(spell->arg, param);
break;
- case SPELLARG_PC:
+ case SPELLARG::PC:
{
- character_t *subject = map_nick2sd (param);
+ character_t *subject = map_nick2sd(param);
if (!subject)
subject = caster;
- set_env_entity (spell->arg, &subject->bl);
- free (param);
+ set_env_entity(spell->arg, &subject->bl);
+ free(param);
break;
}
- case SPELLARG_NONE:
- free (param);
+ case SPELLARG::NONE:
+ free(param);
break;
default:
- free (param);
- fprintf (stderr, "Unexpected spellarg type %d\n",
+ free(param);
+ FPRINTF(stderr, "Unexpected spellarg type %d\n",
spell->spellarg_ty);
}
- set_env_entity (VAR_CASTER, &caster->bl);
- set_env_int (VAR_SPELLPOWER, spellpower);
- set_env_spell (VAR_SPELL, spell);
+ set_env_entity(VAR_CASTER, &caster->bl);
+ set_env_int(VAR_SPELLPOWER, spellpower);
+ set_env_spell(VAR_SPELL, spell);
return env;
}
-static void free_components (component_t ** component_holder)
+static
+void free_components(component_t ** component_holder)
{
if (*component_holder == NULL)
return;
- free_components (&(*component_holder)->next);
- free (*component_holder);
+ free_components(&(*component_holder)->next);
+ free(*component_holder);
*component_holder = NULL;
}
-void magic_add_component (component_t ** component_holder, int id, int count)
+void magic_add_component(component_t ** component_holder, int id, int count)
{
if (count <= 0)
return;
@@ -225,7 +248,7 @@ void magic_add_component (component_t ** component_holder, int id, int count)
if (*component_holder == NULL)
{
component_t *component =
- (component_t *) malloc (sizeof (component_t));
+ (component_t *) malloc(sizeof(component_t));
component->next = NULL;
component->item_id = id;
component->count = count;
@@ -240,33 +263,35 @@ void magic_add_component (component_t ** component_holder, int id, int count)
return;
}
else
- magic_add_component (&component->next, id, count);
+ magic_add_component(&component->next, id, count);
/* Tail-recurse; gcc can optimise this. Not that it matters. */
}
}
-static void
-copy_components (component_t ** component_holder, component_t * component)
+static
+void copy_components(component_t ** component_holder, component_t *component)
{
if (component == NULL)
return;
- magic_add_component (component_holder, component->item_id,
+ magic_add_component(component_holder, component->item_id,
component->count);
- copy_components (component_holder, component->next);
+ copy_components(component_holder, component->next);
}
typedef struct spellguard_check
{
component_t *catalysts, *components;
- int mana, casttime;
+ int mana;
+ interval_t casttime;
} spellguard_check_t;
-static int check_prerequisites (character_t * caster, component_t * component)
+static
+int check_prerequisites(character_t *caster, component_t *component)
{
while (component)
{
- if (pc_count_all_items (caster, component->item_id)
+ if (pc_count_all_items(caster, component->item_id)
< component->count)
return 0; /* insufficient */
@@ -276,59 +301,51 @@ static int check_prerequisites (character_t * caster, component_t * component)
return 1;
}
-static void consume_components (character_t * caster, component_t * component)
+static
+void consume_components(character_t *caster, component_t *component)
{
while (component)
{
- pc_remove_items (caster, component->item_id, component->count);
+ pc_remove_items(caster, component->item_id, component->count);
component = component->next;
}
}
-static int
-spellguard_can_satisfy (spellguard_check_t * check, character_t * caster,
- env_t * env, int *near_miss)
+static
+int spellguard_can_satisfy(spellguard_check_t *check, character_t *caster,
+ env_t *env, int *near_miss)
{
- unsigned int tick = gettick ();
-
- int retval = check_prerequisites (caster, check->catalysts);
+ tick_t tick = gettick();
-/*
- fprintf(stderr, "MC(%d/%s)? %d%d%d%d (%u <= %u)\n",
- caster->bl.id, caster->status.name,
- retval,
- caster->cast_tick <= tick,
- check->mana <= caster->status.sp,
- check_prerequisites(caster, check->components),
- caster->cast_tick, tick);
-*/
+ int retval = check_prerequisites(caster, check->catalysts);
if (retval && near_miss)
*near_miss = 1; // close enough!
retval = retval && caster->cast_tick <= tick /* Hasn't cast a spell too recently */
&& check->mana <= caster->status.sp
- && check_prerequisites (caster, check->components);
+ && check_prerequisites(caster, check->components);
if (retval)
{
- unsigned int casttime = (unsigned int) check->casttime;
+ interval_t casttime = check->casttime;
- if (VAR (VAR_MIN_CASTTIME).ty == TY_INT)
- casttime = MAX (casttime, VAR (VAR_MIN_CASTTIME).v.v_int);
+ if (VAR(VAR_MIN_CASTTIME).ty == TYPE::INT)
+ casttime = max(casttime, static_cast<interval_t>(VAR(VAR_MIN_CASTTIME).v.v_int));
caster->cast_tick = tick + casttime; /* Make sure not to cast too frequently */
- consume_components (caster, check->components);
- pc_heal (caster, 0, -check->mana);
+ consume_components(caster, check->components);
+ pc_heal(caster, 0, -check->mana);
}
return retval;
}
-static effect_set_t *spellguard_check_sub (spellguard_check_t * check,
- spellguard_t * guard,
- character_t * caster, env_t * env,
+static
+effect_set_t *spellguard_check_sub(spellguard_check_t *check,
+ spellguard_t *guard,
+ character_t *caster, env_t *env,
int *near_miss)
{
if (guard == NULL)
@@ -336,20 +353,20 @@ static effect_set_t *spellguard_check_sub (spellguard_check_t * check,
switch (guard->ty)
{
- case SPELLGUARD_CONDITION:
- if (!magic_eval_int (env, guard->s.s_condition))
+ case SPELLGUARD::CONDITION:
+ if (!magic_eval_int(env, guard->s.s_condition))
return NULL;
break;
- case SPELLGUARD_COMPONENTS:
- copy_components (&check->components, guard->s.s_components);
+ case SPELLGUARD::COMPONENTS:
+ copy_components(&check->components, guard->s.s_components);
break;
- case SPELLGUARD_CATALYSTS:
- copy_components (&check->catalysts, guard->s.s_catalysts);
+ case SPELLGUARD::CATALYSTS:
+ copy_components(&check->catalysts, guard->s.s_catalysts);
break;
- case SPELLGUARD_CHOICE:
+ case SPELLGUARD::CHOICE:
{
spellguard_check_t altcheck = *check;
effect_set_t *retval;
@@ -357,57 +374,60 @@ static effect_set_t *spellguard_check_sub (spellguard_check_t * check,
altcheck.components = NULL;
altcheck.catalysts = NULL;
- copy_components (&altcheck.catalysts, check->catalysts);
- copy_components (&altcheck.components, check->components);
+ copy_components(&altcheck.catalysts, check->catalysts);
+ copy_components(&altcheck.components, check->components);
retval =
- spellguard_check_sub (&altcheck, guard->next, caster, env,
+ spellguard_check_sub(&altcheck, guard->next, caster, env,
near_miss);
- free_components (&altcheck.catalysts);
- free_components (&altcheck.components);
+ free_components(&altcheck.catalysts);
+ free_components(&altcheck.components);
if (retval)
return retval;
else
- return spellguard_check_sub (check, guard->s.s_alt, caster,
+ return spellguard_check_sub(check, guard->s.s_alt, caster,
env, near_miss);
}
- case SPELLGUARD_MANA:
- check->mana += magic_eval_int (env, guard->s.s_mana);
+ case SPELLGUARD::MANA:
+ check->mana += magic_eval_int(env, guard->s.s_mana);
break;
- case SPELLGUARD_CASTTIME:
- check->casttime += magic_eval_int (env, guard->s.s_mana);
+ case SPELLGUARD::CASTTIME:
+ check->casttime += static_cast<interval_t>(magic_eval_int(env, guard->s.s_mana));
break;
- case SPELLGUARD_EFFECT:
- if (spellguard_can_satisfy (check, caster, env, near_miss))
+ case SPELLGUARD::EFFECT:
+ if (spellguard_can_satisfy(check, caster, env, near_miss))
return &guard->s.s_effect;
else
return NULL;
default:
- fprintf (stderr, "Unexpected spellguard type %d\n", guard->ty);
+ FPRINTF(stderr, "Unexpected spellguard type %d\n",
+ guard->ty);
return NULL;
}
- return spellguard_check_sub (check, guard->next, caster, env, near_miss);
+ return spellguard_check_sub(check, guard->next, caster, env, near_miss);
}
-static effect_set_t *check_spellguard (spellguard_t * guard,
- character_t * caster, env_t * env,
+static
+effect_set_t *check_spellguard(spellguard_t *guard,
+ character_t *caster, env_t *env,
int *near_miss)
{
spellguard_check_t check;
effect_set_t *retval;
check.catalysts = NULL;
check.components = NULL;
- check.mana = check.casttime = 0;
+ check.mana = 0;
+ check.casttime = interval_t::zero();
- retval = spellguard_check_sub (&check, guard, caster, env, near_miss);
+ retval = spellguard_check_sub(&check, guard, caster, env, near_miss);
- free_components (&check.catalysts);
- free_components (&check.components);
+ free_components(&check.catalysts);
+ free_components(&check.components);
return retval;
}
@@ -416,114 +436,115 @@ static effect_set_t *check_spellguard (spellguard_t * guard,
/* Public API */
/* -------------------------------------------------------------------------------- */
-effect_set_t *spell_trigger (spell_t * spell, character_t * caster,
- env_t * env, int *near_miss)
+effect_set_t *spell_trigger(spell_t *spell, character_t *caster,
+ env_t *env, int *near_miss)
{
- int i;
+ int i;
spellguard_t *guard = spell->spellguard;
if (near_miss)
*near_miss = 0;
for (i = 0; i < spell->letdefs_nr; i++)
- magic_eval (env,
+ magic_eval(env,
&env->vars[spell->letdefs[i].id], spell->letdefs[i].expr);
- return check_spellguard (guard, caster, env, near_miss);
+ return check_spellguard(guard, caster, env, near_miss);
}
-static void spell_set_location (invocation_t * invocation, entity_t * entity)
+static
+void spell_set_location(invocation_t *invocation, entity_t *entity)
{
- magic_clear_var (&invocation->env->vars[VAR_LOCATION]);
- invocation->env->vars[VAR_LOCATION].ty = TY_LOCATION;
+ magic_clear_var(&invocation->env->vars[VAR_LOCATION]);
+ invocation->env->vars[VAR_LOCATION].ty = TYPE::LOCATION;
invocation->env->vars[VAR_LOCATION].v.v_location.m = entity->m;
invocation->env->vars[VAR_LOCATION].v.v_location.x = entity->x;
invocation->env->vars[VAR_LOCATION].v.v_location.y = entity->y;
}
-void spell_update_location (invocation_t * invocation)
+void spell_update_location(invocation_t *invocation)
{
- if (invocation->spell->flags & SPELL_FLAG_LOCAL)
+ if (bool(invocation->spell->flags & SPELL_FLAG::LOCAL))
return;
else
{
- character_t *owner = (character_t *) map_id2bl (invocation->subject);
+ character_t *owner = (character_t *) map_id2bl(invocation->subject);
if (!owner)
return;
- spell_set_location (invocation, (entity_t *) owner);
+ spell_set_location(invocation, (entity_t *) owner);
}
}
-invocation_t *spell_instantiate (effect_set_t * effect_set, env_t * env)
+invocation_t *spell_instantiate(effect_set_t *effect_set, env_t *env)
{
invocation_t *retval;
- CREATE (retval, invocation_t, 1);
+ CREATE(retval, invocation_t, 1);
entity_t *caster;
retval->env = env;
- retval->caster = VAR (VAR_CASTER).v.v_int;
- retval->spell = VAR (VAR_SPELL).v.v_spell;
+ retval->caster = VAR(VAR_CASTER).v.v_int;
+ retval->spell = VAR(VAR_SPELL).v.v_spell;
retval->stack_size = 0;
retval->current_effect = effect_set->effect;
retval->trigger_effect = effect_set->at_trigger;
retval->end_effect = effect_set->at_end;
- caster = map_id2bl (retval->caster); // must still exist
- retval->bl.id = map_addobject (&retval->bl);
- retval->bl.type = BL_SPELL;
+ caster = map_id2bl(retval->caster); // must still exist
+ retval->bl.id = map_addobject(&retval->bl);
+ retval->bl.type = BL::SPELL;
retval->bl.m = caster->m;
retval->bl.x = caster->x;
retval->bl.y = caster->y;
- map_addblock (&retval->bl);
- set_env_invocation (VAR_INVOCATION, retval);
+ map_addblock(&retval->bl);
+ set_env_invocation(VAR_INVOCATION, retval);
return retval;
}
-invocation_t *spell_clone_effect (invocation_t * base)
+invocation_t *spell_clone_effect(invocation_t *base)
{
- invocation_t *retval = (invocation_t *) malloc (sizeof (invocation_t));
+ invocation_t *retval = (invocation_t *) calloc(1, sizeof(invocation_t));
env_t *env;
- memcpy (retval, base, sizeof (invocation_t));
+ memcpy(retval, base, sizeof(invocation_t));
- retval->env = clone_env (retval->env);
+ retval->env = clone_env(retval->env);
env = retval->env;
retval->current_effect = retval->trigger_effect;
retval->next_invocation = NULL;
retval->end_effect = NULL;
retval->script_pos = 0;
retval->stack_size = 0;
- retval->timer = 0;
+ // retval->timer = 0;
retval->subject = 0;
retval->status_change_refs_nr = 0;
retval->status_change_refs = NULL;
- retval->flags = 0;
+ retval->flags = INVOCATION_FLAG::ZERO;
retval->bl.id = 0;
retval->bl.prev = NULL;
retval->bl.next = NULL;
- retval->bl.id = map_addobject (&retval->bl);
- set_env_invocation (VAR_INVOCATION, retval);
+ retval->bl.id = map_addobject(&retval->bl);
+ set_env_invocation(VAR_INVOCATION, retval);
return retval;
}
-void spell_bind (character_t * subject, invocation_t * invocation)
+void spell_bind(character_t *subject, invocation_t *invocation)
{
/* Only bind nonlocal spells */
- if (!(invocation->spell->flags & SPELL_FLAG_LOCAL))
+ if (!bool(invocation->spell->flags & SPELL_FLAG::LOCAL))
{
- if (invocation->flags & INVOCATION_FLAG_BOUND
+ if (bool(invocation->flags & INVOCATION_FLAG::BOUND)
|| invocation->subject || invocation->next_invocation)
{
int *i = NULL;
- fprintf (stderr,
+ FPRINTF(stderr,
"[magic] INTERNAL ERROR: Attempt to re-bind spell invocation `%s'\n",
invocation->spell->name);
*i = 1;
@@ -532,14 +553,14 @@ void spell_bind (character_t * subject, invocation_t * invocation)
invocation->next_invocation = subject->active_spells;
subject->active_spells = invocation;
- invocation->flags |= INVOCATION_FLAG_BOUND;
+ invocation->flags |= INVOCATION_FLAG::BOUND;
invocation->subject = subject->bl.id;
}
- spell_set_location (invocation, (entity_t *) subject);
+ spell_set_location(invocation, (entity_t *) subject);
}
-int spell_unbind (character_t * subject, invocation_t * invocation)
+int spell_unbind(character_t *subject, invocation_t *invocation)
{
invocation_t **seeker = &subject->active_spells;
@@ -549,7 +570,7 @@ int spell_unbind (character_t * subject, invocation_t * invocation)
{
*seeker = invocation->next_invocation;
- invocation->flags &= ~INVOCATION_FLAG_BOUND;
+ invocation->flags &= ~INVOCATION_FLAG::BOUND;
invocation->next_invocation = NULL;
invocation->subject = 0;
diff --git a/src/map/magic-interpreter-lexer.lpp b/src/map/magic-interpreter-lexer.lpp
index c7f9c09..96598a3 100644
--- a/src/map/magic-interpreter-lexer.lpp
+++ b/src/map/magic-interpreter-lexer.lpp
@@ -1,15 +1,18 @@
%{
-#include "magic-interpreter.hpp"
#include "magic-interpreter-parser.hpp"
+#include "../common/cxxstdio.hpp"
+
#ifdef HEADING
-# undef HEADING
+# error "what platform is this? please tell me who #defined HEADING"
#endif
#define FIXLOC magic_frontend_lloc.first_line = magic_frontend_lineno
#define HEADING(dir) { magic_frontend_lval.i = dir; FIXLOC; return DIR; }
+// silence compiler warnings
+#define YY_USER_INIT (void)yylval, (void)yylloc
%}
%option yylineno
@@ -21,86 +24,86 @@
%%
-"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;}
+"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;
+ FIXLOC;
return SCRIPT_DATA;
}
@@ -115,26 +118,26 @@
*dst++ = *src++;
*dst = '\0'; /* terminate */
magic_frontend_lval.s = string;
- FIXLOC;
+ FIXLOC;
return STRING;
}
-"-"?[0-9]+ { magic_frontend_lval.i = atoi(yytext);
- FIXLOC;
+"-"?[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;
+ FIXLOC;
return INT; }
[a-zA-Z][-_a-zA-Z0-9?!]* { magic_frontend_lval.s = strdup(yytext);
- FIXLOC;
+ 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);
+"#".*$ /* 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.ypp b/src/map/magic-interpreter-parser.ypp
index 5fe2646..dd62edf 100644
--- a/src/map/magic-interpreter-parser.ypp
+++ b/src/map/magic-interpreter-parser.ypp
@@ -1,71 +1,84 @@
%code requires {
-#include "magic-expr.hpp"
+#include "magic-interpreter.hpp"
}
%code{
#include "magic-interpreter-parser.hpp"
-#include "magic-interpreter.hpp"
-#include <stdarg.h>
+#include <cstdarg> // exception to "no va_list" rule, even after cxxstdio
+
+#include "../common/cxxstdio.hpp"
+
+#include "itemdb.hpp"
+#include "magic-expr.hpp"
#define YYLEX_PARAM 0, 0
-static int
-intern_id(const char *id_name);
+static
+int intern_id(const char *id_name);
-static expr_t *
-fun_expr(const char *name, int args_nr, expr_t **args, int line, int column);
+static
+expr_t *fun_expr(const char *name, int args_nr, expr_t **args, int line, int column);
-static expr_t *
-dot_expr(expr_t *lhs, int id);
+static
+expr_t *dot_expr(expr_t *lhs, int id);
-#define BIN_EXPR(x, name, arg1, arg2, line, column) { expr_t *e[2]; e[0] = arg1; e[1] = arg2; x = fun_expr(name, 2, e, line, column); }
+static
+void BIN_EXPR(expr_t *& x, const char *name, expr_t *arg1, expr_t *arg2, int line, int column)
+{
+ expr_t *e[2];
+ e[0] = arg1;
+ e[1] = arg2;
+ x = fun_expr(name, 2, e, line, column);
+}
-static int failed_flag = 0;
+static
+int failed_flag = 0;
-static void
-magic_frontend_error(const char *msg);
+static
+void magic_frontend_error(const char *msg);
-static void
-fail(int line, int column, const char *fmt, ...);
+static
+void fail(int line, int column, const char *fmt, ...);
-static spell_t *
-new_spell(spellguard_t *guard);
+static
+spell_t *new_spell(spellguard_t *guard);
-static spellguard_t *
-spellguard_implication(spellguard_t *a, spellguard_t *b);
+static
+spellguard_t *spellguard_implication(spellguard_t *a, spellguard_t *b);
-static spellguard_t *
-new_spellguard(int ty);
+static
+spellguard_t *new_spellguard(SPELLGUARD ty);
-static effect_t *
-new_effect(int ty);
+static
+effect_t *new_effect(EFFECT ty);
-static effect_t *
-set_effect_continuation(effect_t *src, effect_t *continuation);
+static
+effect_t *set_effect_continuation(effect_t *src, effect_t *continuation);
-static void
-add_spell(spell_t *spell, int line_nr);
+static
+void add_spell(spell_t *spell, int line_nr);
-static void
-add_teleport_anchor(teleport_anchor_t *anchor, int line_nr);
+static
+void add_teleport_anchor(teleport_anchor_t *anchor, int line_nr);
-static effect_t *
-op_effect(char *name, int args_nr, expr_t **args, int line, int column);
+static
+effect_t *op_effect(char *name, int args_nr, expr_t **args, int line, int column);
+// in magic-interpreter-lexer.cpp
int magic_frontend_lex(YYSTYPE *, YYLTYPE *);
-static void
-install_proc(proc_t *proc);
+static
+void install_proc(proc_t *proc);
-static effect_t *
-call_proc(char *name, int args_nr, expr_t **args, int line_nr, int column);
+static
+effect_t *call_proc(char *name, int args_nr, expr_t **args, int line_nr, int column);
-static void
-bind_constant(char *name, val_t *val, int line_nr);
+static
+void bind_constant(char *name, val_t *val, int line_nr);
-static val_t *
-find_constant(char *name);
+static
+val_t *find_constant(char *name);
}
@@ -75,6 +88,9 @@ find_constant(char *name);
%union {
int i;
+ SPELL_FLAG spell_flags;
+ SPELLARG spell_arg;
+ FOREACH_FILTER foreach_filter;
char *s;
int op;
magic_conf_t *magic_conf;
@@ -85,7 +101,7 @@ find_constant(char *name);
args_rec_t arg_list;
struct { int letdefs_nr; letdef_t *letdefs; } letdefs;
spell_t *spell;
- struct { int id, ty; } spellarg_def;
+ struct { int id; SPELLARG ty; } spellarg_def;
letdef_t vardef;
spellguard_t *spellguard;
component_t *components;
@@ -152,7 +168,7 @@ find_constant(char *name);
%token SKIP
%token ABORT
%token BREAK
-%token EFFECT
+%token EFFECT_
%token ATEND
%token ATTRIGGER
%token PC_F
@@ -186,15 +202,15 @@ find_constant(char *name);
%type <components> items
%type <components> item_list
%type <i> item_name
-%type <i> selection;
+%type <foreach_filter> selection;
%type <effect> effect
%type <effect> effect_list
%type <effect> maybe_trigger
%type <effect> maybe_end
-%type <i> spell_flags;
+%type <spell_flags> spell_flags;
%type <expr> expr
-%type <i> arg_ty
+%type <spell_arg> arg_ty
%type <proc> proc_formals_list
%type <proc> proc_formals_list_ne
@@ -211,41 +227,41 @@ find_constant(char *name);
%%
-spellconf : /* empty */
+spellconf : /* empty */
{}
| spellconf_option semicolons spellconf
{}
- ;
+ ;
-semicolons : /* empty */
- {}
+semicolons : /* empty */
+ {}
| semicolons ';'
{}
- ;
+ ;
-proc_formals_list : /* empty */
- { CREATE ($$, proc_t, 1); }
- | proc_formals_list_ne
+proc_formals_list : /* empty */
+ { CREATE($$, proc_t, 1); }
+ | proc_formals_list_ne
{ $$ = $1; }
- ;
+ ;
-proc_formals_list_ne : ID
- { CREATE ($$, proc_t, 1);
+proc_formals_list_ne : ID
+ { CREATE($$, proc_t, 1);
$$->args_nr = 1;
$$->args = (int*)malloc(sizeof(int));
$$->args[0] = intern_id($1);
}
- | proc_formals_list_ne ',' ID
+ | proc_formals_list_ne ',' ID
{ $$ = $1;
$$->args = (int*)realloc($$->args, sizeof(int) * (1 + $$->args_nr));
$$->args[$$->args_nr++] = intern_id($3);
}
- ;
+ ;
-spellconf_option : ID '=' expr
- {
+spellconf_option : ID '=' expr
+ {
int var_id;
if (find_constant($1)) {
fail(@1.first_line, 0, "Attempt to redefine constant `%s' as global\n", $1);
@@ -255,8 +271,8 @@ spellconf_option : ID '=' expr
magic_eval(&magic_default_env, &magic_conf.vars[var_id], $3);
}
}
- | CONST ID '=' expr
- {
+ | CONST ID '=' expr
+ {
val_t var;
magic_eval(&magic_default_env, &var, $4);
bind_constant($2, &var, @1.first_line);
@@ -264,7 +280,7 @@ spellconf_option : ID '=' expr
| TELEPORT_ANCHOR ID ':' expr '=' expr
{
teleport_anchor_t *anchor;
- CREATE (anchor, teleport_anchor_t, 1);
+ CREATE(anchor, teleport_anchor_t, 1);
anchor->name = $2;
anchor->invocation = magic_eval_str(&magic_default_env, $4);
anchor->location = $6;
@@ -275,7 +291,7 @@ spellconf_option : ID '=' expr
free(anchor);
failed_flag = 0;
}
- | PROCEDURE ID '(' proc_formals_list ')' '=' effect_list
+ | PROCEDURE ID '(' proc_formals_list ')' '=' effect_list
{
proc_t *proc = $4;
proc->name = $2;
@@ -296,27 +312,27 @@ spellconf_option : ID '=' expr
failed_flag = 0;
}
-spell_flags : /* empty */
- { $$ = 0; }
- | LOCAL spell_flags
- { if ($2 & SPELL_FLAG_LOCAL)
+spell_flags : /* empty */
+ { $$ = SPELL_FLAG::ZERO; }
+ | LOCAL spell_flags
+ { if (bool($2 & SPELL_FLAG::LOCAL))
fail(@1.first_line, @1.first_column, "`LOCAL' specified more than once");
- $$ = $2 | SPELL_FLAG_LOCAL;
+ $$ = $2 | SPELL_FLAG::LOCAL;
}
- | NONMAGIC spell_flags
- { if ($2 & SPELL_FLAG_NONMAGIC)
+ | NONMAGIC spell_flags
+ { if (bool($2 & SPELL_FLAG::NONMAGIC))
fail(@1.first_line, @1.first_column, "`NONMAGIC' specified more than once");
- $$ = $2 | SPELL_FLAG_NONMAGIC;
+ $$ = $2 | SPELL_FLAG::NONMAGIC;
}
- | SILENT spell_flags
- { if ($2 & SPELL_FLAG_SILENT)
+ | SILENT spell_flags
+ { if (bool($2 & SPELL_FLAG::SILENT))
fail(@1.first_line, @1.first_column, "`SILENT' specified more than once");
- $$ = $2 | SPELL_FLAG_SILENT;
+ $$ = $2 | SPELL_FLAG::SILENT;
}
-argopt : /* empty */
- { $$.ty = SPELLARG_NONE; }
+argopt : /* empty */
+ { $$.ty = SPELLARG::NONE; }
| '(' ID ':' arg_ty ')'
{ $$.id = intern_id($2);
$$.ty = $4; }
@@ -324,160 +340,160 @@ argopt : /* empty */
arg_ty : PC_F
- { $$ = SPELLARG_PC; }
+ { $$ = SPELLARG::PC; }
| STRING_TY
- { $$ = SPELLARG_STRING; }
+ { $$ = SPELLARG::STRING; }
;
-value : DIR
- { $$.ty = TY_DIR;
+value : DIR
+ { $$.ty = TYPE::DIR;
$$.v.v_int = $1; }
- | INT
- { $$.ty = TY_INT;
+ | INT
+ { $$.ty = TYPE::INT;
$$.v.v_int = $1; }
- | STRING
- { $$.ty = TY_STRING;
+ | STRING
+ { $$.ty = TYPE::STRING;
$$.v.v_string = $1; }
- ;
+ ;
-expr : value
- { $$ = magic_new_expr(EXPR_VAL);
+expr : value
+ { $$ = magic_new_expr(EXPR::VAL);
$$->e.e_val = $1; }
- | ID
- {
+ | ID
+ {
val_t *val;
if ((val = find_constant($1))) {
- $$ = magic_new_expr(EXPR_VAL);
+ $$ = magic_new_expr(EXPR::VAL);
$$->e.e_val = *val;
} else {
- $$ = magic_new_expr(EXPR_ID);
+ $$ = magic_new_expr(EXPR::ID);
$$->e.e_id = intern_id($1);
}
}
- | area
- { $$ = magic_new_expr(EXPR_AREA);
+ | area
+ { $$ = magic_new_expr(EXPR::AREA);
$$->e.e_area = $1; }
- | expr '+' expr
- { BIN_EXPR($$, "+", $1, $3, @1.first_line, @1.first_column); }
- | expr '-' expr
- { BIN_EXPR($$, "-", $1, $3, @1.first_line, @1.first_column); }
- | expr '*' expr
- { BIN_EXPR($$, "*", $1, $3, @1.first_line, @1.first_column); }
- | expr '%' expr
- { BIN_EXPR($$, "%", $1, $3, @1.first_line, @1.first_column); }
- | expr '/' expr
- { BIN_EXPR($$, "/", $1, $3, @1.first_line, @1.first_column); }
- | expr '<' expr
- { BIN_EXPR($$, ">", $3, $1, @1.first_line, @1.first_column); }
- | expr '>' expr
- { BIN_EXPR($$, ">", $1, $3, @1.first_line, @1.first_column); }
- | expr '&' expr
- { BIN_EXPR($$, "&", $1, $3, @1.first_line, @1.first_column); }
- | expr '^' expr
- { BIN_EXPR($$, "^", $1, $3, @1.first_line, @1.first_column); }
- | expr '|' expr
- { BIN_EXPR($$, "|", $1, $3, @1.first_line, @1.first_column); }
- | expr SHL expr
- { BIN_EXPR($$, "<<", $1, $3, @1.first_line, @1.first_column); }
- | expr SHR expr
- { BIN_EXPR($$, ">>", $1, $3, @1.first_line, @1.first_column); }
- | expr LTE expr
- { BIN_EXPR($$, ">=", $3, $1, @1.first_line, @1.first_column); }
- | expr GTE expr
- { BIN_EXPR($$, ">=", $1, $3, @1.first_line, @1.first_column); }
- | expr ANDAND expr
- { BIN_EXPR($$, "&&", $1, $3, @1.first_line, @1.first_column); }
- | expr OROR expr
- { BIN_EXPR($$, "||", $1, $3, @1.first_line, @1.first_column); }
- | expr EQ expr
- { BIN_EXPR($$, "=", $1, $3, @1.first_line, @1.first_column); }
- | expr '=' expr
- { BIN_EXPR($$, "=", $1, $3, @1.first_line, @1.first_column); }
- | expr NEQ expr
- { BIN_EXPR($$, "=", $1, $3, @1.first_line, @1.first_column);
+ | expr '+' expr
+ { BIN_EXPR($$, "+", $1, $3, @1.first_line, @1.first_column); }
+ | expr '-' expr
+ { BIN_EXPR($$, "-", $1, $3, @1.first_line, @1.first_column); }
+ | expr '*' expr
+ { BIN_EXPR($$, "*", $1, $3, @1.first_line, @1.first_column); }
+ | expr '%' expr
+ { BIN_EXPR($$, "%", $1, $3, @1.first_line, @1.first_column); }
+ | expr '/' expr
+ { BIN_EXPR($$, "/", $1, $3, @1.first_line, @1.first_column); }
+ | expr '<' expr
+ { BIN_EXPR($$, ">", $3, $1, @1.first_line, @1.first_column); }
+ | expr '>' expr
+ { BIN_EXPR($$, ">", $1, $3, @1.first_line, @1.first_column); }
+ | expr '&' expr
+ { BIN_EXPR($$, "&", $1, $3, @1.first_line, @1.first_column); }
+ | expr '^' expr
+ { BIN_EXPR($$, "^", $1, $3, @1.first_line, @1.first_column); }
+ | expr '|' expr
+ { BIN_EXPR($$, "|", $1, $3, @1.first_line, @1.first_column); }
+ | expr SHL expr
+ { BIN_EXPR($$, "<<", $1, $3, @1.first_line, @1.first_column); }
+ | expr SHR expr
+ { BIN_EXPR($$, ">>", $1, $3, @1.first_line, @1.first_column); }
+ | expr LTE expr
+ { BIN_EXPR($$, ">=", $3, $1, @1.first_line, @1.first_column); }
+ | expr GTE expr
+ { BIN_EXPR($$, ">=", $1, $3, @1.first_line, @1.first_column); }
+ | expr ANDAND expr
+ { BIN_EXPR($$, "&&", $1, $3, @1.first_line, @1.first_column); }
+ | expr OROR expr
+ { BIN_EXPR($$, "||", $1, $3, @1.first_line, @1.first_column); }
+ | expr EQ expr
+ { BIN_EXPR($$, "=", $1, $3, @1.first_line, @1.first_column); }
+ | expr '=' expr
+ { BIN_EXPR($$, "=", $1, $3, @1.first_line, @1.first_column); }
+ | expr NEQ expr
+ { BIN_EXPR($$, "=", $1, $3, @1.first_line, @1.first_column);
$$ = fun_expr("not", 1, &$$, @1.first_line, @1.first_column); }
- | ID '(' arg_list ')'
- { $$ = fun_expr($1, $3.args_nr, $3.args, @1.first_line, @1.first_column);
+ | ID '(' arg_list ')'
+ { $$ = fun_expr($1, $3.args_nr, $3.args, @1.first_line, @1.first_column);
if ($3.args)
free($3.args);
free($1); }
- | '(' expr ')'
- { $$ = $2; }
- | expr '.' ID
- { $$ = dot_expr($1, intern_id($3)); }
- ;
+ | '(' expr ')'
+ { $$ = $2; }
+ | expr '.' ID
+ { $$ = dot_expr($1, intern_id($3)); }
+ ;
-arg_list : /* empty */
- { $$.args_nr = 0; }
- | arg_list_ne
- { $$ = $1; }
- ;
+arg_list : /* empty */
+ { $$.args_nr = 0; }
+ | arg_list_ne
+ { $$ = $1; }
+ ;
-arg_list_ne : expr
- { CREATE($$.args, expr_t *, 1);
+arg_list_ne : expr
+ { CREATE($$.args, expr_t *, 1);
$$.args_nr = 1;
$$.args[0] = $1;
}
- | arg_list_ne ',' expr
- { RECREATE($$.args, expr_t *, 1 + $$.args_nr);
+ | arg_list_ne ',' expr
+ { RECREATE($$.args, expr_t *, 1 + $$.args_nr);
$$.args[$$.args_nr++] = $3;
}
- ;
+ ;
-location : '@' '(' expr ',' expr ',' expr ')'
- { $$.m = $3; $$.x = $5; $$.y = $7; }
- ;
+location : '@' '(' expr ',' expr ',' expr ')'
+ { $$.m = $3; $$.x = $5; $$.y = $7; }
+ ;
-area : location
- { $$.ty = AREA_LOCATION;
+area : location
+ { $$.ty = AREA::LOCATION;
$$.a.a_loc = $1;
- }
- | location '@' '+' '(' expr ',' expr ')'
- { $$.ty = AREA_RECT;
+ }
+ | location '@' '+' '(' expr ',' expr ')'
+ { $$.ty = AREA::RECT;
$$.a.a_rect.loc = $1;
$$.a.a_rect.width = $5;
$$.a.a_rect.height = $7;
}
- | location TOWARDS expr ':' '(' expr ',' expr ')'
- { $$.ty = AREA_BAR;
+ | location TOWARDS expr ':' '(' expr ',' expr ')'
+ { $$.ty = AREA::BAR;
$$.a.a_bar.loc = $1;
$$.a.a_bar.width = $6;
$$.a.a_bar.depth = $8;
$$.a.a_bar.dir = $3;
}
- ;
+ ;
-spelldef : spellbody_list
+spelldef : spellbody_list
{ $$ = new_spell($1); }
- | LET defs IN spellbody_list
+ | LET defs IN spellbody_list
{ $$ = new_spell($4);
$$->letdefs_nr = $2.letdefs_nr;
$$->letdefs = $2.letdefs;
$$->spellguard = $4;
}
- ;
+ ;
-defs : semicolons
- { $$.letdefs_nr = 0;
+defs : semicolons
+ { $$.letdefs_nr = 0;
CREATE($$.letdefs, letdef_t, 1);
}
- | defs def semicolons
- { $$ = $1;
+ | defs def semicolons
+ { $$ = $1;
$$.letdefs_nr++;
- RECREATE ($$.letdefs, letdef_t, $$.letdefs_nr);
+ RECREATE($$.letdefs, letdef_t, $$.letdefs_nr);
$$.letdefs[$1.letdefs_nr] = $2;
}
;
-def : ID '=' expr
- {
+def : ID '=' expr
+ {
if (find_constant($1)) {
fail(@1.first_line, @1.first_column, "Attempt to re-define constant `%s' as LET-bound variable.\n", $1);
free($1);
@@ -486,216 +502,216 @@ def : ID '=' expr
$$.expr = $3;
}
}
- ;
+ ;
-spellbody_list : spellbody
- { $$ = $1; }
- | spellbody '|' spellbody_list
- { spellguard_t *sg = new_spellguard(SPELLGUARD_CHOICE);
+spellbody_list : spellbody
+ { $$ = $1; }
+ | spellbody '|' spellbody_list
+ { spellguard_t *sg = new_spellguard(SPELLGUARD::CHOICE);
sg->next = $1;
sg->s.s_alt = $3;
$$ = sg;
}
- ;
+ ;
-spellbody : spellguard DARROW spellbody
- { $$ = spellguard_implication($1, $3); }
- | '(' spellbody_list ')'
- { $$ = $2; }
- | EFFECT effect_list maybe_trigger maybe_end
- { spellguard_t *sg = new_spellguard(SPELLGUARD_EFFECT);
+spellbody : spellguard DARROW spellbody
+ { $$ = spellguard_implication($1, $3); }
+ | '(' spellbody_list ')'
+ { $$ = $2; }
+ | EFFECT_ effect_list maybe_trigger maybe_end
+ { spellguard_t *sg = new_spellguard(SPELLGUARD::EFFECT);
sg->s.s_effect.effect = $2;
sg->s.s_effect.at_trigger = $3;
sg->s.s_effect.at_end = $4;
$$ = sg;
}
- ;
+ ;
-maybe_trigger : /* empty */
- { $$ = NULL; }
- | ATTRIGGER effect_list
- { $$ = $2; }
- ;
+maybe_trigger : /* empty */
+ { $$ = NULL; }
+ | ATTRIGGER effect_list
+ { $$ = $2; }
+ ;
-maybe_end : /* empty */
- { $$ = NULL; }
- | ATEND effect_list
- { $$ = $2; }
- ;
+maybe_end : /* empty */
+ { $$ = NULL; }
+ | ATEND effect_list
+ { $$ = $2; }
+ ;
-spellguard : prereq
- { $$ = $1; }
- | spellguard OR spellguard
- { spellguard_t *sg = new_spellguard(SPELLGUARD_CHOICE);
+spellguard : prereq
+ { $$ = $1; }
+ | spellguard OR spellguard
+ { spellguard_t *sg = new_spellguard(SPELLGUARD::CHOICE);
sg->next = $1;
sg->s.s_alt = $3;
$$ = sg;
}
- | '(' spellguard_list ')'
- { $$ = $2; }
- ;
+ | '(' spellguard_list ')'
+ { $$ = $2; }
+ ;
-spellguard_list : spellguard
- { $$ = $1; }
- | spellguard ',' spellguard_list
- { $$ = spellguard_implication ($1, $3); }
- ;
+spellguard_list : spellguard
+ { $$ = $1; }
+ | spellguard ',' spellguard_list
+ { $$ = spellguard_implication($1, $3); }
+ ;
-prereq : REQUIRE expr
- { $$ = new_spellguard(SPELLGUARD_CONDITION);
+prereq : REQUIRE expr
+ { $$ = new_spellguard(SPELLGUARD::CONDITION);
$$->s.s_condition = $2;
}
- | CATALYSTS items
- { $$ = new_spellguard(SPELLGUARD_CATALYSTS);
+ | CATALYSTS items
+ { $$ = new_spellguard(SPELLGUARD::CATALYSTS);
$$->s.s_catalysts = $2;
}
- | COMPONENTS items
- { $$ = new_spellguard(SPELLGUARD_COMPONENTS);
+ | COMPONENTS items
+ { $$ = new_spellguard(SPELLGUARD::COMPONENTS);
$$->s.s_components = $2;
}
- | MANA expr
- { $$ = new_spellguard(SPELLGUARD_MANA);
+ | MANA expr
+ { $$ = new_spellguard(SPELLGUARD::MANA);
$$->s.s_mana = $2;
}
- | CASTTIME expr
- { $$ = new_spellguard(SPELLGUARD_CASTTIME);
+ | CASTTIME expr
+ { $$ = new_spellguard(SPELLGUARD::CASTTIME);
$$->s.s_casttime = $2;
}
- ;
+ ;
-items : '[' item_list ']'
- { $$ = $2; }
- ;
+items : '[' item_list ']'
+ { $$ = $2; }
+ ;
-item_list : item
- { $$ = NULL;
+item_list : item
+ { $$ = NULL;
magic_add_component(&$$, $1.id, $1.count);
}
- | item_list ',' item
- { $$ = $1;
+ | item_list ',' item
+ { $$ = $1;
magic_add_component(&$$, $3.id, $3.count);
}
- ;
+ ;
-item : INT '*' item_name
- { $$.id = $3; $$.count = $1; }
- | item_name
- { $$.id = $1; $$.count = 1; }
- ;
+item : INT '*' item_name
+ { $$.id = $3; $$.count = $1; }
+ | item_name
+ { $$.id = $1; $$.count = 1; }
+ ;
-item_name : STRING
- { struct item_data *item = itemdb_searchname($1);
+item_name : STRING
+ { struct item_data *item = itemdb_searchname($1);
if (!item) {
- fail (@1.first_line, @1.first_column, "Unknown item `%s'\n", $1);
+ fail(@1.first_line, @1.first_column, "Unknown item `%s'\n", $1);
$$ = 0;
} else
$$ = item->nameid;
- free ($1);
+ free($1);
}
- | INT
- { $$ = $1; }
- ;
-
-
-selection : PC_F
- { $$ = FOREACH_FILTER_PC; }
- | MOB_F
- { $$ = FOREACH_FILTER_MOB; }
- | ENTITY_F
- { $$ = FOREACH_FILTER_ENTITY; }
- | SPELL
- { $$ = FOREACH_FILTER_SPELL; }
- | TARGET_F
- { $$ = FOREACH_FILTER_TARGET; }
- | NPC_F
- { $$ = FOREACH_FILTER_NPC; }
- ;
-
-
-effect : '(' effect_list ')'
- { $$ = $2; }
- | SKIP ';'
- { $$ = new_effect(EFFECT_SKIP); }
- | ABORT ';'
- { $$ = new_effect(EFFECT_ABORT); }
- | END ';'
- { $$ = new_effect(EFFECT_END); }
- | BREAK ';'
- { $$ = new_effect(EFFECT_BREAK); }
- | ID '=' expr ';'
- {
+ | INT
+ { $$ = $1; }
+ ;
+
+
+selection : PC_F
+ { $$ = FOREACH_FILTER::PC; }
+ | MOB_F
+ { $$ = FOREACH_FILTER::MOB; }
+ | ENTITY_F
+ { $$ = FOREACH_FILTER::ENTITY; }
+ | SPELL
+ { $$ = FOREACH_FILTER::SPELL; }
+ | TARGET_F
+ { $$ = FOREACH_FILTER::TARGET; }
+ | NPC_F
+ { $$ = FOREACH_FILTER::NPC; }
+ ;
+
+
+effect : '(' effect_list ')'
+ { $$ = $2; }
+ | SKIP ';'
+ { $$ = new_effect(EFFECT::SKIP); }
+ | ABORT ';'
+ { $$ = new_effect(EFFECT::ABORT); }
+ | END ';'
+ { $$ = new_effect(EFFECT::END); }
+ | BREAK ';'
+ { $$ = new_effect(EFFECT::BREAK); }
+ | ID '=' expr ';'
+ {
if (find_constant($1)) {
fail(@1.first_line, @1.first_column, "Attempt to re-define constant `%s' in assignment.", $1);
free($1);
} else {
- $$ = new_effect(EFFECT_ASSIGN);
+ $$ = new_effect(EFFECT::ASSIGN);
$$->e.e_assign.id = intern_id($1);
$$->e.e_assign.expr = $3;
}
}
- | FOREACH selection ID IN expr DO effect
- { $$ = new_effect(EFFECT_FOREACH);
+ | FOREACH selection ID IN expr DO effect
+ { $$ = new_effect(EFFECT::FOREACH);
$$->e.e_foreach.id = intern_id($3);
$$->e.e_foreach.area = $5;
$$->e.e_foreach.body = $7;
$$->e.e_foreach.filter = $2;
}
- | FOR ID '=' expr TO expr DO effect
- { $$ = new_effect(EFFECT_FOR);
+ | FOR ID '=' expr TO expr DO effect
+ { $$ = new_effect(EFFECT::FOR);
$$->e.e_for.id = intern_id($2);
$$->e.e_for.start = $4;
$$->e.e_for.stop = $6;
$$->e.e_for.body = $8;
}
- | IF expr THEN effect ELSE effect
- { $$ = new_effect(EFFECT_IF);
+ | IF expr THEN effect ELSE effect
+ { $$ = new_effect(EFFECT::IF);
$$->e.e_if.cond = $2;
$$->e.e_if.true_branch = $4;
$$->e.e_if.false_branch = $6;
}
- | IF expr THEN effect
- { $$ = new_effect(EFFECT_IF);
+ | IF expr THEN effect
+ { $$ = new_effect(EFFECT::IF);
$$->e.e_if.cond = $2;
$$->e.e_if.true_branch = $4;
- $$->e.e_if.false_branch = new_effect(EFFECT_SKIP);
+ $$->e.e_if.false_branch = new_effect(EFFECT::SKIP);
}
- | SLEEP expr ';'
- { $$ = new_effect(EFFECT_SLEEP);
+ | SLEEP expr ';'
+ { $$ = new_effect(EFFECT::SLEEP);
$$->e.e_sleep = $2;
}
- | ID '(' arg_list ')' ';'
+ | ID '(' arg_list ')' ';'
{ $$ = op_effect($1, $3.args_nr, $3.args, @1.first_line, @1.first_column);
free($1);
}
- | SCRIPT_DATA
- { $$ = new_effect(EFFECT_SCRIPT);
+ | SCRIPT_DATA
+ { $$ = new_effect(EFFECT::SCRIPT);
$$->e.e_script = parse_script($1, @1.first_line);
free($1);
if ($$->e.e_script == NULL)
fail(@1.first_line, @1.first_column, "Failed to compile script\n");
}
- | CALL ID '(' arg_list ')' ';'
- { $$ = call_proc($2, $4.args_nr, $4.args, @1.first_line, @1.first_column);
+ | CALL ID '(' arg_list ')' ';'
+ { $$ = call_proc($2, $4.args_nr, $4.args, @1.first_line, @1.first_column);
free($2);
}
- ;
+ ;
-effect_list : /* empty */
- { $$ = new_effect(EFFECT_SKIP); }
- | effect semicolons effect_list
- { $$ = set_effect_continuation($1, $3); }
- ;
+effect_list : /* empty */
+ { $$ = new_effect(EFFECT::SKIP); }
+ | effect semicolons effect_list
+ { $$ = set_effect_continuation($1, $3); }
+ ;
%%
@@ -703,8 +719,8 @@ effect_list : /* empty */
/* We do incremental realloc here to store our results. Since this happens only once
* during startup for a relatively manageable set of configs, it should be fine. */
-static int
-intern_id(const char *id_name)
+static
+int intern_id(const char *id_name)
{
int i;
@@ -719,13 +735,13 @@ intern_id(const char *id_name)
RECREATE(magic_conf.var_name, const char *, magic_conf.vars_nr);
magic_conf.var_name[i] = id_name;
RECREATE(magic_conf.vars, val_t, magic_conf.vars_nr);
- magic_conf.vars[i].ty = TY_UNDEF;
+ magic_conf.vars[i].ty = TYPE::UNDEF;
return i;
}
-static void
-add_spell(spell_t *spell, int line_nr)
+static
+void add_spell(spell_t *spell, int line_nr)
{
int index = magic_conf.spells_nr;
int i;
@@ -749,8 +765,8 @@ add_spell(spell_t *spell, int line_nr)
}
-static void
-add_teleport_anchor(teleport_anchor_t *anchor, int line_nr)
+static
+void add_teleport_anchor(teleport_anchor_t *anchor, int line_nr)
{
int index = magic_conf.anchors_nr;
int i;
@@ -777,24 +793,24 @@ static __attribute__((format(printf, 3, 4)))
void fail(int line, int column, const char *fmt, ...)
{
va_list ap;
- fprintf(stderr, "[magic-init] L%d:%d: ", line, column);
+ FPRINTF(stderr, "[magic-init] L%d:%d: ", line, column);
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
failed_flag = 1;
}
-static expr_t *
-dot_expr(expr_t *expr, int id)
+static
+expr_t *dot_expr(expr_t *expr, int id)
{
- expr_t *retval = magic_new_expr(EXPR_SPELLFIELD);
+ expr_t *retval = magic_new_expr(EXPR::SPELLFIELD);
retval->e.e_field.id = id;
retval->e.e_field.expr = expr;
return retval;
}
-static expr_t *
-fun_expr(const char *name, int args_nr, expr_t **args, int line, int column)
+static
+expr_t *fun_expr(const char *name, int args_nr, expr_t **args, int line, int column)
{
int id;
expr_t *expr;
@@ -803,14 +819,14 @@ fun_expr(const char *name, int args_nr, expr_t **args, int line, int column)
if (!fun) {
fail(line, column, "Unknown function `%s'\n", name);
} else if (strlen(fun->signature) != args_nr) {
- fail(line, column, "Incorrect number of arguments to function `%s': Expected %d, found %d\n", name, strlen(fun->signature), args_nr);
+ fail(line, column, "Incorrect number of arguments to function `%s': Expected %zu, found %d\n", name, strlen(fun->signature), args_nr);
fun = NULL;
}
if (fun) {
int i;
- expr = magic_new_expr(EXPR_FUNAPP);
+ expr = magic_new_expr(EXPR::FUNAPP);
expr->e.e_funapp.line_nr = line;
expr->e.e_funapp.column = column;
expr->e.e_funapp.id = id;
@@ -819,15 +835,15 @@ fun_expr(const char *name, int args_nr, expr_t **args, int line, int column)
for (i = 0; i < args_nr; i++)
expr->e.e_funapp.args[i] = args[i];
} else { /* failure */
- expr = magic_new_expr(EXPR_VAL);
- expr->e.e_val.ty = TY_FAIL;
+ expr = magic_new_expr(EXPR::VAL);
+ expr->e.e_val.ty = TYPE::FAIL;
}
return expr;
}
-static spell_t *
-new_spell(spellguard_t *guard)
+static
+spell_t *new_spell(spellguard_t *guard)
{
static int spell_counter = 0;
@@ -837,16 +853,16 @@ new_spell(spellguard_t *guard)
return retval;
}
-static spellguard_t *
-new_spellguard(int ty)
+static
+spellguard_t *new_spellguard(SPELLGUARD ty)
{
spellguard_t *retval = (spellguard_t *)calloc(1, sizeof(spellguard_t));
retval->ty = ty;
return retval;
}
-static spellguard_t *
-spellguard_implication(spellguard_t *a, spellguard_t *b)
+static
+spellguard_t *spellguard_implication(spellguard_t *a, spellguard_t *b)
{
spellguard_t *retval = a;
@@ -864,7 +880,7 @@ spellguard_implication(spellguard_t *a, spellguard_t *b)
return retval;
/* If the premise is a disjunction, b is the continuation of _all_ branches */
- if (a->ty == SPELLGUARD_CHOICE)
+ if (a->ty == SPELLGUARD::CHOICE)
spellguard_implication(a->s.s_alt, b);
if (a->next)
spellguard_implication(a->next, b);
@@ -875,16 +891,16 @@ spellguard_implication(spellguard_t *a, spellguard_t *b)
return retval;
}
-static effect_t *
-new_effect(int ty)
+static
+effect_t *new_effect(EFFECT ty)
{
effect_t *effect = (effect_t *) calloc(1, sizeof(effect_t));
effect->ty = ty;
return effect;
}
-static effect_t *
-set_effect_continuation(effect_t *src, effect_t *continuation)
+static
+effect_t *set_effect_continuation(effect_t *src, effect_t *continuation)
{
effect_t *retval = src;
/* This function is completely analogous to `spellguard_implication' above; read the control flow implications above first before pondering it. */
@@ -894,7 +910,7 @@ set_effect_continuation(effect_t *src, effect_t *continuation)
/* For FOR and FOREACH, we use special stack handlers and thus don't have to set
* the continuation. It's only IF that we need to handle in this fashion. */
- if (src->ty == EFFECT_IF) {
+ if (src->ty == EFFECT::IF) {
set_effect_continuation(src->e.e_if.true_branch, continuation);
set_effect_continuation(src->e.e_if.false_branch, continuation);
}
@@ -906,8 +922,8 @@ set_effect_continuation(effect_t *src, effect_t *continuation)
return retval;
}
-static effect_t *
-op_effect(char *name, int args_nr, expr_t **args, int line, int column)
+static
+effect_t *op_effect(char *name, int args_nr, expr_t **args, int line, int column)
{
int id;
effect_t *effect;
@@ -916,14 +932,14 @@ op_effect(char *name, int args_nr, expr_t **args, int line, int column)
if (!op)
fail(line, column, "Unknown operation `%s'\n", name);
else if (strlen(op->signature) != args_nr) {
- fail(line, column, "Incorrect number of arguments to operation `%s': Expected %d, found %d\n", name, strlen(op->signature), args_nr);
+ fail(line, column, "Incorrect number of arguments to operation `%s': Expected %zu, found %d\n", name, strlen(op->signature), args_nr);
op = NULL;
}
if (op) {
int i;
- effect = new_effect(EFFECT_OP);
+ effect = new_effect(EFFECT::OP);
effect->e.e_op.line_nr = line;
effect->e.e_op.column = column;
effect->e.e_op.id = id;
@@ -932,7 +948,7 @@ op_effect(char *name, int args_nr, expr_t **args, int line, int column)
for (i = 0; i < args_nr; i++)
effect->e.e_op.args[i] = args[i];
} else /* failure */
- effect = new_effect(EFFECT_SKIP);
+ effect = new_effect(EFFECT::SKIP);
return effect;
}
@@ -942,20 +958,20 @@ proc_t *procs = NULL;
int procs_nr = 0;
// I think this is a memory leak, or undefined behavior
-static void
-install_proc(proc_t *proc)
+static
+void install_proc(proc_t *proc)
{
if (!procs) {
procs = proc;
procs_nr = 1;
} else {
- RECREATE (procs, proc_t, 1 + procs_nr);
+ RECREATE(procs, proc_t, 1 + procs_nr);
procs[procs_nr++] = *proc;
}
}
-static effect_t *
-call_proc(char *name, int args_nr, expr_t **args, int line_nr, int column)
+static
+effect_t *call_proc(char *name, int args_nr, expr_t **args, int line_nr, int column)
{
proc_t *p = NULL;
int i;
@@ -969,15 +985,15 @@ call_proc(char *name, int args_nr, expr_t **args, int line_nr, int column)
if (!p) {
fail(line_nr, column, "Unknown procedure `%s'\n", name);
- return new_effect(EFFECT_SKIP);
+ return new_effect(EFFECT::SKIP);
}
if (p->args_nr != args_nr) {
fail(line_nr, column, "Procedure %s/%d invoked with %d parameters\n", name, p->args_nr, args_nr);
- return new_effect(EFFECT_SKIP);
+ return new_effect(EFFECT::SKIP);
}
- retval = new_effect(EFFECT_CALL);
+ retval = new_effect(EFFECT::CALL);
retval->e.e_call.body = p->body;
retval->e.e_call.args_nr = args_nr;
retval->e.e_call.formals = p->args;
@@ -992,8 +1008,8 @@ struct const_def_rec {
int const_defs_nr = 0;
-static void
-bind_constant(char *name, val_t *val, int line_nr)
+static
+void bind_constant(char *name, val_t *val, int line_nr)
{
if (find_constant(name)) {
fail(line_nr, 0, "Redefinition of constant `%s'\n", name);
@@ -1011,8 +1027,8 @@ bind_constant(char *name, val_t *val, int line_nr)
++const_defs_nr;
}
-static val_t *
-find_constant(char *name)
+static
+val_t *find_constant(char *name)
{
int i;
for (i = 0; i < const_defs_nr; i++) {
@@ -1027,8 +1043,16 @@ find_constant(char *name)
-
-#define INTERN_ASSERT(name, id) { int zid = intern_id(name); if (zid != id) fprintf(stderr, "[magic-conf] INTERNAL ERROR: Builtin special var %s interned to %d, not %d as it should be!\n", name, zid, id); error_flag = 1; }
+// FIXME: macro capture
+#define INTERN_ASSERT(name, id) \
+{ \
+ int zid = intern_id(name); \
+ if (zid != id) \
+ FPRINTF(stderr, \
+ "[magic-conf] INTERNAL ERROR: Builtin special var %s interned to %d, not %d as it should be!\n", \
+ name, zid, id); \
+ error_flag = 1; \
+}
extern FILE *magic_frontend_in;
@@ -1063,18 +1087,18 @@ int magic_init(const char *conffile)
magic_frontend_in = fopen(conffile, "r");
if (!magic_frontend_in) {
- fprintf(stderr, "[magic-conf] Magic configuration file `%s' not found -> no magic.\n", conffile);
+ FPRINTF(stderr, "[magic-conf] Magic configuration file `%s' not found -> no magic.\n", conffile);
return 0;
}
magic_frontend_parse();
- if (magic_conf.vars[VAR_MIN_CASTTIME].ty == TY_INT)
+ if (magic_conf.vars[VAR_MIN_CASTTIME].ty == TYPE::INT)
magic_conf.min_casttime = magic_conf.vars[VAR_MIN_CASTTIME].v.v_int;
- if (magic_conf.vars[VAR_OBSCURE_CHANCE].ty == TY_INT)
+ if (magic_conf.vars[VAR_OBSCURE_CHANCE].ty == TYPE::INT)
magic_conf.obscure_chance = magic_conf.vars[VAR_OBSCURE_CHANCE].v.v_int;
- printf("[magic-conf] Magic initialised; obscure at %d%%. %d spells, %d teleport anchors.\n",
+ PRINTF("[magic-conf] Magic initialised; obscure at %d%%. %d spells, %d teleport anchors.\n",
magic_conf.obscure_chance, magic_conf.spells_nr, magic_conf.anchors_nr);
if (procs)
@@ -1084,9 +1108,9 @@ int magic_init(const char *conffile)
extern int magic_frontend_lineno;
-static void
-magic_frontend_error(const char *msg)
+static
+void magic_frontend_error(const char *msg)
{
- fprintf(stderr, "[magic-conf] Parse error: %s at line %d\n", msg, magic_frontend_lineno);
+ FPRINTF(stderr, "[magic-conf] Parse error: %s at line %d\n", msg, magic_frontend_lineno);
failed_flag = 1;
}
diff --git a/src/map/magic-interpreter.hpp b/src/map/magic-interpreter.hpp
index 21e8d39..22223ec 100644
--- a/src/map/magic-interpreter.hpp
+++ b/src/map/magic-interpreter.hpp
@@ -1,62 +1,12 @@
-/* Magic interpreter */
-
#ifndef MAGIC_INTERPRETER_HPP
#define MAGIC_INTERPRETER_HPP
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <math.h>
-
-#include "../common/nullpo.hpp"
+#include "magic-interpreter.t.hpp"
-#include "battle.hpp"
-#include "chat.hpp"
-#include "chrif.hpp"
-#include "clif.hpp"
-#include "intif.hpp"
-#include "itemdb.hpp"
#include "magic.hpp"
#include "map.hpp"
-#include "mob.hpp"
-#include "npc.hpp"
-#include "pc.hpp"
-#include "party.hpp"
#include "script.hpp"
-#include "skill.hpp"
-#include "storage.hpp"
-#include "trade.hpp"
-
-#include "../common/timer.hpp"
-#include "../common/socket.hpp"
-
-#define SPELLARG_NONE 0 /* No spell parameter */
-#define SPELLARG_PC 1 /* Spell parameter describes pc (defaults to self) */
-#define SPELLARG_STRING 2 /* Spell parameter describes pc (defaults to self) */
-
-/* ------ */
-/* Values */
-/* ------ */
-
-#define TY_UNDEF 0
-#define TY_INT 1
-#define TY_DIR 2
-#define TY_STRING 3
-#define TY_ENTITY 5
-#define TY_LOCATION 6
-#define TY_AREA 7
-#define TY_SPELL 8
-#define TY_INVOCATION 9
-#define TY_FAIL 127
-
-#define DIR_S 0
-#define DIR_SW 1
-#define DIR_W 2
-#define DIR_NW 3
-#define DIR_N 4
-#define DIR_NE 5
-#define DIR_E 6
-#define DIR_SE 7
+#include "skill.t.hpp"
struct expr;
struct val;
@@ -67,15 +17,10 @@ struct invocation;
typedef struct location
{
- int m;
- int x, y;
+ int m;
+ int x, y;
} location_t;
-#define AREA_LOCATION 0
-#define AREA_UNION 1
-#define AREA_RECT 2
-#define AREA_BAR 3
-
typedef struct area
{
union a
@@ -84,24 +29,26 @@ typedef struct area
struct
{
location_t loc;
- int width, depth, dir;
+ int width, depth;
+ DIR dir;
} a_bar;
struct
{
location_t loc;
- int width, height;
+ int width, height;
} a_rect;
struct area *a_union[2];
} a;
- int size;
- unsigned char ty;
+ int size;
+ AREA ty;
} area_t;
typedef struct val
{
union v
{
- int v_int;
+ int v_int;
+ DIR v_dir;
char *v_string;
entity_t *v_entity; /* Used ONLY during operation/function invocation; otherwise we use v_int */
area_t *v_area;
@@ -109,7 +56,7 @@ typedef struct val
struct invocation *v_invocation; /* Used ONLY during operation/function invocation; otherwise we use v_int */
struct spell *v_spell;
} v;
- unsigned char ty;
+ TYPE ty;
} val_t;
/* ----------- */
@@ -118,13 +65,6 @@ typedef struct val
#define MAX_ARGS 7 /* Max. # of args used in builtin primitive functions */
-#define EXPR_VAL 0
-#define EXPR_LOCATION 1
-#define EXPR_AREA 2
-#define EXPR_FUNAPP 3
-#define EXPR_ID 4
-#define EXPR_SPELLFIELD 5
-
typedef struct e_location
{
struct expr *m, *x, *y;
@@ -147,7 +87,7 @@ typedef struct e_area
} a_rect;
struct e_area *a_union[2];
} a;
- unsigned char ty;
+ AREA ty;
} e_area_t;
typedef struct expr
@@ -159,44 +99,20 @@ typedef struct expr
e_area_t e_area;
struct
{
- int id, line_nr, column;
- int args_nr;
+ int id, line_nr, column;
+ int args_nr;
struct expr *args[MAX_ARGS];
} e_funapp;
- int e_id;
+ int e_id;
struct
{
struct expr *expr;
- int id;
+ int id;
} e_field;
} e;
- unsigned char ty;
+ EXPR ty;
} expr_t;
-/* ------- */
-/* Effects */
-/* ------- */
-
-#define EFFECT_SKIP 0
-#define EFFECT_ABORT 1
-#define EFFECT_ASSIGN 2
-#define EFFECT_FOREACH 3
-#define EFFECT_FOR 4
-#define EFFECT_IF 5
-#define EFFECT_SLEEP 6
-#define EFFECT_SCRIPT 7
-#define EFFECT_BREAK 8
-#define EFFECT_OP 9
-#define EFFECT_END 10
-#define EFFECT_CALL 11
-
-#define FOREACH_FILTER_MOB 1
-#define FOREACH_FILTER_PC 2
-#define FOREACH_FILTER_ENTITY 3
-#define FOREACH_FILTER_TARGET 4
-#define FOREACH_FILTER_SPELL 5
-#define FOREACH_FILTER_NPC 6
-
typedef struct effect
{
struct effect *next;
@@ -204,19 +120,19 @@ typedef struct effect
{
struct
{
- int id;
+ int id;
expr_t *expr;
} e_assign;
struct
{
- int id;
+ int id;
expr_t *area;
struct effect *body;
- unsigned char filter;
+ FOREACH_FILTER filter;
} e_foreach;
struct
{
- int id;
+ int id;
expr_t *start, *stop;
struct effect *body;
} e_for;
@@ -229,19 +145,19 @@ typedef struct effect
const ScriptCode *e_script;
struct
{
- int id;
- int args_nr;
- int line_nr, column;
+ int id;
+ int args_nr;
+ int line_nr, column;
expr_t *args[MAX_ARGS];
} e_op;
struct
{
- int args_nr, *formals;
+ int args_nr, *formals;
expr_t **actuals;
struct effect *body;
} e_call;
} e;
- unsigned char ty;
+ EFFECT ty;
} effect_t;
/* ---------- */
@@ -251,21 +167,10 @@ typedef struct effect
typedef struct component
{
struct component *next;
- int item_id;
- int count;
+ int item_id;
+ int count;
} component_t;
-/* ----------- */
-/* Spellguards */
-/* ----------- */
-
-#define SPELLGUARD_CONDITION 0
-#define SPELLGUARD_COMPONENTS 1
-#define SPELLGUARD_CATALYSTS 2
-#define SPELLGUARD_CHOICE 3
-#define SPELLGUARD_MANA 4
-#define SPELLGUARD_CASTTIME 5
-#define SPELLGUARD_EFFECT 6
typedef struct effect_set
{
@@ -285,7 +190,7 @@ typedef struct spellguard
struct spellguard *s_alt; /* either `next' or `s.s_alt' */
effect_set_t s_effect;
} s;
- unsigned char ty;
+ SPELLGUARD ty;
} spellguard_t;
/* ------ */
@@ -294,24 +199,20 @@ typedef struct spellguard
typedef struct letdef
{
- int id;
+ int id;
expr_t *expr;
} letdef_t;
-#define SPELL_FLAG_LOCAL (1 << 0) // spell associated not with caster but with place
-#define SPELL_FLAG_SILENT (1 << 1) // spell invocation never uttered
-#define SPELL_FLAG_NONMAGIC (1 << 2) // `magic word' only: don't require spellcasting ability
-
typedef struct spell
{
char *name;
char *invocation;
- int index; // Relative location in the definitions file
- int flags;
- int arg;
- int spellarg_ty;
+ int index; // Relative location in the definitions file
+ SPELL_FLAG flags;
+ int arg;
+ SPELLARG spellarg_ty;
- int letdefs_nr;
+ int letdefs_nr;
letdef_t *letdefs;
spellguard_t *spellguard;
@@ -334,31 +235,32 @@ typedef struct teleport_anchor
typedef struct
{
- int vars_nr;
+ int vars_nr;
const char **var_name;
val_t *vars; /* Initial assignments, if any, or NULL */
- int obscure_chance;
- int min_casttime;
+ int obscure_chance;
+ int min_casttime;
- int spells_nr;
+ int spells_nr;
spell_t **spells;
- int anchors_nr; /* NEGATIVE iff we have sorted the anchors */
+ int anchors_nr; /* NEGATIVE iff we have sorted the anchors */
teleport_anchor_t **anchors;
} magic_conf_t;
/* Execution environment */
-#define VAR_MIN_CASTTIME 0
-#define VAR_OBSCURE_CHANCE 1
-#define VAR_CASTER 2
-#define VAR_SPELLPOWER 3
-#define VAR_SPELL 4
-#define VAR_INVOCATION 5
-#define VAR_TARGET 6
-#define VAR_SCRIPTTARGET 7
-#define VAR_LOCATION 8
+// these are not an enum they're a nasty intern hack
+#define VAR_MIN_CASTTIME 0
+#define VAR_OBSCURE_CHANCE 1
+#define VAR_CASTER 2
+#define VAR_SPELLPOWER 3
+#define VAR_SPELL 4
+#define VAR_INVOCATION 5
+#define VAR_TARGET 6
+#define VAR_SCRIPTTARGET 7
+#define VAR_LOCATION 8
struct magic_config;
@@ -370,10 +272,6 @@ typedef struct env
#define MAX_STACK_SIZE 32
-#define CONT_STACK_FOREACH 0
-#define CONT_STACK_FOR 1
-#define CONT_STACK_PROC 2
-
typedef struct cont_activation_record
{
effect_t *return_location;
@@ -381,62 +279,59 @@ typedef struct cont_activation_record
{
struct
{
- int id, ty;
+ int id;
+ TYPE ty;
effect_t *body;
- int entities_nr;
+ int entities_nr;
int *entities;
- int index;
+ int index;
} c_foreach;
struct
{
- int id;
+ int id;
effect_t *body;
- int current;
- int stop;
+ int current;
+ int stop;
} c_for;
struct
{
- int args_nr, *formals;
+ int args_nr, *formals;
val_t *old_actuals;
} c_proc;
} c;
- unsigned char ty;
+ CONT_STACK ty;
} cont_activation_record_t;
typedef struct status_change_ref
{
- int sc_type;
- int bl_id;
+ StatusChange sc_type;
+ int bl_id;
} status_change_ref_t;
-#define INVOCATION_FLAG_BOUND (1 << 0) /* Bound directly to the caster (i.e., ignore its location) */
-#define INVOCATION_FLAG_ABORTED (1 << 1) /* Used `abort' to terminate */
-#define INVOCATION_FLAG_STOPATTACK (1 << 2) /* On magical attacks: if we run out of steam, stop attacking altogether */
-
typedef struct invocation
{
struct block_list bl;
struct invocation *next_invocation; /* used for spells directly associated with a caster: they form a singly-linked list */
- int flags;
+ INVOCATION_FLAG flags;
env_t *env;
spell_t *spell;
- int caster; /* this is the person who originally invoked the spell */
- int subject; /* when this person dies, the spell dies with it */
+ int caster; /* this is the person who originally invoked the spell */
+ int subject; /* when this person dies, the spell dies with it */
- int timer; /* spell timer, if any */
+ Timer timer; /* spell timer, if any */
- int stack_size;
+ int stack_size;
cont_activation_record_t stack[MAX_STACK_SIZE];
- int script_pos; /* Script position; if nonzero, resume the script we were running. */
+ int script_pos; /* Script position; if nonzero, resume the script we were running. */
effect_t *current_effect;
effect_t *trigger_effect; /* If non-NULL, this is used to spawn a cloned effect based on the same environment */
effect_t *end_effect; /* If non-NULL, this is executed when the spell terminates naturally, e.g. when all status changes have run out or all delays are over. */
/* Status change references: for status change updates, keep track of whom we updated where */
- int status_change_refs_nr;
+ int status_change_refs_nr;
status_change_ref_t *status_change_refs;
} invocation_t;
@@ -447,58 +342,58 @@ extern env_t magic_default_env; /* Fake default environment */
/**
* Adds a component selection to a component holder (which may initially be NULL)
*/
-void magic_add_component (component_t ** component_holder, int id, int count);
+void magic_add_component(component_t ** component_holder, int id, int count);
-teleport_anchor_t *magic_find_anchor (char *name);
+teleport_anchor_t *magic_find_anchor(char *name);
/**
* The parameter `param' must have been dynamically allocated; ownership is transferred to the resultant env_t.
*/
-env_t *spell_create_env (magic_conf_t * conf, spell_t * spell,
- character_t * caster, int spellpower, char *param);
+env_t *spell_create_env(magic_conf_t *conf, spell_t *spell,
+ character_t *caster, int spellpower, char *param);
-void magic_free_env (env_t * env);
+void magic_free_env(env_t *env);
/**
* near_miss is set to nonzero iff the spell only failed due to ephemereal issues (spell delay in effect, out of mana, out of components)
*/
-effect_set_t *spell_trigger (spell_t * spell, character_t * caster,
- env_t * env, int *near_miss);
+effect_set_t *spell_trigger(spell_t *spell, character_t *caster,
+ env_t *env, int *near_miss);
-invocation_t *spell_instantiate (effect_set_t * effect, env_t * env);
+invocation_t *spell_instantiate(effect_set_t *effect, env_t *env);
/**
* Bind a spell to a subject (this is a no-op for `local' spells).
*/
-void spell_bind (character_t * subject, invocation_t * invocation);
+void spell_bind(character_t *subject, invocation_t *invocation);
-int // 1 on failure
- spell_unbind (character_t * subject, invocation_t * invocation);
+// 1 on failure
+int spell_unbind(character_t *subject, invocation_t *invocation);
/**
* Clones a spell to run the at_effect field
*/
-invocation_t *spell_clone_effect (invocation_t * source);
+invocation_t *spell_clone_effect(invocation_t *source);
-spell_t *magic_find_spell (char *invocation);
+spell_t *magic_find_spell(char *invocation);
/* The following is used only by the parser: */
typedef struct args_rec
{
- int args_nr;
+ int args_nr;
expr_t **args;
} args_rec_t;
typedef struct
{
char *name;
- int args_nr;
+ int args_nr;
int *args;
effect_t *body;
} proc_t;
// must be called after itemdb initialisation
int magic_init(const char *);
-void spell_update_location (invocation_t * invocation);
+void spell_update_location(invocation_t *invocation);
-#endif /* !defined (MAGIC_INTERPRETER_H) */
+#endif // MAGIC_INTERPRETER_HPP
diff --git a/src/map/magic-interpreter.t.hpp b/src/map/magic-interpreter.t.hpp
new file mode 100644
index 0000000..d5aa5e5
--- /dev/null
+++ b/src/map/magic-interpreter.t.hpp
@@ -0,0 +1,159 @@
+#ifndef MAGIC_INTERPRETER_T_HPP
+#define MAGIC_INTERPRETER_T_HPP
+
+#include "../common/utils2.hpp"
+
+enum class SPELLARG : uint8_t
+{
+ NONE,
+ PC,
+ STRING,
+};
+
+enum class TYPE : uint8_t
+{
+ UNDEF,
+ INT,
+ DIR,
+ STRING,
+ ENTITY,
+ LOCATION,
+ AREA,
+ SPELL,
+ INVOCATION,
+ FAIL = 127,
+
+ NEGATIVE_1 = 255,
+};
+
+// Note: there is also a typedef by this name in <dirent.h>
+// but we should be fine since we never include it.
+// (in the long term we should still rename this though)
+enum class DIR : uint8_t
+{
+ S = 0,
+ SW = 1,
+ W = 2,
+ NW = 3,
+ N = 4,
+ NE = 5,
+ E = 6,
+ SE = 7,
+
+ COUNT,
+};
+
+constexpr
+earray<int, DIR, DIR::COUNT> dirx //=
+{{
+ 0, -1, -1, -1, 0, 1, 1, 1,
+}}, diry //=
+{{
+ 1, 1, 0, -1, -1, -1, 0, 1,
+}};
+
+constexpr
+bool dir_is_diagonal(DIR d)
+{
+ return static_cast<uint8_t>(d) & 1;
+}
+
+enum class AREA : uint8_t
+{
+ LOCATION,
+ UNION,
+ RECT,
+ BAR,
+};
+
+enum class EXPR : uint8_t
+{
+ VAL,
+ LOCATION,
+ AREA,
+ FUNAPP,
+ ID,
+ SPELLFIELD,
+};
+
+// temporary rename to avoid collision with enum value
+// in magic-interpreter-parser
+enum class EFFECT : uint8_t
+{
+ SKIP,
+ ABORT,
+ ASSIGN,
+ FOREACH,
+ FOR,
+ IF,
+ SLEEP,
+ SCRIPT,
+ BREAK,
+ OP,
+ END,
+ CALL,
+};
+
+enum class FOREACH_FILTER : uint8_t
+{
+ MOB,
+ PC,
+ ENTITY,
+ TARGET,
+ SPELL,
+ NPC,
+};
+
+enum class SPELLGUARD : uint8_t
+{
+ CONDITION,
+ COMPONENTS,
+ CATALYSTS,
+ CHOICE,
+ MANA,
+ CASTTIME,
+ EFFECT,
+};
+
+namespace e
+{
+enum class SPELL_FLAG : uint8_t
+{
+ ZERO = 0,
+
+ // spell associated not with caster but with place
+ LOCAL = 1 << 0,
+ // spell invocation never uttered
+ SILENT = 1 << 1,
+ // `magic word' only: don't require spellcasting ability
+ NONMAGIC = 1 << 2,
+};
+ENUM_BITWISE_OPERATORS(SPELL_FLAG)
+}
+using e::SPELL_FLAG;
+
+enum class CONT_STACK : uint8_t
+{
+ FOREACH,
+ FOR,
+ PROC,
+};
+
+namespace e
+{
+enum class INVOCATION_FLAG : uint8_t
+{
+ ZERO = 0,
+
+ // Bound directly to the caster (i.e., ignore its location)
+ BOUND = 1 << 0,
+ // Used `abort' to terminate
+ ABORTED = 1 << 1,
+ // On magical attacks: if we run out of steam, stop attacking altogether
+ STOPATTACK = 1 << 2,
+};
+ENUM_BITWISE_OPERATORS(INVOCATION_FLAG)
+}
+using e::INVOCATION_FLAG;
+
+#endif // MAGIC_INTERPRETER_T_HPP
diff --git a/src/map/magic-stmt.cpp b/src/map/magic-stmt.cpp
index 5dd51d7..f132ca6 100644
--- a/src/map/magic-stmt.cpp
+++ b/src/map/magic-stmt.cpp
@@ -1,282 +1,314 @@
-#include "magic-interpreter.hpp"
+#include <cassert>
+
+#include "../common/cxxstdio.hpp"
+#include "../common/random2.hpp"
+#include "../common/timer.hpp"
+
#include "magic-expr.hpp"
#include "magic-expr-eval.hpp"
+#include "magic-interpreter.hpp"
#include "magic-interpreter-aux.hpp"
-#define INVISIBLE_NPC 127 /* used for local spell effects */
+#include "battle.hpp"
+#include "clif.hpp"
+#include "mob.hpp"
+#include "npc.hpp"
+#include "pc.hpp"
+#include "skill.hpp"
+
+#include "../poison.hpp"
+
+/* used for local spell effects */
+constexpr int INVISIBLE_NPC = 127;
//#define DEBUG
#ifdef DEBUG
-static void print_val (val_t * v)
+static
+void print_val(val_t *v)
{
switch (v->ty)
{
- case TY_UNDEF:
- fprintf (stderr, "UNDEF");
+ case TYPE::UNDEF:
+ FPRINTF(stderr, "UNDEF");
break;
- case TY_INT:
- fprintf (stderr, "%d", v->v.v_int);
+ case TYPE::INT:
+ FPRINTF(stderr, "%d", v->v.v_int);
break;
- case TY_DIR:
- fprintf (stderr, "dir%d", v->v.v_int);
+ case TYPE::DIR:
+ FPRINTF(stderr, "dir%d", v->v.v_int);
break;
- case TY_STRING:
- fprintf (stderr, "`%s'", v->v.v_string);
+ case TYPE::STRING:
+ FPRINTF(stderr, "`%s'", v->v.v_string);
break;
default:
- fprintf (stderr, "ty%d", v->ty);
+ FPRINTF(stderr, "ty%d", v->ty);
break;
}
}
-static void dump_env (env_t * env)
+static
+void dump_env(env_t *env)
{
- int i;
+ int i;
for (i = 0; i < env->base_env->vars_nr; i++)
{
val_t *v = &env->vars[i];
val_t *bv = &env->base_env->vars[i];
- fprintf (stderr, "%02x %30s ", i, env->base_env->var_name[i]);
- print_val (v);
- fprintf (stderr, "\t(");
- print_val (bv);
- fprintf (stderr, ")\n");
+ FPRINTF(stderr, "%02x %30s ", i, env->base_env->var_name[i]);
+ print_val(v);
+ FPRINTF(stderr, "\t(");
+ print_val(bv);
+ FPRINTF(stderr, ")\n");
}
}
#endif
-static void clear_activation_record (cont_activation_record_t * ar)
+static
+void clear_activation_record(cont_activation_record_t *ar)
{
switch (ar->ty)
{
- case CONT_STACK_FOREACH:
- free (ar->c.c_foreach.entities);
+ case CONT_STACK::FOREACH:
+ free(ar->c.c_foreach.entities);
break;
- case CONT_STACK_PROC:
- free (ar->c.c_proc.old_actuals);
+ case CONT_STACK::PROC:
+ free(ar->c.c_proc.old_actuals);
break;
}
}
-static void
-invocation_timer_callback (timer_id UNUSED, tick_t UNUSED, custom_id_t id, custom_data_t data)
+static
+void invocation_timer_callback(TimerData *, tick_t, int id)
{
- invocation_t *invocation = (invocation_t *) map_id2bl (id);
+ invocation_t *invocation = (invocation_t *) map_id2bl(id);
- if (invocation)
+ assert (invocation != NULL);
{
- invocation->timer = 0;
- spell_execute (invocation);
+ spell_execute(invocation);
}
}
-static void clear_stack (invocation_t * invocation)
+static
+void clear_stack(invocation_t *invocation)
{
- int i;
+ int i;
for (i = 0; i < invocation->stack_size; i++)
- clear_activation_record (&invocation->stack[i]);
+ clear_activation_record(&invocation->stack[i]);
invocation->stack_size = 0;
}
-void spell_free_invocation (invocation_t * invocation)
+void spell_free_invocation(invocation_t *invocation)
{
if (invocation->status_change_refs)
{
- free (invocation->status_change_refs);
+ free(invocation->status_change_refs);
/* The following cleanup shouldn't be necessary, but I've added it to help tracking a certain bug */
invocation->status_change_refs = NULL;
invocation->status_change_refs_nr = 0;
}
- if (invocation->flags & INVOCATION_FLAG_BOUND)
+ if (bool(invocation->flags & INVOCATION_FLAG::BOUND))
{
- entity_t *e = map_id2bl (invocation->subject);
- if (e && e->type == BL_PC)
- spell_unbind ((character_t *) e, invocation);
+ entity_t *e = map_id2bl(invocation->subject);
+ if (e && e->type == BL::PC)
+ spell_unbind((character_t *) e, invocation);
}
- clear_stack (invocation);
+ clear_stack(invocation);
- if (invocation->timer)
- delete_timer (invocation->timer, invocation_timer_callback);
+ invocation->timer.cancel();
- magic_free_env (invocation->env);
+ magic_free_env(invocation->env);
- map_delblock (&invocation->bl);
- map_delobject (invocation->bl.id, BL_SPELL); // also frees the object
+ map_delblock(&invocation->bl);
+ map_delobject(invocation->bl.id, BL::SPELL); // also frees the object
// free(invocation);
}
-static void
-char_set_weapon_icon (character_t * subject, int count, int icon, int look)
+static
+void char_set_weapon_icon(character_t *subject, int count,
+ StatusChange icon, int look)
{
- const int old_icon = subject->attack_spell_icon_override;
+ const StatusChange old_icon = subject->attack_spell_icon_override;
subject->attack_spell_icon_override = icon;
subject->attack_spell_look_override = look;
- if (old_icon && old_icon != icon)
- clif_status_change (&subject->bl, old_icon, 0);
+ if (old_icon != StatusChange::ZERO && old_icon != icon)
+ clif_status_change(&subject->bl, old_icon, 0);
- clif_fixpcpos (subject);
+ clif_fixpcpos(subject);
if (count)
{
- clif_changelook (&subject->bl, LOOK_WEAPON, look);
- if (icon)
- clif_status_change (&subject->bl, icon, 1);
+ clif_changelook(&subject->bl, LOOK::WEAPON, look);
+ if (icon != StatusChange::ZERO)
+ clif_status_change(&subject->bl, icon, 1);
}
else
{
/* Set it to `normal' */
- clif_changelook (&subject->bl, LOOK_WEAPON, subject->status.weapon);
+ clif_changelook(&subject->bl, LOOK::WEAPON,
+ static_cast<uint16_t>(subject->status.weapon));
}
}
-static void char_set_attack_info (character_t * subject, int speed, int range)
+static
+void char_set_attack_info(character_t *subject, interval_t speed, int range)
{
subject->attack_spell_delay = speed;
subject->attack_spell_range = range;
- if (speed == 0)
+ if (speed == interval_t::zero())
{
- pc_calcstatus (subject, 1);
- clif_updatestatus (subject, SP_ASPD);
- clif_updatestatus (subject, SP_ATTACKRANGE);
+ pc_calcstatus(subject, 1);
+ clif_updatestatus(subject, SP::ASPD);
+ clif_updatestatus(subject, SP::ATTACKRANGE);
}
else
{
subject->aspd = speed;
- clif_updatestatus (subject, SP_ASPD);
- clif_updatestatus (subject, SP_ATTACKRANGE);
+ clif_updatestatus(subject, SP::ASPD);
+ clif_updatestatus(subject, SP::ATTACKRANGE);
}
}
-void magic_stop_completely (character_t * c)
+void magic_stop_completely(character_t *c)
{
- int i;
// Zap all status change references to spells
- for (i = 0; i < MAX_STATUSCHANGE; i++)
+ for (StatusChange i : erange(StatusChange(), StatusChange::MAX_STATUSCHANGE))
c->sc_data[i].spell_invocation = 0;
while (c->active_spells)
- spell_free_invocation (c->active_spells);
+ spell_free_invocation(c->active_spells);
if (c->attack_spell_override)
{
invocation_t *attack_spell =
- (invocation_t *) map_id2bl (c->attack_spell_override);
+ (invocation_t *) map_id2bl(c->attack_spell_override);
if (attack_spell)
- spell_free_invocation (attack_spell);
+ spell_free_invocation(attack_spell);
c->attack_spell_override = 0;
- char_set_weapon_icon (c, 0, 0, 0);
- char_set_attack_info (c, 0, 0);
+ char_set_weapon_icon(c, 0, StatusChange::ZERO, 0);
+ char_set_attack_info(c, interval_t::zero(), 0);
}
}
/* Spell execution has finished normally or we have been notified by a finished skill timer */
-static void try_to_finish_invocation (invocation_t * invocation)
+static
+void try_to_finish_invocation(invocation_t *invocation)
{
if (invocation->status_change_refs_nr == 0 && !invocation->current_effect)
{
if (invocation->end_effect)
{
- clear_stack (invocation);
+ clear_stack(invocation);
invocation->current_effect = invocation->end_effect;
invocation->end_effect = NULL;
- spell_execute (invocation);
+ spell_execute(invocation);
}
else
- spell_free_invocation (invocation);
+ spell_free_invocation(invocation);
}
}
-static int trigger_spell (int subject, int spell)
+static
+int trigger_spell(int subject, int spell)
{
- invocation_t *invocation = (invocation_t *) map_id2bl (spell);
+ invocation_t *invocation = (invocation_t *) map_id2bl(spell);
if (!invocation)
return 0;
- invocation = spell_clone_effect (invocation);
+ invocation = spell_clone_effect(invocation);
- spell_bind ((character_t *) map_id2bl (subject), invocation);
- magic_clear_var (&invocation->env->vars[VAR_CASTER]);
- invocation->env->vars[VAR_CASTER].ty = TY_ENTITY;
+ spell_bind((character_t *) map_id2bl(subject), invocation);
+ magic_clear_var(&invocation->env->vars[VAR_CASTER]);
+ invocation->env->vars[VAR_CASTER].ty = TYPE::ENTITY;
invocation->env->vars[VAR_CASTER].v.v_int = subject;
return invocation->bl.id;
}
-static void entity_warp (entity_t * target, int destm, int destx, int desty);
+static
+void entity_warp(entity_t *target, int destm, int destx, int desty);
-static void char_update (character_t * character)
+static
+void char_update(character_t *character)
{
- entity_warp ((entity_t *) character, character->bl.m, character->bl.x,
+ entity_warp((entity_t *) character, character->bl.m, character->bl.x,
character->bl.y);
}
-static void timer_callback_effect (timer_id UNUSED, tick_t UNUSED, custom_id_t id, custom_data_t data)
+static
+void timer_callback_effect(TimerData *, tick_t, int id, int data)
{
- entity_t *target = map_id2bl (id);
+ entity_t *target = map_id2bl(id);
if (target)
- clif_misceffect (target, data);
+ clif_misceffect(target, data);
}
-static void entity_effect (entity_t * entity, int effect_nr, int delay)
+static
+void entity_effect(entity_t *entity, int effect_nr, interval_t delay)
{
- add_timer (gettick () + delay,
- &timer_callback_effect, entity->id, effect_nr);
+ Timer(gettick() + delay,
+ std::bind(&timer_callback_effect, ph::_1, ph::_2,
+ entity->id, effect_nr)
+ ).detach();
}
-void magic_unshroud (character_t * other_char)
+void magic_unshroud(character_t *other_char)
{
other_char->state.shroud_active = 0;
// Now warp the caster out of and back into here to refresh everyone's display
- char_update (other_char);
- clif_displaymessage (other_char->fd, "Your shroud has been dispelled!");
+ char_update(other_char);
+ clif_displaymessage(other_char->fd, "Your shroud has been dispelled!");
// entity_effect(&other_char->bl, MAGIC_EFFECT_REVEAL);
}
-static void
-timer_callback_effect_npc_delete (timer_id UNUSED, tick_t odelay,
- custom_id_t npc_id, custom_data_t UNUSED)
+static
+void timer_callback_effect_npc_delete(TimerData *, tick_t, int npc_id)
{
- struct npc_data *effect_npc = (struct npc_data *) map_id2bl (npc_id);
- npc_free (effect_npc);
+ struct npc_data *effect_npc = (struct npc_data *) map_id2bl(npc_id);
+ npc_free(effect_npc);
}
-static struct npc_data *local_spell_effect (int m, int x, int y, int effect,
- int tdelay)
+static
+struct npc_data *local_spell_effect(int m, int x, int y, int effect,
+ interval_t tdelay)
{
- int delay = 30000; /* 1 minute should be enough for all interesting spell effects, I hope */
- struct npc_data *effect_npc = npc_spawn_text (m, x, y,
- INVISIBLE_NPC, "", "?");
- int effect_npc_id = effect_npc->bl.id;
-
- entity_effect (&effect_npc->bl, effect, tdelay);
- add_timer (gettick () + delay,
- timer_callback_effect_npc_delete, effect_npc_id, 0);
+ /* 1 minute should be enough for all interesting spell effects, I hope */
+ std::chrono::seconds delay = std::chrono::seconds(30);
+ struct npc_data *effect_npc = npc_spawn_text(m, x, y,
+ INVISIBLE_NPC, "", "?");
+ int effect_npc_id = effect_npc->bl.id;
+
+ entity_effect(&effect_npc->bl, effect, tdelay);
+ Timer(gettick() + delay,
+ std::bind(timer_callback_effect_npc_delete, ph::_1, ph::_2,
+ effect_npc_id)
+ ).detach();
return effect_npc;
}
-static int op_sfx (env_t * env, int args_nr, val_t * args)
+static
+int op_sfx(env_t *, int, val_t *args)
{
- int delay = ARGINT (2);
+ interval_t delay = static_cast<interval_t>(ARGINT(2));
- if (TY (0) == TY_ENTITY)
+ if (ARG_TYPE(0) == TYPE::ENTITY)
{
- entity_effect (ARGENTITY (0), ARGINT (1), delay);
+ entity_effect(ARGENTITY(0), ARGINT(1), delay);
}
- else if (TY (0) == TY_LOCATION)
+ else if (ARG_TYPE(0) == TYPE::LOCATION)
{
- local_spell_effect (ARGLOCATION (0).m,
- ARGLOCATION (0).x,
- ARGLOCATION (0).y, ARGINT (1), delay);
+ local_spell_effect(ARGLOCATION(0).m,
+ ARGLOCATION(0).x,
+ ARGLOCATION(0).y, ARGINT(1), delay);
}
else
return 1;
@@ -284,192 +316,213 @@ static int op_sfx (env_t * env, int args_nr, val_t * args)
return 0;
}
-static int op_instaheal (env_t * env, int args_nr, val_t * args)
+static
+int op_instaheal(env_t *env, int, val_t *args)
{
- entity_t *caster = (VAR (VAR_CASTER).ty == TY_ENTITY)
- ? map_id2bl (VAR (VAR_CASTER).v.v_int) : NULL;
- entity_t *subject = ARGENTITY (0);
+ entity_t *caster = (VAR(VAR_CASTER).ty == TYPE::ENTITY)
+ ? map_id2bl(VAR(VAR_CASTER).v.v_int) : NULL;
+ entity_t *subject = ARGENTITY(0);
if (!caster)
caster = subject;
- if (caster->type == BL_PC && subject->type == BL_PC)
+ if (caster->type == BL::PC && subject->type == BL::PC)
{
character_t *caster_pc = (character_t *) caster;
character_t *subject_pc = (character_t *) subject;
- MAP_LOG_PC (caster_pc, "SPELLHEAL-INSTA PC%d FOR %d",
- subject_pc->status.char_id, ARGINT (1));
+ MAP_LOG_PC(caster_pc, "SPELLHEAL-INSTA PC%d FOR %d",
+ subject_pc->status.char_id, ARGINT(1));
}
- battle_heal (caster, subject, ARGINT (1), ARGINT (2), 0);
+ battle_heal(caster, subject, ARGINT(1), ARGINT(2), 0);
return 0;
}
-static int op_itemheal (env_t * env, int args_nr, val_t * args)
+static
+int op_itemheal(env_t *env, int args_nr, val_t *args)
{
- entity_t *subject = ARGENTITY (0);
- if (subject->type == BL_PC)
+ entity_t *subject = ARGENTITY(0);
+ if (subject->type == BL::PC)
{
- pc_itemheal ((struct map_session_data *) subject,
- ARGINT (1), ARGINT (2));
+ pc_itemheal((struct map_session_data *) subject,
+ ARGINT(1), ARGINT(2));
}
else
- return op_instaheal (env, args_nr, args);
+ return op_instaheal(env, args_nr, args);
return 0;
}
-#define SHROUD_HIDE_NAME_TALKING_FLAG (1 << 0)
-#define SHROUD_DISAPPEAR_ON_PICKUP_FLAG (1 << 1)
-#define SHROUD_DISAPPEAR_ON_TALK_FLAG (1 << 2)
+namespace e
+{
+enum class Shroud
+{
+ HIDE_NAME_TALKING_FLAG = 1 << 0,
+ DISAPPEAR_ON_PICKUP_FLAG = 1 << 1,
+ DISAPPEAR_ON_TALK_FLAG = 1 << 2,
+};
+ENUM_BITWISE_OPERATORS(Shroud)
+}
+using e::Shroud;
-#define ARGCHAR(n) (ARGENTITY(n)->type == BL_PC) ? (character_t *)(ARGENTITY(n)) : NULL
+// differs from ARGPC by checking
+#define ARGCHAR(n) (ARGENTITY(n)->type == BL::PC) ? (character_t *)(ARGENTITY(n)) : NULL
-static int op_shroud (env_t * env, int args_nr, val_t * args)
+static
+int op_shroud(env_t *, int, val_t *args)
{
- character_t *subject = ARGCHAR (0);
- int arg = ARGINT (1);
+ character_t *subject = ARGCHAR(0);
+ Shroud arg = static_cast<Shroud>(ARGINT(1));
if (!subject)
return 0;
subject->state.shroud_active = 1;
subject->state.shroud_hides_name_talking =
- (arg & SHROUD_HIDE_NAME_TALKING_FLAG) != 0;
+ bool(arg & Shroud::HIDE_NAME_TALKING_FLAG);
subject->state.shroud_disappears_on_pickup =
- (arg & SHROUD_DISAPPEAR_ON_PICKUP_FLAG) != 0;
+ bool(arg & Shroud::DISAPPEAR_ON_PICKUP_FLAG);
subject->state.shroud_disappears_on_talk =
- (arg & SHROUD_DISAPPEAR_ON_TALK_FLAG) != 0;
+ bool(arg & Shroud::DISAPPEAR_ON_TALK_FLAG);
return 0;
}
-static int op_reveal (env_t * env, int args_nr, val_t * args)
+static
+int op_reveal(env_t *, int, val_t *args)
{
- character_t *subject = ARGCHAR (0);
+ character_t *subject = ARGCHAR(0);
if (subject && subject->state.shroud_active)
- magic_unshroud (subject);
+ magic_unshroud(subject);
return 0;
}
-static int op_message (env_t * env, int args_nr, val_t * args)
+static
+int op_message(env_t *, int, val_t *args)
{
- character_t *subject = ARGCHAR (0);
+ character_t *subject = ARGCHAR(0);
if (subject)
- clif_displaymessage (subject->fd, ARGSTR (1));
+ clif_displaymessage(subject->fd, ARGSTR(1));
return 0;
}
-static void
-timer_callback_kill_npc (timer_id UNUSED, tick_t odelay, custom_id_t npc_id,
- custom_data_t data)
+static
+void timer_callback_kill_npc(TimerData *, tick_t, int npc_id)
{
- struct npc_data *npc = (struct npc_data *) map_id2bl (npc_id);
+ struct npc_data *npc = (struct npc_data *) map_id2bl(npc_id);
if (npc)
- npc_free (npc);
+ npc_free(npc);
}
-static int op_messenger_npc (env_t * env, int args_nr, val_t * args)
+static
+int op_messenger_npc(env_t *, int, val_t *args)
{
struct npc_data *npc;
- location_t *loc = &ARGLOCATION (0);
+ location_t *loc = &ARGLOCATION(0);
- npc = npc_spawn_text (loc->m, loc->x, loc->y,
- ARGINT (1), ARGSTR (2), ARGSTR (3));
+ npc = npc_spawn_text(loc->m, loc->x, loc->y,
+ ARGINT(1), ARGSTR(2), ARGSTR(3));
- add_timer (gettick () + ARGINT (4),
- &timer_callback_kill_npc, npc->bl.id, 0);
+ Timer(gettick() + static_cast<interval_t>(ARGINT(4)),
+ std::bind(timer_callback_kill_npc, ph::_1, ph::_2,
+ npc->bl.id)
+ ).detach();
return 0;
}
-static void entity_warp (entity_t * target, int destm, int destx, int desty)
+static
+void entity_warp(entity_t *target, int destm, int destx, int desty)
{
- if (target->type == BL_PC || target->type == BL_MOB)
+ if (target->type == BL::PC || target->type == BL::MOB)
{
switch (target->type)
{
- case BL_PC:
+ case BL::PC:
{
character_t *character = (character_t *) target;
char *map_name;
- clif_clearchar_area (&character->bl, 3);
- map_delblock (&character->bl);
+ clif_clearchar(&character->bl, BeingRemoveWhy::WARPED);
+ map_delblock(&character->bl);
character->bl.x = destx;
character->bl.y = desty;
character->bl.m = destm;
- pc_touch_all_relevant_npcs (character);
+ pc_touch_all_relevant_npcs(character);
// Note that touching NPCs may have triggered warping and thereby updated x and y:
map_name = map[character->bl.m].name;
// Warp part #1: update relevant data, interrupt trading etc.:
- pc_setpos (character, map_name, character->bl.x, character->bl.y, 0);
+ pc_setpos(character, map_name, character->bl.x, character->bl.y, BeingRemoveWhy::GONE);
// Warp part #2: now notify the client
- clif_changemap (character, map_name,
+ clif_changemap(character, map_name,
character->bl.x, character->bl.y);
break;
}
- case BL_MOB:
+ case BL::MOB:
target->x = destx;
target->y = desty;
target->m = destm;
- clif_fixmobpos ((struct mob_data *) target);
+ clif_fixmobpos((struct mob_data *) target);
break;
}
}
}
-static int op_move (env_t * env, int args_nr, val_t * args)
+static
+int op_move(env_t *, int, val_t *args)
{
- entity_t *subject = ARGENTITY (0);
- int dir = ARGDIR (1);
+ entity_t *subject = ARGENTITY(0);
+ DIR dir = ARGDIR(1);
- int newx = subject->x + heading_x[dir];
- int newy = subject->y + heading_y[dir];
+ int newx = subject->x + dirx[dir];
+ int newy = subject->y + diry[dir];
- if (!map_is_solid (subject->m, newx, newy))
- entity_warp (subject, subject->m, newx, newy);
+ if (!bool(map_getcell(subject->m, newx, newy) & MapCell::UNWALKABLE))
+ entity_warp(subject, subject->m, newx, newy);
return 0;
}
-static int op_warp (env_t * env, int args_nr, val_t * args)
+static
+int op_warp(env_t *, int, val_t *args)
{
- entity_t *subject = ARGENTITY (0);
- location_t *loc = &ARGLOCATION (1);
+ entity_t *subject = ARGENTITY(0);
+ location_t *loc = &ARGLOCATION(1);
- entity_warp (subject, loc->m, loc->x, loc->y);
+ entity_warp(subject, loc->m, loc->x, loc->y);
return 0;
}
-static int op_banish (env_t * env, int args_nr, val_t * args)
+static
+int op_banish(env_t *, int, val_t *args)
{
- entity_t *subject = ARGENTITY (0);
+ entity_t *subject = ARGENTITY(0);
- if (subject->type == BL_MOB)
+ if (subject->type == BL::MOB)
{
struct mob_data *mob = (struct mob_data *) subject;
- if (mob->mode & MOB_MODE_SUMMONED)
- mob_catch_delete (mob, 3);
+ if (bool(mob->mode & MobMode::SUMMONED))
+ mob_catch_delete(mob, BeingRemoveWhy::WARPED);
}
return 0;
}
-static void
-record_status_change (invocation_t * invocation, int bl_id, int sc_id)
+static
+void record_status_change(invocation_t *invocation, int bl_id,
+ StatusChange sc_id)
{
- int index = invocation->status_change_refs_nr++;
+ int index = invocation->status_change_refs_nr++;
status_change_ref_t *cr;
- RECREATE (invocation->status_change_refs, status_change_ref_t, invocation->status_change_refs_nr);
+ RECREATE(invocation->status_change_refs, status_change_ref_t, invocation->status_change_refs_nr);
cr = &invocation->status_change_refs[index];
@@ -477,44 +530,51 @@ record_status_change (invocation_t * invocation, int bl_id, int sc_id)
cr->bl_id = bl_id;
}
-static int op_status_change (env_t * env, int args_nr, val_t * args)
+static
+int op_status_change(env_t *env, int, val_t *args)
{
- entity_t *subject = ARGENTITY (0);
- int invocation_id = VAR (VAR_INVOCATION).ty == TY_INVOCATION
- ? VAR (VAR_INVOCATION).v.v_int : 0;
- invocation_t *invocation = (invocation_t *) map_id2bl (invocation_id);
+ entity_t *subject = ARGENTITY(0);
+ int invocation_id = VAR(VAR_INVOCATION).ty == TYPE::INVOCATION
+ ? VAR(VAR_INVOCATION).v.v_int : 0;
+ invocation_t *invocation = (invocation_t *) map_id2bl(invocation_id);
- skill_status_effect (subject, ARGINT (1), ARGINT (2), ARGINT (3),
- ARGINT (4), ARGINT (5), ARGINT (6), 0,
- invocation_id);
+ assert (!ARGINT(3));
+ assert (!ARGINT(4));
+ assert (!ARGINT(5));
+ skill_status_effect(subject, static_cast<StatusChange>(ARGINT(1)),
+ ARGINT(2),
+ static_cast<interval_t>(ARGINT(6)), invocation_id);
- if (invocation && subject->type == BL_PC)
- record_status_change (invocation, subject->id, ARGINT (1));
+ if (invocation && subject->type == BL::PC)
+ record_status_change(invocation, subject->id, StatusChange(ARGINT(1)));
return 0;
}
-static int op_stop_status_change (env_t * env, int args_nr, val_t * args)
+static
+int op_stop_status_change(env_t *, int, val_t *args)
{
- entity_t *subject = ARGENTITY (0);
+ entity_t *subject = ARGENTITY(0);
- skill_status_change_end (subject, ARGINT (1), -1);
+ StatusChange sc = static_cast<StatusChange>(ARGINT(1));
+ skill_status_change_end(subject, sc, nullptr);
return 0;
}
-static int op_override_attack (env_t * env, int args_nr, val_t * args)
+static
+int op_override_attack(env_t *env, int, val_t *args)
{
- entity_t *psubject = ARGENTITY (0);
- int charges = ARGINT (1);
- int attack_delay = ARGINT (2);
- int attack_range = ARGINT (3);
- int icon = ARGINT (4);
- int look = ARGINT (5);
- int stopattack = ARGINT (6);
+ entity_t *psubject = ARGENTITY(0);
+ int charges = ARGINT(1);
+ interval_t attack_delay = static_cast<interval_t>(ARGINT(2));
+ int attack_range = ARGINT(3);
+ StatusChange icon = StatusChange(ARGINT(4));
+ int look = ARGINT(5);
+ int stopattack = ARGINT(6);
character_t *subject;
- if (psubject->type != BL_PC)
+ if (psubject->type != BL::PC)
return 0;
subject = (character_t *) psubject;
@@ -522,76 +582,86 @@ static int op_override_attack (env_t * env, int args_nr, val_t * args)
if (subject->attack_spell_override)
{
invocation_t *old_invocation =
- (invocation_t *) map_id2bl (subject->attack_spell_override);
+ (invocation_t *) map_id2bl(subject->attack_spell_override);
if (old_invocation)
- spell_free_invocation (old_invocation);
+ spell_free_invocation(old_invocation);
}
subject->attack_spell_override =
- trigger_spell (subject->bl.id, VAR (VAR_INVOCATION).v.v_int);
+ trigger_spell(subject->bl.id, VAR(VAR_INVOCATION).v.v_int);
subject->attack_spell_charges = charges;
if (subject->attack_spell_override)
{
invocation_t *attack_spell =
- (invocation_t *) map_id2bl (subject->attack_spell_override);
+ (invocation_t *) map_id2bl(subject->attack_spell_override);
if (attack_spell && stopattack)
- attack_spell->flags |= INVOCATION_FLAG_STOPATTACK;
+ attack_spell->flags |= INVOCATION_FLAG::STOPATTACK;
- char_set_weapon_icon (subject, charges, icon, look);
- char_set_attack_info (subject, attack_delay, attack_range);
+ char_set_weapon_icon(subject, charges, icon, look);
+ char_set_attack_info(subject, attack_delay, attack_range);
}
return 0;
}
-static int op_create_item (env_t * env, int args_nr, val_t * args)
+static
+int op_create_item(env_t *, int, val_t *args)
{
struct item item;
- entity_t *entity = ARGENTITY (0);
+ entity_t *entity = ARGENTITY(0);
character_t *subject;
- int stackable;
- int count = ARGINT (2);
+ int stackable;
+ int count = ARGINT(2);
if (count <= 0)
return 0;
- if (entity->type == BL_PC)
+ if (entity->type == BL::PC)
subject = (character_t *) entity;
else
return 0;
- GET_ARG_ITEM (1, item, stackable);
+ GET_ARG_ITEM(1, item, stackable);
if (!stackable)
while (count--)
- pc_additem (subject, &item, 1);
+ pc_additem(subject, &item, 1);
else
- pc_additem (subject, &item, count);
+ pc_additem(subject, &item, count);
return 0;
}
-#define AGGRAVATION_MODE_ATTACKS_CASTER(n) ((n) == 0 || (n) == 2)
-#define AGGRAVATION_MODE_MAKES_AGGRESSIVE(n) ((n) > 0)
+inline
+bool AGGRAVATION_MODE_ATTACKS_CASTER(int n)
+{
+ return n == 0 || n == 2;
+}
+inline
+bool AGGRAVATION_MODE_MAKES_AGGRESSIVE(int n)
+{
+ return n > 0;
+}
-static int op_aggravate (env_t * env, int args_nr, val_t * args)
+static
+int op_aggravate(env_t *, int, val_t *args)
{
- entity_t *victim = ARGENTITY (2);
- int mode = ARGINT (1);
- entity_t *target = ARGENTITY (0);
+ entity_t *victim = ARGENTITY(2);
+ int mode = ARGINT(1);
+ entity_t *target = ARGENTITY(0);
struct mob_data *other;
- if (target->type == BL_MOB)
+ if (target->type == BL::MOB)
other = (struct mob_data *) target;
else
return 0;
- mob_target (other, victim, battle_get_range (victim));
+ mob_target(other, victim, battle_get_range(victim));
- if (AGGRAVATION_MODE_MAKES_AGGRESSIVE (mode))
- other->mode = 0x85 | (other->mode & MOB_SENSIBLE_MASK); /* war */
+ if (AGGRAVATION_MODE_MAKES_AGGRESSIVE(mode))
+ other->mode = MobMode::war | (other->mode & MobMode::SENSIBLE_MASK);
- if (AGGRAVATION_MODE_ATTACKS_CASTER (mode))
+ if (AGGRAVATION_MODE_ATTACKS_CASTER(mode))
{
other->target_id = victim->id;
other->attacked_id = victim->id;
@@ -600,37 +670,42 @@ static int op_aggravate (env_t * env, int args_nr, val_t * args)
return 0;
}
-#define MONSTER_ATTITUDE_HOSTILE 0
-#define MONSTER_ATTITUDE_FRIENDLY 1
-#define MONSTER_ATTITUDE_SERVANT 2
-#define MONSTER_ATTITUDE_FROZEN 3
-
-static int op_spawn (env_t * env, int args_nr, val_t * args)
+enum class MonsterAttitude
{
- area_t *area = ARGAREA (0);
- entity_t *owner_e = ARGENTITY (1);
- int monster_id = ARGINT (2);
- int monster_attitude = ARGINT (3);
- int monster_count = ARGINT (4);
- int monster_lifetime = ARGINT (5);
- int i;
+ HOSTILE = 0,
+ FRIENDLY = 1,
+ SERVANT = 2,
+ FROZEN = 3,
+};
- character_t *owner = (monster_attitude == MONSTER_ATTITUDE_SERVANT
- && owner_e->type ==
- BL_PC) ? (character_t *) owner_e : NULL;
+static
+int op_spawn(env_t *, int, val_t *args)
+{
+ area_t *area = ARGAREA(0);
+ entity_t *owner_e = ARGENTITY(1);
+ int monster_id = ARGINT(2);
+ MonsterAttitude monster_attitude = static_cast<MonsterAttitude>(ARGINT(3));
+ int monster_count = ARGINT(4);
+ interval_t monster_lifetime = static_cast<interval_t>(ARGINT(5));
+ int i;
+
+ character_t *owner = NULL;
+ if (monster_attitude == MonsterAttitude::SERVANT
+ && owner_e->type == BL::PC)
+ owner = (character_t *) owner_e;
for (i = 0; i < monster_count; i++)
{
location_t loc;
- magic_random_location (&loc, area);
+ magic_random_location(&loc, area);
- int mob_id;
+ int mob_id;
struct mob_data *mob;
- mob_id = mob_once_spawn (owner, map[loc.m].name, loc.x, loc.y, "--ja--", // Is that needed?
+ mob_id = mob_once_spawn(owner, map[loc.m].name, loc.x, loc.y, "--ja--", // Is that needed?
monster_id, 1, "");
- mob = (struct mob_data *) map_id2bl (mob_id);
+ mob = (struct mob_data *) map_id2bl(mob_id);
if (mob)
{
@@ -638,18 +713,17 @@ static int op_spawn (env_t * env, int args_nr, val_t * args)
switch (monster_attitude)
{
-
- case MONSTER_ATTITUDE_SERVANT:
+ case MonsterAttitude::SERVANT:
mob->state.special_mob_ai = 1;
- mob->mode |= 0x04;
+ mob->mode |= MobMode::AGGRESSIVE;
break;
- case MONSTER_ATTITUDE_FRIENDLY:
- mob->mode = 0x80 | (mob->mode & 1);
+ case MonsterAttitude::FRIENDLY:
+ mob->mode = MobMode::CAN_ATTACK | (mob->mode & MobMode::CAN_MOVE);
break;
- case MONSTER_ATTITUDE_HOSTILE:
- mob->mode = 0x84 | (mob->mode & 1);
+ case MonsterAttitude::HOSTILE:
+ mob->mode = MobMode::CAN_ATTACK | MobMode::AGGRESSIVE | (mob->mode & MobMode::CAN_MOVE);
if (owner)
{
mob->target_id = owner->bl.id;
@@ -657,16 +731,17 @@ static int op_spawn (env_t * env, int args_nr, val_t * args)
}
break;
- case MONSTER_ATTITUDE_FROZEN:
- mob->mode = 0;
+ case MonsterAttitude::FROZEN:
+ mob->mode = MobMode::ZERO;
break;
}
mob->mode |=
- MOB_MODE_SUMMONED | MOB_MODE_TURNS_AGAINST_BAD_MASTER;
+ MobMode::SUMMONED | MobMode::TURNS_AGAINST_BAD_MASTER;
- mob->deletetimer = add_timer (gettick () + monster_lifetime,
- mob_timer_delete, mob_id, 0);
+ mob->deletetimer = Timer(gettick() + monster_lifetime,
+ std::bind(mob_timer_delete, ph::_1, ph::_2,
+ mob_id));
if (owner)
{
@@ -680,13 +755,13 @@ static int op_spawn (env_t * env, int args_nr, val_t * args)
}
static
-const char *get_invocation_name (env_t * env)
+const char *get_invocation_name(env_t *env)
{
invocation_t *invocation;
- if (VAR (VAR_INVOCATION).ty != TY_INVOCATION)
+ if (VAR(VAR_INVOCATION).ty != TYPE::INVOCATION)
return "?";
- invocation = (invocation_t *) map_id2bl (VAR (VAR_INVOCATION).v.v_int);
+ invocation = (invocation_t *) map_id2bl(VAR(VAR_INVOCATION).v.v_int);
if (invocation)
return invocation->spell->name;
@@ -694,16 +769,17 @@ const char *get_invocation_name (env_t * env)
return "??";
}
-static int op_injure (env_t * env, int args_nr, val_t * args)
+static
+int op_injure(env_t *env, int, val_t *args)
{
- entity_t *caster = ARGENTITY (0);
- entity_t *target = ARGENTITY (1);
- int damage_caused = ARGINT (2);
- int mp_damage = ARGINT (3);
- int target_hp = battle_get_hp (target);
- int mdef = battle_get_mdef (target);
-
- if (target->type == BL_PC && !map[target->m].flag.pvp && !((character_t *) target)->special_state.killable && (caster->type != BL_PC || !((character_t *) caster)->special_state.killer))
+ entity_t *caster = ARGENTITY(0);
+ entity_t *target = ARGENTITY(1);
+ int damage_caused = ARGINT(2);
+ int mp_damage = ARGINT(3);
+ int target_hp = battle_get_hp(target);
+ int mdef = battle_get_mdef(target);
+
+ if (target->type == BL::PC && !map[target->m].flag.pvp && !((character_t *) target)->special_state.killable && (caster->type != BL::PC || !((character_t *) caster)->special_state.killer))
return 0; /* Cannot damage other players outside of pvp */
if (target != caster)
@@ -719,107 +795,117 @@ static int op_injure (env_t * env, int args_nr, val_t * args)
damage_caused = 0;
// display damage first, because dealing damage may deallocate the target.
- clif_damage (caster, target, gettick (), 0, 0, damage_caused, 0, 0, 0);
+ clif_damage(caster, target,
+ gettick(), interval_t::zero(), interval_t::zero(),
+ damage_caused, 0, DamageType::NORMAL, 0);
- if (caster->type == BL_PC)
+ if (caster->type == BL::PC)
{
character_t *caster_pc = (character_t *) caster;
- if (target->type == BL_MOB)
+ if (target->type == BL::MOB)
{
struct mob_data *mob = (struct mob_data *) target;
- MAP_LOG_PC (caster_pc, "SPELLDMG MOB%d %d FOR %d BY %s",
+ MAP_LOG_PC(caster_pc, "SPELLDMG MOB%d %d FOR %d BY %s",
mob->bl.id, mob->mob_class, damage_caused,
- get_invocation_name (env));
+ get_invocation_name(env));
}
}
- battle_damage (caster, target, damage_caused, mp_damage);
+ battle_damage(caster, target, damage_caused, mp_damage);
return 0;
}
-static int op_emote (env_t * env, int args_nr, val_t * args)
+static
+int op_emote(env_t *, int, val_t *args)
{
- entity_t *victim = ARGENTITY (0);
- int emotion = ARGINT (1);
- clif_emotion (victim, emotion);
+ entity_t *victim = ARGENTITY(0);
+ int emotion = ARGINT(1);
+ clif_emotion(victim, emotion);
return 0;
}
-static int op_set_script_variable (env_t * env, int args_nr, val_t * args)
+static
+int op_set_script_variable(env_t *, int, val_t *args)
{
- character_t *c = (ETY (0) == BL_PC) ? ARGPC (0) : NULL;
+ character_t *c = (ENTITY_TYPE(0) == BL::PC) ? ARGPC(0) : NULL;
if (!c)
return 1;
- pc_setglobalreg (c, ARGSTR (1), ARGINT (2));
+ pc_setglobalreg(c, ARGSTR(1), ARGINT(2));
return 0;
}
-static int op_set_hair_colour (env_t * env, int args_nr, val_t * args)
+static
+int op_set_hair_colour(env_t *, int, val_t *args)
{
- character_t *c = (ETY (0) == BL_PC) ? ARGPC (0) : NULL;
+ character_t *c = (ENTITY_TYPE(0) == BL::PC) ? ARGPC(0) : NULL;
if (!c)
return 1;
- pc_changelook (c, LOOK_HAIR_COLOR, ARGINT (1));
+ pc_changelook(c, LOOK::HAIR_COLOR, ARGINT(1));
return 0;
}
-static int op_set_hair_style (env_t * env, int args_nr, val_t * args)
+static
+int op_set_hair_style(env_t *, int, val_t *args)
{
- character_t *c = (ETY (0) == BL_PC) ? ARGPC (0) : NULL;
+ character_t *c = (ENTITY_TYPE(0) == BL::PC) ? ARGPC(0) : NULL;
if (!c)
return 1;
- pc_changelook (c, LOOK_HAIR, ARGINT (1));
+ pc_changelook(c, LOOK::HAIR, ARGINT(1));
return 0;
}
-static int op_drop_item_for (env_t * env, int args_nr, val_t * args)
+static
+int op_drop_item_for (env_t *, int args_nr, val_t *args)
{
struct item item;
- int stackable;
- location_t *loc = &ARGLOCATION (0);
- int count = ARGINT (2);
- int time = ARGINT (3);
- character_t *c = ((args_nr > 4) && (ETY (4) == BL_PC)) ? ARGPC (4) : NULL;
- int delay = (args_nr > 5) ? ARGINT (5) : 0;
- int delaytime[3] = { delay, delay, delay };
+ int stackable;
+ location_t *loc = &ARGLOCATION(0);
+ int count = ARGINT(2);
+ interval_t interval = static_cast<interval_t>(ARGINT(3));
+ character_t *c = ((args_nr > 4) && (ENTITY_TYPE(4) == BL::PC)) ? ARGPC(4) : NULL;
+ interval_t delay = (args_nr > 5) ? static_cast<interval_t>(ARGINT(5)) : interval_t::zero();
+ interval_t delaytime[3] = { delay, delay, delay };
character_t *owners[3] = { c, NULL, NULL };
- GET_ARG_ITEM (1, item, stackable);
+ GET_ARG_ITEM(1, item, stackable);
if (stackable)
- map_addflooritem_any (&item, count, loc->m, loc->x, loc->y,
- owners, delaytime, time, 0);
+ map_addflooritem_any(&item, count, loc->m, loc->x, loc->y,
+ owners, delaytime, interval, 0);
else
while (count-- > 0)
- map_addflooritem_any (&item, 1, loc->m, loc->x, loc->y,
- owners, delaytime, time, 0);
+ map_addflooritem_any(&item, 1, loc->m, loc->x, loc->y,
+ owners, delaytime, interval, 0);
return 0;
}
-static int op_gain_exp (env_t * env, int args_nr, val_t * args)
+static
+int op_gain_exp(env_t *, int, val_t *args)
{
- character_t *c = (ETY (0) == BL_PC) ? ARGPC (0) : NULL;
+ character_t *c = (ENTITY_TYPE(0) == BL::PC) ? ARGPC(0) : NULL;
if (!c)
return 1;
- pc_gainexp_reason (c, ARGINT (1), ARGINT (2), ARGINT (3));
+ pc_gainexp_reason(c, ARGINT(1), ARGINT(2),
+ PC_GAINEXP_REASON(ARGINT(3)));
return 0;
}
-static op_t operations[] = {
+static
+op_t operations[] = {
{"sfx", ".ii", op_sfx},
{"instaheal", "eii", op_instaheal},
{"itemheal", "eii", op_itemheal},
@@ -847,16 +933,18 @@ static op_t operations[] = {
{NULL, NULL, NULL}
};
-static int operations_sorted = 0;
-static int operation_count;
+static
+int operations_sorted = 0;
+static
+int operation_count;
static
-int compare_operations (const void *lhs, const void *rhs)
+int compare_operations(const void *lhs, const void *rhs)
{
- return strcmp (((op_t *) lhs)->name, ((op_t *) rhs)->name);
+ return strcmp(((const op_t *) lhs)->name, ((const op_t *) rhs)->name);
}
-op_t *magic_get_op (char *name, int *index)
+op_t *magic_get_op(char *name, int *index)
{
op_t key;
@@ -869,13 +957,13 @@ op_t *magic_get_op (char *name, int *index)
operation_count = opc - operations;
- qsort (operations, operation_count, sizeof (op_t),
+ qsort(operations, operation_count, sizeof(op_t),
compare_operations);
operations_sorted = 1;
}
key.name = name;
- op_t *op = (op_t *)bsearch (&key, operations, operation_count, sizeof (op_t),
+ op_t *op = (op_t *)bsearch(&key, operations, operation_count, sizeof(op_t),
compare_operations);
if (op && index)
@@ -884,15 +972,14 @@ op_t *magic_get_op (char *name, int *index)
return op;
}
-void
-spell_effect_report_termination (int invocation_id, int bl_id, int sc_id,
- int supplanted)
+void spell_effect_report_termination(int invocation_id, int bl_id,
+ StatusChange sc_id, int)
{
- int i;
- int index = -1;
- invocation_t *invocation = (invocation_t *) map_id2bl (invocation_id);
+ int i;
+ int index = -1;
+ invocation_t *invocation = (invocation_t *) map_id2bl(invocation_id);
- if (!invocation || invocation->bl.type != BL_SPELL)
+ if (!invocation || invocation->bl.type != BL::SPELL)
return;
for (i = 0; i < invocation->status_change_refs_nr; i++)
@@ -907,9 +994,9 @@ spell_effect_report_termination (int invocation_id, int bl_id, int sc_id,
if (index == -1)
{
- entity_t *entity = map_id2bl (bl_id);
- if (entity->type == BL_PC)
- fprintf (stderr,
+ entity_t *entity = map_id2bl(bl_id);
+ if (entity->type == BL::PC)
+ FPRINTF(stderr,
"[magic] INTERNAL ERROR: spell-effect-report-termination: tried to terminate on unexpected bl %d, sc %d\n",
bl_id, sc_id);
return;
@@ -922,10 +1009,11 @@ spell_effect_report_termination (int invocation_id, int bl_id, int sc_id,
invocation->
status_change_refs[--invocation->status_change_refs_nr];
- try_to_finish_invocation (invocation);
+ try_to_finish_invocation(invocation);
}
-static effect_t *return_to_stack (invocation_t * invocation)
+static
+effect_t *return_to_stack(invocation_t *invocation)
{
if (!invocation->stack_size)
return NULL;
@@ -936,28 +1024,28 @@ static effect_t *return_to_stack (invocation_t * invocation)
switch (ar->ty)
{
- case CONT_STACK_PROC:
+ case CONT_STACK::PROC:
{
effect_t *ret = ar->return_location;
- int i;
+ int i;
for (i = 0; i < ar->c.c_proc.args_nr; i++)
{
val_t *var =
&invocation->env->vars[ar->c.c_proc.formals[i]];
- magic_clear_var (var);
+ magic_clear_var(var);
*var = ar->c.c_proc.old_actuals[i];
}
- clear_activation_record (ar);
+ clear_activation_record(ar);
--invocation->stack_size;
return ret;
}
- case CONT_STACK_FOREACH:
+ case CONT_STACK::FOREACH:
{
- int entity_id;
+ int entity_id;
val_t *var = &invocation->env->vars[ar->c.c_foreach.id];
do
@@ -965,7 +1053,7 @@ static effect_t *return_to_stack (invocation_t * invocation)
if (ar->c.c_foreach.index >= ar->c.c_foreach.entities_nr)
{
effect_t *ret = ar->return_location;
- clear_activation_record (ar);
+ clear_activation_record(ar);
--invocation->stack_size;
return ret;
}
@@ -973,33 +1061,33 @@ static effect_t *return_to_stack (invocation_t * invocation)
entity_id =
ar->c.c_foreach.entities[ar->c.c_foreach.index++];
}
- while (!entity_id || !map_id2bl (entity_id));
+ while (!entity_id || !map_id2bl(entity_id));
- magic_clear_var (var);
+ magic_clear_var(var);
var->ty = ar->c.c_foreach.ty;
var->v.v_int = entity_id;
return ar->c.c_foreach.body;
}
- case CONT_STACK_FOR:
+ case CONT_STACK::FOR:
if (ar->c.c_for.current > ar->c.c_for.stop)
{
effect_t *ret = ar->return_location;
- clear_activation_record (ar);
+ clear_activation_record(ar);
--invocation->stack_size;
return ret;
}
- magic_clear_var (&invocation->env->vars[ar->c.c_for.id]);
- invocation->env->vars[ar->c.c_for.id].ty = TY_INT;
+ magic_clear_var(&invocation->env->vars[ar->c.c_for.id]);
+ invocation->env->vars[ar->c.c_for.id].ty = TYPE::INT;
invocation->env->vars[ar->c.c_for.id].v.v_int =
ar->c.c_for.current++;
return ar->c.c_for.body;
default:
- fprintf (stderr,
+ FPRINTF(stderr,
"[magic] INTERNAL ERROR: While executing spell `%s': stack corruption\n",
invocation->spell->name);
return NULL;
@@ -1007,15 +1095,15 @@ static effect_t *return_to_stack (invocation_t * invocation)
}
}
-static cont_activation_record_t *add_stack_entry (invocation_t * invocation,
- int ty,
- effect_t * return_location)
+static
+cont_activation_record_t *add_stack_entry(invocation_t *invocation,
+ CONT_STACK ty, effect_t *return_location)
{
cont_activation_record_t *ar =
invocation->stack + invocation->stack_size++;
if (invocation->stack_size >= MAX_STACK_SIZE)
{
- fprintf (stderr,
+ FPRINTF(stderr,
"[magic] Execution stack size exceeded in spell `%s'; truncating effect\n",
invocation->spell->name);
invocation->stack_size--;
@@ -1027,121 +1115,119 @@ static cont_activation_record_t *add_stack_entry (invocation_t * invocation,
return ar;
}
-static int find_entities_in_area_c (entity_t * target, va_list va)
+static
+void find_entities_in_area_c(entity_t *target,
+ int *entities_allocd_p,
+ int *entities_nr_p,
+ int **entities_p,
+ FOREACH_FILTER filter)
{
- int *entities_allocd_p = va_arg (va, int *);
- int *entities_nr_p = va_arg (va, int *);
- int **entities_p = va_arg (va, int **);
- int filter = va_arg (va, int);
-
/* The following macro adds an entity to the result list: */
#define ADD_ENTITY(e) \
if (*entities_nr_p == *entities_allocd_p) { \
/* Need more space */ \
(*entities_allocd_p) += 32; \
- RECREATE (*entities_p, int, *entities_allocd_p); \
+ RECREATE(*entities_p, int, *entities_allocd_p); \
} \
(*entities_p)[(*entities_nr_p)++] = e;
switch (target->type)
{
- case BL_PC:
- if (filter == FOREACH_FILTER_PC
- || filter == FOREACH_FILTER_ENTITY
- || (filter == FOREACH_FILTER_TARGET
+ case BL::PC:
+ if (filter == FOREACH_FILTER::PC
+ || filter == FOREACH_FILTER::ENTITY
+ || (filter == FOREACH_FILTER::TARGET
&& map[target->m].flag.pvp))
break;
- else if (filter == FOREACH_FILTER_SPELL)
+ else if (filter == FOREACH_FILTER::SPELL)
{ /* Check all spells bound to the caster */
invocation_t *invoc = ((character_t *) target)->active_spells;
/* Add all spells locked onto thie PC */
while (invoc)
{
- ADD_ENTITY (invoc->bl.id);
+ ADD_ENTITY(invoc->bl.id);
invoc = invoc->next_invocation;
}
}
- return 0;
+ return;
- case BL_MOB:
- if (filter == FOREACH_FILTER_MOB
- || filter == FOREACH_FILTER_ENTITY
- || filter == FOREACH_FILTER_TARGET)
+ case BL::MOB:
+ if (filter == FOREACH_FILTER::MOB
+ || filter == FOREACH_FILTER::ENTITY
+ || filter == FOREACH_FILTER::TARGET)
break;
else
- return 0;
+ return;
- case BL_SPELL:
- if (filter == FOREACH_FILTER_SPELL)
+ case BL::SPELL:
+ if (filter == FOREACH_FILTER::SPELL)
{
invocation_t *invocation = (invocation_t *) target;
- /* Check whether the spell is `bound'-- if so, we'll consider it iff we see the caster (case BL_PC). */
- if (invocation->flags & INVOCATION_FLAG_BOUND)
- return 0;
+ /* Check whether the spell is `bound'-- if so, we'll consider it iff we see the caster(case BL::PC). */
+ if (bool(invocation->flags & INVOCATION_FLAG::BOUND))
+ return;
else
break; /* Add the spell */
}
else
- return 0;
+ return;
- case BL_NPC:
- if (filter == FOREACH_FILTER_NPC)
+ case BL::NPC:
+ if (filter == FOREACH_FILTER::NPC)
break;
else
- return 0;
+ return;
default:
- return 0;
+ return;
}
- ADD_ENTITY (target->id);
+ ADD_ENTITY(target->id);
#undef ADD_ENTITY
- return 0;
}
-static void
-find_entities_in_area (area_t * area, int *entities_allocd_p,
- int *entities_nr_p, int **entities_p, int filter)
+static
+void find_entities_in_area(area_t *area, int *entities_allocd_p,
+ int *entities_nr_p, int **entities_p, FOREACH_FILTER filter)
{
switch (area->ty)
{
- case AREA_UNION:
- find_entities_in_area (area->a.a_union[0], entities_allocd_p,
+ case AREA::UNION:
+ find_entities_in_area(area->a.a_union[0], entities_allocd_p,
entities_nr_p, entities_p, filter);
- find_entities_in_area (area->a.a_union[1], entities_allocd_p,
+ find_entities_in_area(area->a.a_union[1], entities_allocd_p,
entities_nr_p, entities_p, filter);
break;
default:
{
- int m, x, y, width, height;
- magic_area_rect (&m, &x, &y, &width, &height, area);
- map_foreachinarea (find_entities_in_area_c,
+ int m, x, y, width, height;
+ magic_area_rect(&m, &x, &y, &width, &height, area);
+ map_foreachinarea(std::bind(find_entities_in_area_c, ph::_1, entities_allocd_p, entities_nr_p, entities_p, filter),
m, x, y, x + width, y + height,
- 0 /* filter elsewhere */ ,
- entities_allocd_p, entities_nr_p, entities_p,
- filter);
+ BL::NUL /* filter elsewhere */);
}
}
}
-static effect_t *run_foreach (invocation_t * invocation, effect_t * foreach,
- effect_t * return_location)
+static
+effect_t *run_foreach(invocation_t *invocation, effect_t *foreach,
+ effect_t *return_location)
{
val_t area;
- int filter = foreach->e.e_foreach.filter;
- int id = foreach->e.e_foreach.id;
+ FOREACH_FILTER filter = foreach->e.e_foreach.filter;
+ int id = foreach->e.e_foreach.id;
effect_t *body = foreach->e.e_foreach.body;
- magic_eval (invocation->env, &area, foreach->e.e_foreach.area);
+ magic_eval(invocation->env, &area, foreach->e.e_foreach.area);
- if (area.ty != TY_AREA)
+ if (area.ty != TYPE::AREA)
{
- magic_clear_var (&area);
- fprintf (stderr,
+ magic_clear_var(&area);
+ FPRINTF(stderr,
"[magic] Error in spell `%s': FOREACH loop over non-area\n",
invocation->spell->name);
return return_location;
@@ -1149,38 +1235,20 @@ static effect_t *run_foreach (invocation_t * invocation, effect_t * foreach,
else
{
cont_activation_record_t *ar =
- add_stack_entry (invocation, CONT_STACK_FOREACH, return_location);
- int entities_allocd = 64;
- int *entities_collect;
+ add_stack_entry(invocation, CONT_STACK::FOREACH, return_location);
+ int entities_allocd = 64;
int *entities;
- int *shuffle_board;
- int entities_nr = 0;
- int i;
+ int entities_nr = 0;
if (!ar)
return return_location;
- CREATE (entities_collect, int, entities_allocd);
-
- find_entities_in_area (area.v.v_area, &entities_allocd, &entities_nr,
- &entities_collect, filter);
-
- /* Now shuffle */
- CREATE (shuffle_board, int, entities_nr);
- CREATE (entities, int, entities_nr);
- for (i = 0; i < entities_nr; i++)
- shuffle_board[i] = i;
-
- for (i = entities_nr - 1; i >= 0; i--)
- {
- int random_index = rand () % (i + 1);
- entities[i] = entities_collect[shuffle_board[random_index]];
- shuffle_board[random_index] = shuffle_board[i]; // thus, we are guaranteed only to use unused indices
- }
-
- free (entities_collect);
- free (shuffle_board);
- /* Done shuffling */
+ CREATE(entities, int, entities_allocd);
+ find_entities_in_area(area.v.v_area, &entities_allocd, &entities_nr,
+ &entities, filter);
+ RECREATE(entities, int, entities_nr);
+ // iterator_pair will go away when this gets properly containerized.
+ random_::shuffle(iterator_pair(entities, entities + entities_nr));
ar->c.c_foreach.id = id;
ar->c.c_foreach.body = body;
@@ -1188,36 +1256,37 @@ static effect_t *run_foreach (invocation_t * invocation, effect_t * foreach,
ar->c.c_foreach.entities_nr = entities_nr;
ar->c.c_foreach.entities = entities;
ar->c.c_foreach.ty =
- (filter == FOREACH_FILTER_SPELL) ? TY_INVOCATION : TY_ENTITY;
+ (filter == FOREACH_FILTER::SPELL) ? TYPE::INVOCATION : TYPE::ENTITY;
- magic_clear_var (&area);
+ magic_clear_var(&area);
- return return_to_stack (invocation);
+ return return_to_stack(invocation);
}
}
-static effect_t *run_for (invocation_t * invocation, effect_t * for_,
- effect_t * return_location)
+static
+effect_t *run_for (invocation_t *invocation, effect_t *for_,
+ effect_t *return_location)
{
cont_activation_record_t *ar;
- int id = for_->e.e_for.id;
+ int id = for_->e.e_for.id;
val_t start;
val_t stop;
- magic_eval (invocation->env, &start, for_->e.e_for.start);
- magic_eval (invocation->env, &stop, for_->e.e_for.stop);
+ magic_eval(invocation->env, &start, for_->e.e_for.start);
+ magic_eval(invocation->env, &stop, for_->e.e_for.stop);
- if (start.ty != TY_INT || stop.ty != TY_INT)
+ if (start.ty != TYPE::INT || stop.ty != TYPE::INT)
{
- magic_clear_var (&start);
- magic_clear_var (&stop);
- fprintf (stderr,
+ magic_clear_var(&start);
+ magic_clear_var(&stop);
+ FPRINTF(stderr,
"[magic] Error in spell `%s': FOR loop start or stop point is not an integer\n",
invocation->spell->name);
return return_location;
}
- ar = add_stack_entry (invocation, CONT_STACK_FOR, return_location);
+ ar = add_stack_entry(invocation, CONT_STACK::FOR, return_location);
if (!ar)
return return_location;
@@ -1227,21 +1296,22 @@ static effect_t *run_for (invocation_t * invocation, effect_t * for_,
ar->c.c_for.stop = stop.v.v_int;
ar->c.c_for.body = for_->e.e_for.body;
- return return_to_stack (invocation);
+ return return_to_stack(invocation);
}
-static effect_t *run_call (invocation_t * invocation,
- effect_t * return_location)
+static
+effect_t *run_call(invocation_t *invocation,
+ effect_t *return_location)
{
effect_t *current = invocation->current_effect;
cont_activation_record_t *ar;
- int args_nr = current->e.e_call.args_nr;
+ int args_nr = current->e.e_call.args_nr;
int *formals = current->e.e_call.formals;
val_t *old_actuals;
- CREATE (old_actuals, val_t, args_nr);
- int i;
+ CREATE(old_actuals, val_t, args_nr);
+ int i;
- ar = add_stack_entry (invocation, CONT_STACK_PROC, return_location);
+ ar = add_stack_entry(invocation, CONT_STACK::PROC, return_location);
ar->c.c_proc.args_nr = args_nr;
ar->c.c_proc.formals = formals;
ar->c.c_proc.old_actuals = old_actuals;
@@ -1249,8 +1319,8 @@ static effect_t *run_call (invocation_t * invocation,
{
val_t *env_val = &invocation->env->vars[formals[i]];
val_t result;
- magic_copy_var (&old_actuals[i], env_val);
- magic_eval (invocation->env, &result, current->e.e_call.actuals[i]);
+ magic_copy_var(&old_actuals[i], env_val);
+ magic_eval(invocation->env, &result, current->e.e_call.actuals[i]);
*env_val = result;
}
@@ -1258,67 +1328,68 @@ static effect_t *run_call (invocation_t * invocation,
}
#ifdef DEBUG
-static void print_cfg (int i, effect_t * e)
+static
+void print_cfg(int i, effect_t *e)
{
- int j;
+ int j;
for (j = 0; j < i; j++)
- printf (" ");
+ PRINTF(" ");
- printf ("%p: ", e);
+ PRINTF("%p: ", e);
if (!e)
{
- puts (" -- end --");
+ puts(" -- end --");
return;
}
switch (e->ty)
{
- case EFFECT_SKIP:
- puts ("SKIP");
+ case EFFECT::SKIP:
+ puts("SKIP");
break;
- case EFFECT_END:
- puts ("END");
+ case EFFECT::END:
+ puts("END");
break;
- case EFFECT_ABORT:
- puts ("ABORT");
+ case EFFECT::ABORT:
+ puts("ABORT");
break;
- case EFFECT_ASSIGN:
- puts ("ASSIGN");
+ case EFFECT::ASSIGN:
+ puts("ASSIGN");
break;
- case EFFECT_FOREACH:
- puts ("FOREACH");
- print_cfg (i + 1, e->e.e_foreach.body);
+ case EFFECT::FOREACH:
+ puts("FOREACH");
+ print_cfg(i + 1, e->e.e_foreach.body);
break;
- case EFFECT_FOR:
- puts ("FOR");
- print_cfg (i + 1, e->e.e_for.body);
+ case EFFECT::FOR:
+ puts("FOR");
+ print_cfg(i + 1, e->e.e_for.body);
break;
- case EFFECT_IF:
- puts ("IF");
+ case EFFECT::IF:
+ puts("IF");
for (j = 0; j < i; j++)
- printf (" ");
- puts ("THEN");
- print_cfg (i + 1, e->e.e_if.true_branch);
+ PRINTF(" ");
+ puts("THEN");
+ print_cfg(i + 1, e->e.e_if.true_branch);
for (j = 0; j < i; j++)
- printf (" ");
- puts ("ELSE");
- print_cfg (i + 1, e->e.e_if.false_branch);
+ PRINTF(" ");
+ puts("ELSE");
+ print_cfg(i + 1, e->e.e_if.false_branch);
break;
- case EFFECT_SLEEP:
- puts ("SLEEP");
+ case EFFECT::SLEEP:
+ puts("SLEEP");
break;
- case EFFECT_SCRIPT:
- puts ("SCRIPT");
+ case EFFECT::SCRIPT:
+ puts("NpcSubtype::SCRIPT");
break;
- case EFFECT_BREAK:
- puts ("BREAK");
+ case EFFECT::BREAK:
+ puts("BREAK");
break;
- case EFFECT_OP:
- puts ("OP");
+ case EFFECT::OP:
+ puts("OP");
break;
}
- print_cfg (i, e->next);
+ print_cfg(i, e->next);
}
#endif
@@ -1331,105 +1402,107 @@ static void print_cfg (int i, effect_t * e)
* >1 if we hit `sleep'; the result is the number of ticks we should sleep for.
* -1 if we paused to wait for a user action (via script interaction)
*/
-static int spell_run (invocation_t * invocation, int allow_delete)
+static
+interval_t spell_run(invocation_t *invocation, int allow_delete)
{
const int invocation_id = invocation->bl.id;
-#define REFRESH_INVOCATION invocation = (invocation_t *) map_id2bl(invocation_id); if (!invocation) return 0;
+#define REFRESH_INVOCATION invocation = (invocation_t *) map_id2bl(invocation_id); if (!invocation) return interval_t::zero();
#ifdef DEBUG
- fprintf (stderr, "Resuming execution: invocation of `%s'\n",
+ FPRINTF(stderr, "Resuming execution: invocation of `%s'\n",
invocation->spell->name);
- print_cfg (1, invocation->current_effect);
+ print_cfg(1, invocation->current_effect);
#endif
while (invocation->current_effect)
{
effect_t *e = invocation->current_effect;
effect_t *next = e->next;
- int i;
+ int i;
#ifdef DEBUG
- fprintf (stderr, "Next step of type %d\n", e->ty);
- dump_env (invocation->env);
+ FPRINTF(stderr, "Next step of type %d\n", e->ty);
+ dump_env(invocation->env);
#endif
switch (e->ty)
{
- case EFFECT_SKIP:
+ case EFFECT::SKIP:
break;
- case EFFECT_ABORT:
- invocation->flags |= INVOCATION_FLAG_ABORTED;
+ case EFFECT::ABORT:
+ invocation->flags |= INVOCATION_FLAG::ABORTED;
invocation->end_effect = NULL;
- case EFFECT_END:
- clear_stack (invocation);
+ FALLTHROUGH;
+ case EFFECT::END:
+ clear_stack(invocation);
next = NULL;
break;
- case EFFECT_ASSIGN:
- magic_eval (invocation->env,
+ case EFFECT::ASSIGN:
+ magic_eval(invocation->env,
&invocation->env->vars[e->e.e_assign.id],
e->e.e_assign.expr);
break;
- case EFFECT_FOREACH:
- next = run_foreach (invocation, e, next);
+ case EFFECT::FOREACH:
+ next = run_foreach(invocation, e, next);
break;
- case EFFECT_FOR:
+ case EFFECT::FOR:
next = run_for (invocation, e, next);
break;
- case EFFECT_IF:
- if (magic_eval_int (invocation->env, e->e.e_if.cond))
+ case EFFECT::IF:
+ if (magic_eval_int(invocation->env, e->e.e_if.cond))
next = e->e.e_if.true_branch;
else
next = e->e.e_if.false_branch;
break;
- case EFFECT_SLEEP:
+ case EFFECT::SLEEP:
{
- int sleeptime =
- magic_eval_int (invocation->env, e->e.e_sleep);
+ interval_t sleeptime = static_cast<interval_t>(
+ magic_eval_int(invocation->env, e->e.e_sleep));
invocation->current_effect = next;
- if (sleeptime > 0)
+ if (sleeptime > interval_t::zero())
return sleeptime;
break;
}
- case EFFECT_SCRIPT:
+ case EFFECT::SCRIPT:
{
character_t *caster =
- (character_t *) map_id2bl (invocation->caster);
+ (character_t *) map_id2bl(invocation->caster);
if (caster)
{
env_t *env = invocation->env;
argrec_t arg[] = { {"@target",
- VAR (VAR_TARGET).ty ==
- TY_ENTITY ? 0 : VAR (VAR_TARGET).
+ VAR(VAR_TARGET).ty ==
+ TYPE::ENTITY ? 0 : VAR(VAR_TARGET).
v.v_int}
,
{"@caster", invocation->caster}
,
{"@caster_name$", caster ? caster->status.name : ""}
};
- int message_recipient =
- VAR (VAR_SCRIPTTARGET).ty ==
- TY_ENTITY ? VAR (VAR_SCRIPTTARGET).
+ int message_recipient =
+ VAR(VAR_SCRIPTTARGET).ty ==
+ TYPE::ENTITY ? VAR(VAR_SCRIPTTARGET).
v.v_int : invocation->caster;
character_t *recipient =
- (character_t *) map_id2bl (message_recipient);
+ (character_t *) map_id2bl(message_recipient);
if (recipient->npc_id
&& recipient->npc_id != invocation->bl.id)
break; /* Don't send multiple message boxes at once */
if (!invocation->script_pos) // first time running this script?
- clif_spawn_fake_npc_for_player (recipient,
+ clif_spawn_fake_npc_for_player(recipient,
invocation->bl.id);
// We have to do this or otherwise the client won't think that it's
// dealing with an NPC
- int newpos = run_script_l (e->e.e_script,
+ int newpos = run_script_l(e->e.e_script,
invocation->script_pos,
message_recipient,
invocation->bl.id,
@@ -1440,133 +1513,125 @@ static int spell_run (invocation_t * invocation, int allow_delete)
/* Must set up for continuation */
recipient->npc_id = invocation->bl.id;
recipient->npc_pos = invocation->script_pos = newpos;
- return -1; /* Signal `wait for script' */
+ return static_cast<interval_t>(-1); /* Signal `wait for script' */
}
else
invocation->script_pos = 0;
- clif_clearchar_id (invocation->bl.id, 1, caster->fd);
+ clif_clearchar_id(invocation->bl.id, BeingRemoveWhy::DEAD, caster->fd);
}
REFRESH_INVOCATION; // Script may have killed the caster
break;
}
- case EFFECT_BREAK:
- next = return_to_stack (invocation);
+ case EFFECT::BREAK:
+ next = return_to_stack(invocation);
break;
- case EFFECT_OP:
+ case EFFECT::OP:
{
op_t *op = &operations[e->e.e_op.id];
val_t args[MAX_ARGS];
for (i = 0; i < e->e.e_op.args_nr; i++)
- magic_eval (invocation->env, &args[i], e->e.e_op.args[i]);
+ magic_eval(invocation->env, &args[i], e->e.e_op.args[i]);
- if (!magic_signature_check ("effect", op->name, op->signature,
+ if (!magic_signature_check("effect", op->name, op->signature,
e->e.e_op.args_nr, args,
e->e.e_op.line_nr,
e->e.e_op.column))
- op->op (invocation->env, e->e.e_op.args_nr, args);
+ op->op(invocation->env, e->e.e_op.args_nr, args);
for (i = 0; i < e->e.e_op.args_nr; i++)
- magic_clear_var (&args[i]);
+ magic_clear_var(&args[i]);
REFRESH_INVOCATION; // Effect may have killed the caster
break;
}
- case EFFECT_CALL:
- next = run_call (invocation, next);
+ case EFFECT::CALL:
+ next = run_call(invocation, next);
break;
default:
- fprintf (stderr,
+ FPRINTF(stderr,
"[magic] INTERNAL ERROR: Unknown effect %d\n",
e->ty);
}
if (!next)
- next = return_to_stack (invocation);
+ next = return_to_stack(invocation);
invocation->current_effect = next;
}
if (allow_delete)
- try_to_finish_invocation (invocation);
- return 0;
+ try_to_finish_invocation(invocation);
+ return interval_t::zero();
#undef REFRESH_INVOCATION
}
static
-void spell_execute_d (invocation_t * invocation, int allow_deletion)
+void spell_execute_d(invocation_t *invocation, int allow_deletion)
{
- int delta;
-
- spell_update_location (invocation);
- delta = spell_run (invocation, allow_deletion);
+ spell_update_location(invocation);
+ interval_t delta = spell_run(invocation, allow_deletion);
- if (delta > 0)
+ if (delta > interval_t::zero())
{
- if (invocation->timer)
- {
- fprintf (stderr,
- "[magic] FATAL ERROR: Trying to add multiple timers to the same spell! Already had timer: %d\n",
- invocation->timer);
- /* *((int *)0x0) = 0; */
- }
- invocation->timer = add_timer (gettick () + delta,
- &invocation_timer_callback,
- invocation->bl.id, 0);
+ assert (!invocation->timer);
+ invocation->timer = Timer(gettick() + delta,
+ std::bind(invocation_timer_callback, ph::_1, ph::_2,
+ invocation->bl.id));
}
- /* If 0, the script cleaned itself. If -1 (wait-for-script), we must wait for the user. */
+ /* If 0, the script cleaned itself. If -1(wait-for-script), we must wait for the user. */
}
-void spell_execute (invocation_t * invocation)
+void spell_execute(invocation_t *invocation)
{
- spell_execute_d (invocation, 1);
+ spell_execute_d(invocation, 1);
}
-void spell_execute_script (invocation_t * invocation)
+void spell_execute_script(invocation_t *invocation)
{
if (invocation->script_pos)
- spell_execute_d (invocation, 1);
+ spell_execute_d(invocation, 1);
/* Otherwise the script-within-the-spell has been terminated by some other means.
* In practice this happens when the script doesn't wait for user input: the client
* may still notify the server that it's done. Without the above check, we'd be
* running the same spell twice! */
}
-int spell_attack (int caster_id, int target_id)
+int spell_attack(int caster_id, int target_id)
{
- character_t *caster = (character_t *) map_id2bl (caster_id);
+ character_t *caster = (character_t *) map_id2bl(caster_id);
invocation_t *invocation;
- int stop_attack = 0;
+ int stop_attack = 0;
if (!caster)
return 0;
- invocation = (invocation_t *) map_id2bl (caster->attack_spell_override);
+ invocation = (invocation_t *) map_id2bl(caster->attack_spell_override);
- if (invocation && invocation->flags & INVOCATION_FLAG_STOPATTACK)
+ if (invocation && bool(invocation->flags & INVOCATION_FLAG::STOPATTACK))
stop_attack = 1;
if (invocation && caster->attack_spell_charges > 0)
{
- magic_clear_var (&invocation->env->vars[VAR_TARGET]);
- invocation->env->vars[VAR_TARGET].ty = TY_ENTITY;
+ magic_clear_var(&invocation->env->vars[VAR_TARGET]);
+ invocation->env->vars[VAR_TARGET].ty = TYPE::ENTITY;
invocation->env->vars[VAR_TARGET].v.v_int = target_id;
invocation->current_effect = invocation->trigger_effect;
- invocation->flags &= ~INVOCATION_FLAG_ABORTED;
- spell_execute_d (invocation,
+ invocation->flags &= ~INVOCATION_FLAG::ABORTED;
+ spell_execute_d(invocation,
0 /* don't delete the invocation if done */ );
// If the caster died, we need to refresh here:
invocation =
- (invocation_t *) map_id2bl (caster->attack_spell_override);
+ (invocation_t *) map_id2bl(caster->attack_spell_override);
- if (invocation && !(invocation->flags & INVOCATION_FLAG_ABORTED)) // If we didn't abort:
+ if (invocation && !bool(invocation->flags & INVOCATION_FLAG::ABORTED)) // If we didn't abort:
caster->attack_spell_charges--;
}
@@ -1578,14 +1643,14 @@ int spell_attack (int caster_id, int target_id)
else if (!invocation || caster->attack_spell_charges <= 0)
{
caster->attack_spell_override = 0;
- char_set_weapon_icon (caster, 0, 0, 0);
- char_set_attack_info (caster, 0, 0);
+ char_set_weapon_icon(caster, 0, StatusChange::ZERO, 0);
+ char_set_attack_info(caster, interval_t::zero(), 0);
if (stop_attack)
- pc_stopattack (caster);
+ pc_stopattack(caster);
if (invocation)
- spell_free_invocation (invocation);
+ spell_free_invocation(invocation);
}
return 1;
diff --git a/src/map/magic.cpp b/src/map/magic.cpp
index 4311f09..1377979 100644
--- a/src/map/magic.cpp
+++ b/src/map/magic.cpp
@@ -1,41 +1,43 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <math.h>
+#include <cstring>
+
+#include "../common/cxxstdio.hpp"
#include "magic-interpreter.hpp"
+#include "pc.hpp"
+
+#include "../poison.hpp"
#undef DEBUG
-static char *magic_preprocess_message (character_t * character, char *start,
+static
+char *magic_preprocess_message(character_t *character, char *start,
char *end)
{
if (character->state.shroud_active
&& character->state.shroud_disappears_on_talk)
- magic_unshroud (character);
+ magic_unshroud(character);
if (character->state.shroud_active
&& character->state.shroud_hides_name_talking)
{
- int len = strlen (end);
- strcpy (start, "? ");
- memmove (start + 2, end, len + 1);
+ int len = strlen(end);
+ strcpy(start, "? ");
+ memmove(start + 2, end, len + 1);
return start + 4;
}
else
return end + 2; /* step past blank */
}
-#define ISBLANK(c) ((c) == ' ')
-
/* Returns a dynamically allocated copy of `src'.
* `*parameter' may point within that copy or be NULL. */
-static char *magic_tokenise (char *src, char **parameter)
+static
+char *magic_tokenise(char *src, char **parameter)
{
- char *retval = strdup (src);
+ char *retval = strdup(src);
char *seeker = retval;
- while (*seeker && !ISBLANK (*seeker))
+ while (*seeker && *seeker != ' ')
++seeker;
if (!*seeker)
@@ -45,7 +47,7 @@ static char *magic_tokenise (char *src, char **parameter)
*seeker = 0; /* Terminate invocation */
++seeker;
- while (ISBLANK (*seeker))
+ while (*seeker == ' ')
++seeker;
*parameter = seeker;
@@ -54,15 +56,15 @@ static char *magic_tokenise (char *src, char **parameter)
return retval;
}
-int magic_message (character_t * caster, char *spell_, size_t spell_len)
+int magic_message(character_t *caster, char *spell_, size_t)
{
- if (pc_isdead (caster))
+ if (pc_isdead(caster))
return 0;
- int power = caster->matk1;
+ int power = caster->matk1;
char *invocation_base = spell_ + 8;
char *source_invocation =
- 1 + invocation_base + strlen (caster->status.name);
+ 1 + invocation_base + strlen(caster->status.name);
spell_t *spell;
char *parameter;
char *spell_invocation;
@@ -72,57 +74,57 @@ int magic_message (character_t * caster, char *spell_, size_t spell_len)
/* Pre-message filter in case some spell alters output */
source_invocation =
- magic_preprocess_message (caster, invocation_base, source_invocation);
+ magic_preprocess_message(caster, invocation_base, source_invocation);
- spell_invocation = magic_tokenise (source_invocation, &parameter);
- parameter = parameter ? strdup (parameter) : strdup ("");
+ spell_invocation = magic_tokenise(source_invocation, &parameter);
+ parameter = parameter ? strdup(parameter) : strdup("");
- spell = magic_find_spell (spell_invocation);
- free (spell_invocation);
+ spell = magic_find_spell(spell_invocation);
+ free(spell_invocation);
if (spell)
{
- int near_miss;
+ int near_miss;
env_t *env =
- spell_create_env (&magic_conf, spell, caster, power, parameter);
+ spell_create_env(&magic_conf, spell, caster, power, parameter);
effect_set_t *effects;
- if ((spell->flags & SPELL_FLAG_NONMAGIC) || (power >= 1))
- effects = spell_trigger (spell, caster, env, &near_miss);
+ if (bool(spell->flags & SPELL_FLAG::NONMAGIC) || (power >= 1))
+ effects = spell_trigger(spell, caster, env, &near_miss);
else
effects = NULL;
#ifdef DEBUG
- fprintf (stderr, "Found spell `%s', triggered = %d\n", spell_,
+ FPRINTF(stderr, "Found spell `%s', triggered = %d\n", spell_,
effects != NULL);
#endif
- if (caster->status.option & OPTION_HIDE)
+ if (bool(caster->status.option & Option::HIDE))
return 0; // No spellcasting while hidden
- MAP_LOG_PC (caster, "CAST %s %s",
+ MAP_LOG_PC(caster, "CAST %s %s",
spell->name, effects ? "SUCCESS" : "FAILURE");
if (effects)
{
- invocation_t *invocation = spell_instantiate (effects, env);
+ invocation_t *invocation = spell_instantiate(effects, env);
- spell_bind (caster, invocation);
- spell_execute (invocation);
+ spell_bind(caster, invocation);
+ spell_execute(invocation);
- return (spell->flags & SPELL_FLAG_SILENT) ? -1 : 1;
+ return bool(spell->flags & SPELL_FLAG::SILENT) ? -1 : 1;
}
else
- magic_free_env (env);
+ magic_free_env(env);
return 1;
}
else
- free (parameter);
+ free(parameter);
return 0; /* Not a spell */
}
-void do_init_magic (void)
+void do_init_magic(void)
{
- magic_init (MAGIC_CONFIG_FILE);
+ magic_init(MAGIC_CONFIG_FILE);
}
diff --git a/src/map/magic.hpp b/src/map/magic.hpp
index 168a05f..4b567ea 100644
--- a/src/map/magic.hpp
+++ b/src/map/magic.hpp
@@ -1,8 +1,7 @@
#ifndef MAGIC_HPP
#define MAGIC_HPP
-#include "clif.hpp"
-#include "intif.hpp"
+#include "skill.t.hpp"
#define MAGIC_CONFIG_FILE "conf/magic.conf"
@@ -22,69 +21,68 @@ struct invocation; /* Spell invocation */
* \return 1 or -1 if the input message was magic and was handled by this function, 0 otherwise. -1 is returned when the
* message should not be repeated.
*/
-int magic_message (character_t * caster, char *spell, size_t spell_len);
+int magic_message(character_t *caster, char *spell, size_t spell_len);
/**
* Removes the shroud from a character
*
* \param character The character to remove the shroud from
*/
-void magic_unshroud (character_t * character);
+void magic_unshroud(character_t *character);
/**
* Notifies a running spell that a status_change timer triggered by the spell has expired
*
* \param invocation The invocation to notify
* \param bl_id ID of the PC for whom this happened
- * \param type sc_id ID of the status change entry that finished
+ * \param sc_id ID of the status change entry that finished
* \param supplanted Whether the status_change finished normally (0) or was supplanted by a new status_change (1)
*/
-void
-spell_effect_report_termination (int invocation, int bl_id, int sc_id,
- int supplanted);
+void spell_effect_report_termination(int invocation, int bl_id,
+ StatusChange sc_id, int supplanted);
/**
* Initialise all spells, read config data
*/
-void do_init_magic (void);
+void do_init_magic(void);
/**
* Identifies the invocation used to trigger a spell
*
* Returns NULL if not found
*/
-const char *magic_find_invocation (const char *spellame);
+const char *magic_find_invocation(const char *spellame);
/**
* Identifies the invocation used to denote a teleport location
*
* Returns NULL if not found
*/
-const char *magic_find_anchor_invocation (const char *teleport_location);
+const char *magic_find_anchor_invocation(const char *teleport_location);
/**
* Execute a spell invocation and sets up timers to finish
*/
-void spell_execute (struct invocation *invocation);
+void spell_execute(struct invocation *invocation);
/**
* Continue an NPC script embedded in a spell
*/
-void spell_execute_script (struct invocation *invocation);
+void spell_execute_script(struct invocation *invocation);
/**
* Stops all magic bound to the specified character
*
*/
-void magic_stop_completely (character_t * c);
+void magic_stop_completely(character_t *c);
/**
* Attacks with a magical spell charged to the character
*
* Returns 0 if there is no charged spell or the spell is depleted.
*/
-int spell_attack (int caster, int target);
+int spell_attack(int caster, int target);
-void spell_free_invocation (struct invocation *invocation);
+void spell_free_invocation(struct invocation *invocation);
-#endif /* !defined(MAGIC_H_) */
+#endif // MAGIC_HPP
diff --git a/src/map/map.cpp b/src/map/map.cpp
index af49ad4..a3f600a 100644
--- a/src/map/map.cpp
+++ b/src/map/map.cpp
@@ -1,89 +1,103 @@
-// $Id: map.c,v 1.6 2004/09/25 17:37:01 MouseJstr Exp $
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdarg.h>
-#ifdef LCCWIN32
-#include <winsock.h>
-#else
+#include "map.hpp"
+
+#include <sys/time.h>
+#include <sys/wait.h>
+
#include <netdb.h>
-#endif
+#include <unistd.h>
+
+#include <cassert>
+#include <cstdlib>
+#include <cstring>
+
+#include <fstream>
#include "../common/core.hpp"
-#include "../common/timer.hpp"
+#include "../common/cxxstdio.hpp"
#include "../common/db.hpp"
-#include "../common/grfio.hpp"
-#include "../common/mt_rand.hpp"
-#include "map.hpp"
+#include "../common/random2.hpp"
+#include "../common/nullpo.hpp"
+#include "../common/socket.hpp"
+#include "../common/timer.hpp"
+
+#include "atcommand.hpp"
+#include "battle.hpp"
+#include "chat.hpp"
#include "chrif.hpp"
#include "clif.hpp"
-#include "intif.hpp"
+#include "grfio.hpp"
+#include "itemdb.hpp"
+#include "magic.hpp"
+#include "mob.hpp"
#include "npc.hpp"
+#include "party.hpp"
#include "pc.hpp"
-#include "mob.hpp"
-#include "chat.hpp"
-#include "itemdb.hpp"
-#include "storage.hpp"
+#include "script.hpp"
#include "skill.hpp"
+#include "storage.hpp"
#include "trade.hpp"
-#include "party.hpp"
-#include "battle.hpp"
-#include "script.hpp"
-#include "guild.hpp"
-#include "atcommand.hpp"
-#include "../common/nullpo.hpp"
-#include "../common/socket.hpp"
-#include "magic.hpp"
-
-#ifdef MEMWATCH
-#include "memwatch.hpp"
-#endif
-
-// 極力 staticã§ãƒ­ãƒ¼ã‚«ãƒ«ã«åŽã‚ã‚‹
-static struct dbt *id_db = NULL;
-static struct dbt *map_db = NULL;
-static struct dbt *nick_db = NULL;
-static struct dbt *charid_db = NULL;
-
-static int users = 0;
-static struct block_list *object[MAX_FLOORITEM];
-static int first_free_object_id = 0, last_object_id = 0;
-
-#define block_free_max 1048576
-static void *block_free[block_free_max];
-static int block_free_count = 0, block_free_lock = 0;
-#define BL_LIST_MAX 1048576
-static struct block_list *bl_list[BL_LIST_MAX];
-static int bl_list_count = 0;
+#include "../poison.hpp"
-struct map_data map[MAX_MAP_PER_SERVER];
-int map_num = 0;
+DMap<int, struct block_list *> id_db;
-int map_port = 0;
+static
+DMap<std::string, struct map_data *> map_db;
-int autosave_interval = DEFAULT_AUTOSAVE_INTERVAL;
-int save_settings = 0xFFFF;
-int agit_flag = 0;
-int night_flag = 0; // 0=day, 1=night [Yor]
+static
+DMap<std::string, struct map_session_data *> nick_db;
struct charid2nick
{
char nick[24];
- int req_id;
+ int req_id;
};
+static
+Map<int, struct charid2nick> charid_db;
+
+static
+int users = 0;
+static
+struct block_list *object[MAX_FLOORITEM];
+static
+int first_free_object_id = 0, last_object_id = 0;
+
+constexpr int block_free_max = 1048576;
+static
+void *block_free[block_free_max];
+static
+int block_free_count = 0, block_free_lock = 0;
+
+constexpr int BL_LIST_MAX = 1048576;
+static
+struct block_list *bl_list[BL_LIST_MAX];
+static
+int bl_list_count = 0;
+
+struct map_data map[MAX_MAP_PER_SERVER];
+int map_num = 0;
+
+static
+int map_port = 0;
+
+interval_t autosave_interval = DEFAULT_AUTOSAVE_INTERVAL;
+int save_settings = 0xFFFF;
+
char motd_txt[256] = "conf/motd.txt";
char help_txt[256] = "conf/help.txt";
char wisp_server_name[24] = "Server"; // can be modified in char-server configuration file
+static
+int map_delmap(const char *mapname);
+
/*==========================================
* å…¨map鯖ç·è¨ˆã§ã®æŽ¥ç¶šæ•°è¨­å®š
* (char鯖ã‹ã‚‰é€ã‚‰ã‚Œã¦ãã‚‹)
*------------------------------------------
*/
-void map_setusers (int n)
+void map_setusers(int n)
{
users = n;
}
@@ -92,7 +106,7 @@ void map_setusers (int n)
* å…¨map鯖ç·è¨ˆã§ã®æŽ¥ç¶šæ•°å–å¾— (/wã¸ã®å¿œç­”用)
*------------------------------------------
*/
-int map_getusers (void)
+int map_getusers(void)
{
return users;
}
@@ -106,11 +120,11 @@ int map_getusers (void)
* ロックã•ã‚Œã¦ã„ã‚‹ã¨ãã¯ãƒãƒƒãƒ•ã‚¡ã«ãŸã‚ã‚‹
*------------------------------------------
*/
-int map_freeblock (void *bl)
+int map_freeblock(void *bl)
{
if (block_free_lock == 0)
{
- free (bl);
+ free(bl);
bl = NULL;
}
else
@@ -118,8 +132,7 @@ int map_freeblock (void *bl)
if (block_free_count >= block_free_max)
{
if (battle_config.error_log)
- printf
- ("map_freeblock: *WARNING* too many free block! %d %d\n",
+ PRINTF("map_freeblock: *WARNING* too many free block! %d %d\n",
block_free_count, block_free_lock);
}
else
@@ -132,7 +145,7 @@ int map_freeblock (void *bl)
* blockã®freeを一時的ã«ç¦æ­¢ã™ã‚‹
*------------------------------------------
*/
-int map_freeblock_lock (void)
+int map_freeblock_lock(void)
{
return ++block_free_lock;
}
@@ -143,18 +156,18 @@ int map_freeblock_lock (void)
* ãƒãƒƒãƒ•ã‚¡ã«ãŸã¾ã£ã¦ã„ãŸblockを全部削除
*------------------------------------------
*/
-int map_freeblock_unlock (void)
+int map_freeblock_unlock(void)
{
if ((--block_free_lock) == 0)
{
- int i;
+ int i;
// if(block_free_count>0) {
// if(battle_config.error_log)
-// printf("map_freeblock_unlock: free %d object\n",block_free_count);
+// PRINTF("map_freeblock_unlock: free %d object\n",block_free_count);
// }
for (i = 0; i < block_free_count; i++)
{
- free (block_free[i]);
+ free(block_free[i]);
block_free[i] = NULL;
}
block_free_count = 0;
@@ -162,20 +175,16 @@ int map_freeblock_unlock (void)
else if (block_free_lock < 0)
{
if (battle_config.error_log)
- printf ("map_freeblock_unlock: lock count < 0 !\n");
+ PRINTF("map_freeblock_unlock: lock count < 0 !\n");
}
return block_free_lock;
}
-//
-// block化処ç†
-//
-/*==========================================
- * map[]ã®block_listã‹ã‚‰ç¹‹ãŒã£ã¦ã„ã‚‹å ´åˆã«
- * bl->prevã«bl_headã®ã‚¢ãƒ‰ãƒ¬ã‚¹ã‚’入れã¦ãŠã
- *------------------------------------------
- */
-static struct block_list bl_head;
+/// This is a dummy entry that is shared by all the linked lists,
+/// so that any entry can unlink itself without worrying about
+/// whether it was the the head of the list.
+static
+struct block_list bl_head;
/*==========================================
* map[]ã®block_listã«è¿½åŠ 
@@ -184,16 +193,16 @@ static struct block_list bl_head;
* æ—¢ã«link済ã¿ã‹ã®ç¢ºèªãŒç„¡ã„。å±é™ºã‹ã‚‚
*------------------------------------------
*/
-int map_addblock (struct block_list *bl)
+int map_addblock(struct block_list *bl)
{
- int m, x, y;
+ int m, x, y;
- nullpo_retr (0, bl);
+ nullpo_ret(bl);
if (bl->prev != NULL)
{
if (battle_config.error_log)
- printf ("map_addblock error : bl->prev!=NULL\n");
+ PRINTF("map_addblock error : bl->prev!=NULL\n");
return 0;
}
@@ -204,7 +213,7 @@ int map_addblock (struct block_list *bl)
x < 0 || x >= map[m].xs || y < 0 || y >= map[m].ys)
return 1;
- if (bl->type == BL_MOB)
+ if (bl->type == BL::MOB)
{
bl->next =
map[m].block_mob[x / BLOCK_SIZE + (y / BLOCK_SIZE) * map[m].bxs];
@@ -224,7 +233,7 @@ int map_addblock (struct block_list *bl)
bl->next->prev = bl;
map[m].block[x / BLOCK_SIZE + (y / BLOCK_SIZE) * map[m].bxs] = bl;
map[m].block_count[x / BLOCK_SIZE + (y / BLOCK_SIZE) * map[m].bxs]++;
- if (bl->type == BL_PC)
+ if (bl->type == BL::PC)
map[m].users++;
}
@@ -236,10 +245,10 @@ int map_addblock (struct block_list *bl)
* prevãŒNULLã®å ´åˆlistã«ç¹‹ãŒã£ã¦ãªã„
*------------------------------------------
*/
-int map_delblock (struct block_list *bl)
+int map_delblock(struct block_list *bl)
{
- int b;
- nullpo_retr (0, bl);
+ int b;
+ nullpo_ret(bl);
// æ—¢ã«blocklistã‹ã‚‰æŠœã‘ã¦ã„ã‚‹
if (bl->prev == NULL)
@@ -248,14 +257,14 @@ int map_delblock (struct block_list *bl)
{
// prevãŒNULLã§nextãŒNULLã§ãªã„ã®ã¯æœ‰ã£ã¦ã¯ãªã‚‰ãªã„
if (battle_config.error_log)
- printf ("map_delblock error : bl->next!=NULL\n");
+ PRINTF("map_delblock error : bl->next!=NULL\n");
}
return 0;
}
b = bl->x / BLOCK_SIZE + (bl->y / BLOCK_SIZE) * map[bl->m].bxs;
- if (bl->type == BL_PC)
+ if (bl->type == BL::PC)
map[bl->m].users--;
if (bl->next)
@@ -263,7 +272,7 @@ int map_delblock (struct block_list *bl)
if (bl->prev == &bl_head)
{
// リストã®é ­ãªã®ã§ã€map[]ã®block_listã‚’æ›´æ–°ã™ã‚‹
- if (bl->type == BL_MOB)
+ if (bl->type == BL::MOB)
{
map[bl->m].block_mob[b] = bl->next;
if ((map[bl->m].block_mob_count[b]--) < 0)
@@ -287,47 +296,15 @@ int map_delblock (struct block_list *bl)
}
/*==========================================
- * 周囲ã®PC人数を数ãˆã‚‹ (ç¾åœ¨æœªä½¿ç”¨)
- *------------------------------------------
- */
-int map_countnearpc (int m, int x, int y)
-{
- int bx, by, c = 0;
- struct block_list *bl = NULL;
-
- if (map[m].users == 0)
- return 0;
- for (by = y / BLOCK_SIZE - AREA_SIZE / BLOCK_SIZE - 1;
- by <= y / BLOCK_SIZE + AREA_SIZE / BLOCK_SIZE + 1; by++)
- {
- if (by < 0 || by >= map[m].bys)
- continue;
- for (bx = x / BLOCK_SIZE - AREA_SIZE / BLOCK_SIZE - 1;
- bx <= x / BLOCK_SIZE + AREA_SIZE / BLOCK_SIZE + 1; bx++)
- {
- if (bx < 0 || bx >= map[m].bxs)
- continue;
- bl = map[m].block[bx + by * map[m].bxs];
- for (; bl; bl = bl->next)
- {
- if (bl->type == BL_PC)
- c++;
- }
- }
- }
- return c;
-}
-
-/*==========================================
* セル上ã®PCã¨MOBã®æ•°ã‚’æ•°ãˆã‚‹ (グランドクロス用)
*------------------------------------------
*/
-int map_count_oncell (int m, int x, int y)
+int map_count_oncell(int m, int x, int y)
{
- int bx, by;
+ int bx, by;
struct block_list *bl = NULL;
- int i, c;
- int count = 0;
+ int i, c;
+ int count = 0;
if (x < 0 || y < 0 || (x >= map[m].xs) || (y >= map[m].ys))
return 1;
@@ -338,7 +315,7 @@ int map_count_oncell (int m, int x, int y)
c = map[m].block_count[bx + by * map[m].bxs];
for (i = 0; i < c && bl; i++, bl = bl->next)
{
- if (bl->x == x && bl->y == y && bl->type == BL_PC)
+ if (bl->x == x && bl->y == y && bl->type == BL::PC)
count++;
}
bl = map[m].block_mob[bx + by * map[m].bxs];
@@ -359,17 +336,17 @@ int map_count_oncell (int m, int x, int y)
* type!=0 ãªã‚‰ãã®ç¨®é¡žã®ã¿
*------------------------------------------
*/
-void map_foreachinarea (int (*func) (struct block_list *, va_list), int m,
- int x0, int y0, int x1, int y1, int type, ...)
+void map_foreachinarea(std::function<void(struct block_list *)> func,
+ int m,
+ int x0, int y0, int x1, int y1,
+ BL type)
{
- int bx, by;
+ int bx, by;
struct block_list *bl = NULL;
- va_list ap = NULL;
- int blockcount = bl_list_count, i, c;
+ int blockcount = bl_list_count, i, c;
if (m < 0)
return;
- va_start (ap, type);
if (x0 < 0)
x0 = 0;
if (y0 < 0)
@@ -378,7 +355,7 @@ void map_foreachinarea (int (*func) (struct block_list *, va_list), int m,
x1 = map[m].xs - 1;
if (y1 >= map[m].ys)
y1 = map[m].ys - 1;
- if (type == 0 || type != BL_MOB)
+ if (type == BL::NUL || type != BL::MOB)
for (by = y0 / BLOCK_SIZE; by <= y1 / BLOCK_SIZE; by++)
{
for (bx = x0 / BLOCK_SIZE; bx <= x1 / BLOCK_SIZE; bx++)
@@ -387,7 +364,7 @@ void map_foreachinarea (int (*func) (struct block_list *, va_list), int m,
c = map[m].block_count[bx + by * map[m].bxs];
for (i = 0; i < c && bl; i++, bl = bl->next)
{
- if (bl && type && bl->type != type)
+ if (bl && type != BL::NUL && bl->type != type)
continue;
if (bl && bl->x >= x0 && bl->x <= x1 && bl->y >= y0
&& bl->y <= y1 && bl_list_count < BL_LIST_MAX)
@@ -395,7 +372,7 @@ void map_foreachinarea (int (*func) (struct block_list *, va_list), int m,
}
}
}
- if (type == 0 || type == BL_MOB)
+ if (type == BL::NUL || type == BL::MOB)
for (by = y0 / BLOCK_SIZE; by <= y1 / BLOCK_SIZE; by++)
{
for (bx = x0 / BLOCK_SIZE; bx <= x1 / BLOCK_SIZE; bx++)
@@ -414,18 +391,17 @@ void map_foreachinarea (int (*func) (struct block_list *, va_list), int m,
if (bl_list_count >= BL_LIST_MAX)
{
if (battle_config.error_log)
- printf ("map_foreachinarea: *WARNING* block count too many!\n");
+ PRINTF("map_foreachinarea: *WARNING* block count too many!\n");
}
- map_freeblock_lock (); // メモリã‹ã‚‰ã®è§£æ”¾ã‚’ç¦æ­¢ã™ã‚‹
+ map_freeblock_lock(); // メモリã‹ã‚‰ã®è§£æ”¾ã‚’ç¦æ­¢ã™ã‚‹
for (i = blockcount; i < bl_list_count; i++)
if (bl_list[i]->prev) // 有効ã‹ã©ã†ã‹ãƒã‚§ãƒƒã‚¯
- func (bl_list[i], ap);
+ func(bl_list[i]);
- map_freeblock_unlock (); // 解放を許å¯ã™ã‚‹
+ map_freeblock_unlock(); // 解放を許å¯ã™ã‚‹
- va_end (ap);
bl_list_count = blockcount;
}
@@ -437,16 +413,16 @@ void map_foreachinarea (int (*func) (struct block_list *, va_list), int m,
* dx,dyã¯-1,0,1ã®ã¿ã¨ã™ã‚‹ï¼ˆã©ã‚“ãªå€¤ã§ã‚‚ã„ã„ã£ã½ã„?)
*------------------------------------------
*/
-void map_foreachinmovearea (int (*func) (struct block_list *, va_list), int m,
- int x0, int y0, int x1, int y1, int dx, int dy,
- int type, ...)
+void map_foreachinmovearea(std::function<void(struct block_list *)> func,
+ int m,
+ int x0, int y0, int x1, int y1,
+ int dx, int dy,
+ BL type)
{
- int bx, by;
+ int bx, by;
struct block_list *bl = NULL;
- va_list ap = NULL;
- int blockcount = bl_list_count, i, c;
+ int blockcount = bl_list_count, i, c;
- va_start (ap, type);
if (dx == 0 || dy == 0)
{
// 矩形領域ã®å ´åˆ
@@ -488,7 +464,7 @@ void map_foreachinmovearea (int (*func) (struct block_list *, va_list), int m,
c = map[m].block_count[bx + by * map[m].bxs];
for (i = 0; i < c && bl; i++, bl = bl->next)
{
- if (bl && type && bl->type != type)
+ if (bl && type != BL::NUL && bl->type != type)
continue;
if (bl && bl->x >= x0 && bl->x <= x1 && bl->y >= y0
&& bl->y <= y1 && bl_list_count < BL_LIST_MAX)
@@ -498,7 +474,7 @@ void map_foreachinmovearea (int (*func) (struct block_list *, va_list), int m,
c = map[m].block_mob_count[bx + by * map[m].bxs];
for (i = 0; i < c && bl; i++, bl = bl->next)
{
- if (bl && type && bl->type != type)
+ if (bl && type != BL::NUL && bl->type != type)
continue;
if (bl && bl->x >= x0 && bl->x <= x1 && bl->y >= y0
&& bl->y <= y1 && bl_list_count < BL_LIST_MAX)
@@ -527,7 +503,7 @@ void map_foreachinmovearea (int (*func) (struct block_list *, va_list), int m,
c = map[m].block_count[bx + by * map[m].bxs];
for (i = 0; i < c && bl; i++, bl = bl->next)
{
- if (bl && type && bl->type != type)
+ if (bl && type != BL::NUL && bl->type != type)
continue;
if ((bl)
&& !(bl->x >= x0 && bl->x <= x1 && bl->y >= y0
@@ -546,7 +522,7 @@ void map_foreachinmovearea (int (*func) (struct block_list *, va_list), int m,
c = map[m].block_mob_count[bx + by * map[m].bxs];
for (i = 0; i < c && bl; i++, bl = bl->next)
{
- if (bl && type && bl->type != type)
+ if (bl && type != BL::NUL && bl->type != type)
continue;
if ((bl)
&& !(bl->x >= x0 && bl->x <= x1 && bl->y >= y0
@@ -569,18 +545,17 @@ void map_foreachinmovearea (int (*func) (struct block_list *, va_list), int m,
if (bl_list_count >= BL_LIST_MAX)
{
if (battle_config.error_log)
- printf ("map_foreachinarea: *WARNING* block count too many!\n");
+ PRINTF("map_foreachinarea: *WARNING* block count too many!\n");
}
- map_freeblock_lock (); // メモリã‹ã‚‰ã®è§£æ”¾ã‚’ç¦æ­¢ã™ã‚‹
+ map_freeblock_lock(); // メモリã‹ã‚‰ã®è§£æ”¾ã‚’ç¦æ­¢ã™ã‚‹
for (i = blockcount; i < bl_list_count; i++)
if (bl_list[i]->prev) // 有効ã‹ã©ã†ã‹ãƒã‚§ãƒƒã‚¯
- func (bl_list[i], ap);
+ func(bl_list[i]);
- map_freeblock_unlock (); // 解放を許å¯ã™ã‚‹
+ map_freeblock_unlock(); // 解放を許å¯ã™ã‚‹
- va_end (ap);
bl_list_count = blockcount;
}
@@ -588,33 +563,32 @@ void map_foreachinmovearea (int (*func) (struct block_list *, va_list), int m,
// which only checks the exact single x/y passed to it rather than an
// area radius - may be more useful in some instances)
//
-void map_foreachincell (int (*func) (struct block_list *, va_list), int m,
- int x, int y, int type, ...)
+void map_foreachincell(std::function<void(struct block_list *)> func,
+ int m,
+ int x, int y,
+ BL type)
{
- int bx, by;
+ int bx, by;
struct block_list *bl = NULL;
- va_list ap = NULL;
- int blockcount = bl_list_count, i, c;
-
- va_start (ap, type);
+ int blockcount = bl_list_count, i, c;
by = y / BLOCK_SIZE;
bx = x / BLOCK_SIZE;
- if (type == 0 || type != BL_MOB)
+ if (type == BL::NUL || type != BL::MOB)
{
bl = map[m].block[bx + by * map[m].bxs];
c = map[m].block_count[bx + by * map[m].bxs];
for (i = 0; i < c && bl; i++, bl = bl->next)
{
- if (type && bl && bl->type != type)
+ if (type != BL::NUL && bl && bl->type != type)
continue;
if (bl && bl->x == x && bl->y == y && bl_list_count < BL_LIST_MAX)
bl_list[bl_list_count++] = bl;
}
}
- if (type == 0 || type == BL_MOB)
+ if (type == BL::NUL || type == BL::MOB)
{
bl = map[m].block_mob[bx + by * map[m].bxs];
c = map[m].block_mob_count[bx + by * map[m].bxs];
@@ -628,18 +602,17 @@ void map_foreachincell (int (*func) (struct block_list *, va_list), int m,
if (bl_list_count >= BL_LIST_MAX)
{
if (battle_config.error_log)
- printf ("map_foreachincell: *WARNING* block count too many!\n");
+ PRINTF("map_foreachincell: *WARNING* block count too many!\n");
}
- map_freeblock_lock (); // メモリã‹ã‚‰ã®è§£æ”¾ã‚’ç¦æ­¢ã™ã‚‹
+ map_freeblock_lock(); // メモリã‹ã‚‰ã®è§£æ”¾ã‚’ç¦æ­¢ã™ã‚‹
for (i = blockcount; i < bl_list_count; i++)
if (bl_list[i]->prev) // 有効ã‹ã©ã†ã‹ãƒã‚§ãƒƒã‚¯
- func (bl_list[i], ap);
+ func(bl_list[i]);
- map_freeblock_unlock (); // 解放を許å¯ã™ã‚‹
+ map_freeblock_unlock(); // 解放を許å¯ã™ã‚‹
- va_end (ap);
bl_list_count = blockcount;
}
@@ -650,12 +623,12 @@ void map_foreachincell (int (*func) (struct block_list *, va_list), int m,
* bl->idã‚‚ã“ã®ä¸­ã§è¨­å®šã—ã¦å•é¡Œç„¡ã„?
*------------------------------------------
*/
-int map_addobject (struct block_list *bl)
+int map_addobject(struct block_list *bl)
{
- int i;
+ int i;
if (bl == NULL)
{
- printf ("map_addobject nullpo?\n");
+ PRINTF("map_addobject nullpo?\n");
return 0;
}
if (first_free_object_id < 2 || first_free_object_id >= MAX_FLOORITEM)
@@ -666,36 +639,37 @@ int map_addobject (struct block_list *bl)
if (i >= MAX_FLOORITEM)
{
if (battle_config.error_log)
- printf ("no free object id\n");
+ PRINTF("no free object id\n");
return 0;
}
first_free_object_id = i;
if (last_object_id < i)
last_object_id = i;
object[i] = bl;
- numdb_insert (id_db, i, bl);
+ id_db.put(i, bl);
return i;
}
/*==========================================
* 一時objectã®è§£æ”¾
- * map_delobjectã®freeã—ãªã„ãƒãƒ¼ã‚¸ãƒ§ãƒ³
+ * map_delobjectã®freeã—ãªã„ãƒãƒ¼ã‚¸ãƒ§ãƒ³
*------------------------------------------
*/
-int map_delobjectnofree (int id, int type)
+int map_delobjectnofree(int id, BL type)
{
if (object[id] == NULL)
return 0;
if (object[id]->type != type)
{
- fprintf (stderr, "Incorrect type: expected %d, got %d\n", type,
- object[id]->type);
- *((char *) 0) = 0; // break for backtrace
+ FPRINTF(stderr, "Incorrect type: expected %d, got %d\n",
+ type,
+ object[id]->type);
+ abort();
}
- map_delblock (object[id]);
- numdb_erase (id_db, id);
+ map_delblock(object[id]);
+ id_db.put(id, nullptr);
// map_freeblock(object[id]);
object[id] = NULL;
@@ -716,18 +690,18 @@ int map_delobjectnofree (int id, int type)
* addã¨ã®å¯¾ç§°æ€§ãŒç„¡ã„ã®ãŒæ°—ã«ãªã‚‹
*------------------------------------------
*/
-int map_delobject (int id, int type)
+int map_delobject(int id, BL type)
{
struct block_list *obj = object[id];
if (obj == NULL)
return 0;
- map_delobjectnofree (id, type);
- if (obj->type == BL_PC) // [Fate] Not sure where else to put this... I'm not sure where delobject for PCs is called from
- pc_cleanup ((struct map_session_data *) obj);
+ map_delobjectnofree(id, type);
+ if (obj->type == BL::PC) // [Fate] Not sure where else to put this... I'm not sure where delobject for PCs is called from
+ pc_cleanup((struct map_session_data *) obj);
- map_freeblock (obj);
+ map_freeblock(obj);
return 0;
}
@@ -737,40 +711,36 @@ int map_delobject (int id, int type)
*
*------------------------------------------
*/
-void map_foreachobject (int (*func) (struct block_list *, va_list), int type,
- ...)
+void map_foreachobject(std::function<void(struct block_list *)> func,
+ BL type)
{
- int i;
- int blockcount = bl_list_count;
- va_list ap = NULL;
-
- va_start (ap, type);
+ int i;
+ int blockcount = bl_list_count;
for (i = 2; i <= last_object_id; i++)
{
if (object[i])
{
- if (type && object[i]->type != type)
+ if (type != BL::NUL && object[i]->type != type)
continue;
if (bl_list_count >= BL_LIST_MAX)
{
if (battle_config.error_log)
- printf ("map_foreachobject: too many block !\n");
+ PRINTF("map_foreachobject: too many block !\n");
}
else
bl_list[bl_list_count++] = object[i];
}
}
- map_freeblock_lock ();
+ map_freeblock_lock();
for (i = blockcount; i < bl_list_count; i++)
if (bl_list[i]->prev || bl_list[i]->next)
- func (bl_list[i], ap);
+ func(bl_list[i]);
- map_freeblock_unlock ();
+ map_freeblock_unlock();
- va_end (ap);
bl_list_count = blockcount;
}
@@ -784,73 +754,41 @@ void map_foreachobject (int (*func) (struct block_list *, va_list), int type,
* map.h内ã§#defineã—ã¦ã‚ã‚‹
*------------------------------------------
*/
-void map_clearflooritem_timer (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data)
+void map_clearflooritem_timer(TimerData *tid, tick_t, int id)
{
struct flooritem_data *fitem = NULL;
fitem = (struct flooritem_data *) object[id];
- if (fitem == NULL || fitem->bl.type != BL_ITEM
- || (!data && fitem->cleartimer != tid))
+ if (fitem == NULL || fitem->bl.type != BL::ITEM)
{
if (battle_config.error_log)
- printf ("map_clearflooritem_timer : error\n");
+ PRINTF("map_clearflooritem_timer : error\n");
return;
}
- if (data)
- delete_timer (fitem->cleartimer, map_clearflooritem_timer);
- clif_clearflooritem (fitem, 0);
- map_delobject (fitem->bl.id, BL_ITEM);
+ if (!tid)
+ fitem->cleartimer.cancel();
+ clif_clearflooritem(fitem, 0);
+ map_delobject(fitem->bl.id, BL::ITEM);
}
-/*==========================================
- * (m,x,y)ã®å‘¨å›²rangeマス内ã®ç©ºã(=侵入å¯èƒ½)cellã®
- * 内ã‹ã‚‰é©å½“ãªãƒžã‚¹ç›®ã®åº§æ¨™ã‚’x+(y<<16)ã§è¿”ã™
- *
- * ç¾çŠ¶range=1ã§ã‚¢ã‚¤ãƒ†ãƒ ãƒ‰ãƒ­ãƒƒãƒ—用途ã®ã¿
- *------------------------------------------
- */
-int map_searchrandfreecell (int m, int x, int y, int range)
+std::pair<uint16_t, uint16_t> map_randfreecell(int m, uint16_t x, uint16_t y, uint16_t w, uint16_t h)
{
- int free_cell, i, j, c;
-
- for (free_cell = 0, i = -range; i <= range; i++)
- {
- if (i + y < 0 || i + y >= map[m].ys)
- continue;
- for (j = -range; j <= range; j++)
- {
- if (j + x < 0 || j + x >= map[m].xs)
- continue;
- if ((c = read_gat (m, j + x, i + y)) == 1 || c == 5)
- continue;
- free_cell++;
- }
- }
- if (free_cell == 0)
- return -1;
- free_cell = MRAND (free_cell);
- for (i = -range; i <= range; i++)
+ for (int itr : random_::iterator(w * h))
{
- if (i + y < 0 || i + y >= map[m].ys)
- continue;
- for (j = -range; j <= range; j++)
- {
- if (j + x < 0 || j + x >= map[m].xs)
- continue;
- if ((c = read_gat (m, j + x, i + y)) == 1 || c == 5)
- continue;
- if (free_cell == 0)
- {
- x += j;
- y += i;
- i = range + 1;
- break;
- }
- free_cell--;
- }
+ int dx = itr % w;
+ int dy = itr / w;
+ if (!bool(read_gat(m, x + dx, y + dy) & MapCell::UNWALKABLE))
+ return {static_cast<uint16_t>(x + dx), static_cast<uint16_t>(y + dy)};
}
+ return {static_cast<uint16_t>(0), static_cast<uint16_t>(0)};
+}
- return x + (y << 16);
+/// Return a randomly selected passable cell within a given range.
+static
+std::pair<uint16_t, uint16_t> map_searchrandfreecell(int m, int x, int y, int range)
+{
+ int whole_range = 2 * range + 1;
+ return map_randfreecell(m, x - range, y - range, whole_range, whole_range);
}
/*==========================================
@@ -859,41 +797,39 @@ int map_searchrandfreecell (int m, int x, int y, int range)
* item_dataã¯amount以外をcopyã™ã‚‹
*------------------------------------------
*/
-int map_addflooritem_any (struct item *item_data, int amount, int m, int x,
- int y, struct map_session_data **owners,
- int *owner_protection, int lifetime, int dispersal)
+int map_addflooritem_any(struct item *item_data, int amount,
+ int m, int x, int y,
+ struct map_session_data **owners, interval_t *owner_protection,
+ interval_t lifetime, int dispersal)
{
- int xy, r;
- unsigned int tick;
struct flooritem_data *fitem = NULL;
- nullpo_retr (0, item_data);
-
- if ((xy = map_searchrandfreecell (m, x, y, dispersal)) < 0)
+ nullpo_ret(item_data);
+ auto xy = map_searchrandfreecell(m, x, y, dispersal);
+ if (xy.first == 0 && xy.second == 0)
return 0;
- r = mt_random ();
- CREATE (fitem, struct flooritem_data, 1);
- fitem->bl.type = BL_ITEM;
+ CREATE(fitem, struct flooritem_data, 1);
+ fitem->bl.type = BL::ITEM;
fitem->bl.prev = fitem->bl.next = NULL;
fitem->bl.m = m;
- fitem->bl.x = xy & 0xffff;
- fitem->bl.y = (xy >> 16) & 0xffff;
+ fitem->bl.x = xy.first;
+ fitem->bl.y = xy.second;
fitem->first_get_id = 0;
- fitem->first_get_tick = 0;
+ fitem->first_get_tick = tick_t();
fitem->second_get_id = 0;
- fitem->second_get_tick = 0;
+ fitem->second_get_tick = tick_t();
fitem->third_get_id = 0;
- fitem->third_get_tick = 0;
+ fitem->third_get_tick = tick_t();
- fitem->bl.id = map_addobject (&fitem->bl);
+ fitem->bl.id = map_addobject(&fitem->bl);
if (fitem->bl.id == 0)
{
- free (fitem);
+ free(fitem);
return 0;
}
- tick = gettick ();
+ tick_t tick = gettick();
if (owners[0])
fitem->first_get_id = owners[0]->bl.id;
@@ -907,189 +843,90 @@ int map_addflooritem_any (struct item *item_data, int amount, int m, int x,
fitem->third_get_id = owners[2]->bl.id;
fitem->third_get_tick = tick + owner_protection[2];
- memcpy (&fitem->item_data, item_data, sizeof (*item_data));
+ memcpy(&fitem->item_data, item_data, sizeof(*item_data));
fitem->item_data.amount = amount;
- fitem->subx = (r & 3) * 3 + 3;
- fitem->suby = ((r >> 2) & 3) * 3 + 3;
- fitem->cleartimer =
- add_timer (gettick () + lifetime, map_clearflooritem_timer,
- fitem->bl.id, 0);
-
- map_addblock (&fitem->bl);
- clif_dropflooritem (fitem);
+ // TODO - talk to 4144 about maybe removing this.
+ // It has no effect on the server itself, it is visual only.
+ // If it is desirable to prevent items from visibly stacking
+ // on the ground, that can be done with client-side randomness.
+ // Currently, it yields the numbers {3 6 9 12}.
+ fitem->subx = random_::in(1, 4) * 3;
+ fitem->suby = random_::in(1, 4) * 3;
+ fitem->cleartimer = Timer(gettick() + lifetime,
+ std::bind(map_clearflooritem_timer, ph::_1, ph::_2,
+ fitem->bl.id));
+
+ map_addblock(&fitem->bl);
+ clif_dropflooritem(fitem);
return fitem->bl.id;
}
-int map_addflooritem (struct item *item_data, int amount, int m, int x, int y,
- struct map_session_data *first_sd,
- struct map_session_data *second_sd,
- struct map_session_data *third_sd, int type)
+int map_addflooritem(struct item *item_data, int amount,
+ int m, int x, int y,
+ struct map_session_data *first_sd,
+ struct map_session_data *second_sd,
+ struct map_session_data *third_sd)
{
struct map_session_data *owners[3] = { first_sd, second_sd, third_sd };
- int owner_protection[3];
+ interval_t owner_protection[3];
- if (type)
- {
- owner_protection[0] = battle_config.mvp_item_first_get_time;
- owner_protection[1] =
- owner_protection[0] + battle_config.mvp_item_second_get_time;
- owner_protection[2] =
- owner_protection[1] + battle_config.mvp_item_third_get_time;
- }
- else
{
- owner_protection[0] = battle_config.item_first_get_time;
- owner_protection[1] =
- owner_protection[0] + battle_config.item_second_get_time;
- owner_protection[2] =
- owner_protection[1] + battle_config.item_third_get_time;
+ owner_protection[0] = static_cast<interval_t>(battle_config.item_first_get_time);
+ owner_protection[1] = owner_protection[0] + static_cast<interval_t>(battle_config.item_second_get_time);
+ owner_protection[2] = owner_protection[1] + static_cast<interval_t>(battle_config.item_third_get_time);
}
- return map_addflooritem_any (item_data, amount, m, x, y,
- owners, owner_protection,
- battle_config.flooritem_lifetime, 1);
+ return map_addflooritem_any(item_data, amount, m, x, y,
+ owners, owner_protection,
+ static_cast<interval_t>(battle_config.flooritem_lifetime), 1);
}
-/* int xy,r; */
-/* unsigned int tick; */
-/* struct flooritem_data *fitem=NULL; */
-
-/* nullpo_retr(0, item_data); */
-
-/* if((xy=map_searchrandfreecell(m,x,y,1))<0) */
-/* return 0; */
-/* r=rand(); */
-
-/* fitem = (struct flooritem_data *)aCalloc(1,sizeof(*fitem)); */
-/* fitem->bl.type=BL_ITEM; */
-/* fitem->bl.prev = fitem->bl.next = NULL; */
-/* fitem->bl.m=m; */
-/* fitem->bl.x=xy&0xffff; */
-/* fitem->bl.y=(xy>>16)&0xffff; */
-/* fitem->first_get_id = 0; */
-/* fitem->first_get_tick = 0; */
-/* fitem->second_get_id = 0; */
-/* fitem->second_get_tick = 0; */
-/* fitem->third_get_id = 0; */
-/* fitem->third_get_tick = 0; */
-
-/* fitem->bl.id = map_addobject(&fitem->bl); */
-/* if(fitem->bl.id==0){ */
-/* free(fitem); */
-/* return 0; */
-/* } */
-
-/* tick = gettick(); */
-/* if(first_sd) { */
-/* fitem->first_get_id = first_sd->bl.id; */
-/* if(type) */
-/* fitem->first_get_tick = tick + battle_config.mvp_item_first_get_time; */
-/* else */
-/* fitem->first_get_tick = tick + battle_config.item_first_get_time; */
-/* } */
-/* if(second_sd) { */
-/* fitem->second_get_id = second_sd->bl.id; */
-/* if(type) */
-/* fitem->second_get_tick = tick + battle_config.mvp_item_first_get_time + battle_config.mvp_item_second_get_time; */
-/* else */
-/* fitem->second_get_tick = tick + battle_config.item_first_get_time + battle_config.item_second_get_time; */
-/* } */
-/* if(third_sd) { */
-/* fitem->third_get_id = third_sd->bl.id; */
-/* if(type) */
-/* fitem->third_get_tick = tick + battle_config.mvp_item_first_get_time + battle_config.mvp_item_second_get_time + battle_config.mvp_item_third_get_time; */
-/* else */
-/* fitem->third_get_tick = tick + battle_config.item_first_get_time + battle_config.item_second_get_time + battle_config.item_third_get_time; */
-/* } */
-
-/* memcpy(&fitem->item_data,item_data,sizeof(*item_data)); */
-/* fitem->item_data.amount=amount; */
-/* fitem->subx=(r&3)*3+3; */
-/* fitem->suby=((r>>2)&3)*3+3; */
-/* fitem->cleartimer=add_timer(gettick()+battle_config.flooritem_lifetime,map_clearflooritem_timer,fitem->bl.id,0); */
-
-/* map_addblock(&fitem->bl); */
-/* clif_dropflooritem(fitem); */
-
-/* return fitem->bl.id; */
-/* } */
-
/*==========================================
* charid_dbã¸è¿½åŠ (返信待ã¡ãŒã‚ã‚Œã°è¿”ä¿¡)
*------------------------------------------
*/
-void map_addchariddb (int charid, const char *name)
+void map_addchariddb(int charid, const char *name)
{
- struct charid2nick *p = (struct charid2nick *)numdb_search (charid_db, charid);
+ struct charid2nick *p = charid_db.search(charid);
if (p == NULL)
- { // データベースã«ãªã„
- CREATE (p, struct charid2nick, 1);
- p->req_id = 0;
- }
- else
- numdb_erase (charid_db, charid);
+ p = charid_db.init(charid);
- int req = p->req_id;
- memcpy (p->nick, name, 24);
+ memcpy(p->nick, name, 24);
p->req_id = 0;
- numdb_insert (charid_db, charid, p);
- if (req)
- { // 返信待ã¡ãŒã‚ã‚Œã°è¿”ä¿¡
- struct map_session_data *sd = map_id2sd (req);
- if (sd != NULL)
- clif_solved_charname (sd, charid);
- }
-}
-
-/*==========================================
- * charid_dbã¸è¿½åŠ ï¼ˆè¿”ä¿¡è¦æ±‚ã®ã¿ï¼‰
- *------------------------------------------
- */
-int map_reqchariddb (struct map_session_data *sd, int charid)
-{
- nullpo_retr (0, sd);
-
- struct charid2nick *p = (struct charid2nick *)numdb_search (charid_db, charid);
- if (p != NULL) // データベースã«ã™ã§ã«ã‚ã‚‹
- return 0;
- CREATE (p, struct charid2nick, 1);
- p->req_id = sd->bl.id;
- numdb_insert (charid_db, charid, p);
- return 0;
}
/*==========================================
* id_dbã¸blを追加
*------------------------------------------
*/
-void map_addiddb (struct block_list *bl)
+void map_addiddb(struct block_list *bl)
{
- nullpo_retv (bl);
+ nullpo_retv(bl);
- numdb_insert (id_db, bl->id, bl);
+ id_db.put(bl->id, bl);
}
/*==========================================
* id_dbã‹ã‚‰blを削除
*------------------------------------------
*/
-void map_deliddb (struct block_list *bl)
+void map_deliddb(struct block_list *bl)
{
- nullpo_retv (bl);
+ nullpo_retv(bl);
- numdb_erase (id_db, bl->id);
+ id_db.put(bl->id, nullptr);
}
/*==========================================
* nick_dbã¸sdを追加
*------------------------------------------
*/
-void map_addnickdb (struct map_session_data *sd)
+void map_addnickdb(struct map_session_data *sd)
{
- nullpo_retv (sd);
+ nullpo_retv(sd);
- strdb_insert (nick_db, sd->status.name, sd);
+ nick_db.put(sd->status.name, sd);
}
/*==========================================
@@ -1098,79 +935,62 @@ void map_addnickdb (struct map_session_data *sd)
* quit処ç†ã®ä¸»ä½“ãŒé•ã†ã‚ˆã†ãªæ°—ã‚‚ã—ã¦ããŸ
*------------------------------------------
*/
-int map_quit (struct map_session_data *sd)
+void map_quit(struct map_session_data *sd)
{
- nullpo_retr (0, sd);
+ nullpo_retv(sd);
if (sd->chatID) // ãƒãƒ£ãƒƒãƒˆã‹ã‚‰å‡ºã‚‹
- chat_leavechat (sd);
+ chat_leavechat(sd);
if (sd->trade_partner) // å–引を中断ã™ã‚‹
- trade_tradecancel (sd);
+ trade_tradecancel(sd);
if (sd->party_invite > 0) // パーティ勧誘を拒å¦ã™ã‚‹
- party_reply_invite (sd, sd->party_invite_account, 0);
-
- if (sd->guild_invite > 0) // ギルド勧誘を拒å¦ã™ã‚‹
- guild_reply_invite (sd, sd->guild_invite, 0);
- if (sd->guild_alliance > 0) // ギルドåŒç›Ÿå‹§èª˜ã‚’æ‹’å¦ã™ã‚‹
- guild_reply_reqalliance (sd, sd->guild_alliance_account, 0);
+ party_reply_invite(sd, sd->party_invite_account, 0);
- party_send_logout (sd); // パーティã®ãƒ­ã‚°ã‚¢ã‚¦ãƒˆãƒ¡ãƒƒã‚»ãƒ¼ã‚¸é€ä¿¡
+ party_send_logout(sd); // パーティã®ãƒ­ã‚°ã‚¢ã‚¦ãƒˆãƒ¡ãƒƒã‚»ãƒ¼ã‚¸é€ä¿¡
- guild_send_memberinfoshort (sd, 0); // ギルドã®ãƒ­ã‚°ã‚¢ã‚¦ãƒˆãƒ¡ãƒƒã‚»ãƒ¼ã‚¸é€ä¿¡
+ pc_cleareventtimer(sd); // イベントタイマを破棄ã™ã‚‹
- pc_cleareventtimer (sd); // イベントタイマを破棄ã™ã‚‹
+ skill_castcancel(&sd->bl, 0); // 詠唱を中断ã™ã‚‹
+ skill_stop_dancing(&sd->bl, 1); // ダンス/æ¼”å¥ä¸­æ–­
- skill_castcancel (&sd->bl, 0); // 詠唱を中断ã™ã‚‹
- skill_stop_dancing (&sd->bl, 1); // ダンス/æ¼”å¥ä¸­æ–­
+ skill_status_change_clear(&sd->bl, 1); // ステータス異常を解除ã™ã‚‹
+ pc_stop_walking(sd, 0);
+ pc_stopattack(sd);
+ pc_delinvincibletimer(sd);
+ skill_gangsterparadise(sd, 0);
- if (sd->sc_data && sd->sc_data[SC_BERSERK].timer != -1) //ãƒãƒ¼ã‚µãƒ¼ã‚¯ä¸­ã®çµ‚了ã¯HPã‚’100ã«
- sd->status.hp = 100;
+ pc_calcstatus(sd, 4);
- skill_status_change_clear (&sd->bl, 1); // ステータス異常を解除ã™ã‚‹
- skill_clear_unitgroup (&sd->bl); // スキルユニットグループã®å‰Šé™¤
- skill_cleartimerskill (&sd->bl);
- pc_stop_walking (sd, 0);
- pc_stopattack (sd);
- pc_delinvincibletimer (sd);
- pc_delspiritball (sd, sd->spiritball, 1);
- skill_gangsterparadise (sd, 0);
+ clif_clearchar(&sd->bl, BeingRemoveWhy::QUIT);
- pc_calcstatus (sd, 4);
-
- clif_clearchar_area (&sd->bl, 2);
-
- if (pc_isdead (sd))
- pc_setrestartvalue (sd, 2);
- pc_makesavestatus (sd);
+ if (pc_isdead(sd))
+ pc_setrestartvalue(sd, 2);
+ pc_makesavestatus(sd);
//クローンスキルã§è¦šãˆãŸã‚¹ã‚­ãƒ«ã¯æ¶ˆã™
//The storage closing routines will save the char if needed. [Skotlex]
- if (!sd->state.storage_flag)
- chrif_save (sd);
- else if (sd->state.storage_flag == 1)
- storage_storage_quit (sd);
- else if (sd->state.storage_flag == 2)
- storage_guild_storage_quit (sd, 1);
+ if (!sd->state.storage_open)
+ chrif_save(sd);
+ else if (sd->state.storage_open)
+ storage_storage_quit(sd);
if (sd->npc_stackbuf && sd->npc_stackbuf != NULL)
- free (sd->npc_stackbuf);
-
- map_delblock (&sd->bl);
+ free(sd->npc_stackbuf);
- numdb_erase (id_db, sd->bl.id);
- strdb_erase (nick_db, sd->status.name);
- numdb_erase (charid_db, sd->status.char_id);
+ map_delblock(&sd->bl);
- return 0;
+ id_db.put(sd->bl.id, nullptr);
+ nick_db.put(sd->status.name, nullptr);
+ charid_db.erase(sd->status.char_id);
}
/*==========================================
* id番å·ã®PCを探ã™ã€‚å±…ãªã‘ã‚Œã°NULL
*------------------------------------------
*/
-struct map_session_data *map_id2sd (int id)
+struct map_session_data *map_id2sd(int id)
{
// remove search from db, because:
// 1 - all players, npc, items and mob are in this db (to search, it's not speed, and search in session is more sure)
@@ -1179,14 +999,14 @@ struct map_session_data *map_id2sd (int id)
// replaced by searching in all session.
// by searching in session, we are sure that fd, session, and account exist.
/*
- struct block_list *bl;
+ struct block_list *bl;
- bl=numdb_search(id_db,id);
- if(bl && bl->type==BL_PC)
- return (struct map_session_data*)bl;
- return NULL;
+ bl=numdb_search(id_db,id);
+ if (bl && bl->type==BL::PC)
+ return (struct map_session_data*)bl;
+ return NULL;
*/
- int i;
+ int i;
struct map_session_data *sd = NULL;
for (i = 0; i < fd_max; i++)
@@ -1200,9 +1020,9 @@ struct map_session_data *map_id2sd (int id)
* char_id番å·ã®åå‰ã‚’探ã™
*------------------------------------------
*/
-char *map_charid2nick (int id)
+char *map_charid2nick(int id)
{
- struct charid2nick *p = (struct charid2nick *)numdb_search (charid_db, id);
+ struct charid2nick *p = charid_db.search(id);
if (p == NULL)
return NULL;
@@ -1214,7 +1034,8 @@ char *map_charid2nick (int id)
/*========================================*/
/* [Fate] Operations to iterate over active map sessions */
-static struct map_session_data *map_get_session (int i)
+static
+struct map_session_data *map_get_session(int i)
{
struct map_session_data *d;
@@ -1225,12 +1046,13 @@ static struct map_session_data *map_get_session (int i)
return NULL;
}
-static struct map_session_data *map_get_session_forward (int start)
+static
+struct map_session_data *map_get_session_forward(int start)
{
- int i;
+ int i;
for (i = start; i < fd_max; i++)
{
- struct map_session_data *d = map_get_session (i);
+ struct map_session_data *d = map_get_session(i);
if (d)
return d;
}
@@ -1238,12 +1060,13 @@ static struct map_session_data *map_get_session_forward (int start)
return NULL;
}
-static struct map_session_data *map_get_session_backward (int start)
+static
+struct map_session_data *map_get_session_backward(int start)
{
- int i;
+ int i;
for (i = start; i >= 0; i--)
{
- struct map_session_data *d = map_get_session (i);
+ struct map_session_data *d = map_get_session(i);
if (d)
return d;
}
@@ -1251,24 +1074,24 @@ static struct map_session_data *map_get_session_backward (int start)
return NULL;
}
-struct map_session_data *map_get_first_session (void)
+struct map_session_data *map_get_first_session(void)
{
- return map_get_session_forward (0);
+ return map_get_session_forward(0);
}
-struct map_session_data *map_get_next_session (struct map_session_data *d)
+struct map_session_data *map_get_next_session(struct map_session_data *d)
{
- return map_get_session_forward (d->fd + 1);
+ return map_get_session_forward(d->fd + 1);
}
-struct map_session_data *map_get_last_session (void)
+struct map_session_data *map_get_last_session(void)
{
- return map_get_session_backward (fd_max);
+ return map_get_session_backward(fd_max);
}
-struct map_session_data *map_get_prev_session (struct map_session_data *d)
+struct map_session_data *map_get_prev_session(struct map_session_data *d)
{
- return map_get_session_backward (d->fd - 1);
+ return map_get_session_backward(d->fd - 1);
}
/*==========================================
@@ -1277,16 +1100,16 @@ struct map_session_data *map_get_prev_session (struct map_session_data *d)
* return map_session_data pointer or NULL
*------------------------------------------
*/
-struct map_session_data *map_nick2sd (const char *nick)
+struct map_session_data *map_nick2sd(const char *nick)
{
- int i, quantity = 0, nicklen;
+ int i, quantity = 0, nicklen;
struct map_session_data *sd = NULL;
struct map_session_data *pl_sd = NULL;
if (nick == NULL)
return NULL;
- nicklen = strlen (nick);
+ nicklen = strlen(nick);
for (i = 0; i < fd_max; i++)
{
@@ -1294,10 +1117,10 @@ struct map_session_data *map_nick2sd (const char *nick)
&& pl_sd->state.auth)
{
// Without case sensitive check (increase the number of similar character names found)
- if (strncasecmp (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)
+ if (strcmp(pl_sd->status.name, nick) == 0)
return pl_sd;
quantity++;
sd = pl_sd;
@@ -1318,38 +1141,24 @@ struct map_session_data *map_nick2sd (const char *nick)
* 一時objectã®å ´åˆã¯é…列を引ãã®ã¿
*------------------------------------------
*/
-struct block_list *map_id2bl (int id)
+struct block_list *map_id2bl(int id)
{
struct block_list *bl = NULL;
- if (id < sizeof (object) / sizeof (object[0]))
+ if (id < sizeof(object) / sizeof(object[0]))
bl = object[id];
else
- bl = (struct block_list *)numdb_search (id_db, id);
+ bl = id_db.get(id);
return bl;
}
/*==========================================
- * id_db内ã®å…¨ã¦ã«funcを実行
- *------------------------------------------
- */
-int map_foreachiddb (db_func_t func, ...)
-{
- va_list ap = NULL;
-
- va_start (ap, func);
- numdb_foreach (id_db, func, ap);
- va_end (ap);
- return 0;
-}
-
-/*==========================================
* map.npcã¸è¿½åŠ  (warpç­‰ã®é ˜åŸŸæŒã¡ã®ã¿)
*------------------------------------------
*/
-int map_addnpc (int m, struct npc_data *nd)
+int map_addnpc(int m, struct npc_data *nd)
{
- int i;
+ int i;
if (m < 0 || m >= map_num)
return -1;
for (i = 0; i < map[m].npc_num && i < MAX_NPC_PER_MAP; i++)
@@ -1358,7 +1167,7 @@ int map_addnpc (int m, struct npc_data *nd)
if (i == MAX_NPC_PER_MAP)
{
if (battle_config.error_log)
- printf ("too many NPCs in one map %s\n", map[m].name);
+ PRINTF("too many NPCs in one map %s\n", map[m].name);
return -1;
}
if (i == map[m].npc_num)
@@ -1366,19 +1175,19 @@ int map_addnpc (int m, struct npc_data *nd)
map[m].npc_num++;
}
- nullpo_retr (0, nd);
+ nullpo_ret(nd);
map[m].npc[i] = nd;
nd->n = i;
- numdb_insert (id_db, nd->bl.id, nd);
+ id_db.put(nd->bl.id, (struct block_list *)nd);
return i;
}
static
-void map_removenpc (void)
+void map_removenpc(void)
{
- int i, m, n = 0;
+ int i, m, n = 0;
for (m = 0; m < map_num; m++)
{
@@ -1386,30 +1195,30 @@ void map_removenpc (void)
{
if (map[m].npc[i] != NULL)
{
- clif_clearchar_area (&map[m].npc[i]->bl, 2);
- map_delblock (&map[m].npc[i]->bl);
- numdb_erase (id_db, map[m].npc[i]->bl.id);
- if (map[m].npc[i]->bl.subtype == SCRIPT)
+ clif_clearchar(&map[m].npc[i]->bl, BeingRemoveWhy::QUIT);
+ map_delblock(&map[m].npc[i]->bl);
+ id_db.put(map[m].npc[i]->bl.id, nullptr);
+ if (map[m].npc[i]->bl.subtype == NpcSubtype::SCRIPT)
{
// free(map[m].npc[i]->u.scr.script);
// free(map[m].npc[i]->u.scr.label_list);
}
- free (map[m].npc[i]);
+ free(map[m].npc[i]);
map[m].npc[i] = NULL;
n++;
}
}
}
- printf ("%d NPCs removed.\n", n);
+ PRINTF("%d NPCs removed.\n", n);
}
/*==========================================
* mapåã‹ã‚‰map番å·ã¸å¤‰æ›
*------------------------------------------
*/
-int map_mapname2mapid (const char *name)
+int map_mapname2mapid(const char *name)
{
- struct map_data *md = (struct map_data *)strdb_search (map_db, name);
+ struct map_data *md = map_db.get(name);
if (md == NULL || md->gat == NULL)
return -1;
return md->m;
@@ -1419,9 +1228,9 @@ int map_mapname2mapid (const char *name)
* 他鯖mapåã‹ã‚‰ip,port変æ›
*------------------------------------------
*/
-int map_mapname2ipport (const char *name, struct in_addr *ip, int *port)
+int map_mapname2ipport(const char *name, struct in_addr *ip, int *port)
{
- struct map_data_other_server *mdos = (struct map_data_other_server *)strdb_search (map_db, name);
+ struct map_data_other_server *mdos = (struct map_data_other_server *)map_db.get(name);
if (mdos == NULL || mdos->gat)
return -1;
*ip = mdos->ip;
@@ -1429,100 +1238,73 @@ int map_mapname2ipport (const char *name, struct in_addr *ip, int *port)
return 0;
}
-/*==========================================
- *
- *------------------------------------------
- */
-int map_check_dir (int s_dir, int t_dir)
+/// Check compatibility of directions.
+/// Directions are compatible if they are at most 45° apart.
+///
+/// @return false if compatible, true if incompatible.
+bool map_check_dir(const DIR s_dir, const DIR t_dir)
{
if (s_dir == t_dir)
- return 0;
- switch (s_dir)
- {
- case 0:
- if (t_dir == 7 || t_dir == 1 || t_dir == 0)
- return 0;
- break;
- case 1:
- if (t_dir == 0 || t_dir == 2 || t_dir == 1)
- return 0;
- break;
- case 2:
- if (t_dir == 1 || t_dir == 3 || t_dir == 2)
- return 0;
- break;
- case 3:
- if (t_dir == 2 || t_dir == 4 || t_dir == 3)
- return 0;
- break;
- case 4:
- if (t_dir == 3 || t_dir == 5 || t_dir == 4)
- return 0;
- break;
- case 5:
- if (t_dir == 4 || t_dir == 6 || t_dir == 5)
- return 0;
- break;
- case 6:
- if (t_dir == 5 || t_dir == 7 || t_dir == 6)
- return 0;
- break;
- case 7:
- if (t_dir == 6 || t_dir == 0 || t_dir == 7)
- return 0;
- break;
- }
- return 1;
+ return false;
+
+ const uint8_t sdir = static_cast<uint8_t>(s_dir);
+ const uint8_t tdir = static_cast<uint8_t>(t_dir);
+ if ((sdir + 1) % 8 == tdir)
+ return false;
+ if (sdir == (tdir + 1) % 8)
+ return false;
+
+ return true;
}
/*==========================================
* 彼我ã®æ–¹å‘を計算
*------------------------------------------
*/
-int map_calc_dir (struct block_list *src, int x, int y)
+DIR map_calc_dir(struct block_list *src, int x, int y)
{
- int dir = 0;
- int dx, dy;
+ DIR dir = DIR::S;
+ int dx, dy;
- nullpo_retr (0, src);
+ nullpo_retr(DIR::S, src);
dx = x - src->x;
dy = y - src->y;
if (dx == 0 && dy == 0)
- { // 彼我ã®å ´æ‰€ä¸€è‡´
- dir = 0; // 上
+ {
+ dir = DIR::S;
}
else if (dx >= 0 && dy >= 0)
- { // æ–¹å‘çš„ã«å³ä¸Š
- dir = 7; // å³ä¸Š
+ {
+ dir = DIR::SE;
if (dx * 3 - 1 < dy)
- dir = 0; // 上
+ dir = DIR::S;
if (dx > dy * 3)
- dir = 6; // å³
+ dir = DIR::E;
}
else if (dx >= 0 && dy <= 0)
- { // æ–¹å‘çš„ã«å³ä¸‹
- dir = 5; // å³ä¸‹
+ {
+ dir = DIR::NE;
if (dx * 3 - 1 < -dy)
- dir = 4; // 下
+ dir = DIR::N;
if (dx > -dy * 3)
- dir = 6; // å³
+ dir = DIR::E;
}
else if (dx <= 0 && dy <= 0)
- { // æ–¹å‘çš„ã«å·¦ä¸‹
- dir = 3; // 左下
+ {
+ dir = DIR::NW;
if (dx * 3 + 1 > dy)
- dir = 4; // 下
+ dir = DIR::N;
if (dx < dy * 3)
- dir = 2; // å·¦
+ dir = DIR::W;
}
else
- { // æ–¹å‘çš„ã«å·¦ä¸Š
- dir = 1; // 左上
+ {
+ dir = DIR::SW;
if (-dx * 3 - 1 < dy)
- dir = 0; // 上
+ dir = DIR::S;
if (-dx > dy * 3)
- dir = 2; // å·¦
+ dir = DIR::W;
}
return dir;
}
@@ -1532,10 +1314,10 @@ int map_calc_dir (struct block_list *src, int x, int y)
* (m,x,y)ã®çŠ¶æ…‹ã‚’調ã¹ã‚‹
*------------------------------------------
*/
-int map_getcell (int m, int x, int y)
+MapCell map_getcell(int m, int x, int y)
{
if (x < 0 || x >= map[m].xs - 1 || y < 0 || y >= map[m].ys - 1)
- return 1;
+ return MapCell::UNWALKABLE;
return map[m].gat[x + y * map[m].xs];
}
@@ -1543,44 +1325,47 @@ int map_getcell (int m, int x, int y)
* (m,x,y)ã®çŠ¶æ…‹ã‚’tã«ã™ã‚‹
*------------------------------------------
*/
-int map_setcell (int m, int x, int y, int t)
+void map_setcell(int m, int x, int y, MapCell t)
{
if (x < 0 || x >= map[m].xs || y < 0 || y >= map[m].ys)
- return t;
- return map[m].gat[x + y * map[m].xs] = t;
+ return;
+ map[m].gat[x + y * map[m].xs] = t;
}
/*==========================================
* 他鯖管ç†ã®ãƒžãƒƒãƒ—ã‚’dbã«è¿½åŠ 
*------------------------------------------
*/
-int map_setipport (const char *name, struct in_addr ip, int port)
+int map_setipport(const char *name, struct in_addr ip, int port)
{
- struct map_data_other_server *mdos = NULL;
-
- struct map_data *md = (struct map_data *)strdb_search (map_db, name);
+ struct map_data *md = map_db.get(name);
if (md == NULL)
- { // not exist -> add new data
- CREATE (mdos, struct map_data_other_server, 1);
- memcpy (mdos->name, name, 24);
+ {
+ struct map_data_other_server *mdos = NULL;
+ // not exist -> add new data
+ CREATE(mdos, struct map_data_other_server, 1);
+ memcpy(mdos->name, name, 24);
mdos->gat = NULL;
mdos->ip = ip;
mdos->port = port;
- strdb_insert (map_db, mdos->name, mdos);
+ map_db.put(mdos->name, (struct map_data *)mdos);
}
else
{
if (md->gat)
- { // local -> check data
- if (ip.s_addr != clif_getip ().s_addr || port != clif_getport ())
+ {
+ // local -> check data
+ if (ip.s_addr != clif_getip().s_addr || port != clif_getport())
{
- printf ("from char server : %s -> %s:%d\n", name, ip2str(ip),
+ PRINTF("from char server : %s -> %s:%d\n", name, ip2str(ip),
port);
return 1;
}
}
else
- { // update
+ {
+ // update
+ struct map_data_other_server *mdos = NULL;
mdos = (struct map_data_other_server *) md;
mdos->ip = ip;
mdos->port = port;
@@ -1589,139 +1374,54 @@ int map_setipport (const char *name, struct in_addr ip, int port)
return 0;
}
-// åˆæœŸåŒ–周り
-/*==========================================
- * 水場高ã•è¨­å®š
- *------------------------------------------
- */
-static struct Waterlist
-{
- char mapname[24];
- int waterheight;
-} *waterlist = NULL;
-
-#define NO_WATER 1000000
-
-static int map_waterheight (char *mapname)
-{
- if (waterlist)
- {
- int i;
- for (i = 0; waterlist[i].mapname[0] && i < MAX_MAP_PER_SERVER; i++)
- if (strcmp (waterlist[i].mapname, mapname) == 0)
- return waterlist[i].waterheight;
- }
- return NO_WATER;
-}
-
-static void map_readwater (char *watertxt)
-{
- char line[1024], w1[1024];
- FILE *fp = NULL;
- int n = 0;
-
- fp = fopen_ (watertxt, "r");
- if (fp == NULL)
- {
- printf ("file not found: %s\n", watertxt);
- return;
- }
- if (waterlist == NULL)
- {
- CREATE (waterlist, struct Waterlist, MAX_MAP_PER_SERVER);
- }
- while (fgets (line, 1020, fp) && n < MAX_MAP_PER_SERVER)
- {
- int wh, count;
- if (line[0] == '/' && line[1] == '/')
- continue;
- if ((count = sscanf (line, "%s%d", w1, &wh)) < 1)
- {
- continue;
- }
- strcpy (waterlist[n].mapname, w1);
- if (count >= 2)
- waterlist[n].waterheight = wh;
- else
- waterlist[n].waterheight = 3;
- n++;
- }
- fclose_ (fp);
-}
-
/*==========================================
* マップ1枚読ã¿è¾¼ã¿
*------------------------------------------
*/
-static int map_readmap (int m, char *fn, char *alias)
+static
+bool map_readmap(int m, const_string fn)
{
- int s;
- int x, y, xs, ys;
- struct gat_1cell
- {
- char type;
- } *p;
- int wh;
- size_t size;
-
// read & convert fn
- uint8_t *gat = (uint8_t *)grfio_read (fn);
- if (gat == NULL)
- return -1;
-
- printf ("\rLoading Maps [%d/%d]: %-50s ", m, map_num, fn);
- fflush (stdout);
+ std::vector<uint8_t> gat_v = grfio_reads(fn);
+ if (gat_v.empty())
+ return false;
+ size_t s = gat_v.size() - 4;
map[m].m = m;
- xs = map[m].xs = *(short *) (gat);
- ys = map[m].ys = *(short *) (gat + 2);
- printf ("\n%i %i\n", xs, ys);
- map[m].gat = (uint8_t *)calloc (s = map[m].xs * map[m].ys, 1);
+ int xs = map[m].xs = gat_v[0] | gat_v[1] << 8;
+ int ys = map[m].ys = gat_v[2] | gat_v[3] << 8;
+ PRINTF("\rLoading Maps [%d/%d]: %-30s (%i, %i)",
+ m, map_num, std::string(fn.begin(), fn.end()), xs, ys);
+ fflush(stdout);
+
+ assert (s == xs * ys);
+ map[m].gat = make_unique<MapCell[]>(s);
if (map[m].gat == NULL)
{
- printf ("out of memory : map_readmap gat\n");
- exit (1);
+ PRINTF("out of memory : map_readmap gat\n");
+ exit(1);
}
map[m].npc_num = 0;
map[m].users = 0;
- memset (&map[m].flag, 0, sizeof (map[m].flag));
+ memset(&map[m].flag, 0, sizeof(map[m].flag));
if (battle_config.pk_mode)
map[m].flag.pvp = 1; // make all maps pvp for pk_mode [Valaris]
- wh = map_waterheight (map[m].name);
- for (y = 0; y < ys; y++)
- {
- p = (struct gat_1cell *) (gat + y * xs + 4);
- for (x = 0; x < xs; x++)
- {
- /*if(wh!=NO_WATER && p->type==0){
- * // 水場判定
- * map[m].gat[x+y*xs]=(p->high[0]>wh || p->high[1]>wh || p->high[2]>wh || p->high[3]>wh) ? 3 : 0;
- * } else { */
- map[m].gat[x + y * xs] = p->type;
- //}
- p++;
- }
- }
- free (gat);
+ MapCell *gat_m = reinterpret_cast<MapCell *>(&gat_v[4]);
+ std::copy(gat_m, gat_m + s, &map[m].gat[0]);
map[m].bxs = (xs + BLOCK_SIZE - 1) / BLOCK_SIZE;
map[m].bys = (ys + BLOCK_SIZE - 1) / BLOCK_SIZE;
- size = map[m].bxs * map[m].bys;
-
- CREATE (map[m].block, struct block_list *, size);
-
- CREATE (map[m].block_mob, struct block_list *, size);
-
- CREATE (map[m].block_count, int, size);
-
- CREATE (map[m].block_mob_count, int, size);
+ size_t size = map[m].bxs * map[m].bys;
- strdb_insert (map_db, map[m].name, &map[m]);
+ CREATE(map[m].block, struct block_list *, size);
+ CREATE(map[m].block_mob, struct block_list *, size);
+ CREATE(map[m].block_count, int, size);
+ CREATE(map[m].block_mob_count, int, size);
-// printf("%s read done\n",fn);
+ map_db.put(map[m].name, &map[m]);
- return 0;
+ return true;
}
/*==========================================
@@ -1729,57 +1429,26 @@ static int map_readmap (int m, char *fn, char *alias)
*------------------------------------------
*/
static
-int map_readallmap (void)
+int map_readallmap(void)
{
- int i, maps_removed = 0;
- char fn[256] = "";
+ int i, maps_removed = 0;
- // å…ˆã«å…¨éƒ¨ã®ãƒ£bプã®å­˜åœ¨ã‚’確èª
- for (i = 0; i < map_num; i++)
- {
- if (strstr (map[i].name, ".gat") == NULL)
- continue;
- sprintf (fn, "data\\%s", map[i].name);
- // 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++;
- }
- }
for (i = 0; i < map_num; i++)
{
- if (strstr (map[i].name, ".gat") != NULL)
+ assert (strstr(map[i].name, ".gat") != NULL);
{
- char *p = strstr (map[i].name, ">"); // [MouseJstr]
- if (p != NULL)
{
- char alias[64];
- *p = '\0';
- strcpy (alias, map[i].name);
- strcpy (map[i].name, p + 1);
- sprintf (fn, "data\\%s", map[i].name);
- if (map_readmap (i, fn, alias) == -1)
+ if (!map_readmap(i, map[i].name))
{
- map_delmap (map[i].name);
- maps_removed++;
- }
- }
- else
- {
- sprintf (fn, "data\\%s", map[i].name);
- if (map_readmap (i, fn, NULL) == -1)
- {
- map_delmap (map[i].name);
+ map_delmap(map[i].name);
maps_removed++;
}
}
}
}
- free (waterlist);
- printf ("\rMaps Loaded: %d %60s\n", map_num, "");
- printf ("\rMaps Removed: %d \n", maps_removed);
+ PRINTF("\rMaps Loaded: %d %60s\n", map_num, "");
+ PRINTF("\rMaps Removed: %d \n", maps_removed);
return 0;
}
@@ -1788,9 +1457,9 @@ int map_readallmap (void)
*------------------------------------------
*/
static
-int map_addmap (char *mapname)
+int map_addmap(const char *mapname)
{
- if (strcasecmp (mapname, "clear") == 0)
+ if (strcasecmp(mapname, "clear") == 0)
{
map_num = 0;
return 0;
@@ -1798,10 +1467,10 @@ int map_addmap (char *mapname)
if (map_num >= MAX_MAP_PER_SERVER - 1)
{
- printf ("too many map\n");
+ PRINTF("too many map\n");
return 1;
}
- memcpy (map[map_num].name, mapname, 24);
+ memcpy(map[map_num].name, mapname, 24);
map_num++;
return 0;
}
@@ -1810,11 +1479,12 @@ int map_addmap (char *mapname)
* 読ã¿è¾¼ã‚€mapを削除ã™ã‚‹
*------------------------------------------
*/
-int map_delmap (char *mapname)
+static
+int map_delmap(const char *mapname)
{
- int i;
+ int i;
- if (strcasecmp (mapname, "all") == 0)
+ if (strcasecmp(mapname, "all") == 0)
{
map_num = 0;
return 0;
@@ -1822,84 +1492,94 @@ int map_delmap (char *mapname)
for (i = 0; i < map_num; i++)
{
- if (strcmp (map[i].name, mapname) == 0)
+ if (strcmp(map[i].name, mapname) == 0)
{
- printf ("Removing map [ %s ] from maplist\n", map[i].name);
- memmove (map + i, map + i + 1,
- sizeof (map[0]) * (map_num - i - 1));
+ PRINTF("Removing map [ %s ] from maplist\n", map[i].name);
+ memmove(map + i, map + i + 1,
+ sizeof(map[0]) * (map_num - i - 1));
map_num--;
}
}
return 0;
}
-extern char *gm_logfile_name;
-
-#define LOGFILE_SECONDS_PER_CHUNK_SHIFT 10
+constexpr int LOGFILE_SECONDS_PER_CHUNK_SHIFT = 10;
+static
FILE *map_logfile = NULL;
+static
char *map_logfile_name = NULL;
-static long map_logfile_index;
+static
+long map_logfile_index;
-static void map_close_logfile (void)
+static
+void map_close_logfile(void)
{
if (map_logfile)
{
- char *filenameop_buf = (char*)malloc (strlen (map_logfile_name) + 50);
- sprintf (filenameop_buf, "gzip -f %s.%ld &", map_logfile_name,
- map_logfile_index);
-
- fclose (map_logfile);
+ std::string filename = STRPRINTF("%s.%ld", map_logfile_name, map_logfile_index);
+ const char *args[] =
+ {
+ "gzip",
+ "-f",
+ filename.c_str(),
+ NULL
+ };
+ char **argv = const_cast<char **>(args);
- if (!system (filenameop_buf))
- perror (filenameop_buf);
+ fclose(map_logfile);
- free (filenameop_buf);
+ if (!fork())
+ {
+ execvp("gzip", argv);
+ _exit(1);
+ }
+ wait(NULL);
}
}
-static void map_start_logfile (long suffix)
+static
+void map_start_logfile(long index)
{
- char *filename_buf = (char*)malloc (strlen (map_logfile_name) + 50);
- map_logfile_index = suffix >> LOGFILE_SECONDS_PER_CHUNK_SHIFT;
+ map_logfile_index = index;
- sprintf (filename_buf, "%s.%ld", map_logfile_name, map_logfile_index);
- map_logfile = fopen (filename_buf, "w+");
+ std::string filename_buf = STRPRINTF(
+ "%s.%ld",
+ map_logfile_name,
+ map_logfile_index);
+ map_logfile = fopen(filename_buf.c_str(), "w+");
if (!map_logfile)
- perror (map_logfile_name);
-
- free (filename_buf);
+ perror(map_logfile_name);
}
-static void map_set_logfile (const char *filename)
+static
+void map_set_logfile(const char *filename)
{
struct timeval tv;
- map_logfile_name = strdup (filename);
- gettimeofday (&tv, NULL);
+ map_logfile_name = strdup(filename);
+ gettimeofday(&tv, NULL);
- map_start_logfile (tv.tv_sec);
+ map_start_logfile(tv.tv_sec);
- MAP_LOG ("log-start v3");
+ MAP_LOG("log-start v4");
}
-void map_write_log (const char *format, ...)
+void map_log(const_string line)
{
- struct timeval tv;
- va_list args;
- va_start (args, format);
+ if (!map_logfile)
+ return;
- gettimeofday (&tv, NULL);
+ time_t t = TimeT::now();
+ long i = t >> LOGFILE_SECONDS_PER_CHUNK_SHIFT;
- if ((tv.tv_sec >> LOGFILE_SECONDS_PER_CHUNK_SHIFT) != map_logfile_index)
+ if (i != map_logfile_index)
{
- map_close_logfile ();
- map_start_logfile (tv.tv_sec);
+ map_close_logfile();
+ map_start_logfile(i);
}
- fprintf (map_logfile, "%ld.%06ld ", (long) tv.tv_sec, (long) tv.tv_usec);
- vfprintf (map_logfile, format, args);
- fputc ('\n', map_logfile);
+ log_with_timestamp(map_logfile, line);
}
/*==========================================
@@ -1907,216 +1587,198 @@ void map_write_log (const char *format, ...)
*------------------------------------------
*/
static
-int map_config_read (const char *cfgName)
+int map_config_read(const char *cfgName)
{
- char line[1024], w1[1024], w2[1024];
- FILE *fp;
struct hostent *h = NULL;
- fp = fopen_ (cfgName, "r");
- if (fp == NULL)
+ std::ifstream in(cfgName);
+ if (!in.is_open())
{
- printf ("Map configuration file not found at: %s\n", cfgName);
- exit (1);
+ PRINTF("Map configuration file not found at: %s\n", cfgName);
+ exit(1);
}
- while (fgets (line, sizeof (line) - 1, fp))
+
+ std::string line;
+ while (std::getline(in, line))
{
- if (line[0] == '/' && line[1] == '/')
+ std::string w1, w2;
+ if (!split_key_value(line, &w1, &w2))
continue;
- if (sscanf (line, "%[^:]: %[^\r\n]", w1, w2) == 2)
+ if (w1 == "userid")
{
- if (strcasecmp (w1, "userid") == 0)
- {
- chrif_setuserid (w2);
- }
- else if (strcasecmp (w1, "passwd") == 0)
- {
- chrif_setpasswd (w2);
- }
- else if (strcasecmp (w1, "char_ip") == 0)
+ chrif_setuserid(w2.c_str());
+ }
+ else if (w1 == "passwd")
+ {
+ chrif_setpasswd(w2.c_str());
+ }
+ else if (w1 == "char_ip")
+ {
+ h = gethostbyname(w2.c_str());
+ if (h != NULL)
{
- h = gethostbyname (w2);
- if (h != NULL)
- {
- printf
- ("Character server IP address : %s -> %d.%d.%d.%d\n",
- w2, (unsigned char) h->h_addr[0],
+ 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(w2, "%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]);
- sprintf (w2, "%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]);
- }
- chrif_setip (w2);
- }
- else if (strcasecmp (w1, "char_port") == 0)
- {
- chrif_setport (atoi (w2));
- }
- else if (strcasecmp (w1, "map_ip") == 0)
- {
- h = gethostbyname (w2);
- if (h != NULL)
- {
- printf ("Map 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 (w2, "%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]);
- }
- clif_setip (w2);
- }
- else if (strcasecmp (w1, "map_port") == 0)
- {
- clif_setport (atoi (w2));
- map_port = (atoi (w2));
- }
- else if (strcasecmp (w1, "water_height") == 0)
- {
- map_readwater (w2);
- }
- else if (strcasecmp (w1, "map") == 0)
- {
- map_addmap (w2);
- }
- else if (strcasecmp (w1, "delmap") == 0)
- {
- map_delmap (w2);
- }
- else if (strcasecmp (w1, "npc") == 0)
- {
- npc_addsrcfile (w2);
- }
- else if (strcasecmp (w1, "delnpc") == 0)
- {
- npc_delsrcfile (w2);
- }
- else if (strcasecmp (w1, "autosave_time") == 0)
- {
- autosave_interval = atoi (w2) * 1000;
- if (autosave_interval <= 0)
- autosave_interval = DEFAULT_AUTOSAVE_INTERVAL;
- }
- else if (strcasecmp (w1, "motd_txt") == 0)
- {
- strcpy (motd_txt, w2);
- }
- else if (strcasecmp (w1, "help_txt") == 0)
- {
- strcpy (help_txt, w2);
}
- else if (strcasecmp (w1, "mapreg_txt") == 0)
- {
- strcpy (mapreg_txt, w2);
- }
- else if (strcasecmp (w1, "gm_log") == 0)
- {
- gm_logfile_name = strdup (w2);
- }
- else if (strcasecmp (w1, "log_file") == 0)
- {
- map_set_logfile (w2);
- }
- else if (strcasecmp (w1, "import") == 0)
+ chrif_setip(w2.c_str());
+ }
+ else if (w1 == "char_port")
+ {
+ chrif_setport(atoi(w2.c_str()));
+ }
+ else if (w1 == "map_ip")
+ {
+ h = gethostbyname(w2.c_str());
+ if (h != NULL)
{
- map_config_read (w2);
+ PRINTF("Map 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(w2, "%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]);
}
+ clif_setip(w2.c_str());
+ }
+ else if (w1 == "map_port")
+ {
+ clif_setport(atoi(w2.c_str()));
+ }
+ else if (w1 == "map")
+ {
+ map_addmap(w2.c_str());
+ }
+ else if (w1 == "delmap")
+ {
+ map_delmap(w2.c_str());
+ }
+ else if (w1 == "npc")
+ {
+ npc_addsrcfile(w2.c_str());
+ }
+ else if (w1 == "delnpc")
+ {
+ npc_delsrcfile(w2.c_str());
+ }
+ else if (w1 == "autosave_time")
+ {
+ autosave_interval = std::chrono::seconds(atoi(w2.c_str()));
+ if (autosave_interval <= interval_t::zero())
+ autosave_interval = DEFAULT_AUTOSAVE_INTERVAL;
+ }
+ else if (w1 == "motd_txt")
+ {
+ strzcpy(motd_txt, w2.c_str(), sizeof(motd_txt));
+ }
+ else if (w1 == "help_txt")
+ {
+ strzcpy(help_txt, w2.c_str(), sizeof(help_txt));
+ }
+ else if (w1 == "mapreg_txt")
+ {
+ strzcpy(mapreg_txt, w2.c_str(), sizeof(mapreg_txt));
+ }
+ else if (w1 == "gm_log")
+ {
+ gm_logfile_name = strdup(w2.c_str());
+ }
+ else if (w1 == "log_file")
+ {
+ map_set_logfile(w2.c_str());
+ }
+ else if (w1 == "import")
+ {
+ map_config_read(w2.c_str());
}
}
- fclose_ (fp);
return 0;
}
-static int cleanup_sub (struct block_list *bl, va_list ap)
+static
+void cleanup_sub(struct block_list *bl)
{
- nullpo_retr (0, bl);
+ nullpo_retv(bl);
switch (bl->type)
{
- case BL_PC:
- map_delblock (bl); // There is something better...
+ case BL::PC:
+ map_delblock(bl); // There is something better...
break;
- case BL_NPC:
- npc_delete ((struct npc_data *) bl);
+ case BL::NPC:
+ npc_delete((struct npc_data *) bl);
break;
- case BL_MOB:
- mob_delete ((struct mob_data *) bl);
+ case BL::MOB:
+ mob_delete((struct mob_data *) bl);
break;
- case BL_ITEM:
- map_clearflooritem (bl->id);
+ case BL::ITEM:
+ map_clearflooritem(bl->id);
break;
- case BL_SKILL:
- skill_delunit ((struct skill_unit *) bl);
- break;
- case BL_SPELL:
- spell_free_invocation ((struct invocation *) bl);
+ case BL::SPELL:
+ spell_free_invocation((struct invocation *) bl);
break;
}
-
- return 0;
}
/*==========================================
* map鯖終了時処ç†
*------------------------------------------
*/
-void term_func (void)
+void term_func(void)
{
- map_close_logfile ();
+ map_close_logfile();
- int map_id, i;
+ int map_id, i;
for (map_id = 0; map_id < map_num; map_id++)
{
if (map[map_id].m)
- map_foreachinarea (cleanup_sub, map_id, 0, 0, map[map_id].xs,
- map[map_id].ys, 0, 0);
+ map_foreachinarea(cleanup_sub, map_id,
+ 0, 0, map[map_id].xs, map[map_id].ys,
+ BL::NUL);
}
for (i = 0; i < fd_max; i++)
- delete_session (i);
-
- map_removenpc ();
+ delete_session(i);
- numdb_final (id_db, NULL);
- strdb_final (map_db, NULL);
- strdb_final (nick_db, NULL);
- numdb_final (charid_db, NULL);
+ map_removenpc();
for (i = 0; i <= map_num; i++)
{
- if (map[i].gat)
- free (map[i].gat);
+ map[i].gat = nullptr;
if (map[i].block)
- free (map[i].block);
+ free(map[i].block);
if (map[i].block_mob)
- free (map[i].block_mob);
+ free(map[i].block_mob);
if (map[i].block_count)
- free (map[i].block_count);
+ free(map[i].block_count);
if (map[i].block_mob_count)
- free (map[i].block_mob_count);
+ free(map[i].block_mob_count);
}
- do_final_script ();
- do_final_itemdb ();
- do_final_storage ();
- do_final_guild ();
+ do_final_script();
+ do_final_itemdb();
+ do_final_storage();
}
/// --help was passed
// FIXME this should produce output
-void map_helpscreen (void)
+static __attribute__((noreturn))
+void map_helpscreen(void)
{
- exit (1);
+ exit(1);
}
-int compare_item (struct item *a, struct item *b)
+int compare_item(struct item *a, struct item *b)
{
return ((a->nameid == b->nameid) &&
(a->identify == b->identify) &&
@@ -2131,86 +1793,71 @@ int compare_item (struct item *a, struct item *b)
* Map-Server Init and Command-line Arguments [Valaris]
*------------------------------------------------------
*/
-int do_init (int argc, char *argv[])
+int do_init(int argc, char *argv[])
{
- int i;
+ int i;
const char *MAP_CONF_NAME = "conf/map_athena.conf";
const char *BATTLE_CONF_FILENAME = "conf/battle_athena.conf";
const char *ATCOMMAND_CONF_FILENAME = "conf/atcommand_athena.conf";
- const char *SCRIPT_CONF_NAME = "conf/script_athena.conf";
- const char *MSG_CONF_NAME = "conf/msg_athena.conf";
for (i = 1; i < argc; i++)
{
- if (strcmp (argv[i], "--help") == 0 || strcmp (argv[i], "--h") == 0
- || strcmp (argv[i], "--?") == 0 || strcmp (argv[i], "/?") == 0)
- map_helpscreen ();
- else if (strcmp (argv[i], "--map_config") == 0)
+ if (strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "--h") == 0
+ || strcmp(argv[i], "--?") == 0 || strcmp(argv[i], "/?") == 0)
+ map_helpscreen();
+ else if (strcmp(argv[i], "--map_config") == 0)
MAP_CONF_NAME = argv[i + 1];
- else if (strcmp (argv[i], "--battle_config") == 0)
+ else if (strcmp(argv[i], "--battle_config") == 0)
BATTLE_CONF_FILENAME = argv[i + 1];
- else if (strcmp (argv[i], "--atcommand_config") == 0)
+ else if (strcmp(argv[i], "--atcommand_config") == 0)
ATCOMMAND_CONF_FILENAME = argv[i + 1];
- else if (strcmp (argv[i], "--script_config") == 0)
- SCRIPT_CONF_NAME = argv[i + 1];
- else if (strcmp (argv[i], "--msg_config") == 0)
- MSG_CONF_NAME = argv[i + 1];
}
- map_config_read (MAP_CONF_NAME);
- battle_config_read (BATTLE_CONF_FILENAME);
- atcommand_config_read (ATCOMMAND_CONF_FILENAME);
- script_config_read (SCRIPT_CONF_NAME);
-
- id_db = numdb_init ();
- map_db = strdb_init (16);
- nick_db = strdb_init (24);
- charid_db = numdb_init ();
-
- map_readallmap ();
+ map_config_read(MAP_CONF_NAME);
+ battle_config_read(BATTLE_CONF_FILENAME);
+ atcommand_config_read(ATCOMMAND_CONF_FILENAME);
+ script_config_read();
-// add_timer_func_list (map_clearflooritem_timer, "map_clearflooritem_timer");
+ map_readallmap();
do_init_chrif ();
do_init_clif ();
- do_init_itemdb ();
- do_init_mob (); // npcã®åˆæœŸåŒ–時内ã§mob_spawnã—ã¦ã€mob_dbã‚’å‚ç…§ã™ã‚‹ã®ã§init_npcより先
- do_init_script ();
- do_init_npc ();
- do_init_pc ();
- do_init_party ();
- do_init_guild ();
- do_init_storage ();
- do_init_skill ();
- do_init_magic ();
-
- npc_event_do_oninit (); // npcã®OnInitイベント実行
+ do_init_itemdb();
+ do_init_mob(); // npcã®åˆæœŸåŒ–時内ã§mob_spawnã—ã¦ã€mob_dbã‚’å‚ç…§ã™ã‚‹ã®ã§init_npcより先
+ do_init_script();
+ do_init_npc();
+ do_init_pc();
+ do_init_party();
+ do_init_storage();
+ do_init_skill();
+ do_init_magic();
+
+ npc_event_do_oninit(); // npcã®OnInitイベント実行
if (battle_config.pk_mode == 1)
- printf ("The server is running in \033[1;31mPK Mode\033[0m.\n");
+ PRINTF("The server is running in \033[1;31mPK Mode\033[0m.\n");
- printf
- ("The map-server is \033[1;32mready\033[0m (Server is listening on the port %d).\n\n",
+ PRINTF("The map-server is \033[1;32mready\033[0m (Server is listening on the port %d).\n\n",
map_port);
return 0;
}
-int map_scriptcont (struct map_session_data *sd, int id)
+int map_scriptcont(struct map_session_data *sd, int id)
{
- struct block_list *bl = map_id2bl (id);
+ struct block_list *bl = map_id2bl(id);
if (!bl)
return 0;
switch (bl->type)
{
- case BL_NPC:
- return npc_scriptcont (sd, id);
- case BL_SPELL:
- spell_execute_script ((struct invocation *) bl);
+ case BL::NPC:
+ return npc_scriptcont(sd, id);
+ case BL::SPELL:
+ spell_execute_script((struct invocation *) bl);
break;
}
diff --git a/src/map/map.hpp b/src/map/map.hpp
index 8130739..374282d 100644
--- a/src/map/map.hpp
+++ b/src/map/map.hpp
@@ -1,166 +1,83 @@
-// $Id: map.h,v 1.8 2004/09/25 11:39:17 MouseJstr Exp $
#ifndef MAP_HPP
#define MAP_HPP
-#include <stdio.h>
-#include <stdarg.h>
-#include <time.h>
-#include <sys/time.h>
+#include "map.t.hpp"
+
#include <netinet/in.h>
-#include "../common/mmo.hpp"
-#include "../common/timer.hpp"
+
+#include <functional>
+
#include "../common/db.hpp"
-#include "script.hpp"
-
-#ifndef MAX
-# define MAX(x,y) (((x)>(y)) ? (x) : (y))
-#endif
-#ifndef MIN
-# define MIN(x,y) (((x)<(y)) ? (x) : (y))
-#endif
-
-#define MAX_PC_CLASS (1+6+6+1+6+1+1+1+1+4023)
-#define PC_CLASS_BASE 0
-#define PC_CLASS_BASE2 (PC_CLASS_BASE + 4001)
-#define PC_CLASS_BASE3 (PC_CLASS_BASE2 + 22)
-#define MAX_NPC_PER_MAP 512
-#define BLOCK_SIZE 8
+#include "../common/timer.t.hpp"
+
+#include "battle.t.hpp"
+#include "magic-interpreter.t.hpp"
+#include "mob.t.hpp"
+#include "script.hpp" // change to script.t.hpp
+#include "skill.t.hpp"
+
+constexpr int MAX_NPC_PER_MAP = 512;
+constexpr int BLOCK_SIZE = 8;
#define AREA_SIZE battle_config.area_size
-#define LOCAL_REG_NUM 16
-#define LIFETIME_FLOORITEM 60
-#define DAMAGELOG_SIZE 30
-#define LOOTITEM_SIZE 10
-#define MAX_SKILL_LEVEL 100
-#define MAX_STATUSCHANGE 200
-#define MAX_SKILLUNITGROUP 32
-#define MAX_MOBSKILLUNITGROUP 8
-#define MAX_SKILLUNITGROUPTICKSET 128
-#define MAX_SKILLTIMERSKILL 32
-#define MAX_MOBSKILLTIMERSKILL 10
-#define MAX_MOBSKILL 32
-#define MAX_EVENTQUEUE 2
-#define MAX_EVENTTIMER 32
-#define NATURAL_HEAL_INTERVAL 500
-#define MAX_FLOORITEM 500000
-#define MAX_LEVEL 255
-#define MAX_WALKPATH 48
-#define MAX_DROP_PER_MAP 48
-
-#define DEFAULT_AUTOSAVE_INTERVAL 60*1000
-
-// [Fate] status.option properties. These are persistent status changes.
-// IDs that are not listed are not used in the code (to the best of my knowledge)
-#define OPTION_HIDE2 0x0002 // apparently some weaker non-GM hide
-#define OPTION_CLOAK 0x0004
-#define OPTION_10 0x0010
-#define OPTION_20 0x0020
-#define OPTION_HIDE 0x0040 // [Fate] This is the GM `@hide' flag
-#define OPTION_800 0x0800
-#define OPTION_INVISIBILITY 0x1000 // [Fate] Complete invisibility to other clients
-#define OPTION_SCRIBE 0x2000 // [Fate] Auto-logging of nearby comments
-#define OPTION_CHASEWALK 0x4000
-
-// Below are special clif_changestatus() IDs reserved for option updates
-#define CLIF_OPTION_SC_BASE 0x1000
-#define CLIF_OPTION_SC_INVISIBILITY (CLIF_OPTION_SC_BASE)
-#define CLIF_OPTION_SC_SCRIBE (CLIF_OPTION_SC_BASE + 1)
-
-enum
-{ BL_NUL, BL_PC, BL_NPC, BL_MOB, BL_ITEM, BL_CHAT, BL_SKILL, BL_SPELL };
-enum
-{ WARP, SHOP, SCRIPT, MONS, MESSAGE };
+constexpr std::chrono::seconds LIFETIME_FLOORITEM = std::chrono::minutes(1);
+constexpr int DAMAGELOG_SIZE = 30;
+constexpr int LOOTITEM_SIZE = 10;
+constexpr int MAX_SKILL_LEVEL = 100;
+constexpr int MAX_MOBSKILL = 32;
+constexpr int MAX_EVENTQUEUE = 2;
+constexpr int MAX_EVENTTIMER = 32;
+constexpr interval_t NATURAL_HEAL_INTERVAL = std::chrono::milliseconds(500);
+constexpr int MAX_FLOORITEM = 500000;
+constexpr int MAX_LEVEL = 255;
+constexpr int MAX_WALKPATH = 48;
+constexpr int MAX_DROP_PER_MAP = 48;
+
+constexpr interval_t DEFAULT_AUTOSAVE_INTERVAL = std::chrono::minutes(1);
+
struct block_list
{
struct block_list *next, *prev;
- int id;
+ int id;
short m, x, y;
- unsigned char type;
- unsigned char subtype;
+ BL type;
+ NpcSubtype subtype;
};
struct walkpath_data
{
unsigned char path_len, path_pos, path_half;
- unsigned char path[MAX_WALKPATH];
+ DIR path[MAX_WALKPATH];
};
struct script_reg
{
- int index;
- int data;
+ int index;
+ int data;
};
struct script_regstr
{
- int index;
+ int index;
char data[256];
};
struct status_change
{
- int timer;
- int val1, val2, val3, val4;
- int spell_invocation; /* [Fate] If triggered by a spell, record here */
+ Timer timer;
+ int val1;
+ int spell_invocation; /* [Fate] If triggered by a spell, record here */
};
struct invocation;
-struct skill_unit_group;
-struct skill_unit
-{
- struct block_list bl;
-
- struct skill_unit_group *group;
-
- int limit;
- int val1, val2;
- short alive, range;
-};
-struct skill_unit_group
-{
- int src_id;
- int party_id;
- int guild_id;
- int map, range;
- int target_flag;
- unsigned int tick;
- int limit, interval;
-
- int skill_id, skill_lv;
- int val1, val2;
- char *valstr;
- int unit_id;
- int group_id;
- int unit_count, alive_count;
- struct skill_unit *unit;
-};
-struct skill_unit_group_tickset
-{
- unsigned int tick;
- int group_id;
-};
-struct skill_timerskill
-{
- int timer;
- int src_id;
- int target_id;
- int map;
- short x, y;
- short skill_id, skill_lv;
- int type;
- int flag;
-};
-
struct npc_data;
struct item_data;
struct square;
struct quick_regeneration
{ // [Fate]
- int amount; // Amount of HP/SP left to regenerate
+ int amount; // Amount of HP/SP left to regenerate
unsigned char speed; // less is faster (number of half-second ticks to wait between updates)
unsigned char tickdelay; // number of ticks to next update
};
-#define VERSION_2_SKILLINFO 0x02 // client supports full skillinfo blocks
-
struct map_session_data
{
struct block_list bl;
@@ -176,13 +93,12 @@ struct map_session_data
unsigned lr_flag:2;
unsigned connect_new:1;
unsigned arrow_atk:1;
- unsigned attack_type:3;
+ BF attack_type;//:3;
unsigned skill_flag:1;
unsigned gangsterparadise:1;
unsigned produce_flag:1;
unsigned make_arrow_flag:1;
- unsigned potionpitcher_flag:1;
- unsigned storage_flag:2; //0: closed, 1: Normal Storage open, 2: guild storage open [Skotlex]
+ unsigned storage_open:1;
unsigned shroud_active:1;
unsigned shroud_hides_name_talking:1;
unsigned shroud_disappears_on_pickup:1;
@@ -192,42 +108,35 @@ struct map_session_data
{
unsigned killer:1;
unsigned killable:1;
- unsigned restart_full_recover:1;
- unsigned no_castcancel:1;
- unsigned no_castcancel2:1;
- unsigned no_sizefix:1;
- unsigned no_magic_damage:1;
- unsigned no_weapon_damage:1;
- unsigned no_gemstone:1;
- unsigned infinite_endure:1;
unsigned unbreakable_weapon:1;
unsigned unbreakable_armor:1;
- unsigned infinite_autospell:1;
unsigned deaf:1;
} special_state;
- int char_id, login_id1, login_id2, sex;
+ int char_id, login_id1, login_id2, sex;
unsigned char tmw_version; // tmw client version
struct mmo_charstatus status;
struct item_data *inventory_data[MAX_INVENTORY];
- short equip_index[11];
- int weight, max_weight;
- int cart_weight, cart_max_weight, cart_num, cart_max_num;
+ earray<short, EQUIP, EQUIP::COUNT> equip_index;
+ int weight, max_weight;
+ int cart_weight, cart_max_weight, cart_num, cart_max_num;
char mapname[24];
- int fd, new_fd;
+ int fd, new_fd;
short to_x, to_y;
- short speed, prev_speed;
- short opt1, opt2, opt3;
- char dir, head_dir;
- unsigned int client_tick, server_tick;
+ interval_t speed;
+ Opt1 opt1;
+ Opt2 opt2;
+ Opt3 opt3;
+ DIR dir, head_dir;
+ tick_t client_tick, server_tick;
struct walkpath_data walkpath;
- int walktimer;
- int npc_id, areanpc_id, npc_shopid;
- int npc_pos;
- int npc_menu;
- int npc_amount;
- int npc_stack, npc_stackmax;
+ Timer walktimer;
+ int npc_id, areanpc_id, npc_shopid;
+ int npc_pos;
+ int npc_menu;
+ int npc_amount;
+ int npc_stack, npc_stackmax;
const ScriptCode *npc_script, *npc_scriptroot;
- char *npc_stackbuf;
+ struct script_data *npc_stackbuf;
char npc_str[256];
struct
{
@@ -236,158 +145,105 @@ struct map_session_data
} npc_flags;
unsigned int chatID;
- int attacktimer;
- int attacktarget;
- short attacktarget_lv;
- unsigned int attackabletime;
+ Timer attacktimer;
+ int attacktarget;
+ ATK attacktarget_lv;
+ tick_t attackabletime;
- int followtimer; // [MouseJstr]
- int followtarget;
+ // used by @hugo and @linus
+ int followtarget;
- unsigned int cast_tick; // [Fate] Next tick at which spellcasting is allowed
+ tick_t cast_tick; // [Fate] Next tick at which spellcasting is allowed
struct invocation *active_spells; // [Fate] Singly-linked list of active spells linked to this PC
- int attack_spell_override; // [Fate] When an attack spell is active for this player, they trigger it
+ int attack_spell_override; // [Fate] When an attack spell is active for this player, they trigger it
// like a weapon. Check pc_attack_timer() for details.
- short attack_spell_icon_override; // Weapon equipment slot (slot 4) item override
+ // Weapon equipment slot (slot 4) item override
+ StatusChange attack_spell_icon_override;
short attack_spell_look_override; // Weapon `look' (attack animation) override
short attack_spell_charges; // [Fate] Remaining number of charges for the attack spell
- short attack_spell_delay; // [Fate] ms delay after spell attack
+ interval_t attack_spell_delay; // [Fate] ms delay after spell attack
short attack_spell_range; // [Fate] spell range
short spellpower_bonus_target, spellpower_bonus_current; // [Fate] Spellpower boni. _current is the active one.
//_current slowly approximates _target, and _target is determined by equipment.
short attackrange, attackrange_;
- int skilltimer;
- int skilltarget;
- short skillx, skilly;
- short skillid, skilllv;
- short skillitem, skillitemlv;
- short skillid_old, skilllv_old;
- short skillid_dance, skilllv_dance;
- struct skill_unit_group skillunit[MAX_SKILLUNITGROUP];
- struct skill_unit_group_tickset skillunittick[MAX_SKILLUNITGROUPTICKSET];
- struct skill_timerskill skilltimerskill[MAX_SKILLTIMERSKILL];
- int cloneskill_id, cloneskill_lv;
- int potion_hp, potion_sp, potion_per_hp, potion_per_sp;
// [Fate] Used for gradual healing; amount of enqueued regeneration
struct quick_regeneration quick_regeneration_hp, quick_regeneration_sp;
// [Fate] XP that can be extracted from this player by healing
- int heal_xp; // i.e., OTHER players (healers) can partake in this player's XP
-
- int invincible_timer;
- unsigned int canact_tick;
- unsigned int canmove_tick;
- unsigned int canlog_tick;
- int hp_sub, sp_sub;
- int inchealhptick, inchealsptick, inchealspirithptick,
- inchealspiritsptick;
-// -- moonsoul (new tick for berserk self-damage)
- int berserkdamagetick;
- int fame;
-
- short view_class;
- short weapontype1, weapontype2;
- short disguiseflag, disguise; // [Valaris]
- int paramb[6], paramc[6], parame[6], paramcard[6];
- int hit, flee, flee2, aspd, amotion, dmotion;
- int watk, watk2, atkmods[3];
- int def, def2, mdef, mdef2, critical, matk1, matk2;
- int atk_ele, def_ele, star, overrefine;
- int castrate, hprate, sprate, dsprate;
- int addele[10], addrace[12], addsize[3], subele[10], subrace[12];
- int addeff[10], addeff2[10], reseff[10];
- int watk_, watk_2, atkmods_[3], addele_[10], addrace_[12], addsize_[3]; //二刀æµã®ãŸã‚ã«è¿½åŠ 
- int atk_ele_, star_, overrefine_; //二刀æµã®ãŸã‚ã«è¿½åŠ 
- int base_atk, atk_rate;
- int arrow_atk, arrow_ele, arrow_cri, arrow_hit, arrow_range;
- int arrow_addele[10], arrow_addrace[12], arrow_addsize[3],
- arrow_addeff[10], arrow_addeff2[10];
- int nhealhp, nhealsp, nshealhp, nshealsp, nsshealhp, nsshealsp;
- int aspd_rate, speed_rate, hprecov_rate, sprecov_rate, critical_def,
+ int heal_xp; // i.e., OTHER players (healers) can partake in this player's XP
+
+ Timer invincible_timer;
+ tick_t canact_tick;
+ tick_t canmove_tick;
+ tick_t canlog_tick;
+ interval_t hp_sub, sp_sub;
+ interval_t inchealhptick, inchealsptick;
+
+ ItemLook weapontype1, weapontype2;
+ earray<int, ATTR, ATTR::COUNT> paramb, paramc, parame, paramcard;
+ int hit, flee, flee2;
+ interval_t aspd, amotion, dmotion;
+ int watk, watk2;
+ int def, def2, mdef, mdef2, critical, matk1, matk2;
+ int star, overrefine;
+ int hprate, sprate, dsprate;
+ int watk_, watk_2;
+ int star_, overrefine_; //二刀æµã®ãŸã‚ã«è¿½åŠ 
+ int base_atk, atk_rate;
+ int arrow_atk;
+ int arrow_cri, arrow_hit, arrow_range;
+ int nhealhp, nhealsp, nshealhp, nshealsp, nsshealhp, nsshealsp;
+ int aspd_rate, speed_rate, hprecov_rate, sprecov_rate, critical_def,
double_rate;
- int near_attack_def_rate, long_attack_def_rate, magic_def_rate,
- misc_def_rate;
- int matk_rate, ignore_def_ele, ignore_def_race, ignore_def_ele_,
- ignore_def_race_;
- int ignore_mdef_ele, ignore_mdef_race;
- int magic_addele[10], magic_addrace[12], magic_subrace[12];
- int perfect_hit, get_zeny_num;
- int critical_rate, hit_rate, flee_rate, flee2_rate, def_rate, def2_rate,
+ int matk_rate;
+ int perfect_hit;
+ int critical_rate, hit_rate, flee_rate, flee2_rate, def_rate, def2_rate,
mdef_rate, mdef2_rate;
- int def_ratio_atk_ele, def_ratio_atk_ele_, def_ratio_atk_race,
- def_ratio_atk_race_;
- int add_damage_class_count, add_damage_class_count_,
- add_magic_damage_class_count;
- short add_damage_classid[10], add_damage_classid_[10],
- add_magic_damage_classid[10];
- int add_damage_classrate[10], add_damage_classrate_[10],
- add_magic_damage_classrate[10];
- short add_def_class_count, add_mdef_class_count;
- short add_def_classid[10], add_mdef_classid[10];
- int add_def_classrate[10], add_mdef_classrate[10];
- short monster_drop_item_count;
- short monster_drop_itemid[10];
- int monster_drop_race[10], monster_drop_itemrate[10];
- int double_add_rate, speed_add_rate, aspd_add_rate, perfect_hit_add,
- get_zeny_add_num;
- short splash_range, splash_add_range;
- short autospell_id, autospell_lv, autospell_rate;
+ int double_add_rate, speed_add_rate, aspd_add_rate, perfect_hit_add;
short hp_drain_rate, hp_drain_per, sp_drain_rate, sp_drain_per;
short hp_drain_rate_, hp_drain_per_, sp_drain_rate_, sp_drain_per_;
- int short_weapon_damage_return, long_weapon_damage_return;
- int weapon_coma_ele[10], weapon_coma_race[12];
short break_weapon_rate, break_armor_rate;
short add_steal_rate;
- short spiritball, spiritball_old;
- int spirit_timer[MAX_SKILL_LEVEL];
- int magic_damage_return; // AppleGirl Was Here
- int random_attack_increase_add, random_attack_increase_per; // [Valaris]
- int perfect_hiding; // [Valaris]
- int unbreakable;
-
- int die_counter;
- short doridori_counter;
+ int die_counter;
- int reg_num;
+ int reg_num;
struct script_reg *reg;
- int regstr_num;
+ int regstr_num;
struct script_regstr *regstr;
- struct status_change sc_data[MAX_STATUSCHANGE];
+ earray<struct status_change, StatusChange, StatusChange::MAX_STATUSCHANGE> sc_data;
short sc_count;
struct square dev;
- int trade_partner;
- int deal_item_index[10];
- int deal_item_amount[10];
- int deal_zeny;
+ int trade_partner;
+ int deal_item_index[10];
+ int deal_item_amount[10];
+ int deal_zeny;
short deal_locked;
- int party_sended, party_invite, party_invite_account;
- int party_hp, party_x, party_y;
+ int party_sended, party_invite, party_invite_account;
+ int party_hp, party_x, party_y;
- int guild_sended, guild_invite, guild_invite_account;
- int guild_emblem_id, guild_alliance, guild_alliance_account;
- int guildspy; // [Syrus22]
- int partyspy; // [Syrus22]
+ int partyspy; // [Syrus22]
char message[80];
- int catch_target_class;
+ int catch_target_class;
- int pvp_point, pvp_rank, pvp_timer, pvp_lastusers;
+ int pvp_point, pvp_rank;
+ Timer pvp_timer;
+ int pvp_lastusers;
char eventqueue[MAX_EVENTQUEUE][50];
- int eventtimer[MAX_EVENTTIMER];
+ Timer eventtimer[MAX_EVENTTIMER];
- int last_skillid, last_skilllv; // Added by RoVeRT
struct
{
char name[24];
} ignore[80];
- int ignoreAll;
+ int ignoreAll;
short sg_count;
struct
@@ -395,14 +251,14 @@ struct map_session_data
unsigned in_progress:1;
} auto_ban_info;
- time_t chat_reset_due;
- time_t chat_repeat_reset_due;
- int chat_lines_in;
- int chat_total_repeats;
+ TimeT chat_reset_due;
+ TimeT chat_repeat_reset_due;
+ int chat_lines_in;
+ int chat_total_repeats;
char chat_lastmsg[513];
- unsigned int flood_rates[0x220];
- time_t packet_flood_reset_due;
+ tick_t flood_rates[0x220];
+ TimeT packet_flood_reset_due;
int packet_flood_in;
struct in_addr ip;
@@ -410,27 +266,32 @@ struct map_session_data
struct npc_timerevent_list
{
- int timer, pos;
+ interval_t timer;
+ int pos;
};
struct npc_label_list
{
char name[24];
- int pos;
+ int pos;
};
struct npc_item_list
{
- int nameid, value;
+ int nameid, value;
};
struct npc_data
{
struct block_list bl;
short n;
- short npc_class, dir;
- short speed;
+ short npc_class;
+ DIR dir;
+ interval_t speed;
char name[24];
char exname[24];
- int chat_id;
- short opt1, opt2, opt3, option;
+ int chat_id;
+ Opt1 opt1;
+ Opt2 opt2;
+ Opt3 opt3;
+ Option option;
short flag;
union
{
@@ -438,13 +299,14 @@ struct npc_data
{
const ScriptCode *script;
short xs, ys;
- int guild_id;
- int timer, timerid, timeramount, nexttimer;
- unsigned int timertick;
+ interval_t timer;
+ Timer timerid;
+ int timeramount, nexttimer;
+ tick_t timertick;
struct npc_timerevent_list *timer_event;
- int label_list_num;
+ int label_list_num;
struct npc_label_list *label_list;
- int src_id;
+ int src_id;
} scr;
struct npc_item_list shop_item[1];
struct
@@ -453,50 +315,33 @@ struct npc_data
short x, y;
char name[16];
} warp;
- char *message; // for MESSAGE: only send this message
+ char *message; // for NpcSubtype::MESSAGE: only send this message
} u;
// ã“ã“ã«ãƒ¡ãƒ³ãƒã‚’追加ã—ã¦ã¯ãªã‚‰ãªã„(shop_itemãŒå¯å¤‰é•·ã®ç‚º)
char eventqueue[MAX_EVENTQUEUE][50];
- int eventtimer[MAX_EVENTTIMER];
+ Timer eventtimer[MAX_EVENTTIMER];
short arenaflag;
};
-#define MOB_MODE_SUMMONED 0x1000
-#define MOB_MODE_TURNS_AGAINST_BAD_MASTER 0x2000
-
-#define MOB_SENSIBLE_MASK 0xf000 // fate: mob mode flags that I actually understand
-
-enum mob_stat
-{
- MOB_LV,
- MOB_MAX_HP,
- MOB_STR, MOB_AGI, MOB_VIT, MOB_INT, MOB_DEX, MOB_LUK,
- MOB_ATK1, MOB_ATK2, // low and high attacks
- MOB_ADELAY, // attack delay
- MOB_DEF, MOB_MDEF,
- MOB_SPEED,
- // These must come last:
- MOB_XP_BONUS, /* [Fate] Encoded as base to 1024: 1024 means 100% */
- MOB_LAST
-};
-
-#define MOB_XP_BONUS_BASE 1024
-#define MOB_XP_BONUS_SHIFT 10
+constexpr int MOB_XP_BONUS_BASE = 1024;
+constexpr int MOB_XP_BONUS_SHIFT = 10;
struct mob_data
{
struct block_list bl;
short n;
- short base_class, mob_class, dir, mode;
+ short mob_class;
+ DIR dir;
+ MobMode mode;
short m, x0, y0, xs, ys;
char name[24];
- int spawndelay1, spawndelay2;
+ interval_t spawndelay1, spawndelay2;
struct
{
- unsigned state:8;
- unsigned skillstate:8;
- unsigned targettype:1;
+ MS state;
+ MobSkillState skillstate;
+ unsigned attackable:1;
unsigned steal_flag:1;
unsigned steal_coin_flag:1;
unsigned skillcastcancel:1;
@@ -505,71 +350,64 @@ struct mob_data
unsigned walk_easy:1;
unsigned special_mob_ai:3;
} state;
- int timer;
+ Timer timer;
short to_x, to_y;
- int hp;
- int target_id, attacked_id;
- short target_lv;
+ int hp;
+ int target_id, attacked_id;
+ ATK target_lv;
struct walkpath_data walkpath;
- unsigned int next_walktime;
- unsigned int attackabletime;
- unsigned int last_deadtime, last_spawntime, last_thinktime;
- unsigned int canmove_tick;
+ tick_t next_walktime;
+ tick_t attackabletime;
+ tick_t last_deadtime, last_spawntime, last_thinktime;
+ tick_t canmove_tick;
short move_fail_count;
struct
{
- int id;
- int dmg;
+ int id;
+ int dmg;
} dmglog[DAMAGELOG_SIZE];
struct item *lootitem;
short lootitem_count;
- struct status_change sc_data[MAX_STATUSCHANGE];
+ earray<struct status_change, StatusChange, StatusChange::MAX_STATUSCHANGE> sc_data;
short sc_count;
- short opt1, opt2, opt3, option;
+ Opt1 opt1;
+ Opt2 opt2;
+ Opt3 opt3;
+ Option option;
short min_chase;
short sg_count;
- int guild_id;
- int deletetimer;
+ Timer deletetimer;
- int skilltimer;
- int skilltarget;
+ Timer skilltimer;
+ int skilltarget;
short skillx, skilly;
- short skillid, skilllv, skillidx;
- unsigned int skilldelay[MAX_MOBSKILL];
- int def_ele;
- int master_id, master_dist;
- int exclusion_src, exclusion_party, exclusion_guild;
- struct skill_timerskill skilltimerskill[MAX_MOBSKILLTIMERSKILL];
- struct skill_unit_group skillunit[MAX_MOBSKILLUNITGROUP];
- struct skill_unit_group_tickset skillunittick[MAX_SKILLUNITGROUPTICKSET];
+ SkillID skillid;
+ short skilllv, skillidx;
+ tick_t skilldelay[MAX_MOBSKILL];
+ LevelElement def_ele;
+ int master_id, master_dist;
+ int exclusion_src, exclusion_party;
char npc_event[50];
- unsigned short stats[MOB_LAST]; // [Fate] mob-specific stats
+ // [Fate] mob-specific stats
+ earray<unsigned short, mob_stat, mob_stat::LAST> stats;
short size;
};
-enum
-{ MS_IDLE, MS_WALK, MS_ATTACK, MS_DEAD, MS_DELAY };
-
-enum
-{ NONE_ATTACKABLE, ATTACKABLE };
-
-enum
-{ ATK_LUCKY = 1, ATK_FLEE, ATK_DEF }; // 囲ã¾ã‚ŒãƒšãƒŠãƒ«ãƒ†ã‚£è¨ˆç®—用
-
struct map_data
{
char name[24];
char alias[24]; // [MouseJstr]
- unsigned char *gat; // NULLãªã‚‰ä¸‹ã®map_data_other_serverã¨ã—ã¦æ‰±ã†
+ // if NULL, actually a map_data_other_server
+ std::unique_ptr<MapCell[]> gat;
struct block_list **block;
struct block_list **block_mob;
int *block_count, *block_mob_count;
- int m;
+ int m;
short xs, ys;
short bxs, bys;
- int npc_num;
- int users;
+ int npc_num;
+ int users;
struct
{
unsigned alias:1;
@@ -582,14 +420,9 @@ struct map_data
unsigned nopenalty:1;
unsigned pvp:1;
unsigned pvp_noparty:1;
- unsigned pvp_noguild:1;
- unsigned pvp_nightmaredrop:1;
unsigned pvp_nocalcrank:1;
- unsigned gvg:1;
- unsigned gvg_noparty:1;
unsigned nozenypenalty:1;
unsigned notrade:1;
- unsigned noskill:1;
unsigned nowarp:1;
unsigned nowarpto:1;
unsigned nopvp:1; // [Valaris]
@@ -606,9 +439,9 @@ struct map_data
struct npc_data *npc[MAX_NPC_PER_MAP];
struct
{
- int drop_id;
- int drop_type;
- int drop_per;
+ int drop_id;
+ int drop_type;
+ int drop_per;
} drop_list[MAX_DROP_PER_MAP];
};
struct map_data_other_server
@@ -618,92 +451,37 @@ struct map_data_other_server
struct in_addr ip;
unsigned int port;
};
-#define read_gat(m,x,y) (map[m].gat[(x)+(y)*map[m].xs])
-#define read_gatp(m,x,y) (m->gat[(x)+(y)*m->xs])
-struct flooritem_data
-{
- struct block_list bl;
- short subx, suby;
- int cleartimer;
- int first_get_id, second_get_id, third_get_id;
- unsigned int first_get_tick, second_get_tick, third_get_tick;
- struct item item_data;
-};
+extern struct map_data map[];
+extern int map_num;
-enum
+inline
+MapCell read_gatp(struct map_data *m, int x, int y)
{
- SP_SPEED, SP_BASEEXP, SP_JOBEXP, SP_KARMA, SP_MANNER, SP_HP, SP_MAXHP, SP_SP, // 0-7
- SP_MAXSP, SP_STATUSPOINT, SP_0a, SP_BASELEVEL, SP_SKILLPOINT, SP_STR, SP_AGI, SP_VIT, // 8-15
- SP_INT, SP_DEX, SP_LUK, SP_CLASS, SP_ZENY, SP_SEX, SP_NEXTBASEEXP, SP_NEXTJOBEXP, // 16-23
- SP_WEIGHT, SP_MAXWEIGHT, SP_1a, SP_1b, SP_1c, SP_1d, SP_1e, SP_1f, // 24-31
- SP_USTR, SP_UAGI, SP_UVIT, SP_UINT, SP_UDEX, SP_ULUK, SP_26, SP_27, // 32-39
- SP_28, SP_ATK1, SP_ATK2, SP_MATK1, SP_MATK2, SP_DEF1, SP_DEF2, SP_MDEF1, // 40-47
- SP_MDEF2, SP_HIT, SP_FLEE1, SP_FLEE2, SP_CRITICAL, SP_ASPD, SP_36, SP_JOBLEVEL, // 48-55
- SP_UPPER, SP_PARTNER, SP_CART, SP_FAME, SP_UNBREAKABLE, //56-58
- SP_DEAF = 70,
- SP_CARTINFO = 99, // 99
- SP_GM = 500,
-
- // original 1000-
- SP_ATTACKRANGE = 1000, SP_ATKELE, SP_DEFELE, // 1000-1002
- SP_CASTRATE, SP_MAXHPRATE, SP_MAXSPRATE, SP_SPRATE, // 1003-1006
- SP_ADDELE, SP_ADDRACE, SP_ADDSIZE, SP_SUBELE, SP_SUBRACE, // 1007-1011
- SP_ADDEFF, SP_RESEFF, // 1012-1013
- SP_BASE_ATK, SP_ASPD_RATE, SP_HP_RECOV_RATE, SP_SP_RECOV_RATE, SP_SPEED_RATE, // 1014-1018
- SP_CRITICAL_DEF, SP_NEAR_ATK_DEF, SP_LONG_ATK_DEF, // 1019-1021
- SP_DOUBLE_RATE, SP_DOUBLE_ADD_RATE, SP_MATK, SP_MATK_RATE, // 1022-1025
- SP_IGNORE_DEF_ELE, SP_IGNORE_DEF_RACE, // 1026-1027
- SP_ATK_RATE, SP_SPEED_ADDRATE, SP_ASPD_ADDRATE, // 1028-1030
- SP_MAGIC_ATK_DEF, SP_MISC_ATK_DEF, // 1031-1032
- SP_IGNORE_MDEF_ELE, SP_IGNORE_MDEF_RACE, // 1033-1034
- SP_MAGIC_ADDELE, SP_MAGIC_ADDRACE, SP_MAGIC_SUBRACE, // 1035-1037
- SP_PERFECT_HIT_RATE, SP_PERFECT_HIT_ADD_RATE, SP_CRITICAL_RATE, SP_GET_ZENY_NUM, SP_ADD_GET_ZENY_NUM, // 1038-1042
- SP_ADD_DAMAGE_CLASS, SP_ADD_MAGIC_DAMAGE_CLASS, SP_ADD_DEF_CLASS, SP_ADD_MDEF_CLASS, // 1043-1046
- SP_ADD_MONSTER_DROP_ITEM, SP_DEF_RATIO_ATK_ELE, SP_DEF_RATIO_ATK_RACE, SP_ADD_SPEED, // 1047-1050
- SP_HIT_RATE, SP_FLEE_RATE, SP_FLEE2_RATE, SP_DEF_RATE, SP_DEF2_RATE, SP_MDEF_RATE, SP_MDEF2_RATE, // 1051-1057
- SP_SPLASH_RANGE, SP_SPLASH_ADD_RANGE, SP_AUTOSPELL, SP_HP_DRAIN_RATE, SP_SP_DRAIN_RATE, // 1058-1062
- SP_SHORT_WEAPON_DAMAGE_RETURN, SP_LONG_WEAPON_DAMAGE_RETURN, SP_WEAPON_COMA_ELE, SP_WEAPON_COMA_RACE, // 1063-1066
- SP_ADDEFF2, SP_BREAK_WEAPON_RATE, SP_BREAK_ARMOR_RATE, SP_ADD_STEAL_RATE, // 1067-1070
- SP_MAGIC_DAMAGE_RETURN, SP_RANDOM_ATTACK_INCREASE, SP_ALL_STATS, SP_AGI_VIT, SP_AGI_DEX_STR, SP_PERFECT_HIDE, // 1071-1077
- SP_DISGUISE, // 1077
-
- SP_RESTART_FULL_RECORVER = 2000, SP_NO_CASTCANCEL, SP_NO_SIZEFIX, SP_NO_MAGIC_DAMAGE, SP_NO_WEAPON_DAMAGE, SP_NO_GEMSTONE, // 2000-2005
- SP_NO_CASTCANCEL2, SP_INFINITE_ENDURE, SP_UNBREAKABLE_WEAPON, SP_UNBREAKABLE_ARMOR // 2006-2009
-};
-
-enum
+ return m->gat[x + y * m->xs];
+}
+inline
+MapCell read_gat(int m, int x, int y)
{
- LOOK_BASE,
- LOOK_HAIR,
- LOOK_WEAPON,
- LOOK_HEAD_BOTTOM,
- LOOK_HEAD_TOP,
- LOOK_HEAD_MID,
- LOOK_HAIR_COLOR,
- LOOK_CLOTHES_COLOR,
- LOOK_SHIELD,
- LOOK_SHOES, /* 9 */
- LOOK_GLOVES,
- LOOK_CAPE,
- LOOK_MISC1,
- LOOK_MISC2
-};
+ return read_gatp(&map[m], x, y);
+}
-enum
+struct flooritem_data
{
- EQUIP_SHIELD = 8,
- EQUIP_WEAPON = 9
+ struct block_list bl;
+ short subx, suby;
+ Timer cleartimer;
+ int first_get_id, second_get_id, third_get_id;
+ tick_t first_get_tick, second_get_tick, third_get_tick;
+ struct item item_data;
};
-#define LOOK_LAST LOOK_MISC2
-
struct chat_data
{
struct block_list bl;
char pass[8]; /* password */
- char title[61]; /* room title MAX 60 */
+ char title[61]; /* room title max 60 */
unsigned char limit; /* join limit */
unsigned char trigger;
unsigned char users; /* current users */
@@ -714,111 +492,109 @@ struct chat_data
char npc_event[50];
};
-extern struct map_data map[];
-extern int map_num;
-extern int autosave_interval;
+extern interval_t autosave_interval;
extern int save_settings;
-extern int agit_flag;
-extern int night_flag; // 0=day, 1=night [Yor]
extern char motd_txt[];
extern char help_txt[];
-extern char talkie_mes[];
-
extern char wisp_server_name[];
// 鯖全体情報
-void map_setusers (int);
-int map_getusers (void);
+void map_setusers(int);
+int map_getusers(void);
// block削除関連
-int map_freeblock (void *bl);
-int map_freeblock_lock (void);
-int map_freeblock_unlock (void);
+int map_freeblock(void *bl);
+int map_freeblock_lock(void);
+int map_freeblock_unlock(void);
// block関連
-int map_addblock (struct block_list *);
-int map_delblock (struct block_list *);
-void map_foreachinarea (int (*)(struct block_list *, va_list), int, int, int,
- int, int, int, ...);
+int map_addblock(struct block_list *);
+int map_delblock(struct block_list *);
+void map_foreachinarea(std::function<void(struct block_list *)>,
+ int,
+ int, int, int, int,
+ BL);
// -- moonsoul (added map_foreachincell)
-void map_foreachincell (int (*)(struct block_list *, va_list), int, int, int,
- int, ...);
-void map_foreachinmovearea (int (*)(struct block_list *, va_list), int, int,
- int, int, int, int, int, int, ...);
-int map_countnearpc (int, int, int);
+void map_foreachincell(std::function<void(struct block_list *)>,
+ int,
+ int, int,
+ BL);
+void map_foreachinmovearea(std::function<void(struct block_list *)>,
+ int,
+ int, int, int, int,
+ int, int,
+ BL);
//block関連ã«è¿½åŠ 
-int map_count_oncell (int m, int x, int y);
+int map_count_oncell(int m, int x, int y);
// 一時的object関連
-int map_addobject (struct block_list *);
-int map_delobject (int, int type);
-int map_delobjectnofree (int id, int type);
-void map_foreachobject (int (*)(struct block_list *, va_list), int, ...);
+int map_addobject(struct block_list *);
+int map_delobject(int, BL type);
+int map_delobjectnofree(int id, BL type);
+void map_foreachobject(std::function<void(struct block_list *)>,
+ BL);
//
-int map_quit (struct map_session_data *);
+void map_quit(struct map_session_data *);
// npc
-int map_addnpc (int, struct npc_data *);
+int map_addnpc(int, struct npc_data *);
-extern FILE *map_logfile;
-__attribute__((format(printf, 1, 2)))
-void map_write_log (const char *format, ...);
-#define MAP_LOG(format, args...) {if (map_logfile) map_write_log(format, ##args);}
+void map_log(const_string line);
+#define MAP_LOG(format, ...) \
+ map_log(static_cast<const std::string&>(STRPRINTF(format, ## __VA_ARGS__)))
-#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)
+#define MAP_LOG_PC(sd, fmt, ...) \
+ MAP_LOG("PC%d %d:%d,%d " fmt, \
+ sd->status.char_id, sd->bl.m, sd->bl.x, sd->bl.y, ## __VA_ARGS__)
// 床アイテム関連
-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,
- int *owner_protection,
- int lifetime, int dispersal);
-int map_addflooritem (struct item *, int, int, int, int,
- struct map_session_data *, struct map_session_data *,
- struct map_session_data *, int);
-int map_searchrandfreecell (int, int, int, int);
+void map_clearflooritem_timer(TimerData *, tick_t, int);
+inline
+void map_clearflooritem(int id)
+{
+ map_clearflooritem_timer(nullptr, tick_t(), id);
+}
+int map_addflooritem_any(struct item *, int amount, int m, int x, int y,
+ struct map_session_data **owners, interval_t *owner_protection,
+ interval_t lifetime, int dispersal);
+int map_addflooritem(struct item *, int, int, int, int,
+ struct map_session_data *, struct map_session_data *,
+ struct map_session_data *);
// キャラidï¼ï¼žã‚­ãƒ£ãƒ©å 変æ›é–¢é€£
-void map_addchariddb (int charid, const char *name);
-void map_delchariddb (int charid);
-int map_reqchariddb (struct map_session_data *sd, int charid);
-char *map_charid2nick (int);
-
-struct map_session_data *map_id2sd (int);
-struct block_list *map_id2bl (int);
-int map_mapname2mapid (const char *);
-int map_mapname2ipport (const char *, struct in_addr *, int *);
-int map_setipport (const char *name, struct in_addr ip, int port);
-int map_eraseipport (const char *name, struct in_addr ip, int port);
-void map_addiddb (struct block_list *);
-void map_deliddb (struct block_list *bl);
-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 (const char *);
-int compare_item (struct item *a, struct item *b);
-
-struct map_session_data *map_get_first_session (void);
-struct map_session_data *map_get_last_session (void);
-struct map_session_data *map_get_next_session (struct map_session_data
- *current);
-struct map_session_data *map_get_prev_session (struct map_session_data
- *current);
+extern
+DMap<int, struct block_list *> id_db;
+void map_addchariddb(int charid, const char *name);
+char *map_charid2nick(int);
+
+struct map_session_data *map_id2sd(int);
+struct block_list *map_id2bl(int);
+int map_mapname2mapid(const char *);
+int map_mapname2ipport(const char *, struct in_addr *, int *);
+int map_setipport(const char *name, struct in_addr ip, int port);
+void map_addiddb(struct block_list *);
+void map_deliddb(struct block_list *bl);
+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(const char *);
+int compare_item(struct item *a, struct item *b);
+
+struct map_session_data *map_get_first_session(void);
+struct map_session_data *map_get_last_session(void);
+struct map_session_data *map_get_next_session(
+ struct map_session_data *current);
+struct map_session_data *map_get_prev_session(
+ struct map_session_data *current);
// gat関連
-int map_getcell (int, int, int);
-int map_setcell (int, int, int, int);
+MapCell map_getcell(int, int, int);
+void map_setcell(int, int, int, MapCell);
// ãã®ä»–
-int map_check_dir (int s_dir, int t_dir);
-int map_calc_dir (struct block_list *src, int x, int y);
+bool map_check_dir(DIR s_dir, DIR t_dir);
+DIR map_calc_dir(struct block_list *src, int x, int y);
// path.cより
-int path_search (struct walkpath_data *, int, int, int, int, int, int);
-int path_blownpos (int m, int x0, int y0, int dx, int dy, int count);
-
-int map_who (int fd);
+int path_search(struct walkpath_data *, int, int, int, int, int, int);
-void map_helpscreen (void); // [Valaris]
-int map_delmap (char *mapname);
+std::pair<uint16_t, uint16_t> map_randfreecell(int m, uint16_t x, uint16_t y, uint16_t w, uint16_t h);
-#endif
+#endif // MAP_HPP
diff --git a/src/map/map.t.hpp b/src/map/map.t.hpp
new file mode 100644
index 0000000..c57ea06
--- /dev/null
+++ b/src/map/map.t.hpp
@@ -0,0 +1,560 @@
+#ifndef MAP_T_HPP
+#define MAP_T_HPP
+
+#include "../common/mmo.hpp"
+#include "../common/utils2.hpp"
+
+namespace e
+{
+// [Fate] status.option properties. These are persistent status changes.
+// IDs that are not listed are not used in the code (to the best of my knowledge)
+enum class Option : uint16_t
+{
+ ZERO = 0x0000,
+
+ // [Fate] This is the GM `@hide' flag
+ HIDE = 0x0040,
+ // [Fate] Complete invisibility to other clients
+ INVISIBILITY = 0x1000,
+
+ // ?
+ REAL_ANY_HIDE = HIDE,
+};
+enum class Opt1 : uint16_t
+{
+ ZERO = 0,
+ _stone1 = 1,
+ _freeze = 2,
+ _stan = 3,
+ _sleep = 4,
+ _stone6 = 6,
+};
+enum class Opt2 : uint16_t
+{
+ ZERO = 0x0000,
+ _poison = 0x0001,
+ _curse = 0x0002,
+ _silence = 0x0004,
+ BLIND = 0x0010,
+ _speedpotion0 = 0x0020,
+ _signumcrucis = 0x0040,
+ _atkpot = 0x0080,
+ _heal = 0x0100,
+ _slowpoison = 0x0200,
+};
+enum class Opt3 : uint16_t
+{
+ ZERO = 0x0000,
+ _concentration = 0x0001,
+ _overthrust = 0x0002,
+ _energycoat = 0x0004,
+ _explosionspirits = 0x0008,
+ _steelbody = 0x0010,
+ _berserk = 0x0080,
+
+ _marionette = 0x0400,
+ _assumptio = 0x0800,
+};
+
+ENUM_BITWISE_OPERATORS(Option)
+ENUM_BITWISE_OPERATORS(Opt2)
+ENUM_BITWISE_OPERATORS(Opt3)
+}
+using e::Option;
+using e::Opt1;
+using e::Opt2;
+using e::Opt3;
+
+enum class BL : uint8_t
+{
+ NUL,
+ PC,
+ NPC,
+ MOB,
+ ITEM,
+ CHAT,
+ SPELL,
+};
+enum class NpcSubtype : uint8_t
+{
+ WARP,
+ SHOP,
+ SCRIPT,
+ MONS,
+ MESSAGE,
+};
+
+enum class mob_stat
+{
+ LV,
+ MAX_HP,
+ STR,
+ AGI,
+ VIT,
+ INT,
+ DEX,
+ LUK,
+ // low and high attacks
+ ATK1,
+ ATK2,
+ // attack delay
+ ADELAY,
+ DEF,
+ MDEF,
+ SPEED,
+ // These must come last:
+ // [Fate] Encoded as base to 1024: 1024 means 100%
+ XP_BONUS,
+ LAST,
+};
+
+enum class MS : uint8_t
+{
+ IDLE,
+ WALK,
+ ATTACK,
+ DEAD,
+};
+
+enum class ATK
+{
+ ZERO = 0,
+
+ LUCKY,
+ FLEE,
+ DEF,
+};
+
+enum class SP : uint16_t
+{
+ // sent to client
+ SPEED = 0,
+
+ // when used as "no stat"
+ ZERO = 0,
+
+ // sent to client
+ BASEEXP = 1,
+ // sent to client
+ JOBEXP = 2,
+#if 0
+ KARMA = 3,
+#endif
+
+ // sent to client
+ HP = 5,
+ // sent to client
+ MAXHP = 6,
+ // sent to client
+ SP = 7,
+ // sent to client
+ MAXSP = 8,
+ // sent to client
+ STATUSPOINT = 9,
+
+ // sent to client
+ BASELEVEL = 11,
+ // sent to client
+ SKILLPOINT = 12,
+ // sent to client
+ STR = 13,
+ // sent to client
+ AGI = 14,
+ // sent to client
+ VIT = 15,
+ // sent to client
+ INT = 16,
+ // sent to client
+ DEX = 17,
+ // sent to client
+ LUK = 18,
+ CLASS = 19,
+ // sent to client
+ ZENY = 20,
+ SEX = 21,
+ // sent to client
+ NEXTBASEEXP = 22,
+ // sent to client
+ NEXTJOBEXP = 23,
+ // sent to client
+ WEIGHT = 24,
+ // sent to client
+ MAXWEIGHT = 25,
+
+ // sent to client
+ USTR = 32,
+ // sent to client
+ UAGI = 33,
+ // sent to client
+ UVIT = 34,
+ // sent to client
+ UINT = 35,
+ // sent to client
+ UDEX = 36,
+ // sent to client
+ ULUK = 37,
+
+ // sent to client
+ ATK1 = 41,
+ // sent to client
+ ATK2 = 42,
+ // sent to client
+ MATK1 = 43,
+ // sent to client
+ MATK2 = 44,
+ // sent to client
+ DEF1 = 45,
+ // sent to client
+ DEF2 = 46,
+ // sent to client
+ MDEF1 = 47,
+ // sent to client
+ MDEF2 = 48,
+ // sent to client
+ HIT = 49,
+ // sent to client
+ FLEE1 = 50,
+ // sent to client
+ FLEE2 = 51,
+ // sent to client
+ CRITICAL = 52,
+ // sent to client
+ ASPD = 53,
+
+ // sent to client
+ JOBLEVEL = 55,
+
+#if 0
+ PARTNER = 57,
+ CART = 58,
+ FAME = 59,
+ UNBREAKABLE = 60,
+#endif
+
+ DEAF = 70,
+
+ // sent to client
+ GM = 500,
+
+ // sent to client
+ ATTACKRANGE = 1000,
+#if 0
+ ATKELE = 1001,
+#endif
+#if 0
+ DEFELE = 1002,
+#endif
+#if 0
+ CASTRATE = 1003,
+#endif
+ MAXHPRATE = 1004,
+#if 0
+ MAXSPRATE = 1005,
+#endif
+#if 0
+ SPRATE = 1006,
+#endif
+
+#if 0
+ ADDEFF = 1012,
+#endif
+#if 0
+ RESEFF = 1013,
+#endif
+ BASE_ATK = 1014,
+ ASPD_RATE = 1015,
+ HP_RECOV_RATE = 1016,
+#if 0
+ SP_RECOV_RATE = 1017,
+#endif
+#if 0
+ SPEED_RATE = 1018,
+#endif
+ CRITICAL_DEF = 1019,
+#if 0
+ NEAR_ATK_DEF = 1020,
+#endif
+#if 0
+ LONG_ATK_DEF = 1021,
+#endif
+#if 0
+ DOUBLE_RATE = 1022,
+#endif
+ DOUBLE_ADD_RATE = 1023,
+#if 0
+ MATK = 1024,
+#endif
+#if 0
+ MATK_RATE = 1025,
+#endif
+#if 0
+ IGNORE_DEF_ELE = 1026,
+#endif
+#if 0
+ IGNORE_DEF_RACE = 1027,
+#endif
+#if 0
+ ATK_RATE = 1028,
+#endif
+ SPEED_ADDRATE = 1029,
+#if 0
+ ASPD_ADDRATE = 1030,
+#endif
+#if 0
+ MAGIC_ATK_DEF = 1031,
+#endif
+#if 0
+ MISC_ATK_DEF = 1032,
+#endif
+#if 0
+ IGNORE_MDEF_ELE = 1033,
+#endif
+#if 0
+ IGNORE_MDEF_RACE = 1034,
+#endif
+
+#if 0
+ PERFECT_HIT_RATE = 1038,
+#endif
+#if 0
+ PERFECT_HIT_ADD_RATE = 1039,
+#endif
+#if 0
+ CRITICAL_RATE = 1040,
+#endif
+#if 0
+ GET_ZENY_NUM = 1041,
+#endif
+#if 0
+ ADD_GET_ZENY_NUM = 1042,
+#endif
+
+#if 0
+ ADD_MONSTER_DROP_ITEM = 1047,
+#endif
+#if 0
+ DEF_RATIO_ATK_ELE = 1048,
+#endif
+#if 0
+ DEF_RATIO_ATK_RACE = 1049,
+#endif
+#if 0
+ ADD_SPEED = 1050,
+#endif
+#if 0
+ HIT_RATE = 1051,
+#endif
+#if 0
+ FLEE_RATE = 1052,
+#endif
+#if 0
+ FLEE2_RATE = 1053,
+#endif
+ DEF_RATE = 1054,
+ DEF2_RATE = 1055,
+#if 0
+ MDEF_RATE = 1056,
+#endif
+#if 0
+ MDEF2_RATE = 1057,
+#endif
+#if 0
+ SPLASH_RANGE = 1058,
+#endif
+#if 0
+ SPLASH_ADD_RANGE = 1059,
+#endif
+
+ HP_DRAIN_RATE = 1061,
+#if 0
+ SP_DRAIN_RATE = 1062,
+#endif
+#if 0
+ SHORT_WEAPON_DAMAGE_RETURN = 1063,
+#endif
+#if 0
+ LONG_WEAPON_DAMAGE_RETURN = 1064,
+#endif
+
+#if 0
+ ADDEFF2 = 1067,
+#endif
+ BREAK_WEAPON_RATE = 1068,
+ BREAK_ARMOR_RATE = 1069,
+ ADD_STEAL_RATE = 1070,
+ MAGIC_DAMAGE_RETURN = 1071,
+#if 0
+ RANDOM_ATTACK_INCREASE = 1072,
+#endif
+};
+
+constexpr
+SP attr_to_sp(ATTR attr)
+{
+ return SP(uint16_t(attr) + uint16_t(SP::STR));
+}
+
+constexpr
+ATTR sp_to_attr(SP sp)
+{
+ return ATTR(uint16_t(sp) - uint16_t(SP::STR));
+}
+
+constexpr
+SP attr_to_usp(ATTR attr)
+{
+ return SP(uint16_t(attr) + uint16_t(SP::USTR));
+}
+
+constexpr
+ATTR usp_to_attr(SP sp)
+{
+ return ATTR(uint16_t(sp) - uint16_t(SP::USTR));
+}
+
+constexpr
+SP sp_to_usp(SP sp)
+{
+ return attr_to_usp(sp_to_attr(sp));
+}
+
+constexpr
+SP usp_to_sp(SP sp)
+{
+ return attr_to_sp(usp_to_attr(sp));
+}
+
+
+enum class LOOK : uint8_t
+{
+ BASE = 0,
+ HAIR = 1,
+ WEAPON = 2,
+ HEAD_BOTTOM = 3,
+ HEAD_TOP = 4,
+ HEAD_MID = 5,
+ HAIR_COLOR = 6,
+ CLOTHES_COLOR = 7,
+ SHIELD = 8,
+ SHOES = 9,
+ GLOVES = 10,
+ CAPE = 11,
+ MISC1 = 12,
+ MISC2 = 13,
+
+ COUNT,
+};
+
+enum class EQUIP
+{
+ NONE = -1,
+ MISC2 = 0,
+ CAPE = 1,
+ SHOES = 2,
+ GLOVES = 3,
+ LEGS = 4, // also called "head bottom"
+ TORSO = 5, // also called "head middle"
+ HAT = 6, // also called "head top"
+ MISC1 = 7,
+ SHIELD = 8,
+ WEAPON = 9,
+ ARROW = 10,
+ COUNT = 11,
+};
+
+constexpr
+EQUIP EQUIPs[] =
+{
+ EQUIP::MISC2,
+ EQUIP::CAPE,
+ EQUIP::SHOES,
+ EQUIP::GLOVES,
+ EQUIP::LEGS,
+ EQUIP::TORSO,
+ EQUIP::HAT,
+ EQUIP::MISC1,
+ EQUIP::SHIELD,
+ EQUIP::WEAPON,
+ EQUIP::ARROW,
+};
+
+constexpr
+EQUIP EQUIPs_noarrow[] =
+{
+ EQUIP::MISC2,
+ EQUIP::CAPE,
+ EQUIP::SHOES,
+ EQUIP::GLOVES,
+ EQUIP::LEGS,
+ EQUIP::TORSO,
+ EQUIP::HAT,
+ EQUIP::MISC1,
+ EQUIP::SHIELD,
+ EQUIP::WEAPON,
+};
+
+enum class ItemType : uint8_t
+{
+ USE = 0, // in eA, healing only
+ _1 = 1, // unused
+ _2 = 2, // in eA, other usable items
+ JUNK = 3, // "useless" items (e.g. quests)
+ WEAPON = 4, // all weapons
+ ARMOR = 5, // all other equipment
+ _6 = 6, // in eA, card
+ _7 = 7, // in eA, pet egg
+ _8 = 8, // in eA, pet equipment
+ _9 = 9, // unused
+ ARROW = 10, // ammo
+ _11 = 11, // in eA, delayed use (special script)
+};
+
+namespace e
+{
+enum class MobMode : uint16_t
+{
+ ZERO = 0x0000,
+
+ CAN_MOVE = 0x0001,
+ LOOTER = 0x0002,
+ AGGRESSIVE = 0x0004,
+ ASSIST = 0x0008,
+
+ CAST_SENSOR = 0x0010,
+ BOSS = 0x0020,
+ // sometimes also called "robust"
+ PLANT = 0x0040,
+ CAN_ATTACK = 0x0080,
+
+ DETECTOR = 0x0100,
+ CHANGE_TARGET = 0x0200,
+
+ war = CAN_MOVE | AGGRESSIVE | CAN_ATTACK,
+
+ SUMMONED = 0x1000,
+ TURNS_AGAINST_BAD_MASTER = 0x2000,
+
+ // mob mode flags that Fate actually understood
+ SENSIBLE_MASK = 0xf000,
+};
+
+ENUM_BITWISE_OPERATORS(MobMode)
+}
+using e::MobMode;
+
+namespace e
+{
+enum class MapCell : uint8_t
+{
+ // the usual thing
+ UNWALKABLE = 0x01,
+ // not in tmwa data
+ _range = 0x04,
+ // set in code, not imported
+ NPC_NEAR = 0x80,
+};
+ENUM_BITWISE_OPERATORS(MapCell)
+}
+using e::MapCell;
+
+#endif // MAP_T_HPP
diff --git a/src/map/mob.cpp b/src/map/mob.cpp
index c329a14..be9e71d 100644
--- a/src/map/mob.cpp
+++ b/src/map/mob.cpp
@@ -1,39 +1,36 @@
-// $Id: mob.c,v 1.7 2004/09/25 05:32:18 MouseJstr Exp $
-#include <math.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdarg.h>
-#include <string.h>
-#include "../common/timer.hpp"
-#include "../common/socket.hpp"
-#include "../common/db.hpp"
+#include "mob.hpp"
+
+#include <cassert>
+#include <cmath>
+#include <cstdlib>
+#include <cstring>
+
+#include <algorithm>
+
+#include "../common/cxxstdio.hpp"
+#include "../common/random.hpp"
#include "../common/nullpo.hpp"
-#include "../common/mt_rand.hpp"
-#include "map.hpp"
+#include "../common/socket.hpp"
+#include "../common/timer.hpp"
+
+#include "battle.hpp"
#include "clif.hpp"
-#include "intif.hpp"
-#include "pc.hpp"
-#include "mob.hpp"
-#include "guild.hpp"
#include "itemdb.hpp"
-#include "skill.hpp"
-#include "battle.hpp"
-#include "party.hpp"
+#include "map.hpp"
#include "npc.hpp"
+#include "party.hpp"
+#include "pc.hpp"
+#include "skill.hpp"
-#ifdef MEMWATCH
-#include "memwatch.hpp"
-#endif
-
-#ifndef max
-#define max( a, b ) ( ((a) > (b)) ? (a) : (b) )
-#endif
+#include "../poison.hpp"
-#define MIN_MOBTHINKTIME 100
+constexpr interval_t MIN_MOBTHINKTIME = std::chrono::milliseconds(100);
-#define MOB_LAZYMOVEPERC 50 // Move probability in the negligent mode MOB (rate of 1000 minute)
-#define MOB_LAZYWARPPERC 20 // Warp probability in the negligent mode MOB (rate of 1000 minute)
+// Move probability in the negligent mode MOB (rate of 1000 minute)
+constexpr random_::Fraction MOB_LAZYMOVEPERC {50, 1000};
+// Warp probability in the negligent mode MOB (rate of 1000 minute)
+constexpr random_::Fraction MOB_LAZYWARPPERC {20, 1000};
struct mob_db mob_db[2001];
@@ -41,29 +38,30 @@ struct mob_db mob_db[2001];
* Local prototype declaration (only required thing)
*------------------------------------------
*/
-static int distance (int, int, int, int);
-static int mob_makedummymobdb (int);
-static void mob_timer (timer_id, tick_t, custom_id_t, custom_data_t);
-int mobskill_deltimer (struct mob_data *md);
-int mob_skillid2skillidx (int mob_class, int skillid);
-int mobskill_use_id (struct mob_data *md, struct block_list *target,
- int skill_idx);
-static int mob_unlocktarget (struct mob_data *md, int tick);
+static
+int distance(int, int, int, int);
+static
+int mob_makedummymobdb(int);
+static
+void mob_timer(TimerData *, tick_t, int, unsigned char);
+static
+int mobskill_use_id(struct mob_data *md, struct block_list *target,
+ int skill_idx);
/*==========================================
* Mob is searched with a name.
*------------------------------------------
*/
-int mobdb_searchname (const char *str)
+int mobdb_searchname(const char *str)
{
- int i;
+ int i;
- for (i = 0; i < sizeof (mob_db) / sizeof (mob_db[0]); i++)
+ for (i = 0; i < sizeof(mob_db) / sizeof(mob_db[0]); i++)
{
- 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)
+ 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)
return i;
}
@@ -74,45 +72,46 @@ int mobdb_searchname (const char *str)
* Id Mob is checked.
*------------------------------------------
*/
-int mobdb_checkid (const int id)
+int mobdb_checkid(const int id)
{
- if (id <= 0 || id >= (sizeof (mob_db) / sizeof (mob_db[0]))
+ if (id <= 0 || id >= (sizeof(mob_db) / sizeof(mob_db[0]))
|| mob_db[id].name[0] == '\0')
return 0;
return id;
}
-static void mob_init (struct mob_data *md);
+static
+void mob_init(struct mob_data *md);
/*==========================================
* The minimum data set for MOB spawning
*------------------------------------------
*/
static
-int mob_spawn_dataset (struct mob_data *md, const char *mobname, int mob_class)
+int mob_spawn_dataset(struct mob_data *md, const char *mobname, int mob_class)
{
- nullpo_retr (0, md);
+ nullpo_ret(md);
- if (strcmp (mobname, "--en--") == 0)
- memcpy (md->name, mob_db[mob_class].name, 24);
- else if (strcmp (mobname, "--ja--") == 0)
- memcpy (md->name, mob_db[mob_class].jname, 24);
+ if (strcmp(mobname, "--en--") == 0)
+ memcpy(md->name, mob_db[mob_class].name, 24);
+ else if (strcmp(mobname, "--ja--") == 0)
+ memcpy(md->name, mob_db[mob_class].jname, 24);
else
- memcpy (md->name, mobname, 24);
+ memcpy(md->name, mobname, 24);
md->bl.prev = NULL;
md->bl.next = NULL;
md->n = 0;
- md->base_class = md->mob_class = mob_class;
- md->bl.id = npc_get_new_npc_id ();
+ md->mob_class = mob_class;
+ md->bl.id = npc_get_new_npc_id();
- memset (&md->state, 0, sizeof (md->state));
- md->timer = -1;
+ memset(&md->state, 0, sizeof(md->state));
+ // md->timer = nullptr;
md->target_id = 0;
md->attacked_id = 0;
- mob_init (md);
+ mob_init(md);
return 0;
}
@@ -120,41 +119,45 @@ int mob_spawn_dataset (struct mob_data *md, const char *mobname, int mob_class)
// Mutation values indicate how `valuable' a change to each stat is, XP wise.
// For one 256th of change, we give out that many 1024th fractions of XP change
// (i.e., 1024 means a 100% XP increase for a single point of adjustment, 4 means 100% XP bonus for doubling the value)
-static int mutation_value[MOB_XP_BONUS] = {
- 2, // MOB_LV
- 3, // MOB_MAX_HP
- 1, // MOB_STR
- 2, // MOB_AGI
- 1, // MOB_VIT
- 0, // MOB_INT
- 2, // MOB_DEX
- 2, // MOB_LUK
- 1, // MOB_ATK1
- 1, // MOB_ATK2
- 2, // MOB_ADELAY
- 2, // MOB_DEF
- 2, // MOB_MDEF
- 2, // MOB_SPEED
-};
+static
+earray<int, mob_stat, mob_stat::XP_BONUS> mutation_value //=
+{{
+ 2, // mob_stat::LV
+ 3, // mob_stat::MAX_HP
+ 1, // mob_stat::STR
+ 2, // mob_stat::AGI
+ 1, // mob_stat::VIT
+ 0, // mob_stat::INT
+ 2, // mob_stat::DEX
+ 2, // mob_stat::LUK
+ 1, // mob_stat::ATK1
+ 1, // mob_stat::ATK2
+ 2, // mob_stat::ADELAY
+ 2, // mob_stat::DEF
+ 2, // mob_stat::MDEF
+ 2, // mob_stat::SPEED
+}};
// The mutation scale indicates how far `up' we can go, with 256 indicating 100% Note that this may stack with multiple
// calls to `mutate'.
-static int mutation_scale[MOB_XP_BONUS] = {
- 16, // MOB_LV
- 256, // MOB_MAX_HP
- 32, // MOB_STR
- 48, // MOB_AGI
- 48, // MOB_VIT
- 48, // MOB_INT
- 48, // MOB_DEX
- 64, // MOB_LUK
- 48, // MOB_ATK1
- 48, // MOB_ATK2
- 80, // MOB_ADELAY
- 48, // MOB_DEF
- 48, // MOB_MDEF
- 80, // MOB_SPEED
-};
+static
+earray<int, mob_stat, mob_stat::XP_BONUS> mutation_scale //=
+{{
+ 16, // mob_stat::LV
+ 256, // mob_stat::MAX_HP
+ 32, // mob_stat::STR
+ 48, // mob_stat::AGI
+ 48, // mob_stat::VIT
+ 48, // mob_stat::INT
+ 48, // mob_stat::DEX
+ 64, // mob_stat::LUK
+ 48, // mob_stat::ATK1
+ 48, // mob_stat::ATK2
+ 80, // mob_stat::ADELAY
+ 48, // mob_stat::DEF
+ 48, // mob_stat::MDEF
+ 80, // mob_stat::SPEED
+}};
// The table below indicates the `average' value for each of the statistics, or -1 if there is none.
// This average is used to determine XP modifications for mutations. The experience point bonus is
@@ -163,54 +166,58 @@ static int mutation_scale[MOB_XP_BONUS] = {
// (2) second, determine the absolute stat change
// (3) third, compute the percentage stat change relative to mutation_base (p1)
// (4) fourth, compute the XP mofication based on the smaller of (p0, p1).
-static int mutation_base[MOB_XP_BONUS] = {
- 30, // MOB_LV
- -1, // MOB_MAX_HP
- 20, // MOB_STR
- 20, // MOB_AGI
- 20, // MOB_VIT
- 20, // MOB_INT
- 20, // MOB_DEX
- 20, // MOB_LUK
- -1, // MOB_ATK1
- -1, // MOB_ATK2
- -1, // MOB_ADELAY
- -1, // MOB_DEF
- 20, // MOB_MDEF
- -1, // MOB_SPEED
-};
+static
+earray<int, mob_stat, mob_stat::XP_BONUS> mutation_base //=
+{{
+ 30, // mob_stat::LV
+ -1, // mob_stat::MAX_HP
+ 20, // mob_stat::STR
+ 20, // mob_stat::AGI
+ 20, // mob_stat::VIT
+ 20, // mob_stat::INT
+ 20, // mob_stat::DEX
+ 20, // mob_stat::LUK
+ -1, // mob_stat::ATK1
+ -1, // mob_stat::ATK2
+ -1, // mob_stat::ADELAY
+ -1, // mob_stat::DEF
+ 20, // mob_stat::MDEF
+ -1, // mob_stat::SPEED
+}};
/*========================================
* Mutates a MOB. For large `direction' values, calling this multiple times will give bigger XP boni.
*----------------------------------------
*/
-static void mob_mutate (struct mob_data *md, int stat, int intensity) // intensity: positive: strengthen, negative: weaken. 256 = 100%.
+// intensity: positive: strengthen, negative: weaken. 256 = 100%.
+static
+void mob_mutate(struct mob_data *md, mob_stat stat, int intensity)
{
- int old_stat;
- int new_stat;
- int real_intensity; // relative intensity
+ int old_stat;
+ int new_stat;
+ int real_intensity; // relative intensity
const int mut_base = mutation_base[stat];
- int sign = 1;
+ int sign = 1;
- if (!md || stat < 0 || stat >= MOB_XP_BONUS || intensity == 0)
+ if (!md || stat >= mob_stat::XP_BONUS || intensity == 0)
return;
while (intensity > mutation_scale[stat])
{
- mob_mutate (md, stat, mutation_scale[stat]); // give better XP assignments
+ mob_mutate(md, stat, mutation_scale[stat]); // give better XP assignments
intensity -= mutation_scale[stat];
}
while (intensity < -mutation_scale[stat])
{
- mob_mutate (md, stat, mutation_scale[stat]); // give better XP assignments
+ mob_mutate(md, stat, mutation_scale[stat]); // give better XP assignments
intensity += mutation_scale[stat];
}
if (!intensity)
return;
- // MOB_ADELAY and MOB_SPEED are special because going DOWN is good here.
- if (stat == MOB_ADELAY || stat == MOB_SPEED)
+ // mob_stat::ADELAY and mob_stat::SPEED are special because going DOWN is good here.
+ if (stat == mob_stat::ADELAY || stat == mob_stat::SPEED)
sign = -1;
// Now compute the new stat
@@ -229,7 +236,7 @@ static void mob_mutate (struct mob_data *md, int stat, int intensity) // inten
{
// Now compute the mutation intensity relative to an absolute value.
// Take the lesser of the two effects.
- int real_intensity2 = (((new_stat - old_stat) << 8) / mut_base);
+ int real_intensity2 = (((new_stat - old_stat) << 8) / mut_base);
if (real_intensity < 0)
if (real_intensity2 > real_intensity)
@@ -245,22 +252,22 @@ static void mob_mutate (struct mob_data *md, int stat, int intensity) // inten
md->stats[stat] = new_stat;
// Adjust XP value
- md->stats[MOB_XP_BONUS] += mutation_value[stat] * real_intensity;
- if (md->stats[MOB_XP_BONUS] <= 0)
- md->stats[MOB_XP_BONUS] = 1;
+ md->stats[mob_stat::XP_BONUS] += mutation_value[stat] * real_intensity;
+ if (md->stats[mob_stat::XP_BONUS] <= 0)
+ md->stats[mob_stat::XP_BONUS] = 1;
// Sanitise
- if (md->stats[MOB_ATK1] > md->stats[MOB_ATK2])
+ if (md->stats[mob_stat::ATK1] > md->stats[mob_stat::ATK2])
{
- int swap = md->stats[MOB_ATK2];
- md->stats[MOB_ATK2] = md->stats[MOB_ATK1];
- md->stats[MOB_ATK1] = swap;
+ int swap = md->stats[mob_stat::ATK2];
+ md->stats[mob_stat::ATK2] = md->stats[mob_stat::ATK1];
+ md->stats[mob_stat::ATK1] = swap;
}
}
// This calculates the exp of a given mob
static
-int mob_gen_exp (struct mob_db *mob)
+int mob_gen_exp(struct mob_db *mob)
{
if (mob->max_hp <= 1)
return 1;
@@ -268,70 +275,90 @@ int mob_gen_exp (struct mob_db *mob)
if (100 == mob->def)
mod_def = 1;
double effective_hp =
- ((50 - mob->luk) * mob->max_hp / 50.0) +
- (2 * mob->luk * mob->max_hp / mod_def);
+ ((50 - mob->attrs[ATTR::LUK]) * mob->max_hp / 50.0) +
+ (2 * mob->attrs[ATTR::LUK] * mob->max_hp / mod_def);
double attack_factor =
- (mob->atk1 + mob->atk2 + mob->str / 3.0 + mob->dex / 2.0 +
- mob->luk) * (1872.0 / mob->adelay) / 4;
+ (mob->atk1 + mob->atk2 + mob->attrs[ATTR::STR] / 3.0 + mob->attrs[ATTR::DEX] / 2.0 +
+ mob->attrs[ATTR::LUK]) * (1872.0 / mob->adelay) / 4;
double dodge_factor =
- pow (mob->lv + mob->agi + mob->luk / 2.0, 4.0 / 3.0);
+ pow(mob->lv + mob->attrs[ATTR::AGI] + mob->attrs[ATTR::LUK] / 2.0, 4.0 / 3.0);
+ // TODO s/persuit/pursuit/g sometime when I'm not worried about diffs
double persuit_factor =
- (3 + mob->range) * (mob->mode % 2) * 1000 / mob->speed;
- double aggression_factor = (mob->mode & 4) == 4 ? 10.0 / 9.0 : 1.0;
- int xp =
- (int) floor (effective_hp *
- pow (sqrt (attack_factor) + sqrt (dodge_factor) +
- sqrt (persuit_factor) + 55,
+ (3 + mob->range) * bool(mob->mode & MobMode::CAN_MOVE) * 1000 / mob->speed;
+ double aggression_factor =
+ bool(mob->mode & MobMode::AGGRESSIVE)
+ ? 10.0 / 9.0
+ : 1.0;
+ int xp =
+ (int) floor(effective_hp *
+ pow(sqrt(attack_factor) + sqrt(dodge_factor) +
+ sqrt(persuit_factor) + 55,
3) * aggression_factor / 2000000.0 *
(double) battle_config.base_exp_rate / 100.);
if (xp < 1)
xp = 1;
- printf ("Exp for mob '%s' generated: %d\n", mob->name, xp);
+ PRINTF("Exp for mob '%s' generated: %d\n", mob->name, xp);
return xp;
}
-static void mob_init (struct mob_data *md)
+static
+void mob_init(struct mob_data *md)
{
- int i;
+ int i;
const int mob_class = md->mob_class;
const int mutations_nr = mob_db[mob_class].mutations_nr;
const int mutation_power = mob_db[mob_class].mutation_power;
- md->stats[MOB_LV] = mob_db[mob_class].lv;
- md->stats[MOB_MAX_HP] = mob_db[mob_class].max_hp;
- md->stats[MOB_STR] = mob_db[mob_class].str;
- md->stats[MOB_AGI] = mob_db[mob_class].agi;
- md->stats[MOB_VIT] = mob_db[mob_class].vit;
- md->stats[MOB_INT] = mob_db[mob_class].int_;
- md->stats[MOB_DEX] = mob_db[mob_class].dex;
- md->stats[MOB_LUK] = mob_db[mob_class].luk;
- md->stats[MOB_ATK1] = mob_db[mob_class].atk1;
- md->stats[MOB_ATK2] = mob_db[mob_class].atk2;
- md->stats[MOB_ADELAY] = mob_db[mob_class].adelay;
- md->stats[MOB_DEF] = mob_db[mob_class].def;
- md->stats[MOB_MDEF] = mob_db[mob_class].mdef;
- md->stats[MOB_SPEED] = mob_db[mob_class].speed;
- md->stats[MOB_XP_BONUS] = MOB_XP_BONUS_BASE;
+ md->stats[mob_stat::LV] = mob_db[mob_class].lv;
+ md->stats[mob_stat::MAX_HP] = mob_db[mob_class].max_hp;
+ md->stats[mob_stat::STR] = mob_db[mob_class].attrs[ATTR::STR];
+ md->stats[mob_stat::AGI] = mob_db[mob_class].attrs[ATTR::AGI];
+ md->stats[mob_stat::VIT] = mob_db[mob_class].attrs[ATTR::VIT];
+ md->stats[mob_stat::INT] = mob_db[mob_class].attrs[ATTR::INT];
+ md->stats[mob_stat::DEX] = mob_db[mob_class].attrs[ATTR::DEX];
+ md->stats[mob_stat::LUK] = mob_db[mob_class].attrs[ATTR::LUK];
+ md->stats[mob_stat::ATK1] = mob_db[mob_class].atk1;
+ md->stats[mob_stat::ATK2] = mob_db[mob_class].atk2;
+ md->stats[mob_stat::ADELAY] = mob_db[mob_class].adelay;
+ md->stats[mob_stat::DEF] = mob_db[mob_class].def;
+ md->stats[mob_stat::MDEF] = mob_db[mob_class].mdef;
+ md->stats[mob_stat::SPEED] = mob_db[mob_class].speed;
+ md->stats[mob_stat::XP_BONUS] = MOB_XP_BONUS_BASE;
for (i = 0; i < mutations_nr; i++)
{
- int stat_nr = MRAND (MOB_XP_BONUS + 1);
- int strength;
-
- if (stat_nr >= MOB_XP_BONUS)
- stat_nr = MOB_MAX_HP;
-
- strength =
- ((MRAND ((mutation_power >> 1)) +
- (MRAND ((mutation_power >> 1))) +
- 2) * mutation_scale[stat_nr]) / 100;
-
- strength = MRAND (2) ? strength : -strength;
+ mob_stat stat_nr = random_::choice({
+ mob_stat::LV,
+ mob_stat::MAX_HP,
+ mob_stat::STR,
+ mob_stat::AGI,
+ mob_stat::VIT,
+ mob_stat::INT,
+ mob_stat::DEX,
+ mob_stat::LUK,
+ mob_stat::ATK1,
+ mob_stat::ATK2,
+ mob_stat::ADELAY,
+ mob_stat::DEF,
+ mob_stat::MDEF,
+ mob_stat::SPEED,
+ // double chance to modify hp
+ mob_stat::MAX_HP,
+ });
+ // TODO: if I don't remove this entirely, look into
+ // normal distributions.
+ int strength = (random_::to(mutation_power / 2)
+ + random_::to(mutation_power / 2)
+ + 2)
+ * mutation_scale[stat_nr] / 100;
+
+ if (random_::coin())
+ strength = -strength;
if (strength < -240)
strength = -240; /* Don't go too close to zero */
- mob_mutate (md, stat_nr, strength);
+ mob_mutate(md, stat_nr, strength);
}
}
@@ -339,53 +366,21 @@ static void mob_init (struct mob_data *md)
* The MOB appearance for one time (for scripts)
*------------------------------------------
*/
-int mob_once_spawn (struct map_session_data *sd, const char *mapname,
+int mob_once_spawn(struct map_session_data *sd, const char *mapname,
int x, int y, const char *mobname, int mob_class, int amount,
const char *event)
{
struct mob_data *md = NULL;
- int m, count, lv = 255, r = mob_class;
-
- if (sd)
- lv = sd->status.base_level;
+ int m, count, r = mob_class;
- if (sd && strcmp (mapname, "this") == 0)
+ if (sd && strcmp(mapname, "this") == 0)
m = sd->bl.m;
else
- m = map_mapname2mapid (mapname);
+ m = map_mapname2mapid(mapname);
if (m < 0 || amount <= 0 || (mob_class >= 0 && mob_class <= 1000) || mob_class > 2000) // 値ãŒç•°å¸¸ãªã‚‰å¬å–šã‚’æ­¢ã‚ã‚‹
return 0;
- if (mob_class < 0)
- { // ランダムã«å¬å–š
- int i = 0;
- int j = -mob_class - 1;
- int k;
- if (j >= 0 && j < MAX_RANDOMMONSTER)
- {
- do
- {
- mob_class = MPRAND (1001, 1000);
- k = MRAND (1000000);
- }
- while ((mob_db[mob_class].max_hp <= 0
- || mob_db[mob_class].summonper[j] <= k
- || (lv < mob_db[mob_class].lv
- && battle_config.random_monster_checklv == 1))
- && (i++) < 2000);
- if (i >= 2000)
- {
- mob_class = mob_db[0].summonper[j];
- }
- }
- else
- {
- return 0;
- }
-// if(battle_config.etc_log==1)
-// printf("mobmob_class=%d try=%d\n",mob_class,i);
- }
if (sd)
{
if (x <= 0)
@@ -395,48 +390,38 @@ int mob_once_spawn (struct map_session_data *sd, const char *mapname,
}
else if (x <= 0 || y <= 0)
{
- printf ("mob_once_spawn: ??\n");
+ PRINTF("mob_once_spawn: ??\n");
}
for (count = 0; count < amount; count++)
{
- md = (struct mob_data *) calloc (1, sizeof (struct mob_data));
- if (mob_db[mob_class].mode & 0x02)
+ md = (struct mob_data *) calloc(1, sizeof(struct mob_data));
+ if (bool(mob_db[mob_class].mode & MobMode::LOOTER))
md->lootitem =
- (struct item *) calloc (LOOTITEM_SIZE, sizeof (struct item));
+ (struct item *) calloc(LOOTITEM_SIZE, sizeof(struct item));
else
md->lootitem = NULL;
- mob_spawn_dataset (md, mobname, mob_class);
+ mob_spawn_dataset(md, mobname, mob_class);
md->bl.m = m;
md->bl.x = x;
md->bl.y = y;
if (r < 0 && battle_config.dead_branch_active == 1)
- md->mode = 0x1 + 0x4 + 0x80; //移動ã—ã¦ã‚¢ã‚¯ãƒ†ã‚£ãƒ–ã§åæ’ƒã™ã‚‹
+ //移動ã—ã¦ã‚¢ã‚¯ãƒ†ã‚£ãƒ–ã§åæ’ƒã™ã‚‹
+ md->mode = MobMode::war;
md->m = m;
md->x0 = x;
md->y0 = y;
md->xs = 0;
md->ys = 0;
- md->spawndelay1 = -1; // Only once is a flag.
- md->spawndelay2 = -1; // Only once is a flag.
-
- memcpy (md->npc_event, event, sizeof (md->npc_event));
+ md->spawndelay1 = static_cast<interval_t>(-1); // Only once is a flag.
+ md->spawndelay2 = static_cast<interval_t>(-1); // Only once is a flag.
- md->bl.type = BL_MOB;
- map_addiddb (&md->bl);
- mob_spawn (md->bl.id);
-
- if (mob_class == 1288)
- { // emperium hp based on defense level [Valaris]
- struct guild_castle *gc = guild_mapname2gc (map[md->bl.m].name);
- if (gc)
- {
- mob_db[mob_class].max_hp += 2000 * gc->defense;
- md->hp = mob_db[mob_class].max_hp;
- }
- } // end addition [Valaris]
+ memcpy(md->npc_event, event, sizeof(md->npc_event));
+ md->bl.type = BL::MOB;
+ map_addiddb(&md->bl);
+ mob_spawn(md->bl.id);
}
return (amount > 0) ? md->bl.id : 0;
}
@@ -445,18 +430,18 @@ int mob_once_spawn (struct map_session_data *sd, const char *mapname,
* The MOB appearance for one time (& area specification for scripts)
*------------------------------------------
*/
-int mob_once_spawn_area (struct map_session_data *sd, const char *mapname,
+int mob_once_spawn_area(struct map_session_data *sd, const char *mapname,
int x0, int y0, int x1, int y1,
const char *mobname, int mob_class, int amount,
const char *event)
{
- int x, y, i, c, max, lx = -1, ly = -1, id = 0;
- int m;
+ int x, y, i, max, lx = -1, ly = -1, id = 0;
+ int m;
- if (strcmp (mapname, "this") == 0)
+ if (strcmp(mapname, "this") == 0)
m = sd->bl.m;
else
- m = map_mapname2mapid (mapname);
+ m = map_mapname2mapid(mapname);
max = (y1 - y0 + 1) * (x1 - x0 + 1) * 3;
if (max > 1000)
@@ -467,13 +452,14 @@ int mob_once_spawn_area (struct map_session_data *sd, const char *mapname,
for (i = 0; i < amount; i++)
{
- int j = 0;
+ int j = 0;
do
{
- x = MPRAND (x0, (x1 - x0 + 1));
- y = MPRAND (y0, (y1 - y0 + 1));
+ x = random_::in(x0, x1);
+ y = random_::in(y0, y1);
}
- while (((c = map_getcell (m, x, y)) == 1 || c == 5) && (++j) < max);
+ while (bool(map_getcell(m, x, y) & MapCell::UNWALKABLE)
+ && (++j) < max);
if (j >= max)
{
if (lx >= 0)
@@ -484,178 +470,60 @@ int mob_once_spawn_area (struct map_session_data *sd, const char *mapname,
else
return 0; // Since reference of the place which boils first went wrong, it stops.
}
- id = mob_once_spawn (sd, mapname, x, y, mobname, mob_class, 1, event);
+ id = mob_once_spawn(sd, mapname, x, y, mobname, mob_class, 1, event);
lx = x;
ly = y;
}
return id;
}
-/*==========================================
- * Summoning Guardians [Valaris]
- *------------------------------------------
- */
-int mob_spawn_guardian (struct map_session_data *sd, const char *mapname,
- int x, int y, const char *mobname, int mob_class,
- int amount, const char *event, int guardian)
-{
- struct mob_data *md = NULL;
- int m, count = 1, lv = 255;
-
- if (sd)
- lv = sd->status.base_level;
-
- if (sd && strcmp (mapname, "this") == 0)
- m = sd->bl.m;
- else
- m = map_mapname2mapid (mapname);
-
- if (m < 0 || amount <= 0 || (mob_class >= 0 && mob_class <= 1000) || mob_class > 2000) // 値ãŒç•°å¸¸ãªã‚‰å¬å–šã‚’æ­¢ã‚ã‚‹
- return 0;
-
- if (mob_class < 0)
- return 0;
-
- if (sd)
- {
- if (x <= 0)
- x = sd->bl.x;
- if (y <= 0)
- y = sd->bl.y;
- }
-
- else if (x <= 0 || y <= 0)
- printf ("mob_spawn_guardian: ??\n");
-
- for (count = 0; count < amount; count++)
- {
- struct guild_castle *gc;
- CREATE (md, struct mob_data, 1);
-
- mob_spawn_dataset (md, mobname, mob_class);
- md->bl.m = m;
- md->bl.x = x;
- md->bl.y = y;
- md->m = m;
- md->x0 = x;
- md->y0 = y;
- md->xs = 0;
- md->ys = 0;
- md->spawndelay1 = -1; // Only once is a flag.
- md->spawndelay2 = -1; // Only once is a flag.
-
- memcpy (md->npc_event, event, sizeof (md->npc_event));
-
- md->bl.type = BL_MOB;
- map_addiddb (&md->bl);
- mob_spawn (md->bl.id);
-
- gc = guild_mapname2gc (map[md->bl.m].name);
- if (gc)
- {
- mob_db[mob_class].max_hp += 2000 * gc->defense;
- if (guardian == 0)
- {
- md->hp = gc->Ghp0;
- gc->GID0 = md->bl.id;
- }
- if (guardian == 1)
- {
- md->hp = gc->Ghp1;
- gc->GID1 = md->bl.id;
- }
- if (guardian == 2)
- {
- md->hp = gc->Ghp2;
- gc->GID2 = md->bl.id;
- }
- if (guardian == 3)
- {
- md->hp = gc->Ghp3;
- gc->GID3 = md->bl.id;
- }
- if (guardian == 4)
- {
- md->hp = gc->Ghp4;
- gc->GID4 = md->bl.id;
- }
- if (guardian == 5)
- {
- md->hp = gc->Ghp5;
- gc->GID5 = md->bl.id;
- }
- if (guardian == 6)
- {
- md->hp = gc->Ghp6;
- gc->GID6 = md->bl.id;
- }
- if (guardian == 7)
- {
- md->hp = gc->Ghp7;
- gc->GID7 = md->bl.id;
- }
-
- }
- }
-
- return (amount > 0) ? md->bl.id : 0;
-}
-
-/*==========================================
- * Appearance income of mob
- *------------------------------------------
- */
-int mob_get_viewclass (int mob_class)
-{
- return mob_db[mob_class].view_class;
-}
-
-int mob_get_sex (int mob_class)
+// TODO: deprecate these
+int mob_get_sex(int mob_class)
{
return mob_db[mob_class].sex;
}
-short mob_get_hair (int mob_class)
+short mob_get_hair(int mob_class)
{
return mob_db[mob_class].hair;
}
-short mob_get_hair_color (int mob_class)
+short mob_get_hair_color(int mob_class)
{
return mob_db[mob_class].hair_color;
}
-short mob_get_weapon (int mob_class)
+short mob_get_weapon(int mob_class)
{
return mob_db[mob_class].weapon;
}
-short mob_get_shield (int mob_class)
+short mob_get_shield(int mob_class)
{
return mob_db[mob_class].shield;
}
-short mob_get_head_top (int mob_class)
+short mob_get_head_top(int mob_class)
{
return mob_db[mob_class].head_top;
}
-short mob_get_head_mid (int mob_class)
+short mob_get_head_mid(int mob_class)
{
return mob_db[mob_class].head_mid;
}
-short mob_get_head_buttom (int mob_class)
+short mob_get_head_buttom(int mob_class)
{
return mob_db[mob_class].head_buttom;
}
-short mob_get_clothes_color (int mob_class) // Add for player monster dye - Valaris
+short mob_get_clothes_color(int mob_class) // Add for player monster dye - Valaris
{
return mob_db[mob_class].clothes_color; // End
}
-int mob_get_equip (int mob_class) // mob equip [Valaris]
+int mob_get_equip(int mob_class) // mob equip [Valaris]
{
return mob_db[mob_class].equip;
}
@@ -665,19 +533,12 @@ int mob_get_equip (int mob_class) // mob equip [Valaris]
*------------------------------------------
*/
static
-int mob_can_move (struct mob_data *md)
+int mob_can_move(struct mob_data *md)
{
- nullpo_retr (0, md);
+ nullpo_ret(md);
- if (md->canmove_tick > gettick () || (md->opt1 > 0 && md->opt1 != 6)
- || md->option & 2)
- return 0;
- // アンクル中ã§å‹•ã‘ãªã„ã¨ã‹
- if (md->sc_data[SC_ANKLE].timer != -1 || //アンクルスãƒã‚¢
- md->sc_data[SC_AUTOCOUNTER].timer != -1 || //オートカウンター
- md->sc_data[SC_BLADESTOP].timer != -1 || //白刃å–ã‚Š
- md->sc_data[SC_SPIDERWEB].timer != -1 //スパイダーウェッブ
- )
+ if (md->canmove_tick > gettick()
+ || (bool(md->opt1) && md->opt1 != Opt1::_stone6))
return 0;
return 1;
@@ -687,34 +548,34 @@ int mob_can_move (struct mob_data *md)
* Time calculation concerning one step next to mob
*------------------------------------------
*/
-static int calc_next_walk_step (struct mob_data *md)
+static
+interval_t calc_next_walk_step(struct mob_data *md)
{
- nullpo_retr (0, md);
+ nullpo_retr(interval_t::zero(), md);
if (md->walkpath.path_pos >= md->walkpath.path_len)
- return -1;
- if (md->walkpath.path[md->walkpath.path_pos] & 1)
- return battle_get_speed (&md->bl) * 14 / 10;
- return battle_get_speed (&md->bl);
+ return static_cast<interval_t>(-1);
+ if (dir_is_diagonal(md->walkpath.path[md->walkpath.path_pos]))
+ return battle_get_speed(&md->bl) * 14 / 10;
+ return battle_get_speed(&md->bl);
}
-static int mob_walktoxy_sub (struct mob_data *md);
+static
+int mob_walktoxy_sub(struct mob_data *md);
/*==========================================
* Mob Walk processing
*------------------------------------------
*/
-static int mob_walk (struct mob_data *md, unsigned int tick, int data)
+static
+int mob_walk(struct mob_data *md, tick_t tick, unsigned char data)
{
- int moveblock;
- int i, ctype;
- static int dirx[8] = { 0, -1, -1, -1, 0, 1, 1, 1 };
- static int diry[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };
- int x, y, dx, dy;
+ int moveblock;
+ int x, y, dx, dy;
- nullpo_retr (0, md);
+ nullpo_ret(md);
- md->state.state = MS_IDLE;
+ md->state.state = MS::IDLE;
if (md->walkpath.path_pos >= md->walkpath.path_len
|| md->walkpath.path_pos != data)
return 0;
@@ -725,41 +586,41 @@ static int mob_walk (struct mob_data *md, unsigned int tick, int data)
md->walkpath.path_pos++;
if (md->state.change_walk_target)
{
- mob_walktoxy_sub (md);
+ mob_walktoxy_sub(md);
return 0;
}
}
else
{
- if (md->walkpath.path[md->walkpath.path_pos] >= 8)
+ if (md->walkpath.path[md->walkpath.path_pos] >= DIR::COUNT)
return 1;
x = md->bl.x;
y = md->bl.y;
- ctype = map_getcell (md->bl.m, x, y);
- if (ctype == 1 || ctype == 5)
+ if (bool(map_getcell(md->bl.m, x, y) & MapCell::UNWALKABLE))
{
- mob_stop_walking (md, 1);
+ mob_stop_walking(md, 1);
return 0;
}
md->dir = md->walkpath.path[md->walkpath.path_pos];
dx = dirx[md->dir];
dy = diry[md->dir];
- ctype = map_getcell (md->bl.m, x + dx, y + dy);
- if (ctype == 1 || ctype == 5)
+ if (bool(map_getcell(md->bl.m, x + dx, y + dy)
+ & MapCell::UNWALKABLE))
{
- mob_walktoxy_sub (md);
+ mob_walktoxy_sub(md);
return 0;
}
moveblock = (x / BLOCK_SIZE != (x + dx) / BLOCK_SIZE
|| y / BLOCK_SIZE != (y + dy) / BLOCK_SIZE);
- md->state.state = MS_WALK;
- map_foreachinmovearea (clif_moboutsight, md->bl.m, x - AREA_SIZE,
- y - AREA_SIZE, x + AREA_SIZE, y + AREA_SIZE,
- dx, dy, BL_PC, md);
+ md->state.state = MS::WALK;
+ map_foreachinmovearea(std::bind(clif_moboutsight, ph::_1, md),
+ md->bl.m, x - AREA_SIZE, y - AREA_SIZE,
+ x + AREA_SIZE, y + AREA_SIZE,
+ dx, dy, BL::PC);
x += dx;
y += dy;
@@ -767,33 +628,31 @@ static int mob_walk (struct mob_data *md, unsigned int tick, int data)
md->min_chase--;
if (moveblock)
- map_delblock (&md->bl);
+ map_delblock(&md->bl);
md->bl.x = x;
md->bl.y = y;
if (moveblock)
- map_addblock (&md->bl);
-
- map_foreachinmovearea (clif_mobinsight, md->bl.m, x - AREA_SIZE,
- y - AREA_SIZE, x + AREA_SIZE, y + AREA_SIZE,
- -dx, -dy, BL_PC, md);
- md->state.state = MS_IDLE;
+ map_addblock(&md->bl);
- if (md->option & 4)
- skill_check_cloaking (&md->bl);
-
- skill_unit_move (&md->bl, tick, 1); // Inspection of a skill unit
+ map_foreachinmovearea(std::bind(clif_mobinsight, ph::_1, md),
+ md->bl.m, x - AREA_SIZE, y - AREA_SIZE,
+ x + AREA_SIZE, y + AREA_SIZE,
+ -dx, -dy, BL::PC);
+ md->state.state = MS::IDLE;
}
- if ((i = calc_next_walk_step (md)) > 0)
+ interval_t i = calc_next_walk_step(md);
+ if (i > interval_t::zero())
{
- i = i >> 1;
- if (i < 1 && md->walkpath.path_half == 0)
- i = 1;
- md->timer =
- add_timer (tick + i, mob_timer, md->bl.id, md->walkpath.path_pos);
- md->state.state = MS_WALK;
+ i = i / 2;
+ if (md->walkpath.path_half == 0)
+ i = std::max(i, std::chrono::milliseconds(1));
+ md->timer = Timer(tick + i,
+ std::bind(mob_timer, ph::_1, ph::_2,
+ md->bl.id, md->walkpath.path_pos));
+ md->state.state = MS::WALK;
if (md->walkpath.path_pos >= md->walkpath.path_len)
- clif_fixmobpos (md); // When mob stops, retransmission current of a position.
+ clif_fixmobpos(md); // When mob stops, retransmission current of a position.
}
return 0;
}
@@ -802,152 +661,145 @@ static int mob_walk (struct mob_data *md, unsigned int tick, int data)
* Check if mob should be attempting to attack
*------------------------------------------
*/
-static int mob_check_attack (struct mob_data *md)
+static
+int mob_check_attack(struct mob_data *md)
{
struct block_list *tbl = NULL;
struct map_session_data *tsd = NULL;
struct mob_data *tmd = NULL;
- int mode, race, range;
+ MobMode mode;
+ int range;
- nullpo_retr (0, md);
+ nullpo_ret(md);
md->min_chase = 13;
- md->state.state = MS_IDLE;
- md->state.skillstate = MSS_IDLE;
+ md->state.state = MS::IDLE;
+ md->state.skillstate = MobSkillState::MSS_IDLE;
- if (md->skilltimer != -1)
+ if (md->skilltimer)
return 0;
- if (md->opt1 > 0 || md->option & 2)
+ if (bool(md->opt1))
return 0;
- if (md->sc_data[SC_AUTOCOUNTER].timer != -1)
- return 0;
-
- if (md->sc_data[SC_BLADESTOP].timer != -1)
- return 0;
-
- if ((tbl = map_id2bl (md->target_id)) == NULL)
+ if ((tbl = map_id2bl(md->target_id)) == NULL)
{
md->target_id = 0;
- md->state.targettype = NONE_ATTACKABLE;
+ md->state.attackable = false;
return 0;
}
- if (tbl->type == BL_PC)
+ if (tbl->type == BL::PC)
tsd = (struct map_session_data *) tbl;
- else if (tbl->type == BL_MOB)
+ else if (tbl->type == BL::MOB)
tmd = (struct mob_data *) tbl;
else
return 0;
if (tsd)
{
- if (pc_isdead (tsd) || tsd->invincible_timer != -1
- || pc_isinvisible (tsd) || md->bl.m != tbl->m || tbl->prev == NULL
- || distance (md->bl.x, md->bl.y, tbl->x, tbl->y) >= 13)
+ if (pc_isdead(tsd) || tsd->invincible_timer
+ || pc_isinvisible(tsd) || md->bl.m != tbl->m || tbl->prev == NULL
+ || distance(md->bl.x, md->bl.y, tbl->x, tbl->y) >= 13)
{
md->target_id = 0;
- md->state.targettype = NONE_ATTACKABLE;
+ md->state.attackable = false;
return 0;
}
}
if (tmd)
{
if (md->bl.m != tbl->m || tbl->prev == NULL
- || distance (md->bl.x, md->bl.y, tbl->x, tbl->y) >= 13)
+ || distance(md->bl.x, md->bl.y, tbl->x, tbl->y) >= 13)
{
md->target_id = 0;
- md->state.targettype = NONE_ATTACKABLE;
+ md->state.attackable = false;
return 0;
}
}
- if (!md->mode)
+ if (md->mode == MobMode::ZERO)
mode = mob_db[md->mob_class].mode;
else
mode = md->mode;
- race = mob_db[md->mob_class].race;
- if (!(mode & 0x80))
+ Race race = mob_db[md->mob_class].race;
+ if (!bool(mode & MobMode::CAN_ATTACK))
{
md->target_id = 0;
- md->state.targettype = NONE_ATTACKABLE;
+ md->state.attackable = false;
return 0;
}
- if (tsd && !(mode & 0x20) && (tsd->sc_data[SC_TRICKDEAD].timer != -1 ||
- ((pc_ishiding (tsd)
- || tsd->state.gangsterparadise)
- && race != 4 && race != 6)))
+ if (tsd
+ && !bool(mode & MobMode::BOSS)
+ && (tsd->state.gangsterparadise
+ && race != Race::_insect
+ && race != Race::_demon))
{
md->target_id = 0;
- md->state.targettype = NONE_ATTACKABLE;
+ md->state.attackable = false;
return 0;
}
range = mob_db[md->mob_class].range;
- if (mode & 1)
+ if (bool(mode & MobMode::CAN_MOVE))
range++;
- if (distance (md->bl.x, md->bl.y, tbl->x, tbl->y) > range)
+ if (distance(md->bl.x, md->bl.y, tbl->x, tbl->y) > range)
return 0;
return 1;
}
-static int mob_ancillary_attack(struct block_list *bl, va_list ap)
+static
+void mob_ancillary_attack(struct block_list *bl,
+ struct block_list *mdbl, struct block_list *tbl, tick_t tick)
{
- struct block_list *mdbl = va_arg(ap, struct block_list *);
- struct block_list *tbl = va_arg(ap, struct block_list *);
- unsigned int tick = va_arg(ap, unsigned int);
if (bl != tbl)
- battle_weapon_attack(mdbl, bl, tick, 0);
- return 0;
+ battle_weapon_attack(mdbl, bl, tick);
}
/*==========================================
* Attack processing of mob
*------------------------------------------
*/
-static int mob_attack (struct mob_data *md, unsigned int tick, int data)
+static
+int mob_attack(struct mob_data *md, tick_t tick)
{
struct block_list *tbl = NULL;
- nullpo_retr (0, md);
+ nullpo_ret(md);
- if ((tbl = map_id2bl (md->target_id)) == NULL)
+ if ((tbl = map_id2bl(md->target_id)) == NULL)
return 0;
- if (!mob_check_attack (md))
+ if (!mob_check_attack(md))
return 0;
if (battle_config.monster_attack_direction_change)
- md->dir = map_calc_dir (&md->bl, tbl->x, tbl->y); // å‘ã設定
+ md->dir = map_calc_dir(&md->bl, tbl->x, tbl->y); // å‘ã設定
//clif_fixmobpos(md);
- md->state.skillstate = MSS_ATTACK;
- if (mobskill_use (md, tick, -2)) // スキル使用
+ md->state.skillstate = MobSkillState::MSS_ATTACK;
+ if (mobskill_use(md, tick, MobSkillCondition::NEVER_EQUAL))
return 0;
- md->target_lv = battle_weapon_attack (&md->bl, tbl, tick, 0);
+ md->target_lv = battle_weapon_attack(&md->bl, tbl, tick);
// If you are reading this, please note:
// it is highly platform-specific that this even works at all.
int radius = battle_config.mob_splash_radius;
- if (radius >= 0 && tbl->type == BL_PC && !map[tbl->m].flag.town)
- map_foreachinarea(mob_ancillary_attack,
- tbl->m, tbl->x - radius, tbl->y - radius, tbl->x + radius, tbl->y + radius,
- BL_PC,
- &md->bl, tbl, tick);
-
- if (!(battle_config.monster_cloak_check_type & 2)
- && md->sc_data[SC_CLOAKING].timer != -1)
- skill_status_change_end (&md->bl, SC_CLOAKING, -1);
+ if (radius >= 0 && tbl->type == BL::PC && !map[tbl->m].flag.town)
+ map_foreachinarea(std::bind(mob_ancillary_attack, ph::_1, &md->bl, tbl, tick),
+ tbl->m, tbl->x - radius, tbl->y - radius,
+ tbl->x + radius, tbl->y + radius, BL::PC);
- md->attackabletime = tick + battle_get_adelay (&md->bl);
+ md->attackabletime = tick + battle_get_adelay(&md->bl);
- md->timer = add_timer (md->attackabletime, mob_timer, md->bl.id, 0);
- md->state.state = MS_ATTACK;
+ md->timer = Timer(md->attackabletime,
+ std::bind(mob_timer, ph::_1, ph::_2,
+ md->bl.id, 0));
+ md->state.state = MS::ATTACK;
return 0;
}
@@ -958,86 +810,78 @@ static int mob_attack (struct mob_data *md, unsigned int tick, int data)
*------------------------------------------
*/
static
-int mob_stopattacked (struct map_session_data *sd, va_list ap)
+void mob_stopattacked(struct map_session_data *sd, int id)
{
- int id;
-
- nullpo_retr (0, sd);
- nullpo_retr (0, ap);
+ nullpo_retv(sd);
- id = va_arg (ap, int);
if (sd->attacktarget == id)
- pc_stopattack (sd);
- return 0;
+ pc_stopattack(sd);
}
/*==========================================
* The timer in which the mob's states changes
*------------------------------------------
*/
-int mob_changestate (struct mob_data *md, int state, int type)
+static
+int mob_changestate(struct mob_data *md, MS state, bool type)
{
- unsigned int tick;
- int i;
-
- nullpo_retr (0, md);
+ nullpo_ret(md);
- if (md->timer != -1)
- delete_timer (md->timer, mob_timer);
- md->timer = -1;
+ md->timer.cancel();
md->state.state = state;
switch (state)
{
- case MS_WALK:
- if ((i = calc_next_walk_step (md)) > 0)
+ case MS::WALK:
+ {
+ interval_t i = calc_next_walk_step(md);
+ if (i > interval_t::zero())
{
- i = i >> 2;
- md->timer =
- add_timer (gettick () + i, mob_timer, md->bl.id, 0);
+ i = i / 4;
+ md->timer = Timer(gettick() + i,
+ std::bind(mob_timer, ph::_1, ph::_2,
+ md->bl.id, 0));
}
else
- md->state.state = MS_IDLE;
+ md->state.state = MS::IDLE;
+ }
break;
- case MS_ATTACK:
- tick = gettick ();
- i = DIFF_TICK (md->attackabletime, tick);
- if (i > 0 && i < 2000)
- md->timer =
- add_timer (md->attackabletime, mob_timer, md->bl.id, 0);
+ case MS::ATTACK:
+ {
+ tick_t tick = gettick();
+ interval_t i = md->attackabletime - tick;
+ if (i > interval_t::zero() && i < std::chrono::seconds(2))
+ md->timer = Timer(md->attackabletime,
+ std::bind(mob_timer, ph::_1, ph::_2,
+ md->bl.id, 0));
else if (type)
{
- md->attackabletime = tick + battle_get_amotion (&md->bl);
- md->timer =
- add_timer (md->attackabletime, mob_timer, md->bl.id, 0);
+ md->attackabletime = tick + battle_get_amotion(&md->bl);
+ md->timer = Timer(md->attackabletime,
+ std::bind(mob_timer, ph::_1, ph::_2,
+ md->bl.id, 0));
}
else
{
- md->attackabletime = tick + 1;
- md->timer =
- add_timer (md->attackabletime, mob_timer, md->bl.id, 0);
+ md->attackabletime = tick + std::chrono::milliseconds(1);
+ md->timer = Timer(md->attackabletime,
+ std::bind(mob_timer, ph::_1, ph::_2,
+ md->bl.id, 0));
}
+ }
break;
- case MS_DELAY:
- md->timer =
- add_timer (gettick () + type, mob_timer, md->bl.id, 0);
- break;
- case MS_DEAD:
- skill_castcancel (&md->bl, 0);
-// mobskill_deltimer(md);
- md->state.skillstate = MSS_DEAD;
- md->last_deadtime = gettick ();
+ case MS::DEAD:
+ {
+ skill_castcancel(&md->bl, 0);
+ md->state.skillstate = MobSkillState::MSS_DEAD;
+ md->last_deadtime = gettick();
// Since it died, all aggressors' attack to this mob is stopped.
- clif_foreachclient (mob_stopattacked, md->bl.id);
- skill_unit_out_all (&md->bl, gettick (), 1);
- skill_status_change_clear (&md->bl, 2); // The abnormalities in status are canceled.
- skill_clear_unitgroup (&md->bl); // All skill unit groups are deleted.
- skill_cleartimerskill (&md->bl);
- if (md->deletetimer != -1)
- delete_timer (md->deletetimer, mob_timer_delete);
- md->deletetimer = -1;
+ clif_foreachclient(std::bind(mob_stopattacked, ph::_1, md->bl.id));
+ skill_status_change_clear(&md->bl, 2); // The abnormalities in status are canceled.
+ md->deletetimer.cancel();
md->hp = md->target_id = md->attacked_id = 0;
- md->state.targettype = NONE_ATTACKABLE;
+ md->state.attackable = false;
+ }
break;
}
@@ -1049,53 +893,42 @@ int mob_changestate (struct mob_data *md, int state, int type)
* It branches to a walk and an attack.
*------------------------------------------
*/
-static void mob_timer (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data)
+static
+void mob_timer(TimerData *, tick_t tick, int id, unsigned char data)
{
struct mob_data *md;
struct block_list *bl;
-
- if ((bl = map_id2bl (id)) == NULL)
+ bl = map_id2bl(id);
+ if (bl == NULL)
{ //攻撃ã—ã¦ããŸæ•µãŒã‚‚ã†ã„ãªã„ã®ã¯æ­£å¸¸ã®ã‚ˆã†ã 
return;
}
- if (!bl || !bl->type || bl->type != BL_MOB)
+ if (bl->type == BL::NUL || bl->type != BL::MOB)
return;
- nullpo_retv (md = (struct mob_data *) bl);
+ md = (struct mob_data *) bl;
- if (!md->bl.type || md->bl.type != BL_MOB)
+ if (md->bl.prev == NULL || md->state.state == MS::DEAD)
return;
- if (md->timer != tid)
- {
- if (battle_config.error_log == 1)
- printf ("mob_timer %d != %d\n", md->timer, tid);
- return;
- }
- md->timer = -1;
- if (md->bl.prev == NULL || md->state.state == MS_DEAD)
- return;
-
- map_freeblock_lock ();
+ map_freeblock_lock();
switch (md->state.state)
{
- case MS_WALK:
- mob_check_attack (md);
- mob_walk (md, tick, data);
+ case MS::WALK:
+ mob_check_attack(md);
+ mob_walk(md, tick, data);
break;
- case MS_ATTACK:
- mob_attack (md, tick, data);
- break;
- case MS_DELAY:
- mob_changestate (md, MS_IDLE, 0);
+ case MS::ATTACK:
+ mob_attack(md, tick);
break;
default:
if (battle_config.error_log == 1)
- printf ("mob_timer : %d ?\n", md->state.state);
+ PRINTF("mob_timer : %d ?\n",
+ md->state.state);
break;
}
- map_freeblock_unlock ();
+ map_freeblock_unlock();
return;
}
@@ -1103,21 +936,21 @@ static void mob_timer (timer_id tid, tick_t tick, custom_id_t id, custom_data_t
*
*------------------------------------------
*/
-static int mob_walktoxy_sub (struct mob_data *md)
+static
+int mob_walktoxy_sub(struct mob_data *md)
{
struct walkpath_data wpd;
- nullpo_retr (0, md);
+ nullpo_ret(md);
- if (path_search
- (&wpd, md->bl.m, md->bl.x, md->bl.y, md->to_x, md->to_y,
+ if (path_search(&wpd, md->bl.m, md->bl.x, md->bl.y, md->to_x, md->to_y,
md->state.walk_easy))
return 1;
- memcpy (&md->walkpath, &wpd, sizeof (wpd));
+ memcpy(&md->walkpath, &wpd, sizeof(wpd));
md->state.change_walk_target = 0;
- mob_changestate (md, MS_WALK, 0);
- clif_movemob (md);
+ mob_changestate(md, MS::WALK, 0);
+ clif_movemob(md);
return 0;
}
@@ -1126,26 +959,27 @@ static int mob_walktoxy_sub (struct mob_data *md)
* mob move start
*------------------------------------------
*/
-int mob_walktoxy (struct mob_data *md, int x, int y, int easy)
+static
+int mob_walktoxy(struct mob_data *md, int x, int y, int easy)
{
struct walkpath_data wpd;
- nullpo_retr (0, md);
+ nullpo_ret(md);
- if (md->state.state == MS_WALK
- && path_search (&wpd, md->bl.m, md->bl.x, md->bl.y, x, y, easy))
+ if (md->state.state == MS::WALK
+ && path_search(&wpd, md->bl.m, md->bl.x, md->bl.y, x, y, easy))
return 1;
md->state.walk_easy = easy;
md->to_x = x;
md->to_y = y;
- if (md->state.state == MS_WALK)
+ if (md->state.state == MS::WALK)
{
md->state.change_walk_target = 1;
}
else
{
- return mob_walktoxy_sub (md);
+ return mob_walktoxy_sub(md);
}
return 0;
@@ -1155,9 +989,10 @@ int mob_walktoxy (struct mob_data *md, int x, int y, int easy)
* mob spawn with delay (timer function)
*------------------------------------------
*/
-static void mob_delayspawn (timer_id tid, tick_t tick, custom_id_t m, custom_data_t n)
+static
+void mob_delayspawn(TimerData *, tick_t, int m)
{
- mob_spawn (m);
+ mob_spawn(m);
}
/*==========================================
@@ -1165,54 +1000,47 @@ static void mob_delayspawn (timer_id tid, tick_t tick, custom_id_t m, custom_dat
*------------------------------------------
*/
static
-int mob_setdelayspawn (int id)
+int mob_setdelayspawn(int id)
{
- unsigned int spawntime, spawntime1, spawntime2, spawntime3;
struct mob_data *md;
struct block_list *bl;
- if ((bl = map_id2bl (id)) == NULL)
+ if ((bl = map_id2bl(id)) == NULL)
return -1;
- if (!bl || !bl->type || bl->type != BL_MOB)
+ if (!bl || bl->type == BL::NUL || bl->type != BL::MOB)
return -1;
- nullpo_retr (-1, md = (struct mob_data *) bl);
+ md = (struct mob_data *) bl;
+ nullpo_retr(-1, md);
- if (!md || md->bl.type != BL_MOB)
+ if (!md || md->bl.type != BL::MOB)
return -1;
// Processing of MOB which is not revitalized
- if (md->spawndelay1 == -1 && md->spawndelay2 == -1 && md->n == 0)
+ if (md->spawndelay1 == static_cast<interval_t>(-1)
+ && md->spawndelay2 == static_cast<interval_t>(-1)
+ && md->n == 0)
{
- map_deliddb (&md->bl);
+ map_deliddb(&md->bl);
if (md->lootitem)
{
- map_freeblock (md->lootitem);
+ map_freeblock(md->lootitem);
md->lootitem = NULL;
}
- map_freeblock (md); // Instead of [ of free ]
+ map_freeblock(md); // Instead of [ of free ]
return 0;
}
- spawntime1 = md->last_spawntime + md->spawndelay1;
- spawntime2 = md->last_deadtime + md->spawndelay2;
- spawntime3 = gettick () + 5000;
- // spawntime = max(spawntime1,spawntime2,spawntime3);
- if (DIFF_TICK (spawntime1, spawntime2) > 0)
- {
- spawntime = spawntime1;
- }
- else
- {
- spawntime = spawntime2;
- }
- if (DIFF_TICK (spawntime3, spawntime) > 0)
- {
- spawntime = spawntime3;
- }
+ tick_t spawntime1 = md->last_spawntime + md->spawndelay1;
+ tick_t spawntime2 = md->last_deadtime + md->spawndelay2;
+ tick_t spawntime3 = gettick() + std::chrono::seconds(5);
+ tick_t spawntime = std::max({spawntime1, spawntime2, spawntime3});
- add_timer (spawntime, mob_delayspawn, id, 0);
+ Timer(spawntime,
+ std::bind(mob_delayspawn, ph::_1, ph::_2,
+ id)
+ ).detach();
return 0;
}
@@ -1220,121 +1048,124 @@ int mob_setdelayspawn (int id)
* Mob spawning. Initialization is also variously here.
*------------------------------------------
*/
-int mob_spawn (int id)
+int mob_spawn(int id)
{
- int x = 0, y = 0, i = 0, c;
- unsigned int tick = gettick ();
+ int x = 0, y = 0;
+ tick_t tick = gettick();
struct mob_data *md;
struct block_list *bl;
- nullpo_retr (-1, bl = map_id2bl (id));
+ bl = map_id2bl(id);
+ nullpo_retr(-1, bl);
- if (!bl || !bl->type || bl->type != BL_MOB)
+ if (!bl || bl->type == BL::NUL || bl->type != BL::MOB)
return -1;
- nullpo_retr (-1, md = (struct mob_data *) bl);
+ md = (struct mob_data *) bl;
+ nullpo_retr(-1, md);
- if (!md || !md->bl.type || md->bl.type != BL_MOB)
+ if (!md || md->bl.type == BL::NUL || md->bl.type != BL::MOB)
return -1;
md->last_spawntime = tick;
if (md->bl.prev != NULL)
{
-// clif_clearchar_area(&md->bl,3);
- skill_unit_out_all (&md->bl, gettick (), 1);
- map_delblock (&md->bl);
+ map_delblock(&md->bl);
}
- else
- md->mob_class = md->base_class;
md->bl.m = md->m;
- do
{
- if (md->x0 == 0 && md->y0 == 0)
+ int i = 0;
+ do
{
- x = MPRAND (1, (map[md->bl.m].xs - 2));
- y = MPRAND (1, (map[md->bl.m].ys - 2));
+ if (md->x0 == 0 && md->y0 == 0)
+ {
+ x = random_::in(1, map[md->bl.m].xs - 2);
+ y = random_::in(1, map[md->bl.m].ys - 2);
+ }
+ else
+ {
+ // TODO: move this logic earlier - possibly all the way
+ // into the data files
+ x = md->x0 - md->xs / 2 + random_::in(0, md->xs);
+ y = md->y0 - md->ys / 2 + random_::in(0, md->ys);
+ }
+ i++;
}
- else
+ while (bool(map_getcell(md->bl.m, x, y) & MapCell::UNWALKABLE)
+ && i < 50);
+
+ if (i >= 50)
{
- x = MPRAND (md->x0, (md->xs + 1)) - md->xs / 2;
- y = MPRAND (md->y0, (md->ys + 1)) - md->ys / 2;
+ // if(battle_config.error_log==1)
+ // PRINTF("MOB spawn error %d @ %s\n",id,map[md->bl.m].name);
+ Timer(tick + std::chrono::seconds(5),
+ std::bind(mob_delayspawn, ph::_1, ph::_2,
+ id)
+ ).detach();
+ return 1;
}
- i++;
- }
- while (((c = map_getcell (md->bl.m, x, y)) == 1 || c == 5) && i < 50);
-
- if (i >= 50)
- {
-// if(battle_config.error_log==1)
-// printf("MOB spawn error %d @ %s\n",id,map[md->bl.m].name);
- add_timer (tick + 5000, mob_delayspawn, id, 0);
- return 1;
}
md->to_x = md->bl.x = x;
md->to_y = md->bl.y = y;
- md->dir = 0;
+ md->dir = DIR::S;
- map_addblock (&md->bl);
+ map_addblock(&md->bl);
- memset (&md->state, 0, sizeof (md->state));
+ memset(&md->state, 0, sizeof(md->state));
md->attacked_id = 0;
md->target_id = 0;
md->move_fail_count = 0;
- mob_init (md);
+ mob_init(md);
- if (!md->stats[MOB_SPEED])
- md->stats[MOB_SPEED] = mob_db[md->mob_class].speed;
+ if (!md->stats[mob_stat::SPEED])
+ md->stats[mob_stat::SPEED] = mob_db[md->mob_class].speed;
md->def_ele = mob_db[md->mob_class].element;
md->master_id = 0;
md->master_dist = 0;
- md->state.state = MS_IDLE;
- md->state.skillstate = MSS_IDLE;
- md->timer = -1;
+ md->state.state = MS::IDLE;
+ md->state.skillstate = MobSkillState::MSS_IDLE;
+ assert (!md->timer);
md->last_thinktime = tick;
- md->next_walktime = tick + MPRAND (5000, 50);
+ md->next_walktime = tick + std::chrono::seconds(5) + std::chrono::milliseconds(random_::to(50));
md->attackabletime = tick;
md->canmove_tick = tick;
md->sg_count = 0;
- md->deletetimer = -1;
+ // md->deletetimer = nullptr;
- md->skilltimer = -1;
- for (i = 0, c = tick - 1000 * 3600 * 10; i < MAX_MOBSKILL; i++)
- md->skilldelay[i] = c;
- md->skillid = 0;
+ // md->skilltimer = nullptr;
+ for (int i = 0; i < MAX_MOBSKILL; i++)
+ md->skilldelay[i] = tick - std::chrono::hours(10);
+ md->skillid = SkillID();
md->skilllv = 0;
- memset (md->dmglog, 0, sizeof (md->dmglog));
+ memset(md->dmglog, 0, sizeof(md->dmglog));
if (md->lootitem)
- memset (md->lootitem, 0, sizeof (md->lootitem));
+ memset(md->lootitem, 0, sizeof(*md->lootitem));
md->lootitem_count = 0;
- for (i = 0; i < MAX_MOBSKILLTIMERSKILL; i++)
- md->skilltimerskill[i].timer = -1;
-
- for (i = 0; i < MAX_STATUSCHANGE; i++)
+ for (StatusChange i : erange(StatusChange(), StatusChange::MAX_STATUSCHANGE))
{
- md->sc_data[i].timer = -1;
- md->sc_data[i].val1 = md->sc_data[i].val2 = md->sc_data[i].val3 =
- md->sc_data[i].val4 = 0;
+ assert (!md->sc_data[i].timer);
+ md->sc_data[i].val1 = 0;
}
md->sc_count = 0;
- md->opt1 = md->opt2 = md->opt3 = md->option = 0;
+ md->opt1 = Opt1::ZERO;
+ md->opt2 = Opt2::ZERO;
+ md->opt3 = Opt3::ZERO;
+ md->option = Option::ZERO;
- memset (md->skillunit, 0, sizeof (md->skillunit));
- memset (md->skillunittick, 0, sizeof (md->skillunittick));
-
- md->hp = battle_get_max_hp (&md->bl);
+ md->hp = battle_get_max_hp(&md->bl);
if (md->hp <= 0)
{
- mob_makedummymobdb (md->mob_class);
- md->hp = battle_get_max_hp (&md->bl);
+ mob_makedummymobdb(md->mob_class);
+ md->hp = battle_get_max_hp(&md->bl);
}
- clif_spawnmob (md);
+ clif_spawnmob(md);
return 0;
}
@@ -1343,12 +1174,13 @@ int mob_spawn (int id)
* Distance calculation between two points
*------------------------------------------
*/
-static int distance (int x0, int y0, int x1, int y1)
+static
+int distance(int x0, int y0, int x1, int y1)
{
- int dx, dy;
+ int dx, dy;
- dx = abs (x0 - x1);
- dy = abs (y0 - y1);
+ dx = abs(x0 - x1);
+ dy = abs(y0 - y1);
return dx > dy ? dx : dy;
}
@@ -1356,10 +1188,10 @@ static int distance (int x0, int y0, int x1, int y1)
* The stop of MOB's attack
*------------------------------------------
*/
-int mob_stopattack (struct mob_data *md)
+int mob_stopattack(struct mob_data *md)
{
md->target_id = 0;
- md->state.targettype = NONE_ATTACKABLE;
+ md->state.attackable = false;
md->attacked_id = 0;
return 0;
}
@@ -1368,13 +1200,13 @@ int mob_stopattack (struct mob_data *md)
* The stop of MOB's walking
*------------------------------------------
*/
-int mob_stop_walking (struct mob_data *md, int type)
+int mob_stop_walking(struct mob_data *md, int type)
{
- nullpo_retr (0, md);
+ nullpo_ret(md);
- if (md->state.state == MS_WALK || md->state.state == MS_IDLE)
+ if (md->state.state == MS::WALK || md->state.state == MS::IDLE)
{
- int dx = 0, dy = 0;
+ int dx = 0, dy = 0;
md->walkpath.path_len = 0;
if (type & 4)
@@ -1394,17 +1226,17 @@ int mob_stop_walking (struct mob_data *md, int type)
md->to_y = md->bl.y + dy;
if (dx != 0 || dy != 0)
{
- mob_walktoxy_sub (md);
+ mob_walktoxy_sub(md);
return 0;
}
- mob_changestate (md, MS_IDLE, 0);
+ mob_changestate(md, MS::IDLE, 0);
}
if (type & 0x01)
- clif_fixmobpos (md);
+ clif_fixmobpos(md);
if (type & 0x02)
{
- int delay = battle_get_dmotion (&md->bl);
- unsigned int tick = gettick ();
+ interval_t delay = battle_get_dmotion(&md->bl);
+ tick_t tick = gettick();
if (md->canmove_tick < tick)
md->canmove_tick = tick + delay;
}
@@ -1417,54 +1249,22 @@ int mob_stop_walking (struct mob_data *md, int type)
*------------------------------------------
*/
static
-int mob_can_reach (struct mob_data *md, struct block_list *bl, int range)
+int mob_can_reach(struct mob_data *md, struct block_list *bl, int range)
{
- int dx, dy;
+ int dx, dy;
struct walkpath_data wpd;
- int i;
-
- nullpo_retr (0, md);
- nullpo_retr (0, bl);
-
- dx = abs (bl->x - md->bl.x);
- dy = abs (bl->y - md->bl.y);
-
- //=========== guildcastle guardian no search start===========
- //when players are the guild castle member not attack them !
- if (md->mob_class == 1285 || md->mob_class == 1286 || md->mob_class == 1287)
- {
- struct map_session_data *sd;
- struct guild *g = NULL;
- struct guild_castle *gc = guild_mapname2gc (map[bl->m].name);
-
- if (gc && agit_flag == 0) // Guardians will not attack during non-woe time [Valaris]
- return 0; // end addition [Valaris]
-
- if (bl && bl->type == BL_PC)
- {
- if ((sd = (struct map_session_data *) bl) == NULL)
- {
- printf ("mob_can_reach nullpo\n");
- return 0;
- }
+ int i;
- if (gc && sd && sd->status.guild_id && sd->status.guild_id > 0)
- {
- g = guild_search (sd->status.guild_id); // don't attack guild members [Valaris]
- if (g && g->guild_id > 0 && g->guild_id == gc->guild_id)
- return 0;
- if (g && gc && guild_isallied (g, gc))
- return 0;
+ nullpo_ret(md);
+ nullpo_ret(bl);
- }
- }
- }
- //========== guildcastle guardian no search eof==============
+ dx = abs(bl->x - md->bl.x);
+ dy = abs(bl->y - md->bl.y);
- if (bl && bl->type == BL_PC && battle_config.monsters_ignore_gm == 1)
+ if (bl && bl->type == BL::PC && battle_config.monsters_ignore_gm == 1)
{ // option to have monsters ignore GMs [Valaris]
struct map_session_data *sd;
- if ((sd = (struct map_session_data *) bl) != NULL && pc_isGM (sd))
+ if ((sd = (struct map_session_data *) bl) != NULL && pc_isGM(sd))
return 0;
}
@@ -1481,23 +1281,21 @@ int mob_can_reach (struct mob_data *md, struct block_list *bl, int range)
wpd.path_len = 0;
wpd.path_pos = 0;
wpd.path_half = 0;
- if (path_search (&wpd, md->bl.m, md->bl.x, md->bl.y, bl->x, bl->y, 0) !=
+ if (path_search(&wpd, md->bl.m, md->bl.x, md->bl.y, bl->x, bl->y, 0) !=
-1)
return 1;
- if (bl->type != BL_PC && bl->type != BL_MOB)
+ if (bl->type != BL::PC && bl->type != BL::MOB)
return 0;
// It judges whether it can adjoin or not.
dx = (dx > 0) ? 1 : ((dx < 0) ? -1 : 0);
dy = (dy > 0) ? 1 : ((dy < 0) ? -1 : 0);
- if (path_search
- (&wpd, md->bl.m, md->bl.x, md->bl.y, bl->x - dx, bl->y - dy, 0) != -1)
+ if (path_search(&wpd, md->bl.m, md->bl.x, md->bl.y, bl->x - dx, bl->y - dy, 0) != -1)
return 1;
for (i = 0; i < 9; i++)
{
- if (path_search
- (&wpd, md->bl.m, md->bl.x, md->bl.y, bl->x - 1 + i / 3,
+ if (path_search(&wpd, md->bl.m, md->bl.x, md->bl.y, bl->x - 1 + i / 3,
bl->y - 1 + i % 3, 0) != -1)
return 1;
}
@@ -1508,21 +1306,20 @@ int mob_can_reach (struct mob_data *md, struct block_list *bl, int range)
* Determination for an attack of a monster
*------------------------------------------
*/
-int mob_target (struct mob_data *md, struct block_list *bl, int dist)
+int mob_target(struct mob_data *md, struct block_list *bl, int dist)
{
struct map_session_data *sd;
- struct status_change *sc_data;
- short *option;
- int mode, race;
+ eptr<struct status_change, StatusChange> sc_data;
+ MobMode mode;
- nullpo_retr (0, md);
- nullpo_retr (0, bl);
+ nullpo_ret(md);
+ nullpo_ret(bl);
- sc_data = battle_get_sc_data (bl);
- option = battle_get_option (bl);
- race = mob_db[md->mob_class].race;
+ sc_data = battle_get_sc_data(bl);
+ Option *option = battle_get_option(bl);
+ Race race = mob_db[md->mob_class].race;
- if (!md->mode)
+ if (md->mode == MobMode::ZERO)
{
mode = mob_db[md->mob_class].mode;
}
@@ -1530,35 +1327,39 @@ int mob_target (struct mob_data *md, struct block_list *bl, int dist)
{
mode = md->mode;
}
- if (!(mode & 0x80))
+ if (!bool(mode & MobMode::CAN_ATTACK))
{
md->target_id = 0;
return 0;
}
// Nothing will be carried out if there is no mind of changing TAGE by TAGE ending.
- if ((md->target_id > 0 && md->state.targettype == ATTACKABLE)
- && (!(mode & 0x04) || MRAND (100) > 25))
+ if ((md->target_id > 0 && md->state.attackable)
+ && (!bool(mode & MobMode::AGGRESSIVE)
+ || !random_::chance({25 + 1, 100})))
return 0;
- if (mode & 0x20 || // Coercion is exerted if it is MVPMOB.
- (sc_data && sc_data[SC_TRICKDEAD].timer == -1 &&
- ((option && !(*option & 0x06)) || race == 4 || race == 6)))
+ // Coercion is exerted if it is MVPMOB.
+ if (bool(mode & MobMode::BOSS)
+ || (option != NULL
+ || race == Race::_insect
+ || race == Race::_demon))
{
- if (bl->type == BL_PC)
+ if (bl->type == BL::PC)
{
- nullpo_retr (0, sd = (struct map_session_data *) bl);
- if (sd->invincible_timer != -1 || pc_isinvisible (sd))
+ sd = (struct map_session_data *) bl;
+ nullpo_ret(sd);
+ if (sd->invincible_timer || pc_isinvisible(sd))
return 0;
- if (!(mode & 0x20) && race != 4 && race != 6
+ if (!bool(mode & MobMode::BOSS) && race != Race::_insect && race != Race::_demon
&& sd->state.gangsterparadise)
return 0;
}
md->target_id = bl->id; // Since there was no disturbance, it locks on to target.
- if (bl->type == BL_PC || bl->type == BL_MOB)
- md->state.targettype = ATTACKABLE;
+ if (bl->type == BL::PC || bl->type == BL::MOB)
+ md->state.attackable = true;
else
- md->state.targettype = NONE_ATTACKABLE;
+ md->state.attackable = false;
md->min_chase = dist + 13;
if (md->min_chase > 26)
md->min_chase = 26;
@@ -1570,56 +1371,61 @@ int mob_target (struct mob_data *md, struct block_list *bl, int dist)
* The ?? routine of an active monster
*------------------------------------------
*/
-static int mob_ai_sub_hard_activesearch (struct block_list *bl, va_list ap)
+static
+void mob_ai_sub_hard_activesearch(struct block_list *bl,
+ struct mob_data *smd, int *pcc)
{
struct map_session_data *tsd = NULL;
- struct mob_data *smd, *tmd = NULL;
- int mode, race, dist, *pcc;
+ struct mob_data *tmd = NULL;
+ MobMode mode;
+ int dist;
- nullpo_retr (0, bl);
- nullpo_retr (0, ap);
- nullpo_retr (0, smd = va_arg (ap, struct mob_data *));
- nullpo_retr (0, pcc = va_arg (ap, int *));
+ nullpo_retv(bl);
+ nullpo_retv(smd);
+ nullpo_retv(pcc);
- if (bl->type == BL_PC)
+ if (bl->type == BL::PC)
tsd = (struct map_session_data *) bl;
- else if (bl->type == BL_MOB)
+ else if (bl->type == BL::MOB)
tmd = (struct mob_data *) bl;
else
- return 0;
+ return;
//敵味方判定
- if (battle_check_target (&smd->bl, bl, BCT_ENEMY) == 0)
- return 0;
+ if (battle_check_target(&smd->bl, bl, BCT_ENEMY) == 0)
+ return;
- if (!smd->mode)
+ if (smd->mode == MobMode::ZERO)
mode = mob_db[smd->mob_class].mode;
else
mode = smd->mode;
// アクティブã§ã‚¿ãƒ¼ã‚²ãƒƒãƒˆå°„程内ã«ã„ã‚‹ãªã‚‰ã€ãƒ­ãƒƒã‚¯ã™ã‚‹
- if (mode & 0x04)
+ if (bool(mode & MobMode::AGGRESSIVE))
{
- race = mob_db[smd->mob_class].race;
+ Race race = mob_db[smd->mob_class].race;
//対象ãŒPCã®å ´åˆ
if (tsd &&
- !pc_isdead (tsd) &&
+ !pc_isdead(tsd) &&
tsd->bl.m == smd->bl.m &&
- tsd->invincible_timer == -1 &&
- !pc_isinvisible (tsd) &&
+ !tsd->invincible_timer &&
+ !pc_isinvisible(tsd) &&
(dist =
- distance (smd->bl.x, smd->bl.y, tsd->bl.x, tsd->bl.y)) < 9)
+ distance(smd->bl.x, smd->bl.y, tsd->bl.x, tsd->bl.y)) < 9)
{
- if (mode & 0x20 ||
- (tsd->sc_data[SC_TRICKDEAD].timer == -1 &&
- ((!pc_ishiding (tsd) && !tsd->state.gangsterparadise)
- || race == 4 || race == 6)))
- { // 妨害ãŒãªã„ã‹åˆ¤å®š
- if (mob_can_reach (smd, bl, 12) && // 到é”å¯èƒ½æ€§åˆ¤å®š
- MRAND (1000) < 1000 / (++(*pcc)))
- { // 範囲内PCã§ç­‰ç¢ºçŽ‡ã«ã™ã‚‹
+ if (bool(mode & MobMode::BOSS)
+ || (!tsd->state.gangsterparadise
+ || race == Race::_insect
+ || race == Race::_demon))
+ {
+ // 妨害ãŒãªã„ã‹åˆ¤å®š
+ // 到é”å¯èƒ½æ€§åˆ¤å®š
+ if (mob_can_reach(smd, bl, 12)
+ && random_::chance({1, ++*pcc}))
+ {
+ // 範囲内PCã§ç­‰ç¢ºçŽ‡ã«ã™ã‚‹
smd->target_id = tsd->bl.id;
- smd->state.targettype = ATTACKABLE;
+ smd->state.attackable = true;
smd->min_chase = 13;
}
}
@@ -1628,35 +1434,34 @@ static int mob_ai_sub_hard_activesearch (struct block_list *bl, va_list ap)
else if (tmd &&
tmd->bl.m == smd->bl.m &&
(dist =
- distance (smd->bl.x, smd->bl.y, tmd->bl.x, tmd->bl.y)) < 9)
+ distance(smd->bl.x, smd->bl.y, tmd->bl.x, tmd->bl.y)) < 9)
{
- if (mob_can_reach (smd, bl, 12) && // 到é”å¯èƒ½æ€§åˆ¤å®š
- MRAND (1000) < 1000 / (++(*pcc)))
- { // 範囲内ã§ç­‰ç¢ºçŽ‡ã«ã™ã‚‹
+ // 到é”å¯èƒ½æ€§åˆ¤å®š
+ if (mob_can_reach(smd, bl, 12)
+ && random_::chance({1, ++*pcc}))
+ {
+ // 範囲内ã§ç­‰ç¢ºçŽ‡ã«ã™ã‚‹
smd->target_id = bl->id;
- smd->state.targettype = ATTACKABLE;
+ smd->state.attackable = true;
smd->min_chase = 13;
}
}
}
- return 0;
}
/*==========================================
* loot monster item search
*------------------------------------------
*/
-static int mob_ai_sub_hard_lootsearch (struct block_list *bl, va_list ap)
+static
+void mob_ai_sub_hard_lootsearch(struct block_list *bl, struct mob_data *md, int *itc)
{
- struct mob_data *md;
- int mode, dist, *itc;
+ MobMode mode;
+ int dist;
- nullpo_retr (0, bl);
- nullpo_retr (0, ap);
- nullpo_retr (0, md = va_arg (ap, struct mob_data *));
- nullpo_retr (0, itc = va_arg (ap, int *));
+ nullpo_retv(bl);
- if (!md->mode)
+ if (md->mode == MobMode::ZERO)
{
mode = mob_db[md->mob_class].mode;
}
@@ -1665,118 +1470,110 @@ static int mob_ai_sub_hard_lootsearch (struct block_list *bl, va_list ap)
mode = md->mode;
}
- if (!md->target_id && mode & 0x02)
+ if (!md->target_id && bool(mode & MobMode::LOOTER))
{
if (!md->lootitem
|| (battle_config.monster_loot_type == 1
&& md->lootitem_count >= LOOTITEM_SIZE))
- return 0;
+ return;
if (bl->m == md->bl.m
- && (dist = distance (md->bl.x, md->bl.y, bl->x, bl->y)) < 9)
+ && (dist = distance(md->bl.x, md->bl.y, bl->x, bl->y)) < 9)
{
- if (mob_can_reach (md, bl, 12) && // Reachability judging
- MRAND (1000) < 1000 / (++(*itc)))
- { // It is made a probability, such as within the limits PC.
+ // Reachability judging
+ if (mob_can_reach(md, bl, 12)
+ && random_::chance({1, ++*itc}))
+ {
+ // It is made a probability, such as within the limits PC.
md->target_id = bl->id;
- md->state.targettype = NONE_ATTACKABLE;
+ md->state.attackable = false;
md->min_chase = 13;
}
}
}
- return 0;
}
/*==========================================
* The ?? routine of a link monster
*------------------------------------------
*/
-static int mob_ai_sub_hard_linksearch (struct block_list *bl, va_list ap)
+static
+void mob_ai_sub_hard_linksearch(struct block_list *bl, struct mob_data *md, struct block_list *target)
{
struct mob_data *tmd;
- struct mob_data *md;
- struct block_list *target;
-
- nullpo_retr (0, bl);
- nullpo_retr (0, ap);
- nullpo_retr (0, tmd = (struct mob_data *) bl);
- nullpo_retr (0, md = va_arg (ap, struct mob_data *));
- nullpo_retr (0, target = va_arg (ap, struct block_list *));
-
- // same family free in a range at a link monster -- it will be made to lock if MOB is
-/* if( (md->target_id > 0 && md->state.targettype == ATTACKABLE) && mob_db[md->mob_class].mode&0x08){
- if( tmd->mob_class==md->mob_class && (!tmd->target_id || md->state.targettype == NONE_ATTACKABLE) && tmd->bl.m == md->bl.m){
- if( mob_can_reach(tmd,target,12) ){ // Reachability judging
- tmd->target_id=md->target_id;
- tmd->state.targettype = ATTACKABLE;
- tmd->min_chase=13;
- }
- }
- }*/
- if (md->attacked_id > 0 && mob_db[md->mob_class].mode & 0x08)
+
+ nullpo_retv(bl);
+ tmd = (struct mob_data *) bl;
+ nullpo_retv(md);
+ nullpo_retv(target);
+
+ if (md->attacked_id > 0
+ && bool(mob_db[md->mob_class].mode & MobMode::ASSIST))
{
- if (tmd->mob_class == md->mob_class && tmd->bl.m == md->bl.m
- && (!tmd->target_id || md->state.targettype == NONE_ATTACKABLE))
+ if (tmd->mob_class == md->mob_class
+ && tmd->bl.m == md->bl.m
+ && (!tmd->target_id || !md->state.attackable))
{
- if (mob_can_reach (tmd, target, 12))
- { // Reachability judging
+ if (mob_can_reach(tmd, target, 12))
+ {
+ // Reachability judging
tmd->target_id = md->attacked_id;
- tmd->state.targettype = ATTACKABLE;
+ tmd->state.attackable = true;
tmd->min_chase = 13;
}
}
}
-
- return 0;
}
/*==========================================
* Processing of slave monsters
*------------------------------------------
*/
-static int mob_ai_sub_hard_slavemob (struct mob_data *md, unsigned int tick)
+static
+int mob_ai_sub_hard_slavemob(struct mob_data *md, tick_t tick)
{
struct mob_data *mmd = NULL;
struct block_list *bl;
- int mode, race, old_dist;
+ MobMode mode;
+ int old_dist;
- nullpo_retr (0, md);
+ nullpo_ret(md);
- if ((bl = map_id2bl (md->master_id)) != NULL)
+ if ((bl = map_id2bl(md->master_id)) != NULL)
mmd = (struct mob_data *) bl;
mode = mob_db[md->mob_class].mode;
// It is not main monster/leader.
- if (!mmd || mmd->bl.type != BL_MOB || mmd->bl.id != md->master_id)
+ if (!mmd || mmd->bl.type != BL::MOB || mmd->bl.id != md->master_id)
return 0;
// Since it is in the map on which the master is not, teleport is carried out and it pursues.
if (mmd->bl.m != md->bl.m)
{
- mob_warp (md, mmd->bl.m, mmd->bl.x, mmd->bl.y, 3);
+ mob_warp(md, mmd->bl.m, mmd->bl.x, mmd->bl.y, BeingRemoveWhy::WARPED);
md->state.master_check = 1;
return 0;
}
// Distance with between slave and master is measured.
old_dist = md->master_dist;
- md->master_dist = distance (md->bl.x, md->bl.y, mmd->bl.x, mmd->bl.y);
+ md->master_dist = distance(md->bl.x, md->bl.y, mmd->bl.x, mmd->bl.y);
// Since the master was in near immediately before, teleport is carried out and it pursues.
if (old_dist < 10 && md->master_dist > 18)
{
- mob_warp (md, -1, mmd->bl.x, mmd->bl.y, 3);
+ mob_warp(md, -1, mmd->bl.x, mmd->bl.y, BeingRemoveWhy::WARPED);
md->state.master_check = 1;
return 0;
}
// Although there is the master, since it is somewhat far, it approaches.
- if ((!md->target_id || md->state.targettype == NONE_ATTACKABLE)
- && mob_can_move (md)
+ if ((!md->target_id || !md->state.attackable)
+ && mob_can_move(md)
&& (md->walkpath.path_pos >= md->walkpath.path_len
|| md->walkpath.path_len == 0) && md->master_dist < 15)
{
- int i = 0, dx, dy, ret;
+ int i = 0, dx, dy, ret;
if (md->master_dist > 4)
{
do
@@ -1786,21 +1583,21 @@ static int mob_ai_sub_hard_slavemob (struct mob_data *md, unsigned int tick)
dx = mmd->bl.x - md->bl.x;
dy = mmd->bl.y - md->bl.y;
if (dx < 0)
- dx += (MPRAND (1, ((dx < -3) ? 3 : -dx)));
+ dx += random_::in(1, std::min(3, -dx));
else if (dx > 0)
- dx -= (MPRAND (1, ((dx > 3) ? 3 : dx)));
+ dx -= random_::in(1, std::min(3, dx));
if (dy < 0)
- dy += (MPRAND (1, ((dy < -3) ? 3 : -dy)));
+ dy += random_::in(1, std::min(3, -dy));
else if (dy > 0)
- dy -= (MPRAND (1, ((dy > 3) ? 3 : dy)));
+ dy -= random_::in(1, std::min(3, dy));
}
else
{
- dx = mmd->bl.x - md->bl.x + MRAND (7) - 3;
- dy = mmd->bl.y - md->bl.y + MRAND (7) - 3;
+ dx = mmd->bl.x - md->bl.x + random_::in(-3, 3);
+ dy = mmd->bl.y - md->bl.y + random_::in(-3, 3);
}
- ret = mob_walktoxy (md, md->bl.x + dx, md->bl.y + dy, 0);
+ ret = mob_walktoxy(md, md->bl.x + dx, md->bl.y + dy, 0);
i++;
}
while (ret && i < 10);
@@ -1809,69 +1606,53 @@ static int mob_ai_sub_hard_slavemob (struct mob_data *md, unsigned int tick)
{
do
{
- dx = MRAND (9) - 5;
- dy = MRAND (9) - 5;
+ // changed to do what it was obviously supposed to do,
+ // instead of what it was doing ...
+ dx = random_::in(-4, 4);
+ dy = random_::in(-4, 4);
if (dx == 0 && dy == 0)
{
- dx = (MRAND (1)) ? 1 : -1;
- dy = (MRAND (1)) ? 1 : -1;
+ dx = random_::coin() ? 1 : -1;
+ dy = random_::coin() ? 1 : -1;
}
dx += mmd->bl.x;
dy += mmd->bl.y;
- ret = mob_walktoxy (md, mmd->bl.x + dx, mmd->bl.y + dy, 0);
+ ret = mob_walktoxy(md, mmd->bl.x + dx, mmd->bl.y + dy, 0);
i++;
}
while (ret && i < 10);
}
- md->next_walktime = tick + 500;
+ md->next_walktime = tick + std::chrono::milliseconds(500);
md->state.master_check = 1;
}
// There is the master, the master locks a target and he does not lock.
- if ((mmd->target_id > 0 && mmd->state.targettype == ATTACKABLE)
- && (!md->target_id || md->state.targettype == NONE_ATTACKABLE))
+ if ((mmd->target_id > 0 && mmd->state.attackable)
+ && (!md->target_id || !md->state.attackable))
{
- struct map_session_data *sd = map_id2sd (mmd->target_id);
- if (sd != NULL && !pc_isdead (sd) && sd->invincible_timer == -1
- && !pc_isinvisible (sd))
+ struct map_session_data *sd = map_id2sd(mmd->target_id);
+ if (sd != NULL && !pc_isdead(sd) && !sd->invincible_timer
+ && !pc_isinvisible(sd))
{
- race = mob_db[md->mob_class].race;
- if (mode & 0x20 ||
- (sd->sc_data[SC_TRICKDEAD].timer == -1 &&
- ((!pc_ishiding (sd) && !sd->state.gangsterparadise)
- || race == 4 || race == 6)))
+ Race race = mob_db[md->mob_class].race;
+ if (bool(mode & MobMode::BOSS)
+ || (!sd->state.gangsterparadise
+ || race == Race::_insect
+ || race == Race::_demon))
{ // 妨害ãŒãªã„ã‹åˆ¤å®š
md->target_id = sd->bl.id;
- md->state.targettype = ATTACKABLE;
+ md->state.attackable = true;
md->min_chase =
- 5 + distance (md->bl.x, md->bl.y, sd->bl.x, sd->bl.y);
+ 5 + distance(md->bl.x, md->bl.y, sd->bl.x, sd->bl.y);
md->state.master_check = 1;
}
}
}
- // There is the master, the master locks a target and he does not lock.
-/* if( (md->target_id>0 && mmd->state.targettype == ATTACKABLE) && (!mmd->target_id || mmd->state.targettype == NONE_ATTACKABLE) ){
- struct map_session_data *sd=map_id2sd(md->target_id);
- if(sd!=NULL && !pc_isdead(sd) && sd->invincible_timer == -1 && !pc_isinvisible(sd)){
-
- race=mob_db[mmd->mob_class].race;
- if(mode&0x20 ||
- (sd->sc_data[SC_TRICKDEAD].timer == -1 &&
- (!(sd->status.option&0x06) || race==4 || race==6)
- ) ){ // It judges whether there is any disturbance.
-
- mmd->target_id=sd->bl.id;
- mmd->state.targettype = ATTACKABLE;
- mmd->min_chase=5+distance(mmd->bl.x,mmd->bl.y,sd->bl.x,sd->bl.y);
- }
- }
- }*/
-
return 0;
}
@@ -1879,14 +1660,15 @@ static int mob_ai_sub_hard_slavemob (struct mob_data *md, unsigned int tick)
* A lock of target is stopped and mob moves to a standby state.
*------------------------------------------
*/
-static int mob_unlocktarget (struct mob_data *md, int tick)
+static
+int mob_unlocktarget(struct mob_data *md, tick_t tick)
{
- nullpo_retr (0, md);
+ nullpo_ret(md);
md->target_id = 0;
- md->state.targettype = NONE_ATTACKABLE;
- md->state.skillstate = MSS_IDLE;
- md->next_walktime = tick + MPRAND (3000, 3000);
+ md->state.attackable = false;
+ md->state.skillstate = MobSkillState::MSS_IDLE;
+ md->next_walktime = tick + std::chrono::seconds(3) + std::chrono::milliseconds(random_::to(3000));
return 0;
}
@@ -1894,26 +1676,26 @@ static int mob_unlocktarget (struct mob_data *md, int tick)
* Random walk
*------------------------------------------
*/
-static int mob_randomwalk (struct mob_data *md, int tick)
+static
+int mob_randomwalk(struct mob_data *md, tick_t tick)
{
const int retrycount = 20;
- int speed;
- nullpo_retr (0, md);
+ nullpo_ret(md);
- speed = battle_get_speed (&md->bl);
- if (DIFF_TICK (md->next_walktime, tick) < 0)
+ interval_t speed = battle_get_speed(&md->bl);
+ if (md->next_walktime < tick)
{
- int i, x, y, c, d = 12 - md->move_fail_count;
+ int i, x, y, d = 12 - md->move_fail_count;
if (d < 5)
d = 5;
for (i = 0; i < retrycount; i++)
- { // Search of a movable place
- int r = mt_random ();
- x = md->bl.x + r % (d * 2 + 1) - d;
- y = md->bl.y + r / (d * 2 + 1) % (d * 2 + 1) - d;
- if ((c = map_getcell (md->bl.m, x, y)) != 1 && c != 5
- && mob_walktoxy (md, x, y, 1) == 0)
+ {
+ // Search of a movable place
+ x = md->bl.x + random_::in(-d, d);
+ y = md->bl.y + random_::in(-d, d);
+ if (!bool(map_getcell(md->bl.m, x, y) & MapCell::UNWALKABLE)
+ && mob_walktoxy(md, x, y, 1) == 0)
{
md->move_fail_count = 0;
break;
@@ -1924,23 +1706,24 @@ static int mob_randomwalk (struct mob_data *md, int tick)
if (md->move_fail_count > 1000)
{
if (battle_config.error_log == 1)
- printf
- ("MOB cant move. random spawn %d, mob_class = %d\n",
+ PRINTF("MOB cant move. random spawn %d, mob_class = %d\n",
md->bl.id, md->mob_class);
md->move_fail_count = 0;
- mob_spawn (md->bl.id);
+ mob_spawn(md->bl.id);
}
}
}
- for (i = c = 0; i < md->walkpath.path_len; i++)
- { // The next walk start time is calculated.
- if (md->walkpath.path[i] & 1)
+ interval_t c = interval_t::zero();
+ for (i = 0; i < md->walkpath.path_len; i++)
+ {
+ // The next walk start time is calculated.
+ if (dir_is_diagonal(md->walkpath.path[i]))
c += speed * 14 / 10;
else
c += speed;
}
- md->next_walktime = tick + MPRAND (3000, 3000) + c;
- md->state.skillstate = MSS_WALK;
+ md->next_walktime = tick + std::chrono::seconds(3) + std::chrono::milliseconds(random_::to(3000)) + c;
+ md->state.skillstate = MobSkillState::MSS_WALK;
return 1;
}
return 0;
@@ -1950,85 +1733,81 @@ static int mob_randomwalk (struct mob_data *md, int tick)
* AI of MOB whose is near a Player
*------------------------------------------
*/
-static int mob_ai_sub_hard (struct block_list *bl, va_list ap)
+static
+void mob_ai_sub_hard(struct block_list *bl, tick_t tick)
{
struct mob_data *md, *tmd = NULL;
struct map_session_data *tsd = NULL;
struct block_list *tbl = NULL;
struct flooritem_data *fitem;
- unsigned int tick;
- int i, dx, dy, ret, dist;
- int attack_type = 0;
- int mode, race;
-
- nullpo_retr (0, bl);
- nullpo_retr (0, ap);
- nullpo_retr (0, md = (struct mob_data *) bl);
+ int i, dx, dy, ret, dist;
+ int attack_type = 0;
+ MobMode mode;
- tick = va_arg (ap, unsigned int);
+ nullpo_retv(bl);
+ md = (struct mob_data *) bl;
- if (DIFF_TICK (tick, md->last_thinktime) < MIN_MOBTHINKTIME)
- return 0;
+ if (tick < md->last_thinktime + MIN_MOBTHINKTIME)
+ return;
md->last_thinktime = tick;
- if (md->skilltimer != -1 || md->bl.prev == NULL)
- { // Under a skill aria and death
- if (DIFF_TICK (tick, md->next_walktime) > MIN_MOBTHINKTIME)
+ if (md->skilltimer || md->bl.prev == NULL)
+ {
+ // Under a skill aria and death
+ if (tick > md->next_walktime + MIN_MOBTHINKTIME)
md->next_walktime = tick;
- return 0;
+ return;
}
- if (!md->mode)
+ if (md->mode == MobMode::ZERO)
mode = mob_db[md->mob_class].mode;
else
mode = md->mode;
- race = mob_db[md->mob_class].race;
+ Race race = mob_db[md->mob_class].race;
// Abnormalities
- if ((md->opt1 > 0 && md->opt1 != 6) || md->state.state == MS_DELAY
- || md->sc_data[SC_BLADESTOP].timer != -1)
- return 0;
+ if (bool(md->opt1) && md->opt1 != Opt1::_stone6)
+ return;
- if (!(mode & 0x80) && md->target_id > 0)
+ if (!bool(mode & MobMode::CAN_ATTACK) && md->target_id > 0)
md->target_id = 0;
- if (md->attacked_id > 0 && mode & 0x08)
+ if (md->attacked_id > 0 && bool(mode & MobMode::ASSIST))
{ // Link monster
- struct map_session_data *asd = map_id2sd (md->attacked_id);
+ struct map_session_data *asd = map_id2sd(md->attacked_id);
if (asd)
{
- if (asd->invincible_timer == -1 && !pc_isinvisible (asd))
+ if (!asd->invincible_timer && !pc_isinvisible(asd))
{
- map_foreachinarea (mob_ai_sub_hard_linksearch, md->bl.m,
- md->bl.x - 13, md->bl.y - 13,
- md->bl.x + 13, md->bl.y + 13,
- BL_MOB, md, &asd->bl);
+ map_foreachinarea(std::bind(mob_ai_sub_hard_linksearch, ph::_1, md, &asd->bl),
+ md->bl.m, md->bl.x - 13, md->bl.y - 13,
+ md->bl.x + 13, md->bl.y + 13, BL::MOB);
}
}
}
// It checks to see it was attacked first (if active, it is target change at 25% of probability).
- if (mode > 0 && md->attacked_id > 0
- && (!md->target_id || md->state.targettype == NONE_ATTACKABLE
- || (mode & 0x04 && MRAND (100) < 25)))
+ if (mode != MobMode::ZERO && md->attacked_id > 0
+ && (!md->target_id || !md->state.attackable
+ || (bool(mode & MobMode::AGGRESSIVE) && random_::chance({25, 100}))))
{
- struct block_list *abl = map_id2bl (md->attacked_id);
+ struct block_list *abl = map_id2bl(md->attacked_id);
struct map_session_data *asd = NULL;
if (abl)
{
- if (abl->type == BL_PC)
+ if (abl->type == BL::PC)
asd = (struct map_session_data *) abl;
if (asd == NULL || md->bl.m != abl->m || abl->prev == NULL
- || asd->invincible_timer != -1 || pc_isinvisible (asd)
+ || asd->invincible_timer || pc_isinvisible(asd)
|| (dist =
- distance (md->bl.x, md->bl.y, abl->x, abl->y)) >= 32
- || battle_check_target (bl, abl, BCT_ENEMY) == 0)
+ distance(md->bl.x, md->bl.y, abl->x, abl->y)) >= 32
+ || battle_check_target(bl, abl, BCT_ENEMY) == 0)
md->attacked_id = 0;
else
{
md->target_id = md->attacked_id; // set target
- md->state.targettype = ATTACKABLE;
+ md->state.attackable = true;
attack_type = 1;
md->attacked_id = 0;
md->min_chase = dist + 13;
@@ -2041,96 +1820,89 @@ static int mob_ai_sub_hard (struct block_list *bl, va_list ap)
md->state.master_check = 0;
// Processing of slave monster
if (md->master_id > 0 && md->state.special_mob_ai == 0)
- mob_ai_sub_hard_slavemob (md, tick);
+ mob_ai_sub_hard_slavemob(md, tick);
// アクティヴモンスターã®ç­–敵 (?? of a bitter taste TIVU monster)
- if ((!md->target_id || md->state.targettype == NONE_ATTACKABLE)
- && mode & 0x04 && !md->state.master_check
+ if ((!md->target_id || !md->state.attackable)
+ && bool(mode & MobMode::AGGRESSIVE) && !md->state.master_check
&& battle_config.monster_active_enable == 1)
{
i = 0;
if (md->state.special_mob_ai)
{
- map_foreachinarea (mob_ai_sub_hard_activesearch, md->bl.m,
- md->bl.x - AREA_SIZE * 2,
- md->bl.y - AREA_SIZE * 2,
- md->bl.x + AREA_SIZE * 2,
- md->bl.y + AREA_SIZE * 2, 0, md, &i);
+ map_foreachinarea(std::bind(mob_ai_sub_hard_activesearch, ph::_1, md, &i),
+ md->bl.m, md->bl.x - AREA_SIZE * 2, md->bl.y - AREA_SIZE * 2,
+ md->bl.x + AREA_SIZE * 2, md->bl.y + AREA_SIZE * 2,
+ BL::NUL);
}
else
{
- map_foreachinarea (mob_ai_sub_hard_activesearch, md->bl.m,
- md->bl.x - AREA_SIZE * 2,
- md->bl.y - AREA_SIZE * 2,
- md->bl.x + AREA_SIZE * 2,
- md->bl.y + AREA_SIZE * 2, BL_PC, md, &i);
+ map_foreachinarea(std::bind(mob_ai_sub_hard_activesearch, ph::_1, md, &i),
+ md->bl.m, md->bl.x - AREA_SIZE * 2, md->bl.y - AREA_SIZE * 2,
+ md->bl.x + AREA_SIZE * 2, md->bl.y + AREA_SIZE * 2, BL::PC);
}
}
// The item search of a route monster
- if (!md->target_id && mode & 0x02 && !md->state.master_check)
+ if (!md->target_id
+ && bool(mode & MobMode::LOOTER)
+ && !md->state.master_check)
{
i = 0;
- map_foreachinarea (mob_ai_sub_hard_lootsearch, md->bl.m,
- md->bl.x - AREA_SIZE * 2, md->bl.y - AREA_SIZE * 2,
- md->bl.x + AREA_SIZE * 2, md->bl.y + AREA_SIZE * 2,
- BL_ITEM, md, &i);
+ map_foreachinarea(std::bind(mob_ai_sub_hard_lootsearch, ph::_1, md, &i),
+ md->bl.m, md->bl.x - AREA_SIZE * 2, md->bl.y - AREA_SIZE * 2,
+ md->bl.x + AREA_SIZE * 2, md->bl.y + AREA_SIZE * 2, BL::ITEM);
}
// It will attack, if the candidate for an attack is.
if (md->target_id > 0)
{
- if ((tbl = map_id2bl (md->target_id)))
+ if ((tbl = map_id2bl(md->target_id)))
{
- if (tbl->type == BL_PC)
+ if (tbl->type == BL::PC)
tsd = (struct map_session_data *) tbl;
- else if (tbl->type == BL_MOB)
+ else if (tbl->type == BL::MOB)
tmd = (struct mob_data *) tbl;
if (tsd || tmd)
{
if (tbl->m != md->bl.m || tbl->prev == NULL
|| (dist =
- distance (md->bl.x, md->bl.y, tbl->x,
+ distance(md->bl.x, md->bl.y, tbl->x,
tbl->y)) >= md->min_chase)
- mob_unlocktarget (md, tick); // 別マップã‹ã€è¦–界外
- else if (tsd && !(mode & 0x20)
- && (tsd->sc_data[SC_TRICKDEAD].timer != -1
- ||
- ((pc_ishiding (tsd)
- || tsd->state.gangsterparadise) && race != 4
- && race != 6)))
- mob_unlocktarget (md, tick); // スキルãªã©ã«ã‚ˆã‚‹ç­–敵妨害
- else if (!battle_check_range
- (&md->bl, tbl, mob_db[md->mob_class].range))
+ mob_unlocktarget(md, tick); // 別マップã‹ã€è¦–界外
+ else if (tsd && !bool(mode & MobMode::BOSS)
+ && (tsd->state.gangsterparadise
+ && race != Race::_insect
+ && race != Race::_demon))
+ mob_unlocktarget(md, tick); // スキルãªã©ã«ã‚ˆã‚‹ç­–敵妨害
+ else if (!battle_check_range(&md->bl, tbl, mob_db[md->mob_class].range))
{
// 攻撃範囲外ãªã®ã§ç§»å‹•
- if (!(mode & 1))
+ if (!bool(mode & MobMode::CAN_MOVE))
{ // 移動ã—ãªã„モード
- mob_unlocktarget (md, tick);
- return 0;
+ mob_unlocktarget(md, tick);
+ return;
}
- if (!mob_can_move (md)) // å‹•ã‘ãªã„状態ã«ã‚ã‚‹
- return 0;
- md->state.skillstate = MSS_CHASE; // çªæ’ƒæ™‚スキル
- mobskill_use (md, tick, -1);
-// if(md->timer != -1 && (DIFF_TICK(md->next_walktime,tick)<0 || distance(md->to_x,md->to_y,tsd->bl.x,tsd->bl.y)<2) )
- if (md->timer != -1 && md->state.state != MS_ATTACK
- && (DIFF_TICK (md->next_walktime, tick) < 0
- || distance (md->to_x, md->to_y, tbl->x,
- tbl->y) < 2))
- return 0; // æ—¢ã«ç§»å‹•ä¸­
- if (!mob_can_reach
- (md, tbl, (md->min_chase > 13) ? md->min_chase : 13))
- mob_unlocktarget (md, tick); // 移動ã§ããªã„ã®ã§ã‚¿ã‚²è§£é™¤ï¼ˆIWã¨ã‹ï¼Ÿï¼‰
+ if (!mob_can_move(md)) // å‹•ã‘ãªã„状態ã«ã‚ã‚‹
+ return;
+ md->state.skillstate = MobSkillState::MSS_CHASE; // çªæ’ƒæ™‚スキル
+ mobskill_use(md, tick, MobSkillCondition::ANY);
+ if (md->timer && md->state.state != MS::ATTACK
+ && (md->next_walktime < tick
+ || distance(md->to_x, md->to_y, tbl->x, tbl->y) < 2))
+ return; // æ—¢ã«ç§»å‹•ä¸­
+ if (!mob_can_reach(md, tbl, (md->min_chase > 13) ? md->min_chase : 13))
+ mob_unlocktarget(md, tick); // 移動ã§ããªã„ã®ã§ã‚¿ã‚²è§£é™¤ï¼ˆIWã¨ã‹ï¼Ÿï¼‰
else
{
// 追跡
- md->next_walktime = tick + 500;
+ md->next_walktime = tick + std::chrono::milliseconds(500);
i = 0;
do
{
if (i == 0)
- { // 最åˆã¯AEGISã¨åŒã˜æ–¹æ³•ã§æ¤œç´¢
+ {
+ // 最åˆã¯AEGISã¨åŒã˜æ–¹æ³•ã§æ¤œç´¢
dx = tbl->x - md->bl.x;
dy = tbl->y - md->bl.y;
if (dx < 0)
@@ -2143,21 +1915,13 @@ static int mob_ai_sub_hard (struct block_list *bl, va_list ap)
dy--;
}
else
- { // ã ã‚ãªã‚‰Athenaå¼(ランダム)
- dx = tbl->x - md->bl.x + MRAND (3) - 1;
- dy = tbl->y - md->bl.y + MRAND (3) - 1;
+ {
+ // ã ã‚ãªã‚‰Athenaå¼(ランダム)
+ // {0 1 2}
+ dx = tbl->x - md->bl.x + random_::in(-1, 1);
+ dy = tbl->y - md->bl.y + random_::in(-1, 1);
}
- /* if(path_search(&md->walkpath,md->bl.m,md->bl.x,md->bl.y,md->bl.x+dx,md->bl.y+dy,0)){
- * dx=tsd->bl.x - md->bl.x;
- * dy=tsd->bl.y - md->bl.y;
- * if(dx<0) dx--;
- * else if(dx>0) dx++;
- * if(dy<0) dy--;
- * else if(dy>0) dy++;
- * } */
- ret =
- mob_walktoxy (md, md->bl.x + dx,
- md->bl.y + dy, 0);
+ ret = mob_walktoxy(md, md->bl.x + dx, md->bl.y + dy, 0);
i++;
}
while (ret && i < 5);
@@ -2172,200 +1936,178 @@ static int mob_ai_sub_hard (struct block_list *bl, va_list ap)
dy = 2;
else if (dy > 0)
dy = -2;
- mob_walktoxy (md, md->bl.x + dx, md->bl.y + dy,
+ mob_walktoxy(md, md->bl.x + dx, md->bl.y + dy,
0);
}
}
}
else
{ // 攻撃射程範囲内
- md->state.skillstate = MSS_ATTACK;
- if (md->state.state == MS_WALK)
- mob_stop_walking (md, 1); // 歩行中ãªã‚‰åœæ­¢
- if (md->state.state == MS_ATTACK)
- return 0; // æ—¢ã«æ”»æ’ƒä¸­
- mob_changestate (md, MS_ATTACK, attack_type);
-
-/* if(mode&0x08){ // リンクモンスター
- map_foreachinarea(mob_ai_sub_hard_linksearch,md->bl.m,
- md->bl.x-13,md->bl.y-13,
- md->bl.x+13,md->bl.y+13,
- BL_MOB,md,&tsd->bl);
- }*/
+ md->state.skillstate = MobSkillState::MSS_ATTACK;
+ if (md->state.state == MS::WALK)
+ mob_stop_walking(md, 1); // 歩行中ãªã‚‰åœæ­¢
+ if (md->state.state == MS::ATTACK)
+ return; // æ—¢ã«æ”»æ’ƒä¸­
+ mob_changestate(md, MS::ATTACK, attack_type);
}
- return 0;
+ return;
}
else
{ // ルートモンスター処ç†
- if (tbl == NULL || tbl->type != BL_ITEM || tbl->m != md->bl.m
+ if (tbl == NULL || tbl->type != BL::ITEM || tbl->m != md->bl.m
|| (dist =
- distance (md->bl.x, md->bl.y, tbl->x,
+ distance(md->bl.x, md->bl.y, tbl->x,
tbl->y)) >= md->min_chase || !md->lootitem)
{
// é ã™ãŽã‚‹ã‹ã‚¢ã‚¤ãƒ†ãƒ ãŒãªããªã£ãŸ
- mob_unlocktarget (md, tick);
- if (md->state.state == MS_WALK)
- mob_stop_walking (md, 1); // 歩行中ãªã‚‰åœæ­¢
+ mob_unlocktarget(md, tick);
+ if (md->state.state == MS::WALK)
+ mob_stop_walking(md, 1); // 歩行中ãªã‚‰åœæ­¢
}
else if (dist)
{
- if (!(mode & 1))
+ if (!bool(mode & MobMode::CAN_MOVE))
{ // 移動ã—ãªã„モード
- mob_unlocktarget (md, tick);
- return 0;
+ mob_unlocktarget(md, tick);
+ return;
}
- if (!mob_can_move (md)) // å‹•ã‘ãªã„状態ã«ã‚ã‚‹
- return 0;
- md->state.skillstate = MSS_LOOT; // ルート時スキル使用
- mobskill_use (md, tick, -1);
-// if(md->timer != -1 && (DIFF_TICK(md->next_walktime,tick)<0 || distance(md->to_x,md->to_y,tbl->x,tbl->y)<2) )
- if (md->timer != -1 && md->state.state != MS_ATTACK
- && (DIFF_TICK (md->next_walktime, tick) < 0
- || distance (md->to_x, md->to_y, tbl->x,
- tbl->y) <= 0))
- return 0; // æ—¢ã«ç§»å‹•ä¸­
- md->next_walktime = tick + 500;
+ if (!mob_can_move(md)) // å‹•ã‘ãªã„状態ã«ã‚ã‚‹
+ return;
+ md->state.skillstate = MobSkillState::MSS_LOOT; // ルート時スキル使用
+ mobskill_use(md, tick, MobSkillCondition::ANY);
+ if (md->timer && md->state.state != MS::ATTACK
+ && (md->next_walktime < tick
+ || distance(md->to_x, md->to_y, tbl->x, tbl->y) <= 0))
+ return; // æ—¢ã«ç§»å‹•ä¸­
+ md->next_walktime = tick + std::chrono::milliseconds(500);
dx = tbl->x - md->bl.x;
dy = tbl->y - md->bl.y;
-/* if(path_search(&md->walkpath,md->bl.m,md->bl.x,md->bl.y,md->bl.x+dx,md->bl.y+dy,0)){
- dx=tbl->x - md->bl.x;
- dy=tbl->y - md->bl.y;
- }*/
- ret = mob_walktoxy (md, md->bl.x + dx, md->bl.y + dy, 0);
+ ret = mob_walktoxy(md, md->bl.x + dx, md->bl.y + dy, 0);
if (ret)
- mob_unlocktarget (md, tick); // 移動ã§ããªã„ã®ã§ã‚¿ã‚²è§£é™¤ï¼ˆIWã¨ã‹ï¼Ÿï¼‰
+ mob_unlocktarget(md, tick); // 移動ã§ããªã„ã®ã§ã‚¿ã‚²è§£é™¤ï¼ˆIWã¨ã‹ï¼Ÿï¼‰
}
else
{ // アイテムã¾ã§ãŸã©ã‚Šç€ã„ãŸ
- if (md->state.state == MS_ATTACK)
- return 0; // 攻撃中
- if (md->state.state == MS_WALK)
- mob_stop_walking (md, 1); // 歩行中ãªã‚‰åœæ­¢
+ if (md->state.state == MS::ATTACK)
+ return; // 攻撃中
+ if (md->state.state == MS::WALK)
+ mob_stop_walking(md, 1); // 歩行中ãªã‚‰åœæ­¢
fitem = (struct flooritem_data *) tbl;
if (md->lootitem_count < LOOTITEM_SIZE)
- memcpy (&md->lootitem[md->lootitem_count++],
- &fitem->item_data, sizeof (md->lootitem[0]));
+ memcpy(&md->lootitem[md->lootitem_count++],
+ &fitem->item_data, sizeof(md->lootitem[0]));
else if (battle_config.monster_loot_type == 1
&& md->lootitem_count >= LOOTITEM_SIZE)
{
- mob_unlocktarget (md, tick);
- return 0;
+ mob_unlocktarget(md, tick);
+ return;
}
else
{
for (i = 0; i < LOOTITEM_SIZE - 1; i++)
- memcpy (&md->lootitem[i], &md->lootitem[i + 1],
- sizeof (md->lootitem[0]));
- memcpy (&md->lootitem[LOOTITEM_SIZE - 1],
- &fitem->item_data, sizeof (md->lootitem[0]));
+ memcpy(&md->lootitem[i], &md->lootitem[i + 1],
+ sizeof(md->lootitem[0]));
+ memcpy(&md->lootitem[LOOTITEM_SIZE - 1],
+ &fitem->item_data, sizeof(md->lootitem[0]));
}
- map_clearflooritem (tbl->id);
- mob_unlocktarget (md, tick);
+ map_clearflooritem(tbl->id);
+ mob_unlocktarget(md, tick);
}
- return 0;
+ return;
}
}
else
{
- mob_unlocktarget (md, tick);
- if (md->state.state == MS_WALK)
- mob_stop_walking (md, 4); // 歩行中ãªã‚‰åœæ­¢
- return 0;
+ mob_unlocktarget(md, tick);
+ if (md->state.state == MS::WALK)
+ mob_stop_walking(md, 4); // 歩行中ãªã‚‰åœæ­¢
+ return;
}
}
// It is skill use at the time of /standby at the time of a walk.
- if (mobskill_use (md, tick, -1))
- return 0;
-
- // 歩行処ç†
- if (mode & 1 && mob_can_move (md) && // 移動å¯èƒ½MOB&å‹•ã‘る状態ã«ã‚ã‚‹
- (md->master_id == 0 || md->state.special_mob_ai
- || md->master_dist > 10))
- { //å–ã‚Šå·»ãMOBã˜ã‚ƒãªã„
+ if (mobskill_use(md, tick, MobSkillCondition::ANY))
+ return;
- if (DIFF_TICK (md->next_walktime, tick) > +7000 &&
- (md->walkpath.path_len == 0
- || md->walkpath.path_pos >= md->walkpath.path_len))
+ // mobs that are not slaves can random-walk
+ if (bool(mode & MobMode::CAN_MOVE)
+ && mob_can_move(md)
+ && (md->master_id == 0 || md->state.special_mob_ai
+ || md->master_dist > 10))
+ {
+ // if walktime is more than 7 seconds in the future,
+ // set it to somewhere between 3 and 5 seconds
+ if (md->next_walktime > tick + std::chrono::seconds(7)
+ && (md->walkpath.path_len == 0
+ || md->walkpath.path_pos >= md->walkpath.path_len))
{
- md->next_walktime = tick + 3000 * MRAND (2000);
+ md->next_walktime = tick + std::chrono::seconds(3)
+ + std::chrono::milliseconds(random_::to(2000));
}
// Random movement
- if (mob_randomwalk (md, tick))
- return 0;
+ if (mob_randomwalk(md, tick))
+ return;
}
// Since he has finished walking, it stands by.
if (md->walkpath.path_len == 0
|| md->walkpath.path_pos >= md->walkpath.path_len)
- md->state.skillstate = MSS_IDLE;
- return 0;
+ md->state.skillstate = MobSkillState::MSS_IDLE;
}
/*==========================================
* Serious processing for mob in PC field of view (foreachclient)
*------------------------------------------
*/
-static int mob_ai_sub_foreachclient (struct map_session_data *sd, va_list ap)
+static
+void mob_ai_sub_foreachclient(struct map_session_data *sd, tick_t tick)
{
- unsigned int tick;
- nullpo_retr (0, sd);
- nullpo_retr (0, ap);
+ nullpo_retv(sd);
- tick = va_arg (ap, unsigned int);
- map_foreachinarea (mob_ai_sub_hard, sd->bl.m,
- sd->bl.x - AREA_SIZE * 2, sd->bl.y - AREA_SIZE * 2,
- sd->bl.x + AREA_SIZE * 2, sd->bl.y + AREA_SIZE * 2,
- BL_MOB, tick);
-
- return 0;
+ map_foreachinarea(std::bind(mob_ai_sub_hard, ph::_1, tick),
+ sd->bl.m, sd->bl.x - AREA_SIZE * 2, sd->bl.y - AREA_SIZE * 2,
+ sd->bl.x + AREA_SIZE * 2, sd->bl.y + AREA_SIZE * 2, BL::MOB);
}
/*==========================================
* Serious processing for mob in PC field of view (interval timer function)
*------------------------------------------
*/
-static void mob_ai_hard (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data)
+static
+void mob_ai_hard(TimerData *, tick_t tick)
{
- clif_foreachclient (mob_ai_sub_foreachclient, tick);
+ clif_foreachclient(std::bind(mob_ai_sub_foreachclient, ph::_1, tick));
}
/*==========================================
* Negligent mode MOB AI (PC is not in near)
*------------------------------------------
*/
-static void mob_ai_sub_lazy (db_key_t key, db_val_t data, va_list app)
+static
+void mob_ai_sub_lazy(struct block_list *bl, tick_t tick)
{
- struct mob_data *md = (struct mob_data *)data;
- unsigned int tick;
- va_list ap;
-
- nullpo_retv (md);
- nullpo_retv (app);
- nullpo_retv (ap = va_arg (app, va_list));
+ nullpo_retv(bl);
- if (md == NULL)
+ if (bl->type != BL::MOB)
return;
- if (!md->bl.type || md->bl.type != BL_MOB)
- return;
+ struct mob_data *md = (struct mob_data *)bl;
- tick = va_arg (ap, unsigned int);
-
- if (DIFF_TICK (tick, md->last_thinktime) < MIN_MOBTHINKTIME * 10)
+ if (tick < md->last_thinktime + MIN_MOBTHINKTIME * 10)
return;
md->last_thinktime = tick;
- if (md->bl.prev == NULL || md->skilltimer != -1)
+ if (md->bl.prev == NULL || md->skilltimer)
{
- if (DIFF_TICK (tick, md->next_walktime) > MIN_MOBTHINKTIME * 10)
+ if (tick > md->next_walktime + MIN_MOBTHINKTIME * 10)
md->next_walktime = tick;
return;
}
- if (DIFF_TICK (md->next_walktime, tick) < 0 &&
- (mob_db[md->mob_class].mode & 1) && mob_can_move (md))
+ if (md->next_walktime < tick
+ && bool(mob_db[md->mob_class].mode & MobMode::CAN_MOVE)
+ && mob_can_move(md))
{
if (map[md->bl.m].users > 0)
@@ -2373,14 +2115,15 @@ static void mob_ai_sub_lazy (db_key_t key, db_val_t data, va_list app)
// Since PC is in the same map, somewhat better negligent processing is carried out.
// It sometimes moves.
- if (MRAND (1000) < MOB_LAZYMOVEPERC)
- mob_randomwalk (md, tick);
+ if (random_::chance(MOB_LAZYMOVEPERC))
+ mob_randomwalk(md, tick);
// MOB which is not not the summons MOB but BOSS, either sometimes reboils.
- else if (MRAND (1000) < MOB_LAZYWARPPERC && md->x0 <= 0
- && md->master_id != 0 && mob_db[md->mob_class].mexp <= 0
- && !(mob_db[md->mob_class].mode & 0x20))
- mob_spawn (md->bl.id);
+ else if (random_::chance(MOB_LAZYWARPPERC)
+ && md->x0 <= 0
+ && md->master_id != 0
+ && !bool(mob_db[md->mob_class].mode & MobMode::BOSS))
+ mob_spawn(md->bl.id);
}
else
@@ -2388,13 +2131,14 @@ static void mob_ai_sub_lazy (db_key_t key, db_val_t data, va_list app)
// Since PC is not even in the same map, suitable processing is carried out even if it takes.
// MOB which is not BOSS which is not Summons MOB, either -- a case -- sometimes -- leaping
- if (MRAND (1000) < MOB_LAZYWARPPERC && md->x0 <= 0
- && md->master_id != 0 && mob_db[md->mob_class].mexp <= 0
- && !(mob_db[md->mob_class].mode & 0x20))
- mob_warp (md, -1, -1, -1, -1);
+ if (random_::chance(MOB_LAZYWARPPERC)
+ && md->x0 <= 0
+ && md->master_id != 0
+ && !bool(mob_db[md->mob_class].mode & MobMode::BOSS))
+ mob_warp(md, -1, -1, -1, BeingRemoveWhy::NEGATIVE1);
}
- md->next_walktime = tick + MPRAND (5000, 10000);
+ md->next_walktime = tick + std::chrono::seconds(5) + std::chrono::milliseconds(random_::to(10 * 1000));
}
}
@@ -2402,9 +2146,11 @@ static void mob_ai_sub_lazy (db_key_t key, db_val_t data, va_list app)
* Negligent processing for mob outside PC field of view (interval timer function)
*------------------------------------------
*/
-static void mob_ai_lazy (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data)
+static
+void mob_ai_lazy(TimerData *, tick_t tick)
{
- map_foreachiddb (mob_ai_sub_lazy, tick);
+ for (auto& pair : id_db)
+ mob_ai_sub_lazy(pair.second, tick);
}
/*==========================================
@@ -2415,14 +2161,14 @@ static void mob_ai_lazy (timer_id tid, tick_t tick, custom_id_t id, custom_data_
*/
struct delay_item_drop
{
- int m, x, y;
- int nameid, amount;
+ int m, x, y;
+ int nameid, amount;
struct map_session_data *first_sd, *second_sd, *third_sd;
};
struct delay_item_drop2
{
- int m, x, y;
+ int m, x, y;
struct item item_data;
struct map_session_data *first_sd, *second_sd, *third_sd;
};
@@ -2431,116 +2177,117 @@ struct delay_item_drop2
* item drop with delay (timer function)
*------------------------------------------
*/
-static void mob_delay_item_drop (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data)
+static
+void mob_delay_item_drop(TimerData *, tick_t, struct delay_item_drop *ditem)
{
- struct delay_item_drop *ditem;
struct item temp_item;
- int flag;
+ PickupFail flag;
- nullpo_retv (ditem = (struct delay_item_drop *) id);
+ nullpo_retv(ditem);
- memset (&temp_item, 0, sizeof (temp_item));
+ memset(&temp_item, 0, sizeof(temp_item));
temp_item.nameid = ditem->nameid;
temp_item.amount = ditem->amount;
- temp_item.identify = !itemdb_isequip3 (temp_item.nameid);
+ temp_item.identify = !itemdb_isequip3(temp_item.nameid);
if (battle_config.item_auto_get == 1)
{
if (ditem->first_sd
&& (flag =
- pc_additem (ditem->first_sd, &temp_item, ditem->amount)))
+ pc_additem(ditem->first_sd, &temp_item, ditem->amount))
+ != PickupFail::OKAY)
{
- clif_additem (ditem->first_sd, 0, 0, flag);
- map_addflooritem (&temp_item, 1, ditem->m, ditem->x, ditem->y,
- ditem->first_sd, ditem->second_sd,
- ditem->third_sd, 0);
+ clif_additem(ditem->first_sd, 0, 0, flag);
+ map_addflooritem(&temp_item, 1,
+ ditem->m, ditem->x, ditem->y,
+ ditem->first_sd, ditem->second_sd, ditem->third_sd);
}
- free (ditem);
+ free(ditem);
return;
}
- map_addflooritem (&temp_item, 1, ditem->m, ditem->x, ditem->y,
- ditem->first_sd, ditem->second_sd, ditem->third_sd, 0);
+ map_addflooritem(&temp_item, 1,
+ ditem->m, ditem->x, ditem->y,
+ ditem->first_sd, ditem->second_sd, ditem->third_sd);
- free (ditem);
+ free(ditem);
}
/*==========================================
* item drop (timer function)-lootitem with delay
*------------------------------------------
*/
-static void mob_delay_item_drop2 (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data)
+static
+void mob_delay_item_drop2(TimerData *, tick_t, struct delay_item_drop2 *ditem)
{
- struct delay_item_drop2 *ditem;
- int flag;
+ PickupFail flag;
- nullpo_retv (ditem = (struct delay_item_drop2 *) id);
+ nullpo_retv(ditem);
if (battle_config.item_auto_get == 1)
{
if (ditem->first_sd
&& (flag =
- pc_additem (ditem->first_sd, &ditem->item_data,
- ditem->item_data.amount)))
+ pc_additem(ditem->first_sd, &ditem->item_data,
+ ditem->item_data.amount))
+ != PickupFail::OKAY)
{
- clif_additem (ditem->first_sd, 0, 0, flag);
- map_addflooritem (&ditem->item_data, ditem->item_data.amount,
- ditem->m, ditem->x, ditem->y, ditem->first_sd,
- ditem->second_sd, ditem->third_sd, 0);
+ clif_additem(ditem->first_sd, 0, 0, flag);
+ map_addflooritem(&ditem->item_data, ditem->item_data.amount,
+ ditem->m, ditem->x, ditem->y,
+ ditem->first_sd, ditem->second_sd, ditem->third_sd);
}
- free (ditem);
+ free(ditem);
return;
}
- map_addflooritem (&ditem->item_data, ditem->item_data.amount, ditem->m,
- ditem->x, ditem->y, ditem->first_sd, ditem->second_sd,
- ditem->third_sd, 0);
+ map_addflooritem(&ditem->item_data, ditem->item_data.amount,
+ ditem->m, ditem->x, ditem->y,
+ ditem->first_sd, ditem->second_sd, ditem->third_sd);
- free (ditem);
+ free(ditem);
}
/*==========================================
* mob data is erased.
*------------------------------------------
*/
-int mob_delete (struct mob_data *md)
+int mob_delete(struct mob_data *md)
{
- nullpo_retr (1, md);
+ nullpo_retr(1, md);
if (md->bl.prev == NULL)
return 1;
- mob_changestate (md, MS_DEAD, 0);
- clif_clearchar_area (&md->bl, 1);
- map_delblock (&md->bl);
- if (mob_get_viewclass (md->mob_class) <= 1000)
- clif_clearchar_delay (gettick () + 3000, &md->bl, 0);
- mob_deleteslave (md);
- mob_setdelayspawn (md->bl.id);
+ mob_changestate(md, MS::DEAD, 0);
+ clif_clearchar(&md->bl, BeingRemoveWhy::DEAD);
+ map_delblock(&md->bl);
+ mob_deleteslave(md);
+ mob_setdelayspawn(md->bl.id);
return 0;
}
-int mob_catch_delete (struct mob_data *md, int type)
+int mob_catch_delete(struct mob_data *md, BeingRemoveWhy type)
{
- nullpo_retr (1, md);
+ nullpo_retr(1, md);
if (md->bl.prev == NULL)
return 1;
- mob_changestate (md, MS_DEAD, 0);
- clif_clearchar_area (&md->bl, type);
- map_delblock (&md->bl);
- mob_setdelayspawn (md->bl.id);
+ mob_changestate(md, MS::DEAD, 0);
+ clif_clearchar(&md->bl, type);
+ map_delblock(&md->bl);
+ mob_setdelayspawn(md->bl.id);
return 0;
}
-void mob_timer_delete (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data)
+void mob_timer_delete(TimerData *, tick_t, int id)
{
- struct block_list *bl = map_id2bl (id);
+ struct block_list *bl = map_id2bl(id);
struct mob_data *md;
- nullpo_retv (bl);
+ nullpo_retv(bl);
md = (struct mob_data *) bl;
- mob_catch_delete (md, 3);
+ mob_catch_delete(md, BeingRemoveWhy::WARPED);
}
/*==========================================
@@ -2548,37 +2295,36 @@ void mob_timer_delete (timer_id tid, tick_t tick, custom_id_t id, custom_data_t
*------------------------------------------
*/
static
-int mob_deleteslave_sub (struct block_list *bl, va_list ap)
+void mob_deleteslave_sub(struct block_list *bl, int id)
{
struct mob_data *md;
- int id;
- nullpo_retr (0, bl);
- nullpo_retr (0, ap);
- nullpo_retr (0, md = (struct mob_data *) bl);
+ nullpo_retv(bl);
+ md = (struct mob_data *) bl;
- id = va_arg (ap, int);
if (md->master_id > 0 && md->master_id == id)
- mob_damage (NULL, md, md->hp, 1);
- return 0;
+ mob_damage(NULL, md, md->hp, 1);
}
/*==========================================
*
*------------------------------------------
*/
-int mob_deleteslave (struct mob_data *md)
+int mob_deleteslave(struct mob_data *md)
{
- nullpo_retr (0, md);
+ nullpo_ret(md);
- map_foreachinarea (mob_deleteslave_sub, md->bl.m,
- 0, 0, map[md->bl.m].xs, map[md->bl.m].ys,
- BL_MOB, md->bl.id);
+ map_foreachinarea(std::bind(mob_deleteslave_sub, ph::_1, md->bl.id),
+ md->bl.m, 0, 0,
+ map[md->bl.m].xs, map[md->bl.m].ys, BL::MOB);
return 0;
}
-#define DAMAGE_BONUS_COUNT 6 // max. number of players to account for
-const static double damage_bonus_factor[DAMAGE_BONUS_COUNT + 1] = {
+// max. number of players to account for
+constexpr int DAMAGE_BONUS_COUNT = 6;
+const static
+double damage_bonus_factor[DAMAGE_BONUS_COUNT + 1] =
+{
1.0, 1.0, 2.0, 2.5, 2.75, 2.9, 3.0
};
@@ -2586,7 +2332,7 @@ const static double damage_bonus_factor[DAMAGE_BONUS_COUNT + 1] = {
* It is the damage of sd to damage to md.
*------------------------------------------
*/
-int mob_damage (struct block_list *src, struct mob_data *md, int damage,
+int mob_damage(struct block_list *src, struct mob_data *md, int damage,
int type)
{
int count, minpos, mindmg;
@@ -2594,64 +2340,62 @@ int mob_damage (struct block_list *src, struct mob_data *md, int damage,
struct
{
struct party *p;
- int id, base_exp, job_exp;
+ int id, base_exp, job_exp;
} pt[DAMAGELOG_SIZE];
- int pnum = 0;
- int mvp_damage, max_hp;
- unsigned int tick = gettick ();
+ int pnum = 0;
+ int mvp_damage, max_hp;
+ tick_t tick = gettick();
struct map_session_data *mvp_sd = NULL, *second_sd = NULL, *third_sd =
NULL;
- double dmg_rate, tdmg, temp;
- struct item item;
- int ret;
- int skill, sp;
+ double tdmg;
- nullpo_retr (0, md); //srcã¯NULLã§å‘¼ã°ã‚Œã‚‹å ´åˆã‚‚ã‚ã‚‹ã®ã§ã€ä»–ã§ãƒã‚§ãƒƒã‚¯
+ nullpo_ret(md); //srcã¯NULLã§å‘¼ã°ã‚Œã‚‹å ´åˆã‚‚ã‚ã‚‹ã®ã§ã€ä»–ã§ãƒã‚§ãƒƒã‚¯
if (src && src->id == md->master_id
- && md->mode & MOB_MODE_TURNS_AGAINST_BAD_MASTER)
+ && bool(md->mode & MobMode::TURNS_AGAINST_BAD_MASTER))
{
/* If the master hits a monster, have the monster turn against him */
md->master_id = 0;
- md->mode = 0x85; /* Regular war mode */
+ md->mode = MobMode::war; /* Regular war mode */
md->target_id = src->id;
md->attacked_id = src->id;
}
- max_hp = battle_get_max_hp (&md->bl);
+ max_hp = battle_get_max_hp(&md->bl);
- if (src && src->type == BL_PC)
+ if (src && src->type == BL::PC)
{
sd = (struct map_session_data *) src;
mvp_sd = sd;
}
// if(battle_config.battle_log)
-// printf("mob_damage %d %d %d\n",md->hp,max_hp,damage);
+// PRINTF("mob_damage %d %d %d\n",md->hp,max_hp,damage);
if (md->bl.prev == NULL)
{
if (battle_config.error_log == 1)
- printf ("mob_damage : BlockError!!\n");
+ PRINTF("mob_damage : BlockError!!\n");
return 0;
}
- if (md->state.state == MS_DEAD || md->hp <= 0)
+ if (md->state.state == MS::DEAD || md->hp <= 0)
{
if (md->bl.prev != NULL)
{
- mob_changestate (md, MS_DEAD, 0);
- mobskill_use (md, tick, -1); // It is skill at the time of death.
- clif_clearchar_area (&md->bl, 1);
- map_delblock (&md->bl);
- mob_setdelayspawn (md->bl.id);
+ mob_changestate(md, MS::DEAD, 0);
+ // It is skill at the time of death.
+ mobskill_use(md, tick, MobSkillCondition::ANY);
+
+ clif_clearchar(&md->bl, BeingRemoveWhy::DEAD);
+ map_delblock(&md->bl);
+ mob_setdelayspawn(md->bl.id);
}
return 0;
}
- if (md->sc_data[SC_ENDURE].timer == -1)
- mob_stop_walking (md, 3);
+ mob_stop_walking(md, 3);
if (damage > max_hp >> 2)
- skill_stop_dancing (&md->bl, 0);
+ skill_stop_dancing(&md->bl, 0);
if (md->hp > max_hp)
md->hp = max_hp;
@@ -2692,20 +2436,20 @@ int mob_damage (struct block_list *src, struct mob_data *md, int damage,
if (md->attacked_id <= 0 && md->state.special_mob_ai == 0)
md->attacked_id = sd->bl.id;
}
- if (src && src->type == BL_MOB
+ if (src && src->type == BL::MOB
&& ((struct mob_data *) src)->state.special_mob_ai)
{
struct mob_data *md2 = (struct mob_data *) src;
- struct block_list *master_bl = map_id2bl (md2->master_id);
- if (master_bl && master_bl->type == BL_PC)
+ struct block_list *master_bl = map_id2bl(md2->master_id);
+ if (master_bl && master_bl->type == BL::PC)
{
- MAP_LOG_PC (((struct map_session_data *) master_bl),
+ MAP_LOG_PC(((struct map_session_data *) master_bl),
"MOB-TO-MOB-DMG FROM MOB%d %d TO MOB%d %d FOR %d",
md2->bl.id, md2->mob_class, md->bl.id, md->mob_class,
damage);
}
- nullpo_retr (0, md2);
+ nullpo_ret(md2);
int i;
for (i = 0, minpos = 0, mindmg = 0x7fffffff; i < DAMAGELOG_SIZE;
i++)
@@ -2739,138 +2483,27 @@ int mob_damage (struct block_list *src, struct mob_data *md, int damage,
md->hp -= damage;
- if (md->mob_class >= 1285 && md->mob_class <= 1287)
- { // guardian hp update [Valaris]
- struct guild_castle *gc = guild_mapname2gc (map[md->bl.m].name);
- if (gc)
- {
-
- if (md->bl.id == gc->GID0)
- {
- gc->Ghp0 = md->hp;
- if (gc->Ghp0 <= 0)
- {
- guild_castledatasave (gc->castle_id, 10, 0);
- guild_castledatasave (gc->castle_id, 18, 0);
- }
- }
- if (md->bl.id == gc->GID1)
- {
- gc->Ghp1 = md->hp;
- if (gc->Ghp1 <= 0)
- {
- guild_castledatasave (gc->castle_id, 11, 0);
- guild_castledatasave (gc->castle_id, 19, 0);
- }
- }
- if (md->bl.id == gc->GID2)
- {
- gc->Ghp2 = md->hp;
- if (gc->Ghp2 <= 0)
- {
- guild_castledatasave (gc->castle_id, 12, 0);
- guild_castledatasave (gc->castle_id, 20, 0);
- }
- }
- if (md->bl.id == gc->GID3)
- {
- gc->Ghp3 = md->hp;
- if (gc->Ghp3 <= 0)
- {
- guild_castledatasave (gc->castle_id, 13, 0);
- guild_castledatasave (gc->castle_id, 21, 0);
- }
- }
- if (md->bl.id == gc->GID4)
- {
- gc->Ghp4 = md->hp;
- if (gc->Ghp4 <= 0)
- {
- guild_castledatasave (gc->castle_id, 14, 0);
- guild_castledatasave (gc->castle_id, 22, 0);
- }
- }
- if (md->bl.id == gc->GID5)
- {
- gc->Ghp5 = md->hp;
- if (gc->Ghp5 <= 0)
- {
- guild_castledatasave (gc->castle_id, 15, 0);
- guild_castledatasave (gc->castle_id, 23, 0);
- }
- }
- if (md->bl.id == gc->GID6)
- {
- gc->Ghp6 = md->hp;
- if (gc->Ghp6 <= 0)
- {
- guild_castledatasave (gc->castle_id, 16, 0);
- guild_castledatasave (gc->castle_id, 24, 0);
- }
- }
- if (md->bl.id == gc->GID7)
- {
- gc->Ghp7 = md->hp;
- if (gc->Ghp7 <= 0)
- {
- guild_castledatasave (gc->castle_id, 17, 0);
- guild_castledatasave (gc->castle_id, 25, 0);
-
- }
- }
- }
- } // end addition [Valaris]
-
- if (md->option & 2)
- skill_status_change_end (&md->bl, SC_HIDING, -1);
- if (md->option & 4)
- skill_status_change_end (&md->bl, SC_CLOAKING, -1);
-
- if (md->state.special_mob_ai == 2)
- { //スフィアーマイン
- int skillidx = 0;
-
- if ((skillidx =
- mob_skillid2skillidx (md->mob_class, NPC_SELFDESTRUCTION2)) >= 0)
- {
- md->mode |= 0x1;
- md->next_walktime = tick;
- mobskill_use_id (md, &md->bl, skillidx); //自爆詠唱開始
- md->state.special_mob_ai++;
- }
- }
-
if (md->hp > 0)
{
return 0;
}
- MAP_LOG ("MOB%d DEAD", md->bl.id);
+ MAP_LOG("MOB%d DEAD", md->bl.id);
// ----- ã“ã“ã‹ã‚‰æ­»äº¡å‡¦ç† -----
- map_freeblock_lock ();
- mob_changestate (md, MS_DEAD, 0);
- mobskill_use (md, tick, -1); // 死亡時スキル
+ map_freeblock_lock();
+ // cancels timers
+ mob_changestate(md, MS::DEAD, 0);
+ mobskill_use(md, tick, MobSkillCondition::ANY);
- memset (tmpsd, 0, sizeof (tmpsd));
- memset (pt, 0, sizeof (pt));
+ memset(tmpsd, 0, sizeof(tmpsd));
+ memset(pt, 0, sizeof(pt));
- max_hp = battle_get_max_hp (&md->bl);
+ max_hp = battle_get_max_hp(&md->bl);
- if (src && src->type == BL_MOB)
- mob_unlocktarget ((struct mob_data *) src, tick);
-
- /* ソウルドレイン */
- if (sd && (skill = pc_checkskill (sd, HW_SOULDRAIN)) > 0)
- {
- clif_skill_nodamage (src, &md->bl, HW_SOULDRAIN, skill, 1);
- sp = (battle_get_lv (&md->bl)) * (65 + 15 * skill) / 100;
- if (sd->status.sp + sp > sd->status.max_sp)
- sp = sd->status.max_sp - sd->status.sp;
- sd->status.sp += sp;
- clif_heal (sd->fd, SP_SP, sp);
- }
+ if (src && src->type == BL::MOB)
+ mob_unlocktarget((struct mob_data *) src, tick);
// map外ã«æ¶ˆãˆãŸäººã¯è¨ˆç®—ã‹ã‚‰é™¤ãã®ã§
// overkill分ã¯ç„¡ã„ã‘ã©sumã¯max_hpã¨ã¯é•ã†
@@ -2882,11 +2515,11 @@ int mob_damage (struct block_list *src, struct mob_data *md, int damage,
{
if (md->dmglog[i].id == 0)
continue;
- tmpsd[i] = map_id2sd (md->dmglog[i].id);
+ tmpsd[i] = map_id2sd(md->dmglog[i].id);
if (tmpsd[i] == NULL)
continue;
count++;
- if (tmpsd[i]->bl.m != md->bl.m || pc_isdead (tmpsd[i]))
+ if (tmpsd[i]->bl.m != md->bl.m || pc_isdead(tmpsd[i]))
continue;
tdmg += (double) md->dmglog[i].dmg;
@@ -2902,31 +2535,25 @@ int mob_damage (struct block_list *src, struct mob_data *md, int damage,
// [MouseJstr]
if ((map[md->bl.m].flag.pvp == 0) || (battle_config.pvp_exp == 1))
{
-
- if ((double) max_hp < tdmg)
- dmg_rate = ((double) max_hp) / tdmg;
- else
- dmg_rate = 1;
-
// 経験値ã®åˆ†é…
for (int i = 0; i < DAMAGELOG_SIZE; i++)
{
- int pid, base_exp, job_exp, flag = 1;
+ int pid, base_exp, job_exp, flag = 1;
double per;
struct party *p;
if (tmpsd[i] == NULL || tmpsd[i]->bl.m != md->bl.m)
continue;
/* jAthena's exp formula
- per = ((double)md->dmglog[i].dmg)*(9.+(double)((count > 6)? 6:count))/10./((double)max_hp) * dmg_rate;
- temp = ((double)mob_db[md->mob_class].base_exp * (double)battle_config.base_exp_rate / 100. * per);
- base_exp = (temp > 2147483647.)? 0x7fffffff:(int)temp;
- if(mob_db[md->mob_class].base_exp > 0 && base_exp < 1) base_exp = 1;
- if(base_exp < 0) base_exp = 0;
- temp = ((double)mob_db[md->mob_class].job_exp * (double)battle_config.job_exp_rate / 100. * per);
- job_exp = (temp > 2147483647.)? 0x7fffffff:(int)temp;
- if(mob_db[md->mob_class].job_exp > 0 && job_exp < 1) job_exp = 1;
- if(job_exp < 0) job_exp = 0;
+ per = ((double)md->dmglog[i].dmg)* (9.+(double)((count > 6)? 6:count))/10./((double)max_hp) * dmg_rate;
+ temp = ((double)mob_db[md->mob_class].base_exp * (double)battle_config.base_exp_rate / 100. * per);
+ base_exp = (temp > 2147483647.)? 0x7fffffff:(int)temp;
+ if (mob_db[md->mob_class].base_exp > 0 && base_exp < 1) base_exp = 1;
+ if (base_exp < 0) base_exp = 0;
+ temp = ((double)mob_db[md->mob_class].job_exp * (double)battle_config.job_exp_rate / 100. * per);
+ job_exp = (temp > 2147483647.)? 0x7fffffff:(int)temp;
+ if (mob_db[md->mob_class].job_exp > 0 && job_exp < 1) job_exp = 1;
+ if (job_exp < 0) job_exp = 0;
*/
//eAthena's exp formula rather than jAthena's
// per=(double)md->dmglog[i].dmg*256*(9+(double)((count > 6)? 6:count))/10/(double)max_hp;
@@ -2940,7 +2567,7 @@ int mob_damage (struct block_list *src, struct mob_data *md, int damage,
base_exp =
((mob_db[md->mob_class].base_exp *
- md->stats[MOB_XP_BONUS]) >> MOB_XP_BONUS_SHIFT) * per / 256;
+ md->stats[mob_stat::XP_BONUS]) >> MOB_XP_BONUS_SHIFT) * per / 256;
if (base_exp < 1)
base_exp = 1;
if (sd && md && battle_config.pk_mode == 1
@@ -2965,13 +2592,13 @@ int mob_damage (struct block_list *src, struct mob_data *md, int damage,
if ((pid = tmpsd[i]->status.party_id) > 0)
{ // パーティã«å…¥ã£ã¦ã„ã‚‹
- int j = 0;
+ int j = 0;
for (j = 0; j < pnum; j++) // 公平パーティリストã«ã„ã‚‹ã‹ã©ã†ã‹
if (pt[j].id == pid)
break;
if (j == pnum)
{ // ã„ãªã„ã¨ãã¯å…¬å¹³ã‹ã©ã†ã‹ç¢ºèª
- if ((p = party_search (pid)) != NULL && p->exp != 0)
+ if ((p = party_search(pid)) != NULL && p->exp != 0)
{
pt[pnum].id = pid;
pt[pnum].p = p;
@@ -2989,11 +2616,12 @@ int mob_damage (struct block_list *src, struct mob_data *md, int damage,
}
}
if (flag) // å„自所得
- pc_gainexp (tmpsd[i], base_exp, job_exp);
+ pc_gainexp_reason(tmpsd[i], base_exp, job_exp,
+ PC_GAINEXP_REASON::KILLING);
}
// 公平分é…
for (int i = 0; i < pnum; i++)
- party_exp_share (pt[i].p, md->bl.m, pt[i].base_exp,
+ party_exp_share(pt[i].p, md->bl.m, pt[i].base_exp,
pt[i].job_exp);
// item drop
@@ -3002,26 +2630,23 @@ int mob_damage (struct block_list *src, struct mob_data *md, int damage,
for (int i = 0; i < 8; i++)
{
struct delay_item_drop *ditem;
- int drop_rate;
if (md->state.special_mob_ai >= 1 && battle_config.alchemist_summon_reward != 1) // Added [Valaris]
break; // End
if (mob_db[md->mob_class].dropitem[i].nameid <= 0)
continue;
- drop_rate = mob_db[md->mob_class].dropitem[i].p;
- if (drop_rate <= 0 && battle_config.drop_rate0item == 1)
- drop_rate = 1;
+ random_::Fixed<int, 10000> drop_rate = mob_db[md->mob_class].dropitem[i].p;
if (battle_config.drops_by_luk > 0 && sd && md)
- drop_rate += (sd->status.luk * battle_config.drops_by_luk) / 100; // drops affected by luk [Valaris]
+ drop_rate.num += (sd->status.attrs[ATTR::LUK] * battle_config.drops_by_luk) / 100; // drops affected by luk [Valaris]
if (sd && md && battle_config.pk_mode == 1
&& (mob_db[md->mob_class].lv - sd->status.base_level >= 20))
- drop_rate *= 1.25; // pk_mode increase drops if 20 level difference [Valaris]
- if (drop_rate <= MRAND (10000))
+ drop_rate.num *= 1.25; // pk_mode increase drops if 20 level difference [Valaris]
+ if (!random_::chance(drop_rate))
continue;
ditem = (struct delay_item_drop *)
- calloc (1, sizeof (struct delay_item_drop));
+ calloc(1, sizeof(struct delay_item_drop));
ditem->nameid = mob_db[md->mob_class].dropitem[i].nameid;
ditem->amount = 1;
ditem->m = md->bl.m;
@@ -3030,43 +2655,10 @@ 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);
- }
- if (sd && sd->state.attack_type == BF_WEAPON)
- {
- for (int i = 0; i < sd->monster_drop_item_count; i++)
- {
- struct delay_item_drop *ditem;
- int race = battle_get_race (&md->bl);
- if (sd->monster_drop_itemid[i] <= 0)
- continue;
- if (sd->monster_drop_race[i] & (1 << race) ||
- (mob_db[md->mob_class].mode & 0x20
- && sd->monster_drop_race[i] & 1 << 10)
- || (!(mob_db[md->mob_class].mode & 0x20)
- && sd->monster_drop_race[i] & 1 << 11))
- {
- if (sd->monster_drop_itemrate[i] <= MRAND (10000))
- continue;
-
- 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;
- ditem->x = md->bl.x;
- ditem->y = md->bl.y;
- ditem->first_sd = mvp_sd;
- ditem->second_sd = second_sd;
- ditem->third_sd = third_sd;
- add_timer (tick + 520 + i, mob_delay_item_drop,
- (int) ditem, 0);
- }
- }
- if (sd->get_zeny_num > 0)
- pc_getzeny (sd,
- mob_db[md->mob_class].lv * 10 +
- MRAND ((sd->get_zeny_num + 1)));
+ Timer(tick + std::chrono::milliseconds(500) + static_cast<interval_t>(i),
+ std::bind(mob_delay_item_drop, ph::_1, ph::_2,
+ ditem)
+ ).detach();
}
if (md->lootitem)
{
@@ -3075,80 +2667,25 @@ int mob_damage (struct block_list *src, struct mob_data *md, int damage,
struct delay_item_drop2 *ditem;
ditem = (struct delay_item_drop2 *)
- calloc (1, sizeof (struct delay_item_drop2));
- memcpy (&ditem->item_data, &md->lootitem[i],
- sizeof (md->lootitem[0]));
+ calloc(1, sizeof(struct delay_item_drop2));
+ memcpy(&ditem->item_data, &md->lootitem[i],
+ sizeof(md->lootitem[0]));
ditem->m = md->bl.m;
ditem->x = md->bl.x;
ditem->y = md->bl.y;
ditem->first_sd = mvp_sd;
ditem->second_sd = second_sd;
ditem->third_sd = third_sd;
- add_timer (tick + 540 + i, mob_delay_item_drop2,
- (int) ditem, 0);
+ // ?
+ Timer(tick + std::chrono::milliseconds(540) + static_cast<interval_t>(i),
+ std::bind(mob_delay_item_drop2, ph::_1, ph::_2,
+ ditem)
+ ).detach();
}
}
}
-
- // mvp処ç†
- if (mvp_sd && mob_db[md->mob_class].mexp > 0)
- {
- int j;
- int mexp = battle_get_mexp (&md->bl);
- temp =
- ((double) mexp * (double) battle_config.mvp_exp_rate *
- (9. + (double) count) / 1000.);
- mexp = (temp > 2147483647.) ? 0x7fffffff : (int) temp;
- if (mexp < 1)
- mexp = 1;
- clif_mvp_effect (mvp_sd); // エフェクト
- clif_mvp_exp (mvp_sd, mexp);
- pc_gainexp (mvp_sd, mexp, 0);
- for (j = 0; j < 3; j++)
- {
- int i = MRAND (3);
- if (mob_db[md->mob_class].mvpitem[i].nameid <= 0)
- continue;
- int drop_rate = mob_db[md->mob_class].mvpitem[i].p;
- if (drop_rate <= 0 && battle_config.drop_rate0item == 1)
- drop_rate = 1;
- if (drop_rate < battle_config.item_drop_mvp_min)
- drop_rate = battle_config.item_drop_mvp_min;
- if (drop_rate > battle_config.item_drop_mvp_max)
- drop_rate = battle_config.item_drop_mvp_max;
- if (drop_rate <= MRAND (10000))
- continue;
- memset (&item, 0, sizeof (item));
- item.nameid = mob_db[md->mob_class].mvpitem[i].nameid;
- item.identify = !itemdb_isequip3 (item.nameid);
- clif_mvp_item (mvp_sd, item.nameid);
- if (mvp_sd->weight * 2 > mvp_sd->max_weight)
- map_addflooritem (&item, 1, mvp_sd->bl.m, mvp_sd->bl.x,
- mvp_sd->bl.y, mvp_sd, second_sd,
- third_sd, 1);
- else if ((ret = pc_additem (mvp_sd, &item, 1)))
- {
- clif_additem (sd, 0, 0, ret);
- map_addflooritem (&item, 1, mvp_sd->bl.m, mvp_sd->bl.x,
- mvp_sd->bl.y, mvp_sd, second_sd,
- third_sd, 1);
- }
- break;
- }
- }
-
} // [MouseJstr]
- // <Agit> NPC Event [OnAgitBreak]
- if (md->npc_event[0]
- && strcmp (((md->npc_event) + strlen (md->npc_event) - 13),
- "::OnAgitBreak") == 0)
- {
- printf ("MOB.C: Run NPC_Event[OnAgitBreak].\n");
- if (agit_flag == 1) //Call to Run NPC_Event[OnAgitBreak]
- guild_agit_break (md);
- }
-
// SCRIPT実行
if (md->npc_event[0])
{
@@ -3159,7 +2696,7 @@ int mob_damage (struct block_list *src, struct mob_data *md, int damage,
else
{
struct map_session_data *tmp_sd;
- int i;
+ int i;
for (i = 0; i < fd_max; i++)
{
if (session[i] && (tmp_sd = (struct map_session_data *)session[i]->session_data)
@@ -3175,95 +2712,14 @@ int mob_damage (struct block_list *src, struct mob_data *md, int damage,
}
}
if (sd)
- npc_event (sd, md->npc_event, 0);
+ npc_event(sd, md->npc_event, 0);
}
- clif_clearchar_area (&md->bl, 1);
- map_delblock (&md->bl);
- if (mob_get_viewclass (md->mob_class) <= 1000)
- clif_clearchar_delay (tick + 3000, &md->bl, 0);
- mob_deleteslave (md);
- mob_setdelayspawn (md->bl.id);
- map_freeblock_unlock ();
-
- return 0;
-}
-
-/*==========================================
- *
- *------------------------------------------
- */
-int mob_class_change (struct mob_data *md, int *value)
-{
- unsigned int tick = gettick ();
- int i, c, hp_rate, max_hp, mob_class, count = 0;
-
- nullpo_retr (0, md);
- nullpo_retr (0, value);
-
- if (value[0] <= 1000 || value[0] > 2000)
- return 0;
- if (md->bl.prev == NULL)
- return 0;
-
- while (count < 5 && value[count] > 1000 && value[count] <= 2000)
- count++;
- if (count < 1)
- return 0;
-
- mob_class = value[MRAND (count)];
- if (mob_class <= 1000 || mob_class > 2000)
- return 0;
-
- max_hp = battle_get_max_hp (&md->bl);
- hp_rate = md->hp * 100 / max_hp;
- clif_mob_class_change (md, mob_class);
- md->mob_class = mob_class;
- max_hp = battle_get_max_hp (&md->bl);
- if (battle_config.monster_class_change_full_recover == 1)
- {
- md->hp = max_hp;
- memset (md->dmglog, 0, sizeof (md->dmglog));
- }
- else
- md->hp = max_hp * hp_rate / 100;
- if (md->hp > max_hp)
- md->hp = max_hp;
- else if (md->hp < 1)
- md->hp = 1;
-
- memcpy (md->name, mob_db[mob_class].jname, 24);
- memset (&md->state, 0, sizeof (md->state));
- md->attacked_id = 0;
- md->target_id = 0;
- md->move_fail_count = 0;
-
- md->stats[MOB_SPEED] = mob_db[md->mob_class].speed;
- md->def_ele = mob_db[md->mob_class].element;
-
- mob_changestate (md, MS_IDLE, 0);
- skill_castcancel (&md->bl, 0);
- md->state.skillstate = MSS_IDLE;
- md->last_thinktime = tick;
- md->next_walktime = tick + MPRAND (5000, 50);
- md->attackabletime = tick;
- md->canmove_tick = tick;
- md->sg_count = 0;
-
- for (i = 0, c = tick - 1000 * 3600 * 10; i < MAX_MOBSKILL; i++)
- md->skilldelay[i] = c;
- md->skillid = 0;
- md->skilllv = 0;
-
- if (md->lootitem == NULL && mob_db[mob_class].mode & 0x02)
- md->lootitem = (struct item *)
- calloc (LOOTITEM_SIZE, sizeof (struct item));
-
- skill_clear_unitgroup (&md->bl);
- skill_cleartimerskill (&md->bl);
-
- clif_clearchar_area (&md->bl, 0);
- clif_spawnmob (md);
+ clif_clearchar(&md->bl, BeingRemoveWhy::DEAD);
+ map_delblock(&md->bl);
+ mob_deleteslave(md);
+ mob_setdelayspawn(md->bl.id);
+ map_freeblock_unlock();
return 0;
}
@@ -3272,40 +2728,16 @@ int mob_class_change (struct mob_data *md, int *value)
* mob回復
*------------------------------------------
*/
-int mob_heal (struct mob_data *md, int heal)
+int mob_heal(struct mob_data *md, int heal)
{
- int max_hp = battle_get_max_hp (&md->bl);
+ int max_hp = battle_get_max_hp(&md->bl);
- nullpo_retr (0, md);
+ nullpo_ret(md);
md->hp += heal;
if (max_hp < md->hp)
md->hp = max_hp;
- if (md->mob_class >= 1285 && md->mob_class <= 1287)
- { // guardian hp update [Valaris]
- struct guild_castle *gc = guild_mapname2gc (map[md->bl.m].name);
- if (gc)
- {
- if (md->bl.id == gc->GID0)
- gc->Ghp0 = md->hp;
- if (md->bl.id == gc->GID1)
- gc->Ghp1 = md->hp;
- if (md->bl.id == gc->GID2)
- gc->Ghp2 = md->hp;
- if (md->bl.id == gc->GID3)
- gc->Ghp3 = md->hp;
- if (md->bl.id == gc->GID4)
- gc->Ghp4 = md->hp;
- if (md->bl.id == gc->GID5)
- gc->Ghp5 = md->hp;
- if (md->bl.id == gc->GID6)
- gc->Ghp6 = md->hp;
- if (md->bl.id == gc->GID7)
- gc->Ghp7 = md->hp;
- }
- } // end addition [Valaris]
-
return 0;
}
@@ -3314,18 +2746,14 @@ int mob_heal (struct mob_data *md, int heal)
*------------------------------------------
*/
static
-int mob_warpslave_sub (struct block_list *bl, va_list ap)
+void mob_warpslave_sub(struct block_list *bl, int id, int x, int y)
{
struct mob_data *md = (struct mob_data *) bl;
- int id, x, y;
- id = va_arg (ap, int);
- x = va_arg (ap, int);
- y = va_arg (ap, int);
+
if (md->master_id == id)
{
- mob_warp (md, -1, x, y, 2);
+ mob_warp(md, -1, x, y, BeingRemoveWhy::QUIT);
}
- return 0;
}
/*==========================================
@@ -3333,13 +2761,12 @@ int mob_warpslave_sub (struct block_list *bl, va_list ap)
*------------------------------------------
*/
static
-int mob_warpslave (struct mob_data *md, int x, int y)
+int mob_warpslave(struct mob_data *md, int x, int y)
{
-//printf("warp slave\n");
- map_foreachinarea (mob_warpslave_sub, md->bl.m,
- x - AREA_SIZE, y - AREA_SIZE,
- x + AREA_SIZE, y + AREA_SIZE, BL_MOB,
- md->bl.id, md->bl.x, md->bl.y);
+//PRINTF("warp slave\n");
+ map_foreachinarea(std::bind(mob_warpslave_sub, ph::_1, md->bl.id, md->bl.x, md->bl.y),
+ md->bl.m, x - AREA_SIZE, y - AREA_SIZE,
+ x + AREA_SIZE, y + AREA_SIZE, BL::MOB);
return 0;
}
@@ -3347,11 +2774,11 @@ int mob_warpslave (struct mob_data *md, int x, int y)
* mobワープ
*------------------------------------------
*/
-int mob_warp (struct mob_data *md, int m, int x, int y, int type)
+int mob_warp(struct mob_data *md, int m, int x, int y, BeingRemoveWhy type)
{
- int i = 0, c, xs = 0, ys = 0, bx = x, by = y;
+ int i = 0, xs = 0, ys = 0, bx = x, by = y;
- nullpo_retr (0, md);
+ nullpo_ret(md);
if (md->bl.prev == NULL)
return 0;
@@ -3359,35 +2786,38 @@ int mob_warp (struct mob_data *md, int m, int x, int y, int type)
if (m < 0)
m = md->bl.m;
- if (type >= 0)
+ if (type != BeingRemoveWhy::NEGATIVE1)
{
if (map[md->bl.m].flag.monster_noteleport)
return 0;
- clif_clearchar_area (&md->bl, type);
+ clif_clearchar(&md->bl, type);
}
- skill_unit_out_all (&md->bl, gettick (), 1);
- map_delblock (&md->bl);
+ map_delblock(&md->bl);
if (bx > 0 && by > 0)
{ // ä½ç½®æŒ‡å®šã®å ´åˆå‘¨å›²ï¼™ã‚»ãƒ«ã‚’探索
xs = ys = 9;
}
- while ((x < 0 || y < 0 || ((c = read_gat (m, x, y)) == 1 || c == 5))
- && (i++) < 1000)
+ while ((x < 0
+ || y < 0
+ || bool(read_gat(m, x, y) & MapCell::UNWALKABLE))
+ && (i++) < 1000)
{
if (xs > 0 && ys > 0 && i < 250)
- { // 指定ä½ç½®ä»˜è¿‘ã®æŽ¢ç´¢
- x = MPRAND (bx, xs) - xs / 2;
- y = MPRAND (by, ys) - ys / 2;
+ {
+ // 指定ä½ç½®ä»˜è¿‘ã®æŽ¢ç´¢
+ x = bx + random_::to(xs) - xs / 2;
+ y = by + random_::to(ys) - ys / 2;
}
else
- { // 完全ランダム探索
- x = MPRAND (1, (map[m].xs - 2));
- y = MPRAND (1, (map[m].ys - 2));
+ {
+ // 完全ランダム探索
+ x = random_::in(1, map[m].xs - 2);
+ y = random_::in(1, map[m].ys - 2);
}
}
- md->dir = 0;
+ md->dir = DIR::S;
if (i < 1000)
{
md->bl.x = md->to_x = x;
@@ -3396,29 +2826,29 @@ int mob_warp (struct mob_data *md, int m, int x, int y, int type)
}
else
{
- m = md->bl.m;
if (battle_config.error_log == 1)
- printf ("MOB %d warp failed, mob_class = %d\n", md->bl.id, md->mob_class);
+ PRINTF("MOB %d warp failed, mob_class = %d\n", md->bl.id, md->mob_class);
}
md->target_id = 0; // タゲを解除ã™ã‚‹
- md->state.targettype = NONE_ATTACKABLE;
+ md->state.attackable = false;
md->attacked_id = 0;
- md->state.skillstate = MSS_IDLE;
- mob_changestate (md, MS_IDLE, 0);
+ md->state.skillstate = MobSkillState::MSS_IDLE;
+ mob_changestate(md, MS::IDLE, 0);
- if (type > 0 && i == 1000)
+ if (type != BeingRemoveWhy::GONE && type != BeingRemoveWhy::NEGATIVE1
+ && i == 1000)
{
if (battle_config.battle_log == 1)
- printf ("MOB %d warp to (%d,%d), mob_class = %d\n", md->bl.id, x, y,
+ PRINTF("MOB %d warp to (%d,%d), mob_class = %d\n", md->bl.id, x, y,
md->mob_class);
}
- map_addblock (&md->bl);
- if (type > 0)
+ map_addblock(&md->bl);
+ if (type != BeingRemoveWhy::GONE && type != BeingRemoveWhy::NEGATIVE1)
{
- clif_spawnmob (md);
- mob_warpslave (md, md->bl.x, md->bl.y);
+ clif_spawnmob(md);
+ mob_warpslave(md, md->bl.x, md->bl.y);
}
return 0;
@@ -3429,21 +2859,15 @@ int mob_warp (struct mob_data *md, int m, int x, int y, int type)
*------------------------------------------
*/
static
-int mob_countslave_sub (struct block_list *bl, va_list ap)
+void mob_countslave_sub(struct block_list *bl, int id, int *c)
{
- int id, *c;
struct mob_data *md;
- id = va_arg (ap, int);
-
- nullpo_retr (0, bl);
- nullpo_retr (0, ap);
- nullpo_retr (0, c = va_arg (ap, int *));
- nullpo_retr (0, md = (struct mob_data *) bl);
+ nullpo_retv(bl);
+ md = (struct mob_data *) bl;
if (md->master_id == id)
(*c)++;
- return 0;
}
/*==========================================
@@ -3451,15 +2875,15 @@ int mob_countslave_sub (struct block_list *bl, va_list ap)
*------------------------------------------
*/
static
-int mob_countslave (struct mob_data *md)
+int mob_countslave(struct mob_data *md)
{
- int c = 0;
+ int c = 0;
- nullpo_retr (0, md);
+ nullpo_ret(md);
- map_foreachinarea (mob_countslave_sub, md->bl.m,
- 0, 0, map[md->bl.m].xs - 1, map[md->bl.m].ys - 1,
- BL_MOB, md->bl.id, &c);
+ map_foreachinarea(std::bind(mob_countslave_sub, ph::_1, md->bl.id, &c),
+ md->bl.m, 0, 0,
+ map[md->bl.m].xs - 1, map[md->bl.m].ys - 1, BL::MOB);
return c;
}
@@ -3467,13 +2891,13 @@ int mob_countslave (struct mob_data *md)
* 手下MOBå¬å–š
*------------------------------------------
*/
-int mob_summonslave (struct mob_data *md2, int *value, int amount, int flag)
+int mob_summonslave(struct mob_data *md2, int *value, int amount, int flag)
{
struct mob_data *md;
- int bx, by, m, count = 0, mob_class, k, a = amount;
+ int bx, by, m, count = 0, mob_class, k, a = amount;
- nullpo_retr (0, md2);
- nullpo_retr (0, value);
+ nullpo_ret(md2);
+ nullpo_ret(value);
bx = md2->bl.x;
by = md2->bl.y;
@@ -3494,19 +2918,21 @@ int mob_summonslave (struct mob_data *md2, int *value, int amount, int flag)
continue;
for (; amount > 0; amount--)
{
- int x = 0, y = 0, c = 0, i = 0;
- md = (struct mob_data *) calloc (1, sizeof (struct mob_data));
- if (mob_db[mob_class].mode & 0x02)
+ int x = 0, y = 0, i = 0;
+ md = (struct mob_data *) calloc(1, sizeof(struct mob_data));
+ if (bool(mob_db[mob_class].mode & MobMode::LOOTER))
md->lootitem = (struct item *)
- calloc (LOOTITEM_SIZE, sizeof (struct item));
+ calloc(LOOTITEM_SIZE, sizeof(struct item));
else
md->lootitem = NULL;
- while ((x <= 0 || y <= 0 || (c = map_getcell (m, x, y)) == 1
- || c == 5) && (i++) < 100)
+ while ((x <= 0
+ || y <= 0
+ || bool(map_getcell(m, x, y) & MapCell::UNWALKABLE))
+ && (i++) < 100)
{
- x = MPRAND (bx, 9) - 4;
- y = MPRAND (by, 9) - 4;
+ x = bx + random_::in(-4, 4);
+ y = by + random_::in(-4, 4);
}
if (i >= 100)
{
@@ -3514,7 +2940,7 @@ int mob_summonslave (struct mob_data *md2, int *value, int amount, int flag)
y = by;
}
- mob_spawn_dataset (md, "--ja--", mob_class);
+ mob_spawn_dataset(md, "--ja--", mob_class);
md->bl.prev = NULL;
md->bl.next = NULL;
md->bl.m = m;
@@ -3526,17 +2952,14 @@ int mob_summonslave (struct mob_data *md2, int *value, int amount, int flag)
md->y0 = y;
md->xs = 0;
md->ys = 0;
- md->stats[MOB_SPEED] = md2->stats[MOB_SPEED];
- md->spawndelay1 = -1; // 一度ã®ã¿ãƒ•ãƒ©ã‚°
- md->spawndelay2 = -1; // 一度ã®ã¿ãƒ•ãƒ©ã‚°
-
- memset (md->npc_event, 0, sizeof (md->npc_event));
- md->bl.type = BL_MOB;
- map_addiddb (&md->bl);
- mob_spawn (md->bl.id);
- clif_skill_nodamage (&md->bl, &md->bl,
- (flag) ? NPC_SUMMONSLAVE : NPC_SUMMONMONSTER,
- a, 1);
+ md->stats[mob_stat::SPEED] = md2->stats[mob_stat::SPEED];
+ md->spawndelay1 = static_cast<interval_t>(-1); // 一度ã®ã¿ãƒ•ãƒ©ã‚°
+ md->spawndelay2 = static_cast<interval_t>(-1); // 一度ã®ã¿ãƒ•ãƒ©ã‚°
+
+ memset(md->npc_event, 0, sizeof(md->npc_event));
+ md->bl.type = BL::MOB;
+ map_addiddb(&md->bl);
+ mob_spawn(md->bl.id);
if (flag)
md->master_id = md2->bl.id;
@@ -3549,76 +2972,49 @@ int mob_summonslave (struct mob_data *md2, int *value, int amount, int flag)
* 自分をロックã—ã¦ã„ã‚‹PCã®æ•°ã‚’æ•°ãˆã‚‹(foreachclient)
*------------------------------------------
*/
-static int mob_counttargeted_sub (struct block_list *bl, va_list ap)
+static
+void mob_counttargeted_sub(struct block_list *bl,
+ int id, int *c, struct block_list *src, ATK target_lv)
{
- int id, *c, target_lv;
- struct block_list *src;
-
- id = va_arg (ap, int);
- nullpo_retr (0, bl);
- nullpo_retr (0, ap);
- nullpo_retr (0, c = va_arg (ap, int *));
+ nullpo_retv(bl);
+ nullpo_retv(c);
- src = va_arg (ap, struct block_list *);
- target_lv = va_arg (ap, int);
if (id == bl->id || (src && id == src->id))
- return 0;
- if (bl->type == BL_PC)
+ return;
+ if (bl->type == BL::PC)
{
struct map_session_data *sd = (struct map_session_data *) bl;
- if (sd && sd->attacktarget == id && sd->attacktimer != -1
+ if (sd && sd->attacktarget == id && sd->attacktimer
&& sd->attacktarget_lv >= target_lv)
(*c)++;
}
- else if (bl->type == BL_MOB)
+ else if (bl->type == BL::MOB)
{
struct mob_data *md = (struct mob_data *) bl;
- if (md && md->target_id == id && md->timer != -1
- && md->state.state == MS_ATTACK && md->target_lv >= target_lv)
+ if (md && md->target_id == id && md->timer
+ && md->state.state == MS::ATTACK && md->target_lv >= target_lv)
(*c)++;
}
- return 0;
}
/*==========================================
* 自分をロックã—ã¦ã„ã‚‹PCã®æ•°ã‚’æ•°ãˆã‚‹
*------------------------------------------
*/
-int mob_counttargeted (struct mob_data *md, struct block_list *src,
- int target_lv)
+int mob_counttargeted(struct mob_data *md, struct block_list *src,
+ ATK target_lv)
{
- int c = 0;
+ int c = 0;
- nullpo_retr (0, md);
+ nullpo_ret(md);
- map_foreachinarea (mob_counttargeted_sub, md->bl.m,
- md->bl.x - AREA_SIZE, md->bl.y - AREA_SIZE,
- md->bl.x + AREA_SIZE, md->bl.y + AREA_SIZE, 0,
- md->bl.id, &c, src, target_lv);
+ map_foreachinarea(std::bind(mob_counttargeted_sub, ph::_1, md->bl.id, &c, src, target_lv),
+ md->bl.m, md->bl.x - AREA_SIZE, md->bl.y - AREA_SIZE,
+ md->bl.x + AREA_SIZE, md->bl.y + AREA_SIZE,
+ BL::NUL);
return c;
}
-/*==========================================
- *MOBskillã‹ã‚‰è©²å½“skillidã®skillidxã‚’è¿”ã™
- *------------------------------------------
- */
-int mob_skillid2skillidx (int mob_class, int skillid)
-{
- int i;
- struct mob_skill *ms = mob_db[mob_class].skill;
-
- if (ms == NULL)
- return -1;
-
- for (i = 0; i < mob_db[mob_class].maxskill; i++)
- {
- if (ms[i].skill_id == skillid)
- return i;
- }
- return -1;
-
-}
-
//
// MOBスキル
//
@@ -3627,104 +3023,66 @@ int mob_skillid2skillidx (int mob_class, int skillid)
* スキル使用(詠唱完了ã€ID指定)
*------------------------------------------
*/
-void mobskill_castend_id (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data)
+void mobskill_castend_id(TimerData *, tick_t tick, int id)
{
struct mob_data *md = NULL;
struct block_list *bl;
struct block_list *mbl;
- int range;
+ int range;
- if ((mbl = map_id2bl (id)) == NULL) //è© å”±ã—ãŸMobãŒã‚‚ã†ã„ãªã„ã¨ã„ã†ã®ã¯è‰¯ãã‚る正常処ç†
+ if ((mbl = map_id2bl(id)) == NULL) //è© å”±ã—ãŸMobãŒã‚‚ã†ã„ãªã„ã¨ã„ã†ã®ã¯è‰¯ãã‚る正常処ç†
return;
if ((md = (struct mob_data *) mbl) == NULL)
{
- printf ("mobskill_castend_id nullpo mbl->id:%d\n", mbl->id);
+ PRINTF("mobskill_castend_id nullpo mbl->id:%d\n", mbl->id);
return;
}
- if (md->bl.type != BL_MOB || md->bl.prev == NULL)
+ if (md->bl.type != BL::MOB || md->bl.prev == NULL)
return;
- if (md->skilltimer != tid) // タイマIDã®ç¢ºèª
+
+ if (bool(md->opt1))
return;
- md->skilltimer = -1;
- //沈黙や状態異常ãªã©
- if (md->sc_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;
- if (md->sc_data[SC_AUTOCOUNTER].timer != -1 && md->skillid != KN_AUTOCOUNTER) //オートカウンター
- return;
- if (md->sc_data[SC_BLADESTOP].timer != -1) //白刃å–ã‚Š
- return;
- if (md->sc_data[SC_BERSERK].timer != -1) //ãƒãƒ¼ã‚µãƒ¼ã‚¯
- return;
- }
- if (md->skillid != NPC_EMOTION)
- md->last_thinktime = tick + battle_get_adelay (&md->bl);
+ if (md->skillid != SkillID::NPC_EMOTION)
+ md->last_thinktime = tick + battle_get_adelay(&md->bl);
- if ((bl = map_id2bl (md->skilltarget)) == NULL || bl->prev == NULL)
+ if ((bl = map_id2bl(md->skilltarget)) == NULL || bl->prev == NULL)
{ //スキルターゲットãŒå­˜åœ¨ã—ãªã„
- //printf("mobskill_castend_id nullpo\n");//ターゲットãŒã„ãªã„ã¨ãã¯nullpoã˜ã‚ƒãªãã¦æ™®é€šã«çµ‚了
+ //PRINTF("mobskill_castend_id nullpo\n");//ターゲットãŒã„ãªã„ã¨ãã¯nullpoã˜ã‚ƒãªãã¦æ™®é€šã«çµ‚了
return;
}
if (md->bl.m != bl->m)
return;
- if (md->skillid == PR_LEXAETERNA)
- {
- struct status_change *sc_data = battle_get_sc_data (bl);
- if (sc_data
- && (sc_data[SC_FREEZE].timer != -1
- || (sc_data[SC_STONE].timer != -1
- && sc_data[SC_STONE].val2 == 0)))
- return;
- }
- else if (md->skillid == RG_BACKSTAP)
- {
- int dir = map_calc_dir (&md->bl, bl->x, bl->y), t_dir =
- 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;
- }
- if (((skill_get_inf (md->skillid) & 1) || (skill_get_inf2 (md->skillid) & 4)) && // 彼我敵対関係ãƒã‚§ãƒƒã‚¯
- battle_check_target (&md->bl, bl, BCT_ENEMY) <= 0)
+ if (((skill_get_inf(md->skillid) & 1) || (skill_get_inf2(md->skillid) & 4)) && // 彼我敵対関係ãƒã‚§ãƒƒã‚¯
+ battle_check_target(&md->bl, bl, BCT_ENEMY) <= 0)
return;
- range = skill_get_range (md->skillid, md->skilllv);
+ range = skill_get_range(md->skillid, md->skilllv);
if (range < 0)
- range = battle_get_range (&md->bl) - (range + 1);
+ 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))
+ distance(md->bl.x, md->bl.y, bl->x, bl->y))
return;
md->skilldelay[md->skillidx] = tick;
if (battle_config.mob_skill_log == 1)
- printf ("MOB skill castend skill=%d, mob_class = %d\n", md->skillid,
- md->mob_class);
- mob_stop_walking (md, 0);
+ PRINTF("MOB skill castend skill=%d, mob_class = %d\n",
+ md->skillid, md->mob_class);
+ mob_stop_walking(md, 0);
- switch (skill_get_nk (md->skillid))
+ switch (skill_get_nk(md->skillid))
{
// 攻撃系/å¹ã飛ã°ã—ç³»
case 0:
case 2:
- skill_castend_damage_id (&md->bl, bl, md->skillid, md->skilllv,
- tick, 0);
+ skill_castend_damage_id(&md->bl, bl,
+ md->skillid, md->skilllv,
+ tick, BCT_ZERO);
break;
case 1: // 支æ´ç³»
- if (!mob_db[md->mob_class].skill[md->skillidx].val[0] &&
- (md->skillid == AL_HEAL
- || (md->skillid == ALL_RESURRECTION && bl->type != BL_PC))
- && battle_check_undead (battle_get_race (bl),
- battle_get_elem_type (bl)))
- skill_castend_damage_id (&md->bl, bl, md->skillid,
- md->skilllv, tick, 0);
- else
- skill_castend_nodamage_id (&md->bl, bl, md->skillid,
- md->skilllv, tick, 0);
+ skill_castend_nodamage_id(&md->bl, bl,
+ md->skillid, md->skilllv);
break;
}
}
@@ -3733,152 +3091,56 @@ void mobskill_castend_id (timer_id tid, tick_t tick, custom_id_t id, custom_data
* スキル使用(詠唱完了ã€å ´æ‰€æŒ‡å®šï¼‰
*------------------------------------------
*/
-void mobskill_castend_pos (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data)
+void mobskill_castend_pos(TimerData *, tick_t tick, int id)
{
struct mob_data *md = NULL;
struct block_list *bl;
- int range, maxcount;
+ int range;
//mobskill_castend_idåŒæ§˜è© å”±ã—ãŸMobãŒè© å”±å®Œäº†æ™‚ã«ã‚‚ã†ã„ãªã„ã¨ã„ã†ã®ã¯ã‚ã‚Šãã†ãªã®ã§nullpoã‹ã‚‰é™¤å¤–
- if ((bl = map_id2bl (id)) == NULL)
+ if ((bl = map_id2bl(id)) == NULL)
return;
- nullpo_retv (md = (struct mob_data *) bl);
+ md = (struct mob_data *) bl;
+ nullpo_retv(md);
- if (md->bl.type != BL_MOB || md->bl.prev == NULL)
+ if (md->bl.type != BL::MOB || md->bl.prev == NULL)
return;
- if (md->skilltimer != tid) // タイマIDã®ç¢ºèª
+ if (bool(md->opt1))
return;
- md->skilltimer = -1;
- if (md->sc_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;
- if (md->sc_data[SC_AUTOCOUNTER].timer != -1 && md->skillid != KN_AUTOCOUNTER) //オートカウンター
- return;
- if (md->sc_data[SC_BLADESTOP].timer != -1) //白刃å–ã‚Š
- return;
- if (md->sc_data[SC_BERSERK].timer != -1) //ãƒãƒ¼ã‚µãƒ¼ã‚¯
- return;
- }
-
- if (battle_config.monster_skill_reiteration == 0)
- {
- range = -1;
- switch (md->skillid)
- {
- case MG_SAFETYWALL:
- case WZ_FIREPILLAR:
- case HT_SKIDTRAP:
- case HT_LANDMINE:
- case HT_ANKLESNARE:
- case HT_SHOCKWAVE:
- case HT_SANDMAN:
- case HT_FLASHER:
- case HT_FREEZINGTRAP:
- case HT_BLASTMINE:
- case HT_CLAYMORETRAP:
- case PF_SPIDERWEB: /* スパイダーウェッブ */
- range = 0;
- break;
- case AL_PNEUMA:
- case AL_WARP:
- range = 1;
- break;
- }
- if (range >= 0)
- {
- if (skill_check_unit_range
- (md->bl.m, md->skillx, md->skilly, range, md->skillid) > 0)
- return;
- }
- }
- if (battle_config.monster_skill_nofootset == 1)
- {
- range = -1;
- switch (md->skillid)
- {
- case WZ_FIREPILLAR:
- case HT_SKIDTRAP:
- case HT_LANDMINE:
- case HT_ANKLESNARE:
- case HT_SHOCKWAVE:
- case HT_SANDMAN:
- case HT_FLASHER:
- case HT_FREEZINGTRAP:
- case HT_BLASTMINE:
- case HT_CLAYMORETRAP:
- case AM_DEMONSTRATION:
- case PF_SPIDERWEB: /* スパイダーウェッブ */
- range = 1;
- break;
- case AL_WARP:
- range = 0;
- break;
- }
- if (range >= 0)
- {
- if (skill_check_unit_range2
- (md->bl.m, md->skillx, md->skilly, range) > 0)
- return;
- }
- }
-
- if (battle_config.monster_land_skill_limit == 1)
- {
- maxcount = skill_get_maxcount (md->skillid);
- if (maxcount > 0)
- {
- int i, c;
- for (i = c = 0; i < MAX_MOBSKILLUNITGROUP; i++)
- {
- if (md->skillunit[i].alive_count > 0
- && md->skillunit[i].skill_id == md->skillid)
- c++;
- }
- if (c >= maxcount)
- return;
- }
- }
-
- range = skill_get_range (md->skillid, md->skilllv);
+ range = skill_get_range(md->skillid, md->skilllv);
if (range < 0)
- range = battle_get_range (&md->bl) - (range + 1);
+ 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))
+ distance(md->bl.x, md->bl.y, md->skillx, md->skilly))
return;
md->skilldelay[md->skillidx] = tick;
if (battle_config.mob_skill_log == 1)
- printf ("MOB skill castend skill=%d, mob_class = %d\n", md->skillid,
- md->mob_class);
- mob_stop_walking (md, 0);
-
- skill_castend_pos2 (&md->bl, md->skillx, md->skilly, md->skillid,
- md->skilllv, tick, 0);
-
- return;
+ PRINTF("MOB skill castend skill=%d, mob_class = %d\n",
+ md->skillid, md->mob_class);
+ mob_stop_walking(md, 0);
}
/*==========================================
* Skill use (an aria start, ID specification)
*------------------------------------------
*/
-int mobskill_use_id (struct mob_data *md, struct block_list *target,
+int mobskill_use_id(struct mob_data *md, struct block_list *target,
int skill_idx)
{
- int casttime, range;
+ int range;
struct mob_skill *ms;
- int skill_id, skill_lv, forcecast = 0;
+ SkillID skill_id;
+ int skill_lv;
- nullpo_retr (0, md);
- nullpo_retr (0, ms = &mob_db[md->mob_class].skill[skill_idx]);
+ nullpo_ret(md);
+ ms = &mob_db[md->mob_class].skill[skill_idx];
+ nullpo_ret(ms);
- if (target == NULL && (target = map_id2bl (md->target_id)) == NULL)
+ if (target == NULL && (target = map_id2bl(md->target_id)) == NULL)
return 0;
if (target->prev == NULL || md->bl.prev == NULL)
@@ -3887,91 +3149,32 @@ int mobskill_use_id (struct mob_data *md, struct block_list *target,
skill_id = ms->skill_id;
skill_lv = ms->skill_lv;
- // 沈黙や異常
- if (md->sc_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;
- if (md->sc_data[SC_AUTOCOUNTER].timer != -1 && md->skillid != KN_AUTOCOUNTER) //オートカウンター
- return 0;
- if (md->sc_data[SC_BLADESTOP].timer != -1) //白刃å–ã‚Š
- return 0;
- if (md->sc_data[SC_BERSERK].timer != -1) //ãƒãƒ¼ã‚µãƒ¼ã‚¯
- return 0;
- }
-
- if (md->option & 4 && skill_id == TF_HIDING)
- return 0;
- if (md->option & 2 && skill_id != TF_HIDING && skill_id != AS_GRIMTOOTH
- && skill_id != RG_BACKSTAP && skill_id != RG_RAID)
- return 0;
-
- if (map[md->bl.m].flag.gvg
- && (skill_id == SM_ENDURE || skill_id == AL_TELEPORT
- || skill_id == AL_WARP || skill_id == WZ_ICEWALL
- || skill_id == TF_BACKSLIDING))
+ if (bool(md->opt1))
return 0;
- if (skill_get_inf2 (skill_id) & 0x200 && md->bl.id == target->id)
+ if (skill_get_inf2(skill_id) & 0x200 && md->bl.id == target->id)
return 0;
// 射程ã¨éšœå®³ç‰©ãƒã‚§ãƒƒã‚¯
- range = skill_get_range (skill_id, skill_lv);
+ range = skill_get_range(skill_id, skill_lv);
if (range < 0)
- range = battle_get_range (&md->bl) - (range + 1);
+ range = battle_get_range(&md->bl) - (range + 1);
- if (!battle_check_range (&md->bl, target, range))
+ if (!battle_check_range(&md->bl, target, range))
return 0;
// delay=skill_delayfix(&md->bl, skill_get_delay( skill_id,skill_lv) );
- casttime = skill_castfix (&md->bl, ms->casttime);
+ interval_t casttime = skill_castfix(&md->bl, ms->casttime);
md->state.skillcastcancel = ms->cancel;
- md->skilldelay[skill_idx] = gettick ();
-
- switch (skill_id)
- { /* 何ã‹ç‰¹æ®Šãªå‡¦ç†ãŒå¿…è¦ */
- case ALL_RESURRECTION: /* リザレクション */
- if (target->type != BL_PC
- && battle_check_undead (battle_get_race (target),
- battle_get_elem_type (target)))
- { /* 敵ãŒã‚¢ãƒ³ãƒ‡ãƒƒãƒ‰ãªã‚‰ */
- forcecast = 1; /* ターンアンデットã¨åŒã˜è© å”±æ™‚é–“ */
- casttime =
- skill_castfix (&md->bl,
- skill_get_cast (PR_TURNUNDEAD, skill_lv));
- }
- break;
- case MO_EXTREMITYFIST: /*阿修羅覇鳳拳 */
- case SA_MAGICROD:
- case SA_SPELLBREAKER:
- forcecast = 1;
- break;
- }
+ md->skilldelay[skill_idx] = gettick();
if (battle_config.mob_skill_log == 1)
- printf
- ("MOB skill use target_id=%d skill=%d lv=%d cast=%d, mob_class = %d\n",
- target->id, skill_id, skill_lv, casttime, md->mob_class);
-
- if (casttime > 0 || forcecast)
- { // è© å”±ãŒå¿…è¦
-// struct mob_data *md2;
- clif_skillcasting (&md->bl,
- md->bl.id, target->id, 0, 0, skill_id, casttime);
-
- // è© å”±å応モンスター
-/* if( target->type==BL_MOB && mob_db[(md2=(struct mob_data *)target)->mob_class].mode&0x10 &&
- md2->state.state!=MS_ATTACK){
- md2->target_id=md->bl.id;
- md->state.targettype = ATTACKABLE;
- md2->min_chase=13;
- }*/
- }
+ PRINTF("MOB skill use target_id=%d skill=%d lv=%d cast=%d, mob_class = %d\n",
+ target->id, skill_id, skill_lv,
+ static_cast<uint32_t>(casttime.count()), md->mob_class);
- if (casttime <= 0) // è© å”±ã®ç„¡ã„ã‚‚ã®ã¯ã‚­ãƒ£ãƒ³ã‚»ãƒ«ã•ã‚Œãªã„
+ if (casttime <= interval_t::zero()) // è© å”±ã®ç„¡ã„ã‚‚ã®ã¯ã‚­ãƒ£ãƒ³ã‚»ãƒ«ã•ã‚Œãªã„
md->state.skillcastcancel = 0;
md->skilltarget = target->id;
@@ -3981,20 +3184,16 @@ int mobskill_use_id (struct mob_data *md, struct block_list *target,
md->skilllv = skill_lv;
md->skillidx = skill_idx;
- if (!(battle_config.monster_cloak_check_type & 2)
- && md->sc_data[SC_CLOAKING].timer != -1 && md->skillid != AS_CLOAKING)
- skill_status_change_end (&md->bl, SC_CLOAKING, -1);
-
- if (casttime > 0)
+ if (casttime > interval_t::zero())
{
- md->skilltimer =
- add_timer (gettick () + casttime, mobskill_castend_id, md->bl.id,
- 0);
+ md->skilltimer = Timer(gettick() + casttime,
+ std::bind(mobskill_castend_id, ph::_1, ph::_2,
+ md->bl.id));
}
else
{
- md->skilltimer = -1;
- mobskill_castend_id (md->skilltimer, gettick (), md->bl.id, 0);
+ assert (!md->skilltimer);
+ mobskill_castend_id(nullptr, gettick(), md->bl.id);
}
return 1;
@@ -4005,74 +3204,50 @@ int mobskill_use_id (struct mob_data *md, struct block_list *target,
*------------------------------------------
*/
static
-int mobskill_use_pos (struct mob_data *md,
+int mobskill_use_pos(struct mob_data *md,
int skill_x, int skill_y, int skill_idx)
{
- int casttime = 0, range;
+ int range;
struct mob_skill *ms;
struct block_list bl;
- int skill_id, skill_lv;
+ int skill_lv;
- nullpo_retr (0, md);
- nullpo_retr (0, ms = &mob_db[md->mob_class].skill[skill_idx]);
+ nullpo_ret(md);
+ ms = &mob_db[md->mob_class].skill[skill_idx];
+ nullpo_ret(ms);
if (md->bl.prev == NULL)
return 0;
- skill_id = ms->skill_id;
+ SkillID skill_id = ms->skill_id;
skill_lv = ms->skill_lv;
- //沈黙や状態異常ãªã©
- if (md->sc_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;
- if (md->sc_data[SC_AUTOCOUNTER].timer != -1 && md->skillid != KN_AUTOCOUNTER) //オートカウンター
- return 0;
- if (md->sc_data[SC_BLADESTOP].timer != -1) //白刃å–ã‚Š
- return 0;
- if (md->sc_data[SC_BERSERK].timer != -1) //ãƒãƒ¼ã‚µãƒ¼ã‚¯
- return 0;
- }
-
- if (md->option & 2)
- return 0;
-
- if (map[md->bl.m].flag.gvg
- && (skill_id == SM_ENDURE || skill_id == AL_TELEPORT
- || skill_id == AL_WARP || skill_id == WZ_ICEWALL
- || skill_id == TF_BACKSLIDING))
+ if (bool(md->opt1))
return 0;
// 射程ã¨éšœå®³ç‰©ãƒã‚§ãƒƒã‚¯
- bl.type = BL_NUL;
+ bl.type = BL::NUL;
bl.m = md->bl.m;
bl.x = skill_x;
bl.y = skill_y;
- range = skill_get_range (skill_id, skill_lv);
+ range = skill_get_range(skill_id, skill_lv);
if (range < 0)
- range = battle_get_range (&md->bl) - (range + 1);
- if (!battle_check_range (&md->bl, &bl, range))
+ range = battle_get_range(&md->bl) - (range + 1);
+ if (!battle_check_range(&md->bl, &bl, range))
return 0;
// delay=skill_delayfix(&sd->bl, skill_get_delay( skill_id,skill_lv) );
- casttime = skill_castfix (&md->bl, ms->casttime);
- md->skilldelay[skill_idx] = gettick ();
+ interval_t casttime = skill_castfix(&md->bl, ms->casttime);
+ md->skilldelay[skill_idx] = gettick();
md->state.skillcastcancel = ms->cancel;
if (battle_config.mob_skill_log == 1)
- printf
- ("MOB skill use target_pos=(%d,%d) skill=%d lv=%d cast=%d, mob_class = %d\n",
- skill_x, skill_y, skill_id, skill_lv, casttime, md->mob_class);
-
- if (casttime > 0) // A cast time is required.
- clif_skillcasting (&md->bl,
- md->bl.id, 0, skill_x, skill_y, skill_id,
- casttime);
+ PRINTF("MOB skill use target_pos= (%d,%d) skill=%d lv=%d cast=%d, mob_class = %d\n",
+ skill_x, skill_y, skill_id, skill_lv,
+ static_cast<uint32_t>(casttime.count()), md->mob_class);
- if (casttime <= 0) // A skill without a cast time wont be cancelled.
+ if (casttime <= interval_t::zero())
+ // A skill without a cast time wont be cancelled.
md->state.skillcastcancel = 0;
md->skillx = skill_x;
@@ -4081,238 +3256,94 @@ int mobskill_use_pos (struct mob_data *md,
md->skillid = skill_id;
md->skilllv = skill_lv;
md->skillidx = skill_idx;
- if (!(battle_config.monster_cloak_check_type & 2)
- && md->sc_data[SC_CLOAKING].timer != -1)
- skill_status_change_end (&md->bl, SC_CLOAKING, -1);
- if (casttime > 0)
+ if (casttime > interval_t::zero())
{
- md->skilltimer =
- add_timer (gettick () + casttime, mobskill_castend_pos, md->bl.id,
- 0);
+ md->skilltimer = Timer(gettick() + casttime,
+ std::bind(mobskill_castend_pos, ph::_1, ph::_2,
+ md->bl.id));
}
else
{
- md->skilltimer = -1;
- mobskill_castend_pos (md->skilltimer, gettick (), md->bl.id, 0);
+ assert (!md->skilltimer);
+ mobskill_castend_pos(nullptr, gettick(), md->bl.id);
}
return 1;
}
/*==========================================
- * Friendly Mob whose HP is decreasing by a nearby MOB is looked for.
- *------------------------------------------
- */
-static
-int mob_getfriendhpltmaxrate_sub (struct block_list *bl, va_list ap)
-{
- int rate;
- struct mob_data **fr, *md, *mmd;
-
- nullpo_retr (0, bl);
- nullpo_retr (0, ap);
- nullpo_retr (0, mmd = va_arg (ap, struct mob_data *));
-
- md = (struct mob_data *) bl;
-
- if (mmd->bl.id == bl->id)
- return 0;
- rate = va_arg (ap, int);
- fr = va_arg (ap, struct mob_data **);
- if (md->hp < mob_db[md->mob_class].max_hp * rate / 100)
- (*fr) = md;
- return 0;
-}
-
-static
-struct mob_data *mob_getfriendhpltmaxrate (struct mob_data *md, int rate)
-{
- struct mob_data *fr = NULL;
- const int r = 8;
-
- nullpo_retr (NULL, md);
-
- map_foreachinarea (mob_getfriendhpltmaxrate_sub, md->bl.m,
- md->bl.x - r, md->bl.y - r, md->bl.x + r, md->bl.y + r,
- BL_MOB, md, rate, &fr);
- return fr;
-}
-
-/*==========================================
- * What a status state suits by nearby MOB is looked for.
- *------------------------------------------
- */
-static
-int mob_getfriendstatus_sub (struct block_list *bl, va_list ap)
-{
- int cond1, cond2;
- struct mob_data **fr, *md, *mmd;
- int flag = 0;
-
- nullpo_retr (0, bl);
- nullpo_retr (0, ap);
- nullpo_retr (0, md = (struct mob_data *) bl);
- nullpo_retr (0, mmd = va_arg (ap, struct mob_data *));
-
- if (mmd->bl.id == bl->id)
- return 0;
- cond1 = va_arg (ap, int);
- cond2 = va_arg (ap, int);
- fr = va_arg (ap, struct mob_data **);
- if (cond2 == -1)
- {
- int j;
- for (j = SC_STONE; j <= SC_BLIND && !flag; j++)
- {
- flag = (md->sc_data[j].timer != -1);
- }
- }
- else
- flag = (md->sc_data[cond2].timer != -1);
- if (flag ^ (cond1 == MSC_FRIENDSTATUSOFF))
- (*fr) = md;
-
- return 0;
-}
-
-static
-struct mob_data *mob_getfriendstatus (struct mob_data *md, int cond1,
- int cond2)
-{
- struct mob_data *fr = NULL;
- const int r = 8;
-
- nullpo_retr (0, md);
-
- map_foreachinarea (mob_getfriendstatus_sub, md->bl.m,
- md->bl.x - r, md->bl.y - r, md->bl.x + r, md->bl.y + r,
- BL_MOB, md, cond1, cond2, &fr);
- return fr;
-}
-
-/*==========================================
* Skill use judging
*------------------------------------------
*/
-int mobskill_use (struct mob_data *md, unsigned int tick, int event)
+int mobskill_use(struct mob_data *md, tick_t tick,
+ MobSkillCondition event)
{
struct mob_skill *ms;
// struct block_list *target=NULL;
int max_hp;
- nullpo_retr (0, md);
- nullpo_retr (0, ms = mob_db[md->mob_class].skill);
+ nullpo_ret(md);
+ ms = mob_db[md->mob_class].skill;
+ nullpo_ret(ms);
- max_hp = battle_get_max_hp (&md->bl);
+ max_hp = battle_get_max_hp(&md->bl);
- if (battle_config.mob_skill_use == 0 || md->skilltimer != -1)
+ if (battle_config.mob_skill_use == 0 || md->skilltimer)
return 0;
if (md->state.special_mob_ai)
return 0;
- if (md->sc_data[SC_SELFDESTRUCTION].timer != -1) //自爆中ã¯ã‚¹ã‚­ãƒ«ã‚’使ã‚ãªã„
- return 0;
-
for (int ii = 0; ii < mob_db[md->mob_class].maxskill; ii++)
{
- int c2 = ms[ii].cond2, flag = 0;
- struct mob_data *fmd = NULL;
+ int flag = 0;
// ディレイ中
- if (DIFF_TICK (tick, md->skilldelay[ii]) < ms[ii].delay)
+ if (tick < md->skilldelay[ii] + ms[ii].delay)
continue;
// 状態判定
- if (ms[ii].state >= 0 && ms[ii].state != md->state.skillstate)
+ if (ms[ii].state != MobSkillState::ANY && ms[ii].state != md->state.skillstate)
continue;
- // æ¡ä»¶åˆ¤å®š
+ // Note: these *may* both be MobSkillCondition::ANY
flag = (event == ms[ii].cond1);
if (!flag)
{
switch (ms[ii].cond1)
{
- case MSC_ALWAYS:
+ case MobSkillCondition::MSC_ALWAYS:
flag = 1;
break;
- case MSC_MYHPLTMAXRATE: // HP< maxhp%
- flag = (md->hp < max_hp * c2 / 100);
- break;
- case MSC_MYSTATUSON: // status[num] on
- case MSC_MYSTATUSOFF: // status[num] off
- if (ms[ii].cond2 == -1)
- {
- int j;
- for (j = SC_STONE; j <= SC_BLIND && !flag; j++)
- {
- flag = (md->sc_data[j].timer != -1);
- }
- }
- else
- flag = (md->sc_data[ms[ii].cond2].timer != -1);
- flag ^= (ms[ii].cond1 == MSC_MYSTATUSOFF);
- break;
- case MSC_FRIENDHPLTMAXRATE: // friend HP < maxhp%
- flag =
- ((fmd =
- mob_getfriendhpltmaxrate (md,
- ms[ii].cond2)) != NULL);
- break;
- case MSC_FRIENDSTATUSON: // friend status[num] on
- case MSC_FRIENDSTATUSOFF: // friend status[num] off
- flag =
- ((fmd =
- mob_getfriendstatus (md, ms[ii].cond1,
- ms[ii].cond2)) != NULL);
+ case MobSkillCondition::MSC_MYHPLTMAXRATE: // HP< maxhp%
+ flag = (md->hp < max_hp * ms[ii].cond2i / 100);
break;
- case MSC_NOTINTOWN: // Only outside of towns.
+ case MobSkillCondition::MSC_NOTINTOWN: // Only outside of towns.
flag = !map[md->bl.m].flag.town;
break;
- case MSC_SLAVELT: // slave < num
- flag = (mob_countslave (md) < c2);
+ case MobSkillCondition::MSC_SLAVELT: // slave < num
+ flag = (mob_countslave(md) < ms[ii].cond2i);
break;
- case MSC_ATTACKPCGT: // attack pc > num
- flag = (mob_counttargeted (md, NULL, 0) > c2);
- break;
- case MSC_SLAVELE: // slave <= num
- flag = (mob_countslave (md) <= c2);
- break;
- case MSC_ATTACKPCGE: // attack pc >= num
- flag = (mob_counttargeted (md, NULL, 0) >= c2);
- break;
- case MSC_SKILLUSED: // specificated skill used
- flag = ((event & 0xffff) == MSC_SKILLUSED
- && ((event >> 16) == c2 || c2 == 0));
+ case MobSkillCondition::MSC_SLAVELE: // slave <= num
+ flag = (mob_countslave(md) <= ms[ii].cond2i);
break;
}
}
// 確率判定
- if (flag && MRAND (10000) < ms[ii].permillage)
+ if (flag && random_::chance({ms[ii].permillage, 10000}))
{
- if (skill_get_inf (ms[ii].skill_id) & 2)
+ if (skill_get_inf(ms[ii].skill_id) & 2)
{
// 場所指定
struct block_list *bl = NULL;
- int x = 0, y = 0;
- if (ms[ii].target <= MST_AROUND)
+ int x = 0, y = 0;
{
- if (ms[ii].target == MST_MASTER)
- {
- bl = &md->bl;
- if (md->master_id)
- bl = map_id2bl (md->master_id);
- }
- else
{
- bl = ((ms[ii].target == MST_TARGET
- || ms[ii].target ==
- MST_AROUND5) ? map_id2bl (md->
- target_id)
- : (ms[ii].target ==
- MST_FRIEND) ? &fmd->bl : &md->bl);
+ bl = ms[ii].target == MobSkillTarget::MST_TARGET
+ ? map_id2bl(md->target_id)
+ : &md->bl;
}
if (bl)
@@ -4323,77 +3354,22 @@ int mobskill_use (struct mob_data *md, unsigned int tick, int event)
}
if (x <= 0 || y <= 0)
continue;
- // 自分ã®å‘¨å›²
- if (ms[ii].target >= MST_AROUND1)
- {
- int bx = x, by = y, i = 0, c, m = bl->m, r =
- ms[i].target - MST_AROUND1;
- do
- {
- bx = x + MRAND ((r * 2 + 3)) - r;
- by = y + MRAND ((r * 2 + 3)) - r;
- }
- while ((bx <= 0 || by <= 0 || bx >= map[m].xs
- || by >= map[m].ys
- || ((c = read_gat (m, bx, by)) == 1 || c == 5))
- && (i++) < 1000);
- if (i < 1000)
- {
- x = bx;
- y = by;
- }
- }
- // 相手ã®å‘¨å›²
- if (ms[ii].target >= MST_AROUND5)
- {
- int bx = x, by = y, i = 0, c, m = bl->m, r =
- (ms[i].target - MST_AROUND5) + 1;
- do
- {
- bx = x + MRAND ((r * 2 + 1)) - r;
- by = y + MRAND ((r * 2 + 1)) - r;
- }
- while ((bx <= 0 || by <= 0 || bx >= map[m].xs
- || by >= map[m].ys
- || ((c = read_gat (m, bx, by)) == 1 || c == 5))
- && (i++) < 1000);
- if (i < 1000)
- {
- x = bx;
- y = by;
- }
- }
- if (!mobskill_use_pos (md, x, y, ii))
+ if (!mobskill_use_pos(md, x, y, ii))
return 0;
-
}
else
{
- if (ms[ii].target == MST_MASTER)
- {
- struct block_list *bl = &md->bl;
- if (md->master_id)
- bl = map_id2bl (md->master_id);
-
- if (bl && !mobskill_use_id (md, bl, ii))
- return 0;
- }
- // ID指定
- if (ms[ii].target <= MST_FRIEND)
{
struct block_list *bl = NULL;
- bl = ((ms[ii].target ==
- MST_TARGET) ? map_id2bl (md->
- target_id) : (ms[ii].target
- ==
- MST_FRIEND)
- ? &fmd->bl : &md->bl);
- if (bl && !mobskill_use_id (md, bl, ii))
+ bl = (ms[ii].target == MobSkillTarget::MST_TARGET)
+ ? map_id2bl(md->target_id)
+ : &md->bl;
+ if (bl && !mobskill_use_id(md, bl, ii))
return 0;
}
}
if (ms[ii].emotion >= 0)
- clif_emotion (&md->bl, ms[ii].emotion);
+ clif_emotion(&md->bl, ms[ii].emotion);
return 1;
}
}
@@ -4405,73 +3381,22 @@ int mobskill_use (struct mob_data *md, unsigned int tick, int event)
* Skill use event processing
*------------------------------------------
*/
-int mobskill_event (struct mob_data *md, int flag)
+int mobskill_event(struct mob_data *md, BF flag)
{
- nullpo_retr (0, md);
+ nullpo_ret(md);
- if (flag == -1 && mobskill_use (md, gettick (), MSC_CASTTARGETED))
+ if (flag == BF::NEGATIVE_1
+ && mobskill_use(md, gettick(), MobSkillCondition::ANY))
return 1;
- if ((flag & BF_SHORT)
- && mobskill_use (md, gettick (), MSC_CLOSEDATTACKED))
+ if (bool(flag & BF::SHORT)
+ && mobskill_use(md, gettick(), MobSkillCondition::ANY))
return 1;
- if ((flag & BF_LONG)
- && mobskill_use (md, gettick (), MSC_LONGRANGEATTACKED))
+ if (bool(flag & BF::LONG)
+ && mobskill_use(md, gettick(), MobSkillCondition::ANY))
return 1;
return 0;
}
-/*==========================================
- * MobãŒã‚¨ãƒ³ãƒšãƒªã‚¦ãƒ ãªã©ã®å ´åˆã®åˆ¤å®š
- *------------------------------------------
- */
-int mob_gvmobcheck (struct map_session_data *sd, struct block_list *bl)
-{
- struct mob_data *md = NULL;
-
- nullpo_retr (0, sd);
- nullpo_retr (0, bl);
-
- if (bl->type == BL_MOB && (md = (struct mob_data *) bl) &&
- (md->mob_class == 1288 || md->mob_class == 1287 || md->mob_class == 1286
- || md->mob_class == 1285))
- {
- struct guild_castle *gc = guild_mapname2gc (map[sd->bl.m].name);
- struct guild *g = guild_search (sd->status.guild_id);
-
- if (g == NULL && md->mob_class == 1288)
- return 0; //ギルド未加入ãªã‚‰ãƒ€ãƒ¡ãƒ¼ã‚¸ç„¡ã—
- else if (gc != NULL && !map[sd->bl.m].flag.gvg)
- return 0; //砦内ã§Gvã˜ã‚ƒãªã„ã¨ãã¯ãƒ€ãƒ¡ãƒ¼ã‚¸ãªã—
- else if (g && gc != NULL && g->guild_id == gc->guild_id)
- return 0; //自å é ˜ã‚®ãƒ«ãƒ‰ã®ã‚¨ãƒ³ãƒšãªã‚‰ãƒ€ãƒ¡ãƒ¼ã‚¸ç„¡ã—
- else if (g && guild_checkskill (g, GD_APPROVAL) <= 0
- && md->mob_class == 1288)
- return 0; //æ­£è¦ã‚®ãƒ«ãƒ‰æ‰¿èªãŒãªã„ã¨ãƒ€ãƒ¡ãƒ¼ã‚¸ç„¡ã—
-
- }
-
- return 1;
-}
-
-/*==========================================
- * スキル用タイマー削除
- *------------------------------------------
- */
-int mobskill_deltimer (struct mob_data *md)
-{
- nullpo_retr (0, md);
-
- if (md->skilltimer != -1)
- {
- if (skill_get_inf (md->skillid) & 2)
- delete_timer (md->skilltimer, mobskill_castend_pos);
- else
- delete_timer (md->skilltimer, mobskill_castend_id);
- md->skilltimer = -1;
- }
- return 0;
-}
-
//
// åˆæœŸåŒ–
//
@@ -4479,12 +3404,13 @@ int mobskill_deltimer (struct mob_data *md)
* Since un-setting [ mob ] up was used, it is an initial provisional value setup.
*------------------------------------------
*/
-static int mob_makedummymobdb (int mob_class)
+static
+int mob_makedummymobdb(int mob_class)
{
- int i;
+ int i;
- sprintf (mob_db[mob_class].name, "mob%d", mob_class);
- sprintf (mob_db[mob_class].jname, "mob%d", mob_class);
+ sprintf(mob_db[mob_class].name, "mob%d", mob_class);
+ sprintf(mob_db[mob_class].jname, "mob%d", mob_class);
mob_db[mob_class].lv = 1;
mob_db[mob_class].max_hp = 1000;
mob_db[mob_class].max_sp = 1;
@@ -4495,39 +3421,27 @@ static int mob_makedummymobdb (int mob_class)
mob_db[mob_class].atk2 = 10;
mob_db[mob_class].def = 0;
mob_db[mob_class].mdef = 0;
- mob_db[mob_class].str = 1;
- mob_db[mob_class].agi = 1;
- mob_db[mob_class].vit = 1;
- mob_db[mob_class].int_ = 1;
- mob_db[mob_class].dex = 6;
- mob_db[mob_class].luk = 2;
+ mob_db[mob_class].attrs[ATTR::STR] = 1;
+ mob_db[mob_class].attrs[ATTR::AGI] = 1;
+ mob_db[mob_class].attrs[ATTR::VIT] = 1;
+ mob_db[mob_class].attrs[ATTR::INT] = 1;
+ mob_db[mob_class].attrs[ATTR::DEX] = 6;
+ mob_db[mob_class].attrs[ATTR::LUK] = 2;
mob_db[mob_class].range2 = 10;
mob_db[mob_class].range3 = 10;
- mob_db[mob_class].size = 0;
- mob_db[mob_class].race = 0;
- mob_db[mob_class].element = 0;
- mob_db[mob_class].mode = 0;
+ mob_db[mob_class].size = 0; // 1
+ mob_db[mob_class].race = Race::formless;
+ mob_db[mob_class].element = LevelElement{0, Element::neutral};
+ mob_db[mob_class].mode = MobMode::ZERO;
mob_db[mob_class].speed = 300;
mob_db[mob_class].adelay = 1000;
mob_db[mob_class].amotion = 500;
mob_db[mob_class].dmotion = 500;
- mob_db[mob_class].dropitem[0].nameid = 909; // Jellopy
- mob_db[mob_class].dropitem[0].p = 1000;
- for (i = 1; i < 8; i++)
+ for (i = 0; i < 8; i++)
{
mob_db[mob_class].dropitem[i].nameid = 0;
- mob_db[mob_class].dropitem[i].p = 0;
- }
- // Item1,Item2
- mob_db[mob_class].mexp = 0;
- mob_db[mob_class].mexpper = 0;
- for (i = 0; i < 3; i++)
- {
- mob_db[mob_class].mvpitem[i].nameid = 0;
- mob_db[mob_class].mvpitem[i].p = 0;
+ mob_db[mob_class].dropitem[i].p.num = 0;
}
- for (i = 0; i < MAX_RANDOMMONSTER; i++)
- mob_db[mob_class].summonper[i] = 0;
return 0;
}
@@ -4535,27 +3449,28 @@ static int mob_makedummymobdb (int mob_class)
* db/mob_db.txt reading
*------------------------------------------
*/
-static int mob_readdb (void)
+static
+int mob_readdb(void)
{
FILE *fp;
char line[1024];
const char *filename[] = { "db/mob_db.txt", "db/mob_db2.txt" };
- memset (mob_db, 0, sizeof (mob_db));
+ memset(mob_db, 0, sizeof(mob_db));
for (int j = 0; j < 2; j++)
{
- fp = fopen_ (filename[j], "r");
+ fp = fopen_(filename[j], "r");
if (fp == NULL)
{
if (j > 0)
continue;
return -1;
}
- while (fgets (line, 1020, fp))
+ while (fgets(line, 1020, fp))
{
- int mob_class;
+ int mob_class;
char *str[57], *p, *np;
if (line[0] == '/' && line[1] == '/')
@@ -4566,7 +3481,7 @@ static int mob_readdb (void)
{
while (*p == '\t' || *p == ' ')
p++;
- if ((np = strchr (p, ',')) != NULL)
+ if ((np = strchr(p, ',')) != NULL)
{
str[i] = p;
*np = 0;
@@ -4576,18 +3491,17 @@ static int mob_readdb (void)
str[i] = p;
}
- mob_class = atoi (str[0]);
+ mob_class = atoi(str[0]);
if (mob_class <= 1000 || mob_class > 2000)
continue;
- mob_db[mob_class].view_class = mob_class;
- memcpy (mob_db[mob_class].name, str[1], 24);
- memcpy (mob_db[mob_class].jname, str[2], 24);
- mob_db[mob_class].lv = atoi (str[3]);
- mob_db[mob_class].max_hp = atoi (str[4]);
- mob_db[mob_class].max_sp = atoi (str[5]);
+ memcpy(mob_db[mob_class].name, str[1], 24);
+ memcpy(mob_db[mob_class].jname, str[2], 24);
+ mob_db[mob_class].lv = atoi(str[3]);
+ mob_db[mob_class].max_hp = atoi(str[4]);
+ mob_db[mob_class].max_sp = atoi(str[5]);
- mob_db[mob_class].base_exp = atoi (str[6]);
+ mob_db[mob_class].base_exp = atoi(str[6]);
if (mob_db[mob_class].base_exp < 0)
mob_db[mob_class].base_exp = 0;
else if (mob_db[mob_class].base_exp > 0
@@ -4599,7 +3513,7 @@ static int mob_readdb (void)
else
mob_db[mob_class].base_exp *= battle_config.base_exp_rate / 100;
- mob_db[mob_class].job_exp = atoi (str[7]);
+ mob_db[mob_class].job_exp = atoi(str[7]);
if (mob_db[mob_class].job_exp < 0)
mob_db[mob_class].job_exp = 0;
else if (mob_db[mob_class].job_exp > 0
@@ -4611,85 +3525,39 @@ static int mob_readdb (void)
else
mob_db[mob_class].job_exp *= battle_config.job_exp_rate / 100;
- mob_db[mob_class].range = atoi (str[8]);
- mob_db[mob_class].atk1 = atoi (str[9]);
- mob_db[mob_class].atk2 = atoi (str[10]);
- mob_db[mob_class].def = atoi (str[11]);
- mob_db[mob_class].mdef = atoi (str[12]);
- mob_db[mob_class].str = atoi (str[13]);
- mob_db[mob_class].agi = atoi (str[14]);
- mob_db[mob_class].vit = atoi (str[15]);
- mob_db[mob_class].int_ = atoi (str[16]);
- mob_db[mob_class].dex = atoi (str[17]);
- mob_db[mob_class].luk = atoi (str[18]);
- mob_db[mob_class].range2 = atoi (str[19]);
- mob_db[mob_class].range3 = atoi (str[20]);
- mob_db[mob_class].size = atoi (str[21]);
- mob_db[mob_class].race = atoi (str[22]);
- mob_db[mob_class].element = atoi (str[23]);
- mob_db[mob_class].mode = atoi (str[24]);
- mob_db[mob_class].speed = atoi (str[25]);
- mob_db[mob_class].adelay = atoi (str[26]);
- mob_db[mob_class].amotion = atoi (str[27]);
- mob_db[mob_class].dmotion = atoi (str[28]);
+ mob_db[mob_class].range = atoi(str[8]);
+ mob_db[mob_class].atk1 = atoi(str[9]);
+ mob_db[mob_class].atk2 = atoi(str[10]);
+ mob_db[mob_class].def = atoi(str[11]);
+ mob_db[mob_class].mdef = atoi(str[12]);
+ mob_db[mob_class].attrs[ATTR::STR] = atoi(str[13]);
+ mob_db[mob_class].attrs[ATTR::AGI] = atoi(str[14]);
+ mob_db[mob_class].attrs[ATTR::VIT] = atoi(str[15]);
+ mob_db[mob_class].attrs[ATTR::INT] = atoi(str[16]);
+ mob_db[mob_class].attrs[ATTR::DEX] = atoi(str[17]);
+ mob_db[mob_class].attrs[ATTR::LUK] = atoi(str[18]);
+ mob_db[mob_class].range2 = atoi(str[19]);
+ mob_db[mob_class].range3 = atoi(str[20]);
+ mob_db[mob_class].size = atoi(str[21]); // always 1
+ mob_db[mob_class].race = static_cast<Race>(atoi(str[22]));
+ mob_db[mob_class].element = LevelElement::unpack(atoi(str[23]));
+ mob_db[mob_class].mode = static_cast<MobMode>(atoi(str[24]));
+ mob_db[mob_class].speed = atoi(str[25]);
+ mob_db[mob_class].adelay = atoi(str[26]);
+ mob_db[mob_class].amotion = atoi(str[27]);
+ mob_db[mob_class].dmotion = atoi(str[28]);
for (int i = 0; i < 8; i++)
{
- int rate = 0, type, ratemin, ratemax;
- mob_db[mob_class].dropitem[i].nameid = atoi (str[29 + i * 2]);
- type = itemdb_type (mob_db[mob_class].dropitem[i].nameid);
- if (type == 0)
- { // Added [Valaris]
- rate = battle_config.item_rate_heal;
- ratemin = battle_config.item_drop_heal_min;
- ratemax = battle_config.item_drop_heal_max;
- }
- else if (type == 2)
- {
- rate = battle_config.item_rate_use;
- ratemin = battle_config.item_drop_use_min;
- ratemax = battle_config.item_drop_use_max; // End
- }
- else if (type == 4 || type == 5 || type == 8)
- {
- rate = battle_config.item_rate_equip;
- ratemin = battle_config.item_drop_equip_min;
- ratemax = battle_config.item_drop_equip_max;
- }
- else if (type == 6)
- {
- rate = battle_config.item_rate_card;
- ratemin = battle_config.item_drop_card_min;
- ratemax = battle_config.item_drop_card_max;
- }
- else
- {
- rate = battle_config.item_rate_common;
- ratemin = battle_config.item_drop_common_min;
- ratemax = battle_config.item_drop_common_max;
- }
- rate = (rate / 100) * atoi (str[30 + i * 2]);
- rate =
- (rate < ratemin) ? ratemin : (rate >
- ratemax) ? ratemax : rate;
- mob_db[mob_class].dropitem[i].p = rate;
+ mob_db[mob_class].dropitem[i].nameid = atoi(str[29 + i * 2]);
+ int rate = atoi(str[30 + i * 2]);
+ if (rate < 1) rate = 1;
+ if (rate > 10000) rate = 10000;
+ mob_db[mob_class].dropitem[i].p.num = rate;
}
- // Item1,Item2
- mob_db[mob_class].mexp =
- atoi (str[45]) * battle_config.mvp_exp_rate / 100;
- mob_db[mob_class].mexpper = atoi (str[46]);
- for (int i = 0; i < 3; i++)
- {
- mob_db[mob_class].mvpitem[i].nameid = atoi (str[47 + i * 2]);
- mob_db[mob_class].mvpitem[i].p =
- atoi (str[48 + i * 2]) * battle_config.mvp_item_rate /
- 100;
- }
- mob_db[mob_class].mutations_nr = atoi (str[55]);
- mob_db[mob_class].mutation_power = atoi (str[56]);
+ mob_db[mob_class].mutations_nr = atoi(str[55]);
+ mob_db[mob_class].mutation_power = atoi(str[56]);
- for (int i = 0; i < MAX_RANDOMMONSTER; i++)
- mob_db[mob_class].summonper[i] = 0;
mob_db[mob_class].maxskill = 0;
mob_db[mob_class].sex = 0;
@@ -4703,136 +3571,10 @@ static int mob_readdb (void)
mob_db[mob_class].clothes_color = 0; //Add for player monster dye - Valaris
if (mob_db[mob_class].base_exp == 0)
- mob_db[mob_class].base_exp = mob_gen_exp (&mob_db[mob_class]);
+ mob_db[mob_class].base_exp = mob_gen_exp(&mob_db[mob_class]);
}
- fclose_ (fp);
- printf ("read %s done\n", filename[j]);
- }
- return 0;
-}
-
-/*==========================================
- * MOB display graphic change data reading
- *------------------------------------------
- */
-static int mob_readdb_mobavail (void)
-{
- FILE *fp;
- char line[1024];
- int ln = 0;
- int mob_class, j, k;
- char *str[20], *p, *np;
-
- if ((fp = fopen_ ("db/mob_avail.txt", "r")) == NULL)
- {
- printf ("can't read db/mob_avail.txt\n");
- return -1;
- }
-
- while (fgets (line, 1020, fp))
- {
- if (line[0] == '/' && line[1] == '/')
- continue;
- memset (str, 0, sizeof (str));
-
- for (j = 0, p = line; j < 12; j++)
- {
- if ((np = strchr (p, ',')) != NULL)
- {
- str[j] = p;
- *np = 0;
- p = np + 1;
- }
- else
- str[j] = p;
- }
-
- if (str[0] == NULL)
- continue;
-
- mob_class = atoi (str[0]);
-
- if (mob_class <= 1000 || mob_class > 2000) // 値ãŒç•°å¸¸ãªã‚‰å‡¦ç†ã—ãªã„。
- continue;
- k = atoi (str[1]);
- if (k >= 0)
- mob_db[mob_class].view_class = k;
-
- if ((mob_db[mob_class].view_class < 24)
- || (mob_db[mob_class].view_class > 4000))
- {
- mob_db[mob_class].sex = atoi (str[2]);
- mob_db[mob_class].hair = atoi (str[3]);
- mob_db[mob_class].hair_color = atoi (str[4]);
- mob_db[mob_class].weapon = atoi (str[5]);
- mob_db[mob_class].shield = atoi (str[6]);
- mob_db[mob_class].head_top = atoi (str[7]);
- mob_db[mob_class].head_mid = atoi (str[8]);
- mob_db[mob_class].head_buttom = atoi (str[9]);
- mob_db[mob_class].option = atoi (str[10]) & ~0x46;
- mob_db[mob_class].clothes_color = atoi (str[11]); // Monster player dye option - Valaris
- }
-
- else if (atoi (str[2]) > 0)
- mob_db[mob_class].equip = atoi (str[2]); // mob equipment [Valaris]
-
- ln++;
- }
- fclose_ (fp);
- printf ("read db/mob_avail.txt done (count=%d)\n", ln);
- return 0;
-}
-
-/*==========================================
- * Reading of random monster data
- *------------------------------------------
- */
-static int mob_read_randommonster (void)
-{
- FILE *fp;
- char line[1024];
- char *str[10], *p;
- int i, j;
-
- const char *mobfile[] = {
- "db/mob_branch.txt",
- "db/mob_poring.txt",
- "db/mob_boss.txt"
- };
-
- for (i = 0; i < MAX_RANDOMMONSTER; i++)
- {
- mob_db[0].summonper[i] = 1002; // 設定ã—忘れãŸå ´åˆã¯ãƒãƒªãƒ³ãŒå‡ºã‚‹ã‚ˆã†ã«ã—ã¦ãŠã
- fp = fopen_ (mobfile[i], "r");
- if (fp == NULL)
- {
- printf ("can't read %s\n", mobfile[i]);
- return -1;
- }
- while (fgets (line, 1020, fp))
- {
- int mob_class, per;
- if (line[0] == '/' && line[1] == '/')
- continue;
- memset (str, 0, sizeof (str));
- for (j = 0, p = line; j < 3 && p; j++)
- {
- str[j] = p;
- p = strchr (p, ',');
- if (p)
- *p++ = 0;
- }
-
- if (str[0] == NULL || str[2] == NULL)
- continue;
-
- mob_class = atoi (str[0]);
- per = atoi (str[2]);
- if ((mob_class > 1000 && mob_class <= 2000) || mob_class == 0)
- mob_db[mob_class].summonper[i] = per;
- }
- fclose_ (fp);
- printf ("read %s done\n", mobfile[i]);
+ fclose_(fp);
+ PRINTF("read %s done\n", filename[j]);
}
return 0;
}
@@ -4841,221 +3583,144 @@ static int mob_read_randommonster (void)
* db/mob_skill_db.txt reading
*------------------------------------------
*/
-static int mob_readskilldb (void)
+static
+int mob_readskilldb(void)
{
FILE *fp;
char line[1024];
- int i;
+ int i;
const struct
{
char str[32];
- int id;
+ MobSkillCondition id;
} cond1[] =
{
- {
- "always", MSC_ALWAYS},
- {
- "myhpltmaxrate", MSC_MYHPLTMAXRATE},
- {
- "friendhpltmaxrate", MSC_FRIENDHPLTMAXRATE},
- {
- "mystatuson", MSC_MYSTATUSON},
- {
- "mystatusoff", MSC_MYSTATUSOFF},
- {
- "friendstatuson", MSC_FRIENDSTATUSON},
- {
- "friendstatusoff", MSC_FRIENDSTATUSOFF},
- {
- "notintown", MSC_NOTINTOWN},
- {
- "attackpcgt", MSC_ATTACKPCGT},
- {
- "attackpcge", MSC_ATTACKPCGE},
- {
- "slavelt", MSC_SLAVELT},
- {
- "slavele", MSC_SLAVELE},
- {
- "closedattacked", MSC_CLOSEDATTACKED},
- {
- "longrangeattacked", MSC_LONGRANGEATTACKED},
- {
- "skillused", MSC_SKILLUSED},
- {
- "casttargeted", MSC_CASTTARGETED},}, cond2[] =
+ {"always", MobSkillCondition::MSC_ALWAYS},
+ {"myhpltmaxrate", MobSkillCondition::MSC_MYHPLTMAXRATE},
+ {"notintown", MobSkillCondition::MSC_NOTINTOWN},
+ {"slavelt", MobSkillCondition::MSC_SLAVELT},
+ {"slavele", MobSkillCondition::MSC_SLAVELE},
+ };
+ const struct
{
- {
- "anybad", -1},
- {
- "stone", SC_STONE},
- {
- "freeze", SC_FREEZE},
- {
- "stan", SC_STAN},
- {
- "sleep", SC_SLEEP},
- {
- "poison", SC_POISON},
- {
- "curse", SC_CURSE},
- {
- "silence", SC_SILENCE},
- {
- "confusion", SC_CONFUSION},
- {
- "blind", SC_BLIND},
- {
- "hiding", SC_HIDING},
- {
- "sight", SC_SIGHT},}, state[] =
+ char str[32];
+ MobSkillState id;
+ } state[] =
{
- {
- "any", -1},
- {
- "idle", MSS_IDLE},
- {
- "walk", MSS_WALK},
- {
- "attack", MSS_ATTACK},
- {
- "dead", MSS_DEAD},
- {
- "loot", MSS_LOOT},
- {
- "chase", MSS_CHASE},}, target[] =
+ {"any", MobSkillState::ANY},
+ {"idle", MobSkillState::MSS_IDLE},
+ {"walk", MobSkillState::MSS_WALK},
+ {"attack", MobSkillState::MSS_ATTACK},
+ };
+ const struct
{
- {
- "target", MST_TARGET},
- {
- "self", MST_SELF},
- {
- "friend", MST_FRIEND},
- {
- "master", MST_MASTER},
- {
- "around5", MST_AROUND5},
- {
- "around6", MST_AROUND6},
- {
- "around7", MST_AROUND7},
- {
- "around8", MST_AROUND8},
- {
- "around1", MST_AROUND1},
- {
- "around2", MST_AROUND2},
- {
- "around3", MST_AROUND3},
- {
- "around4", MST_AROUND4},
- {
- "around", MST_AROUND},};
+ char str[32];
+ MobSkillTarget id;
+ } target[] =
+ {
+ {"target", MobSkillTarget::MST_TARGET},
+ {"self", MobSkillTarget::MST_SELF},
+ };
- int x;
+ int x;
const char *filename[] = { "db/mob_skill_db.txt", "db/mob_skill_db2.txt" };
for (x = 0; x < 2; x++)
{
- fp = fopen_ (filename[x], "r");
+ fp = fopen_(filename[x], "r");
if (fp == NULL)
{
if (x == 0)
- printf ("can't read %s\n", filename[x]);
+ PRINTF("can't read %s\n", filename[x]);
continue;
}
- while (fgets (line, 1020, fp))
+ while (fgets(line, 1020, fp))
{
char *sp[20], *p;
- int mob_id;
- struct mob_skill *ms;
- int j = 0;
+ int mob_id;
+ // always initialized, but clang is not smart enough yet
+ struct mob_skill *ms = nullptr;
+ int j = 0;
if (line[0] == '/' && line[1] == '/')
continue;
- memset (sp, 0, sizeof (sp));
+ memset(sp, 0, sizeof(sp));
for (i = 0, p = line; i < 18 && p; i++)
{
sp[i] = p;
- if ((p = strchr (p, ',')) != NULL)
+ if ((p = strchr(p, ',')) != NULL)
*p++ = 0;
}
- if ((mob_id = atoi (sp[0])) <= 0)
+ if ((mob_id = atoi(sp[0])) <= 0)
continue;
- if (strcmp (sp[1], "clear") == 0)
+ if (strcmp(sp[1], "clear") == 0)
{
- memset (mob_db[mob_id].skill, 0,
- sizeof (mob_db[mob_id].skill));
+ memset(mob_db[mob_id].skill, 0,
+ sizeof(mob_db[mob_id].skill));
mob_db[mob_id].maxskill = 0;
continue;
}
for (i = 0; i < MAX_MOBSKILL; i++)
- if ((ms = &mob_db[mob_id].skill[i])->skill_id == 0)
+ if ((ms = &mob_db[mob_id].skill[i])->skill_id == SkillID::ZERO)
break;
if (i == MAX_MOBSKILL)
{
- printf
- ("mob_skill: readdb: too many skill ! [%s] in %d[%s]\n",
+ PRINTF("mob_skill: readdb: too many skill ! [%s] in %d[%s]\n",
sp[1], mob_id, mob_db[mob_id].jname);
continue;
}
- ms->state = atoi (sp[2]);
- for (j = 0; j < sizeof (state) / sizeof (state[0]); j++)
+ ms->state = static_cast<MobSkillState>(atoi(sp[2]));
+ for (j = 0; j < sizeof(state) / sizeof(state[0]); j++)
{
- if (strcmp (sp[2], state[j].str) == 0)
+ if (strcmp(sp[2], state[j].str) == 0)
ms->state = state[j].id;
}
- ms->skill_id = atoi (sp[3]);
- ms->skill_lv = atoi (sp[4]);
-
- ms->permillage = atoi (sp[5]);
- ms->casttime = atoi (sp[6]);
- ms->delay = atoi (sp[7]);
- ms->cancel = atoi (sp[8]);
- if (strcmp (sp[8], "yes") == 0)
+ ms->skill_id = SkillID(atoi(sp[3]));
+ ms->skill_lv = atoi(sp[4]);
+
+ ms->permillage = atoi(sp[5]);
+ ms->casttime = static_cast<interval_t>(atoi(sp[6]));
+ ms->delay = static_cast<interval_t>(atoi(sp[7]));
+ ms->cancel = atoi(sp[8]);
+ if (strcmp(sp[8], "yes") == 0)
ms->cancel = 1;
- ms->target = atoi (sp[9]);
- for (j = 0; j < sizeof (target) / sizeof (target[0]); j++)
+ ms->target = static_cast<MobSkillTarget>(atoi(sp[9]));
+ for (j = 0; j < sizeof(target) / sizeof(target[0]); j++)
{
- if (strcmp (sp[9], target[j].str) == 0)
+ if (strcmp(sp[9], target[j].str) == 0)
ms->target = target[j].id;
}
- ms->cond1 = -1;
- for (j = 0; j < sizeof (cond1) / sizeof (cond1[0]); j++)
+ ms->cond1 = MobSkillCondition::ANY;
+ for (j = 0; j < sizeof(cond1) / sizeof(cond1[0]); j++)
{
- if (strcmp (sp[10], cond1[j].str) == 0)
+ if (strcmp(sp[10], cond1[j].str) == 0)
ms->cond1 = cond1[j].id;
}
- ms->cond2 = atoi (sp[11]);
- for (j = 0; j < sizeof (cond2) / sizeof (cond2[0]); j++)
- {
- if (strcmp (sp[11], cond2[j].str) == 0)
- ms->cond2 = cond2[j].id;
- }
- ms->val[0] = atoi (sp[12]);
- ms->val[1] = atoi (sp[13]);
- ms->val[2] = atoi (sp[14]);
- ms->val[3] = atoi (sp[15]);
- ms->val[4] = atoi (sp[16]);
- if (sp[17] != NULL && strlen (sp[17]) > 2)
- ms->emotion = atoi (sp[17]);
+ ms->cond2i = atoi(sp[11]);
+ ms->val[0] = atoi(sp[12]);
+ ms->val[1] = atoi(sp[13]);
+ ms->val[2] = atoi(sp[14]);
+ ms->val[3] = atoi(sp[15]);
+ ms->val[4] = atoi(sp[16]);
+ if (sp[17] != NULL && strlen(sp[17]) > 2)
+ ms->emotion = atoi(sp[17]);
else
ms->emotion = -1;
mob_db[mob_id].maxskill = i + 1;
}
- fclose_ (fp);
- printf ("read %s done\n", filename[x]);
+ fclose_(fp);
+ PRINTF("read %s done\n", filename[x]);
}
return 0;
}
-void mob_reload (void)
+void mob_reload(void)
{
/*
*
@@ -5064,25 +3729,27 @@ void mob_reload (void)
*
*/
- do_init_mob ();
+ do_init_mob();
}
/*==========================================
* Circumference initialization of mob
*------------------------------------------
*/
-int do_init_mob (void)
+int do_init_mob(void)
{
- mob_readdb ();
+ mob_readdb();
- mob_readdb_mobavail ();
- mob_read_randommonster ();
- mob_readskilldb ();
+ mob_readskilldb();
- 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,
- MIN_MOBTHINKTIME * 10);
+ Timer(gettick() + MIN_MOBTHINKTIME,
+ mob_ai_hard,
+ MIN_MOBTHINKTIME
+ ).detach();
+ Timer(gettick() + MIN_MOBTHINKTIME * 10,
+ mob_ai_lazy,
+ MIN_MOBTHINKTIME * 10
+ ).detach();
return 0;
}
diff --git a/src/map/mob.hpp b/src/map/mob.hpp
index 19addf2..16715c4 100644
--- a/src/map/mob.hpp
+++ b/src/map/mob.hpp
@@ -1,151 +1,105 @@
-// $Id: mob.h,v 1.4 2004/09/25 05:32:18 MouseJstr Exp $
#ifndef MOB_HPP
#define MOB_HPP
-#include "../common/timer.hpp"
-#define MAX_RANDOMMONSTER 3
+
+#include "mob.t.hpp"
+
+#include "../common/mmo.hpp"
+#include "../common/timer.t.hpp"
+#include "../common/random.t.hpp"
+
+#include "clif.t.hpp"
+#include "map.hpp"
+#include "skill.t.hpp"
struct mob_skill
{
- short state;
- short skill_id, skill_lv;
+ MobSkillState state;
+ SkillID skill_id;
+ short skill_lv;
short permillage;
- int casttime, delay;
+ interval_t casttime, delay;
short cancel;
- short cond1, cond2;
- short target;
- int val[5];
+ MobSkillCondition cond1;
+ int cond2i;
+ MobSkillTarget target;
+ int val[5];
short emotion;
};
struct mob_db
{
char name[24], jname[24];
- int lv;
- int max_hp, max_sp;
- int base_exp, job_exp;
- int atk1, atk2;
- int def, mdef;
- int str, agi, vit, int_, dex, luk;
- int range, range2, range3;
- int size, race, element, mode;
- int speed, adelay, amotion, dmotion;
- int mexp, mexpper;
- int mutations_nr, mutation_power;
+ int lv;
+ int max_hp, max_sp;
+ int base_exp, job_exp;
+ int atk1, atk2;
+ int def, mdef;
+ earray<int, ATTR, ATTR::COUNT> attrs;
+ int range, range2, range3;
+ // always 1
+ int size;
+ Race race;
+ LevelElement element;
+ MobMode mode;
+ int speed, adelay, amotion, dmotion;
+ int mutations_nr, mutation_power;
struct
{
- int nameid, p;
+ int nameid;
+ random_::Fixed<int, 10000> p;
} dropitem[8];
- struct
- {
- int nameid, p;
- } mvpitem[3];
- int view_class, sex;
+ int sex;
short hair, hair_color, weapon, shield, head_top, head_mid, head_buttom, option, clothes_color; // [Valaris]
- int equip; // [Valaris]
- int summonper[MAX_RANDOMMONSTER];
- int maxskill;
+ int equip; // [Valaris]
+ int maxskill;
struct mob_skill skill[MAX_MOBSKILL];
};
extern struct mob_db mob_db[];
-enum
-{
- MST_TARGET = 0,
- MST_SELF,
- MST_FRIEND,
- MST_MASTER,
- MST_AROUND5,
- MST_AROUND6,
- MST_AROUND7,
- MST_AROUND8,
- MST_AROUND1,
- MST_AROUND2,
- MST_AROUND3,
- MST_AROUND4,
- MST_AROUND = MST_AROUND4,
-
- MSC_ALWAYS = 0x0000,
- MSC_MYHPLTMAXRATE = 0x0001,
- MSC_FRIENDHPLTMAXRATE = 0x0010,
- MSC_MYSTATUSON = 0x0020,
- MSC_MYSTATUSOFF = 0x0021,
- MSC_FRIENDSTATUSON = 0x0030,
- MSC_FRIENDSTATUSOFF = 0x0031,
- MSC_NOTINTOWN = 0x0032,
-
- MSC_ATTACKPCGT = 0x0100,
- MSC_ATTACKPCGE = 0x0101,
- MSC_SLAVELT = 0x0110,
- MSC_SLAVELE = 0x0111,
- MSC_CLOSEDATTACKED = 0x1000,
- MSC_LONGRANGEATTACKED = 0x1001,
- MSC_SKILLUSED = 0x1010,
- MSC_CASTTARGETED = 0x1011,
-};
-
-enum
-{
- MSS_IDLE, // å¾…æ©Ÿ
- MSS_WALK, // 移動
- MSS_ATTACK, // 攻撃
- MSS_DEAD, // 死亡
- MSS_LOOT, // ルート
- MSS_CHASE, // çªæ’ƒ
-};
-
-int mobdb_searchname (const char *str);
-int mobdb_checkid (const int id);
-int mob_once_spawn (struct map_session_data *sd, const char *mapname,
- int x, int y, const char *mobname, int class_, int amount,
- const char *event);
-int mob_once_spawn_area (struct map_session_data *sd, const char *mapname, int x0,
- int y0, int x1, int y1, const char *mobname,
- int class_, int amount, const char *event);
-
-int mob_spawn_guardian (struct map_session_data *sd, const char *mapname, // Spawning Guardians [Valaris]
- int x, int y, const char *mobname, int class_, int amount, const char *event, int guardian); // Spawning Guardians [Valaris]
-
-int mob_walktoxy (struct mob_data *md, int x, int y, int easy);
-
-int mob_target (struct mob_data *md, struct block_list *bl, int dist);
-int mob_stop_walking (struct mob_data *md, int type);
-int mob_stopattack (struct mob_data *);
-int mob_spawn (int);
-int mob_damage (struct block_list *, struct mob_data *, int, int);
-int mob_changestate (struct mob_data *md, int state, int type);
-int mob_heal (struct mob_data *, int);
-int mob_get_viewclass (int);
-int mob_get_sex (int);
-short mob_get_hair (int);
-short mob_get_hair_color (int);
-short mob_get_weapon (int);
-short mob_get_shield (int);
-short mob_get_head_top (int);
-short mob_get_head_mid (int);
-short mob_get_head_buttom (int);
-short mob_get_clothes_color (int); //player mob dye [Valaris]
-int mob_get_equip (int); // mob equip [Valaris]
-int do_init_mob (void);
-
-int mob_delete (struct mob_data *md);
-int mob_catch_delete (struct mob_data *md, int type);
-void mob_timer_delete (timer_id, tick_t, custom_id_t, custom_data_t);
-
-int mob_deleteslave (struct mob_data *md);
-
-int mob_counttargeted (struct mob_data *md, struct block_list *src,
- int target_lv);
-
-int mob_class_change (struct mob_data *md, int *value);
-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);
-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);
-void mob_reload (void);
-
-#endif
+int mobdb_searchname(const char *str);
+int mobdb_checkid(const int id);
+int mob_once_spawn(struct map_session_data *sd,
+ const char *mapname, int x, int y,
+ const char *mobname, int class_, int amount, const char *event);
+int mob_once_spawn_area(struct map_session_data *sd,
+ const char *mapname, int x0, int y0, int x1, int y1,
+ const char *mobname, int class_, int amount, const char *event);
+
+int mob_target(struct mob_data *md, struct block_list *bl, int dist);
+int mob_stop_walking(struct mob_data *md, int type);
+int mob_stopattack(struct mob_data *);
+int mob_spawn(int);
+int mob_damage(struct block_list *, struct mob_data *, int, int);
+int mob_heal(struct mob_data *, int);
+int mob_get_sex(int);
+short mob_get_hair(int);
+short mob_get_hair_color(int);
+short mob_get_weapon(int);
+short mob_get_shield(int);
+short mob_get_head_top(int);
+short mob_get_head_mid(int);
+short mob_get_head_buttom(int);
+short mob_get_clothes_color(int); //player mob dye [Valaris]
+int mob_get_equip(int); // mob equip [Valaris]
+int do_init_mob(void);
+
+int mob_delete(struct mob_data *md);
+int mob_catch_delete(struct mob_data *md, BeingRemoveWhy type);
+void mob_timer_delete(TimerData *, tick_t, int);
+
+int mob_deleteslave(struct mob_data *md);
+
+int mob_counttargeted(struct mob_data *md, struct block_list *src,
+ ATK target_lv);
+
+int mob_warp(struct mob_data *md, int m, int x, int y, BeingRemoveWhy type);
+
+int mobskill_use(struct mob_data *md, tick_t tick, MobSkillCondition event);
+int mobskill_event(struct mob_data *md, BF flag);
+void mobskill_castend_id(TimerData *tid, tick_t tick, int id);
+void mobskill_castend_pos(TimerData *tid, tick_t tick, int id);
+int mob_summonslave(struct mob_data *md2, int *value, int amount, int flag);
+
+void mob_reload(void);
+
+#endif // MOB_HPP
diff --git a/src/map/mob.t.hpp b/src/map/mob.t.hpp
new file mode 100644
index 0000000..b112c69
--- /dev/null
+++ b/src/map/mob.t.hpp
@@ -0,0 +1,41 @@
+#ifndef MOB_T_HPP
+#define MOB_T_HPP
+
+#include <cstdint>
+
+enum class MobSkillTarget
+{
+ MST_TARGET = 0,
+ MST_SELF,
+};
+
+/// Used as a condition when trying to apply the chosen mob skill.
+enum class MobSkillCondition : uint16_t
+{
+ // used as something that never compares true
+ NEVER_EQUAL = 0xfffe,
+ ANY = 0xffff,
+
+ MSC_ALWAYS = 0x0000,
+ MSC_MYHPLTMAXRATE = 0x0001,
+
+ MSC_NOTINTOWN = 0x0032,
+
+ MSC_SLAVELT = 0x0110,
+ MSC_SLAVELE = 0x0111,
+};
+
+/// Used as a filter when trying to choose a mob skill to use.
+enum class MobSkillState : uint8_t
+{
+ ANY = 0xff,
+
+ MSS_IDLE = 0,
+ MSS_WALK,
+ MSS_ATTACK,
+ MSS_DEAD,
+ MSS_LOOT,
+ MSS_CHASE,
+};
+
+#endif // MOB_T_HPP
diff --git a/src/map/npc.cpp b/src/map/npc.cpp
index c25f585..c08a0e7 100644
--- a/src/map/npc.cpp
+++ b/src/map/npc.cpp
@@ -1,30 +1,26 @@
-// $Id: npc.c,v 1.5 2004/09/25 05:32:18 MouseJstr Exp $
-#include <stdio.h>
-#include <stdlib.h>
-#include <ctype.h>
-#include <string.h>
-#include <math.h>
-#include <time.h>
+#include "npc.hpp"
+
+#include <cassert>
+#include <cstdlib>
+#include <cstring>
+#include <ctime>
+#include "../common/cxxstdio.hpp"
+#include "../common/db.hpp"
#include "../common/nullpo.hpp"
+#include "../common/socket.hpp"
#include "../common/timer.hpp"
#include "battle.hpp"
#include "clif.hpp"
-#include "../common/db.hpp"
-#include "intif.hpp"
#include "itemdb.hpp"
#include "map.hpp"
#include "mob.hpp"
-#include "npc.hpp"
#include "pc.hpp"
#include "script.hpp"
#include "skill.hpp"
-#include "../common/socket.hpp"
-#ifdef MEMWATCH
-#include "memwatch.hpp"
-#endif
+#include "../poison.hpp"
struct npc_src_list
{
@@ -33,24 +29,30 @@ struct npc_src_list
char name[4];
};
-static struct npc_src_list *npc_src_first, *npc_src_last;
-static int npc_id = START_NPC_NUM;
-static int npc_warp, npc_shop, npc_script, npc_mob;
+static
+struct npc_src_list *npc_src_first, *npc_src_last;
+static
+int npc_id = START_NPC_NUM;
+static
+int npc_warp, npc_shop, npc_script, npc_mob;
-int npc_get_new_npc_id (void)
+int npc_get_new_npc_id(void)
{
return npc_id++;
}
-static struct dbt *ev_db;
-static struct dbt *npcname_db;
-
struct event_data
{
struct npc_data *nd;
- int pos;
+ int pos;
};
-static struct tm ev_tm_b; // 時計イベント用
+static
+Map<std::string, struct event_data> ev_db;
+static
+DMap<std::string, struct npc_data *> npcname_db;
+
+static
+struct tm ev_tm_b; // 時計イベント用
/*==========================================
* NPCã®ç„¡åŠ¹åŒ–/有効化
@@ -59,63 +61,48 @@ static struct tm ev_tm_b; // 時計イベント用
*------------------------------------------
*/
static
-int npc_enable_sub (struct block_list *bl, va_list ap)
+void npc_enable_sub(struct block_list *bl, struct npc_data *nd)
{
struct map_session_data *sd;
- struct npc_data *nd;
- char *name = (char *) calloc (50, sizeof (char));
+ char *name = (char *) calloc(50, sizeof(char));
+
+ nullpo_retv(bl);
- nullpo_retr (0, bl);
- nullpo_retr (0, ap);
- nullpo_retr (0, nd = va_arg (ap, struct npc_data *));
- if (bl->type == BL_PC && (sd = (struct map_session_data *) bl))
+ if (bl->type == BL::PC && (sd = (struct map_session_data *) bl))
{
if (nd->flag & 1) // 無効化ã•ã‚Œã¦ã„ã‚‹
- return 1;
+ return;
- memcpy (name, nd->name, sizeof(nd->name));
+ memcpy(name, nd->name, sizeof(nd->name));
if (sd->areanpc_id == nd->bl.id)
- return 1;
+ return; // TODO fix leak of 'name'
sd->areanpc_id = nd->bl.id;
- npc_event (sd, strcat (name, "::OnTouch"), 0);
+ npc_event(sd, strcat(name, "::OnTouch"), 0);
}
- free (name);
- return 0;
+ free(name);
}
-int npc_enable (const char *name, int flag)
+int npc_enable(const char *name, bool flag)
{
- struct npc_data *nd = (struct npc_data *)strdb_search (npcname_db, name);
+ struct npc_data *nd = npcname_db.get(name);
if (nd == NULL)
return 0;
- if (flag & 1)
+ if (flag)
{ // 有効化
nd->flag &= ~1;
- clif_spawnnpc (nd);
- }
- else if (flag & 2)
- {
- nd->flag &= ~1;
- nd->option = 0x0000;
- clif_changeoption (&nd->bl);
- }
- else if (flag & 4)
- {
- nd->flag |= 1;
- nd->option = 0x0002;
- clif_changeoption (&nd->bl);
+ clif_spawnnpc(nd);
}
else
{ // 無効化
nd->flag |= 1;
- clif_clearchar (&nd->bl, 0);
+ clif_clearchar(&nd->bl, BeingRemoveWhy::GONE);
}
- if (flag & 3 && (nd->u.scr.xs > 0 || nd->u.scr.ys > 0))
- map_foreachinarea (npc_enable_sub, nd->bl.m, nd->bl.x - nd->u.scr.xs,
- nd->bl.y - nd->u.scr.ys, nd->bl.x + nd->u.scr.xs,
- nd->bl.y + nd->u.scr.ys, BL_PC, nd);
+ if (flag && (nd->u.scr.xs > 0 || nd->u.scr.ys > 0))
+ map_foreachinarea(std::bind(npc_enable_sub, ph::_1, nd),
+ nd->bl.m, nd->bl.x - nd->u.scr.xs, nd->bl.y - nd->u.scr.ys,
+ nd->bl.x + nd->u.scr.xs, nd->bl.y + nd->u.scr.ys, BL::PC);
return 0;
}
@@ -124,32 +111,32 @@ int npc_enable (const char *name, int flag)
* NPCã‚’åå‰ã§æŽ¢ã™
*------------------------------------------
*/
-struct npc_data *npc_name2id (const char *name)
+struct npc_data *npc_name2id(const char *name)
{
- return (struct npc_data *)strdb_search (npcname_db, name);
+ return npcname_db.get(name);
}
/*==========================================
* イベントキューã®ã‚¤ãƒ™ãƒ³ãƒˆå‡¦ç†
*------------------------------------------
*/
-int npc_event_dequeue (struct map_session_data *sd)
+int npc_event_dequeue(struct map_session_data *sd)
{
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
sd->npc_id = 0;
if (sd->eventqueue[0][0]) // キューã®ã‚¤ãƒ™ãƒ³ãƒˆå‡¦ç†
{
- if (!pc_addeventtimer(sd, 100, sd->eventqueue[0]))
+ if (!pc_addeventtimer(sd, std::chrono::milliseconds(100), sd->eventqueue[0]))
{
- printf ("npc_event_dequeue(): Event timer is full.\n");
+ PRINTF("npc_event_dequeue(): Event timer is full.\n");
return 0;
}
if (MAX_EVENTQUEUE > 1)
- memmove (sd->eventqueue[0], sd->eventqueue[1],
- (MAX_EVENTQUEUE - 1) * sizeof (sd->eventqueue[0]));
+ memmove(sd->eventqueue[0], sd->eventqueue[1],
+ (MAX_EVENTQUEUE - 1) * sizeof(sd->eventqueue[0]));
sd->eventqueue[MAX_EVENTQUEUE - 1][0] = '\0';
return 1;
}
@@ -157,213 +144,94 @@ int npc_event_dequeue (struct map_session_data *sd)
return 0;
}
-int npc_delete (struct npc_data *nd)
+int npc_delete(struct npc_data *nd)
{
- nullpo_retr (1, nd);
+ nullpo_retr(1, nd);
if (nd->bl.prev == NULL)
return 1;
- clif_clearchar_area (&nd->bl, 1);
- map_delblock (&nd->bl);
+ clif_clearchar(&nd->bl, BeingRemoveWhy::DEAD);
+ map_delblock(&nd->bl);
return 0;
}
-/*==========================================
- * イベントã®é…延実行
- *------------------------------------------
- */
-void npc_event_timer (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data)
+int npc_timer_event(const char *eventname) // Added by RoVeRT
{
- struct map_session_data *sd = map_id2sd (id);
- if (sd == NULL)
- return;
-
- npc_event (sd, (const char *) data, 0);
- free ((void *) data);
-}
-
-int npc_timer_event (const char *eventname) // Added by RoVeRT
-{
- struct event_data *ev = (struct event_data *)strdb_search (ev_db, eventname);
+ struct event_data *ev = ev_db.search(eventname);
struct npc_data *nd;
// int xs,ys;
if ((ev == NULL || (nd = ev->nd) == NULL))
{
- printf ("npc_event: event not found [%s]\n", eventname);
+ PRINTF("npc_event: event not found [%s]\n", eventname);
return 0;
}
- run_script (nd->u.scr.script, ev->pos, nd->bl.id, nd->bl.id);
+ run_script(nd->u.scr.script, ev->pos, nd->bl.id, nd->bl.id);
return 0;
}
-/*
-int npc_timer_sub_sub(void *key,void *data,va_list ap) // Added by RoVeRT
-{
- char *p=(char *)key;
- struct event_data *ev=(struct event_data *)data;
- int *c=va_arg(ap,int *);
- int tick=0,ctick=gettick();
- char temp[10];
- char event[100];
-
- if(ev->nd->bl.id==(int)*c && (p=strchr(p,':')) && p && strncasecmp("::OnTimer",p,8)==0 ){
- sscanf(&p[9],"%s",temp);
- tick=atoi(temp);
-
- strcpy( event, ev->nd->name);
- strcat( event, p);
-
- if (ctick >= ev->nd->lastaction && ctick - ev->nd->timer >= tick) {
- npc_timer_event(event);
- ev->nd->lastaction = ctick;
- }
- }
- return 0;
-}
-
-int npc_timer_sub(void *key,void *data,va_list ap) // Added by RoVeRT
-{
- struct npc_data *nd=(struct npc_data*)data;
-
- if(nd->timer == -1)
- return 0;
-
- strdb_foreach(ev_db,npc_timer_sub_sub,&nd->bl.id);
-
- return 0;
-}
-
-int npc_timer(int tid,unsigned int tick,int id,int data) // Added by RoVeRT
-{
- strdb_foreach(npcname_db,npc_timer_sub);
-
- free((void*)data);
- return 0;
-}*/
-/*==========================================
- * イベント用ラベルã®ã‚¨ã‚¯ã‚¹ãƒãƒ¼ãƒˆ
- * npc_parse_script->strdb_foreachã‹ã‚‰å‘¼ã°ã‚Œã‚‹
- *------------------------------------------
- */
-static
-int npc_event_export (void *key, void *data, va_list ap)
-{
- char *lname = (char *) key;
- int pos = (int) data;
- struct npc_data *nd = va_arg (ap, struct npc_data *);
-
- if ((lname[0] == 'O' || lname[0] == 'o')
- && (lname[1] == 'N' || lname[1] == 'n'))
- {
- struct event_data *ev;
- char *buf;
- char *p = strchr (lname, ':');
- // エクスãƒãƒ¼ãƒˆã•ã‚Œã‚‹
- CREATE (ev, struct event_data, 1);
- CREATE (buf, char, 50);
- if (p == NULL || (p - lname) > 24)
- {
- printf ("npc_event_export: label name error !\n");
- exit (1);
- }
- else
- {
- ev->nd = nd;
- ev->pos = pos;
- *p = '\0';
- sprintf (buf, "%s::%s", nd->exname, lname);
- *p = ':';
- strdb_insert (ev_db, buf, ev);
-// if (battle_config.etc_log)
-// printf("npc_event_export: export [%s]\n",buf);
- }
- }
- return 0;
-}
-
/*==========================================
* å…¨ã¦ã®NPCã®On*イベント実行
*------------------------------------------
*/
static
-void npc_event_doall_sub (db_key_t key, db_val_t data, va_list ap)
+void npc_event_doall_sub(const std::string& key, struct event_data *ev,
+ int *c, const char *name, int rid, int argc, argrec_t *argv)
{
- const char *p = key.s;
- int rid, argc;
- argrec_t *argv;
- struct event_data *ev;
- int *c;
- const char *name;
+ const char *p = key.c_str();
- nullpo_retv (ev = (struct event_data *) data);
- nullpo_retv (ap);
- nullpo_retv (c = va_arg (ap, int *));
+ nullpo_retv(ev);
- name = va_arg (ap, const char *);
- rid = va_arg (ap, int);
- argc = va_arg (ap, int);
- argv = va_arg (ap, argrec_t *);
-
- if ((p = strchr (p, ':')) && p && strcasecmp (name, p) == 0)
+ if ((p = strchr(p, ':')) && p && strcasecmp(name, p) == 0)
{
- run_script_l (ev->nd->u.scr.script, ev->pos, rid, ev->nd->bl.id, argc,
+ run_script_l(ev->nd->u.scr.script, ev->pos, rid, ev->nd->bl.id, argc,
argv);
(*c)++;
}
}
-int npc_event_doall_l (const char *name, int rid, int argc, argrec_t * args)
+int npc_event_doall_l(const char *name, int rid, int argc, argrec_t *args)
{
- int c = 0;
+ int c = 0;
char buf[64] = "::";
- strncpy (buf + 2, name, sizeof(buf)-3);
+ strncpy(buf + 2, name, sizeof(buf)-3);
buf[sizeof(buf)-1] = '\0';
- strdb_foreach (ev_db, npc_event_doall_sub, &c, buf, rid, argc, args);
+ for (auto& pair : ev_db)
+ npc_event_doall_sub(pair.first, &pair.second, &c, buf, rid, argc, args);
return c;
}
static
-void npc_event_do_sub (db_key_t key, db_val_t data, va_list ap)
+void npc_event_do_sub(const std::string& key, struct event_data *ev,
+ int *c, const char *name, int rid, int argc, argrec_t *argv)
{
- const char *p = key.s;
- struct event_data *ev;
- int *c;
- const char *name;
- int rid, argc;
- argrec_t *argv;
-
- nullpo_retv (ev = (struct event_data *) data);
- nullpo_retv (ap);
- nullpo_retv (c = va_arg (ap, int *));
+ const char *p = key.c_str();
- name = va_arg (ap, const char *);
- rid = va_arg (ap, int);
- argc = va_arg (ap, int);
- argv = va_arg (ap, argrec_t *);
+ nullpo_retv(ev);
- if (p && strcasecmp (name, p) == 0)
+ if (p && strcasecmp(name, p) == 0)
{
- run_script_l (ev->nd->u.scr.script, ev->pos, rid, ev->nd->bl.id, argc,
+ run_script_l(ev->nd->u.scr.script, ev->pos, rid, ev->nd->bl.id, argc,
argv);
(*c)++;
}
}
-int npc_event_do_l (const char *name, int rid, int argc, argrec_t * args)
+int npc_event_do_l(const char *name, int rid, int argc, argrec_t *args)
{
- int c = 0;
+ int c = 0;
if (*name == ':' && name[1] == ':')
{
- return npc_event_doall_l (name + 2, rid, argc, args);
+ return npc_event_doall_l(name + 2, rid, argc, args);
}
- strdb_foreach (ev_db, npc_event_do_sub, &c, name, rid, argc, args);
+ for (auto& pair : ev_db)
+ npc_event_do_sub(pair.first, &pair.second, &c, name, rid, argc, args);
return c;
}
@@ -372,180 +240,47 @@ int npc_event_do_l (const char *name, int rid, int argc, argrec_t * args)
*------------------------------------------
*/
static
-void npc_event_do_clock (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data)
+void npc_event_do_clock(TimerData *, tick_t)
{
- time_t timer;
- struct tm *t;
- char buf[64];
- int c = 0;
-
- time (&timer);
- t = gmtime (&timer);
+ struct tm t = TimeT::now();
- if (t->tm_min != ev_tm_b.tm_min)
+ if (t.tm_min != ev_tm_b.tm_min)
{
- sprintf (buf, "OnMinute%02d", t->tm_min);
- c += npc_event_doall (buf);
- sprintf (buf, "OnClock%02d%02d", t->tm_hour, t->tm_min);
- c += npc_event_doall (buf);
+ std::string buf;
+ buf = STRPRINTF("OnMinute%02d", t.tm_min);
+ npc_event_doall(buf.c_str());
+ buf = STRPRINTF("OnClock%02d%02d", t.tm_hour, t.tm_min);
+ npc_event_doall(buf.c_str());
}
- if (t->tm_hour != ev_tm_b.tm_hour)
+ if (t.tm_hour != ev_tm_b.tm_hour)
{
- sprintf (buf, "OnHour%02d", t->tm_hour);
- c += npc_event_doall (buf);
+ std::string buf;
+ buf = STRPRINTF("OnHour%02d", t.tm_hour);
+ npc_event_doall(buf.c_str());
}
- if (t->tm_mday != ev_tm_b.tm_mday)
+ if (t.tm_mday != ev_tm_b.tm_mday)
{
- sprintf (buf, "OnDay%02d%02d", t->tm_mon + 1, t->tm_mday);
- c += npc_event_doall (buf);
+ std::string buf;
+ buf = STRPRINTF("OnDay%02d%02d", t.tm_mon + 1, t.tm_mday);
+ npc_event_doall(buf.c_str());
}
- memcpy (&ev_tm_b, t, sizeof (ev_tm_b));
+ ev_tm_b = t;
}
/*==========================================
* OnInitイベント実行(&時計イベント開始)
*------------------------------------------
*/
-int npc_event_do_oninit (void)
-{
- int c = npc_event_doall ("OnInit");
- printf ("npc: OnInit Event done. (%d npc)\n", c);
-
- add_timer_interval (gettick () + 100, npc_event_do_clock, 0, 0, 1000);
-
- return 0;
-}
-
-/*==========================================
- * OnTimer NPC event - by RoVeRT
- *------------------------------------------
- */
-static
-int npc_addeventtimer (struct npc_data *nd, int tick, const char *name)
-{
- int i;
- for (i = 0; i < MAX_EVENTTIMER; i++)
- if (nd->eventtimer[i] == -1)
- break;
- if (i < MAX_EVENTTIMER)
- {
- char *evname;
- CREATE (evname, char, 24);
- memcpy (evname, name, 24);
- nd->eventtimer[i] = add_timer (gettick () + tick,
- npc_event_timer, nd->bl.id,
- (int) evname);
- }
- else
- printf ("npc_addtimer: event timer is full !\n");
-
- return 0;
-}
-
-static
-int npc_deleventtimer (struct npc_data *nd, const char *name)
-{
- int i;
- for (i = 0; i < MAX_EVENTTIMER; i++)
- if (nd->eventtimer[i] != -1 && strcmp ((char
- *) (get_timer (nd->eventtimer
- [i])->data),
- name) == 0)
- {
- delete_timer (nd->eventtimer[i], npc_event_timer);
- nd->eventtimer[i] = -1;
- break;
- }
-
- return 0;
-}
-
-static
-int npc_cleareventtimer (struct npc_data *nd)
-{
- int i;
- for (i = 0; i < MAX_EVENTTIMER; i++)
- if (nd->eventtimer[i] != -1)
- {
- delete_timer (nd->eventtimer[i], npc_event_timer);
- nd->eventtimer[i] = -1;
- }
-
- return 0;
-}
-
-static
-void npc_do_ontimer_sub (db_key_t key, db_val_t data, va_list ap)
+int npc_event_do_oninit(void)
{
- 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 *);
- int option = va_arg (ap, int);
- int tick = 0;
- char temp[10];
- char event[50];
+ int c = npc_event_doall("OnInit");
+ PRINTF("npc: OnInit Event done. (%d npc)\n", c);
- if (ev->nd->bl.id == (int) *c && (p = strchr (p, ':')) && p
- && strncasecmp ("::OnTimer", p, 8) == 0)
- {
- sscanf (&p[9], "%s", temp);
- tick = atoi (temp);
-
- strcpy (event, ev->nd->name);
- strcat (event, p);
-
- if (option != 0)
- {
- npc_addeventtimer (ev->nd, tick, event);
- }
- else
- {
- npc_deleventtimer (ev->nd, event);
- }
- }
-}
-
-int npc_do_ontimer (int id, struct map_session_data *sd, int option)
-{
- strdb_foreach (ev_db, npc_do_ontimer_sub, &id, sd, option);
- return 0;
-}
+ Timer(gettick() + std::chrono::milliseconds(100),
+ npc_event_do_clock,
+ std::chrono::seconds(1)
+ ).detach();
-/*==========================================
- * タイマーイベント用ラベルã®å–ã‚Šè¾¼ã¿
- * npc_parse_script->strdb_foreachã‹ã‚‰å‘¼ã°ã‚Œã‚‹
- *------------------------------------------
- */
-static
-int npc_timerevent_import (void *key, void *data, va_list ap)
-{
- char *lname = (char *) key;
- int pos = (int) data;
- struct npc_data *nd = va_arg (ap, struct npc_data *);
- int t = 0, i = 0;
-
- if (sscanf (lname, "OnTimer%d%n", &t, &i) == 1 && lname[i] == ':')
- {
- // タイマーイベント
- struct npc_timerevent_list *te = nd->u.scr.timer_event;
- int j;
- i = nd->u.scr.timeramount;
- RECREATE (te, struct npc_timerevent_list, i+1);
- for (j = 0; j < i; j++)
- {
- if (te[j].timer > t)
- {
- memmove (te + j + 1, te + j,
- sizeof (struct npc_timerevent_list) * (i - j));
- break;
- }
- }
- te[j].timer = t;
- te[j].pos = pos;
- nd->u.scr.timer_event = te;
- nd->u.scr.timeramount = i + 1;
- }
return 0;
}
@@ -554,40 +289,39 @@ int npc_timerevent_import (void *key, void *data, va_list ap)
*------------------------------------------
*/
static
-void npc_timerevent (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data)
+void npc_timerevent(TimerData *, tick_t tick, int id, interval_t data)
{
- int next, t;
- struct npc_data *nd = (struct npc_data *) map_id2bl (id);
+ struct npc_data *nd = (struct npc_data *) map_id2bl(id);
struct npc_timerevent_list *te;
- if (nd == NULL || nd->u.scr.nexttimer < 0)
- {
- printf ("npc_timerevent: ??\n");
- return;
- }
+ assert (nd != NULL);
+ assert (nd->u.scr.nexttimer >= 0);
+
nd->u.scr.timertick = tick;
te = nd->u.scr.timer_event + nd->u.scr.nexttimer;
- nd->u.scr.timerid = -1;
+ // nd->u.scr.timerid = nullptr;
- t = nd->u.scr.timer += data;
+ interval_t t = nd->u.scr.timer += data;
nd->u.scr.nexttimer++;
if (nd->u.scr.timeramount > nd->u.scr.nexttimer)
{
- next = nd->u.scr.timer_event[nd->u.scr.nexttimer].timer - t;
- nd->u.scr.timerid = add_timer (tick + next, npc_timerevent, id, next);
+ interval_t next = nd->u.scr.timer_event[nd->u.scr.nexttimer].timer - t;
+ nd->u.scr.timerid = Timer(tick + next,
+ std::bind(npc_timerevent, ph::_1, ph::_2,
+ id, next));
}
- run_script (nd->u.scr.script, te->pos, 0, nd->bl.id);
+ run_script(nd->u.scr.script, te->pos, 0, nd->bl.id);
}
/*==========================================
* タイマーイベント開始
*------------------------------------------
*/
-int npc_timerevent_start (struct npc_data *nd)
+int npc_timerevent_start(struct npc_data *nd)
{
- int j, n, next;
+ int j, n;
- nullpo_retr (0, nd);
+ nullpo_ret(nd);
n = nd->u.scr.timeramount;
if (nd->u.scr.nexttimer >= 0 || n == 0)
@@ -599,14 +333,15 @@ int npc_timerevent_start (struct npc_data *nd)
break;
}
nd->u.scr.nexttimer = j;
- nd->u.scr.timertick = gettick ();
+ nd->u.scr.timertick = gettick();
if (j >= n)
return 0;
- next = nd->u.scr.timer_event[j].timer - nd->u.scr.timer;
- nd->u.scr.timerid =
- add_timer (gettick () + next, npc_timerevent, nd->bl.id, next);
+ interval_t next = nd->u.scr.timer_event[j].timer - nd->u.scr.timer;
+ nd->u.scr.timerid = Timer(gettick() + next,
+ std::bind(npc_timerevent, ph::_1, ph::_2,
+ nd->bl.id, next));
return 0;
}
@@ -614,17 +349,15 @@ int npc_timerevent_start (struct npc_data *nd)
* タイマーイベント終了
*------------------------------------------
*/
-int npc_timerevent_stop (struct npc_data *nd)
+int npc_timerevent_stop(struct npc_data *nd)
{
- nullpo_retr (0, nd);
+ nullpo_ret(nd);
if (nd->u.scr.nexttimer >= 0)
{
nd->u.scr.nexttimer = -1;
- nd->u.scr.timer += (int) (gettick () - nd->u.scr.timertick);
- if (nd->u.scr.timerid != -1)
- delete_timer (nd->u.scr.timerid, npc_timerevent);
- nd->u.scr.timerid = -1;
+ nd->u.scr.timer += gettick() - nd->u.scr.timertick;
+ nd->u.scr.timerid.cancel();
}
return 0;
}
@@ -633,16 +366,14 @@ int npc_timerevent_stop (struct npc_data *nd)
* タイマー値ã®æ‰€å¾—
*------------------------------------------
*/
-int npc_gettimerevent_tick (struct npc_data *nd)
+interval_t npc_gettimerevent_tick(struct npc_data *nd)
{
- int tick;
-
- nullpo_retr (0, nd);
+ nullpo_retr(interval_t::zero(), nd);
- tick = nd->u.scr.timer;
+ interval_t tick = nd->u.scr.timer;
if (nd->u.scr.nexttimer >= 0)
- tick += (int) (gettick () - nd->u.scr.timertick);
+ tick += gettick() - nd->u.scr.timertick;
return tick;
}
@@ -650,18 +381,18 @@ int npc_gettimerevent_tick (struct npc_data *nd)
* タイマー値ã®è¨­å®š
*------------------------------------------
*/
-int npc_settimerevent_tick (struct npc_data *nd, int newtimer)
+int npc_settimerevent_tick(struct npc_data *nd, interval_t newtimer)
{
- int flag;
+ int flag;
- nullpo_retr (0, nd);
+ nullpo_ret(nd);
flag = nd->u.scr.nexttimer;
- npc_timerevent_stop (nd);
+ npc_timerevent_stop(nd);
nd->u.scr.timer = newtimer;
if (flag >= 0)
- npc_timerevent_start (nd);
+ npc_timerevent_start(nd);
return 0;
}
@@ -669,41 +400,41 @@ int npc_settimerevent_tick (struct npc_data *nd, int newtimer)
* イベント型ã®NPC処ç†
*------------------------------------------
*/
-int npc_event (struct map_session_data *sd, const char *eventname,
+int npc_event(struct map_session_data *sd, const char *eventname,
int mob_kill)
{
- struct event_data *ev = (struct event_data *)strdb_search (ev_db, eventname);
+ struct event_data *ev = ev_db.search(eventname);
struct npc_data *nd;
- int xs, ys;
+ int xs, ys;
char mobevent[100];
if (sd == NULL)
{
- printf ("npc_event nullpo?\n");
+ PRINTF("npc_event nullpo?\n");
}
if (ev == NULL && eventname
- && strcmp (((eventname) + strlen (eventname) - 9), "::OnTouch") == 0)
+ && strcmp(((eventname) + strlen(eventname) - 9), "::OnTouch") == 0)
return 1;
if (ev == NULL || (nd = ev->nd) == NULL)
{
if (mob_kill && (ev == NULL || (nd = ev->nd) == NULL))
{
- strcpy (mobevent, eventname);
- strcat (mobevent, "::OnMyMobDead");
- ev = (struct event_data *)strdb_search (ev_db, mobevent);
+ strcpy(mobevent, eventname);
+ strcat(mobevent, "::OnMyMobDead");
+ ev = ev_db.search(mobevent);
if (ev == NULL || (nd = ev->nd) == NULL)
{
- if (strncasecmp (eventname, "GM_MONSTER", 10) != 0)
- printf ("npc_event: event not found [%s]\n", mobevent);
+ if (strncasecmp(eventname, "GM_MONSTER", 10) != 0)
+ PRINTF("npc_event: event not found [%s]\n", mobevent);
return 0;
}
}
else
{
if (battle_config.error_log)
- printf ("npc_event: event not found [%s]\n", eventname);
+ PRINTF("npc_event: event not found [%s]\n", eventname);
return 0;
}
}
@@ -725,59 +456,57 @@ int npc_event (struct map_session_data *sd, const char *eventname,
if (sd->npc_id != 0)
{
// if (battle_config.error_log)
-// printf("npc_event: npc_id != 0\n");
- int i;
+// PRINTF("npc_event: npc_id != 0\n");
+ int i;
for (i = 0; i < MAX_EVENTQUEUE; i++)
if (!sd->eventqueue[i][0])
break;
if (i == MAX_EVENTQUEUE)
{
if (battle_config.error_log)
- printf ("npc_event: event queue is full !\n");
+ PRINTF("npc_event: event queue is full !\n");
}
else
{
// if (battle_config.etc_log)
-// printf("npc_event: enqueue\n");
- strncpy (sd->eventqueue[i], eventname, 50);
+// PRINTF("npc_event: enqueue\n");
+ strncpy(sd->eventqueue[i], eventname, 50);
sd->eventqueue[i][49] = '\0';
}
return 1;
}
if (nd->flag & 1)
{ // 無効化ã•ã‚Œã¦ã„ã‚‹
- npc_event_dequeue (sd);
+ npc_event_dequeue(sd);
return 0;
}
sd->npc_id = nd->bl.id;
sd->npc_pos =
- run_script (nd->u.scr.script, ev->pos, sd->bl.id, nd->bl.id);
+ run_script(nd->u.scr.script, ev->pos, sd->bl.id, nd->bl.id);
return 0;
}
static
-void npc_command_sub (db_key_t key, db_val_t data, va_list ap)
+void npc_command_sub(const std::string& key, struct event_data *ev, const char *npcname, const char *command)
{
- 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 *);
+ const char *p = key.c_str();
char temp[100];
- if (strcmp (ev->nd->name, npcname) == 0 && (p = strchr (p, ':')) && p
- && strncasecmp ("::OnCommand", p, 10) == 0)
+ if (strcmp(ev->nd->name, npcname) == 0 && (p = strchr(p, ':')) && p
+ && strncasecmp("::OnCommand", p, 10) == 0)
{
- sscanf (&p[11], "%s", temp);
+ sscanf(&p[11], "%s", temp);
- if (strcmp (command, temp) == 0)
- run_script (ev->nd->u.scr.script, ev->pos, 0, ev->nd->bl.id);
+ if (strcmp(command, temp) == 0)
+ run_script(ev->nd->u.scr.script, ev->pos, 0, ev->nd->bl.id);
}
}
-int npc_command (struct map_session_data *sd, const char *npcname, const char *command)
+int npc_command(struct map_session_data *, const char *npcname, const char *command)
{
- strdb_foreach (ev_db, npc_command_sub, npcname, command);
+ for (auto& pair : ev_db)
+ npc_command_sub(pair.first, &pair.second, npcname, command);
return 0;
}
@@ -786,12 +515,12 @@ int npc_command (struct map_session_data *sd, const char *npcname, const char *c
* 接触型ã®NPC処ç†
*------------------------------------------
*/
-int npc_touch_areanpc (struct map_session_data *sd, int m, int x, int y)
+int npc_touch_areanpc(struct map_session_data *sd, int m, int x, int y)
{
- int i, f = 1;
- int xs, ys;
+ int i, f = 1;
+ int xs, ys;
- nullpo_retr (1, sd);
+ nullpo_retr(1, sd);
if (sd->npc_id)
return 1;
@@ -806,12 +535,12 @@ int npc_touch_areanpc (struct map_session_data *sd, int m, int x, int y)
switch (map[m].npc[i]->bl.subtype)
{
- case WARP:
+ case NpcSubtype::WARP:
xs = map[m].npc[i]->u.warp.xs;
ys = map[m].npc[i]->u.warp.ys;
break;
- case MESSAGE:
- case SCRIPT:
+ case NpcSubtype::MESSAGE:
+ case NpcSubtype::SCRIPT:
xs = map[m].npc[i]->u.scr.xs;
ys = map[m].npc[i]->u.scr.ys;
break;
@@ -829,29 +558,29 @@ int npc_touch_areanpc (struct map_session_data *sd, int m, int x, int y)
if (f)
{
if (battle_config.error_log)
- printf ("npc_touch_areanpc : some bug \n");
+ PRINTF("npc_touch_areanpc : some bug \n");
}
return 1;
}
switch (map[m].npc[i]->bl.subtype)
{
- case WARP:
- skill_stop_dancing (&sd->bl, 0);
- pc_setpos (sd, map[m].npc[i]->u.warp.name,
- map[m].npc[i]->u.warp.x, map[m].npc[i]->u.warp.y, 0);
+ case NpcSubtype::WARP:
+ skill_stop_dancing(&sd->bl, 0);
+ pc_setpos(sd, map[m].npc[i]->u.warp.name,
+ map[m].npc[i]->u.warp.x, map[m].npc[i]->u.warp.y, BeingRemoveWhy::GONE);
break;
- case MESSAGE:
- case SCRIPT:
+ case NpcSubtype::MESSAGE:
+ case NpcSubtype::SCRIPT:
{
- char *name = (char *)malloc (50);
+ char *name = (char *)malloc(50);
- memcpy (name, map[m].npc[i]->name, 50);
+ memcpy(name, map[m].npc[i]->name, 50);
if (sd->areanpc_id == map[m].npc[i]->bl.id)
- return 1;
+ return 1; // TODO fix leak of 'name'
sd->areanpc_id = map[m].npc[i]->bl.id;
- if (npc_event (sd, strcat (name, "::OnTouch"), 0) > 0)
- npc_click (sd, map[m].npc[i]->bl.id);
- free (name);
+ if (npc_event(sd, strcat(name, "::OnTouch"), 0) > 0)
+ npc_click(sd, map[m].npc[i]->bl.id);
+ free(name);
break;
}
}
@@ -862,17 +591,18 @@ int npc_touch_areanpc (struct map_session_data *sd, int m, int x, int y)
* è¿‘ãã‹ã©ã†ã‹ã®åˆ¤å®š
*------------------------------------------
*/
-int npc_checknear (struct map_session_data *sd, int id)
+static
+int npc_checknear(struct map_session_data *sd, int id)
{
struct npc_data *nd;
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
- nd = (struct npc_data *) map_id2bl (id);
- if (nd == NULL || nd->bl.type != BL_NPC)
+ nd = (struct npc_data *) map_id2bl(id);
+ if (nd == NULL || nd->bl.type != BL::NPC)
{
if (battle_config.error_log)
- printf ("no such npc : %d\n", id);
+ PRINTF("no such npc : %d\n", id);
return 1;
}
@@ -894,25 +624,25 @@ int npc_checknear (struct map_session_data *sd, int id)
* クリック時ã®NPC処ç†
*------------------------------------------
*/
-int npc_click (struct map_session_data *sd, int id)
+int npc_click(struct map_session_data *sd, int id)
{
struct npc_data *nd;
- nullpo_retr (1, sd);
+ nullpo_retr(1, sd);
if (sd->npc_id != 0)
{
if (battle_config.error_log)
- printf ("npc_click: npc_id != 0\n");
+ PRINTF("npc_click: npc_id != 0\n");
return 1;
}
- if (npc_checknear (sd, id)) {
- clif_scriptclose (sd, id);
+ if (npc_checknear(sd, id)) {
+ clif_scriptclose(sd, id);
return 1;
}
- nd = (struct npc_data *) map_id2bl (id);
+ nd = (struct npc_data *) map_id2bl(id);
if (nd->flag & 1) // 無効化ã•ã‚Œã¦ã„ã‚‹
return 1;
@@ -920,18 +650,18 @@ int npc_click (struct map_session_data *sd, int id)
sd->npc_id = id;
switch (nd->bl.subtype)
{
- case SHOP:
- clif_npcbuysell (sd, id);
- npc_event_dequeue (sd);
+ case NpcSubtype::SHOP:
+ clif_npcbuysell(sd, id);
+ npc_event_dequeue(sd);
break;
- case SCRIPT:
- sd->npc_pos = run_script (nd->u.scr.script, 0, sd->bl.id, id);
+ case NpcSubtype::SCRIPT:
+ sd->npc_pos = run_script(nd->u.scr.script, 0, sd->bl.id, id);
break;
- case MESSAGE:
+ case NpcSubtype::MESSAGE:
if (nd->u.message)
{
- clif_scriptmes (sd, id, nd->u.message);
- clif_scriptclose (sd, id);
+ clif_scriptmes(sd, id, nd->u.message);
+ clif_scriptclose(sd, id);
}
break;
}
@@ -943,29 +673,29 @@ int npc_click (struct map_session_data *sd, int id)
*
*------------------------------------------
*/
-int npc_scriptcont (struct map_session_data *sd, int id)
+int npc_scriptcont(struct map_session_data *sd, int id)
{
struct npc_data *nd;
- nullpo_retr (1, sd);
+ nullpo_retr(1, sd);
if (id != sd->npc_id)
return 1;
- if (npc_checknear (sd, id)) {
- clif_scriptclose (sd, id);
+ if (npc_checknear(sd, id)) {
+ clif_scriptclose(sd, id);
return 1;
}
- nd = (struct npc_data *) map_id2bl (id);
+ nd = (struct npc_data *) map_id2bl(id);
- if (!nd /* NPC was disposed? */ || nd->bl.subtype == MESSAGE)
+ if (!nd /* NPC was disposed? */ || nd->bl.subtype == NpcSubtype::MESSAGE)
{
- clif_scriptclose (sd, id);
- npc_event_dequeue (sd);
+ clif_scriptclose(sd, id);
+ npc_event_dequeue(sd);
return 0;
}
- sd->npc_pos = run_script (nd->u.scr.script, sd->npc_pos, sd->bl.id, id);
+ sd->npc_pos = run_script(nd->u.scr.script, sd->npc_pos, sd->bl.id, id);
return 0;
}
@@ -974,20 +704,20 @@ int npc_scriptcont (struct map_session_data *sd, int id)
*
*------------------------------------------
*/
-int npc_buysellsel (struct map_session_data *sd, int id, int type)
+int npc_buysellsel(struct map_session_data *sd, int id, int type)
{
struct npc_data *nd;
- nullpo_retr (1, sd);
+ nullpo_retr(1, sd);
- if (npc_checknear (sd, id))
+ if (npc_checknear(sd, id))
return 1;
- nd = (struct npc_data *) map_id2bl (id);
- if (nd->bl.subtype != SHOP)
+ nd = (struct npc_data *) map_id2bl(id);
+ if (nd->bl.subtype != NpcSubtype::SHOP)
{
if (battle_config.error_log)
- printf ("no such shop npc : %d\n", id);
+ PRINTF("no such shop npc : %d\n", id);
sd->npc_id = 0;
return 1;
}
@@ -997,11 +727,11 @@ int npc_buysellsel (struct map_session_data *sd, int id, int type)
sd->npc_shopid = id;
if (type == 0)
{
- clif_buylist (sd, nd);
+ clif_buylist(sd, nd);
}
else
{
- clif_selllist (sd);
+ clif_selllist(sd);
}
return 0;
}
@@ -1010,21 +740,22 @@ int npc_buysellsel (struct map_session_data *sd, int id, int type)
*
*------------------------------------------
*/
-int npc_buylist (struct map_session_data *sd, int n,
- unsigned short *item_list)
+// TODO enumify return type
+int npc_buylist(struct map_session_data *sd, int n,
+ const uint16_t *item_list)
{
struct npc_data *nd;
double z;
- int i, j, w, skill, itemamount = 0, new_stacks = 0;
+ int i, j, w, itemamount = 0, new_stacks = 0;
- nullpo_retr (3, sd);
- nullpo_retr (3, item_list);
+ nullpo_retr(3, sd);
+ nullpo_retr(3, item_list);
- if (npc_checknear (sd, sd->npc_shopid))
+ if (npc_checknear(sd, sd->npc_shopid))
return 3;
- nd = (struct npc_data *) map_id2bl (sd->npc_shopid);
- if (nd->bl.subtype != SHOP)
+ nd = (struct npc_data *) map_id2bl(sd->npc_shopid);
+ if (nd->bl.subtype != NpcSubtype::SHOP)
return 3;
for (i = 0, w = 0, z = 0; i < n; i++)
@@ -1037,88 +768,67 @@ int npc_buylist (struct map_session_data *sd, int n,
if (nd->u.shop_item[j].nameid == 0)
return 3;
- if (itemdb_value_notdc (nd->u.shop_item[j].nameid))
- z += (double) nd->u.shop_item[j].value * item_list[i * 2];
- else
- z += (double) pc_modifybuyvalue (sd,
- nd->u.shop_item[j].value) *
- item_list[i * 2];
+ z += (double) nd->u.shop_item[j].value * item_list[i * 2];
itemamount += item_list[i * 2];
- switch (pc_checkadditem (sd, item_list[i * 2 + 1], item_list[i * 2]))
+ switch (pc_checkadditem(sd, item_list[i * 2 + 1], item_list[i * 2]))
{
- case ADDITEM_EXIST:
+ case ADDITEM::EXIST:
break;
- case ADDITEM_NEW:
- if (itemdb_isequip (item_list[i * 2 + 1]))
+ case ADDITEM::NEW:
+ if (itemdb_isequip(item_list[i * 2 + 1]))
new_stacks += item_list[i * 2];
else
new_stacks++;
break;
- case ADDITEM_OVERAMOUNT:
+ case ADDITEM::OVERAMOUNT:
return 2;
}
- w += itemdb_weight (item_list[i * 2 + 1]) * item_list[i * 2];
+ w += itemdb_weight(item_list[i * 2 + 1]) * item_list[i * 2];
}
if (z > (double) sd->status.zeny)
return 1; // zenyä¸è¶³
if (w + sd->weight > sd->max_weight)
return 2; // é‡é‡è¶…éŽ
- if (pc_inventoryblank (sd) < new_stacks)
+ if (pc_inventoryblank(sd) < new_stacks)
return 3; // 種類数超éŽ
if (sd->trade_partner != 0)
return 4; // cant buy while trading
- pc_payzeny (sd, (int) z);
+ pc_payzeny(sd, (int) z);
for (i = 0; i < n; i++)
{
struct item_data *item_data;
- if ((item_data = itemdb_exists (item_list[i * 2 + 1])) != NULL)
+ if ((item_data = itemdb_exists(item_list[i * 2 + 1])) != NULL)
{
- int amount = item_list[i * 2];
+ int amount = item_list[i * 2];
struct item item_tmp;
- memset (&item_tmp, 0, sizeof (item_tmp));
+ memset(&item_tmp, 0, sizeof(item_tmp));
item_tmp.nameid = item_data->nameid;
item_tmp.identify = 1; // npc販売アイテムã¯é‘‘定済ã¿
if (amount > 1
- && (item_data->type == 4 || item_data->type == 5
- || item_data->type == 7 || item_data->type == 8))
+ && (item_data->type == ItemType::WEAPON
+ || item_data->type == ItemType::ARMOR
+ || item_data->type == ItemType::_7
+ || item_data->type == ItemType::_8))
{
for (j = 0; j < amount; j++)
{
- pc_additem (sd, &item_tmp, 1);
+ pc_additem(sd, &item_tmp, 1);
}
}
else
{
- pc_additem (sd, &item_tmp, amount);
+ pc_additem(sd, &item_tmp, amount);
}
}
}
- //商人経験値
-/* if ((sd->status.class == 5) || (sd->status.class == 10) || (sd->status.class == 18)) {
- z = z * pc_checkskill(sd,MC_DISCOUNT) / ((1 + 300 / itemamount) * 4000) * battle_config.shop_exp;
- pc_gainexp(sd,0,z);
- }*/
- if (battle_config.shop_exp > 0 && z > 0
- && (skill = pc_checkskill (sd, MC_DISCOUNT)) > 0)
- {
- if (skill > 0)
- {
- z = (log (z * (double) skill) * (double) battle_config.shop_exp /
- 100.);
- if (z < 1)
- z = 1;
- pc_gainexp (sd, 0, (int) z);
- }
- }
-
return 0;
}
@@ -1126,20 +836,20 @@ int npc_buylist (struct map_session_data *sd, int n,
*
*------------------------------------------
*/
-int npc_selllist (struct map_session_data *sd, int n,
- unsigned short *item_list)
+int npc_selllist(struct map_session_data *sd, int n,
+ const uint16_t *item_list)
{
double z;
- int i, skill, itemamount = 0;
+ int i, itemamount = 0;
- nullpo_retr (1, sd);
- nullpo_retr (1, item_list);
+ nullpo_retr(1, sd);
+ nullpo_retr(1, item_list);
- if (npc_checknear (sd, sd->npc_shopid))
+ if (npc_checknear(sd, sd->npc_shopid))
return 1;
for (i = 0, z = 0; i < n; i++)
{
- int nameid;
+ int nameid;
if (item_list[i * 2] - 2 < 0 || item_list[i * 2] - 2 >= MAX_INVENTORY)
return 1;
nameid = sd->status.inventory[item_list[i * 2] - 2].nameid;
@@ -1149,40 +859,17 @@ int npc_selllist (struct map_session_data *sd, int n,
return 1;
if (sd->trade_partner != 0)
return 2; // cant sell while trading
- if (itemdb_value_notoc (nameid))
- z += (double) itemdb_value_sell (nameid) * item_list[i * 2 + 1];
- else
- z += (double) pc_modifysellvalue (sd,
- itemdb_value_sell (nameid)) *
- item_list[i * 2 + 1];
+ z += (double) itemdb_value_sell(nameid) * item_list[i * 2 + 1];
itemamount += item_list[i * 2 + 1];
}
if (z > MAX_ZENY)
z = MAX_ZENY;
- pc_getzeny (sd, (int) z);
+ pc_getzeny(sd, (int) z);
for (i = 0; i < n; i++)
{
- int item_id = item_list[i * 2] - 2;
- pc_delitem (sd, item_id, item_list[i * 2 + 1], 0);
- }
-
- //商人経験値
-/* if ((sd->status.class == 5) || (sd->status.class == 10) || (sd->status.class == 18)) {
- z = z * pc_checkskill(sd,MC_OVERCHARGE) / ((1 + 500 / itemamount) * 4000) * battle_config.shop_exp ;
- pc_gainexp(sd,0,z);
- }*/
- if (battle_config.shop_exp > 0 && z > 0
- && (skill = pc_checkskill (sd, MC_OVERCHARGE)) > 0)
- {
- if (skill > 0)
- {
- z = (log (z * (double) skill) * (double) battle_config.shop_exp /
- 100.);
- if (z < 1)
- z = 1;
- pc_gainexp (sd, 0, (int) z);
- }
+ int item_id = item_list[i * 2] - 2;
+ pc_delitem(sd, item_id, item_list[i * 2 + 1], 0);
}
return 0;
@@ -1198,7 +885,7 @@ int npc_selllist (struct map_session_data *sd, int n,
*------------------------------------------
*/
static
-void npc_clearsrcfile (void)
+void npc_clearsrcfile(void)
{
struct npc_src_list *p = npc_src_first;
@@ -1206,7 +893,7 @@ void npc_clearsrcfile (void)
{
struct npc_src_list *p2 = p;
p = p->next;
- free (p2);
+ free(p2);
}
npc_src_first = NULL;
npc_src_last = NULL;
@@ -1216,21 +903,21 @@ void npc_clearsrcfile (void)
* 読ã¿è¾¼ã‚€npcファイルã®è¿½åŠ 
*------------------------------------------
*/
-void npc_addsrcfile (char *name)
+void npc_addsrcfile(const char *name)
{
struct npc_src_list *new_src;
size_t len;
- if (strcasecmp (name, "clear") == 0)
+ if (strcasecmp(name, "clear") == 0)
{
- npc_clearsrcfile ();
+ npc_clearsrcfile();
return;
}
- len = sizeof (*new_src) + strlen (name);
- new_src = (struct npc_src_list *) calloc (1, len);
+ len = sizeof(*new_src) + strlen(name);
+ new_src = (struct npc_src_list *) calloc(1, len);
new_src->next = NULL;
- strncpy (new_src->name, name, strlen (name) + 1);
+ strncpy(new_src->name, name, strlen(name) + 1);
if (npc_src_first == NULL)
npc_src_first = new_src;
if (npc_src_last)
@@ -1243,24 +930,24 @@ void npc_addsrcfile (char *name)
* 読ã¿è¾¼ã‚€npcファイルã®å‰Šé™¤
*------------------------------------------
*/
-void npc_delsrcfile (char *name)
+void npc_delsrcfile(const char *name)
{
struct npc_src_list *p = npc_src_first, *pp = NULL, **lp = &npc_src_first;
- if (strcasecmp (name, "all") == 0)
+ if (strcasecmp(name, "all") == 0)
{
- npc_clearsrcfile ();
+ npc_clearsrcfile();
return;
}
for (; p; lp = &p->next, pp = p, p = p->next)
{
- if (strcmp (p->name, name) == 0)
+ if (strcmp(p->name, name) == 0)
{
*lp = p->next;
if (npc_src_last == p)
npc_src_last = pp;
- free (p);
+ free(p);
break;
}
}
@@ -1270,48 +957,48 @@ void npc_delsrcfile (char *name)
* warp行解æž
*------------------------------------------
*/
-int npc_parse_warp (const char *w1, const char *w2, const char *w3, const char *w4)
+int npc_parse_warp(const char *w1, const char *, const char *w3, const char *w4)
{
- int x, y, xs, ys, to_x, to_y, m;
- int i, j;
+ int x, y, xs, ys, to_x, to_y, m;
+ int i, j;
char mapname[24], to_mapname[24];
struct npc_data *nd;
// 引数ã®å€‹æ•°ãƒã‚§ãƒƒã‚¯
- if (sscanf (w1, "%[^,],%d,%d", mapname, &x, &y) != 3 ||
- sscanf (w4, "%d,%d,%[^,],%d,%d", &xs, &ys, to_mapname, &to_x,
+ if (sscanf(w1, "%[^,],%d,%d", mapname, &x, &y) != 3 ||
+ sscanf(w4, "%d,%d,%[^,],%d,%d", &xs, &ys, to_mapname, &to_x,
&to_y) != 5)
{
- printf ("bad warp line : %s\n", w3);
+ PRINTF("bad warp line : %s\n", w3);
return 1;
}
- m = map_mapname2mapid (mapname);
+ m = map_mapname2mapid(mapname);
- nd = (struct npc_data *) calloc (1, sizeof (struct npc_data));
- nd->bl.id = npc_get_new_npc_id ();
- nd->n = map_addnpc (m, nd);
+ nd = (struct npc_data *) calloc(1, sizeof(struct npc_data));
+ nd->bl.id = npc_get_new_npc_id();
+ nd->n = map_addnpc(m, nd);
nd->bl.prev = nd->bl.next = NULL;
nd->bl.m = m;
nd->bl.x = x;
nd->bl.y = y;
- nd->dir = 0;
+ nd->dir = DIR::S;
nd->flag = 0;
- memcpy (nd->name, w3, 24);
- memcpy (nd->exname, w3, 24);
+ memcpy(nd->name, w3, 24);
+ memcpy(nd->exname, w3, 24);
nd->chat_id = 0;
if (!battle_config.warp_point_debug)
nd->npc_class = WARP_CLASS;
else
nd->npc_class = WARP_DEBUG_CLASS;
- nd->speed = 200;
- nd->option = 0;
- nd->opt1 = 0;
- nd->opt2 = 0;
- nd->opt3 = 0;
- memcpy (nd->u.warp.name, to_mapname, 16);
+ nd->speed = std::chrono::milliseconds(200);
+ nd->option = Option::ZERO;
+ nd->opt1 = Opt1::ZERO;
+ nd->opt2 = Opt2::ZERO;
+ nd->opt3 = Opt3::ZERO;
+ memcpy(nd->u.warp.name, to_mapname, 16);
xs += 2;
ys += 2;
nd->u.warp.x = to_x;
@@ -1323,21 +1010,24 @@ int npc_parse_warp (const char *w1, const char *w2, const char *w3, const char *
{
for (j = 0; j < xs; j++)
{
- int t;
- t = map_getcell (m, x - xs / 2 + j, y - ys / 2 + i);
- if (t == 1 || t == 5)
+ int x_lo = x - xs / 2;
+ int y_lo = y - ys / 2;
+ int xc = x_lo + j;
+ int yc = y_lo + i;
+ MapCell t = map_getcell(m, xc, yc);
+ if (bool(t & MapCell::UNWALKABLE))
continue;
- map_setcell (m, x - xs / 2 + j, y - ys / 2 + i, t | 0x80);
+ map_setcell(m, xc, yc, t | MapCell::NPC_NEAR);
}
}
-// printf("warp npc %s %d read done\n",mapname,nd->bl.id);
+// PRINTF("warp npc %s %d read done\n",mapname,nd->bl.id);
npc_warp++;
- nd->bl.type = BL_NPC;
- nd->bl.subtype = WARP;
- map_addblock (&nd->bl);
- clif_spawnnpc (nd);
- strdb_insert (npcname_db, nd->name, nd);
+ nd->bl.type = BL::NPC;
+ nd->bl.subtype = NpcSubtype::WARP;
+ map_addblock(&nd->bl);
+ clif_spawnnpc(nd);
+ npcname_db.put(nd->name, nd);
return 0;
}
@@ -1346,40 +1036,46 @@ int npc_parse_warp (const char *w1, const char *w2, const char *w3, const char *
* shop行解æž
*------------------------------------------
*/
-static int npc_parse_shop (char *w1, char *w2, char *w3, char *w4)
+static
+int npc_parse_shop(char *w1, char *, char *w3, char *w4)
{
char *p;
- int x, y, dir, m;
- int max = 100, pos = 0;
+ int x, y;
+ DIR dir;
+ int m;
+ int max = 100, pos = 0;
char mapname[24];
struct npc_data *nd;
// 引数ã®å€‹æ•°ãƒã‚§ãƒƒã‚¯
- if (sscanf (w1, "%[^,],%d,%d,%d", mapname, &x, &y, &dir) != 4 ||
- strchr (w4, ',') == NULL)
+ int dir_; // TODO use SSCANF or extract
+ if (sscanf(w1, "%[^,],%d,%d,%d", mapname, &x, &y, &dir_) != 4
+ || dir_ < 0 || dir_ >= 8
+ || strchr(w4, ',') == NULL)
{
- printf ("bad shop line : %s\n", w3);
+ PRINTF("bad shop line : %s\n", w3);
return 1;
}
- m = map_mapname2mapid (mapname);
+ dir = static_cast<DIR>(dir_);
+ m = map_mapname2mapid(mapname);
- nd = (struct npc_data *) calloc (1, sizeof (struct npc_data) +
- sizeof (nd->u.shop_item[0]) * (max +
+ nd = (struct npc_data *) calloc(1, sizeof(struct npc_data) +
+ sizeof(nd->u.shop_item[0]) * (max +
1));
- p = strchr (w4, ',');
+ p = strchr(w4, ',');
while (p && pos < max)
{
- int nameid, value;
+ int nameid, value;
char name[24];
struct item_data *id = NULL;
p++;
- if (sscanf (p, "%d:%d", &nameid, &value) == 2)
+ if (sscanf(p, "%d:%d", &nameid, &value) == 2)
{
}
- else if (sscanf (p, "%s :%d", name, &value) == 2)
+ else if (sscanf(p, "%s :%d", name, &value) == 2)
{
- id = itemdb_searchname (name);
+ id = itemdb_searchname(name);
if (id == NULL)
nameid = -1;
else
@@ -1394,18 +1090,18 @@ static int npc_parse_shop (char *w1, char *w2, char *w3, char *w4)
if (value < 0)
{
if (id == NULL)
- id = itemdb_search (nameid);
- value = id->value_buy * abs (value);
+ id = itemdb_search(nameid);
+ value = id->value_buy * abs(value);
}
nd->u.shop_item[pos].value = value;
pos++;
}
- p = strchr (p, ',');
+ p = strchr(p, ',');
}
if (pos == 0)
{
- free (nd);
+ free(nd);
return 1;
}
nd->u.shop_item[pos++].nameid = 0;
@@ -1414,29 +1110,29 @@ static int npc_parse_shop (char *w1, char *w2, char *w3, char *w4)
nd->bl.m = m;
nd->bl.x = x;
nd->bl.y = y;
- nd->bl.id = npc_get_new_npc_id ();
+ nd->bl.id = npc_get_new_npc_id();
nd->dir = dir;
nd->flag = 0;
- memcpy (nd->name, w3, 24);
- nd->npc_class = atoi (w4);
- nd->speed = 200;
+ memcpy(nd->name, w3, 24);
+ nd->npc_class = atoi(w4);
+ nd->speed = std::chrono::milliseconds(200);
nd->chat_id = 0;
- nd->option = 0;
- nd->opt1 = 0;
- nd->opt2 = 0;
- nd->opt3 = 0;
+ nd->option = Option::ZERO;
+ nd->opt1 = Opt1::ZERO;
+ nd->opt2 = Opt2::ZERO;
+ nd->opt3 = Opt3::ZERO;
nd = (struct npc_data *)
- realloc (nd, sizeof (struct npc_data) + sizeof (nd->u.shop_item[0]) * pos);
+ 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);
+ //PRINTF("shop npc %s %d read done\n",mapname,nd->bl.id);
npc_shop++;
- nd->bl.type = BL_NPC;
- nd->bl.subtype = SHOP;
- nd->n = map_addnpc (m, nd);
- map_addblock (&nd->bl);
- clif_spawnnpc (nd);
- strdb_insert (npcname_db, nd->name, nd);
+ nd->bl.type = BL::NPC;
+ nd->bl.subtype = NpcSubtype::SHOP;
+ nd->n = map_addnpc(m, nd);
+ map_addblock(&nd->bl);
+ clif_spawnnpc(nd);
+ npcname_db.put(nd->name, nd);
return 0;
}
@@ -1446,36 +1142,26 @@ static int npc_parse_shop (char *w1, char *w2, char *w3, char *w4)
*------------------------------------------
*/
static
-void npc_convertlabel_db (db_key_t key, db_val_t data, va_list ap)
+void npc_convertlabel_db(const std::string& lname, int pos, struct npc_data *nd)
{
- const char *lname = key.s;
- int pos = (int) data;
- struct npc_data *nd;
struct npc_label_list *lst;
- int num;
- // this exists for evil purposes
- char *p = const_cast<char *>(strchr (lname, ':'));
+ int num;
- nullpo_retv (ap);
- nullpo_retv (nd = va_arg (ap, struct npc_data *));
+ nullpo_retv(nd);
lst = nd->u.scr.label_list;
num = nd->u.scr.label_list_num;
if (!lst)
{
lst = (struct npc_label_list *)
- calloc (1, sizeof (struct npc_label_list));
+ calloc(1, sizeof(struct npc_label_list));
num = 0;
}
else
lst = (struct npc_label_list *)
- realloc (lst, sizeof (struct npc_label_list) * (num + 1));
+ realloc(lst, sizeof(struct npc_label_list) * (num + 1));
- *p = '\0';
- // temporarily NUL-terminate lname
- strncpy (lst[num].name, lname, sizeof(lst[num].name)-1);
- lst[num].name[sizeof(lst[num].name)-1] = '\0';
- *p = ':';
+ strzcpy(lst[num].name, lname.c_str(), sizeof(lst[num].name));
lst[num].pos = pos;
nd->u.scr.label_list = lst;
nd->u.scr.label_list_num = num + 1;
@@ -1486,25 +1172,26 @@ void npc_convertlabel_db (db_key_t key, db_val_t data, va_list ap)
*------------------------------------------
*/
static
-int npc_parse_script (char *w1, char *w2, char *w3, char *w4,
+int npc_parse_script(char *w1, char *w2, char *w3, char *w4,
const char *first_line, FILE * fp, int *lines)
{
- int x, y, dir = 0, m, xs = 0, ys = 0, npc_class = 0; // [Valaris] thanks to fov
+ int x, y;
+ DIR dir = DIR::S;
+ int m, xs = 0, ys = 0, npc_class = 0; // [Valaris] thanks to fov
char mapname[24];
char *srcbuf = NULL;
const ScriptCode *script = NULL;
- int srcsize = 65536;
- int startline = 0;
+ int srcsize = 65536;
+ int startline = 0;
char line[1024];
struct npc_data *nd;
- int evflag = 0;
- struct dbt *label_db;
+ int evflag = 0;
char *p;
struct npc_label_list *label_dup = NULL;
- int label_dupnum = 0;
- int src_id = 0;
+ int label_dupnum = 0;
+ int src_id = 0;
- if (strcmp (w1, "-") == 0)
+ if (strcmp(w1, "-") == 0)
{
x = 0;
y = 0;
@@ -1513,22 +1200,25 @@ int npc_parse_script (char *w1, char *w2, char *w3, char *w4,
else
{
// 引数ã®å€‹æ•°ãƒã‚§ãƒƒã‚¯
- if (sscanf (w1, "%[^,],%d,%d,%d", mapname, &x, &y, &dir) != 4 ||
- (strcmp (w2, "script") == 0 && strchr (w4, ',') == NULL))
+ int dir_; // TODO use SSCANF or extract
+ if (sscanf(w1, "%[^,],%d,%d,%d", mapname, &x, &y, &dir_) != 4
+ || dir_ < 0 || dir_ >= 8
+ || (strcmp(w2, "script") == 0 && strchr(w4, ',') == NULL))
{
- printf ("bad script line : %s\n", w3);
+ PRINTF("bad script line : %s\n", w3);
return 1;
}
- m = map_mapname2mapid (mapname);
+ dir = static_cast<DIR>(dir_);
+ m = map_mapname2mapid(mapname);
}
- if (strcmp (w2, "script") == 0)
+ if (strcmp(w2, "script") == 0)
{
// スクリプトã®è§£æž
- srcbuf = (char *) calloc (srcsize, sizeof (char));
- if (strchr (first_line, '{'))
+ srcbuf = (char *) calloc(srcsize, sizeof(char));
+ if (strchr(first_line, '{'))
{
- strcpy (srcbuf, strchr (first_line, '{'));
+ strcpy(srcbuf, strchr(first_line, '{'));
startline = *lines;
}
else
@@ -1536,36 +1226,36 @@ int npc_parse_script (char *w1, char *w2, char *w3, char *w4,
while (1)
{
int i;
- for (i = strlen (srcbuf) - 1; i >= 0 && isspace (srcbuf[i]); i--);
+ for (i = strlen(srcbuf) - 1; i >= 0 && isspace(srcbuf[i]); i--);
if (i >= 0 && srcbuf[i] == '}')
break;
- if (!fgets (line, 1020, fp))
+ if (!fgets(line, 1020, fp))
break;
(*lines)++;
- if (feof (fp))
+ if (feof(fp))
break;
- if (strlen (srcbuf) + strlen (line) + 1 >= srcsize)
+ if (strlen(srcbuf) + strlen(line) + 1 >= srcsize)
{
srcsize += 65536;
- srcbuf = (char *) realloc (srcbuf, srcsize);
- memset (srcbuf + srcsize - 65536, '\0', 65536);
+ srcbuf = (char *) realloc(srcbuf, srcsize);
+ memset(srcbuf + srcsize - 65536, '\0', 65536);
}
if (srcbuf[0] != '{')
{
- if (strchr (line, '{'))
+ if (strchr(line, '{'))
{
- strcpy (srcbuf, strchr (line, '{'));
+ strcpy(srcbuf, strchr(line, '{'));
startline = *lines;
}
}
else
- strcat (srcbuf, line);
+ strcat(srcbuf, line);
}
- script = parse_script (srcbuf, startline);
+ script = parse_script(srcbuf, startline);
if (script == NULL)
{
// script parse error?
- free (srcbuf);
+ free(srcbuf);
return 1;
}
@@ -1576,14 +1266,14 @@ int npc_parse_script (char *w1, char *w2, char *w3, char *w4,
char srcname[128];
struct npc_data *nd2;
- if (sscanf (w2, "duplicate(%[^)])", srcname) != 1)
+ if (sscanf(w2, "duplicate (%[^)])", srcname) != 1)
{
- printf ("bad duplicate name! : %s", w2);
+ PRINTF("bad duplicate name! : %s", w2);
return 0;
}
- if ((nd2 = npc_name2id (srcname)) == NULL)
+ if ((nd2 = npc_name2id(srcname)) == NULL)
{
- printf ("bad duplicate name! (not exist) : %s\n", srcname);
+ PRINTF("bad duplicate name! (not exist) : %s\n", srcname);
return 0;
}
script = nd2->u.scr.script;
@@ -1593,17 +1283,17 @@ int npc_parse_script (char *w1, char *w2, char *w3, char *w4,
} // end of スクリプト解æž
- nd = (struct npc_data *) calloc (1, sizeof (struct npc_data));
+ nd = (struct npc_data *) calloc(1, sizeof(struct npc_data));
if (m == -1)
{
// スクリプトコピー用ã®ãƒ€ãƒŸãƒ¼NPC
}
- else if (sscanf (w4, "%d,%d,%d", &npc_class, &xs, &ys) == 3)
+ else if (sscanf(w4, "%d,%d,%d", &npc_class, &xs, &ys) == 3)
{
// 接触型NPC
- int i, j;
+ int i, j;
if (xs >= 0)
xs = xs * 2 + 1;
@@ -1617,11 +1307,14 @@ int npc_parse_script (char *w1, char *w2, char *w3, char *w4,
{
for (j = 0; j < xs; j++)
{
- int t;
- t = map_getcell (m, x - xs / 2 + j, y - ys / 2 + i);
- if (t == 1 || t == 5)
+ int x_lo = x - xs / 2;
+ int y_lo = y - ys / 2;
+ int xc = x_lo + j;
+ int yc = y_lo + i;
+ MapCell t = map_getcell(m, xc, yc);
+ if (bool(t & MapCell::UNWALKABLE))
continue;
- map_setcell (m, x - xs / 2 + j, y - ys / 2 + i, t | 0x80);
+ map_setcell(m, xc, yc, t | MapCell::NPC_NEAR);
}
}
}
@@ -1631,7 +1324,7 @@ int npc_parse_script (char *w1, char *w2, char *w3, char *w4,
}
else
{ // クリック型NPC
- npc_class = atoi (w4);
+ npc_class = atoi(w4);
nd->u.scr.xs = 0;
nd->u.scr.ys = 0;
}
@@ -1641,7 +1334,7 @@ int npc_parse_script (char *w1, char *w2, char *w3, char *w4,
evflag = 1;
}
- while ((p = strchr (w3, ':')))
+ while ((p = strchr(w3, ':')))
{
if (p[1] == ':')
break;
@@ -1649,53 +1342,52 @@ int npc_parse_script (char *w1, char *w2, char *w3, char *w4,
if (p)
{
*p = 0;
- memcpy (nd->name, w3, 24);
- memcpy (nd->exname, p + 2, 24);
+ memcpy(nd->name, w3, 24);
+ memcpy(nd->exname, p + 2, 24);
}
else
{
- memcpy (nd->name, w3, 24);
- memcpy (nd->exname, w3, 24);
+ memcpy(nd->name, w3, 24);
+ memcpy(nd->exname, w3, 24);
}
nd->bl.prev = nd->bl.next = NULL;
nd->bl.m = m;
nd->bl.x = x;
nd->bl.y = y;
- nd->bl.id = npc_get_new_npc_id ();
+ nd->bl.id = npc_get_new_npc_id();
nd->dir = dir;
nd->flag = 0;
nd->npc_class = npc_class;
- nd->speed = 200;
+ nd->speed = std::chrono::milliseconds(200);
nd->u.scr.script = script;
nd->u.scr.src_id = src_id;
nd->chat_id = 0;
- nd->option = 0;
- nd->opt1 = 0;
- nd->opt2 = 0;
- nd->opt3 = 0;
+ nd->option = Option::ZERO;
+ nd->opt1 = Opt1::ZERO;
+ nd->opt2 = Opt2::ZERO;
+ nd->opt3 = Opt3::ZERO;
- //printf("script npc %s %d %d read done\n",mapname,nd->bl.id,nd->class);
+ //PRINTF("script npc %s %d %d read done\n",mapname,nd->bl.id,nd->class);
npc_script++;
- nd->bl.type = BL_NPC;
- nd->bl.subtype = SCRIPT;
+ nd->bl.type = BL::NPC;
+ nd->bl.subtype = NpcSubtype::SCRIPT;
if (m >= 0)
{
- nd->n = map_addnpc (m, nd);
- map_addblock (&nd->bl);
+ nd->n = map_addnpc(m, nd);
+ map_addblock(&nd->bl);
if (evflag)
{ // イベント型
- struct event_data *ev =
- (struct event_data *) calloc (1, sizeof (struct event_data));
- ev->nd = nd;
- ev->pos = 0;
- strdb_insert (ev_db, nd->exname, ev);
+ struct event_data ev {};
+ ev.nd = nd;
+ ev.pos = 0;
+ ev_db.insert(nd->exname, ev);
}
else
- clif_spawnnpc (nd);
+ clif_spawnnpc(nd);
}
- strdb_insert (npcname_db, nd->exname, nd);
+ npcname_db.put(nd->exname, nd);
//-----------------------------------------
// ラベルデータã®æº–å‚™
@@ -1704,11 +1396,11 @@ int npc_parse_script (char *w1, char *w2, char *w3, char *w4,
// script本体ãŒã‚ã‚‹å ´åˆã®å‡¦ç†
// ラベルデータã®ã‚³ãƒ³ãƒãƒ¼ãƒˆ
- label_db = script_get_label_db ();
- strdb_foreach (label_db, npc_convertlabel_db, nd);
+ for (auto& pair : scriptlabel_db)
+ npc_convertlabel_db(pair.first, pair.second, nd);
// ã‚‚ã†ä½¿ã‚ãªã„ã®ã§ãƒãƒƒãƒ•ã‚¡è§£æ”¾
- free (srcbuf);
+ free(srcbuf);
}
else
@@ -1727,29 +1419,21 @@ int npc_parse_script (char *w1, char *w2, char *w3, char *w4,
for (int i = 0; i < nd->u.scr.label_list_num; i++)
{
char *lname = nd->u.scr.label_list[i].name;
- int pos = nd->u.scr.label_list[i].pos;
+ int pos = nd->u.scr.label_list[i].pos;
if ((lname[0] == 'O' || lname[0] == 'o')
&& (lname[1] == 'N' || lname[1] == 'n'))
{
- struct event_data *ev;
- char *buf;
- // エクスãƒãƒ¼ãƒˆã•ã‚Œã‚‹
- ev = (struct event_data *) calloc (1,
- sizeof (struct event_data));
- buf = (char *) calloc (50, sizeof (char));
- if (strlen (lname) > 24)
+ if (strlen(lname) > 24)
{
- printf ("npc_parse_script: label name error !\n");
- exit (1);
- }
- else
- {
- ev->nd = nd;
- ev->pos = pos;
- sprintf (buf, "%s::%s", nd->exname, lname);
- strdb_insert (ev_db, buf, ev);
+ PRINTF("npc_parse_script: label name error !\n");
+ exit(1);
}
+ struct event_data ev {};
+ ev.nd = nd;
+ ev.pos = pos;
+ std::string buf = STRPRINTF("%s::%s", nd->exname, lname);
+ ev_db.insert(buf, ev);
}
}
@@ -1757,29 +1441,30 @@ int npc_parse_script (char *w1, char *w2, char *w3, char *w4,
// ラベルデータã‹ã‚‰ã‚¿ã‚¤ãƒžãƒ¼ã‚¤ãƒ™ãƒ³ãƒˆå–ã‚Šè¾¼ã¿
for (int i = 0; i < nd->u.scr.label_list_num; i++)
{
- int t = 0, n = 0;
+ int t_ = 0, n = 0;
char *lname = nd->u.scr.label_list[i].name;
- int pos = nd->u.scr.label_list[i].pos;
- if (sscanf (lname, "OnTimer%d%n", &t, &n) == 1 && lname[n] == '\0')
+ int pos = nd->u.scr.label_list[i].pos;
+ if (sscanf(lname, "OnTimer%d%n", &t_, &n) == 1 && lname[n] == '\0')
{
+ interval_t t = static_cast<interval_t>(t_);
// タイマーイベント
struct npc_timerevent_list *te = nd->u.scr.timer_event;
- int j, k = nd->u.scr.timeramount;
+ int j, k = nd->u.scr.timeramount;
if (te == NULL)
- te = (struct npc_timerevent_list *) calloc (1,
- sizeof (struct
+ te = (struct npc_timerevent_list *) calloc(1,
+ sizeof(struct
npc_timerevent_list));
else
- te = (struct npc_timerevent_list *) realloc (te,
- sizeof (struct
+ te = (struct npc_timerevent_list *) realloc(te,
+ sizeof(struct
npc_timerevent_list)
* (k + 1));
for (j = 0; j < k; j++)
{
if (te[j].timer > t)
{
- memmove (te + j + 1, te + j,
- sizeof (struct npc_timerevent_list) * (k - j));
+ memmove(te + j + 1, te + j,
+ sizeof(struct npc_timerevent_list) * (k - j));
break;
}
}
@@ -1790,7 +1475,7 @@ int npc_parse_script (char *w1, char *w2, char *w3, char *w4,
}
}
nd->u.scr.nexttimer = -1;
- nd->u.scr.timerid = -1;
+ // nd->u.scr.timerid = nullptr;
return 0;
}
@@ -1799,73 +1484,66 @@ int npc_parse_script (char *w1, char *w2, char *w3, char *w4,
* function行解æž
*------------------------------------------
*/
-static int npc_parse_function (char *w1, char *w2, char *w3, char *w4,
+static
+int npc_parse_function(char *, char *, char *w3, char *,
char *first_line, FILE * fp, int *lines)
{
char *srcbuf = NULL;
const ScriptCode *script;
- int srcsize = 65536;
- int startline = 0;
+ int srcsize = 65536;
+ int startline = 0;
char line[1024];
- int i;
-// struct dbt *label_db;
- char *p;
+ int i;
// スクリプトã®è§£æž
- srcbuf = (char *) calloc (srcsize, sizeof (char));
- if (strchr (first_line, '{'))
+ srcbuf = (char *) calloc(srcsize, sizeof(char));
+ if (strchr(first_line, '{'))
{
- strcpy (srcbuf, strchr (first_line, '{'));
+ strcpy(srcbuf, strchr(first_line, '{'));
startline = *lines;
}
else
srcbuf[0] = 0;
while (1)
{
- for (i = strlen (srcbuf) - 1; i >= 0 && isspace (srcbuf[i]); i--);
+ for (i = strlen(srcbuf) - 1; i >= 0 && isspace(srcbuf[i]); i--);
if (i >= 0 && srcbuf[i] == '}')
break;
- if (!fgets (line, 1020, fp))
+ if (!fgets(line, 1020, fp))
break;
(*lines)++;
- if (feof (fp))
+ if (feof(fp))
break;
- if (strlen (srcbuf) + strlen (line) + 1 >= srcsize)
+ if (strlen(srcbuf) + strlen(line) + 1 >= srcsize)
{
srcsize += 65536;
- srcbuf = (char *) realloc (srcbuf, srcsize);
- memset (srcbuf + srcsize - 65536, '\0', 65536);
+ srcbuf = (char *) realloc(srcbuf, srcsize);
+ memset(srcbuf + srcsize - 65536, '\0', 65536);
}
if (srcbuf[0] != '{')
{
- if (strchr (line, '{'))
+ if (strchr(line, '{'))
{
- strcpy (srcbuf, strchr (line, '{'));
+ strcpy(srcbuf, strchr(line, '{'));
startline = *lines;
}
}
else
- strcat (srcbuf, line);
+ strcat(srcbuf, line);
}
- script = parse_script (srcbuf, startline);
+ script = parse_script(srcbuf, startline);
if (script == NULL)
{
// script parse error?
- free (srcbuf);
+ free(srcbuf);
return 1;
}
- p = (char *) calloc (50, sizeof (char));
-
- strncpy (p, w3, 49);
- strdb_insert (script_get_userfunc_db (), p, script);
-
-// label_db=script_get_label_db();
+ std::string p = w3;
+ userfunc_db.put(p, script);
// ã‚‚ã†ä½¿ã‚ãªã„ã®ã§ãƒãƒƒãƒ•ã‚¡è§£æ”¾
- free (srcbuf);
-
-// printf("function %s => %p\n",p,script);
+ free(srcbuf);
return 0;
}
@@ -1874,26 +1552,29 @@ static int npc_parse_function (char *w1, char *w2, char *w3, char *w4,
* mob行解æž
*------------------------------------------
*/
-int npc_parse_mob (const char *w1, const char *w2, const char *w3, const char *w4)
+static
+int npc_parse_mob(const char *w1, const char *, const char *w3, const char *w4)
{
- int m, x, y, xs, ys, mob_class, num, delay1, delay2;
- int i;
+ int m, x, y, xs, ys, mob_class, num;
+ int i;
char mapname[24];
char eventname[24] = "";
struct mob_data *md;
xs = ys = 0;
- delay1 = delay2 = 0;
+ int delay1_ = 0, delay2_ = 0;
// 引数ã®å€‹æ•°ãƒã‚§ãƒƒã‚¯
- if (sscanf (w1, "%[^,],%d,%d,%d,%d", mapname, &x, &y, &xs, &ys) < 3 ||
- sscanf (w4, "%d,%d,%d,%d,%s", &mob_class, &num, &delay1, &delay2,
+ if (sscanf(w1, "%[^,],%d,%d,%d,%d", mapname, &x, &y, &xs, &ys) < 3 ||
+ sscanf(w4, "%d,%d,%d,%d,%s", &mob_class, &num, &delay1_, &delay2_,
eventname) < 2)
{
- printf ("bad monster line : %s\n", w3);
+ PRINTF("bad monster line : %s\n", w3);
return 1;
}
+ interval_t delay1 = std::chrono::milliseconds(delay1_);
+ interval_t delay2 = std::chrono::milliseconds(delay2_);
- m = map_mapname2mapid (mapname);
+ m = map_mapname2mapid(mapname);
if (num > 1 && battle_config.mob_count_rate != 100)
{
@@ -1903,23 +1584,23 @@ int npc_parse_mob (const char *w1, const char *w2, const char *w3, const char *w
for (i = 0; i < num; i++)
{
- md = (struct mob_data *) calloc (1, sizeof (struct mob_data));
+ md = (struct mob_data *) calloc(1, sizeof(struct mob_data));
md->bl.prev = NULL;
md->bl.next = NULL;
md->bl.m = m;
md->bl.x = x;
md->bl.y = y;
- if (strcmp (w3, "--en--") == 0)
- memcpy (md->name, mob_db[mob_class].name, 24);
- else if (strcmp (w3, "--ja--") == 0)
- memcpy (md->name, mob_db[mob_class].jname, 24);
+ if (strcmp(w3, "--en--") == 0)
+ memcpy(md->name, mob_db[mob_class].name, 24);
+ else if (strcmp(w3, "--ja--") == 0)
+ memcpy(md->name, mob_db[mob_class].jname, 24);
else
- memcpy (md->name, w3, 24);
+ memcpy(md->name, w3, 24);
md->n = i;
- md->base_class = md->mob_class = mob_class;
- md->bl.id = npc_get_new_npc_id ();
+ md->mob_class = mob_class;
+ md->bl.id = npc_get_new_npc_id();
md->m = m;
md->x0 = x;
md->y0 = y;
@@ -1928,31 +1609,31 @@ int npc_parse_mob (const char *w1, const char *w2, const char *w3, const char *w
md->spawndelay1 = delay1;
md->spawndelay2 = delay2;
- memset (&md->state, 0, sizeof (md->state));
- md->timer = -1;
+ memset(&md->state, 0, sizeof(md->state));
+ // md->timer = nullptr;
md->target_id = 0;
md->attacked_id = 0;
- if (mob_db[mob_class].mode & 0x02)
+ if (bool(mob_db[mob_class].mode & MobMode::LOOTER))
md->lootitem =
- (struct item *) calloc (LOOTITEM_SIZE, sizeof (struct item));
+ (struct item *) calloc(LOOTITEM_SIZE, sizeof(struct item));
else
md->lootitem = NULL;
- if (strlen (eventname) >= 4)
+ if (strlen(eventname) >= 4)
{
- memcpy (md->npc_event, eventname, 24);
+ memcpy(md->npc_event, eventname, 24);
}
else
- memset (md->npc_event, 0, 24);
+ memset(md->npc_event, 0, 24);
- md->bl.type = BL_MOB;
- map_addiddb (&md->bl);
- mob_spawn (md->bl.id);
+ md->bl.type = BL::MOB;
+ map_addiddb(&md->bl);
+ mob_spawn(md->bl.id);
npc_mob++;
}
- //printf("warp npc %s %d read done\n",mapname,nd->bl.id);
+ //PRINTF("warp npc %s %d read done\n",mapname,nd->bl.id);
return 0;
}
@@ -1961,175 +1642,125 @@ int npc_parse_mob (const char *w1, const char *w2, const char *w3, const char *w
* マップフラグ行ã®è§£æž
*------------------------------------------
*/
-static int npc_parse_mapflag (char *w1, char *w2, char *w3, char *w4)
+static
+int npc_parse_mapflag(char *w1, char *, char *w3, char *w4)
{
- int m;
+ int m;
char mapname[24], savemap[16];
- int savex, savey;
- char drop_arg1[16], drop_arg2[16];
- int drop_id = 0, drop_type = 0, drop_per = 0;
+ int savex, savey;
// 引数ã®å€‹æ•°ãƒã‚§ãƒƒã‚¯
// if ( sscanf(w1,"%[^,],%d,%d,%d",mapname,&x,&y,&dir) != 4 )
- if (sscanf (w1, "%[^,]", mapname) != 1)
+ if (sscanf(w1, "%[^,]", mapname) != 1)
return 1;
- m = map_mapname2mapid (mapname);
+ m = map_mapname2mapid(mapname);
if (m < 0)
return 1;
//マップフラグ
- if (strcasecmp (w3, "nosave") == 0)
+ if (strcasecmp(w3, "nosave") == 0)
{
- if (strcmp (w4, "SavePoint") == 0)
+ if (strcmp(w4, "SavePoint") == 0)
{
- memcpy (map[m].save.map, "SavePoint", 16);
+ memcpy(map[m].save.map, "SavePoint", 16);
map[m].save.x = -1;
map[m].save.y = -1;
}
- else if (sscanf (w4, "%[^,],%d,%d", savemap, &savex, &savey) == 3)
+ else if (sscanf(w4, "%[^,],%d,%d", savemap, &savex, &savey) == 3)
{
- memcpy (map[m].save.map, savemap, 16);
+ memcpy(map[m].save.map, savemap, 16);
map[m].save.x = savex;
map[m].save.y = savey;
}
map[m].flag.nosave = 1;
}
- else if (strcasecmp (w3, "nomemo") == 0)
+ else if (strcasecmp(w3, "nomemo") == 0)
{
map[m].flag.nomemo = 1;
}
- else if (strcasecmp (w3, "noteleport") == 0)
+ else if (strcasecmp(w3, "noteleport") == 0)
{
map[m].flag.noteleport = 1;
}
- else if (strcasecmp (w3, "nowarp") == 0)
+ else if (strcasecmp(w3, "nowarp") == 0)
{
map[m].flag.nowarp = 1;
}
- else if (strcasecmp (w3, "nowarpto") == 0)
+ else if (strcasecmp(w3, "nowarpto") == 0)
{
map[m].flag.nowarpto = 1;
}
- else if (strcasecmp (w3, "noreturn") == 0)
+ else if (strcasecmp(w3, "noreturn") == 0)
{
map[m].flag.noreturn = 1;
}
- else if (strcasecmp (w3, "monster_noteleport") == 0)
+ else if (strcasecmp(w3, "monster_noteleport") == 0)
{
map[m].flag.monster_noteleport = 1;
}
- else if (strcasecmp (w3, "nobranch") == 0)
+ else if (strcasecmp(w3, "nobranch") == 0)
{
map[m].flag.nobranch = 1;
}
- else if (strcasecmp (w3, "nopenalty") == 0)
+ else if (strcasecmp(w3, "nopenalty") == 0)
{
map[m].flag.nopenalty = 1;
}
- else if (strcasecmp (w3, "pvp") == 0)
+ else if (strcasecmp(w3, "pvp") == 0)
{
map[m].flag.pvp = 1;
}
- else if (strcasecmp (w3, "pvp_noparty") == 0)
+ else if (strcasecmp(w3, "pvp_noparty") == 0)
{
map[m].flag.pvp_noparty = 1;
}
- else if (strcasecmp (w3, "pvp_noguild") == 0)
- {
- map[m].flag.pvp_noguild = 1;
- }
- else if (strcasecmp (w3, "pvp_nightmaredrop") == 0)
- {
- if (sscanf (w4, "%[^,],%[^,],%d", drop_arg1, drop_arg2, &drop_per) ==
- 3)
- {
- int i;
- if (strcmp (drop_arg1, "random") == 0)
- drop_id = -1;
- else if (itemdb_exists ((drop_id = atoi (drop_arg1))) == NULL)
- drop_id = 0;
- if (strcmp (drop_arg2, "inventory") == 0)
- drop_type = 1;
- else if (strcmp (drop_arg2, "equip") == 0)
- drop_type = 2;
- else if (strcmp (drop_arg2, "all") == 0)
- drop_type = 3;
-
- if (drop_id != 0)
- {
- for (i = 0; i < MAX_DROP_PER_MAP; i++)
- {
- if (map[m].drop_list[i].drop_id == 0)
- {
- map[m].drop_list[i].drop_id = drop_id;
- map[m].drop_list[i].drop_type = drop_type;
- map[m].drop_list[i].drop_per = drop_per;
- break;
- }
- }
- map[m].flag.pvp_nightmaredrop = 1;
- }
- }
- }
- else if (strcasecmp (w3, "pvp_nocalcrank") == 0)
+ else if (strcasecmp(w3, "pvp_nocalcrank") == 0)
{
map[m].flag.pvp_nocalcrank = 1;
}
- else if (strcasecmp (w3, "gvg") == 0)
- {
- map[m].flag.gvg = 1;
- }
- else if (strcasecmp (w3, "gvg_noparty") == 0)
- {
- map[m].flag.gvg_noparty = 1;
- }
- else if (strcasecmp (w3, "nozenypenalty") == 0)
+ else if (strcasecmp(w3, "nozenypenalty") == 0)
{
map[m].flag.nozenypenalty = 1;
}
- else if (strcasecmp (w3, "notrade") == 0)
+ else if (strcasecmp(w3, "notrade") == 0)
{
map[m].flag.notrade = 1;
}
- else if (strcasecmp (w3, "noskill") == 0)
- {
- map[m].flag.noskill = 1;
- }
- else if (battle_config.pk_mode && strcasecmp (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 (strcasecmp (w3, "noicewall") == 0)
+ else if (strcasecmp(w3, "noicewall") == 0)
{ // noicewall [Valaris]
map[m].flag.noicewall = 1;
}
- else if (strcasecmp (w3, "snow") == 0)
+ else if (strcasecmp(w3, "snow") == 0)
{ // snow [Valaris]
map[m].flag.snow = 1;
}
- else if (strcasecmp (w3, "fog") == 0)
+ else if (strcasecmp(w3, "fog") == 0)
{ // fog [Valaris]
map[m].flag.fog = 1;
}
- else if (strcasecmp (w3, "sakura") == 0)
+ else if (strcasecmp(w3, "sakura") == 0)
{ // sakura [Valaris]
map[m].flag.sakura = 1;
}
- else if (strcasecmp (w3, "leaves") == 0)
+ else if (strcasecmp(w3, "leaves") == 0)
{ // leaves [Valaris]
map[m].flag.leaves = 1;
}
- else if (strcasecmp (w3, "rain") == 0)
+ else if (strcasecmp(w3, "rain") == 0)
{ // rain [Valaris]
map[m].flag.rain = 1;
}
- else if (strcasecmp (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 (strcasecmp (w3, "town") == 0)
+ else if (strcasecmp(w3, "town") == 0)
{ // town/safe zone [remoitnane]
map[m].flag.town = 1;
}
@@ -2137,177 +1768,119 @@ static int npc_parse_mapflag (char *w1, char *w2, char *w3, char *w4)
return 0;
}
-static void ev_db_final (db_key_t key, db_val_t data, va_list ap)
-{
- free (data);
- if (strstr (key.s, "::") != NULL)
- free ((char*)key.s);
-}
-
-struct npc_data *npc_spawn_text (int m, int x, int y,
+struct npc_data *npc_spawn_text(int m, int x, int y,
int npc_class, const char *name, const char *message)
{
struct npc_data *retval =
- (struct npc_data *) calloc (1, sizeof (struct npc_data));
- retval->bl.id = npc_get_new_npc_id ();
+ (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;
retval->bl.m = m;
- retval->bl.type = BL_NPC;
- retval->bl.subtype = MESSAGE;
+ retval->bl.type = BL::NPC;
+ retval->bl.subtype = NpcSubtype::MESSAGE;
- strncpy (retval->name, name, 23);
- strncpy (retval->exname, name, 23);
+ strncpy(retval->name, name, 23);
+ strncpy(retval->exname, name, 23);
retval->name[15] = 0;
retval->exname[15] = 0;
- retval->u.message = message ? strdup (message) : NULL;
+ retval->u.message = message ? strdup(message) : NULL;
retval->npc_class = npc_class;
- retval->speed = 200;
+ retval->speed = std::chrono::milliseconds(200);
- clif_spawnnpc (retval);
- map_addblock (&retval->bl);
- map_addiddb (&retval->bl);
+ clif_spawnnpc(retval);
+ map_addblock(&retval->bl);
+ map_addiddb(&retval->bl);
if (retval->name && retval->name[0])
- strdb_insert (npcname_db, retval->name, retval);
+ npcname_db.put(retval->name, retval);
return retval;
}
-static void npc_free_internal (struct npc_data *nd)
+static
+void npc_free_internal(struct npc_data *nd)
{
struct chat_data *cd;
- if (nd->chat_id && (cd = (struct chat_data *) map_id2bl (nd->chat_id)))
+ if (nd->chat_id && (cd = (struct chat_data *) map_id2bl(nd->chat_id)))
{
- free (cd);
+ free(cd);
cd = NULL;
}
- if (nd->bl.subtype == SCRIPT)
+ if (nd->bl.subtype == NpcSubtype::SCRIPT)
{
if (nd->u.scr.timer_event)
- free (nd->u.scr.timer_event);
+ free(nd->u.scr.timer_event);
if (nd->u.scr.src_id == 0)
{
if (nd->u.scr.script)
{
- free (const_cast<ScriptCode *>(nd->u.scr.script));
+ free(const_cast<ScriptCode *>(nd->u.scr.script));
nd->u.scr.script = NULL;
}
if (nd->u.scr.label_list)
{
- free (nd->u.scr.label_list);
+ free(nd->u.scr.label_list);
nd->u.scr.label_list = NULL;
}
}
}
- else if (nd->bl.subtype == MESSAGE && nd->u.message)
+ else if (nd->bl.subtype == NpcSubtype::MESSAGE && nd->u.message)
{
- free (nd->u.message);
+ free(nd->u.message);
}
- free (nd);
+ free(nd);
}
static
-void npc_propagate_update (struct npc_data *nd)
-{
- map_foreachinarea (npc_enable_sub,
- nd->bl.m,
- nd->bl.x - nd->u.scr.xs, nd->bl.y - nd->u.scr.ys,
- nd->bl.x + nd->u.scr.xs, nd->bl.y + nd->u.scr.ys,
- BL_PC, nd);
-}
-
-void npc_free (struct npc_data *nd)
+void npc_propagate_update(struct npc_data *nd)
{
- clif_clearchar (&nd->bl, 0);
- npc_propagate_update (nd);
- map_deliddb (&nd->bl);
- map_delblock (&nd->bl);
- npc_free_internal (nd);
+ map_foreachinarea(std::bind(npc_enable_sub, ph::_1, nd),
+ nd->bl.m, nd->bl.x - nd->u.scr.xs, nd->bl.y - nd->u.scr.ys,
+ nd->bl.x + nd->u.scr.xs, nd->bl.y + nd->u.scr.ys, BL::PC);
}
-/*==========================================
- * 終了
- *------------------------------------------
- */
-int do_final_npc (void)
+void npc_free(struct npc_data *nd)
{
- int i;
- struct block_list *bl;
- struct npc_data *nd;
- struct mob_data *md;
-
- 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++)
- {
- if ((bl = map_id2bl (i)))
- {
- if (bl->type == BL_NPC && (nd = (struct npc_data *) bl))
- npc_free_internal (nd);
- else if (bl->type == BL_MOB && (md = (struct mob_data *) bl))
- {
- if (md->lootitem)
- {
- free (md->lootitem);
- md->lootitem = NULL;
- }
- free (md);
- md = NULL;
- }
- }
- }
-
- return 0;
-}
-
-static
-void ev_release (db_key_t key, db_val_t val)
-{
- free ((char*)key.s);
- free (val);
+ clif_clearchar(&nd->bl, BeingRemoveWhy::GONE);
+ npc_propagate_update(nd);
+ map_deliddb(&nd->bl);
+ map_delblock(&nd->bl);
+ npc_free_internal(nd);
}
/*==========================================
* npcåˆæœŸåŒ–
*------------------------------------------
*/
-int do_init_npc (void)
+int do_init_npc(void)
{
struct npc_src_list *nsl;
FILE *fp;
char line[1024];
- int m, lines;
-
- ev_db = strdb_init (24);
- npcname_db = strdb_init (24);
-
- ev_db->release = ev_release;
+ int m, lines;
- memset (&ev_tm_b, -1, sizeof (ev_tm_b));
+ memset(&ev_tm_b, -1, sizeof(ev_tm_b));
for (nsl = npc_src_first; nsl; nsl = nsl->next)
{
if (nsl->prev)
{
- free (nsl->prev);
+ free(nsl->prev);
nsl->prev = NULL;
}
- fp = fopen_ (nsl->name, "r");
+ fp = fopen_(nsl->name, "r");
if (fp == NULL)
{
- printf ("file not found : %s\n", nsl->name);
- exit (1);
+ PRINTF("file not found : %s\n", nsl->name);
+ exit(1);
}
lines = 0;
- while (fgets (line, 1020, fp))
+ while (fgets(line, 1020, fp))
{
char w1[1024], w2[1024], w3[1024], w4[1024], mapname[1024];
- int i, j, w4pos, count;
+ int i, j, w4pos, count;
lines++;
if (line[0] == '/' && line[1] == '/')
@@ -2319,7 +1892,7 @@ int do_init_npc (void)
{
if (!
((line[i + 1]
- && (isspace (line[i + 1]) || line[i + 1] == ','))
+ && (isspace(line[i + 1]) || line[i + 1] == ','))
|| (j && line[j - 1] == ',')))
line[j++] = ' ';
}
@@ -2333,67 +1906,67 @@ int do_init_npc (void)
}
// 最åˆã¯ã‚¿ãƒ–区切りã§ãƒã‚§ãƒƒã‚¯ã—ã¦ã¿ã¦ã€ãƒ€ãƒ¡ãªã‚‰ã‚¹ãƒšãƒ¼ã‚¹åŒºåˆ‡ã‚Šã§ç¢ºèª
if ((count =
- sscanf (line, "%[^\t]\t%[^\t]\t%[^\t\r\n]\t%n%[^\t\r\n]", w1,
+ sscanf(line, "%[^\t]\t%[^\t]\t%[^\t\r\n]\t%n%[^\t\r\n]", w1,
w2, w3, &w4pos, w4)) < 3
&& (count =
- sscanf (line, "%s%s%s%n%s", w1, w2, w3, &w4pos, w4)) < 3)
+ sscanf(line, "%s%s%s%n%s", w1, w2, w3, &w4pos, w4)) < 3)
{
continue;
}
// マップã®å­˜åœ¨ç¢ºèª
- if (strcmp (w1, "-") != 0 && strcasecmp (w1, "function") != 0)
+ if (strcmp(w1, "-") != 0 && strcasecmp(w1, "function") != 0)
{
- sscanf (w1, "%[^,]", mapname);
- m = map_mapname2mapid (mapname);
- if (strlen (mapname) > 16 || m < 0)
+ sscanf(w1, "%[^,]", mapname);
+ m = map_mapname2mapid(mapname);
+ if (strlen(mapname) > 16 || m < 0)
{
// "mapname" is not assigned to this server
continue;
}
}
- if (strcasecmp (w2, "warp") == 0 && count > 3)
+ if (strcasecmp(w2, "warp") == 0 && count > 3)
{
- npc_parse_warp (w1, w2, w3, w4);
+ npc_parse_warp(w1, w2, w3, w4);
}
- else if (strcasecmp (w2, "shop") == 0 && count > 3)
+ else if (strcasecmp(w2, "shop") == 0 && count > 3)
{
- npc_parse_shop (w1, w2, w3, w4);
+ npc_parse_shop(w1, w2, w3, w4);
}
- else if (strcasecmp (w2, "script") == 0 && count > 3)
+ else if (strcasecmp(w2, "script") == 0 && count > 3)
{
- if (strcasecmp (w1, "function") == 0)
+ if (strcasecmp(w1, "function") == 0)
{
- npc_parse_function (w1, w2, w3, w4, line + w4pos, fp,
+ npc_parse_function(w1, w2, w3, w4, line + w4pos, fp,
&lines);
}
else
{
- npc_parse_script (w1, w2, w3, w4, line + w4pos, fp,
+ npc_parse_script(w1, w2, w3, w4, line + w4pos, fp,
&lines);
}
}
else if ((i =
- 0, sscanf (w2, "duplicate%n", &i), (i > 0
+ 0, sscanf(w2, "duplicate%n", &i), (i > 0
&& w2[i] == '('))
&& count > 3)
{
- npc_parse_script (w1, w2, w3, w4, line + w4pos, fp, &lines);
+ npc_parse_script(w1, w2, w3, w4, line + w4pos, fp, &lines);
}
- else if (strcasecmp (w2, "monster") == 0 && count > 3)
+ else if (strcasecmp(w2, "monster") == 0 && count > 3)
{
- npc_parse_mob (w1, w2, w3, w4);
+ npc_parse_mob(w1, w2, w3, w4);
}
- else if (strcasecmp (w2, "mapflag") == 0 && count >= 3)
+ else if (strcasecmp(w2, "mapflag") == 0 && count >= 3)
{
- npc_parse_mapflag (w1, w2, w3, w4);
+ npc_parse_mapflag(w1, w2, w3, w4);
}
}
- fclose_ (fp);
- printf ("\rLoading NPCs [%d]: %-54s", npc_id - START_NPC_NUM,
+ fclose_(fp);
+ PRINTF("\rLoading NPCs [%d]: %-54s", npc_id - START_NPC_NUM,
nsl->name);
- fflush (stdout);
+ fflush(stdout);
}
- printf ("\rNPCs Loaded: %d [Warps:%d Shops:%d Scripts:%d Mobs:%d]\n",
+ 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);
return 0;
diff --git a/src/map/npc.hpp b/src/map/npc.hpp
index 6204316..bedca83 100644
--- a/src/map/npc.hpp
+++ b/src/map/npc.hpp
@@ -1,64 +1,71 @@
-// $Id: npc.h,v 1.5 2004/09/25 11:39:17 MouseJstr Exp $
#ifndef NPC_HPP
#define NPC_HPP
-#define START_NPC_NUM 110000000
+#include <cstddef>
+#include <cstdint>
-#define WARP_CLASS 45
-#define WARP_DEBUG_CLASS 722
-#define INVISIBLE_CLASS 32767
+#include "../common/timer.t.hpp"
-int npc_event_dequeue (struct map_session_data *sd);
-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, const char *npcname, const char *command);
-int npc_touch_areanpc (struct map_session_data *, int, int, int);
-int npc_click (struct map_session_data *, int);
-int npc_scriptcont (struct map_session_data *, int);
-int npc_checknear (struct map_session_data *, int);
-int npc_buysellsel (struct map_session_data *, int, int);
-int npc_buylist (struct map_session_data *, int, unsigned short *);
-int npc_selllist (struct map_session_data *, int, unsigned short *);
-int npc_parse_mob (const char *w1, const char *w2, const char *w3, const char *w4);
-int npc_parse_warp (const char *w1, const char *w2, const char *w3, const char *w4);
+constexpr int START_NPC_NUM = 110000000;
-int npc_enable (const char *name, int flag);
-struct npc_data *npc_name2id (const char *name);
+constexpr int WARP_CLASS = 45;
+constexpr int WARP_DEBUG_CLASS = 722;
+constexpr int INVISIBLE_CLASS = 32767;
-int npc_get_new_npc_id (void);
+int npc_event_dequeue(struct map_session_data *sd);
+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, const char *npcname, const char *command);
+int npc_touch_areanpc(struct map_session_data *, int, int, int);
+int npc_click(struct map_session_data *, int);
+int npc_scriptcont(struct map_session_data *, int);
+int npc_buysellsel(struct map_session_data *, int, int);
+int npc_buylist(struct map_session_data *, int, const uint16_t *);
+int npc_selllist(struct map_session_data *, int, const uint16_t *);
+int npc_parse_warp(const char *w1, const char *w2, const char *w3, const char *w4);
+
+int npc_enable(const char *name, bool flag);
+struct npc_data *npc_name2id(const char *name);
+
+int npc_get_new_npc_id(void);
/**
* Spawns and installs a talk-only NPC
*
* \param message The message to speak. If message is NULL, the NPC will not do anything at all.
*/
-struct npc_data *npc_spawn_text (int m, int x, int y, int class_, const char *name, const char *message); // message is strdup'd within
+struct npc_data *npc_spawn_text(int m, int x, int y, int class_, const char *name, const char *message); // message is strdup'd within
/**
* Uninstalls and frees an NPC
*/
-void npc_free (struct npc_data *npc);
+void npc_free(struct npc_data *npc);
-void npc_addsrcfile (char *);
-void npc_delsrcfile (char *);
-int do_final_npc (void);
-int do_init_npc (void);
-int npc_event_do_oninit (void);
-int npc_do_ontimer (int, struct map_session_data *, int);
+void npc_addsrcfile(const char *);
+void npc_delsrcfile(const char *);
+int do_init_npc(void);
+int npc_event_do_oninit(void);
struct argrec;
-int npc_event_doall_l (const char *name, int rid, int argc,
- struct argrec *argv);
-int npc_event_do_l (const char *name, int rid, int argc,
- struct argrec *argv);
-#define npc_event_doall(name) npc_event_doall_l(name, 0, 0, NULL)
-#define npc_event_do(name) npc_event_do_l(name, 0, 0, NULL)
+int npc_event_doall_l(const char *name, int rid,
+ int argc, struct argrec *argv);
+int npc_event_do_l(const char *name, int rid,
+ int argc, struct argrec *argv);
+inline
+int npc_event_doall(const char *name)
+{
+ return npc_event_doall_l(name, 0, 0, NULL);
+}
+inline
+int npc_event_do(const char *name)
+{
+ return npc_event_do_l(name, 0, 0, NULL);
+}
-int npc_timerevent_start (struct npc_data *nd);
-int npc_timerevent_stop (struct npc_data *nd);
-int npc_gettimerevent_tick (struct npc_data *nd);
-int npc_settimerevent_tick (struct npc_data *nd, int newtimer);
-int npc_delete (struct npc_data *nd);
+int npc_timerevent_start(struct npc_data *nd);
+int npc_timerevent_stop(struct npc_data *nd);
+interval_t npc_gettimerevent_tick(struct npc_data *nd);
+int npc_settimerevent_tick(struct npc_data *nd, interval_t newtimer);
+int npc_delete(struct npc_data *nd);
-#endif
+#endif // NPC_HPP
diff --git a/src/map/party.cpp b/src/map/party.cpp
index 95763b8..f737601 100644
--- a/src/map/party.cpp
+++ b/src/map/party.cpp
@@ -1,151 +1,135 @@
-// $Id: party.c,v 1.2 2004/09/22 02:59:47 Akitasha Exp $
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
#include "party.hpp"
+
+#include <cstring>
+
+#include "../common/cxxstdio.hpp"
#include "../common/db.hpp"
-#include "../common/timer.hpp"
-#include "../common/socket.hpp"
#include "../common/nullpo.hpp"
-#include "pc.hpp"
-#include "map.hpp"
+#include "../common/socket.hpp"
+#include "../common/timer.hpp"
+
#include "battle.hpp"
-#include "intif.hpp"
#include "clif.hpp"
-#include "skill.hpp"
+#include "intif.hpp"
+#include "map.hpp"
+#include "pc.hpp"
#include "tmw.hpp"
-#ifdef MEMWATCH
-#include "memwatch.hpp"
-#endif
-
-#define PARTY_SEND_XYHP_INVERVAL 1000 // 座標やHPé€ä¿¡ã®é–“éš”
+#include "../poison.hpp"
-static struct dbt *party_db;
+// 座標やHPé€ä¿¡ã®é–“éš”
+constexpr interval_t PARTY_SEND_XYHP_INVERVAL = std::chrono::seconds(1);
-void party_send_xyhp_timer (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data);
-/*==========================================
- * 終了
- *------------------------------------------
- */
-static void party_db_final (db_key_t key, db_val_t data, va_list ap)
-{
- free (data);
-}
+static
+Map<int, struct party> party_db;
-void do_final_party (void)
-{
- if (party_db)
- numdb_final (party_db, party_db_final);
-}
+static
+int party_check_conflict(struct map_session_data *sd);
+static
+void party_send_xyhp_timer(TimerData *tid, tick_t tick);
// åˆæœŸåŒ–
-void do_init_party (void)
+void do_init_party(void)
{
- party_db = numdb_init ();
- add_timer_interval (gettick () + PARTY_SEND_XYHP_INVERVAL,
- party_send_xyhp_timer, 0, 0,
- PARTY_SEND_XYHP_INVERVAL);
+ Timer(gettick() + PARTY_SEND_XYHP_INVERVAL,
+ party_send_xyhp_timer,
+ PARTY_SEND_XYHP_INVERVAL
+ ).detach();
}
// 検索
-struct party *party_search (int party_id)
+struct party *party_search(int party_id)
{
- return (struct party *)numdb_search (party_db, party_id);
+ return party_db.search(party_id);
}
static
-void party_searchname_sub (db_key_t key, db_val_t data, va_list ap)
+void party_searchname_sub(struct party *p, const char *str, struct party **dst)
{
- struct party *p = (struct party *) data, **dst;
- const char *str;
- str = va_arg (ap, const char *);
- dst = va_arg (ap, struct party **);
- if (strcasecmp (p->name, str) == 0)
+ if (strcasecmp(p->name, str) == 0)
*dst = p;
}
// パーティå検索
-struct party *party_searchname (const char *str)
+struct party *party_searchname(const char *str)
{
struct party *p = NULL;
- numdb_foreach (party_db, party_searchname_sub, str, &p);
+ for (auto& pair : party_db)
+ party_searchname_sub(&pair.second, str, &p);
return p;
}
/* Process a party creation request. */
-int party_create (struct map_session_data *sd, const char *name)
+int party_create(struct map_session_data *sd, const char *name)
{
char pname[24];
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
- strncpy (pname, name, 24);
+ strncpy(pname, name, 24);
pname[23] = '\0';
- tmw_TrimStr (pname);
+ tmw_TrimStr(pname);
/* The party name is empty/invalid. */
if (!*pname)
- clif_party_created (sd, 1);
+ clif_party_created(sd, 1);
/* Make sure the character isn't already in a party. */
if (sd->status.party_id == 0)
- intif_create_party (sd, pname);
+ intif_create_party(sd, pname);
else
- clif_party_created (sd, 2);
+ clif_party_created(sd, 2);
return 0;
}
/* Relay the result of a party creation request. */
-int party_created (int account_id, int fail, int party_id, const char *name)
+int party_created(int account_id, int fail, int party_id, const char *name)
{
struct map_session_data *sd;
- sd = map_id2sd (account_id);
+ sd = map_id2sd(account_id);
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
/* The party name is valid and not already taken. */
if (!fail)
{
- struct party *p;
sd->status.party_id = party_id;
- if ((p = (struct party *)numdb_search (party_db, party_id)) != NULL)
+ struct party *p = party_db.search(party_id);
+ if (p != NULL)
{
- printf ("party_created(): ID already exists!\n");
- exit (1);
+ PRINTF("party_created(): ID already exists!\n");
+ exit(1);
}
- CREATE (p, struct party, 1);
+ p = party_db.init(party_id);
p->party_id = party_id;
- memcpy (p->name, name, 24);
- numdb_insert (party_db, party_id, p);
+ memcpy(p->name, name, 24);
/* The party was created successfully. */
- clif_party_created (sd, 0);
+ clif_party_created(sd, 0);
}
else
- clif_party_created (sd, 1);
+ clif_party_created(sd, 1);
return 0;
}
// 情報è¦æ±‚
-int party_request_info (int party_id)
+int party_request_info(int party_id)
{
- return intif_request_partyinfo (party_id);
+ return intif_request_partyinfo(party_id);
}
// 所属キャラã®ç¢ºèª
static
-int party_check_member (struct party *p)
+int party_check_member(struct party *p)
{
- int i;
+ int i;
struct map_session_data *sd;
- nullpo_retr (0, p);
+ nullpo_ret(p);
for (i = 0; i < fd_max; i++)
{
@@ -153,22 +137,25 @@ int party_check_member (struct party *p)
{
if (sd->status.party_id == p->party_id)
{
- int j, f = 1;
+ int j, f = 1;
for (j = 0; j < MAX_PARTY; j++)
{ // パーティã«ãƒ‡ãƒ¼ã‚¿ãŒã‚ã‚‹ã‹ç¢ºèª
if (p->member[j].account_id == sd->status.account_id)
{
- if (strcmp (p->member[j].name, sd->status.name) == 0)
+ if (strcmp(p->member[j].name, sd->status.name) == 0)
f = 0; // データãŒã‚ã‚‹
else
- p->member[j].sd = NULL; // åŒåž¢åˆ¥ã‚­ãƒ£ãƒ©ã ã£ãŸ
+ {
+ // I can prove it was already zeroed
+ // p->member[j].sd = NULL; // åŒåž¢åˆ¥ã‚­ãƒ£ãƒ©ã ã£ãŸ
+ }
}
}
if (f)
{
sd->status.party_id = 0;
if (battle_config.error_log)
- printf ("party: check_member %d[%s] is not member\n",
+ PRINTF("party: check_member %d[%s] is not member\n",
sd->status.account_id, sd->status.name);
}
}
@@ -178,9 +165,9 @@ int party_check_member (struct party *p)
}
// 情報所得失敗(ãã®IDã®ã‚­ãƒ£ãƒ©ã‚’全部未所属ã«ã™ã‚‹ï¼‰
-int party_recv_noinfo (int party_id)
+int party_recv_noinfo(int party_id)
{
- int i;
+ int i;
struct map_session_data *sd;
for (i = 0; i < fd_max; i++)
{
@@ -194,31 +181,32 @@ int party_recv_noinfo (int party_id)
}
// 情報所得
-int party_recv_info (struct party *sp)
+int party_recv_info(const struct party *sp)
{
- struct party *p;
- int i;
+ int i;
- nullpo_retr (0, sp);
+ nullpo_ret(sp);
- if ((p = (struct party *)numdb_search (party_db, sp->party_id)) == NULL)
+ struct party *p = party_db.search(sp->party_id);
+ if (p == NULL)
{
- CREATE (p, struct party, 1);
- numdb_insert (party_db, sp->party_id, p);
+ p = party_db.init(sp->party_id);
// 最åˆã®ãƒ­ãƒ¼ãƒ‰ãªã®ã§ãƒ¦ãƒ¼ã‚¶ãƒ¼ã®ãƒã‚§ãƒƒã‚¯ã‚’è¡Œã†
- party_check_member (sp);
+ *p = *sp;
+ party_check_member(p);
}
- memcpy (p, sp, sizeof (struct party));
+ else
+ *p = *sp;
for (i = 0; i < MAX_PARTY; i++)
{ // sdã®è¨­å®š
- struct map_session_data *sd = map_id2sd (p->member[i].account_id);
+ struct map_session_data *sd = map_id2sd(p->member[i].account_id);
p->member[i].sd = (sd != NULL
&& sd->status.party_id == p->party_id) ? sd : NULL;
}
- clif_party_info (p, -1);
+ clif_party_info(p, -1);
for (i = 0; i < MAX_PARTY; i++)
{ // 設定情報ã®é€ä¿¡
@@ -226,7 +214,7 @@ int party_recv_info (struct party *sp)
struct map_session_data *sd = p->member[i].sd;
if (sd != NULL && sd->party_sended == 0)
{
- clif_party_option (p, sd, 0x100);
+ clif_party_option(p, sd, 0x100);
sd->party_sended = 1;
}
}
@@ -235,14 +223,14 @@ int party_recv_info (struct party *sp)
}
/* Process party invitation from sd to account_id. */
-int party_invite (struct map_session_data *sd, int account_id)
+int party_invite(struct map_session_data *sd, int account_id)
{
- struct map_session_data *tsd = map_id2sd (account_id);
- struct party *p = party_search (sd->status.party_id);
- int i;
- int full = 1; /* Indicates whether or not there's room for one more. */
+ struct map_session_data *tsd = map_id2sd(account_id);
+ struct party *p = party_search(sd->status.party_id);
+ int i;
+ int full = 1; /* Indicates whether or not there's room for one more. */
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
if (!tsd || !p || !tsd->fd)
return 0;
@@ -250,10 +238,10 @@ int party_invite (struct map_session_data *sd, int account_id)
if (!battle_config.invite_request_check)
{
/* Disallow the invitation under these conditions. */
- if (tsd->guild_invite > 0 || tsd->trade_partner || tsd->npc_id
- || tsd->npc_shopid || pc_checkskill (tsd, NV_PARTY) < 1)
+ if (tsd->trade_partner || tsd->npc_id
+ || tsd->npc_shopid || pc_checkskill(tsd, SkillID::NV_PARTY) < 1)
{
- clif_party_inviteack (sd, tsd->status.name, 1);
+ clif_party_inviteack(sd, tsd->status.name, 1);
return 0;
}
}
@@ -261,7 +249,7 @@ int party_invite (struct map_session_data *sd, int account_id)
/* The target player is already in a party, or has a pending invitation. */
if (tsd->status.party_id > 0 || tsd->party_invite > 0)
{
- clif_party_inviteack (sd, tsd->status.name, 0);
+ clif_party_inviteack(sd, tsd->status.name, 0);
return 0;
}
@@ -275,7 +263,7 @@ int party_invite (struct map_session_data *sd, int account_id)
*/
if (p->member[i].account_id == account_id)
{
- clif_party_inviteack (sd, tsd->status.name, 1);
+ clif_party_inviteack(sd, tsd->status.name, 1);
return 0;
}
@@ -286,7 +274,7 @@ int party_invite (struct map_session_data *sd, int account_id)
/* There isn't enough room for a new member. */
if (full)
{
- clif_party_inviteack (sd, tsd->status.name, 3);
+ clif_party_inviteack(sd, tsd->status.name, 3);
return 0;
}
@@ -294,14 +282,14 @@ int party_invite (struct map_session_data *sd, int account_id)
tsd->party_invite = sd->status.party_id;
tsd->party_invite_account = sd->status.account_id;
- clif_party_invite (sd, tsd);
+ clif_party_invite(sd, tsd);
return 0;
}
/* Process response to party invitation. */
-int party_reply_invite (struct map_session_data *sd, int account_id, int flag)
+int party_reply_invite(struct map_session_data *sd, int account_id, int flag)
{
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
/* There is no pending invitation. */
if (!sd->party_invite || !sd->party_invite_account)
@@ -316,7 +304,7 @@ int party_reply_invite (struct map_session_data *sd, int account_id, int flag)
/* The invitation was accepted. */
if (flag == 1)
- intif_party_addmember (sd->party_invite, sd->status.account_id);
+ intif_party_addmember(sd->party_invite, sd->status.account_id);
/* The invitation was rejected. */
else
{
@@ -326,44 +314,44 @@ int party_reply_invite (struct map_session_data *sd, int account_id, int flag)
sd->party_invite = 0;
sd->party_invite_account = 0;
- if ((tsd = map_id2sd (account_id)))
- clif_party_inviteack (tsd, sd->status.name, 1);
+ if ((tsd = map_id2sd(account_id)))
+ clif_party_inviteack(tsd, sd->status.name, 1);
}
return 0;
}
// パーティãŒè¿½åŠ ã•ã‚ŒãŸ
-int party_member_added (int party_id, int account_id, int flag)
+int party_member_added(int party_id, int account_id, int flag)
{
- struct map_session_data *sd = map_id2sd (account_id), *sd2;
- struct party *p = party_search (party_id);
+ struct map_session_data *sd = map_id2sd(account_id), *sd2;
+ struct party *p = party_search(party_id);
if (sd == NULL)
{
if (flag == 0)
{
if (battle_config.error_log)
- printf ("party: member added error %d is not online\n",
+ PRINTF("party: member added error %d is not online\n",
account_id);
- intif_party_leave (party_id, account_id); // キャラå´ã«ç™»éŒ²ã§ããªã‹ã£ãŸãŸã‚脱退è¦æ±‚を出ã™
+ intif_party_leave(party_id, account_id); // キャラå´ã«ç™»éŒ²ã§ããªã‹ã£ãŸãŸã‚脱退è¦æ±‚を出ã™
}
return 0;
}
- sd2 = map_id2sd (sd->party_invite_account);
+ sd2 = map_id2sd(sd->party_invite_account);
sd->party_invite = 0;
sd->party_invite_account = 0;
if (p == NULL)
{
- printf ("party_member_added: party %d not found.\n", party_id);
- intif_party_leave (party_id, account_id);
+ PRINTF("party_member_added: party %d not found.\n", party_id);
+ intif_party_leave(party_id, account_id);
return 0;
}
if (flag == 1)
{ // 失敗
if (sd2 != NULL)
- clif_party_inviteack (sd2, sd->status.name, 0);
+ clif_party_inviteack(sd2, sd->status.name, 0);
return 0;
}
@@ -372,26 +360,25 @@ int party_member_added (int party_id, int account_id, int flag)
sd->status.party_id = party_id;
if (sd2 != NULL)
- clif_party_inviteack (sd2, sd->status.name, 2);
+ clif_party_inviteack(sd2, sd->status.name, 2);
// ã„ã¡ãŠã†ç«¶åˆç¢ºèª
- party_check_conflict (sd);
+ party_check_conflict(sd);
- party_send_xy_clear (p);
+ party_send_xy_clear(p);
return 0;
}
// パーティ除åè¦æ±‚
-int party_removemember (struct map_session_data *sd, int account_id,
- const char *name)
+int party_removemember(struct map_session_data *sd, int account_id, const char *)
{
struct party *p;
- int i;
+ int i;
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
- if ((p = party_search (sd->status.party_id)) == NULL)
+ if ((p = party_search(sd->status.party_id)) == NULL)
return 0;
for (i = 0; i < MAX_PARTY; i++)
@@ -405,7 +392,7 @@ int party_removemember (struct map_session_data *sd, int account_id,
{ // 所属ã—ã¦ã„ã‚‹ã‹èª¿ã¹ã‚‹
if (p->member[i].account_id == account_id)
{
- intif_party_leave (p->party_id, account_id);
+ intif_party_leave(p->party_id, account_id);
return 0;
}
}
@@ -413,21 +400,21 @@ int party_removemember (struct map_session_data *sd, int account_id,
}
// パーティ脱退è¦æ±‚
-int party_leave (struct map_session_data *sd)
+int party_leave(struct map_session_data *sd)
{
struct party *p;
- int i;
+ int i;
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
- if ((p = party_search (sd->status.party_id)) == NULL)
+ if ((p = party_search(sd->status.party_id)) == NULL)
return 0;
for (i = 0; i < MAX_PARTY; i++)
{ // 所属ã—ã¦ã„ã‚‹ã‹
if (p->member[i].account_id == sd->status.account_id)
{
- intif_party_leave (p->party_id, sd->status.account_id);
+ intif_party_leave(p->party_id, sd->status.account_id);
return 0;
}
}
@@ -435,17 +422,17 @@ int party_leave (struct map_session_data *sd)
}
// パーティメンãƒãŒè„±é€€ã—ãŸ
-int party_member_leaved (int party_id, int account_id, const char *name)
+int party_member_leaved(int party_id, int account_id, const char *name)
{
- struct map_session_data *sd = map_id2sd (account_id);
- struct party *p = party_search (party_id);
+ struct map_session_data *sd = map_id2sd(account_id);
+ struct party *p = party_search(party_id);
if (p != NULL)
{
- int i;
+ int i;
for (i = 0; i < MAX_PARTY; i++)
if (p->member[i].account_id == account_id)
{
- clif_party_leaved (p, sd, account_id, name, 0x00);
+ clif_party_leaved(p, sd, account_id, name, 0x00);
p->member[i].account_id = 0;
p->member[i].sd = NULL;
}
@@ -459,79 +446,79 @@ int party_member_leaved (int party_id, int account_id, const char *name)
}
// パーティ解散通知
-int party_broken (int party_id)
+int party_broken(int party_id)
{
struct party *p;
- int i;
- if ((p = party_search (party_id)) == NULL)
+ int i;
+ if ((p = party_search(party_id)) == NULL)
return 0;
for (i = 0; i < MAX_PARTY; i++)
{
if (p->member[i].sd != NULL)
{
- clif_party_leaved (p, p->member[i].sd,
+ clif_party_leaved(p, p->member[i].sd,
p->member[i].account_id, p->member[i].name,
0x10);
p->member[i].sd->status.party_id = 0;
p->member[i].sd->party_sended = 0;
}
}
- numdb_erase (party_db, party_id);
+ party_db.erase(party_id);
return 0;
}
// パーティã®è¨­å®šå¤‰æ›´è¦æ±‚
-int party_changeoption (struct map_session_data *sd, int exp, int item)
+int party_changeoption(struct map_session_data *sd, int exp, int item)
{
struct party *p;
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
if (sd->status.party_id == 0
- || (p = party_search (sd->status.party_id)) == NULL)
+ || (p = party_search(sd->status.party_id)) == NULL)
return 0;
- intif_party_changeoption (sd->status.party_id, sd->status.account_id, exp,
+ intif_party_changeoption(sd->status.party_id, sd->status.account_id, exp,
item);
return 0;
}
// パーティã®è¨­å®šå¤‰æ›´é€šçŸ¥
-int party_optionchanged (int party_id, int account_id, int exp, int item,
+int party_optionchanged(int party_id, int account_id, int exp, int item,
int flag)
{
struct party *p;
- struct map_session_data *sd = map_id2sd (account_id);
- if ((p = party_search (party_id)) == NULL)
+ struct map_session_data *sd = map_id2sd(account_id);
+ if ((p = party_search(party_id)) == NULL)
return 0;
if (!(flag & 0x01))
p->exp = exp;
if (!(flag & 0x10))
p->item = item;
- clif_party_option (p, sd, flag);
+ clif_party_option(p, sd, flag);
return 0;
}
// パーティメンãƒã®ç§»å‹•é€šçŸ¥
-int party_recv_movemap (int party_id, int account_id, const char *map, int online,
+int party_recv_movemap(int party_id, int account_id, const char *mapname, int online,
int lv)
{
struct party *p;
- int i;
- if ((p = party_search (party_id)) == NULL)
+ int i;
+ if ((p = party_search(party_id)) == NULL)
return 0;
for (i = 0; i < MAX_PARTY; i++)
{
struct party_member *m = &p->member[i];
if (m == NULL)
{
- printf ("party_recv_movemap nullpo?\n");
+ PRINTF("party_recv_movemap nullpo?\n");
return 0;
}
if (m->account_id == account_id)
{
- memcpy (m->map, map, 16);
+ memcpy(m->map, mapname, 16);
m->online = online;
m->lv = lv;
break;
@@ -540,49 +527,49 @@ int party_recv_movemap (int party_id, int account_id, const char *map, int onlin
if (i == MAX_PARTY)
{
if (battle_config.error_log)
- printf ("party: not found member %d on %d[%s]", account_id,
+ PRINTF("party: not found member %d on %d[%s]", account_id,
party_id, p->name);
return 0;
}
for (i = 0; i < MAX_PARTY; i++)
{ // sdå†è¨­å®š
- struct map_session_data *sd = map_id2sd (p->member[i].account_id);
+ struct map_session_data *sd = map_id2sd(p->member[i].account_id);
p->member[i].sd = (sd != NULL
&& sd->status.party_id == p->party_id) ? sd : NULL;
}
- party_send_xy_clear (p); // 座標å†é€šçŸ¥è¦è«‹
+ party_send_xy_clear(p); // 座標å†é€šçŸ¥è¦è«‹
- clif_party_info (p, -1);
+ clif_party_info(p, -1);
return 0;
}
// パーティメンãƒã®ç§»å‹•
-int party_send_movemap (struct map_session_data *sd)
+int party_send_movemap(struct map_session_data *sd)
{
struct party *p;
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
if (sd->status.party_id == 0)
return 0;
- intif_party_changemap (sd, 1);
+ intif_party_changemap(sd, 1);
if (sd->party_sended != 0) // ã‚‚ã†ãƒ‘ーティデータã¯é€ä¿¡æ¸ˆã¿
return 0;
// 競åˆç¢ºèª
- party_check_conflict (sd);
+ party_check_conflict(sd);
// ã‚ã‚‹ãªã‚‰ãƒ‘ーティ情報é€ä¿¡
- if ((p = party_search (sd->status.party_id)) != NULL)
+ if ((p = party_search(sd->status.party_id)) != NULL)
{
- party_check_member (p); // 所属を確èªã™ã‚‹
+ party_check_member(p); // 所属を確èªã™ã‚‹
if (sd->status.party_id == p->party_id)
{
- clif_party_info (p, sd->fd);
- clif_party_option (p, sd, 0x100);
+ clif_party_info(p, sd->fd);
+ clif_party_option(p, sd, 0x100);
sd->party_sended = 1;
}
}
@@ -591,19 +578,19 @@ int party_send_movemap (struct map_session_data *sd)
}
// パーティメンãƒã®ãƒ­ã‚°ã‚¢ã‚¦ãƒˆ
-int party_send_logout (struct map_session_data *sd)
+int party_send_logout(struct map_session_data *sd)
{
struct party *p;
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
if (sd->status.party_id > 0)
- intif_party_changemap (sd, 0);
+ intif_party_changemap(sd, 0);
// sdãŒç„¡åŠ¹ã«ãªã‚‹ã®ã§ãƒ‘ーティ情報ã‹ã‚‰å‰Šé™¤
- if ((p = party_search (sd->status.party_id)) != NULL)
+ if ((p = party_search(sd->status.party_id)) != NULL)
{
- int i;
+ int i;
for (i = 0; i < MAX_PARTY; i++)
if (p->member[i].sd == sd)
p->member[i].sd = NULL;
@@ -613,43 +600,42 @@ int party_send_logout (struct map_session_data *sd)
}
// パーティメッセージé€ä¿¡
-int party_send_message (struct map_session_data *sd, const char *mes, int len)
+int party_send_message(struct map_session_data *sd, const char *mes, int len)
{
if (sd->status.party_id == 0)
return 0;
- intif_party_message (sd->status.party_id, sd->status.account_id, mes,
+ intif_party_message(sd->status.party_id, sd->status.account_id, mes,
len);
return 0;
}
// パーティメッセージå—ä¿¡
-int party_recv_message (int party_id, int account_id, const char *mes, int len)
+int party_recv_message(int party_id, int account_id, const char *mes, int len)
{
struct party *p;
- if ((p = party_search (party_id)) == NULL)
+ if ((p = party_search(party_id)) == NULL)
return 0;
- clif_party_message (p, account_id, mes, len);
+ clif_party_message(p, account_id, mes, len);
return 0;
}
// パーティ競åˆç¢ºèª
-int party_check_conflict (struct map_session_data *sd)
+int party_check_conflict(struct map_session_data *sd)
{
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
- intif_party_checkconflict (sd->status.party_id, sd->status.account_id,
+ intif_party_checkconflict(sd->status.party_id, sd->status.account_id,
sd->status.name);
return 0;
}
// ä½ç½®ã‚„HP通知用
static
-void party_send_xyhp_timer_sub (db_key_t key, db_val_t data, va_list ap)
+void party_send_xyhp_timer_sub(struct party *p)
{
- struct party *p = (struct party *) data;
- int i;
+ int i;
- nullpo_retv (p);
+ nullpo_retv(p);
for (i = 0; i < MAX_PARTY; i++)
{
@@ -659,14 +645,14 @@ void party_send_xyhp_timer_sub (db_key_t key, db_val_t data, va_list ap)
// 座標通知
if (sd->party_x != sd->bl.x || sd->party_y != sd->bl.y)
{
- clif_party_xy (p, sd);
+ clif_party_xy(p, sd);
sd->party_x = sd->bl.x;
sd->party_y = sd->bl.y;
}
// HP通知
if (sd->party_hp != sd->status.hp)
{
- clif_party_hp (p, sd);
+ clif_party_hp(p, sd);
sd->party_hp = sd->status.hp;
}
@@ -675,17 +661,18 @@ void party_send_xyhp_timer_sub (db_key_t key, db_val_t data, va_list ap)
}
// ä½ç½®ã‚„HP通知
-void party_send_xyhp_timer (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data)
+void party_send_xyhp_timer(TimerData *, tick_t)
{
- numdb_foreach (party_db, party_send_xyhp_timer_sub, tick);
+ for (auto& pair : party_db)
+ party_send_xyhp_timer_sub(&pair.second);
}
// ä½ç½®é€šçŸ¥ã‚¯ãƒªã‚¢
-int party_send_xy_clear (struct party *p)
+int party_send_xy_clear(struct party *p)
{
- int i;
+ int i;
- nullpo_retr (0, p);
+ nullpo_ret(p);
for (i = 0; i < MAX_PARTY; i++)
{
@@ -701,62 +688,55 @@ int party_send_xy_clear (struct party *p)
}
// HP通知ã®å¿…è¦æ€§æ¤œæŸ»ç”¨ï¼ˆmap_foreachinmoveareaã‹ã‚‰å‘¼ã°ã‚Œã‚‹ï¼‰
-int party_send_hp_check (struct block_list *bl, va_list ap)
+void party_send_hp_check(struct block_list *bl, int party_id, int *flag)
{
- int party_id;
- int *flag;
struct map_session_data *sd;
- nullpo_retr (0, bl);
- nullpo_retr (0, ap);
- nullpo_retr (0, sd = (struct map_session_data *) bl);
-
- party_id = va_arg (ap, int);
- flag = va_arg (ap, int *);
+ nullpo_retv(bl);
+ sd = (struct map_session_data *) bl;
if (sd->status.party_id == party_id)
{
*flag = 1;
sd->party_hp = -1;
}
- return 0;
}
// 経験値公平分é…
-int party_exp_share (struct party *p, int map, int base_exp, int job_exp)
+int party_exp_share(struct party *p, int mapid, int base_exp, int job_exp)
{
struct map_session_data *sd;
- int i, c;
+ int i, c;
- nullpo_retr (0, p);
+ nullpo_ret(p);
for (i = c = 0; i < MAX_PARTY; i++)
- if ((sd = p->member[i].sd) != NULL && sd->bl.m == map)
+ if ((sd = p->member[i].sd) != NULL && sd->bl.m == mapid)
c++;
if (c == 0)
return 0;
for (i = 0; i < MAX_PARTY; i++)
- if ((sd = p->member[i].sd) != NULL && sd->bl.m == map)
- pc_gainexp (sd, base_exp / c + 1, job_exp / c + 1);
+ if ((sd = p->member[i].sd) != NULL && sd->bl.m == mapid)
+ pc_gainexp_reason(sd, base_exp / c + 1, job_exp / c + 1,
+ PC_GAINEXP_REASON::SHARING);
return 0;
}
// åŒã˜ãƒžãƒƒãƒ—ã®ãƒ‘ーティメンãƒãƒ¼å…¨ä½“ã«å‡¦ç†ã‚’ã‹ã‘ã‚‹
// type==0 åŒã˜ãƒžãƒƒãƒ—
// !=0 ç”»é¢å†…
-void party_foreachsamemap (int (*func) (struct block_list *, va_list),
- struct map_session_data *sd, int type, ...)
+void party_foreachsamemap(std::function<void(struct block_list *)> func,
+ struct map_session_data *sd, int type)
{
struct party *p;
- va_list ap;
- int i;
- int x0, y0, x1, y1;
+ int i;
+ int x0, y0, x1, y1;
struct block_list *list[MAX_PARTY];
- int blockcount = 0;
+ int blockcount = 0;
- nullpo_retv (sd);
+ nullpo_retv(sd);
- if ((p = party_search (sd->status.party_id)) == NULL)
+ if ((p = party_search(sd->status.party_id)) == NULL)
return;
x0 = sd->bl.x - AREA_SIZE;
@@ -764,8 +744,6 @@ void party_foreachsamemap (int (*func) (struct block_list *, va_list),
x1 = sd->bl.x + AREA_SIZE;
y1 = sd->bl.y + AREA_SIZE;
- va_start (ap, type);
-
for (i = 0; i < MAX_PARTY; i++)
{
struct party_member *m = &p->member[i];
@@ -781,13 +759,11 @@ void party_foreachsamemap (int (*func) (struct block_list *, va_list),
}
}
- map_freeblock_lock (); // メモリã‹ã‚‰ã®è§£æ”¾ã‚’ç¦æ­¢ã™ã‚‹
+ map_freeblock_lock(); // メモリã‹ã‚‰ã®è§£æ”¾ã‚’ç¦æ­¢ã™ã‚‹
for (i = 0; i < blockcount; i++)
if (list[i]->prev) // 有効ã‹ã©ã†ã‹ãƒã‚§ãƒƒã‚¯
- func (list[i], ap);
-
- map_freeblock_unlock (); // 解放を許å¯ã™ã‚‹
+ func(list[i]);
- va_end (ap);
+ map_freeblock_unlock(); // 解放を許å¯ã™ã‚‹
}
diff --git a/src/map/party.hpp b/src/map/party.hpp
index b4d462e..77e3aaf 100644
--- a/src/map/party.hpp
+++ b/src/map/party.hpp
@@ -1,52 +1,48 @@
-// $Id: party.h,v 1.3 2004/09/25 05:32:18 MouseJstr Exp $
#ifndef PARTY_HPP
#define PARTY_HPP
-#include <stdarg.h>
+#include <functional>
struct party;
struct map_session_data;
struct block_list;
-void do_init_party (void);
-void do_final_party (void);
-struct party *party_search (int party_id);
-struct party *party_searchname (const char *str);
-
-int party_create (struct map_session_data *sd, const char *name);
-int party_created (int account_id, int fail, int party_id, const char *name);
-int party_request_info (int party_id);
-int party_invite (struct map_session_data *sd, int account_id);
-int party_member_added (int party_id, int account_id, int flag);
-int party_leave (struct map_session_data *sd);
-int party_removemember (struct map_session_data *sd, int account_id,
- const char *name);
-int party_member_leaved (int party_id, int account_id, const char *name);
-int party_reply_invite (struct map_session_data *sd, int account_id,
- int flag);
-int party_recv_noinfo (int party_id);
-int party_recv_info (struct party *sp);
-int party_recv_movemap (int party_id, int account_id, const char *map, int online,
- int lv);
-int party_broken (int party_id);
-int party_optionchanged (int party_id, int account_id, int exp, int item,
- int flag);
-int party_changeoption (struct map_session_data *sd, int exp, int item);
-
-int party_send_movemap (struct map_session_data *sd);
-int party_send_logout (struct map_session_data *sd);
-
-int party_send_message (struct map_session_data *sd, const char *mes, int len);
-int party_recv_message (int party_id, int account_id, const char *mes, int len);
-
-int party_check_conflict (struct map_session_data *sd);
-
-int party_send_xy_clear (struct party *p);
-int party_send_hp_check (struct block_list *bl, va_list ap);
-
-int party_exp_share (struct party *p, int map, int base_exp, int job_exp);
-
-void party_foreachsamemap (int (*func) (struct block_list *, va_list),
- struct map_session_data *sd, int type, ...);
-
-#endif
+void do_init_party(void);
+struct party *party_search(int party_id);
+struct party *party_searchname(const char *str);
+
+int party_create(struct map_session_data *sd, const char *name);
+int party_created(int account_id, int fail, int party_id, const char *name);
+int party_request_info(int party_id);
+int party_invite(struct map_session_data *sd, int account_id);
+int party_member_added(int party_id, int account_id, int flag);
+int party_leave(struct map_session_data *sd);
+int party_removemember(struct map_session_data *sd, int account_id,
+ const char *name);
+int party_member_leaved(int party_id, int account_id, const char *name);
+int party_reply_invite(struct map_session_data *sd, int account_id,
+ int flag);
+int party_recv_noinfo(int party_id);
+int party_recv_info(const struct party *sp);
+int party_recv_movemap(int party_id, int account_id, const char *map,
+ int online, int lv);
+int party_broken(int party_id);
+int party_optionchanged(int party_id, int account_id, int exp, int item,
+ int flag);
+int party_changeoption(struct map_session_data *sd, int exp, int item);
+
+int party_send_movemap(struct map_session_data *sd);
+int party_send_logout(struct map_session_data *sd);
+
+int party_send_message(struct map_session_data *sd, const char *mes, int len);
+int party_recv_message(int party_id, int account_id, const char *mes, int len);
+
+int party_send_xy_clear(struct party *p);
+void party_send_hp_check(struct block_list *bl, int party_id, int *flag);
+
+int party_exp_share(struct party *p, int map, int base_exp, int job_exp);
+
+void party_foreachsamemap(std::function<void(struct block_list *)> func,
+ struct map_session_data *sd, int type);
+
+#endif // PARTY_HPP
diff --git a/src/map/path.cpp b/src/map/path.cpp
index b68dae6..7a8eb37 100644
--- a/src/map/path.cpp
+++ b/src/map/path.cpp
@@ -1,37 +1,40 @@
-// $Id: path.c,v 1.1.1.1 2004/09/10 17:27:00 MagicalTux Exp $
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
+#include "../common/cxxstdio.hpp"
+#include "../common/random.hpp"
+#include "../common/nullpo.hpp"
-#include "map.hpp"
#include "battle.hpp"
-#include "../common/nullpo.hpp"
+#include "map.hpp"
-#ifdef MEMWATCH
-#include "memwatch.hpp"
-#endif
+#include "../poison.hpp"
//#define PATH_STANDALONETEST
-#define MAX_HEAP 150
+constexpr int MAX_HEAP = 150;
struct tmp_path
{
short x, y, dist, before, cost;
- char dir, flag;
+ DIR dir;
+ char flag;
};
-#define calc_index(x,y) (((x)+(y)*MAX_WALKPATH) & (MAX_WALKPATH*MAX_WALKPATH-1))
+
+static
+int calc_index(int x, int y)
+{
+ return (x + y * MAX_WALKPATH) & (MAX_WALKPATH * MAX_WALKPATH - 1);
+}
/*==========================================
* 経路探索補助heap push
*------------------------------------------
*/
-static void push_heap_path (int *heap, struct tmp_path *tp, int index)
+static
+void push_heap_path(int *heap, struct tmp_path *tp, int index)
{
- int i, h;
+ int i, h;
if (heap == NULL || tp == NULL)
{
- printf ("push_heap_path nullpo\n");
+ PRINTF("push_heap_path nullpo\n");
return;
}
@@ -48,20 +51,21 @@ static void push_heap_path (int *heap, struct tmp_path *tp, int index)
* costãŒæ¸›ã£ãŸã®ã§æ ¹ã®æ–¹ã¸ç§»å‹•
*------------------------------------------
*/
-static void update_heap_path (int *heap, struct tmp_path *tp, int index)
+static
+void update_heap_path(int *heap, struct tmp_path *tp, int index)
{
- int i, h;
+ int i, h;
- nullpo_retv (heap);
- nullpo_retv (tp);
+ nullpo_retv(heap);
+ nullpo_retv(tp);
for (h = 0; h < heap[0]; h++)
if (heap[h + 1] == index)
break;
if (h == heap[0])
{
- fprintf (stderr, "update_heap_path bug\n");
- exit (1);
+ FPRINTF(stderr, "update_heap_path bug\n");
+ exit(1);
}
for (i = (h - 1) / 2;
h > 0 && tp[index].cost < tp[heap[i + 1]].cost; i = (h - 1) / 2)
@@ -73,13 +77,14 @@ static void update_heap_path (int *heap, struct tmp_path *tp, int index)
* 経路探索補助heap pop
*------------------------------------------
*/
-static int pop_heap_path (int *heap, struct tmp_path *tp)
+static
+int pop_heap_path(int *heap, struct tmp_path *tp)
{
- int i, h, k;
- int ret, last;
+ int i, h, k;
+ int ret, last;
- nullpo_retr (-1, heap);
- nullpo_retr (-1, tp);
+ nullpo_retr(-1, heap);
+ nullpo_retr(-1, tp);
if (heap[0] <= 0)
return -1;
@@ -108,11 +113,12 @@ static int pop_heap_path (int *heap, struct tmp_path *tp)
* ç¾åœ¨ã®ç‚¹ã®cost計算
*------------------------------------------
*/
-static int calc_cost (struct tmp_path *p, int x1, int y1)
+static
+int calc_cost(struct tmp_path *p, int x1, int y1)
{
- int xd, yd;
+ int xd, yd;
- nullpo_retr (0, p);
+ nullpo_ret(p);
xd = x1 - p->x;
if (xd < 0)
@@ -127,15 +133,16 @@ static int calc_cost (struct tmp_path *p, int x1, int y1)
* å¿…è¦ãªã‚‰pathを追加/修正ã™ã‚‹
*------------------------------------------
*/
-static int add_path (int *heap, struct tmp_path *tp, int x, int y, int dist,
- int dir, int before, int x1, int y1)
+static
+int add_path(int *heap, struct tmp_path *tp, int x, int y, int dist,
+ DIR dir, int before, int x1, int y1)
{
- int i;
+ int i;
- nullpo_retr (0, heap);
- nullpo_retr (0, tp);
+ nullpo_ret(heap);
+ nullpo_ret(tp);
- i = calc_index (x, y);
+ i = calc_index(x, y);
if (tp[i].x == x && tp[i].y == y)
{
@@ -144,11 +151,11 @@ static int add_path (int *heap, struct tmp_path *tp, int x, int y, int dist,
tp[i].dist = dist;
tp[i].dir = dir;
tp[i].before = before;
- tp[i].cost = calc_cost (&tp[i], x1, y1);
+ tp[i].cost = calc_cost(&tp[i], x1, y1);
if (tp[i].flag)
- push_heap_path (heap, tp, i);
+ push_heap_path(heap, tp, i);
else
- update_heap_path (heap, tp, i);
+ update_heap_path(heap, tp, i);
tp[i].flag = 0;
}
return 0;
@@ -162,9 +169,9 @@ static int add_path (int *heap, struct tmp_path *tp, int x, int y, int dist,
tp[i].dist = dist;
tp[i].dir = dir;
tp[i].before = before;
- tp[i].cost = calc_cost (&tp[i], x1, y1);
+ tp[i].cost = calc_cost(&tp[i], x1, y1);
tp[i].flag = 0;
- push_heap_path (heap, tp, i);
+ push_heap_path(heap, tp, i);
return 0;
}
@@ -174,116 +181,57 @@ static int add_path (int *heap, struct tmp_path *tp, int x, int y, int dist,
* flag 0x10000 é è·é›¢æ”»æ’ƒåˆ¤å®š
*------------------------------------------
*/
-static int can_place (struct map_data *m, int x, int y, int flag)
+static
+bool can_place(struct map_data *m, int x, int y)
{
- int c;
-
- nullpo_retr (0, m);
-
- c = read_gatp (m, x, y);
+ nullpo_ret(m);
- if (c == 1)
- return 0;
- if (!(flag & 0x10000) && c == 5)
- return 0;
- return 1;
+ return !bool(read_gatp(m, x, y) & MapCell::UNWALKABLE);
}
/*==========================================
* (x0,y0)ã‹ã‚‰(x1,y1)ã¸1æ­©ã§ç§»å‹•å¯èƒ½ã‹è¨ˆç®—
*------------------------------------------
*/
-static int can_move (struct map_data *m, int x0, int y0, int x1, int y1,
- int flag)
+static
+int can_move(struct map_data *m, int x0, int y0, int x1, int y1)
{
- nullpo_retr (0, m);
+ nullpo_ret(m);
if (x0 - x1 < -1 || x0 - x1 > 1 || y0 - y1 < -1 || y0 - y1 > 1)
return 0;
if (x1 < 0 || y1 < 0 || x1 >= m->xs || y1 >= m->ys)
return 0;
- if (!can_place (m, x0, y0, flag))
+ if (!can_place(m, x0, y0))
return 0;
- if (!can_place (m, x1, y1, flag))
+ if (!can_place(m, x1, y1))
return 0;
if (x0 == x1 || y0 == y1)
return 1;
- if (!can_place (m, x0, y1, flag) || !can_place (m, x1, y0, flag))
+ if (!can_place(m, x0, y1) || !can_place(m, x1, y0))
return 0;
return 1;
}
/*==========================================
- * (x0,y0)ã‹ã‚‰(dx,dy)æ–¹å‘ã¸countセル分
- * å¹ã飛ã°ã—ãŸã‚ã¨ã®åº§æ¨™ã‚’所得
- *------------------------------------------
- */
-int path_blownpos (int m, int x0, int y0, int dx, int dy, int count)
-{
- struct map_data *md;
-
- if (!map[m].gat)
- return -1;
- md = &map[m];
-
- if (count > 15)
- { // 最大10マスã«åˆ¶é™
- if (battle_config.error_log)
- printf ("path_blownpos: count too many %d !\n", count);
- count = 15;
- }
- if (dx > 1 || dx < -1 || dy > 1 || dy < -1)
- {
- if (battle_config.error_log)
- printf ("path_blownpos: illeagal dx=%d or dy=%d !\n", dx, dy);
- dx = (dx >= 0) ? 1 : ((dx < 0) ? -1 : 0);
- dy = (dy >= 0) ? 1 : ((dy < 0) ? -1 : 0);
- }
-
- while ((count--) > 0 && (dx != 0 || dy != 0))
- {
- if (!can_move (md, x0, y0, x0 + dx, y0 + dy, 0))
- {
- int fx = (dx != 0 && can_move (md, x0, y0, x0 + dx, y0, 0));
- int fy = (dy != 0 && can_move (md, x0, y0, x0, y0 + dy, 0));
- if (fx && fy)
- {
- if (rand () & 1)
- dx = 0;
- else
- dy = 0;
- }
- if (!fx)
- dx = 0;
- if (!fy)
- dy = 0;
- }
- x0 += dx;
- y0 += dy;
- }
- return (x0 << 16) | y0;
-}
-
-/*==========================================
* path探索 (x0,y0)->(x1,y1)
*------------------------------------------
*/
-int path_search (struct walkpath_data *wpd, int m, int x0, int y0, int x1,
- int y1, int flag)
+int path_search(struct walkpath_data *wpd, int m, int x0, int y0, int x1, int y1, int flag)
{
- int heap[MAX_HEAP + 1];
+ int heap[MAX_HEAP + 1];
struct tmp_path tp[MAX_WALKPATH * MAX_WALKPATH];
- int i, rp, x, y;
+ int i, rp, x, y;
struct map_data *md;
- int dx, dy;
+ int dx, dy;
- nullpo_retr (0, wpd);
+ nullpo_ret(wpd);
if (!map[m].gat)
return -1;
md = &map[m];
if (x1 < 0 || x1 >= md->xs || y1 < 0 || y1 >= md->ys
- || (i = read_gatp (md, x1, y1)) == 1 || i == 5)
+ || bool(read_gatp(md, x1, y1) & MapCell::UNWALKABLE))
return -1;
// easy
@@ -291,30 +239,31 @@ int path_search (struct walkpath_data *wpd, int m, int x0, int y0, int x1,
dy = (y1 - y0 < 0) ? -1 : 1;
for (x = x0, y = y0, i = 0; x != x1 || y != y1;)
{
- if (i >= sizeof (wpd->path))
+ if (i >= sizeof(wpd->path))
return -1;
if (x != x1 && y != y1)
{
- if (!can_move (md, x, y, x + dx, y + dy, flag))
+ if (!can_move(md, x, y, x + dx, y + dy))
break;
x += dx;
y += dy;
- wpd->path[i++] =
- (dx < 0) ? ((dy > 0) ? 1 : 3) : ((dy < 0) ? 5 : 7);
+ wpd->path[i++] = (dx < 0)
+ ? ((dy > 0) ? DIR::SW : DIR::NW)
+ : ((dy < 0) ? DIR::NE : DIR::SE);
}
else if (x != x1)
{
- if (!can_move (md, x, y, x + dx, y, flag))
+ if (!can_move(md, x, y, x + dx, y))
break;
x += dx;
- wpd->path[i++] = (dx < 0) ? 2 : 6;
+ wpd->path[i++] = (dx < 0) ? DIR::W : DIR::E;
}
else
{ // y!=y1
- if (!can_move (md, x, y, x, y + dy, flag))
+ if (!can_move(md, x, y, x, y + dy))
break;
y += dy;
- wpd->path[i++] = (dy > 0) ? 0 : 4;
+ wpd->path[i++] = (dy > 0) ? DIR::S : DIR::N;
}
if (x == x1 && y == y1)
{
@@ -327,34 +276,34 @@ int path_search (struct walkpath_data *wpd, int m, int x0, int y0, int x1,
if (flag & 1)
return -1;
- memset (tp, 0, sizeof (tp));
+ memset(tp, 0, sizeof(tp));
- i = calc_index (x0, y0);
+ i = calc_index(x0, y0);
tp[i].x = x0;
tp[i].y = y0;
tp[i].dist = 0;
- tp[i].dir = 0;
+ tp[i].dir = DIR::S;
tp[i].before = 0;
- tp[i].cost = calc_cost (&tp[i], x1, y1);
+ tp[i].cost = calc_cost(&tp[i], x1, y1);
tp[i].flag = 0;
heap[0] = 0;
- push_heap_path (heap, tp, calc_index (x0, y0));
+ push_heap_path(heap, tp, calc_index(x0, y0));
while (1)
{
- int e = 0, fromdir;
+ int e = 0;
if (heap[0] == 0)
return -1;
- rp = pop_heap_path (heap, tp);
+ rp = pop_heap_path(heap, tp);
x = tp[rp].x;
y = tp[rp].y;
if (x == x1 && y == y1)
{
- int len, j;
+ int len, j;
- for (len = 0, i = rp; len < 100 && i != calc_index (x0, y0);
+ for (len = 0, i = rp; len < 100 && i != calc_index(x0, y0);
i = tp[i].before, len++);
- if (len == 100 || len >= sizeof (wpd->path))
+ if (len == 100 || len >= sizeof(wpd->path))
return -1;
wpd->path_len = len;
wpd->path_pos = 0;
@@ -364,82 +313,24 @@ int path_search (struct walkpath_data *wpd, int m, int x0, int y0, int x1,
return 0;
}
- fromdir = tp[rp].dir;
- if (can_move (md, x, y, x + 1, y - 1, flag))
- e += add_path (heap, tp, x + 1, y - 1, tp[rp].dist + 14, 5, rp,
- x1, y1);
- if (can_move (md, x, y, x + 1, y, flag))
- e += add_path (heap, tp, x + 1, y, tp[rp].dist + 10, 6, rp, x1,
- y1);
- if (can_move (md, x, y, x + 1, y + 1, flag))
- e += add_path (heap, tp, x + 1, y + 1, tp[rp].dist + 14, 7, rp,
- x1, y1);
- if (can_move (md, x, y, x, y + 1, flag))
- e += add_path (heap, tp, x, y + 1, tp[rp].dist + 10, 0, rp, x1,
- y1);
- if (can_move (md, x, y, x - 1, y + 1, flag))
- e += add_path (heap, tp, x - 1, y + 1, tp[rp].dist + 14, 1, rp,
- x1, y1);
- if (can_move (md, x, y, x - 1, y, flag))
- e += add_path (heap, tp, x - 1, y, tp[rp].dist + 10, 2, rp, x1,
- y1);
- if (can_move (md, x, y, x - 1, y - 1, flag))
- e += add_path (heap, tp, x - 1, y - 1, tp[rp].dist + 14, 3, rp,
- x1, y1);
- if (can_move (md, x, y, x, y - 1, flag))
- e += add_path (heap, tp, x, y - 1, tp[rp].dist + 10, 4, rp, x1,
- y1);
+ if (can_move(md, x, y, x + 1, y - 1))
+ e += add_path(heap, tp, x + 1, y - 1, tp[rp].dist + 14, DIR::NE, rp, x1, y1);
+ if (can_move(md, x, y, x + 1, y))
+ e += add_path(heap, tp, x + 1, y, tp[rp].dist + 10, DIR::E, rp, x1, y1);
+ if (can_move(md, x, y, x + 1, y + 1))
+ e += add_path(heap, tp, x + 1, y + 1, tp[rp].dist + 14, DIR::SE, rp, x1, y1);
+ if (can_move(md, x, y, x, y + 1))
+ e += add_path(heap, tp, x, y + 1, tp[rp].dist + 10, DIR::S, rp, x1, y1);
+ if (can_move(md, x, y, x - 1, y + 1))
+ e += add_path(heap, tp, x - 1, y + 1, tp[rp].dist + 14, DIR::SW, rp, x1, y1);
+ if (can_move(md, x, y, x - 1, y))
+ e += add_path(heap, tp, x - 1, y, tp[rp].dist + 10, DIR::W, rp, x1, y1);
+ if (can_move(md, x, y, x - 1, y - 1))
+ e += add_path(heap, tp, x - 1, y - 1, tp[rp].dist + 14, DIR::NW, rp, x1, y1);
+ if (can_move(md, x, y, x, y - 1))
+ e += add_path(heap, tp, x, y - 1, tp[rp].dist + 10, DIR::N, rp, x1, y1);
tp[rp].flag = 1;
if (e || heap[0] >= MAX_HEAP - 5)
return -1;
}
- return -1;
-}
-
-#ifdef PATH_STANDALONETEST
-char gat[64][64] = {
- {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, 1, 0, 0, 0, 0, 0},
-};
-
-struct map_data map[1];
-
-/*==========================================
- * 経路探索ルーãƒãƒ³å˜ä½“テスト用main関数
- *------------------------------------------
- */
-void main (int argc, char *argv[])
-{
- struct walkpath_data wpd;
-
- map[0].gat = gat;
- map[0].xs = 64;
- map[0].ys = 64;
-
- path_search (&wpd, 0, 3, 4, 5, 4);
- path_search (&wpd, 0, 5, 4, 3, 4);
- path_search (&wpd, 0, 6, 4, 3, 4);
- path_search (&wpd, 0, 7, 4, 3, 4);
- path_search (&wpd, 0, 4, 3, 4, 5);
- path_search (&wpd, 0, 4, 2, 4, 5);
- path_search (&wpd, 0, 4, 1, 4, 5);
- path_search (&wpd, 0, 4, 5, 4, 3);
- path_search (&wpd, 0, 4, 6, 4, 3);
- path_search (&wpd, 0, 4, 7, 4, 3);
- path_search (&wpd, 0, 7, 4, 3, 4);
- path_search (&wpd, 0, 8, 4, 3, 4);
- path_search (&wpd, 0, 9, 4, 3, 4);
- path_search (&wpd, 0, 10, 4, 3, 4);
- path_search (&wpd, 0, 11, 4, 3, 4);
- path_search (&wpd, 0, 12, 4, 3, 4);
- path_search (&wpd, 0, 13, 4, 3, 4);
- path_search (&wpd, 0, 14, 4, 3, 4);
- path_search (&wpd, 0, 15, 4, 3, 4);
- path_search (&wpd, 0, 16, 4, 3, 4);
- path_search (&wpd, 0, 17, 4, 3, 4);
- path_search (&wpd, 0, 18, 4, 3, 4);
}
-#endif
diff --git a/src/map/pc.cpp b/src/map/pc.cpp
index 256244a..a098978 100644
--- a/src/map/pc.cpp
+++ b/src/map/pc.cpp
@@ -1,118 +1,245 @@
-// $Id: pc.c 101 2004-09-25 17:57:22Z Valaris $
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <ctype.h>
-#include <time.h>
-
-#include "../common/socket.hpp" // [Valaris]
-#include "../common/timer.hpp"
-#include "../common/db.hpp"
+#include "pc.hpp"
+#include <cassert>
+#include <cstdlib>
+#include <cstring>
+
+#include "../common/cxxstdio.hpp"
+#include "../common/random.hpp"
#include "../common/nullpo.hpp"
-#include "../common/mt_rand.hpp"
+#include "../common/socket.hpp"
+#include "../common/timer.hpp"
#include "atcommand.hpp"
#include "battle.hpp"
#include "chat.hpp"
#include "chrif.hpp"
#include "clif.hpp"
-#include "guild.hpp"
#include "intif.hpp"
#include "itemdb.hpp"
+#include "magic.hpp"
#include "map.hpp"
#include "mob.hpp"
#include "npc.hpp"
#include "party.hpp"
-#include "pc.hpp"
#include "script.hpp"
#include "skill.hpp"
#include "storage.hpp"
#include "trade.hpp"
-#ifdef MEMWATCH
-#include "memwatch.hpp"
-#endif
+#include "../poison.hpp"
-#define PVP_CALCRANK_INTERVAL 1000 // PVPé †ä½è¨ˆç®—ã®é–“éš”
+// PVPé †ä½è¨ˆç®—ã®é–“éš”
+constexpr std::chrono::milliseconds PVP_CALCRANK_INTERVAL =
+ std::chrono::seconds(1);
//define it here, since the ifdef only occurs in this file
#define USE_ASTRAL_SOUL_SKILL
-#define STATE_BLIND 0x10
-
#ifdef USE_ASTRAL_SOUL_SKILL
-#define MAGIC_SKILL_THRESHOLD 200 // [fate] At this threshold, the Astral Soul skill kicks in
+// [fate] At this threshold, the Astral Soul skill kicks in
+constexpr int MAGIC_SKILL_THRESHOLD = 200;
#endif
-#define MAP_LOG_STATS(sd, suffix) \
- MAP_LOG_PC(sd, "STAT %d %d %d %d %d %d " suffix, \
- sd->status.str, sd->status.agi, sd->status.vit, sd->status.int_, sd->status.dex, sd->status.luk)
-
-#define MAP_LOG_XP(sd, suffix) \
- MAP_LOG_PC(sd, "XP %d %d JOB %d %d %d ZENY %d + %d " suffix, \
- sd->status.base_level, sd->status.base_exp, sd->status.job_level, sd->status.job_exp, sd->status.skill_point, sd->status.zeny, pc_readaccountreg(sd, "BankAccount"))
-
-#define MAP_LOG_MAGIC(sd, suffix) \
- MAP_LOG_PC(sd, "MAGIC %d %d %d %d %d %d EXP %d %d " suffix, \
- sd->status.skill[TMW_MAGIC].lv, \
- sd->status.skill[TMW_MAGIC_LIFE].lv, \
- sd->status.skill[TMW_MAGIC_WAR].lv, \
- sd->status.skill[TMW_MAGIC_TRANSMUTE].lv, \
- sd->status.skill[TMW_MAGIC_NATURE].lv, \
- sd->status.skill[TMW_MAGIC_ETHER].lv, \
- pc_readglobalreg(sd, "MAGIC_EXPERIENCE") & 0xffff, \
+#define MAP_LOG_STATS(sd, suffix) \
+ MAP_LOG_PC(sd, "STAT %d %d %d %d %d %d " suffix, \
+ sd->status.attrs[ATTR::STR], \
+ sd->status.attrs[ATTR::AGI], \
+ sd->status.attrs[ATTR::VIT], \
+ sd->status.attrs[ATTR::INT], \
+ sd->status.attrs[ATTR::DEX], \
+ sd->status.attrs[ATTR::LUK])
+
+#define MAP_LOG_XP(sd, suffix) \
+ MAP_LOG_PC(sd, "XP %d %d JOB %d %d %d ZENY %d + %d " suffix, \
+ sd->status.base_level, sd->status.base_exp, \
+ sd->status.job_level, sd->status.job_exp, sd->status.skill_point, \
+ sd->status.zeny, pc_readaccountreg(sd, "BankAccount"))
+
+#define MAP_LOG_MAGIC(sd, suffix) \
+ MAP_LOG_PC(sd, "MAGIC %d %d %d %d %d %d EXP %d %d " suffix, \
+ sd->status.skill[SkillID::TMW_MAGIC].lv, \
+ sd->status.skill[SkillID::TMW_MAGIC_LIFE].lv, \
+ sd->status.skill[SkillID::TMW_MAGIC_WAR].lv, \
+ sd->status.skill[SkillID::TMW_MAGIC_TRANSMUTE].lv, \
+ sd->status.skill[SkillID::TMW_MAGIC_NATURE].lv, \
+ sd->status.skill[SkillID::TMW_MAGIC_ETHER].lv, \
+ pc_readglobalreg(sd, "MAGIC_EXPERIENCE") & 0xffff, \
(pc_readglobalreg(sd, "MAGIC_EXPERIENCE") >> 24) & 0xff)
-timer_id day_timer_tid;
-timer_id night_timer_tid;
-
-static int max_weight_base[MAX_PC_CLASS];
-static int hp_coefficient[MAX_PC_CLASS];
-static int hp_coefficient2[MAX_PC_CLASS];
-static int hp_sigma_val[MAX_PC_CLASS][MAX_LEVEL];
-static int sp_coefficient[MAX_PC_CLASS];
-static int aspd_base[MAX_PC_CLASS][20];
-static char job_bonus[3][MAX_PC_CLASS][MAX_LEVEL];
-static int exp_table[14][MAX_LEVEL];
-static char statp[255][7];
-static struct
-{
- int id;
- int max;
- struct
- {
- short id, lv;
- } need[6];
-} skill_tree[3][MAX_PC_CLASS][100];
-
-static int atkmods[3][20]; // 武器ATKサイズ修正(size_fix.txt)
-static int refinebonus[5][3]; // 精錬ボーナステーブル(refine_db.txt)
-static int percentrefinery[5][10]; // 精錬æˆåŠŸçŽ‡(refine_db.txt)
-
-static int dirx[8] = { 0, -1, -1, -1, 0, 1, 1, 1 };
-static int diry[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };
-
-static unsigned int equip_pos[11] =
- { 0x0080, 0x0008, 0x0040, 0x0004, 0x0001, 0x0200, 0x0100, 0x0010, 0x0020,
- 0x0002, 0x8000
+static //const
+int max_weight_base_0 = 20000;
+static //const
+int hp_coefficient_0 = 0;
+static //const
+int hp_coefficient2_0 = 500;
+// TODO see if this can be turned into an "as-needed" formula
+static
+int hp_sigma_val_0[MAX_LEVEL];
+static //const
+int sp_coefficient_0 = 100;
+
+// coefficients for each weapon type
+// (not all used)
+static //const
+earray<interval_t, ItemLook, ItemLook::SINGLE_HANDED_COUNT> aspd_base_0 //=
+{{
+std::chrono::milliseconds(650),
+std::chrono::milliseconds(700),
+std::chrono::milliseconds(750),
+std::chrono::milliseconds(600),
+std::chrono::milliseconds(2000),
+std::chrono::milliseconds(2000),
+std::chrono::milliseconds(800),
+std::chrono::milliseconds(2000),
+std::chrono::milliseconds(700),
+std::chrono::milliseconds(700),
+std::chrono::milliseconds(650),
+std::chrono::milliseconds(900),
+std::chrono::milliseconds(2000),
+std::chrono::milliseconds(2000),
+std::chrono::milliseconds(2000),
+std::chrono::milliseconds(2000),
+std::chrono::milliseconds(2000),
+}};
+static const
+int exp_table_0[MAX_LEVEL] =
+{
+ // 1 .. 9
+ 9, 16, 25, 36,
+ 77, 112, 153, 200, 253,
+ // 10 .. 19
+ 320, 385, 490, 585, 700,
+ 830, 970, 1120, 1260, 1420,
+ // 20 .. 29
+ 1620, 1860, 1990, 2240, 2504,
+ 2950, 3426, 3934, 4474, 6889,
+ // 30 .. 39
+ 7995, 9174, 10425, 11748, 13967,
+ 15775, 17678, 19677, 21773, 30543,
+ // 40 .. 49
+ 34212, 38065, 42102, 46323, 53026,
+ 58419, 64041, 69892, 75973, 102468,
+ // 50 .. 59
+ 115254, 128692, 142784, 157528, 178184,
+ 196300, 215198, 234879, 255341, 330188,
+ // 60 .. 69
+ 365914, 403224, 442116, 482590, 536948,
+ 585191, 635278, 687211, 740988, 925400,
+ // 70 .. 79
+ 1473746, 1594058, 1718928, 1848355, 1982340,
+ 2230113, 2386162, 2547417, 2713878, 3206160,
+ // 80 .. 89
+ 3681024, 4022472, 4377024, 4744680, 5125440,
+ 5767272, 6204000, 6655464, 7121664, 7602600,
+ // 90 .. 99
+ 9738720, 11649960, 13643520, 18339300, 23836800,
+ 35658000, 48687000, 58135000, 99999999, 0,
+};
+// is this *actually* used anywhere?
+static const
+int exp_table_7[MAX_LEVEL] =
+{
+ // 1 .. 9
+ 10, 18, 28, 40, 91, 151, 205, 268, 340
+};
+// TODO generate this table instead
+static int stat_p[MAX_LEVEL] =
+{
+ // 1..9
+ 48, 52, 56, 60, 64, 69, 74, 79, 84,
+ // 10..19
+ 90, 96, 102,108,115, 122,129,136,144,152,
+ // 20..29
+ 160,168,177,186,195, 204,214,224,234,244,
+ // 30..39
+ 255,266,277,288,300, 312,324,336,349,362,
+ // 40..49
+ 375,388,402,416,430, 444,459,474,489,504,
+ // 50..59
+ 520,536,552,568,585, 602,619,636,654,672,
+ // 60..69
+ 690,708,727,746,765, 784,804,824,844,864,
+ // 70..79
+ 885,906,927,948,970, 992,1014,1036,1059,1082,
+ // 80..89
+ 1105,1128,1152,1176,1200, 1224,1249,1274,1299,1324,
+ // 90..99
+ 1350,1376,1402,1428,1455, 1482,1509,1536,1564,1592,
+ // 100..109
+ 1620,1648,1677,1706,1735, 1764,1794,1824,1854,1884,
+ // 110..119
+ 1915,1946,1977,2008,2040, 2072,2104,2136,2169,2202,
+ // 120..129
+ 2235,2268,2302,2336,2370, 2404,2439,2474,2509,2544,
+ // 130..139
+ 2580,2616,2652,2688,2725, 2762,2799,2836,2874,2912,
+ // 140..149
+ 2950,2988,3027,3066,3105, 3144,3184,3224,3264,3304,
+ // 150..159
+ 3345,3386,3427,3468,3510, 3552,3594,3636,3679,3722,
+ // 160..169
+ 3765,3808,3852,3896,3940, 3984,4029,4074,4119,4164,
+ // 170..179
+ 4210,4256,4302,4348,4395, 4442,4489,4536,4584,4632,
+ // 180..189
+ 4680,4728,4777,4826,4875, 4924,4974,5024,5074,5124,
+ // 190..199
+ 5175,5226,5277,5328,5380, 5432,5484,5536,5589,5642,
+ // 200..209
+ 5695,5748,5802,5856,5910, 5964,6019,6074,6129,6184,
+ // 210..219
+ 6240,6296,6352,6408,6465, 6522,6579,6636,6694,6752,
+ // 220..229
+ 6810,6868,6927,6986,7045, 7104,7164,7224,7284,7344,
+ // 230..239
+ 7405,7466,7527,7588,7650, 7712,7774,7836,7899,7962,
+ // 240..249
+ 8025,8088,8152,8216,8280, 8344,8409,8474,8539,8604,
+ // 250..255
+ 8670,8736,8802,8868,8935, 9002,
};
-//static struct dbt *gm_account_db;
-static struct gm_account *gm_account = NULL;
-static int GM_num = 0;
+static
+earray<EPOS, EQUIP, EQUIP::COUNT> equip_pos //=
+{{
+ EPOS::MISC2,
+ EPOS::CAPE,
+ EPOS::SHOES,
+ EPOS::GLOVES,
+ EPOS::LEGS,
+ EPOS::TORSO,
+ EPOS::HAT,
+ EPOS::MISC1,
+ EPOS::SHIELD,
+ EPOS::WEAPON,
+ EPOS::ARROW,
+}};
-int pc_isGM (struct map_session_data *sd)
+static
+struct gm_account *gm_account = NULL;
+static
+int GM_num = 0;
+
+static
+int pc_checkoverhp(struct map_session_data *sd);
+static
+int pc_checkoversp(struct map_session_data *sd);
+static
+int pc_nextbaseafter(struct map_session_data *sd);
+static
+int pc_nextjobafter(struct map_session_data *sd);
+static
+void pc_setdead(struct map_session_data *sd)
{
-// struct gm_account *p;
- int i;
+ sd->state.dead_sit = 1;
+}
- nullpo_retr (0, sd);
+int pc_isGM(struct map_session_data *sd)
+{
+ int i;
-/* p = numdb_search(gm_account_db, sd->status.account_id);
- if (p == NULL)
- return 0;
- return p->level;*/
+ nullpo_ret(sd);
for (i = 0; i < GM_num; i++)
if (gm_account[i].account_id == sd->status.account_id)
@@ -121,17 +248,17 @@ int pc_isGM (struct map_session_data *sd)
}
-int pc_iskiller (struct map_session_data *src,
+int pc_iskiller(struct map_session_data *src,
struct map_session_data *target)
{
- nullpo_retr (0, src);
+ nullpo_ret(src);
- if (src->bl.type != BL_PC)
+ if (src->bl.type != BL::PC)
return 0;
if (src->special_state.killer)
return 1;
- if (target->bl.type != BL_PC)
+ if (target->bl.type != BL::PC)
return 0;
if (target->special_state.killable)
return 1;
@@ -139,9 +266,9 @@ int pc_iskiller (struct map_session_data *src,
return 0;
}
-int pc_set_gm_level (int account_id, int level)
+int pc_set_gm_level(int account_id, int level)
{
- int i;
+ int i;
for (i = 0; i < GM_num; i++)
{
if (account_id == gm_account[i].account_id)
@@ -152,189 +279,56 @@ int pc_set_gm_level (int account_id, int level)
}
GM_num++;
- RECREATE (gm_account, struct gm_account, GM_num);
+ RECREATE(gm_account, struct gm_account, GM_num);
gm_account[GM_num - 1].account_id = account_id;
gm_account[GM_num - 1].level = level;
return 0;
}
-int pc_getrefinebonus (int lv, int type)
-{
- if (lv >= 0 && lv < 5 && type >= 0 && type < 3)
- return refinebonus[lv][type];
- return 0;
-}
-
-static int distance (int x0, int y0, int x1, int y1)
+static
+int distance(int x0, int y0, int x1, int y1)
{
- int dx, dy;
+ int dx, dy;
- dx = abs (x0 - x1);
- dy = abs (y0 - y1);
+ dx = abs(x0 - x1);
+ dy = abs(y0 - y1);
return dx > dy ? dx : dy;
}
-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;
-
- if (sd->invincible_timer != tid)
- {
- if (battle_config.error_log)
- printf ("invincible_timer %d != %d\n", sd->invincible_timer, tid);
- return;
- }
- sd->invincible_timer = -1;
-}
-
-int pc_setinvincibletimer (struct map_session_data *sd, int val)
-{
- nullpo_retr (0, sd);
-
- if (sd->invincible_timer != -1)
- delete_timer (sd->invincible_timer, pc_invincible_timer);
- sd->invincible_timer =
- add_timer (gettick () + val, pc_invincible_timer, sd->bl.id, 0);
- return 0;
-}
-
-int pc_delinvincibletimer (struct map_session_data *sd)
-{
- nullpo_retr (0, sd);
-
- if (sd->invincible_timer != -1)
- {
- delete_timer (sd->invincible_timer, pc_invincible_timer);
- sd->invincible_timer = -1;
- }
- return 0;
-}
-
-static void pc_spiritball_timer (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data)
+static
+void pc_invincible_timer(TimerData *, tick_t, int id)
{
- struct map_session_data *sd;
- int i;
+ struct map_session_data *sd = map_id2sd(id);
- if ((sd = (struct map_session_data *) map_id2sd (id)) == NULL
- || sd->bl.type != BL_PC)
- return;
-
- if (sd->spirit_timer[0] != tid)
- {
- if (battle_config.error_log)
- printf ("spirit_timer %d != %d\n", sd->spirit_timer[0], tid);
- return;
- }
- sd->spirit_timer[0] = -1;
- for (i = 1; i < sd->spiritball; i++)
- {
- sd->spirit_timer[i - 1] = sd->spirit_timer[i];
- sd->spirit_timer[i] = -1;
- }
- sd->spiritball--;
- if (sd->spiritball < 0)
- sd->spiritball = 0;
- clif_spiritball (sd);
+ assert (sd != NULL);
+ assert (sd->bl.type == BL::PC);
}
-int pc_addspiritball (struct map_session_data *sd, int interval, int max)
+int pc_setinvincibletimer(struct map_session_data *sd, interval_t val)
{
- int i;
-
- nullpo_retr (0, sd);
-
- if (max > MAX_SKILL_LEVEL)
- max = MAX_SKILL_LEVEL;
- if (sd->spiritball < 0)
- sd->spiritball = 0;
-
- if (sd->spiritball >= max)
- {
- if (sd->spirit_timer[0] != -1)
- {
- delete_timer (sd->spirit_timer[0], pc_spiritball_timer);
- sd->spirit_timer[0] = -1;
- }
- for (i = 1; i < max; i++)
- {
- sd->spirit_timer[i - 1] = sd->spirit_timer[i];
- sd->spirit_timer[i] = -1;
- }
- }
- else
- sd->spiritball++;
-
- sd->spirit_timer[sd->spiritball - 1] =
- add_timer (gettick () + interval, pc_spiritball_timer, sd->bl.id, 0);
- clif_spiritball (sd);
+ nullpo_ret(sd);
+ sd->invincible_timer = Timer(gettick() + val,
+ std::bind(pc_invincible_timer, ph::_1, ph::_2,
+ sd->bl.id));
return 0;
}
-int pc_delspiritball (struct map_session_data *sd, int count, int type)
+int pc_delinvincibletimer(struct map_session_data *sd)
{
- int i;
-
- nullpo_retr (0, sd);
-
- if (sd->spiritball <= 0)
- {
- sd->spiritball = 0;
- return 0;
- }
-
- if (count > sd->spiritball)
- count = sd->spiritball;
- sd->spiritball -= count;
- if (count > MAX_SKILL_LEVEL)
- count = MAX_SKILL_LEVEL;
-
- for (i = 0; i < count; i++)
- {
- if (sd->spirit_timer[i] != -1)
- {
- delete_timer (sd->spirit_timer[i], pc_spiritball_timer);
- sd->spirit_timer[i] = -1;
- }
- }
- for (i = count; i < MAX_SKILL_LEVEL; i++)
- {
- sd->spirit_timer[i - count] = sd->spirit_timer[i];
- sd->spirit_timer[i] = -1;
- }
-
- if (!type)
- clif_spiritball (sd);
+ nullpo_ret(sd);
+ sd->invincible_timer.cancel();
return 0;
}
-int pc_setrestartvalue (struct map_session_data *sd, int type)
+int pc_setrestartvalue(struct map_session_data *sd, int type)
{
- //転生や養å­ã®å ´åˆã®å…ƒã®è·æ¥­ã‚’算出ã™ã‚‹
- struct pc_base_job s_class;
-
- nullpo_retr (0, sd);
-
- s_class = pc_calc_base_job (sd->status.pc_class);
+ nullpo_ret(sd);
- //-----------------------
- // 死亡ã—ãŸ
- if (sd->special_state.restart_full_recover)
- { // オシリスカード
- sd->status.hp = sd->status.max_hp;
- sd->status.sp = sd->status.max_sp;
- }
- else
{
- if (s_class.job == 0 && battle_config.restart_hp_rate < 50)
- { //ノビã¯åŠåˆ†å›žå¾©
+ if (battle_config.restart_hp_rate < 50)
sd->status.hp = (sd->status.max_hp) / 2;
- }
else
{
if (battle_config.restart_hp_rate <= 0)
@@ -349,31 +343,16 @@ int pc_setrestartvalue (struct map_session_data *sd, int type)
}
if (battle_config.restart_sp_rate > 0)
{
- int sp = sd->status.max_sp * battle_config.restart_sp_rate / 100;
+ int sp = sd->status.max_sp * battle_config.restart_sp_rate / 100;
if (sd->status.sp < sp)
sd->status.sp = sp;
}
}
if (type & 1)
- clif_updatestatus (sd, SP_HP);
+ clif_updatestatus(sd, SP::HP);
if (type & 1)
- clif_updatestatus (sd, SP_SP);
-
- /* removed exp penalty on spawn [Valaris] */
+ clif_updatestatus(sd, SP::SP);
- if (type & 2 && sd->status.pc_class != 0 && battle_config.zeny_penalty > 0
- && !map[sd->bl.m].flag.nozenypenalty)
- {
- int zeny =
- (int) ((double) sd->status.zeny *
- (double) battle_config.zeny_penalty / 10000.);
- if (zeny < 1)
- zeny = 1;
- sd->status.zeny -= zeny;
- if (sd->status.zeny < 0)
- sd->status.zeny = 0;
- clif_updatestatus (sd, SP_ZENY);
- }
sd->heal_xp = 0; // [Fate] Set gainable xp for healing this player to 0
return 0;
@@ -383,49 +362,38 @@ int pc_setrestartvalue (struct map_session_data *sd, int type)
* 自分をロックã—ã¦ã„ã‚‹MOBã®æ•°ã‚’æ•°ãˆã‚‹(foreachclient)
*------------------------------------------
*/
-static int pc_counttargeted_sub (struct block_list *bl, va_list ap)
+static
+void pc_counttargeted_sub(struct block_list *bl,
+ int id, int *c, struct block_list *src, ATK target_lv)
{
- int id, *c, target_lv;
- struct block_list *src;
+ nullpo_retv(bl);
- nullpo_retr (0, bl);
- nullpo_retr (0, ap);
-
- id = va_arg (ap, int);
-
- nullpo_retr (0, c = va_arg (ap, int *));
-
- src = va_arg (ap, struct block_list *);
- target_lv = va_arg (ap, int);
if (id == bl->id || (src && id == src->id))
- return 0;
- if (bl->type == BL_PC)
+ return;
+ if (bl->type == BL::PC)
{
struct map_session_data *sd = (struct map_session_data *) bl;
- if (sd && sd->attacktarget == id && sd->attacktimer != -1
+ if (sd->attacktarget == id && sd->attacktimer
&& sd->attacktarget_lv >= target_lv)
(*c)++;
}
- else if (bl->type == BL_MOB)
+ else if (bl->type == BL::MOB)
{
struct mob_data *md = (struct mob_data *) bl;
- if (md && md->target_id == id && md->timer != -1
- && md->state.state == MS_ATTACK && md->target_lv >= target_lv)
+ if (md->target_id == id && md->timer
+ && md->state.state == MS::ATTACK && md->target_lv >= target_lv)
(*c)++;
- //printf("md->target_lv:%d, target_lv:%d\n",((struct mob_data *)bl)->target_lv,target_lv);
}
- return 0;
}
-int pc_counttargeted (struct map_session_data *sd, struct block_list *src,
- int target_lv)
+int pc_counttargeted(struct map_session_data *sd, struct block_list *src,
+ ATK target_lv)
{
- int c = 0;
- map_foreachinarea (pc_counttargeted_sub, sd->bl.m,
- sd->bl.x - AREA_SIZE, sd->bl.y - AREA_SIZE,
- sd->bl.x + AREA_SIZE, sd->bl.y + AREA_SIZE, 0,
- sd->bl.id, &c, src, target_lv);
+ int c = 0;
+ map_foreachinarea(std::bind(pc_counttargeted_sub, ph::_1, sd->bl.id, &c, src, target_lv),
+ sd->bl.m, sd->bl.x - AREA_SIZE, sd->bl.y - AREA_SIZE,
+ sd->bl.x + AREA_SIZE, sd->bl.y + AREA_SIZE, BL::NUL);
return c;
}
@@ -433,30 +401,31 @@ int pc_counttargeted (struct map_session_data *sd, struct block_list *src,
* ローカルプロトタイプ宣言 (å¿…è¦ãªç‰©ã®ã¿)
*------------------------------------------
*/
-static int pc_walktoxy_sub (struct map_session_data *);
+static
+int pc_walktoxy_sub(struct map_session_data *);
/*==========================================
* saveã«å¿…è¦ãªã‚¹ãƒ†ãƒ¼ã‚¿ã‚¹ä¿®æ­£ã‚’è¡Œãªã†
*------------------------------------------
*/
-int pc_makesavestatus (struct map_session_data *sd)
+int pc_makesavestatus(struct map_session_data *sd)
{
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
// æœã®è‰²ã¯è‰²ã€…弊害ãŒå¤šã„ã®ã§ä¿å­˜å¯¾è±¡ã«ã¯ã—ãªã„
if (!battle_config.save_clothcolor)
sd->status.clothes_color = 0;
// 死亡状態ã ã£ãŸã®ã§hpã‚’1ã€ä½ç½®ã‚’セーブ場所ã«å¤‰æ›´
- if (pc_isdead (sd))
+ if (pc_isdead(sd))
{
- pc_setrestartvalue (sd, 0);
- memcpy (&sd->status.last_point, &sd->status.save_point,
- sizeof (sd->status.last_point));
+ pc_setrestartvalue(sd, 0);
+ memcpy(&sd->status.last_point, &sd->status.save_point,
+ sizeof(sd->status.last_point));
}
else
{
- memcpy (sd->status.last_point.map, sd->mapname, 24);
+ memcpy(sd->status.last_point.map, sd->mapname, 24);
sd->status.last_point.x = sd->bl.x;
sd->status.last_point.y = sd->bl.y;
}
@@ -465,17 +434,14 @@ int pc_makesavestatus (struct map_session_data *sd)
if (map[sd->bl.m].flag.nosave)
{
struct map_data *m = &map[sd->bl.m];
- if (strcmp (m->save.map, "SavePoint") == 0)
- memcpy (&sd->status.last_point, &sd->status.save_point,
- sizeof (sd->status.last_point));
+ if (strcmp(m->save.map, "SavePoint") == 0)
+ memcpy(&sd->status.last_point, &sd->status.save_point,
+ sizeof(sd->status.last_point));
else
- memcpy (&sd->status.last_point, &m->save,
- sizeof (sd->status.last_point));
+ memcpy(&sd->status.last_point, &m->save,
+ sizeof(sd->status.last_point));
}
- //マナーãƒã‚¤ãƒ³ãƒˆãŒãƒ—ラスã ã£ãŸå ´åˆ0ã«
- if (battle_config.muting_players && sd->status.manner > 0)
- sd->status.manner = 0;
return 0;
}
@@ -483,10 +449,10 @@ int pc_makesavestatus (struct map_session_data *sd)
* 接続時ã®åˆæœŸåŒ–
*------------------------------------------
*/
-int pc_setnewpc (struct map_session_data *sd, int account_id, int char_id,
- int login_id1, int client_tick, int sex, int fd)
+int pc_setnewpc(struct map_session_data *sd, int account_id, int char_id,
+ int login_id1, tick_t client_tick, int sex)
{
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
sd->bl.id = account_id;
sd->char_id = char_id;
@@ -495,76 +461,78 @@ int pc_setnewpc (struct map_session_data *sd, int account_id, int char_id,
sd->client_tick = client_tick;
sd->sex = sex;
sd->state.auth = 0;
- sd->bl.type = BL_PC;
- sd->canact_tick = sd->canmove_tick = gettick ();
- sd->canlog_tick = gettick ();
+ sd->bl.type = BL::PC;
+ sd->canact_tick = sd->canmove_tick = gettick();
+ sd->canlog_tick = gettick();
sd->state.waitingdisconnect = 0;
return 0;
}
-int pc_equippoint (struct map_session_data *sd, int n)
+EPOS pc_equippoint(struct map_session_data *sd, int n)
{
- int ep = 0;
- //転生や養å­ã®å ´åˆã®å…ƒã®è·æ¥­ã‚’算出ã™ã‚‹
- struct pc_base_job s_class;
-
- nullpo_retr (0, sd);
+ nullpo_retr(EPOS::ZERO, sd);
if (!sd->inventory_data[n])
- return 0;
+ return EPOS::ZERO;
- s_class = pc_calc_base_job (sd->status.pc_class);
-
- ep = sd->inventory_data[n]->equip;
- if ((sd->inventory_data[n]->look == 1 || sd->inventory_data[n]->look == 2
- || sd->inventory_data[n]->look == 6) && (ep == 2
- &&
- (pc_checkskill (sd, AS_LEFT)
- > 0 || s_class.job == 12)))
- {
- return 34;
- }
+ EPOS ep = sd->inventory_data[n]->equip;
return ep;
}
static
-int pc_setinventorydata (struct map_session_data *sd)
+int pc_setinventorydata(struct map_session_data *sd)
{
- int i, id;
+ int i, id;
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
for (i = 0; i < MAX_INVENTORY; i++)
{
id = sd->status.inventory[i].nameid;
- sd->inventory_data[i] = itemdb_search (id);
+ sd->inventory_data[i] = itemdb_search(id);
}
return 0;
}
static
-int pc_calcweapontype (struct map_session_data *sd)
+int pc_calcweapontype(struct map_session_data *sd)
{
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
- if (sd->weapontype1 != 0 && sd->weapontype2 == 0)
+ if (sd->weapontype1 != ItemLook::NONE
+ && sd->weapontype2 == ItemLook::NONE)
sd->status.weapon = sd->weapontype1;
- if (sd->weapontype1 == 0 && sd->weapontype2 != 0) // 左手武器 Only
+ if (sd->weapontype1 == ItemLook::NONE
+ && sd->weapontype2 != ItemLook::NONE)
sd->status.weapon = sd->weapontype2;
- else if (sd->weapontype1 == 1 && sd->weapontype2 == 1) // åŒçŸ­å‰£
- sd->status.weapon = 0x11;
- else if (sd->weapontype1 == 2 && sd->weapontype2 == 2) // åŒå˜æ‰‹å‰£
- sd->status.weapon = 0x12;
- else if (sd->weapontype1 == 6 && sd->weapontype2 == 6) // åŒå˜æ‰‹æ–§
- sd->status.weapon = 0x13;
- else if ((sd->weapontype1 == 1 && sd->weapontype2 == 2) || (sd->weapontype1 == 2 && sd->weapontype2 == 1)) // 短剣 - å˜æ‰‹å‰£
- sd->status.weapon = 0x14;
- else if ((sd->weapontype1 == 1 && sd->weapontype2 == 6) || (sd->weapontype1 == 6 && sd->weapontype2 == 1)) // 短剣 - 斧
- sd->status.weapon = 0x15;
- else if ((sd->weapontype1 == 2 && sd->weapontype2 == 6) || (sd->weapontype1 == 6 && sd->weapontype2 == 2)) // å˜æ‰‹å‰£ - æ–§
- sd->status.weapon = 0x16;
+ else if (sd->weapontype1 == ItemLook::BLADE
+ && sd->weapontype2 == ItemLook::BLADE)
+ sd->status.weapon = ItemLook::DUAL_BLADE;
+ else if (sd->weapontype1 == ItemLook::_2
+ && sd->weapontype2 == ItemLook::_2)
+ sd->status.weapon = ItemLook::DUAL_2;
+ else if (sd->weapontype1 == ItemLook::_6
+ && sd->weapontype2 == ItemLook::_6)
+ sd->status.weapon = ItemLook::DUAL_6;
+ else if ((sd->weapontype1 == ItemLook::BLADE
+ && sd->weapontype2 == ItemLook::_2)
+ || (sd->weapontype1 == ItemLook::_2
+ && sd->weapontype2 == ItemLook::BLADE))
+ sd->status.weapon = ItemLook::DUAL_12;
+ else if (
+ (sd->weapontype1 == ItemLook::BLADE
+ && sd->weapontype2 == ItemLook::_6)
+ || (sd->weapontype1 == ItemLook::_6
+ && sd->weapontype2 == ItemLook::BLADE))
+ sd->status.weapon = ItemLook::DUAL_16;
+ else if (
+ (sd->weapontype1 == ItemLook::_2
+ && sd->weapontype2 == ItemLook::_6)
+ || (sd->weapontype1 == ItemLook::_6
+ && sd->weapontype2 == ItemLook::_2))
+ sd->status.weapon = ItemLook::DUAL_26;
else
sd->status.weapon = sd->weapontype1;
@@ -572,69 +540,67 @@ int pc_calcweapontype (struct map_session_data *sd)
}
static
-int pc_setequipindex (struct map_session_data *sd)
+int pc_setequipindex(struct map_session_data *sd)
{
- int i, j;
+ nullpo_ret(sd);
- nullpo_retr (0, sd);
-
- for (i = 0; i < 11; i++)
+ for (EQUIP i : EQUIPs)
sd->equip_index[i] = -1;
- for (i = 0; i < MAX_INVENTORY; i++)
+ for (int i = 0; i < MAX_INVENTORY; i++)
{
if (sd->status.inventory[i].nameid <= 0)
continue;
- if (sd->status.inventory[i].equip)
+ if (bool(sd->status.inventory[i].equip))
{
- for (j = 0; j < 11; j++)
- if (sd->status.inventory[i].equip & equip_pos[j])
+ for (EQUIP j : EQUIPs)
+ if (bool(sd->status.inventory[i].equip & equip_pos[j]))
sd->equip_index[j] = i;
- if (sd->status.inventory[i].equip & 0x0002)
+ if (bool(sd->status.inventory[i].equip & EPOS::WEAPON))
{
if (sd->inventory_data[i])
sd->weapontype1 = sd->inventory_data[i]->look;
else
- sd->weapontype1 = 0;
+ sd->weapontype1 = ItemLook::NONE;
}
- if (sd->status.inventory[i].equip & 0x0020)
+ if (bool(sd->status.inventory[i].equip & EPOS::SHIELD))
{
if (sd->inventory_data[i])
{
- if (sd->inventory_data[i]->type == 4)
+ if (sd->inventory_data[i]->type == ItemType::WEAPON)
{
- if (sd->status.inventory[i].equip == 0x0020)
+ if (sd->status.inventory[i].equip == EPOS::SHIELD)
sd->weapontype2 = sd->inventory_data[i]->look;
else
- sd->weapontype2 = 0;
+ sd->weapontype2 = ItemLook::NONE;
}
else
- sd->weapontype2 = 0;
+ sd->weapontype2 = ItemLook::NONE;
}
else
- sd->weapontype2 = 0;
+ sd->weapontype2 = ItemLook::NONE;
}
}
}
- pc_calcweapontype (sd);
+ pc_calcweapontype(sd);
return 0;
}
-int pc_isequip (struct map_session_data *sd, int n)
+static
+int pc_isequip(struct map_session_data *sd, int n)
{
struct item_data *item;
- struct status_change *sc_data;
+ eptr<struct status_change, StatusChange> sc_data;
//転生や養å­ã®å ´åˆã®å…ƒã®è·æ¥­ã‚’算出ã™ã‚‹
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
item = sd->inventory_data[n];
- sc_data = battle_get_sc_data (&sd->bl);
- //s_class = pc_calc_base_job(sd->status.class);
+ sc_data = battle_get_sc_data(&sd->bl);
if (battle_config.gm_allequip > 0
- && pc_isGM (sd) >= battle_config.gm_allequip)
+ && pc_isGM(sd) >= battle_config.gm_allequip)
return 1;
if (item == NULL)
@@ -647,179 +613,69 @@ int pc_isequip (struct map_session_data *sd, int n)
if (map[sd->bl.m].flag.pvp
&& (item->flag.no_equip == 1 || item->flag.no_equip == 3))
return 0;
- if (map[sd->bl.m].flag.gvg
- && (item->flag.no_equip == 2 || item->flag.no_equip == 3))
- return 0;
- if (item->equip & 0x0002 && sc_data
- && sc_data[SC_STRIPWEAPON].timer != -1)
- return 0;
- if (item->equip & 0x0020 && sc_data
- && sc_data[SC_STRIPSHIELD].timer != -1)
- return 0;
- if (item->equip & 0x0010 && sc_data && sc_data[SC_STRIPARMOR].timer != -1)
- return 0;
- if (item->equip & 0x0100 && sc_data && sc_data[SC_STRIPHELM].timer != -1)
- return 0;
return 1;
}
/*==========================================
- * Weapon Breaking [Valaris]
- *------------------------------------------
- */
-int pc_breakweapon (struct map_session_data *sd)
-{
- struct item_data *item;
- char output[255];
- int i;
-
- if (sd == NULL)
- return -1;
- if (sd->unbreakable >= MRAND (100))
- return 0;
- if (sd->sc_data && sd->sc_data[SC_CP_WEAPON].timer != -1)
- return 0;
-
- for (i = 0; i < MAX_INVENTORY; i++)
- {
- if (sd->status.inventory[i].equip
- && sd->status.inventory[i].equip & 0x0002
- && !sd->status.inventory[i].broken)
- {
- item = sd->inventory_data[i];
- sd->status.inventory[i].broken = 1;
- //pc_unequipitem(sd,i,0);
- if (sd->status.inventory[i].equip
- && sd->status.inventory[i].equip & 0x0002
- && sd->status.inventory[i].broken == 1)
- {
- sprintf (output, "%s has broken.", item->jname);
- clif_emotion (&sd->bl, 23);
- clif_displaymessage (sd->fd, output);
- clif_equiplist (sd);
- skill_status_change_start (&sd->bl, SC_BROKNWEAPON, 0, 0, 0,
- 0, 0, 0);
- }
- }
- if (sd->status.inventory[i].broken == 1)
- return 0;
- }
-
- return 0;
-}
-
-/*==========================================
- * Armor Breaking [Valaris]
- *------------------------------------------
- */
-int pc_breakarmor (struct map_session_data *sd)
-{
- struct item_data *item;
- char output[255];
- int i;
-
- if (sd == NULL)
- return -1;
- if (sd->unbreakable >= MRAND (100))
- return 0;
- if (sd->sc_data && sd->sc_data[SC_CP_ARMOR].timer != -1)
- return 0;
-
- for (i = 0; i < MAX_INVENTORY; i++)
- {
- if (sd->status.inventory[i].equip
- && sd->status.inventory[i].equip & 0x0010
- && !sd->status.inventory[i].broken)
- {
- item = sd->inventory_data[i];
- sd->status.inventory[i].broken = 1;
- //pc_unequipitem(sd,i,0);
- if (sd->status.inventory[i].equip
- && sd->status.inventory[i].equip & 0x0010
- && sd->status.inventory[i].broken == 1)
- {
- sprintf (output, "%s has broken.", item->jname);
- clif_emotion (&sd->bl, 23);
- clif_displaymessage (sd->fd, output);
- clif_equiplist (sd);
- skill_status_change_start (&sd->bl, SC_BROKNARMOR, 0, 0, 0, 0,
- 0, 0);
- }
- }
- if (sd->status.inventory[i].broken == 1)
- return 0;
- }
- return 0;
-}
-
-/*==========================================
* session idã«å•é¡Œç„¡ã—
* char鯖ã‹ã‚‰é€ã‚‰ã‚Œã¦ããŸã‚¹ãƒ†ãƒ¼ã‚¿ã‚¹ã‚’設定
*------------------------------------------
*/
-int pc_authok (int id, int login_id2, time_t connect_until_time,
- short tmw_version, struct mmo_charstatus *st)
+int pc_authok(int id, int login_id2, TimeT connect_until_time,
+ short tmw_version, const struct mmo_charstatus *st)
{
struct map_session_data *sd = NULL;
struct party *p;
- struct guild *g;
- unsigned long tick = gettick ();
+ tick_t tick = gettick();
struct sockaddr_in sai;
socklen_t sa_len = sizeof(struct sockaddr);
- sd = map_id2sd (id);
+ sd = map_id2sd(id);
if (sd == NULL)
return 1;
sd->login_id2 = login_id2;
sd->tmw_version = tmw_version;
- memcpy (&sd->status, st, sizeof (*st));
+ memcpy(&sd->status, st, sizeof(*st));
if (sd->status.sex != sd->sex)
{
- clif_authfail_fd (sd->fd, 0);
+ clif_authfail_fd(sd->fd, 0);
return 1;
}
- MAP_LOG_STATS (sd, "LOGIN");
- MAP_LOG_XP (sd, "LOGIN");
- MAP_LOG_MAGIC (sd, "LOGIN");
+ MAP_LOG_STATS(sd, "LOGIN");
+ MAP_LOG_XP(sd, "LOGIN");
+ MAP_LOG_MAGIC(sd, "LOGIN");
- memset (&sd->state, 0, sizeof (sd->state));
+ memset(&sd->state, 0, sizeof(sd->state));
// 基本的ãªåˆæœŸåŒ–
sd->state.connect_new = 1;
sd->bl.prev = sd->bl.next = NULL;
- sd->weapontype1 = sd->weapontype2 = 0;
- sd->view_class = sd->status.pc_class;
+ sd->weapontype1 = sd->weapontype2 = ItemLook::NONE;
sd->speed = DEFAULT_WALK_SPEED;
sd->state.dead_sit = 0;
- sd->dir = 0;
- sd->head_dir = 0;
+ sd->dir = DIR::S;
+ sd->head_dir = DIR::S;
sd->state.auth = 1;
- sd->walktimer = -1;
- sd->attacktimer = -1;
- sd->followtimer = -1; // [MouseJstr]
- sd->skilltimer = -1;
- sd->skillitem = -1;
- sd->skillitemlv = -1;
- sd->invincible_timer = -1;
+ // sd->walktimer = nullptr;
+ // sd->attacktimer = nullptr;
+ // sd->invincible_timer = nullptr;
sd->sg_count = 0;
sd->deal_locked = 0;
sd->trade_partner = 0;
- sd->inchealhptick = 0;
- sd->inchealsptick = 0;
- sd->hp_sub = 0;
- sd->sp_sub = 0;
+ sd->inchealhptick = interval_t::zero();
+ sd->inchealsptick = interval_t::zero();
+ sd->hp_sub = interval_t::zero();
+ sd->sp_sub = interval_t::zero();
sd->quick_regeneration_hp.amount = 0;
sd->quick_regeneration_sp.amount = 0;
sd->heal_xp = 0;
- sd->inchealspirithptick = 0;
- sd->inchealspiritsptick = 0;
sd->canact_tick = tick;
sd->canmove_tick = tick;
sd->attackabletime = tick;
@@ -827,17 +683,13 @@ int pc_authok (int id, int login_id2, time_t connect_until_time,
// Removed because it was buggy with the ~50 day wraparound,
// and there's already a limit on how fast you can log in and log out.
// -o11c
+ //
+ // The above is no longer accurate now that we use <chrono>, but
+ // I'm still not reverting this.
+ // -o11c
sd->cast_tick = tick; // + pc_readglobalreg (sd, "MAGIC_CAST_TICK");
- sd->doridori_counter = 0;
-
- sd->spiritball = 0;
- for (int i = 0; i < MAX_SKILL_LEVEL; i++)
- sd->spirit_timer[i] = -1;
- for (int i = 0; i < MAX_SKILLTIMERSKILL; i++)
- sd->skilltimerskill[i].timer = -1;
-
- memset (&sd->dev, 0, sizeof (struct square));
+ memset(&sd->dev, 0, sizeof(struct square));
for (int i = 0; i < 5; i++)
{
sd->dev.val1[i] = 0;
@@ -845,32 +697,23 @@ int pc_authok (int id, int login_id2, time_t connect_until_time,
}
// アカウント変数ã®é€ä¿¡è¦æ±‚
- intif_request_accountreg (sd);
+ intif_request_accountreg(sd);
// アイテムãƒã‚§ãƒƒã‚¯
- pc_setinventorydata (sd);
- pc_checkitem (sd);
+ pc_setinventorydata(sd);
+ pc_checkitem(sd);
// ステータス異常ã®åˆæœŸåŒ–
- for (int i = 0; i < MAX_STATUSCHANGE; i++)
+ for (StatusChange i : erange(StatusChange(), StatusChange::MAX_STATUSCHANGE))
{
- sd->sc_data[i].timer = -1;
- sd->sc_data[i].val1 = sd->sc_data[i].val2 = sd->sc_data[i].val3 =
- sd->sc_data[i].val4 = 0;
+ // sd->sc_data[i].timer = nullptr;
+ sd->sc_data[i].val1 = 0;
}
sd->sc_count = 0;
- if ((battle_config.atc_gmonly == 0 || pc_isGM (sd)) &&
- (pc_isGM (sd) >= get_atcommand_level (AtCommand_Hide)))
- sd->status.option &= (OPTION_MASK | OPTION_HIDE);
- else
- sd->status.option &= OPTION_MASK;
-
- // スキルユニット関係ã®åˆæœŸåŒ–
- memset (sd->skillunit, 0, sizeof (sd->skillunit));
- memset (sd->skillunittick, 0, sizeof (sd->skillunittick));
+ sd->status.option = Option::ZERO;
// init ignore list
- memset (sd->ignore, 0, sizeof (sd->ignore));
+ memset(sd->ignore, 0, sizeof(sd->ignore));
// パーティー関係ã®åˆæœŸåŒ–
sd->party_sended = 0;
@@ -879,73 +722,58 @@ int pc_authok (int id, int login_id2, time_t connect_until_time,
sd->party_y = -1;
sd->party_hp = -1;
- // ギルド関係ã®åˆæœŸåŒ–
- sd->guild_sended = 0;
- sd->guild_invite = 0;
- sd->guild_alliance = 0;
-
// イベント関係ã®åˆæœŸåŒ–
- memset (sd->eventqueue, 0, sizeof (sd->eventqueue));
+ memset(sd->eventqueue, 0, sizeof(sd->eventqueue));
for (int i = 0; i < MAX_EVENTTIMER; i++)
- sd->eventtimer[i] = -1;
+ {
+ // sd->eventtimer[i] = nullptr;
+ }
+
// ä½ç½®ã®è¨­å®š
- pc_setpos (sd, sd->status.last_point.map, sd->status.last_point.x,
- sd->status.last_point.y, 0);
+ pc_setpos(sd, sd->status.last_point.map, sd->status.last_point.x,
+ sd->status.last_point.y, BeingRemoveWhy::GONE);
// パーティã€ã‚®ãƒ«ãƒ‰ãƒ‡ãƒ¼ã‚¿ã®è¦æ±‚
if (sd->status.party_id > 0
- && (p = party_search (sd->status.party_id)) == NULL)
- party_request_info (sd->status.party_id);
- if (sd->status.guild_id > 0
- && (g = guild_search (sd->status.guild_id)) == NULL)
- guild_request_info (sd->status.guild_id);
+ && (p = party_search(sd->status.party_id)) == NULL)
+ party_request_info(sd->status.party_id);
// pvpã®è¨­å®š
sd->pvp_rank = 0;
sd->pvp_point = 0;
- sd->pvp_timer = -1;
+ // sd->pvp_timer = nullptr;
// 通知
- clif_authok (sd);
- map_addnickdb (sd);
- if (map_charid2nick (sd->status.char_id) == NULL)
- map_addchariddb (sd->status.char_id, sd->status.name);
+ clif_authok(sd);
+ map_addnickdb(sd);
+ if (map_charid2nick(sd->status.char_id) == NULL)
+ map_addchariddb(sd->status.char_id, sd->status.name);
//スパノビ用死ã«ã‚«ã‚¦ãƒ³ã‚¿ãƒ¼ã®ã‚¹ã‚¯ãƒªãƒ—ト変数ã‹ã‚‰ã®èª­ã¿å‡ºã—ã¨sdã¸ã®ã‚»ãƒƒãƒˆ
- sd->die_counter = pc_readglobalreg (sd, "PC_DIE_COUNTER");
-
- if (night_flag == 1)
- {
- char tmpstr[1024];
- strcpy (tmpstr, "Actually, it's the night...");
- clif_wis_message (sd->fd, wisp_server_name, tmpstr,
- strlen (tmpstr) + 1);
- sd->opt2 |= STATE_BLIND;
- }
+ sd->die_counter = pc_readglobalreg(sd, "PC_DIE_COUNTER");
// ステータスåˆæœŸè¨ˆç®—ãªã©
- pc_calcstatus (sd, 1);
+ pc_calcstatus(sd, 1);
- if (pc_isGM (sd))
+ if (pc_isGM(sd))
{
- printf
- ("Connection accepted: character '%s' (account: %d; GM level %d).\n",
- sd->status.name, sd->status.account_id, pc_isGM (sd));
- clif_updatestatus (sd, SP_GM);
+ PRINTF("Connection accepted: character '%s' (account: %d; GM level %d).\n",
+ sd->status.name, sd->status.account_id, pc_isGM(sd));
+ clif_updatestatus(sd, SP::GM);
}
else
- printf ("Connection accepted: Character '%s' (account: %d).\n",
+ PRINTF("Connection accepted: Character '%s' (account: %d).\n",
sd->status.name, sd->status.account_id);
// Message of the Dayã®é€ä¿¡
{
char buf[256];
FILE *fp;
- if ((fp = fopen_ (motd_txt, "r")) != NULL)
+ if ((fp = fopen_(motd_txt, "r")) != NULL)
{
- while (fgets (buf, sizeof (buf) - 1, fp) != NULL)
+ while (fgets(buf, sizeof(buf) - 1, fp) != NULL)
{
for (int i = 0; buf[i]; i++)
{
@@ -955,35 +783,38 @@ int pc_authok (int id, int login_id2, time_t connect_until_time,
break;
}
}
- clif_displaymessage (sd->fd, buf);
+ clif_displaymessage(sd->fd, buf);
}
- fclose_ (fp);
+ fclose_(fp);
}
}
sd->auto_ban_info.in_progress = 0;
// Initialize antispam vars
- sd->chat_reset_due = sd->chat_lines_in = sd->chat_total_repeats =
- sd->chat_repeat_reset_due = 0;
+ sd->chat_reset_due = TimeT();
+ sd->chat_lines_in = sd->chat_total_repeats = 0;
+ sd->chat_repeat_reset_due = TimeT();
sd->chat_lastmsg[0] = '\0';
memset(sd->flood_rates, 0, sizeof(sd->flood_rates));
- sd->packet_flood_reset_due = sd->packet_flood_in = 0;
+ sd->packet_flood_reset_due = TimeT();
+ sd->packet_flood_in = 0;
// Obtain IP address (if they are still connected)
if (!getpeername(sd->fd, (struct sockaddr *)&sai, &sa_len))
sd->ip = sai.sin_addr;
// message of the limited time of the account
- if (connect_until_time != 0)
- { // don't display if it's unlimited or unknow value
- char tmpstr[1024];
- strftime (tmpstr, sizeof (tmpstr) - 1, "Your account time limit is: %d-%m-%Y %H:%M:%S.", gmtime (&connect_until_time));
- clif_wis_message (sd->fd, wisp_server_name, tmpstr,
- strlen (tmpstr) + 1);
+ if (connect_until_time)
+ {
+ // don't display if it's unlimited or unknow value
+ char tmpstr[] = WITH_TIMESTAMP("Your account time limit is: ");
+ REPLACE_TIMESTAMP(tmpstr, connect_until_time);
+
+ clif_wis_message(sd->fd, wisp_server_name, tmpstr, sizeof(tmpstr));
}
- pc_calcstatus (sd, 1);
+ pc_calcstatus(sd, 1);
return 0;
}
@@ -992,24 +823,25 @@ int pc_authok (int id, int login_id2, time_t connect_until_time,
* session idã«å•é¡Œã‚ã‚Šãªã®ã§å¾Œå§‹æœ«
*------------------------------------------
*/
-int pc_authfail (int id)
+int pc_authfail(int id)
{
struct map_session_data *sd;
- sd = map_id2sd (id);
+ sd = map_id2sd(id);
if (sd == NULL)
return 1;
- clif_authfail_fd (sd->fd, 0);
+ clif_authfail_fd(sd->fd, 0);
return 0;
}
-static int pc_calc_skillpoint (struct map_session_data *sd)
+static
+int pc_calc_skillpoint(struct map_session_data *sd)
{
- int i, skill_points = 0;
+ int i, skill_points = 0;
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
for (i = 0; i < skill_pool_skills_size; i++) {
int lv = sd->status.skill[skill_pool_skills[i]].lv;
@@ -1021,226 +853,52 @@ static int pc_calc_skillpoint (struct map_session_data *sd)
}
/*==========================================
- * 覚ãˆã‚‰ã‚Œã‚‹ã‚¹ã‚­ãƒ«ã®è¨ˆç®—
- *------------------------------------------
- */
-static
-int pc_calc_skilltree (struct map_session_data *sd)
-{
- int i, id = 0, flag;
- int c = 0, s = 0;
- //転生や養å­ã®å ´åˆã®å…ƒã®è·æ¥­ã‚’算出ã™ã‚‹
- struct pc_base_job s_class;
-
- nullpo_retr (0, sd);
-
- s_class = pc_calc_base_job (sd->status.pc_class);
- c = s_class.job;
- s = (s_class.upper == 1) ? 1 : 0; //ソ転生以外ã¯é€šå¸¸ã®ã‚¹ã‚­ãƒ«ï¼Ÿ
-
- if ((battle_config.skillup_limit)
- && ((c >= 0 && c < 23) || (c >= 4001 && c < 4023)
- || (c >= 4023 && c < 4045)))
- {
- int skill_point = pc_calc_skillpoint (sd);
- if (skill_point < 9)
- c = 0;
- else if ((sd->status.skill_point >= sd->status.job_level
- && skill_point < 58) && ((c > 6 && c < 23) || (c > 4007
- && c < 4023)
- || (c > 4029 && c < 4045)))
- {
- switch (c)
- {
- case 7:
- case 14:
- c = 1;
- break;
- case 8:
- case 15:
- c = 4;
- break;
- case 9:
- case 16:
- c = 2;
- break;
- case 10:
- case 18:
- c = 5;
- break;
- case 11:
- case 19:
- case 20:
- c = 3;
- break;
- case 12:
- case 17:
- c = 6;
- break;
- case 4008:
- case 4015:
- c = 4002;
- break;
- case 4009:
- case 4016:
- c = 4005;
- break;
- case 4010:
- case 4017:
- c = 4003;
- break;
- case 4011:
- case 4019:
- c = 4006;
- break;
- case 4012:
- case 4020:
- case 4021:
- c = 4004;
- break;
- case 4013:
- case 4018:
- c = 4007;
- break;
- case 4030:
- case 4037:
- c = 4024;
- break;
- case 4031:
- case 4038:
- c = 4027;
- break;
- case 4032:
- case 4039:
- c = 4025;
- break;
- case 4033:
- case 4040:
- c = 4028;
- break;
- case 4034:
- case 4041:
- case 4042:
- c = 4026;
- break;
- case 4035:
- case 4043:
- c = 4029;
- break;
-
- }
- }
- }
-
- /*Comment this out for now, as we manage skills differently
- * for(i=0;i<MAX_SKILL;i++)
- * if (i < TMW_MAGIC || i > TMW_MAGIC_END){ // [Fate] This hack gets TMW magic working and persisted without bothering about the skill tree.
- * if (sd->status.skill[i].flag != 13) sd->status.skill[i].id=0;
- * if (sd->status.skill[i].flag && sd->status.skill[i].flag != 13){ // cardスキルãªã‚‰ã€
- * sd->status.skill[i].lv=(sd->status.skill[i].flag==1)?0:sd->status.skill[i].flag-2; // 本当ã®lvã«
- * sd->status.skill[i].flag=0; // flagã¯0ã«ã—ã¦ãŠã
- * }
- * }
- */
-
- if (battle_config.gm_allskill > 0
- && pc_isGM (sd) >= battle_config.gm_allskill)
- {
- // å…¨ã¦ã®ã‚¹ã‚­ãƒ«
- for (i = 1; i < 158; i++)
- sd->status.skill[i].id = i;
- for (i = 210; i < 291; i++)
- sd->status.skill[i].id = i;
- for (i = 304; i < 337; i++)
- sd->status.skill[i].id = i;
- if (battle_config.enable_upper_class)
- { //confã§ç„¡åŠ¹ã§ãªã‘ã‚Œã°èª­ã¿è¾¼ã‚€
- for (i = 355; i < MAX_SKILL; i++)
- sd->status.skill[i].id = i;
- }
-
- }
- else
- {
- // 通常ã®è¨ˆç®—
- do
- {
- flag = 0;
- for (i = 0; (id = skill_tree[s][c][i].id) > 0; i++)
- {
- int j, f = 1;
- if (!battle_config.skillfree)
- {
- for (j = 0; j < 5; j++)
- {
- if (skill_tree[s][c][i].need[j].id &&
- pc_checkskill (sd,
- skill_tree[s][c][i].need[j].id) <
- skill_tree[s][c][i].need[j].lv)
- f = 0;
- }
- }
- if (f && sd->status.skill[id].id == 0)
- {
- sd->status.skill[id].id = id;
- flag = 1;
- }
- }
- }
- while (flag);
- }
-// if(battle_config.etc_log)
-// printf("calc skill_tree\n");
- return 0;
-}
-
-/*==========================================
* é‡é‡ã‚¢ã‚¤ã‚³ãƒ³ã®ç¢ºèª
*------------------------------------------
*/
-int pc_checkweighticon (struct map_session_data *sd)
+int pc_checkweighticon(struct map_session_data *sd)
{
- int flag = 0;
+ int flag = 0;
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
if (sd->weight * 2 >= sd->max_weight
- && sd->sc_data[SC_FLYING_BACKPACK].timer == -1)
+ && !sd->sc_data[StatusChange::SC_FLYING_BACKPACK].timer)
flag = 1;
if (sd->weight * 10 >= sd->max_weight * 9)
flag = 2;
+ // this is horribly hackish and may have caused crashes
if (flag == 1)
{
- if (sd->sc_data[SC_WEIGHT50].timer == -1)
- skill_status_change_start (&sd->bl, SC_WEIGHT50, 0, 0, 0, 0, 0,
- 0);
+ if (!sd->sc_data[StatusChange::SC_WEIGHT50].timer)
+ skill_status_change_start(&sd->bl, StatusChange::SC_WEIGHT50, 0, interval_t::zero());
}
else
{
- skill_status_change_end (&sd->bl, SC_WEIGHT50, -1);
+ skill_status_change_end(&sd->bl, StatusChange::SC_WEIGHT50, nullptr);
}
if (flag == 2)
{
- if (sd->sc_data[SC_WEIGHT90].timer == -1)
- skill_status_change_start (&sd->bl, SC_WEIGHT90, 0, 0, 0, 0, 0,
- 0);
+ if (!sd->sc_data[StatusChange::SC_WEIGHT90].timer)
+ skill_status_change_start(&sd->bl, StatusChange::SC_WEIGHT90, 0, interval_t::zero());
}
else
{
- skill_status_change_end (&sd->bl, SC_WEIGHT90, -1);
+ skill_status_change_end(&sd->bl, StatusChange::SC_WEIGHT90, nullptr);
}
return 0;
}
static
-void pc_set_weapon_look (struct map_session_data *sd)
+void pc_set_weapon_look(struct map_session_data *sd)
{
if (sd->attack_spell_override)
- clif_changelook (&sd->bl, LOOK_WEAPON,
- sd->attack_spell_look_override);
+ clif_changelook(&sd->bl, LOOK::WEAPON,
+ sd->attack_spell_look_override);
else
- clif_changelook (&sd->bl, LOOK_WEAPON, sd->status.weapon);
+ clif_changelook(&sd->bl, LOOK::WEAPON,
+ static_cast<uint16_t>(sd->status.weapon));
}
/*==========================================
@@ -1250,37 +908,32 @@ void pc_set_weapon_look (struct map_session_data *sd)
* 能動的ã«å¤‰åŒ–ã•ã›ãŸãƒ‘ラメータã¯è‡ªå‰ã§sendã™ã‚‹ã‚ˆã†ã«
*------------------------------------------
*/
-int pc_calcstatus (struct map_session_data *sd, int first)
+int pc_calcstatus(struct map_session_data *sd, int first)
{
- int b_speed, b_max_hp, b_max_sp, b_hp, b_sp, b_weight, b_max_weight,
- b_paramb[6], b_parame[6], b_hit, b_flee;
- int b_aspd, b_watk, b_def, b_watk2, b_def2, b_flee2, b_critical,
- b_attackrange, b_matk1, b_matk2, b_mdef, b_mdef2, b_class;
- int b_base_atk;
- struct skill b_skill[MAX_SKILL];
- int i, bl, index;
- int skill, aspd_rate, wele, wele_, def_ele, refinedef = 0;
- int str, dstr, dex;
- struct pc_base_job s_class;
-
- nullpo_retr (0, sd);
+ int b_max_hp, b_max_sp, b_hp, b_sp, b_weight, b_max_weight,
+ b_hit, b_flee;
+ int b_watk, b_def, b_watk2, b_def2, b_flee2, b_critical,
+ b_attackrange, b_matk1, b_matk2, b_mdef, b_mdef2;
+ int b_base_atk;
+ int bl, index;
+ int aspd_rate, refinedef = 0;
+ int str, dstr, dex;
- //転生や養å­ã®å ´åˆã®å…ƒã®è·æ¥­ã‚’算出ã™ã‚‹
- s_class = pc_calc_base_job (sd->status.pc_class);
+ nullpo_ret(sd);
- b_speed = sd->speed;
+ interval_t b_speed = sd->speed;
b_max_hp = sd->status.max_hp;
b_max_sp = sd->status.max_sp;
b_hp = sd->status.hp;
b_sp = sd->status.sp;
b_weight = sd->weight;
b_max_weight = sd->max_weight;
- memcpy (b_paramb, &sd->paramb, sizeof (b_paramb));
- memcpy (b_parame, &sd->paramc, sizeof (b_parame));
- memcpy (b_skill, &sd->status.skill, sizeof (b_skill));
+ earray<int, ATTR, ATTR::COUNT> b_paramb = sd->paramb;
+ earray<int, ATTR, ATTR::COUNT> b_parame = sd->paramc;
+ earray<skill_value, SkillID, MAX_SKILL> b_skill = sd->status.skill;
b_hit = sd->hit;
b_flee = sd->flee;
- b_aspd = sd->aspd;
+ interval_t b_aspd = sd->aspd;
b_watk = sd->watk;
b_def = sd->def;
b_watk2 = sd->watk2;
@@ -1292,18 +945,14 @@ int pc_calcstatus (struct map_session_data *sd, int first)
b_matk2 = sd->matk2;
b_mdef = sd->mdef;
b_mdef2 = sd->mdef2;
- b_class = sd->view_class;
- sd->view_class = sd->status.pc_class;
b_base_atk = sd->base_atk;
- pc_calc_skilltree (sd); // スキルツリーã®è¨ˆç®—
-
- sd->max_weight = max_weight_base[s_class.job] + sd->status.str * 300;
+ sd->max_weight = max_weight_base_0 + sd->status.attrs[ATTR::STR] * 300;
if (first & 1)
{
sd->weight = 0;
- for (i = 0; i < MAX_INVENTORY; i++)
+ for (int i = 0; i < MAX_INVENTORY; i++)
{
if (sd->status.inventory[i].nameid == 0
|| sd->inventory_data[i] == NULL)
@@ -1316,24 +965,27 @@ int pc_calcstatus (struct map_session_data *sd, int first)
sd->cart_weight = 0;
sd->cart_max_num = MAX_CART;
sd->cart_num = 0;
- for (i = 0; i < MAX_CART; i++)
+ for (int i = 0; i < MAX_CART; i++)
{
if (sd->status.cart[i].nameid == 0)
continue;
sd->cart_weight +=
- itemdb_weight (sd->status.cart[i].nameid) *
+ itemdb_weight(sd->status.cart[i].nameid) *
sd->status.cart[i].amount;
sd->cart_num++;
}
}
- memset (sd->paramb, 0, sizeof (sd->paramb));
- memset (sd->parame, 0, sizeof (sd->parame));
+ for (auto& p : sd->paramb)
+ p = 0;
+ for (auto& p : sd->parame)
+ p = 0;
+
sd->hit = 0;
sd->flee = 0;
sd->flee2 = 0;
sd->critical = 0;
- sd->aspd = 0;
+ sd->aspd = interval_t::zero();
sd->watk = 0;
sd->def = 0;
sd->mdef = 0;
@@ -1344,8 +996,6 @@ int pc_calcstatus (struct map_session_data *sd, int first)
sd->status.max_sp = 0;
sd->attackrange = 0;
sd->attackrange_ = 0;
- sd->atk_ele = 0;
- sd->def_ele = 0;
sd->star = 0;
sd->overrefine = 0;
sd->matk1 = 0;
@@ -1353,33 +1003,17 @@ int pc_calcstatus (struct map_session_data *sd, int first)
sd->speed = DEFAULT_WALK_SPEED;
sd->hprate = 100;
sd->sprate = 100;
- sd->castrate = 100;
sd->dsprate = 100;
sd->base_atk = 0;
sd->arrow_atk = 0;
- sd->arrow_ele = 0;
sd->arrow_hit = 0;
sd->arrow_range = 0;
sd->nhealhp = sd->nhealsp = sd->nshealhp = sd->nshealsp = sd->nsshealhp =
sd->nsshealsp = 0;
- memset (sd->addele, 0, sizeof (sd->addele));
- memset (sd->addrace, 0, sizeof (sd->addrace));
- memset (sd->addsize, 0, sizeof (sd->addsize));
- memset (sd->addele_, 0, sizeof (sd->addele_));
- memset (sd->addrace_, 0, sizeof (sd->addrace_));
- memset (sd->addsize_, 0, sizeof (sd->addsize_));
- memset (sd->subele, 0, sizeof (sd->subele));
- memset (sd->subrace, 0, sizeof (sd->subrace));
- memset (sd->addeff, 0, sizeof (sd->addeff));
- memset (sd->addeff2, 0, sizeof (sd->addeff2));
- memset (sd->reseff, 0, sizeof (sd->reseff));
- memset (&sd->special_state, 0, sizeof (sd->special_state));
- memset (sd->weapon_coma_ele, 0, sizeof (sd->weapon_coma_ele));
- memset (sd->weapon_coma_race, 0, sizeof (sd->weapon_coma_race));
+ memset(&sd->special_state, 0, sizeof(sd->special_state));
sd->watk_ = 0; //二刀æµç”¨(ä»®)
sd->watk_2 = 0;
- sd->atk_ele_ = 0;
sd->star_ = 0;
sd->overrefine_ = 0;
@@ -1389,76 +1023,32 @@ int pc_calcstatus (struct map_session_data *sd, int first)
sd->sprecov_rate = 100;
sd->critical_def = 0;
sd->double_rate = 0;
- sd->near_attack_def_rate = sd->long_attack_def_rate = 0;
sd->atk_rate = sd->matk_rate = 100;
- sd->ignore_def_ele = sd->ignore_def_race = 0;
- sd->ignore_def_ele_ = sd->ignore_def_race_ = 0;
- sd->ignore_mdef_ele = sd->ignore_mdef_race = 0;
sd->arrow_cri = 0;
- sd->magic_def_rate = sd->misc_def_rate = 0;
- memset (sd->arrow_addele, 0, sizeof (sd->arrow_addele));
- memset (sd->arrow_addrace, 0, sizeof (sd->arrow_addrace));
- memset (sd->arrow_addsize, 0, sizeof (sd->arrow_addsize));
- memset (sd->arrow_addeff, 0, sizeof (sd->arrow_addeff));
- memset (sd->arrow_addeff2, 0, sizeof (sd->arrow_addeff2));
- memset (sd->magic_addele, 0, sizeof (sd->magic_addele));
- memset (sd->magic_addrace, 0, sizeof (sd->magic_addrace));
- memset (sd->magic_subrace, 0, sizeof (sd->magic_subrace));
sd->perfect_hit = 0;
sd->critical_rate = sd->hit_rate = sd->flee_rate = sd->flee2_rate = 100;
sd->def_rate = sd->def2_rate = sd->mdef_rate = sd->mdef2_rate = 100;
- sd->def_ratio_atk_ele = sd->def_ratio_atk_ele_ = 0;
- sd->def_ratio_atk_race = sd->def_ratio_atk_race_ = 0;
- sd->get_zeny_num = 0;
- sd->add_damage_class_count = sd->add_damage_class_count_ =
- sd->add_magic_damage_class_count = 0;
- sd->add_def_class_count = sd->add_mdef_class_count = 0;
- sd->monster_drop_item_count = 0;
- memset (sd->add_damage_classrate, 0, sizeof (sd->add_damage_classrate));
- memset (sd->add_damage_classrate_, 0, sizeof (sd->add_damage_classrate_));
- memset (sd->add_magic_damage_classrate, 0,
- sizeof (sd->add_magic_damage_classrate));
- memset (sd->add_def_classrate, 0, sizeof (sd->add_def_classrate));
- memset (sd->add_mdef_classrate, 0, sizeof (sd->add_mdef_classrate));
- memset (sd->monster_drop_race, 0, sizeof (sd->monster_drop_race));
- memset (sd->monster_drop_itemrate, 0, sizeof (sd->monster_drop_itemrate));
sd->speed_add_rate = sd->aspd_add_rate = 100;
- sd->double_add_rate = sd->perfect_hit_add = sd->get_zeny_add_num = 0;
- sd->splash_range = sd->splash_add_range = 0;
- sd->autospell_id = sd->autospell_lv = sd->autospell_rate = 0;
+ sd->double_add_rate = sd->perfect_hit_add = 0;
sd->hp_drain_rate = sd->hp_drain_per = sd->sp_drain_rate =
sd->sp_drain_per = 0;
sd->hp_drain_rate_ = sd->hp_drain_per_ = sd->sp_drain_rate_ =
sd->sp_drain_per_ = 0;
- sd->short_weapon_damage_return = sd->long_weapon_damage_return = 0;
- sd->magic_damage_return = 0; //AppleGirl Was Here
- sd->random_attack_increase_add = sd->random_attack_increase_per = 0;
-
- if (!sd->disguiseflag && sd->disguise)
- {
- sd->disguise = 0;
- pc_set_weapon_look (sd);
- clif_changelook (&sd->bl, LOOK_SHIELD, sd->status.shield);
- clif_changelook (&sd->bl, LOOK_HEAD_BOTTOM, sd->status.head_bottom);
- clif_changelook (&sd->bl, LOOK_HEAD_TOP, sd->status.head_top);
- clif_changelook (&sd->bl, LOOK_HEAD_MID, sd->status.head_mid);
- clif_clearchar (&sd->bl, 9);
- pc_setpos (sd, sd->mapname, sd->bl.x, sd->bl.y, 3);
- }
sd->spellpower_bonus_target = 0;
- for (i = 0; i < 10; i++)
+ for (EQUIP i : EQUIPs_noarrow)
{
index = sd->equip_index[i];
if (index < 0)
continue;
- if (i == 9 && sd->equip_index[8] == index)
+ if (i == EQUIP::WEAPON && sd->equip_index[EQUIP::SHIELD] == index)
continue;
- if (i == 5 && sd->equip_index[4] == index)
+ if (i == EQUIP::TORSO && sd->equip_index[EQUIP::LEGS] == index)
continue;
- if (i == 6
- && (sd->equip_index[5] == index || sd->equip_index[4] == index))
+ if (i == EQUIP::HAT
+ && (sd->equip_index[EQUIP::TORSO] == index
+ || sd->equip_index[EQUIP::LEGS] == index))
continue;
if (sd->inventory_data[index])
@@ -1466,50 +1056,50 @@ int pc_calcstatus (struct map_session_data *sd, int first)
sd->spellpower_bonus_target +=
sd->inventory_data[index]->magic_bonus;
- if (sd->inventory_data[index]->type == 4)
+ if (sd->inventory_data[index]->type == ItemType::WEAPON)
{
if (sd->status.inventory[index].card[0] != 0x00ff
&& sd->status.inventory[index].card[0] != 0x00fe
&& sd->status.inventory[index].card[0] != (short) 0xff00)
{
- int j;
+ int j;
for (j = 0; j < sd->inventory_data[index]->slot; j++)
{ // カード
- int c = sd->status.inventory[index].card[j];
+ int c = sd->status.inventory[index].card[j];
if (c > 0)
{
argrec_t arg[2];
arg[0].name = "@slotId";
- arg[0].v.i = i;
+ arg[0].v.i = int(i);
arg[1].name = "@itemId";
arg[1].v.i = sd->inventory_data[index]->nameid;
- if (i == 8
- && sd->status.inventory[index].equip == 0x20)
+ if (i == EQUIP::SHIELD
+ && sd->status.inventory[index].equip == EPOS::SHIELD)
sd->state.lr_flag = 1;
- run_script_l (itemdb_equipscript (c), 0, sd->bl.id,
+ run_script_l(itemdb_equipscript(c), 0, sd->bl.id,
0, 2, arg);
sd->state.lr_flag = 0;
}
}
}
}
- else if (sd->inventory_data[index]->type == 5)
+ else if (sd->inventory_data[index]->type == ItemType::ARMOR)
{ // 防具
if (sd->status.inventory[index].card[0] != 0x00ff
&& sd->status.inventory[index].card[0] != 0x00fe
&& sd->status.inventory[index].card[0] != (short) 0xff00)
{
- int j;
+ int j;
for (j = 0; j < sd->inventory_data[index]->slot; j++)
{ // カード
- int c = sd->status.inventory[index].card[j];
+ int c = sd->status.inventory[index].card[j];
if (c > 0) {
argrec_t arg[2];
arg[0].name = "@slotId";
- arg[0].v.i = i;
+ arg[0].v.i = int(i);
arg[1].name = "@itemId";
arg[1].v.i = sd->inventory_data[index]->nameid;
- run_script_l (itemdb_equipscript (c), 0, sd->bl.id,
+ run_script_l(itemdb_equipscript(c), 0, sd->bl.id,
0, 2, arg);
}
}
@@ -1522,59 +1112,57 @@ int pc_calcstatus (struct map_session_data *sd, int first)
if (sd->spellpower_bonus_target < 0)
sd->spellpower_bonus_target =
(sd->spellpower_bonus_target * 256) /
- (MIN (128 + skill_power (sd, TMW_ASTRAL_SOUL), 256));
+ (min(128 + skill_power(sd, SkillID::TMW_ASTRAL_SOUL), 256));
#endif
if (sd->spellpower_bonus_target < sd->spellpower_bonus_current)
sd->spellpower_bonus_current = sd->spellpower_bonus_target;
- wele = sd->atk_ele;
- wele_ = sd->atk_ele_;
- def_ele = sd->def_ele;
- memcpy (sd->paramcard, sd->parame, sizeof (sd->paramcard));
+ sd->paramcard = sd->parame;
// 装備å“ã«ã‚ˆã‚‹ã‚¹ãƒ†ãƒ¼ã‚¿ã‚¹å¤‰åŒ–ã¯ã“ã“ã§å®Ÿè¡Œ
- for (i = 0; i < 10; i++)
+ for (EQUIP i : EQUIPs_noarrow)
{
index = sd->equip_index[i];
if (index < 0)
continue;
- if (i == 9 && sd->equip_index[8] == index)
+ if (i == EQUIP::WEAPON && sd->equip_index[EQUIP::SHIELD] == index)
continue;
- if (i == 5 && sd->equip_index[4] == index)
+ if (i == EQUIP::TORSO && sd->equip_index[EQUIP::LEGS] == index)
continue;
- if (i == 6
- && (sd->equip_index[5] == index || sd->equip_index[4] == index))
+ if (i == EQUIP::HAT
+ && (sd->equip_index[EQUIP::TORSO] == index
+ || sd->equip_index[EQUIP::LEGS] == index))
continue;
if (sd->inventory_data[index])
{
sd->def += sd->inventory_data[index]->def;
- if (sd->inventory_data[index]->type == 4)
+ if (sd->inventory_data[index]->type == ItemType::WEAPON)
{
- int r, wlv = sd->inventory_data[index]->wlv;
- if (i == 8 && sd->status.inventory[index].equip == 0x20)
+ int r;
+ if (i == EQUIP::SHIELD
+ && sd->status.inventory[index].equip == EPOS::SHIELD)
{
//二刀æµç”¨ãƒ‡ãƒ¼ã‚¿å…¥åŠ›
sd->watk_ += sd->inventory_data[index]->atk;
sd->watk_2 = (r = sd->status.inventory[index].refine) * // 精錬攻撃力
- refinebonus[wlv][0];
- if ((r -= refinebonus[wlv][2]) > 0) // éŽå‰°ç²¾éŒ¬ãƒœãƒ¼ãƒŠã‚¹
- sd->overrefine_ = r * refinebonus[wlv][1];
+ 0;
+ if ((r -= 10) > 0) // éŽå‰°ç²¾éŒ¬ãƒœãƒ¼ãƒŠã‚¹
+ sd->overrefine_ = r * 0;
if (sd->status.inventory[index].card[0] == 0x00ff)
{ // 製造武器
sd->star_ = (sd->status.inventory[index].card[1] >> 8); // 星ã®ã‹ã‘ら
- wele_ = (sd->status.inventory[index].card[1] & 0x0f); // 属 性
}
sd->attackrange_ += sd->inventory_data[index]->range;
sd->state.lr_flag = 1;
{
argrec_t arg[2];
arg[0].name = "@slotId";
- arg[0].v.i = i;
+ arg[0].v.i = int(i);
arg[1].name = "@itemId";
arg[1].v.i = sd->inventory_data[index]->nameid;
- run_script_l (sd->inventory_data[index]->equip_script, 0,
+ run_script_l(sd->inventory_data[index]->equip_script, 0,
sd->bl.id, 0, 2, arg);
}
sd->state.lr_flag = 0;
@@ -1583,61 +1171,60 @@ int pc_calcstatus (struct map_session_data *sd, int first)
{ //二刀æµæ­¦å™¨ä»¥å¤–
argrec_t arg[2];
arg[0].name = "@slotId";
- arg[0].v.i = i;
+ arg[0].v.i = int(i);
arg[1].name = "@itemId";
arg[1].v.i = sd->inventory_data[index]->nameid;
sd->watk += sd->inventory_data[index]->atk;
sd->watk2 += (r = sd->status.inventory[index].refine) * // 精錬攻撃力
- refinebonus[wlv][0];
- if ((r -= refinebonus[wlv][2]) > 0) // éŽå‰°ç²¾éŒ¬ãƒœãƒ¼ãƒŠã‚¹
- sd->overrefine += r * refinebonus[wlv][1];
+ 0;
+ if ((r -= 10) > 0) // éŽå‰°ç²¾éŒ¬ãƒœãƒ¼ãƒŠã‚¹
+ sd->overrefine += r * 0;
if (sd->status.inventory[index].card[0] == 0x00ff)
{ // 製造武器
sd->star += (sd->status.inventory[index].card[1] >> 8); // 星ã®ã‹ã‘ら
- wele = (sd->status.inventory[index].card[1] & 0x0f); // 属 性
}
sd->attackrange += sd->inventory_data[index]->range;
- run_script_l (sd->inventory_data[index]->equip_script, 0,
+ run_script_l(sd->inventory_data[index]->equip_script, 0,
sd->bl.id, 0, 2, arg);
}
}
- else if (sd->inventory_data[index]->type == 5)
+ else if (sd->inventory_data[index]->type == ItemType::ARMOR)
{
argrec_t arg[2];
arg[0].name = "@slotId";
- arg[0].v.i = i;
+ arg[0].v.i = int(i);
arg[1].name = "@itemId";
arg[1].v.i = sd->inventory_data[index]->nameid;
sd->watk += sd->inventory_data[index]->atk;
refinedef +=
- sd->status.inventory[index].refine * refinebonus[0][0];
- run_script_l (sd->inventory_data[index]->equip_script, 0,
+ sd->status.inventory[index].refine * 0;
+ run_script_l(sd->inventory_data[index]->equip_script, 0,
sd->bl.id, 0, 2, arg);
}
}
}
- if (battle_is_unarmed (&sd->bl))
+ if (battle_is_unarmed(&sd->bl))
{
- sd->watk += skill_power (sd, TMW_BRAWLING) / 3; // +66 for 200
- sd->watk2 += skill_power (sd, TMW_BRAWLING) >> 3; // +25 for 200
- sd->watk_ += skill_power (sd, TMW_BRAWLING) / 3; // +66 for 200
- sd->watk_2 += skill_power (sd, TMW_BRAWLING) >> 3; // +25 for 200
+ sd->watk += skill_power(sd, SkillID::TMW_BRAWLING) / 3; // +66 for 200
+ sd->watk2 += skill_power(sd, SkillID::TMW_BRAWLING) >> 3; // +25 for 200
+ sd->watk_ += skill_power(sd, SkillID::TMW_BRAWLING) / 3; // +66 for 200
+ sd->watk_2 += skill_power(sd, SkillID::TMW_BRAWLING) >> 3; // +25 for 200
}
- if (sd->equip_index[10] >= 0)
+ if (sd->equip_index[EQUIP::ARROW] >= 0)
{ // 矢
- index = sd->equip_index[10];
+ index = sd->equip_index[EQUIP::ARROW];
if (sd->inventory_data[index])
{ //ã¾ã å±žæ€§ãŒå…¥ã£ã¦ã„ãªã„
argrec_t arg[2];
arg[0].name = "@slotId";
- arg[0].v.i = i;
+ arg[0].v.i = int(EQUIP::ARROW);
arg[1].name = "@itemId";
arg[1].v.i = sd->inventory_data[index]->nameid;
sd->state.lr_flag = 2;
- run_script_l (sd->inventory_data[index]->equip_script, 0, sd->bl.id,
+ run_script_l(sd->inventory_data[index]->equip_script, 0, sd->bl.id,
0, 2, arg);
sd->state.lr_flag = 0;
sd->arrow_atk += sd->inventory_data[index]->atk;
@@ -1651,145 +1238,44 @@ int pc_calcstatus (struct map_session_data *sd, int first)
sd->attackrange_ = 1;
if (sd->attackrange < sd->attackrange_)
sd->attackrange = sd->attackrange_;
- if (sd->status.weapon == 11)
+ if (sd->status.weapon == ItemLook::BOW)
sd->attackrange += sd->arrow_range;
- if (wele > 0)
- sd->atk_ele = wele;
- if (wele_ > 0)
- sd->atk_ele_ = wele_;
- if (def_ele > 0)
- sd->def_ele = def_ele;
sd->double_rate += sd->double_add_rate;
sd->perfect_hit += sd->perfect_hit_add;
- sd->get_zeny_num += sd->get_zeny_add_num;
- sd->splash_range += sd->splash_add_range;
if (sd->speed_add_rate != 100)
sd->speed_rate += sd->speed_add_rate - 100;
if (sd->aspd_add_rate != 100)
sd->aspd_rate += sd->aspd_add_rate - 100;
- // 武器ATKサイズ補正 (å³æ‰‹)
- sd->atkmods[0] = atkmods[0][sd->weapontype1];
- sd->atkmods[1] = atkmods[1][sd->weapontype1];
- sd->atkmods[2] = atkmods[2][sd->weapontype1];
- //武器ATKサイズ補正 (左手)
- sd->atkmods_[0] = atkmods[0][sd->weapontype2];
- sd->atkmods_[1] = atkmods[1][sd->weapontype2];
- sd->atkmods_[2] = atkmods[2][sd->weapontype2];
-
-/*
- // jobボーナス分
- for(i=0;i<sd->status.job_level && i<MAX_LEVEL;i++){
- if(job_bonus[s_class.upper][s_class.job][i])
- sd->paramb[job_bonus[s_class.upper][s_class.job][i]-1]++;
- }
-*/
-
- if ((skill = pc_checkskill (sd, MC_INCCARRY)) > 0) // skill can be used with an item now, thanks to orn [Valaris]
- sd->max_weight += skill * 1000;
-
- // ステータス変化ã«ã‚ˆã‚‹åŸºæœ¬ãƒ‘ラメータ補正
- if (sd->sc_count)
- {
- if (sd->sc_data[SC_CONCENTRATE].timer != -1
- && sd->sc_data[SC_QUAGMIRE].timer == -1)
- { // 集中力å‘上
- sd->paramb[1] +=
- (sd->status.agi + sd->paramb[1] + sd->parame[1] -
- sd->paramcard[1]) * (2 +
- sd->sc_data[SC_CONCENTRATE].val1) / 100;
- sd->paramb[4] +=
- (sd->status.dex + sd->paramb[4] + sd->parame[4] -
- sd->paramcard[4]) * (2 +
- sd->sc_data[SC_CONCENTRATE].val1) / 100;
- }
- if (sd->sc_data[SC_INCREASEAGI].timer != -1
- && sd->sc_data[SC_QUAGMIRE].timer == -1
- && sd->sc_data[SC_DONTFORGETME].timer == -1)
- { // 速度増加
- sd->paramb[1] += 2 + sd->sc_data[SC_INCREASEAGI].val1;
- sd->speed -= sd->speed * 25 / 100;
- }
- if (sd->sc_data[SC_DECREASEAGI].timer != -1) // 速度減少(agiã¯battle.cã§)
- sd->speed = sd->speed * 125 / 100;
- if (sd->sc_data[SC_CLOAKING].timer != -1)
- sd->speed =
- (sd->speed * (76 + (sd->sc_data[SC_INCREASEAGI].val1 * 3))) /
- 100;
- if (sd->sc_data[SC_BLESSING].timer != -1)
- { // ブレッシング
- sd->paramb[0] += sd->sc_data[SC_BLESSING].val1;
- sd->paramb[3] += sd->sc_data[SC_BLESSING].val1;
- sd->paramb[4] += sd->sc_data[SC_BLESSING].val1;
- }
- if (sd->sc_data[SC_GLORIA].timer != -1) // グロリア
- sd->paramb[5] += 30;
- if (sd->sc_data[SC_LOUD].timer != -1 && sd->sc_data[SC_QUAGMIRE].timer == -1) // ラウドボイス
- sd->paramb[0] += 4;
- if (sd->sc_data[SC_QUAGMIRE].timer != -1)
- { // クァグマイア
- sd->speed = sd->speed * 3 / 2;
- sd->paramb[1] -=
- (sd->status.agi + sd->paramb[1] + sd->parame[1]) / 2;
- sd->paramb[4] -=
- (sd->status.dex + sd->paramb[4] + sd->parame[4]) / 2;
- }
- if (sd->sc_data[SC_TRUESIGHT].timer != -1)
- { // トゥルーサイト
- sd->paramb[0] += 5;
- sd->paramb[1] += 5;
- sd->paramb[2] += 5;
- sd->paramb[3] += 5;
- sd->paramb[4] += 5;
- sd->paramb[5] += 5;
- }
- }
- sd->speed -= skill_power (sd, TMW_SPEED) >> 3;
- sd->aspd_rate -= skill_power (sd, TMW_SPEED) / 10;
+ sd->speed -= std::chrono::milliseconds(skill_power(sd, SkillID::TMW_SPEED) / 8);
+ sd->aspd_rate -= skill_power(sd, SkillID::TMW_SPEED) / 10;
if (sd->aspd_rate < 20)
sd->aspd_rate = 20;
-/*
- //1度も死んã§ãªã„Job70スパノビã«+10
- if(s_class.job == 23 && sd->die_counter == 0 && sd->status.job_level >= 70){
- sd->paramb[0]+= 15;
- sd->paramb[1]+= 15;
- sd->paramb[2]+= 15;
- sd->paramb[3]+= 15;
- sd->paramb[4]+= 15;
- sd->paramb[5]+= 15;
- }
-*/
- sd->paramc[0] = sd->status.str + sd->paramb[0] + sd->parame[0];
- sd->paramc[1] = sd->status.agi + sd->paramb[1] + sd->parame[1];
- sd->paramc[2] = sd->status.vit + sd->paramb[2] + sd->parame[2];
- sd->paramc[3] = sd->status.int_ + sd->paramb[3] + sd->parame[3];
- sd->paramc[4] = sd->status.dex + sd->paramb[4] + sd->parame[4];
- sd->paramc[5] = sd->status.luk + sd->paramb[5] + sd->parame[5];
- for (i = 0; i < 6; i++)
- if (sd->paramc[i] < 0)
- sd->paramc[i] = 0;
-
- if (sd->status.weapon == 11 || sd->status.weapon == 13
- || sd->status.weapon == 14)
- {
- str = sd->paramc[4];
- dex = sd->paramc[0];
+ for (ATTR attr : ATTRs)
+ sd->paramc[attr] = max(0, sd->status.attrs[attr] + sd->paramb[attr] + sd->parame[attr]);
+
+ if (sd->status.weapon == ItemLook::BOW
+ || sd->status.weapon == ItemLook::_13
+ || sd->status.weapon == ItemLook::_14)
+ {
+ str = sd->paramc[ATTR::DEX];
+ dex = sd->paramc[ATTR::STR];
}
else
{
- str = sd->paramc[0];
- dex = sd->paramc[4];
+ str = sd->paramc[ATTR::STR];
+ dex = sd->paramc[ATTR::DEX];
sd->critical += ((dex * 3) >> 1);
}
dstr = str / 10;
- sd->base_atk += str + dstr * dstr + dex / 5 + sd->paramc[5] / 5;
-//fprintf(stderr, "baseatk = %d = x + %d + %d + %d + %d\n", sd->base_atk, str, dstr*dstr, dex/5, sd->paramc[5]/5);
- sd->matk1 += sd->paramc[3] + (sd->paramc[3] / 5) * (sd->paramc[3] / 5);
- sd->matk2 += sd->paramc[3] + (sd->paramc[3] / 7) * (sd->paramc[3] / 7);
+ sd->base_atk += str + dstr * dstr + dex / 5 + sd->paramc[ATTR::LUK] / 5;
+//FPRINTF(stderr, "baseatk = %d = x + %d + %d + %d + %d\n", sd->base_atk, str, dstr*dstr, dex/5, sd->paramc[ATTR::LUK]/5);
+ sd->matk1 += sd->paramc[ATTR::INT] + (sd->paramc[ATTR::INT] / 5) * (sd->paramc[ATTR::INT] / 5);
+ sd->matk2 += sd->paramc[ATTR::INT] + (sd->paramc[ATTR::INT] / 7) * (sd->paramc[ATTR::INT] / 7);
if (sd->matk1 < sd->matk2)
{
- int temp = sd->matk2;
+ int temp = sd->matk2;
sd->matk2 = sd->matk1;
sd->matk1 = temp;
}
@@ -1798,26 +1284,26 @@ int pc_calcstatus (struct map_session_data *sd, int first)
#ifdef USE_ASTRAL_SOUL_SKILL
if (sd->matk1 > MAGIC_SKILL_THRESHOLD)
{
- int bonus = sd->matk1 - MAGIC_SKILL_THRESHOLD;
+ int bonus = sd->matk1 - MAGIC_SKILL_THRESHOLD;
// Ok if you are above a certain threshold, you get only (1/8) of that matk1
// if you have Astral soul skill you can get the whole power again (and additionally the 1/8 added)
- sd->matk1 = MAGIC_SKILL_THRESHOLD + (bonus>>3) + ((3*bonus*skill_power(sd, TMW_ASTRAL_SOUL))>>9);
+ sd->matk1 = MAGIC_SKILL_THRESHOLD + (bonus>>3) + ((3*bonus*skill_power(sd, SkillID::TMW_ASTRAL_SOUL))>>9);
}
#endif
sd->matk2 = 0;
if (sd->matk1 < 0)
sd->matk1 = 0;
- sd->hit += sd->paramc[4] + sd->status.base_level;
- sd->flee += sd->paramc[1] + sd->status.base_level;
- sd->def2 += sd->paramc[2];
- sd->mdef2 += sd->paramc[3];
- sd->flee2 += sd->paramc[5] + 10;
- sd->critical += (sd->paramc[5] * 3) + 10;
+ sd->hit += sd->paramc[ATTR::DEX] + sd->status.base_level;
+ sd->flee += sd->paramc[ATTR::AGI] + sd->status.base_level;
+ sd->def2 += sd->paramc[ATTR::VIT];
+ sd->mdef2 += sd->paramc[ATTR::INT];
+ sd->flee2 += sd->paramc[ATTR::LUK] + 10;
+ sd->critical += (sd->paramc[ATTR::LUK] * 3) + 10;
// 200 is the maximum of the skill
// def2 is the defence gained by vit, whereas "def", which is gained by armor, stays as is
- int spbsk = skill_power (sd, TMW_RAGING);
+ int spbsk = skill_power(sd, SkillID::TMW_RAGING);
if (spbsk != 0 && sd->attackrange <= 2)
{
sd->critical += sd->critical * spbsk / 100;
@@ -1860,147 +1346,67 @@ int pc_calcstatus (struct map_session_data *sd, int first)
sd->mdef2 = 1;
// äºŒåˆ€æµ ASPD 修正
- if (sd->status.weapon <= 16)
- sd->aspd +=
- aspd_base[s_class.job][sd->status.weapon] - (sd->paramc[1] * 4 +
- sd->paramc[4]) *
- aspd_base[s_class.job][sd->status.weapon] / 1000;
+ if (sd->status.weapon < ItemLook::SINGLE_HANDED_COUNT)
+ sd->aspd += aspd_base_0[sd->status.weapon]
+ - (sd->paramc[ATTR::AGI] * 4 + sd->paramc[ATTR::DEX])
+ * aspd_base_0[sd->status.weapon] / 1000;
else
- sd->aspd += ((aspd_base[s_class.job][sd->weapontype1] -
- (sd->paramc[1] * 4 +
- sd->paramc[4]) *
- aspd_base[s_class.job][sd->weapontype1] / 1000) +
- (aspd_base[s_class.job][sd->weapontype2] -
- (sd->paramc[1] * 4 +
- sd->paramc[4]) *
- aspd_base[s_class.job][sd->weapontype2] / 1000)) * 140 /
- 200;
+ sd->aspd += (
+ (aspd_base_0[sd->weapontype1]
+ - (sd->paramc[ATTR::AGI] * 4 + sd->paramc[ATTR::DEX])
+ * aspd_base_0[sd->weapontype1] / 1000)
+ + (aspd_base_0[sd->weapontype2]
+ - (sd->paramc[ATTR::AGI] * 4 + sd->paramc[ATTR::DEX])
+ * aspd_base_0[sd->weapontype2] / 1000)
+ )
+ * 140 / 200;
aspd_rate = sd->aspd_rate;
//攻撃速度増加
- if ((skill = pc_checkskill (sd, AC_VULTURE)) > 0)
- { // ワシã®ç›®
- sd->hit += skill;
- if (sd->status.weapon == 11)
- sd->attackrange += skill;
- }
-
if (sd->attackrange > 2)
- { // [fate] ranged weapon?
- sd->attackrange += MIN (skill_power (sd, AC_OWL) / 60, 3);
- sd->hit += skill_power (sd, AC_OWL) / 10; // 20 for 200
- }
-
- if ((skill = pc_checkskill (sd, BS_WEAPONRESEARCH)) > 0) // 武器研究ã®å‘½ä¸­çŽ‡å¢—加
- sd->hit += skill * 2;
- if (sd->status.option & 2 && (skill = pc_checkskill (sd, RG_TUNNELDRIVE)) > 0) // トンãƒãƒ«ãƒ‰ãƒ©ã‚¤ãƒ–
- sd->speed += (1.2 * DEFAULT_WALK_SPEED - skill * 9);
- if (pc_iscarton (sd) && (skill = pc_checkskill (sd, MC_PUSHCART)) > 0) // カートã«ã‚ˆã‚‹é€Ÿåº¦ä½Žä¸‹
- sd->speed += (10 - skill) * (DEFAULT_WALK_SPEED * 0.1);
- else if (pc_isriding (sd)) // ペコペコ乗りã«ã‚ˆã‚‹é€Ÿåº¦å¢—加
- sd->speed -= (0.25 * DEFAULT_WALK_SPEED);
- sd->max_weight += 1000;
- if (sd->sc_count)
{
- if (sd->sc_data[SC_WINDWALK].timer != -1) //ウィンドウォーク時ã¯Lv*2%減算
- sd->speed -=
- sd->speed * (sd->sc_data[SC_WINDWALK].val1 * 2) / 100;
- if (sd->sc_data[SC_CARTBOOST].timer != -1) // カートブースト
- sd->speed -= (DEFAULT_WALK_SPEED * 20) / 100;
- if (sd->sc_data[SC_BERSERK].timer != -1) //ãƒãƒ¼ã‚µãƒ¼ã‚¯ä¸­ã¯IAã¨åŒã˜ãらã„速ã„?
- sd->speed -= sd->speed * 25 / 100;
- if (sd->sc_data[SC_WEDDING].timer != -1) //çµå©šä¸­ã¯æ­©ãã®ãŒé…ã„
- sd->speed = 2 * DEFAULT_WALK_SPEED;
+ // [fate] ranged weapon?
+ sd->attackrange += min(skill_power(sd, SkillID::AC_OWL) / 60, 3);
+ sd->hit += skill_power(sd, SkillID::AC_OWL) / 10; // 20 for 200
}
- if ((skill = pc_checkskill (sd, CR_TRUST)) > 0)
- { // フェイス
- sd->status.max_hp += skill * 200;
- sd->subele[6] += skill * 5;
- }
- if ((skill = pc_checkskill (sd, BS_SKINTEMPER)) > 0)
- sd->subele[3] += skill * 4;
+ sd->max_weight += 1000;
bl = sd->status.base_level;
- sd->status.max_hp +=
- (3500 + bl * hp_coefficient2[s_class.job] +
- hp_sigma_val[s_class.job][(bl > 0) ? bl - 1 : 0]) / 100 * (100 +
- sd->paramc
- [2]) /
- 100 + (sd->parame[2] - sd->paramcard[2]);
- if (s_class.upper == 1) // [MouseJstr]
- sd->status.max_hp = sd->status.max_hp * 130 / 100;
+ sd->status.max_hp += (
+ 3500
+ + bl * hp_coefficient2_0
+ + hp_sigma_val_0[(bl > 0) ? bl - 1 : 0]
+ ) / 100 * (100 + sd->paramc[ATTR::VIT]) / 100
+ + (sd->parame[ATTR::VIT] - sd->paramcard[ATTR::VIT]);
if (sd->hprate != 100)
sd->status.max_hp = sd->status.max_hp * sd->hprate / 100;
- if (sd->sc_data && sd->sc_data[SC_BERSERK].timer != -1)
- { // ãƒãƒ¼ã‚µãƒ¼ã‚¯
- sd->status.max_hp = sd->status.max_hp * 3;
- sd->status.hp = sd->status.hp * 3;
- if (sd->status.max_hp > battle_config.max_hp) // removed negative max hp bug by Valaris
- sd->status.max_hp = battle_config.max_hp;
- if (sd->status.hp > battle_config.max_hp) // removed negative max hp bug by Valaris
- sd->status.hp = battle_config.max_hp;
- }
- if (s_class.job == 23 && sd->status.base_level >= 99)
- {
- sd->status.max_hp = sd->status.max_hp + 2000;
- }
-
if (sd->status.max_hp > battle_config.max_hp) // removed negative max hp bug by Valaris
sd->status.max_hp = battle_config.max_hp;
if (sd->status.max_hp <= 0)
sd->status.max_hp = 1; // end
// 最大SP計算
- sd->status.max_sp +=
- ((sp_coefficient[s_class.job] * bl) + 1000) / 100 * (100 +
- sd->paramc[3]) /
- 100 + (sd->parame[3] - sd->paramcard[3]);
- if (s_class.upper == 1) // [MouseJstr]
- sd->status.max_sp = sd->status.max_sp * 130 / 100;
+ sd->status.max_sp += ((sp_coefficient_0 * bl) + 1000)
+ / 100 * (100 + sd->paramc[ATTR::INT]) / 100
+ + (sd->parame[ATTR::INT] - sd->paramcard[ATTR::INT]);
if (sd->sprate != 100)
sd->status.max_sp = sd->status.max_sp * sd->sprate / 100;
- if ((skill = pc_checkskill (sd, HP_MEDITATIO)) > 0) // メディテイティオ
- sd->status.max_sp += sd->status.max_sp * skill / 100;
- if ((skill = pc_checkskill (sd, HW_SOULDRAIN)) > 0) // ソウルドレイン
- sd->status.max_sp += sd->status.max_sp * 2 * skill / 100;
-
if (sd->status.max_sp < 0 || sd->status.max_sp > battle_config.max_sp)
sd->status.max_sp = battle_config.max_sp;
//自然回復HP
- sd->nhealhp = 1 + (sd->paramc[2] / 5) + (sd->status.max_hp / 200);
- if ((skill = pc_checkskill (sd, SM_RECOVERY)) > 0)
- { // HP回復力å‘上
- sd->nshealhp = skill * 5 + (sd->status.max_hp * skill / 500);
- if (sd->nshealhp > 0x7fff)
- sd->nshealhp = 0x7fff;
- }
+ sd->nhealhp = 1 + (sd->paramc[ATTR::VIT] / 5) + (sd->status.max_hp / 200);
//自然回復SP
- sd->nhealsp = 1 + (sd->paramc[3] / 6) + (sd->status.max_sp / 100);
- if (sd->paramc[3] >= 120)
- sd->nhealsp += ((sd->paramc[3] - 120) >> 1) + 4;
- if ((skill = pc_checkskill (sd, MG_SRECOVERY)) > 0)
- { // SP回復力å‘上
- sd->nshealsp = skill * 3 + (sd->status.max_sp * skill / 500);
- if (sd->nshealsp > 0x7fff)
- sd->nshealsp = 0x7fff;
- }
+ sd->nhealsp = 1 + (sd->paramc[ATTR::INT] / 6) + (sd->status.max_sp / 100);
+ if (sd->paramc[ATTR::INT] >= 120)
+ sd->nhealsp += ((sd->paramc[ATTR::INT] - 120) >> 1) + 4;
- if ((skill = pc_checkskill (sd, MO_SPIRITSRECOVERY)) > 0)
- {
- sd->nsshealhp = skill * 4 + (sd->status.max_hp * skill / 500);
- sd->nsshealsp = skill * 2 + (sd->status.max_sp * skill / 500);
- if (sd->nsshealhp > 0x7fff)
- sd->nsshealhp = 0x7fff;
- if (sd->nsshealsp > 0x7fff)
- sd->nsshealsp = 0x7fff;
- }
if (sd->hprecov_rate != 100)
{
sd->nhealhp = sd->nhealhp * sd->hprecov_rate / 100;
@@ -2013,371 +1419,47 @@ int pc_calcstatus (struct map_session_data *sd, int first)
if (sd->nhealsp < 1)
sd->nhealsp = 1;
}
- if ((skill = pc_checkskill (sd, HP_MEDITATIO)) > 0)
- { // メディテイティオã¯SPRã§ã¯ãªã自然回復ã«ã‹ã‹ã‚‹
- sd->nhealsp += 3 * skill * (sd->status.max_sp) / 100;
- if (sd->nhealsp > 0x7fff)
- sd->nhealsp = 0x7fff;
- }
-
- // 種æ—è€æ€§ï¼ˆã“ã‚Œã§ã„ã„ã®ï¼Ÿ ディãƒã‚¤ãƒ³ãƒ—ロテクションã¨åŒã˜å‡¦ç†ãŒã„ã‚‹ã‹ã‚‚)
- if ((skill = pc_checkskill (sd, SA_DRAGONOLOGY)) > 0)
- { // ドラゴノロジー
- skill = skill * 4;
- sd->addrace[9] += skill;
- sd->addrace_[9] += skill;
- sd->subrace[9] += skill;
- sd->magic_addrace[9] += skill;
- sd->magic_subrace[9] -= skill;
- }
-
- //Flee上昇
- if ((skill = pc_checkskill (sd, TF_MISS)) > 0)
- { // 回é¿çŽ‡å¢—加
- if (sd->status.pc_class == 6 || sd->status.pc_class == 4007
- || sd->status.pc_class == 23)
- {
- sd->flee += skill * 3;
- }
- if (sd->status.pc_class == 12 || sd->status.pc_class == 17
- || sd->status.pc_class == 4013 || sd->status.pc_class == 4018)
- sd->flee += skill * 4;
- if (sd->status.pc_class == 12 || sd->status.pc_class == 4013)
- sd->speed -= sd->speed * (skill * .5) / 100;
- }
- if ((skill = pc_checkskill (sd, MO_DODGE)) > 0) // 見切り
- sd->flee += (skill * 3) >> 1;
// スキルやステータス異常ã«ã‚ˆã‚‹æ®‹ã‚Šã®ãƒ‘ラメータ補正
if (sd->sc_count)
{
// ATK/DEF変化形
- if (sd->sc_data[SC_ANGELUS].timer != -1) // エンジェラス
- sd->def2 =
- sd->def2 * (110 + 5 * sd->sc_data[SC_ANGELUS].val1) / 100;
- if (sd->sc_data[SC_IMPOSITIO].timer != -1)
- { // インãƒã‚·ãƒ†ã‚£ã‚ªãƒžãƒŒã‚¹
- sd->watk += sd->sc_data[SC_IMPOSITIO].val1 * 5;
- index = sd->equip_index[8];
- if (index >= 0 && sd->inventory_data[index]
- && sd->inventory_data[index]->type == 4)
- sd->watk_ += sd->sc_data[SC_IMPOSITIO].val1 * 5;
- }
- if (sd->sc_data[SC_PROVOKE].timer != -1)
- { // プロボック
- sd->def2 =
- sd->def2 * (100 - 6 * sd->sc_data[SC_PROVOKE].val1) / 100;
- sd->base_atk =
- sd->base_atk * (100 + 2 * sd->sc_data[SC_PROVOKE].val1) / 100;
- sd->watk =
- sd->watk * (100 + 2 * sd->sc_data[SC_PROVOKE].val1) / 100;
- index = sd->equip_index[8];
- if (index >= 0 && sd->inventory_data[index]
- && sd->inventory_data[index]->type == 4)
- sd->watk_ =
- sd->watk_ * (100 +
- 2 * sd->sc_data[SC_PROVOKE].val1) / 100;
- }
- if (sd->sc_data[SC_ENDURE].timer != -1)
- sd->mdef2 += sd->sc_data[SC_ENDURE].val1;
- if (sd->sc_data[SC_MINDBREAKER].timer != -1)
- { // プロボック
- sd->mdef2 =
- sd->mdef2 * (100 -
- 6 * sd->sc_data[SC_MINDBREAKER].val1) / 100;
- sd->matk1 =
- sd->matk1 * (100 +
- 2 * sd->sc_data[SC_MINDBREAKER].val1) / 100;
- sd->matk2 =
- sd->matk2 * (100 +
- 2 * sd->sc_data[SC_MINDBREAKER].val1) / 100;
- }
- if (sd->sc_data[SC_POISON].timer != -1) // 毒状態
+ if (sd->sc_data[StatusChange::SC_POISON].timer) // 毒状態
sd->def2 = sd->def2 * 75 / 100;
- if (sd->sc_data[SC_DRUMBATTLE].timer != -1)
- { // 戦太鼓ã®éŸ¿ã
- sd->watk += sd->sc_data[SC_DRUMBATTLE].val2;
- sd->def += sd->sc_data[SC_DRUMBATTLE].val3;
- index = sd->equip_index[8];
- if (index >= 0 && sd->inventory_data[index]
- && sd->inventory_data[index]->type == 4)
- sd->watk_ += sd->sc_data[SC_DRUMBATTLE].val2;
- }
- if (sd->sc_data[SC_NIBELUNGEN].timer != -1)
- { // ニーベルングã®æŒ‡è¼ª
- index = sd->equip_index[9];
- if (index >= 0 && sd->inventory_data[index]
- && sd->inventory_data[index]->wlv == 3)
- sd->watk += sd->sc_data[SC_NIBELUNGEN].val3;
- index = sd->equip_index[8];
- if (index >= 0 && sd->inventory_data[index]
- && sd->inventory_data[index]->wlv == 3)
- sd->watk_ += sd->sc_data[SC_NIBELUNGEN].val3;
- if (index >= 0 && sd->inventory_data[index]
- && sd->inventory_data[index]->wlv == 4)
- sd->watk += sd->sc_data[SC_NIBELUNGEN].val2;
- index = sd->equip_index[8];
- if (index >= 0 && sd->inventory_data[index]
- && sd->inventory_data[index]->wlv == 4)
- sd->watk_ += sd->sc_data[SC_NIBELUNGEN].val2;
- }
-
- if (sd->sc_data[SC_VOLCANO].timer != -1 && sd->def_ele == 3)
- { // ボルケーノ
- sd->watk += sd->sc_data[SC_VIOLENTGALE].val3;
- }
-
- if (sd->sc_data[SC_SIGNUMCRUCIS].timer != -1)
- sd->def =
- sd->def * (100 - sd->sc_data[SC_SIGNUMCRUCIS].val2) / 100;
- if (sd->sc_data[SC_ETERNALCHAOS].timer != -1) // エターナルカオス
- sd->def = 0;
-
- if (sd->sc_data[SC_CONCENTRATION].timer != -1)
- { //コンセントレーション
- sd->watk =
- sd->watk * (100 +
- 5 * sd->sc_data[SC_CONCENTRATION].val1) / 100;
- index = sd->equip_index[8];
- if (index >= 0 && sd->inventory_data[index]
- && sd->inventory_data[index]->type == 4)
- sd->watk_ =
- sd->watk * (100 +
- 5 * sd->sc_data[SC_CONCENTRATION].val1) / 100;
- sd->def =
- sd->def * (100 -
- 5 * sd->sc_data[SC_CONCENTRATION].val1) / 100;
- }
- if (sd->sc_data[SC_MAGICPOWER].timer != -1)
- { //魔法力増幅
- sd->matk1 =
- sd->matk1 * (100 + 2 * sd->sc_data[SC_MAGICPOWER].val1) / 100;
- sd->matk2 =
- sd->matk2 * (100 + 2 * sd->sc_data[SC_MAGICPOWER].val1) / 100;
- }
- if (sd->sc_data[SC_ATKPOT].timer != -1)
- sd->watk += sd->sc_data[SC_ATKPOT].val1;
- if (sd->sc_data[SC_MATKPOT].timer != -1)
+ if (sd->sc_data[StatusChange::SC_ATKPOT].timer)
+ sd->watk += sd->sc_data[StatusChange::SC_ATKPOT].val1;
+ if (sd->sc_data[StatusChange::SC_MATKPOT].timer)
{
- sd->matk1 += sd->sc_data[SC_MATKPOT].val1;
- sd->matk2 += sd->sc_data[SC_MATKPOT].val1;
+ sd->matk1 += sd->sc_data[StatusChange::SC_MATKPOT].val1;
+ sd->matk2 += sd->sc_data[StatusChange::SC_MATKPOT].val1;
}
- // ASPD/移動速度変化系
- if (sd->sc_data[SC_TWOHANDQUICKEN].timer != -1 && sd->sc_data[SC_QUAGMIRE].timer == -1 && sd->sc_data[SC_DONTFORGETME].timer == -1) // 2HQ
- aspd_rate -= 30;
- if (sd->sc_data[SC_ADRENALINE].timer != -1
- && sd->sc_data[SC_TWOHANDQUICKEN].timer == -1
- && sd->sc_data[SC_QUAGMIRE].timer == -1
- && sd->sc_data[SC_DONTFORGETME].timer == -1)
- { // アドレナリンラッシュ
- if (sd->sc_data[SC_ADRENALINE].val2
- || !battle_config.party_skill_penaly)
- aspd_rate -= 30;
- else
- aspd_rate -= 25;
- }
- if (sd->sc_data[SC_SPEARSQUICKEN].timer != -1 && sd->sc_data[SC_ADRENALINE].timer == -1 && sd->sc_data[SC_TWOHANDQUICKEN].timer == -1 && sd->sc_data[SC_QUAGMIRE].timer == -1 && sd->sc_data[SC_DONTFORGETME].timer == -1) // スピアクィッケン
- aspd_rate -= sd->sc_data[SC_SPEARSQUICKEN].val2;
- if (sd->sc_data[SC_ASSNCROS].timer != -1 && // 夕陽ã®ã‚¢ã‚µã‚·ãƒ³ã‚¯ãƒ­ã‚¹
- sd->sc_data[SC_TWOHANDQUICKEN].timer == -1
- && sd->sc_data[SC_ADRENALINE].timer == -1
- && sd->sc_data[SC_SPEARSQUICKEN].timer == -1
- && sd->sc_data[SC_DONTFORGETME].timer == -1)
- aspd_rate -=
- 5 + sd->sc_data[SC_ASSNCROS].val1 +
- sd->sc_data[SC_ASSNCROS].val2 + sd->sc_data[SC_ASSNCROS].val3;
- if (sd->sc_data[SC_DONTFORGETME].timer != -1)
- { // ç§ã‚’忘れãªã„ã§
- aspd_rate +=
- sd->sc_data[SC_DONTFORGETME].val1 * 3 +
- sd->sc_data[SC_DONTFORGETME].val2 +
- (sd->sc_data[SC_DONTFORGETME].val3 >> 16);
- sd->speed =
- sd->speed * (100 + sd->sc_data[SC_DONTFORGETME].val1 * 2 +
- sd->sc_data[SC_DONTFORGETME].val2 +
- (sd->sc_data[SC_DONTFORGETME].val3 & 0xffff)) /
- 100;
- }
- if (sd->sc_data[i = SC_SPEEDPOTION2].timer != -1 || sd->sc_data[i = SC_SPEEDPOTION1].timer != -1 || sd->sc_data[i = SC_SPEEDPOTION0].timer != -1) // 増 速ãƒãƒ¼ã‚·ãƒ§ãƒ³
- aspd_rate -= sd->sc_data[i].val1;
+ if (sd->sc_data[StatusChange::SC_SPEEDPOTION0].timer)
+ aspd_rate -= sd->sc_data[StatusChange::SC_SPEEDPOTION0].val1;
- if (sd->sc_data[SC_HASTE].timer != -1)
- aspd_rate -= sd->sc_data[SC_HASTE].val1;
+ if (sd->sc_data[StatusChange::SC_HASTE].timer)
+ aspd_rate -= sd->sc_data[StatusChange::SC_HASTE].val1;
/* Slow down if protected */
- if (sd->sc_data[SC_PHYS_SHIELD].timer != -1)
- aspd_rate += sd->sc_data[SC_PHYS_SHIELD].val1;
-
- // HIT/FLEE変化系
- if (sd->sc_data[SC_WHISTLE].timer != -1)
- { // å£ç¬›
- sd->flee += sd->flee * (sd->sc_data[SC_WHISTLE].val1
- + sd->sc_data[SC_WHISTLE].val2 +
- (sd->sc_data[SC_WHISTLE].val3 >> 16)) /
- 100;
- sd->flee2 +=
- (sd->sc_data[SC_WHISTLE].val1 + sd->sc_data[SC_WHISTLE].val2 +
- (sd->sc_data[SC_WHISTLE].val3 & 0xffff)) * 10;
- }
- if (sd->sc_data[SC_HUMMING].timer != -1) // ãƒãƒŸãƒ³ã‚°
- sd->hit +=
- (sd->sc_data[SC_HUMMING].val1 * 2 +
- sd->sc_data[SC_HUMMING].val2 +
- sd->sc_data[SC_HUMMING].val3) * sd->hit / 100;
- if (sd->sc_data[SC_VIOLENTGALE].timer != -1 && sd->def_ele == 4)
- { // ãƒã‚¤ã‚ªãƒ¬ãƒ³ãƒˆã‚²ã‚¤ãƒ«
- sd->flee += sd->flee * sd->sc_data[SC_VIOLENTGALE].val3 / 100;
- }
- if (sd->sc_data[SC_BLIND].timer != -1)
- { // æš—é»’
- sd->hit -= sd->hit * 25 / 100;
- sd->flee -= sd->flee * 25 / 100;
- }
- if (sd->sc_data[SC_WINDWALK].timer != -1) // ウィンドウォーク
- sd->flee += sd->flee * (sd->sc_data[SC_WINDWALK].val2) / 100;
- if (sd->sc_data[SC_SPIDERWEB].timer != -1) //スパイダーウェブ
- sd->flee -= sd->flee * 50 / 100;
- if (sd->sc_data[SC_TRUESIGHT].timer != -1) //トゥルーサイト
- sd->hit += 3 * (sd->sc_data[SC_TRUESIGHT].val1);
- if (sd->sc_data[SC_CONCENTRATION].timer != -1) //コンセントレーション
- sd->hit += (10 * (sd->sc_data[SC_CONCENTRATION].val1));
-
- // è€æ€§
- if (sd->sc_data[SC_SIEGFRIED].timer != -1)
- { // ä¸æ­»èº«ã®ã‚¸ãƒ¼ã‚¯ãƒ•ãƒªãƒ¼ãƒ‰
- sd->subele[1] += sd->sc_data[SC_SIEGFRIED].val2; // æ°´
- sd->subele[2] += sd->sc_data[SC_SIEGFRIED].val2; // æ°´
- sd->subele[3] += sd->sc_data[SC_SIEGFRIED].val2; // æ°´
- sd->subele[4] += sd->sc_data[SC_SIEGFRIED].val2; // æ°´
- sd->subele[5] += sd->sc_data[SC_SIEGFRIED].val2; // æ°´
- sd->subele[6] += sd->sc_data[SC_SIEGFRIED].val2; // æ°´
- sd->subele[7] += sd->sc_data[SC_SIEGFRIED].val2; // æ°´
- sd->subele[8] += sd->sc_data[SC_SIEGFRIED].val2; // æ°´
- sd->subele[9] += sd->sc_data[SC_SIEGFRIED].val2; // æ°´
- }
- if (sd->sc_data[SC_PROVIDENCE].timer != -1)
- { // プロヴィデンス
- sd->subele[6] += sd->sc_data[SC_PROVIDENCE].val2; // 対 è–属性
- sd->subrace[6] += sd->sc_data[SC_PROVIDENCE].val2; // 対 悪魔
- }
-
- // ãã®ä»–
- if (sd->sc_data[SC_APPLEIDUN].timer != -1)
- { // イドゥンã®æž—檎
- sd->status.max_hp +=
- ((5 + sd->sc_data[SC_APPLEIDUN].val1 * 2 +
- ((sd->sc_data[SC_APPLEIDUN].val2 + 1) >> 1) +
- sd->sc_data[SC_APPLEIDUN].val3 / 10) * sd->status.max_hp) /
- 100;
- if (sd->status.max_hp < 0
- || sd->status.max_hp > battle_config.max_hp)
- sd->status.max_hp = battle_config.max_hp;
- }
- if (sd->sc_data[SC_DELUGE].timer != -1 && sd->def_ele == 1)
- { // デリュージ
- sd->status.max_hp +=
- sd->status.max_hp * sd->sc_data[SC_DELUGE].val3 / 100;
- if (sd->status.max_hp < 0
- || sd->status.max_hp > battle_config.max_hp)
- sd->status.max_hp = battle_config.max_hp;
- }
- if (sd->sc_data[SC_SERVICE4U].timer != -1)
- { // サービスフォーユー
- sd->status.max_sp +=
- sd->status.max_sp * (10 + sd->sc_data[SC_SERVICE4U].val1 +
- sd->sc_data[SC_SERVICE4U].val2 +
- sd->sc_data[SC_SERVICE4U].val3) / 100;
- if (sd->status.max_sp < 0
- || sd->status.max_sp > battle_config.max_sp)
- sd->status.max_sp = battle_config.max_sp;
- sd->dsprate -=
- (10 + sd->sc_data[SC_SERVICE4U].val1 * 3 +
- sd->sc_data[SC_SERVICE4U].val2 +
- sd->sc_data[SC_SERVICE4U].val3);
- if (sd->dsprate < 0)
- sd->dsprate = 0;
- }
-
- if (sd->sc_data[SC_FORTUNE].timer != -1) // 幸é‹ã®ã‚­ã‚¹
- sd->critical +=
- (10 + sd->sc_data[SC_FORTUNE].val1 +
- sd->sc_data[SC_FORTUNE].val2 +
- sd->sc_data[SC_FORTUNE].val3) * 10;
-
- if (sd->sc_data[SC_EXPLOSIONSPIRITS].timer != -1)
- { // 爆裂波動
- if (s_class.job == 23)
- sd->critical += sd->sc_data[SC_EXPLOSIONSPIRITS].val1 * 100;
- else
- sd->critical += sd->sc_data[SC_EXPLOSIONSPIRITS].val2;
- }
-
- if (sd->sc_data[SC_STEELBODY].timer != -1)
- { // 金剛
- sd->def = 90;
- sd->mdef = 90;
- aspd_rate += 25;
- sd->speed = (sd->speed * 125) / 100;
- }
- if (sd->sc_data[SC_DEFENDER].timer != -1)
- {
- sd->aspd += (550 - sd->sc_data[SC_DEFENDER].val1 * 50);
- sd->speed =
- (sd->speed * (155 - sd->sc_data[SC_DEFENDER].val1 * 5)) / 100;
- }
- if (sd->sc_data[SC_ENCPOISON].timer != -1)
- sd->addeff[4] += sd->sc_data[SC_ENCPOISON].val2;
-
- if (sd->sc_data[SC_DANCING].timer != -1)
- { // æ¼”å¥/ダンス使用中
- sd->speed *= 4;
- sd->nhealsp = 0;
- sd->nshealsp = 0;
- sd->nsshealsp = 0;
- }
- if (sd->sc_data[SC_CURSE].timer != -1)
- sd->speed += 450;
-
- if (sd->sc_data[SC_TRUESIGHT].timer != -1) //トゥルーサイト
- sd->critical +=
- sd->critical * (sd->sc_data[SC_TRUESIGHT].val1) / 100;
-
-/* if(sd->sc_data[SC_VOLCANO].timer!=-1) // エンãƒãƒ£ãƒ³ãƒˆãƒã‚¤ã‚ºãƒ³(属性ã¯battle.cã§)
- sd->addeff[2]+=sd->sc_data[SC_VOLCANO].val2;//% of granting
- if(sd->sc_data[SC_DELUGE].timer!=-1) // エンãƒãƒ£ãƒ³ãƒˆãƒã‚¤ã‚ºãƒ³(属性ã¯battle.cã§)
- sd->addeff[0]+=sd->sc_data[SC_DELUGE].val2;//% of granting
- */
+ if (sd->sc_data[StatusChange::SC_PHYS_SHIELD].timer)
+ aspd_rate += sd->sc_data[StatusChange::SC_PHYS_SHIELD].val1;
}
if (sd->speed_rate != 100)
sd->speed = sd->speed * sd->speed_rate / 100;
- if (sd->speed < 1)
- sd->speed = 1;
+ sd->speed = std::max(sd->speed, std::chrono::milliseconds(1));
if (aspd_rate != 100)
sd->aspd = sd->aspd * aspd_rate / 100;
- if (pc_isriding (sd)) // 騎兵修練
- sd->aspd =
- sd->aspd * (100 +
- 10 * (5 -
- pc_checkskill (sd, KN_CAVALIERMASTERY))) / 100;
if (sd->attack_spell_override)
sd->aspd = sd->attack_spell_delay;
- if (sd->aspd < battle_config.max_aspd)
- sd->aspd = battle_config.max_aspd;
+ sd->aspd = std::max(sd->aspd, static_cast<interval_t>(battle_config.max_aspd));
sd->amotion = sd->aspd;
- sd->dmotion = 800 - sd->paramc[1] * 4;
- if (sd->dmotion < 400)
- sd->dmotion = 400;
- if (sd->skilltimer != -1 && (skill = pc_checkskill (sd, SA_FREECAST)) > 0)
- {
- sd->prev_speed = sd->speed;
- sd->speed = sd->speed * (175 - skill * 5) / 100;
- }
+ sd->dmotion = std::chrono::milliseconds(800 - sd->paramc[ATTR::AGI] * 4);
+ sd->dmotion = std::max(sd->dmotion, std::chrono::milliseconds(400));
if (sd->status.hp > sd->status.max_hp)
sd->status.hp = sd->status.max_hp;
@@ -2388,86 +1470,69 @@ int pc_calcstatus (struct map_session_data *sd, int first)
return 0;
if (first & 3)
{
- clif_updatestatus (sd, SP_SPEED);
- clif_updatestatus (sd, SP_MAXHP);
- clif_updatestatus (sd, SP_MAXSP);
+ clif_updatestatus(sd, SP::SPEED);
+ clif_updatestatus(sd, SP::MAXHP);
+ clif_updatestatus(sd, SP::MAXSP);
if (first & 1)
{
- clif_updatestatus (sd, SP_HP);
- clif_updatestatus (sd, SP_SP);
+ clif_updatestatus(sd, SP::HP);
+ clif_updatestatus(sd, SP::SP);
}
return 0;
}
- if (b_class != sd->view_class)
- {
- clif_changelook (&sd->bl, LOOK_BASE, sd->view_class);
- clif_changelook (&sd->bl, LOOK_WEAPON, 0);
- }
-
- if (memcmp (b_skill, sd->status.skill, sizeof (sd->status.skill))
+ if (memcmp(&b_skill, &sd->status.skill, sizeof(sd->status.skill))
|| b_attackrange != sd->attackrange)
- clif_skillinfoblock (sd); // スキルé€ä¿¡
+ clif_skillinfoblock(sd); // スキルé€ä¿¡
if (b_speed != sd->speed)
- clif_updatestatus (sd, SP_SPEED);
+ clif_updatestatus(sd, SP::SPEED);
if (b_weight != sd->weight)
- clif_updatestatus (sd, SP_WEIGHT);
+ clif_updatestatus(sd, SP::WEIGHT);
if (b_max_weight != sd->max_weight)
{
- clif_updatestatus (sd, SP_MAXWEIGHT);
- pc_checkweighticon (sd);
+ clif_updatestatus(sd, SP::MAXWEIGHT);
+ pc_checkweighticon(sd);
}
- for (i = 0; i < 6; i++)
+ for (ATTR i : ATTRs)
if (b_paramb[i] + b_parame[i] != sd->paramb[i] + sd->parame[i])
- clif_updatestatus (sd, SP_STR + i);
+ clif_updatestatus(sd, attr_to_sp(i));
if (b_hit != sd->hit)
- clif_updatestatus (sd, SP_HIT);
+ clif_updatestatus(sd, SP::HIT);
if (b_flee != sd->flee)
- clif_updatestatus (sd, SP_FLEE1);
+ clif_updatestatus(sd, SP::FLEE1);
if (b_aspd != sd->aspd)
- clif_updatestatus (sd, SP_ASPD);
+ clif_updatestatus(sd, SP::ASPD);
if (b_watk != sd->watk || b_base_atk != sd->base_atk)
- clif_updatestatus (sd, SP_ATK1);
+ clif_updatestatus(sd, SP::ATK1);
if (b_def != sd->def)
- clif_updatestatus (sd, SP_DEF1);
+ clif_updatestatus(sd, SP::DEF1);
if (b_watk2 != sd->watk2)
- clif_updatestatus (sd, SP_ATK2);
+ clif_updatestatus(sd, SP::ATK2);
if (b_def2 != sd->def2)
- clif_updatestatus (sd, SP_DEF2);
+ clif_updatestatus(sd, SP::DEF2);
if (b_flee2 != sd->flee2)
- clif_updatestatus (sd, SP_FLEE2);
+ clif_updatestatus(sd, SP::FLEE2);
if (b_critical != sd->critical)
- clif_updatestatus (sd, SP_CRITICAL);
+ clif_updatestatus(sd, SP::CRITICAL);
if (b_matk1 != sd->matk1)
- clif_updatestatus (sd, SP_MATK1);
+ clif_updatestatus(sd, SP::MATK1);
if (b_matk2 != sd->matk2)
- clif_updatestatus (sd, SP_MATK2);
+ clif_updatestatus(sd, SP::MATK2);
if (b_mdef != sd->mdef)
- clif_updatestatus (sd, SP_MDEF1);
+ clif_updatestatus(sd, SP::MDEF1);
if (b_mdef2 != sd->mdef2)
- clif_updatestatus (sd, SP_MDEF2);
+ clif_updatestatus(sd, SP::MDEF2);
if (b_attackrange != sd->attackrange)
- clif_updatestatus (sd, SP_ATTACKRANGE);
+ clif_updatestatus(sd, SP::ATTACKRANGE);
if (b_max_hp != sd->status.max_hp)
- clif_updatestatus (sd, SP_MAXHP);
+ clif_updatestatus(sd, SP::MAXHP);
if (b_max_sp != sd->status.max_sp)
- clif_updatestatus (sd, SP_MAXSP);
+ clif_updatestatus(sd, SP::MAXSP);
if (b_hp != sd->status.hp)
- clif_updatestatus (sd, SP_HP);
+ clif_updatestatus(sd, SP::HP);
if (b_sp != sd->status.sp)
- clif_updatestatus (sd, SP_SP);
-
-/* if(before.cart_num != before.cart_num || before.cart_max_num != before.cart_max_num ||
- before.cart_weight != before.cart_weight || before.cart_max_weight != before.cart_max_weight )
- clif_updatestatus(sd,SP_CARTINFO);*/
-
- if (sd->status.hp < sd->status.max_hp >> 2
- && pc_checkskill (sd, SM_AUTOBERSERK) > 0
- && (sd->sc_data[SC_PROVOKE].timer == -1
- || sd->sc_data[SC_PROVOKE].val2 == 0) && !pc_isdead (sd))
- // オートãƒãƒ¼ã‚µãƒ¼ã‚¯ç™ºå‹•
- skill_status_change_start (&sd->bl, SC_PROVOKE, 10, 1, 0, 0, 0, 0);
+ clif_updatestatus(sd, SP::SP);
return 0;
}
@@ -2476,121 +1541,118 @@ int pc_calcstatus (struct map_session_data *sd, int first)
* 装 å‚™å“ã«ã‚ˆã‚‹èƒ½åŠ›ç­‰ã®ãƒœãƒ¼ãƒŠã‚¹è¨­å®š
*------------------------------------------
*/
-int pc_bonus (struct map_session_data *sd, int type, int val)
+int pc_bonus(struct map_session_data *sd, SP type, int val)
{
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
switch (type)
{
- case SP_STR:
- case SP_AGI:
- case SP_VIT:
- case SP_INT:
- case SP_DEX:
- case SP_LUK:
+ case SP::STR:
+ case SP::AGI:
+ case SP::VIT:
+ case SP::INT:
+ case SP::DEX:
+ case SP::LUK:
if (sd->state.lr_flag != 2)
- sd->parame[type - SP_STR] += val;
+ sd->parame[sp_to_attr(type)] += val;
break;
- case SP_ATK1:
+#if 0
+ case SP::ATK1:
if (!sd->state.lr_flag)
sd->watk += val;
else if (sd->state.lr_flag == 1)
sd->watk_ += val;
break;
- case SP_ATK2:
+#endif
+#if 0
+ case SP::ATK2:
if (!sd->state.lr_flag)
sd->watk2 += val;
else if (sd->state.lr_flag == 1)
sd->watk_2 += val;
break;
- case SP_BASE_ATK:
+#endif
+#if 0
+ case SP::BASE_ATK:
if (sd->state.lr_flag != 2)
sd->base_atk += val;
break;
- case SP_MATK1:
+#endif
+#if 0
+ case SP::MATK1:
if (sd->state.lr_flag != 2)
sd->matk1 += val;
break;
- case SP_MATK2:
- if (sd->state.lr_flag != 2)
- sd->matk2 += val;
- break;
- case SP_MATK:
+#endif
+#if 0
+ case SP::MATK2:
if (sd->state.lr_flag != 2)
- {
- sd->matk1 += val;
sd->matk2 += val;
- }
break;
- case SP_DEF1:
+#endif
+#if 0
+ case SP::DEF1:
if (sd->state.lr_flag != 2)
sd->def += val;
break;
- case SP_MDEF1:
+#endif
+ case SP::MDEF1:
if (sd->state.lr_flag != 2)
sd->mdef += val;
break;
- case SP_MDEF2:
+#if 0
+ case SP::MDEF2:
if (sd->state.lr_flag != 2)
sd->mdef += val;
break;
- case SP_HIT:
+#endif
+ case SP::HIT:
if (sd->state.lr_flag != 2)
sd->hit += val;
else
sd->arrow_hit += val;
break;
- case SP_FLEE1:
+ case SP::FLEE1:
if (sd->state.lr_flag != 2)
sd->flee += val;
break;
- case SP_FLEE2:
+#if 0
+ case SP::FLEE2:
if (sd->state.lr_flag != 2)
sd->flee2 += val * 10;
break;
- case SP_CRITICAL:
+#endif
+ case SP::CRITICAL:
if (sd->state.lr_flag != 2)
sd->critical += val * 10;
else
sd->arrow_cri += val * 10;
break;
- case SP_ATKELE:
- if (!sd->state.lr_flag)
- sd->atk_ele = val;
- else if (sd->state.lr_flag == 1)
- sd->atk_ele_ = val;
- else if (sd->state.lr_flag == 2)
- sd->arrow_ele = val;
- break;
- case SP_DEFELE:
- if (sd->state.lr_flag != 2)
- sd->def_ele = val;
- break;
- case SP_MAXHP:
+ case SP::MAXHP:
if (sd->state.lr_flag != 2)
sd->status.max_hp += val;
break;
- case SP_MAXSP:
+ case SP::MAXSP:
if (sd->state.lr_flag != 2)
sd->status.max_sp += val;
break;
- case SP_CASTRATE:
- if (sd->state.lr_flag != 2)
- sd->castrate += val;
- break;
- case SP_MAXHPRATE:
+ case SP::MAXHPRATE:
if (sd->state.lr_flag != 2)
sd->hprate += val;
break;
- case SP_MAXSPRATE:
+#if 0
+ case SP::MAXSPRATE:
if (sd->state.lr_flag != 2)
sd->sprate += val;
break;
- case SP_SPRATE:
+#endif
+#if 0
+ case SP::SPRATE:
if (sd->state.lr_flag != 2)
sd->dsprate += val;
break;
- case SP_ATTACKRANGE:
+#endif
+ case SP::ATTACKRANGE:
if (!sd->state.lr_flag)
sd->attackrange += val;
else if (sd->state.lr_flag == 1)
@@ -2598,281 +1660,143 @@ int pc_bonus (struct map_session_data *sd, int type, int val)
else if (sd->state.lr_flag == 2)
sd->arrow_range += val;
break;
- case SP_ADD_SPEED:
+#if 0
+ case SP::ADD_SPEED:
if (sd->state.lr_flag != 2)
sd->speed -= val;
break;
- case SP_SPEED_RATE:
+#endif
+#if 0
+ case SP::SPEED_RATE:
if (sd->state.lr_flag != 2)
{
if (sd->speed_rate > 100 - val)
sd->speed_rate = 100 - val;
}
break;
- case SP_SPEED_ADDRATE:
+#endif
+ case SP::SPEED_ADDRATE:
if (sd->state.lr_flag != 2)
sd->speed_add_rate = sd->speed_add_rate * (100 - val) / 100;
break;
- case SP_ASPD:
+#if 0
+ case SP::ASPD:
if (sd->state.lr_flag != 2)
sd->aspd -= val * 10;
break;
- case SP_ASPD_RATE:
+#endif
+ case SP::ASPD_RATE:
if (sd->state.lr_flag != 2)
{
if (sd->aspd_rate > 100 - val)
sd->aspd_rate = 100 - val;
}
break;
- case SP_ASPD_ADDRATE:
+#if 0
+ case SP::ASPD_ADDRATE:
if (sd->state.lr_flag != 2)
sd->aspd_add_rate = sd->aspd_add_rate * (100 - val) / 100;
break;
- case SP_HP_RECOV_RATE:
+#endif
+ case SP::HP_RECOV_RATE:
if (sd->state.lr_flag != 2)
sd->hprecov_rate += val;
break;
- case SP_SP_RECOV_RATE:
+#if 0
+ case SP::SP_RECOV_RATE:
if (sd->state.lr_flag != 2)
sd->sprecov_rate += val;
break;
- case SP_CRITICAL_DEF:
+#endif
+ case SP::CRITICAL_DEF:
if (sd->state.lr_flag != 2)
sd->critical_def += val;
break;
- case SP_NEAR_ATK_DEF:
- if (sd->state.lr_flag != 2)
- sd->near_attack_def_rate += val;
- break;
- case SP_LONG_ATK_DEF:
- if (sd->state.lr_flag != 2)
- sd->long_attack_def_rate += val;
- break;
- case SP_DOUBLE_RATE:
+#if 0
+ case SP::DOUBLE_RATE:
if (sd->state.lr_flag == 0 && sd->double_rate < val)
sd->double_rate = val;
break;
- case SP_DOUBLE_ADD_RATE:
+#endif
+ case SP::DOUBLE_ADD_RATE:
if (sd->state.lr_flag == 0)
sd->double_add_rate += val;
break;
- case SP_MATK_RATE:
+#if 0
+ case SP::MATK_RATE:
if (sd->state.lr_flag != 2)
sd->matk_rate += val;
break;
- case SP_IGNORE_DEF_ELE:
- if (!sd->state.lr_flag)
- sd->ignore_def_ele |= 1 << val;
- else if (sd->state.lr_flag == 1)
- sd->ignore_def_ele_ |= 1 << val;
- break;
- case SP_IGNORE_DEF_RACE:
- if (!sd->state.lr_flag)
- sd->ignore_def_race |= 1 << val;
- else if (sd->state.lr_flag == 1)
- sd->ignore_def_race_ |= 1 << val;
- break;
- case SP_ATK_RATE:
+#endif
+#if 0
+ case SP::ATK_RATE:
if (sd->state.lr_flag != 2)
sd->atk_rate += val;
break;
- case SP_MAGIC_ATK_DEF:
- if (sd->state.lr_flag != 2)
- sd->magic_def_rate += val;
- break;
- case SP_MISC_ATK_DEF:
- if (sd->state.lr_flag != 2)
- sd->misc_def_rate += val;
- break;
- case SP_IGNORE_MDEF_ELE:
- if (sd->state.lr_flag != 2)
- sd->ignore_mdef_ele |= 1 << val;
- break;
- case SP_IGNORE_MDEF_RACE:
- if (sd->state.lr_flag != 2)
- sd->ignore_mdef_race |= 1 << val;
- break;
- case SP_PERFECT_HIT_RATE:
+#endif
+#if 0
+ case SP::PERFECT_HIT_RATE:
if (sd->state.lr_flag != 2 && sd->perfect_hit < val)
sd->perfect_hit = val;
break;
- case SP_PERFECT_HIT_ADD_RATE:
+#endif
+#if 0
+ case SP::PERFECT_HIT_ADD_RATE:
if (sd->state.lr_flag != 2)
sd->perfect_hit_add += val;
break;
- case SP_CRITICAL_RATE:
+#endif
+#if 0
+ case SP::CRITICAL_RATE:
if (sd->state.lr_flag != 2)
sd->critical_rate += val;
break;
- case SP_GET_ZENY_NUM:
- if (sd->state.lr_flag != 2 && sd->get_zeny_num < val)
- sd->get_zeny_num = val;
- break;
- case SP_ADD_GET_ZENY_NUM:
- if (sd->state.lr_flag != 2)
- sd->get_zeny_add_num += val;
- break;
- case SP_DEF_RATIO_ATK_ELE:
- if (!sd->state.lr_flag)
- sd->def_ratio_atk_ele |= 1 << val;
- else if (sd->state.lr_flag == 1)
- sd->def_ratio_atk_ele_ |= 1 << val;
- break;
- case SP_DEF_RATIO_ATK_RACE:
- if (!sd->state.lr_flag)
- sd->def_ratio_atk_race |= 1 << val;
- else if (sd->state.lr_flag == 1)
- sd->def_ratio_atk_race_ |= 1 << val;
- break;
- case SP_HIT_RATE:
+#endif
+#if 0
+ case SP::HIT_RATE:
if (sd->state.lr_flag != 2)
sd->hit_rate += val;
break;
- case SP_FLEE_RATE:
+#endif
+#if 0
+ case SP::FLEE_RATE:
if (sd->state.lr_flag != 2)
sd->flee_rate += val;
break;
- case SP_FLEE2_RATE:
+#endif
+#if 0
+ case SP::FLEE2_RATE:
if (sd->state.lr_flag != 2)
sd->flee2_rate += val;
break;
- case SP_DEF_RATE:
+#endif
+ case SP::DEF_RATE:
if (sd->state.lr_flag != 2)
sd->def_rate += val;
break;
- case SP_DEF2_RATE:
+ case SP::DEF2_RATE:
if (sd->state.lr_flag != 2)
sd->def2_rate += val;
break;
- case SP_MDEF_RATE:
+#if 0
+ case SP::MDEF_RATE:
if (sd->state.lr_flag != 2)
sd->mdef_rate += val;
break;
- case SP_MDEF2_RATE:
+#endif
+#if 0
+ case SP::MDEF2_RATE:
if (sd->state.lr_flag != 2)
sd->mdef2_rate += val;
break;
- case SP_RESTART_FULL_RECORVER:
- if (sd->state.lr_flag != 2)
- sd->special_state.restart_full_recover = 1;
- break;
- case SP_NO_CASTCANCEL:
- if (sd->state.lr_flag != 2)
- sd->special_state.no_castcancel = 1;
- break;
- case SP_NO_CASTCANCEL2:
- if (sd->state.lr_flag != 2)
- sd->special_state.no_castcancel2 = 1;
- break;
- case SP_NO_SIZEFIX:
- if (sd->state.lr_flag != 2)
- sd->special_state.no_sizefix = 1;
- break;
- case SP_NO_MAGIC_DAMAGE:
- if (sd->state.lr_flag != 2)
- sd->special_state.no_magic_damage = 1;
- break;
- case SP_NO_WEAPON_DAMAGE:
- if (sd->state.lr_flag != 2)
- sd->special_state.no_weapon_damage = 1;
- break;
- case SP_NO_GEMSTONE:
- if (sd->state.lr_flag != 2)
- sd->special_state.no_gemstone = 1;
- break;
- case SP_INFINITE_ENDURE:
- if (sd->state.lr_flag != 2)
- sd->special_state.infinite_endure = 1;
- break;
- case SP_SPLASH_RANGE:
- if (sd->state.lr_flag != 2 && sd->splash_range < val)
- sd->splash_range = val;
- break;
- case SP_SPLASH_ADD_RANGE:
- if (sd->state.lr_flag != 2)
- sd->splash_add_range += val;
- break;
- case SP_SHORT_WEAPON_DAMAGE_RETURN:
- if (sd->state.lr_flag != 2)
- sd->short_weapon_damage_return += val;
- break;
- case SP_LONG_WEAPON_DAMAGE_RETURN:
- if (sd->state.lr_flag != 2)
- sd->long_weapon_damage_return += val;
- break;
- case SP_MAGIC_DAMAGE_RETURN: //AppleGirl Was Here
- if (sd->state.lr_flag != 2)
- sd->magic_damage_return += val;
- break;
- case SP_ALL_STATS: // [Valaris]
- if (sd->state.lr_flag != 2)
- {
- sd->parame[SP_STR - SP_STR] += val;
- sd->parame[SP_AGI - SP_STR] += val;
- sd->parame[SP_VIT - SP_STR] += val;
- sd->parame[SP_INT - SP_STR] += val;
- sd->parame[SP_DEX - SP_STR] += val;
- sd->parame[SP_LUK - SP_STR] += val;
- clif_updatestatus (sd, 13);
- clif_updatestatus (sd, 14);
- clif_updatestatus (sd, 15);
- clif_updatestatus (sd, 16);
- clif_updatestatus (sd, 17);
- clif_updatestatus (sd, 18);
- }
- break;
- case SP_AGI_VIT: // [Valaris]
- if (sd->state.lr_flag != 2)
- {
- sd->parame[SP_AGI - SP_STR] += val;
- sd->parame[SP_VIT - SP_STR] += val;
- clif_updatestatus (sd, 14);
- clif_updatestatus (sd, 15);
- }
- break;
- case SP_AGI_DEX_STR: // [Valaris]
- if (sd->state.lr_flag != 2)
- {
- sd->parame[SP_AGI - SP_STR] += val;
- sd->parame[SP_DEX - SP_STR] += val;
- sd->parame[SP_STR - SP_STR] += val;
- clif_updatestatus (sd, 14);
- clif_updatestatus (sd, 17);
- clif_updatestatus (sd, 13);
- }
- break;
- case SP_PERFECT_HIDE: // [Valaris]
- if (sd->state.lr_flag != 2)
- {
- sd->perfect_hiding = 1;
- }
- break;
- case SP_DISGUISE: // Disguise script for items [Valaris]
- if (sd->state.lr_flag != 2 && sd->disguiseflag == 0)
- {
- if (pc_isriding (sd))
- { // temporary prevention of crash caused by peco + disguise, will look into a better solution [Valaris]
- clif_displaymessage (sd->fd,
- "Cannot wear disguise when riding a Peco.");
- break;
- }
- sd->disguise = val;
- clif_clearchar (&sd->bl, 9);
- pc_setpos (sd, sd->mapname, sd->bl.x, sd->bl.y, 3);
- }
- break;
- case SP_UNBREAKABLE:
- if (sd->state.lr_flag != 2)
- {
- sd->unbreakable += val;
- }
- break;
- case SP_DEAF:
+#endif
+ case SP::DEAF:
sd->special_state.deaf = 1;
break;
default:
if (battle_config.error_log)
- printf ("pc_bonus: unknown type %d %d !\n", type, val);
+ PRINTF("pc_bonus: unknown type %d %d !\n",
+ type, val);
break;
}
return 0;
@@ -2882,179 +1806,13 @@ int pc_bonus (struct map_session_data *sd, int type, int val)
* ソスソス ソスソスソスiソスノゑソスソスソスソス\ソスï¾é›£ï½¿ï½½ï½¿ï½½ï¾Œãƒœï½¿ï½½[ソスiソスXソスï¾æŠµï½¿ï½½
*------------------------------------------
*/
-int pc_bonus2 (struct map_session_data *sd, int type, int type2, int val)
+int pc_bonus2(struct map_session_data *sd, SP type, int type2, int val)
{
- int i;
-
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
switch (type)
{
- case SP_ADDELE:
- if (!sd->state.lr_flag)
- sd->addele[type2] += val;
- else if (sd->state.lr_flag == 1)
- sd->addele_[type2] += val;
- else if (sd->state.lr_flag == 2)
- sd->arrow_addele[type2] += val;
- break;
- case SP_ADDRACE:
- if (!sd->state.lr_flag)
- sd->addrace[type2] += val;
- else if (sd->state.lr_flag == 1)
- sd->addrace_[type2] += val;
- else if (sd->state.lr_flag == 2)
- sd->arrow_addrace[type2] += val;
- break;
- case SP_ADDSIZE:
- if (!sd->state.lr_flag)
- sd->addsize[type2] += val;
- else if (sd->state.lr_flag == 1)
- sd->addsize_[type2] += val;
- else if (sd->state.lr_flag == 2)
- sd->arrow_addsize[type2] += val;
- break;
- case SP_SUBELE:
- if (sd->state.lr_flag != 2)
- sd->subele[type2] += val;
- break;
- case SP_SUBRACE:
- if (sd->state.lr_flag != 2)
- sd->subrace[type2] += val;
- break;
- case SP_ADDEFF:
- if (sd->state.lr_flag != 2)
- sd->addeff[type2] += val;
- else
- sd->arrow_addeff[type2] += val;
- break;
- case SP_ADDEFF2:
- if (sd->state.lr_flag != 2)
- sd->addeff2[type2] += val;
- else
- sd->arrow_addeff2[type2] += val;
- break;
- case SP_RESEFF:
- if (sd->state.lr_flag != 2)
- sd->reseff[type2] += val;
- break;
- case SP_MAGIC_ADDELE:
- if (sd->state.lr_flag != 2)
- sd->magic_addele[type2] += val;
- break;
- case SP_MAGIC_ADDRACE:
- if (sd->state.lr_flag != 2)
- sd->magic_addrace[type2] += val;
- break;
- case SP_MAGIC_SUBRACE:
- if (sd->state.lr_flag != 2)
- sd->magic_subrace[type2] += val;
- break;
- case SP_ADD_DAMAGE_CLASS:
- if (!sd->state.lr_flag)
- {
- for (i = 0; i < sd->add_damage_class_count; i++)
- {
- if (sd->add_damage_classid[i] == type2)
- {
- sd->add_damage_classrate[i] += val;
- break;
- }
- }
- if (i >= sd->add_damage_class_count
- && sd->add_damage_class_count < 10)
- {
- sd->add_damage_classid[sd->add_damage_class_count] =
- type2;
- sd->add_damage_classrate[sd->add_damage_class_count] +=
- val;
- sd->add_damage_class_count++;
- }
- }
- else if (sd->state.lr_flag == 1)
- {
- for (i = 0; i < sd->add_damage_class_count_; i++)
- {
- if (sd->add_damage_classid_[i] == type2)
- {
- sd->add_damage_classrate_[i] += val;
- break;
- }
- }
- if (i >= sd->add_damage_class_count_
- && sd->add_damage_class_count_ < 10)
- {
- sd->add_damage_classid_[sd->add_damage_class_count_] =
- type2;
- sd->add_damage_classrate_[sd->add_damage_class_count_] +=
- val;
- sd->add_damage_class_count_++;
- }
- }
- break;
- case SP_ADD_MAGIC_DAMAGE_CLASS:
- if (sd->state.lr_flag != 2)
- {
- for (i = 0; i < sd->add_magic_damage_class_count; i++)
- {
- if (sd->add_magic_damage_classid[i] == type2)
- {
- sd->add_magic_damage_classrate[i] += val;
- break;
- }
- }
- if (i >= sd->add_magic_damage_class_count
- && sd->add_magic_damage_class_count < 10)
- {
- sd->add_magic_damage_classid
- [sd->add_magic_damage_class_count] = type2;
- sd->add_magic_damage_classrate
- [sd->add_magic_damage_class_count] += val;
- sd->add_magic_damage_class_count++;
- }
- }
- break;
- case SP_ADD_DEF_CLASS:
- if (sd->state.lr_flag != 2)
- {
- for (i = 0; i < sd->add_def_class_count; i++)
- {
- if (sd->add_def_classid[i] == type2)
- {
- sd->add_def_classrate[i] += val;
- break;
- }
- }
- if (i >= sd->add_def_class_count
- && sd->add_def_class_count < 10)
- {
- sd->add_def_classid[sd->add_def_class_count] = type2;
- sd->add_def_classrate[sd->add_def_class_count] += val;
- sd->add_def_class_count++;
- }
- }
- break;
- case SP_ADD_MDEF_CLASS:
- if (sd->state.lr_flag != 2)
- {
- for (i = 0; i < sd->add_mdef_class_count; i++)
- {
- if (sd->add_mdef_classid[i] == type2)
- {
- sd->add_mdef_classrate[i] += val;
- break;
- }
- }
- if (i >= sd->add_mdef_class_count
- && sd->add_mdef_class_count < 10)
- {
- sd->add_mdef_classid[sd->add_mdef_class_count] = type2;
- sd->add_mdef_classrate[sd->add_mdef_class_count] += val;
- sd->add_mdef_class_count++;
- }
- }
- break;
- case SP_HP_DRAIN_RATE:
+ case SP::HP_DRAIN_RATE:
if (!sd->state.lr_flag)
{
sd->hp_drain_rate += type2;
@@ -3066,7 +1824,8 @@ int pc_bonus2 (struct map_session_data *sd, int type, int type2, int val)
sd->hp_drain_per_ += val;
}
break;
- case SP_SP_DRAIN_RATE:
+#if 0
+ case SP::SP_DRAIN_RATE:
if (!sd->state.lr_flag)
{
sd->sp_drain_rate += type2;
@@ -3078,77 +1837,13 @@ int pc_bonus2 (struct map_session_data *sd, int type, int type2, int val)
sd->sp_drain_per_ += val;
}
break;
- case SP_WEAPON_COMA_ELE:
- if (sd->state.lr_flag != 2)
- sd->weapon_coma_ele[type2] += val;
- break;
- case SP_WEAPON_COMA_RACE:
- if (sd->state.lr_flag != 2)
- sd->weapon_coma_race[type2] += val;
- break;
- case SP_RANDOM_ATTACK_INCREASE: // [Valaris]
- if (sd->state.lr_flag != 2)
- {
- sd->random_attack_increase_add = type2;
- sd->random_attack_increase_per += val;
- break;
- } // end addition
- default:
- if (battle_config.error_log)
- printf ("pc_bonus2: unknown type %d %d %d!\n", type, type2,
- val);
- break;
- }
- return 0;
-}
-
-int pc_bonus3 (struct map_session_data *sd, int type, int type2, int type3,
- int val)
-{
- int i;
- switch (type)
- {
- case SP_ADD_MONSTER_DROP_ITEM:
- if (sd->state.lr_flag != 2)
- {
- for (i = 0; i < sd->monster_drop_item_count; i++)
- {
- if (sd->monster_drop_itemid[i] == type2)
- {
- sd->monster_drop_race[i] |= 1 << type3;
- if (sd->monster_drop_itemrate[i] < val)
- sd->monster_drop_itemrate[i] = val;
- break;
- }
- }
- if (i >= sd->monster_drop_item_count
- && sd->monster_drop_item_count < 10)
- {
- sd->monster_drop_itemid[sd->monster_drop_item_count] =
- type2;
- sd->monster_drop_race[sd->monster_drop_item_count] |=
- 1 << type3;
- sd->monster_drop_itemrate[sd->monster_drop_item_count] =
- val;
- sd->monster_drop_item_count++;
- }
- }
- break;
- case SP_AUTOSPELL:
- if (sd->state.lr_flag != 2)
- {
- sd->autospell_id = type2;
- sd->autospell_lv = type3;
- sd->autospell_rate = val;
- }
- break;
+#endif
default:
if (battle_config.error_log)
- printf ("pc_bonus3: unknown type %d %d %d %d!\n", type, type2,
- type3, val);
+ PRINTF("pc_bonus2: unknown type %d %d %d!\n",
+ type, type2, val);
break;
}
-
return 0;
}
@@ -3156,165 +1851,69 @@ int pc_bonus3 (struct map_session_data *sd, int type, int type2, int type3,
* スクリプトã«ã‚ˆã‚‹ã‚¹ã‚­ãƒ«æ‰€å¾—
*------------------------------------------
*/
-int pc_skill (struct map_session_data *sd, int id, int level, int flag)
+int pc_skill(struct map_session_data *sd, SkillID id, int level, int flag)
{
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
if (level > MAX_SKILL_LEVEL)
{
if (battle_config.error_log)
- printf ("support card skill only!\n");
+ PRINTF("support card skill only!\n");
return 0;
}
- if (!flag && (sd->status.skill[id].id == id || level == 0))
- { // クエスト所得ãªã‚‰ã“ã“ã§æ¡ä»¶ã‚’確èªã—ã¦é€ä¿¡ã™ã‚‹
+ if (!flag && (sd->status.skill[id].lv || level == 0))
+ {
sd->status.skill[id].lv = level;
- pc_calcstatus (sd, 0);
- clif_skillinfoblock (sd);
+ pc_calcstatus(sd, 0);
+ clif_skillinfoblock(sd);
}
else if (sd->status.skill[id].lv < level)
- { // 覚ãˆã‚‰ã‚Œã‚‹ãŒlvãŒå°ã•ã„ãªã‚‰
- sd->status.skill[id].id = id;
+ {
sd->status.skill[id].lv = level;
}
return 0;
}
-/*==========================================
- * カード挿入
- *------------------------------------------
- */
-int pc_insert_card (struct map_session_data *sd, int idx_card, int idx_equip)
-{
- nullpo_retr (0, sd);
-
- if (idx_card >= 0 && idx_card < MAX_INVENTORY && idx_equip >= 0
- && idx_equip < MAX_INVENTORY && sd->inventory_data[idx_card])
- {
- int i;
- int nameid = sd->status.inventory[idx_equip].nameid;
- int cardid = sd->status.inventory[idx_card].nameid;
- int ep = sd->inventory_data[idx_card]->equip;
-
- if (nameid <= 0 || sd->inventory_data[idx_equip] == NULL ||
- (sd->inventory_data[idx_equip]->type != 4 && sd->inventory_data[idx_equip]->type != 5) || // 装 å‚™ã˜ã‚ƒãªã„
- (sd->status.inventory[idx_equip].identify == 0) || // 未鑑定
- (sd->status.inventory[idx_equip].card[0] == 0x00ff) || // 製造武器
- (sd->status.inventory[idx_equip].card[0] == 0x00fe) ||
- ((sd->inventory_data[idx_equip]->equip & ep) == 0) || // 装 備個所é•ã„
- (sd->inventory_data[idx_equip]->type == 4 && ep == 32) || // 両 手武器ã¨ç›¾ã‚«ãƒ¼ãƒ‰
- (sd->status.inventory[idx_equip].card[0] == (short) 0xff00)
- || sd->status.inventory[idx_equip].equip)
- {
-
- clif_insert_card (sd, idx_equip, idx_card, 1);
- return 0;
- }
- for (i = 0; i < sd->inventory_data[idx_equip]->slot; i++)
- {
- if (sd->status.inventory[idx_equip].card[i] == 0)
- {
- // 空ãスロットãŒã‚ã£ãŸã®ã§å·®ã—込む
- sd->status.inventory[idx_equip].card[i] = cardid;
-
- // カードã¯æ¸›ã‚‰ã™
- clif_insert_card (sd, idx_equip, idx_card, 0);
- pc_delitem (sd, idx_card, 1, 1);
- return 0;
- }
- }
- }
- else
- clif_insert_card (sd, idx_equip, idx_card, 1);
-
- return 0;
-}
-
-//
-// アイテム物
-//
-
-/*==========================================
- * スキルã«ã‚ˆã‚‹è²·ã„値修正
- *------------------------------------------
- */
-int pc_modifybuyvalue (struct map_session_data *sd, int orig_value)
-{
- int skill, val = orig_value, rate1 = 0, rate2 = 0;
- if ((skill = pc_checkskill (sd, MC_DISCOUNT)) > 0) // ディスカウント
- rate1 = 5 + skill * 2 - ((skill == 10) ? 1 : 0);
- if ((skill = pc_checkskill (sd, RG_COMPULSION)) > 0) // コムパルションディスカウント
- rate2 = 5 + skill * 4;
- if (rate1 < rate2)
- rate1 = rate2;
- if (rate1)
- val = (int) ((double) orig_value * (double) (100 - rate1) / 100.);
- if (val < 0)
- val = 0;
- if (orig_value > 0 && val < 1)
- val = 1;
-
- return val;
-}
-
-/*==========================================
- * スキルã«ã‚ˆã‚‹å£²ã‚Šå€¤ä¿®æ­£
- *------------------------------------------
- */
-int pc_modifysellvalue (struct map_session_data *sd, int orig_value)
-{
- int skill, val = orig_value, rate = 0;
- if ((skill = pc_checkskill (sd, MC_OVERCHARGE)) > 0) // オーãƒãƒ¼ãƒãƒ£ãƒ¼ã‚¸
- rate = 5 + skill * 2 - ((skill == 10) ? 1 : 0);
- if (rate)
- val = (int) ((double) orig_value * (double) (100 + rate) / 100.);
- if (val < 0)
- val = 0;
- if (orig_value > 0 && val < 1)
- val = 1;
-
- return val;
-}
/*==========================================
* アイテムを買ã£ãŸæ™‚ã«ã€æ–°ã—ã„アイテム欄を使ã†ã‹ã€
* 3万個制é™ã«ã‹ã‹ã‚‹ã‹ç¢ºèª
*------------------------------------------
*/
-int pc_checkadditem (struct map_session_data *sd, int nameid, int amount)
+ADDITEM pc_checkadditem(struct map_session_data *sd, int nameid, int amount)
{
- int i;
+ int i;
- nullpo_retr (0, sd);
+ nullpo_retr(ADDITEM::ZERO, sd);
- if (itemdb_isequip (nameid))
- return ADDITEM_NEW;
+ if (itemdb_isequip(nameid))
+ return ADDITEM::NEW;
for (i = 0; i < MAX_INVENTORY; i++)
{
if (sd->status.inventory[i].nameid == nameid)
{
if (sd->status.inventory[i].amount + amount > MAX_AMOUNT)
- return ADDITEM_OVERAMOUNT;
- return ADDITEM_EXIST;
+ return ADDITEM::OVERAMOUNT;
+ return ADDITEM::EXIST;
}
}
if (amount > MAX_AMOUNT)
- return ADDITEM_OVERAMOUNT;
- return ADDITEM_NEW;
+ return ADDITEM::OVERAMOUNT;
+ return ADDITEM::NEW;
}
/*==========================================
* 空ãアイテム欄ã®å€‹æ•°
*------------------------------------------
*/
-int pc_inventoryblank (struct map_session_data *sd)
+int pc_inventoryblank(struct map_session_data *sd)
{
- int i, b;
+ int i, b;
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
for (i = 0, b = 0; i < MAX_INVENTORY; i++)
{
@@ -3329,17 +1928,17 @@ int pc_inventoryblank (struct map_session_data *sd)
* ãŠé‡‘を払ã†
*------------------------------------------
*/
-int pc_payzeny (struct map_session_data *sd, int zeny)
+int pc_payzeny(struct map_session_data *sd, int zeny)
{
double z;
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
z = (double) sd->status.zeny;
if (sd->status.zeny < zeny || z - (double) zeny > MAX_ZENY)
return 1;
sd->status.zeny -= zeny;
- clif_updatestatus (sd, SP_ZENY);
+ clif_updatestatus(sd, SP::ZENY);
return 0;
}
@@ -3348,11 +1947,11 @@ int pc_payzeny (struct map_session_data *sd, int zeny)
* ãŠé‡‘ã‚’å¾—ã‚‹
*------------------------------------------
*/
-int pc_getzeny (struct map_session_data *sd, int zeny)
+int pc_getzeny(struct map_session_data *sd, int zeny)
{
double z;
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
z = (double) sd->status.zeny;
if (z + (double) zeny > MAX_ZENY)
@@ -3361,7 +1960,7 @@ int pc_getzeny (struct map_session_data *sd, int zeny)
sd->status.zeny = MAX_ZENY;
}
sd->status.zeny += zeny;
- clif_updatestatus (sd, SP_ZENY);
+ clif_updatestatus(sd, SP::ZENY);
return 0;
}
@@ -3370,11 +1969,11 @@ int pc_getzeny (struct map_session_data *sd, int zeny)
* アイテムを探ã—ã¦ã€ã‚¤ãƒ³ãƒ‡ãƒƒã‚¯ã‚¹ã‚’è¿”ã™
*------------------------------------------
*/
-int pc_search_inventory (struct map_session_data *sd, int item_id)
+int pc_search_inventory(struct map_session_data *sd, int item_id)
{
- int i;
+ int i;
- nullpo_retr (-1, sd);
+ nullpo_retr(-1, sd);
for (i = 0; i < MAX_INVENTORY; i++)
{
@@ -3386,12 +1985,12 @@ int pc_search_inventory (struct map_session_data *sd, int item_id)
return -1;
}
-int pc_count_all_items (struct map_session_data *player, int item_id)
+int pc_count_all_items(struct map_session_data *player, int item_id)
{
- int i;
- int count = 0;
+ int i;
+ int count = 0;
- nullpo_retr (0, player);
+ nullpo_ret(player);
for (i = 0; i < MAX_INVENTORY; i++)
{
@@ -3402,24 +2001,24 @@ int pc_count_all_items (struct map_session_data *player, int item_id)
return count;
}
-int pc_remove_items (struct map_session_data *player, int item_id, int count)
+int pc_remove_items(struct map_session_data *player, int item_id, int count)
{
- int i;
+ int i;
- nullpo_retr (0, player);
+ nullpo_ret(player);
for (i = 0; i < MAX_INVENTORY && count; i++)
{
if (player->status.inventory[i].nameid == item_id)
{
- int to_delete = count;
+ int to_delete = count;
/* only delete as much as we have */
if (to_delete > player->status.inventory[i].amount)
to_delete = player->status.inventory[i].amount;
count -= to_delete;
- pc_delitem (player, i, to_delete,
+ pc_delitem(player, i, to_delete,
0 /* means `really delete and update status' */ );
if (!count)
@@ -3433,26 +2032,26 @@ int pc_remove_items (struct map_session_data *player, int item_id, int count)
* アイテム追加。個数ã®ã¿item構造体ã®æ•°å­—を無視
*------------------------------------------
*/
-int pc_additem (struct map_session_data *sd, struct item *item_data,
+PickupFail pc_additem(struct map_session_data *sd, struct item *item_data,
int amount)
{
struct item_data *data;
- int i, w;
+ int i, w;
- MAP_LOG_PC (sd, "PICKUP %d %d", item_data->nameid, amount);
+ MAP_LOG_PC(sd, "PICKUP %d %d", item_data->nameid, amount);
- nullpo_retr (1, sd);
- nullpo_retr (1, item_data);
+ nullpo_retr(PickupFail::BAD_ITEM, sd);
+ nullpo_retr(PickupFail::BAD_ITEM, item_data);
if (item_data->nameid <= 0 || amount <= 0)
- return 1;
- data = itemdb_search (item_data->nameid);
+ return PickupFail::BAD_ITEM;
+ data = itemdb_search(item_data->nameid);
if ((w = data->weight * amount) + sd->weight > sd->max_weight)
- return 2;
+ return PickupFail::TOO_HEAVY;
i = MAX_INVENTORY;
- if (!itemdb_isequip2 (data))
+ if (!itemdb_isequip2(data))
{
// 装 å‚™å“ã§ã¯ãªã„ã®ã§ã€æ—¢æ‰€æœ‰å“ãªã‚‰å€‹æ•°ã®ã¿å¤‰åŒ–ã•ã›ã‚‹
for (i = 0; i < MAX_INVENTORY; i++)
@@ -3463,47 +2062,47 @@ int pc_additem (struct map_session_data *sd, struct item *item_data,
&& sd->status.inventory[i].card[3] == item_data->card[3])
{
if (sd->status.inventory[i].amount + amount > MAX_AMOUNT)
- return 5;
+ return PickupFail::STACK_FULL;
sd->status.inventory[i].amount += amount;
- clif_additem (sd, i, amount, 0);
+ clif_additem(sd, i, amount, PickupFail::OKAY);
break;
}
}
if (i >= MAX_INVENTORY)
{
// 装 å‚™å“ã‹æœªæ‰€æœ‰å“ã ã£ãŸã®ã§ç©ºã欄ã¸è¿½åŠ 
- i = pc_search_inventory (sd, 0);
+ i = pc_search_inventory(sd, 0);
if (i >= 0)
{
- memcpy (&sd->status.inventory[i], item_data,
- sizeof (sd->status.inventory[0]));
+ memcpy(&sd->status.inventory[i], item_data,
+ sizeof(sd->status.inventory[0]));
- if (item_data->equip)
- sd->status.inventory[i].equip = 0;
+ if (bool(item_data->equip))
+ sd->status.inventory[i].equip = EPOS::ZERO;
sd->status.inventory[i].amount = amount;
sd->inventory_data[i] = data;
- clif_additem (sd, i, amount, 0);
+ clif_additem(sd, i, amount, PickupFail::OKAY);
}
else
- return 4;
+ return PickupFail::INV_FULL;
}
sd->weight += w;
- clif_updatestatus (sd, SP_WEIGHT);
+ clif_updatestatus(sd, SP::WEIGHT);
- return 0;
+ return PickupFail::OKAY;
}
/*==========================================
* アイテムを減らã™
*------------------------------------------
*/
-int pc_delitem (struct map_session_data *sd, int n, int amount, int type)
+int pc_delitem(struct map_session_data *sd, int n, int amount, int type)
{
- nullpo_retr (1, sd);
+ nullpo_retr(1, sd);
if (sd->trade_partner != 0)
- trade_tradecancel (sd);
+ trade_tradecancel(sd);
if (sd->status.inventory[n].nameid == 0 || amount <= 0
|| sd->status.inventory[n].amount < amount
@@ -3514,16 +2113,16 @@ int pc_delitem (struct map_session_data *sd, int n, int amount, int type)
sd->weight -= sd->inventory_data[n]->weight * amount;
if (sd->status.inventory[n].amount <= 0)
{
- if (sd->status.inventory[n].equip)
- pc_unequipitem (sd, n, 0);
- memset (&sd->status.inventory[n], 0,
- sizeof (sd->status.inventory[0]));
+ if (bool(sd->status.inventory[n].equip))
+ pc_unequipitem(sd, n, CalcStatus::NOW);
+ memset(&sd->status.inventory[n], 0,
+ sizeof(sd->status.inventory[0]));
sd->inventory_data[n] = NULL;
}
if (!(type & 1))
- clif_delitem (sd, n, amount);
+ clif_delitem(sd, n, amount);
if (!(type & 2))
- clif_updatestatus (sd, SP_WEIGHT);
+ clif_updatestatus(sd, SP::WEIGHT);
return 0;
}
@@ -3532,11 +2131,11 @@ int pc_delitem (struct map_session_data *sd, int n, int amount, int type)
* アイテムをè½ã™
*------------------------------------------
*/
-int pc_dropitem (struct map_session_data *sd, int n, int amount)
+int pc_dropitem(struct map_session_data *sd, int n, int amount)
{
- nullpo_retr (1, sd);
+ nullpo_retr(1, sd);
- if (sd->trade_partner != 0 || sd->npc_id != 0 || sd->state.storage_flag)
+ if (sd->trade_partner != 0 || sd->npc_id != 0 || sd->state.storage_open)
return 0; // no dropping while trading/npc/storage
if (n < 0 || n >= MAX_INVENTORY)
@@ -3545,15 +2144,16 @@ int pc_dropitem (struct map_session_data *sd, int n, int amount)
if (amount <= 0)
return 0;
- pc_unequipinvyitem (sd, n, 0);
+ pc_unequipinvyitem(sd, n, CalcStatus::NOW);
if (sd->status.inventory[n].nameid <= 0 ||
sd->status.inventory[n].amount < amount ||
sd->trade_partner != 0 || sd->status.inventory[n].amount <= 0)
return 1;
- map_addflooritem (&sd->status.inventory[n], amount, sd->bl.m, sd->bl.x,
- sd->bl.y, NULL, NULL, NULL, 0);
- pc_delitem (sd, n, amount, 0);
+ map_addflooritem(&sd->status.inventory[n], amount,
+ sd->bl.m, sd->bl.x, sd->bl.y,
+ NULL, NULL, NULL);
+ pc_delitem(sd, n, amount, 0);
return 0;
}
@@ -3563,15 +2163,16 @@ int pc_dropitem (struct map_session_data *sd, int n, int amount)
*------------------------------------------
*/
-static int can_pick_item_up_from (struct map_session_data *self, int other_id)
+static
+int can_pick_item_up_from(struct map_session_data *self, int other_id)
{
- struct party *p = party_search (self->status.party_id);
+ struct party *p = party_search(self->status.party_id);
/* From ourselves or from no-one? */
if (!self || self->bl.id == other_id || !other_id)
return 1;
- struct map_session_data *other = map_id2sd (other_id);
+ struct map_session_data *other = map_id2sd(other_id);
/* Other no longer exists? */
if (!other)
@@ -3593,22 +2194,21 @@ static int can_pick_item_up_from (struct map_session_data *self, int other_id)
return 1;
else
{
- int distance_x = abs (other->bl.x - self->bl.x);
- int distance_y = abs (other->bl.y - self->bl.y);
- int distance = (distance_x > distance_y) ? distance_x : distance_y;
+ int distance_x = abs(other->bl.x - self->bl.x);
+ int distance_y = abs(other->bl.y - self->bl.y);
+ int distance = (distance_x > distance_y) ? distance_x : distance_y;
return distance > battle_config.drop_pickup_safety_zone;
}
}
-int pc_takeitem (struct map_session_data *sd, struct flooritem_data *fitem)
+int pc_takeitem(struct map_session_data *sd, struct flooritem_data *fitem)
{
- int flag;
- unsigned int tick = gettick ();
- int can_take;
+ tick_t tick = gettick();
+ int can_take;
- nullpo_retr (0, sd);
- nullpo_retr (0, fitem);
+ nullpo_ret(sd);
+ nullpo_ret(fitem);
/* Sometimes the owners reported to us are buggy: */
@@ -3622,14 +2222,14 @@ int pc_takeitem (struct map_session_data *sd, struct flooritem_data *fitem)
fitem->third_get_id = 0;
}
- can_take = can_pick_item_up_from (sd, fitem->first_get_id);
+ can_take = can_pick_item_up_from(sd, fitem->first_get_id);
if (!can_take)
can_take = fitem->first_get_tick <= tick
- && can_pick_item_up_from (sd, fitem->second_get_id);
+ && can_pick_item_up_from(sd, fitem->second_get_id);
if (!can_take)
can_take = fitem->second_get_tick <= tick
- && can_pick_item_up_from (sd, fitem->third_get_id);
+ && can_pick_item_up_from(sd, fitem->third_get_id);
if (!can_take)
can_take = fitem->third_get_tick <= tick;
@@ -3638,54 +2238,51 @@ int pc_takeitem (struct map_session_data *sd, struct flooritem_data *fitem)
{
/* Can pick up */
- if ((flag =
- pc_additem (sd, &fitem->item_data, fitem->item_data.amount)))
+ PickupFail flag = pc_additem(sd, &fitem->item_data, fitem->item_data.amount);
+ if (flag != PickupFail::OKAY)
// é‡é‡overã§å–得失敗
- clif_additem (sd, 0, 0, flag);
+ clif_additem(sd, 0, 0, flag);
else
{
// å–å¾—æˆåŠŸ
- if (sd->attacktimer != -1)
- pc_stopattack (sd);
- clif_takeitem (&sd->bl, &fitem->bl);
- map_clearflooritem (fitem->bl.id);
+ if (sd->attacktimer)
+ pc_stopattack(sd);
+ clif_takeitem(&sd->bl, &fitem->bl);
+ map_clearflooritem(fitem->bl.id);
}
return 0;
}
/* Otherwise, we can't pick up */
- clif_additem (sd, 0, 0, 6);
+ clif_additem(sd, 0, 0, PickupFail::DROP_STEAL);
return 0;
}
static
-int pc_isUseitem (struct map_session_data *sd, int n)
+int pc_isUseitem(struct map_session_data *sd, int n)
{
struct item_data *item;
- int nameid;
+ int nameid;
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
item = sd->inventory_data[n];
nameid = sd->status.inventory[n].nameid;
if (item == NULL)
return 0;
- if (itemdb_type (nameid) != 0)
- return 0;
- if ((nameid == 605) && map[sd->bl.m].flag.gvg)
+ if (itemdb_type(nameid) != ItemType::USE)
return 0;
if (nameid == 601
- && (map[sd->bl.m].flag.noteleport || map[sd->bl.m].flag.gvg))
+ && (map[sd->bl.m].flag.noteleport))
{
- clif_skill_teleportmessage (sd, 0);
return 0;
}
if (nameid == 602 && map[sd->bl.m].flag.noreturn)
return 0;
if (nameid == 604
- && (map[sd->bl.m].flag.nobranch || map[sd->bl.m].flag.gvg))
+ && (map[sd->bl.m].flag.nobranch))
return 0;
if (item->sex != 2 && sd->status.sex != item->sex)
return 0;
@@ -3699,362 +2296,51 @@ int pc_isUseitem (struct map_session_data *sd, int n)
* アイテムを使ã†
*------------------------------------------
*/
-int pc_useitem (struct map_session_data *sd, int n)
+int pc_useitem(struct map_session_data *sd, int n)
{
- int nameid, amount;
+ int amount;
- nullpo_retr (1, sd);
+ nullpo_retr(1, sd);
if (n >= 0 && n < MAX_INVENTORY && sd->inventory_data[n])
{
- nameid = sd->status.inventory[n].nameid;
amount = sd->status.inventory[n].amount;
if (sd->status.inventory[n].nameid <= 0
|| sd->status.inventory[n].amount <= 0
- || sd->sc_data[SC_BERSERK].timer != -1 || !pc_isUseitem (sd, n))
+ || !pc_isUseitem(sd, n))
{
- clif_useitemack (sd, n, 0, 0);
+ clif_useitemack(sd, n, 0, 0);
return 1;
}
- run_script (sd->inventory_data[n]->use_script, 0, sd->bl.id, 0);
+ run_script(sd->inventory_data[n]->use_script, 0, sd->bl.id, 0);
- clif_useitemack (sd, n, amount - 1, 1);
- pc_delitem (sd, n, 1, 1);
+ clif_useitemack(sd, n, amount - 1, 1);
+ pc_delitem(sd, n, 1, 1);
}
return 0;
}
/*==========================================
- * カートアイテム追加。個数ã®ã¿item構造体ã®æ•°å­—を無視
- *------------------------------------------
- */
-int pc_cart_additem (struct map_session_data *sd, struct item *item_data,
- int amount)
-{
- struct item_data *data;
- int i, w;
-
- nullpo_retr (1, sd);
- nullpo_retr (1, item_data);
-
- if (item_data->nameid <= 0 || amount <= 0)
- return 1;
- data = itemdb_search (item_data->nameid);
-
- if ((w = data->weight * amount) + sd->cart_weight > sd->cart_max_weight)
- return 1;
-
- i = MAX_CART;
- if (!itemdb_isequip2 (data))
- {
- // 装 å‚™å“ã§ã¯ãªã„ã®ã§ã€æ—¢æ‰€æœ‰å“ãªã‚‰å€‹æ•°ã®ã¿å¤‰åŒ–ã•ã›ã‚‹
- for (i = 0; i < MAX_CART; i++)
- {
- if (sd->status.cart[i].nameid == item_data->nameid &&
- sd->status.cart[i].card[0] == item_data->card[0]
- && sd->status.cart[i].card[1] == item_data->card[1]
- && sd->status.cart[i].card[2] == item_data->card[2]
- && sd->status.cart[i].card[3] == item_data->card[3])
- {
- if (sd->status.cart[i].amount + amount > MAX_AMOUNT)
- return 1;
- sd->status.cart[i].amount += amount;
- clif_cart_additem (sd, i, amount, 0);
- break;
- }
- }
- }
- if (i >= MAX_CART)
- {
- // 装 å‚™å“ã‹æœªæ‰€æœ‰å“ã ã£ãŸã®ã§ç©ºã欄ã¸è¿½åŠ 
- for (i = 0; i < MAX_CART; i++)
- {
- if (sd->status.cart[i].nameid == 0)
- {
- memcpy (&sd->status.cart[i], item_data,
- sizeof (sd->status.cart[0]));
- sd->status.cart[i].amount = amount;
- sd->cart_num++;
- clif_cart_additem (sd, i, amount, 0);
- break;
- }
- }
- if (i >= MAX_CART)
- return 1;
- }
- sd->cart_weight += w;
- clif_updatestatus (sd, SP_CARTINFO);
-
- return 0;
-}
-
-/*==========================================
* カートアイテムを減らã™
*------------------------------------------
*/
-int pc_cart_delitem (struct map_session_data *sd, int n, int amount, int type)
+static
+int pc_cart_delitem(struct map_session_data *sd, int n, int amount, int)
{
- nullpo_retr (1, sd);
+ nullpo_retr(1, sd);
if (sd->status.cart[n].nameid == 0 || sd->status.cart[n].amount < amount)
return 1;
sd->status.cart[n].amount -= amount;
- sd->cart_weight -= itemdb_weight (sd->status.cart[n].nameid) * amount;
+ sd->cart_weight -= itemdb_weight(sd->status.cart[n].nameid) * amount;
if (sd->status.cart[n].amount <= 0)
{
- memset (&sd->status.cart[n], 0, sizeof (sd->status.cart[0]));
+ memset(&sd->status.cart[n], 0, sizeof(sd->status.cart[0]));
sd->cart_num--;
}
- if (!type)
- {
- clif_cart_delitem (sd, n, amount);
- clif_updatestatus (sd, SP_CARTINFO);
- }
-
- return 0;
-}
-
-/*==========================================
- * カートã¸ã‚¢ã‚¤ãƒ†ãƒ ç§»å‹•
- *------------------------------------------
- */
-int pc_putitemtocart (struct map_session_data *sd, int idx, int amount)
-{
- struct item *item_data;
-
- nullpo_retr (0, sd);
-
- if (idx < 0 || idx >= MAX_INVENTORY)
- return 1;
-
- nullpo_retr (0, item_data = &sd->status.inventory[idx]);
-
- if (!pc_iscarton (sd))
- return 1;
- if (item_data->nameid == 0 || item_data->amount < amount)
- return 1;
- if (pc_cart_additem (sd, item_data, amount) == 0)
- return pc_delitem (sd, idx, amount, 0);
-
- return 1;
-}
-
-/*==========================================
- * カート内ã®ã‚¢ã‚¤ãƒ†ãƒ æ•°ç¢ºèª(個数ã®å·®åˆ†ã‚’è¿”ã™)
- *------------------------------------------
- */
-int pc_cartitem_amount (struct map_session_data *sd, int idx, int amount)
-{
- struct item *item_data;
-
- nullpo_retr (-1, sd);
-
- if (idx < 0 || idx >= MAX_CART)
- return -1;
-
- nullpo_retr (-1, item_data = &sd->status.cart[idx]);
-
- if (!pc_iscarton (sd))
- return -1;
- if (item_data->nameid == 0 || !item_data->amount)
- return -1;
- return item_data->amount - amount;
-}
-
-/*==========================================
- * カートã‹ã‚‰ã‚¢ã‚¤ãƒ†ãƒ ç§»å‹•
- *------------------------------------------
- */
-
-int pc_getitemfromcart (struct map_session_data *sd, int idx, int amount)
-{
- struct item *item_data;
- int flag;
-
- nullpo_retr (0, sd);
-
- if (idx < 0 || idx >= MAX_CART)
- return 1;
-
- nullpo_retr (0, item_data = &sd->status.cart[idx]);
-
- if (!pc_iscarton (sd))
- return 1;
- if (item_data->nameid == 0 || item_data->amount < amount)
- return 1;
- if ((flag = pc_additem (sd, item_data, amount)) == 0)
- return pc_cart_delitem (sd, idx, amount, 0);
-
- clif_additem (sd, 0, 0, flag);
- return 1;
-}
-
-/*==========================================
- * アイテム鑑定
- *------------------------------------------
- */
-int pc_item_identify (struct map_session_data *sd, int idx)
-{
- int flag = 1;
-
- nullpo_retr (0, sd);
-
- if (idx >= 0 && idx < MAX_INVENTORY)
- {
- if (sd->status.inventory[idx].nameid > 0
- && sd->status.inventory[idx].identify == 0)
- {
- flag = 0;
- sd->status.inventory[idx].identify = 1;
- }
- clif_item_identified (sd, idx, flag);
- }
- else
- clif_item_identified (sd, idx, flag);
-
- return !flag;
-}
-
-/*==========================================
- * スティルå“公開
- *------------------------------------------
- */
-static
-int pc_show_steal (struct block_list *bl, va_list ap)
-{
- struct map_session_data *sd;
- int itemid;
- int type;
-
- struct item_data *item = NULL;
- char output[100];
-
- nullpo_retr (0, bl);
- nullpo_retr (0, ap);
- nullpo_retr (0, sd = va_arg (ap, struct map_session_data *));
-
- itemid = va_arg (ap, int);
- type = va_arg (ap, int);
-
- if (!type)
- {
- if ((item = itemdb_exists (itemid)) == NULL)
- sprintf (output, "%s stole an Unknown_Item.", sd->status.name);
- else
- sprintf (output, "%s stole %s.", sd->status.name, item->jname);
- clif_displaymessage (((struct map_session_data *) bl)->fd, output);
- }
- else
- {
- sprintf (output,
- "%s has not stolen the item because of being overweight.",
- sd->status.name);
- clif_displaymessage (((struct map_session_data *) bl)->fd, output);
- }
-
- return 0;
-}
-
-/*==========================================
- *
- *------------------------------------------
- */
-//** pc.c: Small Steal Item fix by fritz
-int pc_steal_item (struct map_session_data *sd, struct block_list *bl)
-{
- if (sd != NULL && bl != NULL && bl->type == BL_MOB)
- {
- int i, skill, rate, itemid, flag, count;
- struct mob_data *md;
- md = (struct mob_data *) bl;
- if (!md->state.steal_flag && mob_db[md->mob_class].mexp <= 0 &&
- !(mob_db[md->mob_class].mode & 0x20) &&
- md->sc_data[SC_STONE].timer == -1 &&
- md->sc_data[SC_FREEZE].timer == -1 &&
- (!(md->mob_class > 1324 && md->mob_class < 1364))) // prevent stealing from treasure boxes [Valaris]
- {
- skill = sd->paramc[4] - mob_db[md->mob_class].dex
- + pc_checkskill (sd, TF_STEAL) + 10;
-
- if (0 < skill)
- {
- for (count = 8; count <= 8 && count != 0; count--)
- {
- i = rand () % 8;
- itemid = mob_db[md->mob_class].dropitem[i].nameid;
-
- if (itemid > 0 && itemdb_type (itemid) != 6)
- {
- rate =
- (mob_db[md->mob_class].dropitem[i].p /
- battle_config.item_rate_common * 100 * skill) /
- 100;
-
- if (rand () % 10000 < rate)
- {
- struct item tmp_item;
- memset (&tmp_item, 0, sizeof (tmp_item));
- tmp_item.nameid = itemid;
- tmp_item.amount = 1;
- tmp_item.identify = 1;
- flag = pc_additem (sd, &tmp_item, 1);
- if (battle_config.show_steal_in_same_party)
- {
- party_foreachsamemap (pc_show_steal, sd, 1,
- sd, tmp_item.nameid, 0);
- }
-
- if (flag)
- {
- if (battle_config.show_steal_in_same_party)
- {
- party_foreachsamemap (pc_show_steal, sd,
- 1, sd,
- tmp_item.nameid, 1);
- }
-
- clif_additem (sd, 0, 0, flag);
- }
- md->state.steal_flag = 1;
- return 1;
- }
- }
- }
- }
- }
- }
- return 0;
-}
-
-/*==========================================
- *
- *------------------------------------------
- */
-int pc_steal_coin (struct map_session_data *sd, struct block_list *bl)
-{
- if (sd != NULL && bl != NULL && bl->type == BL_MOB)
- {
- int rate, skill;
- struct mob_data *md = (struct mob_data *) bl;
- if (md && !md->state.steal_coin_flag && md->sc_data
- && md->sc_data[SC_STONE].timer == -1
- && md->sc_data[SC_FREEZE].timer == -1)
- {
- skill = pc_checkskill (sd, RG_STEALCOIN) * 10;
- rate =
- skill + (sd->status.base_level - mob_db[md->mob_class].lv) * 3 +
- sd->paramc[4] * 2 + sd->paramc[5] * 2;
- if (MRAND (1000) < rate)
- {
- pc_getzeny (sd, mob_db[md->mob_class].lv * 10 + MRAND (100));
- md->state.steal_coin_flag = 1;
- return 1;
- }
- }
- }
return 0;
}
@@ -4066,135 +2352,103 @@ int pc_steal_coin (struct map_session_data *sd, struct block_list *bl)
* PCã®ä½ç½®è¨­å®š
*------------------------------------------
*/
-int pc_setpos (struct map_session_data *sd, const char *mapname_org, int x, int y,
- int clrtype)
+int pc_setpos(struct map_session_data *sd, const char *mapname_org, int x, int y,
+ BeingRemoveWhy clrtype)
{
char mapname[24];
- int m = 0, c = 0, disguise = 0;
+ int m = 0;
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
if (sd->chatID) // ãƒãƒ£ãƒƒãƒˆã‹ã‚‰å‡ºã‚‹
- chat_leavechat (sd);
+ chat_leavechat(sd);
if (sd->trade_partner) // å–引を中断ã™ã‚‹
- trade_tradecancel (sd);
- if (sd->state.storage_flag == 1)
- storage_storage_quit (sd); // 倉庫を開ã„ã¦ã‚‹ãªã‚‰ä¿å­˜ã™ã‚‹
- else if (sd->state.storage_flag == 2)
- storage_guild_storage_quit (sd, 0);
+ trade_tradecancel(sd);
+ if (sd->state.storage_open)
+ storage_storage_quit(sd); // 倉庫を開ã„ã¦ã‚‹ãªã‚‰ä¿å­˜ã™ã‚‹
if (sd->party_invite > 0) // パーティ勧誘を拒å¦ã™ã‚‹
- party_reply_invite (sd, sd->party_invite_account, 0);
- if (sd->guild_invite > 0) // ギルド勧誘を拒å¦ã™ã‚‹
- guild_reply_invite (sd, sd->guild_invite, 0);
- if (sd->guild_alliance > 0) // ギルドåŒç›Ÿå‹§èª˜ã‚’æ‹’å¦ã™ã‚‹
- guild_reply_reqalliance (sd, sd->guild_alliance_account, 0);
+ party_reply_invite(sd, sd->party_invite_account, 0);
- skill_castcancel (&sd->bl, 0); // 詠唱中断
- pc_stop_walking (sd, 0); // 歩行中断
- pc_stopattack (sd); // 攻撃中断
+ skill_castcancel(&sd->bl, 0); // 詠唱中断
+ pc_stop_walking(sd, 0); // 歩行中断
+ pc_stopattack(sd); // 攻撃中断
- if (pc_issit (sd))
+ if (pc_issit(sd))
{
// pc_setstand (sd); // [fate] Nothing wrong with warping while sitting
- skill_gangsterparadise (sd, 0);
- }
-
- if (sd->sc_data[SC_TRICKDEAD].timer != -1)
- skill_status_change_end (&sd->bl, SC_TRICKDEAD, -1);
- if (sd->status.option & 2)
- skill_status_change_end (&sd->bl, SC_HIDING, -1);
- if (sd->status.option & 4)
- skill_status_change_end (&sd->bl, SC_CLOAKING, -1);
- if (sd->status.option & 16386)
- skill_status_change_end (&sd->bl, SC_CHASEWALK, -1);
- if (sd->sc_data[SC_BLADESTOP].timer != -1)
- skill_status_change_end (&sd->bl, SC_BLADESTOP, -1);
- if (sd->sc_data[SC_DANCING].timer != -1) // clear dance effect when warping [Valaris]
- skill_stop_dancing (&sd->bl, 0);
-
- if (sd->disguise)
- { // clear disguises when warping [Valaris]
- clif_clearchar (&sd->bl, 9);
- disguise = sd->disguise;
- sd->disguise = 0;
- }
-
- memcpy (mapname, mapname_org, 24);
+ skill_gangsterparadise(sd, 0);
+ }
+
+ memcpy(mapname, mapname_org, 24);
mapname[16] = 0;
- if (strstr (mapname, ".gat") == NULL && strlen (mapname) < 16)
+ if (strstr(mapname, ".gat") == NULL && strlen(mapname) < 16)
{
- strcat (mapname, ".gat");
+ strcat(mapname, ".gat");
}
- m = map_mapname2mapid (mapname);
+ m = map_mapname2mapid(mapname);
if (m < 0)
{
if (sd->mapname[0])
{
struct in_addr ip;
int port;
- if (map_mapname2ipport (mapname, &ip, &port) == 0)
+ if (map_mapname2ipport(mapname, &ip, &port) == 0)
{
- skill_stop_dancing (&sd->bl, 1);
- skill_unit_out_all (&sd->bl, gettick (), 1);
- clif_clearchar_area (&sd->bl, clrtype & 0xffff);
- skill_gangsterparadise (sd, 0);
- map_delblock (&sd->bl);
- memcpy (sd->mapname, mapname, 24);
+ skill_stop_dancing(&sd->bl, 1);
+ clif_clearchar(&sd->bl, clrtype);
+ skill_gangsterparadise(sd, 0);
+ map_delblock(&sd->bl);
+ memcpy(sd->mapname, mapname, 24);
sd->bl.x = x;
sd->bl.y = y;
sd->state.waitingdisconnect = 1;
- pc_makesavestatus (sd);
+ pc_makesavestatus(sd);
//The storage close routines save the char data. [Skotlex]
- if (!sd->state.storage_flag)
- chrif_save (sd);
- else if (sd->state.storage_flag == 1)
- storage_storage_quit (sd);
- else if (sd->state.storage_flag == 2)
- storage_guild_storage_quit (sd, 1);
-
- chrif_changemapserver (sd, mapname, x, y, ip, port);
+ if (!sd->state.storage_open)
+ chrif_save(sd);
+ else if (sd->state.storage_open)
+ storage_storage_quit(sd);
+
+ chrif_changemapserver(sd, mapname, x, y, ip, port);
return 0;
}
}
#if 0
- clif_authfail_fd (sd->fd, 0); // cancel
- clif_setwaitclose (sd->fd);
+ clif_authfail_fd(sd->fd, 0); // cancel
+ clif_setwaitclose(sd->fd);
#endif
return 1;
}
if (x < 0 || x >= map[m].xs || y < 0 || y >= map[m].ys)
x = y = 0;
- if ((x == 0 && y == 0) || (c = read_gat (m, x, y)) == 1 || c == 5)
+ if ((x == 0 && y == 0)
+ || bool(read_gat(m, x, y) & MapCell::UNWALKABLE))
{
if (x || y)
{
if (battle_config.error_log)
- printf ("stacked (%d,%d)\n", x, y);
+ PRINTF("stacked (%d,%d)\n", x, y);
}
do
{
- x = MRAND (map[m].xs - 2) + 1;
- y = MRAND (map[m].ys - 2) + 1;
+ x = random_::in(1, map[m].xs - 2);
+ y = random_::in(1, map[m].ys - 2);
}
- while ((c = read_gat (m, x, y)) == 1 || c == 5);
+ while (bool(read_gat(m, x, y) & MapCell::UNWALKABLE));
}
if (sd->mapname[0] && sd->bl.prev != NULL)
{
- skill_unit_out_all (&sd->bl, gettick (), 1);
- clif_clearchar_area (&sd->bl, clrtype & 0xffff);
- skill_gangsterparadise (sd, 0);
- map_delblock (&sd->bl);
- clif_changemap (sd, map[m].name, x, y); // [MouseJstr]
+ clif_clearchar(&sd->bl, clrtype);
+ skill_gangsterparadise(sd, 0);
+ map_delblock(&sd->bl);
+ clif_changemap(sd, map[m].name, x, y); // [MouseJstr]
}
- if (disguise) // disguise teleport fix [Valaris]
- sd->disguise = disguise;
-
- memcpy (sd->mapname, mapname, 24);
+ memcpy(sd->mapname, mapname, 24);
sd->bl.m = m;
sd->to_x = x;
sd->to_y = y;
@@ -4214,12 +2468,12 @@ int pc_setpos (struct map_session_data *sd, const char *mapname_org, int x, int
* PCã®ãƒ©ãƒ³ãƒ€ãƒ ãƒ¯ãƒ¼ãƒ—
*------------------------------------------
*/
-int pc_randomwarp (struct map_session_data *sd, int type)
+int pc_randomwarp(struct map_session_data *sd, BeingRemoveWhy type)
{
- int x, y, c, i = 0;
- int m;
+ int x, y, i = 0;
+ int m;
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
m = sd->bl.m;
@@ -4228,87 +2482,28 @@ int pc_randomwarp (struct map_session_data *sd, int type)
do
{
- x = MRAND (map[m].xs - 2) + 1;
- y = MRAND (map[m].ys - 2) + 1;
+ x = random_::in(1, map[m].xs - 2);
+ y = random_::in(1, map[m].ys - 2);
}
- while (((c = read_gat (m, x, y)) == 1 || c == 5) && (i++) < 1000);
+ while (bool(read_gat(m, x, y) & MapCell::UNWALKABLE)
+ && (i++) < 1000);
if (i < 1000)
- pc_setpos (sd, map[m].name, x, y, type);
+ pc_setpos(sd, map[m].name, x, y, type);
return 0;
}
/*==========================================
- * ç¾åœ¨ä½ç½®ã®ãƒ¡ãƒ¢
- *------------------------------------------
- */
-int pc_memo (struct map_session_data *sd, int i)
-{
- int skill;
- int j;
-
- nullpo_retr (0, sd);
-
- skill = pc_checkskill (sd, AL_WARP);
-
- if (i >= MIN_PORTAL_MEMO)
- i -= MIN_PORTAL_MEMO;
- else if (map[sd->bl.m].flag.nomemo
- || (map[sd->bl.m].flag.nowarpto
- && battle_config.any_warp_GM_min_level > pc_isGM (sd)))
- {
- clif_skill_teleportmessage (sd, 1);
- return 0;
- }
-
- if (skill < 1)
- {
- clif_skill_memo (sd, 2);
- }
-
- if (skill < 2 || i < -1 || i > 2)
- {
- clif_skill_memo (sd, 1);
- return 0;
- }
-
- for (j = 0; j < 3; j++)
- {
- if (strcmp (sd->status.memo_point[j].map, map[sd->bl.m].name) == 0)
- {
- i = j;
- break;
- }
- }
-
- if (i == -1)
- {
- for (i = skill - 3; i >= 0; i--)
- {
- memcpy (&sd->status.memo_point[i + 1], &sd->status.memo_point[i],
- sizeof (struct point));
- }
- i = 0;
- }
- memcpy (sd->status.memo_point[i].map, map[sd->bl.m].name, 24);
- sd->status.memo_point[i].x = sd->bl.x;
- sd->status.memo_point[i].y = sd->bl.y;
-
- clif_skill_memo (sd, 0);
-
- return 1;
-}
-
-/*==========================================
*
*------------------------------------------
*/
-int pc_can_reach (struct map_session_data *sd, int x, int y)
+static
+int pc_can_reach(struct map_session_data *sd, int x, int y)
{
struct walkpath_data wpd;
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
if (sd->bl.x == x && sd->bl.y == y) // åŒã˜ãƒžã‚¹
return 1;
@@ -4317,7 +2512,7 @@ int pc_can_reach (struct map_session_data *sd, int x, int y)
wpd.path_len = 0;
wpd.path_pos = 0;
wpd.path_half = 0;
- return (path_search (&wpd, sd->bl.m, sd->bl.x, sd->bl.y, x, y, 0) !=
+ return (path_search(&wpd, sd->bl.m, sd->bl.x, sd->bl.y, x, y, 0) !=
-1) ? 1 : 0;
}
@@ -4328,13 +2523,14 @@ int pc_can_reach (struct map_session_data *sd, int x, int y)
* 次ã®1æ­©ã«ã‹ã‹ã‚‹æ™‚間を計算
*------------------------------------------
*/
-static int calc_next_walk_step (struct map_session_data *sd)
+static
+interval_t calc_next_walk_step(struct map_session_data *sd)
{
- nullpo_retr (0, sd);
+ nullpo_retr(interval_t::zero(), sd);
if (sd->walkpath.path_pos >= sd->walkpath.path_len)
- return -1;
- if (sd->walkpath.path[sd->walkpath.path_pos] & 1)
+ return static_cast<interval_t>(-1);
+ if (dir_is_diagonal(sd->walkpath.path[sd->walkpath.path_pos]))
return sd->speed * 14 / 10;
return sd->speed;
@@ -4344,136 +2540,119 @@ static int calc_next_walk_step (struct map_session_data *sd)
* åŠæ­©é€²ã‚€(timer関数)
*------------------------------------------
*/
-static void pc_walk (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data)
+static
+void pc_walk(TimerData *, tick_t tick, int id, unsigned char data)
{
struct map_session_data *sd;
- int i, ctype;
- int moveblock;
- int x, y, dx, dy;
+ int moveblock;
+ int x, y, dx, dy;
- sd = map_id2sd (id);
+ sd = map_id2sd(id);
if (sd == NULL)
return;
- if (sd->walktimer != tid)
- {
- if (battle_config.error_log)
- printf ("pc_walk %d != %d\n", sd->walktimer, tid);
- return;
- }
- sd->walktimer = -1;
if (sd->walkpath.path_pos >= sd->walkpath.path_len
|| sd->walkpath.path_pos != data)
return;
- //æ­©ã„ãŸã®ã§æ¯å¹ã®ã‚¿ã‚¤ãƒžãƒ¼ã‚’åˆæœŸåŒ–
- sd->inchealspirithptick = 0;
- sd->inchealspiritsptick = 0;
-
sd->walkpath.path_half ^= 1;
if (sd->walkpath.path_half == 0)
{ // マス目中心ã¸åˆ°ç€
sd->walkpath.path_pos++;
if (sd->state.change_walk_target)
{
- pc_walktoxy_sub (sd);
+ pc_walktoxy_sub(sd);
return;
}
}
else
{ // マス目境界ã¸åˆ°ç€
- if (sd->walkpath.path[sd->walkpath.path_pos] >= 8)
+ if (sd->walkpath.path[sd->walkpath.path_pos] >= DIR::COUNT)
return;
x = sd->bl.x;
y = sd->bl.y;
- ctype = map_getcell (sd->bl.m, x, y);
- if (ctype == 1 || ctype == 5)
+ if (bool(map_getcell(sd->bl.m, x, y) & MapCell::UNWALKABLE))
{
- pc_stop_walking (sd, 1);
+ pc_stop_walking(sd, 1);
return;
}
sd->dir = sd->head_dir = sd->walkpath.path[sd->walkpath.path_pos];
- dx = dirx[(int) sd->dir];
- dy = diry[(int) sd->dir];
- ctype = map_getcell (sd->bl.m, x + dx, y + dy);
- if (ctype == 1 || ctype == 5)
+ dx = dirx[sd->dir];
+ dy = diry[sd->dir];
+ if (bool(map_getcell(sd->bl.m, x + dx, y + dy)
+ & MapCell::UNWALKABLE))
{
- pc_walktoxy_sub (sd);
+ pc_walktoxy_sub(sd);
return;
}
moveblock = (x / BLOCK_SIZE != (x + dx) / BLOCK_SIZE
|| y / BLOCK_SIZE != (y + dy) / BLOCK_SIZE);
- sd->walktimer = 1;
- map_foreachinmovearea (clif_pcoutsight, sd->bl.m, x - AREA_SIZE,
- y - AREA_SIZE, x + AREA_SIZE, y + AREA_SIZE,
- dx, dy, 0, sd);
+ // sd->walktimer = dummy value that is not nullptr;
+ map_foreachinmovearea(std::bind(clif_pcoutsight, ph::_1, sd),
+ sd->bl.m, x - AREA_SIZE, y - AREA_SIZE,
+ x + AREA_SIZE, y + AREA_SIZE,
+ dx, dy,
+ BL::NUL);
x += dx;
y += dy;
if (moveblock)
- map_delblock (&sd->bl);
+ map_delblock(&sd->bl);
sd->bl.x = x;
sd->bl.y = y;
if (moveblock)
- map_addblock (&sd->bl);
+ map_addblock(&sd->bl);
- if (sd->sc_data[SC_DANCING].timer != -1)
- skill_unit_move_unit_group ((struct skill_unit_group *)
- sd->sc_data[SC_DANCING].val2,
- sd->bl.m, dx, dy);
-
- map_foreachinmovearea (clif_pcinsight, sd->bl.m, x - AREA_SIZE,
- y - AREA_SIZE, x + AREA_SIZE, y + AREA_SIZE,
- -dx, -dy, 0, sd);
- sd->walktimer = -1;
+ map_foreachinmovearea(std::bind(clif_pcinsight, ph::_1, sd),
+ sd->bl.m, x - AREA_SIZE, y - AREA_SIZE,
+ x + AREA_SIZE, y + AREA_SIZE,
+ -dx, -dy,
+ BL::NUL);
+ // sd->walktimer = nullptr;
if (sd->status.party_id > 0)
{ // パーティã®ï¼¨ï¼°æƒ…報通知検査
- struct party *p = party_search (sd->status.party_id);
+ struct party *p = party_search(sd->status.party_id);
if (p != NULL)
{
- int p_flag = 0;
- map_foreachinmovearea (party_send_hp_check, sd->bl.m,
- x - AREA_SIZE, y - AREA_SIZE,
- x + AREA_SIZE, y + AREA_SIZE, -dx, -dy,
- BL_PC, sd->status.party_id, &p_flag);
+ int p_flag = 0;
+ map_foreachinmovearea(std::bind(party_send_hp_check, ph::_1, sd->status.party_id, &p_flag),
+ sd->bl.m, x - AREA_SIZE, y - AREA_SIZE,
+ x + AREA_SIZE, y + AREA_SIZE,
+ -dx, -dy,
+ BL::PC);
if (p_flag)
sd->party_hp = -1;
}
}
- if (sd->status.option & 4) // クローキングã®æ¶ˆæ»…検査
- skill_check_cloaking (&sd->bl);
+
// ディボーション検査
- for (i = 0; i < 5; i++)
+ for (int i = 0; i < 5; i++)
if (sd->dev.val1[i])
{
- skill_devotion3 (&sd->bl, sd->dev.val1[i]);
+ skill_devotion3(&sd->bl, sd->dev.val1[i]);
break;
}
- // 被ディボーション検査
- if (sd->sc_data && sd->sc_data[SC_DEVOTION].val1)
- {
- skill_devotion2 (&sd->bl, sd->sc_data[SC_DEVOTION].val1);
- }
-
- skill_unit_move (&sd->bl, tick, 1); // スキルユニットã®æ¤œæŸ»
- if (map_getcell (sd->bl.m, x, y) & 0x80)
- npc_touch_areanpc (sd, sd->bl.m, x, y);
+ if (bool(map_getcell(sd->bl.m, x, y) & MapCell::NPC_NEAR))
+ npc_touch_areanpc(sd, sd->bl.m, x, y);
else
sd->areanpc_id = 0;
}
- if ((i = calc_next_walk_step (sd)) > 0)
+ interval_t i = calc_next_walk_step(sd);
+ if (i > interval_t::zero())
{
- i = i >> 1;
- if (i < 1 && sd->walkpath.path_half == 0)
- i = 1;
- sd->walktimer =
- add_timer (tick + i, pc_walk, id, sd->walkpath.path_pos);
+ i = i / 2;
+ if (sd->walkpath.path_half == 0)
+ i = std::max(i, std::chrono::milliseconds(1));
+
+ sd->walktimer = Timer(tick + i,
+ std::bind(pc_walk, ph::_1, ph::_2,
+ id, sd->walkpath.path_pos));
}
}
@@ -4481,27 +2660,29 @@ static void pc_walk (timer_id tid, tick_t tick, custom_id_t id, custom_data_t da
* 移動å¯èƒ½ã‹ç¢ºèªã—ã¦ã€å¯èƒ½ãªã‚‰æ­©è¡Œé–‹å§‹
*------------------------------------------
*/
-static int pc_walktoxy_sub (struct map_session_data *sd)
+static
+int pc_walktoxy_sub(struct map_session_data *sd)
{
struct walkpath_data wpd;
- int i;
- nullpo_retr (1, sd);
+ nullpo_retr(1, sd);
- if (path_search
- (&wpd, sd->bl.m, sd->bl.x, sd->bl.y, sd->to_x, sd->to_y, 0))
+ if (path_search(&wpd, sd->bl.m, sd->bl.x, sd->bl.y, sd->to_x, sd->to_y, 0))
return 1;
- memcpy (&sd->walkpath, &wpd, sizeof (wpd));
+ memcpy(&sd->walkpath, &wpd, sizeof(wpd));
- clif_walkok (sd);
+ clif_walkok(sd);
sd->state.change_walk_target = 0;
- if ((i = calc_next_walk_step (sd)) > 0)
+ interval_t i = calc_next_walk_step(sd);
+ if (i > interval_t::zero())
{
- i = i >> 2;
- sd->walktimer = add_timer (gettick () + i, pc_walk, sd->bl.id, 0);
+ i = i / 4;
+ sd->walktimer = Timer(gettick() + i,
+ std::bind(pc_walk, ph::_1, ph::_2,
+ sd->bl.id, 0));
}
- clif_movechar (sd);
+ clif_movechar(sd);
return 0;
}
@@ -4510,18 +2691,18 @@ static int pc_walktoxy_sub (struct map_session_data *sd)
* pcæ­© è¡Œè¦æ±‚
*------------------------------------------
*/
-int pc_walktoxy (struct map_session_data *sd, int x, int y)
+int pc_walktoxy(struct map_session_data *sd, int x, int y)
{
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
sd->to_x = x;
sd->to_y = y;
- if (pc_issit (sd))
- pc_setstand (sd);
+ if (pc_issit(sd))
+ pc_setstand(sd);
- if (sd->walktimer != -1 && sd->state.change_walk_target == 0)
+ if (sd->walktimer && sd->state.change_walk_target == 0)
{
// ç¾åœ¨æ­©ã„ã¦ã„る最中ã®ç›®çš„地変更ãªã®ã§ãƒžã‚¹ç›®ã®ä¸­å¿ƒã«æ¥ãŸæ™‚ã«
// timer関数ã‹ã‚‰pc_walktoxy_subを呼ã¶ã‚ˆã†ã«ã™ã‚‹
@@ -4529,7 +2710,7 @@ int pc_walktoxy (struct map_session_data *sd, int x, int y)
}
else
{
- pc_walktoxy_sub (sd);
+ pc_walktoxy_sub(sd);
}
return 0;
@@ -4539,24 +2720,21 @@ int pc_walktoxy (struct map_session_data *sd, int x, int y)
* æ­© è¡Œåœæ­¢
*------------------------------------------
*/
-int pc_stop_walking (struct map_session_data *sd, int type)
+int pc_stop_walking(struct map_session_data *sd, int type)
{
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
+
+ sd->walktimer.cancel();
- if (sd->walktimer != -1)
- {
- delete_timer (sd->walktimer, pc_walk);
- sd->walktimer = -1;
- }
sd->walkpath.path_len = 0;
sd->to_x = sd->bl.x;
sd->to_y = sd->bl.y;
if (type & 0x01)
- clif_fixpos (&sd->bl);
+ clif_fixpos(&sd->bl);
if (type & 0x02 && battle_config.pc_damage_delay)
{
- unsigned int tick = gettick ();
- int delay = battle_get_dmotion (&sd->bl);
+ tick_t tick = gettick();
+ interval_t delay = battle_get_dmotion(&sd->bl);
if (sd->canmove_tick < tick)
sd->canmove_tick = tick + delay;
}
@@ -4564,10 +2742,10 @@ int pc_stop_walking (struct map_session_data *sd, int type)
return 0;
}
-void pc_touch_all_relevant_npcs (struct map_session_data *sd)
+void pc_touch_all_relevant_npcs(struct map_session_data *sd)
{
- if (map_getcell (sd->bl.m, sd->bl.x, sd->bl.y) & 0x80)
- npc_touch_areanpc (sd, sd->bl.m, sd->bl.x, sd->bl.y);
+ if (bool(map_getcell(sd->bl.m, sd->bl.x, sd->bl.y) & MapCell::NPC_NEAR))
+ npc_touch_areanpc(sd, sd->bl.m, sd->bl.x, sd->bl.y);
else
sd->areanpc_id = 0;
}
@@ -4576,64 +2754,62 @@ void pc_touch_all_relevant_npcs (struct map_session_data *sd)
*
*------------------------------------------
*/
-int pc_movepos (struct map_session_data *sd, int dst_x, int dst_y)
+int pc_movepos(struct map_session_data *sd, int dst_x, int dst_y)
{
- int moveblock;
- int dx, dy, dist;
+ int moveblock;
+ int dx, dy;
struct walkpath_data wpd;
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
- if (path_search (&wpd, sd->bl.m, sd->bl.x, sd->bl.y, dst_x, dst_y, 0))
+ if (path_search(&wpd, sd->bl.m, sd->bl.x, sd->bl.y, dst_x, dst_y, 0))
return 1;
- sd->dir = sd->head_dir = map_calc_dir (&sd->bl, dst_x, dst_y);
+ sd->dir = sd->head_dir = map_calc_dir(&sd->bl, dst_x, dst_y);
dx = dst_x - sd->bl.x;
dy = dst_y - sd->bl.y;
- dist = distance (sd->bl.x, sd->bl.y, dst_x, dst_y);
moveblock = (sd->bl.x / BLOCK_SIZE != dst_x / BLOCK_SIZE
|| sd->bl.y / BLOCK_SIZE != dst_y / BLOCK_SIZE);
- map_foreachinmovearea (clif_pcoutsight, sd->bl.m, sd->bl.x - AREA_SIZE,
- sd->bl.y - AREA_SIZE, sd->bl.x + AREA_SIZE,
- sd->bl.y + AREA_SIZE, dx, dy, 0, sd);
+ map_foreachinmovearea(std::bind(clif_pcoutsight, ph::_1, sd),
+ sd->bl.m, sd->bl.x - AREA_SIZE, sd->bl.y - AREA_SIZE,
+ sd->bl.x + AREA_SIZE, sd->bl.y + AREA_SIZE,
+ dx, dy,
+ BL::NUL);
if (moveblock)
- map_delblock (&sd->bl);
+ map_delblock(&sd->bl);
sd->bl.x = dst_x;
sd->bl.y = dst_y;
if (moveblock)
- map_addblock (&sd->bl);
+ map_addblock(&sd->bl);
- map_foreachinmovearea (clif_pcinsight, sd->bl.m, sd->bl.x - AREA_SIZE,
- sd->bl.y - AREA_SIZE, sd->bl.x + AREA_SIZE,
- sd->bl.y + AREA_SIZE, -dx, -dy, 0, sd);
+ map_foreachinmovearea(std::bind(clif_pcinsight, ph::_1, sd),
+ sd->bl.m, sd->bl.x - AREA_SIZE, sd->bl.y - AREA_SIZE,
+ sd->bl.x + AREA_SIZE, sd->bl.y + AREA_SIZE,
+ -dx, -dy,
+ BL::NUL);
if (sd->status.party_id > 0)
{ // パーティã®ï¼¨ï¼°æƒ…報通知検査
- struct party *p = party_search (sd->status.party_id);
+ struct party *p = party_search(sd->status.party_id);
if (p != NULL)
{
- int flag = 0;
- map_foreachinmovearea (party_send_hp_check, sd->bl.m,
- sd->bl.x - AREA_SIZE, sd->bl.y - AREA_SIZE,
- sd->bl.x + AREA_SIZE, sd->bl.y + AREA_SIZE,
- -dx, -dy, BL_PC, sd->status.party_id,
- &flag);
+ int flag = 0;
+ map_foreachinmovearea(std::bind(party_send_hp_check, ph::_1, sd->status.party_id, &flag),
+ sd->bl.m, sd->bl.x - AREA_SIZE, sd->bl.y - AREA_SIZE,
+ sd->bl.x + AREA_SIZE, sd->bl.y + AREA_SIZE,
+ -dx, -dy,
+ BL::PC);
if (flag)
sd->party_hp = -1;
}
}
- if (sd->status.option & 4) // クローキングã®æ¶ˆæ»…検査
- skill_check_cloaking (&sd->bl);
-
- skill_unit_move (&sd->bl, gettick (), dist + 7); // スキルユニットã®æ¤œæŸ»
-
- pc_touch_all_relevant_npcs (sd);
+ pc_touch_all_relevant_npcs(sd);
return 0;
}
@@ -4644,114 +2820,25 @@ int pc_movepos (struct map_session_data *sd, int dst_x, int dst_y)
* スキルã®æ¤œç´¢ 所有ã—ã¦ã„ãŸå ´åˆLvãŒè¿”ã‚‹
*------------------------------------------
*/
-int pc_checkskill (struct map_session_data *sd, int skill_id)
+int pc_checkskill(struct map_session_data *sd, SkillID skill_id)
{
if (sd == NULL)
return 0;
- if (skill_id >= 10000)
- {
- struct guild *g;
- if (sd->status.guild_id > 0
- && (g = guild_search (sd->status.guild_id)) != NULL)
- return guild_checkskill (g, skill_id);
- return 0;
- }
- if (sd->status.skill[skill_id].id == skill_id)
- return (sd->status.skill[skill_id].lv);
-
- return 0;
-}
-
-/*==========================================
- * 武器変更ã«ã‚ˆã‚‹ã‚¹ã‚­ãƒ«ã®ç¶™ç¶šãƒã‚§ãƒƒã‚¯
- * 引数:
- * struct map_session_data *sd セッションデータ
- * int nameid 装備å“ID
- * 返り値:
- * 0 変更ãªã—
- * -1 スキルを解除
- *------------------------------------------
- */
-int pc_checkallowskill (struct map_session_data *sd)
-{
- nullpo_retr (0, sd);
-
- if (sd->sc_data == NULL)
- return 0;
-
- if (!(skill_get_weapontype (KN_TWOHANDQUICKEN) & (1 << sd->status.weapon))
- && sd->sc_data[SC_TWOHANDQUICKEN].timer != -1)
- { // 2HQ
- skill_status_change_end (&sd->bl, SC_TWOHANDQUICKEN, -1); // 2HQを解除
- return -1;
- }
- if (!(skill_get_weapontype (LK_AURABLADE) & (1 << sd->status.weapon))
- && sd->sc_data[SC_AURABLADE].timer != -1)
- { // オーラブレード
- skill_status_change_end (&sd->bl, SC_AURABLADE, -1); // オーラブレードを解除
- return -1;
- }
- if (!(skill_get_weapontype (LK_PARRYING) & (1 << sd->status.weapon))
- && sd->sc_data[SC_PARRYING].timer != -1)
- { // パリイング
- skill_status_change_end (&sd->bl, SC_PARRYING, -1); // パリイングを解除
- return -1;
- }
- if (!(skill_get_weapontype (LK_CONCENTRATION) & (1 << sd->status.weapon))
- && sd->sc_data[SC_CONCENTRATION].timer != -1)
- { // コンセントレーション
- skill_status_change_end (&sd->bl, SC_CONCENTRATION, -1); // コンセントレーションを解除
- return -1;
- }
- if (!(skill_get_weapontype (CR_SPEARQUICKEN) & (1 << sd->status.weapon))
- && sd->sc_data[SC_SPEARSQUICKEN].timer != -1)
- { // スピアクィッケン
- skill_status_change_end (&sd->bl, SC_SPEARSQUICKEN, -1); // スピアクイッケンを解除
- return -1;
- }
- if (!(skill_get_weapontype (BS_ADRENALINE) & (1 << sd->status.weapon))
- && sd->sc_data[SC_ADRENALINE].timer != -1)
- { // アドレナリンラッシュ
- skill_status_change_end (&sd->bl, SC_ADRENALINE, -1); // アドレナリンラッシュを解除
- return -1;
- }
-
- if (sd->status.shield <= 0)
- {
- if (sd->sc_data[SC_AUTOGUARD].timer != -1)
- { // オートガード
- skill_status_change_end (&sd->bl, SC_AUTOGUARD, -1);
- return -1;
- }
- if (sd->sc_data[SC_DEFENDER].timer != -1)
- { // ディフェンダー
- skill_status_change_end (&sd->bl, SC_DEFENDER, -1);
- return -1;
- }
- if (sd->sc_data[SC_REFLECTSHIELD].timer != -1)
- { //リフレクトシールド
- skill_status_change_end (&sd->bl, SC_REFLECTSHIELD, -1);
- return -1;
- }
- }
-
- return 0;
+ return sd->status.skill[skill_id].lv;
}
/*==========================================
* 装 å‚™å“ã®ãƒã‚§ãƒƒã‚¯
*------------------------------------------
*/
-int pc_checkequip (struct map_session_data *sd, int pos)
+int pc_checkequip(struct map_session_data *sd, EPOS pos)
{
- int i;
-
- nullpo_retr (-1, sd);
+ nullpo_retr(-1, sd);
- for (i = 0; i < 11; i++)
+ for (EQUIP i : EQUIPs)
{
- if (pos & equip_pos[i])
+ if (bool(pos & equip_pos[i]))
return sd->equip_index[i];
}
@@ -4759,120 +2846,49 @@ int pc_checkequip (struct map_session_data *sd, int pos)
}
/*==========================================
- * 転生è·ã‚„養å­è·ã®å…ƒã®è·æ¥­ã‚’è¿”ã™
- *------------------------------------------
- */
-struct pc_base_job pc_calc_base_job (int b_class)
-{
- struct pc_base_job bj;
- //転生や養å­ã®å ´åˆã®å…ƒã®è·æ¥­ã‚’算出ã™ã‚‹
- if (b_class < MAX_PC_CLASS)
- { //通常
- bj.job = b_class;
- bj.upper = 0;
- }
- else if (b_class >= 4001 && b_class < 4023)
- { //転生è·
- bj.job = b_class - 4001;
- bj.upper = 1;
- }
- else if (b_class == 23 + 4023 - 1)
- { //養å­ã‚¹ãƒ‘ノビ
- bj.job = b_class - (4023 - 1);
- bj.upper = 2;
- }
- else
- { //養å­ã‚¹ãƒ‘ノビ以外ã®é¤Šå­
- bj.job = b_class - 4023;
- bj.upper = 2;
- }
-
- if (battle_config.enable_upper_class == 0)
- { //confã§ç„¡åŠ¹ã«ãªã£ã¦ã„ãŸã‚‰upper=0
- bj.upper = 0;
- }
-
- if (bj.job == 0)
- {
- bj.type = 0;
- }
- else if (bj.job < 7)
- {
- bj.type = 1;
- }
- else
- {
- bj.type = 2;
- }
-
- return bj;
-}
-
-/*==========================================
* PCã®æ”»æ’ƒ (timer関数)
*------------------------------------------
*/
static
-void pc_attack_timer (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data)
+void pc_attack_timer(TimerData *, tick_t tick, int id)
{
struct map_session_data *sd;
struct block_list *bl;
- struct status_change *sc_data;
- short *opt;
- int dist, skill, range;
- int attack_spell_delay;
+ eptr<struct status_change, StatusChange> sc_data;
+ int dist, range;
- sd = map_id2sd (id);
+ sd = map_id2sd(id);
if (sd == NULL)
return;
- if (sd->attacktimer != tid)
- {
- if (battle_config.error_log)
- printf ("pc_attack_timer %d != %d\n", sd->attacktimer, tid);
- return;
- }
- sd->attacktimer = -1;
if (sd->bl.prev == NULL)
return;
- bl = map_id2bl (sd->attacktarget);
+ bl = map_id2bl(sd->attacktarget);
if (bl == NULL || bl->prev == NULL)
return;
- if (bl->type == BL_PC && pc_isdead ((struct map_session_data *) bl))
+ if (bl->type == BL::PC && pc_isdead((struct map_session_data *) bl))
return;
// åŒã˜mapã§ãªã„ãªã‚‰æ”»æ’ƒã—ãªã„
// PCãŒæ­»ã‚“ã§ã¦ã‚‚攻撃ã—ãªã„
- if (sd->bl.m != bl->m || pc_isdead (sd))
+ if (sd->bl.m != bl->m || pc_isdead(sd))
return;
- if (sd->opt1 > 0 || sd->status.option & 2 || sd->status.option & 16388) // 異常ãªã©ã§æ”»æ’ƒã§ããªã„
+ // 異常ãªã©ã§æ”»æ’ƒã§ããªã„
+ if (sd->opt1 != Opt1::ZERO)
return;
- if (sd->sc_data[SC_AUTOCOUNTER].timer != -1)
- return;
- if (sd->sc_data[SC_BLADESTOP].timer != -1)
+ Option *opt = battle_get_option(bl);
+ if (opt != NULL && bool(*opt & Option::REAL_ANY_HIDE))
return;
- if ((opt = battle_get_option (bl)) != NULL && *opt & 0x46)
- 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;
-
- if (sd->skilltimer != -1 && pc_checkskill (sd, SA_FREECAST) <= 0)
- return;
-
- if (!battle_config.sdelay_attack_enable
- && pc_checkskill (sd, SA_FREECAST) <= 0)
+ if (!battle_config.sdelay_attack_enable)
{
- if (DIFF_TICK (tick, sd->canact_tick) < 0)
+ if (tick < sd->canact_tick)
{
- clif_skill_fail (sd, 1, 4, 0);
+ clif_skill_fail(sd, SkillID::ONE, 4, 0);
return;
}
}
@@ -4880,9 +2896,9 @@ void pc_attack_timer (timer_id tid, tick_t tick, custom_id_t id, custom_data_t d
if (sd->attackabletime > tick)
return; // cannot attack yet
- attack_spell_delay = sd->attack_spell_delay;
+ interval_t attack_spell_delay = sd->attack_spell_delay;
if (sd->attack_spell_override // [Fate] If we have an active attack spell, use that
- && spell_attack (id, sd->attacktarget))
+ && spell_attack(id, sd->attacktarget))
{
// Return if the spell succeeded. If the spell had disspiated, spell_attack() may fail.
sd->attackabletime = tick + attack_spell_delay;
@@ -4890,9 +2906,9 @@ void pc_attack_timer (timer_id tid, tick_t tick, custom_id_t id, custom_data_t d
}
else
{
- dist = distance (sd->bl.x, sd->bl.y, bl->x, bl->y);
+ dist = distance(sd->bl.x, sd->bl.y, bl->x, bl->y);
range = sd->attackrange;
- if (sd->status.weapon != 11)
+ if (sd->status.weapon != ItemLook::BOW)
range++;
if (dist > range)
{ // 届 ã‹ãªã„ã®ã§ç§»å‹•
@@ -4901,57 +2917,40 @@ void pc_attack_timer (timer_id tid, tick_t tick, custom_id_t id, custom_data_t d
return;
}
- if (dist <= range && !battle_check_range (&sd->bl, bl, range))
+ if (dist <= range && !battle_check_range(&sd->bl, bl, range))
{
- if (pc_can_reach (sd, bl->x, bl->y) && sd->canmove_tick < tick
- && (sd->sc_data[SC_ANKLE].timer == -1
- || sd->sc_data[SC_SPIDERWEB].timer == -1))
+ if (pc_can_reach(sd, bl->x, bl->y) && sd->canmove_tick < tick)
// TMW client doesn't support this
//pc_walktoxy(sd,bl->x,bl->y);
- clif_movetoattack (sd, bl);
- sd->attackabletime = tick + (sd->aspd << 1);
+ clif_movetoattack(sd, bl);
+ sd->attackabletime = tick + (sd->aspd * 2);
}
else
{
if (battle_config.pc_attack_direction_change)
- sd->dir = sd->head_dir = map_calc_dir (&sd->bl, bl->x, bl->y); // å‘ã設定
+ sd->dir = sd->head_dir = map_calc_dir(&sd->bl, bl->x, bl->y); // å‘ã設定
- if (sd->walktimer != -1)
- pc_stop_walking (sd, 1);
+ if (sd->walktimer)
+ pc_stop_walking(sd, 1);
- if (sd->sc_data[SC_COMBO].timer == -1)
{
- map_freeblock_lock ();
- pc_stop_walking (sd, 0);
+ map_freeblock_lock();
+ pc_stop_walking(sd, 0);
sd->attacktarget_lv =
- battle_weapon_attack (&sd->bl, bl, tick, 0);
- if (!(battle_config.pc_cloak_check_type & 2)
- && sd->sc_data[SC_CLOAKING].timer != -1)
- skill_status_change_end (&sd->bl, SC_CLOAKING, -1);
- map_freeblock_unlock ();
- if (sd->skilltimer != -1 && (skill = pc_checkskill (sd, SA_FREECAST)) > 0) // フリーキャスト
- sd->attackabletime =
- tick + ((sd->aspd << 1) * (150 - skill * 5) / 100);
- else
- sd->attackabletime = tick + (sd->aspd << 1);
- }
- else if (sd->attackabletime <= tick)
- {
- if (sd->skilltimer != -1 && (skill = pc_checkskill (sd, SA_FREECAST)) > 0) // フリーキャスト
- sd->attackabletime =
- tick + ((sd->aspd << 1) * (150 - skill * 5) / 100);
- else
- sd->attackabletime = tick + (sd->aspd << 1);
+ battle_weapon_attack(&sd->bl, bl, tick);
+ map_freeblock_unlock();
+ sd->attackabletime = tick + (sd->aspd * 2);
}
if (sd->attackabletime <= tick)
- sd->attackabletime = tick + (battle_config.max_aspd << 1);
+ sd->attackabletime = tick + static_cast<interval_t>(battle_config.max_aspd) * 2;
}
}
if (sd->state.attack_continue)
{
- sd->attacktimer =
- add_timer (sd->attackabletime, pc_attack_timer, sd->bl.id, 0);
+ sd->attacktimer = Timer(sd->attackabletime,
+ std::bind(pc_attack_timer, ph::_1, ph::_2,
+ sd->bl.id));
}
}
@@ -4960,40 +2959,40 @@ void pc_attack_timer (timer_id tid, tick_t tick, custom_id_t id, custom_data_t d
* typeãŒ1ãªã‚‰ç¶™ç¶šæ”»æ’ƒ
*------------------------------------------
*/
-int pc_attack (struct map_session_data *sd, int target_id, int type)
+int pc_attack(struct map_session_data *sd, int target_id, int type)
{
struct block_list *bl;
- int d;
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
- bl = map_id2bl (target_id);
+ bl = map_id2bl(target_id);
if (bl == NULL)
return 1;
- if (bl->type == BL_NPC)
+ if (bl->type == BL::NPC)
{ // monster npcs [Valaris]
- npc_click (sd, RFIFOL (sd->fd, 2));
+ npc_click(sd, RFIFOL(sd->fd, 2));
return 0;
}
- if (!battle_check_target (&sd->bl, bl, BCT_ENEMY))
+ if (!battle_check_target(&sd->bl, bl, BCT_ENEMY))
return 1;
- if (sd->attacktimer != -1)
- pc_stopattack (sd);
+ if (sd->attacktimer)
+ pc_stopattack(sd);
sd->attacktarget = target_id;
sd->state.attack_continue = type;
- d = DIFF_TICK (sd->attackabletime, gettick ());
- if (d > 0 && d < 2000)
+ interval_t d = sd->attackabletime - gettick();
+ if (d > interval_t::zero() && d < std::chrono::seconds(2))
{ // 攻撃delay中
- sd->attacktimer =
- add_timer (sd->attackabletime, pc_attack_timer, sd->bl.id, 0);
+ sd->attacktimer = Timer(sd->attackabletime,
+ std::bind(pc_attack_timer, ph::_1, ph::_2,
+ sd->bl.id));
}
else
{
// 本æ¥timer関数ãªã®ã§å¼•æ•°ã‚’åˆã‚ã›ã‚‹
- pc_attack_timer (-1, gettick (), sd->bl.id, 0);
+ pc_attack_timer(nullptr, gettick(), sd->bl.id);
}
return 0;
@@ -5003,15 +3002,12 @@ int pc_attack (struct map_session_data *sd, int target_id, int type)
* 継続攻撃åœæ­¢
*------------------------------------------
*/
-int pc_stopattack (struct map_session_data *sd)
+int pc_stopattack(struct map_session_data *sd)
{
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
+
+ sd->attacktimer.cancel();
- if (sd->attacktimer != -1)
- {
- delete_timer (sd->attacktimer, pc_attack_timer);
- sd->attacktimer = -1;
- }
sd->attacktarget = 0;
sd->state.attack_continue = 0;
@@ -5019,158 +3015,71 @@ int pc_stopattack (struct map_session_data *sd)
}
static
-void pc_follow_timer (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data)
+int pc_checkbaselevelup(struct map_session_data *sd)
{
- struct map_session_data *sd, *bl;
-
- sd = map_id2sd (id);
- if (sd == NULL || sd->followtimer != tid)
- return;
-
- sd->followtimer = -1;
-
- do
- {
- if (sd->bl.prev == NULL)
- break;
-
- bl = (struct map_session_data *) map_id2bl (sd->followtarget);
-
- if (bl == NULL)
- return;
+ int next = pc_nextbaseexp(sd);
- if (bl->bl.prev == NULL)
- break;
-
- if (bl->bl.type == BL_PC
- && pc_isdead ((struct map_session_data *) bl))
- return;
-
- if (sd->skilltimer == -1 && sd->attacktimer == -1
- && sd->walktimer == -1)
- {
- if ((sd->bl.m == bl->bl.m)
- && pc_can_reach (sd, bl->bl.x, bl->bl.y))
- {
- if (distance (sd->bl.x, sd->bl.y, bl->bl.x, bl->bl.y) > 5)
- pc_walktoxy (sd, bl->bl.x, bl->bl.y);
- }
- else
- pc_setpos ((struct map_session_data *) sd, bl->mapname,
- bl->bl.x, bl->bl.y, 3);
- }
- }
- while (0);
-
- sd->followtimer =
- add_timer (tick + sd->aspd, pc_follow_timer, sd->bl.id, 0);
-}
-
-int pc_follow (struct map_session_data *sd, int target_id)
-{
- struct block_list *bl;
-
- bl = map_id2bl (target_id);
- if (bl == NULL)
- return 1;
- sd->followtarget = target_id;
- if (sd->followtimer != -1)
- {
- delete_timer (sd->followtimer, pc_follow_timer);
- sd->followtimer = -1;
- }
-
- pc_follow_timer (-1, gettick (), sd->bl.id, 0);
-
- return 0;
-}
-
-int pc_checkbaselevelup (struct map_session_data *sd)
-{
- int next = pc_nextbaseexp (sd);
-
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
if (sd->status.base_exp >= next && next > 0)
{
- struct pc_base_job s_class = pc_calc_base_job (sd->status.pc_class);
-
// baseå´ãƒ¬ãƒ™ãƒ«ã‚¢ãƒƒãƒ—処ç†
sd->status.base_exp -= next;
sd->status.base_level++;
sd->status.status_point += (sd->status.base_level + 14) / 4;
- clif_updatestatus (sd, SP_STATUSPOINT);
- clif_updatestatus (sd, SP_BASELEVEL);
- clif_updatestatus (sd, SP_NEXTBASEEXP);
- pc_calcstatus (sd, 0);
- pc_heal (sd, sd->status.max_hp, sd->status.max_sp);
-
- //スパノビã¯ã‚­ãƒªã‚¨ã€ã‚¤ãƒ ãƒã€ãƒžãƒ‹ãƒ”ã€ã‚°ãƒ­ã€ã‚µãƒ•ãƒ©Lv1ãŒã‹ã‹ã‚‹
- if (s_class.job == 23)
- {
- skill_status_change_start (&sd->bl,
- SkillStatusChangeTable[PR_KYRIE], 1, 0,
- 0, 0, skill_get_time (PR_KYRIE, 1), 0);
- skill_status_change_start (&sd->bl,
- SkillStatusChangeTable[PR_IMPOSITIO],
- 1, 0, 0, 0,
- skill_get_time (PR_IMPOSITIO, 1), 0);
- skill_status_change_start (&sd->bl,
- SkillStatusChangeTable[PR_MAGNIFICAT],
- 1, 0, 0, 0,
- skill_get_time (PR_MAGNIFICAT, 1), 0);
- skill_status_change_start (&sd->bl,
- SkillStatusChangeTable[PR_GLORIA], 1,
- 0, 0, 0, skill_get_time (PR_GLORIA, 1),
- 0);
- skill_status_change_start (&sd->bl,
- SkillStatusChangeTable[PR_SUFFRAGIUM],
- 1, 0, 0, 0,
- skill_get_time (PR_SUFFRAGIUM, 1), 0);
- }
+ clif_updatestatus(sd, SP::STATUSPOINT);
+ clif_updatestatus(sd, SP::BASELEVEL);
+ clif_updatestatus(sd, SP::NEXTBASEEXP);
+ pc_calcstatus(sd, 0);
+ pc_heal(sd, sd->status.max_hp, sd->status.max_sp);
- clif_misceffect (&sd->bl, 0);
+ clif_misceffect(&sd->bl, 0);
//レベルアップã—ãŸã®ã§ãƒ‘ーティー情報を更新ã™ã‚‹
//(公平範囲ãƒã‚§ãƒƒã‚¯)
- party_send_movemap (sd);
- MAP_LOG_XP (sd, "LEVELUP") return 1;
+ party_send_movemap(sd);
+ MAP_LOG_XP(sd, "LEVELUP");
+ return 1;
}
return 0;
}
+inline
+int RAISE_COST(int x)
+{
+ return (x * (x - 1)) / 2;
+}
+
/*========================================
* Compute the maximum for sd->skill_point, i.e., the max. number of skill points that can still be filled in
*----------------------------------------
*/
static
-int pc_skillpt_potential (struct map_session_data *sd)
+int pc_skillpt_potential(struct map_session_data *sd)
{
- int skill_id;
- int potential = 0;
-
-#define RAISE_COST(x) (((x)*((x)-1))>>1)
+ int potential = 0;
- for (skill_id = 0; skill_id < MAX_SKILL; skill_id++)
- if (sd->status.skill[skill_id].id != 0
+ for (SkillID skill_id = SkillID(); skill_id < MAX_SKILL;
+ skill_id = SkillID(uint16_t(skill_id) + 1))
+ if (sd->status.skill[skill_id].lv
&& sd->status.skill[skill_id].lv < skill_db[skill_id].max_raise)
- potential += RAISE_COST (skill_db[skill_id].max_raise)
- - RAISE_COST (sd->status.skill[skill_id].lv);
-#undef RAISE_COST
+ potential += RAISE_COST(skill_db[skill_id].max_raise)
+ - RAISE_COST(sd->status.skill[skill_id].lv);
return potential;
}
-int pc_checkjoblevelup (struct map_session_data *sd)
+static
+int pc_checkjoblevelup(struct map_session_data *sd)
{
- int next = pc_nextjobexp (sd);
+ int next = pc_nextjobexp(sd);
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
if (sd->status.job_exp >= next && next > 0)
{
- if (pc_skillpt_potential (sd) < sd->status.skill_point)
+ if (pc_skillpt_potential(sd) < sd->status.skill_point)
{ // [Fate] Bah, this is is painful.
// But the alternative is quite error-prone, and eAthena has far worse performance issues...
sd->status.job_exp = next - 1;
@@ -5180,70 +3089,51 @@ int pc_checkjoblevelup (struct map_session_data *sd)
// jobå´ãƒ¬ãƒ™ãƒ«ã‚¢ãƒƒãƒ—処ç†
sd->status.job_exp -= next;
- clif_updatestatus (sd, SP_NEXTJOBEXP);
+ clif_updatestatus(sd, SP::NEXTJOBEXP);
sd->status.skill_point++;
- clif_updatestatus (sd, SP_SKILLPOINT);
- pc_calcstatus (sd, 0);
+ clif_updatestatus(sd, SP::SKILLPOINT);
+ pc_calcstatus(sd, 0);
- MAP_LOG_PC (sd, "SKILLPOINTS-UP %d", sd->status.skill_point);
+ MAP_LOG_PC(sd, "SKILLPOINTS-UP %d", sd->status.skill_point);
if (sd->status.job_level < 250
&& sd->status.job_level < sd->status.base_level * 2)
sd->status.job_level++; // Make levelling up a little harder
- clif_misceffect (&sd->bl, 1);
+ clif_misceffect(&sd->bl, 1);
return 1;
}
return 0;
}
-/*==========================================
- * 経験値å–å¾—
- *------------------------------------------
- */
-int pc_gainexp (struct map_session_data *sd, int base_exp, int job_exp)
-{
- return pc_gainexp_reason (sd, base_exp, job_exp,
- PC_GAINEXP_REASON_KILLING);
-}
-
-int pc_gainexp_reason (struct map_session_data *sd, int base_exp, int job_exp,
- int reason)
+int pc_gainexp_reason(struct map_session_data *sd, int base_exp, int job_exp,
+ PC_GAINEXP_REASON reason)
{
- char output[256];
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
- if (sd->bl.prev == NULL || pc_isdead (sd))
+ if (sd->bl.prev == NULL || pc_isdead(sd))
return 0;
if ((battle_config.pvp_exp == 0) && map[sd->bl.m].flag.pvp) // [MouseJstr]
return 0; // no exp on pvp maps
- MAP_LOG_PC (sd, "GAINXP %d %d %s", base_exp, job_exp,
- ((reason ==
- 2) ? "SCRIPTXP" : ((reason == 1) ? "HEALXP" : "KILLXP")));
-
- if (sd->sc_data[SC_RICHMANKIM].timer != -1)
- { // added bounds checking [Vaalris]
- base_exp +=
- base_exp * (25 + sd->sc_data[SC_RICHMANKIM].val1 * 25) / 100;
- job_exp +=
- job_exp * (25 + sd->sc_data[SC_RICHMANKIM].val1 * 25) / 100;
- }
-
- if (sd->status.guild_id > 0)
- { // ギルドã«ä¸Šç´
- base_exp -= guild_payexp (sd, base_exp);
- if (base_exp < 0)
- base_exp = 0;
- }
-
- if (!battle_config.multi_level_up && pc_nextbaseafter (sd))
- {
- while (sd->status.base_exp + base_exp >= pc_nextbaseafter (sd)
- && sd->status.base_exp <= pc_nextbaseexp (sd)
- && pc_nextbaseafter (sd) > 0)
+ earray<const char *, PC_GAINEXP_REASON, PC_GAINEXP_REASON::COUNT> reasons //=
+ {{
+ "KILLXP",
+ "HEALXP",
+ "SCRIPTXP",
+ "SHAREXP",
+ /* Insert new types here */
+ "UNKNOWNXP"
+ }};
+ MAP_LOG_PC(sd, "GAINXP %d %d %s", base_exp, job_exp, reasons[reason]);
+
+ if (!battle_config.multi_level_up && pc_nextbaseafter(sd))
+ {
+ while (sd->status.base_exp + base_exp >= pc_nextbaseafter(sd)
+ && sd->status.base_exp <= pc_nextbaseexp(sd)
+ && pc_nextbaseafter(sd) > 0)
{
base_exp *= .90;
}
@@ -5252,7 +3142,7 @@ int pc_gainexp_reason (struct map_session_data *sd, int base_exp, int job_exp,
sd->status.base_exp += base_exp;
// [Fate] Adjust experience points that healers can extract from this character
- if (reason != PC_GAINEXP_REASON_HEALING)
+ if (reason != PC_GAINEXP_REASON::HEALING)
{
const int max_heal_xp =
20 + (sd->status.base_level * sd->status.base_level);
@@ -5265,14 +3155,14 @@ int pc_gainexp_reason (struct map_session_data *sd, int base_exp, int job_exp,
if (sd->status.base_exp < 0)
sd->status.base_exp = 0;
- while (pc_checkbaselevelup (sd));
+ while (pc_checkbaselevelup(sd));
- clif_updatestatus (sd, SP_BASEEXP);
- if (!battle_config.multi_level_up && pc_nextjobafter (sd))
+ clif_updatestatus(sd, SP::BASEEXP);
+ if (!battle_config.multi_level_up && pc_nextjobafter(sd))
{
- while (sd->status.job_exp + job_exp >= pc_nextjobafter (sd)
- && sd->status.job_exp <= pc_nextjobexp (sd)
- && pc_nextjobafter (sd) > 0)
+ while (sd->status.job_exp + job_exp >= pc_nextjobafter(sd)
+ && sd->status.job_exp <= pc_nextjobexp(sd)
+ && pc_nextjobafter(sd) > 0)
{
job_exp *= .90;
}
@@ -5282,24 +3172,25 @@ int pc_gainexp_reason (struct map_session_data *sd, int base_exp, int job_exp,
if (sd->status.job_exp < 0)
sd->status.job_exp = 0;
- while (pc_checkjoblevelup (sd));
+ while (pc_checkjoblevelup(sd));
- clif_updatestatus (sd, SP_JOBEXP);
+ clif_updatestatus(sd, SP::JOBEXP);
if (battle_config.disp_experience)
{
- sprintf (output,
- "Experienced Gained Base:%d Job:%d", base_exp, job_exp);
- clif_disp_onlyself (sd, output, strlen (output));
+ std::string output = STRPRINTF(
+ "Experienced Gained Base:%d Job:%d",
+ base_exp, job_exp);
+ clif_displaymessage(sd->fd, output);
}
return 0;
}
-int pc_extract_healer_exp (struct map_session_data *sd, int max)
+int pc_extract_healer_exp(struct map_session_data *sd, int max)
{
- int amount;
- nullpo_retr (0, sd);
+ int amount;
+ nullpo_ret(sd);
amount = sd->heal_xp;
if (max < amount)
@@ -5313,38 +3204,21 @@ int pc_extract_healer_exp (struct map_session_data *sd, int max)
* base levelå´å¿…è¦çµŒé¨“値計算
*------------------------------------------
*/
-int pc_nextbaseexp (struct map_session_data *sd)
+int pc_nextbaseexp(struct map_session_data *sd)
{
- int i;
-
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
if (sd->status.base_level >= MAX_LEVEL || sd->status.base_level <= 0)
return 0;
- if (sd->status.pc_class == 0)
- i = 0;
- else if (sd->status.pc_class <= 6)
- i = 1;
- else if (sd->status.pc_class <= 22)
- i = 2;
- else if (sd->status.pc_class == 23)
- i = 3;
- else if (sd->status.pc_class == 4001)
- i = 4;
- else if (sd->status.pc_class <= 4007)
- i = 5;
- else
- i = 6;
-
- return exp_table[i][sd->status.base_level - 1];
+ return exp_table_0[sd->status.base_level - 1];
}
/*==========================================
* job levelå´å¿…è¦çµŒé¨“値計算
*------------------------------------------
*/
-int pc_nextjobexp (struct map_session_data *sd)
+int pc_nextjobexp(struct map_session_data *sd)
{
// [fate] For normal levels, this ranges from 20k to 50k, depending on job level.
// Job level is at most twice the player's experience level (base_level). Levelling
@@ -5358,83 +3232,44 @@ int pc_nextjobexp (struct map_session_data *sd)
* base level after next [Valaris]
*------------------------------------------
*/
-int pc_nextbaseafter (struct map_session_data *sd)
+int pc_nextbaseafter(struct map_session_data *sd)
{
- int i;
-
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
if (sd->status.base_level >= MAX_LEVEL || sd->status.base_level <= 0)
return 0;
- if (sd->status.pc_class == 0)
- i = 0;
- else if (sd->status.pc_class <= 6)
- i = 1;
- else if (sd->status.pc_class <= 22)
- i = 2;
- else if (sd->status.pc_class == 23)
- i = 3;
- else if (sd->status.pc_class == 4001)
- i = 4;
- else if (sd->status.pc_class <= 4007)
- i = 5;
- else
- i = 6;
-
- return exp_table[i][sd->status.base_level];
+ return exp_table_0[sd->status.base_level];
}
/*==========================================
* job level after next [Valaris]
*------------------------------------------
*/
-int pc_nextjobafter (struct map_session_data *sd)
+int pc_nextjobafter(struct map_session_data *sd)
{
- int i;
-
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
if (sd->status.job_level >= MAX_LEVEL || sd->status.job_level <= 0)
return 0;
- if (sd->status.pc_class == 0)
- i = 7;
- else if (sd->status.pc_class <= 6)
- i = 8;
- else if (sd->status.pc_class <= 22)
- i = 9;
- else if (sd->status.pc_class == 23)
- i = 10;
- else if (sd->status.pc_class == 4001)
- i = 11;
- else if (sd->status.pc_class <= 4007)
- i = 12;
- else
- i = 13;
-
- return exp_table[i][sd->status.job_level];
+ return exp_table_7[sd->status.job_level];
}
/*==========================================
-
* å¿…è¦ã‚¹ãƒ†ãƒ¼ã‚¿ã‚¹ãƒã‚¤ãƒ³ãƒˆè¨ˆç®—
*------------------------------------------
*/
-int pc_need_status_point (struct map_session_data *sd, int type)
+// TODO: replace SP by ATTR
+int pc_need_status_point(struct map_session_data *sd, SP type)
{
- int val;
+ int val;
- nullpo_retr (-1, sd);
+ nullpo_retr(-1, sd);
- if (type < SP_STR || type > SP_LUK)
+ if (type < SP::STR || type > SP::LUK)
return -1;
- val =
- type == SP_STR ? sd->status.str :
- type == SP_AGI ? sd->status.agi :
- type == SP_VIT ? sd->status.vit :
- type == SP_INT ? sd->status.int_ :
- type == SP_DEX ? sd->status.dex : sd->status.luk;
+ val = sd->status.attrs[sp_to_attr(type)];
return (val + 9) / 10 + 1;
}
@@ -5443,75 +3278,36 @@ int pc_need_status_point (struct map_session_data *sd, int type)
* 能力値æˆé•·
*------------------------------------------
*/
-int pc_statusup (struct map_session_data *sd, int type)
+int pc_statusup(struct map_session_data *sd, SP type)
{
- int need, val = 0;
+ int need, val = 0;
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
- switch (type)
- {
- case SP_STR:
- val = sd->status.str;
- break;
- case SP_AGI:
- val = sd->status.agi;
- break;
- case SP_VIT:
- val = sd->status.vit;
- break;
- case SP_INT:
- val = sd->status.int_;
- break;
- case SP_DEX:
- val = sd->status.dex;
- break;
- case SP_LUK:
- val = sd->status.luk;
- break;
- }
+ if (SP::STR <= type && type <= SP::LUK)
+ val = sd->status.attrs[sp_to_attr(type)];
- need = pc_need_status_point (sd, type);
- if (type < SP_STR || type > SP_LUK || need < 0
+ need = pc_need_status_point(sd, type);
+ if (type < SP::STR || type > SP::LUK || need < 0
|| need > sd->status.status_point
|| val >= battle_config.max_parameter)
{
- clif_statusupack (sd, type, 0, val);
- clif_updatestatus (sd, SP_STATUSPOINT);
+ clif_statusupack(sd, type, 0, val);
+ clif_updatestatus(sd, SP::STATUSPOINT);
return 1;
}
- switch (type)
- {
- case SP_STR:
- val = ++sd->status.str;
- break;
- case SP_AGI:
- val = ++sd->status.agi;
- break;
- case SP_VIT:
- val = ++sd->status.vit;
- break;
- case SP_INT:
- val = ++sd->status.int_;
- break;
- case SP_DEX:
- val = ++sd->status.dex;
- break;
- case SP_LUK:
- val = ++sd->status.luk;
- break;
- }
+ val = ++sd->status.attrs[sp_to_attr(type)];
sd->status.status_point -= need;
- if (need != pc_need_status_point (sd, type))
+ if (need != pc_need_status_point(sd, type))
{
- clif_updatestatus (sd, type - SP_STR + SP_USTR);
+ clif_updatestatus(sd, sp_to_usp(type));
}
- clif_updatestatus (sd, SP_STATUSPOINT);
- clif_updatestatus (sd, type);
- pc_calcstatus (sd, 0);
- clif_statusupack (sd, type, 1, val);
+ clif_updatestatus(sd, SP::STATUSPOINT);
+ clif_updatestatus(sd, type);
+ pc_calcstatus(sd, 0);
+ clif_statusupack(sd, type, 1, val);
- MAP_LOG_STATS (sd, "STATUP");
+ MAP_LOG_STATS(sd, "STATUP");
return 0;
}
@@ -5520,77 +3316,24 @@ int pc_statusup (struct map_session_data *sd, int type)
* 能力値æˆé•·
*------------------------------------------
*/
-int pc_statusup2 (struct map_session_data *sd, int type, int val)
+int pc_statusup2(struct map_session_data *sd, SP type, int val)
{
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
- if (type < SP_STR || type > SP_LUK)
+ if (type < SP::STR || type > SP::LUK)
{
- clif_statusupack (sd, type, 0, 0);
+ clif_statusupack(sd, type, 0, 0);
return 1;
}
- switch (type)
- {
- case SP_STR:
- if (sd->status.str + val >= battle_config.max_parameter)
- val = battle_config.max_parameter;
- else if (sd->status.str + val < 1)
- val = 1;
- else
- val += sd->status.str;
- sd->status.str = val;
- break;
- case SP_AGI:
- if (sd->status.agi + val >= battle_config.max_parameter)
- val = battle_config.max_parameter;
- else if (sd->status.agi + val < 1)
- val = 1;
- else
- val += sd->status.agi;
- sd->status.agi = val;
- break;
- case SP_VIT:
- if (sd->status.vit + val >= battle_config.max_parameter)
- val = battle_config.max_parameter;
- else if (sd->status.vit + val < 1)
- val = 1;
- else
- val += sd->status.vit;
- sd->status.vit = val;
- break;
- case SP_INT:
- if (sd->status.int_ + val >= battle_config.max_parameter)
- val = battle_config.max_parameter;
- else if (sd->status.int_ + val < 1)
- val = 1;
- else
- val += sd->status.int_;
- sd->status.int_ = val;
- break;
- case SP_DEX:
- if (sd->status.dex + val >= battle_config.max_parameter)
- val = battle_config.max_parameter;
- else if (sd->status.dex + val < 1)
- val = 1;
- else
- val += sd->status.dex;
- sd->status.dex = val;
- break;
- case SP_LUK:
- if (sd->status.luk + val >= battle_config.max_parameter)
- val = battle_config.max_parameter;
- else if (sd->status.luk + val < 1)
- val = 1;
- else
- val = sd->status.luk + val;
- sd->status.luk = val;
- break;
- }
- clif_updatestatus (sd, type - SP_STR + SP_USTR);
- clif_updatestatus (sd, type);
- pc_calcstatus (sd, 0);
- clif_statusupack (sd, type, 1, val);
- MAP_LOG_STATS (sd, "STATUP2");
+ ATTR attr = sp_to_attr(type);
+ val = sd->status.attrs[attr] + val;
+ val = std::min(val, battle_config.max_parameter);
+ val = std::max(val, 1);
+ clif_updatestatus(sd, sp_to_usp(type));
+ clif_updatestatus(sd, type);
+ pc_calcstatus(sd, 0);
+ clif_statusupack(sd, type, 1, val);
+ MAP_LOG_STATS(sd, "STATUP2");
return 0;
}
@@ -5599,83 +3342,38 @@ int pc_statusup2 (struct map_session_data *sd, int type, int val)
* スキルãƒã‚¤ãƒ³ãƒˆå‰²ã‚ŠæŒ¯ã‚Š
*------------------------------------------
*/
-int pc_skillup (struct map_session_data *sd, int skill_num)
+int pc_skillup(struct map_session_data *sd, SkillID skill_num)
{
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
- if (sd->status.skill[skill_num].id != 0
+ if (sd->status.skill[skill_num].lv
&& sd->status.skill_point >= sd->status.skill[skill_num].lv
&& sd->status.skill[skill_num].lv < skill_db[skill_num].max_raise)
{
sd->status.skill_point -= sd->status.skill[skill_num].lv;
sd->status.skill[skill_num].lv++;
- pc_calcstatus (sd, 0);
- clif_skillup (sd, skill_num);
- clif_updatestatus (sd, SP_SKILLPOINT);
- clif_skillinfoblock (sd);
+ pc_calcstatus(sd, 0);
+ clif_skillup(sd, skill_num);
+ clif_updatestatus(sd, SP::SKILLPOINT);
+ clif_skillinfoblock(sd);
MAP_LOG_PC(sd, "SKILLUP %d %d %d",
- skill_num, sd->status.skill[skill_num].lv, skill_power(sd, skill_num));
+ skill_num, sd->status.skill[skill_num].lv,
+ skill_power(sd, skill_num));
}
return 0;
}
/*==========================================
- * /allskill
- *------------------------------------------
- */
-int pc_allskillup (struct map_session_data *sd)
-{
- int i, id;
- int c = 0, s = 0;
- //転生や養å­ã®å ´åˆã®å…ƒã®è·æ¥­ã‚’算出ã™ã‚‹
- struct pc_base_job s_class;
-
- nullpo_retr (0, sd);
-
- s_class = pc_calc_base_job (sd->status.pc_class);
- c = s_class.job;
- s = (s_class.upper == 1) ? 1 : 0; //転生以外ã¯é€šå¸¸ã®ã‚¹ã‚­ãƒ«ï¼Ÿ
-
- for (i = 0; i < MAX_SKILL; i++)
- sd->status.skill[i].id = 0;
-
- if (battle_config.gm_allskill > 0
- && pc_isGM (sd) >= battle_config.gm_allskill)
- {
- // å…¨ã¦ã®ã‚¹ã‚­ãƒ«
- for (i = 1; i < 158; i++)
- sd->status.skill[i].lv = skill_get_max (i);
- for (i = 210; i < 291; i++)
- sd->status.skill[i].lv = skill_get_max (i);
- for (i = 304; i < MAX_SKILL; i++)
- sd->status.skill[i].lv = skill_get_max (i);
- }
- else
- {
- for (i = 0; (id = skill_tree[s][c][i].id) > 0; i++)
- {
- if (sd->status.skill[id].id == 0 && skill_get_inf2 (id) & 0x01)
- sd->status.skill[id].lv = skill_get_max (id);
- }
- }
- pc_calcstatus (sd, 0);
-
- return 0;
-}
-
-/*==========================================
* /resetlvl
*------------------------------------------
*/
-int pc_resetlvl (struct map_session_data *sd, int type)
+int pc_resetlvl(struct map_session_data *sd, int type)
{
- int i;
-
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
- for (i = 1; i < MAX_SKILL; i++)
+ for (SkillID i : erange(SkillID(1), MAX_SKILL))
{
sd->status.skill[i].lv = 0;
}
@@ -5687,17 +3385,10 @@ int pc_resetlvl (struct map_session_data *sd, int type)
sd->status.job_level = 1;
sd->status.base_exp = 0;
sd->status.job_exp = 0;
- if (sd->status.option != 0)
- sd->status.option = 0;
+ sd->status.option = Option::ZERO;
- sd->status.str = 1;
- sd->status.agi = 1;
- sd->status.vit = 1;
- sd->status.int_ = 1;
- sd->status.dex = 1;
- sd->status.luk = 1;
- if (sd->status.pc_class == 4001)
- sd->status.status_point = 100;
+ for (ATTR attr : ATTRs)
+ sd->status.attrs[attr] = 1;
}
if (type == 2)
@@ -5719,41 +3410,42 @@ int pc_resetlvl (struct map_session_data *sd, int type)
sd->status.job_exp = 0;
}
- clif_updatestatus (sd, SP_STATUSPOINT);
- clif_updatestatus (sd, SP_STR);
- clif_updatestatus (sd, SP_AGI);
- clif_updatestatus (sd, SP_VIT);
- clif_updatestatus (sd, SP_INT);
- clif_updatestatus (sd, SP_DEX);
- clif_updatestatus (sd, SP_LUK);
- clif_updatestatus (sd, SP_BASELEVEL);
- clif_updatestatus (sd, SP_JOBLEVEL);
- clif_updatestatus (sd, SP_STATUSPOINT);
- clif_updatestatus (sd, SP_NEXTBASEEXP);
- clif_updatestatus (sd, SP_NEXTJOBEXP);
- clif_updatestatus (sd, SP_SKILLPOINT);
-
- clif_updatestatus (sd, SP_USTR); // Updates needed stat points - Valaris
- clif_updatestatus (sd, SP_UAGI);
- clif_updatestatus (sd, SP_UVIT);
- clif_updatestatus (sd, SP_UINT);
- clif_updatestatus (sd, SP_UDEX);
- clif_updatestatus (sd, SP_ULUK); // End Addition
-
- for (i = 0; i < 11; i++)
- { // unequip items that can't be equipped by base 1 [Valaris]
+ clif_updatestatus(sd, SP::STATUSPOINT);
+ clif_updatestatus(sd, SP::STR);
+ clif_updatestatus(sd, SP::AGI);
+ clif_updatestatus(sd, SP::VIT);
+ clif_updatestatus(sd, SP::INT);
+ clif_updatestatus(sd, SP::DEX);
+ clif_updatestatus(sd, SP::LUK);
+ clif_updatestatus(sd, SP::BASELEVEL);
+ clif_updatestatus(sd, SP::JOBLEVEL);
+ clif_updatestatus(sd, SP::STATUSPOINT);
+ clif_updatestatus(sd, SP::NEXTBASEEXP);
+ clif_updatestatus(sd, SP::NEXTJOBEXP);
+ clif_updatestatus(sd, SP::SKILLPOINT);
+
+ clif_updatestatus(sd, SP::USTR); // Updates needed stat points - Valaris
+ clif_updatestatus(sd, SP::UAGI);
+ clif_updatestatus(sd, SP::UVIT);
+ clif_updatestatus(sd, SP::UINT);
+ clif_updatestatus(sd, SP::UDEX);
+ clif_updatestatus(sd, SP::ULUK); // End Addition
+
+ for (EQUIP i : EQUIPs)
+ {
+ // unequip items that can't be equipped by base 1 [Valaris]
if (sd->equip_index[i] >= 0)
- if (!pc_isequip (sd, sd->equip_index[i]))
+ if (!pc_isequip(sd, sd->equip_index[i]))
{
- pc_unequipitem (sd, sd->equip_index[i], 1);
+ pc_unequipitem(sd, sd->equip_index[i], CalcStatus::LATER);
sd->equip_index[i] = -1;
}
}
- clif_skillinfoblock (sd);
- pc_calcstatus (sd, 0);
+ clif_skillinfoblock(sd);
+ pc_calcstatus(sd, 0);
- MAP_LOG_STATS (sd, "STATRESET");
+ MAP_LOG_STATS(sd, "STATRESET");
return 0;
}
@@ -5762,50 +3454,23 @@ int pc_resetlvl (struct map_session_data *sd, int type)
* /resetstate
*------------------------------------------
*/
-int pc_resetstate (struct map_session_data *sd)
-{
-#define sumsp(a) ((a)*((a-2)/10+2) - 5*((a-2)/10)*((a-2)/10) - 6*((a-2)/10) -2)
-// int add=0; // Removed by Dexity
-
- nullpo_retr (0, sd);
-
-// New statpoint table used here - Dexity
- sd->status.status_point = atoi (statp[sd->status.base_level - 1]);
-// End addition
-
-// Removed by Dexity - old count
-// add += sumsp(sd->status.str);
-// add += sumsp(sd->status.agi);
-// add += sumsp(sd->status.vit);
-// add += sumsp(sd->status.int_);
-// add += sumsp(sd->status.dex);
-// add += sumsp(sd->status.luk);
-// sd->status.status_point+=add;
-
- clif_updatestatus (sd, SP_STATUSPOINT);
-
- sd->status.str = 1;
- sd->status.agi = 1;
- sd->status.vit = 1;
- sd->status.int_ = 1;
- sd->status.dex = 1;
- sd->status.luk = 1;
-
- clif_updatestatus (sd, SP_STR);
- clif_updatestatus (sd, SP_AGI);
- clif_updatestatus (sd, SP_VIT);
- clif_updatestatus (sd, SP_INT);
- clif_updatestatus (sd, SP_DEX);
- clif_updatestatus (sd, SP_LUK);
-
- clif_updatestatus (sd, SP_USTR); // Updates needed stat points - Valaris
- clif_updatestatus (sd, SP_UAGI);
- clif_updatestatus (sd, SP_UVIT);
- clif_updatestatus (sd, SP_UINT);
- clif_updatestatus (sd, SP_UDEX);
- clif_updatestatus (sd, SP_ULUK); // End Addition
-
- pc_calcstatus (sd, 0);
+int pc_resetstate(struct map_session_data *sd)
+{
+
+ nullpo_ret(sd);
+
+ sd->status.status_point = stat_p[sd->status.base_level - 1];
+
+ clif_updatestatus(sd, SP::STATUSPOINT);
+
+ for (ATTR attr : ATTRs)
+ sd->status.attrs[attr] = 1;
+ for (ATTR attr : ATTRs)
+ clif_updatestatus(sd, attr_to_sp(attr));
+ for (ATTR attr : ATTRs)
+ clif_updatestatus(sd, attr_to_usp(attr));
+
+ pc_calcstatus(sd, 0);
return 0;
}
@@ -5814,24 +3479,24 @@ int pc_resetstate (struct map_session_data *sd)
* /resetskill
*------------------------------------------
*/
-int pc_resetskill (struct map_session_data *sd)
+int pc_resetskill(struct map_session_data *sd)
{
- int i, skill;
+ int skill;
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
- sd->status.skill_point += pc_calc_skillpoint (sd);
+ sd->status.skill_point += pc_calc_skillpoint(sd);
- for (i = 1; i < MAX_SKILL; i++)
- if ((skill = pc_checkskill (sd, i)) > 0)
+ for (SkillID i : erange(SkillID(1), MAX_SKILL))
+ if ((skill = pc_checkskill(sd, i)) > 0)
{
sd->status.skill[i].lv = 0;
- sd->status.skill[i].flags = 0;
+ sd->status.skill[i].flags = SkillFlags::ZERO;
}
- clif_updatestatus (sd, SP_SKILLPOINT);
- clif_skillinfoblock (sd);
- pc_calcstatus (sd, 0);
+ clif_updatestatus(sd, SP::SKILLPOINT);
+ clif_skillinfoblock(sd);
+ pc_calcstatus(sd, 0);
return 0;
}
@@ -5840,87 +3505,64 @@ int pc_resetskill (struct map_session_data *sd)
* pcã«ãƒ€ãƒ¡ãƒ¼ã‚¸ã‚’与ãˆã‚‹
*------------------------------------------
*/
-int pc_damage (struct block_list *src, struct map_session_data *sd,
+int pc_damage(struct block_list *src, struct map_session_data *sd,
int damage)
{
- int i = 0, j = 0;
- struct pc_base_job s_class;
+ int i = 0;
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
- //転生や養å­ã®å ´åˆã®å…ƒã®è·æ¥­ã‚’算出ã™ã‚‹
- s_class = pc_calc_base_job (sd->status.pc_class);
// æ—¢ã«æ­»ã‚“ã§ã„ãŸã‚‰ç„¡åŠ¹
- if (pc_isdead (sd))
+ if (pc_isdead(sd))
return 0;
// 座ã£ã¦ãŸã‚‰ç«‹ã¡ä¸ŠãŒã‚‹
- if (pc_issit (sd))
+ if (pc_issit(sd))
{
- pc_setstand (sd);
- skill_gangsterparadise (sd, 0);
+ pc_setstand(sd);
+ skill_gangsterparadise(sd, 0);
}
if (src)
{
- if (src->type == BL_PC)
+ if (src->type == BL::PC)
{
- MAP_LOG_PC (sd, "INJURED-BY PC%d FOR %d",
+ MAP_LOG_PC(sd, "INJURED-BY PC%d FOR %d",
((struct map_session_data *) src)->status.char_id,
damage);
}
else
{
- MAP_LOG_PC (sd, "INJURED-BY MOB%d FOR %d", src->id, damage);
+ MAP_LOG_PC(sd, "INJURED-BY MOB%d FOR %d", src->id, damage);
}
}
else
- MAP_LOG_PC (sd, "INJURED-BY null FOR %d", damage);
+ MAP_LOG_PC(sd, "INJURED-BY null FOR %d", damage);
- // æ­© ã„ã¦ã„ãŸã‚‰è¶³ã‚’æ­¢ã‚ã‚‹
- if (sd->sc_data[SC_ENDURE].timer == -1
- && !sd->special_state.infinite_endure)
- pc_stop_walking (sd, 3);
+ pc_stop_walking(sd, 3);
// æ¼”å¥/ダンスã®ä¸­æ–­
if (damage > sd->status.max_hp >> 2)
- skill_stop_dancing (&sd->bl, 0);
+ skill_stop_dancing(&sd->bl, 0);
sd->status.hp -= damage;
- if (sd->sc_data[SC_TRICKDEAD].timer != -1)
- skill_status_change_end (&sd->bl, SC_TRICKDEAD, -1);
- if (sd->status.option & 2)
- skill_status_change_end (&sd->bl, SC_HIDING, -1);
- if (sd->status.option & 4)
- skill_status_change_end (&sd->bl, SC_CLOAKING, -1);
- if (sd->status.option & 16386)
- skill_status_change_end (&sd->bl, SC_CHASEWALK, -1);
-
if (sd->status.hp > 0)
{
// ã¾ã ç”Ÿãã¦ã„ã‚‹ãªã‚‰HPæ›´æ–°
- clif_updatestatus (sd, SP_HP);
-
- if (sd->status.hp < sd->status.max_hp >> 2
- && pc_checkskill (sd, SM_AUTOBERSERK) > 0
- && (sd->sc_data[SC_PROVOKE].timer == -1
- || sd->sc_data[SC_PROVOKE].val2 == 0))
- // オートãƒãƒ¼ã‚µãƒ¼ã‚¯ç™ºå‹•
- skill_status_change_start (&sd->bl, SC_PROVOKE, 10, 1, 0, 0, 0,
- 0);
+ clif_updatestatus(sd, SP::HP);
- sd->canlog_tick = gettick ();
+ sd->canlog_tick = gettick();
if (sd->status.party_id > 0)
{ // on-the-fly party hp updates [Valaris]
- struct party *p = party_search (sd->status.party_id);
+ struct party *p = party_search(sd->status.party_id);
if (p != NULL)
- clif_party_hp (p, sd);
+ clif_party_hp(p, sd);
} // end addition [Valaris]
return 0;
}
- MAP_LOG_PC (sd, "DEAD%s", "");
+ MAP_LOG_PC(sd, "DEAD%s", "");
// Character is dead!
@@ -5928,151 +3570,83 @@ int pc_damage (struct block_list *src, struct map_session_data *sd,
// [Fate] Stop quickregen
sd->quick_regeneration_hp.amount = 0;
sd->quick_regeneration_sp.amount = 0;
- skill_update_heal_animation (sd);
-
- pc_setdead (sd);
-
- pc_stop_walking (sd, 0);
- skill_castcancel (&sd->bl, 0); // è© å”±ã®ä¸­æ­¢
- clif_clearchar_area (&sd->bl, 1);
- skill_unit_out_all (&sd->bl, gettick (), 1);
- if (sd->sc_data[SC_BLADESTOP].timer != -1) //白刃ã¯äº‹å‰ã«è§£é™¤
- skill_status_change_end (&sd->bl, SC_BLADESTOP, -1);
- pc_setglobalreg (sd, "PC_DIE_COUNTER", ++sd->die_counter); //æ­»ã«ã‚«ã‚¦ãƒ³ã‚¿ãƒ¼æ›¸ãè¾¼ã¿
- skill_status_change_clear (&sd->bl, 0); // ステータス異常を解除ã™ã‚‹
- clif_updatestatus (sd, SP_HP);
- pc_calcstatus (sd, 0);
+ skill_update_heal_animation(sd);
+
+ pc_setdead(sd);
+
+ pc_stop_walking(sd, 0);
+ skill_castcancel(&sd->bl, 0); // è© å”±ã®ä¸­æ­¢
+ clif_clearchar(&sd->bl, BeingRemoveWhy::DEAD);
+ pc_setglobalreg(sd, "PC_DIE_COUNTER", ++sd->die_counter); //æ­»ã«ã‚«ã‚¦ãƒ³ã‚¿ãƒ¼æ›¸ãè¾¼ã¿
+ skill_status_change_clear(&sd->bl, 0); // ステータス異常を解除ã™ã‚‹
+ clif_updatestatus(sd, SP::HP);
+ pc_calcstatus(sd, 0);
// [Fate] Reset magic
- sd->cast_tick = gettick ();
- magic_stop_completely (sd);
+ sd->cast_tick = gettick();
+ magic_stop_completely(sd);
for (i = 0; i < 5; i++)
if (sd->dev.val1[i])
{
- skill_status_change_end (&map_id2sd (sd->dev.val1[i])->bl,
- SC_DEVOTION, -1);
sd->dev.val1[i] = sd->dev.val2[i] = 0;
}
if (battle_config.death_penalty_type > 0 && sd->status.base_level >= 20)
{ // changed penalty options, added death by player if pk_mode [Valaris]
- if (!map[sd->bl.m].flag.nopenalty && !map[sd->bl.m].flag.gvg)
+ if (!map[sd->bl.m].flag.nopenalty)
{
if (battle_config.death_penalty_type == 1
&& battle_config.death_penalty_base > 0)
sd->status.base_exp -=
- (double) pc_nextbaseexp (sd) *
+ (double) pc_nextbaseexp(sd) *
(double) battle_config.death_penalty_base / 10000;
- if (battle_config.pk_mode && src && src->type == BL_PC)
+ if (battle_config.pk_mode && src && src->type == BL::PC)
sd->status.base_exp -=
- (double) pc_nextbaseexp (sd) *
+ (double) pc_nextbaseexp(sd) *
(double) battle_config.death_penalty_base / 10000;
else if (battle_config.death_penalty_type == 2
&& battle_config.death_penalty_base > 0)
{
- if (pc_nextbaseexp (sd) > 0)
+ if (pc_nextbaseexp(sd) > 0)
sd->status.base_exp -=
(double) sd->status.base_exp *
(double) battle_config.death_penalty_base / 10000;
- if (battle_config.pk_mode && src && src->type == BL_PC)
+ if (battle_config.pk_mode && src && src->type == BL::PC)
sd->status.base_exp -=
(double) sd->status.base_exp *
(double) battle_config.death_penalty_base / 10000;
}
if (sd->status.base_exp < 0)
sd->status.base_exp = 0;
- clif_updatestatus (sd, SP_BASEEXP);
+ clif_updatestatus(sd, SP::BASEEXP);
if (battle_config.death_penalty_type == 1
&& battle_config.death_penalty_job > 0)
sd->status.job_exp -=
- (double) pc_nextjobexp (sd) *
+ (double) pc_nextjobexp(sd) *
(double) battle_config.death_penalty_job / 10000;
- if (battle_config.pk_mode && src && src->type == BL_PC)
+ if (battle_config.pk_mode && src && src->type == BL::PC)
sd->status.job_exp -=
- (double) pc_nextjobexp (sd) *
+ (double) pc_nextjobexp(sd) *
(double) battle_config.death_penalty_job / 10000;
else if (battle_config.death_penalty_type == 2
&& battle_config.death_penalty_job > 0)
{
- if (pc_nextjobexp (sd) > 0)
+ if (pc_nextjobexp(sd) > 0)
sd->status.job_exp -=
(double) sd->status.job_exp *
(double) battle_config.death_penalty_job / 10000;
- if (battle_config.pk_mode && src && src->type == BL_PC)
+ if (battle_config.pk_mode && src && src->type == BL::PC)
sd->status.job_exp -=
(double) sd->status.job_exp *
(double) battle_config.death_penalty_job / 10000;
}
if (sd->status.job_exp < 0)
sd->status.job_exp = 0;
- clif_updatestatus (sd, SP_JOBEXP);
- }
- }
- //ナイトメアモードアイテムドロップ
- if (map[sd->bl.m].flag.pvp_nightmaredrop)
- { // Moved this outside so it works when PVP isnt enabled and during pk mode [Ancyker]
- for (j = 0; j < MAX_DROP_PER_MAP; j++)
- {
- int id = map[sd->bl.m].drop_list[j].drop_id;
- int type = map[sd->bl.m].drop_list[j].drop_type;
- int per = map[sd->bl.m].drop_list[j].drop_per;
- if (id == 0)
- continue;
- if (id == -1)
- { //ランダムドロップ
- int eq_num = 0, eq_n[MAX_INVENTORY];
- memset (eq_n, 0, sizeof (eq_n));
- //å…ˆãšè£…å‚™ã—ã¦ã„るアイテム数をカウント
- for (i = 0; i < MAX_INVENTORY; i++)
- {
- int k;
- if ((type == 1 && !sd->status.inventory[i].equip)
- || (type == 2 && sd->status.inventory[i].equip)
- || type == 3)
- {
- //InventoryIndexã‚’æ ¼ç´
- for (k = 0; k < MAX_INVENTORY; k++)
- {
- if (eq_n[k] <= 0)
- {
- eq_n[k] = i;
- break;
- }
- }
- eq_num++;
- }
- }
- if (eq_num > 0)
- {
- int n = eq_n[MRAND (eq_num)]; //該当アイテムã®ä¸­ã‹ã‚‰ãƒ©ãƒ³ãƒ€ãƒ 
- if (MRAND (10000) < per)
- {
- if (sd->status.inventory[n].equip)
- pc_unequipitem (sd, n, 0);
- pc_dropitem (sd, n, 1);
- }
- }
- }
- else if (id > 0)
- {
- for (i = 0; i < MAX_INVENTORY; i++)
- {
- if (sd->status.inventory[i].nameid == id //ItemIDãŒä¸€è‡´ã—ã¦ã„ã¦
- && MRAND (10000) < per //ドロップ率判定もOKã§
- && ((type == 1 && !sd->status.inventory[i].equip) //タイプ判定もOKãªã‚‰ãƒ‰ãƒ­ãƒƒãƒ—
- || (type == 2 && sd->status.inventory[i].equip)
- || type == 3))
- {
- if (sd->status.inventory[i].equip)
- pc_unequipitem (sd, i, 0);
- pc_dropitem (sd, i, 1);
- break;
- }
- }
- }
+ clif_updatestatus(sd, SP::JOBEXP);
}
}
+
// pvp
if (map[sd->bl.m].flag.pvp && !battle_config.pk_mode)
{ // disable certain pvp functions on pk_mode [Valaris]
@@ -6080,31 +3654,23 @@ int pc_damage (struct block_list *src, struct map_session_data *sd,
if (!map[sd->bl.m].flag.pvp_nocalcrank)
{
sd->pvp_point -= 5;
- if (src && src->type == BL_PC)
+ if (src && src->type == BL::PC)
((struct map_session_data *) src)->pvp_point++;
//} //fixed wrong '{' placement by Lupus
- pc_setdead (sd);
+ pc_setdead(sd);
}
// 強制é€é‚„
if (sd->pvp_point < 0)
{
sd->pvp_point = 0;
- pc_setstand (sd);
- pc_setrestartvalue (sd, 3);
- pc_setpos (sd, sd->status.save_point.map, sd->status.save_point.x,
- sd->status.save_point.y, 0);
+ pc_setstand(sd);
+ pc_setrestartvalue(sd, 3);
+ pc_setpos(sd, sd->status.save_point.map, sd->status.save_point.x,
+ sd->status.save_point.y, BeingRemoveWhy::GONE);
}
}
- //GvG
- if (map[sd->bl.m].flag.gvg)
- {
- pc_setstand (sd);
- pc_setrestartvalue (sd, 3);
- pc_setpos (sd, sd->status.save_point.map, sd->status.save_point.x,
- sd->status.save_point.y, 0);
- }
- if (src && src->type == BL_PC)
+ if (src && src->type == BL::PC)
{
// [Fate] PK death, trigger scripts
argrec_t arg[3];
@@ -6114,10 +3680,10 @@ int pc_damage (struct block_list *src, struct map_session_data *sd,
arg[1].v.i = sd->bl.id;
arg[2].name = "@victimlvl";
arg[2].v.i = sd->status.base_level;
- npc_event_doall_l ("OnPCKilledEvent", sd->bl.id, 3, arg);
- npc_event_doall_l ("OnPCKillEvent", src->id, 3, arg);
+ npc_event_doall_l("OnPCKilledEvent", sd->bl.id, 3, arg);
+ npc_event_doall_l("OnPCKillEvent", src->id, 3, arg);
}
- npc_event_doall_l ("OnPCDieEvent", sd->bl.id, 0, NULL);
+ npc_event_doall_l("OnPCDieEvent", sd->bl.id, 0, NULL);
return 0;
}
@@ -6129,94 +3695,72 @@ int pc_damage (struct block_list *src, struct map_session_data *sd,
* script用PCステータス読ã¿å‡ºã—
*------------------------------------------
*/
-int pc_readparam (struct map_session_data *sd, int type)
+int pc_readparam(struct map_session_data *sd, SP type)
{
- int val = 0;
- struct pc_base_job s_class;
+ int val = 0;
- s_class = pc_calc_base_job (sd->status.pc_class);
-
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
switch (type)
{
- case SP_SKILLPOINT:
+ case SP::SKILLPOINT:
val = sd->status.skill_point;
break;
- case SP_STATUSPOINT:
+ case SP::STATUSPOINT:
val = sd->status.status_point;
break;
- case SP_ZENY:
+ case SP::ZENY:
val = sd->status.zeny;
break;
- case SP_BASELEVEL:
+ case SP::BASELEVEL:
val = sd->status.base_level;
break;
- case SP_JOBLEVEL:
+ case SP::JOBLEVEL:
val = sd->status.job_level;
break;
- case SP_CLASS:
- if (val >= 24 && val < 45)
- val += 3978;
- else
- val = sd->status.pc_class;
- break;
- case SP_UPPER:
- val = s_class.upper;
+ case SP::CLASS:
+ val = sd->status.species;
break;
- case SP_SEX:
+ case SP::SEX:
val = sd->sex;
break;
- case SP_WEIGHT:
+ case SP::WEIGHT:
val = sd->weight;
break;
- case SP_MAXWEIGHT:
+ case SP::MAXWEIGHT:
val = sd->max_weight;
break;
- case SP_BASEEXP:
+ case SP::BASEEXP:
val = sd->status.base_exp;
break;
- case SP_JOBEXP:
+ case SP::JOBEXP:
val = sd->status.job_exp;
break;
- case SP_NEXTBASEEXP:
- val = pc_nextbaseexp (sd);
+ case SP::NEXTBASEEXP:
+ val = pc_nextbaseexp(sd);
break;
- case SP_NEXTJOBEXP:
- val = pc_nextjobexp (sd);
+ case SP::NEXTJOBEXP:
+ val = pc_nextjobexp(sd);
break;
- case SP_HP:
+ case SP::HP:
val = sd->status.hp;
break;
- case SP_MAXHP:
+ case SP::MAXHP:
val = sd->status.max_hp;
break;
- case SP_SP:
+ case SP::SP:
val = sd->status.sp;
break;
- case SP_MAXSP:
+ case SP::MAXSP:
val = sd->status.max_sp;
break;
- case SP_STR:
- val = sd->status.str;
- break;
- case SP_AGI:
- val = sd->status.agi;
- break;
- case SP_VIT:
- val = sd->status.vit;
- break;
- case SP_INT:
- val = sd->status.int_;
- break;
- case SP_DEX:
- val = sd->status.dex;
- break;
- case SP_LUK:
- val = sd->status.luk;
- break;
- case SP_FAME:
- val = sd->fame;
+ case SP::STR:
+ case SP::AGI:
+ case SP::VIT:
+ case SP::INT:
+ case SP::DEX:
+ case SP::LUK:
+ val = sd->status.attrs[sp_to_attr(type)];
break;
}
@@ -6227,18 +3771,15 @@ int pc_readparam (struct map_session_data *sd, int type)
* script用PCステータス設定
*------------------------------------------
*/
-int pc_setparam (struct map_session_data *sd, int type, int val)
+int pc_setparam(struct map_session_data *sd, SP type, int val)
{
- int i = 0, up_level = 50;
- struct pc_base_job s_class;
+ int i = 0, up_level = 50;
- nullpo_retr (0, sd);
-
- s_class = pc_calc_base_job (sd->status.pc_class);
+ nullpo_ret(sd);
switch (type)
{
- case SP_BASELEVEL:
+ case SP::BASELEVEL:
if (val > sd->status.base_level)
{
for (i = 1; i <= (val - sd->status.base_level); i++)
@@ -6247,19 +3788,15 @@ int pc_setparam (struct map_session_data *sd, int type, int val)
}
sd->status.base_level = val;
sd->status.base_exp = 0;
- clif_updatestatus (sd, SP_BASELEVEL);
- clif_updatestatus (sd, SP_NEXTBASEEXP);
- clif_updatestatus (sd, SP_STATUSPOINT);
- clif_updatestatus (sd, SP_BASEEXP);
- pc_calcstatus (sd, 0);
- pc_heal (sd, sd->status.max_hp, sd->status.max_sp);
- break;
- case SP_JOBLEVEL:
- if (sd->status.pc_class == 0)
- up_level -= 40;
- if ((sd->status.pc_class == 23)
- || (sd->status.pc_class >= 4001 && sd->status.pc_class <= 4022))
- up_level += 20;
+ clif_updatestatus(sd, SP::BASELEVEL);
+ clif_updatestatus(sd, SP::NEXTBASEEXP);
+ clif_updatestatus(sd, SP::STATUSPOINT);
+ clif_updatestatus(sd, SP::BASEEXP);
+ pc_calcstatus(sd, 0);
+ pc_heal(sd, sd->status.max_hp, sd->status.max_sp);
+ break;
+ case SP::JOBLEVEL:
+ up_level -= 40;
if (val >= sd->status.job_level)
{
if (val > up_level)
@@ -6267,95 +3804,82 @@ int pc_setparam (struct map_session_data *sd, int type, int val)
sd->status.skill_point += (val - sd->status.job_level);
sd->status.job_level = val;
sd->status.job_exp = 0;
- clif_updatestatus (sd, SP_JOBLEVEL);
- clif_updatestatus (sd, SP_NEXTJOBEXP);
- clif_updatestatus (sd, SP_JOBEXP);
- clif_updatestatus (sd, SP_SKILLPOINT);
- pc_calcstatus (sd, 0);
- clif_misceffect (&sd->bl, 1);
+ clif_updatestatus(sd, SP::JOBLEVEL);
+ clif_updatestatus(sd, SP::NEXTJOBEXP);
+ clif_updatestatus(sd, SP::JOBEXP);
+ clif_updatestatus(sd, SP::SKILLPOINT);
+ pc_calcstatus(sd, 0);
+ clif_misceffect(&sd->bl, 1);
}
else
{
sd->status.job_level = val;
sd->status.job_exp = 0;
- clif_updatestatus (sd, SP_JOBLEVEL);
- clif_updatestatus (sd, SP_NEXTJOBEXP);
- clif_updatestatus (sd, SP_JOBEXP);
- pc_calcstatus (sd, 0);
+ clif_updatestatus(sd, SP::JOBLEVEL);
+ clif_updatestatus(sd, SP::NEXTJOBEXP);
+ clif_updatestatus(sd, SP::JOBEXP);
+ pc_calcstatus(sd, 0);
}
- clif_updatestatus (sd, type);
+ clif_updatestatus(sd, type);
break;
- case SP_SKILLPOINT:
+ case SP::SKILLPOINT:
sd->status.skill_point = val;
break;
- case SP_STATUSPOINT:
+ case SP::STATUSPOINT:
sd->status.status_point = val;
break;
- case SP_ZENY:
+ case SP::ZENY:
sd->status.zeny = val;
break;
- case SP_BASEEXP:
- if (pc_nextbaseexp (sd) > 0)
+ case SP::BASEEXP:
+ if (pc_nextbaseexp(sd) > 0)
{
sd->status.base_exp = val;
if (sd->status.base_exp < 0)
sd->status.base_exp = 0;
- pc_checkbaselevelup (sd);
+ pc_checkbaselevelup(sd);
}
break;
- case SP_JOBEXP:
- if (pc_nextjobexp (sd) > 0)
+ case SP::JOBEXP:
+ if (pc_nextjobexp(sd) > 0)
{
sd->status.job_exp = val;
if (sd->status.job_exp < 0)
sd->status.job_exp = 0;
- pc_checkjoblevelup (sd);
+ pc_checkjoblevelup(sd);
}
break;
- case SP_SEX:
+ case SP::SEX:
sd->sex = val;
break;
- case SP_WEIGHT:
+ case SP::WEIGHT:
sd->weight = val;
break;
- case SP_MAXWEIGHT:
+ case SP::MAXWEIGHT:
sd->max_weight = val;
break;
- case SP_HP:
+ case SP::HP:
sd->status.hp = val;
break;
- case SP_MAXHP:
+ case SP::MAXHP:
sd->status.max_hp = val;
break;
- case SP_SP:
+ case SP::SP:
sd->status.sp = val;
break;
- case SP_MAXSP:
+ case SP::MAXSP:
sd->status.max_sp = val;
break;
- case SP_STR:
- sd->status.str = val;
- break;
- case SP_AGI:
- sd->status.agi = val;
- break;
- case SP_VIT:
- sd->status.vit = val;
- break;
- case SP_INT:
- sd->status.int_ = val;
- break;
- case SP_DEX:
- sd->status.dex = val;
- break;
- case SP_LUK:
- sd->status.luk = val;
- break;
- case SP_FAME:
- sd->fame = val;
+ case SP::STR:
+ case SP::AGI:
+ case SP::VIT:
+ case SP::INT:
+ case SP::DEX:
+ case SP::LUK:
+ sd->status.attrs[sp_to_attr(type)] = val;
break;
}
- clif_updatestatus (sd, type);
+ clif_updatestatus(sd, type);
return 0;
}
@@ -6364,27 +3888,24 @@ int pc_setparam (struct map_session_data *sd, int type, int val)
* HP/SP回復
*------------------------------------------
*/
-int pc_heal (struct map_session_data *sd, int hp, int sp)
+int pc_heal(struct map_session_data *sd, int hp, int sp)
{
// if(battle_config.battle_log)
-// printf("heal %d %d\n",hp,sp);
+// PRINTF("heal %d %d\n",hp,sp);
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
- if (pc_checkoverhp (sd))
+ if (pc_checkoverhp(sd))
{
if (hp > 0)
hp = 0;
}
- if (pc_checkoversp (sd))
+ if (pc_checkoversp(sd))
{
if (sp > 0)
sp = 0;
}
- if (sd->sc_data && sd->sc_data[SC_BERSERK].timer != -1) //ãƒãƒ¼ã‚µãƒ¼ã‚¯ä¸­ã¯å›žå¾©ã•ã›ãªã„らã—ã„
- return 0;
-
if (hp + sd->status.hp > sd->status.max_hp)
hp = sd->status.max_hp - sd->status.hp;
if (sp + sd->status.sp > sd->status.max_sp)
@@ -6393,22 +3914,22 @@ int pc_heal (struct map_session_data *sd, int hp, int sp)
if (sd->status.hp <= 0)
{
sd->status.hp = 0;
- pc_damage (NULL, sd, 1);
+ pc_damage(NULL, sd, 1);
hp = 0;
}
sd->status.sp += sp;
if (sd->status.sp <= 0)
sd->status.sp = 0;
if (hp)
- clif_updatestatus (sd, SP_HP);
+ clif_updatestatus(sd, SP::HP);
if (sp)
- clif_updatestatus (sd, SP_SP);
+ clif_updatestatus(sd, SP::SP);
if (sd->status.party_id > 0)
{ // on-the-fly party hp updates [Valaris]
- struct party *p = party_search (sd->status.party_id);
+ struct party *p = party_search(sd->status.party_id);
if (p != NULL)
- clif_party_hp (p, sd);
+ clif_party_hp(p, sd);
} // end addition [Valaris]
return hp + sp;
@@ -6418,10 +3939,12 @@ int pc_heal (struct map_session_data *sd, int hp, int sp)
* HP/SP回復
*------------------------------------------
*/
-static int pc_itemheal_effect (struct map_session_data *sd, int hp, int sp);
+static
+int pc_itemheal_effect(struct map_session_data *sd, int hp, int sp);
-static int // Compute how quickly we regenerate (less is faster) for that amount
-pc_heal_quick_speed (int amount)
+static
+int // Compute how quickly we regenerate (less is faster) for that amount
+pc_heal_quick_speed(int amount)
{
if (amount >= 100)
{
@@ -6441,35 +3964,35 @@ pc_heal_quick_speed (int amount)
}
}
-static void
-pc_heal_quick_accumulate (int new_amount,
+static
+void pc_heal_quick_accumulate(int new_amount,
struct quick_regeneration *quick_regen, int max)
{
- int current_amount = quick_regen->amount;
- int current_speed = quick_regen->speed;
- int new_speed = pc_heal_quick_speed (new_amount);
+ int current_amount = quick_regen->amount;
+ int current_speed = quick_regen->speed;
+ int new_speed = pc_heal_quick_speed(new_amount);
- int average_speed = ((new_speed * new_amount) + (current_speed * current_amount)) / (current_amount + new_amount); // new_amount > 0, current_amount >= 0
+ int average_speed = ((new_speed * new_amount) + (current_speed * current_amount)) / (current_amount + new_amount); // new_amount > 0, current_amount >= 0
quick_regen->speed = average_speed;
- quick_regen->amount = MIN (current_amount + new_amount, max);
+ quick_regen->amount = min(current_amount + new_amount, max);
- quick_regen->tickdelay = MIN (quick_regen->speed, quick_regen->tickdelay);
+ quick_regen->tickdelay = min(quick_regen->speed, quick_regen->tickdelay);
}
-int pc_itemheal (struct map_session_data *sd, int hp, int sp)
+int pc_itemheal(struct map_session_data *sd, int hp, int sp)
{
/* defer healing */
if (hp > 0)
{
- pc_heal_quick_accumulate (hp,
+ pc_heal_quick_accumulate(hp,
&sd->quick_regeneration_hp,
sd->status.max_hp - sd->status.hp);
hp = 0;
}
if (sp > 0)
{
- pc_heal_quick_accumulate (sp,
+ pc_heal_quick_accumulate(sp,
&sd->quick_regeneration_sp,
sd->status.max_sp - sd->status.sp);
@@ -6478,7 +4001,7 @@ int pc_itemheal (struct map_session_data *sd, int hp, int sp)
/* Hurt right away, if necessary */
if (hp < 0 || sp < 0)
- pc_itemheal_effect (sd, hp, sp);
+ pc_itemheal_effect(sd, hp, sp);
return 0;
}
@@ -6486,54 +4009,30 @@ int pc_itemheal (struct map_session_data *sd, int hp, int sp)
/* pc_itemheal_effect is invoked once every 0.5s whenever the pc
* has health recovery queued up (cf. pc_natural_heal_sub).
*/
-static int pc_itemheal_effect (struct map_session_data *sd, int hp, int sp)
+static
+int pc_itemheal_effect(struct map_session_data *sd, int hp, int sp)
{
- int bonus;
-// if(battle_config.battle_log)
-// printf("heal %d %d\n",hp,sp);
-
- nullpo_retr (0, sd);
-
- if (sd->sc_data && sd->sc_data[SC_GOSPEL].timer != -1) //ãƒãƒ¼ã‚µãƒ¼ã‚¯ä¸­ã¯å›žå¾©ã•ã›ãªã„らã—ã„
- return 0;
+ nullpo_ret(sd);
- if (sd->state.potionpitcher_flag)
- {
- sd->potion_hp = hp;
- sd->potion_sp = sp;
- return 0;
- }
-
- if (pc_checkoverhp (sd))
+ if (pc_checkoverhp(sd))
{
if (hp > 0)
hp = 0;
}
- if (pc_checkoversp (sd))
+ if (pc_checkoversp(sd))
{
if (sp > 0)
sp = 0;
}
if (hp > 0)
{
- bonus =
- (sd->paramc[2] << 1) + 100 + pc_checkskill (sd, SM_RECOVERY) * 10;
- if (bonus != 100)
- hp = hp * bonus / 100;
- bonus = 100 + pc_checkskill (sd, AM_LEARNINGPOTION) * 5;
- if (bonus != 100)
- hp = hp * bonus / 100;
+ int bonus = (sd->paramc[ATTR::VIT] << 1) + 100;
+ hp = hp * bonus / 100;
}
if (sp > 0)
{
- bonus =
- (sd->paramc[3] << 1) + 100 + pc_checkskill (sd,
- MG_SRECOVERY) * 10;
- if (bonus != 100)
- sp = sp * bonus / 100;
- bonus = 100 + pc_checkskill (sd, AM_LEARNINGPOTION) * 5;
- if (bonus != 100)
- sp = sp * bonus / 100;
+ int bonus = (sd->paramc[ATTR::INT] << 1) + 100;
+ sp = sp * bonus / 100;
}
if (hp + sd->status.hp > sd->status.max_hp)
hp = sd->status.max_hp - sd->status.hp;
@@ -6543,16 +4042,16 @@ static int pc_itemheal_effect (struct map_session_data *sd, int hp, int sp)
if (sd->status.hp <= 0)
{
sd->status.hp = 0;
- pc_damage (NULL, sd, 1);
+ pc_damage(NULL, sd, 1);
hp = 0;
}
sd->status.sp += sp;
if (sd->status.sp <= 0)
sd->status.sp = 0;
if (hp)
- clif_updatestatus (sd, SP_HP);
+ clif_updatestatus(sd, SP::HP);
if (sp)
- clif_updatestatus (sd, SP_SP);
+ clif_updatestatus(sd, SP::SP);
return 0;
}
@@ -6561,23 +4060,16 @@ static int pc_itemheal_effect (struct map_session_data *sd, int hp, int sp)
* HP/SP回復
*------------------------------------------
*/
-int pc_percentheal (struct map_session_data *sd, int hp, int sp)
+int pc_percentheal(struct map_session_data *sd, int hp, int sp)
{
- nullpo_retr (0, sd);
-
- if (sd->state.potionpitcher_flag)
- {
- sd->potion_per_hp = hp;
- sd->potion_per_sp = sp;
- return 0;
- }
+ nullpo_ret(sd);
- if (pc_checkoverhp (sd))
+ if (pc_checkoverhp(sd))
{
if (hp > 0)
hp = 0;
}
- if (pc_checkoversp (sd))
+ if (pc_checkoversp(sd))
{
if (sp > 0)
sp = 0;
@@ -6591,7 +4083,7 @@ int pc_percentheal (struct map_session_data *sd, int hp, int sp)
else if (hp <= -100)
{
sd->status.hp = 0;
- pc_damage (NULL, sd, 1);
+ pc_damage(NULL, sd, 1);
}
else
{
@@ -6601,7 +4093,7 @@ int pc_percentheal (struct map_session_data *sd, int hp, int sp)
if (sd->status.hp <= 0)
{
sd->status.hp = 0;
- pc_damage (NULL, sd, 1);
+ pc_damage(NULL, sd, 1);
hp = 0;
}
}
@@ -6626,119 +4118,9 @@ int pc_percentheal (struct map_session_data *sd, int hp, int sp)
}
}
if (hp)
- clif_updatestatus (sd, SP_HP);
+ clif_updatestatus(sd, SP::HP);
if (sp)
- clif_updatestatus (sd, SP_SP);
-
- return 0;
-}
-
-/*==========================================
- * è·å¤‰æ›´
- * 引数 job è·æ¥­ 0〜23
- * upper 通常 0, 転生 1, é¤Šå­ 2, ãã®ã¾ã¾ -1
- *------------------------------------------
- */
-int pc_jobchange (struct map_session_data *sd, int job, int upper)
-{
- int i;
- int b_class = 0;
- //転生や養å­ã®å ´åˆã®å…ƒã®è·æ¥­ã‚’算出ã™ã‚‹
- struct pc_base_job s_class = pc_calc_base_job (sd->status.pc_class);
-
- nullpo_retr (0, sd);
-
- if ((job > 23) && (job < 68))
- job += 3977;
-
- if ((job > 69) && (job < 4000))
- return 1;
-
- if (upper < 0) //ç¾åœ¨è»¢ç”Ÿã‹ã©ã†ã‹ã‚’判断ã™ã‚‹
- upper = s_class.upper;
-
- if (upper == 0)
- { //通常è·ãªã‚‰jobãã®ã¾ã‚“ã¾
- b_class = job;
- }
- else if (upper == 1)
- {
- if (job == 23)
- { //転生ã«ã‚¹ãƒ‘ノビã¯å­˜åœ¨ã—ãªã„ã®ã§ãŠæ–­ã‚Š
- return 1;
- }
- else
- {
- b_class = job + 4001;
- }
- }
- else if (upper == 2)
- { //養å­ã«çµå©šã¯ãªã„ã‘ã©ã©ã†ã›æ¬¡ã§è¹´ã‚‰ã‚Œã‚‹ã‹ã‚‰ã„ã„ã‚„
- b_class = (job == 23) ? job + 4022 : job + 4023;
- }
- else
- {
- return 1;
- }
-
- if ((sd->status.sex == 0 && job == 19) || (sd->status.sex == 1 && job == 20) ||
- (sd->status.sex == 0 && job == 4020) || (sd->status.sex == 1 && job == 4021) ||
- job == 22 || sd->status.pc_class == b_class) //♀ã¯ãƒãƒ¼ãƒ‰ã«ãªã‚Œãªã„ã€â™‚ã¯ãƒ€ãƒ³ã‚µãƒ¼ã«ãªã‚Œãªã„ã€çµå©šè¡£è£³ã‚‚ãŠæ–­ã‚Š
- return 1;
-
- sd->status.pc_class = sd->view_class = b_class;
-
- sd->status.job_level = 1;
- sd->status.job_exp = 0;
- clif_updatestatus (sd, SP_JOBLEVEL);
- clif_updatestatus (sd, SP_JOBEXP);
- clif_updatestatus (sd, SP_NEXTJOBEXP);
-
- for (i = 0; i < 11; i++)
- {
- if (sd->equip_index[i] >= 0)
- if (!pc_isequip (sd, sd->equip_index[i]))
- pc_unequipitem (sd, sd->equip_index[i], 1); // 装備外ã—
- }
-
- clif_changelook (&sd->bl, LOOK_BASE, sd->view_class); // move sprite update to prevent client crashes with incompatible equipment [Valaris]
- if (sd->status.clothes_color > 0)
- clif_changelook (&sd->bl, LOOK_CLOTHES_COLOR,
- sd->status.clothes_color);
- if (battle_config.muting_players && sd->status.manner < 0)
- clif_changestatus (&sd->bl, SP_MANNER, sd->status.manner);
-
- pc_calcstatus (sd, 0);
- pc_checkallowskill (sd);
- pc_equiplookall (sd);
- clif_equiplist (sd);
-
- if (pc_isriding (sd))
- { // remove peco status if changing into invalid class [Valaris]
- if (!(pc_checkskill (sd, KN_RIDING)))
- pc_setoption (sd, sd->status.option | -0x0000);
- if (pc_checkskill (sd, KN_RIDING) > 0)
- pc_setriding (sd);
- }
-
- return 0;
-}
-
-/*==========================================
- * 見ãŸç›®å¤‰æ›´
- *------------------------------------------
- */
-int pc_equiplookall (struct map_session_data *sd)
-{
- nullpo_retr (0, sd);
-
- clif_changelook (&sd->bl, LOOK_WEAPON, 0);
-// clif_changelook(&sd->bl,LOOK_SHOES,0);
- clif_changelook (&sd->bl, LOOK_HEAD_BOTTOM, sd->status.head_bottom);
- clif_changelook (&sd->bl, LOOK_HEAD_TOP, sd->status.head_top);
- clif_changelook (&sd->bl, LOOK_HEAD_MID, sd->status.head_mid);
-
- clif_changelook_accessories (&sd->bl, NULL);
+ clif_updatestatus(sd, SP::SP);
return 0;
}
@@ -6747,40 +4129,40 @@ int pc_equiplookall (struct map_session_data *sd)
* 見ãŸç›®å¤‰æ›´
*------------------------------------------
*/
-int pc_changelook (struct map_session_data *sd, int type, int val)
+int pc_changelook(struct map_session_data *sd, LOOK type, int val)
{
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
switch (type)
{
- case LOOK_HAIR:
+ case LOOK::HAIR:
sd->status.hair = val;
break;
- case LOOK_WEAPON:
- sd->status.weapon = val;
+ case LOOK::WEAPON:
+ sd->status.weapon = static_cast<ItemLook>(static_cast<uint16_t>(val));
break;
- case LOOK_HEAD_BOTTOM:
+ case LOOK::HEAD_BOTTOM:
sd->status.head_bottom = val;
break;
- case LOOK_HEAD_TOP:
+ case LOOK::HEAD_TOP:
sd->status.head_top = val;
break;
- case LOOK_HEAD_MID:
+ case LOOK::HEAD_MID:
sd->status.head_mid = val;
break;
- case LOOK_HAIR_COLOR:
+ case LOOK::HAIR_COLOR:
sd->status.hair_color = val;
break;
- case LOOK_CLOTHES_COLOR:
+ case LOOK::CLOTHES_COLOR:
sd->status.clothes_color = val;
break;
- case LOOK_SHIELD:
+ case LOOK::SHIELD:
sd->status.shield = val;
break;
- case LOOK_SHOES:
+ case LOOK::SHOES:
break;
}
- clif_changelook (&sd->bl, type, val);
+ clif_changelook(&sd->bl, type, val);
return 0;
}
@@ -6789,89 +4171,13 @@ int pc_changelook (struct map_session_data *sd, int type, int val)
* 付属å“(é·¹,ペコ,カート)設定
*------------------------------------------
*/
-int pc_setoption (struct map_session_data *sd, int type)
+int pc_setoption(struct map_session_data *sd, Option type)
{
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
sd->status.option = type;
- clif_changeoption (&sd->bl);
- pc_calcstatus (sd, 0);
-
- return 0;
-}
-
-/*==========================================
- * カート設定
- *------------------------------------------
- */
-int pc_setcart (struct map_session_data *sd, int type)
-{
- int cart[6] = { 0x0000, 0x0008, 0x0080, 0x0100, 0x0200, 0x0400 };
-
- nullpo_retr (0, sd);
-
- if (pc_checkskill (sd, MC_PUSHCART) > 0)
- { // プッシュカートスキル所æŒ
- if (!pc_iscarton (sd))
- { // カートを付ã‘ã¦ã„ãªã„
- pc_setoption (sd, cart[type]);
- clif_cart_itemlist (sd);
- clif_cart_equiplist (sd);
- clif_updatestatus (sd, SP_CARTINFO);
- clif_status_change (&sd->bl, 0x0c, 0);
- }
- else
- {
- pc_setoption (sd, cart[type]);
- }
- }
-
- return 0;
-}
-
-/*==========================================
- * 鷹設定
- *------------------------------------------
- */
-int pc_setfalcon (struct map_session_data *sd)
-{
- if (pc_checkskill (sd, HT_FALCON) > 0)
- { // ファルコンマスタリースキル所æŒ
- pc_setoption (sd, sd->status.option | 0x0010);
- }
-
- return 0;
-}
-
-/*==========================================
- * ペコペコ設定
- *------------------------------------------
- */
-int pc_setriding (struct map_session_data *sd)
-{
- if (sd->disguise > 0)
- { // temporary prevention of crash caused by peco + disguise, will look into a better solution [Valaris]
- clif_displaymessage (sd->fd,
- "Cannot mount a Peco while in disguise.");
- return 0;
- }
-
- if ((pc_checkskill (sd, KN_RIDING) > 0))
- { // ライディングスキル所æŒ
- pc_setoption (sd, sd->status.option | 0x0020);
-
- if (sd->status.pc_class == 7)
- sd->status.pc_class = sd->view_class = 13;
-
- if (sd->status.pc_class == 14)
- sd->status.pc_class = sd->view_class = 21;
-
- if (sd->status.pc_class == 4008)
- sd->status.pc_class = sd->view_class = 4014;
-
- if (sd->status.pc_class == 4015)
- sd->status.pc_class = sd->view_class = 4022;
- }
+ clif_changeoption(&sd->bl);
+ pc_calcstatus(sd, 0);
return 0;
}
@@ -6880,11 +4186,11 @@ int pc_setriding (struct map_session_data *sd)
* script用変数ã®å€¤ã‚’読む
*------------------------------------------
*/
-int pc_readreg (struct map_session_data *sd, int reg)
+int pc_readreg(struct map_session_data *sd, int reg)
{
- int i;
+ int i;
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
for (i = 0; i < sd->reg_num; i++)
if (sd->reg[i].index == reg)
@@ -6897,11 +4203,11 @@ int pc_readreg (struct map_session_data *sd, int reg)
* script用変数ã®å€¤ã‚’設定
*------------------------------------------
*/
-int pc_setreg (struct map_session_data *sd, int reg, int val)
+int pc_setreg(struct map_session_data *sd, int reg, int val)
{
- int i;
+ int i;
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
for (i = 0; i < sd->reg_num; i++)
{
@@ -6912,7 +4218,7 @@ int pc_setreg (struct map_session_data *sd, int reg, int val)
}
}
sd->reg_num++;
- RECREATE (sd->reg, struct script_reg, sd->reg_num);
+ RECREATE(sd->reg, struct script_reg, sd->reg_num);
sd->reg[i].index = reg;
sd->reg[i].data = val;
@@ -6923,11 +4229,11 @@ int pc_setreg (struct map_session_data *sd, int reg, int val)
* script用文字列変数ã®å€¤ã‚’読む
*------------------------------------------
*/
-char *pc_readregstr (struct map_session_data *sd, int reg)
+char *pc_readregstr(struct map_session_data *sd, int reg)
{
- int i;
+ int i;
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
for (i = 0; i < sd->regstr_num; i++)
if (sd->regstr[i].index == reg)
@@ -6940,28 +4246,28 @@ char *pc_readregstr (struct map_session_data *sd, int reg)
* script用文字列変数ã®å€¤ã‚’設定
*------------------------------------------
*/
-int pc_setregstr (struct map_session_data *sd, int reg, const char *str)
+int pc_setregstr(struct map_session_data *sd, int reg, const char *str)
{
- int i;
+ int i;
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
- if (strlen (str) + 1 > sizeof (sd->regstr[0].data))
+ if (strlen(str) + 1 > sizeof(sd->regstr[0].data))
{
- printf ("pc_setregstr(): String too long!\n");
+ PRINTF("pc_setregstr(): String too long!\n");
return 0;
}
for (i = 0; i < sd->regstr_num; i++)
if (sd->regstr[i].index == reg)
{
- strcpy (sd->regstr[i].data, str);
+ strcpy(sd->regstr[i].data, str);
return 0;
}
sd->regstr_num++;
- RECREATE (sd->regstr, struct script_regstr, sd->regstr_num);
+ RECREATE(sd->regstr, struct script_regstr, sd->regstr_num);
sd->regstr[i].index = reg;
- strcpy (sd->regstr[i].data, str);
+ strcpy(sd->regstr[i].data, str);
return 0;
}
@@ -6970,15 +4276,15 @@ int pc_setregstr (struct map_session_data *sd, int reg, const char *str)
* script用グローãƒãƒ«å¤‰æ•°ã®å€¤ã‚’読む
*------------------------------------------
*/
-int pc_readglobalreg (struct map_session_data *sd, const char *reg)
+int pc_readglobalreg(struct map_session_data *sd, const char *reg)
{
- int i;
+ int i;
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
for (i = 0; i < sd->status.global_reg_num; i++)
{
- if (strcmp (sd->status.global_reg[i].str, reg) == 0)
+ if (strcmp(sd->status.global_reg[i].str, reg) == 0)
return sd->status.global_reg[i].value;
}
@@ -6989,23 +4295,23 @@ int pc_readglobalreg (struct map_session_data *sd, const char *reg)
* script用グローãƒãƒ«å¤‰æ•°ã®å€¤ã‚’設定
*------------------------------------------
*/
-int pc_setglobalreg (struct map_session_data *sd, const char *reg, int val)
+int pc_setglobalreg(struct map_session_data *sd, const char *reg, int val)
{
- int i;
+ int i;
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
//PC_DIE_COUNTERãŒã‚¹ã‚¯ãƒªãƒ—トãªã©ã§å¤‰æ›´ã•ã‚ŒãŸæ™‚ã®å‡¦ç†
- if (strcmp (reg, "PC_DIE_COUNTER") == 0 && sd->die_counter != val)
+ if (strcmp(reg, "PC_DIE_COUNTER") == 0 && sd->die_counter != val)
{
sd->die_counter = val;
- pc_calcstatus (sd, 0);
+ pc_calcstatus(sd, 0);
}
if (val == 0)
{
for (i = 0; i < sd->status.global_reg_num; i++)
{
- if (strcmp (sd->status.global_reg[i].str, reg) == 0)
+ if (strcmp(sd->status.global_reg[i].str, reg) == 0)
{
sd->status.global_reg[i] =
sd->status.global_reg[sd->status.global_reg_num - 1];
@@ -7017,7 +4323,7 @@ int pc_setglobalreg (struct map_session_data *sd, const char *reg, int val)
}
for (i = 0; i < sd->status.global_reg_num; i++)
{
- if (strcmp (sd->status.global_reg[i].str, reg) == 0)
+ if (strcmp(sd->status.global_reg[i].str, reg) == 0)
{
sd->status.global_reg[i].value = val;
return 0;
@@ -7025,13 +4331,13 @@ int pc_setglobalreg (struct map_session_data *sd, const char *reg, int val)
}
if (sd->status.global_reg_num < GLOBAL_REG_NUM)
{
- strcpy (sd->status.global_reg[i].str, reg);
+ strcpy(sd->status.global_reg[i].str, reg);
sd->status.global_reg[i].value = val;
sd->status.global_reg_num++;
return 0;
}
if (battle_config.error_log)
- printf ("pc_setglobalreg : couldn't set %s (GLOBAL_REG_NUM = %d)\n",
+ PRINTF("pc_setglobalreg : couldn't set %s (GLOBAL_REG_NUM = %d)\n",
reg, GLOBAL_REG_NUM);
return 1;
@@ -7041,15 +4347,15 @@ int pc_setglobalreg (struct map_session_data *sd, const char *reg, int val)
* script用アカウント変数ã®å€¤ã‚’読む
*------------------------------------------
*/
-int pc_readaccountreg (struct map_session_data *sd, const char *reg)
+int pc_readaccountreg(struct map_session_data *sd, const char *reg)
{
- int i;
+ int i;
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
for (i = 0; i < sd->status.account_reg_num; i++)
{
- if (strcmp (sd->status.account_reg[i].str, reg) == 0)
+ if (strcmp(sd->status.account_reg[i].str, reg) == 0)
return sd->status.account_reg[i].value;
}
@@ -7060,17 +4366,17 @@ int pc_readaccountreg (struct map_session_data *sd, const char *reg)
* script用アカウント変数ã®å€¤ã‚’設定
*------------------------------------------
*/
-int pc_setaccountreg (struct map_session_data *sd, const char *reg, int val)
+int pc_setaccountreg(struct map_session_data *sd, const char *reg, int val)
{
- int i;
+ int i;
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
if (val == 0)
{
for (i = 0; i < sd->status.account_reg_num; i++)
{
- if (strcmp (sd->status.account_reg[i].str, reg) == 0)
+ if (strcmp(sd->status.account_reg[i].str, reg) == 0)
{
sd->status.account_reg[i] =
sd->status.account_reg[sd->status.account_reg_num - 1];
@@ -7078,28 +4384,28 @@ int pc_setaccountreg (struct map_session_data *sd, const char *reg, int val)
break;
}
}
- intif_saveaccountreg (sd);
+ intif_saveaccountreg(sd);
return 0;
}
for (i = 0; i < sd->status.account_reg_num; i++)
{
- if (strcmp (sd->status.account_reg[i].str, reg) == 0)
+ if (strcmp(sd->status.account_reg[i].str, reg) == 0)
{
sd->status.account_reg[i].value = val;
- intif_saveaccountreg (sd);
+ intif_saveaccountreg(sd);
return 0;
}
}
if (sd->status.account_reg_num < ACCOUNT_REG_NUM)
{
- strcpy (sd->status.account_reg[i].str, reg);
+ strcpy(sd->status.account_reg[i].str, reg);
sd->status.account_reg[i].value = val;
sd->status.account_reg_num++;
- intif_saveaccountreg (sd);
+ intif_saveaccountreg(sd);
return 0;
}
if (battle_config.error_log)
- printf ("pc_setaccountreg : couldn't set %s (ACCOUNT_REG_NUM = %d)\n",
+ PRINTF("pc_setaccountreg : couldn't set %s (ACCOUNT_REG_NUM = %d)\n",
reg, ACCOUNT_REG_NUM);
return 1;
@@ -7109,15 +4415,15 @@ int pc_setaccountreg (struct map_session_data *sd, const char *reg, int val)
* script用アカウント変数2ã®å€¤ã‚’読む
*------------------------------------------
*/
-int pc_readaccountreg2 (struct map_session_data *sd, const char *reg)
+int pc_readaccountreg2(struct map_session_data *sd, const char *reg)
{
- int i;
+ int i;
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
for (i = 0; i < sd->status.account_reg2_num; i++)
{
- if (strcmp (sd->status.account_reg2[i].str, reg) == 0)
+ if (strcmp(sd->status.account_reg2[i].str, reg) == 0)
return sd->status.account_reg2[i].value;
}
@@ -7128,17 +4434,17 @@ int pc_readaccountreg2 (struct map_session_data *sd, const char *reg)
* script用アカウント変数2ã®å€¤ã‚’設定
*------------------------------------------
*/
-int pc_setaccountreg2 (struct map_session_data *sd, const char *reg, int val)
+int pc_setaccountreg2(struct map_session_data *sd, const char *reg, int val)
{
- int i;
+ int i;
- nullpo_retr (1, sd);
+ nullpo_retr(1, sd);
if (val == 0)
{
for (i = 0; i < sd->status.account_reg2_num; i++)
{
- if (strcmp (sd->status.account_reg2[i].str, reg) == 0)
+ if (strcmp(sd->status.account_reg2[i].str, reg) == 0)
{
sd->status.account_reg2[i] =
sd->status.account_reg2[sd->status.account_reg2_num - 1];
@@ -7146,111 +4452,69 @@ int pc_setaccountreg2 (struct map_session_data *sd, const char *reg, int val)
break;
}
}
- chrif_saveaccountreg2 (sd);
+ chrif_saveaccountreg2(sd);
return 0;
}
for (i = 0; i < sd->status.account_reg2_num; i++)
{
- if (strcmp (sd->status.account_reg2[i].str, reg) == 0)
+ if (strcmp(sd->status.account_reg2[i].str, reg) == 0)
{
sd->status.account_reg2[i].value = val;
- chrif_saveaccountreg2 (sd);
+ chrif_saveaccountreg2(sd);
return 0;
}
}
if (sd->status.account_reg2_num < ACCOUNT_REG2_NUM)
{
- strcpy (sd->status.account_reg2[i].str, reg);
+ strcpy(sd->status.account_reg2[i].str, reg);
sd->status.account_reg2[i].value = val;
sd->status.account_reg2_num++;
- chrif_saveaccountreg2 (sd);
+ chrif_saveaccountreg2(sd);
return 0;
}
if (battle_config.error_log)
- printf
- ("pc_setaccountreg2 : couldn't set %s (ACCOUNT_REG2_NUM = %d)\n",
+ PRINTF("pc_setaccountreg2 : couldn't set %s (ACCOUNT_REG2_NUM = %d)\n",
reg, ACCOUNT_REG2_NUM);
return 1;
}
/*==========================================
- * 精錬æˆåŠŸçŽ‡
- *------------------------------------------
- */
-int pc_percentrefinery (struct map_session_data *sd, struct item *item)
-{
- int percent;
-
- nullpo_retr (0, item);
- percent = percentrefinery[itemdb_wlv (item->nameid)][(int) item->refine];
-
- percent += pc_checkskill (sd, BS_WEAPONRESEARCH); // 武器研究スキル所æŒ
-
- // 確率ã®æœ‰åŠ¹ç¯„囲ãƒã‚§ãƒƒã‚¯
- if (percent > 100)
- {
- percent = 100;
- }
- if (percent < 0)
- {
- percent = 0;
- }
-
- return percent;
-}
-
-/*==========================================
* イベントタイマー処ç†
*------------------------------------------
*/
static
-void pc_eventtimer (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data)
+void pc_eventtimer(TimerData *, tick_t, int id, const char *data)
{
- struct map_session_data *sd = map_id2sd (id);
- int i;
- if (sd == NULL)
- return;
+ struct map_session_data *sd = map_id2sd(id);
+ assert (sd != NULL);
- for (i = 0; i < MAX_EVENTTIMER; i++)
- {
- if (sd->eventtimer[i] == tid)
- {
- sd->eventtimer[i] = -1;
- npc_event (sd, (const char *) data, 0);
- break;
- }
- }
- free ((void *) data);
- if (i == MAX_EVENTTIMER)
- {
- if (battle_config.error_log)
- printf ("pc_eventtimer: no such event timer\n");
- }
+ npc_event(sd, data, 0);
+
+ free(const_cast<char *>(data));
}
/*==========================================
* イベントタイマー追加
*------------------------------------------
*/
-int pc_addeventtimer (struct map_session_data *sd, int tick, const char *name)
+int pc_addeventtimer(struct map_session_data *sd, interval_t tick, const char *name)
{
- int i;
+ int i;
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
for (i = 0; i < MAX_EVENTTIMER; i++)
- if (sd->eventtimer[i] == -1)
+ if (!sd->eventtimer[i])
break;
if (i < MAX_EVENTTIMER)
{
- char *evname = (char *) calloc (24, 1);
- strncpy (evname, name, 24);
- evname[23] = '\0';
- sd->eventtimer[i] = add_timer (gettick () + tick,
- pc_eventtimer, sd->bl.id,
- (int) evname);
+ char *evname = (char *) calloc(24, 1);
+ strzcpy(evname, name, 24);
+ sd->eventtimer[i] = Timer(gettick() + tick,
+ std::bind(pc_eventtimer, ph::_1, ph::_2,
+ sd->bl.id, evname));
return 1;
}
@@ -7258,69 +4522,15 @@ int pc_addeventtimer (struct map_session_data *sd, int tick, const char *name)
}
/*==========================================
- * イベントタイマー削除
- *------------------------------------------
- */
-int pc_deleventtimer (struct map_session_data *sd, const char *name)
-{
- int i;
-
- nullpo_retr (0, sd);
-
- for (i = 0; i < MAX_EVENTTIMER; i++)
- if (sd->eventtimer[i] != -1 && strcmp ((char
- *) (get_timer (sd->eventtimer
- [i])->data),
- name) == 0)
- {
- delete_timer (sd->eventtimer[i], pc_eventtimer);
- sd->eventtimer[i] = -1;
- break;
- }
-
- return 0;
-}
-
-/*==========================================
- * イベントタイマーカウント値追加
- *------------------------------------------
- */
-int pc_addeventtimercount (struct map_session_data *sd, const char *name,
- int tick)
-{
- int i;
-
- nullpo_retr (0, sd);
-
- for (i = 0; i < MAX_EVENTTIMER; i++)
- if (sd->eventtimer[i] != -1 && strcmp ((char
- *) (get_timer (sd->eventtimer
- [i])->data),
- name) == 0)
- {
- addtick_timer (sd->eventtimer[i], tick);
- break;
- }
-
- return 0;
-}
-
-/*==========================================
* イベントタイマー全削除
*------------------------------------------
*/
-int pc_cleareventtimer (struct map_session_data *sd)
+int pc_cleareventtimer(struct map_session_data *sd)
{
- int i;
-
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
- for (i = 0; i < MAX_EVENTTIMER; i++)
- if (sd->eventtimer[i] != -1)
- {
- delete_timer (sd->eventtimer[i], pc_eventtimer);
- sd->eventtimer[i] = -1;
- }
+ for (int i = 0; i < MAX_EVENTTIMER; i++)
+ sd->eventtimer[i].cancel();
return 0;
}
@@ -7332,191 +4542,157 @@ int pc_cleareventtimer (struct map_session_data *sd)
* アイテムを装備ã™ã‚‹
*------------------------------------------
*/
-static int
-pc_signal_advanced_equipment_change (struct map_session_data *sd, int n)
-{
- if (sd->status.inventory[n].equip & 0x0040)
- clif_changelook (&sd->bl, LOOK_SHOES, 0);
- if (sd->status.inventory[n].equip & 0x0004)
- clif_changelook (&sd->bl, LOOK_GLOVES, 0);
- if (sd->status.inventory[n].equip & 0x0008)
- clif_changelook (&sd->bl, LOOK_CAPE, 0);
- if (sd->status.inventory[n].equip & 0x0010)
- clif_changelook (&sd->bl, LOOK_MISC1, 0);
- if (sd->status.inventory[n].equip & 0x0080)
- clif_changelook (&sd->bl, LOOK_MISC2, 0);
+static
+int pc_signal_advanced_equipment_change(struct map_session_data *sd, int n)
+{
+ if (bool(sd->status.inventory[n].equip & EPOS::SHOES))
+ clif_changelook(&sd->bl, LOOK::SHOES, 0);
+ if (bool(sd->status.inventory[n].equip & EPOS::GLOVES))
+ clif_changelook(&sd->bl, LOOK::GLOVES, 0);
+ if (bool(sd->status.inventory[n].equip & EPOS::CAPE))
+ clif_changelook(&sd->bl, LOOK::CAPE, 0);
+ if (bool(sd->status.inventory[n].equip & EPOS::MISC1))
+ clif_changelook(&sd->bl, LOOK::MISC1, 0);
+ if (bool(sd->status.inventory[n].equip & EPOS::MISC2))
+ clif_changelook(&sd->bl, LOOK::MISC2, 0);
return 0;
}
-int pc_equipitem (struct map_session_data *sd, int n, int pos)
+int pc_equipitem(struct map_session_data *sd, int n, EPOS)
{
- int i, nameid, arrow, view;
+ int nameid;
struct item_data *id;
//ソス]ソスソスソスソスソス{ソスqソスフ場åˆï½¿ï½½ï¾Œé¯‰ï½¿ï½½ï½¿ï½½ï¾Œè·ï½¿ï½½ï¾†ã‚‘ソスソスZソスoソスソスソスソス
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
if (n < 0 || n >= MAX_INVENTORY)
{
- clif_equipitemack (sd, 0, 0, 0);
+ clif_equipitemack(sd, 0, EPOS::ZERO, 0);
return 0;
}
nameid = sd->status.inventory[n].nameid;
id = sd->inventory_data[n];
- pos = pc_equippoint (sd, n);
+ if (!id) // can't actually happen - the only caller checks this.
+ return 0;
+ EPOS pos = pc_equippoint(sd, n);
if (battle_config.battle_log)
- printf ("equip %d(%d) %x:%x\n", nameid, n, id->equip, pos);
- if (!pc_isequip (sd, n) || !pos || sd->status.inventory[n].broken == 1)
+ PRINTF("equip %d (%d) %x:%x\n",
+ nameid, n, id->equip, pos);
+ if (!pc_isequip(sd, n) || pos == EPOS::ZERO || sd->status.inventory[n].broken == 1)
{ // [Valaris]
- clif_equipitemack (sd, n, 0, 0); // fail
+ clif_equipitemack(sd, n, EPOS::ZERO, 0); // fail
return 0;
}
// -- moonsoul (if player is berserk then cannot equip)
//
- if (sd->sc_data[SC_BERSERK].timer != -1)
- {
- clif_equipitemack (sd, n, 0, 0); // fail
- return 0;
- }
-
- if (pos == 0x88)
- { // アクセサリ用例外処ç†
- int epor = 0;
- if (sd->equip_index[0] >= 0)
- epor |= sd->status.inventory[sd->equip_index[0]].equip;
- if (sd->equip_index[1] >= 0)
- epor |= sd->status.inventory[sd->equip_index[1]].equip;
- epor &= 0x88;
- pos = epor == 0x08 ? 0x80 : 0x08;
- }
-
- // 二刀æµå‡¦ç†
- if ((pos == 0x22) // 一応ã€è£…å‚™è¦æ±‚箇所ãŒäºŒåˆ€æµæ­¦å™¨ã‹ãƒã‚§ãƒƒã‚¯ã™ã‚‹
- && (id->equip == 2) // å˜ æ‰‹æ­¦å™¨
- && (pc_checkskill (sd, AS_LEFT) > 0 || sd->status.pc_class == 12)) // 左手修錬有
+ if (pos == (EPOS::MISC2 | EPOS::CAPE))
{
- int tpos = 0;
- if (sd->equip_index[8] >= 0)
- tpos |= sd->status.inventory[sd->equip_index[8]].equip;
- if (sd->equip_index[9] >= 0)
- tpos |= sd->status.inventory[sd->equip_index[9]].equip;
- tpos &= 0x02;
- pos = tpos == 0x02 ? 0x20 : 0x02;
+ // アクセサリ用例外処ç†
+ EPOS epor = EPOS::ZERO;
+ if (sd->equip_index[EQUIP::MISC2] >= 0)
+ epor |= sd->status.inventory[sd->equip_index[EQUIP::MISC2]].equip;
+ if (sd->equip_index[EQUIP::CAPE] >= 0)
+ epor |= sd->status.inventory[sd->equip_index[EQUIP::CAPE]].equip;
+ epor &= (EPOS::MISC2 | EPOS::CAPE);
+ pos = (epor == EPOS::CAPE ? EPOS::MISC2 : EPOS::CAPE);
}
- arrow = pc_search_inventory (sd, pc_checkequip (sd, 9)); // Added by RoVeRT
- for (i = 0; i < 11; i++)
+ for (EQUIP i : EQUIPs)
{
- if (pos & equip_pos[i])
+ if (bool(pos & equip_pos[i]))
{
if (sd->equip_index[i] >= 0) //Slot taken, remove item from there.
- pc_unequipitem (sd, sd->equip_index[i], 1);
+ pc_unequipitem(sd, sd->equip_index[i], CalcStatus::LATER);
sd->equip_index[i] = n;
}
}
// 弓矢装備
- if (pos == 0x8000)
+ if (pos == EPOS::ARROW)
{
- clif_arrowequip (sd, n);
- clif_arrow_fail (sd, 3); // 3=矢ãŒè£…å‚™ã§ãã¾ã—ãŸ
+ clif_arrowequip(sd, n);
+ clif_arrow_fail(sd, 3); // 3=矢ãŒè£…å‚™ã§ãã¾ã—ãŸ
}
else
{
/* Don't update re-equipping if we're using a spell */
- if (!(pos == 4 && sd->attack_spell_override))
- clif_equipitemack (sd, n, pos, 1);
+ if (!(pos == EPOS::GLOVES && sd->attack_spell_override))
+ clif_equipitemack(sd, n, pos, 1);
}
- for (i = 0; i < 11; i++)
+ for (EQUIP i : EQUIPs)
{
- if (pos & equip_pos[i])
+ if (bool(pos & equip_pos[i]))
sd->equip_index[i] = n;
}
sd->status.inventory[n].equip = pos;
+ int view_i = 0;
+ ItemLook view_l = ItemLook::NONE;
+ // TODO: This is ugly.
if (sd->inventory_data[n])
{
- view = sd->inventory_data[n]->look;
- if (view == 0)
- view = sd->inventory_data[n]->nameid;
- }
- else
- {
- view = 0;
+ bool look_not_weapon = sd->inventory_data[n]->look == ItemLook::NONE;
+ bool equip_is_weapon = bool(sd->status.inventory[n].equip & EPOS::WEAPON);
+ assert (look_not_weapon != equip_is_weapon);
+
+ if (look_not_weapon)
+ view_i = sd->inventory_data[n]->nameid;
+ else
+ view_l = sd->inventory_data[n]->look;
}
- if (sd->status.inventory[n].equip & 0x0002)
+ if (bool(sd->status.inventory[n].equip & EPOS::WEAPON))
{
- sd->weapontype1 = view;
- pc_calcweapontype (sd);
- pc_set_weapon_look (sd);
+ sd->weapontype1 = view_l;
+ pc_calcweapontype(sd);
+ pc_set_weapon_look(sd);
}
- if (sd->status.inventory[n].equip & 0x0020)
+ if (bool(sd->status.inventory[n].equip & EPOS::SHIELD))
{
if (sd->inventory_data[n])
{
- if (sd->inventory_data[n]->type == 4)
+ if (sd->inventory_data[n]->type == ItemType::WEAPON)
{
sd->status.shield = 0;
- if (sd->status.inventory[n].equip == 0x0020)
- sd->weapontype2 = view;
+ if (sd->status.inventory[n].equip == EPOS::SHIELD)
+ sd->weapontype2 = view_l;
}
- else if (sd->inventory_data[n]->type == 5)
+ else if (sd->inventory_data[n]->type == ItemType::ARMOR)
{
- sd->status.shield = view;
- sd->weapontype2 = 0;
+ sd->status.shield = view_i;
+ sd->weapontype2 = ItemLook::NONE;
}
}
else
- sd->status.shield = sd->weapontype2 = 0;
- pc_calcweapontype (sd);
- clif_changelook (&sd->bl, LOOK_SHIELD, sd->status.shield);
- }
- if (sd->status.inventory[n].equip & 0x0001)
- {
- sd->status.head_bottom = view;
- clif_changelook (&sd->bl, LOOK_HEAD_BOTTOM, sd->status.head_bottom);
- }
- if (sd->status.inventory[n].equip & 0x0100)
- {
- sd->status.head_top = view;
- clif_changelook (&sd->bl, LOOK_HEAD_TOP, sd->status.head_top);
+ {
+ sd->status.shield = 0;
+ sd->weapontype2 = ItemLook::NONE;
+ }
+ pc_calcweapontype(sd);
+ clif_changelook(&sd->bl, LOOK::SHIELD, sd->status.shield);
}
- if (sd->status.inventory[n].equip & 0x0200)
+ if (bool(sd->status.inventory[n].equip & EPOS::LEGS))
{
- sd->status.head_mid = view;
- clif_changelook (&sd->bl, LOOK_HEAD_MID, sd->status.head_mid);
- }
- pc_signal_advanced_equipment_change (sd, n);
-
- pc_checkallowskill (sd); // 装備å“ã§ã‚¹ã‚­ãƒ«ã‹è§£é™¤ã•ã‚Œã‚‹ã‹ãƒã‚§ãƒƒã‚¯
- if (itemdb_look (sd->status.inventory[n].nameid) == 11 && arrow)
- { // Added by RoVeRT
- clif_arrowequip (sd, arrow);
- sd->status.inventory[arrow].equip = 32768;
+ sd->status.head_bottom = view_i;
+ clif_changelook(&sd->bl, LOOK::HEAD_BOTTOM, sd->status.head_bottom);
}
- pc_calcstatus (sd, 0);
-
- if (sd->special_state.infinite_endure)
+ if (bool(sd->status.inventory[n].equip & EPOS::HAT))
{
- if (sd->sc_data[SC_ENDURE].timer == -1)
- skill_status_change_start (&sd->bl, SC_ENDURE, 10, 1, 0, 0, 0, 0);
+ sd->status.head_top = view_i;
+ clif_changelook(&sd->bl, LOOK::HEAD_TOP, sd->status.head_top);
}
- else
+ if (bool(sd->status.inventory[n].equip & EPOS::TORSO))
{
- if (sd->sc_data[SC_ENDURE].timer != -1 && sd->sc_data[SC_ENDURE].val2)
- skill_status_change_end (&sd->bl, SC_ENDURE, -1);
+ sd->status.head_mid = view_i;
+ clif_changelook(&sd->bl, LOOK::HEAD_MID, sd->status.head_mid);
}
+ pc_signal_advanced_equipment_change(sd, n);
- if (sd->sc_data[SC_SIGNUMCRUCIS].timer != -1
- && !battle_check_undead (7, sd->def_ele))
- skill_status_change_end (&sd->bl, SC_SIGNUMCRUCIS, -1);
- if (sd->sc_data[SC_DANCING].timer != -1
- && (sd->status.weapon != 13 && sd->status.weapon != 14))
- skill_stop_dancing (&sd->bl, 0);
+ pc_calcstatus(sd, 0);
return 0;
}
@@ -7525,98 +4701,87 @@ int pc_equipitem (struct map_session_data *sd, int n, int pos)
* 装 å‚™ã—ãŸç‰©ã‚’外ã™
*------------------------------------------
*/
-int pc_unequipitem (struct map_session_data *sd, int n, int type)
+int pc_unequipitem(struct map_session_data *sd, int n, CalcStatus type)
{
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
// -- moonsoul (if player is berserk then cannot unequip)
//
- if (sd->sc_data[SC_BERSERK].timer != -1)
- {
- clif_unequipitemack (sd, n, 0, 0);
- return 0;
- }
-
if (battle_config.battle_log)
- printf ("unequip %d %x:%x\n", n, pc_equippoint (sd, n),
+ PRINTF("unequip %d %x:%x\n",
+ n, pc_equippoint(sd, n),
sd->status.inventory[n].equip);
- if (sd->status.inventory[n].equip)
+ if (bool(sd->status.inventory[n].equip))
{
- int i;
- for (i = 0; i < 11; i++)
+ for (EQUIP i : EQUIPs)
{
- if (sd->status.inventory[n].equip & equip_pos[i])
+ if (bool(sd->status.inventory[n].equip & equip_pos[i]))
sd->equip_index[i] = -1;
}
- if (sd->status.inventory[n].equip & 0x0002)
+ if (bool(sd->status.inventory[n].equip & EPOS::WEAPON))
{
- sd->weapontype1 = 0;
+ sd->weapontype1 = ItemLook::NONE;
sd->status.weapon = sd->weapontype2;
- pc_calcweapontype (sd);
- pc_set_weapon_look (sd);
+ pc_calcweapontype(sd);
+ pc_set_weapon_look(sd);
}
- if (sd->status.inventory[n].equip & 0x0020)
+ if (bool(sd->status.inventory[n].equip & EPOS::SHIELD))
{
- sd->status.shield = sd->weapontype2 = 0;
- pc_calcweapontype (sd);
- clif_changelook (&sd->bl, LOOK_SHIELD, sd->status.shield);
+ sd->status.shield = 0;
+ sd->weapontype2 = ItemLook::NONE;
+ pc_calcweapontype(sd);
+ clif_changelook(&sd->bl, LOOK::SHIELD, sd->status.shield);
}
- if (sd->status.inventory[n].equip & 0x0001)
+ if (bool(sd->status.inventory[n].equip & EPOS::LEGS))
{
sd->status.head_bottom = 0;
- clif_changelook (&sd->bl, LOOK_HEAD_BOTTOM,
+ clif_changelook(&sd->bl, LOOK::HEAD_BOTTOM,
sd->status.head_bottom);
}
- if (sd->status.inventory[n].equip & 0x0100)
+ if (bool(sd->status.inventory[n].equip & EPOS::HAT))
{
sd->status.head_top = 0;
- clif_changelook (&sd->bl, LOOK_HEAD_TOP, sd->status.head_top);
+ clif_changelook(&sd->bl, LOOK::HEAD_TOP, sd->status.head_top);
}
- if (sd->status.inventory[n].equip & 0x0200)
+ if (bool(sd->status.inventory[n].equip & EPOS::TORSO))
{
sd->status.head_mid = 0;
- clif_changelook (&sd->bl, LOOK_HEAD_MID, sd->status.head_mid);
+ clif_changelook(&sd->bl, LOOK::HEAD_MID, sd->status.head_mid);
}
- pc_signal_advanced_equipment_change (sd, n);
+ pc_signal_advanced_equipment_change(sd, n);
- if (sd->sc_data[SC_BROKNWEAPON].timer != -1
- && sd->status.inventory[n].equip & 0x0002
- && sd->status.inventory[i].broken == 1)
- skill_status_change_end (&sd->bl, SC_BROKNWEAPON, -1);
+ if (sd->sc_data[StatusChange::SC_BROKNWEAPON].timer
+ && bool(sd->status.inventory[n].equip & EPOS::WEAPON)
+ && sd->status.inventory[n].broken == 1)
+ skill_status_change_end(&sd->bl, StatusChange::SC_BROKNWEAPON, nullptr);
- clif_unequipitemack (sd, n, sd->status.inventory[n].equip, 1);
- sd->status.inventory[n].equip = 0;
- if (!type)
- pc_checkallowskill (sd);
- if (sd->weapontype1 == 0 && sd->weapontype2 == 0)
- skill_encchant_eremental_end (&sd->bl, -1); //武器æŒã¡èª“ãˆã¯ç„¡æ¡ä»¶ã§å±žæ€§ä»˜ä¸Žè§£é™¤
+ clif_unequipitemack(sd, n, sd->status.inventory[n].equip, 1);
+ sd->status.inventory[n].equip = EPOS::ZERO;
}
else
{
- clif_unequipitemack (sd, n, 0, 0);
+ clif_unequipitemack(sd, n, EPOS::ZERO, 0);
}
- if (!type)
+ if (type == CalcStatus::NOW)
{
- pc_calcstatus (sd, 0);
- if (sd->sc_data[SC_SIGNUMCRUCIS].timer != -1
- && !battle_check_undead (7, sd->def_ele))
- skill_status_change_end (&sd->bl, SC_SIGNUMCRUCIS, -1);
+ pc_calcstatus(sd, 0);
}
return 0;
}
-int pc_unequipinvyitem (struct map_session_data *sd, int n, int type)
+int pc_unequipinvyitem(struct map_session_data *sd, int n, CalcStatus type)
{
- int i;
-
- nullpo_retr (1, sd);
+ nullpo_retr(1, sd);
- for (i = 0; i < 11; i++)
+ for (EQUIP i : EQUIPs)
{
- if (equip_pos[i] > 0 && sd->equip_index[i] == n)
- { //Slot taken, remove item from there.
- pc_unequipitem (sd, sd->equip_index[i], type);
+ if (equip_pos[i] != EPOS::ZERO
+ && !bool(equip_pos[i] & EPOS::ARROW) // probably a bug
+ && sd->equip_index[i] == n)
+ {
+ //Slot taken, remove item from there.
+ pc_unequipitem(sd, sd->equip_index[i], type);
sd->equip_index[i] = -1;
}
}
@@ -7629,37 +4794,37 @@ int pc_unequipinvyitem (struct map_session_data *sd, int n, int type)
* 装 å‚™å“ã®è£…å‚™å¯èƒ½ãƒã‚§ãƒƒã‚¯ã‚’è¡Œãªã†
*------------------------------------------
*/
-int pc_checkitem (struct map_session_data *sd)
+int pc_checkitem(struct map_session_data *sd)
{
- int i, j, k, id, calc_flag = 0;
+ int i, j, k, id, calc_flag = 0;
struct item_data *it = NULL;
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
// 所æŒå“空ãè©°ã‚
for (i = j = 0; i < MAX_INVENTORY; i++)
{
if ((id = sd->status.inventory[i].nameid) == 0)
continue;
- if (battle_config.item_check && !itemdb_available (id))
+ if (battle_config.item_check && !itemdb_available(id))
{
if (battle_config.error_log)
- printf ("illeagal item id %d in %d[%s] inventory.\n", id,
+ PRINTF("illeagal item id %d in %d[%s] inventory.\n", id,
sd->bl.id, sd->status.name);
- pc_delitem (sd, i, sd->status.inventory[i].amount, 3);
+ pc_delitem(sd, i, sd->status.inventory[i].amount, 3);
continue;
}
if (i > j)
{
- memcpy (&sd->status.inventory[j], &sd->status.inventory[i],
- sizeof (struct item));
+ memcpy(&sd->status.inventory[j], &sd->status.inventory[i],
+ sizeof(struct item));
sd->inventory_data[j] = sd->inventory_data[i];
}
j++;
}
if (j < MAX_INVENTORY)
- memset (&sd->status.inventory[j], 0,
- sizeof (struct item) * (MAX_INVENTORY - j));
+ memset(&sd->status.inventory[j], 0,
+ sizeof(struct item) * (MAX_INVENTORY - j));
for (k = j; k < MAX_INVENTORY; k++)
sd->inventory_data[k] = NULL;
@@ -7668,24 +4833,24 @@ int pc_checkitem (struct map_session_data *sd)
{
if ((id = sd->status.cart[i].nameid) == 0)
continue;
- if (battle_config.item_check && !itemdb_available (id))
+ if (battle_config.item_check && !itemdb_available(id))
{
if (battle_config.error_log)
- printf ("illeagal item id %d in %d[%s] cart.\n", id,
+ PRINTF("illeagal item id %d in %d[%s] cart.\n", id,
sd->bl.id, sd->status.name);
- pc_cart_delitem (sd, i, sd->status.cart[i].amount, 1);
+ pc_cart_delitem(sd, i, sd->status.cart[i].amount, 1);
continue;
}
if (i > j)
{
- memcpy (&sd->status.cart[j], &sd->status.cart[i],
- sizeof (struct item));
+ memcpy(&sd->status.cart[j], &sd->status.cart[i],
+ sizeof(struct item));
}
j++;
}
if (j < MAX_CART)
- memset (&sd->status.cart[j], 0,
- sizeof (struct item) * (MAX_CART - j));
+ memset(&sd->status.cart[j], 0,
+ sizeof(struct item) * (MAX_CART - j));
// 装 å‚™ä½ç½®ãƒã‚§ãƒƒã‚¯
@@ -7696,59 +4861,54 @@ int pc_checkitem (struct map_session_data *sd)
if (sd->status.inventory[i].nameid == 0)
continue;
- if (sd->status.inventory[i].equip & ~pc_equippoint (sd, i))
+ if (bool(sd->status.inventory[i].equip & ~pc_equippoint(sd, i)))
{
- sd->status.inventory[i].equip = 0;
+ sd->status.inventory[i].equip = EPOS::ZERO;
calc_flag = 1;
}
//装備制é™ãƒã‚§ãƒƒã‚¯
- if (sd->status.inventory[i].equip && map[sd->bl.m].flag.pvp
+ if (bool(sd->status.inventory[i].equip)
+ && map[sd->bl.m].flag.pvp
&& (it->flag.no_equip == 1 || it->flag.no_equip == 3))
{ //PvP制é™
- sd->status.inventory[i].equip = 0;
- calc_flag = 1;
- }
- else if (sd->status.inventory[i].equip && map[sd->bl.m].flag.gvg
- && (it->flag.no_equip == 2 || it->flag.no_equip == 3))
- { //GvG制é™
- sd->status.inventory[i].equip = 0;
+ sd->status.inventory[i].equip = EPOS::ZERO;
calc_flag = 1;
}
}
- pc_setequipindex (sd);
+ pc_setequipindex(sd);
if (calc_flag)
- pc_calcstatus (sd, 2);
+ pc_calcstatus(sd, 2);
return 0;
}
-int pc_checkoverhp (struct map_session_data *sd)
+int pc_checkoverhp(struct map_session_data *sd)
{
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
if (sd->status.hp == sd->status.max_hp)
return 1;
if (sd->status.hp > sd->status.max_hp)
{
sd->status.hp = sd->status.max_hp;
- clif_updatestatus (sd, SP_HP);
+ clif_updatestatus(sd, SP::HP);
return 2;
}
return 0;
}
-int pc_checkoversp (struct map_session_data *sd)
+int pc_checkoversp(struct map_session_data *sd)
{
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
if (sd->status.sp == sd->status.max_sp)
return 1;
if (sd->status.sp > sd->status.max_sp)
{
sd->status.sp = sd->status.max_sp;
- clif_updatestatus (sd, SP_SP);
+ clif_updatestatus(sd, SP::SP);
return 2;
}
@@ -7760,41 +4920,36 @@ int pc_checkoversp (struct map_session_data *sd)
*------------------------------------------
*/
static
-int pc_calc_pvprank_sub (struct block_list *bl, va_list ap)
+void pc_calc_pvprank_sub(struct block_list *bl, struct map_session_data *sd2)
{
- struct map_session_data *sd1, *sd2 = NULL;
+ struct map_session_data *sd1;
- nullpo_retr (0, bl);
- nullpo_retr (0, ap);
- nullpo_retr (0, sd1 = (struct map_session_data *) bl);
- nullpo_retr (0, sd2 = va_arg (ap, struct map_session_data *));
+ nullpo_retv(bl);
+ sd1 = (struct map_session_data *) bl;
+ nullpo_retv(sd2);
if (sd1->pvp_point > sd2->pvp_point)
sd2->pvp_rank++;
- return 0;
}
/*==========================================
* PVPé †ä½è¨ˆç®—
*------------------------------------------
*/
-int pc_calc_pvprank (struct map_session_data *sd)
+int pc_calc_pvprank(struct map_session_data *sd)
{
- int old;
struct map_data *m;
- nullpo_retr (0, sd);
- nullpo_retr (0, m = &map[sd->bl.m]);
-
- old = sd->pvp_rank;
+ nullpo_ret(sd);
+ m = &map[sd->bl.m];
+ nullpo_ret(m);
if (!(m->flag.pvp))
return 0;
sd->pvp_rank = 1;
- map_foreachinarea (pc_calc_pvprank_sub, sd->bl.m, 0, 0, m->xs, m->ys,
- BL_PC, sd);
- if (old != sd->pvp_rank || sd->pvp_lastusers != m->users)
- clif_pvpset (sd, sd->pvp_rank, sd->pvp_lastusers = m->users, 0);
+ map_foreachinarea(std::bind(pc_calc_pvprank_sub, ph::_1, sd),
+ sd->bl.m, 0, 0, m->xs, m->ys,
+ BL::PC);
return sd->pvp_rank;
}
@@ -7802,26 +4957,28 @@ int pc_calc_pvprank (struct map_session_data *sd)
* PVPé †ä½è¨ˆç®—(timer)
*------------------------------------------
*/
-void pc_calc_pvprank_timer (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data)
+void pc_calc_pvprank_timer(TimerData *, tick_t, int id)
{
struct map_session_data *sd = NULL;
if (battle_config.pk_mode) // disable pvp ranking if pk_mode on [Valaris]
return;
- sd = map_id2sd (id);
+ sd = map_id2sd(id);
if (sd == NULL)
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);
+ sd->pvp_timer.cancel();
+ if (pc_calc_pvprank(sd) > 0)
+ sd->pvp_timer = Timer(gettick() + PVP_CALCRANK_INTERVAL,
+ std::bind(pc_calc_pvprank_timer, ph::_1, ph::_2,
+ id));
}
/*==========================================
* sdã¯çµå©šã—ã¦ã„ã‚‹ã‹(既婚ã®å ´åˆã¯ç›¸æ–¹ã®char_idã‚’è¿”ã™)
*------------------------------------------
*/
-int pc_ismarried (struct map_session_data *sd)
+static
+int pc_ismarried(struct map_session_data *sd)
{
if (sd == NULL)
return -1;
@@ -7835,7 +4992,7 @@ int pc_ismarried (struct map_session_data *sd)
* sdãŒdstsdã¨çµå©š(dstsd→sdã®çµå©šå‡¦ç†ã‚‚åŒæ™‚ã«è¡Œã†)
*------------------------------------------
*/
-int pc_marriage (struct map_session_data *sd, struct map_session_data *dstsd)
+int pc_marriage(struct map_session_data *sd, struct map_session_data *dstsd)
{
if (sd == NULL || dstsd == NULL || sd->status.partner_id > 0
|| dstsd->status.partner_id > 0)
@@ -7849,20 +5006,20 @@ int pc_marriage (struct map_session_data *sd, struct map_session_data *dstsd)
* sdãŒé›¢å©š(相手ã¯sd->status.partner_idã«ä¾ã‚‹)(相手もåŒæ™‚ã«é›¢å©šãƒ»çµå©šæŒ‡è¼ªè‡ªå‹•å‰¥å¥ª)
*------------------------------------------
*/
-int pc_divorce (struct map_session_data *sd)
+int pc_divorce(struct map_session_data *sd)
{
struct map_session_data *p_sd = NULL;
- if (sd == NULL || !pc_ismarried (sd))
+ if (sd == NULL || !pc_ismarried(sd))
return -1;
// If both are on map server we don't need to bother the char server
if ((p_sd =
- map_nick2sd (map_charid2nick (sd->status.partner_id))) != NULL)
+ map_nick2sd(map_charid2nick(sd->status.partner_id))) != NULL)
{
if (p_sd->status.partner_id != sd->status.char_id
|| sd->status.partner_id != p_sd->status.char_id)
{
- printf ("pc_divorce: Illegal partner_id sd=%d p_sd=%d\n",
+ PRINTF("pc_divorce: Illegal partner_id sd=%d p_sd=%d\n",
sd->status.partner_id, p_sd->status.partner_id);
return -1;
}
@@ -7872,11 +5029,11 @@ int pc_divorce (struct map_session_data *sd)
if (sd->npc_flags.divorce)
{
sd->npc_flags.divorce = 0;
- map_scriptcont (sd, sd->npc_id);
+ map_scriptcont(sd, sd->npc_id);
}
}
else
- chrif_send_divorce (sd->status.char_id);
+ chrif_send_divorce(sd->status.char_id);
return 0;
}
@@ -7885,19 +5042,19 @@ int pc_divorce (struct map_session_data *sd)
* sdã®ç›¸æ–¹ã®map_session_dataã‚’è¿”ã™
*------------------------------------------
*/
-struct map_session_data *pc_get_partner (struct map_session_data *sd)
+struct map_session_data *pc_get_partner(struct map_session_data *sd)
{
struct map_session_data *p_sd = NULL;
char *nick;
- if (sd == NULL || !pc_ismarried (sd))
+ if (sd == NULL || !pc_ismarried(sd))
return NULL;
- nick = map_charid2nick (sd->status.partner_id);
+ nick = map_charid2nick(sd->status.partner_id);
if (nick == NULL)
return NULL;
- if ((p_sd = map_nick2sd (nick)) == NULL)
+ if ((p_sd = map_nick2sd(nick)) == NULL)
return NULL;
return p_sd;
@@ -7910,29 +5067,20 @@ struct map_session_data *pc_get_partner (struct map_session_data *sd)
* SP回復é‡è¨ˆç®—
*------------------------------------------
*/
-static int natural_heal_tick, natural_heal_prev_tick, natural_heal_diff_tick;
-static int pc_spheal (struct map_session_data *sd)
-{
- int a;
- struct guild_castle *gc = NULL;
+static
+tick_t natural_heal_tick, natural_heal_prev_tick;
+static
+interval_t natural_heal_diff_tick;
- nullpo_retr (0, sd);
+static
+interval_t pc_spheal(struct map_session_data *sd)
+{
+ nullpo_retr(interval_t::zero(), sd);
- a = natural_heal_diff_tick;
- if (pc_issit (sd))
- a += a;
- if (sd->sc_data[SC_MAGNIFICAT].timer != -1) // マグニフィカート
+ interval_t a = natural_heal_diff_tick;
+ if (pc_issit(sd))
a += a;
- gc = guild_mapname2gc (sd->mapname); // Increased guild castle regen [Valaris]
- if (gc)
- {
- struct guild *g;
- g = guild_search (sd->status.guild_id);
- if (g && g->guild_id == gc->guild_id)
- a += a;
- } // end addition [Valaris]
-
return a;
}
@@ -7940,333 +5088,154 @@ static int pc_spheal (struct map_session_data *sd)
* HP回復é‡è¨ˆç®—
*------------------------------------------
*/
-static int pc_hpheal (struct map_session_data *sd)
+static
+interval_t pc_hpheal(struct map_session_data *sd)
{
- int a;
- struct guild_castle *gc;
-
- nullpo_retr (0, sd);
+ nullpo_retr(interval_t::zero(), sd);
- a = natural_heal_diff_tick;
- if (pc_issit (sd))
+ interval_t a = natural_heal_diff_tick;
+ if (pc_issit(sd))
a += a;
- if (sd->sc_data[SC_MAGNIFICAT].timer != -1) // Modified by RoVeRT
- a += a;
-
- gc = guild_mapname2gc (sd->mapname); // Increased guild castle regen [Valaris]
- if (gc)
- {
- struct guild *g;
- g = guild_search (sd->status.guild_id);
- if (g && g->guild_id == gc->guild_id)
- a += a;
- } // end addition [Valaris]
return a;
}
-static int pc_natural_heal_hp (struct map_session_data *sd)
+static
+int pc_natural_heal_hp(struct map_session_data *sd)
{
- int bhp;
- int inc_num, bonus, skill, hp_flag;
-
- nullpo_retr (0, sd);
+ int bhp;
+ int bonus;
- if (sd->sc_data[SC_TRICKDEAD].timer != -1) // Modified by RoVeRT
- return 0;
+ nullpo_ret(sd);
- if (pc_checkoverhp (sd))
+ if (pc_checkoverhp(sd))
{
- sd->hp_sub = sd->inchealhptick = 0;
+ sd->hp_sub = sd->inchealhptick = interval_t::zero();
return 0;
}
bhp = sd->status.hp;
- hp_flag = (pc_checkskill (sd, SM_MOVINGRECOVERY) > 0
- && sd->walktimer != -1);
- if (sd->walktimer == -1)
+ if (!sd->walktimer)
{
- inc_num = pc_hpheal (sd);
- if (sd->sc_data[SC_TENSIONRELAX].timer != -1)
- { // テンションリラックス
- sd->hp_sub += 2 * inc_num;
- sd->inchealhptick += 3 * natural_heal_diff_tick;
- }
- else
- {
- sd->hp_sub += inc_num;
- sd->inchealhptick += natural_heal_diff_tick;
- }
- }
- else if (hp_flag)
- {
- inc_num = pc_hpheal (sd);
+ interval_t inc_num = pc_hpheal(sd);
sd->hp_sub += inc_num;
- sd->inchealhptick = 0;
+ sd->inchealhptick += natural_heal_diff_tick;
}
else
{
- sd->hp_sub = sd->inchealhptick = 0;
+ sd->hp_sub = sd->inchealhptick = interval_t::zero();
return 0;
}
- if (sd->hp_sub >= battle_config.natural_healhp_interval)
+ if (sd->hp_sub >= static_cast<interval_t>(battle_config.natural_healhp_interval))
{
bonus = sd->nhealhp;
- if (hp_flag)
- {
- bonus >>= 2;
- if (bonus <= 0)
- bonus = 1;
- }
- while (sd->hp_sub >= battle_config.natural_healhp_interval)
+ while (sd->hp_sub >= static_cast<interval_t>(battle_config.natural_healhp_interval))
{
- sd->hp_sub -= battle_config.natural_healhp_interval;
+ sd->hp_sub -= static_cast<interval_t>(battle_config.natural_healhp_interval);
if (sd->status.hp + bonus <= sd->status.max_hp)
sd->status.hp += bonus;
else
{
sd->status.hp = sd->status.max_hp;
- sd->hp_sub = sd->inchealhptick = 0;
+ sd->hp_sub = sd->inchealhptick = interval_t::zero();
}
}
}
if (bhp != sd->status.hp)
- clif_updatestatus (sd, SP_HP);
+ clif_updatestatus(sd, SP::HP);
if (sd->nshealhp > 0)
{
- if (sd->inchealhptick >= battle_config.natural_heal_skill_interval
+ if (sd->inchealhptick >= static_cast<interval_t>(battle_config.natural_heal_skill_interval)
&& sd->status.hp < sd->status.max_hp)
{
bonus = sd->nshealhp;
- while (sd->inchealhptick >=
- battle_config.natural_heal_skill_interval)
- {
- sd->inchealhptick -=
- battle_config.natural_heal_skill_interval;
- if (sd->status.hp + bonus <= sd->status.max_hp)
- sd->status.hp += bonus;
- else
- {
- bonus = sd->status.max_hp - sd->status.hp;
- sd->status.hp = sd->status.max_hp;
- sd->hp_sub = sd->inchealhptick = 0;
- }
- clif_heal (sd->fd, SP_HP, bonus);
- }
- }
- }
- else
- sd->inchealhptick = 0;
-
- return 0;
-
- if (sd->sc_data[SC_APPLEIDUN].timer != -1)
- { // Apple of Idun
- if (sd->inchealhptick >= 6000 && sd->status.hp < sd->status.max_hp)
- {
- bonus = skill * 20;
- while (sd->inchealhptick >= 6000)
+ while (sd->inchealhptick >= static_cast<interval_t>(battle_config.natural_heal_skill_interval))
{
- sd->inchealhptick -= 6000;
+ sd->inchealhptick -= static_cast<interval_t>(battle_config.natural_heal_skill_interval);
if (sd->status.hp + bonus <= sd->status.max_hp)
sd->status.hp += bonus;
else
{
bonus = sd->status.max_hp - sd->status.hp;
sd->status.hp = sd->status.max_hp;
- sd->hp_sub = sd->inchealhptick = 0;
+ sd->hp_sub = sd->inchealhptick = interval_t::zero();
}
- clif_heal (sd->fd, SP_HP, bonus);
}
}
}
else
- sd->inchealhptick = 0;
+ sd->inchealhptick = interval_t::zero();
return 0;
}
-static int pc_natural_heal_sp (struct map_session_data *sd)
+static
+int pc_natural_heal_sp(struct map_session_data *sd)
{
- int bsp;
- int inc_num, bonus;
+ int bsp;
+ int bonus;
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
- if (sd->sc_data[SC_TRICKDEAD].timer != -1) // Modified by RoVeRT
- return 0;
-
- if (pc_checkoversp (sd))
+ if (pc_checkoversp(sd))
{
- sd->sp_sub = sd->inchealsptick = 0;
+ sd->sp_sub = sd->inchealsptick = interval_t::zero();
return 0;
}
bsp = sd->status.sp;
- inc_num = pc_spheal (sd);
- if (sd->sc_data[SC_EXPLOSIONSPIRITS].timer == -1)
- sd->sp_sub += inc_num;
- if (sd->walktimer == -1)
+ interval_t inc_num = pc_spheal(sd);
+ sd->sp_sub += inc_num;
+ if (!sd->walktimer)
sd->inchealsptick += natural_heal_diff_tick;
else
- sd->inchealsptick = 0;
+ sd->inchealsptick = interval_t::zero();
- if (sd->sp_sub >= battle_config.natural_healsp_interval)
+ if (sd->sp_sub >= static_cast<interval_t>(battle_config.natural_healsp_interval))
{
- bonus = sd->nhealsp;;
- while (sd->sp_sub >= battle_config.natural_healsp_interval)
+ bonus = sd->nhealsp;
+ while (sd->sp_sub >= static_cast<interval_t>(battle_config.natural_healsp_interval))
{
- sd->sp_sub -= battle_config.natural_healsp_interval;
+ sd->sp_sub -= static_cast<interval_t>(battle_config.natural_healsp_interval);
if (sd->status.sp + bonus <= sd->status.max_sp)
sd->status.sp += bonus;
else
{
sd->status.sp = sd->status.max_sp;
- sd->sp_sub = sd->inchealsptick = 0;
+ sd->sp_sub = sd->inchealsptick = interval_t::zero();
}
}
}
if (bsp != sd->status.sp)
- clif_updatestatus (sd, SP_SP);
+ clif_updatestatus(sd, SP::SP);
if (sd->nshealsp > 0)
{
- if (sd->inchealsptick >= battle_config.natural_heal_skill_interval
+ if (sd->inchealsptick >= static_cast<interval_t>(battle_config.natural_heal_skill_interval)
&& sd->status.sp < sd->status.max_sp)
{
- struct pc_base_job s_class = pc_calc_base_job (sd->status.pc_class);
- if (sd->doridori_counter && s_class.job == 23)
- bonus = sd->nshealsp * 2;
- else
- bonus = sd->nshealsp;
- sd->doridori_counter = 0;
- while (sd->inchealsptick >=
- battle_config.natural_heal_skill_interval)
+ bonus = sd->nshealsp;
+ while (sd->inchealsptick >= static_cast<interval_t>(battle_config.natural_heal_skill_interval))
{
- sd->inchealsptick -=
- battle_config.natural_heal_skill_interval;
+ sd->inchealsptick -= static_cast<interval_t>(battle_config.natural_heal_skill_interval);
if (sd->status.sp + bonus <= sd->status.max_sp)
sd->status.sp += bonus;
else
{
bonus = sd->status.max_sp - sd->status.sp;
sd->status.sp = sd->status.max_sp;
- sd->sp_sub = sd->inchealsptick = 0;
+ sd->sp_sub = sd->inchealsptick = interval_t::zero();
}
- clif_heal (sd->fd, SP_SP, bonus);
}
}
}
else
- sd->inchealsptick = 0;
-
- return 0;
-}
-
-static int pc_spirit_heal_hp (struct map_session_data *sd, int level)
-{
- int bonus_hp, interval = battle_config.natural_heal_skill_interval;
- struct status_change *sc_data = battle_get_sc_data (&sd->bl);
-
- nullpo_retr (0, sd);
-
- if (pc_checkoverhp (sd))
- {
- sd->inchealspirithptick = 0;
- return 0;
- }
-
- sd->inchealspirithptick += natural_heal_diff_tick;
-
- if (sd->weight * 100 / sd->max_weight >=
- battle_config.natural_heal_weight_rate
- && sc_data[SC_FLYING_BACKPACK].timer == -1)
- interval += interval;
-
- if (sd->inchealspirithptick >= interval)
- {
- bonus_hp = sd->nsshealhp;
- while (sd->inchealspirithptick >= interval)
- {
- if (pc_issit (sd))
- {
- sd->inchealspirithptick -= interval;
- if (sd->status.hp < sd->status.max_hp)
- {
- if (sd->status.hp + bonus_hp <= sd->status.max_hp)
- sd->status.hp += bonus_hp;
- else
- {
- bonus_hp = sd->status.max_hp - sd->status.hp;
- sd->status.hp = sd->status.max_hp;
- }
- clif_heal (sd->fd, SP_HP, bonus_hp);
- sd->inchealspirithptick = 0;
- }
- }
- else
- {
- sd->inchealspirithptick -= natural_heal_diff_tick;
- break;
- }
- }
- }
-
- return 0;
-}
-
-static int pc_spirit_heal_sp (struct map_session_data *sd, int level)
-{
- int bonus_sp, interval = battle_config.natural_heal_skill_interval;
-
- nullpo_retr (0, sd);
-
- if (pc_checkoversp (sd))
- {
- sd->inchealspiritsptick = 0;
- return 0;
- }
-
- sd->inchealspiritsptick += natural_heal_diff_tick;
-
- if (sd->weight * 100 / sd->max_weight >=
- battle_config.natural_heal_weight_rate)
- interval += interval;
-
- if (sd->inchealspiritsptick >= interval)
- {
- bonus_sp = sd->nsshealsp;
- while (sd->inchealspiritsptick >= interval)
- {
- if (pc_issit (sd))
- {
- sd->inchealspiritsptick -= interval;
- if (sd->status.sp < sd->status.max_sp)
- {
- if (sd->status.sp + bonus_sp <= sd->status.max_sp)
- sd->status.sp += bonus_sp;
- else
- {
- bonus_sp = sd->status.max_sp - sd->status.sp;
- sd->status.sp = sd->status.max_sp;
- }
- clif_heal (sd->fd, SP_SP, bonus_sp);
- sd->inchealspiritsptick = 0;
- }
- }
- else
- {
- sd->inchealspiritsptick -= natural_heal_diff_tick;
- break;
- }
- }
- }
-
+ sd->inchealsptick = interval_t::zero();
return 0;
}
@@ -8275,14 +5244,14 @@ static int pc_spirit_heal_sp (struct map_session_data *sd, int level)
*------------------------------------------
*/
-static int
-pc_quickregenerate_effect (struct quick_regeneration *quick_regen,
+static
+int pc_quickregenerate_effect(struct quick_regeneration *quick_regen,
int heal_speed)
{
if (!(quick_regen->tickdelay--))
{
- int bonus =
- MIN (heal_speed * battle_config.itemheal_regeneration_factor,
+ int bonus =
+ min(heal_speed * battle_config.itemheal_regeneration_factor,
quick_regen->amount);
quick_regen->amount -= bonus;
@@ -8295,11 +5264,10 @@ pc_quickregenerate_effect (struct quick_regeneration *quick_regen,
return 0;
}
-static int pc_natural_heal_sub (struct map_session_data *sd, va_list ap)
+static
+void pc_natural_heal_sub(struct map_session_data *sd)
{
- int skill;
-
- nullpo_retr (0, sd);
+ nullpo_retv(sd);
if (sd->heal_xp > 0)
{
@@ -8313,7 +5281,7 @@ static int pc_natural_heal_sub (struct map_session_data *sd, va_list ap)
if (sd->spellpower_bonus_target < sd->spellpower_bonus_current)
{
sd->spellpower_bonus_current = sd->spellpower_bonus_target;
- pc_calcstatus (sd, 0);
+ pc_calcstatus(sd, 0);
}
else if (sd->spellpower_bonus_target > sd->spellpower_bonus_current)
{
@@ -8321,55 +5289,40 @@ static int pc_natural_heal_sub (struct map_session_data *sd, va_list ap)
1 +
((sd->spellpower_bonus_target -
sd->spellpower_bonus_current) >> 5);
- pc_calcstatus (sd, 0);
+ pc_calcstatus(sd, 0);
}
- if (sd->sc_data[SC_HALT_REGENERATE].timer != -1)
- return 0;
+ if (sd->sc_data[StatusChange::SC_HALT_REGENERATE].timer)
+ return;
if (sd->quick_regeneration_hp.amount || sd->quick_regeneration_sp.amount)
{
- int hp_bonus = pc_quickregenerate_effect (&sd->quick_regeneration_hp,
- (sd->sc_data[SC_POISON].timer == -1 || sd->sc_data[SC_SLOWPOISON].timer != -1) ? sd->nhealhp : 1); // [fate] slow down when poisoned
- int sp_bonus = pc_quickregenerate_effect (&sd->quick_regeneration_sp,
+ int hp_bonus = pc_quickregenerate_effect(&sd->quick_regeneration_hp,
+ (!sd->sc_data[StatusChange::SC_POISON].timer
+ || sd->sc_data[StatusChange::SC_SLOWPOISON].timer)
+ ? sd->nhealhp
+ : 1); // [fate] slow down when poisoned
+ int sp_bonus = pc_quickregenerate_effect(&sd->quick_regeneration_sp,
sd->nhealsp);
- pc_itemheal_effect (sd, hp_bonus, sp_bonus);
+ pc_itemheal_effect(sd, hp_bonus, sp_bonus);
}
- skill_update_heal_animation (sd); // if needed.
+ skill_update_heal_animation(sd); // if needed.
-// -- moonsoul (if conditions below altered to disallow natural healing if under berserk status)
- if ((sd->sc_data[SC_FLYING_BACKPACK].timer != -1
- || battle_config.natural_heal_weight_rate > 100
- || sd->weight * 100 / sd->max_weight <
- battle_config.natural_heal_weight_rate) && !pc_isdead (sd)
- && !pc_ishiding (sd) && sd->sc_data[SC_POISON].timer == -1)
- {
- pc_natural_heal_hp (sd);
- if (sd->sc_data && sd->sc_data[SC_EXTREMITYFIST].timer == -1 && //阿修羅状態ã§ã¯SPãŒå›žå¾©ã—ãªã„
- sd->sc_data[SC_DANCING].timer == -1 && //ダンス状態ã§ã¯SPãŒå›žå¾©ã—ãªã„
- sd->sc_data[SC_BERSERK].timer == -1 //ãƒãƒ¼ã‚µãƒ¼ã‚¯çŠ¶æ…‹ã§ã¯SPãŒå›žå¾©ã—ãªã„
- )
- pc_natural_heal_sp (sd);
- }
- else
+ if ((sd->sc_data[StatusChange::SC_FLYING_BACKPACK].timer
+ || battle_config.natural_heal_weight_rate > 100
+ || sd->weight * 100 / sd->max_weight < battle_config.natural_heal_weight_rate)
+ && !pc_isdead(sd)
+ && !sd->sc_data[StatusChange::SC_POISON].timer)
{
- sd->hp_sub = sd->inchealhptick = 0;
- sd->sp_sub = sd->inchealsptick = 0;
- }
- if ((skill = pc_checkskill (sd, MO_SPIRITSRECOVERY)) > 0
- && !pc_ishiding (sd) && sd->sc_data[SC_POISON].timer == -1
- && sd->sc_data[SC_BERSERK].timer == -1)
- {
- pc_spirit_heal_hp (sd, skill);
- pc_spirit_heal_sp (sd, skill);
+ pc_natural_heal_hp(sd);
+ pc_natural_heal_sp(sd);
}
else
{
- sd->inchealspirithptick = 0;
- sd->inchealspiritsptick = 0;
+ sd->hp_sub = sd->inchealhptick = interval_t::zero();
+ sd->sp_sub = sd->inchealsptick = interval_t::zero();
}
- return 0;
}
/*==========================================
@@ -8377,12 +5330,11 @@ static int pc_natural_heal_sub (struct map_session_data *sd, va_list ap)
*------------------------------------------
*/
static
-void pc_natural_heal (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data)
+void pc_natural_heal(TimerData *, tick_t tick)
{
natural_heal_tick = tick;
- natural_heal_diff_tick =
- DIFF_TICK (natural_heal_tick, natural_heal_prev_tick);
- clif_foreachclient (pc_natural_heal_sub);
+ natural_heal_diff_tick = natural_heal_tick - natural_heal_prev_tick;
+ clif_foreachclient(pc_natural_heal_sub);
natural_heal_prev_tick = tick;
}
@@ -8391,11 +5343,11 @@ void pc_natural_heal (timer_id tid, tick_t tick, custom_id_t id, custom_data_t d
* セーブãƒã‚¤ãƒ³ãƒˆã®ä¿å­˜
*------------------------------------------
*/
-int pc_setsavepoint (struct map_session_data *sd, const char *mapname, int x, int y)
+int pc_setsavepoint(struct map_session_data *sd, const char *mapname, int x, int y)
{
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
- strncpy (sd->status.save_point.map, mapname, 23);
+ strncpy(sd->status.save_point.map, mapname, 23);
sd->status.save_point.map[23] = '\0';
sd->status.save_point.x = x;
sd->status.save_point.y = y;
@@ -8407,47 +5359,21 @@ int pc_setsavepoint (struct map_session_data *sd, const char *mapname, int x, in
* 自動セーブ å„クライアント
*------------------------------------------
*/
-static int last_save_fd, save_flag;
-static int pc_autosave_sub (struct map_session_data *sd, va_list ap)
+static
+int last_save_fd, save_flag;
+static
+void pc_autosave_sub(struct map_session_data *sd)
{
- nullpo_retr (0, sd);
+ nullpo_retv(sd);
if (save_flag == 0 && sd->fd > last_save_fd)
{
- struct guild_castle *gc = NULL;
- int i;
-
- pc_makesavestatus (sd);
- chrif_save (sd);
-
- for (i = 0; i < MAX_GUILDCASTLE; i++)
- {
- gc = guild_castle_search (i);
- if (!gc)
- continue;
- if (gc->visibleG0 == 1)
- guild_castledatasave (gc->castle_id, 18, gc->Ghp0);
- if (gc->visibleG1 == 1)
- guild_castledatasave (gc->castle_id, 19, gc->Ghp1);
- if (gc->visibleG2 == 1)
- guild_castledatasave (gc->castle_id, 20, gc->Ghp2);
- if (gc->visibleG3 == 1)
- guild_castledatasave (gc->castle_id, 21, gc->Ghp3);
- if (gc->visibleG4 == 1)
- guild_castledatasave (gc->castle_id, 22, gc->Ghp4);
- if (gc->visibleG5 == 1)
- guild_castledatasave (gc->castle_id, 23, gc->Ghp5);
- if (gc->visibleG6 == 1)
- guild_castledatasave (gc->castle_id, 24, gc->Ghp6);
- if (gc->visibleG7 == 1)
- guild_castledatasave (gc->castle_id, 25, gc->Ghp7);
- }
+ pc_makesavestatus(sd);
+ chrif_save(sd);
save_flag = 1;
last_save_fd = sd->fd;
}
-
- return 0;
}
/*==========================================
@@ -8455,578 +5381,109 @@ static int pc_autosave_sub (struct map_session_data *sd, va_list ap)
*------------------------------------------
*/
static
-void pc_autosave (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data)
+void pc_autosave(TimerData *, tick_t)
{
- int interval;
-
save_flag = 0;
- clif_foreachclient (pc_autosave_sub);
+ clif_foreachclient(pc_autosave_sub);
if (save_flag == 0)
last_save_fd = 0;
- interval = autosave_interval / (clif_countusers () + 1);
- if (interval <= 0)
- interval = 1;
- add_timer (gettick () + interval, pc_autosave, 0, 0);
+ interval_t interval = autosave_interval / (clif_countusers() + 1);
+ if (interval <= interval_t::zero())
+ interval = std::chrono::milliseconds(1);
+ Timer(gettick() + interval,
+ pc_autosave
+ ).detach();
}
-int pc_read_gm_account (int fd)
+int pc_read_gm_account(int fd)
{
- int i = 0;
+ int i = 0;
if (gm_account != NULL)
- free (gm_account);
+ free(gm_account);
GM_num = 0;
- CREATE (gm_account, struct gm_account, (RFIFOW (fd, 2) - 4) / 5);
- for (i = 4; i < RFIFOW (fd, 2); i = i + 5)
+ CREATE(gm_account, struct gm_account, (RFIFOW(fd, 2) - 4) / 5);
+ for (i = 4; i < RFIFOW(fd, 2); i = i + 5)
{
- gm_account[GM_num].account_id = RFIFOL (fd, i);
- gm_account[GM_num].level = (int) RFIFOB (fd, i + 4);
- //printf("GM account: %d -> level %d\n", gm_account[GM_num].account_id, gm_account[GM_num].level);
+ gm_account[GM_num].account_id = RFIFOL(fd, i);
+ gm_account[GM_num].level = (int) RFIFOB(fd, i + 4);
+ //PRINTF("GM account: %d -> level %d\n", gm_account[GM_num].account_id, gm_account[GM_num].level);
GM_num++;
}
return GM_num;
}
-/*==========================================
- * timer to do the day
- *------------------------------------------
- */
-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;
- char tmpstr[1024];
-
- if (battle_config.day_duration > 0)
- { // if we want a day
- if (night_flag != 0)
- {
- strcpy (tmpstr, "The day has arrived!");
- night_flag = 0; // 0=day, 1=night [Yor]
- for (i = 0; i < fd_max; i++)
- {
- if (session[i] && (pl_sd = (struct map_session_data *)session[i]->session_data)
- && pl_sd->state.auth)
- {
- pl_sd->opt2 &= ~STATE_BLIND;
- clif_changeoption (&pl_sd->bl);
- clif_wis_message (pl_sd->fd, wisp_server_name, tmpstr,
- strlen (tmpstr) + 1);
- }
- }
- }
- }
-}
-
-/*==========================================
- * timer to do the night
- *------------------------------------------
- */
-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;
- char tmpstr[1024];
-
- if (battle_config.night_duration > 0)
- { // if we want a night
- if (night_flag == 0)
- {
- strcpy (tmpstr, "The night has fallen...");
- night_flag = 1; // 0=day, 1=night [Yor]
- for (i = 0; i < fd_max; i++)
- {
- if (session[i] && (pl_sd = (struct map_session_data *)session[i]->session_data)
- && pl_sd->state.auth)
- {
- pl_sd->opt2 |= STATE_BLIND;
- clif_changeoption (&pl_sd->bl);
- clif_wis_message (pl_sd->fd, wisp_server_name, tmpstr,
- strlen (tmpstr) + 1);
- }
- }
- }
- }
-}
-
-void pc_setstand (struct map_session_data *sd)
+void pc_setstand(struct map_session_data *sd)
{
- nullpo_retv (sd);
-
- if (sd->sc_data && sd->sc_data[SC_TENSIONRELAX].timer != -1)
- skill_status_change_end (&sd->bl, SC_TENSIONRELAX, -1);
+ nullpo_retv(sd);
sd->state.dead_sit = 0;
}
-//
-// åˆæœŸåŒ–物
-//
-/*==========================================
- * 設定ファイル読ã¿è¾¼ã‚€
- * exp.txt å¿…è¦çµŒé¨“値
- * job_db1.txt é‡é‡,hp,sp,攻撃速度
- * job_db2.txt job能力値ボーナス
- * skill_tree.txt å„è·æ¯Žã®ã‚¹ã‚­ãƒ«ãƒ„リー
- * attr_fix.txt 属性修正テーブル
- * size_fix.txt サイズ補正テーブル
- * refine_db.txt 精錬データテーブル
- *------------------------------------------
- */
static
-int pc_readdb (void)
+int pc_calc_sigma(void)
{
- int i, j, k;
- FILE *fp;
- char line[1024], *p;
-
- // å¿…è¦çµŒé¨“値読ã¿è¾¼ã¿
-
- fp = fopen_ ("db/exp.txt", "r");
- if (fp == NULL)
- {
- printf ("can't read db/exp.txt\n");
- return 1;
- }
- i = 0;
- while (fgets (line, sizeof (line) - 1, fp))
- {
- int bn, b1, b2, b3, b4, b5, b6, jn, j1, j2, j3, j4, j5, j6;
- if (line[0] == '/' && line[1] == '/')
- continue;
- if (sscanf
- (line, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", &bn, &b1, &b2,
- &b3, &b4, &b5, &b6, &jn, &j1, &j2, &j3, &j4, &j5, &j6) != 14)
- continue;
- exp_table[0][i] = bn;
- exp_table[1][i] = b1;
- exp_table[2][i] = b2;
- exp_table[3][i] = b3;
- exp_table[4][i] = b4;
- exp_table[5][i] = b5;
- exp_table[6][i] = b6;
- exp_table[7][i] = jn;
- exp_table[8][i] = j1;
- exp_table[9][i] = j2;
- exp_table[10][i] = j3;
- exp_table[11][i] = j4;
- exp_table[12][i] = j5;
- exp_table[13][i] = j6;
- i++;
- if (i >= battle_config.maximum_level)
- break;
- }
- fclose_ (fp);
- printf ("read db/exp.txt done\n");
-
- // JOB補正数値1
- fp = fopen_ ("db/job_db1.txt", "r");
- if (fp == NULL)
- {
- printf ("can't read db/job_db1.txt\n");
- return 1;
- }
- i = 0;
- while (fgets (line, sizeof (line) - 1, fp))
- {
- char *split[50];
- if (line[0] == '/' && line[1] == '/')
- continue;
- for (j = 0, p = line; j < 21 && p; j++)
- {
- split[j] = p;
- p = strchr (p, ',');
- if (p)
- *p++ = 0;
- }
- if (j < 21)
- continue;
- max_weight_base[i] = atoi (split[0]);
- hp_coefficient[i] = atoi (split[1]);
- hp_coefficient2[i] = atoi (split[2]);
- sp_coefficient[i] = atoi (split[3]);
- for (j = 0; j < 17; j++)
- aspd_base[i][j] = atoi (split[j + 4]);
- i++;
-// -- moonsoul (below two lines added to accommodate high numbered new class ids)
- if (i == 24)
- i = 4001;
- if (i == MAX_PC_CLASS)
- break;
- }
- fclose_ (fp);
- printf ("read db/job_db1.txt done\n");
-
- // JOBボーナス
- fp = fopen_ ("db/job_db2.txt", "r");
- if (fp == NULL)
- {
- printf ("can't read db/job_db2.txt\n");
- return 1;
- }
- i = 0;
- while (fgets (line, sizeof (line) - 1, fp))
- {
- if (line[0] == '/' && line[1] == '/')
- continue;
- for (j = 0, p = line; j < MAX_LEVEL && p; j++)
- {
- if (sscanf (p, "%d", &k) == 0)
- break;
- job_bonus[0][i][j] = k;
- job_bonus[2][i][j] = k; //養å­è·ã®ãƒœãƒ¼ãƒŠã‚¹ã¯åˆ†ã‹ã‚‰ãªã„ã®ã§ä»®
- p = strchr (p, ',');
- if (p)
- p++;
- }
- i++;
-// -- moonsoul (below two lines added to accommodate high numbered new class ids)
- if (i == 24)
- i = 4001;
- if (i == MAX_PC_CLASS)
- break;
- }
- fclose_ (fp);
- printf ("read db/job_db2.txt done\n");
+ int j, k;
- // JOBボーナス2 転生è·ç”¨
- fp = fopen_ ("db/job_db2-2.txt", "r");
- if (fp == NULL)
- {
- printf ("can't read db/job_db2-2.txt\n");
- return 1;
- }
- i = 0;
- while (fgets (line, sizeof (line) - 1, fp))
{
- if (line[0] == '/' && line[1] == '/')
- continue;
- for (j = 0, p = line; j < MAX_LEVEL && p; j++)
- {
- if (sscanf (p, "%d", &k) == 0)
- break;
- job_bonus[1][i][j] = k;
- p = strchr (p, ',');
- if (p)
- p++;
- }
- i++;
- if (i == MAX_PC_CLASS)
- break;
- }
- fclose_ (fp);
- printf ("read db/job_db2-2.txt done\n");
-
- // スキルツリー
- memset (skill_tree, 0, sizeof (skill_tree));
- fp = fopen_ ("db/skill_tree.txt", "r");
- if (fp == NULL)
- {
- printf ("can't read db/skill_tree.txt\n");
- return 1;
- }
- while (fgets (line, sizeof (line) - 1, fp))
- {
- char *split[50];
- if (line[0] == '/' && line[1] == '/')
- continue;
- for (j = 0, p = line; j < 13 && p; j++)
- {
- split[j] = p;
- p = strchr (p, ',');
- if (p)
- *p++ = 0;
- }
- if (j < 13)
- continue;
- i = atoi (split[0]);
- for (j = 0; skill_tree[0][i][j].id; j++);
- skill_tree[0][i][j].id = atoi (split[1]);
- skill_tree[0][i][j].max = atoi (split[2]);
- skill_tree[2][i][j].id = atoi (split[1]); //養å­è·ã¯è‰¯ã分ã‹ã‚‰ãªã„ã®ã§æš«å®š
- skill_tree[2][i][j].max = atoi (split[2]); //養å­è·ã¯è‰¯ã分ã‹ã‚‰ãªã„ã®ã§æš«å®š
- for (k = 0; k < 5; k++)
- {
- skill_tree[0][i][j].need[k].id = atoi (split[k * 2 + 3]);
- skill_tree[0][i][j].need[k].lv = atoi (split[k * 2 + 4]);
- skill_tree[2][i][j].need[k].id = atoi (split[k * 2 + 3]); //養å­è·ã¯è‰¯ã分ã‹ã‚‰ãªã„ã®ã§æš«å®š
- skill_tree[2][i][j].need[k].lv = atoi (split[k * 2 + 4]); //養å­è·ã¯è‰¯ã分ã‹ã‚‰ãªã„ã®ã§æš«å®š
- }
- }
- fclose_ (fp);
- printf ("read db/skill_tree.txt done\n");
-
- // 属性修正テーブル
- for (i = 0; i < 4; i++)
- for (j = 0; j < 10; j++)
- for (k = 0; k < 10; k++)
- attr_fix_table[i][j][k] = 100;
- fp = fopen_ ("db/attr_fix.txt", "r");
- if (fp == NULL)
- {
- printf ("can't read db/attr_fix.txt\n");
- return 1;
- }
- while (fgets (line, sizeof (line) - 1, fp))
- {
- char *split[10];
- int lv, n;
- if (line[0] == '/' && line[1] == '/')
- continue;
- for (j = 0, p = line; j < 3 && p; j++)
- {
- split[j] = p;
- p = strchr (p, ',');
- if (p)
- *p++ = 0;
- }
- lv = atoi (split[0]);
- n = atoi (split[1]);
-// printf("%d %d\n",lv,n);
-
- for (i = 0; i < n;)
- {
- if (!fgets (line, sizeof (line) - 1, fp))
- break;
- if (line[0] == '/' && line[1] == '/')
- continue;
-
- for (j = 0, p = line; j < n && p; j++)
- {
- while (*p == 32 && *p > 0)
- p++;
- attr_fix_table[lv - 1][i][j] = atoi (p);
- if (battle_config.attr_recover == 0
- && attr_fix_table[lv - 1][i][j] < 0)
- attr_fix_table[lv - 1][i][j] = 0;
- p = strchr (p, ',');
- if (p)
- *p++ = 0;
- }
-
- i++;
- }
- }
- fclose_ (fp);
- printf ("read db/attr_fix.txt done\n");
-
- // サイズ補正テーブル
- for (i = 0; i < 3; i++)
- for (j = 0; j < 20; j++)
- atkmods[i][j] = 100;
- fp = fopen_ ("db/size_fix.txt", "r");
- if (fp == NULL)
- {
- printf ("can't read db/size_fix.txt\n");
- return 1;
- }
- i = 0;
- while (fgets (line, sizeof (line) - 1, fp))
- {
- char *split[20];
- if (line[0] == '/' && line[1] == '/')
- continue;
- if (atoi (line) <= 0)
- continue;
- memset (split, 0, sizeof (split));
- for (j = 0, p = line; j < 20 && p; j++)
- {
- split[j] = p;
- p = strchr (p, ',');
- if (p)
- *p++ = 0;
- }
- for (j = 0; j < 20 && split[j]; j++)
- atkmods[i][j] = atoi (split[j]);
- i++;
- }
- fclose_ (fp);
- printf ("read db/size_fix.txt done\n");
-
- // 精錬データテーブル
- for (i = 0; i < 5; i++)
- {
- for (j = 0; j < 10; j++)
- percentrefinery[i][j] = 100;
- refinebonus[i][0] = 0;
- refinebonus[i][1] = 0;
- refinebonus[i][2] = 10;
- }
- fp = fopen_ ("db/refine_db.txt", "r");
- if (fp == NULL)
- {
- printf ("can't read db/refine_db.txt\n");
- return 1;
- }
- i = 0;
- while (fgets (line, sizeof (line) - 1, fp))
- {
- char *split[16];
- if (line[0] == '/' && line[1] == '/')
- continue;
- if (atoi (line) <= 0)
- continue;
- memset (split, 0, sizeof (split));
- for (j = 0, p = line; j < 16 && p; j++)
- {
- split[j] = p;
- p = strchr (p, ',');
- if (p)
- *p++ = 0;
- }
- refinebonus[i][0] = atoi (split[0]); // 精錬ボーナス
- refinebonus[i][1] = atoi (split[1]); // éŽå‰°ç²¾éŒ¬ãƒœãƒ¼ãƒŠã‚¹
- refinebonus[i][2] = atoi (split[2]); // 安全精錬é™ç•Œ
- for (j = 0; j < 10 && split[j]; j++)
- percentrefinery[i][j] = atoi (split[j + 3]);
- i++;
- }
- fclose_ (fp); //Lupus. close this file!!!
- printf ("read db/refine_db.txt done\n");
-
- return 0;
-}
-
-static int pc_calc_sigma (void)
-{
- int i, j, k;
-
- for (i = 0; i < MAX_PC_CLASS; i++)
- {
- memset (hp_sigma_val[i], 0, sizeof (hp_sigma_val[i]));
+ memset(hp_sigma_val_0, 0, sizeof(hp_sigma_val_0));
for (k = 0, j = 2; j <= MAX_LEVEL; j++)
{
- k += hp_coefficient[i] * j + 50;
+ k += hp_coefficient_0 * j + 50;
k -= k % 100;
- hp_sigma_val[i][j - 1] = k;
+ hp_sigma_val_0[j - 1] = k;
}
}
return 0;
}
-static void pc_statpointdb (void)
-{
- char *buf_stat;
- int i = 0, j = 0, k = 0, l = 0, end = 0;
-
- FILE *stp;
-
- stp = fopen_ ("db/statpoint.txt", "r");
-
- if (stp == NULL)
- {
- printf ("can't read db/statpoint.txt\n");
- return;
- }
-
- fseek (stp, 0, SEEK_END);
- end = ftell (stp);
- rewind (stp);
-
- buf_stat = (char *) malloc (end + 1);
- l = fread (buf_stat, 1, end, stp);
- fclose_ (stp);
- printf ("read db/statpoint.txt done (size=%d)\n", l);
-
- for (i = 0; i < 255; i++)
- {
- j = 0;
- while (*(buf_stat + k) != '\n')
- {
- statp[i][j] = *(buf_stat + k);
- j++;
- k++;
- }
- statp[i][j + 1] = '\0';
- k++;
- }
-
- free (buf_stat);
-}
-
/*==========================================
* pcé–¢ ä¿‚åˆæœŸåŒ–
*------------------------------------------
*/
-int do_init_pc (void)
-{
- pc_readdb ();
- pc_statpointdb ();
- pc_calc_sigma ();
-
-// gm_account_db = numdb_init();
-
- 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);
-
- {
- int day_duration = battle_config.day_duration;
- int night_duration = battle_config.night_duration;
- if (day_duration < 60000)
- day_duration = 60000;
- if (night_duration < 60000)
- night_duration = 60000;
- if (battle_config.night_at_start == 0)
- {
- night_flag = 0; // 0=day, 1=night [Yor]
- day_timer_tid =
- add_timer_interval (gettick () + day_duration +
- night_duration, map_day_timer, 0, 0,
- day_duration + night_duration);
- night_timer_tid =
- add_timer_interval (gettick () + day_duration,
- map_night_timer, 0, 0,
- day_duration + night_duration);
- }
- else
- {
- night_flag = 1; // 0=day, 1=night [Yor]
- day_timer_tid =
- add_timer_interval (gettick () + night_duration,
- map_day_timer, 0, 0,
- day_duration + night_duration);
- night_timer_tid =
- add_timer_interval (gettick () + day_duration +
- night_duration, map_night_timer, 0, 0,
- day_duration + night_duration);
- }
- }
+int do_init_pc(void)
+{
+ pc_calc_sigma();
+ natural_heal_prev_tick = gettick() + NATURAL_HEAL_INTERVAL;
+ Timer(natural_heal_prev_tick,
+ pc_natural_heal,
+ NATURAL_HEAL_INTERVAL
+ ).detach();
+ Timer(gettick() + autosave_interval,
+ pc_autosave
+ ).detach();
return 0;
}
-void pc_cleanup (struct map_session_data *sd)
+void pc_cleanup(struct map_session_data *sd)
{
- magic_stop_completely (sd);
+ magic_stop_completely(sd);
}
-void pc_invisibility (struct map_session_data *sd, int enabled)
+void pc_invisibility(struct map_session_data *sd, int enabled)
{
- if (enabled && !(sd->status.option & OPTION_INVISIBILITY))
+ if (enabled && !bool(sd->status.option & Option::INVISIBILITY))
{
- clif_clearchar_area (&sd->bl, 3);
- sd->status.option |= OPTION_INVISIBILITY;
- clif_status_change (&sd->bl, CLIF_OPTION_SC_INVISIBILITY, 1);
+ clif_clearchar(&sd->bl, BeingRemoveWhy::WARPED);
+ sd->status.option |= Option::INVISIBILITY;
+ clif_status_change(&sd->bl, StatusChange::CLIF_OPTION_SC_INVISIBILITY, 1);
}
else if (!enabled)
{
- sd->status.option &= ~OPTION_INVISIBILITY;
- clif_status_change (&sd->bl, CLIF_OPTION_SC_INVISIBILITY, 0);
- pc_setpos (sd, map[sd->bl.m].name, sd->bl.x, sd->bl.y, 3);
+ sd->status.option &= ~Option::INVISIBILITY;
+ clif_status_change(&sd->bl, StatusChange::CLIF_OPTION_SC_INVISIBILITY, 0);
+ pc_setpos(sd, map[sd->bl.m].name, sd->bl.x, sd->bl.y, BeingRemoveWhy::WARPED);
}
}
-int pc_logout (struct map_session_data *sd) // [fate] Player logs out
+int pc_logout(struct map_session_data *sd) // [fate] Player logs out
{
- unsigned int tick = gettick ();
-
if (!sd)
return 0;
- if (sd->sc_data[SC_POISON].timer != -1)
+ if (sd->sc_data[StatusChange::SC_POISON].timer)
sd->status.hp = 1; // Logging out while poisoned -> bad
/*
@@ -9037,12 +5494,13 @@ int pc_logout (struct map_session_data *sd) // [fate] Player logs out
// Removed because it's buggy, see above.
if (sd->cast_tick > tick)
{
- if (pc_setglobalreg (sd, "MAGIC_CAST_TICK", sd->cast_tick - tick))
+ if (pc_setglobalreg(sd, "MAGIC_CAST_TICK", sd->cast_tick - tick))
sd->status.sp = 1;
}
else
#endif
- pc_setglobalreg (sd, "MAGIC_CAST_TICK", 0);
+ pc_setglobalreg(sd, "MAGIC_CAST_TICK", 0);
- MAP_LOG_STATS (sd, "LOGOUT") return 0;
+ MAP_LOG_STATS(sd, "LOGOUT");
+ return 0;
}
diff --git a/src/map/pc.hpp b/src/map/pc.hpp
index cc433b8..baf1487 100644
--- a/src/map/pc.hpp
+++ b/src/map/pc.hpp
@@ -1,209 +1,159 @@
-// $Id: pc.h,v 1.4 2004/09/25 05:32:18 MouseJstr Exp $
-
#ifndef PC_HPP
#define PC_HPP
+#include "pc.t.hpp"
+
+#include "clif.t.hpp"
#include "map.hpp"
-#define OPTION_MASK 0xd7b8
-#define CART_MASK 0x788
-
-#define pc_setdead(sd) ((sd)->state.dead_sit = 1)
-#define pc_setsit(sd) ((sd)->state.dead_sit = 2)
-//#define pc_setstand(sd) ((sd)->state.dead_sit = 0)
-#define pc_isdead(sd) ((sd)->state.dead_sit == 1)
-#define pc_issit(sd) ((sd)->state.dead_sit == 2)
-#define pc_setdir(sd,b) ((sd)->dir = (b))
-#define pc_setchatid(sd,n) ((sd)->chatID = n)
-#define pc_ishiding(sd) ((sd)->status.option&0x4006)
-#define pc_iscarton(sd) ((sd)->status.option&CART_MASK)
-#define pc_isfalcon(sd) ((sd)->status.option&0x0010)
-#define pc_isriding(sd) ((sd)->status.option&0x0020)
-#define pc_isinvisible(sd) ((sd)->status.option&0x0040)
-#define pc_is50overweight(sd) (sd->weight*2 >= sd->max_weight)
-#define pc_is90overweight(sd) (sd->weight*10 >= sd->max_weight*9)
-
-void pc_touch_all_relevant_npcs (struct map_session_data *sd); /* Checks all npcs/warps at the same location to see whether they
- ** should do something with the specified player. */
-
-int pc_isGM (struct map_session_data *sd);
-int pc_iskiller (struct map_session_data *src, struct map_session_data *target); // [MouseJstr]
-int pc_getrefinebonus (int lv, int type);
-
-void pc_invisibility (struct map_session_data *sd, int enabled); // [Fate]
-int pc_counttargeted (struct map_session_data *sd, struct block_list *src,
- int target_lv);
-int pc_setrestartvalue (struct map_session_data *sd, int type);
-int pc_makesavestatus (struct map_session_data *);
-int pc_setnewpc (struct map_session_data *, int, int, int, int, int, int);
-int pc_authok (int, int, time_t, short tmw_version, struct mmo_charstatus *);
-int pc_authfail (int);
-
-int pc_isequip (struct map_session_data *sd, int n);
-int pc_equippoint (struct map_session_data *sd, int n);
-
-int pc_breakweapon (struct map_session_data *sd); // weapon breaking [Valaris]
-int pc_breakarmor (struct map_session_data *sd); // armor breaking [Valaris]
-
-int pc_checkskill (struct map_session_data *sd, int skill_id);
-int pc_checkallowskill (struct map_session_data *sd);
-int pc_checkequip (struct map_session_data *sd, int pos);
-
-int pc_checkoverhp (struct map_session_data *);
-int pc_checkoversp (struct map_session_data *);
-
-int pc_can_reach (struct map_session_data *, int, int);
-int pc_walktoxy (struct map_session_data *, int, int);
-int pc_stop_walking (struct map_session_data *, int);
-int pc_movepos (struct map_session_data *, int, int);
-int pc_setpos (struct map_session_data *, const char *, int, int, int);
-int pc_setsavepoint (struct map_session_data *, const char *, int, int);
-int pc_randomwarp (struct map_session_data *sd, int type);
-int pc_memo (struct map_session_data *sd, int i);
-
-int pc_checkadditem (struct map_session_data *, int, int);
-int pc_inventoryblank (struct map_session_data *);
-int pc_search_inventory (struct map_session_data *sd, int item_id);
-int pc_payzeny (struct map_session_data *, int);
-int pc_additem (struct map_session_data *, struct item *, int);
-int pc_getzeny (struct map_session_data *, int);
-int pc_delitem (struct map_session_data *, int, int, int);
-int pc_checkitem (struct map_session_data *);
-int pc_count_all_items (struct map_session_data *player, int item_id);
-int pc_remove_items (struct map_session_data *player, int item_id,
- int count);
-
-int pc_cart_additem (struct map_session_data *sd, struct item *item_data,
- int amount);
-int pc_cart_delitem (struct map_session_data *sd, int n, int amount,
- int type);
-int pc_putitemtocart (struct map_session_data *sd, int idx, int amount);
-int pc_getitemfromcart (struct map_session_data *sd, int idx, int amount);
-int pc_cartitem_amount (struct map_session_data *sd, int idx, int amount);
-
-int pc_takeitem (struct map_session_data *, struct flooritem_data *);
-int pc_dropitem (struct map_session_data *, int, int);
-
-int pc_checkweighticon (struct map_session_data *sd);
-
-int pc_calcstatus (struct map_session_data *, int);
-int pc_bonus (struct map_session_data *, int, int);
-int pc_bonus2 (struct map_session_data *sd, int, int, int);
-int pc_bonus3 (struct map_session_data *sd, int, int, int, int);
-int pc_skill (struct map_session_data *, int, int, int);
-
-int pc_insert_card (struct map_session_data *sd, int idx_card,
- int idx_equip);
-
-int pc_item_identify (struct map_session_data *sd, int idx);
-int pc_steal_item (struct map_session_data *sd, struct block_list *bl);
-int pc_steal_coin (struct map_session_data *sd, struct block_list *bl);
-
-int pc_modifybuyvalue (struct map_session_data *, int);
-int pc_modifysellvalue (struct map_session_data *, int);
-
-int pc_attack (struct map_session_data *, int, int);
-int pc_stopattack (struct map_session_data *);
-
-int pc_follow (struct map_session_data *, int); // [MouseJstr]
-
-int pc_checkbaselevelup (struct map_session_data *sd);
-int pc_checkjoblevelup (struct map_session_data *sd);
-int pc_gainexp (struct map_session_data *, int, int);
-
-#define PC_GAINEXP_REASON_KILLING 0
-#define PC_GAINEXP_REASON_HEALING 1
-#define PC_GAINEXP_REASON_SCRIPT 2
-int pc_gainexp_reason (struct map_session_data *, int, int, int reason);
-int pc_extract_healer_exp (struct map_session_data *, int max); // [Fate] Used by healers: extract healer-xp from the target, return result (up to max)
-
-int pc_nextbaseexp (struct map_session_data *);
-int pc_nextbaseafter (struct map_session_data *); // [Valaris]
-int pc_nextjobexp (struct map_session_data *);
-int pc_nextjobafter (struct map_session_data *); // [Valaris]
-int pc_need_status_point (struct map_session_data *, int);
-int pc_statusup (struct map_session_data *, int);
-int pc_statusup2 (struct map_session_data *, int, int);
-int pc_skillup (struct map_session_data *, int);
-int pc_allskillup (struct map_session_data *);
-int pc_resetlvl (struct map_session_data *, int type);
-int pc_resetstate (struct map_session_data *);
-int pc_resetskill (struct map_session_data *);
-int pc_equipitem (struct map_session_data *, int, int);
-int pc_unequipitem (struct map_session_data *, int, int);
-int pc_unequipinvyitem (struct map_session_data *, int, int);
-int pc_useitem (struct map_session_data *, int);
-
-int pc_damage (struct block_list *, struct map_session_data *, int);
-int pc_heal (struct map_session_data *, int, int);
-int pc_itemheal (struct map_session_data *sd, int hp, int sp);
-int pc_percentheal (struct map_session_data *sd, int, int);
-int pc_jobchange (struct map_session_data *, int, int);
-int pc_setoption (struct map_session_data *, int);
-int pc_setcart (struct map_session_data *sd, int type);
-int pc_setfalcon (struct map_session_data *sd);
-int pc_setriding (struct map_session_data *sd);
-int pc_changelook (struct map_session_data *, int, int);
-int pc_equiplookall (struct map_session_data *sd);
-
-int pc_readparam (struct map_session_data *, int);
-int pc_setparam (struct map_session_data *, int, int);
-int pc_readreg (struct map_session_data *, int);
-int pc_setreg (struct map_session_data *, int, int);
-char *pc_readregstr (struct map_session_data *sd, int reg);
-int pc_setregstr (struct map_session_data *sd, int reg, const char *str);
-int pc_readglobalreg (struct map_session_data *, const char *);
-int pc_setglobalreg (struct map_session_data *, const char *, int);
-int pc_readaccountreg (struct map_session_data *, const char *);
-int pc_setaccountreg (struct map_session_data *, const char *, int);
-int pc_readaccountreg2 (struct map_session_data *, const char *);
-int pc_setaccountreg2 (struct map_session_data *, const char *, int);
-int pc_percentrefinery (struct map_session_data *sd, struct item *item);
-
-int pc_addeventtimer (struct map_session_data *sd, int tick,
- const char *name);
-int pc_deleventtimer (struct map_session_data *sd, const char *name);
-int pc_cleareventtimer (struct map_session_data *sd);
-int pc_addeventtimercount (struct map_session_data *sd, const char *name,
- int tick);
-
-int pc_calc_pvprank (struct map_session_data *sd);
-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,
- struct map_session_data *dstsd);
-int pc_divorce (struct map_session_data *sd);
-struct map_session_data *pc_get_partner (struct map_session_data *sd);
-int pc_set_gm_level (int account_id, int level);
-void pc_setstand (struct map_session_data *sd);
-void pc_cleanup (struct map_session_data *sd); // [Fate] Clean up after a logged-out PC
-
-struct pc_base_job
+inline
+void pc_setsit(struct map_session_data *sd)
{
- int job; //è·æ¥­ã€ãŸã ã—転生è·ã‚„養å­è·ã®å ´åˆã¯å…ƒã®è·æ¥­ã‚’è¿”ã™(廃プリ→プリ)
- int type; //ノビ 0, ä¸€æ¬¡è· 1, äºŒæ¬¡è· 2, スパノビ 3
- int upper; //通常 0, 転生 1, é¤Šå­ 2
-};
-
-struct pc_base_job pc_calc_base_job (int b_class); //転生や養å­è·ã®å…ƒã®è·æ¥­ã‚’è¿”ã™
-
-int pc_read_gm_account (int fd);
-int pc_setinvincibletimer (struct map_session_data *sd, int);
-int pc_delinvincibletimer (struct map_session_data *sd);
-int pc_addspiritball (struct map_session_data *sd, int, int);
-int pc_delspiritball (struct map_session_data *sd, int, int);
-int pc_logout (struct map_session_data *sd); // [fate] Player logs out
-
-int do_init_pc (void);
-
-enum
-{ ADDITEM_EXIST, ADDITEM_NEW, ADDITEM_OVERAMOUNT };
-
-// timer for night.day
-extern timer_id day_timer_tid;
-extern 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
+ sd->state.dead_sit = 2;
+}
+//pc_setstand(struct map_session_data *sd) is a normal function
+inline
+bool pc_isdead(struct map_session_data *sd)
+{
+ return sd->state.dead_sit == 1;
+}
+inline
+bool pc_issit(struct map_session_data *sd)
+{
+ return sd->state.dead_sit == 2;
+}
+inline
+void pc_setdir(struct map_session_data *sd, DIR b)
+{
+ sd->dir = (b);
+}
+inline
+void pc_setchatid(struct map_session_data *sd, int n)
+{
+ sd->chatID = n;
+}
+inline
+bool pc_isinvisible(struct map_session_data *sd)
+{
+ return bool(sd->status.option & Option::HIDE);
+}
+inline
+bool pc_is90overweight(struct map_session_data *sd)
+{
+ return sd->weight*10 >= sd->max_weight*9;
+}
+
+// Checks all npcs/warps at the same location to see whether they
+// should do something with the specified player.
+void pc_touch_all_relevant_npcs(struct map_session_data *sd);
+
+int pc_isGM(struct map_session_data *sd);
+int pc_iskiller(struct map_session_data *src, struct map_session_data *target); // [MouseJstr]
+
+void pc_invisibility(struct map_session_data *sd, int enabled); // [Fate]
+int pc_counttargeted(struct map_session_data *sd, struct block_list *src,
+ ATK target_lv);
+int pc_setrestartvalue(struct map_session_data *sd, int type);
+int pc_makesavestatus(struct map_session_data *);
+int pc_setnewpc(struct map_session_data *, int, int, int, tick_t, int);
+int pc_authok(int, int, TimeT, short tmw_version, const struct mmo_charstatus *);
+int pc_authfail(int);
+
+EPOS pc_equippoint(struct map_session_data *sd, int n);
+
+int pc_checkskill(struct map_session_data *sd, SkillID skill_id);
+int pc_checkequip(struct map_session_data *sd, EPOS pos);
+
+int pc_walktoxy(struct map_session_data *, int, int);
+int pc_stop_walking(struct map_session_data *, int);
+int pc_movepos(struct map_session_data *, int, int);
+int pc_setpos(struct map_session_data *, const char *, int, int, BeingRemoveWhy);
+int pc_setsavepoint(struct map_session_data *, const char *, int, int);
+int pc_randomwarp(struct map_session_data *sd, BeingRemoveWhy type);
+
+ADDITEM pc_checkadditem(struct map_session_data *, int, int);
+int pc_inventoryblank(struct map_session_data *);
+int pc_search_inventory(struct map_session_data *sd, int item_id);
+int pc_payzeny(struct map_session_data *, int);
+PickupFail pc_additem(struct map_session_data *, struct item *, int);
+int pc_getzeny(struct map_session_data *, int);
+int pc_delitem(struct map_session_data *, int, int, int);
+int pc_checkitem(struct map_session_data *);
+int pc_count_all_items(struct map_session_data *player, int item_id);
+int pc_remove_items(struct map_session_data *player,
+ int item_id, int count);
+
+int pc_takeitem(struct map_session_data *, struct flooritem_data *);
+int pc_dropitem(struct map_session_data *, int, int);
+
+int pc_checkweighticon(struct map_session_data *sd);
+
+int pc_calcstatus(struct map_session_data *, int);
+int pc_bonus(struct map_session_data *, SP, int);
+int pc_bonus2(struct map_session_data *sd, SP, int, int);
+int pc_skill(struct map_session_data *, SkillID, int, int);
+
+int pc_attack(struct map_session_data *, int, int);
+int pc_stopattack(struct map_session_data *);
+
+int pc_gainexp_reason(struct map_session_data *, int, int,
+ PC_GAINEXP_REASON reason);
+int pc_extract_healer_exp(struct map_session_data *, int max); // [Fate] Used by healers: extract healer-xp from the target, return result (up to max)
+
+int pc_nextbaseexp(struct map_session_data *);
+int pc_nextjobexp(struct map_session_data *);
+int pc_need_status_point(struct map_session_data *, SP);
+int pc_statusup(struct map_session_data *, SP);
+int pc_statusup2(struct map_session_data *, SP, int);
+int pc_skillup(struct map_session_data *, SkillID);
+int pc_resetlvl(struct map_session_data *, int type);
+int pc_resetstate(struct map_session_data *);
+int pc_resetskill(struct map_session_data *);
+int pc_equipitem(struct map_session_data *, int, EPOS);
+int pc_unequipitem(struct map_session_data *, int, CalcStatus);
+int pc_unequipinvyitem(struct map_session_data *, int, CalcStatus);
+int pc_useitem(struct map_session_data *, int);
+
+int pc_damage(struct block_list *, struct map_session_data *, int);
+int pc_heal(struct map_session_data *, int, int);
+int pc_itemheal(struct map_session_data *sd, int hp, int sp);
+int pc_percentheal(struct map_session_data *sd, int, int);
+int pc_setoption(struct map_session_data *, Option);
+int pc_changelook(struct map_session_data *, LOOK, int);
+
+int pc_readparam(struct map_session_data *, SP);
+int pc_setparam(struct map_session_data *, SP, int);
+int pc_readreg(struct map_session_data *, int);
+int pc_setreg(struct map_session_data *, int, int);
+char *pc_readregstr(struct map_session_data *sd, int reg);
+int pc_setregstr(struct map_session_data *sd, int reg, const char *str);
+int pc_readglobalreg(struct map_session_data *, const char *);
+int pc_setglobalreg(struct map_session_data *, const char *, int);
+int pc_readaccountreg(struct map_session_data *, const char *);
+int pc_setaccountreg(struct map_session_data *, const char *, int);
+int pc_readaccountreg2(struct map_session_data *, const char *);
+int pc_setaccountreg2(struct map_session_data *, const char *, int);
+
+int pc_addeventtimer(struct map_session_data *sd, interval_t tick,
+ const char *name);
+int pc_cleareventtimer(struct map_session_data *sd);
+
+int pc_calc_pvprank(struct map_session_data *sd);
+void pc_calc_pvprank_timer(TimerData *, tick_t, int);
+
+int pc_marriage(struct map_session_data *sd,
+ struct map_session_data *dstsd);
+int pc_divorce(struct map_session_data *sd);
+struct map_session_data *pc_get_partner(struct map_session_data *sd);
+int pc_set_gm_level(int account_id, int level);
+void pc_setstand(struct map_session_data *sd);
+void pc_cleanup(struct map_session_data *sd); // [Fate] Clean up after a logged-out PC
+
+int pc_read_gm_account(int fd);
+int pc_setinvincibletimer(struct map_session_data *sd, interval_t);
+int pc_delinvincibletimer(struct map_session_data *sd);
+int pc_logout(struct map_session_data *sd); // [fate] Player logs out
+
+int do_init_pc(void);
+
+#endif // PC_HPP
diff --git a/src/map/pc.t.hpp b/src/map/pc.t.hpp
new file mode 100644
index 0000000..feffd89
--- /dev/null
+++ b/src/map/pc.t.hpp
@@ -0,0 +1,44 @@
+#ifndef PC_T_HPP
+#define PC_T_HPP
+
+#include <cstdint>
+
+enum class PC_GAINEXP_REASON
+{
+ KILLING = 0,
+ HEALING = 1,
+ SCRIPT = 2,
+ SHARING = 3,
+
+ UNKNOWN,
+ COUNT,
+};
+
+enum class ADDITEM
+{
+ EXIST,
+ NEW,
+ OVERAMOUNT,
+
+ // when used as error in nullpo_retr
+ ZERO = 0,
+};
+
+enum class CalcStatus
+{
+ NOW,
+ LATER ,
+};
+
+enum class PickupFail : uint8_t
+{
+ OKAY = 0,
+ BAD_ITEM = 1,
+ TOO_HEAVY = 2,
+ TOO_FAR = 3,
+ INV_FULL = 4,
+ STACK_FULL = 5,
+ DROP_STEAL = 6,
+};
+
+#endif // PC_T_HPP
diff --git a/src/map/script.cpp b/src/map/script.cpp
index fac5ad5..b5e2aca 100644
--- a/src/map/script.cpp
+++ b/src/map/script.cpp
@@ -1,751 +1,143 @@
-// $Id: script.c 148 2004-09-30 14:05:37Z MouseJstr $
-//#define DEBUG_FUNCIN
-//#define DEBUG_DISP
-//#define DEBUG_RUN
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <ctype.h>
-
-#ifndef LCCWIN32
-#include <sys/time.h>
-#endif
-
-#include <time.h>
-#include <math.h>
+#include "script.hpp"
#include <cassert>
+#include <cctype>
+#include <cmath>
+#include <cstdlib>
+#include <cstring>
+#include <ctime>
+#include <fstream>
+
+#include "../common/cxxstdio.hpp"
+#include "../common/db.hpp"
+#include "../common/extract.hpp"
+#include "../common/lock.hpp"
+#include "../common/random.hpp"
#include "../common/socket.hpp"
+#include "../common/utils.hpp"
#include "../common/timer.hpp"
-#include "../common/lock.hpp"
-#include "../common/mt_rand.hpp"
#include "atcommand.hpp"
#include "battle.hpp"
-#include "chat.hpp"
#include "chrif.hpp"
#include "clif.hpp"
-#include "../common/db.hpp"
-#include "guild.hpp"
#include "intif.hpp"
#include "itemdb.hpp"
-#include "../common/lock.hpp"
+#include "magic.hpp"
#include "map.hpp"
#include "mob.hpp"
#include "npc.hpp"
#include "party.hpp"
#include "pc.hpp"
-#include "script.hpp"
#include "skill.hpp"
#include "storage.hpp"
-#ifdef MEMWATCH
-#include "memwatch.hpp"
-#endif
+#include "../poison.hpp"
-#define SCRIPT_BLOCK_SIZE 256
+//#define DEBUG_FUNCIN
+//#define DEBUG_DISP
+//#define DEBUG_RUN
+
+constexpr int SCRIPT_BLOCK_SIZE = 256;
enum
{ LABEL_NEXTLINE = 1, LABEL_START };
-static ScriptCode *script_buf;
-static int script_pos, script_size;
+static
+ScriptCode *script_buf;
+static
+int script_pos, script_size;
+static
char *str_buf;
-int str_pos, str_size;
-static struct str_data_t
+static
+int str_pos, str_size;
+static
+struct str_data_t
{
ScriptCode type;
- int str;
- int backpatch;
- int label;
- int (*func) (struct script_state *);
- int val;
- int next;
+ int str;
+ int backpatch;
+ int label;
+ void(*func)(ScriptState *);
+ int val;
+ int next;
} *str_data;
-int str_num = LABEL_START, str_data_size;
-int str_hash[16];
+static
+int str_num = LABEL_START, str_data_size;
+static
+int str_hash[16];
-static struct dbt *mapreg_db = NULL;
-static struct dbt *mapregstr_db = NULL;
-static int mapreg_dirty = -1;
+static
+DMap<int, int> mapreg_db;
+static
+DMap<int, char *> mapregstr_db;
+static
+int mapreg_dirty = -1;
char mapreg_txt[256] = "save/mapreg.txt";
-#define MAPREG_AUTOSAVE_INTERVAL (10*1000)
-
-static struct dbt *scriptlabel_db = NULL;
-static struct dbt *userfunc_db = NULL;
+constexpr std::chrono::milliseconds MAPREG_AUTOSAVE_INTERVAL = std::chrono::seconds(10);
-struct dbt *script_get_label_db (void)
-{
- return scriptlabel_db;
-}
-
-struct dbt *script_get_userfunc_db (void)
-{
- if (!userfunc_db)
- userfunc_db = strdb_init (50);
- return userfunc_db;
-}
+Map<std::string, int> scriptlabel_db;
+DMap<std::string, const ScriptCode *> userfunc_db;
-static char pos[11][100] =
- { "é ­", "体", "左手", "å³æ‰‹", "ローブ", "é´", "アクセサリー1",
- "アクセサリー2", "é ­2", "é ­3", "装ç€ã—ã¦ã„ãªã„"
+static
+const char *pos[11] =
+{
+ "Head",
+ "Body",
+ "Left hand",
+ "Right hand",
+ "Robe",
+ "Shoes",
+ "Accessory 1",
+ "Accessory 2",
+ "Head 2",
+ "Head 3",
+ "Not Equipped",
};
-static struct Script_Config
-{
- int warn_func_no_comma;
- int warn_cmd_no_comma;
- int warn_func_mismatch_paramnum;
- int warn_cmd_mismatch_paramnum;
- int check_cmdcount;
- int check_gotocount;
+static
+struct Script_Config
+{
+ int warn_func_no_comma;
+ int warn_cmd_no_comma;
+ int warn_func_mismatch_paramnum;
+ int warn_cmd_mismatch_paramnum;
+ int check_cmdcount;
+ int check_gotocount;
} script_config;
-static int parse_cmd_if = 0;
-static int parse_cmd;
+static
+int parse_cmd_if = 0;
+static
+int parse_cmd;
/*==========================================
* ローカルプロトタイプ宣言 (å¿…è¦ãªç‰©ã®ã¿)
*------------------------------------------
*/
-const char *parse_subexpr (const char *, int);
-int buildin_mes (struct script_state *st);
-int buildin_goto (struct script_state *st);
-int buildin_callsub (struct script_state *st);
-int buildin_callfunc (struct script_state *st);
-int buildin_return (struct script_state *st);
-int buildin_getarg (struct script_state *st);
-int buildin_next (struct script_state *st);
-int buildin_close (struct script_state *st);
-int buildin_close2 (struct script_state *st);
-int buildin_menu (struct script_state *st);
-int buildin_rand (struct script_state *st);
-int buildin_pow (struct script_state *st);
-int buildin_warp (struct script_state *st);
-int buildin_isat (struct script_state *st);
-int buildin_areawarp (struct script_state *st);
-int buildin_heal (struct script_state *st);
-int buildin_itemheal (struct script_state *st);
-int buildin_percentheal (struct script_state *st);
-int buildin_jobchange (struct script_state *st);
-int buildin_input (struct script_state *st);
-int buildin_setlook (struct script_state *st);
-int buildin_set (struct script_state *st);
-int buildin_setarray (struct script_state *st);
-int buildin_cleararray (struct script_state *st);
-int buildin_copyarray (struct script_state *st);
-int buildin_getarraysize (struct script_state *st);
-int buildin_deletearray (struct script_state *st);
-int buildin_getelementofarray (struct script_state *st);
-int buildin_if (struct script_state *st);
-int buildin_getitem (struct script_state *st);
-int buildin_getitem2 (struct script_state *st);
-int buildin_makeitem (struct script_state *st);
-int buildin_delitem (struct script_state *st);
-int buildin_viewpoint (struct script_state *st);
-int buildin_countitem (struct script_state *st);
-int buildin_checkweight (struct script_state *st);
-int buildin_readparam (struct script_state *st);
-int buildin_getcharid (struct script_state *st);
-int buildin_getpartyname (struct script_state *st);
-int buildin_getpartymember (struct script_state *st);
-int buildin_getguildname (struct script_state *st);
-int buildin_getguildmaster (struct script_state *st);
-int buildin_getguildmasterid (struct script_state *st);
-int buildin_strcharinfo (struct script_state *st);
-int buildin_getequipid (struct script_state *st);
-int buildin_getequipname (struct script_state *st);
-int buildin_getbrokenid (struct script_state *st); // [Valaris]
-int buildin_repair (struct script_state *st); // [Valaris]
-int buildin_getequipisequiped (struct script_state *st);
-int buildin_getequipisenableref (struct script_state *st);
-int buildin_getequipisidentify (struct script_state *st);
-int buildin_getequiprefinerycnt (struct script_state *st);
-int buildin_getequipweaponlv (struct script_state *st);
-int buildin_getequippercentrefinery (struct script_state *st);
-int buildin_successrefitem (struct script_state *st);
-int buildin_failedrefitem (struct script_state *st);
-int buildin_cutin (struct script_state *st);
-int buildin_cutincard (struct script_state *st);
-int buildin_statusup (struct script_state *st);
-int buildin_statusup2 (struct script_state *st);
-int buildin_bonus (struct script_state *st);
-int buildin_bonus2 (struct script_state *st);
-int buildin_bonus3 (struct script_state *st);
-int buildin_skill (struct script_state *st);
-int buildin_setskill (struct script_state *st);
-int buildin_guildskill (struct script_state *st);
-int buildin_getskilllv (struct script_state *st);
-int buildin_getgdskilllv (struct script_state *st);
-int buildin_basicskillcheck (struct script_state *st);
-int buildin_getgmlevel (struct script_state *st);
-int buildin_end (struct script_state *st);
-int buildin_getopt2 (struct script_state *st);
-int buildin_setopt2 (struct script_state *st);
-int buildin_checkoption (struct script_state *st);
-int buildin_setoption (struct script_state *st);
-int buildin_setcart (struct script_state *st);
-int buildin_checkcart (struct script_state *st); // check cart [Valaris]
-int buildin_setfalcon (struct script_state *st);
-int buildin_checkfalcon (struct script_state *st); // check falcon [Valaris]
-int buildin_setriding (struct script_state *st);
-int buildin_checkriding (struct script_state *st); // check for pecopeco [Valaris]
-int buildin_savepoint (struct script_state *st);
-int buildin_gettimetick (struct script_state *st);
-int buildin_gettime (struct script_state *st);
-int buildin_gettimestr (struct script_state *st);
-int buildin_openstorage (struct script_state *st);
-int buildin_guildopenstorage (struct script_state *st);
-int buildin_itemskill (struct script_state *st);
-int buildin_monster (struct script_state *st);
-int buildin_areamonster (struct script_state *st);
-int buildin_killmonster (struct script_state *st);
-int buildin_killmonsterall (struct script_state *st);
-int buildin_doevent (struct script_state *st);
-int buildin_donpcevent (struct script_state *st);
-int buildin_addtimer (struct script_state *st);
-int buildin_deltimer (struct script_state *st);
-int buildin_addtimercount (struct script_state *st);
-int buildin_initnpctimer (struct script_state *st);
-int buildin_stopnpctimer (struct script_state *st);
-int buildin_startnpctimer (struct script_state *st);
-int buildin_setnpctimer (struct script_state *st);
-int buildin_getnpctimer (struct script_state *st);
-int buildin_announce (struct script_state *st);
-int buildin_mapannounce (struct script_state *st);
-int buildin_areaannounce (struct script_state *st);
-int buildin_getusers (struct script_state *st);
-int buildin_getmapusers (struct script_state *st);
-int buildin_getareausers (struct script_state *st);
-int buildin_getareadropitem (struct script_state *st);
-int buildin_enablenpc (struct script_state *st);
-int buildin_disablenpc (struct script_state *st);
-int buildin_enablearena (struct script_state *st); // Added by RoVeRT
-int buildin_disablearena (struct script_state *st); // Added by RoVeRT
-int buildin_hideoffnpc (struct script_state *st);
-int buildin_hideonnpc (struct script_state *st);
-int buildin_sc_start (struct script_state *st);
-int buildin_sc_start2 (struct script_state *st);
-int buildin_sc_end (struct script_state *st);
-int buildin_sc_check (struct script_state *st); // [Fate]
-int buildin_getscrate (struct script_state *st);
-int buildin_debugmes (struct script_state *st);
-int buildin_resetlvl (struct script_state *st);
-int buildin_resetstatus (struct script_state *st);
-int buildin_resetskill (struct script_state *st);
-int buildin_changebase (struct script_state *st);
-int buildin_changesex (struct script_state *st);
-int buildin_waitingroom (struct script_state *st);
-int buildin_delwaitingroom (struct script_state *st);
-int buildin_enablewaitingroomevent (struct script_state *st);
-int buildin_disablewaitingroomevent (struct script_state *st);
-int buildin_getwaitingroomstate (struct script_state *st);
-int buildin_warpwaitingpc (struct script_state *st);
-int buildin_attachrid (struct script_state *st);
-int buildin_detachrid (struct script_state *st);
-int buildin_isloggedin (struct script_state *st);
-int buildin_setmapflagnosave (struct script_state *st);
-int buildin_setmapflag (struct script_state *st);
-int buildin_removemapflag (struct script_state *st);
-int buildin_pvpon (struct script_state *st);
-int buildin_pvpoff (struct script_state *st);
-int buildin_gvgon (struct script_state *st);
-int buildin_gvgoff (struct script_state *st);
-int buildin_emotion (struct script_state *st);
-int buildin_maprespawnguildid (struct script_state *st);
-int buildin_agitstart (struct script_state *st); // <Agit>
-int buildin_agitend (struct script_state *st);
-int buildin_agitcheck (struct script_state *st); // <Agitcheck>
-int buildin_flagemblem (struct script_state *st); // Flag Emblem
-int buildin_getcastlename (struct script_state *st);
-int buildin_getcastledata (struct script_state *st);
-int buildin_setcastledata (struct script_state *st);
-int buildin_requestguildinfo (struct script_state *st);
-int buildin_getequipcardcnt (struct script_state *st);
-int buildin_successremovecards (struct script_state *st);
-int buildin_failedremovecards (struct script_state *st);
-int buildin_marriage (struct script_state *st);
-int buildin_wedding_effect (struct script_state *st);
-int buildin_divorce (struct script_state *st);
-int buildin_getitemname (struct script_state *st);
-int buildin_getspellinvocation (struct script_state *st); // [Fate]
-int buildin_getanchorinvocation (struct script_state *st); // [Fate]
-int buildin_getexp (struct script_state *st);
-int buildin_getinventorylist (struct script_state *st);
-int buildin_getskilllist (struct script_state *st);
-int buildin_get_pool_skills (struct script_state *st); // [fate]
-int buildin_get_activated_pool_skills (struct script_state *st); // [fate]
-int buildin_get_unactivated_pool_skills (struct script_state *st); // [PO]
-int buildin_activate_pool_skill (struct script_state *st); // [fate]
-int buildin_deactivate_pool_skill (struct script_state *st); // [fate]
-int buildin_check_pool_skill (struct script_state *st); // [fate]
-int buildin_clearitem (struct script_state *st);
-int buildin_classchange (struct script_state *st);
-int buildin_misceffect (struct script_state *st);
-int buildin_soundeffect (struct script_state *st);
-int buildin_mapwarp (struct script_state *st);
-int buildin_inittimer (struct script_state *st);
-int buildin_stoptimer (struct script_state *st);
-int buildin_cmdothernpc (struct script_state *st);
-int buildin_mobcount (struct script_state *st);
-int buildin_strmobinfo (struct script_state *st); // Script for displaying mob info [Valaris]
-int buildin_guardian (struct script_state *st); // Script for displaying mob info [Valaris]
-int buildin_guardianinfo (struct script_state *st); // Script for displaying mob info [Valaris]
-int buildin_npcskilleffect (struct script_state *st); // skill effects for npcs [Valaris]
-int buildin_specialeffect (struct script_state *st); // special effect script [Valaris]
-int buildin_specialeffect2 (struct script_state *st); // special effect script [Valaris]
-int buildin_nude (struct script_state *st); // nude [Valaris]
-int buildin_gmcommand (struct script_state *st); // [MouseJstr]
-int buildin_movenpc (struct script_state *st); // [MouseJstr]
-int buildin_npcwarp (struct script_state *st); // [remoitnane]
-int buildin_message (struct script_state *st); // [MouseJstr]
-int buildin_npctalk (struct script_state *st); // [Valaris]
-int buildin_hasitems (struct script_state *st); // [Valaris]
-int buildin_getlook (struct script_state *st); //Lorky [Lupus]
-int buildin_getsavepoint (struct script_state *st); //Lorky [Lupus]
-int buildin_getpartnerid (struct script_state *st); // [Fate]
-int buildin_areatimer (struct script_state *st); // [Jaxad0127]
-int buildin_isin (struct script_state *st); // [Jaxad0127]
-int buildin_shop (struct script_state *st); // [MadCamel]
-int buildin_isdead (struct script_state *st); // [Jaxad0127]
-int buildin_fakenpcname (struct script_state *st); //[Kage]
-int buildin_unequip_by_id (struct script_state *st); // [Freeyorp]
-int buildin_getx (struct script_state *st); // [Kage]
-int buildin_gety (struct script_state *st); // [Kage]
-
-
-void push_val (struct script_stack *stack, int type, int val);
-int run_func (struct script_state *st);
-
-int mapreg_setreg (int num, int val);
-int mapreg_setregstr (int num, const char *str);
-
-struct
-{
- int (*func) (struct script_state *);
+static
+const char *parse_subexpr(const char *, int);
+
+static
+void run_func(ScriptState *st);
+
+static
+void mapreg_setreg(int num, int val);
+static
+void mapreg_setregstr(int num, const char *str);
+
+struct BuiltinFunction
+{
+ void(*func)(ScriptState *);
const char *name;
const char *arg;
-} buildin_func[] =
-{
- {
- buildin_mes, "mes", "s"},
- {
- buildin_next, "next", ""},
- {
- buildin_close, "close", ""},
- {
- buildin_close2, "close2", ""},
- {
- buildin_menu, "menu", "sL*"},
- {
- buildin_goto, "goto", "L"},
- {
- buildin_callsub, "callsub", "L*"},
- {
- buildin_callfunc, "callfunc", "F*"},
- {
- buildin_return, "return", "*"},
- {
- buildin_getarg, "getarg", "i"},
- {
- buildin_jobchange, "jobchange", "i*"},
- {
- buildin_input, "input", "N"},
- {
- buildin_warp, "warp", "Mxy"},
- {
- buildin_isat, "isat", "Mxy"},
- {
- buildin_areawarp, "areawarp", "MxyxyMxy"},
- {
- buildin_setlook, "setlook", "ii"},
- {
- buildin_set, "set", "Ne"},
- {
- buildin_setarray, "setarray", "Ne*"},
- {
- buildin_cleararray, "cleararray", "Nei"},
- {
- buildin_copyarray, "copyarray", "NNi"},
- {
- buildin_getarraysize, "getarraysize", "N"},
- {
- buildin_deletearray, "deletearray", "N*"},
- {
- buildin_getelementofarray, "getelementofarray", "Ni"},
- {
- buildin_if, "if", "iF*"},
- {
- buildin_getitem, "getitem", "Ii**"},
- {
- buildin_getitem2, "getitem2", "iiiiiiiii*"},
- {
- buildin_makeitem, "makeitem", "IiMxy"},
- {
- buildin_delitem, "delitem", "Ii"},
- {
- buildin_cutin, "cutin", "si"},
- {
- buildin_cutincard, "cutincard", "i"},
- {
- buildin_viewpoint, "viewpoint", "iiiii"},
- {
- buildin_heal, "heal", "ii"},
- {
- buildin_itemheal, "itemheal", "ii"},
- {
- buildin_percentheal, "percentheal", "ii"},
- {
- buildin_rand, "rand", "i*"},
- {
- buildin_pow, "pow", "ii"},
- {
- buildin_countitem, "countitem", "I"},
- {
- buildin_checkweight, "checkweight", "Ii"},
- {
- buildin_readparam, "readparam", "i*"},
- {
- buildin_getcharid, "getcharid", "i*"},
- {
- buildin_getpartyname, "getpartyname", "i"},
- {
- buildin_getpartymember, "getpartymember", "i"},
- {
- buildin_getguildname, "getguildname", "i"},
- {
- buildin_getguildmaster, "getguildmaster", "i"},
- {
- buildin_getguildmasterid, "getguildmasterid", "i"},
- {
- buildin_strcharinfo, "strcharinfo", "i"},
- {
- buildin_getequipid, "getequipid", "i"},
- {
- buildin_getequipname, "getequipname", "i"},
- {
- buildin_getbrokenid, "getbrokenid", "i"}, // [Valaris]
- {
- buildin_repair, "repair", "i"}, // [Valaris]
- {
- buildin_getequipisequiped, "getequipisequiped", "i"},
- {
- buildin_getequipisenableref, "getequipisenableref", "i"},
- {
- buildin_getequipisidentify, "getequipisidentify", "i"},
- {
- buildin_getequiprefinerycnt, "getequiprefinerycnt", "i"},
- {
- buildin_getequipweaponlv, "getequipweaponlv", "i"},
- {
- buildin_getequippercentrefinery, "getequippercentrefinery", "i"},
- {
- buildin_successrefitem, "successrefitem", "i"},
- {
- buildin_failedrefitem, "failedrefitem", "i"},
- {
- buildin_statusup, "statusup", "i"},
- {
- buildin_statusup2, "statusup2", "ii"},
- {
- buildin_bonus, "bonus", "ii"},
- {
- buildin_bonus2, "bonus2", "iii"},
- {
- buildin_bonus3, "bonus3", "iiii"},
- {
- buildin_skill, "skill", "ii*"},
- {
- buildin_setskill, "setskill", "ii"}, // [Fate]
- {
- buildin_guildskill, "guildskill", "ii"},
- {
- buildin_getskilllv, "getskilllv", "i"},
- {
- buildin_getgdskilllv, "getgdskilllv", "ii"},
- {
- buildin_basicskillcheck, "basicskillcheck", "*"},
- {
- buildin_getgmlevel, "getgmlevel", ""},
- {
- buildin_end, "end", ""},
- {
- buildin_getopt2, "getopt2", ""},
- {
- buildin_setopt2, "setopt2", "i"},
- {
- buildin_end, "break", ""},
- {
- buildin_checkoption, "checkoption", "i"},
- {
- buildin_setoption, "setoption", "i"},
- {
- buildin_setcart, "setcart", ""},
- {
- buildin_checkcart, "checkcart", "*"}, //fixed by Lupus (added '*')
- {
- buildin_setfalcon, "setfalcon", ""},
- {
- buildin_checkfalcon, "checkfalcon", "*"}, //fixed by Lupus (fixed wrong pointer, added '*')
- {
- buildin_setriding, "setriding", ""},
- {
- buildin_checkriding, "checkriding", "*"}, //fixed by Lupus (fixed wrong pointer, added '*')
- {
- buildin_savepoint, "save", "sii"},
- {
- buildin_savepoint, "savepoint", "Mxy"},
- {
- buildin_gettimetick, "gettimetick", "i"},
- {
- buildin_gettime, "gettime", "i"},
- {
- buildin_gettimestr, "gettimestr", "si"},
- {
- buildin_openstorage, "openstorage", "*"},
- {
- buildin_guildopenstorage, "guildopenstorage", "*"},
- {
- buildin_itemskill, "itemskill", "iis"},
- {
- buildin_monster, "monster", "Mxysmi*"},
- {
- buildin_areamonster, "areamonster", "Mxyxysmi*"},
- {
- buildin_killmonster, "killmonster", "ME"},
- {
- buildin_killmonsterall, "killmonsterall", "M"},
- {
- buildin_doevent, "doevent", "E"},
- {
- buildin_donpcevent, "donpcevent", "E"},
- {
- buildin_addtimer, "addtimer", "tE"},
- {
- buildin_deltimer, "deltimer", "E"},
- {
- buildin_addtimercount, "addtimercount", "si"},
- {
- buildin_initnpctimer, "initnpctimer", ""},
- {
- buildin_stopnpctimer, "stopnpctimer", ""},
- {
- buildin_startnpctimer, "startnpctimer", "*"},
- {
- buildin_setnpctimer, "setnpctimer", "i"},
- {
- buildin_getnpctimer, "getnpctimer", "i"},
- {
- buildin_announce, "announce", "si"},
- {
- buildin_mapannounce, "mapannounce", "Msi"},
- {
- buildin_areaannounce, "areaannounce", "Mxyxysi"},
- {
- buildin_getusers, "getusers", "i"},
- {
- buildin_getmapusers, "getmapusers", "M"},
- {
- buildin_getareausers, "getareausers", "Mxyxy*"},
- {
- buildin_getareadropitem, "getareadropitem", "Mxyxyi*"},
- {
- buildin_enablenpc, "enablenpc", "s"},
- {
- buildin_disablenpc, "disablenpc", "s"},
- {
- buildin_enablearena, "enablearena", ""}, // Added by RoVeRT
- {
- buildin_disablearena, "disablearena", ""}, // Added by RoVeRT
- {
- buildin_hideoffnpc, "hideoffnpc", "s"},
- {
- buildin_hideonnpc, "hideonnpc", "s"},
- {
- buildin_sc_start, "sc_start", "iTi*"},
- {
- buildin_sc_start2, "sc_start2", "iTii*"},
- {
- buildin_sc_end, "sc_end", "i"},
- {
- buildin_sc_check, "sc_check", "i"},
- {
- buildin_getscrate, "getscrate", "ii*"},
- {
- buildin_debugmes, "debugmes", "s"},
- {
- buildin_resetlvl, "resetlvl", "i"},
- {
- buildin_resetstatus, "resetstatus", ""},
- {
- buildin_resetskill, "resetskill", ""},
- {
- buildin_changebase, "changebase", "i"},
- {
- buildin_changesex, "changesex", ""},
- {
- buildin_waitingroom, "waitingroom", "si*"},
- {
- buildin_warpwaitingpc, "warpwaitingpc", "sii"},
- {
- buildin_delwaitingroom, "delwaitingroom", "*"},
- {
- buildin_enablewaitingroomevent, "enablewaitingroomevent", "*"},
- {
- buildin_disablewaitingroomevent, "disablewaitingroomevent", "*"},
- {
- buildin_getwaitingroomstate, "getwaitingroomstate", "i*"},
- {
- buildin_warpwaitingpc, "warpwaitingpc", "sii*"},
- {
- buildin_attachrid, "attachrid", "i"},
- {
- buildin_detachrid, "detachrid", ""},
- {
- buildin_isloggedin, "isloggedin", "i"},
- {
- buildin_setmapflagnosave, "setmapflagnosave", "MMxy"},
- {
- buildin_setmapflag, "setmapflag", "Mi"},
- {
- buildin_removemapflag, "removemapflag", "Mi"},
- {
- buildin_pvpon, "pvpon", "M"},
- {
- buildin_pvpoff, "pvpoff", "M"},
- {
- buildin_gvgon, "gvgon", "s"},
- {
- buildin_gvgoff, "gvgoff", "s"},
- {
- buildin_emotion, "emotion", "i"},
- {
- buildin_maprespawnguildid, "maprespawnguildid", "sii"},
- {
- buildin_agitstart, "agitstart", ""}, // <Agit>
- {
- buildin_agitend, "agitend", ""},
- {
- buildin_agitcheck, "agitcheck", "i"}, // <Agitcheck>
- {
- buildin_flagemblem, "flagemblem", "i"}, // Flag Emblem
- {
- buildin_getcastlename, "getcastlename", "s"},
- {
- buildin_getcastledata, "getcastledata", "si*"},
- {
- buildin_setcastledata, "setcastledata", "sii"},
- {
- buildin_requestguildinfo, "requestguildinfo", "i*"},
- {
- buildin_getequipcardcnt, "getequipcardcnt", "i"},
- {
- buildin_successremovecards, "successremovecards", "i"},
- {
- buildin_failedremovecards, "failedremovecards", "ii"},
- {
- buildin_marriage, "marriage", "P"},
- {
- buildin_wedding_effect, "wedding", ""},
- {
- buildin_divorce, "divorce", ""},
- {
- buildin_getitemname, "getitemname", "I"},
- {
- buildin_getspellinvocation, "getspellinvocation", "s"},
- {
- buildin_getanchorinvocation, "getanchorinvocation", "s"},
- {
- buildin_getpartnerid, "getpartnerid2", ""},
- {
- buildin_getexp, "getexp", "ii"},
- {
- buildin_getinventorylist, "getinventorylist", ""},
- {
- buildin_getskilllist, "getskilllist", ""},
- {
- buildin_get_pool_skills, "getpoolskilllist", ""},
- {
- buildin_get_activated_pool_skills, "getactivatedpoolskilllist", ""},
- {
- buildin_get_unactivated_pool_skills, "getunactivatedpoolskilllist", ""},
- {
- buildin_activate_pool_skill, "poolskill", "i"},
- {
- buildin_deactivate_pool_skill, "unpoolskill", "i"},
- {
- buildin_check_pool_skill, "checkpoolskill", "i"},
- {
- buildin_clearitem, "clearitem", ""},
- {
- buildin_classchange, "classchange", "ii"},
- {
- buildin_misceffect, "misceffect", "i*"},
- {
- buildin_soundeffect, "soundeffect", "si"},
- {
- buildin_strmobinfo, "strmobinfo", "im"}, // display mob data [Valaris]
- {
- buildin_guardian, "guardian", "siisii*i"}, // summon guardians
- {
- buildin_guardianinfo, "guardianinfo", "i"}, // display guardian data [Valaris]
- {
- buildin_npcskilleffect, "npcskilleffect", "iiii"}, // npc skill effect [Valaris]
- {
- buildin_specialeffect, "specialeffect", "i"}, // npc skill effect [Valaris]
- {
- buildin_specialeffect2, "specialeffect2", "i"}, // skill effect on players[Valaris]
- {
- buildin_nude, "nude", ""}, // nude command [Valaris]
- {
- buildin_mapwarp, "mapwarp", "MMxy"}, // Added by RoVeRT
- {
- buildin_inittimer, "inittimer", ""},
- {
- buildin_stoptimer, "stoptimer", ""},
- {
- buildin_cmdothernpc, "cmdothernpc", "ss"},
- {
- buildin_gmcommand, "gmcommand", "s"}, // [MouseJstr]
-// {buildin_movenpc,"movenpc","siis"}, // [MouseJstr]
- {
- buildin_npcwarp, "npcwarp", "xys"}, // [remoitnane]
- {
- buildin_message, "message", "Ps"}, // [MouseJstr]
- {
- buildin_npctalk, "npctalk", "s"}, // [Valaris]
- {
- buildin_hasitems, "hasitems", ""}, // [Valaris]
- {
- buildin_mobcount, "mobcount", "ME"},
- {
- buildin_getlook, "getlook", "i"},
- {
- buildin_getsavepoint, "getsavepoint", "i"},
- {
- buildin_areatimer, "areatimer", "MxyxytE"},
- {
- buildin_isin, "isin", "Mxyxy"},
- {
- buildin_shop, "shop", "s"},
- {
- buildin_isdead, "isdead", ""},
- {
- buildin_fakenpcname, "fakenpcname", "ssi"},
- {
- buildin_unequip_by_id, "unequipbyid", "i"}, // [Freeyorp]
- {
- buildin_getx, "getx", ""}, // [Kage]
- {
- buildin_gety, "gety", ""}, // [Kage]
- // End Additions
- {
-NULL, NULL, NULL},};
+};
+// defined later
+extern BuiltinFunction builtin_functions[];
+
-#ifdef RECENT_GCC
enum class ScriptCode : uint8_t
{
- // tyoes and specials
+ // types and specials
NOP, POS, INT, PARAM, FUNC, STR, CONSTSTR, ARG,
NAME, EOL, RETINFO,
@@ -754,16 +146,16 @@ enum class ScriptCode : uint8_t
XOR, OR, AND, ADD, SUB, MUL, DIV, MOD, NEG, LNOT,
NOT, R_SHIFT, L_SHIFT
};
-#endif
/*==========================================
* 文字列ã®ãƒãƒƒã‚·ãƒ¥ã‚’計算
*------------------------------------------
*/
-static int calc_hash (const char *s)
+static
+int calc_hash(const char *s)
{
const unsigned char *p = (const unsigned char *)s;
- int h = 0;
+ int h = 0;
while (*p)
{
h = (h << 1) + (h >> 3) + (h >> 5) + (h >> 8);
@@ -777,13 +169,14 @@ static int calc_hash (const char *s)
*------------------------------------------
*/
// 既存ã®ã§ã‚ã‚Œã°ç•ªå·ã€ç„¡ã‘ã‚Œã°-1
-static int search_str (const char *p)
+static
+int search_str(const char *p)
{
- int i;
- i = str_hash[calc_hash (p)];
+ int i;
+ i = str_hash[calc_hash(p)];
while (i)
{
- if (strcmp (str_buf + str_data[i].str, p) == 0)
+ if (strcmp(str_buf + str_data[i].str, p) == 0)
{
return i;
}
@@ -797,22 +190,24 @@ static int search_str (const char *p)
*------------------------------------------
*/
// 既存ã®ã§ã‚ã‚Œã°ç•ªå·ã€ç„¡ã‘ã‚Œã°ç™»éŒ²ã—ã¦æ–°è¦ç•ªå·
-static int add_str (const char *p)
+static
+int add_str(const char *p)
{
- int i;
+ int i;
char *lowcase;
- lowcase = strdup (p);
+ // TODO remove lowcase
+ lowcase = strdup(p);
for (i = 0; lowcase[i]; i++)
- lowcase[i] = tolower (lowcase[i]);
- if ((i = search_str (lowcase)) >= 0)
+ lowcase[i] = tolower(lowcase[i]);
+ if ((i = search_str(lowcase)) >= 0)
{
- free (lowcase);
+ free(lowcase);
return i;
}
- free (lowcase);
+ free(lowcase);
- i = calc_hash (p);
+ i = calc_hash(p);
if (str_hash[i] == 0)
{
str_hash[i] = str_num;
@@ -822,7 +217,7 @@ static int add_str (const char *p)
i = str_hash[i];
for (;;)
{
- if (strcmp (str_buf + str_data[i].str, p) == 0)
+ if (strcmp(str_buf + str_data[i].str, p) == 0)
{
return i;
}
@@ -835,23 +230,23 @@ static int add_str (const char *p)
if (str_num >= str_data_size)
{
str_data_size += 128;
- RECREATE (str_data, struct str_data_t, str_data_size);
- memset (str_data + (str_data_size - 128), '\0', 128);
+ RECREATE(str_data, struct str_data_t, str_data_size);
+ memset(str_data + (str_data_size - 128), '\0', 128);
}
- while (str_pos + strlen (p) + 1 >= str_size)
+ while (str_pos + strlen(p) + 1 >= str_size)
{
str_size += 256;
- str_buf = (char *) realloc (str_buf, str_size);
- memset (str_buf + (str_size - 256), '\0', 256);
+ str_buf = (char *) realloc(str_buf, str_size);
+ memset(str_buf + (str_size - 256), '\0', 256);
}
- strcpy (str_buf + str_pos, p);
+ strcpy(str_buf + str_pos, p);
str_data[str_num].type = ScriptCode::NOP;
str_data[str_num].str = str_pos;
str_data[str_num].next = 0;
str_data[str_num].func = NULL;
str_data[str_num].backpatch = -1;
str_data[str_num].label = -1;
- str_pos += strlen (p) + 1;
+ str_pos += strlen(p) + 1;
return str_num++;
}
@@ -859,13 +254,14 @@ static int add_str (const char *p)
* スクリプトãƒãƒƒãƒ•ã‚¡ã‚µã‚¤ã‚ºã®ç¢ºèªã¨æ‹¡å¼µ
*------------------------------------------
*/
-static void check_script_buf (int size)
+static
+void check_script_buf(int size)
{
if (script_pos + size >= script_size)
{
script_size += SCRIPT_BLOCK_SIZE;
- script_buf = (ScriptCode *) realloc (script_buf, script_size);
- memset (script_buf + script_size - SCRIPT_BLOCK_SIZE, '\0',
+ script_buf = (ScriptCode *) realloc(script_buf, script_size);
+ memset(script_buf + script_size - SCRIPT_BLOCK_SIZE, '\0',
SCRIPT_BLOCK_SIZE);
}
}
@@ -875,9 +271,9 @@ static void check_script_buf (int size)
*------------------------------------------
*/
static
-void add_scriptc (ScriptCode a)
+void add_scriptc(ScriptCode a)
{
- check_script_buf (1);
+ check_script_buf(1);
script_buf[script_pos++] = a;
}
@@ -886,7 +282,7 @@ void add_scriptc (ScriptCode a)
*------------------------------------------
*/
static
-void add_scriptb (uint8_t a)
+void add_scriptb(uint8_t a)
{
add_scriptc(static_cast<ScriptCode>(a));
}
@@ -895,14 +291,15 @@ void add_scriptb (uint8_t a)
* スクリプトãƒãƒƒãƒ•ã‚¡ã«æ•´æ•°ã‚’書ã込む
*------------------------------------------
*/
-static void add_scripti (unsigned int a)
+static
+void add_scripti(unsigned int a)
{
while (a >= 0x40)
{
- add_scriptb (a | 0xc0);
+ add_scriptb(a | 0xc0);
a = (a - 0x40) >> 6;
}
- add_scriptb (a | 0x80);
+ add_scriptb(a | 0x80);
}
/*==========================================
@@ -910,35 +307,36 @@ static void add_scripti (unsigned int a)
*------------------------------------------
*/
// 最大16Mã¾ã§
-static void add_scriptl (int l)
+static
+void add_scriptl(int l)
{
- int backpatch = str_data[l].backpatch;
+ int backpatch = str_data[l].backpatch;
switch (str_data[l].type)
{
case ScriptCode::POS:
- add_scriptc (ScriptCode::POS);
- add_scriptb ({uint8_t(str_data[l].label)});
- add_scriptb ({uint8_t(str_data[l].label >> 8)});
- add_scriptb ({uint8_t(str_data[l].label >> 16)});
+ add_scriptc(ScriptCode::POS);
+ add_scriptb({uint8_t(str_data[l].label)});
+ add_scriptb({uint8_t(str_data[l].label >> 8)});
+ add_scriptb({uint8_t(str_data[l].label >> 16)});
break;
case ScriptCode::NOP:
// ラベルã®å¯èƒ½æ€§ãŒã‚ã‚‹ã®ã§backpatch用データ埋ã‚è¾¼ã¿
- add_scriptc (ScriptCode::NAME);
+ add_scriptc(ScriptCode::NAME);
str_data[l].backpatch = script_pos;
- add_scriptb ({uint8_t(backpatch)});
- add_scriptb ({uint8_t(backpatch >> 8)});
- add_scriptb ({uint8_t(backpatch >> 16)});
+ add_scriptb({uint8_t(backpatch)});
+ add_scriptb({uint8_t(backpatch >> 8)});
+ add_scriptb({uint8_t(backpatch >> 16)});
break;
case ScriptCode::INT:
- add_scripti (str_data[l].val);
+ add_scripti(str_data[l].val);
break;
default:
// ã‚‚ã†ä»–ã®ç”¨é€”ã¨ç¢ºå®šã—ã¦ã‚‹ã®ã§æ•°å­—ã‚’ãã®ã¾ã¾
- add_scriptc (ScriptCode::NAME);
- add_scriptb ({uint8_t(l)});
- add_scriptb ({uint8_t(l >> 8)});
- add_scriptb ({uint8_t(l >> 16)});
+ add_scriptc(ScriptCode::NAME);
+ add_scriptb({uint8_t(l)});
+ add_scriptb({uint8_t(l >> 8)});
+ add_scriptb({uint8_t(l >> 16)});
break;
}
}
@@ -948,15 +346,15 @@ static void add_scriptl (int l)
*------------------------------------------
*/
static
-void set_label (int l, int pos_)
+void set_label(int l, int pos_)
{
- int i, next;
+ int i, next;
str_data[l].type = ScriptCode::POS;
str_data[l].label = pos_;
for (i = str_data[l].backpatch; i >= 0 && i != 0x00ffffff;)
{
- next = (*(int *) (script_buf + i)) & 0x00ffffff;
+ next = (*(int *)(script_buf + i)) & 0x00ffffff;
script_buf[i - 1] = ScriptCode::POS;
script_buf[i] = static_cast<ScriptCode>(pos_);
script_buf[i + 1] = static_cast<ScriptCode>(pos_ >> 8);
@@ -969,11 +367,12 @@ void set_label (int l, int pos_)
* スペース/コメント読ã¿é£›ã°ã—
*------------------------------------------
*/
-static const char *skip_space (const char *p)
+static
+const char *skip_space(const char *p)
{
while (1)
{
- while (isspace (*p))
+ while (isspace(*p))
p++;
if (p[0] == '/' && p[1] == '/')
{
@@ -999,7 +398,7 @@ static const char *skip_space (const char *p)
*------------------------------------------
*/
static
-const char *skip_word (const char *p)
+const char *skip_word(const char *p)
{
// prefix
if (*p == '$')
@@ -1013,7 +412,7 @@ const char *skip_word (const char *p)
if (*p == 'l')
p++; // 一時的変数用(like weiss)
- while (isalnum (*p) || *p == '_')
+ while (isalnum(*p) || *p == '_')
p++;
// postfix
@@ -1023,14 +422,17 @@ const char *skip_word (const char *p)
return p;
}
-static const char *startptr;
-static int startline;
+static
+const char *startptr;
+static
+int startline;
/*==========================================
* エラーメッセージ出力
*------------------------------------------
*/
-static void disp_error_message (const char *mes, const char *pos_)
+static
+void disp_error_message(const char *mes, const char *pos_)
{
int line;
const char *p;
@@ -1038,8 +440,9 @@ static void disp_error_message (const char *mes, const char *pos_)
for (line = startline, p = startptr; p && *p; line++)
{
const char *linestart = p;
- char *lineend = const_cast<char *>(strchr (p, '\n'));
- char c;
+ char *lineend = const_cast<char *>(strchr(p, '\n'));
+ // always initialized, but clang is not smart enough
+ char c = '\0';
if (lineend)
{
c = *lineend;
@@ -1047,17 +450,17 @@ static void disp_error_message (const char *mes, const char *pos_)
}
if (lineend == NULL || pos_ < lineend)
{
- printf ("%s line %d : ", mes, line);
+ PRINTF("%s line %d : ", mes, line);
for (int i = 0;
(linestart[i] != '\r') && (linestart[i] != '\n')
&& linestart[i]; i++)
{
if (linestart + i != pos_)
- printf ("%c", linestart[i]);
+ PRINTF("%c", linestart[i]);
else
- printf ("\'%c\'", linestart[i]);
+ PRINTF("\'%c\'", linestart[i]);
}
- printf ("\a\n");
+ PRINTF("\a\n");
if (lineend)
*lineend = c;
return;
@@ -1072,41 +475,41 @@ static void disp_error_message (const char *mes, const char *pos_)
*------------------------------------------
*/
static
-const char *parse_simpleexpr (const char *p)
+const char *parse_simpleexpr(const char *p)
{
- int i;
- p = skip_space (p);
+ int i;
+ p = skip_space(p);
#ifdef DEBUG_FUNCIN
if (battle_config.etc_log)
- printf ("parse_simpleexpr %s\n", p);
+ PRINTF("parse_simpleexpr %s\n", p);
#endif
if (*p == ';' || *p == ',')
{
- disp_error_message ("unexpected expr end", p);
- exit (1);
+ disp_error_message("unexpected expr end", p);
+ exit(1);
}
if (*p == '(')
{
- p = parse_subexpr (p + 1, -1);
- p = skip_space (p);
+ p = parse_subexpr(p + 1, -1);
+ p = skip_space(p);
if ((*p++) != ')')
{
- disp_error_message ("unmatch ')'", p);
- exit (1);
+ disp_error_message("unmatch ')'", p);
+ exit(1);
}
}
- else if (isdigit (*p) || ((*p == '-' || *p == '+') && isdigit (p[1])))
+ else if (isdigit(*p) || ((*p == '-' || *p == '+') && isdigit(p[1])))
{
char *np;
- i = strtoul (p, &np, 0);
- add_scripti (i);
+ i = strtoul(p, &np, 0);
+ add_scripti(i);
p = np;
}
else if (*p == '"')
{
- add_scriptc (ScriptCode::STR);
+ add_scriptc(ScriptCode::STR);
p++;
while (*p && *p != '"')
{
@@ -1114,44 +517,44 @@ const char *parse_simpleexpr (const char *p)
p++;
else if (*p == '\n')
{
- disp_error_message ("unexpected newline @ string", p);
- exit (1);
+ disp_error_message("unexpected newline @ string", p);
+ exit(1);
}
- add_scriptb (*p++);
+ add_scriptb(*p++);
}
if (!*p)
{
- disp_error_message ("unexpected eof @ string", p);
- exit (1);
+ disp_error_message("unexpected eof @ string", p);
+ exit(1);
}
- add_scriptb (0);
+ add_scriptb(0);
p++; //'"'
}
else
{
int l;
// label , register , function etc
- if (skip_word (p) == p)
+ if (skip_word(p) == p)
{
- disp_error_message ("unexpected character", p);
- exit (1);
+ disp_error_message("unexpected character", p);
+ exit(1);
}
char *p2 = const_cast<char *>(skip_word(p));
char c = *p2;
*p2 = 0; // åå‰ã‚’add_strã™ã‚‹
- l = add_str (p);
+ l = add_str(p);
parse_cmd = l; // warn_*_mismatch_paramnumã®ãŸã‚ã«å¿…è¦
- if (l == search_str ("if")) // warn_cmd_no_commaã®ãŸã‚ã«å¿…è¦
+ if (l == search_str("if")) // warn_cmd_no_commaã®ãŸã‚ã«å¿…è¦
parse_cmd_if++;
/*
- // 廃止予定ã®l14/l15,ãŠã‚ˆã³ãƒ—レフィックスlã®è­¦å‘Š
- if( strcmp(str_buf+str_data[l].str,"l14")==0 ||
- strcmp(str_buf+str_data[l].str,"l15")==0 ){
- disp_error_message("l14 and l15 is DEPRECATED. use @menu instead of l15.",p);
- }else if(str_buf[str_data[l].str]=='l'){
- disp_error_message("prefix 'l' is DEPRECATED. use prefix '@' instead.",p2);
- }
+ // 廃止予定ã®l14/l15,ãŠã‚ˆã³ãƒ—レフィックスlã®è­¦å‘Š
+ if ( strcmp(str_buf+str_data[l].str,"l14")==0 ||
+ strcmp(str_buf+str_data[l].str,"l15")==0 ){
+ disp_error_message("l14 and l15 is DEPRECATED. use @menu instead of l15.",p);
+ }else if (str_buf[str_data[l].str]=='l'){
+ disp_error_message("prefix 'l' is DEPRECATED. use prefix '@' instead.",p2);
+ }
*/
*p2 = c;
p = p2;
@@ -1159,26 +562,26 @@ const char *parse_simpleexpr (const char *p)
if (str_data[l].type != ScriptCode::FUNC && c == '[')
{
// array(name[i] => getelementofarray(name,i) )
- add_scriptl (search_str ("getelementofarray"));
- add_scriptc (ScriptCode::ARG);
- add_scriptl (l);
- p = parse_subexpr (p + 1, -1);
- p = skip_space (p);
+ add_scriptl(search_str("getelementofarray"));
+ add_scriptc(ScriptCode::ARG);
+ add_scriptl(l);
+ p = parse_subexpr(p + 1, -1);
+ p = skip_space(p);
if ((*p++) != ']')
{
- disp_error_message ("unmatch ']'", p);
- exit (1);
+ disp_error_message("unmatch ']'", p);
+ exit(1);
}
- add_scriptc (ScriptCode::FUNC);
+ add_scriptc(ScriptCode::FUNC);
}
else
- add_scriptl (l);
+ add_scriptl(l);
}
#ifdef DEBUG_FUNCIN
if (battle_config.etc_log)
- printf ("parse_simpleexpr end %s\n", p);
+ PRINTF("parse_simpleexpr end %s\n", p);
#endif
return p;
}
@@ -1187,23 +590,23 @@ const char *parse_simpleexpr (const char *p)
* å¼ã®è§£æž
*------------------------------------------
*/
-const char *parse_subexpr (const char *p, int limit)
+const char *parse_subexpr(const char *p, int limit)
{
ScriptCode op;
int opl, len;
#ifdef DEBUG_FUNCIN
if (battle_config.etc_log)
- printf ("parse_subexpr %s\n", p);
+ PRINTF("parse_subexpr %s\n", p);
#endif
- p = skip_space (p);
+ p = skip_space(p);
if (*p == '-')
{
- const char *tmpp = skip_space (p + 1);
+ const char *tmpp = skip_space(p + 1);
if (*tmpp == ';' || *tmpp == ',')
{
- add_scriptl (LABEL_NEXTLINE);
+ add_scriptl(LABEL_NEXTLINE);
p++;
return p;
}
@@ -1212,12 +615,12 @@ const char *parse_subexpr (const char *p, int limit)
if ((op = ScriptCode::NEG, *p == '-') || (op = ScriptCode::LNOT, *p == '!')
|| (op = ScriptCode::NOT, *p == '~'))
{
- p = parse_subexpr (p + 1, 100);
- add_scriptc (op);
+ p = parse_subexpr(p + 1, 100);
+ add_scriptc(op);
}
else
- p = parse_simpleexpr (p);
- p = skip_space (p);
+ p = parse_simpleexpr(p);
+ p = skip_space(p);
while (((op = ScriptCode::ADD, opl = 6, len = 1, *p == '+') ||
(op = ScriptCode::SUB, opl = 6, len = 1, *p == '-') ||
(op = ScriptCode::MUL, opl = 7, len = 1, *p == '*') ||
@@ -1241,63 +644,63 @@ const char *parse_subexpr (const char *p, int limit)
p += len;
if (op == ScriptCode::FUNC)
{
- int i = 0, func = parse_cmd;
+ int i = 0, func = parse_cmd;
const char *plist[128];
if (str_data[func].type != ScriptCode::FUNC)
{
- disp_error_message ("expect function", tmpp);
- exit (0);
+ disp_error_message("expect function", tmpp);
+ exit(0);
}
- add_scriptc (ScriptCode::ARG);
+ add_scriptc(ScriptCode::ARG);
while (*p && *p != ')' && i < 128)
{
plist[i] = p;
- p = parse_subexpr (p, -1);
- p = skip_space (p);
+ p = parse_subexpr(p, -1);
+ p = skip_space(p);
if (*p == ',')
p++;
else if (*p != ')' && script_config.warn_func_no_comma)
{
- disp_error_message ("expect ',' or ')' at func params",
+ disp_error_message("expect ',' or ')' at func params",
p);
}
- p = skip_space (p);
+ p = skip_space(p);
i++;
}
plist[i] = p;
if (*(p++) != ')')
{
- disp_error_message ("func request '(' ')'", p);
- exit (1);
+ disp_error_message("func request '(' ')'", p);
+ exit(1);
}
if (str_data[func].type == ScriptCode::FUNC
&& script_config.warn_func_mismatch_paramnum)
{
- const char *arg = buildin_func[str_data[func].val].arg;
- int j = 0;
+ const char *arg = builtin_functions[str_data[func].val].arg;
+ int j = 0;
for (j = 0; arg[j]; j++)
if (arg[j] == '*')
break;
if ((arg[j] == 0 && i != j) || (arg[j] == '*' && i < j))
{
- disp_error_message ("illegal number of parameters",
+ disp_error_message("illegal number of parameters",
plist[(i < j) ? i : j]);
}
}
}
else // not op == ScriptCode::FUNC
{
- p = parse_subexpr (p, opl);
+ p = parse_subexpr(p, opl);
}
- add_scriptc (op);
- p = skip_space (p);
+ add_scriptc(op);
+ p = skip_space(p);
}
#ifdef DEBUG_FUNCIN
if (battle_config.etc_log)
- printf ("parse_subexpr end %s\n", p);
+ PRINTF("parse_subexpr end %s\n", p);
#endif
return p; /* return first untreated operator */
}
@@ -1307,11 +710,11 @@ const char *parse_subexpr (const char *p, int limit)
*------------------------------------------
*/
static
-const char *parse_expr (const char *p)
+const char *parse_expr(const char *p)
{
#ifdef DEBUG_FUNCIN
if (battle_config.etc_log)
- printf ("parse_expr %s\n", p);
+ PRINTF("parse_expr %s\n", p);
#endif
switch (*p)
{
@@ -1321,13 +724,13 @@ const char *parse_expr (const char *p)
case '[':
case ']':
case '}':
- disp_error_message ("unexpected char", p);
- exit (1);
+ disp_error_message("unexpected char", p);
+ exit(1);
}
- p = parse_subexpr (p, -1);
+ p = parse_subexpr(p, -1);
#ifdef DEBUG_FUNCIN
if (battle_config.etc_log)
- printf ("parse_expr end %s\n", p);
+ PRINTF("parse_expr end %s\n", p);
#endif
return p;
}
@@ -1337,12 +740,12 @@ const char *parse_expr (const char *p)
*------------------------------------------
*/
static
-const char *parse_line (const char *p)
+const char *parse_line(const char *p)
{
- int i = 0, cmd;
+ int i = 0, cmd;
const char *plist[128];
- p = skip_space (p);
+ p = skip_space(p);
if (*p == ';')
return p;
@@ -1350,53 +753,53 @@ const char *parse_line (const char *p)
// 最åˆã¯é–¢æ•°å
const char *p2 = p;
- p = parse_simpleexpr (p);
- p = skip_space (p);
+ p = parse_simpleexpr(p);
+ p = skip_space(p);
cmd = parse_cmd;
if (str_data[cmd].type != ScriptCode::FUNC)
{
- disp_error_message ("expect command", p2);
+ disp_error_message("expect command", p2);
// exit(0);
}
- add_scriptc (ScriptCode::ARG);
+ add_scriptc(ScriptCode::ARG);
while (p && *p && *p != ';' && i < 128)
{
plist[i] = p;
- p = parse_expr (p);
- p = skip_space (p);
+ p = parse_expr(p);
+ p = skip_space(p);
// 引数区切りã®,処ç†
if (*p == ',')
p++;
else if (*p != ';' && script_config.warn_cmd_no_comma
&& parse_cmd_if * 2 <= i)
{
- disp_error_message ("expect ',' or ';' at cmd params", p);
+ disp_error_message("expect ',' or ';' at cmd params", p);
}
- p = skip_space (p);
+ p = skip_space(p);
i++;
}
plist[i] = p;
if (!p || *(p++) != ';')
{
- disp_error_message ("need ';'", p);
- exit (1);
+ disp_error_message("need ';'", p);
+ exit(1);
}
- add_scriptc (ScriptCode::FUNC);
+ add_scriptc(ScriptCode::FUNC);
if (str_data[cmd].type == ScriptCode::FUNC
&& script_config.warn_cmd_mismatch_paramnum)
{
- const char *arg = buildin_func[str_data[cmd].val].arg;
- int j = 0;
+ const char *arg = builtin_functions[str_data[cmd].val].arg;
+ int j = 0;
for (j = 0; arg[j]; j++)
if (arg[j] == '*')
break;
if ((arg[j] == 0 && i != j) || (arg[j] == '*' && i < j))
{
- disp_error_message ("illegal number of parameters",
+ disp_error_message("illegal number of parameters",
plist[(i < j) ? i : j]);
}
}
@@ -1408,15 +811,16 @@ const char *parse_line (const char *p)
* 組ã¿è¾¼ã¿é–¢æ•°ã®è¿½åŠ 
*------------------------------------------
*/
-static void add_buildin_func (void)
+static
+void add_builtin_functions(void)
{
- int i, n;
- for (i = 0; buildin_func[i].func; i++)
+ int i, n;
+ for (i = 0; builtin_functions[i].func; i++)
{
- n = add_str (buildin_func[i].name);
+ n = add_str(builtin_functions[i].name);
str_data[n].type = ScriptCode::FUNC;
str_data[n].val = i;
- str_data[n].func = buildin_func[i].func;
+ str_data[n].func = builtin_functions[i].func;
}
}
@@ -1424,56 +828,59 @@ static void add_buildin_func (void)
* 定数データベースã®èª­ã¿è¾¼ã¿
*------------------------------------------
*/
-static void read_constdb (void)
+static
+void read_constdb(void)
{
- FILE *fp;
- char line[1024], name[1024];
- int val, n, i, type;
-
- fp = fopen_ ("db/const.txt", "r");
- if (fp == NULL)
+ std::ifstream in("db/const.txt");
+ if (!in.is_open())
{
- printf ("can't read db/const.txt\n");
+ PRINTF("can't read db/const.txt\n");
return;
}
- while (fgets (line, 1020, fp))
+
+ std::string line;
+ while (std::getline(in, line))
{
if (line[0] == '/' && line[1] == '/')
continue;
- type = 0;
- if (sscanf (line, "%[A-Za-z0-9_],%d,%d", name, &val, &type) >= 2 ||
- sscanf (line, "%[A-Za-z0-9_] %d %d", name, &val, &type) >= 2)
- {
- for (i = 0; name[i]; i++)
- name[i] = tolower (name[i]);
- n = add_str (name);
- if (type == 0)
- str_data[n].type = ScriptCode::INT;
- else
- str_data[n].type = ScriptCode::PARAM;
- str_data[n].val = val;
- }
+
+ char *name = nullptr;
+ int val;
+ int type = 0; // if not provided
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wformat"
+ if (sscanf(line.c_str(), "%m[A-Za-z0-9_] %i %i", &name, &val, &type) < 2)
+ {
+ free(name);
+ continue;
+ }
+#pragma GCC diagnostic pop
+ for (char *p = name; *p; ++p)
+ *p = tolower(*p);
+ int n = add_str(name);
+ free(name);
+ str_data[n].type = type ? ScriptCode::PARAM : ScriptCode::INT;
+ str_data[n].val = val;
}
- fclose_ (fp);
}
/*==========================================
* スクリプトã®è§£æž
*------------------------------------------
*/
-const ScriptCode *parse_script (const char *src, int line)
+const ScriptCode *parse_script(const char *src, int line)
{
const char *p;
- int i;
+ int i;
static int first = 1;
if (first)
{
- add_buildin_func ();
- read_constdb ();
+ add_builtin_functions();
+ read_constdb();
}
first = 0;
- script_buf = (ScriptCode *) calloc (SCRIPT_BLOCK_SIZE, 1);
+ script_buf = (ScriptCode *) calloc(SCRIPT_BLOCK_SIZE, 1);
script_pos = 0;
script_size = SCRIPT_BLOCK_SIZE;
str_data[LABEL_NEXTLINE].type = ScriptCode::NOP;
@@ -1490,71 +897,70 @@ const ScriptCode *parse_script (const char *src, int line)
}
// 外部用label dbã®åˆæœŸåŒ–
- if (scriptlabel_db != NULL)
- strdb_final (scriptlabel_db, NULL);
- scriptlabel_db = strdb_init (50);
+ scriptlabel_db.clear();
// for error message
startptr = src;
startline = line;
p = src;
- p = skip_space (p);
+ p = skip_space(p);
if (*p != '{')
{
- disp_error_message ("not found '{'", p);
+ disp_error_message("not found '{'", p);
return NULL;
}
for (p++; p && *p && *p != '}';)
{
- p = skip_space (p);
+ p = skip_space(p);
// labelã ã‘特殊処ç†
- if (*skip_space (skip_word (p)) == ':')
+ if (*skip_space(skip_word(p)) == ':')
{
char *tmpp = const_cast<char *>(skip_word(p));
char c = *tmpp;
*tmpp = '\0';
- int l = add_str (p);
+ int l = add_str(p);
if (str_data[l].label != -1)
{
*tmpp = c;
- disp_error_message ("dup label ", p);
- exit (1);
+ disp_error_message("dup label ", p);
+ exit(1);
}
- set_label (l, script_pos);
- strdb_insert (scriptlabel_db, (const char*)p, script_pos); // 外部用label db登録
+ set_label(l, script_pos);
+ std::string str(p, skip_word(p));
+ scriptlabel_db.insert(str, script_pos);
*tmpp = c;
p = tmpp + 1;
continue;
}
// ä»–ã¯å…¨éƒ¨ä¸€ç·’ããŸ
- p = parse_line (p);
- p = skip_space (p);
- add_scriptc (ScriptCode::EOL);
+ p = parse_line(p);
+ p = skip_space(p);
+ add_scriptc(ScriptCode::EOL);
- set_label (LABEL_NEXTLINE, script_pos);
+ set_label(LABEL_NEXTLINE, script_pos);
str_data[LABEL_NEXTLINE].type = ScriptCode::NOP;
str_data[LABEL_NEXTLINE].backpatch = -1;
str_data[LABEL_NEXTLINE].label = -1;
}
- add_scriptc (ScriptCode::NOP);
+ add_scriptc(ScriptCode::NOP);
script_size = script_pos;
- script_buf = (ScriptCode *) realloc (script_buf, script_pos + 1);
+ script_buf = (ScriptCode *) realloc(script_buf, script_pos + 1);
// 未解決ã®ãƒ©ãƒ™ãƒ«ã‚’解決
for (i = LABEL_START; i < str_num; i++)
{
if (str_data[i].type == ScriptCode::NOP)
{
- int j, next;
+ int j, next;
str_data[i].type = ScriptCode::NAME;
str_data[i].label = i;
for (j = str_data[i].backpatch; j >= 0 && j != 0x00ffffff;)
{
- next = (*(int *) (script_buf + j)) & 0x00ffffff;
+ next = (*(int *)(script_buf + j)) & 0x00ffffff;
script_buf[j] = static_cast<ScriptCode>(i);
script_buf[j + 1] = static_cast<ScriptCode>(i >> 8);
script_buf[j + 2] = static_cast<ScriptCode>(i >> 16);
@@ -1567,12 +973,12 @@ const ScriptCode *parse_script (const char *src, int line)
for (i = 0; i < script_pos; i++)
{
if ((i & 15) == 0)
- printf ("%04x : ", i);
- printf ("%02x ", script_buf[i]);
+ PRINTF("%04x : ", i);
+ PRINTF("%02x ", script_buf[i]);
if ((i & 15) == 15)
- printf ("\n");
+ PRINTF("\n");
}
- printf ("\n");
+ PRINTF("\n");
#endif
return script_buf;
@@ -1589,12 +995,12 @@ enum
*------------------------------------------
*/
static
-struct map_session_data *script_rid2sd (struct script_state *st)
+struct map_session_data *script_rid2sd(ScriptState *st)
{
- struct map_session_data *sd = map_id2sd (st->rid);
+ struct map_session_data *sd = map_id2sd(st->rid);
if (!sd)
{
- printf ("script_rid2sd: fatal error ! player not attached!\n");
+ PRINTF("script_rid2sd: fatal error ! player not attached!\n");
}
return sd;
}
@@ -1604,19 +1010,19 @@ struct map_session_data *script_rid2sd (struct script_state *st)
*------------------------------------------
*/
static
-int get_val (struct script_state *st, struct script_data *data)
+void get_val(ScriptState *st, struct script_data *data)
{
struct map_session_data *sd = NULL;
if (data->type == ScriptCode::NAME)
{
char *name = str_buf + str_data[data->u.num & 0x00ffffff].str;
char prefix = *name;
- char postfix = name[strlen (name) - 1];
+ char postfix = name[strlen(name) - 1];
if (prefix != '$')
{
- if ((sd = script_rid2sd (st)) == NULL)
- printf ("get_val error name?:%s\n", name);
+ if ((sd = script_rid2sd(st)) == NULL)
+ PRINTF("get_val error name?:%s\n", name);
}
if (postfix == '$')
{
@@ -1625,16 +1031,15 @@ int get_val (struct script_state *st, struct script_data *data)
if (prefix == '@' || prefix == 'l')
{
if (sd)
- data->u.str = pc_readregstr (sd, data->u.num);
+ data->u.str = pc_readregstr(sd, data->u.num);
}
else if (prefix == '$')
{
- data->u.str =
- (char *) numdb_search (mapregstr_db, data->u.num);
+ data->u.str = mapregstr_db.get(data->u.num);
}
else
{
- printf ("script: get_val: illegal scope string variable.\n");
+ PRINTF("script: get_val: illegal scope string variable.\n");
data->u.str = "!!ERROR!!";
}
if (data->u.str == NULL)
@@ -1647,45 +1052,45 @@ int get_val (struct script_state *st, struct script_data *data)
data->type = ScriptCode::INT;
if (str_data[data->u.num & 0x00ffffff].type == ScriptCode::INT)
{
+ // unreachable
data->u.num = str_data[data->u.num & 0x00ffffff].val;
}
else if (str_data[data->u.num & 0x00ffffff].type == ScriptCode::PARAM)
{
if (sd)
data->u.num =
- pc_readparam (sd,
- str_data[data->u.num & 0x00ffffff].val);
+ pc_readparam(sd,
+ SP(str_data[data->u.num & 0x00ffffff].val));
}
else if (prefix == '@' || prefix == 'l')
{
if (sd)
- data->u.num = pc_readreg (sd, data->u.num);
+ data->u.num = pc_readreg(sd, data->u.num);
}
else if (prefix == '$')
{
- data->u.num = (int) numdb_search (mapreg_db, data->u.num);
+ data->u.num = mapreg_db.get(data->u.num);
}
else if (prefix == '#')
{
if (name[1] == '#')
{
if (sd)
- data->u.num = pc_readaccountreg2 (sd, name);
+ data->u.num = pc_readaccountreg2(sd, name);
}
else
{
if (sd)
- data->u.num = pc_readaccountreg (sd, name);
+ data->u.num = pc_readaccountreg(sd, name);
}
}
else
{
if (sd)
- data->u.num = pc_readglobalreg (sd, name);
+ data->u.num = pc_readglobalreg(sd, name);
}
}
}
- return 0;
}
/*==========================================
@@ -1693,12 +1098,12 @@ int get_val (struct script_state *st, struct script_data *data)
*------------------------------------------
*/
static
-struct script_data get_val2 (struct script_state *st, int num)
+struct script_data get_val2(ScriptState *st, int num)
{
struct script_data dat;
dat.type = ScriptCode::NAME;
dat.u.num = num;
- get_val (st, &dat);
+ get_val(st, &dat);
return dat;
}
@@ -1707,25 +1112,25 @@ struct script_data get_val2 (struct script_state *st, int num)
*------------------------------------------
*/
static
-int set_reg (struct map_session_data *sd, int num, const char *name, struct script_data vd)
+void set_reg(struct map_session_data *sd, int num, const char *name, struct script_data vd)
{
char prefix = *name;
- char postfix = name[strlen (name) - 1];
+ char postfix = name[strlen(name) - 1];
if (postfix == '$')
{
const char *str = vd.u.str;
if (prefix == '@' || prefix == 'l')
{
- pc_setregstr (sd, num, str);
+ pc_setregstr(sd, num, str);
}
else if (prefix == '$')
{
- mapreg_setregstr (num, str);
+ mapreg_setregstr(num, str);
}
else
{
- printf ("script: set_reg: illegal scope string variable !");
+ PRINTF("script: set_reg: illegal scope string variable !");
}
}
else
@@ -1734,45 +1139,44 @@ int set_reg (struct map_session_data *sd, int num, const char *name, struct scri
int val = vd.u.num;
if (str_data[num & 0x00ffffff].type == ScriptCode::PARAM)
{
- pc_setparam (sd, str_data[num & 0x00ffffff].val, val);
+ pc_setparam(sd, SP(str_data[num & 0x00ffffff].val), val);
}
else if (prefix == '@' || prefix == 'l')
{
- pc_setreg (sd, num, val);
+ pc_setreg(sd, num, val);
}
else if (prefix == '$')
{
- mapreg_setreg (num, val);
+ mapreg_setreg(num, val);
}
else if (prefix == '#')
{
if (name[1] == '#')
- pc_setaccountreg2 (sd, name, val);
+ pc_setaccountreg2(sd, name, val);
else
- pc_setaccountreg (sd, name, val);
+ pc_setaccountreg(sd, name, val);
}
else
{
- pc_setglobalreg (sd, name, val);
+ pc_setglobalreg(sd, name, val);
}
}
- return 0;
}
static
-int set_reg (struct map_session_data *sd, int num, const char *name, int id)
+void set_reg(struct map_session_data *sd, int num, const char *name, int id)
{
struct script_data vd;
vd.u.num = id;
- return set_reg(sd, num, name, vd);
+ set_reg(sd, num, name, vd);
}
static
-int set_reg (struct map_session_data *sd, int num, const char *name, const char *zd)
+void set_reg(struct map_session_data *sd, int num, const char *name, const char *zd)
{
struct script_data vd;
vd.u.str = zd;
- return set_reg(sd, num, name, vd);
+ set_reg(sd, num, name, vd);
}
/*==========================================
@@ -1780,25 +1184,26 @@ int set_reg (struct map_session_data *sd, int num, const char *name, const char
*------------------------------------------
*/
static
-const char *conv_str (struct script_state *st, struct script_data *data)
+const char *conv_str(ScriptState *st, struct script_data *data)
{
- get_val (st, data);
+ get_val(st, data);
+ assert (data->type != ScriptCode::RETINFO);
if (data->type == ScriptCode::INT)
{
char *buf;
- buf = (char *) calloc (16, 1);
- sprintf (buf, "%d", data->u.num);
+ buf = (char *) calloc(16, 1);
+ sprintf(buf, "%d", data->u.num);
data->type = ScriptCode::STR;
data->u.str = buf;
-#if 1
}
+#if 1
else if (data->type == ScriptCode::NAME)
{
// テンãƒãƒ©ãƒªã€‚本æ¥ç„¡ã„ã¯ãš
data->type = ScriptCode::CONSTSTR;
data->u.str = str_buf + str_data[data->u.num].str;
-#endif
}
+#endif
return data->u.str;
}
@@ -1807,13 +1212,14 @@ const char *conv_str (struct script_state *st, struct script_data *data)
*------------------------------------------
*/
static
-int conv_num (struct script_state *st, struct script_data *data)
+int conv_num(ScriptState *st, struct script_data *data)
{
- get_val (st, data);
+ get_val(st, data);
+ assert (data->type != ScriptCode::RETINFO);
if (data->type == ScriptCode::STR || data->type == ScriptCode::CONSTSTR)
{
const char *p = data->u.str;
- data->u.num = atoi (p);
+ data->u.num = atoi(p);
if (data->type == ScriptCode::STR)
free(const_cast<char *>(p));
data->type = ScriptCode::INT;
@@ -1821,46 +1227,79 @@ int conv_num (struct script_state *st, struct script_data *data)
return data->u.num;
}
+static
+const ScriptCode *conv_script(ScriptState *st, struct script_data *data)
+{
+ get_val(st, data);
+ assert (data->type == ScriptCode::RETINFO);
+ return data->u.script;
+}
+
/*==========================================
* スタックã¸æ•°å€¤ã‚’プッシュ
*------------------------------------------
*/
-void push_val (struct script_stack *stack, ScriptCode type, int val)
+static
+void push_val(struct script_stack *stack, ScriptCode type, int val)
{
+ assert (type != ScriptCode::RETINFO);
+ assert (type != ScriptCode::STR);
+ assert (type != ScriptCode::CONSTSTR);
if (stack->sp >= stack->sp_max)
{
stack->sp_max += 64;
stack->stack_data = (struct script_data *)
- realloc (stack->stack_data, sizeof (stack->stack_data[0]) *
+ 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)));
+ memset(stack->stack_data + (stack->sp_max - 64), 0,
+ 64 * sizeof(*(stack->stack_data)));
}
// if(battle_config.etc_log)
-// printf("push (%d,%d)-> %d\n",type,val,stack->sp);
+// PRINTF("push (%d,%d)-> %d\n",type,val,stack->sp);
stack->stack_data[stack->sp].type = type;
stack->stack_data[stack->sp].u.num = val;
stack->sp++;
}
+static
+void push_script(struct script_stack *stack, ScriptCode type, const ScriptCode *code)
+{
+ assert (type == ScriptCode::RETINFO);
+ if (stack->sp >= stack->sp_max)
+ {
+ stack->sp_max += 64;
+ 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)));
+ }
+// if(battle_config.etc_log)
+// PRINTF("push (%d,%d)-> %d\n",type,val,stack->sp);
+ stack->stack_data[stack->sp].type = type;
+ stack->stack_data[stack->sp].u.script = code;
+ stack->sp++;
+}
+
/*==========================================
* スタックã¸æ–‡å­—列をプッシュ
*------------------------------------------
*/
static
-void push_str (struct script_stack *stack, ScriptCode type, const char *str)
+void push_str(struct script_stack *stack, ScriptCode type, const char *str)
{
+ assert (type == ScriptCode::STR || type == ScriptCode::CONSTSTR);
if (stack->sp >= stack->sp_max)
{
stack->sp_max += 64;
stack->stack_data = (struct script_data *)
- realloc (stack->stack_data, sizeof (stack->stack_data[0]) *
+ 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)));
+ memset(stack->stack_data + (stack->sp_max - 64), '\0',
+ 64 * sizeof(*(stack->stack_data)));
}
// if(battle_config.etc_log)
-// printf("push (%d,%x)-> %d\n",type,str,stack->sp);
+// PRINTF("push (%d,%x)-> %d\n",type,str,stack->sp);
stack->stack_data[stack->sp].type = type;
stack->stack_data[stack->sp].u.str = str;
stack->sp++;
@@ -1871,18 +1310,18 @@ void push_str (struct script_stack *stack, ScriptCode type, const char *str)
*------------------------------------------
*/
static
-void push_copy (struct script_stack *stack, int pos_)
+void push_copy(struct script_stack *stack, int pos_)
{
switch (stack->stack_data[pos_].type)
{
case ScriptCode::CONSTSTR:
- push_str (stack, ScriptCode::CONSTSTR, stack->stack_data[pos_].u.str);
+ push_str(stack, ScriptCode::CONSTSTR, stack->stack_data[pos_].u.str);
break;
case ScriptCode::STR:
- push_str (stack, ScriptCode::STR, strdup (stack->stack_data[pos_].u.str));
+ push_str(stack, ScriptCode::STR, strdup(stack->stack_data[pos_].u.str));
break;
default:
- push_val (stack, stack->stack_data[pos_].type,
+ push_val(stack, stack->stack_data[pos_].type,
stack->stack_data[pos_].u.num);
break;
}
@@ -1893,20 +1332,20 @@ void push_copy (struct script_stack *stack, int pos_)
*------------------------------------------
*/
static
-void pop_stack (struct script_stack *stack, int start, int end)
+void pop_stack(struct script_stack *stack, int start, int end)
{
- int i;
+ int i;
for (i = start; i < end; i++)
{
if (stack->stack_data[i].type == ScriptCode::STR)
{
- free (const_cast<char *>(stack->stack_data[i].u.str));
+ free(const_cast<char *>(stack->stack_data[i].u.str));
}
}
if (stack->sp > end)
{
- memmove (&stack->stack_data[start], &stack->stack_data[end],
- sizeof (stack->stack_data[0]) * (stack->sp - end));
+ memmove(&stack->stack_data[start], &stack->stack_data[end],
+ sizeof(stack->stack_data[0]) * (stack->sp - end));
}
stack->sp -= end - start;
}
@@ -1918,51 +1357,55 @@ void pop_stack (struct script_stack *stack, int start, int end)
*
*------------------------------------------
*/
-int buildin_mes (struct script_state *st)
+static
+void builtin_mes(ScriptState *st)
{
- conv_str (st, &(st->stack->stack_data[st->start + 2]));
- clif_scriptmes (script_rid2sd (st), st->oid,
+ conv_str(st, &(st->stack->stack_data[st->start + 2]));
+ clif_scriptmes(script_rid2sd(st), st->oid,
st->stack->stack_data[st->start + 2].u.str);
- return 0;
}
/*==========================================
*
*------------------------------------------
*/
-int buildin_goto (struct script_state *st)
+static
+void builtin_goto(ScriptState *st)
{
if (st->stack->stack_data[st->start + 2].type != ScriptCode::POS)
{
- printf ("script: goto: not label !\n");
+ PRINTF("script: goto: not label !\n");
st->state = END;
- return 0;
+ return;
}
- st->pos = conv_num (st, &(st->stack->stack_data[st->start + 2]));
+ st->pos = conv_num(st, &(st->stack->stack_data[st->start + 2]));
st->state = GOTO;
- return 0;
}
/*==========================================
* ユーザー定義関数ã®å‘¼ã³å‡ºã—
*------------------------------------------
*/
-int buildin_callfunc (struct script_state *st)
+static
+void builtin_callfunc(ScriptState *st)
{
const ScriptCode *scr;
- const char *str = conv_str (st, &(st->stack->stack_data[st->start + 2]));
+ const char *str = conv_str(st, &(st->stack->stack_data[st->start + 2]));
- if ((scr = (const ScriptCode *)strdb_search (script_get_userfunc_db (), str)))
+ if ((scr = userfunc_db.get(str)))
{
- int i, j;
- for (i = st->start + 3, j = 0; i < st->end; i++, j++)
- push_copy (st->stack, i);
+ int j = 0;
+ assert (st->start + 3 == st->end);
+#if 0
+ for (int i = st->start + 3; i < st->end; i++, j++)
+ push_copy(st->stack, i);
+#endif
- push_val (st->stack, ScriptCode::INT, j); // 引数ã®æ•°ã‚’プッシュ
- push_val (st->stack, ScriptCode::INT, st->defsp); // ç¾åœ¨ã®åŸºæº–スタックãƒã‚¤ãƒ³ã‚¿ã‚’プッシュ
- push_val (st->stack, ScriptCode::INT, (int) st->script); // ç¾åœ¨ã®ã‚¹ã‚¯ãƒªãƒ—トをプッシュ
- push_val (st->stack, ScriptCode::RETINFO, st->pos); // ç¾åœ¨ã®ã‚¹ã‚¯ãƒªãƒ—トä½ç½®ã‚’プッシュ
+ push_val(st->stack, ScriptCode::INT, j); // 引数ã®æ•°ã‚’プッシュ
+ push_val(st->stack, ScriptCode::INT, st->defsp); // ç¾åœ¨ã®åŸºæº–スタックãƒã‚¤ãƒ³ã‚¿ã‚’プッシュ
+ push_val(st->stack, ScriptCode::INT, st->pos); // ç¾åœ¨ã®ã‚¹ã‚¯ãƒªãƒ—トä½ç½®ã‚’プッシュ
+ push_script(st->stack, ScriptCode::RETINFO, st->script); // ç¾åœ¨ã®ã‚¹ã‚¯ãƒªãƒ—トをプッシュ
st->pos = 0;
st->script = scr;
@@ -1971,125 +1414,103 @@ int buildin_callfunc (struct script_state *st)
}
else
{
- printf ("script:callfunc: function not found! [%s]\n", str);
+ PRINTF("script:callfunc: function not found! [%s]\n", str);
st->state = END;
}
- return 0;
}
/*==========================================
* サブルーティンã®å‘¼ã³å‡ºã—
*------------------------------------------
*/
-int buildin_callsub (struct script_state *st)
-{
- int pos_ = conv_num (st, &(st->stack->stack_data[st->start + 2]));
- int i, j;
- for (i = st->start + 3, j = 0; i < st->end; i++, j++)
- push_copy (st->stack, i);
+static
+void builtin_callsub(ScriptState *st)
+{
+ int pos_ = conv_num(st, &(st->stack->stack_data[st->start + 2]));
+ int j = 0;
+ assert (st->start + 3 == st->end);
+#if 0
+ for (int i = st->start + 3; i < st->end; i++, j++)
+ push_copy(st->stack, i);
+#endif
- push_val (st->stack, ScriptCode::INT, j); // 引数ã®æ•°ã‚’プッシュ
- push_val (st->stack, ScriptCode::INT, st->defsp); // ç¾åœ¨ã®åŸºæº–スタックãƒã‚¤ãƒ³ã‚¿ã‚’プッシュ
- push_val (st->stack, ScriptCode::INT, (int) st->script); // ç¾åœ¨ã®ã‚¹ã‚¯ãƒªãƒ—トをプッシュ
- push_val (st->stack, ScriptCode::RETINFO, st->pos); // ç¾åœ¨ã®ã‚¹ã‚¯ãƒªãƒ—トä½ç½®ã‚’プッシュ
+ push_val(st->stack, ScriptCode::INT, j); // 引数ã®æ•°ã‚’プッシュ
+ push_val(st->stack, ScriptCode::INT, st->defsp); // ç¾åœ¨ã®åŸºæº–スタックãƒã‚¤ãƒ³ã‚¿ã‚’プッシュ
+ push_val(st->stack, ScriptCode::INT, st->pos); // ç¾åœ¨ã®ã‚¹ã‚¯ãƒªãƒ—トä½ç½®ã‚’プッシュ
+ push_script(st->stack, ScriptCode::RETINFO, st->script); // ç¾åœ¨ã®ã‚¹ã‚¯ãƒªãƒ—トをプッシュ
st->pos = pos_;
st->defsp = st->start + 4 + j;
st->state = GOTO;
- return 0;
-}
-
-/*==========================================
- * 引数ã®æ‰€å¾—
- *------------------------------------------
- */
-int buildin_getarg (struct script_state *st)
-{
- int num = conv_num (st, &(st->stack->stack_data[st->start + 2]));
- int max, stsp;
- if (st->defsp < 4
- || st->stack->stack_data[st->defsp - 1].type != ScriptCode::RETINFO)
- {
- printf ("script:getarg without callfunc or callsub!\n");
- st->state = END;
- return 0;
- }
- max = conv_num (st, &(st->stack->stack_data[st->defsp - 4]));
- stsp = st->defsp - max - 4;
- if (num >= max)
- {
- printf ("script:getarg arg1(%d) out of range(%d) !\n", num, max);
- st->state = END;
- return 0;
- }
- push_copy (st->stack, stsp + num);
- return 0;
}
/*==========================================
* サブルーãƒãƒ³/ユーザー定義関数ã®çµ‚了
*------------------------------------------
*/
-int buildin_return (struct script_state *st)
+static
+void builtin_return(ScriptState *st)
{
+#if 0
if (st->end > st->start + 2)
{ // 戻り値有り
- push_copy (st->stack, st->start + 2);
+ push_copy(st->stack, st->start + 2);
}
+#endif
st->state = RETFUNC;
- return 0;
}
/*==========================================
*
*------------------------------------------
*/
-int buildin_next (struct script_state *st)
+static
+void builtin_next(ScriptState *st)
{
st->state = STOP;
- clif_scriptnext (script_rid2sd (st), st->oid);
- return 0;
+ clif_scriptnext(script_rid2sd(st), st->oid);
}
/*==========================================
*
*------------------------------------------
*/
-int buildin_close (struct script_state *st)
+static
+void builtin_close(ScriptState *st)
{
st->state = END;
- clif_scriptclose (script_rid2sd (st), st->oid);
- return 0;
+ clif_scriptclose(script_rid2sd(st), st->oid);
}
-int buildin_close2 (struct script_state *st)
+static
+void builtin_close2(ScriptState *st)
{
st->state = STOP;
- clif_scriptclose (script_rid2sd (st), st->oid);
- return 0;
+ clif_scriptclose(script_rid2sd(st), st->oid);
}
/*==========================================
*
*------------------------------------------
*/
-int buildin_menu (struct script_state *st)
+static
+void builtin_menu(ScriptState *st)
{
char *buf;
- int i, len = 0; // [fate] len is the total # of bytes we need to transmit the string choices
- int menu_choices = 0;
- int finished_menu_items = 0; // [fate] set to 1 after we hit the first empty string
+ int i, len = 0; // [fate] len is the total # of bytes we need to transmit the string choices
+ int menu_choices = 0;
+ int finished_menu_items = 0; // [fate] set to 1 after we hit the first empty string
struct map_session_data *sd;
- sd = script_rid2sd (st);
+ sd = script_rid2sd(st);
// We don't need to do this iteration if the player cancels, strictly speaking.
for (i = st->start + 2; i < st->end; i += 2)
{
- int choice_len;
- conv_str (st, &(st->stack->stack_data[i]));
- choice_len = strlen (st->stack->stack_data[i].u.str);
+ int choice_len;
+ conv_str(st, &(st->stack->stack_data[i]));
+ choice_len = strlen(st->stack->stack_data[i].u.str);
len += choice_len + 1; // count # of bytes we'll need for packet. Only used if menu_or_input = 0.
if (choice_len && !finished_menu_items)
@@ -2103,15 +1524,15 @@ int buildin_menu (struct script_state *st)
st->state = RERUNLINE;
sd->state.menu_or_input = 1;
- buf = (char *) calloc (len + 1, 1);
+ buf = (char *) calloc(len + 1, 1);
buf[0] = 0;
for (i = st->start + 2; menu_choices > 0; i += 2, --menu_choices)
{
- strcat (buf, st->stack->stack_data[i].u.str);
- strcat (buf, ":");
+ strcat(buf, st->stack->stack_data[i].u.str);
+ strcat(buf, ":");
}
- clif_scriptmenu (script_rid2sd (st), st->oid, buf);
- free (buf);
+ clif_scriptmenu(script_rid2sd(st), st->oid, buf);
+ free(buf);
}
else if (sd->npc_menu == 0xff)
{ // cansel
@@ -2121,8 +1542,8 @@ int buildin_menu (struct script_state *st)
else
{ // goto動作
// ragemu互æ›ã®ãŸã‚
- pc_setreg (sd, add_str ("l15"), sd->npc_menu);
- pc_setreg (sd, add_str ("@menu"), sd->npc_menu);
+ pc_setreg(sd, add_str("l15"), sd->npc_menu);
+ pc_setreg(sd, add_str("@menu"), sd->npc_menu);
sd->state.menu_or_input = 0;
if (sd->npc_menu > 0 && sd->npc_menu <= menu_choices)
{
@@ -2130,121 +1551,112 @@ int buildin_menu (struct script_state *st)
stack_data[st->start + sd->npc_menu * 2 + 1].type != ScriptCode::POS)
{
st->state = END;
- return 0;
+ return;
}
st->pos =
- conv_num (st,
+ conv_num(st,
&(st->
stack->stack_data[st->start + sd->npc_menu * 2 +
1]));
st->state = GOTO;
}
}
- return 0;
}
/*==========================================
*
*------------------------------------------
*/
-int buildin_rand (struct script_state *st)
+static
+void builtin_rand(ScriptState *st)
{
- int range, min, max;
-
if (st->end > st->start + 3)
{
- min = conv_num (st, &(st->stack->stack_data[st->start + 2]));
- max = conv_num (st, &(st->stack->stack_data[st->start + 3]));
- if (max < min)
- {
- int tmp;
- tmp = min;
- min = max;
- max = tmp;
- }
- range = max - min + 1;
- push_val (st->stack, ScriptCode::INT, (range <= 0 ? 0 : MRAND (range)) + min);
+ int min = conv_num(st, &(st->stack->stack_data[st->start + 2]));
+ int max = conv_num(st, &(st->stack->stack_data[st->start + 3]));
+ if (min > max)
+ std::swap(max, min);
+ push_val(st->stack, ScriptCode::INT, random_::in(min, max));
}
else
{
- range = conv_num (st, &(st->stack->stack_data[st->start + 2]));
- push_val (st->stack, ScriptCode::INT, range <= 0 ? 0 : MRAND (range));
+ int range = conv_num(st, &(st->stack->stack_data[st->start + 2]));
+ push_val(st->stack, ScriptCode::INT, range <= 0 ? 0 : random_::to(range));
}
- return 0;
}
/*==========================================
*
*------------------------------------------
*/
-int buildin_pow (struct script_state *st)
+static
+void builtin_pow(ScriptState *st)
{
- int a, b;
+ int a, b;
- a = conv_num (st, &(st->stack->stack_data[st->start + 2]));
- b = conv_num (st, &(st->stack->stack_data[st->start + 3]));
+ a = conv_num(st, &(st->stack->stack_data[st->start + 2]));
+ b = conv_num(st, &(st->stack->stack_data[st->start + 3]));
- push_val (st->stack, ScriptCode::INT, (int) pow (a * 0.001, b));
+ push_val(st->stack, ScriptCode::INT, (int) pow(a * 0.001, b));
- return 0;
}
/*==========================================
* Check whether the PC is at the specified location
*------------------------------------------
*/
-int buildin_isat (struct script_state *st)
+static
+void builtin_isat(ScriptState *st)
{
- int x, y;
- struct map_session_data *sd = script_rid2sd (st);
+ int x, y;
+ struct map_session_data *sd = script_rid2sd(st);
- const char *str = conv_str (st, &(st->stack->stack_data[st->start + 2]));
- x = conv_num (st, &(st->stack->stack_data[st->start + 3]));
- y = conv_num (st, &(st->stack->stack_data[st->start + 4]));
+ const char *str = conv_str(st, &(st->stack->stack_data[st->start + 2]));
+ x = conv_num(st, &(st->stack->stack_data[st->start + 3]));
+ y = conv_num(st, &(st->stack->stack_data[st->start + 4]));
if (!sd)
- return 1;
+ return;
- push_val (st->stack, ScriptCode::INT,
+ push_val(st->stack, ScriptCode::INT,
(x == sd->bl.x)
- && (y == sd->bl.y) && (!strcmp (str, map[sd->bl.m].name)));
+ && (y == sd->bl.y) && (!strcmp(str, map[sd->bl.m].name)));
- return 0;
}
/*==========================================
*
*------------------------------------------
*/
-int buildin_warp (struct script_state *st)
+static
+void builtin_warp(ScriptState *st)
{
- int x, y;
- struct map_session_data *sd = script_rid2sd (st);
+ int x, y;
+ struct map_session_data *sd = script_rid2sd(st);
- const char *str = conv_str (st, &(st->stack->stack_data[st->start + 2]));
- x = conv_num (st, &(st->stack->stack_data[st->start + 3]));
- y = conv_num (st, &(st->stack->stack_data[st->start + 4]));
- if (strcmp (str, "Random") == 0)
- pc_randomwarp (sd, 3);
- else if (strcmp (str, "SavePoint") == 0)
+ const char *str = conv_str(st, &(st->stack->stack_data[st->start + 2]));
+ x = conv_num(st, &(st->stack->stack_data[st->start + 3]));
+ y = conv_num(st, &(st->stack->stack_data[st->start + 4]));
+ if (strcmp(str, "Random") == 0)
+ pc_randomwarp(sd, BeingRemoveWhy::WARPED);
+ else if (strcmp(str, "SavePoint") == 0)
{
if (map[sd->bl.m].flag.noreturn) // è¶ç¦æ­¢
- return 0;
+ return;
- pc_setpos (sd, sd->status.save_point.map,
- sd->status.save_point.x, sd->status.save_point.y, 3);
+ pc_setpos(sd, sd->status.save_point.map,
+ sd->status.save_point.x, sd->status.save_point.y, BeingRemoveWhy::WARPED);
}
- else if (strcmp (str, "Save") == 0)
+ else if (strcmp(str, "Save") == 0)
{
if (map[sd->bl.m].flag.noreturn) // è¶ç¦æ­¢
- return 0;
+ return;
- pc_setpos (sd, sd->status.save_point.map,
- sd->status.save_point.x, sd->status.save_point.y, 3);
+ pc_setpos(sd, sd->status.save_point.map,
+ sd->status.save_point.x, sd->status.save_point.y, BeingRemoveWhy::WARPED);
}
else
- pc_setpos (sd, str, x, y, 0);
- return 0;
+ pc_setpos(sd, str, x, y, BeingRemoveWhy::GONE);
}
/*==========================================
@@ -2252,118 +1664,96 @@ int buildin_warp (struct script_state *st)
*------------------------------------------
*/
static
-int buildin_areawarp_sub (struct block_list *bl, va_list ap)
+void builtin_areawarp_sub(struct block_list *bl, const char *mapname, int x, int y)
{
- int x, y;
- const char *mapname = va_arg (ap, const char *);
- x = va_arg (ap, int);
- y = va_arg (ap, int);
- if (strcmp (mapname, "Random") == 0)
- pc_randomwarp ((struct map_session_data *) bl, 3);
+ if (strcmp(mapname, "Random") == 0)
+ pc_randomwarp((struct map_session_data *) bl, BeingRemoveWhy::WARPED);
else
- pc_setpos ((struct map_session_data *) bl, mapname, x, y, 0);
- return 0;
+ pc_setpos((struct map_session_data *) bl, mapname, x, y, BeingRemoveWhy::GONE);
}
-int buildin_areawarp (struct script_state *st)
+static
+void builtin_areawarp(ScriptState *st)
{
- int x, y, m;
- int x0, y0, x1, y1;
+ int x, y, m;
+ int x0, y0, x1, y1;
- const char *mapname = conv_str (st, &(st->stack->stack_data[st->start + 2]));
- x0 = conv_num (st, &(st->stack->stack_data[st->start + 3]));
- y0 = conv_num (st, &(st->stack->stack_data[st->start + 4]));
- x1 = conv_num (st, &(st->stack->stack_data[st->start + 5]));
- y1 = conv_num (st, &(st->stack->stack_data[st->start + 6]));
- const char *str = conv_str (st, &(st->stack->stack_data[st->start + 7]));
- x = conv_num (st, &(st->stack->stack_data[st->start + 8]));
- y = conv_num (st, &(st->stack->stack_data[st->start + 9]));
-
- if ((m = map_mapname2mapid (mapname)) < 0)
- return 0;
+ const char *mapname = conv_str(st, &(st->stack->stack_data[st->start + 2]));
+ x0 = conv_num(st, &(st->stack->stack_data[st->start + 3]));
+ y0 = conv_num(st, &(st->stack->stack_data[st->start + 4]));
+ x1 = conv_num(st, &(st->stack->stack_data[st->start + 5]));
+ y1 = conv_num(st, &(st->stack->stack_data[st->start + 6]));
+ const char *str = conv_str(st, &(st->stack->stack_data[st->start + 7]));
+ x = conv_num(st, &(st->stack->stack_data[st->start + 8]));
+ y = conv_num(st, &(st->stack->stack_data[st->start + 9]));
- map_foreachinarea (buildin_areawarp_sub,
- m, x0, y0, x1, y1, BL_PC, str, x, y);
- return 0;
-}
-
-/*==========================================
- *
- *------------------------------------------
- */
-int buildin_heal (struct script_state *st)
-{
- int hp, sp;
+ if ((m = map_mapname2mapid(mapname)) < 0)
+ return;
- hp = conv_num (st, &(st->stack->stack_data[st->start + 2]));
- sp = conv_num (st, &(st->stack->stack_data[st->start + 3]));
- pc_heal (script_rid2sd (st), hp, sp);
- return 0;
+ map_foreachinarea(std::bind(builtin_areawarp_sub, ph::_1, str, x, y),
+ m, x0, y0, x1, y1, BL::PC);
}
/*==========================================
*
*------------------------------------------
*/
-int buildin_itemheal (struct script_state *st)
+static
+void builtin_heal(ScriptState *st)
{
- int hp, sp;
+ int hp, sp;
- hp = conv_num (st, &(st->stack->stack_data[st->start + 2]));
- sp = conv_num (st, &(st->stack->stack_data[st->start + 3]));
- pc_itemheal (script_rid2sd (st), hp, sp);
- return 0;
+ hp = conv_num(st, &(st->stack->stack_data[st->start + 2]));
+ sp = conv_num(st, &(st->stack->stack_data[st->start + 3]));
+ pc_heal(script_rid2sd(st), hp, sp);
}
/*==========================================
*
*------------------------------------------
*/
-int buildin_percentheal (struct script_state *st)
+static
+void builtin_itemheal(ScriptState *st)
{
- int hp, sp;
+ int hp, sp;
- hp = conv_num (st, &(st->stack->stack_data[st->start + 2]));
- sp = conv_num (st, &(st->stack->stack_data[st->start + 3]));
- pc_percentheal (script_rid2sd (st), hp, sp);
- return 0;
+ hp = conv_num(st, &(st->stack->stack_data[st->start + 2]));
+ sp = conv_num(st, &(st->stack->stack_data[st->start + 3]));
+ pc_itemheal(script_rid2sd(st), hp, sp);
}
/*==========================================
*
*------------------------------------------
*/
-int buildin_jobchange (struct script_state *st)
+static
+void builtin_percentheal(ScriptState *st)
{
- int job, upper = -1;
+ int hp, sp;
- job = conv_num (st, &(st->stack->stack_data[st->start + 2]));
- if (st->end > st->start + 3)
- upper = conv_num (st, &(st->stack->stack_data[st->start + 3]));
-
- if ((job >= 0 && job < MAX_PC_CLASS))
- pc_jobchange (script_rid2sd (st), job, upper);
-
- return 0;
+ hp = conv_num(st, &(st->stack->stack_data[st->start + 2]));
+ sp = conv_num(st, &(st->stack->stack_data[st->start + 3]));
+ pc_percentheal(script_rid2sd(st), hp, sp);
}
/*==========================================
*
*------------------------------------------
*/
-int buildin_input (struct script_state *st)
+static
+void builtin_input(ScriptState *st)
{
struct map_session_data *sd = NULL;
- int num =
+ int num =
(st->end >
st->start + 2) ? st->stack->stack_data[st->start + 2].u.num : 0;
const char *name =
(st->end >
st->start + 2) ? str_buf + str_data[num & 0x00ffffff].str : "";
// char prefix=*name;
- char postfix = name[strlen (name) - 1];
+ char postfix = name[strlen(name) - 1];
- sd = script_rid2sd (st);
+ sd = script_rid2sd(st);
if (sd->state.menu_or_input)
{
sd->state.menu_or_input = 0;
@@ -2372,11 +1762,11 @@ int buildin_input (struct script_state *st)
// 文字列
if (st->end > st->start + 2)
{ // 引数1個
- set_reg (sd, num, name, sd->npc_str);
+ set_reg(sd, num, name, sd->npc_str);
}
else
{
- printf ("buildin_input: string discarded !!\n");
+ PRINTF("builtin_input: string discarded !!\n");
}
}
else
@@ -2386,19 +1776,19 @@ int buildin_input (struct script_state *st)
//** Fix by fritz :X keeps people from abusing old input bugs
if (sd->npc_amount < 0) //** If input amount is less then 0
{
- clif_tradecancelled (sd); // added "Deal has been cancelled" message by Valaris
- buildin_close (st); //** close
+ clif_tradecancelled(sd); // added "Deal has been cancelled" message by Valaris
+ builtin_close(st); //** close
}
// 数値
if (st->end > st->start + 2)
{ // 引数1個
- set_reg (sd, num, name, sd->npc_amount);
+ set_reg(sd, num, name, sd->npc_amount);
}
else
{
// ragemu互æ›ã®ãŸã‚
- pc_setreg (sd, add_str ("l14"), sd->npc_amount);
+ pc_setreg(sd, add_str("l14"), sd->npc_amount);
}
}
}
@@ -2406,97 +1796,97 @@ int buildin_input (struct script_state *st)
{
st->state = RERUNLINE;
if (postfix == '$')
- clif_scriptinputstr (sd, st->oid);
+ clif_scriptinputstr(sd, st->oid);
else
- clif_scriptinput (sd, st->oid);
+ clif_scriptinput(sd, st->oid);
sd->state.menu_or_input = 1;
}
- return 0;
}
/*==========================================
*
*------------------------------------------
*/
-int buildin_if (struct script_state *st)
+static
+void builtin_if (ScriptState *st)
{
- int sel, i;
+ int sel, i;
- sel = conv_num (st, &(st->stack->stack_data[st->start + 2]));
+ sel = conv_num(st, &(st->stack->stack_data[st->start + 2]));
if (!sel)
- return 0;
+ return;
// 関数åをコピー
- push_copy (st->stack, st->start + 3);
+ push_copy(st->stack, st->start + 3);
// é–“ã«å¼•æ•°ãƒžãƒ¼ã‚«ã‚’入れã¦
- push_val (st->stack, ScriptCode::ARG, 0);
+ push_val(st->stack, ScriptCode::ARG, 0);
// 残りã®å¼•æ•°ã‚’コピー
for (i = st->start + 4; i < st->end; i++)
{
- push_copy (st->stack, i);
+ push_copy(st->stack, i);
}
- run_func (st);
+ run_func(st);
- return 0;
}
/*==========================================
* 変数設定
*------------------------------------------
*/
-int buildin_set (struct script_state *st)
+static
+void builtin_set(ScriptState *st)
{
struct map_session_data *sd = NULL;
- int num = st->stack->stack_data[st->start + 2].u.num;
+ int num = st->stack->stack_data[st->start + 2].u.num;
char *name = str_buf + str_data[num & 0x00ffffff].str;
char prefix = *name;
- char postfix = name[strlen (name) - 1];
+ char postfix = name[strlen(name) - 1];
if (st->stack->stack_data[st->start + 2].type != ScriptCode::NAME)
{
- printf ("script: buildin_set: not name\n");
- return 0;
+ PRINTF("script: builtin_set: not name\n");
+ return;
}
if (prefix != '$')
- sd = script_rid2sd (st);
+ sd = script_rid2sd(st);
if (postfix == '$')
{
// 文字列
- const char *str = conv_str (st, &(st->stack->stack_data[st->start + 3]));
- set_reg (sd, num, name, str);
+ const char *str = conv_str(st, &(st->stack->stack_data[st->start + 3]));
+ set_reg(sd, num, name, str);
}
else
{
// 数値
- int val = conv_num (st, &(st->stack->stack_data[st->start + 3]));
- set_reg (sd, num, name, val);
+ int val = conv_num(st, &(st->stack->stack_data[st->start + 3]));
+ set_reg(sd, num, name, val);
}
- return 0;
}
/*==========================================
* é…列変数設定
*------------------------------------------
*/
-int buildin_setarray (struct script_state *st)
+static
+void builtin_setarray(ScriptState *st)
{
struct map_session_data *sd = NULL;
- int num = st->stack->stack_data[st->start + 2].u.num;
+ int num = st->stack->stack_data[st->start + 2].u.num;
char *name = str_buf + str_data[num & 0x00ffffff].str;
char prefix = *name;
- char postfix = name[strlen (name) - 1];
- int i, j;
+ char postfix = name[strlen(name) - 1];
+ int i, j;
if (prefix != '$' && prefix != '@')
{
- printf ("buildin_setarray: illegal scope !\n");
- return 0;
+ PRINTF("builtin_setarray: illegal scope !\n");
+ return;
}
if (prefix != '$')
- sd = script_rid2sd (st);
+ sd = script_rid2sd(st);
for (j = 0, i = st->start + 3; i < st->end && j < 128; i++, j++)
{
@@ -2505,31 +1895,30 @@ int buildin_setarray (struct script_state *st)
else
set_reg(sd, num + (j << 24), name, conv_num(st, &(st->stack->stack_data[i])));
}
- return 0;
}
/*==========================================
* é…列変数クリア
*------------------------------------------
*/
-int buildin_cleararray (struct script_state *st)
+static
+void builtin_cleararray(ScriptState *st)
{
struct map_session_data *sd = NULL;
- int num = st->stack->stack_data[st->start + 2].u.num;
+ int num = st->stack->stack_data[st->start + 2].u.num;
char *name = str_buf + str_data[num & 0x00ffffff].str;
char prefix = *name;
- char postfix = name[strlen (name) - 1];
- int sz = conv_num (st, &(st->stack->stack_data[st->start + 4]));
- int i;
- void *v;
+ char postfix = name[strlen(name) - 1];
+ int sz = conv_num(st, &(st->stack->stack_data[st->start + 4]));
+ int i;
if (prefix != '$' && prefix != '@')
{
- printf ("buildin_cleararray: illegal scope !\n");
- return 0;
+ PRINTF("builtin_cleararray: illegal scope !\n");
+ return;
}
if (prefix != '$')
- sd = script_rid2sd (st);
+ sd = script_rid2sd(st);
if (postfix == '$')
for (i = 0; i < sz; i++)
@@ -2538,241 +1927,110 @@ int buildin_cleararray (struct script_state *st)
for (i = 0; i < sz; i++)
set_reg(sd, num + (i << 24), name, conv_num(st, &(st->stack->stack_data[st->start + 3])));
- return 0;
-}
-
-/*==========================================
- * é…列変数コピー
- *------------------------------------------
- */
-int buildin_copyarray (struct script_state *st)
-{
- struct map_session_data *sd = NULL;
- int num = st->stack->stack_data[st->start + 2].u.num;
- char *name = str_buf + str_data[num & 0x00ffffff].str;
- char prefix = *name;
- char postfix = name[strlen (name) - 1];
- int num2 = st->stack->stack_data[st->start + 3].u.num;
- char *name2 = str_buf + str_data[num2 & 0x00ffffff].str;
- char prefix2 = *name2;
- char postfix2 = name2[strlen (name2) - 1];
- int sz = conv_num (st, &(st->stack->stack_data[st->start + 4]));
- int i;
-
- if (prefix != '$' && prefix != '@' && prefix2 != '$' && prefix2 != '@')
- {
- printf ("buildin_copyarray: illegal scope !\n");
- return 0;
- }
- if ((postfix == '$' || postfix2 == '$') && postfix != postfix2)
- {
- printf ("buildin_copyarray: type mismatch !\n");
- return 0;
- }
- if (prefix != '$' || prefix2 != '$')
- sd = script_rid2sd (st);
-
- for (i = 0; i < sz; i++)
- set_reg (sd, num + (i << 24), name, get_val2 (st, num2 + (i << 24)));
- return 0;
}
/*==========================================
* é…列変数ã®ã‚µã‚¤ã‚ºæ‰€å¾—
*------------------------------------------
*/
-static int getarraysize (struct script_state *st, int num, int postfix)
+static
+int getarraysize(ScriptState *st, int num, int postfix)
{
- int i = (num >> 24), c = i;
+ int i = (num >> 24), c = i;
for (; i < 128; i++)
{
- struct script_data vd = get_val2 (st, num + (i << 24));
+ struct script_data vd = get_val2(st, num + (i << 24));
if (postfix == '$' ? bool(*vd.u.str) : bool(vd.u.num))
c = i;
}
return c + 1;
}
-int buildin_getarraysize (struct script_state *st)
-{
- int num = st->stack->stack_data[st->start + 2].u.num;
- char *name = str_buf + str_data[num & 0x00ffffff].str;
- char prefix = *name;
- char postfix = name[strlen (name) - 1];
-
- if (prefix != '$' && prefix != '@')
- {
- printf ("buildin_copyarray: illegal scope !\n");
- return 0;
- }
-
- push_val (st->stack, ScriptCode::INT, getarraysize (st, num, postfix));
- return 0;
-}
-
-/*==========================================
- * é…列変数ã‹ã‚‰è¦ç´ å‰Šé™¤
- *------------------------------------------
- */
-int buildin_deletearray (struct script_state *st)
+static
+void builtin_getarraysize(ScriptState *st)
{
- struct map_session_data *sd = NULL;
- int num = st->stack->stack_data[st->start + 2].u.num;
+ int num = st->stack->stack_data[st->start + 2].u.num;
char *name = str_buf + str_data[num & 0x00ffffff].str;
char prefix = *name;
- char postfix = name[strlen (name) - 1];
- int count = 1;
- int i, sz = getarraysize (st, num, postfix) - (num >> 24) - count + 1;
-
- if ((st->end > st->start + 3))
- count = conv_num (st, &(st->stack->stack_data[st->start + 3]));
+ char postfix = name[strlen(name) - 1];
if (prefix != '$' && prefix != '@')
{
- printf ("buildin_deletearray: illegal scope !\n");
- return 0;
+ PRINTF("builtin_copyarray: illegal scope !\n");
+ return;
}
- if (prefix != '$')
- sd = script_rid2sd (st);
- for (i = 0; i < sz; i++)
- {
- set_reg (sd, num + (i << 24), name,
- get_val2 (st, num + ((i + count) << 24)));
- }
- for (; i < (128 - (num >> 24)); i++)
- {
- if (postfix != '$')
- set_reg (sd, num + (i << 24), name, 0);
- if (postfix == '$')
- set_reg (sd, num + (i << 24), name, "");
- }
- return 0;
+ push_val(st->stack, ScriptCode::INT, getarraysize(st, num, postfix));
}
/*==========================================
* 指定è¦ç´ ã‚’表ã™å€¤(キー)を所得ã™ã‚‹
*------------------------------------------
*/
-int buildin_getelementofarray (struct script_state *st)
+static
+void builtin_getelementofarray(ScriptState *st)
{
if (st->stack->stack_data[st->start + 2].type == ScriptCode::NAME)
{
- int i = conv_num (st, &(st->stack->stack_data[st->start + 3]));
+ int i = conv_num(st, &(st->stack->stack_data[st->start + 3]));
if (i > 127 || i < 0)
{
- printf
- ("script: getelementofarray (operator[]): param2 illegal number %d\n",
+ PRINTF("script: getelementofarray (operator[]): param2 illegal number %d\n",
i);
- push_val (st->stack, ScriptCode::INT, 0);
+ push_val(st->stack, ScriptCode::INT, 0);
}
else
{
- push_val (st->stack, ScriptCode::NAME,
+ push_val(st->stack, ScriptCode::NAME,
(i << 24) | st->stack->stack_data[st->start + 2].u.num);
}
}
else
{
- printf
- ("script: getelementofarray (operator[]): param1 not name !\n");
- push_val (st->stack, ScriptCode::INT, 0);
+ PRINTF("script: getelementofarray (operator[]): param1 not name !\n");
+ push_val(st->stack, ScriptCode::INT, 0);
}
- return 0;
}
/*==========================================
*
*------------------------------------------
*/
-int buildin_setlook (struct script_state *st)
-{
- int type, val;
-
- type = conv_num (st, &(st->stack->stack_data[st->start + 2]));
- val = conv_num (st, &(st->stack->stack_data[st->start + 3]));
-
- pc_changelook (script_rid2sd (st), type, val);
-
- return 0;
-}
-
-/*==========================================
- *
- *------------------------------------------
- */
-int buildin_cutin (struct script_state *st)
-{
- int type;
-
- conv_str (st, &(st->stack->stack_data[st->start + 2]));
- type = conv_num (st, &(st->stack->stack_data[st->start + 3]));
-
- clif_cutin (script_rid2sd (st),
- st->stack->stack_data[st->start + 2].u.str, type);
-
- return 0;
-}
-
-/*==========================================
- * カードã®ã‚¤ãƒ©ã‚¹ãƒˆã‚’表示ã™ã‚‹
- *------------------------------------------
- */
-int buildin_cutincard (struct script_state *st)
-{
- int itemid;
-
- itemid = conv_num (st, &(st->stack->stack_data[st->start + 2]));
-
- clif_cutin (script_rid2sd (st), itemdb_search (itemid)->cardillustname,
- 4);
-
- return 0;
-}
-
-/*==========================================
- *
- *------------------------------------------
- */
-int buildin_viewpoint (struct script_state *st)
+static
+void builtin_setlook(ScriptState *st)
{
- int type, x, y, id, color;
-
- type = conv_num (st, &(st->stack->stack_data[st->start + 2]));
- x = conv_num (st, &(st->stack->stack_data[st->start + 3]));
- y = conv_num (st, &(st->stack->stack_data[st->start + 4]));
- id = conv_num (st, &(st->stack->stack_data[st->start + 5]));
- color = conv_num (st, &(st->stack->stack_data[st->start + 6]));
+ LOOK type = LOOK(conv_num(st, &(st->stack->stack_data[st->start + 2])));
+ int val = conv_num(st, &(st->stack->stack_data[st->start + 3]));
- clif_viewpoint (script_rid2sd (st), st->oid, type, x, y, id, color);
+ pc_changelook(script_rid2sd(st), type, val);
- return 0;
}
/*==========================================
*
*------------------------------------------
*/
-int buildin_countitem (struct script_state *st)
+static
+void builtin_countitem(ScriptState *st)
{
- int nameid = 0, count = 0, i;
+ int nameid = 0, count = 0, i;
struct map_session_data *sd;
struct script_data *data;
- sd = script_rid2sd (st);
+ sd = script_rid2sd(st);
data = &(st->stack->stack_data[st->start + 2]);
- get_val (st, data);
+ get_val(st, data);
if (data->type == ScriptCode::STR || data->type == ScriptCode::CONSTSTR)
{
- const char *name = conv_str (st, data);
+ const char *name = conv_str(st, data);
struct item_data *item_data;
- if ((item_data = itemdb_searchname (name)) != NULL)
+ if ((item_data = itemdb_searchname(name)) != NULL)
nameid = item_data->nameid;
}
else
- nameid = conv_num (st, data);
+ nameid = conv_num(st, data);
if (nameid >= 500) //if no such ID then skip this iteration
for (i = 0; i < MAX_INVENTORY; i++)
@@ -2783,305 +2041,202 @@ int buildin_countitem (struct script_state *st)
else
{
if (battle_config.error_log)
- printf ("wrong item ID : countitem(%i)\n", nameid);
+ PRINTF("wrong item ID : countitem (%i)\n", nameid);
}
- push_val (st->stack, ScriptCode::INT, count);
+ push_val(st->stack, ScriptCode::INT, count);
- return 0;
}
/*==========================================
* é‡é‡ãƒã‚§ãƒƒã‚¯
*------------------------------------------
*/
-int buildin_checkweight (struct script_state *st)
+static
+void builtin_checkweight(ScriptState *st)
{
- int nameid = 0, amount;
+ int nameid = 0, amount;
struct map_session_data *sd;
struct script_data *data;
- sd = script_rid2sd (st);
+ sd = script_rid2sd(st);
data = &(st->stack->stack_data[st->start + 2]);
- get_val (st, data);
+ get_val(st, data);
if (data->type == ScriptCode::STR || data->type == ScriptCode::CONSTSTR)
{
- const char *name = conv_str (st, data);
- struct item_data *item_data = itemdb_searchname (name);
+ const char *name = conv_str(st, data);
+ struct item_data *item_data = itemdb_searchname(name);
if (item_data)
nameid = item_data->nameid;
}
else
- nameid = conv_num (st, data);
+ nameid = conv_num(st, data);
- amount = conv_num (st, &(st->stack->stack_data[st->start + 3]));
+ amount = conv_num(st, &(st->stack->stack_data[st->start + 3]));
if (amount <= 0 || nameid < 500)
- { //if get wrong item ID or amount<=0, don't count weight of non existing items
- push_val (st->stack, ScriptCode::INT, 0);
+ {
+ //if get wrong item ID or amount<=0, don't count weight of non existing items
+ push_val(st->stack, ScriptCode::INT, 0);
+ return;
}
- sd = script_rid2sd (st);
- if (itemdb_weight (nameid) * amount + sd->weight > sd->max_weight)
+ if (itemdb_weight(nameid) * amount + sd->weight > sd->max_weight)
{
- push_val (st->stack, ScriptCode::INT, 0);
+ push_val(st->stack, ScriptCode::INT, 0);
}
else
{
- push_val (st->stack, ScriptCode::INT, 1);
+ push_val(st->stack, ScriptCode::INT, 1);
}
- return 0;
}
/*==========================================
*
*------------------------------------------
*/
-int buildin_getitem (struct script_state *st)
+static
+void builtin_getitem(ScriptState *st)
{
- int nameid, amount, flag = 0;
+ int nameid, amount;
struct item item_tmp;
struct map_session_data *sd;
struct script_data *data;
- sd = script_rid2sd (st);
+ sd = script_rid2sd(st);
data = &(st->stack->stack_data[st->start + 2]);
- get_val (st, data);
+ get_val(st, data);
if (data->type == ScriptCode::STR || data->type == ScriptCode::CONSTSTR)
{
- const char *name = conv_str (st, data);
- struct item_data *item_data = itemdb_searchname (name);
+ const char *name = conv_str(st, data);
+ struct item_data *item_data = itemdb_searchname(name);
nameid = 727; //Default to iten
if (item_data != NULL)
nameid = item_data->nameid;
}
else
- nameid = conv_num (st, data);
+ nameid = conv_num(st, data);
if ((amount =
- conv_num (st, &(st->stack->stack_data[st->start + 3]))) <= 0)
+ conv_num(st, &(st->stack->stack_data[st->start + 3]))) <= 0)
{
- return 0; //return if amount <=0, skip the useles iteration
- }
- //Violet Box, Blue Box, etc - random item pick
- if (nameid < 0)
- { // ランダム
- nameid = itemdb_searchrandomid (-nameid);
- flag = 1;
+ return; //return if amount <=0, skip the useles iteration
}
if (nameid > 0)
{
- memset (&item_tmp, 0, sizeof (item_tmp));
+ memset(&item_tmp, 0, sizeof(item_tmp));
item_tmp.nameid = nameid;
- if (!flag)
- item_tmp.identify = 1;
- else
- item_tmp.identify = !itemdb_isequip3 (nameid);
+ item_tmp.identify = 1;
if (st->end > st->start + 5) //アイテムを指定ã—ãŸIDã«æ¸¡ã™
- sd = map_id2sd (conv_num
- (st, &(st->stack->stack_data[st->start + 5])));
+ sd = map_id2sd(conv_num(st, &(st->stack->stack_data[st->start + 5])));
if (sd == NULL) //アイテムを渡ã™ç›¸æ‰‹ãŒã„ãªã‹ã£ãŸã‚‰ãŠå¸°ã‚Š
- return 0;
- if ((flag = pc_additem (sd, &item_tmp, amount)))
- {
- clif_additem (sd, 0, 0, flag);
- map_addflooritem (&item_tmp, amount, sd->bl.m, sd->bl.x, sd->bl.y,
- NULL, NULL, NULL, 0);
- }
- }
-
- return 0;
-}
-
-/*==========================================
- *
- *------------------------------------------
- */
-int buildin_getitem2 (struct script_state *st)
-{
- int nameid, amount, flag = 0;
- int iden, ref, attr, c1, c2, c3, c4;
- struct item item_tmp;
- struct map_session_data *sd;
- struct script_data *data;
-
- sd = script_rid2sd (st);
-
- data = &(st->stack->stack_data[st->start + 2]);
- get_val (st, data);
- if (data->type == ScriptCode::STR || data->type == ScriptCode::CONSTSTR)
- {
- const char *name = conv_str (st, data);
- struct item_data *item_data = itemdb_searchname (name);
- nameid = 512; //Apple item ID
- if (item_data)
- nameid = item_data->nameid;
- }
- else
- nameid = conv_num (st, data);
-
- amount = conv_num (st, &(st->stack->stack_data[st->start + 3]));
- iden = conv_num (st, &(st->stack->stack_data[st->start + 4]));
- ref = conv_num (st, &(st->stack->stack_data[st->start + 5]));
- attr = conv_num (st, &(st->stack->stack_data[st->start + 6]));
- c1 = conv_num (st, &(st->stack->stack_data[st->start + 7]));
- c2 = conv_num (st, &(st->stack->stack_data[st->start + 8]));
- c3 = conv_num (st, &(st->stack->stack_data[st->start + 9]));
- c4 = conv_num (st, &(st->stack->stack_data[st->start + 10]));
- if (st->end > st->start + 11) //アイテムを指定ã—ãŸIDã«æ¸¡ã™
- sd = map_id2sd (conv_num
- (st, &(st->stack->stack_data[st->start + 11])));
- if (sd == NULL) //アイテムを渡ã™ç›¸æ‰‹ãŒã„ãªã‹ã£ãŸã‚‰ãŠå¸°ã‚Š
- return 0;
-
- if (nameid < 0)
- { // ランダム
- nameid = itemdb_searchrandomid (-nameid);
- flag = 1;
- }
-
- if (nameid > 0)
- {
- memset (&item_tmp, 0, sizeof (item_tmp));
- struct item_data *item_data = itemdb_search (nameid);
- if (item_data->type == 4 || item_data->type == 5)
- {
- if (ref > 10)
- ref = 10;
- }
- else if (item_data->type == 7)
- {
- iden = 1;
- ref = 0;
- }
- else
- {
- iden = 1;
- ref = attr = 0;
- }
-
- item_tmp.nameid = nameid;
- if (!flag)
- item_tmp.identify = iden;
- else if (item_data->type == 4 || item_data->type == 5)
- item_tmp.identify = 0;
- item_tmp.refine = ref;
- item_tmp.attribute = attr;
- item_tmp.card[0] = c1;
- item_tmp.card[1] = c2;
- item_tmp.card[2] = c3;
- item_tmp.card[3] = c4;
- if ((flag = pc_additem (sd, &item_tmp, amount)))
+ return;
+ PickupFail flag;
+ if ((flag = pc_additem(sd, &item_tmp, amount)) != PickupFail::OKAY)
{
- clif_additem (sd, 0, 0, flag);
- map_addflooritem (&item_tmp, amount, sd->bl.m, sd->bl.x, sd->bl.y,
- NULL, NULL, NULL, 0);
+ clif_additem(sd, 0, 0, flag);
+ map_addflooritem(&item_tmp, amount,
+ sd->bl.m, sd->bl.x, sd->bl.y,
+ NULL, NULL, NULL);
}
}
- return 0;
}
/*==========================================
*
*------------------------------------------
*/
-int buildin_makeitem (struct script_state *st)
+static
+void builtin_makeitem(ScriptState *st)
{
- int nameid, amount, flag = 0;
- int x, y, m;
+ int nameid, amount, flag = 0;
+ int x, y, m;
struct item item_tmp;
struct map_session_data *sd;
struct script_data *data;
- sd = script_rid2sd (st);
+ sd = script_rid2sd(st);
data = &(st->stack->stack_data[st->start + 2]);
- get_val (st, data);
+ get_val(st, data);
if (data->type == ScriptCode::STR || data->type == ScriptCode::CONSTSTR)
{
- const char *name = conv_str (st, data);
- struct item_data *item_data = itemdb_searchname (name);
+ const char *name = conv_str(st, data);
+ struct item_data *item_data = itemdb_searchname(name);
nameid = 512; //Apple Item ID
if (item_data)
nameid = item_data->nameid;
}
else
- nameid = conv_num (st, data);
+ nameid = conv_num(st, data);
- amount = conv_num (st, &(st->stack->stack_data[st->start + 3]));
- const char *mapname = conv_str (st, &(st->stack->stack_data[st->start + 4]));
- x = conv_num (st, &(st->stack->stack_data[st->start + 5]));
- y = conv_num (st, &(st->stack->stack_data[st->start + 6]));
+ amount = conv_num(st, &(st->stack->stack_data[st->start + 3]));
+ const char *mapname = conv_str(st, &(st->stack->stack_data[st->start + 4]));
+ x = conv_num(st, &(st->stack->stack_data[st->start + 5]));
+ y = conv_num(st, &(st->stack->stack_data[st->start + 6]));
- if (sd && strcmp (mapname, "this") == 0)
+ if (sd && strcmp(mapname, "this") == 0)
m = sd->bl.m;
else
- m = map_mapname2mapid (mapname);
-
- if (nameid < 0)
- { // ランダム
- nameid = itemdb_searchrandomid (-nameid);
- flag = 1;
- }
+ m = map_mapname2mapid(mapname);
if (nameid > 0)
{
- memset (&item_tmp, 0, sizeof (item_tmp));
+ memset(&item_tmp, 0, sizeof(item_tmp));
item_tmp.nameid = nameid;
if (!flag)
item_tmp.identify = 1;
else
- item_tmp.identify = !itemdb_isequip3 (nameid);
+ item_tmp.identify = !itemdb_isequip3(nameid);
-// clif_additem(sd,0,0,flag);
- map_addflooritem (&item_tmp, amount, m, x, y, NULL, NULL, NULL, 0);
+ map_addflooritem(&item_tmp, amount, m, x, y, NULL, NULL, NULL);
}
- return 0;
}
/*==========================================
*
*------------------------------------------
*/
-int buildin_delitem (struct script_state *st)
+static
+void builtin_delitem(ScriptState *st)
{
- int nameid = 0, amount, i;
+ int nameid = 0, amount, i;
struct map_session_data *sd;
struct script_data *data;
- sd = script_rid2sd (st);
+ sd = script_rid2sd(st);
data = &(st->stack->stack_data[st->start + 2]);
- get_val (st, data);
+ get_val(st, data);
if (data->type == ScriptCode::STR || data->type == ScriptCode::CONSTSTR)
{
- const char *name = conv_str (st, data);
- struct item_data *item_data = itemdb_searchname (name);
+ const char *name = conv_str(st, data);
+ struct item_data *item_data = itemdb_searchname(name);
//nameid=512;
if (item_data)
nameid = item_data->nameid;
}
else
- nameid = conv_num (st, data);
+ nameid = conv_num(st, data);
- amount = conv_num (st, &(st->stack->stack_data[st->start + 3]));
+ amount = conv_num(st, &(st->stack->stack_data[st->start + 3]));
if (nameid < 500 || amount <= 0)
- { //by Lupus. Don't run FOR if u got wrong item ID or amount<=0
- //printf("wrong item ID or amount<=0 : delitem %i,\n",nameid,amount);
- return 0;
+ {
+ //by Lupus. Don't run FOR if u got wrong item ID or amount<=0
+ //PRINTF("wrong item ID or amount<=0 : delitem %i,\n",nameid,amount);
+ return;
}
- sd = script_rid2sd (st);
for (i = 0; i < MAX_INVENTORY; i++)
{
if (sd->status.inventory[i].nameid <= 0
|| sd->inventory_data[i] == NULL
- || sd->inventory_data[i]->type != 7
+ || sd->inventory_data[i]->type != ItemType::_7
|| sd->status.inventory[i].amount <= 0)
continue;
}
@@ -3091,7 +2246,7 @@ int buildin_delitem (struct script_state *st)
{
if (sd->status.inventory[i].amount >= amount)
{
- pc_delitem (sd, i, amount, 0);
+ pc_delitem(sd, i, amount, 0);
break;
}
else
@@ -3099,71 +2254,67 @@ int buildin_delitem (struct script_state *st)
amount -= sd->status.inventory[i].amount;
if (amount == 0)
amount = sd->status.inventory[i].amount;
- pc_delitem (sd, i, amount, 0);
+ pc_delitem(sd, i, amount, 0);
break;
}
}
}
- return 0;
}
/*==========================================
*キャラ関係ã®ãƒ‘ラメータå–å¾—
*------------------------------------------
*/
-int buildin_readparam (struct script_state *st)
+static
+void builtin_readparam(ScriptState *st)
{
- int type;
struct map_session_data *sd;
- type = conv_num (st, &(st->stack->stack_data[st->start + 2]));
+ SP type = SP(conv_num(st, &(st->stack->stack_data[st->start + 2])));
if (st->end > st->start + 3)
- sd = map_nick2sd (conv_str
- (st, &(st->stack->stack_data[st->start + 3])));
+ sd = map_nick2sd(conv_str(st, &(st->stack->stack_data[st->start + 3])));
else
- sd = script_rid2sd (st);
+ sd = script_rid2sd(st);
if (sd == NULL)
{
- push_val (st->stack, ScriptCode::INT, -1);
- return 0;
+ push_val(st->stack, ScriptCode::INT, -1);
+ return;
}
- push_val (st->stack, ScriptCode::INT, pc_readparam (sd, type));
+ push_val(st->stack, ScriptCode::INT, pc_readparam(sd, type));
- return 0;
}
/*==========================================
*キャラ関係ã®IDå–å¾—
*------------------------------------------
*/
-int buildin_getcharid (struct script_state *st)
+static
+void builtin_getcharid(ScriptState *st)
{
- int num;
+ int num;
struct map_session_data *sd;
- num = conv_num (st, &(st->stack->stack_data[st->start + 2]));
+ num = conv_num(st, &(st->stack->stack_data[st->start + 2]));
if (st->end > st->start + 3)
- sd = map_nick2sd (conv_str
- (st, &(st->stack->stack_data[st->start + 3])));
+ sd = map_nick2sd(conv_str(st, &(st->stack->stack_data[st->start + 3])));
else
- sd = script_rid2sd (st);
+ sd = script_rid2sd(st);
if (sd == NULL)
{
- push_val (st->stack, ScriptCode::INT, -1);
- return 0;
+ push_val(st->stack, ScriptCode::INT, -1);
+ return;
}
if (num == 0)
- push_val (st->stack, ScriptCode::INT, sd->status.char_id);
+ push_val(st->stack, ScriptCode::INT, sd->status.char_id);
if (num == 1)
- push_val (st->stack, ScriptCode::INT, sd->status.party_id);
+ push_val(st->stack, ScriptCode::INT, sd->status.party_id);
if (num == 2)
- push_val (st->stack, ScriptCode::INT, sd->status.guild_id);
+ push_val(st->stack, ScriptCode::INT, 0/*guild_id*/);
if (num == 3)
- push_val (st->stack, ScriptCode::INT, sd->status.account_id);
- return 0;
+ push_val(st->stack, ScriptCode::INT, sd->status.account_id);
}
/*==========================================
@@ -3171,737 +2322,252 @@ int buildin_getcharid (struct script_state *st)
*------------------------------------------
*/
static
-char *buildin_getpartyname_sub (int party_id)
+char *builtin_getpartyname_sub(int party_id)
{
struct party *p;
p = NULL;
- p = party_search (party_id);
+ p = party_search(party_id);
if (p != NULL)
{
char *buf;
- buf = (char *) calloc (24, 1);
- strcpy (buf, p->name);
+ buf = (char *) calloc(24, 1);
+ strcpy(buf, p->name);
return buf;
}
return 0;
}
-int buildin_getpartyname (struct script_state *st)
-{
- char *name;
- int party_id;
-
- party_id = conv_num (st, &(st->stack->stack_data[st->start + 2]));
- name = buildin_getpartyname_sub (party_id);
- if (name != 0)
- push_str (st->stack, ScriptCode::STR, name);
- else
- push_str (st->stack, ScriptCode::CONSTSTR, "null");
-
- return 0;
-}
-
-/*==========================================
- *指定IDã®PT人数ã¨ãƒ¡ãƒ³ãƒãƒ¼IDå–å¾—
- *------------------------------------------
- */
-int buildin_getpartymember (struct script_state *st)
-{
- struct party *p;
- int i, j = 0;
-
- p = NULL;
- p = party_search (conv_num (st, &(st->stack->stack_data[st->start + 2])));
-
- if (p != NULL)
- {
- for (i = 0; i < MAX_PARTY; i++)
- {
- if (p->member[i].account_id)
- {
-// printf("name:%s %d\n",p->member[i].name,i);
- mapreg_setregstr (add_str ("$@partymembername$") + (i << 24),
- p->member[i].name);
- j++;
- }
- }
- }
- mapreg_setreg (add_str ("$@partymembercount"), j);
-
- return 0;
-}
-
-/*==========================================
- *指定IDã®ã‚®ãƒ«ãƒ‰åå–å¾—
- *------------------------------------------
- */
-static
-char *buildin_getguildname_sub (int guild_id)
-{
- struct guild *g = NULL;
- g = guild_search (guild_id);
-
- if (g != NULL)
- {
- char *buf;
- buf = (char *) calloc (24, 1);
- strcpy (buf, g->name);
- return buf;
- }
- return 0;
-}
-
-int buildin_getguildname (struct script_state *st)
-{
- char *name;
- int guild_id = conv_num (st, &(st->stack->stack_data[st->start + 2]));
- name = buildin_getguildname_sub (guild_id);
- if (name != 0)
- push_str (st->stack, ScriptCode::STR, name);
- else
- push_str (st->stack, ScriptCode::CONSTSTR, "null");
- return 0;
-}
-
-/*==========================================
- *指定IDã®GuildMasteråå–å¾—
- *------------------------------------------
- */
-static
-char *buildin_getguildmaster_sub (int guild_id)
-{
- struct guild *g = NULL;
- g = guild_search (guild_id);
-
- if (g != NULL)
- {
- char *buf;
- buf = (char *) calloc (24, 1);
- strncpy (buf, g->master, 23);
- return buf;
- }
-
- return 0;
-}
-
-int buildin_getguildmaster (struct script_state *st)
-{
- char *master;
- int guild_id = conv_num (st, &(st->stack->stack_data[st->start + 2]));
- master = buildin_getguildmaster_sub (guild_id);
- if (master != 0)
- push_str (st->stack, ScriptCode::STR, master);
- else
- push_str (st->stack, ScriptCode::CONSTSTR, "null");
- return 0;
-}
-
-int buildin_getguildmasterid (struct script_state *st)
-{
- char *master;
- struct map_session_data *sd = NULL;
- int guild_id = conv_num (st, &(st->stack->stack_data[st->start + 2]));
- master = buildin_getguildmaster_sub (guild_id);
- if (master != 0)
- {
- if ((sd = map_nick2sd (master)) == NULL)
- {
- push_val (st->stack, ScriptCode::INT, 0);
- return 0;
- }
- push_val (st->stack, ScriptCode::INT, sd->status.char_id);
- }
- else
- {
- push_val (st->stack, ScriptCode::INT, 0);
- }
- return 0;
-}
-
/*==========================================
* キャラクタã®åå‰
*------------------------------------------
*/
-int buildin_strcharinfo (struct script_state *st)
+static
+void builtin_strcharinfo(ScriptState *st)
{
struct map_session_data *sd;
- int num;
+ int num;
- sd = script_rid2sd (st);
- num = conv_num (st, &(st->stack->stack_data[st->start + 2]));
+ sd = script_rid2sd(st);
+ num = conv_num(st, &(st->stack->stack_data[st->start + 2]));
if (num == 0)
{
char *buf;
- buf = (char *) calloc (24, 1);
- strncpy (buf, sd->status.name, 23);
- push_str (st->stack, ScriptCode::STR, buf);
+ buf = (char *) calloc(24, 1);
+ strncpy(buf, sd->status.name, 23);
+ push_str(st->stack, ScriptCode::STR, buf);
}
if (num == 1)
{
char *buf;
- buf = buildin_getpartyname_sub (sd->status.party_id);
+ buf = builtin_getpartyname_sub(sd->status.party_id);
if (buf != 0)
- push_str (st->stack, ScriptCode::STR, buf);
+ push_str(st->stack, ScriptCode::STR, buf);
else
- push_str (st->stack, ScriptCode::CONSTSTR, "");
+ push_str(st->stack, ScriptCode::CONSTSTR, "");
}
if (num == 2)
{
- char *buf;
- buf = buildin_getguildname_sub (sd->status.guild_id);
- if (buf != 0)
- push_str (st->stack, ScriptCode::STR, buf);
- else
- push_str (st->stack, ScriptCode::CONSTSTR, "");
+ // was: guild name
+ push_str(st->stack, ScriptCode::CONSTSTR, "");
}
- return 0;
}
-unsigned int equip[10] =
- { 0x0100, 0x0010, 0x0020, 0x0002, 0x0004, 0x0040, 0x0008, 0x0080, 0x0200,
- 0x0001
+// indexed by the equip_* in db/const.txt
+// TODO change to use EQUIP
+static
+EPOS equip[10] =
+{
+ EPOS::HAT,
+ EPOS::MISC1,
+ EPOS::SHIELD,
+ EPOS::WEAPON,
+ EPOS::GLOVES,
+ EPOS::SHOES,
+ EPOS::CAPE,
+ EPOS::MISC2,
+ EPOS::TORSO,
+ EPOS::LEGS,
};
/*==========================================
* GetEquipID(Pos); Pos: 1-10
*------------------------------------------
*/
-int buildin_getequipid (struct script_state *st)
+static
+void builtin_getequipid(ScriptState *st)
{
- int i, num;
+ int i, num;
struct map_session_data *sd;
struct item_data *item;
- sd = script_rid2sd (st);
+ sd = script_rid2sd(st);
if (sd == NULL)
{
- printf ("getequipid: sd == NULL\n");
- return 0;
+ PRINTF("getequipid: sd == NULL\n");
+ return;
}
- num = conv_num (st, &(st->stack->stack_data[st->start + 2]));
- i = pc_checkequip (sd, equip[num - 1]);
+ num = conv_num(st, &(st->stack->stack_data[st->start + 2]));
+ i = pc_checkequip(sd, equip[num - 1]);
if (i >= 0)
{
item = sd->inventory_data[i];
if (item)
- push_val (st->stack, ScriptCode::INT, item->nameid);
+ push_val(st->stack, ScriptCode::INT, item->nameid);
else
- push_val (st->stack, ScriptCode::INT, 0);
+ push_val(st->stack, ScriptCode::INT, 0);
}
else
{
- push_val (st->stack, ScriptCode::INT, -1);
+ push_val(st->stack, ScriptCode::INT, -1);
}
- return 0;
}
/*==========================================
* 装備å文字列(精錬メニュー用)
*------------------------------------------
*/
-int buildin_getequipname (struct script_state *st)
+static
+void builtin_getequipname(ScriptState *st)
{
- int i, num;
+ int i, num;
struct map_session_data *sd;
struct item_data *item;
char *buf;
- 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]);
+ 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]);
if (i >= 0)
{
item = sd->inventory_data[i];
if (item)
- sprintf (buf, "%s-[%s]", pos[num - 1], item->jname);
+ sprintf(buf, "%s-[%s]", pos[num - 1], item->jname);
else
- sprintf (buf, "%s-[%s]", pos[num - 1], pos[10]);
- }
- else
- {
- sprintf (buf, "%s-[%s]", pos[num - 1], pos[10]);
- }
- push_str (st->stack, ScriptCode::STR, buf);
-
- return 0;
-}
-
-/*==========================================
- * getbrokenid [Valaris]
- *------------------------------------------
- */
-int buildin_getbrokenid (struct script_state *st)
-{
- int i, num, id = 0, brokencounter = 0;
- struct map_session_data *sd;
-
- sd = script_rid2sd (st);
-
- num = conv_num (st, &(st->stack->stack_data[st->start + 2]));
- for (i = 0; i < MAX_INVENTORY; i++)
- {
- if (sd->status.inventory[i].broken == 1)
- {
- brokencounter++;
- if (num == brokencounter)
- {
- id = sd->status.inventory[i].nameid;
- break;
- }
- }
+ sprintf(buf, "%s-[%s]", pos[num - 1], pos[10]);
}
-
- push_val (st->stack, ScriptCode::INT, id);
-
- return 0;
-}
-
-/*==========================================
- * repair [Valaris]
- *------------------------------------------
- */
-int buildin_repair (struct script_state *st)
-{
- int i, num;
- int repaircounter = 0;
- struct map_session_data *sd;
-
- sd = script_rid2sd (st);
-
- num = conv_num (st, &(st->stack->stack_data[st->start + 2]));
- for (i = 0; i < MAX_INVENTORY; i++)
- {
- if (sd->status.inventory[i].broken == 1)
- {
- repaircounter++;
- if (num == repaircounter)
- {
- sd->status.inventory[i].broken = 0;
- clif_equiplist (sd);
- clif_produceeffect (sd, 0, sd->status.inventory[i].nameid);
- clif_misceffect (&sd->bl, 3);
- clif_displaymessage (sd->fd, "Item has been repaired.");
- break;
- }
- }
- }
-
- return 0;
-}
-
-/*==========================================
- * 装備ãƒã‚§ãƒƒã‚¯
- *------------------------------------------
- */
-int buildin_getequipisequiped (struct script_state *st)
-{
- int i, num;
- struct map_session_data *sd;
-
- num = conv_num (st, &(st->stack->stack_data[st->start + 2]));
- sd = script_rid2sd (st);
- i = pc_checkequip (sd, equip[num - 1]);
- if (i >= 0)
- {
- push_val (st->stack, ScriptCode::INT, 1);
- }
- else
- {
- push_val (st->stack, ScriptCode::INT, 0);
- }
-
- return 0;
-}
-
-/*==========================================
- * 装備å“精錬å¯èƒ½ãƒã‚§ãƒƒã‚¯
- *------------------------------------------
- */
-int buildin_getequipisenableref (struct script_state *st)
-{
- int i, num;
- struct map_session_data *sd;
-
- num = conv_num (st, &(st->stack->stack_data[st->start + 2]));
- sd = script_rid2sd (st);
- i = pc_checkequip (sd, equip[num - 1]);
- if (i >= 0 && num < 7 && sd->inventory_data[i]
- && (num != 1 || sd->inventory_data[i]->def > 1
- || (sd->inventory_data[i]->def == 1
- && sd->inventory_data[i]->equip_script == NULL)
- || (sd->inventory_data[i]->def <= 0
- && sd->inventory_data[i]->equip_script != NULL)))
- {
- push_val (st->stack, ScriptCode::INT, 1);
- }
- else
- {
- push_val (st->stack, ScriptCode::INT, 0);
- }
-
- return 0;
-}
-
-/*==========================================
- * 装備å“鑑定ãƒã‚§ãƒƒã‚¯
- *------------------------------------------
- */
-int buildin_getequipisidentify (struct script_state *st)
-{
- int i, num;
- struct map_session_data *sd;
-
- num = conv_num (st, &(st->stack->stack_data[st->start + 2]));
- sd = script_rid2sd (st);
- i = pc_checkequip (sd, equip[num - 1]);
- if (i >= 0)
- push_val (st->stack, ScriptCode::INT, sd->status.inventory[i].identify);
- else
- push_val (st->stack, ScriptCode::INT, 0);
-
- return 0;
-}
-
-/*==========================================
- * 装備å“精錬度
- *------------------------------------------
- */
-int buildin_getequiprefinerycnt (struct script_state *st)
-{
- int i, num;
- struct map_session_data *sd;
-
- num = conv_num (st, &(st->stack->stack_data[st->start + 2]));
- sd = script_rid2sd (st);
- i = pc_checkequip (sd, equip[num - 1]);
- if (i >= 0)
- push_val (st->stack, ScriptCode::INT, sd->status.inventory[i].refine);
- else
- push_val (st->stack, ScriptCode::INT, 0);
-
- return 0;
-}
-
-/*==========================================
- * 装備å“武器LV
- *------------------------------------------
- */
-int buildin_getequipweaponlv (struct script_state *st)
-{
- int i, num;
- struct map_session_data *sd;
-
- num = conv_num (st, &(st->stack->stack_data[st->start + 2]));
- sd = script_rid2sd (st);
- i = pc_checkequip (sd, equip[num - 1]);
- if (i >= 0 && sd->inventory_data[i])
- push_val (st->stack, ScriptCode::INT, sd->inventory_data[i]->wlv);
else
- push_val (st->stack, ScriptCode::INT, 0);
-
- return 0;
-}
-
-/*==========================================
- * 装備å“精錬æˆåŠŸçŽ‡
- *------------------------------------------
- */
-int buildin_getequippercentrefinery (struct script_state *st)
-{
- int i, num;
- struct map_session_data *sd;
-
- num = conv_num (st, &(st->stack->stack_data[st->start + 2]));
- sd = script_rid2sd (st);
- i = pc_checkequip (sd, equip[num - 1]);
- if (i >= 0)
- push_val (st->stack, ScriptCode::INT,
- pc_percentrefinery (sd, &sd->status.inventory[i]));
- else
- push_val (st->stack, ScriptCode::INT, 0);
-
- return 0;
-}
-
-/*==========================================
- * 精錬æˆåŠŸ
- *------------------------------------------
- */
-int buildin_successrefitem (struct script_state *st)
-{
- int i, num, ep;
- struct map_session_data *sd;
-
- num = conv_num (st, &(st->stack->stack_data[st->start + 2]));
- sd = script_rid2sd (st);
- i = pc_checkequip (sd, equip[num - 1]);
- if (i >= 0)
- {
- ep = sd->status.inventory[i].equip;
-
- sd->status.inventory[i].refine++;
- pc_unequipitem (sd, i, 0);
- clif_refine (sd->fd, sd, 0, i, sd->status.inventory[i].refine);
- clif_delitem (sd, i, 1);
- clif_additem (sd, i, 1, 0);
- pc_equipitem (sd, i, ep);
- clif_misceffect (&sd->bl, 3);
- }
-
- return 0;
-}
-
-/*==========================================
- * 精錬失敗
- *------------------------------------------
- */
-int buildin_failedrefitem (struct script_state *st)
-{
- int i, num;
- struct map_session_data *sd;
-
- num = conv_num (st, &(st->stack->stack_data[st->start + 2]));
- sd = script_rid2sd (st);
- i = pc_checkequip (sd, equip[num - 1]);
- if (i >= 0)
{
- sd->status.inventory[i].refine = 0;
- pc_unequipitem (sd, i, 0);
- // 精錬失敗エフェクトã®ãƒ‘ケット
- clif_refine (sd->fd, sd, 1, i, sd->status.inventory[i].refine);
- pc_delitem (sd, i, 1, 0);
- // ä»–ã®äººã«ã‚‚失敗を通知
- clif_misceffect (&sd->bl, 2);
+ sprintf(buf, "%s-[%s]", pos[num - 1], pos[10]);
}
+ push_str(st->stack, ScriptCode::STR, buf);
- return 0;
}
/*==========================================
*
*------------------------------------------
*/
-int buildin_statusup (struct script_state *st)
-{
- int type;
- struct map_session_data *sd;
-
- type = conv_num (st, &(st->stack->stack_data[st->start + 2]));
- sd = script_rid2sd (st);
- pc_statusup (sd, type);
-
- return 0;
-}
-
-/*==========================================
- *
- *------------------------------------------
- */
-int buildin_statusup2 (struct script_state *st)
-{
- int type, val;
- struct map_session_data *sd;
-
- type = conv_num (st, &(st->stack->stack_data[st->start + 2]));
- val = conv_num (st, &(st->stack->stack_data[st->start + 3]));
- sd = script_rid2sd (st);
- pc_statusup2 (sd, type, val);
-
- return 0;
-}
-
-/*==========================================
- * 装備å“ã«ã‚ˆã‚‹èƒ½åŠ›å€¤ãƒœãƒ¼ãƒŠã‚¹
- *------------------------------------------
- */
-int buildin_bonus (struct script_state *st)
+static
+void builtin_statusup2(ScriptState *st)
{
- int type, val;
- struct map_session_data *sd;
-
- type = conv_num (st, &(st->stack->stack_data[st->start + 2]));
- val = conv_num (st, &(st->stack->stack_data[st->start + 3]));
- sd = script_rid2sd (st);
- pc_bonus (sd, type, val);
+ SP type = SP(conv_num(st, &(st->stack->stack_data[st->start + 2])));
+ int val = conv_num(st, &(st->stack->stack_data[st->start + 3]));
+ struct map_session_data *sd = script_rid2sd(st);
+ pc_statusup2(sd, type, val);
- return 0;
}
/*==========================================
* 装備å“ã«ã‚ˆã‚‹èƒ½åŠ›å€¤ãƒœãƒ¼ãƒŠã‚¹
*------------------------------------------
*/
-int buildin_bonus2 (struct script_state *st)
+static
+void builtin_bonus(ScriptState *st)
{
- int type, type2, val;
- struct map_session_data *sd;
-
- type = conv_num (st, &(st->stack->stack_data[st->start + 2]));
- type2 = conv_num (st, &(st->stack->stack_data[st->start + 3]));
- val = conv_num (st, &(st->stack->stack_data[st->start + 4]));
- sd = script_rid2sd (st);
- pc_bonus2 (sd, type, type2, val);
+ SP type = SP(conv_num(st, &(st->stack->stack_data[st->start + 2])));
+ int val = conv_num(st, &(st->stack->stack_data[st->start + 3]));
+ struct map_session_data *sd = script_rid2sd(st);
+ pc_bonus(sd, type, val);
- return 0;
}
/*==========================================
* 装備å“ã«ã‚ˆã‚‹èƒ½åŠ›å€¤ãƒœãƒ¼ãƒŠã‚¹
*------------------------------------------
*/
-int buildin_bonus3 (struct script_state *st)
+static
+void builtin_bonus2(ScriptState *st)
{
- int type, type2, type3, val;
- struct map_session_data *sd;
-
- type = conv_num (st, &(st->stack->stack_data[st->start + 2]));
- type2 = conv_num (st, &(st->stack->stack_data[st->start + 3]));
- type3 = conv_num (st, &(st->stack->stack_data[st->start + 4]));
- val = conv_num (st, &(st->stack->stack_data[st->start + 5]));
- sd = script_rid2sd (st);
- pc_bonus3 (sd, type, type2, type3, val);
+ SP type = SP(conv_num(st, &(st->stack->stack_data[st->start + 2])));
+ int type2 = conv_num(st, &(st->stack->stack_data[st->start + 3]));
+ int val = conv_num(st, &(st->stack->stack_data[st->start + 4]));
+ struct map_session_data *sd = script_rid2sd(st);
+ pc_bonus2(sd, type, type2, val);
- return 0;
}
/*==========================================
* スキル所得
*------------------------------------------
*/
-int buildin_skill (struct script_state *st)
+static
+void builtin_skill(ScriptState *st)
{
- int id, level, flag = 1;
+ int level, flag = 1;
struct map_session_data *sd;
- id = conv_num (st, &(st->stack->stack_data[st->start + 2]));
- level = conv_num (st, &(st->stack->stack_data[st->start + 3]));
+ SkillID id = SkillID(conv_num(st, &(st->stack->stack_data[st->start + 2])));
+ level = conv_num(st, &(st->stack->stack_data[st->start + 3]));
if (st->end > st->start + 4)
- flag = conv_num (st, &(st->stack->stack_data[st->start + 4]));
- sd = script_rid2sd (st);
- pc_skill (sd, id, level, flag);
- clif_skillinfoblock (sd);
+ flag = conv_num(st, &(st->stack->stack_data[st->start + 4]));
+ sd = script_rid2sd(st);
+ pc_skill(sd, id, level, flag);
+ clif_skillinfoblock(sd);
- return 0;
}
/*==========================================
* [Fate] Sets the skill level permanently
*------------------------------------------
*/
-int buildin_setskill (struct script_state *st)
+static
+void builtin_setskill(ScriptState *st)
{
- int id, level;
+ int level;
struct map_session_data *sd;
- id = conv_num (st, &(st->stack->stack_data[st->start + 2]));
- level = conv_num (st, &(st->stack->stack_data[st->start + 3]));
- sd = script_rid2sd (st);
+ SkillID id = static_cast<SkillID>(conv_num(st, &(st->stack->stack_data[st->start + 2])));
+ level = conv_num(st, &(st->stack->stack_data[st->start + 3]));
+ sd = script_rid2sd(st);
- sd->status.skill[id].id = level ? id : 0;
sd->status.skill[id].lv = level;
- clif_skillinfoblock (sd);
- return 0;
-}
-
-/*==========================================
- * ギルドスキルå–å¾—
- *------------------------------------------
- */
-int buildin_guildskill (struct script_state *st)
-{
- int id, level;
- struct map_session_data *sd;
- int i = 0;
-
- id = conv_num (st, &(st->stack->stack_data[st->start + 2]));
- level = conv_num (st, &(st->stack->stack_data[st->start + 3]));
-// if( st->end>st->start+4 )
-// flag=conv_num(st,&(st->stack->stack_data[st->start+4]) );
- sd = script_rid2sd (st);
- for (i = 0; i < level; i++)
- guild_skillup (sd, id);
-
- return 0;
+ clif_skillinfoblock(sd);
}
/*==========================================
* スキルレベル所得
*------------------------------------------
*/
-int buildin_getskilllv (struct script_state *st)
-{
- int id = conv_num (st, &(st->stack->stack_data[st->start + 2]));
- push_val (st->stack, ScriptCode::INT, pc_checkskill (script_rid2sd (st), id));
- return 0;
-}
-
-/*==========================================
- * getgdskilllv(Guild_ID, Skill_ID);
- * skill_id = 10000 : GD_APPROVAL
- * 10001 : GD_KAFRACONTACT
- * 10002 : GD_GUARDIANRESEARCH
- * 10003 : GD_CHARISMA
- * 10004 : GD_EXTENSION
- *------------------------------------------
- */
-int buildin_getgdskilllv (struct script_state *st)
-{
- int guild_id = conv_num (st, &(st->stack->stack_data[st->start + 2]));
- int skill_id = conv_num (st, &(st->stack->stack_data[st->start + 3]));
- struct guild *g = guild_search (guild_id);
- push_val (st->stack, ScriptCode::INT,
- (g == NULL) ? -1 : guild_checkskill (g, skill_id));
- return 0;
-/*
- struct map_session_data *sd=NULL;
- struct guild *g=NULL;
- int skill_id;
-
- skill_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
- sd=script_rid2sd(st);
- if(sd && sd->status.guild_id > 0) g=guild_search(sd->status.guild_id);
- if(sd && g) {
- push_val(st->stack,ScriptCode::INT, guild_checkskill(g,skill_id+9999) );
- } else {
- push_val(st->stack,ScriptCode::INT,-1);
- }
- return 0;
-*/
-}
-
-/*==========================================
- *
- *------------------------------------------
- */
-int buildin_basicskillcheck (struct script_state *st)
+static
+void builtin_getskilllv(ScriptState *st)
{
- push_val (st->stack, ScriptCode::INT, battle_config.basic_skill_check);
- return 0;
+ SkillID id = SkillID(conv_num(st, &(st->stack->stack_data[st->start + 2])));
+ push_val(st->stack, ScriptCode::INT, pc_checkskill(script_rid2sd(st), id));
}
/*==========================================
*
*------------------------------------------
*/
-int buildin_getgmlevel (struct script_state *st)
+static
+void builtin_getgmlevel(ScriptState *st)
{
- push_val (st->stack, ScriptCode::INT, pc_isGM (script_rid2sd (st)));
- return 0;
+ push_val(st->stack, ScriptCode::INT, pc_isGM(script_rid2sd(st)));
}
/*==========================================
*
*------------------------------------------
*/
-int buildin_end (struct script_state *st)
+static
+void builtin_end(ScriptState *st)
{
st->state = END;
- return 0;
}
/*==========================================
@@ -3909,15 +2575,15 @@ int buildin_end (struct script_state *st)
*------------------------------------------
*/
-int buildin_getopt2 (struct script_state *st)
+static
+void builtin_getopt2(ScriptState *st)
{
struct map_session_data *sd;
- sd = script_rid2sd (st);
+ sd = script_rid2sd(st);
- push_val (st->stack, ScriptCode::INT, sd->opt2);
+ push_val(st->stack, ScriptCode::INT, uint16_t(sd->opt2));
- return 0;
}
/*==========================================
@@ -3925,185 +2591,34 @@ int buildin_getopt2 (struct script_state *st)
*------------------------------------------
*/
-int buildin_setopt2 (struct script_state *st)
+static
+void builtin_setopt2(ScriptState *st)
{
- int new_opt2;
struct map_session_data *sd;
- new_opt2 = conv_num (st, &(st->stack->stack_data[st->start + 2]));
- sd = script_rid2sd (st);
+ Opt2 new_opt2 = Opt2(conv_num(st, &(st->stack->stack_data[st->start + 2])));
+ sd = script_rid2sd(st);
if (new_opt2 == sd->opt2)
- return 0;
+ return;
sd->opt2 = new_opt2;
- clif_changeoption (&sd->bl);
- pc_calcstatus (sd, 0);
-
- return 0;
-}
-
-/*==========================================
- *
- *------------------------------------------
- */
-int buildin_checkoption (struct script_state *st)
-{
- int type;
- struct map_session_data *sd;
-
- type = conv_num (st, &(st->stack->stack_data[st->start + 2]));
- sd = script_rid2sd (st);
-
- if (sd->status.option & type)
- {
- push_val (st->stack, ScriptCode::INT, 1);
- }
- else
- {
- push_val (st->stack, ScriptCode::INT, 0);
- }
-
- return 0;
-}
-
-/*==========================================
- *
- *------------------------------------------
- */
-int buildin_setoption (struct script_state *st)
-{
- int type;
- struct map_session_data *sd;
-
- type = conv_num (st, &(st->stack->stack_data[st->start + 2]));
- sd = script_rid2sd (st);
- pc_setoption (sd, type);
-
- return 0;
-}
-
-/*==========================================
- * Checkcart [Valaris]
- *------------------------------------------
- */
-
-int buildin_checkcart (struct script_state *st)
-{
- struct map_session_data *sd;
-
- sd = script_rid2sd (st);
+ clif_changeoption(&sd->bl);
+ pc_calcstatus(sd, 0);
- if (pc_iscarton (sd))
- {
- push_val (st->stack, ScriptCode::INT, 1);
- }
- else
- {
- push_val (st->stack, ScriptCode::INT, 0);
- }
- return 0;
}
/*==========================================
- * カートを付ã‘ã‚‹
+ * セーブãƒã‚¤ãƒ³ãƒˆã®ä¿å­˜
*------------------------------------------
*/
-int buildin_setcart (struct script_state *st)
-{
- struct map_session_data *sd;
-
- sd = script_rid2sd (st);
- pc_setcart (sd, 1);
-
- return 0;
-}
-
-/*==========================================
- * checkfalcon [Valaris]
- *------------------------------------------
- */
-
-int buildin_checkfalcon (struct script_state *st)
-{
- struct map_session_data *sd;
-
- sd = script_rid2sd (st);
-
- if (pc_isfalcon (sd))
- {
- push_val (st->stack, ScriptCode::INT, 1);
- }
- else
- {
- push_val (st->stack, ScriptCode::INT, 0);
- }
-
- return 0;
-}
-
-/*==========================================
- * 鷹を付ã‘ã‚‹
- *------------------------------------------
- */
-int buildin_setfalcon (struct script_state *st)
-{
- struct map_session_data *sd;
-
- sd = script_rid2sd (st);
- pc_setfalcon (sd);
-
- return 0;
-}
-
-/*==========================================
- * Checkcart [Valaris]
- *------------------------------------------
- */
-
-int buildin_checkriding (struct script_state *st)
-{
- struct map_session_data *sd;
-
- sd = script_rid2sd (st);
-
- if (pc_isriding (sd))
- {
- push_val (st->stack, ScriptCode::INT, 1);
- }
- else
- {
- push_val (st->stack, ScriptCode::INT, 0);
- }
-
- return 0;
-}
-
-/*==========================================
- * ペコペコ乗り
- *------------------------------------------
- */
-int buildin_setriding (struct script_state *st)
-{
- struct map_session_data *sd;
-
- sd = script_rid2sd (st);
- pc_setriding (sd);
-
- return 0;
-}
-
-/*==========================================
- * セーブãƒã‚¤ãƒ³ãƒˆã®ä¿å­˜
- *------------------------------------------
- */
-int buildin_savepoint (struct script_state *st)
+static
+void builtin_savepoint(ScriptState *st)
{
- int x, y;
+ int x, y;
- const char *str = conv_str (st, &(st->stack->stack_data[st->start + 2]));
- x = conv_num (st, &(st->stack->stack_data[st->start + 3]));
- y = conv_num (st, &(st->stack->stack_data[st->start + 4]));
- pc_setsavepoint (script_rid2sd (st), str, x, y);
- return 0;
+ const char *str = conv_str(st, &(st->stack->stack_data[st->start + 2]));
+ x = conv_num(st, &(st->stack->stack_data[st->start + 3]));
+ y = conv_num(st, &(st->stack->stack_data[st->start + 4]));
+ pc_setsavepoint(script_rid2sd(st), str, x, y);
}
/*==========================================
@@ -4116,36 +2631,32 @@ int buildin_savepoint (struct script_state *st)
* other value.
*------------------------------------------
*/
-int buildin_gettimetick (struct script_state *st) /* Asgard Version */
+static
+void builtin_gettimetick(ScriptState *st) /* Asgard Version */
{
- int type;
- type = conv_num (st, &(st->stack->stack_data[st->start + 2]));
+ int type;
+ type = conv_num(st, &(st->stack->stack_data[st->start + 2]));
switch (type)
{
- /* Number of seconds elapsed today (0-86399, 00:00:00-23:59:59). */
+ /* Number of seconds elapsed today(0-86399, 00:00:00-23:59:59). */
case 1:
{
- time_t timer;
- struct tm *t;
-
- time (&timer);
- t = gmtime (&timer);
- push_val (st->stack, ScriptCode::INT,
- ((t->tm_hour) * 3600 + (t->tm_min) * 60 + t->tm_sec));
+ struct tm t = TimeT::now();
+ push_val(st->stack, ScriptCode::INT,
+ t.tm_hour * 3600 + t.tm_min * 60 + t.tm_sec);
break;
}
/* Seconds since Unix epoch. */
case 2:
- push_val (st->stack, ScriptCode::INT, (int) time (NULL));
+ push_val(st->stack, ScriptCode::INT, static_cast<time_t>(TimeT::now()));
break;
- /* System tick (unsigned int, and yes, it will wrap). */
+ /* System tick(unsigned int, and yes, it will wrap). */
case 0:
default:
- push_val (st->stack, ScriptCode::INT, gettick ());
+ push_val(st->stack, ScriptCode::INT, gettick().time_since_epoch().count());
break;
}
- return 0;
}
/*==========================================
@@ -4155,185 +2666,144 @@ int buildin_gettimetick (struct script_state *st) /* Asgard Version */
* 7: Year
*------------------------------------------
*/
-int buildin_gettime (struct script_state *st) /* Asgard Version */
+static
+void builtin_gettime(ScriptState *st) /* Asgard Version */
{
- int type;
- time_t timer;
- struct tm *t;
-
- type = conv_num (st, &(st->stack->stack_data[st->start + 2]));
+ int type = conv_num(st, &(st->stack->stack_data[st->start + 2]));
- time (&timer);
- t = gmtime (&timer);
+ struct tm t = TimeT::now();
switch (type)
{
case 1: //Sec(0~59)
- push_val (st->stack, ScriptCode::INT, t->tm_sec);
+ push_val(st->stack, ScriptCode::INT, t.tm_sec);
break;
case 2: //Min(0~59)
- push_val (st->stack, ScriptCode::INT, t->tm_min);
+ push_val(st->stack, ScriptCode::INT, t.tm_min);
break;
case 3: //Hour(0~23)
- push_val (st->stack, ScriptCode::INT, t->tm_hour);
+ push_val(st->stack, ScriptCode::INT, t.tm_hour);
break;
case 4: //WeekDay(0~6)
- push_val (st->stack, ScriptCode::INT, t->tm_wday);
+ push_val(st->stack, ScriptCode::INT, t.tm_wday);
break;
case 5: //MonthDay(01~31)
- push_val (st->stack, ScriptCode::INT, t->tm_mday);
+ push_val(st->stack, ScriptCode::INT, t.tm_mday);
break;
case 6: //Month(01~12)
- push_val (st->stack, ScriptCode::INT, t->tm_mon + 1);
+ push_val(st->stack, ScriptCode::INT, t.tm_mon + 1);
break;
case 7: //Year(20xx)
- push_val (st->stack, ScriptCode::INT, t->tm_year + 1900);
+ push_val(st->stack, ScriptCode::INT, t.tm_year + 1900);
break;
default: //(format error)
- push_val (st->stack, ScriptCode::INT, -1);
+ push_val(st->stack, ScriptCode::INT, -1);
break;
}
- return 0;
}
/*==========================================
* GetTimeStr("TimeFMT", Length);
*------------------------------------------
*/
-int buildin_gettimestr (struct script_state *st)
+static
+void builtin_gettimestr(ScriptState *st)
{
- char *tmpstr;
- int maxlen;
- time_t now = time (NULL);
+ struct tm now = TimeT::now();
- const char *fmtstr = conv_str (st, &(st->stack->stack_data[st->start + 2]));
- maxlen = conv_num (st, &(st->stack->stack_data[st->start + 3]));
+ const char *fmtstr = conv_str(st, &(st->stack->stack_data[st->start + 2]));
+ int maxlen = conv_num(st, &(st->stack->stack_data[st->start + 3]));
- tmpstr = (char *) calloc (maxlen + 1, 1);
- strftime (tmpstr, maxlen, fmtstr, gmtime (&now));
- tmpstr[maxlen] = '\0';
+ char *tmpstr = (char *) calloc(maxlen + 1, 1);
+ strftime(tmpstr, maxlen, fmtstr, &now);
- push_str (st->stack, ScriptCode::STR, tmpstr);
- return 0;
+ push_str(st->stack, ScriptCode::STR, tmpstr);
}
/*==========================================
* カプラ倉庫を開ã
*------------------------------------------
*/
-int buildin_openstorage (struct script_state *st)
+static
+void builtin_openstorage(ScriptState *st)
{
// int sync = 0;
// if (st->end >= 3) sync = conv_num(st,& (st->stack->stack_data[st->start+2]));
- struct map_session_data *sd = script_rid2sd (st);
+ struct map_session_data *sd = script_rid2sd(st);
// if (sync) {
st->state = STOP;
sd->npc_flags.storage = 1;
// } else st->state = END;
- storage_storageopen (sd);
- return 0;
-}
-
-int buildin_guildopenstorage (struct script_state *st)
-{
- struct map_session_data *sd = script_rid2sd (st);
- int ret;
- st->state = STOP;
- ret = storage_guild_storageopen (sd);
- push_val (st->stack, ScriptCode::INT, ret);
- return 0;
-}
-
-/*==========================================
- * アイテムã«ã‚ˆã‚‹ã‚¹ã‚­ãƒ«ç™ºå‹•
- *------------------------------------------
- */
-int buildin_itemskill (struct script_state *st)
-{
- int id, lv;
- struct map_session_data *sd = script_rid2sd (st);
-
- id = conv_num (st, &(st->stack->stack_data[st->start + 2]));
- lv = conv_num (st, &(st->stack->stack_data[st->start + 3]));
- const char *str = conv_str (st, &(st->stack->stack_data[st->start + 4]));
-
- // 詠唱中ã«ã‚¹ã‚­ãƒ«ã‚¢ã‚¤ãƒ†ãƒ ã¯ä½¿ç”¨ã§ããªã„
- if (sd->skilltimer != -1)
- return 0;
-
- sd->skillitem = id;
- sd->skillitemlv = lv;
- clif_item_skill (sd, id, lv, str);
- return 0;
+ storage_storageopen(sd);
}
/*==========================================
* NPCã§çµŒé¨“値上ã’ã‚‹
*------------------------------------------
*/
-int buildin_getexp (struct script_state *st)
+static
+void builtin_getexp(ScriptState *st)
{
- struct map_session_data *sd = script_rid2sd (st);
- int base = 0, job = 0;
+ struct map_session_data *sd = script_rid2sd(st);
+ int base = 0, job = 0;
- base = conv_num (st, &(st->stack->stack_data[st->start + 2]));
- job = conv_num (st, &(st->stack->stack_data[st->start + 3]));
+ base = conv_num(st, &(st->stack->stack_data[st->start + 2]));
+ job = conv_num(st, &(st->stack->stack_data[st->start + 3]));
if (base < 0 || job < 0)
- return 0;
+ return;
if (sd)
- pc_gainexp_reason (sd, base, job, PC_GAINEXP_REASON_SCRIPT);
+ pc_gainexp_reason(sd, base, job, PC_GAINEXP_REASON::SCRIPT);
- return 0;
}
/*==========================================
* モンスター発生
*------------------------------------------
*/
-int buildin_monster (struct script_state *st)
+static
+void builtin_monster(ScriptState *st)
{
- int mob_class, amount, x, y;
+ int mob_class, amount, x, y;
const char *event = "";
- const char *mapname = conv_str (st, &(st->stack->stack_data[st->start + 2]));
- x = conv_num (st, &(st->stack->stack_data[st->start + 3]));
- y = conv_num (st, &(st->stack->stack_data[st->start + 4]));
- const char *str = conv_str (st, &(st->stack->stack_data[st->start + 5]));
- mob_class = conv_num (st, &(st->stack->stack_data[st->start + 6]));
- amount = conv_num (st, &(st->stack->stack_data[st->start + 7]));
+ const char *mapname = conv_str(st, &(st->stack->stack_data[st->start + 2]));
+ x = conv_num(st, &(st->stack->stack_data[st->start + 3]));
+ y = conv_num(st, &(st->stack->stack_data[st->start + 4]));
+ const char *str = conv_str(st, &(st->stack->stack_data[st->start + 5]));
+ mob_class = conv_num(st, &(st->stack->stack_data[st->start + 6]));
+ amount = conv_num(st, &(st->stack->stack_data[st->start + 7]));
if (st->end > st->start + 8)
- event = conv_str (st, &(st->stack->stack_data[st->start + 8]));
+ event = conv_str(st, &(st->stack->stack_data[st->start + 8]));
- mob_once_spawn (map_id2sd (st->rid), mapname, x, y, str, mob_class, amount,
+ mob_once_spawn(map_id2sd(st->rid), mapname, x, y, str, mob_class, amount,
event);
- return 0;
}
/*==========================================
* モンスター発生
*------------------------------------------
*/
-int buildin_areamonster (struct script_state *st)
+static
+void builtin_areamonster(ScriptState *st)
{
- int mob_class, amount, x0, y0, x1, y1;
+ int mob_class, amount, x0, y0, x1, y1;
const char *event = "";
- const char *mapname = conv_str (st, &(st->stack->stack_data[st->start + 2]));
- x0 = conv_num (st, &(st->stack->stack_data[st->start + 3]));
- y0 = conv_num (st, &(st->stack->stack_data[st->start + 4]));
- x1 = conv_num (st, &(st->stack->stack_data[st->start + 5]));
- y1 = conv_num (st, &(st->stack->stack_data[st->start + 6]));
- const char *str = conv_str (st, &(st->stack->stack_data[st->start + 7]));
- mob_class = conv_num (st, &(st->stack->stack_data[st->start + 8]));
- amount = conv_num (st, &(st->stack->stack_data[st->start + 9]));
+ const char *mapname = conv_str(st, &(st->stack->stack_data[st->start + 2]));
+ x0 = conv_num(st, &(st->stack->stack_data[st->start + 3]));
+ y0 = conv_num(st, &(st->stack->stack_data[st->start + 4]));
+ x1 = conv_num(st, &(st->stack->stack_data[st->start + 5]));
+ y1 = conv_num(st, &(st->stack->stack_data[st->start + 6]));
+ const char *str = conv_str(st, &(st->stack->stack_data[st->start + 7]));
+ mob_class = conv_num(st, &(st->stack->stack_data[st->start + 8]));
+ amount = conv_num(st, &(st->stack->stack_data[st->start + 9]));
if (st->end > st->start + 10)
- event = conv_str (st, &(st->stack->stack_data[st->start + 10]));
+ event = conv_str(st, &(st->stack->stack_data[st->start + 10]));
- mob_once_spawn_area (map_id2sd (st->rid), mapname, x0, y0, x1, y1, str, mob_class,
+ mob_once_spawn_area(map_id2sd(st->rid), mapname, x0, y0, x1, y1, str, mob_class,
amount, event);
- return 0;
}
/*==========================================
@@ -4341,191 +2811,147 @@ int buildin_areamonster (struct script_state *st)
*------------------------------------------
*/
static
-int buildin_killmonster_sub (struct block_list *bl, va_list ap)
+void builtin_killmonster_sub(struct block_list *bl, const char *event, int allflag)
{
- char *event = va_arg (ap, char *);
- int allflag = va_arg (ap, int);
-
if (!allflag)
{
- if (strcmp (event, ((struct mob_data *) bl)->npc_event) == 0)
- mob_delete ((struct mob_data *) bl);
- return 0;
+ if (strcmp(event, ((struct mob_data *) bl)->npc_event) == 0)
+ mob_delete((struct mob_data *) bl);
+ return;
}
else if (allflag)
{
- if (((struct mob_data *) bl)->spawndelay1 == -1
- && ((struct mob_data *) bl)->spawndelay2 == -1)
- mob_delete ((struct mob_data *) bl);
- return 0;
+ if (((struct mob_data *) bl)->spawndelay1 == static_cast<interval_t>(-1)
+ && ((struct mob_data *) bl)->spawndelay2 == static_cast<interval_t>(-1))
+ mob_delete((struct mob_data *) bl);
+ return;
}
- return 0;
}
-int buildin_killmonster (struct script_state *st)
+static
+void builtin_killmonster(ScriptState *st)
{
- int m, allflag = 0;
- const char *mapname = conv_str (st, &(st->stack->stack_data[st->start + 2]));
- const char *event = conv_str (st, &(st->stack->stack_data[st->start + 3]));
- if (strcmp (event, "All") == 0)
+ int m, allflag = 0;
+ const char *mapname = conv_str(st, &(st->stack->stack_data[st->start + 2]));
+ const char *event = conv_str(st, &(st->stack->stack_data[st->start + 3]));
+ if (strcmp(event, "All") == 0)
allflag = 1;
- if ((m = map_mapname2mapid (mapname)) < 0)
- return 0;
- map_foreachinarea (buildin_killmonster_sub,
- m, 0, 0, map[m].xs, map[m].ys, BL_MOB, event, allflag);
- return 0;
+ if ((m = map_mapname2mapid(mapname)) < 0)
+ return;
+ map_foreachinarea(std::bind(builtin_killmonster_sub, ph::_1, event, allflag),
+ m, 0, 0, map[m].xs, map[m].ys, BL::MOB);
}
static
-int buildin_killmonsterall_sub (struct block_list *bl, va_list ap)
+void builtin_killmonsterall_sub(struct block_list *bl)
{
- mob_delete ((struct mob_data *) bl);
- return 0;
+ mob_delete((struct mob_data *) bl);
}
-int buildin_killmonsterall (struct script_state *st)
+static
+void builtin_killmonsterall(ScriptState *st)
{
- int m;
- const char *mapname = conv_str (st, &(st->stack->stack_data[st->start + 2]));
-
- if ((m = map_mapname2mapid (mapname)) < 0)
- return 0;
- map_foreachinarea (buildin_killmonsterall_sub,
- m, 0, 0, map[m].xs, map[m].ys, BL_MOB);
- return 0;
-}
+ int m;
+ const char *mapname = conv_str(st, &(st->stack->stack_data[st->start + 2]));
-/*==========================================
- * イベント実行
- *------------------------------------------
- */
-int buildin_doevent (struct script_state *st)
-{
- const char *event = conv_str (st, &(st->stack->stack_data[st->start + 2]));
- npc_event (map_id2sd (st->rid), event, 0);
- return 0;
+ if ((m = map_mapname2mapid(mapname)) < 0)
+ return;
+ map_foreachinarea(builtin_killmonsterall_sub,
+ m, 0, 0, map[m].xs, map[m].ys, BL::MOB);
}
/*==========================================
* NPC主体イベント実行
*------------------------------------------
*/
-int buildin_donpcevent (struct script_state *st)
+static
+void builtin_donpcevent(ScriptState *st)
{
- const char *event = conv_str (st, &(st->stack->stack_data[st->start + 2]));
- npc_event_do (event);
- return 0;
+ const char *event = conv_str(st, &(st->stack->stack_data[st->start + 2]));
+ npc_event_do(event);
}
/*==========================================
* イベントタイマー追加
*------------------------------------------
*/
-int buildin_addtimer (struct script_state *st)
-{
- int tick;
- tick = conv_num (st, &(st->stack->stack_data[st->start + 2]));
- const char *event = conv_str (st, &(st->stack->stack_data[st->start + 3]));
- pc_addeventtimer (script_rid2sd (st), tick, event);
- return 0;
-}
-
-/*==========================================
- * イベントタイマー削除
- *------------------------------------------
- */
-int buildin_deltimer (struct script_state *st)
-{
- const char *event = conv_str (st, &(st->stack->stack_data[st->start + 2]));
- pc_deleventtimer (script_rid2sd (st), event);
- return 0;
-}
-
-/*==========================================
- * イベントタイマーã®ã‚«ã‚¦ãƒ³ãƒˆå€¤è¿½åŠ 
- *------------------------------------------
- */
-int buildin_addtimercount (struct script_state *st)
+static
+void builtin_addtimer(ScriptState *st)
{
- int tick;
- const char *event = conv_str (st, &(st->stack->stack_data[st->start + 2]));
- tick = conv_num (st, &(st->stack->stack_data[st->start + 3]));
- pc_addeventtimercount (script_rid2sd (st), event, tick);
- return 0;
+ interval_t tick = static_cast<interval_t>(conv_num(st, &(st->stack->stack_data[st->start + 2])));
+ const char *event = conv_str(st, &(st->stack->stack_data[st->start + 3]));
+ pc_addeventtimer(script_rid2sd(st), tick, event);
}
/*==========================================
* NPCタイマーåˆæœŸåŒ–
*------------------------------------------
*/
-int buildin_initnpctimer (struct script_state *st)
+static
+void builtin_initnpctimer(ScriptState *st)
{
struct npc_data *nd;
if (st->end > st->start + 2)
- nd = npc_name2id (conv_str
- (st, &(st->stack->stack_data[st->start + 2])));
+ nd = npc_name2id(conv_str(st, &(st->stack->stack_data[st->start + 2])));
else
- nd = (struct npc_data *) map_id2bl (st->oid);
+ nd = (struct npc_data *) map_id2bl(st->oid);
- npc_settimerevent_tick (nd, 0);
- npc_timerevent_start (nd);
- return 0;
+ npc_settimerevent_tick(nd, interval_t::zero());
+ npc_timerevent_start(nd);
}
/*==========================================
* NPCタイマー開始
*------------------------------------------
*/
-int buildin_startnpctimer (struct script_state *st)
+static
+void builtin_startnpctimer(ScriptState *st)
{
struct npc_data *nd;
if (st->end > st->start + 2)
- nd = npc_name2id (conv_str
- (st, &(st->stack->stack_data[st->start + 2])));
+ nd = npc_name2id(conv_str(st, &(st->stack->stack_data[st->start + 2])));
else
- nd = (struct npc_data *) map_id2bl (st->oid);
+ nd = (struct npc_data *) map_id2bl(st->oid);
- npc_timerevent_start (nd);
- return 0;
+ npc_timerevent_start(nd);
}
/*==========================================
* NPCタイマーåœæ­¢
*------------------------------------------
*/
-int buildin_stopnpctimer (struct script_state *st)
+static
+void builtin_stopnpctimer(ScriptState *st)
{
struct npc_data *nd;
if (st->end > st->start + 2)
- nd = npc_name2id (conv_str
- (st, &(st->stack->stack_data[st->start + 2])));
+ nd = npc_name2id(conv_str(st, &(st->stack->stack_data[st->start + 2])));
else
- nd = (struct npc_data *) map_id2bl (st->oid);
+ nd = (struct npc_data *) map_id2bl(st->oid);
- npc_timerevent_stop (nd);
- return 0;
+ npc_timerevent_stop(nd);
}
/*==========================================
* NPCタイマー情報所得
*------------------------------------------
*/
-int buildin_getnpctimer (struct script_state *st)
+static
+void builtin_getnpctimer(ScriptState *st)
{
struct npc_data *nd;
- int type = conv_num (st, &(st->stack->stack_data[st->start + 2]));
- int val = 0;
+ int type = conv_num(st, &(st->stack->stack_data[st->start + 2]));
+ int val = 0;
if (st->end > st->start + 3)
- nd = npc_name2id (conv_str
- (st, &(st->stack->stack_data[st->start + 3])));
+ nd = npc_name2id(conv_str(st, &(st->stack->stack_data[st->start + 3])));
else
- nd = (struct npc_data *) map_id2bl (st->oid);
+ nd = (struct npc_data *) map_id2bl(st->oid);
switch (type)
{
case 0:
- val = npc_gettimerevent_tick (nd);
+ val = (int) npc_gettimerevent_tick(nd).count();
break;
case 1:
val = (nd->u.scr.nexttimer >= 0);
@@ -4534,48 +2960,45 @@ int buildin_getnpctimer (struct script_state *st)
val = nd->u.scr.timeramount;
break;
}
- push_val (st->stack, ScriptCode::INT, val);
- return 0;
+ push_val(st->stack, ScriptCode::INT, val);
}
/*==========================================
* NPCタイマー値設定
*------------------------------------------
*/
-int buildin_setnpctimer (struct script_state *st)
+static
+void builtin_setnpctimer(ScriptState *st)
{
- int tick;
struct npc_data *nd;
- tick = conv_num (st, &(st->stack->stack_data[st->start + 2]));
+ interval_t tick = static_cast<interval_t>(conv_num(st, &(st->stack->stack_data[st->start + 2])));
if (st->end > st->start + 3)
- nd = npc_name2id (conv_str
- (st, &(st->stack->stack_data[st->start + 3])));
+ nd = npc_name2id(conv_str(st, &(st->stack->stack_data[st->start + 3])));
else
- nd = (struct npc_data *) map_id2bl (st->oid);
+ nd = (struct npc_data *) map_id2bl(st->oid);
- npc_settimerevent_tick (nd, tick);
- return 0;
+ npc_settimerevent_tick(nd, tick);
}
/*==========================================
* 天ã®å£°ã‚¢ãƒŠã‚¦ãƒ³ã‚¹
*------------------------------------------
*/
-int buildin_announce (struct script_state *st)
+static
+void builtin_announce(ScriptState *st)
{
- int flag;
- const char *str = conv_str (st, &(st->stack->stack_data[st->start + 2]));
- flag = conv_num (st, &(st->stack->stack_data[st->start + 3]));
+ int flag;
+ const char *str = conv_str(st, &(st->stack->stack_data[st->start + 2]));
+ flag = conv_num(st, &(st->stack->stack_data[st->start + 3]));
if (flag & 0x0f)
{
- struct block_list *bl = (flag & 0x08) ? map_id2bl (st->oid) :
- (struct block_list *) script_rid2sd (st);
- clif_GMmessage (bl, str, strlen (str) + 1, flag);
+ struct block_list *bl = (flag & 0x08) ? map_id2bl(st->oid) :
+ (struct block_list *) script_rid2sd(st);
+ clif_GMmessage(bl, str, flag);
}
else
- intif_GMmessage (str, strlen (str) + 1, flag);
- return 0;
+ intif_GMmessage(str, flag);
}
/*==========================================
@@ -4583,96 +3006,63 @@ int buildin_announce (struct script_state *st)
*------------------------------------------
*/
static
-int buildin_mapannounce_sub (struct block_list *bl, va_list ap)
+void builtin_mapannounce_sub(struct block_list *bl, const char *str, int flag)
{
- char *str;
- int len, flag;
- str = va_arg (ap, char *);
- len = va_arg (ap, int);
- flag = va_arg (ap, int);
- clif_GMmessage (bl, str, len, flag | 3);
- return 0;
+ clif_GMmessage(bl, str, flag | 3);
}
-int buildin_mapannounce (struct script_state *st)
-{
- int flag, m;
-
- const char *mapname = conv_str (st, &(st->stack->stack_data[st->start + 2]));
- const char *str = conv_str (st, &(st->stack->stack_data[st->start + 3]));
- flag = conv_num (st, &(st->stack->stack_data[st->start + 4]));
-
- if ((m = map_mapname2mapid (mapname)) < 0)
- return 0;
- map_foreachinarea (buildin_mapannounce_sub,
- m, 0, 0, map[m].xs, map[m].ys, BL_PC, str,
- strlen (str) + 1, flag & 0x10);
- return 0;
-}
-
-/*==========================================
- * 天ã®å£°ã‚¢ãƒŠã‚¦ãƒ³ã‚¹ï¼ˆç‰¹å®šã‚¨ãƒªã‚¢ï¼‰
- *------------------------------------------
- */
-int buildin_areaannounce (struct script_state *st)
+static
+void builtin_mapannounce(ScriptState *st)
{
- int flag, m;
- int x0, y0, x1, y1;
+ int flag, m;
- const char *mapname = conv_str (st, &(st->stack->stack_data[st->start + 2]));
- x0 = conv_num (st, &(st->stack->stack_data[st->start + 3]));
- y0 = conv_num (st, &(st->stack->stack_data[st->start + 4]));
- x1 = conv_num (st, &(st->stack->stack_data[st->start + 5]));
- y1 = conv_num (st, &(st->stack->stack_data[st->start + 6]));
- const char *str = conv_str (st, &(st->stack->stack_data[st->start + 7]));
- flag = conv_num (st, &(st->stack->stack_data[st->start + 8]));
-
- if ((m = map_mapname2mapid (mapname)) < 0)
- return 0;
+ const char *mapname = conv_str(st, &(st->stack->stack_data[st->start + 2]));
+ const char *str = conv_str(st, &(st->stack->stack_data[st->start + 3]));
+ flag = conv_num(st, &(st->stack->stack_data[st->start + 4]));
- map_foreachinarea (buildin_mapannounce_sub,
- m, x0, y0, x1, y1, BL_PC, str, strlen (str) + 1,
- flag & 0x10);
- return 0;
+ if ((m = map_mapname2mapid(mapname)) < 0)
+ return;
+ map_foreachinarea(std::bind(builtin_mapannounce_sub, ph::_1, str, flag & 0x10),
+ m, 0, 0, map[m].xs, map[m].ys, BL::PC);
}
/*==========================================
* ユーザー数所得
*------------------------------------------
*/
-int buildin_getusers (struct script_state *st)
+static
+void builtin_getusers(ScriptState *st)
{
- int flag = conv_num (st, &(st->stack->stack_data[st->start + 2]));
- struct block_list *bl = map_id2bl ((flag & 0x08) ? st->oid : st->rid);
- int val = 0;
+ int flag = conv_num(st, &(st->stack->stack_data[st->start + 2]));
+ struct block_list *bl = map_id2bl((flag & 0x08) ? st->oid : st->rid);
+ int val = 0;
switch (flag & 0x07)
{
case 0:
val = map[bl->m].users;
break;
case 1:
- val = map_getusers ();
+ val = map_getusers();
break;
}
- push_val (st->stack, ScriptCode::INT, val);
- return 0;
+ push_val(st->stack, ScriptCode::INT, val);
}
/*==========================================
* マップ指定ユーザー数所得
*------------------------------------------
*/
-int buildin_getmapusers (struct script_state *st)
+static
+void builtin_getmapusers(ScriptState *st)
{
- int m;
- const char *str = conv_str (st, &(st->stack->stack_data[st->start + 2]));
- if ((m = map_mapname2mapid (str)) < 0)
+ int m;
+ const char *str = conv_str(st, &(st->stack->stack_data[st->start + 2]));
+ if ((m = map_mapname2mapid(str)) < 0)
{
- push_val (st->stack, ScriptCode::INT, -1);
- return 0;
+ push_val(st->stack, ScriptCode::INT, -1);
+ return;
}
- push_val (st->stack, ScriptCode::INT, map[m].users);
- return 0;
+ push_val(st->stack, ScriptCode::INT, map[m].users);
}
/*==========================================
@@ -4680,45 +3070,41 @@ int buildin_getmapusers (struct script_state *st)
*------------------------------------------
*/
static
-int buildin_getareausers_sub (struct block_list *bl, va_list ap)
+void builtin_getareausers_sub(struct block_list *, int *users)
{
- int *users = va_arg (ap, int *);
(*users)++;
- return 0;
}
static
-int buildin_getareausers_living_sub (struct block_list *bl, va_list ap)
+void builtin_getareausers_living_sub(struct block_list *bl, int *users)
{
- int *users = va_arg (ap, int *);
if (!pc_isdead((struct map_session_data *)bl))
(*users)++;
- return 0;
}
-int buildin_getareausers (struct script_state *st)
+static
+void builtin_getareausers(ScriptState *st)
{
- int m, x0, y0, x1, y1, users = 0;
- const char *str = conv_str (st, &(st->stack->stack_data[st->start + 2]));
- x0 = conv_num (st, &(st->stack->stack_data[st->start + 3]));
- y0 = conv_num (st, &(st->stack->stack_data[st->start + 4]));
- x1 = conv_num (st, &(st->stack->stack_data[st->start + 5]));
- y1 = conv_num (st, &(st->stack->stack_data[st->start + 6]));
+ int m, x0, y0, x1, y1, users = 0;
+ const char *str = conv_str(st, &(st->stack->stack_data[st->start + 2]));
+ x0 = conv_num(st, &(st->stack->stack_data[st->start + 3]));
+ y0 = conv_num(st, &(st->stack->stack_data[st->start + 4]));
+ x1 = conv_num(st, &(st->stack->stack_data[st->start + 5]));
+ y1 = conv_num(st, &(st->stack->stack_data[st->start + 6]));
int living = 0;
if (st->end > st->start + 7)
{
- living = conv_num (st, &(st->stack->stack_data[st->start + 7]));
+ living = conv_num(st, &(st->stack->stack_data[st->start + 7]));
}
- if ((m = map_mapname2mapid (str)) < 0)
+ if ((m = map_mapname2mapid(str)) < 0)
{
- push_val (st->stack, ScriptCode::INT, -1);
- return 0;
+ push_val(st->stack, ScriptCode::INT, -1);
+ return;
}
- map_foreachinarea (living ? buildin_getareausers_living_sub: buildin_getareausers_sub,
- m, x0, y0, x1, y1, BL_PC, &users);
- push_val (st->stack, ScriptCode::INT, users);
- return 0;
+ map_foreachinarea(std::bind(living ? builtin_getareausers_living_sub: builtin_getareausers_sub, ph::_1, &users),
+ m, x0, y0, x1, y1, BL::PC);
+ push_val(st->stack, ScriptCode::INT, users);
}
/*==========================================
@@ -4726,23 +3112,18 @@ int buildin_getareausers (struct script_state *st)
*------------------------------------------
*/
static
-int buildin_getareadropitem_sub (struct block_list *bl, va_list ap)
+void builtin_getareadropitem_sub(struct block_list *bl, int item, int *amount)
{
- int item = va_arg (ap, int);
- int *amount = va_arg (ap, int *);
struct flooritem_data *drop = (struct flooritem_data *) bl;
if (drop->item_data.nameid == item)
(*amount) += drop->item_data.amount;
- return 0;
}
static
-int buildin_getareadropitem_sub_anddelete (struct block_list *bl, va_list ap)
+void builtin_getareadropitem_sub_anddelete(struct block_list *bl, int item, int *amount)
{
- int item = va_arg (ap, int);
- int *amount = va_arg (ap, int *);
struct flooritem_data *drop = (struct flooritem_data *) bl;
if (drop->item_data.nameid == item) {
@@ -4750,241 +3131,122 @@ int buildin_getareadropitem_sub_anddelete (struct block_list *bl, va_list ap)
clif_clearflooritem(drop, 0);
map_delobject(drop->bl.id, drop->bl.type);
}
- return 0;
}
-int buildin_getareadropitem (struct script_state *st)
+static
+void builtin_getareadropitem(ScriptState *st)
{
- int m, x0, y0, x1, y1, item, amount = 0, delitems = 0;
+ int m, x0, y0, x1, y1, item, amount = 0, delitems = 0;
struct script_data *data;
- const char *str = conv_str (st, &(st->stack->stack_data[st->start + 2]));
- x0 = conv_num (st, &(st->stack->stack_data[st->start + 3]));
- y0 = conv_num (st, &(st->stack->stack_data[st->start + 4]));
- x1 = conv_num (st, &(st->stack->stack_data[st->start + 5]));
- y1 = conv_num (st, &(st->stack->stack_data[st->start + 6]));
+ const char *str = conv_str(st, &(st->stack->stack_data[st->start + 2]));
+ x0 = conv_num(st, &(st->stack->stack_data[st->start + 3]));
+ y0 = conv_num(st, &(st->stack->stack_data[st->start + 4]));
+ x1 = conv_num(st, &(st->stack->stack_data[st->start + 5]));
+ y1 = conv_num(st, &(st->stack->stack_data[st->start + 6]));
data = &(st->stack->stack_data[st->start + 7]);
- get_val (st, data);
+ get_val(st, data);
if (data->type == ScriptCode::STR || data->type == ScriptCode::CONSTSTR)
{
- const char *name = conv_str (st, data);
- struct item_data *item_data = itemdb_searchname (name);
+ const char *name = conv_str(st, data);
+ struct item_data *item_data = itemdb_searchname(name);
item = 512;
if (item_data)
item = item_data->nameid;
}
else
- item = conv_num (st, data);
+ item = conv_num(st, data);
if (st->end > st->start + 8)
- delitems = conv_num (st, &(st->stack->stack_data[st->start + 8]));
+ delitems = conv_num(st, &(st->stack->stack_data[st->start + 8]));
- if ((m = map_mapname2mapid (str)) < 0)
+ if ((m = map_mapname2mapid(str)) < 0)
{
- push_val (st->stack, ScriptCode::INT, -1);
- return 0;
+ push_val(st->stack, ScriptCode::INT, -1);
+ return;
}
if (delitems)
- map_foreachinarea (buildin_getareadropitem_sub_anddelete,
- m, x0, y0, x1, y1, BL_ITEM, item, &amount);
+ map_foreachinarea(std::bind(builtin_getareadropitem_sub_anddelete, ph::_1, item, &amount),
+ m, x0, y0, x1, y1, BL::ITEM);
else
- map_foreachinarea (buildin_getareadropitem_sub,
- m, x0, y0, x1, y1, BL_ITEM, item, &amount);
+ map_foreachinarea(std::bind(builtin_getareadropitem_sub, ph::_1, item, &amount),
+ m, x0, y0, x1, y1, BL::ITEM);
- push_val (st->stack, ScriptCode::INT, amount);
- return 0;
+ push_val(st->stack, ScriptCode::INT, amount);
}
/*==========================================
* NPCã®æœ‰åŠ¹åŒ–
*------------------------------------------
*/
-int buildin_enablenpc (struct script_state *st)
+static
+void builtin_enablenpc(ScriptState *st)
{
- const char *str = conv_str (st, &(st->stack->stack_data[st->start + 2]));
- npc_enable (str, 1);
- return 0;
+ const char *str = conv_str(st, &(st->stack->stack_data[st->start + 2]));
+ npc_enable(str, 1);
}
/*==========================================
* NPCã®ç„¡åŠ¹åŒ–
*------------------------------------------
*/
-int buildin_disablenpc (struct script_state *st)
-{
- const char *str = conv_str (st, &(st->stack->stack_data[st->start + 2]));
- npc_enable (str, 0);
- return 0;
-}
-
-int buildin_enablearena (struct script_state *st) // Added by RoVeRT
-{
- struct npc_data *nd = (struct npc_data *) map_id2bl (st->oid);
- struct chat_data *cd;
-
- if (nd == NULL
- || (cd = (struct chat_data *) map_id2bl (nd->chat_id)) == NULL)
- return 0;
-
- npc_enable (nd->name, 1);
- nd->arenaflag = 1;
-
- if (cd->users >= cd->trigger && cd->npc_event[0])
- npc_timer_event (cd->npc_event);
-
- return 0;
-}
-
-int buildin_disablearena (struct script_state *st) // Added by RoVeRT
-{
- struct npc_data *nd = (struct npc_data *) map_id2bl (st->oid);
- nd->arenaflag = 0;
-
- return 0;
-}
-
-/*==========================================
- * éš ã‚Œã¦ã„ã‚‹NPCã®è¡¨ç¤º
- *------------------------------------------
- */
-int buildin_hideoffnpc (struct script_state *st)
-{
- const char *str = conv_str (st, &(st->stack->stack_data[st->start + 2]));
- npc_enable (str, 2);
- return 0;
-}
-
-/*==========================================
- * NPCã‚’ãƒã‚¤ãƒ‡ã‚£ãƒ³ã‚°
- *------------------------------------------
- */
-int buildin_hideonnpc (struct script_state *st)
+static
+void builtin_disablenpc(ScriptState *st)
{
- const char *str = conv_str (st, &(st->stack->stack_data[st->start + 2]));
- npc_enable (str, 4);
- return 0;
+ const char *str = conv_str(st, &(st->stack->stack_data[st->start + 2]));
+ npc_enable(str, 0);
}
/*==========================================
* 状態異常ã«ã‹ã‹ã‚‹
*------------------------------------------
*/
-int buildin_sc_start (struct script_state *st)
+static
+void builtin_sc_start(ScriptState *st)
{
struct block_list *bl;
- int type, tick, val1;
- type = conv_num (st, &(st->stack->stack_data[st->start + 2]));
- tick = conv_num (st, &(st->stack->stack_data[st->start + 3]));
- val1 = conv_num (st, &(st->stack->stack_data[st->start + 4]));
+ int val1;
+ StatusChange type = static_cast<StatusChange>(conv_num(st, &(st->stack->stack_data[st->start + 2])));
+ interval_t tick = static_cast<interval_t>(conv_num(st, &(st->stack->stack_data[st->start + 3])));
+ if (tick < std::chrono::seconds(1))
+ // work around old behaviour of:
+ // speed potion
+ // atk potion
+ // matk potion
+ //
+ // which used to use seconds
+ // all others used milliseconds
+ tick *= 1000;
+ val1 = conv_num(st, &(st->stack->stack_data[st->start + 4]));
if (st->end > st->start + 5) //指定ã—ãŸã‚­ãƒ£ãƒ©ã‚’状態異常ã«ã™ã‚‹
- bl = map_id2bl (conv_num
- (st, &(st->stack->stack_data[st->start + 5])));
+ bl = map_id2bl(conv_num(st, &(st->stack->stack_data[st->start + 5])));
else
- bl = map_id2bl (st->rid);
- if (bl->type == BL_PC
- && ((struct map_session_data *) bl)->state.potionpitcher_flag)
- bl = map_id2bl (((struct map_session_data *) bl)->skilltarget);
- skill_status_change_start (bl, type, val1, 0, 0, 0, tick, 0);
- return 0;
-}
-
-/*==========================================
- * 状態異常ã«ã‹ã‹ã‚‹(確率指定)
- *------------------------------------------
- */
-int buildin_sc_start2 (struct script_state *st)
-{
- struct block_list *bl;
- int type, tick, val1, per;
- type = conv_num (st, &(st->stack->stack_data[st->start + 2]));
- tick = conv_num (st, &(st->stack->stack_data[st->start + 3]));
- val1 = conv_num (st, &(st->stack->stack_data[st->start + 4]));
- per = conv_num (st, &(st->stack->stack_data[st->start + 5]));
- if (st->end > st->start + 6) //指定ã—ãŸã‚­ãƒ£ãƒ©ã‚’状態異常ã«ã™ã‚‹
- bl = map_id2bl (conv_num
- (st, &(st->stack->stack_data[st->start + 6])));
- else
- bl = map_id2bl (st->rid);
- if (bl->type == BL_PC
- && ((struct map_session_data *) bl)->state.potionpitcher_flag)
- bl = map_id2bl (((struct map_session_data *) bl)->skilltarget);
- if (MRAND (10000) < per)
- skill_status_change_start (bl, type, val1, 0, 0, 0, tick, 0);
- return 0;
+ bl = map_id2bl(st->rid);
+ skill_status_change_start(bl, type, val1, tick);
}
/*==========================================
* 状態異常ãŒç›´ã‚‹
*------------------------------------------
*/
-int buildin_sc_end (struct script_state *st)
-{
- struct block_list *bl;
- int type;
- type = conv_num (st, &(st->stack->stack_data[st->start + 2]));
- bl = map_id2bl (st->rid);
- if (bl->type == BL_PC
- && ((struct map_session_data *) bl)->state.potionpitcher_flag)
- bl = map_id2bl (((struct map_session_data *) bl)->skilltarget);
- skill_status_change_end (bl, type, -1);
-// if(battle_config.etc_log)
-// printf("sc_end : %d %d\n",st->rid,type);
- return 0;
-}
-
-int buildin_sc_check (struct script_state *st)
+static
+void builtin_sc_end(ScriptState *st)
{
struct block_list *bl;
- int type;
- type = conv_num (st, &(st->stack->stack_data[st->start + 2]));
- bl = map_id2bl (st->rid);
- if (bl->type == BL_PC
- && ((struct map_session_data *) bl)->state.potionpitcher_flag)
- bl = map_id2bl (((struct map_session_data *) bl)->skilltarget);
-
- push_val (st->stack, ScriptCode::INT, skill_status_change_active (bl, type));
-
- return 0;
+ StatusChange type = StatusChange(conv_num(st, &(st->stack->stack_data[st->start + 2])));
+ bl = map_id2bl(st->rid);
+ skill_status_change_end(bl, type, nullptr);
}
-/*==========================================
- * 状態異常è€æ€§ã‚’計算ã—ãŸç¢ºçŽ‡ã‚’è¿”ã™
- *------------------------------------------
- */
-int buildin_getscrate (struct script_state *st)
+static
+void builtin_sc_check(ScriptState *st)
{
struct block_list *bl;
- int sc_def = 100, sc_def_mdef2, sc_def_vit2, sc_def_int2, sc_def_luk2;
- int type, rate, luk;
-
- type = conv_num (st, &(st->stack->stack_data[st->start + 2]));
- rate = conv_num (st, &(st->stack->stack_data[st->start + 3]));
- if (st->end > st->start + 4) //指定ã—ãŸã‚­ãƒ£ãƒ©ã®è€æ€§ã‚’計算ã™ã‚‹
- bl = map_id2bl (conv_num
- (st, &(st->stack->stack_data[st->start + 6])));
- else
- bl = map_id2bl (st->rid);
-
- luk = battle_get_luk (bl);
- sc_def_mdef2 = 100 - (3 + battle_get_mdef (bl) + luk / 3);
- sc_def_vit2 = 100 - (3 + battle_get_vit (bl) + luk / 3);
- sc_def_int2 = 100 - (3 + battle_get_int (bl) + luk / 3);
- sc_def_luk2 = 100 - (3 + luk);
-
- if (type == SC_STONE || type == SC_FREEZE)
- sc_def = sc_def_mdef2;
- else if (type == SC_STAN || type == SC_POISON || type == SC_SILENCE)
- sc_def = sc_def_vit2;
- else if (type == SC_SLEEP || type == SC_CONFUSION || type == SC_BLIND)
- sc_def = sc_def_int2;
- else if (type == SC_CURSE)
- sc_def = sc_def_luk2;
-
- rate = rate * sc_def / 100;
- push_val (st->stack, ScriptCode::INT, rate);
+ StatusChange type = StatusChange(conv_num(st, &(st->stack->stack_data[st->start + 2])));
+ bl = map_id2bl(st->rid);
- return 0;
+ push_val(st->stack, ScriptCode::INT, skill_status_change_active(bl, type));
}
@@ -4992,371 +3254,81 @@ int buildin_getscrate (struct script_state *st)
*
*------------------------------------------
*/
-int buildin_debugmes (struct script_state *st)
+static
+void builtin_debugmes(ScriptState *st)
{
- conv_str (st, &(st->stack->stack_data[st->start + 2]));
- printf ("script debug : %d %d : %s\n", st->rid, st->oid,
+ conv_str(st, &(st->stack->stack_data[st->start + 2]));
+ PRINTF("script debug : %d %d : %s\n", st->rid, st->oid,
st->stack->stack_data[st->start + 2].u.str);
- return 0;
-}
-
-/*==========================================
- * Added - AppleGirl For Advanced Classes, (Updated for Cleaner Script Purposes)
- *------------------------------------------
- */
-int buildin_resetlvl (struct script_state *st)
-{
- struct map_session_data *sd;
-
- int type = conv_num (st, &(st->stack->stack_data[st->start + 2]));
-
- sd = script_rid2sd (st);
- pc_resetlvl (sd, type);
- return 0;
}
/*==========================================
* ステータスリセット
*------------------------------------------
*/
-int buildin_resetstatus (struct script_state *st)
+static
+void builtin_resetstatus(ScriptState *st)
{
struct map_session_data *sd;
- sd = script_rid2sd (st);
- pc_resetstate (sd);
- return 0;
-}
-
-/*==========================================
- * スキルリセット
- *------------------------------------------
- */
-int buildin_resetskill (struct script_state *st)
-{
- struct map_session_data *sd;
- sd = script_rid2sd (st);
- pc_resetskill (sd);
- return 0;
-}
-
-/*==========================================
- *
- *------------------------------------------
- */
-int buildin_changebase (struct script_state *st)
-{
- struct map_session_data *sd = NULL;
- int vclass;
-
- if (st->end > st->start + 3)
- sd = map_id2sd (conv_num
- (st, &(st->stack->stack_data[st->start + 3])));
- else
- sd = script_rid2sd (st);
-
- if (sd == NULL)
- return 0;
-
- vclass = conv_num (st, &(st->stack->stack_data[st->start + 2]));
- if (vclass == 22 && !battle_config.wedding_modifydisplay)
- return 0;
-
-// if(vclass==22) {
-// pc_unequipitem(sd,sd->equip_index[9],0); // 装備外
-// }
-
- sd->view_class = vclass;
-
- return 0;
+ sd = script_rid2sd(st);
+ pc_resetstate(sd);
}
/*==========================================
* 性別変æ›
*------------------------------------------
*/
-int buildin_changesex (struct script_state *st)
+static
+void builtin_changesex(ScriptState *st)
{
struct map_session_data *sd = NULL;
- sd = script_rid2sd (st);
+ sd = script_rid2sd(st);
if (sd->status.sex == 0)
{
sd->status.sex = 1;
sd->sex = 1;
- if (sd->status.pc_class == 20 || sd->status.pc_class == 4021)
- sd->status.pc_class -= 1;
}
else if (sd->status.sex == 1)
{
sd->status.sex = 0;
sd->sex = 0;
- if (sd->status.pc_class == 19 || sd->status.pc_class == 4020)
- sd->status.pc_class += 1;
}
- chrif_char_ask_name (-1, sd->status.name, 5, 0, 0, 0, 0, 0, 0); // type: 5 - changesex
- chrif_save (sd);
- return 0;
-}
-
-/*==========================================
- * npcãƒãƒ£ãƒƒãƒˆä½œæˆ
- *------------------------------------------
- */
-int buildin_waitingroom (struct script_state *st)
-{
- const char *name, *ev = "";
- int limit, trigger = 0, pub = 1;
- name = conv_str (st, &(st->stack->stack_data[st->start + 2]));
- limit = conv_num (st, &(st->stack->stack_data[st->start + 3]));
- if (limit == 0)
- pub = 3;
-
- if ((st->end > st->start + 5))
- {
- struct script_data *data = &(st->stack->stack_data[st->start + 5]);
- get_val (st, data);
- if (data->type == ScriptCode::INT)
- {
- // æ–°Athena仕様(æ—§Athena仕様ã¨äº’æ›æ€§ã‚ã‚Š)
- ev = conv_str (st, &(st->stack->stack_data[st->start + 4]));
- trigger = conv_num (st, &(st->stack->stack_data[st->start + 5]));
- }
- else
- {
- // eathena仕様
- trigger = conv_num (st, &(st->stack->stack_data[st->start + 4]));
- ev = conv_str (st, &(st->stack->stack_data[st->start + 5]));
- }
- }
- else
- {
- // 旧Athena仕様
- if (st->end > st->start + 4)
- ev = conv_str (st, &(st->stack->stack_data[st->start + 4]));
- }
- chat_createnpcchat ((struct npc_data *) map_id2bl (st->oid),
- limit, pub, trigger, name, strlen (name) + 1, ev);
- return 0;
-}
-
-/*==========================================
- * npcãƒãƒ£ãƒƒãƒˆå‰Šé™¤
- *------------------------------------------
- */
-int buildin_delwaitingroom (struct script_state *st)
-{
- struct npc_data *nd;
- if (st->end > st->start + 2)
- nd = npc_name2id (conv_str
- (st, &(st->stack->stack_data[st->start + 2])));
- else
- nd = (struct npc_data *) map_id2bl (st->oid);
- chat_deletenpcchat (nd);
- return 0;
-}
-
-/*==========================================
- * npcãƒãƒ£ãƒƒãƒˆå…¨å“¡è¹´ã‚Šå‡ºã™
- *------------------------------------------
- */
-static
-int buildin_waitingroomkickall (struct script_state *st)
-{
- struct npc_data *nd;
- struct chat_data *cd;
-
- if (st->end > st->start + 2)
- nd = npc_name2id (conv_str
- (st, &(st->stack->stack_data[st->start + 2])));
- else
- nd = (struct npc_data *) map_id2bl (st->oid);
-
- if (nd == NULL
- || (cd = (struct chat_data *) map_id2bl (nd->chat_id)) == NULL)
- return 0;
- chat_npckickall (cd);
- return 0;
-}
-
-/*==========================================
- * npcãƒãƒ£ãƒƒãƒˆã‚¤ãƒ™ãƒ³ãƒˆæœ‰åŠ¹åŒ–
- *------------------------------------------
- */
-int buildin_enablewaitingroomevent (struct script_state *st)
-{
- struct npc_data *nd;
- struct chat_data *cd;
-
- if (st->end > st->start + 2)
- nd = npc_name2id (conv_str
- (st, &(st->stack->stack_data[st->start + 2])));
- else
- nd = (struct npc_data *) map_id2bl (st->oid);
-
- if (nd == NULL
- || (cd = (struct chat_data *) map_id2bl (nd->chat_id)) == NULL)
- return 0;
- chat_enableevent (cd);
- return 0;
-}
-
-/*==========================================
- * npcãƒãƒ£ãƒƒãƒˆã‚¤ãƒ™ãƒ³ãƒˆç„¡åŠ¹åŒ–
- *------------------------------------------
- */
-int buildin_disablewaitingroomevent (struct script_state *st)
-{
- struct npc_data *nd;
- struct chat_data *cd;
-
- if (st->end > st->start + 2)
- nd = npc_name2id (conv_str
- (st, &(st->stack->stack_data[st->start + 2])));
- else
- nd = (struct npc_data *) map_id2bl (st->oid);
-
- if (nd == NULL
- || (cd = (struct chat_data *) map_id2bl (nd->chat_id)) == NULL)
- return 0;
- chat_disableevent (cd);
- return 0;
-}
-
-/*==========================================
- * npcãƒãƒ£ãƒƒãƒˆçŠ¶æ…‹æ‰€å¾—
- *------------------------------------------
- */
-int buildin_getwaitingroomstate (struct script_state *st)
-{
- struct npc_data *nd;
- struct chat_data *cd;
- int val = 0, type;
- type = conv_num (st, &(st->stack->stack_data[st->start + 2]));
- if (st->end > st->start + 3)
- nd = npc_name2id (conv_str
- (st, &(st->stack->stack_data[st->start + 3])));
- else
- nd = (struct npc_data *) map_id2bl (st->oid);
-
- if (nd == NULL
- || (cd = (struct chat_data *) map_id2bl (nd->chat_id)) == NULL)
- {
- push_val (st->stack, ScriptCode::INT, -1);
- return 0;
- }
-
- switch (type)
- {
- case 0:
- val = cd->users;
- break;
- case 1:
- val = cd->limit;
- break;
- case 2:
- val = cd->trigger & 0x7f;
- break;
- case 3:
- val = ((cd->trigger & 0x80) > 0);
- break;
- case 32:
- val = (cd->users >= cd->limit);
- break;
- case 33:
- val = (cd->users >= cd->trigger);
- break;
-
- case 4:
- push_str (st->stack, ScriptCode::CONSTSTR, cd->title);
- return 0;
- case 5:
- push_str (st->stack, ScriptCode::CONSTSTR, cd->pass);
- return 0;
- case 16:
- push_str (st->stack, ScriptCode::CONSTSTR, cd->npc_event);
- return 0;
- }
- push_val (st->stack, ScriptCode::INT, val);
- return 0;
-}
-
-/*==========================================
- * ãƒãƒ£ãƒƒãƒˆãƒ¡ãƒ³ãƒãƒ¼(è¦å®šäººæ•°)ワープ
- *------------------------------------------
- */
-int buildin_warpwaitingpc (struct script_state *st)
-{
- int x, y, i, n;
- struct npc_data *nd = (struct npc_data *) map_id2bl (st->oid);
- struct chat_data *cd;
-
- if (nd == NULL
- || (cd = (struct chat_data *) map_id2bl (nd->chat_id)) == NULL)
- return 0;
-
- n = cd->trigger & 0x7f;
- const char *str = conv_str (st, &(st->stack->stack_data[st->start + 2]));
- x = conv_num (st, &(st->stack->stack_data[st->start + 3]));
- y = conv_num (st, &(st->stack->stack_data[st->start + 4]));
-
- if (st->end > st->start + 5)
- n = conv_num (st, &(st->stack->stack_data[st->start + 5]));
-
- for (i = 0; i < n; i++)
- {
- struct map_session_data *sd = cd->usersd[0]; // リスト先頭ã®PCを次々ã«ã€‚
-
- mapreg_setreg (add_str ("$@warpwaitingpc") + (i << 24), sd->bl.id);
-
- if (strcmp (str, "Random") == 0)
- pc_randomwarp (sd, 3);
- else if (strcmp (str, "SavePoint") == 0)
- {
- if (map[sd->bl.m].flag.noteleport) // テレãƒç¦æ­¢
- return 0;
-
- pc_setpos (sd, sd->status.save_point.map,
- sd->status.save_point.x, sd->status.save_point.y, 3);
- }
- else
- pc_setpos (sd, str, x, y, 0);
- }
- mapreg_setreg (add_str ("$@warpwaitingpcnum"), n);
- return 0;
+ chrif_char_ask_name(-1, sd->status.name, 5, 0, 0, 0, 0, 0, 0); // type: 5 - changesex
+ chrif_save(sd);
}
/*==========================================
* RIDã®ã‚¢ã‚¿ãƒƒãƒ
*------------------------------------------
*/
-int buildin_attachrid (struct script_state *st)
+static
+void builtin_attachrid(ScriptState *st)
{
- st->rid = conv_num (st, &(st->stack->stack_data[st->start + 2]));
- push_val (st->stack, ScriptCode::INT, (map_id2sd (st->rid) != NULL));
- return 0;
+ st->rid = conv_num(st, &(st->stack->stack_data[st->start + 2]));
+ push_val(st->stack, ScriptCode::INT, (map_id2sd(st->rid) != NULL));
}
/*==========================================
* RIDã®ãƒ‡ã‚¿ãƒƒãƒ
*------------------------------------------
*/
-int buildin_detachrid (struct script_state *st)
+static
+void builtin_detachrid(ScriptState *st)
{
st->rid = 0;
- return 0;
}
/*==========================================
* 存在ãƒã‚§ãƒƒã‚¯
*------------------------------------------
*/
-int buildin_isloggedin (struct script_state *st)
+static
+void builtin_isloggedin(ScriptState *st)
{
- push_val (st->stack, ScriptCode::INT,
- map_id2sd (conv_num
- (st,
+ push_val(st->stack, ScriptCode::INT,
+ map_id2sd(conv_num(st,
&(st->stack->stack_data[st->start + 2]))) != NULL);
- return 0;
}
/*==========================================
@@ -5364,40 +3336,38 @@ int buildin_isloggedin (struct script_state *st)
*------------------------------------------
*/
enum
-{ MF_NOMEMO, MF_NOTELEPORT, MF_NOSAVE, MF_NOBRANCH, MF_NOPENALTY,
- MF_NOZENYPENALTY, MF_PVP, MF_PVP_NOPARTY, MF_PVP_NOGUILD, MF_GVG,
- MF_GVG_NOPARTY, MF_NOTRADE, MF_NOSKILL, MF_NOWARP, MF_NOPVP,
- MF_NOICEWALL,
- MF_SNOW, MF_FOG, MF_SAKURA, MF_LEAVES, MF_RAIN
-};
-
-int buildin_setmapflagnosave (struct script_state *st)
{
- int m, x, y;
-
- const char *str = conv_str (st, &(st->stack->stack_data[st->start + 2]));
- const char *str2 = conv_str (st, &(st->stack->stack_data[st->start + 3]));
- x = conv_num (st, &(st->stack->stack_data[st->start + 4]));
- y = conv_num (st, &(st->stack->stack_data[st->start + 5]));
- m = map_mapname2mapid (str);
- if (m >= 0)
- {
- map[m].flag.nosave = 1;
- memcpy (map[m].save.map, str2, 16);
- map[m].save.x = x;
- map[m].save.y = y;
- }
-
- return 0;
-}
+ MF_NOMEMO = 0,
+ MF_NOTELEPORT = 1,
+ MF_NOSAVE = 2,
+ MF_NOBRANCH = 3,
+ MF_NOPENALTY = 4,
+ MF_NOZENYPENALTY = 5,
+ MF_PVP = 6,
+ MF_PVP_NOPARTY = 7,
+ //MF_PVP_NOGUILD = 8,
+ //MF_GVG = 9,
+ //MF_GVG_NOPARTY = 10,
+ MF_NOTRADE = 11,
+ //MF_NOSKILL = 12,
+ MF_NOWARP = 13,
+ MF_NOPVP = 14,
+ MF_NOICEWALL = 15,
+ MF_SNOW = 16,
+ MF_FOG = 17,
+ MF_SAKURA = 18,
+ MF_LEAVES = 19,
+ MF_RAIN = 20,
+};
-int buildin_setmapflag (struct script_state *st)
+static
+void builtin_setmapflag(ScriptState *st)
{
- int m, i;
+ int m, i;
- const char *str = conv_str (st, &(st->stack->stack_data[st->start + 2]));
- i = conv_num (st, &(st->stack->stack_data[st->start + 3]));
- m = map_mapname2mapid (str);
+ const char *str = conv_str(st, &(st->stack->stack_data[st->start + 2]));
+ i = conv_num(st, &(st->stack->stack_data[st->start + 3]));
+ m = map_mapname2mapid(str);
if (m >= 0)
{
switch (i)
@@ -5417,21 +3387,12 @@ int buildin_setmapflag (struct script_state *st)
case MF_PVP_NOPARTY:
map[m].flag.pvp_noparty = 1;
break;
- case MF_PVP_NOGUILD:
- map[m].flag.pvp_noguild = 1;
- break;
- case MF_GVG_NOPARTY:
- map[m].flag.gvg_noparty = 1;
- break;
case MF_NOZENYPENALTY:
map[m].flag.nozenypenalty = 1;
break;
case MF_NOTRADE:
map[m].flag.notrade = 1;
break;
- case MF_NOSKILL:
- map[m].flag.noskill = 1;
- break;
case MF_NOWARP:
map[m].flag.nowarp = 1;
break;
@@ -5459,16 +3420,16 @@ int buildin_setmapflag (struct script_state *st)
}
}
- return 0;
}
-int buildin_removemapflag (struct script_state *st)
+static
+void builtin_removemapflag(ScriptState *st)
{
- int m, i;
+ int m, i;
- const char *str = conv_str (st, &(st->stack->stack_data[st->start + 2]));
- i = conv_num (st, &(st->stack->stack_data[st->start + 3]));
- m = map_mapname2mapid (str);
+ const char *str = conv_str(st, &(st->stack->stack_data[st->start + 2]));
+ i = conv_num(st, &(st->stack->stack_data[st->start + 3]));
+ m = map_mapname2mapid(str);
if (m >= 0)
{
switch (i)
@@ -5491,18 +3452,9 @@ int buildin_removemapflag (struct script_state *st)
case MF_PVP_NOPARTY:
map[m].flag.pvp_noparty = 0;
break;
- case MF_PVP_NOGUILD:
- map[m].flag.pvp_noguild = 0;
- break;
- case MF_GVG_NOPARTY:
- map[m].flag.gvg_noparty = 0;
- break;
case MF_NOZENYPENALTY:
map[m].flag.nozenypenalty = 0;
break;
- case MF_NOSKILL:
- map[m].flag.noskill = 0;
- break;
case MF_NOWARP:
map[m].flag.nowarp = 0;
break;
@@ -5531,34 +3483,96 @@ int buildin_removemapflag (struct script_state *st)
}
}
- return 0;
}
-int buildin_pvpon (struct script_state *st)
+static
+void builtin_getmapflag(ScriptState *st)
+{
+ int m, i, r = -1;
+
+ const char *str = conv_str(st, &(st->stack->stack_data[st->start + 2]));
+ i = conv_num(st, &(st->stack->stack_data[st->start + 3]));
+ m = map_mapname2mapid(str);
+ if (m >= 0)
+ {
+ switch (i)
+ {
+ case MF_NOMEMO:
+ r = map[m].flag.nomemo;
+ break;
+ case MF_NOTELEPORT:
+ r = map[m].flag.noteleport;
+ break;
+ case MF_NOSAVE:
+ r = map[m].flag.nosave;
+ break;
+ case MF_NOBRANCH:
+ r = map[m].flag.nobranch;
+ break;
+ case MF_NOPENALTY:
+ r = map[m].flag.nopenalty;
+ break;
+ case MF_PVP_NOPARTY:
+ r = map[m].flag.pvp_noparty;
+ break;
+ case MF_NOZENYPENALTY:
+ r = map[m].flag.nozenypenalty;
+ break;
+ case MF_NOWARP:
+ r = map[m].flag.nowarp;
+ break;
+ case MF_NOPVP:
+ r = map[m].flag.nopvp;
+ break;
+ case MF_NOICEWALL: // [Valaris]
+ r = map[m].flag.noicewall;
+ break;
+ case MF_SNOW: // [Valaris]
+ r = map[m].flag.snow;
+ break;
+ case MF_FOG: // [Valaris]
+ r = map[m].flag.fog;
+ break;
+ case MF_SAKURA: // [Valaris]
+ r = map[m].flag.sakura;
+ break;
+ case MF_LEAVES: // [Valaris]
+ r = map[m].flag.leaves;
+ break;
+ case MF_RAIN: // [Valaris]
+ r = map[m].flag.rain;
+ break;
+ }
+ }
+
+ push_val(st->stack, ScriptCode::INT, r);
+}
+
+static
+void builtin_pvpon(ScriptState *st)
{
- int m, i;
+ int m, i;
struct map_session_data *pl_sd = NULL;
- const char *str = conv_str (st, &(st->stack->stack_data[st->start + 2]));
- m = map_mapname2mapid (str);
+ const char *str = conv_str(st, &(st->stack->stack_data[st->start + 2]));
+ m = map_mapname2mapid(str);
if (m >= 0 && !map[m].flag.pvp && !map[m].flag.nopvp)
{
map[m].flag.pvp = 1;
- clif_send0199 (m, 1);
if (battle_config.pk_mode) // disable ranking functions if pk_mode is on [Valaris]
- return 0;
+ return;
for (i = 0; i < fd_max; i++)
{ //人数分ループ
if (session[i] && (pl_sd = (struct map_session_data *)session[i]->session_data)
&& pl_sd->state.auth)
{
- if (m == pl_sd->bl.m && pl_sd->pvp_timer == -1)
+ if (m == pl_sd->bl.m && !pl_sd->pvp_timer)
{
- pl_sd->pvp_timer =
- add_timer (gettick () + 200, pc_calc_pvprank_timer,
- pl_sd->bl.id, 0);
+ pl_sd->pvp_timer = Timer(gettick() + std::chrono::milliseconds(200),
+ std::bind(pc_calc_pvprank_timer, ph::_1, ph::_2,
+ pl_sd->bl.id));
pl_sd->pvp_rank = 0;
pl_sd->pvp_lastusers = 0;
pl_sd->pvp_point = 5;
@@ -5567,23 +3581,22 @@ int buildin_pvpon (struct script_state *st)
}
}
- return 0;
}
-int buildin_pvpoff (struct script_state *st)
+static
+void builtin_pvpoff(ScriptState *st)
{
- int m, i;
+ int m, i;
struct map_session_data *pl_sd = NULL;
- const char *str = conv_str (st, &(st->stack->stack_data[st->start + 2]));
- m = map_mapname2mapid (str);
+ const char *str = conv_str(st, &(st->stack->stack_data[st->start + 2]));
+ m = map_mapname2mapid(str);
if (m >= 0 && map[m].flag.pvp && map[m].flag.nopvp)
{
map[m].flag.pvp = 0;
- clif_send0199 (m, 0);
if (battle_config.pk_mode) // disable ranking options if pk_mode is on [Valaris]
- return 0;
+ return;
for (i = 0; i < fd_max; i++)
{ //人数分ループ
@@ -5592,1124 +3605,297 @@ int buildin_pvpoff (struct script_state *st)
{
if (m == pl_sd->bl.m)
{
- clif_pvpset (pl_sd, 0, 0, 2);
- if (pl_sd->pvp_timer != -1)
- {
- delete_timer (pl_sd->pvp_timer,
- pc_calc_pvprank_timer);
- pl_sd->pvp_timer = -1;
- }
+ pl_sd->pvp_timer.cancel();
}
}
}
}
- return 0;
-}
-
-int buildin_gvgon (struct script_state *st)
-{
- int m;
- const char *str = conv_str (st, &(st->stack->stack_data[st->start + 2]));
- m = map_mapname2mapid (str);
- if (m >= 0 && !map[m].flag.gvg)
- {
- map[m].flag.gvg = 1;
- clif_send0199 (m, 3);
- }
-
- return 0;
-}
-
-int buildin_gvgoff (struct script_state *st)
-{
- int m;
- const char *str = conv_str (st, &(st->stack->stack_data[st->start + 2]));
- m = map_mapname2mapid (str);
- if (m >= 0 && map[m].flag.gvg)
- {
- map[m].flag.gvg = 0;
- clif_send0199 (m, 0);
- }
-
- return 0;
}
/*==========================================
- * NPCエモーション
+ * NPCエモーション
*------------------------------------------
*/
-int buildin_emotion (struct script_state *st)
+static
+void builtin_emotion(ScriptState *st)
{
- int type;
- type = conv_num (st, &(st->stack->stack_data[st->start + 2]));
+ int type;
+ type = conv_num(st, &(st->stack->stack_data[st->start + 2]));
if (type < 0 || type > 100)
- return 0;
- clif_emotion (map_id2bl (st->oid), type);
- return 0;
+ return;
+ clif_emotion(map_id2bl(st->oid), type);
}
static
-int buildin_maprespawnguildid_sub (struct block_list *bl, va_list ap)
+void builtin_mapwarp(ScriptState *st) // Added by RoVeRT
{
- int g_id = va_arg (ap, int);
- int flag = va_arg (ap, int);
- struct map_session_data *sd = NULL;
- struct mob_data *md = NULL;
+ int x, y, m;
+ int x0, y0, x1, y1;
- if (bl->type == BL_PC)
- sd = (struct map_session_data *) bl;
- if (bl->type == BL_MOB)
- md = (struct mob_data *) bl;
-
- if (sd)
- {
- if ((sd->status.guild_id == g_id) && (flag & 1))
- pc_setpos (sd, sd->status.save_point.map, sd->status.save_point.x,
- sd->status.save_point.y, 3);
- else if ((sd->status.guild_id != g_id) && (flag & 2))
- pc_setpos (sd, sd->status.save_point.map, sd->status.save_point.x,
- sd->status.save_point.y, 3);
- else if (sd->status.guild_id == 0) // Warp out players not in guild [Valaris]
- pc_setpos (sd, sd->status.save_point.map, sd->status.save_point.x, sd->status.save_point.y, 3); // end addition [Valaris]
- }
- if (md && flag & 4)
- {
- if (md->mob_class < 1285 || md->mob_class > 1288)
- mob_delete (md);
- }
- return 0;
-}
-
-int buildin_maprespawnguildid (struct script_state *st)
-{
- const char *mapname = conv_str (st, &(st->stack->stack_data[st->start + 2]));
- int g_id = conv_num (st, &(st->stack->stack_data[st->start + 3]));
- int flag = conv_num (st, &(st->stack->stack_data[st->start + 4]));
-
- int m = map_mapname2mapid (mapname);
-
- if (m)
- map_foreachinarea (buildin_maprespawnguildid_sub, m, 0, 0,
- map[m].xs - 1, map[m].ys - 1, BL_NUL, g_id, flag);
- return 0;
-}
-
-int buildin_agitstart (struct script_state *st)
-{
- if (agit_flag == 1)
- return 1; // Agit already Start.
- agit_flag = 1;
- guild_agit_start ();
- return 0;
-}
-
-int buildin_agitend (struct script_state *st)
-{
- if (agit_flag == 0)
- return 1; // Agit already End.
- agit_flag = 0;
- guild_agit_end ();
- return 0;
-}
-
-/*==========================================
- * agitcheck 1; // choice script
- * if(@agit_flag == 1) goto agit;
- * if(agitcheck(0) == 1) goto agit;
- *------------------------------------------
- */
-int buildin_agitcheck (struct script_state *st)
-{
- struct map_session_data *sd;
- int cond;
-
- sd = script_rid2sd (st);
- cond = conv_num (st, &(st->stack->stack_data[st->start + 2]));
-
- if (cond == 0)
- {
- if (agit_flag == 1)
- push_val (st->stack, ScriptCode::INT, 1);
- if (agit_flag == 0)
- push_val (st->stack, ScriptCode::INT, 0);
- }
- else
- {
- if (agit_flag == 1)
- pc_setreg (sd, add_str ("@agit_flag"), 1);
- if (agit_flag == 0)
- pc_setreg (sd, add_str ("@agit_flag"), 0);
- }
- return 0;
-}
-
-int buildin_flagemblem (struct script_state *st)
-{
- int g_id = conv_num (st, &(st->stack->stack_data[st->start + 2]));
-
- if (g_id < 0)
- return 0;
-
-// printf("Script.c: [FlagEmblem] GuildID=%d, Emblem=%d.\n", g->guild_id, g->emblem_id);
- ((struct npc_data *) map_id2bl (st->oid))->u.scr.guild_id = g_id;
- return 1;
-}
-
-int buildin_getcastlename (struct script_state *st)
-{
- const char *mapname = conv_str (st, &(st->stack->stack_data[st->start + 2]));
- struct guild_castle *gc;
- int i;
- char *buf = NULL;
- for (i = 0; i < MAX_GUILDCASTLE; i++)
- {
- if ((gc = guild_castle_search (i)) != NULL)
- {
- if (strcmp (mapname, gc->map_name) == 0)
- {
- buf = (char *) calloc (24, 1);
- strncpy (buf, gc->castle_name, 23);
- break;
- }
- }
- }
- if (buf)
- push_str (st->stack, ScriptCode::STR, buf);
- else
- push_str (st->stack, ScriptCode::CONSTSTR, "");
- return 0;
-}
-
-int buildin_getcastledata (struct script_state *st)
-{
- const char *mapname = conv_str (st, &(st->stack->stack_data[st->start + 2]));
- int index = conv_num (st, &(st->stack->stack_data[st->start + 3]));
- const char *event = NULL;
- struct guild_castle *gc;
- int i, j;
-
- if (st->end > st->start + 4 && index == 0)
- {
- for (i = 0, j = -1; i < MAX_GUILDCASTLE; i++)
- if ((gc = guild_castle_search (i)) != NULL &&
- strcmp (mapname, gc->map_name) == 0)
- j = i;
- if (j >= 0)
- {
- event = conv_str (st, &(st->stack->stack_data[st->start + 4]));
- guild_addcastleinfoevent (j, 17, event);
- }
- }
-
- for (i = 0; i < MAX_GUILDCASTLE; i++)
- {
- if ((gc = guild_castle_search (i)) != NULL)
- {
- if (strcmp (mapname, gc->map_name) == 0)
- {
- switch (index)
- {
- case 0:
- for (j = 1; j < 26; j++)
- guild_castledataload (gc->castle_id, j);
- break; // Initialize[AgitInit]
- case 1:
- push_val (st->stack, ScriptCode::INT, gc->guild_id);
- break;
- case 2:
- push_val (st->stack, ScriptCode::INT, gc->economy);
- break;
- case 3:
- push_val (st->stack, ScriptCode::INT, gc->defense);
- break;
- case 4:
- push_val (st->stack, ScriptCode::INT, gc->triggerE);
- break;
- case 5:
- push_val (st->stack, ScriptCode::INT, gc->triggerD);
- break;
- case 6:
- push_val (st->stack, ScriptCode::INT, gc->nextTime);
- break;
- case 7:
- push_val (st->stack, ScriptCode::INT, gc->payTime);
- break;
- case 8:
- push_val (st->stack, ScriptCode::INT, gc->createTime);
- break;
- case 9:
- push_val (st->stack, ScriptCode::INT, gc->visibleC);
- break;
- case 10:
- push_val (st->stack, ScriptCode::INT, gc->visibleG0);
- break;
- case 11:
- push_val (st->stack, ScriptCode::INT, gc->visibleG1);
- break;
- case 12:
- push_val (st->stack, ScriptCode::INT, gc->visibleG2);
- break;
- case 13:
- push_val (st->stack, ScriptCode::INT, gc->visibleG3);
- break;
- case 14:
- push_val (st->stack, ScriptCode::INT, gc->visibleG4);
- break;
- case 15:
- push_val (st->stack, ScriptCode::INT, gc->visibleG5);
- break;
- case 16:
- push_val (st->stack, ScriptCode::INT, gc->visibleG6);
- break;
- case 17:
- push_val (st->stack, ScriptCode::INT, gc->visibleG7);
- break;
- case 18:
- push_val (st->stack, ScriptCode::INT, gc->Ghp0);
- break;
- case 19:
- push_val (st->stack, ScriptCode::INT, gc->Ghp1);
- break;
- case 20:
- push_val (st->stack, ScriptCode::INT, gc->Ghp2);
- break;
- case 21:
- push_val (st->stack, ScriptCode::INT, gc->Ghp3);
- break;
- case 22:
- push_val (st->stack, ScriptCode::INT, gc->Ghp4);
- break;
- case 23:
- push_val (st->stack, ScriptCode::INT, gc->Ghp5);
- break;
- case 24:
- push_val (st->stack, ScriptCode::INT, gc->Ghp6);
- break;
- case 25:
- push_val (st->stack, ScriptCode::INT, gc->Ghp7);
- break;
- default:
- push_val (st->stack, ScriptCode::INT, 0);
- break;
- }
- return 0;
- }
- }
- }
- push_val (st->stack, ScriptCode::INT, 0);
- return 0;
-}
-
-int buildin_setcastledata (struct script_state *st)
-{
- const char *mapname = conv_str (st, &(st->stack->stack_data[st->start + 2]));
- int index = conv_num (st, &(st->stack->stack_data[st->start + 3]));
- int value = conv_num (st, &(st->stack->stack_data[st->start + 4]));
- struct guild_castle *gc;
- int i;
-
- for (i = 0; i < MAX_GUILDCASTLE; i++)
- {
- if ((gc = guild_castle_search (i)) != NULL)
- {
- if (strcmp (mapname, gc->map_name) == 0)
- {
- // Save Data byself First
- switch (index)
- {
- case 1:
- 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;
- 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;
- default:
- return 0;
- }
- guild_castledatasave (gc->castle_id, index, value);
- return 0;
- }
- }
- }
- return 0;
-}
-
-/* =====================================================================
- * ギルド情報をè¦æ±‚ã™ã‚‹
- * ---------------------------------------------------------------------
- */
-int buildin_requestguildinfo (struct script_state *st)
-{
- int guild_id = conv_num (st, &(st->stack->stack_data[st->start + 2]));
- const char *event = NULL;
-
- if (st->end > st->start + 3)
- event = conv_str (st, &(st->stack->stack_data[st->start + 3]));
-
- if (guild_id > 0)
- guild_npc_request_info (guild_id, event);
- return 0;
-}
-
-/* =====================================================================
- * カードã®æ•°ã‚’å¾—ã‚‹
- * ---------------------------------------------------------------------
- */
-int buildin_getequipcardcnt (struct script_state *st)
-{
- int i, num;
- struct map_session_data *sd;
- int c = 4;
-
- num = conv_num (st, &(st->stack->stack_data[st->start + 2]));
- sd = script_rid2sd (st);
- i = pc_checkequip (sd, equip[num - 1]);
- if (sd->status.inventory[i].card[0] == 0x00ff)
- { // 製造武器ã¯ã‚«ãƒ¼ãƒ‰ãªã—
- push_val (st->stack, ScriptCode::INT, 0);
- return 0;
- }
- do
- {
- if ((sd->status.inventory[i].card[c - 1] > 4000) &&
- (sd->status.inventory[i].card[c - 1] < 5000))
- {
-
- push_val (st->stack, ScriptCode::INT, (c));
- return 0;
- }
- }
- while (c--);
- push_val (st->stack, ScriptCode::INT, 0);
- return 0;
-}
-
-/* ================================================================
- * カードå–り外ã—æˆåŠŸ
- * ----------------------------------------------------------------
- */
-int buildin_successremovecards (struct script_state *st)
-{
- int i, num, cardflag = 0, flag;
- struct map_session_data *sd;
- struct item item_tmp;
- int c = 4;
-
- num = conv_num (st, &(st->stack->stack_data[st->start + 2]));
- sd = script_rid2sd (st);
- i = pc_checkequip (sd, equip[num - 1]);
- if (sd->status.inventory[i].card[0] == 0x00ff)
- { // 製造武器ã¯å‡¦ç†ã—ãªã„
- return 0;
- }
- do
- {
- if ((sd->status.inventory[i].card[c - 1] > 4000) &&
- (sd->status.inventory[i].card[c - 1] < 5000))
- {
-
- cardflag = 1;
- item_tmp.id = 0, item_tmp.nameid =
- sd->status.inventory[i].card[c - 1];
- item_tmp.equip = 0, item_tmp.identify = 1, item_tmp.refine = 0;
- item_tmp.attribute = 0;
- item_tmp.card[0] = 0, item_tmp.card[1] = 0, item_tmp.card[2] =
- 0, item_tmp.card[3] = 0;
-
- if ((flag = pc_additem (sd, &item_tmp, 1)))
- { // æŒã¦ãªã„ãªã‚‰ãƒ‰ãƒ­ãƒƒãƒ—
- clif_additem (sd, 0, 0, flag);
- map_addflooritem (&item_tmp, 1, sd->bl.m, sd->bl.x, sd->bl.y,
- NULL, NULL, NULL, 0);
- }
- }
- }
- while (c--);
-
- if (cardflag == 1)
- { // カードをå–り除ã„ãŸã‚¢ã‚¤ãƒ†ãƒ æ‰€å¾—
- flag = 0;
- item_tmp.id = 0, item_tmp.nameid = sd->status.inventory[i].nameid;
- item_tmp.equip = 0, item_tmp.identify = 1, item_tmp.refine =
- sd->status.inventory[i].refine;
- item_tmp.attribute = sd->status.inventory[i].attribute;
- item_tmp.card[0] = 0, item_tmp.card[1] = 0, item_tmp.card[2] =
- 0, item_tmp.card[3] = 0;
- pc_delitem (sd, i, 1, 0);
- if ((flag = pc_additem (sd, &item_tmp, 1)))
- { // ã‚‚ã¦ãªã„ãªã‚‰ãƒ‰ãƒ­ãƒƒãƒ—
- clif_additem (sd, 0, 0, flag);
- map_addflooritem (&item_tmp, 1, sd->bl.m, sd->bl.x, sd->bl.y,
- NULL, NULL, NULL, 0);
- }
- clif_misceffect (&sd->bl, 3);
- return 0;
- }
- return 0;
-}
-
-/* ================================================================
- * カードå–り外ã—失敗 slot,type
- * type=0: 両方æ失ã€1:カードæ失ã€2:武具æ失ã€3:æ失無ã—
- * ----------------------------------------------------------------
- */
-int buildin_failedremovecards (struct script_state *st)
-{
- int i, num, cardflag = 0, flag, typefail;
- struct map_session_data *sd;
- struct item item_tmp;
- int c = 4;
-
- num = conv_num (st, &(st->stack->stack_data[st->start + 2]));
- typefail = conv_num (st, &(st->stack->stack_data[st->start + 3]));
- sd = script_rid2sd (st);
- i = pc_checkequip (sd, equip[num - 1]);
- if (sd->status.inventory[i].card[0] == 0x00ff)
- { // 製造武器ã¯å‡¦ç†ã—ãªã„
- return 0;
- }
- do
- {
- if ((sd->status.inventory[i].card[c - 1] > 4000) &&
- (sd->status.inventory[i].card[c - 1] < 5000))
- {
-
- cardflag = 1;
-
- if (typefail == 2)
- { // 武具ã®ã¿æ失ãªã‚‰ã€ã‚«ãƒ¼ãƒ‰ã¯å—ã‘å–らã›ã‚‹
- item_tmp.id = 0, item_tmp.nameid =
- sd->status.inventory[i].card[c - 1];
- item_tmp.equip = 0, item_tmp.identify = 1, item_tmp.refine =
- 0;
- item_tmp.attribute = 0;
- item_tmp.card[0] = 0, item_tmp.card[1] = 0, item_tmp.card[2] =
- 0, item_tmp.card[3] = 0;
- if ((flag = pc_additem (sd, &item_tmp, 1)))
- {
- clif_additem (sd, 0, 0, flag);
- map_addflooritem (&item_tmp, 1, sd->bl.m, sd->bl.x,
- sd->bl.y, NULL, NULL, NULL, 0);
- }
- }
- }
- }
- while (c--);
-
- if (cardflag == 1)
- {
-
- if (typefail == 0 || typefail == 2)
- { // 武具æ失
- pc_delitem (sd, i, 1, 0);
- clif_misceffect (&sd->bl, 2);
- return 0;
- }
- if (typefail == 1)
- { // カードã®ã¿æ失(武具を返ã™ï¼‰
- flag = 0;
- item_tmp.id = 0, item_tmp.nameid = sd->status.inventory[i].nameid;
- item_tmp.equip = 0, item_tmp.identify = 1, item_tmp.refine =
- sd->status.inventory[i].refine;
- item_tmp.attribute = sd->status.inventory[i].attribute;
- item_tmp.card[0] = 0, item_tmp.card[1] = 0, item_tmp.card[2] =
- 0, item_tmp.card[3] = 0;
- pc_delitem (sd, i, 1, 0);
- if ((flag = pc_additem (sd, &item_tmp, 1)))
- {
- clif_additem (sd, 0, 0, flag);
- map_addflooritem (&item_tmp, 1, sd->bl.m, sd->bl.x, sd->bl.y,
- NULL, NULL, NULL, 0);
- }
- }
- clif_misceffect (&sd->bl, 2);
- return 0;
- }
- return 0;
-}
-
-int buildin_mapwarp (struct script_state *st) // Added by RoVeRT
-{
- int x, y, m;
- int x0, y0, x1, y1;
-
- const char *mapname = conv_str (st, &(st->stack->stack_data[st->start + 2]));
+ const char *mapname = conv_str(st, &(st->stack->stack_data[st->start + 2]));
x0 = 0;
y0 = 0;
- x1 = map[map_mapname2mapid (mapname)].xs;
- y1 = map[map_mapname2mapid (mapname)].ys;
- const char *str = conv_str (st, &(st->stack->stack_data[st->start + 3]));
- x = conv_num (st, &(st->stack->stack_data[st->start + 4]));
- y = conv_num (st, &(st->stack->stack_data[st->start + 5]));
-
- if ((m = map_mapname2mapid (mapname)) < 0)
- return 0;
-
- map_foreachinarea (buildin_areawarp_sub,
- m, x0, y0, x1, y1, BL_PC, str, x, y);
- return 0;
-}
-
-int buildin_cmdothernpc (struct script_state *st) // Added by RoVeRT
-{
- const char *npc = conv_str (st, &(st->stack->stack_data[st->start + 2]));
- const char *command = conv_str (st, &(st->stack->stack_data[st->start + 3]));
+ x1 = map[map_mapname2mapid(mapname)].xs;
+ y1 = map[map_mapname2mapid(mapname)].ys;
+ const char *str = conv_str(st, &(st->stack->stack_data[st->start + 3]));
+ x = conv_num(st, &(st->stack->stack_data[st->start + 4]));
+ y = conv_num(st, &(st->stack->stack_data[st->start + 5]));
- npc_command (map_id2sd (st->rid), npc, command);
- return 0;
-}
-
-int buildin_inittimer (struct script_state *st) // Added by RoVeRT
-{
-// struct npc_data *nd=(struct npc_data*)map_id2bl(st->oid);
-
-// nd->lastaction=nd->timer=gettick();
- npc_do_ontimer (st->oid, map_id2sd (st->rid), 1);
+ if ((m = map_mapname2mapid(mapname)) < 0)
+ return;
- return 0;
+ map_foreachinarea(std::bind(builtin_areawarp_sub, ph::_1, str, x, y),
+ m, x0, y0, x1, y1, BL::PC);
}
-int buildin_stoptimer (struct script_state *st) // Added by RoVeRT
+static
+void builtin_cmdothernpc(ScriptState *st) // Added by RoVeRT
{
-// struct npc_data *nd=(struct npc_data*)map_id2bl(st->oid);
+ const char *npc = conv_str(st, &(st->stack->stack_data[st->start + 2]));
+ const char *command = conv_str(st, &(st->stack->stack_data[st->start + 3]));
-// nd->lastaction=nd->timer=-1;
- npc_do_ontimer (st->oid, map_id2sd (st->rid), 0);
-
- return 0;
+ npc_command(map_id2sd(st->rid), npc, command);
}
static
-int buildin_mobcount_sub (struct block_list *bl, va_list ap) // Added by RoVeRT
+void builtin_mobcount_sub(struct block_list *bl, const char *event, int *c)
{
- char *event = va_arg (ap, char *);
- int *c = va_arg (ap, int *);
-
- if (strcmp (event, ((struct mob_data *) bl)->npc_event) == 0)
+ if (strcmp(event, ((struct mob_data *) bl)->npc_event) == 0)
(*c)++;
- return 0;
}
-int buildin_mobcount (struct script_state *st) // Added by RoVeRT
+static
+void builtin_mobcount(ScriptState *st) // Added by RoVeRT
{
- int m, c = 0;
- const char *mapname = conv_str (st, &(st->stack->stack_data[st->start + 2]));
- const char *event = conv_str (st, &(st->stack->stack_data[st->start + 3]));
+ int m, c = 0;
+ const char *mapname = conv_str(st, &(st->stack->stack_data[st->start + 2]));
+ const char *event = conv_str(st, &(st->stack->stack_data[st->start + 3]));
- if ((m = map_mapname2mapid (mapname)) < 0)
+ if ((m = map_mapname2mapid(mapname)) < 0)
{
- push_val (st->stack, ScriptCode::INT, -1);
- return 0;
+ push_val(st->stack, ScriptCode::INT, -1);
+ return;
}
- map_foreachinarea (buildin_mobcount_sub,
- m, 0, 0, map[m].xs, map[m].ys, BL_MOB, event, &c);
+ map_foreachinarea(std::bind(builtin_mobcount_sub, ph::_1, event, &c),
+ m, 0, 0, map[m].xs, map[m].ys, BL::MOB);
- push_val (st->stack, ScriptCode::INT, (c - 1));
+ push_val(st->stack, ScriptCode::INT, (c - 1));
- return 0;
}
-int buildin_marriage (struct script_state *st)
+static
+void builtin_marriage(ScriptState *st)
{
- const char *partner = conv_str (st, &(st->stack->stack_data[st->start + 2]));
- struct map_session_data *sd = script_rid2sd (st);
- struct map_session_data *p_sd = map_nick2sd (partner);
+ const char *partner = conv_str(st, &(st->stack->stack_data[st->start + 2]));
+ struct map_session_data *sd = script_rid2sd(st);
+ struct map_session_data *p_sd = map_nick2sd(partner);
- if (sd == NULL || p_sd == NULL || pc_marriage (sd, p_sd) < 0)
+ if (sd == NULL || p_sd == NULL || pc_marriage(sd, p_sd) < 0)
{
- push_val (st->stack, ScriptCode::INT, 0);
- return 0;
+ push_val(st->stack, ScriptCode::INT, 0);
+ return;
}
- push_val (st->stack, ScriptCode::INT, 1);
- return 0;
-}
-
-int buildin_wedding_effect (struct script_state *st)
-{
- struct map_session_data *sd = script_rid2sd (st);
-
- if (sd == NULL)
- return 0;
- clif_wedding_effect (&sd->bl);
- return 0;
+ push_val(st->stack, ScriptCode::INT, 1);
}
-int buildin_divorce (struct script_state *st)
+static
+void builtin_divorce(ScriptState *st)
{
- struct map_session_data *sd = script_rid2sd (st);
+ struct map_session_data *sd = script_rid2sd(st);
st->state = STOP; // rely on pc_divorce to restart
sd->npc_flags.divorce = 1;
- if (sd == NULL || pc_divorce (sd) < 0)
- {
- push_val (st->stack, ScriptCode::INT, 0);
- return 0;
- }
-
- push_val (st->stack, ScriptCode::INT, 1);
- return 0;
-}
-
-/*================================================
- * Script for Displaying MOB Information [Valaris]
- *------------------------------------------------
- */
-int buildin_strmobinfo (struct script_state *st)
-{
-
- int num = conv_num (st, &(st->stack->stack_data[st->start + 2]));
- int mob_class = conv_num (st, &(st->stack->stack_data[st->start + 3]));
-
- if (num <= 0 || num >= 8 || (mob_class >= 0 && mob_class <= 1000) || mob_class > 2000)
- return 0;
-
- if (num == 1)
- {
- char *buf;
- buf = mob_db[mob_class].name;
- push_str (st->stack, ScriptCode::STR, buf);
- return 0;
- }
- else if (num == 2)
+ if (sd == NULL || pc_divorce(sd) < 0)
{
- char *buf;
- buf = mob_db[mob_class].jname;
- push_str (st->stack, ScriptCode::STR, buf);
- return 0;
+ push_val(st->stack, ScriptCode::INT, 0);
+ return;
}
- else if (num == 3)
- push_val (st->stack, ScriptCode::INT, mob_db[mob_class].lv);
- else if (num == 4)
- push_val (st->stack, ScriptCode::INT, mob_db[mob_class].max_hp);
- else if (num == 5)
- push_val (st->stack, ScriptCode::INT, mob_db[mob_class].max_sp);
- else if (num == 6)
- push_val (st->stack, ScriptCode::INT, mob_db[mob_class].base_exp);
- else if (num == 7)
- push_val (st->stack, ScriptCode::INT, mob_db[mob_class].job_exp);
- return 0;
-}
-
-/*==========================================
- * Summon guardians [Valaris]
- *------------------------------------------
- */
-int buildin_guardian (struct script_state *st)
-{
- int mob_class = 0, amount = 1, x = 0, y = 0, guardian = 0;
- const char *event = "";
-
- const char *mapname = conv_str (st, &(st->stack->stack_data[st->start + 2]));
- x = conv_num (st, &(st->stack->stack_data[st->start + 3]));
- y = conv_num (st, &(st->stack->stack_data[st->start + 4]));
- const char *str = conv_str (st, &(st->stack->stack_data[st->start + 5]));
- mob_class = conv_num (st, &(st->stack->stack_data[st->start + 6]));
- amount = conv_num (st, &(st->stack->stack_data[st->start + 7]));
- event = conv_str (st, &(st->stack->stack_data[st->start + 8]));
- if (st->end > st->start + 9)
- guardian = conv_num (st, &(st->stack->stack_data[st->start + 9]));
- mob_spawn_guardian (map_id2sd (st->rid), mapname, x, y, str, mob_class, amount,
- event, guardian);
-
- return 0;
-}
-
-/*================================================
- * Script for Displaying Guardian Info [Valaris]
- *------------------------------------------------
- */
-int buildin_guardianinfo (struct script_state *st)
-{
- int guardian = conv_num (st, &(st->stack->stack_data[st->start + 2]));
- struct map_session_data *sd = script_rid2sd (st);
- struct guild_castle *gc = guild_mapname2gc (map[sd->bl.m].name);
-
- if (guardian == 0 && gc->visibleG0 == 1)
- push_val (st->stack, ScriptCode::INT, gc->Ghp0);
- if (guardian == 1 && gc->visibleG1 == 1)
- push_val (st->stack, ScriptCode::INT, gc->Ghp1);
- if (guardian == 2 && gc->visibleG2 == 1)
- push_val (st->stack, ScriptCode::INT, gc->Ghp2);
- if (guardian == 3 && gc->visibleG3 == 1)
- push_val (st->stack, ScriptCode::INT, gc->Ghp3);
- if (guardian == 4 && gc->visibleG4 == 1)
- push_val (st->stack, ScriptCode::INT, gc->Ghp4);
- if (guardian == 5 && gc->visibleG5 == 1)
- push_val (st->stack, ScriptCode::INT, gc->Ghp5);
- if (guardian == 6 && gc->visibleG6 == 1)
- push_val (st->stack, ScriptCode::INT, gc->Ghp6);
- if (guardian == 7 && gc->visibleG7 == 1)
- push_val (st->stack, ScriptCode::INT, gc->Ghp7);
- else
- push_val (st->stack, ScriptCode::INT, -1);
-
- return 0;
+ push_val(st->stack, ScriptCode::INT, 1);
}
/*==========================================
* IDã‹ã‚‰Itemå
*------------------------------------------
*/
-int buildin_getitemname (struct script_state *st)
+static
+void builtin_getitemname(ScriptState *st)
{
struct item_data *i_data;
char *item_name;
struct script_data *data;
data = &(st->stack->stack_data[st->start + 2]);
- get_val (st, data);
+ get_val(st, data);
if (data->type == ScriptCode::STR || data->type == ScriptCode::CONSTSTR)
{
- const char *name = conv_str (st, data);
- i_data = itemdb_searchname (name);
+ const char *name = conv_str(st, data);
+ i_data = itemdb_searchname(name);
}
else
{
- int item_id = conv_num (st, data);
- i_data = itemdb_search (item_id);
+ int item_id = conv_num(st, data);
+ i_data = itemdb_search(item_id);
}
- item_name = (char *) calloc (24, 1);
+ item_name = (char *) calloc(24, 1);
if (i_data)
- strncpy (item_name, i_data->jname, 23);
+ strncpy(item_name, i_data->jname, 23);
else
- strncpy (item_name, "Unknown Item", 23);
+ strncpy(item_name, "Unknown Item", 23);
- push_str (st->stack, ScriptCode::STR, item_name);
+ push_str(st->stack, ScriptCode::STR, item_name);
- return 0;
}
-int buildin_getspellinvocation (struct script_state *st)
-{
- const char *name = conv_str (st, &(st->stack->stack_data[st->start + 2]));
-
- const char *invocation = magic_find_invocation (name);
- if (!invocation)
- invocation = "...";
-
- push_str (st->stack, ScriptCode::STR, strdup (invocation));
- return 0;
-}
-
-int buildin_getanchorinvocation (struct script_state *st)
+static
+void builtin_getspellinvocation(ScriptState *st)
{
- const char *name = conv_str (st, &(st->stack->stack_data[st->start + 2]));
+ const char *name = conv_str(st, &(st->stack->stack_data[st->start + 2]));
- const char *invocation = magic_find_anchor_invocation (name);
+ const char *invocation = magic_find_invocation(name);
if (!invocation)
invocation = "...";
- push_str (st->stack, ScriptCode::STR, strdup (invocation));
- return 0;
+ push_str(st->stack, ScriptCode::STR, strdup(invocation));
}
-int buildin_getpartnerid (struct script_state *st)
+static
+void builtin_getpartnerid2(ScriptState *st)
{
- struct map_session_data *sd = script_rid2sd (st);
+ struct map_session_data *sd = script_rid2sd(st);
- push_val (st->stack, ScriptCode::INT, sd->status.partner_id);
- return 0;
+ push_val(st->stack, ScriptCode::INT, sd->status.partner_id);
}
/*==========================================
* PCã®æ‰€æŒå“情報読ã¿å–ã‚Š
*------------------------------------------
*/
-int buildin_getinventorylist (struct script_state *st)
+static
+void builtin_getinventorylist(ScriptState *st)
{
- struct map_session_data *sd = script_rid2sd (st);
- int i, j = 0;
+ struct map_session_data *sd = script_rid2sd(st);
+ int i, j = 0;
if (!sd)
- return 0;
+ return;
for (i = 0; i < MAX_INVENTORY; i++)
{
if (sd->status.inventory[i].nameid > 0
&& sd->status.inventory[i].amount > 0)
{
- pc_setreg (sd, add_str ("@inventorylist_id") + (j << 24),
+ pc_setreg(sd, add_str("@inventorylist_id") + (j << 24),
sd->status.inventory[i].nameid);
- pc_setreg (sd, add_str ("@inventorylist_amount") + (j << 24),
+ pc_setreg(sd, add_str("@inventorylist_amount") + (j << 24),
sd->status.inventory[i].amount);
- pc_setreg (sd, add_str ("@inventorylist_equip") + (j << 24),
- sd->status.inventory[i].equip);
- pc_setreg (sd, add_str ("@inventorylist_refine") + (j << 24),
+ pc_setreg(sd, add_str("@inventorylist_equip") + (j << 24),
+ uint16_t(sd->status.inventory[i].equip));
+ pc_setreg(sd, add_str("@inventorylist_refine") + (j << 24),
sd->status.inventory[i].refine);
- pc_setreg (sd, add_str ("@inventorylist_identify") + (j << 24),
+ pc_setreg(sd, add_str("@inventorylist_identify") + (j << 24),
sd->status.inventory[i].identify);
- pc_setreg (sd, add_str ("@inventorylist_attribute") + (j << 24),
+ pc_setreg(sd, add_str("@inventorylist_attribute") + (j << 24),
sd->status.inventory[i].attribute);
- pc_setreg (sd, add_str ("@inventorylist_card1") + (j << 24),
+ pc_setreg(sd, add_str("@inventorylist_card1") + (j << 24),
sd->status.inventory[i].card[0]);
- pc_setreg (sd, add_str ("@inventorylist_card2") + (j << 24),
+ pc_setreg(sd, add_str("@inventorylist_card2") + (j << 24),
sd->status.inventory[i].card[1]);
- pc_setreg (sd, add_str ("@inventorylist_card3") + (j << 24),
+ pc_setreg(sd, add_str("@inventorylist_card3") + (j << 24),
sd->status.inventory[i].card[2]);
- pc_setreg (sd, add_str ("@inventorylist_card4") + (j << 24),
+ pc_setreg(sd, add_str("@inventorylist_card4") + (j << 24),
sd->status.inventory[i].card[3]);
j++;
}
}
- pc_setreg (sd, add_str ("@inventorylist_count"), j);
- return 0;
-}
-
-int buildin_getskilllist (struct script_state *st)
-{
- struct map_session_data *sd = script_rid2sd (st);
- int i, j = 0;
- if (!sd)
- return 0;
- for (i = 0; i < MAX_SKILL; i++)
- {
- if (sd->status.skill[i].id > 0 && sd->status.skill[i].lv > 0)
- {
- pc_setreg (sd, add_str ("@skilllist_id") + (j << 24),
- sd->status.skill[i].id);
- pc_setreg (sd, add_str ("@skilllist_lv") + (j << 24),
- sd->status.skill[i].lv);
- pc_setreg (sd, add_str ("@skilllist_flag") + (j << 24),
- sd->status.skill[i].flags);
- j++;
- }
- }
- pc_setreg (sd, add_str ("@skilllist_count"), j);
- return 0;
+ pc_setreg(sd, add_str("@inventorylist_count"), j);
}
-int buildin_get_activated_pool_skills (struct script_state *st)
+static
+void builtin_getactivatedpoolskilllist(ScriptState *st)
{
- struct map_session_data *sd = script_rid2sd (st);
- int pool_skills[MAX_SKILL_POOL];
- int skill_pool_size = skill_pool (sd, pool_skills);
- int i, count = 0;
+ struct map_session_data *sd = script_rid2sd(st);
+ SkillID pool_skills[MAX_SKILL_POOL];
+ int skill_pool_size = skill_pool(sd, pool_skills);
+ int i, count = 0;
if (!sd)
- return 0;
+ return;
for (i = 0; i < skill_pool_size; i++)
{
- int skill_id = pool_skills[i];
-
- if (sd->status.skill[skill_id].id == skill_id)
- {
- pc_setreg (sd, add_str ("@skilllist_id") + (count << 24),
- sd->status.skill[skill_id].id);
- pc_setreg (sd, add_str ("@skilllist_lv") + (count << 24),
- sd->status.skill[skill_id].lv);
- pc_setreg (sd, add_str ("@skilllist_flag") + (count << 24),
- sd->status.skill[skill_id].flags);
- pc_setregstr (sd, add_str ("@skilllist_name$") + (count << 24),
- skill_name (skill_id));
- ++count;
- }
- }
- pc_setreg (sd, add_str ("@skilllist_count"), count);
-
- return 0;
-}
-
-extern int skill_pool_skills[];
-extern int skill_pool_skills_size;
-
-int buildin_get_unactivated_pool_skills (struct script_state *st)
-{
- struct map_session_data *sd = script_rid2sd (st);
- int i, count = 0;
-
- if (!sd)
- return 0;
-
- for (i = 0; i < skill_pool_skills_size; i++)
- {
- int skill_id = skill_pool_skills[i];
+ SkillID skill_id = pool_skills[i];
- if (sd->status.skill[skill_id].id == skill_id && !(sd->status.skill[skill_id].flags & SKILL_POOL_ACTIVATED))
+ if (sd->status.skill[skill_id].lv)
{
- pc_setreg (sd, add_str ("@skilllist_id") + (count << 24),
- sd->status.skill[skill_id].id);
- pc_setreg (sd, add_str ("@skilllist_lv") + (count << 24),
- sd->status.skill[skill_id].lv);
- pc_setreg (sd, add_str ("@skilllist_flag") + (count << 24),
- sd->status.skill[skill_id].flags);
- pc_setregstr (sd, add_str ("@skilllist_name$") + (count << 24),
- skill_name (skill_id));
+ pc_setreg(sd, add_str("@skilllist_id") + (count << 24),
+ static_cast<uint16_t>(skill_id));
+ pc_setreg(sd, add_str("@skilllist_lv") + (count << 24),
+ sd->status.skill[skill_id].lv);
+ pc_setreg(sd, add_str("@skilllist_flag") + (count << 24),
+ static_cast<uint16_t>(sd->status.skill[skill_id].flags));
+ pc_setregstr(sd, add_str("@skilllist_name$") + (count << 24),
+ skill_name(skill_id));
++count;
}
}
- pc_setreg (sd, add_str ("@skilllist_count"), count);
+ pc_setreg(sd, add_str("@skilllist_count"), count);
- return 0;
}
-int buildin_get_pool_skills (struct script_state *st)
+static
+void builtin_getunactivatedpoolskilllist(ScriptState *st)
{
- struct map_session_data *sd = script_rid2sd (st);
- int i, count = 0;
+ struct map_session_data *sd = script_rid2sd(st);
+ int i, count = 0;
if (!sd)
- return 0;
+ return;
for (i = 0; i < skill_pool_skills_size; i++)
{
- int skill_id = skill_pool_skills[i];
+ SkillID skill_id = skill_pool_skills[i];
- if (sd->status.skill[skill_id].id == skill_id)
+ if (sd->status.skill[skill_id].lv
+ && !bool(sd->status.skill[skill_id].flags & SkillFlags::POOL_ACTIVATED))
{
- pc_setreg (sd, add_str ("@skilllist_id") + (count << 24),
- sd->status.skill[skill_id].id);
- pc_setreg (sd, add_str ("@skilllist_lv") + (count << 24),
- sd->status.skill[skill_id].lv);
- pc_setreg (sd, add_str ("@skilllist_flag") + (count << 24),
- sd->status.skill[skill_id].flags);
- pc_setregstr (sd, add_str ("@skilllist_name$") + (count << 24),
- skill_name (skill_id));
+ pc_setreg(sd, add_str("@skilllist_id") + (count << 24),
+ static_cast<uint16_t>(skill_id));
+ pc_setreg(sd, add_str("@skilllist_lv") + (count << 24),
+ sd->status.skill[skill_id].lv);
+ pc_setreg(sd, add_str("@skilllist_flag") + (count << 24),
+ static_cast<uint16_t>(sd->status.skill[skill_id].flags));
+ pc_setregstr(sd, add_str("@skilllist_name$") + (count << 24),
+ skill_name(skill_id));
++count;
}
}
- pc_setreg (sd, add_str ("@skilllist_count"), count);
-
- return 0;
+ pc_setreg(sd, add_str("@skilllist_count"), count);
}
-int buildin_activate_pool_skill (struct script_state *st)
-{
- struct map_session_data *sd = script_rid2sd (st);
- int skill_id = conv_num (st, &(st->stack->stack_data[st->start + 2]));
-
- skill_pool_activate (sd, skill_id);
- clif_skillinfoblock (sd);
-
- return 0;
-}
-
-int buildin_deactivate_pool_skill (struct script_state *st)
-{
- struct map_session_data *sd = script_rid2sd (st);
- int skill_id = conv_num (st, &(st->stack->stack_data[st->start + 2]));
-
- skill_pool_deactivate (sd, skill_id);
- clif_skillinfoblock (sd);
-
- return 0;
-}
-
-int buildin_check_pool_skill (struct script_state *st)
+static
+void builtin_poolskill(ScriptState *st)
{
- struct map_session_data *sd = script_rid2sd (st);
- int skill_id = conv_num (st, &(st->stack->stack_data[st->start + 2]));
+ struct map_session_data *sd = script_rid2sd(st);
+ SkillID skill_id = SkillID(conv_num(st, &(st->stack->stack_data[st->start + 2])));
- push_val (st->stack, ScriptCode::INT, skill_pool_is_activated (sd, skill_id));
+ skill_pool_activate(sd, skill_id);
+ clif_skillinfoblock(sd);
- return 0;
-}
-
-int buildin_clearitem (struct script_state *st)
-{
- struct map_session_data *sd = script_rid2sd (st);
- int i;
- if (sd == NULL)
- return 0;
- for (i = 0; i < MAX_INVENTORY; i++)
- {
- if (sd->status.inventory[i].amount)
- pc_delitem (sd, i, sd->status.inventory[i].amount, 0);
- }
- return 0;
}
-/*==========================================
- * NPCクラスãƒã‚§ãƒ³ã‚¸
- * classã¯å¤‰ã‚ã‚ŠãŸã„class
- * typeã¯é€šå¸¸0ãªã®ã‹ãªï¼Ÿ
- *------------------------------------------
- */
-int buildin_classchange (struct script_state *st)
+static
+void builtin_unpoolskill(ScriptState *st)
{
- int npc_class, type;
- struct block_list *bl = map_id2bl (st->oid);
+ struct map_session_data *sd = script_rid2sd(st);
+ SkillID skill_id = SkillID(conv_num(st, &(st->stack->stack_data[st->start + 2])));
- if (bl == NULL)
- return 0;
+ skill_pool_deactivate(sd, skill_id);
+ clif_skillinfoblock(sd);
- npc_class = conv_num (st, &(st->stack->stack_data[st->start + 2]));
- type = conv_num (st, &(st->stack->stack_data[st->start + 3]));
- clif_npc_class_change (bl, npc_class, type);
- return 0;
}
/*==========================================
@@ -6723,123 +3909,82 @@ int buildin_classchange (struct script_state *st)
* the current NPC or invoking PC.
*------------------------------------------
*/
-int buildin_misceffect (struct script_state *st)
+static
+void builtin_misceffect(ScriptState *st)
{
- int type;
- int id = 0;
+ int type;
+ int id = 0;
const char *name = NULL;
struct block_list *bl = NULL;
- type = conv_num (st, &(st->stack->stack_data[st->start + 2]));
+ type = conv_num(st, &(st->stack->stack_data[st->start + 2]));
if (st->end > st->start + 3)
{
struct script_data *sdata = &(st->stack->stack_data[st->start + 3]);
- get_val (st, sdata);
+ get_val(st, sdata);
if (sdata->type == ScriptCode::STR || sdata->type == ScriptCode::CONSTSTR)
- name = conv_str (st, sdata);
+ name = conv_str(st, sdata);
else
- id = conv_num (st, sdata);
+ id = conv_num(st, sdata);
}
if (name)
{
- struct map_session_data *sd = map_nick2sd (name);
+ struct map_session_data *sd = map_nick2sd(name);
if (sd)
bl = &sd->bl;
}
else if (id)
- bl = map_id2bl (id);
+ bl = map_id2bl(id);
else if (st->oid)
- bl = map_id2bl (st->oid);
+ bl = map_id2bl(st->oid);
else
{
- struct map_session_data *sd = script_rid2sd (st);
+ struct map_session_data *sd = script_rid2sd(st);
if (sd)
bl = &sd->bl;
}
if (bl)
- clif_misceffect (bl, type);
+ clif_misceffect(bl, type);
- return 0;
-}
-
-/*==========================================
- * サウンドエフェクト
- *------------------------------------------
- */
-int buildin_soundeffect (struct script_state *st)
-{
- struct map_session_data *sd = script_rid2sd (st);
- int type = 0;
-
- const char *name = conv_str (st, &(st->stack->stack_data[st->start + 2]));
- type = conv_num (st, &(st->stack->stack_data[st->start + 3]));
- if (sd)
- {
- if (st->oid)
- clif_soundeffect (sd, map_id2bl (st->oid), name, type);
- else
- {
- clif_soundeffect (sd, &sd->bl, name, type);
- }
- }
- return 0;
-}
-
-/*==========================================
- * NPC skill effects [Valaris]
- *------------------------------------------
- */
-int buildin_npcskilleffect (struct script_state *st)
-{
- struct npc_data *nd = (struct npc_data *) map_id2bl (st->oid);
-
- int skillid = conv_num (st, &(st->stack->stack_data[st->start + 2]));
- int skilllv = conv_num (st, &(st->stack->stack_data[st->start + 3]));
- int x = conv_num (st, &(st->stack->stack_data[st->start + 4]));
- int y = conv_num (st, &(st->stack->stack_data[st->start + 5]));
-
- clif_skill_poseffect (&nd->bl, skillid, skilllv, x, y, gettick ());
-
- return 0;
}
/*==========================================
* Special effects [Valaris]
*------------------------------------------
*/
-int buildin_specialeffect (struct script_state *st)
+static
+void builtin_specialeffect(ScriptState *st)
{
- struct block_list *bl = map_id2bl (st->oid);
+ struct block_list *bl = map_id2bl(st->oid);
if (bl == NULL)
- return 0;
+ return;
- clif_specialeffect (bl,
- conv_num (st,
+ clif_specialeffect(bl,
+ conv_num(st,
&(st->stack->stack_data[st->start + 2])),
0);
- return 0;
}
-int buildin_specialeffect2 (struct script_state *st)
+static
+void builtin_specialeffect2(ScriptState *st)
{
- struct map_session_data *sd = script_rid2sd (st);
+ struct map_session_data *sd = script_rid2sd(st);
if (sd == NULL)
- return 0;
+ return;
- clif_specialeffect (&sd->bl,
- conv_num (st,
+ clif_specialeffect(&sd->bl,
+ conv_num(st,
&(st->stack->stack_data[st->start + 2])),
0);
- return 0;
}
/*==========================================
@@ -6847,20 +3992,19 @@ int buildin_specialeffect2 (struct script_state *st)
*------------------------------------------
*/
-int buildin_nude (struct script_state *st)
+static
+void builtin_nude(ScriptState *st)
{
- struct map_session_data *sd = script_rid2sd (st);
- int i;
+ struct map_session_data *sd = script_rid2sd(st);
if (sd == NULL)
- return 0;
+ return;
- for (i = 0; i < 11; i++)
+ for (EQUIP i : EQUIPs)
if (sd->equip_index[i] >= 0)
- pc_unequipitem (sd, sd->equip_index[i], i);
- pc_calcstatus (sd, 0);
+ pc_unequipitem(sd, sd->equip_index[i], CalcStatus::LATER);
+ pc_calcstatus(sd, 0);
- return 0;
}
/*==========================================
@@ -6868,20 +4012,21 @@ int buildin_nude (struct script_state *st)
*------------------------------------------
*/
-int buildin_unequip_by_id (struct script_state *st)
+static
+void builtin_unequipbyid(ScriptState *st)
{
- struct map_session_data *sd = script_rid2sd (st);
+ struct map_session_data *sd = script_rid2sd(st);
if (sd == NULL)
- return 0;
+ return;
- int slot_id = conv_num (st, &(st->stack->stack_data[st->start + 2]));
+ EQUIP slot_id = EQUIP(conv_num(st, &(st->stack->stack_data[st->start + 2])));
- if (slot_id >= 0 && slot_id < 11 && sd->equip_index[slot_id] >= 0)
- pc_unequipitem (sd, sd->equip_index[slot_id], slot_id);
+ if (slot_id >= EQUIP() && slot_id < EQUIP::COUNT
+ && sd->equip_index[slot_id] >= 0)
+ pc_unequipitem(sd, sd->equip_index[slot_id], CalcStatus::LATER);
- pc_calcstatus (sd, 0);
+ pc_calcstatus(sd, 0);
- return 0;
}
/*==========================================
@@ -6891,36 +4036,16 @@ int buildin_unequip_by_id (struct script_state *st)
*------------------------------------------
*/
-int buildin_gmcommand (struct script_state *st)
-{
- struct map_session_data *sd;
-
- sd = script_rid2sd (st);
- const char *cmd = conv_str (st, &(st->stack->stack_data[st->start + 2]));
-
- is_atcommand (sd->fd, sd, cmd, 99);
-
- return 0;
-}
-
-/*==========================================
- * movenpc [MouseJstr]
- *------------------------------------------
- */
-
-int buildin_movenpc (struct script_state *st)
+static
+void builtin_gmcommand(ScriptState *st)
{
struct map_session_data *sd;
- int x, y;
- sd = script_rid2sd (st);
+ sd = script_rid2sd(st);
+ const char *cmd = conv_str(st, &(st->stack->stack_data[st->start + 2]));
- const char *mapname = conv_str (st, &(st->stack->stack_data[st->start + 2]));
- x = conv_num (st, &(st->stack->stack_data[st->start + 3]));
- y = conv_num (st, &(st->stack->stack_data[st->start + 4]));
- const char *npc = conv_str (st, &(st->stack->stack_data[st->start + 5]));
+ is_atcommand(sd->fd, sd, cmd, 99);
- return 0;
}
/*==========================================
@@ -6928,18 +4053,19 @@ int buildin_movenpc (struct script_state *st)
* Move NPC to a new position on the same map.
*------------------------------------------
*/
-int buildin_npcwarp (struct script_state *st)
+static
+void builtin_npcwarp(ScriptState *st)
{
- int x, y;
+ int x, y;
struct npc_data *nd = NULL;
- x = conv_num (st, &(st->stack->stack_data[st->start + 2]));
- y = conv_num (st, &(st->stack->stack_data[st->start + 3]));
- const char *npc = conv_str (st, &(st->stack->stack_data[st->start + 4]));
- nd = npc_name2id (npc);
+ x = conv_num(st, &(st->stack->stack_data[st->start + 2]));
+ y = conv_num(st, &(st->stack->stack_data[st->start + 3]));
+ const char *npc = conv_str(st, &(st->stack->stack_data[st->start + 4]));
+ nd = npc_name2id(npc);
if (!nd)
- return -1;
+ return;
short m = nd->bl.m;
@@ -6947,16 +4073,15 @@ int buildin_npcwarp (struct script_state *st)
if (m < 0 || !nd->bl.prev
|| x < 0 || x > map[m].xs -1
|| y < 0 || y > map[m].ys - 1)
- return -1;
+ return;
- npc_enable (npc, 0);
+ npc_enable(npc, 0);
map_delblock(&nd->bl); /* [Freeyorp] */
nd->bl.x = x;
nd->bl.y = y;
map_addblock(&nd->bl);
- npc_enable (npc, 1);
+ npc_enable(npc, 1);
- return 0;
}
/*==========================================
@@ -6964,18 +4089,18 @@ int buildin_npcwarp (struct script_state *st)
*------------------------------------------
*/
-int buildin_message (struct script_state *st)
+static
+void builtin_message(ScriptState *st)
{
struct map_session_data *pl_sd = NULL;
- const char *player = conv_str (st, &(st->stack->stack_data[st->start + 2]));
- const char *msg = conv_str (st, &(st->stack->stack_data[st->start + 3]));
+ const char *player = conv_str(st, &(st->stack->stack_data[st->start + 2]));
+ const char *msg = conv_str(st, &(st->stack->stack_data[st->start + 3]));
- if ((pl_sd = map_nick2sd ((char *) player)) == NULL)
- return 1;
- clif_displaymessage (pl_sd->fd, msg);
+ if ((pl_sd = map_nick2sd(player)) == NULL)
+ return;
+ clif_displaymessage(pl_sd->fd, msg);
- return 0;
}
/*==========================================
@@ -6984,129 +4109,99 @@ int buildin_message (struct script_state *st)
*------------------------------------------
*/
-int buildin_npctalk (struct script_state *st)
+static
+void builtin_npctalk(ScriptState *st)
{
char message[255];
- struct npc_data *nd = (struct npc_data *) map_id2bl (st->oid);
- const char *str = conv_str (st, &(st->stack->stack_data[st->start + 2]));
+ struct npc_data *nd = (struct npc_data *) map_id2bl(st->oid);
+ const char *str = conv_str(st, &(st->stack->stack_data[st->start + 2]));
if (nd)
{
- memcpy (message, nd->name, 24);
- strcat (message, " : ");
- strcat (message, str);
- clif_message (&(nd->bl), message);
- }
-
- return 0;
-}
-
-/*==========================================
- * hasitems (checks to see if player has any
- * items on them, if so will return a 1)
- * [Valaris]
- *------------------------------------------
- */
-
-int buildin_hasitems (struct script_state *st)
-{
- int i;
- struct map_session_data *sd;
-
- sd = script_rid2sd (st);
-
- for (i = 0; i < MAX_INVENTORY; i++)
- {
- if (sd->status.inventory[i].amount)
- {
- push_val (st->stack, ScriptCode::INT, 1);
- return 0;
- }
+ memcpy(message, nd->name, 24);
+ strcat(message, " : ");
+ strcat(message, str);
+ clif_message(&nd->bl, message);
}
- push_val (st->stack, ScriptCode::INT, 0);
-
- return 0;
}
/*==========================================
* getlook char info. getlook(arg)
*------------------------------------------
*/
-int buildin_getlook (struct script_state *st)
+static
+void builtin_getlook(ScriptState *st)
{
- int type, val;
- struct map_session_data *sd;
- sd = script_rid2sd (st);
+ struct map_session_data *sd = script_rid2sd(st);
- type = conv_num (st, &(st->stack->stack_data[st->start + 2]));
- val = -1;
+ LOOK type = LOOK(conv_num(st, &(st->stack->stack_data[st->start + 2])));
+ int val = -1;
switch (type)
{
- case LOOK_HAIR: //1
+ case LOOK::HAIR: //1
val = sd->status.hair;
break;
- case LOOK_WEAPON: //2
- val = sd->status.weapon;
+ case LOOK::WEAPON: //2
+ val = static_cast<uint16_t>(sd->status.weapon);
break;
- case LOOK_HEAD_BOTTOM: //3
+ case LOOK::HEAD_BOTTOM: //3
val = sd->status.head_bottom;
break;
- case LOOK_HEAD_TOP: //4
+ case LOOK::HEAD_TOP: //4
val = sd->status.head_top;
break;
- case LOOK_HEAD_MID: //5
+ case LOOK::HEAD_MID: //5
val = sd->status.head_mid;
break;
- case LOOK_HAIR_COLOR: //6
+ case LOOK::HAIR_COLOR: //6
val = sd->status.hair_color;
break;
- case LOOK_CLOTHES_COLOR: //7
+ case LOOK::CLOTHES_COLOR: //7
val = sd->status.clothes_color;
break;
- case LOOK_SHIELD: //8
+ case LOOK::SHIELD: //8
val = sd->status.shield;
break;
- case LOOK_SHOES: //9
+ case LOOK::SHOES: //9
break;
}
- push_val (st->stack, ScriptCode::INT, val);
- return 0;
+ push_val(st->stack, ScriptCode::INT, val);
}
/*==========================================
* get char save point. argument: 0- map name, 1- x, 2- y
*------------------------------------------
*/
-int buildin_getsavepoint (struct script_state *st)
+static
+void builtin_getsavepoint(ScriptState *st)
{
- int x, y, type;
+ int x, y, type;
char *mapname;
struct map_session_data *sd;
- sd = script_rid2sd (st);
+ sd = script_rid2sd(st);
- type = conv_num (st, &(st->stack->stack_data[st->start + 2]));
+ type = conv_num(st, &(st->stack->stack_data[st->start + 2]));
x = sd->status.save_point.x;
y = sd->status.save_point.y;
switch (type)
{
case 0:
- mapname = (char*)calloc (24, 1);
- strncpy (mapname, sd->status.save_point.map, 23);
- push_str (st->stack, ScriptCode::STR, mapname);
+ mapname = (char*)calloc(24, 1);
+ strncpy(mapname, sd->status.save_point.map, 23);
+ push_str(st->stack, ScriptCode::STR, mapname);
break;
case 1:
- push_val (st->stack, ScriptCode::INT, x);
+ push_val(st->stack, ScriptCode::INT, x);
break;
case 2:
- push_val (st->stack, ScriptCode::INT, y);
+ push_val(st->stack, ScriptCode::INT, y);
break;
}
- return 0;
}
/*==========================================
@@ -7114,142 +4209,144 @@ int buildin_getsavepoint (struct script_state *st)
*------------------------------------------
*/
static
-int buildin_areatimer_sub (struct block_list *bl, va_list ap)
+void builtin_areatimer_sub(struct block_list *bl, interval_t tick, const char *event)
{
- int tick;
- char *event;
- tick = va_arg (ap, int);
- event = va_arg (ap, char *);
- pc_addeventtimer ((struct map_session_data *) bl, tick, event);
- return 0;
+ pc_addeventtimer((struct map_session_data *) bl, tick, event);
}
-int buildin_areatimer (struct script_state *st)
+static
+void builtin_areatimer(ScriptState *st)
{
- int tick, m;
- int x0, y0, x1, y1;
+ int m;
+ int x0, y0, x1, y1;
- const char *mapname = conv_str (st, &(st->stack->stack_data[st->start + 2]));
- x0 = conv_num (st, &(st->stack->stack_data[st->start + 3]));
- y0 = conv_num (st, &(st->stack->stack_data[st->start + 4]));
- x1 = conv_num (st, &(st->stack->stack_data[st->start + 5]));
- y1 = conv_num (st, &(st->stack->stack_data[st->start + 6]));
- tick = conv_num (st, &(st->stack->stack_data[st->start + 7]));
- const char *event = conv_str (st, &(st->stack->stack_data[st->start + 8]));
+ const char *mapname = conv_str(st, &(st->stack->stack_data[st->start + 2]));
+ x0 = conv_num(st, &(st->stack->stack_data[st->start + 3]));
+ y0 = conv_num(st, &(st->stack->stack_data[st->start + 4]));
+ x1 = conv_num(st, &(st->stack->stack_data[st->start + 5]));
+ y1 = conv_num(st, &(st->stack->stack_data[st->start + 6]));
+ interval_t tick = static_cast<interval_t>(conv_num(st, &(st->stack->stack_data[st->start + 7])));
+ const char *event = conv_str(st, &(st->stack->stack_data[st->start + 8]));
- if ((m = map_mapname2mapid (mapname)) < 0)
- return 0;
+ if ((m = map_mapname2mapid(mapname)) < 0)
+ return;
- map_foreachinarea (buildin_areatimer_sub,
- m, x0, y0, x1, y1, BL_PC, tick, event);
- return 0;
+ map_foreachinarea(std::bind(builtin_areatimer_sub, ph::_1, tick, event),
+ m, x0, y0, x1, y1, BL::PC);
}
/*==========================================
* Check whether the PC is in the specified rectangle
*------------------------------------------
*/
-int buildin_isin (struct script_state *st)
+static
+void builtin_isin(ScriptState *st)
{
- int x1, y1, x2, y2;
- struct map_session_data *sd = script_rid2sd (st);
+ int x1, y1, x2, y2;
+ struct map_session_data *sd = script_rid2sd(st);
- const char *str = conv_str (st, &(st->stack->stack_data[st->start + 2]));
- x1 = conv_num (st, &(st->stack->stack_data[st->start + 3]));
- y1 = conv_num (st, &(st->stack->stack_data[st->start + 4]));
- x2 = conv_num (st, &(st->stack->stack_data[st->start + 5]));
- y2 = conv_num (st, &(st->stack->stack_data[st->start + 6]));
+ const char *str = conv_str(st, &(st->stack->stack_data[st->start + 2]));
+ x1 = conv_num(st, &(st->stack->stack_data[st->start + 3]));
+ y1 = conv_num(st, &(st->stack->stack_data[st->start + 4]));
+ x2 = conv_num(st, &(st->stack->stack_data[st->start + 5]));
+ y2 = conv_num(st, &(st->stack->stack_data[st->start + 6]));
if (!sd)
- return 1;
+ return;
- push_val (st->stack, ScriptCode::INT,
+ push_val(st->stack, ScriptCode::INT,
(sd->bl.x >= x1 && sd->bl.x <= x2)
&& (sd->bl.y >= y1 && sd->bl.y <= y2)
- && (!strcmp (str, map[sd->bl.m].name)));
+ && (!strcmp(str, map[sd->bl.m].name)));
- return 0;
}
// Trigger the shop on a (hopefully) nearby shop NPC
-int buildin_shop (struct script_state *st)
+static
+void builtin_shop(ScriptState *st)
{
- struct map_session_data *sd = script_rid2sd (st);
+ struct map_session_data *sd = script_rid2sd(st);
struct npc_data *nd;
if (!sd)
- return 1;
+ return;
- nd = npc_name2id (conv_str (st, &(st->stack->stack_data[st->start + 2])));
+ nd = npc_name2id(conv_str(st, &(st->stack->stack_data[st->start + 2])));
if (!nd)
- return 1;
+ return;
- buildin_close (st);
- clif_npcbuysell (sd, nd->bl.id);
- return 0;
+ builtin_close(st);
+ clif_npcbuysell(sd, nd->bl.id);
}
/*==========================================
* Check whether the PC is dead
*------------------------------------------
*/
-int buildin_isdead (struct script_state *st)
+static
+void builtin_isdead(ScriptState *st)
{
- struct map_session_data *sd = script_rid2sd (st);
+ struct map_session_data *sd = script_rid2sd(st);
- push_val (st->stack, ScriptCode::INT, pc_isdead (sd));
- return 0;
+ push_val(st->stack, ScriptCode::INT, pc_isdead(sd));
}
/*========================================
* Changes a NPC name, and sprite
*----------------------------------------
*/
-int buildin_fakenpcname (struct script_state *st)
+static
+void builtin_fakenpcname(ScriptState *st)
{
- int newsprite;
- struct npc_data *nd;
-
- const char *name = conv_str (st, &(st->stack->stack_data[st->start + 2]));
- const char *newname = conv_str (st, &(st->stack->stack_data[st->start + 3]));
- newsprite = conv_num (st, &(st->stack->stack_data[st->start + 4]));
- nd = npc_name2id (name);
+ const char *name = conv_str(st, &(st->stack->stack_data[st->start + 2]));
+ const char *newname = conv_str(st, &(st->stack->stack_data[st->start + 3]));
+ int newsprite = conv_num(st, &(st->stack->stack_data[st->start + 4]));
+ struct npc_data *nd = npc_name2id(name);
if (!nd)
- return 1;
- strncpy (nd->name, newname, sizeof(nd->name)-1);
- nd->name[sizeof(nd->name)-1] = '\0';
+ return;
+ strzcpy(nd->name, newname, sizeof(nd->name));
nd->npc_class = newsprite;
// Refresh this npc
- npc_enable (name, 0);
- npc_enable (name, 1);
+ npc_enable(name, 0);
+ npc_enable(name, 1);
- return 0;
}
/*============================
* Gets the PC's x pos
*----------------------------
*/
-
-int buildin_getx (struct script_state *st)
+static
+void builtin_getx(ScriptState *st)
{
- struct map_session_data *sd = script_rid2sd (st);
+ struct map_session_data *sd = script_rid2sd(st);
- push_val (st->stack, ScriptCode::INT, sd->bl.x);
- return 0;
+ push_val(st->stack, ScriptCode::INT, sd->bl.x);
}
/*============================
* Gets the PC's y pos
*----------------------------
*/
-int buildin_gety (struct script_state *st)
+static
+void builtin_gety(ScriptState *st)
{
- struct map_session_data *sd = script_rid2sd (st);
+ struct map_session_data *sd = script_rid2sd(st);
- push_val (st->stack, ScriptCode::INT, sd->bl.y);
- return 0;
+ push_val(st->stack, ScriptCode::INT, sd->bl.y);
+}
+
+/*
+ * Get the PC's current map's name
+ */
+static
+void builtin_getmap(ScriptState *st)
+{
+ struct map_session_data *sd = script_rid2sd(st);
+
+ // A map_data lives essentially forever.
+ push_str(st->stack, ScriptCode::CONSTSTR, map[sd->bl.m].name);
}
//
@@ -7260,7 +4357,7 @@ int buildin_gety (struct script_state *st)
*------------------------------------------
*/
static
-ScriptCode get_com (const ScriptCode *script, int *pos_)
+ScriptCode get_com(const ScriptCode *script, int *pos_)
{
if (static_cast<uint8_t>(script[*pos_]) >= 0x80)
{
@@ -7274,10 +4371,10 @@ ScriptCode get_com (const ScriptCode *script, int *pos_)
*------------------------------------------
*/
static
-int get_num (const ScriptCode *scr, int *pos_)
+int get_num(const ScriptCode *scr, int *pos_)
{
const uint8_t *script = reinterpret_cast<const uint8_t *>(scr);
- int i, j;
+ int i, j;
i = 0;
j = 0;
while (script[*pos_] >= 0xc0)
@@ -7293,35 +4390,40 @@ int get_num (const ScriptCode *scr, int *pos_)
*------------------------------------------
*/
static
-int pop_val (struct script_state *st)
+int pop_val(ScriptState *st)
{
if (st->stack->sp <= 0)
return 0;
st->stack->sp--;
- get_val (st, &(st->stack->stack_data[st->stack->sp]));
+ get_val(st, &(st->stack->stack_data[st->stack->sp]));
if (st->stack->stack_data[st->stack->sp].type == ScriptCode::INT)
return st->stack->stack_data[st->stack->sp].u.num;
return 0;
}
-#define isstr(c) ((c).type==ScriptCode::STR || (c).type==ScriptCode::CONSTSTR)
+static
+bool isstr(struct script_data& c)
+{
+ return c.type == ScriptCode::STR
+ || c.type == ScriptCode::CONSTSTR;
+}
/*==========================================
* 加算演算å­
*------------------------------------------
*/
static
-void op_add (struct script_state *st)
+void op_add(ScriptState *st)
{
st->stack->sp--;
- get_val (st, &(st->stack->stack_data[st->stack->sp]));
- get_val (st, &(st->stack->stack_data[st->stack->sp - 1]));
+ get_val(st, &(st->stack->stack_data[st->stack->sp]));
+ get_val(st, &(st->stack->stack_data[st->stack->sp - 1]));
- if (isstr (st->stack->stack_data[st->stack->sp])
- || isstr (st->stack->stack_data[st->stack->sp - 1]))
+ if (isstr(st->stack->stack_data[st->stack->sp])
+ || isstr(st->stack->stack_data[st->stack->sp - 1]))
{
- conv_str (st, &(st->stack->stack_data[st->stack->sp]));
- conv_str (st, &(st->stack->stack_data[st->stack->sp - 1]));
+ conv_str(st, &(st->stack->stack_data[st->stack->sp]));
+ conv_str(st, &(st->stack->stack_data[st->stack->sp - 1]));
}
if (st->stack->stack_data[st->stack->sp].type == ScriptCode::INT)
{ // ii
@@ -7332,11 +4434,11 @@ void op_add (struct script_state *st)
{ // ssã®äºˆå®š
char *buf;
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,
+ 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);
+ 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 == ScriptCode::STR)
free(const_cast<char *>(st->stack->stack_data[st->stack->sp - 1].u.str));
if (st->stack->stack_data[st->stack->sp].type == ScriptCode::STR)
@@ -7351,38 +4453,38 @@ void op_add (struct script_state *st)
*------------------------------------------
*/
static
-void op_2str (struct script_state *st, ScriptCode op, int sp1, int sp2)
+void op_2str(ScriptState *st, ScriptCode op, int sp1, int sp2)
{
const char *s1 = st->stack->stack_data[sp1].u.str;
const char *s2 = st->stack->stack_data[sp2].u.str;
- int a = 0;
+ int a = 0;
switch (op)
{
case ScriptCode::EQ:
- a = (strcmp (s1, s2) == 0);
+ a = (strcmp(s1, s2) == 0);
break;
case ScriptCode::NE:
- a = (strcmp (s1, s2) != 0);
+ a = (strcmp(s1, s2) != 0);
break;
case ScriptCode::GT:
- a = (strcmp (s1, s2) > 0);
+ a = (strcmp(s1, s2) > 0);
break;
case ScriptCode::GE:
- a = (strcmp (s1, s2) >= 0);
+ a = (strcmp(s1, s2) >= 0);
break;
case ScriptCode::LT:
- a = (strcmp (s1, s2) < 0);
+ a = (strcmp(s1, s2) < 0);
break;
case ScriptCode::LE:
- a = (strcmp (s1, s2) <= 0);
+ a = (strcmp(s1, s2) <= 0);
break;
default:
- printf ("illegal string operater\n");
+ PRINTF("illegal string operater\n");
break;
}
- push_val (st->stack, ScriptCode::INT, a);
+ push_val(st->stack, ScriptCode::INT, a);
if (st->stack->stack_data[sp1].type == ScriptCode::STR)
free(const_cast<char *>(s1));
@@ -7395,7 +4497,7 @@ void op_2str (struct script_state *st, ScriptCode op, int sp1, int sp2)
*------------------------------------------
*/
static
-void op_2num (struct script_state *st, ScriptCode op, int i1, int i2)
+void op_2num(ScriptState *st, ScriptCode op, int i1, int i2)
{
switch (op)
{
@@ -7451,7 +4553,7 @@ void op_2num (struct script_state *st, ScriptCode op, int i1, int i2)
i1 = i1 << i2;
break;
}
- push_val (st->stack, ScriptCode::INT, i1);
+ push_val(st->stack, ScriptCode::INT, i1);
}
/*==========================================
@@ -7459,34 +4561,34 @@ void op_2num (struct script_state *st, ScriptCode op, int i1, int i2)
*------------------------------------------
*/
static
-void op_2 (struct script_state *st, ScriptCode op)
+void op_2(ScriptState *st, ScriptCode op)
{
- int i1, i2;
+ int i1, i2;
const char *s1 = NULL, *s2 = NULL;
- i2 = pop_val (st);
- if (isstr (st->stack->stack_data[st->stack->sp]))
+ i2 = pop_val(st);
+ if (isstr(st->stack->stack_data[st->stack->sp]))
s2 = st->stack->stack_data[st->stack->sp].u.str;
- i1 = pop_val (st);
- if (isstr (st->stack->stack_data[st->stack->sp]))
+ i1 = pop_val(st);
+ if (isstr(st->stack->stack_data[st->stack->sp]))
s1 = st->stack->stack_data[st->stack->sp].u.str;
if (s1 != NULL && s2 != NULL)
{
// ss => op_2str
- op_2str (st, op, st->stack->sp, st->stack->sp + 1);
+ op_2str(st, op, st->stack->sp, st->stack->sp + 1);
}
else if (s1 == NULL && s2 == NULL)
{
// ii => op_2num
- op_2num (st, op, i1, i2);
+ op_2num(st, op, i1, i2);
}
else
{
// si,is => error
- printf ("script: op_2: int&str, str&int not allow.");
- push_val (st->stack, ScriptCode::INT, 0);
+ PRINTF("script: op_2: int&str, str&int not allow.");
+ push_val(st->stack, ScriptCode::INT, 0);
}
}
@@ -7495,10 +4597,10 @@ void op_2 (struct script_state *st, ScriptCode op)
*------------------------------------------
*/
static
-void op_1num (struct script_state *st, ScriptCode op)
+void op_1num(ScriptState *st, ScriptCode op)
{
- int i1;
- i1 = pop_val (st);
+ int i1;
+ i1 = pop_val(st);
switch (op)
{
case ScriptCode::NEG:
@@ -7511,16 +4613,16 @@ void op_1num (struct script_state *st, ScriptCode op)
i1 = !i1;
break;
}
- push_val (st->stack, ScriptCode::INT, i1);
+ push_val(st->stack, ScriptCode::INT, i1);
}
/*==========================================
* 関数ã®å®Ÿè¡Œ
*------------------------------------------
*/
-int run_func (struct script_state *st)
+void run_func(ScriptState *st)
{
- int i, start_sp, end_sp, func;
+ int i, start_sp, end_sp, func;
end_sp = st->stack->sp;
for (i = end_sp - 1; i >= 0 && st->stack->stack_data[i].type != ScriptCode::ARG;
@@ -7528,10 +4630,10 @@ int run_func (struct script_state *st)
if (i == 0)
{
if (battle_config.error_log)
- printf ("function not found\n");
+ PRINTF("function not found\n");
// st->stack->sp=0;
st->state = END;
- return 0;
+ return;
}
start_sp = i - 1;
st->start = i - 1;
@@ -7541,82 +4643,82 @@ int run_func (struct script_state *st)
if (st->stack->stack_data[st->start].type != ScriptCode::NAME
|| str_data[func].type != ScriptCode::FUNC)
{
- printf ("run_func: not function and command! \n");
+ PRINTF("run_func: not function and command! \n");
// st->stack->sp=0;
st->state = END;
- return 0;
+ return;
}
#ifdef DEBUG_RUN
if (battle_config.etc_log)
{
- printf ("run_func : %s? (%d(%d))\n", str_buf + str_data[func].str,
+ PRINTF("run_func : %s? (%d(%d))\n", str_buf + str_data[func].str,
func, str_data[func].type);
- printf ("stack dump :");
+ PRINTF("stack dump :");
for (i = 0; i < end_sp; i++)
{
switch (st->stack->stack_data[i].type)
{
case ScriptCode::INT:
- printf (" int(%d)", st->stack->stack_data[i].u.num);
+ PRINTF(" int(%d)", st->stack->stack_data[i].u.num);
break;
case ScriptCode::NAME:
- printf (" name(%s)",
+ PRINTF(" name(%s)",
str_buf +
str_data[st->stack->stack_data[i].u.num].str);
break;
case ScriptCode::ARG:
- printf (" arg");
+ PRINTF(" arg");
break;
case ScriptCode::POS:
- printf (" pos(%d)", st->stack->stack_data[i].u.num);
+ PRINTF(" pos(%d)", st->stack->stack_data[i].u.num);
break;
default:
- printf (" %d,%d", st->stack->stack_data[i].type,
+ PRINTF(" %d,%d", st->stack->stack_data[i].type,
st->stack->stack_data[i].u.num);
}
}
- printf ("\n");
+ PRINTF("\n");
}
#endif
if (str_data[func].func)
{
- str_data[func].func (st);
+ str_data[func].func(st);
}
else
{
if (battle_config.error_log)
- printf ("run_func : %s? (%d(%d))\n", str_buf + str_data[func].str,
+ PRINTF("run_func : %s? (%d(%d))\n", str_buf + str_data[func].str,
func, str_data[func].type);
- push_val (st->stack, ScriptCode::INT, 0);
+ push_val(st->stack, ScriptCode::INT, 0);
}
- pop_stack (st->stack, start_sp, end_sp);
+ pop_stack(st->stack, start_sp, end_sp);
if (st->state == RETFUNC)
{
// ユーザー定義関数ã‹ã‚‰ã®å¾©å¸°
- int olddefsp = st->defsp;
+ int olddefsp = st->defsp;
- pop_stack (st->stack, st->defsp, start_sp); // 復帰ã«é‚ªé­”ãªã‚¹ã‚¿ãƒƒã‚¯å‰Šé™¤
+ pop_stack(st->stack, st->defsp, start_sp); // 復帰ã«é‚ªé­”ãªã‚¹ã‚¿ãƒƒã‚¯å‰Šé™¤
if (st->defsp < 4
|| st->stack->stack_data[st->defsp - 1].type != ScriptCode::RETINFO)
{
- printf
- ("script:run_func(return) return without callfunc or callsub!\n");
+ PRINTF("script:run_func (return) return without callfunc or callsub!\n");
st->state = END;
- return 0;
+ return;
}
- i = conv_num (st, &(st->stack->stack_data[st->defsp - 4])); // 引数ã®æ•°æ‰€å¾—
- st->pos = conv_num (st, &(st->stack->stack_data[st->defsp - 1])); // スクリプトä½ç½®ã®å¾©å…ƒ
- st->script = (ScriptCode *) conv_num (st, &(st->stack->stack_data[st->defsp - 2])); // スクリプトを復元
- st->defsp = conv_num (st, &(st->stack->stack_data[st->defsp - 3])); // 基準スタックãƒã‚¤ãƒ³ã‚¿ã‚’復元
+ assert (olddefsp == st->defsp); // pretty sure it hasn't changed yet
+ st->script = conv_script(st, &(st->stack->stack_data[olddefsp - 1])); // スクリプトを復元
+ st->pos = conv_num(st, &(st->stack->stack_data[olddefsp - 2])); // スクリプトä½ç½®ã®å¾©å…ƒ
+ st->defsp = conv_num(st, &(st->stack->stack_data[olddefsp - 3])); // 基準スタックãƒã‚¤ãƒ³ã‚¿ã‚’復元
+ // Number of arguments.
+ i = conv_num(st, &(st->stack->stack_data[olddefsp - 4])); // 引数ã®æ•°æ‰€å¾—
+ assert (i == 0);
- pop_stack (st->stack, olddefsp - 4 - i, olddefsp); // è¦ã‚‰ãªããªã£ãŸã‚¹ã‚¿ãƒƒã‚¯(引数ã¨å¾©å¸°ç”¨ãƒ‡ãƒ¼ã‚¿)削除
+ pop_stack(st->stack, olddefsp - 4 - i, olddefsp); // è¦ã‚‰ãªããªã£ãŸã‚¹ã‚¿ãƒƒã‚¯(引数ã¨å¾©å¸°ç”¨ãƒ‡ãƒ¼ã‚¿)削除
st->state = GOTO;
}
-
- return 0;
}
/*==========================================
@@ -7624,12 +4726,12 @@ int run_func (struct script_state *st)
*------------------------------------------
*/
static
-int run_script_main (const ScriptCode *script, int pos_, int rid, int oid,
- struct script_state *st, const ScriptCode *rootscript)
+void run_script_main(const ScriptCode *script, int pos_, int, int,
+ ScriptState *st, const ScriptCode *rootscript)
{
int rerun_pos;
- int cmdcount = script_config.check_cmdcount;
- int gotocount = script_config.check_gotocount;
+ int cmdcount = script_config.check_cmdcount;
+ int gotocount = script_config.check_gotocount;
struct script_stack *stack = st->stack;
st->defsp = stack->sp;
@@ -7638,35 +4740,35 @@ int run_script_main (const ScriptCode *script, int pos_, int rid, int oid,
rerun_pos = st->pos;
for (st->state = 0; st->state == 0;)
{
- switch (ScriptCode c = get_com (script, &st->pos))
+ switch (ScriptCode c = get_com(script, &st->pos))
{
case ScriptCode::EOL:
if (stack->sp != st->defsp)
{
if (battle_config.error_log)
- printf ("stack.sp(%d) != default(%d)\n", stack->sp,
+ PRINTF("stack.sp (%d) != default (%d)\n", stack->sp,
st->defsp);
stack->sp = st->defsp;
}
rerun_pos = st->pos;
break;
case ScriptCode::INT:
- push_val (stack, ScriptCode::INT, get_num (script, &st->pos));
+ push_val(stack, ScriptCode::INT, get_num(script, &st->pos));
break;
case ScriptCode::POS:
case ScriptCode::NAME:
- push_val (stack, c, (*(int *) (script + st->pos)) & 0xffffff);
+ push_val(stack, c, (*(const int *)(script + st->pos)) & 0xffffff);
st->pos += 3;
break;
case ScriptCode::ARG:
- push_val (stack, c, 0);
+ push_val(stack, c, 0);
break;
case ScriptCode::STR:
- push_str (stack, ScriptCode::CONSTSTR, reinterpret_cast<const char *>(script + st->pos));
+ push_str(stack, ScriptCode::CONSTSTR, reinterpret_cast<const char *>(script + st->pos));
while (script[st->pos++] != ScriptCode::NOP);
break;
case ScriptCode::FUNC:
- run_func (st);
+ run_func(st);
if (st->state == GOTO)
{
rerun_pos = st->pos;
@@ -7674,14 +4776,14 @@ int run_script_main (const ScriptCode *script, int pos_, int rid, int oid,
st->state = 0;
if (gotocount > 0 && (--gotocount) <= 0)
{
- printf ("run_script: infinity loop !\n");
+ PRINTF("run_script: infinity loop !\n");
st->state = END;
}
}
break;
case ScriptCode::ADD:
- op_add (st);
+ op_add(st);
break;
case ScriptCode::SUB:
@@ -7701,13 +4803,13 @@ int run_script_main (const ScriptCode *script, int pos_, int rid, int oid,
case ScriptCode::LOR:
case ScriptCode::R_SHIFT:
case ScriptCode::L_SHIFT:
- op_2 (st, c);
+ op_2(st, c);
break;
case ScriptCode::NEG:
case ScriptCode::NOT:
case ScriptCode::LNOT:
- op_1num (st, c);
+ op_1num(st, c);
break;
case ScriptCode::NOP:
@@ -7716,13 +4818,13 @@ int run_script_main (const ScriptCode *script, int pos_, int rid, int oid,
default:
if (battle_config.error_log)
- printf ("unknown command : %d @ %d\n", c, pos_);
+ PRINTF("unknown command : %d @ %d\n", c, pos_);
st->state = END;
break;
}
if (cmdcount > 0 && (--cmdcount) <= 0)
{
- printf ("run_script: infinity loop !\n");
+ PRINTF("run_script: infinity loop !\n");
st->state = END;
}
}
@@ -7732,10 +4834,10 @@ int run_script_main (const ScriptCode *script, int pos_, int rid, int oid,
break;
case END:
{
- struct map_session_data *sd = map_id2sd (st->rid);
+ struct map_session_data *sd = map_id2sd(st->rid);
st->pos = -1;
if (sd && sd->npc_id == st->oid)
- npc_event_dequeue (sd);
+ npc_event_dequeue(sd);
}
break;
case RERUNLINE:
@@ -7748,15 +4850,15 @@ int run_script_main (const ScriptCode *script, int pos_, int rid, int oid,
if (st->state != END)
{
// å†é–‹ã™ã‚‹ãŸã‚ã«ã‚¹ã‚¿ãƒƒã‚¯æƒ…報をä¿å­˜
- struct map_session_data *sd = map_id2sd (st->rid);
+ struct map_session_data *sd = map_id2sd(st->rid);
if (sd /* && sd->npc_stackbuf==NULL */ )
{
if (sd->npc_stackbuf)
- free (sd->npc_stackbuf);
- 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);
+ free(sd->npc_stackbuf);
+ sd->npc_stackbuf = (struct script_data *)
+ 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;
sd->npc_stackmax = stack->sp_max;
sd->npc_script = script;
@@ -7764,26 +4866,25 @@ int run_script_main (const ScriptCode *script, int pos_, int rid, int oid,
}
}
- return 0;
}
/*==========================================
* スクリプトã®å®Ÿè¡Œ
*------------------------------------------
*/
-int run_script (const ScriptCode *script, int pos_, int rid, int oid)
+int run_script(const ScriptCode *script, int pos_, int rid, int oid)
{
- return run_script_l (script, pos_, rid, oid, 0, NULL);
+ return run_script_l(script, pos_, rid, oid, 0, NULL);
}
-int run_script_l (const ScriptCode *script, int pos_, int rid, int oid,
- int args_nr, argrec_t * args)
+int run_script_l(const ScriptCode *script, int pos_, int rid, int oid,
+ int args_nr, argrec_t *args)
{
struct script_stack stack;
- struct script_state st;
- struct map_session_data *sd = map_id2sd (rid);
+ ScriptState st;
+ struct map_session_data *sd = map_id2sd(rid);
const ScriptCode *rootscript = script;
- int i;
+ int i;
if (script == NULL || pos_ < 0)
return -1;
@@ -7794,10 +4895,10 @@ int run_script_l (const ScriptCode *script, int pos_, int rid, int oid,
stack.sp = sd->npc_stack;
stack.sp_max = sd->npc_stackmax;
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);
+ 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);
sd->npc_stackbuf = NULL;
}
else
@@ -7806,7 +4907,7 @@ int run_script_l (const ScriptCode *script, int pos_, int rid, int oid,
stack.sp = 0;
stack.sp_max = 64;
stack.stack_data = (struct script_data *)
- calloc (stack.sp_max, sizeof (stack.stack_data[0]));
+ calloc(stack.sp_max, sizeof(stack.stack_data[0]));
}
st.stack = &stack;
st.pos = pos_;
@@ -7814,14 +4915,14 @@ int run_script_l (const ScriptCode *script, int pos_, int rid, int oid,
st.oid = oid;
for (i = 0; i < args_nr; i++)
{
- if (args[i].name[strlen (args[i].name) - 1] == '$')
- pc_setregstr (sd, add_str (args[i].name), args[i].v.s);
+ if (args[i].name[strlen(args[i].name) - 1] == '$')
+ pc_setregstr(sd, add_str(args[i].name), args[i].v.s);
else
- pc_setreg (sd, add_str (args[i].name), args[i].v.i);
+ pc_setreg(sd, add_str(args[i].name), args[i].v.i);
}
- run_script_main (script, pos_, rid, oid, &st, rootscript);
+ run_script_main(script, pos_, rid, oid, &st, rootscript);
- free (stack.stack_data);
+ free(stack.stack_data);
stack.stack_data = NULL;
return st.pos;
}
@@ -7830,206 +4931,146 @@ int run_script_l (const ScriptCode *script, int pos_, int rid, int oid,
* マップ変数ã®å¤‰æ›´
*------------------------------------------
*/
-int mapreg_setreg (int num, int val)
+void mapreg_setreg(int num, int val)
{
- if (val != 0)
- numdb_insert (mapreg_db, num, val);
- else
- numdb_erase (mapreg_db, num);
+ mapreg_db.put(num, val);
mapreg_dirty = 1;
- return 0;
}
/*==========================================
* 文字列型マップ変数ã®å¤‰æ›´
*------------------------------------------
*/
-int mapreg_setregstr (int num, const char *str)
+void mapreg_setregstr(int num, const char *str)
{
- char *p;
+ char *p = mapregstr_db.get(num);
+ if (p)
+ free(p);
- if ((p = (char *)numdb_search (mapregstr_db, num)) != NULL)
- free (p);
+ if (!str || !*str)
+ p = NULL;
+ else
+ p = strdup(str);
- if (str == NULL || *str == 0)
- {
- numdb_erase (mapregstr_db, num);
- mapreg_dirty = 1;
- return 0;
- }
- p = (char *) calloc (strlen (str) + 1, 1);
- strcpy (p, str);
- numdb_insert (mapregstr_db, num, p);
+ mapregstr_db.put(num, p);
mapreg_dirty = 1;
- return 0;
}
/*==========================================
* 永続的マップ変数ã®èª­ã¿è¾¼ã¿
*------------------------------------------
*/
-static int script_load_mapreg (void)
+static
+void script_load_mapreg(void)
{
- FILE *fp;
- char line[1024];
+ std::ifstream in(mapreg_txt);
- if ((fp = fopen_ (mapreg_txt, "rt")) == NULL)
- return -1;
+ if (!in.is_open())
+ return;
- while (fgets (line, sizeof (line), fp))
- {
- char buf1[256], buf2[1024], *p;
- int n, v, s, i;
- if (sscanf (line, "%255[^,],%d\t%n", buf1, &i, &n) != 2 &&
- (i = 0, sscanf (line, "%[^\t]\t%n", buf1, &n) != 1))
- continue;
- if (buf1[strlen (buf1) - 1] == '$')
+ std::string line;
+ while (std::getline(in, line))
+ {
+ std::string buf1, buf2;
+ int index = 0;
+ if (extract(line,
+ record<'\t'>(
+ record<','>(&buf1, &index),
+ &buf2))
+ || extract(line,
+ record<'\t'>(
+ record<','>(&buf1),
+ &buf2)))
{
- if (sscanf (line + n, "%[^\n\r]", buf2) != 1)
+ int s = add_str(buf1.c_str());
+ int key = (index << 24) | s;
+ if (buf1.back() == '$')
{
- printf ("%s: %s broken data !\n", mapreg_txt, buf1);
- continue;
+ char *p = strdup(buf2.c_str());
+ mapregstr_db.put(key, p);
+ }
+ else
+ {
+ int v;
+ if (!extract(buf2, &v))
+ goto borken;
+ mapreg_db.put(key, v);
}
- p = (char *) calloc (strlen (buf2) + 1, 1);
- strcpy (p, buf2);
- s = add_str (buf1);
- numdb_insert (mapregstr_db, (i << 24) | s, p);
}
else
{
- if (sscanf (line + n, "%d", &v) != 1)
- {
- printf ("%s: %s broken data !\n", mapreg_txt, buf1);
- continue;
- }
- s = add_str (buf1);
- numdb_insert (mapreg_db, (i << 24) | s, v);
+ borken:
+ PRINTF("%s: %s broken data !\n", mapreg_txt, buf1);
+ continue;
}
}
- fclose_ (fp);
mapreg_dirty = 0;
- return 0;
}
/*==========================================
* 永続的マップ変数ã®æ›¸ãè¾¼ã¿
*------------------------------------------
*/
-static void script_save_mapreg_intsub (db_key_t key, db_val_t data, va_list ap)
+static
+void script_save_mapreg_intsub(int key, int data, FILE *fp)
{
- FILE *fp = va_arg (ap, FILE *);
- int num = key.i & 0x00ffffff, i = key.i >> 24;
+ int num = key & 0x00ffffff, i = key >> 24;
char *name = str_buf + str_data[num].str;
if (name[1] != '@')
{
if (i == 0)
- fprintf (fp, "%s\t%d\n", name, (int) data);
+ FPRINTF(fp, "%s\t%d\n", name, data);
else
- fprintf (fp, "%s,%d\t%d\n", name, i, (int) data);
+ FPRINTF(fp, "%s,%d\t%d\n", name, i, data);
}
}
-static void script_save_mapreg_strsub (db_key_t key, db_val_t data, va_list ap)
+static
+void script_save_mapreg_strsub(int key, char *data, FILE *fp)
{
- FILE *fp = va_arg (ap, FILE *);
- int num = key.i & 0x00ffffff, i = key.i >> 24;
+ int num = key & 0x00ffffff, i = key >> 24;
char *name = str_buf + str_data[num].str;
if (name[1] != '@')
{
if (i == 0)
- fprintf (fp, "%s\t%s\n", name, (char *) data);
+ FPRINTF(fp, "%s\t%s\n", name, data);
else
- fprintf (fp, "%s,%d\t%s\n", name, i, (char *) data);
+ FPRINTF(fp, "%s,%d\t%s\n", name, i, data);
}
}
-static int script_save_mapreg (void)
+static
+void script_save_mapreg(void)
{
FILE *fp;
- int lock;
+ int lock;
- if ((fp = lock_fopen (mapreg_txt, &lock)) == NULL)
- return -1;
- numdb_foreach (mapreg_db, script_save_mapreg_intsub, fp);
- numdb_foreach (mapregstr_db, script_save_mapreg_strsub, fp);
- lock_fclose (fp, mapreg_txt, &lock);
+ if ((fp = lock_fopen(mapreg_txt, &lock)) == NULL)
+ return;
+ for (auto& pair : mapreg_db)
+ script_save_mapreg_intsub(pair.first, pair.second, fp);
+ for (auto& pair : mapregstr_db)
+ script_save_mapreg_strsub(pair.first, pair.second, fp);
+ lock_fclose(fp, mapreg_txt, &lock);
mapreg_dirty = 0;
- return 0;
}
-static void script_autosave_mapreg (timer_id tid, tick_t tick, custom_id_t id,
- custom_data_t data)
+static
+void script_autosave_mapreg(TimerData *, tick_t)
{
if (mapreg_dirty)
- script_save_mapreg ();
+ script_save_mapreg();
}
-/*==========================================
- *
- *------------------------------------------
- */
-static int set_posword (char *p)
+void script_config_read()
{
- char *np, *str[15];
- int i = 0;
- for (i = 0; i < 11; i++)
- {
- if ((np = strchr (p, ',')) != NULL)
- {
- str[i] = p;
- *np = 0;
- p = np + 1;
- }
- else
- {
- str[i] = p;
- p += strlen (p);
- }
- if (str[i])
- strcpy (pos[i], str[i]);
- }
- return 0;
-}
-
-int script_config_read (const char *cfgName)
-{
- int i;
- char line[1024], w1[1024], w2[1024];
- FILE *fp;
-
script_config.warn_func_no_comma = 1;
script_config.warn_cmd_no_comma = 1;
script_config.warn_func_mismatch_paramnum = 1;
script_config.warn_cmd_mismatch_paramnum = 1;
script_config.check_cmdcount = 8192;
script_config.check_gotocount = 512;
-
- 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, "%[^:]: %[^\r\n]", w1, w2);
- if (i != 2)
- continue;
- if (strcasecmp (w1, "refine_posword") == 0)
- {
- set_posword (w2);
- }
- if (strcasecmp (w1, "import") == 0)
- {
- script_config_read (w2);
- }
- }
- fclose_ (fp);
-
- return 0;
}
/*==========================================
@@ -8037,55 +5078,181 @@ int script_config_read (const char *cfgName)
*------------------------------------------
*/
-static void mapregstr_db_final (db_key_t key, db_val_t data, va_list ap)
+static
+void mapregstr_db_final(char *data)
{
- free (data);
+ free(data);
}
-static void userfunc_db_final (db_key_t key, db_val_t data, va_list ap)
+static
+void userfunc_db_final(const ScriptCode *data)
{
- free ((char*)key.s);
- free (data);
+ free(const_cast<ScriptCode *>(data));
}
-int do_final_script (void)
+void do_final_script(void)
{
if (mapreg_dirty >= 0)
- script_save_mapreg ();
+ script_save_mapreg();
+#if 0
+ // labels are allocated just out of this
+ // (so it's a leak ...)
+ // this is disabled because it leads to a crash
+ // due to double-free
if (script_buf)
- free (script_buf);
+ free(script_buf);
+#endif
- if (mapreg_db)
- numdb_final (mapreg_db, NULL);
- if (mapregstr_db)
- strdb_final (mapregstr_db, mapregstr_db_final);
- if (scriptlabel_db)
- strdb_final (scriptlabel_db, NULL);
- if (userfunc_db)
- strdb_final (userfunc_db, userfunc_db_final);
+ mapreg_db.clear();
+ for (auto& pair : mapregstr_db)
+ mapregstr_db_final(pair.second);
+ mapregstr_db.clear();
+ scriptlabel_db.clear();
+ for (auto& pair : userfunc_db)
+ userfunc_db_final(pair.second);
+ userfunc_db.clear();
if (str_data)
- free (str_data);
+ free(str_data);
if (str_buf)
- free (str_buf);
-
- return 0;
+ free(str_buf);
}
/*==========================================
* åˆæœŸåŒ–
*------------------------------------------
*/
-int do_init_script (void)
-{
- mapreg_db = numdb_init ();
- mapregstr_db = numdb_init ();
- script_load_mapreg ();
-
- add_timer_interval (gettick () + MAPREG_AUTOSAVE_INTERVAL,
- script_autosave_mapreg, 0, 0,
- MAPREG_AUTOSAVE_INTERVAL);
-
- scriptlabel_db = strdb_init (50);
- return 0;
-}
+void do_init_script(void)
+{
+ script_load_mapreg();
+
+ Timer(gettick() + MAPREG_AUTOSAVE_INTERVAL,
+ script_autosave_mapreg,
+ MAPREG_AUTOSAVE_INTERVAL
+ ).detach();
+}
+
+#define BUILTIN(func, args) \
+{builtin_##func, #func, args}
+
+BuiltinFunction builtin_functions[] =
+{
+ BUILTIN(mes, "s"),
+ BUILTIN(next, ""),
+ BUILTIN(close, ""),
+ BUILTIN(close2, ""),
+ BUILTIN(menu, "sL*"),
+ BUILTIN(goto, "L"),
+ BUILTIN(callsub, "L"),
+ BUILTIN(callfunc, "F"),
+ BUILTIN(return, ""),
+ BUILTIN(input, "N"),
+ BUILTIN(warp, "Mxy"),
+ BUILTIN(isat, "Mxy"),
+ BUILTIN(areawarp, "MxyxyMxy"),
+ BUILTIN(setlook, "ii"),
+ BUILTIN(set, "Ne"),
+ BUILTIN(setarray, "Ne*"),
+ BUILTIN(cleararray, "Nei"),
+ BUILTIN(getarraysize, "N"),
+ BUILTIN(getelementofarray, "Ni"),
+ BUILTIN(if, "iF*"),
+ BUILTIN(getitem, "Ii**"),
+ BUILTIN(makeitem, "IiMxy"),
+ BUILTIN(delitem, "Ii"),
+ BUILTIN(heal, "ii"),
+ BUILTIN(itemheal, "ii"),
+ BUILTIN(percentheal, "ii"),
+ BUILTIN(rand, "i*"),
+ BUILTIN(pow, "ii"),
+ BUILTIN(countitem, "I"),
+ BUILTIN(checkweight, "Ii"),
+ BUILTIN(readparam, "i*"),
+ BUILTIN(getcharid, "i*"),
+ BUILTIN(strcharinfo, "i"),
+ BUILTIN(getequipid, "i"),
+ BUILTIN(getequipname, "i"),
+ BUILTIN(statusup2, "ii"),
+ BUILTIN(bonus, "ii"),
+ BUILTIN(bonus2, "iii"),
+ BUILTIN(skill, "ii*"),
+ BUILTIN(setskill, "ii"),
+ BUILTIN(getskilllv, "i"),
+ BUILTIN(getgmlevel, ""),
+ BUILTIN(end, ""),
+ BUILTIN(getopt2, ""),
+ BUILTIN(setopt2, "i"),
+ BUILTIN(savepoint, "Mxy"),
+ BUILTIN(gettimetick, "i"),
+ BUILTIN(gettime, "i"),
+ BUILTIN(gettimestr, "si"),
+ BUILTIN(openstorage, "*"),
+ BUILTIN(monster, "Mxysmi*"),
+ BUILTIN(areamonster, "Mxyxysmi*"),
+ BUILTIN(killmonster, "ME"),
+ BUILTIN(killmonsterall, "M"),
+ BUILTIN(donpcevent, "E"),
+ BUILTIN(addtimer, "tE"),
+ BUILTIN(initnpctimer, ""),
+ BUILTIN(stopnpctimer, ""),
+ BUILTIN(startnpctimer, "*"),
+ BUILTIN(setnpctimer, "i"),
+ BUILTIN(getnpctimer, "i"),
+ BUILTIN(announce, "si"),
+ BUILTIN(mapannounce, "Msi"),
+ BUILTIN(getusers, "i"),
+ BUILTIN(getmapusers, "M"),
+ BUILTIN(getareausers, "Mxyxy*"),
+ BUILTIN(getareadropitem, "Mxyxyi*"),
+ BUILTIN(enablenpc, "s"),
+ BUILTIN(disablenpc, "s"),
+ BUILTIN(sc_start, "iTi*"),
+ BUILTIN(sc_end, "i"),
+ BUILTIN(sc_check, "i"),
+ BUILTIN(debugmes, "s"),
+ BUILTIN(resetstatus, ""),
+ BUILTIN(changesex, ""),
+ BUILTIN(attachrid, "i"),
+ BUILTIN(detachrid, ""),
+ BUILTIN(isloggedin, "i"),
+ BUILTIN(setmapflag, "Mi"),
+ BUILTIN(removemapflag, "Mi"),
+ BUILTIN(getmapflag, "Mi"),
+ BUILTIN(pvpon, "M"),
+ BUILTIN(pvpoff, "M"),
+ BUILTIN(emotion, "i"),
+ BUILTIN(marriage, "P"),
+ BUILTIN(divorce, ""),
+ BUILTIN(getitemname, "I"),
+ BUILTIN(getspellinvocation, "s"),
+ BUILTIN(getpartnerid2, ""),
+ BUILTIN(getexp, "ii"),
+ BUILTIN(getinventorylist, ""),
+ BUILTIN(getactivatedpoolskilllist, ""),
+ BUILTIN(getunactivatedpoolskilllist, ""),
+ BUILTIN(poolskill, "i"),
+ BUILTIN(unpoolskill, "i"),
+ BUILTIN(misceffect, "i*"),
+ BUILTIN(specialeffect, "i"),
+ BUILTIN(specialeffect2, "i"),
+ BUILTIN(nude, ""),
+ BUILTIN(mapwarp, "MMxy"),
+ BUILTIN(cmdothernpc, "ss"),
+ BUILTIN(gmcommand, "s"),
+ BUILTIN(npcwarp, "xys"),
+ BUILTIN(message, "Ps"),
+ BUILTIN(npctalk, "s"),
+ BUILTIN(mobcount, "ME"),
+ BUILTIN(getlook, "i"),
+ BUILTIN(getsavepoint, "i"),
+ BUILTIN(areatimer, "MxyxytE"),
+ BUILTIN(isin, "Mxyxy"),
+ BUILTIN(shop, "s"),
+ BUILTIN(isdead, ""),
+ BUILTIN(unequipbyid, "i"),
+ BUILTIN(fakenpcname, "ssi"),
+ BUILTIN(getx, ""),
+ BUILTIN(gety, ""),
+ BUILTIN(getmap, ""),
+ {NULL, NULL, NULL},
+};
diff --git a/src/map/script.hpp b/src/map/script.hpp
index 6b345c4..4caf58e 100644
--- a/src/map/script.hpp
+++ b/src/map/script.hpp
@@ -1,75 +1,50 @@
-// $Id: script.h,v 1.2 2004/09/25 05:32:19 MouseJstr Exp $
#ifndef SCRIPT_HPP
#define SCRIPT_HPP
-// values are private, but gcc < 4.6 doesn't
-// support forward-declared enums
-enum class ScriptCode : uint8_t
-#ifdef RECENT_GCC
-;
-#else
-{
- // types and specials
- NOP, POS, INT, PARAM, FUNC, STR, CONSTSTR, ARG,
- NAME, EOL, RETINFO,
+#include <cstdint>
- // unary and binary operators
- LOR, LAND, LE, LT, GE, GT, EQ, NE,
- XOR, OR, AND, ADD, SUB, MUL, DIV, MOD, NEG, LNOT,
- NOT, R_SHIFT, L_SHIFT,
+#include <string>
- // really nasty workaround for gcc < 4.6
+#include "../common/db.hpp"
- x20, x21, x22, x23, x24, x25, x26, x27, x28, x29, x2a, x2b, x2c, x2d, x2e, x2f,
- x30, x31, x32, x33, x34, x35, x36, x37, x38, x39, x3a, x3b, x3c, x3d, x3e, x3f,
- x40, x41, x42, x43, x44, x45, x46, x47, x48, x49, x4a, x4b, x4c, x4d, x4e, x4f,
- x50, x51, x52, x53, x54, x55, x56, x57, x58, x59, x5a, x5b, x5c, x5d, x5e, x5f,
- x60, x61, x62, x63, x64, x65, x66, x67, x68, x69, x6a, x6b, x6c, x6d, x6e, x6f,
- x70, x71, x72, x73, x74, x75, x76, x77, x78, x79, x7a, x7b, x7c, x7d, x7e, x7f,
- x80, x81, x82, x83, x84, x85, x86, x87, x88, x89, x8a, x8b, x8c, x8d, x8e, x8f,
- x90, x91, x92, x93, x94, x95, x96, x97, x98, x99, x9a, x9b, x9c, x9d, x9e, x9f,
- xa0, xa1, xa2, xa3, xa4, xa5, xa6, xa7, xa8, xa9, xaa, xab, xac, xad, xae, xaf,
- xb0, xb1, xb2, xb3, xb4, xb5, xb6, xb7, xb8, xb9, xba, xbb, xbc, xbd, xbe, xbf,
- xc0, xc1, xc2, xc3, xc4, xc5, xc6, xc7, xc8, xc9, xca, xcb, xcc, xcd, xce, xcf,
- xd0, xd1, xd2, xd3, xd4, xd5, xd6, xd7, xd8, xd9, xda, xdb, xdc, xdd, xde, xdf,
- xe0, xe1, xe2, xe3, xe4, xe5, xe6, xe7, xe8, xe9, xea, xeb, xec, xed, xee, xef,
- xf0, xf1, xf2, xf3, xf4, xf5, xf6, xf7, xf8, xf9, xfa, xfb, xfc, xfd, xfe, xff,
-};
-#endif
+enum class ScriptCode : uint8_t;
struct script_data
{
ScriptCode type;
union
{
- int num;
+ int num;
const char *str;
+ const ScriptCode *script;
} u;
};
struct script_stack
{
- int sp, sp_max;
+ int sp, sp_max;
struct script_data *stack_data;
};
-struct script_state
+// future improvements coming!
+class ScriptState
{
+public:
struct script_stack *stack;
- int start, end;
- int pos, state;
- int rid, oid;
+ int start, end;
+ int pos, state;
+ int rid, oid;
const ScriptCode *script, *new_script;
- int defsp, new_pos, new_defsp;
+ int defsp, new_pos, new_defsp;
};
-const ScriptCode *parse_script (const char *, int);
+const ScriptCode *parse_script(const char *, int);
typedef struct argrec
{
const char *name;
union _aru
{
- int i;
+ int i;
const char *s;
_aru() = default;
@@ -77,16 +52,18 @@ typedef struct argrec
_aru(const char *z) : s(z) {}
} v;
} argrec_t;
-int run_script_l (const ScriptCode *, int, int, int, int, argrec_t * args);
-int run_script (const ScriptCode *, int, int, int);
+int run_script_l(const ScriptCode *, int, int, int, int, argrec_t *args);
+int run_script(const ScriptCode *, int, int, int);
-struct dbt *script_get_label_db (void);
-struct dbt *script_get_userfunc_db (void);
+extern
+Map<std::string, int> scriptlabel_db;
+extern
+DMap<std::string, const ScriptCode *> userfunc_db;
-int script_config_read (const char *cfgName);
-int do_init_script (void);
-int do_final_script (void);
+void script_config_read();
+void do_init_script(void);
+void do_final_script(void);
-extern char mapreg_txt[];
+extern char mapreg_txt[256];
-#endif
+#endif // SCRIPT_HPP
diff --git a/src/map/skill-pools.cpp b/src/map/skill-pools.cpp
index 204036d..c225ebe 100644
--- a/src/map/skill-pools.cpp
+++ b/src/map/skill-pools.cpp
@@ -1,37 +1,20 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
+#include "skill.hpp"
-#include "../common/timer.hpp"
-#include "../common/nullpo.hpp"
-#include "../common/mt_rand.hpp"
-#include "magic.hpp"
+#include "../common/cxxstdio.hpp"
#include "battle.hpp"
-#include "clif.hpp"
-#include "intif.hpp"
-#include "itemdb.hpp"
-#include "map.hpp"
-#include "mob.hpp"
-#include "party.hpp"
#include "pc.hpp"
-#include "script.hpp"
-#include "skill.hpp"
-#include "../common/socket.hpp"
-#ifdef MEMWATCH
-#include "memwatch.hpp"
-#endif
+#include "../poison.hpp"
-int skill_pool_skills[MAX_POOL_SKILLS];
-int skill_pool_skills_size = 0;
+SkillID skill_pool_skills[MAX_POOL_SKILLS];
+int skill_pool_skills_size = 0;
-void skill_pool_register(int id)
+void skill_pool_register(SkillID id)
{
if (skill_pool_skills_size + 1 >= MAX_POOL_SKILLS)
{
- fprintf (stderr,
+ FPRINTF(stderr,
"Too many pool skills! Increase MAX_POOL_SKILLS and recompile.");
return;
}
@@ -39,22 +22,14 @@ void skill_pool_register(int id)
skill_pool_skills[skill_pool_skills_size++] = id;
}
-const char *skill_name (int skill)
-{
- if (skill > 0 && skill < MAX_SKILL_DB)
- return skill_names[skill].desc;
- else
- return NULL;
-}
-
-int skill_pool (struct map_session_data *sd, int *skills)
+int skill_pool(struct map_session_data *sd, SkillID *skills)
{
- int i, count = 0;
+ int i, count = 0;
for (i = 0; count < MAX_SKILL_POOL && i < skill_pool_skills_size; i++)
{
- int skill_id = skill_pool_skills[i];
- if (sd->status.skill[skill_id].flags & SKILL_POOL_ACTIVATED)
+ SkillID skill_id = skill_pool_skills[i];
+ if (bool(sd->status.skill[skill_id].flags & SkillFlags::POOL_ACTIVATED))
{
if (skills)
skills[count] = skill_id;
@@ -65,78 +40,70 @@ int skill_pool (struct map_session_data *sd, int *skills)
return count;
}
-void skill_pool_empty (struct map_session_data *sd)
-{
- int i;
-
- for (i = 0; i < skill_pool_skills_size; i++)
- {
- int skill_id = skill_pool_skills[i];
- sd->status.skill[skill_id].flags = 0;
- }
-}
-
-int skill_pool_size (struct map_session_data *sd)
+int skill_pool_size(struct map_session_data *sd)
{
- return skill_pool (sd, NULL);
+ return skill_pool(sd, NULL);
}
-int skill_pool_max (struct map_session_data *sd)
+int skill_pool_max(struct map_session_data *sd)
{
- return sd->status.skill[TMW_SKILLPOOL].lv;
+ return sd->status.skill[SkillID::TMW_SKILLPOOL].lv;
}
-int skill_pool_activate (struct map_session_data *sd, int skill_id)
+int skill_pool_activate(struct map_session_data *sd, SkillID skill_id)
{
- if (sd->status.skill[skill_id].flags & SKILL_POOL_ACTIVATED)
+ if (bool(sd->status.skill[skill_id].flags & SkillFlags::POOL_ACTIVATED))
return 0; // Already there
- else if (sd->status.skill[skill_id].id == skill_id // knows the skill
- && (skill_pool_size (sd) < skill_pool_max (sd)))
+ else if (sd->status.skill[skill_id].lv
+ && (skill_pool_size(sd) < skill_pool_max(sd)))
{
- sd->status.skill[skill_id].flags |= SKILL_POOL_ACTIVATED;
- pc_calcstatus (sd, 0);
- MAP_LOG_PC (sd, "SKILL-ACTIVATE %d %d %d", skill_id,
- sd->status.skill[skill_id].lv, skill_power (sd,
- skill_id));
+ sd->status.skill[skill_id].flags |= SkillFlags::POOL_ACTIVATED;
+ pc_calcstatus(sd, 0);
+ MAP_LOG_PC(sd, "SKILL-ACTIVATE %d %d %d",
+ skill_id, sd->status.skill[skill_id].lv,
+ skill_power(sd, skill_id));
return 0;
}
return 1; // failed
}
-int skill_pool_is_activated (struct map_session_data *sd, int skill_id)
+bool skill_pool_is_activated(struct map_session_data *sd, SkillID skill_id)
{
- return sd->status.skill[skill_id].flags & SKILL_POOL_ACTIVATED;
+ return bool(sd->status.skill[skill_id].flags & SkillFlags::POOL_ACTIVATED);
}
-int skill_pool_deactivate (struct map_session_data *sd, int skill_id)
+int skill_pool_deactivate(struct map_session_data *sd, SkillID skill_id)
{
- if (sd->status.skill[skill_id].flags & SKILL_POOL_ACTIVATED)
+ if (bool(sd->status.skill[skill_id].flags & SkillFlags::POOL_ACTIVATED))
{
- sd->status.skill[skill_id].flags &= ~SKILL_POOL_ACTIVATED;
- MAP_LOG_PC (sd, "SKILL-DEACTIVATE %d", skill_id);
- pc_calcstatus (sd, 0);
+ sd->status.skill[skill_id].flags &= ~SkillFlags::POOL_ACTIVATED;
+ MAP_LOG_PC(sd, "SKILL-DEACTIVATE %d", skill_id);
+ pc_calcstatus(sd, 0);
return 0;
}
return 1;
}
-int skill_stat (int skill_id)
+// Yields the stat associated with a skill.
+// Returns zero if none, or SP::STR, SP::VIT, ... otherwise
+static
+SP skill_stat(SkillID skill_id)
{
return skill_db[skill_id].stat;
}
-int skill_power (struct map_session_data *sd, int skill_id)
+int skill_power(struct map_session_data *sd, SkillID skill_id)
{
- int stat = skill_stat (skill_id);
- int stat_value, skill_value;
- int result;
+ SP stat = skill_stat(skill_id);
+ int stat_value, skill_value;
+ int result;
- if (stat == 0 || !skill_pool_is_activated (sd, skill_id))
+ if (stat == SP::ZERO || !skill_pool_is_activated(sd, skill_id))
return 0;
- stat_value = battle_get_stat (stat, &(sd->bl));
+ stat_value = battle_get_stat(stat, &(sd->bl));
skill_value = sd->status.skill[skill_id].lv;
if ((skill_value * 10) - 1 > stat_value)
@@ -149,10 +116,10 @@ int skill_power (struct map_session_data *sd, int skill_id)
return result;
}
-int skill_power_bl (struct block_list *bl, int skill)
+int skill_power_bl(struct block_list *bl, SkillID skill)
{
- if (bl->type == BL_PC)
- return skill_power ((struct map_session_data *) bl, skill);
+ if (bl->type == BL::PC)
+ return skill_power((struct map_session_data *) bl, skill);
else
return 0;
}
diff --git a/src/map/skill.cpp b/src/map/skill.cpp
index c7ef9fd..47a2e5c 100644
--- a/src/map/skill.cpp
+++ b/src/map/skill.cpp
@@ -1,1091 +1,195 @@
-// $Id: skill.c,v 1.8 2004/09/25 05:32:19 MouseJstr Exp $
-/* スキル関係 */
+#include "skill.hpp"
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
+#include <cassert>
+#include <cstdlib>
+#include <cstring>
+#include <ctime>
-#include "../common/timer.hpp"
+#include "../common/cxxstdio.hpp"
+#include "../common/random.hpp"
#include "../common/nullpo.hpp"
-#include "../common/mt_rand.hpp"
-#include "magic.hpp"
+#include "../common/socket.hpp"
+#include "../common/timer.hpp"
#include "battle.hpp"
#include "clif.hpp"
-#include "intif.hpp"
-#include "itemdb.hpp"
+#include "magic.hpp"
#include "map.hpp"
#include "mob.hpp"
-#include "party.hpp"
#include "pc.hpp"
-#include "script.hpp"
-#include "skill.hpp"
-#include "../common/socket.hpp"
-#ifdef MEMWATCH
-#include "memwatch.hpp"
-#endif
-
-#define SKILLUNITTIMER_INVERVAL 100
-
-#define STATE_BLIND 0x10
-
-/* スキル番å·ï¼ï¼žã‚¹ãƒ†ãƒ¼ã‚¿ã‚¹ç•°å¸¸ç•ªå·å¤‰æ›ãƒ†ãƒ¼ãƒ–ル */
-int SkillStatusChangeTable[] = { /* skill.hã®enumã®SC_***ã¨ã‚ã‚ã›ã‚‹ã“㨠*/
-/* 0- */
- -1, -1, -1, -1, -1, -1,
- SC_PROVOKE, /* プロボック */
- -1, 1, -1,
-/* 10- */
- SC_SIGHT, /* サイト */
- -1, -1, -1, -1,
- SC_FREEZE, /* フロストダイãƒãƒ¼ */
- SC_STONE, /* ストーンカース */
- -1, -1, -1,
-/* 20- */
- -1, -1, -1, -1,
- SC_RUWACH, /* ルアフ */
- -1, -1, -1, -1,
- SC_INCREASEAGI, /* 速度増加 */
-/* 30- */
- SC_DECREASEAGI, /* 速度減少 */
- -1,
- SC_SIGNUMCRUCIS, /* シグナムクルシス */
- SC_ANGELUS, /* エンジェラス */
- SC_BLESSING, /* ブレッシング */
- -1, -1, -1, -1, -1,
-/* 40- */
- -1, -1, -1, -1, -1,
- SC_CONCENTRATE, /* 集中力å‘上 */
- -1, -1, -1, -1,
-/* 50- */
- -1,
- SC_HIDING, /* ãƒã‚¤ãƒ‡ã‚£ãƒ³ã‚° */
- -1, -1, -1, -1, -1, -1, -1, -1,
-/* 60- */
- SC_TWOHANDQUICKEN, /* 2HQ */
- SC_AUTOCOUNTER,
- -1, -1, -1, -1,
- SC_IMPOSITIO, /* インãƒã‚·ãƒ†ã‚£ã‚ªãƒžãƒŒã‚¹ */
- SC_SUFFRAGIUM, /* サフラギウム */
- SC_ASPERSIO, /* アスペルシオ */
- SC_BENEDICTIO, /* è–体é™ç¦ */
-/* 70- */
- -1,
- SC_SLOWPOISON,
- -1,
- SC_KYRIE, /* キリエエレイソン */
- SC_MAGNIFICAT, /* マグニフィカート */
- SC_GLORIA, /* グロリア */
- SC_DIVINA, /* レックスディビーナ */
- -1,
- SC_AETERNA, /* レックスエーテルナ */
- -1,
-/* 80- */
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-/* 90- */
- -1, -1,
- SC_QUAGMIRE, /* クァグマイア */
- -1, -1, -1, -1, -1, -1, -1,
-/* 100- */
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-/* 110- */
- -1,
- SC_ADRENALINE, /* アドレナリンラッシュ */
- SC_WEAPONPERFECTION, /* ウェãƒãƒ³ãƒ‘ーフェクション */
- SC_OVERTHRUST, /* オーãƒãƒ¼ãƒˆãƒ©ã‚¹ãƒˆ */
- SC_MAXIMIZEPOWER, /* マキシマイズパワー */
- -1, -1, -1, -1, -1,
-/* 120- */
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-/* 130- */
- -1, -1, -1, -1, -1,
- SC_CLOAKING, /* クローキング */
- SC_STAN, /* ソニックブロー */
- -1,
- SC_ENCPOISON, /* エンãƒãƒ£ãƒ³ãƒˆãƒã‚¤ã‚ºãƒ³ */
- SC_POISONREACT, /* ãƒã‚¤ã‚ºãƒ³ãƒªã‚¢ã‚¯ãƒˆ */
-/* 140- */
- SC_POISON, /* ベノムダスト */
- SC_SPLASHER, /* ベナムスプラッシャー */
- -1,
- SC_TRICKDEAD, /* 死んã ãµã‚Š */
- -1, -1, -1, -1, -1, -1,
-/* 150- */
- -1, -1, -1, -1, -1,
- SC_LOUD, /* ラウドボイス */
- -1,
- SC_ENERGYCOAT, /* エナジーコート */
- -1, -1,
-/* 160- */
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1,
- SC_SELFDESTRUCTION,
- -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1,
- SC_KEEPING,
- -1, -1,
- SC_BARRIER,
- -1, -1,
- SC_HALLUCINATION,
- -1, -1,
-/* 210- */
- -1, -1, -1, -1, -1,
- SC_STRIPWEAPON,
- SC_STRIPSHIELD,
- SC_STRIPARMOR,
- SC_STRIPHELM,
- -1,
-/* 220- */
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-/* 230- */
- -1, -1, -1, -1,
- SC_CP_WEAPON,
- SC_CP_SHIELD,
- SC_CP_ARMOR,
- SC_CP_HELM,
- -1, -1,
-/* 240- */
- -1, -1, -1, -1, -1, -1, -1, -1, -1,
- SC_AUTOGUARD,
-/* 250- */
- -1, -1,
- SC_REFLECTSHIELD,
- -1, -1,
- SC_DEVOTION,
- SC_PROVIDENCE,
- SC_DEFENDER,
- SC_SPEARSQUICKEN,
- -1,
-/* 260- */
- -1, -1, -1, -1, -1, -1, -1, -1,
- SC_STEELBODY,
- SC_BLADESTOP_WAIT,
-/* 270- */
- SC_EXPLOSIONSPIRITS,
- SC_EXTREMITYFIST,
- -1, -1, -1, -1,
- SC_MAGICROD,
- -1, -1, -1,
-/* 280- */
- SC_FLAMELAUNCHER,
- SC_FROSTWEAPON,
- SC_LIGHTNINGLOADER,
- SC_SEISMICWEAPON,
- -1,
- SC_VOLCANO,
- SC_DELUGE,
- SC_VIOLENTGALE,
- SC_LANDPROTECTOR,
- -1,
-/* 290- */
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-/* 300- */
- -1, -1, -1, -1, -1, -1,
- SC_LULLABY,
- SC_RICHMANKIM,
- SC_ETERNALCHAOS,
- SC_DRUMBATTLE,
-/* 310- */
- SC_NIBELUNGEN,
- SC_ROKISWEIL,
- SC_INTOABYSS,
- SC_SIEGFRIED,
- -1, -1, -1,
- SC_DISSONANCE,
- -1,
- SC_WHISTLE,
-/* 320- */
- SC_ASSNCROS,
- SC_POEMBRAGI,
- SC_APPLEIDUN,
- -1, -1,
- SC_UGLYDANCE,
- -1,
- SC_HUMMING,
- SC_DONTFORGETME,
- SC_FORTUNE,
-/* 330- */
- SC_SERVICE4U,
- SC_SELFDESTRUCTION,
- -1, -1, -1, -1, -1, -1, -1, -1,
-/* 340- */
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-/* 350- */
- -1, -1, -1, -1, -1,
- SC_AURABLADE,
- SC_PARRYING,
- SC_CONCENTRATION,
- SC_TENSIONRELAX,
- SC_BERSERK,
-/* 360- */
- SC_BERSERK,
- SC_ASSUMPTIO,
- SC_BASILICA,
- -1, -1, -1,
- SC_MAGICPOWER,
- -1, -1,
- SC_GOSPEL,
-/* 370- */
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-/* 380- */
- SC_TRUESIGHT,
- -1, -1,
- SC_WINDWALK,
- SC_MELTDOWN,
- -1, -1,
- SC_CARTBOOST,
- -1,
- SC_CHASEWALK,
-/* 390- */
- SC_REJECTSWORD,
- -1, -1, -1, -1, -1,
- SC_MARIONETTE,
- -1,
- SC_HEADCRUSH,
- SC_JOINTBEAT,
-/* 400 */
- -1, -1,
- SC_MINDBREAKER,
- SC_MEMORIZE,
- SC_FOGWALL,
- SC_SPIDERWEB,
- -1, -1, -1, -1,
-/* 410- */
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-};
+#include "../poison.hpp"
-struct skill_name_db skill_names[] = {
- {AC_CHARGEARROW, "CHARGEARROW", "Charge_Arrow"},
- {AC_CONCENTRATION, "CONCENTRATION", "Improve_Concentration"},
- {AC_DOUBLE, "DOUBLE", "Double_Strafe"},
- {AC_MAKINGARROW, "MAKINGARROW", "Arrow_Creation"},
- {AC_OWL, "OWL", "Owl's_Eye"},
- {AC_SHOWER, "SHOWER", "Arrow_Shower"},
- {AC_VULTURE, "VULTURE", "Vulture's_Eye"},
- {ALL_RESURRECTION, "RESURRECTION", "Resurrection"},
- {AL_ANGELUS, "ANGELUS", "Angelus"},
- {AL_BLESSING, "BLESSING", "Blessing"},
- {AL_CRUCIS, "CRUCIS", "Signum_Crusis"},
- {AL_CURE, "CURE", "Cure"},
- {AL_DECAGI, "DECAGI", "Decrease_AGI"},
- {AL_DEMONBANE, "DEMONBANE", "Demon_Bane"},
- {AL_DP, "DP", "Divine_Protection"},
- {AL_HEAL, "HEAL", "Heal"},
- {AL_HOLYLIGHT, "HOLYLIGHT", "Holy_Light"},
- {AL_HOLYWATER, "HOLYWATER", "Aqua_Benedicta"},
- {AL_INCAGI, "INCAGI", "Increase_AGI"},
- {AL_PNEUMA, "PNEUMA", "Pneuma"},
- {AL_RUWACH, "RUWACH", "Ruwach"},
- {AL_TELEPORT, "TELEPORT", "Teleport"},
- {AL_WARP, "WARP", "Warp_Portal"},
- {AM_ACIDTERROR, "ACIDTERROR", "Acid_Terror"},
- {AM_AXEMASTERY, "AXEMASTERY", "Axe_Mastery"},
- {AM_BERSERKPITCHER, "BERSERKPITCHER", "Berserk Pitcher"},
- {AM_BIOETHICS, "BIOETHICS", "Bioethics"},
- {AM_BIOTECHNOLOGY, "BIOTECHNOLOGY", "Biotechnology"},
- {AM_CALLHOMUN, "CALLHOMUN", "Call_Homunculus"},
- {AM_CANNIBALIZE, "CANNIBALIZE", "Bio_Cannibalize"},
- {AM_CP_ARMOR, "ARMOR", "Chemical_Protection_Armor"},
- {AM_CP_HELM, "HELM", "Chemical_Protection_Helm"},
- {AM_CP_SHIELD, "SHIELD", "Chemical_Protection_Shield"},
- {AM_CP_WEAPON, "WEAPON", "Chemical_Protection_Weapon"},
- {AM_CREATECREATURE, "CREATECREATURE", "Life_Creation"},
- {AM_CULTIVATION, "CULTIVATION", "Cultivation"},
- {AM_DEMONSTRATION, "DEMONSTRATION", "Demonstration"},
- {AM_DRILLMASTER, "DRILLMASTER", "Drillmaster"},
- {AM_FLAMECONTROL, "FLAMECONTROL", "Flame_Control"},
- {AM_HEALHOMUN, "HEALHOMUN", "Heal_Homunculus"},
- {AM_LEARNINGPOTION, "LEARNINGPOTION", "AM_LEARNINGPOTION"},
- {AM_PHARMACY, "PHARMACY", "Pharmacy"},
- {AM_POTIONPITCHER, "POTIONPITCHER", "Potion_Pitcher"},
- {AM_REST, "REST", "Sabbath"},
- {AM_RESURRECTHOMUN, "RESURRECTHOMUN", "Ressurect_Homunculus"},
- {AM_SPHEREMINE, "SPHEREMINE", "Sphere_Mine"},
- {ASC_BREAKER, "BREAKER", "Breaker"},
- {ASC_CDP, "CDP", "Create_Deadly_Poison"},
- {ASC_EDP, "EDP", "Deadly_Poison_Enchantment"},
- {ASC_HALLUCINATION, "HALLUCINATION", "Hallucination_Walk"},
- {ASC_KATAR, "KATAR", "Advanced_Katar_Mastery"},
- {ASC_METEORASSAULT, "METEORASSAULT", "Meteor_Assault"},
- {AS_CLOAKING, "CLOAKING", "Cloaking"},
- {AS_ENCHANTPOISON, "ENCHANTPOISON", "Enchant_Poison"},
- {AS_GRIMTOOTH, "GRIMTOOTH", "Grimtooth"},
- {AS_KATAR, "KATAR", "Katar_Mastery"},
- {AS_LEFT, "LEFT", "Lefthand_Mastery"},
- {AS_POISONREACT, "POISONREACT", "Poison_React"},
- {AS_RIGHT, "RIGHT", "Righthand_Mastery"},
- {AS_SONICBLOW, "SONICBLOW", "Sonic_Blow"},
- {AS_SPLASHER, "SPLASHER", "Venom_Splasher"},
- {AS_VENOMDUST, "VENOMDUST", "Venom_Dust"},
- {BA_APPLEIDUN, "APPLEIDUN", "Apple_of_Idun"},
- {BA_ASSASSINCROSS, "ASSASSINCROSS", "Assassin_Cross"},
- {BA_DISSONANCE, "DISSONANCE", "Dissonance"},
- {BA_FROSTJOKE, "FROSTJOKE", "Dumb_Joke"},
- {BA_MUSICALLESSON, "MUSICALLESSON", "Musical_Lesson"},
- {BA_MUSICALSTRIKE, "MUSICALSTRIKE", "Musical_Strike"},
- {BA_POEMBRAGI, "POEMBRAGI", "Poem_of_Bragi"},
- {BA_WHISTLE, "WHISTLE", "Whistle"},
- {BD_ADAPTATION, "ADAPTATION", "Adaption"},
- {BD_DRUMBATTLEFIELD, "DRUMBATTLEFIELD", "Drumb_BattleField"},
- {BD_ENCORE, "ENCORE", "Encore"},
- {BD_ETERNALCHAOS, "ETERNALCHAOS", "Eternal_Chaos"},
- {BD_INTOABYSS, "INTOABYSS", "Into_the_Abyss"},
- {BD_LULLABY, "LULLABY", "Lullaby"},
- {BD_RAGNAROK, "RAGNAROK", "Ragnarok"},
- {BD_RICHMANKIM, "RICHMANKIM", "Rich_Mankim"},
- {BD_RINGNIBELUNGEN, "RINGNIBELUNGEN", "Ring_of_Nibelugen"},
- {BD_ROKISWEIL, "ROKISWEIL", "Loki's_Wail"},
- {BD_SIEGFRIED, "SIEGFRIED", "Invulnerable_Siegfried"},
- {BS_ADRENALINE, "ADRENALINE", "Adrenaline_Rush"},
- {BS_ADRENALINE2, "ADRENALINE2", "Adrenaline Rush 2"},
- {BS_AXE, "AXE", "Smith_Axe"},
- {BS_DAGGER, "DAGGER", "Smith_Dagger"},
- {BS_ENCHANTEDSTONE, "ENCHANTEDSTONE", "Enchantedstone_Craft"},
- {BS_FINDINGORE, "FINDINGORE", "Ore_Discovery"},
- {BS_HAMMERFALL, "HAMMERFALL", "Hammer_Fall"},
- {BS_HILTBINDING, "HILTBINDING", "Hilt_Binding"},
- {BS_IRON, "IRON", "Iron_Tempering"},
- {BS_KNUCKLE, "KNUCKLE", "Smith_Knucklebrace"},
- {BS_MACE, "MACE", "Smith_Mace"},
- {BS_MAXIMIZE, "MAXIMIZE", "Power_Maximize"},
- {BS_ORIDEOCON, "ORIDEOCON", "Orideocon_Research"},
- {BS_OVERTHRUST, "OVERTHRUST", "Power-Thrust"},
- {BS_REPAIRWEAPON, "REPAIRWEAPON", "Weapon_Repair"},
- {BS_SKINTEMPER, "SKINTEMPER", "Skin_Tempering"},
- {BS_SPEAR, "SPEAR", "Smith_Spear"},
- {BS_STEEL, "STEEL", "Steel_Tempering"},
- {BS_SWORD, "SWORD", "Smith_Sword"},
- {BS_TWOHANDSWORD, "TWOHANDSWORD", "Smith_Two-handed_Sword"},
- {BS_WEAPONPERFECT, "WEAPONPERFECT", "Weapon_Perfection"},
- {BS_WEAPONRESEARCH, "WEAPONRESEARCH", "Weaponry_Research"},
- {CG_ARROWVULCAN, "ARROWVULCAN", "Vulcan_Arrow"},
- {CG_MARIONETTE, "MARIONETTE", "Marionette_Control"},
- {CG_MOONLIT, "MOONLIT", "Moonlight_Petals"},
- {CH_CHAINCRUSH, "CHAINCRUSH", "Chain_Crush_Combo"},
- {CH_PALMSTRIKE, "PALMSTRIKE", "Palm_Push_Strike"},
- {CH_SOULCOLLECT, "SOULCOLLECT", "Collect_Soul"},
- {CH_TIGERFIST, "TIGERFIST", "Tiger_Knuckle_Fist"},
- {CR_ALCHEMY, "ALCHEMY", "Alchemy"},
- {CR_AUTOGUARD, "AUTOGUARD", "Guard"},
- {CR_DEFENDER, "DEFENDER", "Defender"},
- {CR_DEVOTION, "DEVOTION", "Sacrifice"},
- {CR_GRANDCROSS, "GRANDCROSS", "Grand_Cross"},
- {CR_HOLYCROSS, "HOLYCROSS", "Holy_Cross"},
- {CR_PROVIDENCE, "PROVIDENCE", "Providence"},
- {CR_REFLECTSHIELD, "REFLECTSHIELD", "Shield_Reflect"},
- {CR_SHIELDBOOMERANG, "SHIELDBOOMERANG", "Shield_Boomerang"},
- {CR_SHIELDCHARGE, "SHIELDCHARGE", "Shield_Charge"},
- {CR_SPEARQUICKEN, "SPEARQUICKEN", "Spear_Quicken"},
- {CR_SYNTHESISPOTION, "SYNTHESISPOTION", "Potion_Synthesis"},
- {CR_TRUST, "TRUST", "Faith"},
- {DC_DANCINGLESSON, "DANCINGLESSON", "Dancing_Lesson"},
- {DC_DONTFORGETME, "DONTFORGETME", "Don't_Forget_Me"},
- {DC_FORTUNEKISS, "FORTUNEKISS", "Fortune_Kiss"},
- {DC_HUMMING, "HUMMING", "Humming"},
- {DC_SCREAM, "SCREAM", "Scream"},
- {DC_SERVICEFORYOU, "SERVICEFORYOU", "Prostitute"},
- {DC_THROWARROW, "THROWARROW", "Throw_Arrow"},
- {DC_UGLYDANCE, "UGLYDANCE", "Ugly_Dance"},
- {HP_ASSUMPTIO, "ASSUMPTIO", "Assumptio"},
- {HP_BASILICA, "BASILICA", "Basilica"},
- {HP_MEDITATIO, "MEDITATIO", "Meditation"},
- {HT_ANKLESNARE, "ANKLESNARE", "Ankle_Snare"},
- {HT_BEASTBANE, "BEASTBANE", "Beast_Bane"},
- {HT_BLASTMINE, "BLASTMINE", "Blast_Mine"},
- {HT_BLITZBEAT, "BLITZBEAT", "Blitz_Beat"},
- {HT_CLAYMORETRAP, "CLAYMORETRAP", "Claymore_Trap"},
- {HT_DETECTING, "DETECTING", "Detect"},
- {HT_FALCON, "FALCON", "Falconry_Mastery"},
- {HT_FLASHER, "FLASHER", "Flasher"},
- {HT_FREEZINGTRAP, "FREEZINGTRAP", "Freezing_Trap"},
- {HT_LANDMINE, "LANDMINE", "Land_Mine"},
- {HT_REMOVETRAP, "REMOVETRAP", "Remove_Trap"},
- {HT_SANDMAN, "SANDMAN", "Sandman"},
- {HT_SHOCKWAVE, "SHOCKWAVE", "Shockwave_Trap"},
- {HT_SKIDTRAP, "SKIDTRAP", "Skid_Trap"},
- {HT_SPRINGTRAP, "SPRINGTRAP", "Spring_Trap"},
- {HT_STEELCROW, "STEELCROW", "Steel_Crow"},
- {HT_TALKIEBOX, "TALKIEBOX", "Talkie_Box"},
- {HW_MAGICCRASHER, "MAGICCRASHER", "Magic_Crasher"},
- {HW_MAGICPOWER, "MAGICPOWER", "Magic_Power"},
- {HW_NAPALMVULCAN, "NAPALMVULCAN", "Napalm_Vulcan"},
- {HW_SOULDRAIN, "SOULDRAIN", "Soul_Drain"},
- {KN_AUTOCOUNTER, "AUTOCOUNTER", "Counter_Attack"},
- {KN_BOWLINGBASH, "BOWLINGBASH", "Bowling_Bash"},
- {KN_BRANDISHSPEAR, "BRANDISHSPEAR", "Brandish_Spear"},
- {KN_CAVALIERMASTERY, "CAVALIERMASTERY", "Cavalier_Mastery"},
- {KN_PIERCE, "PIERCE", "Pierce"},
- {KN_RIDING, "RIDING", "Peco_Peco_Ride"},
- {KN_SPEARBOOMERANG, "SPEARBOOMERANG", "Spear_Boomerang"},
- {KN_SPEARMASTERY, "SPEARMASTERY", "Spear_Mastery"},
- {KN_SPEARSTAB, "SPEARSTAB", "Spear_Stab"},
- {KN_TWOHANDQUICKEN, "TWOHANDQUICKEN", "Twohand_Quicken"},
- {LK_AURABLADE, "AURABLADE", "Aura_Blade"},
- {LK_BERSERK, "BERSERK", "Berserk"},
- {LK_CONCENTRATION, "CONCENTRATION", "Concentration"},
- {LK_FURY, "FURY", "LK_FURY"},
- {LK_HEADCRUSH, "HEADCRUSH", "Head_Crusher"},
- {LK_JOINTBEAT, "JOINTBEAT", "Joint_Beat"},
- {LK_PARRYING, "PARRYING", "Parrying"},
- {LK_SPIRALPIERCE, "SPIRALPIERCE", "Spiral_Pierce"},
- {LK_TENSIONRELAX, "TENSIONRELAX", "Tension_Relax"},
- {MC_CARTREVOLUTION, "CARTREVOLUTION", "Cart_Revolution"},
- {MC_CHANGECART, "CHANGECART", "Change_Cart"},
- {MC_DISCOUNT, "DISCOUNT", "Discount"},
- {MC_IDENTIFY, "IDENTIFY", "Item_Appraisal"},
- {MC_INCCARRY, "INCCARRY", "Enlarge_Weight_Limit"},
- {MC_LOUD, "LOUD", "Lord_Exclamation"},
- {MC_MAMMONITE, "MAMMONITE", "Mammonite"},
- {MC_OVERCHARGE, "OVERCHARGE", "Overcharge"},
- {MC_PUSHCART, "PUSHCART", "Pushcart"},
- {MG_COLDBOLT, "COLDBOLT", "Cold_Bolt"},
- {MG_ENERGYCOAT, "ENERGYCOAT", "Energy_Coat"},
- {MG_FIREBALL, "FIREBALL", "Fire_Ball"},
- {MG_FIREBOLT, "FIREBOLT", "Fire_Bolt"},
- {MG_FIREWALL, "FIREWALL", "Fire_Wall"},
- {MG_FROSTDIVER, "FROSTDIVER", "Frost_Diver"},
- {MG_LIGHTNINGBOLT, "LIGHTNINGBOLT", "Lightening_Bolt"},
- {MG_NAPALMBEAT, "NAPALMBEAT", "Napalm_Beat"},
- {MG_SAFETYWALL, "SAFETYWALL", "Safety_Wall"},
- {MG_SIGHT, "SIGHT", "Sight"},
- {MG_SOULSTRIKE, "SOULSTRIKE", "Soul_Strike"},
- {MG_SRECOVERY, "SRECOVERY", "Increase_SP_Recovery"},
- {MG_STONECURSE, "STONECURSE", "Stone_Curse"},
- {MG_THUNDERSTORM, "THUNDERSTORM", "Thunderstorm"},
- {MO_ABSORBSPIRITS, "ABSORBSPIRITS", "Absorb_Spirits"},
- {MO_BLADESTOP, "BLADESTOP", "Blade_Stop"},
- {MO_BODYRELOCATION, "BODYRELOCATION", "Body_Relocation"},
- {MO_CALLSPIRITS, "CALLSPIRITS", "Call_Spirits"},
- {MO_CHAINCOMBO, "CHAINCOMBO", "Chain_Combo"},
- {MO_COMBOFINISH, "COMBOFINISH", "Combo_Finish"},
- {MO_DODGE, "DODGE", "Dodge"},
- {MO_EXPLOSIONSPIRITS, "EXPLOSIONSPIRITS", "Explosion_Spirits"},
- {MO_EXTREMITYFIST, "EXTREMITYFIST", "Extremity_Fist"},
- {MO_FINGEROFFENSIVE, "FINGEROFFENSIVE", "Finger_Offensive"},
- {MO_INVESTIGATE, "INVESTIGATE", "Investigate"},
- {MO_IRONHAND, "IRONHAND", "Iron_Hand"},
- {MO_SPIRITSRECOVERY, "SPIRITSRECOVERY", "Spirit_Recovery"},
- {MO_STEELBODY, "STEELBODY", "Steel_Body"},
- {MO_TRIPLEATTACK, "TRIPLEATTACK", "Triple_Blows"},
- {NPC_ATTRICHANGE, "ATTRICHANGE", "NPC_ATTRICHANGE"},
- {NPC_BARRIER, "BARRIER", "NPC_BARRIER"},
- {NPC_BLINDATTACK, "BLINDATTACK", "NPC_BLINDATTACK"},
- {NPC_BLOODDRAIN, "BLOODDRAIN", "NPC_BLOODDRAIN"},
- {NPC_CHANGEDARKNESS, "CHANGEDARKNESS", "NPC_CHANGEDARKNESS"},
- {NPC_CHANGEFIRE, "CHANGEFIRE", "NPC_CHANGEFIRE"},
- {NPC_CHANGEGROUND, "CHANGEGROUND", "NPC_CHANGEGROUND"},
- {NPC_CHANGEHOLY, "CHANGEHOLY", "NPC_CHANGEHOLY"},
- {NPC_CHANGEPOISON, "CHANGEPOISON", "NPC_CHANGEPOISON"},
- {NPC_CHANGETELEKINESIS, "CHANGETELEKINESIS", "NPC_CHANGETELEKINESIS"},
- {NPC_CHANGEWATER, "CHANGEWATER", "NPC_CHANGEWATER"},
- {NPC_CHANGEWIND, "CHANGEWIND", "NPC_CHANGEWIND"},
- {NPC_COMBOATTACK, "COMBOATTACK", "NPC_COMBOATTACK"},
- {NPC_CRITICALSLASH, "CRITICALSLASH", "NPC_CRITICALSLASH"},
- {NPC_CURSEATTACK, "CURSEATTACK", "NPC_CURSEATTACK"},
- {NPC_DARKBLESSING, "DARKBLESSING", "NPC_DARKBLESSING"},
- {NPC_DARKBREATH, "DARKBREATH", "NPC_DARKBREATH"},
- {NPC_DARKCROSS, "DARKCROSS", "NPC_DARKCROSS"},
- {NPC_DARKNESSATTACK, "DARKNESSATTACK", "NPC_DARKNESSATTACK"},
- {NPC_DEFENDER, "DEFENDER", "NPC_DEFENDER"},
- {NPC_EMOTION, "EMOTION", "NPC_EMOTION"},
- {NPC_ENERGYDRAIN, "ENERGYDRAIN", "NPC_ENERGYDRAIN"},
- {NPC_FIREATTACK, "FIREATTACK", "NPC_FIREATTACK"},
- {NPC_GROUNDATTACK, "GROUNDATTACK", "NPC_GROUNDATTACK"},
- {NPC_GUIDEDATTACK, "GUIDEDATTACK", "NPC_GUIDEDATTACK"},
- {NPC_HALLUCINATION, "HALLUCINATION", "NPC_HALLUCINATION"},
- {NPC_HOLYATTACK, "HOLYATTACK", "NPC_HOLYATTACK"},
- {NPC_KEEPING, "KEEPING", "NPC_KEEPING"},
- {NPC_LICK, "LICK", "NPC_LICK"},
- {NPC_MAGICALATTACK, "MAGICALATTACK", "NPC_MAGICALATTACK"},
- {NPC_MENTALBREAKER, "MENTALBREAKER", "NPC_MENTALBREAKER"},
- {NPC_METAMORPHOSIS, "METAMORPHOSIS", "NPC_METAMORPHOSIS"},
- {NPC_PETRIFYATTACK, "PETRIFYATTACK", "NPC_PETRIFYATTACK"},
- {NPC_PIERCINGATT, "PIERCINGATT", "NPC_PIERCINGATT"},
- {NPC_POISON, "POISON", "NPC_POISON"},
- {NPC_POISONATTACK, "POISONATTACK", "NPC_POISONATTACK"},
- {NPC_RANDOMATTACK, "RANDOMATTACK", "NPC_RANDOMATTACK"},
- {NPC_RANGEATTACK, "RANGEATTACK", "NPC_RANGEATTACK"},
- {NPC_REBIRTH, "REBIRTH", "NPC_REBIRTH"},
- {NPC_SELFDESTRUCTION, "SELFDESTRUCTION", "Kabooooom!"},
- {NPC_SELFDESTRUCTION2, "SELFDESTRUCTION2", "NPC_SELFDESTRUCTION2"},
- {NPC_SILENCEATTACK, "SILENCEATTACK", "NPC_SILENCEATTACK"},
- {NPC_SLEEPATTACK, "SLEEPATTACK", "NPC_SLEEPATTACK"},
- {NPC_SMOKING, "SMOKING", "NPC_SMOKING"},
- {NPC_SPLASHATTACK, "SPLASHATTACK", "NPC_SPLASHATTACK"},
- {NPC_STUNATTACK, "STUNATTACK", "NPC_STUNATTACK"},
- {NPC_SUICIDE, "SUICIDE", "NPC_SUICIDE"},
- {NPC_SUMMONMONSTER, "SUMMONMONSTER", "NPC_SUMMONMONSTER"},
- {NPC_SUMMONSLAVE, "SUMMONSLAVE", "NPC_SUMMONSLAVE"},
- {NPC_TELEKINESISATTACK, "TELEKINESISATTACK", "NPC_TELEKINESISATTACK"},
- {NPC_TRANSFORMATION, "TRANSFORMATION", "NPC_TRANSFORMATION"},
- {NPC_WATERATTACK, "WATERATTACK", "NPC_WATERATTACK"},
- {NPC_WINDATTACK, "WINDATTACK", "NPC_WINDATTACK"},
- {NV_EMOTE, "EMOTE", "Emote_Skill"},
- {NV_TRADE, "TRADE", "Trade_Skill"},
- {NV_PARTY, "PARTY", "Party_Skill"},
- {NV_FIRSTAID, "FIRSTAID", "First Aid"},
- {NV_TRICKDEAD, "TRICKDEAD", "Play_Dead"},
- {PA_GOSPEL, "GOSPEL", "Gospel"},
- {PA_PRESSURE, "PRESSURE", "Pressure"},
- {PA_SACRIFICE, "SACRIFICE", "Sacrificial_Ritual"},
- {PF_FOGWALL, "FOGWALL", "Wall_of_Fog"},
- {PF_HPCONVERSION, "HPCONVERSION", "Health_Conversion"},
- {PF_MEMORIZE, "MEMORIZE", "Memorize"},
- {PF_MINDBREAKER, "MINDBREAKER", "Mind_Breaker"},
- {PF_SOULBURN, "SOULBURN", "Soul_Burn"},
- {PF_SOULCHANGE, "SOULCHANGE", "Soul_Change"},
- {PF_SPIDERWEB, "SPIDERWEB", "Spider_Web"},
- {PR_ASPERSIO, "ASPERSIO", "Aspersio"},
- {PR_BENEDICTIO, "BENEDICTIO", "B.S_Sacramenti"},
- {PR_GLORIA, "GLORIA", "Gloria"},
- {PR_IMPOSITIO, "IMPOSITIO", "Impositio_Manus"},
- {PR_KYRIE, "KYRIE", "Kyrie_Eleison"},
- {PR_LEXAETERNA, "LEXAETERNA", "Lex_Aeterna"},
- {PR_LEXDIVINA, "LEXDIVINA", "Lex_Divina"},
- {PR_MACEMASTERY, "MACEMASTERY", "Mace_Mastery"},
- {PR_MAGNIFICAT, "MAGNIFICAT", "Magnificat"},
- {PR_MAGNUS, "MAGNUS", "Magnus_Exorcismus"},
- {PR_SANCTUARY, "SANCTUARY", "Santuary"},
- {PR_SLOWPOISON, "SLOWPOISON", "Slow_Poison"},
- {PR_STRECOVERY, "STRECOVERY", "Status_Recovery"},
- {PR_SUFFRAGIUM, "SUFFRAGIUM", "Suffragium"},
- {PR_TURNUNDEAD, "TURNUNDEAD", "Turn_Undead"},
- {RG_BACKSTAP, "BACKSTAP", "Back_Stab"},
- {RG_CLEANER, "CLEANER", "Remover"},
- {RG_COMPULSION, "COMPULSION", "Compulsion_Discount"},
- {RG_FLAGGRAFFITI, "FLAGGRAFFITI", "Flag_Graffity"},
- {RG_GANGSTER, "GANGSTER", "Gangster's_Paradise"},
- {RG_GRAFFITI, "GRAFFITI", "Graffiti"},
- {RG_INTIMIDATE, "INTIMIDATE", "Intimidate"},
- {RG_PLAGIARISM, "PLAGIARISM", "Plagiarism"},
- {RG_RAID, "RAID", "Raid"},
- {RG_SNATCHER, "SNATCHER", "Snatcher"},
- {RG_STEALCOIN, "STEALCOIN", "Steal_Coin"},
- {RG_STRIPARMOR, "STRIPARMOR", "Strip_Armor"},
- {RG_STRIPHELM, "STRIPHELM", "Strip_Helm"},
- {RG_STRIPSHIELD, "STRIPSHIELD", "Strip_Shield"},
- {RG_STRIPWEAPON, "STRIPWEAPON", "Strip_Weapon"},
- {RG_TUNNELDRIVE, "TUNNELDRIVE", "Tunnel_Drive"},
- {SA_ABRACADABRA, "ABRACADABRA", "Hocus-pocus"},
- {SA_ADVANCEDBOOK, "ADVANCEDBOOK", "Advanced_Book"},
- {SA_AUTOSPELL, "AUTOSPELL", "Auto_Cast"},
- {SA_CASTCANCEL, "CASTCANCEL", "Cast_Cancel"},
- {SA_CLASSCHANGE, "CLASSCHANGE", "Class_Change"},
- {SA_COMA, "COMA", "Coma"},
- {SA_DEATH, "DEATH", "Death"},
- {SA_DELUGE, "DELUGE", "Deluge"},
- {SA_DISPELL, "DISPELL", "Dispel"},
- {SA_DRAGONOLOGY, "DRAGONOLOGY", "Dragonology"},
- {SA_FLAMELAUNCHER, "FLAMELAUNCHER", "Flame_Launcher"},
- {SA_FORTUNE, "FORTUNE", "Fortune"},
- {SA_FREECAST, "FREECAST", "Cast_Freedom"},
- {SA_FROSTWEAPON, "FROSTWEAPON", "Frost_Weapon"},
- {SA_FULLRECOVERY, "FULLRECOVERY", "Full_Recovery"},
- {SA_GRAVITY, "GRAVITY", "Gravity"},
- {SA_INSTANTDEATH, "INSTANTDEATH", "Instant_Death"},
- {SA_LANDPROTECTOR, "LANDPROTECTOR", "Land_Protector"},
- {SA_LEVELUP, "LEVELUP", "Level_Up"},
- {SA_LIGHTNINGLOADER, "LIGHTNINGLOADER", "Lightning_Loader"},
- {SA_MAGICROD, "MAGICROD", "Magic_Rod"},
- {SA_MONOCELL, "MONOCELL", "Monocell"},
- {SA_QUESTION, "QUESTION", "Question?"},
- {SA_REVERSEORCISH, "REVERSEORCISH", "Reverse_Orcish"},
- {SA_SEISMICWEAPON, "SEISMICWEAPON", "Seismic_Weapon"},
- {SA_SPELLBREAKER, "SPELLBREAKER", "Break_Spell"},
- {SA_SUMMONMONSTER, "SUMMONMONSTER", "Summon_Monster"},
- {SA_VIOLENTGALE, "VIOLENTGALE", "Violent_Gale"},
- {SA_VOLCANO, "VOLCANO", "Volcano"},
- {SG_DEVIL, "DEVIL", "Devil"},
- {SG_FEEL, "FEEL", "Feel"},
- {SG_FRIEND, "FRIEND", "Friend"},
- {SG_FUSION, "FUSION", "Fusion"},
- {SG_HATE, "HATE", "Hate"},
- {SG_KNOWLEDGE, "KNOWLEDGE", "Knowledge"},
- {SG_MOON_ANGER, "ANGER", "Moon Anger"},
- {SG_MOON_BLESS, "BLESS", "Moon Bless"},
- {SG_MOON_COMFORT, "COMFORT", "Moon Comfort"},
- {SG_MOON_WARM, "WARM", "Moon Warm"},
- {SG_STAR_ANGER, "ANGER", "Star Anger"},
- {SG_STAR_BLESS, "BLESS", "Star Bless"},
- {SG_STAR_COMFORT, "COMFORT", "Star Comfort"},
- {SG_STAR_WARM, "WARM", "Star Warm"},
- {SG_SUN_ANGER, "ANGER", "Sun Anger"},
- {SG_SUN_BLESS, "BLESS", "Sun Bless"},
- {SG_SUN_COMFORT, "COMFORT", "Sun Comfort"},
- {SG_SUN_WARM, "WARM", "Sun Warm"},
- {SL_ALCHEMIST, "ALCHEMIST", "Alchemist"},
- {SL_ASSASIN, "ASSASIN", "Assasin"},
- {SL_BARDDANCER, "BARDDANCER", "Bard Dancer"},
- {SL_BLACKSMITH, "BLACKSMITH", "Black Smith"},
- {SL_CRUSADER, "CRUSADER", "Crusader"},
- {SL_HUNTER, "HUNTER", "Hunter"},
- {SL_KAAHI, "KAAHI", "Kaahi"},
- {SL_KAINA, "KAINA", "Kaina"},
- {SL_KAITE, "KAITE", "Kaite"},
- {SL_KAIZEL, "KAIZEL", "Kaizel"},
- {SL_KAUPE, "KAUPE", "Kaupe"},
- {SL_KNIGHT, "KNIGHT", "Knight"},
- {SL_MONK, "MONK", "Monk"},
- {SL_PRIEST, "PRIEST", "Priest"},
- {SL_ROGUE, "ROGUE", "Rogue"},
- {SL_SAGE, "SAGE", "Sage"},
- {SL_SKA, "SKA", "SKA"},
- {SL_SKE, "SKE", "SKE"},
- {SL_SMA, "SMA", "SMA"},
- {SL_SOULLINKER, "SOULLINKER", "Soul Linker"},
- {SL_STAR, "STAR", "Star"},
- {SL_STIN, "STIN", "Stin"},
- {SL_STUN, "STUN", "Stun"},
- {SL_SUPERNOVICE, "SUPERNOVICE", "Super Novice"},
- {SL_SWOO, "SWOO", "Swoo"},
- {SL_WIZARD, "WIZARD", "Wizard"},
- {SM_AUTOBERSERK, "AUTOBERSERK", "Auto_Berserk"},
- {SM_BASH, "BASH", "Bash"},
- {SM_ENDURE, "ENDURE", "Endure"},
- {SM_FATALBLOW, "FATALBLOW", "Attack_Weak_Point"},
- {SM_MAGNUM, "MAGNUM", "Magnum_Break"},
- {SM_MOVINGRECOVERY, "MOVINGRECOVERY", "Moving_HP_Recovery"},
- {SM_PROVOKE, "PROVOKE", "Provoke"},
- {SM_RECOVERY, "RECOVERY", "Increase_HP_Recovery"},
- {SM_SWORD, "SWORD", "Sword_Mastery"},
- {SM_TWOHAND, "TWOHAND", "Two-Handed_Sword_Mastery"},
- {SN_FALCONASSAULT, "FALCONASSAULT", "Falcon_Assault"},
- {SN_SHARPSHOOTING, "SHARPSHOOTING", "Sharpshooting"},
- {SN_SIGHT, "SIGHT", "True_Sight"},
- {SN_WINDWALK, "WINDWALK", "Wind_Walk"},
- {ST_CHASEWALK, "CHASEWALK", "Chase_Walk"},
- {ST_REJECTSWORD, "REJECTSWORD", "Reject_Sword"},
- {ST_STEALBACKPACK, "STEALBACKPACK", "Steal_Backpack"},
- {TF_BACKSLIDING, "BACKSLIDING", "Back_Sliding"},
- {TF_DETOXIFY, "DETOXIFY", "Detoxify"},
- {TF_DOUBLE, "DOUBLE", "Double_Attack"},
- {TF_HIDING, "HIDING", "Hiding"},
- {TF_MISS, "MISS", "Improve_Dodge"},
- {TF_PICKSTONE, "PICKSTONE", "Take_Stone"},
- {TF_POISON, "POISON", "Envenom"},
- {TF_SPRINKLESAND, "SPRINKLESAND", "Throw_Sand"},
- {TF_STEAL, "STEAL", "Steal"},
- {TF_THROWSTONE, "THROWSTONE", "Throw_Stone"},
- {TK_COUNTER, "COUNTER", "Counter"},
- {TK_DODGE, "DODGE", "Dodge"},
- {TK_DOWNKICK, "DOWNKICK", "Down Kick"},
- {TK_HIGHJUMP, "HIGHJUMP", "High Jump"},
- {TK_HPTIME, "HPTIME", "HP Time"},
- {TK_JUMPKICK, "JUMPKICK", "Jump Kick"},
- {TK_POWER, "POWER", "Power"},
- {TK_READYCOUNTER, "READYCOUNTER", "Ready Counter"},
- {TK_READYDOWN, "READYDOWN", "Ready Down"},
- {TK_READYSTORM, "READYSTORM", "Ready Storm"},
- {TK_READYTURN, "READYTURN", "Ready Turn"},
- {TK_RUN, "RUN", "TK_RUN"},
- {TK_SEVENWIND, "SEVENWIND", "Seven Wind"},
- {TK_SPTIME, "SPTIME", "SP Time"},
- {TK_STORMKICK, "STORMKICK", "Storm Kick"},
- {TK_TURNKICK, "TURNKICK", "Turn Kick"},
- {WE_BABY, "BABY", "Adopt_Baby"},
- {WE_CALLBABY, "CALLBABY", "Call_Baby"},
- {WE_CALLPARENT, "CALLPARENT", "Call_Parent"},
- {WE_CALLPARTNER, "CALLPARTNER", "I Want to See You"},
- {WE_FEMALE, "FEMALE", "I Only Look Up to You"},
- {WE_MALE, "MALE", "I Will Protect You"},
- {WS_CARTBOOST, "CARTBOOST", "Cart_Boost"},
- {WS_CREATECOIN, "CREATECOIN", "Create_Coins"},
- {WS_CREATENUGGET, "CREATENUGGET", "Create_Nuggets"},
- {WS_MELTDOWN, "MELTDOWN", "Meltdown"},
- {WS_SYSTEMCREATE, "SYSTEMCREATE", "Create_System_tower"},
- {WZ_EARTHSPIKE, "EARTHSPIKE", "Earth_Spike"},
- {WZ_ESTIMATION, "ESTIMATION", "Sense"},
- {WZ_FIREIVY, "FIREIVY", "Fire_Ivy"},
- {WZ_FIREPILLAR, "FIREPILLAR", "Fire_Pillar"},
- {WZ_FROSTNOVA, "FROSTNOVA", "Frost_Nova"},
- {WZ_HEAVENDRIVE, "HEAVENDRIVE", "Heaven's_Drive"},
- {WZ_ICEWALL, "ICEWALL", "Ice_Wall"},
- {WZ_JUPITEL, "JUPITEL", "Jupitel_Thunder"},
- {WZ_METEOR, "METEOR", "Meteor_Storm"},
- {WZ_QUAGMIRE, "QUAGMIRE", "Quagmire"},
- {WZ_SIGHTRASHER, "SIGHTRASHER", "Sightrasher"},
- {WZ_STORMGUST, "STORMGUST", "Storm_Gust"},
- {WZ_VERMILION, "VERMILION", "Lord_of_Vermilion"},
- {WZ_WATERBALL, "WATERBALL", "Water_Ball"},
- {0, 0, 0}
-};
+struct skill_name_db skill_names[] =
+{
+ {SkillID::AC_OWL, "OWL", "Owl's_Eye"},
-static const int dirx[8] = { 0, -1, -1, -1, 0, 1, 1, 1 };
-static const int diry[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };
+ {SkillID::NPC_EMOTION, "EMOTION", "NPC_EMOTION"},
+ {SkillID::NPC_POISON, "POISON", "NPC_POISON"},
+ {SkillID::NPC_SELFDESTRUCTION, "SELFDESTRUCTION", "Kabooooom!"},
+ {SkillID::NPC_SUMMONSLAVE, "SUMMONSLAVE", "NPC_SUMMONSLAVE"},
-static int rdamage;
+ {SkillID::NV_EMOTE, "EMOTE", "Emote_Skill"},
+ {SkillID::NV_TRADE, "TRADE", "Trade_Skill"},
+ {SkillID::NV_PARTY, "PARTY", "Party_Skill"},
-/* スキルデータベース */
-struct skill_db skill_db[MAX_SKILL_DB];
+ {SkillID::TMW_MAGIC, "MAGIC", "General Magic"},
+ {SkillID::TMW_MAGIC_LIFE, "MAGIC_LIFE", "Life Magic"},
+ {SkillID::TMW_MAGIC_WAR, "MAGIC_WAR", "War Magic"},
+ {SkillID::TMW_MAGIC_TRANSMUTE, "MAGIC_TRANSMUTE", "Transmutation Magic"},
+ {SkillID::TMW_MAGIC_NATURE, "MAGIC_NATURE", "Nature Magic"},
+ {SkillID::TMW_MAGIC_ETHER, "MAGIC_ETHER", "Astral Magic"},
+ {SkillID::TMW_MAGIC_DARK, "MAGIC_DARK", "Dark Magic"},
+ {SkillID::TMW_MAGIC_LIGHT, "MAGIC_LIGHT", "Light Magic"},
+
+ {SkillID::TMW_BRAWLING, "BRAWLING", "Brawling"},
+ {SkillID::TMW_LUCKY_COUNTER, "LUCKY_COUNTER", "Lucky Counter"},
+ {SkillID::TMW_SPEED, "SPEED", "Speed"},
+ {SkillID::TMW_RESIST_POISON, "RESIST_POISON", "Resist Poison"},
+ {SkillID::TMW_ASTRAL_SOUL, "ASTRAL_SOUL", "Astral Soul"},
+ {SkillID::TMW_RAGING, "RAGING", "Raging"},
+
+ {SkillID::ZERO, nullptr, nullptr}
+};
-#define UNARMED_PLAYER_DAMAGE_MIN(bl) (skill_power_bl((bl), TMW_BRAWLING) >> 4) // +50 for 200
-#define UNARMED_PLAYER_DAMAGE_MAX(bl) (skill_power_bl((bl), TMW_BRAWLING)) // +200 for 200
+earray<struct skill_db, SkillID, SkillID::MAX_SKILL_DB> skill_db;
-int skill_get_hit (int id)
+
+static
+int skill_attack(BF attack_type, struct block_list *src,
+ struct block_list *dsrc, struct block_list *bl,
+ SkillID skillid, int skilllv, tick_t tick, BCT flag);
+static
+void skill_devotion_end(struct map_session_data *md,
+ struct map_session_data *sd, int target);
+static
+void skill_status_change_timer(TimerData *tid, tick_t tick,
+ int id, StatusChange type);
+
+int skill_get_hit(SkillID id)
{
return skill_db[id].hit;
}
-int skill_get_inf (int id)
+int skill_get_inf(SkillID id)
{
return skill_db[id].inf;
}
-int skill_get_pl (int id)
-{
- return skill_db[id].pl;
-}
-
-int skill_get_nk (int id)
+int skill_get_nk(SkillID id)
{
return skill_db[id].nk;
}
-int skill_get_max (int id)
+int skill_get_max(SkillID id)
{
return skill_db[id].max;
}
-int skill_get_max_raise (int id)
+int skill_get_max_raise(SkillID id)
{
return skill_db[id].max_raise;
}
-int skill_get_range (int id, int lv)
+int skill_get_range(SkillID id, int lv)
{
return (lv <= 0) ? 0 : skill_db[id].range[lv - 1];
}
-int skill_get_hp (int id, int lv)
-{
- return (lv <= 0) ? 0 : skill_db[id].hp[lv - 1];
-}
-
-int skill_get_sp (int id, int lv)
+int skill_get_sp(SkillID id, int lv)
{
return (lv <= 0) ? 0 : skill_db[id].sp[lv - 1];
}
-int skill_get_zeny (int id, int lv)
-{
- return (lv <= 0) ? 0 : skill_db[id].zeny[lv - 1];
-}
-
-int skill_get_num (int id, int lv)
+int skill_get_num(SkillID id, int lv)
{
return (lv <= 0) ? 0 : skill_db[id].num[lv - 1];
}
-int skill_get_cast (int id, int lv)
+int skill_get_cast(SkillID id, int lv)
{
return (lv <= 0) ? 0 : skill_db[id].cast[lv - 1];
}
-int skill_get_delay (int id, int lv)
+int skill_get_delay(SkillID id, int lv)
{
return (lv <= 0) ? 0 : skill_db[id].delay[lv - 1];
}
-int skill_get_time (int id, int lv)
-{
- return (lv <= 0) ? 0 : skill_db[id].upkeep_time[lv - 1];
-}
-
-int skill_get_time2 (int id, int lv)
-{
- return (lv <= 0) ? 0 : skill_db[id].upkeep_time2[lv - 1];
-}
-
-int skill_get_castdef (int id)
-{
- return skill_db[id].cast_def_rate;
-}
-
-int skill_get_weapontype (int id)
-{
- return skill_db[id].weapon;
-}
-
-int skill_get_inf2 (int id)
+int skill_get_inf2(SkillID id)
{
return skill_db[id].inf2;
}
-int skill_get_maxcount (int id)
+int skill_get_maxcount(SkillID id)
{
return skill_db[id].maxcount;
}
-int skill_get_blewcount (int id, int lv)
-{
- return (lv <= 0) ? 0 : skill_db[id].blewcount[lv - 1];
-}
-
-int skill_get_mhp (int id, int lv)
-{
- return (lv <= 0) ? 0 : skill_db[id].mhp[lv - 1];
-}
-
static
-int skill_get_castnodex (int id, int lv)
+int skill_get_castnodex(SkillID id, int lv)
{
return (lv <= 0) ? 0 : skill_db[id].castnodex[lv - 1];
}
-/* プロトタイプ */
-struct skill_unit_group *skill_unitsetting (struct block_list *src,
- int skillid, int skilllv, int x,
- int y, int flag);
-int skill_check_condition (struct map_session_data *sd, int type);
-int skill_frostjoke_scream (struct block_list *bl, va_list ap);
-int skill_status_change_timer_sub (struct block_list *bl, va_list ap);
-int skill_attack_area (struct block_list *bl, va_list ap);
-int skill_clear_element_field (struct block_list *bl);
-int skill_landprotector (struct block_list *bl, va_list ap);
-int skill_trap_splash (struct block_list *bl, va_list ap);
-int skill_count_target (struct block_list *bl, va_list ap);
-
-// [MouseJstr] - skill ok to cast? and when?
-static int skillnotok (int skillid, struct map_session_data *sd)
-{
- if (sd == 0)
- return 0;
- if (pc_isGM (sd) >= 20)
- return 0; // gm's can do anything damn thing they want
- switch (skillid)
- {
- case AL_WARP:
- case AL_TELEPORT:
- case MC_IDENTIFY:
- return 0; // always allowed
- default:
- return (map[sd->bl.m].flag.noskill);
- }
-}
-
-static int distance (int x0, int y0, int x1, int y1)
+static
+int distance(int x0, int y0, int x1, int y1)
{
- int dx, dy;
+ int dx, dy;
- dx = abs (x0 - x1);
- dy = abs (y0 - y1);
+ dx = abs(x0 - x1);
+ dy = abs(y0 - y1);
return dx > dy ? dx : dy;
}
-/* スキルユニットIDã‚’è¿”ã™ï¼ˆã“れもデータベースã«å…¥ã‚ŒãŸã„ãªï¼‰ */
-int skill_get_unit_id (int id, int flag)
-{
-
- switch (id)
- {
- case MG_SAFETYWALL:
- return 0x7e; /* セイフティウォール */
- case MG_FIREWALL:
- return 0x7f; /* ファイアーウォール */
- case AL_WARP:
- return (flag == 0) ? 0x81 : 0x80; /* ワープãƒãƒ¼ã‚¿ãƒ« */
- case PR_BENEDICTIO:
- return 0x82; /* è–体é™ç¦ */
- case PR_SANCTUARY:
- return 0x83; /* サンクãƒãƒ¥ã‚¢ãƒª */
- case PR_MAGNUS:
- return 0x84; /* マグヌスエクソシズム */
- case AL_PNEUMA:
- return 0x85; /* ニューマ */
- case MG_THUNDERSTORM:
- return 0x86; /* サンダーストーム */
- case WZ_HEAVENDRIVE:
- return 0x86; /* ヘヴンズドライブ */
- case WZ_SIGHTRASHER:
- return 0x86; /* サイトラッシャー */
- case WZ_METEOR:
- return 0x86; /* メテオストーム */
- case WZ_VERMILION:
- return 0x86; /* ロードオブヴァーミリオン */
- case WZ_FROSTNOVA:
- return 0x86; /* フロストノヴァ */
- case WZ_STORMGUST:
- return 0x86; /* ストームガスト(ã¨ã‚Šã‚ãˆãšLoVã¨åŒã˜ã§å‡¦ç†) */
- case CR_GRANDCROSS:
- return 0x86; /* グランドクロス */
- case WZ_FIREPILLAR:
- return (flag == 0) ? 0x87 : 0x88; /* ファイアーピラー */
- case HT_TALKIEBOX:
- return 0x99; /* トーキーボックス */
- case WZ_ICEWALL:
- return 0x8d; /* アイスウォール */
- case WZ_QUAGMIRE:
- return 0x8e; /* クァグマイア */
- case HT_BLASTMINE:
- return 0x8f; /* ブラストマイン */
- case HT_SKIDTRAP:
- return 0x90; /* スキッドトラップ */
- case HT_ANKLESNARE:
- return 0x91; /* アンクルスãƒã‚¢ */
- case AS_VENOMDUST:
- return 0x92; /* ベノムダスト */
- case HT_LANDMINE:
- return 0x93; /* ランドマイン */
- case HT_SHOCKWAVE:
- return 0x94; /* ショックウェーブトラップ */
- case HT_SANDMAN:
- return 0x95; /* サンドマン */
- case HT_FLASHER:
- return 0x96; /* フラッシャー */
- case HT_FREEZINGTRAP:
- return 0x97; /* フリージングトラップ */
- case HT_CLAYMORETRAP:
- return 0x98; /* クレイモアートラップ */
- case SA_VOLCANO:
- return 0x9a; /* ボルケーノ */
- case SA_DELUGE:
- return 0x9b; /* デリュージ */
- case SA_VIOLENTGALE:
- return 0x9c; /* ãƒã‚¤ã‚ªãƒ¬ãƒ³ãƒˆã‚²ã‚¤ãƒ« */
- case SA_LANDPROTECTOR:
- return 0x9d; /* ランドプロテクター */
- case BD_LULLABY:
- return 0x9e; /* å­å®ˆæ­Œ */
- case BD_RICHMANKIM:
- return 0x9f; /* ニヨルドã®å®´ */
- case BD_ETERNALCHAOS:
- return 0xa0; /* æ°¸é ã®æ··æ²Œ */
- case BD_DRUMBATTLEFIELD:
- return 0xa1; /* 戦太鼓ã®éŸ¿ã */
- case BD_RINGNIBELUNGEN:
- return 0xa2; /* ニーベルングã®æŒ‡è¼ª */
- case BD_ROKISWEIL:
- return 0xa3; /* ロキã®å«ã³ */
- case BD_INTOABYSS:
- return 0xa4; /* 深淵ã®ä¸­ã« */
- case BD_SIEGFRIED:
- return 0xa5; /* ä¸æ­»èº«ã®ã‚¸ãƒ¼ã‚¯ãƒ•ãƒªãƒ¼ãƒ‰ */
- case BA_DISSONANCE:
- return 0xa6; /* ä¸å”和音 */
- case BA_WHISTLE:
- return 0xa7; /* å£ç¬› */
- case BA_ASSASSINCROSS:
- return 0xa8; /* 夕陽ã®ã‚¢ã‚µã‚·ãƒ³ã‚¯ãƒ­ã‚¹ */
- case BA_POEMBRAGI:
- return 0xa9; /* ブラギã®è©© */
- case BA_APPLEIDUN:
- return 0xaa; /* イドゥンã®æž—檎 */
- case DC_UGLYDANCE:
- return 0xab; /* 自分å‹æ‰‹ãªãƒ€ãƒ³ã‚¹ */
- case DC_HUMMING:
- return 0xac; /* ãƒãƒŸãƒ³ã‚° */
- case DC_DONTFORGETME:
- return 0xad; /* ç§ã‚’忘れãªã„ã§â€¦ */
- case DC_FORTUNEKISS:
- return 0xae; /* 幸é‹ã®ã‚­ã‚¹ */
- case DC_SERVICEFORYOU:
- return 0xaf; /* サービスフォーユー */
- case RG_GRAFFITI:
- return 0xb0; /* グラフィティ */
- case AM_DEMONSTRATION:
- return 0xb1; /* デモンストレーション */
- case WE_CALLPARTNER:
- return 0xb2; /* ã‚ãªãŸã«é€¢ã„ãŸã„ */
- case PA_GOSPEL:
- return 0xb3; /* ゴスペル */
- case HP_BASILICA:
- return 0xb4; /* ãƒã‚¸ãƒªã‚« */
- case PF_FOGWALL:
- return 0xb6; /* フォグウォール */
- case PF_SPIDERWEB:
- return 0xb7; /* スパイダーウェッブ */
- }
- return 0;
- /*
- * 0x89,0x8a,0x8b 表示無ã—
- * 0x9a 炎属性ã®è© å”±ã¿ãŸã„ãªã‚¨ãƒ•ã‚§ã‚¯ãƒˆ
- * 0x9b 水属性ã®è© å”±ã¿ãŸã„ãªã‚¨ãƒ•ã‚§ã‚¯ãƒˆ
- * 0x9c 風属性ã®è© å”±ã¿ãŸã„ãªã‚¨ãƒ•ã‚§ã‚¯ãƒˆ
- * 0x9d 白ã„å°ã•ãªã‚¨ãƒ•ã‚§ã‚¯ãƒˆ
- * 0xb1 Alchemist Demonstration
- * 0xb2 = Pink Warp Portal
- * 0xb3 = Gospel For Paladin
- * 0xb4 = Basilica
- * 0xb5 = Empty
- * 0xb6 = Fog Wall for Professor
- * 0xb7 = Spider Web for Professor
- * 0xb8 = Empty
- * 0xb9 =
- */
-}
-
/*==========================================
* スキル追加効果
*------------------------------------------
*/
-int skill_additional_effect (struct block_list *src, struct block_list *bl,
- int skillid, int skilllv, int attack_type,
- unsigned int tick)
+int skill_additional_effect(struct block_list *src, struct block_list *bl,
+ SkillID skillid, int skilllv)
{
- /* MOB追加効果スキル用 */
- const int sc[] = {
- SC_POISON, SC_BLIND, SC_SILENCE, SC_STAN,
- SC_STONE, SC_CURSE, SC_SLEEP
- };
- const int sc2[] = {
- MG_STONECURSE, MG_FROSTDIVER, NPC_STUNATTACK,
- NPC_SLEEPATTACK, TF_POISON, NPC_CURSEATTACK,
- NPC_SILENCEATTACK, 0, NPC_BLINDATTACK
- };
-
struct map_session_data *sd = NULL;
- struct map_session_data *dstsd = NULL;
struct mob_data *md = NULL;
- struct mob_data *dstmd = NULL;
- int skill, skill2;
- int rate, luk;
+ int luk;
- int sc_def_mdef, sc_def_vit, sc_def_int, sc_def_luk;
- int sc_def_mdef2, sc_def_vit2, sc_def_int2, sc_def_luk2;
- int sc_def_phys_shield_spell;
+ int sc_def_mdef, sc_def_vit, sc_def_int, sc_def_luk;
+ int sc_def_phys_shield_spell;
- nullpo_retr (0, src);
- nullpo_retr (0, bl);
+ nullpo_ret(src);
+ nullpo_ret(bl);
if (skilllv < 0)
return 0;
- if (src->type == BL_PC)
+ if (src->type == BL::PC)
{
- nullpo_retr (0, sd = (struct map_session_data *) src);
+ sd = (struct map_session_data *) src;
+ nullpo_ret(sd);
}
- else if (src->type == BL_MOB)
+ else if (src->type == BL::MOB)
{
- nullpo_retr (0, md = (struct mob_data *) src); //未使用?
+ md = (struct mob_data *) src;
+ nullpo_ret(md); //未使用?
}
sc_def_phys_shield_spell = 0;
- if (battle_get_sc_data (bl)[SC_PHYS_SHIELD].timer != -1)
+ if (battle_get_sc_data(bl)[StatusChange::SC_PHYS_SHIELD].timer)
sc_def_phys_shield_spell =
- battle_get_sc_data (bl)[SC_PHYS_SHIELD].val1;
+ battle_get_sc_data(bl)[StatusChange::SC_PHYS_SHIELD].val1;
//対象ã®è€æ€§
- luk = battle_get_luk (bl);
- sc_def_mdef = 100 - (3 + battle_get_mdef (bl) + luk / 3);
- sc_def_vit = 100 - (3 + battle_get_vit (bl) + luk / 3);
- sc_def_int = 100 - (3 + battle_get_int (bl) + luk / 3);
+ luk = battle_get_luk(bl);
+ sc_def_mdef = 100 - (3 + battle_get_mdef(bl) + luk / 3);
+ sc_def_vit = 100 - (3 + battle_get_vit(bl) + luk / 3);
+ sc_def_int = 100 - (3 + battle_get_int(bl) + luk / 3);
sc_def_luk = 100 - (3 + luk);
//自分ã®è€æ€§
- luk = battle_get_luk (src);
- sc_def_mdef2 = 100 - (3 + battle_get_mdef (src) + luk / 3);
- sc_def_vit2 = 100 - (3 + battle_get_vit (src) + luk / 3);
- sc_def_int2 = 100 - (3 + battle_get_int (src) + luk / 3);
- sc_def_luk2 = 100 - (3 + luk);
- if (bl->type == BL_PC)
- dstsd = (struct map_session_data *) bl;
- else if (bl->type == BL_MOB)
+ luk = battle_get_luk(src);
+
+ if (bl->type == BL::MOB)
{
- dstmd = (struct mob_data *) bl; //未使用?
if (sc_def_mdef > 50)
sc_def_mdef = 50;
if (sc_def_vit > 50)
@@ -1104,561 +208,13 @@ int skill_additional_effect (struct block_list *src, struct block_list *bl,
switch (skillid)
{
- case 0: /* 通常攻撃 */
- /* 自動鷹 */
- if (sd && pc_isfalcon (sd) && sd->status.weapon == 11
- && (skill = pc_checkskill (sd, HT_BLITZBEAT)) > 0
- && MRAND (1000) <= sd->paramc[5] * 10 / 3 + 1)
- {
- int lv = (sd->status.job_level + 9) / 10;
- skill_castend_damage_id (src, bl, HT_BLITZBEAT,
- (skill < lv) ? skill : lv, tick,
- 0xf00000);
- }
- // スナッãƒãƒ£ãƒ¼
- if (sd && sd->status.weapon != 11
- && (skill = pc_checkskill (sd, RG_SNATCHER)) > 0)
- if ((skill * 15 + 55) +
- (skill2 =
- pc_checkskill (sd, TF_STEAL)) * 10 > MRAND (1000))
- {
- if (pc_steal_item (sd, bl))
- clif_skill_nodamage (src, bl, TF_STEAL, skill2, 1);
- else
- clif_skill_fail (sd, skillid, 0, 0);
- }
+ case SkillID::NPC_POISON:
+ // blame Fate for this
+ if (random_::chance({50 - (sc_def_vit >> 2) - (sc_def_phys_shield_spell) + (skilllv >> 2), 100}))
+ skill_status_change_start(bl, StatusChange::SC_POISON, skilllv, static_cast<interval_t>(skilllv));
break;
-
- case SM_BASH: /* ãƒãƒƒã‚·ãƒ¥ï¼ˆæ€¥æ‰€æ”»æ’ƒï¼‰ */
- if (sd && (skill = pc_checkskill (sd, SM_FATALBLOW)) > 0)
- {
- if (MRAND (100) < 6 * (skilllv - 5) * sc_def_vit / 100)
- skill_status_change_start (bl, SC_STAN, skilllv, 0, 0, 0,
- skill_get_time2 (SM_FATALBLOW,
- skilllv), 0);
- }
- break;
-
- case TF_POISON: /* インベナム */
- case AS_SPLASHER: /* ベナムスプラッシャー */
- if (MRAND (100) < (2 * skilllv + 10) * sc_def_vit / 100)
- skill_status_change_start (bl, SC_POISON, skilllv, 0, 0, 0,
- skill_get_time2 (skillid, skilllv),
- 0);
- else
- {
- if (sd && skillid == TF_POISON)
- clif_skill_fail (sd, skillid, 0, 0);
- }
- break;
-
- case AS_SONICBLOW: /* ソニックブロー */
- if (MRAND (100) < (2 * skilllv + 10) * sc_def_vit / 100)
- skill_status_change_start (bl, SC_STAN, skilllv, 0, 0, 0,
- skill_get_time2 (skillid, skilllv),
- 0);
- break;
-
- case HT_FREEZINGTRAP: /* フリージングトラップ */
- rate = skilllv * 3 + 35;
- if (MRAND (100) < rate * sc_def_mdef / 100)
- skill_status_change_start (bl, SC_FREEZE, skilllv, 0, 0, 0,
- skill_get_time2 (skillid, skilllv),
- 0);
- break;
-
- case MG_FROSTDIVER: /* フロストダイãƒãƒ¼ */
- case WZ_FROSTNOVA: /* フロストノヴァ */
- rate =
- (skilllv * 3 + 35) * sc_def_mdef / 100 -
- (battle_get_int (bl) + battle_get_luk (bl)) / 15;
- rate = rate <= 5 ? 5 : rate;
- if (MRAND (100) < rate)
- skill_status_change_start (bl, SC_FREEZE, skilllv, 0, 0, 0,
- skill_get_time2 (skillid, skilllv),
- 0);
- else if (sd)
- clif_skill_fail (sd, skillid, 0, 0);
- break;
-
- case WZ_STORMGUST: /* ストームガスト */
- {
- struct status_change *sc_data = battle_get_sc_data (bl);
- if (sc_data)
- {
- sc_data[SC_FREEZE].val3++;
- if (sc_data[SC_FREEZE].val3 >= 3)
- skill_status_change_start (bl, SC_FREEZE, skilllv, 0, 0,
- 0, skill_get_time2 (skillid,
- skilllv),
- 0);
- }
- }
- break;
-
- case HT_LANDMINE: /* ランドマイン */
- if (MRAND (100) < (5 * skilllv + 30) * sc_def_vit / 100)
- skill_status_change_start (bl, SC_STAN, skilllv, 0, 0, 0,
- skill_get_time2 (skillid, skilllv),
- 0);
- break;
-
- case HT_SHOCKWAVE: /* ショックウェーブトラップ */
- if (map[bl->m].flag.pvp && dstsd)
- {
- dstsd->status.sp -=
- dstsd->status.sp * (5 + 15 * skilllv) / 100;
- pc_calcstatus (dstsd, 0);
- }
- break;
- case HT_SANDMAN: /* サンドマン */
- if (MRAND (100) < (5 * skilllv + 30) * sc_def_int / 100)
- skill_status_change_start (bl, SC_SLEEP, skilllv, 0, 0, 0,
- skill_get_time2 (skillid, skilllv),
- 0);
- break;
- case TF_SPRINKLESAND: /* ç ‚ã¾ã */
- if (MRAND (100) < 15 * sc_def_int / 100)
- skill_status_change_start (bl, SC_BLIND, skilllv, 0, 0, 0,
- skill_get_time2 (skillid, skilllv),
- 0);
- break;
-
- case TF_THROWSTONE: /* 石投㒠*/
- if (MRAND (100) < 5 * sc_def_vit / 100)
- skill_status_change_start (bl, SC_STAN, skilllv, 0, 0, 0,
- skill_get_time2 (skillid, skilllv),
- 0);
- break;
-
- case CR_HOLYCROSS: /* ホーリークロス */
- if (MRAND (100) < 3 * skilllv * sc_def_int / 100)
- skill_status_change_start (bl, SC_BLIND, skilllv, 0, 0, 0,
- skill_get_time2 (skillid, skilllv),
- 0);
- break;
-
- case CR_GRANDCROSS: /* グランドクロス */
- {
- int race = battle_get_race (bl);
- if ((battle_check_undead (race, battle_get_elem_type (bl)) || race == 6) && MRAND (100) < 100000 * sc_def_int / 100) //強制付与ã ãŒå®Œå…¨è€æ€§ã«ã¯ç„¡åŠ¹
- skill_status_change_start (bl, SC_BLIND, skilllv, 0, 0, 0,
- skill_get_time2 (skillid, skilllv),
- 0);
- }
- break;
-
- case CR_SHIELDCHARGE: /* シールドãƒãƒ£ãƒ¼ã‚¸ */
- if (MRAND (100) < (15 + skilllv * 5) * sc_def_vit / 100)
- skill_status_change_start (bl, SC_STAN, skilllv, 0, 0, 0,
- skill_get_time2 (skillid, skilllv),
- 0);
- break;
-
- case RG_RAID: /* サプライズアタック */
- if (MRAND (100) < (10 + 3 * skilllv) * sc_def_vit / 100)
- skill_status_change_start (bl, SC_STAN, skilllv, 0, 0, 0,
- skill_get_time2 (skillid, skilllv),
- 0);
- if (MRAND (100) < (10 + 3 * skilllv) * sc_def_int / 100)
- skill_status_change_start (bl, SC_BLIND, skilllv, 0, 0, 0,
- skill_get_time2 (skillid, skilllv),
- 0);
- break;
- case BA_FROSTJOKE:
- if (MRAND (100) < (15 + 5 * skilllv) * sc_def_mdef / 100)
- skill_status_change_start (bl, SC_FREEZE, skilllv, 0, 0, 0,
- skill_get_time2 (skillid, skilllv),
- 0);
- break;
-
- case DC_SCREAM:
- if (MRAND (100) < (25 + 5 * skilllv) * sc_def_vit / 100)
- skill_status_change_start (bl, SC_STAN, skilllv, 0, 0, 0,
- skill_get_time2 (skillid, skilllv),
- 0);
- break;
-
- case BD_LULLABY: /* å­å®ˆå”„ */
- if (MRAND (100) < 15 * sc_def_int / 100)
- skill_status_change_start (bl, SC_SLEEP, skilllv, 0, 0, 0,
- skill_get_time2 (skillid, skilllv),
- 0);
- break;
-
- /* MOBã®è¿½åŠ åŠ¹æžœä»˜ãスキル */
-
- case NPC_PETRIFYATTACK:
- if (MRAND (100) < sc_def_mdef)
- skill_status_change_start (bl, sc[skillid - NPC_POISON],
- skilllv, 0, 0, 0,
- skill_get_time2 (skillid, skilllv),
- 0);
- break;
- case NPC_POISON:
- case NPC_SILENCEATTACK:
- case NPC_STUNATTACK:
- if (MRAND (100) <
- 50 - (sc_def_vit >> 2) - (sc_def_phys_shield_spell) +
- (skilllv >> 2))
- skill_status_change_start (bl, sc[skillid - NPC_POISON],
- skilllv, 0, 0, 0, skilllv, 0);
- break;
- case NPC_CURSEATTACK:
- if (MRAND (100) < sc_def_luk)
- skill_status_change_start (bl, sc[skillid - NPC_POISON],
- skilllv, 0, 0, 0,
- skill_get_time2 (skillid, skilllv),
- 0);
- break;
- case NPC_SLEEPATTACK:
- case NPC_BLINDATTACK:
- if (MRAND (100) < sc_def_int)
- skill_status_change_start (bl, sc[skillid - NPC_POISON],
- skilllv, 0, 0, 0,
- skill_get_time2 (skillid, skilllv),
- 0);
- break;
- case NPC_MENTALBREAKER:
- if (dstsd)
- {
- int sp = dstsd->status.max_sp * (10 + skilllv) / 100;
- if (sp < 1)
- sp = 1;
- pc_heal (dstsd, 0, -sp);
- }
- break;
-
-// -- moonsoul (adding status effect chance given to wizard aoe skills meteor and vermillion)
-//
- case WZ_METEOR:
- if (MRAND (100) < sc_def_vit)
- skill_status_change_start (bl, SC_STAN, skilllv, 0, 0, 0,
- skill_get_time2 (skillid, skilllv),
- 0);
- break;
- case WZ_VERMILION:
- if (MRAND (100) < sc_def_int)
- skill_status_change_start (bl, SC_BLIND, skilllv, 0, 0, 0,
- skill_get_time2 (skillid, skilllv),
- 0);
- break;
-
-// -- moonsoul (stun ability of new champion skill tigerfist)
-//
- case CH_TIGERFIST:
- if (MRAND (100) < (5 + skilllv * 5) * sc_def_vit / 100)
- skill_status_change_start (bl, SC_STAN, skilllv, 0, 0, 0,
- skill_get_time2 (skillid, skilllv),
- 0);
- break;
-
- case LK_SPIRALPIERCE:
- if (MRAND (100) < (15 + skilllv * 5) * sc_def_vit / 100)
- skill_status_change_start (bl, SC_STAN, skilllv, 0, 0, 0,
- skill_get_time2 (skillid, skilllv),
- 0);
- break;
- case ST_REJECTSWORD: /* フリージングトラップ */
- if (MRAND (100) < (10 + skilllv * 5))
- skill_status_change_start (bl, SC_AUTOCOUNTER, skilllv, 0, 0,
- 0, skill_get_time2 (skillid,
- skilllv), 0);
- break;
- case PF_FOGWALL: /* ホーリークロス */
- if (MRAND (100) < 3 * skilllv * sc_def_int / 100)
- skill_status_change_start (bl, SC_BLIND, skilllv, 0, 0, 0,
- skill_get_time2 (skillid, skilllv),
- 0);
- break;
- case LK_HEADCRUSH: /* ヘッドクラッシュ */
- { //æ¡ä»¶ãŒè‰¯ã分ã‹ã‚‰ãªã„ã®ã§é©å½“ã«
- int race = battle_get_race (bl);
- if (!
- (battle_check_undead (race, battle_get_elem_type (bl))
- || race == 6)
- && MRAND (100) < (2 * skilllv + 10) * sc_def_vit / 100)
- skill_status_change_start (bl, SC_HEADCRUSH, skilllv, 0, 0, 0,
- skill_get_time2 (skillid, skilllv),
- 0);
- }
- break;
- case LK_JOINTBEAT: /* ジョイントビート */
- //æ¡ä»¶ãŒè‰¯ã分ã‹ã‚‰ãªã„ã®ã§é©å½“ã«
- if (MRAND (100) < (2 * skilllv + 10) * sc_def_vit / 100)
- skill_status_change_start (bl, SC_JOINTBEAT, skilllv, 0, 0, 0,
- skill_get_time2 (skillid, skilllv),
- 0);
- break;
- case PF_SPIDERWEB: /* スパイダーウェッブ */
- {
- int sec = skill_get_time2 (skillid, skilllv);
- if (map[src->m].flag.pvp) //PvPã§ã¯æ‹˜æŸæ™‚é–“åŠæ¸›ï¼Ÿ
- sec = sec / 2;
- battle_stopwalking (bl, 1);
- skill_status_change_start (bl, SC_SPIDERWEB, skilllv, 0, 0, 0,
- sec, 0);
- }
- break;
- case ASC_METEORASSAULT: /* メテオアサルト */
- if (MRAND (100) < (15 + skilllv * 5) * sc_def_vit / 100) //状態異常ã¯è©³ç´°ãŒåˆ†ã‹ã‚‰ãªã„ã®ã§é©å½“ã«
- skill_status_change_start (bl, SC_STAN, skilllv, 0, 0, 0,
- skill_get_time2 (skillid, skilllv),
- 0);
- if (MRAND (100) < (10 + 3 * skilllv) * sc_def_int / 100)
- skill_status_change_start (bl, SC_BLIND, skilllv, 0, 0, 0,
- skill_get_time2 (skillid, skilllv),
- 0);
- break;
- case MO_EXTREMITYFIST: /* 阿修羅覇凰拳 */
- //阿修羅を使ã†ã¨5分間自然回復ã—ãªã„よã†ã«ãªã‚‹
- skill_status_change_start (src, SkillStatusChangeTable[skillid],
- skilllv, 0, 0, 0,
- skill_get_time2 (skillid, skilllv), 0);
- break;
- }
-
- if (sd && skillid != MC_CARTREVOLUTION && attack_type & BF_WEAPON)
- { /* カードã«ã‚ˆã‚‹è¿½åŠ åŠ¹æžœ */
- int i;
- int sc_def_card = 100;
-
- for (i = SC_STONE; i <= SC_BLIND; i++)
- {
- //対象ã«çŠ¶æ…‹ç•°å¸¸
- if (i == SC_STONE || i == SC_FREEZE)
- sc_def_card = sc_def_mdef;
- else if (i == SC_STAN || i == SC_POISON || i == SC_SILENCE)
- sc_def_card = sc_def_vit;
- else if (i == SC_SLEEP || i == SC_CONFUSION || i == SC_BLIND)
- sc_def_card = sc_def_int;
- else if (i == SC_CURSE)
- sc_def_card = sc_def_luk;
-
- if (!sd->state.arrow_atk)
- {
- if (MRAND (10000) <
- (sd->addeff[i - SC_STONE]) * sc_def_card / 100)
- {
- if (battle_config.battle_log)
- printf
- ("PC %d skill_addeff: cardã«ã‚ˆã‚‹ç•°å¸¸ç™ºå‹• %d %d\n",
- sd->bl.id, i, sd->addeff[i - SC_STONE]);
- skill_status_change_start (bl, i, 7, 0, 0, 0,
- (i ==
- SC_CONFUSION) ? 10000 +
- 7000 :
- skill_get_time2 (sc2
- [i -
- SC_STONE],
- 7), 0);
- }
- }
- else
- {
- if (MRAND (10000) <
- (sd->addeff[i - SC_STONE] +
- sd->arrow_addeff[i - SC_STONE]) * sc_def_card / 100)
- {
- if (battle_config.battle_log)
- printf
- ("PC %d skill_addeff: cardã«ã‚ˆã‚‹ç•°å¸¸ç™ºå‹• %d %d\n",
- sd->bl.id, i, sd->addeff[i - SC_STONE]);
- skill_status_change_start (bl, i, 7, 0, 0, 0,
- (i ==
- SC_CONFUSION) ? 10000 +
- 7000 :
- skill_get_time2 (sc2
- [i -
- SC_STONE],
- 7), 0);
- }
- }
- //自分ã«çŠ¶æ…‹ç•°å¸¸
- if (i == SC_STONE || i == SC_FREEZE)
- sc_def_card = sc_def_mdef2;
- else if (i == SC_STAN || i == SC_POISON || i == SC_SILENCE)
- sc_def_card = sc_def_vit2;
- else if (i == SC_SLEEP || i == SC_CONFUSION || i == SC_BLIND)
- sc_def_card = sc_def_int2;
- else if (i == SC_CURSE)
- sc_def_card = sc_def_luk2;
-
- if (!sd->state.arrow_atk)
- {
- if (MRAND (10000) <
- (sd->addeff2[i - SC_STONE]) * sc_def_card / 100)
- {
- if (battle_config.battle_log)
- printf
- ("PC %d skill_addeff: cardã«ã‚ˆã‚‹ç•°å¸¸ç™ºå‹• %d %d\n",
- src->id, i, sd->addeff2[i - SC_STONE]);
- skill_status_change_start (src, i, 7, 0, 0, 0,
- (i ==
- SC_CONFUSION) ? 10000 +
- 7000 :
- skill_get_time2 (sc2
- [i -
- SC_STONE],
- 7), 0);
- }
- }
- else
- {
- if (MRAND (10000) <
- (sd->addeff2[i - SC_STONE] +
- sd->arrow_addeff2[i - SC_STONE]) * sc_def_card / 100)
- {
- if (battle_config.battle_log)
- printf
- ("PC %d skill_addeff: cardã«ã‚ˆã‚‹ç•°å¸¸ç™ºå‹• %d %d\n",
- src->id, i, sd->addeff2[i - SC_STONE]);
- skill_status_change_start (src, i, 7, 0, 0, 0,
- (i ==
- SC_CONFUSION) ? 10000 +
- 7000 :
- skill_get_time2 (sc2
- [i -
- SC_STONE],
- 7), 0);
- }
- }
- }
- }
- return 0;
-}
-
-/*=========================================================================
- スキル攻撃å¹ã飛ã°ã—処ç†
--------------------------------------------------------------------------*/
-static
-int skill_blown (struct block_list *src, struct block_list *target, int count)
-{
- int dx = 0, dy = 0, nx, ny;
- int x = target->x, y = target->y;
- int ret, prev_state = MS_IDLE;
- int moveblock;
- struct map_session_data *sd = NULL;
- struct mob_data *md = NULL;
- struct skill_unit *su = NULL;
-
- nullpo_retr (0, src);
- nullpo_retr (0, target);
-
- if (target->type == BL_PC)
- {
- nullpo_retr (0, sd = (struct map_session_data *) target);
- }
- else if (target->type == BL_MOB)
- {
- nullpo_retr (0, md = (struct mob_data *) target);
- }
- else if (target->type == BL_SKILL)
- {
- nullpo_retr (0, su = (struct skill_unit *) target);
- }
- else
- return 0;
-
- if (!(count & 0x10000 && (sd || md || su)))
- { /* 指定ãªã—ãªã‚‰ä½ç½®é–¢ä¿‚ã‹ã‚‰æ–¹å‘を求ã‚ã‚‹ */
- dx = target->x - src->x;
- dx = (dx > 0) ? 1 : ((dx < 0) ? -1 : 0);
- dy = target->y - src->y;
- dy = (dy > 0) ? 1 : ((dy < 0) ? -1 : 0);
- }
- if (dx == 0 && dy == 0)
- {
- int dir = battle_get_dir (target);
- if (dir >= 0 && dir < 8)
- {
- dx = -dirx[dir];
- dy = -diry[dir];
- }
- }
-
- ret = path_blownpos (target->m, x, y, dx, dy, count & 0xffff);
- nx = ret >> 16;
- ny = ret & 0xffff;
- moveblock = (x / BLOCK_SIZE != nx / BLOCK_SIZE
- || y / BLOCK_SIZE != ny / BLOCK_SIZE);
-
- if (count & 0x20000)
- {
- battle_stopwalking (target, 1);
- if (sd)
- {
- sd->to_x = nx;
- sd->to_y = ny;
- sd->walktimer = 1;
- clif_walkok (sd);
- clif_movechar (sd);
- }
- else if (md)
- {
- md->to_x = nx;
- md->to_y = ny;
- prev_state = md->state.state;
- md->state.state = MS_WALK;
- clif_fixmobpos (md);
- }
- }
- else
- battle_stopwalking (target, 2);
-
- dx = nx - x;
- dy = ny - y;
-
- if (sd) /* ç”»é¢å¤–ã«å‡ºãŸã®ã§æ¶ˆåŽ» */
- map_foreachinmovearea (clif_pcoutsight, target->m, x - AREA_SIZE,
- y - AREA_SIZE, x + AREA_SIZE, y + AREA_SIZE,
- dx, dy, 0, sd);
- else if (md)
- map_foreachinmovearea (clif_moboutsight, target->m, x - AREA_SIZE,
- y - AREA_SIZE, x + AREA_SIZE, y + AREA_SIZE,
- dx, dy, BL_PC, md);
-
- if (su)
- {
- skill_unit_move_unit_group (su->group, target->m, dx, dy);
- }
- else
- {
-// struct status_change *sc_data=battle_get_sc_data(target);
- if (moveblock)
- map_delblock (target);
- target->x = nx;
- target->y = ny;
- if (moveblock)
- map_addblock (target);
-/*ダンス中ã«ã‚¨ãƒ•ã‚§ã‚¯ãƒˆã¯ç§»å‹•ã—ãªã„らã—ã„
- if(sc_data && sc_data[SC_DANCING].timer!=-1){ //対象ãŒãƒ€ãƒ³ã‚¹ä¸­ãªã®ã§ã‚¨ãƒ•ã‚§ã‚¯ãƒˆã‚‚移動
- struct skill_unit_group *sg=(struct skill_unit_group *)sc_data[SC_DANCING].val2;
- if(sg)
- skill_unit_move_unit_group(sg,target->m,dx,dy);
- }
-*/
- }
-
- if (sd)
- { /* ç”»é¢å†…ã«å…¥ã£ã¦ããŸã®ã§è¡¨ç¤º */
- map_foreachinmovearea (clif_pcinsight, target->m, nx - AREA_SIZE,
- ny - AREA_SIZE, nx + AREA_SIZE, ny + AREA_SIZE,
- -dx, -dy, 0, sd);
- if (count & 0x20000)
- sd->walktimer = -1;
- }
- else if (md)
- {
- map_foreachinmovearea (clif_mobinsight, target->m, nx - AREA_SIZE,
- ny - AREA_SIZE, nx + AREA_SIZE, ny + AREA_SIZE,
- -dx, -dy, BL_PC, md);
- if (count & 0x20000)
- md->state.state = prev_state;
}
- skill_unit_move (target, gettick (), (count & 0xffff) + 7); /* スキルユニットã®åˆ¤å®š */
-
return 0;
}
@@ -1666,1409 +222,210 @@ int skill_blown (struct block_list *src, struct block_list *target, int count)
* =========================================================================
* スキル攻撃効果処ç†ã¾ã¨ã‚
* flagã®èª¬æ˜Žã€‚16進図
- * 00XRTTff
- * ff = magicã§è¨ˆç®—ã«æ¸¡ã•ã‚Œã‚‹ï¼‰
- * TT = パケットã®type部分(0ã§ãƒ‡ãƒ•ã‚©ãƒ«ãƒˆï¼‰
+ * 00XRTTff
+ * ff = magicã§è¨ˆç®—ã«æ¸¡ã•ã‚Œã‚‹ï¼‰
+ * TT = パケットã®type部分(0ã§ãƒ‡ãƒ•ã‚©ãƒ«ãƒˆï¼‰
* X = パケットã®ã‚¹ã‚­ãƒ«Lv
- * R = 予約(skill_area_subã§ä½¿ç”¨ã™ã‚‹ï¼‰
+ * R = 予約(skill_area_subã§ä½¿ç”¨ã™ã‚‹ï¼‰
*-------------------------------------------------------------------------
*/
-int skill_attack (int attack_type, struct block_list *src,
- struct block_list *dsrc, struct block_list *bl, int skillid,
- int skilllv, unsigned int tick, int flag)
+int skill_attack(BF attack_type, struct block_list *src,
+ struct block_list *dsrc, struct block_list *bl,
+ SkillID skillid, int skilllv, tick_t tick, BCT flag)
{
struct Damage dmg;
- struct status_change *sc_data;
- int type, lv, damage;
+ eptr<struct status_change, StatusChange> sc_data;
+ int type, lv, damage;
- rdamage = 0;
- nullpo_retr (0, src);
- nullpo_retr (0, dsrc);
- nullpo_retr (0, bl);
+ nullpo_ret(src);
+ nullpo_ret(dsrc);
+ nullpo_ret(bl);
- sc_data = battle_get_sc_data (bl);
+ sc_data = battle_get_sc_data(bl);
//何もã—ãªã„判定ã“ã“ã‹ã‚‰
if (dsrc->m != bl->m) //対象ãŒåŒã˜ãƒžãƒƒãƒ—ã«ã„ãªã‘ã‚Œã°ä½•ã‚‚ã—ãªã„
return 0;
if (src->prev == NULL || dsrc->prev == NULL || bl->prev == NULL) //prevよãã‚ã‹ã‚‰ãªã„※
return 0;
- if (src->type == BL_PC && pc_isdead ((struct map_session_data *) src)) //術者?ãŒPCã§ã™ã§ã«æ­»ã‚“ã§ã„ãŸã‚‰ä½•ã‚‚ã—ãªã„
- return 0;
- if (dsrc->type == BL_PC && pc_isdead ((struct map_session_data *) dsrc)) //術者?ãŒPCã§ã™ã§ã«æ­»ã‚“ã§ã„ãŸã‚‰ä½•ã‚‚ã—ãªã„
- return 0;
- if (bl->type == BL_PC && pc_isdead ((struct map_session_data *) bl)) //対象ãŒPCã§ã™ã§ã«æ­»ã‚“ã§ã„ãŸã‚‰ä½•ã‚‚ã—ãªã„
- return 0;
- if (skillnotok (skillid, (struct map_session_data *) bl))
- return 0; // [MouseJstr]
- if (sc_data && sc_data[SC_HIDING].timer != -1)
- { //ãƒã‚¤ãƒ‡ã‚£ãƒ³ã‚°çŠ¶æ…‹ã§
- if (skill_get_pl (skillid) != 2) //スキルã®å±žæ€§ãŒåœ°å±žæ€§ã§ãªã‘ã‚Œã°ä½•ã‚‚ã—ãªã„
- return 0;
- }
- if (sc_data && sc_data[SC_TRICKDEAD].timer != -1) //死んã ãµã‚Šä¸­ã¯ä½•ã‚‚ã—ãªã„
+ if (src->type == BL::PC && pc_isdead((struct map_session_data *) src)) //術者?ãŒPCã§ã™ã§ã«æ­»ã‚“ã§ã„ãŸã‚‰ä½•ã‚‚ã—ãªã„
return 0;
- if (skillid == WZ_STORMGUST)
- { //使用スキルãŒã‚¹ãƒˆãƒ¼ãƒ ã‚¬ã‚¹ãƒˆã§
- if (sc_data && sc_data[SC_FREEZE].timer != -1) //å‡çµçŠ¶æ…‹ãªã‚‰ä½•ã‚‚ã—ãªã„
- return 0;
- }
- if (skillid == WZ_FROSTNOVA && dsrc->x == bl->x && dsrc->y == bl->y) //使用スキルãŒãƒ•ãƒ­ã‚¹ãƒˆãƒŽãƒ´ã‚¡ã§ã€dsrcã¨blãŒåŒã˜å ´æ‰€ãªã‚‰ä½•ã‚‚ã—ãªã„
+ if (dsrc->type == BL::PC && pc_isdead((struct map_session_data *) dsrc)) //術者?ãŒPCã§ã™ã§ã«æ­»ã‚“ã§ã„ãŸã‚‰ä½•ã‚‚ã—ãªã„
return 0;
- if (src->type == BL_PC && ((struct map_session_data *) src)->chatID) //術者ãŒPCã§ãƒãƒ£ãƒƒãƒˆä¸­ãªã‚‰ä½•ã‚‚ã—ãªã„
+ if (bl->type == BL::PC && pc_isdead((struct map_session_data *) bl)) //対象ãŒPCã§ã™ã§ã«æ­»ã‚“ã§ã„ãŸã‚‰ä½•ã‚‚ã—ãªã„
return 0;
- if (dsrc->type == BL_PC && ((struct map_session_data *) dsrc)->chatID) //術者ãŒPCã§ãƒãƒ£ãƒƒãƒˆä¸­ãªã‚‰ä½•ã‚‚ã—ãªã„
+ if (src->type == BL::PC && ((struct map_session_data *) src)->chatID) //術者ãŒPCã§ãƒãƒ£ãƒƒãƒˆä¸­ãªã‚‰ä½•ã‚‚ã—ãªã„
return 0;
- if (src->type == BL_PC && bl
- && mob_gvmobcheck (((struct map_session_data *) src), bl) == 0)
+ if (dsrc->type == BL::PC && ((struct map_session_data *) dsrc)->chatID) //術者ãŒPCã§ãƒãƒ£ãƒƒãƒˆä¸­ãªã‚‰ä½•ã‚‚ã—ãªã„
return 0;
//何もã—ãªã„判定ã“ã“ã¾ã§
type = -1;
- lv = (flag >> 20) & 0xf;
- dmg = battle_calc_attack (attack_type, src, bl, skillid, skilllv, flag & 0xff); //ダメージ計算
-
-//マジックロッド処ç†ã“ã“ã‹ã‚‰
- if (attack_type & BF_MAGIC && sc_data && sc_data[SC_MAGICROD].timer != -1
- && src == dsrc)
- { //魔法攻撃ã§ãƒžã‚¸ãƒƒã‚¯ãƒ­ãƒƒãƒ‰çŠ¶æ…‹ã§src=dsrcãªã‚‰
- dmg.damage = dmg.damage2 = 0; //ダメージ0
- if (bl->type == BL_PC)
- { //対象ãŒPCã®å ´åˆ
- int sp = skill_get_sp (skillid, skilllv); //使用ã•ã‚ŒãŸã‚¹ã‚­ãƒ«ã®SPã‚’å¸åŽ
- sp = sp * sc_data[SC_MAGICROD].val2 / 100; //å¸åŽçŽ‡è¨ˆç®—
- if (skillid == WZ_WATERBALL && skilllv > 1) //ウォーターボールLv1以上
- sp = sp / ((skilllv | 1) * (skilllv | 1)); //ã•ã‚‰ã«è¨ˆç®—?
- if (sp > 0x7fff)
- sp = 0x7fff; //SP多ã™ãŽã®å ´åˆã¯ç†è«–最大値
- else if (sp < 1)
- sp = 1; //1以下ã®å ´åˆã¯1
- if (((struct map_session_data *) bl)->status.sp + sp >
- ((struct map_session_data *) bl)->status.max_sp)
- { //回復SP+ç¾åœ¨ã®SPãŒMSPより大ãã„å ´åˆ
- sp = ((struct map_session_data *) bl)->status.max_sp - ((struct map_session_data *) bl)->status.sp; //SPã‚’MSP-ç¾åœ¨SPã«ã™ã‚‹
- ((struct map_session_data *) bl)->status.sp = ((struct map_session_data *) bl)->status.max_sp; //ç¾åœ¨ã®SPã«MSPを代入
- }
- else //回復SP+ç¾åœ¨ã®SPãŒMSPよりå°ã•ã„å ´åˆã¯å›žå¾©SPを加算
- ((struct map_session_data *) bl)->status.sp += sp;
- clif_heal (((struct map_session_data *) bl)->fd, SP_SP, sp); //SP回復エフェクトã®è¡¨ç¤º
- ((struct map_session_data *) bl)->canact_tick = tick + skill_delayfix (bl, skill_get_delay (SA_MAGICROD, sc_data[SC_MAGICROD].val1)); //
- }
- clif_skill_nodamage (bl, bl, SA_MAGICROD, sc_data[SC_MAGICROD].val1, 1); //マジックロッドエフェクトを表示
- }
-//マジックロッド処ç†ã“ã“ã¾ã§
+ lv = flag.level;
+ dmg = battle_calc_attack(attack_type, src, bl, skillid, skilllv, flag.lo); //ダメージ計算
damage = dmg.damage + dmg.damage2;
if (lv == 15)
lv = -1;
- if (flag & 0xff00)
- type = (flag & 0xff00) >> 8;
-
- if (damage <= 0 || damage < dmg.div_) //å¹ã飛ã°ã—判定?※
- dmg.blewcount = 0;
-
- if (skillid == CR_GRANDCROSS)
- { //グランドクロス
- if (battle_config.gx_disptype)
- dsrc = src; // 敵ダメージ白文字表示
- if (src == bl)
- type = 4; // åå‹•ã¯ãƒ€ãƒ¡ãƒ¼ã‚¸ãƒ¢ãƒ¼ã‚·ãƒ§ãƒ³ãªã—
- }
-
-//使用者ãŒPCã®å ´åˆã®å‡¦ç†ã“ã“ã‹ã‚‰
- if (src->type == BL_PC)
- {
- struct map_session_data *sd = (struct map_session_data *) src;
- nullpo_retr (0, sd);
-//連打掌(MO_CHAINCOMBO)ã“ã“ã‹ã‚‰
- if (skillid == MO_CHAINCOMBO)
- {
- int delay = 1000 - 4 * battle_get_agi (src) - 2 * battle_get_dex (src); //基本ディレイã®è¨ˆç®—
- if (damage < battle_get_hp (bl))
- { //ダメージãŒå¯¾è±¡ã®HPよりå°ã•ã„å ´åˆ
- if (pc_checkskill (sd, MO_COMBOFINISH) > 0 && sd->spiritball > 0) //猛é¾æ‹³(MO_COMBOFINISH)å–得&気çƒä¿æŒæ™‚ã¯+300ms
- delay += 300 * battle_config.combo_delay_rate / 100; //追加ディレイをconfã«ã‚ˆã‚Šèª¿æ•´
-
- skill_status_change_start (src, SC_COMBO, MO_CHAINCOMBO, skilllv, 0, 0, delay, 0); //コンボ状態ã«
- }
- sd->attackabletime = sd->canmove_tick = tick + delay;
- clif_combo_delay (src, delay); //コンボディレイパケットã®é€ä¿¡
- }
-//連打掌(MO_CHAINCOMBO)ã“ã“ã¾ã§
-//猛é¾æ‹³(MO_COMBOFINISH)ã“ã“ã‹ã‚‰
- else if (skillid == MO_COMBOFINISH)
- {
- int delay =
- 700 - 4 * battle_get_agi (src) - 2 * battle_get_dex (src);
- if (damage < battle_get_hp (bl))
- {
- //阿修羅覇凰拳(MO_EXTREMITYFIST)å–得&気çƒ4個ä¿æŒï¼†çˆ†è£‚波動(MO_EXPLOSIONSPIRITS)状態時ã¯+300ms
- //ä¼è™Žæ‹³(CH_TIGERFIST)å–得時も+300ms
- if ((pc_checkskill (sd, MO_EXTREMITYFIST) > 0
- && sd->spiritball >= 4
- && sd->sc_data[SC_EXPLOSIONSPIRITS].timer != -1)
- || (pc_checkskill (sd, CH_TIGERFIST) > 0
- && sd->spiritball > 0)
- || (pc_checkskill (sd, CH_CHAINCRUSH) > 0
- && sd->spiritball > 1))
- delay += 300 * battle_config.combo_delay_rate / 100; //追加ディレイをconfã«ã‚ˆã‚Šèª¿æ•´
-
- skill_status_change_start (src, SC_COMBO, MO_COMBOFINISH, skilllv, 0, 0, delay, 0); //コンボ状態ã«
- }
- sd->attackabletime = sd->canmove_tick = tick + delay;
- clif_combo_delay (src, delay); //コンボディレイパケットã®é€ä¿¡
- }
-//猛é¾æ‹³(MO_COMBOFINISH)ã“ã“ã¾ã§
-//ä¼è™Žæ‹³(CH_TIGERFIST)ã“ã“ã‹ã‚‰
- else if (skillid == CH_TIGERFIST)
- {
- int delay =
- 1000 - 4 * battle_get_agi (src) - 2 * battle_get_dex (src);
- if (damage < battle_get_hp (bl))
- {
- if (pc_checkskill (sd, CH_CHAINCRUSH) > 0) //連柱崩撃(CH_CHAINCRUSH)å–得時ã¯+300ms
- delay += 300 * battle_config.combo_delay_rate / 100; //追加ディレイをconfã«ã‚ˆã‚Šèª¿æ•´
-
- skill_status_change_start (src, SC_COMBO, CH_TIGERFIST, skilllv, 0, 0, delay, 0); //コンボ状態ã«
- }
- sd->attackabletime = sd->canmove_tick = tick + delay;
- clif_combo_delay (src, delay); //コンボディレイパケットã®é€ä¿¡
- }
-//ä¼è™Žæ‹³(CH_TIGERFIST)ã“ã“ã¾ã§
-//連柱崩撃(CH_CHAINCRUSH)ã“ã“ã‹ã‚‰
- else if (skillid == CH_CHAINCRUSH)
- {
- int delay =
- 1000 - 4 * battle_get_agi (src) - 2 * battle_get_dex (src);
- if (damage < battle_get_hp (bl))
- {
- //阿修羅覇凰拳(MO_EXTREMITYFIST)å–得&気çƒ4個ä¿æŒï¼†çˆ†è£‚波動(MO_EXPLOSIONSPIRITS)状態時ã¯+300ms
- if (pc_checkskill (sd, MO_EXTREMITYFIST) > 0
- && sd->spiritball >= 4
- && sd->sc_data[SC_EXPLOSIONSPIRITS].timer != -1)
- delay += 300 * battle_config.combo_delay_rate / 100; //追加ディレイをconfã«ã‚ˆã‚Šèª¿æ•´
-
- skill_status_change_start (src, SC_COMBO, CH_CHAINCRUSH, skilllv, 0, 0, delay, 0); //コンボ状態ã«
- }
- sd->attackabletime = sd->canmove_tick = tick + delay;
- clif_combo_delay (src, delay); //コンボディレイパケットã®é€ä¿¡
- }
-//連柱崩撃(CH_CHAINCRUSH)ã“ã“ã¾ã§
- }
-//使用者ãŒPCã®å ´åˆã®å‡¦ç†ã“ã“ã¾ã§
-//武器スキル?ã“ã“ã‹ã‚‰
- //AppleGirl Was Here
- if (attack_type & BF_MAGIC && damage > 0 && src != bl && src == dsrc)
- { //Blah Blah
- if (bl->type == BL_PC)
- { //Blah Blah
- struct map_session_data *tsd = (struct map_session_data *) bl;
- if (tsd->magic_damage_return > 0)
- { //More Blah
- rdamage += damage * tsd->magic_damage_return / 100;
- if (rdamage < 1)
- rdamage = 1;
- }
- }
- }
- //Stop Here
- if (attack_type & BF_WEAPON && damage > 0 && src != bl && src == dsrc)
- { //武器スキル&ダメージã‚り&使用者ã¨å¯¾è±¡è€…ãŒé•ã†ï¼†src=dsrc
- if (dmg.flag & BF_SHORT)
- { //è¿‘è·é›¢æ”»æ’ƒæ™‚?※
- if (bl->type == BL_PC)
- { //対象ãŒPCã®æ™‚
- struct map_session_data *tsd = (struct map_session_data *) bl;
- nullpo_retr (0, tsd);
- if (tsd->short_weapon_damage_return > 0)
- { //è¿‘è·é›¢æ”»æ’ƒè·³ã­è¿”ã—?※
- rdamage += damage * tsd->short_weapon_damage_return / 100;
- if (rdamage < 1)
- rdamage = 1;
- }
- }
- if (sc_data && sc_data[SC_REFLECTSHIELD].timer != -1)
- { //リフレクトシールド時
- rdamage += damage * sc_data[SC_REFLECTSHIELD].val2 / 100; //è·³ã­è¿”ã—計算
- if (rdamage < 1)
- rdamage = 1;
- }
- }
- else if (dmg.flag & BF_LONG)
- { //é è·é›¢æ”»æ’ƒæ™‚?※
- if (bl->type == BL_PC)
- { //対象ãŒPCã®æ™‚
- struct map_session_data *tsd = (struct map_session_data *) bl;
- nullpo_retr (0, tsd);
- if (tsd->long_weapon_damage_return > 0)
- { //é è·é›¢æ”»æ’ƒè·³ã­è¿”ã—?※
- rdamage += damage * tsd->long_weapon_damage_return / 100;
- if (rdamage < 1)
- rdamage = 1;
- }
- }
- }
- if (rdamage > 0)
- clif_damage (src, src, tick, dmg.amotion, 0, rdamage, 1, 4, 0);
- }
-//武器スキル?ã“ã“ã¾ã§
+ if (flag.mid)
+ type = flag.mid;
switch (skillid)
{
- case WZ_SIGHTRASHER:
- clif_skill_damage (src, bl, tick, dmg.amotion, dmg.dmotion,
- damage, dmg.div_, skillid,
- (lv != 0) ? lv : skilllv, 5);
- break;
- case AS_SPLASHER:
- clif_skill_damage (dsrc, bl, tick, dmg.amotion, dmg.dmotion,
- damage, dmg.div_, skillid, -1, 5);
- break;
- case NPC_SELFDESTRUCTION:
- case NPC_SELFDESTRUCTION2:
+ case SkillID::NPC_SELFDESTRUCTION:
break;
default:
- clif_skill_damage (dsrc, bl, tick, dmg.amotion, dmg.dmotion,
+ clif_skill_damage(dsrc, bl, tick, dmg.amotion, dmg.dmotion,
damage, dmg.div_, skillid,
(lv != 0) ? lv : skilllv,
- (skillid == 0) ? 5 : type);
- }
- if (dmg.blewcount > 0 && !map[src->m].flag.gvg)
- { /* å¹ã飛ã°ã—処ç†ã¨ãã®ãƒ‘ケット */
- if (skillid == WZ_SIGHTRASHER)
- skill_blown (src, bl, dmg.blewcount);
- else
- skill_blown (dsrc, bl, dmg.blewcount);
- if (bl->type == BL_MOB)
- clif_fixmobpos ((struct mob_data *) bl);
- else
- clif_fixpos (bl);
+ (skillid == SkillID::ZERO) ? 5 : type);
}
- map_freeblock_lock ();
+ map_freeblock_lock();
/* 実際ã«ãƒ€ãƒ¡ãƒ¼ã‚¸å‡¦ç†ã‚’行ㆠ*/
- if (skillid != KN_BOWLINGBASH || flag)
- battle_damage (src, bl, damage, 0);
- if (skillid == RG_INTIMIDATE && damage > 0
- && !(battle_get_mode (bl) & 0x20) && !map[src->m].flag.gvg)
- {
- int s_lv = battle_get_lv (src), t_lv = battle_get_lv (bl);
- int rate = 50 + skilllv * 5;
- rate = rate + (s_lv - t_lv);
- if (MRAND (100) < rate)
- skill_addtimerskill (src, tick + 800, bl->id, 0, 0, skillid,
- skilllv, 0, flag);
- }
-/*
- if(damage > 0 && dmg.flag&BF_SKILL && bl->type==BL_PC && pc_checkskill((struct map_session_data *)bl,RG_PLAGIARISM)){
- struct map_session_data *tsd = (struct map_session_data *)bl;
- nullpo_retr(0, tsd);
- if(!tsd->status.skill[skillid].id && !tsd->status.skill[skillid].id
- && !(skillid > NPC_PIERCINGATT && skillid < NPC_SUMMONMONSTER) ){
- //æ—¢ã«ç›—ã‚“ã§ã„るスキルãŒã‚ã‚Œã°è©²å½“スキルを消ã™
- if (tsd->cloneskill_id && tsd->cloneskill_lv && tsd->status.skill[tsd->cloneskill_id].flag==13){
- tsd->status.skill[tsd->cloneskill_id].id=0;
- tsd->status.skill[tsd->cloneskill_id].lv=0;
- tsd->status.skill[tsd->cloneskill_id].flag=0;
- }
- tsd->cloneskill_id=skillid;
- tsd->cloneskill_lv=skilllv;
- tsd->status.skill[skillid].id=skillid;
- tsd->status.skill[skillid].lv=(pc_checkskill(tsd,RG_PLAGIARISM) > skill_get_max(skillid))?
- skill_get_max(skillid):pc_checkskill(tsd,RG_PLAGIARISM);
- tsd->status.skill[skillid].flag=13;//cloneskill flag
- clif_skillinfoblock(tsd);
- }
- }
-*/
+ battle_damage(src, bl, damage, 0);
+
/* ダメージãŒã‚ã‚‹ãªã‚‰è¿½åŠ åŠ¹æžœåˆ¤å®š */
if (bl->prev != NULL)
{
struct map_session_data *sd = (struct map_session_data *) bl;
- nullpo_retr (0, sd);
- if (bl->type != BL_PC || (sd && !pc_isdead (sd)))
+ nullpo_ret(sd);
+ if (bl->type != BL::PC || (sd && !pc_isdead(sd)))
{
if (damage > 0)
- skill_additional_effect (src, bl, skillid, skilllv,
- attack_type, tick);
- if (bl->type == BL_MOB && src != bl) /* スキル使用æ¡ä»¶ã®MOBスキル */
+ skill_additional_effect(src, bl, skillid, skilllv);
+ if (bl->type == BL::MOB && src != bl) /* スキル使用æ¡ä»¶ã®MOBスキル */
{
struct mob_data *md = (struct mob_data *) bl;
- nullpo_retr (0, md);
+ nullpo_ret(md);
if (battle_config.mob_changetarget_byskill == 1)
{
- int target;
+ int target;
target = md->target_id;
- if (src->type == BL_PC)
+ if (src->type == BL::PC)
md->target_id = src->id;
- mobskill_use (md, tick, MSC_SKILLUSED | (skillid << 16));
+ mobskill_use(md, tick, MobSkillCondition::ANY);
md->target_id = target;
}
else
- mobskill_use (md, tick, MSC_SKILLUSED | (skillid << 16));
+ mobskill_use(md, tick, MobSkillCondition::ANY);
}
}
}
- if (src->type == BL_PC && dmg.flag & BF_WEAPON && src != bl && src == dsrc
+ if (src->type == BL::PC
+ && bool(dmg.flag & BF::WEAPON)
+ && src != bl
+ && src == dsrc
&& damage > 0)
{
struct map_session_data *sd = (struct map_session_data *) src;
- int hp = 0, sp = 0;
- nullpo_retr (0, sd);
+ int hp = 0, sp = 0;
+ nullpo_ret(sd);
if (sd->hp_drain_rate && dmg.damage > 0
- && MRAND (100) < sd->hp_drain_rate)
+ && random_::chance({sd->hp_drain_rate, 100}))
{
hp += (dmg.damage * sd->hp_drain_per) / 100;
}
if (sd->hp_drain_rate_ && dmg.damage2 > 0
- && MRAND (100) < sd->hp_drain_rate_)
+ && random_::chance({sd->hp_drain_rate_, 100}))
{
hp += (dmg.damage2 * sd->hp_drain_per_) / 100;
}
if (sd->sp_drain_rate > 0 && dmg.damage > 0
- && MRAND (100) < sd->sp_drain_rate)
+ && random_::chance({sd->sp_drain_rate, 100}))
{
sp += (dmg.damage * sd->sp_drain_per) / 100;
}
if (sd->sp_drain_rate_ > 0 && dmg.damage2 > 0
- && MRAND (100) < sd->sp_drain_rate_)
+ && random_::chance({sd->sp_drain_rate_, 100}))
{
sp += (dmg.damage2 * sd->sp_drain_per_) / 100;
}
if (hp || sp)
- pc_heal (sd, hp, sp);
- }
-
- if ((skillid != KN_BOWLINGBASH || flag) && rdamage > 0)
- battle_damage (bl, src, rdamage, 0);
-
- if (attack_type & BF_WEAPON && sc_data
- && sc_data[SC_AUTOCOUNTER].timer != -1
- && sc_data[SC_AUTOCOUNTER].val4 > 0)
- {
- if (sc_data[SC_AUTOCOUNTER].val3 == dsrc->id)
- battle_weapon_attack (bl, dsrc, tick,
- 0x8000 | sc_data[SC_AUTOCOUNTER].val1);
- skill_status_change_end (bl, SC_AUTOCOUNTER, -1);
+ pc_heal(sd, hp, sp);
}
- map_freeblock_unlock ();
+ map_freeblock_unlock();
return (dmg.damage + dmg.damage2); /* 与ダメを返㙠*/
}
-/*==========================================
- * スキル範囲攻撃用(map_foreachinareaã‹ã‚‰å‘¼ã°ã‚Œã‚‹)
- * flagã«ã¤ã„ã¦ï¼š16進図を確èª
- * MSB <- 00fTffff ->LSB
- * T =ターゲットé¸æŠžç”¨(BCT_*)
- * ffff=自由ã«ä½¿ç”¨å¯èƒ½
- * 0 =予約。0ã«å›ºå®š
- *------------------------------------------
- */
-static int skill_area_temp[8]; /* 一時変数。必è¦ãªã‚‰ä½¿ã†ã€‚ */
-typedef int (*SkillFunc) (struct block_list *, struct block_list *, int, int,
- unsigned int, int);
-static
-int skill_area_sub (struct block_list *bl, va_list ap)
-{
- struct block_list *src;
- int skill_id, skill_lv, flag;
- unsigned int tick;
- SkillFunc func;
-
- nullpo_retr (0, bl);
- nullpo_retr (0, ap);
-
- if (bl->type != BL_PC && bl->type != BL_MOB && bl->type != BL_SKILL)
- return 0;
-
- src = va_arg (ap, struct block_list *); //ã“ã“ã§ã¯srcã®å€¤ã‚’å‚ç…§ã—ã¦ã„ãªã„ã®ã§NULLãƒã‚§ãƒƒã‚¯ã¯ã—ãªã„
- skill_id = va_arg (ap, int);
- skill_lv = va_arg (ap, int);
- tick = va_arg (ap, unsigned int);
- flag = va_arg (ap, int);
- func = va_arg (ap, SkillFunc);
-
- if (battle_check_target (src, bl, flag) > 0)
- func (src, bl, skill_id, skill_lv, tick, flag);
- return 0;
-}
-
-static int skill_check_unit_range_sub (struct block_list *bl, va_list ap)
-{
- struct skill_unit *unit;
- int *c, x, y, range, sx[4], sy[4];
- int t_range, tx[4], ty[4];
- int i, r_flag, skillid;
-
- nullpo_retr (0, bl);
- nullpo_retr (0, ap);
- nullpo_retr (0, unit = (struct skill_unit *) bl);
- nullpo_retr (0, c = va_arg (ap, int *));
-
- if (bl->prev == NULL || bl->type != BL_SKILL)
- return 0;
-
- if (!unit->alive)
- return 0;
+typedef int(*SkillFunc)(struct block_list *, struct block_list *,
+ SkillID, int,
+ tick_t, BCT);
- x = va_arg (ap, int);
- y = va_arg (ap, int);
- range = va_arg (ap, int);
- skillid = va_arg (ap, int);
-
- if (skillid == MG_SAFETYWALL || skillid == AL_PNEUMA)
- {
- if (unit->group->unit_id != 0x7e && unit->group->unit_id != 0x85)
- return 0;
- }
- else if (skillid == AL_WARP)
- {
- if ((unit->group->unit_id < 0x8f || unit->group->unit_id > 0x99)
- && unit->group->unit_id != 0x92)
- return 0;
- }
- else if ((skillid >= HT_SKIDTRAP && skillid <= HT_CLAYMORETRAP)
- || skillid == HT_TALKIEBOX)
- {
- if ((unit->group->unit_id < 0x8f || unit->group->unit_id > 0x99)
- && unit->group->unit_id != 0x92)
- return 0;
- }
- else if (skillid == WZ_FIREPILLAR)
- {
- if (unit->group->unit_id != 0x87)
- return 0;
- }
- else
- return 0;
- t_range = (unit->range != 0) ? unit->range : unit->group->range;
- tx[0] = tx[3] = unit->bl.x - t_range;
- tx[1] = tx[2] = unit->bl.x + t_range;
- ty[0] = ty[1] = unit->bl.y - t_range;
- ty[2] = ty[3] = unit->bl.y + t_range;
- sx[0] = sx[3] = x - range;
- sx[1] = sx[2] = x + range;
- sy[0] = sy[1] = y - range;
- sy[2] = sy[3] = y + range;
- for (i = r_flag = 0; i < 4; i++)
- {
- if (sx[i] >= tx[0] && sx[i] <= tx[1] && sy[i] >= ty[0]
- && sy[i] <= ty[2])
- {
- r_flag = 1;
- break;
- }
- if (tx[i] >= sx[0] && tx[i] <= sx[1] && ty[i] >= sy[0]
- && ty[i] <= sy[2])
- {
- r_flag = 1;
- break;
- }
- }
- if (r_flag)
- (*c)++;
-
- return 0;
-}
-
-int skill_check_unit_range (int m, int x, int y, int range, int skillid)
-{
- int c = 0;
-
- map_foreachinarea (skill_check_unit_range_sub, m, x - 10, y - 10, x + 10,
- y + 10, BL_SKILL, &c, x, y, range, skillid);
-
- return c;
-}
-
-static int skill_check_unit_range2_sub (struct block_list *bl, va_list ap)
-{
- int *c;
-
- nullpo_retr (0, bl);
- nullpo_retr (0, ap);
- nullpo_retr (0, c = va_arg (ap, int *));
-
- if (bl->prev == NULL || (bl->type != BL_PC && bl->type != BL_MOB))
- return 0;
-
- if (bl->type == BL_PC && pc_isdead ((struct map_session_data *) bl))
- return 0;
-
- (*c)++;
-
- return 0;
-}
-
-int skill_check_unit_range2 (int m, int x, int y, int range)
-{
- int c = 0;
-
- map_foreachinarea (skill_check_unit_range2_sub, m, x - range, y - range,
- x + range, y + range, 0, &c);
-
- return c;
-}
-
-/*=========================================================================
- * 範囲スキル使用処ç†å°åˆ†ã‘ã“ã“ã‹ã‚‰
- */
-/* 対象ã®æ•°ã‚’カウントã™ã‚‹ã€‚(skill_area_temp[0]ã‚’åˆæœŸåŒ–ã—ã¦ãŠãã“ã¨ï¼‰ */
static
-int skill_area_sub_count (struct block_list *src, struct block_list *target,
- int skillid, int skilllv, unsigned int tick,
- int flag)
+void skill_area_sub(struct block_list *bl,
+ struct block_list *src, SkillID skill_id, int skill_lv,
+ tick_t tick, BCT flag, SkillFunc func)
{
- if (skill_area_temp[0] < 0xffff)
- skill_area_temp[0]++;
- return 0;
-}
+ nullpo_retv(bl);
-/*==========================================
- *
- *------------------------------------------
- */
-static void skill_timer (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;
- struct block_list *src = map_id2bl (id), *target;
- struct skill_timerskill *skl = NULL;
- int range;
-
- nullpo_retv (src);
-
- if (src->prev == NULL)
- return;
-
- if (src->type == BL_PC)
- {
- nullpo_retv (sd = (struct map_session_data *) src);
- skl = &sd->skilltimerskill[data];
- }
- else if (src->type == BL_MOB)
- {
- nullpo_retv (md = (struct mob_data *) src);
- skl = &md->skilltimerskill[data];
- }
-
- else
+ if (bl->type != BL::PC && bl->type != BL::MOB)
return;
- nullpo_retv (skl);
-
- skl->timer = -1;
- if (skl->target_id)
- {
- struct block_list tbl;
- target = map_id2bl (skl->target_id);
- if (skl->skill_id == RG_INTIMIDATE)
- {
- if (target == NULL)
- {
- target = &tbl; //åˆæœŸåŒ–ã—ã¦ãªã„ã®ã«ã‚¢ãƒ‰ãƒ¬ã‚¹çªã£è¾¼ã‚“ã§ã„ã„ã®ã‹ãªï¼Ÿ
- target->type = BL_NUL;
- target->m = src->m;
- target->prev = target->next = NULL;
- }
- }
- if (target == NULL)
- return;
- if (target->prev == NULL && skl->skill_id != RG_INTIMIDATE)
- return;
- if (src->m != target->m)
- return;
- if (sd && pc_isdead (sd))
- return;
- if (target->type == BL_PC
- && pc_isdead ((struct map_session_data *) target)
- && skl->skill_id != RG_INTIMIDATE)
- return;
-
- switch (skl->skill_id)
- {
- case TF_BACKSLIDING:
- clif_skill_nodamage (src, src, skl->skill_id, skl->skill_lv,
- 1);
- break;
- case RG_INTIMIDATE:
- if (sd && !map[src->m].flag.noteleport)
- {
- int x, y, i, j, c;
- pc_randomwarp (sd, 3);
- for (i = 0; i < 16; i++)
- {
- j = MRAND (8);
- x = sd->bl.x + dirx[j];
- y = sd->bl.y + diry[j];
- if ((c = map_getcell (sd->bl.m, x, y)) != 1 && c != 5)
- break;
- }
- if (i >= 16)
- {
- x = sd->bl.x;
- y = sd->bl.y;
- }
- if (target->prev != NULL)
- {
- if (target->type == BL_PC
- && !pc_isdead ((struct map_session_data *)
- target))
- pc_setpos ((struct map_session_data *) target,
- map[sd->bl.m].name, x, y, 3);
- else if (target->type == BL_MOB)
- mob_warp ((struct mob_data *) target, -1, x, y,
- 3);
- }
- }
- else if (md && !map[src->m].flag.monster_noteleport)
- {
- int x, y, i, j, c;
- mob_warp (md, -1, -1, -1, 3);
- for (i = 0; i < 16; i++)
- {
- j = MRAND (8);
- x = md->bl.x + dirx[j];
- y = md->bl.y + diry[j];
- if ((c = map_getcell (md->bl.m, x, y)) != 1 && c != 5)
- break;
- }
- if (i >= 16)
- {
- x = md->bl.x;
- y = md->bl.y;
- }
- if (target->prev != NULL)
- {
- if (target->type == BL_PC
- && !pc_isdead ((struct map_session_data *)
- target))
- pc_setpos ((struct map_session_data *) target,
- map[md->bl.m].name, x, y, 3);
- else if (target->type == BL_MOB)
- mob_warp ((struct mob_data *) target, -1, x, y,
- 3);
- }
- }
- break;
-
- case BA_FROSTJOKE: /* 寒ã„ジョーク */
- case DC_SCREAM: /* スクリーム */
- range = 15; //視界全体
- map_foreachinarea (skill_frostjoke_scream, src->m,
- src->x - range, src->y - range,
- src->x + range, src->y + range, 0, src,
- skl->skill_id, skl->skill_lv, tick);
- break;
-
- default:
- skill_attack (skl->type, src, src, target, skl->skill_id,
- skl->skill_lv, tick, skl->flag);
- break;
- }
- }
- else
- {
- if (src->m != skl->map)
- return;
- switch (skl->skill_id)
- {
- case WZ_METEOR:
- if (skl->type >= 0)
- {
- skill_unitsetting (src, skl->skill_id, skl->skill_lv,
- skl->type >> 16, skl->type & 0xFFFF,
- 0);
- clif_skill_poseffect (src, skl->skill_id, skl->skill_lv,
- skl->x, skl->y, tick);
- }
- else
- skill_unitsetting (src, skl->skill_id, skl->skill_lv,
- skl->x, skl->y, 0);
- break;
- }
- }
+ if (battle_check_target(src, bl, flag) > 0)
+ func(src, bl, skill_id, skill_lv, tick, flag);
}
-/*==========================================
- *
- *------------------------------------------
- */
-int skill_addtimerskill (struct block_list *src, unsigned int tick,
- int target, int x, int y, int skill_id, int skill_lv,
- int type, int flag)
-{
- int i;
-
- nullpo_retr (1, src);
-
- if (src->type == BL_PC)
- {
- struct map_session_data *sd = (struct map_session_data *) src;
- nullpo_retr (1, sd);
- for (i = 0; i < MAX_SKILLTIMERSKILL; i++)
- {
- if (sd->skilltimerskill[i].timer == -1)
- {
- sd->skilltimerskill[i].timer =
- add_timer (tick, skill_timer, src->id, i);
- sd->skilltimerskill[i].src_id = src->id;
- sd->skilltimerskill[i].target_id = target;
- sd->skilltimerskill[i].skill_id = skill_id;
- sd->skilltimerskill[i].skill_lv = skill_lv;
- sd->skilltimerskill[i].map = src->m;
- sd->skilltimerskill[i].x = x;
- sd->skilltimerskill[i].y = y;
- sd->skilltimerskill[i].type = type;
- sd->skilltimerskill[i].flag = flag;
-
- return 0;
- }
- }
- return 1;
- }
- else if (src->type == BL_MOB)
- {
- struct mob_data *md = (struct mob_data *) src;
- nullpo_retr (1, md);
- for (i = 0; i < MAX_MOBSKILLTIMERSKILL; i++)
- {
- if (md->skilltimerskill[i].timer == -1)
- {
- md->skilltimerskill[i].timer =
- add_timer (tick, skill_timer, src->id, i);
- md->skilltimerskill[i].src_id = src->id;
- md->skilltimerskill[i].target_id = target;
- md->skilltimerskill[i].skill_id = skill_id;
- md->skilltimerskill[i].skill_lv = skill_lv;
- md->skilltimerskill[i].map = src->m;
- md->skilltimerskill[i].x = x;
- md->skilltimerskill[i].y = y;
- md->skilltimerskill[i].type = type;
- md->skilltimerskill[i].flag = flag;
-
- return 0;
- }
- }
- return 1;
- }
-
- return 1;
-}
-
-/*==========================================
- *
- *------------------------------------------
- */
-int skill_cleartimerskill (struct block_list *src)
-{
- int i;
-
- nullpo_retr (0, src);
-
- if (src->type == BL_PC)
- {
- struct map_session_data *sd = (struct map_session_data *) src;
- nullpo_retr (0, sd);
- for (i = 0; i < MAX_SKILLTIMERSKILL; i++)
- {
- if (sd->skilltimerskill[i].timer != -1)
- {
- delete_timer (sd->skilltimerskill[i].timer, skill_timer);
- sd->skilltimerskill[i].timer = -1;
- }
- }
- }
- else if (src->type == BL_MOB)
- {
- struct mob_data *md = (struct mob_data *) src;
- nullpo_retr (0, md);
- for (i = 0; i < MAX_MOBSKILLTIMERSKILL; i++)
- {
- if (md->skilltimerskill[i].timer != -1)
- {
- delete_timer (md->skilltimerskill[i].timer, skill_timer);
- md->skilltimerskill[i].timer = -1;
- }
- }
- }
-
- return 0;
-}
/* 範囲スキル使用処ç†å°åˆ†ã‘ã“ã“ã¾ã§
* -------------------------------------------------------------------------
*/
+// these variables are set in the 'else' branches,
+// and used in the (recursive) 'if' branch
+static int skill_area_temp_id, skill_area_temp_hp;
+
+
/*==========================================
* スキル使用(詠唱完了ã€ID指定攻撃系)
* (スパゲッティã«å‘ã‘ã¦ï¼‘æ­©å‰é€²ï¼(ダメãƒ))
*------------------------------------------
*/
-int skill_castend_damage_id (struct block_list *src, struct block_list *bl,
- int skillid, int skilllv, unsigned int tick,
- int flag)
+int skill_castend_damage_id(struct block_list *src, struct block_list *bl,
+ SkillID skillid, int skilllv,
+ tick_t tick, BCT flag)
{
struct map_session_data *sd = NULL;
- nullpo_retr (1, src);
- nullpo_retr (1, bl);
+ nullpo_retr(1, src);
+ nullpo_retr(1, bl);
- if (src->type == BL_PC)
+ if (src->type == BL::PC)
sd = (struct map_session_data *) src;
- if (sd && pc_isdead (sd))
+ if (sd && pc_isdead(sd))
return 1;
- if ((skillid == WZ_SIGHTRASHER || skillid == CR_GRANDCROSS) && src != bl)
- bl = src;
if (bl->prev == NULL)
return 1;
- if (bl->type == BL_PC && pc_isdead ((struct map_session_data *) bl))
+ if (bl->type == BL::PC && pc_isdead((struct map_session_data *) bl))
return 1;
- map_freeblock_lock ();
+ map_freeblock_lock();
switch (skillid)
{
- /* 武器攻撃系スキル */
- case SM_BASH: /* ãƒãƒƒã‚·ãƒ¥ */
- case MC_MAMMONITE: /* メマーナイト */
- case AC_DOUBLE: /* ダブルストレイフィング */
- case AS_SONICBLOW: /* ソニックブロー */
- case KN_PIERCE: /* ピアース */
- case KN_SPEARBOOMERANG: /* スピアブーメラン */
- case TF_POISON: /* インベナム */
- case TF_SPRINKLESAND: /* ç ‚ã¾ã */
- case AC_CHARGEARROW: /* ãƒãƒ£ãƒ¼ã‚¸ã‚¢ãƒ­ãƒ¼ */
- case KN_SPEARSTAB: /* スピアスタブ */
- case RG_RAID: /* サプライズアタック */
- case RG_INTIMIDATE: /* インティミデイト */
- case BA_MUSICALSTRIKE: /* ミュージカルストライク */
- case DC_THROWARROW: /* 矢撃㡠*/
- case BA_DISSONANCE: /* ä¸å”和音 */
- case CR_HOLYCROSS: /* ホーリークロス */
- case CR_SHIELDCHARGE:
- case CR_SHIELDBOOMERANG:
-
- /* 以下MOB専用 */
- /* å˜ä½“攻撃ã€SP減少攻撃ã€é è·é›¢æ”»æ’ƒã€é˜²å¾¡ç„¡è¦–攻撃ã€å¤šæ®µæ”»æ’ƒ */
- case NPC_PIERCINGATT:
- case NPC_MENTALBREAKER:
- case NPC_RANGEATTACK:
- case NPC_CRITICALSLASH:
- case NPC_COMBOATTACK:
- /* 必中攻撃ã€æ¯’攻撃ã€æš—黒攻撃ã€æ²ˆé»™æ”»æ’ƒã€ã‚¹ã‚¿ãƒ³æ”»æ’ƒ */
- case NPC_GUIDEDATTACK:
- case NPC_POISON:
- case NPC_BLINDATTACK:
- case NPC_SILENCEATTACK:
- case NPC_STUNATTACK:
- /* 石化攻撃ã€å‘ªã„攻撃ã€ç¡çœ æ”»æ’ƒã€ãƒ©ãƒ³ãƒ€ãƒ ATK攻撃 */
- case NPC_PETRIFYATTACK:
- case NPC_CURSEATTACK:
- case NPC_SLEEPATTACK:
- case NPC_RANDOMATTACK:
- /* 水属性攻撃ã€åœ°å±žæ€§æ”»æ’ƒã€ç«å±žæ€§æ”»æ’ƒã€é¢¨å±žæ€§æ”»æ’ƒ */
- case NPC_WATERATTACK:
- case NPC_GROUNDATTACK:
- case NPC_FIREATTACK:
- case NPC_WINDATTACK:
- /* 毒属性攻撃ã€è–属性攻撃ã€é—‡å±žæ€§æ”»æ’ƒã€å¿µå±žæ€§æ”»æ’ƒã€SP減少攻撃 */
- case NPC_POISONATTACK:
- case NPC_HOLYATTACK:
- case NPC_DARKNESSATTACK:
- case NPC_TELEKINESISATTACK:
- case LK_AURABLADE: /* オーラブレード */
- case LK_SPIRALPIERCE: /* スパイラルピアース */
- case LK_HEADCRUSH: /* ヘッドクラッシュ */
- case LK_JOINTBEAT: /* ジョイントビート */
- case PA_PRESSURE: /* プレッシャー */
- case PA_SACRIFICE: /* サクリファイス */
- case SN_SHARPSHOOTING: /* シャープシューティング */
- case CG_ARROWVULCAN: /* アローãƒãƒ«ã‚«ãƒ³ */
- case ASC_BREAKER: /* ソウルブレーカー */
- case HW_MAGICCRASHER: /* マジッククラッシャー */
- skill_attack (BF_WEAPON, src, src, bl, skillid, skilllv, tick,
- flag);
- break;
- case NPC_DARKBREATH:
- clif_emotion (src, 7);
- skill_attack (BF_MISC, src, src, bl, skillid, skilllv, tick,
- flag);
- break;
- case MO_INVESTIGATE: /* ç™ºå‹ */
- {
- struct status_change *sc_data = battle_get_sc_data (src);
- skill_attack (BF_WEAPON, src, src, bl, skillid, skilllv, tick,
+ case SkillID::NPC_POISON:
+ skill_attack(BF::WEAPON, src, src, bl, skillid, skilllv, tick,
flag);
- if (sc_data[SC_BLADESTOP].timer != -1)
- skill_status_change_end (src, SC_BLADESTOP, -1);
- }
- break;
- case SN_FALCONASSAULT: /* ファルコンアサルト */
- skill_attack (BF_MISC, src, src, bl, skillid, skilllv, tick,
- flag);
- break;
- case KN_BRANDISHSPEAR: /* ブランディッシュスピア */
- {
- struct mob_data *md = (struct mob_data *) bl;
- nullpo_retr (1, md);
- skill_attack (BF_WEAPON, src, src, bl, skillid, skilllv, tick,
- flag);
- if (md->hp > 0)
- {
- skill_blown (src, bl, skill_get_blewcount (skillid, skilllv));
- if (bl->type == BL_MOB)
- clif_fixmobpos ((struct mob_data *) bl);
- else
- clif_fixpos (bl);
- }
- }
- break;
- case RG_BACKSTAP: /* ãƒãƒƒã‚¯ã‚¹ã‚¿ãƒ– */
- {
- int dir = map_calc_dir (src, bl->x, bl->y), t_dir =
- battle_get_dir (bl);
- int dist = distance (src->x, src->y, bl->x, bl->y);
- if ((dist > 0 && !map_check_dir (dir, t_dir))
- || bl->type == BL_SKILL)
- {
- struct status_change *sc_data = battle_get_sc_data (src);
- if (sc_data && sc_data[SC_HIDING].timer != -1)
- skill_status_change_end (src, SC_HIDING, -1); // ãƒã‚¤ãƒ‡ã‚£ãƒ³ã‚°è§£é™¤
- skill_attack (BF_WEAPON, src, src, bl, skillid, skilllv, tick,
- flag);
- skill_blown (src, bl, skill_get_blewcount (skillid, skilllv));
- }
- else if (src->type == BL_PC)
- clif_skill_fail (sd, sd->skillid, 0, 0);
- }
break;
- case AM_ACIDTERROR: /* アシッドテラー */
- skill_attack (BF_WEAPON, src, src, bl, skillid, skilllv, tick,
- flag);
- if (bl->type == BL_PC
- && MRAND (100) < skill_get_time (skillid, skilllv)
- && battle_config.equipment_breaking)
- pc_breakarmor ((struct map_session_data *) bl);
- break;
- case MO_FINGEROFFENSIVE: /* 指弾 */
- {
- struct status_change *sc_data = battle_get_sc_data (src);
-
- if (!battle_config.finger_offensive_type)
- skill_attack (BF_WEAPON, src, src, bl, skillid, skilllv, tick,
- flag);
- else
- {
- skill_attack (BF_WEAPON, src, src, bl, skillid, skilllv, tick,
- flag);
- if (sd)
- {
- for (int i = 1; i < sd->spiritball_old; i++)
- skill_addtimerskill (src, tick + i * 200, bl->id, 0,
- 0, skillid, skilllv, BF_WEAPON,
- flag);
- sd->canmove_tick = tick + (sd->spiritball_old - 1) * 200;
- }
- }
- if (sc_data && sc_data[SC_BLADESTOP].timer != -1)
- skill_status_change_end (src, SC_BLADESTOP, -1);
- }
- break;
- case MO_CHAINCOMBO: /* 連打掌 */
- {
- struct status_change *sc_data = battle_get_sc_data (src);
- skill_attack (BF_WEAPON, src, src, bl, skillid, skilllv, tick,
- flag);
- if (sc_data && sc_data[SC_BLADESTOP].timer != -1)
- skill_status_change_end (src, SC_BLADESTOP, -1);
- }
- break;
- case MO_COMBOFINISH: /* 猛é¾æ‹³ */
- case CH_TIGERFIST: /* ä¼è™Žæ‹³ */
- case CH_CHAINCRUSH: /* 連柱崩撃 */
- case CH_PALMSTRIKE: /* 猛虎硬派山 */
- skill_attack (BF_WEAPON, src, src, bl, skillid, skilllv, tick,
- flag);
- break;
- case MO_EXTREMITYFIST: /* 阿修羅覇鳳拳 */
- {
- struct status_change *sc_data = battle_get_sc_data (src);
-
- if (sd)
- {
- struct walkpath_data wpd;
- int dx, dy;
-
- dx = bl->x - sd->bl.x;
- dy = bl->y - sd->bl.y;
- if (dx > 0)
- dx++;
- else if (dx < 0)
- dx--;
- if (dy > 0)
- dy++;
- else if (dy < 0)
- dy--;
- if (dx == 0 && dy == 0)
- dx++;
- if (path_search
- (&wpd, src->m, sd->bl.x, sd->bl.y, sd->bl.x + dx,
- sd->bl.y + dy, 1) == -1)
- {
- dx = bl->x - sd->bl.x;
- dy = bl->y - sd->bl.y;
- if (path_search
- (&wpd, src->m, sd->bl.x, sd->bl.y, sd->bl.x + dx,
- sd->bl.y + dy, 1) == -1)
- {
- clif_skill_fail (sd, sd->skillid, 0, 0);
- break;
- }
- }
- sd->to_x = sd->bl.x + dx;
- sd->to_y = sd->bl.y + dy;
- skill_attack (BF_WEAPON, src, src, bl, skillid, skilllv, tick,
- flag);
- clif_walkok (sd);
- clif_movechar (sd);
- if (dx < 0)
- dx = -dx;
- if (dy < 0)
- dy = -dy;
- sd->attackabletime = sd->canmove_tick =
- tick + 100 + sd->speed * ((dx > dy) ? dx : dy);
- if (sd->canact_tick < sd->canmove_tick)
- sd->canact_tick = sd->canmove_tick;
- pc_movepos (sd, sd->to_x, sd->to_y);
- skill_status_change_end (&sd->bl, SC_COMBO, -1);
- }
- else
- skill_attack (BF_WEAPON, src, src, bl, skillid, skilllv, tick,
- flag);
- skill_status_change_end (src, SC_EXPLOSIONSPIRITS, -1);
- if (sc_data && sc_data[SC_BLADESTOP].timer != -1)
- skill_status_change_end (src, SC_BLADESTOP, -1);
- }
- break;
- /* 武器系範囲攻撃スキル */
- case AC_SHOWER: /* アローシャワー */
- case SM_MAGNUM: /* マグナムブレイク */
- case AS_GRIMTOOTH: /* グリムトゥース */
- case MC_CARTREVOLUTION: /* カートレヴォリューション */
- case NPC_SPLASHATTACK: /* スプラッシュアタック */
- case ASC_METEORASSAULT: /* メテオアサルト */
- case AS_SPLASHER: /* [Valaris] */
- if (flag & 1)
+ case SkillID::NPC_SELFDESTRUCTION: /* 自爆 */
+ if (flag.lo & 1)
{
/* 個別ã«ãƒ€ãƒ¡ãƒ¼ã‚¸ã‚’与ãˆã‚‹ */
- if (bl->id != skill_area_temp[1])
- {
- int dist = 0;
- if (skillid == SM_MAGNUM)
- { /* マグナムブレイクãªã‚‰ä¸­å¿ƒã‹ã‚‰ã®è·é›¢ã‚’計算 */
- int dx = abs (bl->x - skill_area_temp[2]);
- int dy = abs (bl->y - skill_area_temp[3]);
- dist = ((dx > dy) ? dx : dy);
- }
- skill_attack (BF_WEAPON, src, src, bl, skillid, skilllv,
- tick, 0x0500 | dist);
- }
- }
- else
- {
- int ar = 1;
- int x = bl->x, y = bl->y;
- if (skillid == SM_MAGNUM)
- {
- x = src->x;
- y = src->y;
- }
- else if (skillid == AC_SHOWER || skillid == ASC_METEORASSAULT) /* アローシャワーã€ãƒ¡ãƒ†ã‚ªã‚¢ã‚µãƒ«ãƒˆç¯„囲5*5 */
- ar = 2;
- else if (skillid == AS_SPLASHER) /* ベナムスプラッシャー範囲3*3 */
- ar = 1;
- else if (skillid == NPC_SPLASHATTACK) /* スプラッシュアタックã¯ç¯„囲7*7 */
- ar = 3;
- skill_area_temp[1] = bl->id;
- skill_area_temp[2] = x;
- skill_area_temp[3] = y;
- /* ã¾ãšã‚¿ãƒ¼ã‚²ãƒƒãƒˆã«æ”»æ’ƒã‚’加ãˆã‚‹ */
- skill_attack (BF_WEAPON, src, src, bl, skillid, skilllv, tick,
- 0);
- /* ãã®å¾Œã‚¿ãƒ¼ã‚²ãƒƒãƒˆä»¥å¤–ã®ç¯„囲内ã®æ•µå…¨ä½“ã«å‡¦ç†ã‚’行ㆠ*/
- map_foreachinarea (skill_area_sub,
- bl->m, x - ar, y - ar, x + ar, y + ar, 0,
- src, skillid, skilllv, tick,
- flag | BCT_ENEMY | 1,
- skill_castend_damage_id);
- }
- break;
-
- case KN_BOWLINGBASH: /* ボウリングãƒãƒƒã‚·ãƒ¥ */
- if (flag & 1)
- {
- /* 個別ã«ãƒ€ãƒ¡ãƒ¼ã‚¸ã‚’与ãˆã‚‹ */
- if (bl->id != skill_area_temp[1])
- skill_attack (BF_WEAPON, src, src, bl, skillid, skilllv,
- tick, 0x0500);
- }
- else
- {
- int damage;
- map_freeblock_lock ();
- damage =
- skill_attack (BF_WEAPON, src, src, bl, skillid, skilllv,
- tick, 0);
- if (damage > 0)
- {
- int i, c; /* 他人ã‹ã‚‰èžã„ãŸå‹•ããªã®ã§é–“é•ã£ã¦ã‚‹å¯èƒ½æ€§å¤§ï¼†åŠ¹çŽ‡ãŒæ‚ªã„ã£ã™ï¼žï¼œ */
- c = skill_get_blewcount (skillid, skilllv);
- if (map[bl->m].flag.gvg)
- c = 0;
- for (i = 0; i < c; i++)
- {
- skill_blown (src, bl, 1);
- if (bl->type == BL_MOB)
- clif_fixmobpos ((struct mob_data *) bl);
- else
- clif_fixpos (bl);
- skill_area_temp[0] = 0;
- map_foreachinarea (skill_area_sub,
- bl->m, bl->x - 1, bl->y - 1,
- bl->x + 1, bl->y + 1, 0, src,
- skillid, skilllv, tick,
- flag | BCT_ENEMY,
- skill_area_sub_count);
- if (skill_area_temp[0] > 1)
- break;
- }
- skill_area_temp[1] = bl->id;
- skill_area_temp[2] = bl->x;
- skill_area_temp[3] = bl->y;
- /* ãã®å¾Œã‚¿ãƒ¼ã‚²ãƒƒãƒˆä»¥å¤–ã®ç¯„囲内ã®æ•µå…¨ä½“ã«å‡¦ç†ã‚’行ㆠ*/
- map_foreachinarea (skill_area_sub,
- bl->m, bl->x - 1, bl->y - 1, bl->x + 1,
- bl->y + 1, 0, src, skillid, skilllv,
- tick, flag | BCT_ENEMY | 1,
- skill_castend_damage_id);
- battle_damage (src, bl, damage, 1);
- if (rdamage > 0)
- battle_damage (bl, src, rdamage, 0);
- }
- map_freeblock_unlock ();
- }
- break;
-
- case ALL_RESURRECTION: /* リザレクション */
- case PR_TURNUNDEAD: /* ターンアンデッド */
- if (bl->type != BL_PC
- && battle_check_undead (battle_get_race (bl),
- battle_get_elem_type (bl)))
- skill_attack (BF_MAGIC, src, src, bl, skillid, skilllv, tick,
- flag);
- else
- {
- map_freeblock_unlock ();
- return 1;
- }
- break;
-
- /* 魔法系スキル */
- case MG_SOULSTRIKE: /* ソウルストライク */
- case MG_COLDBOLT: /* コールドボルト */
- case MG_FIREBOLT: /* ファイアーボルト */
- case MG_LIGHTNINGBOLT: /* ライトニングボルト */
- case WZ_EARTHSPIKE: /* アーススパイク */
- case AL_HEAL: /* ヒール */
- case AL_HOLYLIGHT: /* ホーリーライト */
- case MG_FROSTDIVER: /* フロストダイãƒãƒ¼ */
- case WZ_JUPITEL: /* ユピテルサンダー */
- case NPC_MAGICALATTACK: /* MOB:魔法打撃攻撃 */
- case PR_ASPERSIO: /* アスペルシオ */
- skill_attack (BF_MAGIC, src, src, bl, skillid, skilllv, tick,
- flag);
- break;
-
- case WZ_WATERBALL: /* ウォーターボール */
- skill_attack (BF_MAGIC, src, src, bl, skillid, skilllv, tick,
- flag);
- if (skilllv > 1)
- skill_status_change_start (src, SC_WATERBALL, skilllv, bl->id,
- 0, 0, 0, 0);
- break;
-
- case PR_BENEDICTIO: /* è–体é™ç¦ */
- if (battle_get_race (bl) == 1 || battle_get_race (bl) == 6)
- skill_attack (BF_MAGIC, src, src, bl, skillid, skilllv, tick,
- flag);
- break;
-
- /* 魔法系範囲攻撃スキル */
- case MG_NAPALMBEAT: /* ナパームビート */
- case MG_FIREBALL: /* ファイヤーボール */
- if (flag & 1)
- {
- /* 個別ã«ãƒ€ãƒ¡ãƒ¼ã‚¸ã‚’与ãˆã‚‹ */
- if (bl->id != skill_area_temp[1])
- {
- if (skillid == MG_FIREBALL)
- { /* ファイヤーボールãªã‚‰ä¸­å¿ƒã‹ã‚‰ã®è·é›¢ã‚’計算 */
- int dx = abs (bl->x - skill_area_temp[2]);
- int dy = abs (bl->y - skill_area_temp[3]);
- skill_area_temp[0] = ((dx > dy) ? dx : dy);
- }
- skill_attack (BF_MAGIC, src, src, bl, skillid, skilllv,
- tick, skill_area_temp[0] | 0x0500);
- }
- }
- else
- {
- int ar = (skillid == MG_NAPALMBEAT) ? 1 : 2;
- skill_area_temp[1] = bl->id;
- if (skillid == MG_NAPALMBEAT)
- { /* ナパームã§ã¯å…ˆã«æ•°ãˆã‚‹ */
- skill_area_temp[0] = 0;
- map_foreachinarea (skill_area_sub,
- bl->m, bl->x - 1, bl->y - 1, bl->x + 1,
- bl->y + 1, 0, src, skillid, skilllv,
- tick, flag | BCT_ENEMY,
- skill_area_sub_count);
- }
- else
- {
- skill_area_temp[0] = 0;
- skill_area_temp[2] = bl->x;
- skill_area_temp[3] = bl->y;
- }
- /* ã¾ãšã‚¿ãƒ¼ã‚²ãƒƒãƒˆã«æ”»æ’ƒã‚’加ãˆã‚‹ */
- skill_attack (BF_MAGIC, src, src, bl, skillid, skilllv, tick,
- skill_area_temp[0]);
- /* ãã®å¾Œã‚¿ãƒ¼ã‚²ãƒƒãƒˆä»¥å¤–ã®ç¯„囲内ã®æ•µå…¨ä½“ã«å‡¦ç†ã‚’行ㆠ*/
- map_foreachinarea (skill_area_sub,
- bl->m, bl->x - ar, bl->y - ar, bl->x + ar,
- bl->y + ar, 0, src, skillid, skilllv, tick,
- flag | BCT_ENEMY | 1,
- skill_castend_damage_id);
- }
- break;
-
- case HW_NAPALMVULCAN: // Fixed By SteelViruZ
- if (flag & 1)
- {
- if (bl->id != skill_area_temp[1])
- {
- skill_attack (BF_MAGIC, src, src, bl, skillid, skilllv,
- tick, skill_area_temp[0]);
- }
- }
- else
- {
- int ar = (skillid == HW_NAPALMVULCAN) ? 1 : 2;
- skill_area_temp[1] = bl->id;
- if (skillid == HW_NAPALMVULCAN)
- {
- skill_area_temp[0] = 0;
- map_foreachinarea (skill_area_sub,
- bl->m, bl->x - 1, bl->y - 1, bl->x + 1,
- bl->y + 1, 0, src, skillid, skilllv,
- tick, flag | BCT_ENEMY,
- skill_area_sub_count);
- }
- else
- {
- skill_area_temp[0] = 0;
- skill_area_temp[2] = bl->x;
- skill_area_temp[3] = bl->y;
- }
- skill_attack (BF_MAGIC, src, src, bl, skillid, skilllv, tick,
- skill_area_temp[0]);
- map_foreachinarea (skill_area_sub,
- bl->m, bl->x - ar, bl->y - ar, bl->x + ar,
- bl->y + ar, 0, src, skillid, skilllv, tick,
- flag | BCT_ENEMY | 1,
- skill_castend_damage_id);
- }
- break;
-
- case WZ_FROSTNOVA: /* フロストノヴァ */
- skill_castend_pos2 (src, bl->x, bl->y, skillid, skilllv, tick, 0);
- skill_attack (BF_MAGIC, src, src, bl, skillid, skilllv, tick,
- flag);
- break;
-
- case WZ_SIGHTRASHER:
- clif_skill_nodamage (src, bl, skillid, skilllv, 1);
- skill_castend_pos2 (src, bl->x, bl->y, skillid, skilllv, tick, 0);
- skill_status_change_end (src, SC_SIGHT, -1);
- break;
-
- /* ãã®ä»– */
- case HT_BLITZBEAT: /* ブリッツビート */
- if (flag & 1)
- {
- /* 個別ã«ãƒ€ãƒ¡ãƒ¼ã‚¸ã‚’与ãˆã‚‹ */
- if (bl->id != skill_area_temp[1])
- skill_attack (BF_MISC, src, src, bl, skillid, skilllv,
- tick,
- skill_area_temp[0] | (flag & 0xf00000));
- }
- else
- {
- skill_area_temp[0] = 0;
- skill_area_temp[1] = bl->id;
- if (flag & 0xf00000)
- map_foreachinarea (skill_area_sub, bl->m, bl->x - 1,
- bl->y - 1, bl->x + 1, bl->y + 1, 0,
- src, skillid, skilllv, tick,
- flag | BCT_ENEMY,
- skill_area_sub_count);
- /* ã¾ãšã‚¿ãƒ¼ã‚²ãƒƒãƒˆã«æ”»æ’ƒã‚’加ãˆã‚‹ */
- skill_attack (BF_MISC, src, src, bl, skillid, skilllv, tick,
- skill_area_temp[0] | (flag & 0xf00000));
- /* ãã®å¾Œã‚¿ãƒ¼ã‚²ãƒƒãƒˆä»¥å¤–ã®ç¯„囲内ã®æ•µå…¨ä½“ã«å‡¦ç†ã‚’行ㆠ*/
- map_foreachinarea (skill_area_sub,
- bl->m, bl->x - 1, bl->y - 1, bl->x + 1,
- bl->y + 1, 0, src, skillid, skilllv, tick,
- flag | BCT_ENEMY | 1,
- skill_castend_damage_id);
- }
- break;
-
- case CR_GRANDCROSS: /* グランドクロス */
- /* スキルユニットé…ç½® */
- skill_castend_pos2 (src, bl->x, bl->y, skillid, skilllv, tick, 0);
- if (sd)
- sd->canmove_tick = tick + 1000;
- else if (src->type == BL_MOB)
- mob_changestate ((struct mob_data *) src, MS_DELAY, 1000);
- break;
-
- case TF_THROWSTONE: /* 石投㒠*/
- case NPC_SMOKING: /* スモーキング */
- skill_attack (BF_MISC, src, src, bl, skillid, skilllv, tick, 0);
- break;
-
- case NPC_SELFDESTRUCTION: /* 自爆 */
- case NPC_SELFDESTRUCTION2: /* 自爆2 */
- if (flag & 1)
- {
- /* 個別ã«ãƒ€ãƒ¡ãƒ¼ã‚¸ã‚’与ãˆã‚‹ */
- if (src->type == BL_MOB)
+ if (src->type == BL::MOB)
{
struct mob_data *mb = (struct mob_data *) src;
- nullpo_retr (1, mb);
- mb->hp = skill_area_temp[2];
- if (bl->id != skill_area_temp[1])
- skill_attack (BF_MISC, src, src, bl,
- NPC_SELFDESTRUCTION, skilllv, tick,
+ nullpo_retr(1, mb);
+ mb->hp = skill_area_temp_hp;
+ if (bl->id != skill_area_temp_id)
+ skill_attack(BF::MISC, src, src, bl,
+ SkillID::NPC_SELFDESTRUCTION, skilllv, tick,
flag);
mb->hp = 1;
}
@@ -3078,69 +435,44 @@ int skill_castend_damage_id (struct block_list *src, struct block_list *bl,
struct mob_data *md;
if ((md = (struct mob_data *) src))
{
- skill_area_temp[1] = bl->id;
- skill_area_temp[2] = battle_get_hp (src);
- clif_skill_nodamage (src, src, NPC_SELFDESTRUCTION, -1,
- 1);
- map_foreachinarea (skill_area_sub, bl->m, bl->x - 5,
- bl->y - 5, bl->x + 5, bl->y + 5, 0,
- src, skillid, skilllv, tick,
- flag | BCT_ENEMY | 1,
- skill_castend_damage_id);
- battle_damage (src, src, md->hp, 0);
+ skill_area_temp_id = bl->id;
+ skill_area_temp_hp = battle_get_hp(src);
+ map_foreachinarea(std::bind(skill_area_sub, ph::_1, src, skillid, skilllv,
+ tick, flag | BCT_ENEMY | BCT_lo_x01, skill_castend_damage_id),
+ bl->m, bl->x - 5, bl->y - 5,
+ bl->x + 5, bl->y + 5, BL::NUL);
+ battle_damage(src, src, md->hp, 0);
}
}
break;
/* HPå¸åŽ/HPå¸åŽé­”法 */
- case NPC_BLOODDRAIN:
- case NPC_ENERGYDRAIN:
- {
- int heal;
- heal =
- skill_attack ((skillid ==
- NPC_BLOODDRAIN) ? BF_WEAPON : BF_MAGIC, src,
- src, bl, skillid, skilllv, tick, flag);
- if (heal > 0)
- {
- struct block_list tbl;
- tbl.id = 0;
- tbl.m = src->m;
- tbl.x = src->x;
- tbl.y = src->y;
- clif_skill_nodamage (&tbl, src, AL_HEAL, heal, 1);
- battle_heal (NULL, src, heal, 0, 0);
- }
- }
- break;
- case 0:
+ case SkillID::ZERO:
if (sd)
{
- if (flag & 3)
+ if (flag.lo & 3)
{
- if (bl->id != skill_area_temp[1])
- skill_attack (BF_WEAPON, src, src, bl, skillid,
- skilllv, tick, 0x0500);
+ if (bl->id != skill_area_temp_id)
+ skill_attack(BF::WEAPON, src, src, bl, skillid,
+ skilllv, tick, BCT_mid_x05);
}
else
{
- int ar = sd->splash_range;
- skill_area_temp[1] = bl->id;
- map_foreachinarea (skill_area_sub,
- bl->m, bl->x - ar, bl->y - ar,
- bl->x + ar, bl->y + ar, 0, src,
- skillid, skilllv, tick,
- flag | BCT_ENEMY | 1,
- skill_castend_damage_id);
+ // TODO does this happen?
+ skill_area_temp_id = bl->id;
+ map_foreachinarea(std::bind(skill_area_sub, ph::_1, src, skillid, skilllv,
+ tick, flag | BCT_ENEMY | BCT_lo_x01, skill_castend_damage_id),
+ bl->m, bl->x - 0, bl->y - 0,
+ bl->x + 0, bl->y + 0, BL::NUL);
}
}
break;
default:
- map_freeblock_unlock ();
+ map_freeblock_unlock();
return 1;
}
- map_freeblock_unlock ();
+ map_freeblock_unlock();
return 0;
}
@@ -3149,45 +481,39 @@ int skill_castend_damage_id (struct block_list *src, struct block_list *bl,
* スキル使用(詠唱完了ã€ID指定支æ´ç³»ï¼‰
*------------------------------------------
*/
-int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl,
- int skillid, int skilllv, unsigned int tick,
- int flag)
+// skillid.nk == 1
+// so skillid in (SkillID::NPC_SUMMONSLAVE, SkillID::NPC_EMOTION)
+int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl,
+ SkillID skillid, int skilllv)
{
struct map_session_data *sd = NULL;
struct map_session_data *dstsd = NULL;
struct mob_data *md = NULL;
struct mob_data *dstmd = NULL;
- int sc_def_vit, sc_def_mdef, strip_fix, strip_time, strip_per;
- int sc_dex, sc_luk;
- //クラスãƒã‚§ãƒ³ã‚¸ç”¨ãƒœã‚¹ãƒ¢ãƒ³ã‚¹ã‚¿ãƒ¼ID
- int changeclass[] =
- { 1038, 1039, 1046, 1059, 1086, 1087, 1112, 1115, 1157, 1159, 1190,
- 1272, 1312, 1373, 1492
- };
- int poringclass[] = { 1002 };
-
- nullpo_retr (1, src);
- nullpo_retr (1, bl);
-
- if (src->type == BL_PC)
+ int sc_def_vit, sc_def_mdef, strip_fix;
+
+ nullpo_retr(1, src);
+ nullpo_retr(1, bl);
+
+ if (src->type == BL::PC)
sd = (struct map_session_data *) src;
- else if (src->type == BL_MOB)
+ else if (src->type == BL::MOB)
md = (struct mob_data *) src;
- sc_dex = battle_get_mdef (bl);
- sc_luk = battle_get_luk (bl);
- sc_def_vit = 100 - (3 + battle_get_vit (bl) + battle_get_luk (bl) / 3);
- sc_def_vit = 100 - (3 + battle_get_vit (bl) + battle_get_luk (bl) / 3);
- sc_def_mdef = 100 - (3 + battle_get_mdef (bl) + battle_get_luk (bl) / 3);
- strip_fix = battle_get_dex (src) - battle_get_dex (bl);
+ sc_def_vit = 100 - (3 + battle_get_vit(bl) + battle_get_luk(bl) / 3);
+ sc_def_vit = 100 - (3 + battle_get_vit(bl) + battle_get_luk(bl) / 3);
+ sc_def_mdef = 100 - (3 + battle_get_mdef(bl) + battle_get_luk(bl) / 3);
+ strip_fix = battle_get_dex(src) - battle_get_dex(bl);
- if (bl->type == BL_PC)
+ if (bl->type == BL::PC)
{
- nullpo_retr (1, dstsd = (struct map_session_data *) bl);
+ dstsd = (struct map_session_data *) bl;
+ nullpo_retr(1, dstsd);
}
- else if (bl->type == BL_MOB)
+ else if (bl->type == BL::MOB)
{
- nullpo_retr (1, dstmd = (struct mob_data *) bl);
+ dstmd = (struct mob_data *) bl;
+ nullpo_retr(1, dstmd);
if (sc_def_vit > 50)
sc_def_vit = 50;
if (sc_def_mdef > 50)
@@ -3202,6260 +528,346 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl,
if (bl == NULL || bl->prev == NULL)
return 1;
- if (sd && pc_isdead (sd))
- return 1;
- if (dstsd && pc_isdead (dstsd) && skillid != ALL_RESURRECTION)
+ if (sd && pc_isdead(sd))
return 1;
- if (battle_get_class (bl) == 1288)
+ if (dstsd && pc_isdead(dstsd))
return 1;
- if (skillnotok (skillid, (struct map_session_data *) bl)) // [MouseJstr]
- return 0;
- map_freeblock_lock ();
+ map_freeblock_lock();
switch (skillid)
{
- case AL_HEAL: /* ヒール */
- {
- int heal = skill_calc_heal (src, skilllv);
- int heal_get_jobexp;
- int skill;
- struct pc_base_job s_class;
-
- if (dstsd && dstsd->special_state.no_magic_damage)
- heal = 0; /* 黄金蟲カード(ヒールé‡ï¼ï¼‰ */
- if (sd)
- {
- s_class = pc_calc_base_job (sd->status.pc_class);
- if ((skill = pc_checkskill (sd, HP_MEDITATIO)) > 0) // メディテイティオ
- heal += heal * (skill * 2 / 100);
- if (sd && dstsd && sd->status.partner_id == dstsd->status.char_id && s_class.job == 23 && sd->status.sex == 0) //自分も対象もPCã€å¯¾è±¡ãŒè‡ªåˆ†ã®ãƒ‘ートナーã€è‡ªåˆ†ãŒã‚¹ãƒ‘ノビã€è‡ªåˆ†ãŒâ™€ãªã‚‰
- heal = heal * 2; //スパノビã®å«ãŒæ—¦é‚£ã«ãƒ’ールã™ã‚‹ã¨2å€ã«ãªã‚‹
- }
-
- clif_skill_nodamage (src, bl, skillid, heal, 1);
- heal_get_jobexp = battle_heal (NULL, bl, heal, 0, 0);
-
- // JOB経験値ç²å¾—
- if (src->type == BL_PC && bl->type == BL_PC && heal > 0
- && src != bl && battle_config.heal_exp > 0)
- {
- heal_get_jobexp =
- heal_get_jobexp * battle_config.heal_exp / 100;
- if (heal_get_jobexp <= 0)
- heal_get_jobexp = 1;
- pc_gainexp ((struct map_session_data *) src, 0,
- heal_get_jobexp);
- }
- }
- break;
-
- case ALL_RESURRECTION: /* リザレクション */
- if (bl->type == BL_PC)
- {
- int per = 0;
- struct map_session_data *tsd = (struct map_session_data *) bl;
- nullpo_retr (1, tsd);
- if ((map[bl->m].flag.pvp) && tsd->pvp_point < 0)
- break; /* PVPã§å¾©æ´»ä¸å¯èƒ½çŠ¶æ…‹ */
-
- if (pc_isdead (tsd))
- { /* 死亡判定 */
- clif_skill_nodamage (src, bl, skillid, skilllv, 1);
- switch (skilllv)
- {
- case 1:
- per = 10;
- break;
- case 2:
- per = 30;
- break;
- case 3:
- per = 50;
- break;
- case 4:
- per = 80;
- break;
- }
- tsd->status.hp = tsd->status.max_hp * per / 100;
- if (tsd->status.hp <= 0)
- tsd->status.hp = 1;
- if (tsd->special_state.restart_full_recover)
- { /* オシリスカード */
- tsd->status.hp = tsd->status.max_hp;
- tsd->status.sp = tsd->status.max_sp;
- }
- pc_setstand (tsd);
- if (battle_config.pc_invincible_time > 0)
- pc_setinvincibletimer (tsd,
- battle_config.pc_invincible_time);
- clif_updatestatus (tsd, SP_HP);
- clif_resurrection (&tsd->bl, 1);
- if (src != bl && sd && battle_config.resurrection_exp > 0)
- {
- int exp = 0, jexp = 0;
- int lv =
- tsd->status.base_level - sd->status.base_level,
- jlv =
- tsd->status.job_level - sd->status.job_level;
- if (lv > 0)
- {
- exp =
- (int) ((double) tsd->status.base_exp *
- (double) lv *
- (double) battle_config.resurrection_exp
- / 1000000.);
- if (exp < 1)
- exp = 1;
- }
- if (jlv > 0)
- {
- jexp =
- (int) ((double) tsd->status.job_exp *
- (double) lv *
- (double) battle_config.resurrection_exp
- / 1000000.);
- if (jexp < 1)
- jexp = 1;
- }
- if (exp > 0 || jexp > 0)
- pc_gainexp (sd, exp, jexp);
- }
- }
- }
- break;
-
- case AL_DECAGI: /* 速度減少 */
- if (bl->type == BL_PC
- && ((struct map_session_data *) bl)->
- special_state.no_magic_damage)
- break;
- if (MRAND (100) <
- (50 + skilllv * 3 +
- (battle_get_lv (src) + battle_get_int (src) / 5) -
- sc_def_mdef))
- {
- clif_skill_nodamage (src, bl, skillid, skilllv, 1);
- skill_status_change_start (bl,
- SkillStatusChangeTable[skillid],
- skilllv, 0, 0, 0,
- skill_get_time (skillid, skilllv),
- 0);
- }
- break;
-
- case AL_CRUCIS:
- if (flag & 1)
- {
- int race = battle_get_race (bl), ele =
- battle_get_elem_type (bl);
- if (battle_check_target (src, bl, BCT_ENEMY)
- && (race == 6 || battle_check_undead (race, ele)))
- {
- int slv = battle_get_lv (src), tlv =
- battle_get_lv (bl), rate;
- rate = 25 + skilllv * 2 + slv - tlv;
- if (MRAND (100) < rate)
- skill_status_change_start (bl,
- SkillStatusChangeTable
- [skillid], skilllv, 0, 0,
- 0, 0, 0);
- }
- }
- else
- {
- int range = 15;
- clif_skill_nodamage (src, bl, skillid, skilllv, 1);
- map_foreachinarea (skill_area_sub,
- src->m, src->x - range, src->y - range,
- src->x + range, src->y + range, 0, src,
- skillid, skilllv, tick,
- flag | BCT_ENEMY | 1,
- skill_castend_nodamage_id);
- }
- break;
-
- case PR_LEXDIVINA: /* レックスディビーナ */
- {
- struct status_change *sc_data = battle_get_sc_data (bl);
- clif_skill_nodamage (src, bl, skillid, skilllv, 1);
- if (bl->type == BL_PC
- && ((struct map_session_data *) bl)->
- special_state.no_magic_damage)
- break;
- if (sc_data && sc_data[SC_DIVINA].timer != -1)
- skill_status_change_end (bl, SC_DIVINA, -1);
- else if (MRAND (100) < sc_def_vit)
- {
- skill_status_change_start (bl,
- SkillStatusChangeTable[skillid],
- skilllv, 0, 0, 0,
- skill_get_time (skillid, skilllv),
- 0);
- }
- }
- break;
- case SA_ABRACADABRA:
- break;
- case SA_COMA:
- clif_skill_nodamage (src, bl, skillid, skilllv, 1);
- if (bl->type == BL_PC
- && ((struct map_session_data *) bl)->
- special_state.no_magic_damage)
- break;
- if (dstsd)
- {
- dstsd->status.hp = 1;
- dstsd->status.sp = 1;
- clif_updatestatus (dstsd, SP_HP);
- clif_updatestatus (dstsd, SP_SP);
- }
- if (dstmd)
- dstmd->hp = 1;
- break;
- case SA_FULLRECOVERY:
- clif_skill_nodamage (src, bl, skillid, skilllv, 1);
- if (bl->type == BL_PC
- && ((struct map_session_data *) bl)->
- special_state.no_magic_damage)
- break;
- if (dstsd)
- pc_heal (dstsd, dstsd->status.max_hp, dstsd->status.max_sp);
- if (dstmd)
- dstmd->hp = battle_get_max_hp (&dstmd->bl);
- break;
- case SA_SUMMONMONSTER:
- clif_skill_nodamage (src, bl, skillid, skilllv, 1);
- if (sd)
- mob_once_spawn (sd, map[sd->bl.m].name, sd->bl.x, sd->bl.y,
- "--ja--", -1, 1, "");
- break;
- case SA_LEVELUP:
- clif_skill_nodamage (src, bl, skillid, skilllv, 1);
- if (sd && pc_nextbaseexp (sd))
- pc_gainexp (sd, pc_nextbaseexp (sd) * 10 / 100, 0);
- break;
-
- case SA_INSTANTDEATH:
- clif_skill_nodamage (src, bl, skillid, skilllv, 1);
- if (sd)
- pc_damage (NULL, sd, sd->status.max_hp);
- break;
-
- case SA_QUESTION:
- case SA_GRAVITY:
- clif_skill_nodamage (src, bl, skillid, skilllv, 1);
- break;
- case SA_CLASSCHANGE:
- clif_skill_nodamage (src, bl, skillid, skilllv, 1);
- if (dstmd)
- mob_class_change (dstmd, changeclass);
- break;
- case SA_MONOCELL:
- clif_skill_nodamage (src, bl, skillid, skilllv, 1);
- if (dstmd)
- mob_class_change (dstmd, poringclass);
- break;
- case SA_DEATH:
- clif_skill_nodamage (src, bl, skillid, skilllv, 1);
- if (dstsd)
- pc_damage (NULL, dstsd, dstsd->status.max_hp);
- if (dstmd)
- mob_damage (NULL, dstmd, dstmd->hp, 1);
- break;
- case SA_REVERSEORCISH:
- clif_skill_nodamage (src, bl, skillid, skilllv, 1);
- if (dstsd)
- pc_setoption (dstsd, dstsd->status.option | 0x0800);
- break;
- case SA_FORTUNE:
- clif_skill_nodamage (src, bl, skillid, skilllv, 1);
- if (sd)
- pc_getzeny (sd, battle_get_lv (bl) * 100);
- break;
- case AL_INCAGI: /* 速度増加 */
- case AL_BLESSING: /* ブレッシング */
- case PR_SLOWPOISON:
- case PR_IMPOSITIO: /* イムãƒã‚·ãƒ†ã‚£ã‚ªãƒžãƒŒã‚¹ */
- case PR_LEXAETERNA: /* レックスエーテルナ */
- case PR_SUFFRAGIUM: /* サフラギウム */
- case PR_BENEDICTIO: /* è–体é™ç¦ */
- case CR_PROVIDENCE: /* プロヴィデンス */
- case CG_MARIONETTE: /* マリオãƒãƒƒãƒˆã‚³ãƒ³ãƒˆãƒ­ãƒ¼ãƒ« */
- if (bl->type == BL_PC
- && ((struct map_session_data *) bl)->
- special_state.no_magic_damage)
- {
- clif_skill_nodamage (src, bl, skillid, skilllv, 1);
- }
- else
- {
- skill_status_change_start (bl,
- SkillStatusChangeTable[skillid],
- skilllv, 0, 0, 0,
- skill_get_time (skillid, skilllv),
- 0);
- clif_skill_nodamage (src, bl, skillid, skilllv, 1);
- }
- break;
-
- case SA_FLAMELAUNCHER: // added failure chance and chance to break weapon if turned on [Valaris]
- case SA_FROSTWEAPON:
- case SA_LIGHTNINGLOADER:
- case SA_SEISMICWEAPON:
- if (bl->type == BL_PC
- && ((struct map_session_data *) bl)->
- special_state.no_magic_damage)
- {
- clif_skill_nodamage (src, bl, skillid, skilllv, 0);
- break;
- }
- if (bl->type == BL_PC)
- {
- struct map_session_data *sd2 = (struct map_session_data *) bl;
- if (sd2->status.weapon == 0
- || sd2->sc_data[SC_FLAMELAUNCHER].timer != -1
- || sd2->sc_data[SC_FROSTWEAPON].timer != -1
- || sd2->sc_data[SC_LIGHTNINGLOADER].timer != -1
- || sd2->sc_data[SC_SEISMICWEAPON].timer != -1
- || sd2->sc_data[SC_ENCPOISON].timer != -1)
- {
- clif_skill_fail (sd, skillid, 0, 0);
- clif_skill_nodamage (src, bl, skillid, skilllv, 0);
- break;
- }
- }
- if (MRAND (100) > (75 + skilllv * 1) && (skilllv != 5))
- {
- clif_skill_fail (sd, skillid, 0, 0);
- clif_skill_nodamage (src, bl, skillid, skilllv, 0);
- if (bl->type == BL_PC && battle_config.equipment_breaking)
- {
- struct map_session_data *sd2 =
- (struct map_session_data *) bl;
- if (sd != sd2)
- clif_displaymessage (sd->fd,
- "You broke target's weapon");
- pc_breakweapon (sd2);
- }
- break;
- }
- else
- {
- skill_status_change_start (bl,
- SkillStatusChangeTable[skillid],
- skilllv, 0, 0, 0,
- skill_get_time (skillid, skilllv),
- 0);
- clif_skill_nodamage (src, bl, skillid, skilllv, 1);
- }
- break;
-
- case PR_ASPERSIO: /* アスペルシオ */
- clif_skill_nodamage (src, bl, skillid, skilllv, 1);
- if (bl->type == BL_PC
- && ((struct map_session_data *) bl)->
- special_state.no_magic_damage)
- break;
- if (bl->type == BL_MOB)
- break;
- skill_status_change_start (bl, SkillStatusChangeTable[skillid],
- skilllv, 0, 0, 0,
- skill_get_time (skillid, skilllv), 0);
- break;
- case PR_KYRIE: /* キリエエレイソン */
- clif_skill_nodamage (bl, bl, skillid, skilllv, 1);
- if (bl->type == BL_PC
- && ((struct map_session_data *) bl)->
- special_state.no_magic_damage)
- break;
- skill_status_change_start (bl, SkillStatusChangeTable[skillid],
- skilllv, 0, 0, 0,
- skill_get_time (skillid, skilllv), 0);
- break;
- case KN_AUTOCOUNTER: /* オートカウンター */
- case KN_TWOHANDQUICKEN: /* ツーãƒãƒ³ãƒ‰ã‚¯ã‚¤ãƒƒã‚±ãƒ³ */
- case CR_SPEARQUICKEN: /* スピアクイッケン */
- case CR_REFLECTSHIELD:
- case AS_POISONREACT: /* ãƒã‚¤ã‚ºãƒ³ãƒªã‚¢ã‚¯ãƒˆ */
- case MC_LOUD: /* ラウドボイス */
- case MG_ENERGYCOAT: /* エナジーコート */
- case SM_ENDURE: /* インデュア */
- case MG_SIGHT: /* サイト */
- case AL_RUWACH: /* ルアフ */
- case MO_EXPLOSIONSPIRITS: // 爆裂波動
- case MO_STEELBODY: // 金剛
- case LK_AURABLADE: /* オーラブレード */
- case LK_PARRYING: /* パリイング */
- case LK_CONCENTRATION: /* コンセントレーション */
- case LK_BERSERK: /* ãƒãƒ¼ã‚µãƒ¼ã‚¯ */
- case HP_ASSUMPTIO: /* */
- case WS_CARTBOOST: /* カートブースト */
- case SN_SIGHT: /* トゥルーサイト */
- case WS_MELTDOWN: /* メルトダウン */
- case ST_REJECTSWORD: /* リジェクトソード */
- case HW_MAGICPOWER: /* 魔法力増幅 */
- case PF_MEMORIZE: /* メモライズ */
- clif_skill_nodamage (src, bl, skillid, skilllv, 1);
- skill_status_change_start (bl, SkillStatusChangeTable[skillid],
- skilllv, 0, 0, 0,
- skill_get_time (skillid, skilllv), 0);
- break;
- case AS_ENCHANTPOISON: // Prevent spamming [Valaris]
- if (bl->type == BL_PC)
- {
- struct map_session_data *sd2 = (struct map_session_data *) bl;
- if (sd2->sc_data[SC_FLAMELAUNCHER].timer != -1
- || sd2->sc_data[SC_FROSTWEAPON].timer != -1
- || sd2->sc_data[SC_LIGHTNINGLOADER].timer != -1
- || sd2->sc_data[SC_SEISMICWEAPON].timer != -1
- || sd2->sc_data[SC_ENCPOISON].timer != -1)
- {
- clif_skill_nodamage (src, bl, skillid, skilllv, 0);
- clif_skill_fail (sd, skillid, 0, 0);
- break;
- }
- }
- clif_skill_nodamage (src, bl, skillid, skilllv, 1);
- skill_status_change_start (bl, SkillStatusChangeTable[skillid],
- skilllv, 0, 0, 0,
- skill_get_time (skillid, skilllv), 0);
- break;
- case LK_TENSIONRELAX: /* テンションリラックス */
- clif_skill_nodamage (src, bl, skillid, skilllv, 1);
- pc_setsit (sd);
- clif_sitting (sd->fd, sd);
- skill_status_change_start (bl, SkillStatusChangeTable[skillid],
- skilllv, 0, 0, 0,
- skill_get_time (skillid, skilllv), 0);
- break;
- case MC_CHANGECART:
- clif_skill_nodamage (src, bl, skillid, skilllv, 1);
- break;
- case AC_CONCENTRATION: /* 集中力å‘上 */
- {
- int range = 1;
- clif_skill_nodamage (src, bl, skillid, skilllv, 1);
- skill_status_change_start (bl, SkillStatusChangeTable[skillid],
- skilllv, 0, 0, 0,
- skill_get_time (skillid, skilllv), 0);
- map_foreachinarea (skill_status_change_timer_sub, src->m,
- src->x - range, src->y - range, src->x + range,
- src->y + range, 0, src,
- SkillStatusChangeTable[skillid], tick);
- }
- break;
- case SM_PROVOKE: /* プロボック */
- {
- struct status_change *sc_data = battle_get_sc_data (bl);
-
- /* MVPmobã¨ä¸æ­»ã«ã¯åŠ¹ã‹ãªã„ */
- if ((bl->type == BL_MOB && battle_get_mode (bl) & 0x20) || battle_check_undead (battle_get_race (bl), battle_get_elem_type (bl))) //ä¸æ­»ã«ã¯åŠ¹ã‹ãªã„
- {
- map_freeblock_unlock ();
- return 1;
- }
-
- clif_skill_nodamage (src, bl, skillid, skilllv, 1);
- skill_status_change_start (bl, SkillStatusChangeTable[skillid],
- skilllv, 0, 0, 0,
- skill_get_time (skillid, skilllv), 0);
-
- if (dstmd && dstmd->skilltimer != -1 && dstmd->state.skillcastcancel) // 詠唱妨害
- skill_castcancel (bl, 0);
- if (dstsd && dstsd->skilltimer != -1
- && (!dstsd->special_state.no_castcancel
- || map[bl->m].flag.gvg) && dstsd->state.skillcastcancel
- && !dstsd->special_state.no_castcancel2)
- skill_castcancel (bl, 0);
-
- if (sc_data)
- {
- if (sc_data[SC_FREEZE].timer != -1)
- skill_status_change_end (bl, SC_FREEZE, -1);
- if (sc_data[SC_STONE].timer != -1
- && sc_data[SC_STONE].val2 == 0)
- skill_status_change_end (bl, SC_STONE, -1);
- if (sc_data[SC_SLEEP].timer != -1)
- skill_status_change_end (bl, SC_SLEEP, -1);
- }
-
- if (bl->type == BL_MOB)
- {
- int range = skill_get_range (skillid, skilllv);
- if (range < 0)
- range = battle_get_range (src) - (range + 1);
- mob_target ((struct mob_data *) bl, src, range);
- }
- }
- break;
-
- case CR_DEVOTION: /* ディボーション */
- if (sd && dstsd)
- {
- //転生や養å­ã®å ´åˆã®å…ƒã®è·æ¥­ã‚’算出ã™ã‚‹
-
- int lv = sd->status.base_level - dstsd->status.base_level;
- lv = (lv < 0) ? -lv : lv;
- if ((dstsd->bl.type != BL_PC) // 相手ã¯PCã˜ã‚ƒãªã„ã¨ã ã‚
- || (sd->bl.id == dstsd->bl.id) // 相手ãŒè‡ªåˆ†ã¯ã ã‚
- || (lv > 10) // レベル差±10ã¾ã§
- || (!sd->status.party_id && !sd->status.guild_id) // PTã«ã‚‚ギルドã«ã‚‚所属無ã—ã¯ã ã‚
- || ((sd->status.party_id != dstsd->status.party_id) // åŒã˜ãƒ‘ーティーã‹ã€
- || (sd->status.guild_id != dstsd->status.guild_id)) // åŒã˜ã‚®ãƒ«ãƒ‰ã˜ã‚ƒãªã„ã¨ã ã‚
- || (dstsd->status.pc_class == 14 || dstsd->status.pc_class == 21
- || dstsd->status.pc_class == 4015
- || dstsd->status.pc_class == 4022))
- { // クルセã ã‚
- clif_skill_fail (sd, skillid, 0, 0);
- map_freeblock_unlock ();
- return 1;
- }
- for (int i = 0; i < skilllv; i++)
- {
- if (!sd->dev.val1[i])
- { // 空ããŒã‚ã£ãŸã‚‰å…¥ã‚Œã‚‹
- sd->dev.val1[i] = bl->id;
- sd->dev.val2[i] = bl->id;
- break;
- }
- else if (i == skilllv - 1)
- { // 空ããŒãªã‹ã£ãŸ
- clif_skill_fail (sd, skillid, 0, 0);
- map_freeblock_unlock ();
- return 1;
- }
- }
- clif_skill_nodamage (src, bl, skillid, skilllv, 1);
- clif_devotion (sd, bl->id);
- skill_status_change_start (bl,
- SkillStatusChangeTable[skillid],
- src->id, 1, 0, 0,
- 1000 * (15 + 15 * skilllv), 0);
- }
- else
- clif_skill_fail (sd, skillid, 0, 0);
- break;
- case MO_CALLSPIRITS: // 気功
- if (sd)
- {
- clif_skill_nodamage (src, bl, skillid, skilllv, 1);
- pc_addspiritball (sd, skill_get_time (skillid, skilllv),
- skilllv);
- }
- break;
- case CH_SOULCOLLECT: // 狂気功
- if (sd)
- {
- clif_skill_nodamage (src, bl, skillid, skilllv, 1);
- for (int i = 0; i < 5; i++)
- pc_addspiritball (sd, skill_get_time (skillid, skilllv),
- 5);
- }
- break;
- case MO_BLADESTOP: // 白刃å–ã‚Š
- clif_skill_nodamage (src, bl, skillid, skilllv, 1);
- skill_status_change_start (src, SkillStatusChangeTable[skillid],
- skilllv, 0, 0, 0,
- skill_get_time (skillid, skilllv), 0);
- break;
- case MO_ABSORBSPIRITS: // 気奪
- {
- int i = 0;
- if (sd && dstsd)
- {
- if (sd == dstsd || map[sd->bl.m].flag.pvp
- || map[sd->bl.m].flag.gvg)
- {
- if (dstsd->spiritball > 0)
- {
- clif_skill_nodamage (src, bl, skillid, skilllv, 1);
- i = dstsd->spiritball * 7;
- pc_delspiritball (dstsd, dstsd->spiritball, 0);
- if (i > 0x7FFF)
- i = 0x7FFF;
- if (sd->status.sp + i > sd->status.max_sp)
- i = sd->status.max_sp - sd->status.sp;
- }
- }
- }
- else if (sd && dstmd)
- { //対象ãŒãƒ¢ãƒ³ã‚¹ã‚¿ãƒ¼ã®å ´åˆ
- //20%ã®ç¢ºçŽ‡ã§å¯¾è±¡ã®Lv*2ã®SPを回復ã™ã‚‹ã€‚æˆåŠŸã—ãŸã¨ãã¯ã‚¿ãƒ¼ã‚²ãƒƒãƒˆ(σ゚Д゚)σゲッツ!!
- if (MRAND (100) < 20)
- {
- i = 2 * mob_db[dstmd->mob_class].lv;
- mob_target (dstmd, src, 0);
- }
- }
- if (i)
- {
- sd->status.sp += i;
- clif_heal (sd->fd, SP_SP, i);
- }
- else
- clif_skill_nodamage (src, bl, skillid, skilllv, 0);
- break;
- }
-
- case AC_MAKINGARROW: /* çŸ¢ä½œæˆ */
-/* if(sd) {
- clif_arrow_create_list(sd);
- clif_skill_nodamage(src,bl,skillid,skilllv,1);
- }*/
- break;
-
- case AM_PHARMACY: /* ãƒãƒ¼ã‚·ãƒ§ãƒ³ä½œæˆ */
-/* if(sd) {
- clif_skill_produce_mix_list(sd,32);
- clif_skill_nodamage(src,bl,skillid,skilllv,1);
- }*/
- break;
- case WS_CREATECOIN: /* クリエイトコイン */
-/* if(sd) {
- clif_skill_produce_mix_list(sd,64);
- clif_skill_nodamage(src,bl,skillid,skilllv,1);
- }*/
- break;
- case WS_CREATENUGGET: /* 塊製造 */
-/* if(sd) {
- clif_skill_produce_mix_list(sd,128);
- clif_skill_nodamage(src,bl,skillid,skilllv,1);
- }*/
- break;
- case BS_HAMMERFALL: /* ãƒãƒ³ãƒžãƒ¼ãƒ•ã‚©ãƒ¼ãƒ« */
- clif_skill_nodamage (src, bl, skillid, skilllv, 1);
- if (bl->type == BL_PC
- && ((struct map_session_data *) bl)->
- special_state.no_weapon_damage)
- break;
- if (MRAND (100) < (20 + 10 * skilllv) * sc_def_vit / 100)
- {
- skill_status_change_start (bl, SC_STAN, skilllv, 0, 0, 0,
- skill_get_time2 (skillid, skilllv),
- 0);
- }
- break;
-
- case RG_RAID: /* サプライズアタック */
- clif_skill_nodamage (src, bl, skillid, skilllv, 1);
- {
- int x = bl->x, y = bl->y;
- skill_area_temp[1] = bl->id;
- skill_area_temp[2] = x;
- skill_area_temp[3] = y;
- map_foreachinarea (skill_area_sub,
- bl->m, x - 1, y - 1, x + 1, y + 1, 0,
- src, skillid, skilllv, tick,
- flag | BCT_ENEMY | 1,
- skill_castend_damage_id);
- }
- skill_status_change_end (src, SC_HIDING, -1); // ãƒã‚¤ãƒ‡ã‚£ãƒ³ã‚°è§£é™¤
- break;
-
- case KN_BRANDISHSPEAR: /*ブランディッシュスピア */
- {
- int c, n = 4, ar;
- int dir = map_calc_dir (src, bl->x, bl->y);
- struct square tc;
- int x = bl->x, y = bl->y;
- ar = skilllv / 3;
- skill_brandishspear_first (&tc, dir, x, y);
- skill_brandishspear_dir (&tc, dir, 4);
- /* 範囲C */
- if (skilllv == 10)
- {
- for (c = 1; c < 4; c++)
- {
- map_foreachinarea (skill_area_sub,
- bl->m, tc.val1[c], tc.val2[c],
- tc.val1[c], tc.val2[c], 0, src,
- skillid, skilllv, tick,
- flag | BCT_ENEMY | n,
- skill_castend_damage_id);
- }
- }
- /* 範囲BA */
- if (skilllv > 6)
- {
- skill_brandishspear_dir (&tc, dir, -1);
- n--;
- }
- else
- {
- skill_brandishspear_dir (&tc, dir, -2);
- n -= 2;
- }
-
- if (skilllv > 3)
- {
- for (c = 0; c < 5; c++)
- {
- map_foreachinarea (skill_area_sub,
- bl->m, tc.val1[c], tc.val2[c],
- tc.val1[c], tc.val2[c], 0, src,
- skillid, skilllv, tick,
- flag | BCT_ENEMY | n,
- skill_castend_damage_id);
- if (skilllv > 6 && n == 3 && c == 4)
- {
- skill_brandishspear_dir (&tc, dir, -1);
- n--;
- c = -1;
- }
- }
- }
- /* 範囲@ */
- for (c = 0; c < 10; c++)
- {
- if (c == 0 || c == 5)
- skill_brandishspear_dir (&tc, dir, -1);
- map_foreachinarea (skill_area_sub,
- bl->m, tc.val1[c % 5], tc.val2[c % 5],
- tc.val1[c % 5], tc.val2[c % 5], 0, src,
- skillid, skilllv, tick,
- flag | BCT_ENEMY | 1,
- skill_castend_damage_id);
- }
- }
- break;
-
- /* パーティスキル */
- case AL_ANGELUS: /* エンジェラス */
- case PR_MAGNIFICAT: /* マグニフィカート */
- case PR_GLORIA: /* グロリア */
- case SN_WINDWALK: /* ウインドウォーク */
- if (sd == NULL || sd->status.party_id == 0 || (flag & 1))
- {
- /* 個別ã®å‡¦ç† */
- clif_skill_nodamage (bl, bl, skillid, skilllv, 1);
- if (bl->type == BL_PC
- && ((struct map_session_data *) bl)->
- special_state.no_magic_damage)
- break;
- skill_status_change_start (bl,
- SkillStatusChangeTable[skillid],
- skilllv, 0, 0, 0,
- skill_get_time (skillid, skilllv),
- 0);
- }
- else
- {
- /* パーティ全体ã¸ã®å‡¦ç† */
- party_foreachsamemap (skill_area_sub,
- sd, 1,
- src, skillid, skilllv, tick,
- flag | BCT_PARTY | 1,
- skill_castend_nodamage_id);
- }
- break;
- case BS_ADRENALINE: /* アドレナリンラッシュ */
- case BS_WEAPONPERFECT: /* ウェãƒãƒ³ãƒ‘ーフェクション */
- case BS_OVERTHRUST: /* オーãƒãƒ¼ãƒˆãƒ©ã‚¹ãƒˆ */
- if (sd == NULL || sd->status.party_id == 0 || (flag & 1))
- {
- /* 個別ã®å‡¦ç† */
- clif_skill_nodamage (bl, bl, skillid, skilllv, 1);
- skill_status_change_start (bl,
- SkillStatusChangeTable[skillid],
- skilllv, (src == bl) ? 1 : 0, 0, 0,
- skill_get_time (skillid, skilllv),
- 0);
- }
- else
- {
- /* パーティ全体ã¸ã®å‡¦ç† */
- party_foreachsamemap (skill_area_sub,
- sd, 1,
- src, skillid, skilllv, tick,
- flag | BCT_PARTY | 1,
- skill_castend_nodamage_id);
- }
- break;
-
- /*(付加ã¨è§£é™¤ãŒå¿…è¦ï¼‰ */
- case BS_MAXIMIZE: /* マキシマイズパワー */
- case NV_TRICKDEAD: /* 死んã ãµã‚Š */
- case CR_DEFENDER: /* ディフェンダー */
- case CR_AUTOGUARD: /* オートガード */
- {
- struct status_change *tsc_data = battle_get_sc_data (bl);
- int sc = SkillStatusChangeTable[skillid];
- clif_skill_nodamage (src, bl, skillid, skilllv, 1);
- if (tsc_data)
- {
- if (tsc_data[sc].timer == -1)
- /* 付加ã™ã‚‹ */
- skill_status_change_start (bl, sc, skilllv, 0, 0, 0,
- skill_get_time (skillid,
- skilllv), 0);
- else
- /* 解除ã™ã‚‹ */
- skill_status_change_end (bl, sc, -1);
- }
- }
- break;
-
- case TF_HIDING: /* ãƒã‚¤ãƒ‡ã‚£ãƒ³ã‚° */
- {
- struct status_change *tsc_data = battle_get_sc_data (bl);
- int sc = SkillStatusChangeTable[skillid];
- clif_skill_nodamage (src, bl, skillid, -1, 1);
- if (tsc_data)
- {
- if (tsc_data[sc].timer == -1)
- /* 付加ã™ã‚‹ */
- skill_status_change_start (bl, sc, skilllv, 0, 0, 0,
- skill_get_time (skillid,
- skilllv), 0);
- else
- /* 解除ã™ã‚‹ */
- skill_status_change_end (bl, sc, -1);
- }
- }
- break;
-
- case AS_CLOAKING: /* クローキング */
- {
- struct status_change *tsc_data = battle_get_sc_data (bl);
- int sc = SkillStatusChangeTable[skillid];
- clif_skill_nodamage (src, bl, skillid, -1, 1);
- if (tsc_data)
- {
- if (tsc_data[sc].timer == -1)
- /* 付加ã™ã‚‹ */
- skill_status_change_start (bl, sc, skilllv, 0, 0, 0,
- skill_get_time (skillid,
- skilllv), 0);
- else
- /* 解除ã™ã‚‹ */
- skill_status_change_end (bl, sc, -1);
- }
-
- skill_check_cloaking (bl);
- }
- break;
-
- case ST_CHASEWALK: /* ãƒã‚¤ãƒ‡ã‚£ãƒ³ã‚° */
- {
- struct status_change *tsc_data = battle_get_sc_data (bl);
- int sc = SkillStatusChangeTable[skillid];
- clif_skill_nodamage (src, bl, skillid, -1, 1);
- if (tsc_data)
- {
- if (tsc_data[sc].timer == -1)
- /* 付加ã™ã‚‹ */
- skill_status_change_start (bl, sc, skilllv, 0, 0, 0,
- skill_get_time (skillid,
- skilllv), 0);
- else
- /* 解除ã™ã‚‹ */
- skill_status_change_end (bl, sc, -1);
- }
- }
- break;
-
- /* 対地スキル */
- case BD_LULLABY: /* å­å®ˆå”„ */
- case BD_RICHMANKIM: /* ニヨルドã®å®´ */
- case BD_ETERNALCHAOS: /* æ°¸é ã®æ··æ²Œ */
- case BD_DRUMBATTLEFIELD: /* 戦太鼓ã®éŸ¿ã */
- case BD_RINGNIBELUNGEN: /* ニーベルングã®æŒ‡è¼ª */
- case BD_ROKISWEIL: /* ロキã®å«ã³ */
- case BD_INTOABYSS: /* 深淵ã®ä¸­ã« */
- case BD_SIEGFRIED: /* ä¸æ­»èº«ã®ã‚¸ãƒ¼ã‚¯ãƒ•ãƒªãƒ¼ãƒ‰ */
- case BA_DISSONANCE: /* ä¸å”和音 */
- case BA_POEMBRAGI: /* ブラギã®è©© */
- case BA_WHISTLE: /* å£ç¬› */
- case BA_ASSASSINCROSS: /* 夕陽ã®ã‚¢ã‚µã‚·ãƒ³ã‚¯ãƒ­ã‚¹ */
- case BA_APPLEIDUN: /* イドゥンã®æž—檎 */
- case DC_UGLYDANCE: /* 自分å‹æ‰‹ãªãƒ€ãƒ³ã‚¹ */
- case DC_HUMMING: /* ãƒãƒŸãƒ³ã‚° */
- case DC_DONTFORGETME: /* ç§ã‚’忘れãªã„ã§â€¦ */
- case DC_FORTUNEKISS: /* 幸é‹ã®ã‚­ã‚¹ */
- case DC_SERVICEFORYOU: /* サービスフォーユー */
- case CG_MOONLIT: /* 月明りã®æ³‰ã«è½ã¡ã‚‹èŠ±ã³ã‚‰ */
- clif_skill_nodamage (src, bl, skillid, skilllv, 1);
- skill_unitsetting (src, skillid, skilllv, src->x, src->y, 0);
- break;
-
- case HP_BASILICA: /* ãƒã‚¸ãƒªã‚« */
- case PA_GOSPEL: /* ゴスペル */
- skill_clear_unitgroup (src);
- clif_skill_nodamage (src, bl, skillid, skilllv, 1);
- skill_unitsetting (src, skillid, skilllv, src->x, src->y, 0);
- break;
-
- case BD_ADAPTATION: /* アドリブ */
- {
- struct status_change *sc_data = battle_get_sc_data (src);
- if (sc_data && sc_data[SC_DANCING].timer != -1)
- {
- clif_skill_nodamage (src, bl, skillid, skilllv, 1);
- skill_stop_dancing (src, 0);
- }
- }
- break;
-
- case BA_FROSTJOKE: /* 寒ã„ジョーク */
- case DC_SCREAM: /* スクリーム */
- clif_skill_nodamage (src, bl, skillid, skilllv, 1);
- skill_addtimerskill (src, tick + 3000, bl->id, 0, 0, skillid,
- skilllv, 0, flag);
- break;
-
- case TF_STEAL: // スティール
- if (sd)
- {
- if (pc_steal_item (sd, bl))
- clif_skill_nodamage (src, bl, skillid, skilllv, 1);
- else
- clif_skill_nodamage (src, bl, skillid, skilllv, 0);
- }
- break;
-
- case RG_STEALCOIN: // スティールコイン
- if (sd)
- {
- if (pc_steal_coin (sd, bl))
- {
- int range = skill_get_range (skillid, skilllv);
- if (range < 0)
- range = battle_get_range (src) - (range + 1);
- clif_skill_nodamage (src, bl, skillid, skilllv, 1);
- mob_target ((struct mob_data *) bl, src, range);
- }
- else
- clif_skill_nodamage (src, bl, skillid, skilllv, 0);
- }
- break;
-
- case MG_STONECURSE: /* ストーンカース */
- if (bl->type == BL_MOB && battle_get_mode (bl) & 0x20)
- {
- clif_skill_fail (sd, sd->skillid, 0, 0);
- break;
- }
- clif_skill_nodamage (src, bl, skillid, skilllv, 1);
- if (bl->type == BL_PC
- && ((struct map_session_data *) bl)->
- special_state.no_magic_damage)
- break;
- if (MRAND (100) < skilllv * 4 + 20
- && !battle_check_undead (battle_get_race (bl),
- battle_get_elem_type (bl)))
- skill_status_change_start (bl, SC_STONE, skilllv, 0, 0, 0,
- skill_get_time2 (skillid, skilllv),
- 0);
- else if (sd)
- clif_skill_fail (sd, skillid, 0, 0);
- break;
-
- case NV_FIRSTAID: /* 応急手当 */
- clif_skill_nodamage (src, bl, skillid, 5, 1);
- battle_heal (NULL, bl, 5, 0, 0);
- break;
-
- case AL_CURE: /* キュアー */
- clif_skill_nodamage (src, bl, skillid, skilllv, 1);
- if (bl->type == BL_PC
- && ((struct map_session_data *) bl)->
- special_state.no_magic_damage)
- break;
- skill_status_change_end (bl, SC_SILENCE, -1);
- skill_status_change_end (bl, SC_BLIND, -1);
- skill_status_change_end (bl, SC_CONFUSION, -1);
- if (battle_check_undead
- (battle_get_race (bl), battle_get_elem_type (bl)))
- { //アンデッドãªã‚‰æš—闇効果
- skill_status_change_start (bl, SC_CONFUSION, 1, 0, 0, 0, 6000,
- 0);
- }
- break;
-
- case TF_DETOXIFY: /* 解毒 */
- clif_skill_nodamage (src, bl, skillid, skilllv, 1);
- skill_status_change_end (bl, SC_POISON, -1);
- break;
-
- case PR_STRECOVERY: /* リカãƒãƒªãƒ¼ */
- {
- clif_skill_nodamage (src, bl, skillid, skilllv, 1);
- if (bl->type == BL_PC
- && ((struct map_session_data *) bl)->
- special_state.no_magic_damage)
- break;
- skill_status_change_end (bl, SC_FREEZE, -1);
- skill_status_change_end (bl, SC_STONE, -1);
- skill_status_change_end (bl, SC_SLEEP, -1);
- skill_status_change_end (bl, SC_STAN, -1);
- if (battle_check_undead
- (battle_get_race (bl), battle_get_elem_type (bl)))
- { //アンデッドãªã‚‰æš—闇効果
- int blind_time;
- //blind_time=30-battle_get_vit(bl)/10-battle_get_int/15;
- blind_time =
- 30 * (100 -
- (battle_get_int (bl) +
- battle_get_vit (bl)) / 2) / 100;
- if (MRAND (100) <
- (100 -
- (battle_get_int (bl) / 2 + battle_get_vit (bl) / 3 +
- battle_get_luk (bl) / 10)))
- skill_status_change_start (bl, SC_BLIND, 1, 0, 0, 0,
- blind_time, 0);
- }
- if (dstmd)
- {
- dstmd->attacked_id = 0;
- dstmd->target_id = 0;
- dstmd->state.targettype = NONE_ATTACKABLE;
- dstmd->state.skillstate = MSS_IDLE;
- dstmd->next_walktime = tick + MRAND (3000) + 3000;
- }
- }
- break;
-
- case WZ_ESTIMATION: /* モンスター情報 */
- if (src->type == BL_PC)
- {
- clif_skill_nodamage (src, bl, skillid, skilllv, 1);
- clif_skill_estimation ((struct map_session_data *) src, bl);
- }
- break;
-
- case MC_IDENTIFY: /* アイテム鑑定 */
- if (sd)
- clif_item_identify_list (sd);
- break;
-
- case BS_REPAIRWEAPON: /* æ­¦å™¨ä¿®ç† */
- if (sd)
-//動作ã—ãªã„ã®ã§ã¨ã‚Šã‚ãˆãšã‚³ãƒ¡ãƒ³ãƒˆã‚¢ã‚¦ãƒˆ
-// clif_item_repair_list(sd);
- break;
-
- case AL_TELEPORT: /* テレãƒãƒ¼ãƒˆ */
- if (sd)
- {
- if (map[sd->bl.m].flag.noteleport)
- { /* テレãƒç¦æ­¢ */
- clif_skill_teleportmessage (sd, 0);
- break;
- }
- clif_skill_nodamage (src, bl, skillid, skilllv, 1);
- if (sd->skilllv == 1)
- clif_skill_warppoint (sd, sd->skillid, "Random", "", "",
- "");
- else
- {
- clif_skill_warppoint (sd, sd->skillid, "Random",
- sd->status.save_point.map, "", "");
- }
- }
- else if (bl->type == BL_MOB)
- mob_warp ((struct mob_data *) bl, -1, -1, -1, 3);
- break;
-
- case AL_HOLYWATER: /* アクアベãƒãƒ‡ã‚£ã‚¯ã‚¿ */
- if (sd)
- {
- int eflag;
- struct item item_tmp;
- clif_skill_nodamage (src, bl, skillid, skilllv, 1);
- memset (&item_tmp, 0, sizeof (item_tmp));
- item_tmp.nameid = 523;
- item_tmp.identify = 1;
- if (battle_config.holywater_name_input)
- {
- item_tmp.card[0] = 0xfe;
- item_tmp.card[1] = 0;
- *((unsigned long *) (&item_tmp.card[2])) = sd->char_id; /* キャラID */
- }
- eflag = pc_additem (sd, &item_tmp, 1);
- if (eflag)
- {
- clif_additem (sd, 0, 0, eflag);
- map_addflooritem (&item_tmp, 1, sd->bl.m, sd->bl.x,
- sd->bl.y, NULL, NULL, NULL, 0);
- }
- }
- break;
- case TF_PICKSTONE:
- if (sd)
- {
- int eflag;
- struct item item_tmp;
- struct block_list tbl;
- clif_skill_nodamage (src, bl, skillid, skilllv, 1);
- memset (&item_tmp, 0, sizeof (item_tmp));
- memset (&tbl, 0, sizeof (tbl)); // [MouseJstr]
- item_tmp.nameid = 7049;
- item_tmp.identify = 1;
- tbl.id = 0;
- clif_takeitem (&sd->bl, &tbl);
- eflag = pc_additem (sd, &item_tmp, 1);
- if (eflag)
- {
- clif_additem (sd, 0, 0, eflag);
- map_addflooritem (&item_tmp, 1, sd->bl.m, sd->bl.x,
- sd->bl.y, NULL, NULL, NULL, 0);
- }
- }
- break;
-
- case RG_STRIPWEAPON: /* ストリップウェãƒãƒ³ */
- {
- struct status_change *tsc_data = battle_get_sc_data (bl);
-
- if (tsc_data && tsc_data[SC_CP_WEAPON].timer != -1)
- break;
- strip_per = 5 + 2 * skilllv + strip_fix / 5;
- strip_time = skill_get_time (skillid, skilllv) + strip_fix / 2;
- if (MRAND (100) < strip_per)
- {
- clif_skill_nodamage (src, bl, skillid, skilllv, 1);
- skill_status_change_start (bl,
- SkillStatusChangeTable[skillid],
- skilllv, 0, 0, 0, strip_time, 0);
- if (dstsd)
- {
- for (int i = 0; i < MAX_INVENTORY; i++)
- {
- if (dstsd->status.inventory[i].equip
- && dstsd->status.inventory[i].equip & 0x0002)
- {
- pc_unequipitem (dstsd, i, 0);
- break;
- }
- }
- }
- }
- }
- break;
-
- case RG_STRIPSHIELD: /* ストリップシールド */
- {
- struct status_change *tsc_data = battle_get_sc_data (bl);
-
- if (tsc_data && tsc_data[SC_CP_SHIELD].timer != -1)
- break;
- strip_per = 5 + 2 * skilllv + strip_fix / 5;
- strip_time = skill_get_time (skillid, skilllv) + strip_fix / 2;
- if (MRAND (100) < strip_per)
- {
- clif_skill_nodamage (src, bl, skillid, skilllv, 1);
- skill_status_change_start (bl,
- SkillStatusChangeTable[skillid],
- skilllv, 0, 0, 0, strip_time, 0);
- if (dstsd)
- {
- for (int i = 0; i < MAX_INVENTORY; i++)
- {
- if (dstsd->status.inventory[i].equip
- && dstsd->status.inventory[i].equip & 0x0020)
- {
- pc_unequipitem (dstsd, i, 0);
- break;
- }
- }
- }
- }
- }
- break;
-
- case RG_STRIPARMOR: /* ストリップアーマー */
- {
- struct status_change *tsc_data = battle_get_sc_data (bl);
-
- if (tsc_data && tsc_data[SC_CP_ARMOR].timer != -1)
- break;
- strip_per = 5 + 2 * skilllv + strip_fix / 5;
- strip_time = skill_get_time (skillid, skilllv) + strip_fix / 2;
- if (MRAND (100) < strip_per)
- {
- clif_skill_nodamage (src, bl, skillid, skilllv, 1);
- skill_status_change_start (bl,
- SkillStatusChangeTable[skillid],
- skilllv, 0, 0, 0, strip_time, 0);
- if (dstsd)
- {
- for (int i = 0; i < MAX_INVENTORY; i++)
- {
- if (dstsd->status.inventory[i].equip
- && dstsd->status.inventory[i].equip & 0x0010)
- {
- pc_unequipitem (dstsd, i, 0);
- break;
- }
- }
- }
- }
- }
- break;
- case RG_STRIPHELM: /* ストリップヘルム */
- {
- struct status_change *tsc_data = battle_get_sc_data (bl);
-
- if (tsc_data && tsc_data[SC_CP_HELM].timer != -1)
- break;
- strip_per = 5 + 2 * skilllv + strip_fix / 5;
- strip_time = skill_get_time (skillid, skilllv) + strip_fix / 2;
- if (MRAND (100) < strip_per)
- {
- clif_skill_nodamage (src, bl, skillid, skilllv, 1);
- skill_status_change_start (bl,
- SkillStatusChangeTable[skillid],
- skilllv, 0, 0, 0, strip_time, 0);
- if (dstsd)
- {
- for (int i = 0; i < MAX_INVENTORY; i++)
- {
- if (dstsd->status.inventory[i].equip
- && dstsd->status.inventory[i].equip & 0x0100)
- {
- pc_unequipitem (dstsd, i, 0);
- break;
- }
- }
- }
- }
- }
- break;
- /* PotionPitcher */
- case AM_POTIONPITCHER: /* ãƒãƒ¼ã‚·ãƒ§ãƒ³ãƒ”ッãƒãƒ£ãƒ¼ */
- {
- struct block_list tbl;
- int i, x, hp = 0, sp = 0;
- if (sd)
- {
- if (sd == dstsd)
- { // cancel use on oneself
- map_freeblock_unlock ();
- return 1;
- }
- x = skilllv % 11 - 1;
- i = pc_search_inventory (sd, skill_db[skillid].itemid[x]);
- if (i < 0 || skill_db[skillid].itemid[x] <= 0)
- {
- clif_skill_fail (sd, skillid, 0, 0);
- map_freeblock_unlock ();
- return 1;
- }
- if (sd->inventory_data[i] == NULL
- || sd->status.inventory[i].amount <
- skill_db[skillid].amount[x])
- {
- clif_skill_fail (sd, skillid, 0, 0);
- map_freeblock_unlock ();
- return 1;
- }
- sd->state.potionpitcher_flag = 1;
- sd->potion_hp = sd->potion_sp = sd->potion_per_hp =
- sd->potion_per_sp = 0;
- sd->skilltarget = bl->id;
- run_script (sd->inventory_data[i]->use_script, 0, sd->bl.id,
- 0);
- pc_delitem (sd, i, skill_db[skillid].amount[x], 0);
- sd->state.potionpitcher_flag = 0;
- if (sd->potion_per_hp > 0 || sd->potion_per_sp > 0)
- {
- hp = battle_get_max_hp (bl) * sd->potion_per_hp / 100;
- hp = hp * (100 +
- pc_checkskill (sd,
- AM_POTIONPITCHER) * 10 +
- pc_checkskill (sd,
- AM_LEARNINGPOTION) * 5) / 100;
- if (dstsd)
- {
- sp = dstsd->status.max_sp * sd->potion_per_sp / 100;
- sp = sp * (100 +
- pc_checkskill (sd,
- AM_POTIONPITCHER) +
- pc_checkskill (sd,
- AM_LEARNINGPOTION) * 5) /
- 100;
- }
- }
- else
- {
- if (sd->potion_hp > 0)
- {
- hp = sd->potion_hp * (100 +
- pc_checkskill (sd,
- AM_POTIONPITCHER)
- * 10 + pc_checkskill (sd,
- AM_LEARNINGPOTION)
- * 5) / 100;
- hp = hp * (100 + (battle_get_vit (bl) << 1)) / 100;
- if (dstsd)
- hp = hp * (100 +
- pc_checkskill (dstsd,
- SM_RECOVERY) * 10) /
- 100;
- }
- if (sd->potion_sp > 0)
- {
- sp = sd->potion_sp * (100 +
- pc_checkskill (sd,
- AM_POTIONPITCHER)
- + pc_checkskill (sd,
- AM_LEARNINGPOTION)
- * 5) / 100;
- sp = sp * (100 + (battle_get_int (bl) << 1)) / 100;
- if (dstsd)
- sp = sp * (100 +
- pc_checkskill (dstsd,
- MG_SRECOVERY) * 10) /
- 100;
- }
- }
- }
- else
- {
- hp = (1 + MRAND (400)) * (100 + skilllv * 10) / 100;
- hp = hp * (100 + (battle_get_vit (bl) << 1)) / 100;
- if (dstsd)
- hp = hp * (100 +
- pc_checkskill (dstsd, SM_RECOVERY) * 10) / 100;
- }
- tbl.id = 0;
- tbl.m = src->m;
- tbl.x = src->x;
- tbl.y = src->y;
- clif_skill_nodamage (src, bl, skillid, skilllv, 1);
- if (hp > 0 || (hp <= 0 && sp <= 0))
- clif_skill_nodamage (&tbl, bl, AL_HEAL, hp, 1);
- if (sp > 0)
- clif_skill_nodamage (&tbl, bl, MG_SRECOVERY, sp, 1);
- battle_heal (src, bl, hp, sp, 0);
- }
- break;
- case AM_CP_WEAPON:
- {
- struct status_change *tsc_data = battle_get_sc_data (bl);
- clif_skill_nodamage (src, bl, skillid, skilllv, 1);
- if (tsc_data && tsc_data[SC_STRIPWEAPON].timer != -1)
- skill_status_change_end (bl, SC_STRIPWEAPON, -1);
- skill_status_change_start (bl, SkillStatusChangeTable[skillid],
- skilllv, 0, 0, 0,
- skill_get_time (skillid, skilllv), 0);
- }
- break;
- case AM_CP_SHIELD:
- {
- struct status_change *tsc_data = battle_get_sc_data (bl);
- clif_skill_nodamage (src, bl, skillid, skilllv, 1);
- if (tsc_data && tsc_data[SC_STRIPSHIELD].timer != -1)
- skill_status_change_end (bl, SC_STRIPSHIELD, -1);
- skill_status_change_start (bl, SkillStatusChangeTable[skillid],
- skilllv, 0, 0, 0,
- skill_get_time (skillid, skilllv), 0);
- }
- break;
- case AM_CP_ARMOR:
- {
- struct status_change *tsc_data = battle_get_sc_data (bl);
- clif_skill_nodamage (src, bl, skillid, skilllv, 1);
- if (tsc_data && tsc_data[SC_STRIPARMOR].timer != -1)
- skill_status_change_end (bl, SC_STRIPARMOR, -1);
- skill_status_change_start (bl, SkillStatusChangeTable[skillid],
- skilllv, 0, 0, 0,
- skill_get_time (skillid, skilllv), 0);
- }
- break;
- case AM_CP_HELM:
- {
- struct status_change *tsc_data = battle_get_sc_data (bl);
- clif_skill_nodamage (src, bl, skillid, skilllv, 1);
- if (tsc_data && tsc_data[SC_STRIPHELM].timer != -1)
- skill_status_change_end (bl, SC_STRIPHELM, -1);
- skill_status_change_start (bl, SkillStatusChangeTable[skillid],
- skilllv, 0, 0, 0,
- skill_get_time (skillid, skilllv), 0);
- }
- break;
- case SA_DISPELL: /* ディスペル */
- {
- int i;
- clif_skill_nodamage (src, bl, skillid, skilllv, 1);
- if (bl->type == BL_PC
- && ((struct map_session_data *) bl)->
- special_state.no_magic_damage)
- break;
- for (i = 0; i < 136; i++)
- {
- if (i == SC_RIDING || i == SC_FALCON || i == SC_HALLUCINATION
- || i == SC_WEIGHT50 || i == SC_WEIGHT90
- || i == SC_STRIPWEAPON || i == SC_STRIPSHIELD
- || i == SC_STRIPARMOR || i == SC_STRIPHELM
- || i == SC_CP_WEAPON || i == SC_CP_SHIELD
- || i == SC_CP_ARMOR || i == SC_CP_HELM || i == SC_COMBO)
- continue;
- skill_status_change_end (bl, i, -1);
- }
- }
- break;
-
- case TF_BACKSLIDING: /* ãƒãƒƒã‚¯ã‚¹ãƒ†ãƒƒãƒ— */
- battle_stopwalking (src, 1);
- skill_blown (src, bl,
- skill_get_blewcount (skillid, skilllv) | 0x10000);
- if (src->type == BL_MOB)
- clif_fixmobpos ((struct mob_data *) src);
- else if (src->type == BL_PC)
- clif_fixpos (src);
- skill_addtimerskill (src, tick + 200, src->id, 0, 0, skillid,
- skilllv, 0, flag);
- break;
-
- case SA_CASTCANCEL:
- clif_skill_nodamage (src, bl, skillid, skilllv, 1);
- skill_castcancel (src, 1);
- if (sd)
- {
- int sp = skill_get_sp (sd->skillid_old, sd->skilllv_old);
- sp = sp * (90 - (skilllv - 1) * 20) / 100;
- if (sp < 0)
- sp = 0;
- pc_heal (sd, 0, -sp);
- }
- break;
- case SA_SPELLBREAKER: // スペルブレイカー
- {
- struct status_change *sc_data = battle_get_sc_data (bl);
- int sp;
- if (sc_data && sc_data[SC_MAGICROD].timer != -1)
- {
- if (dstsd)
- {
- sp = skill_get_sp (skillid, skilllv);
- sp = sp * sc_data[SC_MAGICROD].val2 / 100;
- if (sp > 0x7fff)
- sp = 0x7fff;
- else if (sp < 1)
- sp = 1;
- if (dstsd->status.sp + sp > dstsd->status.max_sp)
- {
- sp = dstsd->status.max_sp - dstsd->status.sp;
- dstsd->status.sp = dstsd->status.max_sp;
- }
- else
- dstsd->status.sp += sp;
- clif_heal (dstsd->fd, SP_SP, sp);
- }
- clif_skill_nodamage (bl, bl, SA_MAGICROD,
- sc_data[SC_MAGICROD].val1, 1);
- if (sd)
- {
- sp = sd->status.max_sp / 5;
- if (sp < 1)
- sp = 1;
- pc_heal (sd, 0, -sp);
- }
- }
- else
- {
- int bl_skillid = 0, bl_skilllv = 0;
- if (bl->type == BL_PC)
- {
- if (dstsd && dstsd->skilltimer != -1)
- {
- bl_skillid = dstsd->skillid;
- bl_skilllv = dstsd->skilllv;
- }
- }
- else if (bl->type == BL_MOB)
- {
- if (dstmd && dstmd->skilltimer != -1)
- {
- bl_skillid = dstmd->skillid;
- bl_skilllv = dstmd->skilllv;
- }
- }
- if (bl_skillid > 0
- && skill_db[bl_skillid].skill_type == BF_MAGIC)
- {
- clif_skill_nodamage (src, bl, skillid, skilllv, 1);
- skill_castcancel (bl, 0);
- sp = skill_get_sp (bl_skillid, bl_skilllv);
- if (dstsd)
- pc_heal (dstsd, 0, -sp);
- if (sd)
- {
- sp = sp * (25 * (skilllv - 1)) / 100;
- if (skilllv > 1 && sp < 1)
- sp = 1;
- if (sp > 0x7fff)
- sp = 0x7fff;
- else if (sp < 1)
- sp = 1;
- if (sd->status.sp + sp > sd->status.max_sp)
- {
- sp = sd->status.max_sp - sd->status.sp;
- sd->status.sp = sd->status.max_sp;
- }
- else
- sd->status.sp += sp;
- clif_heal (sd->fd, SP_SP, sp);
- }
- }
- else if (sd)
- clif_skill_fail (sd, skillid, 0, 0);
- }
- }
- break;
- case SA_MAGICROD:
- if (bl->type == BL_PC
- && ((struct map_session_data *) bl)->
- special_state.no_magic_damage)
- break;
- skill_status_change_start (bl, SkillStatusChangeTable[skillid],
- skilllv, 0, 0, 0,
- skill_get_time (skillid, skilllv), 0);
- break;
- case SA_AUTOSPELL: /* オートスペル */
- clif_skill_nodamage (src, bl, skillid, skilllv, 1);
- if (sd)
- clif_autospell (sd, skilllv);
- else
- {
- int maxlv = 1, spellid = 0;
- static const int spellarray[3] =
- { MG_COLDBOLT, MG_FIREBOLT, MG_LIGHTNINGBOLT };
- if (skilllv >= 10)
- {
- spellid = MG_FROSTDIVER;
- maxlv = skilllv - 9;
- }
- else if (skilllv >= 8)
- {
- spellid = MG_FIREBALL;
- maxlv = skilllv - 7;
- }
- else if (skilllv >= 5)
- {
- spellid = MG_SOULSTRIKE;
- maxlv = skilllv - 4;
- }
- else if (skilllv >= 2)
- {
- int i = MRAND (3);
- spellid = spellarray[i];
- maxlv = skilllv - 1;
- }
- else if (skilllv > 0)
- {
- spellid = MG_NAPALMBEAT;
- maxlv = 3;
- }
- if (spellid > 0)
- skill_status_change_start (src, SC_AUTOSPELL, skilllv,
- spellid, maxlv, 0,
- skill_get_time (SA_AUTOSPELL,
- skilllv), 0);
- }
- break;
-
- /* ランダム属性変化ã€æ°´å±žæ€§å¤‰åŒ–ã€åœ°ã€ç«ã€é¢¨ */
- case NPC_ATTRICHANGE:
- case NPC_CHANGEWATER:
- case NPC_CHANGEGROUND:
- case NPC_CHANGEFIRE:
- case NPC_CHANGEWIND:
- /* 毒ã€è–ã€å¿µã€é—‡ */
- case NPC_CHANGEPOISON:
- case NPC_CHANGEHOLY:
- case NPC_CHANGEDARKNESS:
- case NPC_CHANGETELEKINESIS:
- if (md)
- {
- clif_skill_nodamage (src, bl, skillid, skilllv, 1);
- md->def_ele = skill_get_pl (skillid);
- if (md->def_ele == 0) /* ランダム変化ã€ãŸã ã—〠*/
- md->def_ele = MRAND (10); /* ä¸æ­»å±žæ€§ã¯é™¤ã */
- md->def_ele += (1 + MRAND (4)) * 20; /* 属性レベルã¯ãƒ©ãƒ³ãƒ€ãƒ  */
- }
- break;
-
- case NPC_HALLUCINATION:
- clif_skill_nodamage (src, bl, skillid, skilllv, 1);
- if (bl->type == BL_PC
- && ((struct map_session_data *) bl)->
- special_state.no_magic_damage)
- break;
- skill_status_change_start (bl, SkillStatusChangeTable[skillid],
- skilllv, 0, 0, 0,
- skill_get_time (skillid, skilllv), 0);
- break;
-
- case NPC_KEEPING:
- case NPC_BARRIER:
- {
- int skill_time = skill_get_time (skillid, skilllv);
- clif_skill_nodamage (src, bl, skillid, skilllv, 1);
- skill_status_change_start (bl, SkillStatusChangeTable[skillid],
- skilllv, 0, 0, 0, skill_time, 0);
- mob_changestate ((struct mob_data *) src, MS_DELAY, skill_time);
- }
- break;
-
- case NPC_DARKBLESSING:
- {
- int sc_def = 100 - battle_get_mdef (bl);
- clif_skill_nodamage (src, bl, skillid, skilllv, 1);
- if (bl->type == BL_PC
- && ((struct map_session_data *) bl)->
- special_state.no_magic_damage)
- break;
- if (battle_get_elem_type (bl) == 7 || battle_get_race (bl) == 6)
- break;
- if (MRAND (100) < sc_def * (50 + skilllv * 5) / 100)
- {
- if (dstsd)
- {
- int hp = battle_get_hp (bl) - 1;
- pc_heal (dstsd, -hp, 0);
- }
- else if (dstmd)
- dstmd->hp = 1;
- }
- }
- break;
-
- case NPC_SELFDESTRUCTION: /* 自爆 */
- case NPC_SELFDESTRUCTION2: /* 自爆2 */
- skill_status_change_start (bl, SkillStatusChangeTable[skillid],
- skilllv, skillid, 0, 0,
- skill_get_time (skillid, skilllv), 0);
- break;
- case NPC_LICK:
- clif_skill_nodamage (src, bl, skillid, skilllv, 1);
- if (bl->type == BL_PC
- && ((struct map_session_data *) bl)->
- special_state.no_weapon_damage)
- break;
- if (dstsd)
- pc_heal (dstsd, 0, -100);
- if (MRAND (100) < (skilllv * 5) * sc_def_vit / 100)
- skill_status_change_start (bl, SC_STAN, skilllv, 0, 0, 0,
- skill_get_time2 (skillid, skilllv),
- 0);
- break;
-
- case NPC_SUICIDE: /* 自決 */
- if (src && bl && md)
- {
- clif_skill_nodamage (src, bl, skillid, skilllv, 1);
- mob_damage (NULL, md, md->hp, 0);
- }
- break;
-
- case NPC_SUMMONSLAVE: /* 手下å¬å–š */
- case NPC_SUMMONMONSTER: /* MOBå¬å–š */
+ case SkillID::NPC_SUMMONSLAVE:
if (md && !md->master_id)
{
- mob_summonslave (md,
- mob_db[md->mob_class].skill[md->skillidx].val,
- skilllv,
- (skillid == NPC_SUMMONSLAVE) ? 1 : 0);
+ mob_summonslave(md,
+ mob_db[md->mob_class].skill[md->skillidx].val,
+ skilllv,
+ 1);
}
break;
- case NPC_TRANSFORMATION:
- case NPC_METAMORPHOSIS:
- if (md)
- mob_class_change (md,
- mob_db[md->mob_class].skill[md->skillidx].val);
- break;
-
- case NPC_EMOTION: /* エモーション */
+ case SkillID::NPC_EMOTION:
if (md)
- clif_emotion (&md->bl,
- mob_db[md->mob_class].skill[md->skillidx].val[0]);
- break;
-
- case NPC_DEFENDER:
- clif_skill_nodamage (src, bl, skillid, skilllv, 1);
- break;
-
- case WE_MALE: /* å›ã ã‘ã¯è­·ã‚‹ã‚ˆ */
- if (sd && dstsd)
- {
- int hp_rate =
- (skilllv <=
- 0) ? 0 : skill_db[skillid].hp_rate[skilllv - 1];
- int gain_hp = sd->status.max_hp * abs (hp_rate) / 100; // 15%
- clif_skill_nodamage (src, bl, skillid, gain_hp, 1);
- battle_heal (NULL, bl, gain_hp, 0, 0);
- }
- break;
- case WE_FEMALE: /* ã‚ãªãŸã®ç‚ºã«çŠ ç‰²ã«ãªã‚Šã¾ã™ */
- if (sd && dstsd)
- {
- int sp_rate =
- (skilllv <=
- 0) ? 0 : skill_db[skillid].sp_rate[skilllv - 1];
- int gain_sp = sd->status.max_sp * abs (sp_rate) / 100; // 15%
- clif_skill_nodamage (src, bl, skillid, gain_sp, 1);
- battle_heal (NULL, bl, 0, gain_sp, 0);
- }
- break;
-
- case WE_CALLPARTNER: /* ã‚ãªãŸã«ä¼šã„ãŸã„ */
- if (sd && dstsd)
- {
- if (map[sd->bl.m].flag.nomemo)
- {
- clif_skill_teleportmessage (sd, 1);
- return 0;
- }
- if ((dstsd = pc_get_partner (sd)) == NULL)
- {
- clif_skill_fail (sd, skillid, 0, 0);
- return 0;
- }
- skill_unitsetting (src, skillid, skilllv, sd->bl.x, sd->bl.y,
- 0);
- }
- break;
-
- case PF_HPCONVERSION: /* ライフ置ãæ›ãˆ */
- clif_skill_nodamage (src, bl, skillid, skilllv, 1);
- if (sd)
- {
- int conv_hp = 0, conv_sp = 0;
- conv_hp = sd->status.hp / 10; //基本ã¯HPã®10%
- sd->status.hp -= conv_hp; //HPを減らã™
- conv_sp = conv_hp * 20 * skilllv / 100;
- conv_sp =
- (sd->status.sp + conv_sp >
- sd->status.max_sp) ? sd->status.max_sp -
- sd->status.sp : conv_sp;
- sd->status.sp += conv_sp; //SPを増やã™
- pc_heal (sd, -conv_hp, conv_sp);
- clif_heal (sd->fd, SP_SP, conv_sp);
- }
- break;
- case HT_REMOVETRAP: /* リムーブトラップ */
- clif_skill_nodamage (src, bl, skillid, skilllv, 1);
- {
- struct skill_unit *su = NULL;
- struct item item_tmp;
- if ((bl->type == BL_SKILL) &&
- (su = (struct skill_unit *) bl) &&
- (su->group->src_id == src->id || map[bl->m].flag.pvp
- || map[bl->m].flag.gvg) && (su->group->unit_id >= 0x8f
- && su->group->unit_id <=
- 0x99)
- && (su->group->unit_id != 0x92))
- { //ç½ ã‚’å–ã‚Šè¿”ã™
- if (sd)
- {
- if (battle_config.skill_removetrap_type == 1)
- {
- for (int i = 0; i < 10; i++)
- {
- if (skill_db[su->group->skill_id].itemid[i] >
- 0)
- {
- memset (&item_tmp, 0, sizeof (item_tmp));
- item_tmp.nameid =
- skill_db[su->group->
- skill_id].itemid[i];
- item_tmp.identify = 1;
- int item_flag;
- if (item_tmp.nameid
- && (item_flag =
- pc_additem (sd, &item_tmp,
- skill_db[su->
- group->skill_id].amount
- [i])))
- {
- clif_additem (sd, 0, 0, item_flag);
- map_addflooritem (&item_tmp,
- skill_db[su->
- group->skill_id].amount
- [i], sd->bl.m,
- sd->bl.x, sd->bl.y,
- NULL, NULL, NULL,
- 0);
- }
- }
- }
- }
- else
- {
- memset (&item_tmp, 0, sizeof (item_tmp));
- item_tmp.nameid = 1065;
- item_tmp.identify = 1;
- int item_flag;
- if (item_tmp.nameid
- && (item_flag = pc_additem (sd, &item_tmp, 1)))
- {
- clif_additem (sd, 0, 0, item_flag);
- map_addflooritem (&item_tmp, 1, sd->bl.m,
- sd->bl.x, sd->bl.y, NULL,
- NULL, NULL, 0);
- }
- }
-
- }
- if (su->group->unit_id == 0x91 && su->group->val2)
- {
- struct block_list *target =
- map_id2bl (su->group->val2);
- if (target
- && (target->type == BL_PC
- || target->type == BL_MOB))
- skill_status_change_end (target, SC_ANKLE, -1);
- }
- skill_delunit (su);
- }
- }
- break;
- case HT_SPRINGTRAP: /* スプリングトラップ */
- clif_skill_nodamage (src, bl, skillid, skilllv, 1);
- {
- struct skill_unit *su = NULL;
- if ((bl->type == BL_SKILL) && (su = (struct skill_unit *) bl)
- && (su->group))
- {
- switch (su->group->unit_id)
- {
- case 0x8f: /* ブラストマイン */
- case 0x90: /* スキッドトラップ */
- case 0x93: /* ランドマイン */
- case 0x94: /* ショックウェーブトラップ */
- case 0x95: /* サンドマン */
- case 0x96: /* フラッシャー */
- case 0x97: /* フリージングトラップ */
- case 0x98: /* クレイモアートラップ */
- case 0x99: /* トーキーボックス */
- su->group->unit_id = 0x8c;
- clif_changelook (bl, LOOK_BASE,
- su->group->unit_id);
- su->group->limit =
- DIFF_TICK (tick + 1500, su->group->tick);
- su->limit =
- DIFF_TICK (tick + 1500, su->group->tick);
- }
- }
- }
- break;
- case BD_ENCORE: /* アンコール */
- clif_skill_nodamage (src, bl, skillid, skilllv, 1);
- if (sd)
- skill_use_id (sd, src->id, sd->skillid_dance,
- sd->skilllv_dance);
- break;
- case AS_SPLASHER: /* ベナムスプラッシャー */
- if ((double) battle_get_max_hp (bl) * 2 / 3 < battle_get_hp (bl)) //HPãŒ2/3以上残ã£ã¦ã„ãŸã‚‰å¤±æ•—
- return 1;
- clif_skill_nodamage (src, bl, skillid, skilllv, 1);
- skill_status_change_start (bl, SkillStatusChangeTable[skillid],
- skilllv, skillid, src->id, 0,
- skill_get_time (skillid, skilllv), 0);
- break;
- case PF_MINDBREAKER: /* プロボック */
- {
- struct status_change *sc_data = battle_get_sc_data (bl);
-
- /* MVPmobã¨ä¸æ­»ã«ã¯åŠ¹ã‹ãªã„ */
- if ((bl->type == BL_MOB && battle_get_mode (bl) & 0x20) || battle_check_undead (battle_get_race (bl), battle_get_elem_type (bl))) //ä¸æ­»ã«ã¯åŠ¹ã‹ãªã„
- {
- map_freeblock_unlock ();
- return 1;
- }
-
- clif_skill_nodamage (src, bl, skillid, skilllv, 1);
- skill_status_change_start (bl, SkillStatusChangeTable[skillid],
- skilllv, 0, 0, 0,
- skill_get_time (skillid, skilllv), 0);
-
- if (dstmd && dstmd->skilltimer != -1 && dstmd->state.skillcastcancel) // 詠唱妨害
- skill_castcancel (bl, 0);
- if (dstsd && dstsd->skilltimer != -1
- && (!dstsd->special_state.no_castcancel
- || map[bl->m].flag.gvg) && dstsd->state.skillcastcancel
- && !dstsd->special_state.no_castcancel2)
- skill_castcancel (bl, 0);
-
- if (sc_data)
- {
- if (sc_data[SC_FREEZE].timer != -1)
- skill_status_change_end (bl, SC_FREEZE, -1);
- if (sc_data[SC_STONE].timer != -1
- && sc_data[SC_STONE].val2 == 0)
- skill_status_change_end (bl, SC_STONE, -1);
- if (sc_data[SC_SLEEP].timer != -1)
- skill_status_change_end (bl, SC_SLEEP, -1);
- }
-
- if (bl->type == BL_MOB)
- {
- int range = skill_get_range (skillid, skilllv);
- if (range < 0)
- range = battle_get_range (src) - (range + 1);
- mob_target ((struct mob_data *) bl, src, range);
- }
- }
- break;
-
- case RG_CLEANER: //AppleGirl
- clif_skill_nodamage (src, bl, skillid, skilllv, 1);
- {
- struct skill_unit *su = NULL;
- if ((bl->type == BL_SKILL) &&
- (su = (struct skill_unit *) bl) &&
- (su->group->src_id == src->id || map[bl->m].flag.pvp
- || map[bl->m].flag.gvg) && (su->group->unit_id == 0xb0))
- { //ç½ ã‚’å–ã‚Šè¿”ã™
- if (sd)
- skill_delunit (su);
- }
- }
- break;
- default:
- printf ("Unknown skill used:%d\n", skillid);
- map_freeblock_unlock ();
- return 1;
- }
-
- map_freeblock_unlock ();
- return 0;
-}
-
-/*==========================================
- * スキル使用(詠唱完了ã€ID指定)
- *------------------------------------------
- */
-static
-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_retv ( sd);
-
- if (sd->bl.prev == NULL) //prevãŒç„¡ã„ã®ã¯ã‚ã‚Šãªã®ï¼Ÿ
- return;
-
- if (sd->skillid != SA_CASTCANCEL && sd->skilltimer != tid) /* タイマIDã®ç¢ºèª */
- return;
- if (sd->skillid != SA_CASTCANCEL && sd->skilltimer != -1
- && pc_checkskill (sd, SA_FREECAST) > 0)
- {
- sd->speed = sd->prev_speed;
- clif_updatestatus (sd, SP_SPEED);
- }
- if (sd->skillid != SA_CASTCANCEL)
- sd->skilltimer = -1;
-
- if ((bl = map_id2bl (sd->skilltarget)) == NULL || bl->prev == NULL)
- {
- sd->canact_tick = tick;
- sd->canmove_tick = tick;
- sd->skillitem = sd->skillitemlv = -1;
- return;
- }
- if (sd->bl.m != bl->m || pc_isdead (sd))
- { //マップãŒé•ã†ã‹è‡ªåˆ†ãŒæ­»ã‚“ã§ã„ã‚‹
- sd->canact_tick = tick;
- sd->canmove_tick = tick;
- sd->skillitem = sd->skillitemlv = -1;
- return;
- }
-
- if (sd->skillid == PR_LEXAETERNA)
- {
- struct status_change *sc_data = battle_get_sc_data (bl);
- if (sc_data
- && (sc_data[SC_FREEZE].timer != -1
- || (sc_data[SC_STONE].timer != -1
- && sc_data[SC_STONE].val2 == 0)))
- {
- clif_skill_fail (sd, sd->skillid, 0, 0);
- sd->canact_tick = tick;
- sd->canmove_tick = tick;
- sd->skillitem = sd->skillitemlv = -1;
- return;
- }
- }
- else if (sd->skillid == RG_BACKSTAP)
- {
- int dir = map_calc_dir (&sd->bl, bl->x, bl->y), t_dir =
- battle_get_dir (bl);
- int dist = distance (sd->bl.x, sd->bl.y, bl->x, bl->y);
- if (bl->type != BL_SKILL && (dist == 0 || map_check_dir (dir, t_dir)))
- {
- clif_skill_fail (sd, sd->skillid, 0, 0);
- sd->canact_tick = tick;
- sd->canmove_tick = tick;
- sd->skillitem = sd->skillitemlv = -1;
- return;
- }
- }
-
- inf2 = skill_get_inf2 (sd->skillid);
- if (((skill_get_inf (sd->skillid) & 1) || inf2 & 4) && // 彼我敵対関係ãƒã‚§ãƒƒã‚¯
- battle_check_target (&sd->bl, bl, BCT_ENEMY) <= 0)
- {
- sd->canact_tick = tick;
- sd->canmove_tick = tick;
- sd->skillitem = sd->skillitemlv = -1;
- return;
- }
- if (inf2 & 0xC00 && sd->bl.id != bl->id)
- {
- int fail_flag = 1;
- if (inf2 & 0x400 && battle_check_target (&sd->bl, bl, BCT_PARTY) > 0)
- fail_flag = 0;
- if (inf2 & 0x800 && sd->status.guild_id > 0
- && sd->status.guild_id == battle_get_guild_id (bl))
- fail_flag = 0;
- if (fail_flag)
- {
- clif_skill_fail (sd, sd->skillid, 0, 0);
- sd->canact_tick = tick;
- sd->canmove_tick = tick;
- sd->skillitem = sd->skillitemlv = -1;
- return;
- }
- }
-
- range = skill_get_range (sd->skillid, sd->skilllv);
- if (range < 0)
- range = battle_get_range (&sd->bl) - (range + 1);
- range += battle_config.pc_skill_add_range;
- if ((sd->skillid == MO_EXTREMITYFIST && sd->sc_data[SC_COMBO].timer != -1
- && sd->sc_data[SC_COMBO].val1 == MO_COMBOFINISH)
- || (sd->skillid == CH_TIGERFIST && sd->sc_data[SC_COMBO].timer != -1
- && sd->sc_data[SC_COMBO].val1 == MO_COMBOFINISH)
- || (sd->skillid == CH_CHAINCRUSH && sd->sc_data[SC_COMBO].timer != -1
- && sd->sc_data[SC_COMBO].val1 == MO_COMBOFINISH)
- || (sd->skillid == CH_CHAINCRUSH && sd->sc_data[SC_COMBO].timer != -1
- && sd->sc_data[SC_COMBO].val1 == CH_TIGERFIST))
- range +=
- skill_get_blewcount (MO_COMBOFINISH, sd->sc_data[SC_COMBO].val2);
- if (battle_config.skill_out_range_consume)
- { // changed to allow casting when target walks out of range [Valaris]
- if (range < distance (sd->bl.x, sd->bl.y, bl->x, bl->y))
- {
- clif_skill_fail (sd, sd->skillid, 0, 0);
- sd->canact_tick = tick;
- sd->canmove_tick = tick;
- sd->skillitem = sd->skillitemlv = -1;
- return;
- }
- }
- if (!skill_check_condition (sd, 1))
- { /* 使用æ¡ä»¶ãƒã‚§ãƒƒã‚¯ */
- sd->canact_tick = tick;
- sd->canmove_tick = tick;
- sd->skillitem = sd->skillitemlv = -1;
- return;
- }
- sd->skillitem = sd->skillitemlv = -1;
- if (battle_config.skill_out_range_consume)
- {
- if (range < distance (sd->bl.x, sd->bl.y, bl->x, bl->y))
- {
- clif_skill_fail (sd, sd->skillid, 0, 0);
- sd->canact_tick = tick;
- sd->canmove_tick = tick;
- return;
- }
- }
-
- if (battle_config.pc_skill_log)
- printf ("PC %d skill castend skill=%d\n", sd->bl.id, sd->skillid);
- pc_stop_walking (sd, 0);
-
- switch (skill_get_nk (sd->skillid))
- {
- /* 攻撃系/å¹ã飛ã°ã—ç³» */
- case 0:
- case 2:
- skill_castend_damage_id (&sd->bl, bl, sd->skillid, sd->skilllv,
- tick, 0);
- break;
- case 1: /* 支æ´ç³» */
- if ((sd->skillid == AL_HEAL
- || (sd->skillid == ALL_RESURRECTION && bl->type != BL_PC)
- || sd->skillid == PR_ASPERSIO)
- && battle_check_undead (battle_get_race (bl),
- battle_get_elem_type (bl)))
- skill_castend_damage_id (&sd->bl, bl, sd->skillid,
- sd->skilllv, tick, 0);
- else
- skill_castend_nodamage_id (&sd->bl, bl, sd->skillid,
- sd->skilllv, tick, 0);
- break;
- }
-}
-
-/*==========================================
- * スキル使用(詠唱完了ã€å ´æ‰€æŒ‡å®šã®å®Ÿéš›ã®å‡¦ç†ï¼‰
- *------------------------------------------
- */
-int skill_castend_pos2 (struct block_list *src, int x, int y, int skillid,
- int skilllv, unsigned int tick, int flag)
-{
- struct map_session_data *sd = NULL;
- int i, tmpx = 0, tmpy = 0, x1 = 0, y1 = 0;
-
- nullpo_retr (0, src);
-
- if (src->type == BL_PC)
- {
- nullpo_retr (0, sd = (struct map_session_data *) src);
- }
- if (skillid != WZ_METEOR &&
- skillid != WZ_SIGHTRASHER &&
- skillid != AM_CANNIBALIZE && skillid != AM_SPHEREMINE)
- clif_skill_poseffect (src, skillid, skilllv, x, y, tick);
-
- if (skillnotok (skillid, sd)) // [MouseJstr]
- return 0;
-
- switch (skillid)
- {
- case PR_BENEDICTIO: /* è–体é™ç¦ */
- skill_area_temp[1] = src->id;
- map_foreachinarea (skill_area_sub,
- src->m, x - 1, y - 1, x + 1, y + 1, 0,
- src, skillid, skilllv, tick,
- flag | BCT_NOENEMY | 1,
- skill_castend_nodamage_id);
- map_foreachinarea (skill_area_sub, src->m, x - 1, y - 1, x + 1,
- y + 1, 0, src, skillid, skilllv, tick,
- flag | BCT_ENEMY | 1, skill_castend_damage_id);
- break;
-
- case BS_HAMMERFALL: /* ãƒãƒ³ãƒžãƒ¼ãƒ•ã‚©ãƒ¼ãƒ« */
- skill_area_temp[1] = src->id;
- skill_area_temp[2] = x;
- skill_area_temp[3] = y;
- map_foreachinarea (skill_area_sub,
- src->m, x - 2, y - 2, x + 2, y + 2, 0,
- src, skillid, skilllv, tick,
- flag | BCT_ENEMY | 2,
- skill_castend_nodamage_id);
- break;
-
- case HT_DETECTING: /* ディテクティング */
- {
- const int range = 7;
- map_foreachinarea (skill_status_change_timer_sub,
- src->m, src->x - range, src->y - range,
- src->x + range, src->y + range, 0, src,
- SC_SIGHT, tick);
- }
- break;
-
- case MG_SAFETYWALL: /* セイフティウォール */
- case MG_FIREWALL: /* ファイヤーウォール */
- case MG_THUNDERSTORM: /* サンダーストーム */
- case AL_PNEUMA: /* ニューマ */
- case WZ_ICEWALL: /* アイスウォール */
- case WZ_FIREPILLAR: /* ファイアピラー */
- case WZ_SIGHTRASHER:
- case WZ_QUAGMIRE: /* クァグマイア */
- case WZ_VERMILION: /* ロードオブヴァーミリオン */
- case WZ_FROSTNOVA: /* フロストノヴァ */
- case WZ_STORMGUST: /* ストームガスト */
- case WZ_HEAVENDRIVE: /* ヘヴンズドライブ */
- case PR_SANCTUARY: /* サンクãƒãƒ¥ã‚¢ãƒª */
- case PR_MAGNUS: /* マグヌスエクソシズム */
- case CR_GRANDCROSS: /* グランドクロス */
- case HT_SKIDTRAP: /* スキッドトラップ */
- case HT_LANDMINE: /* ランドマイン */
- case HT_ANKLESNARE: /* アンクルスãƒã‚¢ */
- case HT_SHOCKWAVE: /* ショックウェーブトラップ */
- case HT_SANDMAN: /* サンドマン */
- case HT_FLASHER: /* フラッシャー */
- case HT_FREEZINGTRAP: /* フリージングトラップ */
- case HT_BLASTMINE: /* ブラストマイン */
- case HT_CLAYMORETRAP: /* クレイモアートラップ */
- case AS_VENOMDUST: /* ベノムダスト */
- case AM_DEMONSTRATION: /* デモンストレーション */
- case PF_SPIDERWEB: /* スパイダーウェッブ */
- case PF_FOGWALL: /* フォグウォール */
- case HT_TALKIEBOX: /* トーキーボックス */
- skill_unitsetting (src, skillid, skilllv, x, y, 0);
- break;
-
- case RG_GRAFFITI: /* Graffiti [Valaris] */
- skill_clear_unitgroup (src);
- skill_unitsetting (src, skillid, skilllv, x, y, 0);
- break;
-
- case SA_VOLCANO: /* ボルケーノ */
- case SA_DELUGE: /* デリュージ */
- case SA_VIOLENTGALE: /* ãƒã‚¤ã‚ªãƒ¬ãƒ³ãƒˆã‚²ã‚¤ãƒ« */
- case SA_LANDPROTECTOR: /* ランドプロテクター */
- skill_clear_element_field (src); //æ—¢ã«è‡ªåˆ†ãŒç™ºå‹•ã—ã¦ã„る属性場をクリア
- skill_unitsetting (src, skillid, skilllv, x, y, 0);
- break;
-
- case WZ_METEOR: //メテオストーム
- {
- int flag_ = 0;
- for (i = 0; i < 2 + (skilllv >> 1); i++)
- {
- int j = 0, c;
- do
- {
- tmpx = x + (MRAND (7) - 3);
- tmpy = y + (MRAND (7) - 3);
- if (tmpx < 0)
- tmpx = 0;
- else if (tmpx >= map[src->m].xs)
- tmpx = map[src->m].xs - 1;
- if (tmpy < 0)
- tmpy = 0;
- else if (tmpy >= map[src->m].ys)
- tmpy = map[src->m].ys - 1;
- j++;
- }
- while (((c = map_getcell (src->m, tmpx, tmpy)) == 1 || c == 5)
- && j < 100);
- if (j >= 100)
- continue;
- if (flag_ == 0)
- {
- clif_skill_poseffect (src, skillid, skilllv, tmpx, tmpy,
- tick);
- flag_ = 1;
- }
- if (i > 0)
- skill_addtimerskill (src, tick + i * 1000, 0, tmpx, tmpy,
- skillid, skilllv, (x1 << 16) | y1,
- flag_);
- x1 = tmpx;
- y1 = tmpy;
- }
- skill_addtimerskill (src, tick + i * 1000, 0, tmpx, tmpy, skillid,
- skilllv, -1, flag_);
- }
- break;
-
- case AL_WARP: /* ワープãƒãƒ¼ã‚¿ãƒ« */
- if (sd)
- {
- if (map[sd->bl.m].flag.noteleport) /* テレãƒç¦æ­¢ */
- break;
- clif_skill_warppoint (sd, sd->skillid,
- sd->status.save_point.map,
- (sd->skilllv >
- 1) ? sd->status.memo_point[0].map : "",
- (sd->skilllv >
- 2) ? sd->status.memo_point[1].map : "",
- (sd->skilllv >
- 3) ? sd->status.
- memo_point[2].map : "");
- }
- break;
- case MO_BODYRELOCATION:
- if (sd)
- {
- pc_movepos (sd, x, y);
- }
- else if (src->type == BL_MOB)
- mob_warp ((struct mob_data *) src, -1, x, y, 0);
- break;
- case AM_CANNIBALIZE: // ãƒã‚¤ã‚ªãƒ—ラント
- if (sd)
- {
- int mx, my, id = 0;
- struct mob_data *md;
-
- mx = x; // + (rand()%10 - 5);
- my = y; // + (rand()%10 - 5);
- id = mob_once_spawn (sd, "this", mx, my, "--ja--", 1118, 1,
- "");
- if ((md = (struct mob_data *) map_id2bl (id)) != NULL)
- {
- md->master_id = sd->bl.id;
- md->hp = 2210 + skilllv * 200;
- md->state.special_mob_ai = 1;
- md->deletetimer =
- add_timer (gettick () +
- skill_get_time (skillid, skilllv),
- mob_timer_delete, id, 0);
- }
- clif_skill_poseffect (src, skillid, skilllv, x, y, tick);
- }
- break;
- case AM_SPHEREMINE: // スフィアーマイン
- if (sd)
- {
- int mx, my, id = 0;
- struct mob_data *md;
-
- mx = x; // + (rand()%10 - 5);
- my = y; // + (rand()%10 - 5);
- id = mob_once_spawn (sd, "this", mx, my, "--ja--", 1142, 1,
- "");
- if ((md = (struct mob_data *) map_id2bl (id)) != NULL)
- {
- md->master_id = sd->bl.id;
- md->hp = 1000 + skilllv * 200;
- md->state.special_mob_ai = 2;
- md->deletetimer =
- add_timer (gettick () +
- skill_get_time (skillid, skilllv),
- mob_timer_delete, id, 0);
- }
- clif_skill_poseffect (src, skillid, skilllv, x, y, tick);
- }
+ clif_emotion(&md->bl,
+ mob_db[md->mob_class].skill[md->skillidx].val[0]);
break;
}
+ map_freeblock_unlock();
return 0;
}
/*==========================================
- * スキル使用(詠唱完了ã€map指定)
- *------------------------------------------
- */
-int skill_castend_map (struct map_session_data *sd, int skill_num,
- const char *mapname)
-{
- int x = 0, y = 0;
-
- nullpo_retr (0, sd);
- if (sd->bl.prev == NULL || pc_isdead (sd))
- return 0;
-
- if (sd->opt1 > 0 || sd->status.option & 2)
- return 0;
- //スキルãŒä½¿ãˆãªã„状態異常中
- if (sd->sc_data)
- {
- if (sd->sc_data[SC_DIVINA].timer != -1 ||
- sd->sc_data[SC_ROKISWEIL].timer != -1 ||
- sd->sc_data[SC_AUTOCOUNTER].timer != -1 ||
- sd->sc_data[SC_STEELBODY].timer != -1 ||
- sd->sc_data[SC_DANCING].timer != -1 ||
- sd->sc_data[SC_BERSERK].timer != -1)
- return 0;
- }
-
- if (skill_num != sd->skillid) /* ä¸æ­£ãƒ‘ケットらã—ã„ */
- return 0;
-
- pc_stopattack (sd);
-
- if (battle_config.pc_skill_log)
- printf ("PC %d skill castend skill =%d map=%s\n", sd->bl.id,
- skill_num, mapname);
- pc_stop_walking (sd, 0);
-
- if (strcmp (mapname, "cancel") == 0)
- return 0;
-
- switch (skill_num)
- {
- case AL_TELEPORT: /* テレãƒãƒ¼ãƒˆ */
- if (strcmp (mapname, "Random") == 0)
- pc_randomwarp (sd, 3);
- else
- pc_setpos (sd, sd->status.save_point.map,
- sd->status.save_point.x, sd->status.save_point.y,
- 3);
- break;
-
- case AL_WARP: /* ワープãƒãƒ¼ã‚¿ãƒ« */
- {
- const struct point *p[] = {
- &sd->status.save_point, &sd->status.memo_point[0],
- &sd->status.memo_point[1], &sd->status.memo_point[2],
- };
- struct skill_unit_group *group;
- int i;
- int maxcount = 0;
-
- if ((maxcount = skill_get_maxcount (sd->skillid)) > 0)
- {
- int c;
- for (i = c = 0; i < MAX_SKILLUNITGROUP; i++)
- {
- if (sd->skillunit[i].alive_count > 0
- && sd->skillunit[i].skill_id == sd->skillid)
- c++;
- }
- if (c >= maxcount)
- {
- clif_skill_fail (sd, sd->skillid, 0, 0);
- sd->canact_tick = gettick ();
- sd->canmove_tick = gettick ();
- sd->skillitem = sd->skillitemlv = -1;
- return 0;
- }
- }
-
- for (i = 0; i < sd->skilllv; i++)
- {
- if (strcmp (mapname, p[i]->map) == 0)
- {
- x = p[i]->x;
- y = p[i]->y;
- break;
- }
- }
- if (x == 0 || y == 0) /* ä¸æ­£ãƒ‘ケット? */
- return 0;
-
- if (!skill_check_condition (sd, 3))
- return 0;
- if ((group =
- skill_unitsetting (&sd->bl, sd->skillid, sd->skilllv,
- sd->skillx, sd->skilly, 0)) == NULL)
- return 0;
- CREATE (group->valstr, char, 24);
- memcpy (group->valstr, map, 24);
- group->val2 = (x << 16) | y;
- }
- break;
- }
-
- return 0;
-}
-
-/*==========================================
- * スキルユニット設定処ç†
- *------------------------------------------
- */
-struct skill_unit_group *skill_unitsetting (struct block_list *src,
- int skillid, int skilllv, int x,
- int y, int flag)
-{
- struct skill_unit_group *group;
- int i, count = 1, limit_ = 10000, val1_ = 0, val2_ = 0;
- int target = BCT_ENEMY, interval = 1000, range_ = 0;
- int dir = 0, aoe_diameter = 0; // -- aoe_diameter (moonsoul) added for sage Area Of Effect skills
-
- nullpo_retr (0, src);
-
- switch (skillid)
- { /* 設定 */
-
- case MG_SAFETYWALL: /* セイフティウォール */
- limit_ = skill_get_time (skillid, skilllv);
- val2_ = skilllv + 1;
- interval = -1;
- target = (battle_config.defnotenemy) ? BCT_NOENEMY : BCT_ALL;
- break;
-
- case MG_FIREWALL: /* ファイヤーウォール */
- if (src->x == x && src->y == y)
- dir = 2;
- else
- dir = map_calc_dir (src, x, y);
- if (dir & 1)
- count = 5;
- else
- count = 3;
- limit_ = skill_get_time (skillid, skilllv);
- val2_ = 4 + skilllv;
- interval = 1;
- break;
-
- case AL_PNEUMA: /* ニューマ */
- limit_ = skill_get_time (skillid, skilllv);
- interval = -1;
- target = (battle_config.defnotenemy) ? BCT_NOENEMY : BCT_ALL;
- count = 9;
- break;
-
- case AL_WARP: /* ワープãƒãƒ¼ã‚¿ãƒ« */
- target = BCT_ALL;
- val1_ = skilllv + 6;
- if (flag == 0)
- limit_ = 2000;
- else
- limit_ = skill_get_time (skillid, skilllv);
- break;
-
- case PR_SANCTUARY: /* サンクãƒãƒ¥ã‚¢ãƒª */
- count = 21;
- limit_ = skill_get_time (skillid, skilllv);
- val1_ = skilllv + 3;
- val2_ = (skilllv > 6) ? 777 : skilllv * 100;
- target = BCT_ALL;
- range_ = 1;
- break;
-
- case PR_MAGNUS: /* マグヌスエクソシズム */
- count = 33;
- limit_ = skill_get_time (skillid, skilllv);
- interval = 3000;
- break;
-
- case WZ_FIREPILLAR: /* ファイアーピラー */
- if (flag == 0)
- limit_ = skill_get_time (skillid, skilllv);
- else
- limit_ = 1000;
- interval = 2000;
- val1_ = skilllv + 2;
- range_ = 1;
- break;
-
- case MG_THUNDERSTORM: /* サンダーストーム */
- limit_ = 500;
- range_ = 1;
- break;
-
- case WZ_FROSTNOVA: /* フロストノヴァ */
- limit_ = 500;
- range_ = 5;
- break;
- case WZ_HEAVENDRIVE: /* ヘヴンズドライブ */
- limit_ = 500;
- range_ = 2;
- break;
-
- case WZ_METEOR: /* メテオストーム */
- limit_ = 500;
- range_ = 3;
- break;
-
- case WZ_SIGHTRASHER:
- limit_ = 500;
- count = 41;
- break;
-
- case WZ_VERMILION: /* ロードオブヴァーミリオン */
- limit_ = 4100;
- interval = 1000;
- range_ = 6;
- break;
-
- case WZ_ICEWALL: /* アイスウォール */
- limit_ = skill_get_time (skillid, skilllv);
- count = 5;
- break;
-
- case WZ_STORMGUST: /* ストームガスト */
- limit_ = 4600;
- interval = 450;
- range_ = 5;
- break;
-
- case WZ_QUAGMIRE: /* クァグマイア */
- limit_ = skill_get_time (skillid, skilllv);
- interval = 200;
- count = 25;
- break;
-
- case HT_SKIDTRAP: /* スキッドトラップ */
- case HT_LANDMINE: /* ランドマイン */
- case HT_ANKLESNARE: /* アンクルスãƒã‚¢ */
- case HT_SANDMAN: /* サンドマン */
- case PF_SPIDERWEB: /* スパイダーウェッブ */
- case HT_FLASHER: /* フラッシャー */
- case HT_FREEZINGTRAP: /* フリージングトラップ */
- case HT_BLASTMINE: /* ブラストマイン */
- case HT_CLAYMORETRAP: /* クレイモアートラップ */
- limit_ = skill_get_time (skillid, skilllv);
- range_ = 1;
- break;
-
- case HT_TALKIEBOX: /* トーキーボックス */
- limit_ = skill_get_time (skillid, skilllv);
- range_ = 1;
- target = BCT_ALL;
- break;
-
- case HT_SHOCKWAVE: /* ショックウェーブトラップ */
- limit_ = skill_get_time (skillid, skilllv);
- range_ = 1;
- val1_ = skilllv * 15 + 10;
- break;
-
- case AS_VENOMDUST: /* ベノムダスト */
- limit_ = skill_get_time (skillid, skilllv);
- interval = 1000;
- count = 5;
- break;
-
- case CR_GRANDCROSS: /* グランドクロス */
- count = 29;
- limit_ = 1000;
- interval = 300;
- break;
-
- case SA_VOLCANO: /* ボルケーノ */
- case SA_DELUGE: /* デリュージ */
- case SA_VIOLENTGALE: /* ãƒã‚¤ã‚ªãƒ¬ãƒ³ãƒˆã‚²ã‚¤ãƒ« */
- limit_ = skill_get_time (skillid, skilllv);
- count = skilllv <= 2 ? 25 : (skilllv <= 4 ? 49 : 81);
- target = BCT_ALL;
- break;
-
- case SA_LANDPROTECTOR: /* グランドクロス */
- limit_ = skill_get_time (skillid, skilllv); // changed to get duration from cast_db (moonsoul)
- val1_ = skilllv * 15 + 10;
- aoe_diameter = skilllv + skilllv % 2 + 5;
- target = BCT_ALL;
- count = aoe_diameter * aoe_diameter; // -- this will not function if changed to ^2 (moonsoul)
- break;
-
- case BD_LULLABY: /* å­å®ˆå”„ */
- case BD_ETERNALCHAOS: /* エターナルカオス */
- case BD_ROKISWEIL: /* ロキã®å«ã³ */
- count = 81;
- limit_ = skill_get_time (skillid, skilllv);
- range_ = 5;
- target = BCT_ALL;
- break;
- case BD_RICHMANKIM:
- case BD_DRUMBATTLEFIELD: /* 戦太鼓ã®éŸ¿ã */
- case BD_RINGNIBELUNGEN: /* ニーベルングã®æŒ‡è¼ª */
- case BD_INTOABYSS: /* 深淵ã®ä¸­ã« */
- case BD_SIEGFRIED: /* ä¸æ­»èº«ã®ã‚¸ãƒ¼ã‚¯ãƒ•ãƒªãƒ¼ãƒ‰ */
- count = 81;
- limit_ = skill_get_time (skillid, skilllv);
- range_ = 5;
- target = BCT_PARTY;
- break;
-
- case BA_WHISTLE: /* å£ç¬› */
- count = 49;
- limit_ = skill_get_time (skillid, skilllv);
- range_ = 5;
- target = BCT_NOENEMY;
- if (src->type == BL_PC)
- val1_ =
- (pc_checkskill
- ((struct map_session_data *) src,
- BA_MUSICALLESSON) + 1) >> 1;
- val2_ = ((battle_get_agi (src) / 10) & 0xffff) << 16;
- val2_ |= (battle_get_luk (src) / 10) & 0xffff;
- break;
- case DC_HUMMING: /* ãƒãƒŸãƒ³ã‚° */
- count = 49;
- limit_ = skill_get_time (skillid, skilllv);
- range_ = 5;
- target = BCT_NOENEMY;
- if (src->type == BL_PC)
- val1_ =
- (pc_checkskill
- ((struct map_session_data *) src,
- DC_DANCINGLESSON) + 1) >> 1;
- val2_ = battle_get_dex (src) / 10;
- break;
-
- case BA_DISSONANCE: /* ä¸å”和音 */
- case DC_UGLYDANCE: /* 自分å‹æ‰‹ãªãƒ€ãƒ³ã‚¹ */
- count = 49;
- limit_ = skill_get_time (skillid, skilllv);
- range_ = 5;
- target = BCT_ENEMY;
- break;
-
- case DC_DONTFORGETME: /* ç§ã‚’忘れãªã„ã§â€¦ */
- count = 49;
- limit_ = skill_get_time (skillid, skilllv);
- range_ = 5;
- target = BCT_ENEMY;
- if (src->type == BL_PC)
- val1_ =
- (pc_checkskill
- ((struct map_session_data *) src,
- DC_DANCINGLESSON) + 1) >> 1;
- val2_ = ((battle_get_str (src) / 20) & 0xffff) << 16;
- val2_ |= (battle_get_agi (src) / 10) & 0xffff;
- break;
- case BA_POEMBRAGI: /* ブラギã®è©© */
- count = 49;
- limit_ = skill_get_time (skillid, skilllv);
- range_ = 5;
- target = BCT_NOENEMY;
- if (src->type == BL_PC)
- val1_ =
- pc_checkskill ((struct map_session_data *) src,
- BA_MUSICALLESSON);
- val2_ = ((battle_get_dex (src) / 10) & 0xffff) << 16;
- val2_ |= (battle_get_int (src) / 5) & 0xffff;
- break;
- case BA_APPLEIDUN: /* イドゥンã®æž—檎 */
- count = 49;
- limit_ = skill_get_time (skillid, skilllv);
- range_ = 5;
- target = BCT_NOENEMY;
- if (src->type == BL_PC)
- val1_ =
- ((pc_checkskill
- ((struct map_session_data *) src,
- BA_MUSICALLESSON)) & 0xffff) << 16;
- else
- val1_ = 0;
- val1_ |= (battle_get_vit (src)) & 0xffff;
- val2_ = 0; //回復用タイムカウンタ(6秒毎ã«1増加)
- break;
- case DC_SERVICEFORYOU: /* サービスフォーユー */
- count = 49;
- limit_ = skill_get_time (skillid, skilllv);
- range_ = 5;
- target = BCT_PARTY;
- if (src->type == BL_PC)
- val1_ =
- (pc_checkskill
- ((struct map_session_data *) src,
- DC_DANCINGLESSON) + 1) >> 1;
- val2_ = battle_get_int (src) / 10;
- break;
- case BA_ASSASSINCROSS: /* 夕陽ã®ã‚¢ã‚µã‚·ãƒ³ã‚¯ãƒ­ã‚¹ */
- count = 49;
- limit_ = skill_get_time (skillid, skilllv);
- range_ = 5;
- target = BCT_NOENEMY;
- if (src->type == BL_PC)
- val1_ =
- (pc_checkskill
- ((struct map_session_data *) src,
- BA_MUSICALLESSON) + 1) >> 1;
- val2_ = battle_get_agi (src) / 20;
- break;
- case DC_FORTUNEKISS: /* 幸é‹ã®ã‚­ã‚¹ */
- count = 49;
- limit_ = skill_get_time (skillid, skilllv);
- range_ = 5;
- target = BCT_NOENEMY;
- if (src->type == BL_PC)
- val1_ =
- (pc_checkskill
- ((struct map_session_data *) src,
- DC_DANCINGLESSON) + 1) >> 1;
- val2_ = battle_get_luk (src) / 10;
- break;
- case AM_DEMONSTRATION: /* デモンストレーション */
- limit_ = skill_get_time (skillid, skilllv);
- interval = 1000;
- range_ = 1;
- target = BCT_ENEMY;
- break;
- case WE_CALLPARTNER: /* ã‚ãªãŸã«é€¢ã„ãŸã„ */
- limit_ = skill_get_time (skillid, skilllv);
- range_ = -1;
- break;
-
- case HP_BASILICA: /* ãƒã‚¸ãƒªã‚« */
- limit_ = skill_get_time (skillid, skilllv);
- target = BCT_ALL;
- range_ = 3;
- //Fix to prevent the priest from walking while Basilica is up.
- battle_stopwalking (src, 1);
- skill_status_change_start (src, SC_ANKLE, skilllv, 0, 0, 0, limit_,
- 0);
- break;
- case PA_GOSPEL: /* ゴスペル */
- count = 49;
- target = BCT_PARTY;
- limit_ = skill_get_time (skillid, skilllv);
- break;
- case PF_FOGWALL: /* フォグウォール */
- count = 15;
- limit_ = skill_get_time (skillid, skilllv);
- break;
- case RG_GRAFFITI: /* Graffiti */
- count = 1; // Leave this at 1 [Valaris]
- limit_ = 600000; // Time length [Valaris]
- break;
- };
-
- nullpo_retr (NULL, group =
- skill_initunitgroup (src, count, skillid, skilllv,
- skill_get_unit_id (skillid, flag & 1)));
- group->limit = limit_;
- group->val1 = val1_;
- group->val2 = val2_;
- group->target_flag = target;
- group->interval = interval;
- group->range = range_;
- if (skillid == HT_TALKIEBOX || skillid == RG_GRAFFITI)
- {
- CREATE (group->valstr, char, 80);
- memcpy (group->valstr, talkie_mes, 80);
- }
- for (i = 0; i < count; i++)
- {
- struct skill_unit *unit;
- int ux = x, uy = y, val1 = skilllv, val2 = 0, limit =
- group->limit, alive = 1;
- int range = group->range;
- switch (skillid)
- { /* 設定 */
- case AL_PNEUMA: /* ニューマ */
- {
- static const int dx[9] = { -1, 0, 1, -1, 0, 1, -1, 0, 1 };
- static const int dy[9] = { -1, -1, -1, 0, 0, 0, 1, 1, 1 };
- ux += dx[i];
- uy += dy[i];
- }
- break;
- case MG_FIREWALL: /* ファイヤーウォール */
- {
- if (dir & 1)
- { /* æ–œã‚é…ç½® */
- static const int dx[][5] = {
- {1, 1, 0, 0, -1}, {-1, -1, 0, 0, 1},
- }, dy[][5] =
- {
- {
- 1, 0, 0, -1, -1},
- {
- 1, 0, 0, -1, -1},};
- ux += dx[(dir >> 1) & 1][i];
- uy += dy[(dir >> 1) & 1][i];
- }
- else
- { /* 上下é…ç½® */
- if (dir % 4 == 0) /* 上下 */
- ux += i - 1;
- else /* å·¦å³ */
- uy += i - 1;
- }
- val2 = group->val2;
- }
- break;
-
- case PR_SANCTUARY: /* サンクãƒãƒ¥ã‚¢ãƒª */
- {
- static const int dx[] = {
- -1, 0, 1, -2, -1, 0, 1, 2, -2, -1, 0, 1, 2, -2, -1, 0, 1,
- 2, -1, 0, 1
- };
- static const int dy[] = {
- -2, -2, -2, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 1, 1, 1, 1,
- 1, 2, 2, 2,
- };
- ux += dx[i];
- uy += dy[i];
- }
- break;
-
- case PR_MAGNUS: /* マグヌスエクソシズム */
- {
- static const int dx[] =
- { -1, 0, 1, -1, 0, 1, -3, -2, -1, 0, 1, 2, 3,
- -3, -2, -1, 0, 1, 2, 3, -3, -2, -1, 0, 1, 2, 3, -1, 0, 1,
- -1, 0, 1,
- };
- static const int dy[] = {
- -3, -3, -3, -2, -2, -2, -1, -1, -1, -1, -1, -1, -1,
- 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 3, 3, 3
- };
- ux += dx[i];
- uy += dy[i];
- }
- break;
-
- case WZ_SIGHTRASHER:
- {
- static const int dx[] = {
- -5, 0, 5, -4, 0, 4, -3, 0, 3, -2, 0, 2, -1, 0, 1, -5, -4,
- -3, -2, -1, 0, 1, 2, 3, 4, 5, -1, 0, 1, -2, 0, 2, -3,
- 0, 3, -4, 0, 4, -5, 0, 5
- };
- static const int dy[] = {
- -5, -5, -5, -4, -4, -4, -3, -3, -3, -2, -2, -2, -1, -1,
- -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 2, 2, 2,
- 3, 3, 3, 4, 4, 4, 5, 5, 5
- };
- ux += dx[i];
- uy += dy[i];
- }
- break;
-
- case WZ_ICEWALL: /* アイスウォール */
- {
- if (skilllv <= 1)
- val1 = 500;
- else
- val1 = 200 + 200 * skilllv;
- if (src->x == x && src->y == y)
- dir = 2;
- else
- dir = map_calc_dir (src, x, y);
- ux += (2 - i) * diry[dir];
- uy += (i - 2) * dirx[dir];
- }
- break;
-
- case WZ_QUAGMIRE: /* クァグマイア */
- ux += (i % 5 - 2);
- uy += (i / 5 - 2);
- if (i == 12)
- range = 2;
- else
- range = -1;
-
- break;
-
- case AS_VENOMDUST: /* ベノムダスト */
- {
- static const int dx[] = { -1, 0, 0, 0, 1 };
- static const int dy[] = { 0, -1, 0, 1, 0 };
- ux += dx[i];
- uy += dy[i];
- }
- break;
-
- case CR_GRANDCROSS: /* グランドクロス */
- {
- static const int dx[] = {
- 0, 0, -1, 0, 1, -2, -1, 0, 1, 2, -4, -3, -2, -1, 0, 1, 2,
- 3, 4, -2, -1, 0, 1, 2, -1, 0, 1, 0, 0,
- };
- static const int dy[] = {
- -4, -3, -2, -2, -2, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 3, 4,
- };
- ux += dx[i];
- uy += dy[i];
- }
- break;
- case SA_VOLCANO: /* ボルケーノ */
- case SA_DELUGE: /* デリュージ */
- case SA_VIOLENTGALE: /* ãƒã‚¤ã‚ªãƒ¬ãƒ³ãƒˆã‚²ã‚¤ãƒ« */
- {
- int u_range = 0, central = 0;
- if (skilllv <= 2)
- {
- u_range = 2;
- central = 12;
- }
- else if (skilllv <= 4)
- {
- u_range = 3;
- central = 24;
- }
- else if (skilllv >= 5)
- {
- u_range = 4;
- central = 40;
- }
- ux += (i % (u_range * 2 + 1) - u_range);
- uy += (i / (u_range * 2 + 1) - u_range);
-
- if (i == central)
- range = u_range; //中央ã®ãƒ¦ãƒ‹ãƒƒãƒˆã®åŠ¹æžœç¯„囲ã¯å…¨ç¯„囲
- else
- range = -1; //中央以外ã®ãƒ¦ãƒ‹ãƒƒãƒˆã¯é£¾ã‚Š
- }
- break;
- case SA_LANDPROTECTOR: /* ランドプロテクター */
- {
- int u_range = 0;
-
- if (skilllv <= 2)
- u_range = 3;
- else if (skilllv <= 4)
- u_range = 4;
- else if (skilllv >= 5)
- u_range = 5;
-
- ux += (i % (u_range * 2 + 1) - u_range);
- uy += (i / (u_range * 2 + 1) - u_range);
-
- range = 0;
- }
- break;
-
- /* ダンスãªã© */
- case BD_LULLABY: /* å­å®ˆæ­Œ */
- case BD_RICHMANKIM: /* ニヨルドã®å®´ */
- case BD_ETERNALCHAOS: /* æ°¸é ã®æ··æ²Œ */
- case BD_DRUMBATTLEFIELD: /* 戦太鼓ã®éŸ¿ã */
- case BD_RINGNIBELUNGEN: /* ニーベルングã®æŒ‡è¼ª */
- case BD_ROKISWEIL: /* ロキã®å«ã³ */
- case BD_INTOABYSS: /* 深淵ã®ä¸­ã« */
- case BD_SIEGFRIED: /* ä¸æ­»èº«ã®ã‚¸ãƒ¼ã‚¯ãƒ•ãƒªãƒ¼ãƒ‰ */
- ux += (i % 9 - 4);
- uy += (i / 9 - 4);
- if (i == 40)
- range = 4; /* 中心ã®å ´åˆã¯ç¯„囲を4ã«ã‚ªãƒ¼ãƒãƒ¼ãƒ©ã‚¤ãƒ‰ */
- else
- range = -1; /* 中心ã˜ã‚ƒãªã„å ´åˆã¯ç¯„囲を-1ã«ã‚ªãƒ¼ãƒãƒ¼ãƒ©ã‚¤ãƒ‰ */
- break;
- case BA_DISSONANCE: /* ä¸å”和音 */
- case BA_WHISTLE: /* å£ç¬› */
- case BA_ASSASSINCROSS: /* 夕陽ã®ã‚¢ã‚µã‚·ãƒ³ã‚¯ãƒ­ã‚¹ */
- case BA_POEMBRAGI: /* ブラギã®è©© */
- case BA_APPLEIDUN: /* イドゥンã®æž—檎 */
- case DC_UGLYDANCE: /* 自分å‹æ‰‹ãªãƒ€ãƒ³ã‚¹ */
- case DC_HUMMING: /* ãƒãƒŸãƒ³ã‚° */
- case DC_DONTFORGETME: /* ç§ã‚’忘れãªã„ã§â€¦ */
- case DC_FORTUNEKISS: /* 幸é‹ã®ã‚­ã‚¹ */
- case DC_SERVICEFORYOU: /* サービスフォーユー */
- ux += (i % 7 - 3);
- uy += (i / 7 - 3);
- if (i == 40)
- range = 4; /* 中心ã®å ´åˆã¯ç¯„囲を4ã«ã‚ªãƒ¼ãƒãƒ¼ãƒ©ã‚¤ãƒ‰ */
- else
- range = -1; /* 中心ã˜ã‚ƒãªã„å ´åˆã¯ç¯„囲を-1ã«ã‚ªãƒ¼ãƒãƒ¼ãƒ©ã‚¤ãƒ‰ */
- break;
- case PA_GOSPEL: /* ゴスペル */
- ux += (i % 7 - 3);
- uy += (i / 7 - 3);
- break;
- case PF_FOGWALL: /* フォグウォール */
- ux += (i % 5 - 2);
- uy += (i / 5 - 1);
- break;
- case RG_GRAFFITI: /* Graffiti [Valaris] */
- ux += (i % 5 - 2);
- uy += (i / 5 - 2);
- break;
- }
- //直上スキルã®å ´åˆè¨­ç½®åº§æ¨™ä¸Šã«ãƒ©ãƒ³ãƒ‰ãƒ—ロテクターãŒãªã„ã‹ãƒã‚§ãƒƒã‚¯
- if (range <= 0)
- map_foreachinarea (skill_landprotector, src->m, ux, uy, ux, uy,
- BL_SKILL, skillid, &alive);
-
- if (skillid == WZ_ICEWALL && alive)
- {
- val2 = map_getcell (src->m, ux, uy);
- if (val2 == 5 || val2 == 1)
- alive = 0;
- else
- {
- map_setcell (src->m, ux, uy, 5);
- clif_changemapcell (src->m, ux, uy, 5, 0);
- }
- }
-
- if (alive)
- {
- nullpo_retr (NULL, unit = skill_initunit (group, i, ux, uy));
- unit->val1 = val1;
- unit->val2 = val2;
- unit->limit = limit;
- unit->range = range;
- }
- }
- return group;
-}
-
-/*==========================================
- * スキルユニットã®ç™ºå‹•ã‚¤ãƒ™ãƒ³ãƒˆ
- *------------------------------------------
- */
-static
-int skill_unit_onplace (struct skill_unit *src, struct block_list *bl,
- unsigned int tick)
-{
- struct skill_unit_group *sg;
- struct block_list *ss;
- struct skill_unit_group_tickset *ts;
- struct map_session_data *srcsd = NULL;
- int diff, goflag, splash_count = 0;
-
- nullpo_retr (0, src);
- nullpo_retr (0, bl);
-
- if (bl->prev == NULL || !src->alive
- || (bl->type == BL_PC && pc_isdead ((struct map_session_data *) bl)))
- return 0;
-
- nullpo_retr (0, sg = src->group);
- nullpo_retr (0, ss = map_id2bl (sg->src_id));
-
- if (ss->type == BL_PC)
- nullpo_retr (0, srcsd = (struct map_session_data *) ss);
- if (srcsd && srcsd->chatID)
- return 0;
-
- if (bl->type != BL_PC && bl->type != BL_MOB)
- return 0;
- nullpo_retr (0, ts = skill_unitgrouptickset_search (bl, sg->group_id));
- diff = DIFF_TICK (tick, ts->tick);
- goflag = (diff > sg->interval || diff < 0);
- if (sg->skill_id == CR_GRANDCROSS && !battle_config.gx_allhit) // é‡ãªã£ã¦ã„ãŸã‚‰3HITã—ãªã„
- goflag = (diff > sg->interval * map_count_oncell (bl->m, bl->x, bl->y)
- || diff < 0);
-
- //対象ãŒLP上ã«å±…ã‚‹å ´åˆã¯ç„¡åŠ¹
- map_foreachinarea (skill_landprotector, bl->m, bl->x, bl->y, bl->x, bl->y,
- BL_SKILL, 0, &goflag);
-
- if (!goflag)
- return 0;
- ts->tick = tick;
- ts->group_id = sg->group_id;
-
- switch (sg->unit_id)
- {
- case 0x83: /* サンクãƒãƒ¥ã‚¢ãƒª */
- {
- int race = battle_get_race (bl);
- int damage_flag =
- (battle_check_undead (race, battle_get_elem_type (bl))
- || race == 6) ? 1 : 0;
-
- if (battle_get_hp (bl) >= battle_get_max_hp (bl) && !damage_flag)
- break;
-
- if ((sg->val1--) <= 0)
- {
- skill_delunitgroup (sg);
- return 0;
- }
- if (!damage_flag)
- {
- int heal = sg->val2;
- if (bl->type == BL_PC
- && ((struct map_session_data *) bl)->
- special_state.no_magic_damage)
- heal = 0; /* 黄金蟲カード(ヒールé‡ï¼ï¼‰ */
- clif_skill_nodamage (&src->bl, bl, AL_HEAL, heal, 1);
- battle_heal (NULL, bl, heal, 0, 0);
- }
- else
- skill_attack (BF_MAGIC, ss, &src->bl, bl, sg->skill_id,
- sg->skill_lv, tick, 0);
- }
- break;
-
- case 0x84: /* マグヌスエクソシズム */
- {
- int race = battle_get_race (bl);
- int damage_flag =
- (battle_check_undead (race, battle_get_elem_type (bl))
- || race == 6) ? 1 : 0;
-
- if (!damage_flag)
- return 0;
- skill_attack (BF_MAGIC, ss, &src->bl, bl, sg->skill_id,
- sg->skill_lv, tick, 0);
- }
- break;
-
- case 0x85: /* ニューマ */
- {
- struct skill_unit *unit2;
- struct status_change *sc_data = battle_get_sc_data (bl);
- int type = SC_PNEUMA;
- if (sc_data && sc_data[type].timer == -1)
- skill_status_change_start (bl, type, sg->skill_lv, (int) src,
- 0, 0, 0, 0);
- else if ((unit2 = (struct skill_unit *) sc_data[type].val2)
- && unit2 != src)
- {
- if (DIFF_TICK (sg->tick, unit2->group->tick) > 0)
- skill_status_change_start (bl, type, sg->skill_lv,
- (int) src, 0, 0, 0, 0);
- ts->tick -= sg->interval;
- }
- }
- break;
- case 0x7e: /* セイフティウォール */
- {
- struct skill_unit *unit2;
- struct status_change *sc_data = battle_get_sc_data (bl);
- int type = SC_SAFETYWALL;
- if (sc_data && sc_data[type].timer == -1)
- skill_status_change_start (bl, type, sg->skill_lv, (int) src,
- 0, 0, 0, 0);
- else if ((unit2 = (struct skill_unit *) sc_data[type].val2)
- && unit2 != src)
- {
- if (sg->val1 < unit2->group->val1)
- skill_status_change_start (bl, type, sg->skill_lv,
- (int) src, 0, 0, 0, 0);
- ts->tick -= sg->interval;
- }
- }
- break;
-
- case 0x86: /* ロードオブヴァーミリオン(&ストームガスト &グランドクロス) */
- skill_attack (BF_MAGIC, ss, &src->bl, bl, sg->skill_id,
- sg->skill_lv, tick, 0);
- break;
-
- case 0x7f: /* ファイヤーウォール */
- if ((src->val2--) > 0)
- skill_attack (BF_MAGIC, ss, &src->bl, bl,
- sg->skill_id, sg->skill_lv, tick, 0);
- if (src->val2 <= 0)
- skill_delunit (src);
- break;
-
- case 0x87: /* ファイアーピラー(発動å‰) */
- skill_delunit (src);
- skill_unitsetting (ss, sg->skill_id, sg->skill_lv, src->bl.x,
- src->bl.y, 1);
- break;
-
- case 0x88: /* ファイアーピラー(発動後) */
- if (DIFF_TICK (tick, sg->tick) < 150)
- skill_attack (BF_MAGIC, ss, &src->bl, bl, sg->skill_id,
- sg->skill_lv, tick, 0);
- break;
-
- case 0x90: /* スキッドトラップ */
- {
- int i, c = skill_get_blewcount (sg->skill_id, sg->skill_lv);
- if (map[bl->m].flag.gvg)
- c = 0;
- for (i = 0; i < c; i++)
- skill_blown (&src->bl, bl, 1 | 0x30000);
- sg->unit_id = 0x8c;
- clif_changelook (&src->bl, LOOK_BASE, sg->unit_id);
- sg->limit = DIFF_TICK (tick, sg->tick) + 1500;
- }
- break;
-
- case 0x93: /* ランドマイン */
- skill_attack (BF_MISC, ss, &src->bl, bl, sg->skill_id,
- sg->skill_lv, tick, 0);
- sg->unit_id = 0x8c;
- clif_changelook (&src->bl, LOOK_BASE, 0x88);
- sg->limit = DIFF_TICK (tick, sg->tick) + 1500;
- break;
-
- case 0x8f: /* ブラストマイン */
- case 0x94: /* ショックウェーブトラップ */
- case 0x95: /* サンドマン */
- case 0x96: /* フラッシャー */
- case 0x97: /* フリージングトラップ */
- case 0x98: /* クレイモアートラップ */
- map_foreachinarea (skill_count_target, src->bl.m,
- src->bl.x - src->range, src->bl.y - src->range,
- src->bl.x + src->range, src->bl.y + src->range,
- 0, &src->bl, &splash_count);
- map_foreachinarea (skill_trap_splash, src->bl.m,
- src->bl.x - src->range, src->bl.y - src->range,
- src->bl.x + src->range, src->bl.y + src->range,
- 0, &src->bl, tick, splash_count);
- sg->unit_id = 0x8c;
- clif_changelook (&src->bl, LOOK_BASE, sg->unit_id);
- sg->limit = DIFF_TICK (tick, sg->tick) + 1500;
- break;
-
- case 0x91: /* アンクルスãƒã‚¢ */
- {
- struct status_change *sc_data = battle_get_sc_data (bl);
- if (sg->val2 == 0 && sc_data && sc_data[SC_ANKLE].timer == -1)
- {
- int moveblock = (bl->x / BLOCK_SIZE != src->bl.x / BLOCK_SIZE
- || bl->y / BLOCK_SIZE !=
- src->bl.y / BLOCK_SIZE);
- int sec = skill_get_time2 (sg->skill_id,
- sg->skill_lv) -
- (double) battle_get_agi (bl) * 0.1;
- if (battle_get_mode (bl) & 0x20)
- sec = sec / 5;
- battle_stopwalking (bl, 1);
- skill_status_change_start (bl, SC_ANKLE, sg->skill_lv, 0, 0,
- 0, sec, 0);
-
- if (moveblock)
- map_delblock (bl);
- bl->x = src->bl.x;
- bl->y = src->bl.y;
- if (moveblock)
- map_addblock (bl);
- if (bl->type == BL_MOB)
- clif_fixmobpos ((struct mob_data *) bl);
- else
- clif_fixpos (bl);
- clif_01ac (&src->bl);
- sg->limit = DIFF_TICK (tick, sg->tick) + sec;
- sg->val2 = bl->id;
- }
- }
- break;
-
- case 0x80: /* ワープãƒãƒ¼ã‚¿ãƒ«(発動後) */
- if (bl->type == BL_PC)
- {
- struct map_session_data *sd = (struct map_session_data *) bl;
- if (sd && src->bl.m == bl->m && src->bl.x == bl->x
- && src->bl.y == bl->y && src->bl.x == sd->to_x
- && src->bl.y == sd->to_y)
- {
- if (battle_config.chat_warpportal || !sd->chatID)
- {
- if ((sg->val1--) > 0)
- {
- pc_setpos (sd, sg->valstr, sg->val2 >> 16,
- sg->val2 & 0xffff, 3);
- if (sg->src_id == bl->id
- || (strcmp (map[src->bl.m].name, sg->valstr)
- == 0 && src->bl.x == (sg->val2 >> 16)
- && src->bl.y == (sg->val2 & 0xffff)))
- skill_delunitgroup (sg);
- }
- else
- skill_delunitgroup (sg);
- }
- }
- }
- else if (bl->type == BL_MOB && battle_config.mob_warpportal)
- {
- int m = map_mapname2mapid (sg->valstr);
- struct mob_data *md;
- md = (struct mob_data *) bl;
- mob_warp ((struct mob_data *) bl, m, sg->val2 >> 16,
- sg->val2 & 0xffff, 3);
- }
- break;
-
- case 0x8e: /* クァグマイア */
- {
- int type = SkillStatusChangeTable[sg->skill_id];
- if (bl->type == BL_PC
- && ((struct map_session_data *) bl)->
- special_state.no_magic_damage)
- break;
- if (battle_get_sc_data (bl)[type].timer == -1)
- skill_status_change_start (bl, type, sg->skill_lv, (int) src,
- 0, 0,
- skill_get_time2 (sg->skill_id,
- sg->skill_lv), 0);
- }
- break;
- case 0x92: /* ベノムダスト */
- {
- struct status_change *sc_data = battle_get_sc_data (bl);
- int type = SkillStatusChangeTable[sg->skill_id];
- if (sc_data && sc_data[type].timer == -1)
- skill_status_change_start (bl, type, sg->skill_lv, (int) src,
- 0, 0,
- skill_get_time2 (sg->skill_id,
- sg->skill_lv), 0);
- }
- break;
- case 0x9a: /* ボルケーノ */
- case 0x9b: /* デリュージ */
- case 0x9c: /* ãƒã‚¤ã‚ªãƒ¬ãƒ³ãƒˆã‚²ã‚¤ãƒ« */
- {
- struct skill_unit *unit2;
- struct status_change *sc_data = battle_get_sc_data (bl);
- int type = SkillStatusChangeTable[sg->skill_id];
- if (sc_data && sc_data[type].timer == -1)
- skill_status_change_start (bl, type, sg->skill_lv, (int) src,
- 0, 0,
- skill_get_time2 (sg->skill_id,
- sg->skill_lv), 0);
- else if ((unit2 = (struct skill_unit *) sc_data[type].val2)
- && unit2 != src)
- {
- if (DIFF_TICK (sg->tick, unit2->group->tick) > 0)
- skill_status_change_start (bl, type, sg->skill_lv,
- (int) src, 0, 0,
- skill_get_time2 (sg->skill_id,
- sg->skill_lv),
- 0);
- ts->tick -= sg->interval;
- }
- } break;
-
- case 0x9e: /* å­å®ˆå”„ */
- case 0x9f: /* ニヨルドã®å®´ */
- case 0xa0: /* æ°¸é ã®æ··æ²Œ */
- case 0xa1: /* 戦太鼓ã®éŸ¿ã */
- case 0xa2: /* ニーベルングã®æŒ‡è¼ª */
- case 0xa3: /* ロキã®å«ã³ */
- case 0xa4: /* 深淵ã®ä¸­ã« */
- case 0xa5: /* ä¸æ­»èº«ã®ã‚¸ãƒ¼ã‚¯ãƒ•ãƒªãƒ¼ãƒ‰ */
- case 0xa6: /* ä¸å”和音 */
- case 0xa7: /* å£ç¬› */
- case 0xa8: /* 夕陽ã®ã‚¢ã‚µã‚·ãƒ³ã‚¯ãƒ­ã‚¹ */
- case 0xa9: /* ブラギã®è©© */
- case 0xab: /* 自分å‹æ‰‹ãªãƒ€ãƒ³ã‚¹ */
- case 0xac: /* ãƒãƒŸãƒ³ã‚° */
- case 0xad: /* ç§ã‚’忘れãªã„ã§â€¦ */
- case 0xae: /* 幸é‹ã®ã‚­ã‚¹ */
- case 0xaf: /* サービスフォーユー */
- case 0xb4:
- {
- struct skill_unit *unit2;
- struct status_change *sc_data = battle_get_sc_data (bl);
- int type = SkillStatusChangeTable[sg->skill_id];
- if (sg->src_id == bl->id)
- break;
- if (sc_data && sc_data[type].timer == -1)
- skill_status_change_start (bl, type, sg->skill_lv, sg->val1,
- sg->val2, (int) src,
- skill_get_time2 (sg->skill_id,
- sg->skill_lv), 0);
- else if ((unit2 = (struct skill_unit *) sc_data[type].val4)
- && unit2 != src)
- {
- if (unit2->group
- && DIFF_TICK (sg->tick, unit2->group->tick) > 0)
- skill_status_change_start (bl, type, sg->skill_lv,
- sg->val1, sg->val2, (int) src,
- skill_get_time2 (sg->skill_id,
- sg->skill_lv),
- 0);
- ts->tick -= sg->interval;
- }
- } break;
-
- case 0xaa: /* イドゥンã®æž—檎 */
- {
- struct skill_unit *unit2;
- struct status_change *sc_data = battle_get_sc_data (bl);
- int type = SkillStatusChangeTable[sg->skill_id];
- if (sg->src_id == bl->id)
- break;
- if (sc_data && sc_data[type].timer == -1)
- skill_status_change_start (bl, type, sg->skill_lv,
- (sg->val1) >> 16,
- (sg->val1) & 0xffff, (int) src,
- skill_get_time2 (sg->skill_id,
- sg->skill_lv), 0);
- else if ((unit2 = (struct skill_unit *) sc_data[type].val4)
- && unit2 != src)
- {
- if (DIFF_TICK (sg->tick, unit2->group->tick) > 0)
- skill_status_change_start (bl, type, sg->skill_lv,
- (sg->val1) >> 16,
- (sg->val1) & 0xffff, (int) src,
- skill_get_time2 (sg->skill_id,
- sg->skill_lv),
- 0);
- ts->tick -= sg->interval;
- }
- } break;
-
- case 0xb1: /* デモンストレーション */
- skill_attack (BF_WEAPON, ss, &src->bl, bl, sg->skill_id,
- sg->skill_lv, tick, 0);
- if (bl->type == BL_PC && MRAND (100) < sg->skill_lv
- && battle_config.equipment_breaking)
- pc_breakweapon ((struct map_session_data *) bl);
- break;
- case 0x99: /* トーキーボックス */
- if (sg->src_id == bl->id) //自分ãŒè¸ã‚“ã§ã‚‚発動ã—ãªã„
- break;
- if (sg->val2 == 0)
- {
- clif_talkiebox (&src->bl, sg->valstr);
- sg->unit_id = 0x8c;
- clif_changelook (&src->bl, LOOK_BASE, sg->unit_id);
- sg->limit = DIFF_TICK (tick, sg->tick) + 5000;
- sg->val2 = -1; //è¸ã‚“ã 
- }
- break;
- case 0xb2: /* ã‚ãªãŸã‚’_会ã„ãŸã„ã§ã™ */
- case 0xb3: /* ゴスペル */
- case 0xb6: /* フォグウォール */
- //ã¨ã‚Šã‚ãˆãšä½•ã‚‚ã—ãªã„
- break;
-
- case 0xb7: /* スパイダーウェッブ */
- if (sg->val2 == 0)
- {
- int moveblock = (bl->x / BLOCK_SIZE != src->bl.x / BLOCK_SIZE
- || bl->y / BLOCK_SIZE !=
- src->bl.y / BLOCK_SIZE);
- skill_additional_effect (ss, bl, sg->skill_id, sg->skill_lv,
- BF_MISC, tick);
- if (moveblock)
- map_delblock (bl);
- bl->x = (&src->bl)->x;
- bl->y = (&src->bl)->y;
- if (moveblock)
- map_addblock (bl);
- if (bl->type == BL_MOB)
- clif_fixmobpos ((struct mob_data *) bl);
- else
- clif_fixpos (bl);
- clif_01ac (&src->bl);
- sg->limit =
- DIFF_TICK (tick,
- sg->tick) + skill_get_time2 (sg->skill_id,
- sg->skill_lv);
- sg->val2 = bl->id;
- }
- break;
-
-/* default:
- if(battle_config.error_log)
- printf("skill_unit_onplace: Unknown skill unit id=%d block=%d\n",sg->unit_id,bl->id);
- break;*/
- }
- if (bl->type == BL_MOB && ss != bl) /* スキル使用æ¡ä»¶ã®MOBスキル */
- {
- if (battle_config.mob_changetarget_byskill == 1)
- {
- int target = ((struct mob_data *) bl)->target_id;
- if (ss->type == BL_PC)
- ((struct mob_data *) bl)->target_id = ss->id;
- mobskill_use ((struct mob_data *) bl, tick,
- MSC_SKILLUSED | (sg->skill_id << 16));
- ((struct mob_data *) bl)->target_id = target;
- }
- else
- mobskill_use ((struct mob_data *) bl, tick,
- MSC_SKILLUSED | (sg->skill_id << 16));
- }
-
- return 0;
-}
-
-/*==========================================
- * スキルユニットã‹ã‚‰é›¢è„±ã™ã‚‹(ã‚‚ã—ãã¯ã—ã¦ã„ã‚‹)å ´åˆ
- *------------------------------------------
- */
-static
-int skill_unit_onout (struct skill_unit *src, struct block_list *bl,
- unsigned int tick)
-{
- struct skill_unit_group *sg;
-
- nullpo_retr (0, src);
- nullpo_retr (0, bl);
- nullpo_retr (0, sg = src->group);
-
- if (bl->prev == NULL || !src->alive)
- return 0;
-
- if (bl->type != BL_PC && bl->type != BL_MOB)
- return 0;
-
- switch (sg->unit_id)
- {
- case 0x7e: /* セイフティウォール */
- case 0x85: /* ニューマ */
- case 0x8e: /* クァグマイア */
- {
- struct status_change *sc_data = battle_get_sc_data (bl);
- int type =
- (sg->unit_id == 0x85) ? SC_PNEUMA :
- ((sg->unit_id == 0x7e) ? SC_SAFETYWALL : SC_QUAGMIRE);
- if ((type != SC_QUAGMIRE || bl->type != BL_MOB) &&
- sc_data && sc_data[type].timer != -1
- && ((struct skill_unit *) sc_data[type].val2) == src)
- {
- skill_status_change_end (bl, type, -1);
- }
- } break;
-
- case 0x91: /* アンクルスãƒã‚¢ */
- {
- struct block_list *target = map_id2bl (sg->val2);
- if (target && target == bl)
- {
- skill_status_change_end (bl, SC_ANKLE, -1);
- sg->limit = DIFF_TICK (tick, sg->tick) + 1000;
- }
- }
- break;
- case 0xb5:
- case 0xb8:
- {
- struct block_list *target = map_id2bl (sg->val2);
- if (target == bl)
- skill_status_change_end (bl, SC_SPIDERWEB, -1);
- sg->limit = DIFF_TICK (tick, sg->tick) + 1000;
- }
- break;
- case 0xb6:
- {
- struct block_list *target = map_id2bl (sg->val2);
- if (target == bl)
- skill_status_change_end (bl, SC_FOGWALL, -1);
- sg->limit = DIFF_TICK (tick, sg->tick) + 1000;
- }
- break;
- case 0x9a: /* ボルケーノ */
- case 0x9b: /* デリュージ */
- case 0x9c: /* ãƒã‚¤ã‚ªãƒ¬ãƒ³ãƒˆã‚²ã‚¤ãƒ« */
- {
- struct status_change *sc_data = battle_get_sc_data (bl);
- struct skill_unit *su;
- int type = SkillStatusChangeTable[sg->skill_id];
- if (sc_data && sc_data[type].timer != -1
- && (su = ((struct skill_unit *) sc_data[type].val2))
- && su == src)
- {
- skill_status_change_end (bl, type, -1);
- }
- }
- break;
-
- case 0x9e: /* å­å®ˆå”„ */
- case 0x9f: /* ニヨルドã®å®´ */
- case 0xa0: /* æ°¸é ã®æ··æ²Œ */
- case 0xa1: /* 戦太鼓ã®éŸ¿ã */
- case 0xa2: /* ニーベルングã®æŒ‡è¼ª */
- case 0xa3: /* ロキã®å«ã³ */
- case 0xa4: /* 深淵ã®ä¸­ã« */
- case 0xa5: /* ä¸æ­»èº«ã®ã‚¸ãƒ¼ã‚¯ãƒ•ãƒªãƒ¼ãƒ‰ */
- case 0xa6: /* ä¸å”和音 */
- case 0xa7: /* å£ç¬› */
- case 0xa8: /* 夕陽ã®ã‚¢ã‚µã‚·ãƒ³ã‚¯ãƒ­ã‚¹ */
- case 0xa9: /* ブラギã®è©© */
- case 0xaa: /* イドゥンã®æž—檎 */
- case 0xab: /* 自分å‹æ‰‹ãªãƒ€ãƒ³ã‚¹ */
- case 0xac: /* ãƒãƒŸãƒ³ã‚° */
- case 0xad: /* ç§ã‚’忘れãªã„ã§â€¦ */
- case 0xae: /* 幸é‹ã®ã‚­ã‚¹ */
- case 0xaf: /* サービスフォーユー */
- case 0xb4:
- {
- struct status_change *sc_data = battle_get_sc_data (bl);
- struct skill_unit *su;
- int type = SkillStatusChangeTable[sg->skill_id];
- if (sc_data && sc_data[type].timer != -1
- && (su = ((struct skill_unit *) sc_data[type].val4))
- && su == src)
- {
- skill_status_change_end (bl, type, -1);
- }
- }
- break;
- case 0xb7: /* スパイダーウェッブ */
- {
- struct block_list *target = map_id2bl (sg->val2);
- if (target && target == bl)
- skill_status_change_end (bl, SC_SPIDERWEB, -1);
- sg->limit = DIFF_TICK (tick, sg->tick) + 1000;
- }
- break;
-
-/* default:
- if(battle_config.error_log)
- printf("skill_unit_onout: Unknown skill unit id=%d block=%d\n",sg->unit_id,bl->id);
- break;*/
- }
- skill_unitgrouptickset_delete (bl, sg->group_id);
- return 0;
-}
-
-/*==========================================
- * スキルユニットã®å‰Šé™¤ã‚¤ãƒ™ãƒ³ãƒˆ
- *------------------------------------------
- */
-static
-int skill_unit_ondelete (struct skill_unit *src, struct block_list *bl,
- unsigned int tick)
-{
- struct skill_unit_group *sg;
-
- nullpo_retr (0, src);
- nullpo_retr (0, bl);
- nullpo_retr (0, sg = src->group);
-
- if (bl->prev == NULL || !src->alive)
- return 0;
-
- if (bl->type != BL_PC && bl->type != BL_MOB)
- return 0;
-
- switch (sg->unit_id)
- {
- case 0x85: /* ニューマ */
- case 0x7e: /* セイフティウォール */
- case 0x8e: /* クァグマイヤ */
- case 0x9a: /* ボルケーノ */
- case 0x9b: /* デリュージ */
- case 0x9c: /* ãƒã‚¤ã‚ªãƒ¬ãƒ³ãƒˆã‚²ã‚¤ãƒ« */
- case 0x9e: /* å­å®ˆå”„ */
- case 0x9f: /* ニヨルドã®å®´ */
- case 0xa0: /* æ°¸é ã®æ··æ²Œ */
- case 0xa1: /* 戦太鼓ã®éŸ¿ã */
- case 0xa2: /* ニーベルングã®æŒ‡è¼ª */
- case 0xa3: /* ロキã®å«ã³ */
- case 0xa4: /* 深淵ã®ä¸­ã« */
- case 0xa5: /* ä¸æ­»èº«ã®ã‚¸ãƒ¼ã‚¯ãƒ•ãƒªãƒ¼ãƒ‰ */
- case 0xa6: /* ä¸å”和音 */
- case 0xa7: /* å£ç¬› */
- case 0xa8: /* 夕陽ã®ã‚¢ã‚µã‚·ãƒ³ã‚¯ãƒ­ã‚¹ */
- case 0xa9: /* ブラギã®è©© */
- case 0xaa: /* イドゥンã®æž—檎 */
- case 0xab: /* 自分å‹æ‰‹ãªãƒ€ãƒ³ã‚¹ */
- case 0xac: /* ãƒãƒŸãƒ³ã‚° */
- case 0xad: /* ç§ã‚’忘れãªã„ã§â€¦ */
- case 0xae: /* 幸é‹ã®ã‚­ã‚¹ */
- case 0xaf: /* サービスフォーユー */
- case 0xb4:
- return skill_unit_onout (src, bl, tick);
-
-/* default:
- if(battle_config.error_log)
- printf("skill_unit_ondelete: Unknown skill unit id=%d block=%d\n",sg->unit_id,bl->id);
- break;*/
- }
- skill_unitgrouptickset_delete (bl, sg->group_id);
- return 0;
-}
-
-/*==========================================
- * スキルユニットã®é™ç•Œã‚¤ãƒ™ãƒ³ãƒˆ
- *------------------------------------------
- */
-static
-int skill_unit_onlimit (struct skill_unit *src, unsigned int tick)
-{
- struct skill_unit_group *sg;
-
- nullpo_retr (0, src);
- nullpo_retr (0, sg = src->group);
-
- switch (sg->unit_id)
- {
- case 0x81: /* ワープãƒãƒ¼ã‚¿ãƒ«(発動å‰) */
- {
- struct skill_unit_group *group =
- skill_unitsetting (map_id2bl (sg->src_id), sg->skill_id,
- sg->skill_lv,
- src->bl.x, src->bl.y, 1);
- if (group == NULL)
- return 0;
- CREATE (group->valstr, char, 24);
- memcpy (group->valstr, sg->valstr, 24);
- group->val2 = sg->val2;
- }
- break;
-
- case 0x8d: /* アイスウォール */
- map_setcell (src->bl.m, src->bl.x, src->bl.y, src->val2);
- clif_changemapcell (src->bl.m, src->bl.x, src->bl.y, src->val2,
- 1);
- break;
- case 0xb2: /* ã‚ãªãŸã«ä¼šã„ãŸã„ */
- {
- struct map_session_data *sd = NULL;
- struct map_session_data *p_sd = NULL;
- if ((sd =
- (struct map_session_data *) (map_id2bl (sg->src_id))) ==
- NULL)
- return 0;
- if ((p_sd = pc_get_partner (sd)) == NULL)
- return 0;
-
- pc_setpos (p_sd, map[src->bl.m].name, src->bl.x, src->bl.y, 3);
- }
- break;
- }
- return 0;
-}
-
-/*==========================================
- * スキルユニットã®ãƒ€ãƒ¡ãƒ¼ã‚¸ã‚¤ãƒ™ãƒ³ãƒˆ
- *------------------------------------------
- */
-int skill_unit_ondamaged (struct skill_unit *src, struct block_list *bl,
- int damage, unsigned int tick)
-{
- struct skill_unit_group *sg;
-
- nullpo_retr (0, src);
- nullpo_retr (0, sg = src->group);
-
- switch (sg->unit_id)
- {
- case 0x8d: /* アイスウォール */
- src->val1 -= damage;
- break;
- case 0x8f: /* ブラストマイン */
- case 0x98: /* クレイモアートラップ */
- skill_blown (bl, &src->bl, 2); //å¹ã飛ã°ã—ã¦ã¿ã‚‹
- break;
- default:
- damage = 0;
- break;
- }
- return damage;
-}
-
-/*---------------------------------------------------------------------------- */
-
-/*==========================================
- * スキル使用(詠唱完了ã€å ´æ‰€æŒ‡å®šï¼‰
- *------------------------------------------
- */
-static
-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_retv (sd);
-
- if (sd->bl.prev == NULL)
- return;
- if (sd->skilltimer != tid) /* タイマIDã®ç¢ºèª */
- return;
- if (sd->skilltimer != -1 && pc_checkskill (sd, SA_FREECAST) > 0)
- {
- sd->speed = sd->prev_speed;
- clif_updatestatus (sd, SP_SPEED);
- }
- sd->skilltimer = -1;
- if (pc_isdead (sd))
- {
- sd->canact_tick = tick;
- sd->canmove_tick = tick;
- sd->skillitem = sd->skillitemlv = -1;
- return;
- }
-
- if (battle_config.pc_skill_reiteration == 0)
- {
- range = -1;
- switch (sd->skillid)
- {
- case MG_SAFETYWALL:
- case WZ_FIREPILLAR:
- case HT_SKIDTRAP:
- case HT_LANDMINE:
- case HT_ANKLESNARE:
- case HT_SHOCKWAVE:
- case HT_SANDMAN:
- case HT_FLASHER:
- case HT_FREEZINGTRAP:
- case HT_BLASTMINE:
- case HT_CLAYMORETRAP:
- case HT_TALKIEBOX:
- case AL_WARP:
- case PF_SPIDERWEB: /* スパイダーウェッブ */
- case RG_GRAFFITI: /* グラフィティ */
- range = 0;
- break;
- case AL_PNEUMA:
- range = 1;
- break;
- }
- if (range >= 0)
- {
- if (skill_check_unit_range
- (sd->bl.m, sd->skillx, sd->skilly, range, sd->skillid) > 0)
- {
- clif_skill_fail (sd, sd->skillid, 0, 0);
- sd->canact_tick = tick;
- sd->canmove_tick = tick;
- sd->skillitem = sd->skillitemlv = -1;
- return;
- }
- }
- }
- if (battle_config.pc_skill_nofootset)
- {
- range = -1;
- switch (sd->skillid)
- {
- case WZ_FIREPILLAR:
- case HT_SKIDTRAP:
- case HT_LANDMINE:
- case HT_ANKLESNARE:
- case HT_SHOCKWAVE:
- case HT_SANDMAN:
- case HT_FLASHER:
- case HT_FREEZINGTRAP:
- case HT_BLASTMINE:
- case HT_CLAYMORETRAP:
- case HT_TALKIEBOX:
- case PF_SPIDERWEB: /* スパイダーウェッブ */
- case WZ_ICEWALL:
- range = 1;
- break;
- case AL_WARP:
- range = 0;
- break;
- }
- if (range >= 0)
- {
- if (skill_check_unit_range2
- (sd->bl.m, sd->skillx, sd->skilly, range) > 0)
- {
- clif_skill_fail (sd, sd->skillid, 0, 0);
- sd->canact_tick = tick;
- sd->canmove_tick = tick;
- sd->skillitem = sd->skillitemlv = -1;
- return;
- }
- }
- }
-
- if (battle_config.pc_land_skill_limit)
- {
- maxcount = skill_get_maxcount (sd->skillid);
- if (maxcount > 0)
- {
- int i, c;
- for (i = c = 0; i < MAX_SKILLUNITGROUP; i++)
- {
- if (sd->skillunit[i].alive_count > 0
- && sd->skillunit[i].skill_id == sd->skillid)
- c++;
- }
- if (c >= maxcount)
- {
- clif_skill_fail (sd, sd->skillid, 0, 0);
- sd->canact_tick = tick;
- sd->canmove_tick = tick;
- sd->skillitem = sd->skillitemlv = -1;
- return;
- }
- }
- }
-
- range = skill_get_range (sd->skillid, sd->skilllv);
- if (range < 0)
- range = battle_get_range (&sd->bl) - (range + 1);
- range += battle_config.pc_skill_add_range;
- if (battle_config.skill_out_range_consume)
- { // changed to allow casting when target walks out of range [Valaris]
- if (range < distance (sd->bl.x, sd->bl.y, sd->skillx, sd->skilly))
- {
- clif_skill_fail (sd, sd->skillid, 0, 0);
- sd->canact_tick = tick;
- sd->canmove_tick = tick;
- sd->skillitem = sd->skillitemlv = -1;
- return;
- }
- }
- if (!skill_check_condition (sd, 1))
- { /* 使用æ¡ä»¶ãƒã‚§ãƒƒã‚¯ */
- sd->canact_tick = tick;
- sd->canmove_tick = tick;
- sd->skillitem = sd->skillitemlv = -1;
- return;
- }
- sd->skillitem = sd->skillitemlv = -1;
- if (battle_config.skill_out_range_consume)
- {
- if (range < distance (sd->bl.x, sd->bl.y, sd->skillx, sd->skilly))
- {
- clif_skill_fail (sd, sd->skillid, 0, 0);
- sd->canact_tick = tick;
- sd->canmove_tick = tick;
- return;
- }
- }
-
- if (battle_config.pc_skill_log)
- printf ("PC %d skill castend skill=%d\n", sd->bl.id, sd->skillid);
- pc_stop_walking (sd, 0);
-
- skill_castend_pos2 (&sd->bl, sd->skillx, sd->skilly, sd->skillid,
- sd->skilllv, tick, 0);
-}
-
-/*==========================================
- * 範囲内キャラ存在確èªåˆ¤å®šå‡¦ç†(foreachinarea)
- *------------------------------------------
- */
-
-static int skill_check_condition_char_sub (struct block_list *bl, va_list ap)
-{
- int *c;
- struct block_list *src;
- struct map_session_data *sd;
- struct map_session_data *ssd;
- struct pc_base_job s_class;
- struct pc_base_job ss_class;
-
- nullpo_retr (0, bl);
- nullpo_retr (0, ap);
- nullpo_retr (0, sd = (struct map_session_data *) bl);
- nullpo_retr (0, src = va_arg (ap, struct block_list *));
- nullpo_retr (0, c = va_arg (ap, int *));
- nullpo_retr (0, ssd = (struct map_session_data *) src);
-
- s_class = pc_calc_base_job (sd->status.pc_class);
- //ãƒã‚§ãƒƒã‚¯ã—ãªã„設定ãªã‚‰cã«ã‚ã‚Šãˆãªã„大ããªæ•°å­—ã‚’è¿”ã—ã¦çµ‚了
- if (!battle_config.player_skill_partner_check)
- { //本当ã¯foreachã®å‰ã«ã‚„ã‚ŠãŸã„ã‘ã©è¨­å®šé©ç”¨ç®‡æ‰€ã‚’ã¾ã¨ã‚ã‚‹ãŸã‚ã«ã“ã“ã¸
- (*c) = 99;
- return 0;
- }
-
- ;
- ss_class = pc_calc_base_job (ssd->status.pc_class);
-
- switch (ssd->skillid)
- {
- case PR_BENEDICTIO: /* è–体é™ç¦ */
- if (sd != ssd
- && (sd->status.pc_class == 4 || sd->status.pc_class == 8
- || sd->status.pc_class == 15 || sd->status.pc_class == 4005
- || sd->status.pc_class == 4009 || sd->status.pc_class == 4016)
- && (sd->bl.x == ssd->bl.x - 1 || sd->bl.x == ssd->bl.x + 1)
- && sd->status.sp >= 10)
- (*c)++;
- break;
- case BD_LULLABY: /* å­å®ˆæ­Œ */
- case BD_RICHMANKIM: /* ニヨルドã®å®´ */
- case BD_ETERNALCHAOS: /* æ°¸é ã®æ··æ²Œ */
- case BD_DRUMBATTLEFIELD: /* 戦太鼓ã®éŸ¿ã */
- case BD_RINGNIBELUNGEN: /* ニーベルングã®æŒ‡è¼ª */
- case BD_ROKISWEIL: /* ロキã®å«ã³ */
- case BD_INTOABYSS: /* 深淵ã®ä¸­ã« */
- case BD_SIEGFRIED: /* ä¸æ­»èº«ã®ã‚¸ãƒ¼ã‚¯ãƒ•ãƒªãƒ¼ãƒ‰ */
- case BD_RAGNAROK: /* 神々ã®é»„æ˜ */
- case CG_MOONLIT: /* 月明りã®æ³‰ã«è½ã¡ã‚‹èŠ±ã³ã‚‰ */
- if (sd != ssd &&
- ((ssd->status.pc_class == 19 && sd->status.pc_class == 20) ||
- (ssd->status.pc_class == 20 && sd->status.pc_class == 19) ||
- (ssd->status.pc_class == 4020 && sd->status.pc_class == 4021) ||
- (ssd->status.pc_class == 4021 && sd->status.pc_class == 4020) ||
- (ssd->status.pc_class == 20 && sd->status.pc_class == 4020) ||
- (ssd->status.pc_class == 19 && sd->status.pc_class == 4021)) &&
- pc_checkskill (sd, ssd->skillid) > 0 &&
- (*c) == 0 &&
- sd->status.party_id == ssd->status.party_id &&
- !pc_issit (sd) && sd->sc_data[SC_DANCING].timer == -1)
- (*c) = pc_checkskill (sd, ssd->skillid);
- break;
- }
- return 0;
-}
-
-/*==========================================
- * 範囲内キャラ存在確èªåˆ¤å®šå¾Œã‚¹ã‚­ãƒ«ä½¿ç”¨å‡¦ç†(foreachinarea)
- *------------------------------------------
- */
-
-static int skill_check_condition_use_sub (struct block_list *bl, va_list ap)
-{
- int *c;
- struct block_list *src;
- struct map_session_data *sd;
- struct map_session_data *ssd;
- struct pc_base_job s_class;
- struct pc_base_job ss_class;
- int skillid, skilllv;
-
- nullpo_retr (0, bl);
- nullpo_retr (0, ap);
- nullpo_retr (0, sd = (struct map_session_data *) bl);
- nullpo_retr (0, src = va_arg (ap, struct block_list *));
- nullpo_retr (0, c = va_arg (ap, int *));
- nullpo_retr (0, ssd = (struct map_session_data *) src);
-
- s_class = pc_calc_base_job (sd->status.pc_class);
-
- //ãƒã‚§ãƒƒã‚¯ã—ãªã„設定ãªã‚‰cã«ã‚ã‚Šãˆãªã„大ããªæ•°å­—ã‚’è¿”ã—ã¦çµ‚了
- if (!battle_config.player_skill_partner_check)
- { //本当ã¯foreachã®å‰ã«ã‚„ã‚ŠãŸã„ã‘ã©è¨­å®šé©ç”¨ç®‡æ‰€ã‚’ã¾ã¨ã‚ã‚‹ãŸã‚ã«ã“ã“ã¸
- (*c) = 99;
- return 0;
- }
-
- ss_class = pc_calc_base_job (ssd->status.pc_class);
- skillid = ssd->skillid;
- skilllv = ssd->skilllv;
- switch (skillid)
- {
- case PR_BENEDICTIO: /* è–体é™ç¦ */
- if (sd != ssd
- && (sd->status.pc_class == 4 || sd->status.pc_class == 8
- || sd->status.pc_class == 15 || sd->status.pc_class == 4005
- || sd->status.pc_class == 4009 || sd->status.pc_class == 4016)
- && (sd->bl.x == ssd->bl.x - 1 || sd->bl.x == ssd->bl.x + 1)
- && sd->status.sp >= 10)
- {
- sd->status.sp -= 10;
- pc_calcstatus (sd, 0);
- (*c)++;
- }
- break;
- case BD_LULLABY: /* å­å®ˆæ­Œ */
- case BD_RICHMANKIM: /* ニヨルドã®å®´ */
- case BD_ETERNALCHAOS: /* æ°¸é ã®æ··æ²Œ */
- case BD_DRUMBATTLEFIELD: /* 戦太鼓ã®éŸ¿ã */
- case BD_RINGNIBELUNGEN: /* ニーベルングã®æŒ‡è¼ª */
- case BD_ROKISWEIL: /* ロキã®å«ã³ */
- case BD_INTOABYSS: /* 深淵ã®ä¸­ã« */
- case BD_SIEGFRIED: /* ä¸æ­»èº«ã®ã‚¸ãƒ¼ã‚¯ãƒ•ãƒªãƒ¼ãƒ‰ */
- case BD_RAGNAROK: /* 神々ã®é»„æ˜ */
- case CG_MOONLIT: /* 月明りã®æ³‰ã«è½ã¡ã‚‹èŠ±ã³ã‚‰ */
- if (sd != ssd && //本人以外ã§
- ((ssd->status.pc_class == 19 && sd->status.pc_class == 20) ||
- (ssd->status.pc_class == 20 && sd->status.pc_class == 19) ||
- (ssd->status.pc_class == 4020 && sd->status.pc_class == 4021) ||
- (ssd->status.pc_class == 4021 && sd->status.pc_class == 4020) ||
- (ssd->status.pc_class == 20 && sd->status.pc_class == 4020) ||
- (ssd->status.pc_class == 19 && sd->status.pc_class == 4021)) && //自分ãŒãƒ€ãƒ³ã‚µãƒ¼ãªã‚‰ãƒãƒ¼ãƒ‰ã§
- pc_checkskill (sd, skillid) > 0 && //スキルをæŒã£ã¦ã„ã¦
- (*c) == 0 && //最åˆã®ä¸€äººã§
- sd->status.party_id == ssd->status.party_id && //パーティーãŒåŒã˜ã§
- !pc_issit (sd) && //座ã£ã¦ãªã„
- sd->sc_data[SC_DANCING].timer == -1 //ダンス中ã˜ã‚ƒãªã„
- )
- {
- ssd->sc_data[SC_DANCING].val4 = bl->id;
- clif_skill_nodamage (bl, src, skillid, skilllv, 1);
- skill_status_change_start (bl, SC_DANCING, skillid,
- ssd->sc_data[SC_DANCING].val2, 0,
- src->id, skill_get_time (skillid,
- skilllv) +
- 1000, 0);
- sd->skillid_dance = sd->skillid = skillid;
- sd->skilllv_dance = sd->skilllv = skilllv;
- (*c)++;
- }
- break;
- }
- return 0;
-}
-
-/*==========================================
- * 範囲内ãƒã‚¤ã‚ªãƒ—ラントã€ã‚¹ãƒ•ã‚£ã‚¢ãƒžã‚¤ãƒ³ç”¨Mob存在確èªåˆ¤å®šå‡¦ç†(foreachinarea)
- *------------------------------------------
- */
-
-static int skill_check_condition_mob_master_sub (struct block_list *bl,
- va_list ap)
-{
- int *c, src_id = 0, mob_class = 0;
- struct mob_data *md;
-
- nullpo_retr (0, bl);
- nullpo_retr (0, ap);
- nullpo_retr (0, md = (struct mob_data *) bl);
-
- 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->mob_class == mob_class && md->master_id == src_id)
- (*c)++;
- return 0;
-}
-
-/*==========================================
- * スキル使用æ¡ä»¶ï¼ˆå½ã§ä½¿ç”¨å¤±æ•—)
- *------------------------------------------
- */
-int skill_check_condition (struct map_session_data *sd, int type)
-{
- int hp, sp, hp_rate, sp_rate, zeny, weapon, state, spiritball, skill,
- lv, mhp;
- int index[10], itemid[10], amount[10];
-
- nullpo_retr (0, sd);
-
- if (battle_config.gm_skilluncond > 0
- && pc_isGM (sd) >= battle_config.gm_skilluncond)
- {
- sd->skillitem = sd->skillitemlv = -1;
- return 1;
- }
-
- if (sd->opt1 > 0)
- {
- clif_skill_fail (sd, sd->skillid, 0, 0);
- sd->skillitem = sd->skillitemlv = -1;
- return 0;
- }
- if (pc_is90overweight (sd))
- {
- clif_skill_fail (sd, sd->skillid, 9, 0);
- sd->skillitem = sd->skillitemlv = -1;
- return 0;
- }
-
- if (sd->skillid == AC_MAKINGARROW && sd->state.make_arrow_flag == 1)
- {
- sd->skillitem = sd->skillitemlv = -1;
- return 0;
- }
- /*if(sd->skillid == AM_PHARMACY && sd->state.produce_flag == 1) {
- * sd->skillitem = sd->skillitemlv = -1;
- * return 0;
- * } */
-
- if (sd->skillitem == sd->skillid)
- { /* アイテムã®å ´åˆç„¡æ¡ä»¶æˆåŠŸ */
- if (type & 1)
- sd->skillitem = sd->skillitemlv = -1;
- return 1;
- }
- if (sd->opt1 > 0)
- {
- clif_skill_fail (sd, sd->skillid, 0, 0);
- return 0;
- }
- if (sd->sc_data)
- {
- if (sd->sc_data[SC_DIVINA].timer != -1 ||
- sd->sc_data[SC_ROKISWEIL].timer != -1 ||
- (sd->sc_data[SC_AUTOCOUNTER].timer != -1
- && sd->skillid != KN_AUTOCOUNTER)
- || sd->sc_data[SC_STEELBODY].timer != -1
- || sd->sc_data[SC_BERSERK].timer != -1)
- {
- clif_skill_fail (sd, sd->skillid, 0, 0);
- return 0; /* 状態異常や沈黙ãªã© */
- }
- }
- skill = sd->skillid;
- lv = sd->skilllv;
- hp = skill_get_hp (skill, lv); /* 消費HP */
- sp = skill_get_sp (skill, lv); /* 消費SP */
- if ((sd->skillid_old == BD_ENCORE) && skill == sd->skillid_dance)
- sp = sp / 2; //アンコール時ã¯SP消費ãŒåŠåˆ†
- hp_rate = (lv <= 0) ? 0 : skill_db[skill].hp_rate[lv - 1];
- sp_rate = (lv <= 0) ? 0 : skill_db[skill].sp_rate[lv - 1];
- zeny = skill_get_zeny (skill, lv);
- weapon = skill_db[skill].weapon;
- state = skill_db[skill].state;
- spiritball = (lv <= 0) ? 0 : skill_db[skill].spiritball[lv - 1];
- mhp = skill_get_mhp (skill, lv); /* 消費HP */
- for (int i = 0; i < 10; i++)
- {
- itemid[i] = skill_db[skill].itemid[i];
- amount[i] = skill_db[skill].amount[i];
- }
- if (mhp > 0)
- hp += (sd->status.max_hp * mhp) / 100;
- if (hp_rate > 0)
- hp += (sd->status.hp * hp_rate) / 100;
- else
- hp += (sd->status.max_hp * abs (hp_rate)) / 100;
- if (sp_rate > 0)
- sp += (sd->status.sp * sp_rate) / 100;
- else
- sp += (sd->status.max_sp * abs (sp_rate)) / 100;
- if (sd->dsprate != 100)
- sp = sp * sd->dsprate / 100; /* 消費SP修正 */
-
- switch (skill)
- {
- case SA_CASTCANCEL:
- if (sd->skilltimer == -1)
- {
- clif_skill_fail (sd, skill, 0, 0);
- return 0;
- }
- break;
- case BS_MAXIMIZE: /* マキシマイズパワー */
- case NV_TRICKDEAD: /* 死んã ãµã‚Š */
- case TF_HIDING: /* ãƒã‚¤ãƒ‡ã‚£ãƒ³ã‚° */
- case AS_CLOAKING: /* クローキング */
- case CR_AUTOGUARD: /* オートガード */
- case CR_DEFENDER: /* ディフェンダー */
- case ST_CHASEWALK:
- if (sd->sc_data[SkillStatusChangeTable[skill]].timer != -1)
- return 1; /* 解除ã™ã‚‹å ´åˆã¯SP消費ã—ãªã„ */
- break;
- case AL_TELEPORT:
- case AL_WARP:
- if (map[sd->bl.m].flag.noteleport)
- {
- clif_skill_teleportmessage (sd, 0);
- return 0;
- }
- break;
- case MO_CALLSPIRITS: /* 気功 */
- if (sd->spiritball >= lv)
- {
- clif_skill_fail (sd, skill, 0, 0);
- return 0;
- }
- break;
- case CH_SOULCOLLECT: /* 狂気功 */
- if (sd->spiritball >= 5)
- {
- clif_skill_fail (sd, skill, 0, 0);
- return 0;
- }
- break;
- case MO_FINGEROFFENSIVE: //指弾
- if (sd->spiritball > 0 && sd->spiritball < spiritball)
- {
- spiritball = sd->spiritball;
- sd->spiritball_old = sd->spiritball;
- }
- else
- sd->spiritball_old = lv;
- break;
- case MO_CHAINCOMBO: //連打掌
- if (sd->sc_data[SC_BLADESTOP].timer == -1)
- {
- if (sd->sc_data[SC_COMBO].timer == -1
- || sd->sc_data[SC_COMBO].val1 != MO_TRIPLEATTACK)
- return 0;
- }
- break;
- case MO_COMBOFINISH: //猛é¾æ‹³
- if (sd->sc_data[SC_COMBO].timer == -1
- || sd->sc_data[SC_COMBO].val1 != MO_CHAINCOMBO)
- return 0;
- break;
- case CH_TIGERFIST: //ä¼è™Žæ‹³
- if (sd->sc_data[SC_COMBO].timer == -1
- || sd->sc_data[SC_COMBO].val1 != MO_COMBOFINISH)
- return 0;
- break;
- case CH_CHAINCRUSH: //連柱崩撃
- if (sd->sc_data[SC_COMBO].timer == -1)
- return 0;
- if (sd->sc_data[SC_COMBO].val1 != MO_COMBOFINISH
- && sd->sc_data[SC_COMBO].val1 != CH_TIGERFIST)
- return 0;
- break;
- case MO_EXTREMITYFIST: // 阿修羅覇鳳拳
- if ((sd->sc_data[SC_COMBO].timer != -1
- && (sd->sc_data[SC_COMBO].val1 == MO_COMBOFINISH
- || sd->sc_data[SC_COMBO].val1 == CH_CHAINCRUSH))
- || sd->sc_data[SC_BLADESTOP].timer != -1)
- spiritball--;
- break;
- case BD_ADAPTATION: /* アドリブ */
- {
- struct skill_unit_group *group = NULL;
- if (sd->sc_data[SC_DANCING].timer == -1
- ||
- ((group =
- (struct skill_unit_group *) sd->sc_data[SC_DANCING].val2)
- &&
- (skill_get_time
- (sd->sc_data[SC_DANCING].val1,
- group->skill_lv) - sd->sc_data[SC_DANCING].val3 * 1000) <=
- skill_get_time2 (skill, lv)))
- { //ダンス中ã§ä½¿ç”¨å¾Œ5秒以上ã®ã¿ï¼Ÿ
- clif_skill_fail (sd, skill, 0, 0);
- return 0;
- }
- }
- break;
- case PR_BENEDICTIO: /* è–体é™ç¦ */
- {
- int range = 1;
- int c = 0;
- if (!(type & 1))
- {
- map_foreachinarea (skill_check_condition_char_sub, sd->bl.m,
- sd->bl.x - range, sd->bl.y - range,
- sd->bl.x + range, sd->bl.y + range, BL_PC,
- &sd->bl, &c);
- if (c < 2)
- {
- clif_skill_fail (sd, skill, 0, 0);
- return 0;
- }
- }
- else
- {
- map_foreachinarea (skill_check_condition_use_sub, sd->bl.m,
- sd->bl.x - range, sd->bl.y - range,
- sd->bl.x + range, sd->bl.y + range, BL_PC,
- &sd->bl, &c);
- }
- }
- break;
- case WE_CALLPARTNER: /* ã‚ãªãŸã«é€¢ã„ãŸã„ */
- if (!sd->status.partner_id)
- {
- clif_skill_fail (sd, skill, 0, 0);
- return 0;
- }
- break;
- case AM_CANNIBALIZE: /* ãƒã‚¤ã‚ªãƒ—ラント */
- case AM_SPHEREMINE: /* スフィアーマイン */
- if (type & 1)
- {
- int c = 0;
- int maxcount = skill_get_maxcount (skill);
- int mob_class = (skill == AM_CANNIBALIZE) ? 1118 : 1142;
- if (battle_config.pc_land_skill_limit && maxcount > 0)
- {
- map_foreachinarea (skill_check_condition_mob_master_sub,
- sd->bl.m, 0, 0, map[sd->bl.m].xs,
- map[sd->bl.m].ys, BL_MOB, sd->bl.id,
- mob_class, &c);
- if (c >= maxcount)
- {
- clif_skill_fail (sd, skill, 0, 0);
- return 0;
- }
- }
- }
- break;
- case MG_FIREWALL: /* ファイアーウォール */
- /* æ•°åˆ¶é™ */
- if (battle_config.pc_land_skill_limit)
- {
- int maxcount = skill_get_maxcount (skill);
- if (maxcount > 0)
- {
- int i, c;
- for (i = c = 0; i < MAX_SKILLUNITGROUP; i++)
- {
- if (sd->skillunit[i].alive_count > 0
- && sd->skillunit[i].skill_id == skill)
- c++;
- }
- if (c >= maxcount)
- {
- clif_skill_fail (sd, skill, 0, 0);
- return 0;
- }
- }
- }
- break;
- }
-
- if (!(type & 2))
- {
- if (hp > 0 && sd->status.hp < hp)
- { /* HPãƒã‚§ãƒƒã‚¯ */
- clif_skill_fail (sd, skill, 2, 0); /* HPä¸è¶³ï¼šå¤±æ•—通知 */
- return 0;
- }
- if (sp > 0 && sd->status.sp < sp)
- { /* SPãƒã‚§ãƒƒã‚¯ */
- clif_skill_fail (sd, skill, 1, 0); /* SPä¸è¶³ï¼šå¤±æ•—通知 */
- return 0;
- }
- if (zeny > 0 && sd->status.zeny < zeny)
- {
- clif_skill_fail (sd, skill, 5, 0);
- return 0;
- }
- if (!(weapon & (1 << sd->status.weapon)))
- {
- clif_skill_fail (sd, skill, 6, 0);
- return 0;
- }
- if (spiritball > 0 && sd->spiritball < spiritball)
- {
- clif_skill_fail (sd, skill, 0, 0); // æ°£çƒä¸è¶³
- return 0;
- }
- }
-
- switch (state)
- {
- case ST_HIDING:
- if (!(sd->status.option & 2))
- {
- clif_skill_fail (sd, skill, 0, 0);
- return 0;
- }
- break;
- case ST_CLOAKING:
- if (!(sd->status.option & 4))
- {
- clif_skill_fail (sd, skill, 0, 0);
- return 0;
- }
- break;
- case ST_HIDDEN:
- if (!pc_ishiding (sd))
- {
- clif_skill_fail (sd, skill, 0, 0);
- return 0;
- }
- break;
- case ST_RIDING:
- if (!pc_isriding (sd))
- {
- clif_skill_fail (sd, skill, 0, 0);
- return 0;
- }
- break;
- case ST_FALCON:
- if (!pc_isfalcon (sd))
- {
- clif_skill_fail (sd, skill, 0, 0);
- return 0;
- }
- break;
- case ST_CART:
- if (!pc_iscarton (sd))
- {
- clif_skill_fail (sd, skill, 0, 0);
- return 0;
- }
- break;
- case ST_SHIELD:
- if (sd->status.shield <= 0)
- {
- clif_skill_fail (sd, skill, 0, 0);
- return 0;
- }
- break;
- case ST_SIGHT:
- if (sd->sc_data[SC_SIGHT].timer == -1 && type & 1)
- {
- clif_skill_fail (sd, skill, 0, 0);
- return 0;
- }
- break;
- case ST_EXPLOSIONSPIRITS:
- if (sd->sc_data[SC_EXPLOSIONSPIRITS].timer == -1)
- {
- clif_skill_fail (sd, skill, 0, 0);
- return 0;
- }
- break;
- case ST_RECOV_WEIGHT_RATE:
- if (battle_config.natural_heal_weight_rate <= 100
- && sd->weight * 100 / sd->max_weight >=
- battle_config.natural_heal_weight_rate)
- {
- clif_skill_fail (sd, skill, 0, 0);
- return 0;
- }
- break;
- case ST_MOVE_ENABLE:
- {
- struct walkpath_data wpd;
- if (path_search
- (&wpd, sd->bl.m, sd->bl.x, sd->bl.y, sd->skillx, sd->skilly,
- 1) == -1)
- {
- clif_skill_fail (sd, skill, 0, 0);
- return 0;
- }
- }
- break;
- case ST_WATER:
- if (map_getcell (sd->bl.m, sd->bl.x, sd->bl.y) != 3
- && (sd->sc_data[SC_DELUGE].timer == -1))
- { //水場判定
- clif_skill_fail (sd, skill, 0, 0);
- return 0;
- }
- break;
- }
-
- for (int i = 0; i < 10; i++)
- {
- int x = lv % 11 - 1;
- index[i] = -1;
- if (itemid[i] <= 0)
- continue;
- if (itemid[i] >= 715 && itemid[i] <= 717
- && sd->special_state.no_gemstone)
- continue;
- if (((itemid[i] >= 715 && itemid[i] <= 717) || itemid[i] == 1065)
- && sd->sc_data[SC_INTOABYSS].timer != -1)
- continue;
- if (skill == AM_POTIONPITCHER && i != x)
- continue;
-
- index[i] = pc_search_inventory (sd, itemid[i]);
- if (index[i] < 0 || sd->status.inventory[index[i]].amount < amount[i])
- {
- if (itemid[i] == 716 || itemid[i] == 717)
- clif_skill_fail (sd, skill, (7 + (itemid[i] - 716)), 0);
- else
- clif_skill_fail (sd, skill, 0, 0);
- return 0;
- }
- }
-
- if (!(type & 1))
- return 1;
-
- if (skill != AM_POTIONPITCHER)
- {
- if (skill == AL_WARP && !(type & 2))
- return 1;
- for (int i = 0; i < 10; i++)
- {
- if (index[i] >= 0)
- pc_delitem (sd, index[i], amount[i], 0); // アイテム消費
- }
- }
-
- if (type & 2)
- return 1;
-
- pc_heal (sd, -sp, -hp); // [Fate] This might suppress some dupe messages
-
-/* if(sp > 0) { // SP消費 */
-/* sd->status.sp-=sp; */
-/* clif_updatestatus(sd,SP_SP); */
-/* } */
-/* if(hp > 0) { // HP消費 */
-/* sd->status.hp-=hp; */
-/* clif_updatestatus(sd,SP_HP); */
-/* } */
- if (zeny > 0) // Zeny消費
- pc_payzeny (sd, zeny);
- if (spiritball > 0) // æ°£çƒæ¶ˆè²»
- pc_delspiritball (sd, spiritball, 0);
-
- return 1;
-}
-
-/*==========================================
* 詠唱時間計算
*------------------------------------------
*/
-int skill_castfix (struct block_list *bl, int time)
+interval_t skill_castfix(struct block_list *bl, interval_t interval)
{
- struct map_session_data *sd;
struct mob_data *md; // [Valaris]
- struct status_change *sc_data;
- int dex;
- int castrate = 100;
- int skill, lv, castnodex;
+ eptr<struct status_change, StatusChange> sc_data;
+ int dex;
+ int castrate = 100;
+ SkillID skill;
+ int lv, castnodex;
- nullpo_retr (0, bl);
+ nullpo_retr(interval_t::zero(), bl);
- if (bl->type == BL_MOB)
+ if (bl->type == BL::MOB)
{ // Crash fix [Valaris]
md = (struct mob_data *) bl;
skill = md->skillid;
lv = md->skilllv;
}
-
else
{
- sd = (struct map_session_data *) bl;
- skill = sd->skillid;
- lv = sd->skilllv;
+ skill = SkillID::ZERO;
+ lv = 0;
}
- sc_data = battle_get_sc_data (bl);
- dex = battle_get_dex (bl);
+ sc_data = battle_get_sc_data(bl);
+ dex = battle_get_dex(bl);
- if (skill > MAX_SKILL_DB || skill < 0)
- return 0;
+ if (skill > SkillID::MAX_SKILL_DB /*|| skill < SkillID()*/)
+ return interval_t::zero();
- castnodex = skill_get_castnodex (skill, lv);
+ castnodex = skill_get_castnodex(skill, lv);
- if (time == 0)
- return 0;
- if (castnodex > 0 && bl->type == BL_PC)
- castrate = ((struct map_session_data *) bl)->castrate;
- else if (castnodex <= 0 && bl->type == BL_PC)
+ if (interval == interval_t::zero())
+ return interval_t::zero();
+ if (castnodex > 0 && bl->type == BL::PC)
+ castrate = 100;
+ else if (castnodex <= 0 && bl->type == BL::PC)
{
- castrate = ((struct map_session_data *) bl)->castrate;
- time =
- time * castrate * (battle_config.castrate_dex_scale -
+ castrate = 100;
+ interval =
+ interval * castrate * (battle_config.castrate_dex_scale -
dex) / (battle_config.castrate_dex_scale *
100);
- time = time * battle_config.cast_rate / 100;
+ interval = interval * battle_config.cast_rate / 100;
}
- /* サフラギウム */
- if (sc_data && sc_data[SC_SUFFRAGIUM].timer != -1)
- {
- time = time * (100 - sc_data[SC_SUFFRAGIUM].val1 * 15) / 100;
- skill_status_change_end (bl, SC_SUFFRAGIUM, -1);
- }
- /* ブラギã®è©© */
- if (sc_data && sc_data[SC_POEMBRAGI].timer != -1)
- time =
- time * (100 -
- (sc_data[SC_POEMBRAGI].val1 * 3 +
- sc_data[SC_POEMBRAGI].val2 +
- (sc_data[SC_POEMBRAGI].val3 >> 16))) / 100;
-
- return (time > 0) ? time : 0;
+ return std::max(interval, interval_t::zero());
}
/*==========================================
* ディレイ計算
*------------------------------------------
*/
-int skill_delayfix (struct block_list *bl, int time)
+interval_t skill_delayfix(struct block_list *bl, interval_t interval)
{
- struct status_change *sc_data;
+ eptr<struct status_change, StatusChange> sc_data;
- nullpo_retr (0, bl);
+ nullpo_retr(interval_t::zero(), bl);
- sc_data = battle_get_sc_data (bl);
- if (time <= 0)
- return 0;
+ sc_data = battle_get_sc_data(bl);
+ if (interval <= interval_t::zero())
+ return interval_t::zero();
- if (bl->type == BL_PC)
+ if (bl->type == BL::PC)
{
if (battle_config.delay_dependon_dex) /* dexã®å½±éŸ¿ã‚’計算ã™ã‚‹ */
- time =
- time * (battle_config.castrate_dex_scale -
- battle_get_dex (bl)) /
+ interval =
+ interval * (battle_config.castrate_dex_scale -
+ battle_get_dex(bl)) /
battle_config.castrate_dex_scale;
- time = time * battle_config.delay_rate / 100;
- }
-
- /* ブラギã®è©© */
- if (sc_data && sc_data[SC_POEMBRAGI].timer != -1)
- time =
- time * (100 -
- (sc_data[SC_POEMBRAGI].val1 * 3 +
- sc_data[SC_POEMBRAGI].val2 +
- (sc_data[SC_POEMBRAGI].val3 & 0xffff))) / 100;
-
- return (time > 0) ? time : 0;
-}
-
-/*==========================================
- * スキル使用(ID指定)
- *------------------------------------------
- */
-int skill_use_id (struct map_session_data *sd, int target_id,
- int skill_num, int skill_lv)
-{
- unsigned int tick;
- int casttime = 0, delay = 0, skill, range_;
- struct map_session_data *target_sd = NULL;
- int forcecast = 0;
- struct block_list *bl;
- struct status_change *sc_data;
- tick = gettick ();
-
- nullpo_retr (0, sd);
-
- if ((bl = map_id2bl (target_id)) == NULL)
- {
-/* if(battle_config.error_log)
- printf("skill target not found %d\n",target_id); */
- return 0;
- }
- if (sd->bl.m != bl->m || pc_isdead (sd))
- return 0;
-
- if (skillnotok (skill_num, sd)) // [MouseJstr]
- return 0;
-
- if (sd->skillid == WZ_ICEWALL && map[sd->bl.m].flag.noicewall
- && !map[sd->bl.m].flag.pvp)
- { // noicewall flag [Valaris]
- clif_skill_fail (sd, sd->skillid, 0, 0);
- return 0;
- }
- sc_data = sd->sc_data;
-
- /* 沈黙や異常(ãŸã ã—ã€ã‚°ãƒªãƒ ãªã©ã®åˆ¤å®šã‚’ã™ã‚‹ï¼‰ */
- if (sd->opt1 > 0)
- return 0;
- if (sd->sc_data)
- {
- if (sc_data[SC_CHASEWALK].timer != -1)
- return 0;
- if (sc_data[SC_VOLCANO].timer != -1)
- {
- if (skill_num == WZ_ICEWALL)
- return 0;
- }
- if (sc_data[SC_ROKISWEIL].timer != -1)
- {
- if (skill_num == BD_ADAPTATION)
- return 0;
- }
- if (sd->sc_data[SC_DIVINA].timer != -1 ||
- sd->sc_data[SC_ROKISWEIL].timer != -1 ||
- (sd->sc_data[SC_AUTOCOUNTER].timer != -1
- && sd->skillid != KN_AUTOCOUNTER)
- || sd->sc_data[SC_STEELBODY].timer != -1
- || sd->sc_data[SC_BERSERK].timer != -1)
- {
- return 0; /* 状態異常や沈黙ãªã© */
- }
-
- if (sc_data[SC_BLADESTOP].timer != -1)
- {
- int lv = sc_data[SC_BLADESTOP].val1;
- if (sc_data[SC_BLADESTOP].val2 == 1)
- return 0; //白羽ã•ã‚ŒãŸå´ãªã®ã§ãƒ€ãƒ¡
- if (lv == 1)
- return 0;
- if (lv == 2 && skill_num != MO_FINGEROFFENSIVE)
- return 0;
- if (lv == 3 && skill_num != MO_FINGEROFFENSIVE
- && skill_num != MO_INVESTIGATE)
- return 0;
- if (lv == 4 && skill_num != MO_FINGEROFFENSIVE
- && skill_num != MO_INVESTIGATE && skill_num != MO_CHAINCOMBO)
- return 0;
- if (lv == 5 && skill_num != MO_FINGEROFFENSIVE
- && skill_num != MO_INVESTIGATE && skill_num != MO_CHAINCOMBO
- && skill_num != MO_EXTREMITYFIST)
- return 0;
- }
- }
-
- if (sd->status.option & 4 && skill_num == TF_HIDING)
- return 0;
- if (sd->status.option & 2 && skill_num != TF_HIDING
- && skill_num != AS_GRIMTOOTH && skill_num != RG_BACKSTAP
- && skill_num != RG_RAID)
- return 0;
-
- if (map[sd->bl.m].flag.gvg)
- { //GvGã§ä½¿ç”¨ã§ããªã„スキル
- switch (skill_num)
- {
- case SM_ENDURE:
- case AL_TELEPORT:
- case AL_WARP:
- case WZ_ICEWALL:
- case TF_BACKSLIDING:
- case LK_BERSERK:
- case HP_BASILICA:
- case ST_CHASEWALK:
- return 0;
- }
- }
-
- /* æ¼”å¥/ダンス中 */
- if (sc_data && sc_data[SC_DANCING].timer != -1)
- {
-// if(battle_config.pc_skill_log)
-// printf("dancing! %d\n",skill_num);
- if (sc_data[SC_DANCING].val4 && skill_num != BD_ADAPTATION) //åˆå¥ä¸­ã¯ã‚¢ãƒ‰ãƒªãƒ–以外ä¸å¯
- return 0;
- if (skill_num != BD_ADAPTATION && skill_num != BA_MUSICALSTRIKE
- && skill_num != DC_THROWARROW)
- {
- return 0;
- }
- }
-
- if (skill_get_inf2 (skill_num) & 0x200 && sd->bl.id == target_id)
- return 0;
- //ç›´å‰ã®ã‚¹ã‚­ãƒ«ãŒä½•ã‹è¦šãˆã‚‹å¿…è¦ã®ã‚るスキル
- switch (skill_num)
- {
- case SA_CASTCANCEL:
- if (sd->skillid != skill_num)
- { //キャストキャンセル自体ã¯è¦šãˆãªã„
- sd->skillid_old = sd->skillid;
- sd->skilllv_old = sd->skilllv;
- break;
- }
- case BD_ENCORE: /* アンコール */
- if (!sd->skillid_dance)
- { //å‰å›žä½¿ç”¨ã—ãŸè¸Šã‚ŠãŒãªã„ã¨ã ã‚
- clif_skill_fail (sd, skill_num, 0, 0);
- return 0;
- }
- else
- {
- sd->skillid_old = skill_num;
- }
- break;
- }
-
- sd->skillid = skill_num;
- sd->skilllv = skill_lv;
-
- switch (skill_num)
- { //事å‰ã«ãƒ¬ãƒ™ãƒ«ãŒå¤‰ã‚ã£ãŸã‚Šã™ã‚‹ã‚¹ã‚­ãƒ«
- case BD_LULLABY: /* å­å®ˆæ­Œ */
- case BD_RICHMANKIM: /* ニヨルドã®å®´ */
- case BD_ETERNALCHAOS: /* æ°¸é ã®æ··æ²Œ */
- case BD_DRUMBATTLEFIELD: /* 戦太鼓ã®éŸ¿ã */
- case BD_RINGNIBELUNGEN: /* ニーベルングã®æŒ‡è¼ª */
- case BD_ROKISWEIL: /* ロキã®å«ã³ */
- case BD_INTOABYSS: /* 深淵ã®ä¸­ã« */
- case BD_SIEGFRIED: /* ä¸æ­»èº«ã®ã‚¸ãƒ¼ã‚¯ãƒ•ãƒªãƒ¼ãƒ‰ */
- case BD_RAGNAROK: /* 神々ã®é»„æ˜ */
- case CG_MOONLIT: /* 月明りã®æ³‰ã«è½ã¡ã‚‹èŠ±ã³ã‚‰ */
- {
- int range = 1;
- int c = 0;
- map_foreachinarea (skill_check_condition_char_sub, sd->bl.m,
- sd->bl.x - range, sd->bl.y - range,
- sd->bl.x + range, sd->bl.y + range, BL_PC,
- &sd->bl, &c);
- if (c < 1)
- {
- clif_skill_fail (sd, skill_num, 0, 0);
- return 0;
- }
- else if (c == 99)
- { //相方ä¸è¦è¨­å®šã ã£ãŸ
- ;
- }
- else
- {
- sd->skilllv = (c + skill_lv) / 2;
- }
- }
- break;
- }
-
- if (!skill_check_condition (sd, 0))
- return 0;
-
- /* 射程ã¨éšœå®³ç‰©ãƒã‚§ãƒƒã‚¯ */
- range_ = skill_get_range (skill_num, skill_lv);
- if (range_ < 0)
- range_ = battle_get_range (&sd->bl) - (range_ + 1);
- if (!battle_check_range (&sd->bl, bl, range_))
- return 0;
-
- if (bl->type == BL_PC)
- {
- target_sd = (struct map_session_data *) bl;
- if (target_sd && skill_num == ALL_RESURRECTION
- && !pc_isdead (target_sd))
- return 0;
- }
- if ((skill_num != MO_CHAINCOMBO &&
- skill_num != MO_COMBOFINISH &&
- skill_num != MO_EXTREMITYFIST &&
- skill_num != CH_TIGERFIST &&
- skill_num != CH_CHAINCRUSH) ||
- (skill_num == MO_EXTREMITYFIST && sd->state.skill_flag))
- pc_stopattack (sd);
-
- casttime = skill_castfix (&sd->bl, skill_get_cast (skill_num, skill_lv));
- if (skill_num != SA_MAGICROD)
- delay =
- skill_delayfix (&sd->bl, skill_get_delay (skill_num, skill_lv));
- sd->state.skillcastcancel = skill_db[skill_num].castcancel;
-
- switch (skill_num)
- { /* 何ã‹ç‰¹æ®Šãªå‡¦ç†ãŒå¿…è¦ */
-// case AL_HEAL: /* ヒール */
-// if(battle_check_undead(battle_get_race(bl),battle_get_elem_type(bl)))
-// forcecast=1; /* ヒールアタックãªã‚‰è© å”±ã‚¨ãƒ•ã‚§ã‚¯ãƒˆæœ‰ã‚Š */
-// break;
- case ALL_RESURRECTION: /* リザレクション */
- if (bl->type != BL_PC
- && battle_check_undead (battle_get_race (bl),
- battle_get_elem_type (bl)))
- { /* 敵ãŒã‚¢ãƒ³ãƒ‡ãƒƒãƒ‰ãªã‚‰ */
- forcecast = 1; /* ターンアンデットã¨åŒã˜è© å”±æ™‚é–“ */
- casttime =
- skill_castfix (&sd->bl,
- skill_get_cast (PR_TURNUNDEAD, skill_lv));
- }
- break;
- case MO_FINGEROFFENSIVE: /* 指弾 */
- casttime +=
- casttime *
- ((skill_lv > sd->spiritball) ? sd->spiritball : skill_lv);
- break;
- case MO_CHAINCOMBO: /*連打掌 */
- target_id = sd->attacktarget;
- if (sc_data && sc_data[SC_BLADESTOP].timer != -1)
- {
- struct block_list *tbl;
- if ((tbl = (struct block_list *) sc_data[SC_BLADESTOP].val4) == NULL) //ターゲットãŒã„ãªã„?
- return 0;
- target_id = tbl->id;
- }
- break;
- case MO_COMBOFINISH: /*猛é¾æ‹³ */
- case CH_TIGERFIST: /* ä¼è™Žæ‹³ */
- case CH_CHAINCRUSH: /* 連柱崩撃 */
- target_id = sd->attacktarget;
- break;
-
-// -- moonsoul (altered to allow proper usage of extremity from new champion combos)
-//
- case MO_EXTREMITYFIST: /*阿修羅覇鳳拳 */
- if (sc_data && sc_data[SC_COMBO].timer != -1
- && (sc_data[SC_COMBO].val1 == MO_COMBOFINISH
- || sc_data[SC_COMBO].val1 == CH_CHAINCRUSH))
- {
- casttime = 0;
- target_id = sd->attacktarget;
- }
- forcecast = 1;
- break;
- case SA_MAGICROD:
- case SA_SPELLBREAKER:
- forcecast = 1;
- break;
- case WE_MALE:
- case WE_FEMALE:
- {
- struct map_session_data *p_sd = NULL;
- if ((p_sd = pc_get_partner (sd)) == NULL)
- return 0;
- target_id = p_sd->bl.id;
- //rangeã‚’ã‚‚ã†1回検査
- range_ = skill_get_range (skill_num, skill_lv);
- if (range_ < 0)
- range_ = battle_get_range (&sd->bl) - (range_ + 1);
- if (!battle_check_range (&sd->bl, &p_sd->bl, range_))
- {
- return 0;
- }
- }
- break;
- case AS_SPLASHER: /* ベナムスプラッシャー */
- {
- struct status_change *t_sc_data = battle_get_sc_data (bl);
- if (t_sc_data && t_sc_data[SC_POISON].timer == -1)
- {
- clif_skill_fail (sd, skill_num, 0, 10);
- return 0;
- }
- }
- break;
- case PF_MEMORIZE: /* メモライズ */
- casttime = 12000;
- break;
-
- }
-
- //メモライズ状態ãªã‚‰ã‚­ãƒ£ã‚¹ãƒˆã‚¿ã‚¤ãƒ ãŒ1/3
- if (sc_data && sc_data[SC_MEMORIZE].timer != -1 && casttime > 0)
- {
- casttime = casttime / 3;
- if ((--sc_data[SC_MEMORIZE].val2) <= 0)
- skill_status_change_end (&sd->bl, SC_MEMORIZE, -1);
- }
-
- if (battle_config.pc_skill_log)
- printf ("PC %d skill use target_id=%d skill=%d lv=%d cast=%d\n",
- sd->bl.id, target_id, skill_num, skill_lv, casttime);
-
-// if(sd->skillitem == skill_num)
-// casttime = delay = 0;
-
- if (casttime > 0 || forcecast)
- { /* è© å”±ãŒå¿…è¦ */
- struct mob_data *md;
- clif_skillcasting (&sd->bl,
- sd->bl.id, target_id, 0, 0, skill_num, casttime);
-
- /* è© å”±å応モンスター */
- if (bl->type == BL_MOB && (md = (struct mob_data *) bl)
- && mob_db[md->mob_class].mode & 0x10 && md->state.state != MS_ATTACK
- && sd->invincible_timer == -1)
- {
- md->target_id = sd->bl.id;
- md->state.targettype = ATTACKABLE;
- md->min_chase = 13;
- }
- }
-
- if (casttime <= 0) /* è© å”±ã®ç„¡ã„ã‚‚ã®ã¯ã‚­ãƒ£ãƒ³ã‚»ãƒ«ã•ã‚Œãªã„ */
- sd->state.skillcastcancel = 0;
-
- sd->skilltarget = target_id;
-/* sd->cast_target_bl = bl; */
- sd->skillx = 0;
- sd->skilly = 0;
- sd->canact_tick = tick + casttime + delay;
- sd->canmove_tick = tick;
- if (!(battle_config.pc_cloak_check_type & 2) && sc_data
- && sc_data[SC_CLOAKING].timer != -1 && sd->skillid != AS_CLOAKING)
- skill_status_change_end (&sd->bl, SC_CLOAKING, -1);
- if (casttime > 0)
- {
- sd->skilltimer =
- add_timer (tick + casttime, skill_castend_id, sd->bl.id, 0);
- if ((skill = pc_checkskill (sd, SA_FREECAST)) > 0)
- {
- sd->prev_speed = sd->speed;
- sd->speed = sd->speed * (175 - skill * 5) / 100;
- clif_updatestatus (sd, SP_SPEED);
- }
- else
- pc_stop_walking (sd, 0);
+ interval = interval * battle_config.delay_rate / 100;
}
- else
- {
- if (skill_num != SA_CASTCANCEL)
- sd->skilltimer = -1;
- skill_castend_id (sd->skilltimer, tick, sd->bl.id, 0);
- }
-
- //マジックパワーã®åŠ¹æžœçµ‚了
- if (sc_data && sc_data[SC_MAGICPOWER].timer != -1
- && skill_num != HW_MAGICPOWER)
- skill_status_change_end (&sd->bl, SC_MAGICPOWER, -1);
- return 0;
-}
-
-/*==========================================
- * スキル使用(場所指定)
- *------------------------------------------
- */
-int skill_use_pos (struct map_session_data *sd,
- int skill_x, int skill_y, int skill_num, int skill_lv)
-{
- struct block_list bl;
- struct status_change *sc_data;
- unsigned int tick;
- int casttime = 0, delay = 0, skill, range;
-
- nullpo_retr (0, sd);
-
- if (pc_isdead (sd))
- return 0;
-
- if (skillnotok (skill_num, sd)) // [MoueJstr]
- return 0;
-
- sc_data = sd->sc_data;
-
- if (sd->opt1 > 0)
- return 0;
- if (sc_data)
- {
- if (sc_data[SC_DIVINA].timer != -1 ||
- sc_data[SC_ROKISWEIL].timer != -1 ||
- sc_data[SC_AUTOCOUNTER].timer != -1 ||
- sc_data[SC_STEELBODY].timer != -1 ||
- sc_data[SC_DANCING].timer != -1 ||
- sc_data[SC_BERSERK].timer != -1)
- return 0; /* 状態異常や沈黙ãªã© */
- }
-
- if (sd->status.option & 2)
- return 0;
-
- if (map[sd->bl.m].flag.gvg
- && (skill_num == SM_ENDURE || skill_num == AL_TELEPORT
- || skill_num == AL_WARP || skill_num == WZ_ICEWALL
- || skill_num == TF_BACKSLIDING))
- return 0;
-
- sd->skillid = skill_num;
- sd->skilllv = skill_lv;
- sd->skillx = skill_x;
- sd->skilly = skill_y;
- if (!skill_check_condition (sd, 0))
- return 0;
-
- /* 射程ã¨éšœå®³ç‰©ãƒã‚§ãƒƒã‚¯ */
- bl.type = BL_NUL;
- bl.m = sd->bl.m;
- bl.x = skill_x;
- bl.y = skill_y;
- range = skill_get_range (skill_num, skill_lv);
- if (range < 0)
- range = battle_get_range (&sd->bl) - (range + 1);
- if (!battle_check_range (&sd->bl, &bl, range))
- return 0;
-
- pc_stopattack (sd);
-
- casttime = skill_castfix (&sd->bl, skill_get_cast (skill_num, skill_lv));
- delay = skill_delayfix (&sd->bl, skill_get_delay (skill_num, skill_lv));
- sd->state.skillcastcancel = skill_db[skill_num].castcancel;
-
- if (battle_config.pc_skill_log)
- printf ("PC %d skill use target_pos=(%d,%d) skill=%d lv=%d cast=%d\n",
- sd->bl.id, skill_x, skill_y, skill_num, skill_lv, casttime);
-
-// if(sd->skillitem == skill_num)
-// casttime = delay = 0;
- //メモライズ状態ãªã‚‰ã‚­ãƒ£ã‚¹ãƒˆã‚¿ã‚¤ãƒ ãŒ1/3
- if (sc_data && sc_data[SC_MEMORIZE].timer != -1 && casttime > 0)
- {
- casttime = casttime / 3;
- if ((--sc_data[SC_MEMORIZE].val2) <= 0)
- skill_status_change_end (&sd->bl, SC_MEMORIZE, -1);
- }
-
- if (casttime > 0) /* è© å”±ãŒå¿…è¦ */
- clif_skillcasting (&sd->bl,
- sd->bl.id, 0, skill_x, skill_y, skill_num,
- casttime);
-
- if (casttime <= 0) /* è© å”±ã®ç„¡ã„ã‚‚ã®ã¯ã‚­ãƒ£ãƒ³ã‚»ãƒ«ã•ã‚Œãªã„ */
- sd->state.skillcastcancel = 0;
-
- sd->skilltarget = 0;
-/* sd->cast_target_bl = NULL; */
- tick = gettick ();
- sd->canact_tick = tick + casttime + delay;
- sd->canmove_tick = tick;
- if (!(battle_config.pc_cloak_check_type & 2) && sc_data
- && sc_data[SC_CLOAKING].timer != -1)
- skill_status_change_end (&sd->bl, SC_CLOAKING, -1);
- if (casttime > 0)
- {
- sd->skilltimer =
- add_timer (tick + casttime, skill_castend_pos, sd->bl.id, 0);
- if ((skill = pc_checkskill (sd, SA_FREECAST)) > 0)
- {
- sd->prev_speed = sd->speed;
- sd->speed = sd->speed * (175 - skill * 5) / 100;
- clif_updatestatus (sd, SP_SPEED);
- }
- else
- pc_stop_walking (sd, 0);
- }
- else
- {
- sd->skilltimer = -1;
- skill_castend_pos (sd->skilltimer, tick, sd->bl.id, 0);
- }
- //マジックパワーã®åŠ¹æžœçµ‚了
- if (sc_data && sc_data[SC_MAGICPOWER].timer != -1
- && skill_num != HW_MAGICPOWER)
- skill_status_change_end (&sd->bl, SC_MAGICPOWER, -1);
-
- return 0;
+ return std::max(interval, interval_t::zero());
}
/*==========================================
* スキル詠唱キャンセル
*------------------------------------------
*/
-int skill_castcancel (struct block_list *bl, int type)
+int skill_castcancel(struct block_list *bl, int)
{
- int inf;
+ nullpo_ret(bl);
- nullpo_retr (0, bl);
-
- if (bl->type == BL_PC)
+ if (bl->type == BL::PC)
{
struct map_session_data *sd = (struct map_session_data *) bl;
- unsigned long tick = gettick ();
- nullpo_retr (0, sd);
+ tick_t tick = gettick();
sd->canact_tick = tick;
sd->canmove_tick = tick;
- if (sd->skilltimer != -1)
- {
- if (pc_checkskill (sd, SA_FREECAST) > 0)
- {
- sd->speed = sd->prev_speed;
- clif_updatestatus (sd, SP_SPEED);
- }
- if (!type)
- {
- if ((inf = skill_get_inf (sd->skillid)) == 2 || inf == 32)
- delete_timer (sd->skilltimer, skill_castend_pos);
- else
- delete_timer (sd->skilltimer, skill_castend_id);
- }
- else
- {
- if ((inf = skill_get_inf (sd->skillid_old)) == 2 || inf == 32)
- delete_timer (sd->skilltimer, skill_castend_pos);
- else
- delete_timer (sd->skilltimer, skill_castend_id);
- }
- sd->skilltimer = -1;
- clif_skillcastcancel (bl);
- }
return 0;
}
- else if (bl->type == BL_MOB)
+ else if (bl->type == BL::MOB)
{
struct mob_data *md = (struct mob_data *) bl;
- nullpo_retr (0, md);
- if (md->skilltimer != -1)
+ if (md->skilltimer)
{
- if ((inf = skill_get_inf (md->skillid)) == 2 || inf == 32)
- delete_timer (md->skilltimer, mobskill_castend_pos);
- else
- delete_timer (md->skilltimer, mobskill_castend_id);
- md->skilltimer = -1;
- clif_skillcastcancel (bl);
+ md->skilltimer.cancel();
+ clif_skillcastcancel(bl);
}
return 0;
}
return 1;
}
-/*=========================================
- * ブランディッシュスピア åˆæœŸç¯„囲決定
- *----------------------------------------
- */
-void skill_brandishspear_first (struct square *tc, int dir, int x, int y)
-{
-
- nullpo_retv (tc);
-
- if (dir == 0)
- {
- tc->val1[0] = x - 2;
- tc->val1[1] = x - 1;
- tc->val1[2] = x;
- tc->val1[3] = x + 1;
- tc->val1[4] = x + 2;
- tc->val2[0] =
- tc->val2[1] = tc->val2[2] = tc->val2[3] = tc->val2[4] = y - 1;
- }
- else if (dir == 2)
- {
- tc->val1[0] =
- tc->val1[1] = tc->val1[2] = tc->val1[3] = tc->val1[4] = x + 1;
- tc->val2[0] = y + 2;
- tc->val2[1] = y + 1;
- tc->val2[2] = y;
- tc->val2[3] = y - 1;
- tc->val2[4] = y - 2;
- }
- else if (dir == 4)
- {
- tc->val1[0] = x - 2;
- tc->val1[1] = x - 1;
- tc->val1[2] = x;
- tc->val1[3] = x + 1;
- tc->val1[4] = x + 2;
- tc->val2[0] =
- tc->val2[1] = tc->val2[2] = tc->val2[3] = tc->val2[4] = y + 1;
- }
- else if (dir == 6)
- {
- tc->val1[0] =
- tc->val1[1] = tc->val1[2] = tc->val1[3] = tc->val1[4] = x - 1;
- tc->val2[0] = y + 2;
- tc->val2[1] = y + 1;
- tc->val2[2] = y;
- tc->val2[3] = y - 1;
- tc->val2[4] = y - 2;
- }
- else if (dir == 1)
- {
- tc->val1[0] = x - 1;
- tc->val1[1] = x;
- tc->val1[2] = x + 1;
- tc->val1[3] = x + 2;
- tc->val1[4] = x + 3;
- tc->val2[0] = y - 4;
- tc->val2[1] = y - 3;
- tc->val2[2] = y - 1;
- tc->val2[3] = y;
- tc->val2[4] = y + 1;
- }
- else if (dir == 3)
- {
- tc->val1[0] = x + 3;
- tc->val1[1] = x + 2;
- tc->val1[2] = x + 1;
- tc->val1[3] = x;
- tc->val1[4] = x - 1;
- tc->val2[0] = y - 1;
- tc->val2[1] = y;
- tc->val2[2] = y + 1;
- tc->val2[3] = y + 2;
- tc->val2[4] = y + 3;
- }
- else if (dir == 5)
- {
- tc->val1[0] = x + 1;
- tc->val1[1] = x;
- tc->val1[2] = x - 1;
- tc->val1[3] = x - 2;
- tc->val1[4] = x - 3;
- tc->val2[0] = y + 3;
- tc->val2[1] = y + 2;
- tc->val2[2] = y + 1;
- tc->val2[3] = y;
- tc->val2[4] = y - 1;
- }
- else if (dir == 7)
- {
- tc->val1[0] = x - 3;
- tc->val1[1] = x - 2;
- tc->val1[2] = x - 1;
- tc->val1[3] = x;
- tc->val1[4] = x + 1;
- tc->val2[1] = y;
- tc->val2[0] = y + 1;
- tc->val2[2] = y - 1;
- tc->val2[3] = y - 2;
- tc->val2[4] = y - 3;
- }
-
-}
-
-/*=========================================
- * ブランディッシュスピア æ–¹å‘判定 範囲拡張
- *-----------------------------------------
- */
-void skill_brandishspear_dir (struct square *tc, int dir, int are)
-{
-
- int c;
-
- nullpo_retv (tc);
-
- for (c = 0; c < 5; c++)
- {
- if (dir == 0)
- {
- tc->val2[c] += are;
- }
- else if (dir == 1)
- {
- tc->val1[c] -= are;
- tc->val2[c] += are;
- }
- else if (dir == 2)
- {
- tc->val1[c] -= are;
- }
- else if (dir == 3)
- {
- tc->val1[c] -= are;
- tc->val2[c] -= are;
- }
- else if (dir == 4)
- {
- tc->val2[c] -= are;
- }
- else if (dir == 5)
- {
- tc->val1[c] += are;
- tc->val2[c] -= are;
- }
- else if (dir == 6)
- {
- tc->val1[c] += are;
- }
- else if (dir == 7)
- {
- tc->val1[c] += are;
- tc->val2[c] += are;
- }
- }
-}
-
/*==========================================
* ディボーション 有効確èª
*------------------------------------------
*/
-void skill_devotion (struct map_session_data *md, int target)
+void skill_devotion(struct map_session_data *md, int)
{
// ç·ç¢ºèª
- int n;
+ int n;
- nullpo_retv (md);
+ nullpo_retv(md);
for (n = 0; n < 5; n++)
{
if (md->dev.val1[n])
{
- struct map_session_data *sd = map_id2sd (md->dev.val1[n]);
+ struct map_session_data *sd = map_id2sd(md->dev.val1[n]);
// 相手ãŒè¦‹ã¤ã‹ã‚‰ãªã„ // 相手をディボã—ã¦ã‚‹ã®ãŒè‡ªåˆ†ã˜ã‚ƒãªã„ // è·é›¢ãŒé›¢ã‚Œã¦ã‚‹
if (sd == NULL
- || (sd->sc_data
- && (md->bl.id != sd->sc_data[SC_DEVOTION].val1))
- || skill_devotion3 (&md->bl, md->dev.val1[n]))
+ || (md->bl.id != 0/* was something else - TODO remove this */)
+ || skill_devotion3(&md->bl, md->dev.val1[n]))
{
- skill_devotion_end (md, sd, n);
+ skill_devotion_end(md, sd, n);
}
}
}
}
-void skill_devotion2 (struct block_list *bl, int crusader)
-{
- // 被ディボーションãŒæ­©ã„ãŸæ™‚ã®è·é›¢ãƒã‚§ãƒƒã‚¯
- struct map_session_data *sd = map_id2sd (crusader);
-
- nullpo_retv (bl);
-
- if (sd)
- skill_devotion3 (&sd->bl, bl->id);
-}
-
-int skill_devotion3 (struct block_list *bl, int target)
+int skill_devotion3(struct block_list *bl, int target)
{
// クルセãŒæ­©ã„ãŸæ™‚ã®è·é›¢ãƒã‚§ãƒƒã‚¯
struct map_session_data *md;
struct map_session_data *sd;
- int n, r = 0;
+ int n, r = 0;
- nullpo_retr (1, bl);
+ nullpo_retr(1, bl);
if ((md = (struct map_session_data *) bl) == NULL
- || (sd = map_id2sd (target)) == NULL)
+ || (sd = map_id2sd(target)) == NULL)
return 1;
else
- r = distance (bl->x, bl->y, sd->bl.x, sd->bl.y);
+ r = distance(bl->x, bl->y, sd->bl.x, sd->bl.y);
- if (pc_checkskill (sd, CR_DEVOTION) + 6 < r)
+ if ( + 6 < r)
{ // 許容範囲を超ãˆã¦ãŸ
for (n = 0; n < 5; n++)
if (md->dev.val1[n] == target)
md->dev.val2[n] = 0; // 離れãŸæ™‚ã¯ã€ç³¸ã‚’切るã ã‘
- clif_devotion (md, sd->bl.id);
return 1;
}
return 0;
}
-void skill_devotion_end (struct map_session_data *md,
- struct map_session_data *sd, int target)
+void skill_devotion_end(struct map_session_data *md,
+ struct map_session_data *, int target)
{
// クルセã¨è¢«ãƒ‡ã‚£ãƒœã‚­ãƒ£ãƒ©ã®ãƒªã‚»ãƒƒãƒˆ
- nullpo_retv (md);
- nullpo_retv (sd);
+ nullpo_retv(md);
md->dev.val1[target] = md->dev.val2[target] = 0;
- if (sd && sd->sc_data)
- {
- // skill_status_change_end(sd->bl,SC_DEVOTION,-1);
- sd->sc_data[SC_DEVOTION].val1 = 0;
- sd->sc_data[SC_DEVOTION].val2 = 0;
- clif_status_change (&sd->bl, SC_DEVOTION, 0);
- clif_devotion (md, sd->bl.id);
- }
}
-/*==========================================
- * オートスペル
- *------------------------------------------
- */
-int skill_autospell (struct map_session_data *sd, int skillid)
+int skill_gangsterparadise(struct map_session_data *, int)
{
- int skilllv;
- int maxlv = 1, lv;
-
- nullpo_retr (0, sd);
-
- skilllv = pc_checkskill (sd, SA_AUTOSPELL);
-
- if (skillid == MG_NAPALMBEAT)
- maxlv = 3;
- else if (skillid == MG_COLDBOLT || skillid == MG_FIREBOLT
- || skillid == MG_LIGHTNINGBOLT)
- {
- if (skilllv == 2)
- maxlv = 1;
- else if (skilllv == 3)
- maxlv = 2;
- else if (skilllv >= 4)
- maxlv = 3;
- }
- else if (skillid == MG_SOULSTRIKE)
- {
- if (skilllv == 5)
- maxlv = 1;
- else if (skilllv == 6)
- maxlv = 2;
- else if (skilllv >= 7)
- maxlv = 3;
- }
- else if (skillid == MG_FIREBALL)
- {
- if (skilllv == 8)
- maxlv = 1;
- else if (skilllv >= 9)
- maxlv = 2;
- }
- else if (skillid == MG_FROSTDIVER)
- maxlv = 1;
- else
- return 0;
-
- if (maxlv > (lv = pc_checkskill (sd, skillid)))
- maxlv = lv;
-
- skill_status_change_start (&sd->bl, SC_AUTOSPELL, skilllv, skillid, maxlv, 0, // val1:スキルID val2:使用最大Lv
- skill_get_time (SA_AUTOSPELL, skilllv), 0); // ã«ã—ã¦ã¿ãŸã‘ã©bscriptãŒæ›¸ã易ã„・・・?
return 0;
}
-/*==========================================
- * ギャングスターパラダイス判定処ç†(foreachinarea)
- *------------------------------------------
+/*----------------------------------------------------------------------------
+ * ステータス異常
+ *----------------------------------------------------------------------------
*/
-static int skill_gangster_count (struct block_list *bl, va_list ap)
-{
- int *c;
- struct map_session_data *sd;
-
- nullpo_retr (0, bl);
- nullpo_retr (0, ap);
-
- sd = (struct map_session_data *) bl;
- c = va_arg (ap, int *);
-
- if (sd && c && pc_issit (sd) && pc_checkskill (sd, RG_GANGSTER) > 0)
- (*c)++;
- return 0;
-}
-
-static int skill_gangster_in (struct block_list *bl, va_list ap)
-{
- struct map_session_data *sd;
-
- nullpo_retr (0, bl);
- nullpo_retr (0, ap);
-
- sd = (struct map_session_data *) bl;
- if (sd && pc_issit (sd) && pc_checkskill (sd, RG_GANGSTER) > 0)
- sd->state.gangsterparadise = 1;
- return 0;
-}
-
-static int skill_gangster_out (struct block_list *bl, va_list ap)
-{
- struct map_session_data *sd;
-
- nullpo_retr (0, bl);
- nullpo_retr (0, ap);
-
- sd = (struct map_session_data *) bl;
- if (sd && sd->state.gangsterparadise)
- sd->state.gangsterparadise = 0;
- return 0;
-}
-
-int skill_gangsterparadise (struct map_session_data *sd, int type)
-{
- int range = 1;
- int c = 0;
-
- nullpo_retr (0, sd);
-
- if (pc_checkskill (sd, RG_GANGSTER) <= 0)
- return 0;
-
- if (type == 1)
- { /* 座ã£ãŸæ™‚ã®å‡¦ç† */
- map_foreachinarea (skill_gangster_count, sd->bl.m,
- sd->bl.x - range, sd->bl.y - range,
- sd->bl.x + range, sd->bl.y + range, BL_PC, &c);
- if (c > 0)
- { /*ギャングスターæˆåŠŸã—ãŸã‚‰è‡ªåˆ†ã«ã‚‚ギャングスター属性付与 */
- map_foreachinarea (skill_gangster_in, sd->bl.m,
- sd->bl.x - range, sd->bl.y - range,
- sd->bl.x + range, sd->bl.y + range, BL_PC);
- sd->state.gangsterparadise = 1;
- }
- return 0;
- }
- else if (type == 0)
- { /* ç«‹ã¡ä¸ŠãŒã£ãŸã¨ãã®å‡¦ç† */
- map_foreachinarea (skill_gangster_count, sd->bl.m,
- sd->bl.x - range, sd->bl.y - range,
- sd->bl.x + range, sd->bl.y + range, BL_PC, &c);
- if (c < 1)
- map_foreachinarea (skill_gangster_out, sd->bl.m,
- sd->bl.x - range, sd->bl.y - range,
- sd->bl.x + range, sd->bl.y + range, BL_PC);
- sd->state.gangsterparadise = 0;
- return 0;
- }
- return 0;
-}
-
/*==========================================
- * 寒ã„ジョーク・スクリーム判定処ç†(foreachinarea)
+ * ステータス異常終了
*------------------------------------------
*/
-int skill_frostjoke_scream (struct block_list *bl, va_list ap)
+int skill_status_change_active(struct block_list *bl, StatusChange type)
{
- struct block_list *src;
- int skillnum, skilllv;
- unsigned int tick;
+ eptr<struct status_change, StatusChange> sc_data;
- nullpo_retr (0, bl);
- nullpo_retr (0, ap);
- nullpo_retr (0, src = va_arg (ap, struct block_list *));
-
- skillnum = va_arg (ap, int);
- skilllv = va_arg (ap, int);
- tick = va_arg (ap, unsigned int);
-
- if (src == bl) //自分ã«ã¯åŠ¹ã‹ãªã„
- return 0;
-
- if (battle_check_target (src, bl, BCT_ENEMY) > 0)
- skill_additional_effect (src, bl, skillnum, skilllv, BF_MISC, tick);
- else if (battle_check_target (src, bl, BCT_PARTY) > 0)
+ nullpo_ret(bl);
+ if (bl->type != BL::PC && bl->type != BL::MOB)
{
- if (MRAND (100) < 10) //PTメンãƒã«ã‚‚低確率ã§ã‹ã‹ã‚‹(ã¨ã‚Šã‚ãˆãš10%)
- skill_additional_effect (src, bl, skillnum, skilllv, BF_MISC,
- tick);
- }
-
- return 0;
-}
-
-/*==========================================
- *
- *------------------------------------------
- */
-int skill_attack_area (struct block_list *bl, va_list ap)
-{
- struct block_list *src, *dsrc;
- int atk_type, skillid, skilllv, flag, type;
- unsigned int tick;
-
- nullpo_retr (0, bl);
- nullpo_retr (0, ap);
-
- atk_type = va_arg (ap, int);
- if ((src = va_arg (ap, struct block_list *)) == NULL)
- return 0;
- if ((dsrc = va_arg (ap, struct block_list *)) == NULL)
+ if (battle_config.error_log)
+ PRINTF("skill_status_change_active: neither MOB nor PC !\n");
return 0;
- skillid = va_arg (ap, int);
- skilllv = va_arg (ap, int);
- tick = va_arg (ap, unsigned int);
- flag = va_arg (ap, int);
- type = va_arg (ap, int);
-
- if (battle_check_target (dsrc, bl, type) > 0)
- skill_attack (atk_type, src, dsrc, bl, skillid, skilllv, tick, flag);
-
- return 0;
-}
-
-/*==========================================
- *
- *------------------------------------------
- */
-int skill_clear_element_field (struct block_list *bl)
-{
- struct mob_data *md = NULL;
- struct map_session_data *sd = NULL;
- int i, skillid;
-
- nullpo_retr (0, bl);
-
- if (bl->type == BL_MOB)
- md = (struct mob_data *) bl;
- if (bl->type == BL_PC)
- sd = (struct map_session_data *) bl;
-
- for (i = 0; i < MAX_MOBSKILLUNITGROUP; i++)
- {
- if (sd)
- {
- skillid = sd->skillunit[i].skill_id;
- if (skillid == SA_DELUGE || skillid == SA_VOLCANO
- || skillid == SA_VIOLENTGALE || skillid == SA_LANDPROTECTOR)
- skill_delunitgroup (&sd->skillunit[i]);
- }
- else if (md)
- {
- skillid = md->skillunit[i].skill_id;
- if (skillid == SA_DELUGE || skillid == SA_VOLCANO
- || skillid == SA_VIOLENTGALE || skillid == SA_LANDPROTECTOR)
- skill_delunitgroup (&md->skillunit[i]);
- }
}
- return 0;
-}
-/*==========================================
- * ランドプロテクターãƒã‚§ãƒƒã‚¯(foreachinarea)
- *------------------------------------------
- */
-int skill_landprotector (struct block_list *bl, va_list ap)
-{
- int skillid;
- int *alive;
- struct skill_unit *unit;
-
- nullpo_retr (0, bl);
- nullpo_retr (0, ap);
-
- skillid = va_arg (ap, int);
- alive = va_arg (ap, int *);
- if ((unit = (struct skill_unit *) bl) == NULL)
+ sc_data = battle_get_sc_data(bl);
+ if (not sc_data)
return 0;
- if (skillid == SA_LANDPROTECTOR)
- {
- skill_delunit (unit);
- }
- else
- {
- if (alive && unit->group->skill_id == SA_LANDPROTECTOR)
- (*alive) = 0;
- }
- return 0;
+ return bool(sc_data[type].timer);
}
-/*==========================================
- * イドゥンã®æž—檎ã®å›žå¾©å‡¦ç†(foreachinarea)
- *------------------------------------------
- */
-static
-int skill_idun_heal (struct block_list *bl, va_list ap)
+void skill_status_change_end(struct block_list *bl, StatusChange type, TimerData *tid)
{
- struct skill_unit *unit;
- struct skill_unit_group *sg;
- int heal;
-
- nullpo_retr (0, bl);
- nullpo_retr (0, ap);
- nullpo_retr (0, unit = va_arg (ap, struct skill_unit *));
- nullpo_retr (0, sg = unit->group);
+ eptr<struct status_change, StatusChange> sc_data;
+ int opt_flag = 0, calc_flag = 0;
+ short *sc_count;
+ Option *option;
+ Opt1 *opt1;
+ Opt2 *opt2;
+ Opt3 *opt3;
- heal =
- 30 + sg->skill_lv * 5 + ((sg->val1) >> 16) * 5 +
- ((sg->val1) & 0xfff) / 2;
-
- if (bl->type == BL_SKILL || bl->id == sg->src_id)
- return 0;
-
- if (bl->type == BL_PC || bl->type == BL_MOB)
+ nullpo_retv(bl);
+ if (bl->type != BL::PC && bl->type != BL::MOB)
{
- clif_skill_nodamage (&unit->bl, bl, AL_HEAL, heal, 1);
- battle_heal (NULL, bl, heal, 0, 0);
+ if (battle_config.error_log)
+ PRINTF("skill_status_change_end: neither MOB nor PC !\n");
+ return;
}
- return 0;
-}
-
-/*==========================================
- * 指定範囲内ã§srcã«å¯¾ã—ã¦æœ‰åŠ¹ãªã‚¿ãƒ¼ã‚²ãƒƒãƒˆã®blã®æ•°ã‚’æ•°ãˆã‚‹(foreachinarea)
- *------------------------------------------
- */
-int skill_count_target (struct block_list *bl, va_list ap)
-{
- struct block_list *src;
- int *c;
-
- nullpo_retr (0, bl);
- nullpo_retr (0, ap);
-
- if ((src = va_arg (ap, struct block_list *)) == NULL)
- return 0;
- if ((c = va_arg (ap, int *)) == NULL)
- return 0;
- if (battle_check_target (src, bl, BCT_ENEMY) > 0)
- (*c)++;
- return 0;
-}
-
-/*==========================================
- * トラップ範囲処ç†(foreachinarea)
- *------------------------------------------
- */
-int skill_trap_splash (struct block_list *bl, va_list ap)
-{
- struct block_list *src;
- int tick;
- int splash_count;
- struct skill_unit *unit;
- struct skill_unit_group *sg;
- struct block_list *ss;
- int i;
-
- nullpo_retr (0, bl);
- nullpo_retr (0, ap);
- nullpo_retr (0, src = va_arg (ap, struct block_list *));
- nullpo_retr (0, unit = (struct skill_unit *) src);
- nullpo_retr (0, sg = unit->group);
- nullpo_retr (0, ss = map_id2bl (sg->src_id));
-
- tick = va_arg (ap, int);
- splash_count = va_arg (ap, int);
-
- if (battle_check_target (src, bl, BCT_ENEMY) > 0)
- {
- switch (sg->unit_id)
- {
- case 0x95: /* サンドマン */
- case 0x96: /* フラッシャー */
- case 0x94: /* ショックウェーブトラップ */
- skill_additional_effect (ss, bl, sg->skill_id, sg->skill_lv,
- BF_MISC, tick);
- break;
- case 0x8f: /* ブラストマイン */
- case 0x98: /* クレイモアートラップ */
- for (i = 0; i < splash_count; i++)
- {
- skill_attack (BF_MISC, ss, src, bl, sg->skill_id,
- sg->skill_lv, tick,
- (sg->val2) ? 0x0500 : 0);
- }
- case 0x97: /* フリージングトラップ */
- skill_attack (BF_WEAPON, ss, src, bl, sg->skill_id,
- sg->skill_lv, tick, (sg->val2) ? 0x0500 : 0);
- break;
- default:
- break;
- }
+ sc_data = battle_get_sc_data(bl);
+ if (not sc_data)
+ return;
+ sc_count = battle_get_sc_count(bl);
+ nullpo_retv(sc_count);
+ option = battle_get_option(bl);
+ nullpo_retv(option);
+ opt1 = battle_get_opt1(bl);
+ nullpo_retv(opt1);
+ opt2 = battle_get_opt2(bl);
+ nullpo_retv(opt2);
+ opt3 = battle_get_opt3(bl);
+ nullpo_retv(opt3);
+
+ // status_change_end can be called 2 ways: automatically by a timer,
+ // or manually to cancel it.
+ if (!tid) // if this is a cancel
+ {
+ // and it was not active
+ if (!sc_data[type].timer)
+ // there's nothing to do
+ return;
+ // if it was active, cancel it
+ sc_data[type].timer.cancel();
}
+ // whether we are the timer or a cancel no longer matters
- return 0;
-}
-
-/*----------------------------------------------------------------------------
- * ステータス異常
- *----------------------------------------------------------------------------
- */
-
-/*==========================================
- * ステータス異常タイマー範囲処ç†
- *------------------------------------------
- */
-int skill_status_change_timer_sub (struct block_list *bl, va_list ap)
-{
- struct block_list *src;
- int type;
- unsigned int tick;
-
- nullpo_retr (0, bl);
- nullpo_retr (0, ap);
- nullpo_retr (0, src = va_arg (ap, struct block_list *));
- type = va_arg (ap, int);
- tick = va_arg (ap, unsigned int);
-
- if (bl->type != BL_PC && bl->type != BL_MOB)
- return 0;
+ assert (!sc_data[type].timer);
+ assert ((*sc_count) > 0);
+ (*sc_count)--;
switch (type)
- {
- case SC_SIGHT: /* サイト */
- case SC_CONCENTRATE:
- if ((*battle_get_option (bl)) & 6)
- {
- skill_status_change_end (bl, SC_HIDING, -1);
- skill_status_change_end (bl, SC_CLOAKING, -1);
- }
+ { /* 異常ã®ç¨®é¡žã”ã¨ã®å‡¦ç† */
+ case StatusChange::SC_SPEEDPOTION0: /* 増速ãƒãƒ¼ã‚·ãƒ§ãƒ³ */
+ case StatusChange::SC_ATKPOT: /* attack potion [Valaris] */
+ case StatusChange::SC_MATKPOT: /* magic attack potion [Valaris] */
+ case StatusChange::SC_PHYS_SHIELD:
+ case StatusChange::SC_HASTE:
+ calc_flag = 1;
break;
- case SC_RUWACH: /* ルアフ */
- if ((*battle_get_option (bl)) & 6)
- {
- skill_status_change_end (bl, SC_HIDING, -1);
- skill_status_change_end (bl, SC_CLOAKING, -1);
- if (battle_check_target (src, bl, BCT_ENEMY) > 0)
- {
- struct status_change *sc_data = battle_get_sc_data (bl);
- skill_attack (BF_MAGIC, src, src, bl, AL_RUWACH,
- sc_data[type].val1, tick, 0);
- }
- }
+
+ /* option2 */
+ case StatusChange::SC_POISON: /* 毒 */
+ calc_flag = 1;
break;
}
- return 0;
-}
-/*==========================================
- * ステータス異常終了
- *------------------------------------------
- */
-int skill_status_change_active (struct block_list *bl, int type)
-{
- struct status_change *sc_data;
+ if (bl->type == BL::PC && type < StatusChange::SC_SENDMAX)
+ clif_status_change(bl, type, 0); /* アイコン消去 */
- nullpo_retr (0, bl);
- if (bl->type != BL_PC && bl->type != BL_MOB)
+ switch (type)
{
- if (battle_config.error_log)
- printf ("skill_status_change_active: neither MOB nor PC !\n");
- return 0;
- }
-
- nullpo_retr (0, sc_data = battle_get_sc_data (bl));
+ case StatusChange::SC_POISON:
+ *opt2 &= ~Opt2::_poison;
+ opt_flag = 1;
+ break;
- return sc_data[type].timer != -1;
-}
+ case StatusChange::SC_SLOWPOISON:
+ if (sc_data[StatusChange::SC_POISON].timer)
+ *opt2 |= Opt2::_poison;
+ *opt2 &= ~Opt2::_slowpoison;
+ opt_flag = 1;
+ break;
-int skill_status_change_end (struct block_list *bl, int type, int tid)
-{
- struct status_change *sc_data;
- int opt_flag = 0, calc_flag = 0;
- short *sc_count, *option, *opt1, *opt2, *opt3;
+ case StatusChange::SC_SPEEDPOTION0:
+ *opt2 &= ~Opt2::_speedpotion0;
+ opt_flag = 1;
+ break;
- nullpo_retr (0, bl);
- if (bl->type != BL_PC && bl->type != BL_MOB)
- {
- if (battle_config.error_log)
- printf ("skill_status_change_end: neither MOB nor PC !\n");
- return 0;
+ case StatusChange::SC_ATKPOT:
+ *opt2 &= ~Opt2::_atkpot;
+ opt_flag = 1;
+ break;
}
- nullpo_retr (0, sc_data = battle_get_sc_data (bl));
- nullpo_retr (0, sc_count = battle_get_sc_count (bl));
- nullpo_retr (0, option = battle_get_option (bl));
- nullpo_retr (0, opt1 = battle_get_opt1 (bl));
- nullpo_retr (0, opt2 = battle_get_opt2 (bl));
- nullpo_retr (0, opt3 = battle_get_opt3 (bl));
-
- if ((*sc_count) > 0 && sc_data[type].timer != -1
- && (sc_data[type].timer == tid || tid == -1))
- {
-
- if (tid == -1) // タイマã‹ã‚‰å‘¼ã°ã‚Œã¦ã„ãªã„ãªã‚‰ã‚¿ã‚¤ãƒžå‰Šé™¤ã‚’ã™ã‚‹
- delete_timer (sc_data[type].timer, skill_status_change_timer);
-
- /* 該当ã®ç•°å¸¸ã‚’正常ã«æˆ»ã™ */
- sc_data[type].timer = -1;
- (*sc_count)--;
-
- switch (type)
- { /* 異常ã®ç¨®é¡žã”ã¨ã®å‡¦ç† */
- case SC_PROVOKE: /* プロボック */
- case SC_CONCENTRATE: /* 集中力å‘上 */
- case SC_BLESSING: /* ブレッシング */
- case SC_ANGELUS: /* アンゼルス */
- case SC_INCREASEAGI: /* 速度上昇 */
- case SC_DECREASEAGI: /* 速度減少 */
- case SC_SIGNUMCRUCIS: /* シグナムクルシス */
- case SC_HIDING:
- case SC_TWOHANDQUICKEN: /* 2HQ */
- case SC_ADRENALINE: /* アドレナリンラッシュ */
- case SC_ENCPOISON: /* エンãƒãƒ£ãƒ³ãƒˆãƒã‚¤ã‚ºãƒ³ */
- case SC_IMPOSITIO: /* インãƒã‚·ãƒ†ã‚£ã‚ªãƒžãƒŒã‚¹ */
- case SC_GLORIA: /* グロリア */
- case SC_LOUD: /* ラウドボイス */
- case SC_QUAGMIRE: /* クァグマイア */
- case SC_PROVIDENCE: /* プロヴィデンス */
- case SC_SPEARSQUICKEN: /* スピアクイッケン */
- case SC_VOLCANO:
- case SC_DELUGE:
- case SC_VIOLENTGALE:
- case SC_ETERNALCHAOS: /* エターナルカオス */
- case SC_DRUMBATTLE: /* 戦太鼓ã®éŸ¿ã */
- case SC_NIBELUNGEN: /* ニーベルングã®æŒ‡è¼ª */
- case SC_SIEGFRIED: /* ä¸æ­»èº«ã®ã‚¸ãƒ¼ã‚¯ãƒ•ãƒªãƒ¼ãƒ‰ */
- case SC_WHISTLE: /* å£ç¬› */
- case SC_ASSNCROS: /* 夕陽ã®ã‚¢ã‚µã‚·ãƒ³ã‚¯ãƒ­ã‚¹ */
- case SC_HUMMING: /* ãƒãƒŸãƒ³ã‚° */
- case SC_DONTFORGETME: /* ç§ã‚’忘れãªã„㧠*/
- case SC_FORTUNE: /* 幸é‹ã®ã‚­ã‚¹ */
- case SC_SERVICE4U: /* サービスフォーユー */
- case SC_EXPLOSIONSPIRITS: // 爆裂波動
- case SC_STEELBODY: // 金剛
- case SC_DEFENDER:
- case SC_SPEEDPOTION0: /* 増速ãƒãƒ¼ã‚·ãƒ§ãƒ³ */
- case SC_SPEEDPOTION1:
- case SC_SPEEDPOTION2:
- case SC_APPLEIDUN: /* イドゥンã®æž—檎 */
- case SC_RIDING:
- case SC_BLADESTOP_WAIT:
- case SC_AURABLADE: /* オーラブレード */
- case SC_PARRYING: /* パリイング */
- case SC_CONCENTRATION: /* コンセントレーション */
- case SC_TENSIONRELAX: /* テンションリラックス */
- case SC_ASSUMPTIO: /* アシャンプティオ */
- case SC_WINDWALK: /* ウインドウォーク */
- case SC_TRUESIGHT: /* トゥルーサイト */
- case SC_SPIDERWEB: /* スパイダーウェッブ */
- case SC_MAGICPOWER: /* 魔法力増幅 */
- case SC_CHASEWALK:
- case SC_ATKPOT: /* attack potion [Valaris] */
- case SC_MATKPOT: /* magic attack potion [Valaris] */
- case SC_WEDDING: //çµå©šç”¨(çµå©šè¡£è£³ã«ãªã£ã¦æ­©ãã®ãŒé…ã„ã¨ã‹)
- case SC_MELTDOWN: /* メルトダウン */
- case SC_PHYS_SHIELD:
- case SC_HASTE:
- calc_flag = 1;
- break;
- case SC_BERSERK: /* ãƒãƒ¼ã‚µãƒ¼ã‚¯ */
- calc_flag = 1;
- clif_status_change (bl, SC_INCREASEAGI, 0); /* アイコン消去 */
- break;
- case SC_DEVOTION: /* ディボーション */
- {
- struct map_session_data *md = map_id2sd (sc_data[type].val1);
- sc_data[type].val1 = sc_data[type].val2 = 0;
- skill_devotion (md, bl->id);
- calc_flag = 1;
- }
- break;
- case SC_BLADESTOP:
- {
- struct status_change *t_sc_data =
- battle_get_sc_data ((struct block_list *)
- sc_data[type].val4);
- //片方ãŒåˆ‡ã‚ŒãŸã®ã§ç›¸æ‰‹ã®ç™½åˆƒçŠ¶æ…‹ãŒåˆ‡ã‚Œã¦ãªã„ã®ãªã‚‰è§£é™¤
- if (t_sc_data && t_sc_data[SC_BLADESTOP].timer != -1)
- skill_status_change_end ((struct block_list *)
- sc_data[type].val4, SC_BLADESTOP,
- -1);
-
- if (sc_data[type].val2 == 2)
- clif_bladestop ((struct block_list *) sc_data[type].val3,
- (struct block_list *) sc_data[type].val4,
- 0);
- }
- break;
- case SC_DANCING:
- {
- struct map_session_data *dsd;
- struct status_change *d_sc_data;
- if (sc_data[type].val4
- && (dsd = map_id2sd (sc_data[type].val4)))
- {
- d_sc_data = dsd->sc_data;
- //åˆå¥ã§ç›¸æ‰‹ãŒã„ã‚‹å ´åˆç›¸æ‰‹ã®val4ã‚’0ã«ã™ã‚‹
- if (d_sc_data && d_sc_data[type].timer != -1)
- d_sc_data[type].val4 = 0;
- }
- }
- calc_flag = 1;
- break;
- case SC_GRAFFITI:
- {
- struct skill_unit_group *sg = (struct skill_unit_group *) sc_data[type].val4; //val4ãŒã‚°ãƒ©ãƒ•ã‚£ãƒ†ã‚£ã®group_id
- if (sg)
- skill_delunitgroup (sg);
- }
- break;
- case SC_NOCHAT: //ãƒãƒ£ãƒƒãƒˆç¦æ­¢çŠ¶æ…‹
- {
- struct map_session_data *sd = NULL;
- if (bl->type == BL_PC
- && (sd = (struct map_session_data *) bl))
- {
- sd->status.manner = 0;
- clif_updatestatus (sd, SP_MANNER);
- }
- }
- break;
- case SC_SPLASHER: /* ベナムスプラッシャー */
- {
- struct block_list *src = map_id2bl (sc_data[type].val3);
- if (src && tid != -1)
- {
- //自分ã«ãƒ€ãƒ¡ãƒ¼ã‚¸ï¼†å‘¨å›²3*3ã«ãƒ€ãƒ¡ãƒ¼ã‚¸
- skill_castend_damage_id (src, bl, sc_data[type].val2,
- sc_data[type].val1, gettick (),
- 0);
- }
- }
- break;
- case SC_SELFDESTRUCTION: /* 自爆 */
- {
- //自分ã®ãƒ€ãƒ¡ãƒ¼ã‚¸ã¯0ã«ã—ã¦
- struct mob_data *md = NULL;
- if (bl->type == BL_MOB && (md = (struct mob_data *) bl))
- skill_castend_damage_id (bl, bl, sc_data[type].val2,
- sc_data[type].val1, gettick (),
- 0);
- }
- break;
- /* option1 */
- case SC_FREEZE:
- sc_data[type].val3 = 0;
- break;
-
- /* option2 */
- case SC_POISON: /* 毒 */
- case SC_BLIND: /* æš—é»’ */
- case SC_CURSE:
- calc_flag = 1;
- break;
- }
-
- if (bl->type == BL_PC && type < SC_SENDMAX)
- clif_status_change (bl, type, 0); /* アイコン消去 */
- switch (type)
- { /* 正常ã«æˆ»ã‚‹ã¨ããªã«ã‹å‡¦ç†ãŒå¿…è¦ */
- case SC_STONE:
- case SC_FREEZE:
- case SC_STAN:
- case SC_SLEEP:
- *opt1 = 0;
- opt_flag = 1;
- break;
-
- case SC_POISON:
- case SC_CURSE:
- case SC_SILENCE:
- case SC_BLIND:
- *opt2 &= ~(1 << (type - SC_POISON));
- opt_flag = 1;
- break;
-
- case SC_SLOWPOISON:
- if (sc_data[SC_POISON].timer != -1)
- *opt2 |= 0x1;
- *opt2 &= ~0x200;
- opt_flag = 1;
- break;
-
- case SC_SIGNUMCRUCIS:
- *opt2 &= ~0x40;
- opt_flag = 1;
- break;
-
- case SC_SPEEDPOTION0:
- *opt2 &= ~0x20;
- opt_flag = 1;
- break;
+ if (opt_flag) /* optionã®å¤‰æ›´ã‚’ä¼ãˆã‚‹ */
+ clif_changeoption(bl);
- case SC_ATKPOT:
- *opt2 &= ~0x80;
- opt_flag = 1;
- break;
-
- case SC_HIDING:
- case SC_CLOAKING:
- *option &= ~((type == SC_HIDING) ? 2 : 4);
- opt_flag = 1;
- break;
-
- case SC_CHASEWALK:
- *option &= ~16388;
- opt_flag = 1;
- break;
-
- case SC_SIGHT:
- *option &= ~1;
- opt_flag = 1;
- break;
- case SC_WEDDING: //çµå©šç”¨(çµå©šè¡£è£³ã«ãªã£ã¦æ­©ãã®ãŒé…ã„ã¨ã‹)
- *option &= ~4096;
- opt_flag = 1;
- break;
- case SC_RUWACH:
- *option &= ~8192;
- opt_flag = 1;
- break;
-
- //opt3
- case SC_TWOHANDQUICKEN: /* 2HQ */
- case SC_SPEARSQUICKEN: /* スピアクイッケン */
- case SC_CONCENTRATION: /* コンセントレーション */
- *opt3 &= ~1;
- break;
- case SC_OVERTHRUST: /* オーãƒãƒ¼ã‚¹ãƒ©ã‚¹ãƒˆ */
- *opt3 &= ~2;
- break;
- case SC_ENERGYCOAT: /* エナジーコート */
- *opt3 &= ~4;
- break;
- case SC_EXPLOSIONSPIRITS: // 爆裂波動
- *opt3 &= ~8;
- break;
- case SC_STEELBODY: // 金剛
- *opt3 &= ~16;
- break;
- case SC_BLADESTOP: /* 白刃å–ã‚Š */
- *opt3 &= ~32;
- break;
- case SC_BERSERK: /* ãƒãƒ¼ã‚µãƒ¼ã‚¯ */
- *opt3 &= ~128;
- break;
- case SC_MARIONETTE: /* マリオãƒãƒƒãƒˆã‚³ãƒ³ãƒˆãƒ­ãƒ¼ãƒ« */
- *opt3 &= ~1024;
- break;
- case SC_ASSUMPTIO: /* アスムプティオ */
- *opt3 &= ~2048;
- break;
- }
-
- if (night_flag == 1 && (*opt2 & STATE_BLIND) == 0
- && bl->type == BL_PC)
- { // by [Yor]
- *opt2 |= STATE_BLIND;
- opt_flag = 1;
- }
-
- if (opt_flag) /* optionã®å¤‰æ›´ã‚’ä¼ãˆã‚‹ */
- clif_changeoption (bl);
-
- if (bl->type == BL_PC && calc_flag)
- pc_calcstatus ((struct map_session_data *) bl, 0); /* ステータスå†è¨ˆç®— */
- }
-
- return 0;
+ if (bl->type == BL::PC && calc_flag)
+ pc_calcstatus((struct map_session_data *) bl, 0); /* ステータスå†è¨ˆç®— */
}
-int skill_update_heal_animation (struct map_session_data *sd)
+int skill_update_heal_animation(struct map_session_data *sd)
{
- const int mask = 0x100;
- int was_active;
- int is_active;
+ const Opt2 mask = Opt2::_heal;
- nullpo_retr (0, sd);
- was_active = sd->opt2 & mask;
- is_active = sd->quick_regeneration_hp.amount > 0;
+ nullpo_ret(sd);
+ bool was_active = bool(sd->opt2 & mask);
+ bool is_active = sd->quick_regeneration_hp.amount > 0;
- if ((was_active && is_active) || (!was_active && !is_active))
+ if (was_active == is_active)
return 0; // no update
if (is_active)
@@ -9463,280 +875,61 @@ int skill_update_heal_animation (struct map_session_data *sd)
else
sd->opt2 &= ~mask;
- return clif_changeoption (&sd->bl);
+ return clif_changeoption(&sd->bl);
}
/*==========================================
* ステータス異常終了タイマー
*------------------------------------------
*/
-void skill_status_change_timer (timer_id tid, tick_t tick, custom_id_t id, custom_data_t data)
+void skill_status_change_timer(TimerData *tid, tick_t tick, int id, StatusChange type)
{
- int type = data;
struct block_list *bl;
struct map_session_data *sd = NULL;
- struct status_change *sc_data;
+ eptr<struct status_change, StatusChange> sc_data;
//short *sc_count; //使ã£ã¦ãªã„?
- if ((bl = map_id2bl (id)) == NULL)
- return; //該当IDãŒã™ã§ã«æ¶ˆæ»…ã—ã¦ã„ã‚‹ã¨ã„ã†ã®ã¯ã„ã‹ã«ã‚‚ã‚ã‚Šãã†ãªã®ã§ã‚¹ãƒ«ãƒ¼ã—ã¦ã¿ã‚‹
- nullpo_retv (sc_data = battle_get_sc_data (bl));
+ if ((bl = map_id2bl(id)) == NULL)
+ return;
+ //該当IDãŒã™ã§ã«æ¶ˆæ»…ã—ã¦ã„ã‚‹ã¨ã„ã†ã®ã¯ã„ã‹ã«ã‚‚ã‚ã‚Šãã†ãªã®ã§ã‚¹ãƒ«ãƒ¼ã—ã¦ã¿ã‚‹
+ sc_data = battle_get_sc_data(bl);
+ if (not sc_data)
+ return;
- if (bl->type == BL_PC)
+ if (bl->type == BL::PC)
sd = (struct map_session_data *) bl;
//sc_count=battle_get_sc_count(bl); //使ã£ã¦ãªã„?
- if (sc_data[type].timer != tid)
- {
- if (battle_config.error_log)
- printf ("skill_status_change_timer %d != %d\n", tid,
- sc_data[type].timer);
- }
-
if (sc_data[type].spell_invocation)
{ // Must report termination
- spell_effect_report_termination (sc_data[type].spell_invocation,
+ spell_effect_report_termination(sc_data[type].spell_invocation,
bl->id, type, 0);
sc_data[type].spell_invocation = 0;
}
switch (type)
- { /* 特殊ãªå‡¦ç†ã«ãªã‚‹å ´åˆ */
- case SC_MAXIMIZEPOWER: /* マキシマイズパワー */
- case SC_CLOAKING: /* クローキング */
- case SC_CHASEWALK:
- if (sd)
- {
- if (sd->status.sp > 0)
- { /* SP切れるã¾ã§æŒç¶š */
- sd->status.sp--;
- clif_updatestatus (sd, SP_SP);
- sc_data[type].timer = add_timer ( /* タイマーå†è¨­å®š */
- sc_data[type].val2 +
- tick,
- skill_status_change_timer,
- bl->id, data);
- return;
- }
- }
- break;
-
- case SC_HIDING: /* ãƒã‚¤ãƒ‡ã‚£ãƒ³ã‚° */
- if (sd)
- { /* SPãŒã‚ã£ã¦ã€æ™‚間制é™ã®é–“ã¯æŒç¶š */
- if (sd->status.sp > 0 && (--sc_data[type].val2) > 0)
- {
- if (sc_data[type].val2 % (sc_data[type].val1 + 3) == 0)
- {
- sd->status.sp--;
- clif_updatestatus (sd, SP_SP);
- }
- sc_data[type].timer = add_timer ( /* タイマーå†è¨­å®š */
- 1000 + tick,
- skill_status_change_timer,
- bl->id, data);
- return;
- }
- }
- break;
-
- case SC_SIGHT: /* サイト */
- {
- const int range = 7;
- map_foreachinarea (skill_status_change_timer_sub,
- bl->m, bl->x - range, bl->y - range,
- bl->x + range, bl->y + range, 0, bl, type,
- tick);
-
- if ((--sc_data[type].val2) > 0)
- {
- sc_data[type].timer = add_timer ( /* タイマーå†è¨­å®š */
- 250 + tick,
- skill_status_change_timer,
- bl->id, data);
- return;
- }
- }
- break;
- case SC_RUWACH: /* ルアフ */
- {
- const int range = 5;
- map_foreachinarea (skill_status_change_timer_sub,
- bl->m, bl->x - range, bl->y - range,
- bl->x + range, bl->y + range, 0, bl, type,
- tick);
-
- if ((--sc_data[type].val2) > 0)
- {
- sc_data[type].timer = add_timer ( /* タイマーå†è¨­å®š */
- 250 + tick,
- skill_status_change_timer,
- bl->id, data);
- return;
- }
- }
- break;
-
- case SC_SIGNUMCRUCIS: /* シグナムクルシス */
- {
- int race = battle_get_race (bl);
- if (race == 6
- || battle_check_undead (race, battle_get_elem_type (bl)))
- {
- sc_data[type].timer =
- add_timer (1000 * 600 + tick, skill_status_change_timer,
- bl->id, data);
- return;
- }
- }
- break;
-
- case SC_PROVOKE: /* プロボック/オートãƒãƒ¼ã‚µãƒ¼ã‚¯ */
- if (sc_data[type].val2 != 0)
- { /* オートãƒãƒ¼ã‚µãƒ¼ã‚¯ï¼ˆï¼‘秒ã”ã¨ã«HPãƒã‚§ãƒƒã‚¯ï¼‰ */
- if (sd && sd->status.hp > sd->status.max_hp >> 2) /* åœæ­¢ */
- break;
- sc_data[type].timer =
- add_timer (1000 + tick, skill_status_change_timer, bl->id,
- data);
- return;
- }
- break;
-
- case SC_WATERBALL: /* ウォーターボール */
- {
- struct block_list *target = map_id2bl (sc_data[type].val2);
- if (target == NULL || target->prev == NULL)
- break;
- skill_attack (BF_MAGIC, bl, bl, target, WZ_WATERBALL,
- sc_data[type].val1, tick, 0);
- if ((--sc_data[type].val3) > 0)
- {
- sc_data[type].timer =
- add_timer (150 + tick, skill_status_change_timer, bl->id,
- data);
- return;
- }
- }
- break;
-
- case SC_ENDURE: /* インデュア */
- if (sd && sd->special_state.infinite_endure)
- {
- sc_data[type].timer =
- add_timer (1000 * 600 + tick, skill_status_change_timer,
- bl->id, data);
- sc_data[type].val2 = 1;
- return;
- }
- break;
-
- case SC_DISSONANCE: /* ä¸å”和音 */
- if ((--sc_data[type].val2) > 0)
- {
- struct skill_unit *unit =
- (struct skill_unit *) sc_data[type].val4;
- struct block_list *src;
-
- if (!unit || !unit->group)
- break;
- src = map_id2bl (unit->group->src_id);
- if (!src)
- break;
- skill_attack (BF_MISC, src, &unit->bl, bl,
- unit->group->skill_id, sc_data[type].val1, tick,
- 0);
- sc_data[type].timer =
- add_timer (skill_get_time2
- (unit->group->skill_id,
- unit->group->skill_lv) + tick,
- skill_status_change_timer, bl->id, data);
- return;
- }
- break;
-
- case SC_LULLABY: /* å­å®ˆå”„ */
- if ((--sc_data[type].val2) > 0)
- {
- struct skill_unit *unit =
- (struct skill_unit *) sc_data[type].val4;
- if (!unit || !unit->group || unit->group->src_id == bl->id)
- break;
- skill_additional_effect (bl, bl, unit->group->skill_id,
- sc_data[type].val1,
- BF_LONG | BF_SKILL | BF_MISC, tick);
- sc_data[type].timer =
- add_timer (skill_get_time
- (unit->group->skill_id,
- unit->group->skill_lv) / 10 + tick,
- skill_status_change_timer, bl->id, data);
- return;
- }
- break;
-
- case SC_STONE:
- if (sc_data[type].val2 != 0)
- {
- short *opt1 = battle_get_opt1 (bl);
- sc_data[type].val2 = 0;
- sc_data[type].val4 = 0;
- battle_stopwalking (bl, 1);
- if (opt1)
- {
- *opt1 = 1;
- clif_changeoption (bl);
- }
- sc_data[type].timer =
- add_timer (1000 + tick, skill_status_change_timer, bl->id,
- data);
- return;
- }
- else if ((--sc_data[type].val3) > 0)
- {
- int hp = battle_get_max_hp (bl);
- if ((++sc_data[type].val4) % 5 == 0
- && battle_get_hp (bl) > hp >> 2)
- {
- hp = hp / 100;
- if (hp < 1)
- hp = 1;
- if (bl->type == BL_PC)
- pc_heal ((struct map_session_data *) bl, -hp, 0);
- else if (bl->type == BL_MOB)
- {
- struct mob_data *md;
- if ((md = ((struct mob_data *) bl)) == NULL)
- break;
- md->hp -= hp;
- }
- }
- sc_data[type].timer =
- add_timer (1000 + tick, skill_status_change_timer, bl->id,
- data);
- return;
- }
- break;
- case SC_POISON:
- if (sc_data[SC_SLOWPOISON].timer == -1)
+ {
+ case StatusChange::SC_POISON:
+ if (!sc_data[StatusChange::SC_SLOWPOISON].timer)
{
const int resist_poison =
- skill_power_bl (bl, TMW_RESIST_POISON) >> 3;
+ skill_power_bl(bl, SkillID::TMW_RESIST_POISON) >> 3;
if (resist_poison)
- sc_data[type].val1 -= MRAND (resist_poison + 1);
+ sc_data[type].val1 -= random_::in(0, resist_poison);
if ((--sc_data[type].val1) > 0)
{
- int hp = battle_get_max_hp (bl);
- if (battle_get_hp (bl) > hp >> 4)
+ int hp = battle_get_max_hp(bl);
+ if (battle_get_hp(bl) > hp >> 4)
{
- if (bl->type == BL_PC)
+ if (bl->type == BL::PC)
{
hp = 3 + hp * 3 / 200;
- pc_heal ((struct map_session_data *) bl, -hp, 0);
+ pc_heal((struct map_session_data *) bl, -hp, 0);
}
- else if (bl->type == BL_MOB)
+ else if (bl->type == BL::MOB)
{
struct mob_data *md;
if ((md = ((struct mob_data *) bl)) == NULL)
@@ -9745,1064 +938,224 @@ void skill_status_change_timer (timer_id tid, tick_t tick, custom_id_t id, custo
md->hp -= hp;
}
}
- sc_data[type].timer =
- add_timer (1000 + tick, skill_status_change_timer,
- bl->id, data);
+ sc_data[type].timer = Timer(tick + std::chrono::seconds(1),
+ std::bind(skill_status_change_timer, ph::_1, ph::_2,
+ bl->id, type));
+ return;
}
}
else
- sc_data[type].timer =
- add_timer (2000 + tick, skill_status_change_timer, bl->id,
- data);
- break;
-
- case SC_TENSIONRELAX: /* テンションリラックス */
- if (sd)
- { /* SPãŒã‚ã£ã¦ã€HPãŒæº€ã‚¿ãƒ³ã§ãªã‘ã‚Œã°ç¶™ç¶š */
- if (sd->status.sp > 12 && sd->status.max_hp > sd->status.hp)
- {
- if (sc_data[type].val2 % (sc_data[type].val1 + 3) == 0)
- {
- sd->status.sp -= 12;
- clif_updatestatus (sd, SP_SP);
- }
- sc_data[type].timer = add_timer ( /* タイマーå†è¨­å®š */
- 10000 + tick,
- skill_status_change_timer,
- bl->id, data);
- return;
- }
- if (sd->status.max_hp <= sd->status.hp)
- skill_status_change_end (&sd->bl, SC_TENSIONRELAX, -1);
+ {
+ sc_data[type].timer = Timer(tick + std::chrono::seconds(2),
+ std::bind(skill_status_change_timer, ph::_1, ph::_2,
+ bl->id, type));
+ return;
}
break;
+ // If you manually reschedule the timer, you MUST skip the
+ // call to skill_status_change_end below.
/* 時間切れ無ã—?? */
- case SC_AETERNA:
- case SC_TRICKDEAD:
- case SC_RIDING:
- case SC_FALCON:
- case SC_WEIGHT50:
- case SC_WEIGHT90:
- case SC_MAGICPOWER: /* 魔法力増幅 */
- case SC_REJECTSWORD: /* リジェクトソード */
- case SC_MEMORIZE: /* メモライズ */
- case SC_BROKNWEAPON:
- case SC_BROKNARMOR:
- if (sc_data[type].timer == tid)
- sc_data[type].timer =
- add_timer (1000 * 600 + tick, skill_status_change_timer,
- bl->id, data);
+ case StatusChange::SC_WEIGHT50:
+ case StatusChange::SC_WEIGHT90:
+ case StatusChange::SC_BROKNWEAPON:
+ case StatusChange::SC_BROKNARMOR:
+ sc_data[type].timer = Timer(tick + std::chrono::minutes(10),
+ std::bind(skill_status_change_timer, ph::_1, ph::_2,
+ bl->id, type));
return;
- case SC_DANCING: //ダンススキルã®æ™‚é–“SP消費
- {
- int s = 0;
- if (sd)
- {
- if (sd->status.sp > 0 && (--sc_data[type].val3) > 0)
- {
- switch (sc_data[type].val1)
- {
- case BD_RICHMANKIM: /* ニヨルドã®å®´ 3秒ã«SP1 */
- case BD_DRUMBATTLEFIELD: /* 戦太鼓ã®éŸ¿ã 3秒ã«SP1 */
- case BD_RINGNIBELUNGEN: /* ニーベルングã®æŒ‡è¼ª 3秒ã«SP1 */
- case BD_SIEGFRIED: /* ä¸æ­»èº«ã®ã‚¸ãƒ¼ã‚¯ãƒ•ãƒªãƒ¼ãƒ‰ 3秒ã«SP1 */
- case BA_DISSONANCE: /* ä¸å”和音 3秒ã§SP1 */
- case BA_ASSASSINCROSS: /* 夕陽ã®ã‚¢ã‚µã‚·ãƒ³ã‚¯ãƒ­ã‚¹ 3秒ã§SP1 */
- case DC_UGLYDANCE: /* 自分å‹æ‰‹ãªãƒ€ãƒ³ã‚¹ 3秒ã§SP1 */
- s = 3;
- break;
- case BD_LULLABY: /* å­å®ˆæ­Œ 4秒ã«SP1 */
- case BD_ETERNALCHAOS: /* æ°¸é ã®æ··æ²Œ 4秒ã«SP1 */
- case BD_ROKISWEIL: /* ロキã®å«ã³ 4秒ã«SP1 */
- case DC_FORTUNEKISS: /* 幸é‹ã®ã‚­ã‚¹ 4秒ã§SP1 */
- s = 4;
- break;
- case BD_INTOABYSS: /* 深淵ã®ä¸­ã« 5秒ã«SP1 */
- case BA_WHISTLE: /* å£ç¬› 5秒ã§SP1 */
- case DC_HUMMING: /* ãƒãƒŸãƒ³ã‚° 5秒ã§SP1 */
- case BA_POEMBRAGI: /* ブラギã®è©© 5秒ã§SP1 */
- case DC_SERVICEFORYOU: /* サービスフォーユー 5秒ã§SP1 */
- s = 5;
- break;
- case BA_APPLEIDUN: /* イドゥンã®æž—檎 6秒ã§SP1 */
- s = 6;
- break;
- case DC_DONTFORGETME: /* ç§ã‚’忘れãªã„ã§â€¦ 10秒ã§SP1 */
- case CG_MOONLIT: /* 月明りã®æ³‰ã«è½ã¡ã‚‹èŠ±ã³ã‚‰ 10秒ã§SP1? */
- s = 10;
- break;
- }
- if (s && ((sc_data[type].val3 % s) == 0))
- {
- sd->status.sp--;
- clif_updatestatus (sd, SP_SP);
- }
- sc_data[type].timer = add_timer ( /* タイマーå†è¨­å®š */
- 1000 + tick,
- skill_status_change_timer,
- bl->id, data);
- return;
- }
- }
- }
- break;
- case SC_BERSERK: /* ãƒãƒ¼ã‚µãƒ¼ã‚¯ */
- if (sd)
- { /* HPãŒ100以上ãªã‚‰ç¶™ç¶š */
- if ((sd->status.hp - sd->status.hp / 100) > 100)
- {
- sd->status.hp -= sd->status.hp / 100;
- clif_updatestatus (sd, SP_HP);
- sc_data[type].timer = add_timer ( /* タイマーå†è¨­å®š */
- 15000 + tick,
- skill_status_change_timer,
- bl->id, data);
- return;
- }
- }
- break;
- case SC_WEDDING: //çµå©šç”¨(çµå©šè¡£è£³ã«ãªã£ã¦æ­©ãã®ãŒé…ã„ã¨ã‹)
- if (sd)
- {
- time_t timer;
- if (time (&timer) < ((sc_data[type].val2) + 3600))
- { //1時間ãŸã£ã¦ã„ãªã„ã®ã§ç¶™ç¶š
- sc_data[type].timer = add_timer ( /* タイマーå†è¨­å®š */
- 10000 + tick,
- skill_status_change_timer,
- bl->id, data);
- return;
- }
- }
- break;
- case SC_NOCHAT: //ãƒãƒ£ãƒƒãƒˆç¦æ­¢çŠ¶æ…‹
- if (sd && battle_config.muting_players)
- {
- time_t timer;
- if ((++sd->status.manner)
- && time (&timer) <
- ((sc_data[type].val2) + 60 * (0 - sd->status.manner)))
- { //開始ã‹ã‚‰status.manner分経ã£ã¦ãªã„ã®ã§ç¶™ç¶š
- clif_updatestatus (sd, SP_MANNER);
- sc_data[type].timer = add_timer ( /* タイマーå†è¨­å®š(60秒) */
- 60000 + tick,
- skill_status_change_timer,
- bl->id, data);
- return;
- }
- }
- break;
- case SC_SELFDESTRUCTION: /* 自爆 */
- if (--sc_data[type].val3 > 0)
- {
- struct mob_data *md;
- if (bl->type == BL_MOB && (md = (struct mob_data *) bl)
- && md->stats[MOB_SPEED] > 250)
- {
- md->stats[MOB_SPEED] -= 250;
- md->next_walktime = tick;
- }
- sc_data[type].timer = add_timer ( /* タイマーå†è¨­å®š */
- 1000 + tick,
- skill_status_change_timer,
- bl->id, data);
- return;
- }
- break;
-
- case SC_FLYING_BACKPACK:
- clif_updatestatus (sd, SP_WEIGHT);
+ case StatusChange::SC_FLYING_BACKPACK:
+ clif_updatestatus(sd, SP::WEIGHT);
break;
}
- skill_status_change_end (bl, type, tid);
-}
-
-/*==========================================
- * ステータス異常終了
- *------------------------------------------
- */
-int skill_encchant_eremental_end (struct block_list *bl, int type)
-{
- struct status_change *sc_data;
-
- nullpo_retr (0, bl);
- nullpo_retr (0, sc_data = battle_get_sc_data (bl));
-
- if (type != SC_ENCPOISON && sc_data[SC_ENCPOISON].timer != -1) /* エンãƒãƒ£ãƒ³ãƒˆãƒã‚¤ã‚ºãƒ³è§£é™¤ */
- skill_status_change_end (bl, SC_ENCPOISON, -1);
- if (type != SC_ASPERSIO && sc_data[SC_ASPERSIO].timer != -1) /* アスペルシオ解除 */
- skill_status_change_end (bl, SC_ASPERSIO, -1);
- if (type != SC_FLAMELAUNCHER && sc_data[SC_FLAMELAUNCHER].timer != -1) /* フレイムランãƒãƒ£è§£é™¤ */
- skill_status_change_end (bl, SC_FLAMELAUNCHER, -1);
- if (type != SC_FROSTWEAPON && sc_data[SC_FROSTWEAPON].timer != -1) /* フロストウェãƒãƒ³è§£é™¤ */
- skill_status_change_end (bl, SC_FROSTWEAPON, -1);
- if (type != SC_LIGHTNINGLOADER && sc_data[SC_LIGHTNINGLOADER].timer != -1) /* ライトニングローダー解除 */
- skill_status_change_end (bl, SC_LIGHTNINGLOADER, -1);
- if (type != SC_SEISMICWEAPON && sc_data[SC_SEISMICWEAPON].timer != -1) /* サイスミックウェãƒãƒ³è§£é™¤ */
- skill_status_change_end (bl, SC_SEISMICWEAPON, -1);
-
- return 0;
+ skill_status_change_end(bl, type, tid);
}
/*==========================================
* ステータス異常開始
*------------------------------------------
*/
-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_start(struct block_list *bl, StatusChange type,
+ int val1,
+ interval_t tick)
{
- return skill_status_effect (bl, type, val1, val2, val3, val4, tick, flag,
- 0);
+ return skill_status_effect(bl, type, val1, tick, 0);
}
-int skill_status_effect (struct block_list *bl, int type, int val1, int val2,
- int val3, int val4, int tick, int flag,
- int spell_invocation)
+int skill_status_effect(struct block_list *bl, StatusChange type,
+ int val1,
+ interval_t tick, int spell_invocation)
{
struct map_session_data *sd = NULL;
- struct status_change *sc_data;
- short *sc_count, *option, *opt1, *opt2, *opt3;
- int opt_flag = 0, calc_flag = 0, updateflag =
- 0, race, mode, elem, undead_flag;
- int scdef = 0;
-
- nullpo_retr (0, bl);
- if (bl->type == BL_SKILL)
- return 0;
- nullpo_retr (0, sc_data = battle_get_sc_data (bl));
- nullpo_retr (0, sc_count = battle_get_sc_count (bl));
- nullpo_retr (0, option = battle_get_option (bl));
- nullpo_retr (0, opt1 = battle_get_opt1 (bl));
- nullpo_retr (0, opt2 = battle_get_opt2 (bl));
- nullpo_retr (0, opt3 = battle_get_opt3 (bl));
-
- race = battle_get_race (bl);
- mode = battle_get_mode (bl);
- elem = battle_get_elem_type (bl);
- undead_flag = battle_check_undead (race, elem);
-
- if (type == SC_AETERNA
- && (sc_data[SC_STONE].timer != -1 || sc_data[SC_FREEZE].timer != -1))
- return 0;
+ eptr<struct status_change, StatusChange> sc_data;
+ short *sc_count;
+ Option *option;
+ Opt1 *opt1;
+ Opt2 *opt2;
+ Opt3 *opt3;
+ int opt_flag = 0, calc_flag = 0;
+ SP updateflag = SP::ZERO;
+ int scdef = 0;
+
+ nullpo_ret(bl);
+ sc_data = battle_get_sc_data(bl);
+ if (not sc_data)
+ return 0;
+ sc_count = battle_get_sc_count(bl);
+ nullpo_ret(sc_count);
+ option = battle_get_option(bl);
+ nullpo_ret(option);
+ opt1 = battle_get_opt1(bl);
+ nullpo_ret(opt1);
+ opt2 = battle_get_opt2(bl);
+ nullpo_ret(opt2);
+ opt3 = battle_get_opt3(bl);
+ nullpo_ret(opt3);
switch (type)
{
- case SC_STONE:
- case SC_FREEZE:
- scdef = 3 + battle_get_mdef (bl) + battle_get_luk (bl) / 3;
- break;
- case SC_STAN:
- case SC_SILENCE:
- case SC_POISON:
- scdef = 3 + battle_get_vit (bl) + battle_get_luk (bl) / 3;
- break;
- case SC_SLEEP:
- case SC_BLIND:
- scdef = 3 + battle_get_int (bl) + battle_get_luk (bl) / 3;
+ case StatusChange::SC_POISON:
+ scdef = 3 + battle_get_vit(bl) + battle_get_luk(bl) / 3;
break;
- case SC_CURSE:
- scdef = 3 + battle_get_luk (bl);
- break;
-
-// case SC_CONFUSION:
- default:
- scdef = 0;
}
if (scdef >= 100)
return 0;
- if (bl->type == BL_PC)
+ if (bl->type == BL::PC)
{
sd = (struct map_session_data *) bl;
- if (sd && type == SC_ADRENALINE
- && !(skill_get_weapontype (BS_ADRENALINE) &
- (1 << sd->status.weapon)))
- return 0;
-
- if (SC_STONE <= type && type <= SC_BLIND)
- { /* カードã«ã‚ˆã‚‹è€æ€§ */
- if (sd && sd->reseff[type - SC_STONE] > 0
- && MRAND (10000) < sd->reseff[type - SC_STONE])
- {
- if (battle_config.battle_log)
- printf ("PC %d skill_sc_start: cardã«ã‚ˆã‚‹ç•°å¸¸è€æ€§ç™ºå‹•\n",
- sd->bl.id);
- return 0;
- }
- }
}
- else if (bl->type == BL_MOB)
+ else if (bl->type == BL::MOB)
{
}
else
{
if (battle_config.error_log)
- printf ("skill_status_change_start: neither MOB nor PC !\n");
+ PRINTF("skill_status_change_start: neither MOB nor PC !\n");
return 0;
}
- if (type == SC_FREEZE && undead_flag && !(flag & 1))
- return 0;
-
- if ((type == SC_ADRENALINE || type == SC_WEAPONPERFECTION
- || type == SC_OVERTHRUST) && sc_data[type].timer != -1
- && sc_data[type].val2 && !val2)
- return 0;
-
- if (mode & 0x20 && (type == SC_STONE || type == SC_FREEZE ||
- type == SC_STAN || type == SC_SLEEP
- || type == SC_SILENCE || type == SC_QUAGMIRE
- || type == SC_DECREASEAGI || type == SC_SIGNUMCRUCIS
- || type == SC_PROVOKE || (type == SC_BLESSING
- && (undead_flag
- || race == 6)))
- && !(flag & 1))
- {
- /* ボスã«ã¯åŠ¹ã‹ãªã„(ãŸã ã—カードã«ã‚ˆã‚‹åŠ¹æžœã¯é©ç”¨ã•ã‚Œã‚‹) */
- return 0;
- }
- if (type == SC_FREEZE || type == SC_STAN || type == SC_SLEEP)
- battle_stopwalking (bl, 1);
-
- if (sc_data[type].timer != -1)
+ if (sc_data[type].timer)
{ /* ã™ã§ã«åŒã˜ç•°å¸¸ã«ãªã£ã¦ã„ã‚‹å ´åˆã‚¿ã‚¤ãƒžè§£é™¤ */
- if (sc_data[type].val1 > val1 && type != SC_COMBO && type != SC_DANCING && type != SC_DEVOTION && type != SC_SPEEDPOTION0 && type != SC_SPEEDPOTION1 && type != SC_SPEEDPOTION2 && type != SC_ATKPOT && type != SC_MATKPOT) // added atk and matk potions [Valaris]
+ if (sc_data[type].val1 > val1
+ && type != StatusChange::SC_SPEEDPOTION0
+ && type != StatusChange::SC_ATKPOT
+ && type != StatusChange::SC_MATKPOT) // added atk and matk potions [Valaris]
return 0;
- if (type >= SC_STAN && type <= SC_BLIND)
- return 0; /* 継ãŽè¶³ã—ãŒã§ããªã„状態異常ã§ã‚る時ã¯çŠ¶æ…‹ç•°å¸¸ã‚’è¡Œã‚ãªã„ */
- if (type == SC_GRAFFITI)
- { //異常中ã«ã‚‚ã†ä¸€åº¦çŠ¶æ…‹ç•°å¸¸ã«ãªã£ãŸæ™‚ã«è§£é™¤ã—ã¦ã‹ã‚‰å†åº¦ã‹ã‹ã‚‹
- skill_status_change_end (bl, type, -1);
- }
- else
+ if (type == StatusChange::SC_POISON)
+ return 0;
+
+ /* 継ãŽè¶³ã—ãŒã§ããªã„状態異常ã§ã‚る時ã¯çŠ¶æ…‹ç•°å¸¸ã‚’è¡Œã‚ãªã„ */
{
(*sc_count)--;
- delete_timer (sc_data[type].timer, skill_status_change_timer);
- sc_data[type].timer = -1;
+ sc_data[type].timer.cancel();
}
}
switch (type)
- { /* 異常ã®ç¨®é¡žã”ã¨ã®å‡¦ç† */
- case SC_PROVOKE: /* プロボック */
- calc_flag = 1;
- if (tick <= 0)
- tick = 1000; /* (オートãƒãƒ¼ã‚µãƒ¼ã‚¯) */
- break;
- case SC_ENDURE: /* インデュア */
- if (tick <= 0)
- tick = 1000 * 60;
- break;
- case SC_CONCENTRATE: /* 集中力å‘上 */
- calc_flag = 1;
- break;
- case SC_BLESSING: /* ブレッシング */
- {
- if (bl->type == BL_PC || (!undead_flag && race != 6))
- {
- if (sc_data[SC_CURSE].timer != -1)
- skill_status_change_end (bl, SC_CURSE, -1);
- if (sc_data[SC_STONE].timer != -1
- && sc_data[SC_STONE].val2 == 0)
- skill_status_change_end (bl, SC_STONE, -1);
- }
- calc_flag = 1;
- }
- break;
- case SC_ANGELUS: /* アンゼルス */
- calc_flag = 1;
- break;
- case SC_INCREASEAGI: /* 速度上昇 */
- calc_flag = 1;
- if (sc_data[SC_DECREASEAGI].timer != -1)
- skill_status_change_end (bl, SC_DECREASEAGI, -1);
- if (sc_data[SC_WINDWALK].timer != -1) /* ウインドウォーク */
- skill_status_change_end (bl, SC_WINDWALK, -1);
- break;
- case SC_DECREASEAGI: /* 速度減少 */
- calc_flag = 1;
- if (sc_data[SC_INCREASEAGI].timer != -1)
- skill_status_change_end (bl, SC_INCREASEAGI, -1);
- break;
- case SC_SIGNUMCRUCIS: /* シグナムクルシス */
- calc_flag = 1;
-// val2 = 14 + val1;
- val2 = 10 + val1 * 2;
- tick = 600 * 1000;
- clif_emotion (bl, 4);
- break;
- case SC_SLOWPOISON:
- if (sc_data[SC_POISON].timer == -1)
+ {
+ /* 異常ã®ç¨®é¡žã”ã¨ã®å‡¦ç† */
+ case StatusChange::SC_SLOWPOISON:
+ if (!sc_data[StatusChange::SC_POISON].timer)
return 0;
break;
- case SC_TWOHANDQUICKEN: /* 2HQ */
- *opt3 |= 1;
- calc_flag = 1;
- break;
- case SC_ADRENALINE: /* アドレナリンラッシュ */
- calc_flag = 1;
- break;
- case SC_WEAPONPERFECTION: /* ウェãƒãƒ³ãƒ‘ーフェクション */
- if (battle_config.party_skill_penaly && !val2)
- tick /= 5;
- break;
- case SC_OVERTHRUST: /* オーãƒãƒ¼ã‚¹ãƒ©ã‚¹ãƒˆ */
- *opt3 |= 2;
- if (battle_config.party_skill_penaly && !val2)
- tick /= 10;
- break;
- case SC_MAXIMIZEPOWER: /* マキシマイズパワー(SPãŒ1減る時間,val2ã«ã‚‚) */
- if (bl->type == BL_PC)
- val2 = tick;
- else
- tick = 5000 * val1;
- break;
- case SC_ENCPOISON: /* エンãƒãƒ£ãƒ³ãƒˆãƒã‚¤ã‚ºãƒ³ */
- calc_flag = 1;
- val2 = (((val1 - 1) / 2) + 3) * 100; /* 毒付与確率 */
- skill_encchant_eremental_end (bl, SC_ENCPOISON);
- break;
- case SC_POISONREACT: /* ãƒã‚¤ã‚ºãƒ³ãƒªã‚¢ã‚¯ãƒˆ */
- break;
- case SC_IMPOSITIO: /* インãƒã‚·ãƒ†ã‚£ã‚ªãƒžãƒŒã‚¹ */
- calc_flag = 1;
- break;
- case SC_ASPERSIO: /* アスペルシオ */
- skill_encchant_eremental_end (bl, SC_ASPERSIO);
- break;
- case SC_SUFFRAGIUM: /* サフラギム */
- case SC_BENEDICTIO: /* è–体 */
- case SC_MAGNIFICAT: /* マグニフィカート */
- case SC_AETERNA: /* エーテルナ */
- break;
- case SC_ENERGYCOAT: /* エナジーコート */
- *opt3 |= 4;
- break;
- case SC_MAGICROD:
- val2 = val1 * 20;
- break;
- case SC_KYRIE: /* キリエエレイソン */
- val2 = battle_get_max_hp (bl) * (val1 * 2 + 10) / 100; /* è€ä¹…度 */
- val3 = (val1 / 2 + 5); /* 回数 */
-// -- moonsoul (added to undo assumptio status if target has it)
- if (sc_data[SC_ASSUMPTIO].timer != -1)
- skill_status_change_end (bl, SC_ASSUMPTIO, -1);
- break;
- case SC_MINDBREAKER:
- calc_flag = 1;
- if (tick <= 0)
- tick = 1000; /* (オートãƒãƒ¼ã‚µãƒ¼ã‚¯) */
- case SC_GLORIA: /* グロリア */
- calc_flag = 1;
- break;
- case SC_LOUD: /* ラウドボイス */
- calc_flag = 1;
- break;
- case SC_TRICKDEAD: /* 死んã ãµã‚Š */
- break;
- case SC_QUAGMIRE: /* クァグマイア */
- calc_flag = 1;
- if (sc_data[SC_CONCENTRATE].timer != -1) /* 集中力å‘上解除 */
- skill_status_change_end (bl, SC_CONCENTRATE, -1);
- if (sc_data[SC_INCREASEAGI].timer != -1) /* 速度上昇解除 */
- skill_status_change_end (bl, SC_INCREASEAGI, -1);
- if (sc_data[SC_TWOHANDQUICKEN].timer != -1)
- skill_status_change_end (bl, SC_TWOHANDQUICKEN, -1);
- if (sc_data[SC_SPEARSQUICKEN].timer != -1)
- skill_status_change_end (bl, SC_SPEARSQUICKEN, -1);
- if (sc_data[SC_ADRENALINE].timer != -1)
- skill_status_change_end (bl, SC_ADRENALINE, -1);
- if (sc_data[SC_LOUD].timer != -1)
- skill_status_change_end (bl, SC_LOUD, -1);
- if (sc_data[SC_TRUESIGHT].timer != -1) /* トゥルーサイト */
- skill_status_change_end (bl, SC_TRUESIGHT, -1);
- if (sc_data[SC_WINDWALK].timer != -1) /* ウインドウォーク */
- skill_status_change_end (bl, SC_WINDWALK, -1);
- if (sc_data[SC_CARTBOOST].timer != -1) /* カートブースト */
- skill_status_change_end (bl, SC_CARTBOOST, -1);
- break;
- case SC_FLAMELAUNCHER: /* フレームランãƒãƒ£ãƒ¼ */
- skill_encchant_eremental_end (bl, SC_FLAMELAUNCHER);
- break;
- case SC_FROSTWEAPON: /* フロストウェãƒãƒ³ */
- skill_encchant_eremental_end (bl, SC_FROSTWEAPON);
- break;
- case SC_LIGHTNINGLOADER: /* ライトニングローダー */
- skill_encchant_eremental_end (bl, SC_LIGHTNINGLOADER);
- break;
- case SC_SEISMICWEAPON: /* サイズミックウェãƒãƒ³ */
- skill_encchant_eremental_end (bl, SC_SEISMICWEAPON);
- break;
- case SC_DEVOTION: /* ディボーション */
- calc_flag = 1;
- break;
- case SC_PROVIDENCE: /* プロヴィデンス */
- calc_flag = 1;
- val2 = val1 * 5;
- break;
- case SC_REFLECTSHIELD:
- val2 = 10 + val1 * 3;
- break;
- case SC_STRIPWEAPON:
- case SC_STRIPSHIELD:
- case SC_STRIPARMOR:
- case SC_STRIPHELM:
- case SC_CP_WEAPON:
- case SC_CP_SHIELD:
- case SC_CP_ARMOR:
- case SC_CP_HELM:
- break;
-
- case SC_AUTOSPELL: /* オートスペル */
- val4 = 5 + val1 * 2;
- break;
-
- case SC_VOLCANO:
- calc_flag = 1;
- val3 = val1 * 10;
- val4 =
- val1 >= 5 ? 20 : (val1 ==
- 4 ? 19 : (val1 ==
- 3 ? 17 : (val1 == 2 ? 14 : 10)));
- break;
- case SC_DELUGE:
- calc_flag = 1;
- val3 =
- val1 >= 5 ? 15 : (val1 ==
- 4 ? 14 : (val1 ==
- 3 ? 12 : (val1 == 2 ? 9 : 5)));
- val4 =
- val1 >= 5 ? 20 : (val1 ==
- 4 ? 19 : (val1 ==
- 3 ? 17 : (val1 == 2 ? 14 : 10)));
- break;
- case SC_VIOLENTGALE:
- calc_flag = 1;
- val3 = val1 * 3;
- val4 =
- val1 >= 5 ? 20 : (val1 ==
- 4 ? 19 : (val1 ==
- 3 ? 17 : (val1 == 2 ? 14 : 10)));
- break;
- case SC_SPEARSQUICKEN: /* スピアクイッケン */
- calc_flag = 1;
- val2 = 20 + val1;
- *opt3 |= 1;
- break;
- case SC_COMBO:
- break;
- case SC_BLADESTOP_WAIT: /* 白刃å–ã‚Š(å¾…ã¡) */
- break;
- case SC_BLADESTOP: /* 白刃å–ã‚Š */
- if (val2 == 2)
- clif_bladestop ((struct block_list *) val3,
- (struct block_list *) val4, 1);
- *opt3 |= 32;
- break;
-
- case SC_LULLABY: /* å­å®ˆå”„ */
- val2 = 11;
- break;
- case SC_RICHMANKIM:
- break;
- case SC_ETERNALCHAOS: /* エターナルカオス */
- calc_flag = 1;
- break;
- case SC_DRUMBATTLE: /* 戦太鼓ã®éŸ¿ã */
- calc_flag = 1;
- val2 = (val1 + 1) * 25;
- val3 = (val1 + 1) * 2;
- break;
- case SC_NIBELUNGEN: /* ニーベルングã®æŒ‡è¼ª */
- calc_flag = 1;
- val2 = (val1 + 2) * 50;
- val3 = (val1 + 2) * 25;
- break;
- case SC_ROKISWEIL: /* ロキã®å«ã³ */
- break;
- case SC_INTOABYSS: /* 深淵ã®ä¸­ã« */
- break;
- case SC_SIEGFRIED: /* ä¸æ­»èº«ã®ã‚¸ãƒ¼ã‚¯ãƒ•ãƒªãƒ¼ãƒ‰ */
+ case StatusChange::SC_SPEEDPOTION0: /* 増速ãƒãƒ¼ã‚·ãƒ§ãƒ³ */
+ *opt2 |= Opt2::_speedpotion0;
calc_flag = 1;
- val2 = 40 + val1 * 5;
- val3 = val1 * 10;
- break;
- case SC_DISSONANCE: /* ä¸å”和音 */
- val2 = 10;
- break;
- case SC_WHISTLE: /* å£ç¬› */
- calc_flag = 1;
- break;
- case SC_ASSNCROS: /* 夕陽ã®ã‚¢ã‚µã‚·ãƒ³ã‚¯ãƒ­ã‚¹ */
- calc_flag = 1;
- break;
- case SC_POEMBRAGI: /* ブラギã®è©© */
- break;
- case SC_APPLEIDUN: /* イドゥンã®æž—檎 */
- calc_flag = 1;
- break;
- case SC_UGLYDANCE: /* 自分å‹æ‰‹ãªãƒ€ãƒ³ã‚¹ */
- val2 = 10;
- break;
- case SC_HUMMING: /* ãƒãƒŸãƒ³ã‚° */
- calc_flag = 1;
- break;
- case SC_DONTFORGETME: /* ç§ã‚’忘れãªã„㧠*/
- calc_flag = 1;
- if (sc_data[SC_INCREASEAGI].timer != -1) /* 速度上昇解除 */
- skill_status_change_end (bl, SC_INCREASEAGI, -1);
- if (sc_data[SC_TWOHANDQUICKEN].timer != -1)
- skill_status_change_end (bl, SC_TWOHANDQUICKEN, -1);
- if (sc_data[SC_SPEARSQUICKEN].timer != -1)
- skill_status_change_end (bl, SC_SPEARSQUICKEN, -1);
- if (sc_data[SC_ADRENALINE].timer != -1)
- skill_status_change_end (bl, SC_ADRENALINE, -1);
- if (sc_data[SC_ASSNCROS].timer != -1)
- skill_status_change_end (bl, SC_ASSNCROS, -1);
- if (sc_data[SC_TRUESIGHT].timer != -1) /* トゥルーサイト */
- skill_status_change_end (bl, SC_TRUESIGHT, -1);
- if (sc_data[SC_WINDWALK].timer != -1) /* ウインドウォーク */
- skill_status_change_end (bl, SC_WINDWALK, -1);
- if (sc_data[SC_CARTBOOST].timer != -1) /* カートブースト */
- skill_status_change_end (bl, SC_CARTBOOST, -1);
- break;
- case SC_FORTUNE: /* 幸é‹ã®ã‚­ã‚¹ */
- calc_flag = 1;
- break;
- case SC_SERVICE4U: /* サービスフォーユー */
- calc_flag = 1;
- break;
- case SC_DANCING: /* ダンス/æ¼”å¥ä¸­ */
- calc_flag = 1;
- val3 = tick / 1000;
- tick = 1000;
- break;
-
- case SC_EXPLOSIONSPIRITS: // 爆裂波動
- calc_flag = 1;
- val2 = 75 + 25 * val1;
- *opt3 |= 8;
- break;
- case SC_STEELBODY: // 金剛
- calc_flag = 1;
- *opt3 |= 16;
- break;
- case SC_EXTREMITYFIST: /* 阿修羅覇凰拳 */
- break;
- case SC_AUTOCOUNTER:
- val3 = val4 = 0;
- break;
-
- case SC_SPEEDPOTION0: /* 増速ãƒãƒ¼ã‚·ãƒ§ãƒ³ */
- *opt2 |= 0x20;
- case SC_SPEEDPOTION1:
- case SC_SPEEDPOTION2:
- calc_flag = 1;
- tick = 1000 * tick;
-// val2 = 5*(2+type-SC_SPEEDPOTION0);
+// val2 = 5*(2+type-StatusChange::SC_SPEEDPOTION0);
break;
/* atk & matk potions [Valaris] */
- case SC_ATKPOT:
- *opt2 |= 0x80;
- case SC_MATKPOT:
- calc_flag = 1;
- tick = 1000 * tick;
- break;
- case SC_WEDDING: //çµå©šç”¨(çµå©šè¡£è£³ã«ãªã£ã¦æ­©ãã®ãŒé…ã„ã¨ã‹)
- {
- time_t timer;
-
+ case StatusChange::SC_ATKPOT:
+ *opt2 |= Opt2::_atkpot;
+ FALLTHROUGH;
+ case StatusChange::SC_MATKPOT:
calc_flag = 1;
- tick = 10000;
- if (!val2)
- val2 = time (&timer);
- }
- break;
- case SC_NOCHAT: //ãƒãƒ£ãƒƒãƒˆç¦æ­¢çŠ¶æ…‹
- {
- time_t timer;
-
- if (!battle_config.muting_players)
- break;
-
- tick = 60000;
- if (!val2)
- val2 = time (&timer);
- updateflag = SP_MANNER;
- }
- break;
- case SC_SELFDESTRUCTION: //自爆
- clif_skillcasting (bl, bl->id, bl->id, 0, 0, 331,
- skill_get_time (val2, val1));
- val3 = tick / 1000;
- tick = 1000;
- break;
-
- /* option1 */
- case SC_STONE: /* 石化 */
- if (!(flag & 2))
- {
- int sc_def = battle_get_mdef (bl) * 200;
- tick = tick - sc_def;
- }
- val3 = tick / 1000;
- if (val3 < 1)
- val3 = 1;
- tick = 5000;
- val2 = 1;
- break;
- case SC_SLEEP: /* ç¡çœ  */
- if (!(flag & 2))
- {
-// int sc_def = 100 - (battle_get_int(bl) + battle_get_luk(bl)/3);
-// tick = tick * sc_def / 100;
-// if(tick < 1000) tick = 1000;
- tick = 30000; //ç¡çœ ã¯ã‚¹ãƒ†ãƒ¼ã‚¿ã‚¹è€æ€§ã«é–¢ã‚らãš30秒
- }
- break;
- case SC_FREEZE: /* å‡çµ */
- if (!(flag & 2))
- {
- int sc_def = 100 - battle_get_mdef (bl);
- tick = tick * sc_def / 100;
- }
- break;
- case SC_STAN: /* スタン(val2ã«ãƒŸãƒªç§’セット) */
- if (!(flag & 2))
- {
- int sc_def =
- 100 - (battle_get_vit (bl) + battle_get_luk (bl) / 3);
- tick = tick * sc_def / 100;
- }
break;
/* option2 */
- case SC_POISON: /* 毒 */
- calc_flag = 1;
- if (!(flag & 2))
- {
- int sc_def =
- 100 - (battle_get_vit (bl) + battle_get_luk (bl) / 5);
- tick = tick * sc_def / 100;
- }
- val3 = tick / 1000;
- if (val3 < 1)
- val3 = 1;
- tick = 1000;
- break;
- case SC_SILENCE: /* 沈黙(レックスデビーナ) */
- if (!(flag & 2))
- {
- int sc_def = 100 - battle_get_vit (bl);
- tick = tick * sc_def / 100;
- }
- break;
- case SC_BLIND: /* æš—é»’ */
- calc_flag = 1;
- if (!(flag & 2))
- {
- int sc_def =
- battle_get_lv (bl) / 10 + battle_get_int (bl) / 15;
- tick = 30000 - sc_def;
- }
- break;
- case SC_CURSE:
+ case StatusChange::SC_POISON: /* 毒 */
calc_flag = 1;
- if (!(flag & 2))
{
- int sc_def = 100 - battle_get_vit (bl);
+ int sc_def =
+ 100 - (battle_get_vit(bl) + battle_get_luk(bl) / 5);
tick = tick * sc_def / 100;
}
- break;
-
- /* option */
- case SC_HIDING: /* ãƒã‚¤ãƒ‡ã‚£ãƒ³ã‚° */
- calc_flag = 1;
- if (bl->type == BL_PC)
- {
- val2 = tick / 1000; /* æŒç¶šæ™‚é–“ */
- tick = 1000;
- }
- break;
- case SC_CHASEWALK:
- case SC_CLOAKING: /* クローキング */
- if (bl->type == BL_PC)
- val2 = tick;
- else
- tick = 5000 * val1;
- break;
- case SC_SIGHT: /* サイト/ルアフ */
- case SC_RUWACH:
- val2 = tick / 250;
- tick = 10;
- break;
-
- /* セーフティウォールã€ãƒ‹ãƒ¥ãƒ¼ãƒž */
- case SC_SAFETYWALL:
- case SC_PNEUMA:
- tick = ((struct skill_unit *) val2)->group->limit;
- break;
-
- /* アンクル */
- case SC_ANKLE:
- break;
-
- /* ウォーターボール */
- case SC_WATERBALL:
- tick = 150;
- if (val1 > 5) //レベルãŒ5以上ã®å ´åˆã¯25発ã«åˆ¶é™(1発目ã¯ã™ã§ã«æ‰“ã£ã¦ã‚‹ã®ã§-1)
- val3 = 5 * 5 - 1;
- else
- val3 = (val1 | 1) * (val1 | 1) - 1;
- break;
-
- /* スキルã˜ã‚ƒãªã„/時間ã«é–¢ä¿‚ã—ãªã„ */
- case SC_RIDING:
- calc_flag = 1;
- tick = 600 * 1000;
- break;
- case SC_FALCON:
- case SC_WEIGHT50:
- case SC_WEIGHT90:
- case SC_BROKNWEAPON:
- case SC_BROKNARMOR:
- tick = 600 * 1000;
- break;
-
- case SC_AUTOGUARD:
- {
- int i, t;
- for (i = val2 = 0; i < val1; i++)
- {
- t = 5 - (i >> 1);
- val2 += (t < 0) ? 1 : t;
- }
- }
- break;
- case SC_DEFENDER:
- calc_flag = 1;
- val2 = 5 + val1 * 15;
+ // huh?
+ tick = std::chrono::seconds(1);
break;
- case SC_KEEPING:
- case SC_BARRIER:
- case SC_HALLUCINATION:
- break;
- case SC_CONCENTRATION: /* コンセントレーション */
- *opt3 |= 1;
- calc_flag = 1;
- break;
- case SC_TENSIONRELAX: /* テンションリラックス */
- calc_flag = 1;
- if (bl->type == BL_PC)
- {
- tick = 10000;
- }
- break;
- case SC_AURABLADE: /* オーラブレード */
- case SC_PARRYING: /* パリイング */
-// case SC_ASSUMPTIO: /* */
- case SC_HEADCRUSH: /* ヘッドクラッシュ */
- case SC_JOINTBEAT: /* ジョイントビート */
-// case SC_MARIONETTE: /* マリオãƒãƒƒãƒˆã‚³ãƒ³ãƒˆãƒ­ãƒ¼ãƒ« */
-
- //ã¨ã‚Šã‚ãˆãšæ‰‹æŠœã
+ case StatusChange::SC_WEIGHT50:
+ case StatusChange::SC_WEIGHT90:
+ case StatusChange::SC_BROKNWEAPON:
+ case StatusChange::SC_BROKNARMOR:
+ tick = std::chrono::minutes(10);
break;
-// -- moonsoul (for new upper class related skill status effects)
-/*
- case SC_AURABLADE:
- val2 = val1*10;
- break;
- case SC_PARRYING:
- val2=val1*3;
- break;
- case SC_CONCENTRATION:
- calc_flag=1;
- val2=val1*10;
- val3=val1*5;
- break;
- case SC_TENSIONRELAX:
-// val2 = 10;
-// val3 = 15;
- break;
- case SC_BERSERK:
- calc_flag=1;
- break;
- case SC_ASSUMPTIO:
- if(sc_data[SC_KYRIE].timer!=-1 )
- skill_status_change_end(bl,SC_KYRIE,-1);
- break;
-*/
- case SC_WINDWALK: /* ウインドウォーク */
+ case StatusChange::SC_HASTE:
calc_flag = 1;
- val2 = (val1 / 2); //Flee上昇率
break;
- case SC_BERSERK: /* ãƒãƒ¼ã‚µãƒ¼ã‚¯ */
- if (sd)
- {
- sd->status.sp = 0;
- clif_updatestatus (sd, SP_SP);
- clif_status_change (bl, SC_INCREASEAGI, 1); /* アイコン表示 */
- }
- *opt3 |= 128;
- tick = 1000;
- calc_flag = 1;
- break;
- case SC_ASSUMPTIO: /* アスムプティオ */
- *opt3 |= 2048;
+ case StatusChange::SC_PHYS_SHIELD:
+ case StatusChange::SC_MBARRIER:
+ case StatusChange::SC_HALT_REGENERATE:
+ case StatusChange::SC_HIDE:
break;
- case SC_MARIONETTE: /* マリオãƒãƒƒãƒˆã‚³ãƒ³ãƒˆãƒ­ãƒ¼ãƒ« */
- *opt3 |= 1024;
- break;
- case SC_MELTDOWN: /* メルトダウン */
- case SC_CARTBOOST: /* カートブースト */
- case SC_TRUESIGHT: /* トゥルーサイト */
- case SC_SPIDERWEB: /* スパイダーウェッブ */
- case SC_MAGICPOWER: /* 魔法力増幅 */
- calc_flag = 1;
- break;
- case SC_REJECTSWORD: /* リジェクトソード */
- val2 = 3; //3回攻撃を跳ã­è¿”ã™
- break;
- case SC_MEMORIZE: /* メモライズ */
- val2 = 3; //3回詠唱を1/3ã«ã™ã‚‹
- break;
- case SC_GRAFFITI: /* グラフィティ */
- {
- struct skill_unit_group *sg =
- skill_unitsetting (bl, RG_GRAFFITI, val1, val2, val3, 0);
- if (sg)
- val4 = (int) sg;
- }
- break;
- case SC_HASTE:
- calc_flag = 1;
- case SC_SPLASHER: /* ベナムスプラッシャー */
- case SC_PHYS_SHIELD:
- case SC_MBARRIER:
- case SC_HALT_REGENERATE:
- case SC_HIDE:
- break;
- case SC_FLYING_BACKPACK:
- updateflag = SP_WEIGHT;
+ case StatusChange::SC_FLYING_BACKPACK:
+ updateflag = SP::WEIGHT;
break;
default:
if (battle_config.error_log)
- printf ("UnknownStatusChange [%d]\n", type);
+ PRINTF("UnknownStatusChange [%d]\n", type);
return 0;
}
- if (bl->type == BL_PC && type < SC_SENDMAX)
- clif_status_change (bl, type, 1); /* アイコン表示 */
+ if (bl->type == BL::PC && type < StatusChange::SC_SENDMAX)
+ clif_status_change(bl, type, 1); /* アイコン表示 */
/* optionã®å¤‰æ›´ */
switch (type)
{
- case SC_STONE:
- case SC_FREEZE:
- case SC_STAN:
- case SC_SLEEP:
- battle_stopattack (bl); /* 攻撃åœæ­¢ */
- skill_stop_dancing (bl, 0); /* æ¼”å¥/ダンスã®ä¸­æ–­ */
- { /* åŒæ™‚ã«æŽ›ã‹ã‚‰ãªã„ステータス異常を解除 */
- int i;
- for (i = SC_STONE; i <= SC_SLEEP; i++)
- {
- if (sc_data[i].timer != -1)
- {
- (*sc_count)--;
- delete_timer (sc_data[i].timer,
- skill_status_change_timer);
- sc_data[i].timer = -1;
- }
- }
- }
- if (type == SC_STONE)
- *opt1 = 6;
- else
- *opt1 = type - SC_STONE + 1;
- opt_flag = 1;
- break;
- case SC_POISON:
- if (sc_data[SC_SLOWPOISON].timer == -1)
+ case StatusChange::SC_POISON:
+ if (!sc_data[StatusChange::SC_SLOWPOISON].timer)
{
- *opt2 |= 0x1;
+ *opt2 |= Opt2::_poison;
opt_flag = 1;
}
break;
- case SC_CURSE:
- case SC_SILENCE:
- case SC_BLIND:
- *opt2 |= 1 << (type - SC_POISON);
- opt_flag = 1;
- break;
- case SC_SLOWPOISON:
- *opt2 &= ~0x1;
- *opt2 |= 0x200;
- opt_flag = 1;
- break;
- case SC_SIGNUMCRUCIS:
- *opt2 |= 0x40;
- opt_flag = 1;
- break;
- case SC_HIDING:
- case SC_CLOAKING:
- battle_stopattack (bl); /* 攻撃åœæ­¢ */
- *option |= ((type == SC_HIDING) ? 2 : 4);
+ case StatusChange::SC_SLOWPOISON:
+ *opt2 &= ~Opt2::_poison;
+ *opt2 |= Opt2::_slowpoison;
opt_flag = 1;
break;
- case SC_CHASEWALK:
- battle_stopattack (bl); /* 攻撃åœæ­¢ */
- *option |= 16388;
- opt_flag = 1;
- break;
- case SC_SIGHT:
- *option |= 1;
- opt_flag = 1;
- break;
- case SC_RUWACH:
- *option |= 8192;
- opt_flag = 1;
- break;
- case SC_WEDDING:
- *option |= 4096;
- opt_flag = 1;
}
if (opt_flag) /* optionã®å¤‰æ›´ */
- clif_changeoption (bl);
+ clif_changeoption(bl);
(*sc_count)++; /* ステータス異常ã®æ•° */
sc_data[type].val1 = val1;
- sc_data[type].val2 = val2;
- sc_data[type].val3 = val3;
- sc_data[type].val4 = val4;
if (sc_data[type].spell_invocation) // Supplant by newer spell
- spell_effect_report_termination (sc_data[type].spell_invocation,
+ spell_effect_report_termination(sc_data[type].spell_invocation,
bl->id, type, 1);
sc_data[type].spell_invocation = spell_invocation;
/* タイマー設定 */
- sc_data[type].timer =
- add_timer (gettick () + tick, skill_status_change_timer, bl->id,
- type);
+ sc_data[type].timer = Timer(gettick() + tick,
+ std::bind(skill_status_change_timer, ph::_1, ph::_2,
+ bl->id, type));
- if (bl->type == BL_PC && calc_flag)
- pc_calcstatus (sd, 0); /* ステータスå†è¨ˆç®— */
+ if (bl->type == BL::PC && calc_flag)
+ pc_calcstatus(sd, 0); /* ステータスå†è¨ˆç®— */
- if (bl->type == BL_PC && updateflag)
- clif_updatestatus (sd, updateflag); /* ステータスをクライアントã«é€ã‚‹ */
+ if (bl->type == BL::PC && updateflag != SP::ZERO)
+ clif_updatestatus(sd, updateflag); /* ステータスをクライアントã«é€ã‚‹ */
return 0;
}
@@ -10811,82 +1164,49 @@ int skill_status_effect (struct block_list *bl, int type, int val1, int val2,
* ステータス異常全解除
*------------------------------------------
*/
-int skill_status_change_clear (struct block_list *bl, int type)
-{
- struct status_change *sc_data;
- short *sc_count, *option, *opt1, *opt2, *opt3;
- int i;
-
- nullpo_retr (0, bl);
- nullpo_retr (0, sc_data = battle_get_sc_data (bl));
- nullpo_retr (0, sc_count = battle_get_sc_count (bl));
- nullpo_retr (0, option = battle_get_option (bl));
- nullpo_retr (0, opt1 = battle_get_opt1 (bl));
- nullpo_retr (0, opt2 = battle_get_opt2 (bl));
- nullpo_retr (0, opt3 = battle_get_opt3 (bl));
+int skill_status_change_clear(struct block_list *bl, int type)
+{
+ eptr<struct status_change, StatusChange> sc_data;
+ short *sc_count;
+ Option *option;
+ Opt1 *opt1;
+ Opt2 *opt2;
+ Opt3 *opt3;
+
+ nullpo_ret(bl);
+ sc_data = battle_get_sc_data(bl);
+ if (not sc_data)
+ return 0;
+ sc_count = battle_get_sc_count(bl);
+ nullpo_ret(sc_count);
+ option = battle_get_option(bl);
+ nullpo_ret(option);
+ opt1 = battle_get_opt1(bl);
+ nullpo_ret(opt1);
+ opt2 = battle_get_opt2(bl);
+ nullpo_ret(opt2);
+ opt3 = battle_get_opt3(bl);
+ nullpo_ret(opt3);
if (*sc_count == 0)
return 0;
- for (i = 0; i < MAX_STATUSCHANGE; i++)
+ for (StatusChange i : erange(StatusChange(), StatusChange::MAX_STATUSCHANGE))
{
- if (sc_data[i].timer != -1)
- { /* 異常ãŒã‚ã‚‹ãªã‚‰ã‚¿ã‚¤ãƒžãƒ¼ã‚’削除ã™ã‚‹ */
-/*
- delete_timer(sc_data[i].timer, skill_status_change_timer);
- sc_data[i].timer = -1;
-
- if (!type && i < SC_SENDMAX)
- clif_status_change(bl, i, 0);
-*/
-
- skill_status_change_end (bl, i, -1);
- }
+ if (sc_data[i].timer)
+ skill_status_change_end(bl, i, nullptr);
}
*sc_count = 0;
- *opt1 = 0;
- *opt2 = 0;
- *opt3 = 0;
- *option &= OPTION_MASK;
-
- if (night_flag == 1 && type == BL_PC) // by [Yor]
- *opt2 |= STATE_BLIND;
+ *opt1 = Opt1::ZERO;
+ *opt2 = Opt2::ZERO;
+ *opt3 = Opt3::ZERO;
+ *option = Option::ZERO;
- if (!type || type & 2)
- clif_changeoption (bl);
+ if (type == 0 || type & 2)
+ clif_changeoption(bl);
return 0;
}
-/* クローキング検査(周りã«ç§»å‹•ä¸å¯èƒ½åœ°å¸¯ãŒã‚ã‚‹ã‹ï¼‰ */
-int skill_check_cloaking (struct block_list *bl)
-{
- struct map_session_data *sd = NULL;
- static int dx[] = { -1, 0, 1, -1, 1, -1, 0, 1 };
- static int dy[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
- int end = 1, i;
-
- nullpo_retr (0, bl);
-
- if (pc_checkskill (sd, AS_CLOAKING) > 2)
- return 0;
- if (bl->type == BL_PC && battle_config.pc_cloak_check_type & 1)
- return 0;
- if (bl->type == BL_MOB && battle_config.monster_cloak_check_type & 1)
- return 0;
- for (i = 0; i < sizeof (dx) / sizeof (dx[0]); i++)
- {
- int c = map_getcell (bl->m, bl->x + dx[i], bl->y + dy[i]);
- if (c == 1 || c == 5)
- end = 0;
- }
- if (end)
- {
- skill_status_change_end (bl, SC_CLOAKING, -1);
- *battle_get_option (bl) &= ~4; /* 念ã®ãŸã‚ã®å‡¦ç† */
- }
- return end;
-}
-
/*
*----------------------------------------------------------------------------
* スキルユニット
@@ -10894,891 +1214,18 @@ int skill_check_cloaking (struct block_list *bl)
*/
/*==========================================
- * æ¼”å¥/ダンススキルã‹ã©ã†ã‹åˆ¤å®š
- * 引数 スキルID
- * 戻り ダンスã˜ã‚ƒãªã„=0 åˆå¥=2 ãれ以外ã®ãƒ€ãƒ³ã‚¹=1
- *------------------------------------------
- */
-int skill_is_danceskill (int id)
-{
- int i;
- switch (id)
- {
- case BD_LULLABY: /* å­å®ˆæ­Œ */
- case BD_RICHMANKIM: /* ニヨルドã®å®´ */
- case BD_ETERNALCHAOS: /* æ°¸é ã®æ··æ²Œ */
- case BD_DRUMBATTLEFIELD: /* 戦太鼓ã®éŸ¿ã */
- case BD_RINGNIBELUNGEN: /* ニーベルングã®æŒ‡è¼ª */
- case BD_ROKISWEIL: /* ロキã®å«ã³ */
- case BD_INTOABYSS: /* 深淵ã®ä¸­ã« */
- case BD_SIEGFRIED: /* ä¸æ­»èº«ã®ã‚¸ãƒ¼ã‚¯ãƒ•ãƒªãƒ¼ãƒ‰ */
- case BD_RAGNAROK: /* 神々ã®é»„æ˜ */
- case CG_MOONLIT: /* 月明りã®æ³‰ã«è½ã¡ã‚‹èŠ±ã³ã‚‰ */
- i = 2;
- break;
- case BA_DISSONANCE: /* ä¸å”和音 */
- case BA_FROSTJOKE: /* 寒ã„ジョーク */
- case BA_WHISTLE: /* å£ç¬› */
- case BA_ASSASSINCROSS: /* 夕陽ã®ã‚¢ã‚µã‚·ãƒ³ã‚¯ãƒ­ã‚¹ */
- case BA_POEMBRAGI: /* ブラギã®è©© */
- case BA_APPLEIDUN: /* イドゥンã®æž—檎 */
- case DC_UGLYDANCE: /* 自分å‹æ‰‹ãªãƒ€ãƒ³ã‚¹ */
- case DC_SCREAM: /* スクリーム */
- case DC_HUMMING: /* ãƒãƒŸãƒ³ã‚° */
- case DC_DONTFORGETME: /* ç§ã‚’忘れãªã„ã§â€¦ */
- case DC_FORTUNEKISS: /* 幸é‹ã®ã‚­ã‚¹ */
- case DC_SERVICEFORYOU: /* サービスフォーユー */
- i = 1;
- break;
- default:
- i = 0;
- }
- return i;
-}
-
-/*==========================================
* æ¼”å¥/ダンスをやã‚ã‚‹
* flag 1ã§åˆå¥ä¸­ãªã‚‰ç›¸æ–¹ã«ãƒ¦ãƒ‹ãƒƒãƒˆã‚’ä»»ã›ã‚‹
*
*------------------------------------------
*/
-void skill_stop_dancing (struct block_list *src, int flag)
-{
- struct status_change *sc_data;
- struct skill_unit_group *group;
-
- nullpo_retv (src);
-
- sc_data = battle_get_sc_data (src);
- if (sc_data && sc_data[SC_DANCING].timer == -1)
- return;
- group = (struct skill_unit_group *) sc_data[SC_DANCING].val2; //ダンスã®ã‚¹ã‚­ãƒ«ãƒ¦ãƒ‹ãƒƒãƒˆIDã¯val2ã«å…¥ã£ã¦ã‚‹
- if (group && src->type == BL_PC && sc_data && sc_data[SC_DANCING].val4)
- { //åˆå¥ä¸­æ–­
- struct map_session_data *dsd = map_id2sd (sc_data[SC_DANCING].val4); //相方ã®sdå–å¾—
- if (flag)
- { //ログアウトãªã©ç‰‡æ–¹ãŒè½ã¡ã¦ã‚‚æ¼”å¥ãŒç¶™ç¶šã•ã‚Œã‚‹
- if (dsd && src->id == group->src_id)
- { //グループをæŒã£ã¦ã‚‹PCãŒè½ã¡ã‚‹
- group->src_id = sc_data[SC_DANCING].val4; //相方ã«ã‚°ãƒ«ãƒ¼ãƒ—ã‚’ä»»ã›ã‚‹
- if (flag & 1) //ログアウト
- dsd->sc_data[SC_DANCING].val4 = 0; //相方ã®ç›¸æ–¹ã‚’0ã«ã—ã¦åˆå¥çµ‚了→通常ã®ãƒ€ãƒ³ã‚¹çŠ¶æ…‹
- if (flag & 2) //ãƒã‚¨é£›ã³ãªã©
- return; //åˆå¥ã‚‚ダンス状態も終了ã•ã›ãªã„&スキルユニットã¯ç½®ã„ã¦ã‘ã¼ã‚Š
- }
- else if (dsd && dsd->bl.id == group->src_id)
- { //相方ãŒã‚°ãƒ«ãƒ¼ãƒ—ã‚’æŒã£ã¦ã„ã‚‹PCãŒè½ã¡ã‚‹(自分ã¯ã‚°ãƒ«ãƒ¼ãƒ—ã‚’æŒã£ã¦ã„ãªã„)
- if (flag & 1) //ログアウト
- dsd->sc_data[SC_DANCING].val4 = 0; //相方ã®ç›¸æ–¹ã‚’0ã«ã—ã¦åˆå¥çµ‚了→通常ã®ãƒ€ãƒ³ã‚¹çŠ¶æ…‹
- if (flag & 2) //ãƒã‚¨é£›ã³ãªã©
- return; //åˆå¥ã‚‚ダンス状態も終了ã•ã›ãªã„&スキルユニットã¯ç½®ã„ã¦ã‘ã¼ã‚Š
- }
- skill_status_change_end (src, SC_DANCING, -1); //自分ã®ã‚¹ãƒ†ãƒ¼ã‚¿ã‚¹ã‚’終了ã•ã›ã‚‹
- //ãã—ã¦ã‚°ãƒ«ãƒ¼ãƒ—ã¯æ¶ˆã•ãªã„&消ã•ãªã„ã®ã§ã‚¹ãƒ†ãƒ¼ã‚¿ã‚¹è¨ˆç®—ã‚‚ã„らãªã„?
- return;
- }
- else
- {
- if (dsd && src->id == group->src_id)
- { //グループをæŒã£ã¦ã‚‹PCãŒæ­¢ã‚ã‚‹
- skill_status_change_end ((struct block_list *) dsd, SC_DANCING, -1); //相手ã®ã‚¹ãƒ†ãƒ¼ã‚¿ã‚¹ã‚’終了ã•ã›ã‚‹
- }
- if (dsd && dsd->bl.id == group->src_id)
- { //相方ãŒã‚°ãƒ«ãƒ¼ãƒ—ã‚’æŒã£ã¦ã„ã‚‹PCãŒæ­¢ã‚ã‚‹(自分ã¯ã‚°ãƒ«ãƒ¼ãƒ—ã‚’æŒã£ã¦ã„ãªã„)
- skill_status_change_end (src, SC_DANCING, -1); //自分ã®ã‚¹ãƒ†ãƒ¼ã‚¿ã‚¹ã‚’終了ã•ã›ã‚‹
- }
- }
- }
- if (flag & 2 && group && src->type == BL_PC)
- { //ãƒã‚¨ã§é£›ã‚“ã ã¨ãã¨ã‹ã¯ãƒ¦ãƒ‹ãƒƒãƒˆã‚‚飛ã¶
- struct map_session_data *sd = (struct map_session_data *) src;
- skill_unit_move_unit_group (group, sd->bl.m, (sd->to_x - sd->bl.x),
- (sd->to_y - sd->bl.y));
- return;
- }
- skill_delunitgroup (group);
- if (src->type == BL_PC)
- pc_calcstatus ((struct map_session_data *) src, 0);
-}
-
-/*==========================================
- * スキルユニットåˆæœŸåŒ–
- *------------------------------------------
- */
-struct skill_unit *skill_initunit (struct skill_unit_group *group, int idx,
- int x, int y)
-{
- struct skill_unit *unit;
-
- nullpo_retr (NULL, group);
- nullpo_retr (NULL, unit = &group->unit[idx]);
-
- if (!unit->alive)
- group->alive_count++;
-
- unit->bl.id = map_addobject (&unit->bl);
- unit->bl.type = BL_SKILL;
- unit->bl.m = group->map;
- unit->bl.x = x;
- unit->bl.y = y;
- unit->group = group;
- unit->val1 = unit->val2 = 0;
- unit->alive = 1;
-
- map_addblock (&unit->bl);
- clif_skill_setunit (unit);
- return unit;
-}
-
-int skill_unit_timer_sub_ondelete (struct block_list *bl, va_list ap);
-/*==========================================
- * スキルユニット削除
- *------------------------------------------
- */
-int skill_delunit (struct skill_unit *unit)
-{
- struct skill_unit_group *group;
- int range;
-
- nullpo_retr (0, unit);
- if (!unit->alive)
- return 0;
- nullpo_retr (0, group = unit->group);
-
- /* onlimitイベント呼ã³å‡ºã— */
- skill_unit_onlimit (unit, gettick ());
-
- /* ondeleteイベント呼ã³å‡ºã— */
- range = group->range;
- map_foreachinarea (skill_unit_timer_sub_ondelete, unit->bl.m,
- unit->bl.x - range, unit->bl.y - range,
- unit->bl.x + range, unit->bl.y + range, 0, &unit->bl,
- gettick ());
-
- clif_skill_delunit (unit);
-
- unit->group = NULL;
- unit->alive = 0;
- map_delobjectnofree (unit->bl.id, BL_SKILL);
- if (group->alive_count > 0 && (--group->alive_count) <= 0)
- skill_delunitgroup (group);
-
- return 0;
-}
-
-/*==========================================
- * スキルユニットグループåˆæœŸåŒ–
- *------------------------------------------
- */
-static int skill_unit_group_newid = 10;
-struct skill_unit_group *skill_initunitgroup (struct block_list *src,
- int count, int skillid,
- int skilllv, int unit_id)
-{
- int i;
- struct skill_unit_group *group = NULL, *list = NULL;
- int maxsug = 0;
-
- nullpo_retr (NULL, src);
-
- if (src->type == BL_PC)
- {
- list = ((struct map_session_data *) src)->skillunit;
- maxsug = MAX_SKILLUNITGROUP;
- }
- else if (src->type == BL_MOB)
- {
- list = ((struct mob_data *) src)->skillunit;
- maxsug = MAX_MOBSKILLUNITGROUP;
- }
- if (list)
- {
- for (i = 0; i < maxsug; i++) /* 空ã„ã¦ã„ã‚‹ã‚‚ã®æ¤œç´¢ */
- if (list[i].group_id == 0)
- {
- group = &list[i];
- break;
- }
-
- if (group == NULL)
- { /* 空ã„ã¦ãªã„ã®ã§å¤ã„ã‚‚ã®æ¤œç´¢ */
- int j = 0;
- unsigned maxdiff = 0, x, tick = gettick ();
- for (i = 0; i < maxsug; i++)
- if ((x = DIFF_TICK (tick, list[i].tick)) > maxdiff)
- {
- maxdiff = x;
- j = i;
- }
- skill_delunitgroup (&list[j]);
- group = &list[j];
- }
- }
-
- if (group == NULL)
- {
- printf ("skill_initunitgroup: error unit group !\n");
- exit (1);
- }
-
- group->src_id = src->id;
- group->party_id = battle_get_party_id (src);
- group->guild_id = battle_get_guild_id (src);
- group->group_id = skill_unit_group_newid++;
- if (skill_unit_group_newid <= 0)
- skill_unit_group_newid = 10;
- CREATE (group->unit, struct skill_unit, count);
- group->unit_count = count;
- group->val1 = group->val2 = 0;
- group->skill_id = skillid;
- group->skill_lv = skilllv;
- group->unit_id = unit_id;
- group->map = src->m;
- group->range = 0;
- group->limit = 10000;
- group->interval = 1000;
- group->tick = gettick ();
- group->valstr = NULL;
-
- if (skill_is_danceskill (skillid))
- {
- struct map_session_data *sd = NULL;
- if (src->type == BL_PC && (sd = (struct map_session_data *) src))
- {
- sd->skillid_dance = skillid;
- sd->skilllv_dance = skilllv;
- }
- skill_status_change_start (src, SC_DANCING, skillid, (int) group, 0,
- 0, skill_get_time (skillid,
- skilllv) + 1000, 0);
- switch (skillid)
- { //åˆå¥ã‚¹ã‚­ãƒ«ã¯ç›¸æ–¹ã‚’ダンス状態ã«ã™ã‚‹
- case BD_LULLABY: /* å­å®ˆæ­Œ */
- case BD_RICHMANKIM: /* ニヨルドã®å®´ */
- case BD_ETERNALCHAOS: /* æ°¸é ã®æ··æ²Œ */
- case BD_DRUMBATTLEFIELD: /* 戦太鼓ã®éŸ¿ã */
- case BD_RINGNIBELUNGEN: /* ニーベルングã®æŒ‡è¼ª */
- case BD_ROKISWEIL: /* ロキã®å«ã³ */
- case BD_INTOABYSS: /* 深淵ã®ä¸­ã« */
- case BD_SIEGFRIED: /* ä¸æ­»èº«ã®ã‚¸ãƒ¼ã‚¯ãƒ•ãƒªãƒ¼ãƒ‰ */
- case BD_RAGNAROK: /* 神々ã®é»„æ˜ */
- case CG_MOONLIT: /* 月明りã®æ³‰ã«è½ã¡ã‚‹èŠ±ã³ã‚‰ */
- {
- int range = 1;
- int c = 0;
- if (sd)
- {
- map_foreachinarea (skill_check_condition_use_sub,
- sd->bl.m, sd->bl.x - range,
- sd->bl.y - range, sd->bl.x + range,
- sd->bl.y + range, BL_PC, &sd->bl, &c);
- }
- }
- }
- }
- return group;
-}
-
-/*==========================================
- * スキルユニットグループ削除
- *------------------------------------------
- */
-int skill_delunitgroup (struct skill_unit_group *group)
-{
- struct block_list *src;
- int i;
-
- nullpo_retr (0, group);
- if (group->unit_count <= 0)
- return 0;
-
- src = map_id2bl (group->src_id);
- if (skill_is_danceskill (group->skill_id))
- { //ダンススキルã¯ãƒ€ãƒ³ã‚¹çŠ¶æ…‹ã‚’解除ã™ã‚‹
- if (src)
- skill_status_change_end (src, SC_DANCING, -1);
- }
-
- group->alive_count = 0;
- if (group->unit != NULL)
- {
- for (i = 0; i < group->unit_count; i++)
- if (group->unit[i].alive)
- skill_delunit (&group->unit[i]);
- }
- if (group->valstr != NULL)
- {
- map_freeblock (group->valstr);
- group->valstr = NULL;
- }
-
- map_freeblock (group->unit); /* free()ã®æ›¿ã‚ã‚Š */
- group->unit = NULL;
- group->src_id = 0;
- group->group_id = 0;
- group->unit_count = 0;
- return 0;
-}
-
-/*==========================================
- * スキルユニットグループ全削除
- *------------------------------------------
- */
-int skill_clear_unitgroup (struct block_list *src)
-{
- struct skill_unit_group *group = NULL;
- int maxsug = 0;
-
- nullpo_retr (0, src);
-
- if (src->type == BL_PC)
- {
- group = ((struct map_session_data *) src)->skillunit;
- maxsug = MAX_SKILLUNITGROUP;
- }
- else if (src->type == BL_MOB)
- {
- group = ((struct mob_data *) src)->skillunit;
- maxsug = MAX_MOBSKILLUNITGROUP;
- }
- if (group)
- {
- int i;
- for (i = 0; i < maxsug; i++)
- if (group[i].group_id > 0 && group[i].src_id == src->id)
- skill_delunitgroup (&group[i]);
- }
- return 0;
-}
-
-/*==========================================
- * スキルユニットグループã®è¢«å½±éŸ¿tick検索
- *------------------------------------------
- */
-struct skill_unit_group_tickset *skill_unitgrouptickset_search (struct
- block_list
- *bl,
- int group_id)
+void skill_stop_dancing(struct block_list *, int)
{
- int i, j = 0, k, s = group_id % MAX_SKILLUNITGROUPTICKSET;
- struct skill_unit_group_tickset *set = NULL;
-
- nullpo_retr (0, bl);
-
- if (bl->type == BL_PC)
- {
- set = ((struct map_session_data *) bl)->skillunittick;
- }
- else
- {
- set = ((struct mob_data *) bl)->skillunittick;
- }
- if (set == NULL)
- return 0;
- for (i = 0; i < MAX_SKILLUNITGROUPTICKSET; i++)
- if (set[(k = (i + s) % MAX_SKILLUNITGROUPTICKSET)].group_id ==
- group_id)
- return &set[k];
- else if (set[k].group_id == 0)
- j = k;
-
- return &set[j];
+ // TODO remove this
}
-/*==========================================
- * スキルユニットグループã®è¢«å½±éŸ¿tick削除
- *------------------------------------------
- */
-int skill_unitgrouptickset_delete (struct block_list *bl, int group_id)
-{
- int i, s = group_id % MAX_SKILLUNITGROUPTICKSET;
- struct skill_unit_group_tickset *set = NULL, *ts;
-
- nullpo_retr (0, bl);
-
- if (bl->type == BL_PC)
- {
- set = ((struct map_session_data *) bl)->skillunittick;
- }
- else
- {
- set = ((struct mob_data *) bl)->skillunittick;
- }
-
- if (set != NULL)
- {
-
- for (i = 0; i < MAX_SKILLUNITGROUPTICKSET; i++)
- if ((ts =
- &set[(i + s) % MAX_SKILLUNITGROUPTICKSET])->group_id ==
- group_id)
- ts->group_id = 0;
-
- }
- return 0;
-}
-
-/*==========================================
- * スキルユニットタイマー発動処ç†ç”¨(foreachinarea)
- *------------------------------------------
- */
-static
-int skill_unit_timer_sub_onplace (struct block_list *bl, va_list ap)
-{
- struct block_list *src;
- struct skill_unit *su;
- unsigned int tick;
-
- nullpo_retr (0, bl);
- nullpo_retr (0, ap);
- src = va_arg (ap, struct block_list *);
-
- tick = va_arg (ap, unsigned int);
- su = (struct skill_unit *) src;
-
- if (su && su->alive)
- {
- struct skill_unit_group *sg;
- sg = su->group;
- if (sg && battle_check_target (src, bl, sg->target_flag) > 0)
- skill_unit_onplace (su, bl, tick);
- }
- return 0;
-}
-
-/*==========================================
- * スキルユニットタイマー削除処ç†ç”¨(foreachinarea)
- *------------------------------------------
- */
-int skill_unit_timer_sub_ondelete (struct block_list *bl, va_list ap)
-{
- struct block_list *src;
- struct skill_unit *su;
- unsigned int tick;
-
- nullpo_retr (0, bl);
- nullpo_retr (0, ap);
- src = va_arg (ap, struct block_list *);
-
- tick = va_arg (ap, unsigned int);
- su = (struct skill_unit *) src;
-
- if (su && su->alive)
- {
- struct skill_unit_group *sg;
- sg = su->group;
- if (sg && battle_check_target (src, bl, sg->target_flag) > 0)
- skill_unit_ondelete (su, bl, tick);
- }
- return 0;
-}
-
-/*==========================================
- * スキルユニットタイマー処ç†ç”¨(foreachobject)
- *------------------------------------------
- */
-static
-int skill_unit_timer_sub (struct block_list *bl, va_list ap)
-{
- struct skill_unit *unit;
- struct skill_unit_group *group;
- int range;
- unsigned int tick;
-
- nullpo_retr (0, bl);
- nullpo_retr (0, ap);
- nullpo_retr (0, unit = (struct skill_unit *) bl);
- nullpo_retr (0, group = unit->group);
- tick = va_arg (ap, unsigned int);
-
- if (!unit->alive)
- return 0;
-
- range = (unit->range != 0) ? unit->range : group->range;
-
- /* onplaceイベント呼ã³å‡ºã— */
- if (unit->alive && unit->range >= 0)
- {
- map_foreachinarea (skill_unit_timer_sub_onplace, bl->m,
- bl->x - range, bl->y - range, bl->x + range,
- bl->y + range, 0, bl, tick);
- if (group->unit_id == 0xaa
- && DIFF_TICK (tick, group->tick) >= 6000 * group->val2)
- {
- map_foreachinarea (skill_idun_heal, bl->m,
- bl->x - range, bl->y - range, bl->x + range,
- bl->y + range, 0, unit);
- group->val2++;
- }
- }
- /* 時間切れ削除 */
- if (unit->alive &&
- (DIFF_TICK (tick, group->tick) >= group->limit
- || DIFF_TICK (tick, group->tick) >= unit->limit))
- {
- switch (group->unit_id)
- {
-
- case 0x8f: /* ブラストマイン */
- group->unit_id = 0x8c;
- clif_changelook (bl, LOOK_BASE, group->unit_id);
- group->limit = DIFF_TICK (tick + 1500, group->tick);
- unit->limit = DIFF_TICK (tick + 1500, group->tick);
- break;
- case 0x90: /* スキッドトラップ */
- case 0x91: /* アンクルスãƒã‚¢ */
- case 0x93: /* ランドマイン */
- case 0x94: /* ショックウェーブトラップ */
- case 0x95: /* サンドマン */
- case 0x96: /* フラッシャー */
- case 0x97: /* フリージングトラップ */
- case 0x98: /* クレイモアートラップ */
- case 0x99: /* トーキーボックス */
- {
- struct block_list *src = map_id2bl (group->src_id);
- if (group->unit_id == 0x91 && group->val2);
- else
- {
- if (src && src->type == BL_PC)
- {
- struct item item_tmp;
- memset (&item_tmp, 0, sizeof (item_tmp));
- item_tmp.nameid = 1065;
- item_tmp.identify = 1;
- map_addflooritem (&item_tmp, 1, bl->m, bl->x, bl->y, NULL, NULL, NULL, 0); // 罠返還
- }
- }
- }
- default:
- skill_delunit (unit);
- }
- }
-
- if (group->unit_id == 0x8d)
- {
- unit->val1 -= 5;
- if (unit->val1 <= 0 && unit->limit + group->tick > tick + 700)
- unit->limit = DIFF_TICK (tick + 700, group->tick);
- }
-
- return 0;
-}
-
-/*==========================================
- * スキルユニットタイマー処ç†
- *------------------------------------------
- */
-static
-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 ();
-}
-
-/*==========================================
- * スキルユニット移動時処ç†ç”¨(foreachinarea)
- *------------------------------------------
- */
-static
-int skill_unit_out_all_sub (struct block_list *bl, va_list ap)
-{
- struct skill_unit *unit;
- struct skill_unit_group *group;
- struct block_list *src;
- int range;
- unsigned int tick;
-
- nullpo_retr (0, bl);
- nullpo_retr (0, ap);
- nullpo_retr (0, src = va_arg (ap, struct block_list *));
- nullpo_retr (0, unit = (struct skill_unit *) bl);
- nullpo_retr (0, group = unit->group);
-
- tick = va_arg (ap, unsigned int);
-
- if (!unit->alive || src->prev == NULL)
- return 0;
-
- range = (unit->range != 0) ? unit->range : group->range;
-
- if (range < 0 || battle_check_target (bl, src, group->target_flag) <= 0)
- return 0;
-
- if (src->x >= bl->x - range && src->x <= bl->x + range &&
- src->y >= bl->y - range && src->y <= bl->y + range)
- skill_unit_onout (unit, src, tick);
-
- return 0;
-}
-
-/*==========================================
- * スキルユニット移動時処ç†
- *------------------------------------------
- */
-int skill_unit_out_all (struct block_list *bl, unsigned int tick, int range)
-{
- nullpo_retr (0, bl);
-
- if (bl->prev == NULL)
- return 0;
-
- if (range < 7)
- range = 7;
- map_foreachinarea (skill_unit_out_all_sub,
- bl->m, bl->x - range, bl->y - range, bl->x + range,
- bl->y + range, BL_SKILL, bl, tick);
-
- return 0;
-}
-
-/*==========================================
- * スキルユニット移動時処ç†ç”¨(foreachinarea)
- *------------------------------------------
- */
-static
-int skill_unit_move_sub (struct block_list *bl, va_list ap)
-{
- struct skill_unit *unit;
- struct skill_unit_group *group;
- struct block_list *src;
- int range;
- unsigned int tick;
-
- nullpo_retr (0, bl);
- nullpo_retr (0, ap);
- nullpo_retr (0, unit = (struct skill_unit *) bl);
- nullpo_retr (0, src = va_arg (ap, struct block_list *));
-
- tick = va_arg (ap, unsigned int);
-
- if (!unit->alive || src->prev == NULL)
- return 0;
-
- if ((group = unit->group) == NULL)
- return 0;
- range = (unit->range != 0) ? unit->range : group->range;
-
- if (range < 0 || battle_check_target (bl, src, group->target_flag) <= 0)
- return 0;
-
- if (src->x >= bl->x - range && src->x <= bl->x + range &&
- src->y >= bl->y - range && src->y <= bl->y + range)
- skill_unit_onplace (unit, src, tick);
- else
- skill_unit_onout (unit, src, tick);
-
- return 0;
-}
-
-/*==========================================
- * スキルユニット移動時処ç†
- *------------------------------------------
- */
-int skill_unit_move (struct block_list *bl, unsigned int tick, int range)
-{
- nullpo_retr (0, bl);
-
- if (bl->prev == NULL)
- return 0;
-
- if (range < 7)
- range = 7;
- map_foreachinarea (skill_unit_move_sub,
- bl->m, bl->x - range, bl->y - range, bl->x + range,
- bl->y + range, BL_SKILL, bl, tick);
-
- return 0;
-}
-
-/*==========================================
- * スキルユニット自体ã®ç§»å‹•æ™‚処ç†(foreachinarea)
- *------------------------------------------
- */
-static
-int skill_unit_move_unit_group_sub (struct block_list *bl, va_list ap)
-{
- struct skill_unit *unit;
- struct skill_unit_group *group;
- struct block_list *src;
- int range;
- unsigned int tick;
-
- nullpo_retr (0, bl);
- nullpo_retr (0, ap);
- nullpo_retr (0, src = va_arg (ap, struct block_list *));
- nullpo_retr (0, unit = (struct skill_unit *) src);
- nullpo_retr (0, group = unit->group);
-
- tick = va_arg (ap, unsigned int);
-
- if (!unit->alive || bl->prev == NULL)
- return 0;
-
- range = (unit->range != 0) ? unit->range : group->range;
-
- if (range < 0 || battle_check_target (src, bl, group->target_flag) <= 0)
- return 0;
- if (bl->x >= src->x - range && bl->x <= src->x + range &&
- bl->y >= src->y - range && bl->y <= src->y + range)
- skill_unit_onplace (unit, bl, tick);
- else
- skill_unit_onout (unit, bl, tick);
- return 0;
-}
-
-/*==========================================
- * スキルユニット自体ã®ç§»å‹•æ™‚処ç†
- * 引数ã¯ã‚°ãƒ«ãƒ¼ãƒ—ã¨ç§»å‹•é‡
- *------------------------------------------
- */
-int skill_unit_move_unit_group (struct skill_unit_group *group, int m, int dx,
- int dy)
-{
- nullpo_retr (0, group);
-
- if (group->unit_count <= 0)
- return 0;
-
- if (group->unit != NULL)
- {
- if (!battle_config.unit_movement_type)
- {
- int i;
- for (i = 0; i < group->unit_count; i++)
- {
- struct skill_unit *unit = &group->unit[i];
- if (unit->alive && !(m == unit->bl.m && dx == 0 && dy == 0))
- {
- int range = unit->range;
- map_delblock (&unit->bl);
- unit->bl.m = m;
- unit->bl.x += dx;
- unit->bl.y += dy;
- map_addblock (&unit->bl);
- clif_skill_setunit (unit);
- if (range > 0)
- {
- if (range < 7)
- range = 7;
- map_foreachinarea (skill_unit_move_unit_group_sub,
- unit->bl.m, unit->bl.x - range,
- unit->bl.y - range,
- unit->bl.x + range,
- unit->bl.y + range, 0, &unit->bl,
- gettick ());
- }
- }
- }
- }
- else
- {
- int i, j, *r_flag, *s_flag, *m_flag;
- struct skill_unit *unit1;
- struct skill_unit *unit2;
- r_flag = (int *) malloc (sizeof (int) * group->unit_count);
- s_flag = (int *) malloc (sizeof (int) * group->unit_count);
- m_flag = (int *) malloc (sizeof (int) * group->unit_count);
- memset (r_flag, 0, sizeof (int) * group->unit_count); // 継承フラグ
- memset (s_flag, 0, sizeof (int) * group->unit_count); // 継承フラグ
- memset (m_flag, 0, sizeof (int) * group->unit_count); // 継承フラグ
-
- //å…ˆã«ãƒ•ãƒ©ã‚°ã‚’全部決ã‚ã‚‹
- for (i = 0; i < group->unit_count; i++)
- {
- int move_check = 0; // ã‹ã¶ã‚Šãƒ•ãƒ©ã‚°
- unit1 = &group->unit[i];
- for (j = 0; j < group->unit_count; j++)
- {
- unit2 = &group->unit[j];
- if (unit1->bl.m == m && unit1->bl.x + dx == unit2->bl.x
- && unit1->bl.y + dy == unit2->bl.y)
- {
- //移動先ã«ãƒ¦ãƒ‹ãƒƒãƒˆãŒã‹ã¶ã£ã¦ãŸã‚‰
- s_flag[i] = 1; // 移動å‰ã®ãƒ¦ãƒ‹ãƒƒãƒˆãƒŠãƒ³ãƒãƒ¼ã®ç¶™æ‰¿ãƒ•ãƒ©ã‚°on
- r_flag[j] = 1; // ã‹ã¶ã‚‹ãƒ¦ãƒ‹ãƒƒãƒˆãƒŠãƒ³ãƒãƒ¼ã®æ®‹ç•™ãƒ•ãƒ©ã‚°on
- move_check = 1; //ユニットãŒã‹ã¶ã£ãŸã€‚
- break;
- }
- }
- if (!move_check) // ユニットãŒã‹ã¶ã£ã¦ãªã‹ã£ãŸã‚‰
- m_flag[i] = 1; // 移動å‰ãƒ¦ãƒ‹ãƒƒãƒˆãƒŠãƒ³ãƒãƒ¼ã®ç§»å‹•ãƒ•ãƒ©ã‚°on
- }
-
- //フラグã«åŸºã¥ã„ã¦ãƒ¦ãƒ‹ãƒƒãƒˆç§»å‹•
- for (i = 0; i < group->unit_count; i++)
- {
- unit1 = &group->unit[i];
- if (m_flag[i])
- { // 移動フラグãŒonã§
- if (!r_flag[i])
- { // 残留フラグãŒoffãªã‚‰
- //å˜ç´”移動(rangeも継承ã®å¿…è¦ç„¡ã—)
- int range = unit1->range;
- map_delblock (&unit1->bl);
- unit1->bl.m = m;
- unit1->bl.x += dx;
- unit1->bl.y += dy;
- map_addblock (&unit1->bl);
- clif_skill_setunit (unit1);
- if (range > 0)
- {
- if (range < 7)
- range = 7;
- map_foreachinarea (skill_unit_move_unit_group_sub,
- unit1->bl.m,
- unit1->bl.x - range,
- unit1->bl.y - range,
- unit1->bl.x + range,
- unit1->bl.y + range, 0,
- &unit1->bl, gettick ());
- }
- }
- else
- { // 残留フラグãŒonãªã‚‰
- //空ユニットã«ãªã‚‹ã®ã§ã€ç¶™æ‰¿å¯èƒ½ãªãƒ¦ãƒ‹ãƒƒãƒˆã‚’探ã™
- for (j = 0; j < group->unit_count; j++)
- {
- unit2 = &group->unit[j];
- if (s_flag[j] && !r_flag[j])
- {
- // 継承移動(range継承付ã)
- int range = unit1->range;
- map_delblock (&unit2->bl);
- unit2->bl.m = m;
- unit2->bl.x = unit1->bl.x + dx;
- unit2->bl.y = unit1->bl.y + dy;
- unit2->range = unit1->range;
- map_addblock (&unit2->bl);
- clif_skill_setunit (unit2);
- if (range > 0)
- {
- if (range < 7)
- range = 7;
- map_foreachinarea
- (skill_unit_move_unit_group_sub,
- unit2->bl.m, unit2->bl.x - range,
- unit2->bl.y - range,
- unit2->bl.x + range,
- unit2->bl.y + range, 0, &unit2->bl,
- gettick ());
- }
- s_flag[j] = 0; // 継承完了ã—ãŸã®ã§off
- break;
- }
- }
- }
- }
- }
- free (r_flag);
- free (s_flag);
- free (m_flag);
- }
- }
- return 0;
-}
+void skill_unit_timer_sub_ondelete(struct block_list *bl,
+ struct block_list *src, unsigned int tick);
/*----------------------------------------------------------------------------
* アイテムåˆæˆ
@@ -11789,26 +1236,26 @@ int skill_unit_move_unit_group (struct skill_unit_group *group, int m, int dx,
* åˆæœŸåŒ–ç³»
*/
-static int scan_stat (char *statname)
-{
- if (!strcasecmp (statname, "str"))
- return SP_STR;
- if (!strcasecmp (statname, "dex"))
- return SP_DEX;
- if (!strcasecmp (statname, "agi"))
- return SP_AGI;
- if (!strcasecmp (statname, "vit"))
- return SP_VIT;
- if (!strcasecmp (statname, "int"))
- return SP_INT;
- if (!strcasecmp (statname, "luk"))
- return SP_LUK;
- if (!strcasecmp (statname, "none"))
- return 0;
-
- else
- fprintf (stderr, "Unknown stat `%s'\n", statname);
- return 0;
+static
+SP scan_stat(char *statname)
+{
+ if (!strcasecmp(statname, "str"))
+ return SP::STR;
+ if (!strcasecmp(statname, "dex"))
+ return SP::DEX;
+ if (!strcasecmp(statname, "agi"))
+ return SP::AGI;
+ if (!strcasecmp(statname, "vit"))
+ return SP::VIT;
+ if (!strcasecmp(statname, "int"))
+ return SP::INT;
+ if (!strcasecmp(statname, "luk"))
+ return SP::LUK;
+ if (!strcasecmp(statname, "none"))
+ return SP::ZERO;
+
+ FPRINTF(stderr, "Unknown stat `%s'\n", statname);
+ return SP::ZERO;
}
/*==========================================
@@ -11818,21 +1265,21 @@ static int scan_stat (char *statname)
*------------------------------------------
*/
static
-int skill_readdb (void)
+int skill_readdb(void)
{
- int i, j, k, l;
+ int j, k;
FILE *fp;
char line[1024], *p;
/* The main skill database */
- memset (skill_db, 0, sizeof (skill_db));
- fp = fopen_ ("db/skill_db.txt", "r");
+ memset(&skill_db, 0, sizeof(skill_db));
+ fp = fopen_("db/skill_db.txt", "r");
if (fp == NULL)
{
- printf ("can't read db/skill_db.txt\n");
+ PRINTF("can't read db/skill_db.txt\n");
return 1;
}
- while (fgets (line, 1020, fp))
+ while (fgets(line, 1020, fp))
{
char *split[50], *split2[MAX_SKILL_LEVEL];
if (line[0] == '/' && line[1] == '/')
@@ -11842,414 +1289,97 @@ int skill_readdb (void)
while (*p == '\t' || *p == ' ')
p++;
split[j] = p;
- p = strchr (p, ',');
+ p = strchr(p, ',');
if (p)
*p++ = 0;
}
if (split[17] == NULL || j < 18)
{
- fprintf (stderr, "Incomplete skill db data online (%d entries)\n",
+ FPRINTF(stderr, "Incomplete skill db data online (%d entries)\n",
j);
continue;
}
- i = atoi (split[0]);
- if (i < 0 || i > MAX_SKILL_DB)
+ SkillID i = SkillID(atoi(split[0]));
+ if (/*i < SkillID() ||*/ i > SkillID::MAX_SKILL_DB)
continue;
- memset (split2, 0, sizeof (split2));
+ memset(split2, 0, sizeof(split2));
for (j = 0, p = split[1]; j < MAX_SKILL_LEVEL && p; j++)
{
split2[j] = p;
- p = strchr (p, ':');
+ p = strchr(p, ':');
if (p)
*p++ = 0;
}
for (k = 0; k < MAX_SKILL_LEVEL; k++)
skill_db[i].range[k] =
- (split2[k]) ? atoi (split2[k]) : atoi (split2[0]);
- skill_db[i].hit = atoi (split[2]);
- skill_db[i].inf = atoi (split[3]);
- skill_db[i].pl = atoi (split[4]);
- skill_db[i].nk = atoi (split[5]);
- skill_db[i].max_raise = atoi (split[6]);
- skill_db[i].max = atoi (split[7]);
-
- memset (split2, 0, sizeof (split2));
+ (split2[k]) ? atoi(split2[k]) : atoi(split2[0]);
+ skill_db[i].hit = atoi(split[2]);
+ skill_db[i].inf = atoi(split[3]);
+ skill_db[i].pl = atoi(split[4]);
+ skill_db[i].nk = atoi(split[5]);
+ skill_db[i].max_raise = atoi(split[6]);
+ skill_db[i].max = atoi(split[7]);
+
+ memset(split2, 0, sizeof(split2));
for (j = 0, p = split[8]; j < MAX_SKILL_LEVEL && p; j++)
{
split2[j] = p;
- p = strchr (p, ':');
+ p = strchr(p, ':');
if (p)
*p++ = 0;
}
for (k = 0; k < MAX_SKILL_LEVEL; k++)
skill_db[i].num[k] =
- (split2[k]) ? atoi (split2[k]) : atoi (split2[0]);
+ (split2[k]) ? atoi(split2[k]) : atoi(split2[0]);
- if (strcasecmp (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 (strcasecmp (split[13], "weapon") == 0)
- skill_db[i].skill_type = BF_WEAPON;
- else if (strcasecmp (split[12], "magic") == 0)
- skill_db[i].skill_type = BF_MAGIC;
- else if (strcasecmp (split[12], "misc") == 0)
- skill_db[i].skill_type = BF_MISC;
- else
- skill_db[i].skill_type = 0;
- memset (split2, 0, sizeof (split2));
- for (j = 0, p = split[14]; j < MAX_SKILL_LEVEL && p; j++)
- {
- split2[j] = p;
- p = strchr (p, ':');
- if (p)
- *p++ = 0;
- }
- for (k = 0; k < MAX_SKILL_LEVEL; k++)
- skill_db[i].blewcount[k] =
- (split2[k]) ? atoi (split2[k]) : atoi (split2[0]);
+ skill_db[i].cast_def_rate = atoi(split[10]);
+ skill_db[i].inf2 = atoi(split[11]);
+ skill_db[i].maxcount = atoi(split[12]);
+ // split[13] was one of: BF::WEAPON, BF::MAGIC, BF::MISC, BF::ZERO
+ memset(split2, 0, sizeof(split2));
+ // split[14] was colon-separated blow counts.
- if (!strcasecmp (split[15], "passive"))
+ if (!strcasecmp(split[15], "passive"))
{
- skill_pool_register (i);
- skill_db[i].poolflags = SKILL_POOL_FLAG;
+ skill_pool_register(i);
+ skill_db[i].poolflags = SkillFlags::POOL_FLAG;
}
- else if (!strcasecmp (split[15], "active"))
+ else if (!strcasecmp(split[15], "active"))
{
- skill_pool_register (i);
- skill_db[i].poolflags = SKILL_POOL_FLAG | SKILL_POOL_ACTIVE;
+ skill_pool_register(i);
+ skill_db[i].poolflags = SkillFlags::POOL_FLAG | SkillFlags::POOL_ACTIVE;
}
else
- skill_db[i].poolflags = 0;
+ skill_db[i].poolflags = SkillFlags::ZERO;
- skill_db[i].stat = scan_stat (split[16]);
+ skill_db[i].stat = scan_stat(split[16]);
- char *tmp = strdup (split[17]);
- skill_names[i].desc = tmp;
- { // replace "_" by " "
+ char *tmp = strdup(split[17]);
+ {
+ // replace "_" by " "
char *s = tmp;
- while ((s = strchr (s, '_')))
+ while ((s = strchr(s, '_')))
*s = ' ';
- if ((s = strchr (tmp, '\t'))
- || (s = strchr (tmp, ' '))
- || (s = strchr (tmp, '\n')))
+ if ((s = strchr(tmp, '\t'))
+ || (s = strchr(tmp, ' '))
+ || (s = strchr(tmp, '\n')))
*s = '\000';
}
+ skill_lookup_by_id(i).desc = tmp;
}
- fclose_ (fp);
- printf ("read db/skill_db.txt done\n");
-
- fp = fopen_ ("db/skill_require_db.txt", "r");
- if (fp == NULL)
- {
- printf ("can't read db/skill_require_db.txt\n");
- return 1;
- }
- while (fgets (line, 1020, fp))
- {
- char *split[51], *split2[MAX_SKILL_LEVEL];
- if (line[0] == '/' && line[1] == '/')
- continue;
- for (j = 0, p = line; j < 30 && p; j++)
- {
- while (*p == '\t' || *p == ' ')
- p++;
- split[j] = p;
- p = strchr (p, ',');
- if (p)
- *p++ = 0;
- }
- if (split[29] == NULL || j < 30)
- continue;
-
- i = atoi (split[0]);
- if (i < 0 || i > MAX_SKILL_DB)
- continue;
-
- memset (split2, 0, sizeof (split2));
- for (j = 0, p = split[1]; j < MAX_SKILL_LEVEL && p; j++)
- {
- split2[j] = p;
- p = strchr (p, ':');
- if (p)
- *p++ = 0;
- }
- for (k = 0; k < MAX_SKILL_LEVEL; k++)
- skill_db[i].hp[k] =
- (split2[k]) ? atoi (split2[k]) : atoi (split2[0]);
-
- memset (split2, 0, sizeof (split2));
- for (j = 0, p = split[2]; j < MAX_SKILL_LEVEL && p; j++)
- {
- split2[j] = p;
- p = strchr (p, ':');
- if (p)
- *p++ = 0;
- }
- for (k = 0; k < MAX_SKILL_LEVEL; k++)
- skill_db[i].mhp[k] =
- (split2[k]) ? atoi (split2[k]) : atoi (split2[0]);
-
- memset (split2, 0, sizeof (split2));
- for (j = 0, p = split[3]; j < MAX_SKILL_LEVEL && p; j++)
- {
- split2[j] = p;
- p = strchr (p, ':');
- if (p)
- *p++ = 0;
- }
- for (k = 0; k < MAX_SKILL_LEVEL; k++)
- skill_db[i].sp[k] =
- (split2[k]) ? atoi (split2[k]) : atoi (split2[0]);
-
- memset (split2, 0, sizeof (split2));
- for (j = 0, p = split[4]; j < MAX_SKILL_LEVEL && p; j++)
- {
- split2[j] = p;
- p = strchr (p, ':');
- if (p)
- *p++ = 0;
- }
- for (k = 0; k < MAX_SKILL_LEVEL; k++)
- skill_db[i].hp_rate[k] =
- (split2[k]) ? atoi (split2[k]) : atoi (split2[0]);
-
- memset (split2, 0, sizeof (split2));
- for (j = 0, p = split[5]; j < MAX_SKILL_LEVEL && p; j++)
- {
- split2[j] = p;
- p = strchr (p, ':');
- if (p)
- *p++ = 0;
- }
- for (k = 0; k < MAX_SKILL_LEVEL; k++)
- skill_db[i].sp_rate[k] =
- (split2[k]) ? atoi (split2[k]) : atoi (split2[0]);
-
- memset (split2, 0, sizeof (split2));
- for (j = 0, p = split[6]; j < MAX_SKILL_LEVEL && p; j++)
- {
- split2[j] = p;
- p = strchr (p, ':');
- if (p)
- *p++ = 0;
- }
- for (k = 0; k < MAX_SKILL_LEVEL; k++)
- skill_db[i].zeny[k] =
- (split2[k]) ? atoi (split2[k]) : atoi (split2[0]);
-
- memset (split2, 0, sizeof (split2));
- for (j = 0, p = split[7]; j < 32 && p; j++)
- {
- split2[j] = p;
- p = strchr (p, ':');
- if (p)
- *p++ = 0;
- }
- for (k = 0; k < 32 && split2[k]; k++)
- {
- l = atoi (split2[k]);
- if (l == 99)
- {
- skill_db[i].weapon = 0xffffffff;
- break;
- }
- else
- skill_db[i].weapon |= 1 << l;
- }
-
- if (strcasecmp (split[8], "hiding") == 0)
- skill_db[i].state = ST_HIDING;
- else if (strcasecmp (split[8], "cloaking") == 0)
- skill_db[i].state = ST_CLOAKING;
- else if (strcasecmp (split[8], "hidden") == 0)
- skill_db[i].state = ST_HIDDEN;
- else if (strcasecmp (split[8], "riding") == 0)
- skill_db[i].state = ST_RIDING;
- else if (strcasecmp (split[8], "falcon") == 0)
- skill_db[i].state = ST_FALCON;
- else if (strcasecmp (split[8], "cart") == 0)
- skill_db[i].state = ST_CART;
- else if (strcasecmp (split[8], "shield") == 0)
- skill_db[i].state = ST_SHIELD;
- else if (strcasecmp (split[8], "sight") == 0)
- skill_db[i].state = ST_SIGHT;
- else if (strcasecmp (split[8], "explosionspirits") == 0)
- skill_db[i].state = ST_EXPLOSIONSPIRITS;
- else if (strcasecmp (split[8], "recover_weight_rate") == 0)
- skill_db[i].state = ST_RECOV_WEIGHT_RATE;
- else if (strcasecmp (split[8], "move_enable") == 0)
- skill_db[i].state = ST_MOVE_ENABLE;
- else if (strcasecmp (split[8], "water") == 0)
- skill_db[i].state = ST_WATER;
- else
- skill_db[i].state = ST_NONE;
-
- memset (split2, 0, sizeof (split2));
- for (j = 0, p = split[9]; j < MAX_SKILL_LEVEL && p; j++)
- {
- split2[j] = p;
- p = strchr (p, ':');
- if (p)
- *p++ = 0;
- }
- for (k = 0; k < MAX_SKILL_LEVEL; k++)
- skill_db[i].spiritball[k] =
- (split2[k]) ? atoi (split2[k]) : atoi (split2[0]);
- skill_db[i].itemid[0] = atoi (split[10]);
- skill_db[i].amount[0] = atoi (split[11]);
- skill_db[i].itemid[1] = atoi (split[12]);
- skill_db[i].amount[1] = atoi (split[13]);
- skill_db[i].itemid[2] = atoi (split[14]);
- skill_db[i].amount[2] = atoi (split[15]);
- skill_db[i].itemid[3] = atoi (split[16]);
- skill_db[i].amount[3] = atoi (split[17]);
- skill_db[i].itemid[4] = atoi (split[18]);
- skill_db[i].amount[4] = atoi (split[19]);
- skill_db[i].itemid[5] = atoi (split[20]);
- skill_db[i].amount[5] = atoi (split[21]);
- skill_db[i].itemid[6] = atoi (split[22]);
- skill_db[i].amount[6] = atoi (split[23]);
- skill_db[i].itemid[7] = atoi (split[24]);
- skill_db[i].amount[7] = atoi (split[25]);
- skill_db[i].itemid[8] = atoi (split[26]);
- skill_db[i].amount[8] = atoi (split[27]);
- skill_db[i].itemid[9] = atoi (split[28]);
- skill_db[i].amount[9] = atoi (split[29]);
- }
- fclose_ (fp);
- printf ("read db/skill_require_db.txt done\n");
-
- /* ? */
- fp = fopen_ ("db/skill_cast_db.txt", "r");
- if (fp == NULL)
- {
- printf ("can't read db/skill_cast_db.txt\n");
- return 1;
- }
- while (fgets (line, 1020, fp))
- {
- char *split[50], *split2[MAX_SKILL_LEVEL];
- memset (split, 0, sizeof (split)); // [Valaris] thanks to fov
- if (line[0] == '/' && line[1] == '/')
- continue;
- for (j = 0, p = line; j < 5 && p; j++)
- {
- while (*p == '\t' || *p == ' ')
- p++;
- split[j] = p;
- p = strchr (p, ',');
- if (p)
- *p++ = 0;
- }
- if (split[4] == NULL || j < 5)
- continue;
-
- i = atoi (split[0]);
- if (i < 0 || i > MAX_SKILL_DB)
- continue;
-
- memset (split2, 0, sizeof (split2));
- for (j = 0, p = split[1]; j < MAX_SKILL_LEVEL && p; j++)
- {
- split2[j] = p;
- p = strchr (p, ':');
- if (p)
- *p++ = 0;
- }
- for (k = 0; k < MAX_SKILL_LEVEL; k++)
- skill_db[i].cast[k] =
- (split2[k]) ? atoi (split2[k]) : atoi (split2[0]);
-
- memset (split2, 0, sizeof (split2));
- for (j = 0, p = split[2]; j < MAX_SKILL_LEVEL && p; j++)
- {
- split2[j] = p;
- p = strchr (p, ':');
- if (p)
- *p++ = 0;
- }
- for (k = 0; k < MAX_SKILL_LEVEL; k++)
- skill_db[i].delay[k] =
- (split2[k]) ? atoi (split2[k]) : atoi (split2[0]);
-
- memset (split2, 0, sizeof (split2));
- for (j = 0, p = split[3]; j < MAX_SKILL_LEVEL && p; j++)
- {
- split2[j] = p;
- p = strchr (p, ':');
- if (p)
- *p++ = 0;
- }
- for (k = 0; k < MAX_SKILL_LEVEL; k++)
- skill_db[i].upkeep_time[k] =
- (split2[k]) ? atoi (split2[k]) : atoi (split2[0]);
-
- memset (split2, 0, sizeof (split2));
- for (j = 0, p = split[4]; j < MAX_SKILL_LEVEL && p; j++)
- {
- split2[j] = p;
- p = strchr (p, ':');
- if (p)
- *p++ = 0;
- }
- for (k = 0; k < MAX_SKILL_LEVEL; k++)
- skill_db[i].upkeep_time2[k] =
- (split2[k]) ? atoi (split2[k]) : atoi (split2[0]);
- }
- fclose_ (fp);
- printf ("read db/skill_cast_db.txt done\n");
-
- fp = fopen_ ("db/skill_castnodex_db.txt", "r");
- if (fp == NULL)
- {
- printf ("can't read db/skill_castnodex_db.txt\n");
- return 1;
- }
- while (fgets (line, 1020, fp))
- {
- char *split[50], *split2[MAX_SKILL_LEVEL];
- memset (split, 0, sizeof (split));
- if (line[0] == '/' && line[1] == '/')
- continue;
- for (j = 0, p = line; j < 2 && p; j++)
- {
- while (*p == '\t' || *p == ' ')
- p++;
- split[j] = p;
- p = strchr (p, ',');
- if (p)
- *p++ = 0;
- }
-
- i = atoi (split[0]);
- if (i < 0 || i > MAX_SKILL_DB)
- continue;
-
- memset (split2, 0, sizeof (split2));
- for (j = 0, p = split[1]; j < MAX_SKILL_LEVEL && p; j++)
- {
- split2[j] = p;
- p = strchr (p, ':');
- if (p)
- *p++ = 0;
- }
- for (k = 0; k < MAX_SKILL_LEVEL; k++)
- skill_db[i].castnodex[k] =
- (split2[k]) ? atoi (split2[k]) : atoi (split2[0]);
- }
- fclose_ (fp);
- printf ("read db/skill_castnodex_db.txt done\n");
+ fclose_(fp);
+ PRINTF("read db/skill_db.txt done\n");
return 0;
}
-void skill_reload (void)
+void skill_reload(void)
{
/*
*
@@ -12258,19 +1388,34 @@ void skill_reload (void)
*
*/
- do_init_skill ();
+ do_init_skill();
}
/*==========================================
* スキル関係åˆæœŸåŒ–処ç†
*------------------------------------------
*/
-int do_init_skill (void)
+int do_init_skill(void)
{
- skill_readdb ();
-
- add_timer_interval (gettick () + SKILLUNITTIMER_INVERVAL,
- skill_unit_timer, 0, 0, SKILLUNITTIMER_INVERVAL);
+ skill_readdb();
return 0;
}
+
+constexpr size_t num_names = sizeof(skill_names) / sizeof(skill_names[0]);
+
+skill_name_db& skill_lookup_by_id(SkillID id)
+{
+ for (skill_name_db& ner : skill_names)
+ if (ner.id == id)
+ return ner;
+ return skill_names[num_names - 1];
+}
+
+skill_name_db& skill_lookup_by_name(const char *name)
+{
+ for (skill_name_db& ner : skill_names)
+ if (!strcasecmp(name, ner.name) || !strcasecmp(name, ner.desc))
+ return ner;
+ return skill_names[num_names - 1];
+}
diff --git a/src/map/skill.hpp b/src/map/skill.hpp
index 3dea4d3..a724781 100644
--- a/src/map/skill.hpp
+++ b/src/map/skill.hpp
@@ -1,892 +1,138 @@
-// $Id: skill.h,v 1.5 2004/09/25 05:32:19 MouseJstr Exp $
#ifndef SKILL_HPP
#define SKILL_HPP
-#include "../common/timer.hpp"
+#include "skill.t.hpp"
#include "map.hpp"
-#include "magic.hpp"
-#define MAX_SKILL_DB 450
-#define MAX_SKILL_PRODUCE_DB 150
-#define MAX_SKILL_ARROW_DB 150
-#define MAX_SKILL_ABRA_DB 350
-
-#define SKILL_POOL_FLAG 0x1 // is a pool skill
-#define SKILL_POOL_ACTIVE 0x2 // is an active pool skill
-#define SKILL_POOL_ACTIVATED 0x4 // pool skill has been activated (used for clif)
+constexpr int MAX_SKILL_PRODUCE_DB = 150;
+constexpr int MAX_SKILL_ARROW_DB = 150;
+constexpr int MAX_SKILL_ABRA_DB = 350;
// スキルデータベース
struct skill_db
{
- int range[MAX_SKILL_LEVEL], hit, inf, pl, nk, max, stat, poolflags, max_raise; // `max' is the global max, `max_raise' is the maximum attainable via skill-ups
- int num[MAX_SKILL_LEVEL];
- int cast[MAX_SKILL_LEVEL], delay[MAX_SKILL_LEVEL];
- int upkeep_time[MAX_SKILL_LEVEL], upkeep_time2[MAX_SKILL_LEVEL];
- int castcancel, cast_def_rate;
- int inf2, maxcount, skill_type;
- int blewcount[MAX_SKILL_LEVEL];
- int hp[MAX_SKILL_LEVEL], sp[MAX_SKILL_LEVEL], mhp[MAX_SKILL_LEVEL],
+ int range[MAX_SKILL_LEVEL], hit, inf, pl, nk, max;
+ SP stat;
+ SkillFlags poolflags;
+ int max_raise; // `max' is the global max, `max_raise' is the maximum attainable via skill-ups
+ int num[MAX_SKILL_LEVEL];
+ int cast[MAX_SKILL_LEVEL], delay[MAX_SKILL_LEVEL];
+ int upkeep_time[MAX_SKILL_LEVEL], upkeep_time2[MAX_SKILL_LEVEL];
+ int castcancel, cast_def_rate;
+ int inf2, maxcount;
+ int hp[MAX_SKILL_LEVEL], sp[MAX_SKILL_LEVEL], mhp[MAX_SKILL_LEVEL],
hp_rate[MAX_SKILL_LEVEL], sp_rate[MAX_SKILL_LEVEL],
zeny[MAX_SKILL_LEVEL];
- int weapon, state, spiritball[MAX_SKILL_LEVEL];
- int itemid[10], amount[10];
- int castnodex[MAX_SKILL_LEVEL];
+ int weapon;
+ int itemid[10], amount[10];
+ int castnodex[MAX_SKILL_LEVEL];
};
-extern struct skill_db skill_db[MAX_SKILL_DB];
+extern earray<struct skill_db, SkillID, SkillID::MAX_SKILL_DB> skill_db;
struct skill_name_db
{
- int id; // skill id
+ SkillID id; // skill id
const char *name; // search strings
const char *desc; // description that shows up for search's
};
+
+// used only by @skillid for iteration - should be depublicized
extern struct skill_name_db skill_names[];
+skill_name_db& skill_lookup_by_id(SkillID id);
+skill_name_db& skill_lookup_by_name(const char *name);
+
struct block_list;
struct map_session_data;
-struct skill_unit;
-struct skill_unit_group;
-int do_init_skill (void);
+int do_init_skill(void);
// スキルデータベースã¸ã®ã‚¢ã‚¯ã‚»ã‚µ
-int skill_get_hit (int id);
-int skill_get_inf (int id);
-int skill_get_pl (int id);
-int skill_get_nk (int id);
-int skill_get_max (int id);
-int skill_get_max_raise (int id);
-int skill_get_range (int id, int lv);
-int skill_get_hp (int id, int lv);
-int skill_get_mhp (int id, int lv);
-int skill_get_sp (int id, int lv);
-int skill_get_zeny (int id, int lv);
-int skill_get_num (int id, int lv);
-int skill_get_cast (int id, int lv);
-int skill_get_delay (int id, int lv);
-int skill_get_time (int id, int lv);
-int skill_get_time2 (int id, int lv);
-int skill_get_castdef (int id);
-int skill_get_weapontype (int id);
-int skill_get_unit_id (int id, int flag);
-int skill_get_inf2 (int id);
-int skill_get_maxcount (int id);
-int skill_get_blewcount (int id, int lv);
-
-// スキルã®ä½¿ç”¨
-int skill_use_id (struct map_session_data *sd, int target_id,
- int skill_num, int skill_lv);
-int skill_use_pos (struct map_session_data *sd,
- int skill_x, int skill_y, int skill_num, int skill_lv);
-
-int skill_castend_map (struct map_session_data *sd, int skill_num,
- const char *map);
-
-int skill_cleartimerskill (struct block_list *src);
-int skill_addtimerskill (struct block_list *src, unsigned int tick,
- int target, int x, int y, int skill_id,
- int skill_lv, int type, int flag);
+int skill_get_hit(SkillID id);
+int skill_get_inf(SkillID id);
+int skill_get_nk(SkillID id);
+int skill_get_max(SkillID id);
+int skill_get_max_raise(SkillID id);
+int skill_get_range(SkillID id, int lv);
+int skill_get_sp(SkillID id, int lv);
+int skill_get_num(SkillID id, int lv);
+int skill_get_cast(SkillID id, int lv);
+int skill_get_delay(SkillID id, int lv);
+int skill_get_inf2(SkillID id);
+int skill_get_maxcount(SkillID id);
// 追加効果
-int skill_additional_effect (struct block_list *src, struct block_list *bl,
- int skillid, int skilllv, int attack_type,
- unsigned int tick);
-
-// ユニットスキル
-struct skill_unit *skill_initunit (struct skill_unit_group *group, int idx,
- int x, int y);
-int skill_delunit (struct skill_unit *unit);
-struct skill_unit_group *skill_initunitgroup (struct block_list *src,
- int count, int skillid,
- int skilllv, int unit_id);
-int skill_delunitgroup (struct skill_unit_group *group);
-struct skill_unit_group_tickset *skill_unitgrouptickset_search (struct
- block_list
- *bl,
- int group_id);
-int skill_unitgrouptickset_delete (struct block_list *bl, int group_id);
-int skill_clear_unitgroup (struct block_list *src);
+int skill_additional_effect(struct block_list *src, struct block_list *bl,
+ SkillID skillid, int skilllv);
-int skill_unit_ondamaged (struct skill_unit *src, struct block_list *bl,
- int damage, unsigned int tick);
+interval_t skill_castfix(struct block_list *bl, interval_t time);
+interval_t skill_delayfix(struct block_list *bl, interval_t time);
-int skill_castfix (struct block_list *bl, int time);
-int skill_delayfix (struct block_list *bl, int time);
-int skill_check_unit_range (int m, int x, int y, int range, int skillid);
-int skill_check_unit_range2 (int m, int x, int y, int range);
-// -- moonsoul (added skill_check_unit_cell)
-int skill_check_unit_cell (int skillid, int m, int x, int y, int unit_id);
-int skill_unit_out_all (struct block_list *bl, unsigned int tick, int range);
-int skill_unit_move (struct block_list *bl, unsigned int tick, int range);
-int skill_unit_move_unit_group (struct skill_unit_group *group, int m,
- int dx, int dy);
-
-struct skill_unit_group *skill_check_dancing (struct block_list *src);
-void skill_stop_dancing (struct block_list *src, int flag);
+void skill_stop_dancing(struct block_list *src, int flag);
// 詠唱キャンセル
-int skill_castcancel (struct block_list *bl, int type);
-
-int skill_gangsterparadise (struct map_session_data *sd, int type);
-void skill_brandishspear_first (struct square *tc, int dir, int x, int y);
-void skill_brandishspear_dir (struct square *tc, int dir, int are);
-int skill_autospell (struct map_session_data *md, int skillid);
-void skill_devotion (struct map_session_data *md, int target);
-void skill_devotion2 (struct block_list *bl, int crusader);
-int skill_devotion3 (struct block_list *bl, int target);
-void skill_devotion_end (struct map_session_data *md,
- struct map_session_data *sd, int target);
+int skill_castcancel(struct block_list *bl, int type);
-#define skill_calc_heal(bl,skill_lv) (( battle_get_lv(bl)+battle_get_int(bl) )/8 *(4+ skill_lv*8))
-
-// ãã®ä»–
-int skill_check_cloaking (struct block_list *bl);
-int skill_is_danceskill (int id);
+int skill_gangsterparadise(struct map_session_data *sd, int type);
+void skill_devotion(struct map_session_data *md, int target);
+int skill_devotion3(struct block_list *bl, int target);
// ステータス異常
-int skill_status_effect (struct block_list *bl, int type, int val1, int val2,
- int val3, int val4, int tick, int flag,
- int spell_invocation);
-int skill_status_change_start (struct block_list *bl, int type, int val1,
- int val2, int val3, int val4, int tick,
- int flag);
-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);
-int skill_status_change_clear (struct block_list *bl, int type);
+int skill_status_effect(struct block_list *bl, StatusChange type,
+ int val1,
+ interval_t tick, int spell_invocation);
+int skill_status_change_start(struct block_list *bl, StatusChange type,
+ int val1,
+ interval_t tick);
+int skill_status_change_active(struct block_list *bl, StatusChange type); // [fate]
+void skill_status_change_end(struct block_list *bl, StatusChange type, TimerData *tid);
+int skill_status_change_clear(struct block_list *bl, int type);
// mobスキルã®ãŸã‚
-int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl,
- int skillid, int skilllv, unsigned int tick,
- int flag);
-int skill_castend_damage_id (struct block_list *src, struct block_list *bl,
- int skillid, int skilllv, unsigned int tick,
- int flag);
-int skill_castend_pos2 (struct block_list *src, int x, int y, int skillid,
- int skilllv, unsigned int tick, int flag);
-
-// スキル攻撃一括処ç†
-int skill_attack (int attack_type, struct block_list *src,
- struct block_list *dsrc, struct block_list *bl,
- int skillid, int skilllv, unsigned int tick, int flag);
-
-int skill_update_heal_animation (struct map_session_data *sd); // [Fate] Check whether the healing flag must be updated, do so if needed
-
-void skill_reload (void);
-
-enum
-{
- ST_NONE, ST_HIDING, ST_CLOAKING, ST_HIDDEN, ST_RIDING, ST_FALCON, ST_CART,
- ST_SHIELD, ST_SIGHT, ST_EXPLOSIONSPIRITS,
- ST_RECOV_WEIGHT_RATE, ST_MOVE_ENABLE, ST_WATER,
-};
-
-enum
-{ // struct map_session_data ã® status_changeã®ç•ªå·ãƒ†ãƒ¼ãƒ–ル
- SC_SENDMAX = 256,
- SC_PROVOKE = 0,
- SC_ENDURE = 1,
- SC_TWOHANDQUICKEN = 2,
- SC_CONCENTRATE = 3,
- SC_HIDING = 4,
- SC_CLOAKING = 5,
- SC_ENCPOISON = 6,
- SC_POISONREACT = 7,
- SC_QUAGMIRE = 8,
- SC_ANGELUS = 9,
- SC_BLESSING = 10,
- SC_SIGNUMCRUCIS = 11,
- SC_INCREASEAGI = 12,
- SC_DECREASEAGI = 13,
- SC_SLOWPOISON = 14,
- SC_IMPOSITIO = 15,
- SC_SUFFRAGIUM = 16,
- SC_ASPERSIO = 17,
- SC_BENEDICTIO = 18,
- SC_KYRIE = 19,
- SC_MAGNIFICAT = 20,
- SC_GLORIA = 21,
- SC_AETERNA = 22,
- SC_ADRENALINE = 23,
- SC_WEAPONPERFECTION = 24,
- SC_OVERTHRUST = 25,
- SC_MAXIMIZEPOWER = 26,
- SC_RIDING = 27,
- SC_FALCON = 28,
- SC_TRICKDEAD = 29,
- SC_LOUD = 30,
- SC_ENERGYCOAT = 31,
- SC_BROKNARMOR = 32,
- SC_BROKNWEAPON = 33,
- SC_HALLUCINATION = 34,
- SC_WEIGHT50 = 35,
- SC_WEIGHT90 = 36,
- SC_SPEEDPOTION0 = 37,
- SC_SPEEDPOTION1 = 38,
- SC_SPEEDPOTION2 = 39,
-
- SC_STRIPWEAPON = 50,
- SC_STRIPSHIELD = 51,
- SC_STRIPARMOR = 52,
- SC_STRIPHELM = 53,
- SC_CP_WEAPON = 54,
- SC_CP_SHIELD = 55,
- SC_CP_ARMOR = 56,
- SC_CP_HELM = 57,
- SC_AUTOGUARD = 58,
- SC_REFLECTSHIELD = 59,
- SC_DEVOTION = 60,
- SC_PROVIDENCE = 61,
- SC_DEFENDER = 62,
- SC_AUTOSPELL = 65,
- SC_EXPLOSIONSPIRITS = 86,
- SC_STEELBODY = 87,
- SC_SPEARSQUICKEN = 68,
-
- SC_HEALING = 70,
-
- SC_SIGHTTRASHER = 73,
-
- SC_COMBO = 89,
- SC_FLAMELAUNCHER = 90,
- SC_FROSTWEAPON = 91,
- SC_LIGHTNINGLOADER = 92,
- SC_SEISMICWEAPON = 93,
-
- SC_AURABLADE = 103,
- SC_PARRYING = 104,
- SC_CONCENTRATION = 105,
- SC_TENSIONRELAX = 106,
- SC_BERSERK = 107,
-
- SC_ASSUMPTIO = 110,
-
- SC_MAGICPOWER = 113,
-
- SC_TRUESIGHT = 115,
- SC_WINDWALK = 116,
- SC_MELTDOWN = 117,
- SC_CARTBOOST = 118,
-
- SC_REJECTSWORD = 120,
- SC_MARIONETTE = 121,
-
- SC_HEADCRUSH = 124,
- SC_JOINTBEAT = 125,
- SC_BASILICA = 125,
-
- SC_STONE = 128,
- SC_FREEZE = 129,
- SC_STAN = 130,
- SC_SLEEP = 131,
- SC_POISON = 132,
- SC_CURSE = 133,
- SC_SILENCE = 134,
- SC_CONFUSION = 135,
- SC_BLIND = 136,
-
- SC_SAFETYWALL = 140,
- SC_PNEUMA = 141,
- SC_WATERBALL = 142,
- SC_ANKLE = 143,
- SC_DANCING = 144,
- SC_KEEPING = 145,
- SC_BARRIER = 146,
-
- SC_MAGICROD = 149,
- SC_SIGHT = 150,
- SC_RUWACH = 151,
- SC_AUTOCOUNTER = 152,
- SC_VOLCANO = 153,
- SC_DELUGE = 154,
- SC_VIOLENTGALE = 155,
- SC_BLADESTOP_WAIT = 156,
- SC_BLADESTOP = 157,
- SC_EXTREMITYFIST = 158,
- SC_GRAFFITI = 159,
- SC_ENSEMBLE = 159,
-
- SC_LULLABY = 160,
- SC_RICHMANKIM = 161,
- SC_ETERNALCHAOS = 162,
- SC_DRUMBATTLE = 163,
- SC_NIBELUNGEN = 164,
- SC_ROKISWEIL = 165,
- SC_INTOABYSS = 166,
- SC_SIEGFRIED = 167,
- SC_DISSONANCE = 168,
- SC_WHISTLE = 169,
- SC_ASSNCROS = 170,
- SC_POEMBRAGI = 171,
- SC_APPLEIDUN = 172,
- SC_UGLYDANCE = 173,
- SC_HUMMING = 174,
- SC_DONTFORGETME = 175,
- SC_FORTUNE = 176,
- SC_SERVICE4U = 177,
- SC_FOGWALL = 178,
- SC_GOSPEL = 179,
- SC_SPIDERWEB = 180,
- SC_MEMORIZE = 181,
- SC_LANDPROTECTOR = 182,
- SC_ADAPTATION = 183,
- SC_CHASEWALK = 184,
- SC_ATKPOT = 185,
- SC_MATKPOT = 186,
- SC_WEDDING = 187,
- SC_NOCHAT = 188,
- SC_SPLASHER = 189,
- SC_SELFDESTRUCTION = 190,
- SC_MINDBREAKER = 191,
- SC_SPELLBREAKER = 192,
-
-// Added for Fate's spells
- SC_HIDE = 194, // Hide from `detect' magic
- SC_HALT_REGENERATE = 195, // Suspend regeneration
- SC_FLYING_BACKPACK = 196, // Flying backpack
- SC_MBARRIER = 197, // Magical barrier, magic resistance (val1 : power (%))
- SC_HASTE = 198, // `Haste' spell (val1 : power)
- SC_PHYS_SHIELD = 199, // `Protect' spell, reduce damage (val1: power)
-
- SC_DIVINA = SC_SILENCE,
-};
-extern int SkillStatusChangeTable[];
+int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl,
+ SkillID skillid, int skilllv);
+int skill_castend_damage_id(struct block_list *src, struct block_list *bl,
+ SkillID skillid, int skilllv, tick_t tick,
+ BCT flag);
-enum
-{
- NV_EMOTE = 1,
- NV_TRADE,
- NV_PARTY,
-
- SM_SWORD,
- SM_TWOHAND,
- SM_RECOVERY,
- SM_BASH,
- SM_PROVOKE,
- SM_MAGNUM,
- SM_ENDURE,
-
- MG_SRECOVERY,
- MG_SIGHT,
- MG_NAPALMBEAT,
- MG_SAFETYWALL,
- MG_SOULSTRIKE,
- MG_COLDBOLT,
- MG_FROSTDIVER,
- MG_STONECURSE,
- MG_FIREBALL,
- MG_FIREWALL,
- MG_FIREBOLT,
- MG_LIGHTNINGBOLT,
- MG_THUNDERSTORM,
-
- AL_DP,
- AL_DEMONBANE,
- AL_RUWACH,
- AL_PNEUMA,
- AL_TELEPORT,
- AL_WARP,
- AL_HEAL,
- AL_INCAGI,
- AL_DECAGI,
- AL_HOLYWATER,
- AL_CRUCIS,
- AL_ANGELUS,
- AL_BLESSING,
- AL_CURE,
-
- MC_INCCARRY,
- MC_DISCOUNT,
- MC_OVERCHARGE,
- MC_PUSHCART,
- MC_IDENTIFY,
- MC_VENDING,
- MC_MAMMONITE,
-
- AC_OWL = 45,
- AC_VULTURE,
- AC_CONCENTRATION,
- AC_DOUBLE,
- AC_SHOWER,
-
- TF_DOUBLE,
- TF_MISS,
- TF_STEAL,
- TF_HIDING,
- TF_POISON,
- TF_DETOXIFY,
-
- ALL_RESURRECTION,
-
- KN_SPEARMASTERY,
- KN_PIERCE,
- KN_BRANDISHSPEAR,
- KN_SPEARSTAB,
- KN_SPEARBOOMERANG,
- KN_TWOHANDQUICKEN,
- KN_AUTOCOUNTER,
- KN_BOWLINGBASH,
- KN_RIDING,
- KN_CAVALIERMASTERY,
-
- PR_MACEMASTERY,
- PR_IMPOSITIO,
- PR_SUFFRAGIUM,
- PR_ASPERSIO,
- PR_BENEDICTIO,
- PR_SANCTUARY,
- PR_SLOWPOISON,
- PR_STRECOVERY,
- PR_KYRIE,
- PR_MAGNIFICAT,
- PR_GLORIA,
- PR_LEXDIVINA,
- PR_TURNUNDEAD,
- PR_LEXAETERNA,
- PR_MAGNUS,
-
- WZ_FIREPILLAR,
- WZ_SIGHTRASHER,
- WZ_FIREIVY,
- WZ_METEOR,
- WZ_JUPITEL,
- WZ_VERMILION,
- WZ_WATERBALL,
- WZ_ICEWALL,
- WZ_FROSTNOVA,
- WZ_STORMGUST,
- WZ_EARTHSPIKE,
- WZ_HEAVENDRIVE,
- WZ_QUAGMIRE,
- WZ_ESTIMATION,
-
- BS_IRON,
- BS_STEEL,
- BS_ENCHANTEDSTONE,
- BS_ORIDEOCON,
- BS_DAGGER,
- BS_SWORD,
- BS_TWOHANDSWORD,
- BS_AXE,
- BS_MACE,
- BS_KNUCKLE,
- BS_SPEAR,
- BS_HILTBINDING,
- BS_FINDINGORE,
- BS_WEAPONRESEARCH,
- BS_REPAIRWEAPON,
- BS_SKINTEMPER,
- BS_HAMMERFALL,
- BS_ADRENALINE,
- BS_WEAPONPERFECT,
- BS_OVERTHRUST,
- BS_MAXIMIZE,
-
- HT_SKIDTRAP,
- HT_LANDMINE,
- HT_ANKLESNARE,
- HT_SHOCKWAVE,
- HT_SANDMAN,
- HT_FLASHER,
- HT_FREEZINGTRAP,
- HT_BLASTMINE,
- HT_CLAYMORETRAP,
- HT_REMOVETRAP,
- HT_TALKIEBOX,
- HT_BEASTBANE,
- HT_FALCON,
- HT_STEELCROW,
- HT_BLITZBEAT,
- HT_DETECTING,
- HT_SPRINGTRAP,
-
- AS_RIGHT,
- AS_LEFT,
- AS_KATAR,
- AS_CLOAKING,
- AS_SONICBLOW,
- AS_GRIMTOOTH,
- AS_ENCHANTPOISON,
- AS_POISONREACT,
- AS_VENOMDUST,
- AS_SPLASHER,
-
- NV_FIRSTAID,
- NV_TRICKDEAD,
- SM_MOVINGRECOVERY,
- SM_FATALBLOW,
- SM_AUTOBERSERK,
- AC_MAKINGARROW,
- AC_CHARGEARROW,
- TF_SPRINKLESAND,
- TF_BACKSLIDING,
- TF_PICKSTONE,
- TF_THROWSTONE,
- MC_CARTREVOLUTION,
- MC_CHANGECART,
- MC_LOUD,
- AL_HOLYLIGHT,
- MG_ENERGYCOAT,
-
- NPC_PIERCINGATT,
- NPC_MENTALBREAKER,
- NPC_RANGEATTACK,
- NPC_ATTRICHANGE,
- NPC_CHANGEWATER,
- NPC_CHANGEGROUND,
- NPC_CHANGEFIRE,
- NPC_CHANGEWIND,
- NPC_CHANGEPOISON,
- NPC_CHANGEHOLY,
- NPC_CHANGEDARKNESS,
- NPC_CHANGETELEKINESIS,
- NPC_CRITICALSLASH,
- NPC_COMBOATTACK,
- NPC_GUIDEDATTACK,
- NPC_SELFDESTRUCTION,
- NPC_SPLASHATTACK,
- NPC_SUICIDE,
- NPC_POISON,
- NPC_BLINDATTACK,
- NPC_SILENCEATTACK,
- NPC_STUNATTACK,
- NPC_PETRIFYATTACK,
- NPC_CURSEATTACK,
- NPC_SLEEPATTACK,
- NPC_RANDOMATTACK,
- NPC_WATERATTACK,
- NPC_GROUNDATTACK,
- NPC_FIREATTACK,
- NPC_WINDATTACK,
- NPC_POISONATTACK,
- NPC_HOLYATTACK,
- NPC_DARKNESSATTACK,
- NPC_TELEKINESISATTACK,
- NPC_MAGICALATTACK,
- NPC_METAMORPHOSIS,
- NPC_PROVOCATION,
- NPC_SMOKING,
- NPC_SUMMONSLAVE,
- NPC_EMOTION,
- NPC_TRANSFORMATION,
- NPC_BLOODDRAIN,
- NPC_ENERGYDRAIN,
- NPC_KEEPING,
- NPC_DARKBREATH,
- NPC_DARKBLESSING,
- NPC_BARRIER,
- NPC_DEFENDER,
- NPC_LICK,
- NPC_HALLUCINATION,
- NPC_REBIRTH,
- NPC_SUMMONMONSTER,
-
- RG_SNATCHER,
- RG_STEALCOIN,
- RG_BACKSTAP,
- RG_TUNNELDRIVE,
- RG_RAID,
- RG_STRIPWEAPON,
- RG_STRIPSHIELD,
- RG_STRIPARMOR,
- RG_STRIPHELM,
- RG_INTIMIDATE,
- RG_GRAFFITI,
- RG_FLAGGRAFFITI,
- RG_CLEANER,
- RG_GANGSTER,
- RG_COMPULSION,
- RG_PLAGIARISM,
+int skill_update_heal_animation(struct map_session_data *sd); // [Fate] Check whether the healing flag must be updated, do so if needed
- AM_AXEMASTERY,
- AM_LEARNINGPOTION,
- AM_PHARMACY,
- AM_DEMONSTRATION,
- AM_ACIDTERROR,
- AM_POTIONPITCHER,
- AM_CANNIBALIZE,
- AM_SPHEREMINE,
- AM_CP_WEAPON,
- AM_CP_SHIELD,
- AM_CP_ARMOR,
- AM_CP_HELM,
- AM_BIOETHICS,
- AM_BIOTECHNOLOGY,
- AM_CREATECREATURE,
- AM_CULTIVATION,
- AM_FLAMECONTROL,
- AM_CALLHOMUN,
- AM_REST,
- AM_DRILLMASTER,
- AM_HEALHOMUN,
- AM_RESURRECTHOMUN,
-
- CR_TRUST,
- CR_AUTOGUARD,
- CR_SHIELDCHARGE,
- CR_SHIELDBOOMERANG,
- CR_REFLECTSHIELD,
- CR_HOLYCROSS,
- CR_GRANDCROSS,
- CR_DEVOTION,
- CR_PROVIDENCE,
- CR_DEFENDER,
- CR_SPEARQUICKEN,
-
- MO_IRONHAND,
- MO_SPIRITSRECOVERY,
- MO_CALLSPIRITS,
- MO_ABSORBSPIRITS,
- MO_TRIPLEATTACK,
- MO_BODYRELOCATION,
- MO_DODGE,
- MO_INVESTIGATE,
- MO_FINGEROFFENSIVE,
- MO_STEELBODY,
- MO_BLADESTOP,
- MO_EXPLOSIONSPIRITS,
- MO_EXTREMITYFIST,
- MO_CHAINCOMBO,
- MO_COMBOFINISH,
-
- SA_ADVANCEDBOOK,
- SA_CASTCANCEL,
- SA_MAGICROD,
- SA_SPELLBREAKER,
- SA_FREECAST,
- SA_AUTOSPELL,
- SA_FLAMELAUNCHER,
- SA_FROSTWEAPON,
- SA_LIGHTNINGLOADER,
- SA_SEISMICWEAPON,
- SA_DRAGONOLOGY,
- SA_VOLCANO,
- SA_DELUGE,
- SA_VIOLENTGALE,
- SA_LANDPROTECTOR,
- SA_DISPELL,
- SA_ABRACADABRA,
- SA_MONOCELL,
- SA_CLASSCHANGE,
- SA_SUMMONMONSTER,
- SA_REVERSEORCISH,
- SA_DEATH,
- SA_FORTUNE,
- SA_TAMINGMONSTER,
- SA_QUESTION,
- SA_GRAVITY,
- SA_LEVELUP,
- SA_INSTANTDEATH,
- SA_FULLRECOVERY,
- SA_COMA,
-
- BD_ADAPTATION,
- BD_ENCORE,
- BD_LULLABY,
- BD_RICHMANKIM,
- BD_ETERNALCHAOS,
- BD_DRUMBATTLEFIELD,
- BD_RINGNIBELUNGEN,
- BD_ROKISWEIL,
- BD_INTOABYSS,
- BD_SIEGFRIED,
- BD_RAGNAROK,
-
- BA_MUSICALLESSON,
- BA_MUSICALSTRIKE,
- BA_DISSONANCE,
- BA_FROSTJOKE,
- BA_WHISTLE,
- BA_ASSASSINCROSS,
- BA_POEMBRAGI,
- BA_APPLEIDUN,
-
- DC_DANCINGLESSON,
- DC_THROWARROW,
- DC_UGLYDANCE,
- DC_SCREAM,
- DC_HUMMING,
- DC_DONTFORGETME,
- DC_FORTUNEKISS,
- DC_SERVICEFORYOU,
-
- NPC_SELFDESTRUCTION2 = 333,
-
- WE_MALE = 334,
- WE_FEMALE,
- WE_CALLPARTNER,
-
- NPC_DARKCROSS = 338,
-
- TMW_SKILLPOOL = 339, // skill pool size
-
- TMW_MAGIC = 340,
- TMW_MAGIC_LIFE = 341,
- TMW_MAGIC_WAR = 342,
- TMW_MAGIC_TRANSMUTE = 343,
- TMW_MAGIC_NATURE = 344,
- TMW_MAGIC_ETHER = 345,
- TMW_MAGIC_DARK = 346,
- TMW_MAGIC_LIGHT = 347,
-
- TMW_BRAWLING = 350,
- TMW_LUCKY_COUNTER = 351,
- TMW_SPEED = 352,
- TMW_RESIST_POISON = 353,
- TMW_ASTRAL_SOUL = 354,
- TMW_RAGING = 355,
-
- LK_AURABLADE = 356,
- LK_PARRYING,
- LK_CONCENTRATION,
- LK_TENSIONRELAX,
- LK_BERSERK,
- LK_FURY,
- HP_ASSUMPTIO,
- HP_BASILICA,
- HP_MEDITATIO,
- HW_SOULDRAIN,
- HW_MAGICCRASHER,
- HW_MAGICPOWER,
- PA_PRESSURE,
- PA_SACRIFICE,
- PA_GOSPEL,
- CH_PALMSTRIKE,
- CH_TIGERFIST,
- CH_CHAINCRUSH,
- PF_HPCONVERSION,
- PF_SOULCHANGE,
- PF_SOULBURN,
- ASC_KATAR,
- ASC_HALLUCINATION,
- ASC_EDP,
- ASC_BREAKER,
- SN_SIGHT,
- SN_FALCONASSAULT,
- SN_SHARPSHOOTING,
- SN_WINDWALK,
- WS_MELTDOWN,
- WS_CREATECOIN,
- WS_CREATENUGGET,
- WS_CARTBOOST,
- WS_SYSTEMCREATE,
- ST_CHASEWALK,
- ST_REJECTSWORD,
- ST_STEALBACKPACK,
- CR_ALCHEMY,
- CR_SYNTHESISPOTION,
- CG_ARROWVULCAN,
- CG_MOONLIT,
- CG_MARIONETTE,
- LK_SPIRALPIERCE,
- LK_HEADCRUSH,
- LK_JOINTBEAT,
- HW_NAPALMVULCAN,
- CH_SOULCOLLECT,
- PF_MINDBREAKER,
- PF_MEMORIZE,
- PF_FOGWALL,
- PF_SPIDERWEB,
- ASC_METEORASSAULT,
- ASC_CDP,
- WE_BABY,
- WE_CALLPARENT,
- WE_CALLBABY,
- TK_RUN,
- TK_READYSTORM,
- TK_STORMKICK,
- TK_READYDOWN,
- TK_DOWNKICK,
- TK_READYTURN,
- TK_TURNKICK,
- TK_READYCOUNTER,
- TK_COUNTER,
- TK_DODGE,
- TK_JUMPKICK,
- TK_HPTIME,
- TK_SPTIME,
- TK_POWER,
- TK_SEVENWIND,
- TK_HIGHJUMP,
- SG_FEEL,
- SG_SUN_WARM,
- SG_MOON_WARM,
- SG_STAR_WARM,
- SG_SUN_COMFORT,
- SG_MOON_COMFORT,
- SG_STAR_COMFORT,
- SG_HATE,
- SG_SUN_ANGER,
- SG_MOON_ANGER,
- SG_STAR_ANGER,
- SG_SUN_BLESS,
- SG_MOON_BLESS,
- SG_STAR_BLESS,
- SG_DEVIL,
- SG_FRIEND,
- SG_KNOWLEDGE,
- SG_FUSION,
- SL_ALCHEMIST,
- AM_BERSERKPITCHER,
- SL_MONK,
- SL_STAR,
- SL_SAGE,
- SL_CRUSADER,
- SL_SUPERNOVICE,
- SL_KNIGHT,
- SL_WIZARD,
- SL_PRIEST,
- SL_BARDDANCER,
- SL_ROGUE,
- SL_ASSASIN,
- SL_BLACKSMITH,
- BS_ADRENALINE2,
- SL_HUNTER,
- SL_SOULLINKER,
- SL_KAIZEL,
- SL_KAAHI,
- SL_KAUPE,
- SL_KAITE,
- SL_KAINA,
- SL_STIN,
- SL_STUN,
- SL_SMA,
- SL_SWOO,
- SL_SKE,
- SL_SKA,
-
- GD_APPROVAL = 10000,
- GD_KAFRACONTACT,
- GD_GUARDIANRESEARCH,
- GD_CHARISMA,
- GD_EXTENSION,
-};
+void skill_reload(void);
// [Fate] Skill pools API
// Max. # of active entries in the skill pool
-#define MAX_SKILL_POOL 3
+constexpr int MAX_SKILL_POOL = 3;
// Max. # of skills that may be classified as pool skills in db/skill_db.txt
-#define MAX_POOL_SKILLS 128
+constexpr int MAX_POOL_SKILLS = 128;
-extern int skill_pool_skills[MAX_POOL_SKILLS]; // All pool skills
+extern SkillID skill_pool_skills[MAX_POOL_SKILLS]; // All pool skills
extern int skill_pool_skills_size; // Number of entries in skill_pool_skills
-int skill_pool (struct map_session_data *sd, int *skills); // Yields all active skills in the skill pool; no more than MAX_SKILL_POOL. Return is number of skills.
-int skill_pool_size (struct map_session_data *sd);
-int skill_pool_max (struct map_session_data *sd); // Max. number of pool skills
-void skill_pool_empty (struct map_session_data *sd); // Deactivate all pool skills
-int skill_pool_activate (struct map_session_data *sd, int skill); // Skill into skill pool. Return is zero iff okay.
-int skill_pool_is_activated (struct map_session_data *sd, int skill); // Skill into skill pool. Return is zero when activated.
-int skill_pool_deactivate (struct map_session_data *sd, int skill); // Skill out of skill pool. Return is zero iff okay.
-const char *skill_name(int skill); // Yield configurable skill name
-int skill_stat (int skill); // Yields the stat associated with a skill. Returns zero if none, or SP_STR, SP_VIT, ... otherwise
-int skill_power (struct map_session_data *sd, int skill); // Yields the power of a skill. This is zero if the skill is unknown or if it's a pool skill that is outside of the skill pool,
- // otherwise a value from 0 to 255 (with 200 being the `normal maximum')
-int skill_power_bl (struct block_list *bl, int skill); // Yields the power of a skill. This is zero if the skill is unknown or if it's a pool skill that is outside of the skill pool,
- // otherwise a value from 0 to 255 (with 200 being the `normal maximum')
-
-void skill_pool_register (int id); // [Fate] Remember that a certain skill ID belongs to a pool skill
-#endif
+// Yields all active skills in the skill pool; no more than MAX_SKILL_POOL. Return is number of skills.
+int skill_pool(struct map_session_data *sd, SkillID *skills);
+int skill_pool_size(struct map_session_data *sd);
+int skill_pool_max(struct map_session_data *sd); // Max. number of pool skills
+// Skill into skill pool. Return is zero iff okay.
+int skill_pool_activate(struct map_session_data *sd, SkillID skill);
+// Skill into skill pool. Return is zero when activated.
+bool skill_pool_is_activated(struct map_session_data *sd, SkillID skill);
+// Skill out of skill pool. Return is zero iff okay.
+int skill_pool_deactivate(struct map_session_data *sd, SkillID skill);
+// Yield configurable skill name
+inline
+const char *skill_name(SkillID skill)
+{
+ return skill_lookup_by_id(skill).desc;
+}
+// Yields the power of a skill.
+// This is zero if the skill is unknown
+// or if it's a pool skill that is outside of the skill pool,
+// otherwise a value from 0 to 255 (with 200 being the `normal maximum')
+int skill_power(struct map_session_data *sd, SkillID skill);
+int skill_power_bl(struct block_list *bl, SkillID skill);
+
+// [Fate] Remember that a certain skill ID belongs to a pool skill
+void skill_pool_register(SkillID id);
+#endif // SKILL_HPP
diff --git a/src/map/skill.t.hpp b/src/map/skill.t.hpp
new file mode 100644
index 0000000..3214062
--- /dev/null
+++ b/src/map/skill.t.hpp
@@ -0,0 +1,116 @@
+#ifndef SKILL_T_HPP
+#define SKILL_T_HPP
+
+#include <cstdint>
+
+#include "../common/utils2.hpp"
+
+// TODO remove most of these as their corresponding SkillIDs get deleted.
+enum class StatusChange : uint16_t
+{
+ // indices into (map_session_data).status_change
+ SC_SENDMAX = 256,
+
+ // sometimes means "none", sometimes not
+ NEGATIVE1 = 0xffff,
+
+ // these ones are used by clif_status_change,
+ // e.g. by the magic system
+ ZERO = 0,
+ ATTACK_ICON_GENERIC = 2000,
+ ATTACK_ICON_SHEARING = 2001,
+ CART = 0x0c,
+ CLIF_OPTION_SC_INVISIBILITY = 0x1000,
+ CLIF_OPTION_SC_SCRIBE = 0x1001,
+
+ // the rest are the normal effects
+ SC_SLOWPOISON = 14, // item script
+
+ SC_BROKNARMOR = 32, // ?
+ SC_BROKNWEAPON = 33, // ?
+
+ SC_WEIGHT50 = 35, // ? sort of used
+ SC_WEIGHT90 = 36, // definitely used
+ SC_SPEEDPOTION0 = 37, // item script
+
+ SC_HEALING = 70, // item script
+
+ SC_POISON = 132, // bad; actually used
+
+ SC_ATKPOT = 185, // item script
+ SC_MATKPOT = 186, // unused, but kept for parallel
+
+// Added for Fate's spells
+ SC_HIDE = 194, // Hide from `detect' magic (PCs only)
+ SC_SHEARED = 194, // Has been sheared (mobs only)
+ SC_HALT_REGENERATE = 195, // Suspend regeneration
+ SC_FLYING_BACKPACK = 196, // Flying backpack
+ SC_MBARRIER = 197, // Magical barrier, magic resistance (val1 : power (%))
+ SC_HASTE = 198, // `Haste' spell (val1 : power)
+ SC_PHYS_SHIELD = 199, // `Protect' spell, reduce damage (val1: power)
+ MAX_STATUSCHANGE = 200,
+};
+
+enum class SkillID : uint16_t
+{
+ // TODO: Remove these!
+ NEGATIVE = 0xffff,
+ ZERO = 0x0000,
+ ONE = 0x0001,
+
+ // Basic skills.
+ // These should probably be made unconditional.
+ NV_EMOTE = 1, //
+ NV_TRADE = 2, //
+ NV_PARTY = 3, //
+
+ AC_OWL = 45, // Mallard's Eye
+
+ NPC_SELFDESTRUCTION = 175, //
+
+ NPC_POISON = 178, //
+
+ NPC_SUMMONSLAVE = 198, //
+ NPC_EMOTION = 199, //
+
+ TMW_SKILLPOOL = 339, // skill pool size
+
+ // magic skills
+ TMW_MAGIC = 340, //
+ TMW_MAGIC_LIFE = 341, //
+ TMW_MAGIC_WAR = 342, //
+ TMW_MAGIC_TRANSMUTE = 343, //
+ TMW_MAGIC_NATURE = 344, //
+ TMW_MAGIC_ETHER = 345, //
+ TMW_MAGIC_DARK = 346, //
+ TMW_MAGIC_LIGHT = 347, //
+
+ // focusable skills
+ TMW_BRAWLING = 350, //
+ TMW_LUCKY_COUNTER = 351, //
+ TMW_SPEED = 352, //
+ TMW_RESIST_POISON = 353, //
+ TMW_ASTRAL_SOUL = 354, //
+ TMW_RAGING = 355, //
+
+ // Note: this value is also hard-coded in common/mmo.hpp
+ MAX_SKILL_DB = 474, // not 450
+};
+
+namespace e
+{
+enum class SkillFlags : uint16_t
+{
+ ZERO = 0x00,
+ // is a pool skill
+ POOL_FLAG = 0x01,
+ // is an active pool skill
+ POOL_ACTIVE = 0x02,
+ // pool skill has been activated (used for clif)
+ POOL_ACTIVATED = 0x04,
+};
+ENUM_BITWISE_OPERATORS(SkillFlags)
+}
+using e::SkillFlags;
+
+#endif // SKILL_T_HPP
diff --git a/src/map/storage.cpp b/src/map/storage.cpp
index 7d54343..dcd0dd7 100644
--- a/src/map/storage.cpp
+++ b/src/map/storage.cpp
@@ -1,34 +1,35 @@
// Copyright (c) Athena Dev Teams - Licensed under GNU GPL
-// For more information, see LICENCE in the main folder
+// For more information, see COPYING in the main folder
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
+#include "storage.hpp"
+
+#include <cstdlib>
+#include <cstring>
#include "../common/db.hpp"
#include "../common/nullpo.hpp"
-#include "storage.hpp"
#include "chrif.hpp"
-#include "itemdb.hpp"
#include "clif.hpp"
#include "intif.hpp"
+#include "itemdb.hpp"
+#include "map.hpp"
#include "pc.hpp"
-#include "guild.hpp"
-#include "battle.hpp"
-#include "atcommand.hpp"
-static struct dbt *storage_db;
-static struct dbt *guild_storage_db;
+#include "../poison.hpp"
+
+static
+Map<int, struct storage> storage_db;
/*==========================================
* 倉庫内アイテムソート
*------------------------------------------
*/
-int storage_comp_item (const void *_i1, const void *_i2)
+static
+int storage_comp_item(const void *_i1, const void *_i2)
{
- struct item *i1 = (struct item *) _i1;
- struct item *i2 = (struct item *) _i2;
+ const struct item *i1 = (const struct item *) _i1;
+ const struct item *i2 = (const struct item *) _i2;
if (i1->nameid == i2->nameid)
return 0;
@@ -39,123 +40,61 @@ int storage_comp_item (const void *_i1, const void *_i2)
return i1->nameid - i2->nameid;
}
-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);
-}
-
-static void storage_db_final (db_key_t key, db_val_t data, va_list ap)
-{
- struct storage *stor = (struct storage *) data;
- free (stor);
-}
-
-void sortage_sortitem (struct storage *stor)
-{
- nullpo_retv (stor);
- qsort (stor->storage_, MAX_STORAGE, sizeof (struct item),
- storage_comp_item);
-}
-
-void sortage_gsortitem (struct guild_storage *gstor)
+static
+void sortage_sortitem(struct storage *stor)
{
- nullpo_retv (gstor);
- qsort (gstor->storage_, MAX_GUILD_STORAGE, sizeof (struct item),
+ nullpo_retv(stor);
+ qsort(stor->storage_, MAX_STORAGE, sizeof(struct item),
storage_comp_item);
}
-/*==========================================
- * åˆæœŸåŒ–ã¨ã‹
- *------------------------------------------
- */
-int do_init_storage (void) // map.c::do_init()ã‹ã‚‰å‘¼ã°ã‚Œã‚‹
+void do_init_storage(void)
{
- storage_db = numdb_init ();
- guild_storage_db = numdb_init ();
- return 1;
}
-void do_final_storage (void) // by [MC Cameri]
+void do_final_storage(void)
{
- if (storage_db)
- numdb_final (storage_db, storage_db_final);
- if (guild_storage_db)
- numdb_final (guild_storage_db, guild_storage_db_final);
+ storage_db.clear();
}
-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)
- { //Guild Storage
- struct guild_storage *stor = (struct guild_storage *) data;
- if (stor->dirty && stor->storage_status == 0) //Save closed storages.
- storage_guild_storagesave (0, stor->guild_id, 0);
- }
- else
- { //Account Storage
- struct storage *stor = (struct storage *) data;
- if (stor->dirty && stor->storage_status == 0) //Save closed storages.
- storage_storage_save (stor->account_id, stor->dirty == 2 ? 1 : 0);
- }
-}
-
-//Function to be invoked upon server reconnection to char. To save all 'dirty' storages [Skotlex
-void do_reconnect_storage (void)
-{
- numdb_foreach (storage_db, storage_reconnect_sub, 0);
- numdb_foreach (guild_storage_db, storage_reconnect_sub, 1);
-}
-
-struct storage *account2storage (int account_id)
+struct storage *account2storage(int account_id)
{
- struct storage *stor =
- (struct storage *) numdb_search (storage_db, account_id);
+ struct storage *stor = storage_db.search(account_id);
if (stor == NULL)
{
- CREATE (stor, struct storage, 1);
+ stor = storage_db.init(account_id);
stor->account_id = account_id;
- numdb_insert (storage_db, stor->account_id, stor);
}
return stor;
}
// Just to ask storage, without creation
-struct storage *account2storage2 (int account_id)
+struct storage *account2storage2(int account_id)
{
- return (struct storage *) numdb_search (storage_db, account_id);
+ return storage_db.search(account_id);
}
-int storage_delete (int account_id)
+static
+void storage_delete(int account_id)
{
- struct storage *stor =
- (struct storage *) numdb_search (storage_db, account_id);
- if (stor)
- {
- numdb_erase (storage_db, account_id);
- free (stor);
- }
- return 0;
+ storage_db.erase(account_id);
}
/*==========================================
* カプラ倉庫を開ã
*------------------------------------------
*/
-int storage_storageopen (struct map_session_data *sd)
+int storage_storageopen(struct map_session_data *sd)
{
- struct storage *stor;
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
- if (sd->state.storage_flag)
+ if (sd->state.storage_open)
return 1; //Already open?
- if ((stor =
- (struct storage *) numdb_search (storage_db,
- sd->status.account_id)) == NULL)
+ struct storage *stor = storage_db.search(sd->status.account_id);
+ if (stor == NULL)
{ //Request storage.
- intif_request_storage (sd->status.account_id);
+ intif_request_storage(sd->status.account_id);
return 1;
}
@@ -163,10 +102,10 @@ int storage_storageopen (struct map_session_data *sd)
return 1; //Already open/player already has it open...
stor->storage_status = 1;
- sd->state.storage_flag = 1;
- clif_storageitemlist (sd, stor);
- clif_storageequiplist (sd, stor);
- clif_updatestorageamount (sd, stor);
+ sd->state.storage_open = 1;
+ clif_storageitemlist(sd, stor);
+ clif_storageequiplist(sd, stor);
+ clif_updatestorageamount(sd, stor);
return 0;
}
@@ -174,27 +113,28 @@ int storage_storageopen (struct map_session_data *sd)
* Internal add-item function.
*------------------------------------------
*/
-static int storage_additem (struct map_session_data *sd, struct storage *stor,
+static
+int storage_additem(struct map_session_data *sd, struct storage *stor,
struct item *item_data, int amount)
{
struct item_data *data;
- int i;
+ int i;
if (item_data->nameid <= 0 || amount <= 0)
return 1;
- data = itemdb_search (item_data->nameid);
+ data = itemdb_search(item_data->nameid);
- if (!itemdb_isequip2 (data))
+ if (!itemdb_isequip2(data))
{ //Stackable
for (i = 0; i < MAX_STORAGE; i++)
{
- if (compare_item (&stor->storage_[i], item_data))
+ if (compare_item(&stor->storage_[i], item_data))
{
if (amount > MAX_AMOUNT - stor->storage_[i].amount)
return 1;
stor->storage_[i].amount += amount;
- clif_storageitemadded (sd, stor, i, amount);
+ clif_storageitemadded(sd, stor, i, amount);
stor->dirty = 1;
return 0;
}
@@ -206,11 +146,11 @@ static int storage_additem (struct map_session_data *sd, struct storage *stor,
if (i >= MAX_STORAGE)
return 1;
- memcpy (&stor->storage_[i], item_data, sizeof (stor->storage_[0]));
+ memcpy(&stor->storage_[i], item_data, sizeof(stor->storage_[0]));
stor->storage_[i].amount = amount;
stor->storage_amount++;
- clif_storageitemadded (sd, stor, i, amount);
- clif_updatestorageamount (sd, stor);
+ clif_storageitemadded(sd, stor, i, amount);
+ clif_updatestorageamount(sd, stor);
stor->dirty = 1;
return 0;
}
@@ -219,7 +159,8 @@ static int storage_additem (struct map_session_data *sd, struct storage *stor,
* Internal del-item function
*------------------------------------------
*/
-static int storage_delitem (struct map_session_data *sd, struct storage *stor,
+static
+int storage_delitem(struct map_session_data *sd, struct storage *stor,
int n, int amount)
{
@@ -229,11 +170,11 @@ static int storage_delitem (struct map_session_data *sd, struct storage *stor,
stor->storage_[n].amount -= amount;
if (stor->storage_[n].amount == 0)
{
- memset (&stor->storage_[n], 0, sizeof (stor->storage_[0]));
+ memset(&stor->storage_[n], 0, sizeof(stor->storage_[0]));
stor->storage_amount--;
- clif_updatestorageamount (sd, stor);
+ clif_updatestorageamount(sd, stor);
}
- clif_storageitemremoved (sd, n, amount);
+ clif_storageitemremoved(sd, n, amount);
stor->dirty = 1;
return 0;
@@ -243,12 +184,13 @@ static int storage_delitem (struct map_session_data *sd, struct storage *stor,
* Add an item to the storage from the inventory.
*------------------------------------------
*/
-int storage_storageadd (struct map_session_data *sd, int index, int amount)
+int storage_storageadd(struct map_session_data *sd, int index, int amount)
{
struct storage *stor;
- nullpo_retr (0, sd);
- nullpo_retr (0, stor = account2storage2 (sd->status.account_id));
+ nullpo_ret(sd);
+ stor = account2storage2(sd->status.account_id);
+ nullpo_ret(stor);
if ((stor->storage_amount > MAX_STORAGE) || !stor->storage_status)
return 0; // storage full / storage closed
@@ -263,11 +205,11 @@ int storage_storageadd (struct map_session_data *sd, int index, int amount)
return 0;
// log_tostorage(sd, index, 0);
- if (storage_additem (sd, stor, &sd->status.inventory[index], amount) == 0)
+ if (storage_additem(sd, stor, &sd->status.inventory[index], amount) == 0)
{
// remove item from inventory
- pc_unequipinvyitem (sd, index, 0);
- pc_delitem (sd, index, amount, 0);
+ pc_unequipinvyitem(sd, index, CalcStatus::NOW);
+ pc_delitem(sd, index, amount, 0);
}
return 1;
@@ -277,13 +219,14 @@ int storage_storageadd (struct map_session_data *sd, int index, int amount)
* Retrieve an item from the storage.
*------------------------------------------
*/
-int storage_storageget (struct map_session_data *sd, int index, int amount)
+int storage_storageget(struct map_session_data *sd, int index, int amount)
{
struct storage *stor;
- int flag;
+ PickupFail flag;
- nullpo_retr (0, sd);
- nullpo_retr (0, stor = account2storage2 (sd->status.account_id));
+ nullpo_ret(sd);
+ stor = account2storage2(sd->status.account_id);
+ nullpo_ret(stor);
if (index < 0 || index >= MAX_STORAGE)
return 0;
@@ -294,100 +237,41 @@ int storage_storageget (struct map_session_data *sd, int index, int amount)
if (amount < 1 || amount > stor->storage_[index].amount)
return 0;
- if ((flag = pc_additem (sd, &stor->storage_[index], amount)) == 0)
- storage_delitem (sd, stor, index, amount);
+ if ((flag = pc_additem(sd, &stor->storage_[index], amount)) == PickupFail::OKAY)
+ storage_delitem(sd, stor, index, amount);
else
- clif_additem (sd, 0, 0, flag);
+ clif_additem(sd, 0, 0, flag);
// log_fromstorage(sd, index, 0);
return 1;
}
/*==========================================
- * Move an item from cart to storage.
- *------------------------------------------
- */
-int storage_storageaddfromcart (struct map_session_data *sd, int index,
- int amount)
-{
- struct storage *stor;
-
- nullpo_retr (0, sd);
- nullpo_retr (0, stor = account2storage2 (sd->status.account_id));
-
- if (stor->storage_amount > MAX_STORAGE || !stor->storage_status)
- return 0; // storage full / storage closed
-
- if (index < 0 || index >= MAX_CART)
- return 0;
-
- if (sd->status.cart[index].nameid <= 0)
- return 0; //No item there.
-
- if (amount < 1 || amount > sd->status.cart[index].amount)
- return 0;
-
- if (storage_additem (sd, stor, &sd->status.cart[index], amount) == 0)
- pc_cart_delitem (sd, index, amount, 0);
-
- return 1;
-}
-
-/*==========================================
- * Get from Storage to the Cart
- *------------------------------------------
- */
-int storage_storagegettocart (struct map_session_data *sd, int index,
- int amount)
-{
- struct storage *stor;
-
- nullpo_retr (0, sd);
- nullpo_retr (0, stor = account2storage2 (sd->status.account_id));
-
- if (!stor->storage_status)
- return 0;
-
- if (index < 0 || index >= MAX_STORAGE)
- return 0;
-
- if (stor->storage_[index].nameid <= 0)
- return 0; //Nothing there.
-
- if (amount < 1 || amount > stor->storage_[index].amount)
- return 0;
-
- if (pc_cart_additem (sd, &stor->storage_[index], amount) == 0)
- storage_delitem (sd, stor, index, amount);
-
- return 1;
-}
-
-/*==========================================
* Modified By Valaris to save upon closing [massdriller]
*------------------------------------------
*/
-int storage_storageclose (struct map_session_data *sd)
+int storage_storageclose(struct map_session_data *sd)
{
struct storage *stor;
- nullpo_retr (0, sd);
- nullpo_retr (0, stor = account2storage2 (sd->status.account_id));
+ nullpo_ret(sd);
+ stor = account2storage2(sd->status.account_id);
+ nullpo_ret(stor);
- clif_storageclose (sd);
+ clif_storageclose(sd);
if (stor->storage_status)
{
if (save_settings & 4)
- chrif_save (sd); //Invokes the storage saving as well.
+ chrif_save(sd); //Invokes the storage saving as well.
else
- storage_storage_save (sd->status.account_id, 0);
+ storage_storage_save(sd->status.account_id, 0);
}
stor->storage_status = 0;
- sd->state.storage_flag = 0;
+ sd->state.storage_open = 0;
if (sd->npc_flags.storage)
{
sd->npc_flags.storage = 0;
- map_scriptcont (sd, sd->npc_id);
+ map_scriptcont(sd, sd->npc_id);
}
return 0;
@@ -397,38 +281,28 @@ int storage_storageclose (struct map_session_data *sd)
* When quitting the game.
*------------------------------------------
*/
-int storage_storage_quit (struct map_session_data *sd)
+int storage_storage_quit(struct map_session_data *sd)
{
struct storage *stor;
- nullpo_retr (0, sd);
+ nullpo_ret(sd);
- stor = account2storage2 (sd->status.account_id);
+ stor = account2storage2(sd->status.account_id);
if (stor)
{
- chrif_save (sd); //Invokes the storage saving as well.
+ chrif_save(sd); //Invokes the storage saving as well.
stor->storage_status = 0;
- sd->state.storage_flag = 0;
+ sd->state.storage_open = 0;
}
return 0;
}
-void storage_storage_dirty (struct map_session_data *sd)
-{
- struct storage *stor;
-
- stor = account2storage2 (sd->status.account_id);
-
- if (stor)
- stor->dirty = 1;
-}
-
-int storage_storage_save (int account_id, int final)
+int storage_storage_save(int account_id, int final)
{
struct storage *stor;
- stor = account2storage2 (account_id);
+ stor = account2storage2(account_id);
if (!stor)
return 0;
@@ -439,12 +313,12 @@ int storage_storage_save (int account_id, int final)
stor->dirty = 2;
stor->storage_status = 0; //To prevent further manipulation of it.
}
- intif_send_storage (stor);
+ intif_send_storage(stor);
return 1;
}
if (final)
{ //Clear storage from memory. Nothing to save.
- storage_delete (account_id);
+ storage_delete(account_id);
return 1;
}
@@ -452,337 +326,18 @@ int storage_storage_save (int account_id, int final)
}
//Ack from Char-server indicating the storage was saved. [Skotlex]
-int storage_storage_saved (int account_id)
+int storage_storage_saved(int account_id)
{
struct storage *stor;
- if ((stor = account2storage2 (account_id)) != NULL)
+ if ((stor = account2storage2(account_id)) != NULL)
{ //Only mark it clean if it's not in use. [Skotlex]
if (stor->dirty && stor->storage_status == 0)
{
stor->dirty = 0;
- sortage_sortitem (stor);
+ sortage_sortitem(stor);
}
return 1;
}
return 0;
}
-
-struct guild_storage *guild2storage (int guild_id)
-{
- struct guild_storage *gs = NULL;
- if (guild_search (guild_id) != NULL)
- {
- gs = (struct guild_storage *) numdb_search (guild_storage_db,
- guild_id);
- if (gs == NULL)
- {
- CREATE (gs, struct guild_storage, 1);
- gs->guild_id = guild_id;
- numdb_insert (guild_storage_db, gs->guild_id, gs);
- }
- }
- return gs;
-}
-
-static
-struct guild_storage *guild2storage2 (int guild_id)
-{ //For just locating a storage without creating one. [Skotlex]
- return (struct guild_storage *) numdb_search (guild_storage_db, guild_id);
-}
-
-int guild_storage_delete (int guild_id)
-{
- struct guild_storage *gstor =
- (struct guild_storage *) numdb_search (guild_storage_db, guild_id);
- if (gstor)
- {
- numdb_erase (guild_storage_db, guild_id);
- free (gstor);
- }
- return 0;
-}
-
-int storage_guild_storageopen (struct map_session_data *sd)
-{
- struct guild_storage *gstor;
-
- nullpo_retr (0, sd);
-
- if (sd->status.guild_id <= 0)
- return 2;
-
- if (sd->state.storage_flag)
- return 1; //Can't open both storages at a time.
-
- if ((gstor = guild2storage2 (sd->status.guild_id)) == NULL)
- {
- intif_request_guild_storage (sd->status.account_id,
- sd->status.guild_id);
- return 0;
- }
- if (gstor->storage_status)
- return 1;
-
- gstor->storage_status = 1;
- sd->state.storage_flag = 2;
- clif_guildstorageitemlist (sd, gstor);
- clif_guildstorageequiplist (sd, gstor);
- clif_updateguildstorageamount (sd, gstor);
- return 0;
-}
-
-int guild_storage_additem (struct map_session_data *sd,
- struct guild_storage *stor, struct item *item_data,
- int amount)
-{
- struct item_data *data;
- int i;
-
- nullpo_retr (1, sd);
- nullpo_retr (1, stor);
- nullpo_retr (1, item_data);
- nullpo_retr (1, data = itemdb_search (item_data->nameid));
-
- if (item_data->nameid <= 0 || amount <= 0)
- return 1;
-
- if (!itemdb_isequip2 (data))
- { //Stackable
- for (i = 0; i < MAX_GUILD_STORAGE; i++)
- {
- if (compare_item (&stor->storage_[i], item_data))
- {
- if (stor->storage_[i].amount + amount > MAX_AMOUNT)
- return 1;
- stor->storage_[i].amount += amount;
- clif_guildstorageitemadded (sd, stor, i, amount);
- stor->dirty = 1;
- return 0;
- }
- }
- }
- //Add item
- for (i = 0; i < MAX_GUILD_STORAGE && stor->storage_[i].nameid; i++);
-
- if (i >= MAX_GUILD_STORAGE)
- return 1;
-
- memcpy (&stor->storage_[i], item_data, sizeof (stor->storage_[0]));
- stor->storage_[i].amount = amount;
- stor->storage_amount++;
- clif_guildstorageitemadded (sd, stor, i, amount);
- clif_updateguildstorageamount (sd, stor);
- stor->dirty = 1;
- return 0;
-}
-
-int guild_storage_delitem (struct map_session_data *sd,
- struct guild_storage *stor, int n, int amount)
-{
- nullpo_retr (1, sd);
- nullpo_retr (1, stor);
-
- if (stor->storage_[n].nameid == 0 || stor->storage_[n].amount < amount)
- return 1;
-
- stor->storage_[n].amount -= amount;
- if (stor->storage_[n].amount == 0)
- {
- memset (&stor->storage_[n], 0, sizeof (stor->storage_[0]));
- stor->storage_amount--;
- clif_updateguildstorageamount (sd, stor);
- }
- clif_storageitemremoved (sd, n, amount);
- stor->dirty = 1;
- return 0;
-}
-
-int storage_guild_storageadd (struct map_session_data *sd, int index,
- int amount)
-{
- struct guild_storage *stor;
-
- nullpo_retr (0, sd);
- nullpo_retr (0, stor = guild2storage2 (sd->status.guild_id));
-
- if (!stor->storage_status || stor->storage_amount > MAX_GUILD_STORAGE)
- return 0;
-
- if (index < 0 || index >= MAX_INVENTORY)
- return 0;
-
- if (sd->status.inventory[index].nameid <= 0)
- return 0;
-
- if (amount < 1 || amount > sd->status.inventory[index].amount)
- return 0;
-
-// log_tostorage(sd, index, 1);
- if (guild_storage_additem (sd, stor, &sd->status.inventory[index], amount)
- == 0)
- pc_delitem (sd, index, amount, 0);
-
- return 1;
-}
-
-int storage_guild_storageget (struct map_session_data *sd, int index,
- int amount)
-{
- struct guild_storage *stor;
- int flag;
-
- nullpo_retr (0, sd);
- nullpo_retr (0, stor = guild2storage2 (sd->status.guild_id));
-
- if (!stor->storage_status)
- return 0;
-
- if (index < 0 || index >= MAX_GUILD_STORAGE)
- return 0;
-
- if (stor->storage_[index].nameid <= 0)
- return 0;
-
- if (amount < 1 || amount > stor->storage_[index].amount)
- return 0;
-
- if ((flag = pc_additem (sd, &stor->storage_[index], amount)) == 0)
- guild_storage_delitem (sd, stor, index, amount);
- else
- clif_additem (sd, 0, 0, flag);
-// log_fromstorage(sd, index, 1);
-
- return 0;
-}
-
-int storage_guild_storageaddfromcart (struct map_session_data *sd, int index,
- int amount)
-{
- struct guild_storage *stor;
-
- nullpo_retr (0, sd);
- nullpo_retr (0, stor = guild2storage2 (sd->status.guild_id));
-
- if (!stor->storage_status || stor->storage_amount > MAX_GUILD_STORAGE)
- return 0;
-
- if (index < 0 || index >= MAX_CART)
- return 0;
-
- if (sd->status.cart[index].nameid <= 0)
- return 0;
-
- if (amount < 1 || amount > sd->status.cart[index].amount)
- return 0;
-
- if (guild_storage_additem (sd, stor, &sd->status.cart[index], amount) ==
- 0)
- pc_cart_delitem (sd, index, amount, 0);
-
- return 1;
-}
-
-int storage_guild_storagegettocart (struct map_session_data *sd, int index,
- int amount)
-{
- struct guild_storage *stor;
-
- nullpo_retr (0, sd);
- nullpo_retr (0, stor = guild2storage2 (sd->status.guild_id));
-
- if (!stor->storage_status)
- return 0;
-
- if (index < 0 || index >= MAX_GUILD_STORAGE)
- return 0;
-
- if (stor->storage_[index].nameid <= 0)
- return 0;
-
- if (amount < 1 || amount > stor->storage_[index].amount)
- return 0;
-
- if (pc_cart_additem (sd, &stor->storage_[index], amount) == 0)
- guild_storage_delitem (sd, stor, index, amount);
-
- return 1;
-}
-
-int storage_guild_storagesave (int account_id, int guild_id, int flag)
-{
- struct guild_storage *stor = guild2storage2 (guild_id);
-
- if (stor)
- {
- if (flag) //Char quitting, close it.
- stor->storage_status = 0;
- if (stor->dirty)
- intif_send_guild_storage (account_id, stor);
- return 1;
- }
- return 0;
-}
-
-int storage_guild_storagesaved (int guild_id)
-{
- struct guild_storage *stor;
-
- if ((stor = guild2storage2 (guild_id)) != NULL)
- {
- if (stor->dirty && stor->storage_status == 0)
- { //Storage has been correctly saved.
- stor->dirty = 0;
- sortage_gsortitem (stor);
- }
- return 1;
- }
- return 0;
-}
-
-int storage_guild_storageclose (struct map_session_data *sd)
-{
- struct guild_storage *stor;
-
- nullpo_retr (0, sd);
- nullpo_retr (0, stor = guild2storage2 (sd->status.guild_id));
-
- clif_storageclose (sd);
- chrif_save (sd); //This one also saves the storage. [Skotlex]
-
- stor->storage_status = 0;
- sd->state.storage_flag = 0;
-
- return 0;
-}
-
-int storage_guild_storage_quit (struct map_session_data *sd, int flag)
-{
- struct guild_storage *stor;
-
- nullpo_retr (0, sd);
- nullpo_retr (0, stor = guild2storage2 (sd->status.guild_id));
-
- if (flag)
- { //Only during a guild break flag is 1 (don't save storage)
- sd->state.storage_flag = 0;
- stor->storage_status = 0;
- clif_storageclose (sd);
- if (save_settings & 4)
- chrif_save (sd);
- return 0;
- }
-
- if (stor->storage_status)
- {
- if (save_settings & 4)
- chrif_save (sd);
- else
- storage_guild_storagesave (sd->status.account_id,
- sd->status.guild_id, 1);
- }
- sd->state.storage_flag = 0;
- stor->storage_status = 0;
-
- return 0;
-}
diff --git a/src/map/storage.hpp b/src/map/storage.hpp
index 22625df..1974efb 100644
--- a/src/map/storage.hpp
+++ b/src/map/storage.hpp
@@ -1,54 +1,19 @@
// Copyright (c) Athena Dev Teams - Licensed under GNU GPL
-// For more information, see LICENCE in the main folder
+// For more information, see COPYING in the main folder
#ifndef STORAGE_HPP
#define STORAGE_HPP
-#include "../common/mmo.hpp"
+int storage_storageopen(struct map_session_data *sd);
+int storage_storageadd(struct map_session_data *sd, int index, int amount);
+int storage_storageget(struct map_session_data *sd, int index, int amount);
+int storage_storageclose(struct map_session_data *sd);
+void do_init_storage(void);
+void do_final_storage(void);
+struct storage *account2storage(int account_id);
+struct storage *account2storage2(int account_id);
+int storage_storage_quit(struct map_session_data *sd);
+int storage_storage_save(int account_id, int final);
+int storage_storage_saved(int account_id);
-int storage_storageopen (struct map_session_data *sd);
-int storage_storageadd (struct map_session_data *sd, int index, int amount);
-int storage_storageget (struct map_session_data *sd, int index, int amount);
-int storage_storageaddfromcart (struct map_session_data *sd, int index,
- int amount);
-int storage_storagegettocart (struct map_session_data *sd, int index,
- int amount);
-int storage_storageclose (struct map_session_data *sd);
-int do_init_storage (void);
-void do_final_storage (void);
-void do_reconnect_storage (void);
-struct storage *account2storage (int account_id);
-struct storage *account2storage2 (int account_id);
-int storage_delete (int account_id);
-int storage_storage_quit (struct map_session_data *sd);
-int storage_storage_save (int account_id, int final);
-int storage_storage_saved (int account_id); //Ack from char server that guild store was saved.
-void storage_storage_dirty (struct map_session_data *sd);
-
-struct guild_storage *guild2storage (int guild_id);
-int guild_storage_delete (int guild_id);
-int storage_guild_storageopen (struct map_session_data *sd);
-int guild_storage_additem (struct map_session_data *sd,
- struct guild_storage *stor,
- struct item *item_data, int amount);
-int guild_storage_delitem (struct map_session_data *sd,
- struct guild_storage *stor, int n, int amount);
-int storage_guild_storageadd (struct map_session_data *sd, int index,
- int amount);
-int storage_guild_storageget (struct map_session_data *sd, int index,
- int amount);
-int storage_guild_storageaddfromcart (struct map_session_data *sd, int index,
- int amount);
-int storage_guild_storagegettocart (struct map_session_data *sd, int index,
- int amount);
-int storage_guild_storageclose (struct map_session_data *sd);
-int storage_guild_storage_quit (struct map_session_data *sd, int flag);
-int storage_guild_storagesave (int account_id, int guild_id, int flag);
-int storage_guild_storagesaved (int guild_id); //Ack from char server that guild store was saved.
-
-int storage_comp_item (const void *_i1, const void *_i2);
-//int storage_comp_item(const struct item* i1, const struct item* i2);
-void sortage_sortitem (struct storage *stor);
-void sortage_gsortitem (struct guild_storage *gstor);
-
-#endif
+#endif // STORAGE_HPP
diff --git a/src/map/tmw.cpp b/src/map/tmw.cpp
index 4b1831b..66b8bb9 100644
--- a/src/map/tmw.cpp
+++ b/src/map/tmw.cpp
@@ -1,62 +1,55 @@
-//
-
-#include <string.h>
-#include <ctype.h>
-#include <stdarg.h>
-
#include "tmw.hpp"
-#include "../common/socket.hpp"
-#include "../common/timer.hpp"
-#include "../common/version.hpp"
+#include <cctype>
+#include <cstring>
+
+#include "../common/cxxstdio.hpp"
#include "../common/nullpo.hpp"
#include "atcommand.hpp"
#include "battle.hpp"
-#include "chat.hpp"
#include "chrif.hpp"
#include "clif.hpp"
-#include "guild.hpp"
#include "intif.hpp"
-#include "itemdb.hpp"
-#include "magic.hpp"
#include "map.hpp"
-#include "mob.hpp"
-#include "npc.hpp"
-#include "party.hpp"
#include "pc.hpp"
-#include "script.hpp"
-#include "skill.hpp"
-#include "storage.hpp"
-#include "trade.hpp"
-int tmw_CheckChatSpam (struct map_session_data *sd, const char *message)
+#include "../poison.hpp"
+
+static
+void tmw_AutoBan(struct map_session_data *sd, const char *reason, int length);
+static
+int tmw_CheckChatLameness(struct map_session_data *sd, const char *message);
+static
+int tmw_ShorterStrlen(const char *s1, const char *s2);
+
+
+int tmw_CheckChatSpam(struct map_session_data *sd, const char *message)
{
- nullpo_retr (1, sd);
- time_t now = time (NULL);
+ nullpo_retr(1, sd);
+ TimeT now = TimeT::now();
- if (pc_isGM (sd))
+ if (pc_isGM(sd))
return 0;
if (now > sd->chat_reset_due)
{
- sd->chat_reset_due = now + battle_config.chat_spam_threshold;
+ sd->chat_reset_due = static_cast<time_t>(now) + battle_config.chat_spam_threshold;
sd->chat_lines_in = 0;
}
if (now > sd->chat_repeat_reset_due)
{
sd->chat_repeat_reset_due =
- now + (battle_config.chat_spam_threshold * 60);
+ static_cast<time_t>(now) + (battle_config.chat_spam_threshold * 60);
sd->chat_total_repeats = 0;
}
sd->chat_lines_in++;
// Penalty for repeats.
- if (strncmp
- (sd->chat_lastmsg, message,
- tmw_ShorterStrlen (sd->chat_lastmsg, message)) == 0)
+ if (strncmp(sd->chat_lastmsg, message,
+ tmw_ShorterStrlen(sd->chat_lastmsg, message)) == 0)
{
sd->chat_lines_in += battle_config.chat_lame_penalty;
sd->chat_total_repeats++;
@@ -67,17 +60,17 @@ int tmw_CheckChatSpam (struct map_session_data *sd, const char *message)
}
// Penalty for lame, it can stack on top of the repeat penalty.
- if (tmw_CheckChatLameness (sd, message))
+ if (tmw_CheckChatLameness(sd, message))
sd->chat_lines_in += battle_config.chat_lame_penalty;
- strncpy ((char *) sd->chat_lastmsg, message, battle_config.chat_maxline);
+ strncpy((char *) sd->chat_lastmsg, message, battle_config.chat_maxline);
if (sd->chat_lines_in >= battle_config.chat_spam_flood
|| sd->chat_total_repeats >= battle_config.chat_spam_flood)
{
sd->chat_lines_in = sd->chat_total_repeats = 0;
- tmw_AutoBan (sd, "chat", battle_config.chat_spam_ban);
+ tmw_AutoBan(sd, "chat", battle_config.chat_spam_ban);
return 1;
}
@@ -86,8 +79,8 @@ int tmw_CheckChatSpam (struct map_session_data *sd, const char *message)
(sd->chat_lines_in >= battle_config.chat_spam_warn
|| sd->chat_total_repeats >= battle_config.chat_spam_warn))
{
- clif_displaymessage (sd->fd, "WARNING: You are about to be automatically banned for spam!");
- clif_displaymessage (sd->fd, "WARNING: Please slow down, do not repeat, and do not SHOUT!");
+ clif_displaymessage(sd->fd, "WARNING: You are about to be automatically banned for spam!");
+ clif_displaymessage(sd->fd, "WARNING: Please slow down, do not repeat, and do not SHOUT!");
}
return 0;
@@ -95,43 +88,44 @@ int tmw_CheckChatSpam (struct map_session_data *sd, const char *message)
void tmw_AutoBan(struct map_session_data *sd, const char *reason, int length)
{
- char anotherbuf[512];
-
if (length == 0 || sd->auto_ban_info.in_progress)
return;
sd->auto_ban_info.in_progress = 1;
- tmw_GmHackMsg ("%s has been autobanned for %s spam",
- sd->status.name, reason);
+ std::string hack_msg = STRPRINTF("[GM] %s has been autobanned for %s spam",
+ sd->status.name,
+ reason);
+ tmw_GmHackMsg(hack_msg);
- gm_log ("%s(%d,%d) Server : @autoban %s %dh (%s spam)",
- map[sd->bl.m].name, sd->bl.x, sd->bl.y,
+ std::string fake_command = STRPRINTF("@autoban %s %dh (%s spam)",
sd->status.name, length, reason);
+ log_atcommand(sd, fake_command);
- snprintf (anotherbuf, 511, "You have been banned for %s spamming. Please do not spam.", reason);
+ std::string anotherbuf = STRPRINTF("You have been banned for %s spamming. Please do not spam.",
+ reason);
- clif_displaymessage (sd->fd, anotherbuf);
- /* type: 2 - ban (year, month, day, hour, minute, second) */
- chrif_char_ask_name (-1, sd->status.name, 2, 0, 0, 0, length, 0, 0);
- clif_setwaitclose (sd->fd);
+ clif_displaymessage(sd->fd, anotherbuf);
+ /* type: 2 - ban(year, month, day, hour, minute, second) */
+ chrif_char_ask_name(-1, sd->status.name, 2, 0, 0, 0, length, 0, 0);
+ clif_setwaitclose(sd->fd);
}
// Compares the length of two strings and returns that of the shorter
-int tmw_ShorterStrlen (const char *s1, const char *s2)
+int tmw_ShorterStrlen(const char *s1, const char *s2)
{
- int s1_len = strlen (s1);
- int s2_len = strlen (s2);
+ int s1_len = strlen(s1);
+ int s2_len = strlen(s2);
return (s2_len >= s1_len ? s1_len : s2_len);
}
// Returns true if more than 50% of input message is caps or punctuation
-int tmw_CheckChatLameness (struct map_session_data *sd, const char *message)
+int tmw_CheckChatLameness(struct map_session_data *, const char *message)
{
- int count, lame;
+ int count, lame;
for (count = lame = 0; *message; message++, count++)
- if (isupper (*message) || ispunct (*message))
+ if (isupper(*message) || ispunct(*message))
lame++;
if (count > 7 && lame > count / 2)
@@ -141,26 +135,15 @@ int tmw_CheckChatLameness (struct map_session_data *sd, const char *message)
}
// Sends a whisper to all GMs
-void tmw_GmHackMsg (const char *fmt, ...)
+void tmw_GmHackMsg(const_string line)
{
- char buf[512];
- va_list ap;
-
- va_start (ap, fmt);
- vsnprintf (buf, 511, fmt, ap);
- va_end (ap);
-
- char outbuf[512 + 5];
- strcpy (outbuf, "[GM] ");
- strcat (outbuf, buf);
-
- intif_wis_message_to_gm (wisp_server_name,
- battle_config.hack_info_GM_level, outbuf,
- strlen (outbuf) + 1);
+ intif_wis_message_to_gm(wisp_server_name,
+ battle_config.hack_info_GM_level,
+ line.data(), line.size() + 1);
}
/* Remove leading and trailing spaces from a string, modifying in place. */
-void tmw_TrimStr (char *str)
+void tmw_TrimStr(char *str)
{
char *l;
char *a;
@@ -169,16 +152,16 @@ void tmw_TrimStr (char *str)
if (!*str)
return;
- e = str + strlen (str) - 1;
+ e = str + strlen(str) - 1;
/* Skip all leading spaces. */
- for (l = str; *l && isspace (*l); ++l)
+ for (l = str; *l && isspace(*l); ++l)
;
/* Find the end of the string, or the start of trailing spaces. */
- for (a = e; *a && a > l && isspace (*a); --a)
+ for (a = e; *a && a > l && isspace(*a); --a)
;
- memmove (str, l, a - l + 1);
+ memmove(str, l, a - l + 1);
str[a - l + 1] = '\0';
}
diff --git a/src/map/tmw.hpp b/src/map/tmw.hpp
index 71de462..d64f45e 100644
--- a/src/map/tmw.hpp
+++ b/src/map/tmw.hpp
@@ -1,15 +1,10 @@
-//
#ifndef TMW_HPP
#define TMW_HPP
-#include "map.hpp"
+#include "../common/const_array.hpp"
-int tmw_CheckChatSpam (struct map_session_data *sd, const char *message);
-int tmw_ShorterStrlen (const char *s1, const char *s2);
-int tmw_CheckChatLameness (struct map_session_data *sd, const char *message);
-__attribute__((format(printf, 1, 2)))
-void tmw_GmHackMsg (const char *fmt, ...);
-void tmw_AutoBan (struct map_session_data *sd, const char *reason, int length);
-void tmw_TrimStr (char *str);
+int tmw_CheckChatSpam(struct map_session_data *sd, const char *message);
+void tmw_GmHackMsg(const_string line);
+void tmw_TrimStr(char *str);
-#endif /* TMW_H_ */
+#endif // TMW_HPP
diff --git a/src/map/trade.cpp b/src/map/trade.cpp
index 147db1b..6e81602 100644
--- a/src/map/trade.cpp
+++ b/src/map/trade.cpp
@@ -1,45 +1,47 @@
-#include <stdio.h>
-#include <string.h>
+#include "trade.hpp"
+
+#include "../common/cxxstdio.hpp"
+#include "../common/nullpo.hpp"
+#include "battle.hpp"
#include "clif.hpp"
#include "itemdb.hpp"
#include "map.hpp"
-#include "trade.hpp"
-#include "pc.hpp"
#include "npc.hpp"
-#include "battle.hpp"
+#include "pc.hpp"
#include "storage.hpp"
-#include "../common/nullpo.hpp"
+
+#include "../poison.hpp"
/*==========================================
* å–引è¦è«‹ã‚’相手ã«é€ã‚‹
*------------------------------------------
*/
-void trade_traderequest (struct map_session_data *sd, int target_id)
+void trade_traderequest(struct map_session_data *sd, int target_id)
{
struct map_session_data *target_sd;
- nullpo_retv (sd);
+ nullpo_retv(sd);
- if ((target_sd = map_id2sd (target_id)) != NULL)
+ if ((target_sd = map_id2sd(target_id)) != NULL)
{
if (!battle_config.invite_request_check)
{
- if (target_sd->guild_invite > 0 || target_sd->party_invite > 0)
+ if (target_sd->party_invite > 0)
{
- clif_tradestart (sd, 2); // 相手ã¯PTè¦è«‹ä¸­ã‹Guildè¦è«‹ä¸­
+ clif_tradestart(sd, 2); // 相手ã¯PTè¦è«‹ä¸­ã‹Guildè¦è«‹ä¸­
return;
}
}
if (target_sd->npc_id)
{
//Trade fails if you are using an NPC.
- clif_tradestart (sd, 2);
+ clif_tradestart(sd, 2);
return;
}
if ((target_sd->trade_partner != 0) || (sd->trade_partner != 0))
{
- trade_tradecancel (sd); //person is in another trade
+ trade_tradecancel(sd); //person is in another trade
}
else
{
@@ -49,19 +51,19 @@ void trade_traderequest (struct map_session_data *sd, int target_id)
|| (sd->bl.y - target_sd->bl.y <= -5
|| sd->bl.y - target_sd->bl.y >= 5))
{
- clif_tradestart (sd, 0); //too far
+ clif_tradestart(sd, 0); //too far
}
else if (sd != target_sd)
{
target_sd->trade_partner = sd->status.account_id;
sd->trade_partner = target_sd->status.account_id;
- clif_traderequest (target_sd, sd->status.name);
+ clif_traderequest(target_sd, sd->status.name);
}
}
}
else
{
- clif_tradestart (sd, 1); //character does not exist
+ clif_tradestart(sd, 1); //character does not exist
}
}
@@ -69,15 +71,15 @@ void trade_traderequest (struct map_session_data *sd, int target_id)
* å–引è¦è«‹
*------------------------------------------
*/
-void trade_tradeack (struct map_session_data *sd, int type)
+void trade_tradeack(struct map_session_data *sd, int type)
{
struct map_session_data *target_sd;
- nullpo_retv (sd);
+ nullpo_retv(sd);
- if ((target_sd = map_id2sd (sd->trade_partner)) != NULL)
+ if ((target_sd = map_id2sd(sd->trade_partner)) != NULL)
{
- clif_tradestart (target_sd, type);
- clif_tradestart (sd, type);
+ clif_tradestart(target_sd, type);
+ clif_tradestart(sd, type);
if (type == 4)
{ // Cancel
sd->deal_locked = 0;
@@ -86,15 +88,13 @@ void trade_tradeack (struct map_session_data *sd, int type)
target_sd->trade_partner = 0;
}
if (sd->npc_id != 0)
- npc_event_dequeue (sd);
+ npc_event_dequeue(sd);
if (target_sd->npc_id != 0)
- npc_event_dequeue (target_sd);
+ npc_event_dequeue(target_sd);
//close STORAGE window if it's open. It protects from spooffing packets [Lupus]
- if (sd->state.storage_flag == 1)
- storage_storageclose (sd);
- else if (sd->state.storage_flag == 2)
- storage_guild_storageclose (sd);
+ if (sd->state.storage_open)
+ storage_storageclose(sd);
}
}
@@ -102,19 +102,19 @@ void trade_tradeack (struct map_session_data *sd, int type)
* アイテム追加
*------------------------------------------
*/
-void trade_tradeadditem (struct map_session_data *sd, int index, int amount)
+void trade_tradeadditem(struct map_session_data *sd, int index, int amount)
{
struct map_session_data *target_sd;
struct item_data *id;
- int trade_i;
- int trade_weight = 0;
- int free = 0;
- int c;
- int i;
+ int trade_i;
+ int trade_weight = 0;
+ int free = 0;
+ int c;
+ int i;
- nullpo_retv (sd);
+ nullpo_retv(sd);
- if (((target_sd = map_id2sd (sd->trade_partner)) != NULL)
+ if (((target_sd = map_id2sd(sd->trade_partner)) != NULL)
&& (sd->deal_locked < 1))
{
if (index < 2 || index >= MAX_INVENTORY + 2)
@@ -122,7 +122,7 @@ void trade_tradeadditem (struct map_session_data *sd, int index, int amount)
if (index == 0 && amount > 0 && amount <= sd->status.zeny)
{
sd->deal_zeny = amount;
- clif_tradeadditem (sd, target_sd, 0, amount);
+ clif_tradeadditem(sd, target_sd, 0, amount);
}
}
else if (amount <= sd->status.inventory[index - 2].amount
@@ -151,8 +151,10 @@ void trade_tradeadditem (struct map_session_data *sd, int index, int amount)
&& target_sd->inventory_data[i] != NULL)
{
id = target_sd->inventory_data[i];
- if (id->type != 4 && id->type != 5
- && id->type != 7 && id->type != 8)
+ if (id->type != ItemType::WEAPON
+ && id->type != ItemType::ARMOR
+ && id->type != ItemType::_7
+ && id->type != ItemType::_8)
{
free++;
break;
@@ -163,13 +165,11 @@ void trade_tradeadditem (struct map_session_data *sd, int index, int amount)
if (target_sd->weight + trade_weight >
target_sd->max_weight)
{
- clif_tradeitemok (sd, index, 0, 1); //fail to add item -- the player was over weighted.
- amount = 0; // [MouseJstr]
+ clif_tradeitemok(sd, index, 0, 1); //fail to add item -- the player was over weighted.
}
else if (free <= 0)
{
- clif_tradeitemok (sd, index, 0, 2); //fail to add item -- no free slots at receiver
- amount = 0; // peavey
+ clif_tradeitemok(sd, index, 0, 2); //fail to add item -- no free slots at receiver
}
else
{
@@ -177,15 +177,15 @@ void trade_tradeadditem (struct map_session_data *sd, int index, int amount)
{ // re-deal exploit protection [Valaris]
if (sd->deal_item_index[c] == index)
{
- trade_tradecancel (sd);
+ trade_tradecancel(sd);
return;
}
}
- pc_unequipinvyitem (sd, index - 2, 0);
+ pc_unequipinvyitem(sd, index - 2, CalcStatus::NOW);
sd->deal_item_index[trade_i] = index;
sd->deal_item_amount[trade_i] += amount;
- clif_tradeitemok (sd, index, amount, 0); //success to add item
- clif_tradeadditem (sd, target_sd, index, amount);
+ clif_tradeitemok(sd, index, amount, 0); //success to add item
+ clif_tradeadditem(sd, target_sd, index, amount);
}
break;
}
@@ -205,8 +205,10 @@ void trade_tradeadditem (struct map_session_data *sd, int index, int amount)
&& target_sd->inventory_data[i] != NULL)
{
id = target_sd->inventory_data[i];
- if (id->type != 4 && id->type != 5
- && id->type != 7 && id->type != 8)
+ if (id->type != ItemType::WEAPON
+ && id->type != ItemType::ARMOR
+ && id->type != ItemType::_7
+ && id->type != ItemType::_8)
{
free++;
break;
@@ -225,12 +227,12 @@ void trade_tradeadditem (struct map_session_data *sd, int index, int amount)
* アイテム追加完了(ok押ã—)
*------------------------------------------
*/
-void trade_tradeok (struct map_session_data *sd)
+void trade_tradeok(struct map_session_data *sd)
{
struct map_session_data *target_sd;
- int trade_i;
+ int trade_i;
- nullpo_retv (sd);
+ nullpo_retv(sd);
for (trade_i = 0; trade_i < 10; trade_i++)
{
@@ -238,18 +240,18 @@ void trade_tradeok (struct map_session_data *sd)
sd->status.inventory[sd->deal_item_index[trade_i] - 2].amount
|| sd->deal_item_amount[trade_i] < 0)
{
- trade_tradecancel (sd);
+ trade_tradecancel(sd);
return;
}
}
- if ((target_sd = map_id2sd (sd->trade_partner)) != NULL)
+ if ((target_sd = map_id2sd(sd->trade_partner)) != NULL)
{
sd->deal_locked = 1;
- clif_tradeitemok (sd, 0, 0, 0);
- clif_tradedeal_lock (sd, 0);
- clif_tradedeal_lock (target_sd, 1);
+ clif_tradeitemok(sd, 0, 0, 0);
+ clif_tradedeal_lock(sd, 0);
+ clif_tradedeal_lock(target_sd, 1);
}
}
@@ -257,29 +259,32 @@ void trade_tradeok (struct map_session_data *sd)
* å–引キャンセル
*------------------------------------------
*/
-void trade_tradecancel (struct map_session_data *sd)
+void trade_tradecancel(struct map_session_data *sd)
{
struct map_session_data *target_sd;
- int trade_i;
+ int trade_i;
- nullpo_retv (sd);
+ nullpo_retv(sd);
- if ((target_sd = map_id2sd (sd->trade_partner)) != NULL)
+ if ((target_sd = map_id2sd(sd->trade_partner)) != NULL)
{
for (trade_i = 0; trade_i < 10; trade_i++)
{ //give items back (only virtual)
if (sd->deal_item_amount[trade_i] != 0)
{
- clif_additem (sd, sd->deal_item_index[trade_i] - 2,
- sd->deal_item_amount[trade_i], 0);
+ clif_additem(sd,
+ sd->deal_item_index[trade_i] - 2,
+ sd->deal_item_amount[trade_i],
+ PickupFail::OKAY);
sd->deal_item_index[trade_i] = 0;
sd->deal_item_amount[trade_i] = 0;
}
if (target_sd->deal_item_amount[trade_i] != 0)
{
- clif_additem (target_sd,
- target_sd->deal_item_index[trade_i] - 2,
- target_sd->deal_item_amount[trade_i], 0);
+ clif_additem(target_sd,
+ target_sd->deal_item_index[trade_i] - 2,
+ target_sd->deal_item_amount[trade_i],
+ PickupFail::OKAY);
target_sd->deal_item_index[trade_i] = 0;
target_sd->deal_item_amount[trade_i] = 0;
}
@@ -287,38 +292,36 @@ void trade_tradecancel (struct map_session_data *sd)
if (sd->deal_zeny)
{
sd->deal_zeny = 0;
- clif_updatestatus (sd, SP_ZENY);
+ clif_updatestatus(sd, SP::ZENY);
}
if (target_sd->deal_zeny)
{
- clif_updatestatus (target_sd, SP_ZENY);
+ clif_updatestatus(target_sd, SP::ZENY);
target_sd->deal_zeny = 0;
}
sd->deal_locked = 0;
sd->trade_partner = 0;
target_sd->deal_locked = 0;
target_sd->trade_partner = 0;
- clif_tradecancelled (sd);
- clif_tradecancelled (target_sd);
+ clif_tradecancelled(sd);
+ clif_tradecancelled(target_sd);
}
}
-#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)
-
/*==========================================
* å–引許諾(trade押ã—)
*------------------------------------------
*/
-void trade_tradecommit (struct map_session_data *sd)
+void trade_tradecommit(struct map_session_data *sd)
{
struct map_session_data *target_sd;
- int trade_i;
+ int trade_i;
- nullpo_retv (sd);
+ nullpo_retv(sd);
- if ((target_sd = map_id2sd (sd->trade_partner)) != NULL)
+ if ((target_sd = map_id2sd(sd->trade_partner)) != NULL)
{
- MAP_LOG_PC (sd, " TRADECOMMIT WITH %d GIVE %d GET %d",
+ MAP_LOG_PC(sd, " TRADECOMMIT WITH %d GIVE %d GET %d",
target_sd->status.char_id, sd->deal_zeny,
target_sd->deal_zeny);
if ((sd->deal_locked >= 1) && (target_sd->deal_locked >= 1))
@@ -332,15 +335,15 @@ void trade_tradecommit (struct map_session_data *sd)
if (sd->deal_zeny > sd->status.zeny)
{
sd->deal_zeny = 0;
- trade_tradecancel (sd);
- MAP_LOG_PC (sd, " TRADECANCEL");
+ trade_tradecancel(sd);
+ MAP_LOG_PC(sd, " TRADECANCEL");
return;
}
if (target_sd->deal_zeny > target_sd->status.zeny)
{
target_sd->deal_zeny = 0;
- trade_tradecancel (sd);
- MAP_LOG_PC (sd, " TRADECANCEL");
+ trade_tradecancel(sd);
+ MAP_LOG_PC(sd, " TRADECANCEL");
return;
}
sd->trade_partner = 0;
@@ -349,62 +352,62 @@ void trade_tradecommit (struct map_session_data *sd)
{
if (sd->deal_item_amount[trade_i] != 0)
{
- int n = sd->deal_item_index[trade_i] - 2;
- int flag;
- flag =
- pc_additem (target_sd, &sd->status.inventory[n],
- sd->deal_item_amount[trade_i]);
- if (flag == 0)
- pc_delitem (sd, n, sd->deal_item_amount[trade_i],
+ int n = sd->deal_item_index[trade_i] - 2;
+ PickupFail flag = pc_additem(target_sd,
+ &sd->status.inventory[n],
+ sd->deal_item_amount[trade_i]);
+ if (flag == PickupFail::OKAY)
+ pc_delitem(sd, n, sd->deal_item_amount[trade_i],
1);
else
- clif_additem (sd, n,
- sd->deal_item_amount[trade_i], 0);
+ clif_additem(sd, n,
+ sd->deal_item_amount[trade_i],
+ PickupFail::OKAY);
sd->deal_item_index[trade_i] = 0;
sd->deal_item_amount[trade_i] = 0;
}
if (target_sd->deal_item_amount[trade_i] != 0)
{
- int n = target_sd->deal_item_index[trade_i] - 2;
- int flag;
- flag =
- pc_additem (sd, &target_sd->status.inventory[n],
- target_sd->deal_item_amount[trade_i]);
- if (flag == 0)
- pc_delitem (target_sd, n,
+ int n = target_sd->deal_item_index[trade_i] - 2;
+ PickupFail flag = pc_additem(sd,
+ &target_sd->status.inventory[n],
+ target_sd->deal_item_amount[trade_i]);
+ if (flag == PickupFail::OKAY)
+ pc_delitem(target_sd, n,
target_sd->deal_item_amount[trade_i],
1);
else
- clif_additem (target_sd, n,
- target_sd->deal_item_amount
- [trade_i], 0);
+ clif_additem(target_sd, n,
+
+ target_sd->deal_item_amount[trade_i],
+ PickupFail::OKAY);
target_sd->deal_item_index[trade_i] = 0;
target_sd->deal_item_amount[trade_i] = 0;
}
}
if (sd->deal_zeny)
{
- int deal = sd->deal_zeny;
+ int deal = sd->deal_zeny;
sd->deal_zeny = 0;
sd->status.zeny -= deal;
- clif_updatestatus (sd, SP_ZENY);
+ clif_updatestatus(sd, SP::ZENY);
target_sd->status.zeny += deal;
- clif_updatestatus (target_sd, SP_ZENY);
+ clif_updatestatus(target_sd, SP::ZENY);
}
if (target_sd->deal_zeny)
{
- int deal = target_sd->deal_zeny;
+ int deal = target_sd->deal_zeny;
target_sd->deal_zeny = 0;
target_sd->status.zeny -= deal;
- clif_updatestatus (target_sd, SP_ZENY);
+ clif_updatestatus(target_sd, SP::ZENY);
sd->status.zeny += deal;
- clif_updatestatus (sd, SP_ZENY);
+ clif_updatestatus(sd, SP::ZENY);
}
sd->deal_locked = 0;
target_sd->deal_locked = 0;
- clif_tradecompleted (sd, 0);
- clif_tradecompleted (target_sd, 0);
- MAP_LOG_PC (sd, " TRADEOK");
+ clif_tradecompleted(sd, 0);
+ clif_tradecompleted(target_sd, 0);
+ MAP_LOG_PC(sd, " TRADEOK");
}
}
}
@@ -413,20 +416,20 @@ void trade_tradecommit (struct map_session_data *sd)
// This is called when a char's zeny is changed
// This helps prevent money duplication and other problems
// [Jaxad0127]
-void trade_verifyzeny (struct map_session_data *sd)
+void trade_verifyzeny(struct map_session_data *sd)
{
struct map_session_data *target_sd;
- nullpo_retv (sd);
+ nullpo_retv(sd);
- if ((target_sd = map_id2sd (sd->trade_partner)) != NULL)
+ if ((target_sd = map_id2sd(sd->trade_partner)) != NULL)
{
if (sd->deal_zeny > sd->status.zeny)
{
if (sd->deal_locked < 1)
- trade_tradeadditem (sd, 0, sd->status.zeny); // Fix money ammount
+ trade_tradeadditem(sd, 0, sd->status.zeny); // Fix money ammount
else
- trade_tradecancel (sd); // Or cancel the trade if we can't fix it
+ trade_tradecancel(sd); // Or cancel the trade if we can't fix it
}
}
}
diff --git a/src/map/trade.hpp b/src/map/trade.hpp
index 1e885f4..0edca9c 100644
--- a/src/map/trade.hpp
+++ b/src/map/trade.hpp
@@ -1,14 +1,12 @@
-// $Id: trade.h,v 1.2 2004/09/25 05:32:19 MouseJstr Exp $
#ifndef TRADE_HPP
#define TRADE_HPP
-#include "map.hpp"
-void trade_traderequest (struct map_session_data *sd, int target_id);
-void trade_tradeack (struct map_session_data *sd, int type);
-void trade_tradeadditem (struct map_session_data *sd, int index, int amount);
-void trade_tradeok (struct map_session_data *sd);
-void trade_tradecancel (struct map_session_data *sd);
-void trade_tradecommit (struct map_session_data *sd);
-void trade_verifyzeny (struct map_session_data *sd);
+void trade_traderequest(struct map_session_data *sd, int target_id);
+void trade_tradeack(struct map_session_data *sd, int type);
+void trade_tradeadditem(struct map_session_data *sd, int index, int amount);
+void trade_tradeok(struct map_session_data *sd);
+void trade_tradecancel(struct map_session_data *sd);
+void trade_tradecommit(struct map_session_data *sd);
+void trade_verifyzeny(struct map_session_data *sd);
#endif // TRADE_HPP
diff --git a/src/poison.hpp b/src/poison.hpp
new file mode 100644
index 0000000..11ea41d
--- /dev/null
+++ b/src/poison.hpp
@@ -0,0 +1,16 @@
+// impossible(*) to use safely
+// removed in C11
+#pragma GCC poison gets
+
+// TODO fill in as they are removed from source code:
+// double (use a fixed class)
+#pragma GCC poison float
+// mem* and str* from <string.h>, in favor of <algorithm>
+
+// Local time is forbidden.
+#pragma GCC poison timelocal // timegm
+#pragma GCC poison mktime // timegm
+#pragma GCC poison localtime // gmtime
+#pragma GCC poison localtime_r // gmtime_r
+
+#pragma GCC poison time // TimeT::now() or gettick()
diff --git a/src/tool/adduser.cpp b/src/tool/adduser.cpp
deleted file mode 100644
index 1954b66..0000000
--- a/src/tool/adduser.cpp
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- This program adds an user to account.txt
- Don't usr it When login-sever is working.
-*/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-char *account_txt = "../save/account.txt";
-
-//-----------------------------------------------------
-// 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;
-}
-
-int main (int argc, char *argv[])
-{
-
- char username[24];
- char password[24];
- char sex[2];
-
- int next_id, id;
- char line[1024];
-
- // Check to see if account.txt exists.
- printf ("Checking if '%s' file exists...\n", account_txt);
- FILE *FPaccin = fopen (account_txt, "r");
- if (FPaccin == NULL)
- {
- printf ("'%s' file not found!\n", account_txt);
- printf ("Run the setup wizard please.\n");
- exit (0);
- }
-
- next_id = 2000000;
- while (fgets (line, sizeof (line) - 1, FPaccin))
- {
- if (line[0] == '/' && line[1] == '/')
- {
- continue;
- }
- if (sscanf (line, "%d\t%%newid%%\n", &id) == 1)
- {
- if (next_id < id)
- {
- next_id = id;
- }
- }
- else
- {
- sscanf (line, "%i%[^ ]", &id);
- if (next_id <= id)
- {
- next_id = id + 1;
- }
- }
- }
- fclose (FPaccin);
- printf ("File exists.\n");
-
- printf ("Don't create an account if the login-server is online!!!\n");
- printf
- ("If the login-server is online, press ctrl+C now to stop this software.\n");
- printf ("\n");
-
- strcpy (username, "");
- while (strlen (username) < 4 || strlen (username) > 23)
- {
- printf ("Enter an username (4-23 characters): ");
- scanf ("%s", &username);
- username[23] = 0;
- remove_control_chars (username);
- }
-
- strcpy (password, "");
- while (strlen (password) < 4 || strlen (password) > 23)
- {
- printf ("Enter a password (4-23 characters): ");
- scanf ("%s", &password);
- password[23] = 0;
- remove_control_chars (password);
- }
-
- strcpy (sex, "");
- while (strcmp (sex, "F") != 0 && strcmp (sex, "M") != 0)
- {
- printf ("Enter a gender (M for male, F for female): ");
- scanf ("%s", &sex);
- }
-
- FILE *FPaccout = fopen (account_txt, "r+");
- fseek (FPaccout, 0, SEEK_END);
- fprintf (FPaccout, "%i %s %s - %s -\r\n", next_id, username,
- password, sex);
- fclose (FPaccout);
-
- printf ("Account added.\n");
-}
diff --git a/src/tool/backup b/src/tool/backup
deleted file mode 100644
index bde63b5..0000000
--- a/src/tool/backup
+++ /dev/null
@@ -1,100 +0,0 @@
-#!/usr/bin/perl
-
-##########################################################################
-# Athena用データãƒãƒƒã‚¯ã‚¢ãƒƒãƒ—ツール
-#
-#  Athenaã®å„種データファイル*.txtã‚’ãƒãƒƒã‚¯ã‚¢ãƒƒãƒ—ã™ã‚‹ãƒ„ール
-#
-#-------------------------------------------------------------------------
-# 設定方法
-#  実行ã™ã‚‹æ™‚ã®ã‚«ãƒ¬ãƒ³ãƒˆãƒ•ã‚©ãƒ«ãƒ€ã‹ã‚‰ã®ãƒ‡ãƒ¼ã‚¿ã¸ã®ãƒ‘スã€ãƒ•ã‚¡ã‚¤ãƒ«ã®ãƒªã‚¹ãƒˆã‚’
-#  正ã—ã設定ã—ã¾ã™ã€‚ãƒãƒƒã‚¯ã‚¢ãƒƒãƒ—å…ˆã®ãƒ•ã‚©ãƒ«ãƒ€ã¯è‡ªå‹•ä½œæˆã•ã‚Œãªã„ã®ã§ã€
-#  自分ã§ä½œæˆã—ã¦ãŠãå¿…è¦ãŒã‚ã‚Šã¾ã™ã€‚
-#  フォルダã®æœ€å¾Œã®ã€Œ/ã€ã¯çœç•¥ã§ãã¾ã›ã‚“。
-#
-#  フォルダã¯å¼•æ•°ã§ã‚‚指定ã§ãã¾ã™ã€‚例>./backup ../save/ ./backup_data/
-#  フォルダã®æœ€å¾Œã®ã€Œ/ã€ã¯çœç•¥ã§ãã¾ã›ã‚“。
-#
-#  実行ã™ã‚‹ã¨ãƒãƒƒã‚¯ã‚¢ãƒƒãƒ—å…ˆã®ãƒ•ã‚©ãƒ«ãƒ€ã¸ã€ãƒ•ã‚¡ã‚¤ãƒ«åã«ç¾åœ¨ã®æ—¥ä»˜ã¨æ™‚刻を
-#  ã¤ã‘ã¦ãƒ•ã‚¡ã‚¤ãƒ«ã‚’コピーã—ã¾ã™ã€‚
-#
-# * toolフォルダ内ã«backup_dataフォルダを作æˆã—ã€
-#   athena.shã®ä¸­ã«ã€Œ./tool/backup ./save/ ./tool/backup_data/ã€
-# ã¨ã„ã†è¡Œã‚’追加ã™ã‚‹ã¨ã€athenaã‚’èµ·å‹•ã™ã‚‹ãŸã³ã«ãƒãƒƒã‚¯ã‚¢ãƒƒãƒ—ãŒå–ã‚Œã¾ã™
-#
-# 復元ã™ã‚‹ã¨ãã¯å¼•æ•°ã«ã€Œ-r 日付ã¨æ™‚刻ã€ã‚’指定ã—ã¾ã™ã€‚
-#  ã¾ãŸãã®å¾Œã‚ã«ãƒ•ã‚©ãƒ«ãƒ€ã‚’指定ã™ã‚‹ã“ã¨ã‚‚出æ¥ã¾ã™
-#  例1> ./backup -r 200309191607
-#  例2> ./backup -r 200309191607 ../save ./backup_data/
-#  ã“ã®ä¾‹ã§ã¯2003/09/19ã®16:07分ã«ãƒãƒƒã‚¯ã‚¢ãƒƒãƒ—ã—ãŸãƒ‡ãƒ¼ã‚¿ã‚’復元ã—ã¦ã„ã¾ã™
-#
-#  復元ã™ã‚‹ã¨ãã€Athenaディレクトリã«ã‚るデータ㯠*.bak ã«åå‰ã‚’変更ã—ã¦
-#  残ã—ã¦ã„ã‚‹ã®ã§ã€ã„らãªã„å ´åˆã¯ rm *.bak ãªã©ã§æ¶ˆã—ã¦ãã ã•ã„。
-#
-##########################################################################
-
-$sdir="../save/"; #ãƒãƒƒã‚¯ã‚¢ãƒƒãƒ—å…ƒ(Athenaã®ãƒ‡ã‚£ãƒ¬ã‚¯ãƒˆãƒª/save/)
-$tdir="./backup_data/"; #ãƒãƒƒã‚¯ã‚¢ãƒƒãƒ—å…ˆ
-
-@files=( #ファイルã®ãƒªã‚¹ãƒˆ
- "account","athena","storage","party","guild","castle","pet"
-);
-
-
-#-------------------------------設定ã“ã“ã¾ã§-----------------------------
-
-
-
-
-
-
-
-
-
-
-
-if($ARGV[0]=~/^\-r$/i || $ARGV[0]=~/\-\-(recover|restore)/i){
- #復元処ç†
-
- $file=$ARGV[1];
- $sdir=$ARGV[2]||$sdir;
- $tdir=$ARGV[3]||$tdir;
- &restorecopy($_) foreach @files;
- exit(0);
-}
-
-#ãƒãƒƒã‚¯ã‚¢ãƒƒãƒ—処ç†
-$sdir=$ARGV[0]||$sdir;
-$tdir=$ARGV[1]||$tdir;
-
-unless( -d $tdir ){
- print "$0: \"$tdir\" : No such directory\n";
- exit(1);
-}
-
-(undef,$min,$hour,$day,$month,$year)=localtime;
-
-$file=sprintf("%04d%02d%02d%02d%02d",
- $year+1900, $month+1, $day, $hour, $min );
-
-&backupcopy($_) foreach @files;
-exit(0);
-
-sub backupcopy {
- my($name)= @_;
- system("cp $sdir$name.txt $tdir$name$file.txt");
-}
-
-sub restorecopy {
- my($name)= @_;
- unless( -f "$sdir$name.txt" ){
- printf("$0: \"$sdir$name.txt\" not found!\n");
- return 0;
- }
- unless( -f "$tdir$name$file.txt" ){
- printf("$0: \"$tdir$name$file.txt\" not found!\n");
- return 0;
- }
- rename "$sdir$name.txt","$sdir$name.bak";
- system("cp $tdir$name$file.txt $sdir$name.txt");
-}
diff --git a/src/tool/cgi/addaccount.cgi b/src/tool/cgi/addaccount.cgi
deleted file mode 100644
index 009f30f..0000000
--- a/src/tool/cgi/addaccount.cgi
+++ /dev/null
@@ -1,204 +0,0 @@
-#!/usr/bin/perl
-
-#=========================================================================
-# addaccount.cgi ver.1.00
-# ladminをラップã—ãŸã€ã‚¢ã‚«ã‚¦ãƒ³ãƒˆã‚’作æˆã™ã‚‹CGI。
-# ladmin ver.1.04ã§ã®å‹•ä½œã‚’確èªã€‚
-#
-# ** 設定方法 **
-#
-# - 下ã®$ladmin変数ã«ladminã¸ã®ãƒ‘スを設定ã™ã‚‹ã“ã¨ã€‚
-# - UNIXç³»OSã§ä½¿ç”¨ã™ã‚‹å ´åˆã¯ladminã¨å…±ã«æ”¹è¡Œã‚³ãƒ¼ãƒ‰ã‚’変æ›ã™ã‚‹ã“ã¨ã€ã¾ãŸ
-# ファイル先頭行をperlã®æ­£ã—ã„パスã«ã™ã‚‹ã“ã¨ã€‚例> $ which perl
-# - サーãƒãƒ¼ãƒ—ログラムやブラウザã«ã‚ˆã£ã¦ã¯ $cgiuri ã«ã“ã®ãƒ•ã‚¡ã‚¤ãƒ«ã¸ã®
-# 完全ãªURIをセットã—ãªã‘ã‚Œã°ãªã‚‰ãªã„å ´åˆã‚‚ã‚る。
-# - perlã«ãƒ‘スãŒé€šã£ã¦ã„ãªã„å ´åˆã¯ $perl ã‚’perlã¸ã®æ­£ã—ã„パスã«ã™ã‚‹ã“ã¨ã€‚
-# - ä»–ã¯æ™®é€šã®CGIã¨åŒã˜ã§ã™ã€‚(実行権やcgi-binフォルダãªã©ï¼‰
-#
-# ** ãã®ä»– **
-# addaccount.cgi をブラウザã§é–‹ãã¨ã‚µãƒ³ãƒ—ルHTML(ãã®ã¾ã¾ä½¿ãˆã¾ã™ï¼‰ãŒ
-# é–‹ãã¾ã™ã€‚ã¾ãŸã€ã“ã®cgiã¯ãƒ–ラウザã‹ã‚‰é€ã‚‰ã‚Œã‚‹Accept-LanguageãŒ
-# jaã§å§‹ã¾ã£ã¦ã„ã‚Œã°ãƒ¡ãƒƒã‚»ãƒ¼ã‚¸ã®ä¸€éƒ¨ã‚’日本語ã«å¤‰æ›ã—ã¾ã™ã€‚
-# (IEãªã‚‰ã‚¤ãƒ³ã‚¿ãƒ¼ãƒãƒƒãƒˆã‚ªãƒ—ションã®è¨€èªžè¨­å®šã§ä¸€ç•ªä¸Šã«æ—¥æœ¬èªžã‚’ç½®ã)
-# ãれ以外ã®å ´åˆã¯è‹±èªžã®ã¾ã¾å‡ºåŠ›ã—ã¾ã™ã€‚
-#-------------------------------------------------------------------------
-
-my($ladmin) = "../ladmin"; # ladminã®ãƒ‘ス(ãŠãらã変更ãŒå¿…è¦)
-
-my($cgiuri) = "./addaccount.cgi"; # ã“ã®ãƒ•ã‚¡ã‚¤ãƒ«ã®URI
-my($perl) = "perl"; # perlã®ã‚³ãƒžãƒ³ãƒ‰å
-
-
-
-#--------------------------- 設定ã“ã“ã¾ã§ --------------------------------
-
-
-
-
-
-
-use strict;
-use CGI;
-
-my($cgi)= new CGI;
-my(%langconv)=(
- 'Athena login-server administration tool.*' => '',
- 'logged on.*' => '',
-);
-
-# ----- 日本語環境ãªã‚‰å¤‰æ›ãƒ†ãƒ¼ãƒ–ルをセット -----
-if($ENV{'HTTP_ACCEPT_LANGUAGE'}=~/^ja/){
- my(%tmp)=(
- 'Account \[(.+)\] is successfully created.*'
- => 'アカウント "$1" を作æˆã—ã¾ã—ãŸ.',
- 'Account \[(.+)\] creation failed\. same account exists.*'
- => 'アカウント "$1" ã¯æ—¢ã«å­˜åœ¨ã—ã¾ã™.',
- 'Illeagal charactor found in UserID.*'
- => 'IDã®ä¸­ã«ä¸æ­£ãªæ–‡å­—ãŒã‚ã‚Šã¾ã™.',
- 'Illeagal charactor found in Password.*'
- => 'Passwordã®ä¸­ã«ä¸æ­£ãªæ–‡å­—ãŒã‚ã‚Šã¾ã™.',
- 'input UserID 4-24 bytes.'
- => 'IDã¯åŠè§’4〜24文字ã§å…¥åŠ›ã—ã¦ãã ã•ã„.',
- 'input Password 4-24 bytes.'
- => 'Passwordã¯åŠè§’4〜24文字ã§å…¥åŠ›ã—ã¦ãã ã•ã„.',
- 'Illeagal gender.*'
- => '性別ãŒãŠã‹ã—ã„ã§ã™.',
- 'Cant connect to login server.*'
- => 'ログインサーãƒãƒ¼ã«æŽ¥ç¶šã§ãã¾ã›ã‚“.',
- 'login error.*'
- => 'ログインサーãƒãƒ¼ã¸ã®ç®¡ç†è€…権é™ãƒ­ã‚°ã‚¤ãƒ³ã«å¤±æ•—ã—ã¾ã—ãŸ',
- "Can't execute ladmin.*"
- => 'ladminã®å®Ÿè¡Œã«å¤±æ•—ã—ã¾ã—ãŸ',
- 'UserID "(.+)" is already used.*'
- => 'ID "$1" ã¯æ—¢ã«ä½¿ç”¨ã•ã‚Œã¦ã„ã¾ã™.',
- 'You can use UserID \"(.+)\".*'
- => 'ID "$1" ã¯ä½¿ç”¨å¯èƒ½ã§ã™.',
-
- 'account making' =>'アカウント作æˆ',
- '\>UserID' =>'>ID',
- '\>Password' =>'>パスワード',
- '\>Gender' =>'>性別',
- '\>Male' =>'>男性',
- '\>Female' =>'>女性',
- '\"Make Account\"' =>'"アカウント作æˆ"',
- '\"Check UserID\"' =>'"IDã®ãƒã‚§ãƒƒã‚¯"',
- );
- map { $langconv{$_}=$tmp{$_}; } keys (%tmp);
-}
-
-# ----- 追加 -----
-if( $cgi->param("addaccount") ){
- my($userid)= $cgi->param("userid");
- my($passwd)= $cgi->param("passwd");
- my($gender)= lc(substr($cgi->param("gender"),0,1));
- if(length($userid)<4 || length($userid)>24){
- HttpError("input UserID 4-24 bytes.");
- }
- if(length($passwd)<4 || length($passwd)>24){
- HttpError("input Password 4-24 bytes.");
- }
- if($userid=~/[^0-9A-Za-z\@\_\-\']/){
- HttpError("Illeagal charactor found in UserID.");
- }
- if($passwd=~/[\x00-\x1f\x80-\xff\']/){
- HttpError("Illeagal charactor found in Password.");
- }
- if($gender!~/[mf]/){
- HttpError("Gender error.");
- }
- open PIPE,"$perl $ladmin --add $userid $gender $passwd |"
- or HttpError("Can't execute ladmin.");
- my(@msg)=<PIPE>;
- close PIPE;
- HttpMsg(@msg);
-}
-# ----- 存在ãƒã‚§ãƒƒã‚¯ -----
-elsif( $cgi->param("check") ){
- my($userid)= $cgi->param("userid");
- if(length($userid)<4 || length($userid)>24){
- HttpError("input UserID 4-24 bytes.");
- }
- if($userid=~/[^0-9A-Za-z\@\_\-\']/){
- HttpError("Illeagal charactor found in UserID.");
- }
- open PIPE,"$perl $ladmin --search --regex \\b$userid\\b |"
- or HttpError("Can't execute ladmin.");
- my(@msg)=<PIPE>;
- close PIPE;
- if(scalar(@msg)==6 && (split /[\s\0]+/,substr($msg[4],11,24))[0] eq $userid){
- HttpMsg("NG : UserID \"$userid\" is already used.");
- }elsif(scalar(@msg)==5){
- HttpMsg("OK : You can use UserID \"$userid\"");
- }
- HttpError("ladmin error ?\n---output---\n",@msg);
-}
-
-# ----- フォーム -----
-else{
- print LangConv( <<"EOM" );
-Content-type: text/html\n
-<html>
- <head>
- <title>Athena account making cgi</title>
- </head>
- <body>
- <h1>Athena account making cgi</h1>
- <form action="$cgiuri" method="post">
- <table border=2>
- <tr>
- <th>UserID</th>
- <td><input name="userid" size=24 maxlength=24></td>
- </tr>
- <tr>
- <th>Password</th>
- <td><input name="passwd" size=24 maxlength=24 type="password"></td>
- </tr>
- <tr>
- <th>Gender</th>
- <td>
- <input type="radio" name="gender" value="male">Male
- <input type="radio" name="gender" value="female">Female
- </td>
- </tr>
- <tr>
- <td colspan=2>
- <input type="submit" name="addaccount" value="Make Account">
- <input type="submit" name="check" value="Check UserID">
- </td>
- </tr>
- </table>
- </form>
- </body>
-</html>
-EOM
- exit;
-}
-
-sub LangConv {
- my(@lst)= @_;
- my($a,$b,@out)=();
- foreach $a(@lst){
- foreach $b(keys %langconv){
- $a=~s/$b/$langconv{$b}/g;
- my($rep1)=$1;
- $a=~s/\$1/$rep1/g;
- }
- push @out,$a;
- }
- return @out;
-}
-
-sub HttpMsg {
- my($msg)=join("", LangConv(@_));
- $msg=~s/\n/<br>\n/g;
- print LangConv("Content-type: text/html\n\n"),$msg;
- exit;
-}
-
-sub HttpError {
- my($msg)=join("", LangConv(@_));
- $msg=~s/\n/<br>\n/g;
- print LangConv("Content-type: text/html\n\n"),$msg;
- exit;
-}
-
diff --git a/src/tool/checkversion b/src/tool/checkversion
deleted file mode 100644
index 9e485d9..0000000
--- a/src/tool/checkversion
+++ /dev/null
@@ -1,85 +0,0 @@
-#!/usr/bin/perl -w
-
-##########################################################################
-# INFORMATION TOOL ABOUT THE SERVERS VERSION OF ATHENA
-#
-# By connection on a server, this software display the version of the
-# designed server.
-#-------------------------------------------------------------------------
-# Usages:
-# ./checkversion IP:port
-# ./checkversion IP port
-# perl checkversion IP:port
-# perl checkversion IP port
-#
-# note: default port: 6900
-#
-# When successfull, the software return the value 0.
-#
-##########################################################################
-
-#------------------------- start of configuration ------------------------
-
-$connecttimeout = 10; # Connection Timeout (in seconds)
-
-#-------------------------- End of configuration -------------------------
-
-use IO::Socket;
-
-unless($ARGV[0]) {
- print "USAGE: $0 server_ip:port\n";
- exit(1);
-}
-
-$server = $ARGV[0];
-$port = $ARGV[1];
-$port = $1 if ($server =~ s/:(\d+)//);
-$port ||= 6900;
-
-# Connection to the server
-my($so,$er) = ();
-eval{
- $so = IO::Socket::INET->new(
- PeerAddr=> $server,
- PeerPort=> $port,
- Proto => "tcp",
- Timeout => $connecttimeout) or $er = 1;
-};
-
-if($er || $@) {
- print "Can't not connect to server [$server:$port] !\n";
- exit(2);
-}
-
-# Request for the server version
-print $so pack("v",30000); # 0x7530
-$so->flush();
-
-# Receiving of the answer of the server
-if (read($so,$buf,10) < 10) {
- print "Invalid answer. It isn't an athena server or it is a too old version.\n";
- exit(5);
-}
-
-# Sending end of connection to the server
-print $so pack("v",30002); # 0x7532
-$so->flush();
-
-# Analyse of the answer
-my($ret,$maver,$miver,$rev,$dev,$mod,$type,$mdver) = unpack("v c6 v",$buf);
-
-if ($ret != 30001) { # 0x7531
- print "Invalid answer. It isn't an athena server or it is a too old version.\n";
- exit(6);
-}
-
-my(@stype) = ();
-foreach $i(0..3) {
- push @stype,(("login","char","inter","map")[$i]) if( $type & (1<<$i) );
-}
-print " ".join("/",@stype)." server [$server:$port].\n";
-printf " Athena version %s-%d.%d", ("stable","dev")[$dev], $maver,$miver;
-printf " revision %d",$rev if $rev;
-printf "%s%d\n",("","-mod")[$mod],$mdver;
-
-exit(0);
diff --git a/src/tool/convert.cpp b/src/tool/convert.cpp
deleted file mode 100644
index e256fc9..0000000
--- a/src/tool/convert.cpp
+++ /dev/null
@@ -1,302 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-
-#define MAX_INVENTORY 100
-#define MAX_CART 100
-#define MAX_SKILL 350
-#define GLOBAL_REG_NUM 16
-
-struct item
-{
- int id;
- short nameid;
- short amount;
- short equip;
- char identify;
- char refine;
- char attribute;
- short card[4];
-};
-struct point
-{
- char map[16];
- short x, y;
-};
-struct skill
-{
- unsigned short id, lv, flag;
-};
-struct global_reg
-{
- char str[16];
- int value;
-};
-
-struct mmo_charstatus
-{
- int char_id;
- int account_id;
- int base_exp, job_exp, zeny;
-
- short class;
- short status_point, skill_point;
- short 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;
- unsigned char str, agi, vit, int_, dex, luk, char_num, sex;
-
- struct point last_point, save_point, memo_point[3];
- 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 mmo_char_tostr (char *str, struct mmo_charstatus *p)
-{
- int i;
- sprintf (str, "%d\t%d,%d\t%s\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%s,%d,%d\t%s,%d,%d", p->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->hp, p->max_hp, p->sp, p->max_sp, p->str, p->agi, p->vit, p->int_, p->dex, p->luk, p->status_point, p->skill_point, 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);
- strcat (str, "\t");
- for (i = 0; i < 3; i++)
- if (p->memo_point[i].map[0])
- {
- sprintf (str + strlen (str), "%s,%d,%d", p->memo_point[i].map,
- p->memo_point[i].x, p->memo_point[i].y);
- }
- strcat (str, "\t");
- for (i = 0; i < MAX_INVENTORY; i++)
- if (p->inventory[i].nameid)
- {
- sprintf (str + strlen (str), "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d ",
- p->inventory[i].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]);
- }
- strcat (str, "\t");
- for (i = 0; i < MAX_CART; i++)
- if (p->cart[i].nameid)
- {
- sprintf (str + strlen (str), "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d ",
- p->cart[i].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]);
- }
- strcat (str, "\t");
- for (i = 0; i < MAX_SKILL; i++)
- if (p->skill[i].id)
- {
- sprintf (str + strlen (str), "%d,%d ", p->skill[i].id,
- p->skill[i].lv);
- }
- strcat (str, "\t");
- for (i = 0; i < p->global_reg_num; i++)
- sprintf (str + strlen (str), "%s,%d ", p->global_reg[i].str,
- p->global_reg[i].value);
- strcat (str, "\t");
- return 0;
-}
-
-int mmo_char_fromstr (char *str, struct mmo_charstatus *p)
-{
- int tmp_int[256];
- int set, next, len, i;
-
- 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[26], &tmp_int[27], &tmp_int[28], &tmp_int[29], &tmp_int[30], &tmp_int[31], &tmp_int[32], &tmp_int[33], p->last_point.map, &tmp_int[34], &tmp_int[35], //
- p->save_point.map, &tmp_int[36], &tmp_int[37], &next);
- 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 = 0;
- p->hair = tmp_int[26];
- p->hair_color = tmp_int[27];
- p->clothes_color = tmp_int[28];
- p->weapon = tmp_int[29];
- p->shield = tmp_int[30];
- p->head_top = tmp_int[31];
- p->head_mid = tmp_int[32];
- p->head_bottom = tmp_int[33];
- p->last_point.x = tmp_int[34];
- p->last_point.y = tmp_int[35];
- p->save_point.x = tmp_int[36];
- p->save_point.y = tmp_int[37];
- if (set != 41)
- return 0;
- if (str[next] == '\n' || str[next] == '\r')
- return 1; // æ–°è¦ãƒ‡ãƒ¼ã‚¿
- 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 0;
- 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++)
- {
- set = 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);
- if (set != 11)
- return 0;
- 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];
- next += len;
- if (str[next] == ' ')
- next++;
- }
- next++;
- for (i = 0; str[next] && str[next] != '\t'; i++)
- {
- set = 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);
- if (set != 11)
- return 0;
- 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];
- 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 0;
- 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実装以å‰ã®athena.txt互æ›ã®ãŸã‚一応'\n'ãƒã‚§ãƒƒã‚¯
- set = sscanf (str + next, "%[^,],%d%n",
- p->global_reg[i].str, &p->global_reg[i].value, &len);
- if (set != 2)
- return 0;
- next += len;
- if (str[next] == ' ')
- next++;
- }
- p->global_reg_num = i;
- return 1;
-}
-
-int mmo_char_convert (char *fname1, char *fname2)
-{
- char line[65536];
- int ret;
- struct mmo_charstatus char_dat;
- FILE *ifp, *ofp;
-
- ifp = fopen_ (fname1, "r");
- ofp = fopen_ (fname2, "w");
- if (ifp == NULL)
- {
- printf ("file not found %s\n", fname1);
- return 0;
- }
- if (ofp == NULL)
- {
- printf ("file open error %s\n", fname2);
- return 0;
- }
- while (fgets (line, 65535, ifp))
- {
- memset (&char_dat, 0, sizeof (struct mmo_charstatus));
- ret = mmo_char_fromstr (line, &char_dat);
- if (ret)
- {
- mmo_char_tostr (line, &char_dat);
- fprintf (ofp, "%s\n", line);
- }
- }
- fcloseall ();
- return 0;
-}
-
-int main (int argc, char *argv[])
-{
- if (argc < 3)
- {
- printf ("Usage: convert <input filename> <output filename>\n");
- exit (0);
- }
- mmo_char_convert (argv[1], argv[2]);
-
- return 0;
-}
diff --git a/src/tool/eathena-monitor.cpp b/src/tool/eathena-monitor.cpp
index e070c8a..30e7184 100644
--- a/src/tool/eathena-monitor.cpp
+++ b/src/tool/eathena-monitor.cpp
@@ -7,18 +7,21 @@
* 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/wait.h>
-#include <time.h>
#include <fcntl.h>
-#include <sys/wait.h>
-#include <signal.h>
+#include <unistd.h>
+
+#include <csignal>
+#include <cstdlib>
+#include <cstring>
+#include <ctime>
+
+#include "../common/cxxstdio.hpp"
+#include "../common/utils.hpp"
+
+#include "../poison.hpp"
-#define HOME getenv("HOME")
#define LOGIN_SERVER "./login-server"
#define MAP_SERVER "./map-server"
#define CHAR_SERVER "./char-server"
@@ -26,55 +29,60 @@
#define LOGFILE "log/eathena-monitor.log"
-#define SKIP_BLANK(ptr) ptr += skip_blank(ptr)
-static inline size_t skip_blank(const char* ptr) {
- size_t i = 0;
+static
+void SKIP_BLANK(char *& ptr)
+{
while (
- (ptr[i] == ' ') ||
- (ptr[i] == '\b') ||
- (ptr[i] == '\n') ||
- (ptr[i] == '\r')
- ) ptr++;
- return i;
+ (*ptr == ' ') ||
+ (*ptr == '\b') ||
+ (*ptr == '\n') ||
+ (*ptr == '\r')
+ )
+ ptr++;
}
-#define GOTO_EQL(ptr) ptr += goto_eql(ptr)
-static inline size_t goto_eql(const char* ptr) {
- size_t i = 0;
+static
+void GOTO_EQL(char *& ptr) {
while (
- (ptr[i] != '\0') &&
- (ptr[i] != '=') &&
- (ptr[i] != '\n') &&
- (ptr[i] != '\r')
- ) ptr++;
- return i;
+ (*ptr != '\0') &&
+ (*ptr != '=') &&
+ (*ptr != '\n') &&
+ (*ptr != '\r')
+ )
+ ptr++;
}
-#define GOTO_EOL(ptr) ptr += goto_newline(ptr)
-static inline size_t goto_newline(const char* ptr) {
- size_t i = 0;
+static
+void GOTO_EOL(char *& ptr) {
while (
- (ptr[i] != '\0') &&
- (ptr[i] != '\n') &&
- (ptr[i] != '\r')
- ) ptr++;
- return i;
+ (*ptr != '\0') &&
+ (*ptr != '\n') &&
+ (*ptr != '\r')
+ )
+ ptr++;
}
// initialiized to $HOME/tmwserver
+static
const char *workdir;
//the rest are relative to workdir
+static
const char *login_server = LOGIN_SERVER;
+static
const char *map_server = MAP_SERVER;
+static
const char *char_server = CHAR_SERVER;
+static
const char *logfile = LOGFILE;
// this variable is hard-coded, but the command-line is checked first
+static
const char *config = CONFIG;
+static
pid_t pid_login, pid_map, pid_char;
static
-const char* make_path (const char* base, const char* path) {
+const char* make_path(const char* base, const char* path) {
size_t base_len = strlen(base);
size_t path_len = strlen(path);
char* out = (char *)malloc(base_len + 1 + path_len + 1);
@@ -86,7 +94,7 @@ const char* make_path (const char* base, const char* path) {
}
static
-void parse_option (char *name, char *value) {
+void parse_option(char *name, char *value) {
if (!strcasecmp(name, "login_server")) {
login_server = strdup(value);
} else if (!strcasecmp(name, "map_server")) {
@@ -98,7 +106,7 @@ void parse_option (char *name, char *value) {
} else if (!strcasecmp(name, "logfile")) {
logfile = strdup(value);
} else {
- fprintf(stderr, "WARNING: ingnoring invalid option '%s' = '%s'\n", name, value);
+ FPRINTF(stderr, "WARNING: ingnoring invalid option '%s' = '%s'\n", name, value);
}
}
@@ -107,24 +115,24 @@ void read_config(const char *filename) {
FILE *input;
char string[1000];
- if (!(input = fopen(filename,"r")) && !(input = fopen (config, "r"))) {
+ if (!(input = fopen(filename,"r")) && !(input = fopen(config, "r"))) {
perror("Unable to load config file");
return;
}
while (1) {
- if (fgets (string, sizeof (string) - 1, input) == NULL)
+ if (fgets(string, sizeof(string) - 1, input) == NULL)
break;
char *str = string, *name, *value;
SKIP_BLANK(str);
- string[sizeof (string) - 1] = '\0';
+ string[sizeof(string) - 1] = '\0';
if (*str == '#')
continue;
if (*str == '\0')
continue;
name = str;
- GOTO_EQL (str);
+ GOTO_EQL(str);
if (*str != '=') {
continue;
@@ -138,7 +146,7 @@ void read_config(const char *filename) {
parse_option(name, value);
}
- fclose (input);
+ fclose(input);
}
static
@@ -146,11 +154,14 @@ 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");
+ FPRINTF(stderr, "Failed to fork");
return 0;
}
if (pid == 0) {
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wcast-qual"
execv(exec, (char**)args);
+#pragma GCC diagnostic pop
perror("Failed to exec");
kill(getppid(), SIGABRT);
exit(1);
@@ -176,24 +187,24 @@ int main(int argc, char *argv[]) {
signal(SIGQUIT, stop_process);
signal(SIGABRT, stop_process);
- workdir = make_path(HOME, "tmwserver");
+ workdir = make_path(getenv("HOME"), "tmwserver");
read_config(argc>1 ? argv[1] : NULL);
if (chdir(workdir) < 0) perror("Failed to change directory"), exit(1);
- printf ("Starting:\n");
- printf ("* workdir: %s\n", workdir);
- printf ("* login_server: %s\n", login_server);
- printf ("* map_server: %s\n", map_server);
- printf ("* char_server: %s\n", char_server);
+ PRINTF("Starting:\n");
+ PRINTF("* workdir: %s\n", workdir);
+ PRINTF("* login_server: %s\n", login_server);
+ PRINTF("* map_server: %s\n", map_server);
+ PRINTF("* char_server: %s\n", char_server);
{
//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);
+ 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);
@@ -202,22 +213,20 @@ int main(int argc, char *argv[]) {
}
while (1) {
// write stuff to stderr
- time_t t = time(NULL);
- struct tm *tmp = localtime(&t);
- char timestamp[256];
- strftime(timestamp, sizeof(timestamp), "%F %T", tmp);
+ timestamp_seconds_buffer timestamp;
+ stamp_time(timestamp);
if (!pid_login) {
pid_login = start_process(login_server);
- fprintf (stderr, "[%s] forked login server: %lu\n", timestamp, (unsigned long)pid_login);
+ FPRINTF(stderr, "[%s] forked login server: %lu\n", timestamp, (unsigned long)pid_login);
}
if (!pid_char) {
pid_char = start_process(char_server);
- fprintf (stderr, "[%s] forked char server: %lu\n", timestamp, (unsigned long)pid_char);
+ FPRINTF(stderr, "[%s] forked char server: %lu\n", timestamp, (unsigned long)pid_char);
}
if (!pid_map) {
pid_map = start_process(map_server);
- fprintf (stderr, "[%s] forked map server: %lu\n", timestamp, (unsigned long)pid_map);
+ FPRINTF(stderr, "[%s] forked map server: %lu\n", timestamp, (unsigned long)pid_map);
}
pid_t dead = wait(NULL);
if (dead < 0) perror("Failed to wait for child"), exit(1);
diff --git a/src/tool/getlogincount b/src/tool/getlogincount
deleted file mode 100644
index 45c6f81..0000000
--- a/src/tool/getlogincount
+++ /dev/null
@@ -1,122 +0,0 @@
-#!/usr/bin/perl -w
-
-##########################################################################
-# INFORMATION TOOL ABOUT THE # OF ONLINE PLAYERS ON ATHENA SERVERS
-#
-# By connection on the athena login-server, this software displays the
-# number of online players.
-#
-#-------------------------------------------------------------------------
-# Software usage:
-# Configure the IP, the port and a valid account of the server.
-# After, use at your choice:
-# ./getlogincount - display the number of online players on all servers.
-# ./getlogincount --premier or
-# ./getlogincount --first -- display the number of online players of the
-# first server in the received list.
-# ./getlogincount [servername] -- display the number of online players
-# of the specified server.
-#
-# If successfull, the software return the value 0.
-#
-##########################################################################
-
-#------------------------------ CONFIGURATION ----------------------------
-
-$loginserverip = "127.0.0.1"; # IP of the login-server
-$loginserverport = 6900; # port of the login-server
-$loginaccount = "s1"; # a valid account name
-$loginpasswd = "p1"; # the password of the valid account name
-
-$connecttimeout = 10; # Connection timeout (in seconds)
-
-#-------------------------------------------------------------------------
-
-use IO::Socket;
-
-my($sname) = $ARGV[0];
-if (!defined($sname)) {
- $sname = "";
-}
-
-# Connection to the login-server
-my($so,$er) = ();
-eval{
- $so = IO::Socket::INET->new(
- PeerAddr=> $loginserverip,
- PeerPort=> $loginserverport,
- Proto => "tcp",
- Timeout => $connecttimeout) or $er=1;
-};
-if($er || $@){
- print "Can't not connect to the login-server [${loginserverip}:$loginserverport] !\n";
- exit(2);
-}
-
-# Request to connect on login-server
-print $so pack("v V a24 a24 C",0x0064,9,$loginaccount,$loginpasswd,3);
-$so->flush();
-
-# Fail to connect
-if(unpack("v", &soread(\$so,2)) != 0x0069) {
- print "Login error.\n";
- exit(3);
-}
-
-# Get length of the received packet
-my($plen) = unpack("v",&soread(\$so,2))-4;
-
-# Suppress information of the account (we need only information about the servers)
-&soread(\$so,43);
-$plen -= 43;
-
-# Check about the number of online servers
-if ($plen < 32) {
- printf "No server is connected to login-server.\n";
- exit(1);
-}
-
-# Read information of the servers
-my(@slist) = ();
-for(;$plen > 0;$plen -= 32) {
- my($name,$count) = unpack("x6 a20 V",&soread(\$so,32));
- $name = substr($name,0,index($name,"\0"));
- push @slist, [ $name, $count ];
-}
-
-# Display the result
-if($sname eq "--first" || $sname eq "--premier") { # If we ask only for the first server
- printf "%-20s : %5d\n",$slist[0][0],$slist[0][1];
-} elsif ($sname eq "") { # If we ask for all servers
- foreach $i(@slist) {
- printf "%-20s : %5d\n",$i->[0],$i->[1];
- }
-} else { # If we ask for a specified server (by its name)
- my($flag) = 1;
- foreach $i(@slist) {
- if($i->[0] eq $sname) {
- printf "%-20s : %5d\n",$i->[0],$i->[1];
- $flag = 0;
- }
- }
- if($flag) { # If the server doesn't exist
- printf "The server [$sname] doesn't exist.\n";
- exit(1);
- }
-}
-
-# End of the software
-$so->shutdown(2);
-$so->close();
-exit(0);
-
-# Sub-function: get data from the socket
-sub soread {
- my($so,$len) = @_;
- my($sobuf);
- if(read($$so,$sobuf,$len) < $len) {
- print "Socket read error.\n";
- exit(5);
- }
- return $sobuf;
-};
diff --git a/src/tool/indent.sh b/src/tool/indent.sh
deleted file mode 100755
index d71f224..0000000
--- a/src/tool/indent.sh
+++ /dev/null
@@ -1,8 +0,0 @@
-#!/bin/sh
-# Simple script to help format code to TMW-eA standards.
-# You should use this on any file you edit before
-# committing to git.
-indent -nbad -bap -sc -bl -blf -bli0 -cli4 -cbi0 -di5 \
--nbc -bls -ip2 -nut -ts4 -bap -i4 -sob -npsl $*
-
-
diff --git a/src/tool/ipcheck.rb b/src/tool/ipcheck.rb
deleted file mode 100755
index 7c2e22a..0000000
--- a/src/tool/ipcheck.rb
+++ /dev/null
@@ -1,82 +0,0 @@
-#!/usr/bin/env ruby
-# A script to check which characters play from the same IP address
-# (c) 2009 Bjorn Lindeijer
-#
-# Summary of how it works:
-#
-# Character -> Account
-# Account -> IP
-# IP -> Accounts
-# Accounts -> Characters
-#
-
-if ARGV.length != 1
- puts "Usage: ipcheck.rb character_name"
- exit 1
-else
- $search_character = ARGV[0]
- puts "Searching for character #{$search_character}"
-end
-
-class Character
- attr_reader :name, :account_id
-
- def initialize(name, account_id)
- @name = name
- @account_id = account_id
- end
-end
-
-class Account
- attr_reader :id, :ip, :last_login
-
- def initialize(id, ip, last_login)
- @id = id
- @ip = ip
- @last_login = last_login
- end
-end
-
-accounts = Array.new
-characters = Array.new
-
-File.open("save/athena.txt", "r") do |f|
- f.each_line do |line|
- split = line.split("\t")
- if split.length >= 3
- account_id, char_index = split[1].split(',')
- character_name = split[2]
- characters.push(Character.new(character_name, account_id))
- if $search_character.casecmp(character_name) == 0
- puts "Searching for account #{account_id}"
- $search_account_id = account_id
- end
- end
- end
-end
-
-if not $search_account_id
- puts "Error: character #{$search_character} not found!"
- exit 1
-end
-
-File.open("save/account.txt", "r") do |f|
- f.each_line do |line|
- split = line.split("\t")
- if split.length >= 11
- account_id, last_login, ip = split[0], split[3], split[10]
- accounts.push(Account.new(account_id, ip, last_login))
- if $search_account_id == account_id
- puts "Searching for IP #{ip}"
- $search_ip = ip
- end
- end
- end
-end
-
-accounts.find_all { |a| a.ip == $search_ip }.each do |a|
- puts "Characters for account #{a.id} (last login #{a.last_login}):"
- characters.find_all { |c| c.account_id == a.id }.each do |c|
- puts " #{c.name}"
- end
-end
diff --git a/src/tool/itemfrob.cpp b/src/tool/itemfrob.cpp
deleted file mode 100644
index 81638eb..0000000
--- a/src/tool/itemfrob.cpp
+++ /dev/null
@@ -1,130 +0,0 @@
-// Compile with
-// gcc -m32 -I src/char -I src/common charfrob.c -o charfrob src/common/timer.o src/common/malloc.o src/common/socket.o src/common/lock.o src/common/db.o src/char/int_pet.o src/char/int_storage.o src/char/inter.o src/char/int_party.o src/char/int_guild.o
-
-#include <stdio.h>
-#include <stdlib.h>
-#include "../common/mmo.hpp"
-// Yes, this is intentional
-#include "../char/char.cpp"
-
-// Well, this is not terribly elegant, but I don't have that much time.
-#define MAX_ITEM_ID 65535
-int inv_translate[MAX_ITEM_ID];
-
-void transform_char (struct mmo_charstatus *p)
-{
- int k;
- for (k = 0; k < MAX_INVENTORY; k++)
- p->inventory[k].nameid = inv_translate[p->inventory[k].nameid];
-}
-
-int mmo_char_convert ()
-{
- char line[965536];
- int ret;
- struct mmo_charstatus char_dat;
- FILE *ifp, *ofp;
-
- ifp = stdin;
- ofp = stdout;
- while (fgets (line, 65535, ifp))
- {
- memset (&char_dat, 0, sizeof (struct mmo_charstatus));
- ret = mmo_char_fromstr (line, &char_dat);
- if (ret)
- {
- transform_char (&char_dat);
- mmo_char_tostr (line, &char_dat);
- fprintf (ofp, "%s\n", line);
- }
- }
- return 0;
-}
-
-#define PARSE_MODE_NEXTNUM 0
-#define PARSE_MODE_RANGE 1
-
-int init (char *source, char *dest)
-{
- int i;
- char *end_of_num;
- int dest_nr = strtol (dest, &end_of_num, 0);
- int range_start;
- int mode = PARSE_MODE_NEXTNUM;
-
- if (*end_of_num)
- {
- fprintf (stderr, "Invalid inventory ID: `%s'\n", dest);
- return 1;
- }
-
- /* init */
- for (i = 0; i < MAX_ITEM_ID; i++)
- inv_translate[i] = i;
-
- while (*source)
- {
- int nr = strtol (source, &end_of_num, 0);
- char sep;
-
- if (end_of_num == source)
- {
- fprintf (stderr, "Invalid source range description: `%s'\n",
- source);
- return 1;
- }
-
- switch (mode)
- {
- case PARSE_MODE_NEXTNUM:
- inv_translate[nr] = dest_nr;
- break;
- case PARSE_MODE_RANGE:
- for (i = range_start; i <= nr; i++)
- inv_translate[i] = dest_nr;
- break;
- default:
- fprintf (stderr, "Internal error at %d\n", __LINE__);
- return 1;
- };
-
- sep = *end_of_num++;
-
- switch (sep)
- {
- case '-':
- range_start = nr;
- mode = PARSE_MODE_RANGE;
- break;
- case ',':
- mode = PARSE_MODE_NEXTNUM;
- break;
- case 0:
- return 0;
- default:
- fprintf (stderr, "Invalid token in range spec: `%c'\n", sep);
- return 1;
- }
-
- source = end_of_num;
- }
- return 0;
-}
-
-int main (int argc, char *argv[])
-{
- if (argc < 3)
- {
- printf
- ("Usage: %s <inventory ID input range> <inventory ID output>\n",
- argv[0]);
- printf ("e.g., %s 501-555 701\n", argv[0]);
- exit (0);
- }
- if (init (argv[1], argv[2]))
- return 1;
-
- mmo_char_convert ();
-
- return 0;
-}
diff --git a/src/tool/itemsearch.cpp b/src/tool/itemsearch.cpp
deleted file mode 100644
index ab36a9d..0000000
--- a/src/tool/itemsearch.cpp
+++ /dev/null
@@ -1,136 +0,0 @@
-// This code is GPL, blah blah
-//
-// Writen for TheManaWorld by Chuck Miller, A.K.A. Kage
-
-#include <cstring>
-#include <iostream>
-#include <stdlib.h>
-#include <string>
-
-using namespace std;
-
-bool useStorage;
-int itemID;
-
-int itemCount(string itemData)
-{
- int counter = 0;
- int pointer = 0;
-
- do
- {
- int ending = itemData.find(',', pointer + 1);
- if (ending == string::npos)
- ending = itemData.size();
- if (counter == 1 && atoi(itemData.substr(pointer, ending - pointer).c_str()) != itemID)
- return 0;
- if (counter == 2)
- return atoi(itemData.substr(pointer, ending - pointer).c_str());
- counter++;
- } while ((pointer = itemData.find(',',pointer) + 1) != string::npos + 1);
-
- return 0;
-}
-
-int parseItemData(string &items)
-{
- int counter = 0;
- int pointer = 0;
-
- int total = 0;
-
- do
- {
- int ending = items.find(' ', pointer + 1);
- if (ending == string::npos)
- ending = items.size();
- total += itemCount(items.substr(pointer, ending - pointer));
- counter++;
- } while ((pointer = items.find(' ',pointer) + 1) != string::npos + 1);
-
- return total;
-}
-
-void parseLine(string &line)
-{
- int counter = 0;
- int pointer = 0;
-
- string AccountId, Name, Items;
-
- do
- {
- if (!useStorage)
- {
- if (counter == 1 || counter == 2 || counter == 15)
- {
- int ending = line.find('\t', pointer + 1);
- if (ending == string::npos)
- ending = line.size();
- switch (counter)
- {
- case 1:
- AccountId = line.substr(pointer,ending - pointer);
- break;
- case 2:
- Name = line.substr(pointer, ending - pointer);
- break;
- case 15:
- Items = line.substr(pointer, ending - pointer);
- }
- }
- }
- else if (useStorage)
- {
- int ending = line.find('\t', pointer + 1);
- if (ending == string::npos)
- ending = line.size();
-
- if (counter == 0)
- AccountId = line.substr(pointer,ending - pointer);
- else if (counter == 1)
- Items = line.substr(pointer,ending - pointer);
- }
-
- counter++;
- } while ((pointer = line.find('\t',pointer) + 1) != string::npos + 1 && counter < 16);
-
- if ((counter = parseItemData(Items)) > 0)
- cout << "Account = " << AccountId << "; Name = \"" << Name << "\"; Count = " << counter << "\n";
-}
-
-void parseInput()
-{
- string input;
- while (getline(cin, input))
- {
- parseLine(input);
- }
-}
-
-int main(int argc,char *argv[])
-{
- if(argc < 2)
- {
- printf("Usage: %s <item ID>\n", argv[0]);
- printf("Usage2: %s -s <item ID>\n", argv[0]);
- printf("e.g., %s 701\n", argv[0]);
- printf("Will return all users who own that item\n");
- printf("Option \"-s\" will expect storage files\n");
- exit(0);
- }
- if (strcmp(argv[1],"-s") == 0)
- {
- useStorage = true;
- itemID = atoi(argv[2]);
- }
- else
- {
- useStorage = false;
- itemID = atoi(argv[1]);
- }
- parseInput();
-
- return 0;
-}
-
diff --git a/src/tool/ladmin b/src/tool/ladmin
deleted file mode 100644
index d0c0be4..0000000
--- a/src/tool/ladmin
+++ /dev/null
@@ -1,3793 +0,0 @@
-#!/usr/bin/perl
-use POSIX;
-##########################################################################
-# EAthena login-server remote administration tool
-# New ladamin by [Yor]
-##########################################################################
-#-------------------------------INSTRUCTIONS------------------------------
-# Set the 4 variables below:
-# IP of the login server.
-# Port where the login-server listens incoming packets.
-# Password of administration (same of config_athena.conf).
-# Displayed language of the sofware (if not correct, english is used).
-# IMPORTANT:
-# Be sure that you authorize remote administration in login-server
-# (see login_athena.conf, 'admin_state' parameter)
-#-------------------------------------------------------------------------
-my($loginserverip) = "127.0.0.1"; # IP of login-server
-my($loginserverport) = 6900; # Port of login-server
-my($loginserveradminpassword) = "admin"; # Administration password
-my($connecttimeout) = 10; # Timeout of connection (in seconds)
-my($passenc) = 2; # Encoding type of the password
-my($defaultlanguage) = "E"; # Default language (F: Français/E: English)
- # (if it's not 'F', default is English)
-
-#-------------------------------------------------------------------------
-# LIST of COMMANDs that you can type at the prompt:
-# To use these commands you can only type only the first letters.
-# You must type a minimum of letters (you can not type 'a',
-# because ladmin doesn't know if it's for 'aide' or for 'add')
-# <Example> q <= quit, li <= list, pass <= passwd, etc.
-#
-# Note: every time you must give a account_name, you can use "" or '' (spaces can be included)
-#
-# aide/help/?
-# Display the description of the commands
-# aide/help/? [command]
-# Display the description of the specified command
-#
-# add <account_name> <sex> <password>
-# Create an account with the default email (a@a.com).
-# Concerning the sex, only the first letter is used (F or M).
-# The e-mail is set to a@a.com (default e-mail). It's like to have no e-mail.
-# When the password is omitted, the input is done without displaying of the pressed keys.
-# <example> add testname Male testpass
-#
-# ban/banish yyyy/mm/dd hh:mm:ss <account name>
-# Changes the final date of a banishment of an account.
-# Same command of banset, except that account_name is at end
-#
-# banadd <account_name> <modifier>
-# Adds or substracts time from the final date of a banishment of an account.
-# Modifier is done as follows:
-# Adjustment value (-1, 1, +1, etc...)
-# Modified element:
-# a or y: year
-# m: month
-# j or d: day
-# h: hour
-# mn: minute
-# s: second
-# <example> banadd testname +1m-2mn1s-6y
-# this example adds 1 month and 1 second, and substracts 2 minutes and 6 years at the same time.
-# NOTE: If you modify the final date of a non-banished account,
-# you fix the final date to (actual time +- adjustments)
-#
-# banset <account_name> yyyy/mm/dd [hh:mm:ss]
-# Changes the final date of a banishment of an account.
-# Default time: 23:59:59
-# banset <account_name> 0
-# Set a non-banished account (0 = unbanished).
-#
-# block <account name>
-# Set state 5 (You have been blocked by the GM Team) to an account.
-# Same command of state <account_name> 5.
-#
-# check <account_name> <password>
-# Check the validity of a password for an account
-# NOTE: Server will never sends back a password.
-# It's the only method you have to know if a password is correct.
-# The other method is to have a ('physical') access to the accounts file.
-#
-# create <account_name> <sex> <email> <password>
-# Like the 'add' command, but with e-mail moreover.
-# <example> create testname Male my@mail.com testpass
-#
-# del <account name>
-# Remove an account.
-# This order requires confirmation. After confirmation, the account is deleted.
-#
-# email <account_name> <email>
-# Modify the e-mail of an account.
-#
-# getcount
-# Give the number of players online on all char-servers.
-#
-# gm <account_name> [GM_level]
-# Modify the GM level of an account.
-# Default value remove GM level (GM level = 0).
-# <example> gm testname 80
-#
-# id <account name>
-# Give the id of an account.
-#
-# info <account_id>
-# Display complete information of an account.
-#
-# kami <message>
-# Sends a broadcast message on all map-server (in yellow).
-# kamib <message>
-# Sends a broadcast message on all map-server (in blue).
-#
-# language <language>
-# Change the language of displaying.
-#
-# list/ls [start_id [end_id]]
-# Display a list of accounts.
-# 'start_id', 'end_id': indicate end and start identifiers.
-# Research by name is not possible with this command.
-# <example> list 10 9999999
-#
-# listBan/lsBan [start_id [end_id]]
-# Like list/ls, but only for accounts with state or banished
-#
-# listGM/lsGM [start_id [end_id]]
-# Like list/ls, but only for GM accounts
-#
-# listOK/lsOK [start_id [end_id]]
-# Like list/ls, but only for accounts without state and not banished
-#
-# memo <account_name> <memo>
-# Modify the memo of an account.
-# 'memo': it can have until 253 characters (with spaces or not).
-#
-# name <account_id>
-# Give the name of an account.
-#
-# passwd <account_name> <new_password>
-# Change the password of an account.
-# When new password is omitted, the input is done without displaying of the pressed keys.
-#
-# quit/end/exit
-# End of the program of administration
-#
-# reloadGM
-# Reload GM configuration file
-#
-# search <expression>
-# Seek accounts.
-# Displays the accounts whose names correspond.
-# search -r/-e/--expr/--regex <expression>
-# Seek accounts by regular expression.
-# Displays the accounts whose names correspond.
-#
-# sex <account_name> <sex>
-# Modify the sex of an account.
-# <example> sex testname Male
-#
-# state <account_name> <new_state> <error_message_#7>
-# Change the state of an account.
-# 'new_state': state is the state of the packet 0x006a + 1. The possibilities are:
-# 0 = Account ok 6 = Your Game's EXE file is not the latest version
-# 1 = Unregistered ID 7 = You are Prohibited to log in until %s
-# 2 = Incorrect Password 8 = Server is jammed due to over populated
-# 3 = This ID is expired 9 = No MSG
-# 4 = Rejected from Server 100 = This ID has been totally erased
-# 5 = You have been blocked by the GM Team
-# all other values are 'No MSG', then use state 9 please.
-# 'error_message_#7': message of the code error 6 = Your are Prohibited to log in until %s (packet 0x006a)
-#
-# timeadd <account_name> <modifier>
-# Adds or substracts time from the validity limit of an account.
-# Modifier is done as follows:
-# Adjustment value (-1, 1, +1, etc...)
-# Modified element:
-# a or y: year
-# m: month
-# j or d: day
-# h: hour
-# mn: minute
-# s: second
-# <example> timeadd testname +1m-2mn1s-6y
-# this example adds 1 month and 1 second, and substracts 2 minutes and 6 years at the same time.
-# NOTE: You can not modify a unlimited validity limit.
-# If you want modify it, you want probably create a limited validity limit.
-# So, at first, you must set the validity limit to a date/time.
-#
-# timeset <account_name> yyyy/mm/dd [hh:mm:ss]
-# Changes the validity limit of an account.
-# Default time: 23:59:59
-# timeset <account_name> 0
-# Gives an unlimited validity limit (0 = unlimited).
-#
-# unban/unbanish <account name>
-# Unban an account.
-# Same command of banset 0.
-#
-# unblock <account name>
-# Set state 0 (Account ok) to an account.
-# Same command of state <account_name> 0.
-#
-# version
-# Display the version of the login-server.
-#
-# who <account name>
-# Displays complete information of an account.
-#
-#-------------------------------------------------------------------------
-# Possibilities to execute ladmin in command line by usage of the software with a parameter:
-# ./ladmin --mode param1 ...
-#
-# --makesymlink -- Create the symbolic links for a use in shell
-# --add <account_name> <sex> <password> -- Create an account with the default email (or -a)
-# --ban yyyy/mm/dd hh:mm:ss <account_name> -- Change the final date of a banishment of an account (or -b)
-# --banadd <account_name> <modifier> -- Add or substract time from the final date of a banishment of an account (or - ba)
-# --banset <account_name> yyyy/mm/dd [hh:mm:ss] -- Change the final date of a banishment of an account (or -bs)
-# --banset <account_name> 0 -- Unbanish an account (or -bs)
-# --block <account_name> -- Set state 5 to an account (or -bl)
-# --check <account_name> <password> -- Check the validity of a password for an account (or -check)
-# --create <account_name> <sex> <email> <password> -- Create an account with email (or -c)
-# --del <account_name> -- Remove an account (or -d)
-# --email <account_name> <email> -- Modify an email of an account (or -e)
-# --getcount -- Give the number of players online on all char-servers (or -g)
-# --gm <account_name> <GM_level> -- Change the GM level of an account (or -gm)
-# --id <account_name> -- Give the id of an account (or -i)
-# --info <account_id> -- Display complete information of an account (or -info)
-# --kami <message> -- Sends a broadcast message on all map-server (in yellow).
-# --kamib <message> -- Sends a broadcast message on all map-server (in blue).
-# --language <language> -- Change the language of displaying (-lang).
-# --list [First_id [Last_id]] -- Display a list of accounts (or -l)
-# --listBan [start_id [end_id]] -- Display a list of accounts with state or banished (or -lBan)
-# --listGM [First_id [Last_id]] -- Display a list of GM accounts (or -lGM)
-# --listOK [start_id [end_id]] -- Display a list of accounts without state and not banished (or -lOK)
-# --memo <account_name> <memo> -- Modify the memo of an account (or -e)
-# --name <account_id> -- Give the name of an account (or -n)
-# --passwd <account_name> <new_password> -- Change the password of an account (or -p)
-# --reloadGM -- Reload GM configuration file (or -r)
-# --search <expression> -- Seek accounts (or -s)
-# --search -e/-r/--expr/--regex <expression> -- Seek accounts by REGEX (or -s)
-# --sex <account_name> <sex> -- Change the sex of an account (or -sex)
-# --state <account_name> <new_state> <error_message_#7> -- Change the state of an account (or -t)
-# --timeadd <account_name> <modifier> -- Add or substract time from the validity limit of an account (or - ta)
-# --timeset <account_name> yyyy/mm/dd [hh:mm:ss] -- Change the validify limit of an account (or -ts)
-# --timeset <account_name> 0 -- Give a unlimited validity limit (or -ts)
-# --unban/unbanish <account_name> -- Unban an account (or -uba)
-# --unblock <account_name> -- Set state 0 to an account (or -ubl)
-# --version -- Display the version of the login-server (or -v)
-# --who <account_name> -- Display complete information of an account (or -w)
-#
-# <example> ./ladmin --addaccount testname Male testpass
-#
-#-------------------------------------------------------------------------
-# Possibilities to execute ladmin with symbolic links in Shell
-# To create the symbolic links, execute ladmin with the '-- makesymlink' option.
-#
-# addaccount <account_name> <sex> <password> -- Create an account with the default email
-# banaccount yyyy/mm/dd hh:mm:ss <account_name> -- Change the final date of a banishment of an account
-# banaddaccount <account_name> <modifier> -- Add or substract time from the final date of a banishment of an account
-# bansetaccount <account_name> yyyy/mm/dd [hh:mm:ss] -- Change the final date of a banishment of an account
-# bansetaccount <account_name> 0 -- Unbanish an account
-# blockaccount <account_name> -- Set state 5 (blocked by the GM Team) to an account
-# checkaccount <account_name> <password> -- Check the validity of a password for an account
-# createaccount <account_name> <sex> <email> <password> -- Create an account with email
-# delaccount <account_name> -- Remove an account
-# emailaccount <account_name> <email> -- Modify an email of an account
-# getcount -- Give the number of players online on all char-servers
-# gmaccount <account_name> <GM_level> -- Change the GM level of an account
-# idaccount <account_name> -- Give the id of an account
-# infoaccount <account_id> -- Display complete information of an account
-# kami <message> -- Sends a broadcast message on all map-server (in yellow).
-# kamib <message> -- Sends a broadcast message on all map-server (in blue).
-# ladminlanguage <language> -- Change the language of displaying.
-# listaccount [First_id [Last_id]] -- Display a list of accounts
-# listBanaccount [start_id [end_id]] -- Display a list of accounts with state or banished
-# listGMaccount [First_id [Last_id]] -- Display a list of GM accounts
-# listOKaccount [start_id [end_id]] -- Display a list of accounts without state and not banished
-# loginserverversion -- Display the version of the login-server
-# memoaccount <account_name> <memo> -- Modify the memo of an account
-# nameaccount <account_id> -- Give the name of an account
-# passwdaccount <account_name> <new_password> -- Change the password of an account
-# reloadGM -- Reload GM configuration file
-# searchaccount <expression> -- Seek accounts
-# searchaccount -e/-r/--expr/--regex <expression> -- Seek accounts by REGEX
-# sexaccount <account_name> <sex> -- Change the sex of an account (or -sex)
-# stateaccount <account_name> <new_state> <error_message_#7> -- Change the state of an account
-# timeaddaccount <account_name> <modifier> -- Add or substract time from the validity limit of an account
-# timesetaccount <account_name> yyyy/mm/dd [hh:mm:ss] -- Change the validify limit of an account
-# timesetaccount <account_name> 0 -- Give a unlimited validity limit
-# unbanaccount <account_name> -- Unban an account
-# unblockaccount <account_name> -- Set state 0 (Account ok) to an account
-# whoaccount <account_name> -- Display complete information of an account
-# <exemple> ./addaccount testname Male testpass
-#
-#-------------------------------------------------------------------------
-# About the encoding:
-#
-# The Digest::MD5 module is necessary to use the encrypted password system.
-# When the software cannot found the Digest::MD5 module,
-# encoding is automatically disabled ($passenc=0), which allows
-# to use this program in any cases.
-#
-#-------------------------------------------------------------------------
-# How to use ladmin with UNIX:
-#
-# You excecute ladmin as a standard command.
-# <Example of preparation to have an access to ladmin>
-# $ mv ladmin ladmin_org
-# $ nkf -eLu ladmin_org > ladmin
-# $ chmod 700 ladmin
-# <Example to start directly ladmin>
-# $ perl ladmin
-#
-##########################################################################
-
-
-use strict;
-use IO::Socket;
-use Term::ReadLine;
-eval { use POSIX qw(:termios_h); };
-eval { use Digest::MD5 qw(md5); } if $passenc;
-$passenc = 0 if($@);
-
-my($ver) = "1.00";
-
-# Start of termios
-my($termios, $orgterml, $termlecho, $termlnoecho) = ();
-eval{
- $termios = POSIX::Termios->new();
- $termios->getattr(fileno(STDIN));
- $orgterml = $termios->getlflag();
- $termlecho = ECHO | ECHOK | ICANON;
- $termlnoecho = $orgterml & ~$termlecho;
-};
-
-# Modification of termios for the displaying of passwords (no displays for pressed keys)
-sub cbreak() {
- if ($termios) {
- $termios->setlflag($termlnoecho);
- $termios->setcc(VTIME, 1);
- $termios->setattr(fileno(STDIN), TCSANOW);
- }
-}
-# Modification of termios to return at the normal displaying (after input of the passwords)
-sub cooked() {
- if ($termios) {
- $termios->setlflag($orgterml);
- $termios->setcc(VTIME,0);
- $termios->setattr(fileno(STDIN),TCSANOW);
- }
-}
-END{ cooked() }
-
-if ($defaultlanguage eq "F") {
- print "Outil d'administration à distance de eAthena V.$ver\n";
-} else {
- print "EAthena login-server administration tool V.$ver\n";
-}
-
-# Creation of the symbolic links for call of the program in line command of the shell
-if ($ARGV[0] eq "--makesymlink") {
- symlink $0, "loginserverversion";
- symlink $0, "addaccount";
- symlink $0, "banaccount";
- symlink $0, "banaddaccount";
- symlink $0, "bansetaccount";
- symlink $0, "blockaccount";
- symlink $0, "checkaccount";
- symlink $0, "createaccount";
- symlink $0, "delaccount";
- symlink $0, "emailaccount";
- symlink $0, "getcount";
- symlink $0, "gmaccount";
- symlink $0, "idaccount";
- symlink $0, "infoaccount";
- symlink $0, "kami";
- symlink $0, "kamib";
- symlink $0, "ladminlanguage";
- symlink $0, "listaccount";
- symlink $0, "listBanaccount";
- symlink $0, "listGMaccount";
- symlink $0, "listOKaccount";
- symlink $0, "memoaccount";
- symlink $0, "nameaccount";
- symlink $0, "passwdaccount";
- symlink $0, "reloadGM";
- symlink $0, "searchaccount";
- symlink $0, "sexaccount";
- symlink $0, "stateaccount";
- symlink $0, "timeaddaccount";
- symlink $0, "timesetaccount";
- symlink $0, "unbanaccount";
- symlink $0, "unblockaccount";
- symlink $0, "whoaccount";
- if ($defaultlanguage eq "F") {
- print "Liens symbliques créés.\n";
- } else {
- print "Symbolic links created.\n";
- }
- exit(0);
-}
-
-# Connection to the login-server
-my($so,$er) = ();
-eval{
- $so = IO::Socket::INET->new(
- PeerAddr=> $loginserverip,
- PeerPort=> $loginserverport,
-# Proto => "tcp",
- Timeout => $connecttimeout) or $er = 1;
-};
-if ($er || $@) {
- if ($defaultlanguage eq "F") {
- print "\nImpossible de se connecter au serveur de login [${loginserverip}:$loginserverport] !\n";
- } else {
- print "\nImpossible to have a connection with the login-server [${loginserverip}:$loginserverport] !\n";
- }
- print "$!\n"; # Displaying of the error
- exit(2);
-}
-
-# Sending the administration password
-if ($passenc == 0) {
- print $so pack("v2a24",0x7918,0,$loginserveradminpassword);
- $so->flush();
-} else {
- print $so pack("v",0x791a);
- $so->flush();
- my($buf) = readso(4);
- if (unpack("v",$buf) != 0x01dc) {
- if ($defaultlanguage eq "F") {
- print "Erreur au login (échec de la création de la clef md5).\n";
- } else {
- print "Error at login (failure of the md5 key creation).\n";
- }
- }
- $buf = readso(unpack("x2v",$buf)-4);
- my($md5bin) = md5(($passenc == 1) ? $buf.$loginserveradminpassword : $loginserveradminpassword.$buf);
- print $so pack("v2a16",0x7918,$passenc,$md5bin);
- $so->flush();
-}
-
-# Waiting of the server reply
-my($buf) = readso(3);
-
-if (unpack("v",$buf) != 0x7919 || unpack("x2c",$buf) != 0) {
- if ($defaultlanguage eq "F") {
- print "Erreur de login:\n";
- print " - mot de passe incorrect,\n";
- print " - système d'administration non activé, ou\n";
- print " - IP non autorisée.\n";
- } else {
- print "Error at login:\n";
- print " - incorrect password,\n";
- print " - administration system not activated, or\n";
- print " - unauthorised IP.\n";
- }
- quit();
- exit(4);
-}
-
-if ($defaultlanguage eq "F") {
- print "Connexion établie.\n";
-} else {
- print "Established connection.\n";
-}
-
-#-------------------------------------------------------------------------
-# Here are checked the command lines with arguments and symbolic links (no prompt)
-
-if ($0 =~ /addaccount$/ ||
- (($ARGV[0] eq "-a" || $ARGV[0] eq "--add") && ((shift @ARGV), 1))) {
- my($r) = addaccount($ARGV[0], $ARGV[1], $ARGV[2]);
- quit();
- exit($r);
-} elsif ($0 =~ /banaccount$/ || $0 =~ /banishaccount$/ ||
- (($ARGV[0] eq "-b" || $ARGV[0] eq "--ban" || $ARGV[0] eq "--banish") && ((shift @ARGV), 1))) {
- my($r) = bansetaccount($ARGV[1], $ARGV[2], $ARGV[0]);
- quit();
- exit($r);
-} elsif ($0 =~ /banaddaccount$/ ||
- (($ARGV[0] eq "-ba" || $ARGV[0] eq "--banadd") && ((shift @ARGV), 1))) {
- my($r) = banaddaccount($ARGV[0], $ARGV[1]);
- quit();
- exit($r);
-} elsif ($0 =~ /bansetaccount$/ ||
- (($ARGV[0] eq "-bs" || $ARGV[0] eq "--banset") && ((shift @ARGV), 1))) {
- my($r) = bansetaccount($ARGV[0], $ARGV[1], $ARGV[2]);
- quit();
- exit($r);
-} elsif ($0 =~ /blockaccount$/ ||
- (($ARGV[0] eq "-bl" || $ARGV[0] eq "--block") && ((shift @ARGV), 1))) {
- my($r) = changestate($ARGV[0], 5, "");
- quit();
- exit($r);
-} elsif ($0 =~ /checkaccount$/ ||
- (($ARGV[0] eq "-check" || $ARGV[0] eq "--check") && ((shift @ARGV), 1))) {
- my($r) = checkaccount($ARGV[0], $ARGV[1]);
- quit();
- exit($r);
-} elsif ($0 =~ /createaccount$/ ||
- (($ARGV[0] eq "-c" || $ARGV[0] eq "--create") && ((shift @ARGV), 1))) {
- my($r) = createaccount($ARGV[0], $ARGV[1], $ARGV[2], $ARGV[3]);
- quit();
- exit($r);
-} elsif ($0 =~ /delaccount$/ ||
- (($ARGV[0] eq "-d" || $ARGV[0] eq "--del") && ((shift @ARGV), 1))) {
- my($r) = delaccount($ARGV[0]);
- quit();
- exit($r);
-} elsif ($0 =~ /emailaccount$/ ||
- (($ARGV[0] eq "-e" || $ARGV[0] eq "--email") && ((shift @ARGV), 1))) {
- my($r) = changeemail($ARGV[0], $ARGV[1]);
- quit();
- exit($r);
-} elsif ($0 =~ /getcount$/ ||
- (($ARGV[0] eq "-g" || $ARGV[0] eq "--getcount") && ((shift @ARGV), 1))) {
- my($r) = getlogincount();
- quit();
- exit($r);
-} elsif ($0 =~ /gmaccount$/ ||
- (($ARGV[0] eq "-gm" || $ARGV[0] eq "--gm") && ((shift @ARGV), 1))) {
- my($r) = changegmlevel($ARGV[0], $ARGV[1]);
- quit();
- exit($r);
-} elsif ($0 =~ /id$/ ||
- (($ARGV[0] eq "-i" || $ARGV[0] eq "--id") && ((shift @ARGV), 1))) {
- my($r) = idaccount($ARGV[0]);
- quit();
- exit($r);
-} elsif ($0 =~ /infoaccount$/ ||
- (($ARGV[0] eq "-info" || $ARGV[0] eq "--info") && ((shift @ARGV), 1))) {
- my($r) = infoaccount($ARGV[0]);
- quit();
- exit($r);
-} elsif ($0 =~ /kami$/ ||
- (($ARGV[0] eq "-kami" || $ARGV[0] eq "--kami") && ((shift @ARGV), 1))) {
- my($r) = sendbroadcast(0, $ARGV[0]);
- quit();
- exit($r);
-} elsif ($0 =~ /kamib$/ ||
- (($ARGV[0] eq "-kamib" || $ARGV[0] eq "--kamib") && ((shift @ARGV), 1))) {
- my($r) = sendbroadcast(0x10, $ARGV[0]);
- quit();
- exit($r);
-} elsif ($0 =~ /ladminlanguage$/ ||
- (($ARGV[0] eq "-lang" || $ARGV[0] eq "--language") && ((shift @ARGV), 1))) {
- my($r) = changelanguage($ARGV[0]);
- quit();
- exit($r);
-} elsif ($0 =~ /listaccount$/ ||
- (($ARGV[0] eq "-l" || $ARGV[0] eq "--list") && ((shift @ARGV), 1))) {
- my($r) = listaccount(int($ARGV[0]), int($ARGV[1]), 0); # 0: to list all
- quit();
- exit($r);
-} elsif ($0 =~ /listBanaccount$/ ||
- (($ARGV[0] eq "-lBan" || $ARGV[0] eq "--listBan") && ((shift @ARGV), 1))) {
- my($r) = listaccount(int($ARGV[0]), int($ARGV[1]), 3); # 3: to list only accounts with state or banished
- quit();
- exit($r);
-} elsif ($0 =~ /listGMaccount$/ ||
- (($ARGV[0] eq "-lGM" || $ARGV[0] eq "--listGM") && ((shift @ARGV), 1))) {
- my($r) = listaccount(int($ARGV[0]), int($ARGV[1]), 1); # 1: to list only GM
- quit();
- exit($r);
-} elsif ($0 =~ /listOKaccount$/ ||
- (($ARGV[0] eq "-lOK" || $ARGV[0] eq "--listOK") && ((shift @ARGV), 1))) {
- my($r) = listaccount(int($ARGV[0]), int($ARGV[1]), 4); # 4: to list only accounts without state and not banished
- quit();
- exit($r);
-} elsif ($0 =~ /loginserverversion$/ ||
- (($ARGV[0] eq "-v" || $ARGV[0] eq "--version") && ((shift @ARGV), 1))) {
- my($r) = checkloginversion();
- quit();
- exit($r);
-} elsif ($0 =~ /memoaccount$/ ||
- (($ARGV[0] eq "-m" || $ARGV[0] eq "--memo") && ((shift @ARGV), 1))) {
- my($r) = changememo($ARGV[0], $ARGV[1]);
- quit();
- exit($r);
-} elsif ($0 =~ /nameaccount$/ ||
- (($ARGV[0] eq "-n" || $ARGV[0] eq "--name") && ((shift @ARGV), 1))) {
- my($r) = nameaccount(int($ARGV[0]));
- quit();
- exit($r);
-} elsif ($0 =~ /passwdaccount$/ ||
- (($ARGV[0] eq "-p" || $ARGV[0] eq "--passwd") && ((shift @ARGV), 1))) {
- my($r) = changepasswd($ARGV[0], $ARGV[1]);
- quit();
- exit($r);
-} elsif ($0 =~ /reloadGM$/ ||
- (($ARGV[0] eq "-r" || $ARGV[0] eq "--reloadGM") && ((shift @ARGV), 1))) {
- my($r) = reloadGM();
- quit();
- exit($r);
-} elsif ($0 =~ /searchaccount$/ ||
- (($ARGV[0] eq "-s" || $ARGV[0] eq "--search") && ((shift @ARGV), 1))) {
- my($r) = searchaccount($ARGV[0], $ARGV[1]);
- quit();
- exit($r);
-} elsif ($0 =~ /sexaccount$/ ||
- (($ARGV[0] eq "-sex" || $ARGV[0] eq "--sex") && ((shift @ARGV), 1))) {
- my($r) = changesex($ARGV[0], $ARGV[1]);
- quit();
- exit($r);
-} elsif ($0 =~ /stateaccount$/ ||
- (($ARGV[0] eq "-t" || $ARGV[0] eq "--state") && ((shift @ARGV), 1))) {
- my($r) = changestate($ARGV[0], $ARGV[1], $ARGV[2]);
- quit();
- exit($r);
-} elsif ($0 =~ /timeaddaccount$/ ||
- (($ARGV[0] eq "-ta" || $ARGV[0] eq "--timeadd") && ((shift @ARGV), 1))) {
- my($r) = timeaddaccount($ARGV[0], $ARGV[1]);
- quit();
- exit($r);
-} elsif ($0 =~ /timesetaccount$/ ||
- (($ARGV[0] eq "-ts" || $ARGV[0] eq "--timeset") && ((shift @ARGV), 1))) {
- my($r) = timesetaccount($ARGV[0], $ARGV[1], $ARGV[2]);
- quit();
- exit($r);
-} elsif ($0 =~ /unbanaccount$/ || $0 =~ /unbanishaccount$/ ||
- (($ARGV[0] eq "-uba" || $ARGV[0] eq "--unban" || $ARGV[0] eq "--unbanish") && ((shift @ARGV), 1))) {
- my($r) = bansetaccount($ARGV[0], 0, "");
- quit();
- exit($r);
-} elsif ($0 =~ /unblockaccount$/ ||
- (($ARGV[0] eq "-ubl" || $ARGV[0] eq "--unblock") && ((shift @ARGV), 1))) {
- my($r) = changestate($ARGV[0], 0, "");
- quit();
- exit($r);
-} elsif ($0 =~ /whoaccount$/ ||
- (($ARGV[0] eq "-w" || $ARGV[0] eq "--who") && ((shift @ARGV), 1))) {
- my($r) = whoaccount($ARGV[0]);
- quit();
- exit($r);
-}
-
-#-------------------------------------------------------------------------
-if ($defaultlanguage eq "F") {
- print "Lecture de la version du serveur de login...\n";
-} else {
- print "Reading of the version of the login-server...\n";
-}
-checkloginversion();
-
-# Set the prompt line
-my($term) = new Term::ReadLine "ladmin";
-
-# Here begin the infinite loop to read prompts
-while(1) {
- # Displaying of the prompt
- print "\n";
- if ($defaultlanguage eq "F") {
- printf "\033[32mPour afficher les commandes, tapez 'Entrée'.\033[0m\n";
- } else {
- printf "\033[32mTo list the commands, type 'enter'.\033[0m\n";
- }
- my($cmd) = $term->readline("ladmin> ");
- # split and recovery of the input
- chomp $cmd; # remove cariage return
- $cmd =~ s/\x1b\[\d*\w//g; # remove (esc)[(number)(1alpha) = screen control sequence
- $cmd =~ s/[\x00-\x1f]//g; # remove control char
- my($command, $parameters) = split /\s+/,$cmd,2; # extract command and parameters
- $command = lc($command); # command in lowercase
- my(@paramlist) = split /\s+/,$parameters; # get list of parameters
-
- if ($command eq "?" || $command eq "") {
- $command = "aide" if ($defaultlanguage eq "F");
- $command = "help" if ($defaultlanguage ne "F");
- }
-
- # Analyse of the command
- eval {
-# help
- if ("aide" =~ /^\Q$command/ && $command ne "a") { # check 1 letter command: 'aide' or 'add'?
- displayhelp("aide", $paramlist[0]);
- } elsif ("help" =~ /^\Q$command/) {
- displayhelp("help", $paramlist[0]);
-
-# general commands
- } elsif ("add" =~ /^\Q$command/ && $command ne "a") { # check 1 letter command: 'aide' or 'add'?
- if (@paramlist = ($parameters =~ m/^"(.*)"\s+(\S+)\s+(.*)/)) {
- addaccount($paramlist[0], $paramlist[1], $paramlist[2]); # <account_name> <sex> <password>
- } elsif (@paramlist = ($parameters =~ m/^"(.*)"\s+(\S+)/)) {
- addaccount($paramlist[0], $paramlist[1], ""); # <account_name> <sex> <password>
- } elsif (@paramlist = ($parameters =~ m/^'(.*)'\s+(\S+)\s+(.*)/)) {
- addaccount($paramlist[0], $paramlist[1], $paramlist[2]); # <account_name> <sex> <password>
- } elsif (@paramlist = ($parameters =~ m/^'(.*)'\s+(\S+)/)) {
- addaccount($paramlist[0], $paramlist[1], ""); # <account_name> <sex> <password>
- } else {
- @paramlist = split /\s+/,$parameters;
- addaccount($paramlist[0], $paramlist[1], $paramlist[2]); # <account_name> <sex> <password>
- }
-
- } elsif ($command eq "ban" || ("banish" =~ /^\Q$command/ && length($command) >= 4)) {
- if (@paramlist = ($parameters =~ m/^(\S+)\s+(\S+)\s+"(.*)"/)) { # yyyy/mm/dd hh:mm:ss <account_name>
- bansetaccount($paramlist[2], $paramlist[0], $paramlist[1]); # <account_name> yyyy/mm/dd [hh:mm:ss]
- } elsif (@paramlist = ($parameters =~ m/^(\S+)\s+(\S+)\s+'(.*)'/)) { # yyyy/mm/dd hh:mm:ss <account_name>
- bansetaccount($paramlist[2], $paramlist[0], $paramlist[1]); # <account_name> yyyy/mm/dd [hh:mm:ss]
- } else {
- @paramlist = split /\s+/,$parameters,3; # yyyy/mm/dd hh:mm:ss <account_name>
- bansetaccount($paramlist[2], $paramlist[0], $paramlist[1]); # <account_name> yyyy/mm/dd [hh:mm:ss]
- }
-
- } elsif (("banadd" =~ /^\Q$command/ || $command eq "ba") && $command ne "b") { # check 1 letter command: 'ba' or 'bs'?
- if (@paramlist = ($parameters =~ m/^"(.*)"\s+(\S+)/)) {
- banaddaccount($paramlist[0], $paramlist[1]); # <account_name> <modifier>
- } elsif (@paramlist = ($parameters =~ m/^'(.*)'\s+(\S+)/)) {
- banaddaccount($paramlist[0], $paramlist[1]); # <account_name> <modifier>
- } else {
- @paramlist = split /\s+/,$parameters;
- banaddaccount($paramlist[0], $paramlist[1]); # <account_name> <modifier>
- }
-
- } elsif (("banset" =~ /^\Q$command/ || $command eq "bs") && $command ne "b") { # check 1 letter command: 'ba' or 'bs'?
- if (@paramlist = ($parameters =~ m/^"(.*)"\s+(\S+)\s+(\S+)/)) {
- bansetaccount($paramlist[0], $paramlist[1], $paramlist[2]); # <account_name> yyyy/mm/dd [hh:mm:ss]
- } elsif (@paramlist = ($parameters =~ m/^"(.*)"\s+(\S+)/)) {
- bansetaccount($paramlist[0], $paramlist[1], "23:59:59"); # <account_name> yyyy/mm/dd [hh:mm:ss]
- } elsif (@paramlist = ($parameters =~ m/^'(.*)'\s+(\S+)\s+(\S+)/)) {
- bansetaccount($paramlist[0], $paramlist[1], $paramlist[2]); # <account_name> yyyy/mm/dd [hh:mm:ss]
- } elsif (@paramlist = ($parameters =~ m/^'(.*)'\s+(\S+)/)) {
- bansetaccount($paramlist[0], $paramlist[1], "23:59:59"); # <account_name> yyyy/mm/dd [hh:mm:ss]
- } else {
- @paramlist = split /\s+/,$parameters;
- bansetaccount($paramlist[0], $paramlist[1], $paramlist[2]); # <account_name> yyyy/mm/dd [hh:mm:ss]
- }
-
- } elsif ("block" =~ /^\Q$command/ && length($command) >= 2) {
- if (@paramlist = ($parameters =~ m/^"(.*)"/)) {
- changestate($paramlist[0], 5, ""); # <account_name> <new_state> <error_message_#7>
- } elsif (@paramlist = ($parameters =~ m/^'(.*)'/)) {
- changestate($paramlist[0], 5, ""); # <account_name> <new_state> <error_message_#7>
- } else {
- @paramlist = split /\s+/,$parameters,1;
- changestate($paramlist[0], 5, ""); # <account_name> <new_state> <error_message_#7>
- }
-
- } elsif ("check" =~ /^\Q$command/ && $command ne "c") { # check 1 letter command: 'check' or 'create'?
- if (@paramlist = ($parameters =~ m/^"(.*)"\s+(.*)/)) {
- checkaccount($paramlist[0], $paramlist[1]); # <account_name> <password>
- } elsif (@paramlist = ($parameters =~ m/^"(.*)"/)) {
- checkaccount($paramlist[0], ""); # <account_name> <password>
- } elsif (@paramlist = ($parameters =~ m/^'(.*)'\s+(.*)/)) {
- checkaccount($paramlist[0], $paramlist[1]); # <account_name> <password>
- } elsif (@paramlist = ($parameters =~ m/^'(.*)'/)) {
- checkaccount($paramlist[0], ""); # <account_name> <password>
- } else {
- @paramlist = split /\s+/,$parameters;
- checkaccount($paramlist[0], $paramlist[1]); # <account_name> <password>
- }
-
- } elsif ("create" =~ /^\Q$command/ && $command ne "c") { # check 1 letter command: 'check' or 'create'?
- if (@paramlist = ($parameters =~ m/^"(.*)"\s+(\S+)\s+(\S+)\s+(.*)/)) {
- createaccount($paramlist[0], $paramlist[1], $paramlist[2], $paramlist[3]); # <account_name> <sex> <email> <password>
- } elsif (@paramlist = ($parameters =~ m/^"(.*)"\s+(\S+)\s+(\S+)/)) {
- createaccount($paramlist[0], $paramlist[1], $paramlist[2], ""); # <account_name> <sex> <email> <password>
- } elsif (@paramlist = ($parameters =~ m/^'(.*)'\s+(\S+)\s+(\S+)\s+(.*)/)) {
- createaccount($paramlist[0], $paramlist[1], $paramlist[2], $paramlist[3]); # <account_name> <sex> <email> <password>
- } elsif (@paramlist = ($parameters =~ m/^'(.*)'\s+(\S+)\s+(\S+)/)) {
- createaccount($paramlist[0], $paramlist[1], $paramlist[2], ""); # <account_name> <sex> <email> <password>
- } else {
- @paramlist = split /\s+/,$parameters;
- createaccount($paramlist[0], $paramlist[1], $paramlist[2], $paramlist[3]); # <account_name> <sex> <email> <password>
- }
-
- } elsif ("del" =~ /^\Q$command/ || "delete" =~ /^\Q$command/) {
- if (@paramlist = ($parameters =~ m/^"(.*)"/)) {
- delaccount($paramlist[0]); # <account_name>
- } elsif (@paramlist = ($parameters =~ m/^'(.*)'/)) {
- delaccount($paramlist[0]); # <account_name>
- } else {
- @paramlist = split /\s+/,$parameters,1;
- delaccount($paramlist[0]); # <account_name>
- }
-
- } elsif ("email" =~ /^\Q$command/ && $command ne "e") { # check 1 letter command: 'email', 'end' or 'exit'?
- if (@paramlist = ($parameters =~ m/^"(.*)"\s+(\S+)/)) {
- changeemail($paramlist[0], $paramlist[1]); # <account_name> <email>
- } elsif (@paramlist = ($parameters =~ m/^'(.*)'\s+(\S+)/)) {
- changeemail($paramlist[0], $paramlist[1]); # <account_name> <email>
- } else {
- @paramlist = split /\s+/,$parameters;
- changeemail($paramlist[0], $paramlist[1]); # <account_name> <email>
- }
-
- } elsif ("getcount" =~ /^\Q$command/ && $command ne "g") { # check 1 letter command: 'getcount' or 'gm'?
- getlogincount();
-
- } elsif ("gm" =~ /^\Q$command/ && $command ne "g") { # check 1 letter command: 'getcount' or 'gm'?
- if (@paramlist = ($parameters =~ m/^"(.*)"\s+(\S+)/)) {
- changegmlevel($paramlist[0], int($paramlist[1])); # <account_name> <GM_level>
- } elsif (@paramlist = ($parameters =~ m/^"(.*)"/)) {
- changegmlevel($paramlist[0], 0); # <account_name> <GM_level>
- } elsif (@paramlist = ($parameters =~ m/^'(.*)'\s+(\S+)/)) {
- changegmlevel($paramlist[0], int($paramlist[1])); # <account_name> <GM_level>
- } elsif (@paramlist = ($parameters =~ m/^'(.*)'/)) {
- changegmlevel($paramlist[0], 0); # <account_name> <GM_level>
- } else {
- @paramlist = split /\s+/,$parameters;
- changegmlevel($paramlist[0], int($paramlist[1])); # <account_name> <GM_level>
- }
-
- } elsif ("id" =~ /^\Q$command/ && $command ne "i") { # check 1 letter command: 'id' or 'info'?
- if (@paramlist = ($parameters =~ m/^"(.*)"/)) {
- idaccount($paramlist[0]); # <account_name>
- } elsif (@paramlist = ($parameters =~ m/^'(.*)'/)) {
- idaccount($paramlist[0]); # <account_name>
- } else {
- @paramlist = split /\s+/,$parameters,1;
- idaccount($paramlist[0]); # <account_name>
- }
-
- } elsif ("info" =~ /^\Q$command/ && $command ne "i") { # check 1 letter command: 'id' or 'info'?
- infoaccount(int($paramlist[0])); # <account_id>
-
- } elsif ($command eq "kami") { # check all letters command: 'kami' or 'kamib'?
- @paramlist = split /\s+/,$parameters,1;
- sendbroadcast(0, $paramlist[0]); # <type> <message>
-
- } elsif ($command eq "kamib") { # check all letters command: 'kami' or 'kamib'?
- @paramlist = split /\s+/,$parameters,1;
- sendbroadcast(0x10, $paramlist[0]); # <type> <message>
-
- } elsif ("language" =~ /^\Q$command/ && $command ne "l") { # check 1 letter command: 'list' or 'language'?
- changelanguage($paramlist[0]); # <language>
-
- } elsif (("list" =~ /^\Q$command/ || $command eq "ls") && $command ne "l") { # check 1 letter command: 'list' or 'language'?
- listaccount(int($paramlist[0]), int($paramlist[1]), 0); # [start_id [end_id]] 0: to list all
-
- } elsif (("listban" =~ /^\Q$command/ || $command eq "lsban") && $command ne "l") { # need to specificaly write Ban to have this list # check 1 letter command: 'list' or 'language'?
- listaccount(int($paramlist[0]), int($paramlist[1]), 3); # [start_id [end_id]] 3: to list only accounts with state or banished
-
- } elsif (("listgm" =~ /^\Q$command/ || $command eq "lsgm") && $command ne "l") { # need to specificaly write GM to have this list # check 1 letter command: 'list' or 'language'?
- listaccount(int($paramlist[0]), int($paramlist[1]), 1); # [start_id [end_id]] 1: to list only GM
-
- } elsif (("listok" =~ /^\Q$command/ || $command eq "lsok") && $command ne "l") { # need to specificaly write OK to have this list # check 1 letter command: 'list' or 'language'?
- listaccount(int($paramlist[0]), int($paramlist[1]), 4); # [start_id [end_id]] 4: to list only accounts without state and not banished
-
- } elsif ("memo" =~ /^\Q$command/) {
- if (@paramlist = ($parameters =~ m/^"(.*)"\s+(.*)/)) {
- changememo($paramlist[0], $paramlist[1]); # <account_name> <memo>
- } elsif (@paramlist = ($parameters =~ m/^'(.*)'\s+(.*)/)) {
- changememo($paramlist[0], $paramlist[1]); # <account_name> <memo>
- } else {
- @paramlist = split /\s+/,$parameters,2;
- changememo($paramlist[0], $paramlist[1]); # <account_name> <memo>
- }
-
- } elsif ("name" =~ /^\Q$command/) {
- nameaccount(int($paramlist[0])); # <account_id>
-
- } elsif ("passwd" =~ /^\Q$command/ || "password" =~ /^\Q$command/) {
- if (@paramlist = ($parameters =~ m/^"(.*)"\s+(.*)/)) {
- changepasswd($paramlist[0], $paramlist[1]); # <account_name> <new_password>
- } elsif (@paramlist = ($parameters =~ m/^"(.*)"/)) {
- changepasswd($paramlist[0], ""); # <account_name> <new_password>
- } elsif (@paramlist = ($parameters =~ m/^'(.*)'\s+(.*)/)) {
- changepasswd($paramlist[0], $paramlist[1]); # <account_name> <new_password>
- } elsif (@paramlist = ($parameters =~ m/^'(.*)'/)) {
- changepasswd($paramlist[0], ""); # <account_name> <new_password>
- } else {
- @paramlist = split /\s+/,$parameters,2;
- changepasswd($paramlist[0], $paramlist[1]); # <account_name> <new_password>
- }
-
- } elsif ("reloadgm" =~ /^\Q$command/) {
- reloadGM();
-
- } elsif ("search" =~ /^\Q$command/ && $command ne "s" && # check 1 letter command: 'search', 'state' or 'sex'?
- $command ne "se") { # check 2 letters command: 'search' or 'sex'?
- if (@paramlist = ($parameters =~ m/^(-{1,2}[re]\S*)\s+(.*)/)) {
- searchaccount($paramlist[0], $paramlist[1]); # -r/-e/--expr/--regex <expression> | <expression>
- } else {
- @paramlist = split /\s+/,$parameters,1;
- searchaccount($paramlist[0], ""); # -r/-e/--expr/--regex <expression> | <expression>
- }
-
- } elsif ("sex" =~ /^\Q$command/ && $command ne "s" && # check 1 letter command: 'search', 'state' or 'sex'?
- $command ne "se") { # check 2 letters command: 'search' or 'sex'?
- if (@paramlist = ($parameters =~ m/^"(.*)"\s+(\S+)/)) {
- changesex($paramlist[0], $paramlist[1]); # <account_name> <sex>
- } elsif (@paramlist = ($parameters =~ m/^'(.*)'\s+(\S+)/)) {
- changesex($paramlist[0], $paramlist[1]); # <account_name> <sex>
- } else {
- @paramlist = split /\s+/,$parameters;
- changesex($paramlist[0], $paramlist[1]); # <account_name> <sex>
- }
-
- } elsif ("state" =~ /^\Q$command/ && $command ne "s") { # check 1 letter command: 'search', 'state' or 'sex'?
- if (@paramlist = ($parameters =~ m/^"(.*)"\s+(\d+)\s+(.*)/)) {
- changestate($paramlist[0], int($paramlist[1]), $paramlist[2]); # <account_name> <new_state> <error_message_#7>
- } elsif (@paramlist = ($parameters =~ m/^"(.*)"\s+(\d+)/)) {
- changestate($paramlist[0], int($paramlist[1]), ""); # <account_name> <new_state> <error_message_#7>
- } elsif (@paramlist = ($parameters =~ m/^'(.*)'\s+(\d+)\s+(.*)/)) {
- changestate($paramlist[0], int($paramlist[1]), $paramlist[2]); # <account_name> <new_state> <error_message_#7>
- } elsif (@paramlist = ($parameters =~ m/^'(.*)'\s+(\d+)/)) {
- changestate($paramlist[0], int($paramlist[1]), ""); # <account_name> <new_state> <error_message_#7>
- } else {
- @paramlist = split /\s+/,$parameters,3;
- changestate($paramlist[0], int($paramlist[1]), $paramlist[2]); # <account_name> <new_state> <error_message_#7>
- }
-
- } elsif (("timeadd" =~ /^\Q$command/ || $command eq "ta") && $command ne "t") { # check 1 letter command: 'ta' or 'ts'?
- if (@paramlist = ($parameters =~ m/^"(.*)"\s+(\S+)/)) {
- timeaddaccount($paramlist[0], $paramlist[1]); # <account_name> <modifier>
- } elsif (@paramlist = ($parameters =~ m/^'(.*)'\s+(\S+)/)) {
- timeaddaccount($paramlist[0], $paramlist[1]); # <account_name> <modifier>
- } else {
- @paramlist = split /\s+/,$parameters;
- timeaddaccount($paramlist[0], $paramlist[1]); # <account_name> <modifier>
- }
-
- } elsif (("timeset" =~ /^\Q$command/ || $command eq "ts") && $command ne "t") { # check 1 letter command: 'ta' or 'ts'?
- if (@paramlist = ($parameters =~ m/^"(.*)"\s+(\S+)\s+(\S+)/)) {
- timesetaccount($paramlist[0], $paramlist[1], $paramlist[2]); # <account_name> yyyy/mm/dd [hh:mm:ss]
- } elsif (@paramlist = ($parameters =~ m/^"(.*)"\s+(\S+)/)) {
- timesetaccount($paramlist[0], $paramlist[1], "23:59:59"); # <account_name> yyyy/mm/dd [hh:mm:ss]
- } elsif (@paramlist = ($parameters =~ m/^'(.*)'\s+(\S+)\s+(\S+)/)) {
- timesetaccount($paramlist[0], $paramlist[1], $paramlist[2]); # <account_name> yyyy/mm/dd [hh:mm:ss]
- } elsif (@paramlist = ($parameters =~ m/^'(.*)'\s+(\S+)/)) {
- timesetaccount($paramlist[0], $paramlist[1], "23:59:59"); # <account_name> yyyy/mm/dd [hh:mm:ss]
- } else {
- @paramlist = split /\s+/,$parameters;
- timesetaccount($paramlist[0], $paramlist[1], $paramlist[2]); # <account_name> yyyy/mm/dd [hh:mm:ss]
- }
-
- } elsif ($command eq "unban" || ("unbanish" =~ /^\Q$command/ && length($command) >= 4)) {
- if (@paramlist = ($parameters =~ m/^"(.*)"/)) {
- bansetaccount($paramlist[0], 0, ""); # <account_name> yyyy/mm/dd [hh:mm:ss]
- } elsif (@paramlist = ($parameters =~ m/^'(.*)'/)) {
- bansetaccount($paramlist[0], 0, ""); # <account_name> yyyy/mm/dd [hh:mm:ss]
- } else {
- @paramlist = split /\s+/,$parameters,1;
- bansetaccount($paramlist[0], 0, ""); # <account_name> yyyy/mm/dd [hh:mm:ss]
- }
-
- } elsif ("unblock" =~ /^\Q$command/ && length($command) >= 4) {
- if (@paramlist = ($parameters =~ m/^"(.*)"/)) {
- changestate($paramlist[0], 0, ""); # <account_name> <new_state> <error_message_#7>
- } elsif (@paramlist = ($parameters =~ m/^'(.*)'/)) {
- changestate($paramlist[0], 0, ""); # <account_name> <new_state> <error_message_#7>
- } else {
- @paramlist = split /\s+/,$parameters,1;
- changestate($paramlist[0], 0, ""); # <account_name> <new_state> <error_message_#7>
- }
-
- } elsif ("version" =~ /^\Q$command/) {
- checkloginversion();
-
- } elsif ("who" =~ /^\Q$command/) {
- if (@paramlist = ($parameters =~ m/^"(.*)"/)) {
- whoaccount($paramlist[0]); # <account_name>
- } elsif (@paramlist = ($parameters =~ m/^'(.*)'/)) {
- whoaccount($paramlist[0]); # <account_name>
- } else {
- @paramlist = split /\s+/,$parameters,1;
- whoaccount($paramlist[0]); # <account_name>
- }
-
-# quit
- } elsif ("quit" =~ /^\Q$command/ ||
- (("end" =~ /^\Q$command/ || "exit" =~ /^\Q$command/) && $command ne "e")) { # check 1 letter command: 'email', 'end' or 'exit'?
- last;
-
-# unknown command
- } elsif ($command) {
- if ($defaultlanguage eq "F") {
- print "Commande inconnue [".$command."]\n";
- } else {
- print "Unknown command [".$command."]\n";
- }
- }
-# $term->addhistory($cmd) if $command;
- };
- if ($@) {
- if ($defaultlanguage eq "F") {
- print "Erreur [".$command."]\n$@";
- } else {
- print "Error [".$command."]\n$@";
- }
- }
-};
-
-# End of the software
-quit();
-
-if ($defaultlanguage eq "F") {
- print "Au revoir.\n";
-} else {
- print "Bye.\n";
-}
-exit(0);
-
-#--------------------------------------------------------------------------
-
-# Sub-function: Displaying of the version of the login-server
-sub checkloginversion() {
- print $so pack("v",30000); # 0x7530
- $so->flush();
- $buf = readso(10);
- # Analyse du Packet
- my($ret, $maver, $miver, $rev, $dev, $mod, $type, $mdver) = unpack("vc6v", $buf);
- if ($ret != 30001) { #0x7531
- if ($defaultlanguage eq "F") {
- print "Problème de connexion au serveur (réponse incorrecte).\n";
- } else {
- print "Connection error to the server (incorrect answer).\n";
- }
- exit(6);
- }
-
- print " Login-Server [$loginserverip:$loginserverport]\n";
- printf " eAthena version %s-%d.%d", ("stable", "dev")[$dev], $maver, $miver;
- printf " revision %d", $rev if $rev;
- printf "%s%d.\n", ("", "-mod")[$mod], $mdver;
- return 0;
-}
-
-#--------------------------------------------------------------------------
-
-# Sub-function: Displaying of the help
-sub displayhelp() {
- my($help, $receivedcommand) = @_;
-
- my($command) = lc($receivedcommand); # command in lowercase
-
- if ($command eq "") {
- $command = "not a command"; # any value that is not a command
- }
-
- if ($command eq "?") {
- $command = "aide" if ($defaultlanguage eq "F");
- $command = "help" if ($defaultlanguage ne "F");
- }
-
- if ($help eq "aide") {
- if ("aide" =~ /^\Q$command/ && $command ne "a") { # check 1 letter command: 'aide' or 'add'?
- printf "aide/help/?\n";
- printf " Affiche la description des commandes\n";
- printf "aide/help/? [commande]\n";
- printf " Affiche la description de la commande specifiée\n";
- } elsif ("help" =~ /^\Q$command/) {
- printf "aide/help/?\n";
- printf " Display the description of the commands\n";
- printf "aide/help/? [command]\n";
- printf " Display the description of the specified command\n";
- } elsif ("add" =~ /^\Q$command/ && $command ne "a") { # check 1 letter command: 'aide' or 'add'?
- printf "add <nomcompte> <sexe> <motdepasse>\n";
- printf " Crée un compte avec l'email par défaut (a\@a.com).\n";
- printf " Concernant le sexe, seule la première lettre compte (F ou M).\n";
- printf " 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 " <exemple> add testname Male testpass\n";
- } elsif ($command eq "ban" || ("banish" =~ /^\Q$command/ && length($command) >= 4)) {
- printf "ban/banish aaaa/mm/jj hh:mm:ss <nomcompte>\n";
- printf " Change la date de fin de bannissement d'un compte.\n";
- printf " La différence avec banset est la position du nom du compte.\n";
- } elsif (("banadd" =~ /^\Q$command/ || $command eq "ba") && $command ne "b") { # check 1 letter command: 'ba' or 'bs'?
- printf "banadd <nomcompte> <Modificateur>\n";
- printf " 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 " 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";
- printf " mn: minute\n";
- printf " s: seconde\n";
- printf " <exemple> 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 même temps.\n";
- printf "NOTE: Si vous modifez la date de banissement d'un compte non bani,\n";
- printf " vous indiquez comme date (le moment actuel +- les ajustements)\n";
- } elsif (("banset" =~ /^\Q$command/ || $command eq "bs") && $command ne "b") { # check 1 letter command: 'ba' or 'bs'?
- printf "banset <nomcompte> aaaa/mm/jj [hh:mm:ss]\n";
- printf " Change la date de fin de bannissement d'un compte.\n";
- printf " Heure par défaut: 23:59:59\n";
- printf "banset <nomcompte> 0\n";
- printf " Débanni un compte (0 = de-banni).\n";
- } elsif ("block" =~ /^\Q$command/ && length($command) >= 2) {
- printf "block <nom compte>\n";
- printf " Place le status d'un compte à 5 (You have been blocked by the GM Team).\n";
- printf " La commande est l'équivalent de state <nom_compte> 5.\n";
- } elsif ("check" =~ /^\Q$command/ && $command ne "c") { # check 1 letter command: 'check' or 'create'?
- printf "check <nomcompte> <motdepasse>\n";
- printf " 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 méthode que vous possédez pour savoir\n";
- printf " si un mot de passe est le bon. L'autre méthode est\n";
- printf " d'avoir un accès ('physique') au fichier des comptes.\n";
- } elsif ("create" =~ /^\Q$command/ && $command ne "c") { # check 1 letter command: 'check' or 'create'?
- printf "create <nomcompte> <sexe> <email> <motdepasse>\n";
- printf " Comme la commande add, mais avec l'e-mail en plus.\n";
- printf " <exemple> create testname Male mon\@mail.com testpass\n";
- } elsif ("del" =~ /^\Q$command/ || "delete" =~ /^\Q$command/) {
- printf "del <nomcompte>\n";
- printf " Supprime un compte.\n";
- printf " La commande demande confirmation. Après confirmation, le compte est détruit.\n";
- } elsif ("email" =~ /^\Q$command/ && $command ne "e") { # check 1 letter command: 'email', 'end' or 'exit'?
- printf "email <nomcompte> <email>\n";
- printf " Modifie l'e-mail d'un compte.\n";
- } elsif ("getcount" =~ /^\Q$command/ && $command ne "g") { # check 1 letter command: 'getcount' or 'gm'?
- printf "getcount\n";
- printf " Donne le nombre de joueurs en ligne par serveur de char.\n";
- } elsif ("gm" =~ /^\Q$command/ && $command ne "g") { # check 1 letter command: 'getcount' or 'gm'?
- printf "gm <nomcompte> [Niveau_GM]\n";
- printf " Modifie le niveau de GM d'un compte.\n";
- printf " Valeur par défaut: 0 (suppression du niveau de GM).\n";
- printf " <exemple> gm nomtest 80\n";
- } elsif ("id" =~ /^\Q$command/ && $command ne "i") { # check 1 letter command: 'id' or 'info'?
- printf "id <nomcompte>\n";
- printf " Donne l'id d'un compte.\n";
- } elsif ("info" =~ /^\Q$command/ && $command ne "i") { # check 1 letter command: 'id' or 'info'?
- printf "info <idcompte>\n";
- printf " Affiche les informations sur un compte.\n";
- } elsif ($command eq "kami") { # check all letters command: 'kami' or 'kamib'?
- printf "kami <message>\n";
- printf " Envoi un message général sur tous les serveurs de map (en jaune).\n";
- } elsif ($command eq "kamib") { # check all letters command: 'kami' or 'kamib'?
- printf "kamib <message>\n";
- printf " Envoi un message général sur tous les serveurs de map (en bleu).\n";
- } elsif ("language" =~ /^\Q$command/ && $command ne "l") { # check 1 letter command: 'list' or 'language'?
- printf("language <langue>\n");
- printf(" Change la langue d'affichage.\n");
- printf(" Langues possibles: 'Français' ou 'English'.\n");
- } elsif (("list" =~ /^\Q$command/ || $command eq "ls") && $command ne "l") { # check 1 letter command: 'list' or 'language'?
- printf "list/ls [Premier_id [Dernier_id]]\n";
- printf " Affiche une liste de comptes.\n";
- printf " '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 " <example> list 10 9999999\n";
- } elsif (("listban" =~ /^\Q$command/ || $command eq "lsban") && $command ne "l") { # need to specificaly write Ban to have this list # check 1 letter command: 'list' or 'language'?
- printf "listBan/lsBan [Premier_id [Dernier_id]]\n";
- printf " Comme list/ls, mais seulement pour les comptes GM avec un statut ou bannis.\n";
- } elsif (("listgm" =~ /^\Q$command/ || $command eq "lsgm") && $command ne "l") { # need to specificaly write GM to have this list # check 1 letter command: 'list' or 'language'?
- printf "listGM/lsGM [Premier_id [Dernier_id]]\n";
- printf " Comme list/ls, mais seulement pour les comptes GM.\n";
- } elsif (("listok" =~ /^\Q$command/ || $command eq "lsok") && $command ne "l") { # need to specificaly write OK to have this list # check 1 letter command: 'list' or 'language'?
- printf "listOK/lsOK [Premier_id [Dernier_id]]\n";
- printf " Comme list/ls, mais seulement pour les comptes sans statut et non bannis.\n";
- } elsif ("memo" =~ /^\Q$command/) {
- printf "memo <nomcompte> <memo>\n";
- printf " Modifie le mémo d'un compte.\n";
- printf " 'memo': Il peut avoir jusqu'à 253 caractères (avec des espaces ou non).\n";
- } elsif ("name" =~ /^\Q$command/) {
- printf "name <idcompte>\n";
- printf " Donne le nom d'un compte.\n";
- } elsif ("passwd" =~ /^\Q$command/ || "password" =~ /^\Q$command/) {
- printf "passwd <nomcompte> <nouveaumotdepasse>\n";
- printf " Change le mot de passe d'un compte.\n";
- printf " Lorsque nouveaumotdepasse est omis,\n";
- printf " la saisie se fait sans que la frappe ne se voit.\n";
- } elsif ("reloadgm" =~ /^\Q$command/) {
- printf "reloadGM\n";
- printf " Reload GM configuration file\n";
- } elsif ("search" =~ /^\Q$command/ && $command ne "s" && # check 1 letter command: 'search', 'state' or 'sex'?
- $command ne "se") { # check 2 letters command: 'search' or 'sex'?
- printf "search <expression>\n";
- printf " Cherche des comptes.\n";
- printf " Affiche les comptes dont les noms correspondent.\n";
- printf "search -r/-e/--expr/--regex <expression>\n";
- printf " Cherche des comptes par expression regulière.\n";
- printf " Affiche les comptes dont les noms correspondent.\n";
- } elsif ("sex" =~ /^\Q$command/ && $command ne "s" && # check 1 letter command: 'search', 'state' or 'sex'?
- $command ne "se") { # check 2 letters command: 'search' or 'sex'?
- printf "sex <nomcompte> <sexe>\n";
- printf " Modifie le sexe d'un compte.\n";
- printf " <exemple> sex testname Male\n";
- } elsif ("state" =~ /^\Q$command/ && $command ne "s") { # check 1 letter command: 'search', 'state' or 'sex'?
- printf "state <nomcompte> <nouveaustatut> <message_erreur_7>\n";
- printf " Change le statut d'un compte.\n";
- printf " '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";
- printf " 3 = This ID is expired\n";
- printf " 4 = Rejected from Server\n";
- printf " 5 = You have been blocked by the GM Team\n";
- printf " 6 = Your Game's EXE file is not the latest version\n";
- printf " 7 = You are Prohibited to log in until...\n";
- printf " 8 = Server is jammed due to over populated\n";
- printf " 9 = No MSG\n";
- printf " 100 = This ID has been totally erased\n";
- printf " all other values are 'No MSG', then use state 9 please.\n";
- printf " 'message_erreur_7': message du code erreur 6 =\n";
- printf " = Your are Prohibited to log in until... (packet 0x006a)\n";
- } elsif (("timeadd" =~ /^\Q$command/ || $command eq "ta") && $command ne "t") { # check 1 letter command: 'ta' or 'ts'?
- printf "timeadd <nomcompte> <modificateur>\n";
- printf " 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 " 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";
- printf " mn: minute\n";
- printf " s: seconde\n";
- printf " <exemple> 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 même temps.\n";
- printf "NOTE: Vous ne pouvez pas modifier une limite de validité illimitée. Si vous\n";
- printf " désirez le faire, c'est que vous voulez probablement créer un limite de\n";
- printf " validité limitée. Donc, en premier, fixé une limite de valitidé.\n";
- } elsif (("timeset" =~ /^\Q$command/ || $command eq "ts") && $command ne "t") { # check 1 letter command: 'ta' or 'ts'?
- printf "timeset <nomcompte> aaaa/mm/jj [hh:mm:ss]\n";
- printf " Change la limite de validité d'un compte.\n";
- printf " Heure par défaut: 23:59:59\n";
- printf "timeset <nomcompte> 0\n";
- printf " Donne une limite de validité illimitée (0 = illimitée).\n";
- } elsif ($command eq "unban" || ("unbanish" =~ /^\Q$command/ && length($command) >= 4)) {
- printf "unban/unbanish <nom compte>\n";
- printf " Ote le banissement d'un compte.\n";
- printf " La commande est l'équivalent de banset <nom_compte> 0.\n";
- } elsif ("unblock" =~ /^\Q$command/ && length($command) >= 4) {
- printf "unblock <nom compte>\n";
- printf " Place le status d'un compte à 0 (Compte ok).\n";
- printf " La commande est l'équivalent de state <nom_compte> 0.\n";
- } elsif ("version" =~ /^\Q$command/) {
- printf "version\n";
- printf " Affiche la version du login-serveur.\n";
- } elsif ("who" =~ /^\Q$command/) {
- printf "who <nomcompte>\n";
- printf " Affiche les informations sur un compte.\n";
- } elsif ("quit" =~ /^\Q$command/ ||
- (("end" =~ /^\Q$command/ || "exit" =~ /^\Q$command/) && $command ne "e")) { # check 1 letter command: 'email', 'end' or 'exit'?\n";
- printf "quit/end/exit\n";
- printf " Fin du programme d'administration.\n";
- } else {
- if ($receivedcommand ne "") {
- printf "Commande inconnue [%s] pour l'aide. Affichage de toutes les commandes.\n", $receivedcommand;
- }
- print << "ENDOFAIDE";
- aide/help/? -- Affiche cet aide
- aide/help/? [commande] -- Affiche l'aide de la commande
- add <nomcompte> <sexe> <motdepasse> -- Crée un compte (sans email)
- ban/banish aaaa/mm/jj hh:mm:ss <nomcompte>-- Change la date finale de banismnt
- banadd/ba <nomcompte> <modificateur> -- Ajout/soustrait du temps à la
- exemple: ba moncompte +1m-2mn1s-2y date finale de banissement
- banset/bs <nomcompte> aaaa/mm/jj [hh:mm:ss] -- Change la date fin de banisemnt
- banset/bs <nomcompte> 0 -- Dé-banis un compte.
- block <nom compte> -- Mets le status d'un compte à 5 (blocked by the GM Team)
- check <nomcompte> <motdepasse> -- Vérifie un mot de passe d'un compte
- create <nomcompte> <sexe> <email> <motdepasse> -- Crée un compte (avec email)
- del <nomcompte> -- Supprime un compte
- email <nomcompte> <email> -- Modifie l'e-mail d'un compte
- getcount -- Donne le nb de joueurs en ligne
- gm <nomcompte> [Niveau_GM] -- Modifie le niveau de GM d'un compte
- id <nomcompte> -- Donne l'id d'un compte
- info <idcompte> -- Affiche les infos sur un compte
- kami <message> -- Envoi un message général (en jaune)
- kamib <message> -- Envoi un message général (en bleu)
- language <langue> -- Change la langue d'affichage.
- list/ls [Premier_id [Dernier_id] ] -- Affiche une liste de comptes
- listBan/lsBan [Premier_id [Dernier_id] ]-- Affiche une liste de comptes
- avec un statut ou bannis
- listGM/lsGM [Premier_id [Dernier_id] ] -- Affiche une liste de comptes GM
- listOK/lsOK [Premier_id [Dernier_id] ] -- Affiche une liste de comptes
- sans status et non bannis
- memo <nomcompte> <memo> -- Modifie le memo d'un compte
- name <idcompte> -- Donne le nom d'un compte
- passwd <nomcompte> <nouveaumotdepasse> -- Change le mot de passe d'un compte
- quit/end/exit -- Fin du programme d'administation
- reloadGM -- Recharger le fichier de config des GM
- search <expression> -- Cherche des comptes
- search -e/-r/--expr/--regex <expression> -- Cherche des comptes par REGEX
- sex <nomcompte> <sexe> -- Modifie le sexe d'un compte
- state <nomcompte> <nouveaustatut> <messageerr7> -- Change le statut d'1 compte
- timeadd/ta <nomcompte> <modificateur> -- Ajout/soustrait du temps à la
- exemple: ta moncompte +1m-2mn1s-2y limite de validité
- timeset/ts <nomcompte> aaaa/mm/jj [hh:mm:ss] -- Change la limite de validité
- timeset/ts <nomcompte> 0 -- limite de validité = illimitée
- unban/unbanish <nom compte> -- Ote le banissement d'un compte
- unblock <nom compte> -- Mets le status d'un compte à 0 (Compte ok)
- version -- Donne la version du login-serveur
- who <nomcompte> -- Affiche les infos sur un compte
-ENDOFAIDE
- printf(" Note: Pour les noms de compte avec des espaces, tapez \"<nom compte>\" (ou ').\n");
- }
- } else {
- if ("aide" =~ /^\Q$command/ && $command ne "a") { # check 1 letter command: 'aide' or 'add'?
- printf "aide/help/?\n";
- printf " Display the description of the commands\n";
- printf "aide/help/? [command]\n";
- printf " Display the description of the specified command\n";
- } elsif ("help" =~ /^\Q$command/) {
- printf "aide/help/?\n";
- printf " Display the description of the commands\n";
- printf "aide/help/? [command]\n";
- printf " Display the description of the specified command\n";
- } elsif ("add" =~ /^\Q$command/ && $command ne "a") { # check 1 letter command: 'aide' or 'add'?
- printf "add <account_name> <sex> <password>\n";
- printf " Create an account with the default email (a\@a.com).\n";
- printf " Concerning the sex, only the first letter is used (F or M).\n";
- printf " The e-mail is set to a\@a.com (default e-mail). It's like to have no e-mail.\n";
- printf " When the password is omitted,\n";
- printf " the input is done without displaying of the pressed keys.\n";
- printf " <example> add testname Male testpass\n";
- } elsif ($command eq "ban" || ("banish" =~ /^\Q$command/ && length($command) >= 4)) {
- printf "ban/banish yyyy/mm/dd hh:mm:ss <account_name>\n";
- printf " Changes the final date of a banishment of an account.\n";
- printf " The difference with banset is the position of the account name.\n";
- } elsif (("banadd" =~ /^\Q$command/ || $command eq "ba") && $command ne "b") { # check 1 letter command: 'ba' or 'bs'?
- printf "banadd <account_name> <modifier>\n";
- printf " Adds or substracts time from the final date of a banishment of an account.\n";
- printf " Modifier is done as follows:\n";
- printf " Adjustment value (-1, 1, +1, etc...)\n";
- printf " Modified element:\n";
- printf " a or y: year\n";
- printf " m: month\n";
- printf " j or d: day\n";
- printf " h: hour\n";
- printf " mn: minute\n";
- printf " s: second\n";
- printf " <example> banadd testname +1m-2mn1s-6y\n";
- printf " this example adds 1 month and 1 second, and substracts 2 minutes\n";
- printf " and 6 years at the same time.\n";
- printf "NOTE: If you modify the final date of a non-banished account,\n";
- printf " you fix the final date to (actual time +- adjustments)\n";
- } elsif (("banset" =~ /^\Q$command/ || $command eq "bs") && $command ne "b") { # check 1 letter command: 'ba' or 'bs'?
- printf "banset <account_name> yyyy/mm/dd [hh:mm:ss]\n";
- printf " Changes the final date of a banishment of an account.\n";
- printf " Default time: 23:59:59\n";
- printf "banset <account_name> 0\n";
- printf " Set a non-banished account (0 = unbanished).\n";
- } elsif ("block" =~ /^\Q$command/ && length($command) >= 2) {
- printf "block <account name>\n";
- printf " Set state 5 (You have been blocked by the GM Team) to an account.\n";
- printf " Same command of state <account_name> 5.\n";
- } elsif ("check" =~ /^\Q$command/ && $command ne "c") { # check 1 letter command: 'check' or 'create'?
- printf "check <account_name> <password>\n";
- printf " Check the validity of a password for an account.\n";
- printf " NOTE: Server will never sends back a password.\n";
- printf " It's the only method you have to know if a password is correct.\n";
- printf " The other method is to have a ('physical') access to the accounts file.\n";
- } elsif ("create" =~ /^\Q$command/ && $command ne "c") { # check 1 letter command: 'check' or 'create'?
- printf "create <account_name> <sex> <email> <password>\n";
- printf " Like the 'add' command, but with e-mail moreover.\n";
- printf " <example> create testname Male my\@mail.com testpass\n";
- } elsif ("del" =~ /^\Q$command/ || "delete" =~ /^\Q$command/) {
- printf "del <account_name>\n";
- printf " Remove an account.\n";
- printf " This order requires confirmation. After confirmation, the account is deleted.\n";
- } elsif ("email" =~ /^\Q$command/ && $command ne "e") { # check 1 letter command: 'email', 'end' or 'exit'?
- printf "email <account_name> <email>\n";
- printf " Modify the e-mail of an account.\n";
- } elsif ("getcount" =~ /^\Q$command/ && $command ne "g") { # check 1 letter command: 'getcount' or 'gm'?
- printf "getcount\n";
- printf " Give the number of players online on all char-servers.\n";
- } elsif ("gm" =~ /^\Q$command/ && $command ne "g") { # check 1 letter command: 'getcount' or 'gm'?
- printf "gm <account_name> [GM_level]\n";
- printf " Modify the GM level of an account.\n";
- printf " Default value remove GM level (GM level = 0).\n";
- printf " <example> gm testname 80\n";
- } elsif ("id" =~ /^\Q$command/ && $command ne "i") { # check 1 letter command: 'id' or 'info'?
- printf "id <account_name>\n";
- printf " Give the id of an account.\n";
- } elsif ("info" =~ /^\Q$command/ && $command ne "i") { # check 1 letter command: 'id' or 'info'?
- printf "info <account_id>\n";
- printf " Display complete information of an account.\n";
- } elsif ($command eq "kami") { # check all letters command: 'kami' or 'kamib'?
- printf "kami <message>\n";
- printf " Sends a broadcast message on all map-server (in yellow).\n";
- } elsif ($command eq "kamib") { # check all letters command: 'kami' or 'kamib'?
- printf "kamib <message>\n";
- printf " Sends a broadcast message on all map-server (in blue).\n";
- } elsif ("language" =~ /^\Q$command/ && $command ne "l") { # check 1 letter command: 'list' or 'language'?
- printf("language <language>\n");
- printf(" Change the language of displaying.\n");
- printf(" Possible languages: Français or English.\n");
- } elsif (("list" =~ /^\Q$command/ || $command eq "ls") && $command ne "l") { # check 1 letter command: 'list' or 'language'?
- printf "list/ls [start_id [end_id]]\n";
- printf " Display a list of accounts.\n";
- printf " 'start_id', 'end_id': indicate end and start identifiers.\n";
- printf " Research by name is not possible with this command.\n";
- printf " <example> list 10 9999999\n";
- } elsif (("listban" =~ /^\Q$command/ || $command eq "lsban") && $command ne "l") { # need to specificaly write Ban to have this list # check 1 letter command: 'list' or 'language'?
- printf "listBan/lsBan [start_id [end_id]]\n";
- printf " Like list/ls, but only for accounts with state or banished.\n";
- } elsif (("listgm" =~ /^\Q$command/ || $command eq "lsgm") && $command ne "l") { # need to specificaly write GM to have this list # check 1 letter command: 'list' or 'language'?
- printf "listGM/lsGM [start_id [end_id]]\n";
- printf " Like list/ls, but only for GM accounts.\n";
- } elsif (("listok" =~ /^\Q$command/ || $command eq "lsok") && $command ne "l") { # need to specificaly write OK to have this list # check 1 letter command: 'list' or 'language'?
- printf "listOK/lsOK [start_id [end_id]]\n";
- printf " Like list/ls, but only for accounts without state and not banished.\n";
- } elsif ("memo" =~ /^\Q$command/) {
- printf "memo <account_name> <memo>\n";
- printf " Modify the memo of an account.\n";
- printf " 'memo': it can have until 253 characters (with spaces or not).\n";
- } elsif ("name" =~ /^\Q$command/) {
- printf "name <account_id>\n";
- printf " Give the name of an account.\n";
- } elsif ("passwd" =~ /^\Q$command/ || "password" =~ /^\Q$command/) {
- printf "passwd <account_name> <new_password>\n";
- printf " Change the password of an account.\n";
- printf " When new password is omitted,\n";
- printf " the input is done without displaying of the pressed keys.\n";
- } elsif ("reloadgm" =~ /^\Q$command/) {
- printf "reloadGM\n";
- printf " Reload GM configuration file\n";
- } elsif ("search" =~ /^\Q$command/ && $command ne "s" && # check 1 letter command: 'search', 'state' or 'sex'?
- $command ne "se") { # check 2 letters command: 'search' or 'sex'?
- printf "search <expression>\n";
- printf " Seek accounts.\n";
- printf " Displays the accounts whose names correspond.\n";
- printf "search -r/-e/--expr/--regex <expression>\n";
- printf " Seek accounts by regular expression.\n";
- printf " Displays the accounts whose names correspond.\n";
- } elsif ("sex" =~ /^\Q$command/ && $command ne "s" && # check 1 letter command: 'search', 'state' or 'sex'?
- $command ne "se") { # check 2 letters command: 'search' or 'sex'?
- printf "sex <account_name> <sex>\n";
- printf " Modify the sex of an account.\n";
- printf " <example> sex testname Male\n";
- } elsif ("state" =~ /^\Q$command/ && $command ne "s") { # check 1 letter command: 'search', 'state' or 'sex'?
- printf "state <account_name> <new_state> <error_message_#7>\n";
- printf " Change the state of an account.\n";
- printf " 'new_state': state is the state of the packet 0x006a + 1.\n";
- printf " The possibilities are:\n";
- printf " 0 = Account ok\n";
- printf " 1 = Unregistered ID\n";
- printf " 2 = Incorrect Password\n";
- printf " 3 = This ID is expired\n";
- printf " 4 = Rejected from Server\n";
- printf " 5 = You have been blocked by the GM Team\n";
- printf " 6 = Your Game's EXE file is not the latest version\n";
- printf " 7 = You are Prohibited to log in until...\n";
- printf " 8 = Server is jammed due to over populated\n";
- printf " 9 = No MSG\n";
- printf " 100 = This ID has been totally erased\n";
- printf " all other values are 'No MSG', then use state 9 please.\n";
- printf " 'error_message_#7': message of the code error 6\n";
- printf " = Your are Prohibited to log in until... (packet 0x006a)\n";
- } elsif (("timeadd" =~ /^\Q$command/ || $command eq "ta") && $command ne "t") { # check 1 letter command: 'ta' or 'ts'?
- printf "timeadd <account_name> <modifier>\n";
- printf " Adds or substracts time from the validity limit of an account.\n";
- printf " Modifier is done as follows:\n";
- printf " Adjustment value (-1, 1, +1, etc...)\n";
- printf " Modified element:\n";
- printf " a or y: year\n";
- printf " m: month\n";
- printf " j or d: day\n";
- printf " h: hour\n";
- printf " mn: minute\n";
- printf " s: second\n";
- printf " <example> timeadd testname +1m-2mn1s-6y\n";
- printf " this example adds 1 month and 1 second, and substracts 2 minutes\n";
- printf " and 6 years at the same time.\n";
- printf "NOTE: You can not modify a unlimited validity limit.\n";
- printf " If you want modify it, you want probably create a limited validity limit.\n";
- printf " So, at first, you must set the validity limit to a date/time.\n";
- } elsif (("timeset" =~ /^\Q$command/ || $command eq "ts") && $command ne "t") { # check 1 letter command: 'ta' or 'ts'?
- printf "timeset <account_name> yyyy/mm/dd [hh:mm:ss]\n";
- printf " Changes the validity limit of an account.\n";
- printf " Default time: 23:59:59\n";
- printf "timeset <account_name> 0\n";
- printf " Gives an unlimited validity limit (0 = unlimited).\n";
- } elsif ($command eq "unban" || ("unbanish" =~ /^\Q$command/ && length($command) >= 4)) {
- printf "unban/unbanish <account name>\n";
- printf " Remove the banishment of an account.\n";
- printf " This command works like banset <account_name> 0.\n";
- } elsif ("unblock" =~ /^\Q$command/ && length($command) >= 4) {
- printf "unblock <account name>\n";
- printf " Set state 0 (Account ok) to an account.\n";
- printf " This command works like state <account_name> 0.\n";
- } elsif ("version" =~ /^\Q$command/) {
- printf "version\n";
- printf " Display the version of the login-server.\n";
- } elsif ("who" =~ /^\Q$command/) {
- printf "who <account_name>\n";
- printf " Displays complete information of an account.\n";
- } elsif ("quit" =~ /^\Q$command/ ||
- (("end" =~ /^\Q$command/ || "exit" =~ /^\Q$command/) && $command ne "e")) { # check 1 letter command: 'email', 'end' or 'exit'?\n";
- printf "quit/end/exit\n";
- printf " End of the program of administration.\n";
- } else {
- if ($receivedcommand ne "") {
- printf "Unknown command [%s] for help. Displaying of all commands.\n", $receivedcommand;
- }
- print << "ENDOFHELP";
- aide/help/? -- Display this help
- aide/help/? [command] -- Display the help of the command
- add <account_name> <sex> <password> -- Create an account with default email
- ban/banish yyyy/mm/dd hh:mm:ss <account_name> -- Change final date of a ban
- banadd/ba <account_name> <modifier> -- Add or substract time from the final
- example: ba apple +1m-2mn1s-2y date of a banishment of an account
- banset/bs <account_name> yyyy/mm/dd [hh:mm:ss] -- Change final date of a ban
- banset/bs <account_name> 0 -- Un-banish an account
- block <account name> -- Set state 5 (blocked by the GM Team) to an account
- check <account_name> <password> -- Check the validity of a password
- create <account_name> <sex> <email> <passwrd> -- Create an account with email
- del <account_name> -- Remove an account
- email <account_name> <email> -- Modify an email of an account
- getcount -- Give the number of players online
- gm <account_name> [GM_level] -- Modify the GM level of an account
- id <account_name> -- Give the id of an account
- info <account_id> -- Display all information of an account
- kami <message> -- Sends a broadcast message (in yellow)
- kamib <message> -- Sends a broadcast message (in blue)
- language <language> -- Change the language of displaying.
- list/ls [First_id [Last_id]] -- Display a list of accounts
- listBan/lsBan [First_id [Last_id]] -- Display a list of accounts
- with state or banished
- listGM/lsGM [First_id [Last_id]] -- Display a list of GM accounts
- listOK/lsOK [First_id [Last_id]] -- Display a list of accounts
- without state and not banished
- memo <account_name> <memo> -- Modify the memo of an account
- name <account_id> -- Give the name of an account
- passwd <account_name> <new_password> -- Change the password of an account
- quit/end/exit -- End of the program of administation
- reloadGM -- Reload GM configuration file
- search <expression> -- Seek accounts
- search -e/-r/--expr/--regex <expressn> -- Seek accounts by regular-expression
- sex <nomcompte> <sexe> -- Modify the sex of an account
- state <account_name> <new_state> <error_message_#7> -- Change the state
- timeadd/ta <account_name> <modifier> -- Add or substract time from the
- example: ta apple +1m-2mn1s-2y validity limit of an account
- timeset/ts <account_name> yyyy/mm/dd [hh:mm:ss] -- Change the validify limit
- timeset/ts <account_name> 0 -- Give a unlimited validity limit
- unban/unbanish <account name> -- Remove the banishment of an account
- unblock <account name> -- Set state 0 (Account ok) to an account
- version -- Gives the version of the login-server
- who <account_name> -- Display all information of an account
-ENDOFHELP
- printf(" Note: To use spaces in an account name, type \"<account name>\" (or ').\n");
- }
- }
-
- return 0;
-}
-#--------------------------------------------------------------------------
-
-# Sub-function: Displaying of the accounts list
-sub listaccount() {
- my($st, $ed, $listflag) = @_;
- my($i);
- my($n) = (0);
- # 0123456789 01 01234567890123456789012301234 012345 0123456789012345678901234567
- if ($defaultlanguage eq "F") {
- print " id_compte GM nom_utilisateur sexe count statut\n";
- } else {
- print "account_id GM user_name sex count state\n";
- }
- print "-------------------------------------------------------------------------------\n";
- while(1) {
- print $so pack("vV2", 0x7920, $st, $ed);
- $so->flush();
- $buf = readso(4);
- if (unpack("v", $buf) != 0x7921) {
- if ($defaultlanguage eq "F") {
- print "Problème de connexion au serveur (réponse incorrecte).\n";
- } else {
- print "Connection error to the server (incorrect answer).\n";
- }
- exit(10);
- }
- my($len) = unpack("x2v", $buf);
- last if ($len <= 4);
- for($i = 4; $i < $len; $i += 38) {
- my(@dat) = unpack("VCa24cVV", readso(38));
- $st = $dat[0] + 1;
- if ($listflag == 0 ||
- ($listflag == 1 && $dat[1] > 0) || # check GM flag
- ($listflag == 3 && $dat[5] != 0) || # check with state or banished
- ($listflag == 4 && $dat[5] == 0)) { # check without state and not banished
- printf "%10d %2s %-24s%-5s %6d %-27s\n", $dat[0],
- ($dat[1] == 0 ? " " : $dat[1]),
- $dat[2],
- ($defaultlanguage eq "F" ? ("Femme","Male","Servr")[$dat[3]] : ("Femal","Male","Servr")[$dat[3]]),
- $dat[4],
- (($defaultlanguage eq "F" ? "Compte Ok" : "Account OK"),
- "Unregistered ID",
- "Incorrect Password",
- "This ID is expired",
- "Rejected from Server",
- "Blocked by the GM Team", # You have been blocked by the GM Team
- "Your EXE file is too old", # Your Game's EXE file is not the latest version
- "Banishement or\n Prohibited to login until %s", # You are Prohibited to log in until %s
- "Server is over populated", # Server is jammed due to over populated
- "No MSG",
- "This ID is totally erased")[$dat[5] == 100 ? 10 : $dat[5]]; # This ID has been totally erased
- $n++;
- }
- }
- }
- if ($defaultlanguage eq "F") {
- if ($n == 0) {
- print "Aucun compte trouvé.\n";
- } elsif ($n == 1) {
- print "1 compte trouvé.\n";
- } else {
- print "$n comptes trouvés.\n";
- }
- } else {
- if ($n == 0) {
- print "No account found.\n";
- } elsif ($n == 1) {
- print "1 account found.\n";
- } else {
- print "$n accounts found.\n";
- }
- }
- return 0;
-}
-
-#--------------------------------------------------------------------------
-
-# Sub-function: add an account with the default e-mail
-sub addaccount() {
- my($userid, $sex, $passwd) = @_;
- if ($userid eq "" || !defined($userid)) {
- if ($defaultlanguage eq "F") {
- print "Entrez un nom de compte svp.\n";
- print "<exemple> add nomtest Male motdepassetest\n";
- } else {
- print "Please input an account name.\n";
- print "<example> add testname Male testpass\n";
- }
- return 136;
- }
- if (verify_accountname($userid) == 0) {
- return 102;
- }
-# if ($userid =~ /[^A-Za-z0-9\@-_]/) {
-# if ($defaultlanguage eq "F") {
-# print "Caractère interdit trouvé dans le nom du compte ".$`."[${&}]${'}\n";
-# } else {
-# print "Illegal character found in the account name ".$`."[${&}]${'}\n";
-# }
-# return 101;
-# }
- $sex = uc(substr($sex, 0, 1));
- if ($sex !~ /^[MF]$/) {
- if ($defaultlanguage eq "F") {
- print "Sexe incorrect [$sex]. Entrez M ou F svp.\n";
- } else {
- print "Illegal gender [$sex]. Please input M or F.\n";
- }
- return 103;
- }
- if ($passwd eq "") {
- return 108 if (($passwd = typepasswd()) eq "");
- }
- if (verify_password($passwd) == 0) {
- return 104;
- }
- print $so pack("va24a24a1a40", 0x7930, $userid, $passwd, $sex, "");
- $so->flush();
- $buf = readso(2);
- if (unpack("v", $buf) != 0x7931) {
- if ($defaultlanguage eq "F") {
- print "Problème de connexion au serveur (réponse incorrecte).\n";
- } else {
- print "Connection error to the server (incorrect answer).\n";
- }
- return 106;
- }
- $buf = readso(28);
- if (unpack("V", $buf) == -1 || unpack("V", $buf) == 4294967295) {
- if ($defaultlanguage eq "F") {
- print "Echec à la création du compte [$userid]. Un compte identique existe déjà.\n";
- } else {
- print "Account [$userid] creation failed. Same account already exists.\n";
- }
- return 107;
- } else {
- if ($defaultlanguage eq "F") {
- printf "Compte [$userid] créé avec succès [id: %d].\n", unpack("V",$buf);
- } else {
- printf "Account [$userid] is successfully created [id: %d].\n", unpack("V",$buf);
- }
- }
- return 0;
-}
-
-#--------------------------------------------------------------------------
-
-# Sub-function: add an account with an e-mail
-sub createaccount() {
- my($userid, $sex, $email, $passwd) = @_;
- if ($userid eq "") {
- if ($defaultlanguage eq "F") {
- print "Entrez un nom de compte svp.\n";
- print "<exemple> create nomtest Male mon\@email.com motdepassetest\n";
- } else {
- print "Please input an account name.\n";
- print "<example> create testname Male my\@mail.com testpass\n";
- }
- return 136;
- }
- if (verify_accountname($userid) == 0) {
- return 102;
- }
-# if ($userid =~ /[^A-Za-z0-9\@-_]/) {
-# if ($defaultlanguage eq "F") {
-# print "Caractère interdit trouvé dans le nom du compte ".$`."[${&}]${'}\n";
-# } else {
-# print "Illegal character found in the account name ".$`."[${&}]${'}\n";
-# }
-# return 101;
-# }
- $sex = uc(substr($sex, 0, 1));
- if ($sex !~ /^[MF]$/) {
- if ($defaultlanguage eq "F") {
- print "Sexe incorrect [$sex]. Entrez M ou F svp.\n";
- } else {
- print "Illegal gender [$sex]. Please input M or F.\n";
- }
- return 103;
- }
- if (length($email) < 3) {
- if ($defaultlanguage eq "F") {
- print "Email trop courte [$email]. Entrez une e-mail valide svp.\n";
- } else {
- print "Email is too short [$email]. Please input a valid e-mail.\n";
- }
- return 109;
- }
- if (length($email) > 39) {
- if ($defaultlanguage eq "F") {
- print "Email trop longue [$email]. Entrez une e-mail de 39 caractères maximum svp.\n";
- } else {
- print "Email is too long [$email]. Please input an e-mail with 39 bytes at the most.\n";
- }
- return 109;
- }
- if (verify_email($email) == 0) {
- if ($defaultlanguage eq "F") {
- print "Email incorrecte [$email]. Entrez une e-mail valide svp.\n";
- } else {
- print "Invalid email [$email]. Please input a valid e-mail.\n";
- }
- return 109;
- }
- if ($passwd eq "") {
- return 108 if (($passwd = typepasswd()) eq "");
- }
- if (verify_password($passwd) == 0) {
- return 104;
- }
- print $so pack("va24a24a1a40", 0x7930, $userid, $passwd, $sex, $email);
- $so->flush();
- $buf = readso(2);
- if (unpack("v", $buf) != 0x7931) {
- if ($defaultlanguage eq "F") {
- print "Problème de connexion au serveur (réponse incorrecte).\n";
- } else {
- print "Connection error to the server (incorrect answer).\n";
- }
- return 106;
- }
- $buf = readso(28);
- if (unpack("V", $buf) == -1 || unpack("V", $buf) == 4294967295) {
- if ($defaultlanguage eq "F") {
- print "Echec à la création du compte [$userid]. Un compte identique existe déjà.\n";
- } else {
- print "Account [$userid] creation failed. Same account already exists.\n";
- }
- return 107;
- } else {
- if ($defaultlanguage eq "F") {
- printf "Compte [$userid] créé avec succès [id: %d].\n", unpack("V",$buf);
- } else {
- printf "Account [$userid] is successfully created [id: %d].\n", unpack("V",$buf);
- }
- }
- return 0;
-}
-
-#--------------------------------------------------------------------------
-
-# Sub-function: deletion of an account
-sub delaccount() {
- my($userid) = @_;
- if ($userid eq "") {
- if ($defaultlanguage eq "F") {
- print "Entrez un nom de compte svp.\n";
- print "<exemple> del nomtestasupprimer\n";
- } else {
- print "Please input an account name.\n";
- print "<example> del testnametodelete\n";
- }
- return 136;
- }
- if (verify_accountname($userid) == 0) {
- return 102;
- }
- if ($defaultlanguage eq "F") {
- print "** Etes-vous vraiment sûr de vouloir SUPPRIMER le compte [$userid]? (o/n) ";
- } else {
- print "** Are you really sure to DELETE account [$userid]? (y/n) ";
- }
- if (lc(substr(<STDIN>, 0, 1)) !~ /[oy]/) {
- if ($defaultlanguage eq "F") {
- print "Suppression annulée\n.";
- } else {
- print "Deletion canceled\n";
- }
- return 121;
- }
- print $so pack("va24", 0x7932, $userid);
- $so->flush();
- $buf = readso(2);
- if (unpack("v", $buf) != 0x7933) {
- if ($defaultlanguage eq "F") {
- print "Problème de connexion au serveur (réponse incorrecte).\n";
- } else {
- print "Connection error to the server (incorrect answer).\n";
- }
- return 122;
- }
- $buf = readso(28);
- my($id2, $name) = unpack("Va24", $buf);
- while (length($name) > 0 && substr($name, length($name)-1, 1) eq chr(0)) {
- chop($name);
- };
- if ($id2 == -1 || $id2 == 4294967295) {
- if ($defaultlanguage eq "F") {
- print "Echec de la suppression du compte [$userid]. Le compte n'existe pas.\n";
- } else {
- print "Account [$userid] deletion failed. Account doesn't exist.\n";
- }
- return 123;
- } else {
- if ($defaultlanguage eq "F") {
- print "Compte [$name][id: $id2] SUPPRIME avec succès.\n";
- } else {
- print "Account [$name][id: $id2] is successfully DELETED.\n";
- }
- }
- return 0;
-}
-
-#--------------------------------------------------------------------------
-
-# Sub-function: modification of a password
-sub changepasswd() {
- my($userid, $passwd) = @_;
- if ($userid eq "") {
- if ($defaultlanguage eq "F") {
- print "Entrez un nom de compte svp.\n";
- print "<exemple> passwd nomtest nouveaumotdepasse\n";
- } else {
- print "Please input an account name.\n";
- print "<example> passwd testname newpassword\n";
- }
- return 136;
- }
- if (verify_accountname($userid) == 0) {
- return 102;
- }
- if ($passwd eq "") {
- return 134 if (($passwd = typepasswd()) eq "");
- }
- if (verify_password($passwd) == 0) {
- return 131;
- }
- print $so pack("va24a24", 0x7934, $userid,$passwd);
- $so->flush();
- $buf = readso(2);
- if (unpack("v", $buf) != 0x7935) {
- if ($defaultlanguage eq "F") {
- print "Problème de connexion au serveur (réponse incorrecte).\n";
- } else {
- print "Connection error to the server (incorrect answer).\n";
- }
- return 132;
- }
- $buf = readso(28);
- my($id2, $name) = unpack("Va24", $buf);
- while (length($name) > 0 && substr($name, length($name)-1, 1) eq chr(0)) {
- chop($name);
- };
- if ($id2 == -1 || $id2 == 4294967295) {
- if ($defaultlanguage eq "F") {
- print "Echec de la modification du mot de passe du compte [$userid].\n";
- print "Le compte [$userid] n'existe pas.\n";
- } else {
- print "Account [$userid] password changing failed.\n";
- print "Account [$userid] doesn't exist.\n";
- }
- return 133;
- } else {
- if ($defaultlanguage eq "F") {
- print "Modification du mot de passe du compte [$name][id: $id2] réussie.\n";
- } else {
- print "Account [$name][id: $id2] password successfully changed.\n";
- }
- }
- return 130;
-}
-
-#--------------------------------------------------------------------------
-
-# Sub-function: modification of an account e-mail
-sub changeemail() {
- my($userid, $email) = @_;
- if ($userid eq "") {
- if ($defaultlanguage eq "F") {
- print "Entrez un nom de compte svp.\n";
- print "<exemple> email testname nouveauemail\n";
- } else {
- print "Please input an account name.\n";
- print "<example> email testname newemail\n";
- }
- return 136;
- }
- if (verify_accountname($userid) == 0) {
- return 102;
- }
- if (length($email) < 3) {
- if ($defaultlanguage eq "F") {
- print "Email trop courte [$email]. Entrez une e-mail valide svp.\n";
- } else {
- print "Email is too short [$email]. Please input a valid e-mail.\n";
- }
- return 109;
- }
- if (length($email) > 39) {
- if ($defaultlanguage eq "F") {
- print "Email trop longue [$email]. Entrez une e-mail de 39 caractères maximum svp.\n";
- } else {
- print "Email is too long [$email]. Please input an e-mail with 39 bytes at the most.\n";
- }
- return 109;
- }
- if (verify_email($email) == 0) {
- if ($defaultlanguage eq "F") {
- print "Email incorrect [$email]. Entrez une e-mail valide svp.\n";
- } else {
- print "Invalid email [$email]. Please input a valid e-mail.\n";
- }
- return 109;
- }
- print $so pack("va24a40", 0x7940, $userid, $email);
- $so->flush();
- $buf = readso(2);
- if (unpack("v", $buf) != 0x7941) {
- if ($defaultlanguage eq "F") {
- print "Problème de connexion au serveur (réponse incorrecte).\n";
- } else {
- print "Connection error to the server (incorrect answer).\n";
- }
- return 162;
- }
- $buf = readso(28);
- my($id2, $name) = unpack("Va24", $buf);
- while (length($name) > 0 && substr($name, length($name)-1, 1) eq chr(0)) {
- chop($name);
- };
- if ($id2 == -1 || $id2 == 4294967295) {
- if ($defaultlanguage eq "F") {
- print "Echec de la modification de l'e-mail du compte [$userid].\n";
- print "Le compte [$userid] n'existe pas.\n";
- } else {
- print "Account [$userid] e-mail changing failed.\n";
- print "Account [$userid] doesn't exist.\n";
- }
- return 133;
- } else {
- if ($defaultlanguage eq "F") {
- print "Modification de l'e-mail du compte [$name][id: $id2] réussie.\n";
- } else {
- print "Account [$name][id: $id2] e-mail successfully changed.\n";
- }
- }
- return 160;
-}
-
-#--------------------------------------------------------------------------
-
-# Sub-function: search of accounts
-sub searchaccount() {
- my($p1, $p2) = @_;
- my($exp) = ("");
- if ($p1 eq "-e" || $p1 eq "-r" || $p1 eq "--regex" || $p1 eq "--expr") {
- if ($p2 eq "") {
- if ($defaultlanguage eq "F") {
- print "Entrez une expression régulière ou utilisez 'ls' pour avoir tous les comptes.\n";
- } else {
- print "Input a regular expression or use 'ls' to obtain all accounts.\n";
- }
- return 141;
- }
- $exp = $p2;
- } else {
- if ($p1 eq "") {
- if ($defaultlanguage eq "F") {
- print "Entrez une chaîne ou utilisez 'ls' pour avoir tous les comptes.\n";
- } else {
- print "Input a string or use 'ls' to obtain all accounts.\n";
- }
- return 141;
- }
- my($c) = 0;
- $exp = lc($p1);
- $exp =~ s/([\@])/\\$1/g;
- $c += $exp =~ s/([\-\[\]])/\\$1/g;
- $c += $exp =~ s/([\*\?])/.$1/g;
- $c += $exp =~ s/\\\[(.)\\\-(.)\\\]/[$1-$2]/g;
- $exp = "^$exp\$" if $c;
- }
- if (eval{ "" =~ /$exp/; }, $@) {
- if ($defaultlanguage eq "F") {
- print "Expression régulière non reconnue.\n";
- } else {
- print "Regular-Expression compiling failed.\n";
- }
- return 141;
- }
- my($i);
- my($n, $st) = (0, 0);
- # 0123456789 01 01234567890123456789012301234 012345 0123456789012345678901234567
- if ($defaultlanguage eq "F") {
- print " id_compte GM nom_utilisateur sexe count statut\n";
- } else {
- print "account_id GM user_name sex count state\n";
- }
- print "-------------------------------------------------------------------------------\n";
- while(1) {
- print $so pack("vV2", 0x7920, $st, 0);
- $so->flush();
- $buf = readso(4);
- if (unpack("v", $buf) != 0x7921) {
- if ($defaultlanguage eq "F") {
- print "Problème de connexion au serveur (réponse incorrecte).\n";
- } else {
- print "Connection error to the server (incorrect answer).\n";
- }
- exit(10);
- }
- my($len) = unpack("x2v", $buf);
- last if ($len <= 4);
- for($i = 4; $i < $len; $i += 38) {
- my(@dat) = unpack("VCa24cVV", readso(38));
- $st = $dat[0] + 1;
- next if (lc($dat[2]) !~ /$exp/);
- printf "%10d %2s %-24s%-5s %6d %-27s\n", $dat[0],
- ($dat[1] == 0 ? " " : $dat[1]),
- $dat[2],
- ($defaultlanguage eq "F" ? ("Femme","Male","Servr")[$dat[3]] : ("Femal","Male","Servr")[$dat[3]]),
- $dat[4],
- (($defaultlanguage eq "F" ? "Compte Ok" : "Account OK"),
- "Unregistered ID",
- "Incorrect Password",
- "This ID is expired",
- "Rejected from Server",
- "Blocked by the GM Team", # You have been blocked by the GM Team
- "Your EXE file is too old", # Your Game's EXE file is not the latest version
- "Banishement or\n Prohibited to login until %s", # You are Prohibited to log in until %s
- "Server is over populated", # Server is jammed due to over populated
- "No MSG",
- "This ID is totally erased")[$dat[5] == 100 ? 10 : $dat[5]]; # This ID has been totally erased
- $n++;
- }
- }
- if ($defaultlanguage eq "F") {
- if ($n == 0) {
- print "Aucun compte trouvé.\n";
- } elsif ($n == 1) {
- print "1 compte trouvé.\n";
- } else {
- print "$n comptes trouvés.\n";
- }
- } else {
- if ($n == 0) {
- print "No account found.\n";
- } elsif ($n == 1) {
- print "1 account found.\n";
- } else {
- print "$n accounts found.\n";
- }
- }
- return 0;
-}
-
-#--------------------------------------------------------------------------
-
-# Sub-function: modify the sex of an account
-sub changesex() {
- my($userid, $sex) = @_;
- if ($userid eq "" || !defined($userid)) {
- if ($defaultlanguage eq "F") {
- print "Entrez un nom de compte svp.\n";
- print "<exemple> sex nomtest Male\n";
- } else {
- print "Please input an account name.\n";
- print "<example> sex testname Male\n";
- }
- return 136;
- }
- if (verify_accountname($userid) == 0) {
- return 102;
- }
-# if ($userid =~ /[^A-Za-z0-9\@-_]/) {
-# if ($defaultlanguage eq "F") {
-# print "Caractère interdit trouvé dans le nom du compte ".$`."[${&}]${'}\n";
-# } else {
-# print "Illegal character found in the account name ".$`."[${&}]${'}\n";
-# }
-# return 101;
-# }
- $sex = uc(substr($sex, 0, 1));
- if ($sex !~ /^[MF]$/) {
- if ($defaultlanguage eq "F") {
- print "Sexe incorrect [$sex]. Entrez M ou F svp.\n";
- } else {
- print "Illegal gender [$sex]. Please input M or F.\n";
- }
- return 103;
- }
- print $so pack("va24a1", 0x793c, $userid, $sex);
- $so->flush();
- $buf = readso(2);
- if (unpack("v", $buf) != 0x793d) {
- if ($defaultlanguage eq "F") {
- print "Problème de connexion au serveur (réponse incorrecte).\n";
- } else {
- print "Connection error to the server (incorrect answer).\n";
- }
- return 152;
- }
- $buf = readso(28);
- my($id2, $name) = unpack("Va24", $buf);
- while (length($name) > 0 && substr($name, length($name)-1, 1) eq chr(0)) {
- chop($name);
- };
- if ($id2 == -1 || $id2 == 4294967295) {
- if ($defaultlanguage eq "F") {
- print "Echec du changement du sexe du compte [$userid].\n";
- print "Le compte n'existe pas ou le sexe est déjà celui demandé.\n";
- } else {
- print "Account [$userid] sex changing failed.\n";
- print "Account doesn't exist or the sex is already the good sex.\n";
- }
- } else {
- if ($defaultlanguage eq "F") {
- print "Sexe du compte [$name][id: $id2] changé avec succès.\n";
- } else {
- print "Account [$name][id: $id2] sex successfully changed.\n";
- }
- }
- return 0;
-}
-
-#--------------------------------------------------------------------------
-
-# Sub-function: modify the GM level of an account
-sub changegmlevel() {
- my($userid, $gm_level) = @_;
- if ($userid eq "" || !defined($userid)) {
- if ($defaultlanguage eq "F") {
- print "Entrez un nom de compte svp.\n";
- print "<exemple> gm nomtest 80\n";
- } else {
- print "Please input an account name.\n";
- print "<example> gm testname 80\n";
- }
- return 136;
- }
- if (verify_accountname($userid) == 0) {
- return 102;
- }
-# if ($userid =~ /[^A-Za-z0-9\@-_]/) {
-# if ($defaultlanguage eq "F") {
-# print "Caractère interdit trouvé dans le nom du compte ".$`."[${&}]${'}\n";
-# } else {
-# print "Illegal character found in the account name ".$`."[${&}]${'}\n";
-# }
-# return 101;
-# }
- $gm_level = int($gm_level);
- if ($gm_level < 0 || $gm_level > 99) {
- if ($defaultlanguage eq "F") {
- print "Niveau de GM incorrect [$gm_level]. Entrez une valeur de 0 à 99 svp.\n";
- } else {
- print "Illegal GM level [$gm_level]. Please input a value from 0 to 99.\n";
- }
- return 103;
- }
- print $so pack("va24C", 0x793e, $userid, $gm_level);
- $so->flush();
- $buf = readso(2);
- if (unpack("v", $buf) != 0x793f) {
- if ($defaultlanguage eq "F") {
- print "Problème de connexion au serveur (réponse incorrecte).\n";
- } else {
- print "Connection error to the server (incorrect answer).\n";
- }
- return 152;
- }
- $buf = readso(28);
- my($id2, $name) = unpack("Va24", $buf);
- while (length($name) > 0 && substr($name, length($name)-1, 1) eq chr(0)) {
- chop($name);
- };
- if ($id2 == -1 || $id2 == 4294967295) {
- if ($defaultlanguage eq "F") {
- print "Echec du changement du niveau de GM du compte [$userid].\n";
- print "Le compte n'existe pas, le niveau de GM est déjà celui demandé,\n";
- print "ou il est impossible de modifier le fichier des comptes GM.\n";
- } else {
- print "Account [$userid] GM level changing failed.\n";
- print "Account doesn't exist, the GM level is already the good GM level,\n";
- print "or it's impossible to modify the GM accounts file.\n";
- }
- } else {
- if ($defaultlanguage eq "F") {
- print "Niveau de GM du compte [$name][id: $id2] changé avec succès.\n";
- } else {
- print "Account [$name][id: $id2] GM level successfully changed.\n";
- }
- }
- return 0;
-}
-
-#--------------------------------------------------------------------------
-
-# Sub-function: Modification of a state
-sub changestate {
- my($userid, $s, $error_message) = @_;
- # Valid values: 0: ok, or value of the 0x006a packet + 1
- if ($s eq "" || (($s < 0 || $s > 9) && $s != 100)) {
- if ($defaultlanguage eq "F") {
- print "Entrez une des valeurs suivantes svp:\n";
- print " 0 = Compte ok 6 = Your Game's EXE file is not the latest version\n";
- } else {
- print "Please input one of these values:\n";
- print " 0 = Account ok 6 = Your Game's EXE file is not the latest version\n";
- }
- print " 1 = Unregistered ID 7 = You are Prohibited to log in until %s\n";
- print " 2 = Incorrect Password 8 = Server is jammed due to over populated\n";
- print " 3 = This ID is expired 9 = No MSG\n";
- print " 4 = Rejected from Server 100 = This ID has been totally erased\n";
- print " 5 = You have been blocked by the GM Team\n";
- if ($defaultlanguage eq "F") {
- print "<exemples> state nomtest 5\n";
- print " state nomtest 7 fin de votre ban\n";
- print " block <nom du compte>\n";
- print " unblock <nom du compte>\n";
- } else {
- print "<examples> state testname 5\n";
- print " state testname 7 end of your ban\n";
- print " block <account name>\n";
- print " unblock <account name>\n";
- }
- return 151;
- }
- if ($userid eq "") {
- if ($defaultlanguage eq "F") {
- print "Entrez un nom de compte svp.\n";
- print "<exemples> state nomtest 5\n";
- print " state nomtest 7 fin de votre ban\n";
- print " block <nom du compte>\n";
- print " unblock <nom du compte>\n";
- } else {
- print "Please input an account name.\n";
- print "<examples> state testname 5\n";
- print " state testname 7 end of your ban\n";
- print " block <account name>\n";
- print " unblock <account name>\n";
- }
- return 136;
- }
- if (verify_accountname($userid) == 0) {
- return 102;
- }
- if ($s != 7) {
- $error_message = "-";
- } else {
- if (length($error_message) < 1) {
- if ($defaultlanguage eq "F") {
- print "Message d'erreur trop court. Entrez un message de 1-19 caractères.\n";
- } else {
- print "Error message is too short. Please input a message of 1-19 bytes.\n";
- }
- return 102;
- }
- if (length($error_message) > 19) {
- if ($defaultlanguage eq "F") {
- print "Message d'erreur trop long. Entrez un message de 1-19 caractères.\n";
- } else {
- print "Error message is too long. Please input a message of 1-19 bytes.\n";
- }
- return 102;
- }
- }
- print $so pack("va24Va20", 0x7936, $userid, $s, $error_message);
- $so->flush();
- $buf = readso(2);
- if (unpack("v", $buf) != 0x7937) {
- if ($defaultlanguage eq "F") {
- print "Problème de connexion au serveur (réponse incorrecte).\n";
- } else {
- print "Connection error to the server (incorrect answer).\n";
- }
- return 152;
- }
- $buf = readso(32);
- my(@dat) = unpack("Va24V", $buf);
- while (length($dat[1]) > 0 && substr($dat[1], length($dat[1])-1, 1) eq chr(0)) {
- chop($dat[1]);
- };
- if ($dat[0] != -1 && $dat[0] != 4294967295) {
- if ($defaultlanguage eq "F") {
- print "Statut du compte [$dat[1]][id: $dat[0]] changé avec succès en [";
- } else {
- print "Account [$dat[1]][id: $dat[0]] state successfully changed in [";
- }
- print ((($defaultlanguage eq "F" ? "Compte Ok" : "Account OK"),
- "Unregistered ID",
- "Incorrect Password",
- "This ID is expired",
- "Rejected from Server",
- "You have been blocked by the GM Team",
- "Your Game's EXE file is not the latest version",
- "You are Prohibited to log in until %s",
- "Server is jammed due to over populated",
- "No MSG",
- "This ID has been totally erased")[$dat[2] == 100 ? 10 : $dat[2]]);
- print "].\n";
- } else {
- if ($defaultlanguage eq "F") {
- print "Echec du changement du statut du compte [$userid]. Le compte n'existe pas.\n";
- } else {
- print "Account [$userid] state changing failed. Account doesn't exist.\n";
- }
- }
-}
-
-#--------------------------------------------------------------------------
-
-# Sub-function: Displaying of the number of online players
-sub getlogincount {
- # Request to the login-server
- print $so pack("v", 0x7938);
- $so->flush();
-
- $buf = readso(4);
- # Connection failed
- if (unpack("v", $buf) != 0x7939) {
- if ($defaultlanguage eq "F") {
- print "Problème de connexion au serveur (réponse incorrecte).\n";
- } else {
- print "Connection error to the server (incorrect answer).\n";
- }
- exit(3);
- }
-
- # Get length of the received packet
- my($len) = unpack("x2v", $buf) - 4;
-
- # Read information of the servers
- if ($len < 1) {
- if ($defaultlanguage eq "F") {
- printf " Aucun serveur n'est connecté au login serveur.\n";
- } else {
- printf " No server is connected to the login-server.\n";
- }
- } else {
- my(@slist) = ();
- for(; $len > 0; $len -= 32) {
- my($name, $count) = unpack("x6 a20 V", readso(32));
- $name = substr($name, 0, index($name, "\0"));
- push @slist, [ $name, $count ];
- }
- # Displaying of result
- my($i);
- if ($defaultlanguage eq "F") {
- printf " Nombre de joueurs en ligne (serveur: nb):\n";
- } else {
- printf " Number of online players (server: number).\n";
- }
- foreach $i(@slist) {
- printf " %-20s : %5d\n", $i->[0], $i->[1];
- }
- }
-}
-
-#--------------------------------------------------------------------------
-
-# Sub-function: Modification of a memo field
-sub changememo {
- my($userid, $memo) = @_;
- if ($userid eq "") {
- if ($defaultlanguage eq "F") {
- print "Entrez un nom de compte svp.\n";
- print "<exemple> memo nomtest nouveau memo\n";
- } else {
- print "Please input an account name.\n";
- print "<example> memo testname new memo\n";
- }
- return 136;
- }
- if (verify_accountname($userid) == 0) {
- return 102;
- }
- if (length($memo) > 254) {
- if ($defaultlanguage eq "F") {
- print "Mémo trop long (".length($memo)." caractères).\n";
- print "Entrez un mémo de 254 caractères maximum svp.\n";
- } else {
- print "Memo is too long (".length($memo)." characters).\n";
- print "Please input a memo of 254 bytes at the maximum.\n";
- }
- return 102;
- }
- if (length($memo) == 0) {
- print $so pack("va24v", 0x7942, $userid, 0);
- } else {
- print $so pack("va24va".length($memo), 0x7942, $userid, length($memo), $memo);
- }
- $so->flush();
- $buf = readso(2);
- if (unpack("v", $buf) != 0x7943) {
- if ($defaultlanguage eq "F") {
- print "Problème de connexion au serveur (réponse incorrecte).\n";
- } else {
- print "Connection error to the server (incorrect answer).\n";
- }
- return 152;
- }
- $buf = readso(28);
- my($id2, $name) = unpack("Va24", $buf);
- while (length($name) > 0 && substr($name, length($name)-1, 1) eq chr(0)) {
- chop($name);
- };
- if ($id2 == -1 || $id2 == 4294967295) {
- if ($defaultlanguage eq "F") {
- print "Echec du changement du mémo du compte [$userid]. Le compte n'existe pas.\n";
- } else {
- print "Account [$userid] memo changing failed. Account doesn't exist.\n";
- }
- } else {
- if ($defaultlanguage eq "F") {
- print "Mémo du compte [$name][id: $id2] changé avec succès.\n";
- } else {
- print "Account [$name][id: $id2] memo successfully changed.\n";
- }
- }
-}
-
-#--------------------------------------------------------------------------
-
-# Sub-function: Request to obtain an account id
-sub idaccount() {
- my($userid) = @_;
- if ($userid eq "") {
- if ($defaultlanguage eq "F") {
- print "Entrez un nom de compte svp.\n";
- print "<exemple> id nomtest\n";
- } else {
- print "Please input an account name.\n";
- print "<example> id testname\n";
- }
- return 136;
- }
- if (verify_accountname($userid) == 0) {
- return 102;
- }
- print $so pack("va24", 0x7944, $userid);
- $so->flush();
- $buf = readso(2);
- if (unpack("v", $buf) != 0x7945) {
- if ($defaultlanguage eq "F") {
- print "Problème de connexion au serveur (réponse incorrecte).\n";
- } else {
- print "Connection error to the server (incorrect answer).\n";
- }
- return 122;
- }
- $buf = readso(28);
- my($id2, $name) = unpack("Va24", $buf);
- while (length($name) > 0 && substr($name, length($name)-1, 1) eq chr(0)) {
- chop($name);
- };
- if ($id2 == -1 || $id2 == 4294967295) {
- if ($defaultlanguage eq "F") {
- print "Impossible de trouver l'id du compte [$userid]. Le compte n'existe pas.\n";
- } else {
- print "Unabled to find the account [$userid] id. Account doesn't exist.\n";
- }
- return 123;
- } else {
- if ($defaultlanguage eq "F") {
- print "Le compte [$name] a pour id: $id2.\n";
- } else {
- print "The account [$name] have the id: $id2.\n";
- }
- }
- return 0;
-}
-
-#--------------------------------------------------------------------------
-
-# Sub-function: Request to obtain an account name
-sub nameaccount() {
- my($id) = @_;
- if ($id < 0) {
- if ($defaultlanguage eq "F") {
- print "Entrez un id ayant une valeur positive svp.\n";
- } else {
- print "Please input a positive value for the id.\n";
- }
- return 136;
- }
- print $so pack("vV", 0x7946, $id);
- $so->flush();
- $buf = readso(2);
- if (unpack("v", $buf) != 0x7947) {
- if ($defaultlanguage eq "F") {
- print "Problème de connexion au serveur (réponse incorrecte).\n";
- } else {
- print "Connection error to the server (incorrect answer).\n";
- }
- return 122;
- }
- $buf = readso(28);
- my($id2, $name) = unpack("Va24", $buf);
- while (length($name) > 0 && substr($name, length($name)-1, 1) eq chr(0)) {
- chop($name);
- };
- if (length($name) == 0 || $name eq "") {
- if ($defaultlanguage eq "F") {
- print "Impossible de trouver le nom du compte [id: $id2]. Le compte n'existe pas.\n";
- } else {
- print "Unabled to find the account [id: $id2] name. Account doesn't exist.\n";
- }
- return 123;
- } else {
- if ($defaultlanguage eq "F") {
- print "Le compte [id: $id2] a pour nom: $name.\n";
- } else {
- print "The account [id: $id2] have the name: $name.\n";
- }
- }
- return 0;
-}
-
-#--------------------------------------------------------------------------
-
-# Sub-function: Set a validity limit of an account
-sub timesetaccount() {
- my($userid, $date, $time) = @_;
- if ($userid eq "") {
- if ($defaultlanguage eq "F") {
- print "Entrez un nom de compte svp.\n";
- print "<exemple>: timeset <nom_du_compte> aaaa/mm/jj [hh:mm:ss]\n";
- print " timeset <nom_du_compte> 0 (0 = illimité)\n";
- printf " Heure par défaut [hh:mm:ss]: 23:59:59\n";
- } else {
- print "Please input an account name.\n";
- print "<example>: timeset <account_name> yyyy/mm/dd [hh:mm:ss]\n";
- print " timeset <account_name> 0 (0 = unlimited)\n";
- printf " Default time [hh:mm:ss]: 23:59:59\n";
- }
- return 136;
- }
- if (verify_accountname($userid) == 0) {
- return 102;
- }
- my($year, $month, $day) = split(/[.\-\/]/, $date);
- my($hour, $minute, $second) = split(/:/, $time);
- if ($time eq "") {
- $hour = 23;
- $minute = 59;
- $second = 59;
- }
- my($timestamp);
- if ($year eq "" ||
- ($year != 0 && ($month eq "" || $day eq "" || $hour eq "" || $minute eq "" || $second eq ""))) {
- if ($defaultlanguage eq "F") {
- print "Entrez 0 ou une date et une heure svp (format: 0 ou aaaa/mm/jj hh:mm:ss).\n";
- } else {
- print "Please input 0 or a date and a time (format: 0 or yyyy/mm/dd hh:mm:ss).\n";
- }
- return 102;
- }
- if ($year == 0) {
- $timestamp = 0;
- } else {
- if ($year < 70) {
- $year = $year + 100;
- }
- if ($year >= 1900) {
- $year = $year - 1900;
- }
- if ($month < 1 || $month > 12) {
- if ($defaultlanguage eq "F") {
- print "Entrez un mois correct svp (entre 1 et 12).\n";
- } else {
- print "Please give a correct value for the month (from 1 to 12).\n";
- }
- return 102;
- }
- $month = $month - 1;
- if ($day < 1 || $day > 31) {
- if ($defaultlanguage eq "F") {
- print "Entrez un jour correct svp (entre 1 et 31).\n";
- } else {
- print "Please give a correct value for the day (from 1 to 31).\n";
- }
- return 102;
- }
- if ((($month == 3 || $month == 5 || $month == 8 || $month == 10) && $day > 30) ||
- ($month == 1 && $day > 29)) {
- if ($defaultlanguage eq "F") {
- print "Entrez un jour correct en fonction du mois svp.\n";
- } else {
- print "Please give a correct value for a day of this month.\n";
- }
- return 102;
- }
- if ($hour < 0 || $hour > 23) {
- if ($defaultlanguage eq "F") {
- print "Entrez une heure correcte svp (entre 0 et 23).\n";
- } else {
- print "Please give a correct value for the hour (from 0 to 23).\n";
- }
- return 102;
- }
- if ($minute < 0 || $minute > 59) {
- if ($defaultlanguage eq "F") {
- print "Entrez des minutes correctes svp (entre 0 et 59).\n";
- } else {
- print "Please give a correct value for the minutes (from 0 to 59).\n";
- }
- return 102;
- }
- if ($second < 0 || $second > 59) {
- if ($defaultlanguage eq "F") {
- print "Entrez des secondes correctes svp (entre 0 et 59).\n";
- } else {
- print "Please give a correct value for the seconds (from 0 to 59).\n";
- }
- return 102;
- }
- $timestamp = POSIX::mktime($second, $minute, $hour, $day, $month, $year, 0, 0, -1); # -1: no winter/summer time modification
- if ($timestamp == undef) {
- if ($defaultlanguage eq "F") {
- print "Date incorrecte.\n";
- print "Ajoutez 0 ou une date et une heure svp (format: 0 ou aaaa/mm/jj hh:mm:ss).\n";
- } else {
- print "Invalid date.\n";
- print "Please add 0 or a date and a time (format: 0 or yyyy/mm/dd hh:mm:ss).\n";
- }
- return 102;
- }
- }
-
- print $so pack("va24V", 0x7948, $userid, $timestamp);
- $so->flush();
- $buf = readso(2);
- if (unpack("v", $buf) != 0x7949) {
- if ($defaultlanguage eq "F") {
- print "Problème de connexion au serveur (réponse incorrecte).\n";
- } else {
- print "Connection error to the server (incorrect answer).\n";
- }
- return 152;
- }
- $buf = readso(32);
- my(@dat) = unpack("Va24V", $buf);
- while (length($dat[1]) > 0 && substr($dat[1], length($dat[1])-1, 1) eq chr(0)) {
- chop($dat[1]);
- };
- if ($dat[0] != -1 && $dat[0] != 4294967295) {
- if ($defaultlanguage eq "F") {
- print "Limite de validité du compte [$dat[1]][id: $dat[0]] changée avec succès ".
- ($dat[2] == 0 ? "en [illimité].\n" : "pour être jusqu'au ".(POSIX::ctime($dat[2])));
- } else {
- print "Validity Limit of the account [$dat[1]][id: $dat[0]] successfully changed ".
- ($dat[2] == 0 ? "to [unlimited].\n" : "to be until ".(POSIX::ctime($dat[2])));
- }
- # localtime($dat[2]) is also possible to display instead of POSIX::ctime.
- } else {
- if ($defaultlanguage eq "F") {
- print "Echec du changement de la validité du compte [$userid]. Le compte n'existe pas.\n";
- } else {
- print "Account [$userid] validity limit changing failed. Account doesn't exist.\n";
- }
- }
-
- return 0;
-}
-
-#--------------------------------------------------------------------------
-
-# Sub-function: Add/substract time to the validity limit of an account
-sub timeaddaccount() {
- my($userid, $modif) = @_;
- if ($userid eq "") {
- if ($defaultlanguage eq "F") {
- print "Entrez un nom de compte svp.\n";
- print " <exemple> timeadd nomtest +1m-2mn1s-6y\n";
- print " Cette exemple ajoute 1 mois et 1 seconde, et soustrait 2 minutes\n";
- print " et 6 ans dans le même temps.\n";
- } else {
- print "Please input an account name.\n";
- print " <example> timeadd testname +1m-2mn1s-6y\n";
- print " this example adds 1 month and 1 second, and substracts 2 minutes\n";
- print " and 6 years at the same time.\n";
- }
- return 136;
- }
- if (verify_accountname($userid) == 0) {
- return 102;
- }
- my($year, $month, $day) = (0, 0 ,0);
- my($hour, $minute, $second) = (0, 0 ,0);
-
- $modif = lc($modif);
- while (length($modif) > 0) {
- my($value) = int($modif);
- if ($value == 0) {
- $modif = substr($modif, 1);
- } else {
- if (substr($modif, 0, 1) =~ /[\-\+]/) {
- $modif = substr($modif, 1);
- }
- while (length($modif) > 0 && substr($modif, 0, 1) =~ /[0-9]/) {
- $modif = substr($modif, 1);
- }
- if (index($modif, "s") == 0) {
- $second = $value;
- $modif = substr($modif, 1);
- } elsif (index($modif, "mn") == 0) {
- $minute = $value;
- $modif = substr($modif, 2);
- } elsif (index($modif, "h") == 0) {
- $hour = $value;
- $modif = substr($modif, 1);
- } elsif (index($modif, "d") == 0 || index($modif, "j") == 0) {
- $day = $value;
- $modif = substr($modif, 1);
- } elsif (index($modif, "m") == 0) {
- $month = $value;
- $modif = substr($modif, 1);
- } elsif (index($modif, "y") == 0 || index($modif, "a") == 0) {
- $year = $value;
- $modif = substr($modif, 1);
- } else {
- $modif = substr($modif, 1);
- }
- }
- }
-
- if ($defaultlanguage eq "F") {
- print " année: $year\n";
- print " mois: $month\n";
- print " jour: $day\n";
- print " heure: $hour\n";
- print " minute: $minute\n";
- print " seconde: $second\n";
- } else {
- print " year: $year\n";
- print " month: $month\n";
- print " day: $day\n";
- print " hour: $hour\n";
- print " minute: $minute\n";
- print " second: $second\n";
- }
-
- if ($year == 0 && $month == 0 && $day == 0 && $hour == 0 && $minute == 0 && $second == 0) {
- if ($defaultlanguage eq "F") {
- print "Vous devez entrer un ajustement avec cette commande, svp:\n";
- print " Valeur d'ajustement (-1, 1, +1, etc...)\n";
- print " Element modifié:\n";
- print " a ou y: année\n";
- print " m: mois\n";
- print " j ou d: jour\n";
- print " h: heure\n";
- print " mn: minute\n";
- print " s: seconde\n";
- print " <exemple> timeadd nomtest +1m-2mn1s-6y\n";
- print " Cette exemple ajoute 1 mois et 1 seconde, et soustrait 2 minutes\n";
- print " et 6 ans dans le même temps.\n";
- } else {
- print "Please give an adjustment with this command:\n";
- print " Adjustment value (-1, 1, +1, etc...)\n";
- print " Modified element:\n";
- print " a or y: year\n";
- print " m: month\n";
- print " j or d: day\n";
- print " h: hour\n";
- print " mn: minute\n";
- print " s: second\n";
- print " <example> timeadd testname +1m-2mn1s-6y\n";
- print " this example adds 1 month and 1 second, and substracts 2 minutes\n";
- print " and 6 years at the same time.\n";
- }
- return 137;
- }
- if ($year > 127 || $year < -127) {
- if ($defaultlanguage eq "F") {
- print "Entrez un ajustement d'années correct (de -127 à 127), svp.\n";
- } else {
- print "Please give a correct adjustment for the years (from -127 to 127).\n";
- }
- return 137;
- }
- if ($month > 255 || $month < -255) {
- if ($defaultlanguage eq "F") {
- print "Entrez un ajustement de mois correct (de -255 à 255), svp.\n";
- } else {
- print "Please give a correct adjustment for the months (from -255 to 255).\n";
- }
- return 137;
- }
- if ($day > 32767 || $day < -32767) {
- if ($defaultlanguage eq "F") {
- print "Entrez un ajustement de jours correct (de -32767 à 32767), svp.\n";
- } else {
- print "Please give a correct adjustment for the days (from -32767 to 32767).\n";
- }
- return 137;
- }
- if ($hour > 32767 || $hour < -32767) {
- if ($defaultlanguage eq "F") {
- print "Entrez un ajustement d'heures correct (de -32767 à 32767), svp.\n";
- } else {
- print "Please give a correct adjustment for the hours (from -32767 to 32767).\n";
- }
- return 137;
- }
- if ($minute > 32767 || $minute < -32767) {
- if ($defaultlanguage eq "F") {
- print "Entrez un ajustement de minutes correct (de -32767 à 32767), svp.\n";
- } else {
- print "Please give a correct adjustment for the minutes (from -32767 to 32767).\n";
- }
- return 137;
- }
- if ($second > 32767 || $second < -32767) {
- if ($defaultlanguage eq "F") {
- print "Entrez un ajustement de secondes correct (de -32767 à 32767), svp.\n";
- } else {
- print "Please give a correct adjustment for the seconds (from -32767 to 32767).\n";
- }
- return 137;
- }
-
- print $so pack("va24vvvvvv", 0x7950, $userid, $year, $month, $day, $hour, $minute, $second);
- $so->flush();
- $buf = readso(2);
- if (unpack("v", $buf) != 0x7951) {
- if ($defaultlanguage eq "F") {
- print "Problème de connexion au serveur (réponse incorrecte).\n";
- } else {
- print "Connection error to the server (incorrect answer).\n";
- }
- return 152;
- }
- $buf = readso(32);
- my(@dat) = unpack("Va24V", $buf);
- while (length($dat[1]) > 0 && substr($dat[1], length($dat[1])-1, 1) eq chr(0)) {
- chop($dat[1]);
- };
- if ($dat[0] == -1 || $dat[0] == 4294967295) {
- if ($defaultlanguage eq "F") {
- print "Echec du changement de la validité du compte [$userid]. Le compte n'existe pas.\n";
- } else {
- print "Account [$userid] validity limit changing failed. Account doesn't exist.\n";
- }
- } elsif ($dat[2] == 0) {
- if ($defaultlanguage eq "F") {
- print "Limite de validité du compte [$dat[1]][id: $dat[0]] inchangée.\n";
- print "Le compte a une validité illimitée ou\n";
- print "la modification est impossible avec les ajustements demandés.\n";
- } else {
- print "Validity limit of the account [$dat[1]][id: $dat[0]] unchanged.\n";
- print "The account have an unlimited validity limit or\n";
- print "the changing is impossible with the proposed adjustments.\n";
- }
- } else {
- if ($defaultlanguage eq "F") {
- print "Limite de validité du compte [$dat[1]][id: $dat[0]] changée avec succès ".
- ($dat[2] == 0 ? "en [illimité].\n" : "pour être jusqu'au ".(POSIX::ctime($dat[2])));
- } else {
- print "Validity limit of the account [$dat[1]][id: $dat[0]] successfully changed ".
- ($dat[2] == 0 ? "to [unlimited].\n" : "to be until ".(POSIX::ctime($dat[2])));
- }
- # localtime($dat[2]) is also possible to display instead of POSIX::ctime.
- }
-
- return 0;
-}
-
-#--------------------------------------------------------------------------
-
-# Sub-function: Set the final date of a banishment of an account
-sub bansetaccount() {
- my($userid, $date, $time) = @_;
- if ($userid eq "") {
- if ($defaultlanguage eq "F") {
- print "Entrez un nom de compte svp.\n";
- print "<exemple>: banset <nom_du_compte> aaaa/mm/jj [hh:mm:ss]\n";
- print " banset <nom_du_compte> 0 (0 = dé-bani)\n";
- print " ban/banish aaaa/mm/jj hh:mm:ss <nom du compte>\n";
- print " unban/unbanish <nom du compte>\n";
- printf " Heure par défaut [hh:mm:ss]: 23:59:59\n";
- } else {
- print "Please input an account name.\n";
- print "<example>: banset <account_name> yyyy/mm/dd [hh:mm:ss]\n";
- print " banset <account_name> 0 (0 = un-banished)\n";
- print " ban/banish yyyy/mm/dd hh:mm:ss <account name>\n";
- print " unban/unbanish <account name>\n";
- printf " Default time [hh:mm:ss]: 23:59:59\n";
- }
- return 136;
- }
- if (verify_accountname($userid) == 0) {
- return 102;
- }
- my($year, $month, $day) = split(/[.\-\/]/, $date);
- my($hour, $minute, $second) = split(/:/, $time);
- if ($time eq "") {
- $hour = 23;
- $minute = 59;
- $second = 59;
- }
- my($timestamp);
- if ($year eq "" ||
- ($year != 0 && ($month eq "" || $day eq "" || $hour eq "" || $minute eq "" || $second eq ""))) {
- if ($defaultlanguage eq "F") {
- print "Entrez 0 ou une date et une heure svp (format: 0 ou aaaa/mm/jj hh:mm:ss).\n";
- } else {
- print "Please input 0 or a date and a time (format: 0 or yyyy/mm/dd hh:mm:ss).\n";
- }
- return 102;
- }
- if ($year == 0) {
- $timestamp = 0;
- } else {
- if ($year < 70) {
- $year = $year + 100;
- }
- if ($year >= 1900) {
- $year = $year - 1900;
- }
- if ($month < 1 || $month > 12) {
- if ($defaultlanguage eq "F") {
- print "Entrez un mois correct svp (entre 1 et 12).\n";
- } else {
- print "Please give a correct value for the month (from 1 to 12).\n";
- }
- return 102;
- }
- $month = $month - 1;
- if ($day < 1 || $day > 31) {
- if ($defaultlanguage eq "F") {
- print "Entrez un jour correct svp (entre 1 et 31).\n";
- } else {
- print "Please give a correct value for the day (from 1 to 31).\n";
- }
- return 102;
- }
- if ((($month == 3 || $month == 5 || $month == 8 || $month == 10) && $day > 30) ||
- ($month == 1 && $day > 29)) {
- if ($defaultlanguage eq "F") {
- print "Entrez un jour correct en fonction du mois svp.\n";
- } else {
- print "Please give a correct value for a day of this month.\n";
- }
- return 102;
- }
- if ($hour < 0 || $hour > 23) {
- if ($defaultlanguage eq "F") {
- print "Entrez une heure correcte svp (entre 0 et 23).\n";
- } else {
- print "Please give a correct value for the hour (from 0 to 23).\n";
- }
- return 102;
- }
- if ($minute < 0 || $minute > 59) {
- if ($defaultlanguage eq "F") {
- print "Entrez des minutes correctes svp (entre 0 et 59).\n";
- } else {
- print "Please give a correct value for the minutes (from 0 to 59).\n";
- }
- return 102;
- }
- if ($second < 0 || $second > 59) {
- if ($defaultlanguage eq "F") {
- print "Entrez des secondes correctes svp (entre 0 et 59).\n";
- } else {
- print "Please give a correct value for the seconds (from 0 to 59).\n";
- }
- return 102;
- }
- $timestamp = POSIX::mktime($second, $minute, $hour, $day, $month, $year, 0, 0, -1); # -1: no winter/summer time modification
- if ($timestamp == undef) {
- if ($defaultlanguage eq "F") {
- print "Date incorrecte.\n";
- print "Ajoutez 0 ou une date et une heure svp (format: 0 ou aaaa/mm/jj hh:mm:ss).\n";
- } else {
- print "Invalid date.\n";
- print "Please add 0 or a date and a time (format: 0 or yyyy/mm/dd hh:mm:ss).\n";
- }
- return 102;
- }
- }
-
- print $so pack("va24V", 0x794a, $userid, $timestamp);
- $so->flush();
- $buf = readso(2);
- if (unpack("v", $buf) != 0x794b) {
- if ($defaultlanguage eq "F") {
- print "Problème de connexion au serveur (réponse incorrecte).\n";
- } else {
- print "Connection error to the server (incorrect answer).\n";
- }
- return 152;
- }
- $buf = readso(32);
- my(@dat) = unpack("Va24V", $buf);
- while (length($dat[1]) > 0 && substr($dat[1], length($dat[1])-1, 1) eq chr(0)) {
- chop($dat[1]);
- };
- if ($dat[0] != -1 && $dat[0] != 4294967295) {
- if ($defaultlanguage eq "F") {
- print "Date finale de banissement du compte [$dat[1]][id: $dat[0]] changée avec succès ".
- ($dat[2] == 0 ? "en [dé-bannie].\n" : "pour être jusqu'au ".(POSIX::ctime($dat[2])));
- } else {
- print "Final date of banishment of the account [$dat[1]][id: $dat[0]] successfully changed ".
- ($dat[2] == 0 ? "to [unbanished].\n" : "to be until ".(POSIX::ctime($dat[2])));
- }
- # localtime($dat[2]) is also possible to display instead of POSIX::ctime.
- } else {
- if ($defaultlanguage eq "F") {
- print "Echec du changement de la date finale de banissement du compte [$userid]. Le compte n'existe pas.\n";
- } else {
- print "Account [$userid] final date of banishment changing failed. Account doesn't exist.\n";
- }
- }
-
- return 0;
-}
-
-#--------------------------------------------------------------------------
-
-# Sub-function: Add/substract time to the final date of a banishment of an account
-sub banaddaccount() {
- my($userid, $modif) = @_;
- if ($userid eq "") {
- if ($defaultlanguage eq "F") {
- print "Entrez un nom de compte svp.\n";
- print " <exemple> banadd nomtest +1m-2mn1s-6y\n";
- print " Cette exemple ajoute 1 mois et 1 seconde, et soustrait 2 minutes\n";
- print " et 6 ans dans le même temps.\n";
- } else {
- print "Please input an account name.\n";
- print " <example> banadd testname +1m-2mn1s-6y\n";
- print " this example adds 1 month and 1 second, and substracts 2 minutes\n";
- print " and 6 years at the same time.\n";
- }
- return 136;
- }
- if (verify_accountname($userid) == 0) {
- return 102;
- }
- my($year, $month, $day) = (0, 0 ,0);
- my($hour, $minute, $second) = (0, 0 ,0);
-
- $modif = lc($modif);
- while (length($modif) > 0) {
- my($value) = int($modif);
- if ($value == 0) {
- $modif = substr($modif, 1);
- } else {
- if (substr($modif, 0, 1) =~ /[\-\+]/) {
- $modif = substr($modif, 1);
- }
- while (length($modif) > 0 && substr($modif, 0, 1) =~ /[0-9]/) {
- $modif = substr($modif, 1);
- }
- if (index($modif, "s") == 0) {
- $second = $value;
- $modif = substr($modif, 1);
- } elsif (index($modif, "mn") == 0) {
- $minute = $value;
- $modif = substr($modif, 2);
- } elsif (index($modif, "h") == 0) {
- $hour = $value;
- $modif = substr($modif, 1);
- } elsif (index($modif, "d") == 0 || index($modif, "j") == 0) {
- $day = $value;
- $modif = substr($modif, 1);
- } elsif (index($modif, "m") == 0) {
- $month = $value;
- $modif = substr($modif, 1);
- } elsif (index($modif, "y") == 0 || index($modif, "a") == 0) {
- $year = $value;
- $modif = substr($modif, 1);
- } else {
- $modif = substr($modif, 1);
- }
- }
- }
-
- if ($defaultlanguage eq "F") {
- print " année: $year\n";
- print " mois: $month\n";
- print " jour: $day\n";
- print " heure: $hour\n";
- print " minute: $minute\n";
- print " seconde: $second\n";
- } else {
- print " year: $year\n";
- print " month: $month\n";
- print " day: $day\n";
- print " hour: $hour\n";
- print " minute: $minute\n";
- print " second: $second\n";
- }
-
- if ($year == 0 && $month == 0 && $day == 0 && $hour == 0 && $minute == 0 && $second == 0) {
- if ($defaultlanguage eq "F") {
- print "Vous devez entrer un ajustement avec cette commande, svp:\n";
- print " Valeur d'ajustement (-1, 1, +1, etc...)\n";
- print " Element modifié:\n";
- print " a ou y: année\n";
- print " m: mois\n";
- print " j ou d: jour\n";
- print " h: heure\n";
- print " mn: minute\n";
- print " s: seconde\n";
- print " <exemple> banadd nomtest +1m-2mn1s-6y\n";
- print " Cette exemple ajoute 1 mois et 1 seconde, et soustrait 2 minutes\n";
- print " et 6 ans dans le même temps.\n";
- } else {
- print "Please give an adjustment with this command:\n";
- print " Adjustment value (-1, 1, +1, etc...)\n";
- print " Modified element:\n";
- print " a or y: year\n";
- print " m: month\n";
- print " j or d: day\n";
- print " h: hour\n";
- print " mn: minute\n";
- print " s: second\n";
- print " <example> banadd testname +1m-2mn1s-6y\n";
- print " this example adds 1 month and 1 second, and substracts 2 minutes\n";
- print " and 6 years at the same time.\n";
- }
- return 137;
- }
- if ($year > 127 || $year < -127) {
- if ($defaultlanguage eq "F") {
- print "Entrez un ajustement d'années correct (de -127 à 127), svp.\n";
- } else {
- print "Please give a correct adjustment for the years (from -127 to 127).\n";
- }
- return 137;
- }
- if ($month > 255 || $month < -255) {
- if ($defaultlanguage eq "F") {
- print "Entrez un ajustement de mois correct (de -255 à 255), svp.\n";
- } else {
- print "Please give a correct adjustment for the months (from -255 to 255).\n";
- }
- return 137;
- }
- if ($day > 32767 || $day < -32767) {
- if ($defaultlanguage eq "F") {
- print "Entrez un ajustement de jours correct (de -32767 à 32767), svp.\n";
- } else {
- print "Please give a correct adjustment for the days (from -32767 to 32767).\n";
- }
- return 137;
- }
- if ($hour > 32767 || $hour < -32767) {
- if ($defaultlanguage eq "F") {
- print "Entrez un ajustement d'heures correct (de -32767 à 32767), svp.\n";
- } else {
- print "Please give a correct adjustment for the hours (from -32767 to 32767).\n";
- }
- return 137;
- }
- if ($minute > 32767 || $minute < -32767) {
- if ($defaultlanguage eq "F") {
- print "Entrez un ajustement de minutes correct (de -32767 à 32767), svp.\n";
- } else {
- print "Please give a correct adjustment for the minutes (from -32767 to 32767).\n";
- }
- return 137;
- }
- if ($second > 32767 || $second < -32767) {
- if ($defaultlanguage eq "F") {
- print "Entrez un ajustement de secondes correct (de -32767 à 32767), svp.\n";
- } else {
- print "Please give a correct adjustment for the seconds (from -32767 to 32767).\n";
- }
- return 137;
- }
-
- print $so pack("va24vvvvvv", 0x794c, $userid, $year, $month, $day, $hour, $minute, $second);
- $so->flush();
- $buf = readso(2);
- if (unpack("v", $buf) != 0x794d) {
- if ($defaultlanguage eq "F") {
- print "Problème de connexion au serveur (réponse incorrecte).\n";
- } else {
- print "Connection error to the server (incorrect answer).\n";
- }
- return 152;
- }
- $buf = readso(32);
- my(@dat) = unpack("Va24V", $buf);
- while (length($dat[1]) > 0 && substr($dat[1], length($dat[1])-1, 1) eq chr(0)) {
- chop($dat[1]);
- };
- if ($dat[0] == -1 || $dat[0] == 4294967295) {
- if ($defaultlanguage eq "F") {
- print "Echec du changement de la date finale de banissement du compte [$userid]. Le compte n'existe pas.\n";
- } else {
- print "Account [$userid] final date of banishment changing failed. Account doesn't exist.\n";
- }
- } else {
- if ($defaultlanguage eq "F") {
- print "Date finale de banissement du compte [$dat[1]][id: $dat[0]] changée avec succès ".
- ($dat[2] == 0 ? "en [dé-bannie].\n" : "pour être jusqu'au ".(POSIX::ctime($dat[2])));
- } else {
- print "Final date of banishment of the account [$dat[1]][id: $dat[0]] successfully changed ".
- ($dat[2] == 0 ? "to [unbanished].\n" : "to be until ".(POSIX::ctime($dat[2])));
- }
- # localtime($dat[2]) is also possible to display instead of POSIX::ctime.
- }
-
- return 0;
-}
-
-#--------------------------------------------------------------------------
-
-# Sub-function: Request to displaying information about an account (by its name)
-sub whoaccount() {
- my($userid) = @_;
- if ($userid eq "") {
- if ($defaultlanguage eq "F") {
- print "Entrez un nom de compte svp.\n";
- print "<exemple> who nomtest\n";
- } else {
- print "Please input an account name.\n";
- print "<example> who testname\n";
- }
- return 136;
- }
- if (verify_accountname($userid) == 0) {
- return 102;
- }
-
- print $so pack("va24", 0x7952, $userid);
- $so->flush();
-
- $buf = readso(2);
- if (unpack("v", $buf) != 0x7953) {
- if ($defaultlanguage eq "F") {
- print "Problème de connexion au serveur (réponse incorrecte).\n";
- } else {
- print "Connection error to the server (incorrect answer).\n";
- }
- return 122;
- }
- my($id2, $GM_level, $name, $sex, $count, $status, $error_message, $last_login, $last_ip, $email, $validite, $ban_date, $memo_size) = unpack("VCa24cVVa20a24a16a40VVv", readso(148));
- my($memo) = "";
- if ($memo_size > 0) {
- $memo = unpack("a".$memo_size, readso($memo_size));
- }
- while (length($name) > 0 && substr($name, length($name)-1, 1) eq chr(0)) {
- chop($name);
- };
- while (length($error_message) > 0 && substr($error_message, length($error_message)-1, 1) eq chr(0)) {
- chop($error_message);
- };
- while (length($last_login) > 0 && substr($last_login, length($last_login)-1, 1) eq chr(0)) {
- chop($last_login);
- };
- while (length($last_ip) > 0 && substr($last_ip, length($last_ip)-1, 1) eq chr(0)) {
- chop($last_ip);
- };
- while (length($email) > 0 && substr($email, length($email)-1, 1) eq chr(0)) {
- chop($email);
- };
- while (length($memo) > 0 && substr($memo, length($memo)-1, 1) eq chr(0)) {
- chop($memo);
- };
-
- if ($id2 == -1 || $id2 == 4294967295) {
- if ($defaultlanguage eq "F") {
- print "Impossible de trouver le compte [$userid]. Le compte n'existe pas.\n";
- } else {
- print "Unabled to find the account [$userid]. Account doesn't exist.\n";
- }
- return 123;
- } else {
- if ($defaultlanguage eq "F") {
- print "Le compte [$userid] a les caractéristiques suivantes:\n";
- } else {
- print "The account [$userid] is set with:\n";
- }
- if ($GM_level == 0) {
- print " Id: $id2 (non-GM)\n";
- } else {
- if ($defaultlanguage eq "F") {
- print " Id: $id2 (GM niveau $GM_level)\n";
- } else {
- print " Id: $id2 (GM level $GM_level)\n";
- }
- }
- if ($defaultlanguage eq "F") {
- print " Nom: '$name'\n";
- print " Sexe: ".("Femme", "Male", "Serveur")[$sex]."\n";
- } else {
- print " Name: '$name'\n";
- print " Sex: ".("Female", "Male", "Server")[$sex]."\n";
- }
- print " E-mail: $email\n";
- if ($status == 7) {
- print " Statut: 7 [You are Prohibited to log in until $error_message]\n";
- } else {
- print " Statut: $status [".(
- ($defaultlanguage eq "F" ? "Compte Ok" : "Account OK"),
- "Unregistered ID",
- "Incorrect Password",
- "This ID is expired",
- "Rejected from Server",
- "You have been blocked by the GM Team",
- "Your Game's EXE file is not the latest version",
- "You are Prohibited to log in until %s",
- "Server is jammed due to over populated",
- "No MSG",
- "This ID is totally erased")[$status == 100 ? 10 : $status]."]\n";
- }
- if ($defaultlanguage eq "F") {
- print " Banissement: ".($ban_date == 0 ? "non banni.\n" : "jusqu'au ".(POSIX::ctime($ban_date)));
- print " Compteur: $count connexion".("s", "")[$count > 1 ? 0 : 1]."\n";
- print " Dernière connexion le: $last_login (ip: $last_ip)\n";
- print " Limite de validité: ".($validite == 0 ? "illimité.\n" : "jusqu'au ".(POSIX::ctime($validite)));
- } else {
- print " Banishment: ".($ban_date == 0 ? "not banished.\n" : "until ".(POSIX::ctime($ban_date)));
- print " Count: $count connection".("s", "")[$count > 1 ? 0 : 1]."\n";
- print " Last connection at: $last_login (ip: $last_ip)\n";
- print " Validity limit: ".($validite == 0 ? "unlimited.\n" : "until ".(POSIX::ctime($validite)));
- }
- print " Memo: '$memo'\n";
- }
- return 0;
-}
-
-#--------------------------------------------------------------------------
-
-# Sub-function: Request to displaying information about an account (by its id)
-sub infoaccount() {
- my($id) = @_;
- if ($id < 0) {
- if ($defaultlanguage eq "F") {
- print "Entrez un id ayant une valeur positive svp.\n";
- } else {
- print "Please input a positive value for the id.\n";
- }
- return 136;
- }
-
- print $so pack("vV", 0x7954, $id);
- $so->flush();
-
- $buf = readso(2);
- if (unpack("v", $buf) != 0x7953) {
- if ($defaultlanguage eq "F") {
- print "Problème de connexion au serveur (réponse incorrecte).\n";
- } else {
- print "Connection error to the server (incorrect answer).\n";
- }
- return 122;
- }
- my($id2, $GM_level, $name, $sex, $count, $status, $error_message, $last_login, $last_ip, $email, $validite, $ban_date, $memo_size) = unpack("VCa24cVVa20a24a16a40VVv", readso(148));
- my($memo) = "";
- if ($memo_size > 0) {
- $memo = unpack("a".$memo_size, readso($memo_size));
- }
- while (length($name) > 0 && substr($name, length($name)-1, 1) eq chr(0)) {
- chop($name);
- };
- while (length($error_message) > 0 && substr($error_message, length($error_message)-1, 1) eq chr(0)) {
- chop($error_message);
- };
- while (length($last_login) > 0 && substr($last_login, length($last_login)-1, 1) eq chr(0)) {
- chop($last_login);
- };
- while (length($last_ip) > 0 && substr($last_ip, length($last_ip)-1, 1) eq chr(0)) {
- chop($last_ip);
- };
- while (length($email) > 0 && substr($email, length($email)-1, 1) eq chr(0)) {
- chop($email);
- };
- while (length($memo) > 0 && substr($memo, length($memo)-1, 1) eq chr(0)) {
- chop($memo);
- };
-
- if (length($name) == 0 || $name eq "") {
- if ($defaultlanguage eq "F") {
- print "Impossible de trouver le nom du compte [id: $id2]. Le compte n'existe pas.\n";
- } else {
- print "Unabled to find the account [id: $id2] name. Account doesn't exist.\n";
- }
- return 123;
- } else {
- if ($defaultlanguage eq "F") {
- print "Le compte [id: $id2] a les caractéristiques suivantes:\n";
- } else {
- print "The account [id: $id2] is set with:\n";
- }
- if ($GM_level == 0) {
- print " Id: $id2 (non-GM)\n";
- } else {
- if ($defaultlanguage eq "F") {
- print " Id: $id2 (GM niveau $GM_level)\n";
- } else {
- print " Id: $id2 (GM level $GM_level)\n";
- }
- }
- if ($defaultlanguage eq "F") {
- print " Nom: '$name'\n";
- print " Sexe: ".("Femme", "Male", "Serveur")[$sex]."\n";
- } else {
- print " Name: '$name'\n";
- print " Sex: ".("Female", "Male", "Server")[$sex]."\n";
- }
- print " E-mail: $email\n";
- if ($status == 7) {
- print " Statut: 7 [You are Prohibited to log in until $error_message]\n";
- } else {
- print " Statut: $status [".(
- ($defaultlanguage eq "F" ? "Compte Ok" : "Account OK"),
- "Unregistered ID",
- "Incorrect Password",
- "This ID is expired",
- "Rejected from Server",
- "You have been blocked by the GM Team",
- "Your Game's EXE file is not the latest version",
- "You are Prohibited to log in until %s",
- "Server is jammed due to over populated",
- "No MSG",
- "This ID is totally erased")[$status == 100 ? 10 : $status]."]\n";
- }
- if ($defaultlanguage eq "F") {
- print " Banissement: ".($ban_date == 0 ? "non banni.\n" : "jusqu'au ".(POSIX::ctime($ban_date)));
- print " Compteur: $count connexion".("s", "")[$count > 1 ? 0 : 1]."\n";
- print " Dernière connexion le: $last_login (ip: $last_ip)\n";
- print " Limite de validité: ".($validite == 0 ? "illimité.\n" : "jusqu'au ".(POSIX::ctime($validite)));
- } else {
- print " Banishment: ".($ban_date == 0 ? "not banished.\n" : "until ".(POSIX::ctime($ban_date)));
- print " Count: $count connection".("s", "")[$count > 1 ? 0 : 1]."\n";
- print " Last connection at: $last_login (ip: $last_ip)\n";
- print " Validity limit: ".($validite == 0 ? "unlimited.\n" : "until ".(POSIX::ctime($validite)));
- }
- print " Memo: '$memo'\n";
- }
- return 0;
-}
-
-#--------------------------------------------------------------------------
-
-# Sub-function: Check the validity of a password
-# (Note: never send back a password with login-server!! security of passwords)
-sub checkaccount() {
- my($userid, $passwd) = @_;
- if ($userid eq "") {
- if ($defaultlanguage eq "F") {
- print "Entrez un nom de compte svp.\n";
- print "<exemple> check testname motdepasse\n";
- } else {
- print "Please input an account name.\n";
- print "<example> check testname password\n";
- }
- return 136;
- }
- if (verify_accountname($userid) == 0) {
- return 102;
- }
- if ($passwd eq "") {
- return 134 if (($passwd = typepasswd()) eq "");
- }
- if (verify_password($passwd) == 0) {
- return 131;
- }
- print $so pack("va24a24", 0x793a, $userid,$passwd);
- $so->flush();
- $buf = readso(2);
- if (unpack("v", $buf) != 0x793b) {
- if ($defaultlanguage eq "F") {
- print "Problème de connexion au serveur (réponse incorrecte).\n";
- } else {
- print "Connection error to the server (incorrect answer).\n";
- }
- return 132;
- }
- $buf = readso(28);
- my($id2, $name) = unpack("Va24", $buf);
- while (length($name) > 0 && substr($name, length($name)-1, 1) eq chr(0)) {
- chop($name);
- };
- if ($id2 == -1 || $id2 == 4294967295) {
- if ($defaultlanguage eq "F") {
- print "Le compte [$userid] n'existe pas ou le mot de passe est incorrect.\n";
- } else {
- print "The account [$userid] doesn't exist or the password is incorrect.\n";
- }
- return 133;
- } else {
- if ($defaultlanguage eq "F") {
- print "Le mot de passe donné correspond bien au compte [$name][id: $id2].\n";
- } else {
- print "The proposed password is correct for the account [$name][id: $id2].\n";
- }
- }
- return 130;
-}
-
-#--------------------------------------------------------------------------
-
-# Sub-function: Request to login-server to reload GM configuration file
-sub reloadGM() {
- print $so pack("v", 0x7955);
- $so->flush();
- if ($defaultlanguage eq "F") {
- print "Demande de recharger le fichier de configuration des GM envoyée.\n";
- print "Vérifiez les comptes GM actuels (après rechargement):\n";
- } else {
- print "Request to reload the GM configuration file sended.\n";
- print "Check the actual GM accounts (after reloading):\n";
- }
- &listaccount(0, 0, 1); # 1: to list only GM
- return 180;
-}
-
-#--------------------------------------------------------------------------
-
-# Sub-function: Send a broadcast message
-sub sendbroadcast() {
- my($type, $message) = @_;
- if ($message eq "" || length($message) == 0) {
- if ($defaultlanguage eq "F") {
- print "Entrez un message svp.\n";
- if ($type == 0) {
- print "<exemple> kami un message\n";
- } else {
- print "<exemple> kamib un message\n";
- }
- } else {
- print "Please input a message.\n";
- if ($type == 0) {
- print "<example> kami a message\n";
- } else {
- print "<example> kamib a message\n";
- }
- }
- return 136;
- }
-
- print $so pack("vvVa".length($message), 0x794e, $type, length($message), $message);
- $so->flush();
- $buf = readso(2);
- if (unpack("v", $buf) != 0x794f) {
- if ($defaultlanguage eq "F") {
- print "Problème de connexion au serveur (réponse incorrecte).\n";
- } else {
- print "Connection error to the server (incorrect answer).\n";
- }
- return 152;
- }
- $buf = readso(2);
- my($answer) = unpack("v", $buf);
- if ($answer == -1 || $answer == 65535) {
- if ($defaultlanguage eq "F") {
- print "Echec de l'envoi du message. Aucun server de char en ligne.\n";
- } else {
- print "Message sending failed. No online char-server.\n";
- }
- } else {
- if ($defaultlanguage eq "F") {
- print "Message transmis au server de logins avec succès.\n";
- } else {
- print "Message successfully sended to login-server.\n";
- }
- }
-}
-
-#--------------------------------------------------------------------------
-
-# Sub-function: Change language of displaying
-sub changelanguage() {
- my($language) = @_;
- if ($language eq "" || length($language) == 0) {
- if ($defaultlanguage == 'F') {
- printf("Entrez une langue svp.\n");
- printf("<exemple> language english\n");
- printf(" language français\n");
- } else {
- printf("Please input a language.\n");
- printf("<example> language english\n");
- printf(" language français\n");
- }
- return 136;
- }
-
- $language = uc(substr($language, 0, 1));
- if ($language =~ /^[EF]$/) {
- $defaultlanguage = $language;
- if ($defaultlanguage == 'F') {
- printf("Changement de la langue d'affichage en Français.\n");
- } else {
- printf("Displaying language changed to English.\n");
- }
- } else {
- if ($defaultlanguage == 'F') {
- printf("Langue non paramétrée (langues possibles: 'Français' ou 'English').\n");
- } else {
- printf("Undefined language (possible languages: Français or English).\n");
- }
- }
-
- return 0;
-}
-
-#--------------------------------------------------------------------------
-
-# Sub-function: sending 'end of connection' packet
-sub quit() {
- print $so pack("v", 0x7532);
- $so->flush();
-}
-
-#--------------------------------------------------------------------------
-
-# Sub-function: Get datas from the socket
-sub readso() {
- my($len) = shift;
- my($buf);
- if (read($so, $buf, $len) < $len) {
- if ($defaultlanguage eq "F") {
- print "Erreur de lecture sur la Socket.\n";
- } else {
- print "Socket read error.\n";
- }
- exit(3);
- }
- return $buf;
-}
-
-#--------------------------------------------------------------------------
-
-# Sub-function: Input of a password
-sub typepasswd {
- my($passwd1, $passwd2);
- cbreak();
- if ($defaultlanguage eq "F") {
- print "Entrez le mot de passe > "; $passwd1 = <STDIN>; chomp($passwd1); print "\n";
- print "Ré-entrez le mot de passe > "; $passwd2 = <STDIN>; chomp($passwd2); print "\n";
- } else {
- print "Type the password > "; $passwd1 = <STDIN>; chomp($passwd1); print "\n";
- print "Verify the password > "; $passwd2 = <STDIN>; chomp($passwd2); print "\n";
- }
- cooked();
- if ($passwd1 ne $passwd2) {
- if ($defaultlanguage eq "F") {
- print "Erreur de vérification du mot de passe: Saisissez le même mot de passe svp.\n";
- } else {
- print "Password verification failed. Please input same password.\n";
- }
- return "";
- }
- return $passwd1;
-}
-
-#--------------------------------------------------------------------------
-
-# Sub-function: Return ordonal text of a number
-sub makeordinal {
- my($c) = shift;
- if ($defaultlanguage eq "F") {
- if ($c < 1) {
- return $c;
- }
- return $c.("er", "ème")[$c == 1 ? 0 : 1];
- } else {
- if ($c % 10 < 4 && $c % 10 != 0 && ($c < 10 || $c > 20)) {
- return $c.("st","nd","rd")[$c % 10 - 1];
- }
- return $c."th";
- }
-}
-
-#--------------------------------------------------------------------------
-
-# Sub-function: Test of the validity of an account name (return 0 if incorrect, and 1 if ok)
-sub verify_accountname {
- my($account_name) = @_; # Get the account_name
- if ($account_name =~ /[\x00-\x1f]/) { # remove control char
- my($c) = length($`) + 1;
- if ($defaultlanguage eq "F") {
- print "Caractère interdit trouvé dans le nom du compte (".makeordinal($c)." caractère).\n";
- } else {
- print "Illegal character found in the account name (".makeordinal($c)." character).\n";
- }
- return 0;
- }
- if (length($account_name) < 4) {
- if ($defaultlanguage eq "F") {
- print "Nom du compte trop court. Entrez un nom de compte de 4-23 caractères.\n";
- } else {
- print "Account name is too short. Please input an account name of 4-23 bytes.\n";
- }
- return 0;
- }
- if (length($account_name) > 23) {
- if ($defaultlanguage eq "F") {
- print "Nom du compte trop long. Entrez un nom de compte de 4-23 caractères.\n";
- } else {
- print "Account name is too long. Please input an account name of 4-23 bytes.\n";
- }
- return 0;
- }
- return 1;
-}
-
-#--------------------------------------------------------------------------
-
-# Sub-function: Test of the validity of password (return 0 if incorrect, and 1 if ok)
-sub verify_password {
- my($password) = @_; # Get the password
- if ($password =~ /[\x00-\x1f]/) {
- my($c) = length($`) + 1;
- if ($defaultlanguage eq "F") {
- print "Caractère interdit trouvé dans le mot de passe (".makeordinal($c)." caractère).\n";
- } else {
- print "Illegal character found in the password (".makeordinal($c)." character).\n";
- }
- return 0;
- }
- if (length($password) < 4) {
- if ($defaultlanguage eq "F") {
- print "Mot de passe trop court. Entrez un mot de passe de 4-23 caractères.\n";
- } else {
- print "Password is too short. Please input a password of 4-23 bytes.\n";
- }
- return 0;
- }
- if (length($password) > 23) {
- if ($defaultlanguage eq "F") {
- print "Mot de passe trop long. Entrez un mot de passe de 4-23 caractères.\n";
- } else {
- print "Password is too long. Please input a password of 4-23 bytes.\n";
- }
- return 0;
- }
- return 1;
-}
-
-#--------------------------------------------------------------------------
-
-# Sub-function: Test of the validity of an e-mail (return 0 if incorrect, and 1 if ok)
-sub verify_email {
- my($email) = @_; # Get the e-mail
- # To ignore a '.' before the @ (wanadoo, a provider, do that)
- $email =~ s/\.\@/\@/;
- # If the e-mail is void, it's not correct -> return 0
- if ($email eq '') {
- return(0);
- }
- # If the e-mail have no "@", it's not correct -> return 0
- if ($email !~ /\@/) {
- return(0);
- }
- # If the e-mail have a ",", a space, a tab or a ";", it's not correct -> return 0
- if ($email =~ /[\,|\s|\;]/) {
- return(0)
- };
- # IF
- # (the e-mail contains 2 "@", or ".." or "@." or starts or finishes by a ".")
- # OR IF
- # (the e-mail doesn't contain "@localhost" AND
- # - it doesn't contain characters followed by "@" itself followed by letters itself followed by "." and 2 or more letters
- # - or an IP address)
- # -> so, it's not good ! (finish !)
- if ($email =~ /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)|(\.$)/ ||
- ($email !~ /^.+\@localhost$/ &&
- $email !~ /^.+\@\[?(\w|[-.])+\.[a-zA-Z]{2,3}|[0-9]{1,3}\]?$/)) {
- return(0); # non-valid email
- } else {
- # If not, the e-email address is correct
- return(1); # valid email
- }
-} \ No newline at end of file
diff --git a/src/tool/mapcheck.sh b/src/tool/mapcheck.sh
deleted file mode 100644
index 337884c..0000000
--- a/src/tool/mapcheck.sh
+++ /dev/null
@@ -1,34 +0,0 @@
-#!/bin/sh
-echo "============================================"
-echo "= map server status checker... ="
-echo "============================================"
-./map-server.exe &
-sleep 40
-
-while [ 0 ]
-do
- pcpu=` top -n 1| grep map-server | awk '{print $9}' | awk 'BEGIN{FS="."} {print $1}' `
- if [ "$pcpu" -gt 80 ];then
- echo "============================================"
- echo "map server is more than 80% (now $pcpu%)"
- echo "============================================"
- ppid=` ps -a | grep map-server | awk '{print $1}' `
- kill $ppid
- ./map-server.exe &
- sleep 40
- else
- pmapct=` ps -a| grep map-server | wc -l `
- if [ "$pmapct" -eq 0 ];then
- echo "============================================"
- echo "map server is not running..."
- echo "restart map server..."
- echo "============================================"
- ./map-server.exe &
- sleep 40
- #echo "test"
- else
- echo "map server is ok (now $pcpu%)..."
- sleep 5
- fi
- fi
-done \ No newline at end of file
diff --git a/src/tool/mapchecker.sh b/src/tool/mapchecker.sh
deleted file mode 100644
index 7250c34..0000000
--- a/src/tool/mapchecker.sh
+++ /dev/null
@@ -1,56 +0,0 @@
-#!/bin/bash
-
-athena_dir="/home/athena/658/"
-
-while [ true ] ; do
-
-if [ ` ps fauxw | grep map-server | grep -v grep | wc -l ` -eq 0 ];then
- #echo `date` " -- map-server crashed - restarting"
- echo `date` " -- map-server crashed - restarting" >> /var/log/athena_status.log
- killall -9 map-server
- cd $athena_dir
- nohup ./map-server ./conf/map_athena.conf ./inter_athena.conf &
- sleep 240
- #sleep 40 #for fast pc's remove the "#" at the beginning of the line and delete the line above
-fi
-
-
-if [ ` ps fauxw | grep map-server | grep -v grep | awk '{print $3}' | awk 'BEGIN{FS="."} {print $1}' ` -gt 10 ];then
- #echo `date` " -- mapserver cpuload over 10 - restarting"
- echo `date` " -- mapserver cpuload over 10 - restarting" >> /var/log/athena_status.log
- killall -9 map-server
- cd $athena_dir
- nohup ./map-server ./conf/map_athena.conf ./inter_athena.conf &
- sleep 240
- #sleep 40 #for fast pc's remove the "#" at the beginning of the line and delete the line above
- #echo `date` " -- restarted"
- echo `date` " -- restarted" >> /var/log/athena_status.log
-fi
-
-if [ ` ps fauxw | grep char-server | grep -v grep | wc -l ` -eq 0 ];then
- #echo `date` " -- char server crashed - restarting"
- echo `date` " -- char server crashed - restarting" >> /var/log/athena_status.log
- killall -9 char-server
- cd $athena_dir
- nohup ./char-server ./conf/char_athena.conf ./conf/inter_athena.conf &
- #echo `date` " -- restarted"
- echo `date` " -- restarted" >> /var/log/athena_status.log
-
-fi
-
-if [ ` ps fauxw | grep login-server | grep -v grep | wc -l ` -eq 0 ];then
- #echo `date` " -- login server crashed - restarting"
- echo `date` " -- login server crashed - restarting" >> /var/log/athena_status.log
- killall -9 login-server
- cd $athena_dir
- nohup ./login-server ./conf/login_athena.conf &
- #echo `date` " -- restarted"
- echo `date` " -- restarted" >> /var/log/athena_status.log
-
-fi
-
-
-#echo `date` " -- everything is fine"
-echo `date` " -- everything is fine" >> /var/log/athena_status.log
-sleep 30
-done
diff --git a/src/tool/mapfrob.cpp b/src/tool/mapfrob.cpp
deleted file mode 100644
index 8663ae0..0000000
--- a/src/tool/mapfrob.cpp
+++ /dev/null
@@ -1,129 +0,0 @@
-// Compile with
-// gcc -m32 -I src/char -I src/common charfrob.c -o charfrob src/common/timer.o src/common/malloc.o src/common/socket.o src/common/lock.o src/common/db.o src/char/int_pet.o src/char/int_storage.o src/char/inter.o src/char/int_party.o src/char/int_guild.o
-
-#include <stdio.h>
-#include <stdlib.h>
-#include "../common/mmo.hpp"
-// Yes, this is intentional
-#include "../char/char.cpp"
-
-// Well, this is not terribly elegant, but I don't have that much time.
-#define MAX_MAP 1024
-#define MAP_NAME_SIZE 32
-int maps_nr = 0;
-struct
-{
- char old[MAP_NAME_SIZE], new[MAP_NAME_SIZE];
-} maps[MAX_MAP];
-
-void transform_point (struct point *p)
-{
- int k;
-
- if (!p->map[0])
- return;
-
- for (k = 0; k < maps_nr; k++)
- if (!strcmp (p->map, maps[k].old))
- {
- strcpy (p->map, maps[k].new);
- return;
- }
-
- fprintf (stderr, "Warning: untranslated map `%s'\n", p->map);
-}
-
-void transform_char (struct mmo_charstatus *p)
-{
- int i;
-
- transform_point (&p->last_point);
- transform_point (&p->save_point);
-
- for (i = 0; i < 10; i++)
- transform_point (&p->memo_point[i]);
-}
-
-int mmo_char_convert ()
-{
- char line[965536];
- int ret;
- struct mmo_charstatus char_dat;
- FILE *ifp, *ofp;
-
- ifp = stdin;
- ofp = stdout;
- while (fgets (line, 65535, ifp))
- {
- memset (&char_dat, 0, sizeof (struct mmo_charstatus));
- ret = mmo_char_fromstr (line, &char_dat);
- if (ret)
- {
- transform_char (&char_dat);
- mmo_char_tostr (line, &char_dat);
- fprintf (ofp, "%s\n", line);
- }
- }
- return 0;
-}
-
-#define PARSE_MODE_NEXTNUM 0
-#define PARSE_MODE_RANGE 1
-
-int init (int count, char **translates)
-{
- int i;
- char *suffix = ".gat";
-
- for (i = 0; i < count; i++)
- {
- char *src = translates[i];
- char *dest = strchr (src, ':');
-
- if (!dest)
- {
- fprintf (stderr, "Missing colon in: `%s'\n", src);
- return 1;
- }
-
- *dest++ = 0;
-
- if (strlen (src) + strlen (suffix) >= MAP_NAME_SIZE)
- {
- fprintf (stderr, "Map name prefix too long: `%s'\n", src);
- return 1;
- }
-
- if (strlen (dest) + strlen (suffix) >= MAP_NAME_SIZE)
- {
- fprintf (stderr, "Map name prefix too long: `%s'\n", dest);
- return 1;
- }
-
- strncpy (maps[maps_nr].old, src, MAP_NAME_SIZE);
- strcat (maps[maps_nr].old, suffix);
- strncpy (maps[maps_nr].new, dest, MAP_NAME_SIZE);
- strcat (maps[maps_nr].new, suffix);
-
- ++maps_nr;
- }
-
- return 0;
-}
-
-int main (int argc, char *argv[])
-{
- if (argc < 2)
- {
- printf ("Usage: %s oldmap0:newmap0 oldmap1:newmap1 ...\n", argv[0]);
- printf ("e.g., %s new_1-1:001-2 new_2-1:001-1\n", argv[0]);
- puts ("The extension `.gat' is appended implicitly.");
- exit (0);
- }
- if (init (argc - 1, argv + 1))
- return 1;
-
- mmo_char_convert ();
-
- return 0;
-}
diff --git a/src/tool/marriage-info.cpp b/src/tool/marriage-info.cpp
deleted file mode 100644
index 3552a9b..0000000
--- a/src/tool/marriage-info.cpp
+++ /dev/null
@@ -1,482 +0,0 @@
-/* To build:
-gcc -O2 -m32 -Isrc/common -Isrc/char -Isrc/map -Isrc/login -o marriage-info \
-marriage-info.c src/common/socket.o src/common/timer.o src/common/db.o \
-src/common/lock.o src/common/malloc.o src/char/int_guild.o \
-src/char/int_party.o src/char/int_storage.o src/char/inter.o
-*/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include "../login/login.hpp"
-#include "../common/mmo.hpp"
-// Yes, this is intentional
-#include "../char/char.cpp"
-
-int mode;
-#define MODE_MARRIED 0
-#define MODE_SINGLES_F 1
-#define MODE_SINGLES_M 2
-#define MODE_SINGLES_A 3
-
-#define CHUNK_SIZE 1024
-
-/* chunked list to represent leaves */
-typedef struct {
- int char_id;
- int exp;
- char name[24];
- unsigned char level;
- unsigned char sex;
-} char_leaf_t;
-
-/* Chunks are in descending order, but chars are in ascending order */
-typedef struct chunklist_node {
- int size;
- char_leaf_t chars[CHUNK_SIZE];
- struct chunklist_node *next;
-} chunklist_node_t;
-
-chunklist_node_t *list = NULL;
-
-static void
-insert(chunklist_node_t **listp, struct mmo_charstatus *p)
-{
- chunklist_node_t *chunk = *listp;
- char_leaf_t *l;
-
- if ((chunk && chunk->size == CHUNK_SIZE)
- || (!chunk)) {
- chunk = malloc(sizeof(chunklist_node_t));
- chunk->size = 0;
- chunk->next = *listp;
- *listp = chunk;
- }
-
- l = &chunk->chars[chunk->size++];
-
- l->char_id = p->char_id;
- l->level = p->base_level;
- l->exp = p->base_exp;
- l->sex = p->sex;
- strcpy(l->name, p->name);
-}
-
-static int
-compare_leaf(const void *l, const void *r)
-{
- return ((char_leaf_t *)l)->char_id - ((char_leaf_t *)r)->char_id;
-}
-
-static char_leaf_t *
-find(chunklist_node_t *list, int char_id)
-{
- if (!list)
- return NULL; /* fatal error */
- else {
- int start = list->chars[0].char_id;
- int stop = list->chars[list->size - 1].char_id;
-
- if (char_id >= start && char_id <= stop) { /* in this chunk */
- char_leaf_t key;
- key.char_id = char_id;
- return (char_leaf_t *)
- bsearch(&key, &list->chars, list->size, sizeof(char_leaf_t),
- compare_leaf);
- }
- else find(list->next, char_id);
- }
-}
-
-
-void /* replace blanks with percent signs */
-namefrob(char *n)
-{
- while (*n++) /* can't start with a blank */
- if (*n == ' ')
- *n = '%';
-}
-
-/*
---------------------------------------------------------------------------------
- Copied and pasted due to lacking modularity
-*/
-
-char account_filename[1024] = "save/account.txt";
-int account_id_count = START_ACCOUNT_NUM;
-
-struct auth_dat {
- int account_id, sex;
- char userid[24], pass[24], lastlogin[24];
- int logincount;
- int state;
- char email[40];
- char error_message[20];
- time_t ban_until_time;
- time_t connect_until_time;
- char last_ip[16];
- char memo[255];
- int account_reg2_num;
- struct global_reg account_reg2[ACCOUNT_REG2_NUM];
-} *auth_dat;
-
-int auth_num = 0, auth_max = 0;
-
-
-/*
- Reading of the accounts database
-*/
-int mmo_auth_init(void) {
- FILE *fp;
- int account_id, logincount, state, n, i, j, v;
- char line[2048], *p, 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 str[2048];
- int GM_count = 0;
- int server_count = 0;
-
- auth_dat = calloc(sizeof(struct auth_dat) * 256, 1);
- auth_max = 256;
-
- fp = fopen(account_filename, "r");
- if (fp == NULL) {
- printf("\033[1;31mmmo_auth_init: Accounts file [%s] not found.\033[0m\n", account_filename);
- return 0;
- }
-
- while(fgets(line, sizeof(line)-1, fp) != NULL) {
- if (line[0] == '/' && line[1] == '/')
- continue;
- line[sizeof(line)-1] = '\0';
- p = line;
-
- if (((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)) == 13 && line[n] == '\t') ||
- ((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]%n",
- &account_id, userid, pass, lastlogin, &sex, &logincount, &state,
- email, error_message, &connect_until_time, last_ip, memo, &n)) == 12 && line[n] == '\t')) {
- n = n + 1;
-
- if (account_id > END_ACCOUNT_NUM) {
- continue;
- }
- userid[23] = '\0';
- remove_control_chars(userid);
- for(j = 0; j < auth_num; j++) {
- if (auth_dat[j].account_id == account_id) {
- break;
- } else if (strcmp(auth_dat[j].userid, userid) == 0) {
- break;
- }
- }
- if (j != auth_num)
- continue;
-
- if (auth_num >= auth_max) {
- auth_max += 256;
- auth_dat = realloc(auth_dat, sizeof(struct auth_dat) * auth_max);
- }
-
- memset(&auth_dat[auth_num], '\0', sizeof(struct auth_dat));
-
- auth_dat[auth_num].account_id = account_id;
-
- strncpy(auth_dat[auth_num].userid, userid, 24);
-
- pass[23] = '\0';
- remove_control_chars(pass);
- strncpy(auth_dat[auth_num].pass, pass, 24);
-
- lastlogin[23] = '\0';
- remove_control_chars(lastlogin);
- strncpy(auth_dat[auth_num].lastlogin, lastlogin, 24);
-
- auth_dat[auth_num].sex = (sex == 'S' || sex == 's') ? 2 : (sex == 'M' || sex == 'm');
-
- if (logincount >= 0)
- auth_dat[auth_num].logincount = logincount;
- else
- auth_dat[auth_num].logincount = 0;
-
- if (state > 255)
- auth_dat[auth_num].state = 100;
- else if (state < 0)
- auth_dat[auth_num].state = 0;
- else
- auth_dat[auth_num].state = state;
-
- if (e_mail_check(email) == 0) {
- strncpy(auth_dat[auth_num].email, "a@a.com", 40);
- } else {
- remove_control_chars(email);
- strncpy(auth_dat[auth_num].email, email, 40);
- }
-
- error_message[19] = '\0';
- remove_control_chars(error_message);
- if (error_message[0] == '\0' || state != 7) {
- strncpy(auth_dat[auth_num].error_message, "-", 20);
- } else {
- strncpy(auth_dat[auth_num].error_message, error_message, 20);
- }
-
- if (i == 13)
- auth_dat[auth_num].ban_until_time = ban_until_time;
- else
- auth_dat[auth_num].ban_until_time = 0;
-
- auth_dat[auth_num].connect_until_time = connect_until_time;
-
- last_ip[15] = '\0';
- remove_control_chars(last_ip);
- strncpy(auth_dat[auth_num].last_ip, last_ip, 16);
-
- memo[254] = '\0';
- remove_control_chars(memo);
- strncpy(auth_dat[auth_num].memo, memo, 255);
-
- for(j = 0; j < ACCOUNT_REG2_NUM; j++) {
- p += n;
- if (sscanf(p, "%[^\t,],%d %n", str, &v, &n) != 2) {
- if (p[0] == ',' && sscanf(p, ",%d %n", &v, &n) == 1) {
- j--;
- continue;
- } else
- break;
- }
- str[31] = '\0';
- remove_control_chars(str);
- strncpy(auth_dat[auth_num].account_reg2[j].str, str, 32);
- auth_dat[auth_num].account_reg2[j].value = v;
- }
- auth_dat[auth_num].account_reg2_num = j;
-
- if (isGM(account_id) > 0)
- GM_count++;
- if (auth_dat[auth_num].sex == 2)
- server_count++;
-
- auth_num++;
- if (account_id >= account_id_count)
- account_id_count = account_id + 1;
-
- } else if ((i = sscanf(line, "%d\t%[^\t]\t%[^\t]\t%[^\t]\t%c\t%d\t%d\t%n",
- &account_id, userid, pass, lastlogin, &sex, &logincount, &state, &n)) >= 5) {
- if (account_id > END_ACCOUNT_NUM) {
- continue;
- }
- userid[23] = '\0';
- remove_control_chars(userid);
- for(j = 0; j < auth_num; j++) {
- if (auth_dat[j].account_id == account_id) {
- break;
- } else if (strcmp(auth_dat[j].userid, userid) == 0) {
- break;
- }
- }
- if (j != auth_num)
- continue;
-
- if (auth_num >= auth_max) {
- auth_max += 256;
- auth_dat = realloc(auth_dat, sizeof(struct auth_dat) * auth_max);
- }
-
- memset(&auth_dat[auth_num], '\0', sizeof(struct auth_dat));
-
- auth_dat[auth_num].account_id = account_id;
-
- strncpy(auth_dat[auth_num].userid, userid, 24);
-
- pass[23] = '\0';
- remove_control_chars(pass);
- strncpy(auth_dat[auth_num].pass, pass, 24);
-
- lastlogin[23] = '\0';
- remove_control_chars(lastlogin);
- strncpy(auth_dat[auth_num].lastlogin, lastlogin, 24);
-
- auth_dat[auth_num].sex = (sex == 'S' || sex == 's') ? 2 : (sex == 'M' || sex == 'm');
-
- if (i >= 6) {
- if (logincount >= 0)
- auth_dat[auth_num].logincount = logincount;
- else
- auth_dat[auth_num].logincount = 0;
- } else
- auth_dat[auth_num].logincount = 0;
-
- if (i >= 7) {
- if (state > 255)
- auth_dat[auth_num].state = 100;
- else if (state < 0)
- auth_dat[auth_num].state = 0;
- else
- auth_dat[auth_num].state = state;
- } else
- auth_dat[auth_num].state = 0;
-
- strncpy(auth_dat[auth_num].email, "a@a.com", 40);
- strncpy(auth_dat[auth_num].error_message, "-", 20);
- auth_dat[auth_num].ban_until_time = 0;
- auth_dat[auth_num].connect_until_time = 0;
- strncpy(auth_dat[auth_num].last_ip, "-", 16);
- strncpy(auth_dat[auth_num].memo, "-", 255);
-
- for(j = 0; j < ACCOUNT_REG2_NUM; j++) {
- p += n;
- if (sscanf(p, "%[^\t,],%d %n", str, &v, &n) != 2) {
- if (p[0] == ',' && sscanf(p, ",%d %n", &v, &n) == 1) {
- j--;
- continue;
- } else
- break;
- }
- str[31] = '\0';
- remove_control_chars(str);
- strncpy(auth_dat[auth_num].account_reg2[j].str, str, 32);
- auth_dat[auth_num].account_reg2[j].value = v;
- }
- auth_dat[auth_num].account_reg2_num = j;
-
- if (isGM(account_id) > 0)
- GM_count++;
- if (auth_dat[auth_num].sex == 2)
- server_count++;
-
- auth_num++;
- if (account_id >= account_id_count)
- account_id_count = account_id + 1;
-
- } else {
- i = 0;
- if (sscanf(line, "%d\t%%newid%%\n%n", &account_id, &i) == 1 &&
- i > 0 && account_id > account_id_count)
- account_id_count = account_id;
- }
- }
- fclose(fp);
-
- if (auth_num == 0) {
- sprintf(line, "No account found in %s.", account_filename);
- } else {
- if (auth_num == 1) {
- sprintf(line, "1 account read in %s,", account_filename);
- } else {
- sprintf(line, "%d accounts read in %s,", auth_num, account_filename);
- }
- if (GM_count == 0) {
- sprintf(str, "%s of which is no GM account and", line);
- } else if (GM_count == 1) {
- sprintf(str, "%s of which is 1 GM account and", line);
- } else {
- sprintf(str, "%s of which is %d GM accounts and", line, GM_count);
- }
- if (server_count == 0) {
- sprintf(line, "%s no server account ('S').", str);
- } else if (server_count == 1) {
- sprintf(line, "%s 1 server account ('S').", str);
- } else {
- sprintf(line, "%s %d server accounts ('S').", str, server_count);
- }
- }
-
- return 0;
-}
-
-/*--------------------------------------------------------------------------------*/
-
-
-void
-mmo_check_dumpworthy(struct mmo_charstatus *p)
-{
- int i;
- namefrob(p->name);
-
- for (i = 0; i < auth_num; i++)
- if (auth_dat[i].account_id == p->account_id) {
- p->sex = auth_dat[i].sex;
- break;
- }
-
- if (p->partner_id) {
- if (mode != MODE_MARRIED)
- return;
-
- if (p->partner_id < p->char_id) {
- char_leaf_t *partner = find(list, p->partner_id);
- if (!partner)
- fprintf(stderr, "Char %d (%s)'s partner (%d) no longer available\n",
- p->char_id,
- p->name,
- p->partner_id);
- else
- printf ("%d\t%d\t%s\t%s\t%d\t%s\t%s\t%d--%d,%d\n",
- p->base_level + partner->level,
- p->base_exp + partner->exp,
- p->name, p->sex? "M" : "F", p->base_level,
- partner->name, partner->sex? "M" : "F", partner->level);
- } else {
- insert(&list, p);
- }
- } else if (p->sex == (mode - 1))
- printf("%d\t%d\t%s\n", p->base_level, p->base_exp, p->name);
- else if (mode == MODE_SINGLES_A)
- printf("%d\t%d\t%s\t%s\n", p->base_level, p->base_exp, p->name, p->sex? "M" : "F");
-}
-
-int mmo_char_dump()
-{
- char line[965536];
- int ret;
- struct mmo_charstatus char_dat;
- FILE *ifp,*ofp;
-
- ifp=stdin;
- while(fgets(line,65535,ifp)){
- memset(&char_dat,0,sizeof(struct mmo_charstatus));
- ret=mmo_char_fromstr(line,&char_dat);
- if(ret){
- mmo_check_dumpworthy(&char_dat);
- }
- }
- return 0;
-}
-
-
-int init(char *mode_s)
-{
- if (!strcmp(mode_s, "-c"))
- mode = MODE_MARRIED;
- else if (!strcmp(mode_s, "-f"))
- mode = MODE_SINGLES_F;
- else if (!strcmp(mode_s, "-m"))
- mode = MODE_SINGLES_M;
- else if (!strcmp(mode_s, "-s"))
- mode = MODE_SINGLES_A;
- else {
- fprintf(stderr, "Unknown mode `%s'\n", mode_s);
- return 1;
- }
- return 0;
-}
-
-int main(int argc,char *argv[])
-{
- mmo_auth_init();
-
- if(argc < 2) {
- printf("Usage: %s <mode>\n", argv[0]);
- printf("Where <mode> is one of -c (couples), -s (singles), -f (female singles), -m (male singles)\n", argv[0]);
- exit(0);
- }
- if (init(argv[1]))
- return 1;
-
- mmo_char_dump();
-
- return 0;
-}
diff --git a/src/tool/marriage-info.sh b/src/tool/marriage-info.sh
deleted file mode 100755
index 2389d7f..0000000
--- a/src/tool/marriage-info.sh
+++ /dev/null
@@ -1,20 +0,0 @@
-#! /bin/sh
-
-cd ~/tmwserver
-
-cat save/athena.txt | sort -n > athena-sorted.txt
-
-printf "Top married couples\n===================\n" > ~/public_html/stats/married.txt
-cat athena-sorted.txt | ./marriage-info -c | sort -rn | awk '{printf "%d %s oo %s (%s (%s, %d), %s(%s, %d))\n", ++rank, $3, $6, $3, $4, $5, $6, $7, $8}' | tr '%' ' ' >> ~/public_html/stats/married.txt
-
-printf "Top female singles\n==================\n" > ~/public_html/stats/female-singles.txt
-cat athena-sorted.txt | ./marriage-info -f | sort -rn | awk '{printf "%d %s(%d)\n", ++rank, $3, $1}' | tr '%' ' ' | head -50 >> ~/public_html/stats/female-singles.txt
-
-printf "Top male singles\n===============\n" > ~/public_html/stats/male-singles.txt
-cat athena-sorted.txt | ./marriage-info -m | sort -rn | awk '{printf "%d %s(%d)\n", ++rank, $3, $1}' | tr '%' ' ' | head -50 >> ~/public_html/stats/male-singles.txt
-
-printf "Top singles\n===============\n" > ~/public_html/stats/singles.txt
-cat athena-sorted.txt | ./marriage-info -s | sort -rn | awk '{printf "%d %s(%s, %d)\n", ++rank, $3, $4, $1}' | tr '%' ' ' | head -50 >> ~/public_html/stats/singles.txt
-
-rm athena-sorted.txt
-
diff --git a/src/tool/moneycount/athena_text.cpp b/src/tool/moneycount/athena_text.cpp
deleted file mode 100644
index 8cf5457..0000000
--- a/src/tool/moneycount/athena_text.cpp
+++ /dev/null
@@ -1,263 +0,0 @@
-#include "athena_text.hpp"
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-
-#include "mmo.hpp"
-
-//-------------------------------------------------------------------------
-// Function to set the character from the line (at read of characters file)
-//-------------------------------------------------------------------------
-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->classb = 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];
-
- if (str[next] == '\n' || str[next] == '\r')
- return 1; // ?V?K?f?[?^
-
- next++;
-
- for (i = 0; str[next] && str[next] != '\t'; i++)
- {
- if (sscanf
- (str + next, "%[^,],%d,%d%n", p->memo_point[i].map, &tmp_int[0],
- &tmp_int[1], &len) != 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++)
- {
- if (sscanf (str + next, "%d,%d%n", &tmp_int[0], &tmp_int[1], &len) !=
- 2)
- return -6;
- p->skill[tmp_int[0]].id = tmp_int[0];
- p->skill[tmp_int[0]].lv = tmp_int[1] & 0xffff;
- p->skill[tmp_int[0]].flags = ((tmp_int[1] >> 16) & 0xffff);
- next += len;
- if (str[next] == ' ')
- next++;
- }
-
- next++;
-
- for (i = 0;
- str[next] && str[next] != '\t' && str[next] != '\n'
- && str[next] != '\r'; i++)
- { // global_reg?????O??athena.txt????^????'\n'?`?F?b?N
- if (sscanf
- (str + next, "%[^,],%d%n", p->global_reg[i].str,
- &p->global_reg[i].value, &len) != 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 accreg_fromstr (char *str, struct accreg *reg)
-{
- int j, v, n;
- char buf[128];
- const char *p = str;
-
- if (sscanf (p, "%d\t%n", &reg->account_id, &n) != 1
- || reg->account_id <= 0)
- return 0;
-
- for (j = 0, p += n; j < ACCOUNT_REG_NUM; j++, p += n)
- {
- if (sscanf (p, "%[^,],%d %n", buf, &v, &n) != 2)
- break;
- memcpy (reg->reg[j].str, buf, 32);
- reg->reg[j].value = v;
- }
- reg->reg_num = j;
-
- return 1;
-}
-
diff --git a/src/tool/moneycount/athena_text.hpp b/src/tool/moneycount/athena_text.hpp
deleted file mode 100644
index e4b7025..0000000
--- a/src/tool/moneycount/athena_text.hpp
+++ /dev/null
@@ -1,9 +0,0 @@
-#ifndef ATHENA_TEXT_HPP
-#define ATHENA_TEXT_HPP
-#include "mmo.hpp"
-
-int mmo_char_fromstr (char *str, struct mmo_charstatus *p);
-
-int accreg_fromstr (char *str, struct accreg *reg);
-
-#endif
diff --git a/src/tool/moneycount/inf.cpp b/src/tool/moneycount/inf.cpp
deleted file mode 100644
index 80b0475..0000000
--- a/src/tool/moneycount/inf.cpp
+++ /dev/null
@@ -1,1482 +0,0 @@
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-// The integer is represented as a sequence of bytes. They are stored such that
-// element 0 is the lsB, which makes sense when seen as an integer offset but
-// is counter-intuitive when you think that a string is usually read from left
-// to right, 0 to size-1, in which case the lsB is on the *left*.
-
-// This solution is compatible with 32-bit and 64-bit machines with either
-// little-endian or big-endian representations of integers.
-
-// Problem: I'm using std::string, which is an array of char. However, char is
-// not well-defined - it could be signed or unsigned.
-
-// In fact, there's no requirement for a char to even be one byte - it can be
-// any size of one byte or more. However, it's just impossible to make any
-// progress with that naffness (thanks to the C non-standardisation committee)
-// and the practice is that char on every platform/compiler I've ever come
-// across is that char = byte.
-
-// The algorithms here use unsigned char to represent bit-patterns so I have to
-// be careful to type-cast from char to unsigned char a lot. I use a typedef to
-// make life easier.
-
-////////////////////////////////////////////////////////////////////////////////
-#include "inf.hpp"
-#include <ctype.h>
-////////////////////////////////////////////////////////////////////////////////
-
-namespace stlplus
-{
-
- ////////////////////////////////////////////////////////////////////////////////
- // choose a sensible C type for a byte
-
- typedef unsigned char byte;
-
- ////////////////////////////////////////////////////////////////////////////////
- // local functions
-
- // removes leading bytes that don't contribute to the value to create the minimum string representation
- static void reduce_string(std::string& data)
- {
- while(data.size() > 1 &&
- ((byte(data[data.size()-1]) == byte(0) && byte(data[data.size()-2]) < byte(128)) ||
- (byte(data[data.size()-1]) == byte(255) && byte(data[data.size()-2]) >= byte(128))))
- {
- data.erase(data.end()-1);
- }
- }
-
- // generic implementations of type conversions from integer type to internal representation
- // data: integer value for conversion
- // result: internal representation
-
- template <typename T>
- static void convert_from_signed(const T& data, std::string& result)
- {
- result.erase();
- bool lsb_first = little_endian();
- byte* address = (byte*)&data;
- for (size_t i = 0; i < sizeof(T); i++)
- {
- size_t offset = (lsb_first ? i : (sizeof(T) - i - 1));
- result.append(1,address[offset]);
- }
- reduce_string(result);
- }
-
- template <typename T>
- static void convert_from_unsigned(const T& data, std::string& result)
- {
- result.erase();
- bool lsb_first = little_endian();
- byte* address = (byte*)&data;
- for (size_t i = 0; i < sizeof(T); i++)
- {
- size_t offset = (lsb_first ? i : (sizeof(T) - i - 1));
- result.append(1,address[offset]);
- }
- // inf is signed - so there is a possible extra sign bit to add
- result.append(1,std::string::value_type(0));
- reduce_string(result);
- }
-
- // generic implementations of type conversions from internal representation to an integer type
- // data : string representation of integer
- // result: integer result of conversion
- // return: flag indicating success - false = overflow
-
- template <class T>
- bool convert_to_signed(const std::string& data, T& result)
- {
- bool lsb_first = little_endian();
- byte* address = (byte*)&result;
- for (size_t i = 0; i < sizeof(T); i++)
- {
- size_t offset = lsb_first ? i : (sizeof(T) - i - 1);
- if (i < data.size())
- address[offset] = byte(data[i]);
- else if (data.empty() || (byte(data[data.size()-1]) < byte(128)))
- address[offset] = byte(0);
- else
- address[offset] = byte(255);
- }
- return data.size() <= sizeof(T);
- }
-
- template <class T>
- bool convert_to_unsigned(const std::string& data, T& result)
- {
- bool lsb_first = little_endian();
- byte* address = (byte*)&result;
- for (size_t i = 0; i < sizeof(T); i++)
- {
- size_t offset = lsb_first ? i : (sizeof(T) - i - 1);
- if (i < data.size())
- address[offset] = byte(data[i]);
- else
- address[offset] = byte(0);
- }
- return data.size() <= sizeof(T);
- }
-
- ////////////////////////////////////////////////////////////////////////////////
- // Conversions to string
-
- static char to_char [] = "0123456789abcdefghijklmnopqrstuvwxyz";
- static int from_char [] =
- {
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1,
- -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
- 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, -1,
- -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
- 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
- };
-
- static void convert_to_string(const stlplus::inf& data, std::string& result, unsigned radix = 10)
- throw(std::invalid_argument)
- {
- // only support the C-style radixes plus 0b for binary
- if (radix != 2 && radix != 8 && radix != 10 && radix != 16)
- throw std::invalid_argument("invalid radix value");
- inf local_i = data;
- // untangle all the options
- bool binary = radix == 2;
- bool octal = radix == 8;
- bool hex = radix == 16;
- // the C representations for binary, octal and hex use 2's-complement representation
- // all other represenations use sign-magnitude
- if (hex || octal || binary)
- {
- // bit-pattern representation
- // this is the binary representation optionally shown in octal or hex
- // first generate the binary by masking the bits
- for (unsigned j = local_i.bits(); j--; )
- result += (local_i.bit(j) ? '1' : '0');
- // the result is now the full width of the type - e.g. int will give a 32-bit result
- // now interpret this as either binary, octal or hex and add the prefix
- if (binary)
- {
- // trim down to the smallest string that preserves the value
- while (true)
- {
- // do not trim to less than 1 bit (sign only)
- if (result.size() <= 1) break;
- // only trim if it doesn't change the sign and therefore the value
- if (result[0] != result[1]) break;
- result.erase(0,1);
- }
- // add the prefix
- result.insert((std::string::size_type)0, "0b");
- }
- else if (octal)
- {
- // the result is currently binary
- // trim down to the smallest string that preserves the value
- while (true)
- {
- // do not trim to less than 2 bits (sign plus 1-bit magnitude)
- if (result.size() <= 2) break;
- // only trim if it doesn't change the sign and therefore the value
- if (result[0] != result[1]) break;
- result.erase(0,1);
- }
- // also ensure that the binary is a multiple of 3 bits to make the conversion to octal easier
- while (result.size() % 3 != 0)
- result.insert((std::string::size_type)0, 1, result[0]);
- // now convert to octal
- std::string octal_result;
- for (unsigned i = 0; i < result.size()/3; i++)
- {
- // yuck - ugly or what?
- if (result[i*3] == '0')
- {
- if (result[i*3+1] == '0')
- {
- if (result[i*3+2] == '0')
- octal_result += '0';
- else
- octal_result += '1';
- }
- else
- {
- if (result[i*3+2] == '0')
- octal_result += '2';
- else
- octal_result += '3';
- }
- }
- else
- {
- if (result[i*3+1] == '0')
- {
- if (result[i*3+2] == '0')
- octal_result += '4';
- else
- octal_result += '5';
- }
- else
- {
- if (result[i*3+2] == '0')
- octal_result += '6';
- else
- octal_result += '7';
- }
- }
- }
- result = octal_result;
- // add the prefix
- result.insert((std::string::size_type)0, "0");
- }
- else
- {
- // similar to octal
- while (true)
- {
- // do not trim to less than 2 bits (sign plus 1-bit magnitude)
- if (result.size() <= 2) break;
- // only trim if it doesn't change the sign and therefore the value
- if (result[0] != result[1]) break;
- result.erase(0,1);
- }
- // pad to a multiple of 4 characters
- while (result.size() % 4 != 0)
- result.insert((std::string::size_type)0, 1, result[0]);
- // now convert to hex
- std::string hex_result;
- for (unsigned i = 0; i < result.size()/4; i++)
- {
- // yuck - ugly or what?
- if (result[i*4] == '0')
- {
- if (result[i*4+1] == '0')
- {
- if (result[i*4+2] == '0')
- {
- if (result[i*4+3] == '0')
- hex_result += '0';
- else
- hex_result += '1';
- }
- else
- {
- if (result[i*4+3] == '0')
- hex_result += '2';
- else
- hex_result += '3';
- }
- }
- else
- {
- if (result[i*4+2] == '0')
- {
- if (result[i*4+3] == '0')
- hex_result += '4';
- else
- hex_result += '5';
- }
- else
- {
- if (result[i*4+3] == '0')
- hex_result += '6';
- else
- hex_result += '7';
- }
- }
- }
- else
- {
- if (result[i*4+1] == '0')
- {
- if (result[i*4+2] == '0')
- {
- if (result[i*4+3] == '0')
- hex_result += '8';
- else
- hex_result += '9';
- }
- else
- {
- if (result[i*4+3] == '0')
- hex_result += 'a';
- else
- hex_result += 'b';
- }
- }
- else
- {
- if (result[i*4+2] == '0')
- {
- if (result[i*4+3] == '0')
- hex_result += 'c';
- else
- hex_result += 'd';
- }
- else
- {
- if (result[i*4+3] == '0')
- hex_result += 'e';
- else
- hex_result += 'f';
- }
- }
- }
- }
- result = hex_result;
- // add the prefix
- result.insert((std::string::size_type)0, "0x");
- }
- }
- else
- {
- // convert to sign-magnitude
- // the representation is:
- // [sign]magnitude
- bool negative = local_i.negative();
- local_i.abs();
- // create a representation of the magnitude by successive division
- inf inf_radix(radix);
- do
- {
- std::pair<inf,inf> divided = local_i.divide(inf_radix);
- unsigned remainder = divided.second.to_unsigned();
- char digit = to_char[remainder];
- result.insert((std::string::size_type)0, 1, digit);
- local_i = divided.first;
- }
- while(!local_i.zero());
- // add the prefixes
- // add a sign only for negative values
- if (negative)
- result.insert((std::string::size_type)0, 1, '-');
- }
- }
-
- ////////////////////////////////////////////////////////////////////////////////
- // Conversions FROM string
-
- void convert_from_string(const std::string& str, inf& result, unsigned radix = 10) throw(std::invalid_argument)
- {
- result = 0;
- // only support the C-style radixes plus 0b for binary
- // a radix of 0 means deduce the radix from the input - assume 10
- if (radix != 0 && radix != 2 && radix != 8 && radix != 10 && radix != 16)
- throw std::invalid_argument("invalid radix value");
- unsigned i = 0;
- // the radix passed as a parameter is just the default - it can be
- // overridden by the C prefix
- // Note: a leading zero is the C-style prefix for octal - I only make this
- // override the default when the default radix is not specified
- // first check for a C-style prefix
- bool c_style = false;
- if (i < str.size() && str[i] == '0')
- {
- // binary or hex
- if (i+1 < str.size() && tolower(str[i+1]) == 'x')
- {
- c_style = true;
- radix = 16;
- i += 2;
- }
- else if (i+1 < str.size() && tolower(str[i+1]) == 'b')
- {
- c_style = true;
- radix = 2;
- i += 2;
- }
- else if (radix == 0)
- {
- c_style = true;
- radix = 8;
- i += 1;
- }
- }
- if (radix == 0)
- radix = 10;
- if (c_style)
- {
- // the C style formats are bit patterns not integer values - these need
- // to be sign-extended to get the right value
- std::string binary;
- if (radix == 2)
- {
- for (unsigned j = i; j < str.size(); j++)
- {
- switch(str[j])
- {
- case '0':
- binary += '0';
- break;
- case '1':
- binary += '1';
- break;
- default:
- throw std::invalid_argument("invalid binary character in string " + str);
- }
- }
- }
- else if (radix == 8)
- {
- for (unsigned j = i; j < str.size(); j++)
- {
- switch(str[j])
- {
- case '0':
- binary += "000";
- break;
- case '1':
- binary += "001";
- break;
- case '2':
- binary += "010";
- break;
- case '3':
- binary += "011";
- break;
- case '4':
- binary += "100";
- break;
- case '5':
- binary += "101";
- break;
- case '6':
- binary += "110";
- break;
- case '7':
- binary += "111";
- break;
- default:
- throw std::invalid_argument("invalid octal character in string " + str);
- }
- }
- }
- else
- {
- for (unsigned j = i; j < str.size(); j++)
- {
- switch(tolower(str[j]))
- {
- case '0':
- binary += "0000";
- break;
- case '1':
- binary += "0001";
- break;
- case '2':
- binary += "0010";
- break;
- case '3':
- binary += "0011";
- break;
- case '4':
- binary += "0100";
- break;
- case '5':
- binary += "0101";
- break;
- case '6':
- binary += "0110";
- break;
- case '7':
- binary += "0111";
- break;
- case '8':
- binary += "1000";
- break;
- case '9':
- binary += "1001";
- break;
- case 'a':
- binary += "1010";
- break;
- case 'b':
- binary += "1011";
- break;
- case 'c':
- binary += "1100";
- break;
- case 'd':
- binary += "1101";
- break;
- case 'e':
- binary += "1110";
- break;
- case 'f':
- binary += "1111";
- break;
- default:
- throw std::invalid_argument("invalid hex character in string " + str);
- }
- }
- }
- // now convert the value
- result.resize(binary.size());
- for (unsigned j = 0; j < binary.size(); j++)
- result.preset(binary.size() - j - 1, binary[j] == '1');
- }
- else
- {
- // sign-magnitude representation
- // now scan for a sign and find whether this is a negative number
- bool negative = false;
- if (i < str.size())
- {
- switch (str[i])
- {
- case '-':
- negative = true;
- i++;
- break;
- case '+':
- i++;
- break;
- }
- }
- for (; i < str.size(); i++)
- {
- result *= inf(radix);
- unsigned char ascii = (unsigned char)str[i];
- int ch = from_char[ascii] ;
- if (ch == -1)
- throw std::invalid_argument("invalid decimal character in string " + str);
- result += inf(ch);
- }
- if (negative)
- result.negate();
- }
- }
-
- ////////////////////////////////////////////////////////////////////////////////
- // constructors - mostly implemented in terms of the assignment operators
-
- inf::inf(void)
- {
- // void constructor initialises to zero - represented as a single-byte value containing zero
- m_data.append(1,std::string::value_type(0));
- }
-
- inf::inf(short r)
- {
- operator=(r);
- }
-
- inf::inf(unsigned short r)
- {
- operator=(r);
- }
-
- inf::inf(int r)
- {
- operator=(r);
- }
-
- inf::inf(unsigned r)
- {
- operator=(r);
- }
-
- inf::inf(long r)
- {
- operator=(r);
- }
-
- inf::inf(unsigned long r)
- {
- operator=(r);
- }
-
- inf::inf (const std::string& r) throw(std::invalid_argument)
- {
- operator=(r);
- }
-
- inf::inf(const inf& r)
- {
-#ifdef __BORLANDC__
- // work round bug in Borland compiler - copy constructor fails if string
- // contains null characters, so do my own copy
- for (unsigned i = 0; i < r.m_data.size(); i++)
- m_data += r.m_data[i];
-#else
- m_data = r.m_data;
-#endif
- }
-
- ////////////////////////////////////////////////////////////////////////////////
-
- inf::~inf(void)
- {
- }
-
- ////////////////////////////////////////////////////////////////////////////////
- // assignments convert from iteger types to internal representation
-
- inf& inf::operator = (short r)
- {
- convert_from_signed(r, m_data);
- return *this;
- }
-
- inf& inf::operator = (unsigned short r)
- {
- convert_from_unsigned(r, m_data);
- return *this;
- }
-
- inf& inf::operator = (int r)
- {
- convert_from_signed(r, m_data);
- return *this;
- }
-
- inf& inf::operator = (unsigned r)
- {
- convert_from_unsigned(r, m_data);
- return *this;
- }
-
- inf& inf::operator = (long r)
- {
- convert_from_signed(r, m_data);
- return *this;
- }
-
- inf& inf::operator = (unsigned long r)
- {
- convert_from_unsigned(r, m_data);
- return *this;
- }
-
- inf& inf::operator = (const std::string& r) throw(std::invalid_argument)
- {
- convert_from_string(r, *this);
- return *this;
- }
-
- inf& inf::operator = (const inf& r)
- {
- m_data = r.m_data;
- return *this;
- }
-
- ////////////////////////////////////////////////////////////////////////////////
-
- short inf::to_short(bool truncate) const throw(std::overflow_error)
- {
- short result = 0;
- if (!convert_to_signed(m_data, result))
- if (!truncate)
- throw std::overflow_error("stlplus::inf::to_short");
- return result;
- }
-
- unsigned short inf::to_unsigned_short(bool truncate) const throw(std::overflow_error)
- {
- unsigned short result = 0;
- if (!convert_to_unsigned(m_data, result))
- if (!truncate)
- throw std::overflow_error("stlplus::inf::to_unsigned_short");
- return result;
- }
-
- int inf::to_int(bool truncate) const throw(std::overflow_error)
- {
- int result = 0;
- if (!convert_to_signed(m_data, result))
- if (!truncate)
- throw std::overflow_error("stlplus::inf::to_int");
- return result;
- }
-
- unsigned inf::to_unsigned(bool truncate) const throw(std::overflow_error)
- {
- unsigned result = 0;
- if (!convert_to_unsigned(m_data, result))
- if (!truncate)
- throw std::overflow_error("stlplus::inf::to_unsigned");
- return result;
- }
-
- long inf::to_long(bool truncate) const throw(std::overflow_error)
- {
- long result = 0;
- if (!convert_to_signed(m_data, result))
- if (!truncate)
- throw std::overflow_error("stlplus::inf::to_long");
- return result;
- }
-
- unsigned long inf::to_unsigned_long(bool truncate) const throw(std::overflow_error)
- {
- unsigned long result = 0;
- if (!convert_to_unsigned(m_data, result))
- if (!truncate)
- throw std::overflow_error("stlplus::inf::to_unsigned_long");
- return result;
- }
-
- ////////////////////////////////////////////////////////////////////////////////
- // resize the inf regardless of the data
-
- void inf::resize(unsigned bits)
- {
- if (bits == 0) bits = 1;
- unsigned bytes = (bits+7)/8;
- byte extend = negative() ? byte(255) : byte (0);
- while(bytes > m_data.size())
- m_data.append(1,extend);
- }
-
- // reduce the bit count to the minimum needed to preserve the value
-
- void inf::reduce(void)
- {
- reduce_string(m_data);
- }
-
- ////////////////////////////////////////////////////////////////////////////////
- // the number of significant bits in the number
-
- unsigned inf::bits (void) const
- {
- // The number of significant bits in the integer value - this is the number
- // of indexable bits less any redundant sign bits at the msb
- // This does not assume that the inf has been reduced to its minimum form
- unsigned result = indexable_bits();
- bool sign = bit(result-1);
- while (result > 1 && (sign == bit(result-2)))
- result--;
- return result;
- }
-
- unsigned inf::size(void) const
- {
- return bits();
- }
-
- unsigned inf::indexable_bits (void) const
- {
- return 8 * unsigned(m_data.size());
- }
-
- ////////////////////////////////////////////////////////////////////////////////
- // bitwise operations
-
- bool inf::bit (unsigned index) const throw(std::out_of_range)
- {
- if (index >= indexable_bits())
- throw std::out_of_range(std::string("stlplus::inf::bit"));
- // first split the offset into byte offset and bit offset
- unsigned byte_offset = index/8;
- unsigned bit_offset = index%8;
- return (byte(m_data[byte_offset]) & (byte(1) << bit_offset)) != 0;
- }
-
- bool inf::operator [] (unsigned index) const throw(std::out_of_range)
- {
- return bit(index);
- }
-
- void inf::set (unsigned index) throw(std::out_of_range)
- {
- if (index >= indexable_bits())
- throw std::out_of_range(std::string("stlplus::inf::set"));
- // first split the offset into byte offset and bit offset
- unsigned byte_offset = index/8;
- unsigned bit_offset = index%8;
- m_data[byte_offset] |= (byte(1) << bit_offset);
- }
-
- void inf::clear (unsigned index) throw(std::out_of_range)
- {
- if (index >= indexable_bits())
- throw std::out_of_range(std::string("stlplus::inf::clear"));
- // first split the offset into byte offset and bit offset
- unsigned byte_offset = index/8;
- unsigned bit_offset = index%8;
- m_data[byte_offset] &= (~(byte(1) << bit_offset));
- }
-
- void inf::preset (unsigned index, bool value) throw(std::out_of_range)
- {
- if (value)
- set(index);
- else
- clear(index);
- }
-
- inf inf::slice(unsigned low, unsigned high) const throw(std::out_of_range)
- {
- if (low >= indexable_bits())
- throw std::out_of_range(std::string("stlplus::inf::slice: low index"));
- if (high >= indexable_bits())
- throw std::out_of_range(std::string("stlplus::inf::slice: high index"));
- inf result;
- if (high >= low)
- {
- // create a result the right size and filled with sign bits
- std::string::size_type result_size = (high-low+1+7)/8;
- result.m_data.erase();
- byte extend = bit(high) ? byte(255) : byte (0);
- while (result.m_data.size() < result_size)
- result.m_data.append(1,extend);
- // now set the relevant bits
- for (unsigned i = low; i <= high; i++)
- result.preset(i-low, bit(i));
- }
- return result;
- }
-
- ////////////////////////////////////////////////////////////////////////////////
- // testing operations
-
- bool inf::negative (void) const
- {
- return bit(indexable_bits()-1);
- }
-
- bool inf::natural (void) const
- {
- return !negative();
- }
-
- bool inf::positive (void) const
- {
- return natural() && !zero();
- }
-
- bool inf::zero (void) const
- {
- for (std::string::size_type i = 0; i < m_data.size(); i++)
- if (m_data[i] != 0)
- return false;
- return true;
- }
-
- bool inf::non_zero (void) const
- {
- return !zero();
- }
-
- bool inf::operator ! (void) const
- {
- return zero();
- }
-
- ////////////////////////////////////////////////////////////////////////////////
- // comparison operators
-
- bool inf::operator == (const inf& r) const
- {
- // Two infs are equal if they are numerically equal, even if they are
- // different sizes (i.e. they could be non-reduced values).
- // This makes life a little more complicated than if I could assume that values were reduced.
- byte l_extend = negative() ? byte(255) : byte (0);
- byte r_extend = r.negative() ? byte(255) : byte (0);
- std::string::size_type bytes = maximum(m_data.size(),r.m_data.size());
- for (std::string::size_type i = bytes; i--; )
- {
- byte l_byte = (i < m_data.size() ? byte(m_data[i]) : l_extend);
- byte r_byte = (i < r.m_data.size() ? byte(r.m_data[i]) : r_extend);
- if (l_byte != r_byte)
- return false;
- }
- return true;
- }
-
- bool inf::operator != (const inf& r) const
- {
- return !operator==(r);
- }
-
- bool inf::operator < (const inf& r) const
- {
- // This could be implemented in terms of subtraction. However, it can be
- // simplified since there is no need to calculate the accurate difference,
- // just the direction of the difference. I compare from msB down and as
- // soon as a byte difference is found, that defines the ordering. The
- // problem is that in 2's-complement, all negative values are greater than
- // all natural values if you just do a straight unsigned comparison. I
- // handle this by doing a preliminary test for different signs.
-
- // For example, a 3-bit signed type has the coding:
- // 000 = 0
- // ...
- // 011 = 3
- // 100 = -4
- // ...
- // 111 = -1
-
- // So, for natural values, the ordering of the integer values is the
- // ordering of the bit patterns. Similarly, for negative values, the
- // ordering of the integer values is the ordering of the bit patterns
- // However, the bit patterns for the negative values are *greater than*
- // the natural values. This is a side-effect of the naffness of
- // 2's-complement representation
-
- // first handle the case of comparing two values with different signs
- bool l_sign = negative();
- bool r_sign = r.negative();
- if (l_sign != r_sign)
- {
- // one argument must be negative and the other natural
- // the left is less if it is the negative one
- return l_sign;
- }
- // the arguments are the same sign
- // so the ordering is a simple unsigned byte-by-byte comparison
- // However, this is complicated by the possibility that the values could be different lengths
- byte l_extend = l_sign ? byte(255) : byte (0);
- byte r_extend = r_sign ? byte(255) : byte (0);
- std::string::size_type bytes = maximum(m_data.size(),r.m_data.size());
- for (std::string::size_type i = bytes; i--; )
- {
- byte l_byte = (i < m_data.size() ? byte(m_data[i]) : l_extend);
- byte r_byte = (i < r.m_data.size() ? byte(r.m_data[i]) : r_extend);
- if (l_byte != r_byte)
- return l_byte < r_byte;
- }
- // if I get here, the two are equal, so that is not less-than
- return false;
- }
-
- bool inf::operator <= (const inf& r) const
- {
- return !(r < *this);
- }
-
- bool inf::operator > (const inf& r) const
- {
- return r < *this;
- }
-
- bool inf::operator >= (const inf& r) const
- {
- return !(*this < r);
- }
-
- ////////////////////////////////////////////////////////////////////////////////
- // logical operators
-
- inf& inf::invert (void)
- {
- for (std::string::size_type i = 0; i < m_data.size(); i++)
- m_data[i] = ~m_data[i];
- return *this;
- }
-
- inf inf::operator ~ (void) const
- {
- inf result(*this);
- result.invert();
- return result;
- }
-
- inf& inf::operator &= (const inf& r)
- {
- // bitwise AND is extended to the length of the largest argument
- byte l_extend = negative() ? byte(255) : byte (0);
- byte r_extend = r.negative() ? byte(255) : byte (0);
- std::string::size_type bytes = maximum(m_data.size(),r.m_data.size());
- for (std::string::size_type i = 0; i < bytes; i++)
- {
- byte l_byte = (i < m_data.size() ? byte(m_data[i]) : l_extend);
- byte r_byte = (i < r.m_data.size() ? byte(r.m_data[i]) : r_extend);
- byte result = l_byte & r_byte;
- if (i < m_data.size())
- m_data[i] = result;
- else
- m_data.append(1,result);
- }
- // now reduce the result
- reduce();
- return *this;
- }
-
- inf inf::operator & (const inf& r) const
- {
- inf result(*this);
- result &= r;
- return result;
- }
-
- inf& inf::operator |= (const inf& r)
- {
- // bitwise OR is extended to the length of the largest argument
- byte l_extend = negative() ? byte(255) : byte (0);
- byte r_extend = r.negative() ? byte(255) : byte (0);
- std::string::size_type bytes = maximum(m_data.size(),r.m_data.size());
- for (std::string::size_type i = 0; i < bytes; i++)
- {
- byte l_byte = (i < m_data.size() ? byte(m_data[i]) : l_extend);
- byte r_byte = (i < r.m_data.size() ? byte(r.m_data[i]) : r_extend);
- byte result = l_byte | r_byte;
- if (i < m_data.size())
- m_data[i] = result;
- else
- m_data.append(1,result);
- }
- // now reduce the result
- reduce();
- return *this;
- }
-
- inf inf::operator | (const inf& r) const
- {
- inf result(*this);
- result |= r;
- return result;
- }
-
- inf& inf::operator ^= (const inf& r)
- {
- // bitwise XOR is extended to the length of the largest argument
- byte l_extend = negative() ? byte(255) : byte (0);
- byte r_extend = r.negative() ? byte(255) : byte (0);
- std::string::size_type bytes = maximum(m_data.size(),r.m_data.size());
- for (std::string::size_type i = 0; i < bytes; i++)
- {
- byte l_byte = (i < m_data.size() ? byte(m_data[i]) : l_extend);
- byte r_byte = (i < r.m_data.size() ? byte(r.m_data[i]) : r_extend);
- byte result = l_byte ^ r_byte;
- if (i < m_data.size())
- m_data[i] = result;
- else
- m_data.append(1,result);
- }
- // now reduce the result
- reduce();
- return *this;
- }
-
- inf inf::operator ^ (const inf& r) const
- {
- inf result(*this);
- result ^= r;
- return result;
- }
-
- ////////////////////////////////////////////////////////////////////////////////
- // shift operators all preserve the value by increasing the word size
-
- inf& inf::operator <<= (unsigned shift)
- {
- // left shift is a shift towards the msb, with 0s being shifted in at the lsb
- // split this into a byte shift followed by a bit shift
-
- // first expand the value to be big enough for the result
- std::string::size_type new_size = (indexable_bits() + shift + 7) / 8;
- byte extend = negative() ? byte(255) : byte (0);
- while (m_data.size() < new_size)
- m_data.append(1,extend);
- // now do the byte shift
- unsigned byte_shift = shift/8;
- if (byte_shift > 0)
- {
- for (std::string::size_type b = new_size; b--; )
- m_data[b] = (b >= byte_shift) ? m_data[b-byte_shift] : byte(0);
- }
- // and finally the bit shift
- unsigned bit_shift = shift%8;
- if (bit_shift > 0)
- {
- for (std::string::size_type b = new_size; b--; )
- {
- byte current = byte(m_data[b]);
- byte previous = b > 0 ? m_data[b-1] : byte(0);
- m_data[b] = (current << bit_shift) | (previous >> (8 - bit_shift));
- }
- }
- // now reduce the result
- reduce();
- return *this;
- }
-
- inf inf::operator << (unsigned shift) const
- {
- inf result(*this);
- result <<= shift;
- return result;
- }
-
- inf& inf::operator >>= (unsigned shift)
- {
- // right shift is a shift towards the lsb, with sign bits being shifted in at the msb
- // split this into a byte shift followed by a bit shift
-
- // a byte of sign bits
- byte extend = negative() ? byte(255) : byte (0);
- // do the byte shift
- unsigned byte_shift = shift/8;
- if (byte_shift > 0)
- {
- for (std::string::size_type b = 0; b < m_data.size(); b++)
- m_data[b] = (b + byte_shift < m_data.size()) ? m_data[b+byte_shift] : extend;
- }
- // and finally the bit shift
- unsigned bit_shift = shift%8;
- if (bit_shift > 0)
- {
- for (std::string::size_type b = 0; b < m_data.size(); b++)
- {
- byte current = byte(m_data[b]);
- byte next = ((b+1) < m_data.size()) ? m_data[b+1] : extend;
- byte shifted = (current >> bit_shift) | (next << (8 - bit_shift));
- m_data[b] = shifted;
- }
- }
- // now reduce the result
- reduce();
- return *this;
- }
-
- inf inf::operator >> (unsigned shift) const
- {
- inf result(*this);
- result >>= shift;
- return result;
- }
-
- ////////////////////////////////////////////////////////////////////////////////
- // negation operators
-
- inf& inf::negate (void)
- {
- // do 2's-complement negation
- // equivalent to inversion plus one
- invert();
- operator += (inf(1));
- return *this;
- }
-
- inf inf::operator - (void) const
- {
- inf result(*this);
- result.negate();
- return result;
- }
-
- inf& inf::abs(void)
- {
- if (negative()) negate();
- return *this;
- }
-
- inf abs(const inf& i)
- {
- inf result = i;
- result.abs();
- return result;
- }
-
- ////////////////////////////////////////////////////////////////////////////////
- // addition operators
-
- inf& inf::operator += (const inf& r)
- {
- // do 2's-complement addition
- // Note that the addition can give a result that is larger than either argument
- byte carry = 0;
- std::string::size_type max_size = maximum(m_data.size(),r.m_data.size());
- byte l_extend = negative() ? byte(255) : byte (0);
- byte r_extend = r.negative() ? byte(255) : byte (0);
- for (std::string::size_type i = 0; i < max_size; i++)
- {
- byte l_byte = (i < m_data.size() ? byte(m_data[i]) : l_extend);
- byte r_byte = (i < r.m_data.size() ? byte(r.m_data[i]) : r_extend);
- // calculate the addition in a type that is bigger than a byte in order to catch the carry-out
- unsigned short result = ((unsigned short)(l_byte)) + ((unsigned short)(r_byte)) + carry;
- // now truncate the result to get the lsB
- if (i < m_data.size())
- m_data[i] = byte(result);
- else
- m_data.append(1,byte(result));
- // and capture the carry out by grabbing the second byte of the result
- carry = byte(result >> 8);
- }
- // if the result overflowed or underflowed, add an extra byte to catch it
- unsigned short result = ((unsigned short)(l_extend)) + ((unsigned short)(r_extend)) + carry;
- if (byte(result) != (negative() ? byte(255) : byte(0)))
- m_data.append(1,byte(result));
- // now reduce the result
- reduce();
- return *this;
- }
-
- inf inf::operator + (const inf& r) const
- {
- inf result(*this);
- result += r;
- return result;
- }
-
- ////////////////////////////////////////////////////////////////////////////////
- // subtraction operators
-
- inf& inf::operator -= (const inf& r)
- {
- // subtraction is defined in terms of negation and addition
- inf negated = -r;
- operator += (negated);
- return *this;
- }
-
- inf inf::operator - (const inf& r) const
- {
- inf result(*this);
- result -= r;
- return result;
- }
-
- ////////////////////////////////////////////////////////////////////////////////
- // multiplication operators
-
- inf& inf::operator *= (const inf& r)
- {
- // 2's complement multiplication
- // one day I'll do a more efficient version than this based on the underlying representation
- inf left(*this);
- inf right = r;
- // make the right value natural but preserve its sign for later
- bool right_negative = right.negative();
- right.abs();
- // implemented as a series of conditional additions
- operator = (0);
- // left.resize(right.bits() + left.bits() - 1);
- left <<= right.bits()-1;
- for (unsigned i = right.bits(); i--; )
- {
- if (right[i])
- operator += (left);
- left >>= 1;
- }
- if (right_negative)
- negate();
- // now reduce the result
- reduce();
- return *this;
- }
-
- inf inf::operator * (const inf& r) const
- {
- inf result(*this);
- result *= r;
- return result;
- }
-
- ////////////////////////////////////////////////////////////////////////////////
- // division and remainder operators
-
- std::pair<inf,inf> inf::divide(const inf& right) const throw(divide_by_zero)
- {
- if (right.zero())
- throw divide_by_zero("stlplus::inf::divide");
- inf numerator(*this);
- inf denominator = right;
- // make the numerator natural but preserve the sign for later
- bool numerator_negative = numerator.negative();
- numerator.abs();
- // same with the denominator
- bool denominator_negative = denominator.negative();
- denominator.abs();
- // the quotient and remainder will form the result
- // start with the quotiont zero and the remainder equal to the whole of the
- // numerator, then do trial subtraction from this
- inf quotient;
- inf remainder = numerator;
- // there's nothing more to do if the numerator is smaller than the denominator
- // but otherwise do the division
- if (numerator.bits() >= denominator.bits())
- {
- // make the quotient big enough to take the result
- quotient.resize(numerator.bits());
- // start with the numerator shifted to the far left
- unsigned shift = numerator.bits() - denominator.bits();
- denominator <<= shift;
- // do the division by repeated subtraction,
- for (unsigned i = shift+1; i--; )
- {
- if (remainder >= denominator)
- {
- remainder -= denominator;
- quotient.set(i);
- }
- denominator >>= 1;
- }
- }
- // now adjust the signs
- // x/(-y) == (-x)/y == -(x/y)
- if (numerator_negative != denominator_negative)
- quotient.negate();
- quotient.reduce();
- // x%(-y) == x%y and (-x)%y == -(x%y)
- if (numerator_negative)
- remainder.negate();
- remainder.reduce();
- return std::pair<inf,inf>(quotient,remainder);
- }
-
- inf& inf::operator /= (const inf& r) throw(divide_by_zero)
- {
- std::pair<inf,inf> result = divide(r);
- operator=(result.first);
- return *this;
- }
-
- inf inf::operator / (const inf& r) const throw(divide_by_zero)
- {
- std::pair<inf,inf> result = divide(r);
- return result.first;
- }
-
- inf& inf::operator %= (const inf& r) throw(divide_by_zero)
- {
- std::pair<inf,inf> result = divide(r);
- operator=(result.second);
- return *this;
- }
-
- inf inf::operator % (const inf& r) const throw(divide_by_zero)
- {
- std::pair<inf,inf> result = divide(r);
- return result.second;
- }
-
- ////////////////////////////////////////////////////////////////////////////////
- // prefix (void) and postfix (int) operators
-
- inf& inf::operator ++ (void)
- {
- operator += (inf(1));
- return *this;
- }
-
- inf inf::operator ++ (int)
- {
- inf old(*this);
- operator += (inf(1));
- return old;
- }
-
- inf& inf::operator -- (void)
- {
- operator -= (inf(1));
- return *this;
- }
-
- inf inf::operator -- (int)
- {
- inf old(*this);
- operator -= (inf(1));
- return old;
- }
-
- ////////////////////////////////////////////////////////////////////////////////
- // string representation and I/O routines
-
- std::string inf::to_string(unsigned radix) const
- throw(std::invalid_argument)
- {
- std::string result;
- convert_to_string(*this, result, radix);
- return result;
- }
-
- inf& inf::from_string(const std::string& value, unsigned radix)
- throw(std::invalid_argument)
- {
- convert_from_string(value, *this, radix);
- return *this;
- }
-
- std::ostream& operator << (std::ostream& str, const inf& i)
- {
- try
- {
- // get radix
- unsigned radix = 10;
- if (str.flags() & std::ios_base::oct)
- radix = 8;
- if (str.flags() & std::ios_base::hex)
- radix = 16;
- // the field width is handled by iostream, so I don't need to handle it as well
- // generate the string representation then print it
- str << i.to_string(radix);
- }
- catch(const std::invalid_argument)
- {
- str.setstate(std::ios_base::badbit);
- }
- return str;
- }
-
- std::istream& operator >> (std::istream& str, inf& i)
- {
- try
- {
- // get radix
- unsigned radix = 10;
- if (str.flags() & std::ios_base::oct)
- radix = 8;
- if (str.flags() & std::ios_base::hex)
- radix = 16;
- // now get the string image of the value
- std::string image;
- str >> image;
- // and convert to inf
- i.from_string(image, radix);
- }
- catch(const std::invalid_argument)
- {
- str.setstate(std::ios_base::badbit);
- }
- return str;
- }
-
- ////////////////////////////////////////////////////////////////////////////////
- // diagnostic dump
- // just convert to hex
-
- std::string inf::image_debug(void) const
- {
- // create this dump in the human-readable form, i.e. msB to the left
- std::string result = "0x";
- for (std::string::size_type i = m_data.size(); i--; )
- {
- byte current = m_data[i];
- byte msB = (current & byte(0xf0)) >> 4;
- result += to_char[msB];
- byte lsB = (current & byte(0x0f));
- result += to_char[lsB];
- }
- return result;
- }
-
- const std::string& inf::get_bytes(void) const
- {
- return m_data;
- }
-
- void inf::set_bytes(const std::string& data)
- {
- m_data = data;
- }
-
-} // end namespace stlplus
diff --git a/src/tool/moneycount/inf.hpp b/src/tool/moneycount/inf.hpp
deleted file mode 100644
index f28541a..0000000
--- a/src/tool/moneycount/inf.hpp
+++ /dev/null
@@ -1,228 +0,0 @@
-#ifndef STLPLUS_INF
-#define STLPLUS_INF
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-// An infinite-precision integer class. This allows calculations on large
-// integers to be performed without overflow.
-
-// this class can throw the following exceptions:
-// std::out_of_range
-// std::overflow_error
-// std::invalid_argument
-// stlplus::divide_by_zero // why doesn't std have this?
-// all of these are derivations of the baseclass:
-// std::logic_error
-// So you can catch all of them by catching the baseclass
-
-// Warning: inf was never intended to be fast, it is just for programs which
-// need a bit of infinite-precision integer arithmetic. For high-performance
-// processing, use the Gnu Multi-Precision (GMP) library. The inf type is just
-// easier to integrate and is already ported to all platforms and compilers
-// that STLplus is ported to.
-
-////////////////////////////////////////////////////////////////////////////////
-#include "portability_fixes.hpp"
-#include "portability_exceptions.hpp"
-#include <string>
-#include <iostream>
-
-////////////////////////////////////////////////////////////////////////////////
-
-namespace stlplus
-{
-
-////////////////////////////////////////////////////////////////////////////////
-
- class inf
- {
- public:
-
- //////////////////////////////////////////////////////////////////////////////
- // constructors and assignments initialise the inf
-
- // the void constructor initialises to zero, the others initialise to the
- // value of the C integer type or the text value contained in the string
-
- inf(void);
- explicit inf(short);
- explicit inf(unsigned short);
- explicit inf(int);
- explicit inf(unsigned);
- explicit inf(long);
- explicit inf(unsigned long);
- explicit inf(const std::string&) throw(std::invalid_argument);
- inf(const inf&);
-
- ~inf(void);
-
- // assignments with equivalent behaviour to the constructors
-
- inf& operator = (short);
- inf& operator = (unsigned short);
- inf& operator = (int);
- inf& operator = (unsigned);
- inf& operator = (long);
- inf& operator = (unsigned long);
- inf& operator = (const std::string&) throw(std::invalid_argument);
- inf& operator = (const inf&);
-
- //////////////////////////////////////////////////////////////////////////////
- // conversions back to the C types
- // truncate: controls the behaviour when the value is too long for the result
- // true: truncate the value
- // false: throw an exception
-
- short to_short(bool truncate = true) const throw(std::overflow_error);
- unsigned short to_unsigned_short(bool truncate = true) const throw(std::overflow_error);
-
- int to_int(bool truncate = true) const throw(std::overflow_error);
- unsigned to_unsigned(bool truncate = true) const throw(std::overflow_error);
-
- long to_long(bool truncate = true) const throw(std::overflow_error);
- unsigned long to_unsigned_long(bool truncate = true) const throw(std::overflow_error);
-
- //////////////////////////////////////////////////////////////////////////////
- // bitwise manipulation
-
- void resize(unsigned bits);
- void reduce(void);
-
- // the number of significant bits in the value
- unsigned bits (void) const;
- unsigned size (void) const;
-
- // the number of bits that can be accessed by the bit() method (=bits() rounded up to the next byte)
- unsigned indexable_bits(void) const;
-
- bool bit (unsigned index) const throw(std::out_of_range);
- bool operator [] (unsigned index) const throw(std::out_of_range);
-
- void set (unsigned index) throw(std::out_of_range);
- void clear (unsigned index) throw(std::out_of_range);
- void preset (unsigned index, bool value) throw(std::out_of_range);
-
- inf slice(unsigned low, unsigned high) const throw(std::out_of_range);
-
- //////////////////////////////////////////////////////////////////////////////
- // tests for common values or ranges
-
- bool negative (void) const;
- bool natural (void) const;
- bool positive (void) const;
- bool zero (void) const;
- bool non_zero (void) const;
-
- // tests used in if(i) and if(!i)
-// operator bool (void) const;
- bool operator ! (void) const;
-
- //////////////////////////////////////////////////////////////////////////////
- // comparisons
-
- bool operator == (const inf&) const;
- bool operator != (const inf&) const;
- bool operator < (const inf&) const;
- bool operator <= (const inf&) const;
- bool operator > (const inf&) const;
- bool operator >= (const inf&) const;
-
- //////////////////////////////////////////////////////////////////////////////
- // bitwise logic operations
-
- inf& invert (void);
- inf operator ~ (void) const;
-
- inf& operator &= (const inf&);
- inf operator & (const inf&) const;
-
- inf& operator |= (const inf&);
- inf operator | (const inf&) const;
-
- inf& operator ^= (const inf&);
- inf operator ^ (const inf&) const;
-
- inf& operator <<= (unsigned shift);
- inf operator << (unsigned shift) const;
-
- inf& operator >>= (unsigned shift);
- inf operator >> (unsigned shift) const;
-
- //////////////////////////////////////////////////////////////////////////////
- // arithmetic operations
-
- inf& negate (void);
- inf operator - (void) const;
-
- inf& abs(void);
- friend inf abs(const inf&);
-
- inf& operator += (const inf&);
- inf operator + (const inf&) const;
-
- inf& operator -= (const inf&);
- inf operator - (const inf&) const;
-
- inf& operator *= (const inf&);
- inf operator * (const inf&) const;
-
- inf& operator /= (const inf&) throw(divide_by_zero);
- inf operator / (const inf&) const throw(divide_by_zero);
-
- inf& operator %= (const inf&) throw(divide_by_zero);
- inf operator % (const inf&) const throw(divide_by_zero);
-
- // combined division operator - returns the result pair(quotient,remainder) in one go
- std::pair<inf,inf> divide(const inf&) const throw(divide_by_zero);
-
- //////////////////////////////////////////////////////////////////////////////
- // pre- and post- increment and decrement
-
- inf& operator ++ (void);
- inf operator ++ (int);
- inf& operator -- (void);
- inf operator -- (int);
-
- //////////////////////////////////////////////////////////////////////////////
- // string representation and I/O
-
- std::string image_debug(void) const;
-
- // conversion to a string representation
- // radix must be 10, 2, 8 or 16
- std::string to_string(unsigned radix = 10) const
- throw(std::invalid_argument);
-
- // conversion from a string
- // radix == 0 - radix is deduced from the input - assumed 10 unless number is prefixed by 0b, 0 or 0x
- // however, you can specify the radix to be 10, 2, 8 or 16 to force that interpretation
- inf& from_string(const std::string&, unsigned radix = 0)
- throw(std::invalid_argument);
-
- //////////////////////////////////////////////////////////////////////////////
- private:
- std::string m_data;
- public:
- const std::string& get_bytes(void) const;
- void set_bytes(const std::string&);
- };
-
- ////////////////////////////////////////////////////////////////////////////////
- // redefine friends for gcc v4.1
-
- inf abs(const inf&);
-
- ////////////////////////////////////////////////////////////////////////////////
-
- std::ostream& operator << (std::ostream&, const inf&);
- std::istream& operator >> (std::istream&, inf&);
-
- ////////////////////////////////////////////////////////////////////////////////
-
-} // end namespace stlplus
-
-#endif
diff --git a/src/tool/moneycount/main.cpp b/src/tool/moneycount/main.cpp
deleted file mode 100644
index 2c3d56c..0000000
--- a/src/tool/moneycount/main.cpp
+++ /dev/null
@@ -1,180 +0,0 @@
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <fstream>
-#include <iostream>
-#include <vector>
-#include <algorithm>
-#include <cmath>
-
-#include "mmo.hpp"
-#include "athena_text.hpp"
-#include "inf.hpp"
-
-#define ATHENA_FILE "save/athena.txt"
-#define ACCREG_FILE "save/accreg.txt"
-
-std::vector<int> values;
-
-void countAthena()
-{
- int total = 0;
- std::string input;
- std::ifstream fp(ATHENA_FILE);
- char *buffer = new char[65536];
-
- while (fp.good())
- {
- std::getline(fp,input);
- mmo_charstatus *thisChar = new struct mmo_charstatus;
-
- strcpy(buffer,input.c_str());
-
- if (mmo_char_fromstr(buffer, thisChar))
- {
- total++;
- values.push_back(thisChar->zeny);
- }
-
- delete thisChar;
- }
-
-
- std::cout << "Parsed a total of " << total << " lines in " << ATHENA_FILE << std::endl << std::endl;
-
- delete [] buffer;
- fp.close();
-}
-
-void countAccReg()
-{
- int total = 0;
- std::ifstream fp(ACCREG_FILE);
- char *buffer = new char[65536];
- while (fp.good())
- {
- std::string line;
- std::getline(fp, line);
- struct accreg *reg = new struct accreg;
-
- strcpy(buffer, line.c_str());
-
- if (accreg_fromstr(buffer, reg))
- {
- total++;
- for (int i = 0; i < reg->reg_num; i++)
- {
- if (strcmp(reg->reg[i].str,"#BankAccount") == 0)
- {
- values.push_back(reg->reg[i].value);
- }
- }
- }
-
- delete reg;
- }
-
- std::cout << "Parsed a total of " << total << " lines in " << ACCREG_FILE << std::endl << std::endl;
-
- delete [] buffer;
- fp.close();
-}
-
-stlplus::inf stdDevTotal(0);
-stlplus::inf sum(0);
-stlplus::inf mean(0);
-
-bool lessthan (int i,int j) { return (i<j); }
-void findstddev(int i) { stdDevTotal += stlplus::inf((stlplus::inf(i) - mean) * (stlplus::inf(i) - mean)); }
-void findSum(int i) { sum += stlplus::inf(i); }
-
-stlplus::inf infsqrt(stlplus::inf &x)
-{
- stlplus::inf old(x);
- stlplus::inf newv(x / stlplus::inf(2));
- while (old - newv > stlplus::inf(1))
- {
- old = newv;
- newv = old - (old * old - x) / (stlplus::inf(2) * old);
- }
- return newv;
-}
-
-
-void showStats()
-{
- // Reset globals
- sum = 0;
- mean = 0;
- stdDevTotal = 0;
-
- std::sort(values.begin(), values.end(), lessthan);
- std::for_each(values.begin(), values.end(), findSum);
-
- stlplus::inf total(sum);
- stlplus::inf count(values.size());
- stlplus::inf mean(total / count);
-
- std::for_each(values.begin(), values.end(), findstddev);
-
- int a4th = stlplus::inf(count / stlplus::inf(4)).to_int();
- int a10th = stlplus::inf(count / stlplus::inf(10)).to_int();
-
- int lower = values[0],
-
- t1 = values[a10th * 1],
- t2 = values[a10th * 2],
-
- q1 = values[a4th * 1],
-
- t3 = values[a10th * 3],
- t4 = values[a10th * 4],
-
- median = values[a4th * 2],
-
- t6 = values[a10th * 6],
- t7 = values[a10th * 7],
-
- q3 = values[a4th * 3],
-
- t8 = values[a10th * 8],
- t9 = values[a10th * 9],
-
- upper = values[count.to_int() - 1];
-
- stlplus::inf variance(stdDevTotal / count);
-
- std::cout << "Sum = " << total
- << "\nCount = " << count
- << "\nMean = " << mean
- << "\nSimple Variance = " << variance
- << "\nStandard Deviation = " << infsqrt(variance)
- << "\nLower bound = " << lower
- << "\n10th Percentile = " << t1
- << "\n20th Percentile = " << t2
- << "\nQ1 = " << q1
- << "\n30th Percentile = " << t3
- << "\n40th Percentile = " << t4
- << "\nMedian = " << median
- << "\n60th Percentile = " << t6
- << "\n70th Percentile = " << t7
- << "\nQ3 = " << q3
- << "\n80th Percentile = " << t8
- << "\n90th Percentile = " << t9
- << "\nUpper bound = " << upper << std::endl << std::endl;
-}
-
-int main()
-{
- countAthena();
- std::cout << "The stats for player held money is:" << std::endl;
- showStats();
- values.clear();
-
- countAccReg();
- std::cout << "The stats for bank held money is:" << std::endl;
- showStats();
-
- return 0;
-}
-
diff --git a/src/tool/moneycount/mmo.hpp b/src/tool/moneycount/mmo.hpp
deleted file mode 100644
index beb29c5..0000000
--- a/src/tool/moneycount/mmo.hpp
+++ /dev/null
@@ -1,309 +0,0 @@
-// $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
-
-#ifndef MMO_HPP
-#define MMO_HPP
-
-#include <time.h>
-
-#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
-
-// 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 CHAR_CONF_NAME "conf/char_athena.conf"
-
-struct account
-{
- int account_id;
- char name[50];
- char password[50];
- char lastlogin[50];
- char sex;
- int num_logins;
- int state;
- char email[50];
- char error_message[50];
- long valitidy_time;
- char last_ip[50];
- char memo[50];
- long ban_time;
-};
-
-
-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, flags;
-};
-
-struct global_reg
-{
- char str[32];
- int value;
-};
-
-struct accreg
-{
- int account_id, reg_num;
- struct global_reg reg[ACCOUNT_REG_NUM];
-};
-
-struct mmo_charstatus
-{
- int char_id;
- int account_id;
- int partner_id;
-
- int base_exp, job_exp, zeny;
-
- short classb;
- 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;
-
- 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;
-
- unsigned long mapip;
- unsigned int mapport;
-
- 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 dirty;
- int account_id;
- short storage_status;
- short storage_amount;
- struct item storage_[MAX_STORAGE];
-};
-
-struct guild_storage
-{
- int dirty;
- 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, classb, 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];
- char castle_event[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, // ?M???h??EXP
- GBI_GUILDLV = 2, // ?M???h??Lv
- GBI_SKILLPOINT = 3, // ?M???h?~X?L???|?C???g
- GBI_SKILLLV = 4, // ?M???h?X?L??Lv
-
- GMI_POSITION = 0, // ?????o?[???E??X
- GMI_EXP = 1, // ?????o?[??EXP
-
-};
-
-#endif // MMO_HPP
-
diff --git a/src/tool/moneycount/portability_exceptions.hpp b/src/tool/moneycount/portability_exceptions.hpp
deleted file mode 100644
index c66b7bf..0000000
--- a/src/tool/moneycount/portability_exceptions.hpp
+++ /dev/null
@@ -1,33 +0,0 @@
-#ifndef STLPLUS_PORTABILITY_EXCEPTIONS
-#define STLPLUS_PORTABILITY_EXCEPTIONS
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-// Adds missing arithmetic exceptions used in this library but missing from std
-
-////////////////////////////////////////////////////////////////////////////////
-#include "portability_fixes.hpp"
-#include <string>
-#include <stdexcept>
-
-namespace stlplus
-{
-
- ////////////////////////////////////////////////////////////////////////////////
- // thrown by division when the divisor is zero
- // This is a subclass of std::logic_error so can be caught by a generic catch clause for the superclass
-
- class divide_by_zero : public std::logic_error {
- public:
- divide_by_zero (const std::string& what_arg): std::logic_error (what_arg) { }
- };
-
-////////////////////////////////////////////////////////////////////////////////
-
-} // end namespace stlplus
-
-#endif
diff --git a/src/tool/moneycount/portability_fixes.cpp b/src/tool/moneycount/portability_fixes.cpp
deleted file mode 100644
index e26ee28..0000000
--- a/src/tool/moneycount/portability_fixes.cpp
+++ /dev/null
@@ -1,39 +0,0 @@
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-////////////////////////////////////////////////////////////////////////////////
-#include "portability_fixes.hpp"
-
-#ifdef MSWINDOWS
-#include "windows.h"
-#endif
-
-////////////////////////////////////////////////////////////////////////////////
-// problems with missing functions
-////////////////////////////////////////////////////////////////////////////////
-
-#ifdef MSWINDOWS
-unsigned sleep(unsigned seconds)
-{
- Sleep(1000*seconds);
- // should return remaining time if interrupted - however Windoze Sleep cannot be interrupted
- return 0;
-}
-#endif
-
-////////////////////////////////////////////////////////////////////////////////
-// Function for establishing endian-ness
-////////////////////////////////////////////////////////////////////////////////
-
-bool stlplus::little_endian(void)
-{
- int sample = 1;
- char* sample_bytes = (char*)&sample;
- return sample_bytes[0] != 0;
-}
-
-////////////////////////////////////////////////////////////////////////////////
diff --git a/src/tool/moneycount/portability_fixes.hpp b/src/tool/moneycount/portability_fixes.hpp
deleted file mode 100644
index b6a030c..0000000
--- a/src/tool/moneycount/portability_fixes.hpp
+++ /dev/null
@@ -1,127 +0,0 @@
-#ifndef STLPLUS_PORTABILITY_FIXES
-#define STLPLUS_PORTABILITY_FIXES
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-// Contains work arounds for OS or Compiler specific problems to try to make
-// them look more alike
-
-// It is strongly recommended that this header be included as the first
-// #include in every source file
-
-////////////////////////////////////////////////////////////////////////////////
-
-////////////////////////////////////////////////////////////////////////////////
-// Problem with MicroSoft defining two different macros to identify Windows
-////////////////////////////////////////////////////////////////////////////////
-
-#if defined(_WIN32) || defined(_WIN32_WCE)
-#define MSWINDOWS
-#endif
-
-////////////////////////////////////////////////////////////////////////////////
-// Problems with unnecessary or unfixable compiler warnings
-////////////////////////////////////////////////////////////////////////////////
-
-#ifdef _MSC_VER
-// Microsoft Visual Studio
-// shut up the following irritating warnings
-// 4786 - VC6, identifier string exceeded maximum allowable length and was truncated (only affects debugger)
-// 4305 - VC6, identifier type was converted to a smaller type
-// 4503 - VC6, decorated name was longer than the maximum the compiler allows (only affects debugger)
-// 4309 - VC6, type conversion operation caused a constant to exceeded the space allocated for it
-// 4290 - VC6, C++ exception specification ignored
-// 4800 - VC6, forcing value to bool 'true' or 'false' (performance warning)
-// 4675 - VC7.1, "change" in function overload resolution _might_ have altered program
-// 4996 - VC8, 'xxxx' was declared deprecated
-#pragma warning(disable: 4786 4305 4503 4309 4290 4800 4675 4996)
-#endif
-
-#ifdef __BORLANDC__
-// Borland
-// Shut up the following irritating warnings
-// 8026 - Functions with exception specifications are not expanded inline
-// 8027 - Functions with xxx are not expanded inline
-#pragma warn -8026
-#pragma warn -8027
-#endif
-
-////////////////////////////////////////////////////////////////////////////////
-// Problems with redefinition of min/max in various different versions of library headers
-////////////////////////////////////////////////////////////////////////////////
-
-// The Windows headers define macros called max/min which conflict with the templates std::max and std::min.
-// So, to avoid conflicts, MS removed the std::max/min rather than fixing the problem!
-// From Visual Studio .NET (SV7, compiler version 13.00) the STL templates have been added correctly.
-// For MFC compatibility, only undef min and max in non-MFC programs - some bits of MFC
-// use macro min/max in headers.
-
-// I've created extra template function definitions minimum/maximum that avoid all the problems above
-
-namespace stlplus
-{
- template<typename T> const T& maximum(const T& l, const T& r) {return l > r ? l : r;}
- template<typename T> const T& minimum(const T& l, const T& r) {return l < r ? l : r;}
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// Problems with differences between namespaces
-////////////////////////////////////////////////////////////////////////////////
-
-// Note: not sure of the relevance of this - maybe deprecated?
-// problem in gcc pre-v3 where the sub-namespaces in std aren't present
-// this mean that the statement "using namespace std::rel_ops" created an error because the namespace didn't exist
-
-// I've done a fix here that creates an empty namespace for this case, but I
-// do *not* try to move the contents of std::rel_ops into namespace std
-// This fix only works if you use "using namespace std::rel_ops" to bring in the template relational operators (e.g. != defined i.t.o. ==)
-
-#ifdef __GNUC__
-namespace std
-{
- namespace rel_ops
- {
- }
-}
-#endif
-
-////////////////////////////////////////////////////////////////////////////////
-// problems with missing functions
-////////////////////////////////////////////////////////////////////////////////
-
-#ifdef MSWINDOWS
-unsigned sleep(unsigned seconds);
-#else
-#include <unistd.h>
-#endif
-
-////////////////////////////////////////////////////////////////////////////////
-// Function for establishing endian-ness
-////////////////////////////////////////////////////////////////////////////////
-// Different machine architectures store data using different byte orders.
-// This is referred to as Big- and Little-Endian Byte Ordering.
-//
-// The issue is: where does a pointer to an integer type actually point?
-//
-// In both conventions, the address points to the left of the word but:
-// Big-Endian - The most significant byte is on the left end of a word
-// Little-Endian - The least significant byte is on the left end of a word
-//
-// Bytes are addressed left to right, so in big-endian order byte 0 is the
-// msB, whereas in little-endian order byte 0 is the lsB. For example,
-// Intel-based machines store data in little-endian byte order so byte 0 is
-// the lsB.
-//
-// This function establishes byte order at run-time
-
-namespace stlplus
-{
- bool little_endian(void);
-}
-
-////////////////////////////////////////////////////////////////////////////////
-#endif
diff --git a/src/tool/skillfrob.cpp b/src/tool/skillfrob.cpp
deleted file mode 100644
index 901f765..0000000
--- a/src/tool/skillfrob.cpp
+++ /dev/null
@@ -1,80 +0,0 @@
-// Compile with
-// gcc -m32 -Wall -Wno-pointer-sign -fno-strict-aliasing -I src/char -I src/common src/tool/skillfrob.c -o skillfrob src/common/timer.o src/common/malloc.o src/common/socket.o src/common/lock.o src/common/db.o src/char/int_storage.o src/char/inter.o src/char/int_party.o src/char/int_guild.o
-
-#include <stdio.h>
-#include <stdlib.h>
-#include "../common/mmo.hpp"
-#include "../char/char.cpp"
-
-unsigned char skills[MAX_SKILL];
-
-void transform_char (struct mmo_charstatus *p)
-{
- int i;
-
- for (i = 0; i < MAX_SKILL; i++)
- {
- if (skills[(*p).skill[i].id])
- {
- (*p).skill[i].lv = 0;
- (*p).skill[i].flags = 0;
- }
- }
-}
-
-int mmo_char_convert ()
-{
- char line[965536];
- int ret;
- struct mmo_charstatus char_dat;
- FILE *ifp, *ofp;
-
- ifp = stdin;
- ofp = stdout;
- while (fgets (line, 65535, ifp))
- {
- memset (&char_dat, 0, sizeof (struct mmo_charstatus));
- ret = mmo_char_fromstr (line, &char_dat);
- if (ret)
- {
- transform_char (&char_dat);
- mmo_char_tostr (line, &char_dat);
- fprintf (ofp, "%s\n", line);
- }
- }
- fcloseall ();
- return 0;
-}
-
-int init (int count, char **translates)
-{
- int i, skill;
-
- memset (skills, 0, sizeof (skills));
-
- for (i = 0; i < count; i++)
- {
- skill = atoi (translates[i]);
- if (skill > 0)
- {
- skills[skill] = 1;
- }
- }
-
- return 0;
-}
-
-int main (int argc, char *argv[])
-{
- if (argc < 2)
- {
- printf ("Usage: %s skillid1 skillid2 ...\n", argv[0]);
- exit (0);
- }
- if (init (argc - 1, argv + 1))
- return 1;
-
- mmo_char_convert ();
-
- return 0;
-}
diff --git a/src/tool/stats.sh b/src/tool/stats.sh
deleted file mode 100755
index 9ea021b..0000000
--- a/src/tool/stats.sh
+++ /dev/null
@@ -1,44 +0,0 @@
-#!/bin/bash
-
-ATHENATXT="save/athena.txt"
-DEST="$HOME/public_html/stats"
-
-:> ${DEST}/top-money.txt
-(echo "TOP 50 RICHEST PLAYERS"; echo ""; cat ${ATHENATXT} \
-| awk -F , '{sub(/^[0-9] */,"",$2);sub(/ *[0-9]$/,"",$2); sub(/ *[0-9]+$/,"",$6);print $6,$2}' \
-| sort -nr | head -n 50 | awk '{first=$1;$1="";print $0, "("first")"}' | nl -s ". "; echo ""; echo "Generated at `date`") >> ${DEST}/top-money.txt
-
-:> ${DEST}/top-highest-level.txt
-(echo "TOP 50 HIGHEST LEVEL PLAYERS"; echo ""; cat ${ATHENATXT} \
-| awk -F , '{sub(/^[0-9] */,"",$2);sub(/ *[0-9]$/,"",$2); print $3,$2}' \
-| sort -nr | head -n 50 | awk '{first=$1;$1="";print $0, "("first")"}' | nl -s ". "; echo ""; echo "Generated at `date`") >> ${DEST}/top-highest-level.txt
-
-:> ${DEST}/top-highest-str.txt
-(echo "TOP 50 HIGHEST LEVEL PLAYERS"; echo ""; cat ${ATHENATXT} \
-| awk -F , '{sub(/^[0-9] */,"",$2);sub(/ *[0-9]$/,"",$2); sub(/^[0-9]+[[:space:]]*/,"",$9);print $9,$2}' \
-| sort -nr | head -n 50 | awk '{first=$1;$1="";print $0, "("first")"}' | nl -s ". "; echo ""; echo "Generated at `date`") >> ${DEST}/top-highest-str.txt
-
-:> ${DEST}/top-highest-agi.txt
-(echo "TOP 50 HIGHEST LEVEL PLAYERS"; echo ""; cat ${ATHENATXT} \
-| awk -F , '{sub(/^[0-9] */,"",$2);sub(/ *[0-9]$/,"",$2); print $10,$2}' \
-| sort -nr | head -n 50 | awk '{first=$1;$1="";print $0, "("first")"}' | nl -s ". "; echo ""; echo "Generated at `date`") >> ${DEST}/top-highest-agi.txt
-
-:> ${DEST}/top-highest-vit.txt
-(echo "TOP 50 HIGHEST LEVEL PLAYERS"; echo ""; cat ${ATHENATXT} \
-| awk -F , '{sub(/^[0-9] */,"",$2);sub(/ *[0-9]$/,"",$2); print $11,$2}' \
-| sort -nr | head -n 50 | awk '{first=$1;$1="";print $0, "("first")"}' | nl -s ". "; echo ""; echo "Generated at `date`") >> ${DEST}/top-highest-vit.txt
-
-:> ${DEST}/top-highest-int.txt
-(echo "TOP 50 HIGHEST LEVEL PLAYERS"; echo ""; cat ${ATHENATXT} \
-| awk -F , '{sub(/^[0-9] */,"",$2);sub(/ *[0-9]$/,"",$2); print $12,$2}' \
-| sort -nr | head -n 50 | awk '{first=$1;$1="";print $0, "("first")"}' | nl -s ". "; echo ""; echo "Generated at `date`") >> ${DEST}/top-highest-int.txt
-
-:> ${DEST}/top-highest-dex.txt
-(echo "TOP 50 HIGHEST LEVEL PLAYERS"; echo ""; cat ${ATHENATXT} \
-| awk -F , '{sub(/^[0-9] */,"",$2);sub(/ *[0-9]$/,"",$2); print $13,$2}' \
-| sort -nr | head -n 50 | awk '{first=$1;$1="";print $0, "("first")"}' | nl -s ". "; echo ""; echo "Generated at `date`") >> ${DEST}/top-highest-dex.txt
-
-:> ${DEST}/top-highest-luk.txt
-(echo "TOP 50 HIGHEST LEVEL PLAYERS"; echo ""; cat ${ATHENATXT} \
-| awk -F , '{sub(/^[0-9] */,"",$2);sub(/ *[0-9]$/,"",$2); sub(/[[:space:]]*[0-9]+$/,"",$14);print $14,$2}' \
-| sort -nr | head -n 50 | awk '{first=$1;$1="";print $0, "("first")"}' | nl -s ". "; echo ""; echo "Generated at `date`") >> ${DEST}/top-highest-luk.txt
diff --git a/src/warnings.hpp b/src/warnings.hpp
new file mode 100644
index 0000000..4248155
--- /dev/null
+++ b/src/warnings.hpp
@@ -0,0 +1,672 @@
+// no include guards
+// This is the first file in every compilation, passed by the makefile.
+// This file contains only preprocessor directions.
+
+// This file is currently targeted at:
+// GCC 4.6 (incomplete due to bugs)
+// GCC 4.7 (for few minor workarounds)
+// GCC 4.8 (zarro boogs found)
+// clang 3.1 (may ICE later)
+// clang 3.2 (with a few major workarounds)
+
+// List of warnings that require arguments,
+// and thus cannot reliably be activated:
+// gcc 4.6:
+// -Wlarger-than=<1024>
+// -Wnormalized=<id|nfc|nfd>
+// -Wsuggest-attribute=<noreturn,const,pure,format>
+// gcc 4.7:
+// -Wstack-usage=<8192>
+// ???
+// -Wstrict-aliasing=<1>
+// -Wstrict-overflow=<1>
+
+// options that enable other options
+// only warnings so I can catch the errors
+#pragma GCC diagnostic warning "-Wall"
+#pragma GCC diagnostic warning "-Wextra"
+#pragma GCC diagnostic warning "-Wunused"
+#pragma GCC diagnostic warning "-Wformat"
+
+#ifdef __clang__
+# if __clang_major__ < 3
+# error "your clang is way too old"
+# elif __clang_major__ == 3
+# if __clang_minor__ < 1
+# error "your clang is too old"
+# endif // __clang_minor__
+# endif // __clang_major__
+#else // __clang__
+# if __GNUC__ < 4
+# error "your gcc is way too old"
+# if __GNUC_MINOR__ < 6
+# error "your gcc is too old"
+# elif __GNUC_MINOR__ == 6
+# if __GNUC_PATCHLEVEL__ < 3
+# error "TODO: test this patchlevel"
+# endif // __GNUC_PATCHLEVEL__
+# elif __GNUC_MINOR__ == 7
+# if __GNUC_PATCHLEVEL__ < 2
+# error "your gcc has a known bad patchlevel"
+# endif // __GNUC_PATCHLEVEL__
+# endif // __GNUC_MINOR__
+# endif // __GNUC__
+#endif // __clang__
+
+// BEGIN Macros to make my life easier
+
+// stringification requirement - #sw within #ar
+#define P(ar) _Pragma(#ar)
+
+// Use "GCC diagnostic" for warnings applicable to all versions.
+#define I(sw) P(GCC diagnostic ignored #sw)
+#define W(sw) P(GCC diagnostic warning #sw)
+#define E(sw) P(GCC diagnostic error #sw)
+// configurable thing (also change in clang below!)
+#define X(sw) I(sw)
+
+
+#ifdef __clang__
+
+// Use "clang diagnostic" for warnings specific to clang
+# define IC(sw) P(clang diagnostic ignored #sw)
+# define WC(sw) P(clang diagnostic warning #sw)
+# define EC(sw) P(clang diagnostic error #sw)
+# define XC(sw) IC(sw) // this is below
+
+// warning specific to gcc
+# define IG(sw) static_assert('I', #sw "skipped for clang");
+# define WG(sw) static_assert('W', #sw "skipped for clang");
+# define EG(sw) static_assert('E', #sw "skipped for clang");
+# define XG(sw) static_assert('X', #sw "skipped for clang");
+
+# define IG47(sw) static_assert('I', #sw "only for gcc 4.7+");
+# define WG47(sw) static_assert('W', #sw "only for gcc 4.7+");
+# define EG47(sw) static_assert('E', #sw "only for gcc 4.7+");
+# define XG47(sw) static_assert('X', #sw "only for gcc 4.7+");
+
+# define IG48(sw) static_assert('I', #sw "only for gcc 4.8+");
+# define WG48(sw) static_assert('W', #sw "only for gcc 4.8+");
+# define EG48(sw) static_assert('E', #sw "only for gcc 4.8+");
+# define XG48(sw) static_assert('X', #sw "only for gcc 4.8+");
+
+# define I47(sw) I(sw)
+# define W47(sw) W(sw)
+# define E47(sw) E(sw)
+# define X47(sw) X(sw)
+
+# define I48(sw) I(sw)
+# define W48(sw) W(sw)
+# define E48(sw) E(sw)
+# define X48(sw) X(sw)
+
+#else
+
+// warnings specific to clang
+# define IC(sw) static_assert('I', #sw "skipped for gcc");
+# define WC(sw) static_assert('W', #sw "skipped for gcc");
+# define EC(sw) static_assert('E', #sw "skipped for gcc");
+# define XC(sw) static_assert('X', #sw "skipped for gcc");
+
+// warnings specific to gcc
+# define IG(sw) I(sw)
+# define WG(sw) W(sw)
+# define EG(sw) E(sw)
+# define XG(sw) X(sw)
+
+// used both for warnings not implemented in a version
+// and for warnings that falsely trigger
+# if __GNUC__ == 4
+# if __GNUC_MINOR__ >= 7
+# define IG47(sw) IG(sw)
+# define WG47(sw) WG(sw)
+# define EG47(sw) EG(sw)
+# define XG47(sw) XG(sw)
+
+# define I47(sw) I(sw)
+# define W47(sw) W(sw)
+# define E47(sw) E(sw)
+# define X47(sw) X(sw)
+# else
+# define IG47(sw) static_assert('I', #sw "only for gcc 4.7+");
+# define WG47(sw) static_assert('W', #sw "only for gcc 4.7+");
+# define EG47(sw) static_assert('E', #sw "only for gcc 4.7+");
+# define XG47(sw) static_assert('X', #sw "only for gcc 4.7+");
+
+# define I47(sw) static_assert('I', #sw "only for gcc 4.7+ or clang");
+# define W47(sw) static_assert('W', #sw "only for gcc 4.7+ or clang");
+# define E47(sw) static_assert('E', #sw "only for gcc 4.7+ or clang");
+# define X47(sw) static_assert('X', #sw "only for gcc 4.7+ or clang");
+# endif // __GNUC_MINOR__
+# if __GNUC_MINOR__ >= 8
+# define IG48(sw) IG(sw)
+# define WG48(sw) WG(sw)
+# define EG48(sw) EG(sw)
+# define XG48(sw) XG(sw)
+
+# define I48(sw) IG(sw)
+# define W48(sw) WG(sw)
+# define E48(sw) EG(sw)
+# define X48(sw) XG(sw)
+# else
+# define IG48(sw) static_assert('I', #sw "only for gcc 4.8+");
+# define WG48(sw) static_assert('W', #sw "only for gcc 4.8+");
+# define EG48(sw) static_assert('E', #sw "only for gcc 4.8+");
+# define XG48(sw) static_assert('X', #sw "only for gcc 4.8+");
+
+# define I48(sw) static_assert('I', #sw "only for gcc 4.8+ or clang");
+# define W48(sw) static_assert('W', #sw "only for gcc 4.8+ or clang");
+# define E48(sw) static_assert('E', #sw "only for gcc 4.8+ or clang");
+# define X48(sw) static_assert('X', #sw "only for gcc 4.8+ or clang");
+# endif // __GNUC_MINOR__
+# endif // __GNUC__
+#endif // __clang__
+
+// END macros to make my life easier
+
+
+/// Warn about things that will change when compiling
+/// with an ABI-compliant compiler
+I(-Wabi)
+
+/// Warn if a subobject has an abi_tag attribute that
+/// the complete object type does not have
+WG48(-Wabi-tag)
+
+/// Warn about suspicious uses of memory addresses
+E(-Waddress)
+
+/// Warn about returning structures, unions or arrays
+I(-Waggregate-return)
+
+/// Warn if an array is accessed out of bounds
+E(-Warray-bounds)
+
+/// Warn about inappropriate attribute usage
+E(-Wattributes)
+
+/// Warn when a built-in preprocessor macro is
+// undefined or redefined
+E(-Wbuiltin-macro-redefined)
+
+/// Warn about C++ constructs whose meaning differs
+/// between ISO C++ 1998 and ISO C++ 2011
+E(-Wc++0x-compat)
+//W(-Wc++11-compat)
+
+/// Warn about pointer casts which increase alignment
+X(-Wcast-align)
+
+/// Warn about casts which discard qualifiers
+E(-Wcast-qual)
+
+/// Warn about subscripts whose type is "char"
+E(-Wchar-subscripts)
+
+/// Warn about variables that might be changed by
+/// "longjmp" or "vfork"
+EG(-Wclobbered)
+
+/// Warn about possibly nested block comments, and
+/// C++ comments spanning more than one physical line
+E(-Wcomment)
+
+/// Warn for implicit type conversions that may
+/// change a value
+X(-Wconversion)
+
+/// Warn for converting NULL from/to a non-pointer
+/// type
+E(-Wconversion-null)
+
+/// Warn in case profiles in -fprofile-use do not
+/// match
+WG(-Wcoverage-mismatch)
+
+///
+XC(-Wcovered-switch-default)
+
+/// Warn when a #warning directive is encountered
+WG(-Wcpp)
+
+/// Warn when all constructors and destructors are
+/// private
+E(-Wctor-dtor-privacy)
+
+/// Warn about deleting polymorphic objects with non-
+/// virtual destructors
+E47(-Wdelete-non-virtual-dtor)
+
+/// Warn if a deprecated compiler feature, class,
+/// method, or field is used
+W(-Wdeprecated)
+
+/// Warn about uses of __attribute__((deprecated))
+/// declarations
+W(-Wdeprecated-declarations)
+#ifdef QUIET
+I(-Wdeprecated-declarations)
+#endif
+
+/// Warn when an optimization pass is disabled
+W(-Wdisabled-optimization)
+
+/// Warn about compile-time integer division by zero
+E(-Wdiv-by-zero)
+
+///
+WC(-Wdocumentation)
+
+/// Warn about implicit conversions from "float" to
+/// "double"
+IG(-Wdouble-promotion)
+
+/// Warn about violations of Effective C++ style rules
+I(-Weffc++)
+
+/// Warn about an empty body in an if or else
+/// statement
+E(-Wempty-body)
+
+/// Warn about stray tokens after #elif and #endif
+E(-Wendif-labels)
+
+/// Warn about comparison of different enum types
+E(-Wenum-compare)
+
+///
+EC(-Wextra-semi)
+
+/// Warn if testing floating point numbers for
+/// equality
+E(-Wfloat-equal)
+
+/// Warn about printf/scanf/strftime/strfmon format
+/// string anomalies
+// see below
+EG(-Wformat)
+
+/// Warn about format strings that contain NUL bytes
+EG(-Wformat-contains-nul)
+
+/// Warn if passing too many arguments to a function
+/// for its format string
+E(-Wformat-extra-args)
+
+/// Warn about format strings that are not literals
+EG(-Wformat-nonliteral)
+// Available in clang, but not smart enough to handle constexpr.
+IC(-Wformat-nonliteral)
+
+/// Warn about possible security problems with format
+/// functions
+EG(-Wformat-security)
+// Same.
+IC(-Wformat-security)
+
+/// Warn about strftime formats yielding 2-digit years
+E(-Wformat-y2k)
+
+/// Warn about zero-length formats
+I(-Wformat-zero-length)
+
+/// Warn when attempting to free a non-heap object
+EG47(-Wfree-nonheap-object)
+
+// -Wgnu is a clang alias for -Wpedantic
+
+/// Warn whenever type qualifiers are ignored.
+E(-Wignored-qualifiers)
+
+///
+EC(-Wimplicit-fallthrough)
+
+/// Warn about C++11 inheriting constructors when the
+/// base has a variadic constructor
+WG48(-Winherited-variadic-ctor)
+
+/// Warn about variables which are initialized to
+/// themselves
+E(-Winit-self)
+
+/// Warn when an inlined function cannot be inlined
+X(-Winline)
+
+/// Warn when there is a cast to a pointer from an
+/// integer of a different size
+E(-Wint-to-pointer-cast)
+
+/// Warn when an atomic memory model parameter is
+/// known to be outside the valid range.
+WG47(-Winvalid-memory-model)
+
+/// Warn about invalid uses of the "offsetof" macro
+E(-Winvalid-offsetof)
+
+/// Warn about PCH files that are found but not used
+E(-Winvalid-pch)
+
+/// Warn when a string or character literal is
+/// followed by a ud-suffix which does not begin with
+/// an underscore.
+WG48(-Wliteral-suffix)
+
+/// Warn when a logical operator is suspiciously
+/// always evaluating to true or false
+WG(-Wlogical-op)
+
+/// Do not warn about using "long long" when -pedantic
+I(-Wlong-long)
+
+/// Warn about suspicious declarations of "main"
+E(-Wmain)
+
+/// Warn about maybe uninitialized automatic variables
+EG47(-Wmaybe-uninitialized)
+
+/// Warn about possibly missing braces around
+/// initializers
+// beware of things like std::array!
+E(-Wmissing-braces)
+
+/// Warn about global functions without previous
+/// declarations
+E(-Wmissing-declarations)
+
+/// Warn about missing fields in struct initializers
+// Actually supported by GCC, but gives warnings when I don't want, e.g.:
+// Foo foo = {};
+EC(-Wmissing-field-initializers)
+IG(-Wmissing-field-initializers)
+
+/// Warn about functions which might be candidates
+/// for format attributes
+E(-Wmissing-format-attribute)
+
+/// Warn about user-specified include directories
+/// that do not exist
+E(-Wmissing-include-dirs)
+
+/// Warn about functions which might be candidates
+/// for __attribute__((noreturn))
+W(-Wmissing-noreturn)
+
+///
+// like -Wmissing-declarations but for variables instead of functions
+EC(-Wmissing-variable-declarations)
+
+/// Warn about constructs not instrumented by
+/// -fmudflap
+EG(-Wmudflap)
+
+/// Warn about use of multi-character character
+/// constants
+E(-Wmultichar)
+
+/// Warn about narrowing conversions within { } that
+/// are ill-formed in C++11
+EG47(-Wnarrowing)
+
+/// Warn when a noexcept expression evaluates to
+/// false even though the expression can't actually
+/// throw
+WG(-Wnoexcept)
+
+/// Warn when non-templatized friend functions are
+/// declared within a template
+EG(-Wnon-template-friend)
+
+/// Warn about non-virtual destructors
+E(-Wnon-virtual-dtor)
+
+/// Warn about NULL being passed to argument slots
+/// marked as requiring non-NULL
+E(-Wnonnull)
+
+///
+XC(-Wnull-conversion)
+
+/// Warn if a C-style cast is used in a program
+X(-Wold-style-cast)
+
+/// Warn about overflow in arithmetic expressions
+W(-Woverflow)
+
+/// Warn if a string is longer than the maximum
+/// portable length specified by the standard
+//X(-Woverlength-strings)
+
+/// Warn about overloaded virtual function names
+E(-Woverloaded-virtual)
+
+/// Warn when the packed attribute has no effect on
+/// struct layout
+E(-Wpacked)
+
+/// Warn about packed bit-fields whose offset changed
+/// in GCC 4.4
+WG(-Wpacked-bitfield-compat)
+
+/// Warn when padding is required to align structure
+/// members
+I(-Wpadded)
+
+/// Warn about possibly missing parentheses
+E(-Wparentheses)
+
+/// Issue warnings needed for strict compliance to
+/// the standard
+EG48(-Wpedantic)
+// a bit too noisy
+XC(-Wpedantic)
+
+/// Warn when converting the type of pointers to
+/// member functions
+EG(-Wpmf-conversions)
+
+/// Warn about function pointer arithmetic
+E(-Wpointer-arith)
+
+/// Warn about misuses of pragmas
+EG(-Wpragmas)
+
+/// Warn about multiple declarations of the same
+/// object
+W(-Wredundant-decls)
+
+/// Warn when the compiler reorders code
+E(-Wreorder)
+
+/// Warn about returning a pointer/reference to a
+/// local or temporary variable.
+WG48(-Wreturn-local-addr)
+
+/// Warn whenever a function's return type defaults
+/// to "int" (C), or about inconsistent return types
+/// (C++)
+E(-Wreturn-type)
+
+/// Warn about possible violations of sequence point
+/// rules
+E(-Wsequence-point)
+
+/// Warn when one local variable shadows another
+E(-Wshadow)
+
+/// Warn about signed-unsigned comparisons
+X(-Wsign-compare)
+
+/// Warn when overload promotes from unsigned to
+/// signed
+X(-Wsign-promo)
+
+/// This switch lacks documentation
+WG48(-Wsizeof-pointer-memaccess)
+
+/// Warn when not issuing stack smashing protection
+/// for some reason
+X(-Wstack-protector)
+
+/// Warn about code which might break strict aliasing
+/// rules
+E(-Wstrict-aliasing)
+
+/// Warn about uncasted NULL used as sentinel
+WG(-Wstrict-null-sentinel)
+
+/// Warn about optimizations that assume that signed
+/// overflow is undefined
+X(-Wstrict-overflow)
+
+/// Warn about enumerated switches, with no default,
+/// missing a case
+X(-Wswitch)
+
+/// Warn about enumerated switches missing a
+/// "default:" statement
+X(-Wswitch-default)
+
+/// Warn about all enumerated switches missing a
+/// specific case
+X(-Wswitch-enum)
+
+/// Warn when __sync_fetch_and_nand and
+/// __sync_nand_and_fetch built-in functions are used
+WG(-Wsync-nand)
+
+/// Warn whenever a trampoline is generated
+EG(-Wtrampolines)
+
+/// Warn if trigraphs are encountered that might
+/// affect the meaning of the program
+E(-Wtrigraphs)
+
+/// Warn if a comparison is always true or always
+/// false due to the limited range of the data type
+E(-Wtype-limits)
+
+/// Warn if an undefined macro is used in an #if
+/// directive
+E(-Wundef)
+
+/// Warn about uninitialized automatic variables
+E(-Wuninitialized)
+
+/// Warn about unrecognized pragmas
+E(-Wunknown-pragmas)
+
+///
+// Not an error because of some remaining enum+default
+WC(-Wunreachable-code)
+
+/// Warn if the loop cannot be optimized due to
+/// nontrivial assumptions.
+XG(-Wunsafe-loop-optimizations)
+
+/// Warn when a function parameter is only set,
+/// otherwise unused
+EG(-Wunused-but-set-parameter)
+
+/// Warn when a variable is only set, otherwise unused
+EG(-Wunused-but-set-variable)
+
+/// Warn when a function is unused
+E(-Wunused-function)
+
+/// Warn when a label is unused
+E(-Wunused-label)
+
+/// Warn when typedefs locally defined in a function
+/// are not used
+EG47(-Wunused-local-typedefs)
+
+/// Warn about macros defined in the main file that
+/// are not used
+W(-Wunused-macros)
+
+/// Warn when a function parameter is unused
+E(-Wunused-parameter)
+
+/// Warn if a caller of a function, marked with
+/// attribute warn_unused_result, does not use its
+/// return value
+W(-Wunused-result)
+
+/// Warn when an expression value is unused
+E(-Wunused-value)
+
+/// Warn when a variable is unused
+E(-Wunused-variable)
+
+/// Warn about useless casts
+EG48(-Wuseless-cast)
+
+/// Warn about questionable usage of the macros used
+/// to retrieve variable arguments
+EG48(-Wvarargs)
+
+/// Warn about using variadic macros
+W(-Wvariadic-macros)
+
+/// Warn when a vector operation is compiled
+/// outside the SIMD
+WG47(-Wvector-operation-performance)
+
+/// Warn if a virtual base has a non-trivial move
+/// assignment operator
+EG48(-Wvirtual-move-assign)
+
+/// Warn if a variable length array is used
+I(-Wvla)
+
+/// Warn when a register variable is declared volatile
+E(-Wvolatile-register-var)
+
+/// In C++, nonzero means warn about deprecated
+/// conversion from string literals to 'char *'. In
+/// C, similar warning, except that the conversion is
+/// of course not deprecated by the ISO C standard.
+E(-Wwrite-strings)
+
+/// Warn when a literal '0' is used as null
+/// pointer
+XG47(-Wzero-as-null-pointer-constant)
+
+
+// clean up after myself
+#undef P
+
+#undef I
+#undef W
+#undef E
+#undef X
+
+#undef IC
+#undef WC
+#undef EC
+#undef XC
+
+#undef IG
+#undef WG
+#undef EG
+#undef XG
+
+#undef IG47
+#undef WG47
+#undef EG47
+#undef XG47
+
+#undef IG48
+#undef WG48
+#undef EG48
+#undef XG48
+
+#undef I47
+#undef W47
+#undef E47
+#undef X47
+
+#undef I48
+#undef W48
+#undef E48
+#undef X48
diff --git a/src/webserver/GNUmakefile b/src/webserver/GNUmakefile
deleted file mode 100644
index 0520440..0000000
--- a/src/webserver/GNUmakefile
+++ /dev/null
@@ -1,7 +0,0 @@
-.SUFFIXES:
-all:
- ${MAKE} -C ../.. webserver
-clean:
- rm -r ../../obj/webserver/
-%::
- ${MAKE} -C ../.. obj/webserver/$@
diff --git a/src/webserver/doc/API.txt b/src/webserver/doc/API.txt
deleted file mode 100644
index c80f7bd..0000000
--- a/src/webserver/doc/API.txt
+++ /dev/null
@@ -1,50 +0,0 @@
-Here's the webserver API, so you can work on the webserver.
-
-My personal goal is to make this interface simple, so that coding it
-will be like coding in some scripting language...
-
-
-
-char *get_param(char in_string[500], char swhat[500]);
-
-This function simply returns various data from the query string.
- *Pass get_param NOTHING longer than 500 in length!
-
- What do I pass where in_string is?
- The query string.
-
- What do I pass where swhat is?
- One of two things...
- Either 0 for the path of the 'page'
- or you can pass it the param you wish to lookup.
-
-
-
-
-
-
-char *get_query(char *inquery);
-
-This function simply returns a query string from the raw server request.
-This is used once in main, I doubt you'll need it.
-
-
-
-
-
-void web_send(int sockin, char *in_data);
-
-Super easy way of sending data to a webpage!
-Simply put in the socket name and then the data.
-
- Ex:
- web_send(socket, "I like cheese!\n");
-
-
-
-
-char *html_header(char* title);
-Easy way to print the eAthena header for the server.
-
- Ex:
- web_send(sockethere, html_header("About"));
diff --git a/src/webserver/doc/README b/src/webserver/doc/README
deleted file mode 100644
index 0e94ff2..0000000
--- a/src/webserver/doc/README
+++ /dev/null
@@ -1,11 +0,0 @@
-This readme is intended for the programmers of eAthena.
-
-This webserver's apis are in API.txt.
-
-To make this simple, generate.c should handle most of the work this sever does
-in terms of what people see.
-
-When a request is made the server shoots it off to generate.c.
-
-You are welcome to create more functions used by generate.c to generate pages
-though, so don't feel limited by that one file.
diff --git a/src/webserver/generate.cpp b/src/webserver/generate.cpp
deleted file mode 100644
index 1fed224..0000000
--- a/src/webserver/generate.cpp
+++ /dev/null
@@ -1,35 +0,0 @@
-
-void generate_page (char password[25], int sock_in, char *query, char *ip)
-{
- char *page = get_param (query, 0);
- char *ppass = get_param (query, "password");
-
- if ((ppass == 0) || (strcmp (password, ppass) != 0))
- {
- web_send (sock_in, html_header ("Enter your password"));
- web_send (sock_in,
- "<H1>NOT LOGGED IN!</H1><form action=\"/\" method=\"GET\">\n");
- web_send (sock_in,
- "Enter your password:<br>\n<input type=\"text\" name=\"password\">\n");
- web_send (sock_in, "<input type=\"submit\" value=\"Login\">\n");
- }
- else
- {
-
- //To make this simple, we will have a bunch of if statements
- //that then shoot out data off into functions.
-
- //The 'index'
- if (strcmp (page, "/") == 0)
- generate_notdone (sock_in, query, ip);
-
- //About page:
- if (strcmp (page, "/about.html") == 0)
- generate_about (sock_in, query, ip);
-
- //Test page:
- if (strcmp (page, "/testing/") == 0)
- generate_sample (sock_in, query, ip);
-
- }
-}
diff --git a/src/webserver/htmlstyle.cpp b/src/webserver/htmlstyle.cpp
deleted file mode 100644
index 3007a24..0000000
--- a/src/webserver/htmlstyle.cpp
+++ /dev/null
@@ -1,45 +0,0 @@
-char output[10000];
-
-char *html_header (char *title)
-{
- memset (output, 0x0, 10000);
- char *text =
- "<body text=\"#000000\" bgcolor=\"#939393\" link=\"#0033FF\">\n"
- "<br><table width=\"92%\" cellspacing=\"1\" cellpadding=\"0\" border=\"0\"\n"
- "align=\"center\" class=\"bordercolor\"><tbody><tr><td class=\"bordercolor\" width=\"100%\">\n"
- "<table bgcolor=\"#ffffff\" width=\"100%\" cellspacing=\"0\" cellpadding=\"0\">\n"
- "<tbody><tr><td><table border=\"0\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" bgcolor=\"#ffffff\">\n"
- "<tbody><tr><img src=\"http://eathena.sourceforge.net/athena.jpg\" alt=\"Athena\">\n"
- "<td bgcolor=\"#ffffff\"></td></tr></tbody></table></td></tr></tbody></table>\n"
- "</td></tr><tr align=\"left\"><td class=\"bordercolor\"><table bgcolor=\"#c6c6c6\" width=\"100%\" cellspacing=\"0\"\n"
- "cellpadding=\"0\" style=\"text-align: left; margin-right: auto; margin-left: 0px;\">\n";
- "<tbody><tr><td width=\"100%\" align=\"center\"><table border=\"0\" width=\"100%\" cellpadding=\"3\"\n"
- "cellspacing=\"0\" bgcolor=\"#c6c6c6\" align=\"center\"><tbody><tr>"
- "<td valign=\"middle\" bgcolor=\"#c6c6c6\" align=\"center\"><a href=\"/cgi-bin/forum/YaBB.cgi\">"
- "<span style=\"text-decoration: underline;\"><span style=\"font-weight: bold;\">\n"
- "To the Forum</span></span></a><br></td></tr></tbody></table></td></tr></tbody>\n"
- "</table></td></tr><tr><td class=\"bordercolor\" align=\"center\">\n"
- "<table bgcolor=\"#ffffff\" width=\"100%\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\">\n"
- "<tbody><tr><td width=\"100%\" align=\"center\"><table border=\"0\" width=\"100%\" cellpadding=\"5\"\n"
- "cellspacing=\"0\" bgcolor=\"#ffffff\" align=\"center\"><tbody><tr>\n"
- "<td valign=\"middle\" bgcolor=\"#ffffff\" align=\"center\"><font size=\"2\" color=\"#6e94b7\">\n"
- "<b>Athena</b> &laquo; Portal &raquo;</font></td></tr></tbody></table></td></tr></tbody>"
- "</table></td></tr></tbody></table>\n";
-
- sprintf (output, "<title>%s</title>\n%s\n", title, text);
-
- return output;
-}
-
-char *html_start_form (char *location, char *action)
-{
- memset (output, 0x0, 10000);
- sprintf (output, "<form action=\"%s\" method=\"%s\">", location, action);
- return output;
-
-}
-
-char *html_end_forum (void)
-{
- return "</form>";
-}
diff --git a/src/webserver/logs.cpp b/src/webserver/logs.cpp
deleted file mode 100644
index 67bf55e..0000000
--- a/src/webserver/logs.cpp
+++ /dev/null
@@ -1,8 +0,0 @@
-#include <time.h>
-
-void log_visit (char *query, char *ip)
-{
- time_t timer;
- timer = time (NULL);
- printf ("%s - \"%s\" - %s", ip, query, asctime (localtime (&timer)));
-}
diff --git a/src/webserver/main.cpp b/src/webserver/main.cpp
deleted file mode 100644
index 0e227d3..0000000
--- a/src/webserver/main.cpp
+++ /dev/null
@@ -1,145 +0,0 @@
-/***************************************************************************
- description
- -------------------
- author : (C) 2004 by Michael J. Flickinger
- email : mjflick@cpan.org
-
- ***************************************************************************/
-
-/***************************************************************************
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- ***************************************************************************/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <errno.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <sys/wait.h>
-#include <signal.h>
-
-#define BLOG 10
-
-char *header = "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n";
-char recvin[500], password[25];
-int s_port;
-
-void sigchld_handler (int s)
-{
- while (wait (NULL) > 0);
-}
-
-int main (int argc, char **argv)
-{
- if (argc < 3)
- {
- printf ("eAthena Web Server\n");
- printf ("usage: %s [password] [port]\n", argv[0]);
- exit (0);
- }
-
- s_port = atoi (argv[2]);
-
- if ((s_port < 1) || (s_port > 65534))
- {
- printf ("Error: The port you choose is not valid port.\n");
- exit (0);
- }
-
- if (strlen (argv[1]) > 25)
- {
- printf ("Error: Your password is too long.\n");
- printf ("It must be shorter than 25 characters.\n");
- exit (0);
- }
-
- memset (password, 0x0, 25);
- memcpy (password, argv[1], strlen (argv[1]));
-
- int sockfd, new_fd;
- struct sockaddr_in my_addr;
- struct sockaddr_in their_addr;
- int sin_size;
-
- struct sigaction sa;
-
- int yes = 1;
-
- if ((sockfd = socket (AF_INET, SOCK_STREAM, 0)) == -1)
- {
- perror ("Darn, this is broken.");
- exit (0);
- }
-
- if (setsockopt (sockfd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof (int)) ==
- -1)
- {
- perror ("Error... :-(");
- }
-
- //Now we know we have a working socket. :-)
-
- my_addr.sin_family = AF_INET;
- my_addr.sin_port = htons (s_port);
- my_addr.sin_addr.s_addr = INADDR_ANY;
- memset (&(my_addr.sin_zero), '\0', 8);
-
- if (bind (sockfd, (struct sockaddr *) &my_addr, sizeof (struct sockaddr))
- == -1)
- {
- perror ("can not bind to this port");
- exit (0);
- }
-
- if (listen (sockfd, BLOG) == -1)
- {
- perror ("can not listen on port");
- exit (0);
- }
-
- sa.sa_handler = sigchld_handler;
-
- sigemptyset (&sa.sa_mask);
- sa.sa_flags = SA_RESTART;
-
- if (sigaction (SIGCHLD, &sa, NULL) == -1)
- {
- perror ("sigaction sucks");
- exit (0);
- }
-
- printf ("The eAthena webserver is up and listening on port %i.\n",
- s_port);
-
- while (1)
- {
- sin_size = sizeof (struct sockaddr_in);
- new_fd = accept (sockfd, (struct sockaddr *) &their_addr, &sin_size);
-
- if (!fork ())
- {
- close (sockfd);
- memset (recvin, 0x0, 500);
- recv (new_fd, recvin, 500, 0);
- send (new_fd, header, strlen (header), 0);
- generate_page (password, new_fd, get_query (recvin),
- inet_ntoa (their_addr.sin_addr));
- log_visit (get_query (recvin), inet_ntoa (their_addr.sin_addr));
-
- close (new_fd);
- exit (0);
- }
- close (new_fd);
- }
-
- return 0;
-}
diff --git a/src/webserver/pages/about.cpp b/src/webserver/pages/about.cpp
deleted file mode 100644
index b548da9..0000000
--- a/src/webserver/pages/about.cpp
+++ /dev/null
@@ -1,6 +0,0 @@
-void generate_about (int sock_in, char *query, char *ip)
-{
-//printf("%s", html_header("About"));
- web_send (sock_in, html_header ("About"));
- web_send (sock_in, "<center>eAthena Web Server!</center>\n");
-}
diff --git a/src/webserver/pages/notdone.cpp b/src/webserver/pages/notdone.cpp
deleted file mode 100644
index 1fcd44b..0000000
--- a/src/webserver/pages/notdone.cpp
+++ /dev/null
@@ -1,6 +0,0 @@
-void generate_notdone (int sock_in, char *query, char *ip)
-{
- web_send (sock_in, "<title>Not here!</title>\n");
- web_send (sock_in,
- "<h2><center>This page/feature is not done yet.</center>\n</h2>");
-}
diff --git a/src/webserver/pages/sample.cpp b/src/webserver/pages/sample.cpp
deleted file mode 100644
index 6a33dc0..0000000
--- a/src/webserver/pages/sample.cpp
+++ /dev/null
@@ -1,22 +0,0 @@
-
-void generate_sample (int sock_in, char *query, char *ip)
-{
-
- char *name = get_param (query, "name");
-
- web_send (sock_in, "<title>SAMPLE</title>\n");
-
- //If a name was not entered...
- if (name == '\0')
- {
- web_send (sock_in, "<form action=\"/testing/\" method=\"GET\">\n");
- web_send (sock_in, "<input type=\"text\" name=\"name\">\n");
- web_send (sock_in, "<input type=\"submit\">\n");
- }
- else
- {
- web_send (sock_in, "Your name is: ");
- web_send (sock_in, get_param (query, "name"));
- }
- printf ("OK!\n");
-}
diff --git a/src/webserver/parse.cpp b/src/webserver/parse.cpp
deleted file mode 100644
index 66ef43b..0000000
--- a/src/webserver/parse.cpp
+++ /dev/null
@@ -1,132 +0,0 @@
-#include <stdlib.h>
-
-char filtered_query[2000];
-char rdata[500];
-char param_n[500];
-char param_d[500];
-
-char *get_query (char *inquery)
-{
- memset (filtered_query, 0x0, 2000);
- sscanf (inquery, "GET %s %[$]", filtered_query);
- return (filtered_query);
-}
-
-void web_send (int sockin, char *in_data)
-{
- send (sockin, in_data, strlen (in_data), 0);
-}
-
-//THIS IS BAD CODE BE CAREFULL WITH IT!
-//Watch out for buffer overflow...
-//When using please make sure to check the string size.
-
-//Also note:
-//I take no pride in this code, it is a really bad way of doing this...
-char *get_param (char in_string[500], char swhat[500])
-{
- int i = 0;
- int marker, iswitch, pint, dint;
- char flux[500];
- memset (flux, 0x0, 500);
-
- //Get the path of out "page"
- if (swhat == 0)
- {
- //while i is not equal to array size
- while (i != 500)
- {
- //if there is a question mark, halt!
- if (in_string[i] == '?')
- {
- i = 499;
- }
- else
- rdata[i] = in_string[i];
-
- i++;
- }
- return rdata;
- }
- else //so, we want a param...
- {
- //calculate where param begins
- while (i != 500)
- {
- if (in_string[i] == '?')
- {
- marker = i + 1;
- i = 499;
- }
- i++;
- }
-
- i = 0;
-
- //keep morons from trying to crash this
- if ((marker > 500) || (marker < 1))
- marker = 500;
-
- while (marker != 500)
- {
- if ((in_string[marker] != '&') && (in_string[marker] != '\0'))
- {
- flux[i] = in_string[marker];
- i++;
- }
- else
- {
-
- //we have a param, now we must dig through it
-
- //clear temp vars
- memset (param_n, 0x0, 500);
- memset (param_d, 0x0, 500);
- iswitch = 0;
- pint = 0;
- dint = 0;
- i = 0;
-
- //split result into param_n and param_d
- while (i != 500)
- {
- if ((flux[i] != '=') && (flux[i] != '\0'))
- {
- if (iswitch == 0)
- {
- param_n[pint] = flux[i];
- pint++;
- }
- else
- {
- param_d[dint] = flux[i];
- dint++;
- }
- }
- else
- {
- iswitch = 1;
- }
- if (flux[i] == '\0')
- i = 499;
-
- i++;
- }
-
- if (strcmp (param_n, swhat) == 0)
- {
- return param_d;
- }
-
- i = 0;
- }
-
- if (in_string[marker] == '\0')
- {
- marker = 499;
- }
- marker++;
- }
- return 0;
- }
-}
diff --git a/warnings b/warnings
deleted file mode 100644
index b9ff330..0000000
--- a/warnings
+++ /dev/null
@@ -1,27 +0,0 @@
--Werror=all
--Werror=implicit-function-declaration
--Wextra
--Werror=write-strings
--Wunused
--Wshadow
--Werror=strict-prototypes
--Werror=old-style-definition
--Werror=missing-declarations
--Wvla
--Wstack-protector
--Wno-conversion
--Wlogical-op
--Wformat=2
--Winit-self
--Wmissing-include-dirs
--Wsuggest-attribute=pure
--Wsuggest-attribute=const
--Wsuggest-attribute=noreturn
--Wtrampolines
--Wfloat-equal
--Wmissing-format-attribute
--Werror=redundant-decls
--Wno-sign-compare
-
--Wno-switch
--Wno-format-zero-length