diff options
author | Treeki <treeki@gmail.com> | 2014-01-20 09:53:20 +0100 |
---|---|---|
committer | Treeki <treeki@gmail.com> | 2014-01-20 09:53:20 +0100 |
commit | 0c114045d4a0b16db8c00e710708d7d20a54bf6a (patch) | |
tree | 919fc52de5161459f0e90b7e9f3aa672f6111d64 /core.cpp | |
parent | 1fb18cd2ef80709681e2a4e4b06624ad9e8dc9b2 (diff) | |
download | bounce4-0c114045d4a0b16db8c00e710708d7d20a54bf6a.tar.gz bounce4-0c114045d4a0b16db8c00e710708d7d20a54bf6a.zip |
add server management functions to NetCore
Diffstat (limited to '')
-rw-r--r-- | core.cpp | 34 |
1 files changed, 28 insertions, 6 deletions
@@ -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); |