Skip to content

Commit

Permalink
Added ability to set lobby password
Browse files Browse the repository at this point in the history
  • Loading branch information
MysterD committed Apr 15, 2023
1 parent e676979 commit 875cde6
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 27 deletions.
1 change: 1 addition & 0 deletions lang/English.ini
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ DIRECT_CONNECTION = "Direct Connection"
COOPNET = "CoopNet"
NETWORK_SYSTEM = "Network system"
PORT = "Port"
PASSWORD = "Password"
SAVE_SLOT = "Save Slot"
SETTINGS = "Settings"
MODS = "Mods"
Expand Down
Binary file modified lib/coopnet/linux/libcoopnet.a
Binary file not shown.
6 changes: 4 additions & 2 deletions src/pc/configfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ bool configDebugError = 0;
char configLanguage[MAX_CONFIG_STRING] = "";
char configCoopNetIp[MAX_CONFIG_STRING] = DEFAULT_COOPNET_IP;
unsigned int configCoopNetPort = DEFAULT_COOPNET_PORT;
char configPassword[MAX_PLAYER_STRING] = "";

static const struct ConfigOption options[] = {
{.name = "fullscreen", .type = CONFIG_TYPE_BOOL, .boolValue = &configWindow.fullscreen},
Expand Down Expand Up @@ -268,6 +269,7 @@ static const struct ConfigOption options[] = {
{.name = "language", .type = CONFIG_TYPE_STRING, .stringValue = (char*)&configLanguage, .maxStringLength = MAX_CONFIG_STRING},
{.name = "coopnet_ip", .type = CONFIG_TYPE_STRING, .stringValue = (char*)&configCoopNetIp, .maxStringLength = MAX_CONFIG_STRING},
{.name = "coopnet_port", .type = CONFIG_TYPE_UINT , .uintValue = &configCoopNetPort},
{.name = "coopnet_password", .type = CONFIG_TYPE_STRING, .stringValue = (char*)&configPassword, .maxStringLength = MAX_CONFIG_STRING},
};

// FunctionConfigOption functions
Expand Down Expand Up @@ -556,8 +558,8 @@ static void configfile_load_internal(const char *filename, bool* error) {
if (configFrameLimit < 30) { configFrameLimit = 30; }
if (configFrameLimit > 3000) { configFrameLimit = 3000; }

#ifndef DISCORD_SDK
configNetworkSystem = 1;
#ifndef COOPNET
configNetworkSystem = NS_SOCKET;
#endif
}

Expand Down
1 change: 1 addition & 0 deletions src/pc/configfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ extern bool configDebugError;
extern char configLanguage[];
extern char configCoopNetIp[];
extern unsigned int configCoopNetPort;
extern char configPassword[];

void configfile_load(void);
void configfile_save(const char *filename);
Expand Down
94 changes: 70 additions & 24 deletions src/pc/djui/djui_panel_host.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
#include "pc/configfile.h"
#include "pc/cheats.h"

struct DjuiRect* sRectPort = NULL;
struct DjuiRect* sRectPassword = NULL;
struct DjuiInputbox* sInputboxPort = NULL;
struct DjuiInputbox* sInputboxPassword = NULL;

static void djui_panel_host_network_system_change(UNUSED struct DjuiBase* base) {
#ifndef DISCORD_SDK
Expand All @@ -31,7 +34,11 @@ static void djui_panel_host_network_system_change(UNUSED struct DjuiBase* base)
}
}
#endif

djui_base_set_visible(&sRectPort->base, (configNetworkSystem == NS_SOCKET));
djui_base_set_visible(&sRectPassword->base, (configNetworkSystem == NS_COOPNET));
djui_base_set_enabled(&sInputboxPort->base, (configNetworkSystem == NS_SOCKET));
djui_base_set_enabled(&sInputboxPassword->base, (configNetworkSystem == NS_COOPNET));
}

static bool djui_panel_host_port_valid(void) {
Expand All @@ -51,11 +58,18 @@ static bool djui_panel_host_port_valid(void) {
}

static void djui_panel_host_port_text_change(struct DjuiBase* caller) {
struct DjuiInputbox* inputbox1 = (struct DjuiInputbox*)caller;
struct DjuiInputbox* sInputboxPort = (struct DjuiInputbox*)caller;
if (djui_panel_host_port_valid()) {
djui_inputbox_set_text_color(inputbox1, 0, 0, 0, 255);
djui_inputbox_set_text_color(sInputboxPort, 0, 0, 0, 255);
} else {
djui_inputbox_set_text_color(inputbox1, 255, 0, 0, 255);
djui_inputbox_set_text_color(sInputboxPort, 255, 0, 0, 255);
}
}

static void djui_panel_host_password_text_change(UNUSED struct DjuiBase* caller) {
snprintf(configPassword, 64, "%s", sInputboxPassword->buffer);
if (strlen(sInputboxPassword->buffer) >= 64) {
djui_inputbox_set_text(sInputboxPassword, configPassword);
}
}

Expand Down Expand Up @@ -87,37 +101,69 @@ void djui_panel_host_create(struct DjuiBase* caller) {
: DLANG(HOST, HOST_TITLE));
struct DjuiBase* body = djui_three_panel_get_body(panel);
{
char* nChoices[] = { DLANG(HOST, DISCORD), DLANG(HOST, DIRECT_CONNECTION), DLANG(HOST, COOPNET) };
char* nChoices[] = { DLANG(HOST, DIRECT_CONNECTION), DLANG(HOST, DISCORD), DLANG(HOST, COOPNET) };
struct DjuiSelectionbox* selectionbox1 = djui_selectionbox_create(body, DLANG(HOST, NETWORK_SYSTEM), nChoices, 3, &configNetworkSystem, djui_panel_host_network_system_change);
if (gNetworkType == NT_SERVER) {
djui_base_set_enabled(&selectionbox1->base, false);
}

struct DjuiRect* rect1 = djui_rect_container_create(body, 32);
{
struct DjuiText* text1 = djui_text_create(&rect1->base, DLANG(HOST, PORT));
djui_base_set_size_type(&text1->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE);
djui_base_set_color(&text1->base, 200, 200, 200, 255);
djui_base_set_size(&text1->base, 0.585f, 64);
djui_base_set_alignment(&text1->base, DJUI_HALIGN_LEFT, DJUI_VALIGN_TOP);
if (gNetworkType == NT_SERVER) {
djui_base_set_enabled(&text1->base, false);
sRectPort = djui_rect_container_create(&rect1->base, 32);
djui_base_set_location(&sRectPort->base, 0, 0);
djui_base_set_visible(&sRectPort->base, (configNetworkSystem == NS_SOCKET));
{
struct DjuiText* text1 = djui_text_create(&sRectPort->base, DLANG(HOST, PORT));
djui_base_set_size_type(&text1->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE);
djui_base_set_color(&text1->base, 200, 200, 200, 255);
djui_base_set_size(&text1->base, 0.585f, 64);
djui_base_set_alignment(&text1->base, DJUI_HALIGN_LEFT, DJUI_VALIGN_TOP);
if (gNetworkType == NT_SERVER) {
djui_base_set_enabled(&text1->base, false);
}

sInputboxPort = djui_inputbox_create(&sRectPort->base, 32);
djui_base_set_size_type(&sInputboxPort->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE);
djui_base_set_size(&sInputboxPort->base, 0.4f, 32);
djui_base_set_alignment(&sInputboxPort->base, DJUI_HALIGN_RIGHT, DJUI_VALIGN_TOP);
char portString[32] = { 0 };
snprintf(portString, 32, "%d", configHostPort);
djui_inputbox_set_text(sInputboxPort, portString);
djui_interactable_hook_value_change(&sInputboxPort->base, djui_panel_host_port_text_change);
if (gNetworkType == NT_SERVER) {
djui_base_set_enabled(&sInputboxPort->base, false);
} else {
djui_base_set_enabled(&sInputboxPort->base, (configNetworkSystem == NS_SOCKET));
}
}

struct DjuiInputbox* inputbox1 = djui_inputbox_create(&rect1->base, 32);
djui_base_set_size_type(&inputbox1->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE);
djui_base_set_size(&inputbox1->base, 0.4f, 32);
djui_base_set_alignment(&inputbox1->base, DJUI_HALIGN_RIGHT, DJUI_VALIGN_TOP);
char portString[32] = { 0 };
snprintf(portString, 32, "%d", configHostPort);
djui_inputbox_set_text(inputbox1, portString);
djui_interactable_hook_value_change(&inputbox1->base, djui_panel_host_port_text_change);
if (gNetworkType == NT_SERVER) {
djui_base_set_enabled(&inputbox1->base, false);
} else {
djui_base_set_enabled(&inputbox1->base, (configNetworkSystem == NS_SOCKET));
sRectPassword = djui_rect_container_create(&rect1->base, 32);
djui_base_set_location(&sRectPassword->base, 0, 0);
djui_base_set_visible(&sRectPassword->base, (configNetworkSystem == NS_COOPNET));
{
struct DjuiText* text1 = djui_text_create(&sRectPassword->base, DLANG(HOST, PASSWORD));
djui_base_set_size_type(&text1->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE);
djui_base_set_color(&text1->base, 200, 200, 200, 255);
djui_base_set_size(&text1->base, 0.585f, 64);
djui_base_set_alignment(&text1->base, DJUI_HALIGN_LEFT, DJUI_VALIGN_TOP);
if (gNetworkType == NT_SERVER) {
djui_base_set_enabled(&text1->base, false);
}

sInputboxPassword = djui_inputbox_create(&sRectPassword->base, 32);
djui_base_set_size_type(&sInputboxPassword->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE);
djui_base_set_size(&sInputboxPassword->base, 0.4f, 32);
djui_base_set_alignment(&sInputboxPassword->base, DJUI_HALIGN_RIGHT, DJUI_VALIGN_TOP);
char portPassword[64] = { 0 };
snprintf(portPassword, 64, "%s", configPassword);
djui_inputbox_set_text(sInputboxPassword, portPassword);
djui_interactable_hook_value_change(&sInputboxPassword->base, djui_panel_host_password_text_change);
if (gNetworkType == NT_SERVER) {
djui_base_set_enabled(&sInputboxPassword->base, false);
} else {
djui_base_set_enabled(&sInputboxPassword->base, (configNetworkSystem == NS_COOPNET));
}
}
sInputboxPort = inputbox1;
}

struct DjuiRect* rect2 = djui_rect_container_create(body, 32);
Expand Down
2 changes: 1 addition & 1 deletion src/pc/network/coopnet/coopnet.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ void ns_coopnet_update(void) {
LOG_INFO("Create lobby");
char mode[64] = "";
mods_get_main_mod_name(mode, 64);
coopnet_lobby_create(CN_GAME_STR, get_version(), configPlayerName, mode, (uint16_t)configAmountofPlayers, "");
coopnet_lobby_create(CN_GAME_STR, get_version(), configPlayerName, mode, (uint16_t)configAmountofPlayers, configPassword);
} else if (sNetworkType == NT_CLIENT) {
LOG_INFO("Join lobby");
coopnet_lobby_join(gCoopNetDesiredLobby, "");
Expand Down

0 comments on commit 875cde6

Please sign in to comment.