public static void WriteLine(Message p, String prefix = null, int logLevel = 4) { if(logLevel <= m_vLogLevel) { lock (m_vSyncObject) { m_vTextWriter.Write(DateTime.Now.ToString("yyyy/MM/dd/HH/mm/ss")); m_vTextWriter.Write(";"); if (prefix != null) { m_vTextWriter.Write(prefix); m_vTextWriter.Write(";"); } m_vTextWriter.Write(p.GetMessageType().ToString()); m_vTextWriter.Write("("); m_vTextWriter.Write(p.GetMessageVersion().ToString()); m_vTextWriter.Write(")"); m_vTextWriter.Write(";"); m_vTextWriter.Write(p.GetLength().ToString()); m_vTextWriter.Write(";"); m_vTextWriter.WriteLine(p.ToHexString()); m_vTextWriter.WriteLine(Regex.Replace(p.ToString(), @"[^\u0020-\u007F]", ".")); m_vTextWriter.Flush(); } } }
public Message(Client c, Message m) //Clone { m_vType = m.GetMessageType(); m_vLength = m.GetLength(); m_vData = new byte[m.GetLength()]; Array.Copy(m.GetData(), m_vData, m.GetLength()); m_vMessageVersion = m.GetMessageVersion(); this.Client = c; }
/// <summary> /// This function write the specific text to the actually logging file. /// </summary> /// <param name="p">The message/packet.</param> /// <param name="prefix">The prefix of the log.</param> /// <param name="logLevel">The log level.</param> public static void WriteLine(Message p, string prefix = null, int logLevel = 4) { if (logLevel <= m_vLogLevel) lock (m_vSyncObject) { m_vTextWriter.Write(DateTime.Now.ToString("yyyyMMddHHmmss"), ";"); if (prefix != null) m_vTextWriter.Write(prefix, ";"); m_vTextWriter.Write(p.GetMessageType().ToString(), "(", p.GetMessageVersion().ToString(), ");", p.GetLength().ToString(), ";", p.ToHexString(), "\n", Regex.Replace(p.ToString(), @"[^\u0020-\u007F]", "."), "\n"); m_vTextWriter.Flush(); } }
public static void ProcessOutgoingPacket(Message p) { p.Encode(); try { Level pl = p.Client.GetLevel(); string player = ""; if (pl != null) player += " (" + pl.GetPlayerAvatar().GetId() + ", " + pl.GetPlayerAvatar().GetAvatarName() + ")"; Debugger.WriteLine("[S] " + p.GetMessageType() + " " + p.GetType().Name + player); m_vOutgoingPackets.Enqueue(p); m_vOutgoingWaitHandle.Set(); } catch (Exception) { throw; } }
public static void ProcessOutgoingPacket(Message p) { p.Encode(); //p.Process(p.Client.GetLevel()); try { var pl = p.Client.GetLevel(); var player = ""; if (pl != null) player = " (" + pl.GetPlayerAvatar().GetId() + ", " + pl.GetPlayerAvatar().GetAvatarName() + ")"; Debugger.WriteLine("[UCR][" + p.GetMessageType() + "] Processing " + p.GetType().Name + player); m_vOutgoingPackets.Enqueue(p); m_vOutgoingWaitHandle.Set(); } catch (Exception) { } }
public static void ProcessIncomingPacket(Message p) { m_vIncomingPackets.Enqueue(p); m_vIncomingWaitHandle.Set(); }
public Menu() { while (true) { Console.WriteLine(""); var line = Console.ReadLine(); if (line == "/startx") { m_vMaintance = true; Application.Run(new UCSManager()); } else if (line == "/stopucslist") { Ucslist.Stop(); } else if (line == "/reloadfilter") { Console.WriteLine("Filter Has Been Reload"); Message.ReloadChatFilterList(); } else if (line == "/shutdown") { foreach (var onlinePlayer in ResourcesManager.GetOnlinePlayers()) { var p = new ShutdownStartedMessage(onlinePlayer.GetClient()); p.SetCode(5); PacketManager.ProcessOutgoingPacket(p); } Console.WriteLine("Message has been send to the user"); } else if (line == "/clear") { Console.Clear(); } else if (line == "/restart") { var mail = new AllianceMailStreamEntry(); mail.SetId((int)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds); mail.SetSenderId(0); mail.SetSenderAvatarId(0); mail.SetSenderName("System Manager"); mail.SetIsNew(0); mail.SetAllianceId(0); mail.SetAllianceBadgeData(0); mail.SetAllianceName("Legendary Administrator"); mail.SetMessage("System is about to restart in a few moments."); mail.SetSenderLevel(500); mail.SetSenderLeagueId(22); foreach (var onlinePlayer in ResourcesManager.GetOnlinePlayers()) { var pm = new GlobalChatLineMessage(onlinePlayer.GetClient()); var ps = new ShutdownStartedMessage(onlinePlayer.GetClient()); var p = new AvatarStreamEntryMessage(onlinePlayer.GetClient()); ps.SetCode(5); p.SetAvatarStreamEntry(mail); pm.SetChatMessage("System is about to restart in a few moments."); pm.SetPlayerId(0); pm.SetLeagueId(22); pm.SetPlayerName("System Manager"); PacketManager.ProcessOutgoingPacket(p); PacketManager.ProcessOutgoingPacket(ps); PacketManager.ProcessOutgoingPacket(pm); } Console.WriteLine("System Restarting...."); Program.RestartProgram(); } else if (line == "/update") { var downloadUrl = ""; Version newVersion = null; var aboutUpdate = ""; var xmlUrl = "https://www.flamewall.net/ucs/system.xml"; XmlTextReader reader = null; try { reader = new XmlTextReader(xmlUrl); reader.MoveToContent(); var elementName = ""; if ((reader.NodeType == XmlNodeType.Element) && (reader.Name == "appinfo")) { while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element) { elementName = reader.Name; } else { if ((reader.NodeType == XmlNodeType.Text) && reader.HasValue) { switch (elementName) { case "version": newVersion = new Version(reader.Value); break; case "url": downloadUrl = reader.Value; break; case "about": aboutUpdate = reader.Value; break; } } } } } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { if (reader != null) { reader.Close(); } } var applicationVersion = Assembly.GetExecutingAssembly().GetName().Version; if (applicationVersion.CompareTo(newVersion) < 0) { var str = string.Format( "New version found!\nYour version: {0}.\nNewest version: {1}. \nAdded in this version: {2}. ", applicationVersion, newVersion, aboutUpdate); if (DialogResult.No != MessageBox.Show(str + "\nWould you like to download this update?", "Check for updates", MessageBoxButtons.YesNo, MessageBoxIcon.Question)) { try { Process.Start(downloadUrl); } catch {} return; } ; } else { MessageBox.Show("Your version: " + applicationVersion + " is up to date.", "Check for Updates", MessageBoxButtons.OK, MessageBoxIcon.None); } } else if (line == "/status") { var hostName = Dns.GetHostName(); var IPM = Dns.GetHostByName(hostName).AddressList[0].ToString(); Console.WriteLine("Server IP : " + IPM + " on port 9339"); Console.WriteLine("Online Player : " + ResourcesManager.GetOnlinePlayers().Count); Console.WriteLine("Connected Player : " + ResourcesManager.GetConnectedClients().Count); Console.WriteLine("Starting Gold : " + int.Parse(ConfigurationManager.AppSettings["StartingGold"])); Console.WriteLine("Starting Elixir : " + int.Parse(ConfigurationManager.AppSettings["StartingElixir"])); Console.WriteLine("Starting Dark Elixir : " + int.Parse(ConfigurationManager.AppSettings["StartingDarkElixir"])); Console.WriteLine("Starting Gems : " + int.Parse(ConfigurationManager.AppSettings["StartingGems"])); Console.WriteLine("CoC Version : " + ConfigurationManager.AppSettings["ClientVersion"]); if (Convert.ToBoolean(ConfigurationManager.AppSettings["useCustomPatch"])) { Console.WriteLine("Patch : Active"); Console.WriteLine("Patching Server : " + ConfigurationManager.AppSettings["patchingServer"]); } else { Console.WriteLine("Patch : Disable"); } if (Convert.ToBoolean(ConfigurationManager.AppSettings["maintenanceMode"])) { Console.WriteLine("Maintance Mode : Active"); Console.WriteLine("Maintance time : " + Convert.ToInt32(ConfigurationManager.AppSettings["maintenanceTimeleft"]) + " Seconds"); } else { Console.WriteLine("Maintance Mode : Disable"); } } else if (line == "/sysinfo") { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Server Status is now sent to all online players"); var mail = new AllianceMailStreamEntry(); mail.SetId((int)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds); mail.SetSenderId(0); mail.SetSenderAvatarId(0); mail.SetSenderName("System Manager"); mail.SetIsNew(0); mail.SetAllianceId(0); mail.SetAllianceBadgeData(0); mail.SetAllianceName("Legendary Administrator"); mail.SetMessage("Latest Server Status:\nConnected Players:" + ResourcesManager.GetConnectedClients().Count + "\nIn Memory Alliances:" + ObjectManager.GetInMemoryAlliances().Count + "\nIn Memory Levels:" + ResourcesManager.GetInMemoryLevels().Count); mail.SetSenderLeagueId(22); mail.SetSenderLevel(500); foreach (var onlinePlayer in ResourcesManager.GetOnlinePlayers()) { var p = new AvatarStreamEntryMessage(onlinePlayer.GetClient()); var pm = new GlobalChatLineMessage(onlinePlayer.GetClient()); pm.SetChatMessage("Our current Server Status is now sent at your mailbox!"); pm.SetPlayerId(0); pm.SetLeagueId(22); pm.SetPlayerName("System Manager"); p.SetAvatarStreamEntry(mail); PacketManager.ProcessOutgoingPacket(p); PacketManager.ProcessOutgoingPacket(pm); } Console.ForegroundColor = ConsoleColor.White; } else if (line == "/help") { MenuList(); } else { MenuList(); } } }
public static void ProcessPacket(Message p) { m_vPackets.Enqueue(p); m_vWaitHandle.Set(); }
public bool TryGetPacket(out Message p) { p = null; bool result = false; if(DataStream.Count() >= 5) { int length = ((0x00 << 24) | (DataStream[2] << 16) | (DataStream[3] << 8) | DataStream[4]); ushort type = (ushort)((DataStream[0] << 8) | DataStream[1]); if ((DataStream.Count - 7) >= length) { object obj = null; byte[] packet = DataStream.Take(7 + length).ToArray(); using (var br = new BinaryReader(new MemoryStream(packet))) { obj = MessageFactory.Read(this, br, type); } if (obj != null) { p = (Message)obj; result = true; } else { //Update Decryption Key byte[] data = DataStream.Skip(7).Take(length).ToArray(); Decrypt(data); } DataStream.RemoveRange(0, 7 + length); } } return result; }