Skip to content

Commit 5aaab3f

Browse files
committed
[同步]1. 同步到1.3.0-beta1 版本
1 parent 6845ad6 commit 5aaab3f

27 files changed

+271
-224
lines changed

GameFrameX.Apps/Common/Session/Session.cs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using GameFrameX.NetWork.Abstractions;
1+
using System.Text.Json.Serialization;
2+
using System.Threading.Tasks;
3+
using GameFrameX.NetWork.Abstractions;
24
using GameFrameX.NetWork.Messages;
35

46
namespace GameFrameX.Apps.Common.Session;
@@ -35,6 +37,7 @@ public Session(string sessionId, INetWorkChannel netWorkChannel)
3537
/// <summary>
3638
/// 连接上下文
3739
/// </summary>
40+
[JsonIgnore]
3841
public INetWorkChannel WorkChannel { get; }
3942

4043
/// <summary>
@@ -60,21 +63,12 @@ public void SetSign(string sign)
6063
Sign = sign;
6164
}
6265

63-
/// <summary>
64-
/// 发送消息
65-
/// </summary>
66-
/// <param name="messageObject">消息对象</param>
67-
public void Write(MessageObject messageObject)
68-
{
69-
WorkChannel?.Write(messageObject);
70-
}
71-
7266
/// <summary>
7367
/// 发送消息
7468
/// </summary>
7569
/// <param name="messageObject">消息对象</param>
7670
/// <param name="errorCode">消息错误码</param>
77-
public async void WriteAsync(MessageObject messageObject, int errorCode = 0)
71+
public async Task WriteAsync(MessageObject messageObject, int errorCode = 0)
7872
{
7973
if (WorkChannel != null)
8074
{

GameFrameX.Apps/GameFrameX.Apps.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
</ItemGroup>
1818

1919
<ItemGroup>
20-
<PackageReference Include="GameFrameX.Core" Version="1.2.0-beta22" />
21-
<PackageReference Include="GameFrameX.Monitor" Version="1.2.0-beta22" />
20+
<PackageReference Include="GameFrameX.Core" Version="1.3.0-beta1" />
21+
<PackageReference Include="GameFrameX.Monitor" Version="1.3.0-beta1" />
2222
</ItemGroup>
2323
</Project>

GameFrameX.CodeGenerator/Agent/AgentTemplate.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ namespace GameFrameX.CodeGenerator.Agent;
44

55
public static class AgentTemplate
66
{
7-
private static readonly StringBuilder TemplateStringBuilder = new StringBuilder();
7+
private static readonly StringBuilder TemplateStringBuilder = new();
88

99
public static string Run(AgentInfo info)
1010
{
@@ -43,7 +43,7 @@ public static string Run(AgentInfo info)
4343
else
4444
{
4545
TemplateStringBuilder.AppendLine("\t\t\t(bool needEnqueue, long chainId)= base.Actor.WorkerActor.IsNeedEnqueue();");
46-
TemplateStringBuilder.AppendLine($"\t\t\tif (!needEnqueue)");
46+
TemplateStringBuilder.AppendLine("\t\t\tif (!needEnqueue)");
4747
TemplateStringBuilder.AppendLine("\t\t\t{");
4848
TemplateStringBuilder.AppendLine($"\t\t\t\treturn {(infoMethod.IsAsync ? "await " : string.Empty)} base.{infoMethod.Name}{infoMethod.Typeparams}({infoMethod.ParamString});");
4949
TemplateStringBuilder.AppendLine("\t\t\t}");

GameFrameX.CodeGenerator/GameFrameX.CodeGenerator.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
</PropertyGroup>
1818

1919
<ItemGroup>
20-
<PackageReference Include="GameFrameX.Core" Version="1.2.0-beta22" />
20+
<PackageReference Include="GameFrameX.Core" Version="1.3.0-beta1" />
2121
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.3">
2222
<PrivateAssets>all</PrivateAssets>
2323
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

GameFrameX.Config/ConfigComponent.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ namespace GameFrameX.Config;
66

77
public class ConfigComponent
88
{
9-
public static ConfigComponent Instance { get; } = new ConfigComponent();
109
private readonly ConfigManager _configManager;
1110

1211
private ConfigComponent()
@@ -15,15 +14,17 @@ private ConfigComponent()
1514
Tables = new TablesComponent();
1615
}
1716

18-
private TablesComponent Tables { get; set; }
17+
public static ConfigComponent Instance { get; } = new();
18+
19+
private TablesComponent Tables { get; }
1920

2021
public async void LoadConfig()
2122
{
2223
Tables.Init(Instance);
23-
LogHelper.Info($"Load Config Start...");
24+
LogHelper.Info("Load Config Start...");
2425
Instance.RemoveAllConfigs();
2526
await Tables.LoadAsync(Loader);
26-
LogHelper.Info($"Load Config End...");
27+
LogHelper.Info("Load Config End...");
2728
LogHelper.Info("== load success ==");
2829
}
2930

@@ -36,7 +37,7 @@ private static async Task<ByteBuf> Loader(string file, bool tag)
3637
private static async Task<JsonElement> Loader(string file)
3738
{
3839
var configJson = await File.ReadAllTextAsync($"json/{file}.json");
39-
JsonElement jsonElement = JsonDocument.Parse(configJson).RootElement;
40+
var jsonElement = JsonDocument.Parse(configJson).RootElement;
4041
return jsonElement;
4142
}
4243

GameFrameX.Config/ConfigManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public bool HasConfig(string configName)
4545
/// <returns>是否增加全局配置项成功。</returns>
4646
public void AddConfig(string configName, IDataTable configValue)
4747
{
48-
bool isExist = m_ConfigDatas.TryGetValue(configName, out var value);
48+
var isExist = m_ConfigDatas.TryGetValue(configName, out var value);
4949
if (isExist)
5050
{
5151
return;

GameFrameX.Config/GameFrameX.Config.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<TargetFramework>net8.0</TargetFramework>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>disable</Nullable>
7+
<LangVersion>10</LangVersion>
78
</PropertyGroup>
89

910
<ItemGroup>
@@ -13,8 +14,8 @@
1314
</ItemGroup>
1415

1516
<ItemGroup>
16-
<PackageReference Include="GameFrameX.Core.Config" Version="1.2.0-beta22" />
17-
<PackageReference Include="GameFrameX.Utility" Version="1.2.0-beta22" />
17+
<PackageReference Include="GameFrameX.Core.Config" Version="1.3.0-beta1" />
18+
<PackageReference Include="GameFrameX.Utility" Version="1.3.0-beta1" />
1819
</ItemGroup>
1920

2021
</Project>
Lines changed: 49 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,70 @@
11
using GameFrameX.Apps.Common.Event;
2-
using GameFrameX.Core.Abstractions;
32
using GameFrameX.Core.Abstractions.Agent;
43
using GameFrameX.Core.Abstractions.Events;
54
using GameFrameX.Hotfix.Logic.Server.Server;
65
using GameFrameX.Utility.Extensions;
6+
using GameFrameX.Utility.Log;
77
using GameFrameX.Utility.Setting;
88

9-
namespace GameFrameX.Hotfix.Common.Events
9+
namespace GameFrameX.Hotfix.Common.Events;
10+
11+
public static class EventDispatcherExtensions
1012
{
11-
public static class EventDispatcherExtensions
13+
public static void Dispatch(this IComponentAgent agent, int evtId, Param args = null)
1214
{
13-
public static void Dispatch(this IComponentAgent agent, int evtId, Param args = null)
15+
var evt = new Event
1416
{
15-
var evt = new Event
16-
{
17-
EventId = evtId,
18-
Data = args
19-
};
17+
EventId = evtId,
18+
Data = args,
19+
};
2020

21-
// 自己处理
22-
SelfHandle(agent, evtId, evt);
21+
// 自己处理
22+
SelfHandle(agent, evtId, evt);
23+
24+
if ((EventId)evtId > EventId.RoleSeparator && agent.OwnerType > GlobalConst.ActorTypeSeparator)
25+
{
26+
// 全局非玩家事件,抛给所有玩家
27+
agent.Tell(()
28+
=>
29+
{
30+
return ServerComponentAgent.OnlineRoleForeach(role
31+
=>
32+
{
33+
role.Dispatch(evtId, args);
34+
});
35+
});
36+
}
37+
}
2338

24-
if ((EventId)evtId > EventId.RoleSeparator && agent.OwnerType > GlobalConst.ActorTypeSeparator)
39+
private static void SelfHandle(IComponentAgent agent, int evtId, Event evt)
40+
{
41+
agent.Tell(async () =>
42+
{
43+
// 事件需要在本actor内执行,不可多线程执行,所以不能使用Task.WhenAll来处理
44+
var listeners = HotfixManager.FindListeners(agent.OwnerType, evtId);
45+
if (listeners.IsNullOrEmpty())
2546
{
26-
// 全局非玩家事件,抛给所有玩家
27-
agent.Tell(()
28-
=> ServerComponentAgent.OnlineRoleForeach(role
29-
=> role.Dispatch(evtId, args)));
47+
// Log.Warn($"事件:{(EventID)evtId} 没有找到任何监听者");
48+
return;
3049
}
3150

32-
static void SelfHandle(IComponentAgent agent, int evtId, Event evt)
51+
foreach (var listener in listeners)
3352
{
34-
agent.Tell(async () =>
53+
var comp = await agent.GetComponentAgent(listener.AgentType);
54+
try
3555
{
36-
// 事件需要在本actor内执行,不可多线程执行,所以不能使用Task.WhenAll来处理
37-
var listeners = HotfixManager.FindListeners(agent.OwnerType, evtId);
38-
if (listeners.IsNullOrEmpty())
39-
{
40-
// Log.Warn($"事件:{(EventID)evtId} 没有找到任何监听者");
41-
return;
42-
}
43-
44-
foreach (var listener in listeners)
45-
{
46-
var comp = await agent.GetComponentAgent(listener.AgentType);
47-
await listener.HandleEvent(comp, evt);
48-
}
49-
});
56+
await listener.HandleEvent(comp, evt);
57+
}
58+
catch (Exception exception)
59+
{
60+
LogHelper.Error(exception);
61+
}
5062
}
51-
}
63+
});
64+
}
5265

53-
public static void Dispatch(this IComponentAgent agent, EventId evtId, Param args = null)
54-
{
55-
Dispatch(agent, (int)evtId, args);
56-
}
66+
public static void Dispatch(this IComponentAgent agent, EventId evtId, Param args = null)
67+
{
68+
Dispatch(agent, (int)evtId, args);
5769
}
5870
}
Lines changed: 49 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,52 @@
1-
namespace GameFrameX.Hotfix.Common
1+
namespace GameFrameX.Hotfix.Common;
2+
3+
/// <summary>
4+
/// 操作状态码=>服务器错误码
5+
/// </summary>
6+
public enum OperationStatusCode
27
{
38
/// <summary>
4-
/// 操作状态码=>服务器错误码
5-
/// </summary>
6-
public enum OperationStatusCode
7-
{
8-
/// <summary>
9-
/// 成功
10-
/// </summary>
11-
Success = 0,
12-
13-
/// <summary>
14-
/// 配置表错误
15-
/// </summary>
16-
ConfigErr = 400,
17-
18-
/// <summary>
19-
/// 客户端传递参数错误
20-
/// </summary>
21-
ParamErr,
22-
23-
/// <summary>
24-
/// 消耗不足
25-
/// </summary>
26-
CostNotEnough,
27-
28-
/// <summary>
29-
/// 账号不存在或为空
30-
/// </summary>
31-
AccountCannotBeNull,
32-
33-
/// <summary>
34-
/// 未知平台
35-
/// </summary>
36-
UnknownPlatform,
37-
38-
/// <summary>
39-
/// 正常通知
40-
/// </summary>
41-
Notice = 100000,
42-
43-
/// <summary>
44-
/// 功能未开启,主消息屏蔽
45-
/// </summary>
46-
FuncNotOpen,
47-
48-
/// <summary>
49-
/// 其他
50-
/// </summary>
51-
Other
52-
}
9+
/// 成功
10+
/// </summary>
11+
Success = 0,
12+
13+
/// <summary>
14+
/// 配置表错误
15+
/// </summary>
16+
ConfigErr = 400,
17+
18+
/// <summary>
19+
/// 客户端传递参数错误
20+
/// </summary>
21+
ParamErr,
22+
23+
/// <summary>
24+
/// 消耗不足
25+
/// </summary>
26+
CostNotEnough,
27+
28+
/// <summary>
29+
/// 账号不存在或为空
30+
/// </summary>
31+
AccountCannotBeNull,
32+
33+
/// <summary>
34+
/// 未知平台
35+
/// </summary>
36+
UnknownPlatform,
37+
38+
/// <summary>
39+
/// 正常通知
40+
/// </summary>
41+
Notice = 100000,
42+
43+
/// <summary>
44+
/// 功能未开启,主消息屏蔽
45+
/// </summary>
46+
FuncNotOpen,
47+
48+
/// <summary>
49+
/// 其他
50+
/// </summary>
51+
Other,
5352
}

GameFrameX.Hotfix/GameFrameX.Hotfix.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
</ItemGroup>
2828

2929
<ItemGroup>
30-
<PackageReference Include="GameFrameX.Core" Version="1.2.0-beta22" />
30+
<PackageReference Include="GameFrameX.Core" Version="1.3.0-beta1" />
3131
<PackageReference Include="GameFrameX.SuperSocket.ClientEngine" Version="1.0.3" />
3232
</ItemGroup>
3333

0 commit comments

Comments
 (0)