root/trunk/raknet/raknet/networktypes.d

Revision 33, 3.1 kB (checked in by clayasaurus, 6 years ago)

added UNASSIGNED IDs

Line 
1 module raknet.networktypes;
2
3 debug import std.stdio;
4
5 /* -*- mode: c++; c-file-style: raknet; tab-always-indent: nil; -*- */
6 /**
7  * @file
8  * @brief Unique Player Identifier Class implementation
9  *
10  * This file is part of RakNet Copyright 2003, 2004 Rakkarsoft LLC and
11  * Kevin Jenkins.
12  *
13  * Usage of Raknet is subject to the appropriate licence agreement.
14  * "Shareware" Licensees with Rakkarsoft LLC are subject to the
15  * shareware license found at
16  * http://www.rakkarsoft.com/shareWareLicense.html which you agreed to
17  * upon purchase of a "Shareware license" "Commercial" Licensees with
18  * Rakkarsoft LLC are subject to the commercial license found at
19  * http://www.rakkarsoft.com/sourceCodeLicense.html which you agreed
20  * to upon purchase of a "Commercial license" All other users are
21  * subject to the GNU General Public License as published by the Free
22  * Software Foundation; either version 2 of the License, or (at your
23  * option) any later version.
24  *
25  * Refer to the appropriate license agreement for distribution,
26  * modification, and warranty rights.
27  */
28 //#include "BitStream.h"
29
30 /**
31 * Typename for Network Object Identifier
32 */
33 alias ushort ObjectID;
34 /**
35 * Typename for Unique Id
36 */
37 alias ubyte UniqueIDType;
38 /**
39 * Typename for player index
40 */
41 alias ushort PlayerIndex;
42
43 const PlayerIndex UNASSIGNED_PLAYER_INDEX = 65535;
44
45 const PlayerID UNASSIGNED_PLAYER_ID =
46 {
47    binaryAddress:0xFFFFFFFF, port:0xFFFF
48 };
49
50
51
52 /**
53 * @brief Player Identifier
54 *
55 * This define a Player Unique Identifier.
56 * In fact, it corresponds to the peer address.
57 */
58
59 /// Size of PlayerID data
60 const int PlayerID_Size = 6;
61
62
63 extern(C):
64
65 struct PlayerID
66 {
67    /**
68    * The peer address from inet_addr.
69    */
70    uint binaryAddress;
71    /**
72    * The port number associated to the connexion.
73    */
74    ushort port;
75    /**
76    * Copy operator
77    * @param input a player ID
78    * @return a reference to the current object
79    */
80
81 debug
82 {
83    void print()
84    {
85       writefln("Binary Address: ", binaryAddress, ", port: ", port);
86    }
87 }
88
89    // handles == and !=
90    int opEquals(inout PlayerID pid)
91    {
92       return ( binaryAddress == pid.binaryAddress && port == pid.port );
93    }
94
95    // handles > and <
96    int opCmp(inout PlayerID pid)
97    {
98       return (  ( binaryAddress - pid.binaryAddress ) || ( ( binaryAddress == pid.binaryAddress ) &&
99                 ( port - pid.port ) )  );
100    }
101 }
102
103
104
105 /**
106 * @brief Network Packet
107 *
108 * This structure store information concerning
109 * a packet going throught the network
110 */
111
112 struct  Packet
113 {
114    /**
115    * Server only - this is the index into the player array that this playerId maps to
116    */
117    PlayerIndex playerIndex;
118
119    /**
120    * The Player Unique Identifier that send this packet.
121    */
122    PlayerID playerId;
123
124    /**
125    * The length of the data.
126    * @deprecated You should use bitSize inplace.
127    *
128    */
129    uint length;
130
131    /**
132    * The number of bits in used.
133    * Same as length but represents bits. Length is obsolete and retained for backwards compatibility.
134    */
135    uint bitSize;
136
137    /**
138    * The byte array.
139    * The standard behaviour in RakNet define the first byte of the data array as the packet class.
140    * @see PacketEnumerations.h 
141    */
142    ubyte* data;
143 }
Note: See TracBrowser for help on using the browser.