Esempio n. 1
0
        private static byte[] GetBanner(bool forceUpdate)
        {
            if (_UpdatingBanner || !UpdateStats(forceUpdate))
            {
                return(BannerResponse);
            }

            _UpdatingBanner = true;

            VitaNexCore.TryCatch(
                () =>
            {
                using (var g = Graphics.FromImage(_Banner))
                {
                    g.Clear(Color.Transparent);

                    if (BannerHandler != null)
                    {
                        BannerHandler(_Banner, g);
                    }
                    else
                    {
                        var hf = new Font("Tahoma", 20f);
                        var nf = new Font("Tahoma", 10f);

                        var hp = new Pen(Brushes.Red);
                        var np = new Pen(Brushes.Black);

                        g.DrawRectangle(hp, 0f, 0f, _Banner.Width - 1f, _Banner.Height - 1f);

                        g.DrawString(ServerList.ServerName, hf, hp.Brush, 5f, 2.5f);

                        var ipep = Listener.EndPoints.LastOrDefault();

                        if (ipep != null)
                        {
                            var ipp = IPAddressExtUtility.FindPublic();

                            if (ipp != null)
                            {
                                g.DrawString(String.Format("{0}:{1}", ipp, ipep.Port), nf, np.Brush, 10f, 35f);
                            }
                            else
                            {
                                foreach (var ip in ipep.Address.FindInternal())
                                {
                                    g.DrawString(String.Format("{0}:{1}", ip, ipep.Port), nf, np.Brush, 10f, 35f);
                                    break;
                                }
                            }
                        }
                    }

                    g.Save();

                    using (var ms = new MemoryStream())
                    {
                        _Banner.Save(ms, ImageFormat.Png);

                        BannerResponse = ms.ToArray();
                    }

                    _Banner.Save(IOUtility.GetSafeFilePath(VitaNexCore.CacheDirectory + "/WebStats.png", true), ImageFormat.Png);
                }
            },
                CMOptions.ToConsole);

            _UpdatingBanner = false;

            return(BannerResponse);
        }
Esempio n. 2
0
        private static bool UpdateJson(bool forceUpdate)
        {
            if (_UpdatingJson || !UpdateStats(forceUpdate))
            {
                return(false);
            }

            _UpdatingJson = true;

            VitaNexCore.TryCatch(
                () =>
            {
                var root = _Json;

                root["vnc_version"] = VitaNexCore.Version.Value;
                root["mod_version"] = CMOptions.ModuleVersion;

                root["last_update"]       = _LastUpdate.ToString(CultureInfo.InvariantCulture);
                root["last_update_stamp"] = _LastUpdate.ToTimeStamp().Stamp;

                if (CMOptions.DisplayServer)
                {
                    var server = root.Intern("server", o => o as Dictionary <string, object> ?? new Dictionary <string, object>());

                    server["name"] = ServerList.ServerName;

                    var ipep = Listener.EndPoints.LastOrDefault();

                    if (ipep != null)
                    {
                        var ipp = IPAddressExtUtility.FindPublic();

                        if (ipp != null)
                        {
                            server["host"] = ipp.ToString();
                            server["port"] = ipep.Port;
                        }
                        else
                        {
                            foreach (var ip in ipep.Address.FindInternal())
                            {
                                server["host"] = ip.ToString();
                                server["port"] = ipep.Port;
                                break;
                            }
                        }
                    }

                    server["os"]  = Environment.OSVersion.VersionString;
                    server["net"] = Environment.Version.ToString();

#if SERVUO
                    server["core"] = "ServUO";
#elif JUSTUO
                    server["core"] = "JustUO";
#else
                    server["core"] = "RunUO";
#endif

                    var an = Core.Assembly.GetName();

                    server["assembly"]         = an.Name;
                    server["assembly_version"] = an.Version.ToString();

                    root["server"] = server;
                }
                else
                {
                    var server = root.Intern("server", o => o as Dictionary <string, object>);

                    if (server != null)
                    {
                        server.Clear();
                    }

                    root.Remove("server");
                }

                if (CMOptions.DisplayStats)
                {
                    var stats = root.Intern("stats", o => o as Dictionary <string, object> ?? new Dictionary <string, object>());

                    foreach (var kv in Stats)
                    {
                        var o = kv.Value.Value;

                        if (o is DateTime)
                        {
                            var dt = (DateTime)o;

                            stats[kv.Key]            = dt.ToString(CultureInfo.InvariantCulture);
                            stats[kv.Key + "_stamp"] = Math.Floor(dt.ToTimeStamp().Stamp);
                        }
                        else if (o is TimeSpan)
                        {
                            var ts = (TimeSpan)o;

                            stats[kv.Key]            = ts.ToString();
                            stats[kv.Key + "_stamp"] = ts.TotalSeconds;
                        }
                        else
                        {
                            stats[kv.Key] = o;
                        }
                    }

                    root["stats"] = stats;
                }
                else
                {
                    var stats = root.Intern("stats", o => o as Dictionary <string, object>);

                    if (stats != null)
                    {
                        stats.Clear();
                    }

                    root.Remove("stats");
                }

                if (CMOptions.DisplayPlayers)
                {
                    var players = root.Intern("players", o => o as List <object> ?? new List <object>());

                    var playerIndex = 0;

                    foreach (var p in Snapshot.SelectMany(s => s.Value))
                    {
                        var player = players.Intern(
                            playerIndex,
                            o => o as Dictionary <string, object> ?? new Dictionary <string, object>());

                        player["id"]      = p.Serial.Value;
                        player["name"]    = p.RawName ?? String.Empty;
                        player["title"]   = p.Title ?? String.Empty;
                        player["profile"] = p.Profile ?? String.Empty;

                        player["fame"]  = p.Fame;
                        player["karma"] = p.Karma;
                        player["kills"] = p.Kills;

                        if (CMOptions.DisplayPlayerGuilds && p.Guild != null)
                        {
                            var guild = player.Intern("guild", o => o as Dictionary <string, object> ?? new Dictionary <string, object>());

                            guild["id"]   = p.Guild.Id;
                            guild["name"] = p.Guild.Name ?? String.Empty;
                            guild["abbr"] = p.Guild.Abbreviation ?? String.Empty;

                            player["guild"] = guild;
                        }
                        else
                        {
                            var guild = player.Intern("guild", o => o as Dictionary <string, object>);

                            if (guild != null)
                            {
                                guild.Clear();
                            }

                            player.Remove("guild");
                        }

                        if (CMOptions.DisplayPlayerStats)
                        {
                            var stats = player.Intern("stats", o => o as Dictionary <string, object> ?? new Dictionary <string, object>());

                            stats["cap"]   = p.StatCap;
                            stats["total"] = p.RawStatTotal;

                            stats["str"]     = p.Str;
                            stats["str_raw"] = p.RawStr;

                            stats["dex"]     = p.Dex;
                            stats["dex_raw"] = p.RawDex;

                            stats["int"]     = p.Int;
                            stats["int_raw"] = p.RawInt;

                            stats["hits"]     = p.Hits;
                            stats["hits_max"] = p.HitsMax;

                            stats["stam"]     = p.Stam;
                            stats["stam_max"] = p.StamMax;

                            stats["mana"]     = p.Mana;
                            stats["mana_max"] = p.ManaMax;

                            player["stats"] = stats;
                        }
                        else
                        {
                            var stats = player.Intern("stats", o => o as Dictionary <string, object>);

                            if (stats != null)
                            {
                                stats.Clear();
                            }

                            player.Remove("stats");
                        }

                        if (CMOptions.DisplayPlayerSkills)
                        {
                            var skills = player.Intern("skills", o => o as List <object> ?? new List <object>());

                            var skillIndex = 0;

                            foreach (var s in SkillInfo.Table)
                            {
                                var skill = skills.Intern(skillIndex, o => o as Dictionary <string, object> ?? new Dictionary <string, object>());

                                skill["id"]    = s.SkillID;
                                skill["name"]  = s.Name;
                                skill["base"]  = p.Skills[s.SkillID].Base;
                                skill["value"] = p.Skills[s.SkillID].Value;
                                skill["cap"]   = p.Skills[s.SkillID].Cap;

                                skills.AddOrReplace(skill);

                                ++skillIndex;
                            }

                            skills.TrimEndTo(skillIndex);

                            player["skills"] = skills;
                        }
                        else
                        {
                            var skills = player.Intern("skills", o => o as List <object>);

                            if (skills != null)
                            {
                                skills.Free(true);
                            }

                            player.Remove("skills");
                        }

                        if (CMOptions.DisplayPlayerEquip)
                        {
                            var equip = player.Intern("equip", o => o as List <object> ?? new List <object>());

                            var equipIndex = 0;

                            foreach (var i in p.Items)
                            {
                                var item = equip.Intern(equipIndex, o => o as Dictionary <string, object> ?? new Dictionary <string, object>());

                                item["id"]    = i.Serial.Value;
                                item["type"]  = i.GetType().Name;
                                item["layer"] = (int)i.Layer;
                                item["art"]   = i.ItemID;
                                item["hue"]   = i.Hue;
                                item["name"]  = i.ResolveName();

                                equip.AddOrReplace(item);

                                ++equipIndex;
                            }

                            equip.TrimEndTo(equipIndex);

                            player["equip"] = equip;
                        }
                        else
                        {
                            var equip = player.Intern("equip", o => o as List <object>);

                            if (equip != null)
                            {
                                equip.Free(true);
                            }

                            player.Remove("equip");
                        }

                        players.AddOrReplace(player);

                        ++playerIndex;
                    }

                    players.TrimEndTo(playerIndex);

                    root["players"] = players;
                }
                else
                {
                    var players = root.Intern("players", o => o as List <object>);

                    if (players != null)
                    {
                        players.Free(true);
                    }

                    root.Remove("players");
                }

                JsonResponse = Json.Encode(root);

                File.WriteAllText(IOUtility.GetSafeFilePath(VitaNexCore.CacheDirectory + "/WebStats.json", true), JsonResponse);
            },
                CMOptions.ToConsole);

            _UpdatingJson = false;

            return(true);
        }
Esempio n. 3
0
        private static bool UpdateJson(bool forceUpdate)
        {
            if (_UpdatingJson || !UpdateStats(forceUpdate))
            {
                return(false);
            }

            _UpdatingJson = true;

            VitaNexCore.TryCatch(
                () =>
            {
                _Json["vnc_version"] = VitaNexCore.Version.Value;
                _Json["mod_version"] = CMOptions.ModuleVersion;

                _Json["last_update"]       = _LastUpdate.ToString(CultureInfo.InvariantCulture);
                _Json["last_update_stamp"] = _LastUpdate.ToTimeStamp().Stamp;

                if (CMOptions.DisplayServer)
                {
                    var server = _Json.Intern("server", o => o as Dictionary <string, object> ?? new Dictionary <string, object>());

                    server["name"] = ServerList.ServerName;

                    var ipep = Listener.EndPoints.LastOrDefault();

                    if (ipep != null)
                    {
                        var ipp = IPAddressExtUtility.FindPublic();

                        if (ipp != null)
                        {
                            server["host"] = ipp.ToString();
                            server["port"] = ipep.Port;
                        }
                        else
                        {
                            foreach (var ip in ipep.Address.FindInternal())
                            {
                                server["host"] = ip.ToString();
                                server["port"] = ipep.Port;
                                break;
                            }
                        }
                    }

                    server["os"]  = Environment.OSVersion.VersionString;
                    server["net"] = Environment.Version.ToString();

#if SERVUO
                    server["core"] = "ServUO";
#elif JUSTUO
                    server["core"] = "JustUO";
#else
                    server["core"] = "RunUO";
#endif

                    var an = Core.Assembly.GetName();

                    server["assembly"]         = an.Name;
                    server["assembly_version"] = an.Version.ToString();

                    _Json["server"] = server;
                }
                else
                {
                    var server = _Json.Intern("server", o => o as Dictionary <string, object>);

                    if (server != null)
                    {
                        server.Clear();
                    }

                    _Json.Remove("server");
                }

                if (CMOptions.DisplayStats)
                {
                    var stats = _Json.Intern("stats", o => o as Dictionary <string, object> ?? new Dictionary <string, object>());

                    foreach (var kv in Stats)
                    {
                        var o = kv.Value.Value;

                        if (o is DateTime)
                        {
                            var dt = (DateTime)o;

                            stats[kv.Key]            = dt.ToString(CultureInfo.InvariantCulture);
                            stats[kv.Key + "_stamp"] = Math.Floor(dt.ToTimeStamp().Stamp);
                        }
                        else if (o is TimeSpan)
                        {
                            var ts = (TimeSpan)o;

                            stats[kv.Key]            = ts.ToString();
                            stats[kv.Key + "_stamp"] = ts.TotalSeconds;
                        }
                        else
                        {
                            stats[kv.Key] = o;
                        }
                    }

                    _Json["stats"] = stats;
                }
                else
                {
                    var stats = _Json.Intern("stats", o => o as Dictionary <string, object>);

                    if (stats != null)
                    {
                        stats.Clear();
                    }

                    _Json.Remove("stats");
                }

                File.WriteAllText(
                    IOUtility.GetSafeFilePath(VitaNexCore.CacheDirectory + "/WebStats.json", true),
                    Json.Encode(_Json));
            },
                CMOptions.ToConsole);

            _UpdatingJson = false;

            return(true);
        }