public Connection(Server server, Socket socket) { if (server == null) throw new ArgumentNullException("server"); if (socket == null) throw new ArgumentNullException("socket"); this._server = server; this.Socket = socket; }
static void InitRoutine() { // Extractor.ExtractMonsters(); AppDomain.CurrentDomain.UnhandledException += new System.UnhandledExceptionEventHandler(App_ThreadException); AppDomain.CurrentDomain.ProcessExit += new System.EventHandler(domain_ProcessExit); Console.WriteLine("Server " + "Loading " + Config.ServerName + "..."); ClientHandler = new Server(); IOThread = new IOThread(); WebServer = new WebSocketListener(); playerHandler = PlayerHandler.getSingleton(); world = World.getSingleton(); world.handler = playerHandler; World.w_server = ClientHandler; // instanceManager = InstanceManager.getSingleton(); Map.Init(); /* Task.Factory.StartNew(() => { IOThread.run(); });*/ (new Thread(IOThread.run)).Start(); (new Thread(ClientHandler.run)).Start(); (new Thread(WebServer.run)).Start(); Console.WriteLine("Loading tapping list"); LKCamelot.model.Modules.NSA.LoadTapList(); int waitFails = 0; long lastTicks = CurrentTimeMillis(); long totalTimeSpentProcessing = 0; int cycle = 0; #if DEBUG if (!s_bDoDebugOnlyCode) { while (!shutdownServer) { // playerHandler.process(); //EventManager.getSingleton().shutdown(); // instanceManager.process(); long timeSpent = CurrentTimeMillis() - lastTicks; totalTimeSpentProcessing += timeSpent; if (timeSpent >= Config.CycleTime) { timeSpent = Config.CycleTime; // if (++waitFails > 100) //shutdownServer = true; } try { Thread.Sleep((int)(Config.CycleTime - timeSpent)); } catch { } lastTicks = CurrentTimeMillis(); cycle++; if (cycle % 100 == 0) { //@SuppressWarnings("unused") float time = ((float)totalTimeSpentProcessing) / cycle; Console.WriteLine("KERNEL", ((time * 100) / Config.CycleTime) + "% processing time"); } } // playerHandler.destruct(); ClientHandler.killServer(); ClientHandler = null; } #endif }
public void Disconnect() { // Logger.Trace("Disconnect() | server: " + _server); try { this.Client.player.loggedIn = false; } catch { } if (_server != null) { // Use temp assignment to preven recursion. Server tempServer = _server; _server = null; tempServer.Disconnect(this); } if (this.Socket != null) { try { this.Socket.Shutdown(SocketShutdown.Both); this.Socket.Close(); } catch (Exception) { // Ignore any exceptions that might occur during attempt to close the Socket. } finally { try { this.Socket.Dispose(); this.Socket = null; } catch { } } } }