-nocache option added
BaseCreatures skillcap increased to accommodate skills over 100 Cliloc fix
This commit is contained in:
parent
720c1caaa3
commit
c89964aed6
4 changed files with 504 additions and 269 deletions
358
Server/Main.cs
358
Server/Main.cs
|
|
@ -33,10 +33,12 @@ using Server.Accounting;
|
|||
using Server.Gumps;
|
||||
using Server.Network;
|
||||
|
||||
namespace Server {
|
||||
namespace Server
|
||||
{
|
||||
public delegate void Slice();
|
||||
|
||||
public class Core {
|
||||
public class Core
|
||||
{
|
||||
private static bool m_Crashed;
|
||||
private static Thread timerThread;
|
||||
private static string m_BaseDirectory;
|
||||
|
|
@ -47,6 +49,7 @@ namespace Server {
|
|||
private static Thread m_Thread;
|
||||
private static bool m_Service;
|
||||
private static bool m_Debug;
|
||||
private static bool m_Cache = true;
|
||||
private static MultiTextWriter m_MultiConOut;
|
||||
|
||||
private static bool m_Profiling;
|
||||
|
|
@ -55,32 +58,37 @@ namespace Server {
|
|||
|
||||
private static MessagePump m_MessagePump;
|
||||
|
||||
public static MessagePump MessagePump {
|
||||
public static MessagePump MessagePump
|
||||
{
|
||||
get { return m_MessagePump; }
|
||||
set { m_MessagePump = value; }
|
||||
}
|
||||
|
||||
public static Slice Slice;
|
||||
|
||||
public static bool Profiling {
|
||||
public static bool Profiling
|
||||
{
|
||||
get { return m_Profiling; }
|
||||
set {
|
||||
if ( m_Profiling == value )
|
||||
set
|
||||
{
|
||||
if( m_Profiling == value )
|
||||
return;
|
||||
|
||||
m_Profiling = value;
|
||||
|
||||
if ( m_ProfileStart > DateTime.MinValue )
|
||||
if( m_ProfileStart > DateTime.MinValue )
|
||||
m_ProfileTime += DateTime.Now - m_ProfileStart;
|
||||
|
||||
m_ProfileStart = ( m_Profiling ? DateTime.Now : DateTime.MinValue );
|
||||
m_ProfileStart = (m_Profiling ? DateTime.Now : DateTime.MinValue);
|
||||
}
|
||||
}
|
||||
|
||||
public static TimeSpan ProfileTime {
|
||||
get {
|
||||
if ( m_ProfileStart > DateTime.MinValue )
|
||||
return m_ProfileTime + ( DateTime.Now - m_ProfileStart );
|
||||
public static TimeSpan ProfileTime
|
||||
{
|
||||
get
|
||||
{
|
||||
if( m_ProfileStart > DateTime.MinValue )
|
||||
return m_ProfileTime + (DateTime.Now - m_ProfileStart);
|
||||
|
||||
return m_ProfileTime;
|
||||
}
|
||||
|
|
@ -94,7 +102,7 @@ namespace Server {
|
|||
public static Thread Thread { get { return m_Thread; } }
|
||||
public static MultiTextWriter MultiConsoleOut { get { return m_MultiConOut; } }
|
||||
|
||||
public static readonly bool Is64Bit = ( IntPtr.Size == 8 );
|
||||
public static readonly bool Is64Bit = (IntPtr.Size == 8);
|
||||
|
||||
private static bool m_MultiProcessor;
|
||||
private static int m_ProcessorCount;
|
||||
|
|
@ -102,16 +110,18 @@ namespace Server {
|
|||
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 string FindDataFile( string path ) {
|
||||
if ( m_DataDirectories.Count == 0 )
|
||||
public static string FindDataFile( string path )
|
||||
{
|
||||
if( m_DataDirectories.Count == 0 )
|
||||
throw new InvalidOperationException( "Attempted to FindDataFile before DataDirectories list has been filled." );
|
||||
|
||||
string fullPath = null;
|
||||
|
||||
for ( int i = 0; i < m_DataDirectories.Count; ++i ) {
|
||||
for( int i = 0; i < m_DataDirectories.Count; ++i )
|
||||
{
|
||||
fullPath = Path.Combine( m_DataDirectories[i], path );
|
||||
|
||||
if ( File.Exists( fullPath ) )
|
||||
if( File.Exists( fullPath ) )
|
||||
break;
|
||||
|
||||
fullPath = null;
|
||||
|
|
@ -120,41 +130,52 @@ namespace Server {
|
|||
return fullPath;
|
||||
}
|
||||
|
||||
public static string FindDataFile( string format, params object[] args ) {
|
||||
public static string FindDataFile( string format, params object[] args )
|
||||
{
|
||||
return FindDataFile( String.Format( format, args ) );
|
||||
}
|
||||
|
||||
#region Expansions
|
||||
|
||||
private static Expansion m_Expansion;
|
||||
public static Expansion Expansion {
|
||||
public static Expansion Expansion
|
||||
{
|
||||
get { return m_Expansion; }
|
||||
set { m_Expansion = value; }
|
||||
}
|
||||
|
||||
public static bool AOS {
|
||||
get {
|
||||
public static bool AOS
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Expansion >= Expansion.AOS;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool SE {
|
||||
get {
|
||||
public static bool SE
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Expansion >= Expansion.SE;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool ML {
|
||||
get {
|
||||
public static bool ML
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Expansion >= Expansion.ML;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public static string ExePath {
|
||||
get {
|
||||
if ( m_ExePath == null ) {
|
||||
public static string ExePath
|
||||
{
|
||||
get
|
||||
{
|
||||
if( m_ExePath == null )
|
||||
{
|
||||
m_ExePath = Assembly.Location;
|
||||
//m_ExePath = Process.GetCurrentProcess().MainModule.FileName;
|
||||
}
|
||||
|
|
@ -163,15 +184,21 @@ namespace Server {
|
|||
}
|
||||
}
|
||||
|
||||
public static string BaseDirectory {
|
||||
get {
|
||||
if ( m_BaseDirectory == null ) {
|
||||
try {
|
||||
public static string BaseDirectory
|
||||
{
|
||||
get
|
||||
{
|
||||
if( m_BaseDirectory == null )
|
||||
{
|
||||
try
|
||||
{
|
||||
m_BaseDirectory = ExePath;
|
||||
|
||||
if ( m_BaseDirectory.Length > 0 )
|
||||
if( m_BaseDirectory.Length > 0 )
|
||||
m_BaseDirectory = Path.GetDirectoryName( m_BaseDirectory );
|
||||
} catch {
|
||||
}
|
||||
catch
|
||||
{
|
||||
m_BaseDirectory = "";
|
||||
}
|
||||
}
|
||||
|
|
@ -180,30 +207,40 @@ namespace Server {
|
|||
}
|
||||
}
|
||||
|
||||
private static void CurrentDomain_UnhandledException( object sender, UnhandledExceptionEventArgs e ) {
|
||||
private static void CurrentDomain_UnhandledException( object sender, UnhandledExceptionEventArgs e )
|
||||
{
|
||||
Console.WriteLine( e.IsTerminating ? "Error:" : "Warning:" );
|
||||
Console.WriteLine( e.ExceptionObject );
|
||||
|
||||
if ( e.IsTerminating ) {
|
||||
if( e.IsTerminating )
|
||||
{
|
||||
m_Crashed = true;
|
||||
|
||||
bool close = false;
|
||||
|
||||
try {
|
||||
try
|
||||
{
|
||||
CrashedEventArgs args = new CrashedEventArgs( e.ExceptionObject as Exception );
|
||||
|
||||
EventSink.InvokeCrashed( args );
|
||||
|
||||
close = args.Close;
|
||||
} catch {
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
|
||||
if ( !close && !m_Service ) {
|
||||
try {
|
||||
for ( int i = 0; i < m_MessagePump.Listeners.Length; i++ ) {
|
||||
if( !close && !m_Service )
|
||||
{
|
||||
try
|
||||
{
|
||||
for( int i = 0; i < m_MessagePump.Listeners.Length; i++ )
|
||||
{
|
||||
m_MessagePump.Listeners[i].Dispose();
|
||||
}
|
||||
} catch {
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
|
||||
Console.WriteLine( "This exception is fatal, press return to exit" );
|
||||
|
|
@ -215,11 +252,12 @@ namespace Server {
|
|||
}
|
||||
|
||||
#if !MONO
|
||||
private enum ConsoleEventType {
|
||||
private enum ConsoleEventType
|
||||
{
|
||||
CTRL_C_EVENT,
|
||||
CTRL_BREAK_EVENT,
|
||||
CTRL_CLOSE_EVENT,
|
||||
CTRL_LOGOFF_EVENT = 5,
|
||||
CTRL_LOGOFF_EVENT=5,
|
||||
CTRL_SHUTDOWN_EVENT
|
||||
}
|
||||
|
||||
|
|
@ -229,15 +267,17 @@ namespace Server {
|
|||
[System.Runtime.InteropServices.DllImport( "Kernel32.dll" )]
|
||||
private static extern bool SetConsoleCtrlHandler( ConsoleEventHandler callback, bool add );
|
||||
|
||||
private static bool OnConsoleEvent( ConsoleEventType type ) {
|
||||
if ( World.Saving )
|
||||
private static bool OnConsoleEvent( ConsoleEventType type )
|
||||
{
|
||||
if( World.Saving )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
private static void CurrentDomain_ProcessExit( object sender, EventArgs e ) {
|
||||
private static void CurrentDomain_ProcessExit( object sender, EventArgs e )
|
||||
{
|
||||
HandleClosed();
|
||||
}
|
||||
|
||||
|
|
@ -248,64 +288,79 @@ namespace Server {
|
|||
private static int m_CycleIndex;
|
||||
private static float[] m_CyclesPerSecond = new float[100];
|
||||
|
||||
public static float CyclesPerSecond {
|
||||
get { return m_CyclesPerSecond[Math.Max( 0, ( m_CycleIndex - 1 ) % m_CyclesPerSecond.Length )]; }
|
||||
public static float CyclesPerSecond
|
||||
{
|
||||
get { return m_CyclesPerSecond[Math.Max( 0, (m_CycleIndex - 1) % m_CyclesPerSecond.Length )]; }
|
||||
}
|
||||
|
||||
public static float AverageCPS {
|
||||
get {
|
||||
public static float AverageCPS
|
||||
{
|
||||
get
|
||||
{
|
||||
float t = 0.0f;
|
||||
int c = 0;
|
||||
|
||||
for ( int i = 0; i < m_CycleIndex && i < m_CyclesPerSecond.Length; ++i ) {
|
||||
for( int i = 0; i < m_CycleIndex && i < m_CyclesPerSecond.Length; ++i )
|
||||
{
|
||||
t += m_CyclesPerSecond[i];
|
||||
++c;
|
||||
}
|
||||
|
||||
return ( t / Math.Max( c, 1 ) );
|
||||
return (t / Math.Max( c, 1 ));
|
||||
}
|
||||
}
|
||||
|
||||
private static void HandleClosed() {
|
||||
if ( m_Closing )
|
||||
private static void HandleClosed()
|
||||
{
|
||||
if( m_Closing )
|
||||
return;
|
||||
|
||||
m_Closing = true;
|
||||
|
||||
Console.Write( "Exiting..." );
|
||||
|
||||
if ( !m_Crashed )
|
||||
if( !m_Crashed )
|
||||
EventSink.InvokeShutdown( new ShutdownEventArgs() );
|
||||
|
||||
if ( timerThread.ThreadState != System.Threading.ThreadState.Unstarted )
|
||||
if( timerThread.ThreadState != System.Threading.ThreadState.Unstarted )
|
||||
timerThread.Join();
|
||||
|
||||
Console.WriteLine( "done" );
|
||||
}
|
||||
|
||||
public static void Main( string[] args ) {
|
||||
public static void Main( string[] args )
|
||||
{
|
||||
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler( CurrentDomain_UnhandledException );
|
||||
AppDomain.CurrentDomain.ProcessExit += new EventHandler( CurrentDomain_ProcessExit );
|
||||
|
||||
for ( int i = 0; i < args.Length; ++i ) {
|
||||
if ( Insensitive.Equals( args[i], "-debug" ) )
|
||||
for( int i = 0; i < args.Length; ++i )
|
||||
{
|
||||
if( Insensitive.Equals( args[i], "-debug" ) )
|
||||
m_Debug = true;
|
||||
else if ( Insensitive.Equals( args[i], "-service" ) )
|
||||
else if( Insensitive.Equals( args[i], "-service" ) )
|
||||
m_Service = true;
|
||||
else if ( Insensitive.Equals( args[i], "-profile" ) )
|
||||
else if( Insensitive.Equals( args[i], "-profile" ) )
|
||||
Profiling = true;
|
||||
else if( Insensitive.Equals( args[i], "-nocache" ) )
|
||||
m_Cache = false;
|
||||
}
|
||||
|
||||
try {
|
||||
if ( m_Service ) {
|
||||
if ( !Directory.Exists( "Logs" ) )
|
||||
try
|
||||
{
|
||||
if( m_Service )
|
||||
{
|
||||
if( !Directory.Exists( "Logs" ) )
|
||||
Directory.CreateDirectory( "Logs" );
|
||||
|
||||
Console.SetOut( m_MultiConOut = new MultiTextWriter( Console.Out, new FileLogger( "Logs/Console.log" ) ) );
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.SetOut( m_MultiConOut = new MultiTextWriter( Console.Out ) );
|
||||
}
|
||||
} catch {
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
|
||||
#if !MONO
|
||||
|
|
@ -317,10 +372,10 @@ namespace Server {
|
|||
m_Process = Process.GetCurrentProcess();
|
||||
m_Assembly = Assembly.GetEntryAssembly();
|
||||
|
||||
if ( m_Thread != null )
|
||||
if( m_Thread != null )
|
||||
m_Thread.Name = "Core Thread";
|
||||
|
||||
if ( BaseDirectory.Length > 0 )
|
||||
if( BaseDirectory.Length > 0 )
|
||||
Directory.SetCurrentDirectory( BaseDirectory );
|
||||
|
||||
Timer.TimerThread ttObj = new Timer.TimerThread();
|
||||
|
|
@ -335,24 +390,25 @@ namespace Server {
|
|||
|
||||
string s = Arguments;
|
||||
|
||||
if ( s.Length > 0 )
|
||||
if( s.Length > 0 )
|
||||
Console.WriteLine( "Core: Running with arguments: {0}", s );
|
||||
|
||||
int processorCount = Environment.ProcessorCount;
|
||||
|
||||
if ( processorCount > 1 )
|
||||
if( processorCount > 1 )
|
||||
m_MultiProcessor = true;
|
||||
|
||||
if ( m_MultiProcessor || Is64Bit )
|
||||
if( m_MultiProcessor || Is64Bit )
|
||||
Console.WriteLine( "Core: Optimizing for {0} {2}processor{1}", processorCount, processorCount == 1 ? "" : "s", Is64Bit ? "64-bit " : "" );
|
||||
|
||||
m_ProcessorCount = processorCount;
|
||||
|
||||
while ( !ScriptCompiler.Compile( m_Debug ) ) {
|
||||
while( !ScriptCompiler.Compile( m_Debug, m_Cache ) )
|
||||
{
|
||||
Console.WriteLine( "Scripts: One or more scripts failed to compile or no script files were found." );
|
||||
Console.WriteLine( " - Press return to exit, or R to try again." );
|
||||
|
||||
if ( Console.ReadKey( true ).Key != ConsoleKey.R )
|
||||
if( Console.ReadKey( true ).Key != ConsoleKey.R )
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -360,22 +416,24 @@ namespace Server {
|
|||
|
||||
timerThread.Start();
|
||||
|
||||
for ( int i = 0; i < Map.AllMaps.Count; ++i )
|
||||
for( int i = 0; i < Map.AllMaps.Count; ++i )
|
||||
Map.AllMaps[i].Tiles.Force();
|
||||
|
||||
NetState.Initialize();
|
||||
|
||||
EventSink.InvokeServerStarted();
|
||||
|
||||
try {
|
||||
try
|
||||
{
|
||||
DateTime now, last = DateTime.Now;
|
||||
|
||||
const int sampleInterval = 100;
|
||||
const float ticksPerSecond = ( float ) ( TimeSpan.TicksPerSecond * sampleInterval );
|
||||
const float ticksPerSecond = (float)(TimeSpan.TicksPerSecond * sampleInterval);
|
||||
|
||||
int sample = 0;
|
||||
|
||||
while ( !m_Closing ) {
|
||||
while( !m_Closing )
|
||||
{
|
||||
Thread.Sleep( m_MultiProcessor ? 0 : 1 );
|
||||
|
||||
Mobile.ProcessDeltaQueue();
|
||||
|
|
@ -387,44 +445,53 @@ namespace Server {
|
|||
NetState.FlushAll();
|
||||
NetState.ProcessDisposedQueue();
|
||||
|
||||
if ( Slice != null )
|
||||
if( Slice != null )
|
||||
Slice();
|
||||
|
||||
if ( ( ++sample % sampleInterval ) == 0 ) {
|
||||
if( (++sample % sampleInterval) == 0 )
|
||||
{
|
||||
now = DateTime.Now;
|
||||
m_CyclesPerSecond[m_CycleIndex++ % m_CyclesPerSecond.Length] =
|
||||
ticksPerSecond / ( now.Ticks - last.Ticks );
|
||||
ticksPerSecond / (now.Ticks - last.Ticks);
|
||||
last = now;
|
||||
}
|
||||
}
|
||||
} catch ( Exception e ) {
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
CurrentDomain_UnhandledException( null, new UnhandledExceptionEventArgs( e, true ) );
|
||||
}
|
||||
|
||||
if ( timerThread.IsAlive )
|
||||
if( timerThread.IsAlive )
|
||||
timerThread.Abort();
|
||||
}
|
||||
|
||||
public static string Arguments {
|
||||
get {
|
||||
public static string Arguments
|
||||
{
|
||||
get
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
if ( Core.Debug )
|
||||
if( Core.Debug )
|
||||
Utility.Seperate( sb, "-debug", " " );
|
||||
|
||||
if ( Core.Service )
|
||||
if( Core.Service )
|
||||
Utility.Seperate( sb, "-service", " " );
|
||||
|
||||
if ( Core.Profiling )
|
||||
if( Core.Profiling )
|
||||
Utility.Seperate( sb, "-profile", " " );
|
||||
|
||||
if( !m_Cache )
|
||||
Utility.Seperate( sb, "-nocache", " " );
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
private static int m_GlobalMaxUpdateRange = 24;
|
||||
|
||||
public static int GlobalMaxUpdateRange {
|
||||
public static int GlobalMaxUpdateRange
|
||||
{
|
||||
get { return m_GlobalMaxUpdateRange; }
|
||||
set { m_GlobalMaxUpdateRange = value; }
|
||||
}
|
||||
|
|
@ -434,34 +501,39 @@ namespace Server {
|
|||
public static int ScriptItems { get { return m_ItemCount; } }
|
||||
public static int ScriptMobiles { get { return m_MobileCount; } }
|
||||
|
||||
public static void VerifySerialization() {
|
||||
public static void VerifySerialization()
|
||||
{
|
||||
m_ItemCount = 0;
|
||||
m_MobileCount = 0;
|
||||
|
||||
VerifySerialization( Assembly.GetCallingAssembly() );
|
||||
|
||||
for ( int a = 0; a < ScriptCompiler.Assemblies.Length; ++a )
|
||||
for( int a = 0; a < ScriptCompiler.Assemblies.Length; ++a )
|
||||
VerifySerialization( ScriptCompiler.Assemblies[a] );
|
||||
}
|
||||
|
||||
private static void VerifySerialization( Assembly a ) {
|
||||
if ( a == null )
|
||||
private static void VerifySerialization( Assembly a )
|
||||
{
|
||||
if( a == null )
|
||||
return;
|
||||
|
||||
Type[] ctorTypes = new Type[] { typeof( Serial ) };
|
||||
|
||||
foreach ( Type t in a.GetTypes() ) {
|
||||
foreach( Type t in a.GetTypes() )
|
||||
{
|
||||
bool isItem = t.IsSubclassOf( typeof( Item ) );
|
||||
|
||||
if ( isItem || t.IsSubclassOf( typeof( Mobile ) ) ) {
|
||||
if ( isItem )
|
||||
if( isItem || t.IsSubclassOf( typeof( Mobile ) ) )
|
||||
{
|
||||
if( isItem )
|
||||
++m_ItemCount;
|
||||
else
|
||||
++m_MobileCount;
|
||||
|
||||
bool warned = false;
|
||||
|
||||
try {
|
||||
try
|
||||
{
|
||||
|
||||
/*
|
||||
if( isItem && t.IsPublic && !t.IsAbstract )
|
||||
|
|
@ -478,40 +550,46 @@ namespace Server {
|
|||
}
|
||||
*/
|
||||
|
||||
if ( t.GetConstructor( ctorTypes ) == null ) {
|
||||
if ( !warned )
|
||||
if( t.GetConstructor( ctorTypes ) == null )
|
||||
{
|
||||
if( !warned )
|
||||
Console.WriteLine( "Warning: {0}", t );
|
||||
|
||||
warned = true;
|
||||
Console.WriteLine( " - No serialization constructor" );
|
||||
}
|
||||
|
||||
if ( t.GetMethod( "Serialize", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly ) == null ) {
|
||||
if ( !warned )
|
||||
if( t.GetMethod( "Serialize", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly ) == null )
|
||||
{
|
||||
if( !warned )
|
||||
Console.WriteLine( "Warning: {0}", t );
|
||||
|
||||
warned = true;
|
||||
Console.WriteLine( " - No Serialize() method" );
|
||||
}
|
||||
|
||||
if ( t.GetMethod( "Deserialize", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly ) == null ) {
|
||||
if ( !warned )
|
||||
if( t.GetMethod( "Deserialize", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly ) == null )
|
||||
{
|
||||
if( !warned )
|
||||
Console.WriteLine( "Warning: {0}", t );
|
||||
|
||||
warned = true;
|
||||
Console.WriteLine( " - No Deserialize() method" );
|
||||
}
|
||||
|
||||
if ( warned )
|
||||
if( warned )
|
||||
Console.WriteLine();
|
||||
} catch {
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class FileLogger : TextWriter, IDisposable {
|
||||
public class FileLogger : TextWriter, IDisposable
|
||||
{
|
||||
private string m_FileName;
|
||||
private bool m_NewLine;
|
||||
public const string DateFormat = "[MMMM dd hh:mm:ss.f tt]: ";
|
||||
|
|
@ -519,20 +597,26 @@ namespace Server {
|
|||
public string FileName { get { return m_FileName; } }
|
||||
|
||||
public FileLogger( string file )
|
||||
: this( file, false ) {
|
||||
: this( file, false )
|
||||
{
|
||||
}
|
||||
|
||||
public FileLogger( string file, bool append ) {
|
||||
public FileLogger( string file, bool append )
|
||||
{
|
||||
m_FileName = file;
|
||||
using ( StreamWriter writer = new StreamWriter( new FileStream( m_FileName, append ? FileMode.Append : FileMode.Create, FileAccess.Write, FileShare.Read ) ) ) {
|
||||
using( StreamWriter writer = new StreamWriter( new FileStream( m_FileName, append ? FileMode.Append : FileMode.Create, FileAccess.Write, FileShare.Read ) ) )
|
||||
{
|
||||
writer.WriteLine( ">>>Logging started on {0}.", DateTime.Now.ToString( "f" ) ); //f = Tuesday, April 10, 2001 3:51 PM
|
||||
}
|
||||
m_NewLine = true;
|
||||
}
|
||||
|
||||
public override void Write( char ch ) {
|
||||
using ( StreamWriter writer = new StreamWriter( new FileStream( m_FileName, FileMode.Append, FileAccess.Write, FileShare.Read ) ) ) {
|
||||
if ( m_NewLine ) {
|
||||
public override void Write( char ch )
|
||||
{
|
||||
using( StreamWriter writer = new StreamWriter( new FileStream( m_FileName, FileMode.Append, FileAccess.Write, FileShare.Read ) ) )
|
||||
{
|
||||
if( m_NewLine )
|
||||
{
|
||||
writer.Write( DateTime.Now.ToString( DateFormat ) );
|
||||
m_NewLine = false;
|
||||
}
|
||||
|
|
@ -540,9 +624,12 @@ namespace Server {
|
|||
}
|
||||
}
|
||||
|
||||
public override void Write( string str ) {
|
||||
using ( StreamWriter writer = new StreamWriter( new FileStream( m_FileName, FileMode.Append, FileAccess.Write, FileShare.Read ) ) ) {
|
||||
if ( m_NewLine ) {
|
||||
public override void Write( string str )
|
||||
{
|
||||
using( StreamWriter writer = new StreamWriter( new FileStream( m_FileName, FileMode.Append, FileAccess.Write, FileShare.Read ) ) )
|
||||
{
|
||||
if( m_NewLine )
|
||||
{
|
||||
writer.Write( DateTime.Now.ToString( DateFormat ) );
|
||||
m_NewLine = false;
|
||||
}
|
||||
|
|
@ -550,53 +637,64 @@ namespace Server {
|
|||
}
|
||||
}
|
||||
|
||||
public override void WriteLine( string line ) {
|
||||
using ( StreamWriter writer = new StreamWriter( new FileStream( m_FileName, FileMode.Append, FileAccess.Write, FileShare.Read ) ) ) {
|
||||
if ( m_NewLine )
|
||||
public override void WriteLine( string line )
|
||||
{
|
||||
using( StreamWriter writer = new StreamWriter( new FileStream( m_FileName, FileMode.Append, FileAccess.Write, FileShare.Read ) ) )
|
||||
{
|
||||
if( m_NewLine )
|
||||
writer.Write( DateTime.Now.ToString( DateFormat ) );
|
||||
writer.WriteLine( line );
|
||||
m_NewLine = true;
|
||||
}
|
||||
}
|
||||
|
||||
public override System.Text.Encoding Encoding {
|
||||
public override System.Text.Encoding Encoding
|
||||
{
|
||||
get { return System.Text.Encoding.Default; }
|
||||
}
|
||||
}
|
||||
|
||||
public class MultiTextWriter : TextWriter {
|
||||
public class MultiTextWriter : TextWriter
|
||||
{
|
||||
private List<TextWriter> m_Streams;
|
||||
|
||||
public MultiTextWriter( params TextWriter[] streams ) {
|
||||
public MultiTextWriter( params TextWriter[] streams )
|
||||
{
|
||||
m_Streams = new List<TextWriter>( streams );
|
||||
|
||||
if ( m_Streams.Count < 0 )
|
||||
if( m_Streams.Count < 0 )
|
||||
throw new ArgumentException( "You must specify at least one stream." );
|
||||
}
|
||||
|
||||
public void Add( TextWriter tw ) {
|
||||
public void Add( TextWriter tw )
|
||||
{
|
||||
m_Streams.Add( tw );
|
||||
}
|
||||
|
||||
public void Remove( TextWriter tw ) {
|
||||
public void Remove( TextWriter tw )
|
||||
{
|
||||
m_Streams.Remove( tw );
|
||||
}
|
||||
|
||||
public override void Write( char ch ) {
|
||||
for ( int i = 0; i < m_Streams.Count; i++ )
|
||||
public override void Write( char ch )
|
||||
{
|
||||
for( int i = 0; i < m_Streams.Count; i++ )
|
||||
m_Streams[i].Write( ch );
|
||||
}
|
||||
|
||||
public override void WriteLine( string line ) {
|
||||
for ( int i = 0; i < m_Streams.Count; i++ )
|
||||
public override void WriteLine( string line )
|
||||
{
|
||||
for( int i = 0; i < m_Streams.Count; i++ )
|
||||
m_Streams[i].WriteLine( line );
|
||||
}
|
||||
|
||||
public override void WriteLine( string line, params object[] args ) {
|
||||
public override void WriteLine( string line, params object[] args )
|
||||
{
|
||||
WriteLine( String.Format( line, args ) );
|
||||
}
|
||||
|
||||
public override Encoding Encoding {
|
||||
public override Encoding Encoding
|
||||
{
|
||||
get { return Encoding.Default; }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue