Coder Social home page Coder Social logo

darkrift.documentation's Introduction

Hello!

Welcome to the DarkRift 2 open source project!

DarkRift 1 and 2 were originally written by Jamie Read. DarkRift 2 has since been open sourced under the care of Unordinal AB and the DarkRift community. Unfortunately, Unordinal is no longer able to maintain the project, so it is being cared for by the DarkRift 2 community. Support for DarkRift is 100% community driven, and we encourage new users to join our community discord.

Features

DarkRift is an extremely performant multithreaded networking library best used for creating multiplayer experiance that require authoritative server.

High Performance Unlimited CCU Extremely Low Overhead Full TCP & UDP Support
DarkRift was designed to be as fast, efficient and as powerful as you could ever need. Our multithreading expertise helps you take advantage of every CPU core and thread in your servers. DarkRift has no CCU limits. Scale to thousands of players without worrying about CCU restrictions. DarkRift overhead can go as low as just 3 bytes on UDP. DarkRift 2 introduces bi-channel communication allowing you to mix and send UDP and TCP messages quickly and reliably depending on your needs.
Embedded or Standalone Free, Forever Authoritative Flexible
DarkRift provides support for both Unity embedded and standalone servers allowing you to take advantage of existing Unity features or push for extreme performance with a standalone build. DarkRift 2 is and will remain free and open source. DarkRift servers are fully authoritative. They own the communication and control exactly what the client can and cannot do on your system. You write the logic, DarkRift will handle the messaging. DarkRift is a message passing framework. It doesn't provide opinionated ways of doing things or try to force you into a programming paradigm that doesn't fit your needs
Loves your protocol Scalability Deep Metrics Chat Filter (Bad Word Filter) and other goodies
Got a favourite low level networking library you want to continue using? Swap out DarkRift's Bichannel Network Listener for any library you like. With DarkRift's state of the art server clustering, you can build a backend capable of seamlessly scaling with your player base. Built in support for Prometheus metrics means you can directly integrate with your existing metrics and monitoring solution like Grafana or Datadog. DarkRift comes with some quality of life features including a chat filter, basic matchmaking support, custom metrics, and more.

Getting Started

Grab the latest stable version from the download page.

You can find an example of a minimal embedded .NET server and client here, or follow Any of the below community tutorials to get started.

Bottom to Top Multiplayer with DarkRift - @Robodoig Source Code

FPS style tutorial - @lukesta Source Code

Lets make An "MMO" series tutorial - @Ace Source Code

How To Make A Multiplayer Game With DarkRift - Video Tutorial - @Dexter

Tic Tac Toe Tutorial - Video Tutorial by - @HappySpider

For more resources and other guides related to DarkRift and multiplayer development in general, join the community discord and see #resources.

Building

This project requires Microsoft Visual Studio 2022 (the free Community edition is fine) or at least one Visual C# project will fail to build in VS2019 and below. See detailed exposition in BUILDING.md

Source Code License

Most source files are licensed under MPL 2.0, with some exceptions where MIT applies. See LICENSE.md

Contributing

We are happy to see community contributions to this project. See CONTRIBUTING.md

Code of Conduct

Be civil. See CODE_OF_CONDUCT.md

Wiki

The wiki is publicly editable and is a place for anyone to add content, code snippets, tutorials and anything that would be useful to other members of the DarkRift Networking community.

Feel free to add pages and use the space as you wish. You are more than welcome (and even encouraged) to cross post from personal blogs and link to external sites (as long as it's relevant)!

DarkRift Networking is not responsible for any content or links on the wiki, although we will monitor it nevertheless.

Minimal Example

Examples are using plain .NET with C# 9.0 top level statements for clarity. You can also use similar code in Unity.

First, we start a server that gets its settings from the local file server.config.

using DarkRift;
using DarkRift.Server;

ServerSpawnData spawnData = ServerSpawnData.CreateFromXml("Server.config");

var server = new DarkRiftServer(spawnData);

void Client_MessageReceived(object? sender, MessageReceivedEventArgs e)
{
    using Message message = e.GetMessage();
    using DarkRiftReader reader = message.GetReader();
    Console.WriteLine("Received a message from the client: " + reader.ReadString());
}

void ClientManager_ClientConnected(object? sender, ClientConnectedEventArgs e)
{
    e.Client.MessageReceived += Client_MessageReceived;

    using DarkRiftWriter writer = DarkRiftWriter.Create();
    writer.Write("World of Hel!");

    using Message secretMessage = Message.Create(666, writer);
    e.Client.SendMessage(secretMessage, SendMode.Reliable);
}

server.ClientManager.ClientConnected += ClientManager_ClientConnected;

server.StartServer();

Console.ReadKey(); // Wait until key press. Not necessary in Unity.

The XML file server.config looks like this (hard to make shorter).

<?xml version="1.0" encoding="utf-8" ?>
<!--
  Configuring DarkRift server to listen at ports TCP 4296 and UDP 4297.
-->
<configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://www.darkriftnetworking.com/DarkRift2/Schemas/2.3.1/Server.config.xsd">
  <server maxStrikes="5" />
  
  <pluginSearch/>
 
  <logging>
    <logWriters>
      <logWriter name="ConsoleWriter1" type="ConsoleWriter" levels="trace, info, warning, error, fatal">
        <settings useFastAnsiColoring="false" />
      </logWriter>
    </logWriters>
  </logging>

  <plugins loadByDefault="false"/>

  <data directory="Data/"/>

  <listeners>
    <listener name="DefaultNetworkListener" type="BichannelListener" address="0.0.0.0" port="4296">
      <settings noDelay="true" udpPort="4297" />
    </listener>
  </listeners>
</configuration>

And finally, here is a client that connects to the server and sends "Hello world!" whilst receiving a string that should be "World of Hel!" (just be mindful about pressing any key since that terminates the program early).

using DarkRift;
using DarkRift.Client;
using System.Net;

var client = new DarkRiftClient();

void Client_MessageReceived(object? sender, MessageReceivedEventArgs e)
{
    using Message message = e.GetMessage();
    using DarkRiftReader reader = message.GetReader();
    Console.WriteLine("Received a message from the server: " + reader.ReadString());
}

client.MessageReceived += Client_MessageReceived;

client.Connect(IPAddress.Loopback, tcpPort:4296, udpPort:4297, noDelay:true);

Console.WriteLine("Connected!");

using DarkRiftWriter writer = DarkRiftWriter.Create();
writer.Write("Hello world!");

using Message secretMessage = Message.Create(1337, writer);
client.SendMessage(secretMessage, SendMode.Reliable);

Console.ReadKey(); // Wait until key press. Not necessary in Unity.

Do note that "Connected!" message can be printed even after "World of Hel!" since DR2 is multithreaded.

This was an example of embedding DarkRift into your own programs. You can instead choose to implement DarkRift.Server.Plugin (see the manual) for looser coupling.

darkrift.documentation's People

Contributors

4real avatar aaronrmm avatar aweidermann avatar brettriekman avatar elginas avatar eliseodiegoviola avatar hukha avatar jamjar00 avatar pekaram avatar penca53 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

darkrift.documentation's Issues

No overwrite an object on deserialization in Message

Quick Description

The documentation mentions a function to overwrite an object on deserialization without a reference.

Explanation

The documentation points to the DarkRift.message.Deserialize<T>() : https://www.darkriftnetworking.com/DarkRift2/Docs/2.9.1/advanced/serialization.html
and claims

It is also possible to pass DarkRift an object to overwrite on deserialization to reduce garbage generation.

This functionality is only provided by DarkRiftReader.ReadSerializableInto<T>().

The documentation should best state, that more functionality is provided by DarkRiftReader.

Incompatibility issue Unity 2018.3.8f1 (New Prefab System) in Tutorial

Due to the new prefab system there is now a different hierarchy in prefabs.
Referenced tutorial page is: https://darkriftnetworking.com/DarkRift2/Docs/2.4.0/getting_started/5_movement.html

Before:
Circle(Player) with all the scripts and renderer etc on it.

Now:
Prefab (Parent)
Circle (Child)

Because of this the PlayerSpawner script is giving errors in the SpawnPlayer script when it needs to get the Player and AgarObject component.

Errorlines:
Player player = obj.GetComponent();
AgarObject agarObj = obj.GetComponent();

Fix:
Player player = obj.GetComponentInChildren();
AgarObject agarObj = obj.GetComponentInChildren();

I will try and fix this right now but to be sure I prefer also submitting an issue.

EDIT: Please disregard, false information

Increased Clarity for Pro Features in Documentation

Quick Description

Add a stamp, image, or otherwise clear marker at the top of each page of documentation as to whether the specified class, interface, or other is Free or Pro.

For Feature Requests

Entire documentation would benefit from having visual Free/Pro clarification at the top of each page.

Some current examples where it would help are:
Timer Class: Pro, but missing the remark stating that it was Pro, so it isn't known (bug, but pointed out in discord).
Plugin.BadWorldFilter: Pro, but marked at the bottom of the page in plain text as Pro only. Not immediately visible.

Syntax error in example matchmaker

In the example matchmaker on this page the type parameter on the class is a Player but the ranking function expects a int.

The type parameter on the class should be changed to int.

IPVersion still used in tutorial

The tutorial still shows the obsolete IP version property in an image of the Unity inspector. This image should be updated and any other references fixed.

Parse Error

The default value "localhost" of UnityClient.Host will be parsed incorrectly as "::1" instead of "127.0.0.1" on windows 10 by using darkrift pro.

Tutorial Unity MouseController

Thanks for creating an issue/feature request! Please use the template below to ensure you have all the necessary information.

Quick Description

ControllablePlayer doesn't move with the mouse after adding MouseController to it.

Explanation

Camera.main.ScreenToWorldPoint(Input.mousePosition) always returns zero.

For Issues

Unity version 2018.2.18f1

I resolved ScreenToWorldPoint always returning zero by changing it to:
Camera.main.ScreenToWorldPoint(Input.mousePosition + new Vector3(0, 0, 10))

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.