qq362946 / fantasy Goto Github PK
View Code? Open in Web Editor NEWC # Game Framework, but not limited to games. Can be used for non game business development
Home Page: https://www.fantsida.com/fantasy
License: MIT License
C # Game Framework, but not limited to games. Can be used for non game business development
Home Page: https://www.fantsida.com/fantasy
License: MIT License
添加一个获取所有属性名的函数:
public PropertyInfo[] GetProperties()
{
var t = typeof((ConfigName));
return t.GetProperties();
}
方便通过属性名去获取值。
案例:
多语言文档遍历数据到字典的子字典。
var localizationList = LocalizationData.Instance.List;
_phrases = new Dictionary<string, Dictionary<string, string>>(0);
// 获得类的所有属性名
var lang = LocalizationData.Instance.GetProperties();
for (var i = 2; i < lang.Length; i++)
{
var p = new Dictionary<string, string>();
for (var j = 0; j < localizationList.Count; j++)
{
var local = localizationList[j];
// 通过属性名去获取对于的值
var localProperty = local.GetType().GetProperty(lang[i].Name);
if (localProperty == null) return;
var value = localProperty.GetValue(local, null);
p.Add(localizationList[j].Key, value.ToString());
}
_phrases.Add(lang[i].Name.Insert(2, "-").ToLower(), p);
}
TCP连接的话,无参数的协议或者参数没赋值,服务端没反应。(例如心跳,所以说现在采用TCP连接的话,网络接连过几秒就断开了。。)
如题
去掉
<PackageReference Include="EPPlus" Version="6.2.10" />
换成
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
public class OnCreateScene : AsyncEventSystem<Fantasy.OnCreateScene>
{
public override async FTask Handler(Fantasy.OnCreateScene self)
{
// 服务器是以Scene为单位的、所以Scene下有什么组件都可以自己添加定义
// OnCreateScene这个事件就是给开发者使用的
// 比如Address协议这里、我就是做了一个管理Address地址的一个组件挂在到Address这个Scene下面了
// 比如Hall下你需要一些自定义组件、你也可以在这里操作
var scene = self.Scene;
switch (scene.SceneType)
{
case SceneType.Addressable:
// 挂载管理Address地址组件
scene.AddComponent<AddressableManageComponent>();
Log.Debug($"创建 Addressable 场景完成 {scene.SceneType}");
break;
case SceneType.Chat:
scene.AddComponent<ChatUnitManagerComponent>();
Log.Debug($"创建 Chat 场景完成 {scene.SceneType}");
break;
case SceneType.Hall:
scene.AddComponent<HallUnitManagerComponent>();
Log.Debug($"创建 Hall 场景完成 {scene.SceneType}");
break;
case SceneType.Gate:
scene.AddComponent<GateUnitManagerComponent>();
Log.Debug($"创建 Gate 场景完成 {scene.SceneType}");
break;
}
await FTask.CompletedTask;
}
}
public class OnServerStartComplete : AsyncEventSystem<Fantasy.OnServerStartComplete>
{
public override async FTask Handler(Fantasy.OnServerStartComplete self)
{
var scene = self.Server.Scene;
Log.Debug($"启动服务器完成 {scene.SceneType}");
await FTask.CompletedTask;
}
}
Active code page: 65001
2024-05-18 17:57:03.6143 NetworkProtocol:KCP IPEndPoint:127.0.0.1:11001
2024-05-18 17:57:04.3450 NetworkProtocol:KCP IPEndPoint:127.0.0.1:20000
2024-05-18 17:57:04.3450 创建 Gate 场景完成 1
2024-05-18 17:57:04.3450 启动服务器完成 0
2024-05-18 17:57:04.3450 ServerId:1025 is start complete
2024-05-18 17:57:04.3450 NetworkProtocol:KCP IPEndPoint:127.0.0.1:11002
2024-05-18 17:57:04.3450 创建 Addressable 场景完成 2
2024-05-18 17:57:04.3450 启动服务器完成 0
2024-05-18 17:57:04.3450 ServerId:2049 is start complete
2024-05-18 17:57:04.3450 NetworkProtocol:KCP IPEndPoint:127.0.0.1:11003
2024-05-18 17:57:04.3450 创建 Hall 场景完成 3
2024-05-18 17:57:04.3450 启动服务器完成 0
2024-05-18 17:57:04.3450 ServerId:3073 is start complete
2024-05-18 17:57:04.3450 NetworkProtocol:KCP IPEndPoint:127.0.0.1:11004
2024-05-18 17:57:04.3450 启动服务器完成 0
2024-05-18 17:57:04.3450 ServerId:4097 is start complete
2024-05-18 17:57:04.3450 NetworkProtocol:KCP IPEndPoint:127.0.0.1:11005
2024-05-18 17:57:04.3450 创建 Chat 场景完成 5
2024-05-18 17:57:04.3450 启动服务器完成 0
2024-05-18 17:57:04.3450 ServerId:5121 is start complete
为什么启动时的地方,SceneType 为 0
由于是在开发模式下,在调用session.Scene.NetworkMessagingComponent.CallInnerRoute
时,Scene.GetSession
里面会因为判断到目标Scene
在同一个Process
下从而创建了一个ServerInnerSession
。
接着客户端再发送一个AddressableRPC
消息,这时候会调用到NetworkMessagingComponent.CallInnerRoute(long entityId, long routeTypeOpCode, Type requestType, MemoryStream request)
方法,方法里面var session = Scene.GetSession(entityId);
拿到的是ServerInnerSession
。ServerInnerSession
对象调用public override void Send(MemoryStream memoryStream, uint rpcId = 0, long routeTypeOpCode = 0, long routeId = 0)
,这里面没有对消息进行解析,导致无法处理AddressableRPC
消息。
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DefineConstants>TRACE;FANTASY_NET</DefineConstants>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<NoWarn>1701;1702;IL2121;CS8603;IL2121;CS8625;IL2121;CS8618;CS8622;CS8632;CS8602;CS8603;CS8600;CS8625;CS8600;;CS8604;CS8601;SYSLIB0023</NoWarn>
</PropertyGroup>
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.