-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathGameFinderViewModel.cpp
More file actions
55 lines (43 loc) · 1.52 KB
/
GameFinderViewModel.cpp
File metadata and controls
55 lines (43 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "GameFinderViewModel.h"
#include "GameSessionViewModel.h"
#include "Lockstep.h"
#include "ViewModel.h"
#include "stormancer/IClientFactory.h"
#include "gamefinder/GameFinder.hpp"
#include "gamesession/GameSession.hpp"
GameFinderViewModel::GameFinderViewModel(ClientViewModel* parent)
:parent(parent)
{
}
void GameFinderViewModel::initialize()
{
auto client = Stormancer::IClientFactory::GetClient(this->parent->id);
auto gameFinder = client->dependencyResolver().resolve<Stormancer::GameFinder::GameFinderApi>();
subscription = gameFinder->subscribeGameFound([this](Stormancer::GameFinder::GameFoundEvent evt) {
this->lastConnectionToken = evt.data.connectionToken;
});
}
void GameFinderViewModel::joinGameFound()
{
auto client = Stormancer::IClientFactory::GetClient(this->parent->id);
auto gameSession = client->dependencyResolver().resolve<Stormancer::GameSessions::GameSession>();
this->parent->isProcessing = true;
gameSession->connectToGameSession(lastConnectionToken, "", false).then([this](pplx::task<Stormancer::GameSessions::GameSessionConnectionParameters> t) {
this->parent->isProcessing = false;
try
{
auto p = t.get();
this->parent->gameSession.isHost = p.isHost;
this->parent->gameSession.lockstep->currentState = "";
Stormancer::SessionId::tryParse(p.hostSessionId, this->parent->gameSession.hostSessionId);
}
catch (std::exception& ex)
{
this->parent->lastError = ex.what();
}
});
}
bool GameFinderViewModel::isGameFound()
{
return this->lastConnectionToken != "";
}