summaryrefslogtreecommitdiffstats
path: root/src/server/util
diff options
context:
space:
mode:
authorChristian Klinger2016-05-19 15:55:02 +0200
committerChristian Klinger2016-05-19 15:55:02 +0200
commitc984899f52f11d7148785c9a6cb377b23da87228 (patch)
tree220acd35b0d8b8384437b0de7f4f7c36d742259f /src/server/util
parentadded example switch scripts. (diff)
downloadpvs2-c984899f52f11d7148785c9a6cb377b23da87228.tar.gz
pvs2-c984899f52f11d7148785c9a6cb377b23da87228.tar.xz
pvs2-c984899f52f11d7148785c9a6cb377b23da87228.zip
Closes bug #2807. (And also cleans the code (a bit))
Diffstat (limited to 'src/server/util')
-rw-r--r--src/server/util/global.cpp16
-rw-r--r--src/server/util/global.h9
2 files changed, 22 insertions, 3 deletions
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 <QDebug>
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<QString, QPoint>(), 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_ */