summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilipp Sehmisch <crush@themanaworld.org>2009-02-24 01:12:46 +0100
committerPhilipp Sehmisch <crush@themanaworld.org>2009-02-24 01:12:46 +0100
commitf207bb487da57911350e037d5f894a037fbd74eb (patch)
tree872c96c7eeb1d4b8c3b8c83d76c9095ab445c1a3
parent14d0744bc55eaa147d3949891411db5914e2d3ec (diff)
downloadmanaserv-f207bb487da57911350e037d5f894a037fbd74eb.tar.gz
manaserv-f207bb487da57911350e037d5f894a037fbd74eb.tar.bz2
manaserv-f207bb487da57911350e037d5f894a037fbd74eb.tar.xz
manaserv-f207bb487da57911350e037d5f894a037fbd74eb.zip
Made a lot of hard-coded values configuration options
-rw-r--r--src/account-server/accounthandler.cpp51
-rw-r--r--src/chat-server/chatchannelmanager.cpp6
-rw-r--r--src/chat-server/post.cpp6
-rw-r--r--src/defines.h43
-rw-r--r--src/game-server/accountconnection.cpp8
-rw-r--r--src/game-server/monster.cpp4
-rw-r--r--src/game-server/state.cpp28
-rw-r--r--src/net/connectionhandler.cpp3
-rw-r--r--src/utils/stringfilter.cpp4
9 files changed, 66 insertions, 87 deletions
diff --git a/src/account-server/accounthandler.cpp b/src/account-server/accounthandler.cpp
index 13c280fd..cca17be9 100644
--- a/src/account-server/accounthandler.cpp
+++ b/src/account-server/accounthandler.cpp
@@ -195,7 +195,7 @@ static void handleLoginMessage(AccountClient &computer, MessageIn &msg)
return;
}
- if (accountHandler->getClientNumber() >= MAX_CLIENTS )
+ if (accountHandler->getClientNumber() >= (unsigned)Configuration::getValue("net_maxClients", 1000) )
{
reply.writeByte(ERRMSG_SERVER_FULL);
computer.send(reply);
@@ -289,6 +289,11 @@ static void handleRegisterMessage(AccountClient &computer, MessageIn &msg)
std::string username = msg.readString();
std::string password = msg.readString();
std::string email = msg.readString();
+ int minClientVersion = Configuration::getValue("clientVersion", 0);
+ unsigned minNameLength = Configuration::getValue("account_minNameLength", 4);
+ unsigned maxNameLength = Configuration::getValue("account_maxNameLength", 15);
+ unsigned minPasswordLength = Configuration::getValue("account_minPasswordLength", 6);
+ unsigned maxPasswordLength = Configuration::getValue("account_maxPasswordLength", 25);
MessageOut reply(APMSG_REGISTER_RESPONSE);
@@ -296,7 +301,7 @@ static void handleRegisterMessage(AccountClient &computer, MessageIn &msg)
{
reply.writeByte(ERRMSG_FAILURE);
}
- else if (clientVersion < Configuration::getValue("clientVersion", 0))
+ else if (clientVersion < minClientVersion)
{
reply.writeByte(REGISTER_INVALID_VERSION);
}
@@ -308,13 +313,13 @@ static void handleRegisterMessage(AccountClient &computer, MessageIn &msg)
{
reply.writeByte(ERRMSG_INVALID_ARGUMENT);
}
- else if ((username.length() < MIN_LOGIN_LENGTH) ||
- (username.length() > MAX_LOGIN_LENGTH))
+ else if (username.length() < minNameLength ||
+ username.length() > maxNameLength)
{
reply.writeByte(ERRMSG_INVALID_ARGUMENT);
}
- else if (password.length() < MIN_PASSWORD_LENGTH ||
- password.length() > MAX_PASSWORD_LENGTH)
+ else if (password.length() < minPasswordLength ||
+ password.length() > maxPasswordLength)
{
reply.writeByte(ERRMSG_INVALID_ARGUMENT);
}
@@ -488,6 +493,14 @@ static void handleCharacterCreateMessage(AccountClient &computer, MessageIn &msg
int hairStyle = msg.readByte();
int hairColor = msg.readByte();
int gender = msg.readByte();
+ int numHairStyles = Configuration::getValue("char_numHairStyles", 15);
+ int numHairColors = Configuration::getValue("char_numHairColors", 9);
+ int numGenders = Configuration::getValue("char_numGenders", 2);
+ unsigned minNameLength = Configuration::getValue("char_minNameLength", 4);
+ unsigned maxNameLength = Configuration::getValue("char_maxNameLength", 25);
+ unsigned maxCharacters = Configuration::getValue("char_maxCharacters", 3);
+ unsigned startingPoints = Configuration::getValue("char_startingPoints", 60);
+
MessageOut reply(APMSG_CHAR_CREATE_RESPONSE);
@@ -504,20 +517,20 @@ static void handleCharacterCreateMessage(AccountClient &computer, MessageIn &msg
{
reply.writeByte(ERRMSG_INVALID_ARGUMENT);
}
- else if (hairStyle > MAX_HAIRSTYLE_VALUE)
+ else if (hairStyle > numHairStyles)
{
reply.writeByte(CREATE_INVALID_HAIRSTYLE);
}
- else if (hairColor > MAX_HAIRCOLOR_VALUE)
+ else if (hairColor > numHairColors)
{
reply.writeByte(CREATE_INVALID_HAIRCOLOR);
}
- else if (gender > MAX_GENDER_VALUE)
+ else if (gender > numGenders)
{
reply.writeByte(CREATE_INVALID_GENDER);
}
- else if ((name.length() < MIN_CHARACTER_LENGTH) ||
- (name.length() > MAX_CHARACTER_LENGTH))
+ else if ((name.length() < minNameLength) ||
+ (name.length() > maxNameLength))
{
reply.writeByte(ERRMSG_INVALID_ARGUMENT);
}
@@ -532,7 +545,7 @@ static void handleCharacterCreateMessage(AccountClient &computer, MessageIn &msg
// An account shouldn't have more than MAX_OF_CHARACTERS characters.
Characters &chars = acc->getCharacters();
- if (chars.size() >= MAX_OF_CHARACTERS)
+ if (chars.size() >= maxCharacters)
{
reply.writeByte(CREATE_TOO_MUCH_CHARACTERS);
computer.send(reply);
@@ -557,11 +570,11 @@ static void handleCharacterCreateMessage(AccountClient &computer, MessageIn &msg
if (attributes[i] <= 0) validNonZeroAttributes = false;
}
- if (totalAttributes > POINTS_TO_DISTRIBUTES_AT_LVL1)
+ if (totalAttributes > startingPoints)
{
reply.writeByte(CREATE_ATTRIBUTES_TOO_HIGH);
}
- else if (totalAttributes < POINTS_TO_DISTRIBUTES_AT_LVL1)
+ else if (totalAttributes < startingPoints)
{
reply.writeByte(CREATE_ATTRIBUTES_TOO_LOW);
}
@@ -581,9 +594,9 @@ static void handleCharacterCreateMessage(AccountClient &computer, MessageIn &msg
newCharacter->setGender(gender);
newCharacter->setHairStyle(hairStyle);
newCharacter->setHairColor(hairColor);
- newCharacter->setMapId(Configuration::getValue("defaultMap", 1));
- Point startingPos(Configuration::getValue("startX", 1024),
- Configuration::getValue("startY", 1024));
+ newCharacter->setMapId(Configuration::getValue("char_startMap", 1));
+ Point startingPos(Configuration::getValue("char_startX", 1024),
+ Configuration::getValue("char_startY", 1024));
newCharacter->setPosition(startingPos);
acc->addCharacter(newCharacter);
@@ -651,9 +664,9 @@ static void handleCharacterSelectMessage(AccountClient &computer, MessageIn &msg
reply.writeShort(port);
// TODO: get correct address and port for the chat server
- reply.writeString(Configuration::getValue("accountServerAddress",
+ reply.writeString(Configuration::getValue("net_accountServerAddress",
"localhost"));
- reply.writeShort(Configuration::getValue("accountServerPort",
+ reply.writeShort(Configuration::getValue("net_accountServerPort",
DEFAULT_SERVER_PORT) + 2);
GameServerHandler::registerClient(magic_token, selectedChar);
diff --git a/src/chat-server/chatchannelmanager.cpp b/src/chat-server/chatchannelmanager.cpp
index 580726fc..d78e4bb2 100644
--- a/src/chat-server/chatchannelmanager.cpp
+++ b/src/chat-server/chatchannelmanager.cpp
@@ -28,6 +28,7 @@
#include "chat-server/chatclient.hpp"
#include "chat-server/chathandler.hpp"
#include "chat-server/guildmanager.hpp"
+#include "common/configuration.hpp"
#include "utils/stringfilter.h"
ChatChannelManager::ChatChannelManager() : mNextChannelId(1)
@@ -65,13 +66,14 @@ bool ChatChannelManager::tryNewPublicChannel(const std::string &name)
}
// Checking strings for length and double quotes
+ unsigned maxNameLength = Configuration::getValue("chat_maxChannelNameLength", 150);
if (name.empty() ||
- name.length() > MAX_CHANNEL_NAME ||
+ name.length() > maxNameLength ||
stringFilter->findDoubleQuotes(name))
{
return false;
}
- else if (guildManager->doesExist(name) ||
+ else if (guildManager->doesExist(name) ||
channelExists(name))
{
// Channel already exists
diff --git a/src/chat-server/post.cpp b/src/chat-server/post.cpp
index 8335c1d6..e3f4c4f0 100644
--- a/src/chat-server/post.cpp
+++ b/src/chat-server/post.cpp
@@ -22,7 +22,7 @@
#include "post.hpp"
#include "../account-server/character.hpp"
-#include "../defines.h"
+#include "../common/configuration.hpp"
Letter::Letter(unsigned int type, Character *sender, Character *receiver)
: mId(0), mType(type), mSender(sender), mReceiver(receiver)
@@ -62,7 +62,7 @@ std::string Letter::getContents()
bool Letter::addAttachment(InventoryItem item)
{
- if (mAttachments.size() > MAX_ATTACHMENTS)
+ if (mAttachments.size() > Configuration::getValue("mail_maxAttachments", 3))
{
return false;
}
@@ -102,7 +102,7 @@ Post::~Post()
bool Post::addLetter(Letter *letter)
{
- if (mLetters.size() > MAX_LETTERS)
+ if (mLetters.size() > Configuration::getValue("mail_maxLetters", 10))
{
return false;
}
diff --git a/src/defines.h b/src/defines.h
index 9f64c1fa..b03d2bbd 100644
--- a/src/defines.h
+++ b/src/defines.h
@@ -56,53 +56,10 @@ enum
GAL_OWNER = 255
};
-enum
-{
- // Network related
- MAX_CLIENTS = 1024,
-
- // Chat related
-/**
- * N.B: Private channels can't have an id less
- * than MAX_PUBLIC_CHANNELS_RANGE.
- */
- MAX_PUBLIC_CHANNELS_RANGE = 1000,
- MAX_PRIVATE_CHANNELS_RANGE = 10000,
- MAX_CHANNEL_NAME = 15,
- MAX_CHANNEL_ANNOUNCEMENT = 150,
- MAX_CHANNEL_PASSWORD = 12,
-
- // Post related
- MAX_ATTACHMENTS = 3,
- MAX_LETTERS = 10,
-
- // Registering related
- MIN_LOGIN_LENGTH = 4,
- MAX_LOGIN_LENGTH = 16,
- MIN_PASSWORD_LENGTH = 4,
- MAX_PASSWORD_LENGTH = 25,
- MIN_EMAIL_LENGTH = 7,
- MAX_EMAIL_LENGTH = 50,
-
- // Character related
- MIN_CHARACTER_LENGTH = 4,
- MAX_CHARACTER_LENGTH = 25,
- MAX_OF_CHARACTERS = 3,
- MAX_HAIRSTYLE_VALUE = 15,
- MAX_HAIRCOLOR_VALUE = 9,
- MAX_GENDER_VALUE = 2,
-
-/**
- * Points to give to a brand new character
- */
- POINTS_TO_DISTRIBUTES_AT_LVL1 = 60,
-
// Screen Related
/**
* Determine the area in which a character is aware of other beings
*/
- AROUND_AREA = 320
-};
/**
* Enumerated type for communicated messages:
diff --git a/src/game-server/accountconnection.cpp b/src/game-server/accountconnection.cpp
index c2b5a78e..a69c5eae 100644
--- a/src/game-server/accountconnection.cpp
+++ b/src/game-server/accountconnection.cpp
@@ -51,9 +51,9 @@ AccountConnection::~AccountConnection()
bool AccountConnection::start()
{
const std::string accountServerAddress =
- Configuration::getValue("accountServerAddress", "localhost");
+ Configuration::getValue("net_accountServerAddress", "localhost");
const int accountServerPort =
- Configuration::getValue("accountServerPort", DEFAULT_SERVER_PORT) + 1;
+ Configuration::getValue("net_accountServerPort", DEFAULT_SERVER_PORT) + 1;
if (!Connection::start(accountServerAddress, accountServerPort))
{
@@ -64,9 +64,9 @@ bool AccountConnection::start()
LOG_INFO("Connection established to the account server.");
const std::string gameServerAddress =
- Configuration::getValue("gameServerAddress", "localhost");
+ Configuration::getValue("net_gameServerAddress", "localhost");
const int gameServerPort =
- Configuration::getValue("gameServerPort", DEFAULT_SERVER_PORT + 3);
+ Configuration::getValue("net_gameServerPort", DEFAULT_SERVER_PORT + 3);
// Register with the account server and send the list of maps we handle
MessageOut msg(GAMSG_REGISTER);
diff --git a/src/game-server/monster.cpp b/src/game-server/monster.cpp
index 14f60c03..70e7ab1f 100644
--- a/src/game-server/monster.cpp
+++ b/src/game-server/monster.cpp
@@ -20,6 +20,7 @@
#include "game-server/monster.hpp"
+#include "common/configuration.hpp"
#include "game-server/character.hpp"
#include "game-server/collisiondetection.hpp"
#include "game-server/item.hpp"
@@ -166,7 +167,8 @@ void Monster::update()
Direction bestAttackDirection = DIRECTION_DOWN;
// Iterate through objects nearby
- for (MovingObjectIterator i(getMap()->getAroundCharacterIterator(this, AROUND_AREA)); i; ++i)
+ int aroundArea = Configuration::getValue("visualRange", 320);
+ for (MovingObjectIterator i(getMap()->getAroundCharacterIterator(this, aroundArea)); i; ++i)
{
// We only want to attack player characters
if ((*i)->getType() != OBJECT_CHARACTER) continue;
diff --git a/src/game-server/state.cpp b/src/game-server/state.cpp
index 410028a4..43c242a6 100644
--- a/src/game-server/state.cpp
+++ b/src/game-server/state.cpp
@@ -25,6 +25,7 @@
#include "defines.h"
#include "point.h"
+#include "common/configuration.hpp"
#include "game-server/accountconnection.hpp"
#include "game-server/gamehandler.hpp"
#include "game-server/inventory.hpp"
@@ -162,9 +163,10 @@ static void informPlayer(MapComposite *map, Character *p)
MessageOut damageMsg(GPMSG_BEINGS_DAMAGE);
Point pold = p->getOldPosition(), ppos = p->getPosition();
int pid = p->getPublicID(), pflags = p->getUpdateFlags();
+ int visualRange = Configuration::getValue("visualRange", 320);
// Inform client about activities of other beings near its character
- for (MovingObjectIterator i(map->getAroundCharacterIterator(p, AROUND_AREA)); i; ++i)
+ for (MovingObjectIterator i(map->getAroundCharacterIterator(p, visualRange)); i; ++i)
{
MovingObject *o = *i;
@@ -174,9 +176,9 @@ static void informPlayer(MapComposite *map, Character *p)
int flags = 0;
// Check if the character p and the moving object o are around.
- bool wereInRange = pold.inRangeOf(oold, AROUND_AREA) &&
+ bool wereInRange = pold.inRangeOf(oold, visualRange) &&
!((pflags | oflags) & UPDATEFLAG_NEW_ON_MAP);
- bool willBeInRange = ppos.inRangeOf(opos, AROUND_AREA);
+ bool willBeInRange = ppos.inRangeOf(opos, visualRange);
if (!wereInRange && !willBeInRange)
{
@@ -369,7 +371,7 @@ static void informPlayer(MapComposite *map, Character *p)
// Inform client about items on the ground around its character
MessageOut itemMsg(GPMSG_ITEMS);
- for (FixedObjectIterator i(map->getAroundCharacterIterator(p, AROUND_AREA)); i; ++i)
+ for (FixedObjectIterator i(map->getAroundCharacterIterator(p, visualRange)); i; ++i)
{
assert((*i)->getType() == OBJECT_ITEM ||
(*i)->getType() == OBJECT_EFFECT);
@@ -377,8 +379,8 @@ static void informPlayer(MapComposite *map, Character *p)
Object *o = *i;
Point opos = o->getPosition();
int oflags = o->getUpdateFlags();
- bool willBeInRange = ppos.inRangeOf(opos, AROUND_AREA);
- bool wereInRange = pold.inRangeOf(opos, AROUND_AREA) &&
+ bool willBeInRange = ppos.inRangeOf(opos, visualRange);
+ bool wereInRange = pold.inRangeOf(opos, visualRange) &&
!((pflags | oflags) & UPDATEFLAG_NEW_ON_MAP);
if (willBeInRange ^ wereInRange)
@@ -581,6 +583,7 @@ void GameState::remove(Thing *ptr)
{
assert(!dbgLockObjects);
MapComposite *map = ptr->getMap();
+ int visualRange = Configuration::getValue("visualRange", 320);
ptr->removed();
@@ -600,9 +603,9 @@ void GameState::remove(Thing *ptr)
msg.writeShort(obj->getPublicID());
Point objectPos = obj->getPosition();
- for (CharacterIterator p(map->getAroundObjectIterator(obj, AROUND_AREA)); p; ++p)
+ for (CharacterIterator p(map->getAroundObjectIterator(obj, visualRange)); p; ++p)
{
- if (*p != obj && objectPos.inRangeOf((*p)->getPosition(), AROUND_AREA))
+ if (*p != obj && objectPos.inRangeOf((*p)->getPosition(), visualRange))
{
gameHandler->sendTo(*p, msg);
}
@@ -617,9 +620,9 @@ void GameState::remove(Thing *ptr)
msg.writeShort(pos.x);
msg.writeShort(pos.y);
- for (CharacterIterator p(map->getAroundObjectIterator(obj, AROUND_AREA)); p; ++p)
+ for (CharacterIterator p(map->getAroundObjectIterator(obj, visualRange)); p; ++p)
{
- if (pos.inRangeOf((*p)->getPosition(), AROUND_AREA))
+ if (pos.inRangeOf((*p)->getPosition(), visualRange))
{
gameHandler->sendTo(*p, msg);
}
@@ -693,10 +696,11 @@ void GameState::enqueueWarp(Character *ptr, MapComposite *m, int x, int y)
void GameState::sayAround(Object *obj, std::string const &text)
{
Point speakerPosition = obj->getPosition();
+ int visualRange = Configuration::getValue("visualRange", 320);
- for (CharacterIterator i(obj->getMap()->getAroundObjectIterator(obj, AROUND_AREA)); i; ++i)
+ for (CharacterIterator i(obj->getMap()->getAroundObjectIterator(obj, visualRange)); i; ++i)
{
- if (speakerPosition.inRangeOf((*i)->getPosition(), AROUND_AREA))
+ if (speakerPosition.inRangeOf((*i)->getPosition(), visualRange))
{
sayTo(*i, obj, text);
}
diff --git a/src/net/connectionhandler.cpp b/src/net/connectionhandler.cpp
index 3f3bb72a..123dc0b7 100644
--- a/src/net/connectionhandler.cpp
+++ b/src/net/connectionhandler.cpp
@@ -23,6 +23,7 @@
#include "net/connectionhandler.hpp"
#include "defines.h"
+#include "common/configuration.hpp"
#include "net/bandwidth.hpp"
#include "net/messagein.hpp"
#include "net/messageout.hpp"
@@ -38,7 +39,7 @@ bool ConnectionHandler::startListen(enet_uint16 port)
LOG_INFO("Listening on port " << port << "...");
host = enet_host_create(
&address /* the address to bind the server host to */,
- MAX_CLIENTS /* allow up to MAX_CLIENTS connections */,
+ Configuration::getValue("net_maxClients", 1000) /* allowed connections */,
0 /* assume any amount of incoming bandwidth */,
0 /* assume any amount of outgoing bandwidth */);
diff --git a/src/utils/stringfilter.cpp b/src/utils/stringfilter.cpp
index b1df68f4..93be8b3e 100644
--- a/src/utils/stringfilter.cpp
+++ b/src/utils/stringfilter.cpp
@@ -104,8 +104,8 @@ bool StringFilter::filterContent(const std::string& text)
bool StringFilter::isEmailValid(const std::string& email)
{
// Testing Email validity
- if ((email.length() < MIN_EMAIL_LENGTH) ||
- (email.length() > MAX_EMAIL_LENGTH))
+ if ((email.length() < Configuration::getValue("account_minEmailLength", 7)) ||
+ (email.length() > Configuration::getValue("account_maxEmailLength", 128)))
{
return false;
}