diff options
author | Ben Boeckel <MathStuf@gmail.com> | 2008-10-12 16:51:32 +0000 |
---|---|---|
committer | Ben Boeckel <MathStuf@gmail.com> | 2008-10-12 16:51:32 +0000 |
commit | 03e65c78d1bc08bdaee86cf09a4dd8735b6a9fdd (patch) | |
tree | dcae9e046b80a64e638a741c148fcdec03bc0801 /signet | |
parent | 2e4b02a9410fc51dc0c97bd4a9fd0b8c45bda27f (diff) | |
download | sigen-03e65c78d1bc08bdaee86cf09a4dd8735b6a9fdd.tar.gz sigen-03e65c78d1bc08bdaee86cf09a4dd8735b6a9fdd.tar.xz sigen-03e65c78d1bc08bdaee86cf09a4dd8735b6a9fdd.zip |
[FIX] Fleshing out Signet more
[DEL] Unused top-level directories
git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@275 6ecfd1a5-f3ed-3746-8530-beee90d26b22
Diffstat (limited to 'signet')
-rw-r--r-- | signet/CMakeLists.txt | 7 | ||||
-rw-r--r-- | signet/Client.cpp | 20 | ||||
-rw-r--r-- | signet/ConnectionHandler.cpp | 4 | ||||
-rw-r--r-- | signet/ConnectionHandler.h | 8 | ||||
-rw-r--r-- | signet/Room.cpp | 31 | ||||
-rw-r--r-- | signet/Room.h | 13 | ||||
-rw-r--r-- | signet/Server.cpp | 37 | ||||
-rw-r--r-- | signet/Server.h | 11 | ||||
-rw-r--r-- | signet/ServerConnectionHandler.cpp | 63 | ||||
-rw-r--r-- | signet/Table.cpp | 35 | ||||
-rw-r--r-- | signet/Table.h (renamed from signet/ServerConnectionHandler.h) | 21 | ||||
-rw-r--r-- | signet/signet.pro | 4 |
12 files changed, 143 insertions, 111 deletions
diff --git a/signet/CMakeLists.txt b/signet/CMakeLists.txt index 8682a354..12e92767 100644 --- a/signet/CMakeLists.txt +++ b/signet/CMakeLists.txt @@ -9,10 +9,9 @@ ADD_DEFINITIONS(-DMAKE_SIGNET_LIB) SET(signet_MOC_HEADERS Client.h ConnectionHandler.h - Server.h - ServerConnectionHandler.h Room.h -# RoomConnectionHandler.h + Server.h + Table.h ) QT4_WRAP_CPP(signet_MOC_SRCS ${signet_MOC_HEADERS}) SET(signet_HEADERS @@ -27,7 +26,7 @@ SET(signet_SRCS ConnectionHandler.cpp Room.cpp Server.cpp - ServerConnectionHandler.cpp + Table.cpp ) ADD_LIBRARY(signet diff --git a/signet/Client.cpp b/signet/Client.cpp index 9a032407..a6d39011 100644 --- a/signet/Client.cpp +++ b/signet/Client.cpp @@ -21,6 +21,7 @@ // Signet includes #include "Room.h" #include "Server.h" +#include "Table.h" // Qt includes #include <QtNetwork/QHostAddress> @@ -42,17 +43,25 @@ void Signet::Client::setServer(Server* server) void Signet::Client::joinRoom(Room* room) { + if (!m_rooms.contains(room)) + { + room->addClient(this); + m_rooms[room]; + } } void Signet::Client::leaveRoom(Room* room) { + QList<Table*> tables = QList<Table*>::fromSet(m_rooms[room]); + foreach (Table* table, tables) + table->removeClient(this); + room->removeClient(this); } void Signet::Client::joinTable(Room* room, Table* table) { if (!m_rooms.contains(room)) joinRoom(room); -// table-> } void Signet::Client::leaveTable(Room* room, Table* table) @@ -66,6 +75,8 @@ void Signet::Client::leaveTable(Room* room, Table* table) void Signet::Client::sendData(const QByteArray& data) { + m_socket->write(data); +// m_socket->waitForBytesWritten(); } void Signet::Client::disconnectFromServer() @@ -78,10 +89,5 @@ 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); - } + leaveRoom(room); } diff --git a/signet/ConnectionHandler.cpp b/signet/ConnectionHandler.cpp index 638ddc0d..e72950cd 100644 --- a/signet/ConnectionHandler.cpp +++ b/signet/ConnectionHandler.cpp @@ -26,12 +26,12 @@ Signet::ConnectionHandler::ConnectionHandler(QObject* parent) : { } -void Signet::ConnectionHandler::addClient(Client* socket) +bool Signet::ConnectionHandler::addClient(Client* socket) { // TODO: Add the client } -void Signet::ConnectionHandler::removeClient(Client* socket) +bool Signet::ConnectionHandler::removeClient(Client* socket) { // TODO: Remove the client } diff --git a/signet/ConnectionHandler.h b/signet/ConnectionHandler.h index 661831fd..c845e6b5 100644 --- a/signet/ConnectionHandler.h +++ b/signet/ConnectionHandler.h @@ -36,11 +36,15 @@ class SIGNET_EXPORT ConnectionHandler : public QObject public: ConnectionHandler(QObject* parent); + + virtual QString type() const = 0; + virtual QString name() const = 0; public slots: - void addClient(Client* socket); - void removeClient(Client* socket); + bool addClient(Client* socket); + bool removeClient(Client* socket); signals: void dataReceived(const QByteArray& data); + protected: protected slots: void sendData(Client* client, const QByteArray& data); private: diff --git a/signet/Room.cpp b/signet/Room.cpp index 2ed9732c..461ad437 100644 --- a/signet/Room.cpp +++ b/signet/Room.cpp @@ -18,28 +18,47 @@ // Header include #include "Room.h" +// Signet includes +#include "Table.h" + Signet::Room::Room(const QString& name, QObject* parent) : - QObject(parent), + ConnectionHandler(parent), m_name(name) { } -bool Signet::Room::addClient(Client* client) +QString Signet::Room::type() const +{ + return "room"; +} + +QString Signet::Room::name() const { - // TODO: Estabish a connection with the client + return m_name; } void Signet::Room::createTable(const QString& table) { - // TODO: Create a table + if (m_tables.contains(table)) + return; + m_tables[table] = new Table(table, this); } void Signet::Room::closeTable(const QString& table) { - // TODO: Close a table + if (m_tables.contains(table)) + { + delete m_tables[table]; + m_tables.remove(table); + } } bool Signet::Room::joinTable(Client* client, const QString& tableName) { - // TODO: Add a client to the table + if (!m_tables.contains(tableName)) + createTable(tableName); + if (!m_tables[tableName]->addClient(client)) + { + // TODO: Let the client know about the error. + } } diff --git a/signet/Room.h b/signet/Room.h index c684e756..8cc0ca8a 100644 --- a/signet/Room.h +++ b/signet/Room.h @@ -19,27 +19,27 @@ #define SIGNET_ROOM // Signet includes +#include "ConnectionHandler.h" #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 +class SIGNET_EXPORT Room : public ConnectionHandler { Q_OBJECT - + public: Room(const QString& name, QObject* parent); - bool addClient(Client* client); + QString type() const; + QString name() const; public slots: signals: void globalMessage(const QString& message); @@ -50,8 +50,7 @@ class SIGNET_EXPORT Room : public QObject bool joinTable(Client* client, const QString& tableName); private: QString m_name; - QMap<QString, Table*> m_table; - RoomConnectionHandler* m_handler; + QMap<QString, Table*> m_tables; }; } diff --git a/signet/Server.cpp b/signet/Server.cpp index a5d9aca4..332c305f 100644 --- a/signet/Server.cpp +++ b/signet/Server.cpp @@ -20,7 +20,6 @@ // Signet includes #include "Room.h" -#include "ServerConnectionHandler.h" // KDE includes #include <KConfig> @@ -28,9 +27,9 @@ #include <KGlobal> Signet::Server::Server(QObject* parent) : - QObject(parent) + ConnectionHandler(parent) { - m_handler->connectToMaster(KGlobal::config()->group("Master Server")); + connectToMaster(KGlobal::config()->group("Master Server")); } void Signet::Server::createRoom(const QString& room) @@ -58,3 +57,35 @@ void Signet::Server::joinRoom(Client* client, const QString& roomName) // TODO: Let the client know about the error. } } + +void Signet::Server::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/Server.h b/signet/Server.h index 8cf22e07..58328188 100644 --- a/signet/Server.h +++ b/signet/Server.h @@ -19,25 +19,27 @@ #define SIGNET_SERVER // Signet includes +#include "ConnectionHandler.h" #include "Global.h" // Qt includes #include <QtCore/QMap> #include <QtCore/QObject> +// Forward declarations +class KConfigGroup; + namespace Signet { class Client; class Room; -class ServerConnectionHandler; -class SIGNET_EXPORT Server : public QObject +class SIGNET_EXPORT Server : public ConnectionHandler { Q_OBJECT public: Server(QObject* parent); - public slots: signals: void globalMessage(const QString& message); protected: @@ -47,9 +49,10 @@ class SIGNET_EXPORT Server : public QObject bool verifyUser(Client* client); protected slots: void joinRoom(Client* client, const QString& roomName); + + void connectToMaster(const KConfigGroup& group); private: QMap<QString, Room*> m_rooms; - ServerConnectionHandler* m_handler; }; } diff --git a/signet/ServerConnectionHandler.cpp b/signet/ServerConnectionHandler.cpp deleted file mode 100644 index be5d8e53..00000000 --- a/signet/ServerConnectionHandler.cpp +++ /dev/null @@ -1,63 +0,0 @@ -/* - * 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/Table.cpp b/signet/Table.cpp new file mode 100644 index 00000000..1296e825 --- /dev/null +++ b/signet/Table.cpp @@ -0,0 +1,35 @@ +/* + * 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 "Table.h" + +Signet::Table::Table(const QString& name, QObject* parent) : + ConnectionHandler(parent), + m_name(name) +{ +} + +QString Signet::Table::type() const +{ + return "table"; +} + +QString Signet::Table::name() const +{ + return m_name; +} diff --git a/signet/ServerConnectionHandler.h b/signet/Table.h index 2d758879..20a88c54 100644 --- a/signet/ServerConnectionHandler.h +++ b/signet/Table.h @@ -15,30 +15,29 @@ * with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef SIGNET_SERVERCONNECTIONHANDLER -#define SIGNET_SERVERCONNECTIONHANDLER +#ifndef SIGNET_TABLE +#define SIGNET_TABLE // Signet includes #include "ConnectionHandler.h" #include "Global.h" -// Forward declarations -class KConfigGroup; - namespace Signet { -class Server; +// Forward declarations +class Client; -class SIGNET_EXPORT ServerConnectionHandler : public ConnectionHandler +class SIGNET_EXPORT Table : public ConnectionHandler { Q_OBJECT public: - ServerConnectionHandler(Server* server, QObject* parent); - public slots: - void connectToMaster(const KConfigGroup& group); + Table(const QString& name, QObject* parent); + + QString type() const; + QString name() const; private: - Server* m_server; + QString m_name; }; } diff --git a/signet/signet.pro b/signet/signet.pro index 54c42592..b3336f7e 100644 --- a/signet/signet.pro +++ b/signet/signet.pro @@ -24,13 +24,13 @@ SOURCES += Client.cpp \ ConnectionHandler.cpp \ Room.cpp \ Server.cpp \ - ServerConnectionhandler.cpp + Table.cpp HEADERS += Client.h \ ConnectionHandler.h \ Global.h \ Room.h \ Server.h \ - ServerConnectionHandler.h + Table.h include(../headers.pri) |