Esempio n. 1
0
// for key translations, we must know what the other calculator is
short int recvCalc(short int mycalc) {
	short int calc = -1;

	// give the link 20 seconds to send the requested data before auto-abort
	if (LIO_RecvData(&calc,2,LINKWAIT * 2) != LINKOK) {
		// return FALSE on error
		return 0;
	} else {
		// if our calcs are the same, no translation is needed
		if (calc == mycalc) {
			linkmode = NOTRANSLATE;
		} else {
			// otherwise, make sure and translate those keys
			linkmode = TRANSLATE;
		}
	}

	// on error, we will not reach this TRUE return statement
	return 1;
}
Esempio n. 2
0
/* Communicates between the Host and the Joining Calc all of the necessary data 
   while a game is running */
void Transfer_Data(void) {
	char Control = FALSE, Other_Control;
	unsigned char a;
	
	// Must send three plrs separately
	for(a = 3; a--;) {
		if (g->Calc == Host) {
			if (LIO_SendData(&Team2->plrs[a]->Control, sizeof(char)))
				ERROR(LINK_ERROR);
			if (LIO_RecvData(&Other_Control, sizeof(char), 30))
				ERROR(LINK_ERROR);
			
			/* After a lot of trial and error, this is the only way I found that 
			will allow for one player to take the puck from another player */
			if (Other_Control < 0 && Team1->plrs[a]->Control >= 0)
				Team1->plrs[a]->Control = Other_Control;
			
			if (LIO_SendData((char*)Team1->plrs[a], sizeof(Plr)))  // Send Plr on Team1
				ERROR(LINK_ERROR);
			if (LIO_RecvData((char*)Team2->plrs[a], sizeof(Plr), 30))  // Receive Plr on Team2
				ERROR(LINK_ERROR);
		} else {
			if (LIO_RecvData(&Other_Control, sizeof(char), 30))
				ERROR(LINK_ERROR);
			if (LIO_SendData(&Team1->plrs[a]->Control, sizeof(char)))
				ERROR(LINK_ERROR);
			
			if (Other_Control < 0 && Team2->plrs[a]->Control >= 0)
				Team2->plrs[a]->Control = Other_Control;
			
			if (LIO_RecvData((char*)Team1->plrs[a], sizeof(Plr), 30))  // Receive Plr on Team1
				ERROR(LINK_ERROR);
			if (LIO_SendData((char*)Team2->plrs[a], sizeof(Plr)))  // Send Plr on Team2
				ERROR(LINK_ERROR);
		}
		
		// If the puck is controlled by the other calc, make sure g->Is_Controlled is set 
		// to the correct value and only one player has Control of the puck
		if (Control == FALSE) {
			if (Team1->plrs[a]->Control > 0) {  // Puck controlled by team 1
				g->Is_Controlled = 1;
				if (Team2->plrs[a]->Control > 0)
					Team2->plrs[a]->Control = -1;
				Control = 1;
			} else if (Team2->plrs[a]->Control > 0) {  // Puck controlled by team 2
				g->Is_Controlled = 2;
				Control = 2;
			} else g->Is_Controlled = FALSE;  // Puck is not being controlled by a player
		} else {  // Make sure two players cannot have the puck at the same time
			if (Team1->plrs[a]->Control > 0)
				Team1->plrs[a]->Control = -1;
			if (Team2->plrs[a]->Control > 0)
				Team2->plrs[a]->Control = -1;
		}
	}
	
	// Send or Receive Puck Data, depending on which team has Control of the puck
	if (g->Last_Controlled == 2 && g->Is_Controlled == 0) {
		if (g->Calc == Host && LIO_RecvData((char*)&g->Is_Controlled, 7*sizeof(short), 30))
			ERROR(LINK_ERROR);
		else if (g->Calc == Join && LIO_SendData((char*)&g->Is_Controlled, 7*sizeof(short)))
			ERROR(LINK_ERROR);
	} else if (g->Calc == Host) {
		if (g->Is_Controlled != 2) {
			if (LIO_SendData((char*)&g->Is_Controlled, 7*sizeof(short)))
				ERROR(LINK_ERROR);
		} else if (LIO_RecvData((char*)&g->Is_Controlled, 7*sizeof(short), 30))
			ERROR(LINK_ERROR);
	} else if (g->Calc == Join) {
		if (g->Is_Controlled == 2) {
			if (LIO_SendData((char*)&g->Is_Controlled, 7*sizeof(short)))
				ERROR(LINK_ERROR);
		} else if (LIO_RecvData((char*)&g->Is_Controlled, 7*sizeof(short), 30))
			ERROR(LINK_ERROR);
	}
	
	
	/*if (g->Last_Controlled == 2 && g->Is_Controlled == 0) {
		if (g->Calc == Host && LIO_RecvData((char*)&g->Is_Controlled, sizeof(short)*7, 30))
			ERROR(LINK_ERROR);
		else if (g->Calc == Join && LIO_SendData((char*)&g->Is_Controlled, sizeof(short)*7))
			ERROR(LINK_ERROR);
	} else if (g->Calc == g->Is_Controlled) {
		if (LIO_SendData((char*)&g->Is_Controlled, sizeof(short)*7))
			ERROR(LINK_ERROR);
	} else if (LIO_RecvData((char*)&g->Is_Controlled, sizeof(short)*7, 30))
		ERROR(LINK_ERROR);*/
	
	/*if (g->Calc == Host) {
		if (g->Is_Controlled != 2) {
			if ()
				ERROR(LINK_ERROR);
		} else if (LIO_RecvData((char*)&g->Is_Controlled, sizeof(short)*7, 30))
			ERROR(LINK_ERROR);
	} else if (g->Calc == Join) {
		if (g->Is_Controlled == 2) {
			if (LIO_SendData((char*)&g->Is_Controlled, sizeof(short)*7))
				ERROR(LINK_ERROR);
		} else if (LIO_RecvData((char*)&g->Is_Controlled, sizeof(short)*7, 30))
			ERROR(LINK_ERROR);
	}*/
	// Remember who had the puck last frame
	g->Last_Controlled = g->Is_Controlled;
}