1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
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;
}
}
|