From c984899f52f11d7148785c9a6cb377b23da87228 Mon Sep 17 00:00:00 2001 From: Christian Klinger Date: Thu, 19 May 2016 15:55:02 +0200 Subject: Closes bug #2807. (And also cleans the code (a bit)) --- src/server/util/global.cpp | 16 ++++++++++++++++ src/server/util/global.h | 9 ++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) (limited to 'src/server/util') diff --git a/src/server/util/global.cpp b/src/server/util/global.cpp index 3021ca9..8bb89d0 100644 --- a/src/server/util/global.cpp +++ b/src/server/util/global.cpp @@ -6,6 +6,7 @@ */ #include "global.h" +#include QString Global::_sessionName = QString(); QByteArray Global::_sessionNameArray = QByteArray(); @@ -34,3 +35,18 @@ void Global::setCurrentRoom(QString room) { Global::_currentRoom = room; } + +const Room* Global::getCurrentRoom() { + if (_rooms.contains(_currentRoom)) { + qDebug() << "returning actual room: " << _currentRoom; + return _rooms[_currentRoom]; + } else { + qDebug() << "couldn't find the room name " << _currentRoom << " in the _rooms-Map"; + static Room* defaultRoom = NULL; + if (defaultRoom == NULL) { + defaultRoom = new Room(QMap(), QSize(8, 6), QSize(1,1), ""); + } + qDebug() << "returned default room"; + return defaultRoom; + } +} diff --git a/src/server/util/global.h b/src/server/util/global.h index c258b4a..f9dc327 100644 --- a/src/server/util/global.h +++ b/src/server/util/global.h @@ -28,8 +28,7 @@ struct Room { QString imagePath; }; -class Global -{ +class Global { private: Global(){} ~Global(){} @@ -51,7 +50,11 @@ public: } static void setCurrentRoom(QString room); - static const QString& getCurrentRoom() { return _currentRoom; } + static const QString& getCurrentRoomName() { return _currentRoom; } + + /* returns a pointer to the current room or a pointer to the constant "defaultRoom". + * (NEVER returns NULL or undefined) */ + static const Room* getCurrentRoom(); }; #endif /* GLOBAL_H_ */ -- cgit v1.2.3-55-g7522