public static string EncryptString(string Message, string _Pass) { byte[] _Res; UTF8Encoding _UTF8 = new UTF8Encoding(); MD5CryptoServiceProvider _Hash = new MD5CryptoServiceProvider(); byte[] _Key = _Hash.ComputeHash(_UTF8.GetBytes(_Pass)); byte[] _Data = _UTF8.GetBytes(Message); TripleDESCryptoServiceProvider _Service = new TripleDESCryptoServiceProvider { Key = _Key, Mode = CipherMode.ECB, Padding = PaddingMode.PKCS7 }; try { ICryptoTransform _Encrypter = _Service.CreateEncryptor(); _Res = _Encrypter.TransformFinalBlock(_Data, 0, _Data.Length); } catch (Exception ex) { LogLib.WriteLine("Error in EncryptString(): ", ex); return(""); } finally { _Hash.Clear(); _Service.Clear(); } return(Convert.ToBase64String(_Res)); }
private void ProcessPacket(Spawninfo si) { // SPAWN // si.flags == 0 // Target // si.flags == 1 // MAP // si.flags == 4 // GROUND // si.flags == 5 //ProcInfo// si.flags == 6 //World// si.flags == 8 // PLAYER // si.flags == 253 switch (si.flags) { case PacketType.Zone: f1.ProcessMap(si); break; case PacketType.Player: eq.ProcessGamer(si, f1); break; case PacketType.GroundItem: eq.ProcessGroundItems(si); break; case PacketType.Target: eq.ProcessTarget(si); break; case PacketType.World: eq.ProcessWorld(si); break; case PacketType.Spawn: eq.ProcessSpawns(si, update_hidden); break; case PacketType.GetProcessInfo: ProcessProcessInfo(si); break; default: LogLib.WriteLine("Unknown Packet Type: " + si.flags.ToString(), LogLevel.Warning); break; } }
public bool ConnectToServer(string ServerAddress, int ServerPort, bool errMsg = true) { try { pSocketClient?.Disconnect(); // Instantiate a CSocketClient object pSocketClient = new CSocketClient(100000, new CSocketClient.MESSAGE_HANDLER(MessageHandlerClient), new CSocketClient.CLOSE_HANDLER(CloseHandler) ); // Establish a connection to the server mbGetProcessInfo = true; pSocketClient.Connect(ServerAddress, ServerPort); return(true); } catch (Exception pException) { var msg = $"{ServConErr} {pException.Message}"; LogLib.WriteLine(msg); if (errMsg) { MessageBox.Show( msg + "\r\nTry selecting a different server!", caption: ServConErr, buttons: MessageBoxButtons.OK, icon: MessageBoxIcon.Error); } return(false); } }
// Private Methods //******************************************************************** /// <summary> Called when a message arrives </summary> /// <param name="ar"> RefType: An async result interface </param> private void ReceiveComplete(IAsyncResult ar) { try { // Is the Network Stream object valid if (GetNetworkStream.CanRead) { // Read the current bytes from the stream buffer var iBytesRecieved = GetNetworkStream.EndRead(ar); // If there are bytes to process else the connection is lost if (iBytesRecieved > 0) { // A message came in send it to the MessageHandler try { GetMessageHandler(this, iBytesRecieved); } catch (Exception ex) { LogLib.WriteLine("Error GetMessageHandler - CSocketClient.ReceiveComplete(): ", ex); } // Wait for a new message Receive(); } else { LogLib.WriteLine("CSocketClient.ReceiveComplete(): Shuting Down", LogLevel.Error); throw new SocketException(); } } } catch (Exception) { // The connection must have dropped call the CloseHandler try { GetCloseHandler(this); } catch (Exception ex) { LogLib.WriteLine("Error CSocketClient.ReceiveComplete(): ", ex); } Disconnect(); } }
public void ReadItemList(string file, myseq.EQData eq) { var filePath = CombineCfgDir(file); if (!File.Exists(filePath)) { LogLib.WriteLine("GroundItems.ini file not found", LogLevel.Warning); return; } foreach (var line in File.ReadAllLines(filePath).ToList()) { //sample: IT0_ACTORDEF = Generic if (!line.StartsWith("[") && !string.IsNullOrWhiteSpace(line)) { var entries = line.Split('='); var tmp = entries[0].Split('_'); eq.GroundSpawn.Add(new ListItem { ID = int.Parse(tmp[0].Remove(0, 2)), ActorDef = entries[0], Name = entries[1] }); } } }
public void WriteAlertFile(string zoneName) { // Write new xml alert file try { zoneName = zoneName.ToLower(); var filterFile = CombineFilter($"{zoneName}.xml"); DeleteFile(filterFile); // create the filter file - truncate if exists - going to write all the filters if (zoneName == "global") { WriteGlobalFile(filterFile); } else { WriteZoneFile(filterFile); } PurgeFilters(zoneName); } catch (Exception ex) { LogLib.WriteLine($"Error opening writing filter file for {zoneName}: ", ex); } }
public void StopListening() { try { RequestPending = false; numPackets = numProcessed = 0; pSocketClient?.Disconnect(); pSocketClient = null; } catch (Exception pException) { LogLib.WriteLine($"Error: StopListening: {pException.Message}"); } }
private void ProcessPacket(byte[] packet, int bytes) { var offset = 0; const int SIZE_OF_PACKET = 100; //104 on new server try { if (bytes > 0) { // we have received some bytes, check if this is the beginning of a new packet or a chunk of an existing one. offset = CheckStart(packet); eq.BeginProcessPacket(); //clears spawn&ground arrays for (; offset + SIZE_OF_PACKET <= bytes; offset += SIZE_OF_PACKET) { Spawninfo si = new Spawninfo(); if (offset < 0) { // copy the missing chunk of the incomplete packet to the incomplete packet buffer try { PacketCopy(packet, SIZE_OF_PACKET); } catch (Exception ex) { LogLib.WriteLine("Error: ProcessPacket: Copy Incomplete packet buffer: ", ex); } incompleteCount = 0; if (incompletebuffer.Length == 0) { numPackets = 0; break; } si.Frombytes(incompletebuffer, 0); } else { si.Frombytes(packet, offset); } numProcessed++; ProcessPacket(si); } eq.ProcessSpawnList(f1.SpawnList); eq.ProcessGroundItemList(f1.GroundItemList); } } catch (Exception ex) { LogLib.WriteLine("Error: ProcessPacket: ", ex); } ProcessedPackets(packet, bytes, offset); }
//******************************************************************** /// <summary> Wait for a message to arrive </summary> public void Receive() { if (GetNetworkStream?.CanRead == true) { // Issue an asynchronous read GetNetworkStream.BeginRead(GetRawBuffer, 0, GetSizeOfRawBuffer, GetCallbackReadMethod, null); } else { LogLib.WriteLine("Error CSocketClient.Receive(): Socket Closed"); } }
/// <summary> Function to send a raw buffer to the server </summary> /// <param name="pRawBuffer"> RefType: A Raw buffer of bytes to send </param> public void Send(byte[] pRawBuffer) { if (GetNetworkStream?.CanWrite == true) { // Issue an asynchronus write GetNetworkStream.BeginWrite(pRawBuffer, 0, pRawBuffer.GetLength(0), GetCallbackWriteMethod, null); } else { LogLib.WriteLine("Error CSocketClient.Send(Byte[]): Socket Closed"); } }
//******************************************************************** /// <summary> Called when a message is sent </summary> /// <param name="ar"> RefType: An async result interface </param> private void SendComplete(IAsyncResult ar) { try { // Is the Network Stream object valid if (GetNetworkStream.CanWrite) { GetNetworkStream.EndWrite(ar); LogLib.WriteLine("CSocketClient.SendComplete(): GetNetworkStream.EndWrite()", LogLevel.Debug); } } catch (Exception ex) { LogLib.WriteLine("Error CSocketClient.SendComplete(): ", ex); } }
private void IncompleteCopy(byte[] packet, int bytes, int offset) { incompleteCount = bytes - offset; try { Array.Copy(packet, offset, incompletebuffer, 0, incompleteCount); } catch (Exception ex) { LogLib.WriteLine("Error: ProcessPacket(): Copy to Incomplete Buffer: ", ex); LogLib.WriteLine($"Packet Size: {packet.Length} Offset: {offset}"); LogLib.WriteLine($"Buffer Size: {incompletebuffer.Length} Incomplete Size: {incompleteCount}"); } }
//******************************************************************** public void Tick() { int Request; try { if (!RequestPending) { if (NewProcessID > 0 && !mbGetProcessInfo) { if (!send_process) { // We have a request to change the process Request = (int)RequestTypes.SET_PROCESSINFO; SendData(BitConverter.GetBytes(Request)); send_process = true; } else { SendData(BitConverter.GetBytes(NewProcessID)); send_process = false; NewProcessID = 0; mbGetProcessInfo = true; } } else { RequestPending = true; Request = (int)(RequestTypes.ZONE | RequestTypes.PLAYER | RequestTypes.TARGET | RequestTypes.MOBS | RequestTypes.GROUND_ITEMS | RequestTypes.WORLD); if (mbGetProcessInfo && NewProcessID == 0) { mbGetProcessInfo = false; Request |= (int)RequestTypes.GET_PROCESSINFO; } SendData(BitConverter.GetBytes(Request)); } } } catch (Exception ex) { LogLib.WriteLine("Error: timPackets_Tick: ", ex); } }
public void Load(string filename) { FileStream fs = null; try { fs = new FileStream(filename, FileMode.Open); SoapFormatter sf1 = new SoapFormatter(); Instance = (SmtpSettings)sf1.Deserialize(fs); Instance.prefsDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "MySEQ"); } catch (Exception ex) { LogLib.WriteLine("Error in SmtpSettings.Load(): ", ex); } fs?.Close(); }
public void AddToAlerts(List <string> list, string additem) { // only add to list, if not in list already try { foreach (var item in list) { if (string.Compare(item, additem, true) == 0) { return; } } list.Add(additem); } catch (Exception ex) { LogLib.WriteLine($"Error Adding Alert for {additem}: ", ex); } }
public void Load(string filename) { FileStream fs = null; bool otherLoad = false; try { fs = new FileStream(filename, FileMode.Open); SoapFormatter sf1 = new SoapFormatter(); Settings.Instance = (Settings)sf1.Deserialize(fs); } catch (Exception ex) { LogLib.WriteLine("Error in Settings.Load(): ", ex); otherLoad = true; } String myPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "MySEQ"); Settings.Instance.prefsDir = myPath; if (fs != null) { fs.Close(); } if (otherLoad) { // Try manually loading directly try { XmlTextReader reader = new XmlTextReader(filename); while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element) { switch (reader.Name) { case "ipAddress1": IPAddress1 = reader.ReadElementContentAsString(); break; case "ipAddress2": IPAddress2 = reader.ReadElementContentAsString(); break; case "ipAddress3": IPAddress3 = reader.ReadElementContentAsString(); break; case "ipAddress4": IPAddress4 = reader.ReadElementContentAsString(); break; case "ipAddress5": IPAddress5 = reader.ReadElementContentAsString(); break; case "currentIPAddress": CurrentIPAddress = reader.ReadElementContentAsInt(); break; case "port": Port = reader.ReadElementContentAsInt(); break; case "autoConnect": AutoConnect = reader.ReadElementContentAsBoolean(); break; case "rangeCircle": RangeCircle = reader.ReadElementContentAsInt(); break; case "updateDelay": UpdateDelay = reader.ReadElementContentAsInt(); break; case "showPCNames": ShowPCNames = reader.ReadElementContentAsBoolean(); break; case "showNPCNames": ShowNPCNames = reader.ReadElementContentAsBoolean(); break; case "showNPCCorpseNames": ShowNPCCorpseNames = reader.ReadElementContentAsBoolean(); break; case "showPlayerCorpseNames": ShowPlayerCorpseNames = reader.ReadElementContentAsBoolean(); break; case "gridInterval": GridInterval = reader.ReadElementContentAsInt(); break; case "SpawnSize": SpawnDrawSize = reader.ReadElementContentAsInt(); break; case "colorRangeCircle": ColorRangeCircle = reader.ReadElementContentAsBoolean(); break; case "drawFoV": DrawFoV = reader.ReadElementContentAsBoolean(); break; case "showZoneName": ShowZoneName = reader.ReadElementContentAsBoolean(); break; case "showCharName": ShowCharName = reader.ReadElementContentAsBoolean(); break; case "sodCon": SoDCon = reader.ReadElementContentAsBoolean(); break; case "sofCon": SoFCon = reader.ReadElementContentAsBoolean(); break; case "defaultCon": DefaultCon = reader.ReadElementContentAsBoolean(); break; case "showTargetInfo": ShowTargetInfo = reader.ReadElementContentAsBoolean(); break; case "smallTargetInfo": SmallTargetInfo = reader.ReadElementContentAsBoolean(); break; case "autoSelectEQTarget": AutoSelectEQTarget = reader.ReadElementContentAsBoolean(); break; case "mapDir": MapDir = reader.ReadElementContentAsString(); break; case "FilterDir": FilterDir = reader.ReadElementContentAsString(); break; case "cfgDir": CfgDir = reader.ReadElementContentAsString(); break; case "logDir": LogDir = reader.ReadElementContentAsString(); break; case "timerDir": TimerDir = reader.ReadElementContentAsString(); break; case "showPlayers": ShowPlayers = reader.ReadElementContentAsBoolean(); break; case "showNPCs": ShowNPCs = reader.ReadElementContentAsBoolean(); break; case "showCorpses": ShowCorpses = reader.ReadElementContentAsBoolean(); break; case "showPCCorpses": ShowPCCorpses = reader.ReadElementContentAsBoolean(); break; case "showMyCorpse": ShowMyCorpse = reader.ReadElementContentAsBoolean(); break; case "showInvis": ShowInvis = reader.ReadElementContentAsBoolean(); break; case "showMounts": ShowMounts = reader.ReadElementContentAsBoolean(); break; case "showFamiliars": ShowFamiliars = reader.ReadElementContentAsBoolean(); break; case "showPets": ShowPets = reader.ReadElementContentAsBoolean(); break; case "showPVP": ShowPVP = reader.ReadElementContentAsBoolean(); break; case "showPVPLevel": ShowPVPLevel = reader.ReadElementContentAsBoolean(); break; case "showNPCLevels": ShowNPCLevels = reader.ReadElementContentAsBoolean(); break; case "autoSelectSpawnList": AutoSelectSpawnList = reader.ReadElementContentAsBoolean(); break; case "keepCentered": KeepCentered = reader.ReadElementContentAsBoolean(); break; case "autoExpand": AutoExpand = reader.ReadElementContentAsBoolean(); break; case "saveSpawnLogs": SaveSpawnLogs = reader.ReadElementContentAsBoolean(); break; case "spawnCountdown": SpawnCountdown = reader.ReadElementContentAsBoolean(); break; case "forceDistinct": ForceDistinct = reader.ReadElementContentAsBoolean(); break; case "forceDistinctText": ForceDistinctText = reader.ReadElementContentAsBoolean(); break; case "useDynamicAlpha": UseDynamicAlpha = reader.ReadElementContentAsBoolean(); break; case "fadedLines": FadedLines = reader.ReadElementContentAsInt(); break; case "filterGroundItems": FilterGroundItems = reader.ReadElementContentAsBoolean(); break; case "filterNPCs": FilterNPCs = reader.ReadElementContentAsBoolean(); break; case "filterPlayers": FilterPlayers = reader.ReadElementContentAsBoolean(); break; case "filterMapLines": FilterMapLines = reader.ReadElementContentAsBoolean(); break; case "filterMapText": FilterMapText = reader.ReadElementContentAsBoolean(); break; case "filterSpawnPoints": FilterSpawnPoints = reader.ReadElementContentAsBoolean(); break; case "filterNPCCorpses": FilterNPCCorpses = reader.ReadElementContentAsBoolean(); break; case "filterPlayerCorpses": FilterPlayerCorpses = reader.ReadElementContentAsBoolean(); break; } } } reader.Close(); } catch (Exception ex) { LogLib.WriteLine("Error in Settings.Load(): ", ex); otherLoad = true; } } }