public NetState(Socket socket, MessagePump messagePump) { m_Socket = socket; m_Buffer = new ByteQueue(); m_Running = false; m_RecvBuffer = m_ReceiveBufferPool.AcquireBuffer(); m_MessagePump = messagePump; m_SendQueue = new SendQueue(); m_NextCheckActivity = DateTime.Now + TimeSpan.FromMinutes(0.5); }
public static readonly bool Is64Bit = (IntPtr.Size == 8); //Returns the size for the current /process/ #endif #region Methods public static void Main(string[] args) { // Stuff needed for arguments string customConfig = ""; m_Assembly = Assembly.GetEntryAssembly(); Version ver = m_Assembly.GetName().Version; if (args.Length > 1) { if (Insensitive.Equals(args[1], "-config")) { try { for (int i = 2; i < args.Length; i++) { customConfig += args[i] + " "; } customConfig = customConfig.Trim(); } catch { } if (customConfig == "") { Console.WriteLine("No config file specified. Proper usage: \"-config <configFilePath>\""); return; } } else if (Insensitive.Equals(args[1], "-version")) { Utility.PrintBanner(); Console.WriteLine(string.Format("Hamaxe - Version {0}.{1}, Build {2}.{3}", ver.Major, ver.Minor, ver.Build, ver.Revision)); return; } else { Console.WriteLine("Proper usage: Hamaxe.exe [-config <configFilePath>/-version/-help]"); return; } } try { if (m_Service) { if (!Directory.Exists("Logs")) Directory.CreateDirectory("Logs"); Console.SetOut(m_MultiConOut = new MultiTextWriter(new FileLogger("Logs/Console.log"))); } else { Console.SetOut(m_MultiConOut = new MultiTextWriter(Console.Out)); } } 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"; Utility.PrintBanner(); Console.WriteLine(string.Format("Hamaxe - Version {0}.{1}, Build {2}.{3}", ver.Major, ver.Minor, ver.Build, ver.Revision)); Console.WriteLine(string.Format("Core: Running on .NET Framework Version {0}.{1}.{2}", Environment.Version.Major, Environment.Version.Minor, Environment.Version.Build)); string s = Arguments; if (s.Length > 0) Console.WriteLine("Core: Running with arguments: {0}", s); m_ProcessorCount = Environment.ProcessorCount; if (m_ProcessorCount > 1) m_MultiProcessor = true; if (m_MultiProcessor || Is64Bit) Console.WriteLine("Core: Optimizing for {0} {2}processor{1}", m_ProcessorCount, m_ProcessorCount == 1 ? "" : "s", Is64Bit ? "64-bit " : ""); int platform = (int)Environment.OSVersion.Platform; if (platform == 4 || platform == 128) { // MS 4, MONO 128 m_Unix = true; Console.WriteLine("Core: Unix environment detected"); } if (GCSettings.IsServerGC) Console.WriteLine("Core: Server garbage collection mode enabled"); while (!ScriptCompiler.Compile(m_Debug, false)) { Console.WriteLine("Scripts: One or more scripts failed to compile or no script files were found."); if (m_Service) return; Console.WriteLine(" - Press return to exit, or R to try again."); if (Console.ReadKey(true).Key != ConsoleKey.R) return; } ScriptCompiler.Invoke("Configure"); //Load ScriptCompiler.Invoke("Initialize"); //Console.WriteLine("Starting up Hamaxe"); //Console.WriteLine("Loading configuration"); Config HamaxeServerConfig; if (customConfig == "") customConfig = Serialization.Config.DEFAULT_CONFIG_FILE; else Console.WriteLine("Core: Config file specified: {0}", customConfig); HamaxeServerConfig = new Config().Load(customConfig); HamaxeServerConfig.Save(); // Create file //Server HamaxeServer = new Server(HamaxeServerConfig); Console.WriteLine("Starting input thread"); Input hamaxeInput = new Input(); hamaxeInput.Start(); Console.WriteLine("Running server"); //HamaxeServer.Run(); MessagePump messagePump = new MessagePump(); timerThread.Start(); NetState.Initialize(); EventSink.InvokeServerStarted(); }