summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2006-08-02 23:17:03 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2006-08-02 23:17:03 +0000
commiteff04b5ddb0b00eeed191382aa9d55bf0f56c2a7 (patch)
tree0dde25e7b720a23fb68a1820bd1554f1651d251f /src
parent9400a13b541f60d1c09ca82eeb71e1c9c420eb91 (diff)
downloadmanaserv-eff04b5ddb0b00eeed191382aa9d55bf0f56c2a7.tar.gz
manaserv-eff04b5ddb0b00eeed191382aa9d55bf0f56c2a7.tar.bz2
manaserv-eff04b5ddb0b00eeed191382aa9d55bf0f56c2a7.tar.xz
manaserv-eff04b5ddb0b00eeed191382aa9d55bf0f56c2a7.zip
Defined the GameClient class in its own module.
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am2
-rw-r--r--src/gameclient.cpp56
-rw-r--r--src/gameclient.h71
-rw-r--r--src/gamehandler.cpp65
4 files changed, 131 insertions, 63 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index dcf73896..7b04c953 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -28,6 +28,8 @@ tmwserv_SOURCES = main.cpp \
chatchannelmanager.cpp \
connectionhandler.h \
connectionhandler.cpp \
+ gameclient.h \
+ gameclient.cpp \
gamehandler.h \
gamehandler.cpp \
state.h \
diff --git a/src/gameclient.cpp b/src/gameclient.cpp
new file mode 100644
index 00000000..88deacad
--- /dev/null
+++ b/src/gameclient.cpp
@@ -0,0 +1,56 @@
+/*
+ * The Mana World Server
+ * Copyright 2004 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * The Mana World 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 World 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 World; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id$
+ */
+
+#include "gameclient.h"
+
+#include <cassert>
+
+#include "state.h"
+#include "gamehandler.h"
+
+GameClient::GameClient(GameHandler *handler, ENetPeer *peer):
+ NetComputer(handler, peer),
+ mCharacterPtr(NULL)
+{
+}
+
+GameClient::~GameClient()
+{
+ unsetCharacter();
+}
+
+void GameClient::setCharacter(PlayerPtr ch)
+{
+ assert(mCharacterPtr.get() == NULL);
+ mCharacterPtr = ch;
+ gameState->addObject(ObjectPtr(mCharacterPtr));
+ gameState->informPlayer(mCharacterPtr);
+}
+
+void GameClient::unsetCharacter()
+{
+ if (mCharacterPtr.get() == NULL) return;
+ // remove being from world
+ gameState->removeObject(ObjectPtr(mCharacterPtr));
+ mCharacterPtr = PlayerPtr(NULL);
+}
diff --git a/src/gameclient.h b/src/gameclient.h
new file mode 100644
index 00000000..756b224d
--- /dev/null
+++ b/src/gameclient.h
@@ -0,0 +1,71 @@
+/*
+ * The Mana World Server
+ * Copyright 2004 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * The Mana World 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 World 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 World; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id$
+ */
+
+#ifndef _TMWSERV_GAMECLIENT_H_
+#define _TMWSERV_GAMECLIENT_H_
+
+#include "netcomputer.h"
+
+#include "being.h"
+
+#include <enet/enet.h>
+
+class GameHandler;
+
+/**
+ * A connected computer with an associated character.
+ */
+class GameClient: public NetComputer
+{
+ public:
+ /**
+ * Constructor.
+ */
+ GameClient(GameHandler *handler, ENetPeer *peer);
+
+ /**
+ * Destructor.
+ */
+ ~GameClient();
+
+ /**
+ * Set the selected character associated with connection.
+ */
+ void setCharacter(PlayerPtr ch);
+
+ /**
+ * Deselect the character associated with connection.
+ */
+ void unsetCharacter();
+
+ /**
+ * Get character associated with the connection.
+ */
+ PlayerPtr getCharacter() { return mCharacterPtr; }
+
+ private:
+ /** Character associated with the conneciton. */
+ PlayerPtr mCharacterPtr;
+};
+
+#endif
diff --git a/src/gamehandler.cpp b/src/gamehandler.cpp
index 8fd89919..ef0ed924 100644
--- a/src/gamehandler.cpp
+++ b/src/gamehandler.cpp
@@ -23,10 +23,10 @@
#include "gamehandler.h"
-#include <cassert>
#include <iostream>
#include <map>
+#include "gameclient.h"
#include "messagein.h"
#include "messageout.h"
#include "netcomputer.h"
@@ -34,67 +34,6 @@
#include "state.h"
#include "utils/logger.h"
-class GameClient: public NetComputer
-{
- public:
- /**
- * Constructor.
- */
- GameClient(GameHandler *, ENetPeer *);
-
- /**
- * Destructor.
- */
- ~GameClient();
-
- /**
- * Set the selected character associated with connection.
- */
- void setCharacter(PlayerPtr ch);
-
- /**
- * Deselect the character associated with connection.
- */
- void unsetCharacter();
-
- /**
- * Get character associated with the connection.
- */
- PlayerPtr getCharacter() { return mCharacterPtr; }
-
- private:
- /** Character associated with the conneciton. */
- PlayerPtr mCharacterPtr;
-};
-
-GameClient::GameClient(GameHandler *handler, ENetPeer *peer):
- NetComputer(handler, peer),
- mCharacterPtr(NULL)
-{
-}
-
-GameClient::~GameClient()
-{
- unsetCharacter();
-}
-
-
-void GameClient::setCharacter(PlayerPtr ch)
-{
- assert(mCharacterPtr.get() == NULL);
- mCharacterPtr = ch;
- gameState->addObject(ObjectPtr(mCharacterPtr));
- gameState->informPlayer(mCharacterPtr);
-}
-
-void GameClient::unsetCharacter()
-{
- if (mCharacterPtr.get() == NULL) return;
- // remove being from world
- gameState->removeObject(ObjectPtr(mCharacterPtr));
- mCharacterPtr = PlayerPtr(NULL);
-}
-
struct GamePendingLogin
{
PlayerPtr character;
@@ -222,7 +161,7 @@ void GameHandler::processMessage(NetComputer *comp, MessageIn &message)
// use item
// this should execute a script which will do the appropriate action
// (the script will determine if the item is 1 use only)
- result.writeByte(ERRMSG_OK);
+ result.writeByte(ERRMSG_OK);
} else {
result.writeByte(ERRMSG_FAILURE);
}