View Single Post
Old 08-20-2004, 11:33 PM   #2 (permalink)
Grae
 
Join Date: Aug 2003
Location: Australia
Age: 41
Posts: 198
Post

If you are using a router then the following script is for you.

I do not have or use a router so I could not test it myself. And I do not take any credit for it as it was written by someone else. Thanks goes out to them.

Before using it, backup original ServerList.cs (rename it ServerList.old), make a new text file, copy the following script into the new text file and saveas ServerList (you need to edit the extension .txt to .cs). Also you will need to edit this script to suit your own needs to show the correct Internet address and Network address for your setup and also Server Name.

I have bolded the parts you will need to edit.

Code:
using Server;
using Server.Network;

namespace Server.Misc
{
public class ServerList
{
/* Address:
* 
* The default setting, a value of 'null', will attempt to detect your IP address automatically:
* private const string Address = null;
* 
* This detection, however, does not work for servers behind routers. If you're running behind a router, put in your IP:
* private const string Address = "12.34.56.78";
* 
* If you need to resolve a DNS host name, you can do that too:
* private const string Address = "shard.host.com";
*/

public const string Address = "your public IP here"; 

public const string LocalServerAddress = "your local IP here";

public const string ServerName = "server name here";

public static void Initialize()
{
Listener.Port = 2593;

EventSink.ServerList += new ServerListEventHandler( EventSink_ServerList );
}

public static void EventSink_ServerList( ServerListEventArgs e )
{
try
{
IPAddress ipAddr;
IPAddress LocalAddress = IPAddress.Parse( LocalServerAddress );


if ( Resolve( Address != null && !IsLocalMachine( e.State ) ? Address : Dns.GetHostName(), out ipAddr ) )
{
e.AddServer( ServerName, new IPEndPoint( ipAddr, Listener.Port ) );
e.AddServer( "Local Server", new IPEndPoint( LocalAddress, Listener.Port ) ); 
}
else
e.Rejected = true;
}
catch
{
e.Rejected = true;
}
}

public static bool Resolve( string addr, out IPAddress outValue )
{
try
{
outValue = IPAddress.Parse( addr );
return true;
}
catch
{
try
{
IPHostEntry iphe = Dns.Resolve( addr );

if ( iphe.AddressList.Length > 0 )
{
outValue = iphe.AddressList[iphe.AddressList.Length - 1];
return true;
}
}
catch
{
}
}

outValue = IPAddress.None;
return false;
}

private static bool IsLocalMachine( NetState state )
{
Socket sock = state.Socket;

IPAddress theirAddress = ((IPEndPoint)sock.RemoteEndPoint).Address;

if ( IPAddress.IsLoopback( theirAddress ) )
return true;

bool contains = false;
IPHostEntry iphe = Dns.Resolve( Dns.GetHostName() );

for ( int i = 0; !contains && i < iphe.AddressList.Length; ++i )
contains = theirAddress.Equals( iphe.AddressList[i] );

return contains;
}
}
}
I truely hope this helps those using routers (may not work with all routers). And again many thanks to the author of this script. If all else fails and this script does'nt work for you, try Mr.Fixit's. Most likely found on the UOGateway MessageBoards.

Good Luck.

Grae
Grae is offline