summaryrefslogtreecommitdiff
path: root/src/game-server/accountconnection.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/game-server/accountconnection.cpp')
-rw-r--r--src/game-server/accountconnection.cpp58
1 files changed, 32 insertions, 26 deletions
diff --git a/src/game-server/accountconnection.cpp b/src/game-server/accountconnection.cpp
index 8b517f54..e52393bd 100644
--- a/src/game-server/accountconnection.cpp
+++ b/src/game-server/accountconnection.cpp
@@ -102,11 +102,12 @@ bool AccountConnection::start(int gameServerPort)
return true;
}
-void AccountConnection::sendCharacterData(Character *p)
+void AccountConnection::sendCharacterData(Entity *p)
{
MessageOut msg(GAMSG_PLAYER_DATA);
- msg.writeInt32(p->getDatabaseID());
- serializeCharacterData(*p, msg);
+ auto *characterComponent = p->getComponent<CharacterComponent>();
+ msg.writeInt32(characterComponent->getDatabaseID());
+ serializeCharacterData(CharacterData(p, characterComponent), msg);
send(msg);
}
@@ -154,8 +155,11 @@ void AccountConnection::processMessage(MessageIn &msg)
case AGMSG_PLAYER_ENTER:
{
std::string token = msg.readString(MAGIC_TOKEN_LENGTH);
- Character *ptr = new Character(msg);
- gameHandler->addPendingCharacter(token, ptr);
+ Entity *character = new Entity(OBJECT_CHARACTER);
+ character->addComponent(new ActorComponent(*character));
+ character->addComponent(new BeingComponent(*character));
+ character->addComponent(new CharacterComponent(*character, msg));
+ gameHandler->addPendingCharacter(token, character);
} break;
case AGMSG_ACTIVE_MAP:
@@ -187,16 +191,15 @@ void AccountConnection::processMessage(MessageIn &msg)
if (ItemClass *ic = itemManager->getItem(itemId))
{
- Item *item = new Item(ic, amount);
- item->setMap(m);
- Point dst(posX, posY);
- item->setPosition(dst);
+ Entity *item = Item::create(m,
+ Point(posX, posY),
+ ic, amount);
if (!GameState::insertOrDelete(item))
{
// The map is full.
LOG_WARN("Couldn't add floor item(s) " << itemId
- << " into map " << mapId);
+ << " into map " << mapId);
return;
}
}
@@ -242,7 +245,7 @@ void AccountConnection::processMessage(MessageIn &msg)
case CGMSG_POST_RESPONSE:
{
// get the character
- Character *character = postMan->getCharacter(msg.readInt32());
+ Entity *character = postMan->getCharacter(msg.readInt32());
// check character is still valid
if (!character)
@@ -260,7 +263,7 @@ void AccountConnection::processMessage(MessageIn &msg)
case CGMSG_STORE_POST_RESPONSE:
{
// get character
- Character *character = postMan->getCharacter(msg.readInt32());
+ Entity *character = postMan->getCharacter(msg.readInt32());
// check character is valid
if (!character)
@@ -289,21 +292,21 @@ void AccountConnection::playerReconnectAccount(int id,
send(msg);
}
-void AccountConnection::requestCharacterVar(Character *ch,
+void AccountConnection::requestCharacterVar(Entity *ch,
const std::string &name)
{
MessageOut msg(GAMSG_GET_VAR_CHR);
- msg.writeInt32(ch->getDatabaseID());
+ msg.writeInt32(ch->getComponent<CharacterComponent>()->getDatabaseID());
msg.writeString(name);
send(msg);
}
-void AccountConnection::updateCharacterVar(Character *ch,
+void AccountConnection::updateCharacterVar(Entity *ch,
const std::string &name,
const std::string &value)
{
MessageOut msg(GAMSG_SET_VAR_CHR);
- msg.writeInt32(ch->getDatabaseID());
+ msg.writeInt32(ch->getComponent<CharacterComponent>()->getDatabaseID());
msg.writeString(name);
msg.writeString(value);
send(msg);
@@ -329,10 +332,10 @@ void AccountConnection::updateWorldVar(const std::string &name,
send(msg);
}
-void AccountConnection::banCharacter(Character *ch, int duration)
+void AccountConnection::banCharacter(Entity *ch, int duration)
{
MessageOut msg(GAMSG_BAN_PLAYER);
- msg.writeInt32(ch->getDatabaseID());
+ msg.writeInt32(ch->getComponent<CharacterComponent>()->getDatabaseID());
msg.writeInt32(duration);
send(msg);
}
@@ -358,9 +361,12 @@ void AccountConnection::sendStatistics()
switch (t->getType())
{
case OBJECT_CHARACTER:
- players.push_back
- (static_cast< Character * >(t)->getDatabaseID());
+ {
+ auto *characterComponent =
+ t->getComponent<CharacterComponent>();
+ players.push_back(characterComponent->getDatabaseID());
break;
+ }
case OBJECT_MONSTER:
++nbMonsters;
break;
@@ -380,13 +386,13 @@ void AccountConnection::sendStatistics()
send(msg);
}
-void AccountConnection::sendPost(Character *c, MessageIn &msg)
+void AccountConnection::sendPost(Entity *c, MessageIn &msg)
{
// send message to account server with id of sending player,
// the id of receiving player, the letter receiver and contents, and attachments
LOG_DEBUG("Sending GCMSG_STORE_POST.");
MessageOut out(GCMSG_STORE_POST);
- out.writeInt32(c->getDatabaseID());
+ out.writeInt32(c->getComponent<CharacterComponent>()->getDatabaseID());
out.writeString(msg.readString()); // name of receiver
out.writeString(msg.readString()); // content of letter
while (msg.getUnreadLength()) // attachments
@@ -398,7 +404,7 @@ void AccountConnection::sendPost(Character *c, MessageIn &msg)
send(out);
}
-void AccountConnection::getPost(Character *c)
+void AccountConnection::getPost(Entity *c)
{
// let the postman know to expect some post for this character
postMan->addCharacter(c);
@@ -406,14 +412,14 @@ void AccountConnection::getPost(Character *c)
// send message to account server with id of retrieving player
LOG_DEBUG("Sending GCMSG_REQUEST_POST");
MessageOut out(GCMSG_REQUEST_POST);
- out.writeInt32(c->getDatabaseID());
+ out.writeInt32(c->getComponent<CharacterComponent>()->getDatabaseID());
send(out);
}
-void AccountConnection::changeAccountLevel(Character *c, int level)
+void AccountConnection::changeAccountLevel(Entity *c, int level)
{
MessageOut msg(GAMSG_CHANGE_ACCOUNT_LEVEL);
- msg.writeInt32(c->getDatabaseID());
+ msg.writeInt32(c->getComponent<CharacterComponent>()->getDatabaseID());
msg.writeInt16(level);
send(msg);
}