[+] 接入ET8服务端

[+] 接入ET8服务端
This commit is contained in:
ALEXTANG
2023-07-13 12:23:48 +08:00
parent e0be062006
commit 336d4b2eb9
1316 changed files with 130657 additions and 626 deletions

View File

@@ -0,0 +1,14 @@
using System.Collections.Generic;
using System.Net;
namespace ET.Server
{
/// <summary>
/// http请求分发器
/// </summary>
[ComponentOf(typeof(Scene))]
public class HttpComponent: Entity, IAwake<string>, IDestroy
{
public HttpListener Listener;
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e0de2584d06993846b20ba44c51b8a0b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
namespace ET.Server
{
public class HttpDispatcher: SingletonLock<HttpDispatcher>, ISingletonAwake
{
private readonly Dictionary<string, Dictionary<int, IHttpHandler>> dispatcher = new();
public override void Load()
{
World.Instance.AddSingleton<HttpDispatcher>();
}
public void Awake()
{
HashSet<Type> types = EventSystem.Instance.GetTypes(typeof (HttpHandlerAttribute));
foreach (Type type in types)
{
object[] attrs = type.GetCustomAttributes(typeof(HttpHandlerAttribute), false);
if (attrs.Length == 0)
{
continue;
}
HttpHandlerAttribute httpHandlerAttribute = (HttpHandlerAttribute)attrs[0];
object obj = Activator.CreateInstance(type);
IHttpHandler ihttpHandler = obj as IHttpHandler;
if (ihttpHandler == null)
{
throw new Exception($"HttpHandler handler not inherit IHttpHandler class: {obj.GetType().FullName}");
}
if (!this.dispatcher.TryGetValue(httpHandlerAttribute.Path, out var dict))
{
dict = new Dictionary<int, IHttpHandler>();
this.dispatcher.Add(httpHandlerAttribute.Path, dict);
}
dict.Add((int)httpHandlerAttribute.SceneType, ihttpHandler);
}
}
public IHttpHandler Get(SceneType sceneType, string path)
{
return this.dispatcher[path][(int)sceneType];
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5f32ee5a97327b54dad8859600342649
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,15 @@
namespace ET.Server
{
public class HttpHandlerAttribute: BaseAttribute
{
public SceneType SceneType { get; }
public string Path { get; }
public HttpHandlerAttribute(SceneType sceneType, string path)
{
this.SceneType = sceneType;
this.Path = path;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 536bf765aeb46c44e9d0618fb418c76a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,9 @@
using System.Net;
namespace ET.Server
{
public interface IHttpHandler
{
ETTask Handle(Scene scene, HttpListenerContext context);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 850082c851b74ff419893672cb613cf3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: