QTfrontend/newnetclient.cpp
changeset 468 8403d6884707
parent 465 07eca0a2546c
child 486 7ea71cd3acd5
equal deleted inserted replaced
467:20d36f976b25 468:8403d6884707
    15  * along with this program; if not, write to the Free Software
    15  * along with this program; if not, write to the Free Software
    16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
    16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
    17  */
    17  */
    18 
    18 
    19 #include <QMessageBox>
    19 #include <QMessageBox>
    20 #include <QDebug>
       
    21 
    20 
    22 #include "newnetclient.h"
    21 #include "newnetclient.h"
    23 #include "proto.h"
    22 #include "proto.h"
    24 #include "gameuiconfig.h"
    23 #include "gameuiconfig.h"
    25 #include "game.h"
    24 #include "game.h"
    42 	  SLOT(displayError(QAbstractSocket::SocketError)));
    41 	  SLOT(displayError(QAbstractSocket::SocketError)));
    43 }
    42 }
    44 
    43 
    45 void HWNewNet::Connect(const QString & hostName, quint16 port, const QString & nick)
    44 void HWNewNet::Connect(const QString & hostName, quint16 port, const QString & nick)
    46 {
    45 {
    47   qDebug() << hostName << ":" << port;
       
    48   NetSocket.connectToHost(hostName, port);
    46   NetSocket.connectToHost(hostName, port);
    49   mynick = nick;
    47   mynick = nick;
    50 }
    48 }
    51 
    49 
    52 void HWNewNet::Disconnect()
    50 void HWNewNet::Disconnect()
   184     return;
   182     return;
   185   }
   183   }
   186 
   184 
   187   if(lst[0]=="JOINED") {
   185   if(lst[0]=="JOINED") {
   188     if(lst.size()<2) return;
   186     if(lst.size()<2) return;
   189     qDebug() << "JOINED" << lst[1];
       
   190     emit nickAdded(lst[1]);
   187     emit nickAdded(lst[1]);
   191     return;
   188     return;
   192   }
   189   }
   193 
   190 
   194   if(lst[0]=="LEFT") {
   191   if(lst[0]=="LEFT") {
   195     if(lst.size()<2) return;
   192     if(lst.size()<2) return;
   196     qDebug() << "LEFT" << lst[1];
       
   197     emit nickRemoved(lst[1]);
   193     emit nickRemoved(lst[1]);
   198     return;
   194     return;
   199   }
   195   }
   200 
   196 
   201   if (lst[0] == "CONFIGASKED") {
   197   if (lst[0] == "CONFIGASKED") {
   210   }
   206   }
   211 
   207 
   212   if (lst[0] == "CONFIGURED") {
   208   if (lst[0] == "CONFIGURED") {
   213     lst.pop_front();
   209     lst.pop_front();
   214     if(lst.size()<5) return;
   210     if(lst.size()<5) return;
   215     qDebug() << lst;
       
   216     emit seedChanged(lst[0]);
   211     emit seedChanged(lst[0]);
   217     emit mapChanged(lst[1]);
   212     emit mapChanged(lst[1]);
   218     emit themeChanged(lst[2]);
   213     emit themeChanged(lst[2]);
   219     emit initHealthChanged(lst[3].toUInt());
   214     emit initHealthChanged(lst[3].toUInt());
   220     emit turnTimeChanged(lst[4].toUInt());
   215     emit turnTimeChanged(lst[4].toUInt());
   221     emit fortsModeChanged(lst[5].toInt() != 0);
   216     emit fortsModeChanged(lst[5].toInt() != 0);
   222     return;
   217     return;
   223   }
   218   }
   224 
   219 
   225   if(lst[0]=="TEAM_ACCEPTED") {
   220   if(lst[0]=="TEAM_ACCEPTED") {
   226     qDebug() << "accepted " << lst[2].toUInt() << " team";
       
   227     m_networkToLocalteams.insert(lst[2].toUInt(), lst[1]);
   221     m_networkToLocalteams.insert(lst[2].toUInt(), lst[1]);
   228     m_pTeamSelWidget->changeTeamStatus(lst[1]);
   222     m_pTeamSelWidget->changeTeamStatus(lst[1]);
   229     return;
   223     return;
   230   }
   224   }
   231 
   225 
   271 	  }
   265 	  }
   272 	  tmptm.numHedgehogs=lst[2].toUInt();
   266 	  tmptm.numHedgehogs=lst[2].toUInt();
   273 	  emit hhnumChanged(tmptm);
   267 	  emit hhnumChanged(tmptm);
   274 	  return;
   268 	  return;
   275   	}
   269   	}
   276   	qDebug() << "unknow config param: " << lst[1];
       
   277     return;
   270     return;
   278   }
   271   }
   279 
   272 
   280 
   273 
   281   // should be kinda game states, which don't allow "GAMEMSG:" at configure step,
   274   // should be kinda game states, which don't allow "GAMEMSG:" at configure step,
   283   if (lst[0] == "GAMEMSG:") {
   276   if (lst[0] == "GAMEMSG:") {
   284     QByteArray em = QByteArray::fromBase64(lst[1].toAscii());
   277     QByteArray em = QByteArray::fromBase64(lst[1].toAscii());
   285     emit FromNet(em);
   278     emit FromNet(em);
   286     return;
   279     return;
   287   }
   280   }
   288 
       
   289   qDebug() << "unknown net command: " << msg;
       
   290 
       
   291 }
   281 }
   292 
   282 
   293 
   283 
   294 void HWNewNet::ConfigAsked()
   284 void HWNewNet::ConfigAsked()
   295 {
   285 {
   305 {
   295 {
   306   HWGame* game = new HWGame(config, m_pGameCFGWidget, m_pTeamSelWidget);
   296   HWGame* game = new HWGame(config, m_pGameCFGWidget, m_pTeamSelWidget);
   307   connect(game, SIGNAL(GameStateChanged(GameState)), this, SIGNAL(GameStateChanged(GameState)));
   297   connect(game, SIGNAL(GameStateChanged(GameState)), this, SIGNAL(GameStateChanged(GameState)));
   308   connect(game, SIGNAL(SendNet(const QByteArray &)), this, SLOT(SendNet(const QByteArray &)));
   298   connect(game, SIGNAL(SendNet(const QByteArray &)), this, SLOT(SendNet(const QByteArray &)));
   309   connect(this, SIGNAL(FromNet(const QByteArray &)), game, SLOT(FromNet(const QByteArray &)));
   299   connect(this, SIGNAL(FromNet(const QByteArray &)), game, SLOT(FromNet(const QByteArray &)));
   310   connect(this, SIGNAL(LocalCFG(const QString &)), game, SLOT(LocalCFG(const QString &)));
       
   311   connect(game, SIGNAL(ErrorMessage(const QString &)), this, SLOT(ShowErrorMessage(const QString &)), Qt::QueuedConnection);
   300   connect(game, SIGNAL(ErrorMessage(const QString &)), this, SLOT(ShowErrorMessage(const QString &)), Qt::QueuedConnection);
   312   game->StartNet();
   301   game->StartNet();
   313 }
   302 }
   314 
   303 
   315 void HWNewNet::ShowErrorMessage(const QString & msg)
   304 void HWNewNet::ShowErrorMessage(const QString & msg)
   326 	     .arg(team.numHedgehogs));
   315 	     .arg(team.numHedgehogs));
   327 }
   316 }
   328 
   317 
   329 void HWNewNet::onTeamColorChanged(const HWTeam& team)
   318 void HWNewNet::onTeamColorChanged(const HWTeam& team)
   330 {
   319 {
   331   qDebug() << team.getNetID() << ":" << team.teamColor.name();
       
   332   RawSendNet(QString("CONFIG_PARAM%1TEAM_COLOR+%2+%3%1%4").arg(delimeter).arg(team.TeamName)\
   320   RawSendNet(QString("CONFIG_PARAM%1TEAM_COLOR+%2+%3%1%4").arg(delimeter).arg(team.TeamName)\
   333 	     .arg(team.getNetID() ? team.getNetID() : m_networkToLocalteams.key(team.TeamName))\
   321 	     .arg(team.getNetID() ? team.getNetID() : m_networkToLocalteams.key(team.TeamName))\
   334 	     .arg(team.teamColor.name()));
   322 	     .arg(team.teamColor.name()));
   335 }
   323 }
   336 
   324