diff options
author | LaG1924 <12997935+LaG1924@users.noreply.github.com> | 2017-08-05 17:07:10 +0200 |
---|---|---|
committer | LaG1924 <12997935+LaG1924@users.noreply.github.com> | 2017-08-05 17:07:10 +0200 |
commit | c9c78e191dd71bacd769bbeccd58b80e4376184b (patch) | |
tree | 4da1a8500dd73dd6368fc89496dc0f428d318c5b /src/ThreadNetwork.cpp | |
parent | 2017-08-03 (diff) | |
download | AltCraft-c9c78e191dd71bacd769bbeccd58b80e4376184b.tar AltCraft-c9c78e191dd71bacd769bbeccd58b80e4376184b.tar.gz AltCraft-c9c78e191dd71bacd769bbeccd58b80e4376184b.tar.bz2 AltCraft-c9c78e191dd71bacd769bbeccd58b80e4376184b.tar.lz AltCraft-c9c78e191dd71bacd769bbeccd58b80e4376184b.tar.xz AltCraft-c9c78e191dd71bacd769bbeccd58b80e4376184b.tar.zst AltCraft-c9c78e191dd71bacd769bbeccd58b80e4376184b.zip |
Diffstat (limited to '')
-rw-r--r-- | src/ThreadNetwork.cpp | 26 |
1 files changed, 7 insertions, 19 deletions
diff --git a/src/ThreadNetwork.cpp b/src/ThreadNetwork.cpp index b97a3f0..51c8989 100644 --- a/src/ThreadNetwork.cpp +++ b/src/ThreadNetwork.cpp @@ -9,7 +9,7 @@ ThreadNetwork::~ThreadNetwork() { } void ThreadNetwork::Execute() { - bool isRunning; + state = GlobalState::InitialLoading; EventListener listener; listener.RegisterHandler(EventType::GlobalAppState, [this](EventData eventData) { @@ -17,7 +17,7 @@ void ThreadNetwork::Execute() { state = data.state; }); - listener.RegisterHandler(EventType::ConnectToServer, [this, &isRunning](EventData eventData) { + listener.RegisterHandler(EventType::ConnectToServer, [this](EventData eventData) { auto data = std::get<ConnectToServerData>(eventData); if (data.address == "" || data.port == 0) LOG(FATAL) << "NOT VALID CONNECT-TO-SERVER EVENT"; @@ -25,13 +25,14 @@ void ThreadNetwork::Execute() { LOG(ERROR) << "Already connected"; return; } - + SetGlobalState(GlobalState::Connecting); LOG(INFO) << "Connecting to server"; try { - nc = new NetworkClient(data.address, data.port, "HelloOne", isRunning); + nc = new NetworkClient(data.address, data.port, "HelloOne"); } catch (std::exception &e) { - LOG(WARNING) << "CONNECTION FAIL"; - LOG(FATAL) << "Can't connect to server: " << e.what(); + LOG(WARNING) << "Connection failed"; + EventAgregator::PushEvent(EventType::ConnectionFailed, ConnectionFailedData{e.what()}); + return; } LOG(INFO) << "Connected to server"; EventAgregator::PushEvent(EventType::ConnectionSuccessfull, ConnectionSuccessfullData{nc}); @@ -41,20 +42,7 @@ void ThreadNetwork::Execute() { EventAgregator::PushEvent(EventType::RegisterNetworkClient, RegisterNetworkClientData{nc}); }); - /*listener.RegisterHandler(EventType::SendPacket, [this](EventData eventData) { - auto data = std::get<SendPacketData>(eventData); - auto packet = data.packet; - if (nc) - nc->SendPacket(packet); - else - LOG(ERROR) << "Send packet, while not connected to server"; - });*/ - - while (state != GlobalState::Exiting) { - /*auto packet = nc ? nc->ReceivePacket() : nullptr; - if (packet != nullptr) - EventAgregator::PushEvent(EventType::ReceivePacket, ReceivePacketData{packet});*/ listener.HandleEvent(); } }
\ No newline at end of file |