Starshatter_Open
Open source Starshatter engine
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
NetLink.h
Go to the documentation of this file.
1 /* Project nGenEx
2  Destroyer Studios LLC
3  Copyright © 1997-2004. All Rights Reserved.
4 
5  SUBSYSTEM: NetEx.lib
6  FILE: NetLink.h
7  AUTHOR: John DiCamillo
8 
9 
10  OVERVIEW
11  ========
12  Network Link for Remote Player
13 */
14 
15 
16 #ifndef NetLink_h
17 #define NetLink_h
18 
19 #include <windows.h>
20 #include "NetAddr.h"
21 #include "NetSock.h"
22 #include "List.h"
23 #include "ThreadSync.h"
24 
25 // +-------------------------------------------------------------------+
26 
27 class NetGram;
28 class NetMsg;
29 class NetPeer;
30 
31 // +-------------------------------------------------------------------+
32 
33 class NetLink
34 {
35 public:
36  static const char* TYPENAME() { return "NetLink"; }
37 
38  NetLink();
39  NetLink(NetAddr& a);
40  virtual ~NetLink();
41 
42  int operator == (const NetLink& that) const { return this == &that; }
43 
44  const NetAddr& GetAddress() const { return addr; }
45 
46  DWORD AddPeer(const char* a, WORD p=12345);
47  DWORD AddPeer(DWORD a, WORD p=12345);
48  DWORD AddPeer(const NetAddr& a);
49 
50  bool SendMessage(DWORD nid, void* d, int l, BYTE f=0);
51  bool SendMessage(DWORD nid, BYTE type, const char* text, int len, BYTE f=0);
52  bool SendMessage(NetMsg* msg);
53 
54  NetMsg* GetMessage();
55  NetMsg* GetMessage(DWORD netid);
56 
57  virtual void Shutdown();
58  DWORD DoSendRecv();
59 
60  DWORD GetResendInterval() const { return resend_time; }
61  void SetResendInterval(DWORD t) { resend_time = t; }
62  DWORD GetTrafficInterval() const { return traffic_time; }
63  void SetTrafficInterval(DWORD t) { traffic_time = t; }
64 
65  DWORD GetPacketsSent() const { return packets_sent; }
66  DWORD GetPacketsRecv() const { return packets_recv; }
67  DWORD GetBytesSent() const { return bytes_sent; }
68  DWORD GetBytesRecv() const { return bytes_recv; }
69  DWORD GetRetries() const { return retries; }
70  DWORD GetDrops() const { return drops; }
71  DWORD GetLag() const { return lag; }
72 
73  NetPeer* FindPeer(const NetAddr& a);
74  NetPeer* FindPeer(DWORD netid);
75 
76 protected:
77  void SendNetGram(NetGram* g);
79  void AckNetGram(NetGram* gram);
80  void ProcessAck(NetGram* gram);
81  void QueueNetGram(NetGram* gram);
82 
83  void ReadPackets();
84  void SendPackets();
85  void DoRetries();
86 
92 
93  HANDLE hnet;
94  bool shutdown;
96 
97  DWORD resend_time;
98  DWORD traffic_time;
99 
102  DWORD bytes_sent;
103  DWORD bytes_recv;
104  DWORD retries;
105  DWORD drops;
106  DWORD lag;
107 
108  DWORD lag_samples[10];
110 };
111 
112 
113 #endif NetLink_h