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!

Two shards/one server listing

Status
Not open for further replies.

kage1234

Wanderer
Two shards/one server listing

I was wondering if anyone can explain to me how this works, I would like to merge to shards togather and have the OSI shard listing list the shards instead of UOG.
Code:
                      Shard A: Connect and play
                    /
UOG-Name
                   \
                     Shard B: Connect and play
How does this work/how would I do this? Does this enable the host computer to host two shards?
 

KingSmidgens

Wanderer
Jason, he means how do you get two shards into the connection screen, like

Daemon's World
Test Center
Local Server

like that.. and have the TC and DW different servers with the same account..
err, you probably know what he means anyway..
 

SDragon

Wanderer
Unfortunately I only have access to the B36 script right now (not going to try and install RC1 on my work computer), but I don;t think the file changed any.

Original script code:
PHP:
public static void EventSink_ServerList( ServerListEventArgs e )
{
	try
	{
		IPAddress ipAddr;

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

Ok the part in there that makes an entry in the UO servers list is this:
PHP:
		if ( Resolve( Address != null && !IsLocalMachine( e.State ) ? Address : Dns.GetHostName(), out ipAddr ) )
			e.AddServer( ServerName, new IPEndPoint( ipAddr, Listener.Port ) );
Therefore, all you really need to do is copy that and past it back in so that you have it twice (and change the "if" to "else if" so that the rest of the code will still work properly).

You should have this now:
PHP:
public static void EventSink_ServerList( ServerListEventArgs e )
{
	try
	{
		IPAddress ipAddr;

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

Now, you just have to change the "Address", "ServerName" variables in the second entry with ones that are for the 2nd server. Also, if you are behind a router and both servers will have the same address, then you will have to give them two different port numbers.
 

roadmaster

Sorceror
How exactly does this work? If i want to have a Server that uses the normal 4 facets and also i want a Server that uses a Custom Map, How would i do this?

Now, you just have to change the "Address", "ServerName" variables in the second entry with ones that are for the 2nd server.

Perhaps i have misunderstood, How do you add a second Address and ServerName? Do you have two entries for Address and two entries for ServerName, on one Serverlist.cs? if you do that wont you receive a error "already contains a definition for"? Or are you saying that you have a Serverlist.cs for each Server with its own Address and ServerName thats different from the other? If you do have two separate Server Directories with different settings in the Serverlist.cs how does the Client know to check for the second server?

ie... if i run the primary server and it compiles fine then i run the second server and if also compiles fine, but when i run the client program it only detects the primary server. How does the client know that there is more than one server to choose from?

this is the primary server Serverlist.cs

Code:
using System;
using System.Net;
using System.Net.Sockets;
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 = null;
		public const string Address = "127.0.0.1";

		public const string ServerName = "Roadmaster's Abyss";

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

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

		public static void EventSink_ServerList( ServerListEventArgs e )
		{
			try
			{
				IPAddress ipAddr;

				if ( Resolve( Address != null && !IsLocalMachine( e.State ) ? Address : Dns.GetHostName(), out ipAddr ) )
					e.AddServer( ServerName, new IPEndPoint( ipAddr, Listener.Port ) );
				else if ( Resolve( Address != null && !IsLocalMachine( e.State ) ? Address : Dns.GetHostName(), out ipAddr ) )
					e.AddServer( ServerName, new IPEndPoint( ipAddr, 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;
		}
	}
}

and this is the Secondary ServerList.cs

Code:
using System;
using System.Net;
using System.Net.Sockets;
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 = null;
		public const string Address = "127.0.0.1";

		public const string ServerName = "Roadie's Test Center";

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

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

		public static void EventSink_ServerList( ServerListEventArgs e )
		{
			try
			{
				IPAddress ipAddr;

				if ( Resolve( Address != null && !IsLocalMachine( e.State ) ? Address : Dns.GetHostName(), out ipAddr ) )
					e.AddServer( ServerName, new IPEndPoint( ipAddr, Listener.Port ) );
				else if ( Resolve( Address != null && !IsLocalMachine( e.State ) ? Address : Dns.GetHostName(), out ipAddr ) )
					e.AddServer( ServerName, new IPEndPoint( ipAddr, 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;
		}
	}
}

Doing it like this my client will not acknowledge that there is a second server.


roadmaster
 

SDragon

Wanderer
The problem you are having is that each server list is trying to add itself twice. You have to have the IP/Port/Name information for each server in your serverlist.cs file.


In this file, I have changes the Address and ServerName variables to Address1 & ServerName1, as well as added a Port1. I have also made another copy of those varables but changed the 1 to a 2 (Address2, ServerName2, Port2). Then I modified the two if statments to each make a server entry (see code).

PHP:
using System;
using System.Net;
using System.Net.Sockets;
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 = null;
		public const string Address1 = "127.0.0.1";
		public const string ServerName1 = "Roadmaster's Abyss";
		public const int Port1 = 2593;

		public const string Address2 = "127.0.0.1";
		public const string ServerName2 = "Roadie's Test Center";
		public const int Port2 = 2592;

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

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

		public static void EventSink_ServerList( ServerListEventArgs e )
		{
			try
			{
				IPAddress ipAddr;

				if ( Resolve( Address1 != null && !IsLocalMachine( e.State ) ? Address : Dns.GetHostName(), out ipAddr ) )
					e.AddServer( ServerName1, new IPEndPoint( ipAddr, Port1 ) );
				else if ( Resolve( Address2 != null && !IsLocalMachine( e.State ) ? Address : Dns.GetHostName(), out ipAddr ) )
					e.AddServer( ServerName2, new IPEndPoint( ipAddr, Port2 ) );
				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;
		}
	}
}

If you use this serverlist on your main server (Roadmaster's Abyss), you will see both Roadmaster's Abyss & Roadie's Test Center in your serverlist in the client. You technically don't even need to have your 2nd server display the server list if your primary server is the server that you will be connecting through (ie. that is the server you have set up in UOG). The only think you need to do with it is make sure the second server's listening port is set to the port you want it to listen to. Your secondary server wont be used to choose a server to connect to, only your primary server.

However, one thing you will need to know is that since your primary server will be handling the logins, any accounts you have on the secondary server MUST exist on the primary server.
 

Thraxus

Sorceror
Have you actually proven this to work?

With the if and else if statements, the moment the first if is deemed true, it doesn't execute the else if. Therefore only the first server shows in the server list.

If you change the else if to an if, then both show up, but you can only connect successfully to the first one. If you attempt to connect to the secondary shard, it displays an error on the console that an "Invalid client detected, disconnecting".
 

Jason

Wanderer
Its simple

You can't list another computer once your connected.

You can however use the same computer if you wanted to.
 

danknight21

Wanderer
i have a host....on my host i can make up to 4 shards....same computer they r on...how do i do it?i kno like changing the port an shit

i got

2593
2592
2591

i just dont know how 2 set up the serverlist.cs
 

SDragon

Wanderer
Thraxus said:
Have you actually proven this to work?

With the if and else if statements, the moment the first if is deemed true, it doesn't execute the else if. Therefore only the first server shows in the server list.

*takes foot and shoves in mouth*

How embarassing that is for me. hehe. That is what I get for making a quick script from work where I can't test it. I know you CAN have two servers show up in the list as I have done that before. I will try to make that again tonight when I get home (and CAN test it).


*hides in shame*
 

danknight21

Wanderer
this is what me and a friend got so far. And it does show them both in the shard listing but when u click on the Test Center one the test cent client shows that they r connecting but disconnects them

here is the code:

using System;
using System.Net;
using System.Net.Sockets;
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 = null;

public const string ServerName = "Ultima AoS";

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

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

public static void EventSink_ServerList( ServerListEventArgs e )
{
try
{
IPAddress ipAddr;

if ( Resolve( Address != null && !IsLocalMachine( e.State ) ? Address : Dns.GetHostName(), out ipAddr ) )
{
e.AddServer( "Ultima AoS", new IPEndPoint( ipAddr, 2593 ) );
e.AddServer( "Test Center", new IPEndPoint( ipAddr, 2592 ) );
}
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 );

return contains;
}
}
}
 

will_man

Sorceror
Yes always seem to get "Invalide cliented detected: Disconecting" error when you try to pass it from one server to another, even if i Reset the EventSinks the error is still there which means that there must have been something changed somewhere important and im not quite clever enough to figure out where :p
 

Thraxus

Sorceror
Well SDragon says he's already made it work in the past, so I'm just going to sit tight until he posts the (hopefully successful) results of his scripting and testing.
 

Thraxus

Sorceror
Well all we have to do to find out is wait. He'll either succeed and post the working script, or fail and not post a working script. Can't do much else than wait unless you have a better idea? :p
 

will_man

Sorceror
I have made it work in the past as well, and without writing a new packet handler thingy i cant see a way to make it work now :( ( the thing that throws the error i cant find in any script so i presume its in the core ).
 
Status
Not open for further replies.
Top