first commit
This commit is contained in:
490
Minecraft.Client/Orbis/Network/Orbis_NPToolkit.cpp
Normal file
490
Minecraft.Client/Orbis/Network/Orbis_NPToolkit.cpp
Normal file
@@ -0,0 +1,490 @@
|
||||
#include "stdafx.h"
|
||||
|
||||
#include "Orbis_NPToolkit.h"
|
||||
#include "Orbis\ps4__np_conf.h"
|
||||
#include "Orbis/Network/SonyCommerce_Orbis.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
|
||||
|
||||
// Singleton
|
||||
OrbisNPToolkit NPToolkit;
|
||||
sce::Toolkit::NP::Utilities::Future< sce::Toolkit::NP::NpSessionInformation > OrbisNPToolkit::sm_createJoinFuture;
|
||||
sce::Toolkit::NP::NpSessionInformation OrbisNPToolkit::m_currentSessionInfo;
|
||||
sce::Toolkit::NP::Utilities::Future<sce::Toolkit::NP::MessageAttachment> OrbisNPToolkit::m_messageData;
|
||||
|
||||
|
||||
void OrbisNPToolkit::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_Orbis::SetPresenceFailedCallback();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void OrbisNPToolkit::coreCallback( const sce::Toolkit::NP::Event& event )
|
||||
{
|
||||
switch (event.event)
|
||||
{
|
||||
case sce::Toolkit::NP::Event::enetDown:
|
||||
app.DebugPrintf("Online: Received core callback: Network down \n");
|
||||
ProfileManager.SetNetworkStatus(false);
|
||||
break;
|
||||
case sce::Toolkit::NP::Event::enetUp:
|
||||
app.DebugPrintf("Online: Received core callback: Network up \n");
|
||||
ProfileManager.SetNetworkStatus(true);
|
||||
break;
|
||||
case sce::Toolkit::NP::Event::loggedIn:
|
||||
app.DebugPrintf("Online: Received core callback: PSN sign in \n");
|
||||
assert(event.userInformation.state == SCE_NP_STATE_SIGNED_IN);
|
||||
ProfileManager.SignedInPSNStateCallback(event.userInformation.userId, event.userInformation.state, &event.userInformation.npId);
|
||||
break;
|
||||
case sce::Toolkit::NP::Event::loggedOut:
|
||||
app.DebugPrintf("Online: Received core callback: PSN sign out \n");
|
||||
assert(event.userInformation.state == SCE_NP_STATE_SIGNED_OUT);
|
||||
ProfileManager.SignedInPSNStateCallback(event.userInformation.userId, event.userInformation.state, &event.userInformation.npId);
|
||||
break;
|
||||
default:
|
||||
app.DebugPrintf("Online: Received core callback: event Num: %d \n", event.event);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void OrbisNPToolkit::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:
|
||||
// Menu::Profile::sceNpToolkitCallback(event);
|
||||
// break;
|
||||
// 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);
|
||||
break;
|
||||
// case sce::Toolkit::NP::ServiceType::inGameMessage:
|
||||
// Menu::Messaging::sceNpToolkitCallback(event);
|
||||
// break;
|
||||
|
||||
case sce::Toolkit::NP::ServiceType::commerce:
|
||||
SonyCommerce_Orbis::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 OrbisNPToolkit::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 OrbisNPToolkit::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());
|
||||
|
||||
UINT uiIDA[1] = { IDS_OK };
|
||||
|
||||
switch(m_messageData.getError())
|
||||
{
|
||||
case SCE_NP_ERROR_LATEST_PATCH_PKG_EXIST:
|
||||
case SCE_NP_ERROR_LATEST_PATCH_PKG_DOWNLOADED:
|
||||
app.ShowPatchAvailableError();
|
||||
break;
|
||||
case SCE_NP_ERROR_AGE_RESTRICTION:
|
||||
default:
|
||||
ui.RequestMessageBox(IDS_ONLINE_SERVICE_TITLE, IDS_CONTENT_RESTRICTION, uiIDA, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
void OrbisNPToolkit::messagingCallback( const sce::Toolkit::NP::Event& event)
|
||||
{
|
||||
switch(event.event)
|
||||
{
|
||||
case sce::Toolkit::NP::Event::messageSent: ///< An event generated when a message has been sent.
|
||||
app.DebugPrintf("sce::Toolkit::NP::Event::messageSent\n");
|
||||
SQRNetworkManager_Orbis::s_bInviteDialogRunning = false;
|
||||
break;
|
||||
case sce::Toolkit::NP::Event::messageError: ///< An event generated when a message failed to be received or sent.
|
||||
app.DebugPrintf("sce::Toolkit::NP::Event::messageError\n");
|
||||
SQRNetworkManager_Orbis::s_bInviteDialogRunning = false;
|
||||
break;
|
||||
case sce::Toolkit::NP::Event::messageDialogTerminated: ///< An event generated when a message dialog box is terminated.
|
||||
app.DebugPrintf("sce::Toolkit::NP::Event::messageDialogTerminated\n");
|
||||
SQRNetworkManager_Orbis::s_bInviteDialogRunning = false;
|
||||
break;
|
||||
//case sce::Toolkit::NP::Event::messageRetrieved: ///< An event generated when a message attachment has been retrieved.
|
||||
//case sce::Toolkit::NP::Event::messageInGameDataReceived: ///< An event generated when in-game data is received.
|
||||
//case sce::Toolkit::NP::Event::messageInGameDataRetrievalDone: ///< An event generated when in-game data retrieval is complete.
|
||||
|
||||
// case sce::Toolkit::NP::Event::messageAttachmentReceived: ///< An event generated when a message with a data attachment has been received.
|
||||
// case sce::Toolkit::NP::Event::messageAttachmentOpened: ///< An event generated when a message with a data attachment has been opened (and the sysutil GUI is closed).
|
||||
// case sce::Toolkit::NP::Event::messageInviteReceived: ///< An event generated when a message with an invite has been received.
|
||||
// case sce::Toolkit::NP::Event::messageInviteAccepted: ///< An event generated when a message with an invite has been accepted via ToolkitNp (and the sysutil GUI is closed).
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
void OrbisNPToolkit::init()
|
||||
{
|
||||
// MenuApp menuApp;
|
||||
|
||||
sce::Toolkit::NP::NpTitleId nptTitleId;
|
||||
nptTitleId.setTitleSecret(*SQRNetworkManager_Orbis::GetSceNpTitleId(), *SQRNetworkManager_Orbis::GetSceNpTitleSecret());
|
||||
sce::Toolkit::NP::CommunicationId commsIds(s_npCommunicationId, s_npCommunicationPassphrase, s_npCommunicationSignature);
|
||||
sce::Toolkit::NP::Parameters params(sceNpToolkitCallback,nptTitleId);
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
// Get network status and inform library
|
||||
sce::Toolkit::NP::Utilities::Future<sce::Toolkit::NP::NetStateBasic> netStateFuture = sce::Toolkit::NP::Utilities::Future<sce::Toolkit::NP::NetStateBasic>();
|
||||
sce::Toolkit::NP::NetInfo::Interface::getNetInfo(&netStateFuture);
|
||||
|
||||
// Wait for the net state (< 5ms)
|
||||
while (netStateFuture.isBusy())
|
||||
{
|
||||
Sleep(1);
|
||||
}
|
||||
|
||||
if (netStateFuture.hasResult())
|
||||
{
|
||||
sce::Toolkit::NP::NetStateBasic *netState = netStateFuture.get();
|
||||
ProfileManager.SetNetworkStatus(netState->connectionStatus == SCE_NET_CTL_STATE_IPOBTAINED);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Error message means we're disconnected
|
||||
ProfileManager.SetNetworkStatus(false);
|
||||
}
|
||||
|
||||
// // 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 OrbisNPToolkit::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 OrbisNPToolkit::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 OrbisNPToolkit::leaveNPSession()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void OrbisNPToolkit::getMessageData(SceNpGameCustomDataEventParam* paramData)
|
||||
{
|
||||
|
||||
sce::Toolkit::NP::GameCustomDataGameDataRequest req;
|
||||
SceUserServiceUserId userId = SCE_USER_SERVICE_USER_ID_INVALID;
|
||||
int ret = sceUserServiceGetInitialUser(&userId);
|
||||
if( ret < 0 ) {
|
||||
//Error handling
|
||||
}
|
||||
|
||||
req.itemId = paramData->itemId;
|
||||
req.userInfo.userId = userId;
|
||||
ret = sce::Toolkit::NP::GameCustomData::Interface::getGameData(&req, &m_messageData);
|
||||
if( ret < 0 ) {
|
||||
//Error handling
|
||||
} else {
|
||||
//Error handling
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
//
|
||||
// sce::Toolkit::NP::GameDataRequest req;
|
||||
// SceUserServiceUserId userId = SCE_USER_SERVICE_USER_ID_INVALID;
|
||||
// int ret = sceUserServiceGetInitialUser(&userId);
|
||||
// if( ret < 0 ) {
|
||||
// //Error handling
|
||||
// }
|
||||
//
|
||||
// req.itemId = ItemID ;
|
||||
// req.userInfo.userId = userId;
|
||||
// sce::Toolkit::NP::Utilities::Future<sce::Toolkit::NP::MessageAttachment> actualMessage;
|
||||
// ret = sce::Toolkit::NP::GameCustomData::Interface::getGameData(&req,&actualMessage,false);
|
||||
// if( ret < 0 ) {
|
||||
// //Error handling
|
||||
// } else {
|
||||
// //Error handling
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// app.DebugPrintf("Session Invitation \n");
|
||||
// sce::Toolkit::NP::ReceiveMessageRequest request;
|
||||
// request.eventParamData = paramData;
|
||||
// request.msgType = SCE_TOOLKIT_NP_MESSAGE_TYPE_CUSTOM_DATA;
|
||||
// sceUserServiceGetInitialUser(&request.userInfo.userId);
|
||||
// sce::Toolkit::NP::Messaging::Interface::retrieveMessageAttachmentFromEvent(&request,&m_messageData);
|
||||
}
|
||||
34
Minecraft.Client/Orbis/Network/Orbis_NPToolkit.h
Normal file
34
Minecraft.Client/Orbis/Network/Orbis_NPToolkit.h
Normal file
@@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
|
||||
#include <np_toolkit.h>
|
||||
#include <np_toolkit/game_custom_data_interface.h>
|
||||
|
||||
|
||||
class OrbisNPToolkit
|
||||
{
|
||||
public:
|
||||
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 sessionsCallback( const sce::Toolkit::NP::Event& event);
|
||||
static void gameCustomDataCallback( const sce::Toolkit::NP::Event& event);
|
||||
static void messagingCallback( 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(SceNpGameCustomDataEventParam* 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;
|
||||
|
||||
};
|
||||
|
||||
// Singleton
|
||||
extern OrbisNPToolkit NPToolkit;
|
||||
|
||||
54
Minecraft.Client/Orbis/Network/PsPlusUpsellWrapper_Orbis.cpp
Normal file
54
Minecraft.Client/Orbis/Network/PsPlusUpsellWrapper_Orbis.cpp
Normal file
@@ -0,0 +1,54 @@
|
||||
#include "stdafx.h"
|
||||
#include "PsPlusUpsellWrapper_Orbis.h"
|
||||
|
||||
PsPlusUpsellWrapper::PsPlusUpsellWrapper(int userIndex)
|
||||
: m_userIndex(userIndex)
|
||||
{
|
||||
m_bHasResponse = false;
|
||||
}
|
||||
|
||||
bool PsPlusUpsellWrapper::displayUpsell()
|
||||
{
|
||||
app.DebugPrintf("<PsPlusUpsellWrapper> Bringing up system PsPlus upsell for Pad_%i.\n", m_userIndex);
|
||||
|
||||
sceNpCommerceDialogInitialize();
|
||||
|
||||
SceNpCommerceDialogParam param;
|
||||
sceNpCommerceDialogParamInitialize(¶m);
|
||||
param.mode = SCE_NP_COMMERCE_DIALOG_MODE_PLUS;
|
||||
param.features = SCE_NP_PLUS_FEATURE_REALTIME_MULTIPLAY;
|
||||
param.userId = ProfileManager.getUserID(m_userIndex);
|
||||
|
||||
sceNpCommerceDialogOpen(¶m);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PsPlusUpsellWrapper::hasResponse()
|
||||
{
|
||||
if (m_bHasResponse) return true;
|
||||
|
||||
if (sceNpCommerceDialogUpdateStatus() == SCE_COMMON_DIALOG_STATUS_FINISHED)
|
||||
{
|
||||
app.DebugPrintf(
|
||||
"<PsPlusUpsellWrapper> Pad_%i %s an PsPlus upsell.\n",
|
||||
m_userIndex, (m_result.authorized?"accepted":"rejected")
|
||||
);
|
||||
|
||||
m_bHasResponse = true;
|
||||
|
||||
sceNpCommerceDialogGetResult(&m_result);
|
||||
|
||||
sceNpCommerceDialogTerminate();
|
||||
|
||||
#ifndef _CONTENT_PACKAGE
|
||||
// 4J-JEV: If HasPlayStationPlus is miraculously true now,
|
||||
// we didn't give it enough time to update before bringing up the upsell
|
||||
assert( ProfileManager.HasPlayStationPlus(m_userIndex) == false );
|
||||
#endif
|
||||
|
||||
ProfileManager.PsPlusUpdate(m_userIndex, &m_result);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
20
Minecraft.Client/Orbis/Network/PsPlusUpsellWrapper_Orbis.h
Normal file
20
Minecraft.Client/Orbis/Network/PsPlusUpsellWrapper_Orbis.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
// 4J-JEV: To help handle PsPlus upsells.
|
||||
class PsPlusUpsellWrapper
|
||||
{
|
||||
private:
|
||||
bool m_bHasResponse;
|
||||
|
||||
SceNpCommerceDialogResult m_result;
|
||||
|
||||
public:
|
||||
const int m_userIndex;
|
||||
|
||||
PsPlusUpsellWrapper(int userIndex);
|
||||
|
||||
bool displayUpsell();
|
||||
|
||||
bool hasResponse();
|
||||
};
|
||||
4155
Minecraft.Client/Orbis/Network/SQRNetworkManager_Orbis.cpp
Normal file
4155
Minecraft.Client/Orbis/Network/SQRNetworkManager_Orbis.cpp
Normal file
File diff suppressed because it is too large
Load Diff
355
Minecraft.Client/Orbis/Network/SQRNetworkManager_Orbis.h
Normal file
355
Minecraft.Client/Orbis/Network/SQRNetworkManager_Orbis.h
Normal file
@@ -0,0 +1,355 @@
|
||||
#pragma once
|
||||
#include <np.h>
|
||||
#include <libnetctl.h>
|
||||
#include <net.h>
|
||||
#include <np_toolkit.h>
|
||||
#include <queue>
|
||||
|
||||
#include <unordered_map>
|
||||
// #include "SonyVoiceChat_Orbis.h"
|
||||
|
||||
#include "..\..\Common\Network\Sony\SQRNetworkManager.h"
|
||||
|
||||
class SQRNetworkPlayer;
|
||||
class ISQRNetworkManagerListener;
|
||||
class SonyVoiceChat_Orbis;
|
||||
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_Orbis : public SQRNetworkManager
|
||||
{
|
||||
friend class SonyVoiceChat_Orbis;
|
||||
friend class SQRNetworkPlayer;
|
||||
|
||||
static const eSQRNetworkManagerState m_INTtoEXTStateMappings[SNM_INT_STATE_COUNT];
|
||||
|
||||
public:
|
||||
SQRNetworkManager_Orbis(ISQRNetworkManagerListener *listener);
|
||||
|
||||
// General
|
||||
void Tick();
|
||||
void Initialise();
|
||||
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_Orbis::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();
|
||||
|
||||
// Remote play
|
||||
void UpdateRemotePlay();
|
||||
|
||||
|
||||
|
||||
// void GetInviteDataAndProcess(SceNpBasicAttachmentDataId id);
|
||||
// static bool UpdateInviteData(SQRNetworkManager_Orbis::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 *GetPlayerByXuid(PlayerUID xuid);
|
||||
SQRNetworkPlayer *GetLocalPlayerByUserIndex(int idx);
|
||||
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);
|
||||
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 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);
|
||||
|
||||
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);
|
||||
|
||||
|
||||
// MGH - changed this to queue up the signalling events from the callback and process them later on the server thread
|
||||
class SignallingEvent
|
||||
{
|
||||
public:
|
||||
SceNpMatching2ContextId ctxId;
|
||||
SceNpMatching2RoomId roomId;
|
||||
SceNpMatching2RoomMemberId peerMemberId;
|
||||
SceNpMatching2Event event;
|
||||
int error_code;
|
||||
};
|
||||
std::vector<SignallingEvent> m_signallingEventList;
|
||||
CRITICAL_SECTION m_signallingEventListCS;
|
||||
|
||||
static void SignallingCallback(SceNpMatching2ContextId ctxId, SceNpMatching2RoomId roomId, SceNpMatching2RoomMemberId peerMemberId, SceNpMatching2Event event, int error_code, void *arg);
|
||||
void ProcessSignallingEvent(SceNpMatching2ContextId ctxId, SceNpMatching2RoomId roomId, SceNpMatching2RoomMemberId peerMemberId, SceNpMatching2Event event, int error_code);
|
||||
void SignallingEventsTick();
|
||||
|
||||
// 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);
|
||||
|
||||
// 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, int iPad = -1);
|
||||
//static void CallSignInCompleteCallback();
|
||||
static int (*s_SignInCompleteCallbackFn)(void *pParam, bool bContinue, int pad);
|
||||
static bool s_signInCompleteCallbackIfFailed;
|
||||
static bool s_signInCompleteCallbackFAIL;
|
||||
|
||||
static void *s_SignInCompleteParam;
|
||||
static bool s_SignInCompleteCallbackPending;
|
||||
static long long s_errorDialogClosed;
|
||||
static long long s_systemDialogClosed;
|
||||
static int s_SignInCompleteCallbackPad;
|
||||
|
||||
// Time to wait for system UI before we check result
|
||||
#define SYSTEM_UI_WAIT_TIME 1000
|
||||
|
||||
static int SetRichPresence(const void *data);
|
||||
void SetPresenceDataStartHostingGame();
|
||||
int GetJoiningReadyPercentage();
|
||||
static void SetPresenceFailedCallback();
|
||||
|
||||
// 4J-PB - so we can stop the crash when Iggy's LoadMovie is called from the ContextCallback
|
||||
static bool m_bCallPSNSignInCallback;
|
||||
|
||||
private:
|
||||
static void UpdateRichPresenceCustomData(void *data, unsigned int dataBytes);
|
||||
static void TickRichPresence();
|
||||
static void SendLastPresenceInfo();
|
||||
|
||||
void OnlineCheck();
|
||||
void tickErrorDialog();
|
||||
|
||||
static sce::Toolkit::NP::PresenceDetails s_lastPresenceInfo;
|
||||
|
||||
static const int MIN_PRESENCE_RESEND_TIME = 30 * 1000; // Minimum presence send rate - doesn't seem possible to find out what this actually should be
|
||||
static __int64 s_lastPresenceTime;
|
||||
static __int64 s_resendPresenceTime;
|
||||
|
||||
static bool s_presenceStatusDirty;
|
||||
static bool s_presenceDataDirty;
|
||||
|
||||
static PresenceSyncInfo s_lastPresenceSyncInfo;
|
||||
static PresenceSyncInfo c_presenceSyncInfoNULL;
|
||||
static bool b_inviteRecvGUIRunning;
|
||||
|
||||
// Debug
|
||||
static long long s_roomStartTime;
|
||||
|
||||
// Error dialog
|
||||
static bool s_errorDialogRunning;
|
||||
|
||||
// NP Notify
|
||||
void TickNotify();
|
||||
void NotifyRealtimePlusFeature(int iQuadrant);
|
||||
long long m_lastNotifyTime;
|
||||
|
||||
static void RefreshChatAndContentRestrictionsReturned_HandleInvite(void *pParam);
|
||||
bool m_bRefreshingRestrictionsForInvite;
|
||||
|
||||
public:
|
||||
static bool s_bInviteDialogRunning;
|
||||
};
|
||||
|
||||
1314
Minecraft.Client/Orbis/Network/SonyCommerce_Orbis.cpp
Normal file
1314
Minecraft.Client/Orbis/Network/SonyCommerce_Orbis.cpp
Normal file
File diff suppressed because it is too large
Load Diff
182
Minecraft.Client/Orbis/Network/SonyCommerce_Orbis.h
Normal file
182
Minecraft.Client/Orbis/Network/SonyCommerce_Orbis.h
Normal file
@@ -0,0 +1,182 @@
|
||||
#pragma once
|
||||
|
||||
#include "Common\Network\Sony\SonyCommerce.h"
|
||||
class OrbisNPToolkit;
|
||||
|
||||
class SonyCommerce_Orbis : public SonyCommerce
|
||||
{
|
||||
friend class OrbisNPToolkit;
|
||||
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_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_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_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_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 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 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 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 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:
|
||||
|
||||
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 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);
|
||||
virtual void UpgradeTrial(CallbackFunc cb, LPVOID lpParam);
|
||||
virtual void CheckForTrialUpgradeKey();
|
||||
virtual bool LicenseChecked();
|
||||
|
||||
};
|
||||
285
Minecraft.Client/Orbis/Network/SonyHttp_Orbis.cpp
Normal file
285
Minecraft.Client/Orbis/Network/SonyHttp_Orbis.cpp
Normal file
@@ -0,0 +1,285 @@
|
||||
#include "stdafx.h"
|
||||
#include "SonyHttp_Orbis.h"
|
||||
|
||||
static const int sc_SSLHeapSize = (304 * 1024U);
|
||||
static const int sc_HTTPHeapSize = (48 * 1024);
|
||||
static const int sc_NetHeapSize = (16 * 1024);
|
||||
|
||||
#define TEST_USER_AGENT "SimpleSample/1.00"
|
||||
|
||||
|
||||
int SonyHttp_Orbis::libnetMemId = 0;
|
||||
int SonyHttp_Orbis::libsslCtxId = 0;
|
||||
int SonyHttp_Orbis::libhttpCtxId = 0;
|
||||
bool SonyHttp_Orbis:: bInitialised = false;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool SonyHttp_Orbis::init()
|
||||
{
|
||||
int ret = sceNetPoolCreate("simple", sc_NetHeapSize, 0);
|
||||
assert(ret >= 0);
|
||||
libnetMemId = ret;
|
||||
|
||||
ret = sceSslInit(sc_SSLHeapSize);
|
||||
assert(ret >= 0);
|
||||
libsslCtxId = ret;
|
||||
|
||||
ret = sceHttpInit(libnetMemId, libsslCtxId, sc_HTTPHeapSize);
|
||||
assert(ret >= 0);
|
||||
libhttpCtxId = ret;
|
||||
|
||||
bInitialised = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
void SonyHttp_Orbis::shutdown()
|
||||
{
|
||||
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_Orbis::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_Orbis::printSslCertInfo(int libsslCtxId,SceSslCert *sslCert)
|
||||
{
|
||||
SceInt32 ret;
|
||||
SceUChar8 *sboData = NULL ;
|
||||
SceSize sboLen, counter;
|
||||
|
||||
ret = sceSslGetSerialNumber(libsslCtxId, sslCert, NULL, &sboLen);
|
||||
if (ret < 0){
|
||||
app.DebugPrintf("sceSslGetSerialNumber() returns 0x%x\n", ret);
|
||||
}
|
||||
else {
|
||||
sboData = (SceUChar8*)malloc(sboLen);
|
||||
if ( sboData != NULL ) {
|
||||
ret = sceSslGetSerialNumber(libsslCtxId, 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");
|
||||
}
|
||||
free(sboData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool SonyHttp_Orbis::getDataFromURL( const char* szURL, void** ppOutData, int* pDataSize)
|
||||
{
|
||||
if(!bInitialised)
|
||||
return false;
|
||||
return http_get(szURL, ppOutData, pDataSize);
|
||||
}
|
||||
|
||||
|
||||
SceInt32 SonyHttp_Orbis::sslCallback(int libsslCtxId,unsigned int verifyErr,SceSslCert * const sslCert[],int 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(libsslCtxId,sslCert[i]);
|
||||
}
|
||||
if (verifyErr == 0){
|
||||
return SCE_OK;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
bool SonyHttp_Orbis::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_Orbis::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(libhttpCtxId, 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(tmplId,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)
|
||||
{
|
||||
int contentLengthType;
|
||||
ret = sceHttpGetResponseContentLength(reqId, &contentLengthType, &contentLength);
|
||||
if(ret < 0)
|
||||
{
|
||||
app.DebugPrintf("sceHttpGetContentLength() error: 0x%08X\n", ret);
|
||||
return http_get_close(false, tmplId, connId, reqId);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (contentLengthType == SCE_HTTP_CONTENTLEN_EXIST)
|
||||
{
|
||||
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/Orbis/Network/SonyHttp_Orbis.h
Normal file
26
Minecraft.Client/Orbis/Network/SonyHttp_Orbis.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
|
||||
#include <libhttp.h>
|
||||
|
||||
class SonyHttp_Orbis
|
||||
{
|
||||
static SceInt32 sslCallback(int libsslCtxId,unsigned int verifyErr,SceSslCert * const sslCert[],int 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(int libsslCtxId,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; }
|
||||
};
|
||||
371
Minecraft.Client/Orbis/Network/SonyRemoteStorage_Orbis.cpp
Normal file
371
Minecraft.Client/Orbis/Network/SonyRemoteStorage_Orbis.cpp
Normal file
@@ -0,0 +1,371 @@
|
||||
#include "stdafx.h"
|
||||
|
||||
#include "SonyRemoteStorage_Orbis.h"
|
||||
#include "SonyHttp_Orbis.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_Orbis::staticInternalCallback(const SceRemoteStorageEvent event, int32_t retCode, void * userData)
|
||||
{
|
||||
((SonyRemoteStorage_Orbis*)userData)->internalCallback(event, retCode);
|
||||
}
|
||||
void SonyRemoteStorage_Orbis::internalCallback(const SceRemoteStorageEvent event, int32_t retCode)
|
||||
{
|
||||
m_lastErrorCode = retCode;
|
||||
|
||||
switch(event)
|
||||
{
|
||||
case ERROR_OCCURRED:
|
||||
app.DebugPrintf("SonyRemoteStorage_Orbis: 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();
|
||||
break;
|
||||
|
||||
case GET_DATA_RESULT:
|
||||
if(retCode >= 0)
|
||||
{
|
||||
app.DebugPrintf("SonyRemoteStorage_Orbis: Get Data success \n");
|
||||
m_status = e_getDataSucceeded;
|
||||
}
|
||||
else
|
||||
{
|
||||
app.DebugPrintf("SonyRemoteStorage_Orbis: An error occurred while Get Data was being processed. retCode: 0x%x \n", retCode);
|
||||
m_status = e_error;
|
||||
}
|
||||
if(StorageManager.SaveGameDirUnMount(m_mountPoint) == false)
|
||||
{
|
||||
app.DebugPrintf("Failed to unmount %s\n", m_mountPoint);
|
||||
}
|
||||
|
||||
m_mountPoint[0] = 0;
|
||||
runCallback();
|
||||
break;
|
||||
|
||||
case GET_DATA_PROGRESS:
|
||||
app.DebugPrintf("SonyRemoteStorage_Orbis: 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("SonyRemoteStorage_Orbis: Get Status success \n");
|
||||
app.DebugPrintf("SonyRemoteStorage_Orbis: Remaining Syncs for this user: %llu\n", outputGetStatus->remainingSyncs);
|
||||
app.DebugPrintf("SonyRemoteStorage_Orbis: 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("SonyRemoteStorage_Orbis: 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("SonyRemoteStorage_Orbis: 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("SonyRemoteStorage_Orbis: Set Data success \n");
|
||||
m_status = e_setDataSucceeded;
|
||||
}
|
||||
else
|
||||
{
|
||||
app.DebugPrintf("SonyRemoteStorage_Orbis: An error occurred while Set Data was being processed. retCode: 0x%x \n", retCode);
|
||||
m_status = e_error;
|
||||
}
|
||||
runCallback();
|
||||
break;
|
||||
|
||||
case SET_DATA_PROGRESS:
|
||||
app.DebugPrintf("SonyRemoteStorage_Orbis: Set data progress: %i%%\n", retCode);
|
||||
m_status = e_setDataInProgress;
|
||||
m_dataProgress = retCode;
|
||||
|
||||
break;
|
||||
|
||||
case USER_ACCOUNT_LINKED:
|
||||
app.DebugPrintf("SonyRemoteStorage_Orbis: User's account has been linked with PSN \n");
|
||||
m_bInitialised = true;
|
||||
m_status = e_accountLinked;
|
||||
runCallback();
|
||||
break;
|
||||
|
||||
case WEB_BROWSER_RESULT:
|
||||
app.DebugPrintf("SonyRemoteStorage_Orbis: 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("SonyRemoteStorage_Orbis: This should never happen \n");
|
||||
assert(0);
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
bool SonyRemoteStorage_Orbis::init(CallbackFunc cb, LPVOID lpParam)
|
||||
{
|
||||
|
||||
int ret = 0;
|
||||
int reqId = 0;
|
||||
SceNpId npId;
|
||||
SceUserServiceUserId userId;
|
||||
SceRemoteStorageInitParams params;
|
||||
|
||||
m_callbackFunc = cb;
|
||||
m_callbackParam = lpParam;
|
||||
|
||||
if(m_bInitialised)
|
||||
{
|
||||
runCallback();
|
||||
return true;
|
||||
}
|
||||
|
||||
ret = sceUserServiceGetInitialUser(&userId);
|
||||
if (ret < 0)
|
||||
{
|
||||
app.DebugPrintf("Couldn't retrieve user ID 0x%x\n", ret);
|
||||
return false;
|
||||
}
|
||||
|
||||
ret = sceNpGetNpId(userId, &npId);
|
||||
if (ret < 0) {
|
||||
app.DebugPrintf("Couldn't retrieve NP ID 0x%x\n", ret);
|
||||
return false;
|
||||
}
|
||||
|
||||
// ret = sceNpAuthCreateRequest();
|
||||
// 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.pOnlineId = &npId.handle;
|
||||
// authParams.pScope = AUTH_SCOPE;
|
||||
|
||||
// memcpy(clientId.id, CLIENT_ID, strlen(CLIENT_ID));
|
||||
// authParams.pClientId = &clientId;
|
||||
|
||||
// ret = sceNpAuthGetAuthorizationCode(reqId, &authParams, &authCode, NULL);
|
||||
// if (ret < 0) {
|
||||
// app.DebugPrintf("Failed to get auth code 0x%x\n", ret);
|
||||
// }
|
||||
|
||||
// ret = sceNpAuthDeleteRequest(reqId);
|
||||
// if (ret < 0) {
|
||||
// app.DebugPrintf("Couldn't delete auth request 0x%x\n", ret);
|
||||
// }
|
||||
|
||||
params.callback = staticInternalCallback;
|
||||
params.userData = this;
|
||||
// memcpy(params.authCode, authCode.code, SCE_NP_AUTHORIZATION_CODE_MAX_LEN);
|
||||
params.userId = userId;
|
||||
params.environment = DEVELOPMENT;
|
||||
params.httpContextId = SonyHttp_Orbis::getHTTPContextID();
|
||||
strcpy(params.clientId, CLIENT_ID);
|
||||
|
||||
params.thread.threadAffinity = SCE_KERNEL_CPUMASK_USER_ALL;
|
||||
params.thread.threadPriority = SCE_KERNEL_PRIO_FIFO_DEFAULT;
|
||||
|
||||
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;
|
||||
|
||||
ret = sceRemoteStorageInit(params);
|
||||
if (ret >= 0)
|
||||
{
|
||||
app.DebugPrintf("Session will be created \n");
|
||||
}
|
||||
else if(ret == SCE_REMOTE_STORAGE_ERROR_ALREADY_INITIALISED)
|
||||
{
|
||||
app.DebugPrintf("Already initialised: 0x%x \n", ret);
|
||||
runCallback();
|
||||
}
|
||||
else
|
||||
{
|
||||
app.DebugPrintf("Error creating session: 0x%x \n", ret);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool SonyRemoteStorage_Orbis::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_Orbis::abort()
|
||||
{
|
||||
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_Orbis::setData( PSAVE_INFO info, CallbackFunc cb, LPVOID lpParam )
|
||||
{
|
||||
assert(0);
|
||||
return false;
|
||||
|
||||
// m_callbackFunc = cb;
|
||||
// m_callbackParam = lpParam;
|
||||
//
|
||||
// strcpy(m_saveFilename, savePath);
|
||||
// strcpy(m_saveFileDesc, saveDesc);
|
||||
// m_status = e_setDataInProgress;
|
||||
//
|
||||
//
|
||||
// SceRemoteStorageSetDataReqParams params;
|
||||
// params.visibility = PUBLIC_READ_WRITE;
|
||||
// strcpy(params.pathLocation, m_saveFilename);
|
||||
// sprintf(params.fileName, "/%s/GAMEDATA", m_saveFilename);
|
||||
// // strcpy(params.fileName, "/test/small.txt");
|
||||
// strcpy(params.fileDescription, m_saveFileDesc);
|
||||
// strcpy(params.ps3DataFilename, "GAMEDATA");
|
||||
//
|
||||
// params.ps3FileType = CELL_SAVEDATA_FILETYPE_NORMALFILE;
|
||||
// memcpy(params.secureFileId, m_secureFileId, CELL_SAVEDATA_SECUREFILEID_SIZE);
|
||||
//
|
||||
//
|
||||
//
|
||||
// reqId = sceRemoteStorageSetData(params);
|
||||
//
|
||||
// app.DebugPrintf("\n*******************************\n");
|
||||
// if(reqId >= 0)
|
||||
// {
|
||||
// app.DebugPrintf("Set Data request sent \n");
|
||||
// return true;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// app.DebugPrintf("Error sending Set Data request: 0x%x \n", reqId);
|
||||
// return false;
|
||||
// }
|
||||
}
|
||||
|
||||
bool SonyRemoteStorage_Orbis::getData( const char* remotePath, const char* localPath, CallbackFunc cb, LPVOID lpParam )
|
||||
{
|
||||
m_callbackFunc = cb;
|
||||
m_callbackParam = lpParam;
|
||||
|
||||
if(StorageManager.SaveGameDirMountExisting(m_mountPoint) == false)
|
||||
{
|
||||
app.DebugPrintf("Error mounting save dir \n");
|
||||
m_mountPoint[0] = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
SceRemoteStorageGetDataReqParams params;
|
||||
sprintf(params.pathLocation, "%s/GAMEDATA", m_mountPoint);
|
||||
// strcpy(params.fileName, "/test/small.txt");
|
||||
strcpy(params.fileName, remotePath);
|
||||
SceRemoteStorageData s_getDataOutput;
|
||||
reqId = sceRemoteStorageGetData(params, &s_getDataOutput);
|
||||
|
||||
app.DebugPrintf("\n*******************************\n");
|
||||
if(reqId >= 0)
|
||||
{
|
||||
app.DebugPrintf("Get Data request sent \n");
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
app.DebugPrintf("Error sending Get Data request: 0x%x \n", reqId);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void SonyRemoteStorage_Orbis::runCallback()
|
||||
{
|
||||
assert(m_callbackFunc);
|
||||
if(m_callbackFunc)
|
||||
{
|
||||
m_callbackFunc(m_callbackParam, m_status, m_lastErrorCode);
|
||||
}
|
||||
m_lastErrorCode = SCE_OK;
|
||||
}
|
||||
42
Minecraft.Client/Orbis/Network/SonyRemoteStorage_Orbis.h
Normal file
42
Minecraft.Client/Orbis/Network/SonyRemoteStorage_Orbis.h
Normal file
@@ -0,0 +1,42 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
#include "Common\Network\Sony\SonyRemoteStorage.h"
|
||||
|
||||
class SonyRemoteStorage_Orbis : public SonyRemoteStorage
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
virtual bool init(CallbackFunc cb, LPVOID lpParam);
|
||||
virtual bool setData(PSAVE_INFO info, 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(){ assert(0); }
|
||||
|
||||
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];
|
||||
char m_mountPoint[SCE_SAVE_DATA_MOUNT_POINT_DATA_MAXSIZE];
|
||||
|
||||
static void staticInternalCallback(const SceRemoteStorageEvent event, int32_t retCode, void * userData);
|
||||
void internalCallback(const SceRemoteStorageEvent event, int32_t retCode);
|
||||
|
||||
void runCallback();
|
||||
};
|
||||
|
||||
355
Minecraft.Client/Orbis/Network/SonyVoiceChatParty_Orbis.cpp
Normal file
355
Minecraft.Client/Orbis/Network/SonyVoiceChatParty_Orbis.cpp
Normal file
@@ -0,0 +1,355 @@
|
||||
#include "stdafx.h"
|
||||
|
||||
#include "SonyVoiceChat_Orbis.h"
|
||||
|
||||
|
||||
|
||||
bool m_bIsPartyAPIInitialized;
|
||||
bool m_bIsPartyBinaryMessageAPIReady;
|
||||
|
||||
SceNpPartyState m_stPartyState;
|
||||
|
||||
SonyVoiceChatParty_Orbis::PartyInfo SonyVoiceChatParty_Orbis::m_partyInfo;
|
||||
|
||||
void SonyVoiceChatParty_Orbis::init()
|
||||
{
|
||||
// m_bIsRunning = false;
|
||||
// m_pRenderer = NULL;
|
||||
// m_pPadContext = NULL;
|
||||
// m_pGraphicsContext = NULL;
|
||||
// m_iPartyMemberCount = 0;
|
||||
// m_iPartyLeader = 0;
|
||||
int ret = SCE_OK;
|
||||
SceNpPartyInitializeParam stPartyInit;
|
||||
SceUserServiceLoginUserIdList userIdList;
|
||||
|
||||
|
||||
// Run PartyInitializeParamInitialize inline
|
||||
sceNpPartyInitializeParamInitialize( &stPartyInit );
|
||||
|
||||
// Initialize the Party API
|
||||
ret = sceNpPartyInitialize( &stPartyInit );
|
||||
if( ret != SCE_OK )
|
||||
{
|
||||
app.DebugPrintf( "Error: sceNpPartyInitialize failed result:0x%x\n", ret );
|
||||
return;
|
||||
}
|
||||
|
||||
// Register handlers for party room events
|
||||
SceNpPartyEventHandlers stPartyEventHandler;
|
||||
memset( &stPartyEventHandler, 0, sizeof( SceNpPartyEventHandlers ) );
|
||||
stPartyEventHandler.roomEventHandler = partyRoomEventHandler;
|
||||
stPartyEventHandler.voiceEventHandler = partyVoiceEventHandler;
|
||||
stPartyEventHandler.binaryMessageEventHandler = partyBinaryMessageEventHandler;
|
||||
ret = sceNpPartyRegisterHandler( &stPartyEventHandler, NULL );
|
||||
if( ret != SCE_OK )
|
||||
{
|
||||
app.DebugPrintf( "Error: sceNpPartyRegisterHandler failed result:0x%x\n", ret );
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Get current party state
|
||||
ret = sceNpPartyGetState( &m_stPartyState );
|
||||
if( ret != SCE_OK )
|
||||
{
|
||||
app.DebugPrintf( "Error: sceNpPartyGetState failed result:0x%x\n", ret );
|
||||
return;
|
||||
}
|
||||
|
||||
m_bIsPartyAPIInitialized = true;
|
||||
}
|
||||
|
||||
void SonyVoiceChatParty_Orbis::shutdown()
|
||||
{
|
||||
}
|
||||
|
||||
void SonyVoiceChatParty_Orbis::setEnabled( bool bEnabled )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void SonyVoiceChatParty_Orbis::tick()
|
||||
{
|
||||
sceNpPartyCheckCallback();
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool SonyVoiceChatParty_Orbis::hasMicConnected(const PlayerUID& memberUID)
|
||||
{
|
||||
MemberInfo* pInfo = m_partyInfo.getMember(memberUID);
|
||||
if(pInfo)
|
||||
{
|
||||
// in the party, might not have a mic though, still need to check for this
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void SonyVoiceChatParty_Orbis::mute( bool bMute )
|
||||
{
|
||||
// if(sm_bLoaded && !sm_bUnloading)
|
||||
// {
|
||||
// int err = cellSysutilAvc2SetVoiceMuting(bMute);
|
||||
// assert(err == CELL_OK);
|
||||
// }
|
||||
}
|
||||
|
||||
void SonyVoiceChatParty_Orbis::mutePlayer( const SceNpMatching2RoomMemberId member_id, bool bMute ) /*Turn chat audio from a specified player on or off */
|
||||
{
|
||||
// if(sm_bLoaded && !sm_bUnloading)
|
||||
// {
|
||||
// int err = cellSysutilAvc2SetPlayerVoiceMuting(member_id, bMute);
|
||||
// assert(err == CELL_OK);
|
||||
// }
|
||||
}
|
||||
|
||||
void SonyVoiceChatParty_Orbis::muteLocalPlayer( bool bMute ) /*Turn microphone input on or off */
|
||||
{
|
||||
// if(sm_bLoaded && !sm_bUnloading)
|
||||
// {
|
||||
// int err = cellSysutilAvc2SetVoiceMuting(bMute);
|
||||
// assert(err == CELL_OK);
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
bool SonyVoiceChatParty_Orbis::isMuted()
|
||||
{
|
||||
// if(sm_bLoaded && !sm_bUnloading)
|
||||
// {
|
||||
// uint8_t bMute;
|
||||
// int err = cellSysutilAvc2GetVoiceMuting(&bMute);
|
||||
// assert(err == CELL_OK);
|
||||
// return bMute;
|
||||
// }
|
||||
// return false;
|
||||
}
|
||||
|
||||
bool SonyVoiceChatParty_Orbis::isMutedPlayer( const PlayerUID& memberUID)
|
||||
{
|
||||
MemberInfo* pInfo = m_partyInfo.getMember(memberUID);
|
||||
if(pInfo)
|
||||
return pInfo->m_voiceMuted;
|
||||
assert(0 && "Didn't find playerUID"); //
|
||||
return false;
|
||||
// if(sm_bLoaded && !sm_bUnloading)
|
||||
// {
|
||||
// uint8_t bMute;
|
||||
// int err = cellSysutilAvc2GetPlayerVoiceMuting(member_id, &bMute);
|
||||
// assert(err == CELL_OK);
|
||||
// return bMute;
|
||||
// }
|
||||
// return false;
|
||||
}
|
||||
|
||||
bool SonyVoiceChatParty_Orbis::isMutedLocalPlayer()
|
||||
{
|
||||
// if(sm_bLoaded && !sm_bUnloading)
|
||||
// {
|
||||
// uint8_t bMute;
|
||||
// int err = cellSysutilAvc2GetVoiceMuting(&bMute);
|
||||
// assert(err == CELL_OK);
|
||||
// return bMute;
|
||||
// }
|
||||
// return false;
|
||||
}
|
||||
|
||||
|
||||
bool SonyVoiceChatParty_Orbis::isTalking( const PlayerUID& memberUID)
|
||||
{
|
||||
MemberInfo* pInfo = m_partyInfo.getMember(memberUID);
|
||||
if(pInfo)
|
||||
{
|
||||
DWORD currTime = GetTickCount();
|
||||
DWORD timeElapsed = currTime - pInfo->m_lastTimeTalking;
|
||||
return (timeElapsed < 1000);
|
||||
}
|
||||
assert(0 && "Didn't find playerUID"); //
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void SonyVoiceChatParty_Orbis::partyRoomEventHandler(SceNpPartyRoomEventType eventType, const void* data, void* userdata)
|
||||
{
|
||||
|
||||
switch(eventType)
|
||||
{
|
||||
case SCE_NP_PARTY_ROOM_EVENT_JOINED:
|
||||
{
|
||||
// local player joined party
|
||||
app.DebugPrintf("SCE_NP_PARTY_ROOM_EVENT_JOINED\n");
|
||||
SceNpPartyJoinedInfo* pPartyJoinedInfo = (SceNpPartyJoinedInfo*) data;
|
||||
|
||||
m_partyInfo.clear();
|
||||
app.DebugPrintf("Local user joined party.\n");
|
||||
for(int i=0; i<pPartyJoinedInfo->memberNum;i++)
|
||||
{
|
||||
m_partyInfo.addMember(pPartyJoinedInfo->memberIds[i], pPartyJoinedInfo->members[i], false, false);
|
||||
app.DebugPrintf("Member room ID : %d - Member PSN ID : %s\n", pPartyJoinedInfo->memberIds[i], pPartyJoinedInfo->members[i].handle.data);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case SCE_NP_PARTY_ROOM_EVENT_MEMBER_JOINED:
|
||||
{
|
||||
// remote player joined party
|
||||
app.DebugPrintf("SCE_NP_PARTY_ROOM_EVENT_MEMBER_JOINED\n");
|
||||
SceNpPartyMemberInfo *pNewPartyMemberInfo = (SceNpPartyMemberInfo*) data;
|
||||
app.DebugPrintf("A remote player[%s] has a joined the party.\n",pNewPartyMemberInfo->npId.handle.data);
|
||||
|
||||
m_partyInfo.addMember(pNewPartyMemberInfo->memberId, pNewPartyMemberInfo->npId, pNewPartyMemberInfo->memberFlags & SCE_NP_PARTY_MEMBER_FLAG_IS_LOCAL, pNewPartyMemberInfo->memberFlags & SCE_NP_PARTY_MEMBER_FLAG_IS_PARTY_LEADER);
|
||||
}
|
||||
break;
|
||||
|
||||
case SCE_NP_PARTY_ROOM_EVENT_MEMBER_LEFT:
|
||||
{
|
||||
// remote player left party
|
||||
app.DebugPrintf("SCE_NP_PARTY_ROOM_EVENT_MEMBER_LEFT\n");
|
||||
SceNpPartyMemberInfo *pLeavingPartyMemberInfo = (SceNpPartyMemberInfo*) data;
|
||||
app.DebugPrintf("A remote player[%s] has left the party.\n", pLeavingPartyMemberInfo->npId.handle.data);
|
||||
m_partyInfo.removeMember(pLeavingPartyMemberInfo->memberId);
|
||||
}
|
||||
break;
|
||||
|
||||
case SCE_NP_PARTY_ROOM_EVENT_LEFT:
|
||||
{
|
||||
// local player left party
|
||||
app.DebugPrintf("SCE_NP_PARTY_ROOM_EVENT_LEFT\n");
|
||||
SceNpPartyRoomLeftInfo *pLeftInfo = (SceNpPartyRoomLeftInfo*)data;
|
||||
printf("Local party member[%s] id:%d has left the party. Reason[%d]\n", pLeftInfo->npId.handle.data, pLeftInfo->memberId, pLeftInfo->reason);
|
||||
m_partyInfo.removeMember(pLeftInfo->memberId);
|
||||
}
|
||||
break;
|
||||
|
||||
case SCE_NP_PARTY_ROOM_EVENT_CREATE_RESPONSE:
|
||||
{
|
||||
app.DebugPrintf("SCE_NP_PARTY_ROOM_EVENT_CREATE_RESPONSE\n");
|
||||
SceNpPartyCreateResponseInfo *pCreateResponseInfo = (SceNpPartyCreateResponseInfo*) data;
|
||||
|
||||
switch( pCreateResponseInfo->status )
|
||||
{
|
||||
case SCE_NP_PARTY_ROOM_CREATE_RESPONSE_STATUS_OK:
|
||||
app.DebugPrintf( "Local party member userId[0x%x] response for creating a party. Status = SCE_NP_PARTY_ROOM_CREATE_RESPONSE_STATUS_OK\n" , pCreateResponseInfo->userId );
|
||||
break;
|
||||
case SCE_NP_PARTY_ROOM_CREATE_RESPONSE_STATUS_CANCELLED:
|
||||
app.DebugPrintf( "Local party member userId[0x%x] response for creating a party. Status = SCE_NP_PARTY_ROOM_CREATE_RESPONSE_STATUS_CANCELLED\n" , pCreateResponseInfo->userId );
|
||||
break;
|
||||
default:
|
||||
app.DebugPrintf( "Warning: Unknown SceNpPartyCreateResponseStatus [%d]. Ignore.\n", pCreateResponseInfo->status );
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case SCE_NP_PARTY_ROOM_EVENT_SHOW_INVITATION_RESPONSE:
|
||||
{
|
||||
app.DebugPrintf("SCE_NP_PARTY_ROOM_EVENT_SHOW_INVITATION_RESPONSE\n");
|
||||
SceNpPartyShowInvitationResponseInfo *pShowInvitationResponseInfo = (SceNpPartyShowInvitationResponseInfo*) data;
|
||||
|
||||
switch( pShowInvitationResponseInfo->status )
|
||||
{
|
||||
case SCE_NP_PARTY_ROOM_SHOW_INVITATION_RESPONSE_STATUS_OK:
|
||||
app.DebugPrintf( "Local party member userId[0x%x] response for sending an invitation/suggestion. Status = SCE_NP_PARTY_ROOM_SHOW_INVITATION_RESPONSE_STATUS_OK\n" , pShowInvitationResponseInfo->userId );
|
||||
break;
|
||||
case SCE_NP_PARTY_ROOM_SHOW_INVITATION_RESPONSE_STATUS_CANCELLED:
|
||||
app.DebugPrintf( "Local party member userId[0x%x] response for sending an invitation/suggestion. Status = SCE_NP_PARTY_ROOM_SHOW_INVITATION_RESPONSE_STATUS_CANCELLED\n" , pShowInvitationResponseInfo->userId );
|
||||
break;
|
||||
default:
|
||||
app.DebugPrintf( "Warning: Unknown SceNpPartyShowInvitationResponseStatus [%d]. Ignore.\n", pShowInvitationResponseInfo->status );
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
{
|
||||
app.DebugPrintf( "Warning: Un-handled party event[%d]. Ignore.\n", eventType );
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void SonyVoiceChatParty_Orbis::partyVoiceEventHandler( const SceNpPartyMemberVoiceInfo* memberVoiceInfo, void* userdata )
|
||||
{
|
||||
|
||||
switch(memberVoiceInfo->memberVoiceState)
|
||||
{
|
||||
case SCE_NP_PARTY_MEMBER_VOICE_STATE_DISCONNECTED:
|
||||
{
|
||||
app.DebugPrintf("SCE_NP_PARTY_MEMBER_VOICE_STATE_DISCONNECTED\n");
|
||||
MemberInfo* pInfo = m_partyInfo.getMember(memberVoiceInfo->memberId);
|
||||
assert(pInfo);
|
||||
if(pInfo)
|
||||
pInfo->m_voiceConnected = false;
|
||||
}
|
||||
break;
|
||||
case SCE_NP_PARTY_MEMBER_VOICE_STATE_CONNECTED:
|
||||
{
|
||||
app.DebugPrintf("SCE_NP_PARTY_MEMBER_VOICE_STATE_CONNECTED\n");
|
||||
MemberInfo* pInfo = m_partyInfo.getMember(memberVoiceInfo->memberId);
|
||||
assert(pInfo);
|
||||
if(pInfo)
|
||||
pInfo->m_voiceConnected = true;
|
||||
}
|
||||
break;
|
||||
case SCE_NP_PARTY_MEMBER_VOICE_STATE_TALKING:
|
||||
{
|
||||
app.DebugPrintf("SCE_NP_PARTY_MEMBER_VOICE_STATE_TALKING\n");
|
||||
MemberInfo* pInfo = m_partyInfo.getMember(memberVoiceInfo->memberId);
|
||||
assert(pInfo);
|
||||
if(pInfo)
|
||||
{
|
||||
pInfo->m_voiceMuted = false;
|
||||
pInfo->m_lastTimeTalking = GetTickCount();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SCE_NP_PARTY_MEMBER_VOICE_STATE_MUTED:
|
||||
{
|
||||
app.DebugPrintf("SCE_NP_PARTY_MEMBER_VOICE_STATE_MUTED\n");
|
||||
MemberInfo* pInfo = m_partyInfo.getMember(memberVoiceInfo->memberId);
|
||||
assert(pInfo);
|
||||
if(pInfo)
|
||||
pInfo->m_voiceMuted = true;
|
||||
}
|
||||
break;
|
||||
case SCE_NP_PARTY_MEMBER_VOICE_STATE_UNKNOWN:
|
||||
{
|
||||
app.DebugPrintf("SCE_NP_PARTY_MEMBER_VOICE_STATE_UNKNOWN\n");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
app.DebugPrintf("Warning: Un-handled voice event. Ignore.\n");
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void SonyVoiceChatParty_Orbis::partyBinaryMessageEventHandler( SceNpPartyBinaryMessageEvent event,
|
||||
const void *data,
|
||||
void * userdata
|
||||
)
|
||||
{
|
||||
switch(event)
|
||||
{
|
||||
case SCE_NP_PARTY_BINARY_MESSAGE_EVENT_READY:
|
||||
case SCE_NP_PARTY_BINARY_MESSAGE_EVENT_DATA:
|
||||
case SCE_NP_PARTY_BINARY_MESSAGE_EVENT_COMPATIBILITY:
|
||||
default:
|
||||
// app.DebugPrintf("partyBinaryMessageEventHandler not supported");
|
||||
// assert(0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
111
Minecraft.Client/Orbis/Network/SonyVoiceChatParty_Orbis.h
Normal file
111
Minecraft.Client/Orbis/Network/SonyVoiceChatParty_Orbis.h
Normal file
@@ -0,0 +1,111 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <np\np_party.h>
|
||||
|
||||
class SonyVoiceChatParty_Orbis
|
||||
{
|
||||
public:
|
||||
|
||||
static void init();
|
||||
static void shutdown();
|
||||
static void tick();
|
||||
static void setEnabled(bool bEnabled);
|
||||
static bool hasMicConnected(const PlayerUID& memberUID);
|
||||
static bool isTalking( const PlayerUID& memberUID);
|
||||
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;
|
||||
|
||||
|
||||
private:
|
||||
//NP Party Event Handlers
|
||||
static void partyRoomEventHandler(SceNpPartyRoomEventType eventType,const void* data, void* userdata);
|
||||
static void partyVoiceEventHandler(const SceNpPartyMemberVoiceInfo* memberVoiceInfo,void* userdata);
|
||||
static void partyBinaryMessageEventHandler(SceNpPartyBinaryMessageEvent event, const void *data, void * userdata);
|
||||
|
||||
class MemberInfo
|
||||
{
|
||||
public:
|
||||
SceNpId m_NpId;
|
||||
SceNpPartyRoomMemberId m_roomID;
|
||||
bool m_voiceConnected;
|
||||
bool m_voiceMuted;
|
||||
DWORD m_lastTimeTalking;
|
||||
bool m_localUser;
|
||||
bool m_partyLeader;
|
||||
MemberInfo()
|
||||
{
|
||||
m_voiceConnected = false;
|
||||
m_voiceMuted = false;
|
||||
m_lastTimeTalking = 0;
|
||||
m_localUser = false;
|
||||
m_partyLeader = false;
|
||||
}
|
||||
};
|
||||
class PartyInfo
|
||||
{
|
||||
public:
|
||||
int m_numMembers;
|
||||
MemberInfo m_members[SCE_NP_PARTY_MEMBER_NUM_MAX];
|
||||
bool m_privateParty;
|
||||
|
||||
MemberInfo* getMember(SceNpPartyRoomMemberId roomID)
|
||||
{
|
||||
for(int i=0;i<m_numMembers;i++)
|
||||
{
|
||||
if(m_members[i].m_roomID == roomID)
|
||||
return &m_members[i];
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
MemberInfo* getMember(const PlayerUID& memberUID)
|
||||
{
|
||||
for(int i=0;i<m_numMembers;i++)
|
||||
{
|
||||
if(strcmp(m_members[i].m_NpId.handle.data, memberUID.getOnlineID()) == 0)
|
||||
return &m_members[i];
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
PartyInfo() : m_numMembers(0) {}
|
||||
void addMember(SceNpPartyRoomMemberId roomID, SceNpId npID, bool local, bool leader)
|
||||
{
|
||||
m_members[m_numMembers].m_roomID = roomID;
|
||||
m_members[m_numMembers].m_NpId = npID;
|
||||
m_members[m_numMembers].m_localUser = local;
|
||||
m_members[m_numMembers].m_partyLeader = leader;
|
||||
m_numMembers++;
|
||||
}
|
||||
|
||||
void removeMember(SceNpPartyRoomMemberId roomID)
|
||||
{
|
||||
// find the index of this member first
|
||||
int index = -1;
|
||||
for(int i=0;i<m_numMembers;i++)
|
||||
{
|
||||
if(roomID == m_members[i].m_roomID)
|
||||
{
|
||||
index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
assert(index >= 0);
|
||||
|
||||
m_numMembers--;
|
||||
if(m_numMembers > 0)
|
||||
m_members[index] = m_members[m_numMembers];
|
||||
}
|
||||
void clear() { m_numMembers = 0;}
|
||||
};
|
||||
static PartyInfo m_partyInfo;
|
||||
};
|
||||
1105
Minecraft.Client/Orbis/Network/SonyVoiceChat_Orbis.cpp
Normal file
1105
Minecraft.Client/Orbis/Network/SonyVoiceChat_Orbis.cpp
Normal file
File diff suppressed because it is too large
Load Diff
215
Minecraft.Client/Orbis/Network/SonyVoiceChat_Orbis.h
Normal file
215
Minecraft.Client/Orbis/Network/SonyVoiceChat_Orbis.h
Normal file
@@ -0,0 +1,215 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <voice_qos.h>
|
||||
#include "Common/Network/Sony/SQRNetworkPlayer.h"
|
||||
|
||||
static const int sc_maxVoiceDataSize = 2048;
|
||||
|
||||
|
||||
class VoicePacket
|
||||
{
|
||||
static const int MAX_LOCAL_PLAYER_COUNT = 4;
|
||||
|
||||
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];
|
||||
}
|
||||
void verifyData(int packetSize, int frameSize)
|
||||
{
|
||||
if(m_numFrames == 0)
|
||||
return;
|
||||
int dataSize = m_numFrames*frameSize;
|
||||
assert(packetSize == getPacketSize(dataSize));
|
||||
int checkSum = 0;
|
||||
for(int i=0;i<dataSize;i++)
|
||||
checkSum += m_data[i];
|
||||
assert(checkSum == m_checkSum);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// 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;
|
||||
uint8_t m_localConnections[4]; // connection between this devices mic and other local player's headsets
|
||||
bool m_bChatRestricted;
|
||||
bool m_bFlaggedForShutdown;
|
||||
SceUserServiceUserId m_localUserID;
|
||||
|
||||
public:
|
||||
SQRLocalVoiceDevice()
|
||||
: m_headsetPort(SCE_VOICE_INVALID_PORT_ID)
|
||||
, m_microphonePort(SCE_VOICE_INVALID_PORT_ID)
|
||||
, m_localUserID(SCE_USER_SERVICE_USER_ID_INVALID)
|
||||
{
|
||||
for(int i=0;i<4;i++)
|
||||
m_localConnections[i] = 0;
|
||||
}
|
||||
|
||||
void init(SceUserServiceUserId localUserID, bool bChatRestricted);
|
||||
void flagForShutdown() { m_bFlaggedForShutdown = true;}
|
||||
void shutdownWhenFlagged();
|
||||
bool isValid() { return m_localUserID != SCE_USER_SERVICE_USER_ID_INVALID; }
|
||||
// void setBitRate()
|
||||
// {
|
||||
// int err = sceVoiceSetBitRate(uint32_t portId,
|
||||
// SceVoiceBitRate bitrate
|
||||
// );
|
||||
// }
|
||||
};
|
||||
|
||||
#define VOICE_ENCODED_FORMAT SCE_VOICE_BITRATE_7300
|
||||
|
||||
|
||||
|
||||
class SQRVoiceConnection
|
||||
{
|
||||
static const int MAX_LOCAL_PLAYER_COUNT = 4;
|
||||
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_Orbis
|
||||
{
|
||||
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 = 4;
|
||||
|
||||
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