summaryrefslogtreecommitdiffstats
path: root/src/server/util/global.cpp
blob: 8bb89d05189ec9ca4958a86dfac4735ea6c3cb89 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
 * global.cpp
 *
 *  Created on: 29.01.2013
 *      Author: sr
 */

#include "global.h"
#include <QDebug>

QString Global::_sessionName = QString();
QByteArray Global::_sessionNameArray = QByteArray();
QMap<QString, Room*> Global::_rooms = QMap<QString, Room*>();
QString Global::_currentRoom = QString();

void Global::setSessionName(const QString& name)
{
	Global::_sessionName = name;
	Global::_sessionNameArray = name.toUtf8();
}

void Global::setSessionName()
{
	const QString name = QString::number(qrand() % 9000 + 1000);
	Global::_sessionName = name;
	Global::_sessionNameArray = name.toUtf8();
}

void Global::setRooms(const QMap<QString, Room*>& roomList)
{
	Global::_rooms = roomList;
}

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;
    }
}