private void P99LogMonitor_OnNewLineCaptured(string text) { Map aMap = (Map)mapTabs.TabPages["youTab"].Controls["zoneMap"]; string line; string[] blockDelim = { "\n\0" }; string[] splitDelim = { "] " }; string newZone = "You have entered "; string location = "Your Location is "; string[] tempLocation; foreach (string split in text.Split(blockDelim, StringSplitOptions.None)) { line = split.Split(splitDelim, StringSplitOptions.None)[1]; if (line.StartsWith(newZone)) { zone = line.Remove(0, newZone.Length); zone = zone.TrimEnd('.'); PlayerManagement.GetPlayer(toonName).Zone = zone; // Load map using zone Invoke(new MethodInvoker(delegate() { LoadMap(); })); } else if (line.StartsWith(location)) { if (toonName == null) { return; } tempLocation = line.Remove(0, location.Length).Split(','); PlayerManagement.GetPlayer(toonName).SetLocation(double.Parse(tempLocation[1]), double.Parse(tempLocation[0])); PlayerLoggingUDPClient.Send('L', PlayerManagement.GetPlayer(toonName)); } } }
private void AMap_OnDraw(Graphics g) { // Draw players. Map aMap = (Map)mapTabs.TabPages["youTab"].Controls["zoneMap"]; float X, Y; foreach (PlayerManagement.Player aPlayer in PlayerManagement.GetPlayers()) { if (PlayerManagement.GetPlayer(aPlayer.Name).Location != null) { X = aMap.ConvertCoordXToPanel((float)PlayerManagement.GetPlayer(aPlayer.Name).Location.X + 8); Y = aMap.ConvertCoordYToPanel((float)PlayerManagement.GetPlayer(aPlayer.Name).Location.Y + 8); if (aPlayer.Zone == zone) { g.FillEllipse(PlayerManagement.GetBrush(aPlayer.Name), X, Y, 2, 2); g.DrawString(aPlayer.Name, font, PlayerManagement.GetBrush(aPlayer.Name), X, Y + 1); } } } }
private void P99LogMonitor_OnNewFileCaptured(string filename) { Map aMap = (Map)mapTabs.TabPages["youTab"].Controls["zoneMap"]; string[] fileSplit = filename.Split('_'); if (toonName != null) { PlayerManagement.RemovePlayer(toonName); PlayerLoggingUDPClient.Send('R', PlayerManagement.GetPlayer(toonName)); } toonName = fileSplit[fileSplit.Length - 2]; // Open a stream using the changed file. FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); // We need to read in reverse to find the "Welcome to Everquest!" session start key; string line = ""; string[] splitDelim = { "] " }; string lookFor = "You have entered "; using (StreamReader sr = new StreamReader(fs)) { while (!sr.EndOfStream) { line = sr.ReadLine(); if (line == "") { continue; } line = line.Split(splitDelim, StringSplitOptions.None)[1]; if (line.StartsWith(lookFor)) { zone = line.Remove(0, lookFor.Length); zone = zone.TrimEnd('.'); } } // Load map based on zone name. Invoke(new MethodInvoker(delegate() { LoadMap(); })); logMonitorStatus.Text = "Monitor Status: Can't find zone map " + zone; fs.Seek(0, SeekOrigin.End); } PlayerManagement.AddPlayer(toonName, zone); PlayerLoggingUDPClient.Send('A', PlayerManagement.GetPlayer(toonName)); }
private void shareLocationBox_Click(object sender, EventArgs e) { if (!shareLocationBox.Checked) { // Connect to server string[] hostandport = connectionInfo.Text.Split(':'); try { PlayerLoggingUDPClient.StartClient(hostandport[0], int.Parse(hostandport[1])); shareLocationBox.Checked = true; connectionStatus.Text = "Connection Status: Connected"; if (toonName != null) { if (PlayerManagement.GetPlayer(toonName) != null) { PlayerLoggingUDPClient.Send('A', PlayerManagement.GetPlayer(toonName)); } } } catch (Exception) { shareLocationBox.Checked = false; connectionStatus.Text = "Connection Status: Connection Refused."; } } else { if (toonName != null) { if (PlayerManagement.GetPlayer(toonName) != null) { PlayerLoggingUDPClient.Send('R', PlayerManagement.GetPlayer(toonName)); } } PlayerLoggingUDPClient.StopClient(); shareLocationBox.Checked = false; connectionStatus.Text = "Connection Status: Disconnected."; } }
private void ReceivedMessage(IAsyncResult ar) { IPEndPoint endpoint = (IPEndPoint)(ar.AsyncState); try { if (!connected) { return; } byte[] receivedBytes = instance.client.EndReceive(ar, ref endpoint); instance.client.BeginReceive(new AsyncCallback(ReceivedMessage), e); string json = Encoding.ASCII.GetString(receivedBytes); PlayerWrapper aWrappedPlayer = (PlayerWrapper) new JavaScriptSerializer().Deserialize(json, typeof(PlayerWrapper)); if (aWrappedPlayer.Command == 'A') { // Add user. PlayerManagement.AddPlayer(aWrappedPlayer.Player); } else if (aWrappedPlayer.Command == 'L') { // Update location. PlayerManagement.GetPlayer(aWrappedPlayer.Player.Name).SetLocation(aWrappedPlayer.Player.Location.X, aWrappedPlayer.Player.Location.Y); } else if (aWrappedPlayer.Command == 'R') { // Remove user. PlayerManagement.RemovePlayer(aWrappedPlayer.Player.Name); } } catch (SocketException se) { connected = false; instance.client.Close(); } }