public Communication(IMyProgrammableBlock pb, IMyIntergridCommunicationSystem igc)
 {
     this.igc          = igc;
     broadcastListener = igc.RegisterBroadcastListener(listenerId);
     unicastListener   = igc.UnicastListener;
     this.pb           = pb;
 }
Exemplo n.º 2
0
        public static IEnumerable <IMyBroadcastListener> GetBroadcastListeners(this IMyIntergridCommunicationSystem src)
        {
            var temp = new List <IMyBroadcastListener>();

            src.GetBroadcastListeners(temp);
            return(temp);
        }
Exemplo n.º 3
0
 public AutoConnectionServer(IMyIntergridCommunicationSystem igc, AutoConnector connector, IProcessSpawner spawner)
 {
     this.connector   = connector;
     this.igc         = igc;
     this.mainProcess = spawner.Spawn(p => this.Update(), $"ac-server '{this.Name}'", onDone => this.connector.Stop());
     this.logger?.Invoke($"Connector {this.Name} ready");
 }
        public GreedleManager(IMyIntergridCommunicationSystem IGC, IMyTextSurface outputSurface)
        {
            this.IGC = IGC;
            this.responseListener = IGC.RegisterBroadcastListener("greedle_response");
            this.responseListener.SetMessageCallback("Message Callback");
            this.greedles      = new List <Greedle>();
            this.outputSurface = outputSurface;

            commandTree = new PanelCommander.CommandTree()
            {
                label    = "Greedle Commands",
                commands = new List <PanelCommander.Command>()
                {
                    new PanelCommander.Command()
                    {
                        label = "List", action = ListGreedles
                    },
                    new PanelCommander.Command()
                    {
                        label = "Check For Greedle Updates", action = CheckForUpdates
                    }
                },
                subtrees = new List <PanelCommander.CommandTree>(),
            };
            ListGreedles();
        }
Exemplo n.º 5
0
            public ConnectionClient(IniWatcher ini, IMyGridTerminalSystem gts, IMyIntergridCommunicationSystem igc, CommandLine commandLine, IProcessManager manager, Action <string> logger)
            {
                this.gts    = gts;
                this.igc    = igc;
                this.logger = logger;

                this.mainProcess = manager.Spawn(this.listen, "cc-listen", period: 5);
                this.listenerCmd = new CommandLine("Connection client listener", null, this.mainProcess);
                this.listenerCmd.RegisterCommand(new Command("ac-progress", Command.Wrap(this.progress), "", nArgs: 1));
                this.listenerCmd.RegisterCommand(new Command("ac-done", Command.Wrap(this.done), ""));
                this.listenerCmd.RegisterCommand(new Command("ac-cancel", Command.Wrap(this.serverCancel), ""));
                this.listenerCmd.RegisterCommand(new Command("ac-ko", Command.Wrap(this.ko), ""));
                this.listener = this.igc.UnicastListener;

                ini.Add(this);
                this.Read(ini);
                this.addCmds(commandLine);

                manager.AddOnSave(this.save);
                if (ini.ContainsKey(SECTION, "state"))
                {
                    ConnectionState state;
                    Enum.TryParse(ini.Get(SECTION, "state").ToString(), out state);
                    this.State = state;
                }
            }
Exemplo n.º 6
0
            public InterGridComms(IMyIntergridCommunicationSystem comms, IngameTime time, IMyProgrammableBlock me)
            {
                commands       = new Dictionary <string, Action <object> >();
                keepaliveChann = comms.RegisterBroadcastListener("ServerKeepAlive");

                this.comms = comms;
                this.time  = time;
                this.me    = me;
            }
 public ShipIGC(long shipID, IMyIntergridCommunicationSystem igc)
 {
     if (igc == null)
     {
         throw new ArgumentNullException(nameof(igc));
     }
     this.igc = igc;
     ShipID   = shipID;
 }
Exemplo n.º 8
0
            public DroneManagement(IngameTime time, IMyIntergridCommunicationSystem comms)
            {
                dronesByPosition = new PositionOctree <Drone>();
                drones           = new Dictionary <long, Drone>();
                commands         = new Dictionary <string, Action <object> >();

                this.time  = time;
                this.comms = comms;
            }
Exemplo n.º 9
0
 public MessageHandler(IMyIntergridCommunicationSystem igc, Action <string> logger = null)
 {
     this.IGC = igc;
     IGC.UnicastListener.SetMessageCallback();
     if (logger != null)
     {
         this.logger = logger;
     }
     logger($"{nameof(MessageHandler)} has been created");
 }
Exemplo n.º 10
0
        public static void UnregisterBroadcastListener(this IMyIntergridCommunicationSystem src, string tag)
        {
            var listeners      = src.GetBroadcastListeners();
            var taggedListener = listeners.FirstOrDefault(l => l.Tag == tag);

            if (taggedListener == null)
            {
                return;
            }
            src.DisableBroadcastListener(taggedListener);
        }
        public ExecutionContext(MyGridProgram program, IMyTerminalBlock reference = null)
        {
            Program  = program;
            IGC      = program.IGC;
            Terminal = program.GridTerminalSystem;

            Reference = (reference == null) ? program.Me : reference;

//             Draw = new DrawAPI(Program);
//             if (!Draw.ModDetected)
//                 Draw = null;
        }
Exemplo n.º 12
0
            public Spaceship(IMyGridTerminalSystem system, IMyIntergridCommunicationSystem igc)
            {
                this.system = system;
                this.igc    = igc;

                cpu = FindRunningPB(system);

                control   = FindBlockOfType <IMyRemoteControl>(system, this, Settings.TAG);
                connector = FindBlockOfType <IMyShipConnector>(system, this, Settings.TAG);
                debug     = FindBlockOfType <IMyTextPanel>(system, this, Settings.TAG);
                if (debug == null)
                {
                    IMyCockpit cockpit = FindBlockOfType <IMyCockpit>(system, this, Settings.TAG);
                    if (cockpit.SurfaceCount > 0)
                    {
                        debug = cockpit.GetSurface(0);
                    }
                }
                debug.Font        = "Monospace";
                debug.ContentType = ContentType.TEXT_AND_IMAGE;

                /*
                 *  screen = cockpit.GetSurface(0);
                 *  screen.ContentType = ContentType.SCRIPT;
                 *  MySpriteDrawFrame frame = screen.DrawFrame();
                 *
                 *
                 *  frame.Add(new MySprite(SpriteType.TEXTURE, "SquareSimple", new Vector2(0, 0), new Vector2(512, 512), Color.Black));
                 *  frame.Add(MySprite.CreateText("Ftiaxe Me!!!", "DEBUG", Color.White));
                 *  frame.Dispose();
                 */

                listener = igc.RegisterBroadcastListener(Settings.COMM_CHANNEL);
                listener = igc.RegisterBroadcastListener(Settings.COMM_CHANNEL);
                listener.SetMessageCallback(Settings.COMM_CHANNEL);
                thrusters = new ThrustersManager(this, control, system);

                autopilot = new Autopilot(this, control, FindBlockOfType <IMyGyro>(system, this));
                cas       = new CollisionAvoidanceSystem(this);
                fd        = new FlightDirector(this);

                if (connector.Status == MyShipConnectorStatus.Connected)
                {
                    flags = SpaceshipFlags.Dock;
                }
                else
                {
                    flags = SpaceshipFlags.Idle;
                }
            }
Exemplo n.º 13
0
 Program()
 {
     gts      = GridTerminalSystem;
     igc      = IGC;
     cockpit  = gts.GetBlockWithName(COCKPIT) as IMyCockpit;
     sound    = gts.GetBlockWithName(SOUND) as IMySoundBlock;
     radar    = new Radar(RADAR);
     arta     = new Artillery(ARTA, cockpit, 1200, 900);
     Torpedos = new List <Torpedo>();
     InitializeTorpedos();
     radio          = new Radio();
     WolfPackDelays = new List <int>();
     lcd            = gts.GetBlockWithName(LCD) as IMyTextPanel;
     if (lcd == null)
     {
         lcd = cockpit.GetSurface(0) as IMyTextPanel;
     }
 }
            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);
            }
Exemplo n.º 15
0
 public static void SendBroadcast <TData>(this IMyIntergridCommunicationSystem igc, Command <TData> cmd)
 {
     igc.SendBroadcastMessage(cmd.Tag, cmd.Serialize());
 }
 public NetworkInterface(IMyIntergridCommunicationSystem IGC, bool respondToPing = true)
 {
     this.IGC           = IGC;
     this.respondToPing = respondToPing;
 }
Exemplo n.º 17
0
 public AutoConnectionServer(MyIni ini, IMyIntergridCommunicationSystem igc, AutoConnector connector, IProcessSpawner spawner, Action <string> logger)
     : this(igc, connector, spawner)
 {
     this.logger = logger;
     this.deserialize(ini);
 }
Exemplo n.º 18
0
 // Internals
 internal void _setContext(Program main)
 {
     Me      = main.Me;
     Runtime = main.Runtime;
     IGC     = main.IGC;
 }