QTfrontend/netserver.cpp
changeset 326 c6718bfdd642
parent 319 7f3bd9e31f18
child 332 10080f681118
equal deleted inserted replaced
325:17c860483407 326:c6718bfdd642
    36   if (!IPCServer->listen(QHostAddress::LocalHost, ds_port)) {
    36   if (!IPCServer->listen(QHostAddress::LocalHost, ds_port)) {
    37     QMessageBox::critical(0, tr("Error"),
    37     QMessageBox::critical(0, tr("Error"),
    38 			  tr("Unable to start the server: %1.")
    38 			  tr("Unable to start the server: %1.")
    39 			  .arg(IPCServer->errorString()));
    39 			  .arg(IPCServer->errorString()));
    40   }
    40   }
    41   
    41 
    42   connect(IPCServer, SIGNAL(newConnection()), this, SLOT(NewConnection()));
    42   connect(IPCServer, SIGNAL(newConnection()), this, SLOT(NewConnection()));
    43 }
    43 }
    44 
    44 
    45 void HWNetServer::StopServer()
    45 void HWNetServer::StopServer()
    46 {
    46 {
    50 void HWNetServer::NewConnection()
    50 void HWNetServer::NewConnection()
    51 {
    51 {
    52   QTcpSocket* client = IPCServer->nextPendingConnection();
    52   QTcpSocket* client = IPCServer->nextPendingConnection();
    53   if(!client) return;
    53   if(!client) return;
    54   connclients.push_back(new HWConnectedClient(this, client));
    54   connclients.push_back(new HWConnectedClient(this, client));
    55   connect(connclients.back(), SIGNAL(HWClientDisconnected(HWConnectedClient*)), 
    55   connect(connclients.back(), SIGNAL(HWClientDisconnected(HWConnectedClient*)),
    56 	  this, SLOT(ClientDisconnect(HWConnectedClient*)));
    56 	  this, SLOT(ClientDisconnect(HWConnectedClient*)));
    57 }
    57 }
    58 
    58 
    59 void HWNetServer::ClientDisconnect(HWConnectedClient* client)
    59 void HWNetServer::ClientDisconnect(HWConnectedClient* client)
    60 {
    60 {
    71 quint16 HWNetServer::getRunningPort() const
    71 quint16 HWNetServer::getRunningPort() const
    72 {
    72 {
    73   return ds_port;
    73   return ds_port;
    74 }
    74 }
    75 
    75 
    76 bool HWNetServer::isCheefClient(HWConnectedClient* cl) const
    76 bool HWNetServer::isChiefClient(HWConnectedClient* cl) const
    77 {
    77 {
    78   for(QList<HWConnectedClient*>::const_iterator it=connclients.begin(); it!=connclients.end(); ++it) {
    78   for(QList<HWConnectedClient*>::const_iterator it=connclients.begin(); it!=connclients.end(); ++it) {
    79     if((*it)->getClientNick()!="" && *it==cl)  return true;
    79     if((*it)->getClientNick()!="" && *it==cl)  return true;
    80   }
    80   }
    81   return false;
    81   return false;
   194 
   194 
   195     client_nick=lst[1];
   195     client_nick=lst[1];
   196     qDebug() << "send connected";
   196     qDebug() << "send connected";
   197     RawSendNet(QString("CONNECTED"));
   197     RawSendNet(QString("CONNECTED"));
   198     m_hwserver->teamChanged();
   198     m_hwserver->teamChanged();
   199     if(m_hwserver->isCheefClient(this)) RawSendNet(QString("CONFIGASKED"));
   199     if(m_hwserver->isChiefClient(this)) RawSendNet(QString("CONFIGASKED"));
   200     return;
   200     return;
   201   }
   201   }
   202   if(client_nick=="") return;
   202   if(client_nick=="") return;
   203 
   203 
   204   if (lst[0]=="START:") {
   204   if (lst[0]=="START:") {
   222     if(pclent_team) delete pclent_team;
   222     if(pclent_team) delete pclent_team;
   223     pclent_team=new HWTeam(lst);
   223     pclent_team=new HWTeam(lst);
   224     m_hwserver->teamChanged();
   224     m_hwserver->teamChanged();
   225     return;
   225     return;
   226   }
   226   }
   227   
   227 
   228   m_hwserver->sendOthers(this, msg);
   228   m_hwserver->sendOthers(this, msg);
   229 }
   229 }
   230 
   230 
   231 void HWConnectedClient::teamChangedNotify()
   231 void HWConnectedClient::teamChangedNotify()
   232 {
   232 {