📄 d_net.c
字号:
case PT_CLIENT2CMD: case PT_CLIENTMIS: case PT_CLIENT2MIS: case PT_NODEKEEPALIVE: case PT_NODEKEEPALIVEMIS: fprintf(debugfile ," tic %4d resendfrom %d localtic %d\n" ,ExpandTics (netbuffer->u.clientpak.client_tic) ,ExpandTics (netbuffer->u.clientpak.resendfrom) ,0 /*netbuffer->u.clientpak.cmd.localtic*/); break; case PT_TEXTCMD: case PT_TEXTCMD2: fprintf(debugfile ," length %d\n " ,*(unsigned char*)netbuffer->u.textcmd); fprintfstring(netbuffer->u.textcmd+1,netbuffer->u.textcmd[0]); break; case PT_SERVERCFG: fprintf(debugfile ," playermask %x players %d clientnode %d serverplayer %d gametic %li gamestate %d\n" ,(unsigned int)netbuffer->u.servercfg.playerdetected ,netbuffer->u.servercfg.totalplayernum ,netbuffer->u.servercfg.clientnode ,netbuffer->u.servercfg.serverplayer ,netbuffer->u.servercfg.gametic ,netbuffer->u.servercfg.gamestate); break; case PT_SERVERINFO : fprintf(debugfile ," '%s' player %i/%i, map %s, filenum %d, time %u \n" ,netbuffer->u.serverinfo.servername ,netbuffer->u.serverinfo.numberofplayer ,netbuffer->u.serverinfo.maxplayer ,netbuffer->u.serverinfo.mapname ,netbuffer->u.serverinfo.fileneedednum ,(unsigned int)netbuffer->u.serverinfo.time); fprintfstring(netbuffer->u.serverinfo.fileneeded,(char *)netbuffer+doomcom->datalength-(char *)netbuffer->u.serverinfo.fileneeded); break; case PT_SERVERREFUSE : fprintf(debugfile ," reason %s\n" ,netbuffer->u.serverrefuse.reason); break; case PT_FILEFRAGMENT : fprintf(debugfile ," fileid %d datasize %d position %li\n" ,netbuffer->u.filetxpak.fileid ,netbuffer->u.filetxpak.size ,netbuffer->u.filetxpak.position); break; case PT_REQUESTFILE : default : // write as a raw packet fprintfstring(netbuffer->u.textcmd,(char *)netbuffer+doomcom->datalength-(char *)netbuffer->u.textcmd); break; }}#endif//// HSendPacket//extern boolean HSendPacket(int node,boolean reliable ,byte acknum,int packetlength){ doomcom->datalength = packetlength+BASEPACKETSIZE; if (!node) { if((rebound_head+1)%MAXREBOUND==rebound_tail) {#ifdef PARANOIA CONS_Printf("No more rebound buf\n");#endif return false; } memcpy(&reboundstore[rebound_head],netbuffer,doomcom->datalength); reboundsize[rebound_head]=doomcom->datalength; rebound_head=(rebound_head+1)%MAXREBOUND;#ifdef DEBUGFILE if (debugfile) { doomcom->remotenode = node; DebugPrintpacket("SENDLOCAL"); }#endif return true; }// if (demoplayback)// return true; if (!netgame) I_Error ("Tried to transmit to another node"); // do this before GetFreeAcknum because this function // backup the current paket doomcom->remotenode = 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()<RAND_MAX/5 ) {#ifdef DEBUGFILE if (debugfile) DebugPrintpacket("SEND");#endif I_NetSend(); }#ifdef DEBUGFILE else if (debugfile) DebugPrintpacket("NOTSEND");#endif return true;}//// HGetPacket// Returns false if no packet is waiting// Check Datalength and checksum//extern boolean HGetPacket (void){ // get a packet from my if (rebound_tail!=rebound_head) { 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; 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)); return false; } nodes[doomcom->remotenode].lasttimepacketreceived = I_GetTime(); if (netbuffer->checksum != NetbufferChecksum ()) { DEBFILE("Bad packet checksum\n"); return false; }#ifdef DEBUGFILE if (debugfile) DebugPrintpacket("GET");#endif // proceed the ack and ackreturn field if(!Processackpak()) return false; // discated (duplicated) // a packet with just ackreturn if( netbuffer->packettype == PT_NOTHING) { GotAcks(); return false; } return true;}void Internal_Get(void){ doomcom->remotenode = -1; // I_Error("Get without netgame\n");}void Internal_Send(void){ I_Error("Send without netgame\n");}void Internal_FreeNodenum(int nodenum){}//// D_CheckNetGame// Works out player numbers among the net participants//extern boolean D_CheckNetGame (void){ boolean ret=false; InitAck(); rebound_tail=0; rebound_head=0; statstarttic=I_GetTime(); I_NetGet = Internal_Get; I_NetSend = Internal_Send; I_NetCanSend = NULL; I_NetCloseSocket = NULL; I_NetFreeNodenum = Internal_FreeNodenum; I_NetMakeNode = NULL; hardware_MAXPACKETLENGTH = MAXPACKETLENGTH; net_bandwidth = 3000; // I_InitNetwork sets doomcom and netgame // check and initialize the network driver multiplayer = false; // only dos version with external driver will return true netgame = I_InitNetwork (); if( !netgame ) { doomcom=Z_Malloc(sizeof(doomcom_t),PU_STATIC,NULL); memset(doomcom,0,sizeof(doomcom_t)); doomcom->id = DOOMCOM_ID; doomcom->numplayers = doomcom->numnodes = 1; doomcom->deathmatch = false; doomcom->consoleplayer = 0; doomcom->extratics = 0; netgame = I_InitTcpNetwork(); } if( netgame ) ret = true; if( !server && netgame ) netgame = false; server = true; doomcom->ticdup = 1; if (M_CheckParm ("-extratic")) { if( M_IsNextParm() ) doomcom->extratics = atoi(M_GetNextParm()); else doomcom->extratics = 1; CONS_Printf("Set extratic to %d\n",doomcom->extratics); } if(M_CheckParm ("-bandwidth")) { if(M_IsNextParm()) { net_bandwidth = atoi(M_GetNextParm()); if( net_bandwidth<1000 ) net_bandwidth=1000; if( net_bandwidth>100000 ) hardware_MAXPACKETLENGTH = MAXPACKETLENGTH; CONS_Printf("Network bandwidth set to %d\n",net_bandwidth); } else I_Error("usage : -bandwidth <byte_per_sec>"); } software_MAXPACKETLENGTH=hardware_MAXPACKETLENGTH; if(M_CheckParm ("-packetsize")) { int p=atoi(M_GetNextParm()); if(p<75) p=75; if(p>hardware_MAXPACKETLENGTH) p=hardware_MAXPACKETLENGTH; software_MAXPACKETLENGTH=p; } if( netgame ) multiplayer = true; if (doomcom->id != DOOMCOM_ID) I_Error ("Doomcom buffer invalid!"); if (doomcom->numnodes>MAXNETNODES) I_Error ("To many nodes (%d), max:%d",doomcom->numnodes,MAXNETNODES); netbuffer = (doomdata_t *)&doomcom->data;#ifdef DEBUGFILE if (M_CheckParm ("-debugfile")) { char filename[20]; int k=doomcom->consoleplayer-1; if( M_IsNextParm() ) k = atoi(M_GetNextParm())-1; while (!debugfile && k<MAXPLAYERS) { k++; sprintf (filename,"debug%i.txt",k); debugfile = fopen (filename,"w"); } if( debugfile ) CONS_Printf ("debug output to: %s\n",filename); else CONS_Printf ("\2cannot debug output to file !\n",filename); }#endif D_ClientServerInit(); return ret;}extern void D_CloseConnection( void ){ int i; if( netgame ) { // wait the ackreturn with timout of 5 Sec Net_WaitAllAckReceived(5); // close all connection for( i=0;i<MAXNETNODES;i++ ) Net_CloseConnection(i | FORCECLOSE); InitAck(); if( I_NetCloseSocket ) I_NetCloseSocket(); I_NetGet = Internal_Get; I_NetSend = Internal_Send; I_NetCanSend = NULL; I_NetCloseSocket = NULL; I_NetFreeNodenum = Internal_FreeNodenum; I_NetMakeNode = NULL; netgame = false; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -