diff options
Diffstat (limited to '')
-rwxr-xr-x | build.sh | 2 | ||||
-rw-r--r-- | client.cpp | 3 | ||||
-rw-r--r-- | core.h | 29 | ||||
-rw-r--r-- | ircserver.cpp | 9 | ||||
-rw-r--r-- | mobileclient.cpp | 14 | ||||
-rw-r--r-- | server.cpp | 16 |
6 files changed, 55 insertions, 18 deletions
@@ -1,7 +1,7 @@ #!/bin/sh mkdir -p binary -NETCODE="socketcommon.cpp client.cpp mobileclient.cpp server.cpp netcore.cpp" +NETCODE="socketcommon.cpp client.cpp mobileclient.cpp server.cpp ircserver.cpp netcore.cpp" SOURCES="$NETCODE main.cpp dns.cpp" FLAGS="-std=c++11 -lgnutls -pthread -g" @@ -166,12 +166,13 @@ void Client::handlePacket(Packet::Type type, char *data, int size) { if (!isNullSessionKey(reqKey)) { printf("[fd=%d] Trying to resume session...", sock); - printf("(last they received = %d, last we sent = %d)\n", lastReceivedByClient, nextPacketID - 1); + printf("(last they received = %d)\n", lastReceivedByClient); Client *other = netCore->findClientWithSessionKey(reqKey); printf("[fd=%d] Got client %p\n", sock, other); if (other && other->authState == AS_AUTHED) { + printf("Valid: last packet we sent = %d\n", other->nextPacketID - 1); // Yep, we can go! other->resumeSession(this, lastReceivedByClient); return; @@ -139,15 +139,18 @@ private: }; struct Server : SocketRWCommon { - char ircHostname[256]; - int ircPort; + int port; + bool useTls; + int dnsQueryId; - bool ircUseTls; Server(NetCore *_netCore); ~Server(); - void beginConnect(); +protected: + void connect(const char *hostname, int _port, bool _useTls); + +public: void tryConnectPhase(); void connectionSuccessful(); @@ -158,6 +161,24 @@ private: void handleLine(char *line, int size); }; +struct IRCNetworkConfig { + char hostname[512]; + char nickname[128]; + char realname[128]; + char password[128]; + int port; + bool useTls; +}; + +struct IRCServer : Server { + Bouncer *bouncer; + IRCNetworkConfig config; + + IRCServer(Bouncer *_bouncer); + + void connect(); +}; + struct NetCore { NetCore(); diff --git a/ircserver.cpp b/ircserver.cpp new file mode 100644 index 0000000..94456dc --- /dev/null +++ b/ircserver.cpp @@ -0,0 +1,9 @@ +#include "core.h" + +IRCServer::IRCServer(Bouncer *_bouncer) : Server(_bouncer) { + bouncer = _bouncer; +} + +void IRCServer::connect() { + Server::connect(config.hostname, config.port, config.useTls); +} diff --git a/mobileclient.cpp b/mobileclient.cpp index d7930a1..2377a35 100644 --- a/mobileclient.cpp +++ b/mobileclient.cpp @@ -1,6 +1,7 @@ #include "core.h" MobileClient::MobileClient(Bouncer *_bouncer) : Client(_bouncer) { + bouncer = _bouncer; } void MobileClient::sessionStartEvent() { @@ -33,11 +34,11 @@ void MobileClient::handleDebugCommand(char *line, int size) { } else if (strcmp(line, "quit") == 0) { netCore->quitFlag = true; } else if (strncmp(&line[1], "ddsrv ", 6) == 0) { - Server *srv = new Server(netCore); - strcpy(srv->ircHostname, &line[7]); - srv->ircPort = 1191; - srv->ircUseTls = (line[0] == 's'); - netCore->registerServer(srv); + IRCServer *srv = new IRCServer(bouncer); + strcpy(srv->config.hostname, &line[7]); + srv->config.port = 1191; + srv->config.useTls = (line[0] == 's'); + bouncer->registerServer(srv); Buffer pkt; pkt.writeStr("Your wish is my command!"); @@ -46,7 +47,8 @@ void MobileClient::handleDebugCommand(char *line, int size) { } else if (strncmp(line, "connsrv", 7) == 0) { int sid = line[7] - '0'; - netCore->servers[sid]->beginConnect(); + // ugly hack, fuck casting, will fix later + ((IRCServer*)netCore->servers[sid])->connect(); } else if (line[0] >= '0' && line[0] <= '9') { int sid = line[0] - '0'; netCore->servers[sid]->outputBuf.append(&line[1], size - 1); @@ -3,7 +3,6 @@ Server::Server(NetCore *_netCore) : SocketRWCommon(_netCore) { dnsQueryId = -1; - ircUseTls = false; } Server::~Server() { if (dnsQueryId != -1) @@ -46,10 +45,13 @@ void Server::processReadBuffer() { -void Server::beginConnect() { +void Server::connect(const char *hostname, int _port, bool _useTls) { if (state == CS_DISCONNECTED) { + port = _port; + useTls = _useTls; + DNS::closeQuery(dnsQueryId); // just in case - dnsQueryId = DNS::makeQuery(ircHostname); + dnsQueryId = DNS::makeQuery(hostname); if (dnsQueryId == -1) { // TODO: better error reporting @@ -91,10 +93,10 @@ void Server::tryConnectPhase() { // We have our non-blocking socket, let's try connecting! sockaddr_in outAddr; outAddr.sin_family = AF_INET; - outAddr.sin_port = htons(ircPort); + outAddr.sin_port = htons(port); outAddr.sin_addr.s_addr = result.s_addr; - if (connect(sock, (sockaddr *)&outAddr, sizeof(outAddr)) == -1) { + if (::connect(sock, (sockaddr *)&outAddr, sizeof(outAddr)) == -1) { if (errno == EINPROGRESS) { state = CS_WAITING_CONNECT; } else { @@ -117,7 +119,7 @@ void Server::connectionSuccessful() { outputBuf.clear(); // Do we need to do any TLS junk? - if (ircUseTls) { + if (useTls) { int initRet = gnutls_init(&tls, GNUTLS_CLIENT); if (initRet != GNUTLS_E_SUCCESS) { printf("[Server::connectionSuccessful] gnutls_init borked\n"); @@ -147,3 +149,5 @@ void Server::close() { dnsQueryId = -1; } } + + |