Leaked source code of windows server 2003
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.

389 lines
11 KiB

  1. /*==========================================================================
  2. *
  3. * Copyright (C) 1996-1997 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: create.c
  6. * Content: DirectPlayLobby creation code
  7. *
  8. * History:
  9. * Date By Reason
  10. * ======= ======= ======
  11. * 4/13/96 myronth Created it
  12. * 6/24/96 myronth Added Time Bomb
  13. * 8/23/96 kipo removed time bomb
  14. * 10/23/96 myronth Added client/server methods
  15. * 10/25/96 myronth Added DX5 methods
  16. * 11/20/96 myronth Added DPLC_A_LogonServer
  17. * 1/2/97 myronth Changed vtbl entries for CreateAddress & EnumAddress
  18. * 1/2/97 myronth Cleaned up creation code by adding PRV_LobbyCreate
  19. * 2/12/97 myronth Mass DX5 changes
  20. * 2/18/97 myronth Implemented GetObjectCaps
  21. * 2/26/97 myronth #ifdef'd out DPASYNCDATA stuff (removed dependency)
  22. * 3/12/97 myronth Added AllocateLobbyObject, removed response methods
  23. * for Open and Close since they are synchronous
  24. * 3/17/97 myronth Removed unnecessary Enum functions from IDPLobbySP
  25. * 3/21/97 myronth Removed unnecessary Get/Set response functions
  26. * 3/24/97 kipo Added support for IDirectPlayLobby2 interface
  27. * 3/31/97 myronth Removed dead code, changed IDPLobbySP interface methods
  28. * 5/8/97 myronth Added subgroup methods & StartSession to IDPLobbySP
  29. * 5/17/97 myronth Added SendChatMessage to IDPLobbySP
  30. * 6/25/97 kipo remove time bomb for DX5
  31. * 10/3/97 myronth Added CreateCompoundAddress and EnumAddress to
  32. * IDPLobbySP (12648)
  33. * 10/29/97 myronth Added SetGroupOwner to IDPLobbySP
  34. * 11/24/97 kipo Added time bomb for DX6
  35. * 12/2/97 myronth Added Register/UnregisterApplication methods
  36. * 12/4/97 myronth Added ConnectEx
  37. * 1/20/98 myronth Added WaitForConnectionSettings
  38. * 6/25/98 a-peterz Added DPL_A_ConnectEx
  39. * 2/2/99 aarono Added lobbies to refcount on DPLAY dll to avoid
  40. * accidental unload.
  41. * 04/11/00 rodtoll Added code for redirection for custom builds if registry bit is set
  42. ***************************************************************************/
  43. #include "dplobpr.h"
  44. #include "verinfo.h"
  45. //--------------------------------------------------------------------------
  46. //
  47. // Globals
  48. //
  49. //--------------------------------------------------------------------------
  50. UINT gnSPCount; // Running sp count
  51. //
  52. // The one copy of the direct play callbacks (this is the vtbl!)
  53. //
  54. DIRECTPLAYLOBBYCALLBACKS dplCallbacks =
  55. {
  56. (LPVOID)DPL_QueryInterface,
  57. (LPVOID)DPL_AddRef,
  58. (LPVOID)DPL_Release,
  59. (LPVOID)DPL_Connect,
  60. (LPVOID)DPL_CreateAddress,
  61. (LPVOID)DPL_EnumAddress,
  62. (LPVOID)DPL_EnumAddressTypes,
  63. (LPVOID)DPL_EnumLocalApplications,
  64. (LPVOID)DPL_GetConnectionSettings,
  65. (LPVOID)DPL_ReceiveLobbyMessage,
  66. (LPVOID)DPL_RunApplication,
  67. (LPVOID)DPL_SendLobbyMessage,
  68. (LPVOID)DPL_SetConnectionSettings,
  69. (LPVOID)DPL_SetLobbyMessageEvent,
  70. };
  71. DIRECTPLAYLOBBYCALLBACKSA dplCallbacksA =
  72. {
  73. (LPVOID)DPL_QueryInterface,
  74. (LPVOID)DPL_AddRef,
  75. (LPVOID)DPL_Release,
  76. (LPVOID)DPL_A_Connect,
  77. (LPVOID)DPL_CreateAddress,
  78. (LPVOID)DPL_EnumAddress,
  79. (LPVOID)DPL_EnumAddressTypes,
  80. (LPVOID)DPL_A_EnumLocalApplications,
  81. (LPVOID)DPL_A_GetConnectionSettings,
  82. (LPVOID)DPL_ReceiveLobbyMessage,
  83. (LPVOID)DPL_A_RunApplication,
  84. (LPVOID)DPL_SendLobbyMessage,
  85. (LPVOID)DPL_A_SetConnectionSettings,
  86. (LPVOID)DPL_SetLobbyMessageEvent,
  87. };
  88. // IDirectPlayLobby2 interface
  89. DIRECTPLAYLOBBYCALLBACKS2 dplCallbacks2 =
  90. {
  91. (LPVOID)DPL_QueryInterface,
  92. (LPVOID)DPL_AddRef,
  93. (LPVOID)DPL_Release,
  94. (LPVOID)DPL_Connect,
  95. (LPVOID)DPL_CreateAddress,
  96. (LPVOID)DPL_EnumAddress,
  97. (LPVOID)DPL_EnumAddressTypes,
  98. (LPVOID)DPL_EnumLocalApplications,
  99. (LPVOID)DPL_GetConnectionSettings,
  100. (LPVOID)DPL_ReceiveLobbyMessage,
  101. (LPVOID)DPL_RunApplication,
  102. (LPVOID)DPL_SendLobbyMessage,
  103. (LPVOID)DPL_SetConnectionSettings,
  104. (LPVOID)DPL_SetLobbyMessageEvent,
  105. /*** IDirectPlayLobby2 methods ***/
  106. (LPVOID)DPL_CreateCompoundAddress
  107. };
  108. DIRECTPLAYLOBBYCALLBACKS2A dplCallbacks2A =
  109. {
  110. (LPVOID)DPL_QueryInterface,
  111. (LPVOID)DPL_AddRef,
  112. (LPVOID)DPL_Release,
  113. (LPVOID)DPL_A_Connect,
  114. (LPVOID)DPL_CreateAddress,
  115. (LPVOID)DPL_EnumAddress,
  116. (LPVOID)DPL_EnumAddressTypes,
  117. (LPVOID)DPL_A_EnumLocalApplications,
  118. (LPVOID)DPL_A_GetConnectionSettings,
  119. (LPVOID)DPL_ReceiveLobbyMessage,
  120. (LPVOID)DPL_A_RunApplication,
  121. (LPVOID)DPL_SendLobbyMessage,
  122. (LPVOID)DPL_A_SetConnectionSettings,
  123. (LPVOID)DPL_SetLobbyMessageEvent,
  124. /*** IDirectPlayLobby2A methods ***/
  125. (LPVOID)DPL_CreateCompoundAddress
  126. };
  127. // IDirectPlayLobby3 interface
  128. DIRECTPLAYLOBBYCALLBACKS3 dplCallbacks3 =
  129. {
  130. (LPVOID)DPL_QueryInterface,
  131. (LPVOID)DPL_AddRef,
  132. (LPVOID)DPL_Release,
  133. (LPVOID)DPL_Connect,
  134. (LPVOID)DPL_CreateAddress,
  135. (LPVOID)DPL_EnumAddress,
  136. (LPVOID)DPL_EnumAddressTypes,
  137. (LPVOID)DPL_EnumLocalApplications,
  138. (LPVOID)DPL_GetConnectionSettings,
  139. (LPVOID)DPL_ReceiveLobbyMessage,
  140. (LPVOID)DPL_RunApplication,
  141. (LPVOID)DPL_SendLobbyMessage,
  142. (LPVOID)DPL_SetConnectionSettings,
  143. (LPVOID)DPL_SetLobbyMessageEvent,
  144. /*** IDirectPlayLobby2 methods ***/
  145. (LPVOID)DPL_CreateCompoundAddress,
  146. /*** IDirectPlayLobby3 methods ***/
  147. (LPVOID)DPL_ConnectEx,
  148. (LPVOID)DPL_RegisterApplication,
  149. (LPVOID)DPL_UnregisterApplication,
  150. (LPVOID)DPL_WaitForConnectionSettings
  151. };
  152. DIRECTPLAYLOBBYCALLBACKS3A dplCallbacks3A =
  153. {
  154. (LPVOID)DPL_QueryInterface,
  155. (LPVOID)DPL_AddRef,
  156. (LPVOID)DPL_Release,
  157. (LPVOID)DPL_A_Connect,
  158. (LPVOID)DPL_CreateAddress,
  159. (LPVOID)DPL_EnumAddress,
  160. (LPVOID)DPL_EnumAddressTypes,
  161. (LPVOID)DPL_A_EnumLocalApplications,
  162. (LPVOID)DPL_A_GetConnectionSettings,
  163. (LPVOID)DPL_ReceiveLobbyMessage,
  164. (LPVOID)DPL_A_RunApplication,
  165. (LPVOID)DPL_SendLobbyMessage,
  166. (LPVOID)DPL_A_SetConnectionSettings,
  167. (LPVOID)DPL_SetLobbyMessageEvent,
  168. /*** IDirectPlayLobby2A methods ***/
  169. (LPVOID)DPL_CreateCompoundAddress,
  170. /*** IDirectPlayLobby3 methods ***/
  171. (LPVOID)DPL_A_ConnectEx,
  172. (LPVOID)DPL_A_RegisterApplication,
  173. (LPVOID)DPL_UnregisterApplication,
  174. (LPVOID)DPL_WaitForConnectionSettings
  175. };
  176. DIRECTPLAYLOBBYSPCALLBACKS dplCallbacksSP =
  177. {
  178. (LPVOID)DPL_QueryInterface,
  179. (LPVOID)DPL_AddRef,
  180. (LPVOID)DPL_Release,
  181. (LPVOID)DPLP_AddGroupToGroup,
  182. (LPVOID)DPLP_AddPlayerToGroup,
  183. (LPVOID)DPLP_CreateGroup,
  184. (LPVOID)DPLP_CreateGroupInGroup,
  185. (LPVOID)DPLP_DeleteGroupFromGroup,
  186. (LPVOID)DPLP_DeletePlayerFromGroup,
  187. (LPVOID)DPLP_DestroyGroup,
  188. (LPVOID)DPLP_EnumSessionsResponse,
  189. (LPVOID)DPLP_GetSPDataPointer,
  190. (LPVOID)DPLP_HandleMessage,
  191. (LPVOID)DPLP_SendChatMessage,
  192. (LPVOID)DPLP_SetGroupName,
  193. (LPVOID)DPLP_SetPlayerName,
  194. (LPVOID)DPLP_SetSessionDesc,
  195. (LPVOID)DPLP_SetSPDataPointer,
  196. (LPVOID)DPLP_StartSession,
  197. /*** Methods added for DX6 ***/
  198. (LPVOID)DPL_CreateCompoundAddress,
  199. (LPVOID)DPL_EnumAddress,
  200. (LPVOID)DPLP_SetGroupOwner,
  201. };
  202. //--------------------------------------------------------------------------
  203. //
  204. // Functions
  205. //
  206. //--------------------------------------------------------------------------
  207. #undef DPF_MODNAME
  208. #define DPF_MODNAME "PRV_AllocateLobbyObject"
  209. HRESULT PRV_AllocateLobbyObject(LPDPLAYI_DPLAY lpDPObject,
  210. LPDPLOBBYI_DPLOBJECT * lpthis)
  211. {
  212. LPDPLOBBYI_DPLOBJECT this = NULL;
  213. DPF(7, "Entering PRV_AllocateLobbyObject");
  214. DPF(9, "Parameters: 0x%08x, 0x%08x", lpDPObject, lpthis);
  215. // Allocate memory for our lobby object
  216. this = DPMEM_ALLOC(sizeof(DPLOBBYI_DPLOBJECT));
  217. if(!this)
  218. {
  219. DPF_ERR("Unable to allocate memory for lobby object");
  220. return DPERR_OUTOFMEMORY;
  221. }
  222. // Initialize the ref count
  223. this->dwRefCnt = 0;
  224. this->dwSize = sizeof(DPLOBBYI_DPLOBJECT);
  225. // Store the back pointer
  226. this->lpDPlayObject = lpDPObject;
  227. // Set the output pointer
  228. *lpthis = this;
  229. gnObjects++;
  230. return DP_OK;
  231. } // PRV_AllocateLobbyObject
  232. #undef DPF_MODNAME
  233. #define DPF_MODNAME "PRV_LobbyCreate"
  234. HRESULT WINAPI PRV_LobbyCreate(LPGUID lpGUID, LPDIRECTPLAYLOBBY *lplpDPL,
  235. IUnknown *pUnkOuter, LPVOID lpSPData, DWORD dwSize, BOOL bAnsi)
  236. {
  237. LPDPLOBBYI_DPLOBJECT this = NULL;
  238. LPDPLOBBYI_INTERFACE lpInterface = NULL;
  239. HRESULT hr;
  240. DPF(7, "Entering PRV_LobbyCreate");
  241. DPF(9, "Parameters: 0x%08x, 0x%08x, 0x%08x, 0x%08x, %lu, %lu",
  242. lpGUID, lplpDPL, pUnkOuter, lpSPData, dwSize, bAnsi);
  243. // Must be NULL for this release
  244. if( lpGUID )
  245. {
  246. if( !VALID_READ_PTR(lpGUID, sizeof(GUID)) )
  247. return DPERR_INVALIDPARAMS;
  248. if(!IsEqualGUID(lpGUID, &GUID_NULL))
  249. return DPERR_INVALIDPARAMS;
  250. }
  251. if( pUnkOuter != NULL )
  252. {
  253. return CLASS_E_NOAGGREGATION;
  254. }
  255. if( lpSPData )
  256. {
  257. // Must be NULL for this release
  258. return DPERR_INVALIDPARAMS;
  259. }
  260. if( dwSize )
  261. {
  262. // Must be zero for this release
  263. return DPERR_INVALIDPARAMS;
  264. }
  265. TRY
  266. {
  267. *lplpDPL = NULL;
  268. }
  269. EXCEPT( EXCEPTION_EXECUTE_HANDLER )
  270. {
  271. DPF_ERR( "Exception encountered validating parameters" );
  272. return DPERR_INVALIDPARAMS;
  273. }
  274. #ifndef DX_FINAL_RELEASE
  275. #pragma message("BETA EXPIRATION TIME BOMB! Remove for final build!")
  276. hr = TimeBomb();
  277. if (FAILED(hr))
  278. {
  279. return DPERR_GENERIC;
  280. }
  281. #endif
  282. // Allocate the lobby object
  283. hr = PRV_AllocateLobbyObject(NULL, &this);
  284. if(FAILED(hr))
  285. return hr;
  286. // Get the Unicode interface
  287. hr = PRV_GetInterface(this, &lpInterface, (bAnsi ? &dplCallbacksA : &dplCallbacks));
  288. if(FAILED(hr))
  289. {
  290. DPMEM_FREE(this);
  291. DPF_ERR("Unable to allocate memory for lobby interface structure");
  292. return hr;
  293. }
  294. *lplpDPL = (LPDIRECTPLAYLOBBY)lpInterface;
  295. return DP_OK;
  296. } // PRV_LobbyCreate
  297. #undef DPF_MODNAME
  298. #define DPF_MODNAME "DirectPlayLobbyCreateW"
  299. HRESULT WINAPI DirectPlayLobbyCreateW(LPGUID lpGUID, LPDIRECTPLAYLOBBY *lplpDPL,
  300. IUnknown *pUnkOuter, LPVOID lpSPData, DWORD dwSize)
  301. {
  302. HRESULT hr = DP_OK;
  303. #ifdef DPLAY_LOADANDCHECKTRUE
  304. if( g_hRedirect != NULL )
  305. {
  306. return (*pfnDirectPlayLobbyCreateW)(lpGUID,lplpDPL,pUnkOuter,lpSPData,dwSize);
  307. }
  308. #endif
  309. ENTER_DPLOBBY();
  310. // Call the private create function
  311. hr = PRV_LobbyCreate(lpGUID, lplpDPL, pUnkOuter, lpSPData, dwSize, FALSE);
  312. LEAVE_DPLOBBY();
  313. return hr;
  314. } // DirectPlayLobbyCreateW
  315. #undef DPF_MODNAME
  316. #define DPF_MODNAME "DirectPlayLobbyCreateA"
  317. HRESULT WINAPI DirectPlayLobbyCreateA(LPGUID lpGUID, LPDIRECTPLAYLOBBY *lplpDPL,
  318. IUnknown *pUnkOuter, LPVOID lpSPData, DWORD dwSize)
  319. {
  320. HRESULT hr = DP_OK;
  321. #ifdef DPLAY_LOADANDCHECKTRUE
  322. if( g_hRedirect != NULL )
  323. {
  324. return (*pfnDirectPlayLobbyCreateA)(lpGUID,lplpDPL,pUnkOuter,lpSPData,dwSize);
  325. }
  326. #endif
  327. ENTER_DPLOBBY();
  328. // Call the private create function
  329. hr = PRV_LobbyCreate(lpGUID, lplpDPL, pUnkOuter, lpSPData, dwSize, TRUE);
  330. LEAVE_DPLOBBY();
  331. return hr;
  332. } // DirectPlayLobbyCreateA