mirror of
https://github.com/open-goal/jak-project.git
synced 2024-10-20 00:57:44 -04:00
eb703ee96e
Motivated by - https://github.com/open-goal/opengoal-vscode/pull/358 This addresses the following: - Fixes #2939 spam edge-case - Stop picking a different nREPL port based on the game mode by default, this causes friction for tools in the average usecase (having a REPL open for a single game, and wanting to connect to it). `goalc` spins up fine even if the port is already bound to. - For people that need/want this behaviour, adding per-game configuration to the `repl-config.json` is on my todo list. - Allows `goalc` to permit redefining symbols, including functions. This is defaulted to off via the `repl-config.json` but it allows you to for example, change the definition of a function without having to restart and rebuild the entire game. ![Screenshot 2024-06-02 124558](https://github.com/open-goal/jak-project/assets/13153231/28f81f6e-b7b8-4172-9787-f96e4ab1305b) - Updates the welcome message to include a bunch of useful metadata up-front. Cleaned up all the startup logs that appear when starting goalc, many of whom's information is now included in the welcome message. - Before: ![image](https://github.com/open-goal/jak-project/assets/13153231/814c2374-4808-408e-9ed6-67114902a1d9) - After: ![Screenshot 2024-06-01 235954](https://github.com/open-goal/jak-project/assets/13153231/f3f459fb-2cbb-46ba-a90f-318243d4b3b3)
62 lines
1.2 KiB
C++
62 lines
1.2 KiB
C++
#include "XSocketClient.h"
|
|
|
|
#include <string>
|
|
|
|
#include "common/cross_sockets/XSocket.h"
|
|
#include "common/log/log.h"
|
|
|
|
#include "fmt/core.h"
|
|
|
|
// clang-format off
|
|
#ifdef _WIN32
|
|
#define NOMINMAX
|
|
#define WIN32_LEAN_AND_MEAN
|
|
#include <Windows.h>
|
|
#include <WinSock2.h>
|
|
#include <WS2tcpip.h>
|
|
#endif
|
|
|
|
// clang-format on
|
|
|
|
XSocketClient::XSocketClient(int _tcp_port) {
|
|
tcp_port = _tcp_port;
|
|
}
|
|
|
|
XSocketClient::~XSocketClient() {
|
|
disconnect();
|
|
client_socket = -1;
|
|
}
|
|
|
|
void XSocketClient::disconnect() {
|
|
close_socket(client_socket);
|
|
client_socket = -1;
|
|
}
|
|
|
|
bool XSocketClient::connect() {
|
|
// Open Socket
|
|
client_socket = open_socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
|
if (client_socket < 0) {
|
|
// TODO - log
|
|
disconnect();
|
|
return false;
|
|
}
|
|
|
|
addr.sin_family = AF_INET;
|
|
// Convert IP address from text to binary form using inet_pton()
|
|
if (inet_pton(AF_INET, "127.0.0.1", &addr.sin_addr) <= 0) {
|
|
lg::error("inet_pton() failed");
|
|
return false;
|
|
}
|
|
addr.sin_port = htons(tcp_port);
|
|
|
|
// Connect to server
|
|
int result = connect_socket(client_socket, (sockaddr*)&addr, sizeof(addr));
|
|
if (result == -1) {
|
|
// TODO - log and close
|
|
disconnect();
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|