فهرست منبع

服务端Model跟Hotfix完全共享,DotNet相关代码挪到DotNet.App程序集

tanghai 3 سال پیش
والد
کامیت
f68d50db00

+ 2 - 1
.gitignore

@@ -67,4 +67,5 @@ Server/.DS_Store
 /Unity/ProjectSettings/RiderScriptEditorPersistedState.asset
 /Unity/Unity.Core.csproj
 /Unity/UserSettings
-/Unity/Assets/Scripts/Codes/Link/
+/Unity/Unity.Codes.csproj
+/Unity/Unity.Ignore.csproj

+ 3 - 3
DotNet/Model/CodeLoader.cs → DotNet/App/CodeLoader.cs

@@ -4,7 +4,7 @@ using System.IO;
 using System.Reflection;
 using System.Runtime.Loader;
 
-namespace ET
+namespace ET.Server
 {
     public class CodeLoader
     {
@@ -15,13 +15,13 @@ namespace ET
         public void LoadHotfix()
         {
             assemblyLoadContext?.Unload();
-            System.GC.Collect();
+            GC.Collect();
             assemblyLoadContext = new AssemblyLoadContext("Hotfix", true);
             byte[] dllBytes = File.ReadAllBytes("./Hotfix.dll");
             byte[] pdbBytes = File.ReadAllBytes("./Hotfix.pdb");
             Assembly assembly = assemblyLoadContext.LoadFromStream(new MemoryStream(dllBytes), new MemoryStream(pdbBytes));
             
-            Dictionary<string, Type> types = AssemblyHelper.GetAssemblyTypes(typeof (Game).Assembly, this.GetType().Assembly, assembly);
+            Dictionary<string, Type> types = AssemblyHelper.GetAssemblyTypes(typeof(Program).Assembly, typeof (Game).Assembly, typeof(Entry).Assembly, assembly);
 			
             Game.EventSystem.Add(types);
         }

+ 0 - 0
DotNet/Model/ConfigLoader.cs → DotNet/App/ConfigLoader.cs


+ 6 - 0
DotNet/App/DotNet.App.csproj

@@ -34,4 +34,10 @@
   <ItemGroup>
     <ProjectReference Include="..\Model\DotNet.Model.csproj" />
   </ItemGroup>
+
+  <ItemGroup>
+    <Compile Update="ReloadDllConsoleHandler.cs">
+      <Link>Server\Module\Console\ReloadDllConsoleHandler.cs</Link>
+    </Compile>
+  </ItemGroup>
 </Project>

+ 31 - 2
DotNet/App/Program.cs

@@ -1,8 +1,9 @@
 using System;
 using System.Threading;
-using ET.Server;
+using CommandLine;
+using NLog;
 
-namespace ET
+namespace ET.Server
 {
 	internal static class Program
 	{
@@ -10,6 +11,34 @@ namespace ET
 		{
 			try
 			{	
+				AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
+				{
+					Log.Error(e.ExceptionObject.ToString());
+				};
+				
+				// 异步方法全部会回掉到主线程
+				SynchronizationContext.SetSynchronizationContext(ThreadSynchronizationContext.Instance);
+			
+				
+				
+				// 命令行参数
+				Options options = null;
+				Parser.Default.ParseArguments<Options>(args)
+						.WithNotParsed(error => throw new Exception($"命令行格式错误!"))
+						.WithParsed(o => { options = o; });
+				Options.Instance = options;
+				
+				Game.ILog = new NLogger(Game.Options.AppType.ToString());
+				LogManager.Configuration.Variables["appIdFormat"] = $"{Game.Options.Process:000000}";
+				
+				ETTask.ExceptionHandler += Log.Error;
+
+				CodeLoader.Instance.LoadHotfix();
+				
+				MongoHelper.Register(Game.EventSystem.GetTypes());
+				
+				Log.Console($"app start: {Game.Scene.Id} options: {JsonHelper.ToJson(Game.Options)} ");
+				
 				Entry.Start();
 				
 				while (true)

+ 0 - 3
Unity/Assets/Scripts/Codes/Hotfix/Server/Module/Console/ReloadDllConsoleHandler.cs → DotNet/App/ReloadDllConsoleHandler.cs

@@ -1,6 +1,3 @@
-using System;
-using System.Collections.Generic;
-
 namespace ET.Server
 {
     [ConsoleHandler(ConsoleMode.ReloadDll)]

+ 0 - 4
DotNet/Model/DotNet.Model.csproj

@@ -42,10 +42,6 @@
         <Compile Include="..\..\Unity\Assets\Scripts\Codes\Model\Generate\Server\**\*.cs">
             <Link>Generate\%(RecursiveDir)%(FileName)%(Extension)</Link>
         </Compile>
-
-        <Compile Update="ConfigLoader.cs">
-          <Link>Server\Module\Config\ConfigLoader.cs</Link>
-        </Compile>
         
     </ItemGroup> 
     <ItemGroup> 

+ 7 - 5
README.md

@@ -14,11 +14,13 @@
 
 # ET7开发中,使用master分支,ET6改成release6.0分支
 1. 调整结构,机器人工程与服务器合并,更易使用,一个进程同时可以做server,也能创建机器人,真正的ALL IN ONE! -- 已实现  
-2. 增加软路由,可以防各种网络攻击而不影响正常玩家,网游必备!-- 已实现  
-3. 各种事件跟网络消息订阅带上DomainSceneType,更精确,更不容易出错 -- 已实现  
-4. sj兄弟添加了各种分析器,分析器保证了写出的代码必须符合ET规范,否则编译不通过!(这点ET6也增加上了) -- 已实现  
-5. 利用Linux fork写时复制的机制减少配置文件内存占用(可能GC整理内存会走不通,待研究)-- 暂未实现  
-6. ET7已经去除热更新,请大家自己选择接入,接入huatuo或者ILRuntime都非常简单  
+2. 客户端跟服务端合并,服务端代码全部放在了客户端,客户端中可以带一个服务端,开发超级方便,发布的时候可以选择发布成Dotnet也可以发布成UnityServer,终极All IN ONE  --已实现  
+3. 所有代码都在Unity中,所以开发ET插件变得非常容易,直接使用Unity导入导出即可  -- 已实现  
+4. 增加软路由,可以防各种网络攻击而不影响正常玩家,网游必备!-- 已实现  
+5. 各种事件跟网络消息订阅带上DomainSceneType,更精确,更不容易出错 -- 已实现  
+6. sj兄弟添加了各种分析器,分析器保证了写出的代码必须符合ET规范,否则编译不通过!(这点ET6也增加上了) -- 已实现  
+7. 利用Linux fork写时复制的机制减少配置文件内存占用(可能GC整理内存会走不通,待研究)-- 暂未实现  
+8. ET7已经去除热更新,请大家自己选择接入,接入huatuo或者ILRuntime都非常简单  
 
 
 

+ 0 - 11
Unity/Assets/Scripts/Codes/Hotfix/Server/Module/Console/ReloadDllConsoleHandler.cs.meta

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

+ 1 - 36
Unity/Assets/Scripts/Codes/Model/Server/Entry.cs

@@ -1,10 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Threading;
-using CommandLine;
-using NLog;
-
-namespace ET.Server
+namespace ET.Server
 {
     public static class Entry
     {
@@ -15,35 +9,6 @@ namespace ET.Server
         
         private static async ETTask StartAsync()
         {
-            AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
-            {
-                Log.Error(e.ExceptionObject.ToString());
-            };
-			
-            ETTask.ExceptionHandler += Log.Error;
-
-            // 异步方法全部会回掉到主线程
-            SynchronizationContext.SetSynchronizationContext(ThreadSynchronizationContext.Instance);
-            
-            CodeLoader.Instance.LoadHotfix();
-				
-            MongoHelper.Register(Game.EventSystem.GetTypes());
-
-            string[] args = System.Environment.GetCommandLineArgs();
-            
-            // 命令行参数
-            Options options = null;
-            Parser.Default.ParseArguments<Options>(args)
-                .WithNotParsed(error => throw new Exception($"命令行格式错误!"))
-                .WithParsed(o => { options = o; });
-
-            Options.Instance = options;
-
-            Game.ILog = new NLogger(Game.Options.AppType.ToString());
-            LogManager.Configuration.Variables["appIdFormat"] = $"{Game.Options.Process:000000}";
-				
-            Log.Console($"app start: {Game.Scene.Id} options: {JsonHelper.ToJson(Game.Options)} ");
-            
             await Game.EventSystem.Callback<ETTask>(CallbackType.InitShare);
             await Game.EventSystem.Callback<ETTask>(CallbackType.InitServer);
         }

+ 0 - 63
Unity/Unity.Codes.csproj

@@ -1,63 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
-  <PropertyGroup>
-    <LangVersion>9.0</LangVersion>
-    <_TargetFrameworkDirectories>non_empty_path_generated_by_unity.rider.package</_TargetFrameworkDirectories>
-    <_FullFrameworkReferenceAssemblyPaths>non_empty_path_generated_by_unity.rider.package</_FullFrameworkReferenceAssemblyPaths>
-    <DisableHandlePackageFileConflicts>true</DisableHandlePackageFileConflicts>
-  </PropertyGroup>
-  <PropertyGroup>
-    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
-    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
-    <ProductVersion>10.0.20506</ProductVersion>
-    <SchemaVersion>2.0</SchemaVersion>
-    <RootNamespace></RootNamespace>
-    <ProjectGuid>{c8cdb918-7f4f-0e46-c7aa-900f18d8c944}</ProjectGuid>
-    <ProjectTypeGuids>{E097FAD1-6243-4DAD-9C02-E9B9EFC3FFC1};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
-    <OutputType>Library</OutputType>
-    <AppDesignerFolder>Properties</AppDesignerFolder>
-    <AssemblyName>Unity.Codes</AssemblyName>
-    <TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
-    <FileAlignment>512</FileAlignment>
-    <BaseDirectory>.</BaseDirectory>
-  </PropertyGroup>
-  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
-    <DebugSymbols>true</DebugSymbols>
-    <DebugType>full</DebugType>
-    <Optimize>false</Optimize>
-    <OutputPath>Temp\Bin\Debug\Unity.Rider.Editor\</OutputPath>
-    <DefineConstants>UNITY_EDITOR</DefineConstants>
-    <ErrorReport>prompt</ErrorReport>
-    <WarningLevel>4</WarningLevel>
-    <NoWarn>0169,0649</NoWarn>
-    <AllowUnsafeBlocks>False</AllowUnsafeBlocks>
-    <TreatWarningsAsErrors>False</TreatWarningsAsErrors>
-  </PropertyGroup>
-  <PropertyGroup>
-    <NoConfig>true</NoConfig>
-    <NoStdLib>true</NoStdLib>
-    <AddAdditionalExplicitAssemblyReferences>false</AddAdditionalExplicitAssemblyReferences>
-    <ImplicitlyExpandNETStandardFacades>false</ImplicitlyExpandNETStandardFacades>
-    <ImplicitlyExpandDesignTimeFacades>false</ImplicitlyExpandDesignTimeFacades>
-  </PropertyGroup>
-  <ItemGroup>
-     <None Include="Assets\Scripts\Codes\Unity.Codes.asmdef" />
-     <Reference Include="UnityEngine">
-     <HintPath>C:\Apps\Unity\2021.3.6f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.dll</HintPath>
-     </Reference>
-     <Reference Include="UnityEngine.CoreModule">
-     <HintPath>C:\Apps\Unity\2021.3.6f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.dll</HintPath>
-     </Reference>
-     <Reference Include="UnityEditor">
-     <HintPath>C:\Apps\Unity\2021.3.6f1c1\Editor\Data\Managed\UnityEngine\UnityEditor.dll</HintPath>
-     </Reference>
-  </ItemGroup>
-  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
-  <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
-       Other similar extension points exist, see Microsoft.Common.targets.
-  <Target Name="BeforeBuild">
-  </Target>
-  <Target Name="AfterBuild">
-  </Target>
-  -->
-</Project>

+ 0 - 63
Unity/Unity.Ignore.csproj

@@ -1,63 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
-  <PropertyGroup>
-    <LangVersion>9.0</LangVersion>
-    <_TargetFrameworkDirectories>non_empty_path_generated_by_unity.rider.package</_TargetFrameworkDirectories>
-    <_FullFrameworkReferenceAssemblyPaths>non_empty_path_generated_by_unity.rider.package</_FullFrameworkReferenceAssemblyPaths>
-    <DisableHandlePackageFileConflicts>true</DisableHandlePackageFileConflicts>
-  </PropertyGroup>
-  <PropertyGroup>
-    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
-    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
-    <ProductVersion>10.0.20506</ProductVersion>
-    <SchemaVersion>2.0</SchemaVersion>
-    <RootNamespace></RootNamespace>
-    <ProjectGuid>{3ef4bf99-c919-797e-1d1a-53f1c3d27f6d}</ProjectGuid>
-    <ProjectTypeGuids>{E097FAD1-6243-4DAD-9C02-E9B9EFC3FFC1};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
-    <OutputType>Library</OutputType>
-    <AppDesignerFolder>Properties</AppDesignerFolder>
-    <AssemblyName>Unity.Ignore</AssemblyName>
-    <TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
-    <FileAlignment>512</FileAlignment>
-    <BaseDirectory>.</BaseDirectory>
-  </PropertyGroup>
-  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
-    <DebugSymbols>true</DebugSymbols>
-    <DebugType>full</DebugType>
-    <Optimize>false</Optimize>
-    <OutputPath>Temp\Bin\Debug\Unity.Rider.Editor\</OutputPath>
-    <DefineConstants>UNITY_EDITOR</DefineConstants>
-    <ErrorReport>prompt</ErrorReport>
-    <WarningLevel>4</WarningLevel>
-    <NoWarn>0169,0649</NoWarn>
-    <AllowUnsafeBlocks>False</AllowUnsafeBlocks>
-    <TreatWarningsAsErrors>False</TreatWarningsAsErrors>
-  </PropertyGroup>
-  <PropertyGroup>
-    <NoConfig>true</NoConfig>
-    <NoStdLib>true</NoStdLib>
-    <AddAdditionalExplicitAssemblyReferences>false</AddAdditionalExplicitAssemblyReferences>
-    <ImplicitlyExpandNETStandardFacades>false</ImplicitlyExpandNETStandardFacades>
-    <ImplicitlyExpandDesignTimeFacades>false</ImplicitlyExpandDesignTimeFacades>
-  </PropertyGroup>
-  <ItemGroup>
-     <None Include="Assets\Scripts\Codes\Model\Generate\Client\Unity.Ignore.asmdef" />
-     <Reference Include="UnityEngine">
-     <HintPath>C:\Apps\Unity\2021.3.6f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.dll</HintPath>
-     </Reference>
-     <Reference Include="UnityEngine.CoreModule">
-     <HintPath>C:\Apps\Unity\2021.3.6f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.dll</HintPath>
-     </Reference>
-     <Reference Include="UnityEditor">
-     <HintPath>C:\Apps\Unity\2021.3.6f1c1\Editor\Data\Managed\UnityEngine\UnityEditor.dll</HintPath>
-     </Reference>
-  </ItemGroup>
-  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
-  <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
-       Other similar extension points exist, see Microsoft.Common.targets.
-  <Target Name="BeforeBuild">
-  </Target>
-  <Target Name="AfterBuild">
-  </Target>
-  -->
-</Project>