/Shutdown PATCH

Share files with other Dawn of Light users

Moderator: Support Team

/Shutdown PATCH

Postby Krusck » Sat Mar 12, 2011 11:31 pm

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);
}
}
}
Image
Hurricane BETA Cooming
Krusck
DOL Follower
 
Posts: 426
Joined: Sat Jun 21, 2008 10:24 pm
Website: http://daoc.goa.com
Location: University of Sydney, Western Ave (Australia).

Re: /Shutdown PATCH

Postby Roozzz » Sun Mar 13, 2011 7:57 am

And who wrote the original? It is normal to give credit.
Quidquid latine dictum sit, altum videtur
Roozzz
Database Team
 
Posts: 1943
Joined: Wed Dec 06, 2006 11:00 am

Re: /Shutdown PATCH

Postby Etaew » Sun Mar 13, 2011 9:09 am

And who wrote the original?
I believe it was me.
Retired DOL Enthusiast | Blog
User avatar
Etaew
Inactive Staff Member
 
Posts: 7602
Joined: Mon Oct 13, 2003 5:04 pm
Website: http://etaew.net
Location: England

Re: /Shutdown PATCH

Postby Krusck » Sun Mar 13, 2011 10:36 am

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
Image
Hurricane BETA Cooming
Krusck
DOL Follower
 
Posts: 426
Joined: Sat Jun 21, 2008 10:24 pm
Website: http://daoc.goa.com
Location: University of Sydney, Western Ave (Australia).

Re: /Shutdown PATCH

Postby rdsandersjr » Sun Mar 13, 2011 10:42 am

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.
Thanks,
RDSandersJR
User avatar
rdsandersjr
Support Team
 
Posts: 1089
Joined: Fri Aug 01, 2008 3:01 pm
Location: Cincinnati, Ohio

Re: /Shutdown PATCH

Postby Krusck » Sun Mar 13, 2011 10:51 am

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.
Image
Hurricane BETA Cooming
Krusck
DOL Follower
 
Posts: 426
Joined: Sat Jun 21, 2008 10:24 pm
Website: http://daoc.goa.com
Location: University of Sydney, Western Ave (Australia).

Re: /Shutdown PATCH

Postby Graveen » Sun Mar 13, 2011 11:43 am

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:
Image
* pm me to contribute in Dawn of Light: code, database *
User avatar
Graveen
Project Leader
 
Posts: 12660
Joined: Fri Oct 19, 2007 9:22 pm
Location: France


Return to “%s” User Files

Who is online

Users browsing this forum: No registered users and 1 guest