├── .gitignore ├── .gitmodules ├── CMakeLists.txt ├── CMakePresets.json ├── LICENSE ├── RakNet ├── CMakeLists.txt ├── include │ └── RakNet │ │ ├── AsynchronousFileIO.h │ │ ├── AutopatcherPatchContext.h │ │ ├── AutopatcherRepositoryInterface.h │ │ ├── BigTypes.h │ │ ├── BitStream.h │ │ ├── BitStream_NoTemplate.h │ │ ├── CheckSum.h │ │ ├── ClientContextStruct.h │ │ ├── CommandParserInterface.h │ │ ├── ConsoleServer.h │ │ ├── DS_BPlusTree.h │ │ ├── DS_BinarySearchTree.h │ │ ├── DS_ByteQueue.h │ │ ├── DS_Heap.h │ │ ├── DS_HuffmanEncodingTree.h │ │ ├── DS_HuffmanEncodingTreeFactory.h │ │ ├── DS_HuffmanEncodingTreeNode.h │ │ ├── DS_LinkedList.h │ │ ├── DS_List.h │ │ ├── DS_Map.h │ │ ├── DS_MemoryPool.h │ │ ├── DS_OrderedChannelHeap.h │ │ ├── DS_OrderedList.h │ │ ├── DS_Queue.h │ │ ├── DS_QueueLinkedList.h │ │ ├── DS_RangeList.h │ │ ├── DS_Table.h │ │ ├── DS_Tree.h │ │ ├── DS_WeightedGraph.h │ │ ├── DataBlockEncryptor.h │ │ ├── DataCompressor.h │ │ ├── EmailSender.h │ │ ├── Export.h │ │ ├── ExtendedOverlappedPool.h │ │ ├── FileOperations.h │ │ ├── FullyConnectedMesh.h │ │ ├── GetTime.h │ │ ├── InternalPacket.h │ │ ├── InternalPacketPool.h │ │ ├── LinuxStrings.h │ │ ├── LogCommandParser.h │ │ ├── MTUSize.h │ │ ├── NetworkIDGenerator.h │ │ ├── NetworkTypes.h │ │ ├── PacketEnumerations.h │ │ ├── PacketPool.h │ │ ├── PacketPriority.h │ │ ├── PluginInterface.h │ │ ├── RPCMap.h │ │ ├── RPCNode.h │ │ ├── RSACrypt.h │ │ ├── RakAssert.h │ │ ├── RakClient.h │ │ ├── RakClientInterface.h │ │ ├── RakNetCommandParser.h │ │ ├── RakNetDefines.h │ │ ├── RakNetStatistics.h │ │ ├── RakNetworkFactory.h │ │ ├── RakPeer.h │ │ ├── RakPeerInterface.h │ │ ├── RakServer.h │ │ ├── RakServerInterface.h │ │ ├── RakSleep.h │ │ ├── Rand.h │ │ ├── ReliabilityLayer.h │ │ ├── Replica.h │ │ ├── ReplicaEnums.h │ │ ├── RouterInterface.h │ │ ├── SHA1.h │ │ ├── SimpleMutex.h │ │ ├── SimpleTCPServer.h │ │ ├── SingleProducerConsumer.h │ │ ├── SocketLayer.h │ │ ├── StringCompressor.h │ │ ├── StringTable.h │ │ ├── SystemAddressList.h │ │ ├── SystemDatabaseClient.h │ │ ├── SystemDatabaseServer.h │ │ ├── TCPInterface.h │ │ ├── TableSerializer.h │ │ ├── TelnetTransport.h │ │ ├── ThreadPool.h │ │ ├── TransportInterface.h │ │ ├── Types.h │ │ ├── _findfirst.h │ │ ├── multiplayer.h │ │ ├── rijndael-boxes.h │ │ ├── rijndael.h │ │ └── sampencr.h └── src │ ├── AsynchronousFileIO.cpp │ ├── BitStream.cpp │ ├── CheckSum.cpp │ ├── DS_ByteQueue.cpp │ ├── DS_HuffmanEncodingTree.cpp │ ├── DS_Table.cpp │ ├── DataBlockEncryptor.cpp │ ├── DataCompressor.cpp │ ├── EncodeClassName.cpp │ ├── GetTime.cpp │ ├── InternalPacketPool.cpp │ ├── LinuxStrings.cpp │ ├── NetworkIDGenerator.cpp │ ├── NetworkTypes.cpp │ ├── PluginInterface.cpp │ ├── RPCMap.cpp │ ├── RakClient.cpp │ ├── RakNetStatistics.cpp │ ├── RakNetworkFactory.cpp │ ├── RakPeer.cpp │ ├── RakSleep.cpp │ ├── Rand.cpp │ ├── ReliabilityLayer.cpp │ ├── SHA1.cpp │ ├── SimpleMutex.cpp │ ├── SocketLayer.cpp │ ├── StringCompressor.cpp │ ├── StringTable.cpp │ ├── SystemAddressList.cpp │ ├── TableSerializer.cpp │ ├── _findfirst.cpp │ ├── rakserver.cpp │ ├── rijndael.cpp │ └── sampencr.cpp ├── daemon ├── CMakeLists.txt ├── crtp_singleton.hpp ├── logger.hpp ├── main.cpp ├── rakclient.hpp ├── raknet_plugin.hpp ├── raknet_state.hpp ├── raknet_utils.hpp └── utils.hpp ├── ipc ├── CMakeLists.txt ├── include │ └── ipc │ │ ├── ipc_client.hpp │ │ ├── ipc_headers.hpp │ │ └── ipc_server.hpp └── src │ ├── ipc_client.cpp │ └── ipc_server.cpp ├── sa_module ├── BitStream.cpp ├── BitStream.hpp ├── CMakeLists.txt ├── RakNet.hpp ├── Utils.cpp ├── Utils.hpp ├── actors_state.hpp ├── camera_state.hpp ├── chat_state.hpp ├── checkpoint_state.hpp ├── cp2utf.hpp ├── crtp_singleton.hpp ├── dialog_state.hpp ├── dllmain.cpp ├── gangzone_state.hpp ├── ipc_client.hpp ├── json_utils.hpp ├── kill_list_state.hpp ├── labels_state.hpp ├── local_player_state.hpp ├── logger.hpp ├── markers_state.hpp ├── menus_state.hpp ├── net_stats_state.hpp ├── netgame_state.hpp ├── object_edit_state.hpp ├── object_select_state.hpp ├── objects_state.hpp ├── pickups_state.hpp ├── quaternion.hpp ├── raknet_state.hpp ├── remote_player_state.hpp ├── remove_building_state.hpp ├── rpc_handler.hpp ├── samp_addresses.hpp ├── samp_types.hpp ├── samp_utils.hpp ├── textdraw_state.hpp ├── vector.hpp └── vehicles_state.hpp └── third-party └── CMakeLists.txt /.gitignore: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # This .gitignore file was automatically created by Microsoft(R) Visual Studio. 3 | ################################################################################ 4 | 5 | /.vs 6 | /out/build 7 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "third-party/kthook"] 2 | path = third-party/kthook 3 | url = https://github.com/kin4stat/kthook.git 4 | [submodule "third-party/sampapi"] 5 | path = third-party/sampapi 6 | url = https://github.com/kin4stat/SAMP-API.git 7 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.16) 2 | 3 | project("connd") 4 | 5 | set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:DebugDLL>") 6 | 7 | add_compile_definitions(NOMINMAX) 8 | add_compile_options($<$:/MP>) 9 | 10 | add_subdirectory("ipc") 11 | add_subdirectory("RakNet") 12 | add_subdirectory("third-party") 13 | add_subdirectory("sa_module") 14 | add_subdirectory("daemon") -------------------------------------------------------------------------------- /CMakePresets.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 3, 3 | "configurePresets": [ 4 | { 5 | "name": "windows-base", 6 | "hidden": true, 7 | "generator": "Ninja", 8 | "binaryDir": "${sourceDir}/out/build/${presetName}", 9 | "installDir": "${sourceDir}/out/install/${presetName}", 10 | "cacheVariables": { 11 | "CMAKE_C_COMPILER": "cl.exe", 12 | "CMAKE_CXX_COMPILER": "cl.exe" 13 | }, 14 | "condition": { 15 | "type": "equals", 16 | "lhs": "${hostSystemName}", 17 | "rhs": "Windows" 18 | } 19 | }, 20 | { 21 | "name": "x64-debug", 22 | "displayName": "x64 Debug", 23 | "inherits": "windows-base", 24 | "architecture": { 25 | "value": "x64", 26 | "strategy": "external" 27 | }, 28 | "cacheVariables": { 29 | "CMAKE_BUILD_TYPE": "Debug" 30 | } 31 | }, 32 | { 33 | "name": "x64-release", 34 | "displayName": "x64 Release", 35 | "inherits": "x64-debug", 36 | "cacheVariables": { 37 | "CMAKE_BUILD_TYPE": "Release" 38 | } 39 | }, 40 | { 41 | "name": "x86-debug", 42 | "displayName": "x86 Debug", 43 | "inherits": "windows-base", 44 | "architecture": { 45 | "value": "x86", 46 | "strategy": "external" 47 | }, 48 | "cacheVariables": { 49 | "CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_PATH}/scripts/buildsystems/vcpkg.cmake", 50 | "CMAKE_BUILD_TYPE": "Debug" 51 | } 52 | }, 53 | { 54 | "name": "x86-release", 55 | "displayName": "x86 Release", 56 | "inherits": "x86-debug", 57 | "cacheVariables": { 58 | "CMAKE_BUILD_TYPE": "Release", 59 | "VCPKG_TARGET_TRIPLET": "x86-windows-static" 60 | } 61 | }, 62 | { 63 | "name": "linux-debug", 64 | "displayName": "Linux Debug", 65 | "generator": "Ninja", 66 | "binaryDir": "${sourceDir}/out/build/${presetName}", 67 | "installDir": "${sourceDir}/out/install/${presetName}", 68 | "cacheVariables": { 69 | "CMAKE_BUILD_TYPE": "Debug" 70 | }, 71 | "condition": { 72 | "type": "equals", 73 | "lhs": "${hostSystemName}", 74 | "rhs": "Linux" 75 | }, 76 | "vendor": { 77 | "microsoft.com/VisualStudioRemoteSettings/CMake/1.0": { 78 | "sourceDir": "$env{HOME}/.vs/$ms{projectDirName}" 79 | } 80 | } 81 | }, 82 | { 83 | "name": "macos-debug", 84 | "displayName": "macOS Debug", 85 | "generator": "Ninja", 86 | "binaryDir": "${sourceDir}/out/build/${presetName}", 87 | "installDir": "${sourceDir}/out/install/${presetName}", 88 | "cacheVariables": { 89 | "CMAKE_BUILD_TYPE": "Debug" 90 | }, 91 | "condition": { 92 | "type": "equals", 93 | "lhs": "${hostSystemName}", 94 | "rhs": "Darwin" 95 | }, 96 | "vendor": { 97 | "microsoft.com/VisualStudioRemoteSettings/CMake/1.0": { 98 | "sourceDir": "$env{HOME}/.vs/$ms{projectDirName}" 99 | } 100 | } 101 | } 102 | ] 103 | } 104 | -------------------------------------------------------------------------------- /RakNet/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.16) 2 | 3 | project("RakNet") 4 | 5 | add_library("RakNet" STATIC "src/AsynchronousFileIO.cpp" 6 | "src/BitStream.cpp" 7 | "src/CheckSum.cpp" 8 | "src/DataBlockEncryptor.cpp" 9 | "src/DataCompressor.cpp" 10 | "src/DS_ByteQueue.cpp" 11 | "src/DS_HuffmanEncodingTree.cpp" 12 | "src/DS_Table.cpp" 13 | "src/EncodeClassName.cpp" 14 | "src/GetTime.cpp" 15 | "src/InternalPacketPool.cpp" 16 | "src/LinuxStrings.cpp" 17 | "src/NetworkIDGenerator.cpp" 18 | "src/NetworkTypes.cpp" 19 | "src/PluginInterface.cpp" 20 | "src/RakClient.cpp" 21 | "src/RakNetStatistics.cpp" 22 | "src/RakNetworkFactory.cpp" 23 | "src/RakPeer.cpp" 24 | "src/rakserver.cpp" 25 | "src/RakSleep.cpp" 26 | "src/Rand.cpp" 27 | "src/ReliabilityLayer.cpp" 28 | "src/rijndael.cpp" 29 | "src/RPCMap.cpp" 30 | "src/SHA1.cpp" 31 | "src/SimpleMutex.cpp" 32 | "src/SocketLayer.cpp" 33 | "src/StringCompressor.cpp" 34 | "src/StringTable.cpp" 35 | "src/SystemAddressList.cpp" 36 | "src/TableSerializer.cpp" 37 | "src/_findfirst.cpp" 38 | "src/sampencr.cpp") 39 | 40 | 41 | set_target_properties("RakNet" 42 | PROPERTIES 43 | CXX_STANDARD 14 44 | CXX_STANDARD_REQUIRED ON 45 | ) 46 | 47 | target_compile_definitions("RakNet" PRIVATE _CRT_SECURE_NO_WARNINGS _CRT_SECURE_NO_DEPRECATE) 48 | 49 | target_include_directories("RakNet" PRIVATE "include/RakNet") 50 | target_include_directories("RakNet" PUBLIC "include") 51 | 52 | target_link_libraries("RakNet" PUBLIC ws2_32 comctl32) -------------------------------------------------------------------------------- /RakNet/include/RakNet/AsynchronousFileIO.h: -------------------------------------------------------------------------------- 1 | /// \file 2 | /// \brief \b [Internal] Depreciated, used for windows back 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 | // No longer used as I no longer support IO Completion ports 19 | /* 20 | #ifdef __USE_IO_COMPLETION_PORTS 21 | 22 | #ifndef __ASYNCHRONOUS_FILE_IO_H 23 | #define __ASYNCHRONOUS_FILE_IO_H 24 | 25 | #ifdef _COMPATIBILITY_1 26 | #elif defined(_WIN32) 27 | // IP_DONTFRAGMENT is different between winsock 1 and winsock 2. Therefore, Winsock2.h must be linked againt Ws2_32.lib 28 | // winsock.h must be linked against WSock32.lib. If these two are mixed up the flag won't work correctly 29 | //#include 30 | //#include 31 | #endif 32 | #include "SimpleMutex.h" 33 | 34 | struct ExtendedOverlappedStruct; 35 | 36 | /// Provides asynch file input and ouput, either for sockets or files 37 | class AsynchronousFileIO 38 | { 39 | 40 | public: 41 | 42 | /// Default Constructor 43 | AsynchronousFileIO(); 44 | 45 | /// Destructor 46 | ~AsynchronousFileIO(); 47 | 48 | 49 | /// Associate a socket with a completion port 50 | /// \param[in] socket the socket used for communication 51 | /// \param[in] dwCompletionKey the completion port key 52 | bool AssociateSocketWithCompletionPort( SOCKET socket, DWORD dwCompletionKey );if 53 | 54 | /// Singleton instance 55 | static inline AsynchronousFileIO* Instance() 56 | { 57 | return & I; 58 | } 59 | 60 | /// Increase the number of users of this instance 61 | void IncreaseUserCount( void ); 62 | 63 | /// Decrease the number of users of this instance 64 | void DecreaseUserCount( void ); 65 | 66 | /// Stop using asynchronous IO 67 | void Shutdown( void ); 68 | 69 | /// Get the number of user of the instance 70 | int GetUserCount( void ); 71 | 72 | unsigned threadCount; 73 | bool killThreads; 74 | 75 | private: 76 | HANDLE completionPort; 77 | SimpleMutex userCountMutex; 78 | SYSTEM_INFO systemInfo; 79 | int userCount; 80 | 81 | static AsynchronousFileIO I; 82 | }; 83 | 84 | unsigned __stdcall ThreadPoolFunc( LPVOID arguments ); 85 | 86 | void WriteAsynch( HANDLE handle, ExtendedOverlappedStruct *extended ); 87 | 88 | BOOL ReadAsynch( HANDLE handle, ExtendedOverlappedStruct *extended ); 89 | 90 | #endif 91 | */ -------------------------------------------------------------------------------- /RakNet/include/RakNet/AutopatcherPatchContext.h: -------------------------------------------------------------------------------- 1 | #ifndef __AUTOPATCHER_PATCH_CONTEXT_H 2 | #define __AUTOPATCHER_PATCH_CONTEXT_H 3 | 4 | enum PatchContext 5 | { 6 | PC_HASH_WITH_PATCH, 7 | PC_WRITE_FILE, 8 | PC_ERROR_FILE_WRITE_FAILURE, 9 | PC_ERROR_PATCH_TARGET_MISSING, 10 | PC_ERROR_PATCH_APPLICATION_FAILURE, 11 | PC_ERROR_PATCH_RESULT_CHECKSUM_FAILURE, 12 | PC_NOTICE_WILL_COPY_ON_RESTART, 13 | }; 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /RakNet/include/RakNet/AutopatcherRepositoryInterface.h: -------------------------------------------------------------------------------- 1 | /// \file 2 | /// \brief An interface used by AutopatcherServer to get the data necessary to run an autopatcher. 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 __AUTOPATCHER_REPOSITORY_INTERFACE_H 20 | #define __AUTOPATCHER_REPOSITORY_INTERFACE_H 21 | 22 | class FileList; 23 | namespace RakNet 24 | { 25 | class BitStream; 26 | } 27 | 28 | /// An interface used by AutopatcherServer to get the data necessary to run an autopatcher. This is up to you to implement for custom repository solutions. 29 | class AutopatcherRepositoryInterface 30 | { 31 | public: 32 | /// Get list of files added and deleted since a certain date. This is used by AutopatcherServer and not usually explicitly called. 33 | /// \param[in] applicationName A null terminated string identifying the application 34 | /// \param[out] addedFiles A list of the current versions of filenames with hashes as their data that were created after \a sinceData 35 | /// \param[out] deletedFiles A list of the current versions of filenames that were deleted after \a sinceData 36 | /// \param[in] An input date, in whatever format your repository uses 37 | /// \param[out] currentDate The current server date, in whatever format your repository uses 38 | /// \return True on success, false on failure. 39 | virtual bool GetChangelistSinceDate(const char *applicationName, FileList *addedFiles, FileList *deletedFiles, const char *sinceDate, char currentDate[64])=0; 40 | 41 | /// Get patches (or files) for every file in input, assuming that input has a hash for each of those files. 42 | /// \param[in] applicationName A null terminated string identifying the application 43 | /// \param[in] input A list of files with SHA1_LENGTH byte hashes to get from the database. 44 | /// \param[out] patchList You should return list of files with either the filedata or the patch. This is a subset of \a input. The context data for each file will be either PC_WRITE_FILE (to just write the file) or PC_HASH_WITH_PATCH (to patch). If PC_HASH_WITH_PATCH, then the file contains a SHA1_LENGTH byte patch followed by the hash. The datalength is patchlength + SHA1_LENGTH 45 | /// \return True on success, false on failure. 46 | virtual bool GetPatches(const char *applicationName, FileList *input, FileList *patchList)=0; 47 | 48 | /// \return Whatever this function returns is sent from the AutopatcherServer to the AutopatcherClient when one of the above functions returns false. 49 | virtual char *GetLastError(void) const=0; 50 | }; 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /RakNet/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 | /// Generates and validates checksums 11 | class CheckSum 12 | { 13 | 14 | public: 15 | 16 | /// Default constructor 17 | 18 | CheckSum() 19 | { 20 | Clear(); 21 | } 22 | 23 | void Clear() 24 | { 25 | sum = 0; 26 | r = 55665; 27 | c1 = 52845; 28 | c2 = 22719; 29 | } 30 | 31 | void Add ( unsigned int w ); 32 | 33 | 34 | void Add ( unsigned short w ); 35 | 36 | void Add ( unsigned char* b, unsigned int length ); 37 | 38 | void Add ( unsigned char b ); 39 | 40 | unsigned int Get () 41 | { 42 | return sum; 43 | } 44 | 45 | protected: 46 | unsigned short r; 47 | unsigned short c1; 48 | unsigned short c2; 49 | unsigned int sum; 50 | }; 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /RakNet/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 | class RakPeer; 29 | 30 | #ifdef __USE_IO_COMPLETION_PORTS 31 | 32 | struct ClientContextStruct 33 | { 34 | HANDLE handle; // The socket, also used as a file handle 35 | }; 36 | 37 | struct ExtendedOverlappedStruct 38 | { 39 | OVERLAPPED overlapped; 40 | char data[ MAXIMUM_MTU_SIZE ]; // Used to hold data to send 41 | int length; // Length of the actual data to send, always under MAXIMUM_MTU_SIZE 42 | unsigned int binaryAddress; 43 | unsigned short port; 44 | RakPeer *rakPeer; 45 | bool read; // Set to true for reads, false for writes 46 | }; 47 | 48 | #endif 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /RakNet/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 | class TransportInterface; 22 | class CommandParserInterface; 23 | 24 | #include "DS_List.h" 25 | #include "NetworkTypes.h" 26 | #include "Export.h" 27 | 28 | /// \brief The main entry point for the server portion of your remote console application support. 29 | /// ConsoleServer takes one TransportInterface and one or more CommandParserInterface (s) 30 | /// The TransportInterface will be used to send data between the server and the client. The connecting client must support the 31 | /// protocol used by your derivation of TransportInterface . TelnetTransport and RakNetTransport are two such derivations . 32 | /// When a command is sent by a remote console, it will be processed by your implementations of CommandParserInterface 33 | class RAK_DLL_EXPORT ConsoleServer 34 | { 35 | public: 36 | ConsoleServer(); 37 | ~ConsoleServer(); 38 | 39 | /// Call this with a derivation of TransportInterface so that the console server can send and receive commands 40 | /// \param[in] transportInterface Your interface to use. 41 | /// \param[in] port The port to host on. Telnet uses port 23 by default. RakNet can use whatever you want. 42 | void SetTransportProvider(TransportInterface *transportInterface, unsigned short port); 43 | 44 | /// Add an implementation of CommandParserInterface to the list of command parsers. 45 | /// \param[in] commandParserInterface The command parser referred to 46 | void AddCommandParser(CommandParserInterface *commandParserInterface); 47 | 48 | /// Remove an implementation of CommandParserInterface previously added with AddCommandParser() 49 | /// \param[in] commandParserInterface The command parser referred to 50 | void RemoveCommandParser(CommandParserInterface *commandParserInterface); 51 | 52 | /// Call update to read packet sent from your TransportInterface. 53 | /// You should do this fairly frequently. 54 | void Update(void); 55 | protected: 56 | void ListParsers(PlayerID playerId); 57 | TransportInterface *transport; 58 | DataStructures::List commandParserList; 59 | char* password[256]; 60 | }; 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /RakNet/include/RakNet/DS_ByteQueue.h: -------------------------------------------------------------------------------- 1 | /// \file 2 | /// \brief \b [Internal] Byte queue 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 __BYTE_QUEUE_H 19 | #define __BYTE_QUEUE_H 20 | 21 | #include "Export.h" 22 | 23 | /// The namespace DataStructures was only added to avoid compiler errors for commonly named data structures 24 | /// As these data structures are stand-alone, you can use them outside of RakNet for your own projects if you wish. 25 | namespace DataStructures 26 | { 27 | class ByteQueue 28 | { 29 | public: 30 | ByteQueue(); 31 | ~ByteQueue(); 32 | void WriteBytes(const char *in, unsigned length); 33 | bool ReadBytes(char *out, unsigned length, bool peek); 34 | unsigned GetBytesWritten(void) const; 35 | void IncrementReadOffset(unsigned length); 36 | void Clear(void); 37 | void Print(void); 38 | 39 | protected: 40 | char *data; 41 | unsigned readOffset, writeOffset, lengthAllocated; 42 | }; 43 | } 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /RakNet/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 | /// 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 27 | class RAK_DLL_EXPORT HuffmanEncodingTree 28 | { 29 | 30 | public: 31 | HuffmanEncodingTree(); 32 | ~HuffmanEncodingTree(); 33 | 34 | /// Pass an array of bytes to array and a preallocated BitStream to receive the output 35 | /// \param [in] input Array of bytes to encode 36 | /// \param [in] sizeInBytes size of \a input 37 | /// \param [out] output The bitstream to write to 38 | void EncodeArray( unsigned char *input, unsigned sizeInBytes, RakNet::BitStream * output ); 39 | 40 | // Decodes an array encoded by EncodeArray() 41 | unsigned DecodeArray( RakNet::BitStream * input, unsigned sizeInBits, unsigned maxCharsToWrite, unsigned char *output ); 42 | void DecodeArray( unsigned char *input, unsigned sizeInBits, RakNet::BitStream * output ); 43 | 44 | /// Given a frequency table of 256 elements, all with a frequency of 1 or more, generate the tree 45 | void GenerateFromFrequencyTable( unsigned int frequencyTable[ 256 ] ); 46 | 47 | /// Free the memory used by the tree 48 | void FreeMemory( void ); 49 | 50 | private: 51 | 52 | /// The root node of the tree 53 | 54 | HuffmanEncodingTreeNode *root; 55 | 56 | /// Used to hold bit encoding for one character 57 | 58 | 59 | struct CharacterEncoding 60 | { 61 | unsigned char* encoding; 62 | unsigned short bitLength; 63 | }; 64 | 65 | CharacterEncoding encodingTable[ 256 ]; 66 | 67 | void InsertNodeIntoSortedList( HuffmanEncodingTreeNode * node, DataStructures::LinkedList *huffmanEncodingTreeNodeList ) const; 68 | }; 69 | 70 | #endif 71 | -------------------------------------------------------------------------------- /RakNet/include/RakNet/DS_HuffmanEncodingTreeFactory.h: -------------------------------------------------------------------------------- 1 | /// \file 2 | /// \brief \b [Internal] Creates instances of the class HuffmanEncodingTree 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_FACTORY 19 | #define __HUFFMAN_ENCODING_TREE_FACTORY 20 | 21 | class HuffmanEncodingTree; 22 | 23 | /// \brief Creates instances of the class HuffmanEncodingTree 24 | /// 25 | /// This class takes a frequency table and given that frequence table, will generate an instance of HuffmanEncodingTree 26 | class HuffmanEncodingTreeFactory 27 | { 28 | public: 29 | /// Default constructor 30 | HuffmanEncodingTreeFactory(); 31 | 32 | /// Reset the frequency table. You don't need to call this unless you want to reuse the class for a new tree 33 | void Reset( void ); 34 | 35 | /// Pass an array of bytes to this to add those elements to the frequency table 36 | /// \param[in] array the data to insert into the frequency table 37 | /// \param[in] size the size of the data to insert 38 | void AddToFrequencyTable( unsigned char *array, int size ); 39 | 40 | /// Copies the frequency table to the array passed 41 | /// Retrieve the frequency table 42 | /// \param[in] _frequency The frequency table used currently 43 | void GetFrequencyTable( unsigned int _frequency[ 256 ] ); 44 | 45 | /// Returns the frequency table as a pointer 46 | /// \return the address of the frenquency table 47 | unsigned int * GetFrequencyTable( void ); 48 | 49 | /// Generate a HuffmanEncodingTree. 50 | /// You can also use GetFrequencyTable and GenerateFromFrequencyTable in the tree itself 51 | /// \return The generated instance of HuffmanEncodingTree 52 | HuffmanEncodingTree * GenerateTree( void ); 53 | 54 | private: 55 | 56 | /// Frequency table 57 | unsigned int frequency[ 256 ]; 58 | }; 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /RakNet/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 | struct HuffmanEncodingTreeNode 22 | { 23 | unsigned char value; 24 | unsigned weight; 25 | HuffmanEncodingTreeNode *left; 26 | HuffmanEncodingTreeNode *right; 27 | HuffmanEncodingTreeNode *parent; 28 | }; 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /RakNet/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 DataStructures 8 | { 9 | template 10 | class MemoryPool 11 | { 12 | public: 13 | MemoryPool(); 14 | ~MemoryPool(); 15 | void Preallocate(unsigned numElements); 16 | MemoryBlockType *Allocate(void); 17 | void Release(MemoryBlockType *m); 18 | void Clear(void); 19 | protected: 20 | int blocksOut; 21 | DataStructures::List pool; 22 | }; 23 | 24 | template 25 | MemoryPool::MemoryPool() 26 | { 27 | #ifdef _DEBUG 28 | blocksOut=0; 29 | #endif 30 | } 31 | template 32 | MemoryPool::~MemoryPool() 33 | { 34 | #ifdef _DEBUG 35 | assert(blocksOut==0); 36 | #endif 37 | unsigned i; 38 | for (i=0; i < pool.Size(); i++) 39 | delete pool[i]; 40 | } 41 | 42 | template 43 | void MemoryPool::Preallocate(unsigned numElements) 44 | { 45 | unsigned i; 46 | for (i=pool.Size(); i < numElements; i++) 47 | { 48 | pool.Insert(new MemoryBlockType); 49 | } 50 | } 51 | 52 | template 53 | MemoryBlockType* MemoryPool::Allocate(void) 54 | { 55 | #ifdef _DEBUG 56 | blocksOut++; 57 | #endif 58 | if (pool.Size()==0) 59 | return new MemoryBlockType; 60 | else 61 | { 62 | MemoryBlockType* out; 63 | out=pool[pool.Size()-1]; 64 | pool.Del(); 65 | return out; 66 | } 67 | } 68 | template 69 | void MemoryPool::Release(MemoryBlockType *m) 70 | { 71 | pool.Insert(m); 72 | #ifdef _DEBUG 73 | assert(blocksOut>0); 74 | blocksOut--; 75 | #endif 76 | } 77 | template 78 | void MemoryPool::Clear(void) 79 | { 80 | #ifdef _DEBUG 81 | assert(blocksOut==0); 82 | #endif 83 | unsigned i; 84 | for (i=0; i < pool.Size(); i++) 85 | delete pool[i]; 86 | pool.Clear(); 87 | } 88 | } 89 | 90 | #endif 91 | -------------------------------------------------------------------------------- /RakNet/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 | /// The namespace DataStructures was only added to avoid compiler errors for commonly named data structures 25 | /// As these data structures are stand-alone, you can use them outside of RakNet for your own projects if you wish. 26 | namespace DataStructures 27 | { 28 | /// \brief A queue implemented using a linked list. Rarely used. 29 | template 30 | class RAK_DLL_EXPORT QueueLinkedList 31 | { 32 | 33 | public: 34 | QueueLinkedList(); 35 | QueueLinkedList( const QueueLinkedList& original_copy ); 36 | bool operator= ( const QueueLinkedList& original_copy ); 37 | QueueType Pop( void ); 38 | QueueType& Peek( void ); 39 | QueueType& EndPeek( void ); 40 | void Push( const QueueType& input ); 41 | unsigned int Size( void ); 42 | void Clear( void ); 43 | void Compress( void ); 44 | 45 | private: 46 | LinkedList data; 47 | }; 48 | 49 | template 50 | QueueLinkedList::QueueLinkedList() 51 | { 52 | } 53 | 54 | template 55 | inline unsigned int QueueLinkedList::Size() 56 | { 57 | return data.Size(); 58 | } 59 | 60 | template 61 | inline QueueType QueueLinkedList::Pop( void ) 62 | { 63 | data.Beginning(); 64 | return ( QueueType ) data.Pop(); 65 | } 66 | 67 | template 68 | inline QueueType& QueueLinkedList::Peek( void ) 69 | { 70 | data.Beginning(); 71 | return ( QueueType ) data.Peek(); 72 | } 73 | 74 | template 75 | inline QueueType& QueueLinkedList::EndPeek( void ) 76 | { 77 | data.End(); 78 | return ( QueueType ) data.Peek(); 79 | } 80 | 81 | template 82 | void QueueLinkedList::Push( const QueueType& input ) 83 | { 84 | data.End(); 85 | data.Add( input ); 86 | } 87 | 88 | template 89 | QueueLinkedList::QueueLinkedList( const QueueLinkedList& original_copy ) 90 | { 91 | data = original_copy.data; 92 | } 93 | 94 | template 95 | bool QueueLinkedList::operator= ( const QueueLinkedList& original_copy ) 96 | { 97 | if ( ( &original_copy ) == this ) 98 | return false; 99 | 100 | data = original_copy.data; 101 | } 102 | 103 | template 104 | void QueueLinkedList::Clear ( void ) 105 | { 106 | data.Clear(); 107 | } 108 | } // End namespace 109 | 110 | #endif 111 | -------------------------------------------------------------------------------- /RakNet/include/RakNet/DS_Tree.h: -------------------------------------------------------------------------------- 1 | /// \file 2 | /// \brief \b [Internal] Just a regular 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 __DS_TREE_H 19 | #define __DS_TREE_H 20 | 21 | #include "Export.h" 22 | #include "DS_List.h" 23 | #include "DS_Queue.h" 24 | 25 | /// The namespace DataStructures was only added to avoid compiler errors for commonly named data structures 26 | /// As these data structures are stand-alone, you can use them outside of RakNet for your own projects if you wish. 27 | namespace DataStructures 28 | { 29 | template 30 | class RAK_DLL_EXPORT Tree 31 | { 32 | public: 33 | Tree(); 34 | Tree(TreeType &inputData); 35 | ~Tree(); 36 | void LevelOrderTraversal(DataStructures::List &output); 37 | void AddChild(TreeType &newData); 38 | void DeleteDecendants(void); 39 | 40 | TreeType data; 41 | DataStructures::List children; 42 | }; 43 | 44 | template 45 | Tree::Tree() 46 | { 47 | 48 | } 49 | 50 | template 51 | Tree::Tree(TreeType &inputData) 52 | { 53 | data=inputData; 54 | } 55 | 56 | template 57 | Tree::~Tree() 58 | { 59 | } 60 | 61 | template 62 | void Tree::LevelOrderTraversal(DataStructures::List &output) 63 | { 64 | unsigned i; 65 | Tree *node; 66 | DataStructures::Queue*> queue; 67 | 68 | for (i=0; i < children.Size(); i++) 69 | queue.Push(children[i]); 70 | 71 | while (queue.Size()) 72 | { 73 | node=queue.Pop(); 74 | output.Insert(node); 75 | for (i=0; i < node->children.Size(); i++) 76 | queue.Push(node->children[i]); 77 | } 78 | } 79 | 80 | template 81 | void Tree::AddChild(TreeType &newData) 82 | { 83 | children.Insert(new Tree(newData)); 84 | } 85 | 86 | template 87 | void Tree::DeleteDecendants(void) 88 | { 89 | DataStructures::List output; 90 | LevelOrderTraversal(output); 91 | unsigned i; 92 | for (i=0; i < output.Size(); i++) 93 | delete output[i]; 94 | } 95 | } 96 | 97 | #endif 98 | -------------------------------------------------------------------------------- /RakNet/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 | /// Encrypts and decrypts data blocks. 24 | class DataBlockEncryptor 25 | { 26 | 27 | public: 28 | 29 | /// Constructor 30 | DataBlockEncryptor(); 31 | 32 | /// Destructor 33 | ~DataBlockEncryptor(); 34 | 35 | /// \return true if SetKey has been called previously 36 | bool IsKeySet( void ) const; 37 | 38 | /// Set the encryption key 39 | /// \param[in] key The new encryption key 40 | void SetKey( const unsigned char key[ 16 ] ); 41 | 42 | /// Unset the encryption key 43 | void UnsetKey( void ); 44 | 45 | /// Encryption adds up to 15 bytes. Output should be large enough to hold this. 46 | /// Output can be the same memory block as input 47 | /// \param[in] input the input buffer to encrypt 48 | /// \param[in] inputLength the size of the @em input buffer 49 | /// \param[in] output the output buffer to store encrypted data 50 | /// \param[in] outputLength the size of the output buffer 51 | void Encrypt( unsigned char *input, int inputLength, unsigned char *output, int *outputLength ); 52 | 53 | /// Decryption removes bytes, as few as 6. Output should be large enough to hold this. 54 | /// Output can be the same memory block as input 55 | /// \param[in] input the input buffer to decrypt 56 | /// \param[in] inputLength the size of the @em input buffer 57 | /// \param[in] output the output buffer to store decrypted data 58 | /// \param[in] outputLength the size of the @em output buffer 59 | /// \return False on bad checksum or input, true on success 60 | bool Decrypt( unsigned char *input, int inputLength, unsigned char *output, int *outputLength ); 61 | 62 | protected: 63 | 64 | keyInstance keyEncrypt; 65 | keyInstance keyDecrypt; 66 | cipherInstance cipherInst; 67 | bool keySet; 68 | }; 69 | 70 | #endif 71 | -------------------------------------------------------------------------------- /RakNet/include/RakNet/DataCompressor.h: -------------------------------------------------------------------------------- 1 | /// \file 2 | /// \brief DataCompressor does compression on a block of data. Not very good compression, but it's small and fast so is something you can use per-message at runtime. 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 __DATA_COMPRESSOR_H 20 | #define __DATA_COMPRESSOR_H 21 | 22 | #include "DS_HuffmanEncodingTree.h" 23 | #include "Export.h" 24 | 25 | /// \brief Does compression on a block of data. Not very good compression, but it's small and fast so is something you can compute at runtime. 26 | class RAK_DLL_EXPORT DataCompressor 27 | { 28 | public: 29 | static void Compress( unsigned char *userData, unsigned sizeInBytes, RakNet::BitStream * output ); 30 | static unsigned DecompressAndAllocate( RakNet::BitStream * input, unsigned char **output ); 31 | }; 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /RakNet/include/RakNet/EmailSender.h: -------------------------------------------------------------------------------- 1 | /// \file 2 | /// \brief Rudimentary class to send email from code. Don't expect anything fancy. 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 __EMAIL_SENDER_H 19 | #define __EMAIL_SENDER_H 20 | 21 | class FileList; 22 | class TCPInterface; 23 | #include "NetworkTypes.h" 24 | 25 | /// \brief Rudimentary class to send email from code. 26 | class EmailSender 27 | { 28 | public: 29 | /// Sends an email 30 | /// \param[in] hostAddress The address of the email server. 31 | /// \param[in] hostPort The port of the email server (usually 25) 32 | /// \param[in] sender The email address you are sending from. 33 | /// \param[in] recipient The email address you are sending to. 34 | /// \param[in] senderName The email address you claim to be sending from 35 | /// \param[in] recipientName The email address you claim to be sending to 36 | /// \param[in] subject Email subject 37 | /// \param[in] body Email body 38 | /// \param[in] attachedFiles List of files to attach to the email. (Can be 0 to send none). 39 | /// \param[in] doPrintf true to output SMTP info to console(for debugging?) 40 | /// \return 0 on success, otherwise a string indicating the error message 41 | char *Send(const char *hostAddress, unsigned short hostPort, const char *sender, const char *recipient, const char *senderName, const char *recipientName, const char *subject, const char *body, FileList *attachedFiles, bool doPrintf); 42 | 43 | // Returns how many bytes were written 44 | int Base64Encoding(const char *inputData, int dataLength, char *outputData, const char *base64Map); 45 | protected: 46 | char *GetResponse(TCPInterface *tcpInterface, const PlayerID &emailServer, bool doPrintf); 47 | }; 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /RakNet/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 | -------------------------------------------------------------------------------- /RakNet/include/RakNet/ExtendedOverlappedPool.h: -------------------------------------------------------------------------------- 1 | /// \file 2 | /// \brief \b [Depreciated] This was used for 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 | // No longer used as I no longer support IO Completion ports 19 | /* 20 | #ifdef __USE_IO_COMPLETION_PORTS 21 | #ifndef __EXTENDED_OVERLAPPED_POOL 22 | #define __EXTENDED_OVERLAPPED_POOL 23 | #include "SimpleMutex.h" 24 | #include "ClientContextStruct.h" 25 | #include "DS_Queue.h" 26 | 27 | /// Depreciated - for IO completion ports 28 | class ExtendedOverlappedPool 29 | { 30 | 31 | public: 32 | ExtendedOverlappedPool(); 33 | ~ExtendedOverlappedPool(); 34 | ExtendedOverlappedStruct* GetPointer( void ); 35 | void ReleasePointer( ExtendedOverlappedStruct *p ); 36 | static inline ExtendedOverlappedPool* Instance() 37 | { 38 | return & I; 39 | } 40 | 41 | private: 42 | DataStructures::Queue pool; 43 | SimpleMutex poolMutex; 44 | static ExtendedOverlappedPool I; 45 | }; 46 | 47 | #endif 48 | #endif 49 | 50 | */ 51 | -------------------------------------------------------------------------------- /RakNet/include/RakNet/FileOperations.h: -------------------------------------------------------------------------------- 1 | #ifndef __FILE_OPERATIONS_H 2 | #define __FILE_OPERATIONS_H 3 | 4 | #include "Export.h" 5 | 6 | bool RAK_DLL_EXPORT WriteFileWithDirectories( const char *path, char *data, unsigned dataLength ); 7 | bool RAK_DLL_EXPORT IsSlash(unsigned char c); 8 | void RAK_DLL_EXPORT AddSlash( char *input ); 9 | void RAK_DLL_EXPORT QuoteIfSpaces(char *str); 10 | bool RAK_DLL_EXPORT DirectoryExists(const char *directory); 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /RakNet/include/RakNet/FullyConnectedMesh.h: -------------------------------------------------------------------------------- 1 | /// \file 2 | /// \brief Fully connected mesh plugin. This will connect RakPeer to all connecting peers, and all peers the connecting peer knows about. 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 __FULLY_CONNECTED_MESH_H 19 | #define __FULLY_CONNECTED_MESH_H 20 | 21 | class RakPeerInterface; 22 | #include "PluginInterface.h" 23 | 24 | /// \defgroup FULLY_CONNECTED_MESH_GROUP FullyConnectedMesh 25 | /// \ingroup PLUGINS_GROUP 26 | 27 | /// Fully connected mesh plugin. This will connect RakPeer to all connecting peers, and all peers the connecting peer knows about. 28 | /// \pre You must also install the ConnectionGraph plugin. If you want a password, set it there. 29 | /// \ingroup FULLY_CONNECTED_MESH_GROUP 30 | class FullyConnectedMesh : public PluginInterface 31 | { 32 | public: 33 | FullyConnectedMesh(); 34 | virtual ~FullyConnectedMesh(); 35 | 36 | // -------------------------------------------------------------------------------------------- 37 | // User functions 38 | // -------------------------------------------------------------------------------------------- 39 | // Set the password to use to connect to the other systems 40 | void Initialize(const char *password); 41 | 42 | // -------------------------------------------------------------------------------------------- 43 | // Packet handling functions 44 | // -------------------------------------------------------------------------------------------- 45 | virtual void OnDisconnect(RakPeerInterface *peer); 46 | virtual void Update(RakPeerInterface *peer); 47 | virtual PluginReceiveResult OnReceive(RakPeerInterface *peer, Packet *packet); 48 | 49 | 50 | protected: 51 | char *pw; 52 | }; 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /RakNet/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 | -------------------------------------------------------------------------------- /RakNet/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 | /// 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 26 | /// were to wrap, the newly wrapped values would no longer be in use. Warning: Too large of a value wastes bandwidth! 27 | typedef unsigned short OrderingIndexType; 28 | 29 | typedef unsigned short SplitPacketIdType; 30 | typedef unsigned int SplitPacketIndexType; 31 | 32 | 33 | /// This is the counter used for holding packet numbers, so we can detect duplicate packets. It should be large enough that if the variables 34 | /// were to wrap, the newly wrapped values would no longer be in use. Warning: Too large of a value wastes bandwidth! 35 | /// Use the smallest possible value, such that you send no more than rangeof(MessageNumberType) / GetTimeoutTime() packets per second 36 | /// For the default value of 10 seconds, this is 37 | /// unsigned char - 25.5 packets per second 38 | /// unsigned short - 6553.5 packets per second 39 | /// unsigned int - You'll run out of memory first. 40 | typedef unsigned short MessageNumberType; 41 | 42 | /// Holds a user message, and related information 43 | struct InternalPacket 44 | { 45 | ///True if this is an acknowledgment packet 46 | //bool isAcknowledgement; 47 | 48 | ///A unique numerical identifier given to this user message 49 | MessageNumberType messageNumber; 50 | /// Used only for tracking packetloss and windowing internally, this is the aggreggate packet number that a message was last sent in 51 | unsigned packetNumber; 52 | /// Was this packet number used this update to track windowing drops or increases? Each packet number is only used once per update. 53 | // bool allowWindowUpdate; 54 | ///The priority level of this packet 55 | PacketPriority priority; 56 | ///What type of reliability algorithm to use with this packet 57 | PacketReliability reliability; 58 | ///What ordering channel this packet is on, if the reliability type uses ordering channels 59 | unsigned char orderingChannel; 60 | ///The ID used as identification for ordering channels 61 | OrderingIndexType orderingIndex; 62 | ///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. 63 | SplitPacketIdType splitPacketId; 64 | ///If this is a split packet, the index into the array of subsplit packets 65 | SplitPacketIndexType splitPacketIndex; 66 | ///The size of the array of subsplit packets 67 | SplitPacketIndexType splitPacketCount; 68 | ///When this packet was created 69 | RakNetTimeNS creationTime; 70 | ///The next time to take action on this packet 71 | RakNetTimeNS nextActionTime; 72 | ///How many bits the data is 73 | unsigned int dataBitLength; 74 | ///Buffer is a pointer to the actual data, assuming this packet has data at all 75 | unsigned char *data; 76 | /// For checking packetloss at a particular send rate 77 | unsigned histogramMarker; 78 | }; 79 | 80 | #endif 81 | 82 | -------------------------------------------------------------------------------- /RakNet/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 | /// Handles of a pool of InternalPacket pointers. This is only here for efficiency. 24 | /// \sa InternalPacket.h 25 | class InternalPacketPool 26 | { 27 | public: 28 | 29 | /// Constructor 30 | InternalPacketPool(); 31 | 32 | /// Destructor 33 | ~InternalPacketPool(); 34 | 35 | /// Get an InternalPacket pointer. Will either allocate a new one or return one from the pool 36 | /// \return An InternalPacket pointer. 37 | InternalPacket* GetPointer( void ) 38 | {if ( pool.Size() ) 39 | return pool.Pop(); 40 | return new InternalPacket;} 41 | 42 | /// Return an InternalPacket pointer to the pool. 43 | /// \param[in] p A pointer to an InternalPacket you no longer need. 44 | void ReleasePointer( InternalPacket *p ); 45 | 46 | // Delete all InternalPacket pointers in the pool. 47 | void ClearPool( void ); 48 | 49 | private: 50 | /// Queue of internal packets 51 | DataStructures::Queue pool; 52 | }; 53 | 54 | #endif 55 | 56 | -------------------------------------------------------------------------------- /RakNet/include/RakNet/LinuxStrings.h: -------------------------------------------------------------------------------- 1 | #ifndef _GCC_WIN_STRINGS 2 | #define _GCC_WIN_STRINGS 3 | 4 | #if (defined(__GNUC__) || defined(__GCCXML__)) 5 | int _stricmp(const char* s1, const char* s2); 6 | int _strnicmp(const char* s1, const char* s2, size_t n); 7 | //#ifndef __CYGWIN__ 8 | //int _unlink(const char* filename); 9 | //#endif 10 | 11 | #endif 12 | #endif 13 | -------------------------------------------------------------------------------- /RakNet/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 576 42 | 43 | #endif 44 | 45 | -------------------------------------------------------------------------------- /RakNet/include/RakNet/PacketEnumerations.h: -------------------------------------------------------------------------------- 1 | /// \file 2 | /// \brief All the packet identifiers used by RakNet. Packet identifiers comprise the first byte of any 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 __PACKET_ENUMERATIONS_H 19 | #define __PACKET_ENUMERATIONS_H 20 | 21 | /// You should not edit the file PacketEnumerations.h as it is a part of RakNet static library 22 | /// To define your own message id, define an enum following the code example that follows. 23 | /// 24 | /// \code 25 | /// enum { 26 | /// ID_MYPROJECT_MSG_1 = ID_USER_PACKET_ENUM 27 | /// ID_MYPROJECT_MSG_2, 28 | /// ... 29 | /// }; 30 | /// \endcode 31 | /// 32 | /// \note All these enumerations should be casted to (unsigned char) before writing them to RakNet::BitStream 33 | 34 | enum PacketEnumeration 35 | { 36 | ID_INTERNAL_PING = 6, 37 | ID_PING, 38 | ID_PING_OPEN_CONNECTIONS, 39 | ID_CONNECTED_PONG, 40 | ID_REQUEST_STATIC_DATA, 41 | ID_CONNECTION_REQUEST, 42 | ID_AUTH_KEY, 43 | ID_BROADCAST_PINGS = 14, 44 | ID_SECURED_CONNECTION_RESPONSE, 45 | ID_SECURED_CONNECTION_CONFIRMATION, 46 | ID_RPC_MAPPING, 47 | ID_SET_RANDOM_NUMBER_SEED = 19, 48 | ID_RPC, 49 | ID_RPC_REPLY, 50 | ID_DETECT_LOST_CONNECTIONS = 23, 51 | ID_OPEN_CONNECTION_REQUEST, 52 | ID_OPEN_CONNECTION_REPLY, 53 | ID_OPEN_CONNECTION_COOKIE, 54 | ID_RSA_PUBLIC_KEY_MISMATCH = 28, 55 | ID_CONNECTION_ATTEMPT_FAILED, 56 | ID_NEW_INCOMING_CONNECTION = 30, 57 | ID_NO_FREE_INCOMING_CONNECTIONS = 31, 58 | ID_DISCONNECTION_NOTIFICATION, 59 | ID_CONNECTION_LOST, 60 | ID_CONNECTION_REQUEST_ACCEPTED, 61 | ID_CONNECTION_BANNED = 36, 62 | ID_INVALID_PASSWORD, 63 | ID_MODIFIED_PACKET, 64 | ID_PONG, 65 | ID_TIMESTAMP, 66 | ID_RECEIVED_STATIC_DATA, 67 | ID_REMOTE_DISCONNECTION_NOTIFICATION, 68 | ID_REMOTE_CONNECTION_LOST, 69 | ID_REMOTE_NEW_INCOMING_CONNECTION, 70 | ID_REMOTE_EXISTING_CONNECTION, 71 | ID_REMOTE_STATIC_DATA, 72 | ID_ADVERTISE_SYSTEM = 55, 73 | 74 | ID_PLAYER_SYNC = 207, 75 | ID_MARKERS_SYNC = 208, 76 | ID_UNOCCUPIED_SYNC = 209, 77 | ID_TRAILER_SYNC = 210, 78 | ID_PASSENGER_SYNC = 211, 79 | ID_SPECTATOR_SYNC = 212, 80 | ID_AIM_SYNC = 203, 81 | ID_VEHICLE_SYNC = 200, 82 | ID_RCON_COMMAND = 201, 83 | ID_RCON_RESPONCE = 202, 84 | ID_WEAPONS_UPDATE = 204, 85 | ID_STATS_UPDATE = 205, 86 | ID_BULLET_SYNC = 206, 87 | }; 88 | 89 | #endif 90 | 91 | -------------------------------------------------------------------------------- /RakNet/include/RakNet/PacketPool.h: -------------------------------------------------------------------------------- 1 | /// \file 2 | /// \brief \b [Internal] A pool for the Packet class. I don't believe this is used any longer. 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 | // TODO - Remove this file from the project 19 | /* 20 | #ifndef __PACKET_POOL 21 | #define __PACKET_POOL 22 | #include "SimpleMutex.h" 23 | #include "DS_Queue.h" 24 | 25 | struct Packet; 26 | 27 | class PacketPool 28 | { 29 | 30 | public: 31 | PacketPool(); 32 | ~PacketPool(); 33 | 34 | static void AddReference(void); 35 | static void RemoveReference(void); 36 | Packet* GetPointer( void ); 37 | void ReleasePointer( Packet *p ); 38 | void ClearPool( void ); 39 | static inline PacketPool* Instance() 40 | { 41 | return I; 42 | } 43 | 44 | private: 45 | DataStructures::Queue pool; 46 | SimpleMutex poolMutex; 47 | static PacketPool *I; 48 | static int referenceCount; 49 | #ifdef _DEBUG 50 | int packetsReleased; 51 | #endif 52 | }; 53 | 54 | #endif 55 | 56 | */ -------------------------------------------------------------------------------- /RakNet/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 | /// These enumerations are used to describe when packets are delivered. 22 | enum PacketPriority 23 | { 24 | SYSTEM_PRIORITY, /// \internal Used by RakNet to send above-high priority messages. 25 | HIGH_PRIORITY, /// High priority messages are send before medium priority messages. 26 | MEDIUM_PRIORITY, /// Medium priority messages are send before low priority messages. 27 | LOW_PRIORITY, /// Low priority messages are only sent when no other messages are waiting. 28 | NUMBER_OF_PRIORITIES 29 | }; 30 | 31 | /// These enumerations are used to describe how packets are delivered. 32 | /// \note Note to self: I write this with 3 bits in the stream. If I add more remember to change that 33 | enum PacketReliability 34 | { 35 | UNRELIABLE = 6, /// 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. 36 | 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. 37 | RELIABLE, /// The message is sent reliably, but not necessarily in any order. Same overhead as UNRELIABLE. 38 | 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. 39 | 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. 40 | }; 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /RakNet/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 | /// \ingroup RAKNET_RPC 29 | /// \internal 30 | /// \brief A container class for a list of RPCNodes 31 | struct RAK_DLL_EXPORT RPCMap 32 | { 33 | public: 34 | RPCMap(); 35 | ~RPCMap(); 36 | void Clear(void); 37 | RPCNode *GetNodeFromIndex(RPCIndex index); 38 | RPCNode *GetNodeFromFunctionName(int *uniqueIdentifier); 39 | RPCIndex GetIndexFromFunctionName(int *uniqueIdentifier); 40 | void AddIdentifierWithFunction(int *uniqueIdentifier, void *functionPointer, bool isPointerToMember); 41 | void AddIdentifierAtIndex(RPCIndex insertionIndex); 42 | void RemoveNode(int *uniqueIdentifier); 43 | protected: 44 | DataStructures::List rpcSet; 45 | }; 46 | 47 | #endif 48 | 49 | -------------------------------------------------------------------------------- /RakNet/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 | class RakPeerInterface; 27 | 28 | 29 | /// \defgroup RAKNET_RPC Remote Procedure Call Subsystem 30 | /// \brief A system to call C or object member procudures on other systems, and even to return return values. 31 | 32 | /// \ingroup RAKNET_RPC 33 | /// \internal 34 | /// 35 | /// \brief Map registered procedure inside of a peer. 36 | /// 37 | struct RAK_DLL_EXPORT RPCNode 38 | { 39 | 40 | /// String identifier of the RPC 41 | int uniqueIdentifier; 42 | 43 | /// Force casting of member functions to void * 44 | union 45 | { 46 | void ( *staticFunctionPointer ) ( RPCParameters *rpcParms ); 47 | #if (defined(__GNUC__) || defined(__GCCXML__)) 48 | void (*memberFunctionPointer)(void* _this, RPCParameters *rpcParms); 49 | #else 50 | void (__cdecl *memberFunctionPointer)(void* _this, RPCParameters *rpcParms); 51 | #endif 52 | 53 | void *functionPointer; 54 | }; 55 | 56 | /// Is this a member function pointer? True if so. If false it's a regular C function. 57 | bool isPointerToMember; 58 | }; 59 | 60 | #endif 61 | 62 | -------------------------------------------------------------------------------- /RakNet/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 | -------------------------------------------------------------------------------- /RakNet/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 | class RakPeerInterface; 24 | 25 | /// \brief This allows a console client to call most of the functions in RakPeer 26 | class RAK_DLL_EXPORT RakNetCommandParser : public CommandParserInterface 27 | { 28 | public: 29 | RakNetCommandParser(); 30 | ~RakNetCommandParser(); 31 | 32 | /// Given \a command with parameters \a parameterList , do whatever processing you wish. 33 | /// \param[in] command The command to process 34 | /// \param[in] numParameters How many parameters were passed along with the command 35 | /// \param[in] parameterList The list of parameters. parameterList[0] is the first parameter and so on. 36 | /// \param[in] transport The transport interface we can use to write to 37 | /// \param[in] playerId The player that sent this command. 38 | /// \param[in] originalString The string that was actually sent over the network, in case you want to do your own parsing 39 | bool OnCommand(const char *command, unsigned numParameters, char **parameterList, TransportInterface *transport, PlayerID playerId, const char *originalString); 40 | 41 | /// You are responsible for overriding this function and returning a static string, which will identifier your parser. 42 | /// This should return a static string 43 | /// \return The name that you return. 44 | char *GetName(void) const; 45 | 46 | /// A callback for when you are expected to send a brief description of your parser to \a playerId 47 | /// \param[in] transport The transport interface we can use to write to 48 | /// \param[in] playerId The player that requested help. 49 | void SendHelp(TransportInterface *transport, PlayerID playerId); 50 | 51 | /// Records the instance of RakPeer to perform the desired commands on 52 | /// \param[in] rakPeer The RakPeer instance, or a derived class (e.g. RakServer or RakClient) 53 | void SetRakPeerInterface(RakPeerInterface *rakPeer); 54 | protected: 55 | 56 | /// Which instance of RakPeer we are working on. Set from SetRakPeerInterface() 57 | RakPeerInterface *peer; 58 | }; 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /RakNet/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 | -------------------------------------------------------------------------------- /RakNet/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 | class RakClientInterface; 24 | class RakServerInterface; 25 | class RakPeerInterface; 26 | 27 | class RAK_DLL_EXPORT RakNetworkFactory 28 | { 29 | public: 30 | // For DLL's, these are user classes that you might want to new and delete. 31 | // You can't instantiate exported classes directly in your program. The instantiation 32 | // has to take place inside the DLL. So these functions will do the news and deletes for you. 33 | // if you're using the source or static library you don't need these functions, but can use them if you want. 34 | static RakClientInterface* GetRakClientInterface( void ); 35 | static RakServerInterface* GetRakServerInterface( void ); 36 | static RakPeerInterface* GetRakPeerInterface( void ); 37 | 38 | 39 | // To delete the object returned by the Get functions above. 40 | static void DestroyRakClientInterface( RakClientInterface* i ); 41 | static void DestroyRakServerInterface( RakServerInterface* i ); 42 | static void DestroyRakPeerInterface( RakPeerInterface* i ); 43 | }; 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /RakNet/include/RakNet/RakSleep.h: -------------------------------------------------------------------------------- 1 | #ifndef __RAK_SLEEP_H 2 | #define __RAK_SLEEP_H 3 | 4 | void RakSleep(unsigned int ms); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /RakNet/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 | /// Initialise seed for Random Generator 25 | /// \param[in] seed The seed value for the random number generator. 26 | extern void RAK_DLL_EXPORT seedMT( unsigned int seed ); 27 | 28 | /// \internal 29 | extern unsigned int RAK_DLL_EXPORT reloadMT( void ); 30 | 31 | /// Gets a random unsigned int 32 | /// \return an integer random value. 33 | extern unsigned int RAK_DLL_EXPORT randomMT( void ); 34 | 35 | /// Gets a random float 36 | /// \return 0 to 1.0f, inclusive 37 | extern float RAK_DLL_EXPORT frandomMT( void ); 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /RakNet/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 | /// Replica interface flags, used to enable and disable function calls on the Replica object 22 | /// Passed to ReplicaManager::EnableReplicaInterfaces and ReplicaManager::DisableReplicaInterfaces 23 | enum 24 | { 25 | REPLICA_RECEIVE_DESTRUCTION=1<<0, 26 | REPLICA_RECEIVE_SERIALIZE=1<<1, 27 | REPLICA_RECEIVE_SCOPE_CHANGE=1<<2, 28 | REPLICA_SEND_CONSTRUCTION=1<<3, 29 | REPLICA_SEND_DESTRUCTION=1<<4, 30 | REPLICA_SEND_SCOPE_CHANGE=1<<5, 31 | REPLICA_SEND_SERIALIZE=1<<6, 32 | REPLICA_SET_ALL = 0xFF // Allow all of the above 33 | }; 34 | 35 | enum ReplicaReturnResult 36 | { 37 | /// This means call the function again later, with the same parameters 38 | REPLICA_PROCESS_LATER, 39 | /// This means we are done processing (the normal result to return) 40 | REPLICA_PROCESSING_DONE, 41 | /// This means cancel the processing - don't send any network messages and don't change the current state. 42 | REPLICA_CANCEL_PROCESS, 43 | /// Same as REPLICA_PROCESSING_DONE, where a message is sent, but does not clear the send bit. 44 | /// Useful for multi-part sends with different reliability levels. 45 | /// Only currently used by Replica::Serialize 46 | REPLICA_PROCESS_AGAIN, 47 | }; 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /RakNet/include/RakNet/RouterInterface.h: -------------------------------------------------------------------------------- 1 | #ifndef __ROUTER_INTERFACE_H 2 | #define __ROUTER_INTERFACE_H 3 | 4 | #include "Export.h" 5 | #include "PacketPriority.h" 6 | #include "NetworkTypes.h" 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 | #endif 16 | -------------------------------------------------------------------------------- /RakNet/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 | class RAK_DLL_EXPORT CSHA1 32 | { 33 | 34 | public: 35 | // Rotate x bits to the left 36 | // #define ROL32(value, bits) (((value)<<(bits))|((value)>>(32-(bits)))) 37 | 38 | #ifdef LITTLE_ENDIAN 39 | #define SHABLK0(i) (block->l[i] = (ROL32(block->l[i],24) & 0xFF00FF00) \ 40 | | (ROL32(block->l[i],8) & 0x00FF00FF)) 41 | #else 42 | #define SHABLK0(i) (block->l[i]) 43 | #endif 44 | 45 | #define SHABLK(i) (block->l[i&15] = ROL32(block->l[(i+13)&15] ^ block->l[(i+8)&15] \ 46 | ^ block->l[(i+2)&15] ^ block->l[i&15],1)) 47 | 48 | // SHA-1 rounds 49 | #define R0(v,w,x,y,z,i) { z+=((w&(x^y))^y)+SHABLK0(i)+0x5A827999+ROL32(v,5); w=ROL32(w,30); } 50 | #define R1(v,w,x,y,z,i) { z+=((w&(x^y))^y)+SHABLK(i)+0x5A827999+ROL32(v,5); w=ROL32(w,30); } 51 | #define R2(v,w,x,y,z,i) { z+=(w^x^y)+SHABLK(i)+0x6ED9EBA1+ROL32(v,5); w=ROL32(w,30); } 52 | #define R3(v,w,x,y,z,i) { z+=(((w|x)&y)|(w&x))+SHABLK(i)+0x8F1BBCDC+ROL32(v,5); w=ROL32(w,30); } 53 | #define R4(v,w,x,y,z,i) { z+=(w^x^y)+SHABLK(i)+0xCA62C1D6+ROL32(v,5); w=ROL32(w,30); } 54 | 55 | typedef union { 56 | unsigned char c[ 64 ]; 57 | unsigned int l[ 16 ]; 58 | } SHA1_WORKSPACE_BLOCK; 59 | /* Two different formats for ReportHash(...) 60 | */ 61 | enum { REPORT_HEX = 0, 62 | REPORT_DIGIT = 1}; 63 | 64 | CSHA1(); 65 | virtual ~CSHA1(); 66 | 67 | unsigned int m_state[ 5 ]; 68 | unsigned int m_count[ 2 ]; 69 | unsigned char m_buffer[ 64 ]; 70 | unsigned char m_digest[ 20 ]; 71 | void Reset(); 72 | void Update( unsigned char* data, unsigned int len ); 73 | bool HashFile( char *szFileName ); 74 | void Final(); 75 | void ReportHash( char *szReport, unsigned char uReportType = REPORT_HEX ); 76 | void GetHash( unsigned char *uDest ); 77 | unsigned char * GetHash( void ) const; 78 | 79 | private: 80 | void Transform( unsigned int state[ 5 ], unsigned char buffer[ 64 ] ); 81 | unsigned char workspace[ 64 ]; 82 | }; 83 | 84 | #endif // ___SHA1_H___ 85 | 86 | -------------------------------------------------------------------------------- /RakNet/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 | /// \brief An easy to use mutex. 31 | /// 32 | /// I wrote this because the version that comes with Windows is too complicated and requires too much code to use. 33 | /// @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. 34 | class RAK_DLL_EXPORT SimpleMutex 35 | { 36 | public: 37 | 38 | /// Constructor 39 | SimpleMutex(); 40 | 41 | // Destructor 42 | ~SimpleMutex(); 43 | 44 | // Locks the mutex. Slow! 45 | void Lock(void); 46 | 47 | // Unlocks the mutex. 48 | void Unlock(void); 49 | private: 50 | #ifdef _WIN32 51 | CRITICAL_SECTION criticalSection; /// Docs say this is faster than a mutex for single process access 52 | #else 53 | pthread_mutex_t hMutex; 54 | #endif 55 | }; 56 | 57 | #endif 58 | 59 | -------------------------------------------------------------------------------- /RakNet/include/RakNet/SimpleTCPServer.h: -------------------------------------------------------------------------------- 1 | /// \file 2 | /// \brief A simple TCP based server allowing sends and receives. Can be connected by any TCP client, including telnet. 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_TCP_SERVER 19 | #define __SIMPLE_TCP_SERVER 20 | 21 | #ifdef _COMPATIBILITY_1 22 | #include "Compatibility1Includes.h" 23 | #elif defined(_WIN32) 24 | #include 25 | #include 26 | #else 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | /// Unix/Linux uses ints for sockets 34 | typedef int SOCKET; 35 | #define INVALID_SOCKET -1 36 | #define SOCKET_ERROR -1 37 | #endif 38 | 39 | #include "DS_List.h" 40 | #include "NetworkTypes.h" 41 | #include "SingleProducerConsumer.h" 42 | #include "Export.h" 43 | 44 | struct RemoteClient; 45 | 46 | /// \internal 47 | /// \brief As the name says, a simple multithreaded TCP server. Used by TelnetTransport 48 | class RAK_DLL_EXPORT SimpleTCPServer 49 | { 50 | public: 51 | SimpleTCPServer(); 52 | ~SimpleTCPServer(); 53 | 54 | /// Starts the TCP server on the indicated port 55 | bool Start(unsigned short port); 56 | 57 | /// Stops the TCP server 58 | void Stop(void); 59 | 60 | /// Sends a byte stream 61 | void Send( const char *data, unsigned length, PlayerID playerId ); 62 | 63 | /// Returns data received 64 | Packet* Receive( void ); 65 | 66 | /// Disconnects a player/address 67 | void CloseConnection( PlayerID playerId ); 68 | 69 | /// Deallocates a packet returned by Receive 70 | void DeallocatePacket( Packet *packet ); 71 | 72 | /// Queued events of new connections 73 | PlayerID HasNewConnection(void); 74 | 75 | /// Queued events of lost connections 76 | PlayerID HasLostConnection(void); 77 | protected: 78 | 79 | bool isStarted, threadRunning; 80 | SOCKET listenSocket; 81 | 82 | DataStructures::List remoteClients; 83 | DataStructures::SingleProducerConsumer outgoingMessages, incomingMessages; 84 | DataStructures::SingleProducerConsumer newConnections, lostConnections, requestedCloseConnections; 85 | 86 | #ifdef _WIN32 87 | HANDLE threadHandle; 88 | friend unsigned __stdcall UpdateTCPServerLoop( LPVOID arguments ); 89 | #else 90 | pthread_t threadHandle; 91 | friend void* UpdateTCPServerLoop( void* arguments ); 92 | #endif 93 | 94 | void DeleteRemoteClient(RemoteClient *remoteClient, fd_set *exceptionFD); 95 | }; 96 | 97 | /// Stores information about a remote client. In this case, only the socket used by that client. 98 | struct RemoteClient 99 | { 100 | SOCKET socket; 101 | PlayerID playerId; 102 | }; 103 | 104 | #endif 105 | -------------------------------------------------------------------------------- /RakNet/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 | 30 | class HuffmanEncodingTree; 31 | 32 | /// \brief Writes and reads strings to and from bitstreams. 33 | /// 34 | /// Only works with ASCII strings. The default compression is for English. 35 | /// You can call GenerateTreeFromStrings to compress and decompress other languages efficiently as well. 36 | class RAK_DLL_EXPORT StringCompressor 37 | { 38 | public: 39 | 40 | /// Destructor 41 | ~StringCompressor(); 42 | 43 | /// static function because only static functions can access static members 44 | /// 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. 45 | /// \return the unique instance of the StringCompressor 46 | static StringCompressor* Instance(void); 47 | 48 | /// Given an array of strings, such as a chat log, generate the optimal encoding tree for it. 49 | /// This function is optional and if it is not called a default tree will be used instead. 50 | /// \param[in] input An array of bytes which should point to text. 51 | /// \param[in] inputLength Length of \a input 52 | /// \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. 53 | void GenerateTreeFromStrings( unsigned char *input, unsigned inputLength, int languageID ); 54 | 55 | /// Writes input to output, compressed. Takes care of the null terminator for you. 56 | /// \param[in] input Pointer to an ASCII string 57 | /// \param[in] maxCharsToWrite The max number of bytes to write of \a input. Use 0 to mean no limit. 58 | /// \param[out] output The bitstream to write the compressed string to 59 | /// \param[in] languageID Which language to use 60 | void EncodeString( const char *input, int maxCharsToWrite, RakNet::BitStream *output, int languageID=0 ); 61 | 62 | /// Writes input to output, uncompressed. Takes care of the null terminator for you. 63 | /// \param[out] output A block of bytes to receive the output 64 | /// \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. 65 | /// \param[in] input The bitstream containing the compressed string 66 | /// \param[in] languageID Which language to use 67 | bool DecodeString( char *output, int maxCharsToWrite, RakNet::BitStream *input, int languageID=0 ); 68 | 69 | /// Used so I can allocate and deallocate this singleton at runtime 70 | static void AddReference(void); 71 | 72 | /// Used so I can allocate and deallocate this singleton at runtime 73 | static void RemoveReference(void); 74 | 75 | private: 76 | 77 | /// Private Constructor 78 | StringCompressor(); 79 | 80 | /// Singleton instance 81 | static StringCompressor *instance; 82 | 83 | /// Pointer to the huffman encoding trees. 84 | DataStructures::Map huffmanEncodingTrees; 85 | 86 | static int referenceCount; 87 | }; 88 | 89 | /// Define to more easily reference the string compressor instance. 90 | /// 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. 91 | #define stringCompressor StringCompressor::Instance() 92 | 93 | #endif 94 | -------------------------------------------------------------------------------- /RakNet/include/RakNet/SystemAddressList.h: -------------------------------------------------------------------------------- 1 | /// \file 2 | /// \brief Just a class to hold a list of systems 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 __SYSTEM_ID_LIST_H 19 | #define __SYSTEM_ID_LIST_H 20 | 21 | #include "NetworkTypes.h" 22 | #include "DS_OrderedList.h" 23 | 24 | class SystemAddressList 25 | { 26 | public: 27 | SystemAddressList(); 28 | SystemAddressList(PlayerID system); 29 | void AddSystem(PlayerID system); 30 | void RandomizeOrder(void); 31 | void Serialize(RakNet::BitStream *out); 32 | bool Deserialize(RakNet::BitStream *in); 33 | bool Save(const char *filename); 34 | bool Load(const char *filename); 35 | void RemoveSystem(PlayerID system); 36 | unsigned Size(void) const; 37 | PlayerID& operator[] ( const unsigned int position ) const; 38 | void Clear(void); 39 | 40 | DataStructures::List * GetList(void); 41 | 42 | protected: 43 | DataStructures::List systemList; 44 | }; 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /RakNet/include/RakNet/SystemDatabaseClient.h: -------------------------------------------------------------------------------- 1 | #ifndef __SYSTEM_DATABASE_CLIENT_H 2 | #define __SYSTEM_DATABASE_CLIENT_H 3 | 4 | // TODO 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /RakNet/include/RakNet/SystemDatabaseServer.h: -------------------------------------------------------------------------------- 1 | #ifndef __SYSTEM_DATABASE_SERVER_H 2 | #define __SYSTEM_DATABASE_SERVER_H 3 | 4 | // TODO 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /RakNet/include/RakNet/TCPInterface.h: -------------------------------------------------------------------------------- 1 | /// \file 2 | /// \brief A simple TCP based server allowing sends and receives. Can be connected by any TCP client, including telnet. 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_TCP_SERVER 19 | #define __SIMPLE_TCP_SERVER 20 | 21 | #ifdef _COMPATIBILITY_1 22 | #include "Compatibility1Includes.h" 23 | #elif defined(_WIN32) 24 | #include 25 | #include 26 | #else 27 | #include 28 | #include 29 | #include // fd_set 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | /// Unix/Linux uses ints for sockets 36 | typedef int SOCKET; 37 | #define INVALID_SOCKET -1 38 | #define SOCKET_ERROR -1 39 | #endif 40 | 41 | #include "DS_List.h" 42 | #include "NetworkTypes.h" 43 | #include "SingleProducerConsumer.h" 44 | #include "Export.h" 45 | 46 | struct RemoteClient; 47 | 48 | /// \internal 49 | /// \brief As the name says, a simple multithreaded TCP server. Used by TelnetTransport 50 | class RAK_DLL_EXPORT TCPInterface 51 | { 52 | public: 53 | TCPInterface(); 54 | ~TCPInterface(); 55 | 56 | /// Starts the TCP server on the indicated port 57 | bool Start(unsigned short port, unsigned short maxIncomingConnections); 58 | 59 | /// Stops the TCP server 60 | void Stop(void); 61 | 62 | /// Connect to the specified host on the specified port 63 | PlayerID Connect(const char* host, unsigned short remotePort); 64 | 65 | /// Sends a byte stream 66 | void Send( const char *data, unsigned length, PlayerID playerId ); 67 | 68 | /// Returns data received 69 | Packet* Receive( void ); 70 | 71 | /// Disconnects a player/address 72 | void CloseConnection( PlayerID playerId ); 73 | 74 | /// Deallocates a packet returned by Receive 75 | void DeallocatePacket( Packet *packet ); 76 | 77 | /// Queued events of new connections 78 | PlayerID HasNewConnection(void); 79 | 80 | /// Queued events of lost connections 81 | PlayerID HasLostConnection(void); 82 | protected: 83 | 84 | bool waitForClient; 85 | bool isStarted, threadRunning; 86 | SOCKET listenSocket; 87 | 88 | // Assuming remoteClients is only used by one thread! 89 | DataStructures::List remoteClients; 90 | DataStructures::SingleProducerConsumer outgoingMessages, incomingMessages; 91 | DataStructures::SingleProducerConsumer newConnections, lostConnections, requestedCloseConnections; 92 | DataStructures::SingleProducerConsumer newRemoteClients; 93 | 94 | #ifdef _WIN32 95 | HANDLE threadHandle; 96 | friend unsigned __stdcall UpdateTCPInterfaceLoop( LPVOID arguments ); 97 | #else 98 | pthread_t threadHandle; 99 | friend void* UpdateTCPInterfaceLoop( void* arguments ); 100 | #endif 101 | 102 | void DeleteRemoteClient(RemoteClient *remoteClient, fd_set *exceptionFD); 103 | }; 104 | 105 | /// Stores information about a remote client. In this case, only the socket used by that client. 106 | struct RemoteClient 107 | { 108 | SOCKET socket; 109 | PlayerID playerId; 110 | }; 111 | 112 | #endif 113 | -------------------------------------------------------------------------------- /RakNet/include/RakNet/TelnetTransport.h: -------------------------------------------------------------------------------- 1 | /// \file 2 | /// \brief Contains TelnetTransport , used to supports the telnet transport protocol. Insecure 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 __TELNET_TRANSPORT 19 | #define __TELNET_TRANSPORT 20 | 21 | #include "TransportInterface.h" 22 | #include "DS_List.h" 23 | #include "Export.h" 24 | class TCPInterface; 25 | struct TelnetClient; 26 | 27 | /// \brief Use TelnetTransport to easily allow windows telnet to connect to your ConsoleServer 28 | /// To run Windows telnet, go to your start menu, click run, and in the edit box type "telnet " where is the ip address 29 | /// of your ConsoleServer (most likely the same IP as your game). 30 | /// This implementation always echos commands. 31 | class RAK_DLL_EXPORT TelnetTransport : public TransportInterface 32 | { 33 | public: 34 | TelnetTransport(); 35 | ~TelnetTransport(); 36 | bool Start(unsigned short port, bool serverMode); 37 | void Stop(void); 38 | void Send( PlayerID playerId, const char *data, ... ); 39 | void CloseConnection( PlayerID playerId ); 40 | Packet* Receive( void ); 41 | void DeallocatePacket( Packet *packet ); 42 | PlayerID HasNewConnection(void); 43 | PlayerID HasLostConnection(void); 44 | CommandParserInterface* GetCommandParser(void); 45 | protected: 46 | 47 | struct TelnetClient 48 | { 49 | PlayerID playerId; 50 | char textInput[REMOTE_MAX_TEXT_INPUT]; 51 | unsigned cursorPosition; 52 | }; 53 | 54 | TCPInterface *tcpInterface; 55 | void AutoAllocate(void); 56 | bool ReassembleLine(TelnetTransport::TelnetClient* telnetClient, unsigned char c); 57 | 58 | // Crap this sucks but because windows telnet won't send line at a time, I have to reconstruct the lines at the server per player 59 | DataStructures::List remoteClients; 60 | }; 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /RakNet/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 | class CommandParserInterface; 27 | 28 | /// \brief Defines an interface that is used to send and receive null-terminated strings. 29 | /// In practice this is only used by the CommandParser system for for servers. 30 | class RAK_DLL_EXPORT TransportInterface 31 | { 32 | public: 33 | /// Start the transport provider on the indicated port. 34 | /// \param[in] port The port to start the transport provider on 35 | /// \param[in] serverMode If true, you should allow incoming connections (I don't actually use this anywhere) 36 | /// \return Return true on success, false on failure. 37 | virtual bool Start(unsigned short port, bool serverMode)=0; 38 | 39 | /// Stop the transport provider. You can clear memory and shutdown threads here. 40 | virtual void Stop(void)=0; 41 | 42 | /// Send a null-terminated string to \a playerId 43 | /// If your transport method requires particular formatting of the outgoing data (e.g. you don't just send strings) you can do it here 44 | /// and parse it out in Receive(). 45 | /// \param[in] playerId The player to send the string to 46 | /// \param[in] data format specifier - same as printf 47 | /// \param[in] ... format specification arguments - same as printf 48 | virtual void Send( PlayerID playerId, const char *data, ... )=0; 49 | 50 | /// Disconnect \a playerId . The binary address and port defines the PlayerID structure. 51 | /// \param[in] playerId The player/address to disconnect 52 | virtual void CloseConnection( PlayerID playerId )=0; 53 | 54 | /// Return a string. The string should be allocated and written to Packet::data . 55 | /// The byte length should be written to Packet::length . The player/address should be written to Packet::playerid 56 | /// If your transport protocol adds special formatting to the data stream you should parse it out before returning it in the packet 57 | /// and thus only return a string in Packet::data 58 | /// \return The packet structure containing the result of Receive, or 0 if no data is available 59 | virtual Packet* Receive( void )=0; 60 | 61 | /// Deallocate the Packet structure returned by Receive 62 | /// \param[in] The packet to deallocate 63 | virtual void DeallocatePacket( Packet *packet )=0; 64 | 65 | /// If a new system connects to you, you should queue that event and return the playerId/address of that player in this function. 66 | /// \return The PlayerID/address of the system 67 | virtual PlayerID HasNewConnection(void)=0; 68 | 69 | /// If a system loses the connection, you should queue that event and return the playerId/address of that player in this function. 70 | /// \return The PlayerID/address of the system 71 | virtual PlayerID HasLostConnection(void)=0; 72 | 73 | /// Your transport provider can itself have command parsers if the transport layer has user-modifiable features 74 | /// For example, your transport layer may have a password which you want remote users to be able to set or you may want 75 | /// to allow remote users to turn on or off command echo 76 | /// \return 0 if you do not need a command parser - otherwise the desired derivation of CommandParserInterface 77 | virtual CommandParserInterface* GetCommandParser(void)=0; 78 | protected: 79 | }; 80 | 81 | #endif 82 | 83 | -------------------------------------------------------------------------------- /RakNet/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 | -------------------------------------------------------------------------------- /RakNet/include/RakNet/sampencr.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | char *DumpMem(unsigned char *pAddr, int len); 4 | 5 | extern unsigned char encrBuffer[4092]; 6 | 7 | void kyretardizeDatagram(unsigned char *buf, int len, int port, int unk); 8 | -------------------------------------------------------------------------------- /RakNet/src/CheckSum.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * @brief CheckSum implementation from http://www.flounder.com/checksum.htm 4 | * 5 | */ 6 | #include "CheckSum.h" 7 | 8 | /**************************************************************************** 9 | * CheckSum::add 10 | * Inputs: 11 | * unsigned int d: word to add 12 | * Result: void 13 | * 14 | * Effect: 15 | * Adds the bytes of the unsigned int to the CheckSum 16 | ****************************************************************************/ 17 | 18 | void CheckSum::Add ( unsigned int value ) 19 | { 20 | union 21 | { 22 | unsigned int value; 23 | unsigned char bytes[ 4 ]; 24 | } 25 | 26 | data; 27 | data.value = value; 28 | 29 | for ( unsigned int i = 0; i < sizeof( data.bytes ); i++ ) 30 | Add ( data.bytes[ i ] ) 31 | 32 | ; 33 | } // CheckSum::add(unsigned int) 34 | 35 | /**************************************************************************** 36 | * CheckSum::add 37 | * Inputs: 38 | * unsigned short value: 39 | * Result: void 40 | * 41 | * Effect: 42 | * Adds the bytes of the unsigned short value to the CheckSum 43 | ****************************************************************************/ 44 | 45 | void CheckSum::Add ( unsigned short value ) 46 | { 47 | union 48 | { 49 | unsigned short value; 50 | unsigned char bytes[ 2 ]; 51 | } 52 | 53 | data; 54 | data.value = value; 55 | 56 | for ( unsigned int i = 0; i < sizeof( data.bytes ); i++ ) 57 | Add ( data.bytes[ i ] ) 58 | 59 | ; 60 | } // CheckSum::add(unsigned short) 61 | 62 | /**************************************************************************** 63 | * CheckSum::add 64 | * Inputs: 65 | * unsigned char value: 66 | * Result: void 67 | * 68 | * Effect: 69 | * Adds the byte to the CheckSum 70 | ****************************************************************************/ 71 | 72 | void CheckSum::Add ( unsigned char value ) 73 | { 74 | unsigned char cipher = (unsigned char)( value ^ ( r >> 8 ) ); 75 | r = ( cipher + r ) * c1 + c2; 76 | sum += cipher; 77 | } // CheckSum::add(unsigned char) 78 | 79 | 80 | /**************************************************************************** 81 | * CheckSum::add 82 | * Inputs: 83 | * LPunsigned char b: pointer to byte array 84 | * unsigned int length: count 85 | * Result: void 86 | * 87 | * Effect: 88 | * Adds the bytes to the CheckSum 89 | ****************************************************************************/ 90 | 91 | void CheckSum::Add ( unsigned char *b, unsigned int length ) 92 | { 93 | for ( unsigned int i = 0; i < length; i++ ) 94 | Add ( b[ i ] ) 95 | 96 | ; 97 | } // CheckSum::add(LPunsigned char, unsigned int) 98 | -------------------------------------------------------------------------------- /RakNet/src/DS_ByteQueue.cpp: -------------------------------------------------------------------------------- 1 | #include "DS_ByteQueue.h" 2 | #include // Memmove 3 | //#include // PS3 doesn't have this 4 | #include // realloc 5 | #include 6 | 7 | using namespace DataStructures; 8 | 9 | ByteQueue::ByteQueue() 10 | { 11 | readOffset=writeOffset=lengthAllocated=0; 12 | data=0; 13 | } 14 | ByteQueue::~ByteQueue() 15 | { 16 | Clear(); 17 | 18 | 19 | } 20 | void ByteQueue::WriteBytes(const char *in, unsigned length) 21 | { 22 | unsigned bytesWritten; 23 | bytesWritten=GetBytesWritten(); 24 | if (lengthAllocated==0 || length > lengthAllocated-bytesWritten-1) 25 | { 26 | unsigned oldLengthAllocated=lengthAllocated; 27 | unsigned newAmountToAllocate=length*2; 28 | if (newAmountToAllocate<256) 29 | newAmountToAllocate=256; 30 | lengthAllocated=lengthAllocated + newAmountToAllocate; 31 | data=(char*)realloc(data, lengthAllocated); 32 | if (writeOffset < readOffset) 33 | { 34 | if (writeOffset <= newAmountToAllocate) 35 | { 36 | memcpy(data + oldLengthAllocated, data, writeOffset); 37 | writeOffset=readOffset+bytesWritten; 38 | } 39 | else 40 | { 41 | memcpy(data + oldLengthAllocated, data, newAmountToAllocate); 42 | memmove(data, data+newAmountToAllocate, writeOffset-newAmountToAllocate); 43 | writeOffset-=newAmountToAllocate; 44 | } 45 | } 46 | } 47 | 48 | if (length <= lengthAllocated-writeOffset) 49 | memcpy(data+writeOffset, in, length); 50 | else 51 | { 52 | // Wrap 53 | memcpy(data+writeOffset, in, lengthAllocated-writeOffset); 54 | memcpy(data, in+(lengthAllocated-writeOffset), length-(lengthAllocated-writeOffset)); 55 | } 56 | writeOffset=(writeOffset+length) % lengthAllocated; 57 | } 58 | bool ByteQueue::ReadBytes(char *out, unsigned length, bool peek) 59 | { 60 | if (GetBytesWritten() < length) 61 | return false; 62 | 63 | if (length <= lengthAllocated-readOffset) 64 | memcpy(out, data+readOffset, length); 65 | else 66 | { 67 | // Wrap 68 | memcpy(out, data+readOffset, lengthAllocated-readOffset); 69 | memcpy(out+(lengthAllocated-readOffset), data, length-(lengthAllocated-readOffset)); 70 | } 71 | 72 | if (peek==false) 73 | IncrementReadOffset(length); 74 | 75 | return true; 76 | } 77 | void ByteQueue::Clear(void) 78 | { 79 | if (lengthAllocated) 80 | free(data); 81 | readOffset=writeOffset=lengthAllocated=0; 82 | data=0; 83 | } 84 | unsigned ByteQueue::GetBytesWritten(void) const 85 | { 86 | if (writeOffset>=readOffset) 87 | return writeOffset-readOffset; 88 | else 89 | return (writeOffset-1)+(lengthAllocated-readOffset); 90 | } 91 | void ByteQueue::IncrementReadOffset(unsigned length) 92 | { 93 | readOffset=(readOffset+length) % lengthAllocated; 94 | } 95 | void ByteQueue::Print(void) 96 | { 97 | unsigned i; 98 | for (i=readOffset; i!=writeOffset; i++) 99 | printf("%i ", data[i]); 100 | printf("\n"); 101 | } 102 | -------------------------------------------------------------------------------- /RakNet/src/DataCompressor.cpp: -------------------------------------------------------------------------------- 1 | #include "DataCompressor.h" 2 | #include "DS_HuffmanEncodingTree.h" 3 | #include 4 | #include // Use string.h rather than memory.h for the PS3 5 | 6 | void DataCompressor::Compress( unsigned char *userData, unsigned sizeInBytes, RakNet::BitStream * output ) 7 | { 8 | // Don't use this for small files as you will just make them bigger! 9 | assert(sizeInBytes > 2048); 10 | 11 | unsigned int frequencyTable[ 256 ]; 12 | unsigned int i; 13 | memset(frequencyTable,0,256*sizeof(unsigned int)); 14 | for (i=0; i < sizeInBytes; i++) 15 | ++frequencyTable[userData[i]]; 16 | HuffmanEncodingTree tree; 17 | unsigned int writeOffset1, writeOffset2, bitsUsed1, bitsUsed2; 18 | tree.GenerateFromFrequencyTable(frequencyTable); 19 | output->WriteCompressed(sizeInBytes); 20 | for (i=0; i < 256; i++) 21 | output->WriteCompressed(frequencyTable[i]); 22 | output->AlignWriteToByteBoundary(); 23 | writeOffset1=output->GetWriteOffset(); 24 | output->Write((unsigned int)0); // Dummy value 25 | bitsUsed1=output->GetNumberOfBitsUsed(); 26 | tree.EncodeArray(userData, sizeInBytes, output); 27 | bitsUsed2=output->GetNumberOfBitsUsed(); 28 | writeOffset2=output->GetWriteOffset(); 29 | output->SetWriteOffset(writeOffset1); 30 | output->Write(bitsUsed2-bitsUsed1); // Go back and write how many bits were used for the encoding 31 | output->SetWriteOffset(writeOffset2); 32 | } 33 | 34 | unsigned DataCompressor::DecompressAndAllocate( RakNet::BitStream * input, unsigned char **output ) 35 | { 36 | HuffmanEncodingTree tree; 37 | unsigned int bitsUsed, destinationSizeInBytes, decompressedBytes; 38 | unsigned int frequencyTable[ 256 ]; 39 | unsigned i; 40 | 41 | input->ReadCompressed(destinationSizeInBytes); 42 | for (i=0; i < 256; i++) 43 | input->ReadCompressed(frequencyTable[i]); 44 | input->AlignReadToByteBoundary(); 45 | if (input->Read(bitsUsed)==false) 46 | { 47 | // Read error 48 | #ifdef _DEBUG 49 | assert(0); 50 | #endif 51 | return 0; 52 | } 53 | *output = new unsigned char [destinationSizeInBytes]; 54 | tree.GenerateFromFrequencyTable(frequencyTable); 55 | decompressedBytes=tree.DecodeArray(input, bitsUsed, destinationSizeInBytes, *output ); 56 | assert(decompressedBytes==destinationSizeInBytes); 57 | return destinationSizeInBytes; 58 | } 59 | -------------------------------------------------------------------------------- /RakNet/src/EncodeClassName.cpp: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /RakNet/src/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 | static bool initialized=false; 32 | #ifdef _WIN32 33 | static LARGE_INTEGER yo; 34 | #else 35 | static timeval tp, initialTime; 36 | #endif 37 | 38 | RakNetTime RakNet::GetTime( void ) 39 | { 40 | if ( initialized == false ) 41 | { 42 | #ifdef _WIN32 43 | QueryPerformanceFrequency( &yo ); 44 | // The original code shifted right 10 bits 45 | //counts = yo.QuadPart >> 10; 46 | // It gives the wrong value since 2^10 is not 1000 47 | // counts = yo.QuadPart;// / 1000; 48 | #else 49 | gettimeofday( &initialTime, 0 ); 50 | #endif 51 | 52 | initialized = true; 53 | } 54 | 55 | #ifdef _WIN32 56 | LARGE_INTEGER PerfVal; 57 | 58 | QueryPerformanceCounter( &PerfVal ); 59 | 60 | return (RakNetTime)(PerfVal.QuadPart*1000 / yo.QuadPart); 61 | #else 62 | gettimeofday( &tp, 0 ); 63 | 64 | // Seconds to ms and microseconds to ms 65 | return ( tp.tv_sec - initialTime.tv_sec ) * 1000 + ( tp.tv_usec - initialTime.tv_usec ) / 1000; 66 | 67 | #endif 68 | } 69 | 70 | 71 | RakNetTimeNS RakNet::GetTimeNS( void ) 72 | { 73 | if ( initialized == false ) 74 | { 75 | #ifdef _WIN32 76 | QueryPerformanceFrequency( &yo ); 77 | // The original code shifted right 10 bits 78 | //counts = yo.QuadPart >> 10; 79 | // It gives the wrong value since 2^10 is not 1000 80 | // counts = yo.QuadPart;// / 1000; 81 | #else 82 | gettimeofday( &initialTime, 0 ); 83 | #endif 84 | 85 | initialized = true; 86 | } 87 | 88 | #ifdef _WIN32 89 | LARGE_INTEGER PerfVal; 90 | 91 | QueryPerformanceCounter( &PerfVal ); 92 | 93 | __int64 quotient, remainder; 94 | quotient=((PerfVal.QuadPart*1000) / yo.QuadPart); 95 | remainder=((PerfVal.QuadPart*1000) % yo.QuadPart); 96 | //return (PerfVal.QuadPart*1000 / (yo.QuadPart/1000)); 97 | return quotient*1000 + (remainder*1000 / yo.QuadPart); 98 | 99 | #else 100 | gettimeofday( &tp, 0 ); 101 | 102 | return ( tp.tv_sec - initialTime.tv_sec ) * (RakNetTimeNS) 1000000 + ( tp.tv_usec - initialTime.tv_usec ); 103 | 104 | #endif 105 | } 106 | -------------------------------------------------------------------------------- /RakNet/src/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 | InternalPacketPool::InternalPacketPool() 21 | { 22 | // Speed things up by not reallocating at runtime when a mutex is locked. 23 | pool.ClearAndForceAllocation( 64 ); 24 | unsigned i; 25 | for (i=0; i < 64; i++) 26 | pool.Push(new InternalPacket); 27 | } 28 | 29 | InternalPacketPool::~InternalPacketPool() 30 | { 31 | ClearPool(); 32 | } 33 | 34 | void InternalPacketPool::ClearPool( void ) 35 | { 36 | while ( pool.Size() ) 37 | delete pool.Pop(); 38 | } 39 | /* 40 | InternalPacket* InternalPacketPool::GetPointer( void ) 41 | { 42 | if ( pool.Size() ) 43 | return pool.Pop(); 44 | return new InternalPacket; 45 | 46 | } 47 | */ 48 | 49 | void InternalPacketPool::ReleasePointer( InternalPacket *p ) 50 | { 51 | if ( p == 0 ) 52 | { 53 | // Releasing a null pointer? 54 | #ifdef _DEBUG 55 | assert( 0 ); 56 | #endif 57 | return ; 58 | } 59 | 60 | #ifdef _DEBUG 61 | p->data=0; 62 | #endif 63 | //poolMutex.Lock(); 64 | pool.Push( p ); 65 | //poolMutex.Unlock(); 66 | } 67 | 68 | -------------------------------------------------------------------------------- /RakNet/src/LinuxStrings.cpp: -------------------------------------------------------------------------------- 1 | 2 | #if (defined(__GNUC__) || defined(__GCCXML__)) 3 | #include 4 | int _stricmp(const char* s1, const char* s2) 5 | { 6 | return strcasecmp(s1,s2); 7 | } 8 | int _strnicmp(const char* s1, const char* s2, size_t n) 9 | { 10 | return strncasecmp(s1,s2,n); 11 | } 12 | //#ifndef __CYGWIN__ 13 | //int _unlink(const char* filename) 14 | //{ 15 | // return remove(filename); 16 | //} 17 | //#endif 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /RakNet/src/PluginInterface.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 "PluginInterface.h" 18 | 19 | #ifdef _MSC_VER 20 | #pragma warning( push ) 21 | #endif 22 | 23 | #ifdef _MSC_VER 24 | #pragma warning( disable : 4100 ) // warning C4100: : unreferenced formal parameter 25 | #endif 26 | void PluginInterface::OnAttach(RakPeerInterface *peer) 27 | { 28 | } 29 | #ifdef _MSC_VER 30 | #pragma warning( disable : 4100 ) // warning C4100: : unreferenced formal parameter 31 | #endif 32 | void PluginInterface::OnDetach(RakPeerInterface *peer) 33 | { 34 | } 35 | #ifdef _MSC_VER 36 | #pragma warning( disable : 4100 ) // warning C4100: : unreferenced formal parameter 37 | #endif 38 | void PluginInterface::OnInitialize(RakPeerInterface *peer) 39 | { 40 | } 41 | #ifdef _MSC_VER 42 | #pragma warning( disable : 4100 ) // warning C4100: : unreferenced formal parameter 43 | #endif 44 | void PluginInterface::Update(RakPeerInterface *peer) 45 | { 46 | } 47 | #ifdef _MSC_VER 48 | #pragma warning( disable : 4100 ) // warning C4100: : unreferenced formal parameter 49 | #endif 50 | PluginReceiveResult PluginInterface::OnReceive(RakPeerInterface *peer, Packet *packet) 51 | { 52 | return RR_CONTINUE_PROCESSING; 53 | } 54 | #ifdef _MSC_VER 55 | #pragma warning( disable : 4100 ) // warning C4100: : unreferenced formal parameter 56 | #endif 57 | void PluginInterface::OnDisconnect(RakPeerInterface *peer) 58 | { 59 | } 60 | #ifdef _MSC_VER 61 | #pragma warning( disable : 4100 ) // warning C4100: : unreferenced formal parameter 62 | #endif 63 | void PluginInterface::OnCloseConnection(RakPeerInterface *peer, PlayerID playerId) 64 | { 65 | } 66 | #ifdef _MSC_VER 67 | #pragma warning( disable : 4100 ) // warning C4100: : unreferenced formal parameter 68 | #endif 69 | void PluginInterface::OnDirectSocketSend(const char *data, const unsigned bitsUsed, PlayerID remoteSystemID) 70 | { 71 | } 72 | #ifdef _MSC_VER 73 | #pragma warning( disable : 4100 ) // warning C4100: : unreferenced formal parameter 74 | #endif 75 | void PluginInterface::OnDirectSocketReceive(const char *data, const unsigned bitsUsed, PlayerID remoteSystemID) 76 | { 77 | } 78 | #ifdef _MSC_VER 79 | #pragma warning( disable : 4100 ) // warning C4100: : unreferenced formal parameter 80 | #endif 81 | bool PluginInterface::OnInternalPacket(InternalPacket *internalPacket, unsigned frameNumber, PlayerID remoteSystemID, RakNetTime time, bool isSend) 82 | { 83 | return true; 84 | } 85 | 86 | bool PluginInterface::OnSendImmediate(const char* data, const unsigned bitsUsed) { 87 | return true; 88 | } 89 | 90 | void PluginInterface::OnRpcReceive(unsigned char id, RPCParameters* params) { 91 | } 92 | 93 | #ifdef _MSC_VER 94 | #pragma warning( pop ) 95 | #endif 96 | -------------------------------------------------------------------------------- /RakNet/src/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 "LogCommandParser.h" 18 | #include "RakNetworkFactory.h" 19 | #include "RakServerInterface.h" 20 | #include "RakClientInterface.h" 21 | #include "RakServer.h" 22 | #include "RakClient.h" 23 | #include "RakPeerInterface.h" 24 | #include "RakPeer.h" 25 | 26 | RakClientInterface* RakNetworkFactory::GetRakClientInterface( void ) 27 | { 28 | return new RakClient; 29 | } 30 | RakServerInterface* RakNetworkFactory::GetRakServerInterface( void ) 31 | { 32 | return new RakServer; 33 | } 34 | RakPeerInterface* RakNetworkFactory::GetRakPeerInterface( void ) 35 | { 36 | return new RakPeer; 37 | } 38 | 39 | void RakNetworkFactory::DestroyRakClientInterface( RakClientInterface* i ) 40 | { 41 | delete ( RakClient* ) i; 42 | } 43 | void RakNetworkFactory::DestroyRakServerInterface( RakServerInterface* i ) 44 | { 45 | delete ( RakServer* ) i; 46 | } 47 | void RakNetworkFactory::DestroyRakPeerInterface( RakPeerInterface* i ) 48 | { 49 | delete ( RakPeer* ) i; 50 | } 51 | -------------------------------------------------------------------------------- /RakNet/src/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 | void RakSleep(unsigned int ms) 12 | { 13 | #ifdef _WIN32 14 | Sleep(ms); 15 | #else 16 | usleep(ms * 1000); 17 | #endif 18 | } 19 | -------------------------------------------------------------------------------- /RakNet/src/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 19 | 20 | SimpleMutex::SimpleMutex() 21 | { 22 | #ifdef _WIN32 23 | // hMutex = CreateMutex(NULL, FALSE, 0); 24 | // assert(hMutex); 25 | InitializeCriticalSection(&criticalSection); 26 | #else 27 | int error = pthread_mutex_init(&hMutex, 0); 28 | assert(error==0); 29 | #endif 30 | } 31 | 32 | SimpleMutex::~SimpleMutex() 33 | { 34 | #ifdef _WIN32 35 | // CloseHandle(hMutex); 36 | DeleteCriticalSection(&criticalSection); 37 | #else 38 | pthread_mutex_destroy(&hMutex); 39 | #endif 40 | } 41 | 42 | #ifdef _WIN32 43 | #ifdef _DEBUG 44 | #include 45 | #endif 46 | #endif 47 | 48 | void SimpleMutex::Lock(void) 49 | { 50 | #ifdef _WIN32 51 | /* 52 | DWORD d = WaitForSingleObject(hMutex, INFINITE); 53 | #ifdef _DEBUG 54 | if (d==WAIT_FAILED) 55 | { 56 | LPVOID messageBuffer; 57 | FormatMessage( 58 | FORMAT_MESSAGE_ALLOCATE_BUFFER | 59 | FORMAT_MESSAGE_FROM_SYSTEM | 60 | FORMAT_MESSAGE_IGNORE_INSERTS, 61 | NULL, 62 | GetLastError(), 63 | MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language 64 | (LPTSTR) &messageBuffer, 65 | 0, 66 | NULL 67 | ); 68 | // Process any inserts in messageBuffer. 69 | // ... 70 | // Display the string. 71 | //MessageBox( NULL, (LPCTSTR)messageBuffer, "Error", MB_OK | MB_ICONINFORMATION ); 72 | printf("SimpleMutex error: %s", messageBuffer); 73 | // Free the buffer. 74 | LocalFree( messageBuffer ); 75 | 76 | } 77 | 78 | assert(d==WAIT_OBJECT_0); 79 | */ 80 | EnterCriticalSection(&criticalSection); 81 | 82 | #else 83 | int error = pthread_mutex_lock(&hMutex); 84 | assert(error==0); 85 | #endif 86 | } 87 | 88 | void SimpleMutex::Unlock(void) 89 | { 90 | #ifdef _WIN32 91 | // ReleaseMutex(hMutex); 92 | LeaveCriticalSection(&criticalSection); 93 | #else 94 | int error = pthread_mutex_unlock(&hMutex); 95 | assert(error==0); 96 | #endif 97 | } 98 | 99 | -------------------------------------------------------------------------------- /RakNet/src/StringTable.cpp: -------------------------------------------------------------------------------- 1 | #include "StringTable.h" 2 | #include 3 | #include 4 | #include 5 | #include "BitStream.h" 6 | #include "StringCompressor.h" 7 | 8 | StringTable* StringTable::instance=0; 9 | int StringTable::referenceCount=0; 10 | 11 | int StrAndBoolComp( char *const &key, const StrAndBool &data ) 12 | { 13 | return strcmp(key,(const char*)data.str); 14 | } 15 | 16 | StringTable::StringTable() 17 | { 18 | 19 | } 20 | 21 | StringTable::~StringTable() 22 | { 23 | unsigned i; 24 | for (i=0; i < orderedStringList.Size(); i++) 25 | { 26 | if (orderedStringList[i].b) 27 | delete [] orderedStringList[i].str; 28 | } 29 | } 30 | 31 | void StringTable::AddReference(void) 32 | { 33 | if (++referenceCount==1) 34 | { 35 | instance = new StringTable; 36 | } 37 | } 38 | void StringTable::RemoveReference(void) 39 | { 40 | assert(referenceCount > 0); 41 | 42 | if (referenceCount > 0) 43 | { 44 | if (--referenceCount==0) 45 | { 46 | delete instance; 47 | instance=0; 48 | } 49 | } 50 | } 51 | 52 | StringTable* StringTable::Instance(void) 53 | { 54 | return instance; 55 | } 56 | 57 | void StringTable::AddString(const char *str, bool copyString) 58 | { 59 | StrAndBool sab; 60 | sab.b=copyString; 61 | if (copyString) 62 | { 63 | sab.str = new char [strlen(str)+1]; 64 | strcpy(sab.str, str); 65 | } 66 | else 67 | { 68 | sab.str=(char*)str; 69 | } 70 | 71 | // If it asserts inside here you are adding duplicate strings. 72 | if (!orderedStringList.Insert(sab.str,sab)) 73 | { 74 | if (copyString) 75 | delete sab.str; 76 | } 77 | 78 | // If this assert hits you need to increase the range of StringTableType 79 | assert(orderedStringList.Size() < (StringTableType)-1); 80 | 81 | } 82 | void StringTable::EncodeString( const char *input, int maxCharsToWrite, RakNet::BitStream *output ) 83 | { 84 | unsigned index; 85 | bool objectExists; 86 | // This is fast because the list is kept ordered. 87 | index=orderedStringList.GetIndexFromKey((char*)input, &objectExists); 88 | if (objectExists) 89 | { 90 | output->Write(true); 91 | output->Write((StringTableType)index); 92 | } 93 | else 94 | { 95 | LogStringNotFound(input); 96 | output->Write(false); 97 | stringCompressor->EncodeString(input, maxCharsToWrite, output); 98 | } 99 | } 100 | 101 | bool StringTable::DecodeString( char *output, int maxCharsToWrite, RakNet::BitStream *input ) 102 | { 103 | bool hasIndex; 104 | assert(maxCharsToWrite>0); 105 | 106 | if (maxCharsToWrite==0) 107 | return false; 108 | if (!input->Read(hasIndex)) 109 | return false; 110 | if (hasIndex==false) 111 | { 112 | stringCompressor->DecodeString(output, maxCharsToWrite, input); 113 | } 114 | else 115 | { 116 | StringTableType index; 117 | if (!input->Read(index)) 118 | return false; 119 | if (index >= orderedStringList.Size()) 120 | { 121 | #ifdef _DEBUG 122 | // Critical error - got a string index out of range, which means AddString was called more times on the remote system than on this system. 123 | // All systems must call AddString the same number of types, with the same strings in the same order. 124 | assert(0); 125 | #endif 126 | return false; 127 | } 128 | 129 | strncpy(output, orderedStringList[index].str, maxCharsToWrite); 130 | output[maxCharsToWrite-1]=0; 131 | } 132 | 133 | return true; 134 | } 135 | #ifdef _MSC_VER 136 | #pragma warning( disable : 4100 ) // warning C4100: : unreferenced formal parameter 137 | #endif 138 | void StringTable::LogStringNotFound(const char *strName) 139 | { 140 | #ifdef _DEBUG 141 | printf("Efficiency Warning! Unregistered String %s sent to StringTable.\n", strName); 142 | #endif 143 | } 144 | -------------------------------------------------------------------------------- /RakNet/src/SystemAddressList.cpp: -------------------------------------------------------------------------------- 1 | #include "SystemAddressList.h" 2 | #include "Rand.h" 3 | #include "RakAssert.h" 4 | #include "BitStream.h" 5 | #include 6 | 7 | SystemAddressList::SystemAddressList() 8 | { 9 | 10 | } 11 | SystemAddressList::SystemAddressList(PlayerID system) 12 | { 13 | systemList.Insert(system); 14 | } 15 | void SystemAddressList::AddSystem(PlayerID system) 16 | { 17 | systemList.Insert(system); 18 | } 19 | void SystemAddressList::RandomizeOrder(void) 20 | { 21 | unsigned index, size, randIndex; 22 | PlayerID temp; 23 | size = systemList.Size(); 24 | for (index=0; index < size; index++) 25 | { 26 | randIndex=index + (randomMT() % (size-index)); 27 | if (randIndex!=index) 28 | { 29 | temp=systemList[index]; 30 | systemList[index]=systemList[randIndex]; 31 | systemList[randIndex]=temp; 32 | } 33 | } 34 | } 35 | void SystemAddressList::Serialize(RakNet::BitStream *out) 36 | { 37 | out->Write((unsigned short) systemList.Size()); 38 | unsigned index; 39 | for (index=0; index < systemList.Size(); index++) 40 | out->Write(systemList[index]); 41 | } 42 | bool SystemAddressList::Deserialize(RakNet::BitStream *in) 43 | { 44 | unsigned short systemListSize; 45 | PlayerID systemAddress; 46 | unsigned index; 47 | if (in->Read(systemListSize)==false) 48 | { 49 | RakAssert(0); 50 | return false; 51 | } 52 | systemList.Clear(); 53 | for (index=0; index < systemListSize; index++) 54 | { 55 | if (in->Read(systemAddress)==false) 56 | { 57 | RakAssert(0); 58 | systemList.Clear(); 59 | return false; 60 | } 61 | systemList.Insert(systemAddress); 62 | 63 | } 64 | return true; 65 | } 66 | void SystemAddressList::RemoveSystem(PlayerID system) 67 | { 68 | unsigned i; 69 | for (i=0; i < systemList.Size(); i++) 70 | { 71 | if (systemList[i]==system) 72 | { 73 | systemList.Del(i); 74 | return; 75 | } 76 | } 77 | } 78 | DataStructures::List * SystemAddressList::GetList(void) 79 | { 80 | return &systemList; 81 | } 82 | bool SystemAddressList::Save(const char *filename) 83 | { 84 | RakNet::BitStream temp; 85 | Serialize(&temp); 86 | FILE *fp = fopen(filename, "wb"); 87 | if (fp) 88 | { 89 | fwrite(temp.GetData(), temp.GetNumberOfBytesUsed(), 1, fp); 90 | fclose(fp); 91 | return true; 92 | } 93 | return false; 94 | } 95 | bool SystemAddressList::Load(const char *filename) 96 | { 97 | FILE *fp = NULL; 98 | unsigned long fileSize; 99 | 100 | if ( ( fp = fopen( filename, "rb" ) ) == 0 ) 101 | return false; 102 | 103 | fseek( fp, 0, SEEK_END ); 104 | fileSize = ftell( fp ); 105 | fseek( fp, 0, SEEK_SET ); 106 | if (fileSize==0) 107 | { 108 | fclose(fp); 109 | return false; 110 | } 111 | unsigned char *filedata = new unsigned char [fileSize]; 112 | fread(filedata, fileSize, 1, fp); 113 | fclose(fp); 114 | 115 | RakNet::BitStream bs(filedata, fileSize, false); 116 | Deserialize(&bs); 117 | delete [] filedata; 118 | return true; 119 | } 120 | unsigned SystemAddressList::Size(void) const 121 | { 122 | return systemList.Size(); 123 | } 124 | PlayerID& SystemAddressList::operator[] ( const unsigned int position ) const 125 | { 126 | return systemList[position]; 127 | } 128 | void SystemAddressList::Clear(void) 129 | { 130 | systemList.Clear(); 131 | } 132 | -------------------------------------------------------------------------------- /RakNet/src/_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 | static DataStructures::List< _findinfo_t* > fileInfo; 10 | 11 | /** 12 | * _findfirst - equivalent 13 | */ 14 | long _findfirst(const char *name, _finddata_t *f) 15 | { 16 | 17 | // char* nameCopy = new char[sizeof(name)]; 18 | // memset(nameCopy, '\0', sizeof(nameCopy)); 19 | // 20 | // strcpy(nameCopy, name); 21 | // 22 | // char* filter = new char[sizeof(nameCopy)]; 23 | // memset(filter, '\0', sizeof(filter)); 24 | 25 | int length = strlen(name)+1; 26 | char* nameCopy = new char[length]; 27 | memset(nameCopy, '\0', length); 28 | 29 | strcpy(nameCopy, name); 30 | 31 | char* filter = new char[length]; 32 | memset(filter, '\0', length); 33 | 34 | char* lastSep = strrchr(nameCopy,'/'); 35 | if(!lastSep) 36 | { 37 | strcpy(filter, nameCopy); 38 | strcpy(nameCopy, "."); 39 | } 40 | else 41 | { 42 | strcpy(filter, lastSep+1); 43 | *lastSep = 0; 44 | } 45 | 46 | DIR* dir = opendir(nameCopy); 47 | 48 | if(!dir) 49 | { 50 | return -1; 51 | } 52 | 53 | _findinfo_t* fi = new _findinfo_t; 54 | strcpy(fi->filter,filter); 55 | fi->openedDir = dir; 56 | 57 | while(true) 58 | { 59 | dirent* entry = readdir(dir); 60 | if(entry == 0) 61 | break; 62 | 63 | if(fnmatch(fi->filter,entry->d_name, 200) == 0) 64 | { 65 | strcpy(f->name, entry->d_name); 66 | break; 67 | } 68 | } 69 | 70 | 71 | fileInfo.Insert(fi); 72 | return fileInfo.Size()-1; 73 | 74 | // return 0; 75 | } 76 | 77 | /** 78 | * _findnext - equivalent 79 | */ 80 | int _findnext(long h, _finddata_t *f) 81 | { 82 | 83 | _findinfo_t* fi = fileInfo[h]; 84 | 85 | while(true) 86 | { 87 | dirent* entry = readdir(fi->openedDir); 88 | if(entry == 0) 89 | return -1; 90 | 91 | if(fnmatch(fi->filter,entry->d_name, 200) == 0) 92 | { 93 | strcpy(f->name, entry->d_name); 94 | if (entry->d_type == DT_REG) 95 | f->attrib = _A_NORMAL; 96 | f->size = entry->d_reclen; 97 | return 0; 98 | } 99 | if (entry->d_type == DT_DIR) 100 | { 101 | f->attrib = _A_SUBDIR; 102 | strcpy(f->name, entry->d_name); 103 | return 0; 104 | } 105 | } 106 | 107 | return -1; 108 | } 109 | 110 | /** 111 | * _findclose - equivalent 112 | */ 113 | int _findclose(long h) 114 | { 115 | if (fileInfo.Size()>h) 116 | { 117 | _findinfo_t* fi = fileInfo[h]; 118 | fileInfo.RemoveAtIndex(h); 119 | delete fi; 120 | return 0; 121 | } 122 | else 123 | { 124 | printf("Error _findclose\n"); 125 | return -1; 126 | } 127 | 128 | } 129 | #endif 130 | -------------------------------------------------------------------------------- /daemon/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.16) 2 | 3 | project("connd-daemon") 4 | 5 | find_package(magic_enum REQUIRED) 6 | find_package(nlohmann_json CONFIG REQUIRED) 7 | find_package(spdlog REQUIRED) 8 | 9 | add_executable("connd-daemon" "main.cpp") 10 | 11 | set_target_properties("connd-daemon" 12 | PROPERTIES 13 | CXX_STANDARD 20 14 | CXX_STANDARD_REQUIRED ON 15 | CXX_EXTENSIONS OFF 16 | ) 17 | 18 | target_link_libraries("connd-daemon" PRIVATE magic_enum::magic_enum 19 | nlohmann_json::nlohmann_json 20 | RakNet 21 | connd-ipclib 22 | spdlog::spdlog) 23 | set_target_properties("connd-daemon" PROPERTIES 24 | SUFFIX "-by-kin4stat.exe" 25 | MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:DebugDLL>" 26 | ) -------------------------------------------------------------------------------- /daemon/crtp_singleton.hpp: -------------------------------------------------------------------------------- 1 | #ifndef CRTP_SINGLETON_HPP_ 2 | #define CRTP_SINGLETON_HPP_ 3 | #include 4 | 5 | template 6 | class Singleton { 7 | public: 8 | template 9 | static T* instance(Args&&... args) { 10 | static T instance{std::forward(args)...}; 11 | 12 | return &instance; 13 | } 14 | 15 | protected: 16 | Singleton() = default; 17 | Singleton(const Singleton&) = delete; 18 | Singleton& operator=(const Singleton&) = delete; 19 | virtual ~Singleton() = default; 20 | }; 21 | 22 | #endif // CRTP_SINGLETON_HPP_ 23 | -------------------------------------------------------------------------------- /daemon/logger.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | #ifdef _DEBUG 6 | #define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_TRACE 7 | #else 8 | #define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_INFO 9 | #endif 10 | 11 | #include "crtp_singleton.hpp" 12 | #include "spdlog/sinks/basic_file_sink.h" 13 | #include "spdlog/spdlog.h" 14 | 15 | #ifdef _DEBUG 16 | #define LOG_TRACE(...) SPDLOG_TRACE(__VA_ARGS__) 17 | #define LOG_DEBUG(...) SPDLOG_DEBUG(__VA_ARGS__) 18 | #define LOG_INFO(...) SPDLOG_INFO(__VA_ARGS__) 19 | #define LOG_WARNING(...) SPDLOG_WARN(__VA_ARGS__) 20 | #define LOG_ERROR(...) SPDLOG_ERROR(__VA_ARGS__) 21 | #else 22 | #define LOG_TRACE(...) 23 | #define LOG_DEBUG(...) 24 | #define LOG_INFO(...) spdlog::info(__VA_ARGS__) 25 | #define LOG_WARNING(...) spdlog::warn(__VA_ARGS__) 26 | #define LOG_ERROR(...) spdlog::error(__VA_ARGS__) 27 | #endif 28 | 29 | class logger : public Singleton { 30 | public: 31 | logger() { 32 | constexpr auto logfile = "connd\\daemon.log"; 33 | 34 | std::error_code ec{}; 35 | 36 | std::filesystem::remove(logfile, ec); 37 | 38 | spdlogger = spdlog::basic_logger_mt("main_logger", logfile); 39 | #ifdef _DEBUG 40 | spdlogger->set_level(spdlog::level::trace); 41 | spdlogger->flush_on(spdlog::level::trace); 42 | spdlogger->set_pattern("[%T] [thread: %t] [%l] - %v from [%@ in %!]"); 43 | #else 44 | spdlogger->set_level(spdlog::level::info); 45 | spdlogger->flush_on(spdlog::level::info); 46 | spdlogger->set_pattern("[%T] [%l] - %v"); 47 | #endif 48 | spdlog::set_default_logger(spdlogger); 49 | } 50 | 51 | std::shared_ptr spdlogger{}; 52 | }; 53 | -------------------------------------------------------------------------------- /daemon/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include "raknet_plugin.hpp" 8 | #include "rakclient.hpp" 9 | #include "utils.hpp" 10 | 11 | #include "raknet_state.hpp" 12 | #include "ipc/ipc_client.hpp" 13 | #include "ipc/ipc_server.hpp" 14 | 15 | #include "RakNet/RakNetworkFactory.h" 16 | 17 | #include "logger.hpp" 18 | 19 | RakPlugin* plugin; 20 | std::atomic stop = false; 21 | 22 | void recv_startup_parameters(unsigned short port) { 23 | LOG_INFO("Receiving data from {}:{}", "127.0.0.1", port); 24 | 25 | ipc_client client; 26 | 27 | client.init(); 28 | client.connect("127.0.0.1", port); 29 | 30 | auto [data, name] = client.recv_string(); 31 | if (name == "parameters") { 32 | rak_state = nlohmann::json::parse(data).get(); 33 | 34 | LOG_INFO("Startup data received"); 35 | } 36 | } 37 | 38 | void daemon() { 39 | ipc_server server; 40 | server.init("127.0.0.1", 0); 41 | 42 | std::ofstream output{ R"(.\connd\connd_port.json)" }; 43 | output << server.get_bound_port() << std::endl; 44 | output.close(); 45 | 46 | LOG_INFO("Started daemon server on {}:{}", "127.0.0.1", server.get_bound_port()); 47 | 48 | server.accept(); 49 | 50 | stop = true; 51 | 52 | LOG_INFO("Stopping mainloop"); 53 | 54 | g_rak_client->Disconnect(0, 0); 55 | 56 | LOG_INFO("RakNet Disconnected"); 57 | 58 | auto& rel_level = get_pure_rak_client()->remoteSystemList->reliabilityLayer; 59 | 60 | std::ranges::copy(rel_level.waitingForOrderedPacketWriteIndex, 61 | std::begin(rak_state.waitingForOrderedPacketWriteIndex)); 62 | std::ranges::copy(rel_level.waitingForSequencedPacketWriteIndex, 63 | std::begin(rak_state.waitingForSequencedPacketWriteIndex)); 64 | std::ranges::copy(rel_level.waitingForOrderedPacketReadIndex, 65 | std::begin(rak_state.waitingForOrderedPacketReadIndex)); 66 | std::ranges::copy(rel_level.waitingForSequencedPacketReadIndex, 67 | std::begin(rak_state.waitingForSequencedPacketReadIndex)); 68 | 69 | rak_state.received_packets_base_index = rel_level.receivedPacketsBaseIndex; 70 | rak_state.send_number = rel_level.messageNumber; 71 | 72 | LOG_INFO("Saved reliability level"); 73 | 74 | const nlohmann::json startup_args = rak_state; 75 | 76 | server.send_string("parameters", startup_args.dump()); 77 | 78 | LOG_INFO("Sent network state"); 79 | 80 | plugin->send_rpcs(&server); 81 | 82 | LOG_INFO("Sent rpcs, count: {}", plugin->get_rpc_count()); 83 | 84 | server.disconnect(); 85 | } 86 | 87 | int main(int argc, char* argv[]) { 88 | logger::instance(); 89 | 90 | char temp[1024]; 91 | 92 | GetModuleFileNameA(GetModuleHandleA(nullptr), temp, sizeof(temp)); 93 | 94 | if (std::string_view{ temp }.find("connd-daemon-by-kin4stat.exe") == std::string_view::npos) { 95 | LOG_INFO("Daemon executable name changed, shutting down"); 96 | 97 | return 1; 98 | } 99 | 100 | auto start = std::chrono::steady_clock::now(); 101 | 102 | alloc_console(); 103 | 104 | const auto port = std::stoul(argv[1]); 105 | 106 | recv_startup_parameters(port); 107 | 108 | plugin = new RakPlugin{}; 109 | 110 | srand(time(nullptr)); 111 | 112 | g_rak_client = RakNetworkFactory::GetRakClientInterface(); 113 | 114 | g_rak_client->SetMTUSize(576); 115 | g_rak_client->SetPassword(""); 116 | 117 | g_rak_client->AttachPlugin(plugin); 118 | while (!g_rak_client->Connect(rak_state.hostname.c_str(), rak_state.server_pid.port, rak_state.local_port, 0, 2)) { 119 | std::this_thread::sleep_for(std::chrono::milliseconds(1)); 120 | } 121 | 122 | auto d_thread = std::thread{daemon}; 123 | 124 | while (!stop) { 125 | while (auto pkt = g_rak_client->Receive()) { 126 | g_rak_client->DeallocatePacket(pkt); 127 | } 128 | 129 | std::chrono::duration diff = std::chrono::steady_clock::now() - start; 130 | if (diff.count() > rak_state.timeout) { 131 | [[maybe_unused]] std::error_code ec{}; 132 | 133 | std::filesystem::remove(R"(.\connd\connd_samp_dump.json)", ec); 134 | std::quick_exit(0); 135 | } 136 | 137 | std::this_thread::sleep_for(std::chrono::milliseconds(1)); 138 | } 139 | 140 | LOG_INFO("Mainloop stopped, waiting for daemon thread"); 141 | 142 | d_thread.join(); 143 | 144 | LOG_INFO("Shutting down"); 145 | 146 | return 0; 147 | } 148 | -------------------------------------------------------------------------------- /daemon/rakclient.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "RakNet/RakClientInterface.h" 4 | 5 | inline RakClientInterface* g_rak_client; -------------------------------------------------------------------------------- /daemon/raknet_state.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include "RakNet/NetworkTypes.h" 8 | #include 9 | 10 | class raknet_state { 11 | public: 12 | raknet_state() = default; 13 | ~raknet_state() = default; 14 | 15 | 16 | std::string hostname; 17 | unsigned short local_port; 18 | unsigned short received_packets_base_index; 19 | unsigned short send_number; 20 | 21 | PlayerID server_pid; 22 | PlayerIndex pindex; 23 | 24 | std::vector cookie_dump; 25 | std::vector reply_dump; 26 | std::vector auth_key_dump; 27 | std::vector conn_accept_dump; 28 | std::vector static_data_dump; 29 | 30 | std::array waitingForOrderedPacketWriteIndex; 31 | std::array waitingForSequencedPacketWriteIndex; 32 | std::array waitingForOrderedPacketReadIndex; 33 | std::array waitingForSequencedPacketReadIndex; 34 | 35 | std::uint32_t timeout = 3 * 60; 36 | }; 37 | 38 | inline raknet_state rak_state{}; 39 | 40 | NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(PlayerID, 41 | binaryAddress, 42 | port) 43 | 44 | NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(raknet_state, 45 | hostname, 46 | local_port, 47 | received_packets_base_index, 48 | send_number, 49 | server_pid, 50 | pindex, 51 | cookie_dump, 52 | reply_dump, 53 | auth_key_dump, 54 | conn_accept_dump, 55 | static_data_dump, 56 | waitingForOrderedPacketReadIndex, 57 | waitingForOrderedPacketWriteIndex, 58 | waitingForSequencedPacketReadIndex, 59 | waitingForSequencedPacketWriteIndex, 60 | timeout) 61 | -------------------------------------------------------------------------------- /daemon/raknet_utils.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "rakclient.hpp" 3 | #include "RakNet/RakClient.h" 4 | 5 | RakClient* get_pure_rak_client() { 6 | return static_cast(g_rak_client); 7 | } 8 | 9 | void emulate_packet_recv(std::span packet_data) { 10 | const auto packet_size = packet_data.size(); 11 | const auto packet_data_alloc = new unsigned char[packet_size]; 12 | std::memcpy(packet_data_alloc, packet_data.data(), packet_data.size()); 13 | Packet* packet = AllocPacket(packet_size, packet_data_alloc); 14 | 15 | packet->bitSize = packet_size * 8; 16 | packet->playerId = rak_state.server_pid; 17 | packet->playerIndex = rak_state.pindex; 18 | 19 | get_pure_rak_client()->AddPacketToProducer(packet); 20 | } 21 | 22 | void emulate_socket_recv(std::span packet_data) { 23 | ProcessNetworkPacket(rak_state.server_pid.binaryAddress, 24 | rak_state.server_pid.port, 25 | packet_data.data(), 26 | packet_data.size(), 27 | get_pure_rak_client()); 28 | } -------------------------------------------------------------------------------- /daemon/utils.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | void alloc_console() { 6 | #ifdef _DEBUG 7 | AllocConsole(); 8 | 9 | FILE* fDummy; 10 | freopen_s(&fDummy, "CONIN$", "r", stdin); 11 | freopen_s(&fDummy, "CONOUT$", "w", stderr); 12 | freopen_s(&fDummy, "CONOUT$", "w", stdout); 13 | #endif 14 | } 15 | -------------------------------------------------------------------------------- /ipc/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.16) 2 | 3 | project("connd-ipclib") 4 | 5 | add_library("connd-ipclib" STATIC "src/ipc_server.cpp" "src/ipc_client.cpp") 6 | 7 | target_include_directories("connd-ipclib" PUBLIC "include") 8 | 9 | target_link_libraries("connd-ipclib" PUBLIC ws2_32) 10 | 11 | set_target_properties("connd-ipclib" 12 | PROPERTIES 13 | CXX_STANDARD 20 14 | CXX_STANDARD_REQUIRED ON 15 | CXX_EXTENSIONS OFF 16 | ) -------------------------------------------------------------------------------- /ipc/include/ipc/ipc_client.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | #include "ipc_headers.hpp" 5 | 6 | class ipc_client { 7 | public: 8 | ipc_client() = default; 9 | ~ipc_client(); 10 | 11 | bool init(); 12 | bool connect(std::string_view hostname, unsigned short hostport); 13 | 14 | void send_string(std::string_view name, std::string_view string); 15 | 16 | template 17 | void send_raw_data(std::string_view name, T data); 18 | 19 | template 20 | raw_data_recv recv_raw_data(); 21 | 22 | string_recv recv_string(); 23 | private: 24 | sockaddr_in server{}; 25 | WSADATA wsa{}; 26 | SOCKET s{}; 27 | }; 28 | 29 | template 30 | inline void ipc_client::send_raw_data(std::string_view name, T data) { 31 | send_string(name, std::string_view{ reinterpret_cast(&data), sizeof(data) }); 32 | } 33 | 34 | template 35 | inline raw_data_recv ipc_client::recv_raw_data() { 36 | raw_data_recv result{}; 37 | 38 | auto [s, name] = recv_string(); 39 | 40 | result.name = name; 41 | std::memcpy(&result.data, s.c_str(), s.size()); 42 | 43 | return result; 44 | } -------------------------------------------------------------------------------- /ipc/include/ipc/ipc_headers.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | struct header { 6 | std::size_t size; 7 | }; 8 | 9 | struct string_recv { 10 | std::string string; 11 | std::string name; 12 | }; 13 | 14 | template 15 | struct raw_data_recv { 16 | T data; 17 | std::string name; 18 | }; 19 | -------------------------------------------------------------------------------- /ipc/include/ipc/ipc_server.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | #include "ipc_headers.hpp" 6 | 7 | class ipc_server { 8 | public: 9 | ipc_server() = default; 10 | ~ipc_server(); 11 | 12 | bool init(std::string_view address, unsigned short port); 13 | 14 | void accept(); 15 | void disconnect(); 16 | 17 | void send_string(std::string_view name, std::string_view string); 18 | 19 | template 20 | void send_raw_data(std::string_view name, T data); 21 | 22 | template 23 | raw_data_recv recv_raw_data(); 24 | 25 | string_recv recv_string(); 26 | 27 | unsigned short get_bound_port(); 28 | 29 | private: 30 | sockaddr_in server{}, client{}; 31 | WSADATA wsa{}; 32 | SOCKET s{}, client_s; 33 | }; 34 | 35 | template 36 | inline void ipc_server::send_raw_data(std::string_view name, T data) { 37 | send_string(name, std::string_view{reinterpret_cast(&data), sizeof(data)}); 38 | } 39 | 40 | template <> 41 | inline void ipc_server::send_raw_data(std::string_view name, std::string_view data) { 42 | send_string(name, data); 43 | } 44 | 45 | template 46 | inline raw_data_recv ipc_server::recv_raw_data() { 47 | raw_data_recv result{}; 48 | 49 | auto [s, name] = recv_string(); 50 | 51 | result.name = name; 52 | std::memcpy(&result.data, s.c_str(), s.size()); 53 | 54 | return result; 55 | } 56 | -------------------------------------------------------------------------------- /ipc/src/ipc_client.cpp: -------------------------------------------------------------------------------- 1 | #include "ipc/ipc_client.hpp" 2 | #include "ipc/ipc_headers.hpp" 3 | 4 | ipc_client::~ipc_client() { 5 | closesocket(s); 6 | WSACleanup(); 7 | } 8 | 9 | bool ipc_client::connect(std::string_view hostname, unsigned short hostport) { 10 | server.sin_family = AF_INET; 11 | server.sin_addr.s_addr = inet_addr(hostname.data()); 12 | server.sin_port = htons(hostport); 13 | 14 | if (::connect(s, reinterpret_cast(&server), sizeof(server)) < 0) { 15 | return false; 16 | } 17 | return true; 18 | } 19 | 20 | void ipc_client::send_string(std::string_view name, std::string_view string) { 21 | header h; 22 | h.size = name.size(); 23 | 24 | send(s, reinterpret_cast(&h), sizeof(h), 0); 25 | send(s, name.data(), name.size(), 0); 26 | 27 | h.size = string.size(); 28 | 29 | send(s, reinterpret_cast(&h), sizeof(h), 0); 30 | send(s, string.data(), string.size(), 0); 31 | } 32 | 33 | string_recv ipc_client::recv_string() { 34 | int bytes_received; 35 | string_recv result{}; 36 | 37 | header h{}; 38 | bytes_received = recv(s, reinterpret_cast(&h), sizeof(h), 0); 39 | 40 | if (bytes_received == SOCKET_ERROR || bytes_received != sizeof(h)) { 41 | // 42 | } 43 | 44 | result.name = std::string{}; 45 | result.name.resize(h.size); 46 | 47 | bytes_received = recv(s, result.name.data(), h.size, 0); 48 | 49 | if (bytes_received == SOCKET_ERROR || bytes_received != h.size) { 50 | // 51 | } 52 | 53 | bytes_received = recv(s, reinterpret_cast(&h), sizeof(h), 0); 54 | 55 | if (bytes_received == SOCKET_ERROR || bytes_received != h.size) { 56 | // 57 | } 58 | 59 | result.string.resize(h.size); 60 | 61 | bytes_received = recv(s, result.string.data(), h.size, 0); 62 | 63 | if (bytes_received == SOCKET_ERROR || bytes_received != h.size) { 64 | // 65 | } 66 | 67 | return result; 68 | } 69 | 70 | bool ipc_client::init() { 71 | if (WSAStartup(MAKEWORD(2, 2), &wsa) != 0) { 72 | return false; 73 | } 74 | if ((s = socket(AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET) { 75 | return false; 76 | } 77 | 78 | return true; 79 | } 80 | -------------------------------------------------------------------------------- /ipc/src/ipc_server.cpp: -------------------------------------------------------------------------------- 1 | #include "ipc/ipc_server.hpp" 2 | 3 | #include 4 | 5 | #include "ipc/ipc_headers.hpp" 6 | 7 | ipc_server::~ipc_server() { 8 | closesocket(s); 9 | WSACleanup(); 10 | } 11 | 12 | bool ipc_server::init(std::string_view address, unsigned short port) { 13 | if (WSAStartup(MAKEWORD(2, 2), &wsa) != 0) { 14 | return false; 15 | } 16 | 17 | if ((s = socket(AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET) { 18 | return false; 19 | } 20 | 21 | server.sin_family = AF_INET; 22 | server.sin_addr.s_addr = inet_addr(address.data()); 23 | server.sin_port = htons(port); 24 | 25 | if (bind(s, reinterpret_cast(&server), sizeof(server)) == SOCKET_ERROR) { 26 | return false; 27 | } 28 | 29 | if (listen(s, 1) < 0) { 30 | return false; 31 | } 32 | 33 | return true; 34 | } 35 | 36 | void ipc_server::accept() { 37 | int client_length = sizeof(client); 38 | 39 | if ((client_s = ::accept(s, reinterpret_cast(&client), &client_length)) < 0) { 40 | } 41 | } 42 | 43 | void ipc_server::disconnect() { 44 | closesocket(client_s); 45 | } 46 | 47 | void ipc_server::send_string(std::string_view name, std::string_view string) { 48 | header h; 49 | h.size = name.size(); 50 | 51 | send(client_s, reinterpret_cast(&h), sizeof(h), 0); 52 | send(client_s, name.data(), name.size(), 0); 53 | 54 | h.size = string.size(); 55 | 56 | send(client_s, reinterpret_cast(&h), sizeof(h), 0); 57 | send(client_s, string.data(), string.size(), 0); 58 | } 59 | 60 | string_recv ipc_server::recv_string() { 61 | int bytes_received; 62 | string_recv result{}; 63 | 64 | header h{}; 65 | bytes_received = recv(client_s, reinterpret_cast(&h), sizeof(h), 0); 66 | 67 | if (bytes_received == SOCKET_ERROR || bytes_received != sizeof(h)) { 68 | // 69 | } 70 | 71 | result.name = std::string{}; 72 | result.name.resize(h.size); 73 | 74 | bytes_received = recv(client_s, result.name.data(), h.size, 0); 75 | 76 | if (bytes_received == SOCKET_ERROR || bytes_received != h.size) { 77 | // 78 | } 79 | 80 | bytes_received = recv(client_s, reinterpret_cast(&h), sizeof(h), 0); 81 | 82 | if (bytes_received == SOCKET_ERROR || bytes_received != h.size) { 83 | // 84 | } 85 | 86 | result.string.resize(h.size); 87 | 88 | bytes_received = recv(client_s, result.string.data(), h.size, 0); 89 | 90 | if (bytes_received == SOCKET_ERROR || bytes_received != h.size) { 91 | // 92 | } 93 | 94 | return result; 95 | } 96 | 97 | unsigned short ipc_server::get_bound_port() { 98 | sockaddr_in s_in; 99 | int s_in_size = sizeof(s_in); 100 | 101 | getsockname(s, reinterpret_cast(&s_in), &s_in_size); // read binding 102 | 103 | return ntohs(s_in.sin_port); // get the port number 104 | } 105 | -------------------------------------------------------------------------------- /sa_module/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.16) 2 | 3 | project("connd-sa") 4 | 5 | find_package(magic_enum REQUIRED) 6 | find_package(nlohmann_json CONFIG REQUIRED) 7 | find_package(plugin-sdk REQUIRED) 8 | find_package(spdlog REQUIRED) 9 | 10 | add_library("connd-sa" SHARED "dllmain.cpp" 11 | "BitStream.cpp" 12 | "Utils.cpp") 13 | 14 | set_target_properties("connd-sa" 15 | PROPERTIES 16 | CXX_STANDARD 20 17 | CXX_STANDARD_REQUIRED ON 18 | CXX_EXTENSIONS OFF 19 | ) 20 | 21 | target_link_libraries("connd-sa" PRIVATE kthook 22 | sampapi 23 | magic_enum::magic_enum 24 | nlohmann_json::nlohmann_json 25 | pluginsdk::gtasa 26 | connd-ipclib 27 | RakNet 28 | spdlog::spdlog) 29 | 30 | set_target_properties("connd-sa" PROPERTIES 31 | SUFFIX "-by-kin4stat.asi" 32 | #INTERPROCEDURAL_OPTIMIZATION TRUE 33 | MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:DebugDLL>" 34 | ) -------------------------------------------------------------------------------- /sa_module/Utils.cpp: -------------------------------------------------------------------------------- 1 | #include "Utils.hpp" 2 | 3 | #include 4 | #include "Windows.h" 5 | #include "RakNet.hpp" 6 | #include "raknet_state.hpp" 7 | #include "sampapi/CGame.h" 8 | #include "sampapi/0.3.7-R3-1/CNetGame.h" 9 | 10 | bool utils::is_samp_loaded() { 11 | return GetModuleHandleA("samp.dll") != 0; 12 | } 13 | 14 | utils::samp_version utils::get_samp_version() { 15 | static samp_version ver = []() { 16 | auto base = reinterpret_cast(GetModuleHandleA("samp.dll")); 17 | auto ntheader = reinterpret_cast(base + reinterpret_cast(base)->e_lfanew); 18 | // NOLINT(performance-no-int-to-ptr) 19 | auto ep = ntheader->OptionalHeader.AddressOfEntryPoint; 20 | switch (ep) { 21 | case 0x31DF13: 22 | return samp_version::kR1; 23 | case 0xCC4D0: 24 | return samp_version::kR3; 25 | default: 26 | return samp_version::kUnknown; 27 | //case 0xCBCB0: return samp_version::SAMP_0_3_7_R4; 28 | } 29 | }(); 30 | return ver; 31 | } 32 | 33 | 34 | void utils::MemoryFill(std::uintptr_t address, std::uint8_t value, std::size_t size, bool protect) { 35 | DWORD oldProt; 36 | if (protect) VirtualProtect(reinterpret_cast(address), 8, PAGE_READWRITE, &oldProt); 37 | memset(reinterpret_cast(address), value, size); 38 | if (protect) VirtualProtect(reinterpret_cast(address), 8, oldProt, &oldProt); 39 | } 40 | 41 | void utils::SetRaw(std::uintptr_t address, const char* RawData, std::size_t size, bool protect) { 42 | DWORD oldProt; 43 | if (protect) VirtualProtect(reinterpret_cast(address), 8, PAGE_READWRITE, &oldProt); 44 | memcpy(reinterpret_cast(address), RawData, size); 45 | if (protect) VirtualProtect(reinterpret_cast(address), 8, oldProt, &oldProt); 46 | } 47 | -------------------------------------------------------------------------------- /sa_module/Utils.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | #ifdef __RESHARPER__ 6 | #define WRAP_VERSION sampapi::v037r1::VersionTag 7 | #else 8 | #define WRAP_VERSION auto 9 | #endif 10 | 11 | struct PlayerID; 12 | class RakPeer; 13 | struct RPCParameters; 14 | class CPhysical; 15 | 16 | namespace utils { 17 | enum class samp_version { 18 | kR1, 19 | kR3, 20 | kUnknown, 21 | }; 22 | 23 | bool is_samp_loaded(); 24 | samp_version get_samp_version(); 25 | 26 | void MemoryFill(std::uintptr_t address, std::uint8_t value, std::size_t size, bool protect = true); 27 | void SetRaw(std::uintptr_t address, const char* RawData, std::size_t size, bool protect = true); 28 | } 29 | -------------------------------------------------------------------------------- /sa_module/actors_state.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | #include "samp_types.hpp" 7 | #include "crtp_singleton.hpp" 8 | #include "RakNet.hpp" 9 | #include "vector.hpp" 10 | #include "sampapi/CNetGame.h" 11 | 12 | class rpc_handler; 13 | class BitStream; 14 | 15 | class actors_state : public Singleton { 16 | public: 17 | actors_state() = default; 18 | ~actors_state() override = default; 19 | 20 | void init(rpc_handler* rpch) { 21 | } 22 | 23 | template 24 | void store(WRAP_VERTAG version, nlohmann::json& to) { 25 | auto samp_pool = RefNetGame(version)->GetActorPool(); 26 | 27 | auto& this_pool = to["actor_pool"]; 28 | for (auto i = 0u; i < 1000; ++i) { 29 | if (!samp_pool->m_bNotEmpty[i]) continue; 30 | auto actor_info = samp_pool->m_pGameObject[i]; 31 | if (!actor_info) continue; 32 | 33 | ActorInfo this_state{}; 34 | 35 | this_state.id = i; 36 | this_state.model = actor_info->m_nModelIndex; 37 | this_state.position = actor_info->GetPosition(); 38 | this_state.rotation = actor_info->GetHeading(); 39 | this_state.health = actor_info->m_fHealth; 40 | this_state.invulnerable = actor_info->m_nPhysicalFlags.bBulletProof; 41 | 42 | this_pool.emplace_back(this_state); 43 | } 44 | } 45 | 46 | template 47 | void restore(WRAP_VERTAG version, const nlohmann::json& from) { 48 | auto samp_pool = RefNetGame(version)->GetActorPool(); 49 | for (auto& j : from["actor_pool"]) { 50 | auto this_state = j.get(); 51 | 52 | using actor_info_t = decltype(get_actor_info_type(version)); 53 | 54 | samp_pool->Create(reinterpret_cast(&this_state)); 55 | 56 | auto game_ped = samp_pool->Get(this_state.id)->m_pGamePed; 57 | game_ped->Teleport(this_state.position, true); 58 | game_ped->m_fCurrentRotation = this_state.rotation; 59 | game_ped->m_fAimingRotation = this_state.rotation; 60 | game_ped->SetHeading(this_state.rotation); 61 | 62 | reinterpret_cast(0x446F90)(game_ped); 63 | } 64 | } 65 | 66 | private: 67 | void on_rpc(RPCEnumeration rpc_id, BitStream*, std::uint16_t pid) { 68 | } 69 | }; 70 | -------------------------------------------------------------------------------- /sa_module/camera_state.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | #include "samp_types.hpp" 8 | #include "crtp_singleton.hpp" 9 | #include "RakNet.hpp" 10 | #include "cp2utf.hpp" 11 | #include "sampapi/CGame.h" 12 | #include "sampapi/CNetGame.h" 13 | 14 | class rpc_handler; 15 | class BitStream; 16 | 17 | 18 | class camera_state : public Singleton { 19 | public: 20 | camera_state() = default; 21 | ~camera_state() override = default; 22 | 23 | void init(rpc_handler* rpch) { 24 | } 25 | 26 | template 27 | void store(WRAP_VERTAG version, nlohmann::json& to) { 28 | auto samp_cam = RefGame(version)->GetCamera(); 29 | auto object_pool = RefNetGame(version)->GetObjectPool(); 30 | 31 | Camera this_state{}; 32 | 33 | this_state.attached_to_object = 0xFFFF; 34 | 35 | if (samp_cam->m_pAttachedTo) { 36 | for (auto i = 0u; i < 1000; ++i) { 37 | if (object_pool->m_pObject[i] == samp_cam->m_pAttachedTo) { 38 | this_state.attached_to_object = i; 39 | break; 40 | } 41 | } 42 | } 43 | 44 | if (this_state.attached_to_object == 0xFFFF) { 45 | if (TheCamera.m_bLookingAtVector) { 46 | this_state.look_at_coords.emplace(TheCamera.m_vecFixedModeVector, 47 | TheCamera.m_vecFixedModeSource, 48 | TheCamera.m_vecFixedModeUpOffSet); 49 | } 50 | 51 | if (TheCamera.m_fTrackLinearEndTime - CTimer::m_snTimeInMilliseconds > 0) { 52 | this_state.move_cam = Camera::MoveCam{}; 53 | this_state.move_cam->ticks_left = TheCamera.m_fTrackLinearEndTime - CTimer::m_snTimeInMilliseconds; 54 | this_state.move_cam->track = true; 55 | this_state.move_cam->from = TheCamera.m_vecTrackLinear; 56 | this_state.move_cam->to = TheCamera.m_vecTrackLinearEndPoint; 57 | this_state.move_cam->with_ease = TheCamera.m_bTrackLinearWithEase; 58 | } 59 | else if (TheCamera.m_fMoveLinearEndTime - CTimer::m_snTimeInMilliseconds > 0) { 60 | this_state.move_cam = Camera::MoveCam{}; 61 | this_state.move_cam->ticks_left = TheCamera.m_fMoveLinearEndTime - CTimer::m_snTimeInMilliseconds; 62 | this_state.move_cam->track = true; 63 | this_state.move_cam->from = TheCamera.m_vecMoveLinear; 64 | this_state.move_cam->to = TheCamera.m_vecMoveLinearPosnEnd; 65 | this_state.move_cam->with_ease = TheCamera.m_bMoveLinearWithEase; 66 | } 67 | } 68 | 69 | to.emplace("camera", this_state); 70 | } 71 | 72 | template 73 | void restore(WRAP_VERTAG version, const nlohmann::json& from) { 74 | auto samp_cam = RefGame(version)->GetCamera(); 75 | auto object_pool = RefNetGame(version)->GetObjectPool(); 76 | 77 | auto this_state = from["camera"].get(); 78 | 79 | if (this_state.attached_to_object != 0xFFFF) { 80 | samp_cam->Attach(object_pool->m_pObject[this_state.attached_to_object]); 81 | return; 82 | } 83 | if (this_state.look_at_coords.has_value()) { 84 | CVector pos = this_state.look_at_coords->position; 85 | CVector rotation = this_state.look_at_coords->rotation; 86 | CVector look_at = this_state.look_at_coords->look_at; 87 | TheCamera.TakeControlNoEntity(&look_at, 2, 1); 88 | TheCamera.SetCamPositionForFixedMode(&pos, &rotation); 89 | } 90 | else if (this_state.move_cam.has_value()) { 91 | auto func = &CCamera::VectorMoveLinear; 92 | if (this_state.move_cam->track) 93 | func = &CCamera::VectorTrackLinear; 94 | 95 | CVector start_point = this_state.move_cam->from; 96 | CVector end_point = this_state.move_cam->to; 97 | float ticks_left = this_state.move_cam->ticks_left; 98 | bool with_ease = this_state.move_cam->with_ease; 99 | std::invoke(func, &TheCamera, &start_point, &end_point, ticks_left, with_ease); 100 | } 101 | } 102 | 103 | private: 104 | void on_rpc(RPCEnumeration rpc_id, BitStream*, std::uint16_t pid) { 105 | } 106 | }; 107 | -------------------------------------------------------------------------------- /sa_module/chat_state.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "crtp_singleton.hpp" 6 | #include "RakNet.hpp" 7 | #include "cp2utf.hpp" 8 | #include "samp_types.hpp" 9 | #include "sampapi/CChat.h" 10 | 11 | class rpc_handler; 12 | class BitStream; 13 | 14 | 15 | class chat_state : public Singleton { 16 | public: 17 | chat_state() = default; 18 | ~chat_state() override = default; 19 | 20 | void init(rpc_handler* rpch) { 21 | } 22 | 23 | template 24 | void store(WRAP_VERTAG version, nlohmann::json& to) { 25 | auto samp_chat = RefChat(version); 26 | 27 | Chat this_state{}; 28 | this_state.mode = samp_chat->m_nMode; 29 | 30 | for (auto& entry : samp_chat->m_entry) { 31 | if (!entry.m_timestamp) continue; 32 | 33 | Chat::ChatEntry this_entry; 34 | 35 | this_entry.timestamp = entry.m_timestamp; 36 | this_entry.prefix = cp2utf(entry.m_szPrefix); 37 | this_entry.text = cp2utf(entry.m_szText); 38 | this_entry.type = entry.m_nType; 39 | this_entry.text_color = entry.m_textColor; 40 | this_entry.prefix_color = entry.m_prefixColor; 41 | 42 | this_state.entries.emplace_back(std::move(this_entry)); 43 | } 44 | 45 | to.emplace("chat", std::move(this_state)); 46 | } 47 | 48 | template 49 | void restore(WRAP_VERTAG version, const nlohmann::json& from) { 50 | auto this_state = from["chat"].get(); 51 | auto samp_chat = RefChat(version); 52 | 53 | samp_chat->m_nMode = this_state.mode; 54 | 55 | memset(samp_chat->m_entry, 0, sizeof(samp_chat->m_entry)); 56 | 57 | for (auto& this_entry : this_state.entries) { 58 | auto prefix = utf2cp(this_entry.prefix); 59 | 60 | samp_chat->AddEntry(this_entry.type, 61 | utf2cp(this_entry.text).c_str(), 62 | prefix.empty() ? nullptr : prefix.c_str(), 63 | this_entry.text_color, 64 | this_entry.prefix_color); 65 | } 66 | samp_chat->m_bRedraw = true; 67 | } 68 | 69 | private: 70 | void on_rpc(RPCEnumeration rpc_id, BitStream*, std::uint16_t pid) { 71 | } 72 | }; 73 | -------------------------------------------------------------------------------- /sa_module/checkpoint_state.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "BitStream.hpp" 6 | #include "crtp_singleton.hpp" 7 | #include "RakNet.hpp" 8 | #include "samp_types.hpp" 9 | #include "vector.hpp" 10 | #include "sampapi/sampapi.h" 11 | #include "sampapi/CGame.h" 12 | 13 | class rpc_handler; 14 | 15 | 16 | class checkpoint_state : public Singleton { 17 | public: 18 | checkpoint_state() = default; 19 | ~checkpoint_state() override = default; 20 | 21 | void init(rpc_handler* rpch) { 22 | } 23 | 24 | template 25 | void store(WRAP_VERTAG version, nlohmann::json& to) { 26 | auto game = RefGame(version); 27 | 28 | Checkpoints this_state{}; 29 | 30 | if (game->m_checkpoint.m_bEnabled) { 31 | this_state.checkpoint.emplace(game->m_checkpoint.m_position, 32 | game->m_checkpoint.m_size); 33 | } 34 | if (game->m_racingCheckpoint.m_bEnabled) { 35 | this_state.race_checkpoint.emplace(game->m_racingCheckpoint.m_currentPosition, 36 | game->m_racingCheckpoint.m_nextPosition, 37 | game->m_racingCheckpoint.m_fSize, game->m_racingCheckpoint.m_nType); 38 | } 39 | 40 | to.emplace("checkpoints", this_state); 41 | } 42 | 43 | template 44 | void restore(WRAP_VERTAG version, const nlohmann::json& from) { 45 | auto game = RefGame(version); 46 | 47 | auto this_state = from["checkpoints"].get(); 48 | 49 | if (this_state.checkpoint.has_value()) { 50 | sampapi::CVector pos = this_state.checkpoint->position; 51 | sampapi::CVector size = this_state.checkpoint->size; 52 | game->SetCheckpoint(&pos, &size); 53 | game->m_checkpoint.m_bEnabled = true; 54 | } 55 | if (this_state.race_checkpoint.has_value()) { 56 | sampapi::CVector next_position = this_state.race_checkpoint->next_position; 57 | sampapi::CVector current_position = this_state.race_checkpoint->current_position; 58 | game->SetRacingCheckpoint(this_state.race_checkpoint->type, 59 | &next_position, 60 | ¤t_position, 61 | this_state.race_checkpoint->size); 62 | 63 | game->m_racingCheckpoint.m_bEnabled = true; 64 | } 65 | } 66 | 67 | private: 68 | void on_rpc(RPCEnumeration rpc_id, BitStream*, std::uint16_t pid) { 69 | } 70 | }; 71 | -------------------------------------------------------------------------------- /sa_module/cp2utf.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | 6 | inline std::wstring utf8_to_utf16(std::string_view utf8) { 7 | if (utf8.empty()) return L""; 8 | std::wstring utf16; 9 | const int utf8_len = static_cast(utf8.length()); 10 | auto utf8_data = reinterpret_cast(utf8.data()); 11 | 12 | const int utf16_len = ::MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, utf8_data, utf8_len, nullptr, 0); 13 | if (utf16_len == 0) return utf16; 14 | utf16.resize(utf16_len); 15 | ::MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, utf8_data, utf8_len, utf16.data(), utf16.size()); 16 | return utf16; 17 | } 18 | 19 | inline std::string utf16_to_utf8(std::wstring_view utf16) { 20 | if (utf16.empty()) return ""; 21 | std::string utf8; 22 | const int utf16_len = static_cast(utf16.length()); 23 | const wchar_t* utf16_data = utf16.data(); 24 | 25 | const int utf8_len = ::WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, utf16_data, utf16_len, nullptr, 0, 0, 0); 26 | if (utf8_len == 0) return utf8; 27 | utf8.resize(utf8_len); 28 | auto utf8_data = reinterpret_cast(utf8.data()); 29 | ::WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, utf16_data, utf16_len, utf8_data, utf8.size(), 0, 0); 30 | return utf8; 31 | } 32 | 33 | inline std::wstring cpacp_to_utf16(std::string_view cpacp) { 34 | if (cpacp.empty()) return L""; 35 | std::wstring utf16; 36 | const char* cpacp_data = cpacp.data(); 37 | const int cpacp_len = static_cast(cpacp.length()); 38 | 39 | const int utf16_len = ::MultiByteToWideChar(CP_ACP, 0, cpacp_data, cpacp_len, nullptr, 0); 40 | if (utf16_len == 0) return L""; 41 | utf16.resize(utf16_len); 42 | ::MultiByteToWideChar(CP_ACP, 0, cpacp_data, cpacp_len, utf16.data(), utf16.size()); 43 | return utf16; 44 | } 45 | 46 | inline std::string cpacp_to_utf8(std::string_view cpacp) { 47 | if (cpacp.empty()) return ""; 48 | std::wstring utf16; 49 | const char* cpacp_data = cpacp.data(); 50 | const int cpacp_len = static_cast(cpacp.length()); 51 | 52 | const int utf16_len = ::MultiByteToWideChar(CP_ACP, 0, cpacp_data, cpacp_len, nullptr, 0); 53 | if (utf16_len == 0) return ""; 54 | utf16.resize(utf16_len); 55 | ::MultiByteToWideChar(CP_ACP, 0, cpacp_data, cpacp_len, utf16.data(), utf16.size()); 56 | return utf16_to_utf8(utf16); 57 | } 58 | 59 | inline std::string utf8_to_cpacp(std::string_view utf8) { 60 | if (utf8.empty()) return ""; 61 | std::string cpacp; 62 | std::wstring utf16 = utf8_to_utf16(utf8); 63 | const int utf16_len = static_cast(utf16.length()); 64 | const wchar_t* utf16_data = utf16.c_str(); 65 | const int cpacp_len = ::WideCharToMultiByte(CP_ACP, 0, utf16_data, utf16_len, nullptr, 0, 0, 0); 66 | if (cpacp_len == 0) return ""; 67 | cpacp.resize(cpacp_len); 68 | ::WideCharToMultiByte(CP_ACP, 0, utf16_data, utf16_len, cpacp.data(), cpacp.size(), 0, 0); 69 | return cpacp; 70 | } 71 | 72 | inline std::string cp2utf(std::string_view cpacp) { 73 | return cpacp_to_utf8(cpacp); 74 | } 75 | 76 | inline std::string utf2cp(std::string_view utf8) { 77 | return utf8_to_cpacp(utf8); 78 | } -------------------------------------------------------------------------------- /sa_module/crtp_singleton.hpp: -------------------------------------------------------------------------------- 1 | #ifndef CRTP_SINGLETON_HPP_ 2 | #define CRTP_SINGLETON_HPP_ 3 | #include 4 | 5 | template 6 | class Singleton { 7 | public: 8 | template 9 | static T* instance(Args&&... args) { 10 | static T instance{std::forward(args)...}; 11 | 12 | return &instance; 13 | } 14 | 15 | protected: 16 | Singleton() = default; 17 | Singleton(const Singleton&) = delete; 18 | Singleton& operator=(const Singleton&) = delete; 19 | virtual ~Singleton() = default; 20 | }; 21 | 22 | #endif // CRTP_SINGLETON_HPP_ 23 | -------------------------------------------------------------------------------- /sa_module/dialog_state.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "samp_types.hpp" 6 | #include "Utils.hpp" 7 | #include "cp2utf.hpp" 8 | #include "kthook/kthook.hpp" 9 | #include "crtp_singleton.hpp" 10 | #include "RakNet.hpp" 11 | #include "sampapi/CDialog.h" 12 | 13 | class rpc_handler; 14 | class BitStream; 15 | 16 | class dialog_state : public Singleton { 17 | using CDialog__Show = void(CTHISCALL*)(void*, int, int, const char*, const char*, const char*, const char*, int); 18 | using CDialog__Close = void(CTHISCALL*)(void*, char); 19 | 20 | public: 21 | dialog_state() = default; 22 | ~dialog_state() override = default; 23 | 24 | template 25 | void init(WRAP_VERTAG version, rpc_handler* rpch) { 26 | 27 | dialog_show_hook.set_dest(sampapi::GetAddress(Addresses::dialog_open)); 28 | dialog_close_hook.set_dest(sampapi::GetAddress(Addresses::dialog_close)); 29 | 30 | dialog_show_hook.set_cb([this](const auto& hook, 31 | void* dialog_ptr, 32 | int id, 33 | int type, 34 | const char* caption, 35 | const char* text, 36 | const char* left_button, 37 | const char* right_button, 38 | int serverside) { 39 | Dialog temp; 40 | temp.id = id; 41 | temp.type = type; 42 | temp.caption = cp2utf(caption); 43 | temp.text = cp2utf(text); 44 | temp.left_button = cp2utf(left_button); 45 | temp.right_button = cp2utf(right_button); 46 | temp.serverside = serverside; 47 | 48 | this_state.emplace(std::move(temp)); 49 | 50 | return hook.get_trampoline()(dialog_ptr, id, type, caption, text, left_button, right_button, serverside); 51 | }); 52 | dialog_close_hook.set_cb([this](const auto& hook, void* dialog_ptr, char btn) { 53 | this_state.reset(); 54 | 55 | return hook.get_trampoline()(dialog_ptr, btn); 56 | }); 57 | 58 | dialog_show_hook.install(); 59 | dialog_close_hook.install(); 60 | } 61 | 62 | template 63 | void store(WRAP_VERTAG version, nlohmann::json& to) { 64 | to.emplace("dialog", std::move(this_state)); 65 | } 66 | 67 | template 68 | void restore(WRAP_VERTAG version, const nlohmann::json& from) { 69 | this_state = from["dialog"].get>(); 70 | 71 | if (this_state.has_value()) 72 | RefDialog(version)->Show(this_state->id, 73 | this_state->type, 74 | utf2cp(this_state->caption).c_str(), 75 | utf2cp(this_state->text).c_str(), 76 | utf2cp(this_state->left_button).c_str(), 77 | utf2cp(this_state->right_button).c_str(), 78 | this_state->serverside); 79 | } 80 | 81 | private: 82 | void on_rpc(RPCEnumeration rpc_id, BitStream*, std::uint16_t pid) { 83 | } 84 | 85 | kthook::kthook_simple dialog_show_hook; 86 | kthook::kthook_simple dialog_close_hook; 87 | 88 | std::optional this_state{}; 89 | }; 90 | -------------------------------------------------------------------------------- /sa_module/gangzone_state.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "samp_types.hpp" 6 | #include "crtp_singleton.hpp" 7 | #include "RakNet.hpp" 8 | #include "sampapi/CNetGame.h" 9 | 10 | class rpc_handler; 11 | class BitStream; 12 | 13 | 14 | class gangzone_state : public Singleton { 15 | public: 16 | gangzone_state() = default; 17 | ~gangzone_state() override = default; 18 | 19 | void init(rpc_handler* rpch) { 20 | } 21 | 22 | template 23 | void store(WRAP_VERTAG version, nlohmann::json& to) const { 24 | const auto samp_pool = RefNetGame(version)->m_pPools->m_pGangzone; 25 | auto& pool = to["gangzone_pool"]; 26 | 27 | for (auto i = 0u; i < 1024; ++i) { 28 | if (!samp_pool->m_bNotEmpty[i]) continue; 29 | auto entry = samp_pool->m_pObject[i]; 30 | if (!entry) continue; 31 | 32 | GangZone this_state{}; 33 | 34 | 35 | this_state._this_id = i; 36 | this_state.left = entry->m_rect.left; 37 | this_state.bottom = entry->m_rect.bottom; 38 | this_state.right = entry->m_rect.right; 39 | this_state.top = entry->m_rect.top; 40 | this_state.color = entry->m_color; 41 | this_state.alt_color = entry->m_altColor; 42 | 43 | pool.emplace_back(this_state); 44 | } 45 | } 46 | 47 | template 48 | void restore(WRAP_VERTAG version, nlohmann::json& from) const { 49 | const auto samp_pool = RefNetGame(version)->m_pPools->m_pGangzone; 50 | 51 | for (auto& arr : from["gangzone_pool"]) { 52 | const auto this_state = arr.get(); 53 | 54 | samp_pool->Create(this_state._this_id, 55 | this_state.left, 56 | this_state.top, 57 | this_state.right, 58 | this_state.bottom, 59 | this_state.color); 60 | 61 | if (this_state.color != this_state.alt_color) { 62 | samp_pool->StartFlashing(this_state._this_id, this_state.alt_color); 63 | } 64 | } 65 | } 66 | 67 | private: 68 | void on_rpc(RPCEnumeration rpc_id, BitStream*, std::uint16_t pid) { 69 | } 70 | }; 71 | -------------------------------------------------------------------------------- /sa_module/ipc_client.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | class ipc_client { 7 | public: 8 | ipc_client() = default; 9 | ~ipc_client(); 10 | 11 | void init(); 12 | void connect(std::string_view hostname, unsigned short hostport); 13 | 14 | private: 15 | sockaddr_in server{}; 16 | WSADATA wsa{}; 17 | SOCKET s{}; 18 | }; 19 | -------------------------------------------------------------------------------- /sa_module/json_utils.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | NLOHMANN_JSON_NAMESPACE_BEGIN 5 | template 6 | struct adl_serializer> { 7 | static void to_json(json& j, const std::optional& opt) { 8 | if (!opt.has_value()) { 9 | j = nullptr; 10 | } else { 11 | j = *opt; 12 | } 13 | } 14 | 15 | static void from_json(const json& j, std::optional& opt) { 16 | if (j.is_null()) { 17 | opt = std::nullopt; 18 | } else { 19 | opt = j.get(); 20 | } 21 | } 22 | }; 23 | NLOHMANN_JSON_NAMESPACE_END -------------------------------------------------------------------------------- /sa_module/kill_list_state.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include "samp_types.hpp" 7 | #include "crtp_singleton.hpp" 8 | #include "RakNet.hpp" 9 | #include "cp2utf.hpp" 10 | #include "sampapi/CDeathWindow.h" 11 | 12 | class rpc_handler; 13 | class BitStream; 14 | 15 | 16 | class kill_list_state : public Singleton { 17 | public: 18 | kill_list_state() = default; 19 | ~kill_list_state() override = default; 20 | 21 | void init(rpc_handler* rpch) { 22 | } 23 | 24 | template 25 | void store(WRAP_VERTAG version, nlohmann::json& to) { 26 | auto kill_list = RefDeathWindow(version); 27 | 28 | KillList this_state{}; 29 | this_state.enabled = kill_list->m_bEnabled; 30 | 31 | auto i = 0u; 32 | for (auto& entry : kill_list->m_entry) { 33 | auto& this_entry = this_state.entries[i]; 34 | 35 | this_entry.killer = cp2utf(entry.m_szKiller); 36 | this_entry.victim = cp2utf(entry.m_szVictim); 37 | this_entry.killer_color = entry.m_killerColor; 38 | this_entry.victim_color = entry.m_victimColor; 39 | this_entry.weapon = entry.m_nWeapon; 40 | ++i; 41 | } 42 | 43 | to.emplace("kill_list", std::move(this_state)); 44 | } 45 | 46 | template 47 | void restore(WRAP_VERTAG version, const nlohmann::json& from) { 48 | const auto this_state = from["kill_list"].get(); 49 | const auto kill_list = RefDeathWindow(version); 50 | 51 | kill_list->m_bEnabled = this_state.enabled; 52 | auto i = 0u; 53 | for (auto& this_entry : this_state.entries) { 54 | auto& samp_entry = kill_list->m_entry[i]; 55 | 56 | std::ranges::copy(utf2cp(this_entry.killer), 57 | std::begin(samp_entry.m_szKiller)); 58 | std::ranges::copy(utf2cp(this_entry.victim), 59 | std::begin(samp_entry.m_szVictim)); 60 | samp_entry.m_killerColor = this_entry.killer_color; 61 | samp_entry.m_victimColor = this_entry.victim_color; 62 | samp_entry.m_nWeapon = this_entry.weapon; 63 | ++i; 64 | } 65 | } 66 | 67 | private: 68 | void on_rpc(RPCEnumeration rpc_id, BitStream*, std::uint16_t pid) { 69 | } 70 | }; 71 | -------------------------------------------------------------------------------- /sa_module/labels_state.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "samp_types.hpp" 6 | #include "crtp_singleton.hpp" 7 | #include "sampapi/sampapi.h" 8 | #include "cp2utf.hpp" 9 | #include "sampapi/CNetGame.h" 10 | 11 | class rpc_handler; 12 | 13 | 14 | class labels_state : public Singleton { 15 | public: 16 | labels_state() = default; 17 | ~labels_state() override = default; 18 | 19 | void init(rpc_handler* rpch) { 20 | } 21 | 22 | template 23 | void store(WRAP_VERTAG version, nlohmann::json& to) { 24 | auto& json_pool = to["label_pool"]; 25 | 26 | auto pool = RefNetGame(version)->m_pPools->m_pLabel; 27 | 28 | for (auto i = 0u; i < 2048; ++i) { 29 | if (pool->m_bNotEmpty[i]) { 30 | auto& samp_label = pool->m_object[i]; 31 | 32 | Label temp; 33 | 34 | temp.this_id = i; 35 | 36 | temp.text = cp2utf(samp_label.m_pText); 37 | temp.color = samp_label.m_color; 38 | temp.position = samp_label.m_position; 39 | temp.draw_distance = samp_label.m_fDrawDistance; 40 | temp.draw_behind_walls = samp_label.m_bBehindWalls; 41 | temp.attached_to_player = samp_label.m_nAttachedToPlayer; 42 | temp.attached_to_vehicle = samp_label.m_nAttachedToVehicle; 43 | 44 | json_pool.emplace_back(std::move(temp)); 45 | } 46 | } 47 | } 48 | 49 | template 50 | void restore(WRAP_VERTAG version, const nlohmann::json& from) { 51 | auto label_pool = RefNetGame(version)->m_pPools->m_pLabel; 52 | for (auto& j : from["label_pool"]) { 53 | auto temp = j.get