Compare commits

...

4 Commits

Author SHA1 Message Date
Yue-bin
c818adb693 refactor(Transport): 优化ConvGenerator类的字段命名和实现
- 将smaller和bigger改为私有只读字段localId和remoteId
- 使用属性替代字段存储Math.Min和Math.Max的结果
- 保持原有的位运算逻辑不变,提高代码可读性
2026-04-18 20:22:04 +08:00
Yue-bin
ed34a4eece 📃 docs(plan): 嘻嘻这个不叫好友代码 2026-04-18 20:17:38 +08:00
Yue-bin
92e78f970f feat(Transport): 优化ConvGenerator算法
将CSteamID改为使用AccountID
2026-04-18 20:16:27 +08:00
Yue-bin
97f2ad38bb docs(plan): 优化conv生成算法
将conv的划分算法从steamid改为accountid(好友代码),简化了生成逻辑,
去除了原本64位中的高位噪声(多数情况下一致)
2026-04-18 20:16:02 +08:00
2 changed files with 8 additions and 8 deletions

View File

@@ -5,9 +5,10 @@ namespace stick.plugins.kcpable.Protocol;
public class ConvGenerator(CSteamID local, CSteamID remote, int channel) public class ConvGenerator(CSteamID local, CSteamID remote, int channel)
{ {
readonly ulong smaller = Math.Min(local.m_SteamID, remote.m_SteamID); private readonly uint localId = local.GetAccountID().m_AccountID;
readonly ulong bigger = Math.Max(local.m_SteamID, remote.m_SteamID); private readonly uint remoteId = remote.GetAccountID().m_AccountID;
readonly int channel = channel; private uint Smaller => Math.Min(localId, remoteId);
private ulong Combined => smaller ^ (bigger << 1) ^ ((ulong)channel << 2); // 位交错 private uint Bigger => Math.Max(localId, remoteId);
public uint Generate() => (uint)(Combined & 0xFFFFFFFF) ^ (uint)(Combined >> 32); // 全部64位异或压缩到32位的conv private readonly uint channel = (uint)channel;
public uint Generate() => Smaller ^ (Bigger << 1) ^ (channel << 2); // 位交错
} }

View File

@@ -56,14 +56,13 @@
conv的划分应该精确到单人单channel conv的划分应该精确到单人单channel
1. 取两边steamid 1. 取两边steamid的accountid
2. 按大小分成bigger和smaller 2. 按大小分成bigger和smaller
3. 取需要发送到的目标channel懒得发只定义了两个 3. 取需要发送到的目标channel懒得发只定义了两个
4. 计算 4. 计算
``` csharp ``` csharp
private ulong Combined => smaller ^ (bigger << 1) ^ ((ulong)channel << 2); // 位交错 public uint Generate() => smaller ^ (bigger << 1) ^ (channel << 2); // 位交错
public uint Generate() => (uint)(Combined & 0xFFFFFFFF) ^ (uint)(Combined >> 32); // 全部64位异或压缩到32位的conv
``` ```
## 其它 ## 其它