#include #include "NetworkHandler.h" #include "Globals.h" NetworkHandler::NetworkHandler() : ReferenceCounter() { HINSTANCE dll = dlls->ladeDLL("KSGClient", "data/bin/KSGNetwork.dll"); if (!dll) throw "DLL not found: 'data/bin/KSGNetwork.dll'"; KSGClient::KSGNetworkCreateMain getMainClient = (KSGClient::KSGNetworkCreateMain)GetProcAddress(dll, KSGNETWORK_CREATE_MAIN); if (!getMainClient) throw "Entry point '" KSGNETWORK_CREATE_MAIN "' not found in DLL 'data/bin/KSGNetwork.dll'"; msc = getMainClient(); if (!msc) throw "Could not create Main Server Client from DLL 'data/bin/KSGNetwork.dll'"; InitDatei* iDat = new InitDatei("data/optionen.ini"); iDat->laden(); if (!iDat->zWert("ServerIP")) iDat->addWert("ServerIP", "127.0.0.1"); if (!iDat->zWert("ServerPort")) iDat->addWert("ServerPort", "4225"); iDat->speichern(); Text* ipT = iDat->zWert("ServerIP"); unsigned short port = (unsigned short)TextZuInt(iDat->zWert("ServerPort")->getText(), 10); esc = 0; if (msc->registerSSL(ipT->getText(), port)) { //esc = msc->createErhaltungServerClient(); //esc->verbinde(); } iDat->release(); fc = 0; lsc = 0; gsc = 0; } NetworkHandler::~NetworkHandler() { if (gsc) { gsc->release(); gsc = 0; } if (fc) fc->release(); if (esc) { esc->abmelden(); esc->release(); } if (lsc) { lsc->verbinde(); lsc->logout(); lsc->trenne(1); lsc->release(); } if (msc) { msc->unregister(); msc->release(); } } bool NetworkHandler::login(Framework::Text name, Framework::Text password) { if (!lsc) lsc = msc->createLoginServerClient(); else { if (gsc) { gsc->release(); gsc = 0; } lsc->logout(); } if (!lsc) return 0; lsc->verbinde(); bool ok = lsc->login(name, password); lsc->trenne(ok); if (ok) { accountId = lsc->getAccountId(); lsc->release(); lsc = 0; } return ok; } bool NetworkHandler::connect(Text ip, short port) { if (!gsc) gsc = msc->createMinigameServerClient(); if (!gsc) { std::cout << "could not create minigame server client.\n"; return 0; } Text* secret = gsc->getSecret(); if (!secret) { std::cout << "could not get secret from minigame server.\n"; return 0; } if (!fc) fc = new FactoryClient(); bool ok = fc->connect(ip, port, accountId, *secret); secret->release(); return ok; } FactoryClient* NetworkHandler::zFactoryClient() const { return fc; } bool NetworkHandler::leaveGame() { if (fc) { fc->release(); fc = 0; } return 1; }