Skip to content

Commit

Permalink
Reapply netcode changes
Browse files Browse the repository at this point in the history
  • Loading branch information
geneotech committed Apr 8, 2024
1 parent 1898344 commit 4c1b01c
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 30 deletions.
70 changes: 40 additions & 30 deletions netcode/netcode.c
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,24 @@ void netcode_socket_destroy( struct netcode_socket_t * socket )
}
}

int netcode_socket_set_ttl( struct netcode_socket_t * s, int ttl )
{
return setsockopt(s->handle, IPPROTO_IP, IP_TTL, (const char*)(&ttl), sizeof(ttl));
}

int netcode_socket_get_ttl(struct netcode_socket_t * s)
{
int ttl;
socklen_t len = sizeof(ttl);
int result = getsockopt(s->handle, IPPROTO_IP, IP_TTL, (char*)(&ttl), &len);

(void)result;

netcode_assert(0 == result);

return ttl;
}

int netcode_socket_create( struct netcode_socket_t * s, struct netcode_address_t * address, int send_buffer_size, int receive_buffer_size )
{
netcode_assert( s );
Expand Down Expand Up @@ -3057,6 +3075,16 @@ void netcode_client_receive_packets( struct netcode_client_t * client )
if ( packet_bytes == 0 )
break;

if ( client->config.auxiliary_command_function != NULL ) {
if ( client->config.auxiliary_command_function(
client->config.auxiliary_command_context,
packet_data,
packet_bytes ))
{
continue;
}
}

uint64_t sequence;
void * packet = netcode_read_packet( packet_data,
packet_bytes,
Expand Down Expand Up @@ -4087,21 +4115,7 @@ void netcode_server_disconnect_client_internal( struct netcode_server_t * server
server->config.connect_disconnect_callback( server->config.callback_context, client_index, 0 );
}

if ( send_disconnect_packets )
{
netcode_printf( NETCODE_LOG_LEVEL_DEBUG, "server sent disconnect packets to client %d\n", client_index );

int i;
for ( i = 0; i < NETCODE_NUM_DISCONNECT_PACKETS; ++i )
{
netcode_printf( NETCODE_LOG_LEVEL_DEBUG, "server sent disconnect packet %d\n", i );

struct netcode_connection_disconnect_packet_t packet;
packet.packet_type = NETCODE_CONNECTION_DISCONNECT_PACKET;

netcode_server_send_client_packet( server, &packet, client_index );
}
}
(void)send_disconnect_packets;

while ( 1 )
{
Expand Down Expand Up @@ -4242,21 +4256,6 @@ void netcode_server_process_connection_request_packet( struct netcode_server_t *
return;
}

int found_server_address = 0;
int i;
for ( i = 0; i < connect_token_private.num_server_addresses; ++i )
{
if ( netcode_address_equal( &server->address, &connect_token_private.server_addresses[i] ) )
{
found_server_address = 1;
}
}
if ( !found_server_address )
{
netcode_printf( NETCODE_LOG_LEVEL_DEBUG, "server ignored connection request. server address not in connect token whitelist\n" );
return;
}

if ( netcode_server_find_client_index_by_address( server, from ) != -1 )
{
netcode_printf( NETCODE_LOG_LEVEL_DEBUG, "server ignored connection request. a client with this address is already connected\n" );
Expand Down Expand Up @@ -4616,6 +4615,17 @@ void netcode_server_read_and_process_packet( struct netcode_server_t * server,
if ( packet_bytes <= 1 )
return;

if ( server->config.auxiliary_command_function != NULL ) {
if (server->config.auxiliary_command_function(
server->config.auxiliary_command_context,
from,
packet_data,
packet_bytes
)) {
return;
}
}

uint64_t sequence;

int encryption_index = -1;
Expand Down
6 changes: 6 additions & 0 deletions netcode/netcode.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ struct netcode_client_config_t
int override_send_and_receive;
void (*send_packet_override)(void*,struct netcode_address_t*,NETCODE_CONST uint8_t*,int);
int (*receive_packet_override)(void*,struct netcode_address_t*,uint8_t*,int);

bool (*auxiliary_command_function)(void*,uint8_t*,int);
void * auxiliary_command_context;
};

void netcode_default_client_config( struct netcode_client_config_t * config );
Expand Down Expand Up @@ -204,6 +207,9 @@ struct netcode_server_config_t
int override_send_and_receive;
void (*send_packet_override)(void*,struct netcode_address_t*,NETCODE_CONST uint8_t*,int);
int (*receive_packet_override)(void*,struct netcode_address_t*,uint8_t*,int);

bool (*auxiliary_command_function)(void*,struct netcode_address_t*,uint8_t*,int);
void * auxiliary_command_context;
};

void netcode_default_server_config( struct netcode_server_config_t * config );
Expand Down

0 comments on commit 4c1b01c

Please sign in to comment.