From 196c1c0bffa8bb594ff0a7442748030f47cc9c58 Mon Sep 17 00:00:00 2001 From: Yohann Ferreira Date: Sun, 14 Nov 2010 13:18:14 +0100 Subject: Renamed .hpp files into .h for consistency. Also added an header to the autoattack.{h,cpp} files. Big but trivial fix. --- src/CMakeLists.txt | 136 +++++----- src/account-server/account.cpp | 2 +- src/account-server/account.h | 215 +++++++++++++++ src/account-server/account.hpp | 215 --------------- src/account-server/accountclient.cpp | 2 +- src/account-server/accountclient.h | 77 ++++++ src/account-server/accountclient.hpp | 77 ------ src/account-server/accounthandler.cpp | 36 +-- src/account-server/accounthandler.h | 50 ++++ src/account-server/accounthandler.hpp | 50 ---- src/account-server/character.cpp | 4 +- src/account-server/character.h | 275 +++++++++++++++++++ src/account-server/character.hpp | 275 ------------------- src/account-server/main-account.cpp | 26 +- src/account-server/serverhandler.cpp | 28 +- src/account-server/serverhandler.h | 76 ++++++ src/account-server/serverhandler.hpp | 76 ------ src/account-server/storage.cpp | 14 +- src/account-server/storage.h | 152 +++++++++++ src/account-server/storage.hpp | 152 ----------- src/chat-server/chatchannel.cpp | 4 +- src/chat-server/chatchannel.h | 151 +++++++++++ src/chat-server/chatchannel.hpp | 151 ----------- src/chat-server/chatchannelmanager.cpp | 12 +- src/chat-server/chatchannelmanager.h | 131 +++++++++ src/chat-server/chatchannelmanager.hpp | 131 --------- src/chat-server/chatclient.h | 60 +++++ src/chat-server/chatclient.hpp | 60 ----- src/chat-server/chathandler.cpp | 24 +- src/chat-server/chathandler.h | 343 ++++++++++++++++++++++++ src/chat-server/chathandler.hpp | 343 ------------------------ src/chat-server/guild.cpp | 2 +- src/chat-server/guild.h | 149 +++++++++++ src/chat-server/guild.hpp | 149 ----------- src/chat-server/guildhandler.cpp | 24 +- src/chat-server/guildmanager.cpp | 10 +- src/chat-server/guildmanager.h | 119 +++++++++ src/chat-server/guildmanager.hpp | 119 --------- src/chat-server/party.cpp | 2 +- src/chat-server/party.h | 63 +++++ src/chat-server/party.hpp | 63 ----- src/chat-server/partyhandler.cpp | 14 +- src/chat-server/post.cpp | 7 +- src/chat-server/post.h | 185 +++++++++++++ src/chat-server/post.hpp | 185 ------------- src/common/configuration.cpp | 6 +- src/common/configuration.h | 64 +++++ src/common/configuration.hpp | 64 ----- src/common/inventorydata.h | 61 +++++ src/common/inventorydata.hpp | 61 ----- src/common/permissionmanager.cpp | 8 +- src/common/permissionmanager.h | 71 +++++ src/common/permissionmanager.hpp | 71 ----- src/common/resourcemanager.cpp | 4 +- src/common/resourcemanager.h | 72 +++++ src/common/resourcemanager.hpp | 72 ----- src/common/transaction.h | 67 +++++ src/common/transaction.hpp | 67 ----- src/dal/mysqldataprovider.h | 2 +- src/dal/sqlitedataprovider.h | 2 +- src/game-server/accountconnection.cpp | 32 +-- src/game-server/accountconnection.h | 179 +++++++++++++ src/game-server/accountconnection.hpp | 179 ------------- src/game-server/actor.cpp | 6 +- src/game-server/actor.h | 145 ++++++++++ src/game-server/actor.hpp | 145 ---------- src/game-server/attribute.cpp | 4 +- src/game-server/attribute.h | 184 +++++++++++++ src/game-server/attribute.hpp | 184 ------------- src/game-server/attributemanager.cpp | 8 +- src/game-server/attributemanager.h | 83 ++++++ src/game-server/attributemanager.hpp | 83 ------ src/game-server/autoattack.cpp | 22 +- src/game-server/autoattack.h | 120 +++++++++ src/game-server/autoattack.hpp | 100 ------- src/game-server/being.cpp | 22 +- src/game-server/being.h | 373 ++++++++++++++++++++++++++ src/game-server/being.hpp | 373 -------------------------- src/game-server/buysell.cpp | 14 +- src/game-server/buysell.h | 86 ++++++ src/game-server/buysell.hpp | 86 ------ src/game-server/character.cpp | 38 +-- src/game-server/character.h | 467 +++++++++++++++++++++++++++++++++ src/game-server/character.hpp | 467 --------------------------------- src/game-server/collisiondetection.cpp | 2 +- src/game-server/collisiondetection.h | 55 ++++ src/game-server/collisiondetection.hpp | 55 ---- src/game-server/command.cpp | 20 +- src/game-server/commandhandler.cpp | 34 +-- src/game-server/commandhandler.h | 36 +++ src/game-server/commandhandler.hpp | 36 --- src/game-server/effect.cpp | 6 +- src/game-server/effect.h | 88 +++++++ src/game-server/effect.hpp | 88 ------- src/game-server/eventlistener.h | 102 +++++++ src/game-server/eventlistener.hpp | 102 ------- src/game-server/gamehandler.cpp | 42 +-- src/game-server/gamehandler.h | 157 +++++++++++ src/game-server/gamehandler.hpp | 157 ----------- src/game-server/inventory.cpp | 10 +- src/game-server/inventory.h | 210 +++++++++++++++ src/game-server/inventory.hpp | 210 --------------- src/game-server/item.cpp | 16 +- src/game-server/item.h | 273 +++++++++++++++++++ src/game-server/item.hpp | 273 ------------------- src/game-server/itemmanager.cpp | 14 +- src/game-server/itemmanager.h | 92 +++++++ src/game-server/itemmanager.hpp | 92 ------- src/game-server/main-game.cpp | 36 +-- src/game-server/map.cpp | 2 +- src/game-server/map.h | 216 +++++++++++++++ src/game-server/map.hpp | 216 --------------- src/game-server/mapcomposite.cpp | 10 +- src/game-server/mapcomposite.h | 347 ++++++++++++++++++++++++ src/game-server/mapcomposite.hpp | 347 ------------------------ src/game-server/mapmanager.cpp | 12 +- src/game-server/mapmanager.h | 68 +++++ src/game-server/mapmanager.hpp | 68 ----- src/game-server/mapreader.cpp | 26 +- src/game-server/mapreader.h | 74 ++++++ src/game-server/mapreader.hpp | 74 ------ src/game-server/monster.cpp | 24 +- src/game-server/monster.h | 351 +++++++++++++++++++++++++ src/game-server/monster.hpp | 351 ------------------------- src/game-server/monstermanager.cpp | 12 +- src/game-server/monstermanager.h | 62 +++++ src/game-server/monstermanager.hpp | 62 ----- src/game-server/npc.cpp | 6 +- src/game-server/npc.h | 90 +++++++ src/game-server/npc.hpp | 90 ------- src/game-server/postman.h | 78 ++++++ src/game-server/postman.hpp | 78 ------ src/game-server/quest.cpp | 8 +- src/game-server/quest.h | 60 +++++ src/game-server/quest.hpp | 60 ----- src/game-server/skillmanager.cpp | 8 +- src/game-server/skillmanager.h | 48 ++++ src/game-server/skillmanager.hpp | 48 ---- src/game-server/spawnarea.cpp | 8 +- src/game-server/spawnarea.h | 60 +++++ src/game-server/spawnarea.hpp | 60 ----- src/game-server/state.cpp | 34 +-- src/game-server/state.h | 108 ++++++++ src/game-server/state.hpp | 108 -------- src/game-server/statuseffect.cpp | 6 +- src/game-server/statuseffect.h | 46 ++++ src/game-server/statuseffect.hpp | 46 ---- src/game-server/statusmanager.cpp | 10 +- src/game-server/statusmanager.h | 51 ++++ src/game-server/statusmanager.hpp | 51 ---- src/game-server/thing.cpp | 4 +- src/game-server/thing.h | 121 +++++++++ src/game-server/thing.hpp | 121 --------- src/game-server/trade.cpp | 10 +- src/game-server/trade.h | 107 ++++++++ src/game-server/trade.hpp | 107 -------- src/game-server/trigger.cpp | 10 +- src/game-server/trigger.h | 82 ++++++ src/game-server/trigger.hpp | 82 ------ src/net/bandwidth.cpp | 4 +- src/net/bandwidth.h | 53 ++++ src/net/bandwidth.hpp | 53 ---- src/net/connection.cpp | 8 +- src/net/connection.h | 78 ++++++ src/net/connection.hpp | 78 ------ src/net/connectionhandler.cpp | 12 +- src/net/connectionhandler.h | 121 +++++++++ src/net/connectionhandler.hpp | 121 --------- src/net/messagein.cpp | 2 +- src/net/messagein.h | 87 ++++++ src/net/messagein.hpp | 87 ------ src/net/messageout.cpp | 2 +- src/net/messageout.h | 107 ++++++++ src/net/messageout.hpp | 107 -------- src/net/netcomputer.cpp | 8 +- src/net/netcomputer.h | 96 +++++++ src/net/netcomputer.hpp | 96 ------- src/scripting/lua.cpp | 46 ++-- src/scripting/luascript.cpp | 4 +- src/scripting/luascript.h | 96 +++++++ src/scripting/luascript.hpp | 96 ------- src/scripting/luautil.cpp | 6 +- src/scripting/luautil.h | 126 +++++++++ src/scripting/luautil.hpp | 126 --------- src/scripting/script.cpp | 6 +- src/scripting/script.h | 170 ++++++++++++ src/scripting/script.hpp | 170 ------------ src/serialize/characterdata.h | 215 +++++++++++++++ src/serialize/characterdata.hpp | 215 --------------- src/utils/logger.cpp | 4 +- src/utils/processorutils.cpp | 2 +- src/utils/processorutils.h | 50 ++++ src/utils/processorutils.hpp | 50 ---- src/utils/speedconv.cpp | 2 +- src/utils/speedconv.h | 44 ++++ src/utils/speedconv.hpp | 44 ---- src/utils/string.cpp | 2 +- src/utils/string.h | 86 ++++++ src/utils/string.hpp | 86 ------ src/utils/stringfilter.cpp | 2 +- src/utils/tokencollector.cpp | 2 +- src/utils/tokencollector.h | 138 ++++++++++ src/utils/tokencollector.hpp | 138 ---------- src/utils/tokendispenser.cpp | 2 +- src/utils/tokendispenser.h | 45 ++++ src/utils/tokendispenser.hpp | 45 ---- src/utils/xml.cpp | 6 +- src/utils/xml.h | 107 ++++++++ src/utils/xml.hpp | 107 -------- src/utils/zlib.cpp | 2 +- src/utils/zlib.h | 32 +++ src/utils/zlib.hpp | 32 --- 212 files changed, 9164 insertions(+), 9125 deletions(-) create mode 100644 src/account-server/account.h delete mode 100644 src/account-server/account.hpp create mode 100644 src/account-server/accountclient.h delete mode 100644 src/account-server/accountclient.hpp create mode 100644 src/account-server/accounthandler.h delete mode 100644 src/account-server/accounthandler.hpp create mode 100644 src/account-server/character.h delete mode 100644 src/account-server/character.hpp create mode 100644 src/account-server/serverhandler.h delete mode 100644 src/account-server/serverhandler.hpp create mode 100644 src/account-server/storage.h delete mode 100644 src/account-server/storage.hpp create mode 100644 src/chat-server/chatchannel.h delete mode 100644 src/chat-server/chatchannel.hpp create mode 100644 src/chat-server/chatchannelmanager.h delete mode 100644 src/chat-server/chatchannelmanager.hpp create mode 100644 src/chat-server/chatclient.h delete mode 100644 src/chat-server/chatclient.hpp create mode 100644 src/chat-server/chathandler.h delete mode 100644 src/chat-server/chathandler.hpp create mode 100644 src/chat-server/guild.h delete mode 100644 src/chat-server/guild.hpp create mode 100644 src/chat-server/guildmanager.h delete mode 100644 src/chat-server/guildmanager.hpp create mode 100644 src/chat-server/party.h delete mode 100644 src/chat-server/party.hpp create mode 100644 src/chat-server/post.h delete mode 100644 src/chat-server/post.hpp create mode 100644 src/common/configuration.h delete mode 100644 src/common/configuration.hpp create mode 100644 src/common/inventorydata.h delete mode 100644 src/common/inventorydata.hpp create mode 100644 src/common/permissionmanager.h delete mode 100644 src/common/permissionmanager.hpp create mode 100644 src/common/resourcemanager.h delete mode 100644 src/common/resourcemanager.hpp create mode 100644 src/common/transaction.h delete mode 100644 src/common/transaction.hpp create mode 100644 src/game-server/accountconnection.h delete mode 100644 src/game-server/accountconnection.hpp create mode 100644 src/game-server/actor.h delete mode 100644 src/game-server/actor.hpp create mode 100644 src/game-server/attribute.h delete mode 100644 src/game-server/attribute.hpp create mode 100644 src/game-server/attributemanager.h delete mode 100644 src/game-server/attributemanager.hpp create mode 100644 src/game-server/autoattack.h delete mode 100644 src/game-server/autoattack.hpp create mode 100644 src/game-server/being.h delete mode 100644 src/game-server/being.hpp create mode 100644 src/game-server/buysell.h delete mode 100644 src/game-server/buysell.hpp create mode 100644 src/game-server/character.h delete mode 100644 src/game-server/character.hpp create mode 100644 src/game-server/collisiondetection.h delete mode 100644 src/game-server/collisiondetection.hpp create mode 100644 src/game-server/commandhandler.h delete mode 100644 src/game-server/commandhandler.hpp create mode 100644 src/game-server/effect.h delete mode 100644 src/game-server/effect.hpp create mode 100644 src/game-server/eventlistener.h delete mode 100644 src/game-server/eventlistener.hpp create mode 100644 src/game-server/gamehandler.h delete mode 100644 src/game-server/gamehandler.hpp create mode 100644 src/game-server/inventory.h delete mode 100644 src/game-server/inventory.hpp create mode 100644 src/game-server/item.h delete mode 100644 src/game-server/item.hpp create mode 100644 src/game-server/itemmanager.h delete mode 100644 src/game-server/itemmanager.hpp create mode 100644 src/game-server/map.h delete mode 100644 src/game-server/map.hpp create mode 100644 src/game-server/mapcomposite.h delete mode 100644 src/game-server/mapcomposite.hpp create mode 100644 src/game-server/mapmanager.h delete mode 100644 src/game-server/mapmanager.hpp create mode 100644 src/game-server/mapreader.h delete mode 100644 src/game-server/mapreader.hpp create mode 100644 src/game-server/monster.h delete mode 100644 src/game-server/monster.hpp create mode 100644 src/game-server/monstermanager.h delete mode 100644 src/game-server/monstermanager.hpp create mode 100644 src/game-server/npc.h delete mode 100644 src/game-server/npc.hpp create mode 100644 src/game-server/postman.h delete mode 100644 src/game-server/postman.hpp create mode 100644 src/game-server/quest.h delete mode 100644 src/game-server/quest.hpp create mode 100644 src/game-server/skillmanager.h delete mode 100644 src/game-server/skillmanager.hpp create mode 100644 src/game-server/spawnarea.h delete mode 100644 src/game-server/spawnarea.hpp create mode 100644 src/game-server/state.h delete mode 100644 src/game-server/state.hpp create mode 100644 src/game-server/statuseffect.h delete mode 100644 src/game-server/statuseffect.hpp create mode 100644 src/game-server/statusmanager.h delete mode 100644 src/game-server/statusmanager.hpp create mode 100644 src/game-server/thing.h delete mode 100644 src/game-server/thing.hpp create mode 100644 src/game-server/trade.h delete mode 100644 src/game-server/trade.hpp create mode 100644 src/game-server/trigger.h delete mode 100644 src/game-server/trigger.hpp create mode 100644 src/net/bandwidth.h delete mode 100644 src/net/bandwidth.hpp create mode 100644 src/net/connection.h delete mode 100644 src/net/connection.hpp create mode 100644 src/net/connectionhandler.h delete mode 100644 src/net/connectionhandler.hpp create mode 100644 src/net/messagein.h delete mode 100644 src/net/messagein.hpp create mode 100644 src/net/messageout.h delete mode 100644 src/net/messageout.hpp create mode 100644 src/net/netcomputer.h delete mode 100644 src/net/netcomputer.hpp create mode 100644 src/scripting/luascript.h delete mode 100644 src/scripting/luascript.hpp create mode 100644 src/scripting/luautil.h delete mode 100644 src/scripting/luautil.hpp create mode 100644 src/scripting/script.h delete mode 100644 src/scripting/script.hpp create mode 100644 src/serialize/characterdata.h delete mode 100644 src/serialize/characterdata.hpp create mode 100644 src/utils/processorutils.h delete mode 100644 src/utils/processorutils.hpp create mode 100644 src/utils/speedconv.h delete mode 100644 src/utils/speedconv.hpp create mode 100644 src/utils/string.h delete mode 100644 src/utils/string.hpp create mode 100644 src/utils/tokencollector.h delete mode 100644 src/utils/tokencollector.hpp create mode 100644 src/utils/tokendispenser.h delete mode 100644 src/utils/tokendispenser.hpp create mode 100644 src/utils/xml.h delete mode 100644 src/utils/xml.hpp create mode 100644 src/utils/zlib.h delete mode 100644 src/utils/zlib.hpp (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ae565801..88cbf4ba 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -103,73 +103,73 @@ SET(SRCS defines.h protocol.h point.h - common/configuration.hpp + common/configuration.h common/configuration.cpp - common/inventorydata.hpp - common/resourcemanager.hpp + common/inventorydata.h + common/resourcemanager.h common/resourcemanager.cpp - net/bandwidth.hpp + net/bandwidth.h net/bandwidth.cpp - net/connection.hpp + net/connection.h net/connection.cpp - net/connectionhandler.hpp + net/connectionhandler.h net/connectionhandler.cpp - net/messagein.hpp + net/messagein.h net/messagein.cpp - net/messageout.hpp + net/messageout.h net/messageout.cpp - net/netcomputer.hpp + net/netcomputer.h net/netcomputer.cpp - serialize/characterdata.hpp + serialize/characterdata.h utils/logger.h utils/logger.cpp - utils/processorutils.hpp + utils/processorutils.h utils/processorutils.cpp - utils/string.hpp + utils/string.h utils/string.cpp utils/stringfilter.h utils/stringfilter.cpp utils/timer.h utils/timer.cpp - utils/tokencollector.hpp + utils/tokencollector.h utils/tokencollector.cpp - utils/tokendispenser.hpp + utils/tokendispenser.h utils/tokendispenser.cpp - utils/xml.hpp + utils/xml.h utils/xml.cpp ) SET(SRCS_MANASERVACCOUNT account-server/main-account.cpp - account-server/account.hpp + account-server/account.h account-server/account.cpp - account-server/accountclient.hpp + account-server/accountclient.h account-server/accountclient.cpp - account-server/accounthandler.hpp + account-server/accounthandler.h account-server/accounthandler.cpp - account-server/character.hpp + account-server/character.h account-server/character.cpp - account-server/serverhandler.hpp + account-server/serverhandler.h account-server/serverhandler.cpp - account-server/storage.hpp + account-server/storage.h account-server/storage.cpp - chat-server/chathandler.hpp + chat-server/chathandler.h chat-server/chathandler.cpp - chat-server/chatclient.hpp - chat-server/chatchannel.hpp + chat-server/chatclient.h + chat-server/chatchannel.h chat-server/chatchannel.cpp - chat-server/chatchannelmanager.hpp + chat-server/chatchannelmanager.h chat-server/chatchannelmanager.cpp - chat-server/guild.hpp + chat-server/guild.h chat-server/guild.cpp chat-server/guildhandler.cpp - chat-server/guildmanager.hpp + chat-server/guildmanager.h chat-server/guildmanager.cpp chat-server/party.cpp - chat-server/party.hpp + chat-server/party.h chat-server/partyhandler.cpp chat-server/post.cpp - chat-server/post.hpp + chat-server/post.h dal/dalexcept.h dal/dataprovider.h dal/dataprovider.cpp @@ -186,82 +186,82 @@ SET(SRCS_MANASERVACCOUNT SET(SRCS_MANASERVGAME game-server/main-game.cpp - common/permissionmanager.hpp + common/permissionmanager.h common/permissionmanager.cpp - game-server/accountconnection.hpp + game-server/accountconnection.h game-server/accountconnection.cpp - game-server/actor.hpp + game-server/actor.h game-server/actor.cpp - game-server/attribute.hpp + game-server/attribute.h game-server/attribute.cpp - game-server/attributemanager.hpp + game-server/attributemanager.h game-server/attributemanager.cpp - game-server/autoattack.hpp + game-server/autoattack.h game-server/autoattack.cpp - game-server/being.hpp + game-server/being.h game-server/being.cpp - game-server/buysell.hpp + game-server/buysell.h game-server/buysell.cpp - game-server/character.hpp + game-server/character.h game-server/character.cpp - game-server/collisiondetection.hpp + game-server/collisiondetection.h game-server/collisiondetection.cpp game-server/command.cpp game-server/commandhandler.cpp - game-server/commandhandler.hpp - game-server/effect.hpp + game-server/commandhandler.h + game-server/effect.h game-server/effect.cpp - game-server/eventlistener.hpp - game-server/gamehandler.hpp + game-server/eventlistener.h + game-server/gamehandler.h game-server/gamehandler.cpp - game-server/inventory.hpp + game-server/inventory.h game-server/inventory.cpp - game-server/item.hpp + game-server/item.h game-server/item.cpp - game-server/itemmanager.hpp + game-server/itemmanager.h game-server/itemmanager.cpp - game-server/map.hpp + game-server/map.h game-server/map.cpp - game-server/mapcomposite.hpp + game-server/mapcomposite.h game-server/mapcomposite.cpp - game-server/mapmanager.hpp + game-server/mapmanager.h game-server/mapmanager.cpp - game-server/mapreader.hpp + game-server/mapreader.h game-server/mapreader.cpp - game-server/monster.hpp + game-server/monster.h game-server/monster.cpp - game-server/monstermanager.hpp + game-server/monstermanager.h game-server/monstermanager.cpp - game-server/npc.hpp + game-server/npc.h game-server/npc.cpp - game-server/postman.hpp - game-server/quest.hpp + game-server/postman.h + game-server/quest.h game-server/quest.cpp - game-server/skillmanager.hpp + game-server/skillmanager.h game-server/skillmanager.cpp - game-server/spawnarea.hpp + game-server/spawnarea.h game-server/spawnarea.cpp - game-server/state.hpp + game-server/state.h game-server/state.cpp - game-server/statuseffect.hpp + game-server/statuseffect.h game-server/statuseffect.cpp - game-server/statusmanager.hpp + game-server/statusmanager.h game-server/statusmanager.cpp - game-server/thing.hpp + game-server/thing.h game-server/thing.cpp - game-server/trade.hpp + game-server/trade.h game-server/trade.cpp - game-server/trigger.hpp + game-server/trigger.h game-server/trigger.cpp - scripting/script.hpp + scripting/script.h scripting/script.cpp utils/base64.h utils/base64.cpp utils/mathutils.h utils/mathutils.cpp - utils/speedconv.hpp + utils/speedconv.h utils/speedconv.cpp - utils/zlib.hpp + utils/zlib.h utils/zlib.cpp ) @@ -292,9 +292,9 @@ IF (ENABLE_LUA) SET(SRCS_MANASERVGAME ${SRCS_MANASERVGAME} scripting/lua.cpp scripting/luascript.cpp - scripting/luascript.hpp + scripting/luascript.h scripting/luautil.cpp - scripting/luautil.hpp) + scripting/luautil.h) ENDIF() diff --git a/src/account-server/account.cpp b/src/account-server/account.cpp index af786065..58c1f6ac 100644 --- a/src/account-server/account.cpp +++ b/src/account-server/account.cpp @@ -20,7 +20,7 @@ #include -#include "account-server/account.hpp" +#include "account-server/account.h" Account::~Account() { diff --git a/src/account-server/account.h b/src/account-server/account.h new file mode 100644 index 00000000..2847a03c --- /dev/null +++ b/src/account-server/account.h @@ -0,0 +1,215 @@ +/* + * The Mana Server + * Copyright (C) 2004-2010 The Mana World Development Team + * + * This file is part of The Mana Server. + * + * The Mana Server 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 + * any later version. + * + * The Mana Server 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 The Mana Server. If not, see . + */ + +#ifndef ACCOUNT_H +#define ACCOUNT_H + +#include +#include +#include + +#include "account-server/character.h" + +/** + * A player's account. Stores the account information as well as the + * player characters available under this account. + */ +class Account +{ + public: + /** + * Constructor. + */ + Account(int id = -1): mID(id) + {} + + /** + * Destructor. + */ + ~Account(); + + /** + * Set the user name. + * + * @param name the user name. + */ + void setName(const std::string &name) + { mName = name; } + + /** + * Get the user name. + * + * @return the user name. + */ + const std::string &getName() const + { return mName; } + + /** + * Set the user password. The password is expected to be already + * hashed with a salt. + * + * The hashing must be performed externally from this class or else + * we would end up with the password being hashed many times + * (e.g setPassword(getPassword()) would hash the password twice. + * + * @param password the user password (hashed with salt). + */ + void setPassword(const std::string &password) + { mPassword = password; } + + + /** + * Get the user password (hashed with salt). + * + * @return the user password (hashed with salt). + */ + const std::string &getPassword() const + { return mPassword; } + + + /** + * Set the user email address. The email address is expected to be + * already hashed. + * + * @param email the user email address (hashed). + */ + void setEmail(const std::string &email) + { mEmail = email; } + + + /** + * Get the user email address (hashed). + * + * @return the user email address (hashed). + */ + const std::string &getEmail() const + { return mEmail; } + + + /** + * Set the account level. + * + * @param level the new level. + */ + void setLevel(int level) + { mLevel = level; } + + /** + * Get the account level. + * + * @return the account level. + */ + int getLevel() const + { return mLevel; } + + /** + * Set the characters. + * + * @param characters a list of characters. + */ + void setCharacters(const Characters& characters); + + /** + * Adds a new character. + * + * @param character the new character. + */ + void addCharacter(Character *character); + + /** + * Removes a character from the account. + * + * @param i index of the character. + */ + void delCharacter(int i); + + /** + * Get all the characters. + * + * @return all the characters. + */ + Characters &getCharacters() + { return mCharacters; } + + /** + * Get all the characters. + * + * @return all the characters. + */ + const Characters &getCharacters() const + { return mCharacters; } + + /** + * Get account ID. + * + * @return the unique ID of the account, a negative number if none yet. + */ + int getID() const + { return mID; } + + /** + * Set account ID. + * The account shall not have any ID yet. + */ + void setID(int); + + /** + * Get the time of the account registration. + */ + time_t getRegistrationDate() const + { return mRegistrationDate; } + + /** + * Sets the time of the account registration. + * + * @param time of the account registration. + */ + void setRegistrationDate(time_t time); + + /** + * Get the time of the last login. + */ + time_t getLastLogin() const + { return mLastLogin; } + + /** + * Sets the time of the last login. + * + * @param time of the last login. + */ + void setLastLogin(time_t time); + + private: + Account(const Account &rhs); + Account &operator=(const Account &rhs); + + std::string mName; /**< User name */ + std::string mPassword; /**< User password (hashed with salt) */ + std::string mEmail; /**< User email address (hashed) */ + Characters mCharacters; /**< Character data */ + int mID; /**< Unique id */ + unsigned char mLevel; /**< Account level */ + time_t mRegistrationDate; /**< Date and time of the account registration */ + time_t mLastLogin; /**< Date and time of the last login */ +}; + +typedef std::vector< Account * > Accounts; + +#endif // ACCOUNT_H diff --git a/src/account-server/account.hpp b/src/account-server/account.hpp deleted file mode 100644 index c42ea286..00000000 --- a/src/account-server/account.hpp +++ /dev/null @@ -1,215 +0,0 @@ -/* - * The Mana Server - * Copyright (C) 2004-2010 The Mana World Development Team - * - * This file is part of The Mana Server. - * - * The Mana Server 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 - * any later version. - * - * The Mana Server 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 The Mana Server. If not, see . - */ - -#ifndef ACCOUNT_H -#define ACCOUNT_H - -#include -#include -#include - -#include "account-server/character.hpp" - -/** - * A player's account. Stores the account information as well as the - * player characters available under this account. - */ -class Account -{ - public: - /** - * Constructor. - */ - Account(int id = -1): mID(id) - {} - - /** - * Destructor. - */ - ~Account(); - - /** - * Set the user name. - * - * @param name the user name. - */ - void setName(const std::string &name) - { mName = name; } - - /** - * Get the user name. - * - * @return the user name. - */ - const std::string &getName() const - { return mName; } - - /** - * Set the user password. The password is expected to be already - * hashed with a salt. - * - * The hashing must be performed externally from this class or else - * we would end up with the password being hashed many times - * (e.g setPassword(getPassword()) would hash the password twice. - * - * @param password the user password (hashed with salt). - */ - void setPassword(const std::string &password) - { mPassword = password; } - - - /** - * Get the user password (hashed with salt). - * - * @return the user password (hashed with salt). - */ - const std::string &getPassword() const - { return mPassword; } - - - /** - * Set the user email address. The email address is expected to be - * already hashed. - * - * @param email the user email address (hashed). - */ - void setEmail(const std::string &email) - { mEmail = email; } - - - /** - * Get the user email address (hashed). - * - * @return the user email address (hashed). - */ - const std::string &getEmail() const - { return mEmail; } - - - /** - * Set the account level. - * - * @param level the new level. - */ - void setLevel(int level) - { mLevel = level; } - - /** - * Get the account level. - * - * @return the account level. - */ - int getLevel() const - { return mLevel; } - - /** - * Set the characters. - * - * @param characters a list of characters. - */ - void setCharacters(const Characters& characters); - - /** - * Adds a new character. - * - * @param character the new character. - */ - void addCharacter(Character *character); - - /** - * Removes a character from the account. - * - * @param i index of the character. - */ - void delCharacter(int i); - - /** - * Get all the characters. - * - * @return all the characters. - */ - Characters &getCharacters() - { return mCharacters; } - - /** - * Get all the characters. - * - * @return all the characters. - */ - const Characters &getCharacters() const - { return mCharacters; } - - /** - * Get account ID. - * - * @return the unique ID of the account, a negative number if none yet. - */ - int getID() const - { return mID; } - - /** - * Set account ID. - * The account shall not have any ID yet. - */ - void setID(int); - - /** - * Get the time of the account registration. - */ - time_t getRegistrationDate() const - { return mRegistrationDate; } - - /** - * Sets the time of the account registration. - * - * @param time of the account registration. - */ - void setRegistrationDate(time_t time); - - /** - * Get the time of the last login. - */ - time_t getLastLogin() const - { return mLastLogin; } - - /** - * Sets the time of the last login. - * - * @param time of the last login. - */ - void setLastLogin(time_t time); - - private: - Account(const Account &rhs); - Account &operator=(const Account &rhs); - - std::string mName; /**< User name */ - std::string mPassword; /**< User password (hashed with salt) */ - std::string mEmail; /**< User email address (hashed) */ - Characters mCharacters; /**< Character data */ - int mID; /**< Unique id */ - unsigned char mLevel; /**< Account level */ - time_t mRegistrationDate; /**< Date and time of the account registration */ - time_t mLastLogin; /**< Date and time of the last login */ -}; - -typedef std::vector< Account * > Accounts; - -#endif // ACCOUNT_H diff --git a/src/account-server/accountclient.cpp b/src/account-server/accountclient.cpp index 4eb1484d..f8134ba2 100644 --- a/src/account-server/accountclient.cpp +++ b/src/account-server/accountclient.cpp @@ -18,7 +18,7 @@ * along with The Mana Server. If not, see . */ -#include "account-server/accountclient.hpp" +#include "account-server/accountclient.h" AccountClient::AccountClient(ENetPeer *peer): NetComputer(peer), diff --git a/src/account-server/accountclient.h b/src/account-server/accountclient.h new file mode 100644 index 00000000..bdcc4b8c --- /dev/null +++ b/src/account-server/accountclient.h @@ -0,0 +1,77 @@ +/* + * The Mana Server + * Copyright (C) 2004-2010 The Mana World Development Team + * + * This file is part of The Mana Server. + * + * The Mana Server 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 + * any later version. + * + * The Mana Server 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 The Mana Server. If not, see . + */ + +#ifndef ACCOUNTCLIENT_H +#define ACCOUNTCLIENT_H + +#include + +#include "account-server/account.h" +#include "net/netcomputer.h" + +class AccountHandler; + +enum AccountClientStatus +{ + CLIENT_LOGIN = 0, + CLIENT_CONNECTED, + CLIENT_QUEUED +}; + +/** + * A connected computer with an associated account. + */ +class AccountClient : public NetComputer +{ + public: + /** + * Constructor. + */ + AccountClient(ENetPeer *peer); + + /** + * Destructor. + */ + ~AccountClient(); + + /** + * Set the account associated with the connection + */ + void setAccount(Account *acc); + + /** + * Unset the account associated with the connection + */ + void unsetAccount(); + + /** + * Get account associated with the connection. + */ + Account *getAccount() const + { return mAccount; } + + AccountClientStatus status; + + private: + /** Account associated with connection */ + Account *mAccount; +}; + +#endif diff --git a/src/account-server/accountclient.hpp b/src/account-server/accountclient.hpp deleted file mode 100644 index 15acbd41..00000000 --- a/src/account-server/accountclient.hpp +++ /dev/null @@ -1,77 +0,0 @@ -/* - * The Mana Server - * Copyright (C) 2004-2010 The Mana World Development Team - * - * This file is part of The Mana Server. - * - * The Mana Server 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 - * any later version. - * - * The Mana Server 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 The Mana Server. If not, see . - */ - -#ifndef ACCOUNTCLIENT_H -#define ACCOUNTCLIENT_H - -#include - -#include "account-server/account.hpp" -#include "net/netcomputer.hpp" - -class AccountHandler; - -enum AccountClientStatus -{ - CLIENT_LOGIN = 0, - CLIENT_CONNECTED, - CLIENT_QUEUED -}; - -/** - * A connected computer with an associated account. - */ -class AccountClient : public NetComputer -{ - public: - /** - * Constructor. - */ - AccountClient(ENetPeer *peer); - - /** - * Destructor. - */ - ~AccountClient(); - - /** - * Set the account associated with the connection - */ - void setAccount(Account *acc); - - /** - * Unset the account associated with the connection - */ - void unsetAccount(); - - /** - * Get account associated with the connection. - */ - Account *getAccount() const - { return mAccount; } - - AccountClientStatus status; - - private: - /** Account associated with connection */ - Account *mAccount; -}; - -#endif diff --git a/src/account-server/accounthandler.cpp b/src/account-server/accounthandler.cpp index d76a6b1b..e50c817f 100644 --- a/src/account-server/accounthandler.cpp +++ b/src/account-server/accounthandler.cpp @@ -18,31 +18,31 @@ * along with The Mana Server. If not, see . */ -#include "account-server/accounthandler.hpp" +#include "account-server/accounthandler.h" #include "protocol.h" #include "point.h" -#include "account-server/account.hpp" -#include "account-server/accountclient.hpp" -#include "account-server/character.hpp" -#include "account-server/storage.hpp" -#include "account-server/serverhandler.hpp" -#include "chat-server/chathandler.hpp" -#include "common/configuration.hpp" -#include "common/resourcemanager.hpp" -#include "common/transaction.hpp" -#include "net/connectionhandler.hpp" -#include "net/messagein.hpp" -#include "net/messageout.hpp" -#include "net/netcomputer.hpp" +#include "account-server/account.h" +#include "account-server/accountclient.h" +#include "account-server/character.h" +#include "account-server/storage.h" +#include "account-server/serverhandler.h" +#include "chat-server/chathandler.h" +#include "common/configuration.h" +#include "common/resourcemanager.h" +#include "common/transaction.h" +#include "net/connectionhandler.h" +#include "net/messagein.h" +#include "net/messageout.h" +#include "net/netcomputer.h" #include "utils/functors.h" #include "utils/logger.h" #include "utils/stringfilter.h" -#include "utils/tokencollector.hpp" -#include "utils/tokendispenser.hpp" +#include "utils/tokencollector.h" +#include "utils/tokendispenser.h" #include "utils/sha256.h" -#include "utils/string.hpp" -#include "utils/xml.hpp" +#include "utils/string.h" +#include "utils/xml.h" static void addUpdateHost(MessageOut *msg) { diff --git a/src/account-server/accounthandler.h b/src/account-server/accounthandler.h new file mode 100644 index 00000000..f1ffcfe2 --- /dev/null +++ b/src/account-server/accounthandler.h @@ -0,0 +1,50 @@ +/* + * The Mana Server + * Copyright (C) 2004-2010 The Mana World Development Team + * + * This file is part of The Mana Server. + * + * The Mana Server 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 + * any later version. + * + * The Mana Server 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 The Mana Server. If not, see . + */ + +#ifndef ACCOUNTHANDLER_H +#define ACCOUNTHANDLER_H + +#include + +namespace AccountClientHandler +{ + /** + * Creates a connection handler and starts listening on given port. + */ + bool initialize(const std::string &configFile, int port, + const std::string &host); + + /** + * Stops listening to messages and destroys the connection handler. + */ + void deinitialize(); + + /** + * Prepares a connection for a client coming from a game server. + */ + void prepareReconnect(const std::string &token, int accountID); + + /** + * Processes messages received by the connection handler. + */ + void process(); +} + +#endif // ACCOUNTHANDLER_H diff --git a/src/account-server/accounthandler.hpp b/src/account-server/accounthandler.hpp deleted file mode 100644 index f1ffcfe2..00000000 --- a/src/account-server/accounthandler.hpp +++ /dev/null @@ -1,50 +0,0 @@ -/* - * The Mana Server - * Copyright (C) 2004-2010 The Mana World Development Team - * - * This file is part of The Mana Server. - * - * The Mana Server 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 - * any later version. - * - * The Mana Server 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 The Mana Server. If not, see . - */ - -#ifndef ACCOUNTHANDLER_H -#define ACCOUNTHANDLER_H - -#include - -namespace AccountClientHandler -{ - /** - * Creates a connection handler and starts listening on given port. - */ - bool initialize(const std::string &configFile, int port, - const std::string &host); - - /** - * Stops listening to messages and destroys the connection handler. - */ - void deinitialize(); - - /** - * Prepares a connection for a client coming from a game server. - */ - void prepareReconnect(const std::string &token, int accountID); - - /** - * Processes messages received by the connection handler. - */ - void process(); -} - -#endif // ACCOUNTHANDLER_H diff --git a/src/account-server/character.cpp b/src/account-server/character.cpp index b6918199..48796020 100644 --- a/src/account-server/character.cpp +++ b/src/account-server/character.cpp @@ -18,9 +18,9 @@ * along with The Mana Server. If not, see . */ -#include "account-server/character.hpp" +#include "account-server/character.h" -#include "account-server/account.hpp" +#include "account-server/account.h" Character::Character(const std::string &name, int id): mName(name), diff --git a/src/account-server/character.h b/src/account-server/character.h new file mode 100644 index 00000000..e43b61a1 --- /dev/null +++ b/src/account-server/character.h @@ -0,0 +1,275 @@ +/* + * The Mana Server + * Copyright (C) 2004-2010 The Mana World Development Team + * + * This file is part of The Mana Server. + * + * The Mana Server 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 + * any later version. + * + * The Mana Server 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 The Mana Server. If not, see . + */ + +#ifndef CHARACTERDATA_H +#define CHARACTERDATA_H + +#include +#include +#include + +#include "defines.h" +#include "point.h" +#include "common/inventorydata.h" + +class Account; +class MessageIn; +class MessageOut; + +typedef std::map< unsigned int, std::pair > AttributeMap; + +/** placeholder type needed for include compatibility with game server*/ +typedef void Special; + +class Character +{ + public: + + Character(const std::string &name, int id = -1); + + /** + * Gets the database id of the character. + */ + int getDatabaseID() const { return mDatabaseID; } + void setDatabaseID(int id) { mDatabaseID = id; } + + /** Gets the account the character belongs to. */ + Account *getAccount() const + { return mAccount; } + + /** Sets the account the character belongs to, and related fields. */ + void setAccount(Account *ptr); + + /** + * Gets the ID of the account the character belongs to. + */ + int getAccountID() const { return mAccountID; } + void setAccountID(int id) { mAccountID = id; } + + /** + * Gets the name of the character. + */ + const std::string &getName() const { return mName; } + void setName(const std::string &name) { mName = name; } + + /** + * Gets the gender of the character (male / female). + */ + int getGender() const { return mGender; } + void setGender(int gender) { mGender = gender; } + + /** + * Gets the hairstyle of the character. + */ + int getHairStyle() const { return mHairStyle; } + void setHairStyle(int style) { mHairStyle = style; } + + /** + * Gets the haircolor of the character. + */ + int getHairColor() const { return mHairColor; } + void setHairColor(int color) { mHairColor = color; } + + /** Gets the account level of the user. */ + int getAccountLevel() const + { return mAccountLevel; } + + /** + * Sets the account level of the user. + * @param force ensure the level is not modified by a game server. + */ + void setAccountLevel(int l, bool force = false) + { if (force) mAccountLevel = l; } + + /** + * Gets the level of the character. + */ + int getLevel() const { return mLevel; } + void setLevel(int level) { mLevel = level; } + + /** Sets the value of a base attribute of the character. */ + void setAttribute(unsigned int id, double value) + { mAttributes[id].first = value; } + + void setModAttribute(unsigned int id, double value) + { mAttributes[id].second = value; } + + int getSkillSize() const + { return mExperience.size(); } + + const std::map::const_iterator getSkillBegin() const + { return mExperience.begin(); } + + const std::map::const_iterator getSkillEnd() const + { return mExperience.end(); } + + int getExperience(int skill) const + { return mExperience.find(skill)->second; } + + void setExperience(int skill, int value) + { mExperience[skill] = value; } + + void receiveExperience(int skill, int value) + { mExperience[skill] += value; } + + /** + * Get / Set a status effects + */ + void applyStatusEffect(int id, int time) + { mStatusEffects[id] = time; } + + int getStatusEffectSize() const + { return mStatusEffects.size(); } + + const std::map::const_iterator getStatusEffectBegin() const + { return mStatusEffects.begin(); } + + const std::map::const_iterator getStatusEffectEnd() const + { return mStatusEffects.end(); } + + /** + * Get / Set kill count + */ + int getKillCountSize() const + { return mKillCount.size(); } + + const std::map::const_iterator getKillCountBegin() const + { return mKillCount.begin(); } + + const std::map::const_iterator getKillCountEnd() const + { return mKillCount.end(); } + + void setKillCount(int monsterId, int kills) + { mKillCount[monsterId] = kills; } + + /** + * Get / Set specials + */ + int getSpecialSize() const + { return mSpecials.size(); } + + const std::map::const_iterator getSpecialBegin() const + { return mSpecials.begin(); } + + const std::map::const_iterator getSpecialEnd() const + { return mSpecials.end(); } + + void clearSpecials() + { mSpecials.clear(); } + + void giveSpecial(int id) + { mSpecials[id] = NULL; } + + /** + * Gets the Id of the map that the character is on. + */ + int getMapId() const { return mMapId; } + void setMapId(int mapId) { mMapId = mapId; } + + /** + * Gets the position of the character on the map. + */ + const Point &getPosition() const { return mPos; } + void setPosition(const Point &p) { mPos = p; } + + /** Add a guild to the character */ + void addGuild(const std::string &name) { mGuilds.push_back(name); } + + /** Returns a list of guilds the player belongs to */ + std::vector + getGuilds() const { return mGuilds; } + + /** + * Gets a reference on the possessions. + */ + const Possessions &getPossessions() const + { return mPossessions; } + + /** + * Gets a reference on the possessions. + */ + Possessions &getPossessions() + { return mPossessions; } + + void setCharacterPoints(int points) + { mCharacterPoints = points; } + + int getCharacterPoints() const + { return mCharacterPoints; } + + void setCorrectionPoints(int points) + { mCorrectionPoints = points; } + + int getCorrectionPoints() const + { return mCorrectionPoints; } + + + private: + + Character(const Character &); + Character &operator=(const Character &); + + double getAttrBase(AttributeMap::const_iterator &it) const + { return it->second.first; } + double getAttrMod(AttributeMap::const_iterator &it) const + { return it->second.second; } + + Possessions mPossessions; //!< All the possesions of the character. + std::string mName; //!< Name of the character. + int mDatabaseID; //!< Character database ID. + int mAccountID; //!< Account ID of the owner. + Account *mAccount; //!< Account owning the character. + Point mPos; //!< Position the being is at. + /** + * Stores attributes. + * The key is an unsigned int which is the id of the attribute. + * The value stores the base value of the attribute in the first part, + * and the modified value in the second. The modified value is only + * used when transmitting to the client. + */ + AttributeMap mAttributes; //!< Attributes. + std::map mExperience; //!< Skill Experience. + std::map mStatusEffects; //!< Status Effects + std::map mKillCount; //!< Kill Count + std::map mSpecials; + unsigned short mMapId; //!< Map the being is on. + unsigned char mGender; //!< Gender of the being. + unsigned char mHairStyle; //!< Hair style of the being. + unsigned char mHairColor; //!< Hair color of the being. + short mLevel; //!< Level of the being. + short mCharacterPoints; //!< Unused character points. + short mCorrectionPoints; //!< Unused correction points. + unsigned char mAccountLevel; //!< Level of the associated account. + + std::vector mGuilds; //!< All the guilds the player + //!< belongs to. + friend class AccountHandler; + friend class Storage; + // Set as a friend, but still a lot of redundant accessors. FIXME. + template< class T > + friend void serializeCharacterData(const T &data, MessageOut &msg); +}; + +/** + * Type definition for a list of Characters. + */ +typedef std::vector< Character * > Characters; + +#endif diff --git a/src/account-server/character.hpp b/src/account-server/character.hpp deleted file mode 100644 index f9114c7a..00000000 --- a/src/account-server/character.hpp +++ /dev/null @@ -1,275 +0,0 @@ -/* - * The Mana Server - * Copyright (C) 2004-2010 The Mana World Development Team - * - * This file is part of The Mana Server. - * - * The Mana Server 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 - * any later version. - * - * The Mana Server 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 The Mana Server. If not, see . - */ - -#ifndef CHARACTERDATA_HPP -#define CHARACTERDATA_HPP - -#include -#include -#include - -#include "defines.h" -#include "point.h" -#include "common/inventorydata.hpp" - -class Account; -class MessageIn; -class MessageOut; - -typedef std::map< unsigned int, std::pair > AttributeMap; - -/** placeholder type needed for include compatibility with game server*/ -typedef void Special; - -class Character -{ - public: - - Character(const std::string &name, int id = -1); - - /** - * Gets the database id of the character. - */ - int getDatabaseID() const { return mDatabaseID; } - void setDatabaseID(int id) { mDatabaseID = id; } - - /** Gets the account the character belongs to. */ - Account *getAccount() const - { return mAccount; } - - /** Sets the account the character belongs to, and related fields. */ - void setAccount(Account *ptr); - - /** - * Gets the ID of the account the character belongs to. - */ - int getAccountID() const { return mAccountID; } - void setAccountID(int id) { mAccountID = id; } - - /** - * Gets the name of the character. - */ - const std::string &getName() const { return mName; } - void setName(const std::string &name) { mName = name; } - - /** - * Gets the gender of the character (male / female). - */ - int getGender() const { return mGender; } - void setGender(int gender) { mGender = gender; } - - /** - * Gets the hairstyle of the character. - */ - int getHairStyle() const { return mHairStyle; } - void setHairStyle(int style) { mHairStyle = style; } - - /** - * Gets the haircolor of the character. - */ - int getHairColor() const { return mHairColor; } - void setHairColor(int color) { mHairColor = color; } - - /** Gets the account level of the user. */ - int getAccountLevel() const - { return mAccountLevel; } - - /** - * Sets the account level of the user. - * @param force ensure the level is not modified by a game server. - */ - void setAccountLevel(int l, bool force = false) - { if (force) mAccountLevel = l; } - - /** - * Gets the level of the character. - */ - int getLevel() const { return mLevel; } - void setLevel(int level) { mLevel = level; } - - /** Sets the value of a base attribute of the character. */ - void setAttribute(unsigned int id, double value) - { mAttributes[id].first = value; } - - void setModAttribute(unsigned int id, double value) - { mAttributes[id].second = value; } - - int getSkillSize() const - { return mExperience.size(); } - - const std::map::const_iterator getSkillBegin() const - { return mExperience.begin(); } - - const std::map::const_iterator getSkillEnd() const - { return mExperience.end(); } - - int getExperience(int skill) const - { return mExperience.find(skill)->second; } - - void setExperience(int skill, int value) - { mExperience[skill] = value; } - - void receiveExperience(int skill, int value) - { mExperience[skill] += value; } - - /** - * Get / Set a status effects - */ - void applyStatusEffect(int id, int time) - { mStatusEffects[id] = time; } - - int getStatusEffectSize() const - { return mStatusEffects.size(); } - - const std::map::const_iterator getStatusEffectBegin() const - { return mStatusEffects.begin(); } - - const std::map::const_iterator getStatusEffectEnd() const - { return mStatusEffects.end(); } - - /** - * Get / Set kill count - */ - int getKillCountSize() const - { return mKillCount.size(); } - - const std::map::const_iterator getKillCountBegin() const - { return mKillCount.begin(); } - - const std::map::const_iterator getKillCountEnd() const - { return mKillCount.end(); } - - void setKillCount(int monsterId, int kills) - { mKillCount[monsterId] = kills; } - - /** - * Get / Set specials - */ - int getSpecialSize() const - { return mSpecials.size(); } - - const std::map::const_iterator getSpecialBegin() const - { return mSpecials.begin(); } - - const std::map::const_iterator getSpecialEnd() const - { return mSpecials.end(); } - - void clearSpecials() - { mSpecials.clear(); } - - void giveSpecial(int id) - { mSpecials[id] = NULL; } - - /** - * Gets the Id of the map that the character is on. - */ - int getMapId() const { return mMapId; } - void setMapId(int mapId) { mMapId = mapId; } - - /** - * Gets the position of the character on the map. - */ - const Point &getPosition() const { return mPos; } - void setPosition(const Point &p) { mPos = p; } - - /** Add a guild to the character */ - void addGuild(const std::string &name) { mGuilds.push_back(name); } - - /** Returns a list of guilds the player belongs to */ - std::vector - getGuilds() const { return mGuilds; } - - /** - * Gets a reference on the possessions. - */ - const Possessions &getPossessions() const - { return mPossessions; } - - /** - * Gets a reference on the possessions. - */ - Possessions &getPossessions() - { return mPossessions; } - - void setCharacterPoints(int points) - { mCharacterPoints = points; } - - int getCharacterPoints() const - { return mCharacterPoints; } - - void setCorrectionPoints(int points) - { mCorrectionPoints = points; } - - int getCorrectionPoints() const - { return mCorrectionPoints; } - - - private: - - Character(const Character &); - Character &operator=(const Character &); - - double getAttrBase(AttributeMap::const_iterator &it) const - { return it->second.first; } - double getAttrMod(AttributeMap::const_iterator &it) const - { return it->second.second; } - - Possessions mPossessions; //!< All the possesions of the character. - std::string mName; //!< Name of the character. - int mDatabaseID; //!< Character database ID. - int mAccountID; //!< Account ID of the owner. - Account *mAccount; //!< Account owning the character. - Point mPos; //!< Position the being is at. - /** - * Stores attributes. - * The key is an unsigned int which is the id of the attribute. - * The value stores the base value of the attribute in the first part, - * and the modified value in the second. The modified value is only - * used when transmitting to the client. - */ - AttributeMap mAttributes; //!< Attributes. - std::map mExperience; //!< Skill Experience. - std::map mStatusEffects; //!< Status Effects - std::map mKillCount; //!< Kill Count - std::map mSpecials; - unsigned short mMapId; //!< Map the being is on. - unsigned char mGender; //!< Gender of the being. - unsigned char mHairStyle; //!< Hair style of the being. - unsigned char mHairColor; //!< Hair color of the being. - short mLevel; //!< Level of the being. - short mCharacterPoints; //!< Unused character points. - short mCorrectionPoints; //!< Unused correction points. - unsigned char mAccountLevel; //!< Level of the associated account. - - std::vector mGuilds; //!< All the guilds the player - //!< belongs to. - friend class AccountHandler; - friend class Storage; - // Set as a friend, but still a lot of redundant accessors. FIXME. - template< class T > - friend void serializeCharacterData(const T &data, MessageOut &msg); -}; - -/** - * Type definition for a list of Characters. - */ -typedef std::vector< Character * > Characters; - -#endif diff --git a/src/account-server/main-account.cpp b/src/account-server/main-account.cpp index af6e99fb..9516b4d1 100644 --- a/src/account-server/main-account.cpp +++ b/src/account-server/main-account.cpp @@ -23,20 +23,20 @@ #include "../config.h" #endif -#include "account-server/accounthandler.hpp" -#include "account-server/serverhandler.hpp" -#include "account-server/storage.hpp" -#include "chat-server/chatchannelmanager.hpp" -#include "chat-server/chathandler.hpp" -#include "chat-server/guildmanager.hpp" -#include "chat-server/post.hpp" -#include "common/configuration.hpp" -#include "common/resourcemanager.hpp" -#include "net/bandwidth.hpp" -#include "net/connectionhandler.hpp" -#include "net/messageout.hpp" +#include "account-server/accounthandler.h" +#include "account-server/serverhandler.h" +#include "account-server/storage.h" +#include "chat-server/chatchannelmanager.h" +#include "chat-server/chathandler.h" +#include "chat-server/guildmanager.h" +#include "chat-server/post.h" +#include "common/configuration.h" +#include "common/resourcemanager.h" +#include "net/bandwidth.h" +#include "net/connectionhandler.h" +#include "net/messageout.h" #include "utils/logger.h" -#include "utils/processorutils.hpp" +#include "utils/processorutils.h" #include "utils/stringfilter.h" #include "utils/timer.h" #include "defines.h" diff --git a/src/account-server/serverhandler.cpp b/src/account-server/serverhandler.cpp index 048e65bf..2e471994 100644 --- a/src/account-server/serverhandler.cpp +++ b/src/account-server/serverhandler.cpp @@ -22,21 +22,21 @@ #include #include -#include "account-server/serverhandler.hpp" - -#include "account-server/accountclient.hpp" -#include "account-server/accounthandler.hpp" -#include "account-server/character.hpp" -#include "account-server/storage.hpp" -#include "chat-server/post.hpp" -#include "common/transaction.hpp" -#include "common/configuration.hpp" -#include "net/connectionhandler.hpp" -#include "net/messageout.hpp" -#include "net/netcomputer.hpp" -#include "serialize/characterdata.hpp" +#include "account-server/serverhandler.h" + +#include "account-server/accountclient.h" +#include "account-server/accounthandler.h" +#include "account-server/character.h" +#include "account-server/storage.h" +#include "chat-server/post.h" +#include "common/transaction.h" +#include "common/configuration.h" +#include "net/connectionhandler.h" +#include "net/messageout.h" +#include "net/netcomputer.h" +#include "serialize/characterdata.h" #include "utils/logger.h" -#include "utils/tokendispenser.hpp" +#include "utils/tokendispenser.h" #include "protocol.h" struct MapStatistics diff --git a/src/account-server/serverhandler.h b/src/account-server/serverhandler.h new file mode 100644 index 00000000..5b9ba7f2 --- /dev/null +++ b/src/account-server/serverhandler.h @@ -0,0 +1,76 @@ +/* + * The Mana Server + * Copyright (C) 2006-2010 The Mana World Development Team + * + * This file is part of The Mana Server. + * + * The Mana Server 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 + * any later version. + * + * The Mana Server 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 The Mana Server. If not, see . + */ + +#ifndef SERVERHANDLER_H +#define SERVERHANDLER_H + +#include +#include + +#include "net/messagein.h" + +class Character; + +namespace GameServerHandler +{ + /** + * Creates a connection handler and starts listening on given port. + */ + bool initialize(int port, const std::string &host); + + /** + * Stops listening to messages and destroys the connection handler. + */ + void deinitialize(); + + /** + * Returns the information a client needs to connect to the game server + * corresponding to the given map ID. + */ + bool getGameServerFromMap(int, std::string &address, int &port); + + /** + * Warns a game server about a soon-to-connect client. + */ + void registerClient(const std::string &token, Character *); + + /** + * Dumps per-server statistics into given stream + */ + void dumpStatistics(std::ostream &); + + /** + * Processes messages received by the connection handler. + */ + void process(); + + /** + * Sends chat party information + */ + void sendPartyChange(Character *ptr, int partyId); + + /** + * Takes a GAMSG_PLAYER_SYNC from the gameserver and stores all changes in + * the database. + */ + void syncDatabase(MessageIn &msg); +} + +#endif diff --git a/src/account-server/serverhandler.hpp b/src/account-server/serverhandler.hpp deleted file mode 100644 index 569ade1d..00000000 --- a/src/account-server/serverhandler.hpp +++ /dev/null @@ -1,76 +0,0 @@ -/* - * The Mana Server - * Copyright (C) 2006-2010 The Mana World Development Team - * - * This file is part of The Mana Server. - * - * The Mana Server 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 - * any later version. - * - * The Mana Server 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 The Mana Server. If not, see . - */ - -#ifndef SERVERHANDLER_H -#define SERVERHANDLER_H - -#include -#include - -#include "net/messagein.hpp" - -class Character; - -namespace GameServerHandler -{ - /** - * Creates a connection handler and starts listening on given port. - */ - bool initialize(int port, const std::string &host); - - /** - * Stops listening to messages and destroys the connection handler. - */ - void deinitialize(); - - /** - * Returns the information a client needs to connect to the game server - * corresponding to the given map ID. - */ - bool getGameServerFromMap(int, std::string &address, int &port); - - /** - * Warns a game server about a soon-to-connect client. - */ - void registerClient(const std::string &token, Character *); - - /** - * Dumps per-server statistics into given stream - */ - void dumpStatistics(std::ostream &); - - /** - * Processes messages received by the connection handler. - */ - void process(); - - /** - * Sends chat party information - */ - void sendPartyChange(Character *ptr, int partyId); - - /** - * Takes a GAMSG_PLAYER_SYNC from the gameserver and stores all changes in - * the database. - */ - void syncDatabase(MessageIn &msg); -} - -#endif diff --git a/src/account-server/storage.cpp b/src/account-server/storage.cpp index e741875d..feb5922f 100644 --- a/src/account-server/storage.cpp +++ b/src/account-server/storage.cpp @@ -21,19 +21,19 @@ #include #include -#include "account-server/storage.hpp" +#include "account-server/storage.h" #include "point.h" -#include "account-server/account.hpp" -#include "chat-server/chatchannel.hpp" -#include "chat-server/guild.hpp" -#include "chat-server/post.hpp" -#include "common/configuration.hpp" +#include "account-server/account.h" +#include "chat-server/chatchannel.h" +#include "chat-server/guild.h" +#include "chat-server/post.h" +#include "common/configuration.h" #include "dal/dalexcept.h" #include "dal/dataproviderfactory.h" #include "utils/functors.h" #include "utils/logger.h" -#include "utils/xml.hpp" +#include "utils/xml.h" static const char *DEFAULT_ITEM_FILE = "items.xml"; diff --git a/src/account-server/storage.h b/src/account-server/storage.h new file mode 100644 index 00000000..9dc80693 --- /dev/null +++ b/src/account-server/storage.h @@ -0,0 +1,152 @@ +/* + * The Mana Server + * Copyright (C) 2004-2010 The Mana World Development Team + * + * This file is part of The Mana Server. + * + * The Mana Server 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 + * any later version. + * + * The Mana Server 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 The Mana Server. If not, see . + */ + +#ifndef STORAGE_H +#define STORAGE_H + +#include +#include +#include + +#include "dal/dataprovider.h" + +#include "common/transaction.h" + +class Account; +class Character; +class ChatChannel; +class Guild; +class Letter; +class Post; + +/** + * The high level interface to the database. Through the storage you can access + * all accounts, characters, guilds, worlds states, transactions, etc. + */ +class Storage +{ + public: + Storage(); + ~Storage(); + + void open(); + void close(); + + Account *getAccount(const std::string &userName); + Account *getAccount(int accountID); + + Character *getCharacter(int id, Account *owner); + Character *getCharacter(const std::string &name); + + void addAccount(Account *account); + void delAccount(Account *account); + + void updateLastLogin(const Account *account); + + void updateCharacterPoints(int charId, + int charPoints, int corrPoints); + + void updateExperience(int charId, int skillId, int skillValue); + + void updateAttribute(int charId, unsigned int attrId, + double base, double mod); + + void updateKillCount(int charId, int monsterId, int kills); + + void insertStatusEffect(int charId, int statusId, int time); + + void banCharacter(int id, int duration); + + void delCharacter(int charId) const; + void delCharacter(Character *character) const; + + void checkBannedAccounts(); + + bool doesUserNameExist(const std::string &name); + bool doesEmailAddressExist(const std::string &email); + bool doesCharacterNameExist(const std::string &name); + + bool updateCharacter(Character *ptr); + + void flushSkill(const Character *character, int skill_id); + + void addGuild(Guild *guild); + void removeGuild(Guild *guild); + + void addGuildMember(int guild_id, int memberId); + void removeGuildMember(int guildId, int memberId); + + void setMemberRights(int guildId, int memberId, int rights); + + std::list getGuildList(); + + void flush(Account *); + + std::string getQuestVar(int id, const std::string &); + void setQuestVar(int id, const std::string &, const std::string &); + + std::string getWorldStateVar(const std::string &name, int map_id = -1); + void setWorldStateVar(const std::string &name, + const std::string &value); + void setWorldStateVar(const std::string &name, int mapId, + const std::string &value); + + void setAccountLevel(int id, int level); + void setPlayerLevel(int id, int level); + + void storeLetter(Letter *letter); + Post *getStoredPost(int playerId); + void deletePost(Letter *letter); + + /** + * Returns the version of the local item database. + */ + unsigned int getItemDatabaseVersion() const + { return mItemDbVersion; } + + void setOnlineStatus(int charId, bool online); + + void addTransaction(const Transaction &trans); + + std::vector getTransactions(unsigned int num); + std::vector getTransactions(time_t date); + + /** + * Provides direct access to the database. Use with care! + */ + dal::DataProvider *database() const { return mDb; } + + private: + // Prevent copying + Storage(const Storage &rhs); + Storage &operator=(const Storage &rhs); + + Account *getAccountBySQL(); + Character *getCharacterBySQL(Account *owner); + + void syncDatabase(); + + dal::DataProvider *mDb; /**< the data provider */ + unsigned int mItemDbVersion; /**< Version of the item database. */ +}; + +extern Storage *storage; + +#endif // STORAGE_H diff --git a/src/account-server/storage.hpp b/src/account-server/storage.hpp deleted file mode 100644 index 27d12997..00000000 --- a/src/account-server/storage.hpp +++ /dev/null @@ -1,152 +0,0 @@ -/* - * The Mana Server - * Copyright (C) 2004-2010 The Mana World Development Team - * - * This file is part of The Mana Server. - * - * The Mana Server 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 - * any later version. - * - * The Mana Server 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 The Mana Server. If not, see . - */ - -#ifndef STORAGE_H -#define STORAGE_H - -#include -#include -#include - -#include "dal/dataprovider.h" - -#include "common/transaction.hpp" - -class Account; -class Character; -class ChatChannel; -class Guild; -class Letter; -class Post; - -/** - * The high level interface to the database. Through the storage you can access - * all accounts, characters, guilds, worlds states, transactions, etc. - */ -class Storage -{ - public: - Storage(); - ~Storage(); - - void open(); - void close(); - - Account *getAccount(const std::string &userName); - Account *getAccount(int accountID); - - Character *getCharacter(int id, Account *owner); - Character *getCharacter(const std::string &name); - - void addAccount(Account *account); - void delAccount(Account *account); - - void updateLastLogin(const Account *account); - - void updateCharacterPoints(int charId, - int charPoints, int corrPoints); - - void updateExperience(int charId, int skillId, int skillValue); - - void updateAttribute(int charId, unsigned int attrId, - double base, double mod); - - void updateKillCount(int charId, int monsterId, int kills); - - void insertStatusEffect(int charId, int statusId, int time); - - void banCharacter(int id, int duration); - - void delCharacter(int charId) const; - void delCharacter(Character *character) const; - - void checkBannedAccounts(); - - bool doesUserNameExist(const std::string &name); - bool doesEmailAddressExist(const std::string &email); - bool doesCharacterNameExist(const std::string &name); - - bool updateCharacter(Character *ptr); - - void flushSkill(const Character *character, int skill_id); - - void addGuild(Guild *guild); - void removeGuild(Guild *guild); - - void addGuildMember(int guild_id, int memberId); - void removeGuildMember(int guildId, int memberId); - - void setMemberRights(int guildId, int memberId, int rights); - - std::list getGuildList(); - - void flush(Account *); - - std::string getQuestVar(int id, const std::string &); - void setQuestVar(int id, const std::string &, const std::string &); - - std::string getWorldStateVar(const std::string &name, int map_id = -1); - void setWorldStateVar(const std::string &name, - const std::string &value); - void setWorldStateVar(const std::string &name, int mapId, - const std::string &value); - - void setAccountLevel(int id, int level); - void setPlayerLevel(int id, int level); - - void storeLetter(Letter *letter); - Post *getStoredPost(int playerId); - void deletePost(Letter *letter); - - /** - * Returns the version of the local item database. - */ - unsigned int getItemDatabaseVersion() const - { return mItemDbVersion; } - - void setOnlineStatus(int charId, bool online); - - void addTransaction(const Transaction &trans); - - std::vector getTransactions(unsigned int num); - std::vector getTransactions(time_t date); - - /** - * Provides direct access to the database. Use with care! - */ - dal::DataProvider *database() const { return mDb; } - - private: - // Prevent copying - Storage(const Storage &rhs); - Storage &operator=(const Storage &rhs); - - Account *getAccountBySQL(); - Character *getCharacterBySQL(Account *owner); - - void syncDatabase(); - - dal::DataProvider *mDb; /**< the data provider */ - unsigned int mItemDbVersion; /**< Version of the item database. */ -}; - -extern Storage *storage; - -#endif // STORAGE_H diff --git a/src/chat-server/chatchannel.cpp b/src/chat-server/chatchannel.cpp index 43ca1e92..52c9bf5a 100644 --- a/src/chat-server/chatchannel.cpp +++ b/src/chat-server/chatchannel.cpp @@ -21,8 +21,8 @@ #include #include -#include "chat-server/chatchannel.hpp" -#include "chat-server/chatclient.hpp" +#include "chat-server/chatchannel.h" +#include "chat-server/chatclient.h" ChatChannel::ChatChannel(int id, const std::string &name, diff --git a/src/chat-server/chatchannel.h b/src/chat-server/chatchannel.h new file mode 100644 index 00000000..66ffb5b2 --- /dev/null +++ b/src/chat-server/chatchannel.h @@ -0,0 +1,151 @@ +/* + * The Mana Server + * Copyright (C) 2004-2010 The Mana World Development Team + * + * This file is part of The Mana Server. + * + * The Mana Server 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 + * any later version. + * + * The Mana Server 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 The Mana Server. If not, see . + */ + +#ifndef CHATCHANNEL_H +#define CHATCHANNEL_H + +#include +#include + +class ChatClient; + +/** + * A chat channel. Optionally a channel is private, in which case a password is + * required to join it. + * + * No logic is currently associated with a chat channel except for making sure + * that no user joins the channel twice and checking that a user who leaves + * actually existed in the channel. + * + * @todo b_lindeijer: It would be nicer when some more logic could be + * placed in this class to remove some weight from the ChatHandler. + */ +class ChatChannel +{ + public: + typedef std::vector< ChatClient * > ChannelUsers; + + /** + * Constructor. + * + * @param name the name of the channel. + * @param announcement a welcome message. + * @param password password (for private channels). + * @param privacy whether this channel is private. + */ + ChatChannel(int id, + const std::string &name, + const std::string &announcement = std::string(), + const std::string &password = std::string(), + bool joinable = true); + + /** + * Get the ID of the channel. + */ + int getId() const + { return mId; } + + /** + * Get the name of the channel. + */ + const std::string &getName() const + { return mName; } + + /** + * Get the announcement string of the channel. + */ + const std::string &getAnnouncement() const + { return mAnnouncement; } + + /** + * Get the password of the channel. + */ + const std::string& getPassword() const + { return mPassword; } + + /** + * Sets the name of the channel. + */ + void setName(const std::string &channelName) + { mName = channelName; } + + /** + * Sets the announcement string of the channel. + */ + void setAnnouncement(const std::string &channelAnnouncement) + { mAnnouncement = channelAnnouncement; } + + /** + * Sets the password of the channel. + */ + void setPassword(const std::string &channelPassword) + { mPassword = channelPassword; } + + /** + * Gets the list of the users registered in the channel. + */ + const ChannelUsers &getUserList() const + { return mRegisteredUsers; } + + /** + * Adds a user to the channel. + * + * @return whether the user was successfully added + */ + bool addUser(ChatClient *); + + /** + * Removes a user from the channel. + * + * @return whether the user was successfully removed + */ + bool removeUser(ChatClient *); + + /** + * Empties a channel from its users (admin included). + */ + void removeAllUsers(); + + /** + * Get whether a user can join this channel + */ + bool canJoin() const; + + /** + * Set user mode + */ + void setUserMode(ChatClient *, unsigned char mode); + + /** + * Get user mode + */ + std::string getUserMode(ChatClient *) const; + + private: + unsigned short mId; /**< The ID of the channel. */ + std::string mName; /**< The name of the channel. */ + std::string mAnnouncement; /**< Welcome message. */ + std::string mPassword; /**< The channel password. */ + bool mJoinable; /**< Whether anyone can join. */ + ChannelUsers mRegisteredUsers; /**< Users in this channel. */ + std::string mOwner; /**< Channel owner character name */ +}; + +#endif diff --git a/src/chat-server/chatchannel.hpp b/src/chat-server/chatchannel.hpp deleted file mode 100644 index 66ffb5b2..00000000 --- a/src/chat-server/chatchannel.hpp +++ /dev/null @@ -1,151 +0,0 @@ -/* - * The Mana Server - * Copyright (C) 2004-2010 The Mana World Development Team - * - * This file is part of The Mana Server. - * - * The Mana Server 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 - * any later version. - * - * The Mana Server 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 The Mana Server. If not, see . - */ - -#ifndef CHATCHANNEL_H -#define CHATCHANNEL_H - -#include -#include - -class ChatClient; - -/** - * A chat channel. Optionally a channel is private, in which case a password is - * required to join it. - * - * No logic is currently associated with a chat channel except for making sure - * that no user joins the channel twice and checking that a user who leaves - * actually existed in the channel. - * - * @todo b_lindeijer: It would be nicer when some more logic could be - * placed in this class to remove some weight from the ChatHandler. - */ -class ChatChannel -{ - public: - typedef std::vector< ChatClient * > ChannelUsers; - - /** - * Constructor. - * - * @param name the name of the channel. - * @param announcement a welcome message. - * @param password password (for private channels). - * @param privacy whether this channel is private. - */ - ChatChannel(int id, - const std::string &name, - const std::string &announcement = std::string(), - const std::string &password = std::string(), - bool joinable = true); - - /** - * Get the ID of the channel. - */ - int getId() const - { return mId; } - - /** - * Get the name of the channel. - */ - const std::string &getName() const - { return mName; } - - /** - * Get the announcement string of the channel. - */ - const std::string &getAnnouncement() const - { return mAnnouncement; } - - /** - * Get the password of the channel. - */ - const std::string& getPassword() const - { return mPassword; } - - /** - * Sets the name of the channel. - */ - void setName(const std::string &channelName) - { mName = channelName; } - - /** - * Sets the announcement string of the channel. - */ - void setAnnouncement(const std::string &channelAnnouncement) - { mAnnouncement = channelAnnouncement; } - - /** - * Sets the password of the channel. - */ - void setPassword(const std::string &channelPassword) - { mPassword = channelPassword; } - - /** - * Gets the list of the users registered in the channel. - */ - const ChannelUsers &getUserList() const - { return mRegisteredUsers; } - - /** - * Adds a user to the channel. - * - * @return whether the user was successfully added - */ - bool addUser(ChatClient *); - - /** - * Removes a user from the channel. - * - * @return whether the user was successfully removed - */ - bool removeUser(ChatClient *); - - /** - * Empties a channel from its users (admin included). - */ - void removeAllUsers(); - - /** - * Get whether a user can join this channel - */ - bool canJoin() const; - - /** - * Set user mode - */ - void setUserMode(ChatClient *, unsigned char mode); - - /** - * Get user mode - */ - std::string getUserMode(ChatClient *) const; - - private: - unsigned short mId; /**< The ID of the channel. */ - std::string mName; /**< The name of the channel. */ - std::string mAnnouncement; /**< Welcome message. */ - std::string mPassword; /**< The channel password. */ - bool mJoinable; /**< Whether anyone can join. */ - ChannelUsers mRegisteredUsers; /**< Users in this channel. */ - std::string mOwner; /**< Channel owner character name */ -}; - -#endif diff --git a/src/chat-server/chatchannelmanager.cpp b/src/chat-server/chatchannelmanager.cpp index a8a3df08..7d10f53c 100644 --- a/src/chat-server/chatchannelmanager.cpp +++ b/src/chat-server/chatchannelmanager.cpp @@ -20,14 +20,14 @@ #include -#include "chat-server/chatchannelmanager.hpp" +#include "chat-server/chatchannelmanager.h" #include "protocol.h" -#include "account-server/storage.hpp" -#include "chat-server/chatclient.hpp" -#include "chat-server/chathandler.hpp" -#include "chat-server/guildmanager.hpp" -#include "common/configuration.hpp" +#include "account-server/storage.h" +#include "chat-server/chatclient.h" +#include "chat-server/chathandler.h" +#include "chat-server/guildmanager.h" +#include "common/configuration.h" #include "utils/stringfilter.h" ChatChannelManager::ChatChannelManager() : mNextChannelId(1) diff --git a/src/chat-server/chatchannelmanager.h b/src/chat-server/chatchannelmanager.h new file mode 100644 index 00000000..b7f19eee --- /dev/null +++ b/src/chat-server/chatchannelmanager.h @@ -0,0 +1,131 @@ +/* + * The Mana Server + * Copyright (C) 2004-2010 The Mana World Development Team + * + * This file is part of The Mana Server. + * + * The Mana Server 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 + * any later version. + * + * The Mana Server 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 The Mana Server. If not, see . + */ + +#ifndef CHATCHANNELMANAGER_H +#define CHATCHANNELMANAGER_H + +#include +#include +#include + +#include "chat-server/chatchannel.h" + +/** + * The chat channel manager takes care of registering and removing public and + * private chat channels. Every channel gets a unique channel ID. + */ +class ChatChannelManager +{ + public: + ChatChannelManager(); + ~ChatChannelManager(); + + /** + * Create a new chat channel. + * + * @return the ID of the registered channel + */ + int createNewChannel(const std::string &channelName, + const std::string &channelAnnouncement, + const std::string &channelPassword, + bool joinable); + + /** + * Try to create a new public channel with the given name. + * + * @return true if created successfully, false otherwise. + */ + bool tryNewPublicChannel(const std::string &name); + + /** + * Remove a channel. + */ + bool removeChannel(int channelId); + + /** + * Returns a list containing all public channels. + * + * @return a list of all public channels + */ + std::list getPublicChannels() const; + + /** + * Get the id of a channel from its name. + * + * @return the id of the channel, 0 if it was unsuccessful. + */ + int getChannelId(const std::string &channelName) const; + + /** + * Returns the chat channel with the given channel ID. + * + * @return The chat channel, or NULL when it doesn't exist. + */ + ChatChannel *getChannel(int channelId); + + /** + * Returns the chat channel with the given channel name. + * + * @return The chat channel, or NULL when it doesn't exist. + */ + ChatChannel *getChannel(const std::string &name); + + /** + * Remove a user from all channels. Used at logout. + * + * @see ChatChannel::removeUserFromChannel + */ + void removeUserFromAllChannels(ChatClient *); + + /** + * Set the topic of a channel. + * + * @param topic the new topic of the given channel + */ + void setChannelTopic(int channelId, const std::string &name); + + /** + * Returns whether a channel exists. + * + * @param channelId a channel ID + */ + bool channelExists(int channelId) const; + bool channelExists(const std::string &channelName) const; + + /** + * Get next usable channel ID + */ + int nextUsable(); + + private: + typedef std::map ChatChannels; + + /** + * The map keeping all the chat channels. The channel id must be + * unique. + */ + ChatChannels mChatChannels; + int mNextChannelId; + std::deque mChannelsNoLongerUsed; +}; + +extern ChatChannelManager *chatChannelManager; + +#endif diff --git a/src/chat-server/chatchannelmanager.hpp b/src/chat-server/chatchannelmanager.hpp deleted file mode 100644 index 739b4285..00000000 --- a/src/chat-server/chatchannelmanager.hpp +++ /dev/null @@ -1,131 +0,0 @@ -/* - * The Mana Server - * Copyright (C) 2004-2010 The Mana World Development Team - * - * This file is part of The Mana Server. - * - * The Mana Server 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 - * any later version. - * - * The Mana Server 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 The Mana Server. If not, see . - */ - -#ifndef CHATCHANNELMANAGER_H -#define CHATCHANNELMANAGER_H - -#include -#include -#include - -#include "chat-server/chatchannel.hpp" - -/** - * The chat channel manager takes care of registering and removing public and - * private chat channels. Every channel gets a unique channel ID. - */ -class ChatChannelManager -{ - public: - ChatChannelManager(); - ~ChatChannelManager(); - - /** - * Create a new chat channel. - * - * @return the ID of the registered channel - */ - int createNewChannel(const std::string &channelName, - const std::string &channelAnnouncement, - const std::string &channelPassword, - bool joinable); - - /** - * Try to create a new public channel with the given name. - * - * @return true if created successfully, false otherwise. - */ - bool tryNewPublicChannel(const std::string &name); - - /** - * Remove a channel. - */ - bool removeChannel(int channelId); - - /** - * Returns a list containing all public channels. - * - * @return a list of all public channels - */ - std::list getPublicChannels() const; - - /** - * Get the id of a channel from its name. - * - * @return the id of the channel, 0 if it was unsuccessful. - */ - int getChannelId(const std::string &channelName) const; - - /** - * Returns the chat channel with the given channel ID. - * - * @return The chat channel, or NULL when it doesn't exist. - */ - ChatChannel *getChannel(int channelId); - - /** - * Returns the chat channel with the given channel name. - * - * @return The chat channel, or NULL when it doesn't exist. - */ - ChatChannel *getChannel(const std::string &name); - - /** - * Remove a user from all channels. Used at logout. - * - * @see ChatChannel::removeUserFromChannel - */ - void removeUserFromAllChannels(ChatClient *); - - /** - * Set the topic of a channel. - * - * @param topic the new topic of the given channel - */ - void setChannelTopic(int channelId, const std::string &name); - - /** - * Returns whether a channel exists. - * - * @param channelId a channel ID - */ - bool channelExists(int channelId) const; - bool channelExists(const std::string &channelName) const; - - /** - * Get next usable channel ID - */ - int nextUsable(); - - private: - typedef std::map ChatChannels; - - /** - * The map keeping all the chat channels. The channel id must be - * unique. - */ - ChatChannels mChatChannels; - int mNextChannelId; - std::deque mChannelsNoLongerUsed; -}; - -extern ChatChannelManager *chatChannelManager; - -#endif diff --git a/src/chat-server/chatclient.h b/src/chat-server/chatclient.h new file mode 100644 index 00000000..daac0fcd --- /dev/null +++ b/src/chat-server/chatclient.h @@ -0,0 +1,60 @@ +/* + * The Mana Server + * Copyright (C) 2004-2010 The Mana World Development Team + * + * This file is part of The Mana Server. + * + * The Mana Server 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 + * any later version. + * + * The Mana Server 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 The Mana Server. If not, see . + */ + +#ifndef CHATCLIENT_H +#define CHATCLIENT_H + +#include +#include +#include + +#include "net/netcomputer.h" + +class ChatChannel; +class Guild; +class Party; + +/** + * A client connected to the chat server. Via this class, the chat server + * keeps track of the character name and account level of a client. + */ +class ChatClient : public NetComputer +{ + public: + /** + * Constructor. + */ + ChatClient(ENetPeer *peer): + NetComputer(peer), + party(0), + accountLevel(0) + { + } + + std::string characterName; + unsigned int characterId; + std::vector< ChatChannel * > channels; + Party* party; + unsigned char accountLevel; + std::map userModes; + int numInvites; +}; + +#endif diff --git a/src/chat-server/chatclient.hpp b/src/chat-server/chatclient.hpp deleted file mode 100644 index fed18fb4..00000000 --- a/src/chat-server/chatclient.hpp +++ /dev/null @@ -1,60 +0,0 @@ -/* - * The Mana Server - * Copyright (C) 2004-2010 The Mana World Development Team - * - * This file is part of The Mana Server. - * - * The Mana Server 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 - * any later version. - * - * The Mana Server 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 The Mana Server. If not, see . - */ - -#ifndef CHATCLIENT_H -#define CHATCLIENT_H - -#include -#include -#include - -#include "net/netcomputer.hpp" - -class ChatChannel; -class Guild; -class Party; - -/** - * A client connected to the chat server. Via this class, the chat server - * keeps track of the character name and account level of a client. - */ -class ChatClient : public NetComputer -{ - public: - /** - * Constructor. - */ - ChatClient(ENetPeer *peer): - NetComputer(peer), - party(0), - accountLevel(0) - { - } - - std::string characterName; - unsigned int characterId; - std::vector< ChatChannel * > channels; - Party* party; - unsigned char accountLevel; - std::map userModes; - int numInvites; -}; - -#endif diff --git a/src/chat-server/chathandler.cpp b/src/chat-server/chathandler.cpp index 5740dff9..9a87c0c1 100644 --- a/src/chat-server/chathandler.cpp +++ b/src/chat-server/chathandler.cpp @@ -24,20 +24,20 @@ #include #include "protocol.h" -#include "account-server/character.hpp" -#include "account-server/storage.hpp" -#include "chat-server/guildmanager.hpp" -#include "chat-server/chatchannelmanager.hpp" -#include "chat-server/chatclient.hpp" -#include "chat-server/chathandler.hpp" -#include "common/transaction.hpp" -#include "net/connectionhandler.hpp" -#include "net/messagein.hpp" -#include "net/messageout.hpp" -#include "net/netcomputer.hpp" +#include "account-server/character.h" +#include "account-server/storage.h" +#include "chat-server/guildmanager.h" +#include "chat-server/chatchannelmanager.h" +#include "chat-server/chatclient.h" +#include "chat-server/chathandler.h" +#include "common/transaction.h" +#include "net/connectionhandler.h" +#include "net/messagein.h" +#include "net/messageout.h" +#include "net/netcomputer.h" #include "utils/logger.h" #include "utils/stringfilter.h" -#include "utils/tokendispenser.hpp" +#include "utils/tokendispenser.h" void registerChatClient(const std::string &token, const std::string &name, diff --git a/src/chat-server/chathandler.h b/src/chat-server/chathandler.h new file mode 100644 index 00000000..c6b680e4 --- /dev/null +++ b/src/chat-server/chathandler.h @@ -0,0 +1,343 @@ +/* + * The Mana Server + * Copyright (C) 2004-2010 The Mana World Development Team + * + * This file is part of The Mana Server. + * + * The Mana Server 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 + * any later version. + * + * The Mana Server 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 The Mana Server. If not, see . + */ + +#ifndef CHATHANDLER_H +#define CHATHANDLER_H + +#include +#include +#include + +#include "net/connectionhandler.h" +#include "utils/tokencollector.h" + +class ChatChannel; +class ChatClient; + +/** + * Manages chat related things like private messaging, chat channel handling + * as well as guild chat. The only form of chat not handled by this server is + * local chat, which is handled by the game server. + * + * @todo b_lindeijer: Extend this class with handling of team chat once + * teams are implemented. + */ +class ChatHandler : public ConnectionHandler +{ + private: + /** + * Data needed for initializing a ChatClient. + */ + struct Pending + { + std::string character; + unsigned char level; + }; + + struct PartyInvite + { + std::string mInviter; + std::string mInvited; + int mPartyId; + }; + + std::map mPlayerMap; + std::vector mPartyInvitedUsers; + + public: + ChatHandler(); + + /** + * Start the handler. + */ + bool startListen(enet_uint16 port, const std::string &host); + + /** + * Tell a list of users about an event in a chatchannel. + * + * @param channel the channel to send the message in, must not be NULL + * @param info information pertaining to the event + */ + void warnUsersAboutPlayerEventInChat(ChatChannel *channel, + const std::string &info, + char eventId); + + /** + * Called by TokenCollector when a client wrongly connected. + */ + void deletePendingClient(ChatClient *); + + /** + * Called by TokenCollector when a client failed to connect. + */ + void deletePendingConnect(Pending *); + + /** + * Called by TokenCollector when a client succesfully connected. + */ + void tokenMatched(ChatClient *, Pending *); + + /** + * Send information about a change in the guild list to guild members. + */ + void sendGuildListUpdate(const std::string &guildName, + const std::string &characterName, + char eventId); + + protected: + /** + * Process chat related messages. + */ + void processMessage(NetComputer *computer, MessageIn &message); + + /** + * Returns a ChatClient instance. + */ + NetComputer *computerConnected(ENetPeer *); + + /** + * Cleans up after the disconnected client. + */ + void computerDisconnected(NetComputer *); + + /** + * Send messages for each guild the character belongs to. + */ + void sendGuildRejoin(ChatClient &computer); + + /** + * Send chat and guild info to chat client, so that they can join the + * correct channels. + */ + void sendGuildEnterChannel(const MessageOut &msg, + const std::string &name); + + /** + * Send guild invite. + */ + void sendGuildInvite(const std::string &invitedName, + const std::string &inviterName, + const std::string &guildName); + + private: + /** + * Deal with command messages. + */ + void handleCommand(ChatClient &client, const std::string &command); + + /** + * Deal with Chat messages. + */ + void handleChatMessage(ChatClient &client, MessageIn &msg); + + /** + * Deal with Announcement messages. + */ + void handleAnnounceMessage(ChatClient &client, MessageIn &msg); + + /** + * Deal with Private messages. + */ + void handlePrivMsgMessage(ChatClient &client, MessageIn &msg); + + /** + * Deal with Who messages. + */ + void handleWhoMessage(ChatClient &client); + + /** + * Deal with player entering channel. + */ + void handleEnterChannelMessage(ChatClient &client, MessageIn &msg); + + /** + * Deal with player changing mode. + */ + void handleModeChangeMessage(ChatClient &client, MessageIn &msg); + + /** + * Deal with player kicking other player from channel. + */ + void handleKickUserMessage(ChatClient &client, MessageIn &msg); + + /** + * Deal with player leaving channel. + */ + void handleQuitChannelMessage(ChatClient &client, MessageIn &msg); + + /** + * Deal with listing all accessible channels. + */ + void handleListChannelsMessage(ChatClient &client, MessageIn &msg); + + /** + * Deal with listing all channel users in a channel. + */ + void handleListChannelUsersMessage(ChatClient &client, MessageIn &msg); + + /** + * Deal with changing a channel's topic + */ + void handleTopicChange(ChatClient &client, MessageIn &msg); + + /** + * Deal with disconnection. + */ + void handleDisconnectMessage(ChatClient &client, MessageIn &msg); + + /** + * Deal with creating a guild. + */ + void handleGuildCreation(ChatClient &client, MessageIn &msg); + + /** + * Deal with inviting a player to a guild. + */ + void handleGuildInvitation(ChatClient &client, MessageIn &msg); + + /** + * Deal with accepting an invite to join a guild. + */ + void handleGuildAcceptInvite(ChatClient &client, MessageIn &msg); + + /** + * Deal with returning all the guild members of a guild. + */ + void handleGuildRetrieveMembers(ChatClient &client, MessageIn &msg); + + /** + * Deal with level change of member + */ + void handleGuildMemberLevelChange(ChatClient &client, MessageIn &msg); + + /** + * Deal with kicking a member + */ + void handleGuildMemberKick(ChatClient &client, MessageIn &msg); + + /** + * Deal with leaving a guild. + */ + void handleGuildQuit(ChatClient &client, MessageIn &msg); + + /** + * Deal with a player joining a party. + * @return Returns whether player successfully joined the party + */ + bool handlePartyJoin(const std::string &invited, + const std::string &inviter); + + /** + * Deal with inviting player to a party + */ + void handlePartyInvite(ChatClient &client, MessageIn &msg); + + /** + * Deal with accepting an invite to join a party + */ + void handlePartyAcceptInvite(ChatClient &client, MessageIn &msg); + + /** + * Deal with leaving a party. + */ + void handlePartyQuit(ChatClient &client); + + /** + * Tell user the invite was rejected + */ + void handlePartyRejection(ChatClient &client, MessageIn &msg); + + /** + * Remove user from party + */ + void removeUserFromParty(ChatClient &client); + + /** + * Send new member info to party members. + */ + void sendPartyMemberInfo(ChatClient &client, MessageIn &msg); + + /** + * Tell all the party members a member has left + */ + void informPartyMemberQuit(ChatClient &client); + + /** + * Tell all the party members a member has joined + */ + void informPartyMemberJoined(ChatClient &client); + + /** + * Tell the player to be more polite. + */ + void warnPlayerAboutBadWords(ChatClient &computer); + + /** + * Say something private to a player. + */ + void sayToPlayer(ChatClient &computer, const std::string &playerName, + const std::string &text); + + /** + * Sends a message to every client in a registered channel. + * + * @param channel the channel to send the message in, must not be NULL + * @param msg the message to be sent + */ + void sendInChannel(ChatChannel *channel, MessageOut &msg); + + /** + * Retrieves the guild channel or creates one automatically + * Automatically makes client join it + * @param The name of the guild (and therefore the channel) + * @param The client to join the channel + * @return Returns the channel joined + */ + ChatChannel *joinGuildChannel(const std::string &name, + ChatClient &client); + + /** + * Returns ChatClient from the Player Map + * @param The name of the character + * @return The Chat Client + */ + ChatClient *getClient(const std::string &name) const; + + /** + * Set the topic of a guild channel + */ + void guildChannelTopicChange(ChatChannel *channel, int playerId, + const std::string &topic); + + /** + * Container for pending clients and pending connections. + */ + TokenCollector mTokenCollector; + friend void registerChatClient(const std::string &, const std::string &, int); +}; + +/** + * Register future client attempt. Temporary until physical server split. + */ +void registerChatClient(const std::string &, const std::string &, int); + +extern ChatHandler *chatHandler; + +#endif diff --git a/src/chat-server/chathandler.hpp b/src/chat-server/chathandler.hpp deleted file mode 100644 index 1cd4306b..00000000 --- a/src/chat-server/chathandler.hpp +++ /dev/null @@ -1,343 +0,0 @@ -/* - * The Mana Server - * Copyright (C) 2004-2010 The Mana World Development Team - * - * This file is part of The Mana Server. - * - * The Mana Server 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 - * any later version. - * - * The Mana Server 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 The Mana Server. If not, see . - */ - -#ifndef CHATHANDLER_H -#define CHATHANDLER_H - -#include -#include -#include - -#include "net/connectionhandler.hpp" -#include "utils/tokencollector.hpp" - -class ChatChannel; -class ChatClient; - -/** - * Manages chat related things like private messaging, chat channel handling - * as well as guild chat. The only form of chat not handled by this server is - * local chat, which is handled by the game server. - * - * @todo b_lindeijer: Extend this class with handling of team chat once - * teams are implemented. - */ -class ChatHandler : public ConnectionHandler -{ - private: - /** - * Data needed for initializing a ChatClient. - */ - struct Pending - { - std::string character; - unsigned char level; - }; - - struct PartyInvite - { - std::string mInviter; - std::string mInvited; - int mPartyId; - }; - - std::map mPlayerMap; - std::vector mPartyInvitedUsers; - - public: - ChatHandler(); - - /** - * Start the handler. - */ - bool startListen(enet_uint16 port, const std::string &host); - - /** - * Tell a list of users about an event in a chatchannel. - * - * @param channel the channel to send the message in, must not be NULL - * @param info information pertaining to the event - */ - void warnUsersAboutPlayerEventInChat(ChatChannel *channel, - const std::string &info, - char eventId); - - /** - * Called by TokenCollector when a client wrongly connected. - */ - void deletePendingClient(ChatClient *); - - /** - * Called by TokenCollector when a client failed to connect. - */ - void deletePendingConnect(Pending *); - - /** - * Called by TokenCollector when a client succesfully connected. - */ - void tokenMatched(ChatClient *, Pending *); - - /** - * Send information about a change in the guild list to guild members. - */ - void sendGuildListUpdate(const std::string &guildName, - const std::string &characterName, - char eventId); - - protected: - /** - * Process chat related messages. - */ - void processMessage(NetComputer *computer, MessageIn &message); - - /** - * Returns a ChatClient instance. - */ - NetComputer *computerConnected(ENetPeer *); - - /** - * Cleans up after the disconnected client. - */ - void computerDisconnected(NetComputer *); - - /** - * Send messages for each guild the character belongs to. - */ - void sendGuildRejoin(ChatClient &computer); - - /** - * Send chat and guild info to chat client, so that they can join the - * correct channels. - */ - void sendGuildEnterChannel(const MessageOut &msg, - const std::string &name); - - /** - * Send guild invite. - */ - void sendGuildInvite(const std::string &invitedName, - const std::string &inviterName, - const std::string &guildName); - - private: - /** - * Deal with command messages. - */ - void handleCommand(ChatClient &client, const std::string &command); - - /** - * Deal with Chat messages. - */ - void handleChatMessage(ChatClient &client, MessageIn &msg); - - /** - * Deal with Announcement messages. - */ - void handleAnnounceMessage(ChatClient &client, MessageIn &msg); - - /** - * Deal with Private messages. - */ - void handlePrivMsgMessage(ChatClient &client, MessageIn &msg); - - /** - * Deal with Who messages. - */ - void handleWhoMessage(ChatClient &client); - - /** - * Deal with player entering channel. - */ - void handleEnterChannelMessage(ChatClient &client, MessageIn &msg); - - /** - * Deal with player changing mode. - */ - void handleModeChangeMessage(ChatClient &client, MessageIn &msg); - - /** - * Deal with player kicking other player from channel. - */ - void handleKickUserMessage(ChatClient &client, MessageIn &msg); - - /** - * Deal with player leaving channel. - */ - void handleQuitChannelMessage(ChatClient &client, MessageIn &msg); - - /** - * Deal with listing all accessible channels. - */ - void handleListChannelsMessage(ChatClient &client, MessageIn &msg); - - /** - * Deal with listing all channel users in a channel. - */ - void handleListChannelUsersMessage(ChatClient &client, MessageIn &msg); - - /** - * Deal with changing a channel's topic - */ - void handleTopicChange(ChatClient &client, MessageIn &msg); - - /** - * Deal with disconnection. - */ - void handleDisconnectMessage(ChatClient &client, MessageIn &msg); - - /** - * Deal with creating a guild. - */ - void handleGuildCreation(ChatClient &client, MessageIn &msg); - - /** - * Deal with inviting a player to a guild. - */ - void handleGuildInvitation(ChatClient &client, MessageIn &msg); - - /** - * Deal with accepting an invite to join a guild. - */ - void handleGuildAcceptInvite(ChatClient &client, MessageIn &msg); - - /** - * Deal with returning all the guild members of a guild. - */ - void handleGuildRetrieveMembers(ChatClient &client, MessageIn &msg); - - /** - * Deal with level change of member - */ - void handleGuildMemberLevelChange(ChatClient &client, MessageIn &msg); - - /** - * Deal with kicking a member - */ - void handleGuildMemberKick(ChatClient &client, MessageIn &msg); - - /** - * Deal with leaving a guild. - */ - void handleGuildQuit(ChatClient &client, MessageIn &msg); - - /** - * Deal with a player joining a party. - * @return Returns whether player successfully joined the party - */ - bool handlePartyJoin(const std::string &invited, - const std::string &inviter); - - /** - * Deal with inviting player to a party - */ - void handlePartyInvite(ChatClient &client, MessageIn &msg); - - /** - * Deal with accepting an invite to join a party - */ - void handlePartyAcceptInvite(ChatClient &client, MessageIn &msg); - - /** - * Deal with leaving a party. - */ - void handlePartyQuit(ChatClient &client); - - /** - * Tell user the invite was rejected - */ - void handlePartyRejection(ChatClient &client, MessageIn &msg); - - /** - * Remove user from party - */ - void removeUserFromParty(ChatClient &client); - - /** - * Send new member info to party members. - */ - void sendPartyMemberInfo(ChatClient &client, MessageIn &msg); - - /** - * Tell all the party members a member has left - */ - void informPartyMemberQuit(ChatClient &client); - - /** - * Tell all the party members a member has joined - */ - void informPartyMemberJoined(ChatClient &client); - - /** - * Tell the player to be more polite. - */ - void warnPlayerAboutBadWords(ChatClient &computer); - - /** - * Say something private to a player. - */ - void sayToPlayer(ChatClient &computer, const std::string &playerName, - const std::string &text); - - /** - * Sends a message to every client in a registered channel. - * - * @param channel the channel to send the message in, must not be NULL - * @param msg the message to be sent - */ - void sendInChannel(ChatChannel *channel, MessageOut &msg); - - /** - * Retrieves the guild channel or creates one automatically - * Automatically makes client join it - * @param The name of the guild (and therefore the channel) - * @param The client to join the channel - * @return Returns the channel joined - */ - ChatChannel *joinGuildChannel(const std::string &name, - ChatClient &client); - - /** - * Returns ChatClient from the Player Map - * @param The name of the character - * @return The Chat Client - */ - ChatClient *getClient(const std::string &name) const; - - /** - * Set the topic of a guild channel - */ - void guildChannelTopicChange(ChatChannel *channel, int playerId, - const std::string &topic); - - /** - * Container for pending clients and pending connections. - */ - TokenCollector mTokenCollector; - friend void registerChatClient(const std::string &, const std::string &, int); -}; - -/** - * Register future client attempt. Temporary until physical server split. - */ -void registerChatClient(const std::string &, const std::string &, int); - -extern ChatHandler *chatHandler; - -#endif diff --git a/src/chat-server/guild.cpp b/src/chat-server/guild.cpp index 3807b68f..ba1fdae1 100644 --- a/src/chat-server/guild.cpp +++ b/src/chat-server/guild.cpp @@ -18,7 +18,7 @@ * along with The Mana Server. If not, see . */ -#include "guild.hpp" +#include "guild.h" #include "defines.h" #include diff --git a/src/chat-server/guild.h b/src/chat-server/guild.h new file mode 100644 index 00000000..e9207a31 --- /dev/null +++ b/src/chat-server/guild.h @@ -0,0 +1,149 @@ +/* + * The Mana Server + * Copyright (C) 2004-2010 The Mana World Development Team + * + * This file is part of The Mana Server. + * + * The Mana Server 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 + * any later version. + * + * The Mana Server 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 The Mana Server. If not, see . + */ + +#ifndef CHATSERVER_GUILD_H +#define CHATSERVER_GUILD_H + +#include +#include + +/** + * Guild members + */ + +struct GuildMember +{ +public: + int mId; + std::string mName; + int mPermissions; +}; + +/** + * A guild and its members. + */ +class Guild +{ + public: + /** + * Constructor. + */ + Guild(const std::string &name); + + /** + * Destructor. + */ + ~Guild(); + + /** + * Add a member to the guild. + * Removes a user from invite list if on it + */ + void addMember(int playerId, int permissions = 0); + + /** + * Remove a member from the guild. + */ + void removeMember(int playerId); + + /** + * Return owner id + */ + int getOwner() const; + + /** + * Set player as owner of the guild. + */ + void setOwner(int playerId); + + /** + * Set the ID of the guild. + */ + void setId(int id) + { mId = id; } + + /** + * Check if player has been invited to the guild. + */ + bool checkInvited(int playerId) const; + + /** + * Add a player to the invite list. + */ + void addInvited(int playerId); + + /** + * Returns the name of the guild. + */ + std::string getName() const + { return mName; } + + /** + * Returns the ID of the guild. + */ + int getId() const + { return mId; } + + /** + * Returns a list of the members in this guild. + */ + std::list getMembers() const + { return mMembers; } + + /** + * Returns the number of members in the guild. + */ + int memberCount() const + { return mMembers.size(); } + + /** + * Find member by name. + */ + bool checkInGuild(int playerId) const; + + /** + * Returns whether a user can invite + */ + bool canInvite(int playerId) const; + + /** + * Returns a users permissions + */ + int getUserPermissions(int playerId) const; + + /** + * Sets a users permissions + */ + void setUserPermissions(int playerId, int level); + + protected: + /** + * Searches for a guild member by player ID + */ + GuildMember *getMember(int playerId) const; + + private: + short mId; + std::string mName; + std::list mMembers; + std::list mInvited; +}; + +#endif diff --git a/src/chat-server/guild.hpp b/src/chat-server/guild.hpp deleted file mode 100644 index e9207a31..00000000 --- a/src/chat-server/guild.hpp +++ /dev/null @@ -1,149 +0,0 @@ -/* - * The Mana Server - * Copyright (C) 2004-2010 The Mana World Development Team - * - * This file is part of The Mana Server. - * - * The Mana Server 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 - * any later version. - * - * The Mana Server 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 The Mana Server. If not, see . - */ - -#ifndef CHATSERVER_GUILD_H -#define CHATSERVER_GUILD_H - -#include -#include - -/** - * Guild members - */ - -struct GuildMember -{ -public: - int mId; - std::string mName; - int mPermissions; -}; - -/** - * A guild and its members. - */ -class Guild -{ - public: - /** - * Constructor. - */ - Guild(const std::string &name); - - /** - * Destructor. - */ - ~Guild(); - - /** - * Add a member to the guild. - * Removes a user from invite list if on it - */ - void addMember(int playerId, int permissions = 0); - - /** - * Remove a member from the guild. - */ - void removeMember(int playerId); - - /** - * Return owner id - */ - int getOwner() const; - - /** - * Set player as owner of the guild. - */ - void setOwner(int playerId); - - /** - * Set the ID of the guild. - */ - void setId(int id) - { mId = id; } - - /** - * Check if player has been invited to the guild. - */ - bool checkInvited(int playerId) const; - - /** - * Add a player to the invite list. - */ - void addInvited(int playerId); - - /** - * Returns the name of the guild. - */ - std::string getName() const - { return mName; } - - /** - * Returns the ID of the guild. - */ - int getId() const - { return mId; } - - /** - * Returns a list of the members in this guild. - */ - std::list getMembers() const - { return mMembers; } - - /** - * Returns the number of members in the guild. - */ - int memberCount() const - { return mMembers.size(); } - - /** - * Find member by name. - */ - bool checkInGuild(int playerId) const; - - /** - * Returns whether a user can invite - */ - bool canInvite(int playerId) const; - - /** - * Returns a users permissions - */ - int getUserPermissions(int playerId) const; - - /** - * Sets a users permissions - */ - void setUserPermissions(int playerId, int level); - - protected: - /** - * Searches for a guild member by player ID - */ - GuildMember *getMember(int playerId) const; - - private: - short mId; - std::string mName; - std::list mMembers; - std::list mInvited; -}; - -#endif diff --git a/src/chat-server/guildhandler.cpp b/src/chat-server/guildhandler.cpp index 63d69b6f..e6970182 100644 --- a/src/chat-server/guildhandler.cpp +++ b/src/chat-server/guildhandler.cpp @@ -18,18 +18,18 @@ * along with The Mana Server. If not, see . */ -#include "chathandler.hpp" -#include "chatchannel.hpp" -#include "chatchannelmanager.hpp" -#include "chatclient.hpp" -#include "guild.hpp" -#include "guildmanager.hpp" - -#include "account-server/character.hpp" -#include "account-server/storage.hpp" - -#include "net/messagein.hpp" -#include "net/messageout.hpp" +#include "chathandler.h" +#include "chatchannel.h" +#include "chatchannelmanager.h" +#include "chatclient.h" +#include "guild.h" +#include "guildmanager.h" + +#include "account-server/character.h" +#include "account-server/storage.h" + +#include "net/messagein.h" +#include "net/messageout.h" #include "protocol.h" diff --git a/src/chat-server/guildmanager.cpp b/src/chat-server/guildmanager.cpp index 81dd609f..586878d7 100644 --- a/src/chat-server/guildmanager.cpp +++ b/src/chat-server/guildmanager.cpp @@ -18,13 +18,13 @@ * along with The Mana Server. If not, see . */ -#include "guildmanager.hpp" -#include "guild.hpp" +#include "guildmanager.h" +#include "guild.h" #include "protocol.h" #include "defines.h" -#include "account-server/storage.hpp" -#include "chat-server/chatclient.hpp" -#include "chat-server/chathandler.hpp" +#include "account-server/storage.h" +#include "chat-server/chatclient.h" +#include "chat-server/chathandler.h" GuildManager::GuildManager() { diff --git a/src/chat-server/guildmanager.h b/src/chat-server/guildmanager.h new file mode 100644 index 00000000..b236b75c --- /dev/null +++ b/src/chat-server/guildmanager.h @@ -0,0 +1,119 @@ +/* + * The Mana Server + * Copyright (C) 2004-2010 The Mana World Development Team + * + * This file is part of The Mana Server. + * + * The Mana Server 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 + * any later version. + * + * The Mana Server 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 The Mana Server. If not, see . + */ + +#ifndef CHATSERVER_GUILDMANAGER_H +#define CHATSERVER_GUILDMANAGER_H + +#include +#include +#include + +class Guild; +class ChatClient; + +/** + * Guild manager takes care of creating, removing and modifying guilds. + */ +class GuildManager +{ + public: + GuildManager(); + ~GuildManager(); + + /** + * Creates a guild. + */ + Guild *createGuild(const std::string &name, int playerId); + + /** + * Removes a guild. + */ + void removeGuild(Guild *guild); + + /** + * Adds a member to a guild. + */ + void addGuildMember(Guild *guild, int playerId); + + /** + * Removes a member from a guild. + */ + void removeGuildMember(Guild *guild, int playerId); + + /** + * Returns the guild with the given id. O(n) + * + * @todo b_lindeijer: Since this method is used so often, its + * efficiency should be improved, probably by storing the guilds + * in a map instead of list. + * + * @return the guild with the given id, or NULL if it doesn't exist + */ + Guild *findById(short id) const; + + /** + * Returns the guild with the given name. O(n) + * + * @return the guild with the given name, or NULL if it doesn't exist + */ + Guild *findByName(const std::string &name) const; + + /** + * Returns whether a guild exists. + */ + bool doesExist(const std::string &name) const; + + /** + * Return the guilds a character is in + */ + std::vector getGuildsForPlayer(int playerId) const; + + /** + * Inform guild members that a player has disconnected. + */ + void disconnectPlayer(ChatClient* player); + + /** + * Promote a guild member to higher level or + * Demote a guild member to a lower level + * + * @return Returns 0 if successful, -1 otherwise + */ + int changeMemberLevel(ChatClient *player, Guild *guild, + int playerId, int level); + + /** + * Check if the player already owns a guild + */ + bool alreadyOwner(int playerId) const; + + /** + * Set user rights + */ + void setUserRights(Guild *guild, int playerId, int rights); + + private: + std::list mGuilds; + std::list mOwners; +}; + +extern GuildManager *guildManager; + +#endif diff --git a/src/chat-server/guildmanager.hpp b/src/chat-server/guildmanager.hpp deleted file mode 100644 index b236b75c..00000000 --- a/src/chat-server/guildmanager.hpp +++ /dev/null @@ -1,119 +0,0 @@ -/* - * The Mana Server - * Copyright (C) 2004-2010 The Mana World Development Team - * - * This file is part of The Mana Server. - * - * The Mana Server 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 - * any later version. - * - * The Mana Server 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 The Mana Server. If not, see . - */ - -#ifndef CHATSERVER_GUILDMANAGER_H -#define CHATSERVER_GUILDMANAGER_H - -#include -#include -#include - -class Guild; -class ChatClient; - -/** - * Guild manager takes care of creating, removing and modifying guilds. - */ -class GuildManager -{ - public: - GuildManager(); - ~GuildManager(); - - /** - * Creates a guild. - */ - Guild *createGuild(const std::string &name, int playerId); - - /** - * Removes a guild. - */ - void removeGuild(Guild *guild); - - /** - * Adds a member to a guild. - */ - void addGuildMember(Guild *guild, int playerId); - - /** - * Removes a member from a guild. - */ - void removeGuildMember(Guild *guild, int playerId); - - /** - * Returns the guild with the given id. O(n) - * - * @todo b_lindeijer: Since this method is used so often, its - * efficiency should be improved, probably by storing the guilds - * in a map instead of list. - * - * @return the guild with the given id, or NULL if it doesn't exist - */ - Guild *findById(short id) const; - - /** - * Returns the guild with the given name. O(n) - * - * @return the guild with the given name, or NULL if it doesn't exist - */ - Guild *findByName(const std::string &name) const; - - /** - * Returns whether a guild exists. - */ - bool doesExist(const std::string &name) const; - - /** - * Return the guilds a character is in - */ - std::vector getGuildsForPlayer(int playerId) const; - - /** - * Inform guild members that a player has disconnected. - */ - void disconnectPlayer(ChatClient* player); - - /** - * Promote a guild member to higher level or - * Demote a guild member to a lower level - * - * @return Returns 0 if successful, -1 otherwise - */ - int changeMemberLevel(ChatClient *player, Guild *guild, - int playerId, int level); - - /** - * Check if the player already owns a guild - */ - bool alreadyOwner(int playerId) const; - - /** - * Set user rights - */ - void setUserRights(Guild *guild, int playerId, int rights); - - private: - std::list mGuilds; - std::list mOwners; -}; - -extern GuildManager *guildManager; - -#endif diff --git a/src/chat-server/party.cpp b/src/chat-server/party.cpp index e9f193ba..0719e8ff 100644 --- a/src/chat-server/party.cpp +++ b/src/chat-server/party.cpp @@ -18,7 +18,7 @@ * along with The Mana Server. If not, see . */ -#include "party.hpp" +#include "party.h" #include diff --git a/src/chat-server/party.h b/src/chat-server/party.h new file mode 100644 index 00000000..29bb7f21 --- /dev/null +++ b/src/chat-server/party.h @@ -0,0 +1,63 @@ +/* + * The Mana Server + * Copyright (C) 2008-2010 The Mana World Development Team + * + * This file is part of The Mana Server. + * + * The Mana Server 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 + * any later version. + * + * The Mana Server 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 The Mana Server. If not, see . + */ + +#ifndef PARTY_H +#define PARTY_H + +#include +#include + +/** + * A party that contains 1 or more characters to play together + */ +class Party +{ +public: + typedef std::vector PartyUsers; + + /** Constructor */ + Party(); + + /** + * Add user to party + */ + void addUser(const std::string &name); + + /** + * Remove user from party + */ + void removeUser(const std::string &name); + + /** + * Return number of users in party + */ + unsigned int userCount() const { return mUsers.size(); } + + /** + * Return the party id + */ + unsigned int getId() const { return mId; } + +private: + PartyUsers mUsers; + unsigned int mId; +}; + +#endif diff --git a/src/chat-server/party.hpp b/src/chat-server/party.hpp deleted file mode 100644 index 29bb7f21..00000000 --- a/src/chat-server/party.hpp +++ /dev/null @@ -1,63 +0,0 @@ -/* - * The Mana Server - * Copyright (C) 2008-2010 The Mana World Development Team - * - * This file is part of The Mana Server. - * - * The Mana Server 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 - * any later version. - * - * The Mana Server 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 The Mana Server. If not, see . - */ - -#ifndef PARTY_H -#define PARTY_H - -#include -#include - -/** - * A party that contains 1 or more characters to play together - */ -class Party -{ -public: - typedef std::vector PartyUsers; - - /** Constructor */ - Party(); - - /** - * Add user to party - */ - void addUser(const std::string &name); - - /** - * Remove user from party - */ - void removeUser(const std::string &name); - - /** - * Return number of users in party - */ - unsigned int userCount() const { return mUsers.size(); } - - /** - * Return the party id - */ - unsigned int getId() const { return mId; } - -private: - PartyUsers mUsers; - unsigned int mId; -}; - -#endif diff --git a/src/chat-server/partyhandler.cpp b/src/chat-server/partyhandler.cpp index e3d8e098..3a9b845d 100644 --- a/src/chat-server/partyhandler.cpp +++ b/src/chat-server/partyhandler.cpp @@ -18,15 +18,15 @@ * along with The Mana Server. If not, see . */ -#include "chathandler.hpp" -#include "chatclient.hpp" -#include "party.hpp" +#include "chathandler.h" +#include "chatclient.h" +#include "party.h" -#include "account-server/storage.hpp" -#include "account-server/serverhandler.hpp" +#include "account-server/storage.h" +#include "account-server/serverhandler.h" -#include "net/messagein.hpp" -#include "net/messageout.hpp" +#include "net/messagein.h" +#include "net/messageout.h" #include "protocol.h" diff --git a/src/chat-server/post.cpp b/src/chat-server/post.cpp index 456b09f9..eff5ddb3 100644 --- a/src/chat-server/post.cpp +++ b/src/chat-server/post.cpp @@ -18,15 +18,14 @@ * along with The Mana Server. If not, see . */ -#include "post.hpp" +#include "post.h" -#include "../account-server/character.hpp" -#include "../common/configuration.hpp" +#include "../account-server/character.h" +#include "../common/configuration.h" Letter::Letter(unsigned int type, Character *sender, Character *receiver) : mId(0), mType(type), mSender(sender), mReceiver(receiver) { - } Letter::~Letter() diff --git a/src/chat-server/post.h b/src/chat-server/post.h new file mode 100644 index 00000000..1cb4072c --- /dev/null +++ b/src/chat-server/post.h @@ -0,0 +1,185 @@ +/* + * The Mana Server + * Copyright (C) 2008-2010 The Mana World Development Team + * + * This file is part of The Mana Server. + * + * The Mana Server 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 + * any later version. + * + * The Mana Server 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 The Mana Server. If not, see . + */ + +#ifndef POST_H +#define POST_H + +#include +#include +#include + +#include "../common/inventorydata.h" + +class Item; +class Character; + +class Letter +{ +public: + /** + * Constructor. + * + * Before the letter is stored in the database, the unique Id of the letter + * is 0. + * @param type Type of Letter - unused + * @param sender Pointer to character that sent the letter + * @param receiver Pointer to character that will receive the letter + */ + Letter(unsigned int type, Character *sender, Character *receiver); + + /** + * Destructor + */ + ~Letter(); + + /** + * Gets the unique Id of the letter. + */ + unsigned long getId() const + { return mId; } + + /** + * Sets the unique Id of the letter used as primary key in the database. + * @param Id Unique id of the letter. + */ + void setId(unsigned long Id) + { mId = Id; } + + /** + * Gets the type of the letter. (unused) + */ + unsigned int getType() const + { return mType; } + + /** + * Set the expiry + */ + void setExpiry(unsigned long expiry); + + /** + * Get the expiry + */ + unsigned long getExpiry() const; + + /** + * Add text contents of letter + * This overwrites whatever was there previously + * @param text The content of the letter to add + */ + void addText(const std::string &text); + + /** + * Get the text contents of letter + * @return String containing the text + */ + std::string getContents() const; + + /** + * Add an attachment + * @param item The attachment to add to the letter + * @return Returns true if the letter doesnt have too many attachments + */ + bool addAttachment(InventoryItem item); + + /** + * Get the character receiving the letter + * @return Returns the Character who will receive the letter + */ + Character *getReceiver() const; + + /** + * Get the character who sent the letter + * @return Returns the Character who sent the letter + */ + Character *getSender() const; + + /** + * Get the attachments + */ + std::vector getAttachments() const; + +private: + unsigned int mId; + unsigned int mType; + unsigned long mExpiry; + std::string mContents; + std::vector mAttachments; + Character *mSender; + Character *mReceiver; +}; + +class Post +{ +public: + /** + * Destructor + */ + ~Post(); + + /** + * Add letter to post + * @param letter Letter to add + * @return Returns true if post isnt full + */ + bool addLetter(Letter *letter); + + /** + * Return next letter + */ + Letter* getLetter(int letter) const; + + /** + * Return number of letters in post + * @return Returns the size of mLetters + */ + unsigned int getNumberOfLetters() const; + +private: + std::vector mLetters; +}; + +class PostManager +{ +public: + /** + * Add letter to post box + * @param letter Letter to add + */ + void addLetter(Letter *letter); + + /** + * Get post for character + * @param player Character that is getting post + * @return Returns the post for that character + */ + Post *getPost(Character *player) const; + + /** + * Remove the post for character + */ + void clearPost(Character *player); + +private: + std::map mPostBox; +}; + +extern PostManager *postalManager; + +#endif diff --git a/src/chat-server/post.hpp b/src/chat-server/post.hpp deleted file mode 100644 index 01ded791..00000000 --- a/src/chat-server/post.hpp +++ /dev/null @@ -1,185 +0,0 @@ -/* - * The Mana Server - * Copyright (C) 2008-2010 The Mana World Development Team - * - * This file is part of The Mana Server. - * - * The Mana Server 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 - * any later version. - * - * The Mana Server 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 The Mana Server. If not, see . - */ - -#ifndef POST_H -#define POST_H - -#include -#include -#include - -#include "../common/inventorydata.hpp" - -class Item; -class Character; - -class Letter -{ -public: - /** - * Constructor. - * - * Before the letter is stored in the database, the unique Id of the letter - * is 0. - * @param type Type of Letter - unused - * @param sender Pointer to character that sent the letter - * @param receiver Pointer to character that will receive the letter - */ - Letter(unsigned int type, Character *sender, Character *receiver); - - /** - * Destructor - */ - ~Letter(); - - /** - * Gets the unique Id of the letter. - */ - unsigned long getId() const - { return mId; } - - /** - * Sets the unique Id of the letter used as primary key in the database. - * @param Id Unique id of the letter. - */ - void setId(unsigned long Id) - { mId = Id; } - - /** - * Gets the type of the letter. (unused) - */ - unsigned int getType() const - { return mType; } - - /** - * Set the expiry - */ - void setExpiry(unsigned long expiry); - - /** - * Get the expiry - */ - unsigned long getExpiry() const; - - /** - * Add text contents of letter - * This overwrites whatever was there previously - * @param text The content of the letter to add - */ - void addText(const std::string &text); - - /** - * Get the text contents of letter - * @return String containing the text - */ - std::string getContents() const; - - /** - * Add an attachment - * @param item The attachment to add to the letter - * @return Returns true if the letter doesnt have too many attachments - */ - bool addAttachment(InventoryItem item); - - /** - * Get the character receiving the letter - * @return Returns the Character who will receive the letter - */ - Character *getReceiver() const; - - /** - * Get the character who sent the letter - * @return Returns the Character who sent the letter - */ - Character *getSender() const; - - /** - * Get the attachments - */ - std::vector getAttachments() const; - -private: - unsigned int mId; - unsigned int mType; - unsigned long mExpiry; - std::string mContents; - std::vector mAttachments; - Character *mSender; - Character *mReceiver; -}; - -class Post -{ -public: - /** - * Destructor - */ - ~Post(); - - /** - * Add letter to post - * @param letter Letter to add - * @return Returns true if post isnt full - */ - bool addLetter(Letter *letter); - - /** - * Return next letter - */ - Letter* getLetter(int letter) const; - - /** - * Return number of letters in post - * @return Returns the size of mLetters - */ - unsigned int getNumberOfLetters() const; - -private: - std::vector mLetters; -}; - -class PostManager -{ -public: - /** - * Add letter to post box - * @param letter Letter to add - */ - void addLetter(Letter *letter); - - /** - * Get post for character - * @param player Character that is getting post - * @return Returns the post for that character - */ - Post *getPost(Character *player) const; - - /** - * Remove the post for character - */ - void clearPost(Character *player); - -private: - std::map mPostBox; -}; - -extern PostManager *postalManager; - -#endif diff --git a/src/common/configuration.cpp b/src/common/configuration.cpp index a0e2ab2e..6b79b85e 100644 --- a/src/common/configuration.cpp +++ b/src/common/configuration.cpp @@ -23,11 +23,11 @@ #include #include -#include "common/configuration.hpp" +#include "common/configuration.h" #include "utils/logger.h" -#include "utils/xml.hpp" -#include "utils/string.hpp" +#include "utils/xml.h" +#include "utils/string.h" /**< Persistent configuration. */ static std::map< std::string, std::string > options; diff --git a/src/common/configuration.h b/src/common/configuration.h new file mode 100644 index 00000000..dbb0a7d4 --- /dev/null +++ b/src/common/configuration.h @@ -0,0 +1,64 @@ +/* + * The Mana Server + * Copyright (C) 2004-2010 The Mana World Development Team + * Copyright (C) 2010 The Mana Developers + * + * This file is part of The Mana Server. + * + * The Mana Server 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 + * any later version. + * + * The Mana Server 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 The Mana Server. If not, see . + */ + +#ifndef CONFIGURATION_H +#define CONFIGURATION_H + +#include + +namespace Configuration +{ + /** + * Loads the configuration options into memory. + * @param filename path to the configuration file . + * @return whether the configuration file could be read + */ + bool initialize(const std::string &filename); + + void deinitialize(); + + /** + * Gets an option as a string. + * @param key option identifier. + * @param deflt default value. + */ + std::string getValue(const std::string &key, const std::string &deflt); + + /** + * Gets an option as an integer. + * @param key option identifier. + * @param deflt default value. + */ + int getValue(const std::string &key, int deflt); + + /** + * Gets an option as a boolean. + * @param key option identifier. + * @param deflt default value. + */ + bool getBoolValue(const std::string &key, bool deflt); +} + +#ifndef DEFAULT_SERVER_PORT +#define DEFAULT_SERVER_PORT 9601 +#endif + +#endif // CONFIGURATION_H diff --git a/src/common/configuration.hpp b/src/common/configuration.hpp deleted file mode 100644 index dbb0a7d4..00000000 --- a/src/common/configuration.hpp +++ /dev/null @@ -1,64 +0,0 @@ -/* - * The Mana Server - * Copyright (C) 2004-2010 The Mana World Development Team - * Copyright (C) 2010 The Mana Developers - * - * This file is part of The Mana Server. - * - * The Mana Server 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 - * any later version. - * - * The Mana Server 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 The Mana Server. If not, see . - */ - -#ifndef CONFIGURATION_H -#define CONFIGURATION_H - -#include - -namespace Configuration -{ - /** - * Loads the configuration options into memory. - * @param filename path to the configuration file . - * @return whether the configuration file could be read - */ - bool initialize(const std::string &filename); - - void deinitialize(); - - /** - * Gets an option as a string. - * @param key option identifier. - * @param deflt default value. - */ - std::string getValue(const std::string &key, const std::string &deflt); - - /** - * Gets an option as an integer. - * @param key option identifier. - * @param deflt default value. - */ - int getValue(const std::string &key, int deflt); - - /** - * Gets an option as a boolean. - * @param key option identifier. - * @param deflt default value. - */ - bool getBoolValue(const std::string &key, bool deflt); -} - -#ifndef DEFAULT_SERVER_PORT -#define DEFAULT_SERVER_PORT 9601 -#endif - -#endif // CONFIGURATION_H diff --git a/src/common/inventorydata.h b/src/common/inventorydata.h new file mode 100644 index 00000000..4d5336a1 --- /dev/null +++ b/src/common/inventorydata.h @@ -0,0 +1,61 @@ +/* + * The Mana Server + * Copyright (C) 2007-2010 The Mana World Development Team + * + * This file is part of The Mana Server. + * + * The Mana Server 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 + * any later version. + * + * The Mana Server 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 The Mana Server. If not, see . + */ + +#ifndef COMMON_INVENTORYDATA_H +#define COMMON_INVENTORYDATA_H + +#include +#include + +/** + * Numbers of inventory slots + */ + +enum +{ + INVENTORY_SLOTS = 50 +}; + +/** + * Structure storing an item in the inventory. + * When the itemId is zero, this item represents "amount" consecutive empty slots. + */ + +struct InventoryItem +{ + unsigned int itemId; + unsigned int amount; +}; +// slot id -> { item } +typedef std::map< unsigned short, InventoryItem > InventoryData; +// equip slot type -> { slot ids } +// Equipment taking up multiple slots will be referenced multiple times +typedef std::multimap< unsigned int, unsigned int > EquipData; + +/** + * Structure storing the equipment and inventory of a Player. + */ +struct Possessions +{ + InventoryData inventory; + EquipData equipSlots; +}; + +#endif diff --git a/src/common/inventorydata.hpp b/src/common/inventorydata.hpp deleted file mode 100644 index cf7ba1bf..00000000 --- a/src/common/inventorydata.hpp +++ /dev/null @@ -1,61 +0,0 @@ -/* - * The Mana Server - * Copyright (C) 2007-2010 The Mana World Development Team - * - * This file is part of The Mana Server. - * - * The Mana Server 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 - * any later version. - * - * The Mana Server 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 The Mana Server. If not, see . - */ - -#ifndef COMMON_INVENTORYDATA_HPP -#define COMMON_INVENTORYDATA_HPP - -#include -#include - -/** - * Numbers of inventory slots - */ - -enum -{ - INVENTORY_SLOTS = 50 -}; - -/** - * Structure storing an item in the inventory. - * When the itemId is zero, this item represents "amount" consecutive empty slots. - */ - -struct InventoryItem -{ - unsigned int itemId; - unsigned int amount; -}; -// slot id -> { item } -typedef std::map< unsigned short, InventoryItem > InventoryData; -// equip slot type -> { slot ids } -// Equipment taking up multiple slots will be referenced multiple times -typedef std::multimap< unsigned int, unsigned int > EquipData; - -/** - * Structure storing the equipment and inventory of a Player. - */ -struct Possessions -{ - InventoryData inventory; - EquipData equipSlots; -}; - -#endif diff --git a/src/common/permissionmanager.cpp b/src/common/permissionmanager.cpp index 8483e42e..a2c67cd4 100644 --- a/src/common/permissionmanager.cpp +++ b/src/common/permissionmanager.cpp @@ -18,12 +18,12 @@ * along with The Mana Server. If not, see . */ -#include "common/permissionmanager.hpp" +#include "common/permissionmanager.h" -#include "common/resourcemanager.hpp" -#include "game-server/character.hpp" +#include "common/resourcemanager.h" +#include "game-server/character.h" #include "utils/logger.h" -#include "utils/xml.hpp" +#include "utils/xml.h" #include #include diff --git a/src/common/permissionmanager.h b/src/common/permissionmanager.h new file mode 100644 index 00000000..bf36f658 --- /dev/null +++ b/src/common/permissionmanager.h @@ -0,0 +1,71 @@ +/* + * The Mana Server + * Copyright (C) 2010-2010 The Mana World Development Team + * + * This file is part of The Mana Server. + * + * The Mana Server 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 + * any later version. + * + * The Mana Server 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 The Mana Server. If not, see . + */ + +#ifndef PERMISSIONMANAGER_H +#define PERMISSIONMANAGER_H + +#include +#include +#include + +class Character; + +namespace PermissionManager +{ + enum Result + { + PMR_UNKNOWN, + PMR_DENIED, + PMR_ALLOWED + }; + /** + * Loads permission file. + */ + void initialize(const std::string &); + + /** + * Reloads permission file. + */ + void reload(); + + /** + * Returns if the characters account has the given permission + */ + Result checkPermission(const Character* character, std::string permission); + Result checkPermission(unsigned char level, std::string permission); + + /** + * Gets the permission class bitmask of a class alias + */ + unsigned char getMaskFromAlias(const std::string & alias); + + /** + * Gets a list of all permissions the character is having + */ + std::list getPermissionList(const Character* character); + + /** + * Gets a list of all permissions classes the character is having + */ + std::list getClassList(const Character* character); + +} // namespace PermissionManager + +#endif // PERMISSIONMANAGER_H diff --git a/src/common/permissionmanager.hpp b/src/common/permissionmanager.hpp deleted file mode 100644 index 5ef951be..00000000 --- a/src/common/permissionmanager.hpp +++ /dev/null @@ -1,71 +0,0 @@ -/* - * The Mana Server - * Copyright (C) 2010-2010 The Mana World Development Team - * - * This file is part of The Mana Server. - * - * The Mana Server 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 - * any later version. - * - * The Mana Server 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 The Mana Server. If not, see . - */ - -#ifndef PERMISSIONMANAGER_HPP -#define PERMISSIONMANAGER_HPP - -#include -#include -#include - -class Character; - -namespace PermissionManager -{ - enum Result - { - PMR_UNKNOWN, - PMR_DENIED, - PMR_ALLOWED - }; - /** - * Loads permission file. - */ - void initialize(const std::string &); - - /** - * Reloads permission file. - */ - void reload(); - - /** - * Returns if the characters account has the given permission - */ - Result checkPermission(const Character* character, std::string permission); - Result checkPermission(unsigned char level, std::string permission); - - /** - * Gets the permission class bitmask of a class alias - */ - unsigned char getMaskFromAlias(const std::string & alias); - - /** - * Gets a list of all permissions the character is having - */ - std::list getPermissionList(const Character* character); - - /** - * Gets a list of all permissions classes the character is having - */ - std::list getClassList(const Character* character); - -} // namespace PermissionManager - -#endif // PERMISSIONMANAGER_HPP diff --git a/src/common/resourcemanager.cpp b/src/common/resourcemanager.cpp index 9c52a8e7..b32c6ff7 100644 --- a/src/common/resourcemanager.cpp +++ b/src/common/resourcemanager.cpp @@ -18,9 +18,9 @@ * along with The Mana Server. If not, see . */ -#include "common/resourcemanager.hpp" +#include "common/resourcemanager.h" -#include "common/configuration.hpp" +#include "common/configuration.h" #include "utils/logger.h" diff --git a/src/common/resourcemanager.h b/src/common/resourcemanager.h new file mode 100644 index 00000000..3d722a46 --- /dev/null +++ b/src/common/resourcemanager.h @@ -0,0 +1,72 @@ +/* + * The Mana Server + * Copyright (C) 2004-2010 The Mana World Development Team + * + * This file is part of The Mana Server. + * + * The Mana Server 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 + * any later version. + * + * The Mana Server 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 The Mana Server. If not, see . + */ + +#ifndef RESOURCE_MANAGER_H +#define RESOURCE_MANAGER_H + +#include + +namespace ResourceManager +{ + // A structure retaining the path and file names separately. + struct splittedPath + { + std::string path; + std::string file; + }; + + /** + * Searches for zip files and adds them to PhysFS search path. + */ + void initialize(); + + /** + * Checks whether the given file or directory exists in the search path + */ + bool exists(const std::string &path, bool lookInSearchPath = true); + + /** + * Returns the real file-system path of the resource with the given + * resource path, or an empty string when no such resource exists. + */ + std::string resolve(const std::string &path); + + /** + * Allocates data into a buffer pointer for raw data loading. The + * returned data is expected to be freed using free(). + * + * @param fileName The name of the file to be loaded. + * @param fileSize The size of the file that was loaded. + * + * @return An allocated byte array containing the data that was loaded, + * or NULL on failure. + * @note The array contains an extra \0 character at position fileSize. + */ + char *loadFile(const std::string &fileName, int &fileSize); + + /** + * Returns the filePath sub-part corresponding to the filename only. + * @return splittedPath: the file path ending with '/' or '\' + * and the file name alone. + */ + splittedPath splitFileNameAndPath(const std::string &fullFilePath); +} + +#endif diff --git a/src/common/resourcemanager.hpp b/src/common/resourcemanager.hpp deleted file mode 100644 index 3d722a46..00000000 --- a/src/common/resourcemanager.hpp +++ /dev/null @@ -1,72 +0,0 @@ -/* - * The Mana Server - * Copyright (C) 2004-2010 The Mana World Development Team - * - * This file is part of The Mana Server. - * - * The Mana Server 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 - * any later version. - * - * The Mana Server 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 The Mana Server. If not, see . - */ - -#ifndef RESOURCE_MANAGER_H -#define RESOURCE_MANAGER_H - -#include - -namespace ResourceManager -{ - // A structure retaining the path and file names separately. - struct splittedPath - { - std::string path; - std::string file; - }; - - /** - * Searches for zip files and adds them to PhysFS search path. - */ - void initialize(); - - /** - * Checks whether the given file or directory exists in the search path - */ - bool exists(const std::string &path, bool lookInSearchPath = true); - - /** - * Returns the real file-system path of the resource with the given - * resource path, or an empty string when no such resource exists. - */ - std::string resolve(const std::string &path); - - /** - * Allocates data into a buffer pointer for raw data loading. The - * returned data is expected to be freed using free(). - * - * @param fileName The name of the file to be loaded. - * @param fileSize The size of the file that was loaded. - * - * @return An allocated byte array containing the data that was loaded, - * or NULL on failure. - * @note The array contains an extra \0 character at position fileSize. - */ - char *loadFile(const std::string &fileName, int &fileSize); - - /** - * Returns the filePath sub-part corresponding to the filename only. - * @return splittedPath: the file path ending with '/' or '\' - * and the file name alone. - */ - splittedPath splitFileNameAndPath(const std::string &fullFilePath); -} - -#endif diff --git a/src/common/transaction.h b/src/common/transaction.h new file mode 100644 index 00000000..2715176b --- /dev/null +++ b/src/common/transaction.h @@ -0,0 +1,67 @@ +/* + * The Mana Server + * Copyright (C) 2009-2010 The Mana World Development Team + * + * This file is part of The Mana Server. + * + * The Mana Server 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 + * any later version. + * + * The Mana Server 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 The Mana Server. If not, see . + */ + +#ifndef TRANSACTION_H +#define TRANSACTION_H + +struct Transaction +{ + unsigned int mAction; + unsigned int mCharacterId; + std::string mMessage; +}; + +enum +{ + TRANS_CHAR_CREATE = 1, + TRANS_CHAR_SELECTED, + TRANS_CHAR_DELETED, + TRANS_MSG_PUBLIC, + TRANS_MSG_ANNOUNCE, + TRANS_MSG_PRIVATE, + TRANS_CHANNEL_JOIN, + TRANS_CHANNEL_KICK, + TRANS_CHANNEL_MODE, + TRANS_CHANNEL_QUIT, + TRANS_CHANNEL_LIST, + TRANS_CHANNEL_USERLIST, + TRANS_CHANNEL_TOPIC, + TRANS_CMD_BAN, + TRANS_CMD_DROP, + TRANS_CMD_ITEM, + TRANS_CMD_MONEY, + TRANS_CMD_SETGROUP, + TRANS_CMD_SPAWN, + TRANS_CMD_WARP, + TRANS_ITEM_PICKUP, + TRANS_ITEM_USED, + TRANS_ITEM_DROP, + TRANS_ITEM_MOVE, + TRANS_ATTACK_TARGET, + TRANS_ACTION_CHANGE, + TRANS_TRADE_REQUEST, + TRANS_TRADE_END, + TRANS_TRADE_MONEY, + TRANS_TRADE_ITEM, + TRANS_ATTR_INCREASE, + TRANS_ATTR_DECREASE +}; + +#endif diff --git a/src/common/transaction.hpp b/src/common/transaction.hpp deleted file mode 100644 index 2715176b..00000000 --- a/src/common/transaction.hpp +++ /dev/null @@ -1,67 +0,0 @@ -/* - * The Mana Server - * Copyright (C) 2009-2010 The Mana World Development Team - * - * This file is part of The Mana Server. - * - * The Mana Server 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 - * any later version. - * - * The Mana Server 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 The Mana Server. If not, see . - */ - -#ifndef TRANSACTION_H -#define TRANSACTION_H - -struct Transaction -{ - unsigned int mAction; - unsigned int mCharacterId; - std::string mMessage; -}; - -enum -{ - TRANS_CHAR_CREATE = 1, - TRANS_CHAR_SELECTED, - TRANS_CHAR_DELETED, - TRANS_MSG_PUBLIC, - TRANS_MSG_ANNOUNCE, - TRANS_MSG_PRIVATE, - TRANS_CHANNEL_JOIN, - TRANS_CHANNEL_KICK, - TRANS_CHANNEL_MODE, - TRANS_CHANNEL_QUIT, - TRANS_CHANNEL_LIST, - TRANS_CHANNEL_USERLIST, - TRANS_CHANNEL_TOPIC, - TRANS_CMD_BAN, - TRANS_CMD_DROP, - TRANS_CMD_ITEM, - TRANS_CMD_MONEY, - TRANS_CMD_SETGROUP, - TRANS_CMD_SPAWN, - TRANS_CMD_WARP, - TRANS_ITEM_PICKUP, - TRANS_ITEM_USED, - TRANS_ITEM_DROP, - TRANS_ITEM_MOVE, - TRANS_ATTACK_TARGET, - TRANS_ACTION_CHANGE, - TRANS_TRADE_REQUEST, - TRANS_TRADE_END, - TRANS_TRADE_MONEY, - TRANS_TRADE_ITEM, - TRANS_ATTR_INCREASE, - TRANS_ATTR_DECREASE -}; - -#endif diff --git a/src/dal/mysqldataprovider.h b/src/dal/mysqldataprovider.h index 528d4bea..02fc8ea8 100644 --- a/src/dal/mysqldataprovider.h +++ b/src/dal/mysqldataprovider.h @@ -31,7 +31,7 @@ #include #include "dataprovider.h" -#include "common/configuration.hpp" +#include "common/configuration.h" #include "utils/logger.h" namespace dal diff --git a/src/dal/sqlitedataprovider.h b/src/dal/sqlitedataprovider.h index 40ef3616..39413643 100644 --- a/src/dal/sqlitedataprovider.h +++ b/src/dal/sqlitedataprovider.h @@ -24,7 +24,7 @@ #include #include "limits.h" #include -#include "common/configuration.hpp" +#include "common/configuration.h" // sqlite3_int64 is the preferred new datatype for 64-bit int values. diff --git a/src/game-server/accountconnection.cpp b/src/game-server/accountconnection.cpp index 3c3cd88c..72546fbf 100644 --- a/src/game-server/accountconnection.cpp +++ b/src/game-server/accountconnection.cpp @@ -18,23 +18,23 @@ * along with The Mana Server. If not, see . */ -#include "game-server/accountconnection.hpp" - -#include "common/configuration.hpp" -#include "game-server/character.hpp" -#include "game-server/gamehandler.hpp" -#include "game-server/map.hpp" -#include "game-server/mapcomposite.hpp" -#include "game-server/mapmanager.hpp" -#include "game-server/itemmanager.hpp" -#include "game-server/postman.hpp" -#include "game-server/quest.hpp" -#include "game-server/state.hpp" -#include "net/messagein.hpp" -#include "serialize/characterdata.hpp" +#include "game-server/accountconnection.h" + +#include "common/configuration.h" +#include "game-server/character.h" +#include "game-server/gamehandler.h" +#include "game-server/map.h" +#include "game-server/mapcomposite.h" +#include "game-server/mapmanager.h" +#include "game-server/itemmanager.h" +#include "game-server/postman.h" +#include "game-server/quest.h" +#include "game-server/state.h" +#include "net/messagein.h" +#include "serialize/characterdata.h" #include "utils/logger.h" -#include "utils/tokendispenser.hpp" -#include "utils/tokencollector.hpp" +#include "utils/tokendispenser.h" +#include "utils/tokencollector.h" AccountConnection::AccountConnection(): mSyncBuffer(0) diff --git a/src/game-server/accountconnection.h b/src/game-server/accountconnection.h new file mode 100644 index 00000000..c0bbc5cd --- /dev/null +++ b/src/game-server/accountconnection.h @@ -0,0 +1,179 @@ +/* + * The Mana Server + * Copyright (C) 2006-2010 The Mana World Development Team + * + * This file is part of The Mana Server. + * + * The Mana Server 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 + * any later version. + * + * The Mana Server 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 The Mana Server. If not, see . + */ + +#ifndef ACCOUNTCONNECTION_H +#define ACCOUNTCONNECTION_H + +#include "net/messageout.h" +#include "net/connection.h" + +class Character; + +/** \fn void AccountConnection::syncChanges(bool force = false) + * + * The gameserver holds a buffer with all changes made by a character. The + * changes are added at the time they occur. When the buffer reaches one of + * the following limits, the buffer is sent to the account server and applied + * to the database. + * + * The sync buffer is sent when: + * - forced by any process (param force = true) + * - every 10 seconds + * - buffer reaches size of 1kb (defined in #SYNC_BUFFER_SIZE) + * - buffer holds more then 20 messages (defined in #SYNC_BUFFER_LIMIT) + */ +#define SYNC_BUFFER_SIZE 1024 /**< maximum size of sync buffer in bytes. */ +#define SYNC_BUFFER_LIMIT 20 /**< maximum number of messages in sync buffer. */ + +/** + * A connection to the account server. + */ +class AccountConnection : public Connection +{ + public: + /** + * Constructor. + */ + AccountConnection(); + + /** + * Destructor. + */ + ~AccountConnection(); + + /** + * Initializes a connection to the account server described in the + * configuration file. Registers the maps known by MapManager. + */ + bool start(int gameServerPort); + + /** + * Sends data of a given character. + */ + void sendCharacterData(Character *); + + /** + * Prepares the account server for a reconnecting player + */ + void playerReconnectAccount(int id, const std::string &magic_token); + + /** + * Requests the value of a quest variable from the database. + */ + void requestQuestVar(Character *, const std::string &); + + /** + * Pushes a new quest value to the database. + */ + void updateQuestVar(Character *, const std::string &name, + const std::string &value); + + /** + * Sends ban message. + */ + void banCharacter(Character *, int); + + /** + * Gathers statistics and sends them. + */ + void sendStatistics(); + + /** + * Send letter + */ + void sendPost(Character *, MessageIn &); + + /** + * Get post + */ + void getPost(Character *); + + /** + * Change Account Level + */ + void changeAccountLevel(Character *, int); + + /** + * Sends all changed player data to the account server to minimize + * dataloss due to failure of one server component. + * + * @param force Send changes even if buffer hasn't reached its size + * or message limit. (used to send in timed schedules) + */ + void syncChanges(bool force = false); + + /** + * Write a modification message about character points to the sync + * buffer. + * + * @param charId ID of the character + * @param charPoints character points left for the character + * @param corrPoints correction points left for the character + */ + void updateCharacterPoints(int charId, int charPoints, + int corrPoints); + + /** + * @param charId ID of the character + * @param attribId ID of the modified attribute + * @param attribValue New value of the modified attribute + */ + + void updateAttributes(int charId, int attrId, double base, + double mod); + + /** + * Write a modification message about character skills to the sync + * buffer. + * + * @param charId ID of the character + * @param skillId ID of the skill + * @param skillValue new skill points + */ + void updateExperience(int charId, int skillId, int skillValue); + + /** + * Update the status of a character to online (true) or offline + * (false). + * + * @param charId Id of the character. + * @param online True to flag the character as being online. + */ + void updateOnlineStatus(int charId, bool online); + + /** + * Send transaction to account server + */ + void sendTransaction(int id, int action, const std::string &message); + + protected: + /** + * Processes server messages. + */ + virtual void processMessage(MessageIn &); + + private: + MessageOut* mSyncBuffer; /**< Message buffer to store sync data. */ + int mSyncMessages; /**< Number of messages in the sync buffer. */ +}; + +extern AccountConnection *accountHandler; + +#endif // ACCOUNTCONNECTION_H diff --git a/src/game-server/accountconnection.hpp b/src/game-server/accountconnection.hpp deleted file mode 100644 index 28599f82..00000000 --- a/src/game-server/accountconnection.hpp +++ /dev/null @@ -1,179 +0,0 @@ -/* - * The Mana Server - * Copyright (C) 2006-2010 The Mana World Development Team - * - * This file is part of The Mana Server. - * - * The Mana Server 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 - * any later version. - * - * The Mana Server 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 The Mana Server. If not, see . - */ - -#ifndef ACCOUNTCONNECTION_H -#define ACCOUNTCONNECTION_H - -#include "net/messageout.hpp" -#include "net/connection.hpp" - -class Character; - -/** \fn void AccountConnection::syncChanges(bool force = false) - * - * The gameserver holds a buffer with all changes made by a character. The - * changes are added at the time they occur. When the buffer reaches one of - * the following limits, the buffer is sent to the account server and applied - * to the database. - * - * The sync buffer is sent when: - * - forced by any process (param force = true) - * - every 10 seconds - * - buffer reaches size of 1kb (defined in #SYNC_BUFFER_SIZE) - * - buffer holds more then 20 messages (defined in #SYNC_BUFFER_LIMIT) - */ -#define SYNC_BUFFER_SIZE 1024 /**< maximum size of sync buffer in bytes. */ -#define SYNC_BUFFER_LIMIT 20 /**< maximum number of messages in sync buffer. */ - -/** - * A connection to the account server. - */ -class AccountConnection : public Connection -{ - public: - /** - * Constructor. - */ - AccountConnection(); - - /** - * Destructor. - */ - ~AccountConnection(); - - /** - * Initializes a connection to the account server described in the - * configuration file. Registers the maps known by MapManager. - */ - bool start(int gameServerPort); - - /** - * Sends data of a given character. - */ - void sendCharacterData(Character *); - - /** - * Prepares the account server for a reconnecting player - */ - void playerReconnectAccount(int id, const std::string &magic_token); - - /** - * Requests the value of a quest variable from the database. - */ - void requestQuestVar(Character *, const std::string &); - - /** - * Pushes a new quest value to the database. - */ - void updateQuestVar(Character *, const std::string &name, - const std::string &value); - - /** - * Sends ban message. - */ - void banCharacter(Character *, int); - - /** - * Gathers statistics and sends them. - */ - void sendStatistics(); - - /** - * Send letter - */ - void sendPost(Character *, MessageIn &); - - /** - * Get post - */ - void getPost(Character *); - - /** - * Change Account Level - */ - void changeAccountLevel(Character *, int); - - /** - * Sends all changed player data to the account server to minimize - * dataloss due to failure of one server component. - * - * @param force Send changes even if buffer hasn't reached its size - * or message limit. (used to send in timed schedules) - */ - void syncChanges(bool force = false); - - /** - * Write a modification message about character points to the sync - * buffer. - * - * @param charId ID of the character - * @param charPoints character points left for the character - * @param corrPoints correction points left for the character - */ - void updateCharacterPoints(int charId, int charPoints, - int corrPoints); - - /** - * @param charId ID of the character - * @param attribId ID of the modified attribute - * @param attribValue New value of the modified attribute - */ - - void updateAttributes(int charId, int attrId, double base, - double mod); - - /** - * Write a modification message about character skills to the sync - * buffer. - * - * @param charId ID of the character - * @param skillId ID of the skill - * @param skillValue new skill points - */ - void updateExperience(int charId, int skillId, int skillValue); - - /** - * Update the status of a character to online (true) or offline - * (false). - * - * @param charId Id of the character. - * @param online True to flag the character as being online. - */ - void updateOnlineStatus(int charId, bool online); - - /** - * Send transaction to account server - */ - void sendTransaction(int id, int action, const std::string &message); - - protected: - /** - * Processes server messages. - */ - virtual void processMessage(MessageIn &); - - private: - MessageOut* mSyncBuffer; /**< Message buffer to store sync data. */ - int mSyncMessages; /**< Number of messages in the sync buffer. */ -}; - -extern AccountConnection *accountHandler; - -#endif // ACCOUNTCONNECTION_H diff --git a/src/game-server/actor.cpp b/src/game-server/actor.cpp index 8c183224..b9f4504b 100644 --- a/src/game-server/actor.cpp +++ b/src/game-server/actor.cpp @@ -18,10 +18,10 @@ * along with The Mana Server. If not, see . */ -#include "game-server/actor.hpp" +#include "game-server/actor.h" -#include "game-server/map.hpp" -#include "game-server/mapcomposite.hpp" +#include "game-server/map.h" +#include "game-server/mapcomposite.h" #include diff --git a/src/game-server/actor.h b/src/game-server/actor.h new file mode 100644 index 00000000..483cb78e --- /dev/null +++ b/src/game-server/actor.h @@ -0,0 +1,145 @@ +/* + * The Mana Server + * Copyright (C) 2004-2010 The Mana World Development Team + * + * This file is part of The Mana Server. + * + * The Mana Server 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 + * any later version. + * + * The Mana Server 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 The Mana Server. If not, see . + */ + +#ifndef ACTOR_H +#define ACTOR_H + +#include "point.h" +#include "game-server/map.h" +#include "game-server/thing.h" + +/** + * Flags that are raised as necessary. They trigger messages that are sent to + * the clients. + */ +enum +{ + UPDATEFLAG_NEW_ON_MAP = 1, + UPDATEFLAG_NEW_DESTINATION = 2, + UPDATEFLAG_ATTACK = 4, + UPDATEFLAG_ACTIONCHANGE = 8, + UPDATEFLAG_LOOKSCHANGE = 16, + UPDATEFLAG_DIRCHANGE = 32, + UPDATEFLAG_HEALTHCHANGE = 64 +}; + +/** + * Generic client-visible object. Keeps track of position, size and what to + * update clients about. + */ +class Actor : public Thing +{ + public: + /** + * Constructor. + */ + Actor(ThingType type) + : Thing(type), + mActionTime(0), + mUpdateFlags(0), + mPublicID(65535), + mSize(0) + {} + + /** + * Sets the coordinates. Also updates the walkmap of the map the actor + * is on. + * + * @param p the coordinates. + */ + void setPosition(const Point &p); + + /** + * Gets the coordinates. + * + * @return the coordinates. + */ + const Point &getPosition() const + { return mPos; } + + /** + * Gets what changed in the actor. + */ + int getUpdateFlags() const + { return mUpdateFlags; } + + /** + * Sets some changes in the actor. + */ + void raiseUpdateFlags(int n) + { mUpdateFlags |= n; } + + /** + * Clears changes in the actor. + */ + void clearUpdateFlags() + { mUpdateFlags = 0; } + + /** + * Sets actor bounding circle radius. + */ + void setSize(int s) { mSize = s; } + int getSize() const { return mSize; } + + /** + * Get public ID. + * + * @return the public ID, 65535 if none yet. + */ + int getPublicID() const + { return mPublicID; } + + /** + * Set public ID. The actor shall not have any public ID yet. + */ + void setPublicID(int id) + { mPublicID = id; } + + /** + * Gets the way the actor blocks pathfinding for other actors. + */ + virtual unsigned char getWalkMask() const + { return 0x00; } //can walk through everything + + /** + * Overridden in order to update the walkmap. + */ + virtual void setMap(MapComposite *map); + + protected: + /** + * Gets the way the actor blocks pathfinding for other actors. + */ + virtual Map::BlockType getBlockType() const + { return Map::BLOCKTYPE_NONE; } + + unsigned short mActionTime; /**< Delay until next action. */ + + private: + char mUpdateFlags; /**< Changes in actor status. */ + + /** Actor ID sent to clients (unique with respect to the map). */ + unsigned short mPublicID; + + Point mPos; /**< Coordinates. */ + unsigned char mSize; /**< Radius of bounding circle. */ +}; + +#endif // ACTOR_H diff --git a/src/game-server/actor.hpp b/src/game-server/actor.hpp deleted file mode 100644 index de1e30a1..00000000 --- a/src/game-server/actor.hpp +++ /dev/null @@ -1,145 +0,0 @@ -/* - * The Mana Server - * Copyright (C) 2004-2010 The Mana World Development Team - * - * This file is part of The Mana Server. - * - * The Mana Server 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 - * any later version. - * - * The Mana Server 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 The Mana Server. If not, see . - */ - -#ifndef ACTOR_H -#define ACTOR_H - -#include "point.h" -#include "game-server/map.hpp" -#include "game-server/thing.hpp" - -/** - * Flags that are raised as necessary. They trigger messages that are sent to - * the clients. - */ -enum -{ - UPDATEFLAG_NEW_ON_MAP = 1, - UPDATEFLAG_NEW_DESTINATION = 2, - UPDATEFLAG_ATTACK = 4, - UPDATEFLAG_ACTIONCHANGE = 8, - UPDATEFLAG_LOOKSCHANGE = 16, - UPDATEFLAG_DIRCHANGE = 32, - UPDATEFLAG_HEALTHCHANGE = 64 -}; - -/** - * Generic client-visible object. Keeps track of position, size and what to - * update clients about. - */ -class Actor : public Thing -{ - public: - /** - * Constructor. - */ - Actor(ThingType type) - : Thing(type), - mActionTime(0), - mUpdateFlags(0), - mPublicID(65535), - mSize(0) - {} - - /** - * Sets the coordinates. Also updates the walkmap of the map the actor - * is on. - * - * @param p the coordinates. - */ - void setPosition(const Point &p); - - /** - * Gets the coordinates. - * - * @return the coordinates. - */ - const Point &getPosition() const - { return mPos; } - - /** - * Gets what changed in the actor. - */ - int getUpdateFlags() const - { return mUpdateFlags; } - - /** - * Sets some changes in the actor. - */ - void raiseUpdateFlags(int n) - { mUpdateFlags |= n; } - - /** - * Clears changes in the actor. - */ - void clearUpdateFlags() - { mUpdateFlags = 0; } - - /** - * Sets actor bounding circle radius. - */ - void setSize(int s) { mSize = s; } - int getSize() const { return mSize; } - - /** - * Get public ID. - * - * @return the public ID, 65535 if none yet. - */ - int getPublicID() const - { return mPublicID; } - - /** - * Set public ID. The actor shall not have any public ID yet. - */ - void setPublicID(int id) - { mPublicID = id; } - - /** - * Gets the way the actor blocks pathfinding for other actors. - */ - virtual unsigned char getWalkMask() const - { return 0x00; } //can walk through everything - - /** - * Overridden in order to update the walkmap. - */ - virtual void setMap(MapComposite *map); - - protected: - /** - * Gets the way the actor blocks pathfinding for other actors. - */ - virtual Map::BlockType getBlockType() const - { return Map::BLOCKTYPE_NONE; } - - unsigned short mActionTime; /**< Delay until next action. */ - - private: - char mUpdateFlags; /**< Changes in actor status. */ - - /** Actor ID sent to clients (unique with respect to the map). */ - unsigned short mPublicID; - - Point mPos; /**< Coordinates. */ - unsigned char mSize; /**< Radius of bounding circle. */ -}; - -#endif // ACTOR_H diff --git a/src/game-server/attribute.cpp b/src/game-server/attribute.cpp index c7bc43d2..e5ca1b64 100644 --- a/src/game-server/attribute.cpp +++ b/src/game-server/attribute.cpp @@ -18,8 +18,8 @@ * along with The Mana Server. If not, see . */ -#include "attribute.hpp" -#include "game-server/being.hpp" +#include "attribute.h" +#include "game-server/being.h" #include "utils/logger.h" #include diff --git a/src/game-server/attribute.h b/src/game-server/attribute.h new file mode 100644 index 00000000..c2b8bcfb --- /dev/null +++ b/src/game-server/attribute.h @@ -0,0 +1,184 @@ +/* + * The Mana Server + * Copyright (C) 2004-2010 The Mana World Development Team + * + * This file is part of The Mana Server. + * + * The Mana Server 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 + * any later version. + * + * The Mana Server 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 The Mana Server. If not, see . + */ + +#ifndef ATTRIBUTE_H +#define ATTRIBUTE_H + +#include "defines.h" +#include +#include + +class AttributeModifierState +{ + public: + AttributeModifierState(unsigned short duration, double value, + unsigned int id) + : mDuration(duration), mValue(value), mId(id) {} + ~AttributeModifierState() {} + bool tick() { return mDuration ? !--mDuration : false; } + private: + /** Number of ticks (0 means permanent, e.g. equipment). */ + unsigned short mDuration; + const double mValue; /**< Positive or negative amount. */ + /** + * Special purpose variable used to identify this effect to + * dispells or similar. Exact usage depends on the effect, + * origin, etc. + */ + const unsigned int mId; + friend bool durationCompare(const AttributeModifierState*, + const AttributeModifierState*); + friend class AttributeModifiersEffect; +}; + +class AttributeModifiersEffect { + public: + AttributeModifiersEffect(AT_TY sType, AME_TY eType); + ~AttributeModifiersEffect(); + /** + * Recalculates the value for this level. + * @returns True if the value changed, false if it did not change. + * Note that this will not change values at a higher level, nor the + * overall modified value for this attribute. + * If this returns true, the cached values for *all* modifiers of a + * higher level must be recalculated, as well as the final + */ + bool add(unsigned short duration, double value, + double prevLayerValue, int level); + + /** + * remove() - as with Attribute::remove(). + */ + + bool remove(double value, unsigned int id, bool fullCheck); + + /** + * Performs the necessary modifications to mMod when the states change. + * @param value The value to alter. This is only used in stackable + * types, as the effect can be simply inverted there. + * For non stackable types (and stackable multiplicative types + * where the value is zero), mMod must be recalculated from all + * current modifiers. + * @note This /negates/ the effect of value. + * @note A parameter should always be provided when stackable. + */ + void updateMod(double value = 0); + + /** + * Performs the necessary modifications to mCacheVal when the states + * change. + */ + + bool recalculateModifiedValue(double newPrevLayerValue); + + double getCachedModifiedValue() const { return mCacheVal; } + + bool tick(); + + /** + * clearMods() - removes all modifications present in this layer. + * This only really makes sense when all other layers are being reset too. + * @param baseValue the value to reset to - typically an Attribute's mBase + */ + + void clearMods(double baseValue); + + private: + /** List of all modifications present at this level */ + std::list< AttributeModifierState * > mStates; + /** + * Stores the value that results from mStates. This takes into + * account all previous layers. + */ + double mCacheVal; + /** + * Stores the effective modifying value from mStates. This defaults to + * 0 for additive modifiers and 1 for multiplicative modifiers. + */ + double mMod; + const AT_TY mSType; + const AME_TY mEType; +}; + +class Attribute +{ + public: + Attribute() {throw;} // DEBUG; Find improper constructions + + Attribute(const std::vector &type); + + ~Attribute(); + + void setBase(double base); + double getBase() const { return mBase; } + double getModifiedAttribute() const + { return mMods.empty() ? mBase : + (*mMods.rbegin())->getCachedModifiedValue(); } + + /** + * add() and remove() are the standard functions used to add and + * remove modifiers while keeping track of the modifier state. + */ + + /** + * @param duration The amount of time before the modifier expires + * naturally. + * When set to 0, the effect does not expire. + * @param value The value to be applied as the modifier. + * @param layer The id of the layer with which this modifier is to be + * applied to. + * @param id Used to identify this effect. + * @return Whether the modified attribute value was changed. + */ + + bool add(unsigned short duration, double value, unsigned int layer, int id = 0); + + /** + * @param value The value of the modifier to be removed. + * - When 0, id is used exclusively to identify modifiers. + * @param layer The id of the layer which contains the modifier to be removed. + * @param id Used to identify this effect. + * - When 0, only the first match will be removed. + * - When non-0, all modifiers matching this id and other + * parameters will be removed. + * @param fullcheck Whether to perform a check for all modifiers, + * or only those that are otherwise permanent (ie. duration of 0) + * @returns Whether the modified attribute value was changed. + */ + bool remove(double value, unsigned int layer, int id, bool fullcheck); + + /** + * clearMods() removes *all* modifications present in this Attribute (!) + */ + + void clearMods(); + + /** + * tick() processes all timers associated with modifiers for this attribute. + */ + + bool tick(); + + private: + double mBase; + std::vector< AttributeModifiersEffect * > mMods; +}; + +#endif // ATTRIBUTE_H diff --git a/src/game-server/attribute.hpp b/src/game-server/attribute.hpp deleted file mode 100644 index e0696a4c..00000000 --- a/src/game-server/attribute.hpp +++ /dev/null @@ -1,184 +0,0 @@ -/* - * The Mana Server - * Copyright (C) 2004-2010 The Mana World Development Team - * - * This file is part of The Mana Server. - * - * The Mana Server 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 - * any later version. - * - * The Mana Server 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 The Mana Server. If not, see . - */ - -#ifndef ATTRIBUTE_HPP -#define ATTRIBUTE_HPP - -#include "defines.h" -#include -#include - -class AttributeModifierState -{ - public: - AttributeModifierState(unsigned short duration, double value, - unsigned int id) - : mDuration(duration), mValue(value), mId(id) {} - ~AttributeModifierState() {} - bool tick() { return mDuration ? !--mDuration : false; } - private: - /** Number of ticks (0 means permanent, e.g. equipment). */ - unsigned short mDuration; - const double mValue; /**< Positive or negative amount. */ - /** - * Special purpose variable used to identify this effect to - * dispells or similar. Exact usage depends on the effect, - * origin, etc. - */ - const unsigned int mId; - friend bool durationCompare(const AttributeModifierState*, - const AttributeModifierState*); - friend class AttributeModifiersEffect; -}; - -class AttributeModifiersEffect { - public: - AttributeModifiersEffect(AT_TY sType, AME_TY eType); - ~AttributeModifiersEffect(); - /** - * Recalculates the value for this level. - * @returns True if the value changed, false if it did not change. - * Note that this will not change values at a higher level, nor the - * overall modified value for this attribute. - * If this returns true, the cached values for *all* modifiers of a - * higher level must be recalculated, as well as the final - */ - bool add(unsigned short duration, double value, - double prevLayerValue, int level); - - /** - * remove() - as with Attribute::remove(). - */ - - bool remove(double value, unsigned int id, bool fullCheck); - - /** - * Performs the necessary modifications to mMod when the states change. - * @param value The value to alter. This is only used in stackable - * types, as the effect can be simply inverted there. - * For non stackable types (and stackable multiplicative types - * where the value is zero), mMod must be recalculated from all - * current modifiers. - * @note This /negates/ the effect of value. - * @note A parameter should always be provided when stackable. - */ - void updateMod(double value = 0); - - /** - * Performs the necessary modifications to mCacheVal when the states - * change. - */ - - bool recalculateModifiedValue(double newPrevLayerValue); - - double getCachedModifiedValue() const { return mCacheVal; } - - bool tick(); - - /** - * clearMods() - removes all modifications present in this layer. - * This only really makes sense when all other layers are being reset too. - * @param baseValue the value to reset to - typically an Attribute's mBase - */ - - void clearMods(double baseValue); - - private: - /** List of all modifications present at this level */ - std::list< AttributeModifierState * > mStates; - /** - * Stores the value that results from mStates. This takes into - * account all previous layers. - */ - double mCacheVal; - /** - * Stores the effective modifying value from mStates. This defaults to - * 0 for additive modifiers and 1 for multiplicative modifiers. - */ - double mMod; - const AT_TY mSType; - const AME_TY mEType; -}; - -class Attribute -{ - public: - Attribute() {throw;} // DEBUG; Find improper constructions - - Attribute(const std::vector &type); - - ~Attribute(); - - void setBase(double base); - double getBase() const { return mBase; } - double getModifiedAttribute() const - { return mMods.empty() ? mBase : - (*mMods.rbegin())->getCachedModifiedValue(); } - - /** - * add() and remove() are the standard functions used to add and - * remove modifiers while keeping track of the modifier state. - */ - - /** - * @param duration The amount of time before the modifier expires - * naturally. - * When set to 0, the effect does not expire. - * @param value The value to be applied as the modifier. - * @param layer The id of the layer with which this modifier is to be - * applied to. - * @param id Used to identify this effect. - * @return Whether the modified attribute value was changed. - */ - - bool add(unsigned short duration, double value, unsigned int layer, int id = 0); - - /** - * @param value The value of the modifier to be removed. - * - When 0, id is used exclusively to identify modifiers. - * @param layer The id of the layer which contains the modifier to be removed. - * @param id Used to identify this effect. - * - When 0, only the first match will be removed. - * - When non-0, all modifiers matching this id and other - * parameters will be removed. - * @param fullcheck Whether to perform a check for all modifiers, - * or only those that are otherwise permanent (ie. duration of 0) - * @returns Whether the modified attribute value was changed. - */ - bool remove(double value, unsigned int layer, int id, bool fullcheck); - - /** - * clearMods() removes *all* modifications present in this Attribute (!) - */ - - void clearMods(); - - /** - * tick() processes all timers associated with modifiers for this attribute. - */ - - bool tick(); - - private: - double mBase; - std::vector< AttributeModifiersEffect * > mMods; -}; - -#endif // ATTRIBUTE_HPP diff --git a/src/game-server/attributemanager.cpp b/src/game-server/attributemanager.cpp index 3c9fab23..d590a951 100644 --- a/src/game-server/attributemanager.cpp +++ b/src/game-server/attributemanager.cpp @@ -18,12 +18,12 @@ * along with The Mana Server. If not, see . */ -#include "game-server/attributemanager.hpp" +#include "game-server/attributemanager.h" -#include "common/resourcemanager.hpp" -#include "utils/string.hpp" +#include "common/resourcemanager.h" +#include "utils/string.h" #include "utils/logger.h" -#include "utils/xml.hpp" +#include "utils/xml.h" #include "defines.h" void AttributeManager::initialize() diff --git a/src/game-server/attributemanager.h b/src/game-server/attributemanager.h new file mode 100644 index 00000000..a87ba901 --- /dev/null +++ b/src/game-server/attributemanager.h @@ -0,0 +1,83 @@ +/* + * The Mana Server + * Copyright (C) 2004-2010 The Mana World Development Team + * + * This file is part of The Mana Server. + * + * The Mana Server 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 + * any later version. + * + * The Mana Server 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 The Mana Server. If not, see . + */ + +#ifndef ATTRIBUTEMANAGER_H +#define ATTRIBUTEMANAGER_H + +#include +#include +#include + +typedef struct AttributeInfoType AttributeInfoType_t; + +enum SCOPE_TYPES { + ATTR_BEING = 0, + ATTR_CHAR, + ATTR_MOB, + // Add new types here as needed + ATTR_MAX +}; + +typedef std::map< int, std::vector * > AttributeScopes; + +class AttributeManager +{ + public: + AttributeManager(const std::string &file) : mAttributeReferenceFile(file) {} + /** + * Loads attribute reference file. + */ + void initialize(); + + /** + * Reloads attribute reference file. + */ + void reload(); + const std::vector *getAttributeInfo(unsigned int) const; + + const AttributeScopes &getAttributeInfoForType(SCOPE_TYPES) const; + + bool isAttributeDirectlyModifiable(unsigned int) const; + + std::pair getInfoFromTag(const std::string &) const; + + const std::string *getTagFromInfo(unsigned int, unsigned int) const; + private: + // modifiable, { stackable type, effect type }[] + typedef std::pair< bool, + std::vector > AttributeInfoMap; + + // Attribute id -> { modifiable, { stackable type, effect type }[] } + typedef std::map< int, AttributeInfoMap > AttributeMap; + // tag name -> { attribute id, layer } + typedef std::map< std::string, + std::pair > TagMap; + + // being type id -> (*{ stackable type, effect type })[] + AttributeScopes mAttributeScopes[ATTR_MAX]; + AttributeMap mAttributeMap; + TagMap mTagMap; + + const std::string mAttributeReferenceFile; +}; + +extern AttributeManager *attributeManager; + +#endif // ATTRIBUTEMANAGER_H diff --git a/src/game-server/attributemanager.hpp b/src/game-server/attributemanager.hpp deleted file mode 100644 index c5f1d870..00000000 --- a/src/game-server/attributemanager.hpp +++ /dev/null @@ -1,83 +0,0 @@ -/* - * The Mana Server - * Copyright (C) 2004-2010 The Mana World Development Team - * - * This file is part of The Mana Server. - * - * The Mana Server 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 - * any later version. - * - * The Mana Server 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 The Mana Server. If not, see . - */ - -#ifndef ATTRIBUTEMANAGER_HPP -#define ATTRIBUTEMANAGER_HPP - -#include -#include -#include - -typedef struct AttributeInfoType AttributeInfoType_t; - -enum SCOPE_TYPES { - ATTR_BEING = 0, - ATTR_CHAR, - ATTR_MOB, - // Add new types here as needed - ATTR_MAX -}; - -typedef std::map< int, std::vector * > AttributeScopes; - -class AttributeManager -{ - public: - AttributeManager(const std::string &file) : mAttributeReferenceFile(file) {} - /** - * Loads attribute reference file. - */ - void initialize(); - - /** - * Reloads attribute reference file. - */ - void reload(); - const std::vector *getAttributeInfo(unsigned int) const; - - const AttributeScopes &getAttributeInfoForType(SCOPE_TYPES) const; - - bool isAttributeDirectlyModifiable(unsigned int) const; - - std::pair getInfoFromTag(const std::string &) const; - - const std::string *getTagFromInfo(unsigned int, unsigned int) const; - private: - // modifiable, { stackable type, effect type }[] - typedef std::pair< bool, - std::vector > AttributeInfoMap; - - // Attribute id -> { modifiable, { stackable type, effect type }[] } - typedef std::map< int, AttributeInfoMap > AttributeMap; - // tag name -> { attribute id, layer } - typedef std::map< std::string, - std::pair > TagMap; - - // being type id -> (*{ stackable type, effect type })[] - AttributeScopes mAttributeScopes[ATTR_MAX]; - AttributeMap mAttributeMap; - TagMap mTagMap; - - const std::string mAttributeReferenceFile; -}; - -extern AttributeManager *attributeManager; - -#endif // ATTRIBUTEMANAGER_HPP diff --git a/src/game-server/autoattack.cpp b/src/game-server/autoattack.cpp index dae6b0ff..b8c8a165 100644 --- a/src/game-server/autoattack.cpp +++ b/src/game-server/autoattack.cpp @@ -1,4 +1,24 @@ -#include "autoattack.hpp" +/* + * The Mana Server + * Copyright (C) 2010 The Mana Development Team + * + * This file is part of The Mana Server. + * + * The Mana Server 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 + * any later version. + * + * The Mana Server 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 The Mana Server. If not, see . + */ + +#include "autoattack.h" void AutoAttacks::add(AutoAttack n) { diff --git a/src/game-server/autoattack.h b/src/game-server/autoattack.h new file mode 100644 index 00000000..8be5c608 --- /dev/null +++ b/src/game-server/autoattack.h @@ -0,0 +1,120 @@ +/* + * The Mana Server + * Copyright (C) 2010 The Mana Development Team + * + * This file is part of The Mana Server. + * + * The Mana Server 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 + * any later version. + * + * The Mana Server 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 The Mana Server. If not, see . + */ + +#ifndef AUTOATTACK_H +#define AUTOATTACK_H + +#include +#include + +/** + * Methods of damage calculation + */ +enum DMG_TY +{ + DAMAGE_PHYSICAL = 0, + DAMAGE_MAGICAL, + DAMAGE_DIRECT, + DAMAGE_OTHER = -1 +}; + +/** + * Structure that describes the severity and nature of an attack a being can + * be hit by. + */ +struct Damage +{ + unsigned short base; /**< Base amount of damage. */ + unsigned short delta; /**< Additional damage when lucky. */ + unsigned short cth; /**< Chance to hit. Opposes the evade attribute. */ + unsigned char element; /**< Elemental damage. */ + DMG_TY type; /**< Damage type: Physical or magical? */ + unsigned trueStrike : 1; /**< Override dodge calculation */ + std::list usedSkills; /**< Skills used by source (needed for exp calculation) */ + unsigned short range; /**< Maximum distance that this attack can be used from */ + Damage(unsigned short base, unsigned short delta, unsigned short cth, + unsigned char element, DMG_TY type = DAMAGE_OTHER, + unsigned short range = std::numeric_limits::max()) + : base(base), delta(delta), cth(cth), element(element), type(type), + trueStrike(false), range(range) {} +}; + +/** + * Class that stores information about an auto-attack + */ + +class AutoAttack +{ + public: + AutoAttack(Damage &damage, unsigned int delay, unsigned int warmup) + : mDamage(damage), mTimer(0), mAspd(delay), + mWarmup(warmup && warmup < delay ? warmup : delay >> 2) {} + unsigned short getTimer() const { return mTimer; } + bool tick() { return mTimer ? !--mTimer : false; } + void reset() { mTimer = mAspd; } + bool operator<(const AutoAttack &rhs) const + { return mTimer < rhs.getTimer(); } + bool isReady() const { return !(mTimer - mWarmup); } + void halt() { if (mTimer >= mWarmup) mTimer = 0; } + void softReset() { if (mTimer >= mWarmup) mTimer = mAspd; } + const Damage &getDamage() const { return mDamage; } + private: + Damage mDamage; + /** + * Internal timer that is modified each tick. + * When > warmup, the attack is warming up before a strike + * When = warmup, the attack triggers, dealing damage to the target *if* the target is still in range. + * (The attack is canceled when the target moves out of range before the attack can hit, there should be a trigger for scripts here too) + * (Should the character automatically persue when the target is still visible in this case?) + * When < warmup, the attack is cooling down after a strike. When in cooldown, the timer should not be soft-reset. + * When 0, the attack is inactive (the character is doing something other than attacking and the attack is not in cooldown) + */ + unsigned short mTimer; + unsigned short mAspd; // Value to reset the timer to (warmup + cooldown) + /** + * Pre-attack delay tick. + * This MUST be smaller than or equal to the aspd! + * So the attack triggers where timer == warmup, having gone through aspd - warmup ticks. + */ + unsigned short mWarmup; +}; + +/** + * Helper class for storing multiple auto-attacks. + */ +class AutoAttacks +{ + public: + + /** + * Whether the being has at least one auto attack that is ready. + */ + void add(AutoAttack n); + void clear(); // Wipe the list completely (used in place of remove for now; FIXME) + void start(); + void stop(); // If the character does some action other than attacking, reset all warmups (NOT cooldowns!) + void tick(std::list *ret = 0); + private: + bool mActive; /**< Marks whether or not to keep auto-attacking. Cooldowns still need to be processed when false. */ + std::list < AutoAttack > mAutoAttacks; + +}; + +#endif // AUTOATTACK_H diff --git a/src/game-server/autoattack.hpp b/src/game-server/autoattack.hpp deleted file mode 100644 index a931d924..00000000 --- a/src/game-server/autoattack.hpp +++ /dev/null @@ -1,100 +0,0 @@ -#ifndef AUTOATTACK_HPP -#define AUTOATTACK_HPP - -#include -#include - -/** - * Methods of damage calculation - */ -enum DMG_TY -{ - DAMAGE_PHYSICAL = 0, - DAMAGE_MAGICAL, - DAMAGE_DIRECT, - DAMAGE_OTHER = -1 -}; - -/** - * Structure that describes the severity and nature of an attack a being can - * be hit by. - */ -struct Damage -{ - unsigned short base; /**< Base amount of damage. */ - unsigned short delta; /**< Additional damage when lucky. */ - unsigned short cth; /**< Chance to hit. Opposes the evade attribute. */ - unsigned char element; /**< Elemental damage. */ - DMG_TY type; /**< Damage type: Physical or magical? */ - unsigned trueStrike : 1; /**< Override dodge calculation */ - std::list usedSkills; /**< Skills used by source (needed for exp calculation) */ - unsigned short range; /**< Maximum distance that this attack can be used from */ - Damage(unsigned short base, unsigned short delta, unsigned short cth, - unsigned char element, DMG_TY type = DAMAGE_OTHER, - unsigned short range = std::numeric_limits::max()) - : base(base), delta(delta), cth(cth), element(element), type(type), - trueStrike(false), range(range) {} -}; - -/** - * Class that stores information about an auto-attack - */ - -class AutoAttack -{ - public: - AutoAttack(Damage &damage, unsigned int delay, unsigned int warmup) - : mDamage(damage), mTimer(0), mAspd(delay), - mWarmup(warmup && warmup < delay ? warmup : delay >> 2) {} - unsigned short getTimer() const { return mTimer; } - bool tick() { return mTimer ? !--mTimer : false; } - void reset() { mTimer = mAspd; } - bool operator<(const AutoAttack &rhs) const - { return mTimer < rhs.getTimer(); } - bool isReady() const { return !(mTimer - mWarmup); } - void halt() { if (mTimer >= mWarmup) mTimer = 0; } - void softReset() { if (mTimer >= mWarmup) mTimer = mAspd; } - const Damage &getDamage() const { return mDamage; } - private: - Damage mDamage; - /** - * Internal timer that is modified each tick. - * When > warmup, the attack is warming up before a strike - * When = warmup, the attack triggers, dealing damage to the target *if* the target is still in range. - * (The attack is canceled when the target moves out of range before the attack can hit, there should be a trigger for scripts here too) - * (Should the character automatically persue when the target is still visible in this case?) - * When < warmup, the attack is cooling down after a strike. When in cooldown, the timer should not be soft-reset. - * When 0, the attack is inactive (the character is doing something other than attacking and the attack is not in cooldown) - */ - unsigned short mTimer; - unsigned short mAspd; // Value to reset the timer to (warmup + cooldown) - /** - * Pre-attack delay tick. - * This MUST be smaller than or equal to the aspd! - * So the attack triggers where timer == warmup, having gone through aspd - warmup ticks. - */ - unsigned short mWarmup; -}; - -/** - * Helper class for storing multiple auto-attacks. - */ -class AutoAttacks -{ - public: - - /** - * Whether the being has at least one auto attack that is ready. - */ - void add(AutoAttack n); - void clear(); // Wipe the list completely (used in place of remove for now; FIXME) - void start(); - void stop(); // If the character does some action other than attacking, reset all warmups (NOT cooldowns!) - void tick(std::list *ret = 0); - private: - bool mActive; /**< Marks whether or not to keep auto-attacking. Cooldowns still need to be processed when false. */ - std::list < AutoAttack > mAutoAttacks; - -}; - -#endif // AUTOATTACK_HPP diff --git a/src/game-server/being.cpp b/src/game-server/being.cpp index 65338696..bbd7b4c6 100644 --- a/src/game-server/being.cpp +++ b/src/game-server/being.cpp @@ -20,20 +20,20 @@ #include -#include "game-server/being.hpp" +#include "game-server/being.h" #include "defines.h" -#include "common/configuration.hpp" -#include "game-server/attributemanager.hpp" -#include "game-server/character.hpp" -#include "game-server/collisiondetection.hpp" -#include "game-server/eventlistener.hpp" -#include "game-server/mapcomposite.hpp" -#include "game-server/effect.hpp" -#include "game-server/statuseffect.hpp" -#include "game-server/statusmanager.hpp" +#include "common/configuration.h" +#include "game-server/attributemanager.h" +#include "game-server/character.h" +#include "game-server/collisiondetection.h" +#include "game-server/eventlistener.h" +#include "game-server/mapcomposite.h" +#include "game-server/effect.h" +#include "game-server/statuseffect.h" +#include "game-server/statusmanager.h" #include "utils/logger.h" -#include "utils/speedconv.hpp" +#include "utils/speedconv.h" Being::Being(ThingType type): Actor(type), diff --git a/src/game-server/being.h b/src/game-server/being.h new file mode 100644 index 00000000..375220c9 --- /dev/null +++ b/src/game-server/being.h @@ -0,0 +1,373 @@ +/* + * The Mana Server + * Copyright (C) 2004-2010 The Mana World Development Team + * + * This file is part of The Mana Server. + * + * The Mana Server 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 + * any later version. + * + * The Mana Server 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 The Mana Server. If not, see . + */ + +#ifndef BEING_H +#define BEING_H + +#include +#include +#include +#include +#include "limits.h" + +#include "game-server/actor.h" +#include "game-server/attribute.h" +#include "game-server/autoattack.h" + +class Being; +class MapComposite; +class StatusEffect; + +typedef std::map< unsigned int, Attribute > AttributeMap; + +/** + * Beings and actors directions + * Needs to match client + */ +enum Direction +{ + DIRECTION_UP = 1, + DIRECTION_DOWN, + DIRECTION_LEFT, + DIRECTION_RIGHT +}; + +enum TimerID +{ + T_M_STROLL, // time until monster strolls to new location + T_M_KILLSTEAL_PROTECTED, // killsteal protection time + T_M_DECAY, // time until dead monster is removed + T_M_ATTACK_TIME, // time until monster can attack again + T_B_HP_REGEN, // time until hp is regenerated again + T_C_MUTE // time until the character can chat again +}; + +struct Status +{ + StatusEffect *status; + unsigned time; // Number of ticks +}; + +typedef std::map< int, Status > StatusEffects; + +/** + * Type definition for a list of hits + */ +typedef std::vector Hits; + +/** + * Generic being (living actor). Keeps direction, destination and a few other + * relevant properties. Used for characters & monsters (all animated objects). + */ +class Being : public Actor +{ + public: + /** + * Moves enum for beings and actors for others players vision. + * WARNING: Has to be in sync with the same enum in the Being class + * of the client! + */ + enum Action { + STAND, + WALK, + ATTACK, + SIT, + DEAD, + HURT + }; + + /** + * Moves enum for beings and actors for others players attack types. + * WARNING: Has to be in sync with the same enum in the Being class + * of the client! + */ + enum AttackType + { + HIT = 0x00, + CRITICAL = 0x0a, + MULTI = 0x08, + REFLECT = 0x04, + FLEE = 0x0b + }; + + /** + * Proxy constructor. + */ + Being(ThingType type); + + /** + * Cleans obsolete attribute modifiers. + */ + virtual void update(); + + /** + * Takes a damage structure, computes the real damage based on the + * stats, deducts the result from the hitpoints and adds the result to + * the HitsTaken list. + */ + virtual int damage(Actor *source, const Damage &damage); + + /** Restores all hit points of the being */ + void heal(); + + /** Restores a specific number of hit points of the being */ + void heal(int hp); + + /** + * Changes status and calls all the "died" listeners. + */ + virtual void died(); + + /** + * Performs actions scheduled by the being. + */ + virtual void perform() {} + + /** + * Gets the destination coordinates of the being. + */ + const Point &getDestination() const + { return mDst; } + + /** + * Sets the destination coordinates of the being. + */ + void setDestination(const Point &dst); + + /** + * Sets the destination coordinates of the being to the current + * position. + */ + void clearDestination() + { setDestination(getPosition()); } + + /** + * Gets the old coordinates of the being. + */ + const Point &getOldPosition() const + { return mOld; } + + /** + * Sets the facing direction of the being. + */ + void setDirection(int direction) + { mDirection = direction; raiseUpdateFlags(UPDATEFLAG_DIRCHANGE); } + + int getDirection() const + { return mDirection; } + + /** + * Gets the damage list. + */ + const Hits &getHitsTaken() const + { return mHitsTaken; } + + /** + * Clears the damage list. + */ + void clearHitsTaken() + { mHitsTaken.clear(); } + + /** + * Performs an attack. + * Return Value: damage inflicted or -1 when illegal target + */ + int performAttack(Being *target, const Damage &damage); + int performAttack(Being *target, unsigned range, const Damage &damage); + + /** + * Sets the current action. + */ + void setAction(Action action); + + /** + * Sets the current action. + */ + Action getAction() const + { return mAction; } + + /** + * Gets the type of the attack the being is currently performing. + */ + virtual int getAttackType() const + { return HIT; } + + /** + * Moves the being toward its destination. + */ + void move(); + + /** + * Returns the path to the being's current destination. + */ + virtual Path findPath(); + + /** + * Sets an attribute. + */ + void setAttribute(unsigned int id, double value); + + /** + * Gets an attribute. + */ + double getAttribute(unsigned int id) const; + + /** + * Gets an attribute after applying modifiers. + */ + double getModifiedAttribute(unsigned int id) const; + + /** + * No-op to satisfy shared structure. + * @note The game server calculates this manually, so nothing happens + * here. + */ + void setModAttribute(unsigned int id, double value); + + /** + * Checks whether or not an attribute exists in this being. + * @returns True if the attribute is present in the being, false otherwise. + */ + + bool checkAttributeExists(unsigned int id) const + { return mAttributes.count(id); } + + /** + * Adds a modifier to one attribute. + * @param duration If non-zero, creates a temporary modifier that + * expires after \p duration ticks. + * @param lvl If non-zero, indicates that a temporary modifier can be + * dispelled prematuraly by a spell of given level. + */ + void applyModifier(unsigned int attr, double value, unsigned int layer, + unsigned int duration = 0, unsigned int id = 0); + + bool removeModifier(unsigned int attr, double value, unsigned int layer, + unsigned int id = 0, bool fullcheck = false); + + /** + * Called when an attribute modifier is changed. + * Recalculate the base value of an attribute and update derived + * attributes if it has changed. + * @returns Whether it was changed. + */ + virtual bool recalculateBaseAttribute(unsigned int); + + /** + * Attribute has changed, recalculate base value of dependant + * attributes (and handle other actions for the modified + * attribute) + */ + virtual void updateDerivedAttributes(unsigned int); + + /** + * Sets a statuseffect on this being + */ + void applyStatusEffect(int id, int time); + + /** + * Removes the status effect + */ + void removeStatusEffect(int id); + + /** + * Returns true if the being has a status effect + */ + bool hasStatusEffect(int id) const; + + /** + * Returns the time of the status effect if in effect, or 0 if not + */ + unsigned getStatusEffectTime(int id) const; + + /** + * Changes the time of the status effect (if in effect) + */ + void setStatusEffectTime(int id, int time); + + /** Gets the name of the being. */ + const std::string &getName() const + { return mName; } + + /** Sets the name of the being. */ + void setName(const std::string &name) + { mName = name; } + + /** + * Converts a direction to an angle. Used for combat hit checks. + */ + static int directionToAngle(int direction); + + /** + * Get Target + */ + Being *getTarget() const + { return mTarget; } + + /** + * Set Target + */ + void setTarget(Being *target) + { mTarget = target; } + + + protected: + static const int TICKS_PER_HP_REGENERATION = 100; + Action mAction; + AttributeMap mAttributes; + AutoAttacks mAutoAttacks; + StatusEffects mStatus; + Being *mTarget; + Point mOld; /**< Old coordinates. */ + Point mDst; /**< Target coordinates. */ + + /** Sets timer unless already higher. */ + void setTimerSoft(TimerID id, int value); + + /** + * Sets timer even when already higher (when in doubt this one is + * faster) + */ + void setTimerHard(TimerID id, int value); + + /** Returns number of ticks left on the timer */ + int getTimer(TimerID id) const; + + /** Returns whether timer exists and is > 0 */ + bool isTimerRunning(TimerID id) const; + + /** Returns whether the timer reached 0 in this tick */ + bool isTimerJustFinished(TimerID id) const; + + private: + Being(const Being &rhs); + Being &operator=(const Being &rhs); + + Path mPath; + unsigned char mDirection; /**< Facing direction. */ + + std::string mName; + Hits mHitsTaken; /**< List of punches taken since last update. */ + + typedef std::map Timers; + Timers mTimers; +}; + +#endif // BEING_H diff --git a/src/game-server/being.hpp b/src/game-server/being.hpp deleted file mode 100644 index 4506cfec..00000000 --- a/src/game-server/being.hpp +++ /dev/null @@ -1,373 +0,0 @@ -/* - * The Mana Server - * Copyright (C) 2004-2010 The Mana World Development Team - * - * This file is part of The Mana Server. - * - * The Mana Server 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 - * any later version. - * - * The Mana Server 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 The Mana Server. If not, see . - */ - -#ifndef BEING_H -#define BEING_H - -#include -#include -#include -#include -#include "limits.h" - -#include "game-server/actor.hpp" -#include "game-server/attribute.hpp" -#include "game-server/autoattack.hpp" - -class Being; -class MapComposite; -class StatusEffect; - -typedef std::map< unsigned int, Attribute > AttributeMap; - -/** - * Beings and actors directions - * Needs to match client - */ -enum Direction -{ - DIRECTION_UP = 1, - DIRECTION_DOWN, - DIRECTION_LEFT, - DIRECTION_RIGHT -}; - -enum TimerID -{ - T_M_STROLL, // time until monster strolls to new location - T_M_KILLSTEAL_PROTECTED, // killsteal protection time - T_M_DECAY, // time until dead monster is removed - T_M_ATTACK_TIME, // time until monster can attack again - T_B_HP_REGEN, // time until hp is regenerated again - T_C_MUTE // time until the character can chat again -}; - -struct Status -{ - StatusEffect *status; - unsigned time; // Number of ticks -}; - -typedef std::map< int, Status > StatusEffects; - -/** - * Type definition for a list of hits - */ -typedef std::vector Hits; - -/** - * Generic being (living actor). Keeps direction, destination and a few other - * relevant properties. Used for characters & monsters (all animated objects). - */ -class Being : public Actor -{ - public: - /** - * Moves enum for beings and actors for others players vision. - * WARNING: Has to be in sync with the same enum in the Being class - * of the client! - */ - enum Action { - STAND, - WALK, - ATTACK, - SIT, - DEAD, - HURT - }; - - /** - * Moves enum for beings and actors for others players attack types. - * WARNING: Has to be in sync with the same enum in the Being class - * of the client! - */ - enum AttackType - { - HIT = 0x00, - CRITICAL = 0x0a, - MULTI = 0x08, - REFLECT = 0x04, - FLEE = 0x0b - }; - - /** - * Proxy constructor. - */ - Being(ThingType type); - - /** - * Cleans obsolete attribute modifiers. - */ - virtual void update(); - - /** - * Takes a damage structure, computes the real damage based on the - * stats, deducts the result from the hitpoints and adds the result to - * the HitsTaken list. - */ - virtual int damage(Actor *source, const Damage &damage); - - /** Restores all hit points of the being */ - void heal(); - - /** Restores a specific number of hit points of the being */ - void heal(int hp); - - /** - * Changes status and calls all the "died" listeners. - */ - virtual void died(); - - /** - * Performs actions scheduled by the being. - */ - virtual void perform() {} - - /** - * Gets the destination coordinates of the being. - */ - const Point &getDestination() const - { return mDst; } - - /** - * Sets the destination coordinates of the being. - */ - void setDestination(const Point &dst); - - /** - * Sets the destination coordinates of the being to the current - * position. - */ - void clearDestination() - { setDestination(getPosition()); } - - /** - * Gets the old coordinates of the being. - */ - const Point &getOldPosition() const - { return mOld; } - - /** - * Sets the facing direction of the being. - */ - void setDirection(int direction) - { mDirection = direction; raiseUpdateFlags(UPDATEFLAG_DIRCHANGE); } - - int getDirection() const - { return mDirection; } - - /** - * Gets the damage list. - */ - const Hits &getHitsTaken() const - { return mHitsTaken; } - - /** - * Clears the damage list. - */ - void clearHitsTaken() - { mHitsTaken.clear(); } - - /** - * Performs an attack. - * Return Value: damage inflicted or -1 when illegal target - */ - int performAttack(Being *target, const Damage &damage); - int performAttack(Being *target, unsigned range, const Damage &damage); - - /** - * Sets the current action. - */ - void setAction(Action action); - - /** - * Sets the current action. - */ - Action getAction() const - { return mAction; } - - /** - * Gets the type of the attack the being is currently performing. - */ - virtual int getAttackType() const - { return HIT; } - - /** - * Moves the being toward its destination. - */ - void move(); - - /** - * Returns the path to the being's current destination. - */ - virtual Path findPath(); - - /** - * Sets an attribute. - */ - void setAttribute(unsigned int id, double value); - - /** - * Gets an attribute. - */ - double getAttribute(unsigned int id) const; - - /** - * Gets an attribute after applying modifiers. - */ - double getModifiedAttribute(unsigned int id) const; - - /** - * No-op to satisfy shared structure. - * @note The game server calculates this manually, so nothing happens - * here. - */ - void setModAttribute(unsigned int id, double value); - - /** - * Checks whether or not an attribute exists in this being. - * @returns True if the attribute is present in the being, false otherwise. - */ - - bool checkAttributeExists(unsigned int id) const - { return mAttributes.count(id); } - - /** - * Adds a modifier to one attribute. - * @param duration If non-zero, creates a temporary modifier that - * expires after \p duration ticks. - * @param lvl If non-zero, indicates that a temporary modifier can be - * dispelled prematuraly by a spell of given level. - */ - void applyModifier(unsigned int attr, double value, unsigned int layer, - unsigned int duration = 0, unsigned int id = 0); - - bool removeModifier(unsigned int attr, double value, unsigned int layer, - unsigned int id = 0, bool fullcheck = false); - - /** - * Called when an attribute modifier is changed. - * Recalculate the base value of an attribute and update derived - * attributes if it has changed. - * @returns Whether it was changed. - */ - virtual bool recalculateBaseAttribute(unsigned int); - - /** - * Attribute has changed, recalculate base value of dependant - * attributes (and handle other actions for the modified - * attribute) - */ - virtual void updateDerivedAttributes(unsigned int); - - /** - * Sets a statuseffect on this being - */ - void applyStatusEffect(int id, int time); - - /** - * Removes the status effect - */ - void removeStatusEffect(int id); - - /** - * Returns true if the being has a status effect - */ - bool hasStatusEffect(int id) const; - - /** - * Returns the time of the status effect if in effect, or 0 if not - */ - unsigned getStatusEffectTime(int id) const; - - /** - * Changes the time of the status effect (if in effect) - */ - void setStatusEffectTime(int id, int time); - - /** Gets the name of the being. */ - const std::string &getName() const - { return mName; } - - /** Sets the name of the being. */ - void setName(const std::string &name) - { mName = name; } - - /** - * Converts a direction to an angle. Used for combat hit checks. - */ - static int directionToAngle(int direction); - - /** - * Get Target - */ - Being *getTarget() const - { return mTarget; } - - /** - * Set Target - */ - void setTarget(Being *target) - { mTarget = target; } - - - protected: - static const int TICKS_PER_HP_REGENERATION = 100; - Action mAction; - AttributeMap mAttributes; - AutoAttacks mAutoAttacks; - StatusEffects mStatus; - Being *mTarget; - Point mOld; /**< Old coordinates. */ - Point mDst; /**< Target coordinates. */ - - /** Sets timer unless already higher. */ - void setTimerSoft(TimerID id, int value); - - /** - * Sets timer even when already higher (when in doubt this one is - * faster) - */ - void setTimerHard(TimerID id, int value); - - /** Returns number of ticks left on the timer */ - int getTimer(TimerID id) const; - - /** Returns whether timer exists and is > 0 */ - bool isTimerRunning(TimerID id) const; - - /** Returns whether the timer reached 0 in this tick */ - bool isTimerJustFinished(TimerID id) const; - - private: - Being(const Being &rhs); - Being &operator=(const Being &rhs); - - Path mPath; - unsigned char mDirection; /**< Facing direction. */ - - std::string mName; - Hits mHitsTaken; /**< List of punches taken since last update. */ - - typedef std::map Timers; - Timers mTimers; -}; - -#endif // BEING_H diff --git a/src/game-server/buysell.cpp b/src/game-server/buysell.cpp index a6f68e1a..b3abb3e2 100644 --- a/src/game-server/buysell.cpp +++ b/src/game-server/buysell.cpp @@ -18,14 +18,14 @@ * along with The Mana Server. If not, see . */ -#include "game-server/buysell.hpp" +#include "game-server/buysell.h" -#include "game-server/character.hpp" -#include "game-server/gamehandler.hpp" -#include "game-server/inventory.hpp" -#include "game-server/itemmanager.hpp" -#include "game-server/item.hpp" -#include "net/messageout.hpp" +#include "game-server/character.h" +#include "game-server/gamehandler.h" +#include "game-server/inventory.h" +#include "game-server/itemmanager.h" +#include "game-server/item.h" +#include "net/messageout.h" #include "defines.h" diff --git a/src/game-server/buysell.h b/src/game-server/buysell.h new file mode 100644 index 00000000..506dc8ad --- /dev/null +++ b/src/game-server/buysell.h @@ -0,0 +1,86 @@ +/* + * The Mana Server + * Copyright (C) 2007-2010 The Mana World Development Team + * + * This file is part of The Mana Server. + * + * The Mana Server 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 + * any later version. + * + * The Mana Server 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 The Mana Server. If not, see . + */ + +#ifndef GAMESERVER_BUYSELL_H +#define GAMESERVER_BUYSELL_H + +#include + +class Character; +class Actor; + +class BuySell +{ + public: + + /** + * Sets up a trade between a character and an NPC. + */ + BuySell(Character *, bool sell); + + /** + * Cancels the trade. + */ + void cancel(); + + /** + * Registers an item and indicates how many the NPC is ready to trade + * and how much it will cost. + * @return true if at least one item was registered. + */ + bool registerItem(int id, int amount, int cost); + + /** + * Registers every player's item at an average cost given by the ItemDB. + * @return the number of different soldable items. + */ + int registerPlayerItems(); + + /** + * Sends the item list to player. + * @return true if at least one item was registered before start. + */ + bool start(Actor *actor); + + /** + * Performs the trade. + */ + void perform(int id, int amount); + + private: + + ~BuySell(); + + struct TradedItem + { + unsigned short itemId, amount, cost; + }; + + typedef std::vector< TradedItem > TradedItems; + + /** The attribute ID of the currency to use. Hardcoded for now (FIXME) */ + unsigned int mCurrencyId; + + Character *mChar; /**< Character involved. */ + TradedItems mItems; /**< Traded items. */ + bool mSell; /**< Are items sold? */ +}; + +#endif diff --git a/src/game-server/buysell.hpp b/src/game-server/buysell.hpp deleted file mode 100644 index a9903bc2..00000000 --- a/src/game-server/buysell.hpp +++ /dev/null @@ -1,86 +0,0 @@ -/* - * The Mana Server - * Copyright (C) 2007-2010 The Mana World Development Team - * - * This file is part of The Mana Server. - * - * The Mana Server 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 - * any later version. - * - * The Mana Server 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 The Mana Server. If not, see . - */ - -#ifndef GAMESERVER_BUYSELL_HPP -#define GAMESERVER_BUYSELL_HPP - -#include - -class Character; -class Actor; - -class BuySell -{ - public: - - /** - * Sets up a trade between a character and an NPC. - */ - BuySell(Character *, bool sell); - - /** - * Cancels the trade. - */ - void cancel(); - - /** - * Registers an item and indicates how many the NPC is ready to trade - * and how much it will cost. - * @return true if at least one item was registered. - */ - bool registerItem(int id, int amount, int cost); - - /** - * Registers every player's item at an average cost given by the ItemDB. - * @return the number of different soldable items. - */ - int registerPlayerItems(); - - /** - * Sends the item list to player. - * @return true if at least one item was registered before start. - */ - bool start(Actor *actor); - - /** - * Performs the trade. - */ - void perform(int id, int amount); - - private: - - ~BuySell(); - - struct TradedItem - { - unsigned short itemId, amount, cost; - }; - - typedef std::vector< TradedItem > TradedItems; - - /** The attribute ID of the currency to use. Hardcoded for now (FIXME) */ - unsigned int mCurrencyId; - - Character *mChar; /**< Character involved. */ - TradedItems mItems; /**< Traded items. */ - bool mSell; /**< Are items sold? */ -}; - -#endif diff --git a/src/game-server/character.cpp b/src/game-server/character.cpp index 91fcf469..49cecebc 100644 --- a/src/game-server/character.cpp +++ b/src/game-server/character.cpp @@ -23,25 +23,25 @@ #include #include -#include "game-server/character.hpp" - -#include "common/configuration.hpp" -#include "game-server/accountconnection.hpp" -#include "game-server/attributemanager.hpp" -#include "game-server/buysell.hpp" -#include "game-server/eventlistener.hpp" -#include "game-server/inventory.hpp" -#include "game-server/item.hpp" -#include "game-server/itemmanager.hpp" -#include "game-server/gamehandler.hpp" -#include "game-server/mapcomposite.hpp" -#include "game-server/mapmanager.hpp" -#include "game-server/state.hpp" -#include "game-server/trade.hpp" -#include "scripting/script.hpp" -#include "net/messagein.hpp" -#include "net/messageout.hpp" -#include "serialize/characterdata.hpp" +#include "game-server/character.h" + +#include "common/configuration.h" +#include "game-server/accountconnection.h" +#include "game-server/attributemanager.h" +#include "game-server/buysell.h" +#include "game-server/eventlistener.h" +#include "game-server/inventory.h" +#include "game-server/item.h" +#include "game-server/itemmanager.h" +#include "game-server/gamehandler.h" +#include "game-server/mapcomposite.h" +#include "game-server/mapmanager.h" +#include "game-server/state.h" +#include "game-server/trade.h" +#include "scripting/script.h" +#include "net/messagein.h" +#include "net/messageout.h" +#include "serialize/characterdata.h" #include "utils/logger.h" diff --git a/src/game-server/character.h b/src/game-server/character.h new file mode 100644 index 00000000..dc12099b --- /dev/null +++ b/src/game-server/character.h @@ -0,0 +1,467 @@ +/* + * The Mana Server + * Copyright (C) 2004-2010 The Mana World Development Team + * + * This file is part of The Mana Server. + * + * The Mana Server 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 + * any later version. + * + * The Mana Server 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 The Mana Server. If not, see . + */ + +#ifndef CHARACTER_H +#define CHARACTER_H + +#include +#include +#include + +#include "common/inventorydata.h" +#include "game-server/being.h" +#include "protocol.h" +#include "defines.h" +#include "utils/logger.h" + +class BuySell; +class GameClient; +class MessageIn; +class MessageOut; +class Point; +class Trade; + +struct Special +{ + Special() + : currentMana(0) + , neededMana(0) + {} + + int currentMana; + int neededMana; +}; + +/** + * The representation of a player's character in the game world. + */ +class Character : public Being +{ + public: + /** + * Utility constructor for creating a Character from a received + * characterdata message. + */ + Character(MessageIn &msg); + + ~Character(); + + /** + * recalculates the level when necessary and calls Being::update + */ + void update(); + + /** + * Perform actions. + */ + void perform(); + + /** + * Executes the global die script and calls the base class function + */ + virtual void died(); + + /** + * makes the character respawn + */ + void respawn(); + + /** + * makes the character perform a special action + * when it is allowed to do so + */ + void useSpecial(int id); + + /** + * Allows a character to perform a special action + */ + void giveSpecial(int id); + + /** + * Removes all specials from character + */ + void clearSpecials(); + + /** + * Checks if a character knows a special action + */ + bool hasSpecial(int id) { return mSpecials.find(id) != mSpecials.end(); } + + /** + * Removes an available special action + */ + void takeSpecial(int id); + + /** + * Gets client computer. + */ + GameClient *getClient() const + { return mClient; } + + /** + * Sets client computer. + */ + void setClient(GameClient *c) + { mClient = c; } + + /** + * Gets a reference to the possessions. + */ + const Possessions &getPossessions() const + { return mPossessions; } + + /** + * Gets a reference to the possessions. + */ + Possessions &getPossessions() + { return mPossessions; } + + /** + * Gets the Trade object the character is involved in. + */ + Trade *getTrading() const; + + /** + * Sets the Trade object the character is involved in. + * Cancels other transactions. + */ + void setTrading(Trade *t); + + /** + * Gets the BuySell object the character is involved in. + */ + BuySell *getBuySell() const; + + /** + * Sets the trade object the character is involved in. + * Cancels other transactions. + */ + void setBuySell(BuySell *t); + + /** + * Cancels current transaction. + */ + void cancelTransaction(); + + /** + * Gets transaction status of the character. + */ + bool isBusy() const + { return mTransaction != TRANS_NONE; } + + /* + * Character data: + * Get and set methods + * Most of this should be accessed directly as a friend + */ + + int getDatabaseID() const { return mDatabaseID; } + void setDatabaseID(int id) { mDatabaseID = id; } + + /** Gets the gender of the character (male or female). */ + int getGender() const + { return mGender; } + + /** Sets the gender of the character (male or female). */ + void setGender(int gender) + { mGender = gender; } + + int getHairStyle() const { return mHairStyle; } + void setHairStyle(int style) { mHairStyle = style; } + + int getHairColor() const { return mHairColor; } + void setHairColor(int color) { mHairColor = color; } + + int getLevel() const { return mLevel; } + void setLevel(int level) { mLevel = level; } + + int getAccountLevel() const { return mAccountLevel; } + void setAccountLevel(int l) { mAccountLevel = l; } + + /** Gets the party id of the character */ + int getParty() const + { return mParty; } + + /** Sets the party id of the character */ + void setParty(int party) + { mParty = party; } + + /** + * Sends a message that informs the client about attribute + * modified since last call. + */ + void sendStatus(); + + /** + * Gets the ID of the map that the character is on. + * For serialization purpose only. + */ + int getMapId() const; + + /** + * Sets the ID of the map that the character is on. + * For serialization purpose only. + */ + void setMapId(int); + + /** + * Marks all attributes as being modified. + */ + void modifiedAllAttribute(); + + /** + * Recalculate the base value of an attribute and update derived + * attributes if it has changed. + * @returns Whether it was changed. + */ + bool recalculateBaseAttribute(unsigned int); + + /** + * Attribute has changed, recalculate base value of dependant + * attributes (and handle other actions for the modified + * attribute) + */ + void updateDerivedAttributes(unsigned int); + + /** + * Calls all the "disconnected" listener. + */ + void disconnected(); + + /** + * Associative array containing all the quest variables known by the + * server. + */ + std::map< std::string, std::string > questCache; + + /** + * Gives a skill a specific amount of exp and checks if a levelup + * occured. + */ + void receiveExperience(int skill, int experience, int optimalLevel); + + int getSkillSize() const + { return mExperience.size(); } + + const std::map::const_iterator getSkillBegin() const + { return mExperience.begin(); } + + const std::map::const_iterator getSkillEnd() const + { return mExperience.end(); } + + /** + * Used to serialize status effects. + */ + int getStatusEffectSize() const + { return mStatusEffects.size(); } + + const std::map::const_iterator getStatusEffectBegin() const + { return mStatusEffects.begin(); } + + const std::map::const_iterator getStatusEffectEnd() const + { return mStatusEffects.end(); } + + /** + * Used to serialize kill count. + */ + int getKillCountSize() const + { return mKillCount.size(); } + + const std::map::const_iterator getKillCountBegin() const + { return mKillCount.begin(); } + + const std::map::const_iterator getKillCountEnd() const + { return mKillCount.end(); } + + void setKillCount(int monsterId, int kills) + { mKillCount[monsterId] = kills; } + + /** + * Used to serialize specials. + */ + int getSpecialSize() const + { return mSpecials.size(); } + + const std::map::const_iterator getSpecialBegin() const + { return mSpecials.begin(); } + + const std::map::const_iterator getSpecialEnd() const + { return mSpecials.end(); } + + /** + * Gets total accumulated exp for skill. + */ + int getExperience(int skill) const + { return mExperience.find(skill)->second; } + + /** + * Sets total accumulated exp for skill. + */ + void setExperience(int skill, int value) + { mExperience[skill] = 0; receiveExperience(skill, value, 0); } + + /** + * Adds one kill of the monster type to the characters kill count. + */ + void incrementKillCount(int monsterType); + + /** + * Gets the number of monsters the character killed of a given type. + */ + int getKillCount(int monsterType) const; + + /** + * Returns the exp needed to reach a specific skill level + */ + static int expForLevel(int level); + + /** + * Returns the level for a given exp + */ + static int levelForExp(int exp); + + /** + * Tries to use a character point to increase a + * basic attribute + */ + AttribmodResponseCode useCharacterPoint(size_t attribute); + + /** + * Tries to use a correction point to reduce a + * basic attribute and regain a character point + */ + AttribmodResponseCode useCorrectionPoint(size_t attribute); + + void setCharacterPoints(int points) { mCharacterPoints = points; } + int getCharacterPoints() const { return mCharacterPoints; } + + void setCorrectionPoints(int points) { mCorrectionPoints = points; } + int getCorrectionPoints() const { return mCorrectionPoints; } + + /** + * Gets the way the actor is blocked by other things on the map + */ + virtual unsigned char getWalkMask() const + { return 0x82; } // blocked by walls and monsters ( bin 1000 0010) + + /** Makes it impossible to chat for a while */ + void mute(int seconds) + { setTimerHard(T_C_MUTE, seconds * 10); } + + bool isMuted() const + { return isTimerRunning(T_C_MUTE); } + + protected: + /** + * Gets the way the actor blocks pathfinding for other objects + */ + virtual Map::BlockType getBlockType() const + { return Map::BLOCKTYPE_CHARACTER; } + + private: + double getAttrBase(AttributeMap::const_iterator it) const + { return it->second.getBase(); } + double getAttrMod(AttributeMap::const_iterator it) const + { return it->second.getModifiedAttribute(); } + + Character(const Character &); + Character &operator=(const Character &); + + static const float EXPCURVE_EXPONENT; + static const float EXPCURVE_FACTOR; + static const float LEVEL_SKILL_PRECEDENCE_FACTOR; // I am taking suggestions for a better name + static const float EXP_LEVEL_FLEXIBILITY; + static const int CHARPOINTS_PER_LEVELUP = 5; + static const int CORRECTIONPOINTS_PER_LEVELUP = 2; + static const int CORRECTIONPOINTS_MAX = 10; + + /** + * Advances the character by one level; + */ + void levelup(); + + /** + * Marks attribute as recently modified. + */ + void flagAttribute(int); + + /** + * Returns the exp needed for next skill levelup + */ + int getExpNeeded(size_t skill) const; + + /** + * Returns the exp collected on this skill level + */ + int getExpGot(size_t skill) const; + + /** + * Recalculates the character level + */ + void recalculateLevel(); + + /** + * Informs the client about his characters special charge status + */ + void sendSpecialUpdate(); + + enum TransactionType + { TRANS_NONE, TRANS_TRADE, TRANS_BUYSELL }; + + GameClient *mClient; /**< Client computer. */ + /** Handler of the transaction the character is involved in. */ + void *mTransactionHandler; + + Possessions mPossessions; /**< Possesssions of the character. */ + + /** Attributes modified since last update. */ + std::set mModifiedAttributes; + std::set mModifiedExperience; + + std::map mExperience; /**< experience collected for each skill.*/ + + std::map mSpecials; + std::map mStatusEffects; /**< only used by select functions + to make it easier to make the accountserver + do not modify or use anywhere else*/ + int mRechargePerSpecial; + bool mSpecialUpdateNeeded; + + int mDatabaseID; /**< Character's database ID. */ + unsigned char mGender; /**< Gender of the character. */ + unsigned char mHairStyle; /**< Hair Style of the character. */ + unsigned char mHairColor; /**< Hair Color of the character. */ + int mLevel; /**< Level of the character. */ + int mLevelProgress; /**< progress to next level in percent */ + int mCharacterPoints; /**< Unused attribute points that can be distributed */ + int mCorrectionPoints; /**< Unused attribute correction points */ + bool mUpdateLevelProgress; /**< Flag raised when percent to next level changed */ + bool mRecalculateLevel; /**< Flag raised when the character level might have increased */ + unsigned char mAccountLevel; /**< Account level of the user. */ + int mParty; /**< Party id of the character */ + TransactionType mTransaction; /**< Trade/buy/sell action the character is involved in. */ + std::map mKillCount; /**< How many monsters the character has slain of each type */ + + // Set as a friend, but still a lot of redundant accessors. FIXME. + template< class T > + friend void serializeCharacterData(const T &data, MessageOut &msg); +}; + +#endif // CHARACTER_H diff --git a/src/game-server/character.hpp b/src/game-server/character.hpp deleted file mode 100644 index ed41c2b2..00000000 --- a/src/game-server/character.hpp +++ /dev/null @@ -1,467 +0,0 @@ -/* - * The Mana Server - * Copyright (C) 2004-2010 The Mana World Development Team - * - * This file is part of The Mana Server. - * - * The Mana Server 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 - * any later version. - * - * The Mana Server 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 The Mana Server. If not, see . - */ - -#ifndef CHARACTER_HPP -#define CHARACTER_HPP - -#include -#include -#include - -#include "common/inventorydata.hpp" -#include "game-server/being.hpp" -#include "protocol.h" -#include "defines.h" -#include "utils/logger.h" - -class BuySell; -class GameClient; -class MessageIn; -class MessageOut; -class Point; -class Trade; - -struct Special -{ - Special() - : currentMana(0) - , neededMana(0) - {} - - int currentMana; - int neededMana; -}; - -/** - * The representation of a player's character in the game world. - */ -class Character : public Being -{ - public: - /** - * Utility constructor for creating a Character from a received - * characterdata message. - */ - Character(MessageIn &msg); - - ~Character(); - - /** - * recalculates the level when necessary and calls Being::update - */ - void update(); - - /** - * Perform actions. - */ - void perform(); - - /** - * Executes the global die script and calls the base class function - */ - virtual void died(); - - /** - * makes the character respawn - */ - void respawn(); - - /** - * makes the character perform a special action - * when it is allowed to do so - */ - void useSpecial(int id); - - /** - * Allows a character to perform a special action - */ - void giveSpecial(int id); - - /** - * Removes all specials from character - */ - void clearSpecials(); - - /** - * Checks if a character knows a special action - */ - bool hasSpecial(int id) { return mSpecials.find(id) != mSpecials.end(); } - - /** - * Removes an available special action - */ - void takeSpecial(int id); - - /** - * Gets client computer. - */ - GameClient *getClient() const - { return mClient; } - - /** - * Sets client computer. - */ - void setClient(GameClient *c) - { mClient = c; } - - /** - * Gets a reference to the possessions. - */ - const Possessions &getPossessions() const - { return mPossessions; } - - /** - * Gets a reference to the possessions. - */ - Possessions &getPossessions() - { return mPossessions; } - - /** - * Gets the Trade object the character is involved in. - */ - Trade *getTrading() const; - - /** - * Sets the Trade object the character is involved in. - * Cancels other transactions. - */ - void setTrading(Trade *t); - - /** - * Gets the BuySell object the character is involved in. - */ - BuySell *getBuySell() const; - - /** - * Sets the trade object the character is involved in. - * Cancels other transactions. - */ - void setBuySell(BuySell *t); - - /** - * Cancels current transaction. - */ - void cancelTransaction(); - - /** - * Gets transaction status of the character. - */ - bool isBusy() const - { return mTransaction != TRANS_NONE; } - - /* - * Character data: - * Get and set methods - * Most of this should be accessed directly as a friend - */ - - int getDatabaseID() const { return mDatabaseID; } - void setDatabaseID(int id) { mDatabaseID = id; } - - /** Gets the gender of the character (male or female). */ - int getGender() const - { return mGender; } - - /** Sets the gender of the character (male or female). */ - void setGender(int gender) - { mGender = gender; } - - int getHairStyle() const { return mHairStyle; } - void setHairStyle(int style) { mHairStyle = style; } - - int getHairColor() const { return mHairColor; } - void setHairColor(int color) { mHairColor = color; } - - int getLevel() const { return mLevel; } - void setLevel(int level) { mLevel = level; } - - int getAccountLevel() const { return mAccountLevel; } - void setAccountLevel(int l) { mAccountLevel = l; } - - /** Gets the party id of the character */ - int getParty() const - { return mParty; } - - /** Sets the party id of the character */ - void setParty(int party) - { mParty = party; } - - /** - * Sends a message that informs the client about attribute - * modified since last call. - */ - void sendStatus(); - - /** - * Gets the ID of the map that the character is on. - * For serialization purpose only. - */ - int getMapId() const; - - /** - * Sets the ID of the map that the character is on. - * For serialization purpose only. - */ - void setMapId(int); - - /** - * Marks all attributes as being modified. - */ - void modifiedAllAttribute(); - - /** - * Recalculate the base value of an attribute and update derived - * attributes if it has changed. - * @returns Whether it was changed. - */ - bool recalculateBaseAttribute(unsigned int); - - /** - * Attribute has changed, recalculate base value of dependant - * attributes (and handle other actions for the modified - * attribute) - */ - void updateDerivedAttributes(unsigned int); - - /** - * Calls all the "disconnected" listener. - */ - void disconnected(); - - /** - * Associative array containing all the quest variables known by the - * server. - */ - std::map< std::string, std::string > questCache; - - /** - * Gives a skill a specific amount of exp and checks if a levelup - * occured. - */ - void receiveExperience(int skill, int experience, int optimalLevel); - - int getSkillSize() const - { return mExperience.size(); } - - const std::map::const_iterator getSkillBegin() const - { return mExperience.begin(); } - - const std::map::const_iterator getSkillEnd() const - { return mExperience.end(); } - - /** - * Used to serialize status effects. - */ - int getStatusEffectSize() const - { return mStatusEffects.size(); } - - const std::map::const_iterator getStatusEffectBegin() const - { return mStatusEffects.begin(); } - - const std::map::const_iterator getStatusEffectEnd() const - { return mStatusEffects.end(); } - - /** - * Used to serialize kill count. - */ - int getKillCountSize() const - { return mKillCount.size(); } - - const std::map::const_iterator getKillCountBegin() const - { return mKillCount.begin(); } - - const std::map::const_iterator getKillCountEnd() const - { return mKillCount.end(); } - - void setKillCount(int monsterId, int kills) - { mKillCount[monsterId] = kills; } - - /** - * Used to serialize specials. - */ - int getSpecialSize() const - { return mSpecials.size(); } - - const std::map::const_iterator getSpecialBegin() const - { return mSpecials.begin(); } - - const std::map::const_iterator getSpecialEnd() const - { return mSpecials.end(); } - - /** - * Gets total accumulated exp for skill. - */ - int getExperience(int skill) const - { return mExperience.find(skill)->second; } - - /** - * Sets total accumulated exp for skill. - */ - void setExperience(int skill, int value) - { mExperience[skill] = 0; receiveExperience(skill, value, 0); } - - /** - * Adds one kill of the monster type to the characters kill count. - */ - void incrementKillCount(int monsterType); - - /** - * Gets the number of monsters the character killed of a given type. - */ - int getKillCount(int monsterType) const; - - /** - * Returns the exp needed to reach a specific skill level - */ - static int expForLevel(int level); - - /** - * Returns the level for a given exp - */ - static int levelForExp(int exp); - - /** - * Tries to use a character point to increase a - * basic attribute - */ - AttribmodResponseCode useCharacterPoint(size_t attribute); - - /** - * Tries to use a correction point to reduce a - * basic attribute and regain a character point - */ - AttribmodResponseCode useCorrectionPoint(size_t attribute); - - void setCharacterPoints(int points) { mCharacterPoints = points; } - int getCharacterPoints() const { return mCharacterPoints; } - - void setCorrectionPoints(int points) { mCorrectionPoints = points; } - int getCorrectionPoints() const { return mCorrectionPoints; } - - /** - * Gets the way the actor is blocked by other things on the map - */ - virtual unsigned char getWalkMask() const - { return 0x82; } // blocked by walls and monsters ( bin 1000 0010) - - /** Makes it impossible to chat for a while */ - void mute(int seconds) - { setTimerHard(T_C_MUTE, seconds * 10); } - - bool isMuted() const - { return isTimerRunning(T_C_MUTE); } - - protected: - /** - * Gets the way the actor blocks pathfinding for other objects - */ - virtual Map::BlockType getBlockType() const - { return Map::BLOCKTYPE_CHARACTER; } - - private: - double getAttrBase(AttributeMap::const_iterator it) const - { return it->second.getBase(); } - double getAttrMod(AttributeMap::const_iterator it) const - { return it->second.getModifiedAttribute(); } - - Character(const Character &); - Character &operator=(const Character &); - - static const float EXPCURVE_EXPONENT; - static const float EXPCURVE_FACTOR; - static const float LEVEL_SKILL_PRECEDENCE_FACTOR; // I am taking suggestions for a better name - static const float EXP_LEVEL_FLEXIBILITY; - static const int CHARPOINTS_PER_LEVELUP = 5; - static const int CORRECTIONPOINTS_PER_LEVELUP = 2; - static const int CORRECTIONPOINTS_MAX = 10; - - /** - * Advances the character by one level; - */ - void levelup(); - - /** - * Marks attribute as recently modified. - */ - void flagAttribute(int); - - /** - * Returns the exp needed for next skill levelup - */ - int getExpNeeded(size_t skill) const; - - /** - * Returns the exp collected on this skill level - */ - int getExpGot(size_t skill) const; - - /** - * Recalculates the character level - */ - void recalculateLevel(); - - /** - * Informs the client about his characters special charge status - */ - void sendSpecialUpdate(); - - enum TransactionType - { TRANS_NONE, TRANS_TRADE, TRANS_BUYSELL }; - - GameClient *mClient; /**< Client computer. */ - /** Handler of the transaction the character is involved in. */ - void *mTransactionHandler; - - Possessions mPossessions; /**< Possesssions of the character. */ - - /** Attributes modified since last update. */ - std::set mModifiedAttributes; - std::set mModifiedExperience; - - std::map mExperience; /**< experience collected for each skill.*/ - - std::map mSpecials; - std::map mStatusEffects; /**< only used by select functions - to make it easier to make the accountserver - do not modify or use anywhere else*/ - int mRechargePerSpecial; - bool mSpecialUpdateNeeded; - - int mDatabaseID; /**< Character's database ID. */ - unsigned char mGender; /**< Gender of the character. */ - unsigned char mHairStyle; /**< Hair Style of the character. */ - unsigned char mHairColor; /**< Hair Color of the character. */ - int mLevel; /**< Level of the character. */ - int mLevelProgress; /**< progress to next level in percent */ - int mCharacterPoints; /**< Unused attribute points that can be distributed */ - int mCorrectionPoints; /**< Unused attribute correction points */ - bool mUpdateLevelProgress; /**< Flag raised when percent to next level changed */ - bool mRecalculateLevel; /**< Flag raised when the character level might have increased */ - unsigned char mAccountLevel; /**< Account level of the user. */ - int mParty; /**< Party id of the character */ - TransactionType mTransaction; /**< Trade/buy/sell action the character is involved in. */ - std::map mKillCount; /**< How many monsters the character has slain of each type */ - - // Set as a friend, but still a lot of redundant accessors. FIXME. - template< class T > - friend void serializeCharacterData(const T &data, MessageOut &msg); -}; - -#endif // CHARACTER_HPP diff --git a/src/game-server/collisiondetection.cpp b/src/game-server/collisiondetection.cpp index 8716baa2..55e40d65 100644 --- a/src/game-server/collisiondetection.cpp +++ b/src/game-server/collisiondetection.cpp @@ -18,7 +18,7 @@ * along with The Mana Server. If not, see . */ -#include "game-server/collisiondetection.hpp" +#include "game-server/collisiondetection.h" #include diff --git a/src/game-server/collisiondetection.h b/src/game-server/collisiondetection.h new file mode 100644 index 00000000..36a5bc24 --- /dev/null +++ b/src/game-server/collisiondetection.h @@ -0,0 +1,55 @@ +/* + * The Mana Server + * Copyright (C) 2004-2010 The Mana World Development Team + * + * This file is part of The Mana Server. + * + * The Mana Server 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 + * any later version. + * + * The Mana Server 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 The Mana Server. If not, see . + */ + +#ifndef COLLISIONDETECTION_H +#define COLLISIONDETECTION_H + +class Point; + +/** + * This namespace collects all needed collision detection functions + */ +namespace Collision +{ + + bool circleWithCirclesector(const Point &circlePos, int circleRadius, + const Point &secPos, int secRadius, + float secAngle, float secSize); + + /** + * Checks if a disk and a circle-sector collide + * + * @param halfTopAngle + * The half-top-angle of the circle sector in degrees (0,359). + * @param placeAngle + * The placement-angle of the circle sector in degrees (0,359). + */ + bool diskWithCircleSector(const Point &diskCenter, int diskRadius, + const Point §orCenter, int sectorRadius, + int halfTopAngle, int placeAngle); + + /** + * Checks if two circles intersect. + */ + bool circleWithCircle(const Point ¢er1, int radius1, + const Point ¢er2, int radius2); +} + +#endif diff --git a/src/game-server/collisiondetection.hpp b/src/game-server/collisiondetection.hpp deleted file mode 100644 index 36a5bc24..00000000 --- a/src/game-server/collisiondetection.hpp +++ /dev/null @@ -1,55 +0,0 @@ -/* - * The Mana Server - * Copyright (C) 2004-2010 The Mana World Development Team - * - * This file is part of The Mana Server. - * - * The Mana Server 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 - * any later version. - * - * The Mana Server 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 The Mana Server. If not, see . - */ - -#ifndef COLLISIONDETECTION_H -#define COLLISIONDETECTION_H - -class Point; - -/** - * This namespace collects all needed collision detection functions - */ -namespace Collision -{ - - bool circleWithCirclesector(const Point &circlePos, int circleRadius, - const Point &secPos, int secRadius, - float secAngle, float secSize); - - /** - * Checks if a disk and a circle-sector collide - * - * @param halfTopAngle - * The half-top-angle of the circle sector in degrees (0,359). - * @param placeAngle - * The placement-angle of the circle sector in degrees (0,359). - */ - bool diskWithCircleSector(const Point &diskCenter, int diskRadius, - const Point §orCenter, int sectorRadius, - int halfTopAngle, int placeAngle); - - /** - * Checks if two circles intersect. - */ - bool circleWithCircle(const Point ¢er1, int radius1, - const Point ¢er2, int radius2); -} - -#endif diff --git a/src/game-server/command.cpp b/src/game-server/command.cpp index b421c67d..d47bb889 100644 --- a/src/game-server/command.cpp +++ b/src/game-server/command.cpp @@ -20,16 +20,16 @@ #include -#include "game-server/accountconnection.hpp" -#include "game-server/character.hpp" -#include "game-server/gamehandler.hpp" -#include "game-server/inventory.hpp" -#include "game-server/item.hpp" -#include "game-server/itemmanager.hpp" -#include "game-server/mapmanager.hpp" -#include "game-server/monster.hpp" -#include "game-server/monstermanager.hpp" -#include "game-server/state.hpp" +#include "game-server/accountconnection.h" +#include "game-server/character.h" +#include "game-server/gamehandler.h" +#include "game-server/inventory.h" +#include "game-server/item.h" +#include "game-server/itemmanager.h" +#include "game-server/mapmanager.h" +#include "game-server/monster.h" +#include "game-server/monstermanager.h" +#include "game-server/state.h" template< typename T > static T proxy_cast(intptr_t v) diff --git a/src/game-server/commandhandler.cpp b/src/game-server/commandhandler.cpp index 0e6dad6b..b1d965be 100644 --- a/src/game-server/commandhandler.cpp +++ b/src/game-server/commandhandler.cpp @@ -20,23 +20,23 @@ #include -#include "game-server/commandhandler.hpp" -#include "game-server/accountconnection.hpp" -#include "game-server/character.hpp" -#include "game-server/gamehandler.hpp" -#include "game-server/inventory.hpp" -#include "game-server/item.hpp" -#include "game-server/itemmanager.hpp" -#include "game-server/mapmanager.hpp" -#include "game-server/monster.hpp" -#include "game-server/monstermanager.hpp" -#include "game-server/state.hpp" - -#include "common/configuration.hpp" -#include "common/permissionmanager.hpp" -#include "common/transaction.hpp" - -#include "utils/string.hpp" +#include "game-server/commandhandler.h" +#include "game-server/accountconnection.h" +#include "game-server/character.h" +#include "game-server/gamehandler.h" +#include "game-server/inventory.h" +#include "game-server/item.h" +#include "game-server/itemmanager.h" +#include "game-server/mapmanager.h" +#include "game-server/monster.h" +#include "game-server/monstermanager.h" +#include "game-server/state.h" + +#include "common/configuration.h" +#include "common/permissionmanager.h" +#include "common/transaction.h" + +#include "utils/string.h" struct CmdRef { diff --git a/src/game-server/commandhandler.h b/src/game-server/commandhandler.h new file mode 100644 index 00000000..5327dda7 --- /dev/null +++ b/src/game-server/commandhandler.h @@ -0,0 +1,36 @@ +/* + * The Mana Server + * Copyright (C) 2008-2010 The Mana World Development Team + * + * This file is part of The Mana Server. + * + * The Mana Server 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 + * any later version. + * + * The Mana Server 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 The Mana Server. If not, see . + */ + +#ifndef SERVER_COMMANDHANDLER_H +#define SERVER_COMMANDHANDLER_H + +#include + +class Character; + +namespace CommandHandler +{ + /** + * Parse and handle the given command. + */ + void handleCommand(Character *player, const std::string &command); +} + +#endif //SERVER_COMMANDHANDLER_H diff --git a/src/game-server/commandhandler.hpp b/src/game-server/commandhandler.hpp deleted file mode 100644 index 156cec13..00000000 --- a/src/game-server/commandhandler.hpp +++ /dev/null @@ -1,36 +0,0 @@ -/* - * The Mana Server - * Copyright (C) 2008-2010 The Mana World Development Team - * - * This file is part of The Mana Server. - * - * The Mana Server 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 - * any later version. - * - * The Mana Server 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 The Mana Server. If not, see . - */ - -#ifndef SERVER_COMMANDHANDLER_HPP -#define SERVER_COMMANDHANDLER_HPP - -#include - -class Character; - -namespace CommandHandler -{ - /** - * Parse and handle the given command. - */ - void handleCommand(Character *player, const std::string &command); -} - -#endif //SERVER_COMMANDHANDLER_H diff --git a/src/game-server/effect.cpp b/src/game-server/effect.cpp index d00ae5b2..b7c6c643 100644 --- a/src/game-server/effect.cpp +++ b/src/game-server/effect.cpp @@ -18,10 +18,10 @@ * along with The Mana Server. If not, see . */ -#include "game-server/effect.hpp" +#include "game-server/effect.h" -#include "game-server/mapcomposite.hpp" -#include "game-server/state.hpp" +#include "game-server/mapcomposite.h" +#include "game-server/state.h" void Effect::update() { diff --git a/src/game-server/effect.h b/src/game-server/effect.h new file mode 100644 index 00000000..2e22d46e --- /dev/null +++ b/src/game-server/effect.h @@ -0,0 +1,88 @@ +/* + * The Mana Server + * Copyright (C) 2004-2010 The Mana World Development Team + * + * This file is part of The Mana Server. + * + * The Mana Server 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 + * any later version. + * + * The Mana Server 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 The Mana Server. If not, see . + */ + +#ifndef EFFECT_H +#define EFFECT_H + +#include "game-server/actor.h" +#include "game-server/being.h" + +class Effect : public Actor +{ + public: + Effect(int id) + : Actor(OBJECT_EFFECT) + , mEffectId(id) + , mHasBeenShown(false) + , mBeing(NULL) + {} + + int getEffectId() const + { return mEffectId; } + + Being *getBeing() const + { return mBeing; } + + /** + * Removes effect after it has been shown. + */ + virtual void update(); + + /** + * Called when the object has been shown to a player in the state loop. + */ + void show() + { mHasBeenShown = true; } + + + bool setBeing(Being *b) + { + if (b) + { + setPosition(b->getPosition()); + mBeing = b; + return true; + } else { + return false; + } + } + + private: + int mEffectId; + bool mHasBeenShown; + Being *mBeing; +}; + + +namespace Effects +{ + /** + * Convenience methods to show an effect. + */ + void show(int id, MapComposite *map, const Point &pos); + void show(int id, MapComposite *map, Being *b); + + // TODO: get this in sync with effects.xml + enum { + FIRE_BURST = 15 + }; +} + +#endif diff --git a/src/game-server/effect.hpp b/src/game-server/effect.hpp deleted file mode 100644 index b1341ffc..00000000 --- a/src/game-server/effect.hpp +++ /dev/null @@ -1,88 +0,0 @@ -/* - * The Mana Server - * Copyright (C) 2004-2010 The Mana World Development Team - * - * This file is part of The Mana Server. - * - * The Mana Server 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 - * any later version. - * - * The Mana Server 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 The Mana Server. If not, see . - */ - -#ifndef EFFECT_H -#define EFFECT_H - -#include "game-server/actor.hpp" -#include "game-server/being.hpp" - -class Effect : public Actor -{ - public: - Effect(int id) - : Actor(OBJECT_EFFECT) - , mEffectId(id) - , mHasBeenShown(false) - , mBeing(NULL) - {} - - int getEffectId() const - { return mEffectId; } - - Being *getBeing() const - { return mBeing; } - - /** - * Removes effect after it has been shown. - */ - virtual void update(); - - /** - * Called when the object has been shown to a player in the state loop. - */ - void show() - { mHasBeenShown = true; } - - - bool setBeing(Being *b) - { - if (b) - { - setPosition(b->getPosition()); - mBeing = b; - return true; - } else { - return false; - } - } - - private: - int mEffectId; - bool mHasBeenShown; - Being *mBeing; -}; - - -namespace Effects -{ - /** - * Convenience methods to show an effect. - */ - void show(int id, MapComposite *map, const Point &pos); - void show(int id, MapComposite *map, Being *b); - - // TODO: get this in sync with effects.xml - enum { - FIRE_BURST = 15 - }; -} - -#endif diff --git a/src/game-server/eventlistener.h b/src/game-server/eventlistener.h new file mode 100644 index 00000000..87dac1dc --- /dev/null +++ b/src/game-server/eventlistener.h @@ -0,0 +1,102 @@ +/* + * The Mana Server + * Copyright (C) 2007-2010 The Mana World Development Team + * + * This file is part of The Mana Server. + * + * The Mana Server 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 + * any later version. + * + * The Mana Server 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 The Mana Server. If not, see . + */ + +#ifndef GAMESERVER_EVENTLISTENER_H +#define GAMESERVER_EVENTLISTENER_H + +class Thing; +class Being; +class Character; + +struct EventDispatch; + +/** + * Pointer to a dispatch table. + */ +struct EventListener +{ + const EventDispatch *dispatch; + EventListener(const EventDispatch *d): dispatch(d) {} +}; + +/** + * Dispatch table for event notification. + */ +struct EventDispatch +{ + /** + * Called just after something is inserted in a map. + */ + void (*inserted)(const EventListener *, Thing *); + + /** + * Called just before something is removed from a map. + */ + void (*removed)(const EventListener *, Thing *); + + /** + * Called just after a being has died. + */ + void (*died)(const EventListener *, Being *); + + /** + * Called just before a character is deleted. + */ + void (*disconnected)(const EventListener *, Character *); + + /** + * Initializes dispatch methods as missing. + */ + EventDispatch(): + inserted(0), removed(0), died(0), disconnected(0) + {} +}; + +/** + * Helper for using member functions as dispatch methods. The 3-level structure + * is due to default template parameter not being allowed on functions yet. + * Conceptually, this helper takes two parameters: the name of the member + * variable pointing to the dispatch table and the name of the member function + * to call on dispatch. With these two parameters, it creates a dispatch + * method. When called, this free function forwards the call to the member + * function. + * Pseudo-syntax for getting a dispatch method: + * &EventListenerFactory< _, DispatchPointerName >::create< _, MemberFunctionName >::function + * See the start of the spawnarea.cpp file for a complete example. + */ +template< class T, EventListener T::*D > +struct EventListenerFactory +{ + template< class U, void (T::*F)(U *), class V = U > + struct create + { + static void function(const EventListener *d, V *u) + { + /* Get the address of the T object by substracting the offset of D + from the pointer d. */ + T *t = (T *)((char *)d - + ((char *)&(((T *)42)->*D) - (char *)&(*(T *)42))); + // Then call the method F of this T object. + (t->*F)(u); + } + }; +}; + +#endif diff --git a/src/game-server/eventlistener.hpp b/src/game-server/eventlistener.hpp deleted file mode 100644 index b66021f4..00000000 --- a/src/game-server/eventlistener.hpp +++ /dev/null @@ -1,102 +0,0 @@ -/* - * The Mana Server - * Copyright (C) 2007-2010 The Mana World Development Team - * - * This file is part of The Mana Server. - * - * The Mana Server 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 - * any later version. - * - * The Mana Server 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 The Mana Server. If not, see . - */ - -#ifndef GAMESERVER_EVENTLISTENER_HPP -#define GAMESERVER_EVENTLISTENER_HPP - -class Thing; -class Being; -class Character; - -struct EventDispatch; - -/** - * Pointer to a dispatch table. - */ -struct EventListener -{ - const EventDispatch *dispatch; - EventListener(const EventDispatch *d): dispatch(d) {} -}; - -/** - * Dispatch table for event notification. - */ -struct EventDispatch -{ - /** - * Called just after something is inserted in a map. - */ - void (*inserted)(const EventListener *, Thing *); - - /** - * Called just before something is removed from a map. - */ - void (*removed)(const EventListener *, Thing *); - - /** - * Called just after a being has died. - */ - void (*died)(const EventListener *, Being *); - - /** - * Called just before a character is deleted. - */ - void (*disconnected)(const EventListener *, Character *); - - /** - * Initializes dispatch methods as missing. - */ - EventDispatch(): - inserted(0), removed(0), died(0), disconnected(0) - {} -}; - -/** - * Helper for using member functions as dispatch methods. The 3-level structure - * is due to default template parameter not being allowed on functions yet. - * Conceptually, this helper takes two parameters: the name of the member - * variable pointing to the dispatch table and the name of the member function - * to call on dispatch. With these two parameters, it creates a dispatch - * method. When called, this free function forwards the call to the member - * function. - * Pseudo-syntax for getting a dispatch method: - * &EventListenerFactory< _, DispatchPointerName >::create< _, MemberFunctionName >::function - * See the start of the spawnarea.cpp file for a complete example. - */ -template< class T, EventListener T::*D > -struct EventListenerFactory -{ - template< class U, void (T::*F)(U *), class V = U > - struct create - { - static void function(const EventListener *d, V *u) - { - /* Get the address of the T object by substracting the offset of D - from the pointer d. */ - T *t = (T *)((char *)d - - ((char *)&(((T *)42)->*D) - (char *)&(*(T *)42))); - // Then call the method F of this T object. - (t->*F)(u); - } - }; -}; - -#endif diff --git a/src/game-server/gamehandler.cpp b/src/game-server/gamehandler.cpp index 5c7ba34e..f761abca 100644 --- a/src/game-server/gamehandler.cpp +++ b/src/game-server/gamehandler.cpp @@ -21,26 +21,26 @@ #include #include -#include "game-server/gamehandler.hpp" - -#include "common/transaction.hpp" -#include "game-server/accountconnection.hpp" -#include "game-server/buysell.hpp" -#include "game-server/commandhandler.hpp" -#include "game-server/inventory.hpp" -#include "game-server/item.hpp" -#include "game-server/itemmanager.hpp" -#include "game-server/map.hpp" -#include "game-server/mapcomposite.hpp" -#include "game-server/npc.hpp" -#include "game-server/postman.hpp" -#include "game-server/state.hpp" -#include "game-server/trade.hpp" -#include "net/messagein.hpp" -#include "net/messageout.hpp" -#include "net/netcomputer.hpp" +#include "game-server/gamehandler.h" + +#include "common/transaction.h" +#include "game-server/accountconnection.h" +#include "game-server/buysell.h" +#include "game-server/commandhandler.h" +#include "game-server/inventory.h" +#include "game-server/item.h" +#include "game-server/itemmanager.h" +#include "game-server/map.h" +#include "game-server/mapcomposite.h" +#include "game-server/npc.h" +#include "game-server/postman.h" +#include "game-server/state.h" +#include "game-server/trade.h" +#include "net/messagein.h" +#include "net/messageout.h" +#include "net/netcomputer.h" #include "utils/logger.h" -#include "utils/tokendispenser.hpp" +#include "utils/tokendispenser.h" const unsigned int TILES_TO_BE_NEAR = 7; @@ -135,7 +135,7 @@ static Actor *findActorNear(Actor *p, int id) { MapComposite *map = p->getMap(); const Point &ppos = p->getPosition(); - // See map.hpp for tiles constants + // See map.h for tiles constants const int pixelDist = DEFAULT_TILE_WIDTH * TILES_TO_BE_NEAR; for (ActorIterator i(map->getAroundPointIterator(ppos, pixelDist)); i; ++i) { @@ -151,7 +151,7 @@ static Character *findCharacterNear(Actor *p, int id) { MapComposite *map = p->getMap(); const Point &ppos = p->getPosition(); - // See map.hpp for tiles constants + // See map.h for tiles constants const int pixelDist = DEFAULT_TILE_WIDTH * TILES_TO_BE_NEAR; for (CharacterIterator i(map->getAroundPointIterator(ppos, pixelDist)); i; ++i) diff --git a/src/game-server/gamehandler.h b/src/game-server/gamehandler.h new file mode 100644 index 00000000..5a2630dc --- /dev/null +++ b/src/game-server/gamehandler.h @@ -0,0 +1,157 @@ +/* + * The Mana Server + * Copyright (C) 2004-2010 The Mana World Development Team + * + * This file is part of The Mana Server. + * + * The Mana Server 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 + * any later version. + * + * The Mana Server 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 The Mana Server. If not, see . + */ + +#ifndef SERVER_GAMEHANDLER_H +#define SERVER_GAMEHANDLER_H + +#include "game-server/character.h" +#include "net/connectionhandler.h" +#include "net/netcomputer.h" +#include "utils/tokencollector.h" + +enum +{ + CLIENT_LOGIN = 0, + CLIENT_CONNECTED, + CLIENT_CHANGE_SERVER, + CLIENT_QUEUED +}; + +struct GameClient: NetComputer +{ + GameClient(ENetPeer *peer) + : NetComputer(peer), character(NULL), status(CLIENT_LOGIN) {} + Character *character; + int status; +}; + +/** + * Manages connections to game client. + */ +class GameHandler: public ConnectionHandler +{ + public: + /** + * Constructor + */ + GameHandler(); + + /** + * Starts the handler + */ + bool startListen(enet_uint16 port); + + /** + * Sends message to the given character. + */ + void sendTo(Character *, MessageOut &msg); + + /** + * Kills connection with given character. + */ + void kill(Character *); + + /** + * Prepares a server change for given character. + */ + void prepareServerChange(Character *); + + /** + * Completes a server change for given character ID. + */ + void completeServerChange(int id, const std::string &token, + const std::string &address, int port); + + /** + * Updates the party id of the character + */ + void updateCharacter(int charid, int partyid); + + /** + * Registers a character that should soon be claimed by a client. + * @param token token used by the client when connecting. + */ + void addPendingCharacter(const std::string &token, Character *); + + /** + * Combines a client with its character. + * (Needed for TokenCollector) + */ + void tokenMatched(GameClient *computer, Character *character); + + /** + * Deletes a pending client's data. + * (Needed for TokenCollector) + */ + void deletePendingClient(GameClient *computer); + + /** + * Deletes a pending connection's data. + * (Needed for TokenCollector) + */ + void deletePendingConnect(Character *character); + + /** + * Gets the client associated to a character name. This method is slow, + * so it should never be called for regular operations. + */ + GameClient *getClientByNameSlow(const std::string &) const; + + protected: + NetComputer *computerConnected(ENetPeer *); + void computerDisconnected(NetComputer *); + + /** + * Send error message back to player + */ + void sendError(NetComputer *computer, int id, std::string errorMsg); + + /** + * Processes messages related to core game events. + */ + void processMessage(NetComputer *computer, MessageIn &message); + + /** + * Set the position a player wants to move to + */ + void handleWalk(GameClient *client, MessageIn &message); + + /** + * Send a letter + */ + void handleSendPost(GameClient *client, MessageIn &message); + + /** + * Retrieve a letter + */ + void handleGetPost(GameClient *client, MessageIn &message); + + private: + + /** + * Container for pending clients and pending connections. + */ + TokenCollector mTokenCollector; + +}; + +extern GameHandler *gameHandler; + +#endif diff --git a/src/game-server/gamehandler.hpp b/src/game-server/gamehandler.hpp deleted file mode 100644 index 00e29122..00000000 --- a/src/game-server/gamehandler.hpp +++ /dev/null @@ -1,157 +0,0 @@ -/* - * The Mana Server - * Copyright (C) 2004-2010 The Mana World Development Team - * - * This file is part of The Mana Server. - * - * The Mana Server 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 - * any later version. - * - * The Mana Server 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 The Mana Server. If not, see . - */ - -#ifndef SERVER_GAMEHANDLER_HPP -#define SERVER_GAMEHANDLER_HPP - -#include "game-server/character.hpp" -#include "net/connectionhandler.hpp" -#include "net/netcomputer.hpp" -#include "utils/tokencollector.hpp" - -enum -{ - CLIENT_LOGIN = 0, - CLIENT_CONNECTED, - CLIENT_CHANGE_SERVER, - CLIENT_QUEUED -}; - -struct GameClient: NetComputer -{ - GameClient(ENetPeer *peer) - : NetComputer(peer), character(NULL), status(CLIENT_LOGIN) {} - Character *character; - int status; -}; - -/** - * Manages connections to game client. - */ -class GameHandler: public ConnectionHandler -{ - public: - /** - * Constructor - */ - GameHandler(); - - /** - * Starts the handler - */ - bool startListen(enet_uint16 port); - - /** - * Sends message to the given character. - */ - void sendTo(Character *, MessageOut &msg); - - /** - * Kills connection with given character. - */ - void kill(Character *); - - /** - * Prepares a server change for given character. - */ - void prepareServerChange(Character *); - - /** - * Completes a server change for given character ID. - */ - void completeServerChange(int id, const std::string &token, - const std::string &address, int port); - - /** - * Updates the party id of the character - */ - void updateCharacter(int charid, int partyid); - - /** - * Registers a character that should soon be claimed by a client. - * @param token token used by the client when connecting. - */ - void addPendingCharacter(const std::string &token, Character *); - - /** - * Combines a client with its character. - * (Needed for TokenCollector) - */ - void tokenMatched(GameClient *computer, Character *character); - - /** - * Deletes a pending client's data. - * (Needed for TokenCollector) - */ - void deletePendingClient(GameClient *computer); - - /** - * Deletes a pending connection's data. - * (Needed for TokenCollector) - */ - void deletePendingConnect(Character *character); - - /** - * Gets the client associated to a character name. This method is slow, - * so it should never be called for regular operations. - */ - GameClient *getClientByNameSlow(const std::string &) const; - - protected: - NetComputer *computerConnected(ENetPeer *); - void computerDisconnected(NetComputer *); - - /** - * Send error message back to player - */ - void sendError(NetComputer *computer, int id, std::string errorMsg); - - /** - * Processes messages related to core game events. - */ - void processMessage(NetComputer *computer, MessageIn &message); - - /** - * Set the position a player wants to move to - */ - void handleWalk(GameClient *client, MessageIn &message); - - /** - * Send a letter - */ - void handleSendPost(GameClient *client, MessageIn &message); - - /** - * Retrieve a letter - */ - void handleGetPost(GameClient *client, MessageIn &message); - - private: - - /** - * Container for pending clients and pending connections. - */ - TokenCollector mTokenCollector; - -}; - -extern GameHandler *gameHandler; - -#endif diff --git a/src/game-server/inventory.cpp b/src/game-server/inventory.cpp index b29f08de..b74c727b 100644 --- a/src/game-server/inventory.cpp +++ b/src/game-server/inventory.cpp @@ -21,11 +21,11 @@ #include #include -#include "game-server/gamehandler.hpp" -#include "game-server/inventory.hpp" -#include "game-server/item.hpp" -#include "game-server/itemmanager.hpp" -#include "net/messageout.hpp" +#include "game-server/gamehandler.h" +#include "game-server/inventory.h" +#include "game-server/item.h" +#include "game-server/itemmanager.h" +#include "net/messageout.h" #include "utils/logger.h" // TODO: diff --git a/src/game-server/inventory.h b/src/game-server/inventory.h new file mode 100644 index 00000000..bd9da5c3 --- /dev/null +++ b/src/game-server/inventory.h @@ -0,0 +1,210 @@ +/* + * The Mana Server + * Copyright (C) 2004-2010 The Mana World Development Team + * + * This file is part of The Mana Server. + * + * The Mana Server 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 + * any later version. + * + * The Mana Server 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 The Mana Server. If not, see . + */ + +#ifndef INVENTORY_H +#define INVENTORY_H + +#include "game-server/character.h" +#include "net/messageout.h" + +/*enum +{ +// Equipment rules: +// 1 torso equipment + EQUIP_TORSO_SLOT = 0, +// 1 arms equipment + EQUIP_ARMS_SLOT = 1, +// 1 head equipment + EQUIP_HEAD_SLOT = 2, +// 1 legs equipment + EQUIP_LEGS_SLOT = 3, +// 1 feet equipment + EQUIP_FEET_SLOT = 4, +// 2 rings + EQUIP_RING1_SLOT = 5, + EQUIP_RING2_SLOT = 6, +// 1 necklace + EQUIP_NECKLACE_SLOT = 7, +// Fight: +// 2 one-handed weapons +// or 1 two-handed weapon +// or 1 one-handed weapon + 1 shield. + EQUIP_FIGHT1_SLOT = 8, + EQUIP_FIGHT2_SLOT = 9, +// Projectile: +// this item does not amount to one, it only indicates the chosen projectile. + EQUIP_PROJECTILE_SLOT = 10, + + EQUIP_CLIENT_INVENTORY = 32 +};*/ + +class ItemClass; + +/** + * Class used to handle Character possessions and prepare outgoing messages. + */ +class Inventory +{ + public: + + /** + * Creates a view on the possessions of a character. + * @param delayed If the changes need to be cancelable. + */ + Inventory(Character *, bool delayed = false); + + /** + * Commits delayed changes if applicable. + * Sends the update message to the client. + */ + ~Inventory(); + + /** + * Commits changes. + * Exclusive to delayed mode. + * @param doRestart Whether to prepare the inventory for more changes + after this. If you are unsure, it is safe (though not + terribly efficient) to leave this as true. + */ + void commit(bool doRestart = true); + + /** + * Cancels changes. + * Exclusive to delayed mode. + */ + void cancel(); + + /** + * Sends complete inventory status to the client. + */ + void sendFull() const; + + /** + * Ensures the inventory is sane and apply equipment modifiers. + * Should be run only once and the very first time. + */ + void initialise(); + + /** + * Equips item from given inventory slot. + * @param slot The slot in which the target item is in. + * @param override Whether this item can unequip other items to equip + * itself. If true, items that are unequipped will be + * attempted to be reequipped, but with override disabled. + * @returns whether the item could be equipped. + */ + bool equip(int slot, bool override = true); + + /** + * Unequips item from given equipment slot. + * @param it Starting iterator. When the only parameter, also extracts + * slot number from it. + * Used so that when we already have an iterator to the first + * occurence from a previous operation we can start from + * there. + * @returns Whether it was unequipped. + */ + bool unequip(EquipData::iterator it); + bool unequip(unsigned int slot, EquipData::iterator *itp = 0); + + /** + * Inserts some items into the inventory. + * @return number of items not inserted (to be dropped on floor?). + */ + unsigned int insert(unsigned int itemId, unsigned int amount); + + /** + * Removes some items from inventory. + * @param force If set to true, also remove any equipment encountered + * @return number of items not removed. + */ + unsigned int remove(unsigned int itemId, unsigned int amount, bool force = false); + + /** + * Moves some items from the first slot to the second one. + * @returns number of items not moved. + */ + unsigned int move(unsigned int slot1, unsigned int slot2, unsigned int amount); + + /** + * Removes some items from inventory. + * @return number of items not removed. + */ + unsigned int removeFromSlot(unsigned int slot, unsigned int amount); + + /** + * Counts number of items with given ID. + */ + unsigned int count(unsigned int itemId) const; + + /** + * Gets the ID of the items in a given slot. + */ + unsigned int getItem(unsigned int slot) const; + + private: + + /** + * Make sure that changes are being done on a copy, not directly. + * No effect when not in delayed mode. + */ + void prepare(); + + /** + * Starts a new notification message. + */ + void restart(); + + + /** + * Check the inventory is within the slot limit and capacity. + * Forcibly delete items from the end if it is not. + * @todo Drop items instead? + */ + void checkSize(); + + /** + * Helper function for equip() when computing changes to equipment + * When newCount is 0, the item is being unequipped. + */ + // inventory slot -> {equip slots} + typedef std::multimap IdSlotMap; + void equip_sub(unsigned int newCount, IdSlotMap::const_iterator &it); + + /** + * Changes equipment and adjusts character attributes. + */ + void changeEquipment(unsigned int oldId, unsigned int itemId); + void changeEquipment(ItemClass *oldI, ItemClass *newI); + + Possessions *mPoss; /**< Pointer to the modified possessions. */ + /** + * Update message containing inventory changes. + * Note that in sendFull(), this is reused to send all full changes + * (for both inventory and equipment) + */ + MessageOut mInvMsg; + MessageOut mEqmMsg; /**< Update message containing equipment changes */ + Character *mClient; /**< Character to notify. */ + bool mDelayed; /**< Delayed changes. */ +}; + + +#endif diff --git a/src/game-server/inventory.hpp b/src/game-server/inventory.hpp deleted file mode 100644 index f2168c2b..00000000 --- a/src/game-server/inventory.hpp +++ /dev/null @@ -1,210 +0,0 @@ -/* - * The Mana Server - * Copyright (C) 2004-2010 The Mana World Development Team - * - * This file is part of The Mana Server. - * - * The Mana Server 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 - * any later version. - * - * The Mana Server 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 The Mana Server. If not, see . - */ - -#ifndef INVENTORY_H -#define INVENTORY_H - -#include "game-server/character.hpp" -#include "net/messageout.hpp" - -/*enum -{ -// Equipment rules: -// 1 torso equipment - EQUIP_TORSO_SLOT = 0, -// 1 arms equipment - EQUIP_ARMS_SLOT = 1, -// 1 head equipment - EQUIP_HEAD_SLOT = 2, -// 1 legs equipment - EQUIP_LEGS_SLOT = 3, -// 1 feet equipment - EQUIP_FEET_SLOT = 4, -// 2 rings - EQUIP_RING1_SLOT = 5, - EQUIP_RING2_SLOT = 6, -// 1 necklace - EQUIP_NECKLACE_SLOT = 7, -// Fight: -// 2 one-handed weapons -// or 1 two-handed weapon -// or 1 one-handed weapon + 1 shield. - EQUIP_FIGHT1_SLOT = 8, - EQUIP_FIGHT2_SLOT = 9, -// Projectile: -// this item does not amount to one, it only indicates the chosen projectile. - EQUIP_PROJECTILE_SLOT = 10, - - EQUIP_CLIENT_INVENTORY = 32 -};*/ - -class ItemClass; - -/** - * Class used to handle Character possessions and prepare outgoing messages. - */ -class Inventory -{ - public: - - /** - * Creates a view on the possessions of a character. - * @param delayed If the changes need to be cancelable. - */ - Inventory(Character *, bool delayed = false); - - /** - * Commits delayed changes if applicable. - * Sends the update message to the client. - */ - ~Inventory(); - - /** - * Commits changes. - * Exclusive to delayed mode. - * @param doRestart Whether to prepare the inventory for more changes - after this. If you are unsure, it is safe (though not - terribly efficient) to leave this as true. - */ - void commit(bool doRestart = true); - - /** - * Cancels changes. - * Exclusive to delayed mode. - */ - void cancel(); - - /** - * Sends complete inventory status to the client. - */ - void sendFull() const; - - /** - * Ensures the inventory is sane and apply equipment modifiers. - * Should be run only once and the very first time. - */ - void initialise(); - - /** - * Equips item from given inventory slot. - * @param slot The slot in which the target item is in. - * @param override Whether this item can unequip other items to equip - * itself. If true, items that are unequipped will be - * attempted to be reequipped, but with override disabled. - * @returns whether the item could be equipped. - */ - bool equip(int slot, bool override = true); - - /** - * Unequips item from given equipment slot. - * @param it Starting iterator. When the only parameter, also extracts - * slot number from it. - * Used so that when we already have an iterator to the first - * occurence from a previous operation we can start from - * there. - * @returns Whether it was unequipped. - */ - bool unequip(EquipData::iterator it); - bool unequip(unsigned int slot, EquipData::iterator *itp = 0); - - /** - * Inserts some items into the inventory. - * @return number of items not inserted (to be dropped on floor?). - */ - unsigned int insert(unsigned int itemId, unsigned int amount); - - /** - * Removes some items from inventory. - * @param force If set to true, also remove any equipment encountered - * @return number of items not removed. - */ - unsigned int remove(unsigned int itemId, unsigned int amount, bool force = false); - - /** - * Moves some items from the first slot to the second one. - * @returns number of items not moved. - */ - unsigned int move(unsigned int slot1, unsigned int slot2, unsigned int amount); - - /** - * Removes some items from inventory. - * @return number of items not removed. - */ - unsigned int removeFromSlot(unsigned int slot, unsigned int amount); - - /** - * Counts number of items with given ID. - */ - unsigned int count(unsigned int itemId) const; - - /** - * Gets the ID of the items in a given slot. - */ - unsigned int getItem(unsigned int slot) const; - - private: - - /** - * Make sure that changes are being done on a copy, not directly. - * No effect when not in delayed mode. - */ - void prepare(); - - /** - * Starts a new notification message. - */ - void restart(); - - - /** - * Check the inventory is within the slot limit and capacity. - * Forcibly delete items from the end if it is not. - * @todo Drop items instead? - */ - void checkSize(); - - /** - * Helper function for equip() when computing changes to equipment - * When newCount is 0, the item is being unequipped. - */ - // inventory slot -> {equip slots} - typedef std::multimap IdSlotMap; - void equip_sub(unsigned int newCount, IdSlotMap::const_iterator &it); - - /** - * Changes equipment and adjusts character attributes. - */ - void changeEquipment(unsigned int oldId, unsigned int itemId); - void changeEquipment(ItemClass *oldI, ItemClass *newI); - - Possessions *mPoss; /**< Pointer to the modified possessions. */ - /** - * Update message containing inventory changes. - * Note that in sendFull(), this is reused to send all full changes - * (for both inventory and equipment) - */ - MessageOut mInvMsg; - MessageOut mEqmMsg; /**< Update message containing equipment changes */ - Character *mClient; /**< Character to notify. */ - bool mDelayed; /**< Delayed changes. */ -}; - - -#endif diff --git a/src/game-server/item.cpp b/src/game-server/item.cpp index a2b481d5..02c6a513 100644 --- a/src/game-server/item.cpp +++ b/src/game-server/item.cpp @@ -22,14 +22,14 @@ #include #include -#include "game-server/item.hpp" - -#include "common/configuration.hpp" -#include "game-server/autoattack.hpp" -#include "game-server/attributemanager.hpp" -#include "game-server/being.hpp" -#include "game-server/state.hpp" -#include "scripting/script.hpp" +#include "game-server/item.h" + +#include "common/configuration.h" +#include "game-server/autoattack.h" +#include "game-server/attributemanager.h" +#include "game-server/being.h" +#include "game-server/state.h" +#include "scripting/script.h" bool ItemEffectInfo::apply(Being *itemUser) { diff --git a/src/game-server/item.h b/src/game-server/item.h new file mode 100644 index 00000000..215b738f --- /dev/null +++ b/src/game-server/item.h @@ -0,0 +1,273 @@ +/* + * The Mana Server + * Copyright (C) 2004-2010 The Mana World Development Team + * + * This file is part of The Mana Server. + * + * The Mana Server 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 + * any later version. + * + * The Mana Server 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 The Mana Server. If not, see . + */ + +#ifndef ITEM_H +#define ITEM_H + +#include + +#include "game-server/actor.h" + +class Being; + +typedef std::list< std::pair< unsigned int, unsigned int> > ItemEquipInfo; +typedef std::list< ItemEquipInfo > ItemEquipsInfo; + +/** + * State effects to beings, and actors. + * States can be multiple for the same being. + */ +enum +{ + SET_STATE_NORMAL = 0, + SET_STATE_POISONED, + SET_STATE_STONED, + SET_STATE_STUNNED, + SET_STATE_SLOWED, + SET_STATE_TIRED, + SET_STATE_MAD, + SET_STATE_BERSERK, + SET_STATE_HASTED, + SET_STATE_FLOATING, + + SET_STATE_NOT_POISONED, + SET_STATE_NOT_STONED, + SET_STATE_NOT_STUNNED, + SET_STATE_NOT_SLOWED, + SET_STATE_NOT_TIRED, + SET_STATE_NOT_MAD, + SET_STATE_NOT_BERSERK, + SET_STATE_NOT_HASTED, + SET_STATE_NOT_FLOATING +}; + +struct ItemAutoAttackInfo { + unsigned int base; + unsigned int range; + unsigned int baseSpeed; + unsigned int skillId; + /// attribute id -> damage bonus per point + std::map< unsigned int, double > attrBonus; +}; + +enum ItemTriggerType { + ITT_NULL = 0, + ITT_IN_INVY, // Associated effects apply when the item is in the inventory + ITT_ACTIVATE, // Associated effects apply when the item is activated + ITT_EQUIP, // Assosciated effects apply when the item is equipped + ITT_LEAVE_INVY, // Associated effects apply when the item leaves the inventory + ITT_UNEQUIP, // Associated effects apply when the item is unequipped + ITT_EQUIPCHG // When the item is still equipped, but in a different way +}; + +enum ItemEffectType { + // Effects that are removed automatically when the trigger ends + // (ie. item no longer exists in invy, unequipped) + IET_ATTR_MOD = 0, // Modify a given attribute with a given value + IET_AUTOATTACK, // Give the associated being an autoattack + // Effects that do not need any automatic removal + IET_COOLDOWN, // Set a cooldown to this item, preventing activation for n ticks + IET_G_COOLDOWN, // Set a cooldown to all items of this type for this being + IET_SCRIPT // Call an associated lua script with given variables +}; + +class ItemEffectInfo +{ + public: + virtual bool apply(Being *itemUser); + virtual void dispell(Being *itemUser) {} +}; + +class ItemEffectAttrMod : public ItemEffectInfo +{ + public: + ItemEffectAttrMod(unsigned int attrId, unsigned int layer, double value, + unsigned int id, unsigned int duration = 0) : + mAttributeId(attrId), mAttributeLayer(layer), + mMod(value), mDuration(duration), mId(id) {} + + bool apply(Being *itemUser); + void dispell(Being *itemUser); + + private: + unsigned int mAttributeId; + unsigned int mAttributeLayer; + double mMod; + unsigned int mDuration; + unsigned int mId; +}; + +class ItemEffectAutoAttack : public ItemEffectInfo +{ + public: + bool apply(Being *itemUser); + void dispell(Being *itemUser); +}; + +class ItemEffectConsumes : public ItemEffectInfo +{ + public: + bool apply(Being *itemUser) { return true; } + void dispell(Being *itemUser) {} +}; + +class ItemEffectScript : public ItemEffectInfo +{ + public: + bool apply(Being *itemUser); + void dispell(Being *itemUser); +}; + + +/** + * Class for simple reference to item information. + */ +class ItemClass +{ + public: + ItemClass(int id, unsigned int maxperslot) + : mDatabaseID(id) + , mSpriteID(0) + , mCost(0) + , mMaxPerSlot(maxperslot) + {} + + ~ItemClass() { resetEffects(); } + + /** + * Applies the modifiers of an item to a given user. + * @return true if item should be removed. + */ + bool useTrigger(Being *itemUser, ItemTriggerType trigger); + + /** + * Gets unit cost of these items. + */ + int getCost() const + { return mCost; } + + /** + * Gets max item per slot. + */ + unsigned int getMaxPerSlot() const + { return mMaxPerSlot; } + + bool hasTrigger(ItemTriggerType id) + { return mEffects.count(id); } + + /** + * Gets database ID. + */ + int getDatabaseID() const + { return mDatabaseID; } + + /** + * Gets the sprite ID. + * @note At present this is only a stub, and will always return zero. + * When you would want to extend serializeLooks to be more + * efficient, keep track of a sprite id here. + */ + int getSpriteID() const + { return mSpriteID; } + + /** + * Returns equip requirements. + */ + const ItemEquipsInfo &getItemEquipData() const { return mEquip; } + + + private: + + /** + * Add an effect to a trigger + * @param effect The effect to be run when the trigger is hit. + * @param id The trigger type. + * @param dispell The trigger that the effect should be dispelled on. + * @note FIXME: Should be more than one trigger that an effect + * can be dispelled from. + */ + void addEffect(ItemEffectInfo *effect, + ItemTriggerType id, + ItemTriggerType dispell = ITT_NULL) + { + mEffects.insert(std::make_pair(id, effect)); + if (dispell) + mDispells.insert(std::make_pair(dispell, effect)); + } + + void resetEffects() + { + while (mEffects.begin() != mEffects.end()) + { + delete mEffects.begin()->second; + mEffects.erase(mEffects.begin()); + } + while (mDispells.begin() != mDispells.end()) + { + delete mDispells.begin()->second; + mDispells.erase(mDispells.begin()); + } + } + + unsigned short mDatabaseID; /**< Item reference information */ + /** The sprite that should be shown to the character */ + unsigned short mSpriteID; + unsigned short mCost; /**< Unit cost the item. */ + /** Max item amount per slot in inventory. */ + unsigned int mMaxPerSlot; + + std::multimap< ItemTriggerType, ItemEffectInfo * > mEffects; + std::multimap< ItemTriggerType, ItemEffectInfo * > mDispells; + + /** + * List of list of requirements for equipping. Only one inner list + * need be satisfied to sucessfully equip. Checks occur in order + * from outer front to back. + * All conditions in an inner list must be met for success. + */ + ItemEquipsInfo mEquip; + + friend class ItemManager; +}; + +/** +* Class for an item stack laying on the floor in the game world +*/ + +class Item : public Actor +{ + public: + Item(ItemClass *type, int amount); + + ItemClass *getItemClass() const + { return mType; } + + int getAmount() const + { return mAmount; } + + virtual void update(); + + private: + ItemClass *mType; + unsigned char mAmount; + int mLifetime; +}; + +#endif diff --git a/src/game-server/item.hpp b/src/game-server/item.hpp deleted file mode 100644 index 2c3f9224..00000000 --- a/src/game-server/item.hpp +++ /dev/null @@ -1,273 +0,0 @@ -/* - * The Mana Server - * Copyright (C) 2004-2010 The Mana World Development Team - * - * This file is part of The Mana Server. - * - * The Mana Server 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 - * any later version. - * - * The Mana Server 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 The Mana Server. If not, see . - */ - -#ifndef ITEM_HPP -#define ITEM_HPP - -#include - -#include "game-server/actor.hpp" - -class Being; - -typedef std::list< std::pair< unsigned int, unsigned int> > ItemEquipInfo; -typedef std::list< ItemEquipInfo > ItemEquipsInfo; - -/** - * State effects to beings, and actors. - * States can be multiple for the same being. - */ -enum -{ - SET_STATE_NORMAL = 0, - SET_STATE_POISONED, - SET_STATE_STONED, - SET_STATE_STUNNED, - SET_STATE_SLOWED, - SET_STATE_TIRED, - SET_STATE_MAD, - SET_STATE_BERSERK, - SET_STATE_HASTED, - SET_STATE_FLOATING, - - SET_STATE_NOT_POISONED, - SET_STATE_NOT_STONED, - SET_STATE_NOT_STUNNED, - SET_STATE_NOT_SLOWED, - SET_STATE_NOT_TIRED, - SET_STATE_NOT_MAD, - SET_STATE_NOT_BERSERK, - SET_STATE_NOT_HASTED, - SET_STATE_NOT_FLOATING -}; - -struct ItemAutoAttackInfo { - unsigned int base; - unsigned int range; - unsigned int baseSpeed; - unsigned int skillId; - /// attribute id -> damage bonus per point - std::map< unsigned int, double > attrBonus; -}; - -enum ItemTriggerType { - ITT_NULL = 0, - ITT_IN_INVY, // Associated effects apply when the item is in the inventory - ITT_ACTIVATE, // Associated effects apply when the item is activated - ITT_EQUIP, // Assosciated effects apply when the item is equipped - ITT_LEAVE_INVY, // Associated effects apply when the item leaves the inventory - ITT_UNEQUIP, // Associated effects apply when the item is unequipped - ITT_EQUIPCHG // When the item is still equipped, but in a different way -}; - -enum ItemEffectType { - // Effects that are removed automatically when the trigger ends - // (ie. item no longer exists in invy, unequipped) - IET_ATTR_MOD = 0, // Modify a given attribute with a given value - IET_AUTOATTACK, // Give the associated being an autoattack - // Effects that do not need any automatic removal - IET_COOLDOWN, // Set a cooldown to this item, preventing activation for n ticks - IET_G_COOLDOWN, // Set a cooldown to all items of this type for this being - IET_SCRIPT // Call an associated lua script with given variables -}; - -class ItemEffectInfo -{ - public: - virtual bool apply(Being *itemUser); - virtual void dispell(Being *itemUser) {} -}; - -class ItemEffectAttrMod : public ItemEffectInfo -{ - public: - ItemEffectAttrMod(unsigned int attrId, unsigned int layer, double value, - unsigned int id, unsigned int duration = 0) : - mAttributeId(attrId), mAttributeLayer(layer), - mMod(value), mDuration(duration), mId(id) {} - - bool apply(Being *itemUser); - void dispell(Being *itemUser); - - private: - unsigned int mAttributeId; - unsigned int mAttributeLayer; - double mMod; - unsigned int mDuration; - unsigned int mId; -}; - -class ItemEffectAutoAttack : public ItemEffectInfo -{ - public: - bool apply(Being *itemUser); - void dispell(Being *itemUser); -}; - -class ItemEffectConsumes : public ItemEffectInfo -{ - public: - bool apply(Being *itemUser) { return true; } - void dispell(Being *itemUser) {} -}; - -class ItemEffectScript : public ItemEffectInfo -{ - public: - bool apply(Being *itemUser); - void dispell(Being *itemUser); -}; - - -/** - * Class for simple reference to item information. - */ -class ItemClass -{ - public: - ItemClass(int id, unsigned int maxperslot) - : mDatabaseID(id) - , mSpriteID(0) - , mCost(0) - , mMaxPerSlot(maxperslot) - {} - - ~ItemClass() { resetEffects(); } - - /** - * Applies the modifiers of an item to a given user. - * @return true if item should be removed. - */ - bool useTrigger(Being *itemUser, ItemTriggerType trigger); - - /** - * Gets unit cost of these items. - */ - int getCost() const - { return mCost; } - - /** - * Gets max item per slot. - */ - unsigned int getMaxPerSlot() const - { return mMaxPerSlot; } - - bool hasTrigger(ItemTriggerType id) - { return mEffects.count(id); } - - /** - * Gets database ID. - */ - int getDatabaseID() const - { return mDatabaseID; } - - /** - * Gets the sprite ID. - * @note At present this is only a stub, and will always return zero. - * When you would want to extend serializeLooks to be more - * efficient, keep track of a sprite id here. - */ - int getSpriteID() const - { return mSpriteID; } - - /** - * Returns equip requirements. - */ - const ItemEquipsInfo &getItemEquipData() const { return mEquip; } - - - private: - - /** - * Add an effect to a trigger - * @param effect The effect to be run when the trigger is hit. - * @param id The trigger type. - * @param dispell The trigger that the effect should be dispelled on. - * @note FIXME: Should be more than one trigger that an effect - * can be dispelled from. - */ - void addEffect(ItemEffectInfo *effect, - ItemTriggerType id, - ItemTriggerType dispell = ITT_NULL) - { - mEffects.insert(std::make_pair(id, effect)); - if (dispell) - mDispells.insert(std::make_pair(dispell, effect)); - } - - void resetEffects() - { - while (mEffects.begin() != mEffects.end()) - { - delete mEffects.begin()->second; - mEffects.erase(mEffects.begin()); - } - while (mDispells.begin() != mDispells.end()) - { - delete mDispells.begin()->second; - mDispells.erase(mDispells.begin()); - } - } - - unsigned short mDatabaseID; /**< Item reference information */ - /** The sprite that should be shown to the character */ - unsigned short mSpriteID; - unsigned short mCost; /**< Unit cost the item. */ - /** Max item amount per slot in inventory. */ - unsigned int mMaxPerSlot; - - std::multimap< ItemTriggerType, ItemEffectInfo * > mEffects; - std::multimap< ItemTriggerType, ItemEffectInfo * > mDispells; - - /** - * List of list of requirements for equipping. Only one inner list - * need be satisfied to sucessfully equip. Checks occur in order - * from outer front to back. - * All conditions in an inner list must be met for success. - */ - ItemEquipsInfo mEquip; - - friend class ItemManager; -}; - -/** -* Class for an item stack laying on the floor in the game world -*/ - -class Item : public Actor -{ - public: - Item(ItemClass *type, int amount); - - ItemClass *getItemClass() const - { return mType; } - - int getAmount() const - { return mAmount; } - - virtual void update(); - - private: - ItemClass *mType; - unsigned char mAmount; - int mLifetime; -}; - -#endif diff --git a/src/game-server/itemmanager.cpp b/src/game-server/itemmanager.cpp index 34a6170a..72f8acfe 100644 --- a/src/game-server/itemmanager.cpp +++ b/src/game-server/itemmanager.cpp @@ -18,16 +18,16 @@ * along with The Mana Server. If not, see . */ -#include "game-server/itemmanager.hpp" +#include "game-server/itemmanager.h" #include "defines.h" -#include "common/resourcemanager.hpp" -#include "game-server/attributemanager.hpp" -#include "game-server/item.hpp" -#include "game-server/skillmanager.hpp" -#include "scripting/script.hpp" +#include "common/resourcemanager.h" +#include "game-server/attributemanager.h" +#include "game-server/item.h" +#include "game-server/skillmanager.h" +#include "scripting/script.h" #include "utils/logger.h" -#include "utils/xml.hpp" +#include "utils/xml.h" #include #include diff --git a/src/game-server/itemmanager.h b/src/game-server/itemmanager.h new file mode 100644 index 00000000..ea0641c7 --- /dev/null +++ b/src/game-server/itemmanager.h @@ -0,0 +1,92 @@ +/* + * The Mana Server + * Copyright (C) 2004-2010 The Mana World Development Team + * + * This file is part of The Mana Server. + * + * The Mana Server 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 + * any later version. + * + * The Mana Server 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 The Mana Server. If not, see . + */ + +#ifndef ITEMMANAGER_H +#define ITEMMANAGER_H + +#include +#include +#include + +class ItemClass; + +class ItemManager +{ + public: + ItemManager(const std::string &itemFile, const std::string &equipFile) : + mItemReferenceFile(itemFile), + mEquipCharSlotReferenceFile(equipFile), + mItemDatabaseVersion(0) {} + /** + * Loads item reference file. + */ + void initialize(); + + /** + * Reloads item reference file. + */ + void reload(); + + /** + * Destroy item classes. + */ + void deinitialize(); + + /** + * Gets the ItemClass having the given ID. + */ + ItemClass *getItem(int itemId) const; + + /** + * Gets the version of the loaded item database. + */ + unsigned int getDatabaseVersion() const; + + const std::string &getEquipNameFromId(unsigned int id) const; + + unsigned int getEquipIdFromName(const std::string &name) const; + + unsigned int getMaxSlotsFromId(unsigned int id) const; + + unsigned int getVisibleSlotCount() const; + + bool isEquipSlotVisible(unsigned int id) const; + + private: + typedef std::map< int, ItemClass * > ItemClasses; + // Map a string (name of slot) with (str-id, max-per-equip-slot) + typedef std::vector< std::pair< std::string, unsigned int > > EquipSlots; + // Reference to the vector position of equipSlots + typedef std::vector< unsigned int > VisibleEquipSlots; + + ItemClasses itemClasses; /**< Item reference */ + EquipSlots equipSlots; + VisibleEquipSlots visibleEquipSlots; + + std::string mItemReferenceFile; + std::string mEquipCharSlotReferenceFile; + mutable unsigned int mVisibleEquipSlotCount; // Cache + + unsigned int mItemDatabaseVersion; /**< Version of the loaded items database file.*/ +}; + +extern ItemManager *itemManager; + +#endif diff --git a/src/game-server/itemmanager.hpp b/src/game-server/itemmanager.hpp deleted file mode 100644 index ea0641c7..00000000 --- a/src/game-server/itemmanager.hpp +++ /dev/null @@ -1,92 +0,0 @@ -/* - * The Mana Server - * Copyright (C) 2004-2010 The Mana World Development Team - * - * This file is part of The Mana Server. - * - * The Mana Server 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 - * any later version. - * - * The Mana Server 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 The Mana Server. If not, see . - */ - -#ifndef ITEMMANAGER_H -#define ITEMMANAGER_H - -#include -#include -#include - -class ItemClass; - -class ItemManager -{ - public: - ItemManager(const std::string &itemFile, const std::string &equipFile) : - mItemReferenceFile(itemFile), - mEquipCharSlotReferenceFile(equipFile), - mItemDatabaseVersion(0) {} - /** - * Loads item reference file. - */ - void initialize(); - - /** - * Reloads item reference file. - */ - void reload(); - - /** - * Destroy item classes. - */ - void deinitialize(); - - /** - * Gets the ItemClass having the given ID. - */ - ItemClass *getItem(int itemId) const; - - /** - * Gets the version of the loaded item database. - */ - unsigned int getDatabaseVersion() const; - - const std::string &getEquipNameFromId(unsigned int id) const; - - unsigned int getEquipIdFromName(const std::string &name) const; - - unsigned int getMaxSlotsFromId(unsigned int id) const; - - unsigned int getVisibleSlotCount() const; - - bool isEquipSlotVisible(unsigned int id) const; - - private: - typedef std::map< int, ItemClass * > ItemClasses; - // Map a string (name of slot) with (str-id, max-per-equip-slot) - typedef std::vector< std::pair< std::string, unsigned int > > EquipSlots; - // Reference to the vector position of equipSlots - typedef std::vector< unsigned int > VisibleEquipSlots; - - ItemClasses itemClasses; /**< Item reference */ - EquipSlots equipSlots; - VisibleEquipSlots visibleEquipSlots; - - std::string mItemReferenceFile; - std::string mEquipCharSlotReferenceFile; - mutable unsigned int mVisibleEquipSlotCount; // Cache - - unsigned int mItemDatabaseVersion; /**< Version of the loaded items database file.*/ -}; - -extern ItemManager *itemManager; - -#endif diff --git a/src/game-server/main-game.cpp b/src/game-server/main-game.cpp index cc968c13..084415b0 100644 --- a/src/game-server/main-game.cpp +++ b/src/game-server/main-game.cpp @@ -36,25 +36,25 @@ #include "../config.h" #endif -#include "common/configuration.hpp" -#include "common/permissionmanager.hpp" -#include "common/resourcemanager.hpp" -#include "game-server/accountconnection.hpp" -#include "game-server/attributemanager.hpp" -#include "game-server/gamehandler.hpp" -#include "game-server/skillmanager.hpp" -#include "game-server/itemmanager.hpp" -#include "game-server/mapmanager.hpp" -#include "game-server/monstermanager.hpp" -#include "game-server/statusmanager.hpp" -#include "game-server/postman.hpp" -#include "game-server/state.hpp" -#include "net/bandwidth.hpp" -#include "net/connectionhandler.hpp" -#include "net/messageout.hpp" -#include "scripting/luascript.hpp" +#include "common/configuration.h" +#include "common/permissionmanager.h" +#include "common/resourcemanager.h" +#include "game-server/accountconnection.h" +#include "game-server/attributemanager.h" +#include "game-server/gamehandler.h" +#include "game-server/skillmanager.h" +#include "game-server/itemmanager.h" +#include "game-server/mapmanager.h" +#include "game-server/monstermanager.h" +#include "game-server/statusmanager.h" +#include "game-server/postman.h" +#include "game-server/state.h" +#include "net/bandwidth.h" +#include "net/connectionhandler.h" +#include "net/messageout.h" +#include "scripting/luascript.h" #include "utils/logger.h" -#include "utils/processorutils.hpp" +#include "utils/processorutils.h" #include "utils/stringfilter.h" #include "utils/timer.h" #include "utils/mathutils.h" diff --git a/src/game-server/map.cpp b/src/game-server/map.cpp index e5af1c32..14644026 100644 --- a/src/game-server/map.cpp +++ b/src/game-server/map.cpp @@ -23,7 +23,7 @@ #include #include -#include "game-server/map.hpp" +#include "game-server/map.h" // Basic cost for moving from one tile to another. // Used in findPath() function when computing the A* path algorithm. diff --git a/src/game-server/map.h b/src/game-server/map.h new file mode 100644 index 00000000..fab5baaf --- /dev/null +++ b/src/game-server/map.h @@ -0,0 +1,216 @@ +/* + * The Mana Server + * Copyright (C) 2004-2010 The Mana World Development Team + * + * This file is part of The Mana Server. + * + * The Mana Server 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 + * any later version. + * + * The Mana Server 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 The Mana Server. If not, see . + */ + +#ifndef MAP_H +#define MAP_H + +#include +#include +#include + +const unsigned int DEFAULT_TILE_WIDTH = 32; +const unsigned int DEFAULT_TILE_HEIGHT = 32; + +/** + * A position along a being's path. + * Used to compute each Path Nodes of the path. + */ +struct Position +{ + Position(int x, int y): + x(x), y(y) + { } + + int x; + int y; +}; + +typedef std::list Path; +typedef Path::iterator PathIterator; + +/** + * A meta tile stores additional information about a location on a tile map. + * This is information that doesn't need to be repeated for each tile in each + * layer of the map. + */ +class MetaTile +{ + public: + /** + * Constructor. + */ + MetaTile(); + + // Pathfinding members + int Fcost; /**< Estimation of total path cost */ + int Gcost; /**< Cost from start to this location */ + int Hcost; /**< Estimated cost to goal */ + int whichList; /**< No list, open list or closed list */ + int parentX; /**< X coordinate of parent tile */ + int parentY; /**< Y coordinate of parent tile */ + char blockmask; /**< walkability bitfield */ +}; + +/** + * A location on a tile map. Used for pathfinding, open list. + */ +class Location +{ + public: + /** + * Constructor. + */ + Location(int x, int y, MetaTile *tile); + + /** + * Comparison operator. + */ + bool operator< (const Location &loc) const; + + int x, y; + MetaTile *tile; +}; + +/** + * A tile map. + */ +class Map +{ + public: + enum BlockType + { + BLOCKTYPE_NONE = -1, + BLOCKTYPE_WALL, + BLOCKTYPE_CHARACTER, + BLOCKTYPE_MONSTER, + NB_BLOCKTYPES + }; + + /** + * Constructor that takes initial map size as parameters. + */ + Map(int width = 0, int height = 0, + int twidth = DEFAULT_TILE_WIDTH, int theight = DEFAULT_TILE_HEIGHT); + + /** + * Destructor. + */ + ~Map(); + + /** + * Sets the size of the map. This will destroy any existing map data. + */ + void setSize(int mWidth, int height); + + /** + * Get tile reference. + */ + MetaTile *getMetaTile(int x, int y); + + /** + * Marks a tile as occupied + */ + void blockTile(int x, int y, BlockType type); + + /** + * Marks a tile as unoccupied + */ + void freeTile(int x, int y, BlockType type); + + /** + * Gets walkability for a tile with a blocking bitmask + */ + bool getWalk(int x, int y, char walkmask = BLOCKMASK_WALL) const; + + /** + * Tells if a tile location is within the map range. + */ + bool contains(int x, int y) const; + + /** + * Returns the width of this map. + */ + int getWidth() const + { return mWidth; } + + /** + * Returns the height of this map. + */ + int getHeight() const + { return mHeight; } + + /** + * Returns the tile width of this map. + */ + int getTileWidth() const + { return mTileWidth; } + + /** + * Returns the tile height used by this map. + */ + int getTileHeight() const + { return mTileHeight; } + + /** + * Returns a general map property defined in the map file + */ + const std::string &getProperty(const std::string &key) const; + + /** + * Sets a map property + */ + void setProperty(const std::string& key, const std::string& val) + { mProperties[key] = val; } + + /** + * Find a path from one location to the next. + */ + Path findPath(int startX, int startY, + int destX, int destY, + unsigned char walkmask, + int maxCost = 20); + + /** + * Finds a simple path from location to the next. + */ + Path findSimplePath(int startX, int startY, + int destX, int destY, + unsigned char walkmask); + + private: + /** + * Blockmasks for different entities + */ + static const unsigned char BLOCKMASK_WALL = 0x80; // = bin 1000 0000 + static const unsigned char BLOCKMASK_CHARACTER = 0x01;// = bin 0000 0001 + static const unsigned char BLOCKMASK_MONSTER = 0x02; // = bin 0000 0010 + int *mOccupation[NB_BLOCKTYPES]; + + // map properties + int mWidth, mHeight; + int mTileWidth, mTileHeight; + std::map mProperties; + + // Pathfinding members + MetaTile *mMetaTiles; + int onClosedList, onOpenList; +}; + +#endif diff --git a/src/game-server/map.hpp b/src/game-server/map.hpp deleted file mode 100644 index fab5baaf..00000000 --- a/src/game-server/map.hpp +++ /dev/null @@ -1,216 +0,0 @@ -/* - * The Mana Server - * Copyright (C) 2004-2010 The Mana World Development Team - * - * This file is part of The Mana Server. - * - * The Mana Server 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 - * any later version. - * - * The Mana Server 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 The Mana Server. If not, see . - */ - -#ifndef MAP_H -#define MAP_H - -#include -#include -#include - -const unsigned int DEFAULT_TILE_WIDTH = 32; -const unsigned int DEFAULT_TILE_HEIGHT = 32; - -/** - * A position along a being's path. - * Used to compute each Path Nodes of the path. - */ -struct Position -{ - Position(int x, int y): - x(x), y(y) - { } - - int x; - int y; -}; - -typedef std::list Path; -typedef Path::iterator PathIterator; - -/** - * A meta tile stores additional information about a location on a tile map. - * This is information that doesn't need to be repeated for each tile in each - * layer of the map. - */ -class MetaTile -{ - public: - /** - * Constructor. - */ - MetaTile(); - - // Pathfinding members - int Fcost; /**< Estimation of total path cost */ - int Gcost; /**< Cost from start to this location */ - int Hcost; /**< Estimated cost to goal */ - int whichList; /**< No list, open list or closed list */ - int parentX; /**< X coordinate of parent tile */ - int parentY; /**< Y coordinate of parent tile */ - char blockmask; /**< walkability bitfield */ -}; - -/** - * A location on a tile map. Used for pathfinding, open list. - */ -class Location -{ - public: - /** - * Constructor. - */ - Location(int x, int y, MetaTile *tile); - - /** - * Comparison operator. - */ - bool operator< (const Location &loc) const; - - int x, y; - MetaTile *tile; -}; - -/** - * A tile map. - */ -class Map -{ - public: - enum BlockType - { - BLOCKTYPE_NONE = -1, - BLOCKTYPE_WALL, - BLOCKTYPE_CHARACTER, - BLOCKTYPE_MONSTER, - NB_BLOCKTYPES - }; - - /** - * Constructor that takes initial map size as parameters. - */ - Map(int width = 0, int height = 0, - int twidth = DEFAULT_TILE_WIDTH, int theight = DEFAULT_TILE_HEIGHT); - - /** - * Destructor. - */ - ~Map(); - - /** - * Sets the size of the map. This will destroy any existing map data. - */ - void setSize(int mWidth, int height); - - /** - * Get tile reference. - */ - MetaTile *getMetaTile(int x, int y); - - /** - * Marks a tile as occupied - */ - void blockTile(int x, int y, BlockType type); - - /** - * Marks a tile as unoccupied - */ - void freeTile(int x, int y, BlockType type); - - /** - * Gets walkability for a tile with a blocking bitmask - */ - bool getWalk(int x, int y, char walkmask = BLOCKMASK_WALL) const; - - /** - * Tells if a tile location is within the map range. - */ - bool contains(int x, int y) const; - - /** - * Returns the width of this map. - */ - int getWidth() const - { return mWidth; } - - /** - * Returns the height of this map. - */ - int getHeight() const - { return mHeight; } - - /** - * Returns the tile width of this map. - */ - int getTileWidth() const - { return mTileWidth; } - - /** - * Returns the tile height used by this map. - */ - int getTileHeight() const - { return mTileHeight; } - - /** - * Returns a general map property defined in the map file - */ - const std::string &getProperty(const std::string &key) const; - - /** - * Sets a map property - */ - void setProperty(const std::string& key, const std::string& val) - { mProperties[key] = val; } - - /** - * Find a path from one location to the next. - */ - Path findPath(int startX, int startY, - int destX, int destY, - unsigned char walkmask, - int maxCost = 20); - - /** - * Finds a simple path from location to the next. - */ - Path findSimplePath(int startX, int startY, - int destX, int destY, - unsigned char walkmask); - - private: - /** - * Blockmasks for different entities - */ - static const unsigned char BLOCKMASK_WALL = 0x80; // = bin 1000 0000 - static const unsigned char BLOCKMASK_CHARACTER = 0x01;// = bin 0000 0001 - static const unsigned char BLOCKMASK_MONSTER = 0x02; // = bin 0000 0010 - int *mOccupation[NB_BLOCKTYPES]; - - // map properties - int mWidth, mHeight; - int mTileWidth, mTileHeight; - std::map mProperties; - - // Pathfinding members - MetaTile *mMetaTiles; - int onClosedList, onOpenList; -}; - -#endif diff --git a/src/game-server/mapcomposite.cpp b/src/game-server/mapcomposite.cpp index 30d31bc7..b5a950b1 100644 --- a/src/game-server/mapcomposite.cpp +++ b/src/game-server/mapcomposite.cpp @@ -22,11 +22,11 @@ #include #include "point.h" -#include "common/configuration.hpp" -#include "game-server/map.hpp" -#include "game-server/mapcomposite.hpp" -#include "game-server/character.hpp" -#include "scripting/script.hpp" +#include "common/configuration.h" +#include "game-server/map.h" +#include "game-server/mapcomposite.h" +#include "game-server/character.h" +#include "scripting/script.h" #include "utils/logger.h" /* TODO: Implement overlapping map zones instead of strict partitioning. diff --git a/src/game-server/mapcomposite.h b/src/game-server/mapcomposite.h new file mode 100644 index 00000000..3de83c77 --- /dev/null +++ b/src/game-server/mapcomposite.h @@ -0,0 +1,347 @@ +/* + * The Mana Server + * Copyright (C) 2006-2010 The Mana World Development Team + * + * This file is part of The Mana Server. + * + * The Mana Server 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 + * any later version. + * + * The Mana Server 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 The Mana Server. If not, see . + */ + +#ifndef SERVER_MAPCOMPOSITE_H +#define SERVER_MAPCOMPOSITE_H + +#include +#include + +class Actor; +class Being; +class Character; +class Map; +class MapComposite; +class Point; +class Rectangle; +class Script; +class Thing; + +struct MapContent; +struct MapZone; + +enum PvPRules +{ + PVP_NONE, // no PvP on this map + PVP_FREE // unrestricted PvP on this map + // [space for additional PvP modes] +}; + +/** + * Ordered sets of zones of a map. + */ +typedef std::vector< unsigned > MapRegion; + +/** + * Iterates through the zones of a region of the map. + */ +struct ZoneIterator +{ + MapRegion region; /**< Zones to visit. Empty means the entire map. */ + unsigned pos; + MapZone *current; + const MapContent *map; + + ZoneIterator(const MapRegion &, const MapContent *); + void operator++(); + MapZone *operator*() const { return current; } + operator bool() const { return current; } +}; + +/** + * Iterates through the Characters of a region. + */ +struct CharacterIterator +{ + ZoneIterator iterator; + unsigned short pos; + Character *current; + + CharacterIterator(const ZoneIterator &); + void operator++(); + Character *operator*() const { return current; } + operator bool() const { return iterator; } +}; + +/** + * Iterates through the Beings of a region. + */ +struct BeingIterator +{ + ZoneIterator iterator; + unsigned short pos; + Being *current; + + BeingIterator(const ZoneIterator &); + void operator++(); + Being *operator*() const { return current; } + operator bool() const { return iterator; } +}; + +/** + * Iterates through the non-moving Actors of a region. + */ +struct FixedActorIterator +{ + ZoneIterator iterator; + unsigned short pos; + Actor *current; + + FixedActorIterator(const ZoneIterator &); + void operator++(); + Actor *operator*() const { return current; } + operator bool() const { return iterator; } +}; + +/** + * Iterates through the Actors of a region. + */ +struct ActorIterator +{ + ZoneIterator iterator; + unsigned short pos; + Actor *current; + + ActorIterator(const ZoneIterator &); + void operator++(); + Actor *operator*() const { return current; } + operator bool() const { return iterator; } +}; + +/** + * Part of a map. + */ +struct MapZone +{ + unsigned short nbCharacters, nbMovingObjects; + /** + * Objects present in this zone. + * Characters are stored first, then the remaining MovingObjects, then the + * remaining Objects. + */ + std::vector< Actor * > objects; + + /** + * Destinations of the objects that left this zone. + * This is necessary in order to have an accurate iterator around moving + * objects. + */ + MapRegion destinations; + + MapZone(): nbCharacters(0), nbMovingObjects(0) {} + void insert(Actor *); + void remove(Actor *); +}; + +/** + * Pool of public IDs for MovingObjects on a map. By maintaining public ID + * availability using bits, it can locate an available public ID fast while + * using minimal memory access. + */ +struct ObjectBucket +{ + static int const int_bitsize = sizeof(unsigned) * 8; + unsigned bitmap[256 / int_bitsize]; /**< Bitmap of free locations. */ + short free; /**< Number of empty places. */ + short next_object; /**< Next object to look at. */ + Actor *objects[256]; + + ObjectBucket(); + int allocate(); + void deallocate(int); +}; + +/** + * Entities on a map. + */ +struct MapContent +{ + MapContent(Map *); + ~MapContent(); + + /** + * Allocates a unique ID for an actor on this map. + */ + bool allocate(Actor *); + + /** + * Deallocates an ID. + */ + void deallocate(Actor *); + + /** + * Fills a region of zones within the range of a point. + */ + void fillRegion(MapRegion &, const Point &, int) const; + + /** + * Fills a region of zones inside a rectangle. + */ + void fillRegion(MapRegion &, const Rectangle &) const; + + /** + * Gets zone at given position. + */ + MapZone &getZone(const Point &pos) const; + + /** + * Things (items, characters, monsters, etc) located on the map. + */ + std::vector< Thing * > things; + + /** + * Buckets of MovingObjects located on the map, referenced by ID. + */ + ObjectBucket *buckets[256]; + + int last_bucket; /**< Last bucket acted upon. */ + + /** + * Partition of the Objects, depending on their position on the map. + */ + MapZone *zones; + + unsigned short mapWidth; /**< Width with respect to zones. */ + unsigned short mapHeight; /**< Height with respect to zones. */ +}; + +/** + * Combined map/entity structure. + */ +class MapComposite +{ + public: + /** + * Constructor. + */ + MapComposite(int id, const std::string &name); + + /** + * Destructor. + */ + ~MapComposite(); + + /** + * Sets the underlying pathfinding map. + * Can be done only once. + */ + void setMap(Map *); + + /** + * Gets the underlying pathfinding map. + */ + Map *getMap() const + { return mMap; } + + /** + * Sets the associated script. + */ + void setScript(Script *s) + { mScript = s; } + + /** + * Gets the associated script. + */ + Script *getScript() const + { return mScript; } + + /** + * Returns whether the map is active on this server or not. + */ + bool isActive() const + { return mMap; } + + /** + * Gets the game ID of this map. + */ + int getID() const + { return mID; } + + /** + * Gets the name of this map. + */ + const std::string &getName() const + { return mName; } + + /** + * Inserts a thing on the map. Sets its public ID if relevant. + */ + bool insert(Thing *); + + /** + * Removes a thing from the map. + */ + void remove(Thing *); + + /** + * Updates zones of every moving beings. + */ + void update(); + + /** + * Gets the PvP rules on the map. + */ + PvPRules getPvP() const { return mPvPRules; } + + /** + * Gets an iterator on the objects of the whole map. + */ + ZoneIterator getWholeMapIterator() const + { return ZoneIterator(MapRegion(), mContent); } + + /** + * Gets an iterator on the objects inside a given rectangle. + */ + ZoneIterator getInsideRectangleIterator(const Rectangle &) const; + + /** + * Gets an iterator on the objects around a given point. + */ + ZoneIterator getAroundPointIterator(const Point &, int radius) const; + + /** + * Gets an iterator on the objects around a given actor. + */ + ZoneIterator getAroundActorIterator(Actor *, int radius) const; + + /** + * Gets an iterator on the objects around the old and new positions of + * a character (including the ones that were but are now elsewhere). + */ + ZoneIterator getAroundBeingIterator(Being *, int radius) const; + + /** + * Gets everything related to the map. + */ + const std::vector< Thing * > &getEverything() const; + + private: + MapComposite(const MapComposite &); + + Map *mMap; /**< Actual map. */ + MapContent *mContent; /**< Entities on the map. */ + Script *mScript; /**< Script associated to this map. */ + std::string mName; /**< Name of the map. */ + unsigned short mID; /**< ID of the map. */ + + PvPRules mPvPRules; +}; + +#endif diff --git a/src/game-server/mapcomposite.hpp b/src/game-server/mapcomposite.hpp deleted file mode 100644 index 0f45d8a4..00000000 --- a/src/game-server/mapcomposite.hpp +++ /dev/null @@ -1,347 +0,0 @@ -/* - * The Mana Server - * Copyright (C) 2006-2010 The Mana World Development Team - * - * This file is part of The Mana Server. - * - * The Mana Server 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 - * any later version. - * - * The Mana Server 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 The Mana Server. If not, see . - */ - -#ifndef SERVER_MAPCOMPOSITE_HPP -#define SERVER_MAPCOMPOSITE_HPP - -#include -#include - -class Actor; -class Being; -class Character; -class Map; -class MapComposite; -class Point; -class Rectangle; -class Script; -class Thing; - -struct MapContent; -struct MapZone; - -enum PvPRules -{ - PVP_NONE, // no PvP on this map - PVP_FREE // unrestricted PvP on this map - // [space for additional PvP modes] -}; - -/** - * Ordered sets of zones of a map. - */ -typedef std::vector< unsigned > MapRegion; - -/** - * Iterates through the zones of a region of the map. - */ -struct ZoneIterator -{ - MapRegion region; /**< Zones to visit. Empty means the entire map. */ - unsigned pos; - MapZone *current; - const MapContent *map; - - ZoneIterator(const MapRegion &, const MapContent *); - void operator++(); - MapZone *operator*() const { return current; } - operator bool() const { return current; } -}; - -/** - * Iterates through the Characters of a region. - */ -struct CharacterIterator -{ - ZoneIterator iterator; - unsigned short pos; - Character *current; - - CharacterIterator(const ZoneIterator &); - void operator++(); - Character *operator*() const { return current; } - operator bool() const { return iterator; } -}; - -/** - * Iterates through the Beings of a region. - */ -struct BeingIterator -{ - ZoneIterator iterator; - unsigned short pos; - Being *current; - - BeingIterator(const ZoneIterator &); - void operator++(); - Being *operator*() const { return current; } - operator bool() const { return iterator; } -}; - -/** - * Iterates through the non-moving Actors of a region. - */ -struct FixedActorIterator -{ - ZoneIterator iterator; - unsigned short pos; - Actor *current; - - FixedActorIterator(const ZoneIterator &); - void operator++(); - Actor *operator*() const { return current; } - operator bool() const { return iterator; } -}; - -/** - * Iterates through the Actors of a region. - */ -struct ActorIterator -{ - ZoneIterator iterator; - unsigned short pos; - Actor *current; - - ActorIterator(const ZoneIterator &); - void operator++(); - Actor *operator*() const { return current; } - operator bool() const { return iterator; } -}; - -/** - * Part of a map. - */ -struct MapZone -{ - unsigned short nbCharacters, nbMovingObjects; - /** - * Objects present in this zone. - * Characters are stored first, then the remaining MovingObjects, then the - * remaining Objects. - */ - std::vector< Actor * > objects; - - /** - * Destinations of the objects that left this zone. - * This is necessary in order to have an accurate iterator around moving - * objects. - */ - MapRegion destinations; - - MapZone(): nbCharacters(0), nbMovingObjects(0) {} - void insert(Actor *); - void remove(Actor *); -}; - -/** - * Pool of public IDs for MovingObjects on a map. By maintaining public ID - * availability using bits, it can locate an available public ID fast while - * using minimal memory access. - */ -struct ObjectBucket -{ - static int const int_bitsize = sizeof(unsigned) * 8; - unsigned bitmap[256 / int_bitsize]; /**< Bitmap of free locations. */ - short free; /**< Number of empty places. */ - short next_object; /**< Next object to look at. */ - Actor *objects[256]; - - ObjectBucket(); - int allocate(); - void deallocate(int); -}; - -/** - * Entities on a map. - */ -struct MapContent -{ - MapContent(Map *); - ~MapContent(); - - /** - * Allocates a unique ID for an actor on this map. - */ - bool allocate(Actor *); - - /** - * Deallocates an ID. - */ - void deallocate(Actor *); - - /** - * Fills a region of zones within the range of a point. - */ - void fillRegion(MapRegion &, const Point &, int) const; - - /** - * Fills a region of zones inside a rectangle. - */ - void fillRegion(MapRegion &, const Rectangle &) const; - - /** - * Gets zone at given position. - */ - MapZone &getZone(const Point &pos) const; - - /** - * Things (items, characters, monsters, etc) located on the map. - */ - std::vector< Thing * > things; - - /** - * Buckets of MovingObjects located on the map, referenced by ID. - */ - ObjectBucket *buckets[256]; - - int last_bucket; /**< Last bucket acted upon. */ - - /** - * Partition of the Objects, depending on their position on the map. - */ - MapZone *zones; - - unsigned short mapWidth; /**< Width with respect to zones. */ - unsigned short mapHeight; /**< Height with respect to zones. */ -}; - -/** - * Combined map/entity structure. - */ -class MapComposite -{ - public: - /** - * Constructor. - */ - MapComposite(int id, const std::string &name); - - /** - * Destructor. - */ - ~MapComposite(); - - /** - * Sets the underlying pathfinding map. - * Can be done only once. - */ - void setMap(Map *); - - /** - * Gets the underlying pathfinding map. - */ - Map *getMap() const - { return mMap; } - - /** - * Sets the associated script. - */ - void setScript(Script *s) - { mScript = s; } - - /** - * Gets the associated script. - */ - Script *getScript() const - { return mScript; } - - /** - * Returns whether the map is active on this server or not. - */ - bool isActive() const - { return mMap; } - - /** - * Gets the game ID of this map. - */ - int getID() const - { return mID; } - - /** - * Gets the name of this map. - */ - const std::string &getName() const - { return mName; } - - /** - * Inserts a thing on the map. Sets its public ID if relevant. - */ - bool insert(Thing *); - - /** - * Removes a thing from the map. - */ - void remove(Thing *); - - /** - * Updates zones of every moving beings. - */ - void update(); - - /** - * Gets the PvP rules on the map. - */ - PvPRules getPvP() const { return mPvPRules; } - - /** - * Gets an iterator on the objects of the whole map. - */ - ZoneIterator getWholeMapIterator() const - { return ZoneIterator(MapRegion(), mContent); } - - /** - * Gets an iterator on the objects inside a given rectangle. - */ - ZoneIterator getInsideRectangleIterator(const Rectangle &) const; - - /** - * Gets an iterator on the objects around a given point. - */ - ZoneIterator getAroundPointIterator(const Point &, int radius) const; - - /** - * Gets an iterator on the objects around a given actor. - */ - ZoneIterator getAroundActorIterator(Actor *, int radius) const; - - /** - * Gets an iterator on the objects around the old and new positions of - * a character (including the ones that were but are now elsewhere). - */ - ZoneIterator getAroundBeingIterator(Being *, int radius) const; - - /** - * Gets everything related to the map. - */ - const std::vector< Thing * > &getEverything() const; - - private: - MapComposite(const MapComposite &); - - Map *mMap; /**< Actual map. */ - MapContent *mContent; /**< Entities on the map. */ - Script *mScript; /**< Script associated to this map. */ - std::string mName; /**< Name of the map. */ - unsigned short mID; /**< ID of the map. */ - - PvPRules mPvPRules; -}; - -#endif diff --git a/src/game-server/mapmanager.cpp b/src/game-server/mapmanager.cpp index ab9b2dc5..fce5cc5a 100644 --- a/src/game-server/mapmanager.cpp +++ b/src/game-server/mapmanager.cpp @@ -18,14 +18,14 @@ * along with The Mana Server. If not, see . */ -#include "game-server/mapmanager.hpp" +#include "game-server/mapmanager.h" -#include "common/resourcemanager.hpp" -#include "game-server/map.hpp" -#include "game-server/mapcomposite.hpp" -#include "game-server/mapreader.hpp" +#include "common/resourcemanager.h" +#include "game-server/map.h" +#include "game-server/mapcomposite.h" +#include "game-server/mapreader.h" #include "utils/logger.h" -#include "utils/xml.hpp" +#include "utils/xml.h" #include diff --git a/src/game-server/mapmanager.h b/src/game-server/mapmanager.h new file mode 100644 index 00000000..d21bd419 --- /dev/null +++ b/src/game-server/mapmanager.h @@ -0,0 +1,68 @@ +/* + * The Mana Server + * Copyright (C) 2004-2010 The Mana World Development Team + * + * This file is part of The Mana Server. + * + * The Mana Server 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 + * any later version. + * + * The Mana Server 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 The Mana Server. If not, see . + */ + +#ifndef MAPMANAGER_H +#define MAPMANAGER_H + +#include +#include + +class MapComposite; + +namespace MapManager +{ + typedef std::map< int, MapComposite * > Maps; + + /** + * Loads map reference file and prepares maps. + * @return the number of maps loaded succesfully + */ + int initialize(const std::string &mapReferenceFile); + + /** + * Destroy loaded maps. + */ + void deinitialize(); + + /** + * Returns the requested map. + * + * @return the requested map, or NULL if no map with the given ID exists. + */ + MapComposite *getMap(int mapId); + + /** + * Returns the requested map + */ + MapComposite *getMap(const std::string &mapName); + + /** + * Returns all the maps. + */ + const Maps &getMaps(); + + /** + * Sets the activity status of the map. + * @return true if the activation was successful. + */ + bool raiseActive(int mapId); +} + +#endif // MAPMANAGER_H diff --git a/src/game-server/mapmanager.hpp b/src/game-server/mapmanager.hpp deleted file mode 100644 index d21bd419..00000000 --- a/src/game-server/mapmanager.hpp +++ /dev/null @@ -1,68 +0,0 @@ -/* - * The Mana Server - * Copyright (C) 2004-2010 The Mana World Development Team - * - * This file is part of The Mana Server. - * - * The Mana Server 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 - * any later version. - * - * The Mana Server 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 The Mana Server. If not, see . - */ - -#ifndef MAPMANAGER_H -#define MAPMANAGER_H - -#include -#include - -class MapComposite; - -namespace MapManager -{ - typedef std::map< int, MapComposite * > Maps; - - /** - * Loads map reference file and prepares maps. - * @return the number of maps loaded succesfully - */ - int initialize(const std::string &mapReferenceFile); - - /** - * Destroy loaded maps. - */ - void deinitialize(); - - /** - * Returns the requested map. - * - * @return the requested map, or NULL if no map with the given ID exists. - */ - MapComposite *getMap(int mapId); - - /** - * Returns the requested map - */ - MapComposite *getMap(const std::string &mapName); - - /** - * Returns all the maps. - */ - const Maps &getMaps(); - - /** - * Sets the activity status of the map. - * @return true if the activation was successful. - */ - bool raiseActive(int mapId); -} - -#endif // MAPMANAGER_H diff --git a/src/game-server/mapreader.cpp b/src/game-server/mapreader.cpp index 52dd08bf..a950d448 100644 --- a/src/game-server/mapreader.cpp +++ b/src/game-server/mapreader.cpp @@ -18,21 +18,21 @@ * along with The Mana Server. If not, see . */ -#include "game-server/mapreader.hpp" - -#include "common/resourcemanager.hpp" -#include "game-server/map.hpp" -#include "game-server/mapcomposite.hpp" -#include "game-server/mapmanager.hpp" -#include "game-server/monstermanager.hpp" -#include "game-server/spawnarea.hpp" -#include "game-server/trigger.hpp" -#include "scripting/script.hpp" +#include "game-server/mapreader.h" + +#include "common/resourcemanager.h" +#include "game-server/map.h" +#include "game-server/mapcomposite.h" +#include "game-server/mapmanager.h" +#include "game-server/monstermanager.h" +#include "game-server/spawnarea.h" +#include "game-server/trigger.h" +#include "scripting/script.h" #include "utils/base64.h" #include "utils/logger.h" -#include "utils/xml.hpp" -#include "utils/zlib.hpp" -#include "utils/string.hpp" +#include "utils/xml.h" +#include "utils/zlib.h" +#include "utils/string.h" #include diff --git a/src/game-server/mapreader.h b/src/game-server/mapreader.h new file mode 100644 index 00000000..f4a0e5f8 --- /dev/null +++ b/src/game-server/mapreader.h @@ -0,0 +1,74 @@ +/* + * The Mana Server + * Copyright (C) 2004-2010 The Mana World Development Team + * + * This file is part of The Mana Server. + * + * The Mana Server 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 + * any later version. + * + * The Mana Server 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 The Mana Server. If not, see . + */ + +#ifndef _MAPREADER_H +#define _MAPREADER_H + +#include +#include + +#include + +class Map; +class MapComposite; +class Thing; + +/** + * Reader for XML map files (*.tmx) + */ +class MapReader +{ + public: + /** + * Read an XML map from a file. + * @return true if it was successful. + */ + static bool readMap(const std::string &filename, + MapComposite *composite); + + private: + /** + * Read an XML map from a parsed XML tree, and populate things with + * objects in that map. + */ + static Map *readMap(xmlNodePtr node, const std::string &path, + MapComposite *composite, + std::vector &things); + + /** + * Reads a map layer and adds it to the given map. + */ + static void readLayer(xmlNodePtr node, Map *map); + + /** + * Get the string value from the given object property node. + */ + static std::string getObjectProperty(xmlNodePtr node, + const std::string &def); + + /** + * Get the integer value from the given object property node. + */ + static int getObjectProperty(xmlNodePtr node, int def); + + static void setTileWithGid(Map *map, int x, int y, int gid); +}; + +#endif diff --git a/src/game-server/mapreader.hpp b/src/game-server/mapreader.hpp deleted file mode 100644 index f4a0e5f8..00000000 --- a/src/game-server/mapreader.hpp +++ /dev/null @@ -1,74 +0,0 @@ -/* - * The Mana Server - * Copyright (C) 2004-2010 The Mana World Development Team - * - * This file is part of The Mana Server. - * - * The Mana Server 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 - * any later version. - * - * The Mana Server 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 The Mana Server. If not, see . - */ - -#ifndef _MAPREADER_H -#define _MAPREADER_H - -#include -#include - -#include - -class Map; -class MapComposite; -class Thing; - -/** - * Reader for XML map files (*.tmx) - */ -class MapReader -{ - public: - /** - * Read an XML map from a file. - * @return true if it was successful. - */ - static bool readMap(const std::string &filename, - MapComposite *composite); - - private: - /** - * Read an XML map from a parsed XML tree, and populate things with - * objects in that map. - */ - static Map *readMap(xmlNodePtr node, const std::string &path, - MapComposite *composite, - std::vector &things); - - /** - * Reads a map layer and adds it to the given map. - */ - static void readLayer(xmlNodePtr node, Map *map); - - /** - * Get the string value from the given object property node. - */ - static std::string getObjectProperty(xmlNodePtr node, - const std::string &def); - - /** - * Get the integer value from the given object property node. - */ - static int getObjectProperty(xmlNodePtr node, int def); - - static void setTileWithGid(Map *map, int x, int y, int gid); -}; - -#endif diff --git a/src/game-server/monster.cpp b/src/game-server/monster.cpp index 56391aa5..611fcea0 100644 --- a/src/game-server/monster.cpp +++ b/src/game-server/monster.cpp @@ -18,19 +18,19 @@ * along with The Mana Server. If not, see . */ -#include "game-server/monster.hpp" - -#include "common/configuration.hpp" -#include "common/resourcemanager.hpp" -#include "game-server/attributemanager.hpp" -#include "game-server/character.hpp" -#include "game-server/collisiondetection.hpp" -#include "game-server/item.hpp" -#include "game-server/mapcomposite.hpp" -#include "game-server/state.hpp" -#include "scripting/script.hpp" +#include "game-server/monster.h" + +#include "common/configuration.h" +#include "common/resourcemanager.h" +#include "game-server/attributemanager.h" +#include "game-server/character.h" +#include "game-server/collisiondetection.h" +#include "game-server/item.h" +#include "game-server/mapcomposite.h" +#include "game-server/state.h" +#include "scripting/script.h" #include "utils/logger.h" -#include "utils/speedconv.hpp" +#include "utils/speedconv.h" #include diff --git a/src/game-server/monster.h b/src/game-server/monster.h new file mode 100644 index 00000000..0028920a --- /dev/null +++ b/src/game-server/monster.h @@ -0,0 +1,351 @@ +/* + * The Mana Server + * Copyright (C) 2004-2010 The Mana World Development Team + * + * This file is part of The Mana Server. + * + * The Mana Server 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 + * any later version. + * + * The Mana Server 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 The Mana Server. If not, see . + */ + +#ifndef MONSTER_H +#define MONSTER_H + +#include +#include +#include + +#include "game-server/being.h" +#include "game-server/eventlistener.h" +#include "defines.h" + +class ItemClass; +class Script; + +/** + * Structure containing an item class and its probability to be dropped + * (unit: 1/10000). + */ +struct MonsterDrop +{ + ItemClass *item; + int probability; +}; + +typedef std::vector< MonsterDrop > MonsterDrops; + +/** + * Structure containing different attack types of a monster type + */ +struct MonsterAttack +{ + unsigned id; + int priority; + float damageFactor; + int element; + DMG_TY type; + int preDelay; + int aftDelay; + int range; + std::string scriptFunction; +}; + +typedef std::vector< MonsterAttack *> MonsterAttacks; + +/** + * Class describing the characteristics of a generic monster. + */ +class MonsterClass +{ + public: + MonsterClass(int id): + mId(id), + mSpeed(1), + mSize(16), + mExp(-1), + mAggressive(false), + mTrackRange(1), + mStrollRange(0), + mMutation(0), + mAttackDistance(0), + mOptimalLevel(0), + mScript("") + {} + + /** + * Returns monster type. This is the Id of the monster class. + */ + int getId() const + { return mId; } + + /** + * Sets monster drops. These are the items the monster drops when it + * dies. + */ + void setDrops(const MonsterDrops &v) + { mDrops = v; } + + /** + * Sets a being base attribute. + */ + void setAttribute(int attribute, double value) + { mAttributes[attribute] = value; } + + /** + * Returns a being base attribute. + */ + double getAttribute(int attribute) const + { return mAttributes.at(attribute); } + + /** + * Returns whether the monster has got the attribute. + */ + bool hasAttribute(int attribute) const + { return (mAttributes.find(attribute) != mAttributes.end()); } + + + /** Sets collision circle radius. */ + void setSize(int size) { mSize = size; } + + /** Returns collision circle radius. */ + int getSize() const { return mSize; } + + /** Sets experience reward for killing the monster. */ + void setExp(int exp) { mExp = exp; } + + /** Returns experience reward for killing the monster. */ + int getExp() const { return mExp; } + + /** Gets maximum skill level after which exp reward is reduced */ + void setOptimalLevel(int level) { mOptimalLevel = level; } + + /** Sets maximum skill level after which exp reward is reduced. */ + int getOptimalLevel() const { return mOptimalLevel; } + + /** Sets if the monster attacks without being attacked first. */ + void setAggressive(bool aggressive) { mAggressive = aggressive; } + + /** Returns if the monster attacks without being attacked first. */ + bool isAggressive() const { return mAggressive; } + + /** Sets range in tiles in which the monster searches for enemies. */ + void setTrackRange(unsigned range){ mTrackRange = range; } + + /** + * Returns range in tiles in which the monster searches for enemies. + */ + unsigned getTrackRange() const { return mTrackRange; } + + /** Sets range in tiles in which the monster moves around when idle. */ + void setStrollRange(unsigned range) { mStrollRange = range; } + + /** + * Returns range in tiles in which the monster moves around when idle. + */ + unsigned getStrollRange() const { return mStrollRange; } + + /** Sets mutation factor in percent. */ + void setMutation(unsigned factor) { mMutation = factor; } + + /** Returns mutation factor in percent. */ + unsigned getMutation() const { return mMutation; } + + /** Sets preferred combat distance in pixels. */ + void setAttackDistance(unsigned distance) + { mAttackDistance = distance; } + + /** Returns preferred combat distance in pixels. */ + unsigned getAttackDistance() const { return mAttackDistance; } + + /** Adds an attack to the monsters repertoire. */ + void addAttack(MonsterAttack *type) { mAttacks.push_back(type); } + + /** Returns all attacks of the monster. */ + const MonsterAttacks &getAttacks() const { return mAttacks; } + + /** sets the script file for the monster */ + void setScript(const std::string &filename) { mScript = filename; } + + /** Returns script filename */ + const std::string &getScript() const { return mScript; } + + /** + * Randomly selects a monster drop + * @returns A class of item to drop, or NULL if none was found. + */ + ItemClass *getRandomDrop() const; + + private: + unsigned short mId; + MonsterDrops mDrops; + std::map mAttributes; /**< Base attributes of the monster. */ + float mSpeed; /**< The monster class speed in tiles per second */ + int mSize; + int mExp; + + bool mAggressive; + int mTrackRange; + int mStrollRange; + int mMutation; + int mAttackDistance; + int mOptimalLevel; + MonsterAttacks mAttacks; + std::string mScript; + + friend class MonsterManager; +}; + +/** + * Structure holding possible positions relative to the target from which + * the monster can attack + */ +struct AttackPosition +{ + AttackPosition(int posX, int posY, Direction dir): + x(posX), + y(posY), + direction(dir) + {} + + int x; + int y; + Direction direction; +}; + +/** + * The class for a fightable monster with its own AI + */ +class Monster : public Being +{ + public: + /** Time in game ticks until ownership of a monster can change. */ + static const int KILLSTEAL_PROTECTION_TIME = 100; + + /** + * Constructor. + */ + Monster(MonsterClass *); + + /** + * Destructor. + */ + ~Monster(); + + /** + * Returns monster specy. + */ + MonsterClass *getSpecy() const + { return mSpecy; } + + /** + * Performs one step of controller logic. + */ + void update(); + + /** + * Performs an attack, if needed. + */ + void perform(); + + /** + * Loads a script file for this monster + */ + void loadScript(const std::string &scriptName); + + /** + * + */ + virtual int getAttackType() const + { return mCurrentAttack->id; } + + /** + * Kills the being. + */ + void died(); + + /** + * Alters hate for the monster + */ + void changeAnger(Actor *target, int amount); + + /** + * Calls the damage function in Being and updates the aggro list + */ + virtual int damage(Actor *source, const Damage &damage); + + /** + * Removes a being from the anger list. + */ + void forgetTarget(Thing *being); + + /** + * Returns the way the actor is blocked by other things on the map. + */ + virtual unsigned char getWalkMask() const + { + // blocked walls, other monsters and players ( bin 1000 0011) + return 0x83; + } + + protected: + /** + * Returns the way the actor blocks pathfinding for other objects. + */ + virtual Map::BlockType getBlockType() const + { return Map::BLOCKTYPE_MONSTER; } + + private: + static const int DECAY_TIME = 50; + + int calculatePositionPriority(Point position, int targetPriority); + + MonsterClass *mSpecy; + + /** + * Stores individual script for the monster, when NULL the script + * from mSpecy is used. + */ + Script *mScript; + + /** Aggression towards other beings. */ + std::map mAnger; + + /** Listener for updating the anger list. */ + EventListener mTargetListener; + + /** + * Character who currently owns this monster (killsteal protection). + */ + Character *mOwner; + + /** List of characters and their skills that attacked this monster. */ + std::map > mExpReceivers; + + /** + * List of characters who are entitled to receive exp (killsteal + * protection). + */ + std::set mLegalExpReceivers; + + /** Attack the monster is currently performing. */ + MonsterAttack *mCurrentAttack; + + /** + * Set positions relative to target from which the monster can attack. + */ + std::list mAttackPositions; + + friend struct MonsterTargetEventDispatch; +}; + +#endif // MONSTER_H diff --git a/src/game-server/monster.hpp b/src/game-server/monster.hpp deleted file mode 100644 index 2c4d59e2..00000000 --- a/src/game-server/monster.hpp +++ /dev/null @@ -1,351 +0,0 @@ -/* - * The Mana Server - * Copyright (C) 2004-2010 The Mana World Development Team - * - * This file is part of The Mana Server. - * - * The Mana Server 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 - * any later version. - * - * The Mana Server 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 The Mana Server. If not, see . - */ - -#ifndef MONSTER_H -#define MONSTER_H - -#include -#include -#include - -#include "game-server/being.hpp" -#include "game-server/eventlistener.hpp" -#include "defines.h" - -class ItemClass; -class Script; - -/** - * Structure containing an item class and its probability to be dropped - * (unit: 1/10000). - */ -struct MonsterDrop -{ - ItemClass *item; - int probability; -}; - -typedef std::vector< MonsterDrop > MonsterDrops; - -/** - * Structure containing different attack types of a monster type - */ -struct MonsterAttack -{ - unsigned id; - int priority; - float damageFactor; - int element; - DMG_TY type; - int preDelay; - int aftDelay; - int range; - std::string scriptFunction; -}; - -typedef std::vector< MonsterAttack *> MonsterAttacks; - -/** - * Class describing the characteristics of a generic monster. - */ -class MonsterClass -{ - public: - MonsterClass(int id): - mId(id), - mSpeed(1), - mSize(16), - mExp(-1), - mAggressive(false), - mTrackRange(1), - mStrollRange(0), - mMutation(0), - mAttackDistance(0), - mOptimalLevel(0), - mScript("") - {} - - /** - * Returns monster type. This is the Id of the monster class. - */ - int getId() const - { return mId; } - - /** - * Sets monster drops. These are the items the monster drops when it - * dies. - */ - void setDrops(const MonsterDrops &v) - { mDrops = v; } - - /** - * Sets a being base attribute. - */ - void setAttribute(int attribute, double value) - { mAttributes[attribute] = value; } - - /** - * Returns a being base attribute. - */ - double getAttribute(int attribute) const - { return mAttributes.at(attribute); } - - /** - * Returns whether the monster has got the attribute. - */ - bool hasAttribute(int attribute) const - { return (mAttributes.find(attribute) != mAttributes.end()); } - - - /** Sets collision circle radius. */ - void setSize(int size) { mSize = size; } - - /** Returns collision circle radius. */ - int getSize() const { return mSize; } - - /** Sets experience reward for killing the monster. */ - void setExp(int exp) { mExp = exp; } - - /** Returns experience reward for killing the monster. */ - int getExp() const { return mExp; } - - /** Gets maximum skill level after which exp reward is reduced */ - void setOptimalLevel(int level) { mOptimalLevel = level; } - - /** Sets maximum skill level after which exp reward is reduced. */ - int getOptimalLevel() const { return mOptimalLevel; } - - /** Sets if the monster attacks without being attacked first. */ - void setAggressive(bool aggressive) { mAggressive = aggressive; } - - /** Returns if the monster attacks without being attacked first. */ - bool isAggressive() const { return mAggressive; } - - /** Sets range in tiles in which the monster searches for enemies. */ - void setTrackRange(unsigned range){ mTrackRange = range; } - - /** - * Returns range in tiles in which the monster searches for enemies. - */ - unsigned getTrackRange() const { return mTrackRange; } - - /** Sets range in tiles in which the monster moves around when idle. */ - void setStrollRange(unsigned range) { mStrollRange = range; } - - /** - * Returns range in tiles in which the monster moves around when idle. - */ - unsigned getStrollRange() const { return mStrollRange; } - - /** Sets mutation factor in percent. */ - void setMutation(unsigned factor) { mMutation = factor; } - - /** Returns mutation factor in percent. */ - unsigned getMutation() const { return mMutation; } - - /** Sets preferred combat distance in pixels. */ - void setAttackDistance(unsigned distance) - { mAttackDistance = distance; } - - /** Returns preferred combat distance in pixels. */ - unsigned getAttackDistance() const { return mAttackDistance; } - - /** Adds an attack to the monsters repertoire. */ - void addAttack(MonsterAttack *type) { mAttacks.push_back(type); } - - /** Returns all attacks of the monster. */ - const MonsterAttacks &getAttacks() const { return mAttacks; } - - /** sets the script file for the monster */ - void setScript(const std::string &filename) { mScript = filename; } - - /** Returns script filename */ - const std::string &getScript() const { return mScript; } - - /** - * Randomly selects a monster drop - * @returns A class of item to drop, or NULL if none was found. - */ - ItemClass *getRandomDrop() const; - - private: - unsigned short mId; - MonsterDrops mDrops; - std::map mAttributes; /**< Base attributes of the monster. */ - float mSpeed; /**< The monster class speed in tiles per second */ - int mSize; - int mExp; - - bool mAggressive; - int mTrackRange; - int mStrollRange; - int mMutation; - int mAttackDistance; - int mOptimalLevel; - MonsterAttacks mAttacks; - std::string mScript; - - friend class MonsterManager; -}; - -/** - * Structure holding possible positions relative to the target from which - * the monster can attack - */ -struct AttackPosition -{ - AttackPosition(int posX, int posY, Direction dir): - x(posX), - y(posY), - direction(dir) - {} - - int x; - int y; - Direction direction; -}; - -/** - * The class for a fightable monster with its own AI - */ -class Monster : public Being -{ - public: - /** Time in game ticks until ownership of a monster can change. */ - static const int KILLSTEAL_PROTECTION_TIME = 100; - - /** - * Constructor. - */ - Monster(MonsterClass *); - - /** - * Destructor. - */ - ~Monster(); - - /** - * Returns monster specy. - */ - MonsterClass *getSpecy() const - { return mSpecy; } - - /** - * Performs one step of controller logic. - */ - void update(); - - /** - * Performs an attack, if needed. - */ - void perform(); - - /** - * Loads a script file for this monster - */ - void loadScript(const std::string &scriptName); - - /** - * - */ - virtual int getAttackType() const - { return mCurrentAttack->id; } - - /** - * Kills the being. - */ - void died(); - - /** - * Alters hate for the monster - */ - void changeAnger(Actor *target, int amount); - - /** - * Calls the damage function in Being and updates the aggro list - */ - virtual int damage(Actor *source, const Damage &damage); - - /** - * Removes a being from the anger list. - */ - void forgetTarget(Thing *being); - - /** - * Returns the way the actor is blocked by other things on the map. - */ - virtual unsigned char getWalkMask() const - { - // blocked walls, other monsters and players ( bin 1000 0011) - return 0x83; - } - - protected: - /** - * Returns the way the actor blocks pathfinding for other objects. - */ - virtual Map::BlockType getBlockType() const - { return Map::BLOCKTYPE_MONSTER; } - - private: - static const int DECAY_TIME = 50; - - int calculatePositionPriority(Point position, int targetPriority); - - MonsterClass *mSpecy; - - /** - * Stores individual script for the monster, when NULL the script - * from mSpecy is used. - */ - Script *mScript; - - /** Aggression towards other beings. */ - std::map mAnger; - - /** Listener for updating the anger list. */ - EventListener mTargetListener; - - /** - * Character who currently owns this monster (killsteal protection). - */ - Character *mOwner; - - /** List of characters and their skills that attacked this monster. */ - std::map > mExpReceivers; - - /** - * List of characters who are entitled to receive exp (killsteal - * protection). - */ - std::set mLegalExpReceivers; - - /** Attack the monster is currently performing. */ - MonsterAttack *mCurrentAttack; - - /** - * Set positions relative to target from which the monster can attack. - */ - std::list mAttackPositions; - - friend struct MonsterTargetEventDispatch; -}; - -#endif // MONSTER_H diff --git a/src/game-server/monstermanager.cpp b/src/game-server/monstermanager.cpp index 1444e17b..0ad48f7f 100644 --- a/src/game-server/monstermanager.cpp +++ b/src/game-server/monstermanager.cpp @@ -18,14 +18,14 @@ * along with The Mana Server. If not, see . */ -#include "game-server/monstermanager.hpp" +#include "game-server/monstermanager.h" -#include "common/resourcemanager.hpp" -#include "game-server/attributemanager.hpp" -#include "game-server/itemmanager.hpp" -#include "game-server/monster.hpp" +#include "common/resourcemanager.h" +#include "game-server/attributemanager.h" +#include "game-server/itemmanager.h" +#include "game-server/monster.h" #include "utils/logger.h" -#include "utils/xml.hpp" +#include "utils/xml.h" Element elementFromString (const std::string &name) { diff --git a/src/game-server/monstermanager.h b/src/game-server/monstermanager.h new file mode 100644 index 00000000..36d11e35 --- /dev/null +++ b/src/game-server/monstermanager.h @@ -0,0 +1,62 @@ +/* + * The Mana Server + * Copyright (C) 2007-2010 The Mana World Development Team + * + * This file is part of The Mana Server. + * + * The Mana Server 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 + * any later version. + * + * The Mana Server 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 The Mana Server. If not, see . + */ + +#ifndef MONSTERMANAGER_H +#define MONSTERMANAGER_H + +#include +#include +class MonsterClass; +class MonsterManager +{ + public: + + MonsterManager(const std::string &file) : mMonsterReferenceFile(file) {} + /** + * Loads monster reference file. + */ + void initialize(); + + /** + * Reloads monster reference file. + */ + void reload(); + + /** + * Destroy monster classes. + */ + void deinitialize(); + + /** + * Gets the MonsterClass having the given ID. + */ + MonsterClass *getMonster(int id); + + private: + + typedef std::map< int, MonsterClass * > MonsterClasses; + MonsterClasses mMonsterClasses; /**< Monster reference */ + + std::string mMonsterReferenceFile; +}; + +extern MonsterManager *monsterManager; + +#endif // MONSTERMANAGER_H diff --git a/src/game-server/monstermanager.hpp b/src/game-server/monstermanager.hpp deleted file mode 100644 index 6337b816..00000000 --- a/src/game-server/monstermanager.hpp +++ /dev/null @@ -1,62 +0,0 @@ -/* - * The Mana Server - * Copyright (C) 2007-2010 The Mana World Development Team - * - * This file is part of The Mana Server. - * - * The Mana Server 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 - * any later version. - * - * The Mana Server 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 The Mana Server. If not, see . - */ - -#ifndef MONSTERMANAGER_HPP -#define MONSTERMANAGER_HPP - -#include -#include -class MonsterClass; -class MonsterManager -{ - public: - - MonsterManager(const std::string &file) : mMonsterReferenceFile(file) {} - /** - * Loads monster reference file. - */ - void initialize(); - - /** - * Reloads monster reference file. - */ - void reload(); - - /** - * Destroy monster classes. - */ - void deinitialize(); - - /** - * Gets the MonsterClass having the given ID. - */ - MonsterClass *getMonster(int id); - - private: - - typedef std::map< int, MonsterClass * > MonsterClasses; - MonsterClasses mMonsterClasses; /**< Monster reference */ - - std::string mMonsterReferenceFile; -}; - -extern MonsterManager *monsterManager; - -#endif // MONSTERMANAGER_HPP diff --git a/src/game-server/npc.cpp b/src/game-server/npc.cpp index e22f7f23..c1b91d66 100644 --- a/src/game-server/npc.cpp +++ b/src/game-server/npc.cpp @@ -18,9 +18,9 @@ * along with The Mana Server. If not, see . */ -#include "game-server/character.hpp" -#include "game-server/npc.hpp" -#include "scripting/script.hpp" +#include "game-server/character.h" +#include "game-server/npc.h" +#include "scripting/script.h" NPC::NPC(const std::string &name, int id, Script *s): Being(OBJECT_NPC), diff --git a/src/game-server/npc.h b/src/game-server/npc.h new file mode 100644 index 00000000..02b26a72 --- /dev/null +++ b/src/game-server/npc.h @@ -0,0 +1,90 @@ +/* + * The Mana Server + * Copyright (C) 2007-2010 The Mana World Development Team + * + * This file is part of The Mana Server. + * + * The Mana Server 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 + * any later version. + * + * The Mana Server 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 The Mana Server. If not, see . + */ + +#ifndef GAMESERVER_NPC_H +#define GAMESERVER_NPC_H + +#include "game-server/being.h" + +class Script; +class Character; + +/** + * Class describing a non-player character. + */ +class NPC : public Being +{ + public: + NPC(const std::string &name, int id, Script *); + + void update(); + + /** + * Enables the NPC + */ + void enable(bool enabled); + + /** + * Prompts NPC. + */ + void prompt(Character *, bool restart); + + /** + * Selects an NPC proposition. + */ + void select(Character *, int); + + /** + * The player has choosen an integer. + */ + void integerReceived(Character *ch, int v); + + /** + * The player has entered an string. + */ + void stringReceived(Character *ch, const std::string &v); + + /** + * Gets NPC ID. + */ + int getNPC() const + { return mID; } + + /** + * Gets the way an NPC is blocked by other things on the map + */ + virtual unsigned char getWalkMask() const + { return 0x83; } // blocked like a monster by walls, monsters and characters ( bin 1000 0011) + + protected: + + /** + * Gets the way a monster blocks pathfinding for other objects + */ + virtual Map::BlockType getBlockType() const + { return Map::BLOCKTYPE_CHARACTER; } //blocks like a player character + + private: + Script *mScript; /**< Script describing NPC behavior. */ + unsigned short mID; /**< ID of the NPC. */ + bool mEnabled; /**< Whether NPC is enabled */ +}; + +#endif diff --git a/src/game-server/npc.hpp b/src/game-server/npc.hpp deleted file mode 100644 index f8dd2c33..00000000 --- a/src/game-server/npc.hpp +++ /dev/null @@ -1,90 +0,0 @@ -/* - * The Mana Server - * Copyright (C) 2007-2010 The Mana World Development Team - * - * This file is part of The Mana Server. - * - * The Mana Server 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 - * any later version. - * - * The Mana Server 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 The Mana Server. If not, see . - */ - -#ifndef GAMESERVER_NPC_HPP -#define GAMESERVER_NPC_HPP - -#include "game-server/being.hpp" - -class Script; -class Character; - -/** - * Class describing a non-player character. - */ -class NPC : public Being -{ - public: - NPC(const std::string &name, int id, Script *); - - void update(); - - /** - * Enables the NPC - */ - void enable(bool enabled); - - /** - * Prompts NPC. - */ - void prompt(Character *, bool restart); - - /** - * Selects an NPC proposition. - */ - void select(Character *, int); - - /** - * The player has choosen an integer. - */ - void integerReceived(Character *ch, int v); - - /** - * The player has entered an string. - */ - void stringReceived(Character *ch, const std::string &v); - - /** - * Gets NPC ID. - */ - int getNPC() const - { return mID; } - - /** - * Gets the way an NPC is blocked by other things on the map - */ - virtual unsigned char getWalkMask() const - { return 0x83; } // blocked like a monster by walls, monsters and characters ( bin 1000 0011) - - protected: - - /** - * Gets the way a monster blocks pathfinding for other objects - */ - virtual Map::BlockType getBlockType() const - { return Map::BLOCKTYPE_CHARACTER; } //blocks like a player character - - private: - Script *mScript; /**< Script describing NPC behavior. */ - unsigned short mID; /**< ID of the NPC. */ - bool mEnabled; /**< Whether NPC is enabled */ -}; - -#endif diff --git a/src/game-server/postman.h b/src/game-server/postman.h new file mode 100644 index 00000000..82b7a5a7 --- /dev/null +++ b/src/game-server/postman.h @@ -0,0 +1,78 @@ +/* + * The Mana Server + * Copyright (C) 2008-2010 The Mana World Development Team + * + * This file is part of The Mana Server. + * + * The Mana Server 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 + * any later version. + * + * The Mana Server 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 The Mana Server. If not, see . + */ + +#ifndef POSTMAN_H +#define POSTMAN_H + +#include +#include + +class Character; + +struct PostCallback +{ + void (*handler)(Character *, const std::string &sender, + const std::string &letter, void *data); + void *data; +}; + +class PostMan +{ +public: + Character *getCharacter(int id) const + { + std::map::const_iterator itr = mCharacters.find(id); + if (itr != mCharacters.end()) + return itr->second; + return 0; + } + + void addCharacter(Character *player) + { + std::map::iterator itr = mCharacters.find(player->getDatabaseID()); + if (itr == mCharacters.end()) + { + mCharacters.insert(std::pair(player->getDatabaseID(), player)); + } + } + + void getPost(Character *player, PostCallback &f) + { + mCallbacks.insert(std::pair(player, f)); + accountHandler->getPost(player); + } + + void gotPost(Character *player, std::string sender, std::string letter) + { + std::map::iterator itr = mCallbacks.find(player); + if (itr != mCallbacks.end()) + { + itr->second.handler(player, sender, letter, itr->second.data); + } + } + +private: + std::map mCharacters; + std::map mCallbacks; +}; + +extern PostMan *postMan; + +#endif diff --git a/src/game-server/postman.hpp b/src/game-server/postman.hpp deleted file mode 100644 index 82b7a5a7..00000000 --- a/src/game-server/postman.hpp +++ /dev/null @@ -1,78 +0,0 @@ -/* - * The Mana Server - * Copyright (C) 2008-2010 The Mana World Development Team - * - * This file is part of The Mana Server. - * - * The Mana Server 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 - * any later version. - * - * The Mana Server 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 The Mana Server. If not, see . - */ - -#ifndef POSTMAN_H -#define POSTMAN_H - -#include -#include - -class Character; - -struct PostCallback -{ - void (*handler)(Character *, const std::string &sender, - const std::string &letter, void *data); - void *data; -}; - -class PostMan -{ -public: - Character *getCharacter(int id) const - { - std::map::const_iterator itr = mCharacters.find(id); - if (itr != mCharacters.end()) - return itr->second; - return 0; - } - - void addCharacter(Character *player) - { - std::map::iterator itr = mCharacters.find(player->getDatabaseID()); - if (itr == mCharacters.end()) - { - mCharacters.insert(std::pair(player->getDatabaseID(), player)); - } - } - - void getPost(Character *player, PostCallback &f) - { - mCallbacks.insert(std::pair(player, f)); - accountHandler->getPost(player); - } - - void gotPost(Character *player, std::string sender, std::string letter) - { - std::map::iterator itr = mCallbacks.find(player); - if (itr != mCallbacks.end()) - { - itr->second.handler(player, sender, letter, itr->second.data); - } - } - -private: - std::map mCharacters; - std::map mCallbacks; -}; - -extern PostMan *postMan; - -#endif diff --git a/src/game-server/quest.cpp b/src/game-server/quest.cpp index d1e1b524..0a7b02f9 100644 --- a/src/game-server/quest.cpp +++ b/src/game-server/quest.cpp @@ -23,11 +23,11 @@ #include #include -#include "game-server/quest.hpp" +#include "game-server/quest.h" -#include "game-server/accountconnection.hpp" -#include "game-server/character.hpp" -#include "game-server/eventlistener.hpp" +#include "game-server/accountconnection.h" +#include "game-server/character.h" +#include "game-server/eventlistener.h" #include "utils/logger.h" typedef std::list< QuestCallback > QuestCallbacks; diff --git a/src/game-server/quest.h b/src/game-server/quest.h new file mode 100644 index 00000000..56fa5c2a --- /dev/null +++ b/src/game-server/quest.h @@ -0,0 +1,60 @@ +/* + * The Mana Server + * Copyright (C) 2007-2010 The Mana World Development Team + * + * This file is part of The Mana Server. + * + * The Mana Server 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 + * any later version. + * + * The Mana Server 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 The Mana Server. If not, see . + */ + +#ifndef GAMESERVER_QUEST_H +#define GAMESERVER_QUEST_H + +#include + +class Character; + +struct QuestCallback +{ + void (*handler)(Character *, const std::string &name, + const std::string &value, void *data); + void *data; +}; + +/** + * Gets the value associated to a quest variable. + * @return false if no value was in cache. + */ +bool getQuestVar(Character *, const std::string &name, std::string &value); + +/** + * Sets the value associated to a quest variable. + */ +void setQuestVar(Character *, const std::string &name, + const std::string &value); + +/** + * Starts the recovery of a variable and returns immediatly. The callback will + * be called once the value has been recovered. + */ +void recoverQuestVar(Character *, const std::string &name, + const QuestCallback &); + +/** + * Called by the handler of the account server when a value is received. + */ +void recoveredQuestVar(int id, const std::string &name, + const std::string &value); + +#endif diff --git a/src/game-server/quest.hpp b/src/game-server/quest.hpp deleted file mode 100644 index e3a9f34b..00000000 --- a/src/game-server/quest.hpp +++ /dev/null @@ -1,60 +0,0 @@ -/* - * The Mana Server - * Copyright (C) 2007-2010 The Mana World Development Team - * - * This file is part of The Mana Server. - * - * The Mana Server 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 - * any later version. - * - * The Mana Server 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 The Mana Server. If not, see . - */ - -#ifndef GAMESERVER_QUEST_HPP -#define GAMESERVER_QUEST_HPP - -#include - -class Character; - -struct QuestCallback -{ - void (*handler)(Character *, const std::string &name, - const std::string &value, void *data); - void *data; -}; - -/** - * Gets the value associated to a quest variable. - * @return false if no value was in cache. - */ -bool getQuestVar(Character *, const std::string &name, std::string &value); - -/** - * Sets the value associated to a quest variable. - */ -void setQuestVar(Character *, const std::string &name, - const std::string &value); - -/** - * Starts the recovery of a variable and returns immediatly. The callback will - * be called once the value has been recovered. - */ -void recoverQuestVar(Character *, const std::string &name, - const QuestCallback &); - -/** - * Called by the handler of the account server when a value is received. - */ -void recoveredQuestVar(int id, const std::string &name, - const std::string &value); - -#endif diff --git a/src/game-server/skillmanager.cpp b/src/game-server/skillmanager.cpp index 2cfcba58..d15219a4 100644 --- a/src/game-server/skillmanager.cpp +++ b/src/game-server/skillmanager.cpp @@ -18,12 +18,12 @@ * along with The Mana Server. If not, see . */ -#include "game-server/skillmanager.hpp" +#include "game-server/skillmanager.h" -#include "common/resourcemanager.hpp" -#include "utils/string.hpp" // for the toUpper function +#include "common/resourcemanager.h" +#include "utils/string.h" // for the toUpper function #include "utils/logger.h" -#include "utils/xml.hpp" +#include "utils/xml.h" #include diff --git a/src/game-server/skillmanager.h b/src/game-server/skillmanager.h new file mode 100644 index 00000000..c6a73a5c --- /dev/null +++ b/src/game-server/skillmanager.h @@ -0,0 +1,48 @@ +/* + * The Mana Server + * Copyright (C) 2004-2010 The Mana World Development Team + * + * This file is part of The Mana Server. + * + * The Mana Server 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 + * any later version. + * + * The Mana Server 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 The Mana Server. If not, see . + */ + + +#ifndef SKILLMANAGER_H +#define SKILLMANAGER_H + +#include + +namespace SkillManager +{ + /** + * Loads skill reference file. + */ + void initialize(const std::string &); + + /** + * Reloads skill reference file. + */ + void reload(); + + /** + * Gets the skill ID of a skill string + * (not case-sensitive to reduce wall-bashing) + */ + int getIdFromString(const std::string &name); +} + + + +#endif // SKILLMANAGER_H diff --git a/src/game-server/skillmanager.hpp b/src/game-server/skillmanager.hpp deleted file mode 100644 index c6a73a5c..00000000 --- a/src/game-server/skillmanager.hpp +++ /dev/null @@ -1,48 +0,0 @@ -/* - * The Mana Server - * Copyright (C) 2004-2010 The Mana World Development Team - * - * This file is part of The Mana Server. - * - * The Mana Server 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 - * any later version. - * - * The Mana Server 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 The Mana Server. If not, see . - */ - - -#ifndef SKILLMANAGER_H -#define SKILLMANAGER_H - -#include - -namespace SkillManager -{ - /** - * Loads skill reference file. - */ - void initialize(const std::string &); - - /** - * Reloads skill reference file. - */ - void reload(); - - /** - * Gets the skill ID of a skill string - * (not case-sensitive to reduce wall-bashing) - */ - int getIdFromString(const std::string &name); -} - - - -#endif // SKILLMANAGER_H diff --git a/src/game-server/spawnarea.cpp b/src/game-server/spawnarea.cpp index 105523cf..43e3a937 100644 --- a/src/game-server/spawnarea.cpp +++ b/src/game-server/spawnarea.cpp @@ -18,11 +18,11 @@ * along with The Mana Server. If not, see . */ -#include "game-server/spawnarea.hpp" +#include "game-server/spawnarea.h" -#include "game-server/mapcomposite.hpp" -#include "game-server/monster.hpp" -#include "game-server/state.hpp" +#include "game-server/mapcomposite.h" +#include "game-server/monster.h" +#include "game-server/state.h" #include "utils/logger.h" struct SpawnAreaEventDispatch : EventDispatch diff --git a/src/game-server/spawnarea.h b/src/game-server/spawnarea.h new file mode 100644 index 00000000..d3b2fd08 --- /dev/null +++ b/src/game-server/spawnarea.h @@ -0,0 +1,60 @@ +/* + * The Mana Server + * Copyright (C) 2006-2010 The Mana World Development Team + * + * This file is part of The Mana Server. + * + * The Mana Server 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 + * any later version. + * + * The Mana Server 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 The Mana Server. If not, see . + */ + +#ifndef SPAWNAREA_H +#define SPAWNAREA_H + +#include "point.h" +#include "game-server/eventlistener.h" +#include "game-server/thing.h" + +class Being; +class MonsterClass; + +/** + * A spawn area, where monsters spawn. The area is a rectangular field and will + * spawn a certain number of a given monster type. + */ +class SpawnArea : public Thing +{ + public: + SpawnArea(MapComposite *, MonsterClass *, const Rectangle &zone, + int maxBeings, int spawnRate); + + void update(); + + /** + * Keeps track of the number of spawned being. + */ + void decrease(Thing *); + + private: + MonsterClass *mSpecy; /**< Specy of monster that spawns in this area. */ + EventListener mSpawnedListener; /**< Tracking of spawned monsters. */ + Rectangle mZone; + int mMaxBeings; /**< Maximum population of this area. */ + int mSpawnRate; /**< Number of beings spawning per minute. */ + int mNumBeings; /**< Current population of this area. */ + int mNextSpawn; /**< The time until next being spawn. */ + + friend struct SpawnAreaEventDispatch; +}; + +#endif diff --git a/src/game-server/spawnarea.hpp b/src/game-server/spawnarea.hpp deleted file mode 100644 index e04d69e2..00000000 --- a/src/game-server/spawnarea.hpp +++ /dev/null @@ -1,60 +0,0 @@ -/* - * The Mana Server - * Copyright (C) 2006-2010 The Mana World Development Team - * - * This file is part of The Mana Server. - * - * The Mana Server 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 - * any later version. - * - * The Mana Server 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 The Mana Server. If not, see . - */ - -#ifndef SPAWNAREA_HPP -#define SPAWNAREA_HPP - -#include "point.h" -#include "game-server/eventlistener.hpp" -#include "game-server/thing.hpp" - -class Being; -class MonsterClass; - -/** - * A spawn area, where monsters spawn. The area is a rectangular field and will - * spawn a certain number of a given monster type. - */ -class SpawnArea : public Thing -{ - public: - SpawnArea(MapComposite *, MonsterClass *, const Rectangle &zone, - int maxBeings, int spawnRate); - - void update(); - - /** - * Keeps track of the number of spawned being. - */ - void decrease(Thing *); - - private: - MonsterClass *mSpecy; /**< Specy of monster that spawns in this area. */ - EventListener mSpawnedListener; /**< Tracking of spawned monsters. */ - Rectangle mZone; - int mMaxBeings; /**< Maximum population of this area. */ - int mSpawnRate; /**< Number of beings spawning per minute. */ - int mNumBeings; /**< Current population of this area. */ - int mNextSpawn; /**< The time until next being spawn. */ - - friend struct SpawnAreaEventDispatch; -}; - -#endif diff --git a/src/game-server/state.cpp b/src/game-server/state.cpp index 0c3121ca..c652549b 100644 --- a/src/game-server/state.cpp +++ b/src/game-server/state.cpp @@ -20,26 +20,26 @@ #include -#include "game-server/state.hpp" +#include "game-server/state.h" #include "point.h" -#include "common/configuration.hpp" -#include "game-server/accountconnection.hpp" -#include "game-server/gamehandler.hpp" -#include "game-server/inventory.hpp" -#include "game-server/item.hpp" -#include "game-server/itemmanager.hpp" -#include "game-server/effect.hpp" -#include "game-server/map.hpp" -#include "game-server/mapcomposite.hpp" -#include "game-server/mapmanager.hpp" -#include "game-server/monster.hpp" -#include "game-server/npc.hpp" -#include "game-server/trade.hpp" -#include "net/messageout.hpp" -#include "scripting/script.hpp" +#include "common/configuration.h" +#include "game-server/accountconnection.h" +#include "game-server/gamehandler.h" +#include "game-server/inventory.h" +#include "game-server/item.h" +#include "game-server/itemmanager.h" +#include "game-server/effect.h" +#include "game-server/map.h" +#include "game-server/mapcomposite.h" +#include "game-server/mapmanager.h" +#include "game-server/monster.h" +#include "game-server/npc.h" +#include "game-server/trade.h" +#include "net/messageout.h" +#include "scripting/script.h" #include "utils/logger.h" -#include "utils/speedconv.hpp" +#include "utils/speedconv.h" enum { diff --git a/src/game-server/state.h b/src/game-server/state.h new file mode 100644 index 00000000..f58ab038 --- /dev/null +++ b/src/game-server/state.h @@ -0,0 +1,108 @@ +/* + * The Mana Server + * Copyright (C) 2004-2010 The Mana World Development Team + * + * This file is part of The Mana Server. + * + * The Mana Server 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 + * any later version. + * + * The Mana Server 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 The Mana Server. If not, see . + */ + +#ifndef SERVER_STATE_H +#define SERVER_STATE_H + +#include + +class MapComposite; +class Thing; +class Actor; +class Character; + +namespace GameState +{ + /** + * Updates game state (contains core server logic). + */ + void update(int worldTime); + + /** + * Inserts an thing in the game world. + * @return false if the insertion failed and the thing is in limbo. + * @note No update may be in progress. + */ + bool insert(Thing *) +# ifdef __GNUC__ + __attribute__((warn_unused_result)) +# endif + ; + + /** + * Inserts a thing in the game world. Deletes the thing if the insertion + * failed. + * @return false if the insertion failed. + * @note No update may be in progress. Invalid for characters. + */ + bool insertSafe(Thing *); + + /** + * Removes a thing from the game world. + * @note No update may be in progress. + * @note The thing is not destroyed by this call. + */ + void remove(Thing *); + + /** + * Warps a character between places of the game world. + * @note No update may be in progress. + * @note The character is destroyed, if needed. + */ + void warp(Character *, MapComposite *, int x, int y); + + /** + * Enqueues an insert event. + * @note The event will be executed at end of update. + */ + void enqueueInsert(Actor *); + + /** + * Enqueues a remove event. + * @note The event will be executed at end of update. + * @note The thing will be destroyed at that time. + */ + void enqueueRemove(Actor *); + + /** + * Enqueues a warp event. + * @note The event will be executed at end of update. + */ + void enqueueWarp(Character *, MapComposite *, int x, int y); + + /** + * Says something to an actor. + * @note passing NULL as source generates a message from "Server:" + */ + void sayTo(Actor *destination, Actor *source, const std::string &text); + + /** + * Says something to everything around an actor. + */ + void sayAround(Actor *, const std::string &text); + + /** + * Says something to every player on the server. + */ + void sayToAll(const std::string &text); + +} + +#endif diff --git a/src/game-server/state.hpp b/src/game-server/state.hpp deleted file mode 100644 index c0ddc028..00000000 --- a/src/game-server/state.hpp +++ /dev/null @@ -1,108 +0,0 @@ -/* - * The Mana Server - * Copyright (C) 2004-2010 The Mana World Development Team - * - * This file is part of The Mana Server. - * - * The Mana Server 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 - * any later version. - * - * The Mana Server 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 The Mana Server. If not, see . - */ - -#ifndef SERVER_STATE_HPP -#define SERVER_STATE_HPP - -#include - -class MapComposite; -class Thing; -class Actor; -class Character; - -namespace GameState -{ - /** - * Updates game state (contains core server logic). - */ - void update(int worldTime); - - /** - * Inserts an thing in the game world. - * @return false if the insertion failed and the thing is in limbo. - * @note No update may be in progress. - */ - bool insert(Thing *) -# ifdef __GNUC__ - __attribute__((warn_unused_result)) -# endif - ; - - /** - * Inserts a thing in the game world. Deletes the thing if the insertion - * failed. - * @return false if the insertion failed. - * @note No update may be in progress. Invalid for characters. - */ - bool insertSafe(Thing *); - - /** - * Removes a thing from the game world. - * @note No update may be in progress. - * @note The thing is not destroyed by this call. - */ - void remove(Thing *); - - /** - * Warps a character between places of the game world. - * @note No update may be in progress. - * @note The character is destroyed, if needed. - */ - void warp(Character *, MapComposite *, int x, int y); - - /** - * Enqueues an insert event. - * @note The event will be executed at end of update. - */ - void enqueueInsert(Actor *); - - /** - * Enqueues a remove event. - * @note The event will be executed at end of update. - * @note The thing will be destroyed at that time. - */ - void enqueueRemove(Actor *); - - /** - * Enqueues a warp event. - * @note The event will be executed at end of update. - */ - void enqueueWarp(Character *, MapComposite *, int x, int y); - - /** - * Says something to an actor. - * @note passing NULL as source generates a message from "Server:" - */ - void sayTo(Actor *destination, Actor *source, const std::string &text); - - /** - * Says something to everything around an actor. - */ - void sayAround(Actor *, const std::string &text); - - /** - * Says something to every player on the server. - */ - void sayToAll(const std::string &text); - -} - -#endif diff --git a/src/game-server/statuseffect.cpp b/src/game-server/statuseffect.cpp index f201927e..9f917110 100644 --- a/src/game-server/statuseffect.cpp +++ b/src/game-server/statuseffect.cpp @@ -18,10 +18,10 @@ * along with The Mana Server. If not, see . */ -#include "game-server/statuseffect.hpp" +#include "game-server/statuseffect.h" -#include "scripting/script.hpp" -#include "game-server/being.hpp" +#include "scripting/script.h" +#include "game-server/being.h" StatusEffect::StatusEffect(int id): mId(id), diff --git a/src/game-server/statuseffect.h b/src/game-server/statuseffect.h new file mode 100644 index 00000000..3aa4d843 --- /dev/null +++ b/src/game-server/statuseffect.h @@ -0,0 +1,46 @@ +/* + * The Mana Server + * Copyright (C) 2004-2010 The Mana World Development Team + * + * This file is part of The Mana Server. + * + * The Mana Server 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 + * any later version. + * + * The Mana Server 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 The Mana Server. If not, see . + */ + +#ifndef STATUSEFFECT_H +#define STATUSEFFECT_H + +class Script; +class Being; + +class StatusEffect +{ + public: + StatusEffect(int id); + ~StatusEffect(); + + void tick(Being *target, int count); + + int getId() const + { return mId; } + + void setScript(Script *script) + { mScript = script; } + + private: + int mId; + Script *mScript; +}; + +#endif diff --git a/src/game-server/statuseffect.hpp b/src/game-server/statuseffect.hpp deleted file mode 100644 index 3aa4d843..00000000 --- a/src/game-server/statuseffect.hpp +++ /dev/null @@ -1,46 +0,0 @@ -/* - * The Mana Server - * Copyright (C) 2004-2010 The Mana World Development Team - * - * This file is part of The Mana Server. - * - * The Mana Server 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 - * any later version. - * - * The Mana Server 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 The Mana Server. If not, see . - */ - -#ifndef STATUSEFFECT_H -#define STATUSEFFECT_H - -class Script; -class Being; - -class StatusEffect -{ - public: - StatusEffect(int id); - ~StatusEffect(); - - void tick(Being *target, int count); - - int getId() const - { return mId; } - - void setScript(Script *script) - { mScript = script; } - - private: - int mId; - Script *mScript; -}; - -#endif diff --git a/src/game-server/statusmanager.cpp b/src/game-server/statusmanager.cpp index 008e9827..5e9bfcb6 100644 --- a/src/game-server/statusmanager.cpp +++ b/src/game-server/statusmanager.cpp @@ -18,13 +18,13 @@ * along with The Mana Server. If not, see . */ -#include "game-server/statusmanager.hpp" +#include "game-server/statusmanager.h" -#include "common/resourcemanager.hpp" -#include "game-server/statuseffect.hpp" -#include "scripting/script.hpp" +#include "common/resourcemanager.h" +#include "game-server/statuseffect.h" +#include "scripting/script.h" #include "utils/logger.h" -#include "utils/xml.hpp" +#include "utils/xml.h" #include #include diff --git a/src/game-server/statusmanager.h b/src/game-server/statusmanager.h new file mode 100644 index 00000000..fc09adb5 --- /dev/null +++ b/src/game-server/statusmanager.h @@ -0,0 +1,51 @@ +/* + * The Mana Server + * Copyright (C) 2004-2010 The Mana World Development Team + * + * This file is part of The Mana Server. + * + * The Mana Server 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 + * any later version. + * + * The Mana Server 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 The Mana Server. If not, see . + */ + +#ifndef STATUSMANAGER_H +#define STATUSMANAGER_H + +#include + +class StatusEffect; + +namespace StatusManager +{ + /** + * Loads status reference file. + */ + void initialize(const std::string &); + + /** + * Reloads status reference file. + */ + void reload(); + + /** + * Destroy status classes. + */ + void deinitialize(); + + /** + * Gets the status having the given ID. + */ + StatusEffect *getStatus(int statusId); +} + +#endif // STATUSMANAGER_H diff --git a/src/game-server/statusmanager.hpp b/src/game-server/statusmanager.hpp deleted file mode 100644 index fc09adb5..00000000 --- a/src/game-server/statusmanager.hpp +++ /dev/null @@ -1,51 +0,0 @@ -/* - * The Mana Server - * Copyright (C) 2004-2010 The Mana World Development Team - * - * This file is part of The Mana Server. - * - * The Mana Server 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 - * any later version. - * - * The Mana Server 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 The Mana Server. If not, see . - */ - -#ifndef STATUSMANAGER_H -#define STATUSMANAGER_H - -#include - -class StatusEffect; - -namespace StatusManager -{ - /** - * Loads status reference file. - */ - void initialize(const std::string &); - - /** - * Reloads status reference file. - */ - void reload(); - - /** - * Destroy status classes. - */ - void deinitialize(); - - /** - * Gets the status having the given ID. - */ - StatusEffect *getStatus(int statusId); -} - -#endif // STATUSMANAGER_H diff --git a/src/game-server/thing.cpp b/src/game-server/thing.cpp index 70d2c4c4..5fe94249 100644 --- a/src/game-server/thing.cpp +++ b/src/game-server/thing.cpp @@ -20,9 +20,9 @@ #include -#include "game-server/thing.hpp" +#include "game-server/thing.h" -#include "game-server/eventlistener.hpp" +#include "game-server/eventlistener.h" Thing::~Thing() { diff --git a/src/game-server/thing.h b/src/game-server/thing.h new file mode 100644 index 00000000..f1f0df28 --- /dev/null +++ b/src/game-server/thing.h @@ -0,0 +1,121 @@ +/* + * The Mana Server + * Copyright (C) 2004-2010 The Mana World Development Team + * + * This file is part of The Mana Server. + * + * The Mana Server 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 + * any later version. + * + * The Mana Server 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 The Mana Server. If not, see . + */ + +#ifndef THING_H +#define THING_H + +#include "protocol.h" + +#include + +class EventListener; +class MapComposite; + +/** + * Base class for in-game objects. Knows only its type and the map it resides + * on. Provides listeners. + */ +class Thing +{ + public: + /** + * Constructor. + */ + Thing(ThingType type, MapComposite *map = NULL) + : mMap(map), + mType(type) + {} + + virtual ~Thing(); + + /** + * Gets type of this thing. + * + * @return the type of this thing. + */ + ThingType getType() const + { return mType; } + + /** + * Returns whether this thing is visible on the map or not. (Actor) + */ + bool isVisible() const + { return mType != OBJECT_OTHER; } + + /** + * Returns whether this thing can move on the map or not. (Actor) + */ + bool canMove() const + { return mType == OBJECT_CHARACTER || mType == OBJECT_MONSTER || + mType == OBJECT_NPC; } + + /** + * Returns whether this thing can fight or not. (Being) + */ + bool canFight() const + { return mType == OBJECT_CHARACTER || mType == OBJECT_MONSTER; } + + /** + * Updates the internal status. + */ + virtual void update() = 0; + + /** + * Gets the map this thing is located on. + */ + MapComposite *getMap() const + { return mMap; } + + /** + * Sets the map this thing is located on. + */ + virtual void setMap(MapComposite *map) + { mMap = map; } + + /** + * Adds a new listener. + */ + void addListener(const EventListener *); + + /** + * Removes an existing listener. + */ + void removeListener(const EventListener *); + + /** + * Calls all the "inserted" listeners. + */ + virtual void inserted(); + + /** + * Calls all the "removed" listeners. + */ + virtual void removed(); + + protected: + typedef std::set< const EventListener * > Listeners; + Listeners mListeners; /**< List of event listeners. */ + + private: + MapComposite *mMap; /**< Map the thing is on */ + ThingType mType; /**< Type of this thing. */ +}; + +#endif // THING_H diff --git a/src/game-server/thing.hpp b/src/game-server/thing.hpp deleted file mode 100644 index f1f0df28..00000000 --- a/src/game-server/thing.hpp +++ /dev/null @@ -1,121 +0,0 @@ -/* - * The Mana Server - * Copyright (C) 2004-2010 The Mana World Development Team - * - * This file is part of The Mana Server. - * - * The Mana Server 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 - * any later version. - * - * The Mana Server 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 The Mana Server. If not, see . - */ - -#ifndef THING_H -#define THING_H - -#include "protocol.h" - -#include - -class EventListener; -class MapComposite; - -/** - * Base class for in-game objects. Knows only its type and the map it resides - * on. Provides listeners. - */ -class Thing -{ - public: - /** - * Constructor. - */ - Thing(ThingType type, MapComposite *map = NULL) - : mMap(map), - mType(type) - {} - - virtual ~Thing(); - - /** - * Gets type of this thing. - * - * @return the type of this thing. - */ - ThingType getType() const - { return mType; } - - /** - * Returns whether this thing is visible on the map or not. (Actor) - */ - bool isVisible() const - { return mType != OBJECT_OTHER; } - - /** - * Returns whether this thing can move on the map or not. (Actor) - */ - bool canMove() const - { return mType == OBJECT_CHARACTER || mType == OBJECT_MONSTER || - mType == OBJECT_NPC; } - - /** - * Returns whether this thing can fight or not. (Being) - */ - bool canFight() const - { return mType == OBJECT_CHARACTER || mType == OBJECT_MONSTER; } - - /** - * Updates the internal status. - */ - virtual void update() = 0; - - /** - * Gets the map this thing is located on. - */ - MapComposite *getMap() const - { return mMap; } - - /** - * Sets the map this thing is located on. - */ - virtual void setMap(MapComposite *map) - { mMap = map; } - - /** - * Adds a new listener. - */ - void addListener(const EventListener *); - - /** - * Removes an existing listener. - */ - void removeListener(const EventListener *); - - /** - * Calls all the "inserted" listeners. - */ - virtual void inserted(); - - /** - * Calls all the "removed" listeners. - */ - virtual void removed(); - - protected: - typedef std::set< const EventListener * > Listeners; - Listeners mListeners; /**< List of event listeners. */ - - private: - MapComposite *mMap; /**< Map the thing is on */ - ThingType mType; /**< Type of this thing. */ -}; - -#endif // THING_H diff --git a/src/game-server/trade.cpp b/src/game-server/trade.cpp index 1c197c77..51509307 100644 --- a/src/game-server/trade.cpp +++ b/src/game-server/trade.cpp @@ -21,12 +21,12 @@ #include #include -#include "game-server/trade.hpp" +#include "game-server/trade.h" -#include "game-server/character.hpp" -#include "game-server/gamehandler.hpp" -#include "game-server/inventory.hpp" -#include "net/messageout.hpp" +#include "game-server/character.h" +#include "game-server/gamehandler.h" +#include "game-server/inventory.h" +#include "net/messageout.h" /* * States : diff --git a/src/game-server/trade.h b/src/game-server/trade.h new file mode 100644 index 00000000..d425767a --- /dev/null +++ b/src/game-server/trade.h @@ -0,0 +1,107 @@ +/* + * The Mana Server + * Copyright (C) 2007-2010 The Mana World Development Team + * + * This file is part of The Mana Server. + * + * The Mana Server 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 + * any later version. + * + * The Mana Server 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 The Mana Server. If not, see . + */ + +#ifndef GAMESERVER_TRADE_H +#define GAMESERVER_TRADE_H + +#include + +class Character; +class Inventory; + +class Trade +{ + public: + + /** + * Sets up a trade between two characters. + * Asks for an acknowledgment from the second one. + */ + Trade(Character *, Character *); + + /** + * Cancels a trade by a given character (optional). + * Warns the other character the trade is cancelled. + * Takes care of cleaning afterwards. + */ + void cancel(); + + /** + * Requests a trade to start with given public ID. + * Continues the current trade if the ID is correct, cancels it + * otherwise. + * @return true if the current trade keeps going. + */ + bool request(Character *, int); + + /** + * Confirm the trade. + */ + void confirm(Character *); + + /* + * Agree to complete the trade + */ + void agree(Character *c); + + /** + * Adds some items to the trade. + */ + void addItem(Character *, int slot, int amount); + + /** + * Adds some money to the trade. + */ + void setMoney(Character *, int amount); + + private: + + ~Trade(); + + struct TradedItem + { + unsigned short id; + unsigned char slot, amount; + }; + + typedef std::vector< TradedItem > TradedItems; + + /* + * See trade.cpp for doc on TradeStates + */ + enum TradeState + { + TRADE_INIT = 0, + TRADE_RUN, + TRADE_CONFIRM_WAIT, + TRADE_CONFIRMED, + TRADE_AGREE_WAIT + }; + + static bool perform(TradedItems items, Inventory &inv1, Inventory &inv2); + + Character *mChar1, *mChar2; /**< Characters involved. */ + TradedItems mItems1, mItems2; /**< Traded items. */ + int mMoney1, mMoney2; /**< Traded money. */ + TradeState mState; /**< State of transaction. */ + unsigned int mCurrencyId; /**< The attribute to use as currency. */ +}; + +#endif diff --git a/src/game-server/trade.hpp b/src/game-server/trade.hpp deleted file mode 100644 index a95e89c1..00000000 --- a/src/game-server/trade.hpp +++ /dev/null @@ -1,107 +0,0 @@ -/* - * The Mana Server - * Copyright (C) 2007-2010 The Mana World Development Team - * - * This file is part of The Mana Server. - * - * The Mana Server 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 - * any later version. - * - * The Mana Server 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 The Mana Server. If not, see . - */ - -#ifndef GAMESERVER_TRADE_HPP -#define GAMESERVER_TRADE_HPP - -#include - -class Character; -class Inventory; - -class Trade -{ - public: - - /** - * Sets up a trade between two characters. - * Asks for an acknowledgment from the second one. - */ - Trade(Character *, Character *); - - /** - * Cancels a trade by a given character (optional). - * Warns the other character the trade is cancelled. - * Takes care of cleaning afterwards. - */ - void cancel(); - - /** - * Requests a trade to start with given public ID. - * Continues the current trade if the ID is correct, cancels it - * otherwise. - * @return true if the current trade keeps going. - */ - bool request(Character *, int); - - /** - * Confirm the trade. - */ - void confirm(Character *); - - /* - * Agree to complete the trade - */ - void agree(Character *c); - - /** - * Adds some items to the trade. - */ - void addItem(Character *, int slot, int amount); - - /** - * Adds some money to the trade. - */ - void setMoney(Character *, int amount); - - private: - - ~Trade(); - - struct TradedItem - { - unsigned short id; - unsigned char slot, amount; - }; - - typedef std::vector< TradedItem > TradedItems; - - /* - * See trade.cpp for doc on TradeStates - */ - enum TradeState - { - TRADE_INIT = 0, - TRADE_RUN, - TRADE_CONFIRM_WAIT, - TRADE_CONFIRMED, - TRADE_AGREE_WAIT - }; - - static bool perform(TradedItems items, Inventory &inv1, Inventory &inv2); - - Character *mChar1, *mChar2; /**< Characters involved. */ - TradedItems mItems1, mItems2; /**< Traded items. */ - int mMoney1, mMoney2; /**< Traded money. */ - TradeState mState; /**< State of transaction. */ - unsigned int mCurrencyId; /**< The attribute to use as currency. */ -}; - -#endif diff --git a/src/game-server/trigger.cpp b/src/game-server/trigger.cpp index ce5cd33e..f25b00b8 100644 --- a/src/game-server/trigger.cpp +++ b/src/game-server/trigger.cpp @@ -18,12 +18,12 @@ * along with The Mana Server. If not, see . */ -#include "game-server/trigger.hpp" +#include "game-server/trigger.h" -#include "game-server/character.hpp" -#include "game-server/mapcomposite.hpp" -#include "game-server/actor.hpp" -#include "game-server/state.hpp" +#include "game-server/character.h" +#include "game-server/mapcomposite.h" +#include "game-server/actor.h" +#include "game-server/state.h" #include "utils/logger.h" diff --git a/src/game-server/trigger.h b/src/game-server/trigger.h new file mode 100644 index 00000000..f6649f1b --- /dev/null +++ b/src/game-server/trigger.h @@ -0,0 +1,82 @@ +/* + * The Mana Server + * Copyright (C) 2006-2010 The Mana World Development Team + * + * This file is part of The Mana Server. + * + * The Mana Server 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 + * any later version. + * + * The Mana Server 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 The Mana Server. If not, see . + */ + +#ifndef TRIGGER_H +#define TRIGGER_H + +#include "point.h" +#include "game-server/thing.h" +#include "scripting/script.h" + +class Actor; + +class TriggerAction +{ + public: + virtual ~TriggerAction() {} + virtual void process(Actor *obj) = 0; +}; + +class WarpAction : public TriggerAction +{ + public: + WarpAction(MapComposite *m, int x, int y) + : mMap(m), mX(x), mY(y) {} + + virtual void process(Actor *obj); + + private: + MapComposite *mMap; + unsigned short mX, mY; +}; + +class ScriptAction : public TriggerAction +{ + public: + ScriptAction(Script *script, const std::string &function, int arg) + : mScript(script), mFunction(function), mArg(arg) {} + + virtual void process(Actor *obj); + + private: + Script *mScript; // Script object to be called + std::string mFunction; // Name of the function called in the script object + int mArg; // Argument passed to script function (meaning is function-specific) +}; + +class TriggerArea : public Thing +{ + public: + /** + * Creates a rectangular trigger for a given map. + */ + TriggerArea(MapComposite *m, const Rectangle &r, TriggerAction *ptr, bool once) + : Thing(OBJECT_OTHER, m), mZone(r), mAction(ptr), mOnce(once) {} + + virtual void update(); + + private: + Rectangle mZone; + TriggerAction *mAction; + bool mOnce; + std::set mInside; +}; + +#endif diff --git a/src/game-server/trigger.hpp b/src/game-server/trigger.hpp deleted file mode 100644 index 0b5cb976..00000000 --- a/src/game-server/trigger.hpp +++ /dev/null @@ -1,82 +0,0 @@ -/* - * The Mana Server - * Copyright (C) 2006-2010 The Mana World Development Team - * - * This file is part of The Mana Server. - * - * The Mana Server 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 - * any later version. - * - * The Mana Server 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 The Mana Server. If not, see . - */ - -#ifndef TRIGGER_HPP -#define TRIGGER_HPP - -#include "point.h" -#include "game-server/thing.hpp" -#include "scripting/script.hpp" - -class Actor; - -class TriggerAction -{ - public: - virtual ~TriggerAction() {} - virtual void process(Actor *obj) = 0; -}; - -class WarpAction : public TriggerAction -{ - public: - WarpAction(MapComposite *m, int x, int y) - : mMap(m), mX(x), mY(y) {} - - virtual void process(Actor *obj); - - private: - MapComposite *mMap; - unsigned short mX, mY; -}; - -class ScriptAction : public TriggerAction -{ - public: - ScriptAction(Script *script, const std::string &function, int arg) - : mScript(script), mFunction(function), mArg(arg) {} - - virtual void process(Actor *obj); - - private: - Script *mScript; // Script object to be called - std::string mFunction; // Name of the function called in the script object - int mArg; // Argument passed to script function (meaning is function-specific) -}; - -class TriggerArea : public Thing -{ - public: - /** - * Creates a rectangular trigger for a given map. - */ - TriggerArea(MapComposite *m, const Rectangle &r, TriggerAction *ptr, bool once) - : Thing(OBJECT_OTHER, m), mZone(r), mAction(ptr), mOnce(once) {} - - virtual void update(); - - private: - Rectangle mZone; - TriggerAction *mAction; - bool mOnce; - std::set mInside; -}; - -#endif diff --git a/src/net/bandwidth.cpp b/src/net/bandwidth.cpp index ab6e930c..4d04b3b9 100644 --- a/src/net/bandwidth.cpp +++ b/src/net/bandwidth.cpp @@ -18,9 +18,9 @@ * along with The Mana Server. If not, see . */ -#include "bandwidth.hpp" +#include "bandwidth.h" -#include "netcomputer.hpp" +#include "netcomputer.h" BandwidthMonitor::BandwidthMonitor(): mAmountServerOutput(0), diff --git a/src/net/bandwidth.h b/src/net/bandwidth.h new file mode 100644 index 00000000..4ffeff73 --- /dev/null +++ b/src/net/bandwidth.h @@ -0,0 +1,53 @@ +/* + * The Mana Server + * Copyright (C) 2008-2010 The Mana World Development Team + * + * This file is part of The Mana Server. + * + * The Mana Server 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 + * any later version. + * + * The Mana Server 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 The Mana Server. If not, see . + */ + +#ifndef BANDWIDTH_H +#define BANDWIDTH_H + +#include + +class NetComputer; + +class BandwidthMonitor +{ +public: + BandwidthMonitor(); + void increaseInterServerOutput(int size); + void increaseInterServerInput(int size); + void increaseClientOutput(NetComputer *nc, int size); + void increaseClientInput(NetComputer *nc, int size); + int totalInterServerOut() const { return mAmountServerOutput; } + int totalInterServerIn() const { return mAmountServerInput; } + int totalClientOut() const { return mAmountClientOutput; } + int totalClientIn() const { return mAmountClientInput; } + +private: + int mAmountServerOutput; + int mAmountServerInput; + int mAmountClientOutput; + int mAmountClientInput; + // map of client to output and input + typedef std::map > ClientBandwidth; + ClientBandwidth mClientBandwidth; +}; + +extern BandwidthMonitor *gBandwidth; + +#endif diff --git a/src/net/bandwidth.hpp b/src/net/bandwidth.hpp deleted file mode 100644 index 4ffeff73..00000000 --- a/src/net/bandwidth.hpp +++ /dev/null @@ -1,53 +0,0 @@ -/* - * The Mana Server - * Copyright (C) 2008-2010 The Mana World Development Team - * - * This file is part of The Mana Server. - * - * The Mana Server 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 - * any later version. - * - * The Mana Server 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 The Mana Server. If not, see . - */ - -#ifndef BANDWIDTH_H -#define BANDWIDTH_H - -#include - -class NetComputer; - -class BandwidthMonitor -{ -public: - BandwidthMonitor(); - void increaseInterServerOutput(int size); - void increaseInterServerInput(int size); - void increaseClientOutput(NetComputer *nc, int size); - void increaseClientInput(NetComputer *nc, int size); - int totalInterServerOut() const { return mAmountServerOutput; } - int totalInterServerIn() const { return mAmountServerInput; } - int totalClientOut() const { return mAmountClientOutput; } - int totalClientIn() const { return mAmountClientInput; } - -private: - int mAmountServerOutput; - int mAmountServerInput; - int mAmountClientOutput; - int mAmountClientInput; - // map of client to output and input - typedef std::map > ClientBandwidth; - ClientBandwidth mClientBandwidth; -}; - -extern BandwidthMonitor *gBandwidth; - -#endif diff --git a/src/net/connection.cpp b/src/net/connection.cpp index aeda22a7..88c59f02 100644 --- a/src/net/connection.cpp +++ b/src/net/connection.cpp @@ -18,10 +18,10 @@ * along with The Mana Server. If not, see . */ -#include "net/connection.hpp" -#include "net/bandwidth.hpp" -#include "net/messagein.hpp" -#include "net/messageout.hpp" +#include "net/connection.h" +#include "net/bandwidth.h" +#include "net/messagein.h" +#include "net/messageout.h" #include "utils/logger.h" #ifdef ENET_VERSION_CREATE diff --git a/src/net/connection.h b/src/net/connection.h new file mode 100644 index 00000000..288d9fc2 --- /dev/null +++ b/src/net/connection.h @@ -0,0 +1,78 @@ +/* + * The Mana Server + * Copyright (C) 2006-2010 The Mana World Development Team + * + * This file is part of The Mana Server. + * + * The Mana Server 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 + * any later version. + * + * The Mana Server 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 The Mana Server. If not, see . + */ + +#ifndef CONNECTION_H +#define CONNECTION_H + +#include +#include + +class MessageIn; +class MessageOut; + +/** + * A point-to-point connection to a remote host. The remote host can use a + * ConnectionHandler to handle this incoming connection. + */ +class Connection +{ + public: + Connection(); + virtual ~Connection() {} + + /** + * Connects to the given host/port and waits until the connection is + * established. Returns false if it fails to connect. + */ + bool start(const std::string &, int); + + /** + * Disconnects. + */ + void stop(); + + /** + * Returns whether the connection is established or not. + */ + bool isConnected() const; + + /** + * Sends a message to the remote host. + */ + void send(const MessageOut &msg, bool reliable = true, + unsigned channel = 0); + + /** + * Dispatches received messages to processMessage. + */ + void process(); + + protected: + /** + * Processes a single message from the remote host. + */ + virtual void processMessage(MessageIn &) = 0; + + private: + ENetPeer *mRemote; + ENetHost *mLocal; +}; + +#endif diff --git a/src/net/connection.hpp b/src/net/connection.hpp deleted file mode 100644 index 288d9fc2..00000000 --- a/src/net/connection.hpp +++ /dev/null @@ -1,78 +0,0 @@ -/* - * The Mana Server - * Copyright (C) 2006-2010 The Mana World Development Team - * - * This file is part of The Mana Server. - * - * The Mana Server 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 - * any later version. - * - * The Mana Server 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 The Mana Server. If not, see . - */ - -#ifndef CONNECTION_H -#define CONNECTION_H - -#include -#include - -class MessageIn; -class MessageOut; - -/** - * A point-to-point connection to a remote host. The remote host can use a - * ConnectionHandler to handle this incoming connection. - */ -class Connection -{ - public: - Connection(); - virtual ~Connection() {} - - /** - * Connects to the given host/port and waits until the connection is - * established. Returns false if it fails to connect. - */ - bool start(const std::string &, int); - - /** - * Disconnects. - */ - void stop(); - - /** - * Returns whether the connection is established or not. - */ - bool isConnected() const; - - /** - * Sends a message to the remote host. - */ - void send(const MessageOut &msg, bool reliable = true, - unsigned channel = 0); - - /** - * Dispatches received messages to processMessage. - */ - void process(); - - protected: - /** - * Processes a single message from the remote host. - */ - virtual void processMessage(MessageIn &) = 0; - - private: - ENetPeer *mRemote; - ENetHost *mLocal; -}; - -#endif diff --git a/src/net/connectionhandler.cpp b/src/net/connectionhandler.cpp index ec786663..e9ec1944 100644 --- a/src/net/connectionhandler.cpp +++ b/src/net/connectionhandler.cpp @@ -20,13 +20,13 @@ #include -#include "net/connectionhandler.hpp" +#include "net/connectionhandler.h" -#include "common/configuration.hpp" -#include "net/bandwidth.hpp" -#include "net/messagein.hpp" -#include "net/messageout.hpp" -#include "net/netcomputer.hpp" +#include "common/configuration.h" +#include "net/bandwidth.h" +#include "net/messagein.h" +#include "net/messageout.h" +#include "net/netcomputer.h" #include "utils/logger.h" #ifdef ENET_VERSION_CREATE diff --git a/src/net/connectionhandler.h b/src/net/connectionhandler.h new file mode 100644 index 00000000..96fc90cd --- /dev/null +++ b/src/net/connectionhandler.h @@ -0,0 +1,121 @@ +/* + * The Mana Server + * Copyright (C) 2004-2010 The Mana World Development Team + * + * This file is part of The Mana Server. + * + * The Mana Server 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 + * any later version. + * + * The Mana Server 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 The Mana Server. If not, see . + */ + +#ifndef CONNECTIONHANDLER_H +#define CONNECTIONHANDLER_H + +#include +#include +#include + +class MessageIn; +class MessageOut; +class NetComputer; + +/** + * This class represents the connection handler interface. The connection + * handler will respond to connect/reconnect/disconnect events and handle + * incoming messages, passing them on to registered message handlers. + */ +class ConnectionHandler +{ + public: + virtual ~ConnectionHandler() {} + + /** + * Open the server socket. + * @param port the port to listen to + * @host the host IP to listen on, defaults to the default localhost + */ + bool startListen(enet_uint16 port, + const std::string &host = std::string()); + + /** + * Disconnect all the clients and close the server socket. + */ + void stopListen(); + + /** + * Process outgoing messages and listen to the server socket for + * incoming messages and new connections. + * + * @timeout an optional timeout in milliseconds to wait for something + * to happen when there is nothing to do + */ + virtual void process(enet_uint32 timeout = 0); + + /** + * Process outgoing messages. + */ + void flush(); + + /** + * Called when a computer sends a packet to the network session. + */ + //void receivePacket(NetComputer *computer, Packet *packet); + + /** + * Send packet to every client, used for announcements. + */ + void sendToEveryone(const MessageOut &msg); + + /** + * Return the number of connected clients. + */ + unsigned int getClientCount() const; + + private: + ENetAddress address; /**< Includes the port to listen to. */ + ENetHost *host; /**< The host that listen for connections. */ + + protected: + /** + * Called when a computer connects to the server. Initialize + * an object derived of NetComputer. + */ + virtual NetComputer *computerConnected(ENetPeer *peer) = 0; + + /** + * Called when a computer reconnects to the server. + */ + //virtual NetComputer *computerReconnected(ENetPeer *) = 0; + + /** + * Called when a computer disconnects from the server. + * + * Note: After returning from this method the NetComputer + * reference is no longer guaranteed to be valid. + */ + virtual void computerDisconnected(NetComputer *) = 0; + + /** + * Called when a message is received. + */ + virtual void processMessage(NetComputer *, MessageIn &) = 0; + + typedef std::list NetComputers; + /** + * A list of pointers to the client structures created by + * computerConnected. + */ + NetComputers clients; +}; + +#endif diff --git a/src/net/connectionhandler.hpp b/src/net/connectionhandler.hpp deleted file mode 100644 index 96fc90cd..00000000 --- a/src/net/connectionhandler.hpp +++ /dev/null @@ -1,121 +0,0 @@ -/* - * The Mana Server - * Copyright (C) 2004-2010 The Mana World Development Team - * - * This file is part of The Mana Server. - * - * The Mana Server 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 - * any later version. - * - * The Mana Server 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 The Mana Server. If not, see . - */ - -#ifndef CONNECTIONHANDLER_H -#define CONNECTIONHANDLER_H - -#include -#include -#include - -class MessageIn; -class MessageOut; -class NetComputer; - -/** - * This class represents the connection handler interface. The connection - * handler will respond to connect/reconnect/disconnect events and handle - * incoming messages, passing them on to registered message handlers. - */ -class ConnectionHandler -{ - public: - virtual ~ConnectionHandler() {} - - /** - * Open the server socket. - * @param port the port to listen to - * @host the host IP to listen on, defaults to the default localhost - */ - bool startListen(enet_uint16 port, - const std::string &host = std::string()); - - /** - * Disconnect all the clients and close the server socket. - */ - void stopListen(); - - /** - * Process outgoing messages and listen to the server socket for - * incoming messages and new connections. - * - * @timeout an optional timeout in milliseconds to wait for something - * to happen when there is nothing to do - */ - virtual void process(enet_uint32 timeout = 0); - - /** - * Process outgoing messages. - */ - void flush(); - - /** - * Called when a computer sends a packet to the network session. - */ - //void receivePacket(NetComputer *computer, Packet *packet); - - /** - * Send packet to every client, used for announcements. - */ - void sendToEveryone(const MessageOut &msg); - - /** - * Return the number of connected clients. - */ - unsigned int getClientCount() const; - - private: - ENetAddress address; /**< Includes the port to listen to. */ - ENetHost *host; /**< The host that listen for connections. */ - - protected: - /** - * Called when a computer connects to the server. Initialize - * an object derived of NetComputer. - */ - virtual NetComputer *computerConnected(ENetPeer *peer) = 0; - - /** - * Called when a computer reconnects to the server. - */ - //virtual NetComputer *computerReconnected(ENetPeer *) = 0; - - /** - * Called when a computer disconnects from the server. - * - * Note: After returning from this method the NetComputer - * reference is no longer guaranteed to be valid. - */ - virtual void computerDisconnected(NetComputer *) = 0; - - /** - * Called when a message is received. - */ - virtual void processMessage(NetComputer *, MessageIn &) = 0; - - typedef std::list NetComputers; - /** - * A list of pointers to the client structures created by - * computerConnected. - */ - NetComputers clients; -}; - -#endif diff --git a/src/net/messagein.cpp b/src/net/messagein.cpp index 7d6de273..022ac465 100644 --- a/src/net/messagein.cpp +++ b/src/net/messagein.cpp @@ -27,7 +27,7 @@ #include #endif -#include "net/messagein.hpp" +#include "net/messagein.h" #include "utils/logger.h" MessageIn::MessageIn(const char *data, int length): diff --git a/src/net/messagein.h b/src/net/messagein.h new file mode 100644 index 00000000..f01c1850 --- /dev/null +++ b/src/net/messagein.h @@ -0,0 +1,87 @@ +/* + * The Mana Server + * Copyright (C) 2004-2010 The Mana World Development Team + * + * This file is part of The Mana Server. + * + * The Mana Server 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 + * any later version. + * + * The Mana Server 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 The Mana Server. If not, see . + */ + +#ifndef MESSAGEIN_H +#define MESSAGEIN_H + +#include + +/** + * Used for parsing an incoming message. + */ +class MessageIn +{ + public: + /** + * Constructor. + */ + MessageIn(const char *data, int length); + + /** + * Returns the message ID. + */ + int getId() const { return mId; } + + /** + * Returns the total length of this message. + */ + int getLength() const { return mLength; } + + int readInt8(); /**< Reads a byte. */ + int readInt16(); /**< Reads a short. */ + int readInt32(); /**< Reads a long. */ + + /** + * Reads a double. HACKY and should *not* be used for client + * communication! + */ + double readDouble(); + + /** + * Reads a string. If a length is not given (-1), it is assumed + * that the length of the string is stored in a short at the + * start of the string. + */ + std::string readString(int length = -1); + + /** + * Returns the length of unread data. + */ + int getUnreadLength() const { return mLength - mPos; } + + private: + const char *mData; /**< Packet data */ + unsigned short mLength; /**< Length of data in bytes */ + unsigned short mId; /**< The message ID. */ + + /** + * Actual position in the packet. From 0 to packet->length. A value + * bigger than packet->length means EOP was reached when reading it. + */ + unsigned short mPos; + + /** + * Streams message ID and length to the given output stream. + */ + friend std::ostream& operator <<(std::ostream &os, + const MessageIn &msg); +}; + +#endif diff --git a/src/net/messagein.hpp b/src/net/messagein.hpp deleted file mode 100644 index f01c1850..00000000 --- a/src/net/messagein.hpp +++ /dev/null @@ -1,87 +0,0 @@ -/* - * The Mana Server - * Copyright (C) 2004-2010 The Mana World Development Team - * - * This file is part of The Mana Server. - * - * The Mana Server 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 - * any later version. - * - * The Mana Server 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 The Mana Server. If not, see . - */ - -#ifndef MESSAGEIN_H -#define MESSAGEIN_H - -#include - -/** - * Used for parsing an incoming message. - */ -class MessageIn -{ - public: - /** - * Constructor. - */ - MessageIn(const char *data, int length); - - /** - * Returns the message ID. - */ - int getId() const { return mId; } - - /** - * Returns the total length of this message. - */ - int getLength() const { return mLength; } - - int readInt8(); /**< Reads a byte. */ - int readInt16(); /**< Reads a short. */ - int readInt32(); /**< Reads a long. */ - - /** - * Reads a double. HACKY and should *not* be used for client - * communication! - */ - double readDouble(); - - /** - * Reads a string. If a length is not given (-1), it is assumed - * that the length of the string is stored in a short at the - * start of the string. - */ - std::string readString(int length = -1); - - /** - * Returns the length of unread data. - */ - int getUnreadLength() const { return mLength - mPos; } - - private: - const char *mData; /**< Packet data */ - unsigned short mLength; /**< Length of data in bytes */ - unsigned short mId; /**< The message ID. */ - - /** - * Actual position in the packet. From 0 to packet->length. A value - * bigger than packet->length means EOP was reached when reading it. - */ - unsigned short mPos; - - /** - * Streams message ID and length to the given output stream. - */ - friend std::ostream& operator <<(std::ostream &os, - const MessageIn &msg); -}; - -#endif diff --git a/src/net/messageout.cpp b/src/net/messageout.cpp index c8310c55..a5b0a53c 100644 --- a/src/net/messageout.cpp +++ b/src/net/messageout.cpp @@ -28,7 +28,7 @@ #include #include -#include "net/messageout.hpp" +#include "net/messageout.h" /** Initial amount of bytes allocated for the messageout data buffer. */ const unsigned int INITIAL_DATA_CAPACITY = 16; diff --git a/src/net/messageout.h b/src/net/messageout.h new file mode 100644 index 00000000..cf3e0c73 --- /dev/null +++ b/src/net/messageout.h @@ -0,0 +1,107 @@ +/* + * The Mana Server + * Copyright (C) 2004-2010 The Mana World Development Team + * + * This file is part of The Mana Server. + * + * The Mana Server 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 + * any later version. + * + * The Mana Server 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 The Mana Server. If not, see . + */ + +#ifndef MESSAGEOUT_H +#define MESSAGEOUT_H + +#include + +/** + * Used for building an outgoing message. + */ +class MessageOut +{ + public: + /** + * Constructor. + */ + MessageOut(); + + /** + * Constructor that takes a message ID. + */ + MessageOut(int id); + + /** + * Destructor. + */ + ~MessageOut(); + + /** + * Clears current message. + */ + void clear(); + + void writeInt8(int value); /**< Writes an integer on one byte. */ + + void writeInt16(int value); /**< Writes an integer on two bytes. */ + + void writeInt32(int value); /**< Writes an integer on four bytes. */ + + /** + * Writes a double. HACKY and should *not* be used for client + * communication! + */ + void writeDouble(double value); + + /** + * Writes a 3-byte block containing tile-based coordinates. + */ + void writeCoordinates(int x, int y); + + /** + * Writes a string. If a fixed length is not given (-1), it is stored + * as a short at the start of the string. + */ + void + writeString(const std::string &string, int length = -1); + + /** + * Returns the content of the message. + */ + char* + getData() const { return mData; } + + /** + * Returns the length of the data. + */ + unsigned int + getLength() const { return mPos; } + + private: + /** + * Ensures the capacity of the data buffer is large enough to hold the + * given amount of bytes. + */ + void + expand(size_t size); + + char *mData; /**< Data building up. */ + unsigned int mPos; /**< Position in the data. */ + unsigned int mDataSize; /**< Allocated datasize. */ + + /** + * Streams message ID and length to the given output stream. + */ + friend std::ostream& operator <<(std::ostream &os, + const MessageOut &msg); +}; + +#endif //MESSAGEOUT_H diff --git a/src/net/messageout.hpp b/src/net/messageout.hpp deleted file mode 100644 index cf3e0c73..00000000 --- a/src/net/messageout.hpp +++ /dev/null @@ -1,107 +0,0 @@ -/* - * The Mana Server - * Copyright (C) 2004-2010 The Mana World Development Team - * - * This file is part of The Mana Server. - * - * The Mana Server 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 - * any later version. - * - * The Mana Server 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 The Mana Server. If not, see . - */ - -#ifndef MESSAGEOUT_H -#define MESSAGEOUT_H - -#include - -/** - * Used for building an outgoing message. - */ -class MessageOut -{ - public: - /** - * Constructor. - */ - MessageOut(); - - /** - * Constructor that takes a message ID. - */ - MessageOut(int id); - - /** - * Destructor. - */ - ~MessageOut(); - - /** - * Clears current message. - */ - void clear(); - - void writeInt8(int value); /**< Writes an integer on one byte. */ - - void writeInt16(int value); /**< Writes an integer on two bytes. */ - - void writeInt32(int value); /**< Writes an integer on four bytes. */ - - /** - * Writes a double. HACKY and should *not* be used for client - * communication! - */ - void writeDouble(double value); - - /** - * Writes a 3-byte block containing tile-based coordinates. - */ - void writeCoordinates(int x, int y); - - /** - * Writes a string. If a fixed length is not given (-1), it is stored - * as a short at the start of the string. - */ - void - writeString(const std::string &string, int length = -1); - - /** - * Returns the content of the message. - */ - char* - getData() const { return mData; } - - /** - * Returns the length of the data. - */ - unsigned int - getLength() const { return mPos; } - - private: - /** - * Ensures the capacity of the data buffer is large enough to hold the - * given amount of bytes. - */ - void - expand(size_t size); - - char *mData; /**< Data building up. */ - unsigned int mPos; /**< Position in the data. */ - unsigned int mDataSize; /**< Allocated datasize. */ - - /** - * Streams message ID and length to the given output stream. - */ - friend std::ostream& operator <<(std::ostream &os, - const MessageOut &msg); -}; - -#endif //MESSAGEOUT_H diff --git a/src/net/netcomputer.cpp b/src/net/netcomputer.cpp index 84a10749..c4af3420 100644 --- a/src/net/netcomputer.cpp +++ b/src/net/netcomputer.cpp @@ -22,12 +22,12 @@ #include #include -#include "bandwidth.hpp" -#include "messageout.hpp" -#include "netcomputer.hpp" +#include "bandwidth.h" +#include "messageout.h" +#include "netcomputer.h" #include "../utils/logger.h" -#include "../utils/processorutils.hpp" +#include "../utils/processorutils.h" NetComputer::NetComputer(ENetPeer *peer): mPeer(peer) diff --git a/src/net/netcomputer.h b/src/net/netcomputer.h new file mode 100644 index 00000000..d3485f64 --- /dev/null +++ b/src/net/netcomputer.h @@ -0,0 +1,96 @@ +/* + * The Mana Server + * Copyright (C) 2004-2010 The Mana World Development Team + * + * This file is part of The Mana Server. + * + * The Mana Server 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 + * any later version. + * + * The Mana Server 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 The Mana Server. If not, see . + */ + +#ifndef NETCOMPUTER_H +#define NETCOMPUTER_H + +#include +#include + +class MessageOut; + +/** + * This class represents a known computer on the network. For example a + * connected client or a server we're connected to. + */ +class NetComputer +{ + public: + /** + * Constructor. + */ + NetComputer(ENetPeer *peer); + + /** + * Destructor. + */ + virtual ~NetComputer() {} + + /** + * Returns true if this computer is connected. + */ + bool isConnected(); + + /** + * Disconnects the computer from the server, after sending a message. + * + * The caller of this method should prepare the message, because + * NetComputer does not know which handler is sending it + * (could have been chat/game/account) + */ + void disconnect(const MessageOut &msg); + + /** + * Queues a message for sending to a client. + * + * Reliable packets always arrive, if the client stays connected. + * Unreliable packets may not arrive, and may not even be sent. + * + * Channels are used to ensure that unrelated reliable packets do not + * hold each other up. In essence, each channel represents a different + * queue. + * + * @param msg The message to be sent. + * @param reliable Defines if a reliable or an unreliable packet + * should be sent. + * @param channel The channel number of which the packet should + * be sent. + */ + void send(const MessageOut &msg, bool reliable = true, + unsigned int channel = 0); + + /** + * Returns IP address of computer in 32bit int form + */ + int getIP() const; + + private: + ENetPeer *mPeer; /**< Client peer */ + + /** + * Converts the ip-address of the peer to a stringstream. + * Example: + * std::cout << comp + */ + friend std::ostream& operator <<(std::ostream &os, + const NetComputer &comp); +}; + +#endif // NETCOMPUTER_H diff --git a/src/net/netcomputer.hpp b/src/net/netcomputer.hpp deleted file mode 100644 index d3485f64..00000000 --- a/src/net/netcomputer.hpp +++ /dev/null @@ -1,96 +0,0 @@ -/* - * The Mana Server - * Copyright (C) 2004-2010 The Mana World Development Team - * - * This file is part of The Mana Server. - * - * The Mana Server 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 - * any later version. - * - * The Mana Server 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 The Mana Server. If not, see . - */ - -#ifndef NETCOMPUTER_H -#define NETCOMPUTER_H - -#include -#include - -class MessageOut; - -/** - * This class represents a known computer on the network. For example a - * connected client or a server we're connected to. - */ -class NetComputer -{ - public: - /** - * Constructor. - */ - NetComputer(ENetPeer *peer); - - /** - * Destructor. - */ - virtual ~NetComputer() {} - - /** - * Returns true if this computer is connected. - */ - bool isConnected(); - - /** - * Disconnects the computer from the server, after sending a message. - * - * The caller of this method should prepare the message, because - * NetComputer does not know which handler is sending it - * (could have been chat/game/account) - */ - void disconnect(const MessageOut &msg); - - /** - * Queues a message for sending to a client. - * - * Reliable packets always arrive, if the client stays connected. - * Unreliable packets may not arrive, and may not even be sent. - * - * Channels are used to ensure that unrelated reliable packets do not - * hold each other up. In essence, each channel represents a different - * queue. - * - * @param msg The message to be sent. - * @param reliable Defines if a reliable or an unreliable packet - * should be sent. - * @param channel The channel number of which the packet should - * be sent. - */ - void send(const MessageOut &msg, bool reliable = true, - unsigned int channel = 0); - - /** - * Returns IP address of computer in 32bit int form - */ - int getIP() const; - - private: - ENetPeer *mPeer; /**< Client peer */ - - /** - * Converts the ip-address of the peer to a stringstream. - * Example: - * std::cout << comp - */ - friend std::ostream& operator <<(std::ostream &os, - const NetComputer &comp); -}; - -#endif // NETCOMPUTER_H diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp index 410b1cbf..72d20a66 100644 --- a/src/scripting/lua.cpp +++ b/src/scripting/lua.cpp @@ -27,30 +27,30 @@ extern "C" { #include } -#include "common/resourcemanager.hpp" -#include "game-server/accountconnection.hpp" -#include "game-server/buysell.hpp" -#include "game-server/character.hpp" -#include "game-server/collisiondetection.hpp" -#include "game-server/effect.hpp" -#include "game-server/gamehandler.hpp" -#include "game-server/inventory.hpp" -#include "game-server/item.hpp" -#include "game-server/itemmanager.hpp" -#include "game-server/mapcomposite.hpp" -#include "game-server/mapmanager.hpp" -#include "game-server/monster.hpp" -#include "game-server/monstermanager.hpp" -#include "game-server/npc.hpp" -#include "game-server/postman.hpp" -#include "game-server/quest.hpp" -#include "game-server/state.hpp" -#include "game-server/trigger.hpp" -#include "net/messageout.hpp" -#include "scripting/luautil.hpp" -#include "scripting/luascript.hpp" +#include "common/resourcemanager.h" +#include "game-server/accountconnection.h" +#include "game-server/buysell.h" +#include "game-server/character.h" +#include "game-server/collisiondetection.h" +#include "game-server/effect.h" +#include "game-server/gamehandler.h" +#include "game-server/inventory.h" +#include "game-server/item.h" +#include "game-server/itemmanager.h" +#include "game-server/mapcomposite.h" +#include "game-server/mapmanager.h" +#include "game-server/monster.h" +#include "game-server/monstermanager.h" +#include "game-server/npc.h" +#include "game-server/postman.h" +#include "game-server/quest.h" +#include "game-server/state.h" +#include "game-server/trigger.h" +#include "net/messageout.h" +#include "scripting/luautil.h" +#include "scripting/luascript.h" #include "utils/logger.h" -#include "utils/speedconv.hpp" +#include "utils/speedconv.h" #include diff --git a/src/scripting/luascript.cpp b/src/scripting/luascript.cpp index 23e4fdb9..ff993899 100644 --- a/src/scripting/luascript.cpp +++ b/src/scripting/luascript.cpp @@ -19,9 +19,9 @@ * along with The Mana Server. If not, see . */ -#include "luascript.hpp" +#include "luascript.h" -#include "game-server/being.hpp" +#include "game-server/being.h" #include "utils/logger.h" #include diff --git a/src/scripting/luascript.h b/src/scripting/luascript.h new file mode 100644 index 00000000..cc1675d8 --- /dev/null +++ b/src/scripting/luascript.h @@ -0,0 +1,96 @@ +/* + * The Mana Server + * Copyright (C) 2007-2010 The Mana World Development Team + * + * This file is part of The Mana Server. + * + * The Mana Server 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 + * any later version. + * + * The Mana Server 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 The Mana Server. If not, see . + */ + +#ifndef LUASCRIPT_H +#define LUASCRIPT_H + +extern "C" { +#include +#include +} + +#include "scripting/script.h" + +/** + * Implementation of the Script class for Lua. + */ +class LuaScript: public Script +{ + public: + /** + * Constructor. Initializes a new Lua state, registers the native API + * and loads the libmana.lua file. + */ + LuaScript(); + + /** + * Destructor. + */ + ~LuaScript(); + + void load(const char *prog, const char *name); + + void prepare(const std::string &); + + void push(int); + + void push(const std::string &); + + void push(Thing *); + + int execute(); + + static void getQuestCallback(Character *, const std::string &, + const std::string &, void *); + + static void getPostCallback(Character *, const std::string &, + const std::string &, void *); + + void processDeathEvent(Being *thing); + + void processRemoveEvent(Thing *thing); + + /** + * Loads the global event script file + */ + static bool loadGlobalEventScript(const std::string &file); + static bool loadSpecialActionsScript(const std::string &file); + + private: + lua_State *mState; + int nbArgs; + std::string mCurFunction; +}; + +static char const registryKey = 0; + +static Script *LuaFactory() +{ + return new LuaScript(); +} + +struct LuaRegister +{ + LuaRegister() { Script::registerEngine("lua", LuaFactory); } +}; + +static LuaRegister dummy; + +#endif // LUASCRIPT_H diff --git a/src/scripting/luascript.hpp b/src/scripting/luascript.hpp deleted file mode 100644 index 292c35ad..00000000 --- a/src/scripting/luascript.hpp +++ /dev/null @@ -1,96 +0,0 @@ -/* - * The Mana Server - * Copyright (C) 2007-2010 The Mana World Development Team - * - * This file is part of The Mana Server. - * - * The Mana Server 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 - * any later version. - * - * The Mana Server 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 The Mana Server. If not, see . - */ - -#ifndef LUASCRIPT_HPP -#define LUASCRIPT_HPP - -extern "C" { -#include -#include -} - -#include "scripting/script.hpp" - -/** - * Implementation of the Script class for Lua. - */ -class LuaScript: public Script -{ - public: - /** - * Constructor. Initializes a new Lua state, registers the native API - * and loads the libmana.lua file. - */ - LuaScript(); - - /** - * Destructor. - */ - ~LuaScript(); - - void load(const char *prog, const char *name); - - void prepare(const std::string &); - - void push(int); - - void push(const std::string &); - - void push(Thing *); - - int execute(); - - static void getQuestCallback(Character *, const std::string &, - const std::string &, void *); - - static void getPostCallback(Character *, const std::string &, - const std::string &, void *); - - void processDeathEvent(Being *thing); - - void processRemoveEvent(Thing *thing); - - /** - * Loads the global event script file - */ - static bool loadGlobalEventScript(const std::string &file); - static bool loadSpecialActionsScript(const std::string &file); - - private: - lua_State *mState; - int nbArgs; - std::string mCurFunction; -}; - -static char const registryKey = 0; - -static Script *LuaFactory() -{ - return new LuaScript(); -} - -struct LuaRegister -{ - LuaRegister() { Script::registerEngine("lua", LuaFactory); } -}; - -static LuaRegister dummy; - -#endif // LUASCRIPT_HPP diff --git a/src/scripting/luautil.cpp b/src/scripting/luautil.cpp index 008a5e38..cec3ae76 100644 --- a/src/scripting/luautil.cpp +++ b/src/scripting/luautil.cpp @@ -19,10 +19,10 @@ * along with The Mana Server. If not, see . */ -#include "luautil.hpp" +#include "luautil.h" -#include "game-server/character.hpp" -#include "game-server/npc.hpp" +#include "game-server/character.h" +#include "game-server/npc.h" #include "utils/logger.h" diff --git a/src/scripting/luautil.h b/src/scripting/luautil.h new file mode 100644 index 00000000..87185155 --- /dev/null +++ b/src/scripting/luautil.h @@ -0,0 +1,126 @@ +/* + * The Mana Server + * Copyright (C) 2007-2010 The Mana World Development Team + * + * This file is part of The Mana Server. + * + * The Mana Server 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 + * any later version. + * + * The Mana Server 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 The Mana Server. If not, see . + */ + +#ifndef SCRIPTING_LUAUTIL_H +#define SCRIPTING_LUAUTIL_H + +extern "C" { +#include +#include +} +#include +#include +#include +#include +#include + +class Being; +class NPC; +class Character; +class Thing; + +// Report script errors and interrupt the script. +void raiseScriptError(lua_State *s, const char *format, ...); + +void raiseWarning(lua_State *s, const char *format, ...); + +NPC *getNPC(lua_State *s, int p); +Character *getCharacter(lua_State *s, int p); +Being *getBeing(lua_State *s, int p); + + +/* Polymorphic wrapper for pushing variables. + Useful for templates.*/ +void push(lua_State *s, int val); +void push(lua_State *s, const std::string &val); +void push(lua_State *s, Thing* val); +void push(lua_State *s, double val); + + +/* Pushes an STL LIST */ +template void pushSTLContainer(lua_State *s, const std::list &container) +{ + int len = container.size(); + lua_newtable(s); + int table = lua_gettop(s); + typename std::list::const_iterator i; + i = container.begin(); + + for (int key = 1; key <= len; key++) + { + push(s, key); + push(s, *i); + lua_settable(s, table); + i++; + } +} + +/* Pushes an STL VECTOR */ +template void pushSTLContainer(lua_State *s, const std::vector &container) +{ + int len = container.size(); + lua_createtable(s, 0, len); + int table = lua_gettop(s); + + for (int key = 0; key < len; key++) + { + push(s, key+1); + push(s, container.at(key)); + lua_settable(s, table); + } +} + +/* Pushes an STL MAP */ +template void pushSTLContainer(lua_State *s, const std::map &container) +{ + int len = container.size(); + lua_createtable(s, 0, len); + int table = lua_gettop(s); + typename std::map::const_iterator i; + i = container.begin(); + + for (int key = 1; key <= len; key++) + { + push(s, i->first); + push(s, i->second); + lua_settable(s, table); + i++; + } +} + +/* Pushes an STL SET */ +template void pushSTLContainer(lua_State *s, const std::set &container) +{ + int len = container.size(); + lua_newtable(s); + int table = lua_gettop(s); + typename std::set::const_iterator i; + i = container.begin(); + + for (int key = 1; key <= len; key++) + { + push(s, key); + push(s, *i); + lua_settable(s, table); + i++; + } +} + +#endif diff --git a/src/scripting/luautil.hpp b/src/scripting/luautil.hpp deleted file mode 100644 index aec2c5c2..00000000 --- a/src/scripting/luautil.hpp +++ /dev/null @@ -1,126 +0,0 @@ -/* - * The Mana Server - * Copyright (C) 2007-2010 The Mana World Development Team - * - * This file is part of The Mana Server. - * - * The Mana Server 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 - * any later version. - * - * The Mana Server 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 The Mana Server. If not, see . - */ - -#ifndef SCRIPTING_LUAUTIL_HPP -#define SCRIPTING_LUAUTIL_HPP - -extern "C" { -#include -#include -} -#include -#include -#include -#include -#include - -class Being; -class NPC; -class Character; -class Thing; - -// Report script errors and interrupt the script. -void raiseScriptError(lua_State *s, const char *format, ...); - -void raiseWarning(lua_State *s, const char *format, ...); - -NPC *getNPC(lua_State *s, int p); -Character *getCharacter(lua_State *s, int p); -Being *getBeing(lua_State *s, int p); - - -/* Polymorphic wrapper for pushing variables. - Useful for templates.*/ -void push(lua_State *s, int val); -void push(lua_State *s, const std::string &val); -void push(lua_State *s, Thing* val); -void push(lua_State *s, double val); - - -/* Pushes an STL LIST */ -template void pushSTLContainer(lua_State *s, const std::list &container) -{ - int len = container.size(); - lua_newtable(s); - int table = lua_gettop(s); - typename std::list::const_iterator i; - i = container.begin(); - - for (int key = 1; key <= len; key++) - { - push(s, key); - push(s, *i); - lua_settable(s, table); - i++; - } -} - -/* Pushes an STL VECTOR */ -template void pushSTLContainer(lua_State *s, const std::vector &container) -{ - int len = container.size(); - lua_createtable(s, 0, len); - int table = lua_gettop(s); - - for (int key = 0; key < len; key++) - { - push(s, key+1); - push(s, container.at(key)); - lua_settable(s, table); - } -} - -/* Pushes an STL MAP */ -template void pushSTLContainer(lua_State *s, const std::map &container) -{ - int len = container.size(); - lua_createtable(s, 0, len); - int table = lua_gettop(s); - typename std::map::const_iterator i; - i = container.begin(); - - for (int key = 1; key <= len; key++) - { - push(s, i->first); - push(s, i->second); - lua_settable(s, table); - i++; - } -} - -/* Pushes an STL SET */ -template void pushSTLContainer(lua_State *s, const std::set &container) -{ - int len = container.size(); - lua_newtable(s); - int table = lua_gettop(s); - typename std::set::const_iterator i; - i = container.begin(); - - for (int key = 1; key <= len; key++) - { - push(s, key); - push(s, *i); - lua_settable(s, table); - i++; - } -} - -#endif diff --git a/src/scripting/script.cpp b/src/scripting/script.cpp index 334895c3..b222b0f7 100644 --- a/src/scripting/script.cpp +++ b/src/scripting/script.cpp @@ -18,10 +18,10 @@ * along with The Mana Server. If not, see . */ -#include "scripting/script.hpp" +#include "scripting/script.h" -#include "common/resourcemanager.hpp" -#include "game-server/being.hpp" +#include "common/resourcemanager.h" +#include "game-server/being.h" #include "utils/logger.h" #include diff --git a/src/scripting/script.h b/src/scripting/script.h new file mode 100644 index 00000000..5d5d1f48 --- /dev/null +++ b/src/scripting/script.h @@ -0,0 +1,170 @@ +/* + * The Mana Server + * Copyright (C) 2007-2010 The Mana World Development Team + * + * This file is part of The Mana Server. + * + * The Mana Server 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 + * any later version. + * + * The Mana Server 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 The Mana Server. If not, see . + */ + +#ifndef SCRIPTING_SCRIPT_H +#define SCRIPTING_SCRIPT_H + +#include + +#include "game-server/character.h" +#include "game-server/eventlistener.h" + +class MapComposite; +class Thing; + +/** + * Abstract interface for calling functions written in an external language. + */ +class Script +{ + public: + + typedef Script *(*Factory)(); + + /** + * Registers a new scripting engine. + */ + static void registerEngine(const std::string &, Factory); + + /** + * Creates a new script context for a given engine. + */ + static Script *create(const std::string &engine); + + /** + * Constructor. + */ + Script(); + + /** + * Destructor. + */ + virtual ~Script() {} + + /** + * Loads a chunk of text into script context and executes its global + * statements. + * + * @param prog the program text to load + * @param name the name of the text, used for error reporting + */ + virtual void load(const char *prog, const char *name) = 0; + + /** + * Loads a text file into script context and executes its global + * statements. + */ + virtual bool loadFile(const std::string &); + + /** + * Loads a chunk of text and considers it as an NPC handler. This + * handler will later be used to create the given NPC. + */ + virtual void loadNPC(const std::string &name, int id, int x, int y, + const char *); + + /** + * Called every tick for the script to manage its data. + * Calls the "update" function of the script by default. + */ + virtual void update(); + + /** + * Prepares a call to the given function. + * Only one function can be prepared at once. + */ + virtual void prepare(const std::string &name) = 0; + + /** + * Pushes an integer argument for the function being prepared. + */ + virtual void push(int) = 0; + + /** + * Pushes a string argument for the function being prepared. + */ + virtual void push(const std::string &) = 0; + + /** + * Pushes a pointer argument to a game entity. + * The interface can pass the pointer as an opaque value to the + * scripting engine, if needed. This value will usually be passed + * by the script to some callback functions. + */ + virtual void push(Thing *) = 0; + + /** + * Executes the function being prepared. + * @return the value returned by the script. + */ + virtual int execute() = 0; + + /** + * Sets associated map. + */ + void setMap(MapComposite *m) + { mMap = m; } + + /** + * Gets associated map. + */ + MapComposite *getMap() const + { return mMap; } + + EventListener *getScriptListener() + { return &mEventListener; } + + virtual void processDeathEvent(Being *thing) = 0; + + virtual void processRemoveEvent(Thing *thing) = 0; + + /** + * Runs a function from the global event script file + */ + static bool executeGlobalEventFunction(const std::string &function, Being *obj); + static void addDataToSpecial(int specialId, Special *special); + static bool performSpecialAction(int specialId, Being *caster); + + + protected: + static Script *globalEventScript; + static Script *specialActionsScript; + std::string mScriptFile; + + private: + MapComposite *mMap; + EventListener mEventListener; /**< Tracking of being deaths. */ + + friend struct ScriptEventDispatch; +}; + +struct ScriptEventDispatch: EventDispatch +{ + ScriptEventDispatch() + { + typedef EventListenerFactory< Script, &Script::mEventListener > Factory; + died = &Factory::create< Being, &Script::processDeathEvent >::function; + removed = &Factory::create< Thing, &Script::processRemoveEvent >::function; + } +}; + +static ScriptEventDispatch scriptEventDispatch; + +#endif diff --git a/src/scripting/script.hpp b/src/scripting/script.hpp deleted file mode 100644 index 6f5dded6..00000000 --- a/src/scripting/script.hpp +++ /dev/null @@ -1,170 +0,0 @@ -/* - * The Mana Server - * Copyright (C) 2007-2010 The Mana World Development Team - * - * This file is part of The Mana Server. - * - * The Mana Server 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 - * any later version. - * - * The Mana Server 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 The Mana Server. If not, see . - */ - -#ifndef SCRIPTING_SCRIPT_HPP -#define SCRIPTING_SCRIPT_HPP - -#include - -#include "game-server/character.hpp" -#include "game-server/eventlistener.hpp" - -class MapComposite; -class Thing; - -/** - * Abstract interface for calling functions written in an external language. - */ -class Script -{ - public: - - typedef Script *(*Factory)(); - - /** - * Registers a new scripting engine. - */ - static void registerEngine(const std::string &, Factory); - - /** - * Creates a new script context for a given engine. - */ - static Script *create(const std::string &engine); - - /** - * Constructor. - */ - Script(); - - /** - * Destructor. - */ - virtual ~Script() {} - - /** - * Loads a chunk of text into script context and executes its global - * statements. - * - * @param prog the program text to load - * @param name the name of the text, used for error reporting - */ - virtual void load(const char *prog, const char *name) = 0; - - /** - * Loads a text file into script context and executes its global - * statements. - */ - virtual bool loadFile(const std::string &); - - /** - * Loads a chunk of text and considers it as an NPC handler. This - * handler will later be used to create the given NPC. - */ - virtual void loadNPC(const std::string &name, int id, int x, int y, - const char *); - - /** - * Called every tick for the script to manage its data. - * Calls the "update" function of the script by default. - */ - virtual void update(); - - /** - * Prepares a call to the given function. - * Only one function can be prepared at once. - */ - virtual void prepare(const std::string &name) = 0; - - /** - * Pushes an integer argument for the function being prepared. - */ - virtual void push(int) = 0; - - /** - * Pushes a string argument for the function being prepared. - */ - virtual void push(const std::string &) = 0; - - /** - * Pushes a pointer argument to a game entity. - * The interface can pass the pointer as an opaque value to the - * scripting engine, if needed. This value will usually be passed - * by the script to some callback functions. - */ - virtual void push(Thing *) = 0; - - /** - * Executes the function being prepared. - * @return the value returned by the script. - */ - virtual int execute() = 0; - - /** - * Sets associated map. - */ - void setMap(MapComposite *m) - { mMap = m; } - - /** - * Gets associated map. - */ - MapComposite *getMap() const - { return mMap; } - - EventListener *getScriptListener() - { return &mEventListener; } - - virtual void processDeathEvent(Being *thing) = 0; - - virtual void processRemoveEvent(Thing *thing) = 0; - - /** - * Runs a function from the global event script file - */ - static bool executeGlobalEventFunction(const std::string &function, Being *obj); - static void addDataToSpecial(int specialId, Special *special); - static bool performSpecialAction(int specialId, Being *caster); - - - protected: - static Script *globalEventScript; - static Script *specialActionsScript; - std::string mScriptFile; - - private: - MapComposite *mMap; - EventListener mEventListener; /**< Tracking of being deaths. */ - - friend struct ScriptEventDispatch; -}; - -struct ScriptEventDispatch: EventDispatch -{ - ScriptEventDispatch() - { - typedef EventListenerFactory< Script, &Script::mEventListener > Factory; - died = &Factory::create< Being, &Script::processDeathEvent >::function; - removed = &Factory::create< Thing, &Script::processRemoveEvent >::function; - } -}; - -static ScriptEventDispatch scriptEventDispatch; - -#endif diff --git a/src/serialize/characterdata.h b/src/serialize/characterdata.h new file mode 100644 index 00000000..f36581d0 --- /dev/null +++ b/src/serialize/characterdata.h @@ -0,0 +1,215 @@ +/* + * The Mana Server + * Copyright (C) 2007-2010 The Mana World Development Team + * + * This file is part of The Mana Server. + * + * The Mana Server 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 + * any later version. + * + * The Mana Server 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 The Mana Server. If not, see . + */ + +#ifndef SERIALIZE_CHARACTERDATA_H +#define SERIALIZE_CHARACTERDATA_H + +#include + +#include "defines.h" +#include "common/inventorydata.h" +#include "net/messagein.h" +#include "net/messageout.h" +#include "point.h" + +template< class T > +void serializeCharacterData(const T &data, MessageOut &msg) +{ + // general character properties + msg.writeInt8(data.getAccountLevel()); + msg.writeInt8(data.getGender()); + msg.writeInt8(data.getHairStyle()); + msg.writeInt8(data.getHairColor()); + msg.writeInt16(data.getLevel()); + msg.writeInt16(data.getCharacterPoints()); + msg.writeInt16(data.getCorrectionPoints()); + + msg.writeInt16(data.mAttributes.size()); + AttributeMap::const_iterator attr_it, attr_it_end; + for (attr_it = data.mAttributes.begin(), + attr_it_end = data.mAttributes.end(); + attr_it != attr_it_end; + ++attr_it) + { + msg.writeInt16(attr_it->first); + msg.writeDouble(data.getAttrBase(attr_it)); + msg.writeDouble(data.getAttrMod(attr_it)); + } + + // character skills + msg.writeInt16(data.getSkillSize()); + + std::map::const_iterator skill_it; + for (skill_it = data.getSkillBegin(); skill_it != data.getSkillEnd() ; skill_it++) + { + msg.writeInt16(skill_it->first); + msg.writeInt32(skill_it->second); + } + + // status effects currently affecting the character + msg.writeInt16(data.getStatusEffectSize()); + std::map::const_iterator status_it; + for (status_it = data.getStatusEffectBegin(); status_it != data.getStatusEffectEnd(); status_it++) + { + msg.writeInt16(status_it->first); + msg.writeInt16(status_it->second); + } + + // location + msg.writeInt16(data.getMapId()); + const Point &pos = data.getPosition(); + msg.writeInt16(pos.x); + msg.writeInt16(pos.y); + + // kill count + msg.writeInt16(data.getKillCountSize()); + std::map::const_iterator kills_it; + for (kills_it = data.getKillCountBegin(); kills_it != data.getKillCountEnd(); kills_it++) + { + msg.writeInt16(kills_it->first); + msg.writeInt32(kills_it->second); + } + + // character specials + std::map::const_iterator special_it; + msg.writeInt16(data.getSpecialSize()); + for (special_it = data.getSpecialBegin(); special_it != data.getSpecialEnd() ; special_it++) + { + msg.writeInt32(special_it->first); + } + + // inventory - must be last because size isn't transmitted + const Possessions &poss = data.getPossessions(); + msg.writeInt16(poss.equipSlots.size()); // number of equipment + for (EquipData::const_iterator k = poss.equipSlots.begin(), + k_end = poss.equipSlots.end(); + k != k_end; + ++k) + { + msg.writeInt8(k->first); // Equip slot type + msg.writeInt16(k->second); // Inventory slot + } + for (InventoryData::const_iterator j = poss.inventory.begin(), + j_end = poss.inventory.end(); j != j_end; ++j) + { + msg.writeInt16(j->first); // slot id + msg.writeInt16(j->second.itemId); // item type + msg.writeInt16(j->second.amount); // amount + } +} + +template< class T > +void deserializeCharacterData(T &data, MessageIn &msg) +{ + // general character properties + data.setAccountLevel(msg.readInt8()); + data.setGender(msg.readInt8()); + data.setHairStyle(msg.readInt8()); + data.setHairColor(msg.readInt8()); + data.setLevel(msg.readInt16()); + data.setCharacterPoints(msg.readInt16()); + data.setCorrectionPoints(msg.readInt16()); + + // character attributes + unsigned int attrSize = msg.readInt16(); + for (unsigned int i = 0; i < attrSize; ++i) + { + unsigned int id = msg.readInt16(); + double base = msg.readDouble(), + mod = msg.readDouble(); + data.setAttribute(id, base); + data.setModAttribute(id, mod); + } + + // character skills + int skillSize = msg.readInt16(); + + for (int i = 0; i < skillSize; ++i) + { + int skill = msg.readInt16(); + int level = msg.readInt32(); + data.setExperience(skill,level); + } + + // status effects currently affecting the character + int statusSize = msg.readInt16(); + + for (int i = 0; i < statusSize; i++) + { + int status = msg.readInt16(); + int time = msg.readInt16(); + data.applyStatusEffect(status, time); + } + + // location + data.setMapId(msg.readInt16()); + + Point temporaryPoint; + temporaryPoint.x = msg.readInt16(); + temporaryPoint.y = msg.readInt16(); + data.setPosition(temporaryPoint); + + // kill count + int killSize = msg.readInt16(); + for (int i = 0; i < killSize; i++) + { + int monsterId = msg.readInt16(); + int kills = msg.readInt32(); + data.setKillCount(monsterId, kills); + } + + // character specials + int specialSize = msg.readInt16(); + data.clearSpecials(); + for (int i = 0; i < specialSize; i++) + { + data.giveSpecial(msg.readInt32()); + } + + + Possessions &poss = data.getPossessions(); + poss.equipSlots.clear(); + int equipSlotsSize = msg.readInt16(); + unsigned int eqSlot, invSlot; + for (int j = 0; j < equipSlotsSize; ++j) + { + int equipmentInSlotType = msg.readInt8(); + for (int k = 0; k < equipmentInSlotType; ++k) + { + eqSlot = msg.readInt8(); + invSlot = msg.readInt16(); + poss.equipSlots.insert(poss.equipSlots.end(), + std::make_pair(eqSlot, invSlot)); + } + } + poss.inventory.clear(); + // inventory - must be last because size isn't transmitted + while (msg.getUnreadLength()) + { + InventoryItem i; + int slotId = msg.readInt16(); + i.itemId = msg.readInt16(); + i.amount = msg.readInt16(); + poss.inventory.insert(poss.inventory.end(), std::make_pair(slotId, i)); + } + +} + +#endif diff --git a/src/serialize/characterdata.hpp b/src/serialize/characterdata.hpp deleted file mode 100644 index bf08dc14..00000000 --- a/src/serialize/characterdata.hpp +++ /dev/null @@ -1,215 +0,0 @@ -/* - * The Mana Server - * Copyright (C) 2007-2010 The Mana World Development Team - * - * This file is part of The Mana Server. - * - * The Mana Server 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 - * any later version. - * - * The Mana Server 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 The Mana Server. If not, see . - */ - -#ifndef SERIALIZE_CHARACTERDATA_HPP -#define SERIALIZE_CHARACTERDATA_HPP - -#include - -#include "defines.h" -#include "common/inventorydata.hpp" -#include "net/messagein.hpp" -#include "net/messageout.hpp" -#include "point.h" - -template< class T > -void serializeCharacterData(const T &data, MessageOut &msg) -{ - // general character properties - msg.writeInt8(data.getAccountLevel()); - msg.writeInt8(data.getGender()); - msg.writeInt8(data.getHairStyle()); - msg.writeInt8(data.getHairColor()); - msg.writeInt16(data.getLevel()); - msg.writeInt16(data.getCharacterPoints()); - msg.writeInt16(data.getCorrectionPoints()); - - msg.writeInt16(data.mAttributes.size()); - AttributeMap::const_iterator attr_it, attr_it_end; - for (attr_it = data.mAttributes.begin(), - attr_it_end = data.mAttributes.end(); - attr_it != attr_it_end; - ++attr_it) - { - msg.writeInt16(attr_it->first); - msg.writeDouble(data.getAttrBase(attr_it)); - msg.writeDouble(data.getAttrMod(attr_it)); - } - - // character skills - msg.writeInt16(data.getSkillSize()); - - std::map::const_iterator skill_it; - for (skill_it = data.getSkillBegin(); skill_it != data.getSkillEnd() ; skill_it++) - { - msg.writeInt16(skill_it->first); - msg.writeInt32(skill_it->second); - } - - // status effects currently affecting the character - msg.writeInt16(data.getStatusEffectSize()); - std::map::const_iterator status_it; - for (status_it = data.getStatusEffectBegin(); status_it != data.getStatusEffectEnd(); status_it++) - { - msg.writeInt16(status_it->first); - msg.writeInt16(status_it->second); - } - - // location - msg.writeInt16(data.getMapId()); - const Point &pos = data.getPosition(); - msg.writeInt16(pos.x); - msg.writeInt16(pos.y); - - // kill count - msg.writeInt16(data.getKillCountSize()); - std::map::const_iterator kills_it; - for (kills_it = data.getKillCountBegin(); kills_it != data.getKillCountEnd(); kills_it++) - { - msg.writeInt16(kills_it->first); - msg.writeInt32(kills_it->second); - } - - // character specials - std::map::const_iterator special_it; - msg.writeInt16(data.getSpecialSize()); - for (special_it = data.getSpecialBegin(); special_it != data.getSpecialEnd() ; special_it++) - { - msg.writeInt32(special_it->first); - } - - // inventory - must be last because size isn't transmitted - const Possessions &poss = data.getPossessions(); - msg.writeInt16(poss.equipSlots.size()); // number of equipment - for (EquipData::const_iterator k = poss.equipSlots.begin(), - k_end = poss.equipSlots.end(); - k != k_end; - ++k) - { - msg.writeInt8(k->first); // Equip slot type - msg.writeInt16(k->second); // Inventory slot - } - for (InventoryData::const_iterator j = poss.inventory.begin(), - j_end = poss.inventory.end(); j != j_end; ++j) - { - msg.writeInt16(j->first); // slot id - msg.writeInt16(j->second.itemId); // item type - msg.writeInt16(j->second.amount); // amount - } -} - -template< class T > -void deserializeCharacterData(T &data, MessageIn &msg) -{ - // general character properties - data.setAccountLevel(msg.readInt8()); - data.setGender(msg.readInt8()); - data.setHairStyle(msg.readInt8()); - data.setHairColor(msg.readInt8()); - data.setLevel(msg.readInt16()); - data.setCharacterPoints(msg.readInt16()); - data.setCorrectionPoints(msg.readInt16()); - - // character attributes - unsigned int attrSize = msg.readInt16(); - for (unsigned int i = 0; i < attrSize; ++i) - { - unsigned int id = msg.readInt16(); - double base = msg.readDouble(), - mod = msg.readDouble(); - data.setAttribute(id, base); - data.setModAttribute(id, mod); - } - - // character skills - int skillSize = msg.readInt16(); - - for (int i = 0; i < skillSize; ++i) - { - int skill = msg.readInt16(); - int level = msg.readInt32(); - data.setExperience(skill,level); - } - - // status effects currently affecting the character - int statusSize = msg.readInt16(); - - for (int i = 0; i < statusSize; i++) - { - int status = msg.readInt16(); - int time = msg.readInt16(); - data.applyStatusEffect(status, time); - } - - // location - data.setMapId(msg.readInt16()); - - Point temporaryPoint; - temporaryPoint.x = msg.readInt16(); - temporaryPoint.y = msg.readInt16(); - data.setPosition(temporaryPoint); - - // kill count - int killSize = msg.readInt16(); - for (int i = 0; i < killSize; i++) - { - int monsterId = msg.readInt16(); - int kills = msg.readInt32(); - data.setKillCount(monsterId, kills); - } - - // character specials - int specialSize = msg.readInt16(); - data.clearSpecials(); - for (int i = 0; i < specialSize; i++) - { - data.giveSpecial(msg.readInt32()); - } - - - Possessions &poss = data.getPossessions(); - poss.equipSlots.clear(); - int equipSlotsSize = msg.readInt16(); - unsigned int eqSlot, invSlot; - for (int j = 0; j < equipSlotsSize; ++j) - { - int equipmentInSlotType = msg.readInt8(); - for (int k = 0; k < equipmentInSlotType; ++k) - { - eqSlot = msg.readInt8(); - invSlot = msg.readInt16(); - poss.equipSlots.insert(poss.equipSlots.end(), - std::make_pair(eqSlot, invSlot)); - } - } - poss.inventory.clear(); - // inventory - must be last because size isn't transmitted - while (msg.getUnreadLength()) - { - InventoryItem i; - int slotId = msg.readInt16(); - i.itemId = msg.readInt16(); - i.amount = msg.readInt16(); - poss.inventory.insert(poss.inventory.end(), std::make_pair(slotId, i)); - } - -} - -#endif diff --git a/src/utils/logger.cpp b/src/utils/logger.cpp index 2053c9a8..958d2e52 100644 --- a/src/utils/logger.cpp +++ b/src/utils/logger.cpp @@ -20,8 +20,8 @@ */ #include "logger.h" -#include "common/resourcemanager.hpp" -#include "utils/string.hpp" +#include "common/resourcemanager.h" +#include "utils/string.h" #include #include diff --git a/src/utils/processorutils.cpp b/src/utils/processorutils.cpp index 37db06a2..06ef0178 100644 --- a/src/utils/processorutils.cpp +++ b/src/utils/processorutils.cpp @@ -18,7 +18,7 @@ * along with The Mana Server. If not, see . */ -#include "utils/processorutils.hpp" +#include "utils/processorutils.h" bool utils::processor::isLittleEndian; diff --git a/src/utils/processorutils.h b/src/utils/processorutils.h new file mode 100644 index 00000000..6fc01393 --- /dev/null +++ b/src/utils/processorutils.h @@ -0,0 +1,50 @@ +/* + * The Mana Server + * Copyright (C) 2007-2010 The Mana World Development Team + * + * This file is part of The Mana Server. + * + * The Mana Server 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 + * any later version. + * + * The Mana Server 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 The Mana Server. If not, see . + */ + +#ifndef PROCESSORUTILS_H +#define PROCESSORUTILS_H + +namespace utils +{ + namespace processor + { + /** + * \brief Initialises the processor utils. + * + * Does runtime checks, of which the results are stored in variables + * in this namespace. + */ + void init(); + + /** + * True if the processor is little-endian + * + */ + extern bool isLittleEndian; + + /** + * Returns true if the processor is little-endian. + */ + bool littleEndianCheck(); + + } // namespace processor +} // namespace utils + +#endif // PROCESSORUTILS_H diff --git a/src/utils/processorutils.hpp b/src/utils/processorutils.hpp deleted file mode 100644 index 05bb7c8b..00000000 --- a/src/utils/processorutils.hpp +++ /dev/null @@ -1,50 +0,0 @@ -/* - * The Mana Server - * Copyright (C) 2007-2010 The Mana World Development Team - * - * This file is part of The Mana Server. - * - * The Mana Server 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 - * any later version. - * - * The Mana Server 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 The Mana Server. If not, see . - */ - -#ifndef PROCESSORUTILS_HPP -#define PROCESSORUTILS_HPP - -namespace utils -{ - namespace processor - { - /** - * \brief Initialises the processor utils. - * - * Does runtime checks, of which the results are stored in variables - * in this namespace. - */ - void init(); - - /** - * True if the processor is little-endian - * - */ - extern bool isLittleEndian; - - /** - * Returns true if the processor is little-endian. - */ - bool littleEndianCheck(); - - } // namespace processor -} // namespace utils - -#endif // TOKENDISPENSER_HPP diff --git a/src/utils/speedconv.cpp b/src/utils/speedconv.cpp index 18602abf..f6be2e7b 100644 --- a/src/utils/speedconv.cpp +++ b/src/utils/speedconv.cpp @@ -18,7 +18,7 @@ * along with The Mana Server. If not, see . */ -#include "utils/speedconv.hpp" +#include "utils/speedconv.h" double utils::tpsToSpeed(double tps) { diff --git a/src/utils/speedconv.h b/src/utils/speedconv.h new file mode 100644 index 00000000..33e1a944 --- /dev/null +++ b/src/utils/speedconv.h @@ -0,0 +1,44 @@ +/* + * The Mana Server + * Copyright (C) 2004-2010 The Mana World Development Team + * + * This file is part of The Mana Server. + * + * The Mana Server 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 + * any later version. + * + * The Mana Server 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 The Mana Server. If not, see . + */ + +#ifndef SPEEDCONV_H +#define SPEEDCONV_H + +// Simple helper functions for converting between tiles per +// second and the internal speed representation + +#include "defines.h" + +namespace utils { + /** + * tpsToSpeed() + * @param tps The speed value in tiles per second + * @returns The speed value in the internal representation + */ + double tpsToSpeed(double); + /** + * speedToTps() + * @param speed The speed value in the internal representation + * @returns The speed value in tiles per second + */ + double speedToTps(double); +} + +#endif // SPEEDCONV_H diff --git a/src/utils/speedconv.hpp b/src/utils/speedconv.hpp deleted file mode 100644 index 6a29d0f3..00000000 --- a/src/utils/speedconv.hpp +++ /dev/null @@ -1,44 +0,0 @@ -/* - * The Mana Server - * Copyright (C) 2004-2010 The Mana World Development Team - * - * This file is part of The Mana Server. - * - * The Mana Server 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 - * any later version. - * - * The Mana Server 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 The Mana Server. If not, see . - */ - -#ifndef SPEEDCONV_HPP -#define SPEEDCONV_HPP - -// Simple helper functions for converting between tiles per -// second and the internal speed representation - -#include "defines.h" - -namespace utils { - /** - * tpsToSpeed() - * @param tps The speed value in tiles per second - * @returns The speed value in the internal representation - */ - double tpsToSpeed(double); - /** - * speedToTps() - * @param speed The speed value in the internal representation - * @returns The speed value in tiles per second - */ - double speedToTps(double); -} - -#endif // SPEEDCONV_HPP diff --git a/src/utils/string.cpp b/src/utils/string.cpp index 785a0921..089a5373 100644 --- a/src/utils/string.cpp +++ b/src/utils/string.cpp @@ -18,7 +18,7 @@ * along with The Mana Server. If not, see . */ -#include "utils/string.hpp" +#include "utils/string.h" #include #include diff --git a/src/utils/string.h b/src/utils/string.h new file mode 100644 index 00000000..6127bfed --- /dev/null +++ b/src/utils/string.h @@ -0,0 +1,86 @@ +/* + * The Mana Server + * Copyright (C) 2004-2010 The Mana World Development Team + * + * This file is part of The Mana Server. + * + * The Mana Server 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 + * any later version. + * + * The Mana Server 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 The Mana Server. If not, see . + */ + +#ifndef UTILS_STRING_H +#define UTILS_STRING_H + +#include +#include + +namespace utils +{ + /** + * Returns an upper-cased copy of the string. + */ + std::string toUpper(std::string); + + /** + * Returns an lower-cased copy of the string. + */ + std::string toLower(std::string); + + /** + * Tells whether the string is a numerical representation. + */ + bool isNumeric(const std::string &); + + /** + * Turns a string representing a numerical representation + * into an integer value. + */ + int stringToInt(const std::string &); + + /** + * Compares the two strings case-insensitively. + * + * @param a the first string in the comparison + * @param b the second string in the comparison + * @return 0 if the strings are equal, positive if the first is greater, + * negative if the second is greater + */ + int compareStrI(const std::string &a, const std::string &b); + + /** + * Returns the boolean value represented in a string, or default. + */ + bool stringToBool(const std::string &s, bool defaultValue); + + /** + * Trims spaces off the end and the beginning of the given string. + * + * @param str the string to trim spaces off + */ + void trim(std::string &str); + + /** + * Converts the given value to a string using std::stringstream. + * + * @param arg the value to convert to a string + * @return the string representation of arg + */ + template std::string toString(const T &arg) + { + std::stringstream ss; + ss << arg; + return ss.str(); + } +} + +#endif // UTILS_STRING_H diff --git a/src/utils/string.hpp b/src/utils/string.hpp deleted file mode 100644 index 6127bfed..00000000 --- a/src/utils/string.hpp +++ /dev/null @@ -1,86 +0,0 @@ -/* - * The Mana Server - * Copyright (C) 2004-2010 The Mana World Development Team - * - * This file is part of The Mana Server. - * - * The Mana Server 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 - * any later version. - * - * The Mana Server 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 The Mana Server. If not, see . - */ - -#ifndef UTILS_STRING_H -#define UTILS_STRING_H - -#include -#include - -namespace utils -{ - /** - * Returns an upper-cased copy of the string. - */ - std::string toUpper(std::string); - - /** - * Returns an lower-cased copy of the string. - */ - std::string toLower(std::string); - - /** - * Tells whether the string is a numerical representation. - */ - bool isNumeric(const std::string &); - - /** - * Turns a string representing a numerical representation - * into an integer value. - */ - int stringToInt(const std::string &); - - /** - * Compares the two strings case-insensitively. - * - * @param a the first string in the comparison - * @param b the second string in the comparison - * @return 0 if the strings are equal, positive if the first is greater, - * negative if the second is greater - */ - int compareStrI(const std::string &a, const std::string &b); - - /** - * Returns the boolean value represented in a string, or default. - */ - bool stringToBool(const std::string &s, bool defaultValue); - - /** - * Trims spaces off the end and the beginning of the given string. - * - * @param str the string to trim spaces off - */ - void trim(std::string &str); - - /** - * Converts the given value to a string using std::stringstream. - * - * @param arg the value to convert to a string - * @return the string representation of arg - */ - template std::string toString(const T &arg) - { - std::stringstream ss; - ss << arg; - return ss.str(); - } -} - -#endif // UTILS_STRING_H diff --git a/src/utils/stringfilter.cpp b/src/utils/stringfilter.cpp index 4a9d19cc..617da90d 100644 --- a/src/utils/stringfilter.cpp +++ b/src/utils/stringfilter.cpp @@ -22,7 +22,7 @@ #include "utils/stringfilter.h" -#include "common/configuration.hpp" +#include "common/configuration.h" #include "utils/logger.h" namespace utils diff --git a/src/utils/tokencollector.cpp b/src/utils/tokencollector.cpp index f82dcd10..e41d228e 100644 --- a/src/utils/tokencollector.cpp +++ b/src/utils/tokencollector.cpp @@ -18,7 +18,7 @@ * along with The Mana Server. If not, see . */ -#include "utils/tokencollector.hpp" +#include "utils/tokencollector.h" /* We are optimistic and we assume that clients connect as soon as possible. It means that pending data are mainly outdated ones, except for the newer diff --git a/src/utils/tokencollector.h b/src/utils/tokencollector.h new file mode 100644 index 00000000..3d2b653d --- /dev/null +++ b/src/utils/tokencollector.h @@ -0,0 +1,138 @@ +/* + * The Mana Server + * Copyright (C) 2007-2010 The Mana World Development Team + * + * This file is part of The Mana Server. + * + * The Mana Server 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 + * any later version. + * + * The Mana Server 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 The Mana Server. If not, see . + */ + +#ifndef TOKENCOLLECTOR_H +#define TOKENCOLLECTOR_H + +#include +#include +#include + +/** + * Base class containing the generic implementation of TokenCollector. + */ +class TokenCollectorBase +{ + struct Item + { + std::string token; /**< Cookie used by the client. */ + intptr_t data; /**< User data. */ + time_t timeStamp; /**< Creation time. */ + }; + + /** + * List containing client already connected. Newer clients are at the + * back of the list. + */ + std::list mPendingClients; + + /** + * List containing server data waiting for clients. Newer data are at + * the back of the list. + */ + std::list mPendingConnects; + + /** + * Time at which the TokenCollector performed its last check. + */ + time_t mLastCheck; + + protected: + + virtual void removedClient(intptr_t) = 0; + virtual void removedConnect(intptr_t) = 0; + virtual void foundMatch(intptr_t client, intptr_t connect) = 0; + TokenCollectorBase(); + virtual ~TokenCollectorBase(); + void insertClient(const std::string &, intptr_t); + void removeClient(intptr_t); + void insertConnect(const std::string &, intptr_t); + void removeOutdated(time_t); +}; + +/** + * Compile-time check to ensure that Client and ServerData are simple enough + * for TokenCollector. + */ +template< class T > struct _TC_CheckData; +template<> struct _TC_CheckData< int > {}; +template< class T > struct _TC_CheckData< T * > {}; + +/** + * A class for storing and matching tokens. + * + * The Handler class must provide three member functions: + * - deletePendingClient(Client), + * - deletePendingConnect(ServerData), and + * - tokenMatched(Client, ServerData). + * + * The delete members will be called whenever the collector considers that a + * token has become obsolete and it is about to remove it. + */ +template< class Handler, class Client, class ServerData > +class TokenCollector: private TokenCollectorBase +{ + + public: + + TokenCollector(Handler *h): mHandler(h) + { + _TC_CheckData ClientMustBeSimple; + (void)&ClientMustBeSimple; + _TC_CheckData ServerDataMustBeSimple; + (void)&ServerDataMustBeSimple; + } + + /** + * Checks if the server expected this client token. If so, calls + * Handler::tokenMatched. Otherwise marks the client as pending. + */ + void addPendingClient(const std::string &token, Client data) + { insertClient(token, (intptr_t)data); } + + /** + * Checks if a client already registered this token. If so, calls + * Handler::tokenMatched. Otherwise marks the data as pending. + */ + void addPendingConnect(const std::string &token, ServerData data) + { insertConnect(token, (intptr_t)data); } + + /** + * Removes a pending client. + * @note Does not call destroyPendingClient. + */ + void deletePendingClient(Client data) + { removeClient((intptr_t)data); } + + private: + + void removedClient(intptr_t data) + { mHandler->deletePendingClient((Client)data); } + + void removedConnect(intptr_t data) + { mHandler->deletePendingConnect((ServerData)data); } + + void foundMatch(intptr_t client, intptr_t data) + { mHandler->tokenMatched((Client)client, (ServerData)data); } + + Handler *mHandler; +}; + +#endif // TOKENCOLLECTOR_H diff --git a/src/utils/tokencollector.hpp b/src/utils/tokencollector.hpp deleted file mode 100644 index 5e4c3f2f..00000000 --- a/src/utils/tokencollector.hpp +++ /dev/null @@ -1,138 +0,0 @@ -/* - * The Mana Server - * Copyright (C) 2007-2010 The Mana World Development Team - * - * This file is part of The Mana Server. - * - * The Mana Server 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 - * any later version. - * - * The Mana Server 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 The Mana Server. If not, see . - */ - -#ifndef TOKENCOLLECTOR_HPP -#define TOKENCOLLECTOR_HPP - -#include -#include -#include - -/** - * Base class containing the generic implementation of TokenCollector. - */ -class TokenCollectorBase -{ - struct Item - { - std::string token; /**< Cookie used by the client. */ - intptr_t data; /**< User data. */ - time_t timeStamp; /**< Creation time. */ - }; - - /** - * List containing client already connected. Newer clients are at the - * back of the list. - */ - std::list mPendingClients; - - /** - * List containing server data waiting for clients. Newer data are at - * the back of the list. - */ - std::list mPendingConnects; - - /** - * Time at which the TokenCollector performed its last check. - */ - time_t mLastCheck; - - protected: - - virtual void removedClient(intptr_t) = 0; - virtual void removedConnect(intptr_t) = 0; - virtual void foundMatch(intptr_t client, intptr_t connect) = 0; - TokenCollectorBase(); - virtual ~TokenCollectorBase(); - void insertClient(const std::string &, intptr_t); - void removeClient(intptr_t); - void insertConnect(const std::string &, intptr_t); - void removeOutdated(time_t); -}; - -/** - * Compile-time check to ensure that Client and ServerData are simple enough - * for TokenCollector. - */ -template< class T > struct _TC_CheckData; -template<> struct _TC_CheckData< int > {}; -template< class T > struct _TC_CheckData< T * > {}; - -/** - * A class for storing and matching tokens. - * - * The Handler class must provide three member functions: - * - deletePendingClient(Client), - * - deletePendingConnect(ServerData), and - * - tokenMatched(Client, ServerData). - * - * The delete members will be called whenever the collector considers that a - * token has become obsolete and it is about to remove it. - */ -template< class Handler, class Client, class ServerData > -class TokenCollector: private TokenCollectorBase -{ - - public: - - TokenCollector(Handler *h): mHandler(h) - { - _TC_CheckData ClientMustBeSimple; - (void)&ClientMustBeSimple; - _TC_CheckData ServerDataMustBeSimple; - (void)&ServerDataMustBeSimple; - } - - /** - * Checks if the server expected this client token. If so, calls - * Handler::tokenMatched. Otherwise marks the client as pending. - */ - void addPendingClient(const std::string &token, Client data) - { insertClient(token, (intptr_t)data); } - - /** - * Checks if a client already registered this token. If so, calls - * Handler::tokenMatched. Otherwise marks the data as pending. - */ - void addPendingConnect(const std::string &token, ServerData data) - { insertConnect(token, (intptr_t)data); } - - /** - * Removes a pending client. - * @note Does not call destroyPendingClient. - */ - void deletePendingClient(Client data) - { removeClient((intptr_t)data); } - - private: - - void removedClient(intptr_t data) - { mHandler->deletePendingClient((Client)data); } - - void removedConnect(intptr_t data) - { mHandler->deletePendingConnect((ServerData)data); } - - void foundMatch(intptr_t client, intptr_t data) - { mHandler->tokenMatched((Client)client, (ServerData)data); } - - Handler *mHandler; -}; - -#endif // TOKENCOLLECTOR_HPP diff --git a/src/utils/tokendispenser.cpp b/src/utils/tokendispenser.cpp index 9aff9e4a..2cbf16d9 100644 --- a/src/utils/tokendispenser.cpp +++ b/src/utils/tokendispenser.cpp @@ -18,7 +18,7 @@ * along with The Mana Server. If not, see . */ -#include "utils/tokendispenser.hpp" +#include "utils/tokendispenser.h" #include diff --git a/src/utils/tokendispenser.h b/src/utils/tokendispenser.h new file mode 100644 index 00000000..d04d17b7 --- /dev/null +++ b/src/utils/tokendispenser.h @@ -0,0 +1,45 @@ +/* + * The Mana Server + * Copyright (C) 2007-2010 The Mana World Development Team + * + * This file is part of The Mana Server. + * + * The Mana Server 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 + * any later version. + * + * The Mana Server 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 The Mana Server. If not, see . + */ + +#ifndef TOKENDISPENSER_H +#define TOKENDISPENSER_H + +#define MAGIC_TOKEN_LENGTH 32 + +#include + +namespace utils +{ + /** + * \brief Returns a magic_token. + * + * The tokens are used for spanning a user's session across multiple + * servers. + * NOTE: Uniqueness is not guaranteed, store the account- or characterId + * with the token if that is an issue. + * NOTE: Not passed-by-reference by design. + * NOTE: Store the token in a variable in this namespace if you want to + * avoid 1 copy operation per use. + */ + std::string getMagicToken(); + +} // namespace utils + +#endif // TOKENDISPENSER_H diff --git a/src/utils/tokendispenser.hpp b/src/utils/tokendispenser.hpp deleted file mode 100644 index dc3173c7..00000000 --- a/src/utils/tokendispenser.hpp +++ /dev/null @@ -1,45 +0,0 @@ -/* - * The Mana Server - * Copyright (C) 2007-2010 The Mana World Development Team - * - * This file is part of The Mana Server. - * - * The Mana Server 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 - * any later version. - * - * The Mana Server 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 The Mana Server. If not, see . - */ - -#ifndef TOKENDISPENSER_HPP -#define TOKENDISPENSER_HPP - -#define MAGIC_TOKEN_LENGTH 32 - -#include - -namespace utils -{ - /** - * \brief Returns a magic_token. - * - * The tokens are used for spanning a user's session across multiple - * servers. - * NOTE: Uniqueness is not guaranteed, store the account- or characterId - * with the token if that is an issue. - * NOTE: Not passed-by-reference by design. - * NOTE: Store the token in a variable in this namespace if you want to - * avoid 1 copy operation per use. - */ - std::string getMagicToken(); - -} // namespace utils - -#endif // TOKENDISPENSER_HPP diff --git a/src/utils/xml.cpp b/src/utils/xml.cpp index 29202274..a4a5360e 100644 --- a/src/utils/xml.cpp +++ b/src/utils/xml.cpp @@ -19,11 +19,11 @@ * along with The Mana Server. If not, see . */ -#include "utils/xml.hpp" +#include "utils/xml.h" -#include "common/resourcemanager.hpp" +#include "common/resourcemanager.h" #include "utils/logger.h" -#include "utils/string.hpp" +#include "utils/string.h" #include #include diff --git a/src/utils/xml.h b/src/utils/xml.h new file mode 100644 index 00000000..eba88e56 --- /dev/null +++ b/src/utils/xml.h @@ -0,0 +1,107 @@ +/* + * XML utility functions + * Copyright (C) 2004-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * + * This file is part of The Mana Server. + * + * The Mana Server 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 + * any later version. + * + * The Mana Server 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 The Mana Server. If not, see . + */ + + +#ifndef XML_H +#define XML_H + +#include + +#include + +/** + * XML helper functions. + */ +namespace XML +{ + /** + * A helper class for parsing an XML document, which also cleans it up + * again (RAII). + */ + class Document + { + public: + /** + * Constructor that attempts to load the given file through the + * resource manager. Logs errors. + */ + Document(const std::string &filename, bool useResman = true); + + /** + * Constructor that attempts to load an XML document from memory. + * Does not log errors. + * + * @param data the string to parse as XML + * @param size the length of the string in bytes + */ + Document(const char *data, int size); + + /** + * Destructor. Frees the loaded XML file. + */ + ~Document(); + + /** + * Returns the root node of the document (or NULL if there was a + * load error). + */ + xmlNodePtr rootNode(); + + private: + xmlDocPtr mDoc; + }; + + /** + * Tells if a property from an xmlNodePtr exists. + */ + bool hasProperty(xmlNodePtr node, const char *name); + + /** + * Gets a boolean property from an xmlNodePtr. + */ + bool getBoolProperty(xmlNodePtr node, const char *name, bool def); + + /** + * Gets an integer property from an xmlNodePtr. + */ + int getProperty(xmlNodePtr node, const char *name, int def); + + /** + * Gets an floating point property from an xmlNodePtr. + */ + double getFloatProperty(xmlNodePtr node, const char *name, double def); + + /** + * Gets a string property from an xmlNodePtr. + */ + std::string getProperty(xmlNodePtr node, const char *name, + const std::string &def); + + /** + * Finds the first child node with the given name + */ + xmlNodePtr findFirstChildByName(xmlNodePtr parent, const char *name); +} + +#define for_each_xml_child_node(var, parent) \ + for (xmlNodePtr var = parent->xmlChildrenNode; var; var = var->next) + +#endif // XML_H diff --git a/src/utils/xml.hpp b/src/utils/xml.hpp deleted file mode 100644 index eba88e56..00000000 --- a/src/utils/xml.hpp +++ /dev/null @@ -1,107 +0,0 @@ -/* - * XML utility functions - * Copyright (C) 2004-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * - * This file is part of The Mana Server. - * - * The Mana Server 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 - * any later version. - * - * The Mana Server 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 The Mana Server. If not, see . - */ - - -#ifndef XML_H -#define XML_H - -#include - -#include - -/** - * XML helper functions. - */ -namespace XML -{ - /** - * A helper class for parsing an XML document, which also cleans it up - * again (RAII). - */ - class Document - { - public: - /** - * Constructor that attempts to load the given file through the - * resource manager. Logs errors. - */ - Document(const std::string &filename, bool useResman = true); - - /** - * Constructor that attempts to load an XML document from memory. - * Does not log errors. - * - * @param data the string to parse as XML - * @param size the length of the string in bytes - */ - Document(const char *data, int size); - - /** - * Destructor. Frees the loaded XML file. - */ - ~Document(); - - /** - * Returns the root node of the document (or NULL if there was a - * load error). - */ - xmlNodePtr rootNode(); - - private: - xmlDocPtr mDoc; - }; - - /** - * Tells if a property from an xmlNodePtr exists. - */ - bool hasProperty(xmlNodePtr node, const char *name); - - /** - * Gets a boolean property from an xmlNodePtr. - */ - bool getBoolProperty(xmlNodePtr node, const char *name, bool def); - - /** - * Gets an integer property from an xmlNodePtr. - */ - int getProperty(xmlNodePtr node, const char *name, int def); - - /** - * Gets an floating point property from an xmlNodePtr. - */ - double getFloatProperty(xmlNodePtr node, const char *name, double def); - - /** - * Gets a string property from an xmlNodePtr. - */ - std::string getProperty(xmlNodePtr node, const char *name, - const std::string &def); - - /** - * Finds the first child node with the given name - */ - xmlNodePtr findFirstChildByName(xmlNodePtr parent, const char *name); -} - -#define for_each_xml_child_node(var, parent) \ - for (xmlNodePtr var = parent->xmlChildrenNode; var; var = var->next) - -#endif // XML_H diff --git a/src/utils/zlib.cpp b/src/utils/zlib.cpp index e3d3c60a..3c5e8f3b 100644 --- a/src/utils/zlib.cpp +++ b/src/utils/zlib.cpp @@ -21,7 +21,7 @@ #include #include -#include "utils/zlib.hpp" +#include "utils/zlib.h" #include "utils/logger.h" diff --git a/src/utils/zlib.h b/src/utils/zlib.h new file mode 100644 index 00000000..f78aa26a --- /dev/null +++ b/src/utils/zlib.h @@ -0,0 +1,32 @@ +/* + * The Mana Server + * Copyright (C) 2006-2010 The Mana World Development Team + * + * This file is part of The Mana Server. + * + * The Mana Server 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 + * any later version. + * + * The Mana Server 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 The Mana Server. If not, see . + */ + +#ifndef ZLIB_H +#define ZLIB_H + +/** + * Inflates either zlib or gzip deflated memory. The inflated memory is + * expected to be freed by the caller. Returns true if the inflation was + * sucessful. + */ +bool inflateMemory(char *in, unsigned inLength, + char *&out, unsigned &outLength); + +#endif diff --git a/src/utils/zlib.hpp b/src/utils/zlib.hpp deleted file mode 100644 index 6d5347f1..00000000 --- a/src/utils/zlib.hpp +++ /dev/null @@ -1,32 +0,0 @@ -/* - * The Mana Server - * Copyright (C) 2006-2010 The Mana World Development Team - * - * This file is part of The Mana Server. - * - * The Mana Server 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 - * any later version. - * - * The Mana Server 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 The Mana Server. If not, see . - */ - -#ifndef ZLIB_HPP -#define ZLIB_HPP - -/** - * Inflates either zlib or gzip deflated memory. The inflated memory is - * expected to be freed by the caller. Returns true if the inflation was - * sucessful. - */ -bool inflateMemory(char *in, unsigned inLength, - char *&out, unsigned &outLength); - -#endif -- cgit v1.2.3-70-g09d2