diff -r 8cdfac630261 -r 727d13409891 QTfrontend/newnetclient.cpp --- a/QTfrontend/newnetclient.cpp Sun Sep 25 23:29:04 2011 +0200 +++ b/QTfrontend/newnetclient.cpp Mon Sep 26 00:15:10 2011 +0200 @@ -37,7 +37,7 @@ isChief(false), m_game_connected(false), loginStep(0), - netClientState(0) + netClientState(Disconnected) { // socket stuff connect(&NetSocket, SIGNAL(readyRead()), this, SLOT(ClientRead())); @@ -52,13 +52,14 @@ if (m_game_connected) { RawSendNet(QString("QUIT%1%2").arg(delimeter).arg("User quit")); - emit Disconnected(tr("User quit")); + emit disconnected(tr("User quit")); } NetSocket.flush(); } void HWNewNet::Connect(const QString & hostName, quint16 port, const QString & nick) { + netClientState = Connecting; mynick = nick; myhost = hostName + QString(":%1").arg(port); NetSocket.connectToHost(hostName, port); @@ -75,7 +76,7 @@ void HWNewNet::CreateRoom(const QString & room) { - if(netClientState != 2) + if(netClientState != InLobby) { qWarning("Illegal try to create room!"); return; @@ -89,7 +90,7 @@ void HWNewNet::JoinRoom(const QString & room) { - if(netClientState != 2) + if(netClientState != InLobby) { qWarning("Illegal try to join room!"); return; @@ -172,11 +173,13 @@ void HWNewNet::OnConnect() { + netClientState = Connected; } void HWNewNet::OnDisconnect() { - if(m_game_connected) emit Disconnected(""); + netClientState = Disconnected; + if(m_game_connected) emit disconnected(""); m_game_connected = false; } @@ -188,13 +191,13 @@ case QAbstractSocket::RemoteHostClosedError: break; case QAbstractSocket::HostNotFoundError: - emit Disconnected(tr("The host was not found. Please check the host name and port settings.")); + emit disconnected(tr("The host was not found. Please check the host name and port settings.")); break; case QAbstractSocket::ConnectionRefusedError: - emit Disconnected(tr("Connection refused")); + emit disconnected(tr("Connection refused")); break; default: - emit Disconnected(NetSocket.errorString()); + emit disconnected(NetSocket.errorString()); } } @@ -247,7 +250,7 @@ RawSendNet(QString("NICK%1%2").arg(delimeter).arg(mynick)); RawSendNet(QString("PROTO%1%2").arg(delimeter).arg(*cProtoVer)); - netClientState = 1; + netClientState = Connected; m_game_connected = true; emit adminAccess(false); return; @@ -284,7 +287,7 @@ qWarning("Net: Empty CHAT message"); return; } - if (netClientState == 2) + if (netClientState == InLobby) emit chatStringLobby(lst[1], HWProto::formatChatMsgForFrontend(lst[2])); else emit chatStringFromNet(HWProto::formatChatMsg(lst[1], lst[2])); @@ -299,7 +302,7 @@ } QStringList tmp = lst; tmp.removeFirst(); - if (netClientState == 2) + if (netClientState == InLobby) emit chatStringLobby(tmp.join("\n").prepend('\x01')); else emit chatStringFromNet(tmp.join("\n").prepend('\x01')); @@ -377,13 +380,13 @@ } if(lst[0] == "ROOMABANDONED") { - netClientState = 2; + netClientState = InLobby; emit LeftRoom(tr("Room destroyed")); return; } if(lst[0] == "KICKED") { - netClientState = 2; + netClientState = InLobby; emit LeftRoom(tr("You got kicked")); return; } @@ -399,24 +402,15 @@ { if (lst[i] == mynick) { - netClientState = 3; + netClientState = InRoom; emit EnteredGame(); emit roomMaster(isChief); if (isChief) emit configAsked(); } - // TODO reactivate -/* - if (lst[i] != mynick && isChief && config->Form->ui.pageRoomsList->chatWidget->ignoreList.contains(lst[i], Qt::CaseInsensitive) && !config->Form->ui.pageRoomsList->chatWidget->friendsList.contains(lst[i], Qt::CaseInsensitive)) - { - kickPlayer(lst[i]); - } - else -*/ - { - emit nickAdded(lst[i], isChief && (lst[i] != mynick)); - emit chatStringFromNet(tr("%1 *** %2 has joined the room").arg('\x03').arg(lst[i])); - } + + emit nickAdded(lst[i], isChief && (lst[i] != mynick)); + emit chatStringFromNet(tr("%1 *** %2 has joined the room").arg('\x03').arg(lst[i])); } return; } @@ -432,9 +426,9 @@ { if (lst[i] == mynick) { - netClientState = 2; + netClientState = InLobby; RawSendNet(QString("LIST")); - emit Connected(); + emit connected(); } emit nickAddedLobby(lst[i], false); @@ -482,7 +476,7 @@ } if (lst[0] == "RUN_GAME") { - netClientState = 5; + netClientState = InGame; emit AskForRunGame(); return; } @@ -589,7 +583,7 @@ } m_game_connected = false; Disconnect(); - emit Disconnected(lst[1]); + emit disconnected(lst[1]); return; } @@ -665,7 +659,7 @@ void HWNewNet::askRoomsList() { - if(netClientState != 2) + if(netClientState != InLobby) { qWarning("Illegal try to get rooms list!"); return; @@ -673,7 +667,7 @@ RawSendNet(QString("LIST")); } -int HWNewNet::getClientState() +HWNewNet::ClientState HWNewNet::clientState() { return netClientState; } @@ -700,7 +694,7 @@ void HWNewNet::gameFinished(bool correctly) { - if (netClientState == 5) netClientState = 3; + if (netClientState == InGame) netClientState = InRoom; RawSendNet(QString("ROUNDFINISHED%1%2").arg(delimeter).arg(correctly ? "1" : "0")); } @@ -755,13 +749,13 @@ void HWNewNet::partRoom() { - netClientState = 2; + netClientState = InLobby; RawSendNet(QString("PART")); } bool HWNewNet::isInRoom() { - return netClientState > 2; + return netClientState >= InRoom; } void HWNewNet::setServerMessageNew(const QString & msg)