summaryrefslogtreecommitdiffstats
path: root/signet/Server.cpp
blob: 332c305fff8088d21c64973275a9cdf85a78bb91 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
 * 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"

// KDE includes
#include <KConfig>
#include <KConfigGroup>
#include <KGlobal>

Signet::Server::Server(QObject* parent) :
        ConnectionHandler(parent)
{
    connectToMaster(KGlobal::config()->group("Master Server"));
}

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);
    }
}

void Signet::Server::joinRoom(Client* client, const QString& roomName)
{
    if (!m_rooms.contains(roomName))
        createRoom(roomName);
    if (!m_rooms[roomName]->addClient(client))
    {
        // 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
//     }
}