QTfrontend/netconnectedclient.cpp
changeset 574 1cafd9eb1a21
parent 573 e0cf483e68d6
child 746 980240306370
equal deleted inserted replaced
573:e0cf483e68d6 574:1cafd9eb1a21
     1 /*
     1 /*
     2  * Hedgewars, a worms-like game
     2  * Hedgewars, a worms-like game
     3  * Copyright (c) 2006 Igor Ulyanov <iulyanov@gmail.com>
     3  * Copyright (c) 2006-2007 Igor Ulyanov <iulyanov@gmail.com>
     4  *
     4  *
     5  * This program is free software; you can redistribute it and/or modify
     5  * This program is free software; you can redistribute it and/or modify
     6  * it under the terms of the GNU General Public License as published by
     6  * it under the terms of the GNU General Public License as published by
     7  * the Free Software Foundation; version 2 of the License
     7  * the Free Software Foundation; version 2 of the License
     8  *
     8  *
    58 {
    58 {
    59   QString msg = QString::fromUtf8 (line.data(), line.size());
    59   QString msg = QString::fromUtf8 (line.data(), line.size());
    60   QStringList lst = msg.split(delimeter);
    60   QStringList lst = msg.split(delimeter);
    61   if(!lst.size())
    61   if(!lst.size())
    62   {
    62   {
    63     qWarning("Net: Bad message");
    63     qWarning("Net server: Bad message");
    64     return;
    64     return;
    65   }
    65   }
    66   if (lst[0] == "NICK") {
    66   if (lst[0] == "NICK") {
    67     if(lst.size() < 2)
    67     if(lst.size() < 2)
    68     {
    68     {
    69       qWarning("Net: Bad 'NICK' message");
    69       qWarning("Net server: Bad 'NICK' message");
    70 	  return;
    70 	  return;
    71     }
    71     }
    72     if(m_hwserver->haveNick(lst[1])) {
    72     if(m_hwserver->haveNick(lst[1])) {
    73       RawSendNet(QString("ERRONEUSNICKNAME"));
    73       RawSendNet(QString("ERRONEUSNICKNAME"));
    74       throw ShouldDisconnectException();
    74       throw ShouldDisconnectException();
    97     return;
    97     return;
    98   }
    98   }
    99 
    99 
   100   if(client_nick=="")
   100   if(client_nick=="")
   101   {
   101   {
   102   	qWarning(QString("Net: Message from unnamed client: '%1'").arg(msg).toAscii().data());
   102   	qWarning(QString("Net server: Message from unnamed client: '%1'").arg(msg).toAscii().data());
   103   	return;
   103   	return;
   104   }
   104   }
   105 
   105 
   106   if (lst[0]=="START:") {
   106   if (lst[0]=="START:") {
   107     readyToStart=true;
   107     readyToStart=true;
   113     return;
   113     return;
   114   }
   114   }
   115 
   115 
   116   if(lst[0]=="HHNUM") {
   116   if(lst[0]=="HHNUM") {
   117     if (lst.size()<4) {
   117     if (lst.size()<4) {
   118       qWarning((QString("Net: Bad 'HHNUM' message: ")+msg+" size="+QString("%1").arg(lst.size())).toAscii().data());
   118       qWarning((QString("Net server: Bad 'HHNUM' message: ")+msg+" size="+QString("%1").arg(lst.size())).toAscii().data());
   119       return;
   119       return;
   120     }
   120     }
   121     if(!m_hwserver->isChiefClient(this))
   121     if(!m_hwserver->isChiefClient(this))
   122     {
   122     {
   123       return; // permission denied
   123       return; // permission denied
   133     return;
   133     return;
   134   }
   134   }
   135 
   135 
   136   if(lst[0]=="CONFIG_PARAM") {
   136   if(lst[0]=="CONFIG_PARAM") {
   137     if (lst.size()<3) {
   137     if (lst.size()<3) {
   138       qWarning((QString("Net: Bad 'CONFIG_PARAM' message: ")+msg).toAscii().data());
   138       qWarning((QString("Net server: Bad 'CONFIG_PARAM' message: ")+msg).toAscii().data());
   139       return;
   139       return;
   140     }
   140     }
   141 
   141 
   142     if(!m_hwserver->isChiefClient(this))
   142     if(!m_hwserver->isChiefClient(this))
   143     {
   143     {
   147   }
   147   }
   148 
   148 
   149   if(lst[0]=="ADDTEAM:") {
   149   if(lst[0]=="ADDTEAM:") {
   150     if(lst.size() < 14)
   150     if(lst.size() < 14)
   151     {
   151     {
   152       qWarning("Net: Bad 'ADDTEAM' message");
   152       qWarning("Net server: Bad 'ADDTEAM' message");
   153 	  return;
   153 	  return;
   154     }
   154     }
   155     lst.pop_front();
   155     lst.pop_front();
   156 
   156 
   157     // add team ID
   157     // add team ID
   160 
   160 
   161     // hedgehogs num count
   161     // hedgehogs num count
   162     int maxAdd=18-m_hwserver->hhnum;
   162     int maxAdd=18-m_hwserver->hhnum;
   163     if (maxAdd<=0)
   163     if (maxAdd<=0)
   164     {
   164     {
   165 	  qWarning("Net: 'ADDTEAM' message: rejecting");
   165 	  qWarning("Net server: 'ADDTEAM' message: rejecting");
   166 	  return; // reject command
   166 	  return; // reject command
   167     }
   167     }
   168     int toAdd=maxAdd<4 ? maxAdd : 4;
   168     int toAdd=maxAdd<4 ? maxAdd : 4;
   169     m_hwserver->hhnum+=toAdd;
   169     m_hwserver->hhnum+=toAdd;
   170     // hedgehogs num config
   170     // hedgehogs num config
   189   }
   189   }
   190 
   190 
   191   if(lst[0]=="REMOVETEAM:") {
   191   if(lst[0]=="REMOVETEAM:") {
   192     if(lst.size() < 2)
   192     if(lst.size() < 2)
   193     {
   193     {
   194       qWarning("Net: Bad 'REMOVETEAM' message");
   194       qWarning("Net server: Bad 'REMOVETEAM' message");
   195 	  return;
   195 	  return;
   196     }
   196     }
   197 
   197 
   198     for(QMap<QString, QStringList>::iterator it=m_hwserver->m_gameCfg.begin(); it!=m_hwserver->m_gameCfg.end(); ++it)
   198     for(QMap<QString, QStringList>::iterator it=m_hwserver->m_gameCfg.begin(); it!=m_hwserver->m_gameCfg.end(); ++it)
   199     {
   199     {