using System; using System.IO; namespace ET { public class SessionCountCheckComponentAwakeSystem: AwakeSystem { public override void Awake(SessionCountCheckComponent self) { self.timerId = TimerComponent.Instance.NewRepeatedTimer(1000, self.Check); self.GetParent().Service.ReadCallback += self.OnRead; } } public class SessionCountCheckComponentLoadSystem: LoadSystem { public override void Load(SessionCountCheckComponent self) { TimerComponent.Instance.Remove(self.timerId); self.timerId = TimerComponent.Instance.NewRepeatedTimer(1000, self.Check); } } public class SessionCountCheckComponentDestorySystem: DestroySystem { public override void Destroy(SessionCountCheckComponent self) { self.GetParent().Service.ReadCallback -= self.OnRead; TimerComponent.Instance.Remove(ref self.timerId); self.countDic.Clear(); } } public static class SessionCountCheckComponentSystem { public static void Check(this SessionCountCheckComponent self) { using var listComponent = ListComponent.Create(); listComponent.List.AddRange(self.countDic.Keys); foreach (long id in listComponent.List) { if (!self.countDic.TryGetValue(id, out int count)) { continue; } self.countDic[id] = 0; if (count > 5) { Session session = self.Parent.GetChild(id); User user = session?.GetComponent()?.User; Log.Error($"{user?.NickName} : "+count.ToString()); } if (count <= 8) { continue; } try { CheckAsync(self, id, count).Coroutine(); } catch (Exception e) { Log.Error(e); } } } private static async ETVoid CheckAsync(SessionCountCheckComponent self, long id, int count) { Session session = self.Parent.GetChild(id); if (!session) { Log.Error("session is null"); return; } try { User user = null; try { SessionPlayerComponent sessionPlayerComponent = session.GetComponent(); user = sessionPlayerComponent.User; if (count >= 10) { session.Send(new G2C_ForceOffLine()); await TimerComponent.Instance.WaitAsync(300); } } catch (Exception e) { Log.Error(e); } session.Dispose(); if (user != null) { Log.Error($"***********************\n\n【{user.NickName}({user.Id})】 点击次数特别快 :{count}"); } } catch (Exception e) { Log.Error(e); } } public static void OnRead(this SessionCountCheckComponent self, long channelId, MemoryStream memoryStream) { if (!self.countDic.TryGetValue(channelId, out int oldCount)) { self.countDic[channelId] = 0; } self.countDic[channelId] = oldCount + 1; } } }