Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions core/core-rt/NRtClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -490,12 +490,19 @@ void NRtClient::removeChatMessage(
send(msg);
}

void NRtClient::createMatch(std::function<void(const NMatch&)> successCallback, RtErrorCallback errorCallback) {
NLOG_INFO("...");

void NRtClient::createMatch(
const std::optional<std::string>& name,
std::function<void(const NMatch&)> successCallback,
RtErrorCallback errorCallback) {

NLOG_INFO("...");

::nakama::realtime::Envelope msg;

msg.mutable_match_create();
::nakama::realtime::MatchCreate* matchCreate = msg.mutable_match_create();
if (name.has_value()) {
matchCreate->set_name(*name);
}

std::shared_ptr<RtRequestContext> ctx = createReqContext(msg);

Expand Down Expand Up @@ -1125,10 +1132,10 @@ std::future<void> NRtClient::removeChatMessageAsync(const std::string& channelId
return promise->get_future();
}

std::future<NMatch> NRtClient::createMatchAsync() {
std::future<NMatch> NRtClient::createMatchAsync(const std::optional<std::string>& name) {
auto promise = std::make_shared<std::promise<NMatch>>();

createMatch(
createMatch( name,
[=](const NMatch& match) { promise->set_value(match); },
[=](const NRtError& error) { promise->set_exception(std::make_exception_ptr<NRtException>(error)); });

Expand Down
8 changes: 5 additions & 3 deletions core/core-rt/NRtClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,10 @@ class NRtClient : public NRtClientInterface {
std::function<void(const NChannelMessageAck&)> successCallback = nullptr,
RtErrorCallback errorCallback = nullptr) override;

void
createMatch(std::function<void(const NMatch&)> successCallback, RtErrorCallback errorCallback = nullptr) override;
void createMatch(
const std::optional<std::string>& name = std::nullopt,
std::function<void(const NMatch&)> successCallback = nullptr,
RtErrorCallback errorCallback = nullptr) override;

void joinMatch(
const std::string& matchId,
Expand Down Expand Up @@ -234,7 +236,7 @@ class NRtClient : public NRtClientInterface {

std::future<void> removeChatMessageAsync(const std::string& channelId, const std::string& messageId) override;

std::future<NMatch> createMatchAsync() override;
std::future<NMatch> createMatchAsync(const std::optional<std::string>& name = std::nullopt) override;

std::future<NMatch> joinMatchAsync(const std::string& matchId, const NStringMap& metadata) override;

Expand Down
19 changes: 19 additions & 0 deletions integrationtests/src/realtime/test_match.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,27 @@ void test_rt_matchmaker() {
test2.stopTest(true);
}

void test_rt_create_match_with_name() {
const bool threadedTick = true;
NTest test3(__func__, threadedTick);

test3.runTest();

NSessionPtr session = test3.client->authenticateCustomAsync(TestGuid::newGuid(), std::string(), true).get();
bool createStatus = false;
test3.rtClient->connectAsync(session, createStatus, NTest::RtProtocol).get();

NMatch match1 = test3.rtClient->createMatchAsync("success").get();
NMatch match2 = test3.rtClient->createMatchAsync("success").get();

test3.stopTest(match1.matchId == match2.matchId);

NLOG_INFO("stopped create match");
}

void test_rt_match() {
test_rt_create_match();
test_rt_create_match_with_name();
test_rt_matchmaker();
}

Expand Down
5 changes: 3 additions & 2 deletions interface/include/nakama-cpp/realtime/NRtClientInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,8 @@ NAKAMA_NAMESPACE_BEGIN
* Create a multiplayer match on the server.
*/
virtual void createMatch(
std::function<void(const NMatch&)> successCallback,
const std::optional<std::string>& name = std::nullopt,
std::function<void(const NMatch&)> successCallback = nullptr,
RtErrorCallback errorCallback = nullptr
) = 0;

Expand Down Expand Up @@ -523,7 +524,7 @@ NAKAMA_NAMESPACE_BEGIN
/**
* Create a multiplayer match on the server.
*/
virtual std::future<NMatch> createMatchAsync() = 0;
virtual std::future<NMatch> createMatchAsync(const std::optional<std::string>& name = std::nullopt) = 0;

/**
* Join a multiplayer match by ID.
Expand Down
Loading