first commit
This commit is contained in:
491
Minecraft.Client/PSVita/Network/PSVita_NPToolkit.cpp
Normal file
491
Minecraft.Client/PSVita/Network/PSVita_NPToolkit.cpp
Normal file
@@ -0,0 +1,491 @@
|
||||
#include "stdafx.h"
|
||||
|
||||
#include "PSVita_NPToolkit.h"
|
||||
#include "PSVita/PSVitaExtras/Conf.h"
|
||||
#include "PSVita/Network/SonyCommerce_Vita.h"
|
||||
|
||||
// #define NP_TITLE_ID "CUSA00265_00"
|
||||
// #define NP_TITLE_SECRET_HEX "c37e30fa1f7fd29e3534834d62781143ae29aa7b51d02320e7aa0b45116ad600e4d309e8431bc37977d98b8db480e721876e7d736e11fd906778c0033bbb6370903477b1dc1e65106afc62007a5feee3158844d721b88c3f4bff2e56417b6910cedfdec78b130d2e0dd35a35a9e2ae31d5889f9398c1d62b52a3630bb03faa5b"
|
||||
// #define CLIENT_ID_FOR_SAMPLE "c8c483e7-f0b4-420b-877b-307fcb4c3cdc"
|
||||
|
||||
//#define _USE_STANDARD_ALLOC
|
||||
|
||||
// sce::Toolkit::NP::Utilities::Future< sce::Toolkit::NP::NpSessionInformation > PSVitaNPToolkit::sm_createJoinFuture;
|
||||
// sce::Toolkit::NP::NpSessionInformation PSVitaNPToolkit::m_currentSessionInfo;
|
||||
sce::Toolkit::NP::Utilities::Future<sce::Toolkit::NP::MessageAttachment> PSVitaNPToolkit::m_messageData;
|
||||
|
||||
|
||||
void PSVitaNPToolkit::presenceCallback( const sce::Toolkit::NP::Event& event )
|
||||
{
|
||||
switch(event.event)
|
||||
{
|
||||
case sce::Toolkit::NP::Event::presenceSet:
|
||||
app.DebugPrintf("presenceSet Successfully\n");
|
||||
break;
|
||||
case sce::Toolkit::NP::Event::presenceSetFailed:
|
||||
app.DebugPrintf("presenceSetFailed event received = 0x%x\n", event.returnCode);
|
||||
SQRNetworkManager_Vita::SetPresenceFailedCallback();
|
||||
// assert(0);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void PSVitaNPToolkit::profileCallback( const sce::Toolkit::NP::Event& event )
|
||||
{
|
||||
switch(event.event)
|
||||
{
|
||||
case sce::Toolkit::NP::Event::profileError:
|
||||
app.DebugPrintf("User profile error: 0x%x\n", event.returnCode);
|
||||
break;
|
||||
default:
|
||||
app.DebugPrintf("User profile event: %i\n", event.event);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void PSVitaNPToolkit::messagingCallback( const sce::Toolkit::NP::Event& event )
|
||||
{
|
||||
switch(event.event)
|
||||
{
|
||||
case sce::Toolkit::NP::Event::serviceError:
|
||||
app.DebugPrintf("NP messagingCallback - serviceError: 0x%x\n", event.returnCode);
|
||||
ProfileManager.SetSysUIShowing( false );
|
||||
break;
|
||||
case sce::Toolkit::NP::Event::messageSent:
|
||||
app.DebugPrintf("NP messagingCallback - messageSent: 0x%x\n", event.returnCode);
|
||||
ProfileManager.SetSysUIShowing( false );
|
||||
break;
|
||||
case sce::Toolkit::NP::Event::messageError:
|
||||
app.DebugPrintf("NP messagingCallback - messageError: 0x%x\n", event.returnCode);
|
||||
if(SQRNetworkManager_Vita::m_bSendingInviteMessage) // MGH - added to fix a sysUI lockup on startup - devtrack #5883
|
||||
ProfileManager.SetSysUIShowing( false );
|
||||
break;
|
||||
case sce::Toolkit::NP::Event::messageDialogTerminated:
|
||||
app.DebugPrintf("NP messagingCallback - messageDialogTerminated: 0x%x\n", event.returnCode);
|
||||
ProfileManager.SetSysUIShowing( false );
|
||||
break;
|
||||
case sce::Toolkit::NP::Event::messageRetrieved:
|
||||
app.DebugPrintf("NP messagingCallback - messageRetrieved: 0x%x\n", event.returnCode);
|
||||
if(m_messageData.hasResult())
|
||||
{
|
||||
SQRNetworkManager_Vita::GetInviteDataAndProcess(m_messageData.get());
|
||||
}
|
||||
else
|
||||
{
|
||||
app.DebugPrintf("messageRetrieved error 0x%08x\n", m_messageData.getError());
|
||||
}
|
||||
break;
|
||||
case sce::Toolkit::NP::Event::messageInGameDataReceived:
|
||||
app.DebugPrintf("NP messagingCallback - messageInGameDataReceived: 0x%x\n", event.returnCode);
|
||||
break;
|
||||
case sce::Toolkit::NP::Event::messageInGameDataRetrievalDone:
|
||||
app.DebugPrintf("NP messagingCallback - messageInGameDataRetrievalDone: 0x%x\n", event.returnCode);
|
||||
break;
|
||||
|
||||
default:
|
||||
assert(0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void PSVitaNPToolkit::coreCallback( const sce::Toolkit::NP::Event& event )
|
||||
{
|
||||
switch (event.event)
|
||||
{
|
||||
case sce::Toolkit::NP::Event::enetUp: ///< An event from the NetCtl service generated when a connection has been established.
|
||||
app.DebugPrintf("Received core callback: Network Up \n");
|
||||
break;
|
||||
case sce::Toolkit::NP::Event::enetDown: ///< An event from the NetCtl service generated when the connection layer has gone down.
|
||||
app.DebugPrintf("Received core callback: Network down \n");
|
||||
break;
|
||||
case sce::Toolkit::NP::Event::loggedIn: ///< An event from the NetCtl service generated when a connection to the PSN has been established.
|
||||
app.DebugPrintf("Received core callback: PSN sign in \n");
|
||||
ProfileManager.SetNetworkStatus(true, true);
|
||||
break;
|
||||
case sce::Toolkit::NP::Event::loggedOut: ///< An event from the NetCtl service generated when a connection to the PSN has been lost.
|
||||
app.DebugPrintf("Received core callback: PSN sign out \n");
|
||||
ProfileManager.SetNetworkStatus(false, true);
|
||||
break;
|
||||
default:
|
||||
app.DebugPrintf("Received core callback: event Num: %d \n", event.event);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void PSVitaNPToolkit::sceNpToolkitCallback( const sce::Toolkit::NP::Event& event)
|
||||
{
|
||||
switch(event.service)
|
||||
{
|
||||
case sce::Toolkit::NP::ServiceType::core:
|
||||
coreCallback(event);
|
||||
break;
|
||||
// case sce::Toolkit::NP::ServiceType::netInfo:
|
||||
// Menu::NetInfo::sceNpToolkitCallback(event);
|
||||
// break;
|
||||
// case sce::Toolkit::NP::ServiceType::sessions:
|
||||
// sessionsCallback(event);
|
||||
// break;
|
||||
// case sce::Toolkit::NP::ServiceType::tss:
|
||||
// Menu::Tss::sceNpToolkitCallback(event);
|
||||
// break;
|
||||
// case sce::Toolkit::NP::ServiceType::ranking:
|
||||
// Menu::Ranking::sceNpToolkitCallback(event);
|
||||
// break;
|
||||
// case sce::Toolkit::NP::ServiceType::tus:
|
||||
// Menu::Tus::sceNpToolkitCallback(event);
|
||||
// break;
|
||||
case sce::Toolkit::NP::ServiceType::profile:
|
||||
profileCallback(event);
|
||||
break;
|
||||
case sce::Toolkit::NP::ServiceType::messaging:
|
||||
messagingCallback(event);
|
||||
// case sce::Toolkit::NP::ServiceType::friends:
|
||||
// Menu::Friends::sceNpToolkitCallback(event);
|
||||
// break;
|
||||
// case sce::Toolkit::NP::ServiceType::auth:
|
||||
// Menu::Auth::sceNpToolkitCallback(event);
|
||||
// break;
|
||||
case sce::Toolkit::NP::ServiceType::trophy:
|
||||
// ProfileManager.trophySystemCallback(event);
|
||||
break;
|
||||
// case sce::Toolkit::NP::ServiceType::messaging:
|
||||
// messagingCallback(event);
|
||||
// case sce::Toolkit::NP::ServiceType::inGameMessage:
|
||||
// Menu::Messaging::sceNpToolkitCallback(event);
|
||||
// break;
|
||||
|
||||
case sce::Toolkit::NP::ServiceType::commerce:
|
||||
SonyCommerce_Vita::commerce2Handler(event);
|
||||
break;
|
||||
case sce::Toolkit::NP::ServiceType::presence:
|
||||
presenceCallback(event);
|
||||
break;
|
||||
// case sce::Toolkit::NP::ServiceType::wordFilter:
|
||||
// Menu::WordFilter::sceNpToolkitCallback(event);
|
||||
// break;
|
||||
// case sce::Toolkit::NP::ServiceType::sns:
|
||||
// Menu::Sns::sceNpToolkitCallback(event);
|
||||
// break;
|
||||
|
||||
// case sce::Toolkit::NP::ServiceType::gameCustomData:
|
||||
// gameCustomDataCallback(event);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// void PSVitaNPToolkit::sessionsCallback( const sce::Toolkit::NP::Event& event)
|
||||
// {
|
||||
// switch(event.event)
|
||||
// {
|
||||
// case sce::Toolkit::NP::Event::npSessionCreateResult: ///< An event generated when the %Np session creation process has been completed.
|
||||
// app.DebugPrintf("npSessionCreateResult");
|
||||
// if(sm_createJoinFuture.hasResult())
|
||||
// {
|
||||
// app.DebugPrintf("Session Created Successfully\n");
|
||||
// m_currentSessionInfo = *sm_createJoinFuture.get();
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// app.DebugPrintf("Session Creation Failed 0x%x\n",sm_createJoinFuture.getError());
|
||||
// }
|
||||
// sm_createJoinFuture.reset();
|
||||
// break;
|
||||
// case sce::Toolkit::NP::Event::npSessionJoinResult: ///< An event generated when the join %Np session process has been completed.
|
||||
// app.DebugPrintf("npSessionJoinResult");
|
||||
// if(sm_createJoinFuture.hasResult())
|
||||
// {
|
||||
// app.DebugPrintf("Session joined successfully\n");
|
||||
// m_currentSessionInfo = *sm_createJoinFuture.get();
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// app.DebugPrintf("Session join Failed 0x%x\n",sm_createJoinFuture.getError());
|
||||
// }
|
||||
// sm_createJoinFuture.reset();
|
||||
// break;
|
||||
// case sce::Toolkit::NP::Event::npSessionError: ///< An event generated when there was error performing the current %Np session process.
|
||||
// app.DebugPrintf("npSessionError");
|
||||
// break;
|
||||
// case sce::Toolkit::NP::Event::npSessionLeaveResult: ///< An event generated when the user has left the current %Np session.
|
||||
// app.DebugPrintf("npSessionLeaveResult");
|
||||
// break;
|
||||
// case sce::Toolkit::NP::Event::npSessionModified: ///< An event generated when the %Np session has been modified.
|
||||
// app.DebugPrintf("npSessionModified");
|
||||
// break;
|
||||
// case sce::Toolkit::NP::Event::npSessionUpdateResult: ///< An event generated when the %Np session has been updated.
|
||||
// app.DebugPrintf("npSessionUpdateResult");
|
||||
// break;
|
||||
// case sce::Toolkit::NP::Event::npSessionGetInfoResult: ///< An event generated when the %Np session info has been retrieved.
|
||||
// app.DebugPrintf("npSessionGetInfoResult");
|
||||
// break;
|
||||
// case sce::Toolkit::NP::Event::npSessionGetInfoListResult: ///< An event generated when the %Np session info has been retrieved.
|
||||
// app.DebugPrintf("npSessionGetInfoListResult");
|
||||
// break;
|
||||
// case sce::Toolkit::NP::Event::npSessionGetSessionDataResult: ///< An event generated when the %Np session data has been retrieved.
|
||||
// app.DebugPrintf("npSessionGetSessionDataResult");
|
||||
// break;
|
||||
// case sce::Toolkit::NP::Event::npSessionSearchResult: ///< An event generated when the %Np session search request has been completed.
|
||||
// app.DebugPrintf("npSessionSearchResult");
|
||||
// break;
|
||||
// case sce::Toolkit::NP::Event::npSessionInviteNotification: ///< An event generated when the %Np session push notification is received.
|
||||
// app.DebugPrintf("npSessionInviteNotification");
|
||||
// break;
|
||||
// case sce::Toolkit::NP::Event::npSessionInviteGetInfoResult: ///< An event generated when the %Np session info has been retrieved.
|
||||
// app.DebugPrintf("npSessionInviteGetInfoResult");
|
||||
// break;
|
||||
// case sce::Toolkit::NP::Event::npSessionInviteGetInfoListResult: ///< An event generated when the %Np session info has been retrieved.
|
||||
// app.DebugPrintf("npSessionInviteGetInfoListResult");
|
||||
// break;
|
||||
// case sce::Toolkit::NP::Event::npSessionInviteGetDataResult: ///< An event generated when the %Np session data has been retrieved.
|
||||
// app.DebugPrintf("npSessionInviteGetDataResult");
|
||||
// break;
|
||||
// default:
|
||||
// assert(0);
|
||||
// break;
|
||||
// }
|
||||
//
|
||||
// }
|
||||
|
||||
void PSVitaNPToolkit::gameCustomDataCallback( const sce::Toolkit::NP::Event& event)
|
||||
{
|
||||
// switch(event.event)
|
||||
// {
|
||||
//
|
||||
// case sce::Toolkit::NP::Event::gameCustomDataItemListResult:
|
||||
// app.DebugPrintf("gameCustomDataItemListResult");
|
||||
// break;
|
||||
// case sce::Toolkit::NP::Event::gameCustomDataGameDataResult:
|
||||
// app.DebugPrintf("gameCustomDataGameDataResult");
|
||||
// if(m_messageData.hasResult())
|
||||
// {
|
||||
// SQRNetworkManager_Orbis::GetInviteDataAndProcess(m_messageData.get());
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// app.DebugPrintf("gameCustomDataMessageResult error 0x%08x\n", m_messageData.getError());
|
||||
// }
|
||||
// break;
|
||||
// case sce::Toolkit::NP::Event::gameCustomDataMessageResult:
|
||||
// app.DebugPrintf("gameCustomDataMessageResult");
|
||||
// break;
|
||||
// case sce::Toolkit::NP::Event::gameCustomDataSetUseFlagResult:
|
||||
// app.DebugPrintf("gameCustomDataSetUseFlagResult");
|
||||
// break;
|
||||
// case sce::Toolkit::NP::Event::gameCustomDataGameThumbnailResult:
|
||||
// app.DebugPrintf("gameCustomDataGameThumbnailResult");
|
||||
// break;
|
||||
// case sce::Toolkit::NP::Event::messageError:
|
||||
// app.DebugPrintf("messageError : 0x%08x\n", event.returnCode);
|
||||
// assert(0);
|
||||
// break;
|
||||
// default:
|
||||
// assert(0);
|
||||
// break;
|
||||
// }
|
||||
}
|
||||
|
||||
static uint8_t hexCharToUint(char ch)
|
||||
{
|
||||
uint8_t val = 0;
|
||||
|
||||
if ( isdigit(ch) ){
|
||||
val = (ch - '0');
|
||||
}
|
||||
else if ( isupper(ch) ){
|
||||
val = (ch - 'A' + 10);
|
||||
}
|
||||
else{
|
||||
val = (ch - 'a' + 10);
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
void hexStrToBin(
|
||||
const char *pHexStr,
|
||||
uint8_t *pBinBuf,
|
||||
size_t binBufSize
|
||||
)
|
||||
{
|
||||
uint8_t val = 0;
|
||||
int hexStrLen = strlen(pHexStr);
|
||||
|
||||
int binOffset = 0;
|
||||
for (int i = 0; i < hexStrLen; i++) {
|
||||
val |= hexCharToUint(*(pHexStr + i));
|
||||
if (i % 2 == 0) {
|
||||
val <<= 4;
|
||||
}
|
||||
else {
|
||||
if (pBinBuf != NULL && binOffset < binBufSize) {
|
||||
memcpy(pBinBuf + binOffset, &val, 1);
|
||||
val = 0;
|
||||
}
|
||||
binOffset++;
|
||||
}
|
||||
}
|
||||
|
||||
if (val != 0 && pBinBuf != NULL && binOffset < binBufSize) {
|
||||
memcpy(pBinBuf + binOffset, &val, 1);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
static void npStateCallback(SceNpServiceState state, int retCode, void *userdata)
|
||||
{
|
||||
//CD - Updates the online status of player
|
||||
switch(state)
|
||||
{
|
||||
case SCE_NP_SERVICE_STATE_SIGNED_OUT:
|
||||
ProfileManager.SetNetworkStatus(false, false);
|
||||
break;
|
||||
case SCE_NP_SERVICE_STATE_SIGNED_IN:
|
||||
ProfileManager.SetNetworkStatus(false, true);
|
||||
break;
|
||||
case SCE_NP_SERVICE_STATE_ONLINE:
|
||||
ProfileManager.SetNetworkStatus(true, true);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void PSVitaNPToolkit::init()
|
||||
{
|
||||
// MenuApp menuApp;
|
||||
// sce::Toolkit::NP::NpTitleId nptTitleId;
|
||||
// nptTitleId.setTitleSecret(*SQRNetworkManager_Vita::GetSceNpTitleId(), *SQRNetworkManager_Vita::GetSceNpTitleSecret());
|
||||
sce::Toolkit::NP::CommunicationId commsIds(s_npCommunicationId, s_npCommunicationPassphrase, s_npCommunicationSignature);
|
||||
sce::Toolkit::NP::Parameters params(sceNpToolkitCallback,commsIds);
|
||||
params.m_title.setId(app.GetCommerceCategory());
|
||||
|
||||
|
||||
int ret = sce::Toolkit::NP::Interface::init(params);
|
||||
if (ret != SCE_OK)
|
||||
{
|
||||
app.DebugPrintf("Failed to initialize NP Toolkit Library : 0x%x\n", ret);
|
||||
assert(0);
|
||||
}
|
||||
|
||||
|
||||
ret = sce::Toolkit::NP::Interface::registerNpCommsId(commsIds, sce::Toolkit::NP::matching);
|
||||
if (ret < 0)
|
||||
{
|
||||
app.DebugPrintf("Failed to register TSS Comms ID : 0x%x\n", ret);
|
||||
assert(0);
|
||||
}
|
||||
|
||||
// extern void npStateCallback(SceNpServiceState state, int retCode, void *userdata);
|
||||
|
||||
ret = sceNpRegisterServiceStateCallback(npStateCallback, NULL);
|
||||
if (ret < 0)
|
||||
{
|
||||
app.DebugPrintf("sceNpRegisterServiceStateCallback() failed. ret = 0x%x\n", ret);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// // Register Client ID for Auth
|
||||
// ret = sce::Toolkit::NP::Interface::registerClientId(CLIENT_ID_FOR_SAMPLE);
|
||||
// if (ret < 0)
|
||||
// {
|
||||
// app.DebugPrintf("Failed to register Auth Client ID : 0x%x\n", ret);
|
||||
// assert(0);
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// void PSVitaNPToolkit::createNPSession()
|
||||
// {
|
||||
// #define CURRENT_SESSION_ATTR_NUMS 5
|
||||
// #define SESSION_IMAGE_PATH "/app0/orbis/session_image.png"
|
||||
// #define SESSION_STATUS "Minecraft online game (this text needs defined and localised)"
|
||||
// #define SESSION_NAME "Minecraft(this text needs defined and localised)"
|
||||
//
|
||||
// static const int maxSlots = 8;
|
||||
//
|
||||
// SceUserServiceUserId userId = SCE_USER_SERVICE_USER_ID_INVALID;
|
||||
// int ret = sceUserServiceGetInitialUser(&userId);
|
||||
// if( ret < 0 )
|
||||
// {
|
||||
// app.DebugPrintf("Couldn't retrieve user ID 0x%x ...\n",ret);
|
||||
// }
|
||||
//
|
||||
// sce::Toolkit::NP::CreateNpSessionRequest createSessionRequest;
|
||||
// memset(&createSessionRequest,0,sizeof(createSessionRequest));
|
||||
// strncpy(createSessionRequest.sessionName,SESSION_NAME,strlen(SESSION_NAME));
|
||||
// createSessionRequest.sessionTypeFlag = SCE_TOOLKIT_NP_CREATE_SESSION_TYPE_PUBLIC;
|
||||
// createSessionRequest.maxSlots = maxSlots;
|
||||
// strncpy(createSessionRequest.sessionImgPath,SESSION_IMAGE_PATH,strlen(SESSION_IMAGE_PATH));
|
||||
// strncpy(createSessionRequest.sessionStatus,SESSION_STATUS,strlen(SESSION_STATUS));
|
||||
// createSessionRequest.userInfo.userId = userId;
|
||||
// char test[3] = {'R','K','B'};
|
||||
// createSessionRequest.sessionData= test;
|
||||
// createSessionRequest.sessionDataSize = 3;
|
||||
// ret = sce::Toolkit::NP::Sessions::Interface::create(&createSessionRequest,&sm_createJoinFuture);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// void PSVitaNPToolkit::joinNPSession()
|
||||
// {
|
||||
// SceUserServiceUserId userId = SCE_USER_SERVICE_USER_ID_INVALID;
|
||||
// int ret = sceUserServiceGetInitialUser(&userId);
|
||||
// if( ret < 0 )
|
||||
// {
|
||||
// app.DebugPrintf("Couldn't retrieve user ID 0x%x ...\n",ret);
|
||||
// }
|
||||
//
|
||||
// sce::Toolkit::NP::JoinNpSessionRequest joinSessionRequest;
|
||||
// memset(&joinSessionRequest,0,sizeof(joinSessionRequest));
|
||||
// // still to sort this out
|
||||
// ORBIS_STUBBED;
|
||||
// }
|
||||
//
|
||||
// void PSVitaNPToolkit::leaveNPSession()
|
||||
// {
|
||||
//
|
||||
// }
|
||||
//
|
||||
|
||||
|
||||
void PSVitaNPToolkit::getMessageData(SceAppUtilAppEventParam* paramData)
|
||||
{
|
||||
|
||||
if (SCE_APPUTIL_APPEVENT_TYPE_NP_INVITE_MESSAGE == paramData->type)
|
||||
{
|
||||
sce::Toolkit::NP::Messaging::Interface::retrieveMessageAttachment(paramData,&m_messageData);
|
||||
}
|
||||
else if (SCE_APPUTIL_APPEVENT_TYPE_NP_APP_DATA_MESSAGE == paramData->type)
|
||||
{
|
||||
sce::Toolkit::NP::Messaging::Interface::retrieveMessageAttachment(paramData,&m_messageData);
|
||||
}
|
||||
else if (SCE_APPUTIL_APPEVENT_TYPE_NP_BASIC_JOINABLE_PRESENCE == paramData->type)
|
||||
{
|
||||
SceAppUtilNpBasicJoinablePresenceParam joinParam = {0};
|
||||
int ret = sceAppUtilAppEventParseNpBasicJoinablePresence(paramData, &joinParam);
|
||||
if (ret < 0)
|
||||
{
|
||||
app.DebugPrintf("sceAppUtilAppEventParseNpBasicJoinablePresence() failed: 0x%x\n", ret);
|
||||
}
|
||||
else
|
||||
{
|
||||
SQRNetworkManager_Vita::GetJoinablePresenceDataAndProcess(&joinParam);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(0);
|
||||
}
|
||||
|
||||
}
|
||||
32
Minecraft.Client/PSVita/Network/PSVita_NPToolkit.h
Normal file
32
Minecraft.Client/PSVita/Network/PSVita_NPToolkit.h
Normal file
@@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
#include <np_toolkit.h>
|
||||
// #include <np_toolkit/game_custom_data_interface.h>
|
||||
|
||||
|
||||
class PSVitaNPToolkit
|
||||
{
|
||||
public:
|
||||
static void init();
|
||||
static void sceNpToolkitCallback( const sce::Toolkit::NP::Event& event);
|
||||
static void coreCallback( const sce::Toolkit::NP::Event& event);
|
||||
static void presenceCallback( const sce::Toolkit::NP::Event& event);
|
||||
static void profileCallback( const sce::Toolkit::NP::Event& event);
|
||||
static void messagingCallback( const sce::Toolkit::NP::Event& event);
|
||||
static void sessionsCallback( const sce::Toolkit::NP::Event& event);
|
||||
static void gameCustomDataCallback( const sce::Toolkit::NP::Event& event);
|
||||
|
||||
// static void createNPSession();
|
||||
// static void destroyNPSession();
|
||||
// static void joinNPSession();
|
||||
// static void leaveNPSession();
|
||||
// static SceNpSessionId* getNPSessionID() { return &m_currentSessionInfo.npSessionId; }
|
||||
|
||||
static void getMessageData(SceAppUtilAppEventParam* paramData);
|
||||
private:
|
||||
// static sce::Toolkit::NP::Utilities::Future<sce::Toolkit::NP::NpSessionInformation> sm_createJoinFuture;
|
||||
// static sce::Toolkit::NP::NpSessionInformation m_currentSessionInfo;
|
||||
static sce::Toolkit::NP::Utilities::Future<sce::Toolkit::NP::MessageAttachment> m_messageData;
|
||||
|
||||
};
|
||||
|
||||
3119
Minecraft.Client/PSVita/Network/SQRNetworkManager_AdHoc_Vita.cpp
Normal file
3119
Minecraft.Client/PSVita/Network/SQRNetworkManager_AdHoc_Vita.cpp
Normal file
File diff suppressed because it is too large
Load Diff
352
Minecraft.Client/PSVita/Network/SQRNetworkManager_AdHoc_Vita.h
Normal file
352
Minecraft.Client/PSVita/Network/SQRNetworkManager_AdHoc_Vita.h
Normal file
@@ -0,0 +1,352 @@
|
||||
#pragma once
|
||||
#include <np.h>
|
||||
#include <libnetctl.h>
|
||||
#include <net.h>
|
||||
#include <np_toolkit.h>
|
||||
|
||||
#include <queue>
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
#include "..\..\Common\Network\Sony\SQRNetworkManager.h"
|
||||
//
|
||||
class SQRNetworkPlayer;
|
||||
class ISQRNetworkManagerListener;
|
||||
class SonyVoiceChat_Vita;
|
||||
class SQRVoiceConnection;
|
||||
class C4JThread;
|
||||
|
||||
|
||||
class HelloSyncInfo;
|
||||
|
||||
enum EAdhocDataTag
|
||||
{
|
||||
e_dataTag_Normal,
|
||||
e_dataTag_RoomSync
|
||||
};
|
||||
|
||||
class AdhocDataPacket
|
||||
{
|
||||
public:
|
||||
EAdhocDataTag m_tag;
|
||||
uint32_t m_pData[1];
|
||||
};
|
||||
|
||||
// This is the lowest level manager for providing network functionality on Sony platforms. This manages various network activities including the players within a gaming session.
|
||||
// The game shouldn't directly use this class, it is here to provide functionality required by PlatformNetworkManagerSony.
|
||||
|
||||
class SQRNetworkManager_AdHoc_Vita : public SQRNetworkManager
|
||||
{
|
||||
friend class SonyVoiceChat_Vita;
|
||||
friend class SQRNetworkPlayer;
|
||||
|
||||
static const eSQRNetworkManagerState m_INTtoEXTStateMappings[SNM_INT_STATE_COUNT];
|
||||
|
||||
|
||||
|
||||
public:
|
||||
SQRNetworkManager_AdHoc_Vita(ISQRNetworkManagerListener *listener);
|
||||
|
||||
// General
|
||||
void Tick();
|
||||
void Initialise();
|
||||
bool IsInitialised();
|
||||
void UnInitialise();
|
||||
void Terminate();
|
||||
eSQRNetworkManagerState GetState();
|
||||
bool IsHost();
|
||||
bool IsReadyToPlayOrIdle();
|
||||
bool IsInSession();
|
||||
|
||||
// Session management
|
||||
void CreateAndJoinRoom(int hostIndex, int localPlayerMask, void *extData, int extDataSize, bool offline);
|
||||
void UpdateExternalRoomData();
|
||||
bool FriendRoomManagerIsBusy();
|
||||
bool FriendRoomManagerSearch();
|
||||
bool FriendRoomManagerSearch2();
|
||||
int FriendRoomManagerGetCount();
|
||||
void FriendRoomManagerGetRoomInfo(int idx, SessionSearchResult *searchResult);
|
||||
bool JoinRoom(SessionSearchResult *searchResult, int localPlayerMask);
|
||||
bool JoinRoom(SceNetInAddr netAddr, int localPlayerMask, const HelloSyncInfo *presence);
|
||||
bool JoinRoom(SceNpMatching2RoomId roomId, SceNpMatching2ServerId serverId, int localPlayerMask, const PresenceSyncInfo *presence);
|
||||
void StartGame();
|
||||
void LeaveRoom(bool bActuallyLeaveRoom);
|
||||
void EndGame();
|
||||
bool SessionHasSpace(int spaceRequired);
|
||||
bool AddLocalPlayerByUserIndex(int idx);
|
||||
bool RemoveLocalPlayerByUserIndex(int idx);
|
||||
void SendInviteGUI();
|
||||
static void RecvInviteGUI();
|
||||
void TickInviteGUI();
|
||||
|
||||
|
||||
|
||||
// void GetInviteDataAndProcess(SceNpBasicAttachmentDataId id);
|
||||
static bool UpdateInviteData(HelloSyncInfo *invite);
|
||||
void GetExtDataForRoom( SceNpMatching2RoomId roomId, void *extData, void (* FriendSessionUpdatedFn)(bool success, void *pParam), void *pParam );
|
||||
|
||||
// Player retrieval
|
||||
int GetPlayerCount();
|
||||
int GetOnlinePlayerCount();
|
||||
SQRNetworkPlayer *GetPlayerByIndex(int idx);
|
||||
SQRNetworkPlayer *GetPlayerBySmallId(int idx);
|
||||
SQRNetworkPlayer *GetLocalPlayerByUserIndex(int idx);
|
||||
SQRNetworkPlayer *GetPlayerByXuid(PlayerUID xuid);
|
||||
SQRNetworkPlayer *GetHostPlayer();
|
||||
|
||||
void removePlayerFromVoiceChat(SQRNetworkPlayer* pPlayer);
|
||||
// Communication parameter storage
|
||||
static const SceNpCommunicationId* GetSceNpCommsId();
|
||||
static const SceNpCommunicationSignature* GetSceNpCommsSig();
|
||||
static const SceNpTitleId* GetSceNpTitleId();
|
||||
static const SceNpTitleSecret* GetSceNpTitleSecret();
|
||||
|
||||
static void GetInviteDataAndProcess(sce::Toolkit::NP::MessageAttachment* pInvite);
|
||||
static bool GetAdhocStatus() { return m_adhocStatus; }
|
||||
|
||||
|
||||
int sendDataPacket(SceNetInAddr addr, EAdhocDataTag tag, void* data, int dataSize);
|
||||
int sendDataPacket(SceNetInAddr addr, void* data, int dataSize);
|
||||
|
||||
private:
|
||||
void InitialiseAfterOnline();
|
||||
void ErrorHandlingTick();
|
||||
void UpdateAdhocStatus(int status) { m_adhocStatus = status; }
|
||||
void UpdateLocalIPAddress();
|
||||
|
||||
ISQRNetworkManagerListener *m_listener;
|
||||
SQRNetworkPlayer *GetPlayerIfReady(SQRNetworkPlayer *player);
|
||||
|
||||
// Internal state
|
||||
void SetState(eSQRNetworkManagerInternalState state);
|
||||
void ResetToIdle();
|
||||
eSQRNetworkManagerInternalState m_state;
|
||||
eSQRNetworkManagerState m_stateExternal;
|
||||
bool m_nextIdleReasonIsFull;
|
||||
bool m_isHosting;
|
||||
SceNetInAddr m_localIPAddr;
|
||||
SceNpMatching2RoomMemberId m_localMemberId;
|
||||
SceNpMatching2RoomMemberId m_hostMemberId; // if we're not the host
|
||||
int m_localPlayerCount;
|
||||
int m_localPlayerJoined; // Client only, keep a count of how many local players we have confirmed as joined to the application
|
||||
SceNpMatching2RoomId m_room;
|
||||
unsigned char m_currentSmallId;
|
||||
int m_soc;
|
||||
bool m_offlineGame;
|
||||
bool m_offlineSQR;
|
||||
int m_resendExternalRoomDataCountdown;
|
||||
bool m_matching2initialised;
|
||||
// HelloSyncInfo m_inviteReceived[MAX_SIMULTANEOUS_INVITES];
|
||||
// int m_inviteIndex;
|
||||
// static HelloSyncInfo *m_gameBootInvite;
|
||||
// static HelloSyncInfo m_gameBootInvite_data;
|
||||
// bool m_doBootInviteCheck;
|
||||
bool m_isInSession;
|
||||
// static SceNpBasicAttachmentDataId s_lastInviteIdToRetry;
|
||||
static int m_adhocStatus;
|
||||
bool m_bLinkDisconnected;
|
||||
|
||||
private:
|
||||
|
||||
CRITICAL_SECTION m_csRoomSyncData;
|
||||
RoomSyncData m_roomSyncData;
|
||||
void *m_joinExtData;
|
||||
int m_joinExtDataSize;
|
||||
|
||||
std::vector<SQRNetworkPlayer *> m_vecTempPlayers;
|
||||
SQRNetworkPlayer *m_aRoomSlotPlayers[MAX_ONLINE_PLAYER_COUNT]; // Maps from the players in m_roomSyncData, to SQRNetworkPlayers
|
||||
void FindOrCreateNonNetworkPlayer(int slot, int playerType, SceNpMatching2RoomMemberId memberId, int localPlayerIdx, int smallId);
|
||||
|
||||
void MapRoomSlotPlayers(int roomSlotPlayerCount =-1);
|
||||
void UpdateRoomSyncUIDsFromPlayers();
|
||||
void UpdatePlayersFromRoomSyncUIDs();
|
||||
void LocalDataSend(SQRNetworkPlayer *playerFrom, SQRNetworkPlayer *playerTo, const void *data, unsigned int dataSize);
|
||||
int GetSessionIndex(SQRNetworkPlayer *player);
|
||||
|
||||
bool AddRemotePlayersAndSync( SceNpMatching2RoomMemberId memberId, int playerMask, bool *isFull = NULL );
|
||||
void RemoveRemotePlayersAndSync( SceNpMatching2RoomMemberId memberId, int mask );
|
||||
void RemoveNetworkPlayers( int mask );
|
||||
void SetLocalPlayersAndSync();
|
||||
void SyncRoomData();
|
||||
SceNpMatching2RequestId m_setRoomDataRequestId;
|
||||
SceNpMatching2RequestId m_setRoomIntDataRequestId;
|
||||
SceNpMatching2RequestId m_roomExtDataRequestId;
|
||||
|
||||
// Server context management
|
||||
bool GetMatchingContext(eSQRNetworkManagerInternalState asyncState);
|
||||
bool GetServerContext();
|
||||
bool GetServerContext_AdHoc();
|
||||
bool GetServerContext2();
|
||||
bool GetServerContext(SceNpMatching2ServerId serverId);
|
||||
void DeleteServerContext();
|
||||
bool SelectRandomServer();
|
||||
void ServerContextTick();
|
||||
int m_totalServerCount;
|
||||
int m_serverCount;
|
||||
SceNpMatching2ServerId *m_aServerId;
|
||||
SceNpMatching2ServerId m_serverId;
|
||||
bool m_serverContextValid;
|
||||
SceNpMatching2RequestId m_serverSearchRequestId;
|
||||
SceNpMatching2RequestId m_serverContextRequestId;
|
||||
|
||||
// Room creation management
|
||||
SceNpMatching2RequestId m_getWorldRequestId;
|
||||
SceNpMatching2RequestId m_createRoomRequestId;
|
||||
SceNpMatching2WorldId m_worldId;
|
||||
void RoomCreateTick();
|
||||
|
||||
// Room joining management
|
||||
SceNpMatching2RoomId m_roomToJoin;
|
||||
int m_localPlayerJoinMask;
|
||||
SceNpMatching2RequestId m_joinRoomRequestId;
|
||||
SceNpMatching2RequestId m_kickRequestId;
|
||||
|
||||
// Room leaving management
|
||||
SceNpMatching2RequestId m_leaveRoomRequestId;
|
||||
|
||||
// Adding extra network players management
|
||||
SceNpMatching2RequestId m_setRoomMemberInternalDataRequestId;
|
||||
|
||||
// Player state management
|
||||
void NetworkPlayerConnectionComplete(SQRNetworkPlayer *player);
|
||||
void NetworkPlayerSmallIdAllocated(SQRNetworkPlayer *player, unsigned char smallId);
|
||||
void NetworkPlayerInitialDataReceived(SQRNetworkPlayer *player,void *data);
|
||||
void NonNetworkPlayerComplete(SQRNetworkPlayer *player, unsigned char smallId);
|
||||
void HandlePlayerJoined(SQRNetworkPlayer *player);
|
||||
CRITICAL_SECTION m_csPlayerState;
|
||||
|
||||
// State and thread for managing basic event type messages
|
||||
C4JThread *m_basicEventThread;
|
||||
// SceKernelEqueue m_basicEventQueue;
|
||||
static int BasicEventThreadProc( void *lpParameter);
|
||||
|
||||
// State and storage for managing search for friends' games
|
||||
eSQRNetworkManagerFriendSearchState m_friendSearchState;
|
||||
SceNpMatching2ContextId m_matchingContext;
|
||||
bool m_matchingContextServerValid;
|
||||
bool m_matchingContextClientValid;
|
||||
SceNpMatching2RequestId m_friendSearchRequestId;
|
||||
unsigned int m_friendCount;
|
||||
// C4JThread *m_getFriendCountThread;
|
||||
// static int GetFriendsThreadProc( void* lpParameter );
|
||||
void FriendSearchTick();
|
||||
SceNpMatching2RequestId m_roomDataExternalListRequestId;
|
||||
void (* m_FriendSessionUpdatedFn)(bool success, void *pParam);
|
||||
void *m_pParamFriendSessionUpdated;
|
||||
void *m_pExtDataToUpdate;
|
||||
|
||||
// Results from searching for rooms that friends are playing in - 5 matched arrays to store their NpIds, rooms, servers, whether a room was found, and whether the external data had been received for the room. Also a count of how many elements are used in this array.
|
||||
class FriendSearchResult
|
||||
{
|
||||
public:
|
||||
SceNpId m_NpId;
|
||||
SceNetInAddr m_netAddr;
|
||||
// SceNpMatching2RoomId m_RoomId;
|
||||
// SceNpMatching2ServerId m_ServerId;
|
||||
bool m_RoomFound;
|
||||
void *m_RoomExtDataReceived;
|
||||
void* m_gameSessionData;
|
||||
RoomSyncData m_roomSyncData;
|
||||
};
|
||||
std::vector<FriendSearchResult> m_aFriendSearchResults;
|
||||
bool m_bFriendsSearchChanged;
|
||||
|
||||
// Rudp management and local players
|
||||
std::unordered_map<int,SQRNetworkPlayer *> m_RudpCtxToPlayerMap;
|
||||
std::unordered_map<int,SceNetInAddr> m_RudpCtxToIPAddrMap;
|
||||
|
||||
std::unordered_map<SceNetInAddr_t, SQRVoiceConnection*> m_NetAddrToVoiceConnectionMap;
|
||||
|
||||
bool CreateRudpConnections(SceNetInAddr peer);
|
||||
bool CreateVoiceRudpConnections(SceNpMatching2RoomId roomId, SceNpMatching2RoomMemberId peerMemberId, int playerMask);
|
||||
bool CreateSocket();
|
||||
SQRNetworkPlayer *GetPlayerFromRudpCtx(int rudpCtx);
|
||||
SceNetInAddr* GetIPAddrFromRudpCtx(int rudpCtx);
|
||||
SQRVoiceConnection* GetVoiceConnectionFromRudpCtx(int rudpCtx);
|
||||
|
||||
SQRNetworkPlayer *GetPlayerFromRoomMemberAndLocalIdx(int roomMember, int localIdx);
|
||||
SceNpMatching2RequestId m_roomMemberDataRequestId;
|
||||
|
||||
// Callbacks (for matching)
|
||||
bool RegisterCallbacks();
|
||||
void HandleMatchingContextStart();
|
||||
// #ifdef __PS3__
|
||||
// static void DefaultRequestCallback(SceNpMatching2ContextId id, SceNpMatching2RequestId reqId, SceNpMatching2Event event, SceNpMatching2EventKey eventKey, int errorCode, size_t dataSize, void *arg);
|
||||
// static void RoomEventCallback(SceNpMatching2ContextId id, SceNpMatching2RoomId roomId, SceNpMatching2Event event, SceNpMatching2EventKey eventKey, int errorCode, size_t dataSize, void *arg);
|
||||
// #else
|
||||
// static void DefaultRequestCallback(SceNpMatching2ContextId id, SceNpMatching2RequestId reqId, SceNpMatching2Event event, int errorCode, const void *data, void *arg);
|
||||
// static void RoomEventCallback(SceNpMatching2ContextId id, SceNpMatching2RoomId roomId, SceNpMatching2Event event, const void *data, void *arg);
|
||||
// #endif
|
||||
// static void SignallingCallback(SceNpMatching2ContextId ctxId, SceNpMatching2RoomId roomId, SceNpMatching2RoomMemberId peerMemberId, SceNpMatching2Event event, int error_code, void *arg);
|
||||
|
||||
// Callback for NpBasic
|
||||
static int BasicEventCallback(int event, int retCode, uint32_t reqId, void *arg);
|
||||
|
||||
// Callback for NpManager
|
||||
static void ManagerCallback(int event, int result, void *arg);
|
||||
|
||||
// Callback for sys util
|
||||
static void SysUtilCallback(uint64_t status, uint64_t param, void *userdata);
|
||||
void updateNetCheckDialog(); // get the status of the dialog and run any callbacks needed [CD - Added to match SQRNetworkManager_Vita]
|
||||
|
||||
// Callbacks for rudp
|
||||
static void RudpContextCallback(int ctx_id, int event_id, int error_code, void *arg);
|
||||
static int RudpEventCallback(int event_id, int soc, uint8_t const *data, size_t datalen, struct SceNetSockaddr const *addr, SceNetSocklen_t addrlen, void *arg);
|
||||
|
||||
// Callback for netctl
|
||||
static void NetCtlCallback(int eventType, void *arg);
|
||||
|
||||
// Methods to be called when the server context has been created
|
||||
void ServerContextValid_CreateRoom();
|
||||
void ServerContextValid_JoinRoom();
|
||||
|
||||
// Mask utilities
|
||||
int GetOldMask(SceNpMatching2RoomMemberId memberId);
|
||||
int GetAddedMask(int newMask, int oldMask);
|
||||
int GetRemovedMask(int newMask, int oldMask);
|
||||
|
||||
#ifndef _CONTENT_PACKAGE
|
||||
static bool aForceError[SNM_FORCE_ERROR_COUNT];
|
||||
#endif
|
||||
bool ForceErrorPoint(eSQRForceError err);
|
||||
|
||||
|
||||
static void MatchingEventHandler(int id, int event, SceNetInAddr* peer, int optlen, void *opt);
|
||||
|
||||
|
||||
public:
|
||||
static void AttemptPSNSignIn(int (*SignInCompleteCallbackFn)(void *pParam, bool bContinue, int pad), void *pParam, bool callIfFailed = false);
|
||||
static int (*s_SignInCompleteCallbackFn)(void *pParam, bool bContinue, int pad);
|
||||
static bool s_signInCompleteCallbackIfFailed;
|
||||
static void *s_SignInCompleteParam;
|
||||
|
||||
static int SetRichPresence(const void *data);
|
||||
void SetPresenceDataStartHostingGame();
|
||||
int GetJoiningReadyPercentage();
|
||||
|
||||
void startMatching();
|
||||
private:
|
||||
void UpdateRichPresenceCustomData(void *data, unsigned int dataBytes);
|
||||
static void TickRichPresence();
|
||||
static void SendLastPresenceInfo();
|
||||
void OnlineCheck();
|
||||
|
||||
bool CreateMatchingContext(bool bServer = false);
|
||||
void StopMatchingContext();
|
||||
|
||||
|
||||
static sce::Toolkit::NP::PresenceDetails s_lastPresenceInfo;
|
||||
static int s_resendPresenceCountdown;
|
||||
static bool s_presenceStatusDirty;
|
||||
static bool s_presenceDataDirty;
|
||||
static HelloSyncInfo s_lastPresenceSyncInfo;
|
||||
static HelloSyncInfo c_presenceSyncInfoNULL;
|
||||
static bool b_inviteRecvGUIRunning;
|
||||
// Debug
|
||||
static long long s_roomStartTime;
|
||||
|
||||
int m_hid;
|
||||
bool m_bIsInitialised;
|
||||
|
||||
};
|
||||
|
||||
4080
Minecraft.Client/PSVita/Network/SQRNetworkManager_Vita.cpp
Normal file
4080
Minecraft.Client/PSVita/Network/SQRNetworkManager_Vita.cpp
Normal file
File diff suppressed because it is too large
Load Diff
324
Minecraft.Client/PSVita/Network/SQRNetworkManager_Vita.h
Normal file
324
Minecraft.Client/PSVita/Network/SQRNetworkManager_Vita.h
Normal file
@@ -0,0 +1,324 @@
|
||||
#pragma once
|
||||
#include <np.h>
|
||||
#include <libnetctl.h>
|
||||
#include <net.h>
|
||||
#include <np_toolkit.h>
|
||||
|
||||
#include <queue>
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
#include "..\..\Common\Network\Sony\SQRNetworkManager.h"
|
||||
|
||||
class SQRNetworkPlayer;
|
||||
class ISQRNetworkManagerListener;
|
||||
class SonyVoiceChat_Vita;
|
||||
class SQRVoiceConnection;
|
||||
class C4JThread;
|
||||
|
||||
// This is the lowest level manager for providing network functionality on Sony platforms. This manages various network activities including the players within a gaming session.
|
||||
// The game shouldn't directly use this class, it is here to provide functionality required by PlatformNetworkManagerSony.
|
||||
|
||||
class SQRNetworkManager_Vita : public SQRNetworkManager
|
||||
{
|
||||
friend class SonyVoiceChat_Vita;
|
||||
friend class SQRNetworkPlayer;
|
||||
|
||||
static const eSQRNetworkManagerState m_INTtoEXTStateMappings[SNM_INT_STATE_COUNT];
|
||||
|
||||
public:
|
||||
SQRNetworkManager_Vita(ISQRNetworkManagerListener *listener);
|
||||
|
||||
// General
|
||||
void Tick();
|
||||
void Initialise();
|
||||
bool IsInitialised();
|
||||
void UnInitialise();
|
||||
void Terminate();
|
||||
eSQRNetworkManagerState GetState();
|
||||
bool IsHost();
|
||||
bool IsReadyToPlayOrIdle();
|
||||
bool IsInSession();
|
||||
|
||||
// Session management
|
||||
void CreateAndJoinRoom(int hostIndex, int localPlayerMask, void *extData, int extDataSize, bool offline);
|
||||
void UpdateExternalRoomData();
|
||||
bool FriendRoomManagerIsBusy();
|
||||
bool FriendRoomManagerSearch();
|
||||
bool FriendRoomManagerSearch2();
|
||||
int FriendRoomManagerGetCount();
|
||||
void FriendRoomManagerGetRoomInfo(int idx, SessionSearchResult *searchResult);
|
||||
bool JoinRoom(SessionSearchResult *searchResult, int localPlayerMask);
|
||||
bool JoinRoom(SceNpMatching2RoomId roomId, SceNpMatching2ServerId serverId, int localPlayerMask, const SQRNetworkManager_Vita::PresenceSyncInfo *presence);
|
||||
void StartGame();
|
||||
void LeaveRoom(bool bActuallyLeaveRoom);
|
||||
void EndGame();
|
||||
bool SessionHasSpace(int spaceRequired);
|
||||
bool AddLocalPlayerByUserIndex(int idx);
|
||||
bool RemoveLocalPlayerByUserIndex(int idx);
|
||||
void SendInviteGUI();
|
||||
static void RecvInviteGUI();
|
||||
void TickInviteGUI();
|
||||
|
||||
|
||||
|
||||
// void GetInviteDataAndProcess(SceNpBasicAttachmentDataId id);
|
||||
static bool UpdateInviteData(SQRNetworkManager_Vita::PresenceSyncInfo *invite);
|
||||
void GetExtDataForRoom( SceNpMatching2RoomId roomId, void *extData, void (* FriendSessionUpdatedFn)(bool success, void *pParam), void *pParam );
|
||||
|
||||
// Player retrieval
|
||||
int GetPlayerCount();
|
||||
int GetOnlinePlayerCount();
|
||||
SQRNetworkPlayer *GetPlayerByIndex(int idx);
|
||||
SQRNetworkPlayer *GetPlayerBySmallId(int idx);
|
||||
SQRNetworkPlayer *GetLocalPlayerByUserIndex(int idx);
|
||||
SQRNetworkPlayer *GetPlayerByXuid(PlayerUID xuid);
|
||||
SQRNetworkPlayer *GetHostPlayer();
|
||||
|
||||
void removePlayerFromVoiceChat(SQRNetworkPlayer* pPlayer);
|
||||
// Communication parameter storage
|
||||
static const SceNpCommunicationId* GetSceNpCommsId();
|
||||
static const SceNpCommunicationSignature* GetSceNpCommsSig();
|
||||
static const SceNpTitleId* GetSceNpTitleId();
|
||||
static const SceNpTitleSecret* GetSceNpTitleSecret();
|
||||
|
||||
static void GetInviteDataAndProcess(sce::Toolkit::NP::MessageAttachment* pInvite);
|
||||
static void GetJoinablePresenceDataAndProcess(SceAppUtilNpBasicJoinablePresenceParam* pJoinablePresenceData);
|
||||
static void ProcessJoinablePresenceData();
|
||||
static void TickJoinablePresenceData();
|
||||
|
||||
static int PSNSignInReturnedPresenceInvite(void* pParam, bool bContinue, int iPad);
|
||||
|
||||
|
||||
static bool m_bJoinablePresenceWaitingForOnline;
|
||||
static SceAppUtilNpBasicJoinablePresenceParam m_joinablePresenceParam;
|
||||
static bool m_bSendingInviteMessage;
|
||||
|
||||
private:
|
||||
void InitialiseAfterOnline();
|
||||
void ErrorHandlingTick();
|
||||
void UpdateOnlineStatus(int status) { m_onlineStatus = status; }
|
||||
int GetOnlineStatus() { return m_onlineStatus; }
|
||||
|
||||
ISQRNetworkManagerListener *m_listener;
|
||||
SQRNetworkPlayer *GetPlayerIfReady(SQRNetworkPlayer *player);
|
||||
|
||||
// Internal state
|
||||
void SetState(eSQRNetworkManagerInternalState state);
|
||||
void ResetToIdle();
|
||||
eSQRNetworkManagerInternalState m_state;
|
||||
eSQRNetworkManagerState m_stateExternal;
|
||||
bool m_nextIdleReasonIsFull;
|
||||
bool m_isHosting;
|
||||
SceNpMatching2RoomMemberId m_localMemberId;
|
||||
SceNpMatching2RoomMemberId m_hostMemberId; // if we're not the host
|
||||
int m_localPlayerCount;
|
||||
int m_localPlayerJoined; // Client only, keep a count of how many local players we have confirmed as joined to the application
|
||||
SceNpMatching2RoomId m_room;
|
||||
unsigned char m_currentSmallId;
|
||||
int m_soc;
|
||||
bool m_offlineGame;
|
||||
bool m_offlineSQR;
|
||||
int m_resendExternalRoomDataCountdown;
|
||||
bool m_matching2initialised;
|
||||
PresenceSyncInfo m_inviteReceived[MAX_SIMULTANEOUS_INVITES];
|
||||
int m_inviteIndex;
|
||||
static PresenceSyncInfo *m_gameBootInvite;
|
||||
static PresenceSyncInfo m_gameBootInvite_data;
|
||||
bool m_doBootInviteCheck;
|
||||
bool m_isInSession;
|
||||
// static SceNpBasicAttachmentDataId s_lastInviteIdToRetry;
|
||||
int m_onlineStatus;
|
||||
bool m_bLinkDisconnected;
|
||||
|
||||
|
||||
private:
|
||||
|
||||
CRITICAL_SECTION m_csRoomSyncData;
|
||||
RoomSyncData m_roomSyncData;
|
||||
void *m_joinExtData;
|
||||
int m_joinExtDataSize;
|
||||
|
||||
std::vector<SQRNetworkPlayer *> m_vecTempPlayers;
|
||||
SQRNetworkPlayer *m_aRoomSlotPlayers[MAX_ONLINE_PLAYER_COUNT]; // Maps from the players in m_roomSyncData, to SQRNetworkPlayers
|
||||
void FindOrCreateNonNetworkPlayer(int slot, int playerType, SceNpMatching2RoomMemberId memberId, int localPlayerIdx, int smallId);
|
||||
|
||||
void MapRoomSlotPlayers(int roomSlotPlayerCount =-1);
|
||||
void UpdateRoomSyncUIDsFromPlayers();
|
||||
void UpdatePlayersFromRoomSyncUIDs();
|
||||
void LocalDataSend(SQRNetworkPlayer *playerFrom, SQRNetworkPlayer *playerTo, const void *data, unsigned int dataSize);
|
||||
int GetSessionIndex(SQRNetworkPlayer *player);
|
||||
|
||||
bool AddRemotePlayersAndSync( SceNpMatching2RoomMemberId memberId, int playerMask, bool *isFull = NULL );
|
||||
void RemoveRemotePlayersAndSync( SceNpMatching2RoomMemberId memberId, int mask );
|
||||
void RemoveNetworkPlayers( int mask );
|
||||
void SetLocalPlayersAndSync();
|
||||
void SyncRoomData();
|
||||
SceNpMatching2RequestId m_setRoomDataRequestId;
|
||||
SceNpMatching2RequestId m_setRoomIntDataRequestId;
|
||||
SceNpMatching2RequestId m_roomExtDataRequestId;
|
||||
|
||||
// Server context management
|
||||
bool GetMatchingContext(eSQRNetworkManagerInternalState asyncState);
|
||||
bool GetServerContext();
|
||||
bool GetServerContext_AdHoc();
|
||||
bool GetServerContext2();
|
||||
bool GetServerContext(SceNpMatching2ServerId serverId);
|
||||
void DeleteServerContext();
|
||||
bool SelectRandomServer();
|
||||
void ServerContextTick();
|
||||
int m_totalServerCount;
|
||||
int m_serverCount;
|
||||
SceNpMatching2ServerId *m_aServerId;
|
||||
SceNpMatching2ServerId m_serverId;
|
||||
bool m_serverContextValid;
|
||||
SceNpMatching2RequestId m_serverSearchRequestId;
|
||||
SceNpMatching2RequestId m_serverContextRequestId;
|
||||
|
||||
// Room creation management
|
||||
SceNpMatching2RequestId m_getWorldRequestId;
|
||||
SceNpMatching2RequestId m_createRoomRequestId;
|
||||
SceNpMatching2WorldId m_worldId;
|
||||
void RoomCreateTick();
|
||||
|
||||
// Room joining management
|
||||
SceNpMatching2RoomId m_roomToJoin;
|
||||
int m_localPlayerJoinMask;
|
||||
SceNpMatching2RequestId m_joinRoomRequestId;
|
||||
SceNpMatching2RequestId m_kickRequestId;
|
||||
|
||||
// Room leaving management
|
||||
SceNpMatching2RequestId m_leaveRoomRequestId;
|
||||
|
||||
// Adding extra network players management
|
||||
SceNpMatching2RequestId m_setRoomMemberInternalDataRequestId;
|
||||
|
||||
// Player state management
|
||||
void NetworkPlayerConnectionComplete(SQRNetworkPlayer *player);
|
||||
void NetworkPlayerSmallIdAllocated(SQRNetworkPlayer *player, unsigned char smallId);
|
||||
void NetworkPlayerInitialDataReceived(SQRNetworkPlayer *player,void *data);
|
||||
void NonNetworkPlayerComplete(SQRNetworkPlayer *player, unsigned char smallId);
|
||||
void HandlePlayerJoined(SQRNetworkPlayer *player);
|
||||
CRITICAL_SECTION m_csPlayerState;
|
||||
|
||||
// State and thread for managing basic event type messages
|
||||
C4JThread *m_basicEventThread;
|
||||
// SceKernelEqueue m_basicEventQueue;
|
||||
static int BasicEventThreadProc( void *lpParameter);
|
||||
|
||||
// State and storage for managing search for friends' games
|
||||
eSQRNetworkManagerFriendSearchState m_friendSearchState;
|
||||
SceNpMatching2ContextId m_matchingContext;
|
||||
bool m_matchingContextValid;
|
||||
SceNpMatching2RequestId m_friendSearchRequestId;
|
||||
unsigned int m_friendCount;
|
||||
C4JThread *m_getFriendCountThread;
|
||||
static int GetFriendsThreadProc( void* lpParameter );
|
||||
void FriendSearchTick();
|
||||
SceNpMatching2RequestId m_roomDataExternalListRequestId;
|
||||
void (* m_FriendSessionUpdatedFn)(bool success, void *pParam);
|
||||
void *m_pParamFriendSessionUpdated;
|
||||
void *m_pExtDataToUpdate;
|
||||
|
||||
// Results from searching for rooms that friends are playing in - 5 matched arrays to store their NpIds, rooms, servers, whether a room was found, and whether the external data had been received for the room. Also a count of how many elements are used in this array.
|
||||
class FriendSearchResult
|
||||
{
|
||||
public:
|
||||
SceNpId m_NpId;
|
||||
SceNpMatching2RoomId m_RoomId;
|
||||
SceNpMatching2ServerId m_ServerId;
|
||||
bool m_RoomFound;
|
||||
void *m_RoomExtDataReceived;
|
||||
};
|
||||
std::vector<FriendSearchResult> m_aFriendSearchResults;
|
||||
|
||||
// Rudp management and local players
|
||||
std::unordered_map<int,SQRNetworkPlayer *> m_RudpCtxToPlayerMap;
|
||||
|
||||
std::unordered_map<SceNetInAddr_t, SQRVoiceConnection*> m_NetAddrToVoiceConnectionMap;
|
||||
|
||||
bool CreateRudpConnections(SceNpMatching2RoomId roomId, SceNpMatching2RoomMemberId peerMemberId, int playerMask, SceNpMatching2RoomMemberId playersPeerMemberId);
|
||||
bool CreateVoiceRudpConnections(SceNpMatching2RoomId roomId, SceNpMatching2RoomMemberId peerMemberId, int playerMask);
|
||||
bool CreateSocket();
|
||||
SQRNetworkPlayer *GetPlayerFromRudpCtx(int rudpCtx);
|
||||
SQRVoiceConnection* GetVoiceConnectionFromRudpCtx(int rudpCtx);
|
||||
|
||||
SQRNetworkPlayer *GetPlayerFromRoomMemberAndLocalIdx(int roomMember, int localIdx);
|
||||
SceNpMatching2RequestId m_roomMemberDataRequestId;
|
||||
|
||||
// Callbacks (for matching)
|
||||
bool RegisterCallbacks();
|
||||
static void ContextCallback(SceNpMatching2ContextId id, SceNpMatching2Event event, SceNpMatching2EventCause eventCause, int errorCode, void *arg);
|
||||
// #ifdef __PS3__
|
||||
// static void DefaultRequestCallback(SceNpMatching2ContextId id, SceNpMatching2RequestId reqId, SceNpMatching2Event event, SceNpMatching2EventKey eventKey, int errorCode, size_t dataSize, void *arg);
|
||||
// static void RoomEventCallback(SceNpMatching2ContextId id, SceNpMatching2RoomId roomId, SceNpMatching2Event event, SceNpMatching2EventKey eventKey, int errorCode, size_t dataSize, void *arg);
|
||||
// #else
|
||||
static void DefaultRequestCallback(SceNpMatching2ContextId id, SceNpMatching2RequestId reqId, SceNpMatching2Event event, int errorCode, const void *data, void *arg);
|
||||
static void RoomEventCallback(SceNpMatching2ContextId id, SceNpMatching2RoomId roomId, SceNpMatching2Event event, const void *data, void *arg);
|
||||
// #endif
|
||||
static void SignallingCallback(SceNpMatching2ContextId ctxId, SceNpMatching2RoomId roomId, SceNpMatching2RoomMemberId peerMemberId, SceNpMatching2Event event, int error_code, void *arg);
|
||||
|
||||
// Callback for NpBasic
|
||||
static int BasicEventCallback(int event, int retCode, uint32_t reqId, void *arg);
|
||||
|
||||
// Callback for NpManager
|
||||
static void ManagerCallback(int event, int result, void *arg);
|
||||
|
||||
// Callback for sys util
|
||||
static void SysUtilCallback(uint64_t status, uint64_t param, void *userdata);
|
||||
void updateNetCheckDialog(); // get the status of the dialog and run any callbacks needed
|
||||
|
||||
// Callbacks for rudp
|
||||
static void RudpContextCallback(int ctx_id, int event_id, int error_code, void *arg);
|
||||
static int RudpEventCallback(int event_id, int soc, uint8_t const *data, size_t datalen, struct SceNetSockaddr const *addr, SceNetSocklen_t addrlen, void *arg);
|
||||
|
||||
// Callback for netctl
|
||||
static void NetCtlCallback(int eventType, void *arg);
|
||||
|
||||
// Methods to be called when the server context has been created
|
||||
void ServerContextValid_CreateRoom();
|
||||
void ServerContextValid_JoinRoom();
|
||||
|
||||
// Mask utilities
|
||||
int GetOldMask(SceNpMatching2RoomMemberId memberId);
|
||||
int GetAddedMask(int newMask, int oldMask);
|
||||
int GetRemovedMask(int newMask, int oldMask);
|
||||
|
||||
#ifndef _CONTENT_PACKAGE
|
||||
static bool aForceError[SNM_FORCE_ERROR_COUNT];
|
||||
#endif
|
||||
bool ForceErrorPoint(eSQRForceError err);
|
||||
|
||||
public:
|
||||
static void AttemptPSNSignIn(int (*SignInCompleteCallbackFn)(void *pParam, bool bContinue, int pad), void *pParam, bool callIfFailed = false);
|
||||
static int (*s_SignInCompleteCallbackFn)(void *pParam, bool bContinue, int pad);
|
||||
static bool s_signInCompleteCallbackIfFailed;
|
||||
static void *s_SignInCompleteParam;
|
||||
|
||||
static int SetRichPresence(const void *data);
|
||||
void SetPresenceDataStartHostingGame();
|
||||
int GetJoiningReadyPercentage();
|
||||
static void SetPresenceFailedCallback();
|
||||
GameSessionUID GetHostUID() { return s_lastPresenceSyncInfo.hostPlayerUID; }
|
||||
private:
|
||||
static void UpdateRichPresenceCustomData(void *data, unsigned int dataBytes);
|
||||
static void TickRichPresence();
|
||||
static void SendLastPresenceInfo();
|
||||
void OnlineCheck();
|
||||
|
||||
static sce::Toolkit::NP::PresenceDetails s_lastPresenceInfo;
|
||||
static int s_resendPresenceCountdown;
|
||||
static bool s_presenceStatusDirty;
|
||||
static PresenceSyncInfo s_lastPresenceSyncInfo;
|
||||
static PresenceSyncInfo c_presenceSyncInfoNULL;
|
||||
static bool b_inviteRecvGUIRunning;
|
||||
// 4J-PB - so we can stop the crash when Iggy's LoadMovie is called from the ContextCallback
|
||||
static bool m_bCallPSNSignInCallback;
|
||||
// Debug
|
||||
static long long s_roomStartTime;
|
||||
|
||||
int m_hid;
|
||||
bool m_bIsInitialised;
|
||||
bool m_bShuttingDown;
|
||||
};
|
||||
|
||||
1519
Minecraft.Client/PSVita/Network/SonyCommerce_Vita.cpp
Normal file
1519
Minecraft.Client/PSVita/Network/SonyCommerce_Vita.cpp
Normal file
File diff suppressed because it is too large
Load Diff
204
Minecraft.Client/PSVita/Network/SonyCommerce_Vita.h
Normal file
204
Minecraft.Client/PSVita/Network/SonyCommerce_Vita.h
Normal file
@@ -0,0 +1,204 @@
|
||||
#pragma once
|
||||
|
||||
#include "Common\Network\Sony\SonyCommerce.h"
|
||||
#include <np_toolkit.h>
|
||||
#include <libsysmodule.h>
|
||||
#include <netcheck_dialog.h>
|
||||
|
||||
class SonyCommerce_Vita : public SonyCommerce
|
||||
{
|
||||
friend class PSVitaNPToolkit;
|
||||
enum State
|
||||
{
|
||||
e_state_noSession,
|
||||
e_state_creatingSession,
|
||||
e_state_createSessionDone,
|
||||
e_state_idle,
|
||||
|
||||
|
||||
};
|
||||
/// This enum is used to verify the current utility that is running
|
||||
enum Phase
|
||||
{
|
||||
e_phase_stopped = 0,
|
||||
e_phase_idle,
|
||||
e_phase_voucherRedeemPhase,
|
||||
e_phase_productBrowsePhase,
|
||||
e_phase_creatingSessionPhase,
|
||||
e_phase_checkoutPhase,
|
||||
e_phase_downloadListPhase
|
||||
};
|
||||
|
||||
enum Message
|
||||
{
|
||||
e_message_commerceNone,
|
||||
e_message_commerceCreateSession, ///< Create a commerce session
|
||||
e_message_commerceRecreateSession, ///< Recreate a commerce session
|
||||
e_message_commerceGetCategoryInfo, ///< Information about a category in the Store
|
||||
e_message_commerceGetProductList, ///< Get a list of products available in the Store
|
||||
e_message_commerceGetDetailedProductInfo, ///< Get a list of products available in the Store, with additional details
|
||||
e_message_commerceAddDetailedProductInfo, ///< Add additional details to a ProdcutInfo already retrieved
|
||||
e_message_commerceStoreProductBrowse, ///< Launches the Store to a specified product
|
||||
e_message_commerceUpgradeTrial, ///< Upgrade a trial to full game
|
||||
e_message_commerceRedeemVoucher, ///< Redeem a voucher code
|
||||
e_message_commerceGetEntitlementList, ///< Get a list of entitlements associated with the current PSN user.
|
||||
e_message_commerceConsumeEntitlement, ///< Consume an amount from a consumable entitlement.
|
||||
e_message_commerceCheckout, ///< Launch the Store checkout
|
||||
e_message_commerceDownloadList, ///< Launch the download list
|
||||
e_message_commerceCheckout_Game, ///< Launch the Store checkout
|
||||
e_message_commerceDownloadList_Game, ///< Launch the download list
|
||||
e_message_commerceInstallContent, ///< Install content that's downloaded from the background download manager
|
||||
e_message_commerceEnd ///< End commerce2 processing
|
||||
};
|
||||
|
||||
enum Event
|
||||
{
|
||||
e_event_none,
|
||||
e_event_commerceSessionCreated, ///< An event generated when a commerce session has successfully been created.
|
||||
e_event_commerceSessionRecreated, ///< An event generated when a commerce session has successfully been recreated.
|
||||
e_event_commerceSessionAborted, ///< An event generated when the creation of commerce session has been aborted.
|
||||
e_event_commerceGotCategoryInfo, ///< An event generated when some category information has been retrieved from the store.
|
||||
e_event_commerceGotProductList, ///< An event generated when a list of products that are available has been retrieved from the store.
|
||||
e_event_commerceGotDetailedProductInfo, ///< An event generated when some detailed product information has been retrieved from the store.
|
||||
e_event_commerceAddedDetailedProductInfo, ///< An event generated when some detailed product information has been retrieved from the store.
|
||||
e_event_commerceProductBrowseStarted, ///< An event generated when product overlay has started.
|
||||
e_event_commerceProductBrowseSuccess, ///< An event generated when a product browse was completed successfully, and the user purchased the product.
|
||||
e_event_commerceProductBrowseAborted, ///< An event generated when a product browse was aborted by the user (the user pressed back).
|
||||
e_event_commerceProductBrowseFinished, ///< An event generated when a product browse has finished and it is now safe to free memory.
|
||||
e_event_commerceVoucherInputStarted, ///< An event generated when a voucher code input overlay was started.
|
||||
e_event_commerceVoucherInputSuccess, ///< An event generated when a voucher code input completed successfully.
|
||||
e_event_commerceVoucherInputAborted, ///< An event generated when a voucher code input was aborted by the user (user pressed back).
|
||||
e_event_commerceVoucherInputFinished, ///< An event generated when a voucher code input has finished. It is now safe to free memory.
|
||||
e_event_commerceGotEntitlementList, ///< An event generated when a the list of entitlements has been received for the current user.
|
||||
e_event_commerceConsumedEntitlement, ///< An event generated when the has successfully consumed an entitlement.
|
||||
e_event_commerceCheckoutStarted, ///< An event generated when a store checkout overlay has started.
|
||||
e_event_commerceCheckoutSuccess, ///< An event generated when user has successfully purchased from the checkout.
|
||||
e_event_commerceCheckoutAborted, ///< An event generated when the checkout was aborted by the user (user pressed back).
|
||||
e_event_commerceCheckoutFinished, ///< An event generated when a store checkout overlay has finished.
|
||||
e_event_commerceDownloadListStarted, ///< An event generated when a download list overlay has started.
|
||||
e_event_commerceDownloadListSuccess, ///< An event generated when the user has ended the download list.
|
||||
e_event_commerceDownloadListFinished, ///< An event generated when a download list overlay has finished.
|
||||
e_event_commerceInstallContentStarted,
|
||||
e_event_commerceInstallContentFinished,
|
||||
e_event_commerceError ///< An event generated when a commerce error has occurred.
|
||||
};
|
||||
|
||||
static bool m_bLicenseChecked;
|
||||
static bool m_bCommerceInitialised;
|
||||
// static SceNpCommerce2SessionInfo m_sessionInfo;
|
||||
static State m_state;
|
||||
static int m_errorCode;
|
||||
static LPVOID m_callbackParam;
|
||||
static Event m_event;
|
||||
static Message m_message;
|
||||
// static uint32_t m_requestID;
|
||||
static void* m_receiveBuffer;
|
||||
static std::vector<ProductInfo> *m_pProductInfoList;
|
||||
static ProductInfoDetailed *m_pProductInfoDetailed;
|
||||
static ProductInfo *m_pProductInfo;
|
||||
static CategoryInfo* m_pCategoryInfo;
|
||||
static char* m_pCategoryID;
|
||||
static const char* m_pProductID;
|
||||
static std::queue<Message> m_messageQueue;
|
||||
static CallbackFunc m_callbackFunc;
|
||||
static CheckoutInputParams m_checkoutInputParams;
|
||||
static DownloadListInputParams m_downloadInputParams;
|
||||
// static sys_memory_container_t m_memContainer;
|
||||
static bool m_bUpgradingTrial;
|
||||
static C4JThread* m_tickThread;
|
||||
static CallbackFunc m_trialUpgradeCallbackFunc;
|
||||
static LPVOID m_trialUpgradeCallbackParam;
|
||||
static CRITICAL_SECTION m_queueLock;
|
||||
static bool m_bLicenseInstalled;
|
||||
static bool m_bDownloadsPending;
|
||||
static bool m_bDownloadsReady;
|
||||
static bool m_bInstallingContent;
|
||||
static int m_iClearDLCCountdown;
|
||||
static bool m_bPurchasabilityUpdated;
|
||||
|
||||
static Message m_lastMessage;
|
||||
static void runCallback()
|
||||
{
|
||||
assert(m_callbackFunc);
|
||||
CallbackFunc func = m_callbackFunc;
|
||||
m_callbackFunc = NULL;
|
||||
if(func)
|
||||
func(m_callbackParam, m_errorCode);
|
||||
m_errorCode = SCE_OK;
|
||||
}
|
||||
static void setCallback(CallbackFunc cb,LPVOID lpParam)
|
||||
{
|
||||
assert(m_callbackFunc == NULL);
|
||||
m_callbackFunc = cb;
|
||||
m_callbackParam = lpParam;
|
||||
}
|
||||
|
||||
|
||||
static uint32_t m_contextId; ///< The npcommerce2 context ID
|
||||
static bool m_contextCreated; ///< npcommerce2 context ID created?
|
||||
static Phase m_currentPhase; ///< Current commerce2 util
|
||||
// static char m_commercebuffer[SCE_NP_COMMERCE2_RECV_BUF_SIZE];
|
||||
|
||||
|
||||
|
||||
static void commerce2Handler( const sce::Toolkit::NP::Event& event);
|
||||
static void processMessage();
|
||||
static void processEvent();
|
||||
|
||||
static int createContext();
|
||||
static int createSession();
|
||||
static int recreateSession();
|
||||
static void setError(int err) { m_errorCode = err; }
|
||||
static int getCategoryInfo(CategoryInfo *info, char *categoryId);
|
||||
static int getProductList(std::vector<ProductInfo>* productList, char *categoryId);
|
||||
static int getDetailedProductInfo(ProductInfoDetailed *info, const char *productId, char *categoryId);
|
||||
static int addDetailedProductInfo(ProductInfo *info, const char *productId, char *categoryId);
|
||||
static int checkout(CheckoutInputParams ¶ms);
|
||||
static int downloadList(DownloadListInputParams ¶ms);
|
||||
static int checkout_game(CheckoutInputParams ¶ms);
|
||||
static int downloadList_game(DownloadListInputParams ¶ms);
|
||||
static int installContent();
|
||||
static void UpgradeTrialCallback1(LPVOID lpParam,int err);
|
||||
static void UpgradeTrialCallback2(LPVOID lpParam,int err);
|
||||
static void Delete();
|
||||
static void copyCategoryInfo(CategoryInfo *pInfo, sce::Toolkit::NP::CategoryInfo *pNPInfo);
|
||||
static void copyProductList(std::vector<ProductInfo>* pProductList, std::vector<sce::Toolkit::NP::ProductInfo>* pNPProductList);
|
||||
static void copyDetailedProductInfo(ProductInfoDetailed *pInfo, sce::Toolkit::NP::ProductInfoDetailed* pNPInfo);
|
||||
static void copyAddDetailedProductInfo(ProductInfo *pInfo, sce::Toolkit::NP::ProductInfoDetailed* pNPInfo);
|
||||
static void InstallContentCallback(LPVOID lpParam,int err);
|
||||
|
||||
static int commerceEnd();
|
||||
// static int upgradeTrial();
|
||||
|
||||
static int TickLoop(void* lpParam);
|
||||
//void Test();
|
||||
|
||||
static void Init();
|
||||
static int Shutdown();
|
||||
|
||||
static void CheckForTrialUpgradeKey_Callback(LPVOID param, bool bFullVersion);
|
||||
|
||||
public:
|
||||
static void checkBackgroundDownloadStatus();
|
||||
|
||||
virtual void CreateSession(CallbackFunc cb, LPVOID lpParam);
|
||||
virtual void CloseSession();
|
||||
|
||||
virtual void GetCategoryInfo(CallbackFunc cb, LPVOID lpParam, CategoryInfo *info, const char *categoryId);
|
||||
virtual void GetProductList(CallbackFunc cb, LPVOID lpParam, std::vector<ProductInfo>* productList, const char *categoryId);
|
||||
virtual void GetDetailedProductInfo(CallbackFunc cb, LPVOID lpParam, ProductInfoDetailed* productInfoDetailed, const char *productId, const char *categoryId);
|
||||
virtual void AddDetailedProductInfo( CallbackFunc cb, LPVOID lpParam, ProductInfo* productInfo, const char *productId, const char *categoryId );
|
||||
virtual void Checkout(CallbackFunc cb, LPVOID lpParam, const char* skuID);
|
||||
virtual void Checkout(CallbackFunc cb, LPVOID lpParam, ProductInfo* productInfo);
|
||||
virtual void DownloadAlreadyPurchased(CallbackFunc cb, LPVOID lpParam, const char* skuID);
|
||||
virtual void Checkout_Game(CallbackFunc cb, LPVOID lpParam, const char* skuID);
|
||||
virtual void DownloadAlreadyPurchased_Game(CallbackFunc cb, LPVOID lpParam, const char* skuID);
|
||||
static void InstallContent(CallbackFunc cb, LPVOID lpParam);
|
||||
virtual void UpgradeTrial(CallbackFunc cb, LPVOID lpParam);
|
||||
virtual void CheckForTrialUpgradeKey();
|
||||
virtual bool LicenseChecked();
|
||||
|
||||
static bool getPurchasabilityUpdated();
|
||||
static bool getDLCUpgradePending();
|
||||
|
||||
};
|
||||
271
Minecraft.Client/PSVita/Network/SonyHttp_Vita.cpp
Normal file
271
Minecraft.Client/PSVita/Network/SonyHttp_Vita.cpp
Normal file
@@ -0,0 +1,271 @@
|
||||
#include "stdafx.h"
|
||||
#include "SonyHttp_Vita.h"
|
||||
|
||||
static const int sc_SSLHeapSize = (304 * 1024U);
|
||||
static const int sc_HTTPHeapSize = (80 * 1024);
|
||||
static const int sc_NetHeapSize = (16 * 1024);
|
||||
|
||||
#define TEST_USER_AGENT "SimpleSample/1.00"
|
||||
|
||||
|
||||
// int SonyHttp_Vita::libnetMemId = 0;
|
||||
int SonyHttp_Vita::libsslCtxId = 0;
|
||||
int SonyHttp_Vita::libhttpCtxId = 0;
|
||||
bool SonyHttp_Vita:: bInitialised = false;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool SonyHttp_Vita::init()
|
||||
{
|
||||
// int ret = sceNetPoolCreate("simple", sc_NetHeapSize, 0);
|
||||
// assert(ret >= 0);
|
||||
// libnetMemId = ret;
|
||||
|
||||
// int ret = sceSslInit(sc_SSLHeapSize);
|
||||
// assert(ret >= 0 || ret == SCE_SSL_ERROR_ALREADY_INITED);
|
||||
// libsslCtxId = ret;
|
||||
//
|
||||
// ret = sceHttpInit(sc_HTTPHeapSize);
|
||||
// assert(ret >= 0 || ret == SCE_HTTP_ERROR_ALREADY_INITED);
|
||||
// libhttpCtxId = ret;
|
||||
|
||||
bInitialised = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
void SonyHttp_Vita::shutdown()
|
||||
{
|
||||
PSVITA_STUBBED;
|
||||
// int ret = sceHttpTerm(libhttpCtxId);
|
||||
// assert(ret == SCE_OK);
|
||||
//
|
||||
// ret = sceSslTerm(libsslCtxId);
|
||||
// assert(ret == SCE_OK);
|
||||
//
|
||||
// /* libnet */
|
||||
// ret = sceNetPoolDestroy(libnetMemId);
|
||||
// assert(ret == SCE_OK);
|
||||
|
||||
}
|
||||
void SonyHttp_Vita::printSslError(SceInt32 sslErr, SceUInt32 sslErrDetail)
|
||||
{
|
||||
switch (sslErr)
|
||||
{
|
||||
case (SCE_HTTPS_ERROR_CERT): /* Verify error */
|
||||
/* Internal error at verifying certificate*/
|
||||
if (sslErrDetail & SCE_HTTPS_ERROR_SSL_INTERNAL){
|
||||
app.DebugPrintf("ssl verify error: unexpcted error\n");
|
||||
}
|
||||
/* Error of server certificate or CA certificate */
|
||||
if (sslErrDetail & SCE_HTTPS_ERROR_SSL_INVALID_CERT){
|
||||
app.DebugPrintf("ssl verify error: invalid server cert or CA cert\n");
|
||||
}
|
||||
/* Server hostname and server certificate are mismatched*/
|
||||
if (sslErrDetail & SCE_HTTPS_ERROR_SSL_CN_CHECK){
|
||||
app.DebugPrintf("ssl verify error: invalid server hostname\n");
|
||||
}
|
||||
/* Server certificate or CA certificate is expired.*/
|
||||
if (sslErrDetail & SCE_HTTPS_ERROR_SSL_NOT_AFTER_CHECK){
|
||||
app.DebugPrintf("ssl verify error: server cert or CA cert had expired\n");
|
||||
}
|
||||
/* Server certificate or CA certificate is before validated.*/
|
||||
if (sslErrDetail & SCE_HTTPS_ERROR_SSL_NOT_BEFORE_CHECK){
|
||||
app.DebugPrintf("ssl verify error: server cert or CA cert isn't validated yet.\n");
|
||||
}
|
||||
/* Unknown CA error */
|
||||
if (sslErrDetail & SCE_HTTPS_ERROR_SSL_UNKNOWN_CA){
|
||||
app.DebugPrintf("ssl verify error: unknown CA\n");
|
||||
}
|
||||
break;
|
||||
case (SCE_HTTPS_ERROR_HANDSHAKE): /* fail to ssl-handshake */
|
||||
app.DebugPrintf("ssl error: handshake error\n");
|
||||
break;
|
||||
case (SCE_HTTPS_ERROR_IO): /* Error of Socket IO */
|
||||
app.DebugPrintf("ssl error: io error\n");
|
||||
break;
|
||||
case (SCE_HTTP_ERROR_OUT_OF_MEMORY): /* Out of memory*/
|
||||
app.DebugPrintf("ssl error: out of memory\n");
|
||||
break;
|
||||
case (SCE_HTTPS_ERROR_INTERNAL): /* Unexpected Internal Error*/
|
||||
app.DebugPrintf("ssl error: unexpcted error\n");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void SonyHttp_Vita::printSslCertInfo(SceSslCert *sslCert)
|
||||
{
|
||||
SceInt32 ret;
|
||||
const SceUChar8 *sboData;
|
||||
SceSize sboLen, counter;
|
||||
|
||||
ret = sceSslGetSerialNumber(sslCert, &sboData, &sboLen);
|
||||
if (ret < 0){
|
||||
app.DebugPrintf ("sceSslGetSerialNumber() returns 0x%x\n", ret);
|
||||
} else {
|
||||
app.DebugPrintf("Serial number=");
|
||||
for (counter = 0; counter < sboLen; counter++){
|
||||
app.DebugPrintf("%02X", sboData[counter]);
|
||||
}
|
||||
app.DebugPrintf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool SonyHttp_Vita::getDataFromURL( const char* szURL, void** ppOutData, int* pDataSize)
|
||||
{
|
||||
if(!bInitialised)
|
||||
return false;
|
||||
return http_get(szURL, ppOutData, pDataSize);
|
||||
}
|
||||
|
||||
|
||||
int SonyHttp_Vita::sslCallback(SceUInt32 verifyErr, SceSslCert * const sslCert[], SceInt32 certNum, void *userArg)
|
||||
{
|
||||
SceInt32 i;
|
||||
(void)userArg;
|
||||
|
||||
app.DebugPrintf("Ssl callback:\n");
|
||||
app.DebugPrintf("\tbase tmpl[%x]\n", (SceInt32)userArg);
|
||||
|
||||
if (verifyErr != 0){
|
||||
printSslError((SceInt32)SCE_HTTPS_ERROR_CERT, verifyErr);
|
||||
}
|
||||
for (i = 0; i < certNum; i++){
|
||||
printSslCertInfo(sslCert[i]);
|
||||
}
|
||||
if (verifyErr == 0){
|
||||
return SCE_OK;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
bool SonyHttp_Vita::http_get_close(bool bOK, SceInt32 tmplId, SceInt32 connId, SceInt32 reqId)
|
||||
{
|
||||
SceInt32 ret;
|
||||
if (reqId > 0)
|
||||
{
|
||||
ret = sceHttpDeleteRequest(reqId);
|
||||
assert(ret >= 0);
|
||||
}
|
||||
if (connId > 0)
|
||||
{
|
||||
ret = sceHttpDeleteConnection(connId);
|
||||
assert(ret >= 0);
|
||||
}
|
||||
if (tmplId > 0)
|
||||
{
|
||||
ret = sceHttpDeleteTemplate(tmplId);
|
||||
assert(ret >= 0);
|
||||
}
|
||||
assert(bOK);
|
||||
return bOK;
|
||||
}
|
||||
|
||||
bool SonyHttp_Vita::http_get(const char *targetUrl, void** ppOutData, int* pDataSize)
|
||||
{
|
||||
SceInt32 ret, tmplId=0, connId=0, reqId=0, statusCode;
|
||||
SceULong64 contentLength=0;
|
||||
SceBool finFlag=SCE_FALSE;
|
||||
SceUChar8* recvBuf;
|
||||
|
||||
ret = sceHttpCreateTemplate(TEST_USER_AGENT, SCE_HTTP_VERSION_1_1, SCE_TRUE);
|
||||
if (ret < 0)
|
||||
{
|
||||
app.DebugPrintf("sceHttpCreateTemplate() error: 0x%08X\n", ret);
|
||||
return http_get_close(false, tmplId, connId, reqId);
|
||||
}
|
||||
tmplId = ret;
|
||||
|
||||
/* Perform http_get without server verification */
|
||||
ret = sceHttpsDisableOption(SCE_HTTPS_FLAG_SERVER_VERIFY);
|
||||
if (ret < 0)
|
||||
{
|
||||
app.DebugPrintf("sceHttpsDisableOption() error: 0x%08X\n", ret);
|
||||
return http_get_close(false, tmplId, connId, reqId);
|
||||
}
|
||||
|
||||
/* Register SSL callback */
|
||||
ret = sceHttpsSetSslCallback(tmplId, sslCallback, (void*)&tmplId);
|
||||
if (ret < 0)
|
||||
{
|
||||
app.DebugPrintf("sceHttpsSetSslCallback() error: 0x%08X\n", ret);
|
||||
return http_get_close(false, tmplId, connId, reqId);
|
||||
}
|
||||
|
||||
ret = sceHttpCreateConnectionWithURL(tmplId, targetUrl, SCE_TRUE);
|
||||
if (ret < 0)
|
||||
{
|
||||
app.DebugPrintf("sceHttpCreateConnectionWithURL() error: 0x%08X\n", ret);
|
||||
return http_get_close(false, tmplId, connId, reqId);
|
||||
}
|
||||
connId = ret;
|
||||
|
||||
ret = sceHttpCreateRequestWithURL(connId, SCE_HTTP_METHOD_GET, targetUrl, 0);
|
||||
if (ret < 0)
|
||||
{
|
||||
app.DebugPrintf("sceHttpCreateRequestWithURL() error: 0x%08X\n", ret);
|
||||
return http_get_close(false, tmplId, connId, reqId);
|
||||
}
|
||||
reqId = ret;
|
||||
|
||||
ret = sceHttpSendRequest(reqId, NULL, 0);
|
||||
if (ret < 0)
|
||||
{
|
||||
app.DebugPrintf("sceHttpSendRequest() error: 0x%08X\n", ret);
|
||||
return http_get_close(false, tmplId, connId, reqId);
|
||||
}
|
||||
|
||||
ret = sceHttpGetStatusCode(reqId, &statusCode);
|
||||
if (ret < 0)
|
||||
{
|
||||
app.DebugPrintf("sceHttpGetStatusCode() error: 0x%08X\n", ret);
|
||||
return http_get_close(false, tmplId, connId, reqId);
|
||||
}
|
||||
app.DebugPrintf("response code = %d\n", statusCode);
|
||||
|
||||
if(statusCode == 200)
|
||||
{
|
||||
ret = sceHttpGetResponseContentLength(reqId, &contentLength);
|
||||
if(ret < 0)
|
||||
{
|
||||
app.DebugPrintf("sceHttpGetContentLength() error: 0x%08X\n", ret);
|
||||
return http_get_close(false, tmplId, connId, reqId);
|
||||
}
|
||||
else
|
||||
{
|
||||
app.DebugPrintf("Content-Length = %lu\n", contentLength);
|
||||
}
|
||||
recvBuf = new SceUChar8[contentLength+1];
|
||||
int bufferLeft = contentLength+1;
|
||||
SceUChar8* pCurrBuffPos = recvBuf;
|
||||
int totalBytesRead = 0;
|
||||
while(finFlag != SCE_TRUE)
|
||||
{
|
||||
ret = sceHttpReadData(reqId, pCurrBuffPos, bufferLeft);
|
||||
if (ret < 0)
|
||||
{
|
||||
app.DebugPrintf("\n sceHttpReadData() failed 0x%08X\n", ret);
|
||||
return http_get_close(false, tmplId, connId, reqId);
|
||||
}
|
||||
else if (ret == 0)
|
||||
{
|
||||
finFlag = SCE_TRUE;
|
||||
}
|
||||
app.DebugPrintf("\n sceHttpReadData() read %d bytes\n", ret);
|
||||
pCurrBuffPos += ret;
|
||||
totalBytesRead += ret;
|
||||
bufferLeft -= ret;
|
||||
}
|
||||
}
|
||||
|
||||
*ppOutData = recvBuf;
|
||||
*pDataSize = contentLength;
|
||||
return http_get_close(true, tmplId, connId, reqId);
|
||||
}
|
||||
26
Minecraft.Client/PSVita/Network/SonyHttp_Vita.h
Normal file
26
Minecraft.Client/PSVita/Network/SonyHttp_Vita.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
|
||||
#include <libhttp.h>
|
||||
|
||||
class SonyHttp_Vita
|
||||
{
|
||||
static int sslCallback(SceUInt32 verifyErr, SceSslCert * const sslCert[], SceInt32 certNum, void *userArg);
|
||||
static bool http_get(const char *targetUrl, void** ppOutData, int* pDataSize);
|
||||
static bool http_get_close(bool bOK, SceInt32 tmplId, SceInt32 connId, SceInt32 reqId);
|
||||
|
||||
static void printSslError(SceInt32 sslErr, SceUInt32 sslErrDetail);
|
||||
static void printSslCertInfo(SceSslCert *sslCert);
|
||||
|
||||
// static int libnetMemId;
|
||||
static int libsslCtxId;
|
||||
static int libhttpCtxId;
|
||||
|
||||
static bool bInitialised;
|
||||
|
||||
public:
|
||||
bool init();
|
||||
void shutdown();
|
||||
bool getDataFromURL(const char* szURL, void** ppOutData, int* pDataSize);
|
||||
|
||||
static int getHTTPContextID() { return libhttpCtxId; }
|
||||
};
|
||||
398
Minecraft.Client/PSVita/Network/SonyRemoteStorage_Vita.cpp
Normal file
398
Minecraft.Client/PSVita/Network/SonyRemoteStorage_Vita.cpp
Normal file
@@ -0,0 +1,398 @@
|
||||
#include "stdafx.h"
|
||||
|
||||
#include "SonyRemoteStorage_Vita.h"
|
||||
#include "SonyHttp_Vita.h"
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
#include <stdlib.h>
|
||||
// #include <cell/sysmodule.h>
|
||||
// #include <cell/http.h>
|
||||
// #include <cell/ssl.h>
|
||||
// #include <netex/net.h>
|
||||
// #include <netex/libnetctl.h>
|
||||
// #include <np.h>
|
||||
// #include <sysutil/sysutil_common.h>
|
||||
// #include <sys/timer.h>
|
||||
// #include <sys/paths.h>
|
||||
// #include <sysutil\sysutil_savedata.h>
|
||||
|
||||
|
||||
|
||||
|
||||
#define AUTH_SCOPE "psn:s2s"
|
||||
#define CLIENT_ID "969e9d21-527c-4c22-b539-f8e479f690bc"
|
||||
static SceRemoteStorageData s_getDataOutput;
|
||||
|
||||
|
||||
void SonyRemoteStorage_Vita::staticInternalCallback(const SceRemoteStorageEvent event, int32_t retCode, void * userData)
|
||||
{
|
||||
((SonyRemoteStorage_Vita*)userData)->internalCallback(event, retCode);
|
||||
}
|
||||
|
||||
void SonyRemoteStorage_Vita::internalCallback(const SceRemoteStorageEvent event, int32_t retCode)
|
||||
{
|
||||
m_lastErrorCode = retCode;
|
||||
|
||||
switch(event)
|
||||
{
|
||||
case ERROR_OCCURRED:
|
||||
app.DebugPrintf("An error occurred with retCode: 0x%x \n", retCode);
|
||||
m_status = e_error;
|
||||
// shutdown(); // removed, as the remote storage lib now tries to reconnect if an error has occurred
|
||||
runCallback();
|
||||
m_bTransferStarted = false;
|
||||
break;
|
||||
|
||||
case GET_DATA_RESULT:
|
||||
if(retCode >= 0)
|
||||
{
|
||||
app.DebugPrintf("Get Data success \n");
|
||||
m_status = e_getDataSucceeded;
|
||||
}
|
||||
else
|
||||
{
|
||||
app.DebugPrintf("An error occurred while Get Data was being processed. retCode: 0x%x \n", retCode);
|
||||
m_status = e_error;
|
||||
}
|
||||
runCallback();
|
||||
m_bTransferStarted = false;
|
||||
break;
|
||||
|
||||
case GET_DATA_PROGRESS:
|
||||
app.DebugPrintf("Get data progress: %i%%\n", retCode);
|
||||
m_status = e_getDataInProgress;
|
||||
m_dataProgress = retCode;
|
||||
m_startTime = System::currentTimeMillis();
|
||||
break;
|
||||
|
||||
case GET_STATUS_RESULT:
|
||||
if(retCode >= 0)
|
||||
{
|
||||
app.DebugPrintf("Get Status success \n");
|
||||
app.DebugPrintf("Remaining Syncs for this user: %llu\n", outputGetStatus->remainingSyncs);
|
||||
app.DebugPrintf("Number of files on the cloud: %d\n", outputGetStatus->numFiles);
|
||||
for(int i = 0; i < outputGetStatus->numFiles; i++)
|
||||
{
|
||||
app.DebugPrintf("\n*** File %d information: ***\n", (i + 1));
|
||||
app.DebugPrintf("File name: %s \n", outputGetStatus->data[i].fileName);
|
||||
app.DebugPrintf("File description: %s \n", outputGetStatus->data[i].fileDescription);
|
||||
app.DebugPrintf("MD5 Checksum: %s \n", outputGetStatus->data[i].md5Checksum);
|
||||
app.DebugPrintf("Size of the file: %u bytes \n", outputGetStatus->data[i].fileSize);
|
||||
app.DebugPrintf("Timestamp: %s \n", outputGetStatus->data[i].timeStamp);
|
||||
app.DebugPrintf("Visibility: \"%s\" \n", (outputGetStatus->data[i].visibility == 0)?"Private":((outputGetStatus->data[i].visibility == 1)?"Public read only":"Public read and write"));
|
||||
}
|
||||
m_status = e_getStatusSucceeded;
|
||||
}
|
||||
else
|
||||
{
|
||||
app.DebugPrintf("An error occurred while Get Status was being processed. retCode: 0x%x \n", retCode);
|
||||
m_status = e_error;
|
||||
}
|
||||
runCallback();
|
||||
break;
|
||||
|
||||
case PSN_SIGN_IN_REQUIRED:
|
||||
app.DebugPrintf("User's PSN sign-in through web browser is required \n");
|
||||
m_status = e_signInRequired;
|
||||
runCallback();
|
||||
break;
|
||||
|
||||
case SET_DATA_RESULT:
|
||||
if(retCode >= 0)
|
||||
{
|
||||
app.DebugPrintf("Set Data success \n");
|
||||
m_status = e_setDataSucceeded;
|
||||
}
|
||||
else
|
||||
{
|
||||
app.DebugPrintf("An error occurred while Set Data was being processed. retCode: 0x%x \n", retCode);
|
||||
m_status = e_error;
|
||||
}
|
||||
runCallback();
|
||||
m_bTransferStarted = false;
|
||||
break;
|
||||
|
||||
case SET_DATA_PROGRESS:
|
||||
app.DebugPrintf("Set data progress: %i%%\n", retCode);
|
||||
m_status = e_setDataInProgress;
|
||||
m_dataProgress = retCode;
|
||||
|
||||
break;
|
||||
|
||||
case USER_ACCOUNT_LINKED:
|
||||
app.DebugPrintf("User's account has been linked with PSN \n");
|
||||
m_bInitialised = true;
|
||||
m_status = e_accountLinked;
|
||||
runCallback();
|
||||
break;
|
||||
|
||||
case WEB_BROWSER_RESULT:
|
||||
app.DebugPrintf("This function is not used on PS Vita, as the account will be linked, it is not needed to open a browser to link it \n");
|
||||
assert(0);
|
||||
break;
|
||||
|
||||
default:
|
||||
app.DebugPrintf("This should never happen \n");
|
||||
assert(0);
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
bool SonyRemoteStorage_Vita::init(CallbackFunc cb, LPVOID lpParam)
|
||||
{
|
||||
int ret = 0;
|
||||
int reqId = 0;
|
||||
|
||||
m_callbackFunc = cb;
|
||||
m_callbackParam = lpParam;
|
||||
m_lastErrorCode = SCE_OK;
|
||||
|
||||
if(m_bInitialised)
|
||||
{
|
||||
internalCallback(USER_ACCOUNT_LINKED, 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
ret = sceNpAuthInit();
|
||||
if(ret < 0 && ret != SCE_NP_AUTH_ERROR_ALREADY_INITIALIZED)
|
||||
{
|
||||
app.DebugPrintf("sceNpAuthInit failed 0x%x\n", ret);
|
||||
return false;
|
||||
}
|
||||
|
||||
ret = sceNpAuthCreateOAuthRequest();
|
||||
if (ret < 0)
|
||||
{
|
||||
app.DebugPrintf("Couldn't create auth request 0x%x\n", ret);
|
||||
return false;
|
||||
}
|
||||
|
||||
reqId = ret;
|
||||
|
||||
SceNpClientId clientId;
|
||||
memset(&clientId, 0x0, sizeof(clientId));
|
||||
|
||||
// SceNpAuthorizationCode authCode;
|
||||
// memset(&authCode, 0x0, sizeof(authCode));
|
||||
|
||||
SceNpAuthGetAuthorizationCodeParameter authParams;
|
||||
memset(&authParams, 0x0, sizeof(authParams));
|
||||
|
||||
authParams.size = sizeof(authParams);
|
||||
authParams.pScope = AUTH_SCOPE;
|
||||
|
||||
memcpy(clientId.id, CLIENT_ID, strlen(CLIENT_ID));
|
||||
authParams.pClientId = &clientId;
|
||||
|
||||
int issuerId = 0;
|
||||
// ret = sceNpAuthGetAuthorizationCode(reqId, &authParams, &authCode, &issuerId);
|
||||
// if (ret < 0)
|
||||
// {
|
||||
// app.DebugPrintf("Failed to get auth code 0x%x\n", ret);
|
||||
// sceNpAuthDeleteOAuthRequest(reqId);
|
||||
// return false;
|
||||
// }
|
||||
|
||||
ret = sceNpAuthDeleteOAuthRequest(reqId);
|
||||
if (ret < 0)
|
||||
{
|
||||
app.DebugPrintf("Couldn't delete auth request 0x%x\n", ret);
|
||||
return false;
|
||||
}
|
||||
|
||||
SceRemoteStorageInitParams params;
|
||||
|
||||
params.callback = SonyRemoteStorage_Vita::staticInternalCallback;
|
||||
params.userData = this;
|
||||
params.thread.threadAffinity = SCE_KERNEL_THREAD_CPU_AFFINITY_MASK_DEFAULT;
|
||||
params.thread.threadPriority = SCE_KERNEL_DEFAULT_PRIORITY_USER;
|
||||
// memcpy(params.authCode, authCode.code, SCE_NP_AUTHORIZATION_CODE_MAX_LEN);
|
||||
strcpy(params.clientId, CLIENT_ID);
|
||||
params.timeout.connectMs = 30 * 1000; //30 seconds is the default
|
||||
params.timeout.resolveMs = 30 * 1000; //30 seconds is the default
|
||||
params.timeout.receiveMs = 120 * 1000; //120 seconds is the default
|
||||
params.timeout.sendMs = 120 * 1000; //120 seconds is the default
|
||||
params.pool.memPoolSize = 7 * 1024 * 1024;
|
||||
if(m_memPoolBuffer == NULL)
|
||||
m_memPoolBuffer = malloc(params.pool.memPoolSize);
|
||||
params.pool.memPoolBuffer = m_memPoolBuffer;
|
||||
|
||||
SceRemoteStorageAbortReqParams abortParams;
|
||||
|
||||
ret = sceRemoteStorageInit(params);
|
||||
if(ret >= 0)
|
||||
{
|
||||
abortParams.requestId = ret;
|
||||
app.DebugPrintf("Session will be created \n");
|
||||
}
|
||||
else if(ret == SCE_REMOTE_STORAGE_ERROR_ALREADY_INITIALISED)
|
||||
{
|
||||
app.DebugPrintf("Session already created \n");
|
||||
runCallback();
|
||||
}
|
||||
else
|
||||
{
|
||||
app.DebugPrintf("Error creating session: 0x%x \n", ret);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool SonyRemoteStorage_Vita::getRemoteFileInfo(SceRemoteStorageStatus* pInfo, CallbackFunc cb, LPVOID lpParam)
|
||||
{
|
||||
m_callbackFunc = cb;
|
||||
m_callbackParam = lpParam;
|
||||
outputGetStatus = pInfo;
|
||||
|
||||
SceRemoteStorageStatusReqParams params;
|
||||
reqId = sceRemoteStorageGetStatus(params, outputGetStatus);
|
||||
m_status = e_getStatusInProgress;
|
||||
|
||||
if(reqId >= 0)
|
||||
{
|
||||
app.DebugPrintf("Get Status request sent \n");
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
app.DebugPrintf("Error sending Get Status request: 0x%x \n", reqId);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void SonyRemoteStorage_Vita::abort()
|
||||
{
|
||||
m_bAborting = true;
|
||||
app.DebugPrintf("Aborting...\n");
|
||||
if(m_bTransferStarted)
|
||||
{
|
||||
app.DebugPrintf("transfer has started so we'll call sceRemoteStorageAbort...\n");
|
||||
|
||||
SceRemoteStorageAbortReqParams params;
|
||||
params.requestId = reqId;
|
||||
int ret = sceRemoteStorageAbort(params);
|
||||
|
||||
if(ret >= 0)
|
||||
{
|
||||
app.DebugPrintf("Abort request done \n");
|
||||
}
|
||||
else
|
||||
{
|
||||
app.DebugPrintf("Error in Abort request: 0x%x \n", ret);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool SonyRemoteStorage_Vita::setDataInternal()
|
||||
{
|
||||
// CompressSaveData(); // check if we need to re-save the file compressed first
|
||||
|
||||
snprintf(m_saveFilename, sizeof(m_saveFilename), "%s:%s/GAMEDATA.bin", "savedata0", m_setDataSaveInfo->UTF8SaveFilename);
|
||||
strcpy(m_saveFileDesc, m_setDataSaveInfo->UTF8SaveTitle);
|
||||
m_status = e_setDataInProgress;
|
||||
|
||||
|
||||
SceRemoteStorageSetDataReqParams params;
|
||||
params.visibility = PUBLIC_READ_WRITE;
|
||||
strcpy(params.pathLocation, m_saveFilename);
|
||||
sprintf(params.fileName, getRemoteSaveFilename());
|
||||
|
||||
DescriptionData descData;
|
||||
ZeroMemory(&descData, sizeof(DescriptionData));
|
||||
descData.m_platform[0] = SAVE_FILE_PLATFORM_LOCAL & 0xff;
|
||||
descData.m_platform[1] = (SAVE_FILE_PLATFORM_LOCAL >> 8) & 0xff;
|
||||
descData.m_platform[2] = (SAVE_FILE_PLATFORM_LOCAL >> 16) & 0xff;
|
||||
descData.m_platform[3] = (SAVE_FILE_PLATFORM_LOCAL >> 24)& 0xff;
|
||||
|
||||
if(m_thumbnailData)
|
||||
{
|
||||
unsigned int uiHostOptions;
|
||||
bool bHostOptionsRead;
|
||||
DWORD uiTexturePack;
|
||||
char seed[22];
|
||||
app.GetImageTextData(m_thumbnailData, m_thumbnailDataSize,(unsigned char *)seed, uiHostOptions, bHostOptionsRead, uiTexturePack);
|
||||
|
||||
__int64 iSeed = strtoll(seed,NULL,10);
|
||||
char seedHex[17];
|
||||
sprintf(seedHex,"%016llx",iSeed);
|
||||
memcpy(descData.m_seed,seedHex,16); // Don't copy null
|
||||
|
||||
// Save the host options that this world was last played with
|
||||
char hostOptions[9];
|
||||
sprintf(hostOptions,"%08x",uiHostOptions);
|
||||
memcpy(descData.m_hostOptions,hostOptions,8); // Don't copy null
|
||||
|
||||
// Save the texture pack id
|
||||
char texturePack[9];
|
||||
sprintf(texturePack,"%08x",uiTexturePack);
|
||||
memcpy(descData.m_texturePack,texturePack,8); // Don't copy null
|
||||
}
|
||||
|
||||
memcpy(descData.m_saveNameUTF8, m_saveFileDesc, strlen(m_saveFileDesc)+1); // plus null
|
||||
memcpy(params.fileDescription, &descData, sizeof(descData));
|
||||
|
||||
|
||||
if(m_bAborting)
|
||||
{
|
||||
runCallback();
|
||||
return false;
|
||||
}
|
||||
reqId = sceRemoteStorageSetData(params);
|
||||
|
||||
app.DebugPrintf("\n*******************************\n");
|
||||
if(reqId >= 0)
|
||||
{
|
||||
app.DebugPrintf("Set Data request sent \n");
|
||||
m_bTransferStarted = true;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
app.DebugPrintf("Error sending Set Data request: 0x%x \n", reqId);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool SonyRemoteStorage_Vita::getData( const char* remotePath, const char* localPath, CallbackFunc cb, LPVOID lpParam )
|
||||
{
|
||||
m_callbackFunc = cb;
|
||||
m_callbackParam = lpParam;
|
||||
|
||||
SceRemoteStorageGetDataReqParams params;
|
||||
sprintf(params.pathLocation, "savedata0:%s/GAMEDATA.bin", localPath);
|
||||
// strcpy(params.pathLocation, localPath);
|
||||
// strcpy(params.fileName, "/test/small.txt");
|
||||
strcpy(params.fileName, remotePath);
|
||||
memset(¶ms.psVitaSaveDataSlot, 0, sizeof(params.psVitaSaveDataSlot));
|
||||
SceRemoteStorageData s_getDataOutput;
|
||||
reqId = sceRemoteStorageGetData(params, &s_getDataOutput);
|
||||
|
||||
app.DebugPrintf("\n*******************************\n");
|
||||
if(reqId >= 0)
|
||||
{
|
||||
app.DebugPrintf("Get Data request sent \n");
|
||||
m_bTransferStarted = true;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
app.DebugPrintf("Error sending Get Data request: 0x%x \n", reqId);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void SonyRemoteStorage_Vita::runCallback()
|
||||
{
|
||||
assert(m_callbackFunc);
|
||||
if(m_callbackFunc)
|
||||
{
|
||||
m_callbackFunc(m_callbackParam, m_status, m_lastErrorCode);
|
||||
}
|
||||
m_lastErrorCode = SCE_OK;
|
||||
}
|
||||
43
Minecraft.Client/PSVita/Network/SonyRemoteStorage_Vita.h
Normal file
43
Minecraft.Client/PSVita/Network/SonyRemoteStorage_Vita.h
Normal file
@@ -0,0 +1,43 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
#include "Common\Network\Sony\SonyRemoteStorage.h"
|
||||
|
||||
class SonyRemoteStorage_Vita : public SonyRemoteStorage
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
virtual bool init(CallbackFunc cb, LPVOID lpParam);
|
||||
|
||||
virtual bool getRemoteFileInfo(SceRemoteStorageStatus* pInfo, CallbackFunc cb, LPVOID lpParam);
|
||||
virtual bool getData(const char* remotePath, const char* localPath, CallbackFunc cb, LPVOID lpParam);
|
||||
|
||||
virtual void abort();
|
||||
virtual bool setDataInternal();
|
||||
|
||||
private:
|
||||
int reqId;
|
||||
void * psnTicket;
|
||||
size_t psnTicketSize;
|
||||
bool m_waitingForTicket;
|
||||
bool initialized;
|
||||
SceRemoteStorageStatus* outputGetStatus;
|
||||
SceRemoteStorageData outputGetData;
|
||||
|
||||
int32_t m_lastErrorCode;
|
||||
int m_getDataProgress;
|
||||
int m_setDataProgress;
|
||||
char m_saveFilename[SCE_REMOTE_STORAGE_DATA_NAME_MAX_LEN];
|
||||
char m_saveFileDesc[SCE_REMOTE_STORAGE_DATA_DESCRIPTION_MAX_LEN];
|
||||
char m_remoteFilename[SCE_REMOTE_STORAGE_DATA_NAME_MAX_LEN];
|
||||
|
||||
|
||||
static void staticInternalCallback(const SceRemoteStorageEvent event, int32_t retCode, void * userData);
|
||||
void internalCallback(const SceRemoteStorageEvent event, int32_t retCode);
|
||||
|
||||
void runCallback();
|
||||
|
||||
|
||||
};
|
||||
|
||||
1092
Minecraft.Client/PSVita/Network/SonyVoiceChat_Vita.cpp
Normal file
1092
Minecraft.Client/PSVita/Network/SonyVoiceChat_Vita.cpp
Normal file
File diff suppressed because it is too large
Load Diff
222
Minecraft.Client/PSVita/Network/SonyVoiceChat_Vita.h
Normal file
222
Minecraft.Client/PSVita/Network/SonyVoiceChat_Vita.h
Normal file
@@ -0,0 +1,222 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <voice.h>
|
||||
#include "Common/Network/Sony/SQRNetworkPlayer.h"
|
||||
|
||||
static const int sc_maxVoiceDataSize = 2048;
|
||||
|
||||
|
||||
class VoicePacket
|
||||
{
|
||||
static const int MAX_LOCAL_PLAYER_COUNT = 1;
|
||||
|
||||
public:
|
||||
struct Flags
|
||||
{
|
||||
bool m_bTalking : 1;
|
||||
bool m_bHasMicConnected : 1;
|
||||
};
|
||||
|
||||
Flags m_localPlayerFlags[MAX_LOCAL_PLAYER_COUNT];
|
||||
uint32_t m_frameSendIndex;
|
||||
uint32_t m_numFrames;
|
||||
uint32_t m_checkSum;
|
||||
uint32_t m_playerIndexFlags;
|
||||
char m_data[sc_maxVoiceDataSize];
|
||||
|
||||
static int getPacketSize(int dataSize) { return (uint64_t)&((VoicePacket*)0)->m_data[dataSize];}
|
||||
void setChecksum(int dataSize)
|
||||
{
|
||||
m_checkSum = 0;
|
||||
for(int i=0;i<dataSize;i++)
|
||||
m_checkSum += m_data[i];
|
||||
}
|
||||
bool verifyData(int packetSize, int frameSize)
|
||||
{
|
||||
if(m_numFrames == 0)
|
||||
return false;
|
||||
int dataSize = m_numFrames*frameSize;
|
||||
if(packetSize != getPacketSize(dataSize))
|
||||
return false;
|
||||
int checkSum = 0;
|
||||
for(int i=0;i<dataSize;i++)
|
||||
checkSum += m_data[i];
|
||||
if(checkSum != m_checkSum)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// read-write-safe ring buffer implementation: does not use mutex protection
|
||||
// the writer thread changes pointer <buf_free>,
|
||||
// the reader thread changes pointer <buf_full>
|
||||
class RingBuffer
|
||||
{
|
||||
public:
|
||||
RingBuffer(int sizeBytes);
|
||||
~RingBuffer() { delete buffer; }
|
||||
void Reset(void) { buf_full = buf_free = 0; }
|
||||
unsigned int DataSize(void) { return (buf_free - buf_full); }
|
||||
int Write(char* data, int len_);
|
||||
int Read(char* data, int max_bytes_);
|
||||
int getDataSize() { return buf_free - buf_full; }
|
||||
void ResetByWriter(void) { buf_free = buf_full; }
|
||||
void ResetByReader(void) { buf_full = buf_free; }
|
||||
|
||||
private:
|
||||
char* buffer;
|
||||
unsigned int buf_size;
|
||||
unsigned int buf_full;
|
||||
unsigned int buf_free;
|
||||
};
|
||||
|
||||
|
||||
static const int sc_ringBufferSize = 16384;
|
||||
|
||||
class SQRLocalVoiceDevice
|
||||
{
|
||||
public:
|
||||
uint32_t m_headsetPort;
|
||||
uint32_t m_microphonePort;
|
||||
// int32_t m_micAudioDevicePort;
|
||||
uint8_t m_localConnections[4]; // connection between this devices mic and other local player's headsets
|
||||
bool m_bChatRestricted;
|
||||
|
||||
bool m_bValid;
|
||||
|
||||
public:
|
||||
SQRLocalVoiceDevice()
|
||||
: m_headsetPort(SCE_VOICE_INVALID_PORT_ID)
|
||||
, m_microphonePort(SCE_VOICE_INVALID_PORT_ID)
|
||||
, m_bValid(false)
|
||||
// , m_micAudioDevicePort(-1)
|
||||
{
|
||||
for(int i=0;i<4;i++)
|
||||
m_localConnections[i] = 0;
|
||||
}
|
||||
|
||||
void init(bool bChatRestricted);
|
||||
|
||||
void shutdown();
|
||||
bool isValid() { return m_bValid; }
|
||||
// void setBitRate()
|
||||
// {
|
||||
// int err = sceVoiceSetBitRate(uint32_t portId,
|
||||
// SceVoiceBitRate bitrate
|
||||
// );
|
||||
// }
|
||||
};
|
||||
|
||||
#define VOICE_ENCODED_FORMAT SCEVOICE_BITRATE_7300
|
||||
|
||||
|
||||
|
||||
class SQRVoiceConnection
|
||||
{
|
||||
static const int MAX_LOCAL_PLAYER_COUNT = 1;
|
||||
|
||||
static const int SNP_MAX_PAYLOAD = 1346; // This is the default RUDP payload size - if we want to change this we'll need to use cellRudpSetOption to set something else & adjust segment size
|
||||
class QueuedSendBlock
|
||||
{
|
||||
public:
|
||||
unsigned char *start;
|
||||
unsigned char *end;
|
||||
unsigned char *current;
|
||||
};
|
||||
|
||||
std::queue<QueuedSendBlock> m_sendQueue;
|
||||
CRITICAL_SECTION m_csQueue;
|
||||
|
||||
public:
|
||||
int m_rudpCtx;
|
||||
bool m_bConnected;
|
||||
uint32_t m_voiceInPort; // 1 input port per connection, incoming UDP packets are written to each of these, and then they're connected out to all headsets
|
||||
int m_headsetConnectionMask; // 1 bit per player, if the headset connection has been made
|
||||
RingBuffer m_playRingBuffer;
|
||||
SceNpMatching2RoomMemberId m_remoteRoomMemberId; // Assigned by Matching2 lib, we can use to indicate which machine this player belongs to (note - 16 bits)
|
||||
std::queue<VoicePacket> m_receivedVoicePackets;
|
||||
CRITICAL_SECTION m_csPacketQueue;
|
||||
VoicePacket::Flags m_remotePlayerFlags[MAX_LOCAL_PLAYER_COUNT];
|
||||
uint32_t m_nextExpectedFrameIndex;
|
||||
bool m_bFlaggedForShutdown;
|
||||
SQRVoiceConnection(int rudpCtx, SceNpMatching2RoomMemberId remoteRoomMemberId);
|
||||
~SQRVoiceConnection();
|
||||
|
||||
void SendInternal(const void *data, unsigned int dataSize);
|
||||
void SendMoreInternal();
|
||||
void readRemoteData();
|
||||
bool getNextPacket(VoicePacket& packet);
|
||||
void addPacket(VoicePacket& packet);
|
||||
|
||||
|
||||
};
|
||||
|
||||
class SonyVoiceChat_Vita
|
||||
{
|
||||
public:
|
||||
|
||||
static void init();
|
||||
static void start();
|
||||
static void shutdown();
|
||||
static void tick();
|
||||
static void checkFinished();
|
||||
static void setEnabled(bool bEnabled);
|
||||
static bool hasMicConnected(SQRNetworkPlayer* pNetPlayer);
|
||||
static bool isTalking(SQRNetworkPlayer* pNetPlayer);
|
||||
static void mute(bool bMute); //Turn chat audio on or off
|
||||
static void mutePlayer(const SceNpMatching2RoomMemberId member_id, bool bMute); //Turn chat audio from a specified player on or off;
|
||||
static void muteLocalPlayer(bool bMute); //Turn microphone input on or off;
|
||||
|
||||
static bool isMuted();
|
||||
static bool isMutedPlayer(const PlayerUID& memberUID);
|
||||
static bool isMutedLocalPlayer(); //Turn microphone input on or off;
|
||||
|
||||
static void initLocalPlayer(int playerIndex);
|
||||
|
||||
static SQRVoiceConnection* addRemoteConnection(int RudpCxt, SceNpMatching2RoomMemberId peerMemberId);
|
||||
static void connectPlayer(SQRVoiceConnection* pConnection, int playerIndex);
|
||||
static void connectPlayerToAll(int playerIndex);
|
||||
static void disconnectLocalPlayer(int localIdx);
|
||||
static void disconnectRemoteConnection( SQRVoiceConnection* pVoice );
|
||||
|
||||
static void VoiceEventCallback( SceVoiceEventData* pEvent );
|
||||
|
||||
static std::vector<SQRVoiceConnection*> m_remoteConnections;
|
||||
static void connectPorts(uint32_t inPort, uint32_t outPort);
|
||||
static void disconnectPorts(uint32_t inPort, uint32_t outPort);
|
||||
static void makeLocalConnections();
|
||||
static void breakLocalConnections(int playerIdx);
|
||||
|
||||
static void sendAllVoiceData();
|
||||
static void playAllReceivedData();
|
||||
|
||||
static void sendPCMMicData();
|
||||
static SQRVoiceConnection* getVoiceConnectionFromRoomMemberID(SceNpMatching2RoomMemberId roomMemberID);
|
||||
|
||||
static SQRVoiceConnection* GetVoiceConnectionFromRudpCtx(int RudpCtx);
|
||||
static void setConnected(int RudpCtx);
|
||||
|
||||
private:
|
||||
|
||||
static const int MAX_LOCAL_PLAYER_COUNT = 1;
|
||||
|
||||
static bool m_bVoiceStarted;
|
||||
static int m_numLocalDevicesConnected;
|
||||
static SQRLocalVoiceDevice m_localVoiceDevices[MAX_LOCAL_PLAYER_COUNT];
|
||||
|
||||
static uint32_t m_voiceOutPort; // single output port that all local devices are mixed to, and then sent out to all other remote machines
|
||||
|
||||
static RingBuffer m_recordRingBuffer;
|
||||
static RingBuffer m_playRingBuffer;
|
||||
static VoicePacket::Flags m_localPlayerFlags[MAX_LOCAL_PLAYER_COUNT];
|
||||
static bool m_forceSendPacket; // force a packet across the network, even if there's no data, so we can update flags
|
||||
static bool m_bInitialised;
|
||||
static CRITICAL_SECTION m_csRemoteConnections;
|
||||
|
||||
|
||||
};
|
||||
Reference in New Issue
Block a user