Page 1 of 1

/Shutdown PATCH

PostPosted: Sat Mar 12, 2011 11:31 pm
by Krusck
Edit By RDSandersJR: Krusck updated an old script, didn't give credit where it was due. Claimed it was a re-write on his part.

Consider this a warning Krusck, Plagiarism(http://en.wikipedia.org/wiki/Plagiarism) will NOT be tolerated here.


I took the liberty to update the credits below.
// End Edit
Code: Select all
/*
* Shutdown.cs: Originally coded by DOL Team (Etaew)
* Updated By: Krusck on 3/13/2011
* */
using System;
using System.Collections;
using System.Reflection;
using System.Threading;
using DOL.Events;
using DOL.GS.PacketHandler;
using log4net;
using DOL.Database;

namespace DOL.GS.Commands
{
[CmdAttribute(
"&shutdown",
ePrivLevel.Admin,
"Shutdown the server in next minute",
"/shutdown on <hour>:<min> - shutdown on this time",
"/shutdown <mins> - shutdown in minutes")]
public class ShutdownCommandHandler : AbstractCommandHandler, ICommandHandler
{
/// <summary>
/// Defines a logger for this class.
/// </summary>
private static readonly ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

private static long m_counter = 0;
private static Timer m_timer;
private static int m_time = 5;

public static long getShutdownCounter()
{
return m_counter;
}

[ScriptLoadedEvent]
public static void ScriptLoaded(DOLEvent e, object sender, EventArgs args)
{
DOL.Events.GameEventMgr.AddHandler(GameServerEvent.WorldSave, new DOLEventHandler(AutomaticShutdown));
}

public static void AutomaticShutdown(DOLEvent e, object sender, EventArgs args)
{
if (m_timer != null)
return;

TimeSpan uptime = TimeSpan.FromTicks(GameServer.Instance.TickCount);
}



public static void CountDown(object param)
{
if (m_counter <= 0)
{
m_timer.Dispose();
new Thread(new ThreadStart(ShutDownServer)).Start();
return;
}
else
{
log.Info("Server reboot in " + m_counter + " seconds!");
long secs = m_counter;
long mins = secs / 60;
long hours = mins / 60;

foreach (GameClient client in WorldMgr.GetAllPlayingClients())
{
if (hours > 3) //hours...
{
if (mins % 60 == 0 && secs % 60 == 0) //every hour..
client.Out.SendMessage("Server reboot in " + hours + " hours!", eChatType.CT_Broadcast,
eChatLoc.CL_ChatWindow);
}
else if (hours > 0) //hours
{
if (mins % 30 == 0 && secs % 60 == 0) //every 30 mins..
client.Out.SendMessage("Server reboot in " + hours + " hours and " + (mins - (hours * 60)) + "mins!", eChatType.CT_Staff,
eChatLoc.CL_ChatWindow);
}
else if (mins >= 10)
{
if (mins % 15 == 0 && secs % 60 == 0) //every 15 mins..
client.Out.SendMessage("Server reboot in " + mins + " mins!", eChatType.CT_Broadcast,
eChatLoc.CL_ChatWindow);
}
else if (mins >= 3)
{
if (secs % 60 == 0) //every min...
client.Out.SendMessage("Server reboot in " + mins + " mins!", eChatType.CT_Broadcast,
eChatLoc.CL_ChatWindow);
}
else if (secs > 60)
{
client.Out.SendMessage("Server reboot in " + mins + " minutes! (" + secs + " secs)", eChatType.CT_Broadcast,
eChatLoc.CL_ChatWindow);
}
else
client.Out.SendMessage("Server reboot in " + secs + " secs! Please logout!", eChatType.CT_Broadcast,
eChatLoc.CL_ChatWindow);
}

if (mins <= 5 && GameServer.Instance.ServerStatus != eGameServerStatus.GSS_Closed) // 5 mins remaining
{
GameServer.Instance.Close();
string msg = "Server is now closed (reboot in " + mins + " mins)";

}
}
m_counter -= 15;
}

public static void ShutDownServer()
{
if (GameServer.Instance.IsRunning)
{
GameServer.Instance.Stop();
log.Info("Automated server shutdown!");
Thread.Sleep(2000);
Environment.Exit(0);
}
}

public void OnCommand(GameClient client, string[] args)
{
DateTime date;
//if (m_counter > 0) return 0;
if (args.Length >= 2)
{
if (args.Length == 2)
{
try
{
m_counter = System.Convert.ToInt32(args[1]) * 60;
}
catch (Exception)
{
DisplaySyntax(client);
return;
}
}

else
{
if ((args.Length == 3) && (args[1] == "on"))
{
string[] shutdownsplit = args[2].Split(':');

if ((shutdownsplit == null) || (shutdownsplit.Length < 2))
{
DisplaySyntax(client);
return;
}

int hour = Convert.ToInt32(shutdownsplit[0]);
int min = Convert.ToInt32(shutdownsplit[1]);
// found next date with hour:min

date = DateTime.Now;

if ((date.Hour > hour) ||
(date.Hour == hour && date.Minute > min)
)
date = new DateTime(date.Year, date.Month, date.Day + 1);

if (date.Minute > min)
date = new DateTime(date.Year, date.Month, date.Day, date.Hour + 1, 0, 0);

date = date.AddHours(hour - date.Hour);
date = date.AddMinutes(min - date.Minute + 2);
date = date.AddSeconds(-date.Second);

m_counter = (date.ToFileTime() - DateTime.Now.ToFileTime()) / TimeSpan.TicksPerSecond;

if (m_counter < 60) m_counter = 60;

}
else
{
DisplaySyntax(client);
return;
}

}
}
else
{
DisplaySyntax(client);
return;
}

if (m_counter % 5 != 0)
m_counter = (m_counter / 5 * 5);

if (m_counter == 0)
m_counter = m_time * 60;

date = DateTime.Now;
date = date.AddSeconds(m_counter);

foreach (GameClient m_client in WorldMgr.GetAllPlayingClients())
{
m_client.Out.SendMessage("Server Shutdown in " + m_counter / 60 + " mins! (Reboot on " + date.ToString("HH:mm \"GMT\" zzz") + ")", eChatType.CT_System, eChatLoc.CL_PopupWindow);
}

string msg = "Server Shutdown in " + m_counter / 60 + " mins! (Reboot on " + date.ToString("HH:mm \"GMT\" zzz") + ")";
log.Info(msg);


m_timer = new Timer(new TimerCallback(CountDown), null, 0, 15000);
}
}
}

Re: /Shutdown PATCH

PostPosted: Sun Mar 13, 2011 7:57 am
by Roozzz
And who wrote the original? It is normal to give credit.

Re: /Shutdown PATCH

PostPosted: Sun Mar 13, 2011 9:09 am
by Etaew
And who wrote the original?
I believe it was me.

Re: /Shutdown PATCH

PostPosted: Sun Mar 13, 2011 10:36 am
by Krusck
well, since I am not welcome here, I leave the community of Dawn of Light
under the guise of a principle of racism towards me.
I tried, after several years of study, to come back here expecting to be welcomed as a family, but unfortunately I was wrong.

I will end

Good Day to all. and thanks

Re: /Shutdown PATCH

PostPosted: Sun Mar 13, 2011 10:42 am
by rdsandersjr
well, since I am not welcome here, I leave the community of Dawn of Light
under the guise of a principle of racism towards me.
I tried, after several years of study, to come back here expecting to be welcomed as a family, but unfortunately I was wrong.

I will end

Good Day to all. and thanks
No one around here said you wasn't welcomed, we just wish you would take two seconds to give proper credit where it is due and not give everyone the impression you "recoded a whole script" from scratch when you didn't. If your not sure who to give credit to, say so! Its that simple.

Either choice you make, I hope the best for you.

Re: /Shutdown PATCH

PostPosted: Sun Mar 13, 2011 10:51 am
by Krusck
well, since I am not welcome here, I leave the community of Dawn of Light
under the guise of a principle of racism towards me.
I tried, after several years of study, to come back here expecting to be welcomed as a family, but unfortunately I was wrong.

I will end

Good Day to all. and thanks
No one around here said you wasn't welcomed, we just wish you would take two seconds to give proper credit where it is due and not give everyone the impression you "recoded a whole script" from scratch when you didn't. If your not sure who to give credit to, say so! Its that simple.

Either choice you make, I hope the best for you.
KINDLY could simply write code written by a "someone who does not know, "and closed them, not all those nasty things you've written, the fact is that I do not feel welcome here everything I do I'm always saying something negative so I'm sorry but if you must continue to be there so I apologize.

Re: /Shutdown PATCH

PostPosted: Sun Mar 13, 2011 11:43 am
by Graveen
Effectively Krusck, if you come back in the old mood, you can leave now. Strangely, it seems we have been teleported back 1.5 years ago !

If you can't see the problem, this is the problem :mrgreen: