sheepluva's patch to add a "follow" command to server and frontend, in order to stalk people and join them in their rooms
authorkoda
Sun, 24 Jan 2010 13:38:14 +0000
changeset 2706 935b7d618cf0
parent 2705 2b5625c4ec16
child 2707 633cac1d6f9a
sheepluva's patch to add a "follow" command to server and frontend, in order to stalk people and join them in their rooms
QTfrontend/chatwidget.cpp
QTfrontend/chatwidget.h
QTfrontend/hwform.cpp
QTfrontend/newnetclient.cpp
QTfrontend/newnetclient.h
gameServer/HWProtoCore.hs
--- a/QTfrontend/chatwidget.cpp	Sun Jan 24 13:37:03 2010 +0000
+++ b/QTfrontend/chatwidget.cpp	Sun Jan 24 13:38:14 2010 +0000
@@ -18,7 +18,6 @@
  */
 
 #include <QTextBrowser>
-#include <QListWidget>
 #include <QLineEdit>
 #include <QAction>
 #include <QApplication>
@@ -55,6 +54,9 @@
 	chatNicks->setSortingEnabled(true);
 	chatNicks->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
 	chatNicks->setContextMenuPolicy(Qt::ActionsContextMenu);
+	connect(chatNicks, SIGNAL(itemDoubleClicked(QListWidgetItem *)),
+		this, SLOT(chatNickDoubleClicked(QListWidgetItem *)));
+
 	mainLayout.addWidget(chatNicks, 0, 1);
 
 	acInfo = new QAction(QAction::tr("Info"), chatNicks);
@@ -63,8 +65,11 @@
 	connect(acKick, SIGNAL(triggered(bool)), this, SLOT(onKick()));
 	acBan = new QAction(QAction::tr("Ban"), chatNicks);
 	connect(acBan, SIGNAL(triggered(bool)), this, SLOT(onBan()));
+	acFollow = new QAction(QAction::tr("Follow"), chatNicks);
+	connect(acFollow, SIGNAL(triggered(bool)), this, SLOT(onFollow()));
 
 	chatNicks->insertAction(0, acInfo);
+	chatNicks->insertAction(0, acFollow);
 }
 
 void HWChatWidget::returnPressed()
@@ -148,6 +153,18 @@
 		emit info(curritem->text());
 }
 
+void HWChatWidget::onFollow()
+{
+	QListWidgetItem * curritem = chatNicks->currentItem();
+	if (curritem)
+		emit follow(curritem->text());
+}
+
+void HWChatWidget::chatNickDoubleClicked(QListWidgetItem * item)
+{
+	if (item) onFollow();
+}
+
 void HWChatWidget::setReadyStatus(const QString & nick, bool isReady)
 {
 	QList<QListWidgetItem *> items = chatNicks->findItems(nick, Qt::MatchExactly);
--- a/QTfrontend/chatwidget.h	Sun Jan 24 13:37:03 2010 +0000
+++ b/QTfrontend/chatwidget.h	Sun Jan 24 13:38:14 2010 +0000
@@ -20,6 +20,7 @@
 #define _CHAT_WIDGET_INCLUDED
 
 #include <QWidget>
+#include <QListWidget>
 #include <QString>
 #include <QGridLayout>
 
@@ -48,6 +49,7 @@
   void kick(const QString & str);
   void ban(const QString & str);
   void info(const QString & str);
+  void follow(const QString &);
 
  private:
   QGridLayout mainLayout;
@@ -58,12 +60,15 @@
   QAction * acInfo;
   QAction * acKick;
   QAction * acBan;
+  QAction * acFollow;
 
  private slots:
   void returnPressed();
   void onBan();
   void onKick();
   void onInfo();
+  void onFollow();
+  void chatNickDoubleClicked(QListWidgetItem * item);
 };
 
 #endif // _CHAT_WIDGET_INCLUDED
--- a/QTfrontend/hwform.cpp	Sun Jan 24 13:37:03 2010 +0000
+++ b/QTfrontend/hwform.cpp	Sun Jan 24 13:38:14 2010 +0000
@@ -617,12 +617,16 @@
 		hwnet, SLOT(banPlayer(const QString&)));
 	connect(ui.pageNetGame->pChatWidget, SIGNAL(info(const QString&)),
 		hwnet, SLOT(infoPlayer(const QString&)));
+	connect(ui.pageNetGame->pChatWidget, SIGNAL(follow(const QString&)),
+		hwnet, SLOT(followPlayer(const QString&)));
 	connect(ui.pageRoomsList->chatWidget, SIGNAL(kick(const QString&)),
 		hwnet, SLOT(kickPlayer(const QString&)));
 	connect(ui.pageRoomsList->chatWidget, SIGNAL(ban(const QString&)),
 		hwnet, SLOT(banPlayer(const QString&)));
 	connect(ui.pageRoomsList->chatWidget, SIGNAL(info(const QString&)),
 		hwnet, SLOT(infoPlayer(const QString&)));
+	connect(ui.pageRoomsList->chatWidget, SIGNAL(follow(const QString&)),
+		hwnet, SLOT(followPlayer(const QString&)));
 
 // chatting
 	connect(ui.pageRoomsList->chatWidget, SIGNAL(chatLine(const QString&)),
--- a/QTfrontend/newnetclient.cpp	Sun Jan 24 13:37:03 2010 +0000
+++ b/QTfrontend/newnetclient.cpp	Sun Jan 24 13:38:14 2010 +0000
@@ -646,6 +646,14 @@
 	RawSendNet(QString("INFO%1%2").arg(delimeter).arg(nick));
 }
 
+void HWNewNet::followPlayer(const QString & nick)
+{
+	if (!isInRoom()) {
+		RawSendNet(QString("FOLLOW%1%2").arg(delimeter).arg(nick));
+		isChief = false;
+	}
+}
+
 void HWNewNet::startGame()
 {
 	RawSendNet(QString("START_GAME"));
--- a/QTfrontend/newnetclient.h	Sun Jan 24 13:37:03 2010 +0000
+++ b/QTfrontend/newnetclient.h	Sun Jan 24 13:38:14 2010 +0000
@@ -139,6 +139,7 @@
   void banPlayer(const QString &);
   void kickPlayer(const QString &);
   void infoPlayer(const QString &);
+  void followPlayer(const QString &);
   void startGame();
   void toggleRestrictJoins();
   void toggleRestrictTeamAdds();
--- a/gameServer/HWProtoCore.hs	Sun Jan 24 13:37:03 2010 +0000
+++ b/gameServer/HWProtoCore.hs	Sun Jan 24 13:38:14 2010 +0000
@@ -63,6 +63,20 @@
 			else ""
 
 
+handleCmd_loggedin clID clients rooms ["FOLLOW", asknick] =
+	if inLobby || noSuchClient then
+		[]
+	else
+		handleCmd_lobby clID clients rooms ["JOIN_ROOM", roomname]
+	where
+		maybeClient = find (\cl -> asknick == nick cl) clients
+		noSuchClient = isNothing maybeClient
+		client = fromJust maybeClient
+		room = rooms IntMap.! roomID client
+		roomname = (name room)
+		inLobby = roomname == ""
+
+
 handleCmd_loggedin clID clients rooms cmd =
 	if roomID client == 0 then
 		handleCmd_lobby clID clients rooms cmd