Skip to content

Commit 2b7fe8b

Browse files
committed
feat(好友系统): 添加好友组件及相关请求处理器
1 parent 5c6323e commit 2b7fe8b

6 files changed

Lines changed: 365 additions & 0 deletions

File tree

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// ==========================================================================================
2+
// GameFrameX 组织及其衍生项目的版权、商标、专利及其他相关权利
3+
// GameFrameX organization and its derivative projects' copyrights, trademarks, patents, and related rights
4+
// 均受中华人民共和国及相关国际法律法规保护。
5+
// are protected by the laws of the People's Republic of China and relevant international regulations.
6+
//
7+
// 使用本项目须严格遵守相应法律法规及开源许可证之规定。
8+
// Usage of this project must strictly comply with applicable laws, regulations, and open-source licenses.
9+
//
10+
// 本项目采用 MIT 许可证与 Apache License 2.0 双许可证分发,
11+
// This project is dual-licensed under the MIT License and Apache License 2.0,
12+
// 完整许可证文本请参见源代码根目录下的 LICENSE 文件。
13+
// please refer to the LICENSE file in the root directory of the source code for the full license text.
14+
//
15+
// 禁止利用本项目实施任何危害国家安全、破坏社会秩序、
16+
// It is prohibited to use this project to engage in any activities that endanger national security, disrupt social order,
17+
// 侵犯他人合法权益等法律法规所禁止的行为!
18+
// or infringe upon the legitimate rights and interests of others, as prohibited by laws and regulations!
19+
// 因基于本项目二次开发所产生的一切法律纠纷与责任,
20+
// Any legal disputes and liabilities arising from secondary development based on this project
21+
// 本项目组织与贡献者概不承担。
22+
// shall be borne solely by the developer; the project organization and contributors assume no responsibility.
23+
//
24+
// GitHub 仓库:https://github.com/GameFrameX
25+
// GitHub Repository: https://github.com/GameFrameX
26+
// Gitee 仓库:https://gitee.com/GameFrameX
27+
// Gitee Repository: https://gitee.com/GameFrameX
28+
// 官方文档:https://gameframex.doc.alianblank.com/
29+
// Official Documentation: https://gameframex.doc.alianblank.com/
30+
// ==========================================================================================
31+
32+
33+
namespace GameFrameX.Apps.Player.Friend;
34+
35+
[ComponentType(GlobalConst.ActorTypePlayer)]
36+
public sealed class FriendComponent : StateComponent<FriendState>
37+
{
38+
39+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// ==========================================================================================
2+
// GameFrameX 组织及其衍生项目的版权、商标、专利及其他相关权利
3+
// GameFrameX organization and its derivative projects' copyrights, trademarks, patents, and related rights
4+
// 均受中华人民共和国及相关国际法律法规保护。
5+
// are protected by the laws of the People's Republic of China and relevant international regulations.
6+
//
7+
// 使用本项目须严格遵守相应法律法规及开源许可证之规定。
8+
// Usage of this project must strictly comply with applicable laws, regulations, and open-source licenses.
9+
//
10+
// 本项目采用 MIT 许可证与 Apache License 2.0 双许可证分发,
11+
// This project is dual-licensed under the MIT License and Apache License 2.0,
12+
// 完整许可证文本请参见源代码根目录下的 LICENSE 文件。
13+
// please refer to the LICENSE file in the root directory of the source code for the full license text.
14+
//
15+
// 禁止利用本项目实施任何危害国家安全、破坏社会秩序、
16+
// It is prohibited to use this project to engage in any activities that endanger national security, disrupt social order,
17+
// 侵犯他人合法权益等法律法规所禁止的行为!
18+
// or infringe upon the legitimate rights and interests of others, as prohibited by laws and regulations!
19+
// 因基于本项目二次开发所产生的一切法律纠纷与责任,
20+
// Any legal disputes and liabilities arising from secondary development based on this project
21+
// 本项目组织与贡献者概不承担。
22+
// shall be borne solely by the developer; the project organization and contributors assume no responsibility.
23+
//
24+
// GitHub 仓库:https://github.com/GameFrameX
25+
// GitHub Repository: https://github.com/GameFrameX
26+
// Gitee 仓库:https://gitee.com/GameFrameX
27+
// Gitee Repository: https://gitee.com/GameFrameX
28+
// 官方文档:https://gameframex.doc.alianblank.com/
29+
// Official Documentation: https://gameframex.doc.alianblank.com/
30+
// ==========================================================================================
31+
32+
33+
34+
namespace GameFrameX.Apps.Player.Friend;
35+
36+
public sealed class FriendState : CacheState
37+
{
38+
/// <summary>
39+
/// 账号ID
40+
/// </summary>
41+
public long AccountId { get; set; }
42+
43+
/// <summary>
44+
/// 玩家名
45+
/// </summary>
46+
public string Name { get; set; }
47+
48+
/// <summary>
49+
/// 玩家等级
50+
/// </summary>
51+
public uint Level { get; set; }
52+
53+
/// <summary>
54+
/// 性别
55+
/// </summary>
56+
public int Gender { get; set; }
57+
58+
/// <summary>
59+
/// 头像
60+
/// </summary>
61+
public uint Avatar { get; set; }
62+
63+
/// <summary>
64+
/// 玩家状态
65+
/// </summary>
66+
public int State { get; set; }
67+
68+
/// <summary>
69+
/// 登录时间
70+
/// </summary>
71+
public DateTime LoginTime { get; set; }
72+
73+
/// <summary>
74+
/// 离线时间
75+
/// </summary>
76+
public DateTime OfflineTime { get; set; }
77+
}
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
// ==========================================================================================
2+
// GameFrameX 组织及其衍生项目的版权、商标、专利及其他相关权利
3+
// GameFrameX organization and its derivative projects' copyrights, trademarks, patents, and related rights
4+
// 均受中华人民共和国及相关国际法律法规保护。
5+
// are protected by the laws of the People's Republic of China and relevant international regulations.
6+
//
7+
// 使用本项目须严格遵守相应法律法规及开源许可证之规定。
8+
// Usage of this project must strictly comply with applicable laws, regulations, and open-source licenses.
9+
//
10+
// 本项目采用 MIT 许可证与 Apache License 2.0 双许可证分发,
11+
// This project is dual-licensed under the MIT License and Apache License 2.0,
12+
// 完整许可证文本请参见源代码根目录下的 LICENSE 文件。
13+
// please refer to the LICENSE file in the root directory of the source code for the full license text.
14+
//
15+
// 禁止利用本项目实施任何危害国家安全、破坏社会秩序、
16+
// It is prohibited to use this project to engage in any activities that endanger national security, disrupt social order,
17+
// 侵犯他人合法权益等法律法规所禁止的行为!
18+
// or infringe upon the legitimate rights and interests of others, as prohibited by laws and regulations!
19+
// 因基于本项目二次开发所产生的一切法律纠纷与责任,
20+
// Any legal disputes and liabilities arising from secondary development based on this project
21+
// 本项目组织与贡献者概不承担。
22+
// shall be borne solely by the developer; the project organization and contributors assume no responsibility.
23+
//
24+
// GitHub 仓库:https://github.com/GameFrameX
25+
// GitHub Repository: https://github.com/GameFrameX
26+
// Gitee 仓库:https://gitee.com/GameFrameX
27+
// Gitee Repository: https://gitee.com/GameFrameX
28+
// 官方文档:https://gameframex.doc.alianblank.com/
29+
// Official Documentation: https://gameframex.doc.alianblank.com/
30+
// ==========================================================================================
31+
32+
using GameFrameX.Apps.Player.Friend;
33+
using GameFrameX.Hotfix.Logic.Rpc;
34+
using GameFrameX.NetWork;
35+
using GameFrameX.Proto.BuiltIn;
36+
37+
namespace GameFrameX.Hotfix.Logic.Player.Friend;
38+
39+
public class FriendComponentAgent : StateComponentAgent<FriendComponent, FriendState>
40+
{
41+
public async Task OnFriendList(INetWorkChannel netWorkChannel, ReqFriendList request, RespFriendList response)
42+
{
43+
// 使用统一的RPC客户端调用社交服务
44+
var reqInnerFriendList = MessageObjectPoolHelper.Get<ReqInnerFriendList>();
45+
reqInnerFriendList.PlayerId = ActorId;
46+
47+
try
48+
{
49+
var rpcResult = await ServiceRpcClient.Instance.CallAsync<RespInnerFriendList>(
50+
GlobalConst.SocialServiceName,
51+
reqInnerFriendList
52+
);
53+
54+
if (rpcResult != null && rpcResult.IsSuccess && rpcResult.Message is RespInnerFriendList friendResponse)
55+
{
56+
// 将远程获取的好友列表数据转换给客户端
57+
response.Friends = friendResponse.Friends ?? new List<FriendInfo>();
58+
response.ErrorCode = friendResponse.ErrorCode;
59+
LogHelper.DebugConsole($"Successfully retrieved friend list for player {ActorId}, count: {response.Friends.Count}");
60+
}
61+
else
62+
{
63+
response.ErrorCode = -1;
64+
LogHelper.Error($"Failed to get friend list for player {ActorId}: RPC call failed");
65+
}
66+
}
67+
finally
68+
{
69+
// 释放消息对象回池
70+
MessageObjectPoolHelper.Return(reqInnerFriendList);
71+
}
72+
}
73+
74+
public async Task OnAddFriend(INetWorkChannel netWorkChannel, ReqFriendByAdd request, RespFriendByAdd response)
75+
{
76+
// 使用统一的RPC客户端调用社交服务添加好友
77+
var reqInnerAddFriend = MessageObjectPoolHelper.Get<ReqInnerFriendByAdd>();
78+
reqInnerAddFriend.PlayerId = ActorId;
79+
80+
try
81+
{
82+
var rpcResult = await ServiceRpcClient.Instance.CallAsync<RespInnerFriendByAdd>(
83+
GlobalConst.SocialServiceName,
84+
reqInnerAddFriend
85+
);
86+
87+
if (rpcResult != null && rpcResult.IsSuccess && rpcResult.Message is RespInnerFriendByAdd addFriendResponse)
88+
{
89+
response.Success = addFriendResponse.Success;
90+
91+
if (response.Success)
92+
{
93+
LogHelper.DebugConsole($"Player {ActorId} successfully added friend {request.PlayerId}");
94+
}
95+
else
96+
{
97+
LogHelper.Warning($"Player {ActorId} failed to add friend {request.PlayerId}, error code: {addFriendResponse.ErrorCode}");
98+
}
99+
}
100+
else
101+
{
102+
response.Success = false;
103+
LogHelper.Error($"RPC call failed when adding friend for player {ActorId}");
104+
}
105+
}
106+
finally
107+
{
108+
MessageObjectPoolHelper.Return(reqInnerAddFriend);
109+
}
110+
}
111+
112+
public async Task OnInnerFriendList(INetWorkChannel netWorkChannel, ReqInnerFriendList request, RespInnerFriendList response)
113+
{
114+
// 这个方法现在主要是由Social服务器调用的,提供本地数据
115+
response.Friends = new List<FriendInfo>
116+
{
117+
new FriendInfo
118+
{
119+
PlayerId = 1,
120+
PlayerName = "Player1"
121+
}
122+
};
123+
await Task.CompletedTask;
124+
}
125+
126+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// ==========================================================================================
2+
// GameFrameX 组织及其衍生项目的版权、商标、专利及其他相关权利
3+
// GameFrameX organization and its derivative projects' copyrights, trademarks, patents, and related rights
4+
// 均受中华人民共和国及相关国际法律法规保护。
5+
// are protected by the laws of the People's Republic of China and relevant international regulations.
6+
//
7+
// 使用本项目须严格遵守相应法律法规及开源许可证之规定。
8+
// Usage of this project must strictly comply with applicable laws, regulations, and open-source licenses.
9+
//
10+
// 本项目采用 MIT 许可证与 Apache License 2.0 双许可证分发,
11+
// This project is dual-licensed under the MIT License and Apache License 2.0,
12+
// 完整许可证文本请参见源代码根目录下的 LICENSE 文件。
13+
// please refer to the LICENSE file in the root directory of the source code for the full license text.
14+
//
15+
// 禁止利用本项目实施任何危害国家安全、破坏社会秩序、
16+
// It is prohibited to use this project to engage in any activities that endanger national security, disrupt social order,
17+
// 侵犯他人合法权益等法律法规所禁止的行为!
18+
// or infringe upon the legitimate rights and interests of others, as prohibited by laws and regulations!
19+
// 因基于本项目二次开发所产生的一切法律纠纷与责任,
20+
// Any legal disputes and liabilities arising from secondary development based on this project
21+
// 本项目组织与贡献者概不承担。
22+
// shall be borne solely by the developer; the project organization and contributors assume no responsibility.
23+
//
24+
// GitHub 仓库:https://github.com/GameFrameX
25+
// GitHub Repository: https://github.com/GameFrameX
26+
// Gitee 仓库:https://gitee.com/GameFrameX
27+
// Gitee Repository: https://gitee.com/GameFrameX
28+
// 官方文档:https://gameframex.doc.alianblank.com/
29+
// Official Documentation: https://gameframex.doc.alianblank.com/
30+
// ==========================================================================================
31+
32+
namespace GameFrameX.Hotfix.Logic.Player.Friend;
33+
34+
[MessageMapping(typeof(ReqFriendByAdd))]
35+
internal sealed class ReqFriendByAddHandler : GlobalRpcComponentHandler<FriendComponentAgent, ReqFriendByAdd, RespFriendByAdd>
36+
{
37+
protected override async Task ActionAsync(ReqFriendByAdd request, RespFriendByAdd response)
38+
{
39+
await ComponentAgent.OnAddFriend(NetWorkChannel, request, response);
40+
}
41+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// ==========================================================================================
2+
// GameFrameX 组织及其衍生项目的版权、商标、专利及其他相关权利
3+
// GameFrameX organization and its derivative projects' copyrights, trademarks, patents, and related rights
4+
// 均受中华人民共和国及相关国际法律法规保护。
5+
// are protected by the laws of the People's Republic of China and relevant international regulations.
6+
//
7+
// 使用本项目须严格遵守相应法律法规及开源许可证之规定。
8+
// Usage of this project must strictly comply with applicable laws, regulations, and open-source licenses.
9+
//
10+
// 本项目采用 MIT 许可证与 Apache License 2.0 双许可证分发,
11+
// This project is dual-licensed under the MIT License and Apache License 2.0,
12+
// 完整许可证文本请参见源代码根目录下的 LICENSE 文件。
13+
// please refer to the LICENSE file in the root directory of the source code for the full license text.
14+
//
15+
// 禁止利用本项目实施任何危害国家安全、破坏社会秩序、
16+
// It is prohibited to use this project to engage in any activities that endanger national security, disrupt social order,
17+
// 侵犯他人合法权益等法律法规所禁止的行为!
18+
// or infringe upon the legitimate rights and interests of others, as prohibited by laws and regulations!
19+
// 因基于本项目二次开发所产生的一切法律纠纷与责任,
20+
// Any legal disputes and liabilities arising from secondary development based on this project
21+
// 本项目组织与贡献者概不承担。
22+
// shall be borne solely by the developer; the project organization and contributors assume no responsibility.
23+
//
24+
// GitHub 仓库:https://github.com/GameFrameX
25+
// GitHub Repository: https://github.com/GameFrameX
26+
// Gitee 仓库:https://gitee.com/GameFrameX
27+
// Gitee Repository: https://gitee.com/GameFrameX
28+
// 官方文档:https://gameframex.doc.alianblank.com/
29+
// Official Documentation: https://gameframex.doc.alianblank.com/
30+
// ==========================================================================================
31+
32+
namespace GameFrameX.Hotfix.Logic.Player.Friend;
33+
34+
[MessageMapping(typeof(ReqFriendList))]
35+
internal sealed class ReqFriendListHandler : GlobalRpcComponentHandler<FriendComponentAgent, ReqFriendList, RespFriendList>
36+
{
37+
protected override async Task ActionAsync(ReqFriendList request, RespFriendList response)
38+
{
39+
await ComponentAgent.OnFriendList(NetWorkChannel, request, response);
40+
}
41+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// ==========================================================================================
2+
// GameFrameX 组织及其衍生项目的版权、商标、专利及其他相关权利
3+
// GameFrameX organization and its derivative projects' copyrights, trademarks, patents, and related rights
4+
// 均受中华人民共和国及相关国际法律法规保护。
5+
// are protected by the laws of the People's Republic of China and relevant international regulations.
6+
//
7+
// 使用本项目须严格遵守相应法律法规及开源许可证之规定。
8+
// Usage of this project must strictly comply with applicable laws, regulations, and open-source licenses.
9+
//
10+
// 本项目采用 MIT 许可证与 Apache License 2.0 双许可证分发,
11+
// This project is dual-licensed under the MIT License and Apache License 2.0,
12+
// 完整许可证文本请参见源代码根目录下的 LICENSE 文件。
13+
// please refer to the LICENSE file in the root directory of the source code for the full license text.
14+
//
15+
// 禁止利用本项目实施任何危害国家安全、破坏社会秩序、
16+
// It is prohibited to use this project to engage in any activities that endanger national security, disrupt social order,
17+
// 侵犯他人合法权益等法律法规所禁止的行为!
18+
// or infringe upon the legitimate rights and interests of others, as prohibited by laws and regulations!
19+
// 因基于本项目二次开发所产生的一切法律纠纷与责任,
20+
// Any legal disputes and liabilities arising from secondary development based on this project
21+
// 本项目组织与贡献者概不承担。
22+
// shall be borne solely by the developer; the project organization and contributors assume no responsibility.
23+
//
24+
// GitHub 仓库:https://github.com/GameFrameX
25+
// GitHub Repository: https://github.com/GameFrameX
26+
// Gitee 仓库:https://gitee.com/GameFrameX
27+
// Gitee Repository: https://gitee.com/GameFrameX
28+
// 官方文档:https://gameframex.doc.alianblank.com/
29+
// Official Documentation: https://gameframex.doc.alianblank.com/
30+
// ==========================================================================================
31+
32+
namespace GameFrameX.Hotfix.Logic.Player.Friend;
33+
34+
[MessageMapping(typeof(ReqInnerFriendList))]
35+
internal sealed class ReqInnerFriendListHandler : GlobalRpcComponentHandler<FriendComponentAgent, ReqInnerFriendList, RespInnerFriendList>
36+
{
37+
protected override async Task ActionAsync(ReqInnerFriendList request, RespInnerFriendList response)
38+
{
39+
await ComponentAgent.OnInnerFriendList(NetWorkChannel, request, response);
40+
}
41+
}

0 commit comments

Comments
 (0)