Exemplo n.º 1
0
int AdhocMatchingAccept(const char *mac)
{
	unsigned char mac2[6];
	
	sceNetEtherStrton(mac, mac2);
	
	int ret = sceNetAdhocMatchingSelectTarget(AdhocMatchingId, mac2, 0, 0);
	
	if(ret < 0)
	{
		printf("Adhoc error: sceNetAdhocMatchingSelectTarget: 0x%08X\n", ret);
		return 0;
	}
		
	return 1;
}
Exemplo n.º 2
0
int adhocSelect(void)
{
	int top = 0;
	int rows = 11;
	int currentState = PSP_LISTING;
	int prev_max = 0;
	int update = 1;
	unsigned char mac[6];
	char name[64];
	char temp[64];
	char title[32];

	sprintf(title, "AdHoc - %s", game_name);
	msg_screen_init(WP_LOGO, ICON_SYSTEM, title);

	while (1)
	{
		pad_update();

		msg_set_text_color(0xffff);

		switch (currentState)
		{
		case PSP_LISTING:
			Server = 0;
			if (update)
			{
				msg_screen_init(WP_LOGO, ICON_SYSTEM, title);
				msg_printf(TEXT(SELECT_A_SERVER_TO_CONNECT_TO));
				msg_printf("\n");
				DisplayPspList(top, rows);
				update = 0;
			}
			if (pad_pressed(PSP_CTRL_UP))
			{
				if (pos > 0) pos--;
				update = 1;
			}
			else if (pad_pressed(PSP_CTRL_DOWN))
			{
				if (pos < max - 1) pos++;
				update = 1;
			}
			else if (pad_pressed(PSP_CTRL_CIRCLE))
			{
				if (GetPspEntry(mac, name) > 0)
				{
					if (strcmp(name, g_matchingData) == 0)
					{
						currentState = PSP_SELECTING;
						sceNetAdhocMatchingSelectTarget(matchingId, mac, 0, NULL);
						update = 1;
					}
				}
			}
			else if (pad_pressed(PSP_CTRL_TRIANGLE))
			{
				msg_set_text_color(0xffffffff);
				adhocDisconnect();
				pad_wait_clear();
				return -1;
			}
			if (matchChanged)
			{
				if (g_matchEvent == MATCHING_SELECTED)
				{
					memcpy(mac, g_mac, 6);
					strcpy(name, g_matchOptData);
					currentState = PSP_SELECTED;
				}
				update = 1;
			}
			break;

		case PSP_SELECTING:
			if (update)
			{
				msg_screen_init(WP_LOGO, ICON_SYSTEM, title);
				sceNetEtherNtostr(mac, temp);
				msg_printf(TEXT(WAITING_FOR_x_TO_ACCEPT_THE_CONNECTION), temp);
				msg_printf(TEXT(TO_CANCEL_PRESS_CROSS));
				update = 0;
			}
			if (pad_pressed(PSP_CTRL_CROSS))
			{
				sceNetAdhocMatchingCancelTarget(matchingId, mac);
				currentState = PSP_LISTING;
				update = 1;
			}
			if (matchChanged)
			{
				switch (g_matchEvent)
				{
				case MATCHING_SELECTED:
					sceNetAdhocMatchingCancelTarget(matchingId, mac);
					break;

				case MATCHING_ESTABLISHED:
					currentState = PSP_ESTABLISHED;
					break;

				case MATCHING_REJECTED:
					currentState = PSP_LISTING;
					break;
				}
				update = 1;
			}
			break;

		case PSP_SELECTED:
			Server = 1;
			if (update)
			{
				msg_screen_init(WP_LOGO, ICON_SYSTEM, title);
				sceNetEtherNtostr(mac, temp);
				msg_printf(TEXT(x_HAS_REQUESTED_A_CONNECTION), temp);
				msg_printf(TEXT(TO_ACCEPT_THE_CONNECTION_PRESS_CIRCLE_TO_CANCEL_PRESS_CIRCLE));
				update = 0;
			}
			if (pad_pressed(PSP_CTRL_CROSS))
			{
				sceNetAdhocMatchingCancelTarget(matchingId, mac);
				currentState = PSP_LISTING;
				update = 1;
			}
			else if (pad_pressed(PSP_CTRL_CIRCLE))
			{
				sceNetAdhocMatchingSelectTarget(matchingId, mac, 0, NULL);
				currentState = PSP_WAIT_EST;
				update = 1;
			}
			if (matchChanged)
			{
				if (g_matchEvent == MATCHING_CANCELED)
				{
					currentState = PSP_LISTING;
				}
				update = 1;
			}
			break;

		case PSP_WAIT_EST:
			if (matchChanged)
			{
				if (g_matchEvent == MATCHING_ESTABLISHED)
				{
					currentState = PSP_ESTABLISHED;
				}
				update = 1;
			}
			break;
		}

		matchChanged = 0;
		if (currentState == PSP_ESTABLISHED)
			break;

		if (top > max - rows) top = max - rows;
		if (top < 0) top = 0;
		if (pos >= top + rows) top = pos - rows + 1;
		if (pos < top) top = pos;

		if (max != prev_max)
		{
			prev_max = max;
			update = 1;
		}

		sceDisplayWaitVblankStart();
	}

	msg_set_text_color(0xffffffff);

	if (Server) sceWlanGetEtherAddr(mac);

	sceNetEtherNtostr(mac, temp);

	g_ssid[0] = temp[ 9];
	g_ssid[1] = temp[10];
	g_ssid[2] = temp[12];
	g_ssid[3] = temp[13];
	g_ssid[4] = temp[15];
	g_ssid[5] = temp[16];
	g_ssid[6] = '\0';

	return adhocStartP2P();
}
Exemplo n.º 3
0
////////////////////////////////////////////////////////////////////////////////////
// This is just a quick and easy procedure to wait for a PSP to join, the following
// is what is done in Lumines:
//
//   - Wait for a PSP to join
//   - Add the PSP to the list of machines available
//   - Wait for the user to select a PSP
//   - Call sceMatchingSelectTarget
//   - The other PSP will receive MATCHING_SELECTED event
//   - The other PSP displays a message to accept or cancel
//   - If accepted the other PSP calls sceMatchingSelectTarget
//   - The first PSP receives MATCHING_ESTABLISHED
// 
// In lumines they then close the connection and start a new adhoc connection
// with just those two machines in it.
///////////////////////////////////////////////////////////////////////////////////
int adhocSelect(void)
{
	SceCtrlData m_PspPad;
	int err = 0;
	char mac[10];
	char name[256];
	int waitAccept = 0;
	int currentState = PSP_LISTING;
	int oldButtons = 0;
	char tempStr[100];
	char str[256];
	
	sceDisplaySetMode( 0, SCREEN_WIDTH, SCREEN_HEIGHT );
	sceDisplaySetFrameBuf( (char*)VRAM_ADDR, 512, 1, 1 );
	pgFillAllvram(0);pgScreenFrame(2,0);

	for(;;)
	{
		sceCtrlReadBufferPositive(&m_PspPad, 1);
		//pspDebugScreenSetTextColor(0xFFFF);

		switch(currentState)
		{
			case PSP_LISTING:
			{
				//pspDebugScreenInit();
				//pspDebugScreenPrintf("Select a server to connect to, or triangle to return\n\n\n");
				pgFillAllvram(0);pgScreenFrame(2,0);
				mh_print(0,0,"Select a server to connect to, or triangle to return",0xFFFF);
				
				DisplayPspList();
				
				pgScreenFlipV();

				g_Server = 0;

				if(m_PspPad.Buttons != oldButtons)
				{
					if(m_PspPad.Buttons & PSP_CTRL_UP)
					{
						UpList();
					}

					if(m_PspPad.Buttons & PSP_CTRL_DOWN)
					{
						DownList();
					}

					if(m_PspPad.Buttons & PSP_CTRL_CROSS)
					{
						if(GetPspEntry(mac, name) > 0)
						{
							currentState = PSP_SELECTING;
							sceNetAdhocMatchingSelectTarget(matchingId, mac, 0, 0);
						}
					}

					if(m_PspPad.Buttons & PSP_CTRL_TRIANGLE)
						return -1;
				}		
				if(matchChanged)
				{
					if(g_matchEvent == MATCHING_SELECTED)
					{
						memcpy(mac, g_mac, 6);
						strcpy(name, g_matchOptData);
						currentState = PSP_SELECTED;
					}
				}
				break;
			}
			case PSP_SELECTING:
			{
				//pspDebugScreenInit();
				pgFillAllvram(0);pgScreenFrame(2,0);				
				
				sceNetEtherNtostr(mac, tempStr);
				//printf("Waiting for %s to accept the connection\nTo cancel press O\n", tempStr);
				sprintf(str,"Waiting for %s to accept the connection\nTo cancel press O\n", tempStr);
				mh_print(0,0,str,0xFFFF);
				pgScreenFlipV();

				if(m_PspPad.Buttons != oldButtons)
				{
					if(m_PspPad.Buttons & PSP_CTRL_CIRCLE)
					{
						sceNetAdhocMatchingCancelTarget(matchingId, mac);
						currentState = PSP_LISTING;
					}
				}

				if(matchChanged)
				{
					if(g_matchEvent == MATCHING_SELECTED)
					{
						sceNetAdhocMatchingCancelTarget(matchingId, mac);
					}
					else if(g_matchEvent == MATCHING_ESTABLISHED)
					{
						currentState = PSP_ESTABLISHED;
					}
					else if(g_matchEvent == MATCHING_REJECTED)
					{
						currentState = PSP_LISTING;
					}
				}
				break;
			}
			case PSP_SELECTED:
			{
				g_Server = 1;

				//pspDebugScreenInit();
				pgFillAllvram(0);pgScreenFrame(2,0);
				
				sceNetEtherNtostr(mac, tempStr);
				sprintf(str,"%s has requested a connection\nTo accept the connection press X, to cancel press O\n", tempStr);
				mh_print(0,0,str,0xFFFF);
				pgScreenFlipV();

				if(m_PspPad.Buttons != oldButtons)
				{
					if(m_PspPad.Buttons & PSP_CTRL_CIRCLE)
					{
						sceNetAdhocMatchingCancelTarget(matchingId, mac);
						currentState = PSP_LISTING;
					}
					if(m_PspPad.Buttons & PSP_CTRL_CROSS)
					{
						sceNetAdhocMatchingSelectTarget(matchingId, mac, 0, 0);
						currentState = PSP_WAIT_EST;
					}
				}

				if(matchChanged)
				{
					if(g_matchEvent == MATCHING_CANCELED)
					{
						currentState = PSP_LISTING;
					}
				}
				break;
			}
			case PSP_WAIT_EST:
			{
				if(matchChanged)
				{
					if(g_matchEvent == MATCHING_ESTABLISHED)
					{
						currentState = PSP_ESTABLISHED;
					}
				}
				break;
			}
		}

		matchChanged = 0;
		oldButtons = m_PspPad.Buttons;

		if(currentState == PSP_ESTABLISHED)
			break;

		sceDisplayWaitVblankStart();
	}

	char macAddr[10];
	char *tempMac;
	if(g_Server)
	{
		sceWlanGetEtherAddr(macAddr);
		tempMac = macAddr;
	}
	else
	{
		tempMac = mac;
	}

	sceNetEtherNtostr(tempMac, tempStr);

	char ssid[10];
	sprintf(ssid, "%c%c%c%c%c%c", tempStr[9], tempStr[10], tempStr[12], tempStr[13], 
			tempStr[15], tempStr[16]);
	adhocReconnect(ssid);

	// We only get here if both PSP's have agreed to connect
	//pspDebugScreenInit();
	//pspDebugScreenPrintf("Connected\n");
	pgFillAllvram(0);pgScreenFrame(2,0);
	mh_print(0,0,"Connected",0xFFFF);
	pgScreenFlipV();

	return 0;
}
Exemplo n.º 4
0
void pspAdhocSelectTarget(const PspMAC mac)
{
  sceNetAdhocMatchingSelectTarget(_matching_id, (unsigned char*)mac, 0, 0);
}