⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 multi.c

📁 小型游戏引擎
💻 C
📖 第 1 页 / 共 3 页
字号:
}void netoff(){	if (my7a) *(long *)(0x7a<<2) = 0L;	simulateint(0x7a,0L,(long)0x1,0L,(long)socket,0L,0L);               //Closesocket}void comoff(){	long i;	i = 1048576;	while ((*outbufplc != *outbufend) && (i >= 0))	{		startcom();		i--;	}#ifdef PLATFORM_DOS		_disable();#endif		koutp(0x21,kinp(0x21)|(1<<(comvect&7)));          //Mask vector	if (hangup != 0)	{		koutp((*comport)+1,0);		koutp((*comport)+4,0);	}#ifdef PLATFORM_DOS		_enable();#endif		uninstallbicomhandlers();}void netsend (short otherconnectindex, short messleng){	long i;	i = 32767;	while ((ecbput[8] != 0) && (i > 0)) i--;	for(i=0;i<30;i++) ipxout[i] = 0;	for(i=0;i<48;i++) ecbput[i] = 0;	ipxout[5] = 4;	if (otherconnectindex < 0)	{		memcpy((void *)&ipxout[6],(void *)&compaddr[0][0],4);		ipxout[10] = 0xff, ipxout[11] = 0xff, ipxout[12] = 0xff;		ipxout[13] = 0xff, ipxout[14] = 0xff, ipxout[15] = 0xff;		ipxout[16] = (socket&255), ipxout[17] = (socket>>8);	}	else	{		memcpy((void *)&ipxout[6],(void *)&compaddr[otherconnectindex][0],12);	}	ecbput[10] = (socket&255), ecbput[11] = (socket>>8);	if (otherconnectindex < 0)	{		ecbput[28] = 0xff, ecbput[29] = 0xff, ecbput[30] = 0xff;		ecbput[31] = 0xff, ecbput[32] = 0xff, ecbput[33] = 0xff;	}	else	{		memcpy((void *)&ecbput[28],(void *)&compaddr[otherconnectindex][4],6);	}	ecbput[34] = 2, ecbput[35] = 0;	ecbput[36] = (char)(((long)ipxout-rmoffset32)&255), ecbput[37] = (char)(((long)ipxout-rmoffset32)>>8);	ecbput[38] = (char)(rmsegment16&255), ecbput[39] = (char)(rmsegment16>>8);	ecbput[40] = 30, ecbput[41] = 0;	ecbput[42] = (char)(((long)messout-rmoffset32)&255), ecbput[43] = (char)(((long)messout-rmoffset32)>>8);	ecbput[44] = (char)(rmsegment16&255), ecbput[45] = (char)(rmsegment16>>8);	ecbput[46] = (char)(messleng&255), ecbput[47] = (char)(messleng>>8);	simulateint(0x7a,0L,(long)0x3,0L,0L,(long)ecbput,0L);               //Sendpacket}void comsend(char ch){	if (ch == ESC1)	{		outbuf[*outbufend] = ESC1; *outbufend = (((*outbufend)+1)&(COMBUFSIZ-1));		ch = 128;	}	else if (ch == ESC2)	{		outbuf[*outbufend] = ESC1; *outbufend = (((*outbufend)+1)&(COMBUFSIZ-1));		ch = 129;	}	outbuf[*outbufend] = ch; *outbufend = (((*outbufend)+1)&(COMBUFSIZ-1));}void startcom(){	if ((kinp((*comport)+5)&0x40) == 0) return;	if (*comresend != 0)	{		if (*comresend == 2) koutp(*comport,ESC1);		if (*comresend == 1) koutp(*comport,ESC2);		*comresend = (*comresend) - 1;	}	else if (*comerror != 0)	{		if (*comerror == 2) koutp(*comport,ESC1);		if (*comerror == 1) koutp(*comport,*incnt);		*comerror = (*comerror) - 1;	}	else if (*outbufplc != *outbufend)	{		koutp(*comport,(long)outbuf[*outbufplc]);		*outbufplc = (((*outbufplc)+1)&(COMBUFSIZ-1));	}}void interrupt far comhandler(void){	do	{		comtemp = (kinp((*comport)+2)&7);		if (comtemp == 2)		{			for(comi=(*comtype);comi>0;comi--)			{				if (*comresend != 0)				{					if (*comresend == 2) koutp(*comport,ESC1);					if (*comresend == 1) koutp(*comport,ESC2);					*comresend = (*comresend) - 1;					continue;				}				if (*comerror != 0)				{					if (*comerror == 2) koutp(*comport,ESC1);					if (*comerror == 1) koutp(*comport,*incnt);					*comerror = (*comerror) - 1;					continue;				}				if (*outbufplc != *outbufend)				{					koutp(*comport,(long)outbuf[*outbufplc]);					*outbufplc = (((*outbufplc)+1)&(COMBUFSIZ-1));					continue;				}				break;			}		}		else if (comtemp == 4)		{			do			{				//comtemp = (rand()&255);				//if (comtemp == 17)				//   inbuf[*inbufend] = 17;				//else					inbuf[*inbufend] = (char)kinp(*comport);				//if (comtemp != 11) *inbufend = (((*inbufend)+1)&(COMBUFSIZ-1));				//if (comtemp == 24)				//{				//   inbuf[*inbufend] = 17;					*inbufend = (((*inbufend)+1)&(COMBUFSIZ-1));				//}				//comtemp = 4;			} while ((*comtype == 16) && ((kinp((*comport)+5)&1) > 0));		}	}	while ((comtemp&1) == 0);	koutp(0x20,0x20);}int netinitconnection (long newconnectnum, char *newcompaddr){	long i, j, k, newindex, templong;	char tempchar;		//Check to see if connection number already initialized	for(i=0;i<MAXPLAYERS;i++)		if (connectnum[i] == newconnectnum) return(-1);		//Find blank place to put new connection number	newindex = 0;	while (connectnum[newindex] != 0x7fffffff)	{		newindex++;		if (newindex >= MAXPLAYERS) return(-1);  //Out of space! (more than 16 players)	}		//Insert connection number on connection number list	numplayers++;	connectnum[newindex] = newconnectnum;		//Getinternetworkaddress	memcpy((void *)&compaddr[newindex][0],(void *)newcompaddr,10);	compaddr[newindex][10] = (socket&255);	compaddr[newindex][11] = (socket>>8);		//Sort connection numbers	for(i=1;i<MAXPLAYERS;i++)		for(j=0;j<i;j++)			if (connectnum[i] < connectnum[j])			{				templong = connectnum[i], connectnum[i] = connectnum[j], connectnum[j] = templong;				for(k=0;k<12;k++) tempchar = compaddr[i][k], compaddr[i][k] = compaddr[j][k], compaddr[j][k] = tempchar;			}		//Rebuild linked list, MAKING SURE that the linked list goes through		//   the players in the same order on all computers!	connecthead = 0;	for(i=0;i<numplayers-1;i++) connectpoint2[i] = i+1;	connectpoint2[numplayers-1] = -1;	for(i=0;i<numplayers;i++)		if (connectnum[i] == myconnectnum) myconnectindex = i;	return(1);}void netuninitconnection(short goneindex){	long i, j, k=0;	connectnum[goneindex] = 0x7fffffff; numplayers--;	j = 0;	for(i=0;i<MAXPLAYERS;i++)		if (connectnum[i] != 0x7fffffff)		{			if (j == 0) connecthead = i; else connectpoint2[k] = i;			k = i; j++;		}	connectpoint2[k] = -1;}void sendpacket (short otherconnectindex, unsigned char *bufptr, short messleng){	long i, j, k, l;	if (multioption <= 0) return;	if (multioption < 5)	{			//Allow initial incnt/outcnt syncing		if ((bufptr[0] == 253) || (bufptr[0] == 254)) outcnt = 0;		outbufindex[outcnt] = *outbufend;		comsend(((messleng&1)<<7)+outcnt);		for(i=0;i<messleng;i++) comsend(bufptr[i]);		if ((comrateoption&15) > 0)		{			i = getcrc(bufptr,messleng);			updatecrc16(i,(((messleng&1)<<7)+outcnt));			comsend(i&255); comsend(i>>8);		}		outbuf[*outbufend] = ESC2, *outbufend = (((*outbufend)+1)&(COMBUFSIZ-1));  //Not raw		startcom();		outcnt = ((outcnt+1)&127);	}	else	{		i = 262144;       //Wait for last packet to be sent		while ((i > 0) && (ecbput[8] != 0)) i--;		messout[0] = myconnectindex; j = 1;		if ((unsigned char) bufptr[0] >= 200)		{				//Allow initial incnt/outcnt syncing			for(i=0;i<MAXPLAYERS;i++) netoutcnt[i] = 0;			messout[j++] = 0xfe;			for(i=0;i<messleng;i++) messout[j++] = bufptr[i];			netsend(otherconnectindex,j);			return;		}			//Copy new packet into omess fifo		if (otherconnectindex < 0)		{			for(k=connecthead;k>=0;k=connectpoint2[k])				if (k != myconnectindex)				{					omessconnectindex[k][omessnum[k]] = -1;					omessleng[k][omessnum[k]] = messleng;					for(i=0;i<messleng;i++) omessout[k][omessnum[k]][i] = bufptr[i];				}		}		else		{			omessconnectindex[otherconnectindex][omessnum[otherconnectindex]] = otherconnectindex;			omessleng[otherconnectindex][omessnum[otherconnectindex]] = messleng;			for(i=0;i<messleng;i++) omessout[otherconnectindex][omessnum[otherconnectindex]][i] = bufptr[i];		}			//Put last 4 packets into 1 big packet		for(l=0;l<NETBACKPACKETS;l++)		{				//k = omess index			k = ((omessnum[otherconnectindex]-l)&(NETBACKPACKETS-1));			if (omessconnectindex[otherconnectindex][k] < 0)			{				messout[j++] = 255;				for(i=connecthead;i>=0;i=connectpoint2[i])					if (i != myconnectindex)						messout[j++] = ((netoutcnt[i]-l)&255);			}			else			{				messout[j++] = otherconnectindex;				messout[j++] = ((netoutcnt[otherconnectindex]-l)&255);			}			messout[j++] = (omessleng[otherconnectindex][k]&255);			messout[j++] = ((omessleng[otherconnectindex][k]>>8)&255);			for(i=0;i<omessleng[otherconnectindex][k];i++)				messout[j++] = omessout[otherconnectindex][k][i];		}			//SEND!!!		netsend(otherconnectindex,j);			//Increment outcnt and omessnum counters		if (otherconnectindex < 0)		{			for(i=connecthead;i>=0;i=connectpoint2[i])				if (i != myconnectindex)				{					netoutcnt[i]++;					omessnum[i] = ((omessnum[i]+1)&(NETBACKPACKETS-1));				}		}		else		{			netoutcnt[otherconnectindex]++;			omessnum[otherconnectindex] = ((omessnum[otherconnectindex]+1)&(NETBACKPACKETS-1));		}	}}short getpacket (short *otherconnectindex, char *bufptr){	char toindex, bad, totbad;	short i, j=0, k, messleng, submessleng;	if (multioption <= 0) return(0);	if (multioption < 5)	{		*otherconnectindex = (myconnectindex^1);		bad = 0;		while (*inbufplc != *inbufend)		{			i = (short)inbuf[*inbufplc], *inbufplc = (((*inbufplc)+1)&(COMBUFSIZ-1));			if (i != ESC2)			{				if (i == ESC1) { comescape++; continue; }				if (comescape != 0)				{					comescape--;					if ((i < 128) && (*comresend == 0) && (((i-outcnt)&127) > 4))					{						*comresend = 2;						*outbufplc = outbufindex[i];						startcom();						continue;					}					if (syncbufleng < MAXIPXSIZ)					{						if (i == 128) { syncbuf[syncbufleng++] = ESC1; continue; }						if (i == 129) { syncbuf[syncbufleng++] = ESC2; continue; }					}				}				if (syncbufleng < MAXIPXSIZ) syncbuf[syncbufleng++] = i;				continue;			}			if (comescape != 0)			{				comescape = 0; comreset = 0; *comerror = 0;				syncbufleng = 0;				continue;			}			messleng = syncbufleng-3+(((comrateoption&15)==0)<<1);			if ((syncbuf[0]&127) != *incnt)			{				bad |= 1;      //Packetcnt error				if ((*incnt == 1) && (syncbuf[1] == 254))  //Prevent 2 Masters!					myconnectindex = (myconnectnum<otherconnectnum);			}			if (((syncbuf[0]&128)>>7) != (messleng&1)) bad |= 2;   //messleng error

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -