bool BaseProcessIGCMessage()
        {
            if (!_BASEIGCChannel.HasPendingMessage)
            {
                return(false);
            }
            Echo("Base Response");
            var    igcMessage = _BASEIGCChannel.AcceptMessage();
            string sMessage   = (string)igcMessage.Data;

            string[] aMessage = sMessage.Trim().Split(':');

            double x1, y1, z1;
            int    iOffset = 0;
            string sName   = aMessage[iOffset++];

            long id = 0;

            long.TryParse(aMessage[iOffset++], out id);

            x1 = Convert.ToDouble(aMessage[iOffset++]);
            y1 = Convert.ToDouble(aMessage[iOffset++]);
            z1 = Convert.ToDouble(aMessage[iOffset++]);
            Vector3D vPosition = new Vector3D(x1, y1, z1);

            bool bJumpCapable = stringToBool(aMessage[iOffset++]);

            BaseAdd(id, sName, vPosition, bJumpCapable);

            return(false);
        }
示例#2
0
        public void Main(string argument, UpdateType updateSource)
        {
            if (updateSource.Equals(UpdateType.IGC))
            {
                while (broadcast_listener.HasPendingMessage)
                {
                    var message = broadcast_listener.AcceptMessage();
                    if (message.Tag == broadcast_tag)
                    {
                        string action = message.Data.ToString();

                        if (action == "start")
                        {
                            float velocity = 0.1f;
                            if (piston.Velocity == 0)
                            {
                                piston.Velocity = velocity;
                            }
                            else if (piston.Velocity == velocity)
                            {
                                piston.Velocity = velocity - (velocity * 2);
                            }
                        }
                        else if (action == "halt")
                        {
                            piston.Velocity = 0f;;
                        }
                        else if (action == "drill")
                        {
                            drill.Enabled = !drill.Enabled;
                        }
                    }
                }
            }
        }
        void HandleMessage()
        {
            while (directiveListener.HasPendingMessage)
            {
                var directive = GreedleDirective.FromJSON(JSON.Parse(directiveListener.AcceptMessage().As <string>()));
                switch (directive.type)
                {
                case GreedleDirective.DirectiveType.Respond:
                    IGC.SendBroadcastMessage(
                        "greedle_response",
                        JSON.Stringify(GreedleResponse.ToJSON(new GreedleResponse()
                    {
                        name     = name,
                        position = mainControl.GetPosition()
                    }))
                        ); break;

                case GreedleDirective.DirectiveType.Target:
                {
                    if (directive.targetDirective.addressedTo == name)
                    {
                        Target(directive.targetDirective.target);
                    }
                    break;
                }
                }
            }
        }
示例#4
0
        void UpdatePriorities()
        {
            EnemyPriorityClearScratchpad.Clear();
            foreach (var kvp in EnemyPrioritiesOverride)
            {
                if (!EnemyPrioritiesKeepSet.Contains(kvp.Key))
                {
                    EnemyPriorityClearScratchpad.Add(kvp.Key);
                }
            }
            foreach (var id in EnemyPriorityClearScratchpad)
            {
                EnemyPrioritiesOverride.Remove(id);
            }

            EnemyPrioritiesKeepSet.Clear();
            while (PriorityListener.HasPendingMessage)
            {
                var msg = PriorityListener.AcceptMessage();
                if (msg.Source == CanonicalTimeSourceID)
                {
                    EnemyPriorities = (ImmutableDictionary <long, int>)msg.Data;
                }
            }
        }
示例#5
0
        void UpdateIntelFromReports(TimeSpan timestamp)
        {
            List <IMyBroadcastListener> listeners = new List <IMyBroadcastListener>();

            Context.IGC.GetBroadcastListeners(listeners);

            while (ReportListener.HasPendingMessage)
            {
                var msg = ReportListener.AcceptMessage();
                foreach (var binding in IGCBindings)
                {
                    var updateKey = binding.ReceiveAndUpdateFleetIntelligence(Context, msg.Data, IntelItems, Context.IGC.Me);
                    if (updateKey.HasValue)
                    {
                        Timestamps[updateKey.Value] = timestamp;
                        break;
                    }
                }

                if (msg.Data is MyTuple <long, MyTuple <int, long, MyTuple <MyTuple <Vector3D, Vector3D, double>, MyTuple <string, long, float, int>, MyTuple <int, string, int, int, Vector3I>, MyTuple <long, int> > > > )
                {
                    var unpacked = (MyTuple <long, MyTuple <int, long, MyTuple <MyTuple <Vector3D, Vector3D, double>, MyTuple <string, long, float, int>, MyTuple <int, string, int, int, Vector3I>, MyTuple <long, int> > > >)(msg.Data);
                }
            }
        }
 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());
         }
     }
 }
示例#7
0
    public void Process(string callbackString = "")
    {
        List<Action<MyIGCMessage>> callbacks;

        foreach (var kv in this.listeners) {
            string channel = kv.Key;
            IMyBroadcastListener listener = kv.Value;

            if (listener.HasPendingMessage && this.handlers.TryGetValue(channel, out callbacks)) {
                while (listener.HasPendingMessage) {
                    MyIGCMessage msg = listener.AcceptMessage();
                    foreach (Action<MyIGCMessage> handle in callbacks) {
                        handle(msg);
                    }
                }
            }
        }

        if (this.unicastListener != null) {
            if (this.unicastListener.HasPendingMessage) {
                while (this.unicastListener.HasPendingMessage) {
                    MyIGCMessage msg = this.unicastListener.AcceptMessage();
                    if (this.unicastHandlers.TryGetValue(msg.Tag, out callbacks)) {
                        foreach (Action<MyIGCMessage> handle in callbacks) {
                            handle(msg);
                        }
                    }
                }
            }
        }
    }
示例#8
0
 public void Main(string argument, UpdateType updateSource)
 {
     try
     {
         if ((updateSource & (UpdateType.Trigger | UpdateType.Terminal | UpdateType.Script)) != 0)
         {
             UpdateSettings();
             if (argument.Contains("launch"))
             {
                 var            coord = argument.Replace("launch ", "");
                 MyWaypointInfo wp;
                 if (MyWaypointInfo.TryParse(coord, out wp))
                 {
                     LaunchMissiles(wp);
                 }
                 else
                 {
                     LogLine($"Invalid GPS coordinates \"{coord}\", cannot initiate launch.");
                 }
             }
             else if (argument.Contains("abort"))
             {
                 AbortMissiles(detonate: false);
             }
             else if (argument.Contains("detonate"))
             {
                 AbortMissiles(detonate: true);
             }
         }
         if ((updateSource & UpdateType.IGC) != 0)
         {
             if (missileMsgListener.HasPendingMessage)
             {
                 var msg = missileMsgListener.AcceptMessage();
                 LogLine($">: {msg.Data}");
             }
             if (missileStatusListener.HasPendingMessage)
             {
                 var msg = missileStatusListener.AcceptMessage();
                 statusLogger.OutputLine(msg.Data.ToString());
             }
             messageHandler.Tick();
         }
         if ((updateSource & UpdateType.Update100) != 0)
         {
             if (this.directing && this.directorTurret.IsUnderControl)
             {
                 var azimuth = this.directorTurret.Azimuth;
                 var elev    = this.directorTurret.Elevation;
             }
         }
     }
     catch (Exception ex)
     {
         LogLine($"Launch main expection: {ex}\nStacktrace: \n{ex.StackTrace}");
     }
 }
示例#9
0
            public Ship init()
            {
                Ship ship = new Ship();

                ship.id     = pb.EntityId;
                ship.type   = "0";
                ship.action = "NULL";
                igc.SendBroadcastMessage <String>(listenerId, ship.encode());
                if (broadcastListener.HasPendingMessage)
                {
                    MyIGCMessage message = broadcastListener.AcceptMessage();
                    Ship         s       = new Ship();
                    s.decode(message.Data.ToString());
                    return(s);
                }

                return(null);
            }
            public void ListenToEveryIndirectMsg(string tag, Action <MyIGCMessage> reader)
            {
                IMyBroadcastListener l = p.IGC.RegisterBroadcastListener(tag);

                while (l.HasPendingMessage)
                {
                    reader(l.AcceptMessage());
                }
            }
示例#11
0
        void Main(string argument, UpdateType updateSource)
        {
            if (updateSource == UpdateType.Update1 || updateSource == UpdateType.Update10 || updateSource == UpdateType.Update100)
            {
                // Main code
                Clock.Update();
                if (Clock.Runtime == startRuntime)
                {
                    Echo("Starting.");
                    Start();
                }
                else if (startRuntime != -1)
                {
                    Echo("Waiting to start:");
                    double sec = startDelay - Clock.GetSeconds(0);
                    Echo(sec.ToString("0.0") + 's');
                    return;
                }

                Echo("Running.");
                Detect();
                Echo("Has target: " + detected);
                Echo("Known location: " + lastEnemy.HasValue);
                double secSince = Clock.GetSeconds(contactTime);
                if (secSince > 0 && secSince < timeout)
                {
                    Echo("Time since contact: " + secSince.ToString("0.00"));
                }

                Move();
            }
            else if (updateSource == UpdateType.IGC)
            {
                if (helpListener != null && receiveHelpMsgs && !detected && helpListener.HasPendingMessage && !rc.IsAutoPilotEnabled)
                {
                    MyIGCMessage msg = helpListener.AcceptMessage();
                    if (msg.Data is Vector3D)
                    {
                        Vector3D pos   = (Vector3D)msg.Data;
                        double   dist2 = Vector3D.DistanceSquared(rc.GetPosition(), pos);
                        if (dist2 < replyToHelpRange * replyToHelpRange)
                        {
                            lastEnemy = null;
                            GoTo(pos, "HelpCall");
                        }
                    }
                }
            }
            else
            {
                Command(argument);
            }
        }
示例#12
0
        public void Main(string argument, UpdateType updateSource)
        {
            if (
                (updateSource & (UpdateType.Trigger | UpdateType.Terminal)) > 0 || // run by a terminal action
                (updateSource & (UpdateType.Mod)) > 0 || // script run by a mod
                (updateSource & (UpdateType.Script)) > 0 // this pb run by another script (PB)
                )
            {                                            // script was run because of an action
                if (argument != "")
                {
                    // if we are given an argument, send it out over our broadcast channel
                    IGC.SendBroadcastMessage(_broadCastTag, argument);
                    Echo("Sending message:\n" + argument);
                }
            }

            if ((updateSource & UpdateType.IGC) > 0)
            { // script was run because of incoming IGC message
                if (_myBroadcastListener.HasPendingMessage)
                {
                    var myIGCMessage = _myBroadcastListener.AcceptMessage();
                    if (myIGCMessage.Tag == _broadCastTag)
                    { // This is our tag
                        if (myIGCMessage.Data is string)
                        {
                            string lightName = myIGCMessage.Data.ToString();

                            IMyInteriorLight light;

                            light = GridTerminalSystem.GetBlockWithName(lightName) as IMyInteriorLight;
                            if (light == null)
                            {
                                Echo("Oh my! I couldn't find that block...");
                                Echo(lightName);
                                return;
                            }

                            light.Enabled = !light.Enabled;
                            Echo("I have toggled the light!");
                        }
                        else // if(msg.Data is XXX)
                        {
                            // handle other data types here...
                        }
                    }
                    else
                    {
                        // handle other tags here
                    }
                }
            }
        }
 void GetCommands(TimeSpan timestamp)
 {
     while (CommandListener.HasPendingMessage)
     {
         var msg = CommandListener.AcceptMessage();
         if (msg.Data is MyTuple <int, MyTuple <int, long>, int, int> )
         {
             WaitingCommand          = (MyTuple <int, MyTuple <int, long>, int, int>)msg.Data;
             WaitingCommandTimestamp = timestamp;
             TryAddTaskFromWaitingCommand(timestamp);
         }
     }
 }
 void CheckForUpdates()
 {
     checkForUpdates++;
     while (responseListener.HasPendingMessage)
     {
         greedleResponsesCollected++;
         var response = GreedleResponse.FromJSON(JSON.SyncParse(responseListener.AcceptMessage().As <string>()));
         greedles.Add(new Greedle()
         {
             name = response.name, position = response.position
         });
     }
     DrawOutput();
 }
示例#15
0
 void ReceivePriorityRequests()
 {
     while (PriorityRequestListener.HasPendingMessage)
     {
         var msg = PriorityRequestListener.AcceptMessage();
         if (!(msg.Data is MyTuple <long, int>))
         {
             continue;
         }
         MyTuple <long, int> unpacked = (MyTuple <long, int>)msg.Data;
         var newPriority = Math.Max(0, Math.Min(4, unpacked.Item2));
         MasterEnemyPriorities[unpacked.Item1] = newPriority;
     }
 }
示例#16
0
        // Handle the available messages
        bool  HandleMessages()
        {
            int incomingCount = 1; // keep a count of how many messages we've processed

            do
            {
                Echo("Message " + incomingCount.ToString());

                // check broadcast first, then unicast
                bool bBroadcast = _bListener.HasPendingMessage;
                if (bBroadcast)
                {
                    Echo("Broadcast");
                }
                else
                {
                    Echo("Unicast");
                }
                var msg = _bListener.HasPendingMessage ? _bListener.AcceptMessage() : _uListener.AcceptMessage();


                // information about the received message
                Echo("Received Message");
                Echo(msg.ToString());
                var src = msg.Source;
                Echo("Source=" + src.ToString());
                Echo("Data=" + msg.Data);
                Echo("Tag=" + msg.Tag);


                // we could check to see if the source of the message is still reachable (destroyed, out of range, etc)
                // if(IGC.IsEndpointReachable(msg.Source)) {}

                // If we got a brodcast message, reply with a unicast message to the sender
                if (bBroadcast)
                {
                    if (IGC.SendUnicastMessage <string>(msg.Source, UnicastTag, "Message received by:" + Me.EntityId.ToString()))
                    {
                        Echo("Response Sent");
                    }
                    else
                    {
                        Echo("Error sending response");
                    }
                }
                Echo("----");
                incomingCount++;
            } while (_bListener.HasPendingMessage || _uListener.HasPendingMessage); // Process all pending messages
            return(true);
        }
示例#17
0
            public void CheckPendingMessages()
            {
                while (uniComms.HasPendingMessage)
                {
                    var message = uniComms.AcceptMessage();
                    ProcessUniCommsMessage(message);
                }

                while (keepaliveChann.HasPendingMessage)
                {
                    var message = keepaliveChann.AcceptMessage();
                    ServerKeepAlive((long)message.Data);
                }
            }
示例#18
0
 private void ProcessMessages()
 {
     while (Listener.HasPendingMessage)
     {
         MyIGCMessage msg  = Listener.AcceptMessage();
         string       data = msg.Data.ToString();
         if (DroneID == 0)
         {
             CheckForID(data);
         }
         Echo(data);
         WriteOnScreen(data);
     }
 }
示例#19
0
        void HandleMessageInit()
        {
            if (!_initialized)
            {
                while (_turtleListenerInit.HasPendingMessage)
                {
                    var      vectorString = _turtleListenerInit.AcceptMessage();
                    string[] split        = vectorString.Data.ToString().Split(';');
                    var      name         = split[0];
                    var      data         = split[1];
                    switch (name)
                    {
                    case "A":
                        Vector3D.TryParse(data, out _basis[0]);
                        _basis[1] = -_basis[0];
                        break;

                    case "B":
                        Vector3D.TryParse(data, out _basis[2]);
                        _basis[3] = -_basis[2];
                        break;

                    case "Up":
                        Vector3D.TryParse(data, out _basis[4]);
                        _basis[5] = -_basis[4];
                        break;

                    case "Origin":
                        Vector3D.TryParse(data, out _origin);
                        break;

                    default:
                        _messageBuilder.AppendLine("_turtleListenerInit: Unknown");
                        break;
                    }
                }
                if (VectorsValid())
                {
                    _initialized = true;
                    _messageBuilder.AppendLine("Successfully oriented.\nInitialized.");
                    _turtleListenerInit.DisableMessageCallback();
                }
                else
                {
                    _initialized = false;
                    _messageBuilder.AppendLine("Could not orient.\nFailed to initialize.");
                }
            }
        }
示例#20
0
 public void Main(string argument, UpdateType updateSource)
 {
     Echo(updateSource.ToString() + " arg:" + argument);
     if ((updateSource & UpdateType.IGC) > 0)
     {
         if (listener.HasPendingMessage)
         {
             MyIGCMessage message = listener.AcceptMessage();
             if (message.Data is string)
             {
                 Echo(message.Data.ToString());
             }
         }
     }
 }
示例#21
0
        public void Main(string argument, UpdateType updateSource)
        {
            // Calculate and Output for informational purposes
            _runcount++;
            Echo(_runcount.ToString() + ":" + updateSource.ToString());

            if (
                (updateSource & (UpdateType.Trigger | UpdateType.Terminal)) > 0 || // run by a terminal action
                (updateSource & (UpdateType.Mod)) > 0 || // script run by a mod
                (updateSource & (UpdateType.Script)) > 0 // this pb run by another script (PB)
                )
            {                                            // script was run because of an action
                if (argument != "")
                {
                    // if we are given an argument, send it out over our broadcast channel
                    IGC.SendBroadcastMessage(_broadCastTag, argument);
                    Echo("Sending message:\n" + argument);
                }
            }

            if ((updateSource & UpdateType.IGC) > 0)
            { // script was run because of incoming IGC message
                while (_myBroadcastListener.HasPendingMessage)
                {
                    MyIGCMessage myIGCMessage = _myBroadcastListener.AcceptMessage();
                    if (myIGCMessage.Tag == _broadCastTag)
                    { // This is our tag
                        if (myIGCMessage.Data is string)
                        {
                            string str = myIGCMessage.Data.ToString();
                            Echo("Received IGC Public Message");
                            Echo("Tag=" + myIGCMessage.Tag);
                            Echo("Data=" + myIGCMessage.Data.ToString());
                            Echo("Source=" + myIGCMessage.Source.ToString("X"));
                        }
                        else // if(msg.Data is XXX)
                        {
                            // handle other data types here...
                        }
                    }
                    else
                    {
                        // handle other tags here
                    }
                }
            }
        }
示例#22
0
 public void Main(string argument, UpdateType updateSource)
 {
     Echo(updateSource.ToString() + " arg:" + argument);
     if ((updateSource & UpdateType.IGC) > 0)
     {
         if (listener.HasPendingMessage)
         {
             MyIGCMessage message = listener.AcceptMessage();
             if (message.Data is string)
             {
                 Echo(message.Data.ToString());
                 // отправляем ответное сообщение
                 IGC.SendUnicastMessage <string>(message.Source, TAG, "result message");
             }
         }
     }
 }
示例#23
0
            public void HandleMessage()
            {
                //handle broadcasts:
                while (_myBroadcastListener.HasPendingMessage)
                {
                    var myIGCMessage = _myBroadcastListener.AcceptMessage();
                    if (myIGCMessage.Tag == _recallRequestTag)
                    {
                        var data       = myIGCMessage.Data.ToString();
                        var data_parts = data.Split(';');
                        var arg        = data_parts[0];

                        long sourceGrid = 0;
                        long.TryParse(data_parts[1], out sourceGrid);

                        parent_program.shipIOHandler.Echo("Broadcast received. This ship has been ordered to dock.");

                        var arg_test = parent_program.FindHomeLocation(arg);
                        if (arg_test != null && sourceGrid != parent_program.Me.CubeGrid.EntityId)
                        {
                            parent_program.Main(arg, UpdateType.Script);
                        }
                    }
                }


                // handle unicasts:
                var bFoundMessages = false;

                do
                {
                    bFoundMessages = false;
                    if (_myUnicastListener.HasPendingMessage)
                    {
                        bFoundMessages = true;
                        var msg = _myUnicastListener.AcceptMessage();
                        if (msg.Tag == _responseTag)
                        {
                            ParsePositionalResponse(msg.Data.ToString());
                        }
                        //parent_program.shipIOHandler.Echo("Unicast received. Data: " + .ToString());
                        //parent_program.shipIOHandler.Echo("Tag: " + msg.Tag.ToString());
                    }
                } while (bFoundMessages);
            }
示例#24
0
        void GetSyncMessages(TimeSpan timestamp)
        {
            while (SyncListener.HasPendingMessage)
            {
                var msg = SyncListener.AcceptMessage();
                if (msg.Source == CanonicalTimeSourceID)
                {
                    IGCBindings.ForEach(binding => binding.ReceiveAndUpdateFleetIntelligenceSyncPackage(Context, msg.Data, IntelItems, ref KeyScratchpad, CanonicalTimeSourceID));
                }
            }

            foreach (var key in KeyScratchpad)
            {
                Timestamps[key] = timestamp;
            }

            KeyScratchpad.Clear();
        }
示例#25
0
        void GetTimeMessage(TimeSpan timestamp)
        {
            if (timestamp == TimeSpan.Zero)
            {
                return;
            }

            MyIGCMessage?msg = null;

            while (TimeListener.HasPendingMessage)
            {
                msg = TimeListener.AcceptMessage();
            }

            if (msg != null)
            {
                var tMsg = (MyIGCMessage)msg;
                if (tMsg.Data is MyTuple <double, int, long> )
                {
                    var unpacked = (MyTuple <double, int, long>)tMsg.Data;

                    if (unpacked.Item2 > CanonicalTimeSourceRank || (unpacked.Item2 == CanonicalTimeSourceRank && unpacked.Item3 > CanonicalTimeSourceID))
                    {
                        CanonicalTimeSourceRank = unpacked.Item2;
                        CanonicalTimeSourceID   = unpacked.Item3;
                    }

                    if (CanonicalTimeSourceID == unpacked.Item3)
                    {
                        CanonicalTimeDiff = TimeSpan.FromMilliseconds(unpacked.Item1 + kOneTick) - timestamp;
                    }

                    if (unpacked.Item2 > HighestRank || (unpacked.Item2 == HighestRank && unpacked.Item3 > HighestRankID))
                    {
                        HighestRank   = unpacked.Item2;
                        HighestRankID = unpacked.Item3;
                        if (IsMaster)
                        {
                            Demote(HighestRankID, HighestRank);
                        }
                    }
                }
            }
        }
        void ProcessHangarRequests(TimeSpan timestamp)
        {
            while (HangarListener.HasPendingMessage)
            {
                var data = HangarListener.AcceptMessage().Data;
                if (!(data is MyTuple <long, long, int>))
                {
                    return;
                }
                var unpacked = (MyTuple <long, long, int>)data;

                Hangar hangar;
                if (!HangarsDict.TryGetValue(unpacked.Item2, out hangar))
                {
                    return;
                }
                hangar.TakeRequest(unpacked.Item1, (HangarRequest)unpacked.Item3, timestamp);
            }
        }
示例#27
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));
            }
            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);
            }
示例#29
0
 public void Main(string argument, UpdateType updateSource)
 {
     if ((updateSource & UpdateType.IGC) > 0)
     {
         if (universalListener != null && universalListener.HasPendingMessage)
         {
             MyIGCMessage        message = universalListener.AcceptMessage();
             List <IMyTextPanel> panels  = new List <IMyTextPanel>();
             GridTerminalSystem.GetBlocksOfType(panels);
             if (panels.Count > 0)
             {
                 panels[0].WriteText(message.Tag + " " + message.Source + " " + message.Data + "\n", false);
             }
         }
     }
     else
     {
         universalListener = IGC.RegisterBroadcastListener(argument);
         universalListener.SetMessageCallback();
         Echo("CURRENT LISTENING CODE: " + argument);
     }
 }
        public void Main(string argument, UpdateType updateSource)
        {
            if ((updateSource & (UpdateType.Script | UpdateType.Terminal | UpdateType.Trigger)) > 0)
            {
                string[] args = argument.ToLower().Split(' ');
                if (args.Length > 0)
                {
                    switch (args[0])
                    {
                    case "reg":
                        if (!AEGISUseRadarData)
                        {
                            content = "";
                            return;
                        }
                        if (Radar_Controller == null && !SetRadarController())
                        {
                            break;
                        }

                        content = Radar_Controller.CustomData;
                        break;

                    case "terminate":
                    case "off":
                    case "quit":
                    case "stop":
                        Function(false);
                        break;

                    case "on":
                    case "start":
                        Function(true);
                        break;


                    case "aegis":
                        if (args.Length < 2)
                        {
                            AEGISUseRadarData = !AEGISUseRadarData;
                        }
                        else
                        {
                            switch (args[1])
                            {
                            case "on":
                            case "up":
                            case "true":
                                if (!AEGISIsOnline)
                                {
                                    Function(true);
                                }
                                AEGISUseRadarData = true;
                                break;

                            case "off":
                            case "down":
                            case "false":
                                AEGISUseRadarData = false;
                                break;

                            case "terminate":
                                Function(false);
                                break;
                            }
                        }
                        break;
                    }
                }
            }
            else
            if ((updateSource & UpdateType.IGC) > 0)
            {
                if (AEGISListener != null && AEGISListener.HasPendingMessage)
                {
                    MyIGCMessage message = AEGISListener.AcceptMessage();
                    if (message.Tag.Equals(MY_PREFIX))
                    {
                        string   data = (string)message.Data;
                        string[] bits = data.Split(';');

                        if (bits.Length <= 0)
                        {
                            return;
                        }
                        switch (bits[0].ToUpper())
                        {
                        case "BOOM":
                            long id;
                            if (bits.Length > 1 && long.TryParse(bits[1], out id))
                            {
                                AMTargets.Remove(id);
                            }
                            break;
                        }
                    }
                }
                return;
            }
            else
            {
                string status;
                ParseTurretData(Me.CustomData);
                Me.CustomData = "";

                if (AEGISIsOnline && AEGISUseRadarData)
                {
                    status = "AEGIS online.";
                }
                else if (AEGISIsOnline && !AEGISUseRadarData)
                {
                    status = "AEGIS in passive mode.";
                }
                else
                {
                    status = "AEGIS offline";
                }

                status += string.Format("\nTracking {0} object{1}  {2}", CGTargets.Count, CGTargets.Count == 1? "":"s", ProgressShower());
                if (AEGISTargetsNeutrals)
                {
                    status += "\nincluding neutral targets.";
                }
                status += "\n\n" + GetTurretStatus();

                if (content.Length > 0 && AEGISUseRadarData)
                {
                    ProcessData(content + GetGenericTargettingData());
                    ticksWOOrders = 0;
                    content       = "";
                    Output(status);
                }
                else
                {
                    if (ticksWOOrders >= 10 || !AEGISUseRadarData)
                    {
                        ProcessData(GetGenericTargettingData());
                        Output(status);
                    }
                    else
                    {
                        ticksWOOrders++;
                    }
                }

                if (timeNo++ >= 600)
                {
                    timeNo = 0;
                    GetMeTheTurrets();
                }

                ProcessJobs();
            }
        }