Go Back   RunUO - Ultima Online Emulation > RunUO > Server Support on Windows

Server Support on Windows Get (and give) support on general questions related to the RunUO server itself.

Reply
 
Thread Tools Display Modes
Old 07-21-2006, 04:17 AM   #1 (permalink)
Forum Expert
 
Sparkin's Avatar
 
Join Date: Dec 2005
Location: Missouri , USA
Age: 38
Posts: 256
Default the Client could not attach to the game server

Hello. I jsut switched from Cable to DSL, And the issue is i cannout use UOG to connect from my computers on the network, Only way i can connect on the server is using new local server and the local ip, however that will not work on any of the other computers, i use Mr. Fixits and have tried the stock serverlist.cs, I have tried difrent routers and no router same thing,, anyone have ideas how to get around this?


thanks
__________________
Quote:
Originally Posted by Ryan View Post
You are a moron.
Sparkin is offline   Reply With Quote
Old 07-21-2006, 07:17 AM   #2 (permalink)
Account Terminated
 
Join Date: Sep 2002
Age: 26
Posts: 3,846
Send a message via ICQ to Phantom Send a message via AIM to Phantom Send a message via MSN to Phantom
Default

Quote:
Originally Posted by Sparkin
Hello. I jsut switched from Cable to DSL, And the issue is i cannout use UOG to connect from my computers on the network, Only way i can connect on the server is using new local server and the local ip, however that will not work on any of the other computers, i use Mr. Fixits and have tried the stock serverlist.cs, I have tried difrent routers and no router same thing,, anyone have ideas how to get around this?


thanks
You need to forward the port, clearly if your using a router, if its on the same computer 127.0.0.1 will always work.

Your modem also might be itself a router, contact your provider if you don't know what kind of hardware it is.
Phantom is offline   Reply With Quote
Old 07-21-2006, 08:34 AM   #3 (permalink)
Forum Expert
 
Sparkin's Avatar
 
Join Date: Dec 2005
Location: Missouri , USA
Age: 38
Posts: 256
Default

its not port forwarding * hell if it was that easy*
Other people can get in just fine i think it may be the NAT im not sure ill keep messing with it, it goes to the server list but then when you click on the server it gives that client cannot attach thing i see the connection on the server with valid credentials, then it disconnects and gives the client cannot attach thing
__________________
Quote:
Originally Posted by Ryan View Post
You are a moron.
Sparkin is offline   Reply With Quote
Old 07-25-2006, 06:57 PM   #4 (permalink)
Newbie
 
Join Date: Jul 2006
Age: 20
Posts: 19
Default

I have this same problem could someone please help me out with it.
jack_sisco is offline   Reply With Quote
Old 07-26-2006, 01:24 AM   #5 (permalink)
Account Terminated
 
Join Date: Sep 2002
Age: 26
Posts: 3,846
Send a message via ICQ to Phantom Send a message via AIM to Phantom Send a message via MSN to Phantom
Default

Quote:
Originally Posted by jack_sisco
I have this same problem could someone please help me out with it.
Post your Serverlist.cs

Quote:
its not port forwarding * hell if it was that easy*
Other people can get in just fine i think it may be the NAT im not sure ill keep messing with it, it goes to the server list but then when you click on the server it gives that client cannot attach thing i see the connection on the server with valid credentials, then it disconnects and gives the client cannot attach thing
This is important information you didn't tell us, thus I told you what might have been the problem in the future don't tell me what it isn't if your asking help.

Like jack_sisco, who is rude to post in your thread, its a serverlist.cs issue post it.
Phantom is offline   Reply With Quote
Old 07-30-2006, 11:37 AM   #6 (permalink)
Newbie
 
Join Date: Jan 2006
Posts: 20
Question

I have a very similar problem (if not the same one) so I might as well post it here.

I first encountered the problem way back when, at the time I was using runuo 1.0. Basicly you set the server up on its own computer on a home network, forward the ports in the modems NAT, set you IP/DNS in the ServerList.cs and as expected players can connect to your server... Unless they happen to be on the same home network as the computer the servers runing on. Basicly anyone connecting with an internal IP connects, the account credentials are verified and confirmed, the get sent to the shard list and then you have problems, as soon they select the shard the server disconects them and they get the "game client could not attach to server" message.

Eventualy I got Mr Fixit's server list script and that completely resolved the issue. Fast forward to now. I've updated to runuo 2.0. The Mr Fixit server list script I was using doesn't work. The stock server list script that comes with runuo 2.0 works fine for people external to the network and they can connect and play fine (and are reporting a reduction in lag which is encouraging). However, once again computers on the internal network get disconnected when selecting the shard. Tried getting the latest version of the Mr Fixit's server list script I could find, which was 2.2 found here: ServerList.cs 2.2 but to no avail. Only thing I currently have changed in the script linked is the name of shard 1. Doesn't matter if I enter my external IP, DNS or leave it as null and let it autodetect the IP as I've currently left it, players outside my network can connect fine but still no love for players inside the home network.

Everythings patched up on both the server and other computers on the network (UO client patch 5.0.2g, Windows XP SP2 fully updated with dotnetframework 2.0.50727 etc.) and there are no firewalls causing any problems so I'm at a loss.

Any suggestions?
Astrobia is offline   Reply With Quote
Old 08-06-2006, 05:16 AM   #7 (permalink)
Newbie
 
Join Date: Jan 2006
Posts: 20
Default

I've found at least 5 other threads with people who have this problem that have not come to any conclusion. Surely somebody has a solution for us.
Astrobia is offline   Reply With Quote
Old 08-06-2006, 06:03 AM   #8 (permalink)
Forum Expert
 
Aeolus's Avatar
 
Join Date: Dec 2005
Location: Indianapolis
Posts: 731
Send a message via AIM to Aeolus Send a message via MSN to Aeolus Send a message via Yahoo to Aeolus
Default

Here is my (Mr Fixit) Serverlist.cs I know it works with 2.0. You may have an altered version that supports multiple servers that was released a few months back- if I remember correctly, the scripter said it wouldn't work unless you had multiple servers, but I'm going off memory here. Anyway, you'll need to change the shard name and the port back to 2593. If this doesn't fix your problems, I don't know what the problem is- sorry
Attached Files
File Type: cs ServerList.cs (14.2 KB, 98 views)
__________________
Buy this stuff.
Aeolus is offline   Reply With Quote
Old 08-06-2006, 09:20 AM   #9 (permalink)
Newbie
 
Join Date: Jan 2006
Posts: 20
Default

That helped, thanks. I wonder whats changed in the 2.2 script that actualy prevents the local IP's from authenticating.
Astrobia is offline   Reply With Quote
Old 08-06-2006, 11:57 PM   #10 (permalink)
Forum Expert
 
Aeolus's Avatar
 
Join Date: Dec 2005
Location: Indianapolis
Posts: 731
Send a message via AIM to Aeolus Send a message via MSN to Aeolus Send a message via Yahoo to Aeolus
Default

I believe that was a problem with 1.0 as well, which is why everyone here is always reccomending Mr Fixit's Serverlist.cs

*Edit* I think I misunderstood your post at first... you could use WinMerge to compare the 2 files if you are super curious.
__________________
Buy this stuff.

Last edited by Aeolus; 08-06-2006 at 11:59 PM.
Aeolus is offline   Reply With Quote
Old 09-17-2006, 10:27 PM   #11 (permalink)
Lurker
 
Join Date: Jun 2006
Posts: 7
Default serverlist.cs problems

i have 2.0 mrfixits serverlist.cs and half the time people can connect and the other half i have to restart several time before they can connect! i found a warning when i had an error on another sctipts + Misc/ServerList/ServerList/ServerList.cs:
CS0618: Line 343: 'System.Net.Dns.Resolve(string)' is obsolete: 'Resolve is
obsoleted for this type, please use GetHostEntry instead. http://go.microsoft.co
m/fwlink/?linkid=14202' and here,s my serverlist.cs using System;
using System.Net;
using System.Net.Sockets;
using Server;
using Server.Network;

namespace Server.Misc
{
public class ServerList
{

// ================================================== ================================
// YOUR SERVERS NAME
// ================================================== ================================
public const string ServerName = "_ _ _ _ _ _ _ _";

// ================================================== ================================
// YOUR INTERNET IP OR DNS NAME
// Here you can select to autodetect your internet ip, or manualy specify
// Examples:
// public static string Address = "12.34.56.78";
// public static string Address = "shard.host.com";
// ================================================== ================================
public const bool InternetIPAutodetect = true;
public const int MinutesBetweenIPAutodetect = 1440;
public static string Address = null;

// ================================================== ================================
// Here are some values stored
// ================================================== ================================
private static LocalLanIPRange[] LocalLanIPRanges = new LocalLanIPRange[10];
private static UInt32 LocalLanIPRangesCount;
private static AutoIPMirror[] AutoIPMirrors = new AutoIPMirror[10];
private static UInt32 AutoIPMirrorsCount;
private static DateTime InternetIPAutodetectLast;


// ================================================== ================================
// Initialization
// ================================================== ================================
public static void Initialize()
{
// ----------------------------------------------------
// Select what port to use
// ----------------------------------------------------
Listener.Port = 2593;

// ----------------------------------------------------
// Load the local LAN ip ranges
// ----------------------------------------------------
AddLocalLANIPRange("10.0.0.0", "10.255.255.255");
AddLocalLANIPRange("192.168.0.0", "192.168.255.255");
AddLocalLANIPRange("172.16.0.0", "172.32.255.255");
AddLocalLANIPRange("169.254.0.0", "169.254.255.255");

// ----------------------------------------------------
// Load the Auto IP mirros
// ----------------------------------------------------
AddAutoIPMirror("http://www.findmyip.com/", "Your IP address is:<br>", "</FONT>");
AddAutoIPMirror("http://www.ipaddy.com/", "Your IP address is: ", "<br>");
AddAutoIPMirror("http://checkip.dyndns.org/", "Current IP Address: ", "</body>");
AddAutoIPMirror("http://ipid.shat.net/iponly/", "<title>", "</title>");
AddAutoIPMirror("http://www.edpsciences.com/htbin/ipaddress", "Your IP address is <B> ", " </B>");
AddAutoIPMirror("http://www2.simflex.com/ip.shtml", "Your IP address is <BR>", "<BR>");

// ----------------------------------------------------
// Create the event
// ----------------------------------------------------
EventSink.ServerList += new ServerListEventHandler( EventSink_ServerList );

// ----------------------------------------------------
// Show info in console
// ----------------------------------------------------
Console.WriteLine("Serverlist.cs: 2.0");

// ----------------------------------------------------
// Lets find internet ip
// ----------------------------------------------------
DetectInternetIP();


}


// ================================================== ================================
// Add a range of local lan ips
// ================================================== ================================
private static void AddLocalLANIPRange(string RangeFrom, string RangeTo)
{
LocalLanIPRanges[LocalLanIPRangesCount] = new LocalLanIPRange();
LocalLanIPRanges[LocalLanIPRangesCount].RangeFrom = StringIPToUInt32IP(RangeFrom);
LocalLanIPRanges[LocalLanIPRangesCount].RangeTo = StringIPToUInt32IP(RangeTo);
LocalLanIPRangesCount = LocalLanIPRangesCount + 1;
}


// ================================================== ================================
// Convert a ip string to a binary unsigned int
// ================================================== ================================
private static UInt32 StringIPToUInt32IP(string addr)
{
byte[] byteArray1 = IPAddress.Parse(addr).GetAddressBytes();
byte[] byteArray2 = IPAddress.Parse(addr).GetAddressBytes();
byteArray1[0] = byteArray2[3];
byteArray1[1] = byteArray2[2];
byteArray1[2] = byteArray2[1];
byteArray1[3] = byteArray2[0];
return BitConverter.ToUInt32( byteArray1, 0);
}


// ================================================== ================================
// Used to store the local lan ip ranges
// ================================================== ================================
private class LocalLanIPRange
{
public UInt32 RangeFrom;
public UInt32 RangeTo;
}


// ================================================== ================================
// Add a AutoIP mirror
// ================================================== ================================
private static void AddAutoIPMirror(string sURL, string sStart, string sEnd)
{
AutoIPMirrors[AutoIPMirrorsCount] = new AutoIPMirror();
AutoIPMirrors[AutoIPMirrorsCount].sURL = sURL;
AutoIPMirrors[AutoIPMirrorsCount].sStart = sStart;
AutoIPMirrors[AutoIPMirrorsCount].sEnd = sEnd;
AutoIPMirrorsCount = AutoIPMirrorsCount + 1;
}


// ================================================== ================================
// Used to store the Auto IP mirrors
// ================================================== ================================
private class AutoIPMirror
{
public string sURL;
public string sStart;
public string sEnd;
public UInt32 iFailures;
}


// ================================================== ================================
// Detect ip
// ================================================== ================================
public static void DetectInternetIP()
{

// ----------------------------------------------------
// Autodetect the Internet IP
// ----------------------------------------------------
if (InternetIPAutodetect) {
DateTime UpdateTime = InternetIPAutodetectLast;
UpdateTime = UpdateTime.AddMinutes(MinutesBetweenIPAutodetect);
if (UpdateTime<DateTime.Now) {
string NewAddress = null;
NewAddress = FindInternetIP();
InternetIPAutodetectLast = DateTime.Now;
if (NewAddress!=null)
{
Address = NewAddress;
}
}
}

}

// ================================================== ================================
// The serverlist event
// ================================================== ================================
public static void EventSink_ServerList( ServerListEventArgs e )
{
try
{

// ----------------------------------------------------
// Lets find internet ip
// ----------------------------------------------------
DetectInternetIP();

// ----------------------------------------------------
// Find the server ip to use for this user
// ----------------------------------------------------
IPAddress ipAddr = FindMachineIP(e);

// ----------------------------------------------------
// Send serverlist
// ----------------------------------------------------
if (ipAddr != null)
{
e.AddServer( ServerName, new IPEndPoint( ipAddr, Listener.Port ) );
} else {
e.Rejected = true;
}
}
catch
{
e.Rejected = true;
}
}


// ================================================== ================================
// Connects to a webserver that gives you your internet ip
// ================================================== ================================
public static string FindInternetIP( )
{

// ----------------------------------------------------
// Pick a random mirror
// ----------------------------------------------------
Random rnd = new Random();
int UseMirror = (int)( rnd.NextDouble() * AutoIPMirrorsCount);
string MyIP = "";

// ----------------------------------------------------
// Catch if the mirror is down
// ----------------------------------------------------
try
{
// ----------------------------------------------------
// Get the webpage
// ----------------------------------------------------
WebClient client = new WebClient();
byte[] pageData = client.DownloadData(AutoIPMirrors[UseMirror].sURL);
MyIP = System.Text.Encoding.ASCII.GetString(pageData);

// ----------------------------------------------------
// Find the string
// ----------------------------------------------------
int iStart = MyIP.LastIndexOf(AutoIPMirrors[UseMirror].sStart);
int iEnd = MyIP.IndexOf(AutoIPMirrors[UseMirror].sEnd, iStart+AutoIPMirrors[UseMirror].sStart.Length);
MyIP = MyIP.Substring(iStart+AutoIPMirrors[UseMirror].sStart.Length, iEnd-iStart-AutoIPMirrors[UseMirror].sStart.Length );
MyIP = MyIP.Trim();

// ----------------------------------------------------
// Return value
// ----------------------------------------------------
Console.WriteLine("Internet IP: {0} ({1})", MyIP, AutoIPMirrors[UseMirror].sURL);
return MyIP;
}
catch
{
Console.WriteLine("Unable to autoupdate the Internet IP from {0}!", AutoIPMirrors[UseMirror].sURL);
Console.WriteLine("----------------------------------------------------------------------");
Console.WriteLine(MyIP);
Console.WriteLine("----------------------------------------------------------------------");
return null;
}
}


// ================================================== ================================
// Calculates what server IP to use
// ================================================== ================================
public static IPAddress FindMachineIP( ServerListEventArgs e )
{
// ----------------------------------------------------
// Find the IP of the connecting user
// ----------------------------------------------------
Socket sock = e.State.Socket;
IPAddress theirAddress = ((IPEndPoint)sock.RemoteEndPoint).Address;
IPAddress serverAddress;

// ----------------------------------------------------
// Is it Loopback?
// ----------------------------------------------------
if ( IPAddress.IsLoopback( theirAddress ) )
{
return IPAddress.Parse( "127.0.0.1" );
}

// ----------------------------------------------------
// Local
// ----------------------------------------------------
UInt32 uint32Address = StringIPToUInt32IP(theirAddress.ToString());
for (UInt32 LocalLanIPRangesLoop = 0 ; LocalLanIPRangesLoop < LocalLanIPRangesCount; LocalLanIPRangesLoop++)
{
if ( (LocalLanIPRanges[LocalLanIPRangesLoop].RangeFrom <= uint32Address) && (LocalLanIPRanges[LocalLanIPRangesLoop].RangeTo >= uint32Address) )
{
Resolve(Dns.GetHostName(), out serverAddress);

Console.WriteLine("Player is reconnecting to " + serverAddress.ToString());
return serverAddress;
}
}

// ----------------------------------------------------
// Internet addresses
// ----------------------------------------------------
if (Address!=null)
{
Resolve(Address, out serverAddress);
} else {
Resolve(Dns.GetHostName(), out serverAddress);
}

Console.WriteLine("Player is reconnecting to " + serverAddress.ToString());
return serverAddress;
}


// ================================================== ================================
// Resolves dns names
// ================================================== ================================
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;
}

}
}
strattman_2006 is offline   Reply With Quote
Old 11-01-2006, 12:48 AM   #12 (permalink)
Forum Expert
 
Sparkin's Avatar
 
Join Date: Dec 2005
Location: Missouri , USA
Age: 38
Posts: 256
Red face

Quote:
Originally Posted by Aeolus
I believe that was a problem with 1.0 as well, which is why everyone here is always reccomending Mr Fixit's Serverlist.cs

*Edit* I think I misunderstood your post at first... you could use WinMerge to compare the 2 files if you are super curious.
Actually I am running several shards on one PC im thinking the issue is that "MOD" in the script ill try the Un single server serverlist.cs then tell ya what happens We never got ahit issue fixed but every morning at 6asm it restarts, i wake up at 7am and have an IM from a very faithfull Staff member with a great Hello server is down or UP message and restart uptp 10 times before she can login...
This Issue Started After 1.0 - 2.0 change over for our Shards so most Likely thats the issue

Anyway We will try to get the other Script loaded and see how it goes....

P.S Id Post my script here but im to lazy to remove the * Shard Info *


Peace!
__________________
Quote:
Originally Posted by Ryan View Post
You are a moron.
Sparkin is offline   Reply With Quote
Old 11-01-2006, 12:50 AM   #13 (permalink)
Forum Expert
 
Sparkin's Avatar
 
Join Date: Dec 2005
Location: Missouri , USA
Age: 38
Posts: 256
Default

Quote:
Originally Posted by Aeolus
I believe that was a problem with 1.0 as well, which is why everyone here is always reccomending Mr Fixit's Serverlist.cs

*Edit* I think I misunderstood your post at first... you could use WinMerge to compare the 2 files if you are super curious.

Winmerge would be a great place to run the Diffs on it but then again I think ill jsut try the Updated fixit's one and try it
Thanks
__________________
Quote:
Originally Posted by Ryan View Post
You are a moron.
Sparkin is offline   Reply With Quote
Old 11-01-2006, 12:53 AM   #14 (permalink)
Forum Expert
 
Sparkin's Avatar
 
Join Date: Dec 2005
Location: Missouri , USA
Age: 38
Posts: 256
Thumbs up

Quote:
Originally Posted by strattman_2006
i have 2.0 mrfixits serverlist.cs and half the time people can connect and the other half i have to restart several time before they can connect! i found a warning when i had an error on another sctipts + Misc/ServerList/ServerList/ServerList.cs:
CS0618: Line 343: 'System.Net.Dns.Resolve(string)' is obsolete: 'Resolve is
obsoleted for this type, please use GetHostEntry instead. http://go.microsoft.co
m/fwlink/?linkid=14202' and here,s my serverlist.cs

Try to do this :P

Code:
using System;
using System.Net;
using System.Net.Sockets;
using Server;
using Server.Network;

namespace Server.Misc
{
public class ServerList
{

// ================================================== ================================
// YOUR SERVERS NAME
// ================================================== ================================
public const string ServerName = "_ _ _ _ _ _ _ _";

// ================================================== ================================
// YOUR INTERNET IP OR DNS NAME
// Here you can select to autodetect your internet ip, or manualy specify
// Examples:
// public static string Address = "12.34.56.78";
// public static string Address = "shard.host.com";
// ================================================== ================================
public const bool InternetIPAutodetect = true;
public const int MinutesBetweenIPAutodetect = 1440;
public static string Address = null;

// ================================================== ================================
// Here are some values stored
// ================================================== ================================
private static LocalLanIPRange[] LocalLanIPRanges = new LocalLanIPRange[10]; 
private static UInt32 LocalLanIPRangesCount;
private static AutoIPMirror[] AutoIPMirrors = new AutoIPMirror[10]; 
private static UInt32 AutoIPMirrorsCount;
private static DateTime InternetIPAutodetectLast;


// ================================================== ================================
// Initialization
// ================================================== ================================
public static void Initialize()
{
// ----------------------------------------------------
// Select what port to use
// ----------------------------------------------------
Listener.Port = 2593;

// ----------------------------------------------------
// Load the local LAN ip ranges
// ----------------------------------------------------
AddLocalLANIPRange("10.0.0.0", "10.255.255.255");
AddLocalLANIPRange("192.168.0.0", "192.168.255.255");
AddLocalLANIPRange("172.16.0.0", "172.32.255.255");
AddLocalLANIPRange("169.254.0.0", "169.254.255.255");

// ----------------------------------------------------
// Load the Auto IP mirros
// ----------------------------------------------------
AddAutoIPMirror("http://www.findmyip.com/", "Your IP address is:<br>", "</FONT>");
AddAutoIPMirror("http://www.ipaddy.com/", "Your IP address is: ", "<br>");
AddAutoIPMirror("http://checkip.dyndns.org/", "Current IP Address: ", "</body>");
AddAutoIPMirror("http://ipid.shat.net/iponly/", "<title>", "</title>");
AddAutoIPMirror("http://www.edpsciences.com/htbin/ipaddress", "Your IP address is <B> ", " </B>");
AddAutoIPMirror("http://www2.simflex.com/ip.shtml", "Your IP address is <BR>", "<BR>");

// ----------------------------------------------------
// Create the event
// ----------------------------------------------------
EventSink.ServerList += new ServerListEventHandler( EventSink_ServerList );

// ----------------------------------------------------
// Show info in console
// ----------------------------------------------------
Console.WriteLine("Serverlist.cs: 2.0");

// ----------------------------------------------------
// Lets find internet ip
// ----------------------------------------------------
DetectInternetIP();


}


// ================================================== ================================
// Add a range of local lan ips
// ================================================== ================================
private static void AddLocalLANIPRange(string RangeFrom, string RangeTo)
{
LocalLanIPRanges[LocalLanIPRangesCount] = new LocalLanIPRange();
LocalLanIPRanges[LocalLanIPRangesCount].RangeFrom = StringIPToUInt32IP(RangeFrom);
LocalLanIPRanges[LocalLanIPRangesCount].RangeTo = StringIPToUInt32IP(RangeTo);
LocalLanIPRangesCount = LocalLanIPRangesCount + 1;
}


// ================================================== ================================
// Convert a ip string to a binary unsigned int
// ================================================== ================================
private static UInt32 StringIPToUInt32IP(string addr)
{
byte[] byteArray1 = IPAddress.Parse(addr).GetAddressBytes();
byte[] byteArray2 = IPAddress.Parse(addr).GetAddressBytes();
byteArray1[0] = byteArray2[3];
byteArray1[1] = byteArray2[2];
byteArray1[2] = byteArray2[1];
byteArray1[3] = byteArray2[0];
return BitConverter.ToUInt32( byteArray1, 0);
}


// ================================================== ================================
// Used to store the local lan ip ranges
// ================================================== ================================
private class LocalLanIPRange
{
public UInt32 RangeFrom;
public UInt32 RangeTo;
} 


// ================================================== ================================
// Add a AutoIP mirror
// ================================================== ================================
private static void AddAutoIPMirror(string sURL, string sStart, string sEnd)
{
AutoIPMirrors[AutoIPMirrorsCount] = new AutoIPMirror();
AutoIPMirrors[AutoIPMirrorsCount].sURL = sURL;
AutoIPMirrors[AutoIPMirrorsCount].sStart = sStart;
AutoIPMirrors[AutoIPMirrorsCount].sEnd = sEnd;
AutoIPMirrorsCount = AutoIPMirrorsCount + 1;
}


// ================================================== ================================
// Used to store the Auto IP mirrors
// ================================================== ================================
private class AutoIPMirror
{
public string sURL;
public string sStart;
public string sEnd;
public UInt32 iFailures;
} 


// ================================================== ================================
// Detect ip
// ================================================== ================================
public static void DetectInternetIP()
{

// ----------------------------------------------------
// Autodetect the Internet IP
// ----------------------------------------------------
if (InternetIPAutodetect) {
DateTime UpdateTime = InternetIPAutodetectLast;
UpdateTime = UpdateTime.AddMinutes(MinutesBetweenIPAutodetect); 
if (UpdateTime<DateTime.Now) {
string NewAddress = null;
NewAddress = FindInternetIP();
InternetIPAutodetectLast = DateTime.Now;
if (NewAddress!=null) 
{
Address = NewAddress;
}
}
}

}

// ================================================== ================================
// The serverlist event
// ================================================== ================================
public static void EventSink_ServerList( ServerListEventArgs e )
{
try
{

// ----------------------------------------------------
// Lets find internet ip
// ----------------------------------------------------
DetectInternetIP();

// ----------------------------------------------------
// Find the server ip to use for this user
// ----------------------------------------------------
IPAddress ipAddr = FindMachineIP(e);

// ----------------------------------------------------
// Send serverlist
// ----------------------------------------------------
if (ipAddr != null)
{
e.AddServer( ServerName, new IPEndPoint( ipAddr, Listener.Port ) );
} else {
e.Rejected = true;
}
}
catch
{
e.Rejected = true;
}
}


// ================================================== ================================
// Connects to a webserver that gives you your internet ip
// ================================================== ================================
public static string FindInternetIP( )
{

// ----------------------------------------------------
// Pick a random mirror
// ----------------------------------------------------
Random rnd = new Random();
int UseMirror = (int)( rnd.NextDouble() * AutoIPMirrorsCount);
string MyIP = "";

// ----------------------------------------------------
// Catch if the mirror is down
// ----------------------------------------------------
try
{
// ----------------------------------------------------
// Get the webpage
// ----------------------------------------------------
WebClient client = new WebClient();
byte[] pageData = client.DownloadData(AutoIPMirrors[UseMirror].sURL);
MyIP = System.Text.Encoding.ASCII.GetString(pageData);

// ----------------------------------------------------
// Find the string
// ----------------------------------------------------
int iStart = MyIP.LastIndexOf(AutoIPMirrors[UseMirror].sStart); 
int iEnd = MyIP.IndexOf(AutoIPMirrors[UseMirror].sEnd, iStart+AutoIPMirrors[UseMirror].sStart.Length);
MyIP = MyIP.Substring(iStart+AutoIPMirrors[UseMirror].sStart.Length, iEnd-iStart-AutoIPMirrors[UseMirror].sStart.Length );
MyIP = MyIP.Trim();

// ----------------------------------------------------
// Return value
// ----------------------------------------------------
Console.WriteLine("Internet IP: {0} ({1})", MyIP, AutoIPMirrors[UseMirror].sURL);
return MyIP;
}
catch
{
Console.WriteLine("Unable to autoupdate the Internet IP from {0}!", AutoIPMirrors[UseMirror].sURL);
Console.WriteLine("----------------------------------------------------------------------");
Console.WriteLine(MyIP);
Console.WriteLine("----------------------------------------------------------------------");
return null;
}
}


// ================================================== ================================
// Calculates what server IP to use
// ================================================== ================================
public static IPAddress FindMachineIP( ServerListEventArgs e )
{
// ----------------------------------------------------
// Find the IP of the connecting user
// ----------------------------------------------------
Socket sock = e.State.Socket;
IPAddress theirAddress = ((IPEndPoint)sock.RemoteEndPoint).Address; 
IPAddress serverAddress;

// ----------------------------------------------------
// Is it Loopback?
// ----------------------------------------------------
if ( IPAddress.IsLoopback( theirAddress ) )
{
return IPAddress.Parse( "127.0.0.1" );
}

// ----------------------------------------------------
// Local
// ----------------------------------------------------
UInt32 uint32Address = StringIPToUInt32IP(theirAddress.ToString());
for (UInt32 LocalLanIPRangesLoop = 0 ; LocalLanIPRangesLoop < LocalLanIPRangesCount; LocalLanIPRangesLoop++)
{ 
if ( (LocalLanIPRanges[LocalLanIPRangesLoop].RangeFrom <= uint32Address) && (LocalLanIPRanges[LocalLanIPRangesLoop].RangeTo >= uint32Address) )
{
Resolve(Dns.GetHostName(), out serverAddress);

Console.WriteLine("Player is reconnecting to " + serverAddress.ToString());
return serverAddress;
}
}

// ----------------------------------------------------
// Internet addresses
// ----------------------------------------------------
if (Address!=null)
{
Resolve(Address, out serverAddress); 
} else {
Resolve(Dns.GetHostName(), out serverAddress); 
}

Console.WriteLine("Player is reconnecting to " + serverAddress.ToString());
return serverAddress;
}


// ================================================== ================================
// Resolves dns names
// ================================================== ================================
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;
}

}
}
Ok, Now that i can see the code i will test it and get back with ya with what i find
__________________
Quote:
Originally Posted by Ryan View Post
You are a moron.
Sparkin is offline   Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 RC5