Adding teams now works
authorunc0rr
Wed, 08 Oct 2008 18:56:32 +0000
changeset 1325 c8994d47f41d
parent 1324 4b48ae1f0f53
child 1326 bf91f935feff
Adding teams now works
QTfrontend/newnetclient.cpp
QTfrontend/team.cpp
QTfrontend/team.h
netserver/HWProto.hs
--- a/QTfrontend/newnetclient.cpp	Wed Oct 08 18:46:02 2008 +0000
+++ b/QTfrontend/newnetclient.cpp	Wed Oct 08 18:56:32 2008 +0000
@@ -241,10 +241,10 @@
 		return;
 	}
 
-	if (lst[0] == "ADDTEAM") {
-		if(lst.size() < 22)
+	if (lst[0] == "ADD_TEAM") {
+		if(lst.size() != 21)
 		{
-			qWarning("Net: Too short ADDTEAM message");
+			qWarning("Net: Bad ADDTEAM message");
 			return;
 		}
 		QStringList tmp = lst;
@@ -259,7 +259,7 @@
       qWarning("Net: Bad REMOVETEAM message");
       return;
     }
-    m_pTeamSelWidget->removeNetTeam(HWTeam(lst[1], lst[2].toUInt()));
+    m_pTeamSelWidget->removeNetTeam(HWTeam(lst[1]));
     return;
   }
 
@@ -284,7 +284,7 @@
 		return;
 	}
 
-	if(lst[0]=="LEFT") {
+	if(lst[0] == "LEFT") {
 		if(lst.size() < 2)
 		{
 			qWarning("Net: Bad LEFT message");
@@ -294,21 +294,21 @@
 		return;
 	}
 
-  if (lst[0] == "RUNGAME") {
-    RunGame();
-    return;
-  }
+	if (lst[0] == "RUNGAME") {
+		RunGame();
+		return;
+	}
 
 
-  if(lst[0]=="TEAM_ACCEPTED") {
-    if(lst.size() < 3)
-    {
-      qWarning("Net: Bad TEAM_ACCEPTED message");
-      return;
-    }
-    m_pTeamSelWidget->changeTeamStatus(lst[1]);
-    return;
-  }
+	if (lst[0] == "TEAM_ACCEPTED") {
+		if (lst.size() != 2)
+		{
+			qWarning("Net: Bad TEAM_ACCEPTED message");
+			return;
+		}
+		m_pTeamSelWidget->changeTeamStatus(lst[1]);
+		return;
+	}
 
 	if (lst[0] == "CONFIG_PARAM") {
 		if(lst.size() < 3)
@@ -345,7 +345,7 @@
 			emit ammoChanged(lst[3], lst[2]);
 			return;
 		}
-		QStringList hhTmpList = lst[1].split('+');
+		QStringList hhTmpList = lst[1].split('+');// deprecated stuff
 		if (hhTmpList[0] == "TEAM_COLOR") {
 			HWTeam tmptm(hhTmpList[1]);
 			tmptm.teamColor = QColor(lst[2]);
@@ -363,8 +363,6 @@
 	}
 
 
-  // should be kinda game states, which don't allow "GAMEMSG:" at configure step,
-  // "CONNECTED" at round phase, etc.
   if (lst[0] == "GAMEMSG") {
     if(lst.size() < 2)
     {
--- a/QTfrontend/team.cpp	Wed Oct 08 18:46:02 2008 +0000
+++ b/QTfrontend/team.cpp	Wed Oct 08 18:56:32 2008 +0000
@@ -28,10 +28,10 @@
 #include "hwconsts.h"
 #include "hats.h"
 
-HWTeam::HWTeam(const QString & teamname, unsigned int netID) :
-  difficulty(0),
-  numHedgehogs(4),
-  m_netID(netID)
+HWTeam::HWTeam(const QString & teamname) :
+	difficulty(0),
+	numHedgehogs(4),
+	m_isNetTeam(false)
 {
 	TeamName = teamname;
 	OldTeamName = TeamName;
@@ -50,26 +50,26 @@
 }
 
 HWTeam::HWTeam(const QStringList& strLst) :
-  numHedgehogs(4)
+  numHedgehogs(4),
+  m_isNetTeam(true)
 {
 	// net teams are configured from QStringList
-	if(strLst.size() < 21) throw HWTeamConstructException();
-	TeamName=strLst[0];
-	m_netID=strLst[1].toUInt();
-	Grave=strLst[2];
-	Fort=strLst[3];
-	difficulty=strLst[4].toUInt();
+	if(strLst.size() < 20) throw HWTeamConstructException();
+	TeamName = strLst[0];
+	Grave = strLst[1];
+	Fort = strLst[2];
+	difficulty = strLst[3].toUInt();
 	for(int i = 0; i < 8; i++)
 	{
-		HHName[i]=strLst[i * 2 + 5];
-		HHHat[i]=strLst[i * 2 + 6];
+		HHName[i]=strLst[i * 2 + 4];
+		HHHat[i]=strLst[i * 2 + 5];
 	}
 }
 
 HWTeam::HWTeam(quint8 num) :
   difficulty(0),
   numHedgehogs(4),
-  m_netID(0)
+  m_isNetTeam(false)
 {
 	num %= PREDEFTEAMS_COUNT;
 	TeamName = QApplication::translate("teams", pteams[num].TeamName);
@@ -242,13 +242,13 @@
 	QStringList sl;
 	sl.push_back(QString("eaddteam %1 %2").arg(teamColor.rgb() & 0xffffff).arg(TeamName));
 
-	if (m_netID)
+	if (m_isNetTeam)
 		sl.push_back("erdriven");
 
 	sl.push_back(QString("egrave " + Grave));
 	sl.push_back(QString("efort " + Fort));
 
-	if (!m_netID)
+	if (!m_isNetTeam)
 		for(int i = 0; i < BINDS_NUMBER; i++)
 			sl.push_back(QString("ebind " + binds[i].strbind + " " + binds[i].action));
 
@@ -266,18 +266,14 @@
 
 bool HWTeam::isNetTeam() const
 {
-  return m_netID!=0;
+  return m_isNetTeam;
 }
 
-unsigned int HWTeam::getNetID() const
-{
-  return m_netID;
-}
 
 bool HWTeam::operator==(const HWTeam& t1) const {
-  return TeamName==t1.TeamName && m_netID==t1.m_netID;
+  return TeamName==t1.TeamName;
 }
 
 bool HWTeam::operator<(const HWTeam& t1) const {
-  return m_netID<t1.m_netID || TeamName<t1.TeamName; // if names are equal - test if it is net team
+  return TeamName<t1.TeamName; // if names are equal - test if it is net team
 }
--- a/QTfrontend/team.h	Wed Oct 08 18:46:02 2008 +0000
+++ b/QTfrontend/team.h	Wed Oct 08 18:56:32 2008 +0000
@@ -34,12 +34,11 @@
 class HWTeam
 {
 	public:
-		HWTeam(const QString & teamname, unsigned int netID=0);
+		HWTeam(const QString & teamname);
 		HWTeam(const QStringList& strLst);
 		HWTeam(quint8 num);
 
 		bool isNetTeam() const;
-		unsigned int getNetID() const;
 
 		QString TeamName;
 		QString HHName[8];
@@ -61,7 +60,7 @@
 		bool operator==(const HWTeam& t1) const;
 		bool operator<(const HWTeam& t1) const;
 	private:
-		unsigned int m_netID;
+		bool m_isNetTeam;
 		QString OldTeamName;
 };
 
--- a/netserver/HWProto.hs	Wed Oct 08 18:46:02 2008 +0000
+++ b/netserver/HWProto.hs	Wed Oct 08 18:56:32 2008 +0000
@@ -30,6 +30,10 @@
 		toAnswer (paramName, paramStrs) =
 			(clientOnly, "CONFIG_PARAM" : paramName : paramStrs)
 answerCantAdd = [(clientOnly, ["WARNING", "Too many teams"])]
+answerTeamAccepted team = [(clientOnly, ["TEAM_ACCEPTED", teamname team])]
+answerAddTeam team = [(othersInRoom, ["ADD_TEAM", teamname team, teamgrave team, teamfort team, show $ difficulty team] ++ hhsInfo)]
+	where
+		hhsInfo = concatMap (\(HedgehogInfo name hat) -> [name, hat]) $ hedgehogs team
 
 -- Main state-independent cmd handler
 handleCmd :: CmdHandler
@@ -129,11 +133,12 @@
 	if length (teams clRoom) == 6 then
 		(noChangeClients, noChangeRooms, answerCantAdd)
 	else
-		(noChangeClients, modifyRoom clRoom{teams = newTeam : teams clRoom}, [])
+		(noChangeClients, modifyRoom clRoom{teams = newTeam : teams clRoom}, answerTeamAccepted newTeam ++ answerAddTeam newTeam)
 	where
 		clRoom = roomByName (room client) rooms
 		newTeam = (TeamInfo name color grave fort difficulty (hhsList hhsInfo))
 		difficulty = fromMaybe 0 (maybeRead difStr :: Maybe Int)
+		hhsList [] = []
 		hhsList (n:h:hhs) = HedgehogInfo n h : hhsList hhs