using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using Server;
using Server.Items;
using Server.Mobiles;
using Server.Network;
using Server.Guilds;
namespace Server.Misc
{
public class StatusPage : Timer
{
public static bool Enabled = true;
public static void Initialize()
{
if (Enabled)
new StatusPage().Start();
}
public StatusPage()
: base(TimeSpan.FromSeconds(5.0), TimeSpan.FromSeconds(60.0))
{
Priority = TimerPriority.FiveSeconds;
}
private static string Encode(string input)
{
StringBuilder sb = new StringBuilder(input);
sb.Replace("&", "&");
sb.Replace("<", "<");
sb.Replace(">", ">");
sb.Replace("\"", """);
sb.Replace("'", "'");
return sb.ToString();
}
protected override void OnTick()
{
if (!Directory.Exists("web"))
Directory.CreateDirectory("web");
using (StreamWriter op = new StreamWriter("web/status.html"))
{
op.WriteLine("<html>");
op.WriteLine(" <head>");
op.WriteLine(" <title>Shard Status</title>");
op.WriteLine(" </head>");
op.WriteLine(" <body>");
op.WriteLine(" <div style='float: right'><small>{0} UTC -07:00</small></div>", DateTime.Now);
op.WriteLine(" <h3>List of Online Players</h3>");
op.WriteLine(" <table width=\"100%\">");
op.WriteLine(" <tr>");
op.WriteLine(" <td bgcolor=\"black\"><font color=\"white\">Name</font></td><td bgcolor=\"black\"><font color=\"white\">Title</font></td><td bgcolor=\"black\"><font color=\"white\">Location</font></td>");
op.WriteLine(" </tr>");
foreach (NetState state in NetState.Instances)
{
Mobile m = state.Mobile;
if (m != null)
{
Guild g = m.Guild as Guild;
op.Write(" <tr><td>");
if (g != null)
{
op.Write(Encode(m.Name));
op.Write(" [");
string title = m.GuildTitle;
if (title != null)
title = title.Trim();
else
title = "";
if (title.Length > 0)
{
op.Write(Encode(title));
op.Write(", ");
}
op.Write(Encode(g.Abbreviation));
op.Write(']');
}
else
{
op.Write(Encode(m.Name));
}
op.Write("</td><td>");
op.Write(Titles.GetSkillTitle(m));
op.WriteLine("</td><td>");
if (m.Region.Name != null)
{
op.Write(m.Region.Name);
}
else
{
op.Write(m.X);
op.Write(", ");
op.Write(m.Y);
op.Write(", ");
op.Write(m.Z);
}
op.Write(" (");
op.Write(m.Map);
op.Write(")</td></tr>");
}
}
op.WriteLine(" <tr>");
op.WriteLine(" </table>");
op.WriteLine(" <h3>Shard Statistics</h3>");
op.WriteLine(" <b>Shard Age:</b> {0:n0} days, {1:n0} hours and {2:n0} minutes<br/>", Statistics.ShardAge.Days, Statistics.ShardAge.Hours, Statistics.ShardAge.Minutes);
op.WriteLine(" <b>Total Game Time:</b> {0:n0} hours and {1:n0} minutes<br/>", Statistics.TotalGameTime.TotalHours, Statistics.TotalGameTime.Minutes);
op.WriteLine(" <b>Last Restart:</b> {0}<br/>", Statistics.LastRestart);
op.WriteLine(" <b>Uptime:</b> {0:n0} days, {1:n0} hours and {2:n0} minutes<br/>", Statistics.Uptime.Days, Statistics.Uptime.Hours, Statistics.Uptime.Minutes);
op.WriteLine(" <b>Active Accounts:</b> {0:n0} [{1:n0} Players Online]<br/>", Statistics.ActiveAccounts, Statistics.PlayersOnline);
op.WriteLine(" <b>Active Staff Members:</b> {0:n0} [{1:n0} Staff Online]<br/>", Statistics.ActiveStaffMembers, Statistics.StaffOnline);
op.WriteLine(" <b>Active Parties:</b> {0:n0} [{1:n0} Players in Parties]<br/>", Statistics.ActiveParties, Statistics.PlayersInParty);
op.WriteLine(" <b>Active Guilds:</b> {0:n0}<br/>", Statistics.ActiveGuilds);
op.WriteLine(" <b>Player Houses:</b> {0:n0}<br/>", Statistics.PlayerHouses);
op.WriteLine(" <b>Player Gold:</b> {0:n0}<br/>", Statistics.PlayerGold);
op.WriteLine(" </body>");
op.WriteLine("</html>");
}
}
}
}