Skip to content

Latest commit

 

History

History
64 lines (43 loc) · 1.73 KB

File metadata and controls

64 lines (43 loc) · 1.73 KB

RakSharp

Note

This RakNet was created primarily to help develop Lantern, feel free to find bugs or improvements!

How To Use

using System.Net;
using RakSharp;

var address = new IPEndPoint(IPAddress.Any, 19132);
var server = new Server(address);

await server.Start();

Wait... you don't like how we handle the packets? Good! Then you can write your own handler.

using System.Net;
using RakSharp;
using RakSharp.Protocol.Offline;

var address = new IPEndPoint(IPAddress.Any, 19132);
var server = new Server(address);

server.HandlerSystem.RegisterHandler<UnconnectedPing, MyCustomUnconnectedPingHandler>();

await server.Start();
// Example Code: MyCustomUnconnectedPingHandler

using System.Net;
using RakSharp.Protocol.Offline;
using RakSharp.Utils;

namespace YourProject;

public class MyCustomUnconnectedPingHandler : OfflinePacketHandler<UnconnectedPing> {
    
    public override async Task<bool> HandleAsync() {

        Server.ServerInfo.OnlinePlayers = Server.SessionsManager.GetSessions().Count; // Maybe instead of this, you can do your own things, like:

        Server.ServerInfo.OnlinePlayers = 69 // Funny number, or you can do this:

        Server.ServerInfo.OnlinePlayers = Random.Shared.Next(0, 100); // Wow, a random players counter!

        var response = UnconnectedPong.Create(
            Packet.Timestamp, 
            Server.ServerInfo.ServerGuid, 
            Server.ServerInfo.ToString()
        );
        
        await SendOfflineMessageAsync(response);
        return true;
    }
}

This was just an example of how you could use our RakNet, it has a lot of potential :)