From eff04b5ddb0b00eeed191382aa9d55bf0f56c2a7 Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Wed, 2 Aug 2006 23:17:03 +0000 Subject: Defined the GameClient class in its own module. --- src/Makefile.am | 2 ++ src/gameclient.cpp | 56 ++++++++++++++++++++++++++++++++++++++++++ src/gameclient.h | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++ src/gamehandler.cpp | 65 ++---------------------------------------------- 4 files changed, 131 insertions(+), 63 deletions(-) create mode 100644 src/gameclient.cpp create mode 100644 src/gameclient.h (limited to 'src') 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 + +#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 + +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 #include #include +#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); } -- cgit v1.2.3-70-g09d2