1.1 --- a/mapeditor.cpp Wed Jun 20 11:58:47 2007 +0000
1.2 +++ b/mapeditor.cpp Thu Jun 21 14:27:46 2007 +0000
1.3 @@ -4041,10 +4041,25 @@
1.4 }
1.5 }
1.6
1.7 -void MapEditor::testFunction()
1.8 +void MapEditor::testFunction1()
1.9 {
1.10 +
1.11 + tcpServer = new QTcpServer(this);
1.12 + if (!tcpServer->listen(QHostAddress::Any,54321)) {
1.13 + QMessageBox::critical(this, tr("Fortune Server"),
1.14 + tr("Unable to start the server: %1.")
1.15 + .arg(tcpServer->errorString()));
1.16 + close();
1.17 + return;
1.18 + }
1.19 + connect(tcpServer, SIGNAL(newConnection()), this, SLOT(newClient()));
1.20 + if (debug)
1.21 + cout<<"Server is running on port "<<tcpServer->serverPort()<<endl;
1.22 +
1.23 +/*
1.24 BranchObj *bo=xelection.getBranch();
1.25 if (bo) animObjList.append( bo );
1.26 +*/
1.27
1.28 /*
1.29 WarningDialog dia;
1.30 @@ -4084,6 +4099,23 @@
1.31 }
1.32 cout <<" hidemode="<<hidemode<<endl;
1.33 */
1.34 +}
1.35 +
1.36 +void MapEditor::testFunction2()
1.37 +{
1.38 + QByteArray block;
1.39 + QDataStream out(&block, QIODevice::WriteOnly);
1.40 + out.setVersion(QDataStream::Qt_4_0);
1.41 + out << (quint16)0;
1.42 + out << xelection.getSelectString();
1.43 + out.device()->seek(0);
1.44 + out << (quint16)(block.size() - sizeof(quint16));
1.45 +
1.46 + for (int i=0; i<clientList.size(); ++i)
1.47 + {
1.48 + cout << "Sending to "<<clientList.at(i)->peerAddress().toString().ascii()<<endl;
1.49 + clientList.at(i)->write (block);
1.50 + }
1.51 }
1.52
1.53 void MapEditor::contextMenuEvent ( QContextMenuEvent * e )
1.54 @@ -4735,6 +4767,27 @@
1.55 mainWindow->fileSave (this);
1.56 }
1.57
1.58 +void MapEditor::newClient()
1.59 +{
1.60 + QByteArray block;
1.61 + QDataStream out(&block, QIODevice::WriteOnly);
1.62 + out.setVersion(QDataStream::Qt_4_0);
1.63 + out << (quint16)0;
1.64 + out << xelection.getSelectString();
1.65 + out.device()->seek(0);
1.66 + out << (quint16)(block.size() - sizeof(quint16));
1.67 +
1.68 + QTcpSocket *newClient = tcpServer->nextPendingConnection();
1.69 + connect(newClient, SIGNAL(disconnected()),
1.70 + newClient, SLOT(deleteLater()));
1.71 +
1.72 + cout <<"ME::newClient at "<<newClient->peerAddress().toString().ascii()<<endl;
1.73 +
1.74 + clientList.append (newClient);
1.75 +
1.76 + newClient->write(block);
1.77 + //newClient->disconnectFromHost();
1.78 +}
1.79
1.80 /*TODO not needed? void MapEditor::contentsDropEvent(QDropEvent *event)
1.81 {