public Library(Config.Library libConfig, Assembly _assembly) { name = libConfig.Name; assembly = _assembly; ArrayList typeList = new ArrayList(); assembly.GetTypes(); foreach (Type type in assembly.GetTypes()) { if (libConfig == null || !libConfig.GetIgnoreType(type)) typeList.Add(type); } types = (Type[])typeList.ToArray(typeof(Type)); typesByName = new TypeTable(types.Length); typesByFullName = new TypeTable(types.Length); Type typeofTypeAliasAttribute = typeof(TypeAliasAttribute); foreach (Type type in types) { typesByName.Add(type.Name, type); typesByFullName.Add(type.FullName, type); if (type.IsDefined(typeofTypeAliasAttribute, false)) { object[] attrs = type.GetCustomAttributes(typeofTypeAliasAttribute, false); if (attrs != null && attrs.Length > 0 && attrs[0] != null) { TypeAliasAttribute attr = attrs[0] as TypeAliasAttribute; foreach (string alias in attr.Aliases) typesByFullName.Add(alias, type); } } } typeCache = new TypeCache(types, typesByName, typesByFullName); }
private static void GetScripts(Config.Library libConfig, Hashtable list, string path, string type) { foreach (string dir in Directory.GetDirectories(path)) { string baseName = Path.GetFileName(dir).ToLower(); if (baseName == ".svn" || baseName == "_svn" || baseName == "_darcs" || baseName == ".git" || baseName == ".hg" || baseName == "cvs") continue; GetScripts(libConfig, list, dir, type); } foreach (string filename in Directory.GetFiles(path, type)) { /* XXX: pass relative filename only */ if (libConfig == null || !libConfig.GetIgnoreSource(filename)) list[filename] = File.GetLastWriteTime(filename); } }
private static Hashtable GetScripts(Config.Library libConfig, string type) { Hashtable list = new Hashtable(); GetScripts(libConfig, list, libConfig.SourcePath.FullName, type); return list; }
/** * enqueue a library for compilation, resolving all * dependencies first * * @param dst this array will receive the libraries in the correct order * @param libs source libraries * @param queue somewhat like a stack of libraries currently waiting * @param libConfig the library to be added */ private static void EnqueueLibrary(ArrayList dst, ArrayList libs, Hashtable queue, Config.Library libConfig) { string[] depends = libConfig.Depends; if (libConfig.Name == "core" || libConfig.Disabled) { libs.Remove(libConfig); return; } if (!libConfig.Exists) { libs.Remove(libConfig); log.WarnFormat("library {0} does not exist", libConfig.Name); return; } /* first resolve dependencies */ if (depends != null) { queue[libConfig.Name] = 1; foreach (string depend in depends) { /* if the depended library is already in the * queue, there is a circular dependency */ if (queue.ContainsKey(depend)) { log.ErrorFormat("Circular library dependency {0} on {1}", libConfig.Name, depend); throw new ApplicationException(); } Config.Library next = Core.Config.GetLibrary(depend); if (next == null || !next.Exists) { log.ErrorFormat("Unresolved library dependency: {0} depends on {1}, which does not exist", libConfig.Name, depend); throw new ApplicationException(); } if (next.Disabled) { log.ErrorFormat("Unresolved library dependency: {0} depends on {1}, which is disabled", libConfig.Name, depend); throw new ApplicationException(); } if (!dst.Contains(next)) EnqueueLibrary(dst, libs, queue, next); } queue.Remove(libConfig.Name); } /* then add it to 'dst' */ dst.Add(libConfig); libs.Remove(libConfig); }
private static bool Compile(Config.Library libConfig, bool debug) { /* check if there is source code for this library */ if (libConfig.SourcePath == null) { if (libConfig.BinaryPath == null) { log.WarnFormat("library {0} does not exist", libConfig.Name); return true; } else if (!libConfig.BinaryPath.Exists) { log.WarnFormat("library {0} does not exist: {1}", libConfig.Name, libConfig.BinaryPath); return false; } log.InfoFormat("Loading library {0}", libConfig.Name); libraries.Add(new Library(libConfig, Assembly.LoadFrom(libConfig.BinaryPath.FullName))); m_AdditionalReferences.Add(libConfig.BinaryPath.FullName); return true; } else if (!libConfig.SourcePath.Exists) { log.WarnFormat("library {0} does not exist", libConfig.Name); return true; } DirectoryInfo cache = new DirectoryInfo(Core.Config.CacheDirectory) .CreateSubdirectory("lib") .CreateSubdirectory(libConfig.Name); if (!cache.Exists) { log.ErrorFormat("Failed to create directory {0}", cache.FullName); return false; } ArrayList overlays = null; if (libConfig.Overlays != null) { overlays = new ArrayList(); foreach (string name in libConfig.Overlays) overlays.Add(Core.Config.GetLibrary(name)); } string csFile = Path.Combine(cache.FullName, libConfig.Name + ".dll"); Hashtable files = GetScripts(libConfig, overlays, "*.cs"); if (files.Count > 0) { string stampFile = Path.Combine(cache.FullName, libConfig.Name + ".stm"); if (File.Exists(csFile) && CheckStamps(files, stampFile)) { libraries.Add(new Library(libConfig, Assembly.LoadFrom(csFile))); m_AdditionalReferences.Add(csFile); log.InfoFormat("Loaded binary library {0}", libConfig.Name); } else { /* work around a serious faction bug: the factions code (Reflector.cs) assumes alphabetical directory entry order; simulate this by sorting the array. See my bug report: http://www.runuo.com/forum/showthread.php?p=373540 */ ArrayList sorted = new ArrayList(files.Keys); sorted.Sort(); CompilerResults results = CompileCSScripts(sorted, csFile, libConfig, debug); if (results != null) { if (results.Errors.HasErrors) return false; libraries.Add(new Library(libConfig, results.CompiledAssembly)); WriteStampFile(stampFile, files); } } } string vbFile = Path.Combine(cache.FullName, libConfig.Name + "-vb.dll"); files = GetScripts(libConfig, overlays, "*.vb"); if (files.Count > 0) { string stampFile = Path.Combine(cache.FullName, libConfig.Name + "-vb.stm"); if (File.Exists(vbFile) && CheckStamps(files, stampFile)) { libraries.Add(new Library(libConfig, Assembly.LoadFrom(vbFile))); m_AdditionalReferences.Add(vbFile); log.InfoFormat("Loaded binary library {0}/VB", libConfig.Name); } else { /* workaround again */ ArrayList sorted = new ArrayList(files.Keys); sorted.Sort(); CompilerResults results = CompileVBScripts(sorted, vbFile, libConfig, debug); if (results != null) { if (results.Errors.HasErrors) return false; libraries.Add(new Library(libConfig, results.CompiledAssembly)); } } } return true; }
private static Hashtable GetScripts(Config.Library libConfig, IEnumerable overlays, string type) { Hashtable files = GetScripts(libConfig, type); if (overlays != null) { foreach (Config.Library overlay in overlays) { Hashtable files2 = GetScripts(overlay, type); Overlay(libConfig.SourcePath.FullName, files, overlay.SourcePath.FullName, files2); } } return files; }
private static CompilerResults CompileVBScripts(ICollection fileColl, string assemblyFile, Config.Library libConfig, bool debug) { VBCodeProvider provider = new VBCodeProvider(); ICodeCompiler compiler = provider.CreateCompiler(); string[] files = new string[fileColl.Count]; fileColl.CopyTo(files, 0); log.InfoFormat("Compiling library {0}, {1} C# sources", libConfig.Name, files.Length); CompilerResults results = compiler.CompileAssemblyFromFileBatch( new CompilerParameters( GetReferenceAssemblies(), assemblyFile, true ), files ); m_AdditionalReferences.Add(assemblyFile); if ( results.Errors.Count > 0 ) { int errorCount = 0, warningCount = 0; foreach ( CompilerError e in results.Errors ) { if ( e.IsWarning ) ++warningCount; else ++errorCount; } if ( errorCount > 0 ) log.ErrorFormat("Compilation failed ({0} errors, {1} warnings)", errorCount, warningCount); else log.InfoFormat("Compilation complete ({0} warnings)", warningCount); foreach ( CompilerError e in results.Errors ) { String msg = String.Format("{0}: {1}: (line {2}, column {3}) {4}", e.FileName, e.ErrorNumber, e.Line, e.Column, e.ErrorText); if (e.IsWarning) log.Warn(msg); else log.Error(msg); } } else { log.Info("Compilation complete"); } return results; }
public static void Main(string[] args) { m_Assembly = Assembly.GetEntryAssembly(); /* print a banner */ Version ver = m_Assembly.GetName().Version; Console.WriteLine("SunUO Version {0}.{1}.{2} http://www.sunuo.org/", ver.Major, ver.Minor, ver.Revision); Console.WriteLine(" on {0}, runtime {1}", Environment.OSVersion, Environment.Version); if ((int)Environment.OSVersion.Platform == 128) { Console.WriteLine("Please make sure you have Mono 1.1.7 or newer! (mono -V)"); } Console.WriteLine(); /* prepare SunUO */ AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); AppDomain.CurrentDomain.ProcessExit += new EventHandler(CurrentDomain_ProcessExit); bool debug = false; for (int i = 0; i < args.Length; ++i) { if (Insensitive.Equals(args[i], "-debug")) { debug = true; } else if (Insensitive.Equals(args[i], "-service")) { m_Service = true; } else if (Insensitive.Equals(args[i], "-profile")) { Profiling = true; } else if (args[i] == "--logfile") { string logfile = args[++i]; StreamWriter writer = new StreamWriter(new FileStream(logfile, FileMode.Append, FileAccess.Write)); writer.AutoFlush = true; Console.SetOut(writer); Console.SetError(writer); } } config = new Config(Path.Combine(BaseDirectoryInfo.CreateSubdirectory("etc").FullName, "sunuo.xml")); try { m_MultiConOut = new MultiTextWriter(Console.Out); Console.SetOut(m_MultiConOut); if (m_Service) { string filename = Path.Combine(LogDirectoryInfo.FullName, "console.log"); m_MultiConOut.Add(new FileLogger(filename)); } } catch { } m_Thread = Thread.CurrentThread; m_Process = Process.GetCurrentProcess(); if (m_Thread != null) { m_Thread.Name = "Core Thread"; } if (BaseDirectory.Length > 0) { Directory.SetCurrentDirectory(BaseDirectory); } Timer.TimerThread ttObj = new Timer.TimerThread(); timerThread = new Thread(new ThreadStart(ttObj.TimerMain)); timerThread.Name = "Timer Thread"; if (!ScriptCompiler.Compile(debug)) { return; } Console.Write("Verifying scripts:"); m_ItemCount = 0; m_MobileCount = 0; foreach (Library l in ScriptCompiler.Libraries) { int itemCount = 0, mobileCount = 0; Console.Write(" {0}[", l.Name); l.Verify(ref itemCount, ref mobileCount); Console.Write("{0} items, {1} mobiles]", itemCount, mobileCount); m_ItemCount += itemCount; m_MobileCount += mobileCount; } Console.WriteLine(" - done ({0} items, {1} mobiles)", m_ItemCount, m_MobileCount); try { ScriptCompiler.Configure(); } catch (TargetInvocationException e) { Console.WriteLine("Configure exception: {0}", e.InnerException); return; } if (!config.Exists) { config.Save(); } World.Load(); try { ScriptCompiler.Initialize(); } catch (TargetInvocationException e) { Console.WriteLine("Initialize exception: {0}", e.InnerException); return; } Region.Load(); m_MessagePump = new MessagePump(new Listener(Listener.Port)); timerThread.Start(); NetState.Initialize(); Encryption.Initialize(); EventSink.InvokeServerStarted(); try { while (!m_Closing) { Thread.Sleep(1); Mobile.ProcessDeltaQueue(); Item.ProcessDeltaQueue(); Timer.Slice(); m_MessagePump.Slice(); NetState.FlushAll(); NetState.ProcessDisposedQueue(); if (Slice != null) { Slice(); } } } catch (Exception e) { CurrentDomain_UnhandledException(null, new UnhandledExceptionEventArgs(e, true)); } if (timerThread.IsAlive) { timerThread.Abort(); } }
public static void Main( string[] args ) { m_Assembly = Assembly.GetEntryAssembly(); /* print a banner */ Version ver = m_Assembly.GetName().Version; Console.WriteLine("SunLogin Version {0}.{1}.{2} http://www.sunuo.org/", ver.Major, ver.Minor, ver.Revision); Console.WriteLine(" on {0}, runtime {1}", Environment.OSVersion, Environment.Version); if ((int)Environment.OSVersion.Platform == 128) Console.WriteLine("Please make sure you have Mono 1.1.7 or newer! (mono -V)"); Console.WriteLine(); /* prepare SunUO */ 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], "-service" ) ) m_Service = true; else if ( Insensitive.Equals( args[i], "-profile" ) ) Profiling = true; else if (args[i] == "--logfile") { string logfile = args[++i]; StreamWriter writer = new StreamWriter(new FileStream(logfile, FileMode.Append, FileAccess.Write)); writer.AutoFlush = true; Console.SetOut(writer); Console.SetError(writer); } } config = new Config(Path.Combine(BaseDirectoryInfo.CreateSubdirectory("etc").FullName, "sunuo.xml")); try { m_MultiConOut = new MultiTextWriter(Console.Out); Console.SetOut(m_MultiConOut); if (m_Service) { string filename = Path.Combine(LogDirectoryInfo.FullName, "console.log"); m_MultiConOut.Add(new FileLogger(filename)); } } catch { } m_Thread = Thread.CurrentThread; if ( m_Thread != null ) m_Thread.Name = "Core Thread"; if ( BaseDirectory.Length > 0 ) Directory.SetCurrentDirectory( BaseDirectory ); Timer.TimerThread ttObj = new Timer.TimerThread(); timerThread = new Thread( new ThreadStart( ttObj.TimerMain ) ); timerThread.Name = "Timer Thread"; if (!config.Exists) config.Save(); m_MessagePump = new MessagePump( new Listener( Listener.Port ) ); timerThread.Start(); NetState.Initialize(); Encryption.Initialize(); ServerList.Initialize(); Server.Accounting.AccountHandler.Initialize(); EventSink.InvokeServerStarted(); try { while ( !m_Closing ) { Thread.Sleep( 1 ); Timer.Slice(); m_MessagePump.Slice(); NetState.FlushAll(); NetState.ProcessDisposedQueue(); if ( Slice != null ) Slice(); } } catch ( Exception e ) { CurrentDomain_UnhandledException( null, new UnhandledExceptionEventArgs( e, true ) ); } if ( timerThread.IsAlive ) timerThread.Abort(); }
public static void Start(Config.Root _config, bool debug, bool _service, bool _profiling) { config = _config; m_Service = _service; Profiling = _profiling; m_Assembly = Assembly.GetEntryAssembly(); /* prepare SunUO */ AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler( CurrentDomain_UnhandledException ); AppDomain.CurrentDomain.ProcessExit += new EventHandler( CurrentDomain_ProcessExit ); /* redirect Console to file in service mode */ if (m_Service) { string filename = Path.Combine(LogDirectoryInfo.FullName, "console.log"); FileStream stream = new FileStream(filename, FileMode.Create, FileAccess.Write, FileShare.Read); StreamWriter writer = new StreamWriter(stream); Console.SetOut(writer); Console.SetError(writer); } m_Thread = Thread.CurrentThread; m_Process = Process.GetCurrentProcess(); if ( m_Thread != null ) m_Thread.Name = "Core Thread"; if ( BaseDirectory.Length > 0 ) Directory.SetCurrentDirectory( BaseDirectory ); Timer.TimerThread ttObj = new Timer.TimerThread(); timerThread = new Thread( new ThreadStart( ttObj.TimerMain ) ); timerThread.Name = "Timer Thread"; if (!ScriptCompiler.Compile(debug)) return; m_ItemCount = 0; m_MobileCount = 0; foreach (Library l in ScriptCompiler.Libraries) { int itemCount = 0, mobileCount = 0; l.Verify(ref itemCount, ref mobileCount); log.Info(String.Format("Library {0} verified: {1} items, {2} mobiles", l.Name, itemCount, mobileCount)); m_ItemCount += itemCount; m_MobileCount += mobileCount; } log.Info(String.Format("All libraries verified: {0} items, {1} mobiles)", m_ItemCount, m_MobileCount)); try { ScriptCompiler.Configure(); } catch (TargetInvocationException e) { log.Fatal("Configure exception: {0}", e.InnerException); return; } if (!config.Exists) config.Save(); World.Load(); try { ScriptCompiler.Initialize(); } catch (TargetInvocationException e) { log.Fatal("Initialize exception: {0}", e.InnerException); return; } Region.Load(); m_MessagePump = new MessagePump( new Listener( Listener.Port ) ); timerThread.Start(); NetState.Initialize(); Encryption.Initialize(); EventSink.InvokeServerStarted(); log.Info("SunUO initialized, entering main loop"); try { while ( !m_Closing ) { m_Signal.WaitOne(); m_Now = DateTime.Now; Mobile.ProcessDeltaQueue(); Item.ProcessDeltaQueue(); Timer.Slice(); m_MessagePump.Slice(); NetState.FlushAll(); NetState.ProcessDisposedQueue(); if ( Slice != null ) Slice(); } } catch ( Exception e ) { CurrentDomain_UnhandledException( null, new UnhandledExceptionEventArgs( e, true ) ); } if ( timerThread.IsAlive ) timerThread.Abort(); }
private static void GetScripts(Config.Library libConfig, Hashtable list, string path, string type) { foreach ( string dir in Directory.GetDirectories( path ) ) GetScripts(libConfig, list, dir, type); foreach (string filename in Directory.GetFiles(path, type)) { /* XXX: pass relative filename only */ if (libConfig == null || !libConfig.GetIgnoreSource(filename)) list[filename] = File.GetLastWriteTime(filename); } }
private static CompilerResults CompileVBScripts(ICollection fileColl, string assemblyFile, Config.Library libConfig, bool debug) { VBCodeProvider provider = new VBCodeProvider(); ICodeCompiler compiler = provider.CreateCompiler(); string[] files = new string[fileColl.Count]; fileColl.CopyTo(files, 0); Console.Write("{0}[VB,{1}", libConfig.Name, files.Length); CompilerResults results = compiler.CompileAssemblyFromFileBatch( new CompilerParameters( GetReferenceAssemblies(), assemblyFile, true ), files ); m_AdditionalReferences.Add(assemblyFile); if ( results.Errors.Count > 0 ) { int errorCount = 0, warningCount = 0; foreach ( CompilerError e in results.Errors ) { if ( e.IsWarning ) ++warningCount; else ++errorCount; } Console.WriteLine(); if ( errorCount > 0 ) Console.WriteLine( "failed ({0} errors, {1} warnings)", errorCount, warningCount ); else Console.WriteLine( "done ({0} errors, {1} warnings)", errorCount, warningCount ); foreach ( CompilerError e in results.Errors ) { Console.WriteLine( " - {0}: {1}: {2}: (line {3}, column {4}) {5}", e.IsWarning ? "Warning" : "Error", e.FileName, e.ErrorNumber, e.Line, e.Column, e.ErrorText ); } } else { Console.Write("] "); } return results; }
public static void Initialize(Config.Root _config, bool _service, bool _profiling) { config = _config; m_Service = _service; Profiling = _profiling; m_Assembly = Assembly.GetEntryAssembly(); /* prepare SunUO */ AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler( CurrentDomain_UnhandledException ); AppDomain.CurrentDomain.ProcessExit += new EventHandler( CurrentDomain_ProcessExit ); /* redirect Console to file in service mode */ if (m_Service) { string filename = Path.Combine(LogDirectoryInfo.FullName, "console.log"); FileStream stream = new FileStream(filename, FileMode.Create, FileAccess.Write, FileShare.Read); StreamWriter writer = new StreamWriter(stream); Console.SetOut(writer); Console.SetError(writer); } m_Thread = Thread.CurrentThread; m_Process = Process.GetCurrentProcess(); if ( m_Thread != null ) m_Thread.Name = "Core Thread"; if ( BaseDirectory.Length > 0 ) Directory.SetCurrentDirectory( BaseDirectory ); }
public static void Main( string[] args ) { AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler( CurrentDomain_UnhandledException ); AppDomain.CurrentDomain.ProcessExit += new EventHandler( CurrentDomain_ProcessExit ); bool debug = false; for ( int i = 0; i < args.Length; ++i ) { if ( Insensitive.Equals( args[i], "-debug" ) ) debug = true; else if ( Insensitive.Equals( args[i], "-service" ) ) m_Service = true; else if ( Insensitive.Equals( args[i], "-profile" ) ) Profiling = true; } config = new Config(Path.Combine(BaseDirectoryInfo.CreateSubdirectory("etc").FullName, "sunuo.xml")); try { m_MultiConOut = new MultiTextWriter(Console.Out); Console.SetOut(m_MultiConOut); if (m_Service) { string filename = Path.Combine(LogDirectoryInfo.FullName, "console.log"); m_MultiConOut.Add(new FileLogger(filename)); } } catch { } m_Thread = Thread.CurrentThread; m_Process = Process.GetCurrentProcess(); m_Assembly = Assembly.GetEntryAssembly(); if ( m_Thread != null ) m_Thread.Name = "Core Thread"; if ( BaseDirectory.Length > 0 ) Directory.SetCurrentDirectory( BaseDirectory ); Timer.TimerThread ttObj = new Timer.TimerThread(); timerThread = new Thread( new ThreadStart( ttObj.TimerMain ) ); timerThread.Name = "Timer Thread"; Version ver = m_Assembly.GetName().Version; // Added to help future code support on forums, as a 'check' people can ask for to it see if they recompiled core or not Console.WriteLine("SunUO Version {0}.{1}.{2} http://max.kellermann.name/projects/sunuo/", ver.Major, ver.Minor, ver.Revision); while ( !ScriptCompiler.Compile( debug ) ) { 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." ); string line = Console.ReadLine(); if ( line == null || line.ToLower() != "r" ) return; } Console.Write("Verifying scripts:"); m_ItemCount = 0; m_MobileCount = 0; foreach (Library l in ScriptCompiler.Libraries) { int itemCount = 0, mobileCount = 0; Console.Write(" {0}[", l.Name); l.Verify(ref itemCount, ref mobileCount); Console.Write("{0} items, {1} mobiles]", itemCount, mobileCount); m_ItemCount += itemCount; m_MobileCount += mobileCount; } Console.WriteLine(" - done ({0} items, {1} mobiles)", m_ItemCount, m_MobileCount); try { ScriptCompiler.Configure(); } catch (TargetInvocationException e) { Console.WriteLine("Configure exception: {0}", e.InnerException); return; } config.Save(); World.Load(); try { ScriptCompiler.Initialize(); } catch (TargetInvocationException e) { Console.WriteLine("Initialize exception: {0}", e.InnerException); return; } Region.Load(); MessagePump ms = m_MessagePump = new MessagePump( new Listener( Listener.Port ) ); timerThread.Start(); NetState.Initialize(); EventSink.InvokeServerStarted(); try { while ( !m_Closing ) { Thread.Sleep( 1 ); Mobile.ProcessDeltaQueue(); Item.ProcessDeltaQueue(); Timer.Slice(); m_MessagePump.Slice(); NetState.FlushAll(); NetState.ProcessDisposedQueue(); if ( Slice != null ) Slice(); } } catch ( Exception e ) { CurrentDomain_UnhandledException( null, new UnhandledExceptionEventArgs( e, true ) ); } if ( timerThread.IsAlive ) timerThread.Abort(); }
public static NetState GameServerClient(Config.GameServer config) { if (config == null) return null; String address = config.Address.ToString(); NetState ns = (NetState)m_GameServers[address]; if (ns != null) return ns; try { ns = new NetState(config.Address, Core.MessagePump); ns.Start(); ns.Send(new SendSeed()); m_GameServers[address] = ns; return ns; } catch (Exception e) { log.Error(String.Format("Exception while trying to connect to game server {0} ({1}): {2}", config.Name, address), e); return null; } }
private static CompilerResults CompileCSScripts(ICollection fileColl, string assemblyFile, Config.Library libConfig, bool debug) { CSharpCodeProvider provider = new CSharpCodeProvider(); ICodeCompiler compiler = provider.CreateCompiler(); string[] files; log.InfoFormat("Compiling library {0}, {1} C# sources", libConfig.Name, fileColl.Count); string tempFile = compiler.GetType().FullName == "Mono.CSharp.CSharpCodeCompiler" ? Path.GetTempFileName() : null; if (tempFile == String.Empty) tempFile = null; if (tempFile == null) { files = new string[fileColl.Count]; fileColl.CopyTo(files, 0); } else { /* to prevent an "argument list too long" error, we write a list of file names to a temporary file and add them with @filename */ StreamWriter w = new StreamWriter(tempFile, false); foreach (string file in fileColl) { w.Write("\"" + file + "\" "); } w.Close(); files = new string[0]; } CompilerParameters parms = new CompilerParameters( GetReferenceAssemblies(), assemblyFile, debug ); if (tempFile != null) parms.CompilerOptions += "@" + tempFile; if (libConfig.WarningLevel >= 0) parms.WarningLevel = libConfig.WarningLevel; CompilerResults results = null; try { results = compiler.CompileAssemblyFromFileBatch( parms, files ); } catch (System.ComponentModel.Win32Exception e) { /* from WinError.h: * #define ERROR_FILE_NOT_FOUND 2L * #define ERROR_PATH_NOT_FOUND 3L */ if (e.NativeErrorCode == 2 || e.NativeErrorCode == 3) { log.Fatal("Could not find the compiler - are you sure MCS is installed?"); log.Info("On Debian, try: apt-get install mono-mcs"); Environment.Exit(2); } else { throw e; } } if (tempFile != null) File.Delete(tempFile); m_AdditionalReferences.Add(assemblyFile); if ( results.Errors.Count > 0 ) { int errorCount = 0, warningCount = 0; foreach ( CompilerError e in results.Errors ) { if ( e.IsWarning ) ++warningCount; else ++errorCount; } if ( errorCount > 0 ) log.ErrorFormat("Compilation failed ({0} errors, {1} warnings)", errorCount, warningCount); else log.InfoFormat("Compilation complete ({0} warnings)", warningCount); foreach ( CompilerError e in results.Errors ) { String msg = String.Format("{0}: {1}: (line {2}, column {3}) {4}", e.FileName, e.ErrorNumber, e.Line, e.Column, e.ErrorText); if (e.IsWarning) log.Warn(msg); else log.Error(msg); } } else { log.Info("Compilation complete"); } return results; }
public static void Main( string[] args ) { m_Assembly = Assembly.GetEntryAssembly(); /* print a banner */ Version ver = m_Assembly.GetName().Version; Console.WriteLine("SunUO Version {0}.{1}.{2} http://www.sunuo.org/", ver.Major, ver.Minor, ver.Revision); Console.WriteLine(" on {0}, runtime {1}", Environment.OSVersion, Environment.Version); if ((int)Environment.OSVersion.Platform == 128) Console.WriteLine("Please make sure you have Mono 1.1.7 or newer! (mono -V)"); Console.WriteLine(); /* prepare SunUO */ AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler( CurrentDomain_UnhandledException ); AppDomain.CurrentDomain.ProcessExit += new EventHandler( CurrentDomain_ProcessExit ); bool debug = false; for ( int i = 0; i < args.Length; ++i ) { if ( Insensitive.Equals( args[i], "-debug" ) ) debug = true; else if ( Insensitive.Equals( args[i], "-service" ) ) m_Service = true; else if ( Insensitive.Equals( args[i], "-profile" ) ) Profiling = true; else if (args[i] == "--logfile") { string logfile = args[++i]; StreamWriter writer = new StreamWriter(new FileStream(logfile, FileMode.Append, FileAccess.Write)); writer.AutoFlush = true; Console.SetOut(writer); Console.SetError(writer); } } config = new Config(Path.Combine(BaseDirectoryInfo.CreateSubdirectory("etc").FullName, "sunuo.xml")); try { m_MultiConOut = new MultiTextWriter(Console.Out); Console.SetOut(m_MultiConOut); if (m_Service) { string filename = Path.Combine(LogDirectoryInfo.FullName, "console.log"); m_MultiConOut.Add(new FileLogger(filename)); } } catch { } m_Thread = Thread.CurrentThread; m_Process = Process.GetCurrentProcess(); if ( m_Thread != null ) m_Thread.Name = "Core Thread"; if ( BaseDirectory.Length > 0 ) Directory.SetCurrentDirectory( BaseDirectory ); Timer.TimerThread ttObj = new Timer.TimerThread(); timerThread = new Thread( new ThreadStart( ttObj.TimerMain ) ); timerThread.Name = "Timer Thread"; if (!ScriptCompiler.Compile(debug)) return; Console.Write("Verifying scripts:"); m_ItemCount = 0; m_MobileCount = 0; foreach (Library l in ScriptCompiler.Libraries) { int itemCount = 0, mobileCount = 0; Console.Write(" {0}[", l.Name); l.Verify(ref itemCount, ref mobileCount); Console.Write("{0} items, {1} mobiles]", itemCount, mobileCount); m_ItemCount += itemCount; m_MobileCount += mobileCount; } Console.WriteLine(" - done ({0} items, {1} mobiles)", m_ItemCount, m_MobileCount); try { ScriptCompiler.Configure(); } catch (TargetInvocationException e) { Console.WriteLine("Configure exception: {0}", e.InnerException); return; } if (!config.Exists) config.Save(); World.Load(); try { ScriptCompiler.Initialize(); } catch (TargetInvocationException e) { Console.WriteLine("Initialize exception: {0}", e.InnerException); return; } Region.Load(); m_MessagePump = new MessagePump( new Listener( Listener.Port ) ); timerThread.Start(); NetState.Initialize(); Encryption.Initialize(); EventSink.InvokeServerStarted(); try { while ( !m_Closing ) { Thread.Sleep( 1 ); Mobile.ProcessDeltaQueue(); Item.ProcessDeltaQueue(); Timer.Slice(); m_MessagePump.Slice(); NetState.FlushAll(); NetState.ProcessDisposedQueue(); if ( Slice != null ) Slice(); } } catch ( Exception e ) { CurrentDomain_UnhandledException( null, new UnhandledExceptionEventArgs( e, true ) ); } if ( timerThread.IsAlive ) timerThread.Abort(); }
public static void Main(string[] args) { AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; AppDomain.CurrentDomain.ProcessExit += CurrentDomain_ProcessExit; foreach (string a in args) { if (Insensitive.Equals(a, "-debug")) { Debug = true; } else if (Insensitive.Equals(a, "-service")) { Service = true; } else if (Insensitive.Equals(a, "-profile")) { Profiling = true; } else if (Insensitive.Equals(a, "-nocache")) { _Cache = false; } else if (Insensitive.Equals(a, "-haltonwarning")) { HaltOnWarning = true; } else if (Insensitive.Equals(a, "-vb")) { VBdotNet = true; } else if (Insensitive.Equals(a, "-usehrt")) { _UseHRT = true; } } try { if (Service) { if (!Directory.Exists("Logs")) { Directory.CreateDirectory("Logs"); } Console.SetOut(MultiConsoleOut = new MultiTextWriter(new FileLogger("Logs/Console.log"))); } else { Console.SetOut(MultiConsoleOut = new MultiTextWriter(Console.Out)); } } catch { } Thread = Thread.CurrentThread; Process = Process.GetCurrentProcess(); Assembly = Assembly.GetEntryAssembly(); if (Thread != null) { Thread.Name = "Core Thread"; } if (BaseDirectory.Length > 0) { Directory.SetCurrentDirectory(BaseDirectory); } Timer.TimerThread ttObj = new Timer.TimerThread(); _TimerThread = new Thread(ttObj.TimerMain) { Name = "Timer Thread" }; Version ver = Assembly.GetName().Version; String publishNumber = ""; if (File.Exists("Publish.txt")) { publishNumber = File.ReadAllText("Publish.txt"); } // Added to help future code support on forums, as a 'check' people can ask for to it see if they recompiled core or not Utility.PushColor(ConsoleColor.DarkGreen); Console.WriteLine(new String('-', Console.BufferWidth)); Utility.PopColor(); Utility.PushColor(ConsoleColor.Cyan); Console.WriteLine( "ServUO - [http://www.servuo.com] Version {0}.{1}, Build {2}.{3}", ver.Major, ver.Minor, ver.Build, ver.Revision); Console.WriteLine("Publish {0}", publishNumber); Utility.PopColor(); string s = Arguments; if (s.Length > 0) { Utility.PushColor(ConsoleColor.Yellow); Console.WriteLine("Core: Running with arguments: {0}", s); Utility.PopColor(); } ProcessorCount = Environment.ProcessorCount; if (ProcessorCount > 1) { MultiProcessor = true; } if (MultiProcessor || Is64Bit) { Utility.PushColor(ConsoleColor.Green); Console.WriteLine( "Core: Optimizing for {0} {2}processor{1}", ProcessorCount, ProcessorCount == 1 ? "" : "s", Is64Bit ? "64-bit " : ""); Utility.PopColor(); } int platform = (int)Environment.OSVersion.Platform; if (platform == 4 || platform == 128) { // MS 4, MONO 128 Unix = true; Utility.PushColor(ConsoleColor.Yellow); Console.WriteLine("Core: Unix environment detected"); Utility.PopColor(); } else { m_ConsoleEventHandler = OnConsoleEvent; UnsafeNativeMethods.SetConsoleCtrlHandler(m_ConsoleEventHandler, true); } if (GCSettings.IsServerGC) { Utility.PushColor(ConsoleColor.DarkYellow); Console.WriteLine("Core: Server garbage collection mode enabled"); Utility.PopColor(); } if (_UseHRT) { Utility.PushColor(ConsoleColor.DarkYellow); Console.WriteLine( "Core: Requested high resolution timing ({0})", UsingHighResolutionTiming ? "Supported" : "Unsupported"); Utility.PopColor(); } Utility.PushColor(ConsoleColor.DarkYellow); Console.WriteLine("RandomImpl: {0} ({1})", RandomImpl.Type.Name, RandomImpl.IsHardwareRNG ? "Hardware" : "Software"); Utility.PopColor(); Utility.PushColor(ConsoleColor.DarkYellow); Console.WriteLine("Core: Loading config..."); Config.Load(); Utility.PopColor(); while (!ScriptCompiler.Compile(Debug, _Cache)) { Utility.PushColor(ConsoleColor.Red); Console.WriteLine("Scripts: One or more scripts failed to compile or no script files were found."); Utility.PopColor(); if (Service) { return; } Console.WriteLine(" - Press return to exit, or R to try again."); if (Console.ReadKey(true).Key != ConsoleKey.R) { return; } } ScriptCompiler.Invoke("Configure"); Region.Load(); World.Load(); ScriptCompiler.Invoke("Initialize"); MessagePump messagePump = MessagePump = new MessagePump(); _TimerThread.Start(); foreach (Map m in Map.AllMaps) { m.Tiles.Force(); } NetState.Initialize(); EventSink.InvokeServerStarted(); try { long now, last = TickCount; const int sampleInterval = 100; const float ticksPerSecond = 1000.0f * sampleInterval; long sample = 0; while (!Closing) { _Signal.WaitOne(); Mobile.ProcessDeltaQueue(); Item.ProcessDeltaQueue(); Timer.Slice(); messagePump.Slice(); NetState.FlushAll(); NetState.ProcessDisposedQueue(); if (Slice != null) { Slice(); } if (sample++ % sampleInterval != 0) { continue; } now = TickCount; _CyclesPerSecond[_CycleIndex++ % _CyclesPerSecond.Length] = ticksPerSecond / (now - last); last = now; } } catch (Exception e) { CurrentDomain_UnhandledException(null, new UnhandledExceptionEventArgs(e, true)); } }