- Don't send 'Bad param' msg, as the only reason of it is just some lag
authorunc0rr
Tue, 25 Nov 2008 15:43:10 +0000 (2008-11-25)
changeset 1512 43742041c211
parent 1511 a5bafdafb394
child 1513 a35c90263e27
- Don't send 'Bad param' msg, as the only reason of it is just some lag - Show quit reason message
QTfrontend/hwform.cpp
QTfrontend/newnetclient.cpp
QTfrontend/newnetclient.h
netserver/HWProto.hs
--- a/QTfrontend/hwform.cpp	Mon Nov 24 21:47:59 2008 +0000
+++ b/QTfrontend/hwform.cpp	Tue Nov 25 15:43:10 2008 +0000
@@ -443,6 +443,8 @@
 	
 	hwnet = new HWNewNet(config, ui.pageNetGame->pGameCFG, ui.pageNetGame->pNetTeamsWidget);
 
+	connect(hwnet, SIGNAL(showMessage(const QString &)), this, SLOT(ShowErrorMessage(const QString &)), Qt::QueuedConnection);
+
 	connect(hwnet, SIGNAL(AskForRunGame()), this, SLOT(CreateNetGame()));
 	connect(hwnet, SIGNAL(Connected()), this, SLOT(NetConnected()));
 	connect(hwnet, SIGNAL(EnteredGame()), this, SLOT(NetGameEnter()));
--- a/QTfrontend/newnetclient.cpp	Mon Nov 24 21:47:59 2008 +0000
+++ b/QTfrontend/newnetclient.cpp	Tue Nov 25 15:43:10 2008 +0000
@@ -334,7 +334,10 @@
 			return;
 		}
 		emit nickRemoved(lst[1]);
-		emit chatStringFromNet(QString(tr("*** %1 left")).arg(lst[1]));
+		if (lst.size() < 3)
+			emit chatStringFromNet(QString(tr("*** %1 left")).arg(lst[1]));
+		else
+			emit chatStringFromNet(QString(tr("*** %1 left (%2)")).arg(lst[1], lst[2]));
 		return;
 	}
 
@@ -439,6 +442,16 @@
 		return;
 	}
 
+	if (lst[0] == "BYE") {
+		if (lst.size() < 2)
+		{
+			qWarning("Net: Bad BYE message");
+			return;
+		}
+		emit showMessage(HWNewNet::tr("Quit reason: ") + lst[1]);
+		return;
+	}
+
 	qWarning() << "Net: Unknown message:" << lst;
 }
 
--- a/QTfrontend/newnetclient.h	Mon Nov 24 21:47:59 2008 +0000
+++ b/QTfrontend/newnetclient.h	Tue Nov 25 15:43:10 2008 +0000
@@ -113,6 +113,7 @@
   void serverMessage(const QString &);
 
   void setReadyStatus(const QString & nick, bool isReady);
+  void showMessage(const QString &);
 
  public slots:
   void ToggleReady();
--- a/netserver/HWProto.hs	Mon Nov 24 21:47:59 2008 +0000
+++ b/netserver/HWProto.hs	Tue Nov 25 15:43:10 2008 +0000
@@ -46,7 +46,6 @@
 answerCannotCreateRoom  = answerClientOnly ["WARNING", "Cannot create more rooms"]
 
 answerAbandoned           = answerOthersRoom ["BYE", "Room abandoned"]
-answerQuitInform nick     = answerOthersRoom ["LEFT", nick]
 answerChatString nick msg = answerOthersRoom ["CHAT_STRING", nick, msg]
 answerAddTeam team        = answerOthersRoom $ teamToNet team
 answerRemoveTeam teamName = answerOthersRoom ["REMOVE_TEAM", teamName]
@@ -54,6 +53,11 @@
 answerHHNum teamName hhNumber = answerOthersRoom ["HH_NUM", teamName, show hhNumber]
 answerTeamColor teamName newColor = answerOthersRoom ["TEAM_COLOR", teamName, newColor]
 answerConfigParam paramName paramStrs = answerOthersRoom $ "CONFIG_PARAM" : paramName : paramStrs
+answerQuitInform nick msg =
+	if not $ null msg then
+		answerOthersRoom ["LEFT", nick, msg]
+		else
+		answerOthersRoom ["LEFT", nick]
 
 answerJoined nick   = answerSameRoom ["JOINED", nick]
 answerRunGame       = answerSameRoom ["RUN_GAME"]
@@ -101,7 +105,7 @@
 	else if isMaster client then
 		(noChangeClients, removeRoom (room client), (answerQuit msg) ++ answerAbandoned) -- core disconnects clients on ROOMABANDONED answer
 	else
-		(noChangeClients, modifyRoom clRoom{teams = othersTeams, playersIn = (playersIn clRoom) - 1, readyPlayers = newReadyPlayers}, (answerQuit msg) ++ (answerQuitInform $ nick client) ++ answerRemoveClientTeams)
+		(noChangeClients, modifyRoom clRoom{teams = othersTeams, playersIn = (playersIn clRoom) - 1, readyPlayers = newReadyPlayers}, (answerQuit msg) ++ (answerQuitInform (nick client) msg) ++ answerRemoveClientTeams)
 	where
 		clRoom = roomByName (room client) rooms
 		answerRemoveClientTeams = concatMap (\tn -> answerOthersRoom ["REMOVE_TEAM", teamname tn]) clientTeams
@@ -251,7 +255,7 @@
 		(noChangeClients, noChangeRooms, answerNotMaster)
 	else
 		if hhNumber < 1 || hhNumber > 8 || noSuchTeam || hhNumber > (canAddNumber + (hhnum team)) then
-			(noChangeClients, noChangeRooms, answerBadParam)
+			(noChangeClients, noChangeRooms, [])
 		else
 			(noChangeClients, modifyRoom $ modifyTeam clRoom team{hhnum = hhNumber}, answerHHNum teamName hhNumber)
 	where
@@ -267,7 +271,7 @@
 		(noChangeClients, noChangeRooms, answerNotMaster)
 	else
 		if noSuchTeam then
-			(noChangeClients, noChangeRooms, answerBadParam)
+			(noChangeClients, noChangeRooms, [])
 		else
 			(noChangeClients, modifyRoom $ modifyTeam clRoom team{teamcolor = newColor}, answerTeamColor teamName newColor)
 	where
@@ -278,7 +282,7 @@
 
 handleCmd_inRoom client _ rooms ["REMOVE_TEAM", teamName] =
 	if noSuchTeam then
-		(noChangeClients, noChangeRooms, answerBadParam)
+		(noChangeClients, noChangeRooms, [])
 	else
 		if not $ nick client == teamowner team then
 			(noChangeClients, noChangeRooms, answerNotOwner)