RunUO Community

This is a sample guest message. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

~Destructor?

Oridan

Wanderer
~Destructor?

i need to find a way to activate a deconstructor when somone closes or shuts down RunUO. I'm simply trying to get the server to set the topic to say the shard is down.
For whatever reason making a ~Class destructor doesnt work. any ideas ?

Thanks
Oridan
 

Oridan

Wanderer
hrm... doesnt seem to do anything :S

is this correct?

[code:1]using System;
using System.Net;
using Server;
using Server.IRC;

namespace Server.IRC
{
public sealed class StatusBot : QuakeNetBot
{
private static StatusBot m_Bot;

private static string[] m_Servers = new string[]
{
"irc.quakenet.org",
"uk.quakenet.org"
};

public static void Initialize()
{
bool FoundServer = false;
int CurrentServer = 0;

while ( (FoundServer == false) && (CurrentServer < m_Servers.Length) ) {
try
{
Console.WriteLine("StatusBot: Trying to connect to: " + m_Servers[CurrentServer]);
m_Bot = new StatusBot ( m_Servers[CurrentServer], "^shadowlands^", "slbot", 6667, "#ShadowLands" );
FoundServer = true;
}
catch
{
Console.WriteLine("StatusBot: Failed to connect to: " + m_Servers[CurrentServer]);
CurrentServer += 1;
}
}
}

public StatusBot ( string pServer, string pNickname, string pAuthname, int Port, params string[] pChannels ) : base ( pServer, pNickname, pAuthname, Port, pChannels )
{
}

~StatusBot()
{
m_Bot.SetTopic ("#ShadowLands","4,1Welcome to ShadowLands UO Shard - Shard is DOWN - http://shadowlands.netgamers.co.uk" );
}

private void UpdateTopic()
{
SetTopic ("#ShadowLands","4,1Welcome to ShadowLands UO Shard - Shard is UP - http://shadowlands.netgamers.co.uk" );
}

public override void OnChannelMessage ( string Channel, string Nickname, string Message )
{
// base.OnChannelMessage( Channel, Nickname, Message);

if (String.Compare(Message,"!stats",true) == 0)
{
Say(Channel, "Open Connections: {0}", Network.NetState.Instances.Count.ToString() );
Say(Channel, "Mobiles: {0}", World.Mobiles.Count.ToString() );
Say(Channel, "Items: {0}", World.Items.Count.ToString() );
}
if (String.Compare(Message,"!updatetopic",true) == 0)
{
UpdateTopic();
}
}

public override void OnPrivateMessage ( string Nickname, string Message )
{
// base.OnPrivateMessage( Nickname, Message);
}
}
}[/code:1]
 

Quinox

Sorceror
I Believe you can use the EventSink.Shutdown to do that.

[code:1]
public static void Initialize()
{
EventSink.Shutdown += new ShutdownEventHandler( EventSink_Shutdown );
}
[/code:1]

[code:1]
public static void EventSink_Shutdown( ShutdownEventArgs e )
{
// Your code here
}
[/code:1]

Take a look in the docs at Server.EventSink, Server.ShutdownEventHandler, and Server.ShutdownEventArgs
 

Oridan

Wanderer

yeah thats what i thought, but i currently have this:
[code:1]
using System;
//using Microsoft.Win32;
using Server;
using Server.IRC;

namespace Server.Misc
{
public class ShutdownCatcher
{
public static void Initialize()
{
EventSink.Shutdown += new ShutdownEventHandler( EventSink_Shutdown );

// use Microsoft.Win32 namespace SystemEvents class SessionEnded or SessionEnding events ....
}


public static void EventSink_Shutdown( ShutdownEventArgs e )
{
Console.Write("Finalizing...");
StatusBot.Shutdown();
Console.WriteLine("Done!");
}
}
}[/code:1]

and it seems to do absolutely nothing :S
As you can see i've also tryed using system events rather than server, but all i could find was session end. I think what I need is an application shutdown event, or something similar. :S
 

Oridan

Wanderer
hrmm i've come across the InvokeOnEventThread method, does anyone know if this is a good way of achieving what i'm looking for... and how i'd go about it ?

Many Thanks
Oridan
 

Oridan

Wanderer
Oridan said:
hrmm i've come across the InvokeOnEventThread method, does anyone know if this is a good way of achieving what i'm looking for... and how i'd go about it ?

Many Thanks
Oridan

*bump* can anyone help please?
 

Zippy

Razor Creator
C# doesn't have destructors, its a memory managed language. Resource will automatically be freed for you when the program ends, if you want to preform an action before the server goes down, use ShutdownEvent.
 

Oridan

Wanderer
Zippy said:
C# doesn't have destructors, its a memory managed language. Resource will automatically be freed for you when the program ends, if you want to preform an action before the server goes down, use ShutdownEvent.

doesnt seem to do anything, i've set this up just to see if it'll do something but its not waiting for me to press a key :S

any ideas ?

[code:1]
using System;
using Server;

namespace Server.Misc
{
public class ShutdownCatcher
{
public static void Initialize()
{
Console.WriteLine("Server Shutdown Init");

EventSink.Shutdown += new ShutdownEventHandler( EventSink_Shutdown );
}


public static void EventSink_Shutdown( ShutdownEventArgs e )
{
Console.WriteLine("Server Shutdown...");
Console.ReadLine();
}
}
}[/code:1]
 
Top