//******************************************************************** /// <summary> Function used to disconnect from the server </summary> public void Disconnect() { LogLib.WriteLine("Entering in CSocketClient.Disconnect()", LogLevel.Trace); // Close down the connection if (GetNetworkStream != null) { GetNetworkStream.Close(); } if (GetTcpClient != null) { GetTcpClient.Close(); } if (GetClientSocket != null) { GetClientSocket.Close(); } // Clean up the connection state GetClientSocket = null; GetNetworkStream = null; GetTcpClient = null; LogLib.WriteLine("Exiting in CSocketClient.Disconnect()", LogLevel.Trace); }
// Public Methods //******************************************************************** /// <summary> Function used to connect to a server </summary> /// <param name="strIpAddress"> RefType: The address to connect to </param> /// <param name="iPort"> SimType: The Port to connect to </param> public void Connect(String strIpAddress, Int16 iPort) { LogLib.WriteLine("Entering in CSocketClient.Connect()", LogLevel.Trace); try { if (GetNetworkStream == null) { // Set the Ipaddress and Port GetIpAddress = strIpAddress; GetPort = iPort; // Attempt to establish a connection GetTcpClient = new TcpClient(GetIpAddress, GetPort); GetNetworkStream = GetTcpClient.GetStream(); // Set these socket options GetTcpClient.ReceiveBufferSize = 1048576; GetTcpClient.SendBufferSize = 1048576; GetTcpClient.NoDelay = true; GetTcpClient.LingerState = new System.Net.Sockets.LingerOption(false, 0); // Start to receive messages Receive(); } } catch (System.Net.Sockets.SocketException e) { throw new Exception(e.Message, e.InnerException); } LogLib.WriteLine("Entering in CSocketClient.Connect()", LogLevel.Trace); }
// Constructor, Finalize, Dispose //******************************************************************** /// <summary> Constructor for client support </summary> /// <param name="iSizeOfRawBuffer"> SimType: The size of the raw buffer </param> /// <param name="pUserArg"> RefType: A Reference to the Users arguments </param> /// <param name="pfnMessageHandler"> DelType: Reference to the user defined message handler method </param> /// <param name="pfnCloseHandler"> DelType: Reference to the user defined close handler method </param> /// <param name="pfnErrorHandler"> DelType: Reference to the user defined error handler method </param> public CSocketClient(Int32 iSizeOfRawBuffer, Object pUserArg, MESSAGE_HANDLER pfnMessageHandler, CLOSE_HANDLER pfnCloseHandler, ERROR_HANDLER pfnErrorHandler) { LogLib.WriteLine("Entering in CSocketClient.CSocketClient()", LogLevel.Trace); // Create the raw buffer GetSizeOfRawBuffer = iSizeOfRawBuffer; GetRawBuffer = new Byte[GetSizeOfRawBuffer]; // Save the user argument GetUserArg = pUserArg; // Set the handler methods GetMessageHandler = pfnMessageHandler; GetCloseHandler = pfnCloseHandler; GetErrorHandler = pfnErrorHandler; // Set the async socket method handlers GetCallbackReadMethod = new AsyncCallback(ReceiveComplete); GetCallbackWriteMethod = new AsyncCallback(SendComplete); // Init the dispose flag IsDisposed = false; LogLib.WriteLine("Exiting in CSocketClient.CSocketClient()", LogLevel.Trace); }
public void ColumnsAdd(string ColumnName, int ColumnWidth, HorizontalAlignment CoulumnAlign) { try { listView.Columns.Add(ColumnName, ColumnWidth, CoulumnAlign); } catch (Exception ex) { LogLib.WriteLine("Error in ListViewPanel.ColumnsAdd: ", ex); } }
private void LogSpawns(string msg) { if ((!Settings.Instance.SaveSpawnLogs) || (mapName.Length < 3)) { return; } try { string logpath = Settings.Instance.LogDir; string logfile = string.Format($"spawns-{{0}}-{mapName}.txt", DateTime.Now.ToString("MM-dd-yyyy")); if (!Directory.Exists(logpath)) { Directory.CreateDirectory(logpath); } FileStream fs = new FileStream(Path.Combine(logpath, logfile), FileMode.Append, FileAccess.Write, FileShare.ReadWrite); StreamWriter spawnLog = new StreamWriter(fs); spawnLog.WriteLine($"[{DateTime.Now:MM/dd/yyyy HH:mm:ss.ff}] {msg}"); spawnLog.Close(); fs.Close(); } catch (Exception ex) { LogLib.WriteLine("Error in LogSpawns():", ex); } }
public MapText(string line) { IFormatProvider NumFormat = new CultureInfo("en-US"); var dataRecord = line.Remove(0, 1); var parsedline = dataRecord.Split(",".ToCharArray()); if (parsedline.Length >= 7) { x = -(int)float.Parse(parsedline[0], NumFormat); y = -(int)float.Parse(parsedline[1], NumFormat); z = (int)float.Parse(parsedline[2], NumFormat); var r = int.Parse(parsedline[3], NumFormat); var g = int.Parse(parsedline[4], NumFormat); var b = int.Parse(parsedline[5], NumFormat); color = new SolidBrush(Color.FromArgb(r, g, b)); size = int.Parse(parsedline[6], NumFormat); for (var i = 7; i < parsedline.Length; i++) { label = parsedline[i]; } } else { LogLib.WriteLine("Warning - Label-line has an invalid format and will be ignored.", LogLevel.Warning); } }
public void SearchName(String name) { try { Regex regEx = new Regex(".*" + txtSpawnList.Text + ".*", RegexOptions.IgnoreCase); foreach (ListViewItem lstItem in listView.Items) { // Compile the regular expression. // Match the regular expression pattern against a text string. if (regEx.Match(lstItem.Text).Success) { lstItem.EnsureVisible(); lstItem.Selected = true; break; } } } catch (Exception ex) { LogLib.WriteLine("Error in ListViewPanel.txtSpawnList_TextChanged: ", ex); } }
public bool Loadmap(string filename) { try { if (File.Exists(filename)) { if (filename.EndsWith("_1.txt") || filename.EndsWith("_2.txt") || filename.EndsWith("_3.txt")) { if (!LoadLoYMap(filename, false)) { return(false); } } else if (!LoadLoYMap(filename, true)) { return(false); } return(true); } return(false); } catch (Exception ex) { var msg = $"Failed to load map {filename}: {ex.Message}"; LogLib.WriteLine(msg); return(false); } }
public void loadDummyMap(string mapname) { LogLib.WriteLine("Entering EQMap.loadDummyMap()", LogLevel.Trace); OnExitMap(); ClearMap(); eq.ClearMapStructures(); mapCon.SetDistinctPens(); eq.shortname = mapname; if (mapPane != null) { mapPane.scale.Value = 100M; } //if (mapCon != null) // mapCon.scale = 1.0f; //eq.NewZone = true; OnEnterMap(); LogLib.WriteLine("Exiting EQMap.loadDummyMap()", LogLevel.Trace); }
public event EnterMapHandler EnterMap; // Fires when the map is loaded protected void OnExitMap() { LogLib.WriteLine("Entering OnExitMap", LogLevel.Trace); if (ExitMap != null) { ExitMap(this); } if (mapCon != null) { // reset spawn information window mapCon.lblMobInfo.Text = "Spawn Information Window"; mapCon.lblMobInfo.BackColor = System.Drawing.Color.White; mapCon.lblMobInfo.Visible = true; eq.selectedID = 99999; eq.SpawnX = -1.0f; eq.SpawnY = -1.0f; } LogLib.WriteLine("Exiting OnExitMap", LogLevel.Trace); }
internal bool LoadLoYMapInternal(string filename) //ingame EQ format { var numtexts = 0; var numlines = 0; var curLine = 0; if (!File.Exists(filename)) { LogLib.WriteLine($"File not found loading {filename} in loadLoYMap", LogLevel.Error); return(false); } LogLib.WriteLine($"Loading Zone Map (LoY): {filename}"); foreach (var line in File.ReadAllLines(filename)) { if (line.StartsWith("L") || line.StartsWith("P")) { ParseLP(line, ref numtexts, ref numlines); curLine++; } else { LogLib.WriteLine($"Warning - {line} in map '{filename}' has an invalid format and will be ignored.", LogLevel.Warning); } } LogLib.WriteLine($"{curLine} lines processed.", LogLevel.Debug); LogLib.WriteLine($"Loaded {Lines.Count} lines", LogLevel.Debug); return(numtexts > 0 || Lines.Count > 0); }
//******************************************************************** /// <summary> Called when a socket error occurs </summary> /// <param name="pSocket"> The SocketClient object the message came from </param> /// <param name="pException"> The reason for the error </param> public void ErrorHandler(CSocketClient pSocket, Exception pException) { LogLib.WriteLine("Error with ErrorHandler(): " + pException.Message); MessageBox.Show(pException.Message); }
public void AddToAlerts(ArrayList list, string additem) { // only add to list, if not in list already try { foreach (string item in list) { if (string.Compare(item, additem, true) == 0) { return; } } list.Add(additem); } catch (Exception ex) { LogLib.WriteLine(String.Format("Error Adding Alert for {0}: ", additem), ex); return; } }
private void listView_ColumnClick(object sender, ColumnClickEventArgs e) { try { curDescend = !curDescend; if (ListType == 0) { listView.ListViewItemSorter = new ListBoxComparerSpawnList(listView.Items, curDescend, e.Column); } else if (ListType == 1) { listView.ListViewItemSorter = new ListBoxComparerSpawnTimerList(listView.Items, curDescend, e.Column); } else if (ListType == 2) { listView.ListViewItemSorter = new ListBoxComparerGroundItemsList(listView.Items, curDescend, e.Column); } } catch (Exception ex) { LogLib.WriteLine("Error in ListViewPanel.listView_ColumnClick: ", ex); } }
private void TimersFileLines(string line) { var count = 0; try { Spawntimer st = new Spawntimer(line) { zone = mapName.ToLower() }; st.ZoneSpawnLoc = st.zone + st.SpawnLoc; count++; if (mobsTimer.ContainsKey(st.ZoneSpawnLoc)) { // We already know about this mob. Copy some of the information. GetKnownMobInfo(st); } else if (st.SpawnCount > 1) { SetNewMobTimeInfo(st); mobsTimer.Add(st.ZoneSpawnLoc, st); } } catch (Exception ex) { LogLib.WriteLine($"Error in LoadTimers(), processing line:\r\n{line}", ex); } LogLib.WriteLine($"Spawns read: {count}", LogLevel.Debug); }
// 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 int 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 with GetMessageHandler() in CSocketClient.ReceiveComplete(): ", ex); } // Wait for a new message Receive(); } else { LogLib.WriteLine("CSocketClient.ReceiveComplete(): Shuting Down", LogLevel.Error); throw new Exception("Shut Down"); } } } catch (Exception) { // The connection must have dropped call the CloseHandler try { GetCloseHandler(this); } catch (Exception ex) { LogLib.WriteLine("Error in CSocketClient.ReceiveComplete(): ", ex); } // Dispose of the class Dispose(); } }
// Add a new spawn, or do a re-spawn public void Spawn(Spawninfo si) { try { // ignore players boats boxes corpses and invis man races of level 1 // ignore ldon objects, mounts, pets, mercs, and familiars // ignore any mobs where name starts with "_" var various = si.IsPlayer || (si.Race == 141) || (si.Race == 533) || si.Race == 376 || si.Type == 2 || si.Type == 3; var oddtypes = si.isLDONObject || si.isEventController || si.isPet || si.isMerc || si.isFamiliar || si.isMount; if (various || oddtypes || si.Name.IndexOf("_") == 0) { return; } // If made it this far, then it is a mob that can perform alerts for proximity checks. si.alertMob = true; si.SpawnLoc = $"{si.Y:f3},{si.X:f3}"; si.ZoneSpawnLoc = $"{mapName.ToLower()}{si.Y:f3},{si.X:f3}"; if (mobsTimer.ContainsKey(si.ZoneSpawnLoc)) { // Process a true re-spawn TrueRespawn(si); } else { // First spawn ever FirstSpawn(si); } } catch (Exception ex) { LogLib.WriteLine($"Error creating new SPAWNTIMER for {si.Name}: ", ex); } }
private void listView_SelectedIndexChanged(object sender, EventArgs e) { ListView.SelectedIndexCollection sel = listView.SelectedIndices; listView.HideSelection = false; if (sel.Count > 0) { try { if (listView.Visible) { listView.Focus(); } if (ListType == 0) { eq?.SetSelectedID(int.Parse(listView.Items[sel[0]].SubItems[11].Text)); } else if (ListType == 1) { eq?.SetSelectedTimer(float.Parse(listView.Items[sel[0]].SubItems[4].Text), float.Parse(listView.Items[sel[0]].SubItems[5].Text)); } else if (ListType == 2) { eq?.SetSelectedGroundItem(float.Parse(listView.Items[sel[0]].SubItems[3].Text), float.Parse(listView.Items[sel[0]].SubItems[4].Text)); } mapCon?.Invalidate(); } catch (Exception ex) { LogLib.WriteLine("Error in ListViewPanel.listView_SelectedIndexChanged: ", ex); } } }
public bool loadMap(string filename) { LogLib.WriteLine("Entering EQMap.loadMap(filename='" + filename + "')", LogLevel.Trace); eq.mobsTimers.ResetTimers(); OnExitMap(); ClearMap(); eq.ClearMapStructures(); mapCon.SetDistinctPens(); bool rc = eq.loadMapInternal(filename); if (rc) { eq.OptimizeMap(); eq.CalculateMapLinePens(); // pre-calculate all pen colors used for map drawing. //eq.NewZone = true; OnEnterMap(); } LogLib.WriteLine("Exiting EQMap.loadMap(), rc=" + rc, LogLevel.Trace); return(rc); }
//******************************************************************** /// <summary> Called when a message is extracted from the socket </summary> /// <param name="pSocket"> The SocketClient object the message came from </param> /// <param name="iNumberOfBytes"> The number of bytes in the RawBuffer inside the SocketClient </param> private void MessageHandlerClient(CSocketClient pSocket, int iNumberOfBytes) { // Process the packet try { ProcessPacket(pSocket.GetRawBuffer, iNumberOfBytes); } catch (Exception pException) { LogLib.WriteLine("Error with ProcessPacket: " + pException.Message); } }
private void cmdReset_Click(object sender, EventArgs e) { try { txtSpawnList.Text = ""; txtSpawnList.Focus(); } catch (Exception ex) { LogLib.WriteLine("Error in ListViewPanel.cmdReset_Click: ", ex); } }
private void listView_MouseEnter(object sender, EventArgs e) { try { if (!f1.toolStripScale.Focused && !f1.toolStripZPos.Focused && !f1.toolStripZNeg.Focused && !f1.toolStripLookupBox.Focused) { listView.Focus(); } } catch (Exception ex) { LogLib.WriteLine("Error in ListViewPanel.listView_MouseEnter: ", ex); } }
private void ListViewPanel_Resize(object sender, EventArgs e) { try { txtSpawnList.Width = Width - txtSpawnList.Left; listView.Width = Width; listView.Height = Height - listView.Top; } catch (Exception ex) { LogLib.WriteLine("Error in ListViewPanel.ListViewPanel_Resize: ", ex); } }
//******************************************************************** /// <summary> Dispose </summary> public void Dispose() { try { // Flag that dispose has been called IsDisposed = true; // Disconnect the client from the server Disconnect(); } catch (Exception ex) { LogLib.WriteLine("Error in CSocketClient.Dispose(): ", ex); } }
//******************************************************************** /// <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 in 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 in 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 in CSocketClient.SendComplete(): ", ex); } }
public bool ConnectToServer(string ServerAddress, int ServerPort, bool errMsg = true) { try { if (pSocketClient != null) { Thread.Sleep(2000); pSocketClient.Dispose(); pSocketClient = null; } // Instantiate a CSocketClient object pSocketClient = new CSocketClient(100000, null, new CSocketClient.MESSAGE_HANDLER(MessageHandlerClient), new CSocketClient.CLOSE_HANDLER(CloseHandler), new CSocketClient.ERROR_HANDLER(ErrorHandler)); // Establish a connection to the server mbGetProcessInfo = true; pSocketClient.Connect(ServerAddress, (short)ServerPort); return(true); } catch (Exception pException) { string msg = String.Format("Could not connect to the server: {0}", pException.Message); LogLib.WriteLine(msg); if (errMsg) { MessageBox.Show(msg + "\r\nTry selecting a different server!", "Server Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } return(false); } }
// Saves timers to a file for the current map private void SaveTimers() { var timerfile = FileOps.CombineTimer(mapName); if (!Settings.Default.saveSpawnTimers || mapName.Length < 3) { return; } if (Voidmaps) { MustSave = false; FileOps.DeleteFile(timerfile); return; } try { MustSave = false; LastSaveTime = DateTime.Now; if (mobsTimer2.Count != 0) { var count = 0; foreach (Spawntimer st in mobsTimer2.Values) { if (st.SpawnTimer > 10 && (string.Compare(st.zone, mapName, true) == 0)) { count++; } } if (count > 0) { using (StreamWriter sw = new StreamWriter(File.Open(timerfile, FileMode.Create))) { foreach (Spawntimer st in mobsTimer2.Values) { if (st.SpawnTimer > 10 && (string.Compare(st.zone, mapName, true) == 0)) { sw.WriteLine(st.GetAsString()); } } } } } } catch (Exception ex) { LogLib.WriteLine("Error in SaveTimers():", ex); } }
protected void OnEnterMap() { LogLib.WriteLine("Entering OnEnterMap", LogLevel.Trace); if (EnterMap != null) { EnterMap(this); } LogLib.WriteLine("Exiting OnEnterMap", LogLevel.Trace); }