- Frontend: reorganize code controlling widgets state, fix problems getting room admin status
authorunc0rr
Wed, 02 Sep 2009 09:04:06 +0000
changeset 2345 daf1785f2337
parent 2344 63b3da03ce46
child 2346 f07fd1ac2c48
- Frontend: reorganize code controlling widgets state, fix problems getting room admin status - Server: rename room after new room master
QTfrontend/hwform.cpp
QTfrontend/hwform.h
QTfrontend/newnetclient.cpp
QTfrontend/newnetclient.h
gameServer/Actions.hs
--- a/QTfrontend/hwform.cpp	Wed Sep 02 08:53:46 2009 +0000
+++ b/QTfrontend/hwform.cpp	Wed Sep 02 09:04:06 2009 +0000
@@ -577,13 +577,17 @@
 		hwnet, SLOT(CreateRoom(const QString&)));
 	connect(ui.pageRoomsList, SIGNAL(askForJoinRoom(const QString &)),
 		hwnet, SLOT(JoinRoom(const QString&)));
-	connect(ui.pageRoomsList, SIGNAL(askForCreateRoom(const QString &)),
-		this, SLOT(NetGameMaster()));
-	connect(ui.pageRoomsList, SIGNAL(askForJoinRoom(const QString &)),
-		this, SLOT(NetGameSlave()));
+//	connect(ui.pageRoomsList, SIGNAL(askForCreateRoom(const QString &)),
+//		this, SLOT(NetGameMaster()));
+//	connect(ui.pageRoomsList, SIGNAL(askForJoinRoom(const QString &)),
+//		this, SLOT(NetGameSlave()));
 	connect(ui.pageRoomsList, SIGNAL(askForRoomList()),
 		hwnet, SLOT(askRoomsList()));
 
+// room status stuff
+	connect(hwnet, SIGNAL(roomMaster(bool)),
+		this, SLOT(NetGameChangeStatus(bool)));
+
 // net page stuff
 	connect(hwnet, SIGNAL(chatStringFromNet(const QString&)),
 		ui.pageNetGame->pChatWidget, SLOT(onChatString(const QString&)));
@@ -881,12 +885,22 @@
 		sdli.StopMusic();
 }
 
+void HWForm::NetGameChangeStatus(bool isMaster)
+{
+	if (isMaster)
+		NetGameMaster();
+	else
+		NetGameSlave();
+}
+
 void HWForm::NetGameMaster()
 {
 	ui.pageNetGame->setMasterMode(true);
 	ui.pageNetGame->restrictJoins->setChecked(false);
 	ui.pageNetGame->restrictTeamAdds->setChecked(false);
 	ui.pageNetGame->pGameCFG->GameSchemes->setModel(ammoSchemeModel);
+	ui.pageNetGame->pGameCFG->setEnabled(true);
+	ui.pageNetGame->pNetTeamsWidget->setInteractivity(true);
 	
 	if (hwnet)
 	{
@@ -907,6 +921,9 @@
 
 void HWForm::NetGameSlave()
 {
+	ui.pageNetGame->pGameCFG->setEnabled(false);
+	ui.pageNetGame->pNetTeamsWidget->setInteractivity(false);
+	
 	if (hwnet)
 	{
 		NetAmmoSchemeModel * netAmmo = new NetAmmoSchemeModel(hwnet);
--- a/QTfrontend/hwform.h	Wed Sep 02 08:53:46 2009 +0000
+++ b/QTfrontend/hwform.h	Wed Sep 02 09:04:06 2009 +0000
@@ -96,8 +96,11 @@
 	void UpdateWeapons();
 	void onFrontendFullscreen(bool value);
 	void Music(bool checked);
+
+	void NetGameChangeStatus(bool isMaster);
 	void NetGameMaster();
 	void NetGameSlave();
+	
 	void AsyncNetServerStart();
 	void NetLeftRoom();
 	void selectFirstNetScheme();
--- a/QTfrontend/newnetclient.cpp	Wed Sep 02 08:53:46 2009 +0000
+++ b/QTfrontend/newnetclient.cpp	Wed Sep 02 09:04:06 2009 +0000
@@ -88,8 +88,6 @@
 	}
 	
 	RawSendNet(QString("CREATE_ROOM%1%2").arg(delimeter).arg(room));
-	m_pGameCFGWidget->setEnabled(true);
-	m_pTeamSelWidget->setInteractivity(true);
 	isChief = true;
 }
 
@@ -101,11 +99,7 @@
 		return;
 	}
 	
-	loginStep++;
-
 	RawSendNet(QString("JOIN_ROOM%1%2").arg(delimeter).arg(room));
-	m_pGameCFGWidget->setEnabled(false);
-	m_pTeamSelWidget->setInteractivity(false);
 	isChief = false;
 }
 
@@ -448,7 +442,7 @@
 
 	if (lst[0] == "RUN_GAME") {
 		netClientState = 5;
-		RunGame();
+		emit AskForRunGame();
 		return;
 	}
 
@@ -558,6 +552,7 @@
 		m_pGameCFGWidget->setEnabled(b);
 		m_pTeamSelWidget->setInteractivity(b);
 		isChief = b;
+		emit roomMaster(isChief);
 
 		return;
 	}
@@ -565,11 +560,6 @@
 	qWarning() << "Net: Unknown message:" << lst;
 }
 
-void HWNewNet::RunGame()
-{
-	emit AskForRunGame();
-}
-
 void HWNewNet::onHedgehogsNumChanged(const HWTeam& team)
 {
 	if (isChief)
--- a/QTfrontend/newnetclient.h	Wed Sep 02 08:53:46 2009 +0000
+++ b/QTfrontend/newnetclient.h	Wed Sep 02 09:04:06 2009 +0000
@@ -56,8 +56,6 @@
   QString seed;
   bool m_game_connected;
 
-  void RunGame();
-
   template <typename T>
   void SendCfgStrNet(T a) {
     QByteArray strmsg;
--- a/gameServer/Actions.hs	Wed Sep 02 08:53:46 2009 +0000
+++ b/gameServer/Actions.hs	Wed Sep 02 09:04:06 2009 +0000
@@ -233,9 +233,10 @@
 				adjust (\cl -> cl{isMaster = True}) newMasterId clients,
 				adjust (\r -> r{name = newRoomName}) rID rooms
 				)
-		newRoomName = "abandoned"
+		newRoomName = nick newMasterClient
 		otherPlayersSet = IntSet.delete clID (playersIDs room)
 		newMasterId = IntSet.findMin otherPlayersSet
+		newMasterClient = clients ! newMasterId
 
 
 processAction (clID, serverInfo, clients, rooms) (AddRoom roomName roomPassword) = do