From 552918ebe4c496d7606dc4195836dd9d95c560fb Mon Sep 17 00:00:00 2001 From: Wania Date: Tue, 14 Jul 2026 18:48:12 +0100 Subject: [PATCH] Add Create Match with Name (#77) --- core/core-rt/NRtClient.cpp | 19 +++++++++++++------ core/core-rt/NRtClient.h | 8 +++++--- integrationtests/src/realtime/test_match.cpp | 19 +++++++++++++++++++ .../nakama-cpp/realtime/NRtClientInterface.h | 5 +++-- 4 files changed, 40 insertions(+), 11 deletions(-) diff --git a/core/core-rt/NRtClient.cpp b/core/core-rt/NRtClient.cpp index 12927d509..68a9e905b 100644 --- a/core/core-rt/NRtClient.cpp +++ b/core/core-rt/NRtClient.cpp @@ -490,12 +490,19 @@ void NRtClient::removeChatMessage( send(msg); } -void NRtClient::createMatch(std::function successCallback, RtErrorCallback errorCallback) { - NLOG_INFO("..."); - +void NRtClient::createMatch( + const std::optional& name, + std::function 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 ctx = createReqContext(msg); @@ -1125,10 +1132,10 @@ std::future NRtClient::removeChatMessageAsync(const std::string& channelId return promise->get_future(); } -std::future NRtClient::createMatchAsync() { +std::future NRtClient::createMatchAsync(const std::optional& name) { auto promise = std::make_shared>(); - createMatch( + createMatch( name, [=](const NMatch& match) { promise->set_value(match); }, [=](const NRtError& error) { promise->set_exception(std::make_exception_ptr(error)); }); diff --git a/core/core-rt/NRtClient.h b/core/core-rt/NRtClient.h index 24ac4de0c..62c209a41 100644 --- a/core/core-rt/NRtClient.h +++ b/core/core-rt/NRtClient.h @@ -92,8 +92,10 @@ class NRtClient : public NRtClientInterface { std::function successCallback = nullptr, RtErrorCallback errorCallback = nullptr) override; - void - createMatch(std::function successCallback, RtErrorCallback errorCallback = nullptr) override; + void createMatch( + const std::optional& name = std::nullopt, + std::function successCallback = nullptr, + RtErrorCallback errorCallback = nullptr) override; void joinMatch( const std::string& matchId, @@ -234,7 +236,7 @@ class NRtClient : public NRtClientInterface { std::future removeChatMessageAsync(const std::string& channelId, const std::string& messageId) override; - std::future createMatchAsync() override; + std::future createMatchAsync(const std::optional& name = std::nullopt) override; std::future joinMatchAsync(const std::string& matchId, const NStringMap& metadata) override; diff --git a/integrationtests/src/realtime/test_match.cpp b/integrationtests/src/realtime/test_match.cpp index 2ff33fb30..128b350b6 100644 --- a/integrationtests/src/realtime/test_match.cpp +++ b/integrationtests/src/realtime/test_match.cpp @@ -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(); } diff --git a/interface/include/nakama-cpp/realtime/NRtClientInterface.h b/interface/include/nakama-cpp/realtime/NRtClientInterface.h index e84a7274d..040ab2940 100644 --- a/interface/include/nakama-cpp/realtime/NRtClientInterface.h +++ b/interface/include/nakama-cpp/realtime/NRtClientInterface.h @@ -245,7 +245,8 @@ NAKAMA_NAMESPACE_BEGIN * Create a multiplayer match on the server. */ virtual void createMatch( - std::function successCallback, + const std::optional& name = std::nullopt, + std::function successCallback = nullptr, RtErrorCallback errorCallback = nullptr ) = 0; @@ -523,7 +524,7 @@ NAKAMA_NAMESPACE_BEGIN /** * Create a multiplayer match on the server. */ - virtual std::future createMatchAsync() = 0; + virtual std::future createMatchAsync(const std::optional& name = std::nullopt) = 0; /** * Join a multiplayer match by ID.