- Requirements
- ServUO, A folder named "web" with a Status.html file (Empty or not)
Here is the complete Code I just made for using the Status page for your website!
last updated : 2015-04-15
ServUOPath\script\misc\WebStatus.cs
ServUOPath\script\misc\FTP.cs //This is a new file
Credit : Aztala
If I miss something just tell me and I will edit it asap thanks you!
last updated : 2015-04-15
ServUOPath\script\misc\WebStatus.cs
Code:
//.cs File is at ServUOPath\script\misc\WebStatus.cs
using System;
using System.IO;
using System.Text;
using Server.Guilds;
using Server.Network;
namespace Server.Misc
{
public class StatusPage : Timer
{
public static bool Enabled = true;
public StatusPage()
: base(TimeSpan.FromSeconds(5.0), TimeSpan.FromSeconds(60.0))
{
this.Priority = TimerPriority.FiveSeconds;
}
public static void Initialize()
{
if (Enabled)
new StatusPage().Start();
}
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>ServUO Server Status</title>");
op.WriteLine(" </head>");
op.WriteLine(" <body bgcolor=\"white\">");
op.WriteLine(" <h1>ServUO Server Status</h1>");
op.WriteLine(" Online clients:<br>");
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\">Location</font></td><td bgcolor=\"black\"><font color=\"white\">Kills</font></td><td bgcolor=\"black\"><font color=\"white\">Karma / Fame</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(m.X);
op.Write(", ");
op.Write(m.Y);
op.Write(", ");
op.Write(m.Z);
op.Write(" (");
op.Write(m.Map);
op.Write(")</td><td>");
op.Write(m.Kills);
op.Write("</td><td>");
op.Write(m.Karma);
op.Write(" / ");
op.Write(m.Fame);
op.WriteLine("</td></tr>");
}
}
op.WriteLine(" <tr>");
op.WriteLine(" </table>");
op.WriteLine(" </body>");
op.WriteLine("</html>");
}
}
private static string Encode(string input)
{
StringBuilder sb = new StringBuilder(input);
sb.Replace("&", "&");
sb.Replace("<", "<");
sb.Replace(">", ">");
sb.Replace("\"", """);
sb.Replace("'", "'");
return sb.ToString();
}
}
}
Code:
//.cs File is at ServUOPath\script\misc\FTP.cs
using System;
using System.IO;
using System.Text;
using System.Net;
using Server.Guilds;
using Server.Network;
namespace Server.Misc
{
public class FTPTransfer : Timer
{
public static bool Enabled = true;
public FTPTransfer()
: base(TimeSpan.FromSeconds(5.0), TimeSpan.FromSeconds(50.0))
{
this.Priority = TimerPriority.FiveSeconds;
}
public static void Initialize()
{
if (Enabled)
new FTPTransfer().Start();
}
protected override void OnTick()
{
try
{
string FtpPath = @"ftp://10.10.10.10/";
string OriginalfileName = "status.html";
string OriginalFilePath = @"C:\ServUO\web\status.html";
WebRequest WRequest = WebRequest.Create(FtpPath + OriginalfileName);
WRequest.Method = WebRequestMethods.Ftp.UploadFile;
WRequest.Credentials = new NetworkCredential("FTP-Username", "FTP-Password");
using (FileStream stream = File.OpenRead(OriginalFilePath))
{
using (Stream RStream = WRequest.GetRequestStream())
{
stream.CopyTo(RStream);
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
}
}
Credit : Aztala
If I miss something just tell me and I will edit it asap thanks you!