Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1098 lines
28 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1999
  6. //
  7. // File: dplay4obj.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. // _dxj_DirectPlay2Obj.cpp : Implementation of C_dxj_DirectPlay2Object
  11. // DHF begin - entire file
  12. #include "stdafx.h"
  13. #include "Direct.h"
  14. #include "dms.h"
  15. #include "dPlay.h"
  16. #include "DPAddressObj.h"
  17. #include "DPLConnectionObj.h"
  18. #include "dPlay4Obj.h"
  19. #include "DPEnumPlayersObj.h"
  20. #include "DPEnumSessionsObj.h"
  21. #include "DPEnumConnectionsObj.h"
  22. #include "dpMsgObj.h"
  23. #include "dpSessDataObj.h"
  24. typedef HRESULT (__stdcall *DIRECTPLAYCREATE)( LPGUID lpGUID, LPDIRECTPLAY *lplpDP, IUnknown *pUnk);
  25. extern DIRECTPLAYCREATE pDirectPlayCreate;
  26. typedef HRESULT (__stdcall *DIRECTPLAYENUMERATE)( LPDPENUMDPCALLBACK, LPVOID );
  27. extern DIRECTPLAYENUMERATE pDirectPlayEnumerate;
  28. extern HRESULT FillRealSessionDesc(DPSESSIONDESC2 *dpSessionDesc,DPSessionDesc2 *sessionDesc);
  29. extern void FillCoverSessionDesc(DPSessionDesc2 *sessionDesc,DPSESSIONDESC2 *dpSessionDesc);
  30. extern HRESULT BSTRtoGUID(LPGUID,BSTR);
  31. extern HRESULT BSTRtoPPGUID(LPGUID*,BSTR);
  32. extern BSTR GUIDtoBSTR(LPGUID);
  33. extern void *g_dxj_DirectPlay4;
  34. C_dxj_DirectPlay4Object::C_dxj_DirectPlay4Object()
  35. {
  36. m__dxj_DirectPlay4 = NULL;
  37. parent = NULL;
  38. nextobj = g_dxj_DirectPlay4;
  39. g_dxj_DirectPlay4 = this;
  40. creationid = ++g_creationcount;
  41. }
  42. DESTRUCTOR(_dxj_DirectPlay4, {})
  43. GETSET_OBJECT(_dxj_DirectPlay4);
  44. //
  45. /*** I_dxj_DirectPlay4 methods ***/
  46. //
  47. PASS_THROUGH_CAST_2_R(_dxj_DirectPlay4, addPlayerToGroup, AddPlayerToGroup, Dpid,(DPID), Dpid,(DPID));
  48. PASS_THROUGH_R(_dxj_DirectPlay4, close, Close);
  49. //PASS_THROUGH_CAST_1_R(_dxj_DirectPlay4, initialize, Initialize, DxGuid*, (LPGUID));
  50. PASS_THROUGH_CAST_2_R(_dxj_DirectPlay4, deletePlayerFromGroup, DeletePlayerFromGroup, Dpid, (DPID), Dpid, (DPID));
  51. PASS_THROUGH_CAST_1_R(_dxj_DirectPlay4, destroyPlayer, DestroyPlayer, Dpid,(DPID));
  52. PASS_THROUGH_CAST_1_R(_dxj_DirectPlay4, destroyGroup, DestroyGroup, Dpid,(DPID));
  53. PASS_THROUGH_CAST_2_R(_dxj_DirectPlay4, getMessageCount, GetMessageCount, Dpid,(DPID), long *,(DWORD*));
  54. //PASS_THROUGH_CAST_3_R(_dxj_DirectPlay4, getPlayerCaps, GetPlayerCaps, Dpid, (DPID), DPCaps*, (DPCAPS*), long, (DWORD));
  55. //PASS_THROUGH_CAST_2_R(_dxj_DirectPlay4, startSession, StartSession, long, (DWORD), Dpid, (DPID));
  56. //PASS_THROUGH_CAST_3_R(_dxj_DirectPlay4, getPlayerCaps, GetPlayerCaps, Dpid, (DPID), DPCaps*, (DPCAPS*), long, (DWORD));
  57. //PASS_THROUGH_CAST_2_R(_dxj_DirectPlay4, getCaps, GetCaps, DPCaps*, (LPDPCAPS), long, (DWORD));
  58. STDMETHODIMP C_dxj_DirectPlay4Object::getCaps(DPCaps *c,long flags){
  59. if (!c) return E_INVALIDARG;
  60. c->lSize=sizeof(DPCAPS);
  61. HRESULT hr = m__dxj_DirectPlay4->GetCaps((DPCAPS*)c,(DWORD)flags);
  62. return hr;
  63. }
  64. STDMETHODIMP C_dxj_DirectPlay4Object::startSession(Dpid id){
  65. HRESULT hr = m__dxj_DirectPlay4->StartSession(0,(DPID)id);
  66. return hr;
  67. }
  68. STDMETHODIMP C_dxj_DirectPlay4Object::getPlayerCaps(Dpid id, DPCaps *caps, long flags)
  69. {
  70. ((DPCAPS*)caps)->dwSize=sizeof(DPCAPS);
  71. HRESULT hr = m__dxj_DirectPlay4->GetPlayerCaps((DPID)id,(DPCAPS*)caps,(DWORD)flags);
  72. return hr;
  73. }
  74. /////////////////////////////////////////////////////////////////////////////
  75. STDMETHODIMP C_dxj_DirectPlay4Object::createGroup(
  76. /* [in] */ BSTR friendlyName,
  77. /* [in] */ BSTR formalName,
  78. long flags,
  79. /* [retval][out] */ Dpid *v1)
  80. {
  81. if ( m__dxj_DirectPlay4 == NULL ) return E_FAIL;
  82. DPNAME dpName;
  83. ZeroMemory(&dpName,sizeof(DPNAME));
  84. dpName.dwSize = sizeof(dpName);
  85. if ((!friendlyName) ||(!formalName)) return E_INVALIDARG;
  86. if (0==_wcsicmp(friendlyName,formalName)) return E_INVALIDARG;
  87. if ( friendlyName[0]!=0 )
  88. {
  89. dpName.lpszShortName = (LPWSTR)alloca(sizeof(WCHAR)*(wcslen(friendlyName)+1));
  90. wcscpy(dpName.lpszShortName, friendlyName);
  91. }
  92. if ( formalName[0]!=0 )
  93. {
  94. dpName.lpszLongName = (LPWSTR)alloca(sizeof(WCHAR)*(wcslen(formalName)+1));
  95. wcscpy(dpName.lpszLongName, formalName);
  96. }
  97. HRESULT hr = m__dxj_DirectPlay4->CreateGroup((DWORD*)v1, &dpName, NULL, 0, (DWORD)flags);
  98. return hr;
  99. }
  100. /////////////////////////////////////////////////////////////////////////////
  101. STDMETHODIMP C_dxj_DirectPlay4Object::createPlayer(
  102. /* [in] */ BSTR friendlyName,
  103. /* [in] */ BSTR formalName,
  104. /* [in] */ long receiveEvent,
  105. /* [in] */ long flags,
  106. /* [retval][out] */ Dpid __RPC_FAR *v1)
  107. {
  108. if ( m__dxj_DirectPlay4 == NULL ) return E_FAIL;
  109. DPNAME dpName;
  110. ZeroMemory(&dpName,sizeof(DPNAME));
  111. dpName.dwSize = sizeof(DPNAME);
  112. if ((!friendlyName) ||(!formalName)) return E_INVALIDARG;
  113. if (0==_wcsicmp(friendlyName,formalName)) return E_INVALIDARG;
  114. if ( friendlyName[0]!=0 )
  115. {
  116. dpName.lpszShortName = (LPWSTR)friendlyName;
  117. //dpName.lpszShortName = (LPWSTR)alloca(sizeof(WCHAR)*(wcslen(friendlyName)+1));
  118. //wcscpy(dpName.lpszShortName, friendlyName);
  119. }
  120. if ( formalName[0]!=0 )
  121. {
  122. //dpName.lpszLongName = (LPWSTR)alloca(sizeof(WCHAR)*(wcslen(formalName)+1));
  123. //wcscpy(dpName.lpszLongName, formalName);
  124. dpName.lpszLongName = (LPWSTR)formalName;
  125. }
  126. HRESULT hr = m__dxj_DirectPlay4->CreatePlayer((DWORD*)v1, &dpName, (LPVOID)receiveEvent, NULL, 0, (DWORD)flags);
  127. //if (dpName.lpszShortName) free(dpName.lpszShortName);
  128. //if (dpName.lpszLongName) free(dpName.lpszLongName);
  129. return hr;
  130. }
  131. //////////////////////////////////////////////////////////////////////////
  132. STDMETHODIMP C_dxj_DirectPlay4Object::getDPEnumGroupPlayers(
  133. Dpid groupPID,
  134. BSTR strGuid,
  135. long flags,
  136. I_dxj_DPEnumPlayers2 **retVal){
  137. HRESULT hr=C_dxj_DPEnumPlayersObject::create(m__dxj_DirectPlay4,DPENUMGROUPPLAYERS,groupPID,strGuid,flags,retVal);
  138. return hr;
  139. }
  140. //////////////////////////////////////////////////////////////////////////
  141. STDMETHODIMP C_dxj_DirectPlay4Object::getDPEnumGroups(
  142. BSTR strGuid,
  143. long flags,
  144. I_dxj_DPEnumPlayers2 **retVal){
  145. HRESULT hr=C_dxj_DPEnumPlayersObject::create(m__dxj_DirectPlay4,DPENUMGROUPS,0,strGuid,flags,retVal);
  146. return hr;
  147. }
  148. //////////////////////////////////////////////////////////////////////////
  149. STDMETHODIMP C_dxj_DirectPlay4Object::getDPEnumGroupsInGroup(
  150. Dpid groupPID,
  151. BSTR strGuid,
  152. long flags,
  153. I_dxj_DPEnumPlayers2 **retVal){
  154. HRESULT hr=C_dxj_DPEnumPlayersObject::create(m__dxj_DirectPlay4,DPENUMGROUPSINGROUP,groupPID,strGuid,flags,retVal);
  155. return hr;
  156. }
  157. //////////////////////////////////////////////////////////////////////////
  158. STDMETHODIMP C_dxj_DirectPlay4Object::getDPEnumPlayers(
  159. BSTR strGuid,
  160. long flags,
  161. I_dxj_DPEnumPlayers2 **retVal){
  162. HRESULT hr=C_dxj_DPEnumPlayersObject::create(m__dxj_DirectPlay4,DPENUMPLAYERS,0,strGuid,flags,retVal);
  163. return hr;
  164. }
  165. //////////////////////////////////////////////////////////////////////////
  166. // USE void because we can accept null in VB
  167. STDMETHODIMP C_dxj_DirectPlay4Object::getDPEnumSessions(
  168. I_dxj_DirectPlaySessionData *sessionDesc,
  169. long timeout,
  170. long flags,
  171. I_dxj_DPEnumSessions2 **retVal)
  172. {
  173. HRESULT hr=C_dxj_DPEnumSessionsObject::create(m__dxj_DirectPlay4,sessionDesc,timeout,flags,retVal);
  174. return hr;
  175. }
  176. //////////////////////////////////////////////////////////////////////////
  177. STDMETHODIMP C_dxj_DirectPlay4Object::getGroupData( Dpid id,long flags, BSTR *ret)
  178. {
  179. DWORD size;
  180. HRESULT hr;
  181. void *pData=NULL;
  182. //ASSERT ( m__dxj_DirectPlay4 != NULL )
  183. if (!ret) return E_INVALIDARG;
  184. hr= m__dxj_DirectPlay4->GetGroupData((DWORD)id, (void*)NULL, (LPDWORD)&size, (DWORD)flags);
  185. if (size==0) {
  186. *ret=NULL;
  187. return S_OK;
  188. }
  189. //we only want data we can cast to a string
  190. if ((size % 2)!=0) return E_INVALIDARG;
  191. pData=malloc(size+2);
  192. if (!pData) return E_OUTOFMEMORY;
  193. //null terminate.
  194. ((char*)pData)[size]='\0';
  195. ((char*)pData)[size+1]='\0';
  196. hr= m__dxj_DirectPlay4->GetGroupData((DWORD)id, (void*)pData, (LPDWORD)&size, (DWORD)flags);
  197. if FAILED(hr) {
  198. if (pData) free(pData);
  199. return hr;
  200. }
  201. *ret=SysAllocString((WCHAR*)pData);
  202. if (pData) free(pData);
  203. return hr;
  204. }
  205. //////////////////////////////////////////////////////////////////////////
  206. STDMETHODIMP C_dxj_DirectPlay4Object::getGroupShortName(Dpid id, BSTR *friendlyN)
  207. {
  208. DWORD dwDataSize;
  209. if ( m__dxj_DirectPlay4 == NULL )
  210. return E_FAIL;
  211. if(!friendlyN) return E_INVALIDARG;
  212. *friendlyN=NULL;
  213. HRESULT hr=m__dxj_DirectPlay4->GetGroupName(id, (char*)NULL, &dwDataSize);
  214. if (dwDataSize<sizeof(DPNAME)) return E_INVALIDARG;
  215. // Supply the stack based buffers needed by DIRECTX
  216. LPDPNAME dpName = (LPDPNAME)alloca(dwDataSize);
  217. ZeroMemory(dpName,dwDataSize);
  218. dpName->dwSize=sizeof(DPNAME);
  219. hr = m__dxj_DirectPlay4->GetGroupName((DPID)id, dpName, &dwDataSize);
  220. if FAILED(hr) return hr;
  221. *friendlyN = SysAllocString(dpName->lpszShortName);
  222. return hr;
  223. }
  224. /////////////////////////////////////////////////////////////////////////////
  225. STDMETHODIMP C_dxj_DirectPlay4Object::getGroupLongName(Dpid id, BSTR *formalN)
  226. {
  227. DWORD dwDataSize=0;
  228. if ( m__dxj_DirectPlay4 == NULL )
  229. return E_FAIL;
  230. if(!formalN) return E_INVALIDARG;
  231. *formalN=NULL;
  232. HRESULT hr=m__dxj_DirectPlay4->GetGroupName(id, (char*)NULL, &dwDataSize);
  233. if (dwDataSize<sizeof(DPNAME)) return E_INVALIDARG;
  234. // Supply the stack based buffers needed by DIRECTX
  235. LPDPNAME dpName = (LPDPNAME)alloca(dwDataSize);
  236. ZeroMemory(dpName,dwDataSize);
  237. dpName->dwSize=sizeof(DPNAME);
  238. hr = m__dxj_DirectPlay4->GetGroupName(id, dpName, &dwDataSize);
  239. if FAILED(hr) return hr;
  240. *formalN = SysAllocString(dpName->lpszLongName);
  241. return hr;
  242. }
  243. //////////////////////////////////////////////////////////////////////////
  244. // Gets a DirectPlay abstract address using a player id
  245. //////////////////////////////////////////////////////////////////////////
  246. STDMETHODIMP C_dxj_DirectPlay4Object::getPlayerAddress(
  247. /* [in] */ Dpid id,
  248. /* [out] */ I_dxj_DPAddress **ret)
  249. {
  250. if ( m__dxj_DirectPlay4 == NULL ) return E_FAIL;
  251. void *pAddress;
  252. DWORD size=0;
  253. HRESULT hr;
  254. hr= m__dxj_DirectPlay4->GetPlayerAddress((DPID)id, NULL,&size);
  255. if (size==0) return E_FAIL;
  256. pAddress=malloc(size);
  257. if (pAddress==NULL) return E_OUTOFMEMORY;
  258. hr= m__dxj_DirectPlay4->GetPlayerAddress((DPID)id,pAddress,&size);
  259. if FAILED(hr){
  260. free(pAddress);
  261. return hr;
  262. }
  263. INTERNAL_CREATE_STRUCT(_dxj_DPAddress,ret);
  264. if (*ret==NULL) return E_OUTOFMEMORY;
  265. hr=(*ret)->setAddress((long)PtrToLong(pAddress),size); //bugbug SUNDOWN
  266. free(pAddress);
  267. return hr;
  268. }
  269. //////////////////////////////////////////////////////////////////////////
  270. STDMETHODIMP C_dxj_DirectPlay4Object::getPlayerData(
  271. /* [in] */ Dpid id,
  272. long flags,
  273. /* [out] */ BSTR *ret)
  274. {
  275. DWORD size;
  276. HRESULT hr;
  277. void *pData=NULL;
  278. //ASSERT ( m__dxj_DirectPlay4 != NULL )
  279. hr=m__dxj_DirectPlay4->GetPlayerData((DWORD)id, (void*)NULL, (LPDWORD)&size, (DWORD)flags);
  280. if (size==0) {
  281. *ret=NULL;
  282. return S_OK;
  283. }
  284. //we only want data we can cast to a string
  285. if ((size % 2)!=0) return E_INVALIDARG;
  286. pData=malloc(size+sizeof(WCHAR));
  287. if (!pData) return E_OUTOFMEMORY;
  288. ZeroMemory(pData,size+sizeof(WCHAR));
  289. hr= m__dxj_DirectPlay4->GetPlayerData((DWORD)id, (void*)pData, (LPDWORD)&size, (DWORD)flags);
  290. if FAILED(hr) {
  291. if (pData) free(pData);
  292. }
  293. *ret=SysAllocString((WCHAR*)pData);
  294. if (pData) free(pData);
  295. return hr;
  296. }
  297. //////////////////////////////////////////////////////////////////////////
  298. STDMETHODIMP C_dxj_DirectPlay4Object::getPlayerFriendlyName(Dpid id, BSTR *friendlyN)
  299. {
  300. if ( m__dxj_DirectPlay4 == NULL )
  301. return E_FAIL;
  302. DWORD dwDataSize;
  303. HRESULT hr;
  304. hr=m__dxj_DirectPlay4->GetPlayerName((DPID)id, (char*)NULL, &dwDataSize);
  305. // Supply the stack based buffers needed by DIRECTX
  306. LPDPNAME dpName = (LPDPNAME)alloca(dwDataSize);
  307. ZeroMemory(dpName,dwDataSize);
  308. dpName->dwSize=sizeof(DPNAME);
  309. hr = m__dxj_DirectPlay4->GetPlayerName((DPID)id, dpName, &dwDataSize);
  310. if FAILED(hr) return hr;
  311. *friendlyN = SysAllocString(dpName->lpszShortName);
  312. return hr;
  313. }
  314. /////////////////////////////////////////////////////////////////////////////
  315. STDMETHODIMP C_dxj_DirectPlay4Object::getPlayerFormalName(Dpid id, BSTR *formalN)
  316. {
  317. if ( m__dxj_DirectPlay4 == NULL )
  318. return E_FAIL;
  319. DWORD dwDataSize;
  320. HRESULT hr;
  321. hr=m__dxj_DirectPlay4->GetPlayerName((DPID)id, (char*)NULL, &dwDataSize);
  322. //// Supply the stack based buffers needed by DIRECTX
  323. LPDPNAME dpName = (LPDPNAME)alloca(dwDataSize); // ANSI buffer on stack;
  324. ZeroMemory(dpName,dwDataSize);
  325. dpName->dwSize=sizeof(DPNAME);
  326. hr=m__dxj_DirectPlay4->GetPlayerName((DPID)id, dpName, &dwDataSize); // get ANSI
  327. if FAILED(hr) return hr;
  328. *formalN = SysAllocString(dpName->lpszLongName);
  329. return hr;
  330. }
  331. //////////////////////////////////////////////////////////////////////////
  332. // Gets the current session description
  333. //////////////////////////////////////////////////////////////////////////
  334. STDMETHODIMP C_dxj_DirectPlay4Object::getSessionDesc(
  335. /* [out] */ I_dxj_DirectPlaySessionData __RPC_FAR **sessionDesc)
  336. {
  337. if ( m__dxj_DirectPlay4 == NULL )
  338. return E_FAIL;
  339. if ( sessionDesc == NULL )
  340. return E_FAIL;
  341. DWORD dataSize = 0;
  342. HRESULT hr = m__dxj_DirectPlay4->GetSessionDesc(NULL, &dataSize);
  343. LPVOID data = alloca(dataSize);
  344. hr = m__dxj_DirectPlay4->GetSessionDesc((LPVOID)data, &dataSize);
  345. if(hr != DP_OK) {
  346. return hr;
  347. }
  348. LPDPSESSIONDESC2 dpSessionDesc = (LPDPSESSIONDESC2)data;
  349. hr=C_dxj_DirectPlaySessionDataObject::create(dpSessionDesc,sessionDesc);
  350. return hr;
  351. }
  352. //////////////////////////////////////////////////////////////////////////
  353. // Establish a gaming session instance - create or join a game session
  354. //////////////////////////////////////////////////////////////////////////
  355. STDMETHODIMP C_dxj_DirectPlay4Object::open(I_dxj_DirectPlaySessionData *sessionDesc, long flags)
  356. {
  357. if ( m__dxj_DirectPlay4 == NULL )
  358. return E_FAIL;
  359. if ( sessionDesc == NULL )
  360. return E_INVALIDARG;
  361. DPSESSIONDESC2 dpSessionDesc;
  362. //CONSIDER - validating sessiondesc object
  363. // to return friendly error
  364. sessionDesc->AddRef();
  365. sessionDesc->getData(&dpSessionDesc);
  366. HRESULT hr = m__dxj_DirectPlay4->Open(&dpSessionDesc, flags);
  367. //SysFreeString(dpSessionDesc.lpszPassword);
  368. //SysFreeString(dpSessionDesc.lpszSessionName);
  369. sessionDesc->Release();
  370. if FAILED(hr) return hr;
  371. //FillCoverSessionDesc(sessionDesc,&dpSessionDesc);
  372. return hr;
  373. }
  374. //////////////////////////////////////////////////////////////////////////
  375. STDMETHODIMP C_dxj_DirectPlay4Object::receive(
  376. /* [in, out] */ Dpid *fromPlayerId,
  377. /* [in, out] */ Dpid *toPlayerId,
  378. /* [in] */ long flags,
  379. I_dxj_DirectPlayMessage **msg )
  380. {
  381. HRESULT hr;
  382. DWORD dwSize=0;
  383. void *pData=NULL;
  384. //#pragma message ("check with DPLAY folks if this is necessary")
  385. //DONE: The loop is not neccesary..
  386. //aaronO indicated the message order is consistent
  387. //a call to recieve to get the size can always be folowed by a call to get
  388. //the message - ANDREWKE
  389. //
  390. //BOOL fCont=TRUE;
  391. //while (fCont){
  392. hr = m__dxj_DirectPlay4->Receive((DPID*)fromPlayerId, (DPID*)toPlayerId, (DWORD)flags, NULL, &dwSize);
  393. //fix for manbug24192
  394. if (hr == DPERR_NOMESSAGES ) {
  395. *msg=NULL;
  396. return S_OK;
  397. }
  398. if (hr!=DPERR_BUFFERTOOSMALL) return hr;
  399. hr=C_dxj_DirectPlayMessageObject::create((DWORD)*fromPlayerId,dwSize,&pData,msg);
  400. if FAILED(hr) return hr;
  401. hr = m__dxj_DirectPlay4->Receive((DPID*)fromPlayerId, (DPID*)toPlayerId, (DWORD)flags,pData, &dwSize);
  402. //should never hit this
  403. // if ( hr == DPERR_BUFFERTOOSMALL){
  404. // fCont=TRUE;
  405. // (*msg)->Release();
  406. //
  407. // }
  408. // else{
  409. // fCont=FALSE;
  410. // }
  411. //} end while
  412. if FAILED(hr) {
  413. if (*msg) (*msg)->Release();
  414. *msg=NULL;
  415. }
  416. return hr;
  417. }
  418. /////////////////////////////////////////////////////////////////////////////
  419. STDMETHODIMP C_dxj_DirectPlay4Object::receiveSize(
  420. /* [in,out] */ Dpid *fromPlayerId,
  421. /* [in,out] */ Dpid *toPlayerId,
  422. /* [in] */ long flags,
  423. /* [retval][out] */ int *dataSize)
  424. {
  425. if ( m__dxj_DirectPlay4 == NULL )
  426. return E_FAIL;
  427. unsigned long *id1 = 0, *id2 = 0;
  428. HRESULT hr = m__dxj_DirectPlay4->Receive((DPID*)fromPlayerId, (DPID*)toPlayerId,
  429. (DWORD)flags, (void*)NULL, (LPDWORD)dataSize);
  430. if ( hr == DPERR_BUFFERTOOSMALL || hr == DPERR_NOMESSAGES )
  431. hr = S_OK;
  432. return hr;
  433. }
  434. /////////////////////////////////////////////////////////////////////////////
  435. STDMETHODIMP C_dxj_DirectPlay4Object::send(
  436. /* [in] */ Dpid fromPlayerId,
  437. /* [in] */ Dpid toPlayerId,
  438. /* [in] */ long flags,
  439. /* [in] */ I_dxj_DirectPlayMessage *msg)
  440. {
  441. HRESULT hr;
  442. void *pdata=NULL;
  443. DWORD dataSize=0;
  444. if (!msg) return E_INVALIDARG;
  445. __try {
  446. msg->getPointer((long*)&pdata);
  447. msg->getMessageSize((long*)&dataSize);
  448. hr= m__dxj_DirectPlay4->Send((DPID)fromPlayerId, (DPID)toPlayerId, (DWORD)flags,
  449. (void*)pdata, (DWORD) dataSize);
  450. }
  451. __except (1,1)
  452. {
  453. return E_INVALIDARG;
  454. }
  455. return hr;
  456. }
  457. //////////////////////////////////////////////////////////////////////////
  458. STDMETHODIMP C_dxj_DirectPlay4Object::setGroupData(
  459. /* [in] */ long id,
  460. /* [in] */ BSTR data,
  461. /* [in] */ long flags)
  462. {
  463. HRESULT hr;
  464. DWORD datasize=0;
  465. void *pdata=NULL;
  466. if (data){
  467. pdata=data;
  468. datasize= ((DWORD*)data)[-1];
  469. }
  470. __try {
  471. hr = m__dxj_DirectPlay4->SetGroupData((DPID)id,(void*)pdata,
  472. (DWORD)datasize, (DWORD)flags);
  473. }
  474. __except(1,1){
  475. return E_INVALIDARG;
  476. }
  477. return hr;
  478. }
  479. /////////////////////////////////////////////////////////////////////////////
  480. STDMETHODIMP C_dxj_DirectPlay4Object::setGroupName(
  481. /* [in] */ Dpid id,
  482. /* [in] */ BSTR friendlyName,
  483. /* [in] */ BSTR formalName,
  484. /* [in] */ long flags)
  485. {
  486. //ASSERT( m__dxj_DirectPlay4 != NULL )
  487. DPNAME dpName;
  488. ZeroMemory(&dpName,sizeof(DPNAME));
  489. dpName.dwSize = sizeof(DPNAME);
  490. dpName.lpszShortName=NULL;
  491. dpName.lpszLongName=NULL;
  492. if ( friendlyName )
  493. {
  494. dpName.lpszShortName = friendlyName;
  495. }
  496. if ( formalName )
  497. {
  498. dpName.lpszLongName = formalName;
  499. }
  500. HRESULT hr = m__dxj_DirectPlay4->SetGroupName((DPID)id, &dpName, flags);
  501. return hr;
  502. }
  503. //////////////////////////////////////////////////////////////////////////
  504. STDMETHODIMP C_dxj_DirectPlay4Object::setPlayerData(
  505. /* [in] */ long id,
  506. /* [in] */ BSTR data,
  507. /* [in] */ long flags)
  508. {
  509. HRESULT hr;
  510. DWORD datasize=0;
  511. void *pdata=NULL;
  512. if (data){
  513. if (data[0]!=0x00) {
  514. pdata=data;
  515. datasize= ((DWORD*)data)[-1];
  516. }
  517. }
  518. __try {
  519. hr = m__dxj_DirectPlay4->SetPlayerData((DPID)id,(void*)pdata,
  520. (DWORD)datasize, (DWORD)flags);
  521. }
  522. __except(1,1){
  523. return E_INVALIDARG;
  524. }
  525. return hr;
  526. }
  527. /////////////////////////////////////////////////////////////////////////////
  528. STDMETHODIMP C_dxj_DirectPlay4Object::setPlayerName(
  529. /* [in] */ Dpid id,
  530. /* [in] */ BSTR friendlyName,
  531. /* [in] */ BSTR formalName,
  532. /* [in] */ long flags)
  533. {
  534. if ( m__dxj_DirectPlay4 == NULL )
  535. return E_FAIL;
  536. DWORD l=0;
  537. DPNAME dpName;
  538. ZeroMemory(&dpName,sizeof(DPNAME)) ;
  539. dpName.dwSize=sizeof(DPNAME);
  540. dpName.lpszShortName = friendlyName;
  541. dpName.lpszLongName = formalName;
  542. HRESULT hr = m__dxj_DirectPlay4->SetPlayerName((DPID) id, &dpName, (DWORD)flags);
  543. return hr;
  544. }
  545. //////////////////////////////////////////////////////////////////////////
  546. // Sets the current session description
  547. //////////////////////////////////////////////////////////////////////////
  548. STDMETHODIMP C_dxj_DirectPlay4Object::setSessionDesc(
  549. /* [in] */ I_dxj_DirectPlaySessionData __RPC_FAR *sessionDesc
  550. )
  551. {
  552. if ( m__dxj_DirectPlay4 == NULL )
  553. return E_FAIL;
  554. if (!sessionDesc) return E_INVALIDARG;
  555. DPSESSIONDESC2 dpSessionDesc;
  556. sessionDesc->AddRef();
  557. sessionDesc->getData(&dpSessionDesc);
  558. HRESULT hr = m__dxj_DirectPlay4->SetSessionDesc(&dpSessionDesc, 0);
  559. sessionDesc->Release();
  560. return hr;
  561. }
  562. STDMETHODIMP C_dxj_DirectPlay4Object::setGroupConnectionSettings(// long flags,
  563. Dpid idGroup, I_dxj_DPLConnection *connect)
  564. {
  565. DPLCONNECTION *con;
  566. connect->getConnectionStruct((long*)&con);
  567. HRESULT hr = m__dxj_DirectPlay4->SetGroupConnectionSettings((DWORD)0,(DPID) idGroup,con);
  568. return hr;
  569. }
  570. STDMETHODIMP C_dxj_DirectPlay4Object::sendChatMessage(
  571. Dpid fromPlayerId, Dpid toPlayerId, long flags, BSTR message)
  572. {
  573. DPCHAT dpChat;
  574. dpChat.dwSize=sizeof(DPCHAT);
  575. dpChat.dwFlags=(DWORD)0;
  576. dpChat.lpszMessage=message;
  577. HRESULT hr = m__dxj_DirectPlay4->SendChatMessage((DPID)fromPlayerId,(DPID)toPlayerId,(DWORD)flags,&dpChat);
  578. return hr;
  579. }
  580. STDMETHODIMP C_dxj_DirectPlay4Object::secureOpen(I_dxj_DirectPlaySessionData *desc,
  581. long flags, DPSecurityDesc *security, DPCredentials *credentials){
  582. DPSESSIONDESC2 dpSessionDesc;
  583. DPSECURITYDESC dpSecurity;
  584. DPCREDENTIALS dpCredentials;
  585. LPCDPSECURITYDESC lpSecurity=NULL;
  586. LPCDPCREDENTIALS lpCredentials=NULL;
  587. DWORD l=0,i,j;
  588. if (desc==NULL) return E_INVALIDARG;
  589. //FillRealSessionDesc(&dpSessionDesc,desc);
  590. ZeroMemory((void*)&dpSecurity,sizeof(DPSECURITYDESC));
  591. ZeroMemory((void*)&dpCredentials,sizeof(DPCREDENTIALS));
  592. if (security){
  593. //if all members are NULL then replace with null pointer
  594. j=0;
  595. for (i=0;i<sizeof(DPSecurityDesc);i++){
  596. if (((char*)security)[i]==0) j++;
  597. }
  598. if (j!=sizeof(DPSecurityDesc)){
  599. dpSecurity.dwSize=sizeof(DPSECURITYDESC);
  600. l=0;l=wcslen(security->strSSPIProvider);
  601. if (l){
  602. dpSecurity.lpszSSPIProvider = SysAllocString(security->strSSPIProvider);
  603. }
  604. l=0;l=wcslen(security->strCAPIProvider);
  605. if (l){
  606. dpSecurity.lpszCAPIProvider = SysAllocString(security->strCAPIProvider);
  607. }
  608. lpSecurity=&dpSecurity;
  609. }
  610. }
  611. if (credentials){
  612. //if all members are NULL then replace with null pointer
  613. j=0;
  614. for (i=0;i<sizeof(DPCredentials);i++){
  615. if (((char*)credentials)[i]==0) j++;
  616. }
  617. if (j!=sizeof(DPCredentials)){
  618. dpCredentials.dwSize=sizeof(DPCREDENTIALS);
  619. l=0;l=wcslen(credentials->strUsername);
  620. if (l){
  621. //dpCredentials.lpszUsername = (LPWSTR)alloca(sizeof(WCHAR)*(l+1));
  622. //wcscpy(dpCredentials.lpszUsername , credentials->username);
  623. dpCredentials.lpszUsername=SysAllocString(credentials->strUsername);
  624. }
  625. l=0;l=wcslen(credentials->strPassword);
  626. if (l){
  627. //dpCredentials.lpszPassword = (LPWSTR)alloca(sizeof(WCHAR)*(l+1));
  628. //wcscpy(dpCredentials.lpszPassword , credentials->password);
  629. dpCredentials.lpszPassword = SysAllocString(credentials->strPassword);
  630. }
  631. l=0;l=wcslen(credentials->strDomain);
  632. if (l){
  633. //dpCredentials.lpszDomain = (LPWSTR)alloca(sizeof(WCHAR)*(l+1));
  634. //wcscpy(dpCredentials.lpszDomain , credentials->domain);
  635. dpCredentials.lpszDomain = SysAllocString(credentials->strDomain);
  636. }
  637. lpSecurity=&dpSecurity;
  638. }
  639. }
  640. desc->AddRef();
  641. desc->getData(&dpSessionDesc);
  642. HRESULT hr = m__dxj_DirectPlay4->SecureOpen(&dpSessionDesc,(DWORD)flags,
  643. lpSecurity, lpCredentials);
  644. desc->Release();
  645. if (dpCredentials.lpszDomain) SysFreeString(dpCredentials.lpszDomain);
  646. if (dpCredentials.lpszPassword) SysFreeString(dpCredentials.lpszPassword);
  647. if (dpCredentials.lpszUsername) SysFreeString(dpCredentials.lpszUsername);
  648. if (dpSecurity.lpszSSPIProvider)SysFreeString(dpSecurity.lpszSSPIProvider);
  649. if (dpSecurity.lpszCAPIProvider)SysFreeString(dpSecurity.lpszCAPIProvider);
  650. return hr;
  651. }
  652. STDMETHODIMP C_dxj_DirectPlay4Object::getPlayerFlags(Dpid id, long *ret){
  653. HRESULT hr = m__dxj_DirectPlay4->GetPlayerFlags((DPID)id,(DWORD*)ret);
  654. return hr;
  655. }
  656. STDMETHODIMP C_dxj_DirectPlay4Object::getGroupFlags(Dpid id, long *ret){
  657. HRESULT hr = m__dxj_DirectPlay4->GetGroupFlags((DPID)id,(DWORD*)ret);
  658. return hr;
  659. }
  660. STDMETHODIMP C_dxj_DirectPlay4Object::getGroupParent(Dpid id, long *ret){
  661. HRESULT hr = m__dxj_DirectPlay4->GetGroupParent((DPID)id,(DPID*)ret);
  662. return hr;
  663. }
  664. STDMETHODIMP C_dxj_DirectPlay4Object::deleteGroupFromGroup(Dpid id, Dpid id2){
  665. HRESULT hr = m__dxj_DirectPlay4->DeleteGroupFromGroup((DPID)id,(DPID)id2);
  666. return hr;
  667. }
  668. STDMETHODIMP C_dxj_DirectPlay4Object::addGroupToGroup(Dpid id, Dpid id2){
  669. HRESULT hr = m__dxj_DirectPlay4->AddGroupToGroup((DPID)id,(DPID)id2);
  670. return hr;
  671. }
  672. STDMETHODIMP C_dxj_DirectPlay4Object::getPlayerAccountId(Dpid id, BSTR *ret){
  673. LPDPACCOUNTDESC pdesc;
  674. HRESULT hr;
  675. DWORD size=0;
  676. hr=m__dxj_DirectPlay4->GetPlayerAccount((DPID)id,0,NULL,&size);
  677. if (size==0) return E_FAIL;
  678. pdesc=(LPDPACCOUNTDESC)malloc(size);
  679. if (!pdesc) return E_OUTOFMEMORY;
  680. hr=m__dxj_DirectPlay4->GetPlayerAccount((DPID)id,0,(void*)pdesc,&size);
  681. if FAILED(hr) {
  682. free(pdesc);
  683. return hr;
  684. }
  685. *ret=SysAllocString(pdesc->lpszAccountID);
  686. return S_OK;
  687. }
  688. STDMETHODIMP C_dxj_DirectPlay4Object::initializeConnection(I_dxj_DPAddress *con//,long flags
  689. )
  690. {
  691. DWORD size;
  692. void *pData;
  693. if (!con) return E_INVALIDARG;
  694. con->getAddress((long*)&pData,(long*)&size);
  695. HRESULT hr=m__dxj_DirectPlay4->InitializeConnection(pData,(DWORD)0);
  696. return hr;
  697. }
  698. STDMETHODIMP C_dxj_DirectPlay4Object::createGroupInGroup(Dpid id,BSTR longName,BSTR shortName,long flags, Dpid *retval){
  699. DPNAME dpName;
  700. DWORD l1=0;
  701. DWORD l2=0;
  702. ZeroMemory(&dpName,sizeof(DPNAME));
  703. dpName.dwSize=sizeof(DPNAME);
  704. if (shortName){
  705. l1=wcslen(shortName);
  706. if (l1>0){
  707. dpName.lpszShortName = (LPWSTR)alloca(sizeof(WCHAR)*(l1+1));
  708. wcscpy(dpName.lpszShortName, shortName);
  709. }
  710. }
  711. if (longName){
  712. l2=0;l2=wcslen(longName);
  713. if (l2>0){
  714. dpName.lpszLongName = (LPWSTR)alloca(sizeof(WCHAR)*(l2+1));
  715. wcscpy(dpName.lpszLongName, longName);
  716. }
  717. }
  718. DPID ret;
  719. HRESULT hr;
  720. if ((l1==0)&&(l2==0)){
  721. hr=m__dxj_DirectPlay4->CreateGroupInGroup((DPID)id,&ret,NULL,NULL,0,(DWORD)flags);
  722. }
  723. else {
  724. hr=m__dxj_DirectPlay4->CreateGroupInGroup((DPID)id,&ret,&dpName,NULL,0,(DWORD)flags);
  725. }
  726. *retval=(Dpid)ret;
  727. return hr;
  728. }
  729. //////////////////////////////////////////////////////////////////////////
  730. STDMETHODIMP C_dxj_DirectPlay4Object::getDPEnumConnections(
  731. BSTR strGuid,
  732. long flags,
  733. I_dxj_DPEnumConnections **retVal){
  734. HRESULT hr=C_dxj_DPEnumConnectionsObject::create(m__dxj_DirectPlay4,strGuid,flags,retVal);
  735. return hr;
  736. }
  737. STDMETHODIMP C_dxj_DirectPlay4Object::getMessageQueue(
  738. /* [in] */ long from,
  739. /* [in] */ long to,
  740. long flags,
  741. long *nMessages,
  742. long *nBytes)
  743. {
  744. return m__dxj_DirectPlay4->GetMessageQueue((DPID)from,(DPID)to,(DWORD)flags,(DWORD*)nMessages,(DWORD*)nBytes);
  745. }
  746. STDMETHODIMP C_dxj_DirectPlay4Object::getGroupOwner(
  747. /* [in] */ long groupId,
  748. /* [retval][out] */ long __RPC_FAR *ret)
  749. {
  750. return m__dxj_DirectPlay4->GetGroupOwner((DWORD)groupId,(DWORD*)ret);
  751. }
  752. STDMETHODIMP C_dxj_DirectPlay4Object::cancelPriority(
  753. long minPriority,
  754. long maxPriority
  755. // long flags
  756. )
  757. {
  758. return m__dxj_DirectPlay4->CancelPriority((DWORD)minPriority,(DWORD)maxPriority,(DWORD) 0);
  759. }
  760. STDMETHODIMP C_dxj_DirectPlay4Object::cancelMessage(
  761. /* [in] */ long msgid
  762. ///* [in] */ long flags
  763. )
  764. {
  765. return m__dxj_DirectPlay4->CancelMessage((DWORD)msgid,(DWORD)0);
  766. }
  767. STDMETHODIMP C_dxj_DirectPlay4Object::setGroupOwner(
  768. /* [in] */ long groupId,
  769. /* [in] */ long ownerId)
  770. {
  771. return m__dxj_DirectPlay4->SetGroupOwner((DWORD)groupId,(DWORD)ownerId);
  772. }
  773. STDMETHODIMP C_dxj_DirectPlay4Object::sendEx(
  774. /* [in] */ long fromPlayerId,
  775. /* [in] */ long toPlayerId,
  776. /* [in] */ long flags,
  777. /* [in] */ I_dxj_DirectPlayMessage *msg,
  778. /* [in] */ long priority,
  779. /* [in] */ long timeout,
  780. /* [in] */ long context,
  781. /* [retval][out] */ long *messageid)
  782. {
  783. HRESULT hr;
  784. void *pdata=NULL;
  785. DWORD dataSize=0;
  786. if (!msg) return E_INVALIDARG;
  787. __try {
  788. msg->getPointer((long*)&pdata);
  789. msg->getMessageSize((long*)&dataSize);
  790. hr= m__dxj_DirectPlay4->SendEx((DPID)fromPlayerId, (DPID)toPlayerId, (DWORD)flags,
  791. (void*)pdata, (DWORD) dataSize,
  792. (DWORD) priority,
  793. (DWORD) timeout,
  794. (void*) context,
  795. (DWORD_PTR*) messageid); //bugbug SUNDOWN
  796. }
  797. __except (1,1)
  798. {
  799. return E_INVALIDARG;
  800. }
  801. return hr;
  802. }
  803. STDMETHODIMP C_dxj_DirectPlay4Object::createSessionData( I_dxj_DirectPlaySessionData __RPC_FAR *__RPC_FAR *sessionDesc)
  804. {
  805. HRESULT hr;
  806. hr=C_dxj_DirectPlaySessionDataObject::create((DPSESSIONDESC2*)NULL,sessionDesc);
  807. return hr;
  808. }
  809. STDMETHODIMP C_dxj_DirectPlay4Object::createMessage( I_dxj_DirectPlayMessage __RPC_FAR *__RPC_FAR *ret)
  810. {
  811. HRESULT hr;
  812. hr= C_dxj_DirectPlayMessageObject::create(1,0,NULL,ret);
  813. return hr;
  814. }