添加了授权

This commit is contained in:
CortexCore
2023-09-21 03:49:27 +08:00
parent c59d513cca
commit c65fe87a6c
10 changed files with 317 additions and 20 deletions

View File

@@ -51,6 +51,7 @@ public partial class Entity : Node,IEntity
public override void _ExitTree()
{
_cancellationTokenSource.Cancel();
_entitiesService.UnRegister(this);
}
/// <summary>
@@ -95,6 +96,8 @@ public partial class Entity : Node,IEntity
this._components = entityComponents.ToArray();
SetMeta("Components",Variant.From(_components.Select(x=>x.GetType().Name).ToArray()));
}
public bool TryGetComponent<T>(out T component)
{
if (TypeComponents.TryGetValue(typeof(T), out var iComponent) && iComponent is T _component)
@@ -105,14 +108,6 @@ public partial class Entity : Node,IEntity
component = default;
return false;
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (disposing)
{
_entitiesService.UnRegister(this);
}
}
public bool RegisterComponent<T>(T component)
{

View File

@@ -0,0 +1,63 @@
using Godot;
using System;
using System.Net;
using System.Net.Http;
using BITKit.Net.Http;
using Microsoft.Extensions.DependencyInjection;
namespace BITKit.Net.Http;
public partial class HttpListener_GodotBased : EntityComponent,IHttpListenerService
{
[Export] private bool autoStart;
[Export]
private int port
{
get => _httpListenerServiceImplementation.Port;
set => _httpListenerServiceImplementation.Port = value;
}
private readonly IHttpListenerService _httpListenerServiceImplementation = new HttpListenerService();
public override void BuildService(IServiceCollection serviceCollection)
{
serviceCollection.AddSingleton<IHttpListenerService>(this);
}
public override void _Ready()
{
if (autoStart)
{
Start();
}
}
public override void _ExitTree()
{
if(IsListening)
{
Stop();
}
}
public bool IsListening => _httpListenerServiceImplementation.IsListening;
int IHttpListenerService.Port
{
get => _httpListenerServiceImplementation.Port;
set => _httpListenerServiceImplementation.Port = value;
}
event Func<HttpListenerRequest, HttpContent> IHttpListenerService.OnRequest
{
add => _httpListenerServiceImplementation.OnRequest += value;
remove => _httpListenerServiceImplementation.OnRequest -= value;
}
public void Start()
{
_httpListenerServiceImplementation.Start();
}
public void Stop()
{
_httpListenerServiceImplementation.Stop();
}
}