diff options
author | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
---|---|---|
committer | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
commit | c90c389a8a8d9d8661e9772ec4144c5cf2039f23 (patch) | |
tree | 6d8391395bce9eaea4ad78958617edb20c6a7573 /atlantik/atlanticd | |
download | tdegames-c90c389a8a8d9d8661e9772ec4144c5cf2039f23.tar.gz tdegames-c90c389a8a8d9d8661e9772ec4144c5cf2039f23.zip |
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdegames@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'atlantik/atlanticd')
-rw-r--r-- | atlantik/atlanticd/Makefile.am | 10 | ||||
-rw-r--r-- | atlantik/atlanticd/README | 6 | ||||
-rw-r--r-- | atlantik/atlanticd/TODO | 11 | ||||
-rw-r--r-- | atlantik/atlanticd/atlanticclient.cpp | 49 | ||||
-rw-r--r-- | atlantik/atlanticd/atlanticclient.h | 36 | ||||
-rw-r--r-- | atlantik/atlanticd/atlanticdaemon.cpp | 72 | ||||
-rw-r--r-- | atlantik/atlanticd/atlanticdaemon.h | 48 | ||||
-rw-r--r-- | atlantik/atlanticd/main.cpp | 27 | ||||
-rw-r--r-- | atlantik/atlanticd/serversocket.cpp | 32 | ||||
-rw-r--r-- | atlantik/atlanticd/serversocket.h | 35 |
10 files changed, 326 insertions, 0 deletions
diff --git a/atlantik/atlanticd/Makefile.am b/atlantik/atlanticd/Makefile.am new file mode 100644 index 00000000..65e3475a --- /dev/null +++ b/atlantik/atlanticd/Makefile.am @@ -0,0 +1,10 @@ +KDE_OPTIONS = qtonly + +bin_PROGRAMS = atlanticd + +INCLUDES = -I$(top_srcdir)/atlantik/libatlantic $(QT_INCLUDES) +LDADD = ../libatlantic/libatlantic.la + +atlanticd_SOURCES = atlanticclient.cpp atlanticdaemon.cpp main.cpp serversocket.cpp + +METASOURCES = AUTO diff --git a/atlantik/atlanticd/README b/atlantik/atlanticd/README new file mode 100644 index 00000000..a0bf03b1 --- /dev/null +++ b/atlantik/atlanticd/README @@ -0,0 +1,6 @@ +The purpose of atlanticd is to provide a monopd-compatible server, for +inclusion with the Atlantik client. + +Eventually atlanticd will be full-featured and a capable monopd replacement, +but at this very moment it's still a prototype and not useful for actual +games. diff --git a/atlantik/atlanticd/TODO b/atlantik/atlanticd/TODO new file mode 100644 index 00000000..fb121b4e --- /dev/null +++ b/atlantik/atlanticd/TODO @@ -0,0 +1,11 @@ +This is a very basic TODO, only aimed at the most urgent goals and +requirements. A complete reference would be the existing functionality of +monopd. + +v create base class, AtlanticDaemon + v add monopigator method and timer + v create serversocket here + - let serversocket signal and atlanticd create client object + - create game object + - send list of games upon new connect + diff --git a/atlantik/atlanticd/atlanticclient.cpp b/atlantik/atlanticd/atlanticclient.cpp new file mode 100644 index 00000000..0445165d --- /dev/null +++ b/atlantik/atlanticd/atlanticclient.cpp @@ -0,0 +1,49 @@ +// Copyright (c) 2002 Rob Kaper <cap@capsi.com> +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// version 2 as published by the Free Software Foundation. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +// Boston, MA 02110-1301, USA. + +#include <qtextstream.h> +#include <qtimer.h> + +#include "atlanticclient.h" +#include "atlanticclient.moc" + +AtlanticClient::AtlanticClient(QObject *parent, const char *name) : QSocket(parent, name) +{ + connect(this, SIGNAL(readyRead()), this, SLOT(readData())); +} + +void AtlanticClient::sendData(const QString &data) +{ + writeBlock(data.latin1(), data.length()); +} + +void AtlanticClient::readData() +{ + if (canReadLine()) + { + emit clientInput(this, readLine()); + + // There might be more data + QTimer::singleShot(0, this, SLOT(readData())); + } + else + { + // Maximum message size. Messages won't get bigger than 32k anyway, so + // if we didn't receive a newline by now, we probably won't anyway. + if (bytesAvailable() > (1024 * 32)) + flush(); + } +} diff --git a/atlantik/atlanticd/atlanticclient.h b/atlantik/atlanticd/atlanticclient.h new file mode 100644 index 00000000..7b47b0f3 --- /dev/null +++ b/atlantik/atlanticd/atlanticclient.h @@ -0,0 +1,36 @@ +// Copyright (c) 2002-2003 Rob Kaper <cap@capsi.com> +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// version 2 as published by the Free Software Foundation. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +// Boston, MA 02110-1301, USA. + +#ifndef CLIENT_H +#define CLIENT_H + +#include <qsocket.h> + +class AtlanticClient : public QSocket +{ +Q_OBJECT + +public: + AtlanticClient(QObject *parent = 0, const char *name = 0); + void sendData(const QString &data); + +private slots: + void readData(); + +signals: + void clientInput(AtlanticClient *client, const QString &data); +}; +#endif diff --git a/atlantik/atlanticd/atlanticdaemon.cpp b/atlantik/atlanticd/atlanticdaemon.cpp new file mode 100644 index 00000000..3fb80cf0 --- /dev/null +++ b/atlantik/atlanticd/atlanticdaemon.cpp @@ -0,0 +1,72 @@ +// Copyright (c) 2002 Rob Kaper <cap@capsi.com> +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// version 2 as published by the Free Software Foundation. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +// Boston, MA 02110-1301, USA. + +#include <qtimer.h> +#include <qsocket.h> +#include <qstring.h> + +#include <atlantic_core.h> + +#include "atlanticclient.h" +#include "atlanticdaemon.h" +#include "atlanticdaemon.moc" +#include "serversocket.h" + +AtlanticDaemon::AtlanticDaemon() +{ + m_serverSocket = new ServerSocket(1234, 100); + connect(m_serverSocket, SIGNAL(newClient(AtlanticClient *)), this, SLOT(newClient(AtlanticClient *))); + + m_atlanticCore = new AtlanticCore(this, "atlanticCore"); + + // Create socket for Monopigator + m_monopigatorSocket = new QSocket(); + connect(m_monopigatorSocket, SIGNAL(connected()), this, SLOT(monopigatorConnected())); + + // Register server + monopigatorRegister(); +} + +AtlanticDaemon::~AtlanticDaemon() +{ + delete m_monopigatorSocket; +} + +void AtlanticDaemon::monopigatorRegister() +{ + m_monopigatorSocket->connectToHost("gator.monopd.net", 80); +} + +void AtlanticDaemon::monopigatorConnected() +{ + QString get = "GET /register.php?host=capsi.com&port=1234&version=atlanticd-prototype HTTP/1.1\nHost: gator.monopd.net\n\n"; + m_monopigatorSocket->writeBlock(get.latin1(), get.length()); + m_monopigatorSocket->close(); + + // Monopigator clears old entries, so keep registering every 180s + QTimer::singleShot(180000, this, SLOT(monopigatorRegister())); +} + +void AtlanticDaemon::newClient(AtlanticClient *client) +{ + m_clients.append(client); + + connect(client, SIGNAL(clientInput(AtlanticClient *, const QString &)), this, SLOT(clientInput(AtlanticClient *, const QString &))); +} + +void AtlanticDaemon::clientInput(AtlanticClient *client, const QString &data) +{ +} diff --git a/atlantik/atlanticd/atlanticdaemon.h b/atlantik/atlanticd/atlanticdaemon.h new file mode 100644 index 00000000..729a960e --- /dev/null +++ b/atlantik/atlanticd/atlanticdaemon.h @@ -0,0 +1,48 @@ +// Copyright (c) 2002 Rob Kaper <cap@capsi.com> +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// version 2 as published by the Free Software Foundation. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +// Boston, MA 02110-1301, USA. + +#ifndef ATLANTIC_ATLANTICDAEMON_H +#define ATLANTIC_ATLANTICDAEMON_H + +#include <qptrlist.h> + +class QSocket; + +class AtlanticCore; +class AtlanticClient; +class ServerSocket; + +class AtlanticDaemon : public QObject +{ +Q_OBJECT + +public: + AtlanticDaemon(); + ~AtlanticDaemon(); +private slots: + void monopigatorRegister(); + void monopigatorConnected(); + void newClient(AtlanticClient *client); + void clientInput(AtlanticClient *client, const QString &data); + +private: + QSocket *m_monopigatorSocket; + ServerSocket *m_serverSocket; + AtlanticCore *m_atlanticCore; + QPtrList<AtlanticClient> m_clients; +}; + +#endif diff --git a/atlantik/atlanticd/main.cpp b/atlantik/atlanticd/main.cpp new file mode 100644 index 00000000..235dcd00 --- /dev/null +++ b/atlantik/atlanticd/main.cpp @@ -0,0 +1,27 @@ +// Copyright (c) 2002 Rob Kaper <cap@capsi.com> +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// version 2 as published by the Free Software Foundation. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +// Boston, MA 02110-1301, USA. + +#include <qapplication.h> + +#include "atlanticdaemon.h" + +int main(int argc, char *argv[]) +{ + new AtlanticDaemon(); + + QApplication qapplication(argc, argv); + qapplication.exec(); +} diff --git a/atlantik/atlanticd/serversocket.cpp b/atlantik/atlanticd/serversocket.cpp new file mode 100644 index 00000000..2056a754 --- /dev/null +++ b/atlantik/atlanticd/serversocket.cpp @@ -0,0 +1,32 @@ +// Copyright (c) 2002-2003 Rob Kaper <cap@capsi.com> +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// version 2 as published by the Free Software Foundation. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +// Boston, MA 02110-1301, USA. + +#include "atlanticclient.h" +#include "serversocket.h" + +ServerSocket::ServerSocket(int port, int backlog) : QServerSocket(port, backlog) +{ +} + +void ServerSocket::newConnection(int socket) +{ + AtlanticClient *client = new AtlanticClient(this, "socket"); + client->setSocket(socket); + + emit newClient(client); +} + +#include "serversocket.moc" diff --git a/atlantik/atlanticd/serversocket.h b/atlantik/atlanticd/serversocket.h new file mode 100644 index 00000000..fce347e9 --- /dev/null +++ b/atlantik/atlanticd/serversocket.h @@ -0,0 +1,35 @@ +// Copyright (c) 2002 Rob Kaper <cap@capsi.com> +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// version 2 as published by the Free Software Foundation. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +// Boston, MA 02110-1301, USA. + +#ifndef SERVERSOCKET_H +#define SERVERSOCKET_H + +#include <qserversocket.h> + +class AtlanticClient; + +class ServerSocket : public QServerSocket +{ +Q_OBJECT + +public: + ServerSocket(int port, int backlog); + void newConnection(int socket); + +signals: + void newClient(AtlanticClient *client); +}; +#endif |