Code/HostOnlyHelper.cs
using System;
using System.Linq;
using Sandbox;
namespace Orizon;
internal static class HostOnlyHelper
{
private static void EnsureHost( bool isRpc )
{
if ( !Networking.IsHost && (Networking.IsHost || !isRpc) )
throw new Exception( "Only the client can call this method" );
}
internal static void __host_only_wrapper( WrappedMethod m, params object[] args )
{
var isRpc = m.Attributes.Any( x => x is RpcAttribute );
EnsureHost( isRpc );
m.Resume();
}
internal static T __host_only_wrapper<T>( WrappedMethod<T> m, params object[] args )
{
var isRpc = m.Attributes.Any( x => x is RpcAttribute );
EnsureHost( isRpc );
return m.Resume();
}
}