- Fix build of server (has some bugs now)
authorunc0rr
Sun, 05 Oct 2008 23:27:53 +0000
changeset 1305 453882eb4467
parent 1304 05cebf68ebd8
child 1306 e848447f29be
- Fix build of server (has some bugs now) - Start converting client
QTfrontend/newnetclient.cpp
netserver/HWProto.hs
netserver/newhwserv.hs
--- a/QTfrontend/newnetclient.cpp	Sun Oct 05 23:22:14 2008 +0000
+++ b/QTfrontend/newnetclient.cpp	Sun Oct 05 23:27:53 2008 +0000
@@ -163,18 +163,21 @@
 
 void HWNewNet::ParseCmd(const QStringList & lst)
 {
-  qDebug() << "Server: " << lst;
+	qDebug() << "Server: " << lst;
+
+	if(!lst.size())
+	{
+		qWarning("Net client: Bad message");
+		return;
+	}
 
-  if(!lst.size())
-  {
-    qWarning("Net client: Bad message");
-    return;
-  }
-
-  if (lst[0] == "ERRONEUSNICKNAME") {
-    QMessageBox::information(0, 0, "Your net nickname is in use or cannot be used");
-    return;
-  }
+	if (lst[0] == "ERROR") {
+		if (lst.size() == 2)
+			QMessageBox::information(0, 0, lst[1]);
+		else
+			QMessageBox::information(0, 0, "Unknown error");
+		return;
+	}
 
   if (lst[0] == "CONNECTED") {
     m_game_connected=true;
--- a/netserver/HWProto.hs	Sun Oct 05 23:22:14 2008 +0000
+++ b/netserver/HWProto.hs	Sun Oct 05 23:27:53 2008 +0000
@@ -7,8 +7,8 @@
 import Maybe (fromMaybe, fromJust)
 
 answerBadCmd = [(clientOnly, ["ERROR", "Bad command, state or incorrect parameter"])]
-answerQuit = [(clientOnly, ["QUIT"])]
-answerAbandoned = [(sameRoom, ["ROOMABANDONED"])]
+answerQuit = [(clientOnly, ["BYE"])]
+answerAbandoned = [(sameRoom, ["BYE"])]
 answerQuitInform nick = [(sameRoom, ["QUIT", nick])]
 answerNickChosen = [(clientOnly, ["ERROR", "The nick already chosen"])]
 answerNickChooseAnother = [(clientOnly, ["WARNING", "Choose another nick"])]
--- a/netserver/newhwserv.hs	Sun Oct 05 23:22:14 2008 +0000
+++ b/netserver/newhwserv.hs	Sun Oct 05 23:27:53 2008 +0000
@@ -43,24 +43,24 @@
 			mainLoop servSock acceptChan (ci:clients) rooms
 		Right (cmd, client) -> do
 			putStrLn ("> " ++ show cmd)
-			let (clientsFunc, roomsFunc, handlesFunc, answer) = handleCmd client clients rooms $ cmd
-			putStrLn ("< " ++ show answer)
+			let (clientsFunc, roomsFunc, answers) = handleCmd client clients rooms $ cmd
 
 			let mclients = clientsFunc clients
 			let mrooms = roomsFunc rooms
-			let recipients = handlesFunc client mclients mrooms
-			
-			clHandles' <- forM recipients $
-					\ch -> do
+
+			clHandles' <- forM answers $
+				\(handlesFunc, answer) -> do
+					putStrLn ("< " ++ show answer)
+					let recipients = handlesFunc client mclients mrooms
+					forM recipients $
+						\ch -> do
 							forM_ answer (\str -> hPutStrLn ch str)
 							hPutStrLn ch ""
 							hFlush ch
-							if (not $ null answer) && (head answer == "ROOMABANDONED") then hClose ch >> return [ch] else return []
-					`catch` const (hClose ch >> return [ch])
+							if (not $ null answer) && (head answer == "BYE") then hClose ch >> return [ch] else return []
+						`catch` const (hClose ch >> return [ch])
 
-			clHandle' <- if (not $ null answer) && (head answer == "QUIT") then hClose (handle client) >> return [handle client] else return []
-
-			mainLoop servSock acceptChan (remove (remove mclients (concat clHandles')) clHandle') mrooms
+			mainLoop servSock acceptChan (remove mclients (concat $ concat clHandles')) mrooms
 			where
 				remove list rmClHandles = deleteFirstsBy2t (\ a b -> (handle a) == b) list rmClHandles