summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTreeki <treeki@gmail.com>2014-01-20 09:53:20 +0100
committerTreeki <treeki@gmail.com>2014-01-20 09:53:20 +0100
commit0c114045d4a0b16db8c00e710708d7d20a54bf6a (patch)
tree919fc52de5161459f0e90b7e9f3aa672f6111d64
parent1fb18cd2ef80709681e2a4e4b06624ad9e8dc9b2 (diff)
downloadbounce4-0c114045d4a0b16db8c00e710708d7d20a54bf6a.tar.gz
bounce4-0c114045d4a0b16db8c00e710708d7d20a54bf6a.zip
add server management functions to NetCore
Diffstat (limited to '')
-rw-r--r--core.cpp34
-rw-r--r--core.h6
2 files changed, 34 insertions, 6 deletions
diff --git a/core.cpp b/core.cpp
index fc54013..b403cae 100644
--- a/core.cpp
+++ b/core.cpp
@@ -314,12 +314,11 @@ void Client::handleCommand(char *line, int size) {
} else if (strncmp(line, "resolve ", 8) == 0) {
DNS::makeQuery(&line[8]);
} else if (strncmp(&line[1], "ddsrv ", 6) == 0) {
- int srvID = netCore->serverCount;
- netCore->servers[srvID] = new Server(netCore);
- strcpy(netCore->servers[srvID]->ircHostname, &line[7]);
- netCore->servers[srvID]->ircPort = 1191;
- netCore->servers[srvID]->ircUseTls = (line[0] == 's');
- netCore->serverCount++;
+ Server *srv = new Server(netCore);
+ strcpy(srv->ircHostname, &line[7]);
+ srv->ircPort = 1191;
+ srv->ircUseTls = (line[0] == 's');
+ netCore->registerServer(srv);
Buffer pkt;
pkt.writeStr("Your wish is my command!");
@@ -742,6 +741,29 @@ Client *NetCore::findClientWithSessionKey(uint8_t *key) const {
return 0;
}
+int NetCore::registerServer(Server *server) {
+ if (serverCount >= SERVER_LIMIT)
+ return -1;
+
+ int id = serverCount++;
+ servers[id] = server;
+ return id;
+}
+void NetCore::deregisterServer(int id) {
+ Server *server = servers[id];
+ server->close();
+ delete server;
+
+ serverCount--;
+ servers[id] = servers[serverCount];
+}
+int NetCore::findServerID(Server *server) const {
+ for (int i = 0; i < SERVER_LIMIT; i++)
+ if (servers[i] == server)
+ return i;
+ return -1;
+}
+
int NetCore::execute() {
// prepare the listen socket
int listener = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
diff --git a/core.h b/core.h
index e259d7a..ef1ef0d 100644
--- a/core.h
+++ b/core.h
@@ -136,6 +136,12 @@ struct NetCore {
Client *findClientWithSessionKey(uint8_t *key) const;
private:
virtual Client *constructClient() = 0;
+
+public:
+ int registerServer(Server *server); // THIS FUNCTION WILL BE PROTECTED LATER
+protected:
+ void deregisterServer(int id);
+ int findServerID(Server *server) const;
};
struct Bouncer : NetCore {