|
@@ -9,7 +9,7 @@
|
|
#include "Settings.h"
|
|
#include "Settings.h"
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
-Client::Client(App *app, ActiveClient* ac):
|
|
|
|
|
|
+Client::Client(App *app, ActiveClient* ac, bool supportsSendPrivate):
|
|
QWClient(),
|
|
QWClient(),
|
|
myActiveClient(ac),
|
|
myActiveClient(ac),
|
|
myApp(app),
|
|
myApp(app),
|
|
@@ -23,6 +23,7 @@ Client::Client(App *app, ActiveClient* ac):
|
|
mySpamBroadcastFloodTimer(new QTimer()),
|
|
mySpamBroadcastFloodTimer(new QTimer()),
|
|
myJoinMessagePrinted(false),
|
|
myJoinMessagePrinted(false),
|
|
myJoinMessageScheduled(false),
|
|
myJoinMessageScheduled(false),
|
|
|
|
+ mySupportsSendPrivate(supportsSendPrivate),
|
|
myMaxClients(0)
|
|
myMaxClients(0)
|
|
{
|
|
{
|
|
myJoinMessageTimer->setSingleShot(true);
|
|
myJoinMessageTimer->setSingleShot(true);
|
|
@@ -51,9 +52,15 @@ void Client::connect(const char *host, quint16 port)
|
|
}
|
|
}
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
-void Client::say(const QString &msg)
|
|
|
|
|
|
+void Client::say(const QString &msg, const QString &nickName)
|
|
{
|
|
{
|
|
- QString cmd = "say " + msg;
|
|
|
|
|
|
+ QString cmd("say ");
|
|
|
|
+
|
|
|
|
+ if(!nickName.isEmpty() && mySupportsSendPrivate)
|
|
|
|
+ cmd.append("s-p " + nickName + " ");
|
|
|
|
+
|
|
|
|
+ cmd.append(msg);
|
|
|
|
+
|
|
sendCmd(cmd.toAscii().data());
|
|
sendCmd(cmd.toAscii().data());
|
|
}
|
|
}
|
|
|
|
|
|
@@ -111,40 +118,42 @@ bool Client::isSpamMuted() const
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
void Client::parsePrintedLine()
|
|
void Client::parsePrintedLine()
|
|
{
|
|
{
|
|
- Player player;
|
|
|
|
- bool parsed = false;
|
|
|
|
|
|
+ // Find the player that printed this line of text
|
|
|
|
+ Player player, bestPlayer;
|
|
quint16 lastMatchSize = 0;
|
|
quint16 lastMatchSize = 0;
|
|
|
|
|
|
- QByteArray playerName;
|
|
|
|
- QByteArray printLine(myPrintLine.toAscii());
|
|
|
|
-
|
|
|
|
- QWClient::stripColor(printLine.data());
|
|
|
|
-
|
|
|
|
foreach(player, myPlayerList)
|
|
foreach(player, myPlayerList)
|
|
{
|
|
{
|
|
- playerName = player.name.toAscii();
|
|
|
|
- QWClient::stripColor(playerName.data());
|
|
|
|
- if(printLine.startsWith(playerName) || (player.spectator && printLine.startsWith(QString("[SPEC] " + player.name).toAscii())))
|
|
|
|
|
|
+ if(player.spectator && myPrintLine.startsWith("[SPEC] " + player.name))
|
|
{
|
|
{
|
|
- if(player.spectator && printLine.startsWith("[SPEC] "))
|
|
|
|
|
|
+ if(lastMatchSize < (player.name.size() + 7))
|
|
{
|
|
{
|
|
- if(lastMatchSize < (playerName.size() + 7))
|
|
|
|
- lastMatchSize = (playerName.size() + 7);
|
|
|
|
|
|
+ lastMatchSize = (player.name.size() + 7);
|
|
|
|
+ bestPlayer = player;
|
|
}
|
|
}
|
|
- else if(lastMatchSize < playerName.size())
|
|
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if(myPrintLine.startsWith(player.name))
|
|
|
|
+ {
|
|
|
|
+ if(lastMatchSize < player.name.size())
|
|
{
|
|
{
|
|
- lastMatchSize = playerName.size();
|
|
|
|
|
|
+ lastMatchSize = player.name.size();
|
|
|
|
+ bestPlayer = player;
|
|
}
|
|
}
|
|
- parsed = true;
|
|
|
|
|
|
+ continue;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- if(!parsed)
|
|
|
|
|
|
+ if(!lastMatchSize)
|
|
return;
|
|
return;
|
|
|
|
|
|
- QString nick(myPrintLine.left(lastMatchSize));
|
|
|
|
|
|
+ QString nick(bestPlayer.name);
|
|
|
|
+ if(bestPlayer.spectator)
|
|
|
|
+ nick.prepend("(spec) ");
|
|
|
|
+
|
|
QString message(myPrintLine.right(myPrintLine.size() - lastMatchSize));
|
|
QString message(myPrintLine.right(myPrintLine.size() - lastMatchSize));
|
|
|
|
|
|
- QRegExp regex("^:\\s+\\.(spam|qw|help|qw_mute|qw_unmute|spam_mute|spam_unmute|lastmsgs)\\s*(.+)$");
|
|
|
|
|
|
+ QRegExp regex("^:\\s+\\.(spam|qw|help|qw_mute|qw_unmute|spam_mute|spam_unmute|lm)\\s*(.+)$");
|
|
if(regex.indexIn(message) == -1)
|
|
if(regex.indexIn(message) == -1)
|
|
return;
|
|
return;
|
|
|
|
|
|
@@ -155,7 +164,7 @@ void Client::parsePrintedLine()
|
|
{
|
|
{
|
|
if(!myFloodMsgPrinted)
|
|
if(!myFloodMsgPrinted)
|
|
{
|
|
{
|
|
- say("> FloodProt: Not so fast, wait " + QString::number(floodProtTime + currentTime.secsTo(myFloodTimerStart)) + " sec(s).");
|
|
|
|
|
|
+ say("FloodProt: Not so fast, wait " + QString::number(floodProtTime + currentTime.secsTo(myFloodTimerStart)) + " sec(s).", bestPlayer.name);
|
|
myFloodMsgPrinted = true;
|
|
myFloodMsgPrinted = true;
|
|
}
|
|
}
|
|
return;
|
|
return;
|
|
@@ -169,11 +178,9 @@ void Client::parsePrintedLine()
|
|
|
|
|
|
if(command == "help")
|
|
if(command == "help")
|
|
{
|
|
{
|
|
- //say("> Commands:");
|
|
|
|
- say("> Broadcast a message: .qw <message> and .spam <message>");
|
|
|
|
- //, beware of the floodprot limits 600s for .qw and 300s for .spam");
|
|
|
|
- say("> (Un)Mute: .qw_mute .qw_unmute or .spam_mute .spam_unmute");
|
|
|
|
- say("> Last 5 messages: .lastmsgs");
|
|
|
|
|
|
+ say("Broadcast a message: .qw <message> and .spam <message>", bestPlayer.name);
|
|
|
|
+ say("(Un)Mute: .qw_mute .qw_unmute or .spam_mute .spam_unmute", bestPlayer.name);
|
|
|
|
+ say("Last 5 messages: .lm", bestPlayer.name);
|
|
|
|
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
@@ -182,7 +189,7 @@ void Client::parsePrintedLine()
|
|
{
|
|
{
|
|
if(!args.trimmed().size())
|
|
if(!args.trimmed().size())
|
|
{
|
|
{
|
|
- say("> The format is ." + command + " <message>.");
|
|
|
|
|
|
+ say("The format is ." + command + " <message>.", bestPlayer.name);
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -192,7 +199,7 @@ void Client::parsePrintedLine()
|
|
int qwFloodProtTime = Settings::globalInstance()->qwFloodProtTime();
|
|
int qwFloodProtTime = Settings::globalInstance()->qwFloodProtTime();
|
|
if(myQWBroadcastFloodTimer->isActive())
|
|
if(myQWBroadcastFloodTimer->isActive())
|
|
{
|
|
{
|
|
- say("> FloodProt: Wait " + QString::number(qwFloodProtTime + currentTime.secsTo(myQWBroadcastFloodTimerStart)) + " secs before new .qw");
|
|
|
|
|
|
+ say("> FloodProt: Wait " + QString::number(qwFloodProtTime + currentTime.secsTo(myQWBroadcastFloodTimerStart)) + " secs before new .qw", bestPlayer.name);
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
myQWBroadcastFloodTimerStart = currentTime;
|
|
myQWBroadcastFloodTimerStart = currentTime;
|
|
@@ -203,7 +210,7 @@ void Client::parsePrintedLine()
|
|
int spamFloodProtTime = Settings::globalInstance()->spamFloodProtTime();
|
|
int spamFloodProtTime = Settings::globalInstance()->spamFloodProtTime();
|
|
if(mySpamBroadcastFloodTimer->isActive())
|
|
if(mySpamBroadcastFloodTimer->isActive())
|
|
{
|
|
{
|
|
- say("> FloodProt: Wait " + QString::number(spamFloodProtTime + currentTime.secsTo(mySpamBroadcastFloodTimerStart)) + " secs before new .spam");
|
|
|
|
|
|
+ say("FloodProt: Wait " + QString::number(spamFloodProtTime + currentTime.secsTo(mySpamBroadcastFloodTimerStart)) + " secs before new .spam", bestPlayer.name);
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
mySpamBroadcastFloodTimerStart = currentTime;
|
|
mySpamBroadcastFloodTimerStart = currentTime;
|
|
@@ -225,43 +232,45 @@ void Client::parsePrintedLine()
|
|
else
|
|
else
|
|
myApp->requestBroadcast("dev", nick, server, parsedMsg);
|
|
myApp->requestBroadcast("dev", nick, server, parsedMsg);
|
|
|
|
|
|
|
|
+ say("Broadcasting...", bestPlayer.name);
|
|
|
|
+
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
if(command == "qw_mute")
|
|
if(command == "qw_mute")
|
|
{
|
|
{
|
|
- say("> .qw Frequency Muted.");
|
|
|
|
|
|
+ say(".qw Frequency Muted.", bestPlayer.name);
|
|
myQWMutedFlag = true;
|
|
myQWMutedFlag = true;
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
if(command == "qw_unmute")
|
|
if(command == "qw_unmute")
|
|
{
|
|
{
|
|
- say("> .qw Frequency Unmuted.");
|
|
|
|
|
|
+ say(".qw Frequency Unmuted.", bestPlayer.name);
|
|
myQWMutedFlag = false;
|
|
myQWMutedFlag = false;
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
if(command == "spam_mute")
|
|
if(command == "spam_mute")
|
|
{
|
|
{
|
|
- say("> .spam Frequency Muted.");
|
|
|
|
|
|
+ say(".spam Frequency Muted.", bestPlayer.name);
|
|
mySpamMutedFlag = true;
|
|
mySpamMutedFlag = true;
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
if(command == "spam_unmute")
|
|
if(command == "spam_unmute")
|
|
{
|
|
{
|
|
- say("> .spam Frequency Unmuted.");
|
|
|
|
|
|
+ say(".spam Frequency Unmuted.", bestPlayer.name);
|
|
mySpamMutedFlag = false;
|
|
mySpamMutedFlag = false;
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
- if(command == "lastmsgs")
|
|
|
|
|
|
+ if(command == "lm")
|
|
{
|
|
{
|
|
QStringList messages = myApp->lastMessages();
|
|
QStringList messages = myApp->lastMessages();
|
|
if(!messages.size())
|
|
if(!messages.size())
|
|
{
|
|
{
|
|
- say("None");
|
|
|
|
|
|
+ say("None", bestPlayer.name);
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -272,7 +281,7 @@ void Client::parsePrintedLine()
|
|
if(++i > 5)
|
|
if(++i > 5)
|
|
break;
|
|
break;
|
|
|
|
|
|
- say(msg);
|
|
|
|
|
|
+ say(msg, bestPlayer.name);
|
|
}
|
|
}
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
@@ -444,6 +453,12 @@ void Client::onDownloadFinished()
|
|
print("Download 100% finished.\n");
|
|
print("Download 100% finished.\n");
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
+bool Client::supportsSendPrivate() const
|
|
|
|
+{
|
|
|
|
+ return mySupportsSendPrivate;
|
|
|
|
+}
|
|
|
|
+
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
QString Client::parseNameFun(const QString &string)
|
|
QString Client::parseNameFun(const QString &string)
|
|
{
|
|
{
|