Code/Net/Exceptions/NoAuthorityException.cs
using Sandbox;
using System;
using System.Linq;

namespace ExtendedBox.Net.Exceptions;

public sealed class NoAuthorityException : Exception
{
    public NoAuthorityException(string message) : base(message)
    {

    }

    public static void ThrowIfNotHost()
    {
        if(!Connection.Local.IsHost)
            throw new NoAuthorityException("Local connection is not host.");
    }

    public static void ThrowIfProxy(GameObject gameObject)
    {
        if(gameObject.IsProxy)
            throw new NoAuthorityException("Can't execute if proxy.");
    }

    public static void ThrowIfProxy(Component component)
    {
        if(component.IsProxy)
            throw new NoAuthorityException("Can't execute if proxy.");
    }

    public static void ThrowIfWrongRpcCaller(params Connection?[] rightCallers)
    {
        ThrowIfNotHost();
        if(rightCallers.Contains(Rpc.Caller))
            return;

        throw new NoAuthorityException($"Can't do this rpc by {Rpc.Caller}.");
    }
}