diff options
author | Ben Boeckel <MathStuf@gmail.com> | 2008-10-12 01:39:07 +0000 |
---|---|---|
committer | Ben Boeckel <MathStuf@gmail.com> | 2008-10-12 01:39:07 +0000 |
commit | 2e4b02a9410fc51dc0c97bd4a9fd0b8c45bda27f (patch) | |
tree | e63fe620e7ed88675a26b603b2313bd24ffb43a5 /signet | |
parent | 927c42e73cce66acccc7056ea330a2362b455a00 (diff) | |
download | sigen-2e4b02a9410fc51dc0c97bd4a9fd0b8c45bda27f.tar.gz sigen-2e4b02a9410fc51dc0c97bd4a9fd0b8c45bda27f.tar.xz sigen-2e4b02a9410fc51dc0c97bd4a9fd0b8c45bda27f.zip |
[FIX] Still figuring out things for signet
[ADD] Files for signet
git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@274 6ecfd1a5-f3ed-3746-8530-beee90d26b22
Diffstat (limited to 'signet')
-rw-r--r-- | signet/CMakeLists.txt | 10 | ||||
-rw-r--r-- | signet/Client.cpp | 87 | ||||
-rw-r--r-- | signet/Client.h | 41 | ||||
-rw-r--r-- | signet/ConnectionHandler.cpp | 42 | ||||
-rw-r--r-- | signet/ConnectionHandler.h | 51 | ||||
-rw-r--r-- | signet/Room.cpp | 45 | ||||
-rw-r--r-- | signet/Room.h | 58 | ||||
-rw-r--r-- | signet/Server.cpp | 42 | ||||
-rw-r--r-- | signet/Server.h | 5 | ||||
-rw-r--r-- | signet/ServerConnectionHandler.cpp | 63 | ||||
-rw-r--r-- | signet/ServerConnectionHandler.h | 45 | ||||
-rw-r--r-- | signet/signet.pro | 12 |
12 files changed, 452 insertions, 49 deletions
diff --git a/signet/CMakeLists.txt b/signet/CMakeLists.txt index 5b2825ed..8682a354 100644 --- a/signet/CMakeLists.txt +++ b/signet/CMakeLists.txt @@ -7,7 +7,12 @@ ENDIF(NOT BUILT_FROM_ROOT) ADD_DEFINITIONS(-DMAKE_SIGNET_LIB) SET(signet_MOC_HEADERS + Client.h + ConnectionHandler.h Server.h + ServerConnectionHandler.h + Room.h +# RoomConnectionHandler.h ) QT4_WRAP_CPP(signet_MOC_SRCS ${signet_MOC_HEADERS}) SET(signet_HEADERS @@ -18,7 +23,11 @@ SET(signet_DEVEL ${signet_HEADERS} ) SET(signet_SRCS + Client.cpp + ConnectionHandler.cpp + Room.cpp Server.cpp + ServerConnectionHandler.cpp ) ADD_LIBRARY(signet @@ -34,6 +43,7 @@ SET_TARGET_PROPERTIES(signet TARGET_LINK_LIBRARIES(signet ${QT_QTCORE_LIBRARY} ${QT_QTNETWORK_LIBRARY} + ${KDE4_KDECORE_LIBRARY} ) INSTALL( diff --git a/signet/Client.cpp b/signet/Client.cpp new file mode 100644 index 00000000..9a032407 --- /dev/null +++ b/signet/Client.cpp @@ -0,0 +1,87 @@ +/* + * 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 "Client.h" + +// Signet includes +#include "Room.h" +#include "Server.h" + +// Qt includes +#include <QtNetwork/QHostAddress> +#include <QtNetwork/QTcpSocket> + +Signet::Client::Client(QTcpSocket* socket, QObject* parent) : + QObject(parent), + m_socket(socket) +{ +} + +Signet::Client::~Client() +{ +} + +void Signet::Client::setServer(Server* server) +{ +} + +void Signet::Client::joinRoom(Room* room) +{ +} + +void Signet::Client::leaveRoom(Room* room) +{ +} + +void Signet::Client::joinTable(Room* room, Table* table) +{ + if (!m_rooms.contains(room)) + joinRoom(room); +// table-> +} + +void Signet::Client::leaveTable(Room* room, Table* table) +{ + if (m_rooms.contains(room) && m_rooms[room].contains(table)) + { + table->removeClient(this); + m_rooms[room].remove(table); + } +} + +void Signet::Client::sendData(const QByteArray& data) +{ +} + +void Signet::Client::disconnectFromServer() +{ + disconnectFromAllRooms(); + m_server->removeClient(this); +} + +void Signet::Client::disconnectFromAllRooms() +{ + QList<Room*> rooms = m_rooms.keys(); + foreach (Room* room, rooms) + { + QList<Table*> tables = QList::fromSet(m_rooms[room]); + foreach (Table* table, tables) + table->removeClient(this); + room->removeClient(this); + } +} diff --git a/signet/Client.h b/signet/Client.h index 245d7bb5..87706f51 100644 --- a/signet/Client.h +++ b/signet/Client.h @@ -15,28 +15,55 @@ * with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef SIGBATTLE_CLIENT -#define SIGBATTLE_CLIENT +#ifndef SIGNET_CLIENT +#define SIGNET_CLIENT + +// Signet includes +#include "Global.h" // Qt includes +#include <QtCore/QMap> #include <QtCore/QObject> -namespace Sigbattle +// Forward declarations +class QHostAddress; +class QTcpSocket; + +namespace Signet { -class SIGBATTLE_EXPORT Client : public QObject +class Room; +class Server; +class Table; + +class SIGNET_EXPORT Client : public QObject { Q_OBJECT public: + void setServer(Server* server); + + void joinRoom(Room* room); + void leaveRoom(Room* room); + + void joinTable(Room* room, Table* table); + void leaveTable(Room* room, Table* table); public slots: - virtual sendData(const QByteArray& data) = 0; + void sendData(const QByteArray& data); signals: void dataReceived(const QByteArray& data); + + void timeout(); protected: - Client(const Client& client, QObject* parent); - Client(QObject* parent); + Client(QTcpSocket* socket, QObject* parent); ~Client(); protected slots: + private: + QTcpSocket* m_socket; + Server* m_server; + QMap<Room*, QSet<Table*> > m_rooms; + private slots: + void disconnectFromServer(); + void disconnectFromAllRooms(); }; } diff --git a/signet/ConnectionHandler.cpp b/signet/ConnectionHandler.cpp new file mode 100644 index 00000000..638ddc0d --- /dev/null +++ b/signet/ConnectionHandler.cpp @@ -0,0 +1,42 @@ +/* + * 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 "ConnectionHandler.h" + +// Signet includes +#include "Client.h" + +Signet::ConnectionHandler::ConnectionHandler(QObject* parent) : + QObject(parent) +{ +} + +void Signet::ConnectionHandler::addClient(Client* socket) +{ + // TODO: Add the client +} + +void Signet::ConnectionHandler::removeClient(Client* socket) +{ + // TODO: Remove the client +} + +void Signet::ConnectionHandler::sendData(Client* client, const QByteArray& data) +{ + // TODO: Send data to the client +} diff --git a/signet/ConnectionHandler.h b/signet/ConnectionHandler.h new file mode 100644 index 00000000..661831fd --- /dev/null +++ b/signet/ConnectionHandler.h @@ -0,0 +1,51 @@ +/* + * 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_CONNECTIONHANDLER +#define SIGNET_CONNECTIONHANDLER + +// Signet includes +#include "Global.h" + +// Qt includes +#include <QtCore/QMap> +#include <QtCore/QObject> + +namespace Signet +{ +// Forward declarations +class Client; + +class SIGNET_EXPORT ConnectionHandler : public QObject +{ + Q_OBJECT + + public: + ConnectionHandler(QObject* parent); + public slots: + void addClient(Client* socket); + void removeClient(Client* socket); + signals: + void dataReceived(const QByteArray& data); + protected slots: + void sendData(Client* client, const QByteArray& data); + private: + QList<Client*> m_sockets; +}; +} + +#endif diff --git a/signet/Room.cpp b/signet/Room.cpp new file mode 100644 index 00000000..2ed9732c --- /dev/null +++ b/signet/Room.cpp @@ -0,0 +1,45 @@ +/* + * 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 "Room.h" + +Signet::Room::Room(const QString& name, QObject* parent) : + QObject(parent), + m_name(name) +{ +} + +bool Signet::Room::addClient(Client* client) +{ + // TODO: Estabish a connection with the client +} + +void Signet::Room::createTable(const QString& table) +{ + // TODO: Create a table +} + +void Signet::Room::closeTable(const QString& table) +{ + // TODO: Close a table +} + +bool Signet::Room::joinTable(Client* client, const QString& tableName) +{ + // TODO: Add a client to the table +} diff --git a/signet/Room.h b/signet/Room.h new file mode 100644 index 00000000..c684e756 --- /dev/null +++ b/signet/Room.h @@ -0,0 +1,58 @@ +/* + * 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_ROOM +#define SIGNET_ROOM + +// Signet includes +#include "Global.h" + +// Qt includes +#include <QtCore/QMap> +#include <QtCore/QObject> + +namespace Signet +{ +// Forward declarations +class Client; +class RoomConnectionHandler; +class Table; + +class SIGNET_EXPORT Room : public QObject +{ + Q_OBJECT + + public: + Room(const QString& name, QObject* parent); + + bool addClient(Client* client); + public slots: + signals: + void globalMessage(const QString& message); + protected: + void createTable(const QString& table); + void closeTable(const QString& table); + protected slots: + bool joinTable(Client* client, const QString& tableName); + private: + QString m_name; + QMap<QString, Table*> m_table; + RoomConnectionHandler* m_handler; +}; +} + +#endif diff --git a/signet/Server.cpp b/signet/Server.cpp index 7c7b44d5..a5d9aca4 100644 --- a/signet/Server.cpp +++ b/signet/Server.cpp @@ -24,42 +24,13 @@ // KDE includes #include <KConfig> +#include <KConfigGroup> #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) @@ -78,13 +49,12 @@ void Signet::Server::closeRoom(const QString& room) } } -bool Signet::Server::joinRoom(Client* client, const QString& roomName) +void 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) -{ + if (!m_rooms[roomName]->addClient(client)) + { + // TODO: Let the client know about the error. + } } diff --git a/signet/Server.h b/signet/Server.h index 53cc6ef4..8cf22e07 100644 --- a/signet/Server.h +++ b/signet/Server.h @@ -25,9 +25,6 @@ #include <QtCore/QMap> #include <QtCore/QObject> -// Forward declarations -class QTcpSocket; - namespace Signet { class Client; @@ -49,7 +46,7 @@ class SIGNET_EXPORT Server : public QObject bool verifyUser(Client* client); protected slots: - bool joinRoom(Client* client, const QString& roomName); + void joinRoom(Client* client, const QString& roomName); private: QMap<QString, Room*> m_rooms; ServerConnectionHandler* m_handler; diff --git a/signet/ServerConnectionHandler.cpp b/signet/ServerConnectionHandler.cpp new file mode 100644 index 00000000..be5d8e53 --- /dev/null +++ b/signet/ServerConnectionHandler.cpp @@ -0,0 +1,63 @@ +/* + * 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 "ServerConnectionHandler.h" + +// Signet includes +#include "Server.h" + +// KDE includes +#include <KConfigGroup> + +Signet::ServerConnectionHandler::ServerConnectionHandler(Server* server, QObject* parent) : + ConnectionHandler(parent), + m_server(server) +{ +} + +void Signet::ServerConnectionHandler::connectToMaster(const KConfigGroup& group) +{ + // TODO: Get the information from the configuration + // TODO: Connect to the master +// 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 +// } +} diff --git a/signet/ServerConnectionHandler.h b/signet/ServerConnectionHandler.h new file mode 100644 index 00000000..2d758879 --- /dev/null +++ b/signet/ServerConnectionHandler.h @@ -0,0 +1,45 @@ +/* + * 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_SERVERCONNECTIONHANDLER +#define SIGNET_SERVERCONNECTIONHANDLER + +// Signet includes +#include "ConnectionHandler.h" +#include "Global.h" + +// Forward declarations +class KConfigGroup; + +namespace Signet +{ +class Server; + +class SIGNET_EXPORT ServerConnectionHandler : public ConnectionHandler +{ + Q_OBJECT + + public: + ServerConnectionHandler(Server* server, QObject* parent); + public slots: + void connectToMaster(const KConfigGroup& group); + private: + Server* m_server; +}; +} + +#endif diff --git a/signet/signet.pro b/signet/signet.pro index 561a3c15..54c42592 100644 --- a/signet/signet.pro +++ b/signet/signet.pro @@ -6,6 +6,7 @@ DOC_DIR = ../doc DESTDIR = ../bin INSTALLDIR = lib$$system(kde4-config --libsuffix) LIBS += -L../bin + -lkdecore CONFIG += qt \ warn_on \ @@ -19,10 +20,17 @@ DEFINES += MAKE_SIGNET_LIB include(../install.pri) include(../kde4.pri) -SOURCES += Server.cpp +SOURCES += Client.cpp \ + ConnectionHandler.cpp \ + Room.cpp \ + Server.cpp \ + ServerConnectionhandler.cpp HEADERS += Client.h \ + ConnectionHandler.h \ Global.h \ - Server.h + Room.h \ + Server.h \ + ServerConnectionHandler.h include(../headers.pri) |