mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-01-23 01:21:57 -05:00
3DS: Add untested SSL support and log what's in argv
Also for LOWMEM platforms (3DS/PSP etc), reduce size of initial singleplayer world to 64x64x64
This commit is contained in:
parent
2851e02dcf
commit
54e1e47ada
4 changed files with 81 additions and 16 deletions
|
@ -146,13 +146,12 @@ int File_Exists(const cc_string* path) {
|
||||||
cc_result Directory_Enum(const cc_string* dirPath, void* obj, Directory_EnumCallback callback) {
|
cc_result Directory_Enum(const cc_string* dirPath, void* obj, Directory_EnumCallback callback) {
|
||||||
cc_string path; char pathBuffer[FILENAME_SIZE];
|
cc_string path; char pathBuffer[FILENAME_SIZE];
|
||||||
char str[NATIVE_STR_LEN];
|
char str[NATIVE_STR_LEN];
|
||||||
DIR* dirPtr;
|
|
||||||
struct dirent* entry;
|
struct dirent* entry;
|
||||||
char* src;
|
char* src;
|
||||||
int len, res, is_dir;
|
int len, res, is_dir;
|
||||||
|
|
||||||
GetNativePath(str, dirPath);
|
GetNativePath(str, dirPath);
|
||||||
dirPtr = opendir(str);
|
DIR* dirPtr = opendir(str);
|
||||||
if (!dirPtr) return errno;
|
if (!dirPtr) return errno;
|
||||||
|
|
||||||
/* POSIX docs: "When the end of the directory is encountered, a null pointer is returned and errno is not changed." */
|
/* POSIX docs: "When the end of the directory is encountered, a null pointer is returned and errno is not changed." */
|
||||||
|
@ -320,13 +319,13 @@ static int ParseHost(union SocketAddress* addr, const char* host) {
|
||||||
struct addrinfo hints = { 0 };
|
struct addrinfo hints = { 0 };
|
||||||
struct addrinfo* result;
|
struct addrinfo* result;
|
||||||
struct addrinfo* cur;
|
struct addrinfo* cur;
|
||||||
int success = 0, res;
|
int success = 0;
|
||||||
|
|
||||||
hints.ai_family = AF_INET;
|
hints.ai_family = AF_INET;
|
||||||
hints.ai_socktype = SOCK_STREAM;
|
hints.ai_socktype = SOCK_STREAM;
|
||||||
hints.ai_protocol = IPPROTO_TCP;
|
hints.ai_protocol = IPPROTO_TCP;
|
||||||
|
|
||||||
res = getaddrinfo(host, NULL, &hints, &result);
|
int res = getaddrinfo(host, NULL, &hints, &result);
|
||||||
if (res) return 0;
|
if (res) return 0;
|
||||||
|
|
||||||
for (cur = result; cur; cur = cur->ai_next) {
|
for (cur = result; cur; cur = cur->ai_next) {
|
||||||
|
@ -356,7 +355,6 @@ int Socket_ValidAddress(const cc_string* address) {
|
||||||
|
|
||||||
cc_result Socket_Connect(cc_socket* s, const cc_string* address, int port, cc_bool nonblocking) {
|
cc_result Socket_Connect(cc_socket* s, const cc_string* address, int port, cc_bool nonblocking) {
|
||||||
union SocketAddress addr;
|
union SocketAddress addr;
|
||||||
cc_result res;
|
|
||||||
|
|
||||||
*s = -1;
|
*s = -1;
|
||||||
if (!ParseAddress(&addr, address))
|
if (!ParseAddress(&addr, address))
|
||||||
|
@ -373,7 +371,7 @@ cc_result Socket_Connect(cc_socket* s, const cc_string* address, int port, cc_bo
|
||||||
addr.v4.sin_family = AF_INET;
|
addr.v4.sin_family = AF_INET;
|
||||||
addr.v4.sin_port = htons(port);
|
addr.v4.sin_port = htons(port);
|
||||||
|
|
||||||
res = connect(*s, &addr.raw, sizeof(addr.v4));
|
int res = connect(*s, &addr.raw, sizeof(addr.v4));
|
||||||
return res == -1 ? errno : 0;
|
return res == -1 ? errno : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -396,15 +394,14 @@ void Socket_Close(cc_socket s) {
|
||||||
|
|
||||||
static cc_result Socket_Poll(cc_socket s, int mode, cc_bool* success) {
|
static cc_result Socket_Poll(cc_socket s, int mode, cc_bool* success) {
|
||||||
struct pollfd pfd;
|
struct pollfd pfd;
|
||||||
int flags;
|
|
||||||
|
|
||||||
pfd.fd = s;
|
pfd.fd = s;
|
||||||
pfd.events = mode == SOCKET_POLL_READ ? POLLIN : POLLOUT;
|
pfd.events = mode == SOCKET_POLL_READ ? POLLIN : POLLOUT;
|
||||||
if (poll(&pfd, 1, 0) == -1) { *success = false; return errno; }
|
if (poll(&pfd, 1, 0) == -1) { *success = false; return errno; }
|
||||||
|
|
||||||
/* to match select, closed socket still counts as readable */
|
/* to match select, closed socket still counts as readable */
|
||||||
flags = mode == SOCKET_POLL_READ ? (POLLIN | POLLHUP) : POLLOUT;
|
int flags = mode == SOCKET_POLL_READ ? (POLLIN | POLLHUP) : POLLOUT;
|
||||||
*success = (pfd.revents & flags) != 0;
|
*success = (pfd.revents & flags) != 0;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -527,13 +524,14 @@ cc_result Platform_Decrypt(const void* data, int len, cc_string* dst) {
|
||||||
*-----------------------------------------------------Configuration-------------------------------------------------------*
|
*-----------------------------------------------------Configuration-------------------------------------------------------*
|
||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
int Platform_GetCommandLineArgs(int argc, STRING_REF char** argv, cc_string* args) {
|
int Platform_GetCommandLineArgs(int argc, STRING_REF char** argv, cc_string* args) {
|
||||||
int i, count;
|
|
||||||
// 3DS *sometimes* doesn't use argv[0] for program name and so argc will be 0
|
// 3DS *sometimes* doesn't use argv[0] for program name and so argc will be 0
|
||||||
// (e.g. when running from Citra)
|
// (e.g. when running from Citra)
|
||||||
|
int count = min(argc, GAME_MAX_CMDARGS);
|
||||||
|
Platform_Log1("ARGS: %i", &count);
|
||||||
|
|
||||||
count = min(argc, GAME_MAX_CMDARGS);
|
for (int i = 0; i < count; i++) {
|
||||||
for (i = 0; i < count; i++) {
|
|
||||||
args[i] = String_FromReadonly(argv[i]);
|
args[i] = String_FromReadonly(argv[i]);
|
||||||
|
Platform_Log2(" ARG %i = %c", &i, argv[i]);
|
||||||
}
|
}
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
65
src/SSL.c
65
src/SSL.c
|
@ -43,7 +43,7 @@ void SSLBackend_Init(cc_bool verifyCerts) {
|
||||||
/* Officially, InitSecurityInterfaceA and then AcquireCredentialsA from */
|
/* Officially, InitSecurityInterfaceA and then AcquireCredentialsA from */
|
||||||
/* secur32.dll (or security.dll) should be called - however */
|
/* secur32.dll (or security.dll) should be called - however */
|
||||||
/* AcquireCredentialsA fails with SEC_E_SECPKG_NOT_FOUND on Win 9x */
|
/* AcquireCredentialsA fails with SEC_E_SECPKG_NOT_FOUND on Win 9x */
|
||||||
/* But if you instead directly call those functions from schannel.dll,
|
/* But if you instead directly call those functions from schannel.dll, */
|
||||||
/* then it DOES work. (and on later Windows versions, those functions */
|
/* then it DOES work. (and on later Windows versions, those functions */
|
||||||
/* exported from schannel.dll are just DLL forwards to secur32.dll */
|
/* exported from schannel.dll are just DLL forwards to secur32.dll */
|
||||||
static const struct DynamicLibSym funcs[] = {
|
static const struct DynamicLibSym funcs[] = {
|
||||||
|
@ -407,6 +407,69 @@ cc_result SSL_Free(void* ctx_) {
|
||||||
Mem_Free(ctx);
|
Mem_Free(ctx);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
#elif defined CC_BUILD_3DS
|
||||||
|
#include <3ds.h>
|
||||||
|
#include "String.h"
|
||||||
|
// https://github.com/devkitPro/3ds-examples/blob/master/network/sslc/source/ssl.c
|
||||||
|
// https://github.com/devkitPro/libctru/blob/master/libctru/include/3ds/services/sslc.h
|
||||||
|
static u32 certChainHandle;
|
||||||
|
static cc_bool _verifyCerts;
|
||||||
|
static void SSL_CreateRootChain(void) {
|
||||||
|
int ret = sslcCreateRootCertChain(&certChainHandle);
|
||||||
|
if (ret) { Platform_Log1("sslcCreateRootCertChain failed: %i", &ret); return; }
|
||||||
|
}
|
||||||
|
|
||||||
|
void SSLBackend_Init(cc_bool verifyCerts) {
|
||||||
|
int ret = sslcInit(0);
|
||||||
|
if (ret) { Platform_Log1("sslcInit failed: %i", &ret); return; }
|
||||||
|
|
||||||
|
_verifyCerts = verifyCerts;
|
||||||
|
SSL_CreateRootChain();
|
||||||
|
}
|
||||||
|
cc_bool SSLBackend_DescribeError(cc_result res, cc_string* dst) { return false; }
|
||||||
|
|
||||||
|
cc_result SSL_Init(cc_socket socket, const cc_string* host_, void** out_ctx) {
|
||||||
|
if (!certChainHandle) return HTTP_ERR_NO_SSL;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
sslcContext* ctx;
|
||||||
|
char host[NATIVE_STR_LEN];
|
||||||
|
String_EncodeUtf8(host, host_);
|
||||||
|
|
||||||
|
ctx = Mem_TryAllocCleared(1, sizeof(sslcContext));
|
||||||
|
if (!ctx) return ERR_OUT_OF_MEMORY;
|
||||||
|
*out_ctx = (void*)ctx;
|
||||||
|
|
||||||
|
int opts = _verifyCerts ? SSLCOPT_Default : SSLCOPT_DisableVerify;
|
||||||
|
if ((ret = sslcCreateContext(ctx, socket, opts, host))) return ret;
|
||||||
|
sslcContextSetRootCertChain(ctx, certChainHandle);
|
||||||
|
|
||||||
|
// detect lack of proper SSL support in Citra
|
||||||
|
if (!ctx->sslchandle) return HTTP_ERR_NO_SSL;
|
||||||
|
if ((ret = sslcStartConnection(ctx, NULL, NULL))) return ret;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
cc_result SSL_Read(void* ctx_, cc_uint8* data, cc_uint32 count, cc_uint32* read) {
|
||||||
|
sslcContext* ctx = (sslcContext*)ctx_;
|
||||||
|
int ret = sslcRead(ctx, data, count, false);
|
||||||
|
|
||||||
|
if (ret < 0) return ret;
|
||||||
|
*read = ret; return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
cc_result SSL_Write(void* ctx_, const cc_uint8* data, cc_uint32 count, cc_uint32* wrote) {
|
||||||
|
sslcContext* ctx = (sslcContext*)ctx_;
|
||||||
|
int ret = sslcWrite(ctx, data, count);
|
||||||
|
|
||||||
|
if (ret < 0) return ret;
|
||||||
|
*wrote = ret; return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
cc_result SSL_Free(void* ctx_) {
|
||||||
|
sslcContext* ctx = (sslcContext*)ctx_;
|
||||||
|
return sslcDestroyContext(ctx);
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
void SSLBackend_Init(cc_bool verifyCerts) { }
|
void SSLBackend_Init(cc_bool verifyCerts) { }
|
||||||
cc_bool SSLBackend_DescribeError(cc_result res, cc_string* dst) { return false; }
|
cc_bool SSLBackend_DescribeError(cc_result res, cc_string* dst) { return false; }
|
||||||
|
|
|
@ -127,7 +127,11 @@ static void SPConnection_BeginConnect(void) {
|
||||||
|
|
||||||
Random_SeedFromCurrentTime(&rnd);
|
Random_SeedFromCurrentTime(&rnd);
|
||||||
World_NewMap();
|
World_NewMap();
|
||||||
|
#if defined CC_BUILD_LOWMEM
|
||||||
|
World_SetDimensions(64, 64, 64);
|
||||||
|
#else
|
||||||
World_SetDimensions(128, 64, 128);
|
World_SetDimensions(128, 64, 128);
|
||||||
|
#endif
|
||||||
|
|
||||||
Gen_Vanilla = true;
|
Gen_Vanilla = true;
|
||||||
Gen_Seed = Random_Next(&rnd, Int32_MaxValue);
|
Gen_Seed = Random_Next(&rnd, Int32_MaxValue);
|
||||||
|
|
|
@ -162,7 +162,7 @@ void Window_DrawFramebuffer(Rect2D r);
|
||||||
void Window_FreeFramebuffer(struct Bitmap* bmp);
|
void Window_FreeFramebuffer(struct Bitmap* bmp);
|
||||||
|
|
||||||
struct OpenKeyboardArgs { const cc_string* text; int type; const char* placeholder; cc_bool opaque, multiline; };
|
struct OpenKeyboardArgs { const cc_string* text; int type; const char* placeholder; cc_bool opaque, multiline; };
|
||||||
static void OpenKeyboardArgs_Init(struct OpenKeyboardArgs* args, STRING_REF const cc_string* text, int type) {
|
static CC_INLINE void OpenKeyboardArgs_Init(struct OpenKeyboardArgs* args, STRING_REF const cc_string* text, int type) {
|
||||||
args->text = text;
|
args->text = text;
|
||||||
args->type = type;
|
args->type = type;
|
||||||
args->placeholder = "";
|
args->placeholder = "";
|
||||||
|
|
Loading…
Reference in a new issue