You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
118 lines
4.3 KiB
118 lines
4.3 KiB
using Org.BouncyCastle.Ocsp;
|
|
using ProtoCSStruct;
|
|
using Sog;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Game
|
|
{
|
|
|
|
public class PlayerMsgCache : IPlayerMsgCache
|
|
{
|
|
private Dictionary<int, Dictionary<int, MsgCache>> cache_SendMsg = new Dictionary<int, Dictionary<int, MsgCache>>();
|
|
|
|
private void delete(Dictionary<int, MsgCache> dict, int msgSeq)
|
|
{
|
|
List<int> keys = new List<int>();
|
|
foreach (var kv in dict)
|
|
{
|
|
if (kv.Key < msgSeq)
|
|
{
|
|
keys.Add(kv.Key);
|
|
}
|
|
}
|
|
foreach (var key in keys)
|
|
{
|
|
dict.Remove(key);
|
|
}
|
|
}
|
|
public override void clear()
|
|
{
|
|
cache_SendMsg.Clear();
|
|
}
|
|
public override bool CheckRepeateMsg(PlayerOnGame player, StructPacket packet)
|
|
{
|
|
var msgId = packet.Header.Type;
|
|
if (cache_SendMsg.TryGetValue(msgId, out var dict))
|
|
{
|
|
switch (msgId)
|
|
{
|
|
case (int)CSGameMsgID.CbFinishReq:
|
|
{
|
|
ref var req = ref packet.GetMessage<CSCBFinishLayerReq>();
|
|
if (dict.TryGetValue(req.MsgSeq, out MsgCache msg))
|
|
{
|
|
CSCBFinishLayerRes res = new CSCBFinishLayerRes();
|
|
msg.ParseFrom(ref res);
|
|
player.SendToClient((int)CSGameMsgID.CbFinishRes, ref res);
|
|
return true;
|
|
}
|
|
//删除小于msgseq的数据
|
|
delete(dict, req.MsgSeq);
|
|
}
|
|
break;
|
|
case (int)CSGameMsgID.CbLeaveReq:
|
|
{
|
|
ref var req = ref packet.GetMessage<CSCBLeaveReq>();
|
|
if (dict.TryGetValue(req.MsgSeq, out var msg))
|
|
{
|
|
CSCBLeaveRes res = new CSCBLeaveRes();
|
|
msg.ParseFrom(ref res);
|
|
player.SendToClient((int)CSGameMsgID.CbLeaveRes, ref res);
|
|
return true;
|
|
}
|
|
//删除小于msgseq的数据
|
|
delete(dict, req.MsgSeq);
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
public override void AddSendMsg(PlayerOnGame player, StructPacket packetReq, MsgCache msg)
|
|
{
|
|
var msgId = packetReq.Header.Type;
|
|
if (cache_SendMsg.TryGetValue(msgId, out var dict))
|
|
{
|
|
switch (msgId)
|
|
{
|
|
case (int)CSGameMsgID.CbFinishReq:
|
|
{
|
|
ref var req = ref packetReq.GetMessage<CSCBFinishLayerReq>();
|
|
dict[req.MsgSeq] = msg;
|
|
}
|
|
break;
|
|
case (int)CSGameMsgID.CbLeaveReq:
|
|
{
|
|
ref var req = ref packetReq.GetMessage<CSCBLeaveReq>();
|
|
dict[req.MsgSeq] = msg;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
dict = new Dictionary<int, MsgCache>();
|
|
switch (msgId)
|
|
{
|
|
case (int)CSGameMsgID.CbFinishReq:
|
|
{
|
|
ref var req = ref packetReq.GetMessage<CSCBFinishLayerReq>();
|
|
dict[req.MsgSeq] = msg;
|
|
}
|
|
break;
|
|
case (int)CSGameMsgID.CbLeaveReq:
|
|
{
|
|
ref var req = ref packetReq.GetMessage<CSCBLeaveReq>();
|
|
dict[req.MsgSeq] = msg;
|
|
}
|
|
break;
|
|
}
|
|
cache_SendMsg.Add(msgId, dict);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|