slikenet (RakNet 4.081)

repository·master·Indexed 19 days ago

https://github.com/slikesoft/slikenet

A high-performance networking engine for real-time applications and games. RakNet 4.081 provides reliable and unreliable UDP communication, NAT traversal, and cross-platform support for Windows, Linux, macOS, and Android. The repository includes core source files, pre-compiled libraries, and dependent extensions such as bzip2-1.0.6 and DXTCompressor.

Tokens
52K
Snippets
136
Records
225
Agent score
66%

What's inside slikenet

  1. Overview of PortAudio

    master

    PortAudio is a portable, cross-platform audio I/O library. It provides a unified interface for audio processing across different operating systems and hardware backends.

    Key features:

    • Callback Mechanism: Uses a callback-driven model to request audio processing.
    • Format Support: Supports various audio formats, including 32-bit floating point, which the library converts to the native hardware format internally.
    • Platform Abstraction: Abstracts away platform-specific implementations like Windows DirectSound, Mac SoundManager, or ASIO.
  2. Introduction to Jansson

    master

    Jansson is a C library designed for encoding, decoding, and manipulating JSON data. It is characterized by a simple and intuitive API and data model, making it suitable for a wide range of environments from desktop and server applications to small embedded systems.

    Key features include:

    • Full Unicode support (UTF-8).
    • No dependencies on other libraries.
    • Stable API suitable for production use.
    • Cross-platform compatibility (Unix-like systems and Windows).
  3. Overview of RakNet 4.081 Package Structure

    master

    The RakNet package is organized into several key directories to support different development workflows:

    • Help/: Contains full HTML documentation (starting with index.html).
    • Source/: Contains the core RakNet source files. Use this if you want to integrate the source directly into your program or build your own DLL.
    • Samples/: Contains code samples and game examples demonstrating specific RakNet features.
    • lib/: Contains pre-compiled libraries for both Debug and Release versions of RakNet and RakVoice.

    Build Systems:

    • Linux: Use the make file located in the root directory.
    • Windows: Use the project files located under Samples\Project Samples.
  4. What is SLikeNet?

    master

    SLikeNet™ is an open-source, cross-platform network engine written in C++, specifically designed for games and high-performance applications. It is built upon the discontinued RakNet engine and incorporates bug fixes, security enhancements, and modern compiler support.

    Supported Platforms:

    • Windows
    • Linux
    • Mac
    • Limited support for iPhone®, Android™, Windows Phone 8, and Windows Store 8.
  5. Implement automatic object replication with Replica3

    master

    To create replicatable objects, derive your class from Replica3. You must implement interfaces for construction, remote construction, and serialization to control how data is sent and received.

    Key lifecycle methods:

    • SerializeConstruction(): Called when the object is first created to send initial state.
    • Serialize(): Called every tick to synchronize changing data.
    • PostDeserializeConstruction(): Called on remote systems after the object is constructed to perform additional setup (e.g., triggering visual effects or animations).
  6. String handling and null character restrictions

    master

    Jansson maps JSON strings to C-style null-terminated character arrays using UTF-8 encoding.

    Critical Restriction: Strings may not contain embedded null characters (\u0000), even if they are escaped in the JSON text. Attempting to decode a string containing a null character will result in a parse error.

    All other Unicode codepoints (U+0001 through U+10FFFF) are allowed. Jansson does not perform Unicode normalization; string and key comparisons are performed byte-by-byte using the original UTF-8 representations.

    ["this string contains the null character: \u0000"]
  7. How Jansson distinguishes between Real and Integer numbers

    master

    While JSON does not distinguish between real and integer numbers, Jansson does. Numbers are mapped to either double (Real) or json_int_t (Integer).

    • Real Numbers: A number is treated as a double if its lexical representation includes an exponent (e or E) or a decimal point (.). This applies even if the mathematical value is an integer (e.g., 3.0 or 1E6 are treated as real values).
    • Integer Numbers: All other JSON numbers are treated as json_int_t (which is a typedef of long long or long depending on your compiler).

    Encoding Note: When encoding to JSON, real values are always represented with a fractional part (e.g., the double value 3.0 is encoded as 3.0, not 3).

  8. Manage locale settings in multithreaded programs using Jansson

    master

    Jansson is compatible with any locale, but using setlocale() in a multithreaded environment can cause data corruption or crashes during JSON encoding/decoding.

    The Risk: Jansson uses locale-specific functions for string conversions. Because setlocale() changes the locale for the entire process (all threads), a thread calling setlocale() can change the locale in the middle of another thread's encoding or decoding operation. This breaks the consistency between the string conversion and the JSON representation.

    Solution: If your application must switch locales in a multithreaded context, use the thread-safe uselocale() function instead of setlocale() to avoid affecting other threads currently performing Jansson operations.

  9. SLikeNet Versioning and Compatibility

    master

    SLikeNet follows Semantic Versioning (SemVer 2.0.0).

    Compatibility Rules

    • 1.x.y releases: Maintain API, ABI, and protocol compatibility with RakNet 4.081/4.082. This allows for in-place testing by replacing RakNet DLLs or linking against SLikeNet libraries without code changes.
    • 2.x.y and following: These releases break backwards compatibility with RakNet to allow for performance improvements and new features. Both client and server must run at least version 2.0.0 to work together.
    • Inter-version compatibility: Any x.y.z version is compatible with any other x.y.z version as long as x is the same (or differs by only 1 digit and is at least 2). For example, a 3.0.0 server can support clients running 2.x.y up to 4.x.y.
  10. Handle thread safety and shared JSON values in Jansson

    master

    Jansson is thread-safe and maintains no mutable global state, with the exception of memory allocation functions (which should be configured at most once during program startup).

    However, Jansson does not perform internal locking. If you share JSON values across multiple threads, you must implement your own locking mechanism.

    Key Thread Safety Risks:

    1. Reference Counting: Modifying a container (adding/removing values) can trigger concurrent access to values because containers manage the reference counts of their contents. This can lead to race conditions in reference count increments/decrements.
    2. Encoding Functions: Functions like json_dumps() track reference loops by modifying the internal state of objects and arrays. You must not run encoding functions on the same JSON values in two separate threads simultaneously.
    3. Shared Values: If multiple arrays or objects share the same contained values, modifying one can affect the others via reference counting.

    Best Practice: To ensure two JSON hierarchies do not share any values, use json_deep_copy() to create independent copies.

    // To prevent shared value issues across threads, create a deep copy
    json_t *safe_copy = json_deep_copy(original_value);
  11. Manage Jansson memory with json_decref()

    master

    Jansson uses reference counting for memory management. When you create a JSON object (e.g., via json_loads()) or obtain a new reference, you are responsible for decreasing the reference count when the object is no longer needed. Call json_decref(object) to release the memory associated with the object and its children.

    json_t *root = json_loads(text, 0, &error);
    // ... use root ...
    json_decref(root);