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.

valarnin

Wanderer
Are you sure you have it exactly as i have it? make sure you switch the ServerName and Listener.Port to ServerName2 and Port2:


Code:
					e.AddServer( ServerName, new IPEndPoint( ipAddr, Listener.Port ) );
					e.AddServer( ServerName2, new IPEndPoint( ipAddr, Port2 ) );
And add the following lines:
Code:
		public const string Address2 = "69.170.201.18";  //Server 2's IP address
		public const string ServerName2 = "AOM Test Shard";  //Server 2's Name
		public const int Port2 = 2593;  //Server 2's Port
Finally, use the same ServerList.cs for server 2, but change the following lines:
Code:
		public const int Port2 = 2593;  //Server 2's Port
To:
		public const int Port2 = 2592;  //Server 2's Port
And
			Listener.Port = 2593;  //Server 1's Port
To
			Listener.Port = 2592;  //Server 1's Port
 

TurboABA

Wanderer
I just copied your two diff. types of server lists, but i changed the ip name etc. and it still doesnt work..Could this be because of that iam putting the ip and port in manualy on Uog?
 

valarnin

Wanderer
D'oh!

I see where i screwed up.

Server 2's serverlist.cs should be:
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 Address2 = "69.170.201.18";  //Server 2's IP address

		public const string Address = "69.170.201.18";  //Server's IP address

		public const string ServerName = "Age of Mayhem";  //Server 1's Name

		public const string ServerName2 = "AOM Test Shard";  //Server 2's Name

		public const int Port2 = 2593;  //Server 2's Port

		public static void Initialize()
		{
			Listener.Port = 2592;  //Server 1's Port

			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, Port2 ) );
					e.AddServer( ServerName2, 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;
		}
	}
}
 

valarnin

Wanderer
Clearing Up...

Okay, just to clear up something, the 2 serverlist.cs' that i posted, server 1 from first post and server 2 from fixed post, (IN THEORY) can be used to connect to the same computer, by having RunUO installed 2 times, and forwarding both ports to the same computer in router config. It SHOULD work.
 

eva42

Wanderer
I currently have a shard listing two shards, on the same computer. Everything works, exept if you login threw the first shard, to the second shard, and if the account doesn't exist on the second shard your not able to create a character.

How would I have the second shard auto create an account based apon what it has recieved from the first shard?
 

valarnin

Wanderer
..

-------------------------------------------------EDIT-------------------------------------------------
Thanks to eva42 for pointing out that i missed a line in AccountHandler.cs
-------------------------------------------------EDIT-------------------------------------------------



Replace the second server's Scripts/Accounting/AccountHandler.cs with this:
Code:
using System;
using System.IO;
using System.Net;
using Server;
using Server.Network;
using Server.Accounting;
using Server.Engines.Help;

namespace Server.Misc
{
	public class AccountHandler
	{
		private static int MaxAccountsPerIP = 1;
		private static bool AutoAccountCreation = true;
		private static bool RestrictDeletion = true;
		private static TimeSpan DeleteDelay = TimeSpan.FromDays( 7.0 );

		public static bool ProtectPasswords = true;

		private static AccessLevel m_LockdownLevel;

		public static AccessLevel LockdownLevel
		{
			get{ return m_LockdownLevel; }
			set{ m_LockdownLevel = value; }
		}

		private static CityInfo[] StartingCities = new CityInfo[]
			{
				new CityInfo( "Yew",		"The Empath Abbey",			633,	858,	0  ),
				new CityInfo( "Minoc",		"The Barnacle",				2476,	413,	15 ),
				new CityInfo( "Britain",	"Sweet Dreams Inn",			1496,	1628,	10 ),
				new CityInfo( "Moonglow",	"The Scholars Inn",			4408,	1168,	0  ),
				new CityInfo( "Trinsic",	"The Traveler's Inn",		1845,	2745,	0  ),
				new CityInfo( "Magincia",	"The Great Horns Tavern",	3734,	2222,	20 ),
				new CityInfo( "Jhelom",		"The Mercenary Inn",		1374,	3826,	0  ),
				new CityInfo( "Skara Brae",	"The Falconer's Inn",		618,	2234,	0  ),
				new CityInfo( "Vesper",		"The Ironwood Inn",			2771,	976,	0  ),
				new CityInfo( "Haven",		"Buckler's Hideaway",		3667,	2625,	0  )
			};

		private static bool PasswordCommandEnabled = false;

		public static void Initialize()
		{
			EventSink.DeleteRequest += new DeleteRequestEventHandler( EventSink_DeleteRequest );
			EventSink.AccountLogin += new AccountLoginEventHandler( EventSink_AccountLogin );
			EventSink.GameLogin += new GameLoginEventHandler( EventSink_GameLogin );

			if ( PasswordCommandEnabled )
				Server.Commands.Register( "Password", AccessLevel.Player, new CommandEventHandler( Password_OnCommand ) );

			if ( Core.AOS )
			{
				CityInfo haven = new CityInfo( "Haven", "Uzeraan's Mansion", 3618, 2591, 0 );
				StartingCities[StartingCities.Length - 1] = haven;
			}
		}

		[Usage( "Password <newPassword> <repeatPassword>" )]
		[Description( "Changes the password of the commanding players account. Requires the same C-class IP address as the account's creator." )]
		public static void Password_OnCommand( CommandEventArgs e )
		{
			Mobile from = e.Mobile;
			Account acct = from.Account as Account;

			if ( acct == null )
				return;

			IPAddress[] accessList = acct.LoginIPs;

			if ( accessList.Length == 0 )
				return;

			NetState ns = from.NetState;

			if ( ns == null )
				return;

			if ( e.Length == 0 )
			{
				from.SendMessage( "You must specify the new password." );
				return;
			}
			else if ( e.Length == 1 )
			{
				from.SendMessage( "To prevent potential typing mistakes, you must type the password twice. Use the format:" );
				from.SendMessage( "Password \"(newPassword)\" \"(repeated)\"" );
				return;
			}

			string pass = e.GetString( 0 );
			string pass2 = e.GetString( 1 );

			if ( pass != pass2 )
			{
				from.SendMessage( "The passwords do not match." );
				return;
			}

			bool isSafe = true;

			for ( int i = 0; isSafe && i < pass.Length; ++i )
				isSafe = ( pass[i] >= 0x20 && pass[i] < 0x80 );

			if ( !isSafe )
			{
				from.SendMessage( "That is not a valid password." );
				return;
			}

			try
			{
				IPAddress ipAddress = ((IPEndPoint)ns.Socket.RemoteEndPoint).Address;

				if ( Utility.IPMatchClassC( accessList[0], ipAddress ) )
				{
					acct.SetPassword( pass );
					from.SendMessage( "The password to your account has changed." );
				}
				else
				{
					PageEntry entry = PageQueue.GetEntry( from );

					if ( entry != null )
					{
						if ( entry.Message.StartsWith( "[Automated: Change Password]" ) )
							from.SendMessage( "You already have a password change request in the help system queue." );
						else
							from.SendMessage( "Your IP address does not match that which created this account." );
					}
					else if ( PageQueue.CheckAllowedToPage( from ) )
					{
						from.SendMessage( "Your IP address does not match that which created this account.  A page has been entered into the help system on your behalf." );

						from.SendLocalizedMessage( 501234, "", 0x35 ); /* The next available Counselor/Game Master will respond as soon as possible.
																	    * Please check your Journal for messages every few minutes.
																	    */

						PageQueue.Enqueue( new PageEntry( from, String.Format( "[Automated: Change Password]<br>Desired password: {0}<br>Current IP address: {1}<br>Account IP address: {2}", pass, ipAddress, accessList[0] ), PageType.Account ) );
					}

				}
			}
			catch
			{
			}
		}

		private static void EventSink_DeleteRequest( DeleteRequestEventArgs e )
		{
			NetState state = e.State;
			int index = e.Index;

			Account acct = state.Account as Account;

			if ( acct == null )
			{
				state.Dispose();
			}
			else if ( index < 0 || index >= 5 )
			{
				state.Send( new DeleteResult( DeleteResultType.BadRequest ) );
				state.Send( new CharacterListUpdate( acct ) );
			}
			else
			{
				Mobile m = acct[index];

				if ( m == null )
				{
					state.Send( new DeleteResult( DeleteResultType.CharNotExist ) );
					state.Send( new CharacterListUpdate( acct ) );
				}
				else if ( m.NetState != null )
				{
					state.Send( new DeleteResult( DeleteResultType.CharBeingPlayed ) );
					state.Send( new CharacterListUpdate( acct ) );
				}
				else if ( RestrictDeletion && DateTime.Now < (m.CreationTime + DeleteDelay) )
				{
					state.Send( new DeleteResult( DeleteResultType.CharTooYoung ) );
					state.Send( new CharacterListUpdate( acct ) );
				}
				else
				{
					Console.WriteLine( "Client: {0}: Deleting character {1} (0x{2:X})", state, index, m.Serial.Value );

					m.Delete();
					state.Send( new CharacterListUpdate( acct ) );
				}
			}
		}

		private static Account CreateAccount( NetState state, string un, string pw )
		{
			if ( un.Length == 0 || pw.Length == 0 )
				return null;

			bool isSafe = true;

			for ( int i = 0; isSafe && i < un.Length; ++i )
				isSafe = ( un[i] >= 0x20 && un[i] < 0x80 );

			for ( int i = 0; isSafe && i < pw.Length; ++i )
				isSafe = ( pw[i] >= 0x20 && pw[i] < 0x80 );

			if ( !isSafe )
				return null;

			IPAddress ip = state.Address;

			int count = 0;

			foreach ( Account a in Accounts.Table.Values )
			{
				if ( a.LoginIPs.Length > 0 && a.LoginIPs[0].Equals( ip ) )
				{
					++count;

					if ( count >= MaxAccountsPerIP )
					{
						Console.WriteLine( "Login: {0}: Account '{1}' not created, ip already has {2} account{3}.", state, un, MaxAccountsPerIP, MaxAccountsPerIP == 1 ? "" : "s" );
						return null;
					}
				}
			}

			Console.WriteLine( "Login: {0}: Creating new account '{1}'", state, un );
			return Accounts.AddAccount( un, pw );
		}

		public static void EventSink_AccountLogin( AccountLoginEventArgs e )
		{
			if ( !IPLimiter.SocketBlock && !IPLimiter.Verify( e.State ) )
			{
				e.Accepted = false;
				e.RejectReason = ALRReason.InUse;

				Console.WriteLine( "Login: {0}: Past IP limit threshold", e.State );

				using ( StreamWriter op = new StreamWriter( "ipLimits.log", true ) )
					op.WriteLine( "{0}\tPast IP limit threshold\t{1}", e.State, DateTime.Now );

				return;
			}

			string un = e.Username;
			string pw = e.Password;

			e.Accepted = false;
			Account acct = Accounts.GetAccount( un );

			if ( acct == null )
			{
				if ( AutoAccountCreation )
				{
					e.State.Account = acct = CreateAccount( e.State, un, pw );
					e.Accepted = acct == null ? false : acct.CheckAccess( e.State );

					if ( !e.Accepted )
						e.RejectReason = ALRReason.BadComm;
				}
				else
				{
					Console.WriteLine( "Login: {0}: Invalid username '{1}'", e.State, un );
					e.RejectReason = ALRReason.Invalid;
				}
			}
			else if ( !acct.HasAccess( e.State ) )
			{
				Console.WriteLine( "Login: {0}: Access denied for '{1}'", e.State, un );
				e.RejectReason = ( m_LockdownLevel > AccessLevel.Player ? ALRReason.BadComm : ALRReason.BadPass );
			}
			else if ( !acct.CheckPassword( pw ) )
			{
				Console.WriteLine( "Login: {0}: Invalid password for '{1}'", e.State, un );
				e.RejectReason = ALRReason.BadPass;
			}
			else if ( acct.Banned )
			{
				Console.WriteLine( "Login: {0}: Banned account '{1}'", e.State, un );
				e.RejectReason = ALRReason.Blocked;
			}
			else
			{
				Console.WriteLine( "Login: {0}: Valid credentials for '{1}'", e.State, un );
				e.State.Account = acct;
				e.Accepted = true;

				acct.LogAccess( e.State );
				acct.LastLogin = DateTime.Now;
			}

			if ( !e.Accepted )
				AccountAttackLimiter.RegisterInvalidAccess( e.State );
		}

		public static void EventSink_GameLogin( GameLoginEventArgs e )
		{
			if ( !IPLimiter.SocketBlock && !IPLimiter.Verify( e.State ) )
			{
				e.Accepted = false;

				Console.WriteLine( "Login: {0}: Past IP limit threshold", e.State );

				using ( StreamWriter op = new StreamWriter( "ipLimits.log", true ) )
					op.WriteLine( "{0}\tPast IP limit threshold\t{1}", e.State, DateTime.Now );

				return;
			}

			string un = e.Username;
			string pw = e.Password;

			Account acct = Accounts.GetAccount( un );

			if ( acct == null )
			{
				if ( AutoAccountCreation )
				{
					e.State.Account = acct = CreateAccount( e.State, un, pw );
					e.Accepted = acct == null ? false : acct.CheckAccess( e.State );
						e.CityInfo = StartingCities; //I forgot to add this line, Thanks to eva42 for pointing it out to me.

				}
				else
				{
					Console.WriteLine( "Login: {0}: Invalid username '{1}'", e.State, un );
				}
			}
			else if ( !acct.HasAccess( e.State ) )
			{
				Console.WriteLine( "Login: {0}: Access denied for '{1}'", e.State, un );
				e.Accepted = false;
			}
			else if ( !acct.CheckPassword( pw ) )
			{
				Console.WriteLine( "Login: {0}: Invalid password for '{1}'", e.State, un );
				e.Accepted = false;
			}
			else if ( acct.Banned )
			{
				Console.WriteLine( "Login: {0}: Banned account '{1}'", e.State, un );
				e.Accepted = false;
			}
			else
			{
				acct.LogAccess( e.State );

				Console.WriteLine( "Login: {0}: Account '{1}' at character list", e.State, un );
				e.State.Account = acct;
				e.Accepted = true;
				e.CityInfo = StartingCities;
			}

			if ( !e.Accepted )
				AccountAttackLimiter.RegisterInvalidAccess( e.State );
		}
	}
}
 

VOX

Wanderer
Is it even possible to connect to 2 different severs on port 2593 and trying to connect to port 2592 without changing the port manualy?
 

Twlizer

Sorceror
Help

I am useing the serverlist.cs posted in thread. I have 2 Shards On 2 Server's. I am behind a router I am forwarding both ports to each computer like they should be 2593 on main shard and 2592 on second shard. My local ips are 192.168.2.100:2593 for main shard and 192,168.2.101 for second shard. When you try to connect to second shard says host can not be reached. Any Ideas?
 

bean56

Wanderer
This is to two have two servers on one computer, not to have 2 servers on two different computers. Use a regular serverlist and everything and just forward the two different ports to the two different ips.
 

Twlizer

Sorceror
Serverlist

OK but how will i show them in the same server list? I dont want to post two different shard on uog....
 

bean56

Wanderer
Twlizer said:
OK but how will i show them in the same server list? I dont want to post two different shard on uog....
You won't. You can have people make a custom one or you will just have to make two serverlist on UOG.
 

Igon

Wanderer
As much as i hate to bring back old posts, this is of great interest to me. We are trying to run 2 shards from 2 different servers , Valarnin seems to have it pretty much done.

I can connect to the first shard fine, but I'm getting "Invalid client cetected, disconnecting" when connecting to the 2nd shard. I think I followed all the posts here and still cant quite get it.

For now I'm trying to get it to work with 2 shards on 2 different computers on the same LAN. My hope is that we can get it to function with 2 servers at 2 different locations.
 

Sep102

Page
Igon said:
As much as i hate to bring back old posts
Good, then don't do it anymore.

If you're going to ask a question, don't bring back an old thread to address it, create a new thread yourself and post the question if you'd like support, please.
 

Twlizer

Sorceror
I Don't think you can

I don't think you can. I tried for a month and was finally told you cant. I hope you do. If so please post
 

Igon

Wanderer
Sep102 said:
Good, then don't do it anymore.

If you're going to ask a question, don't bring back an old thread to address it, create a new thread yourself and post the question if you'd like support, please.

There is some usefull information in previous posts, there is no need to reinvent the wheel. It looks like Valarnin was pretty close. Why make everyone look in several different locations just to get up to speed.?
 

uoraider

Wanderer
Sep102 said:
Good, then don't do it anymore.

If you're going to ask a question, don't bring back an old thread to address it, create a new thread yourself and post the question if you'd like support, please.


All well and good Sep, But if you would take the time to read a few of Phantoms posts as well as others they all basically say the same thing. Do a search! Read the threads, If you can't solve your problem then ask the question. And in this instant we are not talking of some worthless thread that should be deleted. And to keep from getting flamed why start a new thread? Just to be tolds that this is a old subject and refered back to this thread?

We know what the answer is to the question, Yes two servers can be run on one system! But at this moment in time we see two servers in our list and only the first one can be connected to! We have followed the instructions above to a tee. But to no avail.

If you can help solve the problem then please do, If you are incapable of assisting then why speak at all?

In advance thank you all for the help on this.

uoraider
 

Sep102

Page
Igon said:
There is some usefull information in previous posts, there is no need to reinvent the wheel. It looks like Valarnin was pretty close. Why make everyone look in several different locations just to get up to speed.?
It's a better idea to create multiple threads to address different problems. Many people will only wade through so much information before posting a new question themself asking what was answered further in the thread they were browsing.

By creating different threads addressing different parts of the same problem, you allow different users to only have to look through (hopefully) a page or two of posts to find an answer to there problem, rather than five or six as in this thread.

What I would advocate related to your suggestion, though it will never happen because of the amount of time it will take due to the amount of information, is to create different groups of related threads so that users can peruse a group of threads answering different parts of a main problem. This allows them to find answers specific to their problem fast and easily if they do exist. If you have ever heard of programming recursive solutions to a larger problem, this goes along the same lines, answering the smallest problems then grouping them with other elementary answers that are then grouped with other answers until you have an answer to the entire problem.
 

HellRazor

Knight
Sep102 said:
Good, then don't do it anymore.

If you're going to ask a question, don't bring back an old thread to address it, create a new thread yourself and post the question if you'd like support, please.

And then he'll be told to "do a search". :p
 

Sep102

Page
Yes, but in this case the original thread does not completely address the problem. But there is one thing I would also like to know that does go along the same lines of this topic, why even create two shards on the same server listing? Is your shard so large as to need multiple shards to split the traffic such as on OSI? What would be the problem with having two different servers, each with one listing on the server listing?
 
Status
Not open for further replies.
Top