//[Initialization(InitializationPass.Second, Name = "Misc Packet Definition")] public static void Init() { var msgSegment = new PacketSegment(SimpleType.CString, "Message"); var targetMsgSegment = new ComplexPacketSegment( new PacketSegment(SimpleType.CString, "Target"), new PacketSegment(SimpleType.CString, "Message") ); SwitchPacketSegment msgTypeSwitch; PacketAnalyzer.RegisterDefintion(new PacketDefinition(RealmServerOpCode.CMSG_MESSAGECHAT, msgTypeSwitch = new SwitchPacketSegment(SimpleType.UInt, "Type", (segment, parser) => { parser.ParsedSegments.SetCurrentMoveNext((ChatMsgType)parser.Packet.ReadUInt32()); }, new Condition(ComparisonType.Equal, ChatMsgType.Say, msgSegment), new Condition(ComparisonType.Equal, ChatMsgType.Yell, msgSegment), new Condition(ComparisonType.Equal, ChatMsgType.Emote, msgSegment), new Condition(ComparisonType.Equal, ChatMsgType.Party, msgSegment), new Condition(ComparisonType.Equal, ChatMsgType.Raid, msgSegment), new Condition(ComparisonType.Equal, ChatMsgType.RaidLeader, msgSegment), new Condition(ComparisonType.Equal, ChatMsgType.RaidWarn, msgSegment), new Condition(ComparisonType.Equal, ChatMsgType.Whisper, targetMsgSegment), new Condition(ComparisonType.Equal, ChatMsgType.Channel, targetMsgSegment) ), new PacketSegment(SimpleType.UInt, "Language", (segment, parser) => { parser.ParsedSegments.SetCurrentMoveNext((ChatLanguage)parser.Packet.ReadUInt32()); }), new ConditionalPacketSegment(msgTypeSwitch) )); }
static void AddRealmPacket(IDictionary <RealmServerOpCode, LockfreeQueue <RealmReceiveInfo> > packets, PacketSender sender, PacketIn packet, TestFakeClient client) { var opCode = (RealmServerOpCode)packet.PacketId.RawId; LockfreeQueue <RealmReceiveInfo> queue; if (!packets.TryGetValue(opCode, out queue)) { packets.Add(opCode, queue = new LockfreeQueue <RealmReceiveInfo>()); } var def = PacketAnalyzer.GetDefinition(packet.PacketId, sender); if (def != null) { if (packet is RealmPacketIn) { packet = ((DisposableRealmPacketIn)packet).Copy(); } var parser = new PacketParser(packet, sender); parser.Parse(); queue.Enqueue(new RealmReceiveInfo { Parser = parser, Client = client }); //packet.IncrementUsage(); } }
public static void ParsePacket(ParsablePacketInfo info, IndentTextWriter writer) { PacketAnalyzer.Dump(info, writer); writer.WriteLine(); ((IDisposable)info.Packet).Dispose(); }
public static void DumpPacket(RealmPacketIn packet, PacketSender sender, bool copy, IndentTextWriter writer) { lock (writer) { try { if (copy) { using (var pkt = packet.Copy()) { PacketAnalyzer.Dump(new ParsablePacketInfo(pkt, sender, DateTime.Now), writer); } } else { PacketAnalyzer.Dump(new ParsablePacketInfo(packet, sender, DateTime.Now), writer); } } catch (Exception e) { LogUtil.ErrorException(e, "Unable to parse/render packet " + packet); writer.IndentLevel = 0; writer.Write(packet.ToHexDump()); } } }
/// <summary> /// 初始化 /// </summary> public CallCenter() { #region 变量初始化 QueueWriteToHistory = new LinkQueue <TextMessage>(); QueueUnSendToDB = new LinkQueue <TextMessage>(); QueueLogin = new LinkQueue <Login>(); QueueWaitSend = new LinkQueue <TextMessage>(); #endregion #region IM服务端初始化配置 PacketAnalyzer = new ProtobufPacket(); TcpConfig.Setup(Startup.ServerConfig.MaxConnectionCount); Server = new TcpServer(); Server.ChannelConnected += Server_ChannelConnected; //客户端连接时处理 Server.ChannelDisposed += Server_ChannelDisposed; //客户端断开时处理 Server.ChannelReceived += Server_ChannelReceived; //客户端收到消息时处理 Server.ChannelSent += Server_ChannelSent; //客户端发送消息处理 Server.Error += Server_Error; //服务发生错误时处理 #endregion #region 线程初始化 threadWriteToHistoryQueueWork = new Thread(new ThreadStart(WriteToHistoryQueueWork)); //写入消息历史队列处理-线程 threadLoginQueueWork = new Thread(new ThreadStart(LoginQueueWork)); //登录消息队列处理-线程 threadUnsendQueueWork = new Thread(new ThreadStart(UnsendQueueWork)); //待写入数据库的未发送出去消息队列处理-线程 threadWaitSendQueueWork = new Thread(new ThreadStart(WaitSendQueueWork)); //待发送给用户的消息队列处理-线程 threadWriteToHistoryQueueWork.IsBackground = true; threadLoginQueueWork.IsBackground = true; threadUnsendQueueWork.IsBackground = true; threadWaitSendQueueWork.IsBackground = true; #endregion }
private static void HandleRawPacket(JObject parameters) { //Log.CW("[ProxyMessageHandler] Handling raw packet"); var direction = (MessageDirection)parameters["direction"].Value <uint>(); var content = new Message(DateTime.UtcNow, direction, parameters["content"].Value <string>().Substring(4)); PacketAnalyzer.EnqueuePacket(content); }
/// <summary> /// Loads all Packet definitions from XML /// </summary> public static void LoadDefinitions() { if (DefinitionDir == null) { DefinitionDir = new DirectoryInfo(Path.Combine(RealmServerConfiguration.ContentDir, "Packets")); } PacketAnalyzer.LoadDefinitions(DefinitionDir); }
//[Initialization(InitializationPass.Second, Name = "Spell Packet Definition")] public static void Init() { PacketAnalyzer.RegisterDefintion(new PacketDefinition(RealmServerOpCode.CMSG_CAST_SPELL, new PacketSegment(SimpleType.UInt, "SpellId", SpellIdParser) )); PacketAnalyzer.RegisterDefintion(new PacketDefinition(RealmServerOpCode.CMSG_CANCEL_CAST, new PacketSegment(SimpleType.UInt, "SpellId", SpellIdParser) )); }
public GOSerializer(LogParser parser, IndentTextWriter writer) : base(parser, new LogHandler(ValidateOpCode, HandlePacket)) { // just make sure to have the XML-definition of the packet before using this Class if (!PacketAnalyzer.IsDefined(RealmServerOpCode.SMSG_GAMEOBJECT_QUERY_RESPONSE, PacketSender.Server)) { throw new InvalidOperationException("SMSG_GAMEOBJECT_QUERY_RESPONSE is not defined."); } s_Writer = writer; }
public GameNetworkMonitor(Process p) { this.ProcessWorking = p; var consumers = ConsumerSearcher.FindConsumers("Thaliak.Network.Messages"); ConsumerSet = consumers; _dispatcher = new MessageDispatcher(ConsumerSet); _analyzer = new PacketAnalyzer(_dispatcher); }
/// <summary> /// Renders the given log file to the given output. /// </summary> /// <param name="file">The file from where to read the ksniffer-style logs</param> /// <param name="output">A StreamWriter or Console.Out etc</param> public static void ConvertLog(string logFile, TextWriter output) { // @"F:\coding\C#\WCell\Dumps\Dump_Spells.txt" var writer = new IndentTextWriter(output); FieldRenderUtil.IsOldEntity = false; var log = File.ReadAllLines(logFile); var packets = Extract(log); foreach (var packet in packets) { PacketAnalyzer.Render(packet, writer); writer.WriteLine(); packet.Dispose(); } }
public void TestSavingAndLoading() { var def = new PacketDefinition(RealmServerOpCode.CMSG_SET_CHANNEL_WATCH, PacketSender.Client, new List <PacketSegmentStructure>()); PacketAnalyzer.RegisterDefintion(def); var def2 = PacketAnalyzer.GetDefinition(RealmServerOpCode.CMSG_SET_CHANNEL_WATCH, PacketSender.Client); Assert.AreEqual(def, def2); def = new PacketDefinition(RealmServerOpCode.CMSG_SET_CHANNEL_WATCH, PacketSender.Any, new List <PacketSegmentStructure>()); PacketAnalyzer.RegisterDefintion(def); def2 = PacketAnalyzer.GetDefinition(RealmServerOpCode.CMSG_SET_CHANNEL_WATCH, PacketSender.Server); Assert.AreEqual(def, def2); }
public RealmReceiveInfo DequeueCMSGInfo(RealmServerOpCode opCode) { Setup.WriteLine("Fetching packet " + opCode); Assert.IsNotNull(RealmPacketMgr.Instance[opCode], "You did not add a PacketHandler for: {0} - " + "To do so, simply call one of the Add*Handler(...) methods of this class during initialization.", opCode); LockfreeQueue <RealmReceiveInfo> queue; CMSGPackets.TryGetValue(opCode, out queue); if (queue != null) { var info = queue.TryDequeue(); if (info == null) { var def = PacketAnalyzer.GetDefinition(opCode, PacketSender.Client); Assert.IsNotNull(def, "You did not define the packet-structure for OpCode {0}!", opCode); } return(info); } throw new InvalidOperationException("Packets are not cached!"); }
private static void HandleRawPacket(JObject parameters) { var jDir = parameters["direction"]; if (jDir == null) { return; } var jContent = parameters["content"]; if (jContent == null) { return; } var direction = (MessageDirection)jDir.Value <uint>(); var content = new Message(DateTime.UtcNow, direction, jContent.Value <string>().Substring(4)); PacketAnalyzer.EnqueuePacket(content); }
public static void DumpPacket(RealmPacketIn packet, bool copy, IndentTextWriter writer) { try { if (copy) { using (PinnedRealmPacketIn pkt = packet.Copy()) { PacketAnalyzer.Render(pkt, writer); } } else { PacketAnalyzer.Render(packet, writer); } } catch (Exception e) { log.ErrorException("Unable to parse/render packet " + packet, e); writer.IndentLevel = 0; writer.Write(packet.ToHexDump()); } }
private async void OnStartup(object sender, StartupEventArgs e) { BaseDispatcher = Dispatcher.CurrentDispatcher; BaseDispatcher.Thread.Name = "Main"; TccMessageBox.Create(); //Create it here in STA thread if (IsRunning()) { TccMessageBox.Show("Another instance of TCC is already running. Shutting down.", MessageBoxType.Information); Current.Shutdown(); return; } Loading = true; var v = Assembly.GetExecutingAssembly().GetName().Version; AppVersion = $"TCC v{v.Major}.{v.Minor}.{v.Build}{(Experimental ? "-e" : "")}"; InitSplashScreen(); AppDomain.CurrentDomain.UnhandledException += GlobalExceptionHandler.HandleGlobalException; TryDeleteUpdater(); SplashScreen.SetText("Checking for application updates..."); await UpdateManager.CheckAppVersion(); SplashScreen.SetText("Checking for database updates..."); await UpdateManager.CheckIconsVersion(); SplashScreen.SetText("Loading settings..."); var sr = new SettingsReader(); sr.LoadWindowSettings(); sr.LoadSettings(); Process.GetCurrentProcess().PriorityClass = SettingsHolder.HighPriority ? ProcessPriorityClass.High : ProcessPriorityClass.Normal; if (SettingsHolder.ForceSoftwareRendering) { RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly; } SplashScreen.SetText("Pre-loading databases..."); UpdateManager.CheckDatabaseHash(); SessionManager.InitDatabasesAsync(string.IsNullOrEmpty(SettingsHolder.LastLanguage) ? "EU-EN" : SettingsHolder.LastLanguage == "EU" ? "EU-EN" : SettingsHolder.LastLanguage); UpdateManager.CheckServersFile(); SplashScreen.SetText("Initializing windows..."); WindowManager.Init(); SplashScreen.SetText("Initializing packet processor..."); PacketAnalyzer.InitAsync(); SplashScreen.SetText("Starting"); TimeManager.Instance.SetServerTimeZone(SettingsHolder.LastLanguage); ChatWindowManager.Instance.AddTccMessage(AppVersion); SplashScreen.CloseWindowSafe(); UpdateManager.StartPeriodicCheck(); if (!Experimental && SettingsHolder.ExperimentalNotification && UpdateManager.IsExperimentalNewer()) { WindowManager.FloatingButton.NotifyExtended("TCC experimental", "An experimental version of TCC is available. Open System settings to download it or disable this notification.", NotificationType.Success, 10000); } Loading = false; }
private void OnStartup(object sender, StartupEventArgs e) { Loading = true; var v = Assembly.GetExecutingAssembly().GetName().Version; AppVersion = $"TCC v{v.Major}.{v.Minor}.{v.Build}"; InitSplashScreen(); BaseDispatcher = Dispatcher.CurrentDispatcher; TccMessageBox.Create(); //Create it here in STA thread #if !DEBUG AppDomain.CurrentDomain.UnhandledException += GlobalUnhandledExceptionHandler; #endif TryDeleteUpdater(); SplashScreen.SetText("Checking for application updates..."); UpdateManager.CheckAppVersion(); SplashScreen.SetText("Checking for database updates..."); UpdateManager.CheckDatabaseVersion(); SplashScreen.SetText("Loading settings..."); var sr = new SettingsReader(); sr.LoadWindowSettings(); sr.LoadSettings(); Process.GetCurrentProcess().PriorityClass = SettingsHolder.HighPriority ? ProcessPriorityClass.High : ProcessPriorityClass.Normal; if (SettingsHolder.ForceSoftwareRendering) { RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly; } SplashScreen.SetText("Pre-loading databases..."); SessionManager.InitDatabases(string.IsNullOrEmpty(SettingsHolder.LastRegion) ? "EU-EN" : SettingsHolder.LastRegion == "EU" ? "EU-EN" : SettingsHolder.LastRegion); SplashScreen.SetText("Initializing windows..."); WindowManager.Init(); //debug //WindowManager.Dashboard.ShowWindow(); // SplashScreen.SetText("Initializing packet processor..."); PacketAnalyzer.Init(); WindowManager.FloatingButton.NotifyExtended("TCC", "Ready to connect.", NotificationType.Normal); SplashScreen.SetText("Starting"); TimeManager.Instance.SetServerTimeZone(SettingsHolder.LastRegion); ChatWindowManager.Instance.AddTccMessage(AppVersion); SplashScreen.CloseWindowSafe(); UpdateManager.StartCheck(); //if (Settings.Settings.LastRegion == "NA" || Settings.Settings.LastRegion == "") // WindowManager.FloatingButton.NotifyExtended("So long, and thanks for all the fish", ThankYou_mEME, NotificationType.Error, 15000); #pragma warning disable 0162 if (Debug) { DebugStuff(); } #pragma warning restore 0162 Loading = false; // new DebugWindow().Show(); }
private static async Task Setup() { TccUtils.SetAlignment(); NoticeChecker.Init(); TccSplashScreen.InitOnNewThread(); if (!ToolboxMode) { UpdateManager.TryDeleteUpdater(); SplashScreen.VM.BottomText = "Checking for application updates..."; await UpdateManager.CheckAppVersion(); } // ---------------------------- SplashScreen.VM.Progress = 10; SplashScreen.VM.BottomText = "Loading settings..."; Settings = SettingsContainer.Load(); WindowManager.InitSettingsWindow(); // need it in case language is not correct SplashScreen.VM.Progress = 20; Process.GetCurrentProcess().PriorityClass = Settings.HighPriority ? ProcessPriorityClass.High : ProcessPriorityClass.Normal; if (Settings.ForceSoftwareRendering) { RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly; } // ---------------------------- SplashScreen.VM.Progress = 30; SplashScreen.VM.BottomText = "Pre-loading databases..."; UpdateManager.CheckDatabaseHash(); SplashScreen.VM.Progress = 40; await Game.InitAsync(); // ---------------------------- SplashScreen.VM.Progress = 50; SplashScreen.VM.BottomText = "Initializing widgets..."; await WindowManager.Init(); SplashScreen.VM.Progress = 60; StartDispatcherWatcher(); // ---------------------------- SplashScreen.VM.Progress = 70; SplashScreen.VM.BottomText = "Checking for icon database updates..."; _ = Task.Run(() => new IconsUpdater().CheckForUpdates()); // ---------------------------- SplashScreen.VM.BottomText = "Initializing packet processor..."; SplashScreen.VM.Progress = 80; PacketAnalyzer.ProcessorReady += LoadModules; await PacketAnalyzer.InitAsync(); // ---------------------------- SplashScreen.VM.Progress = 90; SplashScreen.VM.BottomText = "Starting"; GameEventManager.Instance.SetServerTimeZone(Settings.LastLanguage); UpdateManager.StartPeriodicCheck(); SplashScreen.VM.Progress = 100; SplashScreen.CloseWindowSafe(); // ---------------------------- Log.Chat($"{AppVersion} ready."); ReadyEvent?.Invoke(); if (!Beta && Settings.BetaNotification && UpdateManager.IsBetaNewer()) { Log.N("TCC beta available", SR.BetaAvailable, NotificationType.Success, 10000); } }