- Add protocol description (just started)
authorunc0rr
Wed, 08 Oct 2008 18:25:08 +0000
changeset 1321 d7dc4e86201e
parent 1320 bffc7262e25e
child 1322 c624b04699fb
- Add protocol description (just started) - Some work on server to make team add posiible
QTfrontend/newnetclient.cpp
doc/Protocol.dia
doc/Protocol.odt
netserver/HWProto.hs
netserver/Miscutils.hs
netserver/newhwserv.hs
--- a/QTfrontend/newnetclient.cpp	Wed Oct 08 15:57:35 2008 +0000
+++ b/QTfrontend/newnetclient.cpp	Wed Oct 08 18:25:08 2008 +0000
@@ -61,7 +61,7 @@
 {
 	if(netClientState != 2)
 	{
-		qDebug("Illegal try to create room!");
+		qWarning("Illegal try to create room!");
 		return;
 	}
 	
@@ -73,7 +73,7 @@
 {
 	if(netClientState != 2)
 	{
-		qDebug("Illegal try to join room!");
+		qWarning("Illegal try to join room!");
 		return;
 	}
 	
@@ -242,19 +242,19 @@
 		return;
 	}
 
-  if (lst[0] == "ADDTEAM:") {
-    if(lst.size() < 22)
-    {
-	  qWarning("Net: Too short ADDTEAM message");
-	  return;
-    }
-    QStringList tmp = lst;
-    tmp.removeFirst();
-    emit AddNetTeam(tmp);
-    return;
-  }
+	if (lst[0] == "ADDTEAM") {
+		if(lst.size() < 22)
+		{
+			qWarning("Net: Too short ADDTEAM message");
+			return;
+		}
+		QStringList tmp = lst;
+		tmp.removeFirst();
+		emit AddNetTeam(tmp);
+		return;
+	}
 
-  if (lst[0] == "REMOVETEAM:") {
+  if (lst[0] == "REMOVETEAM") {
     if(lst.size() < 3)
     {
       qWarning("Net: Bad REMOVETEAM message");
@@ -410,16 +410,16 @@
 
 void HWNewNet::onHedgehogsNumChanged(const HWTeam& team)
 {
-  RawSendNet(QString("HHNUM%1%2%1%3%1%4").arg(delimeter).arg(team.TeamName)\
-	     .arg(team.getNetID() ? team.getNetID() : m_networkToLocalteams.key(team.TeamName))\
-	     .arg(team.numHedgehogs));
+	RawSendNet(QString("HHNUM%1%2%1%3%1%4").arg(delimeter).arg(team.TeamName)
+			.arg(team.getNetID() ? team.getNetID() : m_networkToLocalteams.key(team.TeamName))
+			.arg(team.numHedgehogs));
 }
 
 void HWNewNet::onTeamColorChanged(const HWTeam& team)
 {
-  RawSendNet(QString("CONFIG_PARAM%1TEAM_COLOR+%2+%3%1%4").arg(delimeter).arg(team.TeamName)\
-	     .arg(team.getNetID() ? team.getNetID() : m_networkToLocalteams.key(team.TeamName))\
-	     .arg(team.teamColor.name()));
+	RawSendNet(QString("CONFIG_PARAM%1TEAM_COLOR+%2+%3%1%4").arg(delimeter).arg(team.TeamName)
+			.arg(team.getNetID() ? team.getNetID() : m_networkToLocalteams.key(team.TeamName))
+			.arg(team.teamColor.name()));
 }
 
 void HWNewNet::onSeedChanged(const QString & seed)
@@ -469,7 +469,7 @@
 {
 	if(netClientState != 2)
 	{
-		qDebug("Illegal try to get rooms list!");
+		qWarning("Illegal try to get rooms list!");
 		return;
 	}
 	RawSendNet(QString("LIST"));
Binary file doc/Protocol.dia has changed
Binary file doc/Protocol.odt has changed
--- a/netserver/HWProto.hs	Wed Oct 08 15:57:35 2008 +0000
+++ b/netserver/HWProto.hs	Wed Oct 08 18:25:08 2008 +0000
@@ -27,7 +27,7 @@
 answerConfigParam paramName paramStrs = [(othersInRoom, "CONFIG_PARAM" : paramName : paramStrs)]
 answerFullConfig room = map toAnswer (Map.toList $ params room)
 	where
-		toAnswer (paramName, paramStrs)=
+		toAnswer (paramName, paramStrs) =
 			(clientOnly, "CONFIG_PARAM" : paramName : paramStrs)
 
 -- Main state-independent cmd handler
@@ -95,14 +95,14 @@
 handleCmd_noRoom client clients rooms ["JOIN", roomName, roomPassword] =
 	if noSuchRoom then
 		(noChangeClients, noChangeRooms, answerNoRoom)
-	else if roomPassword /= password joinRoom then
+	else if roomPassword /= password clRoom then
 		(noChangeClients, noChangeRooms, answerWrongPassword)
 	else
-		(modifyClient client{room = roomName}, noChangeRooms, (answerJoined $ nick client) ++ answerNicks ++ answerFullConfig joinRoom)
+		(modifyClient client{room = roomName}, noChangeRooms, (answerJoined $ nick client) ++ answerNicks ++ answerFullConfig clRoom)
 	where
 		noSuchRoom = isNothing $ find (\room -> roomName == name room) rooms
 		answerNicks = [(clientOnly, ["JOINED"] ++ (map nick $ filter (\ci -> room ci == roomName) clients))]
-		joinRoom = roomByName roomName rooms
+		clRoom = roomByName roomName rooms
 
 handleCmd_noRoom client clients rooms ["JOIN", roomName] =
 	handleCmd_noRoom client clients rooms ["JOIN", roomName, ""]
@@ -115,10 +115,16 @@
 handleCmd_inRoom client _ _ ["CHAT_STRING", _, msg] =
 	(noChangeClients, noChangeRooms, answerChatString (nick client) msg)
 
-handleCmd_inRoom client _ _ ("CONFIG_PARAM":paramName:paramStrs) =
+handleCmd_inRoom client _ rooms ("CONFIG_PARAM":paramName:paramStrs) =
 	if isMaster client then
-		(noChangeClients, changeRoomConfig (room client) paramName paramStrs, answerConfigParam paramName paramStrs)
+		(noChangeClients, modifyRoom clRoom{params = Map.insert paramName paramStrs (params room)}, answerConfigParam paramName paramStrs)
 	else
 		(noChangeClients, noChangeRooms, answerNotMaster)
+	where
+		clRoom = roomByName (room client) rooms
+
+
+handleCmd_inRoom client _ _ ("ADDTEAM" : name : color : grave : fort : difStr : hhsInfo)
+	| length hhsInfo == 16 = (noChangeClients, noChangeRooms, answerBadCmd)
 
 handleCmd_inRoom _ _ _ _ = (noChangeClients, noChangeRooms, answerBadCmd)
--- a/netserver/Miscutils.hs	Wed Oct 08 15:57:35 2008 +0000
+++ b/netserver/Miscutils.hs	Wed Oct 08 18:25:08 2008 +0000
@@ -29,6 +29,10 @@
 	TeamInfo
 	{
 		teamname :: String,
+		teamcolor :: String,
+		teamgrave :: String,
+		teamfort :: String,
+		difficulty :: Int,
 		hedgehogs :: [HedgehogInfo]
 	}
 
@@ -82,6 +86,7 @@
 noChangeClients a = a
 
 modifyClient :: ClientInfo -> ClientsTransform
+modifyClient _ [] = error "modifyClient: no such client"
 modifyClient client (cl:cls) =
 	if cl == client then
 		client : cls
@@ -97,10 +102,10 @@
 removeRoom :: String -> RoomsTransform
 removeRoom roomname rooms = filter (\rm -> roomname /= name rm) rooms
 
-changeRoomConfig :: String -> String -> [String] -> RoomsTransform
-changeRoomConfig _ _ _ [] = error "changeRoomConfig: no such room"
-changeRoomConfig roomName paramName paramStrs (room:rooms) =
-	if roomName == name room then
-		room{params = Map.insert paramName paramStrs (params room)} : rooms
+modifyRoom :: RoomInfo -> RoomsTransform
+modifyRoom _ [] = error "changeRoomConfig: no such room"
+modifyRoom room (rm:rms) =
+	if name room == name rm then
+		room : rms
 	else
-		room : changeRoomConfig roomName paramName paramStrs rooms
+		room : modifyRoom room rms
--- a/netserver/newhwserv.hs	Wed Oct 08 15:57:35 2008 +0000
+++ b/netserver/newhwserv.hs	Wed Oct 08 18:25:08 2008 +0000
@@ -42,7 +42,7 @@
 sendAnswers [] _ clients _ = return clients
 sendAnswers ((handlesFunc, answer):answers) client clients rooms = do
 	let recipients = handlesFunc client clients rooms
-	putStrLn ("< " ++ (show answer) ++ " (" ++ (show $ length recipients) ++ " recipients)")
+	putStrLn ("< " ++ (show answer))
 
 	clHandles' <- forM recipients $
 		\ch -> Control.Exception.handle (\e -> putStrLn (show e) >> hClose ch >> return [ch]) $