|
||
|
|||||||
| Custom Script Release Archive This is a pre-script database archive of what our users had released. |
|
|
Thread Tools | Display Modes |
|
|
#1 (permalink) |
|
Newbie
Join Date: Jun 2003
Posts: 42
|
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;
}
}
}
Last edited by warlocke; 05-03-2006 at 02:39 PM. |
|
|
|
|
#3 (permalink) |
|
Account Terminated
Join Date: Apr 2004
Location: Titusville PA
Age: 26
Posts: 975
|
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
![]() |
|
|
|
|
#5 (permalink) | |
|
Forum Expert
|
Quote:
|
|
|
|
|
|
#11 (permalink) |
|
Forum Expert
|
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 |
|
|
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|