using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using Server;
using System.Threading;
using Server.Commands;
using System.Diagnostics;
using Server.Gumps;
using Server.Network;
using Server.Mobiles;
using Server.Accounting;
namespace Server.Misc
{
class ServerConsole
{
private static bool Hearconsole;
private static ArrayList m_ConsoleHear = new ArrayList();
public static void Initialize()
{
EventSink.ServerStarted += new ServerStartedEventHandler(EventSink_ServerStarted);
EventSink.Speech += new SpeechEventHandler(OnSpeech);
}
public static void EventSink_ServerStarted()
{
new Thread(new ThreadStart(ConsoleListen)).Start();
Console.WriteLine("CC initialized...");
}
private static void OnSpeech(SpeechEventArgs args)
{
if (args.Mobile != null)
{
try
{
string msg;
if (args.Mobile.Region.Name.Length > 0)
msg = String.Format("{0} ({1}): {2}", args.Mobile.Name, args.Mobile.Region.Name, args.Speech);
else
msg = String.Format("{0}: {1}", args.Mobile.Name, args.Speech);
if (Hearconsole)
Console.WriteLine(msg);
}
catch { }
}
}
public static void ConsoleListen()
{
string input = Console.ReadLine();
Next(input);
}
public static void PBroadCast()
{
string input = Console.ReadLine();
BroadcastMessage(AccessLevel.Player, 0x35, String.Format("[Admin] {0}", input));
Console.WriteLine("Player: {0}", input);
}
public static void SBroadCast()
{
string input = Console.ReadLine();
BroadcastMessage(AccessLevel.Counselor, 0x35, String.Format("[Admin] {0}", input));
Console.WriteLine("Staff: {0}", input);
}
public static void BroadcastMessage(AccessLevel ac, int hue, string message)
{
foreach (NetState state in NetState.Instances)
{
Mobile m = state.Mobile;
if (m != null && m.AccessLevel >= ac)
m.SendMessage(hue, message);
}
}
public static void Next(string input)
{
string line = input.ToLower();
switch (line)
{
case "shutdown":
{
World.Save();
Core.Process.Kill();
break;
}
case "shutdown nosave":
{
Core.Process.Kill();
break;
}
case "restart":
{
BroadcastMessage(AccessLevel.Player, 0x35, String.Format("[Server] The Server is restarting ..."));
World.Save();
Process.Start(Core.ExePath);
Core.Process.Kill();
break;
}
case "broadcast":
{
Console.WriteLine("What would you like to say to everyone?");
new Thread(new ThreadStart(PBroadCast)).Start();
break;
}
case "online":
{
ArrayList list = new ArrayList();
List<NetState> states = NetState.Instances;
if (states.Count == 0)
{ Console.WriteLine("There are no users online at this time."); }
for (int i = 0; i < states.Count; ++i)
{
Account a = states[i].Account as Account;
if (a == null)
continue;
Mobile m = states[i].Mobile;
if (m != null)
Console.WriteLine("- Account: {0}, Name: {1}, IP: {2}", a.Username, m.Name, states[i]);
}
break;
}
case "list":
{
Console.WriteLine(" ");
Console.WriteLine("Commands:");
Console.WriteLine("save - Performs a forced save.");
Console.WriteLine("shutdown - Performs a forced save then shuts down the server.");
Console.WriteLine("shutdown nosave - Shuts down the server without saving.");
Console.WriteLine("restart - Sends a message to players informing them that the server is");
Console.WriteLine(" restarting, performs a forced save, then shuts down and");
Console.WriteLine(" restarts the server.");
Console.WriteLine("online - Shows a list of every person online:");
Console.WriteLine(" Account, Char Name, IP.");
Console.WriteLine("broadcast - Type this command, then you will be prompted for a message");
Console.WriteLine(" to send. The message will then be relayed to all players.");
Console.WriteLine("Staff - Type this command, then you will be prompted for a message");
Console.WriteLine(" to send. The message will then be relayed to all staff.");
Console.WriteLine("consolehear - Copies all local speech to this console:");
Console.WriteLine(" Char Name (Region name): Speech.");
Console.WriteLine("list or help - Shows this list.");
Console.WriteLine(" ");
break;
}
case "help":
{
Console.WriteLine(" ");
Console.WriteLine("Commands:");
Console.WriteLine("save - Performs a forced save.");
Console.WriteLine("shutdown - Performs a forced save then shuts down the server.");
Console.WriteLine("shutdown nosave - Shuts down the server without saving.");
Console.WriteLine("restart - Sends a message to players informing them that the server is");
Console.WriteLine(" restarting, performs a forced save, then shuts down and");
Console.WriteLine(" restarts the server.");
Console.WriteLine("online - Shows a list of every person online:");
Console.WriteLine(" Account, Char Name, IP.");
Console.WriteLine("broadcast - Type this command, then you will be prompted for a message");
Console.WriteLine(" to send. The message will then be relayed to all players.");
Console.WriteLine("Staff - Type this command, then you will be prompted for a message");
Console.WriteLine(" to send. The message will then be relayed to all staff.");
Console.WriteLine("consolehear - Copies all local speech to this console:");
Console.WriteLine(" Char Name (Region name): Speech.");
Console.WriteLine("list or help - Shows this list.");
Console.WriteLine(" ");
break;
}
case "save":
{
World.Save();
break;
}
case "staff":
{
Console.WriteLine("What would you like to say to your staff?");
new Thread(new ThreadStart(SBroadCast)).Start();
break;
}
case "consolehear"://credit to Zippy for the HearAll script!
{
Hearconsole = !Hearconsole;
if (Hearconsole)
Console.WriteLine("Now sending all speech to the console.");
else
Console.WriteLine("No longer sending speech to the console.");
break;
}
default:
{
Console.WriteLine(" ");
Console.WriteLine("Commands:");
Console.WriteLine("save - Performs a forced save.");
Console.WriteLine("shutdown - Performs a forced save then shuts down the server.");
Console.WriteLine("shutdown nosave - Shuts down the server without saving.");
Console.WriteLine("restart - Sends a message to players informing them that the server is");
Console.WriteLine(" restarting, performs a forced save, then shuts down and");
Console.WriteLine(" restarts the server.");
Console.WriteLine("online - Shows a list of every person online:");
Console.WriteLine(" Account, Char Name, IP.");
Console.WriteLine("broadcast - Type this command, then you will be prompted for a message");
Console.WriteLine(" to send. The message will then be relayed to all players.");
Console.WriteLine("Staff - Type this command, then you will be prompted for a message");
Console.WriteLine(" to send. The message will then be relayed to all staff.");
Console.WriteLine("consolehear - Copies all local speech to this console:");
Console.WriteLine(" Char Name (Region name): Speech.");
Console.WriteLine("list or help - Shows this list.");
Console.WriteLine(" ");
break;
}
}
new Thread(new ThreadStart(ConsoleListen)).Start();
}
}
}