Skip to content

Commit

Permalink
If : is provided as first character of username, treat it as a server…
Browse files Browse the repository at this point in the history
… hash to autojoin instead
  • Loading branch information
UnknownShadow200 committed May 17, 2019
1 parent 283734c commit f32f263
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 18 deletions.
2 changes: 2 additions & 0 deletions src/Game.c
Expand Up @@ -58,10 +58,12 @@ static int Game_TasksCount, entTaskI;
static char Game_UsernameBuffer[FILENAME_SIZE];
static char Game_MppassBuffer[STRING_SIZE];
static char Game_IPAddressBuffer[STRING_SIZE];
static char Game_HashBuffer[STRING_SIZE];

String Game_Username = String_FromArray(Game_UsernameBuffer);
String Game_Mppass = String_FromArray(Game_MppassBuffer);
String Game_IPAddress = String_FromArray(Game_IPAddressBuffer);
String Game_Hash = String_FromArray(Game_HashBuffer);

static struct IGameComponent* comps_head;
static struct IGameComponent* comps_tail;
Expand Down
1 change: 1 addition & 0 deletions src/Game.h
Expand Up @@ -25,6 +25,7 @@ extern bool Game_UseCPEBlocks;
extern String Game_Username;
extern String Game_Mppass;
extern String Game_IPAddress;
extern String Game_Hash;
extern int Game_Port;

extern int Game_ViewDistance;
Expand Down
8 changes: 4 additions & 4 deletions src/Graphics.c
Expand Up @@ -1864,11 +1864,11 @@ void Gfx_DrawIndexedVb_TrisT2fC4b(int verticesCount, int startVertex) {

static void GL_CheckSupport(void) {
const static String vboExt = String_FromConst("GL_ARB_vertex_buffer_object");
String extensions = String_FromReadonly(glGetString(GL_EXTENSIONS));
String version = String_FromReadonly(glGetString(GL_VERSION));
String extensions = String_FromReadonly(glGetString(GL_EXTENSIONS));
const GLubyte* ver = glGetString(GL_VERSION);

int major = (int)(version.buffer[0] - '0'); /* x.y. (and so forth) */
int minor = (int)(version.buffer[2] - '0');
/* Version string is always: x.y. (and whatever afterwards) */
int major = ver[0] - '0', minor = ver[2] - '0';

/* Supported in core since 1.5 */
if (major > 1 || (major == 1 && minor >= 5)) {
Expand Down
10 changes: 6 additions & 4 deletions src/Input.h
Expand Up @@ -5,7 +5,7 @@
Copyright 2017 ClassicalSharp | Licensed under BSD-3 | Based on OpenTK code
*/

typedef enum Key_ {
enum Key_ {
KEY_NONE, /* Unrecognised key */

KEY_F1, KEY_F2, KEY_F3, KEY_F4, KEY_F5, KEY_F6, KEY_F7, KEY_F8, KEY_F9, KEY_F10,
Expand Down Expand Up @@ -41,7 +41,8 @@ typedef enum Key_ {

KEY_XBUTTON1, KEY_XBUTTON2, /* so these can be used for hotkeys */
KEY_COUNT
} Key;
};
typedef int Key;

/* Simple names for each keyboard button. */
extern const char* Key_Names[KEY_COUNT];
Expand Down Expand Up @@ -69,10 +70,11 @@ void Key_SetPressed(Key key, bool pressed);
void Key_Clear(void);


typedef enum MouseButton_ {
enum MouseButton_ {
MOUSE_LEFT, MOUSE_RIGHT, MOUSE_MIDDLE,
MOUSE_COUNT
} MouseButton;
};
typedef int MouseButton;

/* Wheel position of the mouse. Use Mouse_SetWheel to change. */
extern float Mouse_Wheel;
Expand Down
6 changes: 5 additions & 1 deletion src/LScreens.c
Expand Up @@ -920,7 +920,11 @@ static void MainScreen_TickFetchServers(struct MainScreen* s) {

if (FetchServersTask.Base.Success) {
s->SigningIn = false;
Launcher_SetScreen(ServersScreen_MakeInstance());
if (Game_Hash.length) {
Launcher_ConnectToServer(&Game_Hash);
} else {
Launcher_SetScreen(ServersScreen_MakeInstance());
}
} else {
MainScreen_Error(&FetchServersTask.Base, "retrieving servers list");
}
Expand Down
11 changes: 10 additions & 1 deletion src/Program.c
Expand Up @@ -147,11 +147,20 @@ int main(int argc, char** argv) {
if (argsCount == 0) {
#ifdef CC_BUILD_WEB
String_AppendConst(&Game_Username, "WebTest!");
Program_RunGame();
Program_RunGame();
#else
Launcher_Run();
#endif
} else if (argsCount == 1) {
#ifndef CC_BUILD_WEB
/* :hash to auto join server with the given hash */
if (args[0].buffer[0] == ':') {
args[0] = String_UNSAFE_SubstringAt(&args[0], 1);
String_Copy(&Game_Hash, &args[0]);
Launcher_Run();
return 0;
}
#endif
String_Copy(&Game_Username, &args[0]);
Program_RunGame();
} else if (argsCount < 4) {
Expand Down
4 changes: 2 additions & 2 deletions src/Resources.c
Expand Up @@ -293,7 +293,7 @@ static ReturnCode ZipPatcher_WriteData(struct Stream* dst, struct ResourceTextur
static ReturnCode ZipPatcher_WriteZipEntry(struct Stream* src, struct ResourceTexture* tex, struct ZipState* state) {
uint8_t tmp[2048];
uint32_t read;
struct Stream* dst = state->Obj;
struct Stream* dst = (struct Stream*)state->Obj;
ReturnCode res;

tex->Size = state->_curEntry->UncompressedSize;
Expand Down Expand Up @@ -464,7 +464,7 @@ static ReturnCode ModernPatcher_ProcessEntry(const String* path, struct Stream*
}

if (String_CaselessEqualsConst(path, "assets/minecraft/textures/blocks/fire_layer_1.png")) {
struct Stream* dst = state->Obj;
struct Stream* dst = (struct Stream*)state->Obj;
return ModernPatcher_MakeAnimations(dst, data);
}

Expand Down
12 changes: 6 additions & 6 deletions src/Window.c
Expand Up @@ -149,7 +149,7 @@ const static uint8_t key_map[14 * 16] = {
KEY_TILDE, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, KEY_LBRACKET, KEY_BACKSLASH, KEY_RBRACKET, KEY_QUOTE, 0,
};
static int Window_MapKey(WPARAM key) { return key < Array_Elems(key_map) ? key_map[key] : 0; }
static Key Window_MapKey(WPARAM key) { return key < Array_Elems(key_map) ? key_map[key] : 0; }

static void Window_ResetWindowState(void) {
suppress_resize++;
Expand Down Expand Up @@ -762,7 +762,7 @@ static long win_eventMask;
/*########################################################################################################################*
*-----------------------------------------------------Private details-----------------------------------------------------*
*#########################################################################################################################*/
static int Window_MapKey(KeySym key) {
static Key Window_MapKey(KeySym key) {
if (key >= XK_0 && key <= XK_9) { return '0' + (key - XK_0); }
if (key >= XK_A && key <= XK_Z) { return 'A' + (key - XK_A); }
if (key >= XK_a && key <= XK_z) { return 'A' + (key - XK_a); }
Expand Down Expand Up @@ -1033,7 +1033,7 @@ void Window_SetVisible(bool visible) {
}
}

void* Window_GetHandle(void) { return win_handle; }
void* Window_GetHandle(void) { return (void*)win_handle; }

int Window_GetWindowState(void) {
Atom prop_type;
Expand Down Expand Up @@ -1653,7 +1653,7 @@ const static uint8_t key_map[8 * 16] = {
KEY_F5, KEY_F6, KEY_F7, KEY_F3, KEY_F8, KEY_F9, 0, KEY_F11, 0, KEY_F13, 0, KEY_F14, 0, KEY_F10, 0, KEY_F12,
'U', KEY_F15, KEY_INSERT, KEY_HOME, KEY_PAGEUP, KEY_DELETE, KEY_F4, KEY_END, KEY_F2, KEY_PAGEDOWN, KEY_F1, KEY_LEFT, KEY_RIGHT, KEY_DOWN, KEY_UP, 0,
};
static int Window_MapKey(UInt32 key) { return key < Array_Elems(key_map) ? key_map[key] : 0; }
static Key Window_MapKey(UInt32 key) { return key < Array_Elems(key_map) ? key_map[key] : 0; }
/* TODO: Check these.. */
/* case 0x37: return KEY_LWIN; */
/* case 0x38: return KEY_LSHIFT; */
Expand Down Expand Up @@ -2381,7 +2381,7 @@ void Window_Close(void) {
SDL_PushEvent(&e);
}

static int Window_MapKey(SDL_Keycode k) {
static Key Window_MapKey(SDL_Keycode k) {
if (k >= SDLK_0 && k <= SDLK_9) { return '0' + (k - SDLK_0); }
if (k >= SDLK_a && k <= SDLK_z) { return 'A' + (k - SDLK_a); }
if (k >= SDLK_F1 && k <= SDLK_F12) { return KEY_F1 + (k - SDLK_F1); }
Expand Down Expand Up @@ -2697,7 +2697,7 @@ static const char* Window_BeforeUnload(int type, const void* ev, void *data) {
return NULL;
}

static int Window_MapKey(int k) {
static Key Window_MapKey(int k) {
if (k >= '0' && k <= '9') return k;
if (k >= 'A' && k <= 'Z') return k;
if (k >= DOM_VK_F1 && k <= DOM_VK_F24) { return KEY_F1 + (k - DOM_VK_F1); }
Expand Down

0 comments on commit f32f263

Please sign in to comment.