From 9ac7b2760611b5dd80b11f910271b02d6813543d Mon Sep 17 00:00:00 2001 From: mark Date: Fri, 14 Sep 2007 06:40:55 +0000 Subject: [PATCH] testing a whim --- Server/Main.cs | 18 +++++++++++----- Server/Network/Compression.cs | 39 ++++++++++++++++++++++++++++++++++- 2 files changed, 51 insertions(+), 6 deletions(-) diff --git a/Server/Main.cs b/Server/Main.cs index 6eaee0394..b0dd05e43 100644 --- a/Server/Main.cs +++ b/Server/Main.cs @@ -109,8 +109,12 @@ namespace Server private static bool m_MultiProcessor; private static int m_ProcessorCount; - public static bool MultiProcessor { get { return m_MultiProcessor; } set { m_MultiProcessor = value; } } - public static int ProcessorCount { get { return m_ProcessorCount; } set { m_ProcessorCount = value; } } + public static bool MultiProcessor { get { return m_MultiProcessor; } } + public static int ProcessorCount { get { return m_ProcessorCount; } } + + private static bool m_Unix; + + public static bool Unix { get { return m_Unix; } } public static string FindDataFile( string path ) { @@ -422,15 +426,19 @@ namespace Server if( s.Length > 0 ) Console.WriteLine( "Core: Running with arguments: {0}", s ); - int processorCount = Environment.ProcessorCount; + m_ProcessorCount = Environment.ProcessorCount; - if( processorCount > 1 ) + if( m_ProcessorCount > 1 ) m_MultiProcessor = true; if( m_MultiProcessor || Is64Bit ) Console.WriteLine( "Core: Optimizing for {0} {2}processor{1}", processorCount, processorCount == 1 ? "" : "s", Is64Bit ? "64-bit " : "" ); - m_ProcessorCount = processorCount; + int platform = (int)Environment.OSVersion.Platform; + if ( ( platform == 4 ) || ( platform == 128 ) ) { // MS 4, MONO 128 + m_Unix = true; + Console.WriteLine( "Core: Unix environment detected" ); + } while( !ScriptCompiler.Compile( m_Debug, m_Cache ) ) { diff --git a/Server/Network/Compression.cs b/Server/Network/Compression.cs index 1d9deeadd..d33666493 100644 --- a/Server/Network/Compression.cs +++ b/Server/Network/Compression.cs @@ -177,7 +177,9 @@ namespace Server.Network { public static readonly ICompressor Compressor; static Compression() { - if ( Core.Is64Bit ) + if ( Core.Unix ) + Compressor = new CompressorUnix(); + else if ( Core.Is64Bit ) Compressor = new Compressor64(); else Compressor = new Compressor32(); @@ -277,6 +279,41 @@ namespace Server.Network { } } + public sealed class CompressorUnix : ICompressor { + [DllImport( "libz" )] + private static extern string zlibVersion(); + + [DllImport( "libz" )] + private static extern ZLibError compress( byte[] dest, ref int destLength, byte[] source, int sourceLength ); + + [DllImport( "libz" )] + private static extern ZLibError compress2( byte[] dest, ref int destLength, byte[] source, int sourceLength, ZLibQuality quality ); + + [DllImport( "libz" )] + private static extern ZLibError uncompress( byte[] dest, ref int destLen, byte[] source, int sourceLen ); + + public CompressorUnix() { + } + + public string Version { + get { + return zlibVersion(); + } + } + + public ZLibError Compress( byte[] dest, ref int destLength, byte[] source, int sourceLength ) { + return compress( dest, ref destLength, source, sourceLength ); + } + + public ZLibError Compress( byte[] dest, ref int destLength, byte[] source, int sourceLength, ZLibQuality quality ) { + return compress2( dest, ref destLength, source, sourceLength, quality ); + } + + public ZLibError Decompress( byte[] dest, ref int destLength, byte[] source, int sourceLength ) { + return uncompress( dest, ref destLength, source, sourceLength ); + } + } + public enum ZLibError : int { VersionError = -6, BufferError = -5,