More fixes to UDPConnection
This commit is contained in:
parent
d35f081585
commit
96bc9caf92
1 changed files with 69 additions and 32 deletions
|
@ -506,8 +506,8 @@ void UDPC_update(UDPC_Context *ctx)
|
||||||
UDPC_INTERNAL_atostr(ctx, receivedData.sin_addr.s_addr),
|
UDPC_INTERNAL_atostr(ctx, receivedData.sin_addr.s_addr),
|
||||||
ntohs(receivedData.sin_port));
|
ntohs(receivedData.sin_port));
|
||||||
UDPC_INTERNAL_ConnectionData newCD = {
|
UDPC_INTERNAL_ConnectionData newCD = {
|
||||||
1,
|
0x9,
|
||||||
(ctx->flags & 0x2) != 0 ? conID : UDPC_INTERNAL_generate_id(ctx),
|
UDPC_INTERNAL_generate_id(ctx),
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
0xFFFFFFFF,
|
0xFFFFFFFF,
|
||||||
|
@ -777,6 +777,8 @@ void UDPC_INTERNAL_update_send(void *userData, uint32_t addr, char *data)
|
||||||
cd->flags = cd->flags & 0xFFFFFFFE;
|
cd->flags = cd->flags & 0xFFFFFFFE;
|
||||||
|
|
||||||
if((cd->flags & 0x8) != 0)
|
if((cd->flags & 0x8) != 0)
|
||||||
|
{
|
||||||
|
if((us->ctx->flags & 0x2) != 0)
|
||||||
{
|
{
|
||||||
// initiate connection to server
|
// initiate connection to server
|
||||||
if(UDPC_INTERNAL_ts_diff(&us->tsNow, &cd->sent) < UDPC_INIT_PKT_INTERVAL_F)
|
if(UDPC_INTERNAL_ts_diff(&us->tsNow, &cd->sent) < UDPC_INIT_PKT_INTERVAL_F)
|
||||||
|
@ -812,6 +814,41 @@ void UDPC_INTERNAL_update_send(void *userData, uint32_t addr, char *data)
|
||||||
free(data);
|
free(data);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// initiate connection to client
|
||||||
|
cd->flags &= 0xFFFFFFF7;
|
||||||
|
cd->sent = us->tsNow;
|
||||||
|
|
||||||
|
char *data = malloc(20);
|
||||||
|
UDPC_INTERNAL_prepare_pkt(
|
||||||
|
data,
|
||||||
|
UDPC_ID_CONNECT | cd->id,
|
||||||
|
cd->rseq,
|
||||||
|
cd->ack,
|
||||||
|
&cd->lseq,
|
||||||
|
0);
|
||||||
|
|
||||||
|
struct sockaddr_in destinationInfo;
|
||||||
|
destinationInfo.sin_family = AF_INET;
|
||||||
|
destinationInfo.sin_addr.s_addr = addr;
|
||||||
|
destinationInfo.sin_port = htons(cd->port);
|
||||||
|
long int sentBytes = sendto(
|
||||||
|
us->ctx->socketHandle,
|
||||||
|
data,
|
||||||
|
20,
|
||||||
|
0,
|
||||||
|
(struct sockaddr*) &destinationInfo,
|
||||||
|
sizeof(struct sockaddr_in));
|
||||||
|
if(sentBytes != 20)
|
||||||
|
{
|
||||||
|
UDPC_INTERNAL_log(us->ctx, 0, "Failed to send init packet to %s "
|
||||||
|
"port %d", UDPC_INTERNAL_atostr(us->ctx, addr), cd->port);
|
||||||
|
free(data);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue