- Allow team color changing
authorunc0rr
Thu, 09 Oct 2008 13:53:03 +0000
changeset 1330 12c13ffb426f
parent 1329 69ddc231a911
child 1331 ae291cfd617a
- Allow team color changing - Fix team removing handler in client's code
QTfrontend/newnetclient.cpp
doc/Protocol.odt
netserver/HWProto.hs
--- a/QTfrontend/newnetclient.cpp	Thu Oct 09 13:48:06 2008 +0000
+++ b/QTfrontend/newnetclient.cpp	Thu Oct 09 13:53:03 2008 +0000
@@ -254,7 +254,7 @@
 	}
 
   if (lst[0] == "REMOVE_TEAM") {
-    if(lst.size() < 3)
+    if(lst.size() != 2)
     {
       qWarning("Net: Bad REMOVETEAM message");
       return;
@@ -345,13 +345,6 @@
 			emit ammoChanged(lst[3], lst[2]);
 			return;
 		}
-/*		QStringList hhTmpList = lst[1].split('+');// deprecated stuff
-		if (hhTmpList[0] == "TEAM_COLOR") {
-			HWTeam tmptm(hhTmpList[1]);
-			tmptm.teamColor = QColor(lst[2]);
-			emit teamColorChanged(tmptm);
-			return;
-		}*/
 		qWarning() << "Net: Unknown 'CONFIG_PARAM' message:" << lst;
 		return;
 	}
@@ -368,6 +361,18 @@
 		return;
 	}
 
+	if (lst[0] == "TEAM_COLOR") {
+		if (lst.size() != 3)
+		{
+			qWarning("Net: Bad TEAM_COLOR message");
+			return;
+		}
+		HWTeam tmptm(lst[1]);
+		tmptm.teamColor = QColor(lst[2]);
+		emit teamColorChanged(tmptm);
+		return;
+	}
+
   if (lst[0] == "GAMEMSG") {
     if(lst.size() < 2)
     {
@@ -405,6 +410,7 @@
 
 void HWNewNet::onHedgehogsNumChanged(const HWTeam& team)
 {
+	if (isChief)
 	RawSendNet(QString("HH_NUM%1%2%1%3")
 			.arg(delimeter)
 			.arg(team.TeamName)
@@ -413,7 +419,8 @@
 
 void HWNewNet::onTeamColorChanged(const HWTeam& team)
 {
-	RawSendNet(QString("CONFIG_PARAM%1TEAM_COLOR%1%2%1%3")
+	if (isChief)
+	RawSendNet(QString("TEAM_COLOR%1%2%1%3")
 			.arg(delimeter)
 			.arg(team.TeamName)
 			.arg(team.teamColor.name()));
Binary file doc/Protocol.odt has changed
--- a/netserver/HWProto.hs	Thu Oct 09 13:48:06 2008 +0000
+++ b/netserver/HWProto.hs	Thu Oct 09 13:53:03 2008 +0000
@@ -38,6 +38,7 @@
 answerHHNum teamName hhNumber = [(othersInRoom, ["HH_NUM", teamName, show hhNumber])]
 answerRemoveTeam teamName = [(othersInRoom, ["REMOVE_TEAM", teamName])]
 answerNotOwner = [(clientOnly, ["ERROR", "You do not own this team"])]
+answerTeamColor teamName newColor = [(othersInRoom, ["TEAM_COLOR", teamName, newColor])]
 
 -- Main state-independent cmd handler
 handleCmd :: CmdHandler
@@ -164,6 +165,17 @@
 		clRoom = roomByName (room client) rooms
 		canAddNumber = 18 - (sum . map hhnum $ teams clRoom)
 
+handleCmd_inRoom client _ rooms ["TEAM_COLOR", teamName, newColor] =
+	if not $ isMaster client then
+		(noChangeClients, noChangeRooms, answerNotMaster)
+	else
+		(noChangeClients, modifyRoom $ modifyTeam clRoom team{teamcolor = newColor}, answerTeamColor teamName newColor)
+	where
+		noSuchTeam = isNothing findTeam
+		team = fromJust findTeam
+		findTeam = find (\t -> teamName == teamname t) $ teams clRoom
+		clRoom = roomByName (room client) rooms
+
 handleCmd_inRoom client _ rooms ["REMOVE_TEAM", teamName] =
 	if noSuchTeam then
 		(noChangeClients, noChangeRooms, answerBadParam)