├── .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