|
@@ -366,8 +366,8 @@ void App::say(const QString &msg, int *serverCount, int *userCount)
|
|
|
if(ac->client()->state() == Client::ConnectedState)
|
|
|
{
|
|
|
ac->client()->say(msg);
|
|
|
- *userCount += ac->queryThread()->playerCount();
|
|
|
- *serverCount++;
|
|
|
+ *userCount += ac->queryThread()->playerCount() - 1;
|
|
|
+ (*serverCount)++;
|
|
|
}
|
|
|
}
|
|
|
print("Say command sent to all clients\n");
|
|
@@ -408,6 +408,26 @@ void App::listClients()
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+void App::activeClientsReplyCounters(int *serverCount, int *playerCount)
|
|
|
+{
|
|
|
+ ActiveClient* ac;
|
|
|
+
|
|
|
+ foreach(ac, myClients)
|
|
|
+ {
|
|
|
+ if(ac->client()->state() == Client::ConnectedState)
|
|
|
+ {
|
|
|
+ int pc = ac->queryThread()->playerCount();
|
|
|
+ if(pc == 255 || pc == 0)
|
|
|
+ pc = 0;
|
|
|
+ else
|
|
|
+ pc--;
|
|
|
+
|
|
|
+ *playerCount += pc;
|
|
|
+ (*serverCount)++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
void App::timerEvent(QTimerEvent *e)
|
|
|
{
|
|
|
if(e->timerId() == myClientsFrameTimerID)
|
|
@@ -455,12 +475,41 @@ App::~App()
|
|
|
delete myServer;
|
|
|
}
|
|
|
|
|
|
+void App::setReplyHash(const QString &serverAddress, const QString &hash)
|
|
|
+{
|
|
|
+ ActiveClient* ac;
|
|
|
+ foreach(ac, myClients)
|
|
|
+ {
|
|
|
+ if(serverAddress == ac->serverAddressString())
|
|
|
+ {
|
|
|
+ ac->setReplyHash(hash);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void App::incrementReplyCounters(const QString &hash, int userCount, int serverCount)
|
|
|
+{
|
|
|
+ ActiveClient* ac;
|
|
|
+ foreach(ac, myClients)
|
|
|
+ {
|
|
|
+ if(ac->replyHash() == hash)
|
|
|
+ {
|
|
|
+ ac->incrementReplyCounters(userCount, serverCount);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
//========================================================================
|
|
|
|
|
|
App::ActiveClient::ActiveClient(App *app):
|
|
|
myApp(app),
|
|
|
myClient(new Client(app)),
|
|
|
- myQueryThread(new ServerQueryThread())
|
|
|
+ myQueryThread(new ServerQueryThread()),
|
|
|
+ myBroadcastReplyTimer(new QTimer()),
|
|
|
+ myUniqueUserCount(0),
|
|
|
+ myUniqueServerCount(0)
|
|
|
{
|
|
|
}
|
|
|
|
|
@@ -473,6 +522,7 @@ App::ActiveClient::~ActiveClient()
|
|
|
while(queryThread()->isRunning());
|
|
|
|
|
|
delete myQueryThread;
|
|
|
+ delete myBroadcastReplyTimer;
|
|
|
}
|
|
|
|
|
|
Client* App::ActiveClient::client()
|
|
@@ -492,6 +542,7 @@ void App::ActiveClient::setAddress(const QHostAddress &address, quint16 port)
|
|
|
|
|
|
void App::ActiveClient::run()
|
|
|
{
|
|
|
+ /* If the client is disconnect check if there is at least one player connected to the server */
|
|
|
if(client()->state() == Client::DisconnectedState)
|
|
|
{
|
|
|
if(!queryThread()->isRunning())
|
|
@@ -509,6 +560,7 @@ void App::ActiveClient::run()
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+ /* If the client is connected and left alone on the server, disconnect yourself */
|
|
|
if(client()->state() == Client::ConnectedState)
|
|
|
{
|
|
|
int playerCount = queryThread()->playerCount();
|
|
@@ -520,5 +572,48 @@ void App::ActiveClient::run()
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /* Say the broadcast count */
|
|
|
+ if(!myBroadcastReplyTimer->isActive() && myReplyTimerWasActive)
|
|
|
+ {
|
|
|
+ myApp->activeClientsReplyCounters(&myUniqueServerCount, &myUniqueUserCount); //add my internal counter to the list
|
|
|
+
|
|
|
+ client()->say("::cims:: Sent to " + QString::number(myUniqueServerCount) + " channels, " + QString::number(myUniqueUserCount) + " unique users.");
|
|
|
+ myUniqueServerCount = myUniqueUserCount = 0;
|
|
|
+ }
|
|
|
+ myReplyTimerWasActive = myBroadcastReplyTimer->isActive();
|
|
|
+
|
|
|
client()->run();
|
|
|
}
|
|
|
+
|
|
|
+const QString App::ActiveClient::serverAddressString()
|
|
|
+{
|
|
|
+ return QString(queryThread()->serverAddress().toString() + ':' + QString::number(queryThread()->serverPort()));
|
|
|
+}
|
|
|
+
|
|
|
+void App::ActiveClient::setReplyHash(const QString &hash)
|
|
|
+{
|
|
|
+ myReplyHash = hash;
|
|
|
+
|
|
|
+ /* Wait for 5 seconds */
|
|
|
+ myBroadcastReplyTimer->setSingleShot(true);
|
|
|
+ myBroadcastReplyTimer->start(5000);
|
|
|
+}
|
|
|
+
|
|
|
+const QString& App::ActiveClient::replyHash() const
|
|
|
+{
|
|
|
+ return myReplyHash;
|
|
|
+}
|
|
|
+
|
|
|
+bool App::ActiveClient::isWaitingReply() const
|
|
|
+{
|
|
|
+ return myBroadcastReplyTimer->isActive();
|
|
|
+}
|
|
|
+
|
|
|
+void App::ActiveClient::incrementReplyCounters(int userCount, int serverCount)
|
|
|
+{
|
|
|
+ if(!myBroadcastReplyTimer->isActive())
|
|
|
+ return;
|
|
|
+ myUniqueUserCount += userCount;
|
|
|
+ myUniqueServerCount += serverCount;
|
|
|
+}
|