dnet.h

Engine/source/core/dnet.h

More...

Classes:

class

The base class for Torque's networking protocol.

Detailed Description

 1
 2//-----------------------------------------------------------------------------
 3// Copyright (c) 2012 GarageGames, LLC
 4//
 5// Permission is hereby granted, free of charge, to any person obtaining a copy
 6// of this software and associated documentation files (the "Software"), to
 7// deal in the Software without restriction, including without limitation the
 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 9// sell copies of the Software, and to permit persons to whom the Software is
10// furnished to do so, subject to the following conditions:
11//
12// The above copyright notice and this permission notice shall be included in
13// all copies or substantial portions of the Software.
14//
15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21// IN THE SOFTWARE.
22//-----------------------------------------------------------------------------
23
24#ifndef _DNET_H_
25#define _DNET_H_
26
27#ifndef _PLATFORM_H_
28#include "platform/platform.h"
29#endif
30
31#include "platform/platformNet.h"
32
33class BitStream;
34class ResizeBitStream;
35
36/// The base class for Torque's networking protocol.
37///
38/// This implements a sliding window connected message stream over an unreliable transport (UDP). It
39/// provides a simple notify protocol to allow subclasses to be aware of what packets were sent
40/// succesfully and which failed.
41///
42/// Basically, a window size of 32 is provided, and each packet contains in the header a bitmask,
43/// acknowledging the receipt (or failure to receive) of the last 32 packets.
44///
45/// @see NetConnection, @ref NetProtocol
46class ConnectionProtocol
47{
48protected:
49   U32 mLastSeqRecvdAtSend[32];
50   U32 mLastSeqRecvd;
51   U32 mHighestAckedSeq;
52   U32 mLastSendSeq;
53   U32 mAckMask;
54   U32 mConnectSequence;
55   U32 mLastRecvAckAck;
56   bool mConnectionEstablished;
57public:
58   ConnectionProtocol();
59
60   void buildSendPacketHeader(BitStream *bstream, S32 packetType = 0);
61
62   void sendPingPacket();
63   void sendAckPacket();
64   void setConnectionEstablished() { mConnectionEstablished = true; }
65
66   bool windowFull();
67   bool connectionEstablished();
68   void setConnectSequence(U32 connectSeq) { mConnectSequence = connectSeq; }
69
70   virtual void writeDemoStartBlock(ResizeBitStream *stream);
71   virtual bool readDemoStartBlock(BitStream *stream);
72
73   virtual void processRawPacket(BitStream *bstream);
74   virtual Net::Error sendPacket(BitStream *bstream) = 0;
75   virtual void keepAlive() = 0;
76   virtual void handleConnectionEstablished() = 0;
77   virtual void handleNotify(bool recvd) = 0;
78   virtual void handlePacket(BitStream *bstream) = 0;
79};
80
81#endif
82