Ejemplo n.º 1
0
size_t I_GetPacket(packet_header_t* buffer, size_t buflen)
{
  int checksum;
  size_t len;
  int status;

  status = SDLNet_UDP_Recv(udp_socket, udp_packet);
  len = udp_packet->len;
  if (buflen<len)
    len=buflen;
  if ( (status!=0) && (len>0) )
    memcpy(buffer, udp_packet->data, len);
  sentfrom=udp_packet->channel;
#ifndef SDL_NET_UDP_PACKET_SRC
  sentfrom_addr=udp_packet->address;
#else
  sentfrom_addr=udp_packet->src; /* cph - allow for old SDL_net library */
#endif
  checksum=buffer->checksum;
  buffer->checksum=0;
  if ( (status!=0) && (len>0)) {
    byte psum = ChecksumPacket(buffer, udp_packet->len);
/*    fprintf(stderr, "recvlen = %u, stolen = %u, csum = %u, psum = %u\n",
  udp_packet->len, len, checksum, psum); */
    if (psum == checksum) return len;
  }
  return 0;
}
void I_SendPacketTo(packet_header_t* packet, size_t len, UDP_CHANNEL *to)
{
  printf("I_SendPacketTo Packet=%p, len=%d, Dest=%p\n", packet, len, to);

  packet->checksum = ChecksumPacket(packet, len);
  memcpy(udp_packet->data, packet, udp_packet->len = len);
  SDLNet_UDP_Send(udp_socket, *to, udp_packet);
}
Ejemplo n.º 3
0
void send_udp_packet(enum packet_type_e type, unsigned tic, void* data, size_t len) {
  packet_header_t* p = calloc(sizeof(packet_header_t)+len+1,1);
  p->tic = doom_htonl(basetic = tic); p->type = type;
  if (!data) {
    data = (void*)&consoleplayer; len = 1;
  }
  memcpy(((char*)p)+sizeof(*p),data,len);
  p->checksum = ChecksumPacket(p,sizeof(packet_header_t)+len);
  write(udps,p,sizeof(packet_header_t)+len+1);
}
void I_SendPacket(packet_header_t* packet, size_t len)
{
  printf("I_SendPacket Packet=%p, len=%d\n", packet, len);

  packet->checksum = ChecksumPacket(packet, len);

  DumpPacketHeader (packet);

  memcpy(udp_packet->data, packet, udp_packet->len = len);
  SDLNet_UDP_Send(udp_socket, 0, udp_packet);

}
Ejemplo n.º 5
0
void I_SendPacketTo(packet_header_t* packet, size_t len, UDP_CHANNEL *to)
{
  packet->checksum = ChecksumPacket(packet, len);
  memcpy(udp_packet->data, packet, udp_packet->len = len);
  SDLNet_UDP_Send(udp_socket, *to, udp_packet);
}