├── README.md ├── app ├── .gitignore ├── RakSAMPClient.xml ├── binding.gyp ├── index.js ├── node_modules │ └── nan │ │ ├── CHANGELOG.md │ │ ├── LICENSE.md │ │ ├── README.md │ │ ├── doc │ │ ├── asyncworker.md │ │ ├── buffers.md │ │ ├── callback.md │ │ ├── converters.md │ │ ├── errors.md │ │ ├── json.md │ │ ├── maybe_types.md │ │ ├── methods.md │ │ ├── new.md │ │ ├── node_misc.md │ │ ├── object_wrappers.md │ │ ├── persistent.md │ │ ├── scopes.md │ │ ├── script.md │ │ ├── string_bytes.md │ │ ├── v8_internals.md │ │ └── v8_misc.md │ │ ├── include_dirs.js │ │ ├── nan-2.11.1.tgz │ │ ├── nan.h │ │ ├── nan_callbacks.h │ │ ├── nan_callbacks_12_inl.h │ │ ├── nan_callbacks_pre_12_inl.h │ │ ├── nan_converters.h │ │ ├── nan_converters_43_inl.h │ │ ├── nan_converters_pre_43_inl.h │ │ ├── nan_define_own_property_helper.h │ │ ├── nan_implementation_12_inl.h │ │ ├── nan_implementation_pre_12_inl.h │ │ ├── nan_json.h │ │ ├── nan_maybe_43_inl.h │ │ ├── nan_maybe_pre_43_inl.h │ │ ├── nan_new.h │ │ ├── nan_object_wrap.h │ │ ├── nan_persistent_12_inl.h │ │ ├── nan_persistent_pre_12_inl.h │ │ ├── nan_private.h │ │ ├── nan_string_bytes.h │ │ ├── nan_typedarray_contents.h │ │ ├── nan_weak.h │ │ ├── package.json │ │ └── tools │ │ ├── 1to2.js │ │ ├── README.md │ │ └── package.json └── package.json └── src ├── AsynchronousFileIO.cpp ├── AsynchronousFileIO.h ├── AutopatcherPatchContext.h ├── AutopatcherRepositoryInterface.h ├── BigTypes.h ├── BitStream.cpp ├── BitStream.h ├── BitStream_NoTemplate.cpp ├── BitStream_NoTemplate.h ├── CheckSum.cpp ├── CheckSum.h ├── ClientContextStruct.h ├── CommandParserInterface.cpp ├── CommandParserInterface.h ├── ConsoleServer.cpp ├── ConsoleServer.h ├── DS_BPlusTree.h ├── DS_BinarySearchTree.h ├── DS_ByteQueue.cpp ├── DS_ByteQueue.h ├── DS_Heap.h ├── DS_HuffmanEncodingTree.cpp ├── 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.cpp ├── DS_Table.h ├── DS_Tree.h ├── DS_WeightedGraph.h ├── DataBlockEncryptor.cpp ├── DataBlockEncryptor.h ├── DataCompressor.cpp ├── DataCompressor.h ├── EmailSender.cpp ├── EmailSender.h ├── EncodeClassName.cpp ├── Export.h ├── ExtendedOverlappedPool.cpp ├── ExtendedOverlappedPool.h ├── FileOperations.cpp ├── FileOperations.h ├── FullyConnectedMesh.cpp ├── FullyConnectedMesh.h ├── GetTime.cpp ├── GetTime.h ├── InternalPacket.h ├── InternalPacketPool.cpp ├── InternalPacketPool.h ├── LinuxStrings.cpp ├── LinuxStrings.h ├── LogCommandParser.cpp ├── LogCommandParser.h ├── MTUSize.h ├── NetworkIDGenerator.cpp ├── NetworkIDGenerator.h ├── NetworkTypes.cpp ├── NetworkTypes.h ├── PacketEnumerations.h ├── PacketPool.h ├── PacketPriority.h ├── PluginInterface.cpp ├── PluginInterface.h ├── RPCMap.cpp ├── RPCMap.h ├── RPCNode.h ├── RSACrypt.h ├── RakAssert.h ├── RakClient.cpp ├── RakClient.h ├── RakClientInterface.h ├── RakNetCommandParser.cpp ├── RakNetCommandParser.h ├── RakNetDefines.h ├── RakNetStatistics.cpp ├── RakNetStatistics.h ├── RakNetworkFactory.cpp ├── RakNetworkFactory.h ├── RakPeer.cpp ├── RakServer.h ├── RakSleep.cpp ├── RakSleep.h ├── Rand.cpp ├── Rand.h ├── ReliabilityLayer.cpp ├── ReliabilityLayer.h ├── Replica.h ├── ReplicaEnums.h ├── RouterInterface.h ├── SAMP ├── SAMPRPC.cpp ├── SAMPRPC.h ├── SAMP_VER.h ├── samp_auth.cpp ├── samp_auth.h ├── samp_netencr.cpp └── samp_netencr.h ├── SHA1.cpp ├── SHA1.h ├── SimpleMutex.cpp ├── SimpleMutex.h ├── SimpleTCPServer.h ├── SingleProducerConsumer.h ├── SocketLayer.cpp ├── SocketLayer.h ├── StringCompressor.cpp ├── StringCompressor.h ├── StringTable.cpp ├── StringTable.h ├── SystemAddressList.cpp ├── SystemDatabaseClient.cpp ├── SystemDatabaseClient.h ├── SystemDatabaseServer.cpp ├── SystemDatabaseServer.h ├── TCPInterface.cpp ├── TCPInterface.h ├── TableSerializer.cpp ├── TableSerializer.h ├── TelnetTransport.cpp ├── TelnetTransport.h ├── ThreadPool.h ├── TransportInterface.h ├── Types.h ├── _findfirst.cpp ├── _findfirst.h ├── common ├── common.cpp └── common.h ├── main ├── localplayer.cpp ├── localplayer.h ├── log.cpp ├── log.h ├── main.cpp ├── main.h ├── misc_funcs.cpp ├── misc_funcs.h ├── xmlsets.cpp └── xmlsets.h ├── multiplayer.h ├── net ├── netgame.cpp ├── netgame.h ├── netrpc.cpp └── netrpc.h ├── rakpeer.h ├── rakpeerinterface.h ├── rakserver.cpp ├── rakserverinterface.h ├── rijndael-boxes.h ├── rijndael.cpp ├── rijndael.h ├── systemaddresslist.h └── tinyxml ├── tinystr.cpp ├── tinystr.h ├── tinyxml.cpp ├── tinyxml.h ├── tinyxmlerror.cpp └── tinyxmlparser.cpp /README.md: -------------------------------------------------------------------------------- 1 | # RakNet Fake Client for San Andreas Multiplayer 2 | ### This is an incomplete wrap of RakNet SAMP Fake Client for NodeJS 3 | ___ 4 | 5 | ### Basic Informations 6 | This is a fork of https://github.com/P3ti/RakSAMP. I used node-gyp to wrap basic RakSAMP functions to read SA:MP messages on a Node environment. I'm not a C/CPP expert so the CPP code may be bad written. 7 | If you need more SA:MP feature you can get them by copying RakSAMP classes in the project and adding them in *binding.gyp*. 8 | 9 | ### Setup 10 | - Install *Node-GYP*. 11 | https://github.com/nodejs/node-gyp 12 | - Insert your Python 2.7 path in *app/package.json* 13 | Node-GYP uses Python 2.7 for some routines. 14 | ``` 15 | "scripts": { 16 | "build": "node-gyp --python="YOUR_PYTHON_ABSOLUTE_PATH" build", 17 | "configure": "node-gyp --python="YOUR_PYTHON_ABSOLUTE_PATH" configure", 18 | "debug": "node-gyp --python="YOUR_PYTHON_ABSOLUTE_PATH" build --debug" 19 | } 20 | ``` 21 | - Open a console in *app* and type `npm install` 22 | This command will install all dependencies defined in package.json. You clearly need NodeJS installed. 23 | - Configure and build the code 24 | Use `npm run configure && npm run debug`. This will configure the building environment and build the code in a new folder called *Build*. 25 | - Insert your nickname and the server IP in *RakSAMPClient.xml* 26 | - Run the software by using `node index.js` 27 | 28 | 29 | ### Known issues 30 | - The code won't compile in Release mode. At the end of compiling it says that's impossible to open the compiled file (*samp.node*) while in Debug mode it compiles correctly. 31 | 32 | - The main loop in *src/main/main.cpp* makes it impossible to use other Cpp functions because the thread is occupied. I've tried to put the loop on another thread but - for some reason - it suddenly crashes. As I said I'm not a C/Cpp expert so I don't know very well how can I solve this issue. If you want you can try to fix it and send a pull request. 33 | 34 | 35 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | build -------------------------------------------------------------------------------- /app/RakSAMPClient.xml: -------------------------------------------------------------------------------- 1 | 10 | 11 | 15 | 16 | 0.0.0.0:7777 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /app/index.js: -------------------------------------------------------------------------------- 1 | const { connect } = require('./build/Debug/samp'); 2 | connect(message); 3 | 4 | function message(msg) { 5 | console.log('JAVASCRIPT MSG', msg); 6 | } 7 | -------------------------------------------------------------------------------- /app/node_modules/nan/LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | ===================== 3 | 4 | Copyright (c) 2018 NAN contributors 5 | ----------------------------------- 6 | 7 | *NAN contributors listed at * 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 14 | -------------------------------------------------------------------------------- /app/node_modules/nan/doc/buffers.md: -------------------------------------------------------------------------------- 1 | ## Buffers 2 | 3 | NAN's `node::Buffer` helpers exist as the API has changed across supported Node versions. Use these methods to ensure compatibility. 4 | 5 | - Nan::NewBuffer() 6 | - Nan::CopyBuffer() 7 | - Nan::FreeCallback() 8 | 9 | 10 | ### Nan::NewBuffer() 11 | 12 | Allocate a new `node::Buffer` object with the specified size and optional data. Calls `node::Buffer::New()`. 13 | 14 | Note that when creating a `Buffer` using `Nan::NewBuffer()` and an existing `char*`, it is assumed that the ownership of the pointer is being transferred to the new `Buffer` for management. 15 | When a `node::Buffer` instance is garbage collected and a `FreeCallback` has not been specified, `data` will be disposed of via a call to `free()`. 16 | You _must not_ free the memory space manually once you have created a `Buffer` in this way. 17 | 18 | Signature: 19 | 20 | ```c++ 21 | Nan::MaybeLocal Nan::NewBuffer(uint32_t size) 22 | Nan::MaybeLocal Nan::NewBuffer(char* data, uint32_t size) 23 | Nan::MaybeLocal Nan::NewBuffer(char *data, 24 | size_t length, 25 | Nan::FreeCallback callback, 26 | void *hint) 27 | ``` 28 | 29 | 30 | 31 | ### Nan::CopyBuffer() 32 | 33 | Similar to [`Nan::NewBuffer()`](#api_nan_new_buffer) except that an implicit memcpy will occur within Node. Calls `node::Buffer::Copy()`. 34 | 35 | Management of the `char*` is left to the user, you should manually free the memory space if necessary as the new `Buffer` will have its own copy. 36 | 37 | Signature: 38 | 39 | ```c++ 40 | Nan::MaybeLocal Nan::CopyBuffer(const char *data, uint32_t size) 41 | ``` 42 | 43 | 44 | 45 | ### Nan::FreeCallback() 46 | 47 | A free callback that can be provided to [`Nan::NewBuffer()`](#api_nan_new_buffer). 48 | The supplied callback will be invoked when the `Buffer` undergoes garbage collection. 49 | 50 | Signature: 51 | 52 | ```c++ 53 | typedef void (*FreeCallback)(char *data, void *hint); 54 | ``` 55 | -------------------------------------------------------------------------------- /app/node_modules/nan/doc/callback.md: -------------------------------------------------------------------------------- 1 | ## Nan::Callback 2 | 3 | `Nan::Callback` makes it easier to use `v8::Function` handles as callbacks. A class that wraps a `v8::Function` handle, protecting it from garbage collection and making it particularly useful for storage and use across asynchronous execution. 4 | 5 | - Nan::Callback 6 | 7 | 8 | ### Nan::Callback 9 | 10 | ```c++ 11 | class Callback { 12 | public: 13 | Callback(); 14 | 15 | explicit Callback(const v8::Local &fn); 16 | 17 | ~Callback(); 18 | 19 | bool operator==(const Callback &other) const; 20 | 21 | bool operator!=(const Callback &other) const; 22 | 23 | v8::Local operator*() const; 24 | 25 | MaybeLocal operator()(AsyncResource* async_resource, 26 | v8::Local target, 27 | int argc = 0, 28 | v8::Local argv[] = 0) const; 29 | 30 | MaybeLocal operator()(AsyncResource* async_resource, 31 | int argc = 0, 32 | v8::Local argv[] = 0) const; 33 | 34 | void SetFunction(const v8::Local &fn); 35 | 36 | v8::Local GetFunction() const; 37 | 38 | bool IsEmpty() const; 39 | 40 | void Reset(const v8::Local &fn); 41 | 42 | void Reset(); 43 | 44 | MaybeLocal Call(v8::Local target, 45 | int argc, 46 | v8::Local argv[], 47 | AsyncResource* async_resource) const; 48 | MaybeLocal Call(int argc, 49 | v8::Local argv[], 50 | AsyncResource* async_resource) const; 51 | 52 | // Deprecated versions. Use the versions that accept an async_resource instead 53 | // as they run the callback in the correct async context as specified by the 54 | // resource. If you want to call a synchronous JS function (i.e. on a 55 | // non-empty JS stack), you can use Nan::Call instead. 56 | v8::Local operator()(v8::Local target, 57 | int argc = 0, 58 | v8::Local argv[] = 0) const; 59 | 60 | v8::Local operator()(int argc = 0, 61 | v8::Local argv[] = 0) const; 62 | v8::Local Call(v8::Local target, 63 | int argc, 64 | v8::Local argv[]) const; 65 | 66 | v8::Local Call(int argc, v8::Local argv[]) const; 67 | }; 68 | ``` 69 | 70 | Example usage: 71 | 72 | ```c++ 73 | v8::Local function; 74 | Nan::Callback callback(function); 75 | callback.Call(0, 0); 76 | ``` 77 | -------------------------------------------------------------------------------- /app/node_modules/nan/doc/converters.md: -------------------------------------------------------------------------------- 1 | ## Converters 2 | 3 | NAN contains functions that convert `v8::Value`s to other `v8::Value` types and native types. Since type conversion is not guaranteed to succeed, they return `Nan::Maybe` types. These converters can be used in place of `value->ToX()` and `value->XValue()` (where `X` is one of the types, e.g. `Boolean`) in a way that provides a consistent interface across V8 versions. Newer versions of V8 use the new `v8::Maybe` and `v8::MaybeLocal` types for these conversions, older versions don't have this functionality so it is provided by NAN. 4 | 5 | - Nan::To() 6 | 7 | 8 | ### Nan::To() 9 | 10 | Converts a `v8::Local` to a different subtype of `v8::Value` or to a native data type. Returns a `Nan::MaybeLocal<>` or a `Nan::Maybe<>` accordingly. 11 | 12 | See [maybe_types.md](./maybe_types.md) for more information on `Nan::Maybe` types. 13 | 14 | Signatures: 15 | 16 | ```c++ 17 | // V8 types 18 | Nan::MaybeLocal Nan::To(v8::Local val); 19 | Nan::MaybeLocal Nan::To(v8::Local val); 20 | Nan::MaybeLocal Nan::To(v8::Local val); 21 | Nan::MaybeLocal Nan::To(v8::Local val); 22 | Nan::MaybeLocal Nan::To(v8::Local val); 23 | Nan::MaybeLocal Nan::To(v8::Local val); 24 | Nan::MaybeLocal Nan::To(v8::Local val); 25 | 26 | // Native types 27 | Nan::Maybe Nan::To(v8::Local val); 28 | Nan::Maybe Nan::To(v8::Local val); 29 | Nan::Maybe Nan::To(v8::Local val); 30 | Nan::Maybe Nan::To(v8::Local val); 31 | Nan::Maybe Nan::To(v8::Local val); 32 | ``` 33 | 34 | ### Example 35 | 36 | ```c++ 37 | v8::Local val; 38 | Nan::MaybeLocal str = Nan::To(val); 39 | Nan::Maybe d = Nan::To(val); 40 | ``` 41 | 42 | -------------------------------------------------------------------------------- /app/node_modules/nan/doc/json.md: -------------------------------------------------------------------------------- 1 | ## JSON 2 | 3 | The _JSON_ object provides the c++ versions of the methods offered by the `JSON` object in javascript. V8 exposes these methods via the `v8::JSON` object. 4 | 5 | - Nan::JSON.Parse 6 | - Nan::JSON.Stringify 7 | 8 | Refer to the V8 JSON object in the [V8 documentation](https://v8docs.nodesource.com/node-7.4/da/d6f/classv8_1_1_j_s_o_n.html) for more information about these methods and their arguments. 9 | 10 | 11 | 12 | ### Nan::JSON.Parse 13 | 14 | A simple wrapper around [`v8::JSON::Parse`](https://v8docs.nodesource.com/node-7.4/da/d6f/classv8_1_1_j_s_o_n.html#a936310d2540fb630ed37d3ee3ffe4504). 15 | 16 | Definition: 17 | 18 | ```c++ 19 | Nan::MaybeLocal Nan::JSON::Parse(v8::Local json_string); 20 | ``` 21 | 22 | Use `JSON.Parse(json_string)` to parse a string into a `v8::Value`. 23 | 24 | Example: 25 | 26 | ```c++ 27 | v8::Local json_string = Nan::New("{ \"JSON\": \"object\" }").ToLocalChecked(); 28 | 29 | Nan::JSON NanJSON; 30 | Nan::MaybeLocal result = NanJSON.Parse(json_string); 31 | if (!result.IsEmpty()) { 32 | v8::Local val = result.ToLocalChecked(); 33 | } 34 | ``` 35 | 36 | 37 | 38 | ### Nan::JSON.Stringify 39 | 40 | A simple wrapper around [`v8::JSON::Stringify`](https://v8docs.nodesource.com/node-7.4/da/d6f/classv8_1_1_j_s_o_n.html#a44b255c3531489ce43f6110209138860). 41 | 42 | Definition: 43 | 44 | ```c++ 45 | Nan::MaybeLocal Nan::JSON::Stringify(v8::Local json_object, v8::Local gap = v8::Local()); 46 | ``` 47 | 48 | Use `JSON.Stringify(value)` to stringify a `v8::Object`. 49 | 50 | Example: 51 | 52 | ```c++ 53 | // using `v8::Local val` from the `JSON::Parse` example 54 | v8::Local obj = Nan::To(val).ToLocalChecked(); 55 | 56 | Nan::JSON NanJSON; 57 | Nan::MaybeLocal result = NanJSON.Stringify(obj); 58 | if (!result.IsEmpty()) { 59 | v8::Local stringified = result.ToLocalChecked(); 60 | } 61 | ``` 62 | 63 | -------------------------------------------------------------------------------- /app/node_modules/nan/doc/scopes.md: -------------------------------------------------------------------------------- 1 | ## Scopes 2 | 3 | A _local handle_ is a pointer to an object. All V8 objects are accessed using handles, they are necessary because of the way the V8 garbage collector works. 4 | 5 | A handle scope can be thought of as a container for any number of handles. When you've finished with your handles, instead of deleting each one individually you can simply delete their scope. 6 | 7 | The creation of `HandleScope` objects is different across the supported versions of V8. Therefore, NAN provides its own implementations that can be used safely across these. 8 | 9 | - Nan::HandleScope 10 | - Nan::EscapableHandleScope 11 | 12 | Also see the V8 Embedders Guide section on [Handles and Garbage Collection](https://github.com/v8/v8/wiki/Embedder%27s%20Guide#handles-and-garbage-collection). 13 | 14 | 15 | ### Nan::HandleScope 16 | 17 | A simple wrapper around [`v8::HandleScope`](https://v8docs.nodesource.com/io.js-3.3/d3/d95/classv8_1_1_handle_scope.html). 18 | 19 | Definition: 20 | 21 | ```c++ 22 | class Nan::HandleScope { 23 | public: 24 | Nan::HandleScope(); 25 | static int NumberOfHandles(); 26 | }; 27 | ``` 28 | 29 | Allocate a new `Nan::HandleScope` whenever you are creating new V8 JavaScript objects. Note that an implicit `HandleScope` is created for you on JavaScript-accessible methods so you do not need to insert one yourself. 30 | 31 | Example: 32 | 33 | ```c++ 34 | // new object is created, it needs a new scope: 35 | void Pointless() { 36 | Nan::HandleScope scope; 37 | v8::Local obj = Nan::New(); 38 | } 39 | 40 | // JavaScript-accessible method already has a HandleScope 41 | NAN_METHOD(Pointless2) { 42 | v8::Local obj = Nan::New(); 43 | } 44 | ``` 45 | 46 | 47 | ### Nan::EscapableHandleScope 48 | 49 | Similar to [`Nan::HandleScope`](#api_nan_handle_scope) but should be used in cases where a function needs to return a V8 JavaScript type that has been created within it. 50 | 51 | Definition: 52 | 53 | ```c++ 54 | class Nan::EscapableHandleScope { 55 | public: 56 | Nan::EscapableHandleScope(); 57 | static int NumberOfHandles(); 58 | template v8::Local Escape(v8::Local value); 59 | } 60 | ``` 61 | 62 | Use `Escape(value)` to return the object. 63 | 64 | Example: 65 | 66 | ```c++ 67 | v8::Local EmptyObj() { 68 | Nan::EscapableHandleScope scope; 69 | v8::Local obj = Nan::New(); 70 | return scope.Escape(obj); 71 | } 72 | ``` 73 | 74 | -------------------------------------------------------------------------------- /app/node_modules/nan/doc/script.md: -------------------------------------------------------------------------------- 1 | ## Script 2 | 3 | NAN provides a `v8::Script` helpers as the API has changed over the supported versions of V8. 4 | 5 | - Nan::CompileScript() 6 | - Nan::RunScript() 7 | 8 | 9 | 10 | ### Nan::CompileScript() 11 | 12 | A wrapper around [`v8::Script::Compile()`](https://v8docs.nodesource.com/io.js-3.3/da/da5/classv8_1_1_script_compiler.html#a93f5072a0db55d881b969e9fc98e564b). 13 | 14 | Note that `Nan::BoundScript` is an alias for `v8::Script`. 15 | 16 | Signature: 17 | 18 | ```c++ 19 | Nan::MaybeLocal Nan::CompileScript( 20 | v8::Local s, 21 | const v8::ScriptOrigin& origin); 22 | Nan::MaybeLocal Nan::CompileScript(v8::Local s); 23 | ``` 24 | 25 | 26 | 27 | ### Nan::RunScript() 28 | 29 | Calls `script->Run()` or `script->BindToCurrentContext()->Run(Nan::GetCurrentContext())`. 30 | 31 | Note that `Nan::BoundScript` is an alias for `v8::Script` and `Nan::UnboundScript` is an alias for `v8::UnboundScript` where available and `v8::Script` on older versions of V8. 32 | 33 | Signature: 34 | 35 | ```c++ 36 | Nan::MaybeLocal Nan::RunScript(v8::Local script) 37 | Nan::MaybeLocal Nan::RunScript(v8::Local script) 38 | ``` 39 | -------------------------------------------------------------------------------- /app/node_modules/nan/doc/string_bytes.md: -------------------------------------------------------------------------------- 1 | ## Strings & Bytes 2 | 3 | Miscellaneous string & byte encoding and decoding functionality provided for compatibility across supported versions of V8 and Node. Implemented by NAN to ensure that all encoding types are supported, even for older versions of Node where they are missing. 4 | 5 | - Nan::Encoding 6 | - Nan::Encode() 7 | - Nan::DecodeBytes() 8 | - Nan::DecodeWrite() 9 | 10 | 11 | 12 | ### Nan::Encoding 13 | 14 | An enum representing the supported encoding types. A copy of `node::encoding` that is consistent across versions of Node. 15 | 16 | Definition: 17 | 18 | ```c++ 19 | enum Nan::Encoding { ASCII, UTF8, BASE64, UCS2, BINARY, HEX, BUFFER } 20 | ``` 21 | 22 | 23 | 24 | ### Nan::Encode() 25 | 26 | A wrapper around `node::Encode()` that provides a consistent implementation across supported versions of Node. 27 | 28 | Signature: 29 | 30 | ```c++ 31 | v8::Local Nan::Encode(const void *buf, 32 | size_t len, 33 | enum Nan::Encoding encoding = BINARY); 34 | ``` 35 | 36 | 37 | 38 | ### Nan::DecodeBytes() 39 | 40 | A wrapper around `node::DecodeBytes()` that provides a consistent implementation across supported versions of Node. 41 | 42 | Signature: 43 | 44 | ```c++ 45 | ssize_t Nan::DecodeBytes(v8::Local val, 46 | enum Nan::Encoding encoding = BINARY); 47 | ``` 48 | 49 | 50 | 51 | ### Nan::DecodeWrite() 52 | 53 | A wrapper around `node::DecodeWrite()` that provides a consistent implementation across supported versions of Node. 54 | 55 | Signature: 56 | 57 | ```c++ 58 | ssize_t Nan::DecodeWrite(char *buf, 59 | size_t len, 60 | v8::Local val, 61 | enum Nan::Encoding encoding = BINARY); 62 | ``` 63 | -------------------------------------------------------------------------------- /app/node_modules/nan/doc/v8_misc.md: -------------------------------------------------------------------------------- 1 | ## Miscellaneous V8 Helpers 2 | 3 | - Nan::Utf8String 4 | - Nan::GetCurrentContext() 5 | - Nan::SetIsolateData() 6 | - Nan::GetIsolateData() 7 | - Nan::TypedArrayContents 8 | 9 | 10 | 11 | ### Nan::Utf8String 12 | 13 | Converts an object to a UTF-8-encoded character array. If conversion to a string fails (e.g. due to an exception in the toString() method of the object) then the length() method returns 0 and the * operator returns NULL. The underlying memory used for this object is managed by the object. 14 | 15 | An implementation of [`v8::String::Utf8Value`](https://v8docs.nodesource.com/io.js-3.3/d4/d1b/classv8_1_1_string_1_1_utf8_value.html) that is consistent across all supported versions of V8. 16 | 17 | Definition: 18 | 19 | ```c++ 20 | class Nan::Utf8String { 21 | public: 22 | Nan::Utf8String(v8::Local from); 23 | 24 | int length() const; 25 | 26 | char* operator*(); 27 | const char* operator*() const; 28 | }; 29 | ``` 30 | 31 | 32 | ### Nan::GetCurrentContext() 33 | 34 | A call to [`v8::Isolate::GetCurrent()->GetCurrentContext()`](https://v8docs.nodesource.com/io.js-3.3/d5/dda/classv8_1_1_isolate.html#a81c7a1ed7001ae2a65e89107f75fd053) that works across all supported versions of V8. 35 | 36 | Signature: 37 | 38 | ```c++ 39 | v8::Local Nan::GetCurrentContext() 40 | ``` 41 | 42 | 43 | ### Nan::SetIsolateData() 44 | 45 | A helper to provide a consistent API to [`v8::Isolate#SetData()`](https://v8docs.nodesource.com/io.js-3.3/d5/dda/classv8_1_1_isolate.html#a7acadfe7965997e9c386a05f098fbe36). 46 | 47 | Signature: 48 | 49 | ```c++ 50 | void Nan::SetIsolateData(v8::Isolate *isolate, T *data) 51 | ``` 52 | 53 | 54 | 55 | ### Nan::GetIsolateData() 56 | 57 | A helper to provide a consistent API to [`v8::Isolate#GetData()`](https://v8docs.nodesource.com/io.js-3.3/d5/dda/classv8_1_1_isolate.html#aabd223436bc1100a787dadaa024c6257). 58 | 59 | Signature: 60 | 61 | ```c++ 62 | T *Nan::GetIsolateData(v8::Isolate *isolate) 63 | ``` 64 | 65 | 66 | ### Nan::TypedArrayContents 67 | 68 | A helper class for accessing the contents of an ArrayBufferView (aka a typedarray) from C++. If the input array is not a valid typedarray, then the data pointer of TypedArrayContents will default to `NULL` and the length will be 0. If the data pointer is not compatible with the alignment requirements of type, an assertion error will fail. 69 | 70 | Note that you must store a reference to the `array` object while you are accessing its contents. 71 | 72 | Definition: 73 | 74 | ```c++ 75 | template 76 | class Nan::TypedArrayContents { 77 | public: 78 | TypedArrayContents(v8::Local array); 79 | 80 | size_t length() const; 81 | 82 | T* const operator*(); 83 | const T* const operator*() const; 84 | }; 85 | ``` 86 | -------------------------------------------------------------------------------- /app/node_modules/nan/include_dirs.js: -------------------------------------------------------------------------------- 1 | console.log(require('path').relative('.', __dirname)); 2 | -------------------------------------------------------------------------------- /app/node_modules/nan/nan-2.11.1.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SyncroIT/RakClient-NodeGYP/06ee47c95396ec80e0ce90434e52887b06c44715/app/node_modules/nan/nan-2.11.1.tgz -------------------------------------------------------------------------------- /app/node_modules/nan/nan_callbacks.h: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * NAN - Native Abstractions for Node.js 3 | * 4 | * Copyright (c) 2018 NAN contributors 5 | * 6 | * MIT License 7 | ********************************************************************/ 8 | 9 | #ifndef NAN_CALLBACKS_H_ 10 | #define NAN_CALLBACKS_H_ 11 | 12 | template class FunctionCallbackInfo; 13 | template class PropertyCallbackInfo; 14 | template class Global; 15 | 16 | typedef void(*FunctionCallback)(const FunctionCallbackInfo&); 17 | typedef void(*GetterCallback) 18 | (v8::Local, const PropertyCallbackInfo&); 19 | typedef void(*SetterCallback)( 20 | v8::Local, 21 | v8::Local, 22 | const PropertyCallbackInfo&); 23 | typedef void(*PropertyGetterCallback)( 24 | v8::Local, 25 | const PropertyCallbackInfo&); 26 | typedef void(*PropertySetterCallback)( 27 | v8::Local, 28 | v8::Local, 29 | const PropertyCallbackInfo&); 30 | typedef void(*PropertyEnumeratorCallback) 31 | (const PropertyCallbackInfo&); 32 | typedef void(*PropertyDeleterCallback)( 33 | v8::Local, 34 | const PropertyCallbackInfo&); 35 | typedef void(*PropertyQueryCallback)( 36 | v8::Local, 37 | const PropertyCallbackInfo&); 38 | typedef void(*IndexGetterCallback)( 39 | uint32_t, 40 | const PropertyCallbackInfo&); 41 | typedef void(*IndexSetterCallback)( 42 | uint32_t, 43 | v8::Local, 44 | const PropertyCallbackInfo&); 45 | typedef void(*IndexEnumeratorCallback) 46 | (const PropertyCallbackInfo&); 47 | typedef void(*IndexDeleterCallback)( 48 | uint32_t, 49 | const PropertyCallbackInfo&); 50 | typedef void(*IndexQueryCallback)( 51 | uint32_t, 52 | const PropertyCallbackInfo&); 53 | 54 | namespace imp { 55 | typedef v8::Local Sig; 56 | 57 | static const int kDataIndex = 0; 58 | 59 | static const int kFunctionIndex = 1; 60 | static const int kFunctionFieldCount = 2; 61 | 62 | static const int kGetterIndex = 1; 63 | static const int kSetterIndex = 2; 64 | static const int kAccessorFieldCount = 3; 65 | 66 | static const int kPropertyGetterIndex = 1; 67 | static const int kPropertySetterIndex = 2; 68 | static const int kPropertyEnumeratorIndex = 3; 69 | static const int kPropertyDeleterIndex = 4; 70 | static const int kPropertyQueryIndex = 5; 71 | static const int kPropertyFieldCount = 6; 72 | 73 | static const int kIndexPropertyGetterIndex = 1; 74 | static const int kIndexPropertySetterIndex = 2; 75 | static const int kIndexPropertyEnumeratorIndex = 3; 76 | static const int kIndexPropertyDeleterIndex = 4; 77 | static const int kIndexPropertyQueryIndex = 5; 78 | static const int kIndexPropertyFieldCount = 6; 79 | 80 | } // end of namespace imp 81 | 82 | #if NODE_MODULE_VERSION > NODE_0_10_MODULE_VERSION 83 | # include "nan_callbacks_12_inl.h" // NOLINT(build/include) 84 | #else 85 | # include "nan_callbacks_pre_12_inl.h" // NOLINT(build/include) 86 | #endif 87 | 88 | #endif // NAN_CALLBACKS_H_ 89 | -------------------------------------------------------------------------------- /app/node_modules/nan/nan_converters.h: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * NAN - Native Abstractions for Node.js 3 | * 4 | * Copyright (c) 2018 NAN contributors 5 | * 6 | * MIT License 7 | ********************************************************************/ 8 | 9 | #ifndef NAN_CONVERTERS_H_ 10 | #define NAN_CONVERTERS_H_ 11 | 12 | namespace imp { 13 | template struct ToFactoryBase { 14 | typedef MaybeLocal return_t; 15 | }; 16 | template struct ValueFactoryBase { typedef Maybe return_t; }; 17 | 18 | template struct ToFactory; 19 | 20 | template<> 21 | struct ToFactory : ToFactoryBase { 22 | static inline return_t convert(v8::Local val) { 23 | if (val.IsEmpty() || !val->IsFunction()) return MaybeLocal(); 24 | return MaybeLocal(val.As()); 25 | } 26 | }; 27 | 28 | #define X(TYPE) \ 29 | template<> \ 30 | struct ToFactory : ToFactoryBase { \ 31 | static inline return_t convert(v8::Local val); \ 32 | }; 33 | 34 | X(Boolean) 35 | X(Number) 36 | X(String) 37 | X(Object) 38 | X(Integer) 39 | X(Uint32) 40 | X(Int32) 41 | 42 | #undef X 43 | 44 | #define X(TYPE) \ 45 | template<> \ 46 | struct ToFactory : ValueFactoryBase { \ 47 | static inline return_t convert(v8::Local val); \ 48 | }; 49 | 50 | X(bool) 51 | X(double) 52 | X(int64_t) 53 | X(uint32_t) 54 | X(int32_t) 55 | 56 | #undef X 57 | } // end of namespace imp 58 | 59 | template 60 | inline 61 | typename imp::ToFactory::return_t To(v8::Local val) { 62 | return imp::ToFactory::convert(val); 63 | } 64 | 65 | #if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 4 || \ 66 | (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 3)) 67 | # include "nan_converters_43_inl.h" 68 | #else 69 | # include "nan_converters_pre_43_inl.h" 70 | #endif 71 | 72 | #endif // NAN_CONVERTERS_H_ 73 | -------------------------------------------------------------------------------- /app/node_modules/nan/nan_converters_43_inl.h: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * NAN - Native Abstractions for Node.js 3 | * 4 | * Copyright (c) 2018 NAN contributors 5 | * 6 | * MIT License 7 | ********************************************************************/ 8 | 9 | #ifndef NAN_CONVERTERS_43_INL_H_ 10 | #define NAN_CONVERTERS_43_INL_H_ 11 | 12 | #define X(TYPE) \ 13 | imp::ToFactory::return_t \ 14 | imp::ToFactory::convert(v8::Local val) { \ 15 | v8::Isolate *isolate = v8::Isolate::GetCurrent(); \ 16 | v8::EscapableHandleScope scope(isolate); \ 17 | return scope.Escape( \ 18 | val->To ## TYPE(isolate->GetCurrentContext()) \ 19 | .FromMaybe(v8::Local())); \ 20 | } 21 | 22 | X(Boolean) 23 | X(Number) 24 | X(String) 25 | X(Object) 26 | X(Integer) 27 | X(Uint32) 28 | X(Int32) 29 | 30 | #undef X 31 | 32 | #define X(TYPE, NAME) \ 33 | imp::ToFactory::return_t \ 34 | imp::ToFactory::convert(v8::Local val) { \ 35 | v8::Isolate *isolate = v8::Isolate::GetCurrent(); \ 36 | v8::HandleScope scope(isolate); \ 37 | return val->NAME ## Value(isolate->GetCurrentContext()); \ 38 | } 39 | 40 | X(bool, Boolean) 41 | X(double, Number) 42 | X(int64_t, Integer) 43 | X(uint32_t, Uint32) 44 | X(int32_t, Int32) 45 | 46 | #undef X 47 | 48 | #endif // NAN_CONVERTERS_43_INL_H_ 49 | -------------------------------------------------------------------------------- /app/node_modules/nan/nan_converters_pre_43_inl.h: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * NAN - Native Abstractions for Node.js 3 | * 4 | * Copyright (c) 2018 NAN contributors 5 | * 6 | * MIT License 7 | ********************************************************************/ 8 | 9 | #ifndef NAN_CONVERTERS_PRE_43_INL_H_ 10 | #define NAN_CONVERTERS_PRE_43_INL_H_ 11 | 12 | #define X(TYPE) \ 13 | imp::ToFactory::return_t \ 14 | imp::ToFactory::convert(v8::Local val) { \ 15 | return val->To ## TYPE(); \ 16 | } 17 | 18 | X(Boolean) 19 | X(Number) 20 | X(String) 21 | X(Object) 22 | X(Integer) 23 | X(Uint32) 24 | X(Int32) 25 | 26 | #undef X 27 | 28 | #define X(TYPE, NAME) \ 29 | imp::ToFactory::return_t \ 30 | imp::ToFactory::convert(v8::Local val) { \ 31 | return Just(val->NAME ## Value()); \ 32 | } 33 | 34 | X(bool, Boolean) 35 | X(double, Number) 36 | X(int64_t, Integer) 37 | X(uint32_t, Uint32) 38 | X(int32_t, Int32) 39 | 40 | #undef X 41 | 42 | #endif // NAN_CONVERTERS_PRE_43_INL_H_ 43 | -------------------------------------------------------------------------------- /app/node_modules/nan/nan_define_own_property_helper.h: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * NAN - Native Abstractions for Node.js 3 | * 4 | * Copyright (c) 2018 NAN contributors 5 | * 6 | * MIT License 7 | ********************************************************************/ 8 | 9 | #ifndef NAN_DEFINE_OWN_PROPERTY_HELPER_H_ 10 | #define NAN_DEFINE_OWN_PROPERTY_HELPER_H_ 11 | 12 | namespace imp { 13 | 14 | inline Maybe DefineOwnPropertyHelper( 15 | v8::PropertyAttribute current 16 | , v8::Handle obj 17 | , v8::Handle key 18 | , v8::Handle value 19 | , v8::PropertyAttribute attribs = v8::None) { 20 | return !(current & v8::DontDelete) || // configurable OR 21 | (!(current & v8::ReadOnly) && // writable AND 22 | !((attribs ^ current) & ~v8::ReadOnly)) // same excluding RO 23 | ? Just(obj->ForceSet(key, value, attribs)) 24 | : Nothing(); 25 | } 26 | 27 | } // end of namespace imp 28 | 29 | #endif // NAN_DEFINE_OWN_PROPERTY_HELPER_H_ 30 | -------------------------------------------------------------------------------- /app/node_modules/nan/nan_object_wrap.h: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * NAN - Native Abstractions for Node.js 3 | * 4 | * Copyright (c) 2018 NAN contributors 5 | * 6 | * MIT License 7 | ********************************************************************/ 8 | 9 | #ifndef NAN_OBJECT_WRAP_H_ 10 | #define NAN_OBJECT_WRAP_H_ 11 | 12 | class ObjectWrap { 13 | public: 14 | ObjectWrap() { 15 | refs_ = 0; 16 | } 17 | 18 | 19 | virtual ~ObjectWrap() { 20 | if (persistent().IsEmpty()) { 21 | return; 22 | } 23 | 24 | assert(persistent().IsNearDeath()); 25 | persistent().ClearWeak(); 26 | persistent().Reset(); 27 | } 28 | 29 | 30 | template 31 | static inline T* Unwrap(v8::Local object) { 32 | assert(!object.IsEmpty()); 33 | assert(object->InternalFieldCount() > 0); 34 | // Cast to ObjectWrap before casting to T. A direct cast from void 35 | // to T won't work right when T has more than one base class. 36 | void* ptr = GetInternalFieldPointer(object, 0); 37 | ObjectWrap* wrap = static_cast(ptr); 38 | return static_cast(wrap); 39 | } 40 | 41 | 42 | inline v8::Local handle() const { 43 | return New(handle_); 44 | } 45 | 46 | 47 | inline Persistent& persistent() { 48 | return handle_; 49 | } 50 | 51 | 52 | protected: 53 | inline void Wrap(v8::Local object) { 54 | assert(persistent().IsEmpty()); 55 | assert(object->InternalFieldCount() > 0); 56 | SetInternalFieldPointer(object, 0, this); 57 | persistent().Reset(object); 58 | MakeWeak(); 59 | } 60 | 61 | #if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 4 || \ 62 | (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 3)) 63 | 64 | inline void MakeWeak() { 65 | persistent().v8::PersistentBase::SetWeak( 66 | this, WeakCallback, v8::WeakCallbackType::kParameter); 67 | persistent().MarkIndependent(); 68 | } 69 | 70 | #elif NODE_MODULE_VERSION > NODE_0_10_MODULE_VERSION 71 | 72 | inline void MakeWeak() { 73 | persistent().v8::PersistentBase::SetWeak(this, WeakCallback); 74 | persistent().MarkIndependent(); 75 | } 76 | 77 | #else 78 | 79 | inline void MakeWeak() { 80 | persistent().persistent.MakeWeak(this, WeakCallback); 81 | persistent().MarkIndependent(); 82 | } 83 | 84 | #endif 85 | 86 | /* Ref() marks the object as being attached to an event loop. 87 | * Refed objects will not be garbage collected, even if 88 | * all references are lost. 89 | */ 90 | virtual void Ref() { 91 | assert(!persistent().IsEmpty()); 92 | persistent().ClearWeak(); 93 | refs_++; 94 | } 95 | 96 | /* Unref() marks an object as detached from the event loop. This is its 97 | * default state. When an object with a "weak" reference changes from 98 | * attached to detached state it will be freed. Be careful not to access 99 | * the object after making this call as it might be gone! 100 | * (A "weak reference" means an object that only has a 101 | * persistant handle.) 102 | * 103 | * DO NOT CALL THIS FROM DESTRUCTOR 104 | */ 105 | virtual void Unref() { 106 | assert(!persistent().IsEmpty()); 107 | assert(!persistent().IsWeak()); 108 | assert(refs_ > 0); 109 | if (--refs_ == 0) 110 | MakeWeak(); 111 | } 112 | 113 | int refs_; // ro 114 | 115 | private: 116 | NAN_DISALLOW_ASSIGN_COPY_MOVE(ObjectWrap) 117 | #if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 4 || \ 118 | (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 3)) 119 | 120 | static void 121 | WeakCallback(v8::WeakCallbackInfo const& info) { 122 | ObjectWrap* wrap = info.GetParameter(); 123 | assert(wrap->refs_ == 0); 124 | assert(wrap->handle_.IsNearDeath()); 125 | wrap->handle_.Reset(); 126 | delete wrap; 127 | } 128 | 129 | #elif NODE_MODULE_VERSION > NODE_0_10_MODULE_VERSION 130 | 131 | static void 132 | WeakCallback(v8::WeakCallbackData const& data) { 133 | ObjectWrap* wrap = data.GetParameter(); 134 | assert(wrap->refs_ == 0); 135 | assert(wrap->handle_.IsNearDeath()); 136 | wrap->handle_.Reset(); 137 | delete wrap; 138 | } 139 | 140 | #else 141 | 142 | static void WeakCallback(v8::Persistent value, void *data) { 143 | ObjectWrap *wrap = static_cast(data); 144 | assert(wrap->refs_ == 0); 145 | assert(wrap->handle_.IsNearDeath()); 146 | wrap->handle_.Reset(); 147 | delete wrap; 148 | } 149 | 150 | #endif 151 | Persistent handle_; 152 | }; 153 | 154 | 155 | #endif // NAN_OBJECT_WRAP_H_ 156 | -------------------------------------------------------------------------------- /app/node_modules/nan/nan_persistent_12_inl.h: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * NAN - Native Abstractions for Node.js 3 | * 4 | * Copyright (c) 2018 NAN contributors 5 | * 6 | * MIT License 7 | ********************************************************************/ 8 | 9 | #ifndef NAN_PERSISTENT_12_INL_H_ 10 | #define NAN_PERSISTENT_12_INL_H_ 11 | 12 | template class Persistent : 13 | public v8::Persistent { 14 | public: 15 | inline Persistent() : v8::Persistent() {} 16 | 17 | template inline Persistent(v8::Local that) : 18 | v8::Persistent(v8::Isolate::GetCurrent(), that) {} 19 | 20 | template 21 | inline 22 | Persistent(const v8::Persistent &that) : // NOLINT(runtime/explicit) 23 | v8::Persistent(v8::Isolate::GetCurrent(), that) {} 24 | 25 | inline void Reset() { v8::PersistentBase::Reset(); } 26 | 27 | template 28 | inline void Reset(const v8::Local &other) { 29 | v8::PersistentBase::Reset(v8::Isolate::GetCurrent(), other); 30 | } 31 | 32 | template 33 | inline void Reset(const v8::PersistentBase &other) { 34 | v8::PersistentBase::Reset(v8::Isolate::GetCurrent(), other); 35 | } 36 | 37 | template 38 | inline void SetWeak( 39 | P *parameter 40 | , typename WeakCallbackInfo

::Callback callback 41 | , WeakCallbackType type); 42 | 43 | private: 44 | inline T *operator*() const { return *PersistentBase::persistent; } 45 | 46 | template 47 | inline void Copy(const Persistent &that) { 48 | TYPE_CHECK(T, S); 49 | 50 | this->Reset(); 51 | 52 | if (!that.IsEmpty()) { 53 | this->Reset(that); 54 | M::Copy(that, this); 55 | } 56 | } 57 | }; 58 | 59 | #if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 4 || \ 60 | (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 3)) 61 | template 62 | class Global : public v8::Global { 63 | public: 64 | inline Global() : v8::Global() {} 65 | 66 | template inline Global(v8::Local that) : 67 | v8::Global(v8::Isolate::GetCurrent(), that) {} 68 | 69 | template 70 | inline 71 | Global(const v8::PersistentBase &that) : // NOLINT(runtime/explicit) 72 | v8::Global(v8::Isolate::GetCurrent(), that) {} 73 | 74 | inline void Reset() { v8::PersistentBase::Reset(); } 75 | 76 | template 77 | inline void Reset(const v8::Local &other) { 78 | v8::PersistentBase::Reset(v8::Isolate::GetCurrent(), other); 79 | } 80 | 81 | template 82 | inline void Reset(const v8::PersistentBase &other) { 83 | v8::PersistentBase::Reset(v8::Isolate::GetCurrent(), other); 84 | } 85 | 86 | template 87 | inline void SetWeak( 88 | P *parameter 89 | , typename WeakCallbackInfo

::Callback callback 90 | , WeakCallbackType type) { 91 | reinterpret_cast*>(this)->SetWeak( 92 | parameter, callback, type); 93 | } 94 | }; 95 | #else 96 | template 97 | class Global : public v8::UniquePersistent { 98 | public: 99 | inline Global() : v8::UniquePersistent() {} 100 | 101 | template inline Global(v8::Local that) : 102 | v8::UniquePersistent(v8::Isolate::GetCurrent(), that) {} 103 | 104 | template 105 | inline 106 | Global(const v8::PersistentBase &that) : // NOLINT(runtime/explicit) 107 | v8::UniquePersistent(v8::Isolate::GetCurrent(), that) {} 108 | 109 | inline void Reset() { v8::PersistentBase::Reset(); } 110 | 111 | template 112 | inline void Reset(const v8::Local &other) { 113 | v8::PersistentBase::Reset(v8::Isolate::GetCurrent(), other); 114 | } 115 | 116 | template 117 | inline void Reset(const v8::PersistentBase &other) { 118 | v8::PersistentBase::Reset(v8::Isolate::GetCurrent(), other); 119 | } 120 | 121 | template 122 | inline void SetWeak( 123 | P *parameter 124 | , typename WeakCallbackInfo

::Callback callback 125 | , WeakCallbackType type) { 126 | reinterpret_cast*>(this)->SetWeak( 127 | parameter, callback, type); 128 | } 129 | }; 130 | #endif 131 | 132 | #endif // NAN_PERSISTENT_12_INL_H_ 133 | -------------------------------------------------------------------------------- /app/node_modules/nan/nan_private.h: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * NAN - Native Abstractions for Node.js 3 | * 4 | * Copyright (c) 2018 NAN contributors 5 | * 6 | * MIT License 7 | ********************************************************************/ 8 | 9 | #ifndef NAN_PRIVATE_H_ 10 | #define NAN_PRIVATE_H_ 11 | 12 | inline Maybe 13 | HasPrivate(v8::Local object, v8::Local key) { 14 | HandleScope scope; 15 | #if NODE_MODULE_VERSION >= NODE_6_0_MODULE_VERSION 16 | v8::Isolate *isolate = v8::Isolate::GetCurrent(); 17 | v8::Local context = isolate->GetCurrentContext(); 18 | v8::Local private_key = v8::Private::ForApi(isolate, key); 19 | return object->HasPrivate(context, private_key); 20 | #else 21 | return Just(!object->GetHiddenValue(key).IsEmpty()); 22 | #endif 23 | } 24 | 25 | inline MaybeLocal 26 | GetPrivate(v8::Local object, v8::Local key) { 27 | #if NODE_MODULE_VERSION >= NODE_6_0_MODULE_VERSION 28 | v8::Isolate *isolate = v8::Isolate::GetCurrent(); 29 | v8::EscapableHandleScope scope(isolate); 30 | v8::Local context = isolate->GetCurrentContext(); 31 | v8::Local private_key = v8::Private::ForApi(isolate, key); 32 | v8::MaybeLocal v = object->GetPrivate(context, private_key); 33 | return scope.Escape(v.ToLocalChecked()); 34 | #else 35 | EscapableHandleScope scope; 36 | v8::Local v = object->GetHiddenValue(key); 37 | if (v.IsEmpty()) { 38 | v = Undefined(); 39 | } 40 | return scope.Escape(v); 41 | #endif 42 | } 43 | 44 | inline Maybe SetPrivate( 45 | v8::Local object, 46 | v8::Local key, 47 | v8::Local value) { 48 | #if NODE_MODULE_VERSION >= NODE_6_0_MODULE_VERSION 49 | HandleScope scope; 50 | v8::Isolate *isolate = v8::Isolate::GetCurrent(); 51 | v8::Local context = isolate->GetCurrentContext(); 52 | v8::Local private_key = v8::Private::ForApi(isolate, key); 53 | return object->SetPrivate(context, private_key, value); 54 | #else 55 | return Just(object->SetHiddenValue(key, value)); 56 | #endif 57 | } 58 | 59 | inline Maybe DeletePrivate( 60 | v8::Local object, 61 | v8::Local key) { 62 | #if NODE_MODULE_VERSION >= NODE_6_0_MODULE_VERSION 63 | HandleScope scope; 64 | v8::Isolate *isolate = v8::Isolate::GetCurrent(); 65 | v8::Local private_key = v8::Private::ForApi(isolate, key); 66 | return object->DeletePrivate(isolate->GetCurrentContext(), private_key); 67 | #else 68 | return Just(object->DeleteHiddenValue(key)); 69 | #endif 70 | } 71 | 72 | #endif // NAN_PRIVATE_H_ 73 | 74 | -------------------------------------------------------------------------------- /app/node_modules/nan/nan_typedarray_contents.h: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * NAN - Native Abstractions for Node.js 3 | * 4 | * Copyright (c) 2018 NAN contributors 5 | * 6 | * MIT License 7 | ********************************************************************/ 8 | 9 | #ifndef NAN_TYPEDARRAY_CONTENTS_H_ 10 | #define NAN_TYPEDARRAY_CONTENTS_H_ 11 | 12 | template 13 | class TypedArrayContents { 14 | public: 15 | inline explicit TypedArrayContents(v8::Local from) : 16 | length_(0), data_(NULL) { 17 | HandleScope scope; 18 | 19 | size_t length = 0; 20 | void* data = NULL; 21 | 22 | #if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 4 || \ 23 | (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 3)) 24 | 25 | if (from->IsArrayBufferView()) { 26 | v8::Local array = 27 | v8::Local::Cast(from); 28 | 29 | const size_t byte_length = array->ByteLength(); 30 | const ptrdiff_t byte_offset = array->ByteOffset(); 31 | v8::Local buffer = array->Buffer(); 32 | 33 | length = byte_length / sizeof(T); 34 | data = static_cast(buffer->GetContents().Data()) + byte_offset; 35 | } 36 | 37 | #else 38 | 39 | if (from->IsObject() && !from->IsNull()) { 40 | v8::Local array = v8::Local::Cast(from); 41 | 42 | MaybeLocal buffer = Get(array, 43 | New("buffer").ToLocalChecked()); 44 | MaybeLocal byte_length = Get(array, 45 | New("byteLength").ToLocalChecked()); 46 | MaybeLocal byte_offset = Get(array, 47 | New("byteOffset").ToLocalChecked()); 48 | 49 | if (!buffer.IsEmpty() && 50 | !byte_length.IsEmpty() && byte_length.ToLocalChecked()->IsUint32() && 51 | !byte_offset.IsEmpty() && byte_offset.ToLocalChecked()->IsUint32()) { 52 | data = array->GetIndexedPropertiesExternalArrayData(); 53 | if(data) { 54 | length = byte_length.ToLocalChecked()->Uint32Value() / sizeof(T); 55 | } 56 | } 57 | } 58 | 59 | #endif 60 | 61 | #if defined(_MSC_VER) && _MSC_VER >= 1900 || __cplusplus >= 201103L 62 | assert(reinterpret_cast(data) % alignof (T) == 0); 63 | #elif defined(_MSC_VER) && _MSC_VER >= 1600 || defined(__GNUC__) 64 | assert(reinterpret_cast(data) % __alignof(T) == 0); 65 | #else 66 | assert(reinterpret_cast(data) % sizeof (T) == 0); 67 | #endif 68 | 69 | length_ = length; 70 | data_ = static_cast(data); 71 | } 72 | 73 | inline size_t length() const { return length_; } 74 | inline T* operator*() { return data_; } 75 | inline const T* operator*() const { return data_; } 76 | 77 | private: 78 | NAN_DISALLOW_ASSIGN_COPY_MOVE(TypedArrayContents) 79 | 80 | //Disable heap allocation 81 | void *operator new(size_t size); 82 | void operator delete(void *, size_t) { 83 | abort(); 84 | } 85 | 86 | size_t length_; 87 | T* data_; 88 | }; 89 | 90 | #endif // NAN_TYPEDARRAY_CONTENTS_H_ 91 | -------------------------------------------------------------------------------- /app/node_modules/nan/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "_from": "nan@^2.11.1", 3 | "_id": "nan@2.11.1", 4 | "_inBundle": false, 5 | "_integrity": "sha512-iji6k87OSXa0CcrLl9z+ZiYSuR2o+c0bGuNmXdrhTQTakxytAFsC56SArGYoiHlJlFoHSnvmhpceZJaXkVuOtA==", 6 | "_location": "/nan", 7 | "_phantomChildren": {}, 8 | "_requested": { 9 | "type": "range", 10 | "registry": true, 11 | "raw": "nan@^2.11.1", 12 | "name": "nan", 13 | "escapedName": "nan", 14 | "rawSpec": "^2.11.1", 15 | "saveSpec": null, 16 | "fetchSpec": "^2.11.1" 17 | }, 18 | "_requiredBy": [ 19 | "/" 20 | ], 21 | "_resolved": "https://registry.npmjs.org/nan/-/nan-2.11.1.tgz", 22 | "_shasum": "90e22bccb8ca57ea4cd37cc83d3819b52eea6766", 23 | "_spec": "nan@^2.11.1", 24 | "_where": "C:\\Users\\kochy\\Downloads\\RakSAMP-master\\node\\app", 25 | "bugs": { 26 | "url": "https://github.com/nodejs/nan/issues" 27 | }, 28 | "bundleDependencies": false, 29 | "contributors": [ 30 | { 31 | "name": "Rod Vagg", 32 | "email": "r@va.gg", 33 | "url": "https://github.com/rvagg" 34 | }, 35 | { 36 | "name": "Benjamin Byholm", 37 | "email": "bbyholm@abo.fi", 38 | "url": "https://github.com/kkoopa/" 39 | }, 40 | { 41 | "name": "Trevor Norris", 42 | "email": "trev.norris@gmail.com", 43 | "url": "https://github.com/trevnorris" 44 | }, 45 | { 46 | "name": "Nathan Rajlich", 47 | "email": "nathan@tootallnate.net", 48 | "url": "https://github.com/TooTallNate" 49 | }, 50 | { 51 | "name": "Brett Lawson", 52 | "email": "brett19@gmail.com", 53 | "url": "https://github.com/brett19" 54 | }, 55 | { 56 | "name": "Ben Noordhuis", 57 | "email": "info@bnoordhuis.nl", 58 | "url": "https://github.com/bnoordhuis" 59 | }, 60 | { 61 | "name": "David Siegel", 62 | "email": "david@artcom.de", 63 | "url": "https://github.com/agnat" 64 | }, 65 | { 66 | "name": "Michael Ira Krufky", 67 | "email": "mkrufky@gmail.com", 68 | "url": "https://github.com/mkrufky" 69 | } 70 | ], 71 | "deprecated": false, 72 | "description": "Native Abstractions for Node.js: C++ header for Node 0.8 -> 10 compatibility", 73 | "devDependencies": { 74 | "bindings": "~1.2.1", 75 | "commander": "^2.8.1", 76 | "glob": "^5.0.14", 77 | "node-gyp": "~3.6.2", 78 | "readable-stream": "^2.1.4", 79 | "request": "=2.81.0", 80 | "tap": "~0.7.1", 81 | "xtend": "~4.0.0" 82 | }, 83 | "homepage": "https://github.com/nodejs/nan#readme", 84 | "license": "MIT", 85 | "main": "include_dirs.js", 86 | "name": "nan", 87 | "repository": { 88 | "type": "git", 89 | "url": "git://github.com/nodejs/nan.git" 90 | }, 91 | "scripts": { 92 | "docs": "doc/.build.sh", 93 | "rebuild-tests": "node-gyp rebuild --msvs_version=2015 --directory test", 94 | "test": "tap --gc --stderr test/js/*-test.js", 95 | "test:worker": "node --experimental-worker test/tap-as-worker.js --gc --stderr test/js/*-test.js" 96 | }, 97 | "version": "2.11.1" 98 | } 99 | -------------------------------------------------------------------------------- /app/node_modules/nan/tools/README.md: -------------------------------------------------------------------------------- 1 | 1to2 naively converts source code files from NAN 1 to NAN 2. There will be erroneous conversions, 2 | false positives and missed opportunities. The input files are rewritten in place. Make sure that 3 | you have backups. You will have to manually review the changes afterwards and do some touchups. 4 | 5 | ```sh 6 | $ tools/1to2.js 7 | 8 | Usage: 1to2 [options] 9 | 10 | Options: 11 | 12 | -h, --help output usage information 13 | -V, --version output the version number 14 | ``` 15 | -------------------------------------------------------------------------------- /app/node_modules/nan/tools/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "1to2", 3 | "version": "1.0.0", 4 | "description": "NAN 1 -> 2 Migration Script", 5 | "main": "1to2.js", 6 | "repository": { 7 | "type": "git", 8 | "url": "git://github.com/nodejs/nan.git" 9 | }, 10 | "contributors": [ 11 | "Benjamin Byholm (https://github.com/kkoopa/)", 12 | "Mathias Küsel (https://github.com/mathiask88/)" 13 | ], 14 | "dependencies": { 15 | "glob": "~5.0.10", 16 | "commander": "~2.8.1" 17 | }, 18 | "license": "MIT" 19 | } 20 | -------------------------------------------------------------------------------- /app/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "samp-listener", 3 | "version": "1.0.0", 4 | "main": "index.js", 5 | "scripts": { 6 | "build": "node-gyp --python=\"C:\\Python27\" build", 7 | "configure": "node-gyp --python=\"C:\\Python27\" configure", 8 | "debug": "node-gyp --python=\"C:\\Python27\" build --debug" 9 | }, 10 | "dependencies": { 11 | "nan": "^2.11.1" 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/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 | */ -------------------------------------------------------------------------------- /src/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 | -------------------------------------------------------------------------------- /src/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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /src/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 | -------------------------------------------------------------------------------- /src/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 | -------------------------------------------------------------------------------- /src/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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /src/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 | -------------------------------------------------------------------------------- /src/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 | -------------------------------------------------------------------------------- /src/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 | -------------------------------------------------------------------------------- /src/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 | -------------------------------------------------------------------------------- /src/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 | -------------------------------------------------------------------------------- /src/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 | -------------------------------------------------------------------------------- /src/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 | -------------------------------------------------------------------------------- /src/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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /src/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 | -------------------------------------------------------------------------------- /src/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 | -------------------------------------------------------------------------------- /src/EncodeClassName.cpp: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /src/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 | -------------------------------------------------------------------------------- /src/ExtendedOverlappedPool.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 | // No longer used as I no longer support IO Completion ports 18 | /* 19 | #ifdef __USE_IO_COMPLETION_PORTS 20 | #include "ExtendedOverlappedPool.h" 21 | 22 | ExtendedOverlappedPool ExtendedOverlappedPool::I; 23 | 24 | ExtendedOverlappedPool::ExtendedOverlappedPool() 25 | {} 26 | 27 | ExtendedOverlappedPool::~ExtendedOverlappedPool() 28 | { 29 | // The caller better have returned all the packets! 30 | ExtendedOverlappedStruct * p; 31 | poolMutex.Lock(); 32 | 33 | while ( pool.Size() ) 34 | { 35 | p = pool.Pop(); 36 | delete p; 37 | } 38 | 39 | poolMutex.Unlock(); 40 | } 41 | 42 | ExtendedOverlappedStruct* ExtendedOverlappedPool::GetPointer( void ) 43 | { 44 | ExtendedOverlappedStruct * p = 0; 45 | poolMutex.Lock(); 46 | 47 | if ( pool.Size() ) 48 | p = pool.Pop(); 49 | 50 | poolMutex.Unlock(); 51 | 52 | if ( p ) 53 | return p; 54 | 55 | return new ExtendedOverlappedStruct; 56 | } 57 | 58 | void ExtendedOverlappedPool::ReleasePointer( ExtendedOverlappedStruct *p ) 59 | { 60 | poolMutex.Lock(); 61 | pool.Push( p ); 62 | poolMutex.Unlock(); 63 | } 64 | 65 | #endif 66 | 67 | */ 68 | -------------------------------------------------------------------------------- /src/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 | -------------------------------------------------------------------------------- /src/FileOperations.cpp: -------------------------------------------------------------------------------- 1 | #include "_findfirst.h" // For linux 2 | #include "FileOperations.h" 3 | #include 4 | #include 5 | #ifdef _WIN32 6 | // For mkdir 7 | #include 8 | #include 9 | #else 10 | #include 11 | #include 12 | #include "LinuxStrings.h" 13 | #include "_findfirst.h" 14 | #endif 15 | 16 | 17 | bool WriteFileWithDirectories( const char *path, char *data, unsigned dataLength ) 18 | { 19 | int index; 20 | FILE *fp; 21 | char *pathCopy; 22 | #ifndef _WIN32 23 | 24 | char *systemCommand; 25 | #endif 26 | 27 | if ( path == 0 || path[ 0 ] == 0 ) 28 | return false; 29 | 30 | #ifndef _WIN32 31 | 32 | systemCommand = new char [ strlen( path ) + 1 + 6 ]; 33 | 34 | #endif 35 | 36 | pathCopy = new char [ strlen( path ) + 1 ]; 37 | 38 | strcpy( pathCopy, path ); 39 | 40 | index = 0; 41 | 42 | while ( pathCopy[ index ] ) 43 | { 44 | if ( pathCopy[ index ] == '/' || pathCopy[ index ] == '\\') 45 | { 46 | pathCopy[ index ] = 0; 47 | #ifdef _WIN32 48 | _mkdir( pathCopy ); 49 | #else 50 | 51 | mkdir( pathCopy, 0744 ); 52 | #endif 53 | 54 | pathCopy[ index ] = '/'; 55 | } 56 | 57 | index++; 58 | } 59 | 60 | if (data && dataLength) 61 | { 62 | fp = fopen( path, "wb" ); 63 | 64 | if ( fp == 0 ) 65 | { 66 | delete [] pathCopy; 67 | #ifndef _WIN32 68 | delete [] systemCommand; 69 | #endif 70 | return false; 71 | } 72 | 73 | fwrite( data, 1, dataLength, fp ); 74 | 75 | fclose( fp ); 76 | } 77 | else 78 | { 79 | #ifdef _WIN32 80 | _mkdir( pathCopy ); 81 | #else 82 | mkdir( pathCopy, 0744 ); 83 | #endif 84 | } 85 | 86 | delete [] pathCopy; 87 | #ifndef _WIN32 88 | delete [] systemCommand; 89 | #endif 90 | 91 | 92 | return true; 93 | } 94 | bool IsSlash(unsigned char c) 95 | { 96 | return c=='/' || c=='\\'; 97 | } 98 | 99 | void AddSlash( char *input ) 100 | { 101 | if (input==0 || input[0]==0) 102 | return; 103 | 104 | int lastCharIndex=(int) strlen(input)-1; 105 | if (input[lastCharIndex]=='\\') 106 | input[lastCharIndex]='/'; 107 | else if (input[lastCharIndex]!='/') 108 | { 109 | input[lastCharIndex+1]='/'; 110 | input[lastCharIndex+2]=0; 111 | } 112 | } 113 | bool DirectoryExists(const char *directory) 114 | { 115 | _finddata_t fileInfo; 116 | intptr_t dir; 117 | char baseDirWithStars[560]; 118 | strcpy(baseDirWithStars, directory); 119 | AddSlash(baseDirWithStars); 120 | strcat(baseDirWithStars, "*.*"); 121 | dir=_findfirst(baseDirWithStars, &fileInfo ); 122 | if (dir==-1) 123 | return false; 124 | _findclose(dir); 125 | return true; 126 | } 127 | void QuoteIfSpaces(char *str) 128 | { 129 | unsigned i; 130 | bool hasSpace=false; 131 | for (i=0; str[i]; i++) 132 | { 133 | if (str[i]==' ') 134 | { 135 | hasSpace=true; 136 | break; 137 | } 138 | } 139 | if (hasSpace) 140 | { 141 | int len=(int)strlen(str); 142 | memmove(str+1, str, len); 143 | str[0]='\"'; 144 | str[len]='\"'; 145 | str[len+1]=0; 146 | } 147 | } 148 | -------------------------------------------------------------------------------- /src/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 | -------------------------------------------------------------------------------- /src/FullyConnectedMesh.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 "FullyConnectedMesh.h" 18 | #include "RakPeerInterface.h" 19 | #include "PacketEnumerations.h" 20 | #include "BitStream.h" 21 | #include 22 | #include 23 | 24 | #ifdef _MSC_VER 25 | #pragma warning( push ) 26 | #endif 27 | 28 | FullyConnectedMesh::FullyConnectedMesh() 29 | { 30 | pw=0; 31 | } 32 | 33 | FullyConnectedMesh::~FullyConnectedMesh() 34 | { 35 | if (pw) 36 | delete [] pw; 37 | } 38 | 39 | void FullyConnectedMesh::Initialize(const char *password) 40 | { 41 | if (pw) 42 | delete [] pw; 43 | if (password && password[0]) 44 | { 45 | pw = new char [strlen(password)+1]; 46 | strcpy(pw, password); 47 | } 48 | else 49 | pw=0; 50 | 51 | } 52 | 53 | #ifdef _MSC_VER 54 | #pragma warning( disable : 4100 ) // warning C4100: : unreferenced formal parameter 55 | #endif 56 | void FullyConnectedMesh::OnDisconnect(RakPeerInterface *peer) 57 | { 58 | } 59 | #ifdef _MSC_VER 60 | #pragma warning( disable : 4701 ) // warning C4701: local variable may be used without having been initialized 61 | #pragma warning( disable : 4100 ) // warning C4100: : unreferenced formal parameter 62 | #endif 63 | void FullyConnectedMesh::Update(RakPeerInterface *peer) 64 | { 65 | } 66 | 67 | PluginReceiveResult FullyConnectedMesh::OnReceive(RakPeerInterface *peer, Packet *packet) 68 | { 69 | assert(packet); 70 | assert(peer); 71 | 72 | switch (packet->data[0]) 73 | { 74 | case ID_REMOTE_NEW_INCOMING_CONNECTION: // This comes from the connection graph plugin 75 | { 76 | RakNet::BitStream b(packet->data, packet->length, false); 77 | b.IgnoreBits(8); 78 | ConnectionGraphGroupID group1, group2; 79 | PlayerID node1, node2; 80 | b.Read(node1); 81 | b.Read(group1); 82 | if (peer->GetIndexFromPlayerID(node1)==-1) 83 | peer->Connect(peer->PlayerIDToDottedIP(node1), node1.port, pw, pw ? (int)strlen(pw) : 0); 84 | b.Read(node2); 85 | b.Read(group2); 86 | if (peer->GetIndexFromPlayerID(node2)==-1) 87 | peer->Connect(peer->PlayerIDToDottedIP(node2), node2.port, pw, pw ? (int)strlen(pw) : 0); 88 | break; 89 | } 90 | } 91 | 92 | return RR_CONTINUE_PROCESSING; 93 | } 94 | 95 | #ifdef _MSC_VER 96 | #pragma warning( pop ) 97 | #endif 98 | -------------------------------------------------------------------------------- /src/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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /src/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 | -------------------------------------------------------------------------------- /src/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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /src/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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /src/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 | -------------------------------------------------------------------------------- /src/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 | -------------------------------------------------------------------------------- /src/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 | #include "SAMP/SAMP_VER.h" 22 | 23 | /// You should not edit the file PacketEnumerations.h as it is a part of RakNet static library 24 | /// To define your own message id, define an enum following the code example that follows. 25 | /// 26 | /// \code 27 | /// enum { 28 | /// ID_MYPROJECT_MSG_1 = ID_USER_PACKET_ENUM 29 | /// ID_MYPROJECT_MSG_2, 30 | /// ... 31 | /// }; 32 | /// \endcode 33 | /// 34 | /// \note All these enumerations should be casted to (unsigned char) before writing them to RakNet::BitStream 35 | 36 | enum PacketEnumeration 37 | { 38 | ID_INTERNAL_PING = 6, 39 | ID_PING, 40 | ID_PING_OPEN_CONNECTIONS, 41 | ID_CONNECTED_PONG, 42 | ID_REQUEST_STATIC_DATA, 43 | ID_CONNECTION_REQUEST, 44 | ID_AUTH_KEY, 45 | ID_BROADCAST_PINGS = 14, 46 | ID_SECURED_CONNECTION_RESPONSE, 47 | ID_SECURED_CONNECTION_CONFIRMATION, 48 | ID_RPC_MAPPING, 49 | ID_SET_RANDOM_NUMBER_SEED = 19, 50 | ID_RPC, 51 | ID_RPC_REPLY, 52 | ID_DETECT_LOST_CONNECTIONS = 23, 53 | ID_OPEN_CONNECTION_REQUEST, 54 | ID_OPEN_CONNECTION_REPLY, 55 | ID_OPEN_CONNECTION_COOKIE, 56 | ID_RSA_PUBLIC_KEY_MISMATCH = 28, 57 | ID_CONNECTION_ATTEMPT_FAILED, 58 | ID_NEW_INCOMING_CONNECTION = 30, 59 | ID_NO_FREE_INCOMING_CONNECTIONS = 31, 60 | ID_DISCONNECTION_NOTIFICATION, 61 | ID_CONNECTION_LOST, 62 | ID_CONNECTION_REQUEST_ACCEPTED, 63 | ID_CONNECTION_BANNED = 36, 64 | ID_INVALID_PASSWORD, 65 | ID_MODIFIED_PACKET, 66 | ID_PONG, 67 | ID_TIMESTAMP, 68 | ID_RECEIVED_STATIC_DATA, 69 | ID_REMOTE_DISCONNECTION_NOTIFICATION, 70 | ID_REMOTE_CONNECTION_LOST, 71 | ID_REMOTE_NEW_INCOMING_CONNECTION, 72 | ID_REMOTE_EXISTING_CONNECTION, 73 | ID_REMOTE_STATIC_DATA, 74 | ID_ADVERTISE_SYSTEM = 55, 75 | 76 | ID_PLAYER_SYNC = 207, 77 | ID_MARKERS_SYNC = 208, 78 | ID_UNOCCUPIED_SYNC = 209, 79 | ID_TRAILER_SYNC = 210, 80 | ID_PASSENGER_SYNC = 211, 81 | ID_SPECTATOR_SYNC = 212, 82 | ID_AIM_SYNC = 203, 83 | ID_VEHICLE_SYNC = 200, 84 | ID_RCON_COMMAND = 201, 85 | ID_RCON_RESPONCE = 202, 86 | ID_WEAPONS_UPDATE = 204, 87 | ID_STATS_UPDATE = 205, 88 | ID_BULLET_SYNC = 206, 89 | }; 90 | 91 | #endif 92 | 93 | -------------------------------------------------------------------------------- /src/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 | */ -------------------------------------------------------------------------------- /src/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 | -------------------------------------------------------------------------------- /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 | void PluginInterface::OnInternalPacket(InternalPacket *internalPacket, unsigned frameNumber, PlayerID remoteSystemID, RakNetTime time, bool isSend) 82 | { 83 | } 84 | 85 | #ifdef _MSC_VER 86 | #pragma warning( pop ) 87 | #endif 88 | -------------------------------------------------------------------------------- /src/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 | -------------------------------------------------------------------------------- /src/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 | -------------------------------------------------------------------------------- /src/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 | -------------------------------------------------------------------------------- /src/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 | -------------------------------------------------------------------------------- /src/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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /src/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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /src/RakSleep.h: -------------------------------------------------------------------------------- 1 | #ifndef __RAK_SLEEP_H 2 | #define __RAK_SLEEP_H 3 | 4 | void RakSleep(unsigned int ms); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /src/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 | -------------------------------------------------------------------------------- /src/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 | -------------------------------------------------------------------------------- /src/RouterInterface.h: -------------------------------------------------------------------------------- 1 | #ifndef __ROUTER_INTERFACE_H 2 | #define __ROUTER_INTERFACE_H 3 | 4 | #include "Export.h" 5 | 6 | /// On failed directed sends, RakNet can call an alternative send function to use. 7 | class RAK_DLL_EXPORT RouterInterface 8 | { 9 | public: 10 | virtual bool Send( const char *data, unsigned bitLength, PacketPriority priority, PacketReliability reliability, char orderingChannel, PlayerID playerId )=0; 11 | }; 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /src/SAMP/SAMPRPC.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Updated to 0.3.7 by P3ti 3 | */ 4 | 5 | #include "../main/main.h" 6 | 7 | int RPC_ServerJoin = 137; 8 | int RPC_ServerQuit = 138; 9 | int RPC_InitGame = 139; 10 | int RPC_ClientJoin = 25; 11 | int RPC_NPCJoin = 54; 12 | int RPC_Death = 53; 13 | int RPC_RequestClass = 128; 14 | int RPC_RequestSpawn = 129; 15 | int RPC_SetInteriorId = 118; 16 | int RPC_Spawn = 52; 17 | int RPC_Chat = 101; 18 | int RPC_EnterVehicle = 26; 19 | int RPC_ExitVehicle = 154; 20 | int RPC_DamageVehicle = 106; 21 | int RPC_MenuSelect = 132; 22 | int RPC_MenuQuit = 140; 23 | int RPC_ScmEvent = 96; 24 | int RPC_AdminMapTeleport = 255; 25 | int RPC_WorldPlayerAdd = 32; 26 | int RPC_WorldPlayerDeath = 166; 27 | int RPC_WorldPlayerRemove = 163; 28 | int RPC_WorldVehicleAdd = 164; 29 | int RPC_WorldVehicleRemove = 165; 30 | int RPC_SetCheckpoint = 107; 31 | int RPC_DisableCheckpoint = 37; 32 | int RPC_SetRaceCheckpoint = 38; 33 | int RPC_DisableRaceCheckpoint = 39; 34 | int RPC_UpdateScoresPingsIPs = 155; 35 | int RPC_SvrStats = 102; 36 | int RPC_GameModeRestart = 40; 37 | int RPC_ConnectionRejected = 130; 38 | int RPC_ClientMessage = 93; 39 | int RPC_WorldTime = 94; 40 | int RPC_Pickup = 95; 41 | int RPC_DestroyPickup = 63; 42 | int RPC_DestroyWeaponPickup = 97; 43 | int RPC_Weather = 152; 44 | int RPC_SetTimeEx = 255; 45 | int RPC_ToggleClock = 30; 46 | int RPC_ServerCommand = 50; 47 | int RPC_PickedUpPickup = 131; 48 | int RPC_PickedUpWeapon = 255; 49 | int RPC_VehicleDestroyed = 136; 50 | int RPC_DialogResponse = 62; 51 | int RPC_PlayAudioStream = 41; 52 | int RPC_StopAudioStream = 42; 53 | int RPC_ClickPlayer = 23; 54 | int RPC_PlayerUpdate = 60; 55 | int RPC_ClickTextDraw = 83; 56 | int RPC_MapMarker = 119; 57 | int RPC_PlayerGiveTakeDamage = 115; 58 | int RPC_EnterEditObject = 27; 59 | int RPC_EditObject = 117; 60 | 61 | int RPC_ScrSetSpawnInfo = 68; 62 | int RPC_ScrSetPlayerTeam = 69; 63 | int RPC_ScrSetPlayerSkin = 153; 64 | int RPC_ScrSetPlayerName = 11; 65 | int RPC_ScrSetPlayerPos = 12; 66 | int RPC_ScrSetPlayerPosFindZ = 13; 67 | int RPC_ScrSetPlayerHealth = 14; 68 | int RPC_ScrPutPlayerInVehicle = 70; 69 | int RPC_ScrRemovePlayerFromVehicle = 71; 70 | int RPC_ScrSetPlayerColor = 72; 71 | int RPC_ScrDisplayGameText = 73; 72 | int RPC_ScrSetInterior = 156; 73 | int RPC_ScrSetCameraPos = 157; 74 | int RPC_ScrSetCameraLookAt = 158; 75 | int RPC_ScrSetVehiclePos = 159; 76 | int RPC_ScrSetVehicleZAngle = 160; 77 | int RPC_ScrVehicleParams = 161; 78 | int RPC_ScrSetCameraBehindPlayer = 162; 79 | int RPC_ScrTogglePlayerControllable = 15; 80 | int RPC_ScrPlaySound = 16; 81 | int RPC_ScrSetWorldBounds = 17; 82 | int RPC_ScrHaveSomeMoney = 18; 83 | int RPC_ScrSetPlayerFacingAngle = 19; 84 | int RPC_ScrResetMoney = 20; 85 | int RPC_ScrResetPlayerWeapons = 21; 86 | int RPC_ScrGivePlayerWeapon = 22; 87 | int RPC_ScrRespawnVehicle = 255; 88 | int RPC_ScrLinkVehicle = 65; 89 | int RPC_ScrSetPlayerArmour = 66; 90 | int RPC_ScrDeathMessage = 55; 91 | int RPC_ScrSetMapIcon = 56; 92 | int RPC_ScrDisableMapIcon = 144; 93 | int RPC_ScrSetWeaponAmmo = 145; 94 | int RPC_ScrSetGravity = 146; 95 | int RPC_ScrSetVehicleHealth = 147; 96 | int RPC_ScrAttachTrailerToVehicle = 148; 97 | int RPC_ScrDetachTrailerFromVehicle = 149; 98 | int RPC_ScrCreateObject = 44; 99 | int RPC_ScrSetObjectPos = 45; 100 | int RPC_ScrSetObjectRotation = 46; 101 | int RPC_ScrDestroyObject = 47; 102 | int RPC_ScrCreateExplosion = 79; 103 | int RPC_ScrShowNameTag = 80; 104 | int RPC_ScrMoveObject = 99; 105 | int RPC_ScrStopObject = 122; 106 | int RPC_ScrNumberPlate = 123; 107 | int RPC_ScrTogglePlayerSpectating = 124; 108 | int RPC_ScrSetPlayerSpectating = 255; 109 | int RPC_ScrPlayerSpectatePlayer = 126; 110 | int RPC_ScrPlayerSpectateVehicle = 127; 111 | int RPC_ScrRemoveComponent = 57; 112 | int RPC_ScrForceSpawnSelection = 74; 113 | int RPC_ScrAttachObjectToPlayer = 75; 114 | int RPC_ScrInitMenu = 76; 115 | int RPC_ScrShowMenu = 77; 116 | int RPC_ScrHideMenu = 78; 117 | int RPC_ScrSetPlayerWantedLevel = 133; 118 | int RPC_ScrShowTextDraw = 134; 119 | int RPC_ScrHideTextDraw = 135; 120 | int RPC_ScrEditTextDraw = 105; 121 | int RPC_ScrAddGangZone = 108; 122 | int RPC_ScrRemoveGangZone = 120; 123 | int RPC_ScrFlashGangZone = 121; 124 | int RPC_ScrStopFlashGangZone = 85; 125 | int RPC_ScrApplyAnimation = 86; 126 | int RPC_ScrClearAnimations = 87; 127 | int RPC_ScrSetSpecialAction = 88; 128 | int RPC_ScrEnableStuntBonus = 104; 129 | int RPC_ScrSetFightingStyle = 89; 130 | int RPC_ScrSetPlayerVelocity = 90; 131 | int RPC_ScrSetVehicleVelocity = 91; 132 | int RPC_ScrToggleWidescreen = 255; 133 | int RPC_ScrSetVehicleTireStatus = 255; 134 | int RPC_ScrSetPlayerDrunkLevel = 35; 135 | int RPC_ScrDialogBox = 61; 136 | int RPC_ScrCreate3DTextLabel = 36; -------------------------------------------------------------------------------- /src/SAMP/SAMPRPC.h: -------------------------------------------------------------------------------- 1 | /* 2 | Updated to 0.3.7 by P3ti 3 | */ 4 | 5 | #include "SAMP_VER.h" 6 | 7 | extern int RPC_ServerJoin; 8 | extern int RPC_ServerQuit; 9 | extern int RPC_InitGame; 10 | extern int RPC_ClientJoin; 11 | extern int RPC_NPCJoin; 12 | extern int RPC_Death; 13 | extern int RPC_RequestClass; 14 | extern int RPC_RequestSpawn; 15 | extern int RPC_SetInteriorId; 16 | extern int RPC_Spawn; 17 | extern int RPC_Chat; 18 | extern int RPC_EnterVehicle; 19 | extern int RPC_ExitVehicle; 20 | extern int RPC_DamageVehicle; 21 | extern int RPC_MenuSelect; 22 | extern int RPC_MenuQuit; 23 | extern int RPC_ScmEvent; 24 | extern int RPC_AdminMapTeleport; 25 | extern int RPC_WorldPlayerAdd; 26 | extern int RPC_WorldPlayerDeath; 27 | extern int RPC_WorldPlayerRemove; 28 | extern int RPC_WorldVehicleAdd; 29 | extern int RPC_WorldVehicleRemove; 30 | extern int RPC_SetCheckpoint; 31 | extern int RPC_DisableCheckpoint; 32 | extern int RPC_SetRaceCheckpoint; 33 | extern int RPC_DisableRaceCheckpoint; 34 | extern int RPC_UpdateScoresPingsIPs; 35 | extern int RPC_SvrStats; 36 | extern int RPC_GameModeRestart; 37 | extern int RPC_ConnectionRejected; 38 | extern int RPC_ClientMessage; 39 | extern int RPC_WorldTime; 40 | extern int RPC_Pickup; 41 | extern int RPC_DestroyPickup; 42 | extern int RPC_DestroyWeaponPickup; 43 | extern int RPC_Weather; 44 | extern int RPC_SetTimeEx; 45 | extern int RPC_ToggleClock; 46 | extern int RPC_ServerCommand; 47 | extern int RPC_PickedUpPickup; 48 | extern int RPC_PickedUpWeapon; 49 | extern int RPC_VehicleDestroyed; 50 | extern int RPC_DialogResponse; 51 | extern int RPC_PlayAudioStream; 52 | extern int RPC_StopAudioStream; 53 | extern int RPC_ClickPlayer; 54 | extern int RPC_ClickTextDraw; 55 | extern int RPC_MapMarker; 56 | 57 | extern int RPC_ScrSetSpawnInfo; 58 | extern int RPC_ScrSetPlayerTeam; 59 | extern int RPC_ScrSetPlayerSkin; 60 | extern int RPC_ScrSetPlayerName; 61 | extern int RPC_ScrSetPlayerPos; 62 | extern int RPC_ScrSetPlayerPosFindZ; 63 | extern int RPC_ScrSetPlayerHealth; 64 | extern int RPC_ScrPutPlayerInVehicle; 65 | extern int RPC_ScrRemovePlayerFromVehicle; 66 | extern int RPC_ScrSetPlayerColor; 67 | extern int RPC_ScrDisplayGameText; 68 | extern int RPC_ScrSetInterior; 69 | extern int RPC_ScrSetCameraPos; 70 | extern int RPC_ScrSetCameraLookAt; 71 | extern int RPC_ScrSetVehiclePos; 72 | extern int RPC_ScrSetVehicleZAngle; 73 | extern int RPC_ScrVehicleParams; 74 | extern int RPC_ScrSetCameraBehindPlayer; 75 | extern int RPC_ScrTogglePlayerControllable; 76 | extern int RPC_ScrPlaySound; 77 | extern int RPC_ScrSetWorldBounds; 78 | extern int RPC_ScrHaveSomeMoney; 79 | extern int RPC_ScrSetPlayerFacingAngle; 80 | extern int RPC_ScrResetMoney; 81 | extern int RPC_ScrResetPlayerWeapons; 82 | extern int RPC_ScrGivePlayerWeapon; 83 | extern int RPC_ScrRespawnVehicle; 84 | extern int RPC_ScrLinkVehicle; 85 | extern int RPC_ScrSetPlayerArmour; 86 | extern int RPC_ScrDeathMessage; 87 | extern int RPC_ScrSetMapIcon; 88 | extern int RPC_ScrDisableMapIcon; 89 | extern int RPC_ScrSetWeaponAmmo; 90 | extern int RPC_ScrSetGravity; 91 | extern int RPC_ScrSetVehicleHealth; 92 | extern int RPC_ScrAttachTrailerToVehicle; 93 | extern int RPC_ScrDetachTrailerFromVehicle; 94 | extern int RPC_ScrCreateObject; 95 | extern int RPC_ScrSetObjectPos; 96 | extern int RPC_ScrSetObjectRotation; 97 | extern int RPC_ScrDestroyObject; 98 | extern int RPC_ScrCreateExplosion; 99 | extern int RPC_ScrShowNameTag; 100 | extern int RPC_ScrMoveObject; 101 | extern int RPC_ScrStopObject; 102 | extern int RPC_ScrNumberPlate; 103 | extern int RPC_ScrTogglePlayerSpectating; 104 | extern int RPC_ScrSetPlayerSpectating; 105 | extern int RPC_ScrPlayerSpectatePlayer; 106 | extern int RPC_ScrPlayerSpectateVehicle; 107 | extern int RPC_ScrRemoveComponent; 108 | extern int RPC_ScrForceSpawnSelection; 109 | extern int RPC_ScrAttachObjectToPlayer; 110 | extern int RPC_ScrInitMenu; 111 | extern int RPC_ScrShowMenu; 112 | extern int RPC_ScrHideMenu; 113 | extern int RPC_ScrSetPlayerWantedLevel; 114 | extern int RPC_ScrShowTextDraw; 115 | extern int RPC_ScrHideTextDraw; 116 | extern int RPC_ScrEditTextDraw; 117 | extern int RPC_ScrAddGangZone; 118 | extern int RPC_ScrRemoveGangZone; 119 | extern int RPC_ScrFlashGangZone; 120 | extern int RPC_ScrStopFlashGangZone; 121 | extern int RPC_ScrApplyAnimation; 122 | extern int RPC_ScrClearAnimations; 123 | extern int RPC_ScrSetSpecialAction; 124 | extern int RPC_ScrEnableStuntBonus; 125 | extern int RPC_ScrSetFightingStyle; 126 | extern int RPC_ScrSetPlayerVelocity; 127 | extern int RPC_ScrSetVehicleVelocity; 128 | extern int RPC_ScrToggleWidescreen; 129 | extern int RPC_ScrSetVehicleTireStatus; 130 | extern int RPC_ScrSetPlayerDrunkLevel; 131 | extern int RPC_ScrDialogBox; 132 | extern int RPC_PlayerUpdate; 133 | extern int RPC_ScrCreate3DTextLabel; -------------------------------------------------------------------------------- /src/SAMP/SAMP_VER.h: -------------------------------------------------------------------------------- 1 | //this file only defines samp version 2 | #define SAMP_037 -------------------------------------------------------------------------------- /src/SAMP/samp_auth.h: -------------------------------------------------------------------------------- 1 | extern char AuthKeyTable[512][2][128]; 2 | -------------------------------------------------------------------------------- /src/SAMP/samp_netencr.h: -------------------------------------------------------------------------------- 1 | /* 2 | Updated to 0.3.7 by P3ti 3 | */ 4 | 5 | char *DumpMem(unsigned char *pAddr, int len); 6 | 7 | #ifdef RAKSAMP_CLIENT 8 | extern unsigned char encrBuffer[4092]; 9 | #else 10 | extern unsigned char decrBuffer[4092]; 11 | #endif 12 | 13 | #ifdef RAKSAMP_CLIENT 14 | void kyretardizeDatagram(unsigned char *buf, int len, int port, int unk); 15 | #else 16 | void unKyretardizeDatagram(unsigned char *buf, int len, int port, int unk); 17 | #endif 18 | -------------------------------------------------------------------------------- /src/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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /src/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 | -------------------------------------------------------------------------------- /src/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 | -------------------------------------------------------------------------------- /src/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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /src/SystemDatabaseClient.cpp: -------------------------------------------------------------------------------- 1 | #include "SystemDatabaseClient.h" 2 | 3 | // TODO 4 | -------------------------------------------------------------------------------- /src/SystemDatabaseClient.h: -------------------------------------------------------------------------------- 1 | #ifndef __SYSTEM_DATABASE_CLIENT_H 2 | #define __SYSTEM_DATABASE_CLIENT_H 3 | 4 | // TODO 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /src/SystemDatabaseServer.cpp: -------------------------------------------------------------------------------- 1 | #include "SystemDatabaseServer.h" 2 | 3 | // TODO 4 | -------------------------------------------------------------------------------- /src/SystemDatabaseServer.h: -------------------------------------------------------------------------------- 1 | #ifndef __SYSTEM_DATABASE_SERVER_H 2 | #define __SYSTEM_DATABASE_SERVER_H 3 | 4 | // TODO 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /src/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 | -------------------------------------------------------------------------------- /src/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 | -------------------------------------------------------------------------------- /src/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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /src/_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 | -------------------------------------------------------------------------------- /src/main/localplayer.h: -------------------------------------------------------------------------------- 1 | /* 2 | Updated to 0.3.7 by P3ti 3 | */ 4 | 5 | void SendOnFootFullSyncData(ONFOOT_SYNC_DATA *pofSync, int sendDeathNoti, PLAYERID followPlayerID); 6 | void SendInCarFullSyncData(INCAR_SYNC_DATA *picSync, int iUseCarPos, PLAYERID followPlayerID); 7 | void SendPassengerFullSyncData(VEHICLEID vehicleID); 8 | void SendAimSyncData(DWORD dwAmmoInClip, int iReloading, PLAYERID copyFromPlayer); 9 | void SendUnoccupiedSyncData(UNOCCUPIED_SYNC_DATA *punocSync); 10 | void SendSpectatorData(SPECTATOR_SYNC_DATA *pSpecData); 11 | void SendBulletData(BULLET_SYNC_DATA *pBulletData); 12 | 13 | void SendEnterVehicleNotification(VEHICLEID VehicleID, BOOL bPassenger); 14 | void SendExitVehicleNotification(VEHICLEID VehicleID); 15 | void SendWastedNotification(BYTE byteDeathReason, PLAYERID WhoWasResponsible); 16 | void NotifyVehicleDeath(VEHICLEID VehicleID); 17 | void SendDamageVehicle(WORD vehicleID, DWORD panel, DWORD door, BYTE lights, BYTE tires); -------------------------------------------------------------------------------- /src/main/log.cpp: -------------------------------------------------------------------------------- 1 | #include "log.h" 2 | #include "main.h" 3 | 4 | void Log(char *fmt, ...) 5 | { 6 | char buffer[512]; 7 | memset(buffer, 0, 512); 8 | 9 | va_list args; 10 | va_start(args, fmt); 11 | vsprintf_s(buffer, 512, fmt, args); 12 | va_end(args); 13 | printf(buffer); 14 | printf("\n"); 15 | } -------------------------------------------------------------------------------- /src/main/log.h: -------------------------------------------------------------------------------- 1 | extern void Log(char *fmt, ...); -------------------------------------------------------------------------------- /src/main/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "log.h" 3 | #include "main.h" 4 | 5 | RakClientInterface *pRakClient = NULL; 6 | bool IsConnectionRequired = true; 7 | 8 | int iAreWeConnected = 0, iConnectionRequested = 0, iSpawned = 0, iGameInited = 0, iSpawnsAvailable = 0; 9 | int iReconnectTime = 2 * 1000, iNotificationDisplayedBeforeSpawn = 0; 10 | PLAYERID g_myPlayerID; 11 | char g_szNickName[32]; 12 | struct stPlayerInfo playerInfo[MAX_PLAYERS]; 13 | struct stVehiclePool vehiclePool[MAX_VEHICLES]; 14 | 15 | bool chatListening = false; 16 | 17 | /** Callbacks **/ 18 | v8::Local listenChatFunc; 19 | 20 | 21 | char* ToCString(const v8::String::Utf8Value& value) { 22 | return *value ? *value : ""; 23 | } 24 | 25 | void ConnectAsync() { 26 | int connectionId = 0; 27 | srand((unsigned int)GetTickCount()); 28 | pRakClient = RakNetworkFactory::GetRakClientInterface(); 29 | if (pRakClient == NULL) 30 | return; 31 | 32 | pRakClient->SetMTUSize(576); 33 | RegisterRPCs(pRakClient); 34 | int iLastStatsUpdate = GetTickCount(); 35 | int iLastMoney = iMoney; 36 | int iLastDrunkLevel = iDrunkLevel; 37 | while(1) { 38 | UpdateNetwork(pRakClient); 39 | if (IsConnectionRequired) { 40 | Log("Connecting to %s", settings.server.szAddr); 41 | 42 | // pRakClient->SetPassword(password); 43 | connectionId = (int) pRakClient->Connect(settings.server.szAddr, settings.server.iPort, 0, 0, 5); 44 | Log(connectionId > 0 ? "Connected" : "Connection failed"); 45 | 46 | IsConnectionRequired = false; 47 | } 48 | } 49 | } 50 | 51 | void Connect(const Nan::FunctionCallbackInfo& info) { 52 | int setLoaded = LoadSettings(); 53 | Log("Settings Loaded %i", setLoaded); 54 | 55 | listenChatFunc = v8::Local::Cast(info[0]); 56 | 57 | strcpy(g_szNickName, settings.server.szNickname); 58 | 59 | ConnectAsync(); 60 | // std::thread t1(ConnectAsync); 61 | 62 | // t1.join(); 63 | // v8::Local nodeConnectionId = Nan::New(connectionId); 64 | // info.GetReturnValue().Set(nodeConnectionId); 65 | } 66 | 67 | 68 | void MessageReceived(char* message) { 69 | const int argc = 1; 70 | v8::Local args[argc]; 71 | args[0] = Nan::New(message).ToLocalChecked(); 72 | Nan::Callback cb(listenChatFunc); 73 | cb.Call(argc, args); 74 | } 75 | 76 | void Init(v8::Local exports) { 77 | exports->Set(Nan::New("connect").ToLocalChecked(), 78 | Nan::New(Connect)->GetFunction()); 79 | } 80 | 81 | 82 | NODE_MODULE(NODE_GYP_MODULE_NAME, Init); -------------------------------------------------------------------------------- /src/main/main.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | 7 | #pragma comment(lib, "ws2_32") 8 | // raknet stuff 9 | #include "../PacketEnumerations.h" 10 | #include "../RakNetworkFactory.h" 11 | #include "../RakClientInterface.h" 12 | #include "../NetworkTypes.h" 13 | #include "../BitStream.h" 14 | #include "../StringCompressor.h" 15 | #include "../SAMP/samp_netencr.h" 16 | 17 | #include "../tinyxml/tinyxml.h" 18 | 19 | enum eRunModes 20 | { 21 | RUNMODE_RCON, 22 | RUNMODE_BARE, 23 | RUNMODE_STILL, 24 | RUNMODE_NORMAL, 25 | RUNMODE_FOLLOWPLAYER, 26 | RUNMODE_FOLLOWPLAYERSVEHICLE, 27 | RUNMODE_PLAYROUTES 28 | }; 29 | 30 | #include "../SAMP/SAMPRPC.h" 31 | #include "../common/common.h" 32 | #include "../net/netrpc.h" 33 | #include "../net/netgame.h" 34 | #include "localplayer.h" 35 | #include "misc_funcs.h" 36 | #include "xmlsets.h" 37 | #include "log.h" 38 | 39 | #pragma warning(disable:4996) 40 | 41 | struct stVehiclePool 42 | { 43 | int iDoesExist; 44 | float fPos[3]; 45 | int iModelID; 46 | }; 47 | 48 | extern int iAreWeConnected, iConnectionRequested, iSpawned, iGameInited, iSpawnsAvailable; 49 | extern int iReconnectTime; 50 | extern PLAYERID g_myPlayerID; 51 | extern char g_szNickName[32]; 52 | 53 | extern int iMoney, iDrunkLevel, iLocalPlayerSkin; 54 | extern struct stPlayerInfo playerInfo[MAX_PLAYERS]; 55 | extern struct stVehiclePool vehiclePool[MAX_VEHICLES]; 56 | 57 | extern PLAYERID imitateID; 58 | 59 | void handleQueries(char *s, int len); 60 | void SaveTextDrawData ( WORD wTextID, TEXT_DRAW_TRANSMIT *pData, CHAR* cText ); 61 | void gen_random(char *s, const int len); 62 | void MessageReceived(char* message); 63 | extern RakClientInterface *pRakClient; 64 | -------------------------------------------------------------------------------- /src/main/misc_funcs.h: -------------------------------------------------------------------------------- 1 | /* 2 | Updated to 0.3.7 by P3ti 3 | */ 4 | 5 | void onFootUpdateAtNormalPos(); 6 | void onFootUpdateFollow(PLAYERID followID); 7 | void inCarUpdateFollow(PLAYERID followID, VEHICLEID withVehicleID); 8 | void spectatorUpdate(); 9 | 10 | int sampConnect(char *szHostname, int iPort, char *szNickname, char *szPassword, RakClientInterface *pRakClient); 11 | void sampDisconnect(int iTimeout); 12 | void sampRequestClass(int iClass); 13 | void sampSpawn(); 14 | void sampFakeKill(); 15 | void sampLag(); 16 | void sampJoinFlood(); 17 | void sampChatFlood(); 18 | void sampClassFlood(); 19 | void sendServerCommand(char *szCommand); 20 | void sendChat(char *szMessage); 21 | void sendRconCommand(char *szRCONCmd, int iIsLogin); 22 | void sendScmEvent(int iEventType, DWORD dwParam1, DWORD dwParam2, DWORD dwParam3); 23 | void sendDialogResponse(WORD wDialogID, BYTE bButtonID, WORD wListBoxItem, char *szInputResp); 24 | void sendPickUp(int iPickupID); 25 | void selectTextDraw(int iTextDrawID); 26 | 27 | int isPlayerConnected(PLAYERID iPlayerID); 28 | int getPlayerID(char *szPlayerName); 29 | char *getPlayerName(PLAYERID iPlayerID); 30 | int getPlayerPos(PLAYERID iPlayerID, float *fPos); 31 | 32 | PLAYERID getPlayerIDFromPlayerName(char *szName); 33 | unsigned short getPlayerCount(); 34 | 35 | const struct vehicle_entry *gta_vehicle_get_by_id ( int id ); 36 | 37 | int gen_gpci(char buf[64], unsigned long factor); 38 | 39 | void SetStringFromCommandLine(char *szCmdLine, char *szString); 40 | 41 | void processPulsator(); 42 | void processBulletFlood(); 43 | 44 | void useTeleport(int iTeleportID); 45 | 46 | void gen_auth_key(char buf[260], char* auth_in); 47 | int gen_gpci(char buf[64], unsigned long factor); 48 | void BIG_NUM_MUL(unsigned long in[5], unsigned long out[6], unsigned long factor); -------------------------------------------------------------------------------- /src/main/xmlsets.h: -------------------------------------------------------------------------------- 1 | /* 2 | Updated to 0.3.7 by P3ti 3 | */ 4 | 5 | #define MAX_AUTORUN_CMDS 32 6 | #define MAX_FIND_ITEMS 128 7 | #define MAX_TELEPORT_ITEMS 200 8 | 9 | struct stServer 10 | { 11 | char szAddr[256]; 12 | int iPort; 13 | char szNickname[20]; 14 | char szPassword[32]; 15 | }; 16 | 17 | struct stAutoRunCMD 18 | { 19 | int iExists; 20 | char szCMD[512]; 21 | }; 22 | 23 | struct stFindItem 24 | { 25 | int iExists; 26 | char szFind[512]; 27 | char szSay[512]; 28 | unsigned char bBkRed; 29 | unsigned char bBkGreen; 30 | unsigned char bBkBlue; 31 | unsigned char bTextRed; 32 | unsigned char bTextGreen; 33 | unsigned char bTextBlue; 34 | }; 35 | 36 | struct stCheckpointData 37 | { 38 | bool bActive; 39 | float fPosition[3]; 40 | float fSize; 41 | }; 42 | 43 | struct stTeleport 44 | { 45 | bool bCreated; 46 | char szName[64]; 47 | float fPosition[3]; 48 | }; 49 | 50 | struct stSettings 51 | { 52 | struct stServer server; 53 | SOCKET RCONSocket; 54 | struct sockaddr_in RCONserver; 55 | struct sockaddr_in RCONclient; 56 | int iRCONLoggedIn; 57 | char szRCONPass[512]; 58 | int iConsole; 59 | eRunModes runMode; 60 | int iAutorun; 61 | int iFind; 62 | int iClassID; 63 | int iManualSpawn; 64 | int iPrintTimestamps; 65 | 66 | int iUpdateStats; 67 | int iMinFPS; 68 | int iMaxFPS; 69 | 70 | char szClientVersion[20]; 71 | 72 | bool bSpam; 73 | bool bFakeKill; 74 | bool bLag; 75 | bool bJoinFlood; 76 | bool bChatFlood; 77 | bool bClassFlood; 78 | 79 | unsigned int uiSpamInterval; 80 | unsigned int uiFakeKillInterval; 81 | unsigned int uiLagInterval; 82 | unsigned int uiJoinFloodInterval; 83 | unsigned int uiChatFloodInterval; 84 | unsigned int uiClassFloodInterval; 85 | unsigned int uiBulletFloodInterval; 86 | 87 | unsigned int uiObjectsLogging; 88 | unsigned int uiPickupsLogging; 89 | unsigned int uiTextLabelsLogging; 90 | unsigned int uiTextDrawsLogging; 91 | 92 | unsigned char bChatColorRed; 93 | unsigned char bChatColorGreen; 94 | unsigned char bChatColorBlue; 95 | 96 | unsigned char bCMsgRed; 97 | unsigned char bCMsgGreen; 98 | unsigned char bCMsgBlue; 99 | 100 | unsigned char bCPAlertRed; 101 | unsigned char bCPAlertGreen; 102 | unsigned char bCPAlertBlue; 103 | 104 | char szFollowingPlayerName[20]; 105 | int iFollowingWithVehicleID; 106 | float fFollowXOffset; 107 | float fFollowYOffset; 108 | float fFollowZOffset; 109 | 110 | float fNormalModePos[3]; 111 | float fNormalModeRot; 112 | int iNormalModePosForce; 113 | 114 | bool bPulsator; 115 | 116 | float fHealthBeforePulse; 117 | float fArmourBeforePulse; 118 | 119 | float fPlayerHealth; 120 | float fPlayerArmour; 121 | 122 | bool bulletFlood; 123 | 124 | float fCurrentPosition[3]; 125 | 126 | BYTE bCurrentWeapon; 127 | 128 | struct stAutoRunCMD autoRunCMDs[MAX_AUTORUN_CMDS]; 129 | struct stFindItem findItems[MAX_FIND_ITEMS]; 130 | 131 | unsigned int uiChallange; 132 | 133 | struct stCheckpointData CurrentCheckpoint; 134 | 135 | bool AutoGotoCP; 136 | 137 | stTeleport TeleportLocations[MAX_TELEPORT_ITEMS]; 138 | 139 | unsigned int uiForceCustomSendRates; 140 | }; 141 | extern struct stSettings settings; 142 | 143 | int LoadSettings(); 144 | int UnLoadSettings(); 145 | int ReloadSettings(); 146 | -------------------------------------------------------------------------------- /src/net/netgame.h: -------------------------------------------------------------------------------- 1 | /* 2 | Updated to 0.3.7 by P3ti 3 | */ 4 | 5 | void resetPools(int iRestart, DWORD dwTimeReconnect); 6 | void UpdatePlayerScoresAndPings(int iWait, int iMS, RakClientInterface *pRakClient); 7 | void UpdateNetwork(RakClientInterface *pRakClient); 8 | -------------------------------------------------------------------------------- /src/net/netrpc.h: -------------------------------------------------------------------------------- 1 | /* 2 | Updated to 0.3.7 by P3ti 3 | */ 4 | 5 | #define REJECT_REASON_BAD_VERSION 1 6 | #define REJECT_REASON_BAD_NICKNAME 2 7 | #define REJECT_REASON_BAD_MOD 3 8 | #define REJECT_REASON_BAD_PLAYERID 4 9 | 10 | extern int iNetModeNormalOnfootSendRate, iNetModeNormalIncarSendRate, iNetModeFiringSendRate, iNetModeSendMultiplier; 11 | extern char g_szHostName[256]; 12 | 13 | #define MAX_MENU_ITEMS 12 14 | #define MAX_MENU_LINE 32 15 | #define MAX_COLUMNS 2 16 | struct MENU_INT 17 | { 18 | BOOL bMenu; 19 | BOOL bRow[MAX_MENU_ITEMS]; 20 | BOOL bPadding[8 - ((MAX_MENU_ITEMS + 1) % 8)]; 21 | }; 22 | struct stGTAMenu 23 | { 24 | char szTitle[MAX_MENU_LINE]; 25 | char szSeparator[MAX_MENU_LINE]; // ??? 26 | BYTE byteColCount; 27 | char szColumnContent[MAX_COLUMNS][MAX_MENU_LINE]; 28 | }; 29 | 30 | #define IDB_BUTTON1 10 31 | #define IDB_BUTTON2 11 32 | #define IDE_INPUTEDIT 12 33 | #define IDL_LISTBOX 13 34 | 35 | #define DIALOG_STYLE_MSGBOX 0 36 | #define DIALOG_STYLE_INPUT 1 37 | #define DIALOG_STYLE_LIST 2 38 | #define DIALOG_STYLE_PASSWORD 3 39 | 40 | struct stSAMPDialog 41 | { 42 | int iIsActive; 43 | BYTE bDialogStyle; 44 | WORD wDialogID; 45 | BYTE bTitleLength; 46 | char szTitle[257]; 47 | BYTE bButton1Len; 48 | char szButton1[257]; 49 | BYTE bButton2Len; 50 | char szButton2[257]; 51 | char szInfo[257]; 52 | }; 53 | extern struct stSAMPDialog sampDialog; 54 | 55 | extern bool iGettingNewName; 56 | 57 | void RegisterRPCs(RakClientInterface *pRakClient); 58 | void UnRegisterRPCs(RakClientInterface * pRakClient); 59 | -------------------------------------------------------------------------------- /src/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 | -------------------------------------------------------------------------------- /src/tinyxml/tinystr.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SyncroIT/RakClient-NodeGYP/06ee47c95396ec80e0ce90434e52887b06c44715/src/tinyxml/tinystr.cpp -------------------------------------------------------------------------------- /src/tinyxml/tinyxmlerror.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | www.sourceforge.net/projects/tinyxml 3 | Original code (2.0 and earlier )copyright (c) 2000-2006 Lee Thomason (www.grinninglizard.com) 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any 7 | damages arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any 10 | purpose, including commercial applications, and to alter it and 11 | redistribute it freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must 14 | not claim that you wrote the original software. If you use this 15 | software in a product, an acknowledgment in the product documentation 16 | would be appreciated but is not required. 17 | 18 | 2. Altered source versions must be plainly marked as such, and 19 | must not be misrepresented as being the original software. 20 | 21 | 3. This notice may not be removed or altered from any source 22 | distribution. 23 | */ 24 | 25 | #include "tinyxml.h" 26 | 27 | // The goal of the seperate error file is to make the first 28 | // step towards localization. tinyxml (currently) only supports 29 | // english error messages, but the could now be translated. 30 | // 31 | // It also cleans up the code a bit. 32 | // 33 | 34 | const char* TiXmlBase::errorString[ TIXML_ERROR_STRING_COUNT ] = 35 | { 36 | "No error", 37 | "Error", 38 | "Failed to open file", 39 | "Error parsing Element.", 40 | "Failed to read Element name", 41 | "Error reading Element value.", 42 | "Error reading Attributes.", 43 | "Error: empty tag.", 44 | "Error reading end tag.", 45 | "Error parsing Unknown.", 46 | "Error parsing Comment.", 47 | "Error parsing Declaration.", 48 | "Error document empty.", 49 | "Error null (0) or unexpected EOF found in input stream.", 50 | "Error parsing CDATA.", 51 | "Error when TiXmlDocument added to document, because TiXmlDocument can only be at the root.", 52 | }; 53 | --------------------------------------------------------------------------------