Go Back   RunUO - Ultima Online Emulation > RunUO > Custom Script Release Archive

Custom Script Release Archive This is a pre-script database archive of what our users had released.

 
 
Thread Tools Display Modes
Old 05-31-2005, 02:14 PM   #1 (permalink)
Newbie
 
Join Date: Jun 2003
Posts: 42
Default Client Version fix + extra functionality

Updated 5/2/06 to use regular expression matching and have a better default client listing. Copy the code and paste to ClientRestriction.cs in your custom folder (or filename/location of your choice)

Heya folks,

Here's my solution for RunUO mis-reading Client Versions with revisions > 9 (4.0.10b for example). It also adds the ability to explicitly allow/deny specific client versions. The settings in misc/ClientVerification.cs will still be taken into consideration.

The point of this is to fix Client Versions without having to rebuild the core.

I think it's important to note that this fix actually patches up a problem in the core - without having to rebuild the core. Should save people some headaches.

Enjoy!

Code:
/// Client Version Restrictions + Fix
/// by WarLocke, based on RunUO core ClientVersion.cs
/// Developed for Alexandria, the EasyUO shard.
/// Revised 5/2/06 to use regular expressions.

using System;
using System.Collections;
using System.Net;
using Server;
using Server.Gumps;
using Server.Network;
using Server.Mobiles;
using Server.Accounting;
using System.Text;
using System.Text.RegularExpressions;
using CV = Server.ClientVersion;

namespace Server
{
	public class ClientVersionRestriction
	{
		private static bool Enabled = true;
		private static bool CheckAllowedClient = true; // check to see if client is in valid list
		private static bool CheckIllegalClient = false; // check to see if client is in banned client list
		
		private static string[] AllowedClients = new string[] {
			"5.0.2", "5.0.2a", "5.0.2b", "5.0.2c", "5.0.2d",
			"5.0.1a", "5.0.1b", "5.0.1c", "5.0.1d", "5.0.1e", "5.0.1f", "5.0.1g", "5.0.1h", "5.0.1i", "5.0.1j", "5.0.1k",
			"5.0.0a", "5.0.0b", "5.0.0c", "5.0.0d", "5.0.0e"
		};
		
		private static string[] IllegalClients = new string[] {
			"2.0.0", "2.0.3", "3.0.0c"
		};
		
		public static void Initialize()
		{
			// Register our packet handler
			PacketHandlers.Register(0xBD,   0,  true, new OnPacketReceive( ClientVersion ));
			if (Enabled) Console.WriteLine("Client Restriction is ENABLED...");
		}
		
		public static void ClientVersion( NetState state, PacketReader pvSrc )
		{
			// we want to use ClientVersion( maj, min, rev, pat, ClientType type )
			int Major = 0; 
			int Minor = 0; 
			int Revision = 0; 
			int Patch = 0; 
			ClientType CType = ClientType.Regular;
			GetVersionNumbers( pvSrc.ReadString() , ref Major, ref Minor, ref Revision, ref Patch, ref CType );
			CV version = state.Version = new CV( Major, Minor, Revision, Patch, CType );
			// end version fix
						
			if (state.Mobile != null && state.Mobile is PlayerMobile && state.Mobile.AccessLevel > AccessLevel.Player)
				return; // don't bother testing version, this character needs access.
			
			if (Enabled) {
				string kickMessage = null;
				if ((CheckAllowedClient && !ListContains(AllowedClients, version.SourceString)) 
						|| (CheckIllegalClient && ListContains(IllegalClients, version.SourceString))) {
					kickMessage = "This server requires a client version other than the one you are using.";
				} else if ( CV.Required != null && version < CV.Required ) {
					kickMessage = String.Format( "This server requires your client version be at least {0}.", CV.Required );
				} else if ( !CV.AllowGod || !CV.AllowRegular || !CV.AllowUOTD )	{
					if ( !CV.AllowGod && version.Type == ClientType.God )
						kickMessage = "This server does not allow god clients to connect.";
					else if ( !CV.AllowRegular && version.Type == ClientType.Regular )
						kickMessage = "This server does not allow regular clients to connect.";
					else if ( !CV.AllowUOTD && version.Type == ClientType.UOTD )
						kickMessage = "This server does not allow UO:TD clients to connect.";
	
					if ( !CV.AllowGod && !CV.AllowRegular && !CV.AllowUOTD )
					{
						kickMessage = "This server does not allow any clients to connect.";
					}
					else if ( CV.AllowGod && !CV.AllowRegular && !CV.AllowUOTD && version.Type != ClientType.God )
					{
						kickMessage = "This server requires you to use the god client.";
					}
					else if ( kickMessage != null )
					{
						if ( CV.AllowRegular && CV.AllowUOTD )
							kickMessage += " You can use regular or UO:TD clients.";
						else if ( CV.AllowRegular )
							kickMessage += " You can use regular clients.";
						else if ( CV.AllowUOTD )
							kickMessage += " You can use UO:TD clients.";
					}
				}
				
				if ( kickMessage != null ) {
					state.Mobile.SendMessage( 0x22, kickMessage );
					state.Mobile.SendMessage( 0x22, "You will be disconnected in {0} seconds.", CV.KickDelay.TotalSeconds );
	
					new KickTimer( state, CV.KickDelay ).Start();
				}
			}
		}
		
		private class KickTimer : Timer
		{
			private NetState m_State;

			public KickTimer( NetState state, TimeSpan delay ) : base( delay )
			{
				m_State = state;
			}

			protected override void OnTick()
			{
				if ( m_State.Socket != null ) {
					Console.WriteLine( "Client: {0}: Disconnecting, bad version ({1})", m_State, m_State.Version.SourceString );
					m_State.Dispose();
				}
			}
		}
		
		private static void GetVersionNumbers(string VerString, ref int Major, ref int Minor, ref int Revision, ref int Patch, ref ClientType Cl_Type ) {
			string Test = VerString.ToLower();
			string Exp = @"^([0-9]+)\.([0-9]+)\.([0-9]+)([a-z]?)$";
			Regex RegExp = new Regex(Exp);
			Match m = RegExp.Match(Test);
			int PatchNum = 0;
			try {
				if (m.Success) {
					if (Convert.ToString(m.Groups[4]) != "") PatchNum = (Convert.ToChar(m.Groups[4].Value) - 'a') + 1;
					Major = Convert.ToInt16(m.Groups[1].Value);
					Minor = Convert.ToInt16(m.Groups[2].Value);
					Revision = Convert.ToInt16(m.Groups[3].Value);
					Patch = PatchNum;
					if ( Test.IndexOf( "god" ) >= 0 || Test.IndexOf( "gq" ) >= 0 )
						Cl_Type = ClientType.God;
					else if ( Test.IndexOf( "third dawn" ) >= 0 || Test.IndexOf( "uo:td" ) >= 0 || Test.IndexOf( "uotd" ) >= 0 || Test.IndexOf( "uo3d" ) >= 0 || Test.IndexOf( "uo:3d" ) >= 0 )
						Cl_Type = ClientType.UOTD;
					else
						Cl_Type = ClientType.Regular;
				} else {
					throw(new System.Exception("Invalid Client Attempting Connection."));
				}
			} catch (Exception e) {
				Console.WriteLine("Exception: {0}", e.Message);
				Major = 0;
				Minor = 0;
				Revision = 0;
				Patch = 0;
				Cl_Type = ClientType.Regular;
			} finally {
			}
			return;
		}
		
		private static bool ListContains(string[] VerList, string Check) {
			for(int i = 0; i < VerList.Length; i++) {
				if (VerList[i] == Check) return true;
			}
			return false;
		}
		
	}
}
Just save as ClientRestriction.cs (or whatever name you desire) in your custom folder, and it's good to go.

Last edited by warlocke; 05-03-2006 at 02:39 PM.
warlocke is offline  
Old 06-03-2005, 08:26 PM   #2 (permalink)
 
Join Date: Apr 2005
Age: 23
Posts: 24
Default

I only need to put it in a custom folder?
Thereaper is offline  
Old 06-03-2005, 10:01 PM   #3 (permalink)
Account Terminated
 
Join Date: Apr 2004
Location: Titusville PA
Age: 26
Posts: 975
Default

Yeah how do we add this? I havent looked at it much and could probly figure it out but it would be nice if you included that in the post and maybe even a modified distro or .cs attachment. Looks like a sweet idea I think ill use it on my shard. I like the client restriction reminds me off Lonewolf but easier to use
evil lord kirby is offline  
Old 06-04-2005, 10:25 PM   #4 (permalink)
Newbie
 
Join Date: Jun 2003
Posts: 42
Default

just stick it in your custom folder, yes
warlocke is offline  
Old 06-04-2005, 11:39 PM   #5 (permalink)
Forum Expert
 
Erica's Avatar
 
Join Date: Jan 2005
Location: Laramie Wyoming
Age: 43
Posts: 1,323
Send a message via ICQ to Erica Send a message via AIM to Erica Send a message via MSN to Erica Send a message via Yahoo to Erica Send a message via Skype™ to Erica
Question

Quote:
Originally Posted by warlocke
Heya folks,

Here's my solution for RunUO mis-reading Client Versions with revisions > 9 (4.0.10b for example). It also adds the ability to explicitly allow/deny specific client versions. The settings in misc/ClientVerification.cs will still be taken into consideration.

The point of this is to fix Client Versions without having to rebuild the core.

Enjoy!

Code:
/// Client Version Restrictions + Fix
/// by WarLocke, based on RunUO core ClientVersion.cs
/// Developed for Alexandria, the EasyUO shard.

using System;
using System.Collections;
using System.Net;
using Server;
using Server.Gumps;
using Server.Network;
using Server.Mobiles;
using Server.Accounting;
using CV = Server.ClientVersion;

namespace Server
{
	public class ClientVersionRestriction
	{
		private static bool Enabled = true;
		private static bool CheckAllowedClient = false; // check to see if client is in valid list
		private static bool CheckIllegalClient = false; // check to see if client is in banned client list
		
		private static string[] AllowedClients = new string[] {
			"4.0.10c", "4.0.10b", "4.0.10a",
			"4.0.9b", "4.0.9a",
			"4.0.8a",
			"4.0.7b", "4.0.7a",
			"4.0.6a", 
			"4.0.5b", "4.0.5a",
			"4.0.4b", "4.0.4a",
			"4.0.3e", "4.0.3d", "4.0.3c", "4.0.3b", "4.0.3a",
			"4.0.2a",
			"4.0.1b"
		};
		
		private static string[] IllegalClients = new string[] {
			"2.0.0", "2.0.3", "3.0.0c"
		};
		
		public static void Initialize()
		{
			// Register our packet handler
			PacketHandlers.Register(0xBD,   0,  true, new OnPacketReceive( ClientVersion ));
			if (Enabled) Console.WriteLine("Client Restriction is ENABLED...");
		}
		
		public static void ClientVersion( NetState state, PacketReader pvSrc )
		{
			// we want to use ClientVersion( maj, min, rev, pat, ClientType type )
			int Major = 0; 
			int Minor = 0; 
			int Revision = 0; 
			int Patch = 0; 
			ClientType CType = ClientType.Regular;
			GetVersionNumbers( pvSrc.ReadString() , ref Major, ref Minor, ref Revision, ref Patch, ref CType );
			CV version = state.Version = new CV( Major, Minor, Revision, Patch, CType );
			// end version fix
						
			if (Enabled) {
				string kickMessage = null;
				if ((CheckAllowedClient && !ListContains(AllowedClients, version.SourceString)) 
						|| (CheckIllegalClient && ListContains(IllegalClients, version.SourceString))) {
					kickMessage = "This server requires a client version other than the one you are using.";
				} else if ( CV.Required != null && version < CV.Required ) {
					kickMessage = String.Format( "This server requires your client version be at least {0}.", CV.Required );
				} else if ( !CV.AllowGod || !CV.AllowRegular || !CV.AllowUOTD )	{
					if ( !CV.AllowGod && version.Type == ClientType.God )
						kickMessage = "This server does not allow god clients to connect.";
					else if ( !CV.AllowRegular && version.Type == ClientType.Regular )
						kickMessage = "This server does not allow regular clients to connect.";
					else if ( !CV.AllowUOTD && version.Type == ClientType.UOTD )
						kickMessage = "This server does not allow UO:TD clients to connect.";
	
					if ( !CV.AllowGod && !CV.AllowRegular && !CV.AllowUOTD )
					{
						kickMessage = "This server does not allow any clients to connect.";
					}
					else if ( CV.AllowGod && !CV.AllowRegular && !CV.AllowUOTD && version.Type != ClientType.God )
					{
						kickMessage = "This server requires you to use the god client.";
					}
					else if ( kickMessage != null )
					{
						if ( CV.AllowRegular && CV.AllowUOTD )
							kickMessage += " You can use regular or UO:TD clients.";
						else if ( CV.AllowRegular )
							kickMessage += " You can use regular clients.";
						else if ( CV.AllowUOTD )
							kickMessage += " You can use UO:TD clients.";
					}
				}
				
				if ( kickMessage != null ) {
					state.Mobile.SendMessage( 0x22, kickMessage );
					state.Mobile.SendMessage( 0x22, "You will be disconnected in {0} seconds.", CV.KickDelay.TotalSeconds );
	
					new KickTimer( state, CV.KickDelay ).Start();
				}
			}
		}
		
		private class KickTimer : Timer
		{
			private NetState m_State;

			public KickTimer( NetState state, TimeSpan delay ) : base( delay )
			{
				m_State = state;
			}

			protected override void OnTick()
			{
				if ( m_State.Socket != null ) {
					Console.WriteLine( "Client: {0}: Disconnecting, bad version ({1})", m_State, m_State.Version.SourceString );
					m_State.Dispose();
				}
			}
		}
		
		
		private static char[] Alphabet = new char[] { 
			'a','b','c','d','e','f','g','h','i','j','k',
			'l','m','n','o','p','q','r','s','t','u','v',
			'w','x','y','z'
		};
		
		private static void GetVersionNumbers(string VerString, ref int Major, ref int Minor, ref int Revision, ref int Patch, ref ClientType Cl_Type ) {
			int placeHolder = 0;
			int dot;
			try {
				VerString.ToLower();
				//Console.WriteLine(VerString);
				Major = int.Parse(VerString.Substring(placeHolder, dot = VerString.IndexOf(".", placeHolder)));
				placeHolder = dot + 1;
				Minor = int.Parse(VerString.Substring(placeHolder, (dot = VerString.IndexOf(".", placeHolder)) - placeHolder));
				placeHolder = dot + 1;
				if (VerString.IndexOfAny(Alphabet) > 0) {
					Revision = int.Parse(VerString.Substring(placeHolder, VerString.IndexOfAny(Alphabet) - placeHolder));
					Patch = ( VerString[VerString.IndexOfAny( Alphabet )] - 'a' ) + 1;
				} else {
					Revision = int.Parse(VerString.Substring(placeHolder));
				}
				if ( VerString.IndexOf( "god" ) >= 0 || VerString.IndexOf( "gq" ) >= 0 )
					Cl_Type = ClientType.God;
				else if ( VerString.IndexOf( "third dawn" ) >= 0 || VerString.IndexOf( "uo:td" ) >= 0 || VerString.IndexOf( "uotd" ) >= 0 || VerString.IndexOf( "uo3d" ) >= 0 || VerString.IndexOf( "uo:3d" ) >= 0 )
					Cl_Type = ClientType.UOTD;
				else
					Cl_Type = ClientType.Regular;
			} catch {
				Major = 0;
				Minor = 0;
				Revision = 0;
				Patch = 0;
				Cl_Type = ClientType.Regular;
			}
		}
		
		private static bool ListContains(string[] VerList, string Check) {
			for(int i = 0; i < VerList.Length; i++) {
				if (VerList[i] == Check) return true;
			}
			return false;
		}
		
	}
}
Just save as ClientRestriction.cs (or whatever name you desire) in your custom folder, and it's good to go.
just curious but what does this script do exactly
Erica is offline  
Old 06-05-2005, 12:52 AM   #6 (permalink)
Newbie
 
Join Date: Jun 2003
Posts: 42
Default

the current runuo release misreads client versions (4.0.10b as 4.0.1)
this fixes that. it also adds the ability to restrict allowed clients.

i'm pretty sure that's what I said in the initial post, tho...
warlocke is offline  
Old 05-01-2006, 11:21 PM   #7 (permalink)
Forum Expert
 
Join Date: Mar 2005
Location: Berlin, Germany
Age: 27
Posts: 1,136
Send a message via ICQ to Sotho Tal Ker Send a message via MSN to Sotho Tal Ker
Default

This, btw, also fixes the so called "5.0.2 client error"
Sotho Tal Ker is offline  
Old 05-02-2006, 04:29 PM   #8 (permalink)
Newbie
 
Join Date: Jun 2003
Posts: 42
Default

Wow that's some mildly embarassing code...
I'll rewrite it in a bit.

edit:
Updated.

Last edited by warlocke; 05-03-2006 at 02:43 PM.
warlocke is offline  
Old 05-03-2006, 02:48 PM   #9 (permalink)
Forum Expert
 
Erica's Avatar
 
Join Date: Jan 2005
Location: Laramie Wyoming
Age: 43
Posts: 1,323
Send a message via ICQ to Erica Send a message via AIM to Erica Send a message via MSN to Erica Send a message via Yahoo to Erica Send a message via Skype™ to Erica
Default

Is this like clientwarning script that if there on lower client then 5.0.0a they will get disconnected . Until they patch up to 5.0.0a and up?
__________________

Last edited by Erica; 05-03-2006 at 02:57 PM.
Erica is offline  
Old 05-03-2006, 03:10 PM   #10 (permalink)
Newbie
 
Join Date: Jun 2003
Posts: 42
Default

Yes, however that feature can be disabled by setting it to false.
It's primary intent is to fix client version interpretation, additional restriction stuff is secondary.
warlocke is offline  
Old 05-03-2006, 04:22 PM   #11 (permalink)
Forum Expert
 
Join Date: Mar 2005
Location: Berlin, Germany
Age: 27
Posts: 1,136
Send a message via ICQ to Sotho Tal Ker Send a message via MSN to Sotho Tal Ker
Default

I'm a good necromancer, what do you think? :P

Anyway, i liked this script and since i never experienced problems with client 5.0.2, i just mentioned it here.
And all people were so crazy about 5.0.2 and "OSI tries to f*ck up the emulator scene" bubble :P
Sotho Tal Ker is offline  
Old 05-03-2006, 04:52 PM   #12 (permalink)
Newbie
 
Join Date: Jun 2003
Posts: 42
Default

Hahah yeah, nice thread res
warlocke is offline  
 

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 - 2009, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 RC5