FactoryServerApi
1.0.0
Uma implementação do arquivo de documentação da API de servidor dedicado dedicado, UDP e HTTP.
É integrado ao host genérico e totalmente assíncrono.
O ponto de entrada do UDP IFactoryServerUdpClient , obtido de uma fábrica IFactoryServerUdpClientFactory , um exemplo de uso
var builder = Host . CreateApplicationBuilder ( args ) ;
builder . AddFactoryServerServices ( ) ;
var app = builder . Build ( ) ;
var factoryUdpClientFactory = app . Services . GetRequiredService < IFactoryServerUdpClientFactory > ( ) ;
var factoryUdpClient = await factoryUdpClientFactory . BuildFactoryServerUdpServiceAsync ( "urlOrIPAddress" , port ) ;
factoryUdpClient . ServerStateReceived += FactoryUdpClient_ServerStateReceived ;
factoryUdpClient . ErrorOccurred += FactoryUdpClient_ErrorOccurred ;
var listenerCTS = new CancellationTokenSource ( ) ;
_ = factoryUdpClient . StartListeningAsync ( listenerCTS . Token ) ;
var pollTask = factoryUdpClient . PollServerStateAsync ( TimeSpan . FromMinutes ( 3 ) , TimeSpan . FromSeconds ( 10 ) , false , 1 , null ) ;
while ( ! pollTask . IsCompleted ) {
}
listenerCTS . Cancel ( ) ;
return 0 ;
private static void FactoryUdpClient_ErrorOccurred ( object ? sender , Exception e )
{
.. .
}
private static void FactoryUdpClient_ServerStateReceived ( object ? sender , FactoryServerStateResponse e )
{
var json = JsonSerializer . Serialize ( e ) ;
.. .
} O ponto de entrada HTTP IFactoryServerHttpService , um exemplo de uso
var builder = Host . CreateApplicationBuilder ( args ) ;
builder . AddFactoryServerServices ( ) ;
var app = builder . Build ( ) ;
var factoryServer = app . Services . GetRequiredService < IFactoryServerHttpService > ( ) ;
//Here in connection info you can set the AuthenticationToken provided for the login functions or third party tokens provided by server
var connectionInfo = new FactoryServerConnectionInfo ( "https_url" , port ) ;
var result = await factoryServer . HealthCheckAsync ( null , connectionInfo ) ;
string ? json = null ;
if ( result . Result is not null )
{
json = JsonSerializer . Serialize ( result . Result ) ;
}
else if ( result . Error is not null )
{
json = JsonSerializer . Serialize ( result . Error ) ;
}Eu sou novo nisso e fiz isso como um hobby para gerenciar remotamente um servidor com meus amigos, não seja duro.
Sinta -se à vontade para criar problemas para bugs e melhorias ou garfo.