QTfrontend/netwwwserver.cpp
changeset 659 5eafb20566f1
parent 635 0fb6d55ecd66
child 660 7c155e849602
equal deleted inserted replaced
658:a7e625f5d9d0 659:5eafb20566f1
    24 #include "hwconsts.h"
    24 #include "hwconsts.h"
    25 
    25 
    26 HWNetWwwServer::HWNetWwwServer(QObject *parent, const QString & descr, quint16 port) :
    26 HWNetWwwServer::HWNetWwwServer(QObject *parent, const QString & descr, quint16 port) :
    27   HWNetRegisterServer(parent, descr, port), timer(0)
    27   HWNetRegisterServer(parent, descr, port), timer(0)
    28 {
    28 {
       
    29 	destroyPosted = false;
       
    30 	destroyPostId = 0;
       
    31 
    29 	http = new QHttp(this);
    32 	http = new QHttp(this);
    30 	http->setHost("www.hedgewars.org", 80);
    33 	http->setHost("www.hedgewars.org", 80);
    31 	connect(http, SIGNAL(requestFinished(int, bool)), this, SLOT(onClientRead(int, bool)));
    34 	connect(http, SIGNAL(requestFinished(int, bool)), this, SLOT(onClientRead(int, bool)));
    32 
    35 
    33 	QString request = QString("game[title]=%1&game[port]=%2&game[password]=%3&game[protocol_version]=%4")
    36 	QString request = QString("game[title]=%1&game[port]=%2&game[password]=%3&game[protocol_version]=%4")
    38 	http->post("/games/create", request.toUtf8());
    41 	http->post("/games/create", request.toUtf8());
    39 }
    42 }
    40 
    43 
    41 void HWNetWwwServer::onClientRead(int id, bool error)
    44 void HWNetWwwServer::onClientRead(int id, bool error)
    42 {
    45 {
       
    46 	if (destroyPosted && (id == destroyPostId))
       
    47 	{
       
    48 		deleteLater();
       
    49 		return;
       
    50 	}
       
    51 
    43 	if (error)
    52 	if (error)
    44 	{
    53 	{
    45 		QMessageBox::critical(0,
    54 		QMessageBox::critical(0,
    46 				tr("Error"),
    55 				tr("Error"),
    47 				tr("Server registration error") + "\n" +
    56 				tr("Server registration error") + "\n" +
    78 void HWNetWwwServer::unregister()
    87 void HWNetWwwServer::unregister()
    79 {
    88 {
    80 	QString request = QString("id=%1&key=%2")
    89 	QString request = QString("id=%1&key=%2")
    81 			.arg(servid)
    90 			.arg(servid)
    82 			.arg(servkey);
    91 			.arg(servkey);
    83 	http->post("/games/destroy_game", request.toUtf8());
    92 	destroyPostId = http->post("/games/destroy_game", request.toUtf8());
       
    93 	destroyPosted = true;
    84 }
    94 }