public void Main(string argument, UpdateType updateType)
 {
     while (hangarBroadcastListener.HasPendingMessage)
     {
         MyIGCMessage igc_message = hangarBroadcastListener.AcceptMessage();
         ShipIGC      ship_igc;
         if (shipIGCs.ContainsKey(igc_message.Source))
         {
             ship_igc = shipIGCs[igc_message.Source];
         }
         else
         {
             ship_igc = new ShipIGC(igc_message.Source, IGC);
             shipIGCs.Add(igc_message.Source, ship_igc);
         }
         try
         {
             string igc_message_data = igc_message.As <string>();
             if (igc_message_data != null)
             {
                 shipCommands.Parse(igc_message_data, ship_igc);
             }
         }
         catch (Exception e)
         {
             Echo(e.ToString());
         }
     }
 }
 void HandlePing(MyIGCMessage message)
 {
     if (message.Source == IGC.Me)
     {
         return;
     }
     if (message.As <bool>() == true)
     {
         return;                 // Recieved Pong
     }
     if (respondToPing)
     {
         SendPong(message.Source);
     }
 }
示例#3
0
            public void OnUpdateFrame(string arguments, UpdateType updateSource)
            {
                if ((updateSource & UpdateType.IGC) == UpdateType.IGC)
                {
                    while (listener.HasPendingMessage)
                    {
                        MyIGCMessage message = listener.AcceptMessage();
                        MyTuple <long, string, MatrixD, float> packet = message.As <MyTuple <long, string, MatrixD, float> >();
                        if (destinations.ContainsKey(packet.Item1))
                        {
                            destinations[packet.Item1].id     = packet.Item1;
                            destinations[packet.Item1].name   = packet.Item2;
                            destinations[packet.Item1].matrix = packet.Item3;
                            destinations[packet.Item1].size   = packet.Item4;
                        }
                        else
                        {
                            destinations.Add(packet.Item1, new Destination {
                                id = packet.Item1, name = packet.Item2, matrix = packet.Item3, size = packet.Item4
                            });
                        }
                    }
                }

                if ((updateSource & UpdateType.Trigger) == UpdateType.Trigger)
                {
                    HandleMenu(arguments);
                }

                if ((updateSource & UpdateType.Trigger) == UpdateType.Trigger || (updateSource & UpdateType.Terminal) == UpdateType.Terminal)
                {
                    commands.Execute(arguments);
                }

                if ((updateSource & UpdateType.Update10) == UpdateType.Update10)
                {
                    OnFlightUpdateFrame();
                }
                OnUpdateInfoFrame();
                debug.WriteText(menu.Draw(this));
            }
示例#4
0
 void ProcessStepCheckBroadcastMessages()
 {
     if (this.BroadcastListener.HasPendingMessage)
     {
         EchoR("Received broadcast message");
         MyIGCMessage message = this.BroadcastListener.AcceptMessage();
         try
         {
             var     data       = message.As <MyTuple <long, string, Vector3D, string> >();
             GPSInfo gpsmessage = new GPSInfo()
             {
                 ID       = data.Item1,
                 Name     = data.Item2,
                 Position = data.Item3,
                 Created  = DateTime.Now
             };
             CelestialMap.AddGPSPosition(gpsmessage.Name, gpsmessage.Position);
         }
         catch { }
     }
 }
            public AutoConnectionDispatcher(MyGridProgram program, CommandLine command, MyIni ini, Action <string> logger, IProcessManager manager)
            {
                this.logger  = logger;
                this.manager = manager;
                // Station level initialization
                this.stationName   = ini.GetThrow(INI_GENERAL_SECTION, INI_NAME_KEY).ToString();
                this.referenceName = ini.GetThrow(INI_GENERAL_SECTION, INI_REFERENCE_KEY).ToString();
                IMyTerminalBlock reference = program.GridTerminalSystem.GetBlockWithName(this.referenceName);

                if (reference == null)
                {
                    throw new ArgumentException($"Could not find reference block '{this.referenceName}'");
                }
                this.igc         = program.IGC;
                this.transformer = new CoordinatesTransformer(reference, manager);
                this.log("initializing");
                // Connectors initialization
                var sections = new List <string>();

                ini.GetSections(sections);
                foreach (string sectionName in sections.Where(s => s.StartsWith(AutoConnector.IniConnectorPrefix)))
                {
                    var connector = new AutoConnector(this.stationName, sectionName, program, this.logger, this.transformer, ini);
                    this.autoConnectors.Add(new AutoConnectionServer(ini, this.igc, connector, manager, this.logger));
                }
                this.log($"has {this.autoConnectors.Count} auto connectors");
                this.registerCommands(command, program);

                IMyBroadcastListener listener = this.igc.RegisterBroadcastListener("StationConnectionRequests");

                this.manager.Spawn(p => {
                    if (listener.HasPendingMessage)
                    {
                        MyIGCMessage msg = listener.AcceptMessage();
                        command.StartCmd($"{msg.As<string>()} {msg.Source}", CommandTrigger.Antenna);
                    }
                }, "ac-dispatcher");

                this.manager.AddOnSave(save);
            }
        //Activated message callback invokes this method each time we get new message
        public void Main()
        {
            //Check if there is message waiting
            if (this.IGC.UnicastListener.HasPendingMessage == false)
            {
                return;
            }

            //Accept waiting message
            MyIGCMessage message = this.IGC.UnicastListener.AcceptMessage();

            //This is sender's direct address. We can use it to send direct response right back
            long senderAddress = message.Source;

            //And some data from message
            string data = message.As <string>();

            //Let's log message ...
            this.Echo($"Received message from: {senderAddress}{Environment.NewLine}{data}");

            //... and echo the data right back to sender
            this.IGC.SendUnicastMessage(data, message.Source);
        }
示例#7
0
        public void Main()
        {
            Commands = new Dictionary <string, ExecuteCommandDelegate>
            {
                { "discover", DiscoverCommand },

                { "authenticate", AuthenticateCommand },
                { "auth", AuthenticateCommand },
                { "login", AuthenticateCommand },

                { "exit", ExitCommand },
                { "leave", ExitCommand },
                { "bye", ExitCommand },

                { "list", ListCommand },
                { "ls", ListCommand },
                { "l", ListCommand },

                { "changedirectory", ChangeDirectoryCommand },
                { "cd", ChangeDirectoryCommand },

                { "read", ReadFileCommand },
                { "r", ReadFileCommand },

                { "write", WriteFileCommand },
                { "w", WriteFileCommand },

                { "readstring", ReadStringFileCommand },
                { "rs", ReadStringFileCommand },

                { "writestring", WriteStringFileCommand },
                { "ws", WriteStringFileCommand },
            };
            while (fileSystemListener.HasPendingMessage)
            {
                try
                {
                    MyIGCMessage message = fileSystemListener.AcceptMessage();
                    if (message.Data is string)
                    {
                        string raw_command = message.As <string>().TrimStart();
                        if (raw_command.Length > 0)
                        {
                            List <string> arguments = new List <string>(raw_command.Split(' '));
                            if (arguments.Count > 0)
                            {
                                string command = arguments[0].ToLower();
                                arguments.RemoveAt(0);
                                if (command.Length > 0)
                                {
                                    if (Commands.ContainsKey(command))
                                    {
                                        Session session = (sessions.ContainsKey(message.Source) ? sessions[message.Source] : new Session(message.Source, string.Empty));
                                        Commands[command](arguments.ToArray(), (raw_command.Length > command.Length) ? raw_command.Substring(command.Length).TrimStart() : string.Empty, session, users.ContainsKey(session.UserName) ? users[session.UserName] : null);
                                    }
                                }
                            }
                            arguments.Clear();
                        }
                    }
                }
                catch (Exception e)
                {
                    Echo(e.ToString());
                }
            }
        }