瀏覽代碼

Merge branch 'dev' into 'master'

Dev

Converted to compile on Qt5, I'm not sure if it's qt4 compatible =). Let's test it first before merge. And the new colored text parsing feature needs some testing too.
Paul-Dieter Klumpp 10 年之前
父節點
當前提交
2f5a0aceea
共有 6 個文件被更改,包括 47 次插入28 次删除
  1. 2 2
      ActiveClient.cpp
  2. 7 7
      App.cpp
  3. 35 16
      Client.cpp
  4. 1 1
      ServerQuery.cpp
  5. 1 1
      Settings.cpp
  6. 1 1
      SshClient.cpp

+ 2 - 2
ActiveClient.cpp

@@ -46,7 +46,7 @@ ActiveClient::ActiveClient(App *app, const QString& password, QObject *parent):
 
   myQueryTimer->setSingleShot(true);
 
-  myClient->setPassword(password.toAscii().data());
+  myClient->setPassword(password.toLatin1().data());
 }
 
 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@@ -97,7 +97,7 @@ void ActiveClient::queryFinished()
     if(playerCount > 0 && myDisconnectTime->elapsed() > 10000)
     {
       myApp->print("Players online on server " + serverAddressString() + ". Joining...\n");
-      myClient->connect(myQuery->address().toString().toAscii(), myQuery->port());
+      myClient->connect(myQuery->address().toString().toLatin1(), myQuery->port());
     }
     return;
   }

+ 7 - 7
App.cpp

@@ -93,7 +93,7 @@ App::~App()
 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 bool App::parseCommandLine()
 {
-  if(argc() < 2)
+  if(arguments().size() < 2)
     return true;
 
   QStringList args = App::arguments();
@@ -104,7 +104,7 @@ bool App::parseCommandLine()
     arg = *itr;
     if(arg == "--help" || arg == "-h")
     {
-      printf("Usage: %s [--config/-c config_file] [-h]\n", args.at(0).section("/", -1).toAscii().data());
+      printf("Usage: %s [--config/-c config_file] [-h]\n", args.at(0).section("/", -1).toLatin1().data());
       return false;
     }
     else if(arg == "--config" || arg == "-c")
@@ -116,7 +116,7 @@ bool App::parseCommandLine()
         return false;
       }
       arg = *itr;
-      printf("Using config file [%s]...\n", arg.toAscii().data());
+      printf("Using config file [%s]...\n", arg.toLatin1().data());
       Settings::globalInstance()->changeConfigFile(*itr);
       return true;
     }
@@ -166,10 +166,10 @@ const QStringList& App::lastMessages() const
 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 void App::print(const QString &msg)
 {
-  printf("%s", msg.toAscii().data());
+  printf("%s", msg.toLatin1().data());
   if(mySocketConnectedFlag)
   {
-    mySocket->write(msg.toAscii());
+    mySocket->write(msg.toLatin1());
     mySocket->waitForBytesWritten();
   }
 }
@@ -191,8 +191,8 @@ bool App::addClient(const QString &host, quint16 port, const QString& password)
 
   ac = new ActiveClient(this, password, this);
   ac->setAddress(ha, port);
-  ac->client()->setQuakeFolder(Settings::globalInstance()->quakeFolder().toAscii().data());
-  ac->client()->setName(Settings::globalInstance()->botName().toAscii().data());
+  ac->client()->setQuakeFolder(Settings::globalInstance()->quakeFolder().toLatin1().data());
+  ac->client()->setName(Settings::globalInstance()->botName().toLatin1().data());
   ac->client()->setSpectator(Settings::globalInstance()->botSpectator());
   ac->client()->setPing(Settings::globalInstance()->botPing());
   ac->client()->setColor(Settings::globalInstance()->botTopColor(), Settings::globalInstance()->botBottomColor());

+ 35 - 16
Client.cpp

@@ -28,6 +28,9 @@ along with this program.  If not, see < http://www.gnu.org/licenses/ >.
 #include "App.h"
 #include "Settings.h"
 
+static QRegExp rxColoredPattern("&c[0-9a-fA-F]{3}");
+static QRegExp rxBrackets("\\{[^}]*\\}");
+
 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 Client::Client(App *app, ActiveClient* ac):
   QWClient(),
@@ -46,6 +49,7 @@ Client::Client(App *app, ActiveClient* ac):
   myMaxClients(0),
   myCmdScheduledTimer(new QTimer())
 {
+  rxBrackets.setMinimal(true);
   myKeepNickTimer->setSingleShot(true);
   myFloodTimer->setSingleShot(true);
   myQWBroadcastFloodTimer->setSingleShot(true);
@@ -82,13 +86,13 @@ void Client::say(const QString &msg, const QString &nickName)
 
   cmd.append(msg);
 
-  sendCmd(cmd.toAscii().data());
+  sendCmd(cmd.toLatin1().data());
 }
 
 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 void Client::setTeam(const QString &msg)
 {
-  sendCmd(QString("setinfo \"team\" \"" + msg + "\"").toAscii().data());
+  sendCmd(QString("setinfo \"team\" \"" + msg + "\"").toLatin1().data());
 }
 
 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@@ -104,9 +108,9 @@ void Client::print(const QString &msg)
   QString str;
 
   str = "[" + QTime::currentTime().toString(Qt::ISODate) + "] " + QString(host()) + ":" + QString::number(port()) + "> " + msg;
-  QByteArray b = str.toAscii();
+  QByteArray b = str.toLatin1();
   Client::stripColor(b.data());
-  str = QString::fromAscii(b.data());
+  str = QString::fromLatin1(b.data());
 
   myApp->print(str);
 }
@@ -258,14 +262,17 @@ void Client::parsePrintedLine()
     }
     else if(command == "spam")
     {
-      int spamFloodProtTime = Settings::globalInstance()->spamFloodProtTime();
-      if(mySpamBroadcastFloodTimer->isActive())
-      {
-        say("FloodProt: Wait " + QString::number(spamFloodProtTime + currentTime.secsTo(mySpamBroadcastFloodTimerStart)) + " secs before new .spam", bestPlayer.name);
-        return;
-      }
-      mySpamBroadcastFloodTimerStart = currentTime;
-      mySpamBroadcastFloodTimer->start(spamFloodProtTime*1000);
+      say("Only .qw is allowed within QW servers. Please use .qw to broadcast your message.");
+      return;
+
+//      int spamFloodProtTime = Settings::globalInstance()->spamFloodProtTime();
+//      if(mySpamBroadcastFloodTimer->isActive())
+//      {
+//        say("FloodProt: Wait " + QString::number(spamFloodProtTime + currentTime.secsTo(mySpamBroadcastFloodTimerStart)) + " secs before new .spam", bestPlayer.name);
+//        return;
+//      }
+//      mySpamBroadcastFloodTimerStart = currentTime;
+//      mySpamBroadcastFloodTimer->start(spamFloodProtTime*1000);
     }
 
     // Prepare all strings to be broadcasted
@@ -465,14 +472,14 @@ void Client::run()
   // Keep nick... Simply set name again after 30 secs
   if(!myKeepNickTimer->isActive())
   {
-    setName(Settings::globalInstance()->botName().toAscii().data());
+    setName(Settings::globalInstance()->botName().toLatin1().data());
     myKeepNickTimer->start(30000);
   }
 
   // Scheduled commands
   if(!myCmdScheduled.isEmpty() && !myCmdScheduledTimer->isActive())
   {
-    sendCmd(myCmdScheduled.toAscii().data());
+    sendCmd(myCmdScheduled.toLatin1().data());
     myCmdScheduled.clear();
   }
 
@@ -537,12 +544,24 @@ void Client::spDetection()
 }
 
 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+static QRegExp coloredTextStrings("(\\{&c[0-9a-fA-F]{3}).*?(\\{&c[0-9a-fA-F]{3})|(\\})");
 QString Client::parseNameFun(const QString &string)
 {
-  QByteArray b(string.toAscii());
+  QByteArray b(string.toLatin1());
   QWClient::stripColor(b.data());
+  QString text = QString::fromLatin1(b);
+  int pos = 0;
+  int index_adj;
+  while ((pos = rxBrackets.indexIn(text, pos)) != -1) {
+      QString match = rxBrackets.cap(0);
+      QString newtext = rxBrackets.cap(0).replace(rxColoredPattern, "");
+      newtext = newtext.mid(1, newtext.size()-2);
+      index_adj = match.length() - newtext.length();
+      text.replace(match, newtext);
+      pos += rxBrackets.matchedLength() - index_adj;
+  }
 
-  return QString(b);
+  return text;
 }
 
 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

+ 1 - 1
ServerQuery.cpp

@@ -309,7 +309,7 @@ QString ServerQuery::convertNameFun(const QString &name)
   QString stripped;
 
   for(int i = 0; i < name.length(); i++)
-    stripped.append(QChar(ourReadableCharsTable[(unsigned char)name.at(i).toAscii()] & 127));
+    stripped.append(QChar(ourReadableCharsTable[(unsigned char)name.at(i).toLatin1()] & 127));
 
   return stripped;
 }

+ 1 - 1
Settings.cpp

@@ -48,7 +48,7 @@ bool Settings::changeConfigFile(const QString &fileName)
   QSettings::Status status = ourSettings->status();
   if(status != QSettings::NoError)
   {
-    printf("Failed to load config file [%s]. Falling back to default config file.\n", fileName.toAscii().data());
+    printf("Failed to load config file [%s]. Falling back to default config file.\n", fileName.toLatin1().data());
     delete ourSettings;
     ourSettings = NULL;
     return false;

+ 1 - 1
SshClient.cpp

@@ -104,7 +104,7 @@ void SshClient::pong()
 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 void SshClient::write(const QString &data)
 {
-  myProcess->write(data.toAscii());
+  myProcess->write(data.toLatin1());
   myProcess->waitForBytesWritten();
 }