QTfrontend/net/newnetclient.cpp
changeset 6060 fdfc01419815
parent 6036 727d13409891
child 6062 2827ded8a5ef
equal deleted inserted replaced
6059:ddf020d0941a 6060:fdfc01419815
       
     1 /*
       
     2  * Hedgewars, a free turn based strategy game
       
     3  * Copyright (c) 2006-2008 Igor Ulyanov <iulyanov@gmail.com>
       
     4  * Copyright (c) 2008-2011 Andrey Korotaev <unC0Rr@gmail.com>
       
     5  *
       
     6  * This program is free software; you can redistribute it and/or modify
       
     7  * it under the terms of the GNU General Public License as published by
       
     8  * the Free Software Foundation; version 2 of the License
       
     9  *
       
    10  * This program is distributed in the hope that it will be useful,
       
    11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    13  * GNU General Public License for more details.
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License
       
    16  * along with this program; if not, write to the Free Software
       
    17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
       
    18  */
       
    19 
       
    20 #include <QDebug>
       
    21 #include <QInputDialog>
       
    22 #include <QCryptographicHash>
       
    23 
       
    24 #include "hwconsts.h"
       
    25 #include "newnetclient.h"
       
    26 #include "proto.h"
       
    27 #include "game.h"
       
    28 #include "misc.h"
       
    29 /* only to get the ignoreList from the chat widget */
       
    30 #include "hwform.h"
       
    31 #include "chatwidget.h"
       
    32 
       
    33 char delimeter='\n';
       
    34 
       
    35 HWNewNet::HWNewNet() :
       
    36   isChief(false),
       
    37   m_game_connected(false),
       
    38   loginStep(0),
       
    39   netClientState(Disconnected)
       
    40 {
       
    41 // socket stuff
       
    42     connect(&NetSocket, SIGNAL(readyRead()), this, SLOT(ClientRead()));
       
    43     connect(&NetSocket, SIGNAL(connected()), this, SLOT(OnConnect()));
       
    44     connect(&NetSocket, SIGNAL(disconnected()), this, SLOT(OnDisconnect()));
       
    45     connect(&NetSocket, SIGNAL(error(QAbstractSocket::SocketError)), this,
       
    46             SLOT(displayError(QAbstractSocket::SocketError)));
       
    47 }
       
    48 
       
    49 HWNewNet::~HWNewNet()
       
    50 {
       
    51     if (m_game_connected)
       
    52     {
       
    53         RawSendNet(QString("QUIT%1%2").arg(delimeter).arg("User quit"));
       
    54         emit disconnected(tr("User quit"));
       
    55     }
       
    56     NetSocket.flush();
       
    57 }
       
    58 
       
    59 void HWNewNet::Connect(const QString & hostName, quint16 port, const QString & nick)
       
    60 {
       
    61     netClientState = Connecting;
       
    62     mynick = nick;
       
    63     myhost = hostName + QString(":%1").arg(port);
       
    64     NetSocket.connectToHost(hostName, port);
       
    65 }
       
    66 
       
    67 void HWNewNet::Disconnect()
       
    68 {
       
    69     if (m_game_connected)
       
    70         RawSendNet(QString("QUIT%1%2").arg(delimeter).arg("User quit"));
       
    71     m_game_connected = false;
       
    72 
       
    73     NetSocket.disconnectFromHost();
       
    74 }
       
    75 
       
    76 void HWNewNet::CreateRoom(const QString & room)
       
    77 {
       
    78     if(netClientState != InLobby)
       
    79     {
       
    80         qWarning("Illegal try to create room!");
       
    81         return;
       
    82     }
       
    83 
       
    84     myroom = room;
       
    85 
       
    86     RawSendNet(QString("CREATE_ROOM%1%2").arg(delimeter).arg(room));
       
    87     isChief = true;
       
    88 }
       
    89 
       
    90 void HWNewNet::JoinRoom(const QString & room)
       
    91 {
       
    92     if(netClientState != InLobby)
       
    93     {
       
    94         qWarning("Illegal try to join room!");
       
    95         return;
       
    96     }
       
    97 
       
    98     myroom = room;
       
    99 
       
   100     RawSendNet(QString("JOIN_ROOM%1%2").arg(delimeter).arg(room));
       
   101     isChief = false;
       
   102 }
       
   103 
       
   104 void HWNewNet::AddTeam(const HWTeam & team)
       
   105 {
       
   106     QString cmd = QString("ADD_TEAM") + delimeter +
       
   107          team.name() + delimeter +
       
   108          team.color().name() + delimeter +
       
   109          team.grave() + delimeter +
       
   110          team.fort() + delimeter +
       
   111          team.voicepack() + delimeter +
       
   112          team.flag() + delimeter +
       
   113          QString::number(team.difficulty());
       
   114 
       
   115     for(int i = 0; i < HEDGEHOGS_PER_TEAM; ++i)
       
   116     {
       
   117         cmd.append(delimeter);
       
   118         cmd.append(team.hedgehog(i).Name);
       
   119         cmd.append(delimeter);
       
   120         cmd.append(team.hedgehog(i).Hat);
       
   121     }
       
   122     RawSendNet(cmd);
       
   123 }
       
   124 
       
   125 void HWNewNet::RemoveTeam(const HWTeam & team)
       
   126 {
       
   127     RawSendNet(QString("REMOVE_TEAM") + delimeter + team.name());
       
   128 }
       
   129 
       
   130 void HWNewNet::NewNick(const QString & nick)
       
   131 {
       
   132     RawSendNet(QString("NICK%1%2").arg(delimeter).arg(nick));
       
   133 }
       
   134 
       
   135 void HWNewNet::ToggleReady()
       
   136 {
       
   137   RawSendNet(QString("TOGGLE_READY"));
       
   138 }
       
   139 
       
   140 void HWNewNet::SendNet(const QByteArray & buf)
       
   141 {
       
   142   QString msg = QString(buf.toBase64());
       
   143 
       
   144   RawSendNet(QString("EM%1%2").arg(delimeter).arg(msg));
       
   145 }
       
   146 
       
   147 void HWNewNet::RawSendNet(const QString & str)
       
   148 {
       
   149   RawSendNet(str.toUtf8());
       
   150 }
       
   151 
       
   152 void HWNewNet::RawSendNet(const QByteArray & buf)
       
   153 {
       
   154     qDebug() << "Client: " << QString(buf).split("\n");
       
   155     NetSocket.write(buf);
       
   156     NetSocket.write("\n\n", 2);
       
   157 }
       
   158 
       
   159 void HWNewNet::ClientRead()
       
   160 {
       
   161     while (NetSocket.canReadLine()) {
       
   162         QString s = QString::fromUtf8(NetSocket.readLine());
       
   163         if (s.endsWith('\n')) s.chop(1);
       
   164 
       
   165         if (s.size() == 0) {
       
   166             ParseCmd(cmdbuf);
       
   167             cmdbuf.clear();
       
   168         } else
       
   169             cmdbuf << s;
       
   170     }
       
   171 }
       
   172 
       
   173 void HWNewNet::OnConnect()
       
   174 {
       
   175     netClientState = Connected;
       
   176 }
       
   177 
       
   178 void HWNewNet::OnDisconnect()
       
   179 {
       
   180     netClientState = Disconnected;
       
   181     if(m_game_connected) emit disconnected("");
       
   182     m_game_connected = false;
       
   183 }
       
   184 
       
   185 void HWNewNet::displayError(QAbstractSocket::SocketError socketError)
       
   186 {
       
   187     m_game_connected = false;
       
   188 
       
   189     switch (socketError) {
       
   190         case QAbstractSocket::RemoteHostClosedError:
       
   191             break;
       
   192         case QAbstractSocket::HostNotFoundError:
       
   193             emit disconnected(tr("The host was not found. Please check the host name and port settings."));
       
   194             break;
       
   195         case QAbstractSocket::ConnectionRefusedError:
       
   196             emit disconnected(tr("Connection refused"));
       
   197             break;
       
   198         default:
       
   199             emit disconnected(NetSocket.errorString());
       
   200         }
       
   201 }
       
   202 
       
   203 void HWNewNet::SendPasswordHash(const QString & hash)
       
   204 {
       
   205     RawSendNet(QString("PASSWORD%1%2").arg(delimeter).arg(hash));
       
   206 }
       
   207 
       
   208 void HWNewNet::ParseCmd(const QStringList & lst)
       
   209 {
       
   210   qDebug() << "Server: " << lst;
       
   211 
       
   212     if(!lst.size())
       
   213     {
       
   214         qWarning("Net client: Bad message");
       
   215         return;
       
   216     }
       
   217 
       
   218     if (lst[0] == "NICK")
       
   219     {
       
   220         mynick = lst[1];
       
   221         return ;
       
   222     }
       
   223 
       
   224     if (lst[0] == "PROTO")
       
   225         return ;
       
   226 
       
   227     if (lst[0] == "ERROR") {
       
   228         if (lst.size() == 2)
       
   229             emit Error(lst[1]);
       
   230         else
       
   231             emit Error("Unknown error");
       
   232         return;
       
   233     }
       
   234 
       
   235     if (lst[0] == "WARNING") {
       
   236         if (lst.size() == 2)
       
   237             emit Warning(lst[1]);
       
   238         else
       
   239             emit Warning("Unknown warning");
       
   240         return;
       
   241     }
       
   242 
       
   243     if (lst[0] == "CONNECTED") {
       
   244         if(lst.size() < 3 || lst[2].toInt() < cMinServerVersion)
       
   245         {
       
   246             // TODO: Warn user, disconnect
       
   247             qWarning() << "Server too old";
       
   248         }
       
   249 
       
   250         RawSendNet(QString("NICK%1%2").arg(delimeter).arg(mynick));
       
   251         RawSendNet(QString("PROTO%1%2").arg(delimeter).arg(*cProtoVer));
       
   252         netClientState = Connected;
       
   253         m_game_connected = true;
       
   254         emit adminAccess(false);
       
   255         return;
       
   256     }
       
   257 
       
   258     if (lst[0] == "PING") {
       
   259         if (lst.size() > 1)
       
   260             RawSendNet(QString("PONG%1%2").arg(delimeter).arg(lst[1]));
       
   261         else
       
   262             RawSendNet(QString("PONG"));
       
   263         return;
       
   264     }
       
   265 
       
   266     if (lst[0] == "ROOMS") {
       
   267         QStringList tmp = lst;
       
   268         tmp.removeFirst();
       
   269         emit roomsList(tmp);
       
   270         return;
       
   271     }
       
   272 
       
   273     if (lst[0] == "SERVER_MESSAGE") {
       
   274         if(lst.size() < 2)
       
   275         {
       
   276             qWarning("Net: Empty SERVERMESSAGE message");
       
   277             return;
       
   278         }
       
   279         emit serverMessage(lst[1]);
       
   280         return;
       
   281     }
       
   282 
       
   283     if (lst[0] == "CHAT") {
       
   284         if(lst.size() < 3)
       
   285         {
       
   286             qWarning("Net: Empty CHAT message");
       
   287             return;
       
   288         }
       
   289         if (netClientState == InLobby)
       
   290             emit chatStringLobby(lst[1], HWProto::formatChatMsgForFrontend(lst[2]));
       
   291         else
       
   292             emit chatStringFromNet(HWProto::formatChatMsg(lst[1], lst[2]));
       
   293         return;
       
   294     }
       
   295 
       
   296     if (lst[0] == "INFO") {
       
   297         if(lst.size() < 5)
       
   298         {
       
   299             qWarning("Net: Malformed INFO message");
       
   300             return;
       
   301         }
       
   302         QStringList tmp = lst;
       
   303         tmp.removeFirst();
       
   304         if (netClientState == InLobby)
       
   305             emit chatStringLobby(tmp.join("\n").prepend('\x01'));
       
   306         else
       
   307             emit chatStringFromNet(tmp.join("\n").prepend('\x01'));
       
   308         return;
       
   309     }
       
   310 
       
   311     if (lst[0] == "SERVER_VARS") {
       
   312         QStringList tmp = lst;
       
   313         tmp.removeFirst();
       
   314         while (tmp.size() >= 2)
       
   315         {
       
   316             if(tmp[0] == "MOTD_NEW") emit serverMessageNew(tmp[1]);
       
   317             else if(tmp[0] == "MOTD_OLD") emit serverMessageOld(tmp[1]);
       
   318             else if(tmp[0] == "LATEST_PROTO") emit latestProtocolVar(tmp[1].toInt());
       
   319 
       
   320             tmp.removeFirst();
       
   321             tmp.removeFirst();
       
   322         }
       
   323         return;
       
   324     }
       
   325 
       
   326     if (lst[0] == "CLIENT_FLAGS")
       
   327     {
       
   328         if(lst.size() < 3 || lst[1].size() < 2)
       
   329         {
       
   330             qWarning("Net: Malformed CLIENT_FLAGS message");
       
   331             return;
       
   332         }
       
   333 
       
   334         QString flags = lst[1];
       
   335         bool setFlag = flags[0] == '+';
       
   336 
       
   337         while(flags.size() > 1)
       
   338         {
       
   339             flags.remove(0, 1);
       
   340             char c = flags[0].toAscii();
       
   341 
       
   342             switch(c)
       
   343             {
       
   344             case 'r':
       
   345                 {
       
   346                     for(int i = 2; i < lst.size(); ++i)
       
   347                     {
       
   348                         if (lst[i] == mynick)
       
   349                             emit setMyReadyStatus(setFlag);
       
   350                         emit setReadyStatus(lst[i], setFlag);
       
   351                     }
       
   352                 }
       
   353             }
       
   354         }
       
   355 
       
   356         return;
       
   357     }
       
   358 
       
   359     if (lst[0] == "ADD_TEAM") {
       
   360         if(lst.size() != 24)
       
   361         {
       
   362             qWarning("Net: Bad ADDTEAM message");
       
   363             return;
       
   364         }
       
   365         QStringList tmp = lst;
       
   366         tmp.removeFirst();
       
   367         emit AddNetTeam(tmp);
       
   368         return;
       
   369     }
       
   370 
       
   371     if (lst[0] == "REMOVE_TEAM") {
       
   372         if(lst.size() != 2)
       
   373         {
       
   374             qWarning("Net: Bad REMOVETEAM message");
       
   375             return;
       
   376         }
       
   377         emit RemoveNetTeam(HWTeam(lst[1]));
       
   378         return;
       
   379     }
       
   380 
       
   381     if(lst[0] == "ROOMABANDONED") {
       
   382         netClientState = InLobby;
       
   383         emit LeftRoom(tr("Room destroyed"));
       
   384         return;
       
   385     }
       
   386 
       
   387     if(lst[0] == "KICKED") {
       
   388         netClientState = InLobby;
       
   389         emit LeftRoom(tr("You got kicked"));
       
   390         return;
       
   391     }
       
   392 
       
   393     if(lst[0] == "JOINED") {
       
   394         if(lst.size() < 2)
       
   395         {
       
   396             qWarning("Net: Bad JOINED message");
       
   397             return;
       
   398         }
       
   399 
       
   400         for(int i = 1; i < lst.size(); ++i)
       
   401         {
       
   402             if (lst[i] == mynick)
       
   403             {
       
   404                 netClientState = InRoom;
       
   405                 emit EnteredGame();
       
   406                 emit roomMaster(isChief);
       
   407                 if (isChief)
       
   408                     emit configAsked();
       
   409             }
       
   410 
       
   411             emit nickAdded(lst[i], isChief && (lst[i] != mynick));
       
   412             emit chatStringFromNet(tr("%1 *** %2 has joined the room").arg('\x03').arg(lst[i]));
       
   413         }
       
   414         return;
       
   415     }
       
   416 
       
   417     if(lst[0] == "LOBBY:JOINED") {
       
   418         if(lst.size() < 2)
       
   419         {
       
   420             qWarning("Net: Bad JOINED message");
       
   421             return;
       
   422         }
       
   423 
       
   424         for(int i = 1; i < lst.size(); ++i)
       
   425         {
       
   426             if (lst[i] == mynick)
       
   427             {
       
   428                 netClientState = InLobby;
       
   429                 RawSendNet(QString("LIST"));
       
   430                 emit connected();
       
   431             }
       
   432 
       
   433             emit nickAddedLobby(lst[i], false);
       
   434             emit chatStringLobby(lst[i], tr("%1 *** %2 has joined").arg('\x03').arg("|nick|"));
       
   435         }
       
   436         return;
       
   437     }
       
   438 
       
   439     if(lst[0] == "LEFT") {
       
   440         if(lst.size() < 2)
       
   441         {
       
   442             qWarning("Net: Bad LEFT message");
       
   443             return;
       
   444         }
       
   445         emit nickRemoved(lst[1]);
       
   446         if (lst.size() < 3)
       
   447             emit chatStringFromNet(tr("%1 *** %2 has left").arg('\x03').arg(lst[1]));
       
   448         else
       
   449             emit chatStringFromNet(tr("%1 *** %2 has left (%3)").arg('\x03').arg(lst[1], lst[2]));
       
   450         return;
       
   451     }
       
   452 
       
   453     if(lst[0] == "ROOM") {
       
   454         if(lst.size() < 2)
       
   455         {
       
   456             qWarning("Net: Bad ROOM message");
       
   457             return;
       
   458         }
       
   459         RawSendNet(QString("LIST"));
       
   460         return;
       
   461     }
       
   462 
       
   463     if(lst[0] == "LOBBY:LEFT") {
       
   464         if(lst.size() < 2)
       
   465         {
       
   466             qWarning("Net: Bad LOBBY:LEFT message");
       
   467             return;
       
   468         }
       
   469         emit nickRemovedLobby(lst[1]);
       
   470         if (lst.size() < 3)
       
   471             emit chatStringLobby(tr("%1 *** %2 has left").arg('\x03').arg(lst[1]));
       
   472         else
       
   473             emit chatStringLobby(tr("%1 *** %2 has left (%3)").arg('\x03').arg(lst[1], lst[2]));
       
   474         return;
       
   475     }
       
   476 
       
   477     if (lst[0] == "RUN_GAME") {
       
   478         netClientState = InGame;
       
   479         emit AskForRunGame();
       
   480         return;
       
   481     }
       
   482 
       
   483     if (lst[0] == "ASKPASSWORD") {
       
   484         emit AskForPassword(mynick);
       
   485         return;
       
   486     }
       
   487 
       
   488     if (lst[0] == "NOTICE") {
       
   489         if(lst.size() < 2)
       
   490         {
       
   491             qWarning("Net: Bad NOTICE message");
       
   492             return;
       
   493         }
       
   494 
       
   495         bool ok;
       
   496         int n = lst[1].toInt(&ok);
       
   497         if(!ok)
       
   498         {
       
   499             qWarning("Net: Bad NOTICE message");
       
   500             return;
       
   501         }
       
   502 
       
   503         handleNotice(n);
       
   504 
       
   505         return;
       
   506     }
       
   507 
       
   508     if (lst[0] == "TEAM_ACCEPTED") {
       
   509         if (lst.size() != 2)
       
   510         {
       
   511             qWarning("Net: Bad TEAM_ACCEPTED message");
       
   512             return;
       
   513         }
       
   514         emit TeamAccepted(lst[1]);
       
   515         return;
       
   516     }
       
   517 
       
   518 
       
   519     if (lst[0] == "CFG") {
       
   520         if(lst.size() < 3)
       
   521         {
       
   522             qWarning("Net: Bad CFG message");
       
   523             return;
       
   524         }
       
   525         QStringList tmp = lst;
       
   526         tmp.removeFirst();
       
   527         tmp.removeFirst();
       
   528         if (lst[1] == "SCHEME")
       
   529             emit netSchemeConfig(tmp);
       
   530         else
       
   531             emit paramChanged(lst[1], tmp);
       
   532         return;
       
   533     }
       
   534 
       
   535     if (lst[0] == "HH_NUM") {
       
   536         if (lst.size() != 3)
       
   537         {
       
   538             qWarning("Net: Bad TEAM_ACCEPTED message");
       
   539             return;
       
   540         }
       
   541         HWTeam tmptm(lst[1]);
       
   542         tmptm.setNumHedgehogs(lst[2].toUInt());
       
   543         emit hhnumChanged(tmptm);
       
   544         return;
       
   545     }
       
   546 
       
   547     if (lst[0] == "TEAM_COLOR") {
       
   548         if (lst.size() != 3)
       
   549         {
       
   550             qWarning("Net: Bad TEAM_COLOR message");
       
   551             return;
       
   552         }
       
   553         HWTeam tmptm(lst[1]);
       
   554         tmptm.setColor(QColor(lst[2]));
       
   555         emit teamColorChanged(tmptm);
       
   556         return;
       
   557     }
       
   558 
       
   559     if (lst[0] == "EM") {
       
   560         if(lst.size() < 2)
       
   561         {
       
   562             qWarning("Net: Bad EM message");
       
   563             return;
       
   564         }
       
   565         for(int i = 1; i < lst.size(); ++i)
       
   566         {
       
   567             QByteArray em = QByteArray::fromBase64(lst[i].toAscii());
       
   568             emit FromNet(em);
       
   569         }
       
   570         return;
       
   571     }
       
   572 
       
   573     if (lst[0] == "BYE") {
       
   574         if (lst.size() < 2)
       
   575         {
       
   576             qWarning("Net: Bad BYE message");
       
   577             return;
       
   578         }
       
   579         if (lst[1] == "Authentication failed")
       
   580         {
       
   581             emit AuthFailed();
       
   582         }
       
   583         m_game_connected = false;
       
   584         Disconnect();
       
   585         emit disconnected(lst[1]);
       
   586         return;
       
   587     }
       
   588 
       
   589 
       
   590     if (lst[0] == "ADMIN_ACCESS") {
       
   591         emit adminAccess(true);
       
   592         return;
       
   593     }
       
   594 
       
   595     if (lst[0] == "ROOM_CONTROL_ACCESS") {
       
   596         if (lst.size() < 2)
       
   597         {
       
   598             qWarning("Net: Bad ROOM_CONTROL_ACCESS message");
       
   599             return;
       
   600         }
       
   601         isChief = (lst[1] != "0");
       
   602         emit roomMaster(isChief);
       
   603         return;
       
   604     }
       
   605 
       
   606     qWarning() << "Net: Unknown message:" << lst;
       
   607 }
       
   608 
       
   609 void HWNewNet::onHedgehogsNumChanged(const HWTeam& team)
       
   610 {
       
   611     if (isChief)
       
   612     RawSendNet(QString("HH_NUM%1%2%1%3")
       
   613             .arg(delimeter)
       
   614             .arg(team.name())
       
   615             .arg(team.numHedgehogs()));
       
   616 }
       
   617 
       
   618 void HWNewNet::onTeamColorChanged(const HWTeam& team)
       
   619 {
       
   620     if (isChief)
       
   621     RawSendNet(QString("TEAM_COLOR%1%2%1%3")
       
   622             .arg(delimeter)
       
   623             .arg(team.name())
       
   624             .arg(team.color().name()));
       
   625 }
       
   626 
       
   627 void HWNewNet::onParamChanged(const QString & param, const QStringList & value)
       
   628 {
       
   629     if (isChief)
       
   630         RawSendNet(
       
   631                 QString("CFG%1%2%1%3")
       
   632                     .arg(delimeter)
       
   633                     .arg(param)
       
   634                     .arg(value.join(QString(delimeter)))
       
   635                 );
       
   636 }
       
   637 
       
   638 void HWNewNet::chatLineToNet(const QString& str)
       
   639 {
       
   640     if(str != "") {
       
   641         RawSendNet(QString("CHAT") + delimeter + str);
       
   642         emit(chatStringFromMe(HWProto::formatChatMsg(mynick, str)));
       
   643     }
       
   644 }
       
   645 
       
   646 void HWNewNet::chatLineToLobby(const QString& str)
       
   647 {
       
   648     if(str != "") {
       
   649         RawSendNet(QString("CHAT") + delimeter + str);
       
   650         emit(chatStringFromMeLobby(HWProto::formatChatMsg(mynick, str)));
       
   651     }
       
   652 }
       
   653 
       
   654 void HWNewNet::SendTeamMessage(const QString& str)
       
   655 {
       
   656     RawSendNet(QString("TEAMCHAT") + delimeter + str);
       
   657 }
       
   658 
       
   659 void HWNewNet::askRoomsList()
       
   660 {
       
   661     if(netClientState != InLobby)
       
   662     {
       
   663         qWarning("Illegal try to get rooms list!");
       
   664         return;
       
   665     }
       
   666     RawSendNet(QString("LIST"));
       
   667 }
       
   668 
       
   669 HWNewNet::ClientState HWNewNet::clientState()
       
   670 {
       
   671     return netClientState;
       
   672 }
       
   673 
       
   674 QString HWNewNet::getNick()
       
   675 {
       
   676     return mynick;
       
   677 }
       
   678 
       
   679 QString HWNewNet::getRoom()
       
   680 {
       
   681     return myroom;
       
   682 }
       
   683 
       
   684 QString HWNewNet::getHost()
       
   685 {
       
   686     return myhost;
       
   687 }
       
   688 
       
   689 bool HWNewNet::isRoomChief()
       
   690 {
       
   691     return isChief;
       
   692 }
       
   693 
       
   694 void HWNewNet::gameFinished(bool correctly)
       
   695 {
       
   696     if (netClientState == InGame) netClientState = InRoom;
       
   697     RawSendNet(QString("ROUNDFINISHED%1%2").arg(delimeter).arg(correctly ? "1" : "0"));
       
   698 }
       
   699 
       
   700 void HWNewNet::banPlayer(const QString & nick)
       
   701 {
       
   702     RawSendNet(QString("BAN%1%2").arg(delimeter).arg(nick));
       
   703 }
       
   704 
       
   705 void HWNewNet::kickPlayer(const QString & nick)
       
   706 {
       
   707     RawSendNet(QString("KICK%1%2").arg(delimeter).arg(nick));
       
   708 }
       
   709 
       
   710 void HWNewNet::infoPlayer(const QString & nick)
       
   711 {
       
   712     RawSendNet(QString("INFO%1%2").arg(delimeter).arg(nick));
       
   713 }
       
   714 
       
   715 void HWNewNet::followPlayer(const QString & nick)
       
   716 {
       
   717     if (!isInRoom()) {
       
   718         RawSendNet(QString("FOLLOW%1%2").arg(delimeter).arg(nick));
       
   719         isChief = false;
       
   720     }
       
   721 }
       
   722 
       
   723 void HWNewNet::startGame()
       
   724 {
       
   725     RawSendNet(QString("START_GAME"));
       
   726 }
       
   727 
       
   728 void HWNewNet::updateRoomName(const QString & name)
       
   729 {
       
   730     RawSendNet(QString("ROOM_NAME%1%2").arg(delimeter).arg(name));
       
   731 }
       
   732 
       
   733 
       
   734 void HWNewNet::toggleRestrictJoins()
       
   735 {
       
   736     RawSendNet(QString("TOGGLE_RESTRICT_JOINS"));
       
   737 }
       
   738 
       
   739 void HWNewNet::toggleRestrictTeamAdds()
       
   740 {
       
   741     RawSendNet(QString("TOGGLE_RESTRICT_TEAMS"));
       
   742 }
       
   743 
       
   744 void HWNewNet::clearAccountsCache()
       
   745 {
       
   746     RawSendNet(QString("CLEAR_ACCOUNTS_CACHE"));
       
   747 }
       
   748 
       
   749 void HWNewNet::partRoom()
       
   750 {
       
   751     netClientState = InLobby;
       
   752     RawSendNet(QString("PART"));
       
   753 }
       
   754 
       
   755 bool HWNewNet::isInRoom()
       
   756 {
       
   757     return netClientState >= InRoom;
       
   758 }
       
   759 
       
   760 void HWNewNet::setServerMessageNew(const QString & msg)
       
   761 {
       
   762     RawSendNet(QString("SET_SERVER_VAR%1MOTD_NEW%1%2").arg(delimeter).arg(msg));
       
   763 }
       
   764 
       
   765 void HWNewNet::setServerMessageOld(const QString & msg)
       
   766 {
       
   767     RawSendNet(QString("SET_SERVER_VAR%1MOTD_OLD%1%2").arg(delimeter).arg(msg));
       
   768 }
       
   769 
       
   770 void HWNewNet::setLatestProtocolVar(int proto)
       
   771 {
       
   772     RawSendNet(QString("SET_SERVER_VAR%1LATEST_PROTO%1%2").arg(delimeter).arg(proto));
       
   773 }
       
   774 
       
   775 void HWNewNet::askServerVars()
       
   776 {
       
   777     RawSendNet(QString("GET_SERVER_VAR"));
       
   778 }
       
   779 
       
   780 void HWNewNet::handleNotice(int n)
       
   781 {
       
   782     switch(n)
       
   783     {
       
   784         case 0:
       
   785         {
       
   786             emit NickTaken(mynick);
       
   787             break;
       
   788         }
       
   789     }
       
   790 }