Exemple #1
0
        public static void ShowUpdate(JEvent data)
        {
            if (IsServerFiltered(data.server) || IsEventFiltered(data.key))
            {
                return;
            }

            string monster = data.key.Split('.')[1].Split('.')[0]
                             .Replace("Dragon_Head_Leader", "Rock_Dragon")
                             .Replace("shtrs_Defense_System", "Avatar");

            if ((data.key.Contains("killed") || data.key.Contains("death")) &&
                Settings.Default.showOnDeath)
            {
                if (Settings.Default.playSoundDeath)
                {
                    new SoundPlayer().Play();
                }
                _ShowNotification(
                    monster.Replace("_", " "),
                    "was killed in\n" + data.server + " " + data.realm,
                    false, monster); //FALSE FOR NOW
            }
            else if (data.key.Contains("new") && Settings.Default.showOnSpawn)
            {
                if (Settings.Default.playSoundSpawn)
                {
                    new SoundPlayer().Play();
                }
                _ShowNotification(
                    monster.Replace("_", " "),
                    "has spawned in\n" + data.server + " " + data.realm,
                    false, monster);
            }
            else if (data.key.Contains("many") && Settings.Default.showOnCount)
            {
                if (Settings.Default.soundOnCount)
                {
                    new SoundPlayer().Play();
                }
                _ShowNotification(
                    data.tokens["COUNT"] + " " + monster.Replace("_", " ") + "s",
                    "left in\n" + data.server + " " + data.realm,
                    false, monster);
            }
            else if (data.key.Contains("one") && Settings.Default.showOnCount)
            {
                if (Settings.Default.soundOnCount)
                {
                    new SoundPlayer().Play();
                }
                _ShowNotification(
                    "One " + monster.Replace("_", " "),
                    "left in\n" + data.server + " " + data.realm,
                    false, monster);
            }
        }
        private void ReadCallback(IAsyncResult ar)
        {
            NetworkStream ns = _client.GetStream();

            byte[] buffer = (byte[])ar.AsyncState;

            try
            {
                int read = ns.EndRead(ar);

                if (read > 0)
                {
                    //Log("\nRead " + read + " bytes.");
                    int    id  = BitConverter.ToInt16(buffer, 0);
                    string msg = Encoding.ASCII.GetString(buffer, 3, read - 3);
                    msg = msg.Replace("\r", "").Replace("\n", "");

                    if (id == (int)Packets.EVENT)
                    {
                        JEvent data = JsonConvert.DeserializeObject <JEvent>(msg);
                        if (msg.Contains("tokens"))
                        {
                            string tokenData = msg.Split(new string[] { "\"tokens\":" }, StringSplitOptions.None)[1];
                            tokenData = "[" + tokenData.Remove(tokenData.Length - 1) + "]";
                            JArray tokens = JArray.Parse(tokenData);

                            foreach (JObject o in tokens.Children <JObject>())
                            {
                                foreach (JProperty p in o.Properties())
                                {
                                    data.tokens[p.Name] = p.Value.ToString();
                                }
                            }
                        }

                        Log(data.key.Replace("stringlist", "")
                            .Replace(".", " ")
                            .Replace("0", "")
                            .Replace("1", "")
                            + " " + data.server + " " + data.realm);

                        Interface.ShowUpdate(data);
                    }
                }

                buffer = new byte[buffer.Length];
                //Log("trying to read more");
                ns.BeginRead(buffer, 0, buffer.Length, ReadCallback, buffer);
            }
            catch
            {
                Log("Reading data from RealmBot failed! Disconnecting.");
                Reconnect();
            }
        }
        public static void ShowUpdate(JEvent data)
        {
            if (IsServerFiltered(data.server) || IsEventFiltered(data.key))
                return;

            string monster = data.key.Split('.')[1].Split('.')[0]
                .Replace("Dragon_Head_Leader", "Rock_Dragon")
                .Replace("shtrs_Defense_System", "Avatar");
            if ((data.key.Contains("killed") || data.key.Contains("death"))
                && Settings.Default.showOnDeath)
            {
                if (Settings.Default.playSoundDeath)
                    new SoundPlayer().Play();
                _ShowNotification(
                    monster.Replace("_", " "),
                    "was killed in\n" + data.server + " " + data.realm,
                    false, monster); //FALSE FOR NOW
            }
            else if (data.key.Contains("new") && Settings.Default.showOnSpawn)
            {
                if (Settings.Default.playSoundSpawn)
                    new SoundPlayer().Play();
                _ShowNotification(
                    monster.Replace("_", " "),
                    "has spawned in\n" + data.server + " " + data.realm,
                    false, monster);
            }
            else if (data.key.Contains("many") && Settings.Default.showOnCount)
            {
                if (Settings.Default.soundOnCount)
                    new SoundPlayer().Play();
                _ShowNotification(
                    data.tokens["COUNT"] + " " + monster.Replace("_", " ") + "s",
                    "left in\n" + data.server + " " + data.realm,
                    false, monster);
            }
            else if (data.key.Contains("one") && Settings.Default.showOnCount)
            {
                if (Settings.Default.soundOnCount)
                    new SoundPlayer().Play();
                _ShowNotification(
                    "One " + monster.Replace("_", " "),
                    "left in\n" + data.server + " " + data.realm,
                    false, monster);
            }
        }