summaryrefslogtreecommitdiffstats
path: root/src/server
diff options
context:
space:
mode:
authorChristian Klinger2016-05-19 16:05:20 +0200
committerChristian Klinger2016-05-19 16:05:20 +0200
commit6e0dd4bd2848b1be03ab733803130b5f07b6b696 (patch)
treed323eb5bcecb33d56f7bddc268e954446f3e2bd8 /src/server
parent[shared/server] define preferred styles and enable it if supported (diff)
parentCloses bug #2807. (And also cleans the code (a bit)) (diff)
downloadpvs2-6e0dd4bd2848b1be03ab733803130b5f07b6b696.tar.gz
pvs2-6e0dd4bd2848b1be03ab733803130b5f07b6b696.tar.xz
pvs2-6e0dd4bd2848b1be03ab733803130b5f07b6b696.zip
Merge branch 'bugfix/segfault-clientsize'
Diffstat (limited to 'src/server')
-rw-r--r--src/server/mainwindow/mainwindow.cpp21
-rw-r--r--src/server/net/client.cpp2
-rw-r--r--src/server/net/discoverylistener.cpp4
-rw-r--r--src/server/util/global.cpp16
-rw-r--r--src/server/util/global.h9
5 files changed, 36 insertions, 16 deletions
diff --git a/src/server/mainwindow/mainwindow.cpp b/src/server/mainwindow/mainwindow.cpp
index c21f2d6..453c8e0 100644
--- a/src/server/mainwindow/mainwindow.cpp
+++ b/src/server/mainwindow/mainwindow.cpp
@@ -190,7 +190,8 @@ float distance(QPoint a, QPoint b) {
void MainWindow::placeFrameInFreeSlot(ConnectionFrame* frame, QPoint preferred)
{
qDebug() << "placeFrameInFreeSlot(preferred = " << preferred << ")";
- const QSize& clientSize = Global::getRooms()[Global::getCurrentRoom()]->clientSize;
+ const QSize& clientSize = Global::getCurrentRoom()->clientSize;
+ // TODO: Fix this qDebug() << "clientSize: " << &clientSize
/* Get occupied cell of each frame and store status in an array */
bool grid[_tilesX][_tilesY];
memset(grid, 0, sizeof(bool) * _tilesX * _tilesY); // set everything to false
@@ -222,7 +223,6 @@ void MainWindow::placeFrameInFreeSlot(ConnectionFrame* frame, QPoint preferred)
}
if (isFree) {
QPoint freePos(x,y);
- qDebug() << "found free: " << freePos;
freePositions.push_back(freePos);
}
}
@@ -252,8 +252,8 @@ void MainWindow::placeFrameInFreeSlot(ConnectionFrame* frame, QPoint preferred)
ConnectionFrame* MainWindow::createFrame()
{
// Allocate and resize
- int width = getTileWidthPx() * Global::getRooms()[Global::getCurrentRoom()]->clientSize.width();
- int height= getTileHeightPx() * Global::getRooms()[Global::getCurrentRoom()]->clientSize.height();
+ int width = getTileWidthPx() * Global::getCurrentRoom()->clientSize.width();
+ int height= getTileHeightPx() * Global::getCurrentRoom()->clientSize.height();
ConnectionFrame *cf = new ConnectionFrame(ui->frmRoom, width, height);
_clientFrames.append(cf);
@@ -272,7 +272,7 @@ ConnectionFrame* MainWindow::createFrame()
ConnectionFrame* MainWindow::createFrame(QString computerId, QPoint pxCoord, QPoint gridPosition)
{
// Allocate and resize
- Room* room = Global::getRooms()[Global::getCurrentRoom()];
+ const Room* room = Global::getCurrentRoom();
qDebug() << "createFrame, access room: " << room;
int width = getTileWidthPx() * (room == NULL ? 1 : room->clientSize.width());
int height = getTileHeightPx() * (room == NULL ? 1 : room->clientSize.height());
@@ -562,11 +562,12 @@ AspectStatus checkAspectRatio(const QSize& frameSize, const QSize& gridSize) {
*/
void MainWindow::resizeEvent(QResizeEvent* e)
{
- Room* room = Global::getRooms()[Global::getCurrentRoom()];
+ const Room* room = Global::getCurrentRoom();
+ const QSize& clientSize = room->clientSize;
-
- if (room == NULL) {return; } /* Nothing to do here */
- QSize& clientSize = room->clientSize;
+ // TODO: Do I still need this?
+ // if (room == NULL) {return; } /* Nothing to do here */
+ // QSize& clientSize = room->clientSize;
if (ui->frmRoom->size().width() < 100 || ui->frmRoom->size().height() < 100 || _tilesX <= 0 || _tilesY <= 0) { return; }
QSize newGridSize = room->gridSize;
@@ -895,7 +896,7 @@ void MainWindow::onReloadRoomOk()
}
/* load background image */
- QString imgPath = Global::getRooms()[Global::getCurrentRoom()]->imagePath;
+ QString imgPath = Global::getCurrentRoom()->imagePath;
if (imgPath == "") {
/* set empty pixmap*/
QPixmap empty;
diff --git a/src/server/net/client.cpp b/src/server/net/client.cpp
index 8a10cd8..e55fb3b 100644
--- a/src/server/net/client.cpp
+++ b/src/server/net/client.cpp
@@ -255,7 +255,7 @@ void Client::handleMsg()
QByteArray hash(_fromClient.getFieldBytes(_HASH));
QByteArray challenge(_fromClient.getFieldBytes(_CHALLENGE));
if (genSha1(&Global::sessionNameArray(), &_challenge) != hash
- && !(Global::getRooms()[Global::getCurrentRoom()]->clientPositions.contains(_socket->peerAddress().toString())))
+ && !(Global::getCurrentRoom()->clientPositions.contains(_socket->peerAddress().toString())))
{ // Challenge reply is invalid, drop client
NetworkMessage msgErr;
msgErr.buildErrorMessage("Challenge reply invalid.");
diff --git a/src/server/net/discoverylistener.cpp b/src/server/net/discoverylistener.cpp
index c5b06fc..c0b80b8 100644
--- a/src/server/net/discoverylistener.cpp
+++ b/src/server/net/discoverylistener.cpp
@@ -159,9 +159,9 @@ void DiscoveryListener::onReadyRead()
if (!Network::isAddressInList(QString::fromUtf8(iplist), addr.toString()))
continue;
// If so, check if the submitted hash seems valid
- if (Global::getCurrentRoom() == "") { continue; }
+ // if (Global::getCurrentRoom() == "") { continue; } // TODO: Can we remove this check?
if (genSha1(&Global::sessionNameArray(), &salt1, &iplist) != hash &&
- !(Global::getRooms()[Global::getCurrentRoom()]->clientPositions.contains(addr.toString())))
+ !(Global::getCurrentRoom()->clientPositions.contains(addr.toString())))
{
// did not match local session name and client is not in same room.
continue;
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_ */