Beispiel #1
0
void NET_SendFrags(player_t *player)
{
	int i;
	int frags;

	netbuffer->checksum = NetbufferChecksum();

	if (demoplayback)
	{
		return;
	}
	if (!netgame)
	{
		I_Error ("Tried to transmit to another node");
	}

	frags = 0;
	for(i = 0; i < MAXPLAYERS; i++)
	{
		frags += player->frags[i];
	}
	doomcom->command = CMD_FRAG;
	doomcom->remotenode = frags;
	doomcom->datalength = NetbufferSize ();

	I_NetCmd ();
}
Beispiel #2
0
boolean HGetPacket (void)
{       
	if (reboundpacket)
	{
		*netbuffer = reboundstore;
		doomcom->remotenode = 0;
		reboundpacket = false;
		return true;
	}

	if (!netgame)
		return false;
	if (demoplayback)
		return false;
		
	doomcom->command = CMD_GET;
	I_NetCmd ();
	if (doomcom->remotenode == -1)
		return false;

	if (doomcom->datalength != NetbufferSize ())
	{
		if (debugfile)
			fprintf (debugfile,"bad packet length %i\n",doomcom->datalength);
		return false;
	}
	
	if (NetbufferChecksum () != (netbuffer->checksum&NCMD_CHECKSUM) )
	{
		if (debugfile)
			fprintf (debugfile,"bad packet checksum\n");
		return false;
	}

if (debugfile)
{
	int             realretrans;
			int     i;
			
	if (netbuffer->checksum & NCMD_SETUP)
		fprintf (debugfile,"setup packet\n");
	else
	{
		if (netbuffer->checksum & NCMD_RETRANSMIT)
			realretrans = ExpandTics (netbuffer->retransmitfrom);
		else
			realretrans = -1;
		fprintf (debugfile,"get %i = (%i + %i, R %i)[%i] ",doomcom->remotenode,
		ExpandTics(netbuffer->starttic),netbuffer->numtics, realretrans, doomcom->datalength);
		for (i=0 ; i<doomcom->datalength ; i++)
			fprintf (debugfile,"%i ",((byte *)netbuffer)[i]);
		fprintf (debugfile,"\n");
	}
}
	return true;    
}
Beispiel #3
0
//
// HSendPacket
//
void
HSendPacket
 (int	node,
  int	flags )
{
    netbuffer->checksum = NetbufferChecksum () | flags;

    if (!node)
    {
	reboundstore = *netbuffer;
	reboundpacket = true;
	return;
    }

    if (demoplayback)
	return;

    if (!netgame)
	I_Error ("Tried to transmit to another node");
		
    doomcom->command = CMD_SEND;
    doomcom->remotenode = node;
    doomcom->datalength = NetbufferSize ();

#if 0	// AJH HACK
    if (debugfile)
    {
	int		i;
	int		realretrans;
	if (netbuffer->checksum & NCMD_RETRANSMIT)
	    realretrans = ExpandTics (netbuffer->retransmitfrom);
	else
	    realretrans = -1;

	I_DBGprintf("send (%i + %i, R %i) [%i] ",
		 ExpandTics(netbuffer->starttic),
		 netbuffer->numtics, realretrans, doomcom->datalength);
	
	for (i=0 ; i<doomcom->datalength ; i++)
		I_DBGprintf("%i ",((byte *)netbuffer)[i]);

	I_DBGprintf("\n");
    }
#endif

    I_NetCmd ();
}
Beispiel #4
0
//
// HGetPacket
// Returns false if no packet is waiting
// Check Datalength and checksum
//
boolean HGetPacket(void)
{
	// get a packet from self
	if (rebound_tail != rebound_head)
	{
		M_Memcpy(netbuffer, &reboundstore[rebound_tail], reboundsize[rebound_tail]);
		doomcom->datalength = reboundsize[rebound_tail];
		if (netbuffer->packettype == PT_NODETIMEOUT)
			doomcom->remotenode = netbuffer->u.textcmd[0];
		else
			doomcom->remotenode = 0;

		rebound_tail = (rebound_tail+1) % MAXREBOUND;
#ifdef DEBUGFILE
		if (debugfile)
			DebugPrintpacket("GETLOCAL");
#endif
		return true;
	}

	if (!netgame)
		return false;

#ifndef NONET

	while(true)
	{
		I_NetGet();

		if (doomcom->remotenode == -1)
			return false;

		getbytes += packetheaderlength + doomcom->datalength; // for stat

		if (doomcom->remotenode >= MAXNETNODES)
		{
			DEBFILE(va("receive packet from node %d !\n", doomcom->remotenode));
			continue;
		}

		nodes[doomcom->remotenode].lasttimepacketreceived = I_GetTime();

		if (netbuffer->checksum != NetbufferChecksum())
		{
			DEBFILE("Bad packet checksum\n");
			Net_CloseConnection(doomcom->remotenode);
			continue;
		}

#ifdef DEBUGFILE
		if (debugfile)
			DebugPrintpacket("GET");
#endif

		// proceed the ack and ackreturn field
		if (!Processackpak())
			continue; // discarded (duplicated)

		// a packet with just ackreturn
		if (netbuffer->packettype == PT_NOTHING)
		{
			GotAcks();
			continue;
		}
		break;
	}
#endif // ndef NONET

	return true;
}
Beispiel #5
0
//
// HSendPacket
//
boolean HSendPacket(INT32 node, boolean reliable, UINT8 acknum, size_t packetlength)
{
	doomcom->datalength = (INT16)(packetlength + BASEPACKETSIZE);
	if (node == 0) // packet is to go back to us
	{
		if ((rebound_head+1) % MAXREBOUND == rebound_tail)
		{
#ifdef PARANOIA
			CONS_Debug(DBG_NETPLAY, "No more rebound buf\n");
#endif
			return false;
		}
		M_Memcpy(&reboundstore[rebound_head], netbuffer,
			doomcom->datalength);
		reboundsize[rebound_head] = doomcom->datalength;
		rebound_head = (rebound_head+1) % MAXREBOUND;
#ifdef DEBUGFILE
		if (debugfile)
		{
			doomcom->remotenode = (INT16)node;
			DebugPrintpacket("SENDLOCAL");
		}
#endif
		return true;
	}

	if (!netgame)
		I_Error("Tried to transmit to another node");

#ifdef NONET
	(void)node;
	(void)reliable;
	(void)acknum;
#else
	// do this before GetFreeAcknum because this function backup
	// the current packet
	doomcom->remotenode = (INT16)node;
	if (doomcom->datalength <= 0)
	{
		DEBFILE("HSendPacket: nothing to send\n");
#ifdef DEBUGFILE
		if (debugfile)
			DebugPrintpacket("TRISEND");
#endif
		return false;
	}

	if (node < MAXNETNODES) // can be a broadcast
		netbuffer->ackreturn = GetAcktosend(node);
	else
		netbuffer->ackreturn = 0;
	if (reliable)
	{
		if (I_NetCanSend && !I_NetCanSend())
		{
			if (netbuffer->packettype < PT_CANFAIL)
				GetFreeAcknum(&netbuffer->ack, true);

			DEBFILE("HSendPacket: Out of bandwidth\n");
			return false;
		}
		else if (!GetFreeAcknum(&netbuffer->ack, false))
			return false;
	}
	else
		netbuffer->ack = acknum;

	netbuffer->checksum = NetbufferChecksum();
	sendbytes += packetheaderlength + doomcom->datalength; // for stat

	// simulate internet :)
	if (true || rand()<(INT32)RAND_MAX/5)
	{
#ifdef DEBUGFILE
		if (debugfile)
			DebugPrintpacket("SEND");
#endif
		I_NetSend();
	}
#ifdef DEBUGFILE
	else if (debugfile)
		DebugPrintpacket("NOTSEND");
#endif

#endif // ndef NONET

	return true;
}
Beispiel #6
0
void udp_receive(int s) {
  size_t len = 1024;
  packet_header_t *p = malloc(len);
  int rc;
  
  rc = read(s,p,len);
  if (rc < 0) {
    fprintf(stderr,"read(udp): %s\n", strerror(errno));
    exit(-2);
  }
  if (rc > 0) {
    switch (p->type) {
	    case PKT_SETUP:
		    {
			    struct setup_packet_s *sinfo = (void*)(p+1);
			    consoleplayer = sinfo->yourplayer;
			    send_udp_packet(PKT_GO,0,NULL,0);
			    write(ipxs,"\xff\xff\xff\xff\x00\x00\x00\x00\x02\x00\x02\x00\x00\x00\x00\x00",16);
		    }
		    break;
	    case PKT_GO:
		    {
			    ipxpacket_t pkt;
			    memset(&pkt,0,sizeof(pkt));
			    pkt.tic = ipxcounter++;
			    pkt.u.d.player = consoleplayer^1;
			    pkt.u.d.starttic = 0;
			    pkt.u.d.numtics = 0;
			    pkt.u.d.retransmitfrom = 0;
			    pkt.u.d.checksum = NetbufferChecksum(&pkt.u.d.retransmitfrom, 4);
			    write(ipxs,&pkt,16);
		    }
		    break;
	    case PKT_TICS:
		    {
			    ipxpacket_t pkt;
			    int tic = doom_ntohl(p->tic);
			    byte *pp = (void*)(p+1);
			    int tics = *pp++;
			    memset(&pkt,0,sizeof(pkt));
			    size_t len;

			    pkt.tic = ipxcounter++;
			    pkt.u.d.starttic = tic;
			    pkt.u.d.player = (consoleplayer == 0 ? 1 : 0);
			    pkt.u.d.numtics = tics;

			    for (int t=0; t<tics; t++) {
			      int players = *pp++;
			      for (int i=0; i<players; i++) {
				if (*pp++ == pkt.u.d.player)
				  RawToTic(&pkt.u.d.cmds[t],pp);
				pp += sizeof(ticcmd_t);
			      }
			    }
			    pkt.u.d.retransmitfrom = 0;
			    len = 12+tics*sizeof(ticcmd_t);
			    len = (len+7)&0xff8; // round up to next 16
			    pkt.u.d.checksum = NetbufferChecksum(&pkt.u.d.retransmitfrom, len-8);
			    write(ipxs,&pkt,len);
		    }
    }
  }
}