Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
deus369 committed Nov 18, 2024
1 parent bc740f9 commit 8b97a42
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/core/networking/networking.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void spawn_prefabs_networking(ecs_world_t *world) {
void initialize_networking() {
#ifdef zox_testing_networking
if (server_mode) spawn_net_room(world, SERVER_PORT);
else spawn_net_player(world, PORT, IP_TO, SERVER_PORT);
else spawn_net_player(world, PORT, server_ip, SERVER_PORT);
if (server_mode) zox_log(" > network server mode activated\n")
else zox_log(" > network client mode activated\n")
#endif
Expand Down
3 changes: 2 additions & 1 deletion src/core/networking/settings/settings.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// atm using 127.0.0.1 for same machine testing
// later for secure packets, keep sending with udp every x seconds
#define IP_TO (byte4) { 127, 0, 0, 1 } // "192.0.2.1"
#define server_ip (byte4) { 194, 195, 251, 84 } // "192.0.2.1"
#define local_server_ip (byte4) { 127, 0, 0, 1 } // "192.0.2.1"
#define PORT 12345
#define SERVER_PORT 12346
#define BUFFER_SIZE 128 // 1024 // the size of the buffer to use for receiving and sending data
Expand Down
10 changes: 5 additions & 5 deletions src/core/networking/systems/packet_recieve_system.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ void PacketRecieveSystem(ecs_iter_t *it) {
unsigned char return_packet_size = 1;
unsigned char send_buffer[1] = { zoxel_packet_type_connect_confirm }; // return packet
int send_size = sendto(socketLink->value, (const char *) send_buffer, return_packet_size, 0, (struct sockaddr*) &recv_addr, sizeof(recv_addr));
if (send_size == SOCKET_ERROR) {
if (send_size == socket_error_code) {
check_socket_error("recieve_system");
} else {
zoxel_log(" - sent return packet type [%i].\n", send_buffer[0]);
Expand All @@ -28,9 +28,9 @@ void PacketRecieveSystem(ecs_iter_t *it) {
} else if (packet_type == zoxel_packet_type_msg_confirm) {
zoxel_log(" - message has reached the server.\n");
} else if (packet_type == zoxel_packet_type_msg) {
unsigned char recv_buffer_2[2];
int text_size2 = recvfrom(socketLink->value, (char *) recv_buffer_2, 2, MSG_PEEK, (struct sockaddr*) &recv_addr, &recv_addr_len);
if (text_size2 == SOCKET_ERROR) {
unsigned char recv_buffer_2[1 + peek_packet_size];
int text_size2 = recvfrom(socketLink->value, (char *) recv_buffer_2, 1 + peek_packet_size, MSG_PEEK, (struct sockaddr*) &recv_addr, &recv_addr_len);
if (text_size2 == socket_error_code) {
check_socket_error("recieve_system2");
} else {
unsigned char text_length = recv_buffer_2[1];
Expand All @@ -39,7 +39,7 @@ void PacketRecieveSystem(ecs_iter_t *it) {
unsigned char recv_buffer_3[packet_size];
is_consume_packet = 0;
recv_size = recvfrom(socketLink->value, (char *) recv_buffer_3, packet_size, 0, (struct sockaddr*) &recv_addr, &recv_addr_len);
if (recv_size == SOCKET_ERROR) {
if (recv_size == socket_error_code) {
check_socket_error("recieve_system3");
// perror(" PacketRecieveSystem : zoxel_packet_type_msg 2 : recvfrom");
} else {
Expand Down
2 changes: 2 additions & 0 deletions src/core/networking/util/socket_util.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
unsigned char sockets_enabled = 0;
#ifndef zoxel_on_windows
#define peek_packet_size 1
#define socket_error_code -1
const unsigned long non_blocking = O_NONBLOCK;
const unsigned long f_getfl = F_GETFL;
const unsigned long f_setfl = F_SETFL;
Expand All @@ -19,6 +20,7 @@ unsigned char sockets_enabled = 0;
}
#else
#define peek_packet_size 1024
#define socket_error_code SOCKET_ERROR
#include <winsock2.h>
#include <ws2tcpip.h>
const unsigned long non_blocking = 1; // O_NONBLOCK
Expand Down

0 comments on commit 8b97a42

Please sign in to comment.