Exemple #1
0
        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 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();
            }
        }