Start work on lobby: add/remove nick from the list on join/quit
authorunc0rr
Fri, 02 Jan 2009 19:44:52 +0000
changeset 1566 6b63c75fdc68
parent 1565 1b670ec71e47
child 1567 95d7aab0df3f
Start work on lobby: add/remove nick from the list on join/quit
QTfrontend/hwform.cpp
QTfrontend/newnetclient.cpp
QTfrontend/newnetclient.h
hedgewars/uConsts.pas
netserver/HWProto.hs
share/hedgewars/Data/Sounds/voices/Default/CMakeLists.txt
--- a/QTfrontend/hwform.cpp	Fri Jan 02 17:33:56 2009 +0000
+++ b/QTfrontend/hwform.cpp	Fri Jan 02 19:44:52 2009 +0000
@@ -435,6 +435,7 @@
 	}
 	
 	ui.pageNetGame->pChatWidget->clear();
+	ui.pageRoomsList->chatWidget->clear();
 	
 	hwnet = new HWNewNet(config, ui.pageNetGame->pGameCFG, ui.pageNetGame->pNetTeamsWidget);
 
@@ -471,11 +472,16 @@
 		hwnet, SLOT(chatLineToNet(const QString&)));
 	connect(ui.pageNetGame->pChatWidget, SIGNAL(kick(const QString&)),
 		hwnet, SLOT(kickPlayer(const QString&)));
+	connect(ui.pageNetGame->BtnGo, SIGNAL(clicked()), hwnet, SLOT(ToggleReady()));
+
 	connect(hwnet, SIGNAL(nickAdded(const QString&)),
 		ui.pageNetGame->pChatWidget, SLOT(nickAdded(const QString&)));
 	connect(hwnet, SIGNAL(nickRemoved(const QString&)),
 		ui.pageNetGame->pChatWidget, SLOT(nickRemoved(const QString&)));
-	connect(ui.pageNetGame->BtnGo, SIGNAL(clicked()), hwnet, SLOT(ToggleReady()));
+	connect(hwnet, SIGNAL(nickAddedLobby(const QString&)),
+		ui.pageRoomsList->chatWidget, SLOT(nickAdded(const QString&)));
+	connect(hwnet, SIGNAL(nickRemovedLobby(const QString&)),
+		ui.pageRoomsList->chatWidget, SLOT(nickRemoved(const QString&)));
 
 	connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(hhogsNumChanged(const HWTeam&)),
 		hwnet, SLOT(onHedgehogsNumChanged(const HWTeam&)));
--- a/QTfrontend/newnetclient.cpp	Fri Jan 02 17:33:56 2009 +0000
+++ b/QTfrontend/newnetclient.cpp	Fri Jan 02 19:44:52 2009 +0000
@@ -189,7 +189,7 @@
 
 void HWNewNet::ParseCmd(const QStringList & lst)
 {
-//	qDebug() << "Server: " << lst;
+	qDebug() << "Server: " << lst;
 
 	if(!lst.size())
 	{
@@ -334,6 +334,21 @@
 		return;
 	}
 
+	if(lst[0]=="LOBBY:JOINED") {
+		if(lst.size() < 2)
+		{
+			qWarning("Net: Bad JOINED message");
+			return;
+		}
+		
+		for(int i = 1; i < lst.size(); ++i)
+		{
+			emit nickAddedLobby(lst[i]);
+			//emit chatStringFromNet(QString(tr("*** %1 joined")).arg(lst[i]));
+		}
+		return;
+	}
+
 	if(lst[0] == "LEFT") {
 		if(lst.size() < 2)
 		{
@@ -348,6 +363,20 @@
 		return;
 	}
 
+	if(lst[0] == "LOBBY:LEFT") {
+		if(lst.size() < 2)
+		{
+			qWarning("Net: Bad LEFT message");
+			return;
+		}
+		emit nickRemovedLobby(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;
+	}
+
 	if (lst[0] == "RUN_GAME") {
 		netClientState = 5;
 		RunGame();
--- a/QTfrontend/newnetclient.h	Fri Jan 02 17:33:56 2009 +0000
+++ b/QTfrontend/newnetclient.h	Fri Jan 02 19:44:52 2009 +0000
@@ -94,6 +94,8 @@
   void EnteredGame();
   void nickAdded(const QString& nick);
   void nickRemoved(const QString& nick);
+  void nickAddedLobby(const QString& nick);
+  void nickRemovedLobby(const QString& nick);
   void FromNet(const QByteArray & buf);
   void AddNetTeam(const HWTeam&);
 
--- a/hedgewars/uConsts.pas	Fri Jan 02 17:33:56 2009 +0000
+++ b/hedgewars/uConsts.pas	Fri Jan 02 19:44:52 2009 +0000
@@ -274,7 +274,7 @@
 			'Locale',                        // ptLocale
 			'Graphics/AmmoMenu',             // ptAmmoMenu
 			'Graphics/Hedgehog',             // ptHedgehog
-			'Sounds/voices',                 // ptVoices
+			'Sounds/voices/Default',         // ptVoices
 			'Graphics/Hats'                  // ptHats
 			);
 
--- a/netserver/HWProto.hs	Fri Jan 02 17:33:56 2009 +0000
+++ b/netserver/HWProto.hs	Fri Jan 02 19:44:52 2009 +0000
@@ -58,6 +58,11 @@
 		answerOthersRoom ["LEFT", nick, msg]
 		else
 		answerOthersRoom ["LEFT", nick]
+answerQuitLobby nick msg =
+	if not $ null msg then
+		answerOthersRoom ["LOBBY:LEFT", nick, msg]
+		else
+		answerOthersRoom ["LOBBY:LEFT", nick]
 
 answerJoined nick   = answerSameRoom ["JOINED", nick]
 answerRunGame       = answerSameRoom ["RUN_GAME"]
@@ -101,11 +106,11 @@
 handleCmd :: CmdHandler
 handleCmd client _ rooms ("QUIT" : xs) =
 	if null (room client) then
-		(noChangeClients, noChangeRooms, answerQuit msg)
+		(noChangeClients, noChangeRooms, answerQuit msg ++ (answerQuitLobby (nick client) msg) )
 	else if isMaster client then
-		(noChangeClients, removeRoom (room client), (answerQuit msg) ++ answerAbandoned) -- core disconnects clients on ROOMABANDONED answer
+		(noChangeClients, removeRoom (room client), (answerQuit msg) ++ (answerQuitLobby (nick client) 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) msg) ++ answerRemoveClientTeams)
+		(noChangeClients, modifyRoom clRoom{teams = othersTeams, playersIn = (playersIn clRoom) - 1, readyPlayers = newReadyPlayers}, (answerQuit msg) ++ (answerQuitInform (nick client) msg) ++ (answerQuitLobby (nick client) msg) ++ answerRemoveClientTeams)
 	where
 		clRoom = roomByName (room client) rooms
 		answerRemoveClientTeams = concatMap (\tn -> answerOthersRoom ["REMOVE_TEAM", teamname tn]) clientTeams
@@ -136,6 +141,13 @@
 
 
 -- 'no info' state - need to get protocol number and nickname
+onLoginFinished client clients =
+	if (protocol client < 20) || (null $ nick client) || (protocol client == 0) then
+		[]
+	else
+		(answerClientOnly $ ["LOBBY:JOINED"] ++ (map nick $ clients)) ++
+		(answerOthersRoom ["LOBBY:JOINED", nick client])
+
 handleCmd_noInfo :: CmdHandler
 handleCmd_noInfo client clients _ ["NICK", newNick] =
 	if not . null $ nick client then
@@ -143,17 +155,17 @@
 	else if haveSameNick then
 		(noChangeClients, noChangeRooms, answerNickChooseAnother)
 	else
-		(modifyClient client{nick = newNick}, noChangeRooms, answerNick newNick)
+		(modifyClient client{nick = newNick}, noChangeRooms, answerNick newNick ++ (onLoginFinished client{nick = newNick} clients))
 	where
 		haveSameNick = isJust $ find (\cl -> newNick == nick cl) clients
 
-handleCmd_noInfo client _ _ ["PROTO", protoNum] =
+handleCmd_noInfo client clients _ ["PROTO", protoNum] =
 	if protocol client > 0 then
 		(noChangeClients, noChangeRooms, answerProtocolKnown)
 	else if parsedProto == 0 then
 		(noChangeClients, noChangeRooms, answerBadInput)
 	else
-		(modifyClient client{protocol = parsedProto}, noChangeRooms, answerProto parsedProto)
+		(modifyClient client{protocol = parsedProto}, noChangeRooms, answerProto parsedProto ++ (onLoginFinished client{protocol = parsedProto} clients))
 	where
 		parsedProto = fromMaybe 0 (maybeRead protoNum :: Maybe Word16)
 
--- a/share/hedgewars/Data/Sounds/voices/Default/CMakeLists.txt	Fri Jan 02 17:33:56 2009 +0000
+++ b/share/hedgewars/Data/Sounds/voices/Default/CMakeLists.txt	Fri Jan 02 19:44:52 2009 +0000
@@ -2,4 +2,4 @@
 
 install(FILES
 	${BaseSounds}
-	DESTINATION ${SHAREPATH}Data/Sounds/voices)
+	DESTINATION ${SHAREPATH}Data/Sounds/voices/Default)