# HG changeset patch # User unc0rr # Date 1302889019 -14400 # Node ID 7b65e83e261d7c60732d7d5bcdc5a1450d782376 # Parent 120f4271f197870eec29ae70b94fb0e0add47b37 Send server's name in udp packet. Fixes issue #25 diff -r 120f4271f197 -r 7b65e83e261d QTfrontend/netudpserver.cpp --- a/QTfrontend/netudpserver.cpp Thu Apr 14 18:17:30 2011 -0400 +++ b/QTfrontend/netudpserver.cpp Fri Apr 15 21:36:59 2011 +0400 @@ -22,7 +22,8 @@ #include "netudpserver.h" HWNetUdpServer::HWNetUdpServer(QObject *parent, const QString & descr, quint16 port) : - HWNetRegisterServer(parent, descr, port) + HWNetRegisterServer(parent, descr, port), + m_descr(descr) { pUdpSocket = new QUdpSocket(this); pUdpSocket->bind(46631); @@ -37,9 +38,9 @@ QHostAddress clientAddr; quint16 clientPort; pUdpSocket->readDatagram(datagram.data(), datagram.size(), &clientAddr, &clientPort); - if(QString("%1").arg(datagram.data())==QString("hedgewars client")) { + if(datagram.startsWith("hedgewars client")) { // send answer to client - pUdpSocket->writeDatagram("hedgewars server", clientAddr, clientPort); + pUdpSocket->writeDatagram(QString("hedgewars server\n%1").arg(m_descr).toUtf8(), clientAddr, clientPort); } } } diff -r 120f4271f197 -r 7b65e83e261d QTfrontend/netudpserver.h --- a/QTfrontend/netudpserver.h Thu Apr 14 18:17:30 2011 -0400 +++ b/QTfrontend/netudpserver.h Fri Apr 15 21:36:59 2011 +0400 @@ -40,6 +40,7 @@ private: QUdpSocket* pUdpSocket; + QString m_descr; }; #endif // _NET_UDPSERVER_INCLUDED diff -r 120f4271f197 -r 7b65e83e261d QTfrontend/netudpwidget.cpp --- a/QTfrontend/netudpwidget.cpp Thu Apr 14 18:17:30 2011 -0400 +++ b/QTfrontend/netudpwidget.cpp Fri Apr 15 21:36:59 2011 +0400 @@ -37,6 +37,7 @@ reset(); pUdpSocket->writeDatagram("hedgewars client", QHostAddress::Broadcast, 46631); + pUdpSocket->writeDatagram("hedgewars client", QHostAddress("127.0.0.1"), 46631); } void HWNetUdpModel::onClientRead() @@ -49,9 +50,10 @@ pUdpSocket->readDatagram(datagram.data(), datagram.size(), &clientAddr, &clientPort); - if(QString("%1").arg(datagram.data())==QString("hedgewars server")) { + QString packet = QString::fromUtf8(datagram.data()); + if(packet.startsWith("hedgewars server")) { QStringList sl; - sl << "-" << clientAddr.toString() << "46631"; + sl << packet.remove(0, 17) << clientAddr.toString() << "46631"; games.append(sl); } }