in GomokuClient/GomokuClient/MatchController.cpp [47:99]
void MatchController::RequestMatch()
{
if (mMatchStarted)
return;
json::value postData;
postData[L"PlayerName"] = json::value::string(s2ws(GGuiController->GetPlayerName()));
postData[L"PlayerPass"] = json::value::string(s2ws(GGuiController->GetPlayerPassword()));
auto reqEndpoint = s2ws(mMatchApiEndpoint) + std::wstring(L"/matchrequest");
http_client client(reqEndpoint);
client.request(methods::POST, L"", postData.serialize().c_str(), L"application/json").then([this](http_response response) {
if (response.status_code() == status_codes::OK)
{
json::value jsonValue = response.extract_json().get();
mMatchStarted = true;
mMatchTicketId = ws2s(jsonValue[L"TicketId"].serialize());
mMatchTicketId.erase(0, 1);
mMatchTicketId.erase(mMatchTicketId.size() - 1);
GGuiController->OnMatchWait(true);
return true;
}
GGuiController->OnMatchWait(false);
return false;
}).then([this](bool isOk) {
if (isOk)
{
while (true)
{
Sleep(1000);
if (CheckMatchStatus())
{
GGuiController->OnMatchComplete();
break;
}
}
}
});
}