Libraries

s&box libraries

Orizon Rpc

orizon.orizon_rpc

A simple library to call rpc's and receive a response callback

About

// Your data model
public struct YourData
{
public SteamId SteamId { get; set; }
public string FirstName { get; set;}
}

// Create your struct request
private record struct GetDataRequest : IRpcRequest
{
public Guid CallbackId { get; set; }
public int DataId { get; set; }
}

// Create your struct response
private record struct GetDataResponse : IRpcResponse
{
public Guid CallbackId { get; set; }
public YourData Data { get; set; }
}

// Called on the host
private static GetDataResponse OnGetDataRequest( GetDataRequest request )
{
// Do your work here and return the result
var data = ...

return new GetDataResponse { Data = data };
}
In your custom script, e.g Character.cs
// Register your rpc callback here
protected override void OnStart()
{
if ( IsProxy ) return;

RpcServer.RegisterHandler<GetDataRequest, GetDataResponse>( OnGetDataRequest );
}

// Call this function on the client to get your data
public static async Task<YourData> GetDataAsync( int dataId )
{
var request = new GetDataRequest { DataId = dataId };

// Your data is store in the result variable
var result = await RpcClient.SendRpc<GetDataRequest, GetDataResponse>( request );
return result.Data;
}

callbacknetworkingrpc

More by orizon

01
Mongo Rest thumbnail
Mongo Rest orizon.mongo_rest

MongoRest transforms MongoDB into a generic RESTful API for simplified CRUD operations

apidatabasemongodbrest
+0 24h
0favorites
2upvotes
34%Wilson score