211 lines
6.9 KiB
C
211 lines
6.9 KiB
C
#ifndef __ACE_SDK_SERVER_IMPL_H__
|
|
#define __ACE_SDK_SERVER_IMPL_H__
|
|
|
|
#include "ace_sdk_common.h"
|
|
|
|
struct __AceSdkServerLibraryInfo;
|
|
struct __AceSdkServerAuthInfo;
|
|
struct __AceSdkServerDeploymentInfo;
|
|
|
|
#define ACE_SDK_SERVER_MAX_GAME_DEV_LANGUAGE_LEN 64
|
|
#pragma pack(push, 1)
|
|
typedef struct
|
|
{
|
|
char library_path_[ACE_SDK_MAX_LIBRARY_DIR_LENGTH * 2];
|
|
char game_dev_language_[ACE_SDK_SERVER_MAX_GAME_DEV_LANGUAGE_LEN];
|
|
} AceSdkServerExtendInfo;
|
|
#pragma pack(pop)
|
|
|
|
#if defined(ACE_CGO)
|
|
extern int __ace_sdk_init_succ;
|
|
#elif defined(_WIN32) && defined(_MSC_VER)
|
|
__declspec(selectany) int __ace_sdk_init_succ = 0;
|
|
#else
|
|
__attribute__((weak)) int __ace_sdk_init_succ = 0;
|
|
#endif
|
|
|
|
/***
|
|
* Internal functions' implementation
|
|
*/
|
|
|
|
inline AceSdkResult ace_sdk_server_report_extend_info(const AceSdkServerExtendInfo* extend_info)
|
|
{
|
|
if (extend_info == NULL)
|
|
{
|
|
return ACE_SDK_RESULT_OK;
|
|
}
|
|
typedef int(ACE_SDK_CALL* AceSdkServerExtendInfoReport)(const AceSdkServerExtendInfo* info);
|
|
AceSdkServerExtendInfoReport func_extend_info = (AceSdkServerExtendInfoReport)__ace_sdk_get_symbol("__ace_sdk_server_extend_info");
|
|
if (func_extend_info != NULL)
|
|
{
|
|
func_extend_info(extend_info);
|
|
}
|
|
return ACE_SDK_RESULT_OK;
|
|
}
|
|
|
|
/**
|
|
* Initialize the SDK using the specified interface.
|
|
*/
|
|
inline AceSdkResult ace_sdk_server_init_specified(const struct __AceSdkServerLibraryInfo* library_info, const struct __AceSdkServerAuthInfo* auth_info, const struct __AceSdkServerDeploymentInfo* deployment_info, const char* name)
|
|
{
|
|
int32_t ret = ACE_SDK_RESULT_OK;
|
|
if (library_info == NULL || auth_info == NULL || deployment_info == NULL || name == NULL)
|
|
{
|
|
return ACE_SDK_RESULT_INVALID_PARAMETER;
|
|
}
|
|
|
|
ACE_CHAR library_path[ACE_SDK_MAX_LIBRARY_DIR_LENGTH * 2] = {0};
|
|
#ifdef _WIN32
|
|
_snwprintf_s(library_path, sizeof(library_path)/sizeof(library_path[0]), _TRUNCATE, L"%s/%s", library_info->library_dir_, L"ace_sdk.dll");
|
|
#else
|
|
snprintf(library_path, sizeof(library_path), "%s/%s", library_info->library_dir_, "libace_sdk.so");
|
|
#endif
|
|
ret = __ace_sdk_load_library(library_path);
|
|
if (ret != 0)
|
|
{
|
|
return ACE_SDK_RESULT_LOAD_LIBRARY_FAILED;
|
|
}
|
|
typedef int(ACE_SDK_CALL* AceSdkServerInit)(const struct __AceSdkServerAuthInfo*, const struct __AceSdkServerDeploymentInfo*);
|
|
AceSdkServerInit func = (AceSdkServerInit)__ace_sdk_get_symbol(name);
|
|
if (func == NULL)
|
|
{
|
|
return ACE_SDK_RESULT_SYMBOL_NOT_FOUND;
|
|
}
|
|
ret = func(auth_info, deployment_info);
|
|
if (ret != 0)
|
|
{
|
|
return ACE_SDK_RESULT_INVALID_PARAMETER;
|
|
}
|
|
__ace_sdk_init_succ = 1;
|
|
// report extend info
|
|
AceSdkServerExtendInfo extend_info;
|
|
#ifdef _WIN32
|
|
char library_path_utf8[ACE_SDK_MAX_LIBRARY_DIR_LENGTH] = {0};
|
|
int library_path_utf8_len = WideCharToMultiByte(CP_UTF8, 0, library_info->library_dir_, -1, library_path_utf8, sizeof(library_path_utf8)-1, NULL, NULL);
|
|
if (library_path_utf8_len <= 0)
|
|
{
|
|
return ACE_SDK_RESULT_OK;
|
|
}
|
|
|
|
library_path_utf8[library_path_utf8_len] = 0;
|
|
snprintf(extend_info.library_path_, sizeof(extend_info.library_path_), "%s/%s", library_path_utf8, "ace_sdk.dll");
|
|
#else
|
|
snprintf(extend_info.library_path_, sizeof(extend_info.library_path_), "%s/%s", library_info->library_dir_, "libace_sdk.so");
|
|
#endif
|
|
snprintf(extend_info.game_dev_language_, sizeof(extend_info.game_dev_language_), "C/C++");
|
|
ace_sdk_server_report_extend_info(&extend_info);
|
|
return ACE_SDK_RESULT_OK;
|
|
}
|
|
|
|
inline AceSdkResult ace_sdk_server_init(const struct __AceSdkServerLibraryInfo* library_info, const struct __AceSdkServerAuthInfo* auth_info, const struct __AceSdkServerDeploymentInfo* deployment_info)
|
|
{
|
|
return ace_sdk_server_init_specified(library_info, auth_info, deployment_info, "__ace_sdk_server_init");
|
|
}
|
|
|
|
inline AceSdkResult ace_sdk_server_init_without_proc(const struct __AceSdkServerLibraryInfo* library_info, const struct __AceSdkServerAuthInfo* auth_info, const struct __AceSdkServerDeploymentInfo* deployment_info)
|
|
{
|
|
return ace_sdk_server_init_specified(library_info, auth_info, deployment_info, "__ace_sdk_server_init_without_proc");
|
|
}
|
|
|
|
inline AceSdkResult ace_sdk_server_proc()
|
|
{
|
|
if (!__ace_sdk_init_succ)
|
|
{
|
|
return ACE_SDK_RESULT_INIT_NOT_CALLED_OR_FAILED;
|
|
}
|
|
typedef int(ACE_SDK_CALL* ace_sdk_server_proc)();
|
|
ace_sdk_server_proc func = (ace_sdk_server_proc)__ace_sdk_get_symbol("__ace_sdk_server_proc");
|
|
if (func != NULL)
|
|
{
|
|
func();
|
|
}
|
|
return ACE_SDK_RESULT_OK;
|
|
}
|
|
|
|
inline AceSdkResult ace_sdk_server_deinit()
|
|
{
|
|
int32_t ret = ACE_SDK_RESULT_OK;
|
|
__ace_sdk_init_succ = 0;
|
|
typedef int(ACE_SDK_CALL* AceSdkServerDeinit)();
|
|
AceSdkServerDeinit func = (AceSdkServerDeinit)__ace_sdk_get_symbol("__ace_sdk_server_deinit");
|
|
if (func != NULL)
|
|
{
|
|
func();
|
|
}
|
|
ret = __ace_sdk_unload_library();
|
|
if (ret != 0)
|
|
{
|
|
return ACE_SDK_RESULT_UNLOAD_LIBRARY_FAILED;
|
|
}
|
|
return ACE_SDK_RESULT_OK;
|
|
}
|
|
|
|
/***
|
|
* Internal functions' implementation for special usage
|
|
*/
|
|
|
|
#pragma pack(push, 1)
|
|
|
|
/**
|
|
AceSdkServerEnvType
|
|
*/
|
|
typedef enum
|
|
{
|
|
ACE_SDK_SERVER_TEST = 101,
|
|
ACE_SDK_SERVER_PRODUCT = 1001
|
|
} AceSdkServerEnvType;
|
|
|
|
/**
|
|
AceSdkServerNetworkType
|
|
*/
|
|
typedef enum
|
|
{
|
|
ACE_SDK_SERVER_INTRA_NET = 0,
|
|
ACE_SDK_SERVER_PUBLIC_NET = 1,
|
|
} AceSdkServerNetType;
|
|
|
|
/**
|
|
AceSdkServerAccessInfo
|
|
*/
|
|
#define ACE_SDK_SERVER_MAX_DOMAIN_LEN 1024
|
|
typedef struct
|
|
{
|
|
char product_data_proxy_[ACE_SDK_SERVER_MAX_DOMAIN_LEN];
|
|
char product_busi_proxy_[ACE_SDK_SERVER_MAX_DOMAIN_LEN];
|
|
char test_data_proxy_[ACE_SDK_SERVER_MAX_DOMAIN_LEN];
|
|
char test_busi_proxy_[ACE_SDK_SERVER_MAX_DOMAIN_LEN];
|
|
AceSdkServerEnvType env_type_;
|
|
AceSdkServerNetType net_type_;
|
|
} AceSdkServerAccessInfo;
|
|
|
|
#pragma pack(pop)
|
|
|
|
inline AceSdkResult ace_sdk_server_customized_init(const struct __AceSdkServerLibraryInfo* library_info, const struct __AceSdkServerAuthInfo* auth_info, const AceSdkServerAccessInfo* access_info)
|
|
{
|
|
int32_t ret = ACE_SDK_RESULT_OK;
|
|
ACE_CHAR library_path[ACE_SDK_MAX_LIBRARY_DIR_LENGTH * 2] = {0};
|
|
#ifdef _WIN32
|
|
_snwprintf_s(library_path, sizeof(library_path)/sizeof(library_path[0]), _TRUNCATE, L"%s/%s", library_info->library_dir_, L"ace_sdk.dll");
|
|
#else
|
|
snprintf(library_path, sizeof(library_path), "%s/%s", library_info->library_dir_, "libace_sdk.so");
|
|
#endif
|
|
ret = __ace_sdk_load_library(library_path);
|
|
if (ret != 0)
|
|
{
|
|
return ACE_SDK_RESULT_LOAD_LIBRARY_FAILED;
|
|
}
|
|
typedef int(ACE_SDK_CALL* AceSdkServerInit)(const struct __AceSdkServerAuthInfo*, const AceSdkServerAccessInfo*);
|
|
AceSdkServerInit func = (AceSdkServerInit)__ace_sdk_get_symbol("__ace_sdk_server_customized_init");
|
|
if (func == NULL)
|
|
{
|
|
return ACE_SDK_RESULT_SYMBOL_NOT_FOUND;
|
|
}
|
|
ret = func(auth_info, access_info);
|
|
if (ret != 0)
|
|
{
|
|
return ACE_SDK_RESULT_INVALID_PARAMETER;
|
|
}
|
|
__ace_sdk_init_succ = 1;
|
|
return ACE_SDK_RESULT_OK;
|
|
}
|
|
#endif // __ACE_SDK_SERVER_IMPL_H__
|