mirror of
https://github.com/tribufu/sdk-cpp
synced 2025-06-15 11:44:20 +00:00
Use native tribufu sdk
This commit is contained in:
@ -1,12 +0,0 @@
|
||||
# Shared
|
||||
|
||||
[profile.dev]
|
||||
lto = "off"
|
||||
|
||||
[profile.release]
|
||||
lto = "thin"
|
||||
|
||||
# Windows
|
||||
|
||||
[target.'cfg(target_os = "windows")']
|
||||
rustflags = ["-C", "target-feature=+crt-static"]
|
16
Cargo.toml
16
Cargo.toml
@ -1,16 +0,0 @@
|
||||
[package]
|
||||
name = "tribufu-native"
|
||||
version = "0.0.4"
|
||||
description = "Tribufu Native"
|
||||
repository = "https://github.com/Tribufu/TribufuNative"
|
||||
authors = ["Tribufu <contact@tribufu.com>"]
|
||||
license = "Apache-2.0"
|
||||
edition = "2021"
|
||||
publish = false
|
||||
|
||||
[lib]
|
||||
name = "tribufu_native"
|
||||
crate-type = ["staticlib"]
|
||||
path = "src/lib.rs"
|
||||
|
||||
[dependencies]
|
@ -1,157 +0,0 @@
|
||||
language = "C"
|
||||
header = "// Copyright (c) Tribufu. All Rights Reserved."
|
||||
pragma_once = true
|
||||
include_version = false
|
||||
namespaces = []
|
||||
using_namespaces = []
|
||||
sys_includes = ["tribufu/prelude.h"]
|
||||
includes = []
|
||||
no_includes = true
|
||||
cpp_compat = false
|
||||
braces = "NextLine"
|
||||
line_length = 100
|
||||
tab_width = 4
|
||||
documentation = true
|
||||
documentation_style = "doxy"
|
||||
style = "tag"
|
||||
|
||||
[defines]
|
||||
"debug_assertions" = "TRIBUFU_DEVEL"
|
||||
"not(debug_assertions)" = "TRIBUFU_RETAIL"
|
||||
"panic = abort" = "TRIBUFU_PANIC_ABORT"
|
||||
"panic = unwind" = "TRIBUFU_PANIC_UNWIND"
|
||||
"proc_macro" = "TRIBUFU_PROC_MACRO"
|
||||
"target_arch = aarch64" = "TRIBUFU_AARCH64"
|
||||
"target_arch = arm" = "TRIBUFU_ARM"
|
||||
"target_arch = armV7" = "TRIBUFU_ARMV7"
|
||||
"target_arch = armv4t" = "TRIBUFU_ARMV4T"
|
||||
"target_arch = armv6" = "TRIBUFU_ARMV6"
|
||||
"target_arch = armv7a" = "TRIBUFU_ARMV7A"
|
||||
"target_arch = armv7s" = "TRIBUFU_ARMV7S"
|
||||
"target_arch = avr" = "TRIBUFU_AVR"
|
||||
"target_arch = bpfeb" = "TRIBUFU_BPFEB"
|
||||
"target_arch = bpfel" = "TRIBUFU_BPFEL"
|
||||
"target_arch = hexagon" = "TRIBUFU_HEXAGON"
|
||||
"target_arch = i386" = "TRIBUFU_I386"
|
||||
"target_arch = i586" = "TRIBUFU_I586"
|
||||
"target_arch = i686" = "TRIBUFU_I686"
|
||||
"target_arch = m68k" = "TRIBUFU_M68K"
|
||||
"target_arch = mips" = "TRIBUFU_MIPS"
|
||||
"target_arch = mipsel" = "TRIBUFU_MIPSEL"
|
||||
"target_arch = msp430" = "TRIBUFU_MSP430"
|
||||
"target_arch = powerpc" = "TRIBUFU_POWERPC"
|
||||
"target_arch = powerpc64" = "TRIBUFU_POWERPC64"
|
||||
"target_arch = powerpc64l" = "TRIBUFU_POWERPC64L"
|
||||
"target_arch = riscv32gc" = "TRIBUFU_RISCV32GC"
|
||||
"target_arch = s390x" = "TRIBUFU_S390X"
|
||||
"target_arch = sparc" = "TRIBUFU_SPARC"
|
||||
"target_arch = sparc64" = "TRIBUFU_SPARC64"
|
||||
"target_arch = thumbv4t" = "TRIBUFU_THUMBV4T"
|
||||
"target_arch = thumbv7a" = "TRIBUFU_THUMBV7A"
|
||||
"target_arch = thumbv7neon" = "TRIBUFU_THUMBV7NEON"
|
||||
"target_arch = wasm32" = "TRIBUFU_WASM32"
|
||||
"target_arch = wasm64" = "TRIBUFU_WASM64"
|
||||
"target_arch = x86" = "TRIBUFU_X86"
|
||||
"target_arch = x86_64" = "TRIBUFU_X86_64"
|
||||
"target_endian = big" = "TRIBUFU_BIG_ENDIAN"
|
||||
"target_endian = little" = "TRIBUFU_LITTLE_ENDIAN"
|
||||
"target_env = gnu" = "TRIBUFU_GNU"
|
||||
"target_env = msvc" = "TRIBUFU_MSVC"
|
||||
"target_env = musl" = "TRIBUFU_MUSL"
|
||||
"target_env = sgx" = "TRIBUFU_SGX"
|
||||
"target_family = unix" = "TRIBUFU_UNIX"
|
||||
"target_family = wasm" = "TRIBUFU_WASM"
|
||||
"target_family = windows" = "TRIBUFU_MICROSOFT"
|
||||
"target_feature = avx" = "TRIBUFU_AVX"
|
||||
"target_feature = avx2" = "TRIBUFU_AVX2"
|
||||
"target_feature = crt-static" = "TRIBUFU_CRTSTATIC"
|
||||
"target_feature = rdrand" = "TRIBUFU_RDRAND"
|
||||
"target_feature = sse" = "TRIBUFU_SSE"
|
||||
"target_feature = sse2" = "TRIBUFU_SSE2"
|
||||
"target_feature = sse4.1" = "TRIBUFU_SSE41"
|
||||
"target_has_atomic = 128" = "TRIBUFU_ATOMIC_128"
|
||||
"target_has_atomic = 16" = "TRIBUFU_ATOMIC_16"
|
||||
"target_has_atomic = 32" = "TRIBUFU_ATOMIC_32"
|
||||
"target_has_atomic = 64" = "TRIBUFU_ATOMIC_64"
|
||||
"target_has_atomic = 8" = "TRIBUFU_ATOMIC_8"
|
||||
"target_has_atomic = ptr" = "TRIBUFU_ATOMIC_PTR"
|
||||
"target_os = android" = "TRIBUFU_ANDROID"
|
||||
"target_os = dragonfly" = "TRIBUFU_DRAGONFLY"
|
||||
"target_os = freebsd" = "TRIBUFU_FREEBSD"
|
||||
"target_os = ios" = "TRIBUFU_IOS"
|
||||
"target_os = linux" = "TRIBUFU_LINUX"
|
||||
"target_os = macos" = "TRIBUFU_MACOS"
|
||||
"target_os = netbsd" = "TRIBUFU_NETBSD"
|
||||
"target_os = openbsd" = "TRIBUFU_OPENBSD"
|
||||
"target_os = windows" = "TRIBUFU_WINDOWS"
|
||||
"target_pointer_width = 16" = "TRIBUFU_POINTER_16"
|
||||
"target_pointer_width = 32" = "TRIBUFU_POINTER_32"
|
||||
"target_pointer_width = 64" = "TRIBUFU_POINTER_64"
|
||||
"target_vendor = apple" = "TRIBUFU_APPLE"
|
||||
"target_vendor = fortanix" = "TRIBUFU_FORTANIX"
|
||||
"target_vendor = pc" = "TRIBUFU_MICROSOFT"
|
||||
"target_vendor = unknown" = "TRIBUFU_UNKNOWN"
|
||||
|
||||
[export]
|
||||
include = []
|
||||
exclude = []
|
||||
item_types = ["enums", "structs", "typedefs", "functions"]
|
||||
renaming_overrides_prefixing = false
|
||||
|
||||
[layout]
|
||||
packed = "PACKED"
|
||||
aligned_n = "ALIGNED"
|
||||
|
||||
[fn]
|
||||
prefix = "NATIVE_API"
|
||||
args = "horizontal"
|
||||
must_use = "MUST_USE_FUNC"
|
||||
no_return = "NO_RETURN"
|
||||
rename_args = "None"
|
||||
sort_by = "Name"
|
||||
|
||||
[struct]
|
||||
rename_fields = "None"
|
||||
must_use = "MUST_USE_STRUCT"
|
||||
derive_constructor = true
|
||||
derive_eq = false
|
||||
derive_neq = false
|
||||
derive_lt = false
|
||||
derive_lte = false
|
||||
derive_gt = false
|
||||
derive_gte = false
|
||||
|
||||
[enum]
|
||||
rename_variants = "None"
|
||||
add_sentinel = false
|
||||
prefix_with_name = false
|
||||
enum_class = false
|
||||
derive_helper_methods = false
|
||||
derive_const_casts = false
|
||||
derive_mut_casts = false
|
||||
must_use = "MUST_USE_ENUM"
|
||||
derive_tagged_enum_destructor = false
|
||||
derive_tagged_enum_copy_constructor = false
|
||||
derive_tagged_enum_copy_assignment = false
|
||||
private_default_tagged_enum_constructor = false
|
||||
|
||||
[const]
|
||||
allow_static_const = true
|
||||
allow_constexpr = false
|
||||
sort_by = "Name"
|
||||
|
||||
[macro_expansion]
|
||||
bitflags = true
|
||||
|
||||
[parse]
|
||||
parse_deps = true
|
||||
include = []
|
||||
exclude = []
|
||||
clean = false
|
||||
extra_bindings = []
|
||||
|
||||
[parse.expand]
|
||||
crates = []
|
||||
all_features = true
|
||||
default_features = true
|
||||
features = []
|
@ -1,11 +1,31 @@
|
||||
// Copyright (c) Tribufu. All Rights Reserved.
|
||||
|
||||
#include <iostream>
|
||||
#include <tribufu/client.h>
|
||||
#include <tribufu++/sdk.h>
|
||||
|
||||
using namespace tribufu;
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
if (TribufuSdk::Initialize())
|
||||
{
|
||||
std::cout << "Tribufu SDK initialized successfully!" << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Failed to initialize Tribufu SDK!" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (TribufuSdk::Ping())
|
||||
{
|
||||
std::cout << "Tribufu SDK is online!" << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Tribufu SDK is offline!" << std::endl;
|
||||
}
|
||||
|
||||
TribufuSdk::Shutdown();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -7,8 +7,8 @@ project "example"
|
||||
|
||||
cppdialect "C++20"
|
||||
|
||||
targetdir("../bin/%{cfg.platform:gsub('-', '/')}")
|
||||
objdir("../target/%{cfg.buildcfg}/obj/%{prj.name}/%{cfg.platform:gsub('-', '/')}")
|
||||
targetdir("../bin/%{cfg.platform}")
|
||||
objdir("../target/%{cfg.buildcfg}/obj/%{prj.name}/%{cfg.platform}")
|
||||
|
||||
files
|
||||
{
|
||||
@ -19,13 +19,14 @@ project "example"
|
||||
|
||||
includedirs
|
||||
{
|
||||
"../../TribufuSdk/include",
|
||||
"../include",
|
||||
"../vendor/*/include",
|
||||
}
|
||||
|
||||
libdirs
|
||||
{
|
||||
"../bin/%{cfg.platform:gsub('-', '/')}",
|
||||
"../bin/%{cfg.platform}",
|
||||
}
|
||||
|
||||
-- Profile
|
||||
|
20
include/tribufu++/sdk.h
Normal file
20
include/tribufu++/sdk.h
Normal file
@ -0,0 +1,20 @@
|
||||
// Copyright (c) Tribufu. All Rights Reserved.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <tribufu/sdk.h>
|
||||
|
||||
namespace tribufu
|
||||
{
|
||||
class TRIBUFU_API TribufuSdk
|
||||
{
|
||||
public:
|
||||
static bool Initialize();
|
||||
static void Shutdown();
|
||||
static bool Ping();
|
||||
static void PingAsync(void *client_date, TribufuSdkPingCallback callback);
|
||||
|
||||
private:
|
||||
static void PingCallbackHandler(void *client_data, bool result);
|
||||
};
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
// Copyright (c) Tribufu. All Rights Reserved.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <tribufu/client.h>
|
||||
#include <tribufu/json.h>
|
@ -1,27 +0,0 @@
|
||||
// Copyright (c) Tribufu. All Rights Reserved.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <tribufu/options.h>
|
||||
#include <tribufu/prelude.h>
|
||||
|
||||
namespace tribufu
|
||||
{
|
||||
static const char *VERSION = "0.0.4";
|
||||
static const char *API_URL = "https://api.tribufu.com";
|
||||
|
||||
class TRIBUFU_API TribufuApi
|
||||
{
|
||||
private:
|
||||
std::string base_url;
|
||||
TribufuApiOptions options;
|
||||
|
||||
public:
|
||||
TribufuApi();
|
||||
TribufuApi(std::string api_key);
|
||||
TribufuApi(TribufuApiOptions options);
|
||||
~TribufuApi();
|
||||
static TribufuApi from_env();
|
||||
static TribufuApi from_env(std::string prefix);
|
||||
};
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
// Copyright (c) Tribufu. All Rights Reserved.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <tribufu/api.h>
|
||||
#include <tribufu/prelude.h>
|
||||
|
||||
namespace tribufu
|
||||
{
|
||||
class TRIBUFU_API TribufuClient : public TribufuApi
|
||||
{
|
||||
private:
|
||||
uint64_t client_id;
|
||||
std::string client_secret;
|
||||
|
||||
public:
|
||||
TribufuClient(uint64_t id, const std::string &secret);
|
||||
~TribufuClient();
|
||||
uint64_t &get_client_id();
|
||||
};
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
// Copyright (c) Tribufu. All Rights Reserved.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <tribufu/native.h>
|
||||
#include <tribufu/prelude.h>
|
||||
|
||||
#ifdef TRIBUFU_CPP
|
||||
#include <nlohmann/json.hpp>
|
||||
using json = nlohmann::json;
|
||||
#endif
|
@ -1,18 +0,0 @@
|
||||
// Copyright (c) Tribufu. All Rights Reserved.
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define TRIBUFU_CPP
|
||||
#endif
|
||||
|
||||
#ifdef TRIBUFU_LIBRARY
|
||||
#define TRIBUFU_API DLLEXPORT
|
||||
#else
|
||||
#define TRIBUFU_API DLLIMPORT
|
||||
#endif
|
||||
|
||||
// Macros Utils
|
||||
|
||||
#define TRIBUFU_EXPAND_MACRO(x) x
|
||||
#define TRIBUFU_STRINGIFY_MACRO(x) #x
|
@ -1,5 +0,0 @@
|
||||
// Copyright (c) Tribufu. All Rights Reserved.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <tribufu/prelude.h>
|
@ -1,133 +0,0 @@
|
||||
// Copyright (c) Tribufu. All Rights Reserved.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <tribufu/prelude.h>
|
||||
|
||||
namespace tribufu
|
||||
{
|
||||
enum class TRIBUFU_API OAuth2ResponseType
|
||||
{
|
||||
Code,
|
||||
Token,
|
||||
};
|
||||
|
||||
enum class TRIBUFU_API OAuth2ClientType
|
||||
{
|
||||
Confidential,
|
||||
Public,
|
||||
};
|
||||
|
||||
enum class TRIBUFU_API OAuth2TokenHintType
|
||||
{
|
||||
AccessToken,
|
||||
RefreshToken,
|
||||
};
|
||||
|
||||
enum class TRIBUFU_API OAuth2GrantType
|
||||
{
|
||||
AuthorizationCode,
|
||||
ClientCredentials,
|
||||
DeviceCode,
|
||||
Password,
|
||||
RefreshToken,
|
||||
};
|
||||
|
||||
enum class TRIBUFU_API OAuth2AuthorizeError
|
||||
{
|
||||
AccessDenied,
|
||||
InvalidRequest,
|
||||
InvalidScope,
|
||||
ServerError,
|
||||
TemporarilyUnavailable,
|
||||
UnauthorizedClient,
|
||||
UnsupportedResponseType,
|
||||
};
|
||||
|
||||
enum class TRIBUFU_API OAuth2TokenType
|
||||
{
|
||||
Bearer,
|
||||
};
|
||||
|
||||
class TRIBUFU_API OAuth2AuthorizeRequest
|
||||
{
|
||||
private:
|
||||
OAuth2ResponseType response_type;
|
||||
uint64_t client_id;
|
||||
std::string client_secret;
|
||||
std::string redirect_uri;
|
||||
std::string scope;
|
||||
std::string state;
|
||||
|
||||
public:
|
||||
OAuth2AuthorizeRequest();
|
||||
OAuth2AuthorizeRequest(OAuth2ResponseType response_type, uint64_t client_id, const std::string &client_secret,
|
||||
const std::string &redirect_uri, const std::string &scope, const std::string &state);
|
||||
~OAuth2AuthorizeRequest();
|
||||
};
|
||||
|
||||
class TRIBUFU_API OAuth2CodeResponse
|
||||
{
|
||||
private:
|
||||
std::string code;
|
||||
std::string state;
|
||||
|
||||
public:
|
||||
OAuth2CodeResponse();
|
||||
OAuth2CodeResponse(const std::string &code, const std::string &state);
|
||||
~OAuth2CodeResponse();
|
||||
};
|
||||
|
||||
class TRIBUFU_API OAuth2ErrorResponse
|
||||
{
|
||||
private:
|
||||
OAuth2AuthorizeError error;
|
||||
std::string error_description;
|
||||
std::string error_uri;
|
||||
std::string state;
|
||||
|
||||
public:
|
||||
OAuth2ErrorResponse();
|
||||
OAuth2ErrorResponse(OAuth2AuthorizeError error, const std::string &error_description,
|
||||
const std::string &error_uri, const std::string &state);
|
||||
~OAuth2ErrorResponse();
|
||||
};
|
||||
|
||||
class TRIBUFU_API OAuth2TokenRequest
|
||||
{
|
||||
private:
|
||||
OAuth2GrantType grant_type;
|
||||
uint64_t client_id;
|
||||
std::string client_secret;
|
||||
std::string redirect_uri;
|
||||
std::string code;
|
||||
std::string refresh_token;
|
||||
std::string username;
|
||||
std::string password;
|
||||
|
||||
public:
|
||||
OAuth2TokenRequest();
|
||||
OAuth2TokenRequest(OAuth2GrantType grant_type, uint64_t client_id, const std::string &client_secret,
|
||||
const std::string &redirect_uri, const std::string &code, const std::string &refresh_token,
|
||||
const std::string &username, const std::string &password);
|
||||
~OAuth2TokenRequest();
|
||||
};
|
||||
|
||||
class TRIBUFU_API OAuth2TokenResponse
|
||||
{
|
||||
private:
|
||||
OAuth2TokenType token_type;
|
||||
std::string access_token;
|
||||
std::string refresh_token;
|
||||
std::string scope;
|
||||
std::string state;
|
||||
uint64_t expires_in;
|
||||
|
||||
public:
|
||||
OAuth2TokenResponse();
|
||||
OAuth2TokenResponse(OAuth2TokenType token_type, const std::string &access_token,
|
||||
const std::string &refresh_token, const std::string &scope, const std::string &state,
|
||||
uint64_t expires_in);
|
||||
~OAuth2TokenResponse();
|
||||
};
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
// Copyright (c) Tribufu. All Rights Reserved.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <tribufu/prelude.h>
|
||||
|
||||
namespace tribufu
|
||||
{
|
||||
class TRIBUFU_API TribufuApiOptions
|
||||
{
|
||||
public:
|
||||
std::string api_key;
|
||||
std::string access_token;
|
||||
std::string refresh_token;
|
||||
float expires_in;
|
||||
|
||||
public:
|
||||
TribufuApiOptions();
|
||||
TribufuApiOptions(std::string api_key);
|
||||
TribufuApiOptions(std::string access_token, std::string refresh_token, float expires_in);
|
||||
TribufuApiOptions(std::string api_key, std::string access_token, std::string refresh_token, float expires_in);
|
||||
~TribufuApiOptions();
|
||||
};
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
// Copyright (c) Tribufu. All Rights Reserved.
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef _WIN32
|
||||
#ifndef DLLEXPORT
|
||||
#define DLLEXPORT __declspec(dllexport)
|
||||
#endif
|
||||
#ifndef DLLIMPORT
|
||||
#define DLLIMPORT __declspec(dllimport)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef __MACH__ || __APPLE__ || __linux__ || __FreeBSD__ || __ANDROID__
|
||||
#ifndef DLLEXPORT
|
||||
#define DLLEXPORT __attribute__((visibility("default")))
|
||||
#endif
|
||||
#ifndef DLLIMPORT
|
||||
#define DLLIMPORT __attribute__((visibility("default")))
|
||||
#endif
|
||||
#endif
|
@ -1,8 +0,0 @@
|
||||
// Copyright (c) Tribufu. All Rights Reserved.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <tribufu/macros.h>
|
||||
#include <tribufu/native.h>
|
||||
#include <tribufu/platform.h>
|
||||
#include <tribufu/std.h>
|
@ -1,20 +0,0 @@
|
||||
// Copyright (c) Tribufu. All Rights Reserved.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <tribufu/client.h>
|
||||
#include <tribufu/prelude.h>
|
||||
|
||||
namespace tribufu
|
||||
{
|
||||
class TRIBUFU_API TribufuServer : public TribufuClient
|
||||
{
|
||||
private:
|
||||
uint64_t server_id;
|
||||
|
||||
public:
|
||||
TribufuServer(uint64_t server_id, uint64_t client_id, const std::string &client_secret);
|
||||
~TribufuServer();
|
||||
uint64_t &get_server_id();
|
||||
};
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
// Copyright (c) Tribufu. All Rights Reserved.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <tribufu/prelude.h>
|
||||
#include <tribufu/json.h>
|
||||
|
||||
namespace tribufu
|
||||
{
|
||||
class TRIBUFU_API Server
|
||||
{
|
||||
private:
|
||||
uint64_t id;
|
||||
std::string name;
|
||||
std::string description;
|
||||
std::string address;
|
||||
uint16_t game_port;
|
||||
uint16_t query_port;
|
||||
uint64_t package_id;
|
||||
|
||||
public:
|
||||
Server();
|
||||
Server(json data);
|
||||
~Server();
|
||||
|
||||
json to_json();
|
||||
};
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
// Copyright (c) Tribufu. All Rights Reserved.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef TRIBUFU_CPP
|
||||
#include <algorithm>
|
||||
#include <cstdarg>
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <functional>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <new>
|
||||
#include <ostream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#endif
|
@ -1,47 +0,0 @@
|
||||
// Copyright (c) Tribufu. All Rights Reserved.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <tribufu/prelude.h>
|
||||
#include <tribufu/json.h>
|
||||
|
||||
namespace tribufu
|
||||
{
|
||||
enum class UserType
|
||||
{
|
||||
User,
|
||||
Bot,
|
||||
Org,
|
||||
};
|
||||
|
||||
class TRIBUFU_API Profile
|
||||
{
|
||||
private:
|
||||
uint64_t id;
|
||||
std::string uuid;
|
||||
std::string name;
|
||||
std::string display_name;
|
||||
UserType type;
|
||||
uint64_t public_flags;
|
||||
bool verified;
|
||||
uint32_t level;
|
||||
double experience;
|
||||
bool public_birthday;
|
||||
double points;
|
||||
std::string location;
|
||||
std::string photo_url;
|
||||
std::string banner_url;
|
||||
std::string last_online;
|
||||
std::string biography;
|
||||
uint32_t view_count;
|
||||
std::string created;
|
||||
std::string updated;
|
||||
|
||||
public:
|
||||
Profile();
|
||||
Profile(json data);
|
||||
~Profile();
|
||||
|
||||
json to_json();
|
||||
};
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
--- @diagnostic disable: undefined-global
|
||||
|
||||
workspace "tribufu"
|
||||
workspace "tribufu_cpp"
|
||||
location "."
|
||||
configurations { "debug", "release" }
|
||||
|
||||
|
@ -1,8 +1,6 @@
|
||||
#!/usr/bin/env pwsh
|
||||
|
||||
echo "Building for windows-x86_64"
|
||||
cargo build --package tribufu-native --target x86_64-pc-windows-msvc
|
||||
New-Item "bin/windows/x86_64" -ItemType Directory -Force
|
||||
Remove-Item -Path "bin/windows/x86_64/*" -Force
|
||||
Copy-Item -Path "target/x86_64-pc-windows-msvc/debug/tribufu_native.lib" -Destination "bin/windows/x86_64" -Force
|
||||
New-Item "bin/windows-x86_64" -ItemType Directory -Force
|
||||
Remove-Item -Path "bin/windows-x86_64/*" -Force
|
||||
msbuild /p:Configuration="debug" /p:Platform="windows-x86_64"
|
||||
|
51
src/api.cpp
51
src/api.cpp
@ -1,51 +0,0 @@
|
||||
// Copyright (c) Tribufu. All Rights Reserved.
|
||||
|
||||
#include <tribufu/api.h>
|
||||
|
||||
namespace tribufu
|
||||
{
|
||||
TribufuApi::TribufuApi()
|
||||
{
|
||||
}
|
||||
|
||||
TribufuApi::TribufuApi(std::string api_key)
|
||||
{
|
||||
this->options.api_key = api_key;
|
||||
}
|
||||
|
||||
TribufuApi::TribufuApi(TribufuApiOptions options)
|
||||
{
|
||||
this->options = options;
|
||||
}
|
||||
|
||||
TribufuApi::~TribufuApi()
|
||||
{
|
||||
}
|
||||
|
||||
TribufuApi TribufuApi::from_env()
|
||||
{
|
||||
return TribufuApi::from_env("");
|
||||
}
|
||||
|
||||
TribufuApi TribufuApi::from_env(std::string prefix)
|
||||
{
|
||||
std::string env_prefix = "";
|
||||
|
||||
if (prefix != "")
|
||||
{
|
||||
env_prefix = prefix + "_";
|
||||
}
|
||||
|
||||
size_t required_size;
|
||||
char api_key[64];
|
||||
|
||||
auto response = getenv_s(&required_size, api_key, sizeof(api_key), (env_prefix + "API_KEY").c_str());
|
||||
|
||||
if (response == 0 && required_size > 0)
|
||||
{
|
||||
return TribufuApi(api_key);
|
||||
}
|
||||
|
||||
return TribufuApi();
|
||||
}
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
// Copyright (c) Tribufu. All Rights Reserved.
|
||||
|
||||
#include <tribufu/client.h>
|
||||
|
||||
namespace tribufu
|
||||
{
|
||||
TribufuClient::TribufuClient(uint64_t client_id, const std::string &client_secret) : TribufuApi()
|
||||
{
|
||||
this->client_id = client_id;
|
||||
this->client_secret = client_secret;
|
||||
}
|
||||
|
||||
TribufuClient::~TribufuClient()
|
||||
{
|
||||
}
|
||||
|
||||
uint64_t &TribufuClient::get_client_id()
|
||||
{
|
||||
return this->client_id;
|
||||
}
|
||||
|
||||
/*
|
||||
void TribufuClient::get_token()
|
||||
{
|
||||
try
|
||||
{
|
||||
std::string url = "https://api.tribufu.com/v1/servers";
|
||||
FHttpResponse response = this->http.get(url);
|
||||
std::cout << "status_code: " << response.status_code << std::endl;
|
||||
|
||||
if (response.body != nullptr)
|
||||
{
|
||||
json response_body = json::parse(response.body);
|
||||
std::string json_str = response_body.dump(4);
|
||||
std::cout << json_str << std::endl;
|
||||
}
|
||||
|
||||
mintaka_http_free_response(response);
|
||||
}
|
||||
catch (std::exception &e)
|
||||
{
|
||||
std::cout << "exception: " << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
@ -1 +0,0 @@
|
||||
// Copyright (c) Tribufu. All Rights Reserved.
|
100
src/oauth2.cpp
100
src/oauth2.cpp
@ -1,100 +0,0 @@
|
||||
// Copyright (c) Tribufu. All Rights Reserved.
|
||||
|
||||
#include <tribufu/oauth2.h>
|
||||
|
||||
namespace tribufu
|
||||
{
|
||||
OAuth2AuthorizeRequest::OAuth2AuthorizeRequest()
|
||||
{
|
||||
}
|
||||
|
||||
OAuth2AuthorizeRequest::OAuth2AuthorizeRequest(OAuth2ResponseType response_type, uint64_t client_id,
|
||||
const std::string &client_secret, const std::string &redirect_uri,
|
||||
const std::string &scope, const std::string &state)
|
||||
{
|
||||
this->response_type = response_type;
|
||||
this->client_id = client_id;
|
||||
this->client_secret = client_secret;
|
||||
this->redirect_uri = redirect_uri;
|
||||
this->scope = scope;
|
||||
this->state = state;
|
||||
}
|
||||
|
||||
OAuth2AuthorizeRequest::~OAuth2AuthorizeRequest()
|
||||
{
|
||||
}
|
||||
|
||||
OAuth2CodeResponse::OAuth2CodeResponse()
|
||||
{
|
||||
}
|
||||
|
||||
OAuth2CodeResponse::OAuth2CodeResponse(const std::string &code, const std::string &state)
|
||||
{
|
||||
this->code = code;
|
||||
this->state = state;
|
||||
}
|
||||
|
||||
OAuth2CodeResponse::~OAuth2CodeResponse()
|
||||
{
|
||||
}
|
||||
|
||||
OAuth2ErrorResponse::OAuth2ErrorResponse()
|
||||
{
|
||||
}
|
||||
|
||||
OAuth2ErrorResponse::OAuth2ErrorResponse(OAuth2AuthorizeError error, const std::string &error_description,
|
||||
const std::string &error_uri, const std::string &state)
|
||||
{
|
||||
this->error = error;
|
||||
this->error_description = error_description;
|
||||
this->error_uri = error_uri;
|
||||
this->state = state;
|
||||
}
|
||||
|
||||
OAuth2ErrorResponse::~OAuth2ErrorResponse()
|
||||
{
|
||||
}
|
||||
|
||||
OAuth2TokenRequest::OAuth2TokenRequest()
|
||||
{
|
||||
}
|
||||
|
||||
OAuth2TokenRequest::OAuth2TokenRequest(OAuth2GrantType grant_type, uint64_t client_id,
|
||||
const std::string &client_secret, const std::string &redirect_uri,
|
||||
const std::string &code, const std::string &refresh_token,
|
||||
const std::string &username, const std::string &password)
|
||||
{
|
||||
this->grant_type = grant_type;
|
||||
this->client_id = client_id;
|
||||
this->client_secret = client_secret;
|
||||
this->redirect_uri = redirect_uri;
|
||||
this->code = code;
|
||||
this->refresh_token = refresh_token;
|
||||
this->username = username;
|
||||
this->password = password;
|
||||
}
|
||||
|
||||
OAuth2TokenRequest::~OAuth2TokenRequest()
|
||||
{
|
||||
}
|
||||
|
||||
OAuth2TokenResponse::OAuth2TokenResponse()
|
||||
{
|
||||
}
|
||||
|
||||
OAuth2TokenResponse::OAuth2TokenResponse(OAuth2TokenType token_type, const std::string &access_token,
|
||||
const std::string &refresh_token, const std::string &scope,
|
||||
const std::string &state, uint64_t expires_in)
|
||||
{
|
||||
this->token_type = token_type;
|
||||
this->access_token = access_token;
|
||||
this->refresh_token = refresh_token;
|
||||
this->scope = scope;
|
||||
this->state = state;
|
||||
this->expires_in = expires_in;
|
||||
}
|
||||
|
||||
OAuth2TokenResponse::~OAuth2TokenResponse()
|
||||
{
|
||||
}
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
// Copyright (c) Tribufu. All Rights Reserved.
|
||||
|
||||
#include <tribufu/options.h>
|
||||
|
||||
namespace tribufu
|
||||
{
|
||||
TribufuApiOptions::TribufuApiOptions() : TribufuApiOptions(nullptr, nullptr, nullptr, 0.0f)
|
||||
{
|
||||
}
|
||||
|
||||
TribufuApiOptions::TribufuApiOptions(std::string api_key) : TribufuApiOptions(api_key, nullptr, nullptr, 0.0f)
|
||||
{
|
||||
}
|
||||
|
||||
TribufuApiOptions::TribufuApiOptions(std::string access_token, std::string refresh_token, float expires_in)
|
||||
: TribufuApiOptions(nullptr, access_token, refresh_token, expires_in)
|
||||
{
|
||||
}
|
||||
|
||||
TribufuApiOptions::TribufuApiOptions(std::string api_key, std::string access_token, std::string refresh_token,
|
||||
float expires_in)
|
||||
{
|
||||
this->api_key = api_key;
|
||||
this->access_token = access_token;
|
||||
this->refresh_token = refresh_token;
|
||||
this->expires_in = expires_in;
|
||||
}
|
||||
|
||||
TribufuApiOptions::~TribufuApiOptions()
|
||||
{
|
||||
}
|
||||
}
|
@ -6,7 +6,7 @@ project "tribufu_cpp"
|
||||
|
||||
cppdialect "C++20"
|
||||
|
||||
targetdir("../bin/%{cfg.platform:gsub('-', '/')}")
|
||||
targetdir("../bin/%{cfg.platform}")
|
||||
objdir("../target/%{cfg.buildcfg}/%{cfg.platform}/%{prj.name}}")
|
||||
|
||||
files
|
||||
@ -24,6 +24,7 @@ project "tribufu_cpp"
|
||||
|
||||
includedirs
|
||||
{
|
||||
"../../TribufuSdk/include",
|
||||
"../include",
|
||||
"../vendor/*/include",
|
||||
"../vendor/*/vendor/*/include",
|
||||
@ -31,8 +32,9 @@ project "tribufu_cpp"
|
||||
|
||||
libdirs
|
||||
{
|
||||
"../bin/%{cfg.platform:gsub('-', '/')}",
|
||||
"../vendor/*/lib/%{cfg.platform:gsub('-', '/')}",
|
||||
"../../TribufuSdk/bin/%{cfg.platform}",
|
||||
"../bin/%{cfg.platform}",
|
||||
"../vendor/*/lib/%{cfg.platform}",
|
||||
}
|
||||
|
||||
-- Profile
|
||||
@ -79,7 +81,7 @@ project "tribufu_cpp"
|
||||
|
||||
links
|
||||
{
|
||||
"tribufu_native.lib",
|
||||
"tribufu_sdk.lib",
|
||||
}
|
||||
|
||||
prelinkcommands
|
||||
@ -88,6 +90,7 @@ project "tribufu_cpp"
|
||||
|
||||
postbuildcommands
|
||||
{
|
||||
"{COPYFILE} ../../TribufuSdk/bin/%{cfg.platform}/tribufu_sdk.dll ../bin/%{cfg.platform}",
|
||||
}
|
||||
|
||||
filter { "platforms:mac-*" }
|
||||
@ -108,7 +111,7 @@ project "tribufu_cpp"
|
||||
|
||||
links
|
||||
{
|
||||
"tribufu_native",
|
||||
"tribufu_sdk",
|
||||
}
|
||||
|
||||
prelinkcommands
|
||||
@ -117,6 +120,7 @@ project "tribufu_cpp"
|
||||
|
||||
postbuildcommands
|
||||
{
|
||||
"{COPYFILE} ../../TribufuSdk/bin/%{cfg.platform}/libtribufu_sdk.dylib ../bin/%{cfg.platform}",
|
||||
}
|
||||
|
||||
filter { "platforms:linux-*" }
|
||||
@ -136,7 +140,7 @@ project "tribufu_cpp"
|
||||
|
||||
links
|
||||
{
|
||||
"tribufu_native",
|
||||
"tribufu_sdk",
|
||||
}
|
||||
|
||||
prelinkcommands
|
||||
@ -145,6 +149,7 @@ project "tribufu_cpp"
|
||||
|
||||
postbuildcommands
|
||||
{
|
||||
"{COPYFILE} ../../TribufuSdk/bin/%{cfg.platform}/libtribufu_sdk.so ../bin/%{cfg.platform}",
|
||||
}
|
||||
|
||||
filter { "platforms:android-*" }
|
||||
@ -164,7 +169,7 @@ project "tribufu_cpp"
|
||||
|
||||
links
|
||||
{
|
||||
"tribufu_native",
|
||||
"tribufu_sdk",
|
||||
}
|
||||
|
||||
prelinkcommands
|
||||
@ -173,6 +178,7 @@ project "tribufu_cpp"
|
||||
|
||||
postbuildcommands
|
||||
{
|
||||
"{COPYFILE} ../../TribufuSdk/bin/%{cfg.platform}/libtribufu_sdk.so ../bin/%{cfg.platform}",
|
||||
}
|
||||
|
||||
filter { "platforms:ios-*" }
|
||||
@ -193,7 +199,7 @@ project "tribufu_cpp"
|
||||
|
||||
links
|
||||
{
|
||||
"tribufu_native",
|
||||
"tribufu_sdk",
|
||||
}
|
||||
|
||||
prelinkcommands
|
||||
|
35
src/sdk.cpp
Normal file
35
src/sdk.cpp
Normal file
@ -0,0 +1,35 @@
|
||||
// Copyright (c) Tribufu. All Rights Reserved.
|
||||
|
||||
#include <tribufu++/sdk.h>
|
||||
|
||||
namespace tribufu
|
||||
{
|
||||
bool TribufuSdk::Initialize()
|
||||
{
|
||||
return tribufu_sdk_initialize(nullptr);
|
||||
}
|
||||
|
||||
void TribufuSdk::Shutdown()
|
||||
{
|
||||
tribufu_sdk_shutdown();
|
||||
}
|
||||
|
||||
bool TribufuSdk::Ping()
|
||||
{
|
||||
std::promise<bool> promise;
|
||||
std::future<bool> future = promise.get_future();
|
||||
PingAsync(static_cast<void *>(&promise), PingCallbackHandler);
|
||||
return future.get();
|
||||
}
|
||||
|
||||
void TribufuSdk::PingCallbackHandler(void *client_data, bool result)
|
||||
{
|
||||
std::promise<bool> *promise = static_cast<std::promise<bool> *>(client_data);
|
||||
promise->set_value(result);
|
||||
}
|
||||
|
||||
void TribufuSdk::PingAsync(void *client_data, TribufuSdkPingCallback callback)
|
||||
{
|
||||
tribufu_sdk_ping(client_data, callback);
|
||||
}
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
// Copyright (c) Tribufu. All Rights Reserved.
|
||||
|
||||
#include <tribufu/server.h>
|
||||
|
||||
namespace tribufu
|
||||
{
|
||||
TribufuServer::TribufuServer(uint64_t server_id, uint64_t client_id, const std::string &client_secret)
|
||||
: TribufuClient(client_id, client_secret)
|
||||
{
|
||||
this->server_id = server_id;
|
||||
}
|
||||
|
||||
TribufuServer::~TribufuServer()
|
||||
{
|
||||
}
|
||||
|
||||
uint64_t &TribufuServer::get_server_id()
|
||||
{
|
||||
return this->server_id;
|
||||
}
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
// Copyright (c) Tribufu. All Rights Reserved.
|
||||
|
||||
#include <tribufu/servers/server.h>
|
||||
|
||||
namespace tribufu
|
||||
{
|
||||
Server::Server()
|
||||
{
|
||||
}
|
||||
|
||||
Server::Server(json data)
|
||||
{
|
||||
this->id = data["id"];
|
||||
this->name = data["name"];
|
||||
this->description = data["description"];
|
||||
this->address = data["address"];
|
||||
this->game_port = data["game_port"];
|
||||
this->query_port = data["query_port"];
|
||||
this->package_id = data["package_id"];
|
||||
}
|
||||
|
||||
Server::~Server()
|
||||
{
|
||||
}
|
||||
|
||||
json Server::to_json()
|
||||
{
|
||||
json data;
|
||||
data["id"] = this->id;
|
||||
data["name"] = this->name;
|
||||
data["description"] = this->description;
|
||||
data["address"] = this->address;
|
||||
data["game_port"] = this->game_port;
|
||||
data["query_port"] = this->query_port;
|
||||
data["package_id"] = this->package_id;
|
||||
return data;
|
||||
}
|
||||
}
|
@ -1,62 +0,0 @@
|
||||
// Copyright (c) Tribufu. All Rights Reserved.
|
||||
|
||||
#include <tribufu/users/profile.h>
|
||||
|
||||
namespace tribufu
|
||||
{
|
||||
Profile::Profile()
|
||||
{
|
||||
}
|
||||
|
||||
Profile::Profile(json data)
|
||||
{
|
||||
this->id = data["id"];
|
||||
this->uuid = data["uuid"];
|
||||
this->name = data["name"];
|
||||
this->display_name = data["display_name"];
|
||||
this->type = data["type"];
|
||||
this->public_flags = data["public_flags"];
|
||||
this->verified = data["verified"];
|
||||
this->level = data["level"];
|
||||
this->experience = data["experience"];
|
||||
this->public_birthday = data["public_birthday"];
|
||||
this->points = data["points"];
|
||||
this->location = data["location"];
|
||||
this->photo_url = data["photo_url"];
|
||||
this->banner_url = data["banner_url"];
|
||||
this->last_online = data["last_online"];
|
||||
this->biography = data["biography"];
|
||||
this->view_count = data["view_count"];
|
||||
this->created = data["created"];
|
||||
this->updated = data["updated"];
|
||||
}
|
||||
|
||||
Profile::~Profile()
|
||||
{
|
||||
}
|
||||
|
||||
json Profile::to_json()
|
||||
{
|
||||
json data;
|
||||
data["id"] = this->id;
|
||||
data["uuid"] = this->uuid;
|
||||
data["name"] = this->name;
|
||||
data["display_name"] = this->display_name;
|
||||
data["type"] = this->type;
|
||||
data["public_flags"] = this->public_flags;
|
||||
data["verified"] = this->verified;
|
||||
data["level"] = this->level;
|
||||
data["experience"] = this->experience;
|
||||
data["public_birthday"] = this->public_birthday;
|
||||
data["points"] = this->points;
|
||||
data["location"] = this->location;
|
||||
data["photo_url"] = this->photo_url;
|
||||
data["banner_url"] = this->banner_url;
|
||||
data["last_online"] = this->last_online;
|
||||
data["biography"] = this->biography;
|
||||
data["view_count"] = this->view_count;
|
||||
data["created"] = this->created;
|
||||
data["updated"] = this->updated;
|
||||
return data;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user