summaryrefslogtreecommitdiffstats
path: root/signet
diff options
context:
space:
mode:
authorBen Boeckel <MathStuf@gmail.com>2008-10-11 14:40:58 +0000
committerBen Boeckel <MathStuf@gmail.com>2008-10-11 14:40:58 +0000
commit927c42e73cce66acccc7056ea330a2362b455a00 (patch)
treefd37832bb336c19c2dc5d6776c36e6fff0b969d0 /signet
parent3a096bed018254f9d662f9ae85792b8ae5df4837 (diff)
downloadsigen-927c42e73cce66acccc7056ea330a2362b455a00.tar.gz
sigen-927c42e73cce66acccc7056ea330a2362b455a00.tar.xz
sigen-927c42e73cce66acccc7056ea330a2362b455a00.zip
[FIX] Reordered sections in class declarations
[FIX] Using QSet rather than QList for players [ADD] Started signet library (compilation fails) git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@273 6ecfd1a5-f3ed-3746-8530-beee90d26b22
Diffstat (limited to 'signet')
-rw-r--r--signet/CMakeLists.txt49
-rw-r--r--signet/Client.h43
-rw-r--r--signet/Global.h36
-rw-r--r--signet/Server.cpp90
-rw-r--r--signet/Server.h59
-rw-r--r--signet/signet.pro28
6 files changed, 305 insertions, 0 deletions
diff --git a/signet/CMakeLists.txt b/signet/CMakeLists.txt
new file mode 100644
index 00000000..5b2825ed
--- /dev/null
+++ b/signet/CMakeLists.txt
@@ -0,0 +1,49 @@
+PROJECT(signet)
+
+IF(NOT BUILT_FROM_ROOT)
+ MESSAGE(FATAL_ERROR "Not built from source root")
+ENDIF(NOT BUILT_FROM_ROOT)
+
+ADD_DEFINITIONS(-DMAKE_SIGNET_LIB)
+
+SET(signet_MOC_HEADERS
+ Server.h
+)
+QT4_WRAP_CPP(signet_MOC_SRCS ${signet_MOC_HEADERS})
+SET(signet_HEADERS
+ ${signet_MOC_HEADERS}
+ Global.h
+)
+SET(signet_DEVEL
+ ${signet_HEADERS}
+)
+SET(signet_SRCS
+ Server.cpp
+)
+
+ADD_LIBRARY(signet
+ ${signet_SRCS}
+ ${signet_MOC_SRCS}
+)
+SET_TARGET_PROPERTIES(signet
+ PROPERTIES
+ VERSION ${SIGEN_VERSION}
+ SOVERSION ${SIGEN_SOVERSION}
+ LINK_INTERFACE_LIBRARIES ""
+)
+TARGET_LINK_LIBRARIES(signet
+ ${QT_QTCORE_LIBRARY}
+ ${QT_QTNETWORK_LIBRARY}
+)
+
+INSTALL(
+ TARGETS signet
+ DESTINATION ${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}
+ COMPONENT runtime
+)
+
+INSTALL(
+ FILES ${signet_DEVEL}
+ DESTINATION ${CMAKE_INSTALL_PREFIX}/include/${CMAKE_PROJECT_NAME}/${PROJECT_NAME}
+ COMPONENT development
+)
diff --git a/signet/Client.h b/signet/Client.h
new file mode 100644
index 00000000..245d7bb5
--- /dev/null
+++ b/signet/Client.h
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2008 Ben Boeckel <MathStuf@gmail.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * 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. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef SIGBATTLE_CLIENT
+#define SIGBATTLE_CLIENT
+
+// Qt includes
+#include <QtCore/QObject>
+
+namespace Sigbattle
+{
+class SIGBATTLE_EXPORT Client : public QObject
+{
+ Q_OBJECT
+
+ public:
+ public slots:
+ virtual sendData(const QByteArray& data) = 0;
+ signals:
+ void dataReceived(const QByteArray& data);
+ protected:
+ Client(const Client& client, QObject* parent);
+ Client(QObject* parent);
+ ~Client();
+ protected slots:
+};
+}
+
+#endif
diff --git a/signet/Global.h b/signet/Global.h
new file mode 100644
index 00000000..dc68ead7
--- /dev/null
+++ b/signet/Global.h
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2008 Ben Boeckel <MathStuf@gmail.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * 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. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef SIGNET_GLOBAL
+#define SIGNET_GLOBAL
+
+// KDE includes
+#include <kdemacros.h>
+
+#ifndef SIGNET_EXPORT
+# ifdef MAKE_SIGNET_LIB
+# define SIGNET_EXPORT KDE_EXPORT
+# else
+# define SIGNET_EXPORT KDE_IMPORT
+# endif
+#endif
+
+#ifndef SIGNET_EXPORT_DEPRECATED
+# define SIGNET_EXPORT_DEPRECATED KDE_DEPRECATED SIGNET_EXPORT
+#endif
+
+#endif
diff --git a/signet/Server.cpp b/signet/Server.cpp
new file mode 100644
index 00000000..7c7b44d5
--- /dev/null
+++ b/signet/Server.cpp
@@ -0,0 +1,90 @@
+/*
+ * Copyright 2008 Ben Boeckel <MathStuf@gmail.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * 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. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+// Header include
+#include "Server.h"
+
+// Signet includes
+#include "Room.h"
+#include "ServerConnectionHandler.h"
+
+// KDE includes
+#include <KConfig>
+#include <KGlobal>
+
+// Qt includes
+#include <QtNetwork/QHostAddress>
+#include <QtNetwork/QTcpSocket>
+
+Signet::Server::Server(QObject* parent) :
+ QObject(parent)
+{
+ m_handler->connectToMaster(KGlobal::config()->group("Master Server"));
+// QHostAddress masterAddress;
+// int port;
+// QString key;
+// int timeout;
+// if (config->hasGroup("Master Server"))
+// {
+// const KConfigGroup& group = config->group("Master Server");
+// QString address = group.readEntry("Address", "");
+// if (!masterAddress.setAddress(address))
+// qFatal(QString("Invalid address for the master server: %1").arg(address));
+// port = group.readEntry("Port", -1);
+// if (port < 0)
+// qFatal(QString("Invalid port for the master server: %1").arg(port));
+// key = group.readEntry("Key", "");
+// timeout = group.readEntry("Timeout", 30000);
+// }
+// else
+// {
+// // TODO: Configuration not complete
+// }
+// // TODO: Proxy support?
+// m_masterServer->connectToHost(masterAddress, port);
+// if (!m_masterServer->waitForConnect(timeout))
+// {
+// // TODO: Connect failed
+// }
+}
+
+void Signet::Server::createRoom(const QString& room)
+{
+ if (m_rooms.contains(room))
+ return;
+ m_rooms[room] = new Room(room, this);
+}
+
+void Signet::Server::closeRoom(const QString& room)
+{
+ if (m_rooms.contains(room))
+ {
+ delete m_rooms[room];
+ m_rooms.remove(room);
+ }
+}
+
+bool Signet::Server::joinRoom(Client* client, const QString& roomName)
+{
+ if (!m_rooms.contains(roomName))
+ createRoom(roomName);
+ m_rooms[room]->addClient(client);
+}
+
+void Signet::Server::receiveData(const QByteArray& data)
+{
+}
diff --git a/signet/Server.h b/signet/Server.h
new file mode 100644
index 00000000..53cc6ef4
--- /dev/null
+++ b/signet/Server.h
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2008 Ben Boeckel <MathStuf@gmail.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * 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. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef SIGNET_SERVER
+#define SIGNET_SERVER
+
+// Signet includes
+#include "Global.h"
+
+// Qt includes
+#include <QtCore/QMap>
+#include <QtCore/QObject>
+
+// Forward declarations
+class QTcpSocket;
+
+namespace Signet
+{
+class Client;
+class Room;
+class ServerConnectionHandler;
+
+class SIGNET_EXPORT Server : public QObject
+{
+ Q_OBJECT
+
+ public:
+ Server(QObject* parent);
+ public slots:
+ signals:
+ void globalMessage(const QString& message);
+ protected:
+ void createRoom(const QString& room);
+ void closeRoom(const QString& room);
+
+ bool verifyUser(Client* client);
+ protected slots:
+ bool joinRoom(Client* client, const QString& roomName);
+ private:
+ QMap<QString, Room*> m_rooms;
+ ServerConnectionHandler* m_handler;
+};
+}
+
+#endif
diff --git a/signet/signet.pro b/signet/signet.pro
new file mode 100644
index 00000000..561a3c15
--- /dev/null
+++ b/signet/signet.pro
@@ -0,0 +1,28 @@
+include(../version.pri)
+TEMPLATE = lib
+OBJECTS_DIR = .obj
+MOC_DIR = .moc
+DOC_DIR = ../doc
+DESTDIR = ../bin
+INSTALLDIR = lib$$system(kde4-config --libsuffix)
+LIBS += -L../bin
+
+CONFIG += qt \
+ warn_on \
+ dll
+
+QT -= gui
+QT += network
+
+DEFINES += MAKE_SIGNET_LIB
+
+include(../install.pri)
+include(../kde4.pri)
+
+SOURCES += Server.cpp
+
+HEADERS += Client.h \
+ Global.h \
+ Server.h
+
+include(../headers.pri)