# HG changeset patch # User unc0rr # Date 1231271239 0 # Node ID 5ee77ee470a6ac3c14eb11552a6f9cac76b03b8c # Parent 1db9b654f880ecc05bbf1cf533e83a42e363e4bd Start converting network protocol to no-disconnecting religion diff -r 1db9b654f880 -r 5ee77ee470a6 QTfrontend/hwform.cpp --- a/QTfrontend/hwform.cpp Tue Jan 06 17:51:39 2009 +0000 +++ b/QTfrontend/hwform.cpp Tue Jan 06 19:47:19 2009 +0000 @@ -315,7 +315,7 @@ ui.Pages->setCurrentIndex(id); OnPageShown(id, curid); - if (id == ID_PAGE_ROOMSLIST || id == ID_PAGE_NETSERVER) { + if (id == ID_PAGE_NETSERVER) { GoBack(); } if (id == ID_PAGE_NET) { @@ -445,6 +445,7 @@ connect(hwnet, SIGNAL(Connected()), this, SLOT(NetConnected())); connect(hwnet, SIGNAL(EnteredGame()), this, SLOT(NetGameEnter())); connect(hwnet, SIGNAL(AddNetTeam(const HWTeam&)), this, SLOT(AddNetTeam(const HWTeam&))); + connect(ui.pageNetGame->BtnBack, SIGNAL(clicked()), hwnet, SLOT(partRoom())); connect(hwnet, SIGNAL(roomsList(const QStringList&)), ui.pageRoomsList, SLOT(setRoomsList(const QStringList&))); diff -r 1db9b654f880 -r 5ee77ee470a6 QTfrontend/newnetclient.cpp --- a/QTfrontend/newnetclient.cpp Tue Jan 06 17:51:39 2009 +0000 +++ b/QTfrontend/newnetclient.cpp Tue Jan 06 19:47:19 2009 +0000 @@ -140,7 +140,7 @@ void HWNewNet::RawSendNet(const QByteArray & buf) { - //qDebug() << "Client: " << QString(buf).split("\n"); + qDebug() << "Client: " << QString(buf).split("\n"); NetSocket.write(buf); NetSocket.write("\n\n", 2); } @@ -332,6 +332,12 @@ return; } + if(lst[0]=="ROOMABANDONED") { + netClientState = 2; + emit LeftRoom(); + return; + } + if(lst[0]=="JOINED") { if(lst.size() < 2) { @@ -687,3 +693,9 @@ { RawSendNet(QString("TOGGLE_RESTRICT_TEAMS")); } + +void HWNewNet::partRoom() +{ + netClientState = 2; + RawSendNet(QString("PART")); +} diff -r 1db9b654f880 -r 5ee77ee470a6 QTfrontend/newnetclient.h --- a/QTfrontend/newnetclient.h Tue Jan 06 17:51:39 2009 +0000 +++ b/QTfrontend/newnetclient.h Tue Jan 06 19:47:19 2009 +0000 @@ -92,6 +92,7 @@ void Connected(); void Disconnected(); void EnteredGame(); + void LeftRoom(); void nickAdded(const QString& nick); void nickRemoved(const QString& nick); void nickAddedLobby(const QString& nick); @@ -148,6 +149,7 @@ void startGame(); void toggleRestrictJoins(); void toggleRestrictTeamAdds(); + void partRoom(); private slots: void ClientRead(); diff -r 1db9b654f880 -r 5ee77ee470a6 netserver/HWProto.hs --- a/netserver/HWProto.hs Tue Jan 06 17:51:39 2009 +0000 +++ b/netserver/HWProto.hs Tue Jan 06 19:47:19 2009 +0000 @@ -50,7 +50,12 @@ where roomInfo = if not $ null $ room client then "room " ++ (room client) else "lobby" -answerAbandoned = answerOthersRoom ["BYE", "Room abandoned"] +answerAbandoned protocol = + if protocol < 20 then + answerOthersRoom ["BYE", "Room abandoned"] + else + answerOthersRoom ["ROOMABANDONED"] + answerChatString nick msg = answerOthersRoom ["CHAT_STRING", nick, msg] answerAddTeam team = answerOthersRoom $ teamToNet team answerRemoveTeam teamName = answerOthersRoom ["REMOVE_TEAM", teamName] @@ -63,6 +68,8 @@ answerOthersRoom ["LEFT", nick, msg] else answerOthersRoom ["LEFT", nick] + +answerPartInform nick = answerOthersRoom ["LEFT", nick, "bye room"] answerQuitLobby nick msg = if not $ null nick then if not $ null msg then @@ -118,7 +125,7 @@ if null (room client) then (noChangeClients, noChangeRooms, answerQuit msg ++ (answerQuitLobby (nick client) msg) ) else if isMaster client then - (noChangeClients, removeRoom (room client), (answerQuit msg) ++ (answerQuitLobby (nick client) msg) ++ answerAbandoned ++ (answerRoomDeleted $ room client)) -- core disconnects clients on ROOMABANDONED answer + (modifyRoomClients clRoom (\cl -> cl{room = [], isReady = False}), removeRoom (room client), (answerQuit msg) ++ (answerQuitLobby (nick client) msg) ++ (answerAbandoned $ protocol client) ++ (answerRoomDeleted $ room client)) -- core disconnects clients on ROOMABANDONED answer else (noChangeClients, modifyRoom clRoom{teams = othersTeams, playersIn = (playersIn clRoom) - 1, readyPlayers = newReadyPlayers}, (answerQuit msg) ++ (answerQuitInform (nick client) msg) ++ (answerQuitLobby (nick client) msg) ++ answerRemoveClientTeams) where @@ -260,6 +267,17 @@ where clRoom = roomByName (room client) rooms +handleCmd_inRoom client _ rooms ["PART"] = + if isMaster client then + (modifyRoomClients clRoom (\cl -> cl{room = [], isReady = False}), removeRoom (room client), (answerAbandoned $ protocol client) ++ (answerRoomDeleted $ room client)) + else + (modifyClient client{room = [], isReady = False}, modifyRoom clRoom{teams = othersTeams, playersIn = (playersIn clRoom) - 1, readyPlayers = newReadyPlayers}, (answerPartInform (nick client)) ++ answerRemoveClientTeams) + where + clRoom = roomByName (room client) rooms + answerRemoveClientTeams = concatMap (\tn -> answerOthersRoom ["REMOVE_TEAM", teamname tn]) clientTeams + (clientTeams, othersTeams) = partition (\t -> teamowner t == nick client) $ teams clRoom + newReadyPlayers = if isReady client then (readyPlayers clRoom) - 1 else readyPlayers clRoom + handleCmd_inRoom client _ rooms ["MAP", mapName] = if isMaster client then (noChangeClients, modifyRoom clRoom{gamemap = mapName}, answerMap mapName)