Fix /me chat command in demos
authorunc0rr
Sat, 03 Oct 2009 12:38:56 +0000
changeset 2405 3b8607ac32c6
parent 2404 8281eea32196
child 2406 2e757b32991e
Fix /me chat command in demos
QTfrontend/game.cpp
QTfrontend/newnetclient.cpp
QTfrontend/newnetclient.h
QTfrontend/proto.cpp
QTfrontend/proto.h
--- a/QTfrontend/game.cpp	Sat Oct 03 12:35:24 2009 +0000
+++ b/QTfrontend/game.cpp	Sat Oct 03 12:38:56 2009 +0000
@@ -225,9 +225,9 @@
 			QString msgbody = QString::fromUtf8(msg.mid(2).left(size - 4));
 			emit SendChat(msgbody);
 			// FIXME: /me command doesn't work here
-			//QByteArray buf;
-			//HWProto::addStringToBuffer(buf, QString("s\x01%1: %2\x20\x20").arg(config->netNick()).arg(msgbody));
-			//demo.append(buf);
+			QByteArray buf;
+			HWProto::addStringToBuffer(buf, "s" + HWProto::formatChatMsg(config->netNick(), msgbody) + "\x20\x20");
+			demo.append(buf);
 			break;
 		}
 		case 'b': {
--- a/QTfrontend/newnetclient.cpp	Sat Oct 03 12:35:24 2009 +0000
+++ b/QTfrontend/newnetclient.cpp	Sat Oct 03 12:38:56 2009 +0000
@@ -270,9 +270,9 @@
 			return;
 		}
 		if (netClientState == 2)
-			emit chatStringLobby(formatChatMsg(lst[1], lst[2]));
+			emit chatStringLobby(HWProto::formatChatMsg(lst[1], lst[2]));
 		else
-			emit chatStringFromNet(formatChatMsg(lst[1], lst[2]));
+			emit chatStringFromNet(HWProto::formatChatMsg(lst[1], lst[2]));
 		return;
 	}
 
@@ -593,7 +593,7 @@
 {
 	if(str != "") {
 		RawSendNet(QString("CHAT") + delimeter + str);
-		emit(chatStringFromMe(formatChatMsg(mynick, str)));
+		emit(chatStringFromMe(HWProto::formatChatMsg(mynick, str)));
 	}
 }
 
@@ -601,7 +601,7 @@
 {
 	if(str != "") {
 		RawSendNet(QString("CHAT") + delimeter + str);
-		emit(chatStringFromMeLobby(formatChatMsg(mynick, str)));
+		emit(chatStringFromMeLobby(HWProto::formatChatMsg(mynick, str)));
 	}
 }
 
@@ -631,14 +631,6 @@
 	RawSendNet(QString("ROUNDFINISHED"));
 }
 
-QString HWNewNet::formatChatMsg(const QString & nick, const QString & msg)
-{
-	if(msg.left(4) == "/me ")
-		return QString("\x02* %1 %2").arg(nick).arg(msg.mid(4));
-	else
-		return QString("\x01%1: %2").arg(nick).arg(msg);
-}
-
 void HWNewNet::banPlayer(const QString & nick)
 {
 	RawSendNet(QString("BAN%1%2").arg(delimeter).arg(nick));
--- a/QTfrontend/newnetclient.h	Sat Oct 03 12:35:24 2009 +0000
+++ b/QTfrontend/newnetclient.h	Sat Oct 03 12:38:56 2009 +0000
@@ -80,7 +80,6 @@
   void RawSendNet(const QString & buf);
   void RawSendNet(const QByteArray & buf);
   void ParseCmd(const QStringList & lst);
-  QString formatChatMsg(const QString & nick, const QString & msg);
 
   int loginStep;
   int netClientState;
--- a/QTfrontend/proto.cpp	Sat Oct 03 12:35:24 2009 +0000
+++ b/QTfrontend/proto.cpp	Sat Oct 03 12:38:56 2009 +0000
@@ -39,3 +39,11 @@
 		addStringToBuffer(buf, strList[i]);
 	return buf;
 }
+
+QString HWProto::formatChatMsg(const QString & nick, const QString & msg)
+{
+	if(msg.left(4) == "/me ")
+		return QString("\x02* %1 %2").arg(nick).arg(msg.mid(4));
+	else
+		return QString("\x01%1: %2").arg(nick).arg(msg);
+}
--- a/QTfrontend/proto.h	Sat Oct 03 12:35:24 2009 +0000
+++ b/QTfrontend/proto.h	Sat Oct 03 12:38:56 2009 +0000
@@ -32,6 +32,7 @@
 	HWProto();
 	static QByteArray & addStringToBuffer(QByteArray & buf, const QString & string);
 	static QByteArray & addStringListToBuffer(QByteArray & buf, const QStringList & strList);
+	static QString formatChatMsg(const QString & nick, const QString & msg);
 };
 
 #endif // _PROTO_H