Fix when starting the game via dropping a map file onto it, your in-game player used file path for name/skin instead of default username (Thanks Neonium)

This commit is contained in:
UnknownShadow200 2022-12-02 20:50:00 +11:00
parent 6755047052
commit 8deb8044e9
5 changed files with 13 additions and 3 deletions

View File

@ -80,4 +80,6 @@ enum SKIN_TYPE { SKIN_64x32, SKIN_64x64, SKIN_64x64_SLIM, SKIN_INVALID = 0xF0 };
#define RESOURCE_SERVER "http://static.classicube.net" #define RESOURCE_SERVER "http://static.classicube.net"
/* Webpage where users can register for a new account */ /* Webpage where users can register for a new account */
#define REGISTERNEW_URL "https://www.classicube.net/acc/register/" #define REGISTERNEW_URL "https://www.classicube.net/acc/register/"
#define DEFAULT_USERNAME "Singleplayer"
#endif #endif

View File

@ -396,6 +396,8 @@ static cc_result HttpBackend_Do(struct HttpRequest* req, cc_string* url) {
/* must be at least CURL_ERROR_SIZE (256) in size */ /* must be at least CURL_ERROR_SIZE (256) in size */
req->error = Mem_TryAllocCleared(257, 1); req->error = Mem_TryAllocCleared(257, 1);
_curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, req->error); _curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, req->error);
/* TODO stackalloc instead and then copy to dynamic array later? */
/* probably not worth the extra complexity though */
req->_capacity = 0; req->_capacity = 0;
http_curProgress = HTTP_PROGRESS_FETCHING_DATA; http_curProgress = HTTP_PROGRESS_FETCHING_DATA;

View File

@ -753,7 +753,7 @@ static void MainScreen_Resume(void* w) {
} }
static void MainScreen_Singleplayer(void* w) { static void MainScreen_Singleplayer(void* w) {
static const cc_string defUser = String_FromConst("Singleplayer"); static const cc_string defUser = String_FromConst(DEFAULT_USERNAME);
const cc_string* user = &MainScreen.iptUsername.text; const cc_string* user = &MainScreen.iptUsername.text;
if (!user->length) user = &defUser; if (!user->length) user = &defUser;

View File

@ -81,7 +81,7 @@ static int RunProgram(int argc, char** argv) {
if (argsCount == 0) { if (argsCount == 0) {
#ifdef CC_BUILD_WEB #ifdef CC_BUILD_WEB
String_AppendConst(&Game_Username, "WebTest!"); String_AppendConst(&Game_Username, DEFAULT_USERNAME);
RunGame(); RunGame();
#else #else
Launcher_Run(); Launcher_Run();

View File

@ -24,6 +24,7 @@
#include "Platform.h" #include "Platform.h"
#include "Input.h" #include "Input.h"
#include "Errors.h" #include "Errors.h"
#include "Options.h"
static char nameBuffer[STRING_SIZE]; static char nameBuffer[STRING_SIZE];
static char motdBuffer[STRING_SIZE]; static char motdBuffer[STRING_SIZE];
@ -121,7 +122,12 @@ static void SPConnection_BeginConnect(void) {
/* For when user drops a map file onto ClassiCube.exe */ /* For when user drops a map file onto ClassiCube.exe */
path = Game_Username; path = Game_Username;
if (SP_HasDir(path) && File_Exists(&path)) { if (SP_HasDir(path) && File_Exists(&path)) {
Map_LoadFrom(&path); return; Map_LoadFrom(&path);
Options_Get(LOPT_USERNAME, &Game_Username, DEFAULT_USERNAME);
/* TODO Entity_SetNameSkin function? */
Entity_SetName(&LocalPlayer_Instance.Base, &Game_Username);
Entity_SetSkin(&LocalPlayer_Instance.Base, &Game_Username);
return;
} }
Random_SeedFromCurrentTime(&rnd); Random_SeedFromCurrentTime(&rnd);