Permalink
Browse files

#24 core functionality to track online players

  • Loading branch information...
1 parent 17bdd80 commit c8d2837a58a0fe0d6466ba9a82f49f5bf35ba039 @thejoshwolfe thejoshwolfe committed Nov 2, 2011
Showing with 29 additions and 5 deletions.
  1. +13 −3 src/Game.cpp
  2. +6 −2 src/Game.h
  3. +8 −0 src/Server.cpp
  4. +2 −0 src/Server.h
View
16 src/Game.cpp
@@ -132,12 +132,14 @@ Game::Game(QUrl connection_info) :
Q_ASSERT(success);
success = connect(&m_server, SIGNAL(openWindow(int,Message::WindowType,int)), this, SLOT(handleOpenWindow(int,Message::WindowType,int)));
Q_ASSERT(success);
-
-
- // pass directly through
success = connect(&m_server, SIGNAL(unloadChunk(Int3D)), this, SLOT(handleUnloadChunk(Int3D)));
Q_ASSERT(success);
+ success = connect(&m_server, SIGNAL(playerPing(QString,int)), this, SLOT(handlePlayerPing(QString,int)));
+ Q_ASSERT(success);
+ success = connect(&m_server, SIGNAL(playerDisconnected(QString)), this, SLOT(handlePlayerDisconnected(QString)));
+ Q_ASSERT(success);
+
success = connect(this, SIGNAL(chunkUpdated(Int3D,Int3D)), this, SLOT(checkForDiggingStopped(Int3D,Int3D)));
Q_ASSERT(success);
success = connect(this, SIGNAL(chunkUpdated(Int3D,Int3D)), this, SLOT(checkForDestroyedSigns(Int3D,Int3D)));
@@ -1456,3 +1458,11 @@ void Game::handleRespawn(Dimension world)
m_player_dimension = world;
}
+void Game::handlePlayerPing(QString name, int ping)
+{
+ m_online_players.insert(name, ping);
+}
+void Game::handlePlayerDisconnected(QString name)
+{
+ m_online_players.remove(name);
+}
View
8 src/Game.h
@@ -201,6 +201,7 @@ class Game : public QObject
Dimension dimension() const { return m_player_dimension; }
+ QMap<QString, int> onlinePlayers() { return m_online_players; }
signals:
@@ -238,8 +239,6 @@ class Game : public QObject
static const Int3D c_side_offset[];
-
-
Server m_server;
QSet<QChar> m_legal_chat_chars;
@@ -303,6 +302,8 @@ class Game : public QObject
Dimension m_player_dimension;
+ QMap<QString, int> m_online_players;
+
private:
static Int3D chunkKey(const Int3D & coord);
@@ -358,6 +359,9 @@ private slots:
void handleRespawn(Dimension world);
+ void handlePlayerPing(QString name, int ping);
+ void handlePlayerDisconnected(QString name);
+
void sendPosition();
void animateDigging();
View
8 src/Server.cpp
@@ -460,6 +460,14 @@ void Server::processIncomingMessage(QSharedPointer<IncomingResponse> incomingMes
emit respawned(message->world);
break;
}
+ case Message::PlayerOnlineStatus: {
+ PlayerOnlineStatusResponse * message = (PlayerOnlineStatusResponse *) incomingMessage.data();
+ if (message->online)
+ emit playerPing(message->name, message->ping_milliseconds);
+ else
+ emit playerDisconnected(message->name);
+ break;
+ }
default: {
// qDebug() << "ignoring message type: 0x" << QString::number(incomingMessage.data()->messageType, 16).toStdString().c_str();
break;
View
2 src/Server.h
@@ -84,6 +84,8 @@ class Server : public QObject
void openWindow(int window_id, Message::WindowType inventory_type, int number_of_slots);
void signUpdated(Int3D position, QString text);
void respawned(int world);
+ void playerPing(QString name, int ping);
+ void playerDisconnected(QString name);
public slots:
// actually connect to the server

0 comments on commit c8d2837

Please sign in to comment.