├── .dockerignore ├── .gitattributes ├── .github ├── actions │ ├── build-library-and-upload │ │ └── action.yml │ ├── build-test-and-run │ │ └── action.yml │ ├── handle-failure │ │ └── action.yml │ ├── setup-ubuntu │ │ └── action.yml │ └── setup-vcpkg │ │ └── action.yml └── workflows │ ├── build_all.yml │ ├── build_android.yml │ ├── build_ios.yml │ ├── build_linux.yml │ ├── build_osx.yml │ ├── build_windows.yml │ ├── test_all.yml │ ├── test_linux.yml │ ├── test_osx.yml │ └── test_windows.yml ├── .gitignore ├── CHANGELOG.md ├── CMakeLists.txt ├── CMakePresets.json ├── LICENSE.txt ├── README.md ├── RELEASEINST.md ├── android ├── app │ ├── build.gradle │ └── src │ │ └── main │ │ ├── AndroidManifest.xml │ │ └── java │ │ └── com │ │ └── heroiclabs │ │ └── nakamasdk │ │ └── AndroidCA.java ├── gradle.properties ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle ├── cmake ├── compilerFlags.cmake ├── linkerFlags.cmake ├── localCompilerFlags.cmake ├── platformSupport.cmake └── triplets │ ├── arm-neon-android-heroic.cmake │ ├── arm64-android-heroic.cmake │ ├── arm64-ios-heroic.cmake │ ├── arm64-osx-heroic.cmake │ ├── arm64-windows-static-heroic.cmake │ ├── feature-lto.cmake │ ├── feature-visibility-hidden.cmake │ ├── x64-android-heroic.cmake │ ├── x64-iphonesimulator-heroic.cmake │ ├── x64-linux-dynamic-release.cmake │ ├── x64-linux-heroic.cmake │ ├── x64-osx-heroic.cmake │ ├── x64-windows-static-heroic.cmake │ └── x86-windows-release.cmake ├── core ├── CMakeLists.txt ├── buildProtoFiles.cmake ├── common │ ├── BaseClient.cpp │ ├── BaseClient.h │ ├── CMakeLists.txt │ ├── DataHelper.cpp │ ├── DataHelper.h │ ├── DefaultSession.cpp │ ├── DefaultSession.h │ ├── NError.cpp │ ├── NRtError.cpp │ ├── NUtils.cpp │ ├── RapidjsonHelper.h │ ├── StrUtil.cpp │ ├── StrUtil.h │ └── Version.cpp.in ├── core-grpc │ ├── CMakeLists.txt │ ├── GrpcClient.cpp │ └── GrpcClient.h ├── core-rest │ ├── CMakeLists.txt │ ├── RestClient.cpp │ ├── RestClient.h │ └── grpc_status_code_enum.h ├── core-rt │ ├── CMakeLists.txt │ ├── NRtClient.cpp │ ├── NRtClient.h │ ├── NRtClientProtocolInterface.h │ ├── NRtClientProtocol_Json.cpp │ ├── NRtClientProtocol_Json.h │ ├── NRtClientProtocol_Protobuf.cpp │ └── NRtClientProtocol_Protobuf.h └── src │ ├── CMakeLists.txt │ ├── log │ ├── NConsoleLogSink.cpp │ └── NLogger.cpp │ ├── roots_pem.cpp │ └── roots_pem.h ├── example ├── CMakeLists.txt ├── CMakePresets.json ├── README.md ├── example.entitlements ├── example.plist ├── main.cpp ├── vcpkg-configuration.json └── vcpkg.json ├── factory ├── CMakeLists.txt ├── ClientFactory.cpp └── NWebsocketsFactory.cpp ├── impl ├── android │ ├── AndroidCA.cpp │ ├── AndroidCA.h │ └── CMakeLists.txt ├── httpCppRest │ ├── CMakeLists.txt │ ├── CppRestUtils.h │ ├── NHttpClientCppRest.cpp │ └── NHttpClientCppRest.h ├── httpCurl │ ├── CMakeLists.txt │ ├── NHttpClientLibCurl.cpp │ ├── NHttpClientLibCurl.h │ ├── NHttpClientLibCurlContext.cpp │ └── NHttpClientLibCurlContext.h ├── httpLibHttpClient │ ├── CMakeLists.txt │ ├── NHttpClientLibHC.cpp │ └── NHttpClientLibHC.h ├── wsCppRest │ ├── CMakeLists.txt │ ├── CppRestUtils.h │ ├── NWebsocketCppRest.cpp │ └── NWebsocketCppRest.h ├── wsLibHttpClient │ ├── CMakeLists.txt │ ├── NWebsocketLibHC.cpp │ └── NWebsocketLibHC.h └── wsWslay │ ├── CMakeLists.txt │ ├── NWebsocketWslay.cpp │ ├── NWebsocketWslay.h │ ├── WslayIOCurl.h │ └── sha1.h ├── interface ├── CMakeLists.txt ├── config.h.in └── include │ └── nakama-cpp │ ├── ClientFactory.h │ ├── NClientInterface.h │ ├── NError.h │ ├── NException.h │ ├── NExport.h │ ├── NHttpTransportInterface.h │ ├── NPlatformParams.h │ ├── NSessionInterface.h │ ├── NTypes.h │ ├── NUtils.h │ ├── Nakama.h │ ├── NakamaVersion.h │ ├── URLParts.h │ ├── data │ ├── NAccount.h │ ├── NAccountDevice.h │ ├── NChannelMessage.h │ ├── NChannelMessageList.h │ ├── NFriend.h │ ├── NFriendList.h │ ├── NGroup.h │ ├── NGroupList.h │ ├── NGroupUser.h │ ├── NGroupUserList.h │ ├── NLeaderboardRecord.h │ ├── NLeaderboardRecordList.h │ ├── NMatch.h │ ├── NMatchList.h │ ├── NNotification.h │ ├── NNotificationList.h │ ├── NRpc.h │ ├── NStorageObject.h │ ├── NStorageObjectAck.h │ ├── NStorageObjectId.h │ ├── NStorageObjectList.h │ ├── NStorageObjectWrite.h │ ├── NStoragePermissions.h │ ├── NTournament.h │ ├── NTournamentList.h │ ├── NTournamentRecordList.h │ ├── NUser.h │ ├── NUserGroup.h │ ├── NUserGroupList.h │ └── NUsers.h │ ├── log │ ├── NConsoleLogSink.h │ ├── NLogSinkInterface.h │ └── NLogger.h │ └── realtime │ ├── NRtClientDisconnectInfo.h │ ├── NRtClientInterface.h │ ├── NRtClientListenerInterface.h │ ├── NRtDefaultClientListener.h │ ├── NRtTransportInterface.h │ ├── NWebsocketsFactory.h │ ├── rtdata │ ├── NChannel.h │ ├── NChannelMessageAck.h │ ├── NChannelPresenceEvent.h │ ├── NMatchData.h │ ├── NMatchPresenceEvent.h │ ├── NMatchmakerMatched.h │ ├── NMatchmakerTicket.h │ ├── NParty.h │ ├── NPartyClose.h │ ├── NPartyData.h │ ├── NPartyJoinRequest.h │ ├── NPartyLeader.h │ ├── NPartyMatchmakerTicket.h │ ├── NPartyPresenceEvent.h │ ├── NRtError.h │ ├── NRtException.h │ ├── NStatus.h │ ├── NStatusPresenceEvent.h │ ├── NStream.h │ ├── NStreamData.h │ ├── NStreamPresenceEvent.h │ └── NUserPresence.h │ └── wslay │ └── WslayIOInterface.h ├── nakama-sdk-config.cmake.in ├── nakama-sdk-preconfig.cmake.in ├── scripts ├── Dockerfile └── build.sh ├── test ├── CMakeLists.txt ├── CMakePresets.json ├── README.md ├── android │ ├── .gitattributes │ ├── .gitignore │ ├── build.gradle │ ├── deploy.sh │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ ├── settings.gradle │ └── src │ │ └── main │ │ ├── AndroidManifest.xml │ │ └── java │ │ └── com │ │ └── heroiclabs │ │ └── nakamatest │ │ └── MainActivity.java ├── include │ └── NTestLib.h ├── main.cpp ├── nakama-test-config.cmake.in ├── src │ ├── NTest.cpp │ ├── NTest.h │ ├── NTestLib.cpp │ ├── TestGuid.cpp │ ├── TestGuid.h │ ├── globals.cpp │ ├── globals.h │ ├── realtime │ │ ├── test_authoritative_match.cpp │ │ ├── test_chat.cpp │ │ ├── test_lifecycle.cpp │ │ ├── test_match.cpp │ │ ├── test_notifications.cpp │ │ ├── test_parties.cpp │ │ ├── test_realtime.cpp │ │ ├── test_rpc.cpp │ │ └── test_tournament.cpp │ ├── test_authentication.cpp │ ├── test_disconnect.cpp │ ├── test_errors.cpp │ ├── test_friends.cpp │ ├── test_getAccount.cpp │ ├── test_groups.cpp │ ├── test_internals.cpp │ ├── test_listMatches.cpp │ ├── test_restoreSession.cpp │ └── test_storage.cpp ├── test.plist ├── vcpkg-configuration.json └── vcpkg.json ├── vcpkg-configuration.json ├── vcpkg.json └── version.cmake /.dockerignore: -------------------------------------------------------------------------------- 1 | /build 2 | /out 3 | /cmake/vcpkg/buildtrees/ 4 | /cmake/vcpkg/build*/ 5 | /cmake/vcpkg/downloads/ 6 | /cmake/vcpkg/installed*/ 7 | /cmake/vcpkg/packages/ 8 | /cmake/vcpkg/scripts/buildsystems/tmp/ 9 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Ensure shell script uses LF. 2 | Dockerfile eol=lf 3 | *.sh eol=lf -------------------------------------------------------------------------------- /.github/actions/build-test-and-run/action.yml: -------------------------------------------------------------------------------- 1 | name: 'Build test and run' 2 | description: 'Build a test for nakama-cpp and run it' 3 | inputs: 4 | preset: 5 | description: 'Configure preset name' 6 | required: true 7 | nakama-cpp-path: 8 | description: 'Relative path under $GITHUB_WORKSPACE to the nakama-cpp repository' 9 | required: true 10 | testrunner-pat: 11 | description: 'PAT to access the private Nakama testrunner' 12 | required: true 13 | build-type: 14 | description: The build type. 15 | required: true 16 | native-tool-options: 17 | description: 'Flags to pass to the underlying build system used by the CMake generator.' 18 | required: false 19 | 20 | runs: 21 | using: "composite" 22 | steps: 23 | - name: Checkout nakama-client-testrunner 24 | uses: actions/checkout@v2 25 | with: 26 | repository: heroiclabs/nakama-client-testrunner 27 | token: ${{ inputs.testrunner-pat }} 28 | path: nakama-client-testrunner 29 | - name: Start docker containers for nakama-client-testrunner 30 | run: | 31 | docker-compose up -d 32 | working-directory: nakama-client-testrunner 33 | shell: bash 34 | - id: build 35 | run: | 36 | cmake --preset ${{ inputs.preset }} -DBUILD_SHARED_NAKAMA_SDK=ON 37 | cmake --build ./build/${{ inputs.preset }} --config ${{ inputs.build-type }} --target install run -- ${{ inputs.native-tool-options }} 38 | shell: bash 39 | working-directory: ${{ inputs.nakama-cpp-path }}/test 40 | -------------------------------------------------------------------------------- /.github/actions/setup-ubuntu/action.yml: -------------------------------------------------------------------------------- 1 | name: 'Setup Ubuntu' 2 | description: 'Sets up prereqs for all ubuntu machines' 3 | runs: 4 | using: "composite" 5 | steps: 6 | - run: | 7 | install_ninja() { 8 | ( 9 | mkdir -p ~/bin 10 | cd /tmp 11 | curl -L -O https://github.com/ninja-build/ninja/releases/download/v1.11.0/ninja-linux.zip 12 | unzip ninja-linux.zip 13 | mv ninja /usr/local/bin/ 14 | ) 15 | ninja --version 2>/dev/null 16 | } 17 | 18 | # vcpkg wants mono, make sure it finds one 19 | # see: https://github.com/microsoft/vcpkg/issues/25585 20 | ensure_mono() { 21 | type -p mono || { 22 | # mono not found, lets try dotnet 23 | type -p dotnet || { echo "ERROR: neither mono nor dotnet found"; exit 1; } 24 | ln -s "$(type -p dotnet)" ~/bin/ 25 | } 26 | mono --version >/dev/null 27 | } 28 | 29 | ninja --version 2>/dev/null || install_ninja 30 | ensure_mono 31 | shell: bash 32 | 33 | -------------------------------------------------------------------------------- /.github/actions/setup-vcpkg/action.yml: -------------------------------------------------------------------------------- 1 | name: 'Setup Vcpkg' 2 | description: 'Clone and bootstrap vcpkg' 3 | inputs: 4 | vcpkg-path: 5 | description: 'Relative path under $GITHUB_WORKSPACE to the vcpkg repository' 6 | required: true 7 | github_token: 8 | description: 'github token' 9 | required: true 10 | runs: 11 | using: "composite" 12 | steps: 13 | - uses: actions/checkout@v3 14 | with: 15 | path: ${{ inputs.vcpkg-path }} 16 | repository: microsoft/vcpkg 17 | fetch-depth: 0 18 | - if: runner.os != 'Windows' 19 | run: "echo VCPKG_ROOT=${{ github.workspace }}/${{ inputs.vcpkg-path }} >> $GITHUB_ENV" 20 | shell: bash 21 | working-directory: ${{ inputs.vcpkg-path }} 22 | - if: runner.os == 'Windows' 23 | run: | 24 | echo "VCPKG_ROOT=${{ github.workspace }}/${{ inputs.vcpkg-path }}" | Out-File -FilePath $env:GITHUB_ENV -Append 25 | shell: powershell 26 | working-directory: ${{ inputs.vcpkg-path }} 27 | - if: runner.os == 'Linux' 28 | run: sudo eatmydata "./bootstrap-vcpkg.sh" 29 | shell: bash 30 | working-directory: ${{ inputs.vcpkg-path }} 31 | - if: runner.os == 'Windows' 32 | run: .\bootstrap-vcpkg.bat 33 | shell: powershell 34 | working-directory: ${{ inputs.vcpkg-path }} 35 | - name: Setup NuGet API key 36 | shell: bash 37 | run: > 38 | $( type -p mono || :) `vcpkg fetch nuget | tail -n 1` 39 | setapikey "${{ inputs.github_token }}" 40 | -source "https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json" 41 | working-directory: ${{ inputs.vcpkg-path }} 42 | - run: echo "VCPKG_BINARY_SOURCES=clear;nuget,GitHub,readwrite" >> $GITHUB_ENV 43 | shell: bash 44 | - name: 'Setup NuGet Credentials' 45 | shell: bash 46 | run: > 47 | mono=$( type -p mono || :); 48 | nuget="$mono $(vcpkg fetch nuget | tail -n 1)"; 49 | $nuget sources list | grep -q ${{ github.repository_owner }} || $nuget sources add 50 | -source "https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json" 51 | -storepasswordincleartext 52 | -name "GitHub" 53 | -username "heroiclabs" 54 | -password "${{ inputs.github_token }}" 55 | working-directory: ${{ inputs.vcpkg-path }} 56 | -------------------------------------------------------------------------------- /.github/workflows/build_all.yml: -------------------------------------------------------------------------------- 1 | name: Build All 2 | on: [workflow_dispatch] 3 | jobs: 4 | build_android: 5 | uses: ./.github/workflows/build_android.yml 6 | build_ios: 7 | uses: ./.github/workflows/build_ios.yml 8 | build_linux: 9 | uses: ./.github/workflows/build_linux.yml 10 | build_osx: 11 | uses: ./.github/workflows/build_osx.yml 12 | build_windows: 13 | uses: ./.github/workflows/build_windows.yml 14 | -------------------------------------------------------------------------------- /.github/workflows/build_android.yml: -------------------------------------------------------------------------------- 1 | name: Build Android 2 | on: [workflow_call, workflow_dispatch] 3 | jobs: 4 | build_android: 5 | timeout-minutes: 30 6 | strategy: 7 | matrix: 8 | preset: ["android-arm64-v8a-host_linux-x64", "android-x64-host_linux-x64", "android-armeabi-v7a-host_linux-x64"] 9 | build-type: [MinSizeRel] 10 | runs-on: ubuntu-22.04 11 | steps: 12 | - uses: actions/checkout@v3 13 | with: 14 | path: nakama-cpp 15 | - uses: ./nakama-cpp/.github/actions/setup-vcpkg 16 | with: 17 | github_token: ${{ secrets.github_token }} 18 | vcpkg-path: vcpkg 19 | - uses: ./nakama-cpp/.github/actions/setup-ubuntu 20 | - uses: ./nakama-cpp/.github/actions/build-library-and-upload 21 | with: 22 | nakama-cpp-path: nakama-cpp 23 | preset: ${{ matrix.preset }} 24 | build-type: ${{ matrix.build-type }} 25 | - if: failure() 26 | uses: ./nakama-cpp/.github/actions/handle-failure 27 | with: 28 | nakama-cpp-path: nakama-cpp 29 | vcpkg-path: vcpkg -------------------------------------------------------------------------------- /.github/workflows/build_ios.yml: -------------------------------------------------------------------------------- 1 | name: Build iOS 2 | on: [workflow_call, workflow_dispatch] 3 | jobs: 4 | build_ios: 5 | timeout-minutes: 30 6 | strategy: 7 | matrix: 8 | preset: ["ios-arm64-host_x64", "iphonesimulator-x64-host_x64"] 9 | build-type: [MinSizeRel] 10 | runs-on: macos-12 11 | steps: 12 | - uses: actions/checkout@v3 13 | with: 14 | path: nakama-cpp 15 | - run: | 16 | brew install pkg-config 17 | shell: bash 18 | - uses: ./nakama-cpp/.github/actions/setup-vcpkg 19 | with: 20 | github_token: ${{ secrets.github_token }} 21 | vcpkg-path: vcpkg 22 | - uses: ./nakama-cpp/.github/actions/build-library-and-upload 23 | with: 24 | nakama-cpp-path: nakama-cpp 25 | preset: ${{ matrix.preset }} 26 | build-type: ${{ matrix.build-type }} 27 | - if: failure() 28 | uses: ./nakama-cpp/.github/actions/handle-failure 29 | with: 30 | nakama-cpp-path: nakama-cpp 31 | vcpkg-path: vcpkg 32 | 33 | -------------------------------------------------------------------------------- /.github/workflows/build_linux.yml: -------------------------------------------------------------------------------- 1 | name: Build Linux 2 | on: [workflow_call, workflow_dispatch] 3 | jobs: 4 | build_linux: 5 | timeout-minutes: 30 6 | strategy: 7 | matrix: 8 | build-type: [MinSizeRel] 9 | runs-on: ubuntu-20.04 10 | steps: 11 | - uses: actions/checkout@v3 12 | with: 13 | path: nakama-cpp 14 | - uses: ./nakama-cpp/.github/actions/setup-ubuntu 15 | - uses: ./nakama-cpp/.github/actions/setup-vcpkg 16 | with: 17 | github_token: ${{ secrets.github_token }} 18 | vcpkg-path: vcpkg 19 | - uses: ./nakama-cpp/.github/actions/build-library-and-upload 20 | with: 21 | nakama-cpp-path: nakama-cpp 22 | preset: linux-amd64 23 | build-type: ${{ matrix.build-type }} 24 | - if: failure() 25 | uses: ./nakama-cpp/.github/actions/handle-failure 26 | with: 27 | nakama-cpp-path: nakama-cpp 28 | vcpkg-path: vcpkg -------------------------------------------------------------------------------- /.github/workflows/build_osx.yml: -------------------------------------------------------------------------------- 1 | name: Build OSX 2 | on: [workflow_call, workflow_dispatch] 3 | jobs: 4 | build_osx: 5 | timeout-minutes: 30 6 | strategy: 7 | matrix: 8 | preset: ["macosx-x64-host_x64", "macosx-arm64-host_x64"] 9 | build-type: [MinSizeRel] 10 | runs-on: macos-12 11 | steps: 12 | - uses: actions/checkout@v3 13 | with: 14 | path: nakama-cpp 15 | - run: | 16 | brew install pkg-config 17 | shell: bash 18 | - uses: ./nakama-cpp/.github/actions/setup-vcpkg 19 | with: 20 | github_token: ${{ secrets.github_token }} 21 | vcpkg-path: vcpkg 22 | - uses: ./nakama-cpp/.github/actions/build-library-and-upload 23 | with: 24 | nakama-cpp-path: nakama-cpp 25 | preset: ${{ matrix.preset }} 26 | build-type: ${{ matrix.build-type }} 27 | - if: failure() 28 | uses: ./nakama-cpp/.github/actions/handle-failure 29 | with: 30 | nakama-cpp-path: nakama-cpp 31 | vcpkg-path: vcpkg -------------------------------------------------------------------------------- /.github/workflows/build_windows.yml: -------------------------------------------------------------------------------- 1 | name: Build Windows 2 | on: [workflow_call, workflow_dispatch] 3 | jobs: 4 | build_windows: 5 | timeout-minutes: 30 6 | strategy: 7 | matrix: 8 | build-type: [MinSizeRel, Debug] 9 | preset: [win-x64, win-x86] 10 | runs-on: windows-latest 11 | steps: 12 | - uses: actions/checkout@v3 13 | with: 14 | path: nakama-cpp 15 | - uses: ./nakama-cpp/.github/actions/setup-vcpkg 16 | with: 17 | github_token: ${{ secrets.github_token }} 18 | vcpkg-path: vcpkg 19 | - uses: ./nakama-cpp/.github/actions/build-library-and-upload 20 | with: 21 | nakama-cpp-path: nakama-cpp 22 | preset: ${{ matrix.preset }} 23 | build-type: ${{ matrix.build-type }} 24 | - if: failure() 25 | uses: ./nakama-cpp/.github/actions/handle-failure 26 | with: 27 | nakama-cpp-path: nakama-cpp 28 | vcpkg-path: vcpkg -------------------------------------------------------------------------------- /.github/workflows/test_all.yml: -------------------------------------------------------------------------------- 1 | name: Test All 2 | on: [workflow_dispatch] 3 | jobs: 4 | test_linux: 5 | uses: ./.github/workflows/test_linux.yml 6 | secrets: inherit 7 | test_osx: 8 | uses: ./.github/workflows/test_osx.yml 9 | secrets: inherit 10 | test_windows: 11 | uses: ./.github/workflows/test_windows.yml 12 | secrets: inherit 13 | -------------------------------------------------------------------------------- /.github/workflows/test_linux.yml: -------------------------------------------------------------------------------- 1 | name: Test Linux 2 | on: [workflow_dispatch, workflow_call, pull_request] 3 | jobs: 4 | test_linux: 5 | timeout-minutes: 30 6 | strategy: 7 | matrix: 8 | build-type: [MinSizeRel] 9 | runs-on: ubuntu-20.04 10 | steps: 11 | - uses: actions/checkout@v3 12 | with: 13 | path: nakama-cpp 14 | - uses: ./nakama-cpp/.github/actions/setup-ubuntu 15 | - uses: ./nakama-cpp/.github/actions/setup-vcpkg 16 | with: 17 | github_token: ${{ secrets.github_token }} 18 | vcpkg-path: vcpkg 19 | - uses: ./nakama-cpp/.github/actions/build-library-and-upload 20 | with: 21 | nakama-cpp-path: nakama-cpp 22 | preset: linux-amd64 23 | build-type: ${{ matrix.build-type }} 24 | - uses: ./nakama-cpp/.github/actions/build-test-and-run 25 | with: 26 | nakama-cpp-path: nakama-cpp 27 | preset: linux-amd64 28 | testrunner-pat: ${{ secrets.GH_PAT }} 29 | build-type: ${{ matrix.build-type }} 30 | - if: failure() 31 | uses: ./nakama-cpp/.github/actions/handle-failure 32 | with: 33 | nakama-cpp-path: nakama-cpp 34 | vcpkg-path: vcpkg -------------------------------------------------------------------------------- /.github/workflows/test_windows.yml: -------------------------------------------------------------------------------- 1 | name: Test Windows 2 | on: [workflow_dispatch, workflow_call] 3 | jobs: 4 | test_windows: 5 | strategy: 6 | matrix: 7 | build-type: [MinSizeRel] 8 | preset: [win-x64, win-x86] 9 | timeout-minutes: 40 10 | runs-on: windows-latest 11 | steps: 12 | - uses: actions/checkout@v3 13 | with: 14 | path: nakama-cpp 15 | - uses: ./nakama-cpp/.github/actions/setup-vcpkg 16 | with: 17 | github_token: ${{ secrets.github_token }} 18 | vcpkg-path: vcpkg 19 | - uses: ./nakama-cpp/.github/actions/build-library-and-upload 20 | with: 21 | nakama-cpp-path: nakama-cpp 22 | preset: ${{ matrix.preset }} 23 | build-type: ${{ matrix.build-type }} 24 | - uses: ./nakama-cpp/.github/actions/build-test-and-run 25 | with: 26 | nakama-cpp-path: nakama-cpp 27 | preset: ${{ matrix.preset }} 28 | testrunner-pat: ${{ secrets.GH_PAT }} 29 | build-type: ${{ matrix.build-type }} 30 | - if: failure() 31 | uses: ./nakama-cpp/.github/actions/handle-failure 32 | with: 33 | nakama-cpp-path: nakama-cpp 34 | vcpkg-path: vcpkg -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | cmake-build-* 2 | build 3 | out 4 | .idea 5 | /test/Engine 6 | CMakeUserPresets.json 7 | local.properties 8 | 9 | # Ignore Gradle project-specific cache directory 10 | android/.gradle 11 | 12 | # Ignore Gradle build output directory 13 | android/build 14 | android/app/.cxx 15 | -------------------------------------------------------------------------------- /RELEASEINST.md: -------------------------------------------------------------------------------- 1 | - Increment the version in `version.cmake`. 2 | - Update the CHANGELOG.md. 3 | - Run the "Build All" and "Test All" workflows to and ensure that everything has passed. Manually test on mobile. 4 | - Create a new tag and release with the changelog notes and upload the built artifacts from the "Build All" workflow. 5 | - Add a new entry for the package version in the vcpkg registry: https://github.com/heroiclabs/nakama-vcpkg-registry 6 | - Update the dependent Heroic C++ repositories with the new C++ and kick off those releases as well. -------------------------------------------------------------------------------- /android/app/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'com.android.library' version '7.4.0' apply true 3 | } 4 | 5 | repositories { 6 | google() 7 | mavenCentral() 8 | } 9 | 10 | android { 11 | compileSdkVersion 32 12 | defaultConfig { 13 | minSdkVersion 21 14 | targetSdkVersion 32 15 | } 16 | 17 | libraryVariants.all { 18 | variant -> 19 | variant.outputs.all { 20 | outputFileName = "libnakama-sdk.aar" 21 | } 22 | } 23 | } 24 | 25 | dependencies { 26 | implementation 'androidx.appcompat:appcompat:1.5.1' 27 | implementation 'org.bouncycastle:bcpkix-jdk15on:1.66' 28 | } 29 | -------------------------------------------------------------------------------- /android/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /android/app/src/main/java/com/heroiclabs/nakamasdk/AndroidCA.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.heroiclabs.nakamasdk; 18 | 19 | import androidx.annotation.Keep; 20 | import java.io.ByteArrayOutputStream; 21 | import java.io.OutputStreamWriter; 22 | import java.io.Writer; 23 | import java.security.KeyStore; 24 | import java.security.cert.Certificate; 25 | import java.security.cert.CertificateException; 26 | import java.security.cert.X509Certificate; 27 | import android.util.Base64; 28 | import java.util.Enumeration; 29 | 30 | public class AndroidCA { 31 | 32 | @Keep 33 | public static byte[] getCaCertificates() { 34 | try { 35 | KeyStore keyStore = KeyStore.getInstance("AndroidCAStore"); 36 | keyStore.load(null, null); 37 | Enumeration aliases = keyStore.aliases(); 38 | 39 | ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); 40 | Writer writer = new OutputStreamWriter(outputStream); 41 | 42 | while (aliases.hasMoreElements()) { 43 | String alias = aliases.nextElement(); 44 | X509Certificate cert = (X509Certificate) keyStore.getCertificate(alias); 45 | 46 | writer.write("-----BEGIN CERTIFICATE-----\n"); 47 | byte[] certBytes = cert.getEncoded(); 48 | writer.write(Base64.encodeToString(certBytes, 0, certBytes.length, Base64.NO_WRAP)); 49 | writer.write("\n-----END CERTIFICATE-----\n"); 50 | } 51 | 52 | writer.flush(); 53 | return outputStream.toByteArray(); 54 | } catch (Exception e) { 55 | e.printStackTrace(); 56 | return new byte[0]; 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /android/gradle.properties: -------------------------------------------------------------------------------- 1 | android.enableJetifier=true 2 | android.useAndroidX=true 3 | -------------------------------------------------------------------------------- /android/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heroiclabs/nakama-cpp/27322aaffe264bc991f7726189b5aea32040e6cf/android/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /android/settings.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * This file was generated by the Gradle 'init' task. 3 | * 4 | * The settings file is used to specify which projects to include in your build. 5 | * 6 | * Detailed information about configuring a multi-project build in Gradle can be found 7 | * in the user manual at https://docs.gradle.org/7.4.2/userguide/multi_project_builds.html 8 | */ 9 | 10 | pluginManagement { 11 | repositories { 12 | google() 13 | mavenCentral() 14 | gradlePluginPortal() 15 | } 16 | } 17 | 18 | rootProject.name = 'nakama-sdk' 19 | include ':app' 20 | -------------------------------------------------------------------------------- /cmake/linkerFlags.cmake: -------------------------------------------------------------------------------- 1 | if(MSVC) 2 | add_link_options( 3 | /debug # always create PDB files 4 | /OPT:REF /OPT:ICF # restore linked optimizations disabled by /debug 5 | ) 6 | elseif(CMAKE_CXX_COMPILER_ID MATCHES "^Apple") 7 | add_link_options(-Wl,-dead_strip) 8 | endif() 9 | -------------------------------------------------------------------------------- /cmake/localCompilerFlags.cmake: -------------------------------------------------------------------------------- 1 | # compiler flags set for SDK only. 2 | # Use for flags you can't/don't want to set on for vcpkg packages, like error on warnings for instance 3 | 4 | if (MSVC) 5 | target_compile_options( 6 | nakama-sdk 7 | PRIVATE 8 | /W4 /WX # error on warnings 9 | /Z7 # generate debug info so that PDB contains line numbers even in Release builds 10 | /utf-8 # our source code is using utf-8 11 | ) 12 | elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU") 13 | target_compile_options( 14 | nakama-sdk 15 | PRIVATE 16 | -Wall -Wextra -Werror # error on warnings 17 | -Wno-unknown-pragmas # ignore pragmas from other compilers 18 | ) 19 | endif() -------------------------------------------------------------------------------- /cmake/platformSupport.cmake: -------------------------------------------------------------------------------- 1 | # Various platform specific defines 2 | 3 | if (CMAKE_SYSTEM_NAME STREQUAL Windows OR WindowsDesktop) 4 | set(WindowsDesktop ON) 5 | message("Configuring Windows Desktop build") 6 | # Sets minimual Windows version we are targeting 7 | # https://docs.microsoft.com/en-us/windows/win32/WinProg/using-the-windows-headers 8 | add_compile_definitions(NTDDI_VERSION=NTDDI_WIN7 _WIN32_WINNT=_WIN32_WINNT_WIN7) 9 | set(BUILDWIN32 ON) # libhttpclient 10 | set(CMAKE_INSTALL_BINDIR ${CMAKE_INSTALL_LIBDIR}) # place .dll where .lib is so that multiplatform archives can be created 11 | elseif(CMAKE_SYSTEM_NAME STREQUAL Darwin) 12 | set(Darwin) 13 | message("Configuring Apple MacOSX build") 14 | # when changing, dont forget also set it in {arm64,x64}-osx-heroic vcpkg triplet 15 | # NOTE: we can't use CMAKE_SYSTEM_PROCESSOR here because it is always arm64 on M1 silicon for some reason 16 | if (VCPKG_TARGET_TRIPLET MATCHES "arm64") 17 | set(CMAKE_OSX_DEPLOYMENT_TARGET "11") # minimal OSX to support M1 18 | else() 19 | set(CMAKE_OSX_DEPLOYMENT_TARGET "10.15") # this is what Unreal builds for by default 20 | endif() 21 | elseif(CMAKE_OSX_SYSROOT MATCHES Simulator) 22 | message("Configuring Apple iphonesimulator build") 23 | set(CMAKE_OSX_DEPLOYMENT_TARGET "11") 24 | set(CMAKE_OSX_ARCHITECTURES "x86_64") 25 | elseif(CMAKE_SYSTEM_NAME STREQUAL iOS) 26 | message("Configuring Apple iOS build") 27 | # Don't forget to edit ./cmake/triplets too! 28 | # Value is picked based on https://developer.apple.com/support/app-store/ numbers 29 | set(CMAKE_OSX_DEPLOYMENT_TARGET "11") 30 | set(CMAKE_OSX_ARCHITECTURES "arm64") 31 | elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux") 32 | message("Configuring Linux build") 33 | set(LINUX ON) 34 | set(THREADS_PREFER_PTHREAD_FLAG ON) 35 | find_package(Threads REQUIRED) 36 | set(PTHREADS_LIB Threads::Threads) 37 | endif() 38 | -------------------------------------------------------------------------------- /cmake/triplets/arm-neon-android-heroic.cmake: -------------------------------------------------------------------------------- 1 | set(VCPKG_TARGET_ARCHITECTURE arm) 2 | set(VCPKG_CRT_LINKAGE dynamic) 3 | set(VCPKG_LIBRARY_LINKAGE static) 4 | set(VCPKG_CMAKE_SYSTEM_NAME Android) 5 | set(VCPKG_BUILD_TYPE release) 6 | set(ANDROID_ARM_NEON ON) -------------------------------------------------------------------------------- /cmake/triplets/arm64-android-heroic.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_FIND_DEBUG_MODE 1) 2 | set(VCPKG_TARGET_ARCHITECTURE arm64) 3 | set(VCPKG_CRT_LINKAGE dynamic) 4 | set(VCPKG_LIBRARY_LINKAGE static) 5 | set(VCPKG_CMAKE_SYSTEM_NAME Android) 6 | 7 | set(VCPKG_BUILD_TYPE release) 8 | set(VCPKG_CMAKE_CONFIGURE_OPTIONS -DANDROID_ABI=arm64-v8a) 9 | set(ANDROID_ARM_NEON ON) 10 | -------------------------------------------------------------------------------- /cmake/triplets/arm64-ios-heroic.cmake: -------------------------------------------------------------------------------- 1 | set(VCPKG_TARGET_ARCHITECTURE arm64) 2 | set(VCPKG_CRT_LINKAGE dynamic) 3 | set(VCPKG_LIBRARY_LINKAGE static) 4 | set(VCPKG_CMAKE_SYSTEM_NAME iOS) 5 | 6 | # HeroicLabs additions to standard triplets: 7 | set(VCPKG_BUILD_TYPE release) 8 | set(VCPKG_OSX_DEPLOYMENT_TARGET "11") 9 | set(VCPKG_OSX_ARCHITECTURES "arm64") 10 | 11 | include(${CMAKE_CURRENT_LIST_DIR}/feature-visibility-hidden.cmake) 12 | -------------------------------------------------------------------------------- /cmake/triplets/arm64-osx-heroic.cmake: -------------------------------------------------------------------------------- 1 | set(VCPKG_TARGET_ARCHITECTURE arm64) 2 | set(VCPKG_CRT_LINKAGE dynamic) 3 | set(VCPKG_LIBRARY_LINKAGE static) 4 | set(VCPKG_BUILD_TYPE release) 5 | 6 | set(VCPKG_CMAKE_SYSTEM_NAME Darwin) 7 | set(VCPKG_OSX_ARCHITECTURES arm64) 8 | 9 | # HeroicLabs additions to standard triplets: 10 | set(VCPKG_OSX_DEPLOYMENT_TARGET "11") 11 | set(VCPKG_BUILD_TYPE release) 12 | include(${CMAKE_CURRENT_LIST_DIR}/feature-visibility-hidden.cmake) 13 | -------------------------------------------------------------------------------- /cmake/triplets/arm64-windows-static-heroic.cmake: -------------------------------------------------------------------------------- 1 | set(VCPKG_TARGET_ARCHITECTURE arm64) 2 | set(VCPKG_CRT_LINKAGE dynamic) 3 | set(VCPKG_LIBRARY_LINKAGE static) 4 | set(CMAKE_GENERATOR Visual Studio 17 2022) 5 | 6 | string(APPEND VCPKG_C_FLAGS_RELEASE " /O1 /Ob2 /Gw /Gy") 7 | string(APPEND VCPKG_CXX_FLAGS_RELEASE " /O1 /Ob2 /Gw /Gy") 8 | 9 | list(APPEND VCPKG_KEEP_ENV_VARS "PATH" "Path") 10 | -------------------------------------------------------------------------------- /cmake/triplets/feature-lto.cmake: -------------------------------------------------------------------------------- 1 | macro(enable_lto COMPILER_KIND) 2 | if(${COMPILER_KIND} STREQUAL MSVC) 3 | elseif(${COMPILER_KIND} STREQUAL APPLE) 4 | string(APPEND VCPKG_C_FLAGS " -ffunction-sections -fdata-sections") 5 | string(APPEND VCPKG_CXX_FLAGS " -ffunction-sections -fdata-sections") 6 | string(APPEND VCPKG_LINKER_FLAGS " -Wl,-dead_strip") 7 | elseif(${COMPILER_KIND} STREQUAL "GNU") 8 | string(APPEND VCPKG_C_FLAGS " -ffunction-sections -fdata-sections") 9 | string(APPEND VCPKG_CXX_FLAGS " -ffunction-sections -fdata-sections") 10 | string(APPEND VCPKG_LINKER_FLAGS " -Wl,--gc-sections") 11 | elseif(${COMPILER_KIND} STREQUAL "Clang") 12 | string(APPEND VCPKG_C_FLAGS " -ffunction-sections -fdata-sections") 13 | string(APPEND VCPKG_CXX_FLAGS " -ffunction-sections -fdata-sections") 14 | string(APPEND VCPKG_LINKER_FLAGS " -Wl,--gc-sections") 15 | endif() 16 | endmacro() 17 | -------------------------------------------------------------------------------- /cmake/triplets/feature-visibility-hidden.cmake: -------------------------------------------------------------------------------- 1 | # vcpkg dependencies are built statically and then linked into our shared lib. 2 | # There is no way to reliably hide symbols from static lib dependencies in the shared lib. 3 | # So instead of hiding symbols when linking, we build dependencies such that there is no public 4 | # symbols in them in the first place. 5 | # See following issues for context: 6 | # - https://gitlab.kitware.com/cmake/cmake/-/issues/22177#note_983766 7 | # - https://gitlab.kitware.com/cmake/cmake/-/issues/16977 8 | string(APPEND VCPKG_C_FLAGS " -fvisibility=hidden -fvisibility-inlines-hidden") 9 | string(APPEND VCPKG_CXX_FLAGS " -fvisibility=hidden -fvisibility-inlines-hidden") 10 | -------------------------------------------------------------------------------- /cmake/triplets/x64-android-heroic.cmake: -------------------------------------------------------------------------------- 1 | set(VCPKG_TARGET_ARCHITECTURE x64) 2 | set(VCPKG_CRT_LINKAGE dynamic) 3 | set(VCPKG_LIBRARY_LINKAGE static) 4 | set(VCPKG_CMAKE_SYSTEM_NAME Android) 5 | 6 | set(VCPKG_BUILD_TYPE release) 7 | set(ANDROID_ARM_NEON ON) 8 | set(VCPKG_CMAKE_CONFIGURE_OPTIONS -DANDROID_ABI=x86_64) -------------------------------------------------------------------------------- /cmake/triplets/x64-iphonesimulator-heroic.cmake: -------------------------------------------------------------------------------- 1 | set(VCPKG_TARGET_ARCHITECTURE x64) 2 | set(VCPKG_CRT_LINKAGE dynamic) 3 | set(VCPKG_LIBRARY_LINKAGE static) 4 | set(VCPKG_CMAKE_SYSTEM_NAME iOS) 5 | 6 | # Heroic Labs additions to standard triplets: 7 | set(VCPKG_BUILD_TYPE release) 8 | set(VCPKG_OSX_DEPLOYMENT_TARGET "11") 9 | set(VCPKG_OSX_ARCHITECTURES "x86_64") 10 | set(VCPKG_OSX_SYSROOT iphonesimulator) 11 | 12 | include(${CMAKE_CURRENT_LIST_DIR}/feature-visibility-hidden.cmake) 13 | -------------------------------------------------------------------------------- /cmake/triplets/x64-linux-dynamic-release.cmake: -------------------------------------------------------------------------------- 1 | set(VCPKG_TARGET_ARCHITECTURE x64) 2 | set(VCPKG_CRT_LINKAGE dynamic) 3 | set(VCPKG_LIBRARY_LINKAGE dynamic) 4 | 5 | set(VCPKG_CMAKE_SYSTEM_NAME Linux) 6 | set(VCPKG_BUILD_TYPE release) 7 | -------------------------------------------------------------------------------- /cmake/triplets/x64-linux-heroic.cmake: -------------------------------------------------------------------------------- 1 | set(VCPKG_TARGET_ARCHITECTURE x64) 2 | set(VCPKG_CRT_LINKAGE dynamic) 3 | set(VCPKG_LIBRARY_LINKAGE static) 4 | 5 | set(VCPKG_CMAKE_SYSTEM_NAME Linux) 6 | set(VCPKG_BUILD_TYPE release) 7 | -------------------------------------------------------------------------------- /cmake/triplets/x64-osx-heroic.cmake: -------------------------------------------------------------------------------- 1 | set(VCPKG_TARGET_ARCHITECTURE x64) 2 | set(VCPKG_CRT_LINKAGE dynamic) 3 | set(VCPKG_LIBRARY_LINKAGE static) 4 | set(VCPKG_BUILD_TYPE release) 5 | 6 | set(VCPKG_CMAKE_SYSTEM_NAME Darwin) 7 | set(VCPKG_OSX_ARCHITECTURES x86_64) 8 | 9 | # Heroic Labs additions to standard triplets: 10 | set(VCPKG_OSX_DEPLOYMENT_TARGET "10.15") 11 | include(${CMAKE_CURRENT_LIST_DIR}/feature-visibility-hidden.cmake) -------------------------------------------------------------------------------- /cmake/triplets/x64-windows-static-heroic.cmake: -------------------------------------------------------------------------------- 1 | set(VCPKG_TARGET_ARCHITECTURE x64) 2 | set(VCPKG_CRT_LINKAGE dynamic) 3 | set(VCPKG_LIBRARY_LINKAGE static) 4 | set(CMAKE_GENERATOR Visual Studio 17 2022) 5 | 6 | string(APPEND VCPKG_C_FLAGS_RELEASE " /O1 /Ob2 /Gw /Gy") 7 | string(APPEND VCPKG_CXX_FLAGS_RELEASE " /O1 /Ob2 /Gw /Gy") 8 | 9 | list(APPEND VCPKG_KEEP_ENV_VARS "PATH" "Path") 10 | -------------------------------------------------------------------------------- /cmake/triplets/x86-windows-release.cmake: -------------------------------------------------------------------------------- 1 | set(VCPKG_TARGET_ARCHITECTURE x86) 2 | set(VCPKG_CRT_LINKAGE dynamic) 3 | set(VCPKG_LIBRARY_LINKAGE static) 4 | 5 | set(CMAKE_GENERATOR Visual Studio 17 2022) 6 | -------------------------------------------------------------------------------- /core/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.22) 2 | project(nakama-sdk-cpp DESCRIPTION "Nakama C++ Client" LANGUAGES CXX) 3 | 4 | set(NAKAMA_GIT_TAG "master" CACHE STRING "nakama Git tag to fetch Proto files from") 5 | set(NAKAMA_COMMON_GIT_TAG "master" CACHE STRING "nakama-common Git tag to fetch Proto files from") 6 | 7 | # unconditional 8 | find_package(RapidJSON CONFIG REQUIRED) 9 | 10 | # unconditional, because core-rt is always built and it uses nakama-api-proto 11 | # TODO: split buildProtoFiles into grpc and api-proto 12 | find_package(Protobuf CONFIG REQUIRED) 13 | include(buildProtoFiles.cmake) 14 | 15 | add_subdirectory(common EXCLUDE_FROM_ALL) 16 | add_subdirectory(src) 17 | add_subdirectory(core-rt EXCLUDE_FROM_ALL) 18 | add_subdirectory(core-rest EXCLUDE_FROM_ALL) 19 | 20 | ## for createRtClient() 21 | target_link_libraries(nakama-sdk-core-rest PUBLIC nakama-sdk-core-rt factory) 22 | 23 | if (BUILD_GRPC_CLIENT) 24 | add_subdirectory(core-grpc EXCLUDE_FROM_ALL) 25 | endif() 26 | -------------------------------------------------------------------------------- /core/common/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | execute_process( 3 | COMMAND git log -1 --format=%h 4 | WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} 5 | OUTPUT_VARIABLE GIT_HASH 6 | OUTPUT_STRIP_TRAILING_WHITESPACE 7 | ) 8 | 9 | configure_file(Version.cpp.in Version.cpp @ONLY) 10 | 11 | file( 12 | GLOB_RECURSE srcs 13 | LIST_DIRECTORIES false 14 | "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp" 15 | "${CMAKE_CURRENT_SOURCE_DIR}/*.h" 16 | "${CMAKE_CURRENT_BINARY_DIR}/Version.cpp" 17 | ) 18 | 19 | #set(CMAKE_INCLUDE_CURRENT_DIR ON) 20 | #set(CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE ON) 21 | 22 | add_library(nakama-sdk-core-common OBJECT ${srcs}) 23 | 24 | target_link_libraries(nakama-sdk-core-common 25 | PUBLIC 26 | nakama-sdk-interface 27 | # required for datahelper 28 | nakama::api-proto 29 | $<$:nakama::grpc-proto> 30 | PRIVATE 31 | protobuf::libprotobuf # because of StrUtil::Base64Encode 32 | ) 33 | 34 | target_include_directories(nakama-sdk-core-common PUBLIC 35 | $ 36 | $ 37 | ) 38 | 39 | 40 | -------------------------------------------------------------------------------- /core/common/DefaultSession.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include "nakama-cpp/NSessionInterface.h" 20 | 21 | namespace Nakama { 22 | 23 | class DefaultSession : public NSessionInterface 24 | { 25 | public: 26 | DefaultSession(const std::string& token, const std::string& refreshToken, bool created); 27 | const std::string& getAuthToken() const override; 28 | const std::string& getRefreshToken() const override; 29 | bool isCreated() const override; 30 | const std::string& getUsername() const override; 31 | const std::string& getUserId() const override; 32 | NTimestamp getCreateTime() const override; 33 | NTimestamp getExpireTime() const override; 34 | bool isExpired() const override; 35 | bool isExpired(NTimestamp now) const override; 36 | bool isRefreshExpired() const override; 37 | bool isRefreshExpired(NTimestamp now) const override; 38 | const NStringMap& getVariables() const override; 39 | std::string getVariable(const std::string& name) const override; 40 | 41 | private: 42 | std::string _token; 43 | std::string _user_id; 44 | std::string _username; 45 | bool _created = false; 46 | NTimestamp _create_time = 0; 47 | NTimestamp _expire_time = 0; 48 | NStringMap _variables; 49 | std::string _refresh_token; 50 | NTimestamp _refresh_expire_time; 51 | std::string jwtUnpack(std::string token); 52 | }; 53 | } 54 | -------------------------------------------------------------------------------- /core/common/NError.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "nakama-cpp/NError.h" 18 | 19 | namespace Nakama { 20 | 21 | const char * toString(ErrorCode code) 22 | { 23 | switch (code) 24 | { 25 | case ErrorCode::Unknown: return "Unknown"; 26 | case ErrorCode::NotFound: return "NotFound"; 27 | case ErrorCode::AlreadyExists: return "AlreadyExists"; 28 | case ErrorCode::InvalidArgument: return "InvalidArgument"; 29 | case ErrorCode::ConnectionError: return "ConnectionError"; 30 | case ErrorCode::InternalError: return "InternalError"; 31 | case ErrorCode::Unauthenticated: return "Unauthenticated"; 32 | case ErrorCode::PermissionDenied: return "PermissionDenied"; 33 | case ErrorCode::CancelledByUser: return "CancelledByUser"; 34 | default: 35 | break; 36 | } 37 | 38 | return ""; 39 | } 40 | 41 | std::string toString(const NError & error) 42 | { 43 | std::string str; 44 | 45 | str.append("NError: ").append(toString(error.code)); 46 | 47 | if (!error.message.empty()) 48 | { 49 | str.append("\n").append(error.message); 50 | } 51 | 52 | return str; 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /core/common/NRtError.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "nakama-cpp/realtime/rtdata/NRtError.h" 18 | 19 | namespace Nakama { 20 | 21 | const char* toString(RtErrorCode code) 22 | { 23 | switch (code) 24 | { 25 | case Nakama::RtErrorCode::CONNECT_ERROR : return "CONNECT_ERROR"; 26 | case Nakama::RtErrorCode::TRANSPORT_ERROR : return "TRANSPORT_ERROR"; 27 | case Nakama::RtErrorCode::DISCONNECTED : return "DISCONNECTED"; 28 | case Nakama::RtErrorCode::RUNTIME_EXCEPTION : return "RUNTIME_EXCEPTION"; 29 | case Nakama::RtErrorCode::UNRECOGNIZED_PAYLOAD : return "UNRECOGNIZED_PAYLOAD"; 30 | case Nakama::RtErrorCode::MISSING_PAYLOAD : return "MISSING_PAYLOAD"; 31 | case Nakama::RtErrorCode::BAD_INPUT : return "BAD_INPUT"; 32 | case Nakama::RtErrorCode::MATCH_NOT_FOUND : return "MATCH_NOT_FOUND"; 33 | case Nakama::RtErrorCode::MATCH_JOIN_REJECTED : return "MATCH_JOIN_REJECTED"; 34 | case Nakama::RtErrorCode::RUNTIME_FUNCTION_NOT_FOUND: return "RUNTIME_FUNCTION_NOT_FOUND"; 35 | case Nakama::RtErrorCode::RUNTIME_FUNCTION_EXCEPTION: return "RUNTIME_FUNCTION_EXCEPTION"; 36 | default: 37 | break; 38 | } 39 | 40 | return "Unknown"; 41 | } 42 | 43 | std::string toString(const NRtError & error) 44 | { 45 | std::string str; 46 | 47 | str.append("NRtError: ").append(toString(error.code)); 48 | 49 | if (!error.message.empty()) 50 | { 51 | str.append("\n").append(error.message); 52 | } 53 | 54 | if (!error.context.empty()) 55 | { 56 | str.append("\nContext:"); 57 | 58 | for (auto it : error.context) 59 | { 60 | str.append("\n").append(it.first).append("=").append(it.second); 61 | } 62 | } 63 | 64 | return str; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /core/common/NUtils.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "nakama-cpp/NUtils.h" 18 | #include 19 | 20 | namespace Nakama { 21 | 22 | using namespace std::chrono; 23 | 24 | NTimestamp getUnixTimestampMs() 25 | { 26 | milliseconds ms = duration_cast(system_clock::now().time_since_epoch()); 27 | 28 | return ms.count(); 29 | } 30 | 31 | } // namespace Nakama 32 | -------------------------------------------------------------------------------- /core/common/RapidjsonHelper.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #define RAPIDJSON_HAS_STDSTRING 1 18 | #define RAPIDJSON_NAMESPACE Nakama::rapidjson 19 | #define RAPIDJSON_NAMESPACE_BEGIN namespace Nakama { namespace rapidjson { 20 | #define RAPIDJSON_NAMESPACE_END }} 21 | 22 | #include "rapidjson/document.h" 23 | -------------------------------------------------------------------------------- /core/common/StrUtil.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include "nakama-cpp/NTypes.h" 20 | #include "nakama-cpp/NExport.h" 21 | #include "nakama-cpp/URLParts.h" 22 | #include 23 | #include 24 | 25 | NAKAMA_NAMESPACE_BEGIN 26 | 27 | typedef std::string Base64Buffer; 28 | 29 | /** 30 | * Encode bytes buffer using `base64` algorithm 31 | * 32 | * @param buffer byte buffer to encode 33 | * @return std::string encoded `base64` string 34 | */ 35 | std::string base64Encode(const Base64Buffer& buffer); 36 | 37 | /** 38 | * Encode bytes buffer using `base64Url` algorithm 39 | * 40 | * @param buffer byte buffer to encode 41 | * @return std::string encoded `base64Url` string 42 | */ 43 | std::string base64EncodeUrl(const Base64Buffer& buffer); 44 | 45 | /** 46 | * Decode `base64Url` string 47 | * 48 | * @param base64str `base64Url` string 49 | * @return Base64Buffer byte buffer 50 | */ 51 | Base64Buffer base64DecodeUrl(const std::string& base64str); 52 | 53 | /** 54 | * Encode string to allow use it in an URL 55 | * 56 | * @param str string to encode 57 | * @return std::string encoded string 58 | */ 59 | std::string encodeURIComponent(std::string decoded); 60 | 61 | /** 62 | * returns true if a string starts with the specified prefix 63 | * 64 | * @param str The string 65 | * @param prefix The prefix to check 66 | * @return bool 67 | */ 68 | bool isStringStartsWith(const std::string& str, const std::string& prefix); 69 | 70 | //Definitely not fully compliant, but good enough for us 71 | opt::optional ParseURL(const std::string& url); 72 | 73 | NAKAMA_NAMESPACE_END 74 | -------------------------------------------------------------------------------- /core/common/Version.cpp.in: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "nakama-cpp/NakamaVersion.h" 18 | 19 | namespace Nakama { 20 | 21 | const char* getNakamaSdkVersion() 22 | { 23 | return "@LIBNAKAMA_VERSION@ git:@GIT_HASH@"; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /core/core-grpc/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(nakama-sdk-cpp-core-grpc LANGUAGES CXX) 2 | 3 | file( 4 | GLOB_RECURSE srcs 5 | LIST_DIRECTORIES false 6 | "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp" 7 | "${CMAKE_CURRENT_SOURCE_DIR}/*.h" 8 | ) 9 | 10 | set(CMAKE_INCLUDE_CURRENT_DIR ON) 11 | 12 | find_package(gRPC CONFIG REQUIRED) 13 | 14 | add_library(nakama-sdk-core-grpc OBJECT ${srcs}) 15 | target_link_libraries(nakama-sdk-core-grpc 16 | PUBLIC nakama-sdk-interface nakama-grpc-proto 17 | PUBLIC nakama-sdk-core-common 18 | nakama-sdk-core-rt 19 | ) -------------------------------------------------------------------------------- /core/core-rest/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(nakama-sdk-cpp-core-rest LANGUAGES CXX) 2 | 3 | file( 4 | GLOB_RECURSE srcs 5 | LIST_DIRECTORIES false 6 | "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp" 7 | "${CMAKE_CURRENT_SOURCE_DIR}/*.h" 8 | ) 9 | 10 | set(CMAKE_INCLUDE_CURRENT_DIR ON) 11 | 12 | add_library(nakama-sdk-core-rest OBJECT ${srcs}) 13 | add_library(nakama::sdk-core-rest ALIAS nakama-sdk-core-rest) 14 | target_compile_definitions(nakama-sdk-core-rest PRIVATE 15 | RAPIDJSON_HAS_STDSTRING=1 16 | 17 | # on consoles rapidjson fail to detect C++11 strings presence 18 | # we know we have them, so set them unconditionally 19 | RAPIDJSON_HAS_CXX11_RVALUE_REFS=1 20 | ) 21 | target_link_libraries(nakama-sdk-core-rest 22 | PUBLIC nakama-sdk-interface 23 | PRIVATE rapidjson 24 | nakama-sdk-core-common 25 | nakama-sdk-core-rt 26 | ) 27 | -------------------------------------------------------------------------------- /core/core-rt/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(nakama-cpp-sdk-core-rt LANGUAGES CXX) 2 | 3 | file( 4 | GLOB_RECURSE srcs 5 | LIST_DIRECTORIES false 6 | "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp" 7 | "${CMAKE_CURRENT_SOURCE_DIR}/*.h" 8 | ) 9 | 10 | set(CMAKE_INCLUDE_CURRENT_DIR ON) 11 | 12 | add_library(nakama-sdk-core-rt OBJECT ${srcs}) 13 | target_link_libraries(nakama-sdk-core-rt 14 | PUBLIC nakama-sdk-interface nakama-api-proto 15 | PUBLIC nakama-sdk-core-common 16 | PRIVATE nakama::rtclient-factory # because of BaseClient.cpp 17 | ) 18 | -------------------------------------------------------------------------------- /core/core-rt/NRtClientProtocolInterface.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include "nakama-cpp/NTypes.h" 20 | #include "google/protobuf/message.h" 21 | 22 | namespace Nakama { 23 | 24 | class NRtClientProtocolInterface 25 | { 26 | public: 27 | virtual ~NRtClientProtocolInterface() {} 28 | 29 | virtual bool serialize(const google::protobuf::Message& message, NBytes& output) = 0; 30 | virtual bool parse(const NBytes& input, google::protobuf::Message& message) = 0; 31 | }; 32 | 33 | using NRtClientProtocolPtr = std::shared_ptr; 34 | 35 | } 36 | -------------------------------------------------------------------------------- /core/core-rt/NRtClientProtocol_Json.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "NRtClientProtocol_Json.h" 18 | #include "google/protobuf/util/json_util.h" 19 | 20 | namespace Nakama { 21 | 22 | bool NRtClientProtocol_Json::serialize(const google::protobuf::Message& message, NBytes& output) 23 | { 24 | auto status = google::protobuf::util::MessageToJsonString(message, &output); 25 | 26 | return status.ok(); 27 | } 28 | 29 | bool NRtClientProtocol_Json::parse(const NBytes& input, google::protobuf::Message& message) 30 | { 31 | google::protobuf::util::JsonParseOptions options; 32 | options.ignore_unknown_fields = true; 33 | auto status = google::protobuf::util::JsonStringToMessage(input, &message, options); 34 | 35 | return status.ok(); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /core/core-rt/NRtClientProtocol_Json.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include "NRtClientProtocolInterface.h" 20 | 21 | namespace Nakama { 22 | 23 | class NRtClientProtocol_Json : public NRtClientProtocolInterface 24 | { 25 | public: 26 | bool serialize(const google::protobuf::Message& message, NBytes& output) override; 27 | bool parse(const NBytes& input, google::protobuf::Message& message) override; 28 | }; 29 | 30 | } 31 | -------------------------------------------------------------------------------- /core/core-rt/NRtClientProtocol_Protobuf.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "NRtClientProtocol_Protobuf.h" 18 | 19 | namespace Nakama { 20 | 21 | bool NRtClientProtocol_Protobuf::serialize(const google::protobuf::Message& message, NBytes& output) 22 | { 23 | size_t size = message.ByteSizeLong(); 24 | 25 | output.resize(size); 26 | 27 | return message.SerializeToArray(&output[0], static_cast(size)); 28 | } 29 | 30 | bool NRtClientProtocol_Protobuf::parse(const NBytes& input, google::protobuf::Message& message) 31 | { 32 | return message.ParseFromArray(input.data(), static_cast(input.size())); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /core/core-rt/NRtClientProtocol_Protobuf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include "NRtClientProtocolInterface.h" 20 | 21 | namespace Nakama { 22 | 23 | class NRtClientProtocol_Protobuf : public NRtClientProtocolInterface 24 | { 25 | public: 26 | bool serialize(const google::protobuf::Message& message, NBytes& output) override; 27 | bool parse(const NBytes& input, google::protobuf::Message& message) override; 28 | }; 29 | 30 | } 31 | -------------------------------------------------------------------------------- /core/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2019 The Nakama Authors 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | set(_src_root_path ${CMAKE_CURRENT_LIST_DIR}) 18 | file( 19 | GLOB_RECURSE _source_list 20 | LIST_DIRECTORIES false 21 | "${_src_root_path}/*.c*" 22 | "${_src_root_path}/*.h*" 23 | ) 24 | 25 | add_library(nakama-sdk-core-misc OBJECT ${_source_list}) 26 | 27 | target_link_libraries(nakama-sdk-core-misc 28 | PUBLIC nakama-sdk-interface 29 | ) 30 | 31 | if(ANDROID) 32 | target_link_libraries(nakama-sdk-core-misc PRIVATE log) 33 | endif() 34 | 35 | set(CMAKE_INCLUDE_CURRENT_DIR ON) 36 | -------------------------------------------------------------------------------- /core/src/log/NConsoleLogSink.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "nakama-cpp/log/NConsoleLogSink.h" 18 | #include 19 | #ifdef __ANDROID__ 20 | #include 21 | #endif 22 | 23 | #ifdef WIN32 24 | #include 25 | #endif 26 | 27 | namespace Nakama { 28 | 29 | using namespace std; 30 | 31 | #ifdef __ANDROID__ 32 | static android_LogPriority androidLogPrio(NLogLevel level) { 33 | switch (level) { 34 | case NLogLevel::Fatal: return ANDROID_LOG_FATAL; 35 | case NLogLevel::Error: return ANDROID_LOG_ERROR; 36 | case NLogLevel::Warn: return ANDROID_LOG_WARN; 37 | case NLogLevel::Info: return ANDROID_LOG_INFO; 38 | case NLogLevel::Debug: return ANDROID_LOG_DEBUG; 39 | default: return ANDROID_LOG_UNKNOWN; 40 | } 41 | } 42 | #endif 43 | 44 | void NConsoleLogSink::log(NLogLevel level, const std::string& message, const char* func) 45 | { 46 | std::string tmp; 47 | 48 | if (func && func[0]) 49 | { 50 | tmp.append("[").append(func).append("] "); 51 | } 52 | 53 | tmp.append(message).append("\n"); 54 | 55 | #ifdef __ANDROID__ 56 | __android_log_print(androidLogPrio(level), "nakama", "%s", message.c_str()); 57 | #else 58 | // write to console 59 | std::ostream& os = (level >= NLogLevel::Error) ? std::cerr : std::cout; 60 | os << tmp; 61 | #endif 62 | 63 | #ifdef WIN32 64 | // write debug string so Visual Studio and DebugView will catch it 65 | OutputDebugStringA(tmp.c_str()); 66 | #endif 67 | } 68 | 69 | void NConsoleLogSink::flush() 70 | { 71 | #if !defined(__ANDROID__) 72 | std::cout.flush(); 73 | std::cerr.flush(); 74 | #endif 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /core/src/roots_pem.h: -------------------------------------------------------------------------------- 1 | // file generated by conv_roots_pem.py 2 | 3 | #pragma once 4 | 5 | #include 6 | 7 | extern const char* g_roots_pem; 8 | extern const uint32_t g_roots_pem_size; 9 | -------------------------------------------------------------------------------- /example/README.md: -------------------------------------------------------------------------------- 1 | This is an example project that integrates nakama-cpp via CMake. You'll need an architecture-specific `nakama-sdk` release 2 | installed in `out`. 3 | 4 | If you are building for Mac/iOS, you'll need to set your NAKAMA_TEST_DEVELOPMENT_TEAM environment variable to the team ID printed in parentheses here: `xcrun security find-identity -v -p codesigning` 5 | 6 | In-tree example: 7 | ``` 8 | cd example 9 | cmake --list-presets 10 | cmake --preset 11 | cmake --build --preset --target install 12 | ``` -------------------------------------------------------------------------------- /example/example.entitlements: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /example/example.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | -------------------------------------------------------------------------------- /example/vcpkg-configuration.json: -------------------------------------------------------------------------------- 1 | { 2 | "registries": 3 | [ 4 | { 5 | "kind": "builtin", 6 | "baseline": "62d01b70df227850b728f5050418b917ad6d2b32", 7 | "packages": [] 8 | }, 9 | { 10 | "kind": "git", 11 | "repository": "https://github.com/heroiclabs/nakama-vcpkg-registry", 12 | "baseline": "9a381b48a69ef8c73cf630f5fc3a569e375b8536", 13 | "reference": "master", 14 | "packages": ["nakama-sdk", "wslay"] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /example/vcpkg.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nakama-example", 3 | "version": "1.0.0", 4 | "dependencies": [ 5 | { 6 | "name": "nakama-sdk", 7 | "version>=": "2.6.0#3", 8 | "platform": "ios | osx | linux", 9 | "features": ["wslay", "curl", "libhttpclient-http"] 10 | }, 11 | { 12 | "name": "nakama-sdk", 13 | "version>=": "2.6.0#3", 14 | "platform": "android | windows", 15 | "features": ["libhttpclient-ws", "libhttpclient-http"] 16 | } 17 | ], 18 | "default-features": [], 19 | "builtin-baseline": "62d01b70df227850b728f5050418b917ad6d2b32" 20 | } 21 | -------------------------------------------------------------------------------- /factory/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(nakama-sdk-client-factory OBJECT ClientFactory.cpp) 2 | add_library(nakama::client-factory ALIAS nakama-sdk-client-factory) 3 | target_link_libraries(nakama-sdk-client-factory 4 | PRIVATE nakama-sdk-core-rest nakama-sdk-core-grpc ${HTTP_IMPL_LIB}) 5 | 6 | if (BUILD_GRPC_CLIENT) 7 | target_compile_definitions(nakama-sdk-client-factory PRIVATE BUILD_GRPC_CLIENT) 8 | endif() 9 | 10 | target_compile_definitions(nakama-sdk-client-factory PRIVATE HTTP_COMPILE_DEFINITION) 11 | 12 | add_library(nakama-sdk-rtclient-factory OBJECT NWebsocketsFactory.cpp) 13 | add_library(nakama::rtclient-factory ALIAS nakama-sdk-rtclient-factory) 14 | 15 | target_link_libraries(nakama-sdk-rtclient-factory 16 | PUBLIC nakama-sdk-interface 17 | PRIVATE ${WS_IMPL_LIB} 18 | ) 19 | -------------------------------------------------------------------------------- /factory/NWebsocketsFactory.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "nakama-cpp/realtime/NWebsocketsFactory.h" 18 | #include "nakama-cpp/log/NLogger.h" 19 | #include "nakama-cpp/NPlatformParams.h" 20 | 21 | #ifdef BUILD_WEBSOCKET_WSLAY 22 | #include "nakama-cpp/realtime/wslay/WslayIOInterface.h" 23 | #endif 24 | 25 | #if defined(BUILD_WEBSOCKET_LIBHTTPCLIENT) 26 | #include "../../impl/wsLibHttpClient/NWebsocketLibHC.h" 27 | #elif defined(BUILD_WEBSOCKET_WSLAY) 28 | #include "NWebsocketWslay.h" 29 | #if defined(BUILD_CURL_IO) 30 | #include "WslayIOCurl.h" 31 | #endif 32 | #elif defined(BUILD_WEBSOCKET_CPPRESTSDK) 33 | #include "NWebsocketCppRest.h" 34 | #endif 35 | 36 | namespace Nakama { 37 | 38 | #if !defined(WITH_EXTERNAL_WS) && !defined(BUILD_IO_EXTERNAL) 39 | 40 | NRtTransportPtr createDefaultWebsocket(const NPlatformParameters& platformParams) 41 | { 42 | (void)platformParams; // silence unused variable warning on some platforms 43 | #if defined(BUILD_WEBSOCKET_LIBHTTPCLIENT) 44 | return NRtTransportPtr(NWebsocketLibHC::New(platformParams)); 45 | #elif defined(BUILD_WEBSOCKET_WSLAY) && defined(BUILD_CURL_IO) 46 | return NRtTransportPtr(new NWebsocketWslay(std::move(std::unique_ptr(new WslayIOCurl())))); 47 | #elif defined(BUILD_WEBSOCKET_CPPRESTSDK) 48 | return NRtTransportPtr(new NWebsocketCppRest()); 49 | #else 50 | #error Could not find default web socket transport or IO for platform. 51 | #endif 52 | } 53 | 54 | #endif 55 | 56 | #ifdef BUILD_WEBSOCKET_WSLAY 57 | NRtTransportPtr createWslayWebsocket(std::unique_ptr io) 58 | { 59 | return std::make_shared(std::move(io)); 60 | } 61 | #endif 62 | 63 | } // namespace Nakama 64 | -------------------------------------------------------------------------------- /impl/android/AndroidCA.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 Heroic Labs 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | namespace Nakama 24 | { 25 | struct CACertificateData 26 | { 27 | unsigned char* data; 28 | int len; 29 | }; 30 | 31 | CACertificateData* getCaCertificates(); 32 | }; 33 | 34 | -------------------------------------------------------------------------------- /impl/android/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file( 2 | GLOB_RECURSE srcs 3 | LIST_DIRECTORIES false 4 | "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp" 5 | "${CMAKE_CURRENT_SOURCE_DIR}/*.h" 6 | ) 7 | 8 | add_library(android-ca OBJECT ${srcs}) 9 | target_include_directories(android-ca PUBLIC 10 | "$" 11 | "$") 12 | 13 | target_link_libraries(android-ca 14 | PRIVATE android nakama-sdk-core-misc 15 | ) 16 | -------------------------------------------------------------------------------- /impl/httpCppRest/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file( 2 | GLOB_RECURSE srcs 3 | LIST_DIRECTORIES false 4 | "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp" 5 | "${CMAKE_CURRENT_SOURCE_DIR}/*.h" 6 | ) 7 | 8 | set(CMAKE_INCLUDE_CURRENT_DIR ON) 9 | find_package(cpprestsdk CONFIG REQUIRED) 10 | 11 | add_library(nakama-impl-http-cppRest OBJECT ${srcs}) 12 | target_link_libraries(nakama-impl-http-cppRest 13 | PUBLIC nakama-api-proto nakama::sdk-interface 14 | PRIVATE cpprestsdk::cpprest 15 | ) 16 | add_library(nakama::impl-http-cppRest ALIAS nakama-impl-http-cppRest) 17 | set(HTTP_IMPL_LIB nakama-impl-http-cppRest PARENT_SCOPE) 18 | -------------------------------------------------------------------------------- /impl/httpCppRest/CppRestUtils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include "cpprest/asyncrt_utils.h" 20 | 21 | #ifdef _WIN32 22 | #define TO_STD_STR(ws_str) utility::conversions::to_utf8string(ws_str) 23 | #define FROM_STD_STR(utf8str) utility::conversions::to_string_t(utf8str) 24 | #else 25 | #define TO_STD_STR(ws_str) ws_str 26 | #define FROM_STD_STR(utf8str) utf8str 27 | #endif 28 | -------------------------------------------------------------------------------- /impl/httpCppRest/NHttpClientCppRest.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include 20 | #include "nakama-cpp/NPlatformParams.h" 21 | #include "cpprest/http_client.h" 22 | #include 23 | #include 24 | 25 | namespace Nakama { 26 | 27 | class NHttpClientCppRestContext; 28 | 29 | /** 30 | * HTTP client using C++ REST SDK (https://github.com/microsoft/cpprestsdk) 31 | */ 32 | class NHttpClientCppRest : public NHttpTransportInterface 33 | { 34 | public: 35 | using ReqId = uint64_t; 36 | 37 | NHttpClientCppRest(const NPlatformParameters& platformParams); 38 | ~NHttpClientCppRest(); 39 | 40 | void setBaseUri(const std::string& uri) override; 41 | 42 | void tick() override; 43 | 44 | void request(const NHttpRequest& req, const NHttpResponseCallback& callback = nullptr) override; 45 | 46 | void cancelAllRequests() override; 47 | 48 | protected: 49 | friend class NHttpClientCppRestContext; 50 | 51 | struct ReqContext 52 | { 53 | ReqContext(ReqId _id) : id(_id) {} 54 | 55 | ReqId id; 56 | NHttpResponseCallback callback; 57 | NHttpResponsePtr response; 58 | }; 59 | 60 | using ReqContextPtr = std::shared_ptr; 61 | 62 | std::shared_ptr createReqContext(); 63 | void finishReq(ReqId id, NHttpResponsePtr response); 64 | void finishReqWithError(ReqId id, int statusCode, std::string&& reason); 65 | void removePendingReq(ReqId id); 66 | ReqContextPtr popFinishedReq(); 67 | 68 | protected: 69 | std::shared_ptr _context; 70 | std::unique_ptr _client; 71 | std::list _pendingRequests; 72 | std::list _finishedRequests; 73 | utility::string_t _baseUri; 74 | }; 75 | 76 | } 77 | -------------------------------------------------------------------------------- /impl/httpCurl/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file( 2 | GLOB_RECURSE srcs 3 | LIST_DIRECTORIES false 4 | "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp" 5 | "${CMAKE_CURRENT_SOURCE_DIR}/*.h" 6 | ) 7 | 8 | set(CMAKE_INCLUDE_CURRENT_DIR ON) 9 | 10 | add_library(nakama-impl-http-libcurl OBJECT ${srcs}) 11 | 12 | target_include_directories(nakama-impl-http-libcurl PRIVATE ${CURL_INCLUDE_DIRS}) 13 | 14 | target_link_libraries(nakama-impl-http-libcurl 15 | PUBLIC nakama-api-proto nakama::sdk-interface 16 | ) 17 | 18 | set(HTTP_IMPL_LIB nakama-impl-http-libcurl PARENT_SCOPE) 19 | -------------------------------------------------------------------------------- /impl/httpCurl/NHttpClientLibCurl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include "NHttpClientLibCurlContext.h" 27 | #if __ANDROID__ 28 | #include 29 | #endif 30 | 31 | namespace Nakama { 32 | class NHttpClientLibCurl: public NHttpTransportInterface 33 | { 34 | public: 35 | NHttpClientLibCurl(const NPlatformParameters& platformParameters); 36 | 37 | void setBaseUri(const std::string& uri) override; 38 | void tick() override; 39 | void request(const NHttpRequest& req, const NHttpResponseCallback& callback = nullptr) noexcept override; 40 | void cancelAllRequests() override; 41 | private: 42 | std::unique_ptr _curl_multi; 43 | std::string _base_uri; 44 | // TODO implement curl_easy reuse. 45 | // TODO would be more performant but less safe as a map with CURL* as key 46 | std::list, std::unique_ptr>> _contexts; 47 | void handle_curl_easy_set_opt_error(std::string action, CURLcode code, const NHttpResponseCallback& callback); 48 | std::mutex _mutex; 49 | }; 50 | } 51 | -------------------------------------------------------------------------------- /impl/httpCurl/NHttpClientLibCurlContext.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include 18 | #include 19 | #include "nakama-cpp/NHttpTransportInterface.h" 20 | #include "NHttpClientLibCurlContext.h" 21 | 22 | namespace Nakama 23 | { 24 | NHttpClientLibCurlContext::NHttpClientLibCurlContext(const NHttpResponseCallback callback, curl_slist* headers) : _callback(callback), _headers(headers) 25 | { 26 | } 27 | 28 | NHttpResponseCallback NHttpClientLibCurlContext::get_callback() 29 | { 30 | return _callback; 31 | } 32 | 33 | NHttpClientLibCurlContext::~NHttpClientLibCurlContext() 34 | { 35 | if (_headers != NULL) 36 | { 37 | curl_slist_free_all(_headers); 38 | } 39 | } 40 | 41 | curl_slist* NHttpClientLibCurlContext::get_headers() 42 | { 43 | return _headers; 44 | } 45 | 46 | std::string NHttpClientLibCurlContext::get_body() 47 | { 48 | return _body; 49 | } 50 | 51 | void NHttpClientLibCurlContext::append_body(std::string body) 52 | { 53 | _body += body; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /impl/httpCurl/NHttpClientLibCurlContext.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | 18 | #pragma once 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | namespace Nakama 25 | { 26 | 27 | class NHttpClientLibCurlContext 28 | { 29 | public: 30 | NHttpClientLibCurlContext(const NHttpResponseCallback callback, curl_slist* headers); 31 | ~NHttpClientLibCurlContext(); 32 | 33 | NHttpResponseCallback get_callback(); 34 | curl_slist* get_headers(); 35 | std::string get_body(); 36 | void append_body(std::string body); 37 | 38 | private: 39 | NHttpResponseCallback _callback; 40 | curl_slist* _headers; 41 | std::string _body; 42 | }; 43 | 44 | } 45 | -------------------------------------------------------------------------------- /impl/httpLibHttpClient/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file( 2 | GLOB_RECURSE srcs 3 | LIST_DIRECTORIES false 4 | "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp" 5 | "${CMAKE_CURRENT_SOURCE_DIR}/*.h" 6 | ) 7 | 8 | set(CMAKE_INCLUDE_CURRENT_DIR ON) 9 | 10 | add_library(nakama-impl-http-libhttpclient OBJECT ${srcs}) 11 | 12 | if (APPLE) 13 | target_compile_definitions(nakama-impl-http-libhttpclient INTERFACE "HC_APPLE_POSIX") 14 | endif() 15 | 16 | target_link_libraries(nakama-impl-http-libhttpclient 17 | PUBLIC nakama-api-proto nakama::sdk-interface 18 | # libhttpclient is OBJECT library, so this link wont create 19 | # link time dependency on libhttpclient, but still going to 20 | # configure include paths 21 | PUBLIC ${LIBHTTPCLIENT_TARGET} 22 | ) 23 | set(HTTP_IMPL_LIB nakama-impl-http-libhttpclient PARENT_SCOPE) 24 | -------------------------------------------------------------------------------- /impl/httpLibHttpClient/NHttpClientLibHC.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | namespace Nakama { 25 | class NHttpClientLibHC: public NHttpTransportInterface 26 | { 27 | public: 28 | NHttpClientLibHC(const NPlatformParameters& platformParameters); 29 | ~NHttpClientLibHC() noexcept; 30 | 31 | void setBaseUri(const std::string& uri) override; 32 | 33 | void tick() override; 34 | 35 | void request(const NHttpRequest& req, const NHttpResponseCallback& callback = nullptr) override; 36 | 37 | void cancelAllRequests() override; 38 | private: 39 | void submit_cb(const NHttpResponseCallback &cb, int statusCode, std::string body, std::string err = "") noexcept; 40 | HRESULT prep_hc_call(const NHttpRequest& req, std::unique_ptr& call); 41 | 42 | std::unique_ptr::type, decltype(&XTaskQueueCloseHandle)> m_queue; 43 | std::string m_baseUri; 44 | std::atomic m_queue_terminated; 45 | }; 46 | } 47 | -------------------------------------------------------------------------------- /impl/wsCppRest/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file( 2 | GLOB_RECURSE srcs 3 | LIST_DIRECTORIES false 4 | "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp" 5 | "${CMAKE_CURRENT_SOURCE_DIR}/*.h" 6 | ) 7 | 8 | set(CMAKE_INCLUDE_CURRENT_DIR ON) 9 | find_package(cpprestsdk CONFIG REQUIRED) 10 | find_package(OpenSSL REQUIRED) 11 | 12 | add_library(nakama-impl-ws-cppRest OBJECT ${srcs}) 13 | target_include_directories(nakama-impl-ws-cppRest INTERFACE .) 14 | target_link_libraries(nakama-impl-ws-cppRest 15 | PUBLIC nakama-api-proto nakama::sdk-interface 16 | PRIVATE cpprestsdk::cpprest OpenSSL::SSL 17 | ) 18 | add_library(nakama::impl-ws-cppRest ALIAS nakama-impl-ws-cppRest) 19 | set(WS_IMPL_LIB nakama-impl-ws-cppRest PARENT_SCOPE) 20 | -------------------------------------------------------------------------------- /impl/wsCppRest/CppRestUtils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include "cpprest/asyncrt_utils.h" 20 | 21 | #ifdef _WIN32 22 | #define TO_STD_STR(ws_str) utility::conversions::to_utf8string(ws_str) 23 | #define FROM_STD_STR(utf8str) utility::conversions::to_string_t(utf8str) 24 | #else 25 | #define TO_STD_STR(ws_str) ws_str 26 | #define FROM_STD_STR(utf8str) utf8str 27 | #endif 28 | -------------------------------------------------------------------------------- /impl/wsLibHttpClient/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file( 2 | GLOB_RECURSE srcs 3 | LIST_DIRECTORIES false 4 | "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp" 5 | "${CMAKE_CURRENT_SOURCE_DIR}/*.h" 6 | ) 7 | 8 | set(CMAKE_INCLUDE_CURRENT_DIR ON) 9 | 10 | add_library(nakama-impl-ws-libhttpclient OBJECT ${srcs}) 11 | target_link_libraries(nakama-impl-ws-libhttpclient 12 | PUBLIC nakama-api-proto nakama::sdk-interface 13 | # libhttpclient is OBJECT library, so this link wont create 14 | # link time dependency on libhttpclient, but still going to 15 | # configure include paths 16 | PUBLIC ${LIBHTTPCLIENT_TARGET} 17 | ) 18 | 19 | -------------------------------------------------------------------------------- /impl/wsWslay/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file( 2 | GLOB_RECURSE srcs 3 | LIST_DIRECTORIES false 4 | "${CMAKE_CURRENT_SOURCE_DIR}/*.h" 5 | "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp" 6 | ) 7 | 8 | find_package(wslay CONFIG REQUIRED) 9 | add_library(nakama-impl-ws-wslay OBJECT ${srcs}) 10 | 11 | target_link_libraries(nakama-impl-ws-wslay PUBLIC 12 | nakama-api-proto nakama::sdk-interface 13 | nakama-sdk-core-common nakama-sdk-core-misc 14 | wslay 15 | ) 16 | 17 | target_include_directories(nakama-impl-ws-wslay INTERFACE 18 | "$" 19 | "$") 20 | 21 | 22 | if (BUILD_CURL_IO OR BUILD_CURL_IO_SYSTEM) 23 | target_include_directories(nakama-impl-ws-wslay PRIVATE ${CURL_INCLUDE_DIRS}) 24 | endif() 25 | 26 | target_compile_definitions(nakama-impl-ws-wslay PUBLIC "WSLAY_NETIO_${WSLAY_NETIO}") 27 | -------------------------------------------------------------------------------- /interface/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.23) 2 | project(nakama-sdk-core LANGUAGES CXX) 3 | include(GNUInstallDirs) 4 | 5 | file(GLOB CORE_HEADERS 6 | include/nakama-cpp/* 7 | include/nakama-cpp/data/* 8 | include/nakama-cpp/data/log/* 9 | include/nakama-cpp/data/realtime/* 10 | include/nakama-cpp/data/realtime/rtdata/* 11 | ) 12 | 13 | if (WS_IMPL STREQUAL "wslay") 14 | file(GLOB WSLAY_HEADERS include/nakama-cpp/data/realtime/wslay/*) 15 | list(APPEND CORE_HEADERS ${WSLAY_HEADERS}) 16 | endif() 17 | 18 | 19 | add_library(nakama-sdk-interface INTERFACE ${CORE_HEADERS}) 20 | add_library(nakama::sdk-interface ALIAS nakama-sdk-interface) 21 | 22 | # Force nonstd::optional save our choice in config.h 23 | set(optional_CONFIG_SELECT_OPTIONAL optional_OPTIONAL_NONSTD) 24 | target_compile_definitions(nakama-sdk-interface INTERFACE optional_CONFIG_SELECT_OPTIONAL=${optional_CONFIG_SELECT_OPTIONAL}) 25 | 26 | if (FORCE_DLL_IMPORT_EXPORT) 27 | target_compile_definitions(nakama-sdk-interface INTERFACE FORCE_DLL_IMPORT_EXPORT) 28 | endif() 29 | 30 | # Create configure file with all 31 | configure_file(config.h.in nakama-cpp/config.h) 32 | 33 | target_sources(nakama-sdk-interface INTERFACE 34 | FILE_SET HEADERS FILES BASE_DIRS ${CMAKE_CURRENT_BINARY_DIR} FILES ${CMAKE_CURRENT_BINARY_DIR}/nakama-cpp/config.h 35 | FILE_SET HEADERS FILES BASE_DIRS include FILES ${CORE_HEADERS} 36 | ) 37 | 38 | target_include_directories(nakama-sdk-interface INTERFACE 39 | "$" 40 | "$") 41 | 42 | target_link_libraries(nakama-sdk-interface INTERFACE nonstd::optional-lite) 43 | 44 | -------------------------------------------------------------------------------- /interface/config.h.in: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #cmakedefine optional_CONFIG_SELECT_OPTIONAL @optional_CONFIG_SELECT_OPTIONAL@ 4 | #define @HTTP_COMPILE_DEFINITION@ 5 | #define @WS_COMPILE_DEFINITION@ 6 | #define @WS_IO_COMPILE_DEFINITION@ 7 | -------------------------------------------------------------------------------- /interface/include/nakama-cpp/NException.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include "NError.h" 20 | 21 | namespace Nakama 22 | { 23 | class NException : public std::runtime_error { 24 | public: 25 | NException(const NError& error) 26 | : std::runtime_error(error.message), error(error) {} 27 | 28 | const NError error; 29 | }; 30 | } 31 | -------------------------------------------------------------------------------- /interface/include/nakama-cpp/NExport.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #undef NAKAMA_API 20 | 21 | #if defined _WIN32 || defined __CYGWIN__ || defined FORCE_DLL_IMPORT_EXPORT 22 | #ifdef NAKAMA_SHARED_LIBRARY_EXPORTS 23 | #define NAKAMA_API __declspec(dllexport) 24 | #else 25 | #define NAKAMA_API __declspec(dllimport) 26 | #endif 27 | #elif __GNUC__ >= 4 28 | #ifdef NAKAMA_SHARED_LIBRARY_EXPORTS 29 | #define NAKAMA_API __attribute__((visibility("default"))) 30 | #else 31 | #define NAKAMA_API 32 | #endif 33 | #else 34 | #define NAKAMA_API 35 | #endif 36 | -------------------------------------------------------------------------------- /interface/include/nakama-cpp/NPlatformParams.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include 20 | 21 | #ifdef __ANDROID__ 22 | #include "jni.h" 23 | #endif 24 | 25 | NAKAMA_NAMESPACE_BEGIN 26 | 27 | // Keeping for API stability in the case that we need to add platform-specific features. 28 | struct NPlatformParameters {}; 29 | 30 | NAKAMA_NAMESPACE_END 31 | -------------------------------------------------------------------------------- /interface/include/nakama-cpp/NTypes.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #ifndef NAKAMA_NAMESPACE 28 | #define NAKAMA_NAMESPACE Nakama 29 | #define NAKAMA_NAMESPACE_BEGIN namespace NAKAMA_NAMESPACE { 30 | #define NAKAMA_NAMESPACE_END } 31 | #endif 32 | 33 | NAKAMA_NAMESPACE_BEGIN 34 | 35 | /// The group role status. 36 | enum class NUserGroupState 37 | { 38 | SUPERADMIN = 0, ///< The user is a superadmin with full control of the group. 39 | ADMIN = 1, ///< The user is an admin with additional privileges. 40 | MEMBER = 2, ///< The user is a regular member. 41 | JOIN_REQUEST = 3 ///< The user has requested to join the group 42 | }; 43 | 44 | /// The available channel types on the server. 45 | enum class NChannelType 46 | { 47 | TYPE_UNSPECIFIED = 0, ///< Default case. Assumed as ROOM type. 48 | ROOM = 1, ///< A chat room which can be created dynamically with a name. 49 | DIRECT_MESSAGE = 2, ///< A private chat between two users. 50 | GROUP = 3 ///< A chat within a group on the server. 51 | }; 52 | 53 | /// UNIX time in milliseconds. 54 | /// Use getUnixTimestampMs() to get current time. 55 | using NTimestamp = uint64_t; 56 | 57 | /// array of bytes 58 | using NBytes = std::string; 59 | 60 | using NStringMap = std::map; 61 | using NStringDoubleMap = std::map; 62 | namespace opt = nonstd; 63 | 64 | /// Constant for defaut port. 65 | /// This is not valid port, actual port will be selected automatically. 66 | static const int32_t DEFAULT_PORT = -1; 67 | 68 | NAKAMA_NAMESPACE_END 69 | -------------------------------------------------------------------------------- /interface/include/nakama-cpp/NUtils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include 20 | #include 21 | 22 | NAKAMA_NAMESPACE_BEGIN 23 | 24 | /** 25 | * Get current UNIX time in milliseconds. 26 | * 27 | * Returns number of milliseconds that have elapsed since 00:00:00 Thursday, 1 January 1970. 28 | * 29 | * @return UNIX time in milliseconds. 30 | */ 31 | NAKAMA_API NTimestamp getUnixTimestampMs(); 32 | 33 | NAKAMA_NAMESPACE_END 34 | -------------------------------------------------------------------------------- /interface/include/nakama-cpp/Nakama.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | -------------------------------------------------------------------------------- /interface/include/nakama-cpp/NakamaVersion.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include 20 | #include 21 | 22 | NAKAMA_NAMESPACE_BEGIN 23 | 24 | NAKAMA_API const char* getNakamaSdkVersion(); 25 | 26 | NAKAMA_NAMESPACE_END 27 | -------------------------------------------------------------------------------- /interface/include/nakama-cpp/URLParts.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include 20 | #include 21 | 22 | namespace Nakama { 23 | struct URLParts { 24 | std::string scheme; 25 | std::string host; 26 | opt::optional port; 27 | std::string pathAndArgs; 28 | std::string url; 29 | }; 30 | } 31 | -------------------------------------------------------------------------------- /interface/include/nakama-cpp/data/NAccount.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | NAKAMA_NAMESPACE_BEGIN 27 | 28 | /// A user with additional account details. Always the current user. 29 | struct NAccount { 30 | NUser user; ///< The user object. 31 | std::string wallet; ///< The user's wallet data. 32 | std::string email; ///< The email address of the user. 33 | std::vector devices; ///< The devices which belong to the user's account. 34 | std::string customId; ///< The custom id in the user's account. 35 | NTimestamp verifyTime = 0; ///< The UNIX time when the user's email was verified. 36 | NTimestamp disableTime = 0; ///< The UNIX time when the user's account was disabled/banned. 37 | }; 38 | 39 | using NAccountPtr = std::shared_ptr; 40 | 41 | NAKAMA_NAMESPACE_END 42 | -------------------------------------------------------------------------------- /interface/include/nakama-cpp/data/NAccountDevice.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include 20 | #include 21 | 22 | NAKAMA_NAMESPACE_BEGIN 23 | 24 | /// Used with authenticate/link/unlink and user. 25 | struct NAccountDevice { 26 | std::string id; ///< A device identifier. Should be obtained by a platform-specific device API. 27 | NStringMap vars; ///< Extra information that will be bundled in the session token. 28 | }; 29 | 30 | NAKAMA_NAMESPACE_END 31 | -------------------------------------------------------------------------------- /interface/include/nakama-cpp/data/NChannelMessage.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include 20 | #include 21 | 22 | NAKAMA_NAMESPACE_BEGIN 23 | 24 | /// A message sent on a channel. 25 | struct NChannelMessage 26 | { 27 | std::string channelId; ///< The channel this message belongs to. 28 | std::string messageId; ///< The unique ID of this message. 29 | int32_t code = 0; ///< The code representing a message type or category. 30 | std::string senderId; ///< Message sender, usually a user ID. 31 | std::string username; ///< The username of the message sender, if any. 32 | std::string content; ///< The content payload. 33 | NTimestamp createTime = 0; ///< The UNIX time when the message was created. 34 | NTimestamp updateTime = 0; ///< The UNIX time when the message was last updated. 35 | bool persistent = false; ///< True if the message was persisted to the channel's history, false otherwise. 36 | std::string roomName; ///< The name of the chat room, or an empty string if this message was not sent through a chat room. 37 | std::string groupId; ///< The ID of the group, or an empty string if this message was not sent through a group channel. 38 | std::string userIdOne; ///< The ID of the first DM user, or an empty string if this message was not sent through a DM chat. 39 | std::string userIdTwo; ///< The ID of the second DM user, or an empty string if this message was not sent through a DM chat. 40 | }; 41 | 42 | NAKAMA_NAMESPACE_END 43 | -------------------------------------------------------------------------------- /interface/include/nakama-cpp/data/NChannelMessageList.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | NAKAMA_NAMESPACE_BEGIN 26 | 27 | /// A list of channel messages, usually a result of a list operation. 28 | struct NChannelMessageList 29 | { 30 | std::vector messages; ///< A list of messages. 31 | std::string nextCursor; ///< The cursor to send when retireving the next page, if any. 32 | std::string prevCursor; ///< The cursor to send when retrieving the previous page, if any. 33 | }; 34 | 35 | using NChannelMessageListPtr = std::shared_ptr; 36 | 37 | NAKAMA_NAMESPACE_END 38 | -------------------------------------------------------------------------------- /interface/include/nakama-cpp/data/NFriend.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | NAKAMA_NAMESPACE_BEGIN 24 | 25 | /// A friend of a user. 26 | struct NFriend 27 | { 28 | /// The friendship status. 29 | enum class State { 30 | FRIEND = 0, ///< The user is a friend of the current user. 31 | INVITE_SENT = 1, ///< The current user has sent an invite to the user. 32 | INVITE_RECEIVED = 2, ///< The current user has received an invite from this user. 33 | BLOCKED = 3 ///< The current user has blocked this user. 34 | }; 35 | 36 | NUser user; ///< The user object. 37 | State state; ///< The friend status. 38 | NTimestamp updateTime = 0; ///< Time of the latest relationship update. 39 | }; 40 | 41 | NAKAMA_NAMESPACE_END 42 | -------------------------------------------------------------------------------- /interface/include/nakama-cpp/data/NFriendList.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | NAKAMA_NAMESPACE_BEGIN 26 | 27 | ///< A collection of zero or more friends of the user. 28 | struct NFriendList 29 | { 30 | std::vector friends; ///< The Friend objects. 31 | std::string cursor; ///< Cursor for the next page of results, if any. 32 | }; 33 | 34 | using NFriendListPtr = std::shared_ptr; 35 | 36 | NAKAMA_NAMESPACE_END 37 | -------------------------------------------------------------------------------- /interface/include/nakama-cpp/data/NGroup.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include 20 | #include 21 | 22 | NAKAMA_NAMESPACE_BEGIN 23 | 24 | /// A group in the server. 25 | struct NGroup 26 | { 27 | std::string id; ///< The id of a group. 28 | std::string creatorId; ///< The id of the user who created the group. 29 | std::string name; ///< The unique name of the group. 30 | std::string description; ///< A description for the group. 31 | std::string lang; ///< The language expected to be a tag which follows the BCP-47 spec. 32 | std::string metadata; ///< Additional information stored as a JSON object. 33 | std::string avatarUrl; ///< A URL for an avatar image. 34 | bool open = false; ///< Anyone can join open groups, otherwise only admins can accept members. 35 | int32_t edgeCount = 0; ///< The current count of all members in the group. 36 | int32_t maxCount = 0; ///< The maximum number of members allowed. 37 | NTimestamp createTime = 0; ///< The UNIX time when the group was created. 38 | NTimestamp updateTime = 0; ///< The UNIX time when the group was last updated. 39 | }; 40 | 41 | NAKAMA_NAMESPACE_END 42 | -------------------------------------------------------------------------------- /interface/include/nakama-cpp/data/NGroupList.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | NAKAMA_NAMESPACE_BEGIN 26 | 27 | /// One or more groups returned from a listing operation. 28 | struct NGroupList 29 | { 30 | std::vector groups; ///< One or more groups. 31 | std::string cursor; ///< A cursor used to get the next page. 32 | }; 33 | 34 | using NGroupListPtr = std::shared_ptr; 35 | 36 | NAKAMA_NAMESPACE_END 37 | -------------------------------------------------------------------------------- /interface/include/nakama-cpp/data/NGroupUser.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | NAKAMA_NAMESPACE_BEGIN 24 | 25 | /// A single user-role pair. 26 | struct NGroupUser 27 | { 28 | NUser user; ///< User. 29 | NUserGroupState state; ///< Their relationship to the group. 30 | }; 31 | 32 | NAKAMA_NAMESPACE_END 33 | -------------------------------------------------------------------------------- /interface/include/nakama-cpp/data/NGroupUserList.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | NAKAMA_NAMESPACE_BEGIN 26 | 27 | /// A list of users belonging to a group, along with their role. 28 | struct NGroupUserList 29 | { 30 | std::vector groupUsers; ///< User-role pairs for a group. 31 | std::string cursor; ///< Cursor for the next page of results, if any. 32 | }; 33 | 34 | using NGroupUserListPtr = std::shared_ptr; 35 | 36 | NAKAMA_NAMESPACE_END 37 | -------------------------------------------------------------------------------- /interface/include/nakama-cpp/data/NLeaderboardRecord.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include 20 | #include 21 | 22 | #include 23 | #include 24 | 25 | NAKAMA_NAMESPACE_BEGIN 26 | 27 | /// Represents a complete leaderboard record with all scores and associated metadata. 28 | struct NLeaderboardRecord 29 | { 30 | std::string leaderboardId; ///< The ID of the leaderboard this score belongs to. 31 | std::string ownerId; ///< The ID of the score owner, usually a user or group. 32 | std::string username; ///< The username of the score owner, if the owner is a user. 33 | std::int64_t score = 0; ///< The score value. 34 | std::int64_t subscore = 0; ///< An optional subscore value. 35 | int32_t numScore = 0; ///< The number of submissions to this score record. 36 | uint32_t maxNumScore = 0; ///< The maximum number of score updates allowed by the owner. 37 | std::string metadata; ///< Metadata. 38 | NTimestamp createTime = 0; ///< The UNIX time when the leaderboard record was created. 39 | NTimestamp updateTime = 0; ///< The UNIX time when the leaderboard record was updated. 40 | NTimestamp expiryTime = 0; ///< The UNIX time when the leaderboard record expires. 41 | std::int64_t rank = 0; ///< The rank of this record. 42 | }; 43 | 44 | NAKAMA_NAMESPACE_END 45 | -------------------------------------------------------------------------------- /interface/include/nakama-cpp/data/NLeaderboardRecordList.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | NAKAMA_NAMESPACE_BEGIN 27 | 28 | /// A set of leaderboard records, may be part of a leaderboard records page or a batch of individual records. 29 | struct NLeaderboardRecordList 30 | { 31 | std::vector records; ///< A list of leaderboard records. 32 | std::vector ownerRecords; ///< A batched set of leaderboard records belonging to specified owners. 33 | std::string nextCursor; ///< The cursor to send when retrieving the next page, if any. 34 | std::string prevCursor; ///< The cursor to send when retrieving the previous page, if any. 35 | }; 36 | 37 | using NLeaderboardRecordListPtr = std::shared_ptr; 38 | 39 | NAKAMA_NAMESPACE_END 40 | -------------------------------------------------------------------------------- /interface/include/nakama-cpp/data/NMatch.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | NAKAMA_NAMESPACE_BEGIN 24 | 25 | /// Represents a realtime match. 26 | struct NMatch 27 | { 28 | std::string matchId; ///< The ID of the match, can be used to join. 29 | bool authoritative = false; ///< True if it's an server-managed authoritative match, false otherwise. 30 | std::string label; ///< Match label, if any. 31 | int32_t size = 0; ///< Current number of users in the match. 32 | std::vector presences; ///< The users currently in the match. 33 | NUserPresence self; ///< A reference to the current user's presence in the match. 34 | }; 35 | 36 | NAKAMA_NAMESPACE_END 37 | -------------------------------------------------------------------------------- /interface/include/nakama-cpp/data/NMatchList.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | NAKAMA_NAMESPACE_BEGIN 26 | 27 | /// A list of realtime matches. 28 | struct NMatchList 29 | { 30 | std::vector matches; ///< A number of matches corresponding to a list operation. 31 | }; 32 | 33 | using NMatchListPtr = std::shared_ptr; 34 | 35 | NAKAMA_NAMESPACE_END 36 | -------------------------------------------------------------------------------- /interface/include/nakama-cpp/data/NNotification.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include 20 | #include 21 | 22 | NAKAMA_NAMESPACE_BEGIN 23 | 24 | /// A notification in the server. 25 | struct NNotification 26 | { 27 | std::string id; ///< ID of the Notification. 28 | std::string subject; ///< Subject of the notification. 29 | std::string content; ///< Content of the notification in JSON. 30 | int32_t code = 0; ///< Category code for this notification. 31 | std::string senderId; ///< ID of the sender, if a user. Otherwise 'null'. 32 | NTimestamp createTime = 0; ///< The UNIX time when the notification was created. 33 | bool persistent = false; ///< True if this notification was persisted to the database. 34 | }; 35 | 36 | NAKAMA_NAMESPACE_END 37 | -------------------------------------------------------------------------------- /interface/include/nakama-cpp/data/NNotificationList.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | NAKAMA_NAMESPACE_BEGIN 26 | 27 | /// A collection of zero or more notifications. 28 | struct NNotificationList 29 | { 30 | std::vector notifications; ///< Collection of notifications. 31 | std::string cacheableCursor; ///< Use this cursor to paginate notifications. Cache this to catch up to new notifications. 32 | }; 33 | 34 | using NNotificationListPtr = std::shared_ptr; 35 | 36 | NAKAMA_NAMESPACE_END 37 | -------------------------------------------------------------------------------- /interface/include/nakama-cpp/data/NRpc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include 20 | #include 21 | 22 | NAKAMA_NAMESPACE_BEGIN 23 | 24 | /// Execute an Lua function on the server. 25 | struct NRpc 26 | { 27 | std::string id; ///< The identifier of the function. 28 | std::string payload; ///< The payload of the function which must be a JSON object. 29 | std::string httpKey; ///< The authentication key used when executed as a non-client HTTP request. 30 | }; 31 | 32 | NAKAMA_NAMESPACE_END 33 | -------------------------------------------------------------------------------- /interface/include/nakama-cpp/data/NStorageObject.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | NAKAMA_NAMESPACE_BEGIN 25 | 26 | /// An object within the storage engine. 27 | struct NStorageObject 28 | { 29 | std::string collection; ///< The collection which stores the object. 30 | std::string key; ///< The key of the object within the collection. 31 | std::string userId; ///< The user owner of the object. 32 | std::string value; ///< The value of the object. 33 | std::string version; ///< The version hash of the object. 34 | NStoragePermissionRead permissionRead 35 | = NStoragePermissionRead::NO_READ; ///< The read access permissions for the object. 36 | NStoragePermissionWrite permissionWrite 37 | = NStoragePermissionWrite::NO_WRITE; ///< The write access permissions for the object. 38 | NTimestamp createTime = 0; ///< The UNIX time when the object was created. 39 | NTimestamp updateTime = 0; ///< The UNIX time when the object was last updated. 40 | }; 41 | 42 | using NStorageObjects = std::vector; 43 | 44 | NAKAMA_NAMESPACE_END 45 | -------------------------------------------------------------------------------- /interface/include/nakama-cpp/data/NStorageObjectAck.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | NAKAMA_NAMESPACE_BEGIN 24 | 25 | /// A storage acknowledgement. 26 | struct NStorageObjectAck 27 | { 28 | std::string collection; ///< The collection which stores the object. 29 | std::string key; ///< The key of the object within the collection. 30 | std::string version; ///< The version hash of the object. 31 | std::string userId; ///< The owner of the object. 32 | }; 33 | 34 | /// Batch of acknowledgements. 35 | using NStorageObjectAcks = std::vector; 36 | 37 | NAKAMA_NAMESPACE_END 38 | -------------------------------------------------------------------------------- /interface/include/nakama-cpp/data/NStorageObjectId.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include 20 | #include 21 | 22 | NAKAMA_NAMESPACE_BEGIN 23 | 24 | /// Storage objects to get. 25 | struct NReadStorageObjectId 26 | { 27 | std::string collection; ///< The collection which stores the object. 28 | std::string key; ///< The key of the object within the collection. 29 | std::string userId; ///< The user owner of the object. 30 | }; 31 | 32 | /// Storage objects to delete. 33 | struct NDeleteStorageObjectId 34 | { 35 | std::string collection; ///< The collection which stores the object. 36 | std::string key; ///< The key of the object within the collection. 37 | std::string version; ///< The version hash of the object. 38 | }; 39 | 40 | NAKAMA_NAMESPACE_END 41 | -------------------------------------------------------------------------------- /interface/include/nakama-cpp/data/NStorageObjectList.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | NAKAMA_NAMESPACE_BEGIN 26 | 27 | /// List of storage objects. 28 | struct NStorageObjectList 29 | { 30 | std::vector objects; ///< The list of storage objects. 31 | std::string cursor; ///< The cursor for the next page of results, if any. 32 | }; 33 | 34 | using NStorageObjectListPtr = std::shared_ptr; 35 | 36 | NAKAMA_NAMESPACE_END 37 | -------------------------------------------------------------------------------- /interface/include/nakama-cpp/data/NStorageObjectWrite.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | NAKAMA_NAMESPACE_BEGIN 25 | 26 | /// The object to store. 27 | struct NStorageObjectWrite 28 | { 29 | std::string collection; ///< The collection which stores the object. 30 | std::string key; ///< The key of the object within the collection. 31 | std::string value; ///< The value of the object. Must be JSON 32 | std::string version; ///< The version hash of the object to check. Possible values are: ["", "*", "#hash#"]. 33 | opt::optional permissionRead; ///< The read access permissions for the object. 34 | opt::optional permissionWrite; ///< The write access permissions for the object. 35 | }; 36 | 37 | NAKAMA_NAMESPACE_END 38 | -------------------------------------------------------------------------------- /interface/include/nakama-cpp/data/NStoragePermissions.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include 20 | #include 21 | 22 | NAKAMA_NAMESPACE_BEGIN 23 | 24 | /// The read access permissions. 25 | enum class NStoragePermissionRead 26 | { 27 | NO_READ = 0, ///< The object is only readable by server runtime. 28 | OWNER_READ = 1, ///< Only the user who owns it may access. 29 | PUBLIC_READ = 2 ///< Any user can read the object. 30 | }; 31 | 32 | /// The write access permissions. 33 | enum class NStoragePermissionWrite 34 | { 35 | NO_WRITE = 0, ///< The object is only writable by server runtime. 36 | OWNER_WRITE = 1 ///< Only the user who owns it may write. 37 | }; 38 | 39 | NAKAMA_NAMESPACE_END 40 | -------------------------------------------------------------------------------- /interface/include/nakama-cpp/data/NTournamentList.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | NAKAMA_NAMESPACE_BEGIN 26 | 27 | /// A list of tournaments. 28 | struct NTournamentList 29 | { 30 | std::vector tournaments; ///< The list of tournaments returned. 31 | std::string cursor; ///< A pagination cursor (optional). 32 | }; 33 | 34 | using NTournamentListPtr = std::shared_ptr; 35 | 36 | NAKAMA_NAMESPACE_END 37 | -------------------------------------------------------------------------------- /interface/include/nakama-cpp/data/NTournamentRecordList.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | NAKAMA_NAMESPACE_BEGIN 27 | 28 | /// A set of tournament records which may be part of a tournament records page or a batch of individual records. 29 | struct NTournamentRecordList 30 | { 31 | std::vector records; ///< A list of tournament records. 32 | std::vector ownerRecords; ///< A batched set of tournament records belonging to specified owners. 33 | std::string nextCursor; ///< The cursor to send when retireving the next page, if any. 34 | std::string prevCursor; ///< The cursor to send when retrieving the previous page, if any. 35 | }; 36 | 37 | using NTournamentRecordListPtr = std::shared_ptr; 38 | 39 | NAKAMA_NAMESPACE_END 40 | -------------------------------------------------------------------------------- /interface/include/nakama-cpp/data/NUser.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | NAKAMA_NAMESPACE_BEGIN 24 | 25 | /// A user in the server. 26 | struct NUser 27 | { 28 | std::string id; ///< The id of the user's account. 29 | std::string username; ///< The username of the user's account. 30 | std::string displayName; ///< The display name of the user. 31 | std::string avatarUrl; ///< A URL for an avatar image. 32 | std::string lang; ///< The language expected to be a tag which follows the BCP-47 spec. 33 | std::string location; ///< The location set by the user. 34 | std::string timeZone; ///< The timezone set by the user. 35 | std::string metadata; ///< Additional information stored as a JSON object. 36 | std::string facebookId; ///< The Facebook id in the user's account. 37 | std::string googleId; ///< The Google id in the user's account. 38 | std::string gameCenterId; ///< The Apple Game Center in of the user's account. 39 | std::string appleId; ///< The Apple Sign In ID in the user's account. 40 | std::string steamId; ///< The Steam id in the user's account. 41 | bool online = false; ///< Indicates whether the user is currently online. 42 | int32_t edgeCount = 0; ///< Number of related edges to this user (friends). 43 | NTimestamp createdAt = 0; ///< The UNIX time when the user was created. 44 | NTimestamp updatedAt = 0; ///< The UNIX time when the user was last updated. 45 | }; 46 | 47 | NAKAMA_NAMESPACE_END 48 | -------------------------------------------------------------------------------- /interface/include/nakama-cpp/data/NUserGroup.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | NAKAMA_NAMESPACE_BEGIN 24 | 25 | /// A single group-role pair. 26 | struct NUserGroup 27 | { 28 | NGroup group; ///< Group. 29 | NUserGroupState state; ///< The user's relationship to the group. 30 | }; 31 | 32 | NAKAMA_NAMESPACE_END 33 | -------------------------------------------------------------------------------- /interface/include/nakama-cpp/data/NUserGroupList.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | NAKAMA_NAMESPACE_BEGIN 26 | 27 | /// A list of groups belonging to a user, along with the user's role in each group. 28 | struct NUserGroupList 29 | { 30 | std::vector userGroups; ///< Group-role pairs for a user. 31 | std::string cursor; ///< Cursor for the next page of results, if any. 32 | }; 33 | 34 | using NUserGroupListPtr = std::shared_ptr; 35 | 36 | NAKAMA_NAMESPACE_END 37 | -------------------------------------------------------------------------------- /interface/include/nakama-cpp/data/NUsers.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | NAKAMA_NAMESPACE_BEGIN 24 | 25 | /// A collection of zero or more users. 26 | struct NUsers 27 | { 28 | std::vector users; 29 | }; 30 | 31 | NAKAMA_NAMESPACE_END 32 | -------------------------------------------------------------------------------- /interface/include/nakama-cpp/log/NConsoleLogSink.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | NAKAMA_NAMESPACE_BEGIN 24 | 25 | /// Writes logs to console output 26 | class NAKAMA_API NConsoleLogSink : public NLogSinkInterface 27 | { 28 | public: 29 | ~NConsoleLogSink() {} 30 | 31 | void log(NLogLevel level, const std::string& message, const char* func) override; 32 | 33 | void flush() override; 34 | }; 35 | 36 | NAKAMA_NAMESPACE_END 37 | -------------------------------------------------------------------------------- /interface/include/nakama-cpp/log/NLogSinkInterface.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | NAKAMA_NAMESPACE_BEGIN 24 | 25 | enum class NLogLevel 26 | { 27 | Debug = 1, 28 | Info = 2, 29 | Warn = 3, 30 | Error = 4, 31 | Fatal = 5 32 | }; 33 | 34 | class NAKAMA_API NLogSinkInterface 35 | { 36 | public: 37 | NLogSinkInterface() {} 38 | virtual ~NLogSinkInterface() {} 39 | 40 | /** 41 | * Output log message 42 | * 43 | * @param level the level of log message 44 | * @param message the log message string 45 | * @param func the function name from which log message comes. 46 | * Usually has class name e.g. `NDefaultClient::onResponse` 47 | */ 48 | virtual void log(NLogLevel level, const std::string& message, const char* func = nullptr) = 0; 49 | 50 | /** 51 | * Flush cached data. 52 | */ 53 | virtual void flush() = 0; 54 | 55 | /** 56 | * Set the logging level boundary 57 | * 58 | * @param level the logging level boundary 59 | */ 60 | void setLevel(NLogLevel level) { _level = level; } 61 | 62 | /** 63 | * Get the logging level boundary 64 | * 65 | * @return NLogLevel 66 | */ 67 | NLogLevel getLevel() const { return _level; } 68 | 69 | protected: 70 | NLogLevel _level = NLogLevel::Info; 71 | }; 72 | 73 | using NLogSinkPtr = std::shared_ptr; 74 | 75 | NAKAMA_NAMESPACE_END 76 | -------------------------------------------------------------------------------- /interface/include/nakama-cpp/realtime/NRtClientDisconnectInfo.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include 20 | #include 21 | 22 | NAKAMA_NAMESPACE_BEGIN 23 | 24 | struct NRtClientDisconnectInfo 25 | { 26 | enum Code { 27 | NORMAL_CLOSURE = 1000, 28 | GOING_AWAY = 1001, 29 | PROTOCOL_ERROR = 1002, 30 | UNSUPPORTED_DATA = 1003, 31 | NO_STATUS_RCVD = 1005, 32 | ABNORMAL_CLOSURE = 1006, 33 | INVALID_FRAME_PAYLOAD_DATA = 1007, 34 | POLICY_VIOLATION = 1008, 35 | MESSAGE_TOO_BIG = 1009, 36 | MANDATORY_EXT = 1010, 37 | INTERNAL_SERVER_ERROR = 1011, 38 | TLS_HANDSHAKE = 1015, 39 | 40 | HEARTBEAT_FAILURE = 4000, 41 | TRANSPORT_ERROR = 4001 42 | }; 43 | 44 | /// close code. 45 | /// https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent 46 | uint16_t code = 0; 47 | 48 | /// close reason. Optional. 49 | std::string reason; 50 | 51 | /// true if close was initiated by server. 52 | bool remote = false; 53 | }; 54 | 55 | NAKAMA_NAMESPACE_END 56 | -------------------------------------------------------------------------------- /interface/include/nakama-cpp/realtime/NWebsocketsFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | #if defined BUILD_WEBSOCKET_WSLAY 25 | #include 26 | #endif 27 | 28 | NAKAMA_NAMESPACE_BEGIN 29 | 30 | /** 31 | * Create default websocket transport. 32 | * 33 | */ 34 | #if !defined(WITH_EXTERNAL_WS) && !defined(BUILD_IO_EXTERNAL) 35 | NAKAMA_API NRtTransportPtr createDefaultWebsocket(const NPlatformParameters& platformParameters); 36 | #endif 37 | 38 | #if defined BUILD_WEBSOCKET_WSLAY 39 | NAKAMA_API NRtTransportPtr createWslayWebsocket(std::unique_ptr io); 40 | #endif 41 | 42 | 43 | NAKAMA_NAMESPACE_END 44 | -------------------------------------------------------------------------------- /interface/include/nakama-cpp/realtime/rtdata/NChannel.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | NAKAMA_NAMESPACE_BEGIN 26 | 27 | /// A realtime chat channel. 28 | struct NChannel 29 | { 30 | std::string id; ///< The ID of the channel. 31 | std::vector presences; ///< The users currently in the channel. 32 | NUserPresence self; ///< A reference to the current user's presence in the channel. 33 | std::string roomName; ///< The name of the chat room, or an empty string if this message was not sent through a chat room. 34 | std::string groupId; ///< The ID of the group, or an empty string if this message was not sent through a group channel. 35 | std::string userIdOne; ///< The ID of the first DM user, or an empty string if this message was not sent through a DM chat. 36 | std::string userIdTwo; ///< The ID of the second DM user, or an empty string if this message was not sent through a DM chat. 37 | }; 38 | 39 | using NChannelPtr = std::shared_ptr; 40 | 41 | NAKAMA_NAMESPACE_END 42 | -------------------------------------------------------------------------------- /interface/include/nakama-cpp/realtime/rtdata/NChannelMessageAck.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | NAKAMA_NAMESPACE_BEGIN 24 | 25 | /// A receipt reply from a channel message send operation. 26 | struct NChannelMessageAck 27 | { 28 | std::string channelId; ///< The channel the message was sent to. 29 | std::string messageId; ///< The unique ID assigned to the message. 30 | std::string username; ///< Username of the message sender. 31 | int32_t code = 0; ///< The code representing a message type or category. 32 | NTimestamp createTime = 0; ///< The UNIX time when the message was created. 33 | NTimestamp updateTime = 0; ///< The UNIX time when the message was last updated. 34 | bool persistent = false; ///< True if the message was persisted to the channel's history, false otherwise. 35 | std::string roomName; ///< The name of the chat room, or an empty string if this message was not sent through a chat room. 36 | std::string groupId; ///< The ID of the group, or an empty string if this message was not sent through a group channel. 37 | std::string userIdOne; ///< The ID of the first DM user, or an empty string if this message was not sent through a DM chat. 38 | std::string userIdTwo; ///< The ID of the second DM user, or an empty string if this message was not sent through a DM chat. 39 | }; 40 | 41 | NAKAMA_NAMESPACE_END 42 | -------------------------------------------------------------------------------- /interface/include/nakama-cpp/realtime/rtdata/NChannelPresenceEvent.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | NAKAMA_NAMESPACE_BEGIN 25 | 26 | /// A set of joins and leaves on a particular channel. 27 | struct NChannelPresenceEvent 28 | { 29 | std::string channelId; ///< The channel identifier this event is for. 30 | std::vector joins; ///< Presences joining the channel as part of this event, if any. 31 | std::vector leaves; ///< Presences leaving the channel as part of this event, if any. 32 | std::string roomName; ///< The name of the chat room, or an empty string if this message was not sent through a chat room. 33 | std::string groupId; ///< The ID of the group, or an empty string if this message was not sent through a group channel. 34 | std::string userIdOne; ///< The ID of the first DM user, or an empty string if this message was not sent through a DM chat. 35 | std::string userIdTwo; ///< The ID of the second DM user, or an empty string if this message was not sent through a DM chat. 36 | }; 37 | 38 | NAKAMA_NAMESPACE_END 39 | -------------------------------------------------------------------------------- /interface/include/nakama-cpp/realtime/rtdata/NMatchData.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | NAKAMA_NAMESPACE_BEGIN 24 | 25 | /// Realtime match data received from the server. 26 | struct NMatchData 27 | { 28 | std::string matchId; ///< The match unique ID. 29 | NUserPresence presence; ///< A reference to the user presence that sent this data, if any. 30 | std::int64_t opCode; ///< Op code value. 31 | NBytes data; ///< Data payload, if any. 32 | }; 33 | 34 | NAKAMA_NAMESPACE_END 35 | -------------------------------------------------------------------------------- /interface/include/nakama-cpp/realtime/rtdata/NMatchPresenceEvent.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | NAKAMA_NAMESPACE_BEGIN 25 | 26 | /// A set of joins and leaves on a particular realtime match. 27 | struct NMatchPresenceEvent 28 | { 29 | std::string matchId; /// The match unique ID. 30 | std::vector joins; /// User presences that have just joined the match. 31 | std::vector leaves; /// User presences that have just left the match. 32 | }; 33 | 34 | NAKAMA_NAMESPACE_END 35 | -------------------------------------------------------------------------------- /interface/include/nakama-cpp/realtime/rtdata/NMatchmakerMatched.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | NAKAMA_NAMESPACE_BEGIN 26 | 27 | struct NMatchmakerUser 28 | { 29 | NUserPresence presence; ///< User info. 30 | NStringMap stringProperties; ///< String properties. 31 | NStringDoubleMap numericProperties; ///< Numeric properties. 32 | }; 33 | 34 | /// A successful matchmaking result. 35 | struct NMatchmakerMatched 36 | { 37 | std::string ticket; ///< The matchmaking ticket that has completed. 38 | ///< The match token or match ID to join. 39 | std::string matchId; ///< Match ID. 40 | std::string token; ///< Match join token. 41 | std::vector users; ///< The users that have been matched together, and information about their matchmaking data. 42 | NMatchmakerUser self; ///< A reference to the current user and their properties. 43 | }; 44 | 45 | using NMatchmakerMatchedPtr = std::shared_ptr; 46 | 47 | NAKAMA_NAMESPACE_END 48 | -------------------------------------------------------------------------------- /interface/include/nakama-cpp/realtime/rtdata/NMatchmakerTicket.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | 24 | NAKAMA_NAMESPACE_BEGIN 25 | 26 | /// A ticket representing a new matchmaking process. 27 | struct NMatchmakerTicket 28 | { 29 | std::string ticket; ///< The ticket that can be used to cancel matchmaking. 30 | }; 31 | 32 | NAKAMA_NAMESPACE_END 33 | -------------------------------------------------------------------------------- /interface/include/nakama-cpp/realtime/rtdata/NParty.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | NAKAMA_NAMESPACE_BEGIN 25 | 26 | /// Information about a party. 27 | struct NParty 28 | { 29 | std::string id; /// The unique party identifier. 30 | 31 | bool open; /// True, if the party is open to join. 32 | 33 | int maxSize; /// The maximum number of party members. 34 | 35 | NUserPresence self; /// The current user in this party. i.e. Yourself. 36 | 37 | NUserPresence leader; /// The current party leader. 38 | 39 | std::vector presences; /// All members currently in the party. 40 | }; 41 | 42 | NAKAMA_NAMESPACE_END -------------------------------------------------------------------------------- /interface/include/nakama-cpp/realtime/rtdata/NPartyClose.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | NAKAMA_NAMESPACE_BEGIN 24 | 25 | /// Information about a party close event. 26 | struct NPartyClose 27 | { 28 | std::string id; /// The unique party identifier of the closing party. 29 | }; 30 | 31 | NAKAMA_NAMESPACE_END -------------------------------------------------------------------------------- /interface/include/nakama-cpp/realtime/rtdata/NPartyData.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | NAKAMA_NAMESPACE_BEGIN 26 | 27 | /// Incoming party data delivered from the server. 28 | struct NPartyData 29 | { 30 | /// The ID of the party. 31 | std::string partyId; 32 | 33 | /// A reference to the user presence that sent this data, if any. 34 | NUserPresence presence; 35 | 36 | /// The operation code the message was sent with. 37 | std::int64_t opCode; 38 | 39 | /// Data payload, if any. 40 | NBytes data; 41 | }; 42 | 43 | NAKAMA_NAMESPACE_END -------------------------------------------------------------------------------- /interface/include/nakama-cpp/realtime/rtdata/NPartyJoinRequest.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | NAKAMA_NAMESPACE_BEGIN 26 | 27 | /// Incoming notification for one or more new presences attempting to join the party. 28 | struct NPartyJoinRequest 29 | { 30 | /// The ID of the party to get a list of join requests for. 31 | std::string partyId; 32 | 33 | /// Presences attempting to join, or who have joined. 34 | std::vector presences; 35 | }; 36 | 37 | NAKAMA_NAMESPACE_END -------------------------------------------------------------------------------- /interface/include/nakama-cpp/realtime/rtdata/NPartyLeader.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | NAKAMA_NAMESPACE_BEGIN 26 | 27 | /// Announcement of a new party leader. 28 | struct NPartyLeader 29 | { 30 | /// The ID of the party to announce the new leader for. 31 | std::string partyId; 32 | 33 | /// The presence of the new party leader. 34 | NUserPresence presence; 35 | }; 36 | 37 | NAKAMA_NAMESPACE_END -------------------------------------------------------------------------------- /interface/include/nakama-cpp/realtime/rtdata/NPartyMatchmakerTicket.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | NAKAMA_NAMESPACE_BEGIN 25 | 26 | /// A response from starting a new party matchmaking process. 27 | struct NPartyMatchmakerTicket 28 | { 29 | /// The ID of the party. 30 | std::string partyId; 31 | 32 | /// The ticket that can be used to cancel matchmaking. 33 | std::string ticket; 34 | }; 35 | 36 | NAKAMA_NAMESPACE_END -------------------------------------------------------------------------------- /interface/include/nakama-cpp/realtime/rtdata/NPartyPresenceEvent.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | NAKAMA_NAMESPACE_BEGIN 26 | 27 | /// Presence update for a particular party. 28 | struct NPartyPresenceEvent 29 | { 30 | /// The ID of the party. 31 | std::string partyId; 32 | 33 | /// The user presences that have just joined the party. 34 | std::vector joins; 35 | 36 | /// The user presences that have just left the party. 37 | std::vector leaves; 38 | }; 39 | 40 | NAKAMA_NAMESPACE_END -------------------------------------------------------------------------------- /interface/include/nakama-cpp/realtime/rtdata/NRtException.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include "NRtError.h" 20 | 21 | namespace Nakama 22 | { 23 | class NRtException : public std::runtime_error { 24 | public: 25 | NRtException(const NRtError& error) 26 | : std::runtime_error(error.message), error(error) {} 27 | 28 | const NRtError error; 29 | }; 30 | } 31 | -------------------------------------------------------------------------------- /interface/include/nakama-cpp/realtime/rtdata/NStatus.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | NAKAMA_NAMESPACE_BEGIN 25 | 26 | /// A snapshot of statuses for some set of users. 27 | struct NStatus 28 | { 29 | std::vector presences; ///< User statuses. 30 | }; 31 | 32 | NAKAMA_NAMESPACE_END 33 | -------------------------------------------------------------------------------- /interface/include/nakama-cpp/realtime/rtdata/NStatusPresenceEvent.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | NAKAMA_NAMESPACE_BEGIN 25 | 26 | /// A batch of status updates for a given user. 27 | struct NStatusPresenceEvent 28 | { 29 | std::vector joins; ///< New statuses for the user. 30 | std::vector leaves; ///< Previous statuses for the user. 31 | }; 32 | 33 | NAKAMA_NAMESPACE_END 34 | -------------------------------------------------------------------------------- /interface/include/nakama-cpp/realtime/rtdata/NStream.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | 24 | NAKAMA_NAMESPACE_BEGIN 25 | 26 | /// Represents identifying information for a stream. 27 | struct NStream 28 | { 29 | int32_t mode = 0; ///< Mode identifies the type of stream. 30 | std::string subject; ///< Subject is the primary identifier, if any. 31 | std::string subcontext; ///< Subcontext is a secondary identifier, if any. 32 | std::string label; ///< The label is an arbitrary identifying string, if the stream has one. 33 | }; 34 | 35 | NAKAMA_NAMESPACE_END 36 | -------------------------------------------------------------------------------- /interface/include/nakama-cpp/realtime/rtdata/NStreamData.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | NAKAMA_NAMESPACE_BEGIN 25 | 26 | /// A data message delivered over a stream. 27 | struct NStreamData 28 | { 29 | NStream stream; ///< The stream this data message relates to. 30 | NUserPresence sender; ///< The sender, if any. 31 | std::string data; ///< Arbitrary contents of the data message. 32 | }; 33 | 34 | NAKAMA_NAMESPACE_END 35 | -------------------------------------------------------------------------------- /interface/include/nakama-cpp/realtime/rtdata/NStreamPresenceEvent.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | NAKAMA_NAMESPACE_BEGIN 26 | 27 | /// A set of joins and leaves on a particular stream. 28 | struct NStreamPresenceEvent 29 | { 30 | NStream stream; ///< The stream this event relates to. 31 | std::vector joins; ///< Presences joining the stream as part of this event, if any. 32 | std::vector leaves; ///< Presences leaving the stream as part of this event, if any. 33 | }; 34 | 35 | NAKAMA_NAMESPACE_END 36 | -------------------------------------------------------------------------------- /interface/include/nakama-cpp/realtime/rtdata/NUserPresence.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | 24 | NAKAMA_NAMESPACE_BEGIN 25 | 26 | /// A user session associated to a stream, usually through a list operation or a join/leave event. 27 | struct NUserPresence 28 | { 29 | std::string userId; ///< The user this presence belongs to. 30 | std::string sessionId; ///< A unique session ID identifying the particular connection, because the user may have many. 31 | std::string username; ///< The username for display purposes. 32 | bool persistence = false; ///< Whether this presence generates persistent data/messages, if applicable for the stream type. 33 | std::string status; ///< A user-set status message for this stream, if applicable. 34 | }; 35 | 36 | NAKAMA_NAMESPACE_END 37 | -------------------------------------------------------------------------------- /interface/include/nakama-cpp/realtime/wslay/WslayIOInterface.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "nakama-cpp/URLParts.h" 4 | 5 | namespace Nakama { 6 | 7 | // Result of async operation 8 | enum class NetIOAsyncResult { 9 | ERR = -1, // error, no further progress possible 10 | AGAIN = 0, // to be called again 11 | DONE = 1, // successful completion 12 | }; 13 | 14 | class WslayIOInterface { 15 | public: 16 | virtual ~WslayIOInterface() {} 17 | virtual int recv(void* buf, size_t len, int* wouldBlock) = 0; 18 | virtual int send(const void* data, size_t len, int* wouldBlock) = 0; 19 | virtual void close() = 0; 20 | virtual NetIOAsyncResult connect_init(const URLParts& urlParts) = 0; 21 | virtual NetIOAsyncResult connect_tick() = 0; 22 | }; 23 | 24 | } -------------------------------------------------------------------------------- /nakama-sdk-config.cmake.in: -------------------------------------------------------------------------------- 1 | @PACKAGE_INIT@ 2 | 3 | #################################################################################### 4 | 5 | include ( ${CMAKE_CURRENT_LIST_DIR}/nakama-export.cmake ) 6 | -------------------------------------------------------------------------------- /nakama-sdk-preconfig.cmake.in: -------------------------------------------------------------------------------- 1 | set(NAKAMA_SDK_BUILD_TYPE "@NAKAMA_SDK_BUILD_TYPE@") 2 | -------------------------------------------------------------------------------- /scripts/Dockerfile: -------------------------------------------------------------------------------- 1 | # syntax=docker/dockerfile:1.4 2 | ARG UBUNTU_BASE=ubuntu:20.04 3 | FROM $UBUNTU_BASE 4 | 5 | ENV DEBIAN_FRONTEND=noninteractive 6 | 7 | RUN rm -f /etc/apt/apt.conf.d/docker-clean; echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache 8 | RUN --mount=type=cache,target=/var/cache/apt --mount=type=cache,target=/var/lib/apt \ 9 | apt update && apt-get install --no-install-recommends -y libc-dev curl zip unzip ca-certificates busybox git-core pkg-config software-properties-common make 10 | 11 | RUN --mount=type=cache,target=/var/cache/apt --mount=type=cache,target=/var/lib/apt < 12 | cmake --build build/ --target install run 13 | ``` 14 | 15 | To build and deploy for iOS, you will need to pass `-- -allowProvisioningUpdates` to the end of your cmake build command. 16 | 17 | To build for Android, inside the `android` folder: 18 | 19 | `./gradlew assemble -Pabi= -Phost=` where ANDROID_ABI and HOST is one of those defined in `CMakePresets.json`. 20 | 21 | For example: 22 | `./gradlew assemble -Pabi=arm64-v8a -Phost=osx_arm64` 23 | 24 | We provide an optional helper for deploying to an Android device: `deploy.sh `. The device ID can be obtained through `adb devices`. 25 | -------------------------------------------------------------------------------- /test/android/.gitattributes: -------------------------------------------------------------------------------- 1 | # 2 | # https://help.github.com/articles/dealing-with-line-endings/ 3 | # 4 | # These are explicitly windows files and should use crlf 5 | *.bat text eol=crlf 6 | 7 | -------------------------------------------------------------------------------- /test/android/.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore Gradle project-specific cache directory 2 | .gradle 3 | 4 | # Ignore Gradle build output directory 5 | build 6 | /.cxx/ 7 | -------------------------------------------------------------------------------- /test/android/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | buildscript { 18 | dependencies { 19 | classpath 'com.android.tools.build:gradle:7.3.0' 20 | } 21 | } 22 | plugins { 23 | id('com.android.application') version '7.1.1' 24 | } 25 | 26 | dependencies { 27 | implementation files("../../out/android-${abi}/lib/libnakama-sdk.aar") 28 | } 29 | 30 | repositories { 31 | google() 32 | mavenCentral() 33 | gradlePluginPortal() 34 | 35 | } 36 | 37 | android { 38 | compileSdkVersion 30 39 | defaultConfig { 40 | applicationId "com.heroiclabs.nakamatest" 41 | minSdkVersion 21 42 | targetSdkVersion 31 43 | versionCode 1 44 | versionName '1.0' 45 | ndk { 46 | abiFilters "${abi}" 47 | } 48 | externalNativeBuild { 49 | cmake { 50 | arguments '--preset', 51 | "android-${abi}-host_${host}", 52 | // TODO figure out why assigning these in CMakePresets.json cache variables doesn't work 53 | "-DANDROID_STL=c++_shared", 54 | "-DCMAKE_BUILD_TYPE=Debug" 55 | targets 'nakama-test' 56 | } 57 | } 58 | } 59 | externalNativeBuild { 60 | cmake { 61 | version "3.25.0+" 62 | path "../CMakeLists.txt" 63 | } 64 | } 65 | buildTypes { 66 | customDebugType { 67 | debuggable true 68 | } 69 | release { 70 | minifyEnabled false 71 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /test/android/deploy.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | adb -s "$1" uninstall com.heroiclabs.nakamatest 4 | adb -s "$1" install ./build/outputs/apk/debug/nakamatest-debug.apk 5 | adb logcat -c 6 | adb shell am start -n com.heroiclabs.nakamatest/.MainActivity 7 | adb logcat -------------------------------------------------------------------------------- /test/android/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heroiclabs/nakama-cpp/27322aaffe264bc991f7726189b5aea32040e6cf/test/android/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /test/android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | android.enablePrefab=true 7 | android.enableParallelJsonGen=false 8 | android.prefabVersion=${prefab.version} -------------------------------------------------------------------------------- /test/android/settings.gradle: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | repositories { 3 | gradlePluginPortal() 4 | google() 5 | mavenCentral() 6 | } 7 | } 8 | 9 | rootProject.name = 'nakamatest' -------------------------------------------------------------------------------- /test/android/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 7 | 8 | 22 | 23 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /test/android/src/main/java/com/heroiclabs/nakamatest/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.heroiclabs.nakamatest; 2 | 3 | import android.app.Activity; 4 | import android.util.Log; 5 | import android.os.Bundle; 6 | 7 | public class MainActivity extends Activity { 8 | @Override 9 | protected void onCreate(final Bundle savedInstanceState) { 10 | // load sdk first so that it may initialize before the test application 11 | Log.i("libnakama-test MainActivity", "Loading libnakama..."); 12 | System.loadLibrary("nakama-sdk"); 13 | Log.i("libnakama-test MainActivity", "Loading libnakama-test..."); 14 | System.loadLibrary("nakama-test"); 15 | } 16 | } -------------------------------------------------------------------------------- /test/include/NTestLib.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include "nakama-cpp/NUtils.h" 20 | #include "nakama-cpp/NPlatformParams.h" 21 | #include "nakama-cpp/ClientFactory.h" 22 | 23 | #if defined NAKAMA_TEST_SHARED_LIBRARY && (defined _WIN32 || defined __CYGWIN__ || defined FORCE_DLL_IMPORT_EXPORT) 24 | #ifdef NAKAMA_TEST_SHARED_LIBRARY_EXPORTS 25 | #define NAKAMA_TEST_API __declspec(dllexport) 26 | #else 27 | #define NAKAMA_TEST_API __declspec(dllimport) 28 | #endif 29 | #elif defined NAKAMA_TEST_SHARED_LIBRARY && __GNUC__ >= 4 30 | #ifdef NAKAMA_TEST_SHARED_LIBRARY_EXPORTS 31 | #define NAKAMA_TEST_API __attribute__((visibility("default"))) 32 | #else 33 | #define NAKAMA_TEST_API 34 | #endif 35 | #else 36 | #define NAKAMA_TEST_API 37 | #endif 38 | 39 | 40 | 41 | namespace Nakama { 42 | namespace Test { 43 | 44 | NAKAMA_TEST_API int runAllTests(std::function clientFactory, std::function rtClientFactory, NClientParameters parameters, std::string serverHttpKey); 45 | 46 | } 47 | } -------------------------------------------------------------------------------- /test/nakama-test-config.cmake.in: -------------------------------------------------------------------------------- 1 | @PACKAGE_INIT@ 2 | 3 | #################################################################################### 4 | 5 | include ( ${CMAKE_CURRENT_LIST_DIR}/nakama-test-export.cmake ) 6 | -------------------------------------------------------------------------------- /test/src/TestGuid.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include "TestGuid.h" 22 | 23 | namespace Nakama { 24 | namespace Test { 25 | // unlikely to meet the uniqueness + unpredictability requirements of a real GUID generator, 26 | // but more portable than any other library and good enough for a test suite. 27 | std::string TestGuid::newGuid() { 28 | std::random_device rd; 29 | std::mt19937_64 gen(rd()); 30 | std::uniform_int_distribution dis(0, std::numeric_limits::max()); 31 | 32 | // Generate 128 bits of random data 33 | uint64_t data1 = dis(gen); 34 | uint64_t data2 = dis(gen); 35 | 36 | // Format the data as a GUID 37 | std::stringstream ss; 38 | ss << std::hex << std::setfill('0') << std::setw(16) << data1 << std::setw(16) << data2; 39 | std::string guid = ss.str(); 40 | 41 | // Insert hyphens at the appropriate positions 42 | guid.insert(20, "-"); 43 | guid.insert(16, "-"); 44 | guid.insert(12, "-"); 45 | guid.insert(8, "-"); 46 | 47 | return guid; 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /test/src/TestGuid.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include 18 | 19 | namespace Nakama 20 | { 21 | namespace Test 22 | { 23 | class TestGuid 24 | { 25 | public: 26 | static std::string newGuid(); 27 | }; 28 | }; 29 | } -------------------------------------------------------------------------------- /test/src/globals.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "nakama-cpp/log/NLogger.h" 18 | #include "NTest.h" 19 | #include "globals.h" 20 | 21 | namespace Nakama { 22 | namespace Test { 23 | uint32_t g_runTestsCount = 0; 24 | uint32_t g_failedTestsCount = 0; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /test/src/globals.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include "nakama-cpp/log/NLogger.h" 20 | #include "NTest.h" 21 | 22 | namespace Nakama { 23 | namespace Test { 24 | static inline void NTEST_ASSERT(bool cond) 25 | { 26 | if (!cond) 27 | { 28 | NLOG_INFO("TEST ASSERT FAILED!"); 29 | NLOG_INFO(std::string(__FILE__) + ":" + std::to_string(__LINE__)); 30 | abort(); 31 | } 32 | } 33 | 34 | // stats 35 | extern uint32_t g_runTestsCount; 36 | extern uint32_t g_failedTestsCount; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /test/src/realtime/test_authoritative_match.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "nakama-cpp/log/NLogger.h" 18 | #include "NTest.h" 19 | #define RAPIDJSON_HAS_STDSTRING 1 20 | #include "rapidjson/document.h" 21 | #include "TestGuid.h" 22 | 23 | namespace Nakama { 24 | namespace Test { 25 | 26 | using namespace std; 27 | 28 | void test_authoritative_match() 29 | { 30 | bool threadedTick = true; 31 | NTest test(__func__ , threadedTick); 32 | NTest test2("test_authoritative_match_join", threadedTick); 33 | 34 | test.runTest(); 35 | test2.runTest(); 36 | 37 | NSessionPtr session = test.client->authenticateCustomAsync(TestGuid::newGuid(), std::string(), true).get(); 38 | bool createStatus = false; 39 | test.rtClient->connectAsync(session, createStatus, NTest::RtProtocol).get(); 40 | 41 | NSessionPtr session2 = test2.client->authenticateCustomAsync(TestGuid::newGuid(), std::string(), true).get(); 42 | test2.rtClient->connectAsync(session2, createStatus, NTest::RtProtocol).get(); 43 | 44 | const NRpc rpc = test.rtClient->rpcAsync("clientrpc.create_authoritative_match", "{\"debug\": true, \"label\": \"TestAuthoritativeMatch\"}").get(); 45 | 46 | rapidjson::Document document; 47 | if (!document.Parse(rpc.payload).HasParseError()) 48 | { 49 | auto& jsonMatchId = document["match_id"]; 50 | 51 | if (jsonMatchId.IsString()) 52 | { 53 | string matchId = jsonMatchId.GetString(); 54 | test2.rtClient->joinMatchAsync(matchId, {}).get(); 55 | } 56 | else 57 | { 58 | test.stopTest(false); 59 | } 60 | } 61 | else 62 | { 63 | test.stopTest(false); 64 | } 65 | 66 | test.stopTest(true); 67 | test2.stopTest(true); 68 | } 69 | 70 | } // namespace Test 71 | } // namespace Nakama 72 | -------------------------------------------------------------------------------- /test/src/realtime/test_chat.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "nakama-cpp/log/NLogger.h" 18 | #include "NTest.h" 19 | #include "TestGuid.h" 20 | 21 | namespace Nakama { 22 | namespace Test { 23 | 24 | void test_rt_joinChat() 25 | { 26 | bool threadedTick = true; 27 | NTest test(__func__, threadedTick); 28 | test.runTest(); 29 | 30 | NSessionPtr session = test.client->authenticateCustomAsync(TestGuid::newGuid(), std::string(), true).get(); 31 | bool createStatus = false; 32 | test.rtClient->connectAsync(session, createStatus, NTest::RtProtocol).get(); 33 | 34 | // data must be JSON 35 | std::string json_data = "{\"msg\":\"Hello there!\"}"; 36 | 37 | const NChannelPtr channel = test.rtClient->joinChatAsync("chat", NChannelType::ROOM, {}, {}).get(); 38 | const NChannelMessageAck ack = test.rtClient->writeChatMessageAsync(channel->id, json_data).get(); 39 | 40 | NLOG_INFO("call stop test"); 41 | test.stopTest(ack.channelId == channel->id); 42 | NLOG_INFO("done call stop test"); 43 | } 44 | 45 | void test_rt_joinGroupChat() 46 | { 47 | NLOG_INFO("calling join group chat"); 48 | 49 | bool threadedTick = true; 50 | NTest test(__func__, threadedTick); 51 | test.runTest(); 52 | NSessionPtr session = test.client->authenticateCustomAsync(TestGuid::newGuid(), std::string(), true).get(); 53 | bool createStatus = false; 54 | test.rtClient->connectAsync(session, createStatus, NTest::RtProtocol).get(); 55 | const NGroup group = test.client->createGroupAsync(session, TestGuid::newGuid(), "a group for chatting", "", "", false, {}).get(); 56 | const NChannelPtr channelPtr = test.rtClient->joinChatAsync(group.id, NChannelType::GROUP, {}, {}).get(); 57 | test.stopTest(true); 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /test/src/realtime/test_realtime.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include 18 | #include "NTest.h" 19 | #include "globals.h" 20 | 21 | namespace Nakama { 22 | namespace Test { 23 | 24 | using namespace std; 25 | 26 | void test_rt_match(); 27 | void test_notifications(); 28 | void test_authoritative_match(); 29 | void test_tournament(); 30 | void test_rpc(); 31 | void test_rt_party(); 32 | void test_rt_joinChat(); 33 | void test_rt_joinGroupChat(); 34 | void test_rt_quickdestroy(); 35 | void test_rt_rapiddisconnect(); 36 | void test_rt_reconnect(); 37 | void test_rt_connect_callback(); 38 | void test_rt_double_connect(); 39 | void test_rt_double_connect_async(); 40 | void test_rt_simultaneous_connect(); 41 | 42 | void test_connectivity_loss(); 43 | 44 | void run_realtime_tests() 45 | { 46 | test_rt_joinChat(); 47 | test_rt_joinGroupChat(); 48 | test_rt_match(); 49 | test_notifications(); 50 | test_authoritative_match(); 51 | test_tournament(); 52 | test_rpc(); 53 | test_rt_party(); 54 | } 55 | 56 | void test_realtime() 57 | { 58 | // These tests are not protocol specific 59 | test_rt_rapiddisconnect(); 60 | test_rt_connect_callback(); 61 | test_rt_double_connect(); 62 | test_rt_double_connect_async(); 63 | // optional test. requires session.single_socket to be true in server configuration. 64 | // test_rt_simultaneous_connect(); 65 | 66 | // optional "test". run websocket for a full minute. useful for testing connection loss with network link conditioner. 67 | // test_connectivity_loss(); 68 | 69 | /// change to 10 iterations to trigger https://github.com/microsoft/libHttpClient/issues/698 bug 70 | for (int i = 0; i < 1; i++) { 71 | test_rt_reconnect(); 72 | } 73 | 74 | NTest::RtProtocol = NRtClientProtocol::Json; 75 | run_realtime_tests(); 76 | 77 | NTest::RtProtocol = NRtClientProtocol::Protobuf; 78 | run_realtime_tests(); 79 | } 80 | 81 | } // namespace Test 82 | } // namespace Nakama 83 | -------------------------------------------------------------------------------- /test/src/test_disconnect.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "NTest.h" 18 | #include "nakama-cpp/log/NLogger.h" 19 | 20 | namespace Nakama { 21 | namespace Test { 22 | 23 | using namespace std; 24 | 25 | void test_connectError() 26 | { 27 | NClientParameters parameters; 28 | parameters.port = 1111; 29 | 30 | NTest test(__func__, parameters); 31 | test.setTestTimeoutMs(20000); 32 | 33 | auto successCallback = [&test](NSessionPtr session) 34 | { 35 | test.stopTest(); 36 | }; 37 | 38 | auto errorCallback = [&test](const NError& error) 39 | { 40 | NLOG_INFO("connect error " + std::to_string((int) error.code)); 41 | 42 | test.stopTest(error.code == ErrorCode::ConnectionError || error.code == ErrorCode::CancelledByUser); 43 | }; 44 | 45 | test.client->authenticateDevice("mytestdevice0001", opt::nullopt, opt::nullopt, {}, successCallback, errorCallback); 46 | 47 | test.runTest(); 48 | } 49 | 50 | void test_disconnection() 51 | { 52 | NTest test(__func__); 53 | 54 | auto successCallback = [&test](NSessionPtr session) 55 | { 56 | NLOG_INFO("session token: " + session->getAuthToken()); 57 | test.stopTest(true); 58 | }; 59 | 60 | auto errorCallback = [&test](const NError& error) 61 | { 62 | test.stopTest(error); 63 | }; 64 | 65 | test.client->authenticateDevice("mytestdevice0001", opt::nullopt, opt::nullopt, {}, successCallback, errorCallback); 66 | 67 | test.client->disconnect(); 68 | 69 | test.runTest(); 70 | } 71 | 72 | void test_disconnect() 73 | { 74 | test_connectError(); 75 | //test_disconnection(); depending on transport implementation either success or error may be legitimately called. Test is inheritly racy 76 | } 77 | 78 | } // namespace Test 79 | } // namespace Nakama 80 | -------------------------------------------------------------------------------- /test/src/test_getAccount.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "nakama-cpp/log/NLogger.h" 18 | #include "NTest.h" 19 | 20 | namespace Nakama { 21 | namespace Test { 22 | 23 | using namespace std; 24 | 25 | void test_getAccount() 26 | { 27 | NTest test(__func__); 28 | 29 | auto successCallback = [&test](NSessionPtr session) 30 | { 31 | NLOG_INFO("session token: " + session->getAuthToken()); 32 | 33 | auto successCallback = [&test, session](const NAccount& account) 34 | { 35 | NLOG_INFO("account user id: " + account.user.id); 36 | 37 | auto successCallback = [&test]() 38 | { 39 | NLOG_INFO("account updated"); 40 | test.stopTest(true); 41 | }; 42 | 43 | test.client->updateAccount(session, 44 | opt::nullopt, 45 | "Nakama-test", 46 | opt::nullopt, 47 | opt::nullopt, 48 | opt::nullopt, 49 | opt::nullopt, 50 | successCallback); 51 | }; 52 | 53 | test.client->getAccount(session, successCallback); 54 | }; 55 | 56 | test.client->authenticateDevice("mytestdevice0000", opt::nullopt, true, {}, successCallback); 57 | 58 | test.runTest(); 59 | } 60 | 61 | } // namespace Test 62 | } // namespace Nakama 63 | -------------------------------------------------------------------------------- /test/src/test_internals.cpp: -------------------------------------------------------------------------------- 1 | // unit tests, can use non public headers 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include "nakama-cpp/log/NLogger.h" 8 | 9 | // Copy of internal function from StrUtil so that we can test it 10 | std::string encodeURIComponent(std::string decoded) 11 | { 12 | std::ostringstream oss; 13 | std::regex r("[-.0-9A-Za-z_~]"); 14 | 15 | for (char c : decoded) 16 | { 17 | if (std::regex_match(std::string(1, c), r)) 18 | { 19 | oss << c; 20 | } 21 | else 22 | { 23 | oss <<'%' << std::uppercase << std::hex << static_cast(0xff & c) ; 24 | } 25 | } 26 | return oss.str(); 27 | } 28 | 29 | namespace Nakama { 30 | namespace Test { 31 | 32 | void test_uriencode() { 33 | std::string input = u8"βσκαταη3"; 34 | std::string encoded = encodeURIComponent(input); 35 | std::string expected = "%CE%B2%CF%83%CE%BA%CE%B1%CF%84%CE%B1%CE%B73"; 36 | 37 | if (encoded != expected) { 38 | NLOG_ERROR("Expected: " + expected); 39 | NLOG_ERROR("Encoded: " + encoded); 40 | abort(); 41 | } 42 | 43 | NLOG_INFO("test_uriencode passed"); 44 | } 45 | 46 | 47 | void test_internals() { 48 | unsigned char c = char(120); 49 | test_uriencode(); 50 | } 51 | 52 | } 53 | } 54 | 55 | -------------------------------------------------------------------------------- /test/src/test_listMatches.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 The Nakama Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "NTest.h" 18 | #include "globals.h" 19 | 20 | namespace Nakama { 21 | namespace Test { 22 | 23 | using namespace std; 24 | 25 | class NMatchListTest : public NTest 26 | { 27 | NSessionPtr session; 28 | 29 | public: 30 | explicit NMatchListTest(const char* name) : NTest(name) {} 31 | 32 | void runTest() override 33 | { 34 | auto successCallback = [this](NSessionPtr sess) 35 | { 36 | this->session = sess; 37 | 38 | NLOG_INFO("session token: " + sess->getAuthToken()); 39 | 40 | listMatches(); 41 | }; 42 | 43 | client->authenticateDevice("mytestdevice0000", opt::nullopt, true, {}, successCallback); 44 | 45 | NTest::runTest(); 46 | } 47 | 48 | void listMatches() 49 | { 50 | auto rpcSuccessCallback = [this](const NRpc& rpc) 51 | { 52 | auto successCallback = [this](NMatchListPtr matchList) 53 | { 54 | NLOG_INFO("Expecting match count to be 2. Actual count: " + std::to_string(matchList->matches.size())); 55 | NTEST_ASSERT(matchList->matches.size() == 2); 56 | stopTest(true); 57 | }; 58 | 59 | int minPlayers = 0; 60 | int maxPlayers = 10; 61 | int limit = 10; 62 | bool authoritative = true; 63 | string label = ""; 64 | string query = "+label.type:freeforall +label.difficulty:>1"; 65 | client->listMatches(session, minPlayers, maxPlayers, limit, label, query, authoritative, successCallback); 66 | }; 67 | 68 | client->rpc(session, "create_matches", "", rpcSuccessCallback); 69 | } 70 | }; 71 | 72 | void test_listMatches() 73 | { 74 | NMatchListTest test(__func__); 75 | test.runTest(); 76 | } 77 | 78 | } // namespace Test 79 | } // namespace Nakama 80 | -------------------------------------------------------------------------------- /test/test.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | -------------------------------------------------------------------------------- /test/vcpkg-configuration.json: -------------------------------------------------------------------------------- 1 | { 2 | "registries": 3 | [ 4 | { 5 | "kind": "builtin", 6 | "baseline": "4cb4a5c5ddcb9de0c83c85837ee6974c8333f032", 7 | "packages": [] 8 | }, 9 | { 10 | "kind": "git", 11 | "repository": "https://github.com/heroiclabs/nakama-vcpkg-registry", 12 | "baseline": "d6557f2635c62879dd58a7719cbfc917c10d42ff", 13 | "reference": "master", 14 | "packages": ["nakama-sdk", "wslay"] 15 | } 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /test/vcpkg.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nakama-test", 3 | "builtin-baseline": "4cb4a5c5ddcb9de0c83c85837ee6974c8333f032", 4 | "version-string": "0.0.0", 5 | "default-features": [], 6 | "dependencies": [ 7 | { 8 | "name": "rapidjson", 9 | "version>=": "2020-09-14#2" 10 | }, 11 | "optional-lite", 12 | "protobuf", 13 | "curl" 14 | ], 15 | "overrides": [ 16 | {"name": "wslay", "version": "1.1.1#6"} 17 | ], 18 | "features": { 19 | "nakama-sdk": { 20 | "description": "Use the vcpkg installation of the nakama sdk", 21 | "dependencies": [ 22 | { 23 | "name": "nakama-sdk", 24 | "version>=": "2.8.0#5", 25 | "platform": "ios | osx | linux", 26 | "features": ["wslay", "curl-io", "curl-http", "logs"] 27 | }, 28 | { 29 | "name": "nakama-sdk", 30 | "version>=": "2.8.0#5", 31 | "platform": "windows", 32 | "features": ["wslay", "curl-io", "curl-http", "logs"] 33 | }, 34 | { 35 | "name": "nakama-sdk", 36 | "version>=": "2.8.0#5", 37 | "platform": "android", 38 | "features": ["wslay", "curl-io", "curl-http", "logs"] 39 | } 40 | ] 41 | }, 42 | "wslay": { 43 | "description": "Websockets library decoupled from IO and handshakes. For testing static Nakama builds.", 44 | "dependencies": [ 45 | { 46 | "name": "wslay" 47 | } 48 | ] 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /vcpkg-configuration.json: -------------------------------------------------------------------------------- 1 | { 2 | "registries": 3 | [ 4 | { 5 | "kind": "builtin", 6 | "baseline": "b4f29c54450ddfc7efd2989cb9d32158ae291b40", 7 | "packages": [] 8 | }, 9 | { 10 | "kind": "git", 11 | "repository": "https://github.com/heroiclabs/nakama-vcpkg-registry", 12 | "baseline": "8a1b872ce6626dfdba5692ffa8c5170f7e40652c", 13 | "reference": "master", 14 | "packages": ["nakama-sdk", "wslay"] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /version.cmake: -------------------------------------------------------------------------------- 1 | # Easy to update by CI scripts file containing our version as well as 2 | # dependent git repos to achieve reproducible builds 3 | 4 | set(LIBNAKAMA_VERSION 2.8.5) 5 | --------------------------------------------------------------------------------