123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- #include <InitDatei.h>
- #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)
- return 0;
- Text* secret = gsc->getSecret();
- if (!secret)
- 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;
- }
|