// -------------------------------------------------------------------------- // ========================================================================== // File: TDPSessionDesc.CPP // Authors: BCB_Code_Generator v1.62, // Darren Dwyer (source code, documentation, demos, website), // Hugh Edwards (documentation, icons), // Brian Austin (some source code, documentation) // Description: This file contains the code for the TDPSessionDesc Component // // "TDx_Play_Library v1.62" // (c) 2002 BCB-Tools.com Pty. Ltd., Sydney, Australia. // All Rights Reserved. // // Refer to the 'Licence.Txt' file for licencing & copyright information. // ========================================================================== // -------------------------------------------------------------------------- // #includes ... // -------------------------------------------------------------------------- #include #pragma hdrstop // -------------------------------------------------------------------------- #include "TDPSessionDesc.H" // -------------------------------------------------------------------------- #pragma link "TDx_Library_Defns" #pragma link "TDx_Library_Functions" #pragma link "TDx_Play_Library_Defns" #pragma link "TDx_Play_Library_Functions" // -------------------------------------------------------------------------- // Object Registration... // -------------------------------------------------------------------------- #if (__BORLANDC__ >= 0x0530) // BCB Version 3+ #pragma package(smart_init) #endif // -------------------------------------------------------------------------- static inline void ValidCtrCheck(TDPSessionDesc*) { new TDPSessionDesc(NULL); } // -------------------------------------------------------------------------- namespace Tdpsessiondesc { #if (__BORLANDC__ >= 0x0530) // BCB Version 3+ void __fastcall PACKAGE Register() #else void __fastcall Register() #endif { TComponentClass classes[1] = {__classid(TDPSessionDesc)}; RegisterComponents("TDx_Play", classes, 0); } } // -------------------------------------------------------------------------- // Constructor: TDPSessionDesc::TDPSessionDesc() // Description: The default constructor for the TDPSessionDesc object. // -------------------------------------------------------------------------- __fastcall TDPSessionDesc::TDPSessionDesc(TComponent* Owner) : TComponent(Owner) { Clear(); fFlags_Strings=NULL; } // -------------------------------------------------------------------------- // Destructor: TDPSessionDesc::~TDPSessionDesc() // Description: The destructor for the TDPSessionDesc object. // -------------------------------------------------------------------------- __fastcall TDPSessionDesc::~TDPSessionDesc() { if (fFlags_Strings!=NULL) delete fFlags_Strings; } // -------------------------------------------------------------------------- // Property: Application // Description: The Application property identifies the application that is // running in this session. // // This is used to ensure that connections are only made to // computers running the same application. // Set to GUID_NULL to enumerate all application sessions. // -------------------------------------------------------------------------- GUID __fastcall TDPSessionDesc::FGetApplication() { return fDPSESSIONDESC2.guidApplication; } // -------------------------------------------------------------------------- void __fastcall TDPSessionDesc::FSetApplication( GUID pApplication ) { fDPSESSIONDESC2.guidApplication = pApplication; } // -------------------------------------------------------------------------- // Property: CurrentPlayers // Description: The CurrentPlayers property defines the current number of // players in the session. // -------------------------------------------------------------------------- dword __fastcall TDPSessionDesc::FGetCurrentPlayers() { return fDPSESSIONDESC2.dwCurrentPlayers; } // -------------------------------------------------------------------------- void __fastcall TDPSessionDesc::FSetCurrentPlayers( dword pCurrentPlayers ) { fDPSESSIONDESC2.dwCurrentPlayers = pCurrentPlayers; } // -------------------------------------------------------------------------- // Property: ErrorValue // Description: The ErrorValue property contains the last error value // returned from a call to a TDPSessionDesc method or fget/fset. // eg. DP_OK or DDERR_SURFACELOST or TDX_ERROR // -------------------------------------------------------------------------- HRESULT __fastcall TDPSessionDesc::FGetErrorValue() { return fErrorValue; } // -------------------------------------------------------------------------- void __fastcall TDPSessionDesc::FSetErrorValue( HRESULT pErrorValue ) { fErrorValue = pErrorValue; } // -------------------------------------------------------------------------- // Property: Flags // Description: The Flags property defines flags indicating the nature of the // session. // The described effect applies when the flag is set. // // Some of these flags, as noted, may not be modified once the // session has been created. // Flags: DPSESSION_CLIENTSERVER - // This is a client/server session hosted by an application // server process. // // Cannot be modified once the session is created. // Clients joining the session can only enumerate local // players and the server player. // The session host will see all the sessions players and can // only create a server player. // Incompatible with DPSESSION_MIGRATEHOST. // DPSESSION_DIRECTPLAYPROTOCOL - // The session is to use the DirectPlay guaranteed protocol, // not the guaranteed protocol implemented by the service // provider. // // Setting this flag allows message throttling, all // TDx_Play::SendEx() functionallity and guaranteed messaging // ability, as well as using DirectPlay TCP/IP reliablilty // code to improve throughput and delivery. // DPSESSION_JOINDISABLED - // No new applications can join the session. // // Calls to TDx_Play::Open() with the DPOPEN_JOIN flag and // this sessions GUID will fail. // The number of remote players will otherwise be limited by // TDPSessiondDesc::MaxPlayers. // DPSESSION_KEEPALIVE - // Abnormally disconnected remote players will be detected and // deleted from the session. // // Cannot be modified once the session is created. // When disconnection was due to a temporary communications // problem, the rejoining player will be informed that they // have been dropped from the session by a DPMSG_SESSIONLOST // message. // A disconnected player will cause the session to be // terminated if this flag is not set. // DPSESSION_MIGRATEHOST - // Enables another computer to become the host if the current // host leaves the session. // // Cannot be modified once the session is created. // A DPMSG_HOST system message will be sent to players on the // new host. // Incompatible with DPSESSION_CLIENTSERVER, // DPSESSION_MULTICASTSERVER and DPSESSION_SECURESERVER. // The session becomes unavailable to new players and // computers when the host exits if this flag is not set. // DPSESSION_MULTICASTSERVER - // All group and broadcast messages will be routed through the // host, which will multicast the message to all recipients. // // Cannot be modified once the session is created. // Incompatible with DPSESSION_MIGRATEHOST. // DPSESSION_NEWPLAYERSDISABLED - // No new players or applications can can be created or join // the session. // // TDx_Play::CreatePlayer() will return an error. // The number of remote players will otherwise be limited by // TDPSessiondDesc::MaxPlayers. // DPSESSION_NODATAMESSAGES - // System messages regarding updates to remote // player/group/session data will not be generated. // // The methods that generate data messages are // TDx_Play::SetPlayerData(), TDx_Play::SetGroupData(), // TDx_Play::SetPlayerName(), TDx_Play::SetGroupName() and // TDx_Play::SetSessionDesc(). // DPMSG_SETSESSIONDESC will also be suppressed. // DPSESSION_NOMESSAGEID - // Information indicating the sender and receiver of a message // will not be attached to the message. // // Cannot be modified once the session is created. // This can reduce message overhead when the id's are not // relevent. // DPSESSION_NOPRESERVEORDER - // The order in which guaranteed messages are received is // irrelevent. // // If the order of messages receipt is not important, delays // may be reduced by using this flag. // DPSESSION_OPTIMIZELATENCY - // Optimises communications for latency, as opposed to // bandwidth. // // This flag disables TCP/IP nagling. // DPSESSION_PASSWORDREQUIRED - // The session requires a password to join. // // This read only flag is automatically set when // TDPSessionDesc::Password or TDPSessionDesc::PasswordA is // not NULL. // DPSESSION_PRIVATE - // The session is private and will not be enumerated unless a // matching password is provided. // DPSESSION_SECURESERVER - // The host of the session is a secure server and credentials // must be supplied before it can be opened. // // Cannot be modified once the session is created. // Incompatible with DPSESSION_MIGRATEHOST. // -------------------------------------------------------------------------- dword __fastcall TDPSessionDesc::FGetFlags() { return fDPSESSIONDESC2.dwFlags; } // -------------------------------------------------------------------------- void __fastcall TDPSessionDesc::FSetFlags( dword pFlags ) { fDPSESSIONDESC2.dwFlags = pFlags; } // -------------------------------------------------------------------------- // Property: Instance // Description: The Instance property identifies the session instance. // -------------------------------------------------------------------------- GUID __fastcall TDPSessionDesc::FGetInstance() { return fDPSESSIONDESC2.guidInstance; } // -------------------------------------------------------------------------- void __fastcall TDPSessionDesc::FSetInstance( GUID pInstance ) { fDPSESSIONDESC2.guidInstance = pInstance; } // -------------------------------------------------------------------------- // Property: MaxPlayers // Description: The MaxPlayers property defines the maximum number of players // allowed in the session. // // Set to 0 for no maximum player numbers. // -------------------------------------------------------------------------- dword __fastcall TDPSessionDesc::FGetMaxPlayers() { return fDPSESSIONDESC2.dwMaxPlayers; } // -------------------------------------------------------------------------- void __fastcall TDPSessionDesc::FSetMaxPlayers( dword pMaxPlayers ) { fDPSESSIONDESC2.dwMaxPlayers = pMaxPlayers; } // -------------------------------------------------------------------------- // Property: Password // Description: The Password property references the password used to join // the session, stored as a unicode string. // -------------------------------------------------------------------------- AnsiString __fastcall TDPSessionDesc::FGetPassword() { if ((LPWSTR)fPassword.c_str()!=fDPSESSIONDESC2.lpszPassword) fPassword = fDPSESSIONDESC2.lpszPassword; return fPassword; } // -------------------------------------------------------------------------- void __fastcall TDPSessionDesc::FSetPassword( AnsiString pPassword ) { fPassword = pPassword; fDPSESSIONDESC2.lpszPassword = (LPWSTR) fPassword.c_str(); } // -------------------------------------------------------------------------- // Property: PasswordA // Description: The PasswordA property references the password used to join // the session, stored as an ANSI string. // -------------------------------------------------------------------------- AnsiString __fastcall TDPSessionDesc::FGetPasswordA() { if ((LPSTR)fPasswordA.c_str()!=fDPSESSIONDESC2.lpszPasswordA) fPasswordA = fDPSESSIONDESC2.lpszPasswordA; return fPasswordA; } // -------------------------------------------------------------------------- void __fastcall TDPSessionDesc::FSetPasswordA( AnsiString pPasswordA ) { fPasswordA = pPasswordA; fDPSESSIONDESC2.lpszPasswordA = (LPSTR) fPasswordA.c_str(); } // -------------------------------------------------------------------------- // Property: SessionName // Description: The SessionName property references the name of the session, // stored as a unicode string. // -------------------------------------------------------------------------- AnsiString __fastcall TDPSessionDesc::FGetSessionName() { if ((LPWSTR)fSessionName.c_str()!=fDPSESSIONDESC2.lpszSessionName) fSessionName = fDPSESSIONDESC2.lpszSessionName; return fSessionName; } // -------------------------------------------------------------------------- void __fastcall TDPSessionDesc::FSetSessionName( AnsiString pSessionName ) { fSessionName = pSessionName; fDPSESSIONDESC2.lpszSessionName = (LPWSTR) fSessionName.c_str(); } // -------------------------------------------------------------------------- // Property: SessionNameA // Description: The SessionNameA property references the name of the session, // stored as an ANSI string. // -------------------------------------------------------------------------- AnsiString __fastcall TDPSessionDesc::FGetSessionNameA() { if ((LPSTR)fSessionNameA.c_str()!=fDPSESSIONDESC2.lpszSessionNameA) fSessionNameA = fDPSESSIONDESC2.lpszSessionNameA; return fSessionNameA; } // -------------------------------------------------------------------------- void __fastcall TDPSessionDesc::FSetSessionNameA( AnsiString pSessionNameA ) { fSessionNameA = pSessionNameA; fDPSESSIONDESC2.lpszSessionNameA = (LPSTR) fSessionNameA.c_str(); } // -------------------------------------------------------------------------- // Property: Size // Description: The Size property contains the size in bytes of the internal // DPSESSIONDESC2 structure. // -------------------------------------------------------------------------- dword __fastcall TDPSessionDesc::FGetSize() { return fDPSESSIONDESC2.dwSize; } // -------------------------------------------------------------------------- void __fastcall TDPSessionDesc::FSetSize( dword pSize ) { fDPSESSIONDESC2.dwSize = pSize; } // -------------------------------------------------------------------------- // Property: User1 // Description: The User1 property defines data specified and used by the // application for the session. // -------------------------------------------------------------------------- dword __fastcall TDPSessionDesc::FGetUser1() { return fDPSESSIONDESC2.dwUser1; } // -------------------------------------------------------------------------- void __fastcall TDPSessionDesc::FSetUser1( dword pUser1 ) { fDPSESSIONDESC2.dwUser1 = pUser1; } // -------------------------------------------------------------------------- // Property: User2 // Description: The User2 property defines data specified and used by the // application for the session. // -------------------------------------------------------------------------- dword __fastcall TDPSessionDesc::FGetUser2() { return fDPSESSIONDESC2.dwUser2; } // -------------------------------------------------------------------------- void __fastcall TDPSessionDesc::FSetUser2( dword pUser2 ) { fDPSESSIONDESC2.dwUser2 = pUser2; } // -------------------------------------------------------------------------- // Property: User3 // Description: The User3 property defines data specified and used by the // application for the session. // -------------------------------------------------------------------------- dword __fastcall TDPSessionDesc::FGetUser3() { return fDPSESSIONDESC2.dwUser3; } // -------------------------------------------------------------------------- void __fastcall TDPSessionDesc::FSetUser3( dword pUser3 ) { fDPSESSIONDESC2.dwUser3 = pUser3; } // -------------------------------------------------------------------------- // Property: User4 // Description: The User4 property defines data specified and used by the // application for the session. // -------------------------------------------------------------------------- dword __fastcall TDPSessionDesc::FGetUser4() { return fDPSESSIONDESC2.dwUser4; } // -------------------------------------------------------------------------- void __fastcall TDPSessionDesc::FSetUser4( dword pUser4 ) { fDPSESSIONDESC2.dwUser4 = pUser4; } // -------------------------------------------------------------------------- // Method: Clear() // Description: The Clear() method can be used to clear the contents of the // TDPSessionDesc's internal DPSESSIONDESC2 structure. // Note: if you have manually linked a structure member to a // chunk of memory, make sure you release this memory before // calling Clear(). // -------------------------------------------------------------------------- void __fastcall TDPSessionDesc::Clear() { ZeroMemory(&fApplication,sizeof(_GUID)); fDPSESSIONDESC2.dwCurrentPlayers = 0; fErrorValue = DP_OK; fDPSESSIONDESC2.dwFlags = 0; ZeroMemory(&fInstance,sizeof(_GUID)); fDPSESSIONDESC2.dwMaxPlayers = 0; fDPSESSIONDESC2.dwSize = sizeof(DPSESSIONDESC2); fDPSESSIONDESC2.dwUser1 = 0; fDPSESSIONDESC2.dwUser2 = 0; fDPSESSIONDESC2.dwUser3 = 0; fDPSESSIONDESC2.dwUser4 = 0; } // -------------------------------------------------------------------------- // Internal Structure Access // -------------------------------------------------------------------------- DPSESSIONDESC2* __fastcall TDPSessionDesc::FGetInternal_DPSESSIONDESC2_Ptr() { return &fDPSESSIONDESC2; } // -------------------------------------------------------------------------- void __fastcall TDPSessionDesc::FSetInternal_DPSESSIONDESC2( DPSESSIONDESC2* pDPSESSIONDESC2 ) { if (pDPSESSIONDESC2==NULL) { fErrorValue = TDX_ERROR; if (FOnError) FOnError(this, "TDPSessionDesc::FSetInternal_DPSESSIONDESC2()", "TDX_ERROR", "The supplied DPSESSIONDESC2* was NULL" ); return; } CopyMemory( &fDPSESSIONDESC2, pDPSESSIONDESC2, sizeof(DPSESSIONDESC2) ); Internal_DPSESSIONDESC2_Update(); } // -------------------------------------------------------------------------- void __fastcall TDPSessionDesc::Internal_DPSESSIONDESC2_Update() { } // -------------------------------------------------------------------------- // Method: FGetFlags_ // Description: This method returns a TDPSessionDesc_Flags_Set<> of the flags // in the current fDPSESSIONDESC2.dwFlags. // Note: Wrapper components use the following method to modify flags // via the BCB Object Inspector. // -------------------------------------------------------------------------- TDPSessionDesc_Flags_Set __fastcall TDPSessionDesc::FGetFlags_() { TDPSessionDesc_Flags_Set TempFlags_; TempFlags_.Clear(); if (fDPSESSIONDESC2.dwFlags & DPSESSION_CLIENTSERVER) TempFlags_ = TempFlags_ << dpsession_clientserver; if (fDPSESSIONDESC2.dwFlags & DPSESSION_DIRECTPLAYPROTOCOL) TempFlags_ = TempFlags_ << dpsession_directplayprotocol; if (fDPSESSIONDESC2.dwFlags & DPSESSION_JOINDISABLED) TempFlags_ = TempFlags_ << dpsession_joindisabled; if (fDPSESSIONDESC2.dwFlags & DPSESSION_KEEPALIVE) TempFlags_ = TempFlags_ << dpsession_keepalive; if (fDPSESSIONDESC2.dwFlags & DPSESSION_MIGRATEHOST) TempFlags_ = TempFlags_ << dpsession_migratehost; if (fDPSESSIONDESC2.dwFlags & DPSESSION_MULTICASTSERVER) TempFlags_ = TempFlags_ << dpsession_multicastserver; if (fDPSESSIONDESC2.dwFlags & DPSESSION_NEWPLAYERSDISABLED) TempFlags_ = TempFlags_ << dpsession_newplayersdisabled; if (fDPSESSIONDESC2.dwFlags & DPSESSION_NODATAMESSAGES) TempFlags_ = TempFlags_ << dpsession_nodatamessages; if (fDPSESSIONDESC2.dwFlags & DPSESSION_NOMESSAGEID) TempFlags_ = TempFlags_ << dpsession_nomessageid; if (fDPSESSIONDESC2.dwFlags & DPSESSION_NOPRESERVEORDER) TempFlags_ = TempFlags_ << dpsession_nopreserveorder; if (fDPSESSIONDESC2.dwFlags & DPSESSION_OPTIMIZELATENCY) TempFlags_ = TempFlags_ << dpsession_optimizelatency; if (fDPSESSIONDESC2.dwFlags & DPSESSION_PASSWORDREQUIRED) TempFlags_ = TempFlags_ << dpsession_passwordrequired; if (fDPSESSIONDESC2.dwFlags & DPSESSION_PRIVATE) TempFlags_ = TempFlags_ << dpsession_private; if (fDPSESSIONDESC2.dwFlags & DPSESSION_SECURESERVER) TempFlags_ = TempFlags_ << dpsession_secureserver; return TempFlags_; } // -------------------------------------------------------------------------- void __fastcall TDPSessionDesc::FSetFlags_( TDPSessionDesc_Flags_Set pFlags_ ) { fDPSESSIONDESC2.dwFlags = 0; if (pFlags_.Contains(dpsession_clientserver)) fDPSESSIONDESC2.dwFlags |= DPSESSION_CLIENTSERVER; if (pFlags_.Contains(dpsession_directplayprotocol)) fDPSESSIONDESC2.dwFlags |= DPSESSION_DIRECTPLAYPROTOCOL; if (pFlags_.Contains(dpsession_joindisabled)) fDPSESSIONDESC2.dwFlags |= DPSESSION_JOINDISABLED; if (pFlags_.Contains(dpsession_keepalive)) fDPSESSIONDESC2.dwFlags |= DPSESSION_KEEPALIVE; if (pFlags_.Contains(dpsession_migratehost)) fDPSESSIONDESC2.dwFlags |= DPSESSION_MIGRATEHOST; if (pFlags_.Contains(dpsession_multicastserver)) fDPSESSIONDESC2.dwFlags |= DPSESSION_MULTICASTSERVER; if (pFlags_.Contains(dpsession_newplayersdisabled)) fDPSESSIONDESC2.dwFlags |= DPSESSION_NEWPLAYERSDISABLED; if (pFlags_.Contains(dpsession_nodatamessages)) fDPSESSIONDESC2.dwFlags |= DPSESSION_NODATAMESSAGES; if (pFlags_.Contains(dpsession_nomessageid)) fDPSESSIONDESC2.dwFlags |= DPSESSION_NOMESSAGEID; if (pFlags_.Contains(dpsession_nopreserveorder)) fDPSESSIONDESC2.dwFlags |= DPSESSION_NOPRESERVEORDER; if (pFlags_.Contains(dpsession_optimizelatency)) fDPSESSIONDESC2.dwFlags |= DPSESSION_OPTIMIZELATENCY; if (pFlags_.Contains(dpsession_passwordrequired)) fDPSESSIONDESC2.dwFlags |= DPSESSION_PASSWORDREQUIRED; if (pFlags_.Contains(dpsession_private)) fDPSESSIONDESC2.dwFlags |= DPSESSION_PRIVATE; if (pFlags_.Contains(dpsession_secureserver)) fDPSESSIONDESC2.dwFlags |= DPSESSION_SECURESERVER; } // -------------------------------------------------------------------------- // Method: FGetFlags_Strings() // This method creates and then returns a TStringList containing // the current set of 'Flags' flags. // Note: You must manually delete the retrieved TStringList after use // to avoid memory corruption. // -------------------------------------------------------------------------- TStringList* __fastcall TDPSessionDesc::FGetFlags_Strings() { // if the strings have not been allocated if (fFlags_Strings==NULL) { // attempt to allocate the strings fFlags_Strings = new TStringList(); // if the allocation failed if (fFlags_Strings==NULL) { fErrorValue = TDX_ERROR; if (FOnError) FOnError(this, "TDPSessionDesc::FGetFlags_Strings()", "TDX_ERROR", "Could not allocate memory used to retrieve various Flags_Strings" ); return NULL; } } fFlags_Strings->Clear(); if (fDPSESSIONDESC2.dwFlags & DPSESSION_CLIENTSERVER) fFlags_Strings->Add("DPSESSION_CLIENTSERVER"); if (fDPSESSIONDESC2.dwFlags & DPSESSION_DIRECTPLAYPROTOCOL) fFlags_Strings->Add("DPSESSION_DIRECTPLAYPROTOCOL"); if (fDPSESSIONDESC2.dwFlags & DPSESSION_JOINDISABLED) fFlags_Strings->Add("DPSESSION_JOINDISABLED"); if (fDPSESSIONDESC2.dwFlags & DPSESSION_KEEPALIVE) fFlags_Strings->Add("DPSESSION_KEEPALIVE"); if (fDPSESSIONDESC2.dwFlags & DPSESSION_MIGRATEHOST) fFlags_Strings->Add("DPSESSION_MIGRATEHOST"); if (fDPSESSIONDESC2.dwFlags & DPSESSION_MULTICASTSERVER) fFlags_Strings->Add("DPSESSION_MULTICASTSERVER"); if (fDPSESSIONDESC2.dwFlags & DPSESSION_NEWPLAYERSDISABLED) fFlags_Strings->Add("DPSESSION_NEWPLAYERSDISABLED"); if (fDPSESSIONDESC2.dwFlags & DPSESSION_NODATAMESSAGES) fFlags_Strings->Add("DPSESSION_NODATAMESSAGES"); if (fDPSESSIONDESC2.dwFlags & DPSESSION_NOMESSAGEID) fFlags_Strings->Add("DPSESSION_NOMESSAGEID"); if (fDPSESSIONDESC2.dwFlags & DPSESSION_NOPRESERVEORDER) fFlags_Strings->Add("DPSESSION_NOPRESERVEORDER"); if (fDPSESSIONDESC2.dwFlags & DPSESSION_OPTIMIZELATENCY) fFlags_Strings->Add("DPSESSION_OPTIMIZELATENCY"); if (fDPSESSIONDESC2.dwFlags & DPSESSION_PASSWORDREQUIRED) fFlags_Strings->Add("DPSESSION_PASSWORDREQUIRED"); if (fDPSESSIONDESC2.dwFlags & DPSESSION_PRIVATE) fFlags_Strings->Add("DPSESSION_PRIVATE"); if (fDPSESSIONDESC2.dwFlags & DPSESSION_SECURESERVER) fFlags_Strings->Add("DPSESSION_SECURESERVER"); return fFlags_Strings; } // --------------------------------------------------------------------------