mirror of
https://github.com/coop-deluxe/sm64coopdx.git
synced 2024-11-22 20:15:17 +00:00
parent
8d81d8df50
commit
b72344c6e4
4 changed files with 39 additions and 12 deletions
|
@ -72,6 +72,7 @@ static bool djui_panel_join_ip_parse_port(char** msg) {
|
||||||
|
|
||||||
static bool djui_panel_join_ip_valid(char* buffer) {
|
static bool djui_panel_join_ip_valid(char* buffer) {
|
||||||
char** msg = &buffer;
|
char** msg = &buffer;
|
||||||
|
|
||||||
if (!djui_panel_join_ip_parse_numbers(msg)) { return false; }
|
if (!djui_panel_join_ip_parse_numbers(msg)) { return false; }
|
||||||
if (!djui_panel_join_ip_parse_period(msg)) { return false; }
|
if (!djui_panel_join_ip_parse_period(msg)) { return false; }
|
||||||
if (!djui_panel_join_ip_parse_numbers(msg)) { return false; }
|
if (!djui_panel_join_ip_parse_numbers(msg)) { return false; }
|
||||||
|
@ -86,15 +87,6 @@ static bool djui_panel_join_ip_valid(char* buffer) {
|
||||||
return (**msg == '\0');
|
return (**msg == '\0');
|
||||||
}
|
}
|
||||||
|
|
||||||
static void djui_panel_join_ip_text_change(struct DjuiBase* caller) {
|
|
||||||
struct DjuiInputbox* inputbox1 = (struct DjuiInputbox*)caller;
|
|
||||||
if (djui_panel_join_ip_valid(inputbox1->buffer)) {
|
|
||||||
djui_inputbox_set_text_color(inputbox1, 0, 0, 0, 255);
|
|
||||||
} else {
|
|
||||||
djui_inputbox_set_text_color(inputbox1, 255, 0, 0, 255);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void djui_panel_join_ip_text_set_new(void) {
|
static void djui_panel_join_ip_text_set_new(void) {
|
||||||
char buffer[256] = { 0 };
|
char buffer[256] = { 0 };
|
||||||
snprintf(buffer, 256, "%s", sInputboxIp->buffer);
|
snprintf(buffer, 256, "%s", sInputboxIp->buffer);
|
||||||
|
@ -136,11 +128,11 @@ static void djui_panel_join_ip_text_set(struct DjuiInputbox* inputbox1) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void djui_panel_join_do_join(struct DjuiBase* caller) {
|
void djui_panel_join_do_join(struct DjuiBase* caller) {
|
||||||
if (!djui_panel_join_ip_valid(sInputboxIp->buffer)) {
|
if (!(strlen(sInputboxIp->buffer) > 0)) {
|
||||||
djui_interactable_set_input_focus(&sInputboxIp->base);
|
djui_interactable_set_input_focus(&sInputboxIp->base);
|
||||||
djui_inputbox_select_all(sInputboxIp);
|
djui_inputbox_select_all(sInputboxIp);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
djui_panel_join_ip_text_set_new();
|
djui_panel_join_ip_text_set_new();
|
||||||
network_set_system(NS_SOCKET);
|
network_set_system(NS_SOCKET);
|
||||||
network_init(NT_CLIENT);
|
network_init(NT_CLIENT);
|
||||||
|
@ -183,7 +175,6 @@ void djui_panel_join_create(struct DjuiBase* caller) {
|
||||||
struct DjuiInputbox* inputbox1 = djui_inputbox_create(&body->base, 256);
|
struct DjuiInputbox* inputbox1 = djui_inputbox_create(&body->base, 256);
|
||||||
djui_base_set_size_type(&inputbox1->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE);
|
djui_base_set_size_type(&inputbox1->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE);
|
||||||
djui_base_set_size(&inputbox1->base, 1.0f, 32.0f);
|
djui_base_set_size(&inputbox1->base, 1.0f, 32.0f);
|
||||||
djui_interactable_hook_value_change(&inputbox1->base, djui_panel_join_ip_text_change);
|
|
||||||
sInputboxIp = inputbox1;
|
sInputboxIp = inputbox1;
|
||||||
djui_panel_join_ip_text_set(inputbox1);
|
djui_panel_join_ip_text_set(inputbox1);
|
||||||
|
|
||||||
|
|
34
src/pc/network/socket/domain_res.c
Normal file
34
src/pc/network/socket/domain_res.c
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "socket.h"
|
||||||
|
#include "pc/configfile.h"
|
||||||
|
#include "pc/debuglog.h"
|
||||||
|
#include "pc/djui/djui.h"
|
||||||
|
#ifdef WINSOCK
|
||||||
|
#include <winsock2.h>
|
||||||
|
#include <ws2tcpip.h>
|
||||||
|
#else
|
||||||
|
#include <netdb.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
void domain_resolution(void) {
|
||||||
|
struct in_addr addr;
|
||||||
|
char *host_name;
|
||||||
|
struct hostent *remoteHost;
|
||||||
|
char* domainname = "";
|
||||||
|
host_name = configJoinIp;
|
||||||
|
if (host_name == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int i = 0;
|
||||||
|
remoteHost = gethostbyname(host_name);
|
||||||
|
i = 0;
|
||||||
|
if (remoteHost->h_addrtype == AF_INET) {
|
||||||
|
|
||||||
|
while (remoteHost->h_addr_list[i] != 0) {
|
||||||
|
addr.s_addr = *(u_long *) remoteHost->h_addr_list[i++];
|
||||||
|
domainname = inet_ntoa(addr);
|
||||||
|
snprintf(configJoinIp, MAX_CONFIG_STRING, "%s", domainname);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -78,6 +78,7 @@ static bool ns_socket_initialize(enum NetworkType networkType) {
|
||||||
// save the port to send to
|
// save the port to send to
|
||||||
addr[0].sin_family = AF_INET;
|
addr[0].sin_family = AF_INET;
|
||||||
addr[0].sin_port = htons(port);
|
addr[0].sin_port = htons(port);
|
||||||
|
domain_resolution();
|
||||||
addr[0].sin_addr.s_addr = inet_addr(configJoinIp);
|
addr[0].sin_addr.s_addr = inet_addr(configJoinIp);
|
||||||
LOG_INFO("connecting to %s %u", configJoinIp, port);
|
LOG_INFO("connecting to %s %u", configJoinIp, port);
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,5 +13,6 @@ extern struct NetworkSystem gNetworkSystemSocket;
|
||||||
|
|
||||||
SOCKET socket_initialize(void);
|
SOCKET socket_initialize(void);
|
||||||
void socket_shutdown(SOCKET socket);
|
void socket_shutdown(SOCKET socket);
|
||||||
|
void domain_resolution(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue