Giter VIP home page Giter VIP logo

light-reflective-mirror's Introduction

Logo

Light Reflective Mirror

Maintainability

LRM Node / MultiCompiled

Build status

Docker Cloud Build Status

LoadBalancer

Build status

Docker Cloud Build Status

Unity Package

Build status

What

Light Reflective Mirror is a transport for Mirror Networking which relays network traffic through your own servers. This allows you to have clients host game servers and not worry about NAT/Port Forwarding, etc. There are still features I plan on adding but it still is completely stable in its current state.

Features

  • WebGL Support, WebGL can host servers!
  • Built in server list!
  • Relay password to stop other games from stealing your precious relay!
  • Relay supports connecting users without them needing to port forward!
  • NAT Punchtrough (Full Cone, Restricted Cone, and Port Restricted Cone)
  • Direct Connecting
  • Load Balancing with multi-relay setup

How does it work?

I took a bit of a unique approach to this version and instead of using one fixed net library for the game to communicate with the standalone relay server, I instead made it use any of mirrors transports! This allows you to make it work with websockets, Ignorance(ENET), LiteNetLib, and all the others!

Known Issues/Flaws

Disconnects from the relay will not auto reconnect yet. So a dedicated host is extremely recommended! Or implement your own logic to auto reconnect.

Tutorials

(I recommend these over the text format)

How to setup LRM on an ubuntu server

https://www.youtube.com/watch?v=0SpKIs0Beuo

How to setup LRM in unity, along with basic usage

https://www.youtube.com/watch?v=Wi0rp2b8KmM

Usage

Now for the juicy part, using it. Like I mentioned in the 'What' section, this is a prototype so if theres problems, please report them to me. Also PRs are also always welcomed! :)

First things first, you will need:

  • Mirror, Install that from Asset Store.
  • Download the latest release of Light Reflective Mirror Unity Package and put that in your project also. Download from: Releases.

Client Setup

Running a client is fairly straight forward, attach the LightReflectiveMirrorTransport script to your NetworkManager and set it as the transport. Put in the IP/Port of your relay server, assign LightReflectiveMirror as the Transport on the NetworkManager. Then attach the SimpleWebTransport script and assign that in the 'ClientToServerTransport' in the Light Reflective Mirror inspector. When you start a server, you can simply get the URI from the transport and use that to connect. If you wish to connect without the URI, the LightReflectiveMirror component has a public "Server ID" field which is what clients would set as the address to connect to.

If your relay server has a password, enter it in the relayPassword field or else you wont be able to connect. By default the relays have the password as "Secret Auth Key".

Server List

Light Reflective Mirror has a built in room/server list if you would like to use it. To use it you need to set all the values in the 'Server Data' tab in the transport. Also if you would like to make the server show on the list, make sure "Is Public Server" is checked. Once you create a server, you can update those variables from the "UpdateRoomInfo" function on the LightReflectiveMirrorTransport script.

To request the server list you need a reference to the LightReflectiveMirrorTransport from your script and call 'RequestServerList()'. This will invoke a request to the server to update our server list. Once the response is recieved the field 'relayServerList' will be populated and you can get all the servers from there.

Server Setup

Download the latest Server release from: Releases Make sure you have .NET Core 5.0 And all you need to do is run LRM.exe on windows, or "dotnet LRM.dll" on linux!

Server Config

In the config.json file there are a few fields.

TransportDLL - This is the name of the dll of the compiled transport dll.

TransportClass - The class name of the transport inside the DLL, Including namespaces! By default, there are 5 compiled transports in the MultiCompiled dll. To switch between them you have the following options:

  • Mirror.TelepathyTransport
  • kcp2k.KcpTransport
  • Mirror.SimpleWebTransport
  • MultiCompiled.KcpWebCombined

AuthenticationKey - This is the key the clients need to have on their inspector. It cannot be blank.

UpdateLoopTime - The time in miliseconds between calling 'Update' on the transport

UpdateHeartbeatInterval - the amounts of update calls before sending a heartbeat. By default its 100, which if updateLoopTime is 10, means every (10 * 100 = 1000ms) it will send out a heartbeat.

What to choose, Epic, Steam, LRM?

There are quiet a few relay transports for mirror at this point, It can often be difficult to pick one that most suits your needs. So I'll quickly go over my view on it and hopefully it helps you make an informed decision.

Steam

Starting with steam, steam offers a free relay with NAT punchthrough for anyone releasing a game on steam. This integrates into their lobby invites and also only allows connections from other users who actually own the game (No pirates sneaking into your servers!) and it works wonders. Steam has well documented SDK, a huge community, and they are active on their forums. If you plan on releasing on steam and only steam, go with this. To get the steam relay, go into the #steam channel in mirror's discord and use whichever one is the same as your wrapper.

Epic

Epic is a newer transport that offers NAT Punchthrough, and a relay service for free. As of writing this its only available for usage on Windows/Mac/Linux (More platforms are planned and releasing in the future). This one is great because they offer it for free! Thats right, a free relay and NAT punchthrough server, plus more! They have more tools such as Matchmaking, server browser, statistics, and more! This is NOT locked into only releasing on Epic Store, like how steams is. So you can release on any store you want if your game uses this. Now onto the downsides, they have a very PITA SDK to use with a fairly small community for the C# side of things. (FakeByte helps alot in the discord and will help with features outside of the relay transport!). The documentation is sub-par and severely lacking in some places, which is expected as its fairly new. They also have Epic Account Services, which is similar to steams but like the relay, not locked into one store! With those services you get user accounts, In game purchases, achievements, and much more. So if you want a free relay/NAT Punchthrough server, and want to go along for the ride of EoS, this is the one. You cant beat free. :P Check it out here

LRM

LRM is a self-hosted, open source, relay/NAT Punchthrough server. It's available for all platforms (PC, Mac, Linux, WebGL, Android, IOS, You name it!). It does this by supporting any of mirrors existing transports. If you want webgl? Use websockets! Want TCP? Telepathy! UDP? KCP! This is one of LRM's main features. The game developer can decide on how they want their data sent between the server and clients. With LRM, you are going to have to host the servers yourself. We are releasing a load balancer soon which will make it super easy to expand servers in regions and balance users out between them. The more powerful of a server you have, the more that LRM node can host. With some tests (All clients relayed, none NAT punched), we could get about ~200 CCU on a $5 google cloud server (f1-micro). Though, LRM is still constantly being worked on and could have changes, rewrites, etc at any time. You are able to contribute if you find any bugs, just by opening a PR! So, if you are more of a self-hosting person, who wants full control of your servers, or want a relay for a platform the others don't support (WebGL). Use LRM, if you have any questions, we are in the discord channel everyday! :)

Video Tutorial Commands

Pull docker image: docker pull derekrs/lrm_node:Bleeding-Edge

Run docker for config: docker run -it --rm -v /root/:/config --name lrm-node derekrs/lrm_node:Bleeding-Edge

Run docker headless: docker run -d -it --rm -p 8080:8080 -p 7777:7777/udp -p 7776:7776/udp -v /root/:/config --name lrm-node derekrs/lrm_node:Bleeding-Edge

Credits

Cooper - Assisted with development and made some wonderful features! He's also active in the discord to help answer questions and help with issues.

Maqsoom & JesusLuvsYooh - Both really active testers and have been testing it since I pitched the idea. They tested almost all versions of DRM and I am sure they will test the crap out of LRM!

All Mirror Transport Creators! - They made all the transports that this thing relies on! Especially the Simple Web Transport by default!

License

MIT

light-reflective-mirror's People

Contributors

cxxpxr avatar derek-r-s avatar mukaschultze avatar sableangle avatar tufcode avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

light-reflective-mirror's Issues

AWS connection issues

Absolutely love this asset and the YouTube tutorials, thank you so much for putting them together!

I'm trying to set up an AWS relay server and am not having any luck just yet. I've got LRM installed and running on the EC2 instance without any problem, and I've allowed incoming traffic from ports 7776, 7777, and 8080 on the server.

While following the Unity tutorial, I'm getting a KCP timeout error in Unity after 10 seconds: KCP: Connection timed out after not receiving any message for 10000ms. Disconnecting.

I've tried pasting both the public and private IP addresses of the EC2 instance into the LRM Server IP field with the same result. Can you think of anything I might be missing or if there's something AWS-specific I should be doing?

Thanks again, really appreciate your work on this!

Missing LICENSE file

The read me says it uses the MIT license but I cannot find it in the repo iself. I assume it is missing?

Can not connect to the LAN host server.

Using LRM v11 and Mirror v42.2.12(current version in assetstore).
When host and client are in the same LAN.(Using kcp direct connect)
Hosting server on like 192.168.0.100,
and client on like 192.168.0.101,
after clicking join server which serverId get from the relayServer,
console show the following log:

KCP: Connection timed out after not receiving any message for 10000ms. Disconnecting.

Is the LRM not compatible with the LAN or is there a way like network discovery to connect in LAN?

Endpoint port issue?

Hello,

On Ubuntu 18.04 when I run sudo dotnet LRM.dll there is an error about an endpoint service.

Starting Endpoint Service... Server: listening port=7777
System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'System.Net.HttpListener'.
at System.Net.HttpListener.CheckDisposed()
at System.Net.HttpListener.Stop()
at Grapevine.RestServer.Start() in C:\Users\scott\source\grapevine\src\Grapevine\RestServer.cs:line 174
at LightReflectiveMirror.Endpoints.EndpointServer.Start(UInt16 port)
FAILED
Please run as administrator or check if port is in use.

GET request to http://{loadBalancerAddress}:{loadBalancerPort}/api/join/ returns "Method Not Implemented: Get /api/join"

Hello! I've followed both tutorials and put everything on an EC2 instance on AWS, but nothing seems to be happening. I state that I have a lot of inexperience on the BE side, so I might be doing something wrong.

Nothing seems to happen when I connect to Unity, and doing some Debugging I noticed that this request returns Method Not Implemented. Any idea what I might have been doing wrong?

Host mode Client exits the game and reports an error

When the Client in Host mode is disconnected, LightReflectiveMirrorTransport._isClient = false will be executed first. When LightReflectiveMirrorTransport.DataReceived is executed and opcode == ServerLeft _isClient is already equal to false, the OnClientDisconnected event cannot be called normally.

Code

LRM version: BleedingEdge-v13.0
Mirror version: v67.1.0

Dedicated server config

Hi Derek-R-S,
I have some issues using the server on a remote (linux) machine,
The server dll starts e shows up all the standards messages, it receives client connections as well.

The things gets weird on client side when starting mirror as a host/server and the LRM transport does not receives back the "Server Id" from the relay.

Tried on your machine [34.67.125.123] and on a local network machine and it works as expected (very well btw!)

so... is there any config I should pay attention on for a linux (debian10) server?

ConnectedToRelay is registered too late

Latest change breaks connecting to relay:
```
private void OnEnable()
{
clientToServerTransport.OnClientConnected = ConnectedToRelay;
...


If I have "Connect on Awake" checked then `ConnectToRelay()` is called before `OnEnable()` so `ConnectedToRelay()` is never called and LRMTransport doesn't know it was actually connected(_connectedToRelay remains false).

Unstable Direct connection module

Evn.
Client to Server transport : SimpleWebTransport
Direct connection module transport : KcpTransport
Relay Server hosted on a NAS's VM with public ip address

LightReflectiveMirrorTransport component setup
Relay Server port : 7000
NAT punchthrough port : 7001
Kcp transport port : 7777
SimpleWebTransport port : 7778

The Direct connection works great while all client under same LAN.

But if I change one of my unity editor into iPhone's hotspot network and try to connect to host.
The direct connect will failed.
Host console will show msg "Direct Connect Client Connected" and after a while and new msg "Kicked direct connect client." shows.

Client show msg "KCP: Connection timed out after not receiving any message for 10000ms. Disconnecting."

Trying to connect in unity but no luck!

Hi, i've setup relay server exactly the way showed in the youtube videos, but no luck inside Unity to connect to relay server. Please can you send me the discord changel to see what could be? thanks!

Issue with lrm.Dll

Hi! When I try to run dotnet lrm.dll it throws an json parse error (LRM.runtimeconfig.json file) In Linux machine

ServerId is wrong on LightReflectiveMirrorTransport component

Use the ver in Release 9.0.
The ServerId on LightReflectiveMirrorTransport component didn't match the value return by the API /api/servers.

For instance, on my Unity host the ServerId value is 19, but the /api/servers return value like this:
[ { "serverId": 963094828, "hostId": 22, "serverName": "Squid_4145's Room", "serverData": "Map 1", "isPublic": true, "maxPlayers": 6, "clients": [] } ]

Seems the hostId is fill into the ServerId on host's LightReflectiveMirrorTransport component.

WebGL build crashes when accessing LRM server

My WebGL game crashes when making a request to https://relay.example.com:8080/api/compressed/servers (where relay.example.com resolves to a digital ocean vps).

Visiting the url through firefox shows the following:

Secure Connection Failed

An error occurred during a connection to relay.example.com:8080. SSL received a record that exceeded the maximum permissible length.

Error code: SSL_ERROR_RX_RECORD_TOO_LONG

- The page you are trying to view cannot be shown because the authenticity of the received data could not be verified.
- Please contact the website owners to inform them of this problem.

If I visit the url with http instead of https, everything seems to be fine.

Are there settings in LRM/Mirror that I'm missing that can help with this?

Typo in config.json

There is a typo in config.json - which should probably be updated at some point. This might require support for both the correct and incorrect spelling to prevent breaking existing LRM servers.

"EnableNATPunchtroughServer":
"NATPunchtroughPort":

Should be:

"EnableNATPunchthroughServer":
"NATPunchthroughPort":

The ability to use user's Json Library in LRM

Since there is usually already a Json library is in a Unity project. (But maybe not JSON.Net)
I wish to let user use their Json Library to deserialize json in LRM.

Currently I do some modify like this

Add the delegate in LightReflectiveMirrorTransport

public static System.Func<string, List<Room>> OnDeserializeRoom;
public static System.Func<string, RelayAddress> OnDeserializeRelayAddress;

Then register the delegate. In my case I use LitJson.

(Some script execute before Transport init)

public override void Awake()
{
        LightReflectiveMirror.LightReflectiveMirrorTransport.OnDeserializeRoom += (result) =>
        {
            return LitJson.JsonMapper.ToObject<List<LightReflectiveMirror.Room>>(result);
        };
        
        LightReflectiveMirror.LightReflectiveMirrorTransport.OnDeserializeRelayAddress += (result) =>
        {
            return LitJson.JsonMapper.ToObject<LightReflectiveMirror.RelayAddress>(result);
        };
}

I have done this modify in my local branch, if you also think this is a good idea, I will make a pull request.
Or any suggestion about the implementation is welcome.

KCP: Random amounts of lobbies crashing/freezing at random intervals

I'm using v12 and one relay server, and the image attached is (likely) outputted to the console when it crashes.
By crash/freeze, I mean the lobby stops sending and receiving traffic. No disconnect packets are sent from what I've gathered, but the relay itself is still functional, but people just need to restart their lobbies.
unknown
I am also using a piece of software called pterodactyl to "host" the web panel for the console, and I'm using AWS Lightsail to host it.
If you need to quickly contact me, my Discord is Virtual#7802

EDIT#1:
After looking through the source code of KCP and the relay, it seems it's just an issue with KCP, so I am going to switch the relay to use websockets or something else and see if that fixes it.

Room status

Thank you for the great project.
It's really good starting point for me.

  • when host start playing the game, is there a logic to prevent not joining to the game?

V12 crash on debian

Hello,
I am developing, I have the node server which is launched on debian by "screen -dmSL servrelay dotnet LRM.dll".

And since these last days, the server crashed randomly or so during my test and debug but I did not make any changes in LRM, only listed my game.

I have UseEndpoint, EndpointServerList and EnableNATPunchtroughServer enabled in the config
and i use KcpTransport

this is my log (sorry i have only that):

Unhandled exception. System.ArgumentOutOfRangeException: Length cannot be less than zero. (Parameter 'length')
at System.String.Substring(Int32 startIndex, Int32 length)
at System.Net.HttpListenerRequestUriBuilder.GetPath(String uriString)
at System.Net.HttpListenerRequestUriBuilder.BuildRequestUriUsingRawPath()
at System.Net.HttpListenerRequestUriBuilder.Build()
at System.Net.HttpListenerRequest.FinishInitialization()
at System.Net.HttpConnection.OnReadInternal(IAsyncResult ares)
at System.Net.LazyAsyncResult.Complete(IntPtr userToken)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
at System.Net.ContextAwareResult.Complete(IntPtr userToken)
at System.Net.Sockets.SocketAsyncEngine.System.Threading.IThreadPoolWorkItem.Execute()
at System.Threading.ThreadPoolWorkQueue.Dispatch()

Thanks for help

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.