cMultiplayer.h
上传用户:sycq158
上传日期:2008-10-22
资源大小:15361k
文件大小:4k
- // CMAIN LIB - APPLICATION AND DIRECT WRAPPER
- //
- // Written by Mauricio Teichmann Ritter
- //
- // Copyright (C) 2002, Brazil. All rights reserved.
- //
- //
- // cMultiplayer.h: interface for the cMultiplayer class.
- //
- //////////////////////////////////////////////////////////////////////
- #if !defined(AFX_CMULTIPLAYER_H__1AA8D187_1064_40A7_A709_B2684653429F__INCLUDED_)
- #define AFX_CMULTIPLAYER_H__1AA8D187_1064_40A7_A709_B2684653429F__INCLUDED_
- #if _MSC_VER > 1000
- #pragma once
- #endif // _MSC_VER > 1000
- #include "stdafx.h"
- #include "cApplication.h"
- #include "cMessageHandler.h"
- #include <dplay8.h>
- #include <vector>
- #include <list>
- using namespace std;
- #define PLAYERTYPE_HOST 1
- #define PLAYERTYPE_PEER 2
- extern const GUID g_guidApp;
- struct PLAYER_MESSAGE
- {
- int m_iType;
- BYTE* pReceiveData;
- };
- struct PLAYER_INFO
- {
- DPNID dpnidPlayer;
- };
- struct HOST_NODE
- {
- DPN_APPLICATION_DESC* pAppDesc;
- IDirectPlay8Address* pHostAddress;
- WCHAR* pwszSessionName;
- HOST_NODE* pNext;
- };
- typedef vector<PLAYER_INFO*> PLAYERINFO_VECTOR;
- typedef list<PLAYER_MESSAGE*> PLAYER_MESSAGES;
- typedef list<PLAYER_MESSAGE*>::iterator PLAYERMESSAGE_ELEMENT;
- class cMultiplayer : public cMessageHandler
- {
- private:
- cMessageHandler* m_pHandler;
- DWORD m_dwTcpPort;
- int m_iModemDevice;
- IDirectPlay8Peer *m_pDP;
- IDirectPlay8Address *m_pDeviceAddress;
- DPN_SERVICE_PROVIDER_INFO* m_pdnSPInfo;
- DPN_SERVICE_PROVIDER_INFO* m_pdnDeviceInfo;
- char m_sFlowControl[10];
- char m_sParity[10];
- char m_sStopBits[10];
- DWORD m_dwNumSP;
- DWORD m_dwNumDevices;
- int m_iSPIndex;
- int m_iSerialDevice;
- HOST_NODE* m_pHostList;
- int m_iNumHosts;
- BOOL m_bCanConnect;
- int m_iPlayerType;
- DPNID m_dpnidHost;
- DPNID m_dpnidSelf;
- PLAYER_MESSAGES m_lstMessages;
- CRITICAL_SECTION m_csMessages;
- PLAYERINFO_VECTOR m_lstPlayers;
- public:
- void SetHandler(cMessageHandler *pHandler);
- void ReleaseMessage();
- int GetMyId();
- void FindHost();
- int GetHost();
- void RemoveMessage(PLAYER_MESSAGE* pMessage);
- PLAYER_MESSAGE* GetMessage(int iIndex);
- int GetNumMessages();
- void SendTo(DPNID dpnidTarget, int iType, LPBYTE lpBuffer, DWORD dwSize, DWORD dwFlags = DPNSEND_SYNC | DPNSEND_NOLOOPBACK);
- PLAYER_INFO* GetPlayerInfo(int iIndex);
- int GetNumConnected();
- BOOL IsHosting();
- void Connect(int iHost);
- BOOL GetCanConnect();
- void SetCanConnect(BOOL bValue);
- void GetSessionName(int iIndex, char* sValue, int iSize);
- int GetNumSessions();
- BOOL EnumSessions();
- BOOL Host(char* sSessionName);
- void AdvanceSPOption(int iOption);
- void GetSPOption(int iOption, char* szBuffer, DWORD dwBufferSize);
- char* GetSPOptionName(int iOption);
- int GetSPOptionType(int iOption);
- int GetSPIndex();
- void NextSP();
- int GetNumSPOptions();
- GUID* GetSPGuid(int iIndex);
- char* GetSPName(int iIndex);
- long GetNumSPs();
- void Destroy();
- void EnumServiceProviders();
- static HRESULT WINAPI cMultiplayer::StaticDirectPlayMessageHandler(
- PVOID pvUserContext,
- DWORD dwMessageId,
- PVOID pMsgBuffer );
- HRESULT WINAPI cMultiplayer::DirectPlayMessageHandler(
- PVOID pvUserContext,
- DWORD dwMessageId,
- PVOID pMsgBuffer );
- BOOL Initialize();
- cMultiplayer();
- virtual ~cMultiplayer();
- DWORD GetRegDWValue(char* lpszValue);
- char* GetRegStringValue(char* lpszValue, char* szBuffer, DWORD dwBufLen);
- void SetRegDWValue(char* lpszValueName, DWORD dwValue);
- void SetRegStringValue(char* lpszValueName, char* lpszValue);
- protected:
- DWORD m_dwBaudRate;
- void EnumDevices();
- };
- #endif // !defined(AFX_CMULTIPLAYER_H__1AA8D187_1064_40A7_A709_B2684653429F__INCLUDED_)