public void StartTextChatServer() { try { List <SimulationEvent> incomingEvents = new List <SimulationEvent>(); server.Subscribe("TextChatRequest"); server.Subscribe("TimeTick"); server.Subscribe("CreateChatRoom"); server.Subscribe("AddToChatRoom"); server.Subscribe("CloseChatRoom"); isRunning = true; //This can be set false elsewhere, and end the loop. while (isRunning) { incomingEvents = server.GetEvents(); if (incomingEvents.Count != 0) { foreach (SimulationEvent se in incomingEvents) { switch (se.eventType) { case "TextChatRequest": TextChatRequest(se); break; case "TimeTick": currentTick = ((IntegerValue)se["Time"]).value; timeString = ((StringValue)se["SimulationTime"]).value; break; case "CreateChatRoom": CreateChatRoom(se); break; case "CloseChatRoom": CloseChatRoom(se); break; case "AddToChatRoom": AddToChatRoom(se); break; default: break; } } } Thread.Sleep(500); } } catch (ThreadAbortException) { } catch (Exception exc) { MessageBox.Show("An error '" + exc.Message + "' has occurred 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(); }
public void StartHandshakeManager() { //started in a thread List <SimulationEvent> incomingEvents = new List <SimulationEvent>(); string eventType; //if (availableDMs.Count == 0) // return; //foreach (string s in availableDMs) lock (dmLock) { foreach (string s in allDMs.Keys) { dmToTerminalMap.Add(s, string.Empty); } } server.Subscribe("HandshakeGUIRegister"); server.Subscribe("HandshakeGUIRoleRequest"); server.Subscribe("HandshakeInitializeGUIDone"); server.Subscribe("ClientSideAssetTransferAllowed"); while (!stopLoop) { incomingEvents = server.GetEvents(); foreach (SimulationEvent e in incomingEvents) { eventType = e.eventType; switch (eventType) { case "HandshakeGUIRegister": GUIRegister(e); break; case "HandshakeGUIRoleRequest": GUIRoleRequest(e); break; case "HandshakeInitializeGUIDone": InitializeGUIDone(e); break; default: break; } } Thread.Sleep(200); } }
private void InitializeDistributor() { distributor = new SimulationEventDistributor(ref simModelInfo); distClient = new SimulationEventDistributorClient(); distributor.RegisterClient(ref distClient); foreach (Aptima.Asim.DDD.CommonComponents.SimulationModelTools.EventInfo e in simModelInfo.eventModel.events.Values) { if (e.simCoreSubscribe) { distClient.Subscribe(e.name); } } }
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 }
//[STAThread] static void Main(string[] args) { string hostname = args[0]; int port = Int32.Parse(args[1]); string simModelName = args[2]; SimulationModelReader smr = new SimulationModelReader(); SimulationModelInfo simModelInfo = smr.readModel(simModelName); SimulationEventDistributor dist = new SimulationEventDistributor(ref simModelInfo); SimulationEventDistributorClient cc = new SimulationEventDistributorClient(); dist.RegisterClient(ref cc); cc.Subscribe("ALL"); ScenarioReader scenarioReader = new ScenarioReader(); QueueManager queueManager = QueueManager.UniqueInstance(); c = new NetworkClient(); c.Connect(hostname, port); EventListener myEL = EventListener.UniqueInstance(c); int t = 0; int dt = simModelInfo.simulationExecutionModel.updateFrequency; SimulationEvent tick = SimulationEventFactory.BuildEvent(ref simModelInfo, "TimeTick"); ((IntegerValue)tick["Time"]).value = t; ConsoleKeyInfo cki; //Console.TreatControlCAsInput = false; //This explodes my code for some reason, but is in Gabe's client code and works fine, what does it do? Console.CancelKeyPress += new ConsoleCancelEventHandler(MyExitHandler); List<SimulationEvent> events = null; while (c.IsConnected() && queueManager.count() > 0) { //Read incoming events queue //if any events deal with a conditional event, remove the conditional //event from the conditional list, and place it onto the event queue //if a unit dies, remove them from the event queue and condition list while (c.IsConnected() && !(queueManager.eventsAtTime(t))) { events = c.GetEvents(); foreach (SimulationEvent e in events) { if (e.eventType == "MoveDone") c.PutEvent(myEL.MoveDoneReceived(e, simModelInfo, tick)); System.Console.WriteLine(SimulationEventFactory.XMLSerialize(e)); } ((IntegerValue)tick["Time"]).value = t; c.PutEvent(tick); //Console.WriteLine("Sending..."); //Console.WriteLine(SimulationEventFactory.XMLSerialize(tick)); Thread.Sleep(dt); t += dt; } if (c.IsConnected()) { QueueManager.sendEventsAtTime(t, c); ((IntegerValue)tick["Time"]).value = t; c.PutEvent(tick); //Console.WriteLine("Sending..."); //Console.WriteLine(SimulationEventFactory.XMLSerialize(e)); t += dt; } } while (c.IsConnected()) { ((IntegerValue)tick["Time"]).value = t; c.PutEvent(tick); //Console.WriteLine("Sending..."); //Console.WriteLine(SimulationEventFactory.XMLSerialize(tick)); Thread.Sleep(dt); t += dt; } }
public void WriteToLog() { try { //SimulationEventDistributor dist = new SimulationEventDistributor(ref simModelInfo); //cc = new SimulationEventDistributorClient(); List <SimulationEvent> incomingEvents = new List <SimulationEvent>(); FileStream file = new FileStream(logPath, FileMode.Create); StreamWriter sr = new StreamWriter(file); sr.WriteLine("<Creator><Version>" + productVersion + "</Version><CompiledOn>" + compileDate + "</CompiledOn></Creator>"); actualTime = 0; //dist.RegisterClient(ref cc); foreach (string subString in simModelInfo.eventModel.events.Keys) { //cc.Subscribe(subString); //If the user wants the detailed log, or if the event is flagged with the shouldLog //bool value, it should subscribe to that event. Otherwise, don't subscribe. if ((logMode == "Detailed") || simModelInfo.eventModel.events[subString].shouldLog) { cc.Subscribe(subString); } } isRunning = true; while (isRunning) { //incomingEvents = cc.GetEvents(); incomingEvents = cc.GetEvents(); if (incomingEvents.Count != 0) { foreach (SimulationEvent se in incomingEvents) { if (se.eventType == "TimeTick") { actualTime = ((IntegerValue)se["Time"]).value; } ((IntegerValue)se["Time"]).value = actualTime; try { sr.WriteLine(SimulationEventFactory.XMLSerialize(se)); } catch (Exception exc) { ErrorLog.Write(String.Format("NONFATAL Serialize Error in ReplayLogger: {0}", se.eventType)); ErrorLog.Write(exc.ToString()); continue; } sr.Flush(); } incomingEvents.Clear(); } Thread.Sleep(100); } sr.Close(); file.Close(); //dist.RemoveClient(cc.id); //is this correct? //server.Disconnect(); } catch (ThreadAbortException) { } catch (Exception exc) { MessageBox.Show("An error '" + exc.Message + "' has occurred 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 void StartViewManagerLoop() { try { List <SimulationEvent> incomingEvents; foreach (string e in simModelInfo.eventModel.events.Keys) { server.Subscribe(e); } while (isRunning) { incomingEvents = server.GetEvents(); foreach (SimulationEvent e in incomingEvents) { //eventStreamViewer.AddEvent(e.eventType, ((IntegerValue)e.parameters["Time"]).value); switch (e.eventType) {//this should eventually just send handshake manager the event, and HM will determine //how to handle it. case "AuthenticationRequest": authenticationManager.AuthenticationRequest(e); break; case "HandshakeGUIRegister": handshakeManager.GUIRegister(e); break; case "HandshakeGUIRoleRequest": handshakeManager.GUIRoleRequest(e); break; case "HandshakeInitializeGUIDone": handshakeManager.InitializeGUIDone(e); authenticationManager.IncrementUsers(); break; case "Playfield": handshakeManager.SetPlayfieldInformation(e); break; //case "TextChat": // textChat.AddTextMessage(e); // break; case "DisconnectDecisionMaker": handshakeManager.DisconnectPlayer(e); if (((StringValue)e["DecisionMakerID"]).value != string.Empty) { authenticationManager.DecrementUsers(); //TODO: See if this is called as well as below } break; case "DisconnectTerminal": handshakeManager.DisconnectTerminal(e); //authenticationManager.DecrementUsers(); //TODO: See if this is called as well as above break; case "NewObject": if (((StringValue)e["ObjectType"]).value == "DecisionMaker") { handshakeManager.ReceiveDecisionMakerEvent(e); } break; case "CreateChatRoom": handshakeManager.CreateChatRoom(e); break; case "CloseChatRoom": handshakeManager.CloseChatRoom(e); break; case "CreateVoiceChannel": handshakeManager.CreateVoiceChannel(e); break; case "CloseVoiceChannel": handshakeManager.CloseVoiceChannel(e); break; case "CreateWhiteboardRoom": handshakeManager.CreateWhiteboardRoom(e); break; case "ClientSideAssetTransferAllowed": handshakeManager.SetAssetTransferFlag(e); break; case "StopScenario": authenticationManager.ResetUserCount(); break; default: break; } } Thread.Sleep(500); } } catch (ThreadAbortException) { } catch (Exception exc) { MessageBox.Show("An error '" + exc.Message + "' has occurred 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(); } }
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(); } } }
//[STAThread] static void Main(string[] args) { string hostname = args[0]; int port = Int32.Parse(args[1]); string simModelName = args[2]; SimulationModelReader smr = new SimulationModelReader(); SimulationModelInfo simModelInfo = smr.readModel(simModelName); SimulationEventDistributor dist = new SimulationEventDistributor(ref simModelInfo); SimulationEventDistributorClient cc = new SimulationEventDistributorClient(); dist.RegisterClient(ref cc); cc.Subscribe("ALL"); ScenarioReader scenarioReader = new ScenarioReader(); QueueManager queueManager = QueueManager.UniqueInstance(); c = new NetworkClient(); c.Connect(hostname, port); EventListener myEL = EventListener.UniqueInstance(c); int t = 0; int dt = simModelInfo.simulationExecutionModel.updateFrequency; SimulationEvent tick = SimulationEventFactory.BuildEvent(ref simModelInfo, "TimeTick"); ((IntegerValue)tick["Time"]).value = t; ConsoleKeyInfo cki; //Console.TreatControlCAsInput = false; //This explodes my code for some reason, but is in Gabe's client code and works fine, what does it do? Console.CancelKeyPress += new ConsoleCancelEventHandler(MyExitHandler); List <SimulationEvent> events = null; while (c.IsConnected() && queueManager.count() > 0) { //Read incoming events queue //if any events deal with a conditional event, remove the conditional //event from the conditional list, and place it onto the event queue //if a unit dies, remove them from the event queue and condition list while (c.IsConnected() && !(queueManager.eventsAtTime(t))) { events = c.GetEvents(); foreach (SimulationEvent e in events) { if (e.eventType == "MoveDone") { c.PutEvent(myEL.MoveDoneReceived(e, simModelInfo, tick)); } System.Console.WriteLine(SimulationEventFactory.XMLSerialize(e)); } ((IntegerValue)tick["Time"]).value = t; c.PutEvent(tick); //Console.WriteLine("Sending..."); //Console.WriteLine(SimulationEventFactory.XMLSerialize(tick)); Thread.Sleep(dt); t += dt; } if (c.IsConnected()) { QueueManager.sendEventsAtTime(t, c); ((IntegerValue)tick["Time"]).value = t; c.PutEvent(tick); //Console.WriteLine("Sending..."); //Console.WriteLine(SimulationEventFactory.XMLSerialize(e)); t += dt; } } while (c.IsConnected()) { ((IntegerValue)tick["Time"]).value = t; c.PutEvent(tick); //Console.WriteLine("Sending..."); //Console.WriteLine(SimulationEventFactory.XMLSerialize(tick)); Thread.Sleep(dt); t += dt; } }