|
@@ -9,7 +9,7 @@
|
|
|
#include "Settings.h"
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
-Client::Client(App *app, ActiveClient* ac):
|
|
|
+Client::Client(App *app, ActiveClient* ac, bool supportsSendPrivate):
|
|
|
QWClient(),
|
|
|
myActiveClient(ac),
|
|
|
myApp(app),
|
|
@@ -23,6 +23,7 @@ Client::Client(App *app, ActiveClient* ac):
|
|
|
mySpamBroadcastFloodTimer(new QTimer()),
|
|
|
myJoinMessagePrinted(false),
|
|
|
myJoinMessageScheduled(false),
|
|
|
+ mySupportsSendPrivate(supportsSendPrivate),
|
|
|
myMaxClients(0)
|
|
|
{
|
|
|
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());
|
|
|
}
|
|
|
|
|
@@ -111,40 +118,42 @@ bool Client::isSpamMuted() const
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
void Client::parsePrintedLine()
|
|
|
{
|
|
|
- Player player;
|
|
|
- bool parsed = false;
|
|
|
+ // Find the player that printed this line of text
|
|
|
+ Player player, bestPlayer;
|
|
|
quint16 lastMatchSize = 0;
|
|
|
|
|
|
- QByteArray playerName;
|
|
|
- QByteArray printLine(myPrintLine.toAscii());
|
|
|
-
|
|
|
- QWClient::stripColor(printLine.data());
|
|
|
-
|
|
|
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;
|
|
|
|
|
|
- QString nick(myPrintLine.left(lastMatchSize));
|
|
|
+ QString nick(bestPlayer.name);
|
|
|
+ if(bestPlayer.spectator)
|
|
|
+ nick.prepend("(spec) ");
|
|
|
+
|
|
|
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)
|
|
|
return;
|
|
|
|
|
@@ -155,7 +164,7 @@ void Client::parsePrintedLine()
|
|
|
{
|
|
|
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;
|
|
|
}
|
|
|
return;
|
|
@@ -169,11 +178,9 @@ void Client::parsePrintedLine()
|
|
|
|
|
|
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;
|
|
|
}
|
|
@@ -182,7 +189,7 @@ void Client::parsePrintedLine()
|
|
|
{
|
|
|
if(!args.trimmed().size())
|
|
|
{
|
|
|
- say("> The format is ." + command + " <message>.");
|
|
|
+ say("The format is ." + command + " <message>.", bestPlayer.name);
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -192,7 +199,7 @@ void Client::parsePrintedLine()
|
|
|
int qwFloodProtTime = Settings::globalInstance()->qwFloodProtTime();
|
|
|
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;
|
|
|
}
|
|
|
myQWBroadcastFloodTimerStart = currentTime;
|
|
@@ -203,7 +210,7 @@ void Client::parsePrintedLine()
|
|
|
int spamFloodProtTime = Settings::globalInstance()->spamFloodProtTime();
|
|
|
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;
|
|
|
}
|
|
|
mySpamBroadcastFloodTimerStart = currentTime;
|
|
@@ -225,43 +232,45 @@ void Client::parsePrintedLine()
|
|
|
else
|
|
|
myApp->requestBroadcast("dev", nick, server, parsedMsg);
|
|
|
|
|
|
+ say("Broadcasting...", bestPlayer.name);
|
|
|
+
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
if(command == "qw_mute")
|
|
|
{
|
|
|
- say("> .qw Frequency Muted.");
|
|
|
+ say(".qw Frequency Muted.", bestPlayer.name);
|
|
|
myQWMutedFlag = true;
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
if(command == "qw_unmute")
|
|
|
{
|
|
|
- say("> .qw Frequency Unmuted.");
|
|
|
+ say(".qw Frequency Unmuted.", bestPlayer.name);
|
|
|
myQWMutedFlag = false;
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
if(command == "spam_mute")
|
|
|
{
|
|
|
- say("> .spam Frequency Muted.");
|
|
|
+ say(".spam Frequency Muted.", bestPlayer.name);
|
|
|
mySpamMutedFlag = true;
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
if(command == "spam_unmute")
|
|
|
{
|
|
|
- say("> .spam Frequency Unmuted.");
|
|
|
+ say(".spam Frequency Unmuted.", bestPlayer.name);
|
|
|
mySpamMutedFlag = false;
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- if(command == "lastmsgs")
|
|
|
+ if(command == "lm")
|
|
|
{
|
|
|
QStringList messages = myApp->lastMessages();
|
|
|
if(!messages.size())
|
|
|
{
|
|
|
- say("None");
|
|
|
+ say("None", bestPlayer.name);
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -272,7 +281,7 @@ void Client::parsePrintedLine()
|
|
|
if(++i > 5)
|
|
|
break;
|
|
|
|
|
|
- say(msg);
|
|
|
+ say(msg, bestPlayer.name);
|
|
|
}
|
|
|
return;
|
|
|
}
|
|
@@ -444,6 +453,12 @@ void Client::onDownloadFinished()
|
|
|
print("Download 100% finished.\n");
|
|
|
}
|
|
|
|
|
|
+// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
+bool Client::supportsSendPrivate() const
|
|
|
+{
|
|
|
+ return mySupportsSendPrivate;
|
|
|
+}
|
|
|
+
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
QString Client::parseNameFun(const QString &string)
|
|
|
{
|