├── CMakeLists.txt ├── Include └── raknet │ ├── BigTypes.h │ ├── BitStream.h │ ├── CheckSum.h │ ├── ClientContextStruct.h │ ├── CommandParserInterface.h │ ├── ConsoleServer.h │ ├── DS_BPlusTree.h │ ├── DS_BinarySearchTree.h │ ├── DS_HuffmanEncodingTree.h │ ├── DS_HuffmanEncodingTreeNode.h │ ├── DS_LinkedList.h │ ├── DS_List.h │ ├── DS_Map.h │ ├── DS_MemoryPool.h │ ├── DS_OrderedList.h │ ├── DS_Queue.h │ ├── DS_QueueLinkedList.h │ ├── DS_RangeList.h │ ├── DataBlockEncryptor.h │ ├── Export.h │ ├── GetTime.h │ ├── InternalPacket.h │ ├── InternalPacketPool.h │ ├── MTUSize.h │ ├── NetworkIDGenerator.h │ ├── NetworkTypes.h │ ├── PacketEnumerations.h │ ├── PacketLogger.h │ ├── PacketPriority.h │ ├── PluginInterface.h │ ├── RPCMap.h │ ├── RPCNode.h │ ├── RSACrypt.h │ ├── RakAssert.h │ ├── RakClient.h │ ├── RakClientInterface.h │ ├── RakNetCommandParser.h │ ├── RakNetDefines.h │ ├── RakNetStatistics.h │ ├── RakNetTransport.h │ ├── RakNetworkFactory.h │ ├── RakPeer.h │ ├── RakPeerInterface.h │ ├── RakServer.h │ ├── RakServerInterface.h │ ├── RakSleep.h │ ├── Rand.h │ ├── ReliabilityLayer.h │ ├── ReplicaEnums.h │ ├── RouterInterface.h │ ├── SHA1.h │ ├── SimpleMutex.h │ ├── SingleProducerConsumer.h │ ├── SocketLayer.h │ ├── StringCompressor.h │ ├── StringTable.h │ ├── TransportInterface.h │ ├── Types.h │ ├── _findfirst.h │ ├── rijndael-boxes.h │ └── rijndael.h ├── README.md ├── SAMPRakNet.cpp ├── SAMPRakNet.hpp ├── Source ├── BitStream.cpp ├── CheckSum.cpp ├── CommandParserInterface.cpp ├── ConsoleServer.cpp ├── DS_HuffmanEncodingTree.cpp ├── DataBlockEncryptor.cpp ├── GetTime.cpp ├── InternalPacketPool.cpp ├── Makefile ├── Makefile.am ├── NetworkTypes.cpp ├── PluginInterface.cpp ├── RPCMap.cpp ├── RakClient.cpp ├── RakNetCommandParser.cpp ├── RakNetworkFactory.cpp ├── RakPeer.cpp ├── RakSleep.cpp ├── Rand.cpp ├── ReliabilityLayer.cpp ├── SHA1.cpp ├── SimpleMutex.cpp ├── SocketLayer.cpp ├── StringCompressor.cpp ├── StringTable.cpp ├── _findfirst.cpp ├── rakserver.cpp └── rijndael.cpp ├── SpeexLicense.txt └── readme.txt /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if(WIN32) 2 | add_definitions( 3 | -D_CRT_SECURE_NO_WARNINGS 4 | -D_WINSOCK_DEPRECATED_NO_WARNINGS 5 | -DWIN32_LEAN_AND_MEAN 6 | ) 7 | endif() 8 | 9 | set(RAKNET_SOURCES 10 | Source/BitStream.cpp 11 | Source/CheckSum.cpp 12 | Source/CommandParserInterface.cpp 13 | Source/ConsoleServer.cpp 14 | Source/DataBlockEncryptor.cpp 15 | Source/DS_HuffmanEncodingTree.cpp 16 | Source/GetTime.cpp 17 | Source/InternalPacketPool.cpp 18 | Source/NetworkTypes.cpp 19 | Source/RakClient.cpp 20 | Source/RakNetCommandParser.cpp 21 | Source/RakNetworkFactory.cpp 22 | Source/RakPeer.cpp 23 | Source/rakserver.cpp 24 | Source/RakSleep.cpp 25 | Source/Rand.cpp 26 | Source/ReliabilityLayer.cpp 27 | Source/rijndael.cpp 28 | Source/RPCMap.cpp 29 | Source/SHA1.cpp 30 | Source/SimpleMutex.cpp 31 | Source/SocketLayer.cpp 32 | Source/StringCompressor.cpp 33 | Source/StringTable.cpp 34 | Source/PluginInterface.cpp 35 | SAMPRakNet.cpp 36 | ) 37 | 38 | add_library(raknet STATIC ${RAKNET_SOURCES}) 39 | 40 | set_property(TARGET raknet PROPERTY POSITION_INDEPENDENT_CODE ON) 41 | 42 | target_compile_definitions(raknet 43 | PUBLIC 44 | -DRAKNET_LEGACY 45 | -DPACKETS_PER_TICK=3 46 | ) 47 | target_include_directories(raknet 48 | INTERFACE Include 49 | PRIVATE Include/raknet 50 | ) 51 | 52 | if (WIN32) 53 | target_link_libraries(raknet Ws2_32 OMP-SDK) 54 | else() 55 | target_link_libraries(raknet OMP-SDK) 56 | endif() 57 | -------------------------------------------------------------------------------- /Include/raknet/CheckSum.h: -------------------------------------------------------------------------------- 1 | /// \file 2 | /// \brief \b [Internal] Generates and validates checksums 3 | /// 4 | /// \note I didn't write this, but took it from http://www.flounder.com/checksum.htm 5 | /// 6 | 7 | #ifndef __CHECKSUM_H 8 | #define __CHECKSUM_H 9 | 10 | namespace RakNet 11 | { 12 | /// Generates and validates checksums 13 | class CheckSum 14 | { 15 | 16 | public: 17 | 18 | /// Default constructor 19 | 20 | CheckSum() 21 | { 22 | Clear(); 23 | } 24 | 25 | void Clear() 26 | { 27 | sum = 0; 28 | r = 55665; 29 | c1 = 52845; 30 | c2 = 22719; 31 | } 32 | 33 | void Add ( unsigned int w ); 34 | 35 | 36 | void Add ( unsigned short w ); 37 | 38 | void Add ( unsigned char* b, unsigned int length ); 39 | 40 | void Add ( unsigned char b ); 41 | 42 | unsigned int Get () 43 | { 44 | return sum; 45 | } 46 | 47 | protected: 48 | unsigned short r; 49 | unsigned short c1; 50 | unsigned short c2; 51 | unsigned int sum; 52 | }; 53 | } 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /Include/raknet/ClientContextStruct.h: -------------------------------------------------------------------------------- 1 | /// \file 2 | /// \brief \b [Internal] Depreciated, back from when I supported IO Completion ports. 3 | /// 4 | /// This file is part of RakNet Copyright 2003 Kevin Jenkins. 5 | /// 6 | /// Usage of RakNet is subject to the appropriate license agreement. 7 | /// Creative Commons Licensees are subject to the 8 | /// license found at 9 | /// http://creativecommons.org/licenses/by-nc/2.5/ 10 | /// Single application licensees are subject to the license found at 11 | /// http://www.rakkarsoft.com/SingleApplicationLicense.html 12 | /// Custom license users are subject to the terms therein. 13 | /// GPL license users are subject to the GNU General Public 14 | /// License as published by the Free 15 | /// Software Foundation; either version 2 of the License, or (at your 16 | /// option) any later version. 17 | 18 | #ifndef __CLIENT_CONTEXT_STRUCT_H 19 | #define __CLIENT_CONTEXT_STRUCT_H 20 | 21 | #ifdef _COMPATIBILITY_1 22 | #elif defined(_WIN32) 23 | //#include 24 | #endif 25 | #include "NetworkTypes.h" 26 | #include "MTUSize.h" 27 | 28 | namespace RakNet 29 | { 30 | class RakPeer; 31 | 32 | #ifdef __USE_IO_COMPLETION_PORTS 33 | 34 | struct ClientContextStruct 35 | { 36 | HANDLE handle; // The socket, also used as a file handle 37 | }; 38 | 39 | struct ExtendedOverlappedStruct 40 | { 41 | OVERLAPPED overlapped; 42 | char data[ MAXIMUM_MTU_SIZE ]; // Used to hold data to send 43 | int length; // Length of the actual data to send, always under MAXIMUM_MTU_SIZE 44 | unsigned int binaryAddress; 45 | unsigned short port; 46 | RakPeer *rakPeer; 47 | bool read; // Set to true for reads, false for writes 48 | }; 49 | 50 | #endif 51 | } 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /Include/raknet/CommandParserInterface.h: -------------------------------------------------------------------------------- 1 | /// \file 2 | /// \brief Contains CommandParserInterface , from which you derive custom command parsers 3 | /// 4 | /// This file is part of RakNet Copyright 2003 Kevin Jenkins. 5 | /// 6 | /// Usage of RakNet is subject to the appropriate license agreement. 7 | /// Creative Commons Licensees are subject to the 8 | /// license found at 9 | /// http://creativecommons.org/licenses/by-nc/2.5/ 10 | /// Single application licensees are subject to the license found at 11 | /// http://www.rakkarsoft.com/SingleApplicationLicense.html 12 | /// Custom license users are subject to the terms therein. 13 | /// GPL license users are subject to the GNU General Public 14 | /// License as published by the Free 15 | /// Software Foundation; either version 2 of the License, or (at your 16 | /// option) any later version. 17 | 18 | #ifndef __COMMAND_PARSER_INTERFACE 19 | #define __COMMAND_PARSER_INTERFACE 20 | 21 | #include "NetworkTypes.h" 22 | #include "DS_OrderedList.h" 23 | #include "Export.h" 24 | 25 | namespace RakNet 26 | { 27 | class TransportInterface; 28 | 29 | /// \internal 30 | /// Contains the information related to one command registered with RegisterCommand() 31 | /// Implemented so I can have an automatic help system via SendCommandList() 32 | struct RAK_DLL_EXPORT RegisteredCommand 33 | { 34 | const char *command; 35 | const char *commandHelp; 36 | unsigned char parameterCount; 37 | }; 38 | 39 | /// List of commands registered with RegisterCommand() 40 | int RAK_DLL_EXPORT RegisteredCommandComp( const char* const & key, const RegisteredCommand &data ); 41 | 42 | /// CommandParserInterface provides a set of functions and interfaces that plug into the ConsoleServer class. 43 | /// Each CommandParserInterface works at the same time as other interfaces in the system. 44 | /// \brief The interface used by command parsers. 45 | class RAK_DLL_EXPORT CommandParserInterface 46 | { 47 | public: 48 | CommandParserInterface(); 49 | virtual ~CommandParserInterface(); 50 | 51 | /// You are responsible for overriding this function and returning a static string, which will identifier your parser. 52 | /// This should return a static string 53 | /// \return The name that you return. 54 | virtual char *GetName(void) const=0; 55 | 56 | /// A callback for when \a playerId has connected to us. 57 | /// \param[in] playerId The player that has connected. 58 | /// \param[in] transport The transport interface that sent us this information. Can be used to send messages to this or other players. 59 | virtual void OnNewIncomingConnection(PlayerID playerId, TransportInterface *transport); 60 | 61 | /// A callback for when \a playerId has disconnected, either gracefully or forcefully 62 | /// \param[in] playerId The player that has disconnected. 63 | /// \param[in] transport The transport interface that sent us this information. 64 | virtual void OnConnectionLost(PlayerID playerId, TransportInterface *transport); 65 | 66 | /// A callback for when you are expected to send a brief description of your parser to \a playerId 67 | /// \param[in] transport The transport interface we can use to write to 68 | /// \param[in] playerId The player that requested help. 69 | virtual void SendHelp(TransportInterface *transport, PlayerID playerId)=0; 70 | 71 | /// Given \a command with parameters \a parameterList , do whatever processing you wish. 72 | /// \param[in] command The command to process 73 | /// \param[in] numParameters How many parameters were passed along with the command 74 | /// \param[in] parameterList The list of parameters. parameterList[0] is the first parameter and so on. 75 | /// \param[in] transport The transport interface we can use to write to 76 | /// \param[in] playerId The player that sent this command. 77 | /// \param[in] originalString The string that was actually sent over the network, in case you want to do your own parsing 78 | virtual bool OnCommand(const char *command, unsigned numParameters, char **parameterList, TransportInterface *transport, PlayerID playerId, const char *originalString)=0; 79 | 80 | /// This is called every time transport interface is registered. If you want to save a copy of the TransportInterface pointer 81 | /// This is the place to do it 82 | /// \param[in] transport The new TransportInterface 83 | virtual void OnTransportChange(TransportInterface *transport); 84 | 85 | /// \internal 86 | /// Scan commandList and return the associated array 87 | /// \param[in] command The string to find 88 | /// \param[out] rc Contains the result of this operation 89 | /// \return True if we found the command, false otherwise 90 | virtual bool GetRegisteredCommand(const char *command, RegisteredCommand *rc); 91 | 92 | /// \internal 93 | /// Goes through str, replacing the delineating character with 0's. 94 | /// \param[in] str The string sent by the transport interface 95 | /// \param[in] delineator The character to scan for to use as a delineator 96 | /// \param[in] delineatorToggle When encountered the delineator replacement is toggled on and off 97 | /// \param[out] numParameters How many pointers were written to \a parameterList 98 | /// \param[out] parameterList An array of pointers to characters. Will hold pointers to locations inside \a str 99 | /// \param[in] parameterListLength How big the \a parameterList array is 100 | static void ParseConsoleString(char *str, const char delineator, unsigned char delineatorToggle, unsigned *numParameters, char **parameterList, unsigned parameterListLength); 101 | 102 | /// \internal 103 | /// Goes through the variable commandList and sends the command portion of each struct 104 | /// \param[in] transport The transport interface we can use to write to 105 | /// \param[in] playerId The player to write to 106 | virtual void SendCommandList(TransportInterface *transport, PlayerID playerId); 107 | 108 | static const unsigned char VARIABLE_NUMBER_OF_PARAMETERS; 109 | 110 | protected: 111 | // Currently only takes static strings - doesn't make a copy of what you pass. 112 | // parameterCount is the number of parameters that the sender has to include with the command. 113 | // Pass 255 to parameterCount to indicate variable number of parameters 114 | 115 | /// Registers a command. 116 | /// \param[in] parameterCount How many parameters your command requires. If you want to accept a variable number of commands, pass CommandParserInterface::VARIABLE_NUMBER_OF_PARAMETERS 117 | /// \param[in] command A pointer to a STATIC string that has your command. I keep a copy of the pointer here so don't deallocate the string. 118 | /// \param[in] commandHelp A pointer to a STATIC string that has the help information for your command. I keep a copy of the pointer here so don't deallocate the string. 119 | virtual void RegisterCommand(unsigned char parameterCount, const char *command, const char *commandHelp); 120 | 121 | /// Just writes a string to the remote system based on the result ( \a res )of your operation 122 | /// This is not necessary to call, but makes it easier to return results of function calls 123 | /// \param[in] res The result to write 124 | /// \param[in] command The command that this result came from 125 | /// \param[in] transport The transport interface that will be written to 126 | /// \param[in] playerId The player this result will be sent to 127 | virtual void ReturnResult(bool res, const char *command, TransportInterface *transport, PlayerID playerId); 128 | virtual void ReturnResult(char *res, const char *command, TransportInterface *transport, PlayerID playerId); 129 | virtual void ReturnResult(PlayerID res, const char *command, TransportInterface *transport, PlayerID playerId); 130 | virtual void ReturnResult(int res, const char *command,TransportInterface *transport, PlayerID playerId); 131 | 132 | /// Just writes a string to the remote system when you are calling a function that has no return value 133 | /// This is not necessary to call, but makes it easier to return results of function calls 134 | /// \param[in] res The result to write 135 | /// \param[in] command The command that this result came from 136 | /// \param[in] transport The transport interface that will be written to 137 | /// \param[in] playerId The player this result will be sent to 138 | virtual void ReturnResult(const char *command,TransportInterface *transport, PlayerID playerId); 139 | 140 | 141 | /// Since there's no way to specify a playerID directly, the user needs to specify both the binary address and port. 142 | /// Given those parameters, this returns the corresponding PlayerID 143 | /// \param[in] binaryAddress The binaryAddress portion of PlayerID 144 | /// \param[in] port The port portion of PlayerID 145 | PlayerID IntegersToPlayerID(int binaryAddress, int port); 146 | 147 | DataStructures::OrderedList commandList; 148 | }; 149 | } 150 | 151 | #endif 152 | -------------------------------------------------------------------------------- /Include/raknet/ConsoleServer.h: -------------------------------------------------------------------------------- 1 | /// \file 2 | /// \brief Contains ConsoleServer , used to plugin to your game to accept remote console-based connections 3 | /// 4 | /// This file is part of RakNet Copyright 2003 Kevin Jenkins. 5 | /// 6 | /// Usage of RakNet is subject to the appropriate license agreement. 7 | /// Creative Commons Licensees are subject to the 8 | /// license found at 9 | /// http://creativecommons.org/licenses/by-nc/2.5/ 10 | /// Single application licensees are subject to the license found at 11 | /// http://www.rakkarsoft.com/SingleApplicationLicense.html 12 | /// Custom license users are subject to the terms therein. 13 | /// GPL license users are subject to the GNU General Public 14 | /// License as published by the Free 15 | /// Software Foundation; either version 2 of the License, or (at your 16 | /// option) any later version. 17 | 18 | #ifndef __CONSOLE_SERVER_H 19 | #define __CONSOLE_SERVER_H 20 | 21 | #include "DS_List.h" 22 | #include "NetworkTypes.h" 23 | #include "Export.h" 24 | 25 | namespace RakNet 26 | { 27 | class TransportInterface; 28 | class CommandParserInterface; 29 | 30 | /// \brief The main entry point for the server portion of your remote console application support. 31 | /// ConsoleServer takes one TransportInterface and one or more CommandParserInterface (s) 32 | /// The TransportInterface will be used to send data between the server and the client. The connecting client must support the 33 | /// protocol used by your derivation of TransportInterface . TelnetTransport and RakNetTransport are two such derivations . 34 | /// When a command is sent by a remote console, it will be processed by your implementations of CommandParserInterface 35 | class RAK_DLL_EXPORT ConsoleServer 36 | { 37 | public: 38 | ConsoleServer(); 39 | ~ConsoleServer(); 40 | 41 | /// Call this with a derivation of TransportInterface so that the console server can send and receive commands 42 | /// \param[in] transportInterface Your interface to use. 43 | /// \param[in] port The port to host on. Telnet uses port 23 by default. RakNet can use whatever you want. 44 | void SetTransportProvider(TransportInterface *transportInterface, unsigned short port); 45 | 46 | /// Add an implementation of CommandParserInterface to the list of command parsers. 47 | /// \param[in] commandParserInterface The command parser referred to 48 | void AddCommandParser(CommandParserInterface *commandParserInterface); 49 | 50 | /// Remove an implementation of CommandParserInterface previously added with AddCommandParser() 51 | /// \param[in] commandParserInterface The command parser referred to 52 | void RemoveCommandParser(CommandParserInterface *commandParserInterface); 53 | 54 | /// Call update to read packet sent from your TransportInterface. 55 | /// You should do this fairly frequently. 56 | void Update(void); 57 | protected: 58 | void ListParsers(PlayerID playerId); 59 | TransportInterface *transport; 60 | DataStructures::List commandParserList; 61 | char* password[256]; 62 | }; 63 | } 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /Include/raknet/DS_HuffmanEncodingTree.h: -------------------------------------------------------------------------------- 1 | /// \file 2 | /// \brief \b [Internal] Generates a huffman encoding tree, used for string and global compression. 3 | /// 4 | /// This file is part of RakNet Copyright 2003 Kevin Jenkins. 5 | /// 6 | /// Usage of RakNet is subject to the appropriate license agreement. 7 | /// Creative Commons Licensees are subject to the 8 | /// license found at 9 | /// http://creativecommons.org/licenses/by-nc/2.5/ 10 | /// Single application licensees are subject to the license found at 11 | /// http://www.rakkarsoft.com/SingleApplicationLicense.html 12 | /// Custom license users are subject to the terms therein. 13 | /// GPL license users are subject to the GNU General Public 14 | /// License as published by the Free 15 | /// Software Foundation; either version 2 of the License, or (at your 16 | /// option) any later version. 17 | 18 | #ifndef __HUFFMAN_ENCODING_TREE 19 | #define __HUFFMAN_ENCODING_TREE 20 | 21 | #include "DS_HuffmanEncodingTreeNode.h" 22 | #include "BitStream.h" 23 | #include "Export.h" 24 | #include "DS_LinkedList.h" 25 | 26 | namespace RakNet 27 | { 28 | namespace DataStructures 29 | { 30 | /// This generates special cases of the huffman encoding tree using 8 bit keys with the additional condition that unused combinations of 8 bits are treated as a frequency of 1 31 | class RAK_DLL_EXPORT HuffmanEncodingTree 32 | { 33 | 34 | public: 35 | HuffmanEncodingTree(); 36 | ~HuffmanEncodingTree(); 37 | 38 | /// Pass an array of bytes to array and a preallocated BitStream to receive the output 39 | /// \param [in] input Array of bytes to encode 40 | /// \param [in] sizeInBytes size of \a input 41 | /// \param [out] output The bitstream to write to 42 | void EncodeArray( unsigned char *input, unsigned sizeInBytes, RakNet::BitStream * output ); 43 | 44 | // Decodes an array encoded by EncodeArray() 45 | unsigned DecodeArray( RakNet::BitStream * input, unsigned & sizeInBits, unsigned maxCharsToWrite, unsigned char *output, bool skip = true ); 46 | void DecodeArray( unsigned char *input, unsigned sizeInBits, RakNet::BitStream * output ); 47 | 48 | /// Given a frequency table of 256 elements, all with a frequency of 1 or more, generate the tree 49 | void GenerateFromFrequencyTable( unsigned int frequencyTable[ 256 ] ); 50 | 51 | /// Free the memory used by the tree 52 | void FreeMemory( void ); 53 | 54 | private: 55 | 56 | /// The root node of the tree 57 | 58 | HuffmanEncodingTreeNode *root; 59 | 60 | /// Used to hold bit encoding for one character 61 | 62 | 63 | struct CharacterEncoding 64 | { 65 | unsigned char* encoding; 66 | unsigned short bitLength; 67 | }; 68 | 69 | CharacterEncoding encodingTable[ 256 ]; 70 | 71 | void InsertNodeIntoSortedList( HuffmanEncodingTreeNode * node, LinkedList *huffmanEncodingTreeNodeList ) const; 72 | }; 73 | } 74 | } 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /Include/raknet/DS_HuffmanEncodingTreeNode.h: -------------------------------------------------------------------------------- 1 | /// \file 2 | /// \brief \b [Internal] A single node in the Huffman Encoding Tree. 3 | /// 4 | /// This file is part of RakNet Copyright 2003 Kevin Jenkins. 5 | /// 6 | /// Usage of RakNet is subject to the appropriate license agreement. 7 | /// Creative Commons Licensees are subject to the 8 | /// license found at 9 | /// http://creativecommons.org/licenses/by-nc/2.5/ 10 | /// Single application licensees are subject to the license found at 11 | /// http://www.rakkarsoft.com/SingleApplicationLicense.html 12 | /// Custom license users are subject to the terms therein. 13 | /// GPL license users are subject to the GNU General Public 14 | /// License as published by the Free 15 | /// Software Foundation; either version 2 of the License, or (at your 16 | /// option) any later version. 17 | 18 | #ifndef __HUFFMAN_ENCODING_TREE_NODE 19 | #define __HUFFMAN_ENCODING_TREE_NODE 20 | 21 | namespace RakNet 22 | { 23 | namespace DataStructures 24 | { 25 | struct HuffmanEncodingTreeNode 26 | { 27 | unsigned char value; 28 | unsigned weight; 29 | HuffmanEncodingTreeNode *left; 30 | HuffmanEncodingTreeNode *right; 31 | HuffmanEncodingTreeNode *parent; 32 | }; 33 | } 34 | } 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /Include/raknet/DS_MemoryPool.h: -------------------------------------------------------------------------------- 1 | #ifndef __MEMORY_POOL_H 2 | #define __MEMORY_POOL_H 3 | 4 | #include "DS_List.h" 5 | #include 6 | 7 | namespace RakNet 8 | { 9 | namespace DataStructures 10 | { 11 | template 12 | class MemoryPool 13 | { 14 | public: 15 | MemoryPool(); 16 | ~MemoryPool(); 17 | void Preallocate(unsigned numElements); 18 | MemoryBlockType *Allocate(void); 19 | void Release(MemoryBlockType *m); 20 | void Clear(void); 21 | protected: 22 | int blocksOut; 23 | List pool; 24 | }; 25 | 26 | template 27 | MemoryPool::MemoryPool() 28 | { 29 | #ifdef _DEBUG 30 | blocksOut=0; 31 | #endif 32 | } 33 | template 34 | MemoryPool::~MemoryPool() 35 | { 36 | 37 | RakAssert(blocksOut==0); 38 | 39 | unsigned i; 40 | for (i=0; i < pool.Size(); i++) 41 | delete pool[i]; 42 | } 43 | 44 | template 45 | void MemoryPool::Preallocate(unsigned numElements) 46 | { 47 | unsigned i; 48 | for (i=pool.Size(); i < numElements; i++) 49 | { 50 | pool.Insert(new MemoryBlockType); 51 | } 52 | } 53 | 54 | template 55 | MemoryBlockType* MemoryPool::Allocate(void) 56 | { 57 | #ifdef _DEBUG 58 | blocksOut++; 59 | #endif 60 | if (pool.Size()==0) 61 | return new MemoryBlockType; 62 | else 63 | { 64 | MemoryBlockType* out; 65 | out=pool[pool.Size()-1]; 66 | pool.Del(); 67 | return out; 68 | } 69 | } 70 | template 71 | void MemoryPool::Release(MemoryBlockType *m) 72 | { 73 | pool.Insert(m); 74 | #ifdef _DEBUG 75 | RakAssert(blocksOut>0); 76 | blocksOut--; 77 | #endif 78 | } 79 | template 80 | void MemoryPool::Clear(void) 81 | { 82 | 83 | RakAssert(blocksOut==0); 84 | 85 | unsigned i; 86 | for (i=0; i < pool.Size(); i++) 87 | delete pool[i]; 88 | pool.Clear(); 89 | } 90 | } 91 | } 92 | 93 | #endif 94 | -------------------------------------------------------------------------------- /Include/raknet/DS_QueueLinkedList.h: -------------------------------------------------------------------------------- 1 | /// \file 2 | /// \brief \b [Internal] A queue implemented as a linked list. 3 | /// 4 | /// This file is part of RakNet Copyright 2003 Kevin Jenkins. 5 | /// 6 | /// Usage of RakNet is subject to the appropriate license agreement. 7 | /// Creative Commons Licensees are subject to the 8 | /// license found at 9 | /// http://creativecommons.org/licenses/by-nc/2.5/ 10 | /// Single application licensees are subject to the license found at 11 | /// http://www.rakkarsoft.com/SingleApplicationLicense.html 12 | /// Custom license users are subject to the terms therein. 13 | /// GPL license users are subject to the GNU General Public 14 | /// License as published by the Free 15 | /// Software Foundation; either version 2 of the License, or (at your 16 | /// option) any later version. 17 | 18 | #ifndef __QUEUE_LINKED_LIST_H 19 | #define __QUEUE_LINKED_LIST_H 20 | 21 | #include "DS_LinkedList.h" 22 | #include "Export.h" 23 | 24 | namespace RakNet 25 | { 26 | /// The namespace DataStructures was only added to avoid compiler errors for commonly named data structures 27 | /// As these data structures are stand-alone, you can use them outside of RakNet for your own projects if you wish. 28 | namespace DataStructures 29 | { 30 | /// \brief A queue implemented using a linked list. Rarely used. 31 | template 32 | class RAK_DLL_EXPORT QueueLinkedList 33 | { 34 | 35 | public: 36 | QueueLinkedList(); 37 | QueueLinkedList( const QueueLinkedList& original_copy ); 38 | bool operator= ( const QueueLinkedList& original_copy ); 39 | QueueType Pop( void ); 40 | QueueType& Peek( void ); 41 | QueueType& EndPeek( void ); 42 | void Push( const QueueType& input ); 43 | unsigned int Size( void ); 44 | void Clear( void ); 45 | void Compress( void ); 46 | 47 | private: 48 | LinkedList data; 49 | }; 50 | 51 | template 52 | QueueLinkedList::QueueLinkedList() 53 | { 54 | } 55 | 56 | template 57 | inline unsigned int QueueLinkedList::Size() 58 | { 59 | return data.Size(); 60 | } 61 | 62 | template 63 | inline QueueType QueueLinkedList::Pop( void ) 64 | { 65 | data.Beginning(); 66 | return ( QueueType ) data.Pop(); 67 | } 68 | 69 | template 70 | inline QueueType& QueueLinkedList::Peek( void ) 71 | { 72 | data.Beginning(); 73 | return ( QueueType ) data.Peek(); 74 | } 75 | 76 | template 77 | inline QueueType& QueueLinkedList::EndPeek( void ) 78 | { 79 | data.End(); 80 | return ( QueueType ) data.Peek(); 81 | } 82 | 83 | template 84 | void QueueLinkedList::Push( const QueueType& input ) 85 | { 86 | data.End(); 87 | data.Add( input ); 88 | } 89 | 90 | template 91 | QueueLinkedList::QueueLinkedList( const QueueLinkedList& original_copy ) 92 | { 93 | data = original_copy.data; 94 | } 95 | 96 | template 97 | bool QueueLinkedList::operator= ( const QueueLinkedList& original_copy ) 98 | { 99 | if ( ( &original_copy ) == this ) 100 | return false; 101 | 102 | data = original_copy.data; 103 | } 104 | 105 | template 106 | void QueueLinkedList::Clear ( void ) 107 | { 108 | data.Clear(); 109 | } 110 | } // End namespace 111 | } 112 | 113 | #endif 114 | -------------------------------------------------------------------------------- /Include/raknet/DS_RangeList.h: -------------------------------------------------------------------------------- 1 | #ifndef __RANGE_LIST_H 2 | #define __RANGE_LIST_H 3 | 4 | #include "DS_OrderedList.h" 5 | #include "BitStream.h" 6 | #include 7 | 8 | namespace RakNet 9 | { 10 | namespace DataStructures 11 | { 12 | template 13 | struct RangeNode 14 | { 15 | RangeNode() {} 16 | ~RangeNode() {} 17 | RangeNode(range_type min, range_type max) {minIndex=min; maxIndex=max;} 18 | range_type minIndex = 0; 19 | range_type maxIndex = 0; 20 | }; 21 | 22 | 23 | template 24 | int RangeNodeComp(const range_type &a, const RangeNode &b) 25 | { 26 | if (a b.maxIndex) 29 | return 1; 30 | return 0; 31 | } 32 | 33 | template 34 | class RAK_DLL_EXPORT RangeList 35 | { 36 | public: 37 | RangeList(); 38 | ~RangeList(); 39 | void Insert(range_type index); 40 | void Clear(void); 41 | unsigned Size(void); 42 | unsigned RangeSum(void); 43 | unsigned Serialize(RakNet::BitStream *in, int maxBits, bool clearSerialized); 44 | bool Deserialize(RakNet::BitStream *out); 45 | 46 | OrderedList , RangeNodeComp > ranges; 47 | }; 48 | 49 | template 50 | unsigned RangeList::Serialize(RakNet::BitStream *in, int maxBits, bool clearSerialized) 51 | { 52 | RakAssert(ranges.Size() < (unsigned short)-1); 53 | RakNet::BitStream tempBS; 54 | int bitsWritten; 55 | unsigned short countWritten; 56 | unsigned i; 57 | countWritten=0; 58 | bitsWritten=0; 59 | for (i=0; i < ranges.Size(); i++) 60 | { 61 | if ((int)sizeof(unsigned short)*8+bitsWritten+(int)sizeof(range_type)*8*2+1>maxBits) 62 | break; 63 | tempBS.Write(ranges[i].minIndex==ranges[i].maxIndex); 64 | tempBS.Write(ranges[i].minIndex); 65 | bitsWritten+=sizeof(range_type)*8+1; 66 | if (ranges[i].minIndex!=ranges[i].maxIndex) 67 | { 68 | tempBS.Write(ranges[i].maxIndex); 69 | bitsWritten+=sizeof(range_type)*8; 70 | } 71 | countWritten++; 72 | } 73 | 74 | int before=in->GetWriteOffset(); 75 | in->WriteCompressed(countWritten); 76 | bitsWritten+=in->GetWriteOffset()-before; 77 | // printf("%i ", in->GetNumberOfBitsUsed()); 78 | in->Write(&tempBS, tempBS.GetNumberOfBitsUsed()); 79 | // printf("%i %i \n", tempBS.GetNumberOfBitsUsed(),in->GetNumberOfBitsUsed()); 80 | 81 | if (clearSerialized && countWritten) 82 | { 83 | unsigned rangeSize=ranges.Size(); 84 | for (i=0; i < rangeSize-countWritten; i++) 85 | { 86 | ranges[i]=ranges[i+countWritten]; 87 | } 88 | ranges.Del(countWritten); 89 | } 90 | 91 | return bitsWritten; 92 | } 93 | template 94 | bool RangeList::Deserialize(RakNet::BitStream *out) 95 | { 96 | ranges.Clear(); 97 | unsigned short count; 98 | out->ReadCompressed(count); 99 | unsigned short i; 100 | range_type min,max; 101 | bool maxEqualToMin; 102 | 103 | for (i=0; i < count; i++) 104 | { 105 | out->Read(maxEqualToMin); 106 | if (out->Read(min)==false) 107 | return false; 108 | if (maxEqualToMin==false) 109 | { 110 | if (out->Read(max)==false) 111 | return false; 112 | if (max(min,max)); 119 | } 120 | return true; 121 | } 122 | 123 | template 124 | RangeList::RangeList() 125 | { 126 | RangeNodeComp(0, RangeNode()); 127 | } 128 | 129 | template 130 | RangeList::~RangeList() 131 | { 132 | Clear(); 133 | } 134 | 135 | template 136 | void RangeList::Insert(range_type index) 137 | { 138 | if (ranges.Size()==0) 139 | { 140 | ranges.Insert(index, RangeNode(index, index)); 141 | return; 142 | } 143 | 144 | bool objectExists; 145 | unsigned insertionIndex=ranges.GetIndexFromKey(index, &objectExists); 146 | if (insertionIndex==ranges.Size()) 147 | { 148 | if (index == ranges[insertionIndex-1].maxIndex+1) 149 | ranges[insertionIndex-1].maxIndex++; 150 | else if (index > ranges[insertionIndex-1].maxIndex+1) 151 | { 152 | // Insert at end 153 | ranges.Insert(index, RangeNode(index, index)); 154 | } 155 | 156 | return; 157 | } 158 | 159 | if (index < ranges[insertionIndex].minIndex-1) 160 | { 161 | // Insert here 162 | ranges.InsertAtIndex(RangeNode(index, index), insertionIndex); 163 | 164 | return; 165 | } 166 | else if (index == ranges[insertionIndex].minIndex-1) 167 | { 168 | // Decrease minIndex and join left 169 | ranges[insertionIndex].minIndex--; 170 | if (insertionIndex>0 && ranges[insertionIndex-1].maxIndex+1==ranges[insertionIndex].minIndex) 171 | { 172 | ranges[insertionIndex-1].maxIndex=ranges[insertionIndex].maxIndex; 173 | ranges.RemoveAtIndex(insertionIndex); 174 | } 175 | 176 | return; 177 | } 178 | else if (index >= ranges[insertionIndex].minIndex && index <= ranges[insertionIndex].maxIndex) 179 | { 180 | // Already exists 181 | return; 182 | } 183 | else if (index == ranges[insertionIndex].maxIndex+1) 184 | { 185 | // Increase maxIndex and join right 186 | ranges[insertionIndex].maxIndex++; 187 | if (insertionIndex 198 | void RangeList::Clear(void) 199 | { 200 | ranges.Clear(); 201 | } 202 | 203 | template 204 | unsigned RangeList::Size(void) 205 | { 206 | return ranges.Size(); 207 | } 208 | 209 | template 210 | unsigned RangeList::RangeSum(void) 211 | { 212 | unsigned sum,i; 213 | for (i=0; i < ranges.Size(); i++) 214 | sum+=ranges[i].maxIndex-ranges[i].minIndex+1; 215 | return sum; 216 | } 217 | 218 | } 219 | } 220 | 221 | #endif 222 | -------------------------------------------------------------------------------- /Include/raknet/DataBlockEncryptor.h: -------------------------------------------------------------------------------- 1 | /// \file 2 | /// \brief \b [Internal] Encrypts and decrypts data blocks. Used as part of secure connections. 3 | /// 4 | /// This file is part of RakNet Copyright 2003 Kevin Jenkins. 5 | /// 6 | /// Usage of RakNet is subject to the appropriate license agreement. 7 | /// Creative Commons Licensees are subject to the 8 | /// license found at 9 | /// http://creativecommons.org/licenses/by-nc/2.5/ 10 | /// Single application licensees are subject to the license found at 11 | /// http://www.rakkarsoft.com/SingleApplicationLicense.html 12 | /// Custom license users are subject to the terms therein. 13 | /// GPL license users are subject to the GNU General Public 14 | /// License as published by the Free 15 | /// Software Foundation; either version 2 of the License, or (at your 16 | /// option) any later version. 17 | 18 | #ifndef __DATA_BLOCK_ENCRYPTOR_H 19 | #define __DATA_BLOCK_ENCRYPTOR_H 20 | 21 | #include "rijndael.h" 22 | 23 | namespace RakNet 24 | { 25 | /// Encrypts and decrypts data blocks. 26 | class DataBlockEncryptor 27 | { 28 | 29 | public: 30 | 31 | /// Constructor 32 | DataBlockEncryptor(); 33 | 34 | /// Destructor 35 | ~DataBlockEncryptor(); 36 | 37 | /// \return true if SetKey has been called previously 38 | bool IsKeySet( void ) const; 39 | 40 | /// Set the encryption key 41 | /// \param[in] key The new encryption key 42 | void SetKey( const unsigned char key[ 16 ] ); 43 | 44 | /// Unset the encryption key 45 | void UnsetKey( void ); 46 | 47 | /// Encryption adds up to 15 bytes. Output should be large enough to hold this. 48 | /// Output can be the same memory block as input 49 | /// \param[in] input the input buffer to encrypt 50 | /// \param[in] inputLength the size of the @em input buffer 51 | /// \param[in] output the output buffer to store encrypted data 52 | /// \param[in] outputLength the size of the output buffer 53 | void Encrypt( unsigned char *input, int inputLength, unsigned char *output, int *outputLength ); 54 | 55 | /// Decryption removes bytes, as few as 6. Output should be large enough to hold this. 56 | /// Output can be the same memory block as input 57 | /// \param[in] input the input buffer to decrypt 58 | /// \param[in] inputLength the size of the @em input buffer 59 | /// \param[in] output the output buffer to store decrypted data 60 | /// \param[in] outputLength the size of the @em output buffer 61 | /// \return False on bad checksum or input, true on success 62 | bool Decrypt( unsigned char *input, int inputLength, unsigned char *output, int *outputLength ); 63 | 64 | protected: 65 | 66 | keyInstance keyEncrypt; 67 | keyInstance keyDecrypt; 68 | cipherInstance cipherInst; 69 | bool keySet; 70 | }; 71 | } 72 | 73 | #endif 74 | -------------------------------------------------------------------------------- /Include/raknet/Export.h: -------------------------------------------------------------------------------- 1 | // Fuck it, GCC won't compile with exports. Someone else can fix this if they want 2 | #if defined(_WIN32) && !(defined(__GNUC__) || defined(__GCCXML__)) && !defined(_RAKNET_LIB) && defined(_RAKNET_DLL) 3 | #define RAK_DLL_EXPORT __declspec(dllexport) 4 | #else 5 | #define RAK_DLL_EXPORT 6 | #endif 7 | -------------------------------------------------------------------------------- /Include/raknet/GetTime.h: -------------------------------------------------------------------------------- 1 | /// \file 2 | /// \brief Returns the value from QueryPerformanceCounter. This is the function RakNet uses to represent time. 3 | /// 4 | /// This file is part of RakNet Copyright 2003 Kevin Jenkins. 5 | /// 6 | /// Usage of RakNet is subject to the appropriate license agreement. 7 | /// Creative Commons Licensees are subject to the 8 | /// license found at 9 | /// http://creativecommons.org/licenses/by-nc/2.5/ 10 | /// Single application licensees are subject to the license found at 11 | /// http://www.rakkarsoft.com/SingleApplicationLicense.html 12 | /// Custom license users are subject to the terms therein. 13 | /// GPL license users are subject to the GNU General Public 14 | /// License as published by the Free 15 | /// Software Foundation; either version 2 of the License, or (at your 16 | /// option) any later version. 17 | 18 | #ifndef __GET_TIME_H 19 | #define __GET_TIME_H 20 | 21 | #include "Export.h" 22 | #include "NetworkTypes.h" // For RakNetTime 23 | 24 | /// The namespace RakNet is not consistently used. It's only purpose is to avoid compiler errors for classes whose names are very common. 25 | /// For the most part I've tried to avoid this simply by using names very likely to be unique for my classes. 26 | namespace RakNet 27 | { 28 | /// Returns the value from QueryPerformanceCounter. This is the function RakNet uses to represent time. 29 | RakNetTime RAK_DLL_EXPORT GetTime( void ); 30 | RakNetTimeNS RAK_DLL_EXPORT GetTimeNS( void ); 31 | } 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /Include/raknet/InternalPacket.h: -------------------------------------------------------------------------------- 1 | /// \file 2 | /// \brief \b [Internal] A class which stores a user message, and all information associated with sending and receiving that message. 3 | /// 4 | /// This file is part of RakNet Copyright 2003 Kevin Jenkins. 5 | /// 6 | /// Usage of RakNet is subject to the appropriate license agreement. 7 | /// Creative Commons Licensees are subject to the 8 | /// license found at 9 | /// http://creativecommons.org/licenses/by-nc/2.5/ 10 | /// Single application licensees are subject to the license found at 11 | /// http://www.rakkarsoft.com/SingleApplicationLicense.html 12 | /// Custom license users are subject to the terms therein. 13 | /// GPL license users are subject to the GNU General Public 14 | /// License as published by the Free 15 | /// Software Foundation; either version 2 of the License, or (at your 16 | /// option) any later version. 17 | 18 | #ifndef __INTERNAL_PACKET_H 19 | #define __INTERNAL_PACKET_H 20 | 21 | #include "PacketPriority.h" 22 | #include "NetworkTypes.h" 23 | 24 | 25 | namespace RakNet 26 | { 27 | /// This is the counter used for holding ordered packet numbers, so we can detect out-of-order packets. It should be large enough that if the variables 28 | /// were to wrap, the newly wrapped values would no longer be in use. Warning: Too large of a value wastes bandwidth! 29 | typedef unsigned short OrderingIndexType; 30 | 31 | typedef unsigned short SplitPacketIdType; 32 | typedef unsigned int SplitPacketIndexType; 33 | 34 | 35 | /// This is the counter used for holding packet numbers, so we can detect duplicate packets. It should be large enough that if the variables 36 | /// were to wrap, the newly wrapped values would no longer be in use. Warning: Too large of a value wastes bandwidth! 37 | /// Use the smallest possible value, such that you send no more than rangeof(MessageNumberType) / GetTimeoutTime() packets per second 38 | /// For the default value of 10 seconds, this is 39 | /// unsigned char - 25.5 packets per second 40 | /// unsigned short - 6553.5 packets per second 41 | /// unsigned int - You'll run out of memory first. 42 | typedef unsigned short MessageNumberType; 43 | 44 | /// Holds a user message, and related information 45 | struct InternalPacket 46 | { 47 | ///True if this is an acknowledgment packet 48 | //bool isAcknowledgement; 49 | 50 | ///A unique numerical identifier given to this user message 51 | MessageNumberType messageNumber; 52 | /// Used only for tracking packetloss and windowing internally, this is the aggreggate packet number that a message was last sent in 53 | unsigned packetNumber; 54 | /// Was this packet number used this update to track windowing drops or increases? Each packet number is only used once per update. 55 | // bool allowWindowUpdate; 56 | ///The priority level of this packet 57 | PacketPriority priority; 58 | ///What type of reliability algorithm to use with this packet 59 | PacketReliability reliability; 60 | ///What ordering channel this packet is on, if the reliability type uses ordering channels 61 | unsigned char orderingChannel; 62 | ///The ID used as identification for ordering channels 63 | OrderingIndexType orderingIndex; 64 | ///The ID of the split packet, if we have split packets. This is the maximum number of split messages we can send simultaneously per connection. 65 | SplitPacketIdType splitPacketId; 66 | ///If this is a split packet, the index into the array of subsplit packets 67 | SplitPacketIndexType splitPacketIndex; 68 | ///The size of the array of subsplit packets 69 | SplitPacketIndexType splitPacketCount; 70 | ///When this packet was created 71 | RakNetTimeNS creationTime; 72 | ///The next time to take action on this packet 73 | RakNetTimeNS nextActionTime; 74 | ///How many bits the data is 75 | unsigned int dataBitLength; 76 | ///Buffer is a pointer to the actual data, assuming this packet has data at all 77 | unsigned char *data; 78 | /// For checking packetloss at a particular send rate 79 | unsigned histogramMarker; 80 | }; 81 | } 82 | 83 | #endif 84 | 85 | -------------------------------------------------------------------------------- /Include/raknet/InternalPacketPool.h: -------------------------------------------------------------------------------- 1 | /// \file 2 | /// \brief \b [Internal] Memory pool for InternalPacket* 3 | /// 4 | /// This file is part of RakNet Copyright 2003 Kevin Jenkins. 5 | /// 6 | /// Usage of RakNet is subject to the appropriate license agreement. 7 | /// Creative Commons Licensees are subject to the 8 | /// license found at 9 | /// http://creativecommons.org/licenses/by-nc/2.5/ 10 | /// Single application licensees are subject to the license found at 11 | /// http://www.rakkarsoft.com/SingleApplicationLicense.html 12 | /// Custom license users are subject to the terms therein. 13 | /// GPL license users are subject to the GNU General Public 14 | /// License as published by the Free 15 | /// Software Foundation; either version 2 of the License, or (at your 16 | /// option) any later version. 17 | 18 | #ifndef __INTERNAL_PACKET_POOL 19 | #define __INTERNAL_PACKET_POOL 20 | #include "DS_Queue.h" 21 | #include "InternalPacket.h" 22 | 23 | namespace RakNet 24 | { 25 | /// open.mp's InternalPacketPool reimplementation 26 | /// Handles of a pool of InternalPacket pointers. This is only here for efficiency. 27 | /// \sa InternalPacket.h 28 | class InternalPacketPool 29 | { 30 | public: 31 | InternalPacket* GetPointer(); 32 | void ReleasePointer(InternalPacket* p); 33 | }; 34 | } 35 | 36 | #endif 37 | 38 | -------------------------------------------------------------------------------- /Include/raknet/MTUSize.h: -------------------------------------------------------------------------------- 1 | /// \file 2 | /// \brief \b [Internal] Defines the default maximum transfer unit. 3 | /// 4 | /// This file is part of RakNet Copyright 2003 Kevin Jenkins. 5 | /// 6 | /// Usage of RakNet is subject to the appropriate license agreement. 7 | /// Creative Commons Licensees are subject to the 8 | /// license found at 9 | /// http://creativecommons.org/licenses/by-nc/2.5/ 10 | /// Single application licensees are subject to the license found at 11 | /// http://www.rakkarsoft.com/SingleApplicationLicense.html 12 | /// Custom license users are subject to the terms therein. 13 | /// GPL license users are subject to the GNU General Public 14 | /// License as published by the Free 15 | /// Software Foundation; either version 2 of the License, or (at your 16 | /// option) any later version. 17 | 18 | #ifndef DEFAULT_MTU_SIZE 19 | 20 | /// The MTU size to use if RakPeer::SetMTUSize() is not called. 21 | /// \remarks I think many people forget to call RakPeer::SetMTUSize() so I'm setting this to 1500 by default for efficiency. 22 | /// \li \em 17914 16 Mbit/Sec Token Ring 23 | /// \li \em 4464 4 Mbits/Sec Token Ring 24 | /// \li \em 4352 FDDI 25 | /// \li \em 1500. The largest Ethernet packet size \b recommended. This is the typical setting for non-PPPoE, non-VPN connections. The default value for NETGEAR routers, adapters and switches. 26 | /// \li \em 1492. The size PPPoE prefers. 27 | /// \li \em 1472. Maximum size to use for pinging. (Bigger packets are fragmented.) 28 | /// \li \em 1468. The size DHCP prefers. 29 | /// \li \em 1460. Usable by AOL if you don't have large email attachments, etc. 30 | /// \li \em 1430. The size VPN and PPTP prefer. 31 | /// \li \em 1400. Maximum size for AOL DSL. 32 | /// \li \em 576. Typical value to connect to dial-up ISPs. 33 | #ifdef _COMPATIBILITY_1 34 | #define DEFAULT_MTU_SIZE 1264 35 | #else 36 | #define DEFAULT_MTU_SIZE 1500 37 | #endif 38 | 39 | /// The largest value for an UDP datagram 40 | /// \sa RakPeer::SetMTUSize() 41 | #define MAXIMUM_MTU_SIZE 1500 42 | 43 | #endif 44 | 45 | -------------------------------------------------------------------------------- /Include/raknet/NetworkIDGenerator.h: -------------------------------------------------------------------------------- 1 | /// \file 2 | /// \brief A class you can derive from to make it easier to represent every networked object with an integer. This way you can refer to objects over the network. 3 | /// 4 | /// This file is part of RakNet Copyright 2003 Kevin Jenkins. 5 | /// 6 | /// Usage of RakNet is subject to the appropriate license agreement. 7 | /// Creative Commons Licensees are subject to the 8 | /// license found at 9 | /// http://creativecommons.org/licenses/by-nc/2.5/ 10 | /// Single application licensees are subject to the license found at 11 | /// http://www.rakkarsoft.com/SingleApplicationLicense.html 12 | /// Custom license users are subject to the terms therein. 13 | /// GPL license users are subject to the GNU General Public 14 | /// License as published by the Free 15 | /// Software Foundation; either version 2 of the License, or (at your 16 | /// option) any later version. 17 | 18 | #if !defined(__NETWORK_ID_GENERATOR) 19 | #define __NETWORK_ID_GENERATOR 20 | 21 | #include "DS_BinarySearchTree.h" 22 | #include "NetworkTypes.h" 23 | #include "Export.h" 24 | 25 | namespace RakNet 26 | { 27 | class NetworkIDGenerator; 28 | 29 | /// \internal 30 | /// \brief A node in the AVL tree that holds the mapping between NetworkID and pointers. 31 | struct RAK_DLL_EXPORT NetworkIDNode 32 | { 33 | NetworkID networkID; 34 | NetworkIDGenerator *object; 35 | NetworkIDNode(); 36 | NetworkIDNode( NetworkID _networkID, NetworkIDGenerator *_object ); 37 | bool operator==( const NetworkIDNode& right ) const; 38 | bool operator > ( const NetworkIDNode& right ) const; 39 | bool operator < ( const NetworkIDNode& right ) const; 40 | }; 41 | 42 | /// \brief Unique shared ids for each object instance 43 | /// 44 | /// A class you can derive from to make it easier to represent every networked object with an integer. This way you can refer to objects over the network. 45 | /// One system should return true for IsNetworkIDAuthority() and the rest should return false. When an object needs to be created, have the the one system create the object. 46 | /// Then have that system send a message to all other systems, and include the value returned from GetNetworkID() in that packet. All other systems should then create the same 47 | /// class of object, and call SetNetworkID() on that class with the NetworkID in the packet. 48 | /// \see the manual for more information on this. 49 | class RAK_DLL_EXPORT NetworkIDGenerator 50 | { 51 | public: 52 | 53 | /// Constructor. NetworkIDs, if IsNetworkIDAuthority() is true, are created here. 54 | NetworkIDGenerator(); 55 | 56 | /// Destructor. Used NetworkIDs, if any, are freed here. 57 | virtual ~NetworkIDGenerator(); 58 | 59 | /// Returns the NetworkID that you can use to refer to this object over the network. 60 | /// \retval UNASSIGNED_NETWORK_ID UNASSIGNED_NETWORK_ID is returned IsNetworkIDAuthority() is false and SetNetworkID() was not previously called. This is also returned if you call this function in the constructor. 61 | /// \retval 0-65534 Any other value is a valid NetworkID. NetworkIDs start at 0 and go to 65534, wrapping at that point. 62 | virtual NetworkID GetNetworkID( void ); 63 | 64 | /// Sets the NetworkID for this instance. Usually this is called by the clients and determined from the servers. However, if you save multiplayer games you would likely use 65 | /// This on load as well. 66 | virtual void SetNetworkID( NetworkID id ); 67 | 68 | /// Your class does not have to derive from NetworkIDGenerator, although that is the easiest way to implement this. 69 | /// If you want this to be a member object of another class, rather than inherit, then call SetParent() with a pointer to the parent class instance. 70 | /// GET_OBJECT_FROM_ID will then return the parent rather than this instance. 71 | virtual void SetParent( void *_parent ); 72 | 73 | /// Return what was passed to SetParent 74 | /// \return The value passed to SetParent, or 0 if it was never called. 75 | virtual void* GetParent( void ) const; 76 | 77 | /// This AVL tree holds the pointer to NetworkID mappings 78 | static DataStructures::AVLBalancedBinarySearchTree IDTree; 79 | 80 | /// These function is only meant to be used when saving games as you 81 | /// should save the HIGHEST value staticItemID has achieved upon save 82 | /// and reload it upon load. Save AFTER you've created all the items 83 | /// derived from this class you are going to create. 84 | /// \return the HIGHEST Object Id currently used 85 | static unsigned short GetStaticNetworkID( void ); 86 | 87 | /// These function is only meant to be used when loading games. Load 88 | /// BEFORE you create any new objects that are not SetIDed based on 89 | /// the save data. 90 | /// \param[in] i the highest number of NetworkIDGenerator reached. 91 | static void SetStaticNetworkID( unsigned short i ); 92 | 93 | /// For every group of systems, one system needs to be responsible for creating unique IDs for all objects created on all systems. 94 | /// This way, systems can send that id in packets to refer to objects (you can't send pointers because the memory allocations may be different). 95 | /// In a client/server enviroment, the system that creates unique IDs would be the server. 96 | /// return true if this system is responsible for creating unique IDs (probably the server), return true. Otherwise return false. 97 | virtual bool IsNetworkIDAuthority(void) const=0; 98 | 99 | /// Necessary for peer to peer, as NetworkIDs are then composed of your external player Id (doesn't matter which, as long as unique) 100 | /// plus the usual object ID number. 101 | /// Get this from RakPeer::GetExternalPlayerID) one time, the first time you make a connection. 102 | /// \param[in] playerId Your external playerID 103 | static void SetExternalPlayerID(PlayerID playerId); 104 | static PlayerID GetExternalPlayerID(void); 105 | 106 | /// Overload this function and return true if you require that SetParent is called before this object is used. 107 | /// This is a safety check you should do this if you want this to be 108 | /// a member object of another class rather than derive from this class. 109 | virtual bool RequiresSetParent(void) const; 110 | 111 | /// If you use a parent, returns this instance rather than the parent object. 112 | static void* GET_BASE_OBJECT_FROM_ID( NetworkID x ); 113 | 114 | /// Returns the parent object, or this instance if you don't use a parent. 115 | static void* GET_OBJECT_FROM_ID( NetworkID x ); 116 | 117 | protected: 118 | 119 | /// The network ID of this object 120 | NetworkID networkID; 121 | 122 | /// The parent set by SetParent() 123 | void *parent; 124 | 125 | /// Internal function to generate an ID when needed. This is deferred until needed and is not called from the constructor. 126 | void GenerateID(void); 127 | 128 | /// This is crap but is necessary because virtual functions don't work in the constructor 129 | bool callGenerationCode; 130 | 131 | private: 132 | static PlayerID externalPlayerId; 133 | static unsigned short staticItemID; 134 | }; 135 | } 136 | 137 | #endif 138 | -------------------------------------------------------------------------------- /Include/raknet/PacketLogger.h: -------------------------------------------------------------------------------- 1 | /// \file 2 | /// \brief This will write all incoming and outgoing network messages to the local console screen. See derived functions for other outputs 3 | /// 4 | /// This file is part of RakNet Copyright 2003 Kevin Jenkins. 5 | /// 6 | /// Usage of RakNet is subject to the appropriate license agreement. 7 | /// Creative Commons Licensees are subject to the 8 | /// license found at 9 | /// http://creativecommons.org/licenses/by-nc/2.5/ 10 | /// Single application licensees are subject to the license found at 11 | /// http://www.rakkarsoft.com/SingleApplicationLicense.html 12 | /// Custom license users are subject to the terms therein. 13 | /// GPL license users are subject to the GNU General Public 14 | /// License as published by the Free 15 | /// Software Foundation; either version 2 of the License, or (at your 16 | /// option) any later version. 17 | 18 | #ifndef __PACKET_LOGGER_H 19 | #define __PACKET_LOGGER_H 20 | 21 | #include "NetworkTypes.h" 22 | #include "PluginInterface.h" 23 | #include "Export.h" 24 | 25 | namespace RakNet 26 | { 27 | class RakPeerInterface; 28 | 29 | /// \defgroup PACKETLOGGER_GROUP PacketLogger 30 | /// \ingroup PLUGINS_GROUP 31 | 32 | /// \brief Writes incoming and outgoing messages to the screen. 33 | /// This will write all incoming and outgoing messages to the console window, or to a file if you override it and give it this functionality. 34 | /// \ingroup PACKETLOGGER_GROUP 35 | class RAK_DLL_EXPORT PacketLogger : public PluginInterface 36 | { 37 | public: 38 | PacketLogger(); 39 | virtual ~PacketLogger(); 40 | 41 | virtual void OnAttach(RakPeerInterface *peer); 42 | 43 | /// Events on low level sends and receives. These functions may be called from different threads at the same time. 44 | virtual void OnDirectSocketSend(const char *data, const unsigned bitsUsed, PlayerID remoteSystemID); 45 | virtual void OnDirectSocketReceive(const char *data, const unsigned bitsUsed, PlayerID remoteSystemID); 46 | virtual void OnInternalPacket(InternalPacket *internalPacket, unsigned frameNumber, PlayerID remoteSystemID, RakNetTime time, bool isSend); 47 | 48 | /// Logs out a header for all the data 49 | virtual void LogHeader(void); 50 | 51 | /// Override this to log strings to wherever. Log should be threadsafe 52 | virtual void WriteLog(const char *str); 53 | 54 | // Set to true to print ID_* instead of numbers 55 | virtual void SetPrintID(bool print); 56 | // Print or hide acks (clears up the screen not to print them but is worse for debugging) 57 | virtual void SetPrintAcks(bool print); 58 | protected: 59 | char* IDTOString(unsigned char Id); 60 | char* BaseIDTOString(unsigned char Id); 61 | // Users should override this 62 | virtual char* UserIDTOString(unsigned char Id); 63 | 64 | RakPeerInterface *rakPeer; 65 | bool printId, printAcks; 66 | }; 67 | } 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /Include/raknet/PacketPriority.h: -------------------------------------------------------------------------------- 1 | /// \file 2 | /// \brief This file contains enumerations for packet priority and reliability enumerations. 3 | /// 4 | /// This file is part of RakNet Copyright 2003 Kevin Jenkins. 5 | /// 6 | /// Usage of RakNet is subject to the appropriate license agreement. 7 | /// Creative Commons Licensees are subject to the 8 | /// license found at 9 | /// http://creativecommons.org/licenses/by-nc/2.5/ 10 | /// Single application licensees are subject to the license found at 11 | /// http://www.rakkarsoft.com/SingleApplicationLicense.html 12 | /// Custom license users are subject to the terms therein. 13 | /// GPL license users are subject to the GNU General Public 14 | /// License as published by the Free 15 | /// Software Foundation; either version 2 of the License, or (at your 16 | /// option) any later version. 17 | 18 | #ifndef __PACKET_PRIORITY_H 19 | #define __PACKET_PRIORITY_H 20 | 21 | namespace RakNet 22 | { 23 | /// These enumerations are used to describe when packets are delivered. 24 | enum PacketPriority 25 | { 26 | SYSTEM_PRIORITY, /// \internal Used by RakNet to send above-high priority messages. 27 | HIGH_PRIORITY, /// High priority messages are send before medium priority messages. 28 | MEDIUM_PRIORITY, /// Medium priority messages are send before low priority messages. 29 | LOW_PRIORITY, /// Low priority messages are only sent when no other messages are waiting. 30 | NUMBER_OF_PRIORITIES 31 | }; 32 | 33 | /// These enumerations are used to describe how packets are delivered. 34 | /// \note Note to self: I write this with 3/4 bits in the stream. If I add more remember to change that 35 | enum PacketReliability 36 | { 37 | #if RAKNET_LEGACY 38 | UNRELIABLE = 6, /// SA:MP seems to like `+6` offsets. 39 | #else 40 | UNRELIABLE, /// Same as regular UDP, except that it will also discard duplicate datagrams. RakNet adds (6 to 17) + 21 bits of overhead, 16 of which is used to detect duplicate packets and 6 to 17 of which is used for message length. 41 | #endif 42 | UNRELIABLE_SEQUENCED, /// Regular UDP with a sequence counter. Out of order messages will be discarded. This adds an additional 13 bits on top what is used for UNRELIABLE. 43 | RELIABLE, /// The message is sent reliably, but not necessarily in any order. Same overhead as UNRELIABLE. 44 | RELIABLE_ORDERED, /// This message is reliable and will arrive in the order you sent it. Messages will be delayed while waiting for out of order messages. Same overhead as UNRELIABLE_SEQUENCED. 45 | RELIABLE_SEQUENCED /// This message is reliable and will arrive in the sequence you sent it. Out or order messages will be dropped. Same overhead as UNRELIABLE_SEQUENCED. 46 | }; 47 | } 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /Include/raknet/PluginInterface.h: -------------------------------------------------------------------------------- 1 | /// \file 2 | /// \brief \b RakNet's plugin functionality system. You can derive from this to create your own plugins. 3 | /// 4 | /// This file is part of RakNet Copyright 2003 Kevin Jenkins. 5 | /// 6 | /// Usage of RakNet is subject to the appropriate license agreement. 7 | /// Creative Commons Licensees are subject to the 8 | /// license found at 9 | /// http://creativecommons.org/licenses/by-nc/2.5/ 10 | /// Single application licensees are subject to the license found at 11 | /// http://www.rakkarsoft.com/SingleApplicationLicense.html 12 | /// Custom license users are subject to the terms therein. 13 | /// GPL license users are subject to the GNU General Public 14 | /// License as published by the Free 15 | /// Software Foundation; either version 2 of the License, or (at your 16 | /// option) any later version. 17 | 18 | #ifndef __PLUGIN_INTERFACE_H 19 | #define __PLUGIN_INTERFACE_H 20 | 21 | #include "NetworkTypes.h" 22 | #include "Export.h" 23 | 24 | namespace RakNet 25 | { 26 | class RakPeerInterface; 27 | struct Packet; 28 | struct InternalPacket; 29 | 30 | enum PluginReceiveResult 31 | { 32 | // The plugin used this message and it shouldn't be given to the user. 33 | RR_STOP_PROCESSING_AND_DEALLOCATE=0, 34 | 35 | // This message will be processed by other plugins, and at last by the user. 36 | RR_CONTINUE_PROCESSING, 37 | 38 | // The plugin is going to hold on to this message. Do not deallocate it but do not pass it to other plugins either. 39 | RR_STOP_PROCESSING, 40 | }; 41 | 42 | /// \defgroup PLUGINS_GROUP PluginInterface 43 | 44 | /// \brief PluginInterface provides a mechanism to add functionality in a modular way. 45 | /// MessageHandlers should derive from PluginInterface and be attached to RakPeer using the function AttachPlugin 46 | /// On a user call to Receive, OnReceive is called for every PluginInterface, which can then take action based on the message 47 | /// passed to it. This is used to transparently add game-independent functional modules, similar to browser plugins 48 | /// 49 | /// \sa ReplicaManager 50 | /// \sa FullyConnectedMesh 51 | /// \sa PacketLogger 52 | /// \ingroup PLUGINS_GROUP 53 | class RAK_DLL_EXPORT PluginInterface 54 | { 55 | public: 56 | /// Called when the interface is attached 57 | /// \param[in] peer the instance of RakPeer that is calling Receive 58 | virtual void OnAttach(RakPeerInterface *peer); 59 | 60 | /// Called when the interface is detached 61 | /// \param[in] peer the instance of RakPeer that is calling Receive 62 | virtual void OnDetach(RakPeerInterface *peer); 63 | 64 | /// Called when RakPeer is initialized 65 | /// \param[in] peer the instance of RakPeer that is calling Receive 66 | virtual void OnInitialize(RakPeerInterface *peer); 67 | 68 | /// Update is called every time a packet is checked for . 69 | /// \param[in] peer - the instance of RakPeer that is calling Receive 70 | virtual void Update(RakPeerInterface *peer); 71 | 72 | /// OnReceive is called for every packet. 73 | /// \param[in] peer the instance of RakPeer that is calling Receive 74 | /// \param[in] packet the packet that is being returned to the user 75 | /// \return True to allow the game and other plugins to get this message, false to absorb it 76 | virtual PluginReceiveResult OnReceive(RakPeerInterface *peer, Packet *packet); 77 | 78 | /// Called when RakPeer is shutdown 79 | /// \param[in] peer the instance of RakPeer that is calling Receive 80 | virtual void OnDisconnect(RakPeerInterface *peer); 81 | 82 | /// Called when a connection is dropped because the user called RakPeer::CloseConnection() for a particular system 83 | /// \param[in] peer the instance of RakPeer that is calling Receive 84 | /// \param[in] playerId The system whose connection was closed 85 | virtual void OnCloseConnection(RakPeerInterface *peer, PlayerID playerId); 86 | 87 | /// Called on a send to the socket, per datagram, that does not go through the reliability layer 88 | /// \param[in] data The data being sent 89 | /// \param[in] bitsUsed How many bits long \a data is 90 | /// \param[in] remoteSystemID Which system this message is being sent to 91 | virtual void OnDirectSocketSend(const char *data, const unsigned bitsUsed, PlayerID remoteSystemID); 92 | 93 | /// Called on a receive from the socket, per datagram, that does not go through the reliability layer 94 | /// \param[in] data The data being sent 95 | /// \param[in] bitsUsed How many bits long \a data is 96 | /// \param[in] remoteSystemID Which system this message is being sent to 97 | virtual void OnDirectSocketReceive(const char *data, const unsigned bitsUsed, PlayerID remoteSystemID); 98 | 99 | /// Called on a send or recieve within the reliability layer 100 | /// \param[in] internalPacket The user message, along with all send data. 101 | /// \param[in] frameNumber The number of frames sent or received so far for this player depending on \a isSend . Indicates the frame of this user message. 102 | /// \param[in] remoteSystemID The player we sent or got this packet from 103 | /// \param[in] time The current time as returned by RakNet::GetTime() 104 | /// \param[in] isSend Is this callback representing a send event or receive event? 105 | virtual void OnInternalPacket(InternalPacket *internalPacket, unsigned frameNumber, PlayerID remoteSystemID, RakNetTime time, bool isSend); 106 | }; 107 | } 108 | 109 | #endif 110 | 111 | -------------------------------------------------------------------------------- /Include/raknet/RPCMap.h: -------------------------------------------------------------------------------- 1 | /// \file 2 | /// \brief \b [Internal] A container class for a list of RPCNodes 3 | /// 4 | /// \ingroup RAKNET_RPC 5 | /// 6 | /// This file is part of RakNet Copyright 2003 Kevin Jenkins. 7 | /// 8 | /// Usage of RakNet is subject to the appropriate license agreement. 9 | /// Creative Commons Licensees are subject to the 10 | /// license found at 11 | /// http://creativecommons.org/licenses/by-nc/2.5/ 12 | /// Single application licensees are subject to the license found at 13 | /// http://www.rakkarsoft.com/SingleApplicationLicense.html 14 | /// Custom license users are subject to the terms therein. 15 | /// GPL license users are subject to the GNU General Public 16 | /// License as published by the Free 17 | /// Software Foundation; either version 2 of the License, or (at your 18 | /// option) any later version. 19 | 20 | #ifndef __RPC_MAP 21 | #define __RPC_MAP 22 | 23 | #include "RPCNode.h" 24 | #include "DS_List.h" 25 | #include "NetworkTypes.h" 26 | #include "Export.h" 27 | 28 | namespace RakNet 29 | { 30 | /// \ingroup RAKNET_RPC 31 | /// \internal 32 | /// \brief A container class for a list of RPCNodes 33 | struct RAK_DLL_EXPORT RPCMap 34 | { 35 | public: 36 | RPCMap(); 37 | ~RPCMap(); 38 | void Clear(void); 39 | RPCNode *GetNodeFromIndex(RPCIndex index); 40 | RPCNode *GetNodeFromFunctionName(RPCID uniqueIdentifier); 41 | RPCIndex GetIndexFromFunctionName(RPCID uniqueIdentifier); 42 | void AddIdentifierWithFunction(RPCID uniqueIdentifier, void *functionPointer, bool isPointerToMember, void *extraPointer); 43 | void AddIdentifierAtIndex(RPCID uniqueIdentifier, RPCIndex insertionIndex); 44 | void RemoveNode(RPCID uniqueIdentifier); 45 | protected: 46 | DataStructures::List rpcSet; 47 | }; 48 | } 49 | 50 | #endif 51 | 52 | -------------------------------------------------------------------------------- /Include/raknet/RPCNode.h: -------------------------------------------------------------------------------- 1 | /// \file 2 | /// \brief \b [Internal] Holds information related to a RPC 3 | /// 4 | /// \ingroup RAKNET_RPC 5 | /// 6 | /// This file is part of RakNet Copyright 2003 Kevin Jenkins. 7 | /// 8 | /// Usage of RakNet is subject to the appropriate license agreement. 9 | /// Creative Commons Licensees are subject to the 10 | /// license found at 11 | /// http://creativecommons.org/licenses/by-nc/2.5/ 12 | /// Single application licensees are subject to the license found at 13 | /// http://www.rakkarsoft.com/SingleApplicationLicense.html 14 | /// Custom license users are subject to the terms therein. 15 | /// GPL license users are subject to the GNU General Public 16 | /// License as published by the Free 17 | /// Software Foundation; either version 2 of the License, or (at your 18 | /// option) any later version. 19 | 20 | #ifndef __RPC_NODE 21 | #define __RPC_NODE 22 | 23 | #include "NetworkTypes.h" 24 | #include "Export.h" 25 | 26 | namespace RakNet 27 | { 28 | class RakPeerInterface; 29 | 30 | 31 | /// \defgroup RAKNET_RPC Remote Procedure Call Subsystem 32 | /// \brief A system to call C or object member procudures on other systems, and even to return return values. 33 | 34 | /// \ingroup RAKNET_RPC 35 | /// \internal 36 | /// 37 | /// \brief Map registered procedure inside of a peer. 38 | /// 39 | struct RAK_DLL_EXPORT RPCNode 40 | { 41 | 42 | /// String identifier of the RPC 43 | RPCID uniqueIdentifier; 44 | 45 | /// Force casting of member functions to void * 46 | union 47 | { 48 | void ( *staticFunctionPointer ) ( RPCParameters *rpcParms, void* extra ); 49 | #if (defined(__GNUC__) || defined(__GCCXML__)) 50 | void (*memberFunctionPointer)(void* _this, RPCParameters *rpcParms, void* extra); 51 | #else 52 | void (__cdecl *memberFunctionPointer)(void* _this, RPCParameters *rpcParms); 53 | #endif 54 | 55 | void *functionPointer; 56 | }; 57 | 58 | /// Is this a member function pointer? True if so. If false it's a regular C function. 59 | bool isPointerToMember; 60 | 61 | void* extraPointer; 62 | }; 63 | } 64 | 65 | #endif 66 | 67 | -------------------------------------------------------------------------------- /Include/raknet/RakAssert.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // So stupid Linux doesn't assert in release 4 | #ifdef _DEBUG 5 | #define RakAssert(x) assert(x); 6 | #else 7 | #define RakAssert(x) 8 | #endif 9 | -------------------------------------------------------------------------------- /Include/raknet/RakNetCommandParser.h: -------------------------------------------------------------------------------- 1 | /// \file 2 | /// \brief Contains RakNetCommandParser , used to send commands to an instance of RakPeer 3 | /// 4 | /// This file is part of RakNet Copyright 2003 Kevin Jenkins. 5 | /// 6 | /// Usage of RakNet is subject to the appropriate license agreement. 7 | /// Creative Commons Licensees are subject to the 8 | /// license found at 9 | /// http://creativecommons.org/licenses/by-nc/2.5/ 10 | /// Single application licensees are subject to the license found at 11 | /// http://www.rakkarsoft.com/SingleApplicationLicense.html 12 | /// Custom license users are subject to the terms therein. 13 | /// GPL license users are subject to the GNU General Public 14 | /// License as published by the Free 15 | /// Software Foundation; either version 2 of the License, or (at your 16 | /// option) any later version. 17 | 18 | #ifndef __RAKNET_COMMAND_PARSER 19 | #define __RAKNET_COMMAND_PARSER 20 | 21 | #include "CommandParserInterface.h" 22 | #include "Export.h" 23 | 24 | namespace RakNet 25 | { 26 | class RakPeerInterface; 27 | 28 | /// \brief This allows a console client to call most of the functions in RakPeer 29 | class RAK_DLL_EXPORT RakNetCommandParser : public CommandParserInterface 30 | { 31 | public: 32 | RakNetCommandParser(); 33 | ~RakNetCommandParser(); 34 | 35 | /// Given \a command with parameters \a parameterList , do whatever processing you wish. 36 | /// \param[in] command The command to process 37 | /// \param[in] numParameters How many parameters were passed along with the command 38 | /// \param[in] parameterList The list of parameters. parameterList[0] is the first parameter and so on. 39 | /// \param[in] transport The transport interface we can use to write to 40 | /// \param[in] playerId The player that sent this command. 41 | /// \param[in] originalString The string that was actually sent over the network, in case you want to do your own parsing 42 | bool OnCommand(const char *command, unsigned numParameters, char **parameterList, TransportInterface *transport, PlayerID playerId, const char *originalString); 43 | 44 | /// You are responsible for overriding this function and returning a static string, which will identifier your parser. 45 | /// This should return a static string 46 | /// \return The name that you return. 47 | char *GetName(void) const; 48 | 49 | /// A callback for when you are expected to send a brief description of your parser to \a playerId 50 | /// \param[in] transport The transport interface we can use to write to 51 | /// \param[in] playerId The player that requested help. 52 | void SendHelp(TransportInterface *transport, PlayerID playerId); 53 | 54 | /// Records the instance of RakPeer to perform the desired commands on 55 | /// \param[in] rakPeer The RakPeer instance, or a derived class (e.g. RakServer or RakClient) 56 | void SetRakPeerInterface(RakPeerInterface *rakPeer); 57 | protected: 58 | 59 | /// Which instance of RakPeer we are working on. Set from SetRakPeerInterface() 60 | RakPeerInterface *peer; 61 | }; 62 | } 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /Include/raknet/RakNetDefines.h: -------------------------------------------------------------------------------- 1 | /// Define __GET_TIME_64BIT to have RakNetTime use a 64, rather than 32 bit value. A 32 bit value will overflow after about 5 weeks. 2 | /// However, this doubles the bandwidth use for sending times, so don't do it unless you have a reason to. 3 | /// Disabled by default. 4 | // #define __GET_TIME_64BIT 5 | 6 | /// Makes RakNet threadsafe 7 | /// Define this if you use the same instance of RakPeer from multiple threads 8 | /// Otherwise leave it undefined, since it makes things an order of magnitude slower. 9 | /// Disabled by default 10 | // #define _RAKNET_THREADSAFE 11 | 12 | /// Can interrupt a Sleep() if a message is incoming. Useful to define if you pass a large sleep value to RakPeer::Initialize 13 | // #define USE_WAIT_FOR_MULTIPLE_EVENTS 14 | 15 | /// Define __BITSTREAM_NATIVE_END to NOT support endian swapping in the BitStream class. This is faster and is what you should use 16 | /// unless you actually plan to have different endianness systems connect to each other 17 | /// Enabled by default. 18 | //#define __BITSTREAM_NATIVE_END 19 | 20 | /// Maximum (stack) size to use with _alloca before using new and delete instead. 21 | #define MAX_ALLOCA_STACK_ALLOCATION 1048576 22 | -------------------------------------------------------------------------------- /Include/raknet/RakNetStatistics.h: -------------------------------------------------------------------------------- 1 | /// \file 2 | /// \brief A structure that holds all statistical data returned by RakNet. 3 | /// 4 | /// This file is part of RakNet Copyright 2003 Kevin Jenkins. 5 | /// 6 | /// Usage of RakNet is subject to the appropriate license agreement. 7 | /// Creative Commons Licensees are subject to the 8 | /// license found at 9 | /// http://creativecommons.org/licenses/by-nc/2.5/ 10 | /// Single application licensees are subject to the license found at 11 | /// http://www.rakkarsoft.com/SingleApplicationLicense.html 12 | /// Custom license users are subject to the terms therein. 13 | /// GPL license users are subject to the GNU General Public 14 | /// License as published by the Free 15 | /// Software Foundation; either version 2 of the License, or (at your 16 | /// option) any later version. 17 | 18 | 19 | #ifndef __RAK_NET_STATISTICS_H 20 | #define __RAK_NET_STATISTICS_H 21 | 22 | #include "PacketPriority.h" 23 | #include "Export.h" 24 | #include "NetworkTypes.h" 25 | 26 | namespace RakNet 27 | { 28 | /// \brief Network Statisics Usage 29 | /// 30 | /// Store Statistics information related to network usage 31 | struct RAK_DLL_EXPORT RakNetStatisticsStruct 32 | { 33 | /// Number of Messages in the send Buffer (high, medium, low priority) 34 | unsigned messageSendBuffer[ NUMBER_OF_PRIORITIES ]; 35 | /// Number of messages sent (high, medium, low priority) 36 | unsigned messagesSent[ NUMBER_OF_PRIORITIES ]; 37 | /// Number of data bits used for user messages 38 | unsigned messageDataBitsSent[ NUMBER_OF_PRIORITIES ]; 39 | /// Number of total bits used for user messages, including headers 40 | unsigned messageTotalBitsSent[ NUMBER_OF_PRIORITIES ]; 41 | 42 | /// Number of packets sent containing only acknowledgements 43 | unsigned packetsContainingOnlyAcknowlegements; 44 | /// Number of acknowledgements sent 45 | unsigned acknowlegementsSent; 46 | /// Number of acknowledgements waiting to be sent 47 | unsigned acknowlegementsPending; 48 | /// Number of acknowledgements bits sent 49 | unsigned acknowlegementBitsSent; 50 | 51 | /// Number of packets containing only acknowledgements and resends 52 | unsigned packetsContainingOnlyAcknowlegementsAndResends; 53 | 54 | /// Number of messages resent 55 | unsigned messageResends; 56 | /// Number of bits resent of actual data 57 | unsigned messageDataBitsResent; 58 | /// Total number of bits resent, including headers 59 | unsigned long long messagesTotalBitsResent; 60 | /// Number of messages waiting for ack (// TODO - rename this) 61 | unsigned messagesOnResendQueue; 62 | 63 | /// Number of messages not split for sending 64 | unsigned numberOfUnsplitMessages; 65 | /// Number of messages split for sending 66 | unsigned numberOfSplitMessages; 67 | /// Total number of splits done for sending 68 | unsigned totalSplits; 69 | 70 | /// Total packets sent 71 | unsigned packetsSent; 72 | 73 | /// Number of bits added by encryption 74 | unsigned encryptionBitsSent; 75 | /// total bits sent 76 | unsigned long long totalBitsSent; 77 | 78 | /// Number of sequenced messages arrived out of order 79 | unsigned sequencedMessagesOutOfOrder; 80 | /// Number of sequenced messages arrived in order 81 | unsigned sequencedMessagesInOrder; 82 | 83 | /// Number of ordered messages arrived out of order 84 | unsigned orderedMessagesOutOfOrder; 85 | /// Number of ordered messages arrived in order 86 | unsigned orderedMessagesInOrder; 87 | 88 | /// Packets with a good CRC received 89 | unsigned packetsReceived; 90 | /// Packets with a bad CRC received 91 | unsigned packetsWithBadCRCReceived; 92 | /// Bits with a good CRC received 93 | unsigned bitsReceived; 94 | /// Bits with a bad CRC received 95 | unsigned bitsWithBadCRCReceived; 96 | /// Number of acknowledgement messages received for packets we are resending 97 | unsigned acknowlegementsReceived; 98 | /// Number of acknowledgement messages received for packets we are not resending 99 | unsigned duplicateAcknowlegementsReceived; 100 | /// Number of data messages (anything other than an ack) received that are valid and not duplicate 101 | unsigned messagesReceived; 102 | /// Number of data messages (anything other than an ack) received that are invalid 103 | unsigned invalidMessagesReceived; 104 | /// Number of data messages (anything other than an ack) received that are duplicate 105 | unsigned duplicateMessagesReceived; 106 | /// Number of messages received in one second 107 | unsigned perSecondReceivedMsgCount; 108 | /// Number of messages waiting for reassembly 109 | unsigned messagesWaitingForReassembly; 110 | /// Number of messages in reliability output queue 111 | unsigned internalOutputQueueSize; 112 | /// Current bits per second 113 | double bitsPerSecond; 114 | /// connection start time 115 | RakNetTime connectionStartTime; 116 | /// Last time raknet stored per second received messages 117 | RakNetTimeNS lastRecvMsgProcess; 118 | 119 | /// Used for messages_limit config option in open.mp 120 | RakNetTimeNS perFrameMessagesLimitCheckLastTick; 121 | unsigned int perFrameMessagesLimitCounter; 122 | unsigned int perSecondMessagesLimitCounter; 123 | 124 | /// Used for acks_limit config option in open.mp 125 | RakNetTimeNS perFrameAcksLimitCheckLastTick; 126 | unsigned int perFrameAcksLimitCounter; 127 | unsigned int perSecondAcksLimitCounter; 128 | 129 | RakNetStatisticsStruct operator +=(const RakNetStatisticsStruct& other) 130 | { 131 | unsigned i; 132 | for (i=0; i < NUMBER_OF_PRIORITIES; i++) 133 | { 134 | messageSendBuffer[i]+=other.messageSendBuffer[i]; 135 | messagesSent[i]+=other.messagesSent[i]; 136 | messageDataBitsSent[i]+=other.messageDataBitsSent[i]; 137 | messageTotalBitsSent[i]+=other.messageTotalBitsSent[i]; 138 | } 139 | 140 | packetsContainingOnlyAcknowlegements+=other.packetsContainingOnlyAcknowlegements; 141 | acknowlegementsSent+=other.packetsContainingOnlyAcknowlegements; 142 | acknowlegementsPending+=other.acknowlegementsPending; 143 | acknowlegementBitsSent+=other.acknowlegementBitsSent; 144 | packetsContainingOnlyAcknowlegementsAndResends+=other.packetsContainingOnlyAcknowlegementsAndResends; 145 | messageResends+=other.messageResends; 146 | messageDataBitsResent+=other.messageDataBitsResent; 147 | messagesTotalBitsResent+=other.messagesTotalBitsResent; 148 | messagesOnResendQueue+=other.messagesOnResendQueue; 149 | numberOfUnsplitMessages+=other.numberOfUnsplitMessages; 150 | numberOfSplitMessages+=other.numberOfSplitMessages; 151 | totalSplits+=other.totalSplits; 152 | packetsSent+=other.packetsSent; 153 | encryptionBitsSent+=other.encryptionBitsSent; 154 | totalBitsSent+=other.totalBitsSent; 155 | sequencedMessagesOutOfOrder+=other.sequencedMessagesOutOfOrder; 156 | sequencedMessagesInOrder+=other.sequencedMessagesInOrder; 157 | orderedMessagesOutOfOrder+=other.orderedMessagesOutOfOrder; 158 | orderedMessagesInOrder+=other.orderedMessagesInOrder; 159 | packetsReceived+=other.packetsReceived; 160 | packetsWithBadCRCReceived+=other.packetsWithBadCRCReceived; 161 | bitsReceived+=other.bitsReceived; 162 | bitsWithBadCRCReceived+=other.bitsWithBadCRCReceived; 163 | acknowlegementsReceived+=other.acknowlegementsReceived; 164 | duplicateAcknowlegementsReceived+=other.duplicateAcknowlegementsReceived; 165 | messagesReceived+=other.messagesReceived; 166 | invalidMessagesReceived+=other.invalidMessagesReceived; 167 | duplicateMessagesReceived+=other.duplicateMessagesReceived; 168 | messagesWaitingForReassembly+=other.messagesWaitingForReassembly; 169 | internalOutputQueueSize+=other.internalOutputQueueSize; 170 | 171 | return *this; 172 | } 173 | }; 174 | 175 | /// Verbosity level currently supports 0 (low), 1 (medium), 2 (high) 176 | /// \param[in] s The Statistical information to format out 177 | /// \param[in] buffer The buffer containing a formated report 178 | /// \param[in] verbosityLevel 179 | /// 0 low 180 | /// 1 medium 181 | /// 2 high 182 | void StatisticsToString( RakNetStatisticsStruct *s, char *buffer, int verbosityLevel ); 183 | } 184 | 185 | #endif 186 | -------------------------------------------------------------------------------- /Include/raknet/RakNetTransport.h: -------------------------------------------------------------------------------- 1 | /// \file 2 | /// \brief Contains RakNetTransportCommandParser and RakNetTransport used to provide a secure console connection. 3 | /// 4 | /// This file is part of RakNet Copyright 2003 Kevin Jenkins. 5 | /// 6 | /// Usage of RakNet is subject to the appropriate license agreement. 7 | /// Creative Commons Licensees are subject to the 8 | /// license found at 9 | /// http://creativecommons.org/licenses/by-nc/2.5/ 10 | /// Single application licensees are subject to the license found at 11 | /// http://www.rakkarsoft.com/SingleApplicationLicense.html 12 | /// Custom license users are subject to the terms therein. 13 | /// GPL license users are subject to the GNU General Public 14 | /// License as published by the Free 15 | /// Software Foundation; either version 2 of the License, or (at your 16 | /// option) any later version. 17 | 18 | #ifndef __RAKNET_TRANSPORT 19 | #define __RAKNET_TRANSPORT 20 | 21 | #include "TransportInterface.h" 22 | #include "DS_Queue.h" 23 | #include "CommandParserInterface.h" 24 | #include "Export.h" 25 | 26 | namespace RakNet 27 | { 28 | class RakPeerInterface; 29 | class RakNetTransport; 30 | class BitStream; 31 | 32 | /// \brief RakNetTransport has its own command parser to enable remote users to change the command console's password. 33 | class RAK_DLL_EXPORT RakNetTransportCommandParser : public CommandParserInterface 34 | { 35 | public: 36 | RakNetTransportCommandParser(); 37 | ~RakNetTransportCommandParser(); 38 | 39 | /// Given \a command with parameters \a parameterList , do whatever processing you wish. 40 | /// \param[in] command The command to process 41 | /// \param[in] numParameters How many parameters were passed along with the command 42 | /// \param[in] parameterList The list of parameters. parameterList[0] is the first parameter and so on. 43 | /// \param[in] transport The transport interface we can use to write to 44 | /// \param[in] playerId The player that sent this command. 45 | /// \param[in] originalString The string that was actually sent over the network, in case you want to do your own parsing 46 | bool OnCommand(const char *command, unsigned numParameters, char **parameterList, TransportInterface *transport, PlayerID playerId, const char *originalString); 47 | 48 | /// You are responsible for overriding this function and returning a static string, which will identifier your parser. 49 | /// This should return a static string 50 | /// \return The name that you return. 51 | char* GetName(void) const; 52 | 53 | /// A callback for when you are expected to send a brief description of your parser to \a playerId 54 | /// \param[in] transport The transport interface we can use to write to 55 | /// \param[in] playerId The player that requested help. 56 | void SendHelp(TransportInterface *transport, PlayerID playerId); 57 | protected: 58 | }; 59 | 60 | /// \brief Use RakNetTransport if you need a secure connection between the client and the console server. 61 | /// RakNetTransport automatically initializes security for the system. Use the project CommandConsoleClient to connect 62 | /// To the ConsoleServer if you use RakNetTransport 63 | class RAK_DLL_EXPORT RakNetTransport : public TransportInterface 64 | { 65 | public: 66 | RakNetTransport(); 67 | ~RakNetTransport(); 68 | 69 | /// Start the transport provider on the indicated port. 70 | /// \param[in] port The port to start the transport provider on 71 | /// \param[in] serverMode If true, you should allow incoming connections (I don't actually use this anywhere) 72 | /// \return Return true on success, false on failure. 73 | bool Start(unsigned short port, bool serverMode); 74 | 75 | /// Stop the transport provider. You can clear memory and shutdown threads here. 76 | void Stop(void); 77 | 78 | /// Send a null-terminated string to \a playerId 79 | /// If your transport method requires particular formatting of the outgoing data (e.g. you don't just send strings) you can do it here 80 | /// and parse it out in Receive(). 81 | /// \param[in] playerId The player to send the string to 82 | /// \param[in] data format specifier - same as printf 83 | /// \param[in] ... format specification arguments - same as printf 84 | void Send( PlayerID playerId, const char *data, ... ); 85 | 86 | /// Return a string. The string should be allocated and written to Packet::data . 87 | /// The byte length should be written to Packet::length . The player/address should be written to Packet::playerid 88 | /// If your transport protocol adds special formatting to the data stream you should parse it out before returning it in the packet 89 | /// and thus only return a string in Packet::data 90 | /// \return The packet structure containing the result of Receive, or 0 if no data is available 91 | Packet* Receive( void ); 92 | 93 | /// Deallocate the Packet structure returned by Receive 94 | /// \param[in] The packet to deallocate 95 | void DeallocatePacket( Packet *packet ); 96 | 97 | /// Disconnect \a playerId . The binary address and port defines the PlayerID structure. 98 | /// \param[in] playerId The player/address to disconnect 99 | void CloseConnection( PlayerID playerId ); 100 | 101 | /// If a new system connects to you, you should queue that event and return the playerId/address of that player in this function. 102 | /// \return The PlayerID/address of the system 103 | PlayerID HasNewConnection(void); 104 | 105 | /// If a system loses the connection, you should queue that event and return the playerId/address of that player in this function. 106 | /// \return The PlayerID/address of the system 107 | PlayerID HasLostConnection(void); 108 | 109 | /// Sets the password which incoming connections must match. 110 | /// While not required, it is highly recommended you set this in a real game environment or anyone can login and control your server. 111 | /// Don't set it to a fixed value, but instead require that the server admin sets it when you start the application server 112 | /// \param[in] password Null-terminated string to use as a password. 113 | void SetIncomingPassword(const char *password); 114 | 115 | /// Returns the password set by SetIncomingPassword(). 116 | /// \return The password set by SetIncomingPassword() 117 | char * GetIncomingPassword(void); 118 | 119 | /// Returns RakNetTransportCommandParser so the console admin can change the password 120 | CommandParserInterface* GetCommandParser(void); 121 | 122 | protected: 123 | RakPeerInterface *rakPeer; 124 | void AutoAllocate(void); 125 | DataStructures::Queue newConnections, lostConnections; 126 | RakNetTransportCommandParser rakNetTransportCommandParser; 127 | }; 128 | } 129 | 130 | #endif 131 | -------------------------------------------------------------------------------- /Include/raknet/RakNetworkFactory.h: -------------------------------------------------------------------------------- 1 | /// \file 2 | /// \brief Factory class for RakServerInterface, RakClientInterface, and RakPeerInterface 3 | /// 4 | /// This file is part of RakNet Copyright 2003 Kevin Jenkins. 5 | /// 6 | /// Usage of RakNet is subject to the appropriate license agreement. 7 | /// Creative Commons Licensees are subject to the 8 | /// license found at 9 | /// http://creativecommons.org/licenses/by-nc/2.5/ 10 | /// Single application licensees are subject to the license found at 11 | /// http://www.rakkarsoft.com/SingleApplicationLicense.html 12 | /// Custom license users are subject to the terms therein. 13 | /// GPL license users are subject to the GNU General Public 14 | /// License as published by the Free 15 | /// Software Foundation; either version 2 of the License, or (at your 16 | /// option) any later version. 17 | 18 | #ifndef __RAK_NETWORK_FACTORY_H 19 | #define __RAK_NETWORK_FACTORY_H 20 | 21 | #include "Export.h" 22 | 23 | namespace RakNet 24 | { 25 | class RakClientInterface; 26 | class RakServerInterface; 27 | class RakPeerInterface; 28 | class ConsoleServer; 29 | //class ReplicaManager; 30 | //class LogCommandParser; 31 | //class PacketLogger; 32 | class RakNetCommandParser; 33 | //class RakNetTransport; 34 | //class TelnetTransport; 35 | //class PacketConsoleLogger; 36 | //class PacketFileLogger; 37 | //class Router; 38 | //class ConnectionGraph; 39 | 40 | class RAK_DLL_EXPORT RakNetworkFactory 41 | { 42 | public: 43 | // For DLL's, these are user classes that you might want to new and delete. 44 | // You can't instantiate exported classes directly in your program. The instantiation 45 | // has to take place inside the DLL. So these functions will do the news and deletes for you. 46 | // if you're using the source or static library you don't need these functions, but can use them if you want. 47 | static RakClientInterface* GetRakClientInterface( void ); 48 | static RakServerInterface* GetRakServerInterface( void ); 49 | static RakPeerInterface* GetRakPeerInterface( void ); 50 | static ConsoleServer* GetConsoleServer( void ); 51 | //static ReplicaManager* GetReplicaManager( void ); 52 | //static LogCommandParser* GetLogCommandParser( void ); 53 | //static PacketLogger* GetPacketLogger( void ); 54 | static RakNetCommandParser* GetRakNetCommandParser( void ); 55 | //static RakNetTransport* GetRakNetTransport( void ); 56 | //static TelnetTransport* GetTelnetTransport( void ); 57 | //static PacketConsoleLogger* GetPacketConsoleLogger( void ); 58 | //static PacketFileLogger* GetPacketFileLogger( void ); 59 | //static Router* GetRouter( void ); 60 | //static ConnectionGraph* GetConnectionGraph( void ); 61 | 62 | // To delete the object returned by the Get functions above. 63 | static void DestroyRakClientInterface( RakClientInterface* i ); 64 | static void DestroyRakServerInterface( RakServerInterface* i ); 65 | static void DestroyRakPeerInterface( RakPeerInterface* i ); 66 | static void DestroyConsoleServer( ConsoleServer* i); 67 | //static void DestroyReplicaManager( ReplicaManager* i); 68 | //static void DestroyLogCommandParser( LogCommandParser* i); 69 | //static void DestroyPacketLogger( PacketLogger* i); 70 | static void DestroyRakNetCommandParser( RakNetCommandParser* i ); 71 | //static void DestroyRakNetTransport( RakNetTransport* i ); 72 | //static void DestroyTelnetTransport( TelnetTransport* i ); 73 | //static void DestroyPacketConsoleLogger( PacketConsoleLogger* i ); 74 | //static void DestroyPacketFileLogger( PacketFileLogger* i ); 75 | //static void DestroyRouter( Router* i ); 76 | //static void DestroyConnectionGraph( ConnectionGraph* i ); 77 | }; 78 | } 79 | 80 | #endif 81 | -------------------------------------------------------------------------------- /Include/raknet/RakSleep.h: -------------------------------------------------------------------------------- 1 | #ifndef __RAK_SLEEP_H 2 | #define __RAK_SLEEP_H 3 | 4 | namespace RakNet 5 | { 6 | void RakSleep(unsigned int ms); 7 | } 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /Include/raknet/Rand.h: -------------------------------------------------------------------------------- 1 | /// \file 2 | /// \brief \b [Internal] Random number generator 3 | /// 4 | /// This file is part of RakNet Copyright 2003 Kevin Jenkins. 5 | /// 6 | /// Usage of RakNet is subject to the appropriate license agreement. 7 | /// Creative Commons Licensees are subject to the 8 | /// license found at 9 | /// http://creativecommons.org/licenses/by-nc/2.5/ 10 | /// Single application licensees are subject to the license found at 11 | /// http://www.rakkarsoft.com/SingleApplicationLicense.html 12 | /// Custom license users are subject to the terms therein. 13 | /// GPL license users are subject to the GNU General Public 14 | /// License as published by the Free 15 | /// Software Foundation; either version 2 of the License, or (at your 16 | /// option) any later version. 17 | 18 | 19 | #ifndef __RAND_H 20 | #define __RAND_H 21 | 22 | #include "Export.h" 23 | 24 | namespace RakNet 25 | { 26 | /// Initialise seed for Random Generator 27 | /// \param[in] seed The seed value for the random number generator. 28 | extern void RAK_DLL_EXPORT seedMT( unsigned int seed ); 29 | 30 | /// \internal 31 | extern unsigned int RAK_DLL_EXPORT reloadMT( void ); 32 | 33 | /// Gets a random unsigned int 34 | /// \return an integer random value. 35 | extern unsigned int RAK_DLL_EXPORT randomMT( void ); 36 | 37 | /// Gets a random float 38 | /// \return 0 to 1.0f, inclusive 39 | extern float RAK_DLL_EXPORT frandomMT( void ); 40 | } 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /Include/raknet/ReplicaEnums.h: -------------------------------------------------------------------------------- 1 | /// \file 2 | /// \brief Contains enumerations used by the ReplicaManager system. This file is a lightweight header, so you can include it without worrying about linking in lots of other crap 3 | /// 4 | /// This file is part of RakNet Copyright 2003 Kevin Jenkins. 5 | /// 6 | /// Usage of RakNet is subject to the appropriate license agreement. 7 | /// Creative Commons Licensees are subject to the 8 | /// license found at 9 | /// http://creativecommons.org/licenses/by-nc/2.5/ 10 | /// Single application licensees are subject to the license found at 11 | /// http://www.rakkarsoft.com/SingleApplicationLicense.html 12 | /// Custom license users are subject to the terms therein. 13 | /// GPL license users are subject to the GNU General Public 14 | /// License as published by the Free 15 | /// Software Foundation; either version 2 of the License, or (at your 16 | /// option) any later version. 17 | 18 | #ifndef __REPLICA_ENUMS_H 19 | #define __REPLICA_ENUMS_H 20 | 21 | namespace RakNet 22 | { 23 | /// Replica interface flags, used to enable and disable function calls on the Replica object 24 | /// Passed to ReplicaManager::EnableReplicaInterfaces and ReplicaManager::DisableReplicaInterfaces 25 | enum 26 | { 27 | REPLICA_RECEIVE_DESTRUCTION=1<<0, 28 | REPLICA_RECEIVE_SERIALIZE=1<<1, 29 | REPLICA_RECEIVE_SCOPE_CHANGE=1<<2, 30 | REPLICA_SEND_CONSTRUCTION=1<<3, 31 | REPLICA_SEND_DESTRUCTION=1<<4, 32 | REPLICA_SEND_SCOPE_CHANGE=1<<5, 33 | REPLICA_SEND_SERIALIZE=1<<6, 34 | REPLICA_SET_ALL = 0xFF // Allow all of the above 35 | }; 36 | 37 | enum ReplicaReturnResult 38 | { 39 | /// This means call the function again later, with the same parameters 40 | REPLICA_PROCESS_LATER, 41 | /// This means we are done processing (the normal result to return) 42 | REPLICA_PROCESSING_DONE, 43 | /// This means cancel the processing - don't send any network messages and don't change the current state. 44 | REPLICA_CANCEL_PROCESS, 45 | /// Same as REPLICA_PROCESSING_DONE, where a message is sent, but does not clear the send bit. 46 | /// Useful for multi-part sends with different reliability levels. 47 | /// Only currently used by Replica::Serialize 48 | REPLICA_PROCESS_AGAIN, 49 | }; 50 | } 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /Include/raknet/RouterInterface.h: -------------------------------------------------------------------------------- 1 | #ifndef __ROUTER_INTERFACE_H 2 | #define __ROUTER_INTERFACE_H 3 | 4 | #include "Export.h" 5 | 6 | namespace RakNet 7 | { 8 | /// On failed directed sends, RakNet can call an alternative send function to use. 9 | class RAK_DLL_EXPORT RouterInterface 10 | { 11 | public: 12 | virtual bool Send( const char *data, unsigned bitLength, PacketPriority priority, PacketReliability reliability, char orderingChannel, PlayerID playerId )=0; 13 | }; 14 | } 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /Include/raknet/SHA1.h: -------------------------------------------------------------------------------- 1 | /// \brief \b [Internal] SHA-1 computation class 2 | /// 3 | /// 100% free public domain implementation of the SHA-1 4 | /// algorithm by Dominik Reichl 5 | /// 6 | /// 7 | /// === Test Vectors (from FIPS PUB 180-1) === 8 | /// 9 | /// "abc" 10 | /// A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D 11 | /// 12 | /// "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" 13 | /// 84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1 14 | /// 15 | /// A million repetitions of "a" 16 | /// 34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F 17 | 18 | #ifndef ___SHA1_H___ 19 | #define ___SHA1_H___ 20 | 21 | #include // Needed for file access 22 | #include // Needed for memset and memcpy 23 | #include // Needed for strcat and strcpy 24 | #include "Types.h" 25 | #include "Export.h" 26 | 27 | #define MAX_FILE_READ_BUFFER 8000 28 | 29 | #define SHA1_LENGTH 20 30 | 31 | namespace RakNet 32 | { 33 | class RAK_DLL_EXPORT CSHA1 34 | { 35 | 36 | public: 37 | // Rotate x bits to the left 38 | // #define ROL32(value, bits) (((value)<<(bits))|((value)>>(32-(bits)))) 39 | 40 | #ifdef LITTLE_ENDIAN 41 | #define SHABLK0(i) (block->l[i] = (ROL32(block->l[i],24) & 0xFF00FF00) \ 42 | | (ROL32(block->l[i],8) & 0x00FF00FF)) 43 | #else 44 | #define SHABLK0(i) (block->l[i]) 45 | #endif 46 | 47 | #define SHABLK(i) (block->l[i&15] = ROL32(block->l[(i+13)&15] ^ block->l[(i+8)&15] \ 48 | ^ block->l[(i+2)&15] ^ block->l[i&15],1)) 49 | 50 | // SHA-1 rounds 51 | #define R0(v,w,x,y,z,i) { z+=((w&(x^y))^y)+SHABLK0(i)+0x5A827999+ROL32(v,5); w=ROL32(w,30); } 52 | #define R1(v,w,x,y,z,i) { z+=((w&(x^y))^y)+SHABLK(i)+0x5A827999+ROL32(v,5); w=ROL32(w,30); } 53 | #define R2(v,w,x,y,z,i) { z+=(w^x^y)+SHABLK(i)+0x6ED9EBA1+ROL32(v,5); w=ROL32(w,30); } 54 | #define R3(v,w,x,y,z,i) { z+=(((w|x)&y)|(w&x))+SHABLK(i)+0x8F1BBCDC+ROL32(v,5); w=ROL32(w,30); } 55 | #define R4(v,w,x,y,z,i) { z+=(w^x^y)+SHABLK(i)+0xCA62C1D6+ROL32(v,5); w=ROL32(w,30); } 56 | 57 | typedef union { 58 | unsigned char c[ 64 ]; 59 | unsigned int l[ 16 ]; 60 | } SHA1_WORKSPACE_BLOCK; 61 | /* Two different formats for ReportHash(...) 62 | */ 63 | enum { REPORT_HEX = 0, 64 | REPORT_DIGIT = 1}; 65 | 66 | CSHA1(); 67 | virtual ~CSHA1(); 68 | 69 | unsigned int m_state[ 5 ]; 70 | unsigned int m_count[ 2 ]; 71 | unsigned char m_buffer[ 64 ]; 72 | unsigned char m_digest[ 20 ]; 73 | void Reset(); 74 | void Update( unsigned char* data, unsigned int len ); 75 | bool HashFile( char *szFileName ); 76 | void Final(); 77 | void ReportHash( char *szReport, unsigned char uReportType = REPORT_HEX ); 78 | void GetHash( unsigned char *uDest ); 79 | unsigned char * GetHash( void ) const; 80 | 81 | private: 82 | void Transform( unsigned int state[ 5 ], unsigned char buffer[ 64 ] ); 83 | unsigned char workspace[ 64 ]; 84 | }; 85 | } 86 | 87 | #endif // ___SHA1_H___ 88 | 89 | -------------------------------------------------------------------------------- /Include/raknet/SimpleMutex.h: -------------------------------------------------------------------------------- 1 | /// \file 2 | /// \brief \b [Internal] Encapsulates a mutex 3 | /// 4 | /// This file is part of RakNet Copyright 2003 Kevin Jenkins. 5 | /// 6 | /// Usage of RakNet is subject to the appropriate license agreement. 7 | /// Creative Commons Licensees are subject to the 8 | /// license found at 9 | /// http://creativecommons.org/licenses/by-nc/2.5/ 10 | /// Single application licensees are subject to the license found at 11 | /// http://www.rakkarsoft.com/SingleApplicationLicense.html 12 | /// Custom license users are subject to the terms therein. 13 | /// GPL license users are subject to the GNU General Public 14 | /// License as published by the Free 15 | /// Software Foundation; either version 2 of the License, or (at your 16 | /// option) any later version. 17 | 18 | #ifndef __SIMPLE_MUTEX_H 19 | #define __SIMPLE_MUTEX_H 20 | 21 | #ifdef _COMPATIBILITY_1 22 | #include "Compatibility1Includes.h" 23 | #elif defined(_WIN32) 24 | #include 25 | #else 26 | #include 27 | #include 28 | #endif 29 | #include "Export.h" 30 | 31 | namespace RakNet 32 | { 33 | /// \brief An easy to use mutex. 34 | /// 35 | /// I wrote this because the version that comes with Windows is too complicated and requires too much code to use. 36 | /// @remark Previously I used this everywhere, and in fact for a year or two RakNet was totally threadsafe. While doing profiling, I saw that this function was incredibly slow compared to the blazing performance of everything else, so switched to single producer / consumer everywhere. Now the user thread of RakNet is not threadsafe, but it's 100X faster than before. 37 | class RAK_DLL_EXPORT SimpleMutex 38 | { 39 | public: 40 | 41 | /// Constructor 42 | SimpleMutex(); 43 | 44 | // Destructor 45 | ~SimpleMutex(); 46 | 47 | // Locks the mutex. Slow! 48 | void Lock(void); 49 | 50 | // Unlocks the mutex. 51 | void Unlock(void); 52 | private: 53 | #ifdef _WIN32 54 | CRITICAL_SECTION criticalSection; /// Docs say this is faster than a mutex for single process access 55 | #else 56 | pthread_mutex_t hMutex; 57 | #endif 58 | }; 59 | } 60 | 61 | #endif 62 | 63 | -------------------------------------------------------------------------------- /Include/raknet/SocketLayer.h: -------------------------------------------------------------------------------- 1 | /// \file 2 | /// \brief \b [Internal] Encapsulates Berkely sockets 3 | /// 4 | /// This file is part of RakNet Copyright 2003 Kevin Jenkins. 5 | /// 6 | /// Usage of RakNet is subject to the appropriate license agreement. 7 | /// Creative Commons Licensees are subject to the 8 | /// license found at 9 | /// http://creativecommons.org/licenses/by-nc/2.5/ 10 | /// Single application licensees are subject to the license found at 11 | /// http://www.rakkarsoft.com/SingleApplicationLicense.html 12 | /// Custom license users are subject to the terms therein. 13 | /// GPL license users are subject to the GNU General Public 14 | /// License as published by the Free 15 | /// Software Foundation; either version 2 of the License, or (at your 16 | /// option) any later version. 17 | 18 | 19 | #ifndef __SOCKET_LAYER_H 20 | #define __SOCKET_LAYER_H 21 | 22 | #ifdef _COMPATIBILITY_1 23 | #include "Compatibility1Includes.h" 24 | #elif defined(_WIN32) 25 | // IP_DONTFRAGMENT is different between winsock 1 and winsock 2. Therefore, Winsock2.h must be linked againt Ws2_32.lib 26 | // winsock.h must be linked against WSock32.lib. If these two are mixed up the flag won't work correctly 27 | #include 28 | #include 29 | #else 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | /// Unix/Linux uses ints for sockets 37 | typedef int SOCKET; 38 | #define INVALID_SOCKET -1 39 | #define SOCKET_ERROR -1 40 | #endif 41 | #include "ClientContextStruct.h" 42 | 43 | namespace RakNet 44 | { 45 | class RakPeer; 46 | 47 | // A platform independent implementation of Berkeley sockets, with settings used by RakNet 48 | class SocketLayer 49 | { 50 | 51 | public: 52 | 53 | /// Default Constructor 54 | SocketLayer(); 55 | 56 | /// Destructor 57 | ~SocketLayer(); 58 | 59 | // Get the singleton instance of the Socket Layer. 60 | /// \return unique instance 61 | static inline SocketLayer* Instance() 62 | { 63 | if (_instance == nullptr) 64 | _instance = new SocketLayer(); 65 | return _instance; 66 | } 67 | static inline void Destroy() 68 | { 69 | if (_instance != nullptr) 70 | { 71 | delete _instance; 72 | _instance = nullptr; 73 | } 74 | } 75 | 76 | // Connect a socket to a remote host. 77 | /// \param[in] writeSocket The local socket. 78 | /// \param[in] binaryAddress The address of the remote host. 79 | /// \param[in] port the remote port. 80 | /// \return A new socket used for communication. 81 | SOCKET Connect( SOCKET writeSocket, unsigned int binaryAddress, unsigned short port ); 82 | 83 | // Creates a bound socket to listen for incoming connections on the specified port 84 | /// \param[in] port the port number 85 | /// \param[in] blockingSocket 86 | /// \return A new socket used for accepting clients 87 | SOCKET CreateBoundSocket( unsigned short port, bool blockingSocket, const char *forceHostAddress ); 88 | 89 | #if !defined(_COMPATIBILITY_1) 90 | const char* DomainNameToIP( const char *domainName ); 91 | #endif 92 | 93 | #ifdef __USE_IO_COMPLETION_PORTS 94 | void AssociateSocketWithCompletionPort( SOCKET socket, ClientContextStruct* completionKey ); 95 | #endif 96 | 97 | /// Start an asynchronous read using the specified socket. The callback will use the specified PlayerID (associated with this socket) and call either the client or the server callback (one or 98 | /// the other should be 0) 99 | /// \note Was used for depreciated IO completion ports. 100 | bool AssociateSocketWithCompletionPortAndRead( SOCKET readSocket, unsigned int binaryAddress, unsigned short port, RakPeer* rakPeer ); 101 | 102 | /// Write \a data of length \a length to \a writeSocket 103 | /// \param[in] writeSocket The socket to write to 104 | /// \param[in] data The data to write 105 | /// \param[in] length The length of \a data 106 | void Write( const SOCKET writeSocket, const char* data, const int length ); 107 | 108 | /// Read data from a socket 109 | /// \param[in] s the socket 110 | /// \param[in] rakPeer The instance of rakPeer containing the recvFrom C callback 111 | /// \param[in] errorCode An error code if an error occured . 112 | /// \return Returns true if you successfully read data, false on error. 113 | int RecvFrom( const SOCKET s, RakPeer *rakPeer, int *errorCode ); 114 | 115 | #if !defined(_COMPATIBILITY_1) 116 | /// Retrieve all local IP address in a string format. 117 | /// \param[in] ipList An array of ip address in dotted notation. 118 | void GetMyIP( char ipList[ 10 ][ 16 ] ); 119 | #endif 120 | 121 | /// Call sendto (UDP obviously) 122 | /// \param[in] s the socket 123 | /// \param[in] data The byte buffer to send 124 | /// \param[in] length The length of the \a data in bytes 125 | /// \param[in] ip The address of the remote host in dotted notation. 126 | /// \param[in] port The port number to send to. 127 | /// \return 0 on success, nonzero on failure. 128 | int SendTo( SOCKET s, const char *data, int length, char ip[ 16 ], unsigned short port ); 129 | 130 | /// Call sendto (UDP obviously) 131 | /// \param[in] s the socket 132 | /// \param[in] data The byte buffer to send 133 | /// \param[in] length The length of the \a data in bytes 134 | /// \param[in] binaryAddress The address of the remote host in binary format. 135 | /// \param[in] port The port number to send to. 136 | /// \return 0 on success, nonzero on failure. 137 | int SendTo( SOCKET s, const char *data, int length, unsigned int binaryAddress, unsigned short port ); 138 | 139 | /// Returns the local port, useful when passing 0 as the startup port. 140 | /// \param[in] s The socket whose port we are referring to 141 | /// \return The local port 142 | unsigned short GetLocalPort ( SOCKET s ); 143 | private: 144 | 145 | static bool socketLayerStarted; 146 | #ifdef _WIN32 147 | static WSADATA winsockInfo; 148 | #endif 149 | static SocketLayer *_instance; 150 | }; 151 | } 152 | 153 | #endif 154 | 155 | -------------------------------------------------------------------------------- /Include/raknet/StringCompressor.h: -------------------------------------------------------------------------------- 1 | /// \file 2 | /// \brief \b Compresses/Decompresses ASCII strings and writes/reads them to BitStream class instances. You can use this to easily serialize and deserialize your own strings. 3 | /// 4 | /// This file is part of RakNet Copyright 2003 Kevin Jenkins. 5 | /// 6 | /// Usage of RakNet is subject to the appropriate license agreement. 7 | /// Creative Commons Licensees are subject to the 8 | /// license found at 9 | /// http://creativecommons.org/licenses/by-nc/2.5/ 10 | /// Single application licensees are subject to the license found at 11 | /// http://www.rakkarsoft.com/SingleApplicationLicense.html 12 | /// Custom license users are subject to the terms therein. 13 | /// GPL license users are subject to the GNU General Public 14 | /// License as published by the Free 15 | /// Software Foundation; either version 2 of the License, or (at your 16 | /// option) any later version. 17 | 18 | #ifndef __STRING_COMPRESSOR_H 19 | #define __STRING_COMPRESSOR_H 20 | 21 | #include "Export.h" 22 | #include "DS_Map.h" 23 | 24 | /// Forward declaration 25 | namespace RakNet 26 | { 27 | class BitStream; 28 | 29 | namespace DataStructures 30 | { 31 | class HuffmanEncodingTree; 32 | } 33 | 34 | /// \brief Writes and reads strings to and from bitstreams. 35 | /// 36 | /// Only works with ASCII strings. The default compression is for English. 37 | /// You can call GenerateTreeFromStrings to compress and decompress other languages efficiently as well. 38 | class RAK_DLL_EXPORT StringCompressor 39 | { 40 | public: 41 | 42 | /// Destructor 43 | ~StringCompressor(); 44 | 45 | /// static function because only static functions can access static members 46 | /// The RakPeer constructor adds a reference to this class, so don't call this until an instance of RakPeer exists, or unless you call AddReference yourself. 47 | /// \return the unique instance of the StringCompressor 48 | static StringCompressor* Instance(void); 49 | 50 | /// Given an array of strings, such as a chat log, generate the optimal encoding tree for it. 51 | /// This function is optional and if it is not called a default tree will be used instead. 52 | /// \param[in] input An array of bytes which should point to text. 53 | /// \param[in] inputLength Length of \a input 54 | /// \param[in] languageID An identifier for the language / string table to generate the tree for. English is automatically created with ID 0 in the constructor. 55 | void GenerateTreeFromStrings( unsigned char *input, unsigned inputLength, int languageID ); 56 | 57 | /// Writes input to output, compressed. Takes care of the null terminator for you. 58 | /// \param[in] input Pointer to an ASCII string 59 | /// \param[in] maxCharsToWrite The max number of bytes to write of \a input. Use 0 to mean no limit. 60 | /// \param[out] output The bitstream to write the compressed string to 61 | /// \param[in] languageID Which language to use 62 | void EncodeString( const char *input, int maxCharsToWrite, RakNet::BitStream *output, int languageID=0 ); 63 | 64 | /// Writes input to output, uncompressed. Takes care of the null terminator for you. 65 | /// \param[out] output A block of bytes to receive the output 66 | /// \param[in] maxCharsToWrite Size, in bytes, of \a output . A NULL terminator will always be appended to the output string. If the maxCharsToWrite is not large enough, the string will be truncated. 67 | /// \param[in] input The bitstream containing the compressed string 68 | /// \param[in] languageID Which language to use 69 | bool DecodeString( char *output, int maxCharsToWrite, RakNet::BitStream *input, int languageID=0); 70 | 71 | /// Writes input to output, uncompressed. Takes care of the null terminator for you. Can be resumed by tracking stringBitLength. 72 | /// \param[out] output A block of bytes to receive the output 73 | /// \param[in] maxCharsToWrite Size, in bytes, of \a output . A NULL terminator will always be appended to the output string. If the maxCharsToWrite is not large enough, the string will be truncated. 74 | /// \param[in] input The bitstream containing the compressed string 75 | /// \param[in] languageID Which language to use 76 | /// \param[in] stringBitLength How many bits were not previously decoded 77 | /// \param[in] skip If there is too much data to fit in the output, drop the remainder 78 | bool DecodeString( char *output, int maxCharsToWrite, RakNet::BitStream *input, int languageID, unsigned & stringBitLength, bool skip ); 79 | 80 | /// Used so I can allocate and deallocate this singleton at runtime 81 | static void AddReference(void); 82 | 83 | /// Used so I can allocate and deallocate this singleton at runtime 84 | static void RemoveReference(void); 85 | 86 | private: 87 | 88 | /// Private Constructor 89 | StringCompressor(); 90 | 91 | /// Singleton instance 92 | static StringCompressor *instance; 93 | 94 | /// Pointer to the huffman encoding trees. 95 | DataStructures::Map huffmanEncodingTrees; 96 | 97 | static int referenceCount; 98 | }; 99 | } 100 | 101 | /// Define to more easily reference the string compressor instance. 102 | /// The RakPeer constructor adds a reference to this class, so don't call this until an instance of RakPeer exists, or unless you call AddReference yourself. 103 | #define stringCompressor StringCompressor::Instance() 104 | 105 | #endif 106 | -------------------------------------------------------------------------------- /Include/raknet/StringTable.h: -------------------------------------------------------------------------------- 1 | /// \file 2 | /// \brief A simple class to encode and decode known strings based on a lookup table. Similar to the StringCompressor class. 3 | /// 4 | /// This file is part of RakNet Copyright 2003 Kevin Jenkins. 5 | /// 6 | /// Usage of RakNet is subject to the appropriate license agreement. 7 | /// Creative Commons Licensees are subject to the 8 | /// license found at 9 | /// http://creativecommons.org/licenses/by-nc/2.5/ 10 | /// Single application licensees are subject to the license found at 11 | /// http://www.rakkarsoft.com/SingleApplicationLicense.html 12 | /// Custom license users are subject to the terms therein. 13 | /// GPL license users are subject to the GNU General Public 14 | /// License as published by the Free 15 | /// Software Foundation; either version 2 of the License, or (at your 16 | /// option) any later version. 17 | 18 | #ifndef __STRING_TABLE_H 19 | #define __STRING_TABLE_H 20 | 21 | #include "DS_OrderedList.h" 22 | #include "Export.h" 23 | 24 | /// Forward declaration 25 | namespace RakNet 26 | { 27 | class BitStream; 28 | 29 | /// StringTableType should be the smallest type possible, or else it defeats the purpose of the StringTable class, which is to save bandwidth. 30 | typedef unsigned char StringTableType; 31 | 32 | /// The string plus a bool telling us if this string was copied or not. 33 | struct StrAndBool 34 | { 35 | char *str; 36 | bool b; 37 | }; 38 | int RAK_DLL_EXPORT StrAndBoolComp( char *const &key, const StrAndBool &data ); 39 | 40 | /// This is an even more efficient alternative to StringCompressor in that it writes a single byte from a lookup table and only does compression 41 | /// if the string does not already exist in the table. 42 | /// All string tables must match on all systems - hence you must add all the strings in the same order on all systems. 43 | /// Furthermore, this must be done before sending packets that use this class, since the strings are ordered for fast lookup. Adding after that time would mess up all the indices so don't do it. 44 | /// Don't use this class to write strings which were not previously registered with AddString, since you just waste bandwidth then. Use StringCompressor instead. 45 | /// \brief Writes a string index, instead of the whole string 46 | class RAK_DLL_EXPORT StringTable 47 | { 48 | public: 49 | 50 | /// Destructor 51 | ~StringTable(); 52 | 53 | /// static function because only static functions can access static members 54 | /// The RakPeer constructor adds a reference to this class, so don't call this until an instance of RakPeer exists, or unless you call AddReference yourself. 55 | /// \return the unique instance of the StringTable 56 | static StringTable* Instance(void); 57 | 58 | /// Add a string to the string table. 59 | /// \param[in] str The string to add to the string table 60 | /// \param[in] copyString true to make a copy of the passed string (takes more memory), false to not do so (if your string is in static memory). 61 | void AddString(const char *str, bool copyString); 62 | 63 | /// Writes input to output, compressed. Takes care of the null terminator for you. 64 | /// Relies on the StringCompressor class, which is automatically reference counted in the constructor and destructor in RakPeer. You can call the reference counting functions yourself if you wish too. 65 | /// \param[in] input Pointer to an ASCII string 66 | /// \param[in] maxCharsToWrite The size of \a input 67 | /// \param[out] output The bitstream to write the compressed string to 68 | void EncodeString( const char *input, int maxCharsToWrite, RakNet::BitStream *output ); 69 | 70 | /// Writes input to output, uncompressed. Takes care of the null terminator for you. 71 | /// Relies on the StringCompressor class, which is automatically reference counted in the constructor and destructor in RakPeer. You can call the reference counting functions yourself if you wish too. 72 | /// \param[out] output A block of bytes to receive the output 73 | /// \param[in] maxCharsToWrite Size, in bytes, of \a output . A NULL terminator will always be appended to the output string. If the maxCharsToWrite is not large enough, the string will be truncated. 74 | /// \param[in] input The bitstream containing the compressed string 75 | bool DecodeString( char *output, int maxCharsToWrite, RakNet::BitStream *input ); 76 | 77 | /// Used so I can allocate and deallocate this singleton at runtime 78 | static void AddReference(void); 79 | 80 | /// Used so I can allocate and deallocate this singleton at runtime 81 | static void RemoveReference(void); 82 | 83 | protected: 84 | /// Called when you mess up and send a string using this class that was not registered with AddString 85 | /// \param[in] maxCharsToWrite Size, in bytes, of \a output . A NULL terminator will always be appended to the output string. If the maxCharsToWrite is not large enough, the string will be truncated. 86 | void LogStringNotFound(const char *strName); 87 | 88 | /// Private Constructor 89 | StringTable(); 90 | 91 | /// Singleton instance 92 | static StringTable *instance; 93 | static int referenceCount; 94 | 95 | DataStructures::OrderedList orderedStringList; 96 | }; 97 | } 98 | 99 | /// Define to more easily reference the string table instance. 100 | /// The RakPeer constructor adds a reference to this class, so don't call this until an instance of RakPeer exists, or unless you call AddReference yourself. 101 | #define stringTable StringTable::Instance() 102 | 103 | #endif 104 | -------------------------------------------------------------------------------- /Include/raknet/TransportInterface.h: -------------------------------------------------------------------------------- 1 | /// \file 2 | /// \brief Contains TransportInterface from which you can derive custom transport providers for ConsoleServer. 3 | /// 4 | /// This file is part of RakNet Copyright 2003 Kevin Jenkins. 5 | /// 6 | /// Usage of RakNet is subject to the appropriate license agreement. 7 | /// Creative Commons Licensees are subject to the 8 | /// license found at 9 | /// http://creativecommons.org/licenses/by-nc/2.5/ 10 | /// Single application licensees are subject to the license found at 11 | /// http://www.rakkarsoft.com/SingleApplicationLicense.html 12 | /// Custom license users are subject to the terms therein. 13 | /// GPL license users are subject to the GNU General Public 14 | /// License as published by the Free 15 | /// Software Foundation; either version 2 of the License, or (at your 16 | /// option) any later version. 17 | 18 | #ifndef __TRANSPORT_INTERFACE_H 19 | #define __TRANSPORT_INTERFACE_H 20 | 21 | #include "NetworkTypes.h" 22 | #include "Export.h" 23 | 24 | #define REMOTE_MAX_TEXT_INPUT 512 25 | 26 | namespace RakNet 27 | { 28 | class CommandParserInterface; 29 | 30 | /// \brief Defines an interface that is used to send and receive null-terminated strings. 31 | /// In practice this is only used by the CommandParser system for for servers. 32 | class RAK_DLL_EXPORT TransportInterface 33 | { 34 | public: 35 | /// Start the transport provider on the indicated port. 36 | /// \param[in] port The port to start the transport provider on 37 | /// \param[in] serverMode If true, you should allow incoming connections (I don't actually use this anywhere) 38 | /// \return Return true on success, false on failure. 39 | virtual bool Start(unsigned short port, bool serverMode)=0; 40 | 41 | /// Stop the transport provider. You can clear memory and shutdown threads here. 42 | virtual void Stop(void)=0; 43 | 44 | /// Send a null-terminated string to \a playerId 45 | /// If your transport method requires particular formatting of the outgoing data (e.g. you don't just send strings) you can do it here 46 | /// and parse it out in Receive(). 47 | /// \param[in] playerId The player to send the string to 48 | /// \param[in] data format specifier - same as printf 49 | /// \param[in] ... format specification arguments - same as printf 50 | virtual void Send( PlayerID playerId, const char *data, ... )=0; 51 | 52 | /// Disconnect \a playerId . The binary address and port defines the PlayerID structure. 53 | /// \param[in] playerId The player/address to disconnect 54 | virtual void CloseConnection( PlayerID playerId )=0; 55 | 56 | /// Return a string. The string should be allocated and written to Packet::data . 57 | /// The byte length should be written to Packet::length . The player/address should be written to Packet::playerid 58 | /// If your transport protocol adds special formatting to the data stream you should parse it out before returning it in the packet 59 | /// and thus only return a string in Packet::data 60 | /// \return The packet structure containing the result of Receive, or 0 if no data is available 61 | virtual Packet* Receive( void )=0; 62 | 63 | /// Deallocate the Packet structure returned by Receive 64 | /// \param[in] The packet to deallocate 65 | virtual void DeallocatePacket( Packet *packet )=0; 66 | 67 | /// If a new system connects to you, you should queue that event and return the playerId/address of that player in this function. 68 | /// \return The PlayerID/address of the system 69 | virtual PlayerID HasNewConnection(void)=0; 70 | 71 | /// If a system loses the connection, you should queue that event and return the playerId/address of that player in this function. 72 | /// \return The PlayerID/address of the system 73 | virtual PlayerID HasLostConnection(void)=0; 74 | 75 | /// Your transport provider can itself have command parsers if the transport layer has user-modifiable features 76 | /// For example, your transport layer may have a password which you want remote users to be able to set or you may want 77 | /// to allow remote users to turn on or off command echo 78 | /// \return 0 if you do not need a command parser - otherwise the desired derivation of CommandParserInterface 79 | virtual CommandParserInterface* GetCommandParser(void)=0; 80 | protected: 81 | }; 82 | } 83 | 84 | #endif 85 | 86 | -------------------------------------------------------------------------------- /Include/raknet/_findfirst.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Original file by the_viking, fixed by Rômulo Fernandes 3 | * Should emulate windows finddata structure 4 | */ 5 | 6 | #ifndef GCC_FINDFIRST_H 7 | #define GCC_FINDFIRST_H 8 | 9 | #if (defined(__GNUC__) || defined(__GCCXML__)) && !defined(__WIN32) 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #define _A_NORMAL 0x00 // Normal file 18 | #define _A_RDONLY 0x01 // Read-only file 19 | #define _A_HIDDEN 0x02 // Hidden file 20 | #define _A_SYSTEM 0x04 // System file 21 | #define _A_VOLID 0x08 // Volume ID 22 | #define _A_SUBDIR 0x10 // Subdirectory 23 | #define _A_ARCH 0x20 // File changed since last archive 24 | #define FA_NORMAL 0x00 // Synonym of _A_NORMAL 25 | #define FA_RDONLY 0x01 // Synonym of _A_RDONLY 26 | #define FA_HIDDEN 0x02 // Synonym of _A_HIDDEN 27 | #define FA_SYSTEM 0x04 // Synonym of _A_SYSTEM 28 | #define FA_LABEL 0x08 // Synonym of _A_VOLID 29 | #define FA_DIREC 0x10 // Synonym of _A_SUBDIR 30 | #define FA_ARCH 0x20 // Synonym of _A_ARCH 31 | 32 | typedef struct _finddata_t 33 | { 34 | char name[260]; 35 | int attrib; 36 | unsigned long size; 37 | } _finddata; 38 | 39 | /** Hold information about the current search 40 | */ 41 | typedef struct _findinfo_t 42 | { 43 | DIR* openedDir; 44 | char filter[260]; 45 | } _findinfo; 46 | 47 | long _findfirst(const char *name, _finddata_t *f); 48 | int _findnext(long h, _finddata_t *f); 49 | int _findclose(long h); 50 | 51 | #endif 52 | #endif 53 | -------------------------------------------------------------------------------- /Include/raknet/rijndael.h: -------------------------------------------------------------------------------- 1 | /// \file 2 | /// \brief \b [Internal] AES encoding / decoding 3 | /// rijndael-alg-fst.h v2.0 August '99 4 | /// Optimised ANSI C code 5 | /// taken from the 'aescrypt' project: www.sf.net/projects/aescrypt 6 | /// See LICENSE-EST for the license applicable to this file 7 | 8 | 9 | /// \note Although the routines claim to support 192 and 256 bit blocks, 10 | /// don't take your chances - stick to the 128 bit (16 byte) blocks unless 11 | /// you've run tests to prove that 192 and 256 are correctly supported. 12 | /// - Cirilo 13 | 14 | 15 | #include 16 | 17 | #ifndef __RIJNDAEL_ALG_H 18 | #define __RIJNDAEL_ALG_H 19 | 20 | #define MAXKC (256/32) 21 | #define MAXROUNDS 14 22 | 23 | namespace RakNet 24 | { 25 | typedef unsigned char word8; 26 | typedef unsigned short word16; 27 | typedef unsigned int word32; 28 | 29 | int rijndaelKeySched (word8 k[MAXKC][4], int keyBits, 30 | word8 rk[MAXROUNDS+1][4][4]); 31 | int rijndaelKeyEnctoDec (int keyBits, word8 W[MAXROUNDS+1][4][4]); 32 | int rijndaelEncrypt (word8 a[16], word8 b[16], 33 | word8 rk[MAXROUNDS+1][4][4]); 34 | int rijndaelEncryptRound (word8 a[4][4], 35 | word8 rk[MAXROUNDS+1][4][4], int rounds); 36 | int rijndaelDecrypt (word8 a[16], word8 b[16], 37 | word8 rk[MAXROUNDS+1][4][4]); 38 | int rijndaelDecryptRound (word8 a[4][4], 39 | word8 rk[MAXROUNDS+1][4][4], int rounds); 40 | 41 | #endif 42 | 43 | // End of algorithm headers. begin the AES API header defs 44 | 45 | 46 | #ifndef __RIJNDAEL_API_H 47 | #define __RIJNDAEL_API_H 48 | 49 | // rijndael-api-fst.h v2.0 August '99 50 | // Optimised ANSI C code 51 | 52 | 53 | // Defines: 54 | // Add any additional defines you need 55 | 56 | 57 | #define DIR_ENCRYPT 0 // Are we encrpyting? 58 | #define DIR_DECRYPT 1 // Are we decrpyting? 59 | #define MODE_ECB 1 // Are we ciphering in ECB mode? 60 | #define MODE_CBC 2 // Are we ciphering in CBC mode? 61 | #define MODE_CFB1 3 // Are we ciphering in 1-bit CFB mode? 62 | #ifndef TRUE 63 | #define TRUE 1 64 | #endif 65 | #ifndef FALSE 66 | #define FALSE 0 67 | #endif 68 | #define BITSPERBLOCK 128 // Default number of bits in a cipher block 69 | 70 | // Error Codes - CHANGE POSSIBLE: inclusion of additional error codes 71 | #define BAD_KEY_DIR -1 // Key direction is invalid, e.g., unknown value 72 | #define BAD_KEY_MAT -2 // Key material not of correct length 73 | #define BAD_KEY_INSTANCE -3 // Key passed is not valid 74 | #define BAD_CIPHER_MODE -4 // Params struct passed to cipherInit invalid 75 | #define BAD_CIPHER_STATE -5 // Cipher in wrong state (e.g., not initialized) 76 | #define BAD_BLOCK_LENGTH -6 77 | #define BAD_CIPHER_INSTANCE -7 78 | 79 | 80 | // CHANGE POSSIBLE: inclusion of algorithm specific defines 81 | // 14.Dec.2005 Cirilo: keys are now unsigned char rather than hex (ASCII) 82 | #define MAX_KEY_SIZE 32 // # of unsigned char's needed to represent a key 83 | #define MAX_IV_SIZE 16 // # bytes needed to represent an IV 84 | 85 | // Typedefs: 86 | // Typedef'ed data storage elements. Add any algorithm specific parameters at the bottom of the structs as appropriate. 87 | 88 | typedef unsigned char BYTE; 89 | 90 | // The structure for key information 91 | typedef struct { 92 | BYTE direction; /// Key used for encrypting or decrypting? 93 | int keyLen; /// Length of the key 94 | char keyMaterial[MAX_KEY_SIZE+1]; /// Raw key data in ASCII, e.g., user input or KAT values 95 | /// The following parameters are algorithm dependent, replace or add as necessary 96 | int blockLen; /// block length 97 | word8 keySched[MAXROUNDS+1][4][4]; /// key schedule 98 | } keyInstance; 99 | 100 | // The structure for cipher information 101 | typedef struct { // changed order of the components 102 | BYTE mode; /// MODE_ECB, MODE_CBC, or MODE_CFB1 103 | BYTE IV[MAX_IV_SIZE]; /// A possible Initialization Vector for ciphering 104 | // Add any algorithm specific parameters needed here 105 | int blockLen; /// Sample: Handles non-128 bit block sizes (if available) 106 | } cipherInstance; 107 | 108 | 109 | // Function protoypes 110 | // CHANGED: makeKey(): parameter blockLen added this parameter is absolutely necessary if you want to 111 | // setup the round keys in a variable block length setting 112 | // cipherInit(): parameter blockLen added (for obvious reasons) 113 | 114 | int makeKey(keyInstance *key, BYTE direction, int keyLen, char *keyMaterial); 115 | 116 | int cipherInit(cipherInstance *cipher, BYTE mode, char *IV); 117 | 118 | int blockEncrypt(cipherInstance *cipher, keyInstance *key, BYTE *input, 119 | int inputLen, BYTE *outBuffer); 120 | 121 | int blockDecrypt(cipherInstance *cipher, keyInstance *key, BYTE *input, 122 | int inputLen, BYTE *outBuffer); 123 | int cipherUpdateRounds(cipherInstance *cipher, keyInstance *key, BYTE *input, 124 | int inputLen, BYTE *outBuffer, int Rounds); 125 | } 126 | 127 | #endif // __RIJNDAEL_API_H 128 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # RakNet 2.52 2 | This is a modified version of RakNet 2.52 used in open.mp. 3 | Modifications are done to work with SA:MP version of RakNet with some additional security fixes and improvements. 4 | 5 | **NOTE:** This is not taken from SA:MP leaked source code. 6 | -------------------------------------------------------------------------------- /SAMPRakNet.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #if defined _WIN32 || defined WIN32 8 | #include 9 | #include 10 | #else 11 | #include 12 | typedef int SOCKET; 13 | #define INVALID_SOCKET -1 14 | #define SOCKET_ERROR -1 15 | #endif 16 | 17 | #if __has_include() 18 | #include 19 | #endif 20 | 21 | #ifndef MAXIMUM_MTU_SIZE 22 | #define MAXIMUM_MTU_SIZE 1500 23 | #endif 24 | 25 | #define MAX_AUTH_RESPONSE_LEN (64) 26 | 27 | #include "../../Server/Components/LegacyNetwork/Query/query.hpp" 28 | 29 | #include "Include/raknet/NetworkTypes.h" 30 | #include "Include/raknet/GetTime.h" 31 | 32 | #define MAX_UNVERIFIED_RPCS (5) 33 | 34 | #define LOCALHOST (0x0100007fu) 35 | 36 | #include 37 | 38 | enum class OmpVersion 39 | { 40 | None = 0, 41 | v0_0_1 = 0x000001, 42 | v0_1_4 = 0x000104, 43 | }; 44 | 45 | using PlayerAddressHash = uint64_t; 46 | 47 | class SAMPRakNet 48 | { 49 | public: 50 | static constexpr int ENCRYPTION_KEY_SIZE = 4; 51 | static constexpr int MAGIC_OMP_IDENTIFICATION_NUMBER = 0x006F6D70; // sent to client on connect request and handled there so we know it's a real packet from us. it's basically 'omp' in 32bit btw 52 | static constexpr int OMP_PETARDED = 0x6D70; // it's basically 'mp' in 16bit 53 | static constexpr int SAMP_PETARDED = 0x6969; // it's from default SAMP... Petarded [S04E06] 54 | static constexpr OmpVersion CURRENT_OMP_CLIENT_MOD_VERSION = OmpVersion::v0_1_4; 55 | 56 | enum AuthType 57 | { 58 | AuthType_Invalid, 59 | AuthType_Player, 60 | AuthType_NPC 61 | }; 62 | 63 | struct RemoteSystemData 64 | { 65 | uint8_t authIndex; 66 | AuthType authType; 67 | uint8_t unverifiedRPCs; 68 | 69 | RemoteSystemData() 70 | : authIndex(0) 71 | , authType(AuthType_Invalid) 72 | , unverifiedRPCs(0) 73 | { 74 | } 75 | }; 76 | 77 | struct OmpPlayerEncryptionData 78 | { 79 | uint32_t key; 80 | OmpVersion version; 81 | 82 | OmpPlayerEncryptionData() 83 | : key(0) 84 | , version(OmpVersion::None) 85 | { 86 | } 87 | 88 | OmpPlayerEncryptionData(uint32_t _key, OmpVersion _version) 89 | : key(_key) 90 | , version(_version) 91 | { 92 | } 93 | }; 94 | 95 | static void Init(ICore* core) 96 | { 97 | core_ = core; 98 | srand(time(nullptr)); 99 | } 100 | 101 | static PlayerAddressHash HashPlayerID(const RakNet::PlayerID& player) 102 | { 103 | return (static_cast(player.binaryAddress) << 16) | player.port; 104 | } 105 | 106 | static uint8_t* Decrypt(uint8_t const* src, int len); 107 | static uint8_t* Encrypt(const OmpPlayerEncryptionData* encryptionData, uint8_t const* src, int len); 108 | 109 | static uint16_t GetPort(); 110 | static void SetPort(uint16_t value); 111 | 112 | static uint32_t GetToken() { return token_; } 113 | static void SeedToken() { token_ = rand(); } 114 | 115 | static void HandleQuery(SOCKET instance, int outsize, const sockaddr_in& client, char const* buf, int insize); 116 | 117 | static Pair GenerateAuth(); 118 | static bool CheckAuth(uint8_t index, StringView auth); 119 | 120 | static void SeedCookie(); 121 | static uint16_t GetCookie(unsigned int address); 122 | 123 | static void SetTimeout(unsigned int timeout) { timeout_ = timeout; } 124 | static unsigned int GetTimeout() { return timeout_; } 125 | 126 | static void SetQuery(Query* query) { query_ = query; } 127 | 128 | static void SetLogCookies(bool log) { logCookies_ = log; } 129 | static bool ShouldLogCookies() { return logCookies_; } 130 | 131 | static void SetMinConnectionTime(unsigned int time) { minConnectionTime_ = time; } 132 | static unsigned int GetMinConnectionTime() { return minConnectionTime_; } 133 | 134 | static void SetMessagesLimit(unsigned int limit) { messagesLimit_ = limit; } 135 | static unsigned int GetMessagesLimit() { return messagesLimit_; } 136 | 137 | static void SetMessageHoleLimit(unsigned int limit) { messageHoleLimit_ = limit; } 138 | static unsigned int GetMessageHoleLimit() { return messageHoleLimit_; } 139 | 140 | static void SetAcksLimit(unsigned int limit) { acksLimit_ = limit; } 141 | static unsigned int GetAcksLimit() { return acksLimit_; } 142 | 143 | static void SetNetworkLimitsBanTime(unsigned int time) { networkLimitsBanTime_ = time; } 144 | static unsigned int GetNetworkLimitsBanTime() { return networkLimitsBanTime_; } 145 | 146 | static void SetGracePeriod(unsigned int time) { gracePeriod_ = RakNet::GetTime() + time; } 147 | static RakNet::RakNetTime GetGracePeriod() { return gracePeriod_; } 148 | 149 | static ICore* GetCore() { return core_; } 150 | 151 | static void ReplyToOmpClientAccessRequest(SOCKET connectionSocket, const RakNet::PlayerID& playerId, uint32_t encryptionKey); 152 | 153 | static bool IsPlayerUsingOmp(PlayerAddressHash hash) 154 | { 155 | return ompPlayers_.find(hash) != ompPlayers_.end(); 156 | } 157 | 158 | static bool IsPlayerUsingOmp(const RakNet::PlayerID& player) 159 | { 160 | auto hash = HashPlayerID(player); 161 | return ompPlayers_.find(hash) != ompPlayers_.end(); 162 | } 163 | 164 | static void ResetOmpPlayerConfiguration(const RakNet::PlayerID& player) 165 | { 166 | auto hash = HashPlayerID(player); 167 | ompPlayers_.erase(hash); 168 | } 169 | 170 | static void ConfigurePlayerUsingOmp(const RakNet::PlayerID& player, uint32_t key) 171 | { 172 | auto hash = HashPlayerID(player); 173 | ompPlayers_[hash] = OmpPlayerEncryptionData(key, OmpVersion::None); 174 | } 175 | 176 | static void SetPlayerOmpVersion(const RakNet::PlayerID& player, uint32_t ompVersion) 177 | { 178 | auto hash = HashPlayerID(player); 179 | auto data = ompPlayers_.find(hash); 180 | if (data != ompPlayers_.end()) 181 | { 182 | data->second.version = OmpVersion(ompVersion); 183 | } 184 | } 185 | 186 | static const OmpPlayerEncryptionData* GetOmpPlayerEncryptionData(PlayerAddressHash hash) 187 | { 188 | auto it = ompPlayers_.find(hash); 189 | if (it != ompPlayers_.end()) 190 | { 191 | return &it->second; 192 | } 193 | return nullptr; 194 | } 195 | 196 | static const OmpPlayerEncryptionData* GetOmpPlayerEncryptionData(const RakNet::PlayerID& player) 197 | { 198 | auto hash = HashPlayerID(player); 199 | auto it = ompPlayers_.find(hash); 200 | if (it != ompPlayers_.end()) 201 | { 202 | return &it->second; 203 | } 204 | return nullptr; 205 | } 206 | 207 | static bool IsAlreadyRequestingConnection(unsigned int binaryAddress) 208 | { 209 | return incomingConnections_.find(binaryAddress) != incomingConnections_.end(); 210 | } 211 | 212 | static void SetRequestingConnection(unsigned int binaryAddress, bool status) 213 | { 214 | if (status) 215 | incomingConnections_.insert(binaryAddress); 216 | else 217 | incomingConnections_.erase(binaryAddress); 218 | } 219 | 220 | static bool IsOmpEncryptionEnabled() 221 | { 222 | static bool* isEnabled = core_->getConfig().getBool("network.use_omp_encryption"); 223 | return isEnabled ? *isEnabled : false; 224 | } 225 | 226 | static bool OnConnectionRequest( 227 | SOCKET connectionSocket, 228 | RakNet::PlayerID& playerId, 229 | const char* data, 230 | RakNet::RakNetTime& minConnectionTick, 231 | RakNet::RakNetTime& minConnectionLogTick); 232 | 233 | private: 234 | static uint8_t decryptBuffer_[MAXIMUM_MTU_SIZE]; 235 | static uint8_t encryptBuffer_[MAXIMUM_MTU_SIZE]; 236 | static uint32_t token_; 237 | static uint16_t portNumber; 238 | static Query* query_; 239 | static unsigned int timeout_; 240 | static bool logCookies_; 241 | static unsigned int minConnectionTime_; 242 | static unsigned int messagesLimit_; 243 | static unsigned int messageHoleLimit_; 244 | static unsigned int acksLimit_; 245 | static unsigned int networkLimitsBanTime_; 246 | static ICore* core_; 247 | static FlatHashSet incomingConnections_; 248 | static RakNet::RakNetTime gracePeriod_; 249 | static FlatHashMap ompPlayers_; 250 | }; 251 | -------------------------------------------------------------------------------- /Source/CheckSum.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * @brief CheckSum implementation from http://www.flounder.com/checksum.htm 4 | * 5 | */ 6 | #include "CheckSum.h" 7 | 8 | using namespace RakNet; 9 | 10 | /**************************************************************************** 11 | * CheckSum::add 12 | * Inputs: 13 | * unsigned int d: word to add 14 | * Result: void 15 | * 16 | * Effect: 17 | * Adds the bytes of the unsigned int to the CheckSum 18 | ****************************************************************************/ 19 | 20 | void CheckSum::Add ( unsigned int value ) 21 | { 22 | union 23 | { 24 | unsigned int value; 25 | unsigned char bytes[ 4 ]; 26 | } 27 | 28 | data; 29 | data.value = value; 30 | 31 | for ( unsigned int i = 0; i < sizeof( data.bytes ); i++ ) 32 | Add ( data.bytes[ i ] ) 33 | 34 | ; 35 | } // CheckSum::add(unsigned int) 36 | 37 | /**************************************************************************** 38 | * CheckSum::add 39 | * Inputs: 40 | * unsigned short value: 41 | * Result: void 42 | * 43 | * Effect: 44 | * Adds the bytes of the unsigned short value to the CheckSum 45 | ****************************************************************************/ 46 | 47 | void CheckSum::Add ( unsigned short value ) 48 | { 49 | union 50 | { 51 | unsigned short value; 52 | unsigned char bytes[ 2 ]; 53 | } 54 | 55 | data; 56 | data.value = value; 57 | 58 | for ( unsigned int i = 0; i < sizeof( data.bytes ); i++ ) 59 | Add ( data.bytes[ i ] ) 60 | 61 | ; 62 | } // CheckSum::add(unsigned short) 63 | 64 | /**************************************************************************** 65 | * CheckSum::add 66 | * Inputs: 67 | * unsigned char value: 68 | * Result: void 69 | * 70 | * Effect: 71 | * Adds the byte to the CheckSum 72 | ****************************************************************************/ 73 | 74 | void CheckSum::Add ( unsigned char value ) 75 | { 76 | unsigned char cipher = (unsigned char)( value ^ ( r >> 8 ) ); 77 | r = ( cipher + r ) * c1 + c2; 78 | sum += cipher; 79 | } // CheckSum::add(unsigned char) 80 | 81 | 82 | /**************************************************************************** 83 | * CheckSum::add 84 | * Inputs: 85 | * LPunsigned char b: pointer to byte array 86 | * unsigned int length: count 87 | * Result: void 88 | * 89 | * Effect: 90 | * Adds the bytes to the CheckSum 91 | ****************************************************************************/ 92 | 93 | void CheckSum::Add ( unsigned char *b, unsigned int length ) 94 | { 95 | for ( unsigned int i = 0; i < length; i++ ) 96 | Add ( b[ i ] ) 97 | 98 | ; 99 | } // CheckSum::add(LPunsigned char, unsigned int) 100 | -------------------------------------------------------------------------------- /Source/CommandParserInterface.cpp: -------------------------------------------------------------------------------- 1 | #include "CommandParserInterface.h" 2 | #include "TransportInterface.h" 3 | #include 4 | #include 5 | #include 6 | #ifdef _COMPATIBILITY_1 7 | #include "Compatibility1Includes.h" 8 | #elif defined(_WIN32) 9 | // IP_DONTFRAGMENT is different between winsock 1 and winsock 2. Therefore, Winsock2.h must be linked againt Ws2_32.lib 10 | // winsock.h must be linked against WSock32.lib. If these two are mixed up the flag won't work correctly 11 | #include 12 | #else 13 | #include 14 | #include 15 | #include 16 | #endif 17 | 18 | #if (defined(__GNUC__) || defined(__GCCXML__)) && !defined(_stricmp) 19 | #define _stricmp strcasecmp 20 | #endif 21 | 22 | using namespace RakNet; 23 | 24 | #ifdef _MSC_VER 25 | #pragma warning( push ) 26 | #endif 27 | 28 | const unsigned char CommandParserInterface::VARIABLE_NUMBER_OF_PARAMETERS=255; 29 | 30 | namespace RakNet 31 | { 32 | int RegisteredCommandComp( const char* const & key, const RegisteredCommand &data ) 33 | { 34 | return _stricmp(key,data.command); 35 | } 36 | } 37 | 38 | CommandParserInterface::CommandParserInterface() {} 39 | CommandParserInterface::~CommandParserInterface() {} 40 | 41 | void CommandParserInterface::ParseConsoleString(char *str, const char delineator, unsigned char delineatorToggle, unsigned *numParameters, char **parameterList, unsigned parameterListLength) 42 | { 43 | unsigned strIndex, parameterListIndex; 44 | unsigned strLen; 45 | bool replaceDelineator=true; 46 | 47 | strLen = (unsigned) strlen(str); 48 | 49 | // Replace every instance of delineator, \n, \r with 0 50 | for (strIndex=0; strIndex < strLen; strIndex++) 51 | { 52 | if (str[strIndex]==delineator && replaceDelineator) 53 | str[strIndex]=0; 54 | 55 | if (str[strIndex]=='\n' || str[strIndex]=='\r') 56 | str[strIndex]=0; 57 | 58 | if (str[strIndex]==delineatorToggle) 59 | { 60 | str[strIndex]=0; 61 | replaceDelineator=!replaceDelineator; 62 | } 63 | } 64 | 65 | // Fill up parameterList starting at each non-0 66 | for (strIndex=0, parameterListIndex=0; strIndex < strLen; ) 67 | { 68 | if (str[strIndex]!=0) 69 | { 70 | parameterList[parameterListIndex]=str+strIndex; 71 | parameterListIndex++; 72 | RakAssert(parameterListIndex < parameterListLength); 73 | if (parameterListIndex >= parameterListLength) 74 | break; 75 | 76 | strIndex++; 77 | while (str[strIndex]!=0 && strIndex < strLen) 78 | strIndex++; 79 | } 80 | else 81 | strIndex++; 82 | } 83 | 84 | parameterList[parameterListIndex]=0; 85 | *numParameters=parameterListIndex; 86 | } 87 | void CommandParserInterface::SendCommandList(TransportInterface *transport, PlayerID playerId) 88 | { 89 | unsigned i; 90 | if (commandList.Size()) 91 | { 92 | for (i=0; i < commandList.Size(); i++) 93 | { 94 | transport->Send(playerId, "%s", commandList[i].command); 95 | if (i < commandList.Size()-1) 96 | transport->Send(playerId, ", "); 97 | } 98 | transport->Send(playerId, "\r\n"); 99 | } 100 | else 101 | transport->Send(playerId, "No registered commands\r\n"); 102 | } 103 | void CommandParserInterface::RegisterCommand(unsigned char parameterCount, const char *command, const char *commandHelp) 104 | { 105 | RegisteredCommand rc; 106 | rc.command=command; 107 | rc.commandHelp=commandHelp; 108 | rc.parameterCount=parameterCount; 109 | commandList.Insert( command, rc); 110 | } 111 | bool CommandParserInterface::GetRegisteredCommand(const char *command, RegisteredCommand *rc) 112 | { 113 | bool objectExists; 114 | unsigned index; 115 | index=commandList.GetIndexFromKey(command, &objectExists); 116 | if (objectExists) 117 | *rc=commandList[index]; 118 | return objectExists; 119 | } 120 | #ifdef _MSC_VER 121 | #pragma warning( disable : 4100 ) // warning C4100: : unreferenced formal parameter 122 | #endif 123 | void CommandParserInterface::OnTransportChange(TransportInterface *transport) 124 | { 125 | } 126 | #ifdef _MSC_VER 127 | #pragma warning( disable : 4100 ) // warning C4100: : unreferenced formal parameter 128 | #endif 129 | void CommandParserInterface::OnNewIncomingConnection(PlayerID playerId, TransportInterface *transport) 130 | { 131 | } 132 | #ifdef _MSC_VER 133 | #pragma warning( disable : 4100 ) // warning C4100: : unreferenced formal parameter 134 | #endif 135 | void CommandParserInterface::OnConnectionLost(PlayerID playerId, TransportInterface *transport) 136 | { 137 | } 138 | void CommandParserInterface::ReturnResult(bool res, const char *command,TransportInterface *transport, PlayerID playerId) 139 | { 140 | if (res) 141 | transport->Send(playerId, "%s returned true.\r\n", command); 142 | else 143 | transport->Send(playerId, "%s returned false.\r\n", command); 144 | } 145 | void CommandParserInterface::ReturnResult(int res, const char *command,TransportInterface *transport, PlayerID playerId) 146 | { 147 | transport->Send(playerId, "%s returned %i.\r\n", command, res); 148 | } 149 | void CommandParserInterface::ReturnResult(const char *command, TransportInterface *transport, PlayerID playerId) 150 | { 151 | transport->Send(playerId, "Successfully called %s.\r\n", command); 152 | } 153 | void CommandParserInterface::ReturnResult(char *res, const char *command, TransportInterface *transport, PlayerID playerId) 154 | { 155 | transport->Send(playerId, "%s returned %s.\r\n", command, res); 156 | } 157 | void CommandParserInterface::ReturnResult(PlayerID res, const char *command, TransportInterface *transport, PlayerID playerId) 158 | { 159 | #if !defined(_COMPATIBILITY_1) 160 | in_addr in; 161 | in.s_addr = playerId.binaryAddress; 162 | inet_ntoa( in ); 163 | transport->Send(playerId, "%s returned %s %i:%i\r\n", command,inet_ntoa( in ),res.binaryAddress, res.port); 164 | #else 165 | transport->Send(playerId, "%s returned %i:%i\r\n", command,res.binaryAddress, res.port); 166 | #endif 167 | } 168 | PlayerID CommandParserInterface::IntegersToPlayerID(int binaryAddress, int port) 169 | { 170 | PlayerID playerId; 171 | playerId.binaryAddress=binaryAddress; 172 | playerId.port=(unsigned short)port; 173 | return playerId; 174 | } 175 | 176 | #ifdef _MSC_VER 177 | #pragma warning( pop ) 178 | #endif 179 | 180 | -------------------------------------------------------------------------------- /Source/DataBlockEncryptor.cpp: -------------------------------------------------------------------------------- 1 | /// \file 2 | /// 3 | /// This file is part of RakNet Copyright 2003 Kevin Jenkins. 4 | /// 5 | /// Usage of RakNet is subject to the appropriate license agreement. 6 | /// Creative Commons Licensees are subject to the 7 | /// license found at 8 | /// http://creativecommons.org/licenses/by-nc/2.5/ 9 | /// Single application licensees are subject to the license found at 10 | /// http://www.rakkarsoft.com/SingleApplicationLicense.html 11 | /// Custom license users are subject to the terms therein. 12 | /// GPL license users are subject to the GNU General Public 13 | /// License as published by the Free 14 | /// Software Foundation; either version 2 of the License, or (at your 15 | /// option) any later version. 16 | 17 | #include "DataBlockEncryptor.h" 18 | #include "CheckSum.h" 19 | #include "GetTime.h" 20 | #include "Rand.h" 21 | #include 22 | #include 23 | #include "rijndael.h" 24 | #include "Types.h" 25 | #include "RakAssert.h" 26 | 27 | using namespace RakNet; 28 | 29 | DataBlockEncryptor::DataBlockEncryptor() 30 | { 31 | keySet = false; 32 | } 33 | 34 | DataBlockEncryptor::~DataBlockEncryptor() 35 | {} 36 | 37 | bool DataBlockEncryptor::IsKeySet( void ) const 38 | { 39 | return keySet; 40 | } 41 | 42 | void DataBlockEncryptor::SetKey( const unsigned char key[ 16 ] ) 43 | { 44 | keySet = true; 45 | //secretKeyAES128.set_key( key ); 46 | makeKey(&keyEncrypt, DIR_ENCRYPT, 16, (char*)key); 47 | makeKey(&keyDecrypt, DIR_DECRYPT, 16, (char*)key); 48 | cipherInit(&cipherInst, MODE_ECB, 0); // ECB is not secure except that I chain manually farther down. 49 | } 50 | 51 | void DataBlockEncryptor::UnsetKey( void ) 52 | { 53 | keySet = false; 54 | } 55 | 56 | void DataBlockEncryptor::Encrypt( unsigned char *input, int inputLength, unsigned char *output, int *outputLength ) 57 | { 58 | unsigned index, byteIndex, lastBlock; 59 | unsigned int checkSum; 60 | unsigned char paddingBytes; 61 | unsigned char encodedPad; 62 | unsigned char randomChar; 63 | CheckSum checkSumCalculator; 64 | 65 | 66 | 67 | RakAssert( keySet ); 68 | 69 | 70 | RakAssert( input && inputLength ); 71 | 72 | 73 | // randomChar will randomize the data so the same data sent twice will not look the same 74 | randomChar = (unsigned char) randomMT(); 75 | 76 | // 16-(((x-1) % 16)+1) 77 | 78 | // # of padding bytes is 16 -(((input_length + extra_data -1) % 16)+1) 79 | paddingBytes = (unsigned char) ( 16 - ( ( ( inputLength + sizeof( randomChar ) + sizeof( checkSum ) + sizeof( encodedPad ) - 1 ) % 16 ) + 1 ) ); 80 | 81 | // Randomize the pad size variable 82 | encodedPad = (unsigned char) randomMT(); 83 | encodedPad <<= 4; 84 | encodedPad |= paddingBytes; 85 | 86 | *outputLength = inputLength + sizeof( randomChar ) + sizeof( checkSum ) + sizeof( encodedPad ) + paddingBytes; 87 | 88 | // Write the data first, in case we are overwriting ourselves 89 | 90 | if ( input == output ) 91 | memmove( output + sizeof( checkSum ) + sizeof( randomChar ) + sizeof( encodedPad ) + paddingBytes, input, inputLength ); 92 | else 93 | memcpy( output + sizeof( checkSum ) + sizeof( randomChar ) + sizeof( encodedPad ) + paddingBytes, input, inputLength ); 94 | 95 | // Write the random char 96 | memcpy( output + sizeof( checkSum ), ( char* ) & randomChar, sizeof( randomChar ) ); 97 | 98 | // Write the pad size variable 99 | memcpy( output + sizeof( checkSum ) + sizeof( randomChar ), ( char* ) & encodedPad, sizeof( encodedPad ) ); 100 | 101 | // Write the padding 102 | for ( index = 0; index < paddingBytes; index++ ) 103 | *( output + sizeof( checkSum ) + sizeof( randomChar ) + sizeof( encodedPad ) + index ) = (unsigned char) randomMT(); 104 | 105 | // Calculate the checksum on the data 106 | checkSumCalculator.Add( output + sizeof( checkSum ), inputLength + sizeof( randomChar ) + sizeof( encodedPad ) + paddingBytes ); 107 | 108 | checkSum = checkSumCalculator.Get(); 109 | 110 | // Write checksum 111 | #ifdef HOST_ENDIAN_IS_BIG 112 | output[0] = checkSum&0xFF; 113 | output[1] = (checkSum>>8)&0xFF; 114 | output[2] = (checkSum>>16)&0xFF; 115 | output[3] = (checkSum>>24)&0xFF; 116 | #else 117 | memcpy( output, ( char* ) & checkSum, sizeof( checkSum ) ); 118 | #endif 119 | 120 | // AES on the first block 121 | // secretKeyAES128.encrypt16( output ); 122 | blockEncrypt(&cipherInst, &keyEncrypt, output, 16, output); 123 | 124 | lastBlock = 0; 125 | 126 | // Now do AES on every other block from back to front 127 | for ( index = *outputLength - 16; index >= 16; index -= 16 ) 128 | { 129 | for ( byteIndex = 0; byteIndex < 16; byteIndex++ ) 130 | output[ index + byteIndex ] ^= output[ lastBlock + byteIndex ]; 131 | 132 | //secretKeyAES128.encrypt16( output + index ); 133 | blockEncrypt(&cipherInst, &keyEncrypt, output+index, 16, output+index); 134 | 135 | lastBlock = index; 136 | } 137 | } 138 | 139 | bool DataBlockEncryptor::Decrypt( unsigned char *input, int inputLength, unsigned char *output, int *outputLength ) 140 | { 141 | unsigned index, byteIndex; 142 | unsigned int checkSum; 143 | unsigned char paddingBytes; 144 | unsigned char encodedPad; 145 | unsigned char randomChar; 146 | CheckSum checkSumCalculator; 147 | 148 | 149 | RakAssert( keySet ); 150 | 151 | 152 | if ( input == 0 || inputLength < 16 || ( inputLength % 16 ) != 0 ) 153 | { 154 | return false; 155 | } 156 | 157 | // Unchain in reverse order 158 | for ( index = 16; ( int ) index <= inputLength - 16;index += 16 ) 159 | { 160 | // secretKeyAES128.decrypt16( input + index ); 161 | blockDecrypt(&cipherInst, &keyDecrypt, input + index, 16, input + index); 162 | 163 | for ( byteIndex = 0; byteIndex < 16; byteIndex++ ) 164 | { 165 | if ( index + 16 == ( unsigned ) inputLength ) 166 | input[ index + byteIndex ] ^= input[ byteIndex ]; 167 | else 168 | input[ index + byteIndex ] ^= input[ index + 16 + byteIndex ]; 169 | } 170 | }; 171 | 172 | // Decrypt the first block 173 | //secretKeyAES128.decrypt16( input ); 174 | blockDecrypt(&cipherInst, &keyDecrypt, input, 16, input); 175 | 176 | // Read checksum 177 | #ifdef HOST_ENDIAN_IS_BIG 178 | checkSum = (unsigned int)input[0] | (unsigned int)(input[1]<<8) | 179 | (unsigned int)(input[2]<<16)|(unsigned int)(input[3]<<24); 180 | #else 181 | memcpy( ( char* ) & checkSum, input, sizeof( checkSum ) ); 182 | #endif 183 | 184 | // Read the pad size variable 185 | memcpy( ( char* ) & encodedPad, input + sizeof( randomChar ) + sizeof( checkSum ), sizeof( encodedPad ) ); 186 | 187 | // Ignore the high 4 bytes 188 | paddingBytes = encodedPad & 0x0F; 189 | 190 | 191 | // Get the data length 192 | *outputLength = inputLength - sizeof( randomChar ) - sizeof( checkSum ) - sizeof( encodedPad ) - paddingBytes; 193 | 194 | // Calculate the checksum on the data. 195 | checkSumCalculator.Add( input + sizeof( checkSum ), *outputLength + sizeof( randomChar ) + sizeof( encodedPad ) + paddingBytes ); 196 | 197 | if ( checkSum != checkSumCalculator.Get() ) 198 | return false; 199 | 200 | // Read the data 201 | if ( input == output ) 202 | memmove( output, input + sizeof( randomChar ) + sizeof( checkSum ) + sizeof( encodedPad ) + paddingBytes, *outputLength ); 203 | else 204 | memcpy( output, input + sizeof( randomChar ) + sizeof( checkSum ) + sizeof( encodedPad ) + paddingBytes, *outputLength ); 205 | 206 | 207 | return true; 208 | } 209 | -------------------------------------------------------------------------------- /Source/GetTime.cpp: -------------------------------------------------------------------------------- 1 | /// \file 2 | /// 3 | /// This file is part of RakNet Copyright 2003 Kevin Jenkins. 4 | /// 5 | /// Usage of RakNet is subject to the appropriate license agreement. 6 | /// Creative Commons Licensees are subject to the 7 | /// license found at 8 | /// http://creativecommons.org/licenses/by-nc/2.5/ 9 | /// Single application licensees are subject to the license found at 10 | /// http://www.rakkarsoft.com/SingleApplicationLicense.html 11 | /// Custom license users are subject to the terms therein. 12 | /// GPL license users are subject to the GNU General Public 13 | /// License as published by the Free 14 | /// Software Foundation; either version 2 of the License, or (at your 15 | /// option) any later version. 16 | 17 | #include "GetTime.h" 18 | #ifdef _COMPATIBILITY_1 19 | #include "Compatibility1Includes.h" // Developers of a certain platform will know what to do here. 20 | #elif defined(_WIN32) 21 | #include 22 | #elif defined(_COMPATIBILITY_2) 23 | #include "Compatibility2Includes.h" 24 | #include 25 | #include 26 | #else 27 | #include 28 | #include 29 | #endif 30 | 31 | using namespace RakNet; 32 | 33 | static bool initialized=false; 34 | #ifdef _WIN32 35 | static LARGE_INTEGER yo; 36 | #else 37 | static timeval initialTime; 38 | #endif 39 | 40 | RakNetTime RakNet::GetTime( void ) 41 | { 42 | if ( initialized == false ) 43 | { 44 | #ifdef _WIN32 45 | QueryPerformanceFrequency( &yo ); 46 | // The original code shifted right 10 bits 47 | //counts = yo.QuadPart >> 10; 48 | // It gives the wrong value since 2^10 is not 1000 49 | // counts = yo.QuadPart;// / 1000; 50 | #else 51 | gettimeofday( &initialTime, 0 ); 52 | #endif 53 | 54 | initialized = true; 55 | } 56 | 57 | #ifdef _WIN32 58 | LARGE_INTEGER PerfVal; 59 | 60 | QueryPerformanceCounter( &PerfVal ); 61 | 62 | return (RakNetTime)(PerfVal.QuadPart*1000 / yo.QuadPart); 63 | #else 64 | struct timeval tp; 65 | gettimeofday( &tp, 0 ); 66 | 67 | // Seconds to ms and microseconds to ms 68 | return ( tp.tv_sec - initialTime.tv_sec ) * 1000 + ( tp.tv_usec - initialTime.tv_usec ) / 1000; 69 | 70 | #endif 71 | } 72 | 73 | 74 | RakNetTimeNS RakNet::GetTimeNS( void ) 75 | { 76 | if ( initialized == false ) 77 | { 78 | #ifdef _WIN32 79 | QueryPerformanceFrequency( &yo ); 80 | // The original code shifted right 10 bits 81 | //counts = yo.QuadPart >> 10; 82 | // It gives the wrong value since 2^10 is not 1000 83 | // counts = yo.QuadPart;// / 1000; 84 | #else 85 | gettimeofday( &initialTime, 0 ); 86 | #endif 87 | 88 | initialized = true; 89 | } 90 | 91 | #ifdef _WIN32 92 | LARGE_INTEGER PerfVal; 93 | 94 | QueryPerformanceCounter( &PerfVal ); 95 | 96 | __int64 quotient, remainder; 97 | quotient=((PerfVal.QuadPart*1000) / yo.QuadPart); 98 | remainder=((PerfVal.QuadPart*1000) % yo.QuadPart); 99 | //return (PerfVal.QuadPart*1000 / (yo.QuadPart/1000)); 100 | return quotient*1000 + (remainder*1000 / yo.QuadPart); 101 | 102 | #else 103 | struct timeval tp; 104 | gettimeofday( &tp, 0 ); 105 | 106 | return ( tp.tv_sec - initialTime.tv_sec ) * (RakNetTimeNS) 1000000 + ( tp.tv_usec - initialTime.tv_usec ); 107 | 108 | #endif 109 | } 110 | -------------------------------------------------------------------------------- /Source/InternalPacketPool.cpp: -------------------------------------------------------------------------------- 1 | /// \file 2 | /// 3 | /// This file is part of RakNet Copyright 2003 Kevin Jenkins. 4 | /// 5 | /// Usage of RakNet is subject to the appropriate license agreement. 6 | /// Creative Commons Licensees are subject to the 7 | /// license found at 8 | /// http://creativecommons.org/licenses/by-nc/2.5/ 9 | /// Single application licensees are subject to the license found at 10 | /// http://www.rakkarsoft.com/SingleApplicationLicense.html 11 | /// Custom license users are subject to the terms therein. 12 | /// GPL license users are subject to the GNU General Public 13 | /// License as published by the Free 14 | /// Software Foundation; either version 2 of the License, or (at your 15 | /// option) any later version. 16 | 17 | #include "InternalPacketPool.h" 18 | #include 19 | 20 | using namespace RakNet; 21 | 22 | // open.mp's InternalPacketPool reimplementation. 23 | // Amir: Instead of relying on a super slow DataStructures::Queue pool, we allocate and deallocate in time of need. 24 | // This way since we know when deallocation is needed and we do it, we don't have to rely on ClearPool usage in ReliablityLayer::FreeThreadedMemory; 25 | // Because no InternalPacket is left to be cleared/deallocated anyway. 26 | 27 | InternalPacket* InternalPacketPool::GetPointer() 28 | { 29 | return new InternalPacket; 30 | } 31 | 32 | void InternalPacketPool::ReleasePointer(InternalPacket* p) 33 | { 34 | delete p; 35 | } 36 | -------------------------------------------------------------------------------- /Source/Makefile: -------------------------------------------------------------------------------- 1 | include $(BASE_DIR)/makefile.defs 2 | 3 | all: shared static 4 | 5 | shared: 6 | mkdir -p $(BASE_DIR)/Lib/linux/ 7 | $(CC) $(DEBUG) -I$(INCLUDE) -w -c *.cpp 8 | $(CC) $(DEBUG) -shared -Wl-soname,libraknet.so.2 -o $(BASE_DIR)/Lib/linux/libraknet.so.$(VERSION) *.o $(LIBS) 9 | 10 | static: 11 | mkdir -p $(BASE_DIR)/Lib/linux/ 12 | $(CC) $(DEBUG) -I$(INCLUDE) -w -c *.cpp 13 | $(AR) rcs $(BASE_DIR)/Lib/linux/libraknet.a *.o 14 | 15 | clean: 16 | rm -f core 17 | rm -f *.o 18 | rm -f $(BASE_DIR)/Lib/linux/libraknet.so.$(VERSION) 19 | rm -f $(BASE_DIR)/Lib/linux/linuxraknet.a 20 | -------------------------------------------------------------------------------- /Source/Makefile.am: -------------------------------------------------------------------------------- 1 | # Makefile.am 2 | # RakNet configure script 3 | SUBDIRS=Autopatcher RakVoice . 4 | 5 | lib_LTLIBRARIES=libRakNet.la 6 | 7 | 8 | #RakNet headers 9 | libRakNet_ladir=$(includedir)/RakNet 10 | libRakNet_la_HEADERS=\ 11 | AES128.h\ 12 | ArrayList.h\ 13 | AsynchronousFileIO.h\ 14 | BigTypes.h\ 15 | BinarySearchTree.h\ 16 | BitStream.h\ 17 | CheckSum.h\ 18 | ClientContextStruct.h\ 19 | DataBlockEncryptor.h\ 20 | DistributedNetworkObject.h\ 21 | DistributedNetworkObjectHeader.h\ 22 | DistributedNetworkObjectManager.h\ 23 | DistributedNetworkObjectStub.h\ 24 | EncodeClassName.h\ 25 | ExtendedOverlappedPool.h\ 26 | GetTime.h\ 27 | HuffmanEncodingTree.h\ 28 | HuffmanEncodingTreeFactory.h\ 29 | HuffmanEncodingTreeNode.h\ 30 | InternalPacket.h\ 31 | InternalPacketPool.h\ 32 | LinkedList.h\ 33 | MTUSize.h\ 34 | Multiplayer.h\ 35 | NetworkObject.h\ 36 | NetworkTypes.h\ 37 | PacketEnumerations.h\ 38 | PacketPool.h\ 39 | PacketPriority.h\ 40 | Queue.h\ 41 | QueueLinkedList.h\ 42 | RPCNode.h\ 43 | RSACrypt.h\ 44 | RakClient.h\ 45 | RakClientInterface.h\ 46 | RakNetStatistics.h\ 47 | RakNetworkFactory.h\ 48 | RakPeer.h\ 49 | RakPeerInterface.h\ 50 | RakServer.h\ 51 | RakServerInterface.h\ 52 | Rand.h\ 53 | ReliabilityLayer.h\ 54 | SHA1.h\ 55 | SimpleMutex.h\ 56 | SocketLayer.h\ 57 | StringCompressor.h\ 58 | Types.h 59 | 60 | #RakNet sources files 61 | libRakNet_la_SOURCES=\ 62 | AES128.cpp\ 63 | AsynchronousFileIO.cpp\ 64 | BitStream.cpp\ 65 | CheckSum.cpp\ 66 | DataBlockEncryptor.cpp\ 67 | DistributedNetworkObject.cpp\ 68 | DistributedNetworkObjectManager.cpp\ 69 | DistributedNetworkObjectStub.cpp\ 70 | EncodeClassName.cpp\ 71 | ExtendedOverlappedPool.cpp\ 72 | GetTime.cpp\ 73 | HuffmanEncodingTree.cpp\ 74 | HuffmanEncodingTreeFactory.cpp\ 75 | InternalPacketPool.cpp\ 76 | NetworkObject.cpp\ 77 | NetworkTypes.cpp\ 78 | PacketPool.cpp\ 79 | RPCNode.cpp\ 80 | RakClient.cpp\ 81 | RakNetStatistics.cpp\ 82 | RakNetworkFactory.cpp\ 83 | RakPeer.cpp\ 84 | RakServer.cpp\ 85 | Rand.cpp\ 86 | ReliabilityLayer.cpp\ 87 | SHA1.cpp\ 88 | SimpleMutex.cpp\ 89 | SocketLayer.cpp\ 90 | StringCompressor.cpp 91 | 92 | if BUILD_RAKVOICE 93 | 94 | if BUILD_MONOLITHIC 95 | libRakNet_la_LIBADD=\ 96 | Autopatcher/libRakNet_autopatcher.la\ 97 | RakVoice/libRakNet_voice.la 98 | else 99 | libRakNet_la_LIBADD=\ 100 | Autopatcher/libRakNet_autopatcher.la 101 | endif 102 | 103 | else 104 | libRakNet_la_LIBADD=\ 105 | Autopatcher/libRakNet_autopatcher.la 106 | endif 107 | -------------------------------------------------------------------------------- /Source/NetworkTypes.cpp: -------------------------------------------------------------------------------- 1 | /// \file 2 | /// 3 | /// This file is part of RakNet Copyright 2003 Kevin Jenkins. 4 | /// 5 | /// Usage of RakNet is subject to the appropriate license agreement. 6 | /// Creative Commons Licensees are subject to the 7 | /// license found at 8 | /// http://creativecommons.org/licenses/by-nc/2.5/ 9 | /// Single application licensees are subject to the license found at 10 | /// http://www.rakkarsoft.com/SingleApplicationLicense.html 11 | /// Custom license users are subject to the terms therein. 12 | /// GPL license users are subject to the GNU General Public 13 | /// License as published by the Free 14 | /// Software Foundation; either version 2 of the License, or (at your 15 | /// option) any later version. 16 | 17 | #include "NetworkTypes.h" 18 | #include 19 | #include 20 | 21 | #ifdef _COMPATIBILITY_1 22 | #include "Compatibility1Includes.h" 23 | #elif defined(_WIN32) 24 | // IP_DONTFRAGMENT is different between winsock 1 and winsock 2. Therefore, Winsock2.h must be linked againt Ws2_32.lib 25 | // winsock.h must be linked against WSock32.lib. If these two are mixed up the flag won't work correctly 26 | #include 27 | #include // itoa 28 | #else 29 | #include 30 | #include 31 | #include 32 | #endif 33 | 34 | using namespace RakNet; 35 | 36 | // Fast itoa from http://www.jb.man.ac.uk/~slowe/cpp/itoa.html for Linux since it seems like Linux doesn't support this function. 37 | // I modified it to remove the std dependencies. 38 | char* my_itoa( int value, char* result, int base ) { 39 | // check that the base if valid 40 | if (base < 2 || base > 16) { *result = 0; return result; } 41 | char* out = result; 42 | int quotient = value; 43 | 44 | int absQModB; 45 | 46 | do { 47 | // KevinJ - get rid of this dependency 48 | //*out = "0123456789abcdef"[ std::abs( quotient % base ) ]; 49 | absQModB=quotient % base; 50 | if (absQModB < 0) 51 | absQModB=-absQModB; 52 | *out = "0123456789abcdef"[ absQModB ]; 53 | ++out; 54 | quotient /= base; 55 | } while ( quotient ); 56 | 57 | // Only apply negative sign for base 10 58 | if ( value < 0 && base == 10) *out++ = '-'; 59 | 60 | // KevinJ - get rid of this dependency 61 | // std::reverse( result, out ); 62 | *out = 0; 63 | 64 | // KevinJ - My own reverse code 65 | char *start = result; 66 | char temp; 67 | out--; 68 | while (start < out) 69 | { 70 | temp=*start; 71 | *start=*out; 72 | *out=temp; 73 | start++; 74 | out--; 75 | } 76 | 77 | return result; 78 | } 79 | 80 | // Defaults to not in peer to peer mode for NetworkIDs. This only sends the localSystemId portion in the BitStream class 81 | // This is what you want for client/server, where the server assigns all NetworkIDs and it is unnecessary to transmit the full structure. 82 | // For peer to peer, this will transmit the playerId of the system that created the object in addition to localSystemId. This allows 83 | // Any system to create unique ids locally. 84 | // All systems must use the same value for this variable. 85 | bool RAK_DLL_EXPORT NetworkID::peerToPeerMode=false; 86 | 87 | bool PlayerID::operator==( const PlayerID& right ) const 88 | { 89 | return binaryAddress == right.binaryAddress && port == right.port; 90 | } 91 | 92 | bool PlayerID::operator!=( const PlayerID& right ) const 93 | { 94 | return binaryAddress != right.binaryAddress || port != right.port; 95 | } 96 | 97 | bool PlayerID::operator>( const PlayerID& right ) const 98 | { 99 | return ( ( binaryAddress > right.binaryAddress ) || ( ( binaryAddress == right.binaryAddress ) && ( port > right.port ) ) ); 100 | } 101 | 102 | bool PlayerID::operator<( const PlayerID& right ) const 103 | { 104 | return ( ( binaryAddress < right.binaryAddress ) || ( ( binaryAddress == right.binaryAddress ) && ( port < right.port ) ) ); 105 | } 106 | char *PlayerID::ToString(bool writePort) const 107 | { 108 | #ifdef _COMPATIBILITY_1 109 | return ""; 110 | #else 111 | static char str[22]; 112 | in_addr in; 113 | in.s_addr = binaryAddress; 114 | strcpy(str, inet_ntoa( in )); 115 | if (writePort) 116 | { 117 | strcat(str, ":"); 118 | #if (defined(__GNUC__) || defined(__GCCXML__)) 119 | my_itoa(port, str+strlen(str), 10); 120 | #else 121 | _itoa(port, str+strlen(str), 10); 122 | #endif 123 | } 124 | 125 | return (char*) str; 126 | #endif 127 | } 128 | void PlayerID::SetBinaryAddress(const char *str) 129 | { 130 | #ifdef _COMPATIBILITY_1 131 | binaryAddress=UNASSIGNED_PLAYER_ID.binaryAddress; 132 | #else 133 | binaryAddress=inet_addr(str); 134 | #endif 135 | } 136 | 137 | NetworkID& NetworkID::operator = ( const NetworkID& input ) 138 | { 139 | playerId = input.playerId; 140 | localSystemId = input.localSystemId; 141 | return *this; 142 | } 143 | 144 | bool NetworkID::operator==( const NetworkID& right ) const 145 | { 146 | if (NetworkID::peerToPeerMode) 147 | return playerId == right.playerId && localSystemId == right.localSystemId; 148 | else 149 | return localSystemId==right.localSystemId; 150 | } 151 | 152 | bool NetworkID::operator!=( const NetworkID& right ) const 153 | { 154 | if (NetworkID::peerToPeerMode) 155 | return playerId != right.playerId || localSystemId != right.localSystemId; 156 | else 157 | return localSystemId!=right.localSystemId; 158 | } 159 | 160 | bool NetworkID::operator>( const NetworkID& right ) const 161 | { 162 | if (NetworkID::peerToPeerMode) 163 | return ( ( playerId > right.playerId ) || ( ( playerId == right.playerId ) && ( localSystemId > right.localSystemId ) ) ); 164 | else 165 | return localSystemId>right.localSystemId; 166 | } 167 | 168 | bool NetworkID::operator<( const NetworkID& right ) const 169 | { 170 | if (NetworkID::peerToPeerMode) 171 | return ( ( playerId < right.playerId ) || ( ( playerId == right.playerId ) && ( localSystemId < right.localSystemId ) ) ); 172 | else 173 | return localSystemId : unreferenced formal parameter 27 | #endif 28 | void PluginInterface::OnAttach(RakPeerInterface *peer) 29 | { 30 | } 31 | #ifdef _MSC_VER 32 | #pragma warning( disable : 4100 ) // warning C4100: : unreferenced formal parameter 33 | #endif 34 | void PluginInterface::OnDetach(RakPeerInterface *peer) 35 | { 36 | } 37 | #ifdef _MSC_VER 38 | #pragma warning( disable : 4100 ) // warning C4100: : unreferenced formal parameter 39 | #endif 40 | void PluginInterface::OnInitialize(RakPeerInterface *peer) 41 | { 42 | } 43 | #ifdef _MSC_VER 44 | #pragma warning( disable : 4100 ) // warning C4100: : unreferenced formal parameter 45 | #endif 46 | void PluginInterface::Update(RakPeerInterface *peer) 47 | { 48 | } 49 | #ifdef _MSC_VER 50 | #pragma warning( disable : 4100 ) // warning C4100: : unreferenced formal parameter 51 | #endif 52 | PluginReceiveResult PluginInterface::OnReceive(RakPeerInterface *peer, Packet *packet) 53 | { 54 | return RR_CONTINUE_PROCESSING; 55 | } 56 | #ifdef _MSC_VER 57 | #pragma warning( disable : 4100 ) // warning C4100: : unreferenced formal parameter 58 | #endif 59 | void PluginInterface::OnDisconnect(RakPeerInterface *peer) 60 | { 61 | } 62 | #ifdef _MSC_VER 63 | #pragma warning( disable : 4100 ) // warning C4100: : unreferenced formal parameter 64 | #endif 65 | void PluginInterface::OnCloseConnection(RakPeerInterface *peer, PlayerID playerId) 66 | { 67 | } 68 | #ifdef _MSC_VER 69 | #pragma warning( disable : 4100 ) // warning C4100: : unreferenced formal parameter 70 | #endif 71 | void PluginInterface::OnDirectSocketSend(const char *data, const unsigned bitsUsed, PlayerID remoteSystemID) 72 | { 73 | } 74 | #ifdef _MSC_VER 75 | #pragma warning( disable : 4100 ) // warning C4100: : unreferenced formal parameter 76 | #endif 77 | void PluginInterface::OnDirectSocketReceive(const char *data, const unsigned bitsUsed, PlayerID remoteSystemID) 78 | { 79 | } 80 | #ifdef _MSC_VER 81 | #pragma warning( disable : 4100 ) // warning C4100: : unreferenced formal parameter 82 | #endif 83 | void PluginInterface::OnInternalPacket(InternalPacket *internalPacket, unsigned frameNumber, PlayerID remoteSystemID, RakNetTime time, bool isSend) 84 | { 85 | } 86 | 87 | #ifdef _MSC_VER 88 | #pragma warning( pop ) 89 | #endif 90 | -------------------------------------------------------------------------------- /Source/RPCMap.cpp: -------------------------------------------------------------------------------- 1 | /// \file 2 | /// 3 | /// This file is part of RakNet Copyright 2003 Kevin Jenkins. 4 | /// 5 | /// Usage of RakNet is subject to the appropriate license agreement. 6 | /// Creative Commons Licensees are subject to the 7 | /// license found at 8 | /// http://creativecommons.org/licenses/by-nc/2.5/ 9 | /// Single application licensees are subject to the license found at 10 | /// http://www.rakkarsoft.com/SingleApplicationLicense.html 11 | /// Custom license users are subject to the terms therein. 12 | /// GPL license users are subject to the GNU General Public 13 | /// License as published by the Free 14 | /// Software Foundation; either version 2 of the License, or (at your 15 | /// option) any later version. 16 | 17 | #include "RPCMap.h" 18 | #include 19 | 20 | using namespace RakNet; 21 | 22 | RPCMap::RPCMap() 23 | { 24 | } 25 | RPCMap::~RPCMap() 26 | { 27 | Clear(); 28 | } 29 | void RPCMap::Clear(void) 30 | { 31 | unsigned i; 32 | RPCNode *node; 33 | for (i=0; i < rpcSet.Size(); i++) 34 | { 35 | node=rpcSet[i]; 36 | if (node) 37 | { 38 | #if RPCID_STRING 39 | delete [] node->uniqueIdentifier; 40 | #endif 41 | delete node; 42 | } 43 | } 44 | rpcSet.Clear(); 45 | } 46 | RPCNode *RPCMap::GetNodeFromIndex(RPCIndex index) 47 | { 48 | if ((unsigned)index < rpcSet.Size()) 49 | return rpcSet[(unsigned)index]; 50 | return 0; 51 | } 52 | RPCNode *RPCMap::GetNodeFromFunctionName(RPCID uniqueIdentifier) 53 | { 54 | unsigned index; 55 | index=(unsigned)GetIndexFromFunctionName(uniqueIdentifier); 56 | if ((RPCIndex)index!=UNDEFINED_RPC_INDEX) 57 | return rpcSet[index]; 58 | return 0; 59 | } 60 | RPCIndex RPCMap::GetIndexFromFunctionName(RPCID uniqueIdentifier) 61 | { 62 | unsigned index; 63 | for (index=0; index < rpcSet.Size(); index++) 64 | if (rpcSet[index] && 65 | #if RPCID_STRING 66 | strcmp(rpcSet[index]->uniqueIdentifier, uniqueIdentifier)==0 67 | #else 68 | rpcSet[index]->uniqueIdentifier==uniqueIdentifier 69 | #endif 70 | ) 71 | return (RPCIndex) index; 72 | return UNDEFINED_RPC_INDEX; 73 | } 74 | 75 | // Called from the user thread for the local system 76 | void RPCMap::AddIdentifierWithFunction(RPCID uniqueIdentifier, void *functionPointer, bool isPointerToMember, void* extraPointer) 77 | { 78 | #ifdef _DEBUG 79 | RakAssert(rpcSet.Size()+1 < MAX_RPC_MAP_SIZE); // If this hits change the typedef of RPCIndex to use an unsigned short 80 | RakAssert(uniqueIdentifier); 81 | #if RPCID_STRING 82 | RakAssert(uniqueIdentifier[0]); 83 | #endif 84 | RakAssert(functionPointer); 85 | #endif 86 | 87 | unsigned index, existingNodeIndex; 88 | RPCNode *node; 89 | 90 | existingNodeIndex=GetIndexFromFunctionName(uniqueIdentifier); 91 | if ((RPCIndex)existingNodeIndex!=UNDEFINED_RPC_INDEX) // Insert at any free spot. 92 | { 93 | // Trying to insert an identifier at any free slot and that identifier already exists 94 | // The user should not insert nodes that already exist in the list 95 | 96 | // RakAssert(0); 97 | 98 | return; 99 | } 100 | 101 | node = new RPCNode; 102 | #if RPCID_STRING 103 | node->uniqueIdentifier = new char [strlen(uniqueIdentifier)+1]; 104 | strcpy(node->uniqueIdentifier, uniqueIdentifier); 105 | #else 106 | node->uniqueIdentifier = uniqueIdentifier; 107 | #endif 108 | node->functionPointer=functionPointer; 109 | node->isPointerToMember=isPointerToMember; 110 | node->extraPointer=extraPointer; 111 | 112 | // Insert into an empty spot if possible 113 | for (index=0; index < rpcSet.Size(); index++) 114 | { 115 | if (rpcSet[index]==0) 116 | { 117 | rpcSet.Replace(node, 0, index); 118 | return; 119 | } 120 | } 121 | 122 | rpcSet.Insert(node); // No empty spots available so just add to the end of the list 123 | 124 | } 125 | void RPCMap::AddIdentifierAtIndex(RPCID uniqueIdentifier, RPCIndex insertionIndex) 126 | { 127 | 128 | RakAssert(uniqueIdentifier); 129 | #if RPCID_STRING 130 | RakAssert(uniqueIdentifier[0]); 131 | #endif 132 | 133 | 134 | unsigned existingNodeIndex; 135 | RPCNode *node, *oldNode; 136 | 137 | existingNodeIndex=GetIndexFromFunctionName(uniqueIdentifier); 138 | 139 | if (existingNodeIndex==insertionIndex) 140 | return; // Already there 141 | 142 | if ((RPCIndex)existingNodeIndex!=UNDEFINED_RPC_INDEX) 143 | { 144 | // Delete the existing one 145 | oldNode=rpcSet[existingNodeIndex]; 146 | rpcSet[existingNodeIndex]=0; 147 | #if RPCID_STRING 148 | delete [] oldNode->uniqueIdentifier; 149 | #endif 150 | delete oldNode; 151 | } 152 | 153 | node = new RPCNode; 154 | #if RPCID_STRING 155 | node->uniqueIdentifier = new char [strlen(uniqueIdentifier)+1]; 156 | strcpy(node->uniqueIdentifier, uniqueIdentifier); 157 | #else 158 | node->uniqueIdentifier = uniqueIdentifier; 159 | #endif 160 | node->functionPointer=0; 161 | 162 | // Insert at a user specified spot 163 | if (insertionIndex < rpcSet.Size()) 164 | { 165 | // Overwrite what is there already 166 | oldNode=rpcSet[insertionIndex]; 167 | if (oldNode) 168 | { 169 | #if RPCID_STRING 170 | delete [] oldNode->uniqueIdentifier; 171 | #endif 172 | delete oldNode; 173 | } 174 | rpcSet[insertionIndex]=node; 175 | } 176 | else 177 | { 178 | // Insert after the end of the list and use 0 as a filler for the empty spots 179 | rpcSet.Replace(node, 0, insertionIndex); 180 | } 181 | } 182 | 183 | void RPCMap::RemoveNode(RPCID uniqueIdentifier) 184 | { 185 | unsigned index; 186 | index=GetIndexFromFunctionName(uniqueIdentifier); 187 | 188 | RakAssert(index!=UNDEFINED_RPC_INDEX); // If this hits then the user was removing an RPC call that wasn't currently registered 189 | 190 | RPCNode *node; 191 | node = rpcSet[index]; 192 | #if RPCID_STRING 193 | delete [] node->uniqueIdentifier; 194 | #endif 195 | delete node; 196 | rpcSet[index]=0; 197 | } 198 | 199 | -------------------------------------------------------------------------------- /Source/RakNetworkFactory.cpp: -------------------------------------------------------------------------------- 1 | /// \file 2 | /// 3 | /// This file is part of RakNet Copyright 2003 Kevin Jenkins. 4 | /// 5 | /// Usage of RakNet is subject to the appropriate license agreement. 6 | /// Creative Commons Licensees are subject to the 7 | /// license found at 8 | /// http://creativecommons.org/licenses/by-nc/2.5/ 9 | /// Single application licensees are subject to the license found at 10 | /// http://www.rakkarsoft.com/SingleApplicationLicense.html 11 | /// Custom license users are subject to the terms therein. 12 | /// GPL license users are subject to the GNU General Public 13 | /// License as published by the Free 14 | /// Software Foundation; either version 2 of the License, or (at your 15 | /// option) any later version. 16 | 17 | #include "RakNetworkFactory.h" 18 | #include "RakServerInterface.h" 19 | #include "RakClientInterface.h" 20 | #include "RakServer.h" 21 | #include "RakClient.h" 22 | #include "RakPeerInterface.h" 23 | #include "RakPeer.h" 24 | #include "ConsoleServer.h" 25 | #include "PacketLogger.h" 26 | #include "RakNetCommandParser.h" 27 | 28 | using namespace RakNet; 29 | 30 | RakClientInterface* RakNetworkFactory::GetRakClientInterface( void ) 31 | { 32 | return new RakClient; 33 | } 34 | RakServerInterface* RakNetworkFactory::GetRakServerInterface( void ) 35 | { 36 | return new RakServer; 37 | } 38 | RakPeerInterface* RakNetworkFactory::GetRakPeerInterface( void ) 39 | { 40 | return new RakPeer; 41 | } 42 | ConsoleServer* RakNetworkFactory::GetConsoleServer( void ) 43 | { 44 | return new ConsoleServer; 45 | } 46 | //ReplicaManager* RakNetworkFactory::GetReplicaManager( void ) 47 | //{ 48 | // return new ReplicaManager; 49 | //} 50 | //LogCommandParser* RakNetworkFactory::GetLogCommandParser( void ) 51 | //{ 52 | // return new LogCommandParser; 53 | //} 54 | //PacketLogger* RakNetworkFactory::GetPacketLogger( void ) 55 | //{ 56 | // return new PacketLogger; 57 | //} 58 | RakNetCommandParser* RakNetworkFactory::GetRakNetCommandParser( void ) 59 | { 60 | return new RakNetCommandParser; 61 | } 62 | //RakNetTransport* RakNetworkFactory::GetRakNetTransport( void ) 63 | //{ 64 | // return new RakNetTransport; 65 | //} 66 | //TelnetTransport* RakNetworkFactory::GetTelnetTransport( void ) 67 | //{ 68 | // return new TelnetTransport; 69 | //} 70 | //PacketConsoleLogger* RakNetworkFactory::GetPacketConsoleLogger( void ) 71 | //{ 72 | // return new PacketConsoleLogger; 73 | //} 74 | //PacketFileLogger* RakNetworkFactory::GetPacketFileLogger( void ) 75 | //{ 76 | // return new PacketFileLogger; 77 | //} 78 | //Router* RakNetworkFactory::GetRouter( void ) 79 | //{ 80 | // return new Router; 81 | //} 82 | //ConnectionGraph* RakNetworkFactory::GetConnectionGraph( void ) 83 | //{ 84 | // return new ConnectionGraph; 85 | //} 86 | void RakNetworkFactory::DestroyRakClientInterface( RakClientInterface* i ) 87 | { 88 | delete ( RakClient* ) i; 89 | } 90 | void RakNetworkFactory::DestroyRakServerInterface( RakServerInterface* i ) 91 | { 92 | delete ( RakServer* ) i; 93 | } 94 | void RakNetworkFactory::DestroyRakPeerInterface( RakPeerInterface* i ) 95 | { 96 | delete ( RakPeer* ) i; 97 | } 98 | void RakNetworkFactory::DestroyConsoleServer( ConsoleServer* i) 99 | { 100 | delete ( ConsoleServer* ) i; 101 | } 102 | //void RakNetworkFactory::DestroyReplicaManager( ReplicaManager* i) 103 | //{ 104 | // delete ( ReplicaManager* ) i; 105 | //} 106 | //void RakNetworkFactory::DestroyLogCommandParser( LogCommandParser* i) 107 | //{ 108 | // delete ( LogCommandParser* ) i; 109 | //} 110 | //void RakNetworkFactory::DestroyPacketLogger( PacketLogger* i) 111 | //{ 112 | // delete ( PacketLogger* ) i; 113 | //} 114 | void RakNetworkFactory::DestroyRakNetCommandParser( RakNetCommandParser* i ) 115 | { 116 | delete ( RakNetCommandParser* ) i; 117 | } 118 | //void RakNetworkFactory::DestroyRakNetTransport( RakNetTransport* i ) 119 | //{ 120 | // delete ( RakNetTransport* ) i; 121 | //} 122 | //void RakNetworkFactory::DestroyTelnetTransport( TelnetTransport* i ) 123 | //{ 124 | // delete ( TelnetTransport* ) i; 125 | //} 126 | //void RakNetworkFactory::DestroyPacketConsoleLogger( PacketConsoleLogger* i ) 127 | //{ 128 | // delete ( PacketConsoleLogger* ) i; 129 | //} 130 | //void RakNetworkFactory::DestroyPacketFileLogger( PacketFileLogger* i ) 131 | //{ 132 | // delete ( PacketFileLogger* ) i; 133 | //} 134 | //void RakNetworkFactory::DestroyRouter( Router* i ) 135 | //{ 136 | // delete ( Router* ) i; 137 | //} 138 | //void RakNetworkFactory::DestroyConnectionGraph( ConnectionGraph* i ) 139 | //{ 140 | // delete ( ConnectionGraph* ) i; 141 | //} 142 | -------------------------------------------------------------------------------- /Source/RakSleep.cpp: -------------------------------------------------------------------------------- 1 | #if defined(_COMPATIBILITY_1) 2 | #include "Compatibility1Includes.h" 3 | #elif defined(_WIN32) 4 | #include // Sleep 5 | #elif defined(_COMPATIBILITY_2) 6 | #include "Compatibility2Includes.h" 7 | #else 8 | #include // usleep 9 | #endif 10 | 11 | namespace RakNet 12 | { 13 | void RakSleep(unsigned int ms) 14 | { 15 | #ifdef _WIN32 16 | Sleep(ms); 17 | #else 18 | usleep(ms * 1000); 19 | #endif 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Source/Rand.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Grabbed by Kevin from http://www.math.keio.ac.jp/~matumoto/cokus.c 4 | * This is the ``Mersenne Twister'' random number generator MT19937, which 5 | * generates pseudorandom integers uniformly distributed in 0..(2^32 - 1) 6 | * starting from any odd seed in 0..(2^32 - 1). This version is a recode 7 | * by Shawn Cokus (Cokus@math.washington.edu) on March 8, 1998 of a version by 8 | * Takuji Nishimura (who had suggestions from Topher Cooper and Marc Rieffel in 9 | * July-August 1997). 10 | * 11 | * Effectiveness of the recoding (on Goedel2.math.washington.edu, a DEC Alpha 12 | * running OSF/1) using GCC -O3 as a compiler: before recoding: 51.6 sec. to 13 | * generate 300 million random numbers; after recoding: 24.0 sec. for the same 14 | * (i.e., 46.5% of original time), so speed is now about 12.5 million random 15 | * number generations per second on this machine. 16 | * 17 | * According to the URL 18 | * (and paraphrasing a bit in places), the Mersenne Twister is ``designed 19 | * with consideration of the flaws of various existing generators,'' has 20 | * a period of 2^19937 - 1, gives a sequence that is 623-dimensionally 21 | * equidistributed, and ``has passed many stringent tests, including the 22 | * die-hard test of G. Marsaglia and the load test of P. Hellekalek and 23 | * S. Wegenkittl.'' It is efficient in memory usage (typically using 2506 24 | * to 5012 bytes of static data, depending on data type sizes, and the code 25 | * is quite short as well). It generates random numbers in batches of 624 26 | * at a time, so the caching and pipelining of modern systems is exploited. 27 | * It is also divide- and mod-free. 28 | * 29 | * This library is free software; you can redistribute it and/or modify it 30 | * under the terms of the GNU Library General Public License as published by 31 | * the Free Software Foundation (either version 2 of the License or, at your 32 | * option, any later version). This library is distributed in the hope that 33 | * it will be useful, but WITHOUT ANY WARRANTY, without even the implied 34 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 35 | * the GNU Library General Public License for more details. You should have 36 | * received a copy of the GNU Library General Public License along with this 37 | * library; if not, write to the Free Software Foundation, Inc., 59 Temple 38 | * Place, Suite 330, Boston, MA 02111-1307, USA. 39 | * 40 | * The code as Shawn received it included the following notice: 41 | * 42 | * Copyright (C) 1997 Makoto Matsumoto and Takuji Nishimura. When 43 | * you use this, send an e-mail to with 44 | * an appropriate reference to your work. 45 | * 46 | * It would be nice to CC: when you write. 47 | */ 48 | 49 | #include 50 | #include 51 | 52 | namespace RakNet 53 | { 54 | // 55 | // uint32 must be an unsigned integer type capable of holding at least 32 56 | // bits; exactly 32 should be fastest, but 64 is better on an Alpha with 57 | // GCC at -O3 optimization so try your options and see what's best for you 58 | // 59 | 60 | //typedef unsigned int uint32; 61 | 62 | #define N (624) // length of state vector 63 | #define M (397) // a period parameter 64 | #define K (0x9908B0DFU) // a magic constant 65 | #define hiBit(u) ((u) & 0x80000000U) // mask all but highest bit of u 66 | #define loBit(u) ((u) & 0x00000001U) // mask all but lowest bit of u 67 | #define loBits(u) ((u) & 0x7FFFFFFFU) // mask the highest bit of u 68 | #define mixBits(u, v) (hiBit(u)|loBits(v)) // move hi bit of u to hi bit of v 69 | 70 | static unsigned int state[N + 1]; // state vector + 1 extra to not violate ANSI C 71 | static unsigned int *next; // next random value is computed from here 72 | static int left = -1; // can *next++ this many times before reloading 73 | 74 | 75 | void seedMT(unsigned int seed) // Defined in cokus_c.c 76 | { 77 | // 78 | // We initialize state[0..(N-1)] via the generator 79 | // 80 | // x_new = (69069 * x_old) mod 2^32 81 | // 82 | // from Line 15 of Table 1, p. 106, Sec. 3.3.4 of Knuth's 83 | // _The Art of Computer Programming_, Volume 2, 3rd ed. 84 | // 85 | // Notes (SJC): I do not know what the initial state requirements 86 | // of the Mersenne Twister are, but it seems this seeding generator 87 | // could be better. It achieves the maximum period for its modulus 88 | // (2^30) iff x_initial is odd (p. 20-21, Sec. 3.2.1.2, Knuth); if 89 | // x_initial can be even, you have sequences like 0, 0, 0, ...; 90 | // 2^31, 2^31, 2^31, ...; 2^30, 2^30, 2^30, ...; 2^29, 2^29 + 2^31, 91 | // 2^29, 2^29 + 2^31, ..., etc. so I force seed to be odd below. 92 | // 93 | // Even if x_initial is odd, if x_initial is 1 mod 4 then 94 | // 95 | // the lowest bit of x is always 1, 96 | // the next-to-lowest bit of x is always 0, 97 | // the 2nd-from-lowest bit of x alternates ... 0 1 0 1 0 1 0 1 ... , 98 | // the 3rd-from-lowest bit of x 4-cycles ... 0 1 1 0 0 1 1 0 ... , 99 | // the 4th-from-lowest bit of x has the 8-cycle ... 0 0 0 1 1 1 1 0 ... , 100 | // ... 101 | // 102 | // and if x_initial is 3 mod 4 then 103 | // 104 | // the lowest bit of x is always 1, 105 | // the next-to-lowest bit of x is always 1, 106 | // the 2nd-from-lowest bit of x alternates ... 0 1 0 1 0 1 0 1 ... , 107 | // the 3rd-from-lowest bit of x 4-cycles ... 0 0 1 1 0 0 1 1 ... , 108 | // the 4th-from-lowest bit of x has the 8-cycle ... 0 0 1 1 1 1 0 0 ... , 109 | // ... 110 | // 111 | // The generator's potency (min. s>=0 with (69069-1)^s = 0 mod 2^32) is 112 | // 16, which seems to be alright by p. 25, Sec. 3.2.1.3 of Knuth. It 113 | // also does well in the dimension 2..5 spectral tests, but it could be 114 | // better in dimension 6 (Line 15, Table 1, p. 106, Sec. 3.3.4, Knuth). 115 | // 116 | // Note that the random number user does not see the values generated 117 | // here directly since reloadMT() will always munge them first, so maybe 118 | // none of all of this matters. In fact, the seed values made here could 119 | // even be extra-special desirable if the Mersenne Twister theory says 120 | // so-- that's why the only change I made is to restrict to odd seeds. 121 | // 122 | 123 | unsigned int x = (seed | 1U) & 0xFFFFFFFFU, *s = state; 124 | int j; 125 | 126 | for (left = 0, *s++ = x, j = N; --j; 127 | *s++ = (x *= 69069U) & 0xFFFFFFFFU) 128 | 129 | ; 130 | } 131 | 132 | 133 | unsigned int reloadMT(void) 134 | { 135 | unsigned int * p0 = state, *p2 = state + 2, *pM = state + M, s0, s1; 136 | int j; 137 | 138 | if (left < -1) 139 | seedMT(4357U); 140 | 141 | left = N - 1, next = state + 1; 142 | 143 | for (s0 = state[0], s1 = state[1], j = N - M + 1; --j; s0 = s1, s1 = *p2++) 144 | * p0++ = *pM++ ^ (mixBits(s0, s1) >> 1) ^ (loBit(s1) ? K : 0U); 145 | 146 | for (pM = state, j = M; --j; s0 = s1, s1 = *p2++) 147 | * p0++ = *pM++ ^ (mixBits(s0, s1) >> 1) ^ (loBit(s1) ? K : 0U); 148 | 149 | s1 = state[0], *p0 = *pM ^ (mixBits(s0, s1) >> 1) ^ (loBit(s1) ? K : 0U); 150 | 151 | s1 ^= (s1 >> 11); 152 | 153 | s1 ^= (s1 << 7) & 0x9D2C5680U; 154 | 155 | s1 ^= (s1 << 15) & 0xEFC60000U; 156 | 157 | return (s1 ^ (s1 >> 18)); 158 | } 159 | 160 | 161 | unsigned int randomMT(void) 162 | { 163 | unsigned int y; 164 | 165 | if (--left < 0) 166 | return (reloadMT()); 167 | 168 | y = *next++; 169 | 170 | y ^= (y >> 11); 171 | 172 | y ^= (y << 7) & 0x9D2C5680U; 173 | 174 | y ^= (y << 15) & 0xEFC60000U; 175 | 176 | return (y ^ (y >> 18)); 177 | 178 | // This change made so the value returned is in the same range as what rand() returns 179 | // return(y ^ (y >> 18)) % 32767; 180 | } 181 | 182 | float frandomMT(void) 183 | { 184 | return (float)((double)randomMT() / 4294967296.0); 185 | } 186 | 187 | /* 188 | int main(void) 189 | { 190 | int j; 191 | 192 | // you can seed with any uint32, but the best are odds in 0..(2^32 - 1) 193 | 194 | seedMT(4357U); 195 | 196 | // print the first 2,002 random numbers seven to a line as an example 197 | 198 | for(j=0; j<2002; j++) 199 | printf(" %10lu%s", (unsigned int) randomMT(), (j%7)==6 ? "\n" : ""); 200 | 201 | return(EXIT_SUCCESS); 202 | } 203 | 204 | */ 205 | } 206 | -------------------------------------------------------------------------------- /Source/SHA1.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @brief SHA-1 Hash key computation 3 | * 4 | * 100% free public domain implementation of the SHA-1 5 | * algorithm by Dominik Reichl 6 | * 7 | * 8 | * === Test Vectors (from FIPS PUB 180-1) === 9 | * 10 | * "abc" 11 | * A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D 12 | * 13 | * "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" 14 | * 84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1 15 | * 16 | * A million repetitions of "a" 17 | * 34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F 18 | */ 19 | 20 | 21 | #include "SHA1.h" 22 | #include 23 | 24 | using namespace RakNet; 25 | 26 | CSHA1::CSHA1() 27 | { 28 | Reset(); 29 | } 30 | 31 | CSHA1::~CSHA1() 32 | { 33 | Reset(); 34 | } 35 | 36 | 37 | void CSHA1::Reset() 38 | { 39 | // SHA1 initialization constants 40 | m_state[ 0 ] = 0x67452301; 41 | m_state[ 1 ] = 0xEFCDAB89; 42 | m_state[ 2 ] = 0x98BADCFE; 43 | m_state[ 3 ] = 0x10325476; 44 | m_state[ 4 ] = 0xC3D2E1F0; 45 | 46 | m_count[ 0 ] = 0; 47 | m_count[ 1 ] = 0; 48 | } 49 | 50 | void CSHA1::Transform( unsigned int state[ 5 ], unsigned char buffer[ 64 ] ) 51 | { 52 | unsigned int a = 0, b = 0, c = 0, d = 0, e = 0; 53 | 54 | SHA1_WORKSPACE_BLOCK* block; 55 | // static unsigned char workspace[64]; 56 | block = ( SHA1_WORKSPACE_BLOCK * ) workspace; 57 | memcpy( block, buffer, 64 ); 58 | 59 | // Copy state[] to working vars 60 | a = state[ 0 ]; 61 | b = state[ 1 ]; 62 | c = state[ 2 ]; 63 | d = state[ 3 ]; 64 | e = state[ 4 ]; 65 | 66 | // 4 rounds of 20 operations each. Loop unrolled. 67 | R0( a, b, c, d, e, 0 ); 68 | R0( e, a, b, c, d, 1 ); 69 | R0( d, e, a, b, c, 2 ); 70 | R0( c, d, e, a, b, 3 ); 71 | R0( b, c, d, e, a, 4 ); 72 | R0( a, b, c, d, e, 5 ); 73 | R0( e, a, b, c, d, 6 ); 74 | R0( d, e, a, b, c, 7 ); 75 | R0( c, d, e, a, b, 8 ); 76 | R0( b, c, d, e, a, 9 ); 77 | R0( a, b, c, d, e, 10 ); 78 | R0( e, a, b, c, d, 11 ); 79 | R0( d, e, a, b, c, 12 ); 80 | R0( c, d, e, a, b, 13 ); 81 | R0( b, c, d, e, a, 14 ); 82 | R0( a, b, c, d, e, 15 ); 83 | R1( e, a, b, c, d, 16 ); 84 | R1( d, e, a, b, c, 17 ); 85 | R1( c, d, e, a, b, 18 ); 86 | R1( b, c, d, e, a, 19 ); 87 | R2( a, b, c, d, e, 20 ); 88 | R2( e, a, b, c, d, 21 ); 89 | R2( d, e, a, b, c, 22 ); 90 | R2( c, d, e, a, b, 23 ); 91 | R2( b, c, d, e, a, 24 ); 92 | R2( a, b, c, d, e, 25 ); 93 | R2( e, a, b, c, d, 26 ); 94 | R2( d, e, a, b, c, 27 ); 95 | R2( c, d, e, a, b, 28 ); 96 | R2( b, c, d, e, a, 29 ); 97 | R2( a, b, c, d, e, 30 ); 98 | R2( e, a, b, c, d, 31 ); 99 | R2( d, e, a, b, c, 32 ); 100 | R2( c, d, e, a, b, 33 ); 101 | R2( b, c, d, e, a, 34 ); 102 | R2( a, b, c, d, e, 35 ); 103 | R2( e, a, b, c, d, 36 ); 104 | R2( d, e, a, b, c, 37 ); 105 | R2( c, d, e, a, b, 38 ); 106 | R2( b, c, d, e, a, 39 ); 107 | R3( a, b, c, d, e, 40 ); 108 | R3( e, a, b, c, d, 41 ); 109 | R3( d, e, a, b, c, 42 ); 110 | R3( c, d, e, a, b, 43 ); 111 | R3( b, c, d, e, a, 44 ); 112 | R3( a, b, c, d, e, 45 ); 113 | R3( e, a, b, c, d, 46 ); 114 | R3( d, e, a, b, c, 47 ); 115 | R3( c, d, e, a, b, 48 ); 116 | R3( b, c, d, e, a, 49 ); 117 | R3( a, b, c, d, e, 50 ); 118 | R3( e, a, b, c, d, 51 ); 119 | R3( d, e, a, b, c, 52 ); 120 | R3( c, d, e, a, b, 53 ); 121 | R3( b, c, d, e, a, 54 ); 122 | R3( a, b, c, d, e, 55 ); 123 | R3( e, a, b, c, d, 56 ); 124 | R3( d, e, a, b, c, 57 ); 125 | R3( c, d, e, a, b, 58 ); 126 | R3( b, c, d, e, a, 59 ); 127 | R4( a, b, c, d, e, 60 ); 128 | R4( e, a, b, c, d, 61 ); 129 | R4( d, e, a, b, c, 62 ); 130 | R4( c, d, e, a, b, 63 ); 131 | R4( b, c, d, e, a, 64 ); 132 | R4( a, b, c, d, e, 65 ); 133 | R4( e, a, b, c, d, 66 ); 134 | R4( d, e, a, b, c, 67 ); 135 | R4( c, d, e, a, b, 68 ); 136 | R4( b, c, d, e, a, 69 ); 137 | R4( a, b, c, d, e, 70 ); 138 | R4( e, a, b, c, d, 71 ); 139 | R4( d, e, a, b, c, 72 ); 140 | R4( c, d, e, a, b, 73 ); 141 | R4( b, c, d, e, a, 74 ); 142 | R4( a, b, c, d, e, 75 ); 143 | R4( e, a, b, c, d, 76 ); 144 | R4( d, e, a, b, c, 77 ); 145 | R4( c, d, e, a, b, 78 ); 146 | R4( b, c, d, e, a, 79 ); 147 | 148 | // Add the working vars back into state[] 149 | state[ 0 ] += a; 150 | state[ 1 ] += b; 151 | state[ 2 ] += c; 152 | state[ 3 ] += d; 153 | state[ 4 ] += e; 154 | 155 | // Wipe variables 156 | a = 0; 157 | b = 0; 158 | c = 0; 159 | d = 0; 160 | e = 0; 161 | } 162 | 163 | // Use this function to hash in binary data and strings 164 | void CSHA1::Update( unsigned char* data, unsigned int len ) 165 | { 166 | unsigned int i = 0, j = 0; 167 | 168 | j = ( m_count[ 0 ] >> 3 ) & 63; 169 | 170 | if ( ( m_count[ 0 ] += len << 3 ) < ( len << 3 ) ) 171 | m_count[ 1 ] ++; 172 | 173 | m_count[ 1 ] += ( len >> 29 ); 174 | 175 | if ( ( j + len ) > 63 ) 176 | { 177 | memcpy( &m_buffer[ j ], data, ( i = 64 - j ) ); 178 | Transform( m_state, m_buffer ); 179 | 180 | for ( ; i + 63 < len; i += 64 ) 181 | { 182 | Transform( m_state, &data[ i ] ); 183 | } 184 | 185 | j = 0; 186 | } 187 | 188 | else 189 | i = 0; 190 | 191 | memcpy( &m_buffer[ j ], &data[ i ], len - i ); 192 | } 193 | 194 | // Hash in file contents 195 | bool CSHA1::HashFile( char *szFileName ) 196 | { 197 | unsigned long ulFileSize = 0, ulRest = 0, ulBlocks = 0; 198 | unsigned long i = 0; 199 | unsigned char uData[ MAX_FILE_READ_BUFFER ]; 200 | FILE *fIn = NULL; 201 | 202 | if ( ( fIn = fopen( szFileName, "rb" ) ) == NULL ) 203 | return ( false ); 204 | 205 | fseek( fIn, 0, SEEK_END ); 206 | 207 | ulFileSize = ftell( fIn ); 208 | 209 | fseek( fIn, 0, SEEK_SET ); 210 | 211 | // This is faster 212 | div_t temp; 213 | 214 | temp = div( ulFileSize, MAX_FILE_READ_BUFFER ); 215 | 216 | ulRest = temp.rem; 217 | 218 | ulBlocks = temp.quot; 219 | 220 | // ulRest = ulFileSize % MAX_FILE_READ_BUFFER; 221 | // ulBlocks = ulFileSize / MAX_FILE_READ_BUFFER; 222 | 223 | for ( i = 0; i < ulBlocks; i++ ) 224 | { 225 | fread( uData, 1, MAX_FILE_READ_BUFFER, fIn ); 226 | Update( uData, MAX_FILE_READ_BUFFER ); 227 | } 228 | 229 | if ( ulRest != 0 ) 230 | { 231 | fread( uData, 1, ulRest, fIn ); 232 | Update( uData, ulRest ); 233 | } 234 | 235 | fclose( fIn ); 236 | fIn = NULL; 237 | 238 | return ( true ); 239 | } 240 | 241 | void CSHA1::Final() 242 | { 243 | unsigned int i = 0; 244 | unsigned char finalcount[ 8 ] = 245 | { 246 | 0, 0, 0, 0, 0, 0, 0, 0 247 | }; 248 | 249 | for ( i = 0; i < 8; i++ ) 250 | finalcount[ i ] = (unsigned char) ( ( m_count[ ( i >= 4 ? 0 : 1 ) ] 251 | >> ( ( 3 - ( i & 3 ) ) * 8 ) ) & 255 ); // Endian independent 252 | 253 | Update( ( unsigned char * ) "\200", 1 ); 254 | 255 | while ( ( m_count[ 0 ] & 504 ) != 448 ) 256 | Update( ( unsigned char * ) "\0", 1 ); 257 | 258 | Update( finalcount, 8 ); // Cause a SHA1Transform() 259 | 260 | for ( i = 0; i < 20; i++ ) 261 | { 262 | m_digest[ i ] = (unsigned char) ( ( m_state[ i >> 2 ] >> ( ( 3 - ( i & 3 ) ) * 8 ) ) & 255 ); 263 | } 264 | 265 | // Wipe variables for security reasons 266 | i = 0; 267 | 268 | memset( m_buffer, 0, 64 ); 269 | 270 | memset( m_state, 0, 20 ); 271 | 272 | memset( m_count, 0, 8 ); 273 | 274 | memset( finalcount, 0, 8 ); 275 | 276 | Transform( m_state, m_buffer ); 277 | } 278 | 279 | // Get the final hash as a pre-formatted string 280 | void CSHA1::ReportHash( char *szReport, unsigned char uReportType ) 281 | { 282 | unsigned char i = 0; 283 | char szTemp[ 4 ]; 284 | 285 | if ( uReportType == REPORT_HEX ) 286 | { 287 | sprintf( szTemp, "%02X", m_digest[ 0 ] ); 288 | strcat( szReport, szTemp ); 289 | 290 | for ( i = 1; i < 20; i++ ) 291 | { 292 | sprintf( szTemp, " %02X", m_digest[ i ] ); 293 | strcat( szReport, szTemp ); 294 | } 295 | } 296 | 297 | else 298 | if ( uReportType == REPORT_DIGIT ) 299 | { 300 | sprintf( szTemp, "%u", m_digest[ 0 ] ); 301 | strcat( szReport, szTemp ); 302 | 303 | for ( i = 1; i < 20; i++ ) 304 | { 305 | sprintf( szTemp, " %u", m_digest[ i ] ); 306 | strcat( szReport, szTemp ); 307 | } 308 | } 309 | 310 | else 311 | strcpy( szReport, "Error: Unknown report type!" ); 312 | } 313 | 314 | // Get the raw message digest 315 | void CSHA1::GetHash( unsigned char *uDest ) 316 | { 317 | memcpy( uDest, m_digest, 20 ); 318 | } 319 | 320 | // Get the raw message digest 321 | // Added by Kevin to be quicker 322 | unsigned char * CSHA1::GetHash( void ) const 323 | { 324 | return ( unsigned char * ) m_digest; 325 | } 326 | -------------------------------------------------------------------------------- /Source/SimpleMutex.cpp: -------------------------------------------------------------------------------- 1 | /// \file 2 | /// 3 | /// This file is part of RakNet Copyright 2003 Kevin Jenkins. 4 | /// 5 | /// Usage of RakNet is subject to the appropriate license agreement. 6 | /// Creative Commons Licensees are subject to the 7 | /// license found at 8 | /// http://creativecommons.org/licenses/by-nc/2.5/ 9 | /// Single application licensees are subject to the license found at 10 | /// http://www.rakkarsoft.com/SingleApplicationLicense.html 11 | /// Custom license users are subject to the terms therein. 12 | /// GPL license users are subject to the GNU General Public 13 | /// License as published by the Free 14 | /// Software Foundation; either version 2 of the License, or (at your 15 | /// option) any later version. 16 | 17 | #include "SimpleMutex.h" 18 | #include "RakAssert.h" 19 | 20 | using namespace RakNet; 21 | 22 | SimpleMutex::SimpleMutex() 23 | { 24 | #ifdef _WIN32 25 | // hMutex = CreateMutex(NULL, FALSE, 0); 26 | // RakAssert(hMutex); 27 | InitializeCriticalSection(&criticalSection); 28 | #else 29 | int error = pthread_mutex_init(&hMutex, 0); 30 | RakAssert(error==0); 31 | #endif 32 | } 33 | 34 | SimpleMutex::~SimpleMutex() 35 | { 36 | #ifdef _WIN32 37 | // CloseHandle(hMutex); 38 | DeleteCriticalSection(&criticalSection); 39 | #else 40 | pthread_mutex_destroy(&hMutex); 41 | #endif 42 | } 43 | 44 | #ifdef _WIN32 45 | #ifdef _DEBUG 46 | #include 47 | #endif 48 | #endif 49 | 50 | void SimpleMutex::Lock(void) 51 | { 52 | #ifdef _WIN32 53 | /* 54 | DWORD d = WaitForSingleObject(hMutex, INFINITE); 55 | #ifdef _DEBUG 56 | if (d==WAIT_FAILED) 57 | { 58 | LPVOID messageBuffer; 59 | FormatMessage( 60 | FORMAT_MESSAGE_ALLOCATE_BUFFER | 61 | FORMAT_MESSAGE_FROM_SYSTEM | 62 | FORMAT_MESSAGE_IGNORE_INSERTS, 63 | NULL, 64 | GetLastError(), 65 | MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language 66 | (LPTSTR) &messageBuffer, 67 | 0, 68 | NULL 69 | ); 70 | // Process any inserts in messageBuffer. 71 | // ... 72 | // Display the string. 73 | //MessageBox( NULL, (LPCTSTR)messageBuffer, "Error", MB_OK | MB_ICONINFORMATION ); 74 | printf("SimpleMutex error: %s", messageBuffer); 75 | // Free the buffer. 76 | LocalFree( messageBuffer ); 77 | 78 | } 79 | 80 | RakAssert(d==WAIT_OBJECT_0); 81 | */ 82 | EnterCriticalSection(&criticalSection); 83 | 84 | #else 85 | int error = pthread_mutex_lock(&hMutex); 86 | RakAssert(error==0); 87 | #endif 88 | } 89 | 90 | void SimpleMutex::Unlock(void) 91 | { 92 | #ifdef _WIN32 93 | // ReleaseMutex(hMutex); 94 | LeaveCriticalSection(&criticalSection); 95 | #else 96 | int error = pthread_mutex_unlock(&hMutex); 97 | RakAssert(error==0); 98 | #endif 99 | } 100 | 101 | -------------------------------------------------------------------------------- /Source/StringCompressor.cpp: -------------------------------------------------------------------------------- 1 | /// \file 2 | /// 3 | /// This file is part of RakNet Copyright 2003 Kevin Jenkins. 4 | /// 5 | /// Usage of RakNet is subject to the appropriate license agreement. 6 | /// Creative Commons Licensees are subject to the 7 | /// license found at 8 | /// http://creativecommons.org/licenses/by-nc/2.5/ 9 | /// Single application licensees are subject to the license found at 10 | /// http://www.rakkarsoft.com/SingleApplicationLicense.html 11 | /// Custom license users are subject to the terms therein. 12 | /// GPL license users are subject to the GNU General Public 13 | /// License as published by the Free 14 | /// Software Foundation; either version 2 of the License, or (at your 15 | /// option) any later version. 16 | 17 | #include "StringCompressor.h" 18 | #include "DS_HuffmanEncodingTree.h" 19 | #include "BitStream.h" 20 | #include 21 | #include 22 | #include 23 | 24 | using namespace RakNet; 25 | 26 | StringCompressor* StringCompressor::instance=0; 27 | int StringCompressor::referenceCount=0; 28 | 29 | void StringCompressor::AddReference(void) 30 | { 31 | if (++referenceCount==1) 32 | { 33 | instance = new StringCompressor; 34 | } 35 | } 36 | void StringCompressor::RemoveReference(void) 37 | { 38 | RakAssert(referenceCount > 0); 39 | 40 | if (referenceCount > 0) 41 | { 42 | if (--referenceCount==0) 43 | { 44 | delete instance; 45 | instance=0; 46 | } 47 | } 48 | } 49 | 50 | StringCompressor* StringCompressor::Instance(void) 51 | { 52 | return instance; 53 | } 54 | 55 | unsigned int englishCharacterFrequencies[ 256 ] = 56 | { 57 | 0, 58 | 0, 59 | 0, 60 | 0, 61 | 0, 62 | 0, 63 | 0, 64 | 0, 65 | 0, 66 | 0, 67 | 722, 68 | 0, 69 | 0, 70 | 2, 71 | 0, 72 | 0, 73 | 0, 74 | 0, 75 | 0, 76 | 0, 77 | 0, 78 | 0, 79 | 0, 80 | 0, 81 | 0, 82 | 0, 83 | 0, 84 | 0, 85 | 0, 86 | 0, 87 | 0, 88 | 0, 89 | 11084, 90 | 58, 91 | 63, 92 | 1, 93 | 0, 94 | 31, 95 | 0, 96 | 317, 97 | 64, 98 | 64, 99 | 44, 100 | 0, 101 | 695, 102 | 62, 103 | 980, 104 | 266, 105 | 69, 106 | 67, 107 | 56, 108 | 7, 109 | 73, 110 | 3, 111 | 14, 112 | 2, 113 | 69, 114 | 1, 115 | 167, 116 | 9, 117 | 1, 118 | 2, 119 | 25, 120 | 94, 121 | 0, 122 | 195, 123 | 139, 124 | 34, 125 | 96, 126 | 48, 127 | 103, 128 | 56, 129 | 125, 130 | 653, 131 | 21, 132 | 5, 133 | 23, 134 | 64, 135 | 85, 136 | 44, 137 | 34, 138 | 7, 139 | 92, 140 | 76, 141 | 147, 142 | 12, 143 | 14, 144 | 57, 145 | 15, 146 | 39, 147 | 15, 148 | 1, 149 | 1, 150 | 1, 151 | 2, 152 | 3, 153 | 0, 154 | 3611, 155 | 845, 156 | 1077, 157 | 1884, 158 | 5870, 159 | 841, 160 | 1057, 161 | 2501, 162 | 3212, 163 | 164, 164 | 531, 165 | 2019, 166 | 1330, 167 | 3056, 168 | 4037, 169 | 848, 170 | 47, 171 | 2586, 172 | 2919, 173 | 4771, 174 | 1707, 175 | 535, 176 | 1106, 177 | 152, 178 | 1243, 179 | 100, 180 | 0, 181 | 2, 182 | 0, 183 | 10, 184 | 0, 185 | 0, 186 | 0, 187 | 0, 188 | 0, 189 | 0, 190 | 0, 191 | 0, 192 | 0, 193 | 0, 194 | 0, 195 | 0, 196 | 0, 197 | 0, 198 | 0, 199 | 0, 200 | 0, 201 | 0, 202 | 0, 203 | 0, 204 | 0, 205 | 0, 206 | 0, 207 | 0, 208 | 0, 209 | 0, 210 | 0, 211 | 0, 212 | 0, 213 | 0, 214 | 0, 215 | 0, 216 | 0, 217 | 0, 218 | 0, 219 | 0, 220 | 0, 221 | 0, 222 | 0, 223 | 0, 224 | 0, 225 | 0, 226 | 0, 227 | 0, 228 | 0, 229 | 0, 230 | 0, 231 | 0, 232 | 0, 233 | 0, 234 | 0, 235 | 0, 236 | 0, 237 | 0, 238 | 0, 239 | 0, 240 | 0, 241 | 0, 242 | 0, 243 | 0, 244 | 0, 245 | 0, 246 | 0, 247 | 0, 248 | 0, 249 | 0, 250 | 0, 251 | 0, 252 | 0, 253 | 0, 254 | 0, 255 | 0, 256 | 0, 257 | 0, 258 | 0, 259 | 0, 260 | 0, 261 | 0, 262 | 0, 263 | 0, 264 | 0, 265 | 0, 266 | 0, 267 | 0, 268 | 0, 269 | 0, 270 | 0, 271 | 0, 272 | 0, 273 | 0, 274 | 0, 275 | 0, 276 | 0, 277 | 0, 278 | 0, 279 | 0, 280 | 0, 281 | 0, 282 | 0, 283 | 0, 284 | 0, 285 | 0, 286 | 0, 287 | 0, 288 | 0, 289 | 0, 290 | 0, 291 | 0, 292 | 0, 293 | 0, 294 | 0, 295 | 0, 296 | 0, 297 | 0, 298 | 0, 299 | 0, 300 | 0, 301 | 0, 302 | 0, 303 | 0, 304 | 0, 305 | 0, 306 | 0, 307 | 0, 308 | 0, 309 | 0, 310 | 0, 311 | 0, 312 | 0 313 | }; 314 | 315 | StringCompressor::StringCompressor() 316 | { 317 | DataStructures::Map::IMPLEMENT_DEFAULT_COMPARISON(); 318 | 319 | // Make a default tree immediately, since this is used for RPC possibly from multiple threads at the same time 320 | DataStructures::HuffmanEncodingTree *huffmanEncodingTree = new DataStructures::HuffmanEncodingTree; 321 | huffmanEncodingTree->GenerateFromFrequencyTable( englishCharacterFrequencies ); 322 | huffmanEncodingTrees.Set(0, huffmanEncodingTree); 323 | } 324 | void StringCompressor::GenerateTreeFromStrings( unsigned char *input, unsigned inputLength, int languageID ) 325 | { 326 | DataStructures::HuffmanEncodingTree *huffmanEncodingTree; 327 | if (huffmanEncodingTrees.Has(languageID)) 328 | { 329 | huffmanEncodingTree = huffmanEncodingTrees.Get(languageID); 330 | delete huffmanEncodingTree; 331 | } 332 | 333 | unsigned index; 334 | unsigned int frequencyTable[ 256 ]; 335 | 336 | if ( inputLength == 0 ) 337 | return ; 338 | 339 | // Zero out the frequency table 340 | memset( frequencyTable, 0, sizeof( frequencyTable ) ); 341 | 342 | // Generate the frequency table from the strings 343 | for ( index = 0; index < inputLength; index++ ) 344 | frequencyTable[ input[ index ] ] ++; 345 | 346 | // Build the tree 347 | huffmanEncodingTree = new DataStructures::HuffmanEncodingTree; 348 | huffmanEncodingTree->GenerateFromFrequencyTable( frequencyTable ); 349 | huffmanEncodingTrees.Set(languageID, huffmanEncodingTree); 350 | } 351 | 352 | StringCompressor::~StringCompressor() 353 | { 354 | for (unsigned i=0; i < huffmanEncodingTrees.Size(); i++) 355 | delete huffmanEncodingTrees[i]; 356 | } 357 | 358 | void StringCompressor::EncodeString( const char *input, int maxCharsToWrite, RakNet::BitStream *output, int languageID ) 359 | { 360 | DataStructures::HuffmanEncodingTree *huffmanEncodingTree; 361 | if (huffmanEncodingTrees.Has(languageID)==false) 362 | return; 363 | huffmanEncodingTree=huffmanEncodingTrees.Get(languageID); 364 | 365 | if ( input == 0 ) 366 | { 367 | output->WriteCompressed( (unsigned short) 0 ); 368 | return ; 369 | } 370 | 371 | RakNet::BitStream encodedBitStream; 372 | 373 | unsigned short stringBitLength; 374 | 375 | int charsToWrite; 376 | 377 | if ( maxCharsToWrite<=0 || ( int ) strlen( input ) < maxCharsToWrite ) 378 | charsToWrite = ( int ) strlen( input ); 379 | else 380 | charsToWrite = maxCharsToWrite - 1; 381 | 382 | huffmanEncodingTree->EncodeArray( ( unsigned char* ) input, charsToWrite, &encodedBitStream ); 383 | 384 | stringBitLength = ( unsigned short ) encodedBitStream.GetNumberOfBitsUsed(); 385 | 386 | output->WriteCompressed( stringBitLength ); 387 | 388 | output->WriteBits( encodedBitStream.GetData(), stringBitLength ); 389 | } 390 | 391 | bool StringCompressor::DecodeString( char *output, int maxCharsToWrite, RakNet::BitStream *input, int languageID, unsigned & stringBitLength, bool skip ) 392 | { 393 | DataStructures::HuffmanEncodingTree *huffmanEncodingTree; 394 | if (huffmanEncodingTrees.Has(languageID)==false) 395 | return false; 396 | huffmanEncodingTree=huffmanEncodingTrees.Get(languageID); 397 | 398 | //unsigned short stringBitLength; 399 | int bytesInStream; 400 | 401 | output[ 0 ] = 0; 402 | 403 | if ( stringBitLength == 0 ) 404 | { 405 | short shortBitLength; 406 | 407 | if ( input->ReadCompressed( shortBitLength ) == false ) 408 | return false; 409 | 410 | stringBitLength = shortBitLength; 411 | } 412 | 413 | if ( input->GetNumberOfUnreadBits() < stringBitLength ) 414 | return false; 415 | 416 | bytesInStream = huffmanEncodingTree->DecodeArray( input, stringBitLength, maxCharsToWrite - 1, ( unsigned char* ) output, skip ); 417 | 418 | output[ bytesInStream ] = 0; 419 | 420 | return true; 421 | } 422 | 423 | bool StringCompressor::DecodeString( char *output, int maxCharsToWrite, RakNet::BitStream *input, int languageID ) 424 | { 425 | unsigned stringBitLength = 0; 426 | return DecodeString( output, maxCharsToWrite, input, languageID, stringBitLength, true ); 427 | } 428 | -------------------------------------------------------------------------------- /Source/StringTable.cpp: -------------------------------------------------------------------------------- 1 | #include "StringTable.h" 2 | #include 3 | #include 4 | #include 5 | #include "BitStream.h" 6 | #include "StringCompressor.h" 7 | 8 | using namespace RakNet; 9 | 10 | StringTable* StringTable::instance=0; 11 | int StringTable::referenceCount=0; 12 | 13 | namespace RakNet 14 | { 15 | int StrAndBoolComp( char *const &key, const StrAndBool &data ) 16 | { 17 | return strcmp(key,(const char*)data.str); 18 | } 19 | } 20 | 21 | StringTable::StringTable() 22 | { 23 | 24 | } 25 | 26 | StringTable::~StringTable() 27 | { 28 | unsigned i; 29 | for (i=0; i < orderedStringList.Size(); i++) 30 | { 31 | if (orderedStringList[i].b) 32 | delete [] orderedStringList[i].str; 33 | } 34 | } 35 | 36 | void StringTable::AddReference(void) 37 | { 38 | if (++referenceCount==1) 39 | { 40 | instance = new StringTable; 41 | } 42 | } 43 | void StringTable::RemoveReference(void) 44 | { 45 | RakAssert(referenceCount > 0); 46 | 47 | if (referenceCount > 0) 48 | { 49 | if (--referenceCount==0) 50 | { 51 | delete instance; 52 | instance=0; 53 | } 54 | } 55 | } 56 | 57 | StringTable* StringTable::Instance(void) 58 | { 59 | return instance; 60 | } 61 | 62 | void StringTable::AddString(const char *str, bool copyString) 63 | { 64 | StrAndBool sab; 65 | sab.b=copyString; 66 | if (copyString) 67 | { 68 | sab.str = new char [strlen(str)+1]; 69 | strcpy(sab.str, str); 70 | } 71 | else 72 | { 73 | sab.str=(char*)str; 74 | } 75 | 76 | // If it asserts inside here you are adding duplicate strings. 77 | if (!orderedStringList.Insert(sab.str,sab)) 78 | { 79 | if (copyString) 80 | delete sab.str; 81 | } 82 | 83 | // If this assert hits you need to increase the range of StringTableType 84 | RakAssert(orderedStringList.Size() < (StringTableType)-1); 85 | 86 | } 87 | void StringTable::EncodeString( const char *input, int maxCharsToWrite, RakNet::BitStream *output ) 88 | { 89 | unsigned index; 90 | bool objectExists; 91 | // This is fast because the list is kept ordered. 92 | index=orderedStringList.GetIndexFromKey((char*)input, &objectExists); 93 | if (objectExists) 94 | { 95 | output->Write(true); 96 | output->Write((StringTableType)index); 97 | } 98 | else 99 | { 100 | LogStringNotFound(input); 101 | output->Write(false); 102 | stringCompressor->EncodeString(input, maxCharsToWrite, output); 103 | } 104 | } 105 | 106 | bool StringTable::DecodeString( char *output, int maxCharsToWrite, RakNet::BitStream *input ) 107 | { 108 | bool hasIndex; 109 | RakAssert(maxCharsToWrite>0); 110 | 111 | if (maxCharsToWrite==0) 112 | return false; 113 | if (!input->Read(hasIndex)) 114 | return false; 115 | if (hasIndex==false) 116 | { 117 | stringCompressor->DecodeString(output, maxCharsToWrite, input); 118 | } 119 | else 120 | { 121 | StringTableType index; 122 | if (!input->Read(index)) 123 | return false; 124 | if (index >= orderedStringList.Size()) 125 | { 126 | 127 | // Critical error - got a string index out of range, which means AddString was called more times on the remote system than on this system. 128 | // All systems must call AddString the same number of types, with the same strings in the same order. 129 | RakAssert(0); 130 | 131 | return false; 132 | } 133 | 134 | strncpy(output, orderedStringList[index].str, maxCharsToWrite); 135 | output[maxCharsToWrite-1]=0; 136 | } 137 | 138 | return true; 139 | } 140 | #ifdef _MSC_VER 141 | #pragma warning( disable : 4100 ) // warning C4100: : unreferenced formal parameter 142 | #endif 143 | void StringTable::LogStringNotFound(const char *strName) 144 | { 145 | #ifdef _DEBUG 146 | printf("Efficiency Warning! Unregistered String %s sent to StringTable.\n", strName); 147 | #endif 148 | } 149 | -------------------------------------------------------------------------------- /Source/_findfirst.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Original file by the_viking, fixed by R√¥mulo Fernandes, fixed by Emmanuel Nars 3 | * Should emulate windows finddata structure 4 | */ 5 | #if (defined(__GNUC__) || defined(__GCCXML__)) && !defined(__WIN32) 6 | #include "_findfirst.h" 7 | #include "DS_List.h" 8 | 9 | using namespace RakNet; 10 | 11 | static DataStructures::List< _findinfo_t* > fileInfo; 12 | 13 | /** 14 | * _findfirst - equivalent 15 | */ 16 | long _findfirst(const char *name, _finddata_t *f) 17 | { 18 | 19 | // char* nameCopy = new char[sizeof(name)]; 20 | // memset(nameCopy, '\0', sizeof(nameCopy)); 21 | // 22 | // strcpy(nameCopy, name); 23 | // 24 | // char* filter = new char[sizeof(nameCopy)]; 25 | // memset(filter, '\0', sizeof(filter)); 26 | 27 | int length = strlen(name)+1; 28 | char* nameCopy = new char[length]; 29 | memset(nameCopy, '\0', length); 30 | 31 | strcpy(nameCopy, name); 32 | 33 | char* filter = new char[length]; 34 | memset(filter, '\0', length); 35 | 36 | char* lastSep = strrchr(nameCopy,'/'); 37 | if(!lastSep) 38 | { 39 | strcpy(filter, nameCopy); 40 | strcpy(nameCopy, "."); 41 | } 42 | else 43 | { 44 | strcpy(filter, lastSep+1); 45 | *lastSep = 0; 46 | } 47 | 48 | DIR* dir = opendir(nameCopy); 49 | 50 | if(!dir) 51 | { 52 | return -1; 53 | } 54 | 55 | _findinfo_t* fi = new _findinfo_t; 56 | strcpy(fi->filter,filter); 57 | fi->openedDir = dir; 58 | 59 | while(true) 60 | { 61 | dirent* entry = readdir(dir); 62 | if(entry == 0) 63 | break; 64 | 65 | if(fnmatch(fi->filter,entry->d_name, 200) == 0) 66 | { 67 | strcpy(f->name, entry->d_name); 68 | break; 69 | } 70 | } 71 | 72 | 73 | fileInfo.Insert(fi); 74 | return fileInfo.Size()-1; 75 | 76 | // return 0; 77 | } 78 | 79 | /** 80 | * _findnext - equivalent 81 | */ 82 | int _findnext(long h, _finddata_t *f) 83 | { 84 | 85 | _findinfo_t* fi = fileInfo[h]; 86 | 87 | while(true) 88 | { 89 | dirent* entry = readdir(fi->openedDir); 90 | if(entry == 0) 91 | return -1; 92 | 93 | if(fnmatch(fi->filter,entry->d_name, 200) == 0) 94 | { 95 | strcpy(f->name, entry->d_name); 96 | if (entry->d_type == DT_REG) 97 | f->attrib = _A_NORMAL; 98 | f->size = entry->d_reclen; 99 | return 0; 100 | } 101 | if (entry->d_type == DT_DIR) 102 | { 103 | f->attrib = _A_SUBDIR; 104 | strcpy(f->name, entry->d_name); 105 | return 0; 106 | } 107 | } 108 | 109 | return -1; 110 | } 111 | 112 | /** 113 | * _findclose - equivalent 114 | */ 115 | int _findclose(long h) 116 | { 117 | if (fileInfo.Size()>h) 118 | { 119 | _findinfo_t* fi = fileInfo[h]; 120 | fileInfo.RemoveAtIndex(h); 121 | delete fi; 122 | return 0; 123 | } 124 | else 125 | { 126 | printf("Error _findclose\n"); 127 | return -1; 128 | } 129 | 130 | } 131 | #endif 132 | -------------------------------------------------------------------------------- /SpeexLicense.txt: -------------------------------------------------------------------------------- 1 | Redistribution and use in source and binary forms, with or without 2 | modification, are permitted provided that the following conditions 3 | are met: 4 | 5 | - Redistributions of source code must retain the above copyright 6 | notice, this list of conditions and the following disclaimer. 7 | 8 | - Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | 12 | - Neither the name of the Xiph.org Foundation nor the names of its 13 | contributors may be used to endorse or promote products derived from 14 | this software without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR 20 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 21 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 22 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 23 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 24 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | -------------------------------------------------------------------------------- /readme.txt: -------------------------------------------------------------------------------- 1 | RakNet 2.52 2 | Copyright 2002-2005 Kevin Jenkins (rakkar@rakkarsoft.com). 3 | This API and the code herein created by and wholly and privately owned by Kevin Jenkins except where specifically indicated otherwise. 4 | Licensed under the "RakNet" brand by Jenkins Software and subject to the terms of the relevant licensing agreement available at http://www.rakkarsoft.com 5 | 6 | See Help/revisionlog.html for what has changed. 7 | 8 | ------------------------------------------ 9 | Windows users (Visual Studio 2005) 10 | ----------------------------------------- 11 | Load RakNet.sln and convert. 12 | If it doesn't work, see Help/compilersetup.html or the training video at http://www.rakkarsoft.com/raknet/manual/helloworldvideo.html on how to setup the project. 13 | 14 | ----------------------------------------- 15 | Windows users (.NET 2003) 16 | ----------------------------------------- 17 | Load RakNet.sln 18 | 19 | ----------------------------------------- 20 | Windows users (VC6) 21 | ----------------------------------------- 22 | Load RakNet.dsw . I've gotten mixed reports on if it works or not - this is an auto-generated file. 23 | If it doesn't work, see Help/compilersetup.html or the training video at http://www.rakkarsoft.com/raknet/manual/helloworldvideo.html on how to setup the project. 24 | 25 | ----------------------------------------- 26 | CYGWIN users 27 | ----------------------------------------- 28 | Copy Include, Source, and whatever you want to run in the home directory. Then type 29 | g++ ../../lib/w32api/libws2_32.a *.cpp 30 | You can run a.exe 31 | You might have to copy *.dll from cygwin\bin as well. 32 | 33 | ----------------------------------------- 34 | Linux users 35 | ----------------------------------------- 36 | Linux build files are community contributed. I do not support them. As far as I'm concerned "gcc -c *.cpp" is all you ever need. If the files are out of date and you know how to fix them, 37 | email me fixes at rakkar@rakkarsoft.com and I will include the fixes in the next version. 38 | 39 | - Kevin 40 | 41 | What follows is a user note: 42 | 43 | These new makefiles are based on the old ones by NathanH, i almost rewrote everything he done but i left some basic stuff, before compile, make sure to check the file makefile.defs, change the INCLUDE_DIR= to your include directory(generally /usr/local/include or /usr/include) and LIBS_DIR to your library directory( usually /usr/lib or /usr/local/lib ). 44 | 45 | 1-To compile raknet just type "make" on the root directory 46 | 2-To install it, log as root ( su ) and type "make install", after install it, check your /etc/ld.so.config(in debian) for the lib directories, if your LIBS_DIR directory isnt there, include it, and run ldconfig after the install process. 47 | 3-To compile the linux samples go to the linux sample directories and run make 48 | 4-To compile a program using raknet just use -I/usr/local/include(or your INCLUDE_DIR) and -lraknet for linking 49 | 50 | by romulo fernandes(abra185@gmail.com) feel 51 | free to distribute it or even modify it. 52 | Theres no compilation for macOSX present cause i dont have a mac system, if you want to use those, use NathanH makefiles. Thanks. 53 | 54 | if you get errors related to speex do one of the following: 55 | 1. just download the devel package for speex from your distributions package repository and install that 56 | 2. you could download speex from the speex homepage (google for it) and compile and install that 57 | 3. if you don't plan to use the voice part of raknet you can disable it by removing in Makefile the voicestatic and voiceshared from that line: 58 | all: static shared voicestatic voiceshared 59 | 60 | the speex distributed with raknet in the zip archive is actually pretty useless for linux users, cause you would need to run configure to get some of the headers built, but configure seams to be broken because it has been on a windows filesystem, where all the flags like "executable" get removed. 61 | 62 | updated by Simon Schmeisser (mail_to_wrt@gmx.de) 63 | 64 | ----------------------------------------- 65 | DevCPP Users 66 | ----------------------------------------- 67 | Load RakNet.dev 68 | 69 | ----------------------------------------- 70 | CodeBlocks Users 71 | ----------------------------------------- 72 | Load RakNet.cbp 73 | 74 | ------------------------------------------ 75 | DigitalMars Users 76 | ----------------------------------------- 77 | A user contributed file DMCMakefile.win is included in the distribution. I have no idea if it works or not. If it doesn't, you can email me updates at rakkar@rakkarsoft.com 78 | 79 | ----------------------------------------- 80 | Mac Users 81 | ----------------------------------------- 82 | From http://www.rakkarsoft.com/raknet/forum/index.php?topic=746.0;topicseen 83 | Open a Terminal window and type: cd ~/Desktop/RakNet/Source 84 | 85 | Give the following command: 86 | 87 | Code: 88 | gcc -c -I ../Include -isysroot /Developer/SDKs/MacOSX10.3.9.sdk/ -arch ppc *.cpp 89 | 90 | The sources should build cleanly. This gives you a bunch of PowerPC binaries, compiled against the 10.3.9 SDK which is a good thing. 91 | 92 | Give the following command: 93 | 94 | Code: 95 | libtool -static -o raknetppc.a *.o 96 | 97 | This will stitch together a static library for the PowerPC architecture. There may be warnings that some .o files do not have any symbols. If you want to be prudent, remove the named files (the .o files, not the .cpp files!) and re-run the libtool command. 98 | 99 | Now, we build the source files for Intel: 100 | 101 | Code: 102 | gcc -c -I ../Include -isysroot /Developer/SDKs/MacOSX10.4u.sdk/ -arch i386 *.cpp 103 | 104 | ..and stitch it into a i386 library: 105 | 106 | Code: 107 | libtool -static -o rakneti386.a *.o 108 | 109 | Now, type: 110 | 111 | Code: 112 | ls *.a 113 | 114 | which should list the two .a files. Now, we make them into a universal binary: 115 | 116 | Code: 117 | lipo -create *.a -o libraknet.a 118 | 119 | You now have a file named libraknet.a. This is the RakNet library, built to run on both PowerPC and Intel Macs. Enjoy! ;-) 120 | 121 | 122 | ----------------------------------------- 123 | Other Platforms 124 | ----------------------------------------- 125 | The define _COMPATIBILITY_1 while adding Compatibility1Includes.h may work for you. 126 | 127 | ----------------------------------------- 128 | Package notes 129 | ----------------------------------------- 130 | The Source directory contain all files required for the core of Raknet and is used if you want to use the source in your program or create your own dll 131 | The Samples directory contains code samples and one game using an older version of Raknet. The code samples each demonstrate one feature of Raknet. The game samples cover several features. 132 | The lib directory contains libs for debug and release versions of RakNet and RakVoice 133 | The Help directory contains index.html, which is full help documentation in HTML format 134 | There is a make file for linux users in the root directory. Windows users can use projects under Samples\Project Samples 135 | 136 | For support please visit 137 | http://www.rakkarsoft.com --------------------------------------------------------------------------------