Esempio n. 1
0
int AdhocMatchingStart(const char *hello)
{
	int ret;
	
	if(hello == NULL)
		ret = sceNetAdhocMatchingStart(AdhocMatchingId, 16, 32 * 1024, 16, 0, 0, NULL);
	else
		ret = sceNetAdhocMatchingStart(AdhocMatchingId, 16, 32 * 1024, 16, 0, strlen(hello) + 1, (void*)hello);
	 
	if(ret < 0)
	{
		printf("Adhoc error: sceNetAdhocMatchingStart\n");
		return 0;
	}
	
	return 1;
}
Esempio n. 2
0
int adhocInit(const char *matchingData)
{
	struct productStruct product;
	int error = 0, state = 0;
	unsigned char mac[6];
	const char *unknown = "";
	char message[256];

	video_set_mode(32);

	mode = MODE_LOBBY;
	Server = 0;
	adhoc_initialized = 0;

	g_unk1        = 0;
	g_matchEvent  = 0;
	g_matchOptLen = 0;
	matchChanged  = 0;
	memset(g_mac, 0, sizeof(g_mac));
	memset(g_mymac, 0, sizeof(g_mymac));

	sprintf((char *)product.product, PRODUCT "00%d%d%d", VERSION_MAJOR, VERSION_MINOR, VERSION_BUILD);
	product.unknown = 0;

	ClearPspList();

	if (strlen(matchingData) == 0)
		return -1;

	strcpy(g_matchingData, matchingData);

	sprintf(message, TEXT(CONNECTING_TO_x), TEXT(LOBBY));
	adhoc_init_progress(10, message);

	if ((error = sceNetInit(0x20000, 0x20, 0x1000, 0x20, 0x1000)) == 0)
	{
		update_progress();
		if ((error = sceNetAdhocInit()) == 0)
		{
			update_progress();
			if ((error = sceNetAdhocctlInit(0x2000, 0x20, &product)) == 0)
			{
				update_progress();
				if ((error = sceNetAdhocctlConnect(unknown)) == 0)
				{
					update_progress();
					do
					{
						if ((error = sceNetAdhocctlGetState(&state)) != 0) break;
						sceKernelDelayThread(1000000/60);

					} while (state != 1);

					if (!error)
					{
						update_progress();

						sceWlanGetEtherAddr(mac);
						update_progress();

						if ((pdpId = sceNetAdhocPdpCreate(mac, PDP_PORT, PDP_BUFFER_SIZE, 0)) > 0)
						{
							update_progress();
							if ((error = sceNetAdhocMatchingInit(0x20000)) == 0)
							{
								update_progress();
								if ((matchingId = sceNetAdhocMatchingCreate(MATCHING_CREATE_PARAMS)) >= 0)
								{
									update_progress();
									if ((error = sceNetAdhocMatchingStart(MATCHING_START_PARAMS)) == 0)
									{
										update_progress();
										show_progress(TEXT(CONNECTED));
										sceKernelDelayThread(1000000);
										adhoc_initialized = 1;
										return 0;
									}
									sceNetAdhocMatchingDelete(matchingId);
								}
								error = 2;
								sceNetAdhocMatchingTerm();
							}
							sceNetAdhocPdpDelete(pdpId, 0);
						}
						error = 1;
					}
					sceNetAdhocctlDisconnect();
				}
				sceNetAdhocctlTerm();
			}
			sceNetAdhocTerm();
		}
		sceNetTerm();
	}

	switch (error)
	{
	case 1:  sprintf(message, "%s (PDP ID = %08x)", TEXT(FAILED), pdpId); break;
	case 2:  sprintf(message, "%s (Matching ID = %08x)", TEXT(FAILED), matchingId); break;
	default: sprintf(message, "%s (Error Code = %08x)", TEXT(FAILED), error); break;
	}

	show_progress(message);

	pad_wait_clear();
	pad_wait_press(PAD_WAIT_INFINITY);

	return -1;
}
Esempio n. 3
0
int adhocInit(char *MatchingData)
{
	char mac[6];
	struct productStruct product;

	ClearPspList();

	strcpy(product.product, "ULUS99999");
	product.unknown = 0;

    u32 err;
	printf2("sceNetInit()\n");
    err = sceNetInit(0x20000, 0x20, 0x1000, 0x20, 0x1000);
    if (err != 0)
        return err;
	g_NetInit = true;

	printf2("sceNetAdhocInit()\n");
    err = sceNetAdhocInit();
    if (err != 0)
        return err;
	g_NetAdhocInit = true;
	
	printf2("sceNetAdhocctlInit()\n");
    err = sceNetAdhocctlInit(0x2000, 0x20, &product);
    if (err != 0)
        return err;
	g_NetAdhocctlInit = true;

    // Connect
    err = sceNetAdhocctlConnect("");
    if (err != 0)
        return err;
	g_NetAdhocctlConnect = true;

    int stateLast = -1;
    printf2("Connecting...\n");
    while (1)
    {
        int state;
        err = sceNetAdhocctlGetState(&state);
        if (err != 0)
        {
        		pspDebugScreenInit();
            printf("sceNetApctlGetState returns $%x\n", err);
            sceKernelDelayThread(10*1000000); // 10sec to read before exit
			return -1;
        }
        if (state > stateLast)
        {
        		sprintf(temp,"  connection state %d of 1\n", state);
            printf2(temp);
            stateLast = state;
        }
        if (state == 1)
            break;  // connected

        // wait a little before polling again
        sceKernelDelayThread(50*1000); // 50ms
    }
    printf2("Connected!\n");
    
    
	sceWlanGetEtherAddr(mac);
	
	
    printf2("sceNetAdhocPdpCreate\n");
    
    
	pdpId = sceNetAdhocPdpCreate(mac,
		     0x309,		// 0x309 in lumines
		     0x400, 	// 0x400 in lumines
		     0);		// 0 in lumines
	if(pdpId <= 0)
	{
		
		pspDebugScreenInit();
		printf("pdpId = %x\n", pdpId);
		return -1;
	}
	g_NetAdhocPdpCreate = true;

	printf2("sceNetAdhocMatchingInit()\n");
	
	err = sceNetAdhocMatchingInit(0x20000);
	if(err != 0)
	{
		pspDebugScreenInit();
		printf("error = %x\n", err);
	}
	g_NetAdhocMatchingInit = true;
	
	printf2("sceNetAdhocMatchingCreate()\n");
	matchingId = sceNetAdhocMatchingCreate( 3,
											0xa,
											0x22b,
											0x800,
											0x2dc6c0,
											0x5b8d80,
											3,
											0x7a120,
											matchingCallback);

	if(matchingId < 0)
	{
		sprintf(temp,"matchingId = %x\n", matchingId);
		printf2(temp);
	}
	g_NetAdhocMatchingCreate = true;

	/*char tempStr[100];
	tempStr[0] = '\0';	
	if(strlen(MatchingData))
	{
		strncpy(tempStr, strrchr(MatchingData, '/')+1, 100);
		strrchr(tempStr, '.')[0] = '\0';
	}*
	printf("tempStr=%s\n", tempStr);*/

	printf2("sceNetAdhocMatchingStart()\n");
	
	err = sceNetAdhocMatchingStart(matchingId, 	// 1 in lumines (presuming what is returned from create)
			 0x10,		// 0x10
			 0x2000,		// 0x2000
			 0x10,		// 0x10
			 0x2000,		// 0x2000
			 strlen(MatchingData)+1,
			 MatchingData);		
	if(err != 0)
	{
		pspDebugScreenInit();
		printf("error = %x\n", err);
	}
	
	g_NetAdhocMatchingStart = true;

	// All the init functions have passed
	return 0;
}
Esempio n. 4
0
int pspAdhocInit(const char *product_name, 
                PspMatchingCallback callback)
{
  /* Shut down adhoc, if currently enabled */
  pspAdhocShutdown();

  struct productStruct product;
  char mac[20];
  int err, state = 0;

  strncpy(product.product, product_name, 9);
  product.unknown = 0;
  if (sceUtilityGetSystemParamString(PSP_SYSTEMPARAM_ID_STRING_NICKNAME, 
                                     _matching_data, 128) != 0)
    return 0;

  if ((err = sceNetInit(0x20000, 0x2A, 0x1000, 0x2A, 0x1000)) == 0)
  {
    _net_init = 1;
    if ((err = sceNetAdhocInit()) == 0)
    {
      _net_adhoc_init = 1;
      if ((err = sceNetAdhocctlInit(0x2000, 0x20, &product)) == 0)
      {
        _net_adhoc_ctl_init = 1;
        if ((err = sceNetAdhocctlConnect((void*)"")) == 0)
        {
          _net_adhoc_ctl_connect = 1;
          do
          {
            if ((err = sceNetAdhocctlGetState(&state)) != 0) break;
            sceKernelDelayThread(1000000/60);
          } while (state != 1);

          /* Get WLAN MAC */
          unsigned char own_mac[8];
          sceWlanGetEtherAddr(own_mac);
          memcpy(_own_mac, own_mac, sizeof(unsigned char) * 6);

          if (err == 0)
          {
            sceWlanGetEtherAddr((unsigned char*)mac);
            if ((_pdp_id = sceNetAdhocPdpCreate((unsigned char*)mac, 0x309, 0x400, 0)) > 0)
            {
              _net_adhoc_pdp_create = 1;
              if ((err = sceNetAdhocMatchingInit(0x20000)) == 0)
              {
                _net_adhoc_matching_init = 1;
                _matching_id = sceNetAdhocMatchingCreate(3,
                                                        0xa,
                                                        0x22b,
                                                        0x800,
                                                        0x2dc6c0,
                                                        0x5b8d80,
                                                        3,
                                                        0x7a120,
                                                        callback);
                if (_matching_id >= 0)
                {
                  _net_adhoc_matching_create = 1;
                  err = sceNetAdhocMatchingStart(_matching_id,
                                                0x10,
                                                0x2000,
                                                0x10,
                                                0x2000,
                                                strlen(_matching_data) + 1,
                                                _matching_data);
                  if (err == 0)
                  {
                    _net_adhoc_matching_start = 1;
                    /* Everything checked out */
                    return 1;
                  }
                  sceNetAdhocMatchingDelete(_matching_id);
                  _net_adhoc_matching_create = 0;
                }
                sceNetAdhocMatchingTerm();
                _net_adhoc_matching_init = 0;
              }
              sceNetAdhocPdpDelete(_pdp_id, 0);
              _net_adhoc_pdp_create = 0;
            }
          }
          sceNetAdhocctlDisconnect();
          _net_adhoc_ctl_connect = 0;
        }
        sceNetAdhocctlTerm();
        _net_adhoc_ctl_init = 0;
      }
      sceNetAdhocTerm();
      _net_adhoc_init = 0;
    }
    sceNetTerm();
    _net_init = 0;
  }
  
  return 0;
}