home *** CD-ROM | disk | FTP | other *** search
/ Programming an RTS Game with Direct3D / Programming an RTS Game with Direct3D.iso / Examples / Chapter 15 / Example 15.2 / network.h < prev    next >
Encoding:
C/C++ Source or Header  |  2006-06-30  |  1.5 KB  |  47 lines

  1. #ifndef _RTS_NETWORK_
  2. #define _RTS_NETWORK_
  3.  
  4. #include <windows.h>
  5. #include <dplay8.h>     // directplay
  6. #include <vector>
  7. #include "debug.h"
  8. #include "terrain.h"
  9. #include "network_messages.h"
  10.  
  11. class NETWORK
  12. {
  13.     friend HRESULT WINAPI ServerCallback(PVOID pvUserContext, DWORD dwMessageType, PVOID pMessage);
  14.     friend HRESULT WINAPI ClientCallback(PVOID pvUserContext, DWORD dwMessageType, PVOID pMessage);
  15.     public:
  16.         NETWORK();
  17.         ~NETWORK();
  18.  
  19.         void Init(bool _server, char _playerName[]);
  20.         void Release();
  21.         void HostNewSession(char sessionName[]);
  22.         void FindSessions();                                    //Enumerate all available sessions
  23.         HRESULT ConnectToSession(int index);
  24.         DP_PLAYER *FindPlayer(DPNID id);
  25.         void Send(RTS_MSG *msg, bool guaranteed);                //Send to all (or server)
  26.         void SendTo(DPNID id, RTS_MSG *msg, bool guaranteed);    //Send To specific player 
  27.         
  28.         //Public Variables
  29.         bool server, connected;
  30.         char playerName[64];                //Name of local player
  31.         char activeSession[50];                //name of active session
  32.         std::vector<SESSION> sessions;
  33.         std::vector<DP_PLAYER> players;
  34.         std::vector<std::string> chat;
  35.  
  36.     private:
  37.         IDirectPlay8Server *m_pServer;
  38.         IDirectPlay8Client *m_pClient;
  39.         IDirectPlay8Address *m_pMyAddress, *m_pServerAddress;
  40.         DPNID m_localID;
  41. };
  42.  
  43. //Network callback functions
  44. HRESULT WINAPI ServerCallback(PVOID pvUserContext, DWORD dwMessageType, PVOID pMessage);
  45. HRESULT WINAPI ClientCallback(PVOID pvUserContext, DWORD dwMessageType, PVOID pMessage);
  46.  
  47. #endif