public SimCoreServer() { ServerOptions.ReadFile(); WriteClientAppConfig(); simEngine.Initialize(ServerOptions.SimulationModelPath, ServerOptions.PortNumber); simEngine.StartSimCore(); simEngine.StartViewManager(); eventClient = new SimulationEventDistributorClient(); simEngine.simCore.distributor.RegisterClient(ref eventClient); eventClient.Subscribe("PauseScenarioRequest"); eventClient.Subscribe("ResumeScenarioRequest"); eventClient.Subscribe("LoadScenarioRequest"); eventClient.Subscribe("StopScenarioRequest"); eventClient.Subscribe("SimCoreReady"); eventClient.Subscribe("ForkReplayStarted"); eventClient.Subscribe("ForkReplayFinished"); eventClient.Subscribe("GameSpeedRequest"); //AD: UN-Removed for now }
private void ConnectionHandler() { NetMessage m = new NetMessage(); SimulationEvent e = null; while (true) { try { m.Receive(ref netStream); switch (m.type) { case NetMessageType.REGISTER: eventDistClient = new SimulationEventDistributorClient(); networkServer.eventDist.RegisterClient(ref eventDistClient); m_terminalID = m.TerminalID; m.type = NetMessageType.REGISTER_RESPONSE; //m.clientID = networkServer.RegisterClient(); m.clientID = eventDistClient.id; m.Send(ref netStream, m.TerminalID); break; case NetMessageType.SUBSCRIBE: eventDistClient.Subscribe(m.msg); break; case NetMessageType.EVENT: try { e = SimulationEventFactory.XMLDeserialize(m.msg); eventDistClient.PutEvent(e); } catch (Exception exc) { ErrorLog.Write(String.Format("NONFATAL Deserialize Error in NetworkServer: {0}", m.msg)); ErrorLog.Write(exc.ToString()); } //networkServer.EventFromClient(e); break; case NetMessageType.DISCONNECT: //netStream.Close(0); System.Console.WriteLine("NetworkServerConnectionHandler.ConnectionHandler:connection closed"); //netStream.Dispose(); //networkServer.RemoveClient(eventDistClient.id); sendThread.Abort(); ForceClose(); return; case NetMessageType.NONE: ErrorLog.Write(String.Format("NONFATAL Deserialize Error in NetworkServer: {0}", m.msg)); ErrorLog.Write(String.Format("TYPE: {0}; MSG: {1};",m.type, m.msg)); break; default: throw new Exception("connection handler got an invalid event"); } } catch (System.IO.IOException exc) { System.Console.WriteLine("NetworkServerConnectionHandler.ConnectionHandler:lost connection with client"); ForceClose(); return; } catch (System.ObjectDisposedException) { return; } catch (ThreadAbortException) { return; } catch (Exception exc) { MessageBox.Show("An error has occured in the Simulation Server.\nPlease email the C:\\DDDErrorLog.txt file to Aptima customer support with a description of what you were doing at the time of the error."); ErrorLog.Write(exc.ToString() + "\n"); throw new Exception(); } } }
public Form1() { string errorMsg = string.Empty; int seats = -1; if (Environment.GetCommandLineArgs().Length > 1) { ServerOptions.ReadFile(); String portString = Environment.GetCommandLineArgs()[1]; ServerOptions.PortNumber = Int32.Parse(portString); ServerOptions.WriteFile(); } else { ServerConfigDialog d = new ServerConfigDialog(); d.DialogMessage = "Configure the server port:"; if (d.ShowDialog(this) == DialogResult.Cancel) { MessageBox.Show(this, "Closing DDD", "User Requested Shutdown", MessageBoxButtons.OK); this.Close(); return; } while (!SimCoreServer.SimCoreServer.CheckNetworkSettings()) { d.DialogMessage = "The specified port is not available.\nPlease shutdown any other application\nusing the port or choose a different one."; d.ShowDialog(this); } } InitializeComponent(); server = new SimCoreServer.SimCoreServer(); LoadServerOptions(); eventClient = new SimulationEventDistributorClient(); SimCoreServer.SimCoreServer.simEngine.simCore.distributor.RegisterClient(ref eventClient); eventClient.Subscribe("ServerState"); eventClient.Subscribe("PauseScenario"); eventClient.Subscribe("ResumeScenario"); serverState = "SCENARIO_STOPPED"; comboBoxReplaySpeed.SelectedIndex = 4; comboBoxReplaySpeed.Enabled = false; toolStripStatusLabelServerStatus.Text = "Server: STOPPED"; toolStripStatusLabelSimStatus.Text = "Simulation: STOPPED"; DMInfo = new DMInfoManager(this); UpdateScenarioNameLabel(); updateTimer.Start(); UpdateVoiceServerButton(); }
/// <summary> /// This method allows either the user or the constructor to /// set up an existing network connection. /// Parameters: /// NetworkClient: The client to connect to. /// Subscriptions to incoming events are set here. /// </summary> public void AddNetworkClient(SimulationEventDistributorClient s) { server = s; server.Subscribe("SimCoreReady"); server.Subscribe("MoveDone"); server.Subscribe("StateChange"); server.Subscribe("MoveObjectRequest"); server.Subscribe("AttackObjectRequest"); server.Subscribe("WeaponLaunchRequest"); server.Subscribe("RequestChatRoomCreate"); server.Subscribe("RequestCloseChatRoom"); server.Subscribe("RequestWhiteboardRoomCreate"); server.Subscribe("SubplatformLaunchRequest"); server.Subscribe("SubplatformDockRequest"); server.Subscribe("SelfDefenseAttackStarted"); server.Subscribe("AttackSucceeded"); server.Subscribe("ClientSideAssetTransferAllowed"); server.Subscribe("ChangeTagRequest"); server.Subscribe("TransferObjectRequest"); server.Subscribe("DynamicCreate"); server.Subscribe("DynamicReveal"); }